Skip to content

Commit

Permalink
- Added Absyn.Info comments for statements in the generated C-code
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7847 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 2, 2011
1 parent 005aa88 commit 6d4cd60
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 72 deletions.
12 changes: 7 additions & 5 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -819,6 +819,7 @@ uniontype Case "case in match or matchcontinue"
list<ElementItem> localDecls " local decls ";
list<EquationItem> equations " equations [] for no equations ";
Exp result " result ";
Info resultInfo "file information of the result-exp";
Option<String> comment " comment after case like: case pattern string_comment ";
Info info "file information of the whole case";
end CASE;
Expand All @@ -827,6 +828,7 @@ uniontype Case "case in match or matchcontinue"
list<ElementItem> localDecls " local decls ";
list<EquationItem> equations " equations [] for no equations ";
Exp result " result ";
Info resultInfo "file information of the result-exp";
Option<String> comment " comment after case like: case pattern string_comment ";
Info info "file information of the whole case";
end ELSE;
Expand Down Expand Up @@ -2205,27 +2207,27 @@ algorithm
local
tuple<FuncType, FuncType, Argument> tup;
Exp pattern, result;
Info info, pinfo;
Info info, resultInfo, pinfo;
list<ElementItem> ldecls;
list<EquationItem> eql;
Option<String> cmt;

case (CASE(pattern = pattern, patternInfo = pinfo, localDecls = ldecls,
equations = eql, result = result, comment = cmt, info = info), tup)
equations = eql, result = result, resultInfo = resultInfo, comment = cmt, info = info), tup)
equation
(pattern, tup) = traverseExpBidir(pattern, tup);
(eql, tup) = Util.listMapAndFold(eql, traverseEquationItemBidir, tup);
(result, tup) = traverseExpBidir(result, tup);
then
(CASE(pattern, pinfo, ldecls, eql, result, cmt, info), tup);
(CASE(pattern, pinfo, ldecls, eql, result, resultInfo, cmt, info), tup);

