Skip to content

Commit

Permalink
- Partial fix for problems with traverseExp
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Oct 29, 2010
1 parent 9d58064 commit 0fba28c
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 264 deletions.
24 changes: 12 additions & 12 deletions Compiler/Algorithm.mo
Expand Up @@ -687,25 +687,25 @@ end getAllExps;

public function getAllExpsStmts "function: getAllExpsStmts

This function takes a list of statements and returns all expressions
This function takes a list of statements and returns all expressions and subexpressions
in all statements.
"
input list<Statement> stmts;
output list<DAE.Exp> exps;
list<list<DAE.Exp>> expslist;
list<Statement> stms;
algorithm
(stms,exps) := DAEUtil.traverseDAEEquationsStmts(stmts,getAllExpsStmtsCollecter,{});
(_,exps) := DAEUtil.traverseDAEEquationsStmts(stmts,getAllExpsStmtsCollector,{});
end getAllExpsStmts;

function getAllExpsStmtsCollecter
input DAE.Exp exp;
input list<DAE.Exp> inExps;
output DAE.Exp oexp;
output list<DAE.Exp> outExps;
function getAllExpsStmtsCollector
input tuple<DAE.Exp,list<DAE.Exp>> itpl;
output tuple<DAE.Exp,list<DAE.Exp>> otpl;
algorithm
oexp:=exp;
outExps:=listAppend(inExps,{exp});
end getAllExpsStmtsCollecter;
otpl := matchcontinue itpl
local
DAE.Exp exp;
list<DAE.Exp> inExps;
case ((exp,inExps)) then Expression.traverseExp(exp,Expression.expressionCollector,inExps);
end matchcontinue;
end getAllExpsStmtsCollector;

end Algorithm;
45 changes: 20 additions & 25 deletions Compiler/BackendDAECreate.mo
Expand Up @@ -994,8 +994,8 @@ algorithm
equation
e1_1 = Inline.inlineExp(e1,(SOME(funcs),{DAE.NORM_INLINE()}));
e2_1 = Inline.inlineExp(e2,(SOME(funcs),{DAE.NORM_INLINE()}));
(e1_2,_) = BackendDAEUtil.extendArrExp(e1_1,SOME(funcs));
(e2_2,_) = BackendDAEUtil.extendArrExp(e2_1,SOME(funcs));
((e1_2,_)) = BackendDAEUtil.extendArrExp((e1_1,SOME(funcs)));
((e2_2,_)) = BackendDAEUtil.extendArrExp((e2_1,SOME(funcs)));
e1_3 = ExpressionSimplify.simplify(e1_2);
e2_3 = ExpressionSimplify.simplify(e2_2);
then
Expand All @@ -1005,8 +1005,8 @@ algorithm
equation
e1_1 = Inline.inlineExp(e1,(SOME(funcs),{DAE.NORM_INLINE()}));
e2_1 = Inline.inlineExp(e2,(SOME(funcs),{DAE.NORM_INLINE()}));
(e1_2,_) = BackendDAEUtil.extendArrExp(e1_1,SOME(funcs));
(e2_2,_) = BackendDAEUtil.extendArrExp(e2_1,SOME(funcs));
((e1_2,_)) = BackendDAEUtil.extendArrExp((e1_1,SOME(funcs)));
((e2_2,_)) = BackendDAEUtil.extendArrExp((e2_1,SOME(funcs)));
e1_3 = ExpressionSimplify.simplify(e1_2);
e2_3 = ExpressionSimplify.simplify(e2_2);
then
Expand Down Expand Up @@ -1844,21 +1844,15 @@ end states;
protected function statesExp
"function: statesExp
Helper function to states."
input DAE.Exp inExp;
input BackendDAE.BinTree inBinTree;
output DAE.Exp outExp;
output BackendDAE.BinTree outBinTree;
input tuple<DAE.Exp,BackendDAE.BinTree> itpl;
output tuple<DAE.Exp,BackendDAE.BinTree> otpl;
algorithm
(outExp,outBinTree) := matchcontinue (inExp,inBinTree)
otpl := matchcontinue itpl
local
DAE.Exp e;
BackendDAE.BinTree bt;
case (inExp,bt)
equation
((e,bt)) = Expression.traverseExp(inExp,traversingstatesExpFinder,bt);
then
(e,bt);
case (e,bt) then (e,bt);
case ((e,bt)) then Expression.traverseExp(e,traversingstatesExpFinder,bt);
case ((e,bt)) then ((e,bt));
end matchcontinue;
end statesExp;

