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

Commit

Permalink
[NF] Fix Expression.makeSubscriptedExp.
Browse files Browse the repository at this point in the history
- Merge subscripts properly in makeSubscriptedExp instead of just
  concatenating them.

Belonging to [master]:
  - #2630
  • Loading branch information
perost authored and OpenModelica-Hudson committed Sep 4, 2018
1 parent 9aaad99 commit 7d0f654
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -971,22 +971,22 @@ public
output Expression outExp;
protected
Expression e;
list<Subscript> subs;
list<Subscript> subs, extra_subs;
Type ty;
list<Dimension> dims, accum_dims;
Dimension dim;
Integer dim_count;
algorithm
// If the expression is already a SUBSCRIPTED_EXP we need to concatenate the
// old subscripts with the new. Otherwise we just create a new SUBSCRIPTED_EXP.
(e, subs, ty) := match exp
case SUBSCRIPTED_EXP() then (exp.exp, listAppend(exp.subscripts, subscripts), Expression.typeOf(exp.exp));
else (exp, subscripts, Expression.typeOf(exp));
case SUBSCRIPTED_EXP() then (exp.exp,exp.subscripts, Expression.typeOf(exp.exp));
else (exp, {}, Expression.typeOf(exp));
end match;

dims := Type.arrayDims(ty);
dim_count := Type.dimensionCount(ty);
(subs, extra_subs) := Subscript.mergeList(subscripts, subs, dim_count);

// Check that the expression has enough dimensions to be subscripted.
if listLength(dims) < listLength(subs) then
if not listEmpty(extra_subs) then
Error.assertion(false, getInstanceName() + ": too few dimensions in " +
Expression.toString(exp) + " to apply subscripts " + Subscript.toStringList(subscripts), sourceInfo());
end if;
Expand Down

3 comments on commit 7d0f654

@casella
Copy link

@casella casella commented on 7d0f654 Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@perost, after this commit the net number of improvements is 109+225-324=10, which is positive but not very large. Were you expecting a more substantial improvement?

@perost
Copy link
Member Author

@perost perost commented on 7d0f654 Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casella: The main goal was to fix the subscripting code so that it can handle multiple subscripts and do slicing correctly, because that's needed for the function evaluation among other things. I thought it might fix a bit more models than that, but it was a necessary change regardless.

@casella
Copy link

@casella casella commented on 7d0f654 Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@perost: OK. Good luck then!

Please sign in to comment.