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

Commit f42e280

Browse files
perostOpenModelica-Hudson
authored andcommitted
NFInst improvements.
- 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.
1 parent 15ba583 commit f42e280

21 files changed

Lines changed: 671 additions & 261 deletions

Compiler/FFrontEnd/FGraphBuild.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ algorithm
11721172
then
11731173
((equ, (ref, k, g)));
11741174

1175-
case ((equr as SCode.EQ_REINIT(cref = cref1), (ref, k, g)))
1175+
case ((equr as SCode.EQ_REINIT(cref = Absyn.CREF(componentRef = cref1)), (ref, k, g)))
11761176
equation
11771177
g = analyseCref(cref1, ref, k, g);
11781178
(equ, (_, _, g)) = SCode.traverseEEquationExps(equr, traverseExp, (ref, k, g));

Compiler/FFrontEnd/FGraphBuildEnv.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ algorithm
11581158
then
11591159
((equ, (ref, k, g)));
11601160

1161-
case ((equr as SCode.EQ_REINIT(cref = cref1), (ref, k, g)))
1161+
case ((equr as SCode.EQ_REINIT(cref = Absyn.CREF(componentRef = cref1)), (ref, k, g)))
11621162
equation
11631163
g = analyseCref(cref1, ref, k, g);
11641164
(equ, (_, _, g)) = SCode.traverseEEquationExps(equr, traverseExp, (ref, k, g));

Compiler/FrontEnd/DAEUtil.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,7 +2954,7 @@ algorithm
29542954
case DAE.REINIT()
29552955
equation
29562956
info = ElementSource.getElementSourceFileInfo(ElementSource.getElementSource(el));
2957-
Error.addSourceMessageAndFail(Error.REINIT_NOTIN_WHEN, {}, info);
2957+
Error.addSourceMessageAndFail(Error.REINIT_NOT_IN_WHEN, {}, info);
29582958
then ();
29592959
else ();
29602960
end match;
@@ -3004,7 +3004,7 @@ algorithm
30043004
case DAE.REINIT()
30053005
equation
30063006
info = ElementSource.getElementSourceFileInfo(ElementSource.getElementSource(el));
3007-
Error.addSourceMessageAndFail(Error.REINIT_NOTIN_WHEN, {}, info);
3007+
Error.addSourceMessageAndFail(Error.REINIT_NOT_IN_WHEN, {}, info);
30083008
then ();
30093009
case DAE.WHEN_EQUATION(cond, eqs, ew, source)
30103010
equation

Compiler/FrontEnd/InstExtends.mo

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,11 +1170,11 @@ algorithm
11701170
equation
11711171
exp = fixExp(cache,inEnv,exp,tree);
11721172
then (SCode.EQ_TERMINATE(exp,comment,info));
1173-
case SCode.EQ_REINIT(cref,exp,comment,info)
1173+
case SCode.EQ_REINIT(exp1,exp,comment,info)
11741174
equation
1175-
cref = fixCref(cache,inEnv,cref,tree);
1175+
exp1 = fixExp(cache,inEnv,exp1,tree);
11761176
exp = fixExp(cache,inEnv,exp,tree);
1177-
then (SCode.EQ_REINIT(cref,exp,comment,info));
1177+
then (SCode.EQ_REINIT(exp1,exp,comment,info));
11781178
case SCode.EQ_NORETCALL(exp,comment,info)
11791179
equation
11801180
exp = fixExp(cache,inEnv,exp,tree);
@@ -1318,11 +1318,11 @@ algorithm
13181318
exp2 := fixExp(cache, inEnv, exp1, tree);
13191319
then if referenceEq(exp1,exp2) then inStmt else SCode.ALG_TERMINATE(exp2, comment, info);
13201320

1321-
case SCode.ALG_REINIT(cr1, exp1, comment, info)
1321+
case SCode.ALG_REINIT(exp1, exp2, comment, info)
13221322
algorithm
1323-
cr2 := fixCref(cache, inEnv, cr1, tree);
1324-
exp2 := fixExp(cache, inEnv, exp1, tree);
1325-
then if referenceEq(cr1,cr2) and referenceEq(exp1,exp2) then inStmt else SCode.ALG_REINIT(cr2, exp2, comment, info);
1323+
exp1_1 := fixExp(cache, inEnv, exp1, tree);
1324+
exp2_1 := fixExp(cache, inEnv, exp2, tree);
1325+
then if referenceEq(exp1, exp1_1) and referenceEq(exp2, exp2_1) then inStmt else SCode.ALG_REINIT(exp1_1, exp2_1, comment, info);
13261326

