Skip to content

Commit

Permalink
- Refactoring: SCode.ALG_NORETCALL now takes an expression to simplif…
Browse files Browse the repository at this point in the history
…y traversal

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11996 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 7, 2012
1 parent c00395c commit face260
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 55 deletions.
7 changes: 3 additions & 4 deletions Compiler/FrontEnd/InstExtends.mo
Expand Up @@ -1258,11 +1258,10 @@ algorithm
(cache,whenlst) = fixListTuple2(cache,env,whenlst,ht,fixExp,fixListAlgorithmItem);
then (cache,SCode.ALG_WHEN_A(whenlst,comment,info));

case (cache,env,SCode.ALG_NORETCALL(cref,fargs,comment,info),ht)
case (cache,env,SCode.ALG_NORETCALL(exp,comment,info),ht)
equation
(cache,fargs) = fixFarg(cache,env,fargs,ht);
(cache,cref) = fixCref(cache,env,cref,ht);
then (cache,SCode.ALG_NORETCALL(cref,fargs,comment,info));
(cache,exp) = fixExp(cache,env,exp,ht);
then (cache,SCode.ALG_NORETCALL(exp,comment,info));

case (cache,env,SCode.ALG_RETURN(comment,info),ht) then (cache,SCode.ALG_RETURN(comment,info));

Expand Down
17 changes: 8 additions & 9 deletions Compiler/FrontEnd/InstSection.mo
Expand Up @@ -2541,8 +2541,8 @@ algorithm
then fail();

/* assert(cond,msg) */
case (cache,env,ih,pre,_,SCode.ALG_NORETCALL(functionCall = Absyn.CREF_IDENT(name = "assert"),
functionArgs = Absyn.FUNCTIONARGS(args = {cond,msg},argNames = {}), info = info),source,initial_,impl,unrollForLoops,_)
case (cache,env,ih,pre,_,SCode.ALG_NORETCALL(exp=Absyn.CALL(function_ = Absyn.CREF_IDENT(name = "assert"),
functionArgs = Absyn.FUNCTIONARGS(args = {cond,msg},argNames = {})), info = info),source,initial_,impl,unrollForLoops,_)
equation
(cache,cond_1,cprop,_) = Static.elabExp(cache, env, cond, impl,NONE(), true,pre,info);
(cache, cond_1, cprop) = Ceval.cevalIfConstant(cache, env, cond_1, cprop, impl, info);
Expand All @@ -2556,8 +2556,8 @@ algorithm
(cache,stmts);

/* terminate(msg) */
case (cache,env,ih,pre,_,SCode.ALG_NORETCALL(functionCall = Absyn.CREF_IDENT(name = "terminate"),
functionArgs = Absyn.FUNCTIONARGS(args = {msg},argNames = {}), info = info),source,initial_,impl,unrollForLoops,_)
case (cache,env,ih,pre,_,SCode.ALG_NORETCALL(exp=Absyn.CALL(function_ = Absyn.CREF_IDENT(name = "terminate"),
functionArgs = Absyn.FUNCTIONARGS(args = {msg},argNames = {})), info = info),source,initial_,impl,unrollForLoops,_)
equation
(cache,msg_1,msgprop,_) = Static.elabExp(cache, env, msg, impl,NONE(), true,pre,info);
(cache, msg_1, msgprop) = Ceval.cevalIfConstant(cache, env, msg_1, msgprop, impl, info);
Expand All @@ -2568,8 +2568,8 @@ algorithm
(cache,{stmt});

/* reinit(variable,value) */
case (cache,env,ih,pre,ci_state,SCode.ALG_NORETCALL(functionCall = Absyn.CREF_IDENT(name = "reinit"),
functionArgs = Absyn.FUNCTIONARGS(args = {var,value},argNames = {}), info = info),source,initial_,impl,unrollForLoops,_)
case (cache,env,ih,pre,ci_state,SCode.ALG_NORETCALL(exp=Absyn.CALL(function_ = Absyn.CREF_IDENT(name = "reinit"),
functionArgs = Absyn.FUNCTIONARGS(args = {var,value},argNames = {})), info = info),source,initial_,impl,unrollForLoops,_)
equation
failure(ClassInf.isFunction(ci_state));
(cache,var_1,varprop,_) = Static.elabExp(cache, env, var, impl,NONE(), true,pre,info);
Expand All @@ -2584,12 +2584,11 @@ algorithm
(cache,{stmt});

