Skip to content

Commit

Permalink
Move functions into new package ElementSource
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 4, 2016
1 parent 492b0cc commit 18c51d6
Show file tree
Hide file tree
Showing 42 changed files with 980 additions and 985 deletions.
43 changes: 22 additions & 21 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -56,6 +56,7 @@ protected import DAEDump;
protected import DAEUtil;
protected import Debug;
protected import DynamicOptimization;
protected import ElementSource;
protected import Error;
protected import Expression;
protected import ExpressionDump;
Expand Down Expand Up @@ -778,7 +779,7 @@ algorithm
equation
e1 = BaseHashTable.get(iExp,iInlineHT);
// print("use chache Inline\n" + ExpressionDump.printExpStr(iExp) + "\n");
source = DAEUtil.addSymbolicTransformation(iSource,DAE.OP_INLINE(DAE.PARTIAL_EQUATION(iExp),DAE.PARTIAL_EQUATION(e1)));
source = ElementSource.addSymbolicTransformation(iSource,DAE.OP_INLINE(DAE.PARTIAL_EQUATION(iExp),DAE.PARTIAL_EQUATION(e1)));
then (e1,source,iInlineHT,{});
case (DAE.CALL(),_,_,_)
equation
Expand All @@ -790,7 +791,7 @@ algorithm
equation
e1 = BaseHashTable.get(e,iInlineHT);
// print("use chache Inline\n" + ExpressionDump.printExpStr(iExp) + "\n");
source = DAEUtil.addSymbolicTransformation(iSource,DAE.OP_INLINE(DAE.PARTIAL_EQUATION(e),DAE.PARTIAL_EQUATION(e1)));
source = ElementSource.addSymbolicTransformation(iSource,DAE.OP_INLINE(DAE.PARTIAL_EQUATION(e),DAE.PARTIAL_EQUATION(e1)));
(e, source, _,_) = Inline.inlineExp(DAE.ASUB(e1,elst), fnstpl, source);
then (e,source,iInlineHT,{});
case (DAE.ASUB(e,elst),_,_,_)
Expand Down Expand Up @@ -1248,7 +1249,7 @@ algorithm
case (_,_,_,_,_)
equation
s = "BackendDAECreate.lowerEqn failed for " + DAEDump.dumpElementsStr({inElement});
Error.addSourceMessage(Error.INTERNAL_ERROR, {s}, DAEUtil.getElementSourceFileInfo(DAEUtil.getElementSource(inElement)));
Error.addSourceMessage(Error.INTERNAL_ERROR, {s}, ElementSource.getElementSourceFileInfo(ElementSource.getElementSource(inElement)));
then fail();

end match;
Expand Down Expand Up @@ -1739,10 +1740,10 @@ algorithm

