Skip to content

Commit

Permalink
- use Error.addCompilerWarning instead of print in BackendDAETransfor…
Browse files Browse the repository at this point in the history
…m.splitMixedEquations

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17843 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Oct 23, 2013
1 parent 386ceb9 commit ab7bd52
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 96 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAETransform.mo
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,8 @@ algorithm
then (contEqnLst, contVarLst, discEqnLst, discVarLst, indxcontEqnLst, indxcontVarLst, indxdiscEqnLst, indxdiscVarLst);

case (_, _, _, _) equation
BackendDump.printVarList(varLst);
BackendDump.printEquationList(eqnLst);
Error.addCompilerWarning(BackendDump.varListString(varLst, "involved variables"));
Error.addCompilerWarning(BackendDump.equationListString(eqnLst, "involved equations"));
then fail();
end matchcontinue;
end splitMixedEquations;
Expand Down
96 changes: 82 additions & 14 deletions Compiler/BackEnd/BackendDump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,40 @@ algorithm
oInteger := (i + 1,iscalar + size);
end printEquationList2;

public function equationListString
input list<BackendDAE.Equation> inEqns;
input String heading;
output String outString;
algorithm
outString := match(inEqns, heading)
local
String buffer;

case (_, "") equation
((_, _, buffer)) = List.fold(inEqns, equationList2String, (1, 1, ""));
then buffer;

else equation
((_, _, buffer)) = List.fold(inEqns, equationList2String, (1, 1, ""));
buffer = heading +& "\n" +& UNDERLINE +& "\n" +& buffer;
then buffer;
end match;
end equationListString;

protected function equationList2String
input BackendDAE.Equation inEquation;
input tuple<Integer, Integer, String /*buffer*/> inTuple;
output tuple<Integer, Integer, String /*buffer*/> outTuple;
protected
Integer iscalar, i, size;
String buffer;
algorithm
(i, iscalar, buffer) := inTuple;
size := BackendEquation.equationSize(inEquation);
buffer := buffer +& intString(i) +& "/" +& intString(iscalar) +& " (" +& intString(size) +& "): " +& equationString(inEquation) +& "\n";
outTuple := (i + 1, iscalar + size, buffer);
end equationList2String;

public function printEquations ""
input list<Integer> inIntegerLst;
input BackendDAE.EqSystem syst;
Expand Down Expand Up @@ -282,7 +316,7 @@ algorithm
debuglst((crstates,ComponentReference.printComponentRefStr,"\n","\n"));
end printStateSet;

public function printVar ""
public function printVar
input BackendDAE.Var inVar;
algorithm
print(varString(inVar) +& "\n");
Expand Down Expand Up @@ -311,6 +345,40 @@ algorithm
outVarNo := inVarNo + 1;
end printVars1;

public function varListString
input list<BackendDAE.Var> inVars;
input String heading;
output String outString;
algorithm
outString := match(inVars, heading)
local
String buffer;

case (_, "") equation
((_, buffer)) = List.fold(inVars, var1String, (1, ""));
then buffer;

else equation
((_, buffer)) = List.fold(inVars, var1String, (1, ""));
buffer = heading +& "\n" +& UNDERLINE +& "\n" +& buffer;
then buffer;
end match;
end varListString;

protected function var1String
input BackendDAE.Var inVar;
input tuple<Integer /*inVarNo*/, String /*buffer*/> inTpl;
output tuple<Integer /*outVarNo*/, String /*buffer*/> outTpl;
protected
Integer varNo;
String buffer;
algorithm
(varNo, buffer) := inTpl;
buffer := buffer +& intString(varNo) +& ": ";
buffer := buffer +& varString(inVar) +& "\n";
outTpl := (varNo + 1, buffer);
end var1String;

protected function printExternalObjectClasses "dump classes of external objects"
input BackendDAE.ExternalObjectClasses cls;
algorithm
Expand Down Expand Up @@ -2828,19 +2896,20 @@ algorithm
local
array<Integer> ass1;
BackendDAE.StrongComponents comps;
case (BackendDAE.NO_MATCHING()) equation print("no matching\n"); then ();
case (BackendDAE.MATCHING(ass1,_,comps))
equation
dumpMatching(ass1);
print("\n\n");
dumpComponents(comps);
then
();
end match;

