Skip to content

Commit

Permalink
Support for fixed=false for strings
Browse files Browse the repository at this point in the history
Modelica 3.4 added a fixed attribute for strings. This adds support
for it in the compiler. Fixes ticket:4703.

Belonging to [master]:
  - OpenModelica/OMCompiler#2101
  - OpenModelica/OpenModelica-testsuite#816
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 10, 2018
1 parent 5c05ef6 commit bcf422b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 28 deletions.
7 changes: 4 additions & 3 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -6495,14 +6495,15 @@ algorithm
end if;
then (a,outExtraArg);

case(SOME(DAE.VAR_ATTR_STRING(q,i,eqbound,p,fin,startOrigin)),_,_) equation
case(SOME(DAE.VAR_ATTR_STRING(q,i,f,eqbound,p,fin,startOrigin)),_,_) equation
(q_,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg);
(i_,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg);
(f_,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg);
(eqbound_,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg);
if referenceEq(q,q_) and referenceEq(i,i_) and referenceEq(eqbound,eqbound_) then
if referenceEq(q,q_) and referenceEq(i,i_) and referenceEq(f,f_) and referenceEq(eqbound,eqbound_) then
a = attr;
else
a = SOME(DAE.VAR_ATTR_STRING(q_,i_,eqbound_,p,fin,startOrigin));
a = SOME(DAE.VAR_ATTR_STRING(q_,i_,f_,eqbound_,p,fin,startOrigin));
end if;
then (a,outExtraArg);

Expand Down
5 changes: 3 additions & 2 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -2664,13 +2664,14 @@ algorithm
startOrigin = replaceOptionExp(startOrigin,repl);
then DAE.VAR_ATTR_BOOL(quantity,start,fixed,equationBound,isProtected,finalPrefix,startOrigin);

case(DAE.VAR_ATTR_STRING(quantity,start,equationBound,isProtected,finalPrefix,startOrigin),_)
case(DAE.VAR_ATTR_STRING(quantity,start,fixed,equationBound,isProtected,finalPrefix,startOrigin),_)
equation
quantity = replaceOptionExp(quantity,repl);
start = replaceOptionExp(start,repl);
fixed = replaceOptionExp(fixed,repl);
equationBound = replaceOptionExp(equationBound,repl);
startOrigin = replaceOptionExp(startOrigin,repl);
then DAE.VAR_ATTR_STRING(quantity,start,equationBound,isProtected,finalPrefix,startOrigin);
then DAE.VAR_ATTR_STRING(quantity,start,fixed,equationBound,isProtected,finalPrefix,startOrigin);

