Skip to content

Commit

Permalink
[NF] Fix tuple calls in builtins and reductions.
Browse files Browse the repository at this point in the history
- Fix the origin for arguments of special builtin calls and
  reductions/array constructors so that tuple calls are handled
  correctly.

Belonging to [master]:
  - OpenModelica/OMCompiler#2946
  • Loading branch information
perost authored and OpenModelica-Hudson committed Feb 26, 2019
1 parent a44d71c commit c4e03c8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 44 deletions.
84 changes: 43 additions & 41 deletions Compiler/NFFrontEnd/NFBuiltinCall.mo
Expand Up @@ -99,53 +99,55 @@ public
Expression first;
list<Expression> rest;
String name;
ExpOrigin.Type next_origin;
algorithm
Call.UNTYPED_CALL(ref = cref) := call;
next_origin := ExpOrigin.setFlag(origin, ExpOrigin.SUBEXPRESSION);

(callExp, ty, variability) := match ComponentRef.firstName(cref)
case "String" then typeStringCall(call, origin, info);
case "branch" then typeBranchCall(call, origin, info);
case "cardinality" then typeCardinalityCall(call, origin, info);
case "cat" then typeCatCall(call, origin, info);
case "change" then typeChangeCall(call, origin, info);
case "der" then typeDerCall(call, origin, info);
case "diagonal" then typeDiagonalCall(call, origin, info);
case "edge" then typeEdgeCall(call, origin, info);
case "fill" then typeFillCall(call, origin, info);
case "String" then typeStringCall(call, next_origin, info);
case "branch" then typeBranchCall(call, next_origin, info);
case "cardinality" then typeCardinalityCall(call, next_origin, info);
case "cat" then typeCatCall(call, next_origin, info);
case "change" then typeChangeCall(call, next_origin, info);
case "der" then typeDerCall(call, next_origin, info);
case "diagonal" then typeDiagonalCall(call, next_origin, info);
case "edge" then typeEdgeCall(call, next_origin, info);
case "fill" then typeFillCall(call, next_origin, info);
case "getInstanceName" then typeGetInstanceName(call);
case "initial" then typeDiscreteCall(call, origin, info);
case "isRoot" then typeIsRootCall(call, origin, info);
case "matrix" then typeMatrixCall(call, origin, info);
case "max" then typeMinMaxCall("max", call, origin, info);
case "min" then typeMinMaxCall("min", call, origin, info);
case "ndims" then typeNdimsCall(call, origin, info);
case "noEvent" then typeNoEventCall(call, origin, info);
case "ones" then typeZerosOnesCall("ones", call, origin, info);
case "potentialRoot" then typePotentialRootCall(call, origin, info);
case "pre" then typePreCall(call, origin, info);
case "product" then typeProductCall(call, origin, info);
case "root" then typeRootCall(call, origin, info);
case "rooted" then typeRootedCall(call, origin, info);
case "scalar" then typeScalarCall(call, origin, info);
case "smooth" then typeSmoothCall(call, origin, info);
case "sum" then typeSumCall(call, origin, info);
case "symmetric" then typeSymmetricCall(call, origin, info);
case "terminal" then typeDiscreteCall(call, origin, info);
case "transpose" then typeTransposeCall(call, origin, info);
case "vector" then typeVectorCall(call, origin, info);
case "zeros" then typeZerosOnesCall("zeros", call, origin, info);
case "Clock" guard Config.synchronousFeaturesAllowed() then typeClockCall(call, origin, info);
case "sample" then typeSampleCall(call, origin, info);
case "initial" then typeDiscreteCall(call, next_origin, info);
case "isRoot" then typeIsRootCall(call, next_origin, info);
case "matrix" then typeMatrixCall(call, next_origin, info);
case "max" then typeMinMaxCall("max", call, next_origin, info);
case "min" then typeMinMaxCall("min", call, next_origin, info);
case "ndims" then typeNdimsCall(call, next_origin, info);
case "noEvent" then typeNoEventCall(call, next_origin, info);
case "ones" then typeZerosOnesCall("ones", call, next_origin, info);
case "potentialRoot" then typePotentialRootCall(call, next_origin, info);
case "pre" then typePreCall(call, next_origin, info);
case "product" then typeProductCall(call, next_origin, info);
case "root" then typeRootCall(call, next_origin, info);
case "rooted" then typeRootedCall(call, next_origin, info);
case "scalar" then typeScalarCall(call, next_origin, info);
case "smooth" then typeSmoothCall(call, next_origin, info);
case "sum" then typeSumCall(call, next_origin, info);
case "symmetric" then typeSymmetricCall(call, next_origin, info);
case "terminal" then typeDiscreteCall(call, next_origin, info);
case "transpose" then typeTransposeCall(call, next_origin, info);
case "vector" then typeVectorCall(call, next_origin, info);
case "zeros" then typeZerosOnesCall("zeros", call, next_origin, info);
case "Clock" guard Config.synchronousFeaturesAllowed() then typeClockCall(call, next_origin, info);
case "sample" then typeSampleCall(call, next_origin, info);
/*
case "hold" guard Config.synchronousFeaturesAllowed() then typeHoldCall(call, origin, info);
case "shiftSample" guard Config.synchronousFeaturesAllowed() then typeShiftSampleCall(call, origin, info);
case "backSample" guard Config.synchronousFeaturesAllowed() then typeBackSampleCall(call, origin, info);
case "noClock" guard Config.synchronousFeaturesAllowed() then typeNoClockCall(call, origin, info);
case "transition" guard Config.synchronousFeaturesAllowed() then typeTransitionCall(call, origin, info);
case "initialState" guard Config.synchronousFeaturesAllowed() then typeInitialStateCall(call, origin, info);
case "activeState" guard Config.synchronousFeaturesAllowed() then typeActiveStateCall(call, origin, info);
case "ticksInState" guard Config.synchronousFeaturesAllowed() then typeTicksInStateCall(call, origin, info);
case "timeInState" guard Config.synchronousFeaturesAllowed() then typeTimeInStateCall(call, origin, info);
case "hold" guard Config.synchronousFeaturesAllowed() then typeHoldCall(call, next_origin, info);
case "shiftSample" guard Config.synchronousFeaturesAllowed() then typeShiftSampleCall(call, next_origin, info);
case "backSample" guard Config.synchronousFeaturesAllowed() then typeBackSampleCall(call, next_origin, info);
case "noClock" guard Config.synchronousFeaturesAllowed() then typeNoClockCall(call, next_origin, info);
case "transition" guard Config.synchronousFeaturesAllowed() then typeTransitionCall(call, next_origin, info);
case "initialState" guard Config.synchronousFeaturesAllowed() then typeInitialStateCall(call, next_origin, info);
case "activeState" guard Config.synchronousFeaturesAllowed() then typeActiveStateCall(call, next_origin, info);
case "ticksInState" guard Config.synchronousFeaturesAllowed() then typeTicksInStateCall(call, next_origin, info);
case "timeInState" guard Config.synchronousFeaturesAllowed() then typeTimeInStateCall(call, next_origin, info);
*/
else
algorithm
Expand Down
8 changes: 5 additions & 3 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -990,10 +990,11 @@ protected
variability := Variability.CONSTANT;
// The size of the expression must be known unless we're in a function.
is_structural := ExpOrigin.flagNotSet(origin, ExpOrigin.FUNCTION);
next_origin := ExpOrigin.setFlag(origin, ExpOrigin.SUBEXPRESSION);