case (BackendDAE.NO_MATCHING()) equation
print("no matching\n");
then ();

case (BackendDAE.MATCHING(ass1, _, comps)) equation
dumpMatching(ass1);
print("\n\n");
dumpComponents(comps);
then ();
end match;
end dumpFullMatching;

public function dumpMatching
"author: PA
public function dumpMatching "author: PA
prints the matching information on stdout."
input array<Integer> v;
protected
Expand All @@ -2856,8 +2925,7 @@ algorithm
dumpMatching2(v, 1, len);
end dumpMatching;

protected function dumpMatching2
"author: PA
protected function dumpMatching2 "author: PA
Helper function to dumpMatching."
input array<Integer> v;
input Integer i;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/Initialization.mo
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ algorithm
initdae = BackendDAEUtil.transformBackendDAE(initdae, SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())), NONE(), NONE());

// simplify system
(initdae, Util.SUCCESS()) = BackendDAEUtil.postOptimizeDAE(initdae, pastOptModules, matchingAlgorithm, daeHandler);
(initdae, Util.SUCCESS()) = BackendDAEUtil.postOptimizeDAE(initdae, pastOptModules, matchingAlgorithm, daeHandler);
Debug.fcall2(Flags.DUMP_INITIAL_SYSTEM, BackendDump.dumpBackendDAE, initdae, "solved initial system");

// warn about selected default initial conditions
Expand Down
139 changes: 60 additions & 79 deletions Compiler/BackEnd/Uncertainties.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2196,111 +2196,92 @@ public function applyOptionSimplify
input Option<DAE.Exp> bindExpIn;
output Option<DAE.Exp> bindExpOut;
algorithm
bindExpOut:=
match (bindExpIn)
bindExpOut := match(bindExpIn)
local
DAE.Exp e,e1;
case (NONE()) then NONE();
case (SOME(e))
equation
(e1,_) = ExpressionSimplify.simplify1(e);
then
SOME(e1);
DAE.Exp e, e1;

case NONE()
then NONE();

case SOME(e) equation
(e1,_) = ExpressionSimplify.simplify1(e);
then SOME(e1);
end match;
end applyOptionSimplify;

public function setVarCref "
author: PA

sets the ComponentRef of a variable.
"
public function setVarCref "author: PA
Sets the ComponentRef of a variable."
input BackendDAE.Var inVar;
input DAE.ComponentRef cr;
output BackendDAE.Var outVar;
algorithm
outVar := match (inVar,cr)
local
DAE.ComponentRef name;
BackendDAE.VarKind kind;
DAE.VarDirection dir;
DAE.VarParallelism prl;
DAE.Type tp;
Option<DAE.Exp> bind ;
Option<Values.Value> bindval;
DAE.InstDims ad;
DAE.ElementSource source;
Option<DAE.VariableAttributes> attr;
Option<SCode.Comment> cmt;
DAE.ConnectorType ct;
case (BackendDAE.VAR(name,kind,dir,prl,tp,bind,bindval,ad,source,attr,cmt,ct),_) then
BackendDAE.VAR(cr,kind,dir,prl,tp,bind,bindval,ad,source,attr,cmt,ct);
end match;
protected
DAE.ComponentRef name;
BackendDAE.VarKind kind;
DAE.VarDirection dir;
DAE.VarParallelism prl;
DAE.Type tp;
Option<DAE.Exp> bind ;
Option<Values.Value> bindval;
DAE.InstDims ad;
DAE.ElementSource source;
Option<DAE.VariableAttributes> attr;
Option<SCode.Comment> cmt;
DAE.ConnectorType ct;
algorithm
BackendDAE.VAR(name,kind,dir,prl,tp,bind,bindval,ad,source,attr,cmt,ct) := inVar;
outVar := BackendDAE.VAR(cr,kind,dir,prl,tp,bind,bindval,ad,source,attr,cmt,ct);
end setVarCref;

public function setVarBindingOpt "
author: PA

