Skip to content

Commit

Permalink
[NB] various minor fixes (#11546)
Browse files Browse the repository at this point in the history
- events: set unset return expression in case
 - function alias: update hasSingleOrEmptyBody so it returns false for builtin always
 - multaries: only create multaries for integer, boolean and real
  • Loading branch information
kabdelhak committed Nov 9, 2023
1 parent 43dfd75 commit 1655a56
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
17 changes: 11 additions & 6 deletions OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBEvents.mo
Expand Up @@ -352,21 +352,21 @@ public
algorithm
(exp, bucket, failed) := match exp
local
Expression exp1, exp2, new_exp;
Expression exp1, exp2;
Boolean b1, b2;

case new_exp as Expression.LBINARY()
case Expression.LBINARY()
guard(Operator.getMathClassification(exp.operator) == NFOperator.MathClassification.LOGICAL)
algorithm
(exp1, bucket, b1) := create(exp.exp1, bucket, iter, eqn, funcTree, createAux);
(exp2, bucket, b2) := create(exp.exp2, bucket, iter, eqn, funcTree, createAux);
failed := (b1 or b2);
if not failed then
// we could simplify here
new_exp.exp1 := exp1;
new_exp.exp2 := exp2;
exp.exp1 := exp1;
exp.exp2 := exp2;
end if;
then (new_exp, bucket, failed);
then (exp, bucket, failed);

else createSingleOrSample(exp, bucket, iter, eqn, funcTree);
end match;
Expand Down Expand Up @@ -396,7 +396,7 @@ public
Solve.Status status;
Boolean invert, can_trigger;
Call call;
Expression trigger, new_exp = exp;
Expression trigger, new_exp;
TimeEvent timeEvent;
Pointer<Boolean> containsTime = Pointer.create(false);

Expand Down Expand Up @@ -436,6 +436,7 @@ public
else
// inside if can always trigger, keep the expression as is
can_trigger := true;
new_exp := exp;
end if;

// create and add the time event
Expand All @@ -450,9 +451,11 @@ public
failed := false;
else
failed := true;
new_exp := exp;
end if;
else
failed := true;
new_exp := exp;
end if;
then (new_exp, failed);

Expand Down Expand Up @@ -819,6 +822,8 @@ public
SOME(cev) := cev_opt;
if not BVariable.isDummyVariable(cev.auxiliary) then
exp := Expression.fromCref(BVariable.getVarName(cev.auxiliary));
else
exp := condition.exp;
end if;
else
if createAux then
Expand Down
7 changes: 4 additions & 3 deletions OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBFunctionAlias.mo
Expand Up @@ -408,10 +408,10 @@ protected
algorithm
b := not Inline.functionInlineable(fn)
and not Function.isSpecialBuiltin(fn)
and not inlineException(fn);
and not replaceException(fn);
end checkCallReplacement;

function inlineException
function replaceException
input Function fn;
output Boolean b;
protected
Expand All @@ -430,11 +430,12 @@ protected
else
b := match AbsynUtil.pathFirstIdent(path)
case "integer" then true;
case "String" then true;
else false;
end match;
end if;
end if;
end inlineException;
end replaceException;

function filterFrames
"filters the list of frames for all iterators that occure in exp"
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -2661,19 +2661,19 @@ protected

function hasSingleOrEmptyBody
input Function fn;
output Boolean b;
output Boolean b = false;
protected
list<Algorithm> algorithms;
algorithm
try
// InstNode.getSections can fail
if isBuiltin(fn) then return; end if;
b := match InstNode.getSections(fn.node)
case Sections.SECTIONS(algorithms = algorithms) then listLength(algorithms) < 2;
case Sections.EMPTY() then true;
else false;
end match;
else
b := false;
end try;
end hasSingleOrEmptyBody;

Expand Down
8 changes: 8 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFOperator.mo
Expand Up @@ -795,6 +795,14 @@ public
input Operator operator;
output Boolean b;
algorithm
b := match Type.arrayElementType(operator.ty)
case Type.INTEGER() then true;
case Type.REAL() then true;
case Type.BOOLEAN() then true;
else false;
end match;
if not b then return; end if;

b := match operator.op
case Op.ADD then true;
case Op.MUL then true;
Expand Down

0 comments on commit 1655a56

Please sign in to comment.