else
equation
source = DAEUtil.getElementSource(inElement);
source = ElementSource.getElementSource(inElement);
str = "BackendDAECreate.lowerWhenEqn: equation not handled:\n" +
DAEDump.dumpElementsStr({inElement});
Error.addSourceMessage(Error.INTERNAL_ERROR, {str}, DAEUtil.getElementSourceFileInfo(source));
Error.addSourceMessage(Error.INTERNAL_ERROR, {str}, ElementSource.getElementSourceFileInfo(source));
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -1993,7 +1994,7 @@ algorithm
inEqns;
case ((cr, (e, source))::rest, _, _, _)
equation
source = DAEUtil.mergeSources(iSource, source);
source = ElementSource.mergeSources(iSource, source);
size = Expression.sizeOf(Expression.typeof(e));
whenOp = BackendDAE.ASSIGN(cr, e, source);
whenEq = BackendDAE.WHEN_STMTS(inCond, {whenOp}, NONE());
Expand Down Expand Up @@ -2059,7 +2060,7 @@ algorithm
(e, source, _,_) = Inline.inlineExp(e, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
((exp, source1)) = BaseHashTable.get(cr, iHt);
exp = DAE.IFEXP(condition, e, exp);
source = DAEUtil.mergeSources(source, source1);
source = ElementSource.mergeSources(source, source1);
ht = BaseHashTable.add((cr, (exp, source)), iHt);
then
lowerWhenIfEqns1(condition, rest, functionTree, ht);
Expand All @@ -2069,7 +2070,7 @@ algorithm
(e, source, _,_) = Inline.inlineExp(e, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
((exp, source1)) = BaseHashTable.get(cr, iHt);
exp = DAE.IFEXP(condition, e, exp);
source = DAEUtil.mergeSources(source, source1);
source = ElementSource.mergeSources(source, source1);
ht = BaseHashTable.add((cr, (exp, source)), iHt);
then
lowerWhenIfEqns1(condition, rest, functionTree, ht);
Expand All @@ -2079,7 +2080,7 @@ algorithm
(e, source, _,_) = Inline.inlineExp(e, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
((exp, source1)) = BaseHashTable.get(cr, iHt);
exp = DAE.IFEXP(condition, e, exp);
source = DAEUtil.mergeSources(source, source1);
source = ElementSource.mergeSources(source, source1);
ht = BaseHashTable.add((cr, (exp, source)), iHt);
then
lowerWhenIfEqns1(condition, rest, functionTree, ht);
Expand All @@ -2089,7 +2090,7 @@ algorithm
(e, source, _,_) = Inline.inlineExp(e, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
((exp, source1)) = BaseHashTable.get(cr, iHt);
exp = DAE.IFEXP(condition, e, exp);
source = DAEUtil.mergeSources(source, source1);
source = ElementSource.mergeSources(source, source1);
ht = BaseHashTable.add((cr, (exp, source)), iHt);
then
lowerWhenIfEqns1(condition, rest, functionTree, ht);
Expand All @@ -2099,7 +2100,7 @@ algorithm
(e, source, _,_) = Inline.inlineExp(e, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
((exp, source1)) = BaseHashTable.get(cr, iHt);
exp = DAE.IFEXP(condition, e, exp);
source = DAEUtil.mergeSources(source, source1);
source = ElementSource.mergeSources(source, source1);
ht = BaseHashTable.add((cr, (exp, source)), iHt);
then
lowerWhenIfEqns1(condition, rest, functionTree, ht);
Expand Down Expand Up @@ -2139,7 +2140,7 @@ algorithm
equation
((exp, _)) = BaseHashTable.get(cr, iHt);
exp = DAE.IFEXP(inCond, e, exp);
source = DAEUtil.mergeSources(iSource, source);
source = ElementSource.mergeSources(iSource, source);
ht = BaseHashTable.add((cr, (exp, source)), iHt);
then
lowerWhenIfEqnsMergeNestedIf(rest, inCond, iSource, ht);
Expand Down Expand Up @@ -2435,7 +2436,7 @@ algorithm
(cond, source, _,_) = Inline.inlineExp(cond, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
(msg, source, _,_) = Inline.inlineExp(msg, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
(level, source, _,_) = Inline.inlineExp(level, (SOME(functionTree), {DAE.NORM_INLINE()}), source);
BackendDAEUtil.checkAssertCondition(cond, msg, level, DAEUtil.getElementSourceFileInfo(source));
BackendDAEUtil.checkAssertCondition(cond, msg, level, ElementSource.getElementSourceFileInfo(source));
alg = DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond, msg, level, source)});
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);

Expand All @@ -2456,7 +2457,7 @@ algorithm
// only report error if no other error is in the queue!
0 = Error.getNumErrorMessages();
str = "BackendDAECreate.lowerAlgorithm failed for:\n" + DAEDump.dumpElementsStr({inElement});
Error.addSourceMessage(Error.INTERNAL_ERROR, {str}, DAEUtil.getElementSourceFileInfo(DAEUtil.getElementSource(inElement)));
Error.addSourceMessage(Error.INTERNAL_ERROR, {str}, ElementSource.getElementSourceFileInfo(ElementSource.getElementSource(inElement)));
then fail();
end matchcontinue;
end lowerAlgorithm;
Expand Down Expand Up @@ -2799,7 +2800,7 @@ algorithm
// merge fixed, start, nominal
var = BackendVariable.mergeAliasVars(v1, v2, false, iKnVars);
// setAliasType
ops = DAEUtil.getSymbolicTransformations(source);
ops = ElementSource.getSymbolicTransformations(source);
avar = BackendVariable.mergeVariableOperations(v2, DAE.SOLVED(cr2, e1)::ops);
avar = BackendVariable.setBindExp(avar, SOME(e1));
// remove from vars
Expand All @@ -2825,7 +2826,7 @@ algorithm
// merge fixed, start, nominal
var = BackendVariable.mergeAliasVars(v2, v1, false, iKnVars);
// setAliasType
ops = DAEUtil.getSymbolicTransformations(source);
ops = ElementSource.getSymbolicTransformations(source);
avar = BackendVariable.mergeVariableOperations(v1, DAE.SOLVED(cr1, e2)::ops);
avar = BackendVariable.setBindExp(avar, SOME(e2));
// remove from vars
Expand Down Expand Up @@ -2860,7 +2861,7 @@ algorithm
// merge fixed, start, nominal
var = BackendVariable.mergeAliasVars(var, avar, false, iKnVars);
// setAliasType
ops = DAEUtil.getSymbolicTransformations(source);
ops = ElementSource.getSymbolicTransformations(source);
avar = BackendVariable.mergeVariableOperations(avar, DAE.SOLVED(acr, e)::ops);
avar = BackendVariable.setBindExp(avar, SOME(e));
avar = if b1 then BackendVariable.setVarKind(avar, BackendDAE.DUMMY_STATE()) else avar;
Expand All @@ -2886,7 +2887,7 @@ algorithm
// merge fixed, start, nominal
var = BackendVariable.mergeAliasVars(v2, v1, false, iKnVars);
// setAliasType
ops = DAEUtil.getSymbolicTransformations(source);
ops = ElementSource.getSymbolicTransformations(source);
avar = BackendVariable.mergeVariableOperations(v1, DAE.SOLVED(cr1, e2)::ops);
avar = BackendVariable.setBindExp(avar, SOME(e2));
avar = if BackendVariable.isStateVar(v1) then BackendVariable.setVarKind(avar, BackendDAE.DUMMY_STATE()) else avar;
Expand All @@ -2912,7 +2913,7 @@ algorithm
// merge fixed, start, nominal
var = BackendVariable.mergeAliasVars(v1, v2, false, iKnVars);
// setAliasType
ops = DAEUtil.getSymbolicTransformations(source);
ops = ElementSource.getSymbolicTransformations(source);
avar = BackendVariable.mergeVariableOperations(v2, DAE.SOLVED(cr2, e1)::ops);
avar = BackendVariable.setBindExp(avar, SOME(e1));
avar = if BackendVariable.isStateVar(v2) then BackendVariable.setVarKind(avar, BackendDAE.DUMMY_STATE()) else avar;
Expand All @@ -2938,7 +2939,7 @@ algorithm
// merge fixed, start, nominal
var = BackendVariable.mergeAliasVars(v2, v1, false, iKnVars);
// setAliasType
ops = DAEUtil.getSymbolicTransformations(source);
ops = ElementSource.getSymbolicTransformations(source);
avar = BackendVariable.mergeVariableOperations(v1, DAE.SOLVED(cr1, e2)::ops);
avar = BackendVariable.setBindExp(avar, SOME(e2));
avar = if BackendVariable.isStateVar(v1) then BackendVariable.setVarKind(avar, BackendDAE.DUMMY_STATE()) else avar;
Expand All @@ -2964,7 +2965,7 @@ algorithm
// merge fixed, start, nominal
var = BackendVariable.mergeAliasVars(v1, v2, false, iKnVars);
// setAliasType
ops = DAEUtil.getSymbolicTransformations(source);
ops = ElementSource.getSymbolicTransformations(source);
avar = BackendVariable.mergeVariableOperations(v2, DAE.SOLVED(cr2, e1)::ops);
avar = BackendVariable.setBindExp(avar, SOME(e1));
avar = if BackendVariable.isStateVar(v2) then BackendVariable.setVarKind(avar, BackendDAE.DUMMY_STATE()) else avar;
Expand Down
97 changes: 49 additions & 48 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -65,6 +65,7 @@ import DAEUtil;
import DAEDump;
import Debug;
import Differentiate;
import ElementSource;
import Expression;
import ExpressionDump;
import ExpressionSolve;
Expand Down Expand Up @@ -1724,7 +1725,7 @@ algorithm
false = Expression.isZero(e1) or Expression.isZero(e2);
e = DAE.BINARY(e1,DAE.SUB(DAE.T_REAL_DEFAULT),e2);
(e,_) = ExpressionSimplify.simplify(e);
source = DAEUtil.addSymbolicTransformation(source, DAE.OP_RESIDUAL(e1,e2,e));
source = ElementSource.addSymbolicTransformation(source, DAE.OP_RESIDUAL(e1,e2,e));
then (BackendDAE.EQUATION(DAE.RCONST(0.0),e,source,eqAttr),i);
else (inEq,ii);
end matchcontinue;
Expand Down Expand Up @@ -2711,7 +2712,7 @@ algorithm
case (_, {}, _)
equation
Error.addSourceMessage(Error.IF_EQUATION_MISSING_ELSE, {},
DAEUtil.getElementSourceFileInfo(source));
ElementSource.getElementSourceFileInfo(source));
then
fail();

Expand All @@ -2725,7 +2726,7 @@ algorithm
strs = List.map(nrOfEquationsBranches, intString);
str = stringDelimitList(strs,",");
str = "{" + str + "," + intString(nrOfEquations) + "}";
Error.addSourceMessage(Error.IF_EQUATION_UNBALANCED_2,{str,eqstr},DAEUtil.getElementSourceFileInfo(source));
Error.addSourceMessage(Error.IF_EQUATION_UNBALANCED_2,{str,eqstr},ElementSource.getElementSourceFileInfo(source));
then
fail();

Expand All @@ -2748,7 +2749,7 @@ algorithm
equation
str = BackendDump.equationString(eq);
str = Util.stringReplaceChar(str,"\n","");
Error.addSourceMessage(Error.IF_EQUATION_WARNING,{str},DAEUtil.getElementSourceFileInfo(source));
Error.addSourceMessage(Error.IF_EQUATION_WARNING,{str},ElementSource.getElementSourceFileInfo(source));
exps = makeEquationLstToResidualExpLst(rest);
then exps;
case (eq::rest)
Expand Down Expand Up @@ -4202,20 +4203,20 @@ algorithm
BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns) := syst;
BackendDAE.EQUATION_ARRAY(numberOfElement = n) := eqns;
update := false;
indRemove := {};
indRemove := {};

for i in 1:n loop
try
eqn := BackendEquation.equationNth1(eqns, i);
else
continue;
end try;
try
eqn := BackendEquation.equationNth1(eqns, i);
else
continue;
end try;
if BackendEquation.isComplexEquation(eqn) or BackendEquation.isArrayEquation(eqn) then
if BackendEquation.isComplexEquation(eqn) then
BackendDAE.COMPLEX_EQUATION(size=size,left=left, right=right, attr= attr, source=source) := eqn;
else
BackendDAE.ARRAY_EQUATION(left=left, right=right, attr= attr, source=source) := eqn;
end if;
if BackendEquation.isComplexEquation(eqn) then
BackendDAE.COMPLEX_EQUATION(size=size,left=left, right=right, attr= attr, source=source) := eqn;
else
BackendDAE.ARRAY_EQUATION(left=left, right=right, attr= attr, source=source) := eqn;
end if;

if Expression.isTuple(left) and Expression.isTuple(right) then // tuple() = tuple()
//print(BackendDump.equationString(eqn) + "--In--\n");
Expand Down Expand Up @@ -4243,39 +4244,39 @@ algorithm
end if; //isScalar
end if; // isWild
end for;
elseif Expression.isArray(left) and Expression.isArray(right)
then // array{} = array{} // not work with arrayType
elseif Expression.isArray(left) and Expression.isArray(right)
then // array{} = array{} // not work with arrayType
//print(BackendDump.equationString(eqn) + "--In--\n");
try
left_lst := Expression.getArrayOrRangeContents(left);
right_lst := Expression.getArrayOrRangeContents(right);
update := true;
indRemove := i :: indRemove;
for e1 in left_lst loop
e2 :: right_lst := right_lst;
//print("=>" + ExpressionDump.printExpStr(e2) + " = " + ExpressionDump.printExpStr(e1) + "\n");
if not Expression.isWild(e1) then
if Expression.isScalar(e2) then
eqn1 := BackendEquation.generateEquation(e1, e2, source, attr);
eqns := BackendEquation.addEquation(eqn1, eqns);
//print(BackendDump.equationString(eqn1) + "--new--\n");
else
expLst := simplifyComplexFunction2(e1);
arrayLst := simplifyComplexFunction2(e2);
for e_asub in arrayLst loop
e3 :: expLst := expLst;
eqn1 := BackendEquation.generateEquation(e_asub, e3, source, attr);
eqns := BackendEquation.addEquation(eqn1, eqns);
//print(BackendDump.equationString(eqn1) + "--new--\n");
end for;
end if; //isScalar
end if; // isWild
end for;
else
continue;
end try;
try
left_lst := Expression.getArrayOrRangeContents(left);
right_lst := Expression.getArrayOrRangeContents(right);
update := true;
indRemove := i :: indRemove;
for e1 in left_lst loop
e2 :: right_lst := right_lst;
//print("=>" + ExpressionDump.printExpStr(e2) + " = " + ExpressionDump.printExpStr(e1) + "\n");
if not Expression.isWild(e1) then
if Expression.isScalar(e2) then
eqn1 := BackendEquation.generateEquation(e1, e2, source, attr);
eqns := BackendEquation.addEquation(eqn1, eqns);
//print(BackendDump.equationString(eqn1) + "--new--\n");
else
expLst := simplifyComplexFunction2(e1);
arrayLst := simplifyComplexFunction2(e2);
for e_asub in arrayLst loop
e3 :: expLst := expLst;
eqn1 := BackendEquation.generateEquation(e_asub, e3, source, attr);
eqns := BackendEquation.addEquation(eqn1, eqns);
//print(BackendDump.equationString(eqn1) + "--new--\n");
end for;
end if; //isScalar
end if; // isWild
end for;
else
continue;
end try;
elseif withTmpVars and Expression.isTuple(left) and Expression.isCall(right) //tuple() = call()
then
then
DAE.TUPLE(PR = left_lst) := left;
DAE.CALL(path=path,expLst = expLst, attr= cattr) := right;
expLst := {};
Expand Down Expand Up @@ -4347,8 +4348,8 @@ algorithm

if update then
for i in listReverse(indRemove) loop
//print("\neqns:" + intString(i) + "\n");
//BackendDump.printEquationArray(eqns);
//print("\neqns:" + intString(i) + "\n");
//BackendDump.printEquationArray(eqns);
eqns := BackendEquation.equationRemove(i,eqns);
end for;
eqns := BackendEquation.listEquation(BackendEquation.equationList(eqns));
Expand Down

0 comments on commit 18c51d6

Please sign in to comment.