13271327
case SCode.ALG_NORETCALL(exp1,comment,info)
13281328
equation

Compiler/FrontEnd/InstSection.mo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ protected function instEquationCommonWork
293293
algorithm
294294
(outDae, outState) := matchcontinue inEEquation
295295
local
296-
Absyn.ComponentRef lhs_acr, rhs_acr;
296+
Absyn.ComponentRef lhs_acr, rhs_acr, acr;
297297
SourceInfo info;
298298
Absyn.Exp lhs_aexp, rhs_aexp, range_aexp;
299299
SCode.Comment comment;
@@ -536,11 +536,11 @@ algorithm
536536
then
537537
(outDae, inState);
538538

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

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

555555
(outCache, cr_exp, exp, cr_prop) := condenseArrayEquation(outCache,
556-
inEnv, Absyn.CREF(inEEquation.cref), inEEquation.expReinit, cr_exp,
556+
inEnv, inEEquation.cref, inEEquation.expReinit, cr_exp,
557557
exp, cr_prop, prop, inImpl, inPrefix, info);
558558
(outCache, cr_exp) := PrefixUtil.prefixExp(outCache, inEnv, inIH, cr_exp, inPrefix);
559559
(outCache, exp) := PrefixUtil.prefixExp(outCache, inEnv, inIH, exp, inPrefix);
@@ -2383,7 +2383,7 @@ algorithm
23832383
case SCode.ALG_REINIT(info = info)
23842384
algorithm
23852385
(outCache, cr_exp, cr_prop) := instExp(outCache, inEnv, inIH, inPrefix,
2386-
Absyn.CREF(inStatement.cref), inImpl, info);
2386+
inStatement.cref, inImpl, info);
23872387
(outCache, exp, prop) := instExp(outCache, inEnv, inIH, inPrefix,
23882388
inStatement.newValue, inImpl, info);
23892389
source := ElementSource.addElementSourceFileInfo(inSource, info);

Compiler/FrontEnd/NFSCodeDependency.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ algorithm
16661666
then
16671667
((equ, env));
16681668

1669-
case ((equ as SCode.EQ_REINIT(cref = cref1, info = info), env))
1669+
case ((equ as SCode.EQ_REINIT(cref = Absyn.CREF(componentRef = cref1), info = info), env))
16701670
equation
16711671
analyseCref(cref1, env, info);
16721672
(equ, _) = SCode.traverseEEquationExps(equ, traverseExp, (env, info));

Compiler/FrontEnd/NFSCodeFlattenImports.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ algorithm
346346
SourceInfo info;
347347
Absyn.ComponentRef cref;
348348
SCode.Comment cmt;
349-
Absyn.Exp exp;
349+
Absyn.Exp crefExp, exp;
350350

351351
case ((equ as SCode.EQ_FOR(index = iter_name, info = info), env))
352352
equation
@@ -355,11 +355,11 @@ algorithm
355355
then
356356
((equ, env));
357357

