Skip to content

Commit

Permalink
- made Connection.isRoot function non-constant in Stati.elabBuiltinIs…
Browse files Browse the repository at this point in the history
…Root as otherwise it expects

  constant input arguments and generates errors of kind: 
  "Error: No constant value for variable frame_a.R in scope Modelica.Mechanics.MultiBody.Parts.Body"
- added ceval handler for rooted operator (non-existent in Modelica Specification but used in MSL)
  see more here: https://trac.modelica.org/Modelica/ticket/95
- more informative fail traces in Mod.mo, Types.mo, ValuesUtil.mo
- speed up the fail traces from Types.mo (type checking should be faster now).
- the fail traces from Types are now guided by "types" not by "failtrace" 
  as they generate way too many messages that are not of interest.
  just add +d=types to bring the messages back.
- more informative printing of enumerations in ValuesUtil.mo


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4564 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 24, 2009
1 parent ba2cea4 commit 45f2dc9
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 42 deletions.
49 changes: 45 additions & 4 deletions Compiler/Ceval.mo
Expand Up @@ -963,6 +963,7 @@ algorithm
case "String" then cevalBuiltinString;
case "linspace" then cevalBuiltinLinspace;
case "Integer" then cevalBuiltinIntegerEnumeration;
case "rooted" then cevalBuiltinRooted; //
case "print" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalBuiltinPrint;
// MetaModelica type conversions
case "intReal" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalIntReal;
Expand Down Expand Up @@ -3711,6 +3712,38 @@ algorithm
end matchcontinue;
end cevalBuiltinInteger;

protected function cevalBuiltinRooted
"function cevalBuiltinRooted
author: adrpo
Evaluates the builtin rooted operator from MultiBody"
input Env.Cache inCache;
input Env.Env inEnv;
input list<DAE.Exp> inExpExpLst;
input Boolean inBoolean;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Msg inMsg;
output Env.Cache outCache;
output Values.Value outValue;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outValue,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv,inExpExpLst,inBoolean,inInteractiveInteractiveSymbolTableOption,inMsg)
local
Real rv;
Integer ri;
list<Env.Frame> env;
DAE.Exp exp;
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st;
Msg msg;
Env.Cache cache;
case (cache,env,{exp},impl,st,msg)
equation
(cache,_,_) = ceval(cache, env, exp, impl, st, NONE, msg);
then
(cache,Values.BOOL(true),st);
end matchcontinue;
end cevalBuiltinRooted;

protected function cevalBuiltinIntegerEnumeration "function cevalBuiltinIntegerEnumeration
author: LP
Expand Down Expand Up @@ -4020,6 +4053,7 @@ algorithm
Integer i1,i2;
String s1,s2;
DAE.ComponentRef cr1, cr2;
DAE.Operator op;

case (v1,DAE.GREATER(ty = t),v2)
equation
Expand Down Expand Up @@ -4166,6 +4200,11 @@ algorithm
b = (i1 >= i2);
then
Values.BOOL(b);
case (Values.ENUM(index = i1),DAE.EQUAL(ty = DAE.ET_ENUMERATION(index = SOME(_))),Values.INTEGER(i2))
equation
bb = (i1 == i2);
then
Values.BOOL(bb);
case (Values.ENUM(index = i1),DAE.EQUAL(ty = DAE.ET_ENUMERATION(index = SOME(_))),Values.ENUM(index = i2))
// case (Values.ENUM(cr1,i1),DAE.EQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
equation
Expand All @@ -4174,7 +4213,7 @@ algorithm
bb = (i1 == i2);
// b = boolAnd(ba, bb);
then
Values.BOOL(bb);
Values.BOOL(bb);
case (Values.ENUM(index = i1),DAE.NEQUAL(ty = DAE.ET_ENUMERATION(index = SOME(_))),Values.ENUM(index = i2))
// case (Values.ENUM(cr1,i1),DAE.NEQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
equation
Expand All @@ -4184,10 +4223,12 @@ algorithm
then
Values.BOOL(bb);