case(DAE.VAR_ATTR_ENUMERATION(quantity,min,max,start,fixed,equationBound,isProtected,finalPrefix,startOrigin),_)
equation
Expand Down
3 changes: 2 additions & 1 deletion Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -114,6 +114,7 @@ algorithm
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_REAL(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_INT(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_BOOL(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_STRING(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_ENUMERATION(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;

// params and consts are by default fixed
Expand Down Expand Up @@ -481,7 +482,7 @@ algorithm
case DAE.T_INTEGER() then DAE.VAR_ATTR_INT(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
case DAE.T_INTEGER() then DAE.VAR_ATTR_INT(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
case DAE.T_BOOL() then DAE.VAR_ATTR_BOOL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
case DAE.T_STRING() then DAE.VAR_ATTR_STRING(NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
case DAE.T_STRING() then DAE.VAR_ATTR_STRING(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
case DAE.T_ENUMERATION() then DAE.VAR_ATTR_ENUMERATION(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
else equation
// repord a warning on failtrace
Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -503,6 +503,7 @@ uniontype VariableAttributes
record VAR_ATTR_STRING
Option<Exp> quantity "quantity";
Option<Exp> start "start value";
Option<Exp> fixed "new in Modelica 3.4; fixed - true: default for parameter/constant, false - default for other variables";
Option<Exp> equationBound;
Option<Boolean> isProtected;
Option<Boolean> finalPrefix;
Expand Down
5 changes: 3 additions & 2 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -624,14 +624,15 @@ algorithm
then
res;

case (SOME(DAE.VAR_ATTR_STRING(quant,initialExp,_,_,_,startOrigin)))
case (SOME(DAE.VAR_ATTR_STRING(quant,initialExp,fixed,_,_,_,startOrigin)))
equation
quantity = Dump.getOptionWithConcatStr(quant, ExpressionDump.printExpStr, "quantity = ");
initial_str = Dump.getOptionWithConcatStr(initialExp, ExpressionDump.printExpStr, "start = ");
fixed_str = Dump.getOptionWithConcatStr(fixed, ExpressionDump.printExpStr, "fixed = ");

startOriginStr = getStartOrigin(startOrigin);

res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,startOriginStr}, ", ");
res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,fixed_str,startOriginStr}, ", ");
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;
Expand Down
21 changes: 11 additions & 10 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -303,8 +303,8 @@ algorithm
case (_,SOME(DAE.VAR_ATTR_BOOL(e1,e2,e3,_,ip,fn,so)))
then SOME(DAE.VAR_ATTR_BOOL(e1,e2,e3,SOME(bindExp),ip,fn,so));

case (_,SOME(DAE.VAR_ATTR_STRING(e1,e2,_,ip,fn,so)))
then SOME(DAE.VAR_ATTR_STRING(e1,e2,SOME(bindExp),ip,fn,so));
case (_,SOME(DAE.VAR_ATTR_STRING(e1,e2,e3,_,ip,fn,so)))
then SOME(DAE.VAR_ATTR_STRING(e1,e2,e3,SOME(bindExp),ip,fn,so));

case (_,SOME(DAE.VAR_ATTR_ENUMERATION(e1,min,max,e2,e3,_,ip,fn,so)))
then SOME(DAE.VAR_ATTR_ENUMERATION(e1,min,max,e2,e3,SOME(bindExp),ip,fn,so));
Expand Down Expand Up @@ -1197,8 +1197,8 @@ algorithm
then SOME(DAE.VAR_ATTR_INT(q,min,max,i,f,unc,distOpt,eb,SOME(isProtected),fn,so));
case (SOME(DAE.VAR_ATTR_BOOL(q,i,f,eb,_,fn,so)),_)
then SOME(DAE.VAR_ATTR_BOOL(q,i,f,eb,SOME(isProtected),fn,so));
case (SOME(DAE.VAR_ATTR_STRING(q,i,eb,_,fn,so)),_)
then SOME(DAE.VAR_ATTR_STRING(q,i,eb,SOME(isProtected),fn,so));
case (SOME(DAE.VAR_ATTR_STRING(q,i,f,eb,_,fn,so)),_)
then SOME(DAE.VAR_ATTR_STRING(q,i,f,eb,SOME(isProtected),fn,so));
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,du,eb,_,fn,so)),_)
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,du,eb,SOME(isProtected),fn,so));
case (SOME(DAE.VAR_ATTR_CLOCK(fn,_)), _)
Expand Down Expand Up @@ -1246,8 +1246,8 @@ algorithm
then SOME(DAE.VAR_ATTR_INT(q,min,max,ini,fixed,unc,distOpt,eb,ip,fn,so));
case (SOME(DAE.VAR_ATTR_BOOL(q,ini,_,eb,ip,fn,so)),_)
then SOME(DAE.VAR_ATTR_BOOL(q,ini,fixed,eb,ip,fn,so));
case (SOME(DAE.VAR_ATTR_STRING(q,ini,eb,ip,fn,so)),_)
then SOME(DAE.VAR_ATTR_STRING(q,ini,eb,ip,fn,so));
case (SOME(DAE.VAR_ATTR_STRING(q,ini,_,eb,ip,fn,so)),_)
then SOME(DAE.VAR_ATTR_STRING(q,ini,fixed,eb,ip,fn,so));
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,_,eb,ip,fn,so)),_)
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,fixed,eb,ip,fn,so));
end match;
Expand Down Expand Up @@ -1277,8 +1277,8 @@ algorithm
// BTH
case (SOME(DAE.VAR_ATTR_CLOCK(ip,_)),_)
then SOME(DAE.VAR_ATTR_CLOCK(ip,SOME(finalPrefix)));
case (SOME(DAE.VAR_ATTR_STRING(q,i,eb,ip,_,so)),_)
then SOME(DAE.VAR_ATTR_STRING(q,i,eb,ip,SOME(finalPrefix),so));
case (SOME(DAE.VAR_ATTR_STRING(q,i,f,eb,ip,_,so)),_)
then SOME(DAE.VAR_ATTR_STRING(q,i,f,eb,ip,SOME(finalPrefix),so));
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,du,eb,ip,_,so)),_)
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,du,eb,ip,SOME(finalPrefix),so));
case (NONE(),_)
Expand Down Expand Up @@ -4933,11 +4933,12 @@ algorithm
case(SOME(DAE.VAR_ATTR_CLOCK(_,_)),_,extraArg)
then (attr,extraArg);

case(SOME(DAE.VAR_ATTR_STRING(quantity,start,eb,ip,fn,so)),_,extraArg)
case(SOME(DAE.VAR_ATTR_STRING(quantity,start,fixed,eb,ip,fn,so)),_,extraArg)
equation
(quantity,extraArg) = traverseDAEOptExp(quantity,func,extraArg);
(start,extraArg) = traverseDAEOptExp(start,func,extraArg);
then (SOME(DAE.VAR_ATTR_STRING(quantity,start,eb,ip,fn,so)),extraArg);
(fixed,extraArg) = traverseDAEOptExp(fixed,func,extraArg);
then (SOME(DAE.VAR_ATTR_STRING(quantity,start,fixed,eb,ip,fn,so)),extraArg);

