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

Commit bcf422b

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Support for fixed=false for strings
Modelica 3.4 added a fixed attribute for strings. This adds support for it in the compiler. Fixes ticket:4703. Belonging to [master]: - #2101 - OpenModelica/OpenModelica-testsuite#816
1 parent 5c05ef6 commit bcf422b

File tree

10 files changed

+35
-28
lines changed

10 files changed

+35
-28
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6495,14 +6495,15 @@ algorithm
64956495
end if;
64966496
then (a,outExtraArg);
64976497

6498-
case(SOME(DAE.VAR_ATTR_STRING(q,i,eqbound,p,fin,startOrigin)),_,_) equation
6498+
case(SOME(DAE.VAR_ATTR_STRING(q,i,f,eqbound,p,fin,startOrigin)),_,_) equation
64996499
(q_,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg);
65006500
(i_,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg);
6501+
(f_,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg);
65016502
(eqbound_,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg);
6502-
if referenceEq(q,q_) and referenceEq(i,i_) and referenceEq(eqbound,eqbound_) then
6503+
if referenceEq(q,q_) and referenceEq(i,i_) and referenceEq(f,f_) and referenceEq(eqbound,eqbound_) then
65036504
a = attr;
65046505
else
6505-
a = SOME(DAE.VAR_ATTR_STRING(q_,i_,eqbound_,p,fin,startOrigin));
6506+
a = SOME(DAE.VAR_ATTR_STRING(q_,i_,f_,eqbound_,p,fin,startOrigin));
65066507
end if;
65076508
then (a,outExtraArg);
65086509

Compiler/BackEnd/BackendVarTransform.mo

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,13 +2664,14 @@ algorithm
26642664
startOrigin = replaceOptionExp(startOrigin,repl);
26652665
then DAE.VAR_ATTR_BOOL(quantity,start,fixed,equationBound,isProtected,finalPrefix,startOrigin);
26662666

2667-
case(DAE.VAR_ATTR_STRING(quantity,start,equationBound,isProtected,finalPrefix,startOrigin),_)
2667+
case(DAE.VAR_ATTR_STRING(quantity,start,fixed,equationBound,isProtected,finalPrefix,startOrigin),_)
26682668
equation
26692669
quantity = replaceOptionExp(quantity,repl);
26702670
start = replaceOptionExp(start,repl);
2671+
fixed = replaceOptionExp(fixed,repl);
26712672
equationBound = replaceOptionExp(equationBound,repl);
26722673
startOrigin = replaceOptionExp(startOrigin,repl);
2673-
then DAE.VAR_ATTR_STRING(quantity,start,equationBound,isProtected,finalPrefix,startOrigin);
2674+
then DAE.VAR_ATTR_STRING(quantity,start,fixed,equationBound,isProtected,finalPrefix,startOrigin);
26742675

26752676
case(DAE.VAR_ATTR_ENUMERATION(quantity,min,max,start,fixed,equationBound,isProtected,finalPrefix,startOrigin),_)
26762677
equation