case (_,_,_)
case (v1,op,v2)
equation
Debug.fprint("failtrace", "- Ceval.cevalRelation failed\n");
//print("- Ceval.cevalRelation failed\n");
Debug.fprintln("failtrace", "- Ceval.cevalRelation failed on: " +&
ValuesUtil.printValStr(v1) +&
Exp.binopSymbol(op) +&
ValuesUtil.printValStr(v2));
then
fail();
end matchcontinue;
Expand Down
9 changes: 8 additions & 1 deletion Compiler/Inst.mo
Expand Up @@ -9589,7 +9589,7 @@ protected function instEEquation
output ClassInf.State outState;
output ConnectionGraph.ConnectionGraph outGraph;
algorithm
(outCache,outEnv,outIH,outDAEElementLst,outSets,outState, outGraph):=
(outCache,outEnv,outIH,outDAEElementLst,outSets,outState, outGraph) :=
matchcontinue (inCache,inEnv,inIH,inMod,inPrefix,inSets,inState,inEEquation,inBoolean,inGraph)
local
list<DAE.Element> dae;
Expand Down Expand Up @@ -15051,6 +15051,7 @@ algorithm
Env.Cache cache;
ConnectionGraph.ConnectionGraph graph;
InstanceHierarchy ih;
SCode.EEquation eee;

case (cache,env,ih,mod,pre,csets,ci_state,{},_,impl,graph)
then
Expand All @@ -15067,6 +15068,12 @@ algorithm
(cache,env_2,ih,llb,csets_2,ci_state_2,graph) = instIfTrueBranches(cache,env_1,ih, mod, pre, csets_1, ci_state_1, es, true, impl,graph);
then
(cache,env_2,ih,lb::llb,csets_2,ci_state_2,graph);
case (cache,env,ih,mod,pre,csets,ci_state,(e :: es),_,impl,graph)
equation
Debug.fprintln("failtrace", "Inst.instIfTrueBranches failed on equations: " +&
Util.stringDelimitList(Util.listMap(e, SCode.equationStr), "\n"));
then
fail();
end matchcontinue;
end instIfTrueBranches;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/Lookup.mo
Expand Up @@ -105,7 +105,7 @@ algorithm
t = (DAE.T_FUNCTION({("x", (DAE.T_ANYTYPE(NONE), NONE))}, (DAE.T_BOOL({}), NONE)), NONE);
then
(cache, t, env);

// Special handling for MultiBody 3.x rooted() operator
case (cache,env,Absyn.IDENT("rooted"),msg)
equation
Expand Down
36 changes: 18 additions & 18 deletions Compiler/Mod.mo
Expand Up @@ -721,7 +721,7 @@ algorithm
then
fail();
case(xs,m) equation
print("maekIdxmods failed for mod:");print(printModStr(m));print("\n");
print("Mod.makeIdxmods failed for mod:");print(printModStr(m));print("\n");
print("subs =");print(Util.stringDelimitList(Util.listMap(xs,Exp.printSubscriptStr),","));
print("\n");
then fail();
Expand Down Expand Up @@ -1246,8 +1246,9 @@ algorithm
then
DAE.MOD(f,Absyn.NON_EACH(),subs_1,eq_1);
case (DAE.MOD(finalPrefix = f,each_ = Absyn.EACH(),subModLst = subs,eqModOption = eq),idx) then DAE.MOD(f,Absyn.EACH(),subs,eq);
case (_,_) equation
Debug.fprint("failtrace", "-lookupIdxModification3 failed\n");
case (inMod,idx) equation
Debug.fprintln("failtrace", "- Mod.lookupIdxModification3 failed for mod: \n" +&
printModStr(inMod) +& "\n for index:" +& intString(idx));
then fail();
end matchcontinue;
end lookupIdxModification3;
Expand All @@ -1274,6 +1275,8 @@ algorithm
DAE.Const c;
Integer x;
list<Integer> xs;
DAE.EqMod eq;

