Skip to content

Commit

Permalink
- made parser/walker/Absyn.mo/Dump.mo to handle failure and equality …
Browse files Browse the repository at this point in the history
…in the algorithm section

- do not dive into DERIVED classes when querying internal classes in Interactive.mo;
  is not correct to dive into derived classes and if we do then we run into stack overflow;
  Example: lookup of Env.Env in Env.Env.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4402 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 27, 2009
1 parent 2915535 commit eb6bf4b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 25 deletions.
4 changes: 4 additions & 0 deletions Compiler/Absyn.mo
Expand Up @@ -584,6 +584,10 @@ uniontype Algorithm "The Algorithm type describes one algorithm statement in an
record ALG_LABEL
String labelName;
end ALG_LABEL;

record ALG_FAILURE
AlgorithmItem equ;
end ALG_FAILURE;
//-------------------------------

end Algorithm;
Expand Down
30 changes: 24 additions & 6 deletions Compiler/Dump.mo
Expand Up @@ -2819,7 +2819,8 @@ algorithm
Ident i;
Absyn.AlgorithmItem algItem;
Absyn.ComponentRef cref;
Absyn.FunctionArgs fargs;
Absyn.FunctionArgs fargs;

case (Absyn.ALG_ASSIGN(assignComponent = assignComp,value = exp))
equation
Print.printBuf("ALG_ASSIGN(");
Expand Down Expand Up @@ -2866,11 +2867,12 @@ algorithm
Print.printBuf("}");
then
();
case Absyn.ALG_WHEN_A(boolExpr = e,whenBody = al,elseWhenAlgorithmBranch = el) /* rule Print.print_buf \"WHEN_E \" & print_exp(e) &
Print.print_buf \" {\" & print_list_debug(\"print_algorithm\",al, print_algorithmitem, \";\") & Print.print_buf \"}\"
----------------------------------------------------------
print_algorithm Absyn.ALG_WHEN_E(e,al)
*/
case Absyn.ALG_WHEN_A(boolExpr = e,whenBody = al,elseWhenAlgorithmBranch = el)
/* rule Print.print_buf \"WHEN_E \" & print_exp(e) &
Print.print_buf \" {\" & print_list_debug(\"print_algorithm\",al, print_algorithmitem, \";\") & Print.print_buf \"}\"
----------------------------------------------------------
print_algorithm Absyn.ALG_WHEN_E(e,al)
*/
local list<tuple<Absyn.Exp, list<Absyn.AlgorithmItem>>> el;
equation
Print.printBuf("WHEN_A ");
Expand All @@ -2890,6 +2892,13 @@ algorithm
Print.printBuf("BREAK()");
then
();
case Absyn.ALG_FAILURE(algItem)
equation
Print.printBuf("FAILURE(");
printAlgorithmitem(algItem);
Print.printBuf(")");
then
();
case (_)
equation
Print.printBuf(" ** UNKNOWN ALGORITHM CLAUSE ** ");
Expand Down Expand Up @@ -2971,6 +2980,7 @@ algorithm
Absyn.Annotation ann;
Absyn.ForIterators iterators;
Absyn.AlgorithmItem algItem;

