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

Commit 38fd61a

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Various fixes.
- Unpack input arrays that have been packed after an external call. - Fix ordering of initial algorithm sections. - Type cast the branches of an if-expression instead of the whole expression. - Fix expansion of cast expressions. Belonging to [master]: - #2906 - OpenModelica/OpenModelica-testsuite#1116
1 parent 9a35199 commit 38fd61a

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ function convertInitialAlgorithms
875875
input list<Algorithm> algorithms;
876876
input output list<DAE.Element> elements;
877877
algorithm
878-
for alg in algorithms loop
878+
for alg in listReverse(algorithms) loop
879879
elements := convertInitialAlgorithm(alg, elements);
880880
end for;
881881
end convertInitialAlgorithms;

Compiler/NFFrontEnd/NFExpandExp.mo

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,11 @@ public
943943
input Type ty;
944944
output Expression outExp;
945945
output Boolean expanded;
946-
protected
947-
Type ety = Type.arrayElementType(ty);
948946
algorithm
949947
(outExp, expanded) := expand(exp);
950948

951949
if expanded then
952-
outExp := Expression.mapArrayElements(outExp, function Expression.typeCast(castTy = ety));
950+
outExp := Expression.typeCastElements(outExp, ty);
953951
else
954952
outExp := exp;
955953
end if;

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ public
817817
algorithm
818818
exp := match (exp, ty)
819819
local
820-
Type t;
820+
Type t, ety;
821821
list<Expression> el;
822822

823823
case (INTEGER(), Type.REAL())
@@ -827,14 +827,20 @@ public
827827

828828
case (ARRAY(ty = t, elements = el), _)
829829
algorithm
830-
el := list(typeCastElements(e, ty) for e in el);
830+
ety := Type.arrayElementType(ty);
831+
el := list(typeCastElements(e, ety) for e in el);
831832
t := Type.setArrayElementType(t, ty);
832833
then
833834
ARRAY(t, el, exp.literal);
834835

835836
case (UNARY(), _)
836837
then UNARY(exp.operator, typeCastElements(exp.exp, ty));
837838

839+
case (IF(), _)
840+
then IF(exp.condition,
841+
typeCastElements(exp.trueBranch, ty),
842+
typeCastElements(exp.falseBranch, ty));
843+
838844
else
839845
algorithm
840846
t := typeOf(exp);

Compiler/Template/CodegenCFunctions.tpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ template extFunCallVardecl(SimExtArg arg, Text &varDecls, Text &auxFunction, Boo
21932193
case SIMEXTARG(isInput = true, isArray = true, type_ = ty, cref = c) then
21942194
match expTypeShort(ty)
21952195
case "integer" then
2196-
'pack_integer_array(&<%contextCref(c,contextFunction,&auxFunction)%>);'
2196+
'pack_integer_array(&<%contextCref(c,contextFunction,&auxFunction)%>);<%\n%>'
21972197
else ""
21982198
case SIMEXTARG(isInput = false, isArray = true, type_ = ty, cref = c) then
21992199
match expTypeShort(ty)
@@ -2315,6 +2315,12 @@ template extFunCallVarcopy(SimExtArg arg, Text &auxFunction)
23152315
"Helper to extFunCall."
23162316
::=
23172317
match arg
2318+
case SIMEXTARG(isInput = true, isArray = true, type_ = ty, cref = c) then
2319+
// Inputs that have been packed should be unpacked after the external call.
2320+
match expTypeShort(ty)
2321+
case "integer" then
2322+
'unpack_integer_array(&<%contextCref(c,contextFunction,&auxFunction)%>);'
2323+
else ""
23182324
case SIMEXTARG(outputIndex=0) then ""
23192325
case SIMEXTARG(outputIndex=oi, isArray=true, cref=c, type_=ty) then
23202326
match expTypeShort(ty)

0 commit comments

Comments
 (0)