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

Commit 338d1df

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve constant evaluation.
- Implemented evaluation of more operators and expressions. - Implemented evaluation of the String function. - Added Expression.contains utility function. - Improved unrolling of for equations. - Added System.sprintff to print Real values of any size. Belonging to [master]: - #2398 - OpenModelica/OpenModelica-testsuite#934
1 parent 2718416 commit 338d1df

File tree

13 files changed

+1317
-133
lines changed

13 files changed

+1317
-133
lines changed

Compiler/NFFrontEnd/NFBinding.mo

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,43 @@ public
159159
end match;
160160
end setTypedExp;
161161

162+
function getExp
163+
input Binding binding;
164+
output Expression exp;
165+
algorithm
166+
exp := match binding
167+
case UNTYPED_BINDING() then binding.bindingExp;
168+
case TYPED_BINDING() then binding.bindingExp;
169+
case FLAT_BINDING() then binding.bindingExp;
170+
end match;
171+
end getExp;
172+
173+
function setExp
174+
input Expression exp;
175+
input output Binding binding;
176+
algorithm
177+
() := match binding
178+
case UNTYPED_BINDING()
179+
algorithm
180+
binding.bindingExp := exp;
181+
then
182+
();
183+
184+
case TYPED_BINDING()
185+
algorithm
186+
binding.bindingExp := exp;
187+
then
188+
();
189+
190+
case FLAT_BINDING()
191+
algorithm
192+
binding.bindingExp := exp;
193+
then
194+
();
195+
196+
end match;
197+
end setExp;
198+
162199
function isRecordExp
163200
input Binding binding;
164201
output Boolean isRecordExp;

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,25 +339,22 @@ uniontype Call
339339
input list<Absyn.ForIterator> inIters;
340340
input InstNode scope;
341341
input SourceInfo info;
342-
output InstNode iter_scope;
343-
output list<InstNode> outIters;
342+
output InstNode outScope = scope;
343+
output list<InstNode> outIters = {};
344344
protected
345345
Binding binding;
346346
InstNode iter;
347347
algorithm
348-
outIters := {};
349-
iter_scope := scope;
350-
for Absiter in inIters loop
351-
binding := Binding.fromAbsyn(Absiter.range, false, 0, iter_scope, info);
348+
for i in inIters loop
349+
binding := Binding.fromAbsyn(i.range, false, 0, outScope, info);
352350
binding := Inst.instBinding(binding);
353-
(iter_scope, iter) := Inst.addIteratorToScope(Absiter.name, binding, iter_scope);
354-
outIters := iter::outIters;
351+
(outScope, iter) := Inst.addIteratorToScope(i.name, binding, outScope, info);
352+
outIters := iter :: outIters;
355353
end for;
356354

357355
outIters := listReverse(outIters);
358356
end instIterators;
359357

360-
361358
function builtinSpecialHandling
362359
input Call call;
363360
output Boolean special;
@@ -503,7 +500,7 @@ uniontype Call
503500
case UNTYPED_MAP_CALL() algorithm
504501

505502
for iter in call.iters loop
506-
Typing.typeIterator(iter, info, ExpOrigin.FUNCTION, structural = false);
503+
Typing.typeIterator(iter, ExpOrigin.FUNCTION, structural = false);
507504
end for;
508505
(arg, arg_ty, arg_var) := Typing.typeExp(call.exp, origin, info);
509506

@@ -678,7 +675,7 @@ uniontype Call
678675
bind := Binding.TYPED_BINDING(exp, ty, Variability.CONSTANT, origin, false);
679676

680677
// Add an iterator to the call scope.
681-
(iter_scope, iter) := Inst.addIteratorToScope("$i" + intString(i), bind, iter_scope, Type.INTEGER());
678+
(iter_scope, iter) := Inst.addIteratorToScope("$i" + intString(i), bind, iter_scope, info, Type.INTEGER());
682679
iters := iter::iters;
683680

684681
// Now that iterator is ready apply it, as a subscript, to each argument that is supposed to be vectorized
@@ -2181,8 +2178,7 @@ protected
21812178
if variability > Variability.PARAMETER then
21822179
Error.addSourceMessageAndFail(Error.NF_CAT_FIRST_ARG_EVAL, {Expression.toString(arg), Prefixes.variabilityString(variability)}, info);
21832180
end if;
2184-
arg := Ceval.evalExp(arg, Ceval.EvalTarget.GENERIC(info));
2185-
Expression.INTEGER(n) := SimplifyExp.simplifyExp(arg);
2181+
Expression.INTEGER(n) := Ceval.evalExp(arg, Ceval.EvalTarget.GENERIC(info));
21862182

21872183
res := {};
21882184
tys := {};

0 commit comments

Comments
 (0)