Skip to content

Commit

Permalink
NFInst improvements.
Browse files Browse the repository at this point in the history
- Added type checking and various other checks for equations and
  algorithms.
- Improved flattening of initial equation and algorithm sections.
- Changed SCode.EQ_REINIT to have a Absyn.Exp instead of
  Absyn.ComponentRef as first field, for better error handling.
- Removed Statement.REINIT, since reinit statements are not allowed.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 2, 2017
1 parent 15ba583 commit f42e280
Show file tree
Hide file tree
Showing 21 changed files with 671 additions and 261 deletions.
2 changes: 1 addition & 1 deletion Compiler/FFrontEnd/FGraphBuild.mo
Expand Up @@ -1172,7 +1172,7 @@ algorithm
then
((equ, (ref, k, g)));

case ((equr as SCode.EQ_REINIT(cref = cref1), (ref, k, g)))
case ((equr as SCode.EQ_REINIT(cref = Absyn.CREF(componentRef = cref1)), (ref, k, g)))
equation
g = analyseCref(cref1, ref, k, g);
(equ, (_, _, g)) = SCode.traverseEEquationExps(equr, traverseExp, (ref, k, g));
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FFrontEnd/FGraphBuildEnv.mo
Expand Up @@ -1158,7 +1158,7 @@ algorithm
then
((equ, (ref, k, g)));

case ((equr as SCode.EQ_REINIT(cref = cref1), (ref, k, g)))
case ((equr as SCode.EQ_REINIT(cref = Absyn.CREF(componentRef = cref1)), (ref, k, g)))
equation
g = analyseCref(cref1, ref, k, g);
(equ, (_, _, g)) = SCode.traverseEEquationExps(equr, traverseExp, (ref, k, g));
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -2954,7 +2954,7 @@ algorithm
case DAE.REINIT()
equation
info = ElementSource.getElementSourceFileInfo(ElementSource.getElementSource(el));
Error.addSourceMessageAndFail(Error.REINIT_NOTIN_WHEN, {}, info);
Error.addSourceMessageAndFail(Error.REINIT_NOT_IN_WHEN, {}, info);
then ();
else ();
end match;
Expand Down Expand Up @@ -3004,7 +3004,7 @@ algorithm
case DAE.REINIT()
equation
info = ElementSource.getElementSourceFileInfo(ElementSource.getElementSource(el));
Error.addSourceMessageAndFail(Error.REINIT_NOTIN_WHEN, {}, info);
Error.addSourceMessageAndFail(Error.REINIT_NOT_IN_WHEN, {}, info);
then ();
case DAE.WHEN_EQUATION(cond, eqs, ew, source)
equation
Expand Down
14 changes: 7 additions & 7 deletions Compiler/FrontEnd/InstExtends.mo
Expand Up @@ -1170,11 +1170,11 @@ algorithm
equation
exp = fixExp(cache,inEnv,exp,tree);
then (SCode.EQ_TERMINATE(exp,comment,info));
case SCode.EQ_REINIT(cref,exp,comment,info)
case SCode.EQ_REINIT(exp1,exp,comment,info)
equation
cref = fixCref(cache,inEnv,cref,tree);
exp1 = fixExp(cache,inEnv,exp1,tree);
exp = fixExp(cache,inEnv,exp,tree);
then (SCode.EQ_REINIT(cref,exp,comment,info));
then (SCode.EQ_REINIT(exp1,exp,comment,info));
case SCode.EQ_NORETCALL(exp,comment,info)
equation
exp = fixExp(cache,inEnv,exp,tree);
Expand Down Expand Up @@ -1318,11 +1318,11 @@ algorithm
exp2 := fixExp(cache, inEnv, exp1, tree);
then if referenceEq(exp1,exp2) then inStmt else SCode.ALG_TERMINATE(exp2, comment, info);

case SCode.ALG_REINIT(cr1, exp1, comment, info)
case SCode.ALG_REINIT(exp1, exp2, comment, info)
algorithm
cr2 := fixCref(cache, inEnv, cr1, tree);
exp2 := fixExp(cache, inEnv, exp1, tree);
then if referenceEq(cr1,cr2) and referenceEq(exp1,exp2) then inStmt else SCode.ALG_REINIT(cr2, exp2, comment, info);
exp1_1 := fixExp(cache, inEnv, exp1, tree);
exp2_1 := fixExp(cache, inEnv, exp2, tree);
then if referenceEq(exp1, exp1_1) and referenceEq(exp2, exp2_1) then inStmt else SCode.ALG_REINIT(exp1_1, exp2_1, comment, info);