case (NONE,_) then NONE;
case (e,{}) then e;
/* Subscripting empty array gives no value. This is needed in e.g. fill(1.0,0,2) */
Expand All @@ -1299,8 +1302,10 @@ algorithm
e = indexEqmod(SOME(DAE.TYPED(exp,NONE,DAE.PROP(t_1,c))), xs);
then
e;
case (_,_) equation
Debug.fprint("failtrace", "-indexEqmod failed\n");
case (SOME(eq),inIntegerLst) equation
Debug.fprintln("failtrace", "- Mod.indexEqmod failed for mod:\n " +&
Types.unparseEqMod(eq) +& "\n indexes:" +&
Util.stringDelimitList(Util.listMap(inIntegerLst, intString), ", "));
then fail();
end matchcontinue;
end indexEqmod;
Expand Down Expand Up @@ -1811,12 +1816,9 @@ algorithm
end matchcontinue;
end eqModEqual;

public function printModStr "
This function prints a modification. It uses a few other function
to do its stuff.

"
public function printModStr
"This function prints a modification.
It uses a few other function to do its stuff."
input DAE.Mod inMod;
output String outString;
algorithm
Expand Down Expand Up @@ -2048,15 +2050,13 @@ algorithm
end matchcontinue;
end printSubscripts2Str;

protected function printEqmodStr "function: printEqmodStr
Helper function to print_mod_str
"
protected function printEqmodStr
"function: printEqmodStr
Helper function to printModStr"
input Option<DAE.EqMod> inTypesEqModOption;
output String outString;
algorithm
outString:=
matchcontinue (inTypesEqModOption)
outString := matchcontinue (inTypesEqModOption)
local
Ident str,str2,e_val_str,res;
DAE.Exp e;
Expand All @@ -2068,7 +2068,7 @@ algorithm
str = Exp.printExpStr(e);
str2 = Types.printPropStr(prop);
e_val_str = ValuesUtil.valString(e_val);
res = Util.stringAppendList({" = (typed)",str,str2,", E_VALUE:",e_val_str});
res = Util.stringAppendList({" = (typed)",str," ",str2,", E_VALUE: ",e_val_str});
then
res;
case SOME(DAE.TYPED(e,NONE,prop))
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Static.mo
Expand Up @@ -5540,7 +5540,7 @@ algorithm
(cache,
DAE.CALL(Absyn.QUALIFIED("Connections", Absyn.IDENT("isRoot")), {exp},
false, true, DAE.ET_BOOL,false),
DAE.PROP((DAE.T_BOOL({}), NONE), DAE.C_CONST));
DAE.PROP((DAE.T_BOOL({}), NONE), DAE.C_VAR));
end matchcontinue;
end elabBuiltinIsRoot;

Expand Down Expand Up @@ -9836,7 +9836,7 @@ algorithm
then
(cache,e_1,DAE.C_PARAM(),SCode.RO());

case (cache,env,cr,acc,var,io,tt,DAE.EQBOUND(exp = exp,constant_ = const),doVect,_)
case (cache,env,cr,acc,var,io,tt,DAE.EQBOUND(exp = exp,constant_ = const),doVect,_)
local DAE.ExpType t;
equation
true = SCode.isParameterOrConst(var);
Expand Down
49 changes: 35 additions & 14 deletions Compiler/Types.mo
Expand Up @@ -77,16 +77,13 @@ protected import Static;
protected import RTOpts;
protected import ValuesUtil;

public function discreteType "function: discreteType
author: PA
Succeeds for all the discrete types, Integer, String, Boolean and
enumeration.
"
public function discreteType
"function: discreteType
author: PA
Succeeds for all the discrete types, Integer, String, Boolean and enumeration."
input Type inType;
algorithm
_:=
matchcontinue (inType)
_ := matchcontinue (inType)
case ((DAE.T_INTEGER(varLstInt = _),_)) then ();
case ((DAE.T_STRING(varLstString = _),_)) then ();
case ((DAE.T_BOOL(varLstBool = _),_)) then ();
Expand Down Expand Up @@ -3597,9 +3594,9 @@ algorithm

case(e,inProperties2,inProperties3)
equation
Debug.fprint("failtrace", " Failure in Types.matchProp exp: "+& Exp.printExpStr(e)+& "\n");
Debug.fprint("failtrace", printPropStr(inProperties2) +& "\n");
Debug.fprint("failtrace", printPropStr(inProperties3) +& "\n");
Debug.fprintln("types", " Failure in Types.matchProp exp: "+& Exp.printExpStr(e));
Debug.fprintln("types", printPropStr(inProperties2) +& " != ");
Debug.fprintln("types", printPropStr(inProperties3) +& "\n");
then fail();
end matchcontinue;
end matchProp;
Expand Down Expand Up @@ -5121,7 +5118,7 @@ algorithm
(e_1,e_type_1,polymorphicBindings);
case (_,_,_,_)
equation
Debug.fprintln("failtrace", "- Types.matchTypePolymorphic failed");
Debug.fprintln("types", "- Types.matchTypePolymorphic failed");
then fail();
end matchcontinue;
end matchTypePolymorphic;
Expand Down Expand Up @@ -5157,13 +5154,37 @@ algorithm
(e_1,e_type_1,polymorphicBindings) = typeConvert(e, e_type, expected_type, polymorphicBindings, matchTypeRegular);
then
(e_1,e_type_1,polymorphicBindings);
case (_,_,_,_)
case (e,e_type,expected_type,_)
equation
Debug.fprintln("failtrace", "- Types.matchTypeRegular failed");
printFailure("types", e, e_type, expected_type);
then fail();
end matchcontinue;
end matchTypeRegular;

protected function printFailure
"@author adrpo
print the message only when flag is on.
this is to speed up the flattening as we don't
generate the strings at all."
input String flag;
input DAE.Exp e;
input Type e_type;
input Type expected_type;
algorithm
_ := matchcontinue (flag, e, e_type, expected_type)
case (flag, e, e_type, expected_type)
equation
true = RTOpts.debugFlag(flag);
Debug.fprint("types", "- Types.matchTypeRegular failed on:" +& Exp.printExpStr(e));
Debug.fprintln("types", " type:" +& printTypeStr(e_type) +& " differs from expected\n type:" +& printTypeStr(expected_type));
then ();
case (flag, e, e_type, expected_type)
equation
false = RTOpts.debugFlag(flag);
then ();
end matchcontinue;
end printFailure;

public function fixPolymorphicRestype "TODO: This needs to be more generic so for example list<polymorphic<X>> is also translated"
input Type ty;
input PolymorphicBindings bindings;
Expand Down
6 changes: 4 additions & 2 deletions Compiler/ValuesUtil.mo
Expand Up @@ -1662,6 +1662,8 @@ algorithm
Value r;
Absyn.CodeNode c;
DAE.ComponentRef cr;
Absyn.Path p;

case Values.INTEGER(integer = n)
equation
s = intString(n);
Expand Down Expand Up @@ -1735,9 +1737,9 @@ algorithm
s_2;
/* Until is it no able to get from an string Enumeration the C-Enumeration use the index value */
/* Example: This is yet not possible Enum.e1 \\ PEnum -> 1 \\ PEnum with enum Enum(e1,e2), Enum PEnum; */
case(Values.ENUM(index = n)) equation
case (Values.ENUM(index = n, path=p)) equation
// s = Exp.printComponentRefStr(cr);
s = intString(n);
s = intString(n) +& " /* ENUM: " +& Absyn.pathString(p) +& " */";
then s;
case(Values.NORETCALL) then "";
case _
Expand Down

0 comments on commit 45f2dc9

Please sign in to comment.