Skip to content

Commit

Permalink
Fix for #3212 and #3213:
Browse files Browse the repository at this point in the history
- Changed Expression.expandSubscript to use expandRange, so that it's able to
  also handle non-integer ranges.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25085 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Mar 13, 2015
1 parent 8cd1d4b commit a798a5f
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -11576,49 +11576,36 @@ public function expandSubscript
input DAE.Dimension inDimension;
output list<DAE.Subscript> outSubscripts;
algorithm
outSubscripts := match(inSubscript, inDimension)
outSubscripts := match inSubscript
local
DAE.Exp exp;

// An index subscript from range.
case (DAE.INDEX(exp = exp as DAE.RANGE()), _)
then getRangeContents(exp);
case DAE.INDEX(exp = DAE.RANGE())
then list(DAE.INDEX(e) for e in expandRange(inSubscript.exp));

// An index subscript from array.
// This really shouldn't be happening. But the backend creats things like this.
// e.g. When finding Incidence Matrix entry for for-loops in Algorithm sections.
// That whole creating IM should be done the way checkModel works. but it's not. :( so
// we have this.
case (DAE.INDEX(exp = exp as DAE.ARRAY()), _)
then expandSlice(exp);
case DAE.INDEX(exp = DAE.ARRAY())
then expandSlice(inSubscript.exp);

// An index subscript, return it as an array.
case (DAE.INDEX(), _) then {inSubscript};
case DAE.INDEX() then {inSubscript};

// A : subscript, use the dimension to generate all subscripts.
case (DAE.WHOLEDIM(), _)
case DAE.WHOLEDIM()
then expandDimension(inDimension);

// A slice subscript.
case (DAE.SLICE(exp = exp), _)
then expandSlice(exp);
case DAE.SLICE()
then expandSlice(inSubscript.exp);

end match;
end expandSubscript;

protected function getRangeContents
input DAE.Exp inExp;
output list<DAE.Subscript> outSubscripts;
protected
Integer istart, istep, istop;
Option<DAE.Exp> iostep;
algorithm
DAE.RANGE(DAE.T_INTEGER(), DAE.ICONST(istart), iostep,
DAE.ICONST(istop)) := inExp;
DAE.ICONST(istep) := Util.getOptionOrDefault(iostep, DAE.ICONST(1));
outSubscripts := intSubscripts(List.intRange3(istart, istep, istop));
end getRangeContents;

public function expandDimension
"Generates a list of subscripts given an array dimension."
input DAE.Dimension inDimension;
Expand Down Expand Up @@ -12052,6 +12039,8 @@ algorithm
end typeCastElements;

public function expandRange
"Expands a range expression into its elements:
expandRange(1:4) => {1, 2, 3, 4}"
input DAE.Exp inRange;
output list<DAE.Exp> outValues;
protected
Expand All @@ -12066,29 +12055,35 @@ algorithm
DAE.RANGE(start = start_exp, step = ostep_exp, stop = stop_exp) := inRange;

outValues := match (start_exp, stop_exp)
// An integer range, with or without a step value.
case (DAE.ICONST(), DAE.ICONST())
algorithm
DAE.ICONST(istep) := Util.getOptionOrDefault(ostep_exp, DAE.ICONST(1));
then
list(DAE.ICONST(i) for i in
List.intRange3(start_exp.integer, istep, stop_exp.integer));

// A real range, with or without a step value.
case (DAE.RCONST(), DAE.RCONST())
algorithm
DAE.RCONST(rstep) := Util.getOptionOrDefault(ostep_exp, DAE.RCONST(1.0));
then
list(DAE.RCONST(r) for r in
ExpressionSimplify.simplifyRangeReal(start_exp.real, rstep, stop_exp.real));

// false:true => {false, true}
case (DAE.BCONST(false), DAE.BCONST(true))
then {start_exp, stop_exp};

// true:false => {}
case (DAE.BCONST(true), DAE.BCONST(false))
then {};

// true:true => true, false:false => false
case (DAE.BCONST(), DAE.BCONST())
then {start_exp};

// An enumeration range, no step value allowed.
case (DAE.ENUM_LITERAL(), DAE.ENUM_LITERAL())
algorithm
if start_exp.index > stop_exp.index then
Expand Down

0 comments on commit a798a5f

Please sign in to comment.