Skip to content

Commit 80ac1a4

Browse files
authored
Remove bind from outside markings for default constructors. (#705)
* Remove bind from outside markings for default constructors of non derived records. - The default constructor should not use outside bindings. Unless it is for a derived record which has bindings on declaration. Unfortunately the old FrontEnd creates additional record types even when the modification on a record variable declaration are not declarations. - Therefore, we now remove the outside binding markings from the types_vars even for the default constructor so that they are not picked by the codegen function when generating the body for the default constructors. - Constructors with outside inputs are generated explicitly with a name that contains the index of the variable.
1 parent 533e9a8 commit 80ac1a4

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

OMCompiler/Compiler/FrontEnd/DAE.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ constant Attributes dummyAttrInput = ATTR(NON_CONNECTOR(), SCode.NON_PARALLEL(),
836836
public uniontype BindingSource "where this binding came from: either default binding or start value"
837837
record BINDING_FROM_DEFAULT_VALUE "the binding came from the default value" end BINDING_FROM_DEFAULT_VALUE;
838838
record BINDING_FROM_START_VALUE "the binding came from the start value" end BINDING_FROM_START_VALUE;
839-
record BINDING_FROM_RECORD_SUBMODS "the EQ binding is created from the submods of a record declration" end BINDING_FROM_RECORD_SUBMODS;
839+
record BINDING_FROM_RECORD_SUBMODS "the EQ binding is created from the submods of a record VARIABLE declration e.g. 'R r(i=2)' tranformed by instantiation to 'R r = R(i=2)' " end BINDING_FROM_RECORD_SUBMODS;
840+
record BINDING_FROM_DERIVED_RECORD_DECL "the binding is created from the submods of a DERIVED record DECLARATION e.g. 'record K = R(i=3)'" end BINDING_FROM_DERIVED_RECORD_DECL;
840841
end BindingSource;
841842

842843
public

OMCompiler/Compiler/FrontEnd/Inst.mo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ algorithm
990990
for submod in submods loop
991991
if varIsModifiedInDerivedMod(var.name, submod) then
992992
var.bind_from_outside := true;
993+
var.binding := markBindingFromDerivedRecordMods(var.binding);
993994
break;
994995
end if;
995996
end for;
@@ -1003,6 +1004,18 @@ algorithm
10031004

10041005
end markDerivedRecordOutsideBindings;
10051006

1007+
function markBindingFromDerivedRecordMods
1008+
input output DAE.Binding bind;
1009+
algorithm
1010+
_ := match bind
1011+
case DAE.EQBOUND() algorithm
1012+
bind.source := DAE.BINDING_FROM_DERIVED_RECORD_DECL();
1013+
then ();
1014+
1015+
else ();
1016+
end match;
1017+
end markBindingFromDerivedRecordMods;
1018+
10061019
function varIsModifiedInDerivedMod
10071020
input String inName;
10081021
input SCode.SubMod inSubmod;

OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,8 +1616,11 @@ algorithm
16161616

16171617
if not listMember(name, rt_1) then
16181618
rt_1 := name :: rt_1;
1619-
vars := List.map(varlst, typesVar);
16201619
(accRecDecls, rt_1) := elaborateNestedRecordDeclarations(varlst, accRecDecls, rt_1);
1620+
1621+
varlst := List.map(varlst, simCodeVarRemoveBindFromOutside);
1622+
vars := List.map(varlst, typesVar);
1623+
// vars := List.map(vars, simCodeVarRemoveBindFromOutside);
16211624
recDecl := SimCodeFunction.RECORD_DECL_FULL(name, NONE(), path, vars);
16221625
accRecDecls := List.appendElt(recDecl, accRecDecls);
16231626
end if;
@@ -1712,6 +1715,19 @@ algorithm
17121715
end match;
17131716
end typesVar;
17141717

1718+
protected function simCodeVarRemoveBindFromOutside
1719+
input output DAE.Var var;
1720+
algorithm
1721+
_ := match (var)
1722+
case DAE.TYPES_VAR(binding = DAE.EQBOUND(source=DAE.BINDING_FROM_DERIVED_RECORD_DECL()))
1723+
then ();
1724+
case DAE.TYPES_VAR()
1725+
algorithm
1726+
var.bind_from_outside := false;
1727+
then ();
1728+
end match;
1729+
end simCodeVarRemoveBindFromOutside;
1730+
17151731
protected function checkSourceAndGetBindingExp
17161732
input DAE.Binding inBinding;
17171733
output Option<DAE.Exp> bindExp;

0 commit comments

Comments
 (0)