Compiler/BackEnd/BackendVariable.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ algorithm
114114
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_REAL(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
115115
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_INT(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
116116
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_BOOL(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
117+
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_STRING(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
117118
case (BackendDAE.VAR(values=SOME(DAE.VAR_ATTR_ENUMERATION(fixed=SOME(DAE.BCONST(fixed)))))) then fixed;
118119

119120
// params and consts are by default fixed
@@ -481,7 +482,7 @@ algorithm
481482
case DAE.T_INTEGER() then DAE.VAR_ATTR_INT(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
482483
case DAE.T_INTEGER() then DAE.VAR_ATTR_INT(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
483484
case DAE.T_BOOL() then DAE.VAR_ATTR_BOOL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
484-
case DAE.T_STRING() then DAE.VAR_ATTR_STRING(NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
485+
case DAE.T_STRING() then DAE.VAR_ATTR_STRING(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
485486
case DAE.T_ENUMERATION() then DAE.VAR_ATTR_ENUMERATION(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
486487
else equation
487488
// repord a warning on failtrace

Compiler/FrontEnd/DAE.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ uniontype VariableAttributes
503503
record VAR_ATTR_STRING
504504
Option<Exp> quantity "quantity";
505505
Option<Exp> start "start value";
506+
Option<Exp> fixed "new in Modelica 3.4; fixed - true: default for parameter/constant, false - default for other variables";
506507
Option<Exp> equationBound;
507508
Option<Boolean> isProtected;
508509
Option<Boolean> finalPrefix;

Compiler/FrontEnd/DAEDump.mo

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,14 +624,15 @@ algorithm
624624
then
625625
res;
626626

627-
case (SOME(DAE.VAR_ATTR_STRING(quant,initialExp,_,_,_,startOrigin)))
627+
case (SOME(DAE.VAR_ATTR_STRING(quant,initialExp,fixed,_,_,_,startOrigin)))
628628
equation
629629
quantity = Dump.getOptionWithConcatStr(quant, ExpressionDump.printExpStr, "quantity = ");
630630
initial_str = Dump.getOptionWithConcatStr(initialExp, ExpressionDump.printExpStr, "start = ");
631+
fixed_str = Dump.getOptionWithConcatStr(fixed, ExpressionDump.printExpStr, "fixed = ");
631632

632633
startOriginStr = getStartOrigin(startOrigin);
633634

634-
res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,startOriginStr}, ", ");
635+
res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,fixed_str,startOriginStr}, ", ");
635636
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
636637
then
637638
res;

Compiler/FrontEnd/DAEUtil.mo

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ algorithm
303303
case (_,SOME(DAE.VAR_ATTR_BOOL(e1,e2,e3,_,ip,fn,so)))
304304
then SOME(DAE.VAR_ATTR_BOOL(e1,e2,e3,SOME(bindExp),ip,fn,so));
305305

306-
case (_,SOME(DAE.VAR_ATTR_STRING(e1,e2,_,ip,fn,so)))
307-
then SOME(DAE.VAR_ATTR_STRING(e1,e2,SOME(bindExp),ip,fn,so));
306+
case (_,SOME(DAE.VAR_ATTR_STRING(e1,e2,e3,_,ip,fn,so)))
307+
then SOME(DAE.VAR_ATTR_STRING(e1,e2,e3,SOME(bindExp),ip,fn,so));
308308

309309
case (_,SOME(DAE.VAR_ATTR_ENUMERATION(e1,min,max,e2,e3,_,ip,fn,so)))
310310
then SOME(DAE.VAR_ATTR_ENUMERATION(e1,min,max,e2,e3,SOME(bindExp),ip,fn,so));
@@ -1197,8 +1197,8 @@ algorithm
11971197
then SOME(DAE.VAR_ATTR_INT(q,min,max,i,f,unc,distOpt,eb,SOME(isProtected),fn,so));
11981198
case (SOME(DAE.VAR_ATTR_BOOL(q,i,f,eb,_,fn,so)),_)
11991199
then SOME(DAE.VAR_ATTR_BOOL(q,i,f,eb,SOME(isProtected),fn,so));
1200-
case (SOME(DAE.VAR_ATTR_STRING(q,i,eb,_,fn,so)),_)
1201-
then SOME(DAE.VAR_ATTR_STRING(q,i,eb,SOME(isProtected),fn,so));
1200+
case (SOME(DAE.VAR_ATTR_STRING(q,i,f,eb,_,fn,so)),_)
1201+
then SOME(DAE.VAR_ATTR_STRING(q,i,f,eb,SOME(isProtected),fn,so));
12021202
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,du,eb,_,fn,so)),_)
12031203
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,du,eb,SOME(isProtected),fn,so));
12041204
case (SOME(DAE.VAR_ATTR_CLOCK(fn,_)), _)
@@ -1246,8 +1246,8 @@ algorithm
12461246
then SOME(DAE.VAR_ATTR_INT(q,min,max,ini,fixed,unc,distOpt,eb,ip,fn,so));
12471247
case (SOME(DAE.VAR_ATTR_BOOL(q,ini,_,eb,ip,fn,so)),_)
12481248
then SOME(DAE.VAR_ATTR_BOOL(q,ini,fixed,eb,ip,fn,so));
1249-
case (SOME(DAE.VAR_ATTR_STRING(q,ini,eb,ip,fn,so)),_)
1250-
then SOME(DAE.VAR_ATTR_STRING(q,ini,eb,ip,fn,so));
1249+
case (SOME(DAE.VAR_ATTR_STRING(q,ini,_,eb,ip,fn,so)),_)
1250+
then SOME(DAE.VAR_ATTR_STRING(q,ini,fixed,eb,ip,fn,so));
12511251
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,_,eb,ip,fn,so)),_)
12521252
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,fixed,eb,ip,fn,so));
12531253
end match;
@@ -1277,8 +1277,8 @@ algorithm
12771277
// BTH
12781278
case (SOME(DAE.VAR_ATTR_CLOCK(ip,_)),_)
12791279
then SOME(DAE.VAR_ATTR_CLOCK(ip,SOME(finalPrefix)));
1280-
case (SOME(DAE.VAR_ATTR_STRING(q,i,eb,ip,_,so)),_)
1281-
then SOME(DAE.VAR_ATTR_STRING(q,i,eb,ip,SOME(finalPrefix),so));
1280+
case (SOME(DAE.VAR_ATTR_STRING(q,i,f,eb,ip,_,so)),_)
1281+
then SOME(DAE.VAR_ATTR_STRING(q,i,f,eb,ip,SOME(finalPrefix),so));
12821282
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,du,eb,ip,_,so)),_)
12831283
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,u,du,eb,ip,SOME(finalPrefix),so));
12841284
case (NONE(),_)
@@ -4933,11 +4933,12 @@ algorithm
49334933
case(SOME(DAE.VAR_ATTR_CLOCK(_,_)),_,extraArg)
49344934
then (attr,extraArg);
49354935

