Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Replace evaluated parameters in hideResult
Browse files Browse the repository at this point in the history
- introduce hideResult in BackendDAE.VAR
- replace parameters in that attribute and do not use annotation anymore

see ticket:4089
  • Loading branch information
ptaeuber authored and OpenModelica-Hudson committed Nov 2, 2016
1 parent 8747e2f commit 70c7422
Show file tree
Hide file tree
Showing 20 changed files with 234 additions and 158 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ uniontype Var "variables"
.DAE.ElementSource source "origin of variable";
Option< .DAE.VariableAttributes> values "values on built-in attributes";
Option<TearingSelect> tearingSelectOption "value for TearingSelect";
.DAE.Exp hideResult "expression from the hideResult annotation";
Option<SCode.Comment> comment "this contains the comment and annotation from Absyn";
.DAE.ConnectorType connectorType "flow, stream, unspecified or not connector.";
.DAE.VarInnerOuter innerOuter "inner, outer, inner outer or unspecified";
Expand Down
22 changes: 14 additions & 8 deletions Compiler/BackEnd/BackendDAECreate.mo
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ algorithm
DAE.ConnectorType ct;
DAE.ElementSource source;
Option<DAE.VariableAttributes> dae_var_attr;
Option<BackendDAE.TearingSelect> ts;
Option<BackendDAE.TearingSelect> ts;
DAE.Exp hideResult;
Option<SCode.Comment> comment;
DAE.Type t;
DAE.VarVisibility protection;
Expand All @@ -752,8 +753,9 @@ algorithm
dae_var_attr = DAEUtil.setProtectedAttr(dae_var_attr, b);
dae_var_attr = setMinMaxFromEnumeration(t, dae_var_attr);
ts = BackendDAEUtil.setTearingSelectAttribute(comment);
hideResult = BackendDAEUtil.setHideResultAttribute(comment, b);
then
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io), false));
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false));
end match;
end lowerDynamicVar;

Expand All @@ -780,7 +782,8 @@ algorithm
DAE.ConnectorType ct;
DAE.ElementSource source;
Option<DAE.VariableAttributes> dae_var_attr;
Option<BackendDAE.TearingSelect> ts;
Option<BackendDAE.TearingSelect> ts;
DAE.Exp hideResult;
Option<SCode.Comment> comment;
DAE.Type t;
DAE.VarVisibility protection;
Expand Down Expand Up @@ -815,8 +818,9 @@ algorithm
eqLst = buildAssertAlgorithms({},source,assrtEqIn);
// building an algorithm of the assert
ts = NONE();
hideResult = BackendDAEUtil.setHideResultAttribute(comment, b);
then
(BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io), false), iInlineHT, eqLst);
(BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false), iInlineHT, eqLst);

else
equation
Expand Down Expand Up @@ -1112,7 +1116,8 @@ algorithm
DAE.ConnectorType ct;
DAE.ElementSource source;
Option<DAE.VariableAttributes> dae_var_attr;
Option<BackendDAE.TearingSelect> ts;
Option<BackendDAE.TearingSelect> ts;
DAE.Exp hideResult;
Option<SCode.Comment> comment;
DAE.Type t;
Absyn.InnerOuter io;
Expand All @@ -1131,9 +1136,10 @@ algorithm
equation
kind_1 = lowerExtObjVarkind(t);
tp = lowerType(t);
ts = NONE();
ts = NONE();
hideResult = DAE.BCONST(false);
then
BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io), false);
BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false);
end match;
end lowerExtObjVar;