Expand Down Expand Up @@ -1901,12 +1895,13 @@ end processDelayExpressions;

protected function transformDelayExpressions
"Helper for processDelayExpressions()"
input DAE.Exp inExp;
input Integer inInteger;
output DAE.Exp outExp;
output Integer outInteger;
input tuple<DAE.Exp,Integer> itpl;
output tuple<DAE.Exp,Integer> otpl;
DAE.Exp e;
Integer i;
algorithm
((outExp, outInteger)) := Expression.traverseExp(inExp, transformDelayExpression, inInteger);
(e,i) := itpl;
otpl := Expression.traverseExp(e, transformDelayExpression, i);
end transformDelayExpressions;

protected function transformDelayExpression
Expand Down Expand Up @@ -2656,7 +2651,7 @@ algorithm
case((DAE.CALL(Absyn.IDENT(name = "der"),{e1},tuple_ = false,builtin = true),(vars,funcs))) equation
e1 = Derive.differentiateExpTime(e1,(vars,funcs));
e1 = ExpressionSimplify.simplify(e1);
(_,bt) = statesExp(e1,BackendDAE.emptyBintree);
((_,bt)) = statesExp((e1,BackendDAE.emptyBintree));
(newStates,_) = BackendDAEUtil.bintreeToList(bt);
vars = updateStatesVars(vars,newStates);
then ((e1,(vars,funcs)));
Expand Down Expand Up @@ -3230,8 +3225,8 @@ algorithm
// array types to array equations
case ((e1 as DAE.CREF(componentRef=cr1,ty=DAE.ET_ARRAY(arrayDimensions=ad)),e2),source,inFuncs)
equation
(e1_1,_) = BackendDAEUtil.extendArrExp(e1,SOME(inFuncs));
(e2_1,_) = BackendDAEUtil.extendArrExp(e2,SOME(inFuncs));
((e1_1,_)) = BackendDAEUtil.extendArrExp((e1,SOME(inFuncs)));
((e2_1,_)) = BackendDAEUtil.extendArrExp((e2,SOME(inFuncs)));
e2_2 = ExpressionSimplify.simplify(e2_1);
ds = Util.listMap(ad, Expression.dimensionSize);
then
Expand All @@ -3241,8 +3236,8 @@ algorithm
equation
tp = Expression.typeof(e1);
false = DAEUtil.expTypeComplex(tp);
(e1_1,_) = BackendDAEUtil.extendArrExp(e1,SOME(inFuncs));
(e2_1,_) = BackendDAEUtil.extendArrExp(e2,SOME(inFuncs));
((e1_1,_)) = BackendDAEUtil.extendArrExp((e1,SOME(inFuncs)));
((e2_1,_)) = BackendDAEUtil.extendArrExp((e2,SOME(inFuncs)));
e2_2 = ExpressionSimplify.simplify(e2_1);
eqn = BackendEquation.generateEQUATION((e1_1,e2_2),source);
then
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackendDAEOptimize.mo
Expand Up @@ -270,7 +270,7 @@ algorithm
// check List
failure(_ = Util.listFindWithCompareFunc(crlst,sc,ComponentReference.crefEqualNoStringCompare,false));
// extend cr
(e1,_) = BackendDAEUtil.extendArrExp(DAE.CREF(sc,ty),NONE());
((e1,_)) = BackendDAEUtil.extendArrExp((DAE.CREF(sc,ty),NONE()));
// add
repl_1 = VarTransform.addReplacement(repl, sc, e1);
then
Expand Down
50 changes: 21 additions & 29 deletions Compiler/BackendDAEUtil.mo
Expand Up @@ -1402,7 +1402,7 @@ algorithm
/* Special Case for unextended arrays */
case ((e as DAE.CREF(componentRef = cr,ty = DAE.ET_ARRAY(arrayDimensions=_))),vars)
equation
(e1,_) = extendArrExp(e,NONE());
((e1,_)) = extendArrExp((e,NONE()));
res = statesAndVarsExp(e1, vars);
then
res;
Expand Down Expand Up @@ -2724,19 +2724,15 @@ end bintreeDepth;