4936-
case(SOME(DAE.VAR_ATTR_STRING(quantity,start,eb,ip,fn,so)),_,extraArg)
4936+
case(SOME(DAE.VAR_ATTR_STRING(quantity,start,fixed,eb,ip,fn,so)),_,extraArg)
49374937
equation
49384938
(quantity,extraArg) = traverseDAEOptExp(quantity,func,extraArg);
49394939
(start,extraArg) = traverseDAEOptExp(start,func,extraArg);
4940-
then (SOME(DAE.VAR_ATTR_STRING(quantity,start,eb,ip,fn,so)),extraArg);
4940+
(fixed,extraArg) = traverseDAEOptExp(fixed,func,extraArg);
4941+
then (SOME(DAE.VAR_ATTR_STRING(quantity,start,fixed,eb,ip,fn,so)),extraArg);
49414942

49424943
case(SOME(DAE.VAR_ATTR_ENUMERATION(quantity,min,max,start,fixed,eb,ip,fn,so)),_,extraArg)
49434944
equation

Compiler/FrontEnd/Inline.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ algorithm
108108
equation
109109
(r,source,true,_) = inlineExp(r,fns,isource);
110110
then (SOME(DAE.VAR_ATTR_BOOL(quantity,SOME(r),fixed,equationBound,isProtected,finalPrefix,so)),source,true);
111-
case (SOME(DAE.VAR_ATTR_STRING(quantity=quantity,start = SOME(r),
111+
case (SOME(DAE.VAR_ATTR_STRING(quantity=quantity,start = SOME(r),fixed=fixed,
112112
equationBound=equationBound,isProtected=isProtected,finalPrefix=finalPrefix,startOrigin=so)),_,_)
113113
equation
114114
(r,source,true,_) = inlineExp(r,fns,isource);
115-
then (SOME(DAE.VAR_ATTR_STRING(quantity,SOME(r),equationBound,isProtected,finalPrefix,so)),source,true);
115+
then (SOME(DAE.VAR_ATTR_STRING(quantity,SOME(r),fixed,equationBound,isProtected,finalPrefix,so)),source,true);
116116
case (SOME(DAE.VAR_ATTR_ENUMERATION(quantity=quantity,min=min,max=max,start = SOME(r),
117117
fixed=fixed,equationBound=equationBound,
118118
isProtected=isProtected,finalPrefix=finalPrefix,startOrigin=so)),_,_)

Compiler/FrontEnd/InstBinding.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,10 @@ algorithm
384384
equation
385385
(quantity_str) = instBinding(mod, varLst, tp, index_list, "quantity",false);
386386
(start_val) = instBinding(mod, varLst, tp, index_list, "start",false);
387+
(fixed_val) = instBinding(mod, varLst, DAE.T_BOOL_DEFAULT, index_list, "fixed",true);
387388
startOrigin = instStartOrigin(mod, varLst, "start");
388389
then
389-
(cache,SOME(DAE.VAR_ATTR_STRING(quantity_str,start_val,NONE(),NONE(),NONE(),startOrigin)));
390+
(cache,SOME(DAE.VAR_ATTR_STRING(quantity_str,start_val,fixed_val,NONE(),NONE(),NONE(),startOrigin)));
390391

391392
// Enumeration
392393
case (cache,_,mod,enumtype as DAE.T_ENUMERATION(attributeLst = varLst),index_list)

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,13 @@ function convertStringVarAttributes
326326
input list<Modifier> mods;
327327
output Option<DAE.VariableAttributes> attributes;
328328
protected
329-
Option<DAE.Exp> quantity = NONE(), start = NONE();
329+
Option<DAE.Exp> quantity = NONE(), start = NONE(), fixed = NONE();
330330
algorithm
331331
for m in mods loop
332332
() := match Modifier.name(m)
333333
case "quantity" algorithm quantity := convertVarAttribute(m); then ();
334334
case "start" algorithm start := convertVarAttribute(m); then ();
335-
// TODO: VAR_ATTR_STRING has no field for fixed.
336-
case "fixed" then ();
335+
case "fixed" algorithm fixed := convertVarAttribute(m); then ();
337336

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

348347
attributes := SOME(DAE.VariableAttributes.VAR_ATTR_STRING(
349-
quantity, start, NONE(), NONE(), NONE(), NONE()));
348+
quantity, start, fixed, NONE(), NONE(), NONE(), NONE()));
350349
end convertStringVarAttributes;
351350

352351
function convertEnumVarAttributes

Compiler/Util/VarTransform.mo

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,16 @@ algorithm
353353
(fixed) = replaceExpOpt(fixed,repl,condExpFunc);
354354
then SOME(DAE.VAR_ATTR_BOOL(quantity,initial_,fixed,eb,ip,fn,startOrigin));
355355

356-
case(SOME(DAE.VAR_ATTR_STRING(quantity,initial_,eb,ip,fn,startOrigin)),_,_)
356+
case(SOME(DAE.VAR_ATTR_STRING(quantity,initial_,fixed,eb,ip,fn,startOrigin)),_,_)
357357
equation
358358
(quantity) = replaceExpOpt(quantity,repl,condExpFunc);
359359
(initial_) = replaceExpOpt(initial_,repl,condExpFunc);
360-
then SOME(DAE.VAR_ATTR_STRING(quantity,initial_,eb,ip,fn,startOrigin));
360+
(fixed) = replaceExpOpt(fixed,repl,condExpFunc);
361+
then SOME(DAE.VAR_ATTR_STRING(quantity,initial_,fixed,eb,ip,fn,startOrigin));
361362

362363
case (NONE(),_,_) then NONE();
363364
end match;
364-
end applyReplacementsVarAttr;
365+
end applyReplacementsVarAttr;
365366

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

0 commit comments

Comments
 (0)