Skip to content

Commit

Permalink
[NB] update function alias in when and if (#11896)
Browse files Browse the repository at this point in the history
* [NB] update function alias in when and if

 - for now skip function alias creation inside when and if
 - future plans: collect conditions and create them

* [testsuite] model runs by hand but not on server

 - the model CombiTimeTable.mos runs and verifies if executed by hand, but not using rtest. are dependencies missing?
  • Loading branch information
kabdelhak committed Jan 29, 2024
1 parent cfdfeb8 commit fb3f6d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBFunctionAlias.mo
Expand Up @@ -119,6 +119,12 @@ protected
record CALL_ID
Expression call;
Iterator iter;
// ToDo: instead of skipping when and if, one could collect these conditions
// and create the function call equations with them.
// Note: update hashing, isEqual and take into account that there can be
// elseif/elsewhen which need to be chained
// Option<Expression> when_condition
// Option<Expression> if_condition
end CALL_ID;

function toString
Expand Down Expand Up @@ -316,12 +322,20 @@ protected
input Boolean init;
protected
Iterator iter;
Boolean stop;
algorithm
iter := match eq
case Equation.FOR_EQUATION() then eq.iter;
else Iterator.EMPTY();
(iter, stop) := match eq
local
Equation body;
case Equation.FOR_EQUATION(body = {body}) then (eq.iter, Equation.isWhenEquation(Pointer.create(body))
or Equation.isIfEquation(Pointer.create(body)));
case Equation.WHEN_EQUATION() then (Iterator.EMPTY(), true);
case Equation.IF_EQUATION() then (Iterator.EMPTY(), true);
else (Iterator.EMPTY(), false);
end match;
eq := Equation.map(eq, function introduceFunctionAlias(map = map, index = index, iter = iter, init = init));
if not stop then
eq := Equation.map(eq, function introduceFunctionAlias(map = map, index = index, iter = iter, init = init));
end if;
end introduceFunctionAliasEquation;

function introduceFunctionAlias
Expand Down
Expand Up @@ -29,6 +29,7 @@ SimpleAdvection.mos \
FAILINGTESTFILES = \
CombiTimeTable.mos \
TransmissionLineEquations.mos \
CombiTimeTable.mos \

# Dependency files that are not .mo .mos or Makefile
# Add them here or they will be cleaned.
Expand Down

0 comments on commit fb3f6d4

Please sign in to comment.