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

Commit 4af9b08

Browse files
mahgeOpenModelica-Hudson
authored andcommitted
NFFrontEnd improvments
- Improved function call typing. - Vectorization - Record constructors
1 parent 6367803 commit 4af9b08

File tree

8 files changed

+772
-234
lines changed

8 files changed

+772
-234
lines changed

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ uniontype Component
232232
end match;
233233
end getBinding;
234234

235+
function hasBinding
236+
input Component component;
237+
output Boolean b;
238+
algorithm
239+
b := match getBinding(component)
240+
case UNBOUND() then false;
241+
else true;
242+
end match;
243+
end hasBinding;
244+
235245
function attr2DaeAttr
236246
input Attributes attr;
237247
output DAE.Attributes daeAttr;
@@ -278,6 +288,49 @@ uniontype Component
278288
else false;
279289
end match;
280290
end isOutput;
291+
292+
function variability
293+
input Component component;
294+
output DAE.VarKind variability;
295+
algorithm
296+
variability := match component
297+
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
298+
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
299+
else fail();
300+
end match;
301+
end variability;
302+
303+
function isConst
304+
input Component component;
305+
output Boolean isConst;
306+
algorithm
307+
isConst := match variability(component)
308+
case DAE.VarKind.CONST() then true;
309+
else false;
310+
end match;
311+
end isConst;
312+
313+
function visibility
314+
input Component component;
315+
output DAE.VarVisibility visibility;
316+
algorithm
317+
visibility := match component
318+
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(visibility = visibility)) then visibility;
319+
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(visibility = visibility)) then visibility;
320+
else fail();
321+
end match;
322+
end visibility;
323+
324+
function isPublic
325+
input Component component;
326+
output Boolean isInput;
327+
algorithm
328+
isInput := match visibility(component)
329+
case DAE.VarVisibility.PUBLIC() then true;
330+
else false;
331+
end match;
332+
end isPublic;
333+
281334
end Component;
282335

283336
annotation(__OpenModelica_Interface="frontend");

Compiler/NFFrontEnd/NFDimension.mo

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ public
148148
end match;
149149
end isEqual;
150150

151+
public function allEqual
152+
input list<Dimension> dims1;
153+
input list<Dimension> dims2;
154+
output Boolean allEqual;
155+
algorithm
156+
allEqual := match(dims1, dims2)
157+
local
158+
Dimension dim1, dim2;
159+
list<Dimension> rest1, rest2;
160+
161+
case ({}, {}) then true;
162+
case (dim1::rest1, dim2::rest2) guard isEqual(dim1, dim2)
163+
then allEqual(rest1, rest2);
164+
else false;
165+
end match;
166+
end allEqual;
167+
151168
function isEqualKnown
152169
input Dimension dim1;
153170
input Dimension dim2;

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import NFInstNode.InstNode;
3636
import NFPrefix.Prefix;
3737
import Operator = NFOperator;
3838
import Subscript = NFSubscript;
39+
import Dimension = NFDimension;
3940
import Type = NFType;
4041

4142
protected
@@ -105,6 +106,12 @@ uniontype Expression
105106
Expression stop;
106107
end RANGE;
107108

109+
record RECORD
110+
Absyn.Path path; // Maybe not needed since the type contains the name. Prefix?
111+
Type ty;
112+
list<Expression> elements;
113+
end RECORD;
114+
108115
record CALL
109116
Absyn.Path path;
110117
Expression cref "a pointer to the class of the function and the prefix, Expression.CREF";
@@ -513,6 +520,52 @@ uniontype Expression
513520
end match;
514521
end arrayElement;
515522

523+
function arrayFromList
524+
input list<Expression> inExps;
525+
input Type elemTy;
526+
input list<Dimension> inDims;
527+
output Expression outExp;
528+
algorithm
529+
outExp := arrayFromList_impl(inExps, elemTy, listReverse(inDims));
530+
end arrayFromList;
531+
532+
function arrayFromList_impl
533+
input list<Expression> inExps;
534+
input Type elemTy;
535+
input list<Dimension> inDims;
536+
output Expression outExp;
537+
protected
538+
Dimension ldim;
539+
list<Dimension> restdims;
540+
Type ty;
541+
list<Expression> newlst;
542+
list<list<Expression>> partexps;
543+
Integer dimsize;
544+
algorithm
545+
546+
assert(listLength(inDims) > 0, "Empty dimension list given in arrayFromList.");
547+
548+
ldim::restdims := inDims;
549+
dimsize := Dimension.size(ldim);
550+
ty := Type.liftArrayLeft(elemTy, ldim);
551+
552+
if listLength(inDims) == 1 then
553+
assert(dimsize == listLength(inExps), "Length mismatch in arrayFromList.");
554+
outExp := ARRAY(ty,inExps);
555+
return;
556+
end if;
557+
558+
partexps := List.partition(inExps, dimsize);
559+
560+
newlst := {};
561+
for arrexp in partexps loop
562+
newlst := ARRAY(ty,arrexp)::newlst;
563+
end for;
564+
565+
newlst := listReverse(newlst);
566+
outExp := arrayFromList(newlst, ty, restdims);
567+
end arrayFromList_impl;
568+
516569
function toInteger
517570
input Expression exp;
518571
output Integer i;
@@ -580,6 +633,7 @@ uniontype Expression
580633
dexp := match exp
581634
local
582635
Type ty;
636+
InstNode clsnode;
583637

584638
case INTEGER() then DAE.ICONST(exp.value);
585639
case REAL() then DAE.RCONST(exp.value);
@@ -595,6 +649,10 @@ uniontype Expression
595649
then DAE.ARRAY(Type.toDAE(exp.ty), Type.isScalarArray(exp.ty),
596650
list(toDAE(e) for e in exp.elements));
597651

652+
case RECORD()
653+
then DAE.RECORD(exp.path, list(toDAE(e) for e in exp.elements), {}, Type.toDAE(exp.ty));
654+
655+
598656
case RANGE()
599657
then DAE.RANGE(
600658
Type.toDAE(exp.ty),

0 commit comments

Comments
 (0)