case (ELSE(localDecls = ldecls, equations = eql, result = result,
case (ELSE(localDecls = ldecls, equations = eql, result = result, resultInfo = resultInfo,
comment = cmt, info = info), tup)
equation
(eql, tup) = Util.listMapAndFold(eql, traverseEquationItemBidir, tup);
(result, tup) = traverseExpBidir(result, tup);
then
(ELSE(ldecls, eql, result, cmt, info), tup);
(ELSE(ldecls, eql, result, resultInfo, cmt, info), tup);

end match;
end traverseMatchCase;
Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -1197,6 +1197,7 @@ public uniontype MatchCase
list<Element> localDecls;
list<Statement> body;
Option<Exp> result;
Absyn.Info resultInfo "We need to keep the line info here so we can set a breakpoint at the last statement of a match-expression";
Integer jump "the number of iterations we should skip if we succeed with pattern-matching, but don't succeed";
Absyn.Info info;
end CASE;
Expand Down
28 changes: 16 additions & 12 deletions Compiler/FrontEnd/Dump.mo
Expand Up @@ -3920,7 +3920,7 @@ algorithm
list<Absyn.EquationItem> e;
Absyn.Exp r;
Option<String> c;
case Absyn.CASE(p, _, l, e, r, c, _)
case Absyn.CASE(p, _, l, e, r, _, c, _)
equation
Print.printBuf("Absyn.CASE(");
Print.printBuf("Pattern(");
Expand All @@ -3935,7 +3935,7 @@ algorithm
printStringCommentOption(c);
Print.printBuf(")");
then ();
case Absyn.ELSE(l, e, r, c, _)
case Absyn.ELSE(l, e, r, _, c, _)
equation
Print.printBuf("Absyn.ELSE(\nLocal Decls(");
printElementitems(l);
Expand Down Expand Up @@ -4543,26 +4543,26 @@ algorithm
list<Absyn.EquationItem> eq;
Absyn.Exp r;
Option<String> c;
case Absyn.CASE(p, _, {}, {}, r, c, _)
case Absyn.CASE(p, _, {}, {}, r, _, c, _)
equation
s1 = printExpStr(p);
s4 = printExpStr(r);
s = stringAppendList({"\tcase (", s1, ") then ", s4, ";"});
then s;
case Absyn.CASE(p, _, l, eq, r, c, _)
case Absyn.CASE(p, _, l, eq, r, _, c, _)
equation
s1 = printExpStr(p);
s2 = unparseLocalElements(3, l);
s3 = unparseLocalEquations(3, eq);
s4 = printExpStr(r);
s = stringAppendList({"\tcase (", s1, ")", s2, s3, "\t then ", s4, ";"});
then s;
case Absyn.ELSE({}, {}, r, c, _)
case Absyn.ELSE({}, {}, r, _, c, _)
equation
s4 = printExpStr(r);
s = stringAppendList({"\telse then ", s4, ";"});
then s;
case Absyn.ELSE(l, eq, r, c, _)
case Absyn.ELSE(l, eq, r, _, c, _)
equation
s2 = unparseLocalElements(3, l);
s3 = unparseLocalEquations(3, eq);
Expand Down Expand Up @@ -6758,41 +6758,45 @@ algorithm
_ := match case_
local
Absyn.Exp pattern;
Absyn.Info patternInfo,info;
Absyn.Info patternInfo,info,resultInfo;
list<Absyn.ElementItem> localDecls;
list<Absyn.EquationItem> equations;
Absyn.Exp result;
Option<String> comment;
case Absyn.CASE(pattern,patternInfo,localDecls,equations,result,comment,info)
case Absyn.CASE(pattern,patternInfo,localDecls,equations,result,resultInfo,comment,info)
equation
Print.printBuf("record Absyn.CASE pattern = ");
printExpAsCorbaString(pattern);
Print.printBuf(", patternInfo = ");
printInfo(patternInfo);
printInfoAsCorbaString(patternInfo);
Print.printBuf(", localDecls = ");
printListAsCorbaString(localDecls, printElementItemAsCorbaString, ",");
Print.printBuf(", equations = ");
printListAsCorbaString(equations, printEquationItemAsCorbaString, ",");
Print.printBuf(", result = ");
printExpAsCorbaString(result);
Print.printBuf(", resultInfo = ");
printInfoAsCorbaString(resultInfo);
Print.printBuf(", comment = ");
printStringCommentOption(comment);
Print.printBuf(", info = ");
printInfo(info);
printInfoAsCorbaString(info);
Print.printBuf(" end Absyn.CASE;");
then ();
case Absyn.ELSE(localDecls,equations,result,comment,info)
case Absyn.ELSE(localDecls,equations,result,resultInfo,comment,info)
equation
Print.printBuf("record Absyn.ELSE localDecls = ");
printListAsCorbaString(localDecls, printElementItemAsCorbaString, ",");
Print.printBuf(", equations = ");
printListAsCorbaString(equations, printEquationItemAsCorbaString, ",");
Print.printBuf(", result = ");
printExpAsCorbaString(result);
Print.printBuf(", resultInfo = ");
printInfoAsCorbaString(resultInfo);
Print.printBuf(", comment = ");
printStringCommentOption(comment);
Print.printBuf(", info = ");
printInfo(info);
printInfoAsCorbaString(info);
Print.printBuf(" end Absyn.ELSE;");
then ();
end match;
Expand Down
19 changes: 14 additions & 5 deletions Compiler/FrontEnd/ExpressionDump.mo
Expand Up @@ -950,19 +950,28 @@ algorithm
local
list<DAE.Pattern> patterns;
list<DAE.Statement> body;
Option<DAE.Exp> result;
DAE.Exp result;
String resultStr,patternsStr,bodyStr;
case DAE.CASE(patterns=patterns, body={}, result=result)
case DAE.CASE(patterns=patterns, body={}, result=SOME(result))
equation
patternsStr = Patternm.patternStr(DAE.PAT_META_TUPLE(patterns));
resultStr = Util.getOptionOrDefault(Util.applyOption(result, printExpStr), "fail()");
resultStr = printExpStr(result);
then stringAppendList({" case ",patternsStr," then ",resultStr,";\n"});
case DAE.CASE(patterns=patterns, body=body, result=result)
case DAE.CASE(patterns=patterns, body={}, result=NONE())
equation
patternsStr = Patternm.patternStr(DAE.PAT_META_TUPLE(patterns));
resultStr = Util.getOptionOrDefault(Util.applyOption(result, printExpStr), "fail()");
then stringAppendList({" case ",patternsStr," then fail();\n"});
case DAE.CASE(patterns=patterns, body=body, result=SOME(result))
equation
patternsStr = Patternm.patternStr(DAE.PAT_META_TUPLE(patterns));
resultStr = printExpStr(result);
bodyStr = stringAppendList(Util.listMap1(body, DAEDump.ppStmtStr, 8));
then stringAppendList({" case ",patternsStr,"\n algorithm\n",bodyStr," then ",resultStr,";\n"});
case DAE.CASE(patterns=patterns, body=body, result=NONE())
equation
patternsStr = Patternm.patternStr(DAE.PAT_META_TUPLE(patterns));
bodyStr = stringAppendList(Util.listMap1(body, DAEDump.ppStmtStr, 8));
then stringAppendList({" case ",patternsStr,"\n algorithm\n",bodyStr," then fail();\n"});
end match;
end printCase2Str;

Expand Down
75 changes: 39 additions & 36 deletions Compiler/FrontEnd/Patternm.mo
Expand Up @@ -806,13 +806,13 @@ algorithm
list<DAE.Statement> body;
Option<DAE.Exp> result;
Integer jump;
Absyn.Info info;
Absyn.Info resultInfo, info;
case ({},_) then {};
case (DAE.CASE(patterns, localDecls, body, result, jump, info)::cases,ht)
case (DAE.CASE(patterns, localDecls, body, result, resultInfo, jump, info)::cases,ht)
equation
(patterns,_) = traversePatternList(patterns, removePatternAsBinding, (ht,info));
cases = filterUnusedAsBindings(cases,ht);
then DAE.CASE(patterns, localDecls, body, result, jump, info)::cases;
then DAE.CASE(patterns, localDecls, body, result, resultInfo, jump, info)::cases;
end match;
end filterUnusedAsBindings;

Expand Down Expand Up @@ -1248,10 +1248,10 @@ algorithm
list<DAE.Element> localDecls;
list<DAE.Statement> body;
Option<DAE.Exp> result;
Absyn.Info info;
Absyn.Info resultInfo, info;
case (case_,0) then case_;
case (DAE.CASE(patterns, localDecls, body, result, _, info), jump)
then DAE.CASE(patterns, localDecls, body, result, jump, info);
case (DAE.CASE(patterns, localDecls, body, result, resultInfo, _, info), jump)
then DAE.CASE(patterns, localDecls, body, result, resultInfo, jump, info);
end match;
end updateMatchCaseJump;

Expand Down Expand Up @@ -1489,9 +1489,9 @@ algorithm
list<SCode.Statement> algs;
list<DAE.Statement> body;
list<Absyn.ElementItem> decls;
Absyn.Info patternInfo,info;
Absyn.Info patternInfo,resultInfo,info;
Integer len;
case (cache,env,Absyn.CASE(pattern=pattern,patternInfo=patternInfo,localDecls=decls,equations=eq1,result=result,info=info),tys,impl,st,performVectorization,pre)
case (cache,env,Absyn.CASE(pattern=pattern,patternInfo=patternInfo,localDecls=decls,equations=eq1,result=result,resultInfo=resultInfo,info=info),tys,impl,st,performVectorization,pre)
equation
(cache,SOME((env,DAE.DAE(caseDecls)))) = addLocalDecls(cache,env,decls,Env.caseScopeName,impl,info);
patterns = MetaUtil.extractListFromTuple(pattern, 0);
Expand All @@ -1500,17 +1500,17 @@ algorithm
(cache,eqAlgs) = Static.fromEquationsToAlgAssignments(eq1,{},cache,env,pre);
algs = SCodeUtil.translateClassdefAlgorithmitems(eqAlgs);
(cache,body) = InstSection.instStatements(cache, env, InnerOuter.emptyInstHierarchy, pre, algs, DAEUtil.addElementSourceFileInfo(DAE.emptyElementSource,patternInfo), SCode.NON_INITIAL(), true, Inst.neverUnroll);
(cache,body,elabResult,resType,st) = elabResultExp(cache,env,body,result,impl,st,performVectorization,pre,patternInfo);
then (cache,DAE.CASE(elabPatterns, caseDecls, body, elabResult, 0, info),elabResult,resType,st);
(cache,body,elabResult,resultInfo,resType,st) = elabResultExp(cache,env,body,result,impl,st,performVectorization,pre,resultInfo);
then (cache,DAE.CASE(elabPatterns, caseDecls, body, elabResult, resultInfo, 0, info),elabResult,resType,st);

// ELSE is the same as CASE, but without pattern
case (cache,env,Absyn.ELSE(localDecls=decls,equations=eq1,result=result,info=info),tys,impl,st,performVectorization,pre)
case (cache,env,Absyn.ELSE(localDecls=decls,equations=eq1,result=result,resultInfo=resultInfo,info=info),tys,impl,st,performVectorization,pre)
equation
// Needs to be same length as any other pattern for the simplification algorithms, etc to work properly
len = listLength(tys);
patterns = Util.listFill(Absyn.CREF(Absyn.WILD()),listLength(tys));
pattern = Util.if_(len == 1, Absyn.CREF(Absyn.WILD()), Absyn.TUPLE(patterns));
(cache,elabCase,elabResult,resType,st) = elabMatchCase(cache,env,Absyn.CASE(pattern,info,decls,eq1,result,NONE(),info),tys,impl,st,performVectorization,pre);
(cache,elabCase,elabResult,resType,st) = elabMatchCase(cache,env,Absyn.CASE(pattern,info,decls,eq1,result,resultInfo,NONE(),info),tys,impl,st,performVectorization,pre);
then (cache,elabCase,elabResult,resType,st);

end match;
Expand All @@ -1529,23 +1529,24 @@ protected function elabResultExp
output Env.Cache outCache;
output list<DAE.Statement> outBody;
output Option<DAE.Exp> resExp;
output Absyn.Info resultInfo;
output Option<DAE.Type> resType;
output Option<Interactive.InteractiveSymbolTable> outSt;
algorithm
(outCache,outBody,resExp,resType,outSt) := matchcontinue (cache,env,body,exp,impl,st,performVectorization,pre,info)
(outCache,outBody,resExp,resultInfo,resType,outSt) := matchcontinue (cache,env,body,exp,impl,st,performVectorization,pre,info)
local
DAE.Exp elabExp;
DAE.Properties prop;
DAE.Type ty;
case (cache,env,body,Absyn.CALL(function_ = Absyn.CREF_IDENT("fail",{}), functionArgs = Absyn.FUNCTIONARGS({},{})),impl,st,performVectorization,pre,info)
then (cache,body,NONE(),NONE(),st);
then (cache,body,NONE(),info,NONE(),st);

case (cache,env,body,exp,impl,st,performVectorization,pre,info)
equation
(cache,elabExp,prop,st) = Static.elabExp(cache,env,exp,impl,st,performVectorization,pre,info);
(body,elabExp) = elabResultExp2(RTOpts.debugFlag("patternmSkipMoveLastExp"),body,elabExp);
(body,elabExp,info) = elabResultExp2(RTOpts.debugFlag("patternmSkipMoveLastExp"),body,elabExp,info);
ty = Types.getPropType(prop);
then (cache,body,SOME(elabExp),SOME(ty),st);
then (cache,body,SOME(elabExp),info,SOME(ty),st);
end matchcontinue;
end elabResultExp;

Expand All @@ -1564,27 +1565,29 @@ protected function elabResultExp2
input Boolean skipPhase;
input list<DAE.Statement> body;
input DAE.Exp elabExp;
input Absyn.Info info;
output list<DAE.Statement> outBody;
output DAE.Exp outExp;
output Absyn.Info outInfo;
algorithm
(outBody,outExp) := matchcontinue (skipPhase,body,elabExp)
(outBody,outExp,outInfo) := matchcontinue (skipPhase,body,elabExp,info)
local
DAE.Exp elabCr1,elabCr2;
list<DAE.Exp> elabCrs1,elabCrs2;
case (true,body,elabExp) then (body,elabExp);
case (_,body,elabCr2 as DAE.CREF(ty=_))
case (true,body,elabExp,info) then (body,elabExp,info);
case (_,body,elabCr2 as DAE.CREF(ty=_),_)
equation
(DAE.STMT_ASSIGN(exp1=elabCr1,exp=elabExp),body) = Util.listSplitLast(body);
(DAE.STMT_ASSIGN(exp1=elabCr1,exp=elabExp,source=DAE.SOURCE(info=info)),body) = Util.listSplitLast(body);
true = Expression.expEqual(elabCr1,elabCr2);
(body,elabExp) = elabResultExp2(false,body,elabExp);
then (body,elabExp);
case (_,body,DAE.TUPLE(elabCrs2))
(body,elabExp,info) = elabResultExp2(false,body,elabExp,info);
then (body,elabExp,info);
case (_,body,DAE.TUPLE(elabCrs2),_)
equation
(DAE.STMT_TUPLE_ASSIGN(expExpLst=elabCrs1,exp=elabExp),body) = Util.listSplitLast(body);
(DAE.STMT_TUPLE_ASSIGN(expExpLst=elabCrs1,exp=elabExp,source=DAE.SOURCE(info=info)),body) = Util.listSplitLast(body);
Util.listThreadMapAllValue(elabCrs1, elabCrs2, Expression.expEqual, true);
(body,elabExp) = elabResultExp2(false,body,elabExp);
then (body,elabExp);
else (body,elabExp);
(body,elabExp,info) = elabResultExp2(false,body,elabExp,info);
then (body,elabExp,info);
else (body,elabExp,info);
end matchcontinue;
end elabResultExp2;

Expand Down Expand Up @@ -1632,13 +1635,13 @@ algorithm
DAE.Exp exp;
DAE.MatchCase case_;
Integer jump;
Absyn.Info info2;
Absyn.Info resultInfo,info2;
case ({},{},_) then {};

case (DAE.CASE(patterns,decls,body,SOME(_),jump,info2)::cases,exp::exps,info)
case (DAE.CASE(patterns,decls,body,SOME(_),resultInfo,jump,info2)::cases,exp::exps,info)
equation
cases = fixCaseReturnTypes2(cases,exps,info);
then DAE.CASE(patterns,decls,body,SOME(exp),jump,info2)::cases;
then DAE.CASE(patterns,decls,body,SOME(exp),resultInfo,jump,info2)::cases;

case ((case_ as DAE.CASE(result=NONE()))::cases,exps,info)
equation
Expand Down Expand Up @@ -1671,14 +1674,14 @@ algorithm
list<DAE.Statement> body;
Option<DAE.Exp> result;
Integer jump;
Absyn.Info info;
Absyn.Info resultInfo,info;
case ({},_,a) then ({},a);
case (DAE.CASE(patterns,decls,body,result,jump,info)::cases,_,a)
case (DAE.CASE(patterns,decls,body,result,resultInfo,jump,info)::cases,_,a)
equation
(body,(_,a)) = DAEUtil.traverseDAEEquationsStmts(body,Expression.traverseSubexpressionsHelper,(func,a));
((result,a)) = Expression.traverseExpOpt(result,func,a);
(cases,a) = traverseCases(cases,func,a);
then (DAE.CASE(patterns,decls,body,result,jump,info)::cases,a);
then (DAE.CASE(patterns,decls,body,result,resultInfo,jump,info)::cases,a);
end match;
end traverseCases;

Expand Down Expand Up @@ -1830,9 +1833,9 @@ algorithm
list<DAE.Statement> body;
Option<DAE.Exp> result;
Integer jump;
Absyn.Info info;
case (DAE.CASE(_,localDecls,body,result,jump,info),pats)
then DAE.CASE(pats,localDecls,body,result,jump,info);
Absyn.Info resultInfo,info;
case (DAE.CASE(_,localDecls,body,result,resultInfo,jump,info),pats)
then DAE.CASE(pats,localDecls,body,result,resultInfo,jump,info);
end match;
end setCasePatterns;

Expand Down

0 comments on commit 6d4cd60

Please sign in to comment.