/* generic NORETCALL */
case (cache,env,ih,pre,ci_state,(SCode.ALG_NORETCALL(functionCall = callFunc, functionArgs = callArgs, info = info)),source,initial_,impl,unrollForLoops,_)
case (cache,env,ih,pre,ci_state,(SCode.ALG_NORETCALL(exp = e, info = info)),source,initial_,impl,unrollForLoops,_)
equation
(cache, DAE.CALL(ap, eexpl, attr), varprop, _) =
Static.elabExp(cache, env, Absyn.CALL(callFunc, callArgs), impl,NONE(), true,pre,info);
Static.elabExp(cache, env, e, impl,NONE(), true,pre,info);
// DO NOT PREFIX THIS PATH; THE PREFIX IS ONLY USED FOR COMPONENTS, NOT NAMES OF FUNCTIONS....
// ap = PrefixUtil.prefixPath(ap,pre);
(cache,eexpl) = PrefixUtil.prefixExpList(cache, env, ih, eexpl, pre);
source = DAEUtil.addElementSourceFileInfo(source, info);
stmt = DAE.STMT_NORETCALL(DAE.CALL(ap,eexpl,attr),source);
Expand Down
26 changes: 6 additions & 20 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -402,8 +402,7 @@ public uniontype Statement "The Statement type describes one algorithm statement
end ALG_WHEN_A;

record ALG_NORETCALL
Absyn.ComponentRef functionCall "functionCall" ;
Absyn.FunctionArgs functionArgs "functionArgs; general fcalls without return value" ;
Absyn.Exp exp;
Option<Comment> comment;
Absyn.Info info;
end ALG_NORETCALL;
Expand Down Expand Up @@ -2107,7 +2106,7 @@ algorithm
abranches = List.threadTuple(conditions,algsLst);
then Absyn.ALGORITHMITEM(Absyn.ALG_WHEN_A(boolExpr,algs1,abranches),NONE(),info);

case ALG_NORETCALL(functionCall,functionArgs,comment,info)
case ALG_NORETCALL(Absyn.CALL(function_=functionCall,functionArgs=functionArgs),comment,info)
then Absyn.ALGORITHMITEM(Absyn.ALG_NORETCALL(functionCall,functionArgs),NONE(),info);

case ALG_RETURN(comment,info)
Expand Down Expand Up @@ -2209,10 +2208,8 @@ algorithm
lst_lst = List.map1r(List.map(branches,Util.tuple22),findIteratorInStatements,id);
lst=List.flatten(lst_1::lst_lst);
then lst;
case (id,ALG_NORETCALL(functionArgs = funcArgs))
equation
lst=Absyn.findIteratorInFunctionArgs(id,funcArgs);
then lst;
case (id,ALG_NORETCALL(exp = e_1))
then Absyn.findIteratorInExp(id,e_1);
case (id,ALG_TRY(tryBody = algLst_1))
equation
lst=findIteratorInStatements(id,algLst_1);
Expand Down Expand Up @@ -3010,22 +3007,11 @@ algorithm
then
(ALG_WHEN_A(branches, comment, info), tup);

case (ALG_NORETCALL(cr1, Absyn.FUNCTIONARGS(expl1, args), comment, info), tup)
case (ALG_NORETCALL(e1, comment, info), (traverser, arg))
equation
(cr1, (traverser, arg)) = traverseComponentRefExps(cr1, tup);
((expl1, arg)) = Absyn.traverseExpList(expl1, traverser, arg);
(args, tup) = List.mapFold(args, traverseNamedArgExps, (traverser, arg));
then
(ALG_NORETCALL(cr1, Absyn.FUNCTIONARGS(expl1, args), comment, info), tup);

