Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 9878b52

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fill in field names when converting records.
- Fill in the field names when converting record expressions to DAE, since the old ExpressionSimplify relies on them being present. Belonging to [master]: - #2478
1 parent 12e54e0 commit 9878b52

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ uniontype Class
547547
else node;
548548
end match;
549549
end lastBaseClass;
550+
550551
end Class;
551552

552553
annotation(__OpenModelica_Interface="frontend");

Compiler/NFFrontEnd/NFComplexType.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public
5555

5656
record RECORD
5757
InstNode constructor;
58+
list<String> fieldNames;
5859
end RECORD;
5960

6061
record EXTERNAL_OBJECT

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected
4242
import NFPrefixes.Variability;
4343
import Prefixes = NFPrefixes;
4444
import Ceval = NFCeval;
45+
import ComplexType = NFComplexType;
4546
import MetaModelica.Dangerous.listReverseInPlace;
4647

4748
public
@@ -1084,6 +1085,7 @@ public
10841085
DAE.Operator daeOp;
10851086
Boolean swap;
10861087
DAE.Exp dae1, dae2;
1088+
list<String> names;
10871089

10881090
case INTEGER() then DAE.ICONST(exp.value);
10891091
case REAL() then DAE.RCONST(exp.value);
@@ -1102,8 +1104,8 @@ public
11021104
then DAE.ARRAY(Type.toDAE(exp.ty), Type.isScalarArray(exp.ty),
11031105
list(toDAE(e) for e in exp.elements));
11041106

1105-
case RECORD()
1106-
then DAE.RECORD(exp.path, list(toDAE(e) for e in exp.elements), {}, Type.toDAE(exp.ty));
1107+
case RECORD(ty = Type.COMPLEX(complexTy = ComplexType.RECORD(fieldNames = names)))
1108+
then DAE.RECORD(exp.path, list(toDAE(e) for e in exp.elements), names, Type.toDAE(exp.ty));
11071109

11081110
case RANGE()
11091111
then DAE.RANGE(

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ algorithm
17961796
// Instantiate local equation/algorithm sections.
17971797
sections := instSections(node, scope, sections);
17981798

1799-
ty := makeComplexType(cls.restriction, node);
1799+
ty := makeComplexType(cls.restriction, node, cls);
18001800
inst_cls := Class.INSTANCED_CLASS(ty, cls.elements, sections, cls.restriction);
18011801
InstNode.updateClass(inst_cls, node);
18021802

@@ -1840,19 +1840,33 @@ end instExpressions;
18401840
function makeComplexType
18411841
input Restriction restriction;
18421842
input InstNode node;
1843+
input Class cls;
18431844
output Type ty;
18441845
protected
18451846
ComplexType cty;
18461847
algorithm
18471848
cty := match restriction
1848-
case Restriction.RECORD()
1849-
then ComplexType.RECORD(InstNode.classScope(InstNode.getDerivedNode(node)));
1849+
case Restriction.RECORD() then makeRecordComplexType(node, cls);
18501850
else ComplexType.CLASS();
18511851
end match;
18521852

18531853
ty := Type.COMPLEX(node, cty);
18541854
end makeComplexType;
18551855

1856+
function makeRecordComplexType
1857+
input InstNode node;
1858+
input Class cls;
1859+
output ComplexType ty;
1860+
protected
1861+
InstNode cls_node;
1862+
list<String> fields;
1863+
algorithm
1864+
cls_node := InstNode.classScope(InstNode.getDerivedNode(node));
1865+
fields := list(InstNode.name(c) for c guard not InstNode.isEmpty(c) in
1866+
ClassTree.getComponents(Class.classTree(cls)));
1867+
ty := ComplexType.RECORD(cls_node, fields);
1868+
end makeRecordComplexType;
1869+
18561870
function instComplexType
18571871
input Type ty;
18581872
algorithm

0 commit comments

Comments
 (0)