Skip to content

Commit aab314c

Browse files
authored
[NF] allow non elementwise div for arrays (OpenModelica#13837)
- needed for retyping - attempt to fix more regressions from OpenModelica#13807
1 parent 83d7028 commit aab314c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

OMCompiler/Compiler/NFFrontEnd/NFTypeCheck.mo

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,23 @@ function checkBinaryOperation
167167
input Variability var2;
168168
input InstContext.Type context;
169169
input SourceInfo info;
170+
input Boolean retype "when retyping accept non elementwise operators for elementwise binaries";
170171
output Expression binaryExp;
171172
output Type resultType;
172173
algorithm
173174
if Type.isConditionalArray(type1) or Type.isConditionalArray(type2) then
174-
(binaryExp, resultType) := checkConditionalBinaryOperator(exp1, type1, var1, operator, exp2, type2, var2, context, info);
175+
(binaryExp, resultType) := checkConditionalBinaryOperator(exp1, type1, var1, operator, exp2, type2, var2, context, info, retype);
175176
elseif Type.isComplex(Type.arrayElementType(type1)) or
176177
Type.isComplex(Type.arrayElementType(type2)) then
177178
(binaryExp, resultType) := checkOverloadedBinaryOperator(exp1, type1, var1, operator, exp2, type2, var2, context, info);
178179
elseif Type.isBoxed(type1) and Type.isBoxed(type2) then
179-
(binaryExp, resultType) := checkBinaryOperationBoxed(exp1, type1, var1, operator, exp2, type2, var2, context, info);
180+
(binaryExp, resultType) := checkBinaryOperationBoxed(exp1, type1, var1, operator, exp2, type2, var2, context, info, retype);
180181
else
181182
(binaryExp, resultType) := match operator.op
182183
case Op.ADD then checkBinaryOperationAdd(exp1, type1, exp2, type2, info);
183184
case Op.SUB then checkBinaryOperationSub(exp1, type1, exp2, type2, info);
184185
case Op.MUL then checkBinaryOperationMul(exp1, type1, exp2, type2, info);
185-
case Op.DIV then checkBinaryOperationDiv(exp1, type1, exp2, type2, info, isElementWise = false);
186+
case Op.DIV then checkBinaryOperationDiv(exp1, type1, exp2, type2, info, isElementWise = retype);
186187
case Op.POW then checkBinaryOperationPow(exp1, type1, exp2, type2, info);
187188
case Op.ADD_EW then checkBinaryOperationEW(exp1, type1, exp2, type2, Op.ADD, info);
188189
case Op.SUB_EW then checkBinaryOperationEW(exp1, type1, exp2, type2, Op.SUB, info);
@@ -201,8 +202,8 @@ algorithm
201202
case Op.MUL_MATRIX_VECTOR then checkBinaryOperationMul(exp1, type1, exp2, type2, info);
202203
case Op.SCALAR_PRODUCT then checkBinaryOperationMul(exp1, type1, exp2, type2, info);
203204
case Op.MATRIX_PRODUCT then checkBinaryOperationMul(exp1, type1, exp2, type2, info);
204-
case Op.DIV_SCALAR_ARRAY then checkBinaryOperationDiv(exp1, type1, exp2, type2, info, isElementWise = false);
205-
case Op.DIV_ARRAY_SCALAR then checkBinaryOperationDiv(exp1, type1, exp2, type2, info, isElementWise = false);
205+
case Op.DIV_SCALAR_ARRAY then checkBinaryOperationDiv(exp1, type1, exp2, type2, info, isElementWise = retype);
206+
case Op.DIV_ARRAY_SCALAR then checkBinaryOperationDiv(exp1, type1, exp2, type2, info, isElementWise = retype);
206207
case Op.POW_SCALAR_ARRAY then checkBinaryOperationPowEW(exp1, type1, exp2, type2, info);
207208
case Op.POW_ARRAY_SCALAR then checkBinaryOperationPowEW(exp1, type1, exp2, type2, info);
208209
case Op.POW_MATRIX then checkBinaryOperationPow(exp1, type1, exp2, type2, info);
@@ -345,6 +346,7 @@ public function checkBinaryOperationBoxed
345346
input Variability var2;
346347
input InstContext.Type context;
347348
input SourceInfo info;
349+
input Boolean retype;
348350
output Expression outExp;
349351
output Type outType;
350352
protected
@@ -353,7 +355,7 @@ protected
353355
algorithm
354356
(e1, ty1) := matchTypes(type1, Type.unbox(type1), exp1);
355357
(e2, ty2) := matchTypes(type2, Type.unbox(type2), exp2);
356-
(outExp, outType) := checkBinaryOperation(e1, ty1, var1, op, e2, ty2, var2, context, info);
358+
(outExp, outType) := checkBinaryOperation(e1, ty1, var1, op, e2, ty2, var2, context, info, retype);
357359
end checkBinaryOperationBoxed;
358360

359361
protected
@@ -367,6 +369,7 @@ function checkConditionalBinaryOperator
367369
input Variability var2;
368370
input InstContext.Type context;
369371
input SourceInfo info;
372+
input Boolean retype;
370373
output Expression outExp;
371374
output Type outType;
372375
protected
@@ -384,14 +387,14 @@ algorithm
384387

385388
ErrorExt.setCheckpoint(getInstanceName());
386389
try
387-
(e1, ty1) := checkBinaryOperation(exp1, tty1, var1, op, exp2, tty2, var2, context, info);
390+
(e1, ty1) := checkBinaryOperation(exp1, tty1, var1, op, exp2, tty2, var2, context, info, retype);
388391
valid1 := true;
389392
else
390393
valid1 := false;
391394
end try;
392395

393396
try
394-
(e2, ty2) := checkBinaryOperation(exp1, fty1, var1, op, exp2, fty2, var2, context, info);
397+
(e2, ty2) := checkBinaryOperation(exp1, fty1, var1, op, exp2, fty2, var2, context, info, retype);
395398
valid2 := true;
396399
else
397400
valid2 := false;

OMCompiler/Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ algorithm
13621362
next_context := InstContext.set(context, NFInstContext.SUBEXPRESSION);
13631363
(e1, ty1, var1, pur1) := typeExp(exp.exp1, next_context, info);
13641364
(e2, ty2, var2, pur2) := typeExp(exp.exp2, next_context, info);
1365-
(exp, ty) := TypeCheck.checkBinaryOperation(e1, ty1, var1, exp.operator, e2, ty2, var2, context, info);
1365+
(exp, ty) := TypeCheck.checkBinaryOperation(e1, ty1, var1, exp.operator, e2, ty2, var2, context, info, retype);
13661366
then
13671367
(exp, ty, Prefixes.variabilityMax(var1, var2), Prefixes.purityMin(pur1, pur2));
13681368

0 commit comments

Comments
 (0)