Expand Down Expand Up @@ -1796,7 +1802,7 @@ algorithm
varDirection = DAE.BIDIR(), varParallelism = DAE.NON_PARALLEL(),
varType = DAE.T_CLOCK_DEFAULT, bindExp = NONE(),
bindValue = NONE(), arryDim = {}, source = DAE.emptyElementSource,
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()),
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()), hideResult = DAE.BCONST(false),
comment = NONE(), connectorType = DAE.NON_CONNECTOR(),
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = true ) :: inVars;
outEqs := BackendDAE.EQUATION( exp = DAE.CREF(componentRef = cr, ty = DAE.T_CLOCK_DEFAULT),
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5687,7 +5687,7 @@ protected
algorithm
(BackendDAE.DAE(eqs, shared), _) := BackendDAEUtil.mapEqSystemAndFold(inDAE, addTimeAsState1, 0);
orderedVars := BackendVariable.emptyVars();
var := BackendDAE.VAR(DAE.crefTimeState, BackendDAE.STATE(1, NONE()), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
var := BackendDAE.VAR(DAE.crefTimeState, BackendDAE.STATE(1, NONE()), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
var := BackendVariable.setVarFixed(var, true);
var := BackendVariable.setVarStartValue(var, DAE.CREF(DAE.crefTime, DAE.T_REAL_DEFAULT));
orderedVars := BackendVariable.addVar(var, orderedVars);
Expand Down
39 changes: 32 additions & 7 deletions Compiler/BackEnd/BackendDAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ protected
algorithm
name := Expression.reductionIterName(iter);
cr := ComponentReference.makeCrefIdent(name,DAE.T_INTEGER_DEFAULT,{});
backendVar := BackendDAE.VAR(cr, BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_INTEGER_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
backendVar := BackendDAE.VAR(cr, BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_INTEGER_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
end makeIterVariable;

protected function checkEquationSize"author: Frenkel TUD 2010-12
Expand Down Expand Up @@ -689,6 +689,7 @@ algorithm
DAE.ElementSource src;
Option<DAE.VariableAttributes> va;
Option<BackendDAE.TearingSelect> ts;
DAE.Exp hideResult;
Option<SCode.Comment> c;
DAE.ConnectorType ct;
Values.Value v;
Expand All @@ -702,7 +703,7 @@ algorithm
inVar;
case BackendDAE.VAR(varName = cr, varKind = vk, varDirection = vd, varParallelism = prl,
varType = ty, bindExp = SOME(e), arryDim = dims, source = src,
values = va, tearingSelectOption = ts, comment = c, connectorType = ct, innerOuter = io)
values = va, tearingSelectOption = ts, hideResult = hideResult, comment = c, connectorType = ct, innerOuter = io)
equation
// wbraun: Evaluate parameter expressions only if they are
// constant at compile time otherwise we solve them
Expand All @@ -711,7 +712,7 @@ algorithm
true = Expression.isConst(e);
(_, v, _) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
then
BackendDAE.VAR(cr, vk, vd, prl, ty, SOME(e), SOME(v), dims, src, va, ts, c, ct, io, false);
BackendDAE.VAR(cr, vk, vd, prl, ty, SOME(e), SOME(v), dims, src, va, ts, hideResult, c, ct, io, false);
else inVar;
end matchcontinue;
end calculateValue;
Expand Down Expand Up @@ -1207,6 +1208,7 @@ end simplifySubscript;


public function setTearingSelectAttribute
"Returns the expression of the tearingSelect annotation"
input Option<SCode.Comment> comment;
output Option<BackendDAE.TearingSelect> ts;
protected
Expand All @@ -1232,6 +1234,28 @@ algorithm
end setTearingSelectAttribute;


public function setHideResultAttribute
"Returns the expression of the hideResult annotation.
Uses isProtected as default if the annotation is not specified.
See Modelica Spec 3.3, section 18.3"
input Option<SCode.Comment> comment;
input Boolean isProtected;
output DAE.Exp hideResult;
protected
SCode.Annotation ann;
Absyn.Exp val;
String ts_str;
algorithm
try
SOME(SCode.COMMENT(annotation_=SOME(ann))) := comment;
val := SCode.getNamedAnnotation(ann, "HideResult");
hideResult := Expression.fromAbsynExp(val);
else
hideResult := DAE.BCONST(isProtected);
end try;
end setHideResultAttribute;


/*******************************************
Functions that deals with BackendDAE as input
********************************************/
Expand Down Expand Up @@ -6258,6 +6282,7 @@ algorithm
list<DAE.Dimension> instdims;
Option<DAE.VariableAttributes> attr, attr_;
Option<BackendDAE.TearingSelect> ts;
DAE.Exp hideResult;
Type_a ext_arg_1, ext_arg_2;
BackendDAE.VarKind varKind;
DAE.VarDirection varDirection;
Expand All @@ -6275,22 +6300,22 @@ algorithm
case NONE()
then (NONE(), inTypeA);

case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)) equation
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), bindValue, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
(e1_, ext_arg_1) = func(e1, inTypeA);
(attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, ext_arg_1);
if referenceEq(e1,e1_) and referenceEq(attr,attr_) then
v = inVar;
else
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1_), bindValue, instdims, source, attr_, ts, comment, ct, io, unreplaceable));
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1_), bindValue, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
end if;
then (v, ext_arg_2);

case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)) equation
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
(attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, inTypeA);
if referenceEq(attr,attr_) then
v = inVar;
else
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr_, ts, comment, ct, io, unreplaceable));
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
end if;
then (v, ext_arg_2);

Expand Down
12 changes: 6 additions & 6 deletions Compiler/BackEnd/BackendEquation.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.LESS(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e1,e2);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2312,7 +2312,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.LESSEQ(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e1,e2);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2322,7 +2322,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.GREATER(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2332,7 +2332,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.GREATEREQ(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2342,7 +2342,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.EQUAL(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2357,7 +2357,7 @@ algorithm
end try;

lhs := ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar := BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar := BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar := BackendVariable.mergeAliasVars(dummyVar, v, false, knvars);
eqn := BackendDAE.SOLVED_EQUATION(lhs, e1, Source, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN);

Expand Down
5 changes: 3 additions & 2 deletions Compiler/BackEnd/BackendInline.mo
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ algorithm
DAE.InstDims arrayDim;
Option<DAE.VariableAttributes> values,values1;
Option<BackendDAE.TearingSelect> ts;
DAE.Exp hideResult;
Option<SCode.Comment> comment;
DAE.ConnectorType ct;
DAE.ElementSource source;
Expand All @@ -524,10 +525,10 @@ algorithm
DAE.VarInnerOuter io;
Boolean unreplaceable;

case BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values,ts,comment,ct,io,unreplaceable) equation
case BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values,ts,hideResult,comment,ct,io,unreplaceable) equation
(bind,source,b1) = Inline.inlineExpOpt(bind,inElementList,source);
(values1,source,b2) = Inline.inlineStartAttribute(values,source,inElementList);
then (BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values1,ts,comment,ct,io,unreplaceable), b1 or b2);
then (BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values1,ts,hideResult,comment,ct,io,unreplaceable), b1 or b2);

else (inVar, false);
end match;
Expand Down

0 comments on commit 70c7422

Please sign in to comment.