case(SOME(DAE.VAR_ATTR_ENUMERATION(quantity,min,max,start,fixed,eb,ip,fn,so)),_,extraArg)
equation
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -108,11 +108,11 @@ algorithm
equation
(r,source,true,_) = inlineExp(r,fns,isource);
then (SOME(DAE.VAR_ATTR_BOOL(quantity,SOME(r),fixed,equationBound,isProtected,finalPrefix,so)),source,true);
case (SOME(DAE.VAR_ATTR_STRING(quantity=quantity,start = SOME(r),
case (SOME(DAE.VAR_ATTR_STRING(quantity=quantity,start = SOME(r),fixed=fixed,
equationBound=equationBound,isProtected=isProtected,finalPrefix=finalPrefix,startOrigin=so)),_,_)
equation
(r,source,true,_) = inlineExp(r,fns,isource);
then (SOME(DAE.VAR_ATTR_STRING(quantity,SOME(r),equationBound,isProtected,finalPrefix,so)),source,true);
then (SOME(DAE.VAR_ATTR_STRING(quantity,SOME(r),fixed,equationBound,isProtected,finalPrefix,so)),source,true);
case (SOME(DAE.VAR_ATTR_ENUMERATION(quantity=quantity,min=min,max=max,start = SOME(r),
fixed=fixed,equationBound=equationBound,
isProtected=isProtected,finalPrefix=finalPrefix,startOrigin=so)),_,_)
Expand Down
3 changes: 2 additions & 1 deletion Compiler/FrontEnd/InstBinding.mo
Expand Up @@ -384,9 +384,10 @@ algorithm
equation
(quantity_str) = instBinding(mod, varLst, tp, index_list, "quantity",false);
(start_val) = instBinding(mod, varLst, tp, index_list, "start",false);
(fixed_val) = instBinding(mod, varLst, DAE.T_BOOL_DEFAULT, index_list, "fixed",true);
startOrigin = instStartOrigin(mod, varLst, "start");
then
(cache,SOME(DAE.VAR_ATTR_STRING(quantity_str,start_val,NONE(),NONE(),NONE(),startOrigin)));
(cache,SOME(DAE.VAR_ATTR_STRING(quantity_str,start_val,fixed_val,NONE(),NONE(),NONE(),startOrigin)));

// Enumeration
case (cache,_,mod,enumtype as DAE.T_ENUMERATION(attributeLst = varLst),index_list)
Expand Down
7 changes: 3 additions & 4 deletions Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -326,14 +326,13 @@ function convertStringVarAttributes
input list<Modifier> mods;
output Option<DAE.VariableAttributes> attributes;
protected
Option<DAE.Exp> quantity = NONE(), start = NONE();
Option<DAE.Exp> quantity = NONE(), start = NONE(), fixed = NONE();
algorithm
for m in mods loop
() := match Modifier.name(m)
case "quantity" algorithm quantity := convertVarAttribute(m); then ();
case "start" algorithm start := convertVarAttribute(m); then ();
// TODO: VAR_ATTR_STRING has no field for fixed.
case "fixed" then ();
case "fixed" algorithm fixed := convertVarAttribute(m); then ();

// The attributes should already be type checked, so we shouldn't get any
// unknown attributes here.
Expand All @@ -346,7 +345,7 @@ algorithm
end for;

attributes := SOME(DAE.VariableAttributes.VAR_ATTR_STRING(
quantity, start, NONE(), NONE(), NONE(), NONE()));
quantity, start, fixed, NONE(), NONE(), NONE(), NONE()));
end convertStringVarAttributes;

function convertEnumVarAttributes
Expand Down
7 changes: 4 additions & 3 deletions Compiler/Util/VarTransform.mo
Expand Up @@ -353,15 +353,16 @@ algorithm
(fixed) = replaceExpOpt(fixed,repl,condExpFunc);
then SOME(DAE.VAR_ATTR_BOOL(quantity,initial_,fixed,eb,ip,fn,startOrigin));

case(SOME(DAE.VAR_ATTR_STRING(quantity,initial_,eb,ip,fn,startOrigin)),_,_)
case(SOME(DAE.VAR_ATTR_STRING(quantity,initial_,fixed,eb,ip,fn,startOrigin)),_,_)
equation
(quantity) = replaceExpOpt(quantity,repl,condExpFunc);
(initial_) = replaceExpOpt(initial_,repl,condExpFunc);
then SOME(DAE.VAR_ATTR_STRING(quantity,initial_,eb,ip,fn,startOrigin));
(fixed) = replaceExpOpt(fixed,repl,condExpFunc);
then SOME(DAE.VAR_ATTR_STRING(quantity,initial_,fixed,eb,ip,fn,startOrigin));

case (NONE(),_,_) then NONE();
end match;
end applyReplacementsVarAttr;
end applyReplacementsVarAttr;

public function applyReplacements "This function takes a VariableReplacements and two component references.
It applies the replacements to each component reference.
Expand Down

0 comments on commit bcf422b

Please sign in to comment.