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

Commit

Permalink
Expand arrays in record when generating simcode
Browse files Browse the repository at this point in the history
This avoids a problem with generating scalar assignments for arrays in
a record variable in simulation context (code generation fails).
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jul 19, 2017
1 parent 49a3767 commit f50884b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -11946,6 +11946,18 @@ algorithm
end makeVectorCall;


public function expandCrefs
input output DAE.Exp exp;
input output Integer dummy=0 "For traversal";
algorithm
exp := match exp
local
DAE.Type ty;
case DAE.CREF(ty=DAE.T_ARRAY(ty=ty)) then makeArray(list(makeCrefExp(cr, ty) for cr in ComponentReference.expandCref(exp.componentRef, true)), exp.ty, not Types.isArray(ty));
else exp;
end match;
end expandCrefs;

public function expandExpression
" mahge:
Expands a given expression to a list of expression. this means flattening any records in the
Expand Down
2 changes: 2 additions & 0 deletions Compiler/SimCode/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5997,6 +5997,7 @@ algorithm
// check all crefs are on the lhs
ht = HashSet.emptyHashSet();
ht = List.fold(crefs, BaseHashSet.add, ht);
expLst = Expression.traverseExpList(expLst, Expression.expandCrefs, 0) "The routines generate bad code for arrays inside the record unless we expand them";
List.foldAllValue(expLst, createSingleComplexEqnCode3, true, ht);
(e2_1, _) = Expression.extendArrExp(e2, false);

Expand Down Expand Up @@ -6027,6 +6028,7 @@ algorithm
// check all crefs are on the rhs => turn
ht = HashSet.emptyHashSet();
ht = List.fold(crefs, BaseHashSet.add, ht);
expLst = Expression.traverseExpList(expLst, Expression.expandCrefs, 0) "The routines generate bad code for arrays inside the record unless we expand them";
List.foldAllValue(expLst, createSingleComplexEqnCode3, true, ht);
(e1_1, _) = Expression.extendArrExp(e1, false);
// true = ComponentReference.crefEqualNoStringCompare(cr, cr2);
Expand Down

0 comments on commit f50884b

Please sign in to comment.