case (i,Absyn.ALGORITHMITEM(algorithm_ = Absyn.ALG_ASSIGN(assignComponent = assignComp,value = exp),comment = optcmt)) /* ALG_ASSIGN */
equation
s1 = printExpStr(assignComp);
Expand Down Expand Up @@ -3059,6 +3069,14 @@ algorithm
str = is +& "break" +& s3 +& ";";
then
str;
case (i,Absyn.ALGORITHMITEM(algorithm_ = Absyn.ALG_FAILURE(algItem),comment = optcmt)) /* ALG_FAILURE */
equation
s1 = unparseAlgorithmStr(0, algItem);
s3 = unparseCommentOption(optcmt);
is = indentStr(i);
str = is +& "failure(" +& s1 +& ")" +& s3 +& ";";
then
str;
case (i,Absyn.ALGORITHMITEM(algorithm_ = Absyn.ALG_MATCHCASES(explist), comment = optcmt))
local
list<Absyn.Exp> explist;
Expand Down
23 changes: 18 additions & 5 deletions Compiler/Interactive.mo
Expand Up @@ -9317,12 +9317,13 @@ algorithm
matchcontinue (inPath1,inPath2,inProgram3)
local
Absyn.Class inmodeldef,cdef;
Absyn.Path newpath,path,inmodel,innewpath,respath,inpath;
Absyn.Path newpath,path,inmodel,innewpath,respath;
Absyn.Program p;
String s1,s2;
Absyn.TimeStamp ts;
case (path,inmodel,p as Absyn.PROGRAM(globalBuildTimes=ts))
equation
//Debug.fprintln("inter", "Interactive.lookupClassdef 1 Looking for: " +& Absyn.pathString(path) +& " in: " +& Absyn.pathString(inmodel));
// remove self reference, otherwise we go into an infinite loop!
path = Inst.removeSelfReference(Absyn.pathLastIdent(inmodel),path);
inmodeldef = getPathedClassInProgram(inmodel, p) "Look first inside \'inmodel\'" ;
Expand All @@ -9332,12 +9333,14 @@ algorithm
(cdef,newpath);
case (path,inmodel,p) /* Then look inside next level */
equation
//Debug.fprintln("inter", "Interactive.lookupClassdef 2 Looking for: " +& Absyn.pathString(path) +& " in: " +& Absyn.pathString(inmodel));
innewpath = Absyn.stripLast(inmodel);
(cdef,respath) = lookupClassdef(path, innewpath, p);
then
(cdef,respath);
case (path,_,p)
case (path,inmodel,p)
equation
//Debug.fprintln("inter", "Interactive.lookupClassdef 3 Looking for: " +& Absyn.pathString(path) +& " in: " +& Absyn.pathString(inmodel));
cdef = getPathedClassInProgram(path, p) "Finally look in top level" ;
then
(cdef,path);
Expand All @@ -9349,10 +9352,11 @@ algorithm
Absyn.PARTS({},NONE),Absyn.dummyInfo),Absyn.IDENT("String"));
case (Absyn.IDENT(name = "Boolean"),_,_) then (Absyn.CLASS("Boolean",false,false,false,Absyn.R_PREDEFINED_BOOL(),
Absyn.PARTS({},NONE),Absyn.dummyInfo),Absyn.IDENT("Boolean"));
case (path,inpath,_)
case (path,inmodel,_)
equation
//Debug.fprintln("inter", "Interactive.lookupClassdef 8 Looking for: " +& Absyn.pathString(path) +& " in: " +& Absyn.pathString(inmodel));
s1 = Absyn.pathString(path);
s2 = Absyn.pathString(inpath);
s2 = Absyn.pathString(inmodel);
Error.addMessage(Error.LOOKUP_ERROR, {s1,s2});
then
fail();
Expand Down Expand Up @@ -11610,8 +11614,11 @@ algorithm
/* a derived class */
case (inmodel,p,Absyn.CLASS(body = Absyn.DERIVED(typeSpec=Absyn.TPATH(path,_))))
equation
/* adrpo: 2009-10-27 we shouldn't look into derived!
(cdef,newpath) = lookupClassdef(path, inmodel, p);
res = getPackagesInClass(newpath, p, cdef);
*/
res = "";
then
res;
end matchcontinue;
Expand Down Expand Up @@ -11870,8 +11877,11 @@ algorithm
/* a derived class */
case (inmodel,p,Absyn.CLASS(body = Absyn.DERIVED(typeSpec=Absyn.TPATH(path, _))))
equation
/* adrpo 2009-10-27: we sholdn't dive into derived classes!
(cdef,newpath) = lookupClassdef(path, inmodel, p);
res = getClassnamesInClass(newpath, p, cdef);
*/
res = "";
then
res;
end matchcontinue;
Expand Down Expand Up @@ -15644,9 +15654,12 @@ algorithm
res;
case (modelpath,p,Absyn.CLASS(body = Absyn.DERIVED(typeSpec = Absyn.TPATH(path,_))))
equation
// print("Looking up -> lookupClassdef(" +& Absyn.pathString(path) +& ", " +& Absyn.pathString(modelpath) +& ")\n");
// print("Looking up -> lookupClassdef(" +& Absyn.pathString(path) +& ", " +& Absyn.pathString(modelpath) +& ")\n");
/* adrpo 2009-10-27: do not dive into derived classes!
(cdef,newpath) = lookupClassdef(path, modelpath, p);
res = getClassesInClass(newpath, p, cdef);
*/
res = {};
then
res;
end matchcontinue;
Expand Down
36 changes: 22 additions & 14 deletions Compiler/absyn_builder/walker.g
Expand Up @@ -1391,19 +1391,19 @@ equation returns [void* ast]
)
(cmt = comment)?
{
if (fa)
if (fa)
{
ast = Absyn__EQUATIONITEM(Absyn__EQ_5fFAILURE(ast),cmt ? mk_some(cmt) : mk_none());
ast = Absyn__EQUATIONITEM(Absyn__EQ_5fFAILURE(ast),cmt ? mk_some(cmt) : mk_none());
}
else if (eq1 && eq2)
{
ast = mk_cons(eq2,mk_nil());
ast = Absyn__FUNCTIONARGS(mk_cons(eq1,ast),mk_nil());
ast = Absyn__EQUATIONITEM(Absyn__EQ_5fNORETCALL(Absyn__CREF_5fIDENT(mk_scon("equality"),mk_nil()),ast),cmt ? mk_some(cmt) : mk_none());
ast = mk_cons(eq2,mk_nil());
ast = Absyn__FUNCTIONARGS(mk_cons(eq1,ast),mk_nil());
ast = Absyn__EQUATIONITEM(Absyn__EQ_5fNORETCALL(Absyn__CREF_5fIDENT(mk_scon("equality"),mk_nil()),ast),cmt ? mk_some(cmt) : mk_none());
}
else
{
ast = Absyn__EQUATIONITEM(ast,cmt ? mk_some(cmt) : mk_none());
ast = Absyn__EQUATIONITEM(ast,cmt ? mk_some(cmt) : mk_none());
}
}
)
Expand All @@ -1426,6 +1426,8 @@ algorithm returns [void* ast]
void* cmt = 0;
void* e1 = 0;
void* e2 = 0;
void* ea1 = 0;
void* ea2 = 0;
}
:
#(ALGORITHM_STATEMENT
Expand All @@ -1441,21 +1443,27 @@ algorithm returns [void* ast]
| ast = when_clause_a
| BREAK { ast = Absyn__ALG_5fBREAK; }
| RETURN { ast = Absyn__ALG_5fRETURN; }
/* | #(FAILURE ast = fa:algorithm)
| #(EQUALITY ast = eq:algorithm) */
| #(FAILURE ast = fa:algorithm)
| #(EQUALITY e1 = expression e2 = expression)
)
(cmt = comment)?
{
/* if (fa) // Commented out because we don't use failure or equality in algorithms!
// Commented out because we don't use failure or equality in algorithms!
if (fa) // adrpo: 2009-10-27 is actually used in DAE.isNotVar!
{
ast = Absyn__ALGORITHMITEM(Absyn__ALG_5fFAILURE(ast),cmt ? mk_some(cmt) : mk_none());
ast = Absyn__ALGORITHMITEM(Absyn__ALG_5fFAILURE(ast),cmt ? mk_some(cmt) : mk_none());
}
else if (eq)
else if (ea1 && ea2)
{
ast = Absyn__ALGORITHMITEM(Absyn__ALG_5fEQUALITY(ast),cmt ? mk_some(cmt) : mk_none());
} */
ast = Absyn__ALGORITHMITEM(ast,cmt ? mk_some(cmt) : mk_none());
ast = mk_cons(ea2,mk_nil());
ast = Absyn__FUNCTIONARGS(mk_cons(ea1,ast),mk_nil());
ast = Absyn__EQUATIONITEM(Absyn__ALG_5fNORETCALL(Absyn__CREF_5fIDENT(mk_scon("equality"),mk_nil()),ast),cmt ? mk_some(cmt) : mk_none());
}
else
{
ast = Absyn__ALGORITHMITEM(ast,cmt ? mk_some(cmt) : mk_none());
}
}
)
;
Expand Down
1 change: 1 addition & 0 deletions modelica_parser/src/modelica_parser.g
Expand Up @@ -684,6 +684,7 @@ algorithm :
| BREAK
| RETURN
| FAILURE^ LPAR! algorithm RPAR!
| EQUALITY^ LPAR! expression (EQUALS!|COMMA!) expression RPAR!
)
comment
{
Expand Down

0 comments on commit eb6bf4b

Please sign in to comment.