public function extendArrExp "
Author: Frenkel TUD 2010-07"
input DAE.Exp inExp;
input Option<DAE.FunctionTree> infuncs;
output DAE.Exp outExp;
output Option<DAE.FunctionTree> outfuncs;
input tuple<DAE.Exp,Option<DAE.FunctionTree>> itpl;
output tuple<DAE.Exp,Option<DAE.FunctionTree>> otpl;
algorithm
(outExp,outfuncs) := matchcontinue(inExp,infuncs)
local DAE.Exp e;
case(inExp,infuncs)
equation
((e,outfuncs)) = Expression.traverseExp(inExp, traversingextendArrExp, infuncs);
then
(e,outfuncs);
case(inExp,infuncs) then (inExp,infuncs);
otpl := matchcontinue itpl
local
DAE.Exp e;
Option<DAE.FunctionTree> funcs;
case ((e,funcs)) then Expression.traverseExp(e, traversingextendArrExp, funcs);
case _ then itpl;
end matchcontinue;
end extendArrExp;

Expand Down Expand Up @@ -2888,19 +2884,15 @@ end collateAlgorithm;

public function collateArrExp "
Author: Frenkel TUD 2010-07"
input DAE.Exp inExp;
input Option<DAE.FunctionTree> infuncs;
output DAE.Exp outExp;
output Option<DAE.FunctionTree> outfuncs;
input tuple<DAE.Exp,Option<DAE.FunctionTree>> itpl;
output tuple<DAE.Exp,Option<DAE.FunctionTree>> otpl;
algorithm
(outExp,outfuncs) := matchcontinue(inExp,infuncs)
local DAE.Exp e;
case(inExp,infuncs)
equation
((e,outfuncs)) = Expression.traverseExp(inExp, traversingcollateArrExp, infuncs);
then
(e,outfuncs);
case(inExp,infuncs) then (inExp,infuncs);
otpl := matchcontinue itpl
local
DAE.Exp e;
Option<DAE.FunctionTree> funcs;
case ((e,funcs)) then Expression.traverseExp(e, traversingcollateArrExp, funcs);
case itpl then itpl;
end matchcontinue;
end collateArrExp;

Expand All @@ -2919,28 +2911,28 @@ algorithm outExp := matchcontinue(inExp)
case ((e as DAE.MATRIX(ty=ty,integer=i,scalar=(((e1 as DAE.CREF(componentRef = cr)),_)::_)::_),funcs))
equation
e1_1 = Expression.expStripLastSubs(e1);
(e1_2,_) = extendArrExp(e1_1,funcs);
((e1_2,_)) = extendArrExp((e1_1,funcs));
true = Expression.expEqual(e,e1_2);
then
((e1_1,funcs));
case ((e as DAE.MATRIX(ty=ty,integer=i,scalar=(((e1 as DAE.UNARY(exp = DAE.CREF(componentRef = cr))),_)::_)::_),funcs))
equation
e1_1 = Expression.expStripLastSubs(e1);
(e1_2,_) = extendArrExp(e1_1,funcs);
((e1_2,_)) = extendArrExp((e1_1,funcs));
true = Expression.expEqual(e,e1_2);
then
((e1_1,funcs));
case ((e as DAE.ARRAY(ty=ty,scalar=b,array=(e1 as DAE.CREF(componentRef = cr))::_),funcs))
equation
e1_1 = Expression.expStripLastSubs(e1);
(e1_2,_) = extendArrExp(e1_1,funcs);
((e1_2,_)) = extendArrExp((e1_1,funcs));
true = Expression.expEqual(e,e1_2);
then
((e1_1,funcs));
case ((e as DAE.ARRAY(ty=ty,scalar=b,array=(e1 as DAE.UNARY(exp = DAE.CREF(componentRef = cr)))::_),funcs))
equation
e1_1 = Expression.expStripLastSubs(e1);
(e1_2,_) = extendArrExp(e1_1,funcs);
((e1_2,_)) = extendArrExp((e1_1,funcs));
true = Expression.expEqual(e,e1_2);
then
((e1_1,funcs));
Expand Down
22 changes: 0 additions & 22 deletions Compiler/CevalScript.mo
Expand Up @@ -4392,28 +4392,6 @@ algorithm
functionName := ModUtil.pathStringReplaceDot(functionPath, "_");
end generateFunctionName;

protected constant String constCfileHeader =
"#include \"modelica.h\"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#if defined(_MSC_VER)
#define DLLExport __declspec( dllexport )
#else
#define DLLExport /* nothing */
#endif

#if !defined(MODELICA_ASSERT)
#define MODELICA_ASSERT(cond,msg) { if (!(cond)) fprintf(stderr,\"Modelica Assert: %s!\\n\", msg); }
#endif
#if !defined(MODELICA_TERMINATE)
#define MODELICA_TERMINATE(msg) { fprintf(stderr,\"Modelica Terminate: %s!\\n\", msg); fflush(stderr); }
#endif


";

public function cevalGenerateFunction "function: cevalGenerateFunction
Generates code for a given function name."
input Env.Cache inCache;
Expand Down
28 changes: 13 additions & 15 deletions Compiler/ConnectionGraph.mo
Expand Up @@ -1151,42 +1151,40 @@ end evalIsRoot;

protected function evalIsRootHelper
"Helper function for evalIsRoot."
input DAE.Exp inExp;
input list<DAE.ComponentRef> inRoots;
output DAE.Exp outExp;
output list<DAE.ComponentRef> outRoots;
input tuple<DAE.Exp,list<DAE.ComponentRef>> inRoots;
output tuple<DAE.Exp,list<DAE.ComponentRef>> outRoots;
algorithm
(outExp,outRoots) := matchcontinue(inExp,inRoots)
outRoots := matchcontinue inRoots
local
DAE.Exp exp;
DAE.Exp inExp,exp;
list<DAE.ComponentRef> roots;
DAE.ComponentRef cref;
Boolean result;

// no roots, same exp
case (exp, {}) then (exp, {});
case ((exp, {})) then ((exp, {}));
// deal with Connections.isRoot
case (DAE.CALL(path=Absyn.QUALIFIED("Connections", Absyn.IDENT("isRoot")),
expLst={DAE.CREF(componentRef = cref)}), roots)
case ((inExp as DAE.CALL(path=Absyn.QUALIFIED("Connections", Absyn.IDENT("isRoot")),
expLst={DAE.CREF(componentRef = cref)}), roots))
equation
result = Util.listContainsWithCompareFunc(cref, roots, ComponentReference.crefEqual);
Debug.fprintln("cgraph", "- ConnectionGraph.evalIsRootHelper: " +&
ExpressionDump.printExpStr(inExp) +& " = " +& Util.if_(result, "true", "false"));
then (DAE.BCONST(result), roots);
then ((DAE.BCONST(result), roots));
// deal with NOT Connections.isRoot
case (DAE.LUNARY(DAE.NOT(), DAE.CALL(path=Absyn.QUALIFIED("Connections", Absyn.IDENT("isRoot")),
expLst={DAE.CREF(componentRef = cref)})), roots)
case ((inExp as DAE.LUNARY(DAE.NOT(), DAE.CALL(path=Absyn.QUALIFIED("Connections", Absyn.IDENT("isRoot")),
expLst={DAE.CREF(componentRef = cref)})), roots))
equation
result = Util.listContainsWithCompareFunc(cref, roots, ComponentReference.crefEqual);
result = boolNot(result);
Debug.fprintln("cgraph", "- ConnectionGraph.evalIsRootHelper: " +&
ExpressionDump.printExpStr(inExp) +& " = " +& Util.if_(result, "true", "false"));
then (DAE.BCONST(result), roots);
then ((DAE.BCONST(result), roots));
// no replacement needed
case (exp, roots)
case ((exp, roots))
equation
// Debug.fprintln("cgraph", ExpressionDump.printExpStr(exp) +& " not found in roots!");
then (exp, roots);
then ((exp, roots));
end matchcontinue;
end evalIsRootHelper;

Expand Down

0 comments on commit 0fba28c

Please sign in to comment.