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

Commit

Permalink
[NF] Various fixes.
Browse files Browse the repository at this point in the history
- Evaluate all constants in Typing.typeExp by default, and disable
  the package constant replacing phase since it's no longer needed.
- Don't evaluate iterators in Ceval.
- Use a type alias for ExpOrigin instead of Integer, to make it
  clearer what it is.
- Add generic error for unbound constants.

Belonging to [master]:
  - #2120
  - OpenModelica/OpenModelica-testsuite#830
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 23, 2018
1 parent dbda08c commit c5ca0a5
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/MetaModelicaBuiltin.mo
Expand Up @@ -260,7 +260,7 @@ function intBitRShift
output Integer o;
external "builtin";
annotation(Documentation(info="<html>
<p>Bit-wise right shift (like C, i << s).</p>
<p>Bit-wise right shift (like C, i >> s).</p>
</html>"));
end intBitRShift;

Expand Down
52 changes: 26 additions & 26 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -352,7 +352,7 @@ uniontype Call

function typeSpecialBuiltinFunction
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -400,7 +400,7 @@ uniontype Call
public
function typeCall
input output Expression callExp;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Type ty;
output Variability variability;
Expand Down Expand Up @@ -430,7 +430,7 @@ uniontype Call

function typeMapIteratorCall
input output Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Type ty;
output Variability variability;
Expand Down Expand Up @@ -474,7 +474,7 @@ uniontype Call

function typeMatchNormalCall
input output Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Type ty;
output Variability variability;
Expand All @@ -487,7 +487,7 @@ uniontype Call

function typeNormalCall
input output Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
algorithm
call := match call
Expand Down Expand Up @@ -537,7 +537,7 @@ uniontype Call

function matchTypedNormalCall
input output Call argtycall;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Type ty;
output Variability variability;
Expand Down Expand Up @@ -684,7 +684,7 @@ uniontype Call

function typeArgs
input output Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
algorithm
call := match call
Expand Down Expand Up @@ -1122,7 +1122,7 @@ protected
"Types a function call that can be typed normally, but which always has
discrete variability regardless of the variability of the arguments."
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand All @@ -1140,7 +1140,7 @@ protected

function typeNdimsCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty = Type.INTEGER();
Expand Down Expand Up @@ -1172,7 +1172,7 @@ protected

function typePreCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1207,7 +1207,7 @@ protected

function typeChangeCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1240,7 +1240,7 @@ protected

function typeDerCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1292,7 +1292,7 @@ protected

function typeEdgeCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1325,7 +1325,7 @@ protected

function typeMinMaxCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand All @@ -1347,7 +1347,7 @@ protected

function typeSumProductCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand All @@ -1373,7 +1373,7 @@ protected

function typeSmoothCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand All @@ -1393,7 +1393,7 @@ protected

function typeFillCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1432,7 +1432,7 @@ protected
input Type fillType;
input list<Expression> fillArgs;
input list<Expression> dimensionArgs;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1485,7 +1485,7 @@ protected

function typeZerosOnesCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1519,7 +1519,7 @@ protected

function typeScalarCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1559,7 +1559,7 @@ protected

function typeVectorCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1603,7 +1603,7 @@ protected

function typeMatrixCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1653,7 +1653,7 @@ protected

function typeSymmetricCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand All @@ -1678,7 +1678,7 @@ protected

function typeTransposeCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down Expand Up @@ -1717,7 +1717,7 @@ protected

function typeCardinalityCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand All @@ -1737,7 +1737,7 @@ protected

function typeNoEventCall
input Call call;
input Integer origin;
input ExpOrigin.Type origin;
input SourceInfo info;
output Expression callExp;
output Type ty;
Expand Down
16 changes: 14 additions & 2 deletions Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -70,6 +70,10 @@ uniontype EvalTarget
SourceInfo info;
end CONDITION;

record GENERIC
SourceInfo info;
end GENERIC;

record IGNORE_ERRORS end IGNORE_ERRORS;

function isRange
Expand Down Expand Up @@ -124,7 +128,8 @@ algorithm
ComponentRef cref;
Dimension dim;

case Expression.CREF(cref = cref as ComponentRef.CREF(node = c as InstNode.COMPONENT_NODE()))
case Expression.CREF(cref = cref as ComponentRef.CREF(node = c as InstNode.COMPONENT_NODE(),
origin = NFComponentRef.Origin.CREF))
algorithm
Typing.typeComponentBinding(c, ExpOrigin.CLASS);
binding := Component.getBinding(InstNode.component(c));
Expand Down Expand Up @@ -236,7 +241,6 @@ algorithm
end match;
end evalExpOpt;


function evalBinding
input Binding binding;
input Expression originExp "The expression the binding came from, e.g. a cref.";
Expand Down Expand Up @@ -407,6 +411,14 @@ algorithm
then
fail();

case EvalTarget.GENERIC()
algorithm
Error.addMultiSourceMessage(Error.UNBOUND_CONSTANT,
{Expression.toString(exp)},
{InstNode.info(ComponentRef.node(Expression.toCref(exp))), target.info});
then
fail();

else ();
end match;
end printUnboundError;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -39,6 +39,7 @@ protected
import Function = NFFunction;
import RangeIterator = NFRangeIterator;
import NFPrefixes.Variability;
import Prefixes = NFPrefixes;

public
import Absyn.Path;
Expand Down Expand Up @@ -2250,6 +2251,5 @@ public
end match;
end hasArrayCall2;


annotation(__OpenModelica_Interface="frontend");
end NFExpression;
16 changes: 9 additions & 7 deletions Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -140,13 +140,15 @@ algorithm
// Flatten and convert the class into a DAE.
(flat_model, funcs) := Flatten.flatten(inst_cls, name);

// Replace or collect package constants depending on the
// replacePackageConstants debug flag.
if Flags.isSet(Flags.REPLACE_PACKAGE_CONSTS) then
(flat_model, funcs) := Package.replaceConstants(flat_model, funcs);
else
flat_model := Package.collectConstants(flat_model, funcs);
end if;
// The backend doesn't handle constants well, so for now we just replace all
// constants in Typing.typeExp.
//// Replace or collect package constants depending on the
//// replacePackageConstants debug flag.
//if Flags.isSet(Flags.REPLACE_PACKAGE_CONSTS) then
// (flat_model, funcs) := Package.replaceConstants(flat_model, funcs);
//else
// flat_model := Package.collectConstants(flat_model, funcs);
//end if;

flat_model := Scalarize.scalarize(flat_model, name);
(dae, daeFuncs) := ConvertDAE.convert(flat_model, funcs, name, InstNode.info(inst_cls));
Expand Down

0 comments on commit c5ca0a5

Please sign in to comment.