Skip to content

Commit

Permalink
- Started removing assert(true, ...) from algorithm sections (functions)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8478 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Apr 4, 2011
1 parent 9ed7895 commit 00b4491
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 86 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/SimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,7 @@ algorithm
equation
// Yes, do this better later on...
print(Tpl.tplString(SimCodeDump.dumpSimCode, simCode));
print("\n");
then ();
case (_,target)
equation
Expand Down
20 changes: 18 additions & 2 deletions Compiler/FrontEnd/Algorithm.mo
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,26 @@ public function makeAssert "function: makeAssert
input DAE.Properties inProperties3;
input DAE.Properties inProperties4;
input DAE.ElementSource source;
output Statement outStatement;
output list<Statement> outStatement;
algorithm
outStatement := match (cond,msg,inProperties3,inProperties4,source)
case (cond,msg,DAE.PROP(type_ = (DAE.T_BOOL(varLstBool = _),_)),DAE.PROP(type_ = (DAE.T_STRING(varLstString = _),_)),source) then DAE.STMT_ASSERT(cond,msg,source);
local
String str;
Absyn.Info info;
case (DAE.BCONST(true),_,_,_,source)
then {};
/* Do not evaluate all assertions. These may or may not be evaluated during runtime...
case (DAE.BCONST(false),DAE.SCONST(str),_,_,DAE.SOURCE(info=info))
equation
Error.addSourceMessage(Error.ASSERT_CONSTANT_FALSE_ERROR,{str},info);
then fail();
case (DAE.BCONST(false),_,_,_,DAE.SOURCE(info=info))
equation
Error.addSourceMessage(Error.ASSERT_CONSTANT_FALSE_ERROR,{"Message was not constant and could not be evaluated"},info);
then fail();
*/
case (cond,msg,DAE.PROP(type_ = (DAE.T_BOOL(varLstBool = _),_)),DAE.PROP(type_ = (DAE.T_STRING(varLstString = _),_)),source)
then {DAE.STMT_ASSERT(cond,msg,source)};
end match;
end makeAssert;

Expand Down
7 changes: 4 additions & 3 deletions Compiler/FrontEnd/ConnectUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1059,17 +1059,18 @@ algorithm
list<Absyn.Within> partOfLst;
list<Option<DAE.ComponentRef>> instanceOptLst;
list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> connectEquationOptLst;
list<Absyn.Path> typeLst;
list<Absyn.Path> typeLst;
list<DAE.SymbolicOperation> operations;

case {_} then DAEUtil.emptyDae;

case ((ee1 as (x,_,src1)) :: ((ee2 as (y,_,src2)) :: cs))
equation
ee1 = Util.if_(RTOpts.orderConnections(), ee1, ee2);
DAE.DAE(eq) = equEquations(ee1 :: cs);
DAE.SOURCE(info, partOfLst, instanceOptLst, connectEquationOptLst, typeLst) = DAEUtil.mergeSources(src1,src2);
DAE.SOURCE(info, partOfLst, instanceOptLst, connectEquationOptLst, typeLst, operations) = DAEUtil.mergeSources(src1,src2);
// do not propagate connects from different sources! use the crefs directly!
src = DAE.SOURCE(info, partOfLst, instanceOptLst, {SOME((x,y))}, typeLst);
src = DAE.SOURCE(info, partOfLst, instanceOptLst, {SOME((x,y))}, typeLst, operations);
then
(DAE.DAE(DAE.EQUEQUATION(x,y,src) :: eq));

Expand Down
14 changes: 13 additions & 1 deletion Compiler/FrontEnd/DAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,22 @@ uniontype ElementSource "gives information about the origin of the element"
list<Option<ComponentRef>> instanceOptLst "the instance(s) this element is part of";
list<Option<tuple<ComponentRef, ComponentRef>>> connectEquationOptLst "this element came from this connect(s)";
list<Absyn.Path> typeLst "the classes where the type(s) of the element is defined";
list<SymbolicOperation> operations "the symbolic operations used to end up with the final state of the element";
end SOURCE;
end ElementSource;

public constant ElementSource emptyElementSource = SOURCE(Absyn.dummyInfo,{},{},{},{});
public uniontype SymbolicOperation
record SIMPLIFY
Exp before;
Exp after;
end SIMPLIFY;
record SUBSTITUTION
Exp source;
Exp target;
end SUBSTITUTION;
end SymbolicOperation;

public constant ElementSource emptyElementSource = SOURCE(Absyn.dummyInfo,{},{},{},{},{});