sets the optional binding of a variable.
"
public function setVarBindingOpt "author: PA
Sets the optional binding of a variable."
input BackendDAE.Var inVar;
input Option<DAE.Exp> bindExp;
output BackendDAE.Var outVar;
algorithm
outVar := match (inVar,bindExp)
local
DAE.ComponentRef name;
BackendDAE.VarKind kind;
DAE.VarDirection dir;
DAE.VarParallelism prl;
BackendDAE.Type tp;
Option<DAE.Exp> bind ;
Option<Values.Value> bindval;
DAE.InstDims ad;
DAE.ElementSource source;
Option<DAE.VariableAttributes> attr;
Option<SCode.Comment> cmt;
DAE.ConnectorType ct;
case (BackendDAE.VAR(name,kind,dir,prl,tp,bind,bindval,ad,source,attr,cmt,ct),_) then
BackendDAE.VAR(name,kind,dir,prl,tp,bindExp,bindval,ad,source,attr,cmt,ct);
end match;
protected
DAE.ComponentRef name;
BackendDAE.VarKind kind;
DAE.VarDirection dir;
DAE.VarParallelism prl;
BackendDAE.Type tp;
Option<DAE.Exp> bind ;
Option<Values.Value> bindval;
DAE.InstDims ad;
DAE.ElementSource source;
Option<DAE.VariableAttributes> attr;
Option<SCode.Comment> cmt;
DAE.ConnectorType ct;
algorithm
BackendDAE.VAR(name,kind,dir,prl,tp,bind,bindval,ad,source,attr,cmt,ct) := inVar;
outVar := BackendDAE.VAR(name,kind,dir,prl,tp,bindExp,bindval,ad,source,attr,cmt,ct);
end setVarBindingOpt;

public function moveVariables "
This function takes the two variable lists of a dae (states+alg) and
known vars and moves a set of variables from the first to the second set.
This function is needed to manage this in complexity O(n) by only
traversing the set once for all variables.
"
traversing the set once for all variables."
input BackendDAE.Variables inVariables1;
input BackendDAE.Variables inVariables2;
input HashTable.HashTable hashTable;
output BackendDAE.Variables outVariables1;
output BackendDAE.Variables outVariables2;
algorithm
(outVariables1,outVariables2) := match (inVariables1,inVariables2,hashTable)
local
list<BackendDAE.Var> lst1,lst2,lst1_1,lst2_1;
BackendDAE.Variables v1,v2,vars,knvars,vars1,vars2;
HashTable.HashTable mvars;
case (vars1,vars2,mvars)
equation
lst1 = BackendVariable.varList(vars1);
lst2 = BackendVariable.varList(vars2);
(lst1_1,lst2_1) = moveVariables2(lst1, lst2, mvars);
v1 = BackendVariable.emptyVars();
v2 = BackendVariable.emptyVars();
//vars = addVarsNoUpdCheck(lst1_1, v1);
vars = BackendVariable.addVars(lst1_1, v1);
//knvars = addVarsNoUpdCheck(lst2_1, v2);
knvars = BackendVariable.addVars(lst2_1, v2);
then
(vars,knvars);
end match;
protected
list<BackendDAE.Var> lst1, lst2, lst1_1, lst2_1;
BackendDAE.Variables v1, v2, vars, knvars;
algorithm
lst1 := BackendVariable.varList(inVariables1);
lst2 := BackendVariable.varList(inVariables2);
(lst1_1, lst2_1) := moveVariables2(lst1, lst2, hashTable);
v1 := BackendVariable.emptyVars();
v2 := BackendVariable.emptyVars();
//vars := addVarsNoUpdCheck(lst1_1, v1);
outVariables1 := BackendVariable.addVars(lst1_1, v1);
//knvars := addVarsNoUpdCheck(lst2_1, v2);
outVariables2 := BackendVariable.addVars(lst2_1, v2);
end moveVariables;

protected function moveVariables2 "
helper function to move_variables.
"
Helper function to moveVariables."
input list<BackendDAE.Var> inVarLst1;
input list<BackendDAE.Var> inVarLst2;
input HashTable.HashTable hashTable;
Expand Down
13 changes: 13 additions & 0 deletions Compiler/Util/Error.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1121,4 +1121,17 @@ algorithm
end match;
end addCompilerWarning;

public function addCompilerNotification
"Used to make a compiler notification"
input String message;
algorithm
_ := match (message)
case _
equation
addMessage(COMPILER_NOTIFICATION, {message});
then
();
end match;
end addCompilerNotification;

end Error;

0 comments on commit ab7bd52

Please sign in to comment.