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

Commit a2b203f

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Evaluate more package constants in functions.
- Evaluate package constants in the children of function parameters too (e.g. in attributes of basic type function parameters). Belonging to [master]: - #2782
1 parent 13a4ae4 commit a2b203f

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ uniontype Component
432432
case UNTYPED_COMPONENT() then component.binding;
433433
case TYPED_COMPONENT() then component.binding;
434434
case TYPE_ATTRIBUTE() then Modifier.binding(component.modifier);
435+
else NFBinding.EMPTY_BINDING;
435436
end match;
436437
end getBinding;
437438

@@ -452,6 +453,11 @@ uniontype Component
452453
then
453454
();
454455

456+
case TYPE_ATTRIBUTE()
457+
algorithm
458+
component.modifier := Modifier.setBinding(binding, component.modifier);
459+
then
460+
();
455461
end match;
456462
end setBinding;
457463

Compiler/NFFrontEnd/NFEvalConstants.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,15 @@ algorithm
392392
end evaluateStmtBranch;
393393

394394
function evaluateFunction
395-
input Function func;
395+
input output Function func;
396396
protected
397397
Class cls;
398398
Algorithm fn_body;
399399
Sections sections;
400400
algorithm
401401
if not Function.isEvaluated(func) then
402402
Function.markEvaluated(func);
403-
Function.mapExp(func, evaluateFuncExp);
403+
func := Function.mapExp(func, evaluateFuncExp);
404404

405405
for fn_der in func.derivatives loop
406406
for der_fn in Function.getCachedFuncs(fn_der.derivativeFn) loop

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,11 +1503,13 @@ algorithm
15031503
end collectExpFuncs_traverse;
15041504

15051505
function flattenFunction
1506-
input Function fn;
1506+
input Function func;
15071507
input output FunctionTree funcs;
1508+
protected
1509+
Function fn = func;
15081510
algorithm
15091511
if not Function.isCollected(fn) then
1510-
EvalConstants.evaluateFunction(fn);
1512+
fn := EvalConstants.evaluateFunction(fn);
15111513
SimplifyModel.simplifyFunction(fn);
15121514
Function.collect(fn);
15131515

Compiler/NFFrontEnd/NFFunction.mo

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import Type = NFType;
3939
import NFPrefixes.*;
4040
import List;
4141
import FunctionDerivative = NFFunctionDerivative;
42+
import NFModifier.Modifier;
4243

4344
protected
4445
import ErrorExt;
@@ -1525,6 +1526,7 @@ uniontype Function
15251526
if mapParameters then
15261527
ctree := Class.classTree(cls);
15271528
ClassTree.applyComponents(ctree, function mapExpParameter(mapFn = mapFn));
1529+
fn.returnType := makeReturnType(fn);
15281530
end if;
15291531

15301532
if mapBody then
@@ -1544,6 +1546,7 @@ uniontype Function
15441546
protected
15451547
Component comp;
15461548
Binding binding, binding2;
1549+
Class cls;
15471550
algorithm
15481551
if not InstNode.isEmpty(node) then
15491552
comp := InstNode.component(node);
@@ -1554,6 +1557,13 @@ uniontype Function
15541557
comp := Component.setBinding(binding2, comp);
15551558
InstNode.updateComponent(comp, node);
15561559
end if;
1560+
1561+
if not Component.isTypeAttribute(comp) and
1562+
not Type.isEnumeration(Component.getType(comp)) then
1563+
cls := InstNode.getClass(Component.classInstance(comp));
1564+
ClassTree.applyComponents(Class.classTree(cls),
1565+
function mapExpParameter(mapFn = mapFn));
1566+
end if;
15571567
end if;
15581568
end mapExpParameter;
15591569

@@ -1867,7 +1877,7 @@ protected
18671877
end match;
18681878
end isValidParamState;
18691879

1870-
function makeReturnType
1880+
public function makeReturnType
18711881
input Function fn;
18721882
output Type returnType;
18731883
protected

0 commit comments

Comments
 (0)