case (ALG_NORETCALL(cr1, Absyn.FOR_ITER_FARG(e1, iters), comment, info), tup)
equation
(cr1, (traverser, arg)) = traverseComponentRefExps(cr1, tup);
((e1, arg)) = traverser((e1, arg));
(iters, tup) = List.mapFold(iters, traverseForIteratorExps,
(traverser, arg));
then
(ALG_NORETCALL(cr1, Absyn.FOR_ITER_FARG(e1, iters), comment, info), tup);
(ALG_NORETCALL(e1, comment, info), (traverser, arg));

else then (inStatement, inTuple);
end match;
Expand Down
7 changes: 0 additions & 7 deletions Compiler/FrontEnd/SCodeDependency.mo
Expand Up @@ -1558,13 +1558,6 @@ algorithm
then
((stmt, env));

case ((stmt as SCode.ALG_NORETCALL(functionCall = cref, info = info), env))
equation
analyseCref(cref, env, info);
(_, _) = SCode.traverseStatementExps(stmt, (traverseExp, (env, info)));
then
((stmt, env));

case ((stmt, env))
equation
info = SCode.getStatementInfo(stmt);
Expand Down
9 changes: 0 additions & 9 deletions Compiler/FrontEnd/SCodeFlattenImports.mo
Expand Up @@ -463,15 +463,6 @@ algorithm
then
((stmt, env));

case ((stmt as SCode.ALG_NORETCALL(functionCall = cref,
functionArgs = fargs, comment = cmt, info = info), env))
equation
cref = SCodeLookup.lookupComponentRef(cref, env, info);
stmt = SCode.ALG_NORETCALL(cref, fargs, cmt, info);
(stmt, _) = SCode.traverseStatementExps(stmt, (traverseExp, (env, info)));
then
((stmt, env));

case ((stmt, env))
equation
info = SCode.getStatementInfo(stmt);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -969,7 +969,7 @@ algorithm
then SCode.ALG_WHEN_A(sbranches,comment,info);

case (Absyn.ALG_NORETCALL(functionCall,functionArgs),comment,info)
then SCode.ALG_NORETCALL(functionCall,functionArgs,comment,info);
then SCode.ALG_NORETCALL(Absyn.CALL(functionCall,functionArgs),comment,info);

case (Absyn.ALG_RETURN(),comment,info)
then SCode.ALG_RETURN(comment,info);
Expand Down
5 changes: 2 additions & 3 deletions Compiler/susan_codegen/SimCode/SCodeDumpTpl.tpl
Expand Up @@ -444,10 +444,9 @@ match statement
case ALG_WHILE(__) then dumpWhileStatement(statement)
case ALG_WHEN_A(__) then dumpWhenStatement(statement)
case ALG_NORETCALL(__) then
let func_str = AbsynDumpTpl.dumpCref(functionCall)
let args_str = AbsynDumpTpl.dumpFunctionArgs(functionArgs)
let exp_str = AbsynDumpTpl.dumpExp(exp)
let cmt_str = dumpCommentOpt(comment)
'<%func_str%>(<%args_str%>)<%cmt_str%>;'
'<%exp_str%><%cmt_str%>;'
case ALG_RETURN(__) then
let cmt_str = dumpCommentOpt(comment)
'return<%cmt_str%>;'
Expand Down
3 changes: 1 addition & 2 deletions Compiler/susan_codegen/SimCode/SCodeTV.mo
Expand Up @@ -602,8 +602,7 @@ package SCode
end ALG_WHEN_A;

record ALG_NORETCALL
Absyn.ComponentRef functionCall;
Absyn.FunctionArgs functionArgs;
Absyn.Exp exp;
Option<Comment> comment;
Absyn.Info info;
end ALG_NORETCALL;
Expand Down

0 comments on commit face260

Please sign in to comment.