public uniontype Element
record VAR
Expand Down
33 changes: 20 additions & 13 deletions Compiler/FrontEnd/DAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4273,9 +4273,10 @@ algorithm
list<Absyn.Within> partOfLst "the models this element came from" ;
list<Option<DAE.ComponentRef>> instanceOptLst "the instance this element is part of" ;
list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> connectEquationOptLst "this element came from this connect" ;
list<DAE.SymbolicOperation> operations;

case (DAE.SOURCE(info, partOfLst, instanceOptLst, connectEquationOptLst, typeLst), classPath)
then DAE.SOURCE(info, partOfLst, instanceOptLst, connectEquationOptLst, classPath::typeLst);
case (DAE.SOURCE(info, partOfLst, instanceOptLst, connectEquationOptLst, typeLst, operations), classPath)
then DAE.SOURCE(info, partOfLst, instanceOptLst, connectEquationOptLst, classPath::typeLst, operations);
end match;
end addElementSourceType;

Expand Down Expand Up @@ -4308,9 +4309,10 @@ algorithm
list<Absyn.Within> partOfLst "the models this element came from" ;
list<Option<DAE.ComponentRef>> instanceOptLst "the instance this element is part of" ;
list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> connectEquationOptLst "this element came from this connect" ;
list<DAE.SymbolicOperation> operations;

case (DAE.SOURCE(info,partOfLst, instanceOptLst, connectEquationOptLst, typeLst), withinPath)
then DAE.SOURCE(info,withinPath::partOfLst, instanceOptLst, connectEquationOptLst, typeLst);
case (DAE.SOURCE(info,partOfLst, instanceOptLst, connectEquationOptLst, typeLst, operations), withinPath)
then DAE.SOURCE(info,withinPath::partOfLst, instanceOptLst, connectEquationOptLst, typeLst, operations);
end match;
end addElementSourcePartOf;

Expand Down Expand Up @@ -4347,8 +4349,9 @@ algorithm
list<Option<DAE.ComponentRef>> instanceOptLst "the instance this element is part of" ;
list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> connectEquationOptLst "this element came from this connect" ;
Absyn.Info info;
case (DAE.SOURCE(_,partOfLst,instanceOptLst,connectEquationOptLst,typeLst), info)
then DAE.SOURCE(info,partOfLst,instanceOptLst,connectEquationOptLst,typeLst);
list<DAE.SymbolicOperation> operations;
case (DAE.SOURCE(_,partOfLst,instanceOptLst,connectEquationOptLst,typeLst,operations), info)
then DAE.SOURCE(info,partOfLst,instanceOptLst,connectEquationOptLst,typeLst,operations);
end match;
end addElementSourceFileInfo;

Expand All @@ -4364,10 +4367,11 @@ algorithm
list<Option<DAE.ComponentRef>> instanceOptLst "the instance this element is part of" ;
list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> connectEquationOptLst "this element came from this connect" ;
list<Absyn.Path> typeLst "the classes where the type of the element is defined" ;
list<DAE.SymbolicOperation> operations;

// a NONE() means top level (equivalent to NO_PRE, SOME(cref) means subcomponent
case (DAE.SOURCE(info,partOfLst,instanceOptLst,connectEquationOptLst,typeLst), instanceOpt)
then DAE.SOURCE(info,partOfLst,instanceOpt::instanceOptLst,connectEquationOptLst,typeLst);
case (DAE.SOURCE(info,partOfLst,instanceOptLst,connectEquationOptLst,typeLst,operations), instanceOpt)
then DAE.SOURCE(info,partOfLst,instanceOpt::instanceOptLst,connectEquationOptLst,typeLst,operations);
end match;
end addElementSourceInstanceOpt;

Expand All @@ -4383,11 +4387,12 @@ algorithm
list<Option<DAE.ComponentRef>> instanceOptLst "the instance this element is part of" ;
list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> connectEquationOptLst "this element came from this connect" ;
list<Absyn.Path> typeLst "the classes where the type of the element is defined" ;
list<DAE.SymbolicOperation> operations;

// a top level
case (inSource, NONE()) then inSource;
case (inSource as DAE.SOURCE(info,partOfLst,instanceOptLst,connectEquationOptLst,typeLst), connectEquationOpt)
then DAE.SOURCE(info,partOfLst,instanceOptLst,connectEquationOpt::connectEquationOptLst,typeLst);
case (inSource as DAE.SOURCE(info,partOfLst,instanceOptLst,connectEquationOptLst,typeLst,operations), connectEquationOpt)
then DAE.SOURCE(info,partOfLst,instanceOptLst,connectEquationOpt::connectEquationOptLst,typeLst,operations);
end matchcontinue;
end addElementSourceConnectOpt;

