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

[NF] Various fixes. #2819

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions Compiler/NFFrontEnd/NFCall.mo
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import Operator = NFOperator;
public
uniontype CallAttributes
record CALL_ATTR
Type ty "The type of the return value, if several return values this is undefined";
Boolean tuple_ "tuple" ;
Boolean builtin "builtin Function call" ;
Boolean isImpure "if the function has prefix *impure* is true, else false";
Expand All @@ -81,9 +80,10 @@ public

function toDAE
input CallAttributes attr;
input Type returnType;
output DAE.CallAttributes fattr;
algorithm
fattr := DAE.CALL_ATTR(Type.toDAE(attr.ty), attr.tuple_, attr.builtin,
fattr := DAE.CALL_ATTR(Type.toDAE(returnType), attr.tuple_, attr.builtin,
attr.isImpure, attr.isFunctionPointerCall, attr.inlineType, attr.tailCall);
end toDAE;
end CallAttributes;
Expand Down Expand Up @@ -297,7 +297,6 @@ uniontype Call
CallAttributes ca;
algorithm
ca := CallAttributes.CALL_ATTR(
returnType,
Type.isTuple(returnType),
Function.isBuiltin(fn),
Function.isImpure(fn),
Expand Down Expand Up @@ -685,7 +684,7 @@ uniontype Call
then DAE.CALL(
Function.nameConsiderBuiltin(call.fn),
list(Expression.toDAE(e) for e in call.arguments),
CallAttributes.toDAE(call.attributes));
CallAttributes.toDAE(call.attributes, call.ty));

case TYPED_ARRAY_CONSTRUCTOR()
algorithm
Expand Down
1 change: 0 additions & 1 deletion Compiler/NFFrontEnd/NFExpandExp.mo
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ public
algorithm
Call.TYPED_CALL(fn, ty, var, {arg}, attr) := call;
ty := Type.arrayElementType(ty);
attr.ty := ty;

(arg, true) := expand(arg);
outExp := expandBuiltinGeneric2(arg, fn, ty, var, attr);
Expand Down
33 changes: 33 additions & 0 deletions Compiler/NFFrontEnd/NFExpression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,9 @@ public
case CALL(call = Call.TYPED_ARRAY_CONSTRUCTOR())
then applySubscriptArrayConstructor(subscript, exp.call, restSubscripts);

case CALL()
then applySubscriptCall(subscript, exp, restSubscripts);

case IF() then applySubscriptIf(subscript, exp, restSubscripts);

else makeSubscriptedExp(subscript :: restSubscripts, exp);
Expand Down Expand Up @@ -1163,6 +1166,36 @@ public
end match;
end applyIndexSubscriptRange2;

function applySubscriptCall
input Subscript subscript;
input Expression exp;
input list<Subscript> restSubscripts;
output Expression outExp;
protected
Call call;
algorithm
CALL(call = call) := exp;

outExp := match call
local
Expression arg;
Type ty;

case Call.TYPED_CALL(arguments = {arg})
guard Function.Function.isSubscriptableBuiltin(call.fn)
algorithm
arg := applySubscript(subscript, arg, restSubscripts);
ty := Type.copyDims(typeOf(arg), call.ty);
then
CALL(Call.TYPED_CALL(call.fn, ty, call.var, {arg}, call.attributes));

case Call.TYPED_ARRAY_CONSTRUCTOR()
then applySubscriptArrayConstructor(subscript, call, restSubscripts);

else makeSubscriptedExp(subscript :: restSubscripts, exp);
end match;
end applySubscriptCall;

function applySubscriptArrayConstructor
input Subscript subscript;
input Call call;
Expand Down
17 changes: 17 additions & 0 deletions Compiler/NFFrontEnd/NFFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,23 @@ uniontype Function
end if;
end isSpecialBuiltin;

function isSubscriptableBuiltin
input Function fn;
output Boolean scalarBuiltin;
protected
algorithm
if not isBuiltin(fn) then
scalarBuiltin := false;
else
scalarBuiltin := match Absyn.pathFirstIdent(Function.nameConsiderBuiltin(fn))
case "change" then true;
case "der" then true;
case "pre" then true;
else false;
end match;
end if;
end isSubscriptableBuiltin;

function isImpure
input Function fn;
output Boolean isImpure = fn.attributes.isImpure;
Expand Down
8 changes: 7 additions & 1 deletion Compiler/NFFrontEnd/NFSimplifyExp.mo
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,13 @@ algorithm
case Expression.BOOLEAN()
then simplify(if cond.value then tb else fb);

else Expression.IF(cond, simplify(tb), simplify(fb));
else
algorithm
tb := simplify(tb);
fb := simplify(fb);
then
if Expression.isEqual(tb, fb) then tb else Expression.IF(cond, tb, fb);

end match;
end simplifyIf;

Expand Down
14 changes: 9 additions & 5 deletions Compiler/NFFrontEnd/NFType.mo
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,16 @@ public
input Type dstType;
output Type ty;
algorithm
ty := match dstType
case ARRAY()
then ARRAY(dstType.elementType, arrayDims(srcType));
if listEmpty(arrayDims(srcType)) then
ty := arrayElementType(dstType);
else
ty := match dstType
case ARRAY()
then ARRAY(dstType.elementType, arrayDims(srcType));

else ARRAY(dstType, arrayDims(srcType));
end match;
else ARRAY(dstType, arrayDims(srcType));
end match;
end if;
end copyDims;

function nthDimension
Expand Down