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

Commit 72c299e

Browse files
committed
Handle inline where inputs are record fun-calls
Use DAE.RSUB() to handle general expressions. When doing inline of a function call, we can use DAE.RSUB instead of failing; previously we only handled component references passed to the call. Also added code generation and simplifications for DAE.RSUB since it was only used for MetaModelica previously. This fixes some of the issues raised in ticket:4423.
1 parent beb2a6b commit 72c299e

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

Compiler/FrontEnd/ExpressionSimplify.mo

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ algorithm
282282

283283
case (DAE.CALL(),_) then (simplifyCall(inExp),options);
284284

285+
case (DAE.RSUB(),_) then (simplifyRSub(inExp),options);
286+
285287
case (DAE.MATCHEXPRESSION(),_) then (simplifyMatch(inExp),options);
286288
case (DAE.UNBOX(),_) then (simplifyUnbox(inExp),options);
287289
case (DAE.BOX(),_) then (simplifyUnbox(inExp),options);
@@ -302,6 +304,18 @@ algorithm
302304
end match;
303305
end simplifyWork;
304306

307+
protected function simplifyRSub
308+
input output DAE.Exp e;
309+
algorithm
310+
e := match e
311+
local
312+
DAE.ComponentRef cr;
313+
case (DAE.RSUB(exp=DAE.CREF(componentRef=cr), ix=-1))
314+
then DAE.CREF(ComponentReference.joinCrefs(cr, ComponentReference.makeCrefIdent(e.fieldName, e.ty, {})), e.ty);
315+
else e;
316+
end match;
317+
end simplifyRSub;
318+
305319
protected function simplifyAsubExp
306320
input DAE.Exp origExp;
307321
input DAE.Exp inExp;

Compiler/FrontEnd/Inline.mo

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ public function replaceArgs
14241424
algorithm
14251425
(outExp,outTuple) := matchcontinue (inExp,inTuple)
14261426
local
1427-
DAE.ComponentRef cref;
1427+
DAE.ComponentRef cref, firstCref;
14281428
list<tuple<DAE.ComponentRef, DAE.Exp>> argmap;
14291429
DAE.Exp e;
14301430
Absyn.Path path;
@@ -1447,6 +1447,18 @@ algorithm
14471447
BaseHashTable.hasKey(ComponentReference.crefFirstCref(cref),checkcr)
14481448
then (inExp,(argmap,checkcr,false));
14491449

1450+
case (DAE.CREF(componentRef = cref),(argmap,checkcr,true))
1451+
algorithm
1452+
firstCref := ComponentReference.crefFirstCref(cref);
1453+
{} := ComponentReference.crefSubs(firstCref);
1454+
e := getExpFromArgMap(argmap,firstCref);
1455+
while not ComponentReference.crefIsIdent(cref) loop
1456+
cref := ComponentReference.crefRest(cref);
1457+
{} := ComponentReference.crefSubs(cref);
1458+
e := DAE.RSUB(e, -1, ComponentReference.crefFirstIdent(cref), ComponentReference.crefType(cref));
1459+
end while;
1460+
then (e,inTuple);
1461+
14501462
case (DAE.CREF(componentRef = cref),(argmap,checkcr,true))
14511463
equation
14521464
getExpFromArgMap(argmap,ComponentReference.crefStripSubs(ComponentReference.crefFirstCref(cref)));

Compiler/Template/CodegenCFunctions.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3699,6 +3699,7 @@ template expTypeFromExpFlag(Exp exp, Integer flag)
36993699
case e as CONS(__)
37003700
case e as LIST(__)
37013701
case e as SIZE(__) then expTypeFlag(typeof(e), flag)
3702+
case c as RSUB(ix=-1) then expTypeFlag(c.ty, flag)
37023703

37033704
case META_TUPLE(__)
37043705
case META_OPTION(__)
@@ -6246,6 +6247,9 @@ template daeExpRsub(Exp inExp, Context context, Text &preExp,
62466247
"Generates code for an tsub expression."
62476248
::=
62486249
match inExp
6250+
case RSUB(ix=-1) then
6251+
let res = daeExp(exp, context, &preExp, &varDecls, &auxFunction)
6252+
'<%res%>._<%fieldName%>'
62496253
case RSUB(__) then
62506254
let res = daeExp(exp, context, &preExp, &varDecls, &auxFunction)
62516255
let offset = intAdd(ix,1) // 1-based

Compiler/Template/CodegenCppCommon.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,22 @@ template daeExp(Exp exp, Context context, Text &preExp /*BUFP*/, Text &varDecls
973973
case e as PARTEVALFUNCTION(__)then daeExpPartEvalFunction(e, context, &preExp, &varDecls, simCode , &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
974974
case e as BOX(__) then daeExpBox(e, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
975975
case e as UNBOX(__) then daeExpUnbox(e, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
976+
case e as RSUB(__) then daeExpRSub(e, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
976977

977978
else error(sourceInfo(), 'Unknown exp:<%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
978979
end daeExp;
979980

981+
template daeExpRSub(Exp exp, Context context, Text &preExp, Text &varDecls, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl,
982+
Text extraFuncsNamespace, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)
983+
"Generates code for an tsub expression."
984+
::=
985+
match exp
986+
case RSUB(ix=-1) then
987+
let res = daeExp(exp, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
988+
'<%res%>.<%fieldName%>_'
989+
case RSUB(__) then
990+
error(sourceInfo(), '<%ExpressionDumpTpl.dumpExp(exp,"\"")%>: failed')
991+
end daeExpRSub;
980992

981993
template daeExpRange(Exp exp, Context context, Text &preExp, Text &varDecls, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl,
982994
Text extraFuncsNamespace, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)

0 commit comments

Comments
 (0)