Skip to content

Commit

Permalink
Handle record indexing better
Browse files Browse the repository at this point in the history
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]:
  - OpenModelica/OMCompiler#2093
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 4, 2018
1 parent 5aac106 commit d1104ce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 2 additions & 3 deletions Compiler/BackEnd/Differentiate.mo
Expand Up @@ -2119,7 +2119,7 @@ algorithm
case (e as DAE.CALL(path=path, expLst=expl, attr=attr), _, _, _, _) guard( Expression.isRecordCall(e, inFunctionTree))
equation
(dexpl, functions) = List.map3Fold(expl, function differentiateExp(maxIter=maxIter), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
then (DAE.CALL(path, dexpl, attr), functions);
then (DAE.CALL(path, dexpl, attr), functions);

//differentiate function partial
case (e, _, _, _, _)
Expand Down Expand Up @@ -2155,8 +2155,7 @@ algorithm
when differentiating.";
tp = Expression.typeof(inExp);
zero = Expression.createZeroExpression(tp);
then
(zero, inFunctionTree);
then (zero, inFunctionTree);

else
equation
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -4494,10 +4494,10 @@ algorithm
// record type
case DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(path)) equation
cr = DAE.CREF_IDENT("$TMP", inType, {});
crefs = ComponentReference.expandCref(cr, true);
typeLst = List.mapMap(crefs, crefExp, typeof);
typeLst = list(v.ty for v in varLst);
expLst = List.map(typeLst, createZeroExpression);
varNames = List.map(varLst, varName);
true = listLength(varNames) == listLength(expLst);
e = DAE.RECORD(path, expLst, varNames, inType);
then e;

Expand Down
11 changes: 11 additions & 0 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -310,8 +310,19 @@ algorithm
e := match e
local
DAE.ComponentRef cr;
Integer i;
list<DAE.Exp> exps;
list<String> comp;
Absyn.Path p1,p2;
DAE.Type ty;
list<DAE.Var> vars;
case (DAE.RSUB(exp=DAE.CREF(componentRef=cr), ix=-1))
then DAE.CREF(ComponentReference.joinCrefs(cr, ComponentReference.makeCrefIdent(e.fieldName, e.ty, {})), e.ty);
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))
guard Absyn.pathEqual(p1,p2)
then listGet(exps, List.position1OnTrue(list(v.name for v in vars), stringEq, e.fieldName));
case (DAE.RSUB(exp=DAE.RECORD(exps=exps,comp=comp), ix=-1))
then listGet(exps, List.position1OnTrue(comp, stringEq, e.fieldName));
else e;
end match;
end simplifyRSub;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -13330,7 +13330,7 @@ algorithm
case SimCodeVar.NEGATEDALIAS(varName=cref)
algorithm
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);
then fail();
then sv;
end match;
then sv;

Expand Down

0 comments on commit d1104ce

Please sign in to comment.