Expand Down Expand Up @@ -4424,14 +4429,16 @@ algorithm
list<Option<DAE.ComponentRef>> instanceOptLst1,instanceOptLst2,i;
list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> connectEquationOptLst1,connectEquationOptLst2,c;
list<Absyn.Path> typeLst1,typeLst2,t;
case (DAE.SOURCE(info, partOfLst1, instanceOptLst1, connectEquationOptLst1, typeLst1),
DAE.SOURCE(_ /* Discard */, partOfLst2, instanceOptLst2, connectEquationOptLst2, typeLst2))
list<DAE.SymbolicOperation> o,operations1,operations2;
case (DAE.SOURCE(info, partOfLst1, instanceOptLst1, connectEquationOptLst1, typeLst1, operations1),
DAE.SOURCE(_ /* Discard */, partOfLst2, instanceOptLst2, connectEquationOptLst2, typeLst2, operations2))
equation
p = listAppend(partOfLst1, partOfLst2);
i = listAppend(instanceOptLst1, instanceOptLst2);
c = listAppend(connectEquationOptLst1, connectEquationOptLst1);
t = listAppend(typeLst1, typeLst2);
then DAE.SOURCE(info,p,i,c,t);
o = listAppend(operations1, operations2);
then DAE.SOURCE(info,p,i,c,t, o);
end match;
end mergeSources;

Expand Down
39 changes: 2 additions & 37 deletions Compiler/FrontEnd/InstSection.mo
Original file line number Diff line number Diff line change
Expand Up @@ -462,41 +462,6 @@ algorithm
then
(cache,env,ih,dae,csets_1,ci_state_1,graph);

//------------------------------------------------------
// Part of the MetaModelica extension
/* equality equations cref = array(...) */
// Should be removed??
// case (cache,env,ih,mods,pre,csets,ci_state,SCode.EQ_EQUALS(e1 as Absyn.CREF(cr),Absyn.ARRAY(expList)),initial_,impl)
// local Option<Interactive.InteractiveSymbolTable> c1,c2;
// list<Absyn.Exp> expList;
// Absyn.ComponentRef cr;
// DAE.Properties cprop;
// equation
// true = RTOpts.acceptMetaModelicaGrammar();
// If this is a list assignment, then the Absyn.ARRAY expression should
// be evaluated to DAE.LIST
// (cache,_,cprop,_) = Static.elabCref(cache,env, cr, impl,false);
// true = MetaUtil.isList(cprop);
// Do static analysis and constant evaluation of expressions.
// Gives expression and properties
// (Type bool | (Type Const as (bool | Const list))).
// For a function, it checks the funtion name.
// Also the function call\'s in parameters are type checked with
// the functions definition\'s inparameters. This is done with
// regard to the position of the input arguments.
// Returns the output parameters from the function.
// (cache,e1_1,prop1,c1) = Static.elabExp(cache,env, e1, impl,NONE(),true /*do vectorization*/);
// (cache,e2_1,prop2,c2) = Static.elabListExp(cache,env, expList, cprop, impl,NONE(),true/* do vectorization*/);
// (cache,e1_1,e2_1) = condenseArrayEquation(cache,env,e1,e2,e1_1,e2_1,prop1,impl);
// (cache,e1_2) = PrefixUtil.prefixExp(cache, env, ih, e1_1, pre);
// (cache,e2_2) = PrefixUtil.prefixExp(cache, env, ih, e2_1, pre);
// Check that the lefthandside and the righthandside get along.
// dae = instEqEquation(e1_2, prop1, e2_2, prop2, initial_, impl);
// ci_state_1 = instEquationCommonCiTrans(ci_state, initial_);
// then
// (cache,env,ih,dae,csets,ci_state_1);
//------------------------------------------------------

/* equality equations e1 = e2 */
case (cache,env,ih,mods,pre,csets,ci_state,SCode.EQ_EQUALS(expLeft = e1,expRight = e2,info = info),initial_,impl,graph)
equation
Expand Down Expand Up @@ -2473,9 +2438,9 @@ algorithm
(cache, msg_1, msgprop) = Ceval.cevalIfConstant(cache, env, msg_1, msgprop, impl);
(cache,msg_2) = PrefixUtil.prefixExp(cache, env, ih, msg_1, pre);
source = DAEUtil.addElementSourceFileInfo(source, info);
stmt = Algorithm.makeAssert(cond_2, msg_2, cprop, msgprop, source);
stmts = Algorithm.makeAssert(cond_2, msg_2, cprop, msgprop, source);
then
(cache,{stmt});
(cache,stmts);

/* terminate(msg) */
case (cache,env,ih,pre,SCode.ALG_NORETCALL(functionCall = Absyn.CREF_IDENT(name = "terminate"),
Expand Down

0 comments on commit 00b4491

Please sign in to comment.