for i in call.iters loop
(iter, range) := i;
(range, iter_ty, iter_var) := Typing.typeIterator(iter, range, origin, is_structural);
(range, iter_ty, iter_var) := Typing.typeIterator(iter, range, next_origin, is_structural);

if is_structural then
range := Ceval.evalExp(range, Ceval.EvalTarget.RANGE(info));
Expand All @@ -1007,7 +1008,7 @@ protected
iters := listReverseInPlace(iters);

// ExpOrigin.FOR is used here as a marker that this expression may contain iterators.
next_origin := intBitOr(origin, ExpOrigin.FOR);
next_origin := intBitOr(next_origin, ExpOrigin.FOR);
(arg, ty) := Typing.typeExp(call.exp, next_origin, info);
ty := Type.liftArrayLeftList(ty, dims);
then
Expand Down Expand Up @@ -1039,6 +1040,7 @@ protected
case UNTYPED_REDUCTION()
algorithm
variability := Variability.CONSTANT;
next_origin := ExpOrigin.setFlag(origin, ExpOrigin.SUBEXPRESSION);

for i in call.iters loop
(iter, range) := i;
Expand All @@ -1050,7 +1052,7 @@ protected
iters := listReverseInPlace(iters);

// ExpOrigin.FOR is used here as a marker that this expression may contain iterators.
next_origin := intBitOr(origin, ExpOrigin.FOR);
next_origin := intBitOr(next_origin, ExpOrigin.FOR);
(arg, ty) := Typing.typeExp(call.exp, next_origin, info);
{fn} := Function.typeRefCache(call.ref);
TypeCheck.checkReductionType(ty, Function.name(fn), call.exp, info);
Expand Down

0 comments on commit c4e03c8

Please sign in to comment.