358-
case ((SCode.EQ_REINIT(cref = cref, expReinit = exp, comment = cmt,
358+
case ((SCode.EQ_REINIT(cref = crefExp as Absyn.CREF(componentRef = cref), expReinit = exp, comment = cmt,
359359
info = info), env))
360360
equation
361361
cref = NFSCodeLookup.lookupComponentRef(cref, env, info);
362-
equ = SCode.EQ_REINIT(cref, exp, cmt, info);
362+
equ = SCode.EQ_REINIT(crefExp, exp, cmt, info);
363363
(equ, _) = SCode.traverseEEquationExps(equ, traverseExp, (env, info));
364364
then
365365
((equ, env));

Compiler/FrontEnd/SCode.mo

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ uniontype EEquation
320320
end EQ_TERMINATE;
321321

322322
record EQ_REINIT "a reinit equation"
323-
Absyn.ComponentRef cref "the variable to initialize";
324-
Absyn.Exp expReinit "the new value" ;
323+
Absyn.Exp cref "the variable to initialize";
324+
Absyn.Exp expReinit "the new value" ;
325325
Comment comment;
326326
SourceInfo info;
327327
end EQ_REINIT;
@@ -412,7 +412,7 @@ public uniontype Statement "The Statement type describes one algorithm statement
412412
end ALG_TERMINATE;
413413

414414
record ALG_REINIT
415-
Absyn.ComponentRef cref;
415+
Absyn.Exp cref;
416416
Absyn.Exp newValue;
417417
Comment comment;
418418
SourceInfo info;
@@ -1518,10 +1518,10 @@ algorithm
15181518
then
15191519
true;
15201520

1521-
case (EQ_REINIT(cref = cr1, expReinit = e1),EQ_REINIT(cref = cr2, expReinit = e2))
1521+
case (EQ_REINIT(), EQ_REINIT())
15221522
equation
1523-
true = Absyn.expEqual(e1,e2);
1524-
true = Absyn.crefEqual(cr1,cr2);
1523+
true = Absyn.expEqual(eq1.cref, eq2.cref);
1524+
true = Absyn.expEqual(eq1.expReinit, eq2.expReinit);
15251525
then
15261526
true;
15271527

@@ -2055,7 +2055,7 @@ algorithm
20552055

20562056
case ALG_REINIT()
20572057
then Absyn.ALGORITHMITEM(Absyn.ALG_NORETCALL(Absyn.CREF_IDENT("reinit", {}),
2058-
Absyn.FUNCTIONARGS({Absyn.CREF(stmt.cref), stmt.newValue}, {})), NONE(), stmt.info);
2058+
Absyn.FUNCTIONARGS({stmt.cref, stmt.newValue}, {})), NONE(), stmt.info);
20592059

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

22872287
case EQ_REINIT()
22882288
algorithm
2289-
outArg := inFunc(Absyn.CREF(inEquation.cref), outArg);
2289+
outArg := inFunc(inEquation.cref, outArg);
22902290
outArg := inFunc(inEquation.expReinit, outArg);
22912291
then
22922292
outArg;
@@ -2383,7 +2383,7 @@ algorithm
23832383

23842384
case ALG_REINIT()
23852385
algorithm
2386-
outArg := inFunc(Absyn.CREF(inStatement.cref), outArg);
2386+
outArg := inFunc(inStatement.cref, outArg);
23872387
then
23882388
inFunc(inStatement.newValue, outArg);
23892389

@@ -2635,12 +2635,12 @@ algorithm
26352635
then
26362636
(EQ_TERMINATE(e1, comment, info), arg);
26372637

2638-
case (EQ_REINIT(cr1, e1, comment, info), traverser, _)
2638+
case (EQ_REINIT(e1, e2, comment, info), traverser, _)
26392639
equation
2640-
(cr1, arg) = traverseComponentRefExps(cr1, traverser, inArg);
2641-
(e1, arg) = traverser(e1, arg);
2640+
(e1, arg) = traverser(e1, inArg);
2641+
(e2, arg) = traverser(e2, arg);
26422642
then
2643-
(EQ_REINIT(cr1, e1, comment, info), arg);
2643+
(EQ_REINIT(e1, e2, comment, info), arg);
26442644

26452645
case (EQ_NORETCALL(e1, comment, info), traverser, arg)
26462646
equation
@@ -3090,10 +3090,10 @@ algorithm
30903090

30913091
case (ALG_REINIT(), traverser, arg)
30923092
algorithm
3093-
(Absyn.CREF(cref), arg) := traverser(Absyn.CREF(inStatement.cref), arg);
3093+
(e1, arg) := traverser(inStatement.cref, arg);
30943094
(e2, arg) := traverser(inStatement.newValue, arg);
30953095
then
3096-
(ALG_REINIT(cref, e2, inStatement.comment, inStatement.info), arg);
3096+
(ALG_REINIT(e1, e2, inStatement.comment, inStatement.info), arg);
30973097

30983098
case (ALG_NORETCALL(e1, comment, info), traverser, arg)
30993099
equation

Compiler/FrontEnd/SCodeUtil.mo

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,8 @@ algorithm
884884
then SCode.ALG_TERMINATE(e1, comment, info);
885885

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

891890
case Absyn.ALG_NORETCALL()
892891
algorithm
@@ -1677,9 +1676,9 @@ algorithm
16771676

16781677
// reinit(cref, exp)
16791678
case Absyn.EQ_NORETCALL(functionName = Absyn.CREF_IDENT(name = "reinit"),
1680-
functionArgs = Absyn.FUNCTIONARGS(args = {Absyn.CREF(componentRef = cr), e2},
1679+
functionArgs = Absyn.FUNCTIONARGS(args = {e1, e2},
16811680
argNames = {}))
1682-
then SCode.EQ_REINIT(cr, e2, inComment, inInfo);
1681+
then SCode.EQ_REINIT(e1, e2, inComment, inInfo);
16831682

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

0 commit comments

Comments
 (0)