Skip to content

Commit

Permalink
Fix for bug #1825:
Browse files Browse the repository at this point in the history
- Made handling of real ranges a bit more robust.
- Moved some scodeinst tests to failing tests.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13016 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 21, 2012
1 parent eff6aa5 commit a3d71e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 43 deletions.
47 changes: 17 additions & 30 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -4275,10 +4275,11 @@ algorithm
outValues := matchcontinue(inStart, inStep, inStop)
local
String error_str;
Integer steps;

case (_, _, _)
equation
equality(inStep = 0.0);
true = realAbs(inStep) <=. 1e-14;
error_str = stringDelimitList(
List.map({inStart, inStep, inStop}, realString), ":");
Error.addMessage(Error.ZERO_STEP_IN_ARRAY_CONSTRUCTOR, {error_str});
Expand All @@ -4290,54 +4291,40 @@ algorithm
equality(inStart = inStop);
then {inStart};

case (_, _, _)
else
equation
true = (inStep >. 0.0);
then simplifyRangeReal2(inStart, inStep, inStop, realGt, {});
steps = Util.realRangeSize(inStart, inStep, inStop) - 1;
then
simplifyRangeReal2(inStart, inStep, steps, {});

case (_, _, _)
equation
true = (inStep <. 0.0);
then simplifyRangeReal2(inStart, inStep, inStop, realLt, {});
end matchcontinue;
end simplifyRangeReal;

protected function simplifyRangeReal2
"Helper function to cevalRangeReal."
"Helper function to simplifyRangeReal."
input Real inStart;
input Real inStep;
input Real inStop;
input CompFunc compFunc;
input Integer inSteps;
input list<Real> inValues;
output list<Real> outValues;

partial function CompFunc
input Real inValue1;
input Real inValue2;
output Boolean outRes;
end CompFunc;
algorithm
outValues := matchcontinue(inStart, inStep, inStop, compFunc, inValues)
outValues := match(inStart, inStep, inSteps, inValues)
local
Real next;
list<Real> vals;

case (_, _, _, _, _)
equation
true = compFunc(inStart, inStop);
then
listReverse(inValues);
case (_, _, -1, _) then inValues;

case (_, _, _, _, _)
else
equation
next = inStart +. inStep;
vals = inStart :: inValues;
vals = simplifyRangeReal2(next, inStep, inStop, compFunc, vals);
next = inStart +. inStep *. intReal(inSteps);
vals = next :: inValues;
then
vals;
end matchcontinue;
simplifyRangeReal2(inStart, inStep, inSteps - 1, vals);

end match;
end simplifyRangeReal2;

protected function simplifyReduction
input DAE.Exp inReduction;
input Boolean b;
Expand Down
15 changes: 2 additions & 13 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -2138,22 +2138,11 @@ algorithm
dim;

case (Values.REAL(real_start), NONE(), Values.REAL(real_stop))
equation
r = real_stop -. real_start;
r = realFloor(r);
dim = realInt(r) + 1;
then
dim;
then Util.realRangeSize(real_start, 1.0, real_stop);

case (Values.REAL(real_start), SOME(Values.REAL(real_step)),
Values.REAL(real_stop))
equation
r = real_stop -. real_start;
r = realDiv(r, real_step);
r = realFloor(r);
dim = realInt(r) + 1;
then
dim;
then Util.realRangeSize(real_start, real_step, real_stop);

case (Values.ENUM_LITERAL(index = int_start), NONE(),
Values.ENUM_LITERAL(index = int_stop))
Expand Down
11 changes: 11 additions & 0 deletions Compiler/Util/Util.mo
Expand Up @@ -3498,4 +3498,15 @@ algorithm
end match;
end swap;

public function realRangeSize
"Calculates the size of a Real range given the start, step and stop values."
input Real inStart;
input Real inStep;
input Real inStop;
output Integer outSize;
algorithm
outSize := realInt(realFloor(((inStop -. inStart) /. inStep) +. 5e-15)) + 1;
outSize := intMax(outSize, 0);
end realRangeSize;

end Util;

0 comments on commit a3d71e7

Please sign in to comment.