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

Commit 407a017

Browse files
mahgeOpenModelica-Hudson
authored andcommitted
[NF][#4784] Fix conversion of complex types to old DAE.
- Create proper DAE.TYPES_VAR for complex types. - create DAE complex equation for complex equations - until we start scalarizing complex equations. Belonging to [master]: - #2266
1 parent a134d4e commit 407a017

File tree

5 files changed

+121
-2
lines changed

5 files changed

+121
-2
lines changed

Compiler/NFFrontEnd/NFBinding.mo

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,25 @@ public
250250
end match;
251251
end isEqual;
252252

253+
function toDAE
254+
input Binding b;
255+
output DAE.Binding outb;
256+
algorithm
257+
outb := match b
258+
case UNBOUND() then DAE.UNBOUND();
259+
case TYPED_BINDING()
260+
then DAE.EQBOUND(Expression.toDAE(b.bindingExp)
261+
, NONE()
262+
, Variability.variabilityToDAEConst(b.variability)
263+
, DAE.BINDING_FROM_DEFAULT_VALUE() // TODO: revise this.
264+
);
265+
266+
else algorithm
267+
Error.assertion(false, getInstanceName() + " got untyped binding.", sourceInfo());
268+
then fail();
269+
270+
end match;
271+
end toDAE;
272+
253273
annotation(__OpenModelica_Interface="frontend");
254274
end NFBinding;

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ constant Component.Attributes DISCRETE_ATTR =
9595

9696
uniontype Component
9797
uniontype Attributes
98+
import SCode;
99+
98100
record ATTRIBUTES
99101
// adrpo: keep the order in DAE.ATTR
100102
ConnectorType connectorType;
@@ -103,6 +105,19 @@ uniontype Component
103105
Direction direction;
104106
InnerOuter innerOuter;
105107
end ATTRIBUTES;
108+
109+
function toDAE
110+
input Attributes ina;
111+
output DAE.Attributes outa;
112+
algorithm
113+
outa := DAE.ATTR(connectorTypeToDAE(ina.connectorType)
114+
, parallelismToSCode(ina.parallelism)
115+
, variabilityToSCode(ina.variability)
116+
, directionToAbsyn(ina.direction)
117+
, innerOuterToAbsyn(ina.innerOuter)
118+
, SCode.PUBLIC() // TODO: Use the actual visibility.
119+
);
120+
end toDAE;
106121
end Attributes;
107122

108123
record COMPONENT_DEF

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import Util;
5757
import MetaModelica.Dangerous.listReverseInPlace;
5858
import Sections = NFSections;
5959
import Function = NFFunction.Function;
60-
import ClassTree = NFClassTree;
60+
import NFClassTree.ClassTree;
6161
import NFPrefixes.Visibility;
6262
import NFPrefixes.Direction;
6363
import Variable = NFVariable;
@@ -453,6 +453,13 @@ algorithm
453453
list<DAE.Dimension> dims;
454454
list<DAE.Element> body;
455455

456+
case Equation.EQUALITY() guard Type.isComplex(eq.ty)
457+
algorithm
458+
e1 := Expression.toDAE(eq.lhs);
459+
e2 := Expression.toDAE(eq.rhs);
460+
then
461+
DAE.Element.COMPLEX_EQUATION(e1, e2, eq.source) :: elements;
462+
456463
case Equation.EQUALITY()
457464
algorithm
458465
e1 := Expression.toDAE(eq.lhs);
@@ -1027,5 +1034,46 @@ algorithm
10271034
end match;
10281035
end convertExternalDeclOutput;
10291036

1037+
public
1038+
function makeTypesVars
1039+
input Type complex_ty;
1040+
output list<DAE.Var> type_vars;
1041+
protected
1042+
InstNode cls_node;
1043+
Component comp;
1044+
DAE.Var type_var;
1045+
algorithm
1046+
Type.COMPLEX(cls = cls_node) := complex_ty;
1047+
type_vars := {};
1048+
1049+
() := match cls as InstNode.getClass(cls_node)
1050+
case Class.INSTANCED_CLASS(elements = ClassTree.FLAT_TREE()) algorithm
1051+
1052+
for c in ClassTree.getComponents(cls.elements) loop
1053+
if InstNode.isOnlyOuter(c) or InstNode.isEmpty(c) then
1054+
continue;
1055+
end if;
1056+
comp := InstNode.component(InstNode.resolveOuter(c));
1057+
InstNode.name(c);
1058+
1059+
type_var := DAE.TYPES_VAR(InstNode.name(c)
1060+
, Component.Attributes.toDAE(Component.getAttributes(comp))
1061+
, Type.toDAE(Component.getType(comp))
1062+
, Binding.toDAE(Component.getBinding(comp))
1063+
,NONE()
1064+
);
1065+
type_vars := type_var::type_vars;
1066+
end for;
1067+
1068+
type_vars := listReverse(type_vars);
1069+
then ();
1070+
1071+
else ();
1072+
1073+
end match;
1074+
1075+
end makeTypesVars;
1076+
1077+
10301078
annotation(__OpenModelica_Interface="frontend");
10311079
end NFConvertDAE;

Compiler/NFFrontEnd/NFPrefixes.mo

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ algorithm
131131
end match;
132132
end parallelismFromSCode;
133133

134+
function parallelismToSCode
135+
input Parallelism par;
136+
output SCode.Parallelism scodePar;
137+
algorithm
138+
scodePar := match par
139+
case Parallelism.GLOBAL then SCode.Parallelism.PARGLOBAL();
140+
case Parallelism.LOCAL then SCode.Parallelism.PARLOCAL() ;
141+
case Parallelism.NON_PARALLEL then SCode.Parallelism.NON_PARALLEL() ;
142+
end match;
143+
end parallelismToSCode;
144+
134145
function parallelismToDAE
135146
input Parallelism par;
136147
output DAE.VarParallelism dpar;
@@ -182,6 +193,18 @@ algorithm
182193
end match;
183194
end variabilityFromSCode;
184195

196+
function variabilityToSCode
197+
input Variability var;
198+
output SCode.Variability scodeVar;
199+
algorithm
200+
scodeVar := match var
201+
case Variability.CONSTANT then SCode.CONST();
202+
case Variability.PARAMETER then SCode.PARAM();
203+
case Variability.DISCRETE then SCode.DISCRETE();
204+
case Variability.CONTINUOUS then SCode.VAR();
205+
end match;
206+
end variabilityToSCode;
207+
185208
function variabilityToDAE
186209
input Variability var;
187210
input Type ty;
@@ -318,6 +341,18 @@ algorithm
318341
end match;
319342
end innerOuterFromSCode;
320343

344+
function innerOuterToAbsyn
345+
input InnerOuter inIO;
346+
output Absyn.InnerOuter outIO;
347+
algorithm
348+
outIO := match inIO
349+
case InnerOuter.NOT_INNER_OUTER then Absyn.NOT_INNER_OUTER();
350+
case InnerOuter.INNER then Absyn.INNER();
351+
case InnerOuter.OUTER then Absyn.OUTER();
352+
case InnerOuter.INNER_OUTER then Absyn.INNER_OUTER();
353+
end match;
354+
end innerOuterToAbsyn;
355+
321356
function innerOuterString
322357
input InnerOuter io;
323358
output String str;

Compiler/NFFrontEnd/NFType.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public
3939
import NFInstNode.InstNode;
4040
import Subscript = NFSubscript;
4141
import ComplexType = NFComplexType;
42+
import ConvertDAE = NFConvertDAE;
4243

4344
record INTEGER
4445
end INTEGER;
@@ -515,7 +516,7 @@ public
515516
case Type.UNKNOWN() then DAE.T_UNKNOWN_DEFAULT;
516517
case Type.COMPLEX()
517518
// TODO: Use proper ClassInf.State here.
518-
then DAE.Type.T_COMPLEX(ClassInf.MODEL(InstNode.scopePath(ty.cls)), {}, NONE());
519+
then DAE.Type.T_COMPLEX(ClassInf.MODEL(InstNode.scopePath(ty.cls)), ConvertDAE.makeTypesVars(ty), NONE());
519520
case Type.POLYMORPHIC() then DAE.T_METAPOLYMORPHIC(ty.name);
520521
case Type.ANY() then DAE.T_ANYTYPE(NONE());
521522
else

0 commit comments

Comments
 (0)