Skip to content

Commit 493450f

Browse files
authored
[NB] partially fix fill() and similar functions for resizable input (#13520)
- [NF] add a resizable check to the frontend so it accepts it - lower variable and equation types
1 parent 222c8d9 commit 493450f

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

OMCompiler/Compiler/NBackEnd/Classes/NBackendDAE.mo

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,10 @@ protected
612612
variables := VariablePointers.addList(binding_iter_lst, variables);
613613
knowns := VariablePointers.addList(binding_iter_lst, knowns);
614614
artificials := VariablePointers.addList(binding_iter_lst, artificials);
615+
616+
// lower the component references properly
615617
variables := VariablePointers.map(variables, function Variable.mapExp(fn = function lowerComponentReferenceExp(variables = variables)));
618+
variables := VariablePointers.map(variables, function Variable.applyToType(func = function Type.applyToDims(func = function lowerDimension(variables = variables))));
616619

617620
/* lower the records to add children */
618621
records := VariablePointers.mapPtr(records, function lowerRecordChildren(variables = variables));
@@ -1278,11 +1281,28 @@ protected
12781281
call.iters := list(Util.applyTuple21(tpl, function lowerInstNode(variables = variables)) for tpl in call.iters);
12791282
exp.call := call;
12801283
then exp;
1284+
12811285
else exp;
12821286
end match;
1287+
1288+
// also lower dimensions in the case of resizable variables
1289+
exp := Expression.applyToType(exp, function Type.applyToDims(func = function lowerDimension(variables = variables)));
12831290
end lowerComponentReferenceExp;
12841291

1285-
protected function lowerComponentReference
1292+
protected function lowerDimension
1293+
input output Dimension dim;
1294+
input VariablePointers variables;
1295+
algorithm
1296+
dim := match dim
1297+
case Dimension.RESIZABLE() algorithm
1298+
dim.exp := Expression.map(dim.exp, function lowerComponentReferenceExp(variables = variables));
1299+
then dim;
1300+
1301+
else dim;
1302+
end match;
1303+
end lowerDimension;
1304+
1305+
function lowerComponentReference
12861306
input output ComponentRef cref;
12871307
input VariablePointers variables;
12881308
protected

OMCompiler/Compiler/NFFrontEnd/NFBuiltinCall.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ protected
956956
(arg, arg_ty, arg_var, arg_pur) := Typing.typeExp(arg, context, info);
957957

958958
if not (InstContext.inAlgorithm(context) or InstContext.inFunction(context)) then
959-
if arg_var > Variability.PARAMETER and not InstContext.inInstanceAPI(context) then
959+
if arg_var > Variability.PARAMETER and not (InstContext.inInstanceAPI(context) or Expression.contains(arg, Expression.isResizableCref)) then
960960
Error.addSourceMessageAndFail(Error.NON_PARAMETER_EXPRESSION_DIMENSION,
961961
{Expression.toString(arg), String(index),
962962
List.toString(fillArg :: dimensionArgs, Expression.toString,

OMCompiler/Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,6 +4479,16 @@ public
44794479
end match;
44804480
end extractCref;
44814481

4482+
function isResizableCref
4483+
input Expression exp;
4484+
output Boolean b;
4485+
algorithm
4486+
b := match exp
4487+
case CREF() then ComponentRef.isResizable(exp.cref);
4488+
else false;
4489+
end match;
4490+
end isResizableCref;
4491+
44824492
function isIterator
44834493
input Expression exp;
44844494
output Boolean isIterator;

0 commit comments

Comments
 (0)