Skip to content

Commit

Permalink
Make non-final constants inputs in constructors (#9016)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed May 24, 2022
1 parent d1c1c19 commit e4e4270
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 23 deletions.
7 changes: 0 additions & 7 deletions OMCompiler/Compiler/NFFrontEnd/NFComponent.mo
Expand Up @@ -980,13 +980,6 @@ public
end match;
end isTypeAttribute;

function isModifiable
input Component component;
output Boolean isModifiable;
algorithm
isModifiable := not isFinal(component) and not (isConst(component) and hasBinding(component));
end isModifiable;

function countConnectorVars
"Returns the number of potential (neither constant, parameter, input, nor
output), flow, and stream variables in the given connector."
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -1271,10 +1271,10 @@ algorithm
comp := InstNode.component(component);
attr := Component.getAttributes(comp);

if Component.isModifiable(comp) then
vis := InstNode.visibility(component);
else
if Component.isFinal(comp) then
vis := Visibility.PROTECTED;
else
vis := InstNode.visibility(component);
end if;

binding := Component.getBinding(comp);
Expand Down
10 changes: 5 additions & 5 deletions OMCompiler/Compiler/NFFrontEnd/NFRecord.mo
Expand Up @@ -253,12 +253,12 @@ algorithm

comp := InstNode.component(comp_node);

if Component.isModifiable(comp) then
setFieldDirection(comp_node, Direction.INPUT);
inputs := comp_node :: inputs;
else
if Component.isFinal(comp) then
setFieldDirection(comp_node, Direction.NONE);
locals := comp_node :: locals;
else
setFieldDirection(comp_node, Direction.INPUT);
inputs := comp_node :: inputs;
end if;
end collectRecordParam;

Expand Down Expand Up @@ -296,7 +296,7 @@ algorithm
else
comp := InstNode.component(comp_node);

if not Component.isModifiable(comp) then
if Component.isFinal(comp) then
fields := Field.LOCAL(InstNode.name(comp_node)) :: fields;
elseif not Component.isOutput(comp) then
fields := Field.INPUT(InstNode.name(comp_node)) :: fields;
Expand Down
Expand Up @@ -31,7 +31,7 @@ end FunctionRecordArg3;
// end BaseR;
//
// function R "Automatically generated record constructor for R"
// protected Integer n = 2;
// input Integer n = 2;
// input Real[2] x;
// output R res;
// end R;
Expand Down
4 changes: 2 additions & 2 deletions testsuite/flattening/modelica/scodeinst/RecordBinding6.mo
Expand Up @@ -6,7 +6,7 @@

record R
Real x;
constant Real y = 2.0;
final constant Real y = 2.0;
Real z;
end R;

Expand All @@ -20,7 +20,7 @@ end RecordBinding6;
// Result:
// class RecordBinding6
// constant Real r.x = 1.0;
// constant Real r.y = 2.0;
// final constant Real r.y = 2.0;
// constant Real r.z = 3.0;
// constant Real x = 1.0;
// constant Real y = 2.0;
Expand Down
4 changes: 2 additions & 2 deletions testsuite/flattening/modelica/scodeinst/RecordBinding7.mo
Expand Up @@ -6,7 +6,7 @@

record R
Real x;
constant Real y = x / 2.0;
final constant Real y = x / 2.0;
Real z;
end R;

Expand All @@ -20,7 +20,7 @@ end RecordBinding7;
// Result:
// class RecordBinding7
// constant Real r.x = 1.0;
// constant Real r.y = 0.5;
// final constant Real r.y = 0.5;
// constant Real r.z = 3.0;
// constant Real x = 1.0;
// constant Real y = 0.5;
Expand Down
6 changes: 3 additions & 3 deletions testsuite/flattening/modelica/scodeinst/RecordConstructor2.mo
Expand Up @@ -3,13 +3,13 @@
// status: correct
// cflags: -d=newInst
//
// Checks that constants in a record becomes protected in the default
// Checks that final components in a record becomes protected in the default
// constructor.
//

record R
Real x;
constant Real y = 1.0;
final constant Real y = 1.0;
end R;

model RecordConstructor2
Expand All @@ -27,7 +27,7 @@ end RecordConstructor2;
//
// class RecordConstructor2
// Real r.x;
// constant Real r.y = 1.0;
// final constant Real r.y = 1.0;
// algorithm
// r := R(time, 1.0);
// end RecordConstructor2;
Expand Down

0 comments on commit e4e4270

Please sign in to comment.