case SCode.ALG_NORETCALL(exp1,comment,info)
equation
Expand Down
10 changes: 5 additions & 5 deletions Compiler/FrontEnd/InstSection.mo
Expand Up @@ -293,7 +293,7 @@ protected function instEquationCommonWork
algorithm
(outDae, outState) := matchcontinue inEEquation
local
Absyn.ComponentRef lhs_acr, rhs_acr;
Absyn.ComponentRef lhs_acr, rhs_acr, acr;
SourceInfo info;
Absyn.Exp lhs_aexp, rhs_aexp, range_aexp;
SCode.Comment comment;
Expand Down Expand Up @@ -536,11 +536,11 @@ algorithm
then
(outDae, inState);

case SCode.EQ_REINIT(info = info)
case SCode.EQ_REINIT(cref = Absyn.CREF(componentRef = acr), info = info)
algorithm
// Elaborate the cref.
(outCache, cr_exp as DAE.CREF(cr, ty), cr_prop, _) :=
Static.elabCrefNoEval(outCache, inEnv, inEEquation.cref, inImpl, false, inPrefix, info);
Static.elabCrefNoEval(outCache, inEnv, acr, inImpl, false, inPrefix, info);
true := checkReinitType(ty, cr_prop, cr, info);

// Elaborate the reinit expression.
Expand All @@ -553,7 +553,7 @@ algorithm
exp := Types.matchProp(exp, prop, cr_prop, true);

(outCache, cr_exp, exp, cr_prop) := condenseArrayEquation(outCache,
inEnv, Absyn.CREF(inEEquation.cref), inEEquation.expReinit, cr_exp,
inEnv, inEEquation.cref, inEEquation.expReinit, cr_exp,
exp, cr_prop, prop, inImpl, inPrefix, info);
(outCache, cr_exp) := PrefixUtil.prefixExp(outCache, inEnv, inIH, cr_exp, inPrefix);
(outCache, exp) := PrefixUtil.prefixExp(outCache, inEnv, inIH, exp, inPrefix);
Expand Down Expand Up @@ -2383,7 +2383,7 @@ algorithm
case SCode.ALG_REINIT(info = info)
algorithm
(outCache, cr_exp, cr_prop) := instExp(outCache, inEnv, inIH, inPrefix,
Absyn.CREF(inStatement.cref), inImpl, info);
inStatement.cref, inImpl, info);
(outCache, exp, prop) := instExp(outCache, inEnv, inIH, inPrefix,
inStatement.newValue, inImpl, info);
source := ElementSource.addElementSourceFileInfo(inSource, info);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/NFSCodeDependency.mo
Expand Up @@ -1666,7 +1666,7 @@ algorithm
then
((equ, env));

case ((equ as SCode.EQ_REINIT(cref = cref1, info = info), env))
case ((equ as SCode.EQ_REINIT(cref = Absyn.CREF(componentRef = cref1), info = info), env))
equation
analyseCref(cref1, env, info);
(equ, _) = SCode.traverseEEquationExps(equ, traverseExp, (env, info));
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/NFSCodeFlattenImports.mo
Expand Up @@ -346,7 +346,7 @@ algorithm
SourceInfo info;
Absyn.ComponentRef cref;
SCode.Comment cmt;
Absyn.Exp exp;
Absyn.Exp crefExp, exp;

case ((equ as SCode.EQ_FOR(index = iter_name, info = info), env))
equation
Expand All @@ -355,11 +355,11 @@ algorithm
then
((equ, env));

case ((SCode.EQ_REINIT(cref = cref, expReinit = exp, comment = cmt,
case ((SCode.EQ_REINIT(cref = crefExp as Absyn.CREF(componentRef = cref), expReinit = exp, comment = cmt,
info = info), env))
equation
cref = NFSCodeLookup.lookupComponentRef(cref, env, info);
equ = SCode.EQ_REINIT(cref, exp, cmt, info);
equ = SCode.EQ_REINIT(crefExp, exp, cmt, info);
(equ, _) = SCode.traverseEEquationExps(equ, traverseExp, (env, info));
then
((equ, env));
Expand Down
30 changes: 15 additions & 15 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -320,8 +320,8 @@ uniontype EEquation
end EQ_TERMINATE;

record EQ_REINIT "a reinit equation"
Absyn.ComponentRef cref "the variable to initialize";
Absyn.Exp expReinit "the new value" ;
Absyn.Exp cref "the variable to initialize";
Absyn.Exp expReinit "the new value" ;
Comment comment;
SourceInfo info;
end EQ_REINIT;
Expand Down Expand Up @@ -412,7 +412,7 @@ public uniontype Statement "The Statement type describes one algorithm statement
end ALG_TERMINATE;

record ALG_REINIT
Absyn.ComponentRef cref;
Absyn.Exp cref;
Absyn.Exp newValue;
Comment comment;
SourceInfo info;
Expand Down Expand Up @@ -1518,10 +1518,10 @@ algorithm
then
true;

case (EQ_REINIT(cref = cr1, expReinit = e1),EQ_REINIT(cref = cr2, expReinit = e2))
case (EQ_REINIT(), EQ_REINIT())
equation
true = Absyn.expEqual(e1,e2);
true = Absyn.crefEqual(cr1,cr2);
true = Absyn.expEqual(eq1.cref, eq2.cref);
true = Absyn.expEqual(eq1.expReinit, eq2.expReinit);
then
true;

Expand Down Expand Up @@ -2055,7 +2055,7 @@ algorithm

case ALG_REINIT()
then Absyn.ALGORITHMITEM(Absyn.ALG_NORETCALL(Absyn.CREF_IDENT("reinit", {}),
Absyn.FUNCTIONARGS({Absyn.CREF(stmt.cref), stmt.newValue}, {})), NONE(), stmt.info);
Absyn.FUNCTIONARGS({stmt.cref, stmt.newValue}, {})), NONE(), stmt.info);

case ALG_NORETCALL(Absyn.CALL(function_=functionCall,functionArgs=functionArgs),_,info)
then Absyn.ALGORITHMITEM(Absyn.ALG_NORETCALL(functionCall,functionArgs),NONE(),info);
Expand Down Expand Up @@ -2286,7 +2286,7 @@ algorithm

case EQ_REINIT()
algorithm
outArg := inFunc(Absyn.CREF(inEquation.cref), outArg);
outArg := inFunc(inEquation.cref, outArg);
outArg := inFunc(inEquation.expReinit, outArg);
then
outArg;
Expand Down Expand Up @@ -2383,7 +2383,7 @@ algorithm

case ALG_REINIT()
algorithm
outArg := inFunc(Absyn.CREF(inStatement.cref), outArg);
outArg := inFunc(inStatement.cref, outArg);
then
inFunc(inStatement.newValue, outArg);

Expand Down Expand Up @@ -2635,12 +2635,12 @@ algorithm
then
(EQ_TERMINATE(e1, comment, info), arg);

case (EQ_REINIT(cr1, e1, comment, info), traverser, _)
case (EQ_REINIT(e1, e2, comment, info), traverser, _)
equation
(cr1, arg) = traverseComponentRefExps(cr1, traverser, inArg);
(e1, arg) = traverser(e1, arg);
(e1, arg) = traverser(e1, inArg);
(e2, arg) = traverser(e2, arg);
then
(EQ_REINIT(cr1, e1, comment, info), arg);
(EQ_REINIT(e1, e2, comment, info), arg);

case (EQ_NORETCALL(e1, comment, info), traverser, arg)
equation
Expand Down Expand Up @@ -3090,10 +3090,10 @@ algorithm

case (ALG_REINIT(), traverser, arg)
algorithm
(Absyn.CREF(cref), arg) := traverser(Absyn.CREF(inStatement.cref), arg);
(e1, arg) := traverser(inStatement.cref, arg);
(e2, arg) := traverser(inStatement.newValue, arg);
then
(ALG_REINIT(cref, e2, inStatement.comment, inStatement.info), arg);
(ALG_REINIT(e1, e2, inStatement.comment, inStatement.info), arg);

case (ALG_NORETCALL(e1, comment, info), traverser, arg)
equation
Expand Down
9 changes: 4 additions & 5 deletions Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -884,9 +884,8 @@ algorithm
then SCode.ALG_TERMINATE(e1, comment, info);

case Absyn.ALG_NORETCALL(functionCall = Absyn.CREF_IDENT(name = "reinit"),
functionArgs = Absyn.FUNCTIONARGS(args = {Absyn.CREF(componentRef = cr), e2},
argNames = {}))
then SCode.ALG_REINIT(cr, e2, comment, info);
functionArgs = Absyn.FUNCTIONARGS(args = {e1, e2}, argNames = {}))
then SCode.ALG_REINIT(e1, e2, comment, info);

case Absyn.ALG_NORETCALL()
algorithm
Expand Down Expand Up @@ -1677,9 +1676,9 @@ algorithm

// reinit(cref, exp)
case Absyn.EQ_NORETCALL(functionName = Absyn.CREF_IDENT(name = "reinit"),
functionArgs = Absyn.FUNCTIONARGS(args = {Absyn.CREF(componentRef = cr), e2},
functionArgs = Absyn.FUNCTIONARGS(args = {e1, e2},
argNames = {}))
then SCode.EQ_REINIT(cr, e2, inComment, inInfo);
then SCode.EQ_REINIT(e1, e2, inComment, inInfo);

// Other nonreturning calls. assert, terminate and reinit with the wrong
// number of arguments is also turned into a noretcall, since it's
Expand Down

0 comments on commit f42e280

Please sign in to comment.