Skip to content

Commit c5ca0a5

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Various fixes.
- Evaluate all constants in Typing.typeExp by default, and disable the package constant replacing phase since it's no longer needed. - Don't evaluate iterators in Ceval. - Use a type alias for ExpOrigin instead of Integer, to make it clearer what it is. - Add generic error for unbound constants. Belonging to [master]: - OpenModelica/OMCompiler#2120 - OpenModelica/OpenModelica-testsuite#830
1 parent dbda08c commit c5ca0a5

File tree

7 files changed

+130
-97
lines changed

7 files changed

+130
-97
lines changed

Compiler/FrontEnd/MetaModelicaBuiltin.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function intBitRShift
260260
output Integer o;
261261
external "builtin";
262262
annotation(Documentation(info="<html>
263-
<p>Bit-wise right shift (like C, i << s).</p>
263+
<p>Bit-wise right shift (like C, i >> s).</p>
264264
</html>"));
265265
end intBitRShift;
266266

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ uniontype Call
352352

353353
function typeSpecialBuiltinFunction
354354
input Call call;
355-
input Integer origin;
355+
input ExpOrigin.Type origin;
356356
input SourceInfo info;
357357
output Expression callExp;
358358
output Type ty;
@@ -400,7 +400,7 @@ uniontype Call
400400
public
401401
function typeCall
402402
input output Expression callExp;
403-
input Integer origin;
403+
input ExpOrigin.Type origin;
404404
input SourceInfo info;
405405
output Type ty;
406406
output Variability variability;
@@ -430,7 +430,7 @@ uniontype Call
430430

431431
function typeMapIteratorCall
432432
input output Call call;
433-
input Integer origin;
433+
input ExpOrigin.Type origin;
434434
input SourceInfo info;
435435
output Type ty;
436436
output Variability variability;
@@ -474,7 +474,7 @@ uniontype Call
474474

475475
function typeMatchNormalCall
476476
input output Call call;
477-
input Integer origin;
477+
input ExpOrigin.Type origin;
478478
input SourceInfo info;
479479
output Type ty;
480480
output Variability variability;
@@ -487,7 +487,7 @@ uniontype Call
487487

488488
function typeNormalCall
489489
input output Call call;
490-
input Integer origin;
490+
input ExpOrigin.Type origin;
491491
input SourceInfo info;
492492
algorithm
493493
call := match call
@@ -537,7 +537,7 @@ uniontype Call
537537

538538
function matchTypedNormalCall
539539
input output Call argtycall;
540-
input Integer origin;
540+
input ExpOrigin.Type origin;
541541
input SourceInfo info;
542542
output Type ty;
543543
output Variability variability;
@@ -684,7 +684,7 @@ uniontype Call
684684

685685
function typeArgs
686686
input output Call call;
687-
input Integer origin;
687+
input ExpOrigin.Type origin;
688688
input SourceInfo info;
689689
algorithm
690690
call := match call
@@ -1122,7 +1122,7 @@ protected
11221122
"Types a function call that can be typed normally, but which always has
11231123
discrete variability regardless of the variability of the arguments."
11241124
input Call call;
1125-
input Integer origin;
1125+
input ExpOrigin.Type origin;
11261126
input SourceInfo info;
11271127
output Expression callExp;
11281128
output Type ty;
@@ -1140,7 +1140,7 @@ protected
11401140

11411141
function typeNdimsCall
11421142
input Call call;
1143-
input Integer origin;
1143+
input ExpOrigin.Type origin;
11441144
input SourceInfo info;
11451145
output Expression callExp;
11461146
output Type ty = Type.INTEGER();
@@ -1172,7 +1172,7 @@ protected
11721172

11731173
function typePreCall
11741174
input Call call;
1175-
input Integer origin;
1175+
input ExpOrigin.Type origin;
11761176
input SourceInfo info;
11771177
output Expression callExp;
11781178
output Type ty;
@@ -1207,7 +1207,7 @@ protected
12071207

12081208
function typeChangeCall
12091209
input Call call;
1210-
input Integer origin;
1210+
input ExpOrigin.Type origin;
12111211
input SourceInfo info;
12121212
output Expression callExp;
12131213
output Type ty;
@@ -1240,7 +1240,7 @@ protected
12401240

12411241
function typeDerCall
12421242
input Call call;
1243-
input Integer origin;
1243+
input ExpOrigin.Type origin;
12441244
input SourceInfo info;
12451245
output Expression callExp;
12461246
output Type ty;
@@ -1292,7 +1292,7 @@ protected
12921292

12931293
function typeEdgeCall
12941294
input Call call;
1295-
input Integer origin;
1295+
input ExpOrigin.Type origin;
12961296
input SourceInfo info;
12971297
output Expression callExp;
12981298
output Type ty;
@@ -1325,7 +1325,7 @@ protected
13251325

13261326
function typeMinMaxCall
13271327
input Call call;
1328-
input Integer origin;
1328+
input ExpOrigin.Type origin;
13291329
input SourceInfo info;
13301330
output Expression callExp;
13311331
output Type ty;
@@ -1347,7 +1347,7 @@ protected
13471347

13481348
function typeSumProductCall
13491349
input Call call;
1350-
input Integer origin;
1350+
input ExpOrigin.Type origin;
13511351
input SourceInfo info;
13521352
output Expression callExp;
13531353
output Type ty;
@@ -1373,7 +1373,7 @@ protected
13731373

13741374
function typeSmoothCall
13751375
input Call call;
1376-
input Integer origin;
1376+
input ExpOrigin.Type origin;
13771377
input SourceInfo info;
13781378
output Expression callExp;
13791379
output Type ty;
@@ -1393,7 +1393,7 @@ protected
13931393

13941394
function typeFillCall
13951395
input Call call;
1396-
input Integer origin;
1396+
input ExpOrigin.Type origin;
13971397
input SourceInfo info;
13981398
output Expression callExp;
13991399
output Type ty;
@@ -1432,7 +1432,7 @@ protected
14321432
input Type fillType;
14331433
input list<Expression> fillArgs;
14341434
input list<Expression> dimensionArgs;
1435-
input Integer origin;
1435+
input ExpOrigin.Type origin;
14361436
input SourceInfo info;
14371437
output Expression callExp;
14381438
output Type ty;
@@ -1485,7 +1485,7 @@ protected
14851485

14861486
function typeZerosOnesCall
14871487
input Call call;
1488-
input Integer origin;
1488+
input ExpOrigin.Type origin;
14891489
input SourceInfo info;
14901490
output Expression callExp;
14911491
output Type ty;
@@ -1519,7 +1519,7 @@ protected
15191519

15201520
function typeScalarCall
15211521
input Call call;
1522-
input Integer origin;
1522+
input ExpOrigin.Type origin;
15231523
input SourceInfo info;
15241524
output Expression callExp;
15251525
output Type ty;
@@ -1559,7 +1559,7 @@ protected
15591559

15601560
function typeVectorCall
15611561
input Call call;
1562-
input Integer origin;
1562+
input ExpOrigin.Type origin;
15631563
input SourceInfo info;
15641564
output Expression callExp;
15651565
output Type ty;
@@ -1603,7 +1603,7 @@ protected
16031603

16041604
function typeMatrixCall
16051605
input Call call;
1606-
input Integer origin;
1606+
input ExpOrigin.Type origin;
16071607
input SourceInfo info;
16081608
output Expression callExp;
16091609
output Type ty;
@@ -1653,7 +1653,7 @@ protected
16531653

16541654
function typeSymmetricCall
16551655
input Call call;
1656-
input Integer origin;
1656+
input ExpOrigin.Type origin;
16571657
input SourceInfo info;
16581658
output Expression callExp;
16591659
output Type ty;
@@ -1678,7 +1678,7 @@ protected
16781678

16791679
function typeTransposeCall
16801680
input Call call;
1681-
input Integer origin;
1681+
input ExpOrigin.Type origin;
16821682
input SourceInfo info;
16831683
output Expression callExp;
16841684
output Type ty;
@@ -1717,7 +1717,7 @@ protected
17171717

17181718
function typeCardinalityCall
17191719
input Call call;
1720-
input Integer origin;
1720+
input ExpOrigin.Type origin;
17211721
input SourceInfo info;
17221722
output Expression callExp;
17231723
output Type ty;
@@ -1737,7 +1737,7 @@ protected
17371737

17381738
function typeNoEventCall
17391739
input Call call;
1740-
input Integer origin;
1740+
input ExpOrigin.Type origin;
17411741
input SourceInfo info;
17421742
output Expression callExp;
17431743
output Type ty;

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ uniontype EvalTarget
7070
SourceInfo info;
7171
end CONDITION;
7272

73+
record GENERIC
74+
SourceInfo info;
75+
end GENERIC;
76+
7377
record IGNORE_ERRORS end IGNORE_ERRORS;
7478

7579
function isRange
@@ -124,7 +128,8 @@ algorithm
124128
ComponentRef cref;
125129
Dimension dim;
126130

127-
case Expression.CREF(cref = cref as ComponentRef.CREF(node = c as InstNode.COMPONENT_NODE()))
131+
case Expression.CREF(cref = cref as ComponentRef.CREF(node = c as InstNode.COMPONENT_NODE(),
132+
origin = NFComponentRef.Origin.CREF))
128133
algorithm
129134
Typing.typeComponentBinding(c, ExpOrigin.CLASS);
130135
binding := Component.getBinding(InstNode.component(c));
@@ -236,7 +241,6 @@ algorithm
236241
end match;
237242
end evalExpOpt;
238243

239-
240244
function evalBinding
241245
input Binding binding;
242246
input Expression originExp "The expression the binding came from, e.g. a cref.";
@@ -407,6 +411,14 @@ algorithm
407411
then
408412
fail();
409413

414+
case EvalTarget.GENERIC()
415+
algorithm
416+
Error.addMultiSourceMessage(Error.UNBOUND_CONSTANT,
417+
{Expression.toString(exp)},
418+
{InstNode.info(ComponentRef.node(Expression.toCref(exp))), target.info});
419+
then
420+
fail();
421+
410422
else ();
411423
end match;
412424
end printUnboundError;

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected
3939
import Function = NFFunction;
4040
import RangeIterator = NFRangeIterator;
4141
import NFPrefixes.Variability;
42+
import Prefixes = NFPrefixes;
4243

4344
public
4445
import Absyn.Path;
@@ -2250,6 +2251,5 @@ public
22502251
end match;
22512252
end hasArrayCall2;
22522253

2253-
22542254
annotation(__OpenModelica_Interface="frontend");
22552255
end NFExpression;

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ algorithm
140140
// Flatten and convert the class into a DAE.
141141
(flat_model, funcs) := Flatten.flatten(inst_cls, name);
142142

143-
// Replace or collect package constants depending on the
144-
// replacePackageConstants debug flag.
145-
if Flags.isSet(Flags.REPLACE_PACKAGE_CONSTS) then
146-
(flat_model, funcs) := Package.replaceConstants(flat_model, funcs);
147-
else
148-
flat_model := Package.collectConstants(flat_model, funcs);
149-
end if;
143+
// The backend doesn't handle constants well, so for now we just replace all
144+
// constants in Typing.typeExp.
145+
//// Replace or collect package constants depending on the
146+
//// replacePackageConstants debug flag.
147+
//if Flags.isSet(Flags.REPLACE_PACKAGE_CONSTS) then
148+
// (flat_model, funcs) := Package.replaceConstants(flat_model, funcs);
149+
//else
150+
// flat_model := Package.collectConstants(flat_model, funcs);
151+
//end if;
150152

151153
flat_model := Scalarize.scalarize(flat_model, name);
152154
(dae, daeFuncs) := ConvertDAE.convert(flat_model, funcs, name, InstNode.info(inst_cls));

0 commit comments

Comments
 (0)