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

Commit c4ab684

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
fixes for ticket:4276
- allow write to parameter(fixed=false) in initial algorithm
1 parent f4e679c commit c4ab684

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

Compiler/FrontEnd/Algorithm.mo

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,51 @@ algorithm
367367
end match;
368368
end makeAssignmentsList;
369369

370+
public function checkLHSWritable
371+
"@author: adrpo
372+
check if the parameters on rhs have fixed = false
373+
and fail otherwise"
374+
input list<DAE.Exp> lhs;
375+
input list<DAE.Properties> props;
376+
input DAE.Exp rhs;
377+
input DAE.ElementSource source;
378+
protected
379+
DAE.Type ty;
380+
Integer i = 1;
381+
String c, l, r;
382+
algorithm
383+
for p in props loop
384+
_ := matchcontinue p
385+
// variables is fine
386+
case DAE.PROP(constFlag = DAE.C_VAR()) then ();
387+
// constant
388+
case DAE.PROP(ty, DAE.C_CONST())
389+
equation
390+
l = stringAppendList({"(", stringDelimitList(List.map(lhs, ExpressionDump.printExpStr), ", "), ")"});
391+
r = ExpressionDump.printExpStr(rhs);
392+
Error.addSourceMessage(Error.ASSIGN_CONSTANT_ERROR, {l, r}, ElementSource.getElementSourceFileInfo(source));
393+
fail();
394+
then
395+
();
396+
// parameters
397+
case DAE.PROP(ty, DAE.C_PARAM())
398+
equation
399+
if Types.getFixedVarAttributeParameterOrConstant(ty) then
400+
l = stringAppendList({"(", stringDelimitList(List.map(lhs, ExpressionDump.printExpStr), ", "), ")"});
401+
r = ExpressionDump.printExpStr(rhs);
402+
c = ExpressionDump.printExpStr(listGet(lhs, i));
403+
Error.addSourceMessage(Error.ASSIGN_PARAM_FIXED_ERROR, {c, l, r}, ElementSource.getElementSourceFileInfo(source));
404+
fail();
405+
end if;
406+
then
407+
();
408+
// tuples? TODO! FIXME! can we get tuple here? maybe only for MetaModelica
409+
case DAE.PROP_TUPLE(ty, _) then ();
410+
end matchcontinue;
411+
i := i + 1;
412+
end for;
413+
end checkLHSWritable;
414+
370415
public function makeTupleAssignment "This function creates an `DAE.STMT_TUPLE_ASSIGN\' construct, and checks that the
371416
assignment is semantically valid, which means that the component
372417
being assigned is not constant, and that the types match."
@@ -390,6 +435,7 @@ algorithm
390435
list<DAE.Type> lhrtypes, tpl;
391436
list<DAE.TupleConst> clist;
392437
DAE.Type ty;
438+
DAE.Const const;
393439

394440
case (lhs, lprop, rhs, _, _, _)
395441
equation
@@ -416,8 +462,7 @@ algorithm
416462
// a normal prop in rhs that contains a T_TUPLE!
417463
case (expl, lhprops, rhs, DAE.PROP(type_ = ty as DAE.T_TUPLE(types = tpl)), _, _)
418464
equation
419-
bvals = List.map(lhprops, Types.propAnyConst);
420-
DAE.C_VAR() = List.reduce(bvals, Types.constOr);
465+
checkLHSWritable(expl, lhprops, rhs, source);
421466
lhrtypes = List.map(lhprops, Types.getPropType);
422467
Types.matchTypeTupleCall(rhs, tpl, lhrtypes);
423468
/* Don\'t use new rhs\', since type conversions of
@@ -426,8 +471,7 @@ algorithm
426471
// a tuple in rhs
427472
case (expl, lhprops, rhs, DAE.PROP_TUPLE(type_ = ty as DAE.T_TUPLE(types = tpl), tupleConst = DAE.TUPLE_CONST()), _, _)
428473
equation
429-
bvals = List.map(lhprops, Types.propAnyConst);
430-
DAE.C_VAR() = List.reduce(bvals, Types.constOr);
474+
checkLHSWritable(expl, lhprops, rhs, source);
431475
lhrtypes = List.map(lhprops, Types.getPropType);
432476
Types.matchTypeTupleCall(rhs, tpl, lhrtypes);
433477
/* Don\'t use new rhs\', since type conversions of several output args are not clearly defined. */

Compiler/Util/Error.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ public constant Message USER_TEARING_VARS = MESSAGE(578, SYMBOLIC(), NOTIFICATIO
866866
Util.gettext("Following iteration variables are selected by the user for strong component %s (DAE kind: %s):\n%s"));
867867
public constant Message CLASS_EXTENDS_TARGET_NOT_FOUND = MESSAGE(579, TRANSLATION(), ERROR(),
868868
Util.gettext("Base class targeted by class extends %s not found in the inherited classes."));
869+
public constant Message ASSIGN_PARAM_FIXED_ERROR = MESSAGE(580, TRANSLATION(), ERROR(),
870+
Util.gettext("Trying to assign to parameter component %s(fixed=true) in %s := %s"));
869871

870872
public constant Message MATCH_SHADOWING = MESSAGE(5001, TRANSLATION(), ERROR(),
871873
Util.gettext("Local variable '%s' shadows another variable."));

0 commit comments

Comments
 (0)