Skip to content

Commit

Permalink
- replace equality(x = y) with stringEqual/intEq/realEq
Browse files Browse the repository at this point in the history
- added more comments and updated some of the formatting
- use Exp.crefEqualNoStringCompare in ConnectUtil.setsEqual as we cannot have stringified crefs there.
- proper dimension printing in PrefixUtil.printPrefixStr
- removed some debug prints from SCodeUtil.mo to make it faster


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5770 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Jul 1, 2010
1 parent 4b6744d commit 6edafbc
Show file tree
Hide file tree
Showing 23 changed files with 1,592 additions and 1,354 deletions.
21 changes: 12 additions & 9 deletions Compiler/Ceval.mo
Expand Up @@ -2088,7 +2088,6 @@ algorithm
print("\n");
print("prefix =");print(Exp.printComponentRefStr(prefix));print("\n");*/
// print("env:");print(Env.printEnvStr(env));

then
(cache,res);
end matchcontinue;
Expand Down Expand Up @@ -4019,6 +4018,7 @@ algorithm
String RowString,matrixDimensionString;
Env.Cache cache;
Values.Value v;

case (cache,env,s1,impl,st,matrixDimension,row,{},msg)
equation
s2 = DAE.ICONST(row);
Expand All @@ -4032,12 +4032,14 @@ algorithm
(cache,retExp) = cevalBuiltinDiagonal2(cache,env, s1, impl, st, matrixDimension, newRow, {v}, msg);
then
(cache,retExp);

case (cache,env,s1,impl,st,matrixDimension,row,listIN,msg)
equation
s2 = DAE.ICONST(row);
(cache,Values.REAL(rv2),_) = ceval(cache,env, DAE.ASUB(s1,{s2}), impl, st, NONE, msg);

failure(equality(matrixDimension = row));

false = intEq(matrixDimension, row);

correctDim = matrixDimension - 1;
zeroList = Util.listFill(Values.REAL(0.0), correctDim);
correctPlace = row - 1;
Expand Down Expand Up @@ -4068,7 +4070,8 @@ algorithm
equation
s2 = DAE.ICONST(row);
(cache,Values.INTEGER(rv2),_) = ceval(cache,env, DAE.ASUB(s1,{s2}), impl, st, NONE, msg);
failure(equality(matrixDimension = row));

false = intEq(matrixDimension, row);

correctDim = matrixDimension - 1;
zeroList = Util.listFill(Values.INTEGER(0), correctDim);
Expand All @@ -4083,7 +4086,7 @@ algorithm
(cache,retExp);
case (cache,env,s1,impl,st,matrixDimension,row,listIN,msg)
equation
equality(matrixDimension = row);
true = intEq(matrixDimension, row);
then
(cache,listIN);
case (_,_,_,_,_,matrixDimension,row,list_,MSG())
Expand Down Expand Up @@ -4778,7 +4781,7 @@ algorithm
case (cache,env,DAE.CREF_IDENT(ident = id,subscriptLst = subsc),DAE.EQBOUND(exp = exp,constant_ = DAE.C_CONST()),impl,MSG())
equation
DAE.REDUCTION(path = Absyn.IDENT(name = rfn),expr = elexp,ident = iter,range = iterexp) = exp;
equality(rfn = "array");
true = stringEqual(rfn, "array");
Debug.fprintln("ceval", "#- Ceval.cevalCrefBinding: Array evaluation");
then
fail();
Expand All @@ -4787,7 +4790,7 @@ algorithm
case (cache,env,cr,DAE.EQBOUND(exp = exp,constant_ = DAE.C_CONST()),impl,msg)
equation
DAE.REDUCTION(path = Absyn.IDENT(name = rfn),expr = elexp,ident = iter,range = iterexp) = exp;
failure(equality(rfn = "array"));
false = stringEqual(rfn, "array");
cr_1 = Exp.crefStripLastSubs(cr) "lookup without subscripts, so dimension sizes can be determined." ;
subsc = Exp.crefLastSubs(cr);
(cache,_,tp,_,_,_,_,_) = Lookup.lookupVar(cache,env, cr_1) "DAE.CREF_IDENT(id,{})" ;
Expand Down Expand Up @@ -5436,7 +5439,7 @@ algorithm
then HASHTABLE(hashvec,varr_1,bsize,n);
case (_,_)
equation
print("-CevalHashTable.add failed\n");
print("- CevalHashTable.add failed\n");
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -5473,7 +5476,7 @@ algorithm
then HASHTABLE(hashvec_1,varr_1,bsize,n_1);
case (_,_)
equation
print("-CevalHashTable.addNoUpdCheck failed\n");
print("- CevalHashTable.addNoUpdCheck failed\n");
then
fail();
end matchcontinue;
Expand Down
113 changes: 75 additions & 38 deletions Compiler/CevalScript.mo

