Skip to content

Commit

Permalink
Fix for #2643:
Browse files Browse the repository at this point in the history
- Remove default values on record members if the are given a binding by a
  modifier.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19914 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Apr 1, 2014
1 parent 970ddec commit b62f02c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 10 deletions.
34 changes: 28 additions & 6 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -1069,19 +1069,16 @@ algorithm
DAE.Type tp;
DAE.InstDims dim;
DAE.ConnectorType ct;
DAE.VarVisibility prot;
Option<DAE.Exp> bind;
Option<DAE.VariableAttributes> dae_var_attr;
Option<SCode.Comment> comment;
Absyn.Path newtype;
Absyn.InnerOuter io;
DAE.ElementSource source "the element origin";

case (DAE.VAR(componentRef = cr,
kind = kind,
direction = dir,
parallelism = prl,
protection = prot,
ty = tp,
binding = bind,
dims = dim,
Expand All @@ -1106,7 +1103,6 @@ algorithm
local
DAE.ComponentRef cr;
DAE.VarKind kind;
DAE.VarDirection dir;
DAE.VarParallelism prl;
DAE.Type tp;
DAE.InstDims dim;
Expand All @@ -1115,13 +1111,11 @@ algorithm
Option<DAE.Exp> bind;
Option<DAE.VariableAttributes> dae_var_attr;
Option<SCode.Comment> comment;
Absyn.Path newtype;
Absyn.InnerOuter io;
DAE.ElementSource source "the element origin";

case (DAE.VAR(componentRef = cr,
kind = kind,
direction = dir,
parallelism = prl,
protection = prot,
ty = tp,
Expand All @@ -1138,6 +1132,34 @@ algorithm
end match;
end setElementVarDirection;

public function setElementVarBinding
"Sets the binding of a VAR DAE.Element."
input DAE.Element inElement;
input Option<DAE.Exp> inBinding;
output DAE.Element outElement;
algorithm
outElement := match(inElement, inBinding)
local
DAE.ComponentRef cr;
DAE.VarKind vk;
DAE.VarDirection vd;
DAE.VarParallelism vp;
DAE.VarVisibility vv;
DAE.Type ty;
DAE.InstDims dims;
DAE.ConnectorType ct;
DAE.ElementSource src;
Option<DAE.VariableAttributes> va;
Option<SCode.Comment> cmt;
Absyn.InnerOuter io;

case (DAE.VAR(cr, vk, vd, vp, vv, ty, _, dims, ct, src, va, cmt, io),_)
then DAE.VAR(cr, vk, vd, vp, vv, ty, inBinding, dims, ct, src, va, cmt, io);

else inElement;
end match;
end setElementVarBinding;

public function setProtectedAttr "
sets the start attribute. If NONE(), assumes Real attributes."
input Option<DAE.VariableAttributes> attr;
Expand Down
62 changes: 58 additions & 4 deletions Compiler/FrontEnd/InstVar.mo
Expand Up @@ -1041,7 +1041,7 @@ protected function instScalar2
algorithm
outDae := match(inCref, inType, inVariability, inMod, inDae, inClassDae, inSource, inImpl)
local
DAE.DAElist dae;
DAE.DAElist dae, cls_dae;

// Constant with binding.
case (_, _, SCode.CONST(), DAE.MOD(eqModOption = SOME(DAE.TYPED(modifierAsExp = _))),
Expand Down Expand Up @@ -1096,15 +1096,69 @@ algorithm
// All other scalars.
else
equation
dae = InstBinding.instModEquation(inCref, inType, inMod, inSource, inImpl);
dae = Util.if_(Types.isComplexType(inType), dae, DAE.emptyDae);
dae = Debug.bcallret5(Types.isComplexType(inType),
InstBinding.instModEquation, inCref, inType, inMod, inSource, inImpl,
DAE.emptyDae);
cls_dae = stripRecordDefaultBindingsFromDAE(inClassDae, inType, dae);
dae = DAEUtil.joinDaes(dae, inDae);
dae = DAEUtil.joinDaes(inClassDae, dae);
dae = DAEUtil.joinDaes(cls_dae, dae);
then
dae;
end match;
end instScalar2;

protected function stripRecordDefaultBindingsFromDAE
"This function removes bindings from record members for which a binding
equation has already been generated. This is done because the record members
otherwise get a binding from the default argument of the record too."
input DAE.DAElist inClassDAE;
input DAE.Type inType;
input DAE.DAElist inEqDAE;
output DAE.DAElist outClassDAE;
algorithm
outClassDAE := match(inClassDAE, inType, inEqDAE)
local
list<DAE.Element> els, eqs;

// Check if the component is of record type, and if any equations have been
// generated for the component's binding.
case (DAE.DAE(elementLst = els),
DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path = _)),
DAE.DAE(elementLst = eqs as _ :: _))
equation
// This assumes that the equations are ordered the same as the variables.
(els, _) = List.mapFold(els, stripRecordDefaultBindingsFromElement, eqs);
then
DAE.DAE(els);

else inClassDAE;
end match;
end stripRecordDefaultBindingsFromDAE;

protected function stripRecordDefaultBindingsFromElement
input DAE.Element inVar;
input list<DAE.Element> inEqs;
output DAE.Element outVar;
output list<DAE.Element> outEqs;
algorithm
(outVar, outEqs) := matchcontinue(inVar, inEqs)
local
DAE.ComponentRef var_cr, eq_cr;
list<DAE.Element> rest_eqs;

case (DAE.VAR(componentRef = var_cr),
DAE.EQUATION(exp = DAE.CREF(componentRef = eq_cr)) :: rest_eqs)
equation
true = ComponentReference.crefEqual(var_cr, eq_cr);
// The first equation assigns the variable. Remove the variable's
// binding and discard the equation.
then
(DAEUtil.setElementVarBinding(inVar, NONE()), rest_eqs);

else (inVar, inEqs);
end matchcontinue;
end stripRecordDefaultBindingsFromElement;

protected function instArray
"When an array is instantiated by instVar, this function is used
to go through all the array elements and instantiate each array
Expand Down

0 comments on commit b62f02c

Please sign in to comment.