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

Commit d1104ce

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Handle record indexing better
Simplify record constructor calls with record indexing. Also, handle construction of zero records better (array components were flattened before, resulting in additional arguments to the constructor). Belonging to [master]: - #2093
1 parent 5aac106 commit d1104ce

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

Compiler/BackEnd/Differentiate.mo

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,7 @@ algorithm
21192119
case (e as DAE.CALL(path=path, expLst=expl, attr=attr), _, _, _, _) guard( Expression.isRecordCall(e, inFunctionTree))
21202120
equation
21212121
(dexpl, functions) = List.map3Fold(expl, function differentiateExp(maxIter=maxIter), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
2122-
then (DAE.CALL(path, dexpl, attr), functions);
2122+
then (DAE.CALL(path, dexpl, attr), functions);
21232123

21242124
//differentiate function partial
21252125
case (e, _, _, _, _)
@@ -2155,8 +2155,7 @@ algorithm
21552155
when differentiating.";
21562156
tp = Expression.typeof(inExp);
21572157
zero = Expression.createZeroExpression(tp);
2158-
then
2159-
(zero, inFunctionTree);
2158+
then (zero, inFunctionTree);
21602159

21612160
else
21622161
equation

Compiler/FrontEnd/Expression.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,10 +4494,10 @@ algorithm
44944494
// record type
44954495
case DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(path)) equation
44964496
cr = DAE.CREF_IDENT("$TMP", inType, {});
4497-
crefs = ComponentReference.expandCref(cr, true);
4498-
typeLst = List.mapMap(crefs, crefExp, typeof);
4497+
typeLst = list(v.ty for v in varLst);
44994498
expLst = List.map(typeLst, createZeroExpression);
45004499
varNames = List.map(varLst, varName);
4500+
true = listLength(varNames) == listLength(expLst);
45014501
e = DAE.RECORD(path, expLst, varNames, inType);
45024502
then e;
45034503

Compiler/FrontEnd/ExpressionSimplify.mo

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,19 @@ algorithm
310310
e := match e
311311
local
312312
DAE.ComponentRef cr;
313+
Integer i;
314+
list<DAE.Exp> exps;
315+
list<String> comp;
316+
Absyn.Path p1,p2;
317+
DAE.Type ty;
318+
list<DAE.Var> vars;
313319
case (DAE.RSUB(exp=DAE.CREF(componentRef=cr), ix=-1))
314320
then DAE.CREF(ComponentReference.joinCrefs(cr, ComponentReference.makeCrefIdent(e.fieldName, e.ty, {})), e.ty);
321+
case (DAE.RSUB(exp=DAE.CALL(path=p1, expLst=exps, attr=DAE.CALL_ATTR(ty=DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path=p2), varLst=vars))), ix=-1))
322+
guard Absyn.pathEqual(p1,p2)
323+
then listGet(exps, List.position1OnTrue(list(v.name for v in vars), stringEq, e.fieldName));
324+
case (DAE.RSUB(exp=DAE.RECORD(exps=exps,comp=comp), ix=-1))
325+
then listGet(exps, List.position1OnTrue(comp, stringEq, e.fieldName));
315326
else e;
316327
end match;
317328
end simplifyRSub;

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13330,7 +13330,7 @@ algorithm
1333013330
case SimCodeVar.NEGATEDALIAS(varName=cref)
1333113331
algorithm
1333213332
Error.addSourceMessage(Error.INTERNAL_ERROR, {getInstanceName() + " got a negated alias variable " + ComponentReference.printComponentRefStr(inCref) + " to " + ComponentReference.printComponentRefStr(cref) + ", but before code generation these should have been removed"}, sv.source.info);
13333-
then fail();
13333+
then sv;
1333413334
end match;
1333513335
then sv;
1333613336

0 commit comments

Comments
 (0)