Large diffs are not rendered by default.

121 changes: 63 additions & 58 deletions Compiler/Cevalfunc.mo
Expand Up @@ -361,58 +361,62 @@ helper function for setValuesInRecord"
input list<String> invarName; // eq
input list<Values.Value> inValue; // eq
output DAE.Var oType;
algorithm oType := matchcontinue(inVars,invarName,inValue)
local
String varName3,varName2;
list<String> varNames;
DAE.Attributes a;
Boolean p;
DAE.Type t,ty2;
DAE.Binding b;
Values.Value val;
list<Values.Value> values;
DAE.Var tv,tv1;
list<DAE.Var> tvs,rest;
Option<DAE.Const> constOfForIteratorRange;
list<DAE.Var> typeslst,lv2;
list<Values.Value> vals;
list<String> names;
Absyn.Path fpath;

algorithm
oType := matchcontinue(inVars,invarName,inValue)
local
String varName3,varName2;
list<String> varNames;
DAE.Attributes a;
Boolean p;
DAE.Type t,ty2;
DAE.Binding b;
Values.Value val;
list<Values.Value> values;
DAE.Var tv,tv1;
list<DAE.Var> tvs,rest;
Option<DAE.Const> constOfForIteratorRange;
list<DAE.Var> typeslst,lv2;
list<Values.Value> vals;
list<String> names;
Absyn.Path fpath;

// unbound, try to take the value from the type
case(DAE.TYPES_VAR(varName2,a,p,t,DAE.UNBOUND(),constOfForIteratorRange),{},{})
equation
val = typeOfValue(t);
tv = DAE.TYPES_VAR(varName2,a,p,t,DAE.VALBOUND(val),constOfForIteratorRange);
then
tv;
// value bound
case(tv as DAE.TYPES_VAR(binding = DAE.VALBOUND(val)),{},{})
then
tv;
// complex types (records)
case(DAE.TYPES_VAR(varName3,a,p,t as (DAE.T_COMPLEX(complexVarLst = typeslst),_),b,constOfForIteratorRange),
varName2::varNames, (val as Values.RECORD(fpath,vals,names,-1))::values)
equation
equality(varName3 = varName2);
lv2 = setValuesInRecord(typeslst,names,vals);
ty2 = (DAE.T_COMPLEX(ClassInf.RECORD(fpath) ,lv2 , NONE, NONE),NONE);
tv = DAE.TYPES_VAR(varName3,a,p,ty2,DAE.VALBOUND(val),constOfForIteratorRange);
then tv;
case(DAE.TYPES_VAR(varName3,a,p,t,b,constOfForIteratorRange) ,varName2::varNames, val::values)
equation
equality(varName3 = varName2);
tv = DAE.TYPES_VAR(varName3,a,p,t,DAE.VALBOUND(val),constOfForIteratorRange);
then tv;
case(tv1,varName3::varNames, val::values)
equation
tv = setValuesInRecord2(tv1,varNames,values);
then tv;
end matchcontinue;
// unbound, try to take the value from the type
case(DAE.TYPES_VAR(varName2,a,p,t,DAE.UNBOUND(),constOfForIteratorRange),{},{})
equation
val = typeOfValue(t);
tv = DAE.TYPES_VAR(varName2,a,p,t,DAE.VALBOUND(val),constOfForIteratorRange);
then
tv;

// value bound
case(tv as DAE.TYPES_VAR(binding = DAE.VALBOUND(val)),{},{})
then
tv;

// complex types (records)
case(DAE.TYPES_VAR(varName3,a,p,t as (DAE.T_COMPLEX(complexVarLst = typeslst),_),b,constOfForIteratorRange),
varName2::varNames, (val as Values.RECORD(fpath,vals,names,-1))::values)
equation
true = stringEqual(varName3, varName2);
lv2 = setValuesInRecord(typeslst,names,vals);
ty2 = (DAE.T_COMPLEX(ClassInf.RECORD(fpath) ,lv2 , NONE, NONE),NONE);
tv = DAE.TYPES_VAR(varName3,a,p,ty2,DAE.VALBOUND(val),constOfForIteratorRange);
then tv;

case(DAE.TYPES_VAR(varName3,a,p,t,b,constOfForIteratorRange) ,varName2::varNames, val::values)
equation
true = stringEqual(varName3, varName2);
tv = DAE.TYPES_VAR(varName3,a,p,t,DAE.VALBOUND(val),constOfForIteratorRange);
then tv;

case(tv1,varName3::varNames, val::values)
equation
tv = setValuesInRecord2(tv1,varNames,values);
then tv;
end matchcontinue;
end setValuesInRecord2;

protected function makeComplexEnv "Function: makeComplexEnv
protected function makeComplexEnv "function: makeComplexEnv
This function extends the env with a complex var."
input Env.Env env;
input list<DAE.Var> tvars;
Expand Down Expand Up @@ -1170,7 +1174,7 @@ algorithm oenv := matchcontinue(env,inVal,inCr)
end matchcontinue;
end setQualValue;

protected function setQualValue2 "Function: setQualValue2
protected function setQualValue2 "function: setQualValue2
Helper function for setQualValue"
input Env.AvlTree env;
input Values.Value inVal;
Expand All @@ -1197,26 +1201,27 @@ algorithm oenv := matchcontinue(env,inVal,inCr ,hashKey)

case(Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,rval as Env.VAR(fv,c,i,varEnv))),h,oleft,oright), inVal, inCr as Absyn.CREF_QUAL(str,_,child) ,hashKey)
equation
equality(rkey = str);
true = stringEqual(rkey, str);
true = Absyn.crefIsIdent(child);
varEnv2 = setValue(inVal,varEnv,Absyn.CREF(child));
then
Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,Env.VAR(fv,c,i,varEnv2))),h,oleft,oright);

/*case(Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,rval as Env.VAR(fv,c,i,varEnv))),h,oleft,oright), inVal, inCr as Absyn.CREF_QUAL(str,_,child) ,hashKey)
/*
case(Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,rval as Env.VAR(fv,c,i,varEnv))),h,oleft,oright), inVal, inCr as Absyn.CREF_QUAL(str,_,child) ,hashKey)
equation
equality(rkey = str);
true = stringEqual(rkey, str);
varEnv2 = setQualValue(varEnv,inVal,child);
then
Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,Env.VAR(fv,c,i,varEnv2))),h,oleft,oright);
// Check right
then
Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,Env.VAR(fv,c,i,varEnv2))),h,oleft,oright);
// Check right
case(Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,rval)),h,oleft,SOME(right)), inVal, inCr ,hashKey)
equation
true = System.strcmp(key,rkey) > 0;
right = setQualValue2(right,inVal,inCr,hashKey);
then
Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,rval)),h,oleft,SOME(right));
// Check left
// Check left
case(Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,rval)),h,SOME(left),oright), inVal, inCr ,hashKey)
equation
true = System.strcmp(key,rkey) 0;
Expand All @@ -1225,7 +1230,7 @@ algorithm oenv := matchcontinue(env,inVal,inCr ,hashKey)
left = setQualValue2(left,inVal,inCr,hashKey);
then
Env.AVLTREENODE(SOME(Env.AVLTREEVALUE(rkey,rval)),h,SOME(left),oright);
*/
*/
end matchcontinue;
end setQualValue2;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/ConnectUtil.mo
Expand Up @@ -974,15 +974,15 @@ algorithm
// deal with non empty Connect.EQU
case (Connect.EQU((cr1,_)::equRest1), Connect.EQU((cr2,_)::equRest2))
equation
true = Exp.crefEqual(cr1, cr2); // equality(cr1 = cr2);
true = Exp.crefEqualNoStringCompare(cr1, cr2); // equality(cr1 = cr2);
true = setsEqual(Connect.EQU(equRest1),Connect.EQU(equRest2));
then
true;
// deal with non empty Connect.FLOW
case (Connect.FLOW((cr1,face1,_)::flowRest1), Connect.FLOW((cr2,face2,_)::flowRest2))
equation
true = faceEqual(face1, face2);
true = Exp.crefEqual(cr1, cr2); // equality(cr1 = cr2);
true = Exp.crefEqualNoStringCompare(cr1, cr2); // equality(cr1 = cr2);
true = setsEqual(Connect.FLOW(flowRest1),Connect.FLOW(flowRest2));
then
true;
Expand Down
89 changes: 49 additions & 40 deletions Compiler/Derive.mo
Expand Up @@ -815,7 +815,7 @@ algorithm
end matchcontinue;
end differentiateFunctionTime1;

protected function checkDerFunctionConds"
protected function checkDerFunctionConds "
Author: Frenkel TUD"
input list<Boolean> inblst;
input list<tuple<Integer,DAE.derivativeCond>> crlst;
Expand All @@ -824,53 +824,62 @@ Author: Frenkel TUD"
output list<Boolean> outblst;
algorithm
blst := matchcontinue(inblst,crlst,expl,inVarsandFuncs)
local
Integer i,i_1;
DAE.Exp e,de;
list<Boolean> bl,bl1;
Boolean[:] ba;
Absyn.Path p1,p2;
local
Integer i,i_1;
DAE.Exp e,de;
list<Boolean> bl,bl1;
Boolean[:] ba;
Absyn.Path p1,p2;

// no conditions
case(inblst,{},expl,inVarsandFuncs) then inblst;

// zeroDerivative
case(inblst,(i,DAE.ZERO_DERIVATIVE())::crlst,expl,inVarsandFuncs)
equation
i_1 = i-1;
// get expression
e = listNth(expl,i_1);
// diverentiate exp
de = differentiateExpTime(e,inVarsandFuncs);
// is diverentiated exp zero
true = Exp.isZero(de);
// remove input from list
ba = listArray(inblst);
ba = arrayUpdate(ba,i,false);
bl1 = arrayList(ba);
bl = checkDerFunctionConds(bl1,crlst,expl,inVarsandFuncs);
then bl;
equation
i_1 = i-1;
// get expression
e = listNth(expl,i_1);
// diverentiate exp
de = differentiateExpTime(e,inVarsandFuncs);
// is diverentiated exp zero
true = Exp.isZero(de);
// remove input from list
ba = listArray(inblst);
ba = arrayUpdate(ba,i,false);
bl1 = arrayList(ba);
bl = checkDerFunctionConds(bl1,crlst,expl,inVarsandFuncs);
then
bl;

// noDerivative
case(inblst,(i,DAE.NO_DERIVATIVE(binding=DAE.CALL(path=p1)))::crlst,expl,inVarsandFuncs)
equation
i_1 = i-1;
// get expression
DAE.CALL(path=p2) = listNth(expl,i_1);
equality(p1 = p2);
// path equal
// remove input from list
ba = listArray(inblst);
ba = arrayUpdate(ba,i,false);
bl1 = arrayList(ba);
bl = checkDerFunctionConds(bl1,crlst,expl,inVarsandFuncs);
then bl;
equation
i_1 = i-1;
// get expression
DAE.CALL(path=p2) = listNth(expl,i_1);
true = Absyn.pathEqual(p1, p2);
// path equal
// remove input from list
ba = listArray(inblst);
ba = arrayUpdate(ba,i,false);
bl1 = arrayList(ba);
bl = checkDerFunctionConds(bl1,crlst,expl,inVarsandFuncs);
then
bl;

// noDerivative
case(inblst,(i,DAE.NO_DERIVATIVE(binding=DAE.ICONST(_)))::crlst,expl,inVarsandFuncs)
equation
// remove input from list
ba = listArray(inblst);
ba = arrayUpdate(ba,i,false);
bl1 = arrayList(ba);
bl = checkDerFunctionConds(bl1,crlst,expl,inVarsandFuncs);
then bl;
equation
// remove input from list
ba = listArray(inblst);
ba = arrayUpdate(ba,i,false);
bl1 = arrayList(ba);
bl = checkDerFunctionConds(bl1,crlst,expl,inVarsandFuncs);
then
bl;

// failure
case (_,_,_,_)
equation
Debug.fprintln("failtrace", "-Derive.checkDerFunctionConds failed\n");
Expand Down

0 comments on commit 6edafbc

Please sign in to comment.