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

Commit 64d4bf1

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
[NF] Use Error.assertion() instead of assert()
Error.assertion reports errors to the error buffer, which means that the message can be access in scripting and OMPython. This fixes ticket:4676 Belonging to [master]: - #2080
1 parent 62af4e6 commit 64d4bf1

24 files changed

+111
-124
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ uniontype Call
142142
case Absyn.FOR_ITER_FARG() then instIteratorCall(functionName, functionArgs, scope, info);
143143
else
144144
algorithm
145-
assert(false, getInstanceName() + " got unknown call type");
145+
Error.assertion(false, getInstanceName() + " got unknown call type", sourceInfo());
146146
then
147147
fail();
148148
end match;
@@ -194,7 +194,7 @@ uniontype Call
194194

195195
else
196196
algorithm
197-
assert(false, getInstanceName() + " got unknown function args");
197+
Error.assertion(false, getInstanceName() + " got unknown function args", sourceInfo());
198198
then
199199
fail();
200200
end match;
@@ -356,7 +356,7 @@ uniontype Call
356356
case "zeros" then typeZerosOnesCall(call, origin, info);
357357
else
358358
algorithm
359-
assert(false, getInstanceName() + " got unhandled builtin function");
359+
Error.assertion(false, getInstanceName() + " got unhandled builtin function", sourceInfo());
360360
then
361361
fail();
362362
end match;
@@ -412,7 +412,7 @@ uniontype Call
412412
case UNTYPED_MAP_CALL(ref = ComponentRef.CREF(node = fn_node)) algorithm
413413
// Fetch the cached function(s).
414414
fnl := typeCachedFunctions(call.ref);
415-
assert(listLength(fnl) == 1, getInstanceName() + " overloaded functions in mapping functions not handled yet.");
415+
Error.assertion(listLength(fnl) == 1, getInstanceName() + " overloaded functions in mapping functions not handled yet.", sourceInfo());
416416
fn := listHead(fnl);
417417

418418
for iter in call.iters loop
@@ -431,7 +431,7 @@ uniontype Call
431431
(TYPED_MAP_CALL(fn, ty, arg, call.iters), ty, variability);
432432

433433
else algorithm
434-
assert(false, getInstanceName() + " got invalid function call expression");
434+
Error.assertion(false, getInstanceName() + " got invalid function call expression", sourceInfo());
435435
then
436436
fail();
437437
end match;
@@ -462,7 +462,7 @@ uniontype Call
462462
typeArgs(call, origin, info);
463463

464464
else algorithm
465-
assert(false, getInstanceName() + " got invalid function call expression");
465+
Error.assertion(false, getInstanceName() + " got invalid function call expression", sourceInfo());
466466
then
467467
fail();
468468
end match;
@@ -494,7 +494,7 @@ uniontype Call
494494

495495
else
496496
algorithm
497-
assert(false, getInstanceName() + " got invalid function call reference");
497+
Error.assertion(false, getInstanceName() + " got invalid function call reference", sourceInfo());
498498
then
499499
fail();
500500
end match;
@@ -537,7 +537,7 @@ uniontype Call
537537
(TYPED_CALL(fn, ty, args, ca), ty, variability);
538538

539539
else algorithm
540-
assert(false, getInstanceName() + " got invalid function call expression");
540+
Error.assertion(false, getInstanceName() + " got invalid function call expression", sourceInfo());
541541
then
542542
fail();
543543
end match;
@@ -758,7 +758,7 @@ protected
758758

759759
else
760760
algorithm
761-
assert(false, getInstanceName() + " got untyped call");
761+
Error.assertion(false, getInstanceName() + " got untyped call", sourceInfo());
762762
then
763763
fail();
764764
end match;
@@ -839,7 +839,7 @@ protected
839839
case TYPED_MAP_CALL() then call.fn;
840840
else
841841
algorithm
842-
assert(false, getInstanceName() + " got untyped function");
842+
Error.assertion(false, getInstanceName() + " got untyped function", sourceInfo());
843843
then
844844
fail();
845845
end match;

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ algorithm
126126

127127
case Expression.RECORD()
128128
algorithm
129-
assert(false, "Unimplemented case for " + Expression.toString(exp) + " in " + getInstanceName());
129+
Error.assertion(false, "Unimplemented case for " + Expression.toString(exp) + " in " + getInstanceName(), sourceInfo());
130130
then fail();
131131

132132
case Expression.CALL(call = call as Call.TYPED_CALL())
@@ -226,7 +226,7 @@ algorithm
226226
originExp;
227227
else
228228
algorithm
229-
assert(false, getInstanceName() + " failed on untyped binding");
229+
Error.assertion(false, getInstanceName() + " failed on untyped binding", sourceInfo());
230230
then
231231
fail();
232232
end match;
@@ -280,7 +280,7 @@ algorithm
280280

281281
else
282282
algorithm
283-
assert(false, getInstanceName() + " got invalid typename");
283+
Error.assertion(false, getInstanceName() + " got invalid typename", sourceInfo());
284284
then
285285
fail();
286286

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ uniontype Class
281281
();
282282
else
283283
algorithm
284-
assert(false, getInstanceName() + " got non-modifiable class");
284+
Error.assertion(false, getInstanceName() + " got non-modifiable class", sourceInfo());
285285
then
286286
fail();
287287
end match;

Compiler/NFFrontEnd/NFClassTree.mo

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public
400400

401401
else
402402
algorithm
403-
assert(false, getInstanceName() + " got invalid component");
403+
Error.assertion(false, getInstanceName() + " got invalid component", sourceInfo());
404404
then
405405
fail();
406406
end match;
@@ -556,8 +556,8 @@ public
556556
end for;
557557

558558
// Sanity check.
559-
assert(comp_idx == compCount + 1, getInstanceName() + " miscounted components in " + InstNode.name(clsNode));
560-
assert(cls_idx == classCount + 1, getInstanceName() + " miscounted classes in " + InstNode.name(clsNode));
559+
Error.assertion(comp_idx == compCount + 1, getInstanceName() + " miscounted components in " + InstNode.name(clsNode), sourceInfo());
560+
Error.assertion(cls_idx == classCount + 1, getInstanceName() + " miscounted classes in " + InstNode.name(clsNode), sourceInfo());
561561

562562
// Create a new class tree and update the class in the node.
563563
cls.elements := INSTANTIATED_TREE(ltree, clss, comps, local_comps, exts, imps, dups);
@@ -573,7 +573,7 @@ public
573573

574574
else
575575
algorithm
576-
assert(false, getInstanceName() + " got invalid class");
576+
Error.assertion(false, getInstanceName() + " got invalid class", sourceInfo());
577577
then
578578
fail();
579579

@@ -945,7 +945,7 @@ public
945945
node := resolveEntry(entry.entry, tree);
946946
end if;
947947
else
948-
assert(false, getInstanceName() + " failed on " + name);
948+
Error.assertion(false, getInstanceName() + " failed on " + name, sourceInfo());
949949
end try;
950950
end getRedeclaredNode;
951951

@@ -1137,13 +1137,13 @@ public
11371137
end for;
11381138

11391139
// Make extra sure that we actually found the component.
1140-
assert(i == entry.index, getInstanceName() + " got invalid entry index");
1140+
Error.assertion(i == entry.index, getInstanceName() + " got invalid entry index", sourceInfo());
11411141
then
11421142
node;
11431143

11441144
else
11451145
algorithm
1146-
assert(false, getInstanceName() + " got invalid entry");
1146+
Error.assertion(false, getInstanceName() + " got invalid entry", sourceInfo());
11471147
then
11481148
fail();
11491149

Compiler/NFFrontEnd/NFComponentRef.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public
345345

346346
else
347347
algorithm
348-
assert(false, getInstanceName() + " failed");
348+
Error.assertion(false, getInstanceName() + " failed", sourceInfo());
349349
then
350350
fail();
351351
end match;

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ algorithm
255255
// unknown attributes here.
256256
else
257257
algorithm
258-
assert(false, getInstanceName() + " got unknown type attribute " +
259-
Modifier.name(m));
258+
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
260259
then
261260
fail();
262261
end match;
@@ -286,8 +285,7 @@ algorithm
286285
// unknown attributes here.
287286
else
288287
algorithm
289-
assert(false, getInstanceName() + " got unknown type attribute " +
290-
Modifier.name(m));
288+
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
291289
then
292290
fail();
293291
end match;
@@ -314,8 +312,7 @@ algorithm
314312
// unknown attributes here.
315313
else
316314
algorithm
317-
assert(false, getInstanceName() + " got unknown type attribute " +
318-
Modifier.name(m));
315+
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
319316
then
320317
fail();
321318
end match;
@@ -342,8 +339,7 @@ algorithm
342339
// unknown attributes here.
343340
else
344341
algorithm
345-
assert(false, getInstanceName() + " got unknown type attribute " +
346-
Modifier.name(m));
342+
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
347343
then
348344
fail();
349345
end match;
@@ -372,8 +368,7 @@ algorithm
372368
// unknown attributes here.
373369
else
374370
algorithm
375-
assert(false, getInstanceName() + " got unknown type attribute " +
376-
Modifier.name(m));
371+
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
377372
then
378373
fail();
379374
end match;
@@ -396,7 +391,7 @@ algorithm
396391

397392
else
398393
algorithm
399-
assert(false, getInstanceName() + " got untyped binding");
394+
Error.assertion(false, getInstanceName() + " got untyped binding", sourceInfo());
400395
then
401396
fail();
402397

@@ -427,13 +422,13 @@ algorithm
427422

428423
case Modifier.MODIFIER(binding = Binding.TYPED_BINDING())
429424
algorithm
430-
assert(false, getInstanceName() + " got non StateSelect value");
425+
Error.assertion(false, getInstanceName() + " got non StateSelect value", sourceInfo());
431426
then
432427
fail();
433428

434429
else
435430
algorithm
436-
assert(false, getInstanceName() + " got untyped binding");
431+
Error.assertion(false, getInstanceName() + " got untyped binding", sourceInfo());
437432
then
438433
fail();
439434

@@ -452,7 +447,7 @@ algorithm
452447
case "always" then DAE.StateSelect.ALWAYS();
453448
else
454449
algorithm
455-
assert(false, getInstanceName() + " got unknown StateSelect literal " + name);
450+
Error.assertion(false, getInstanceName() + " got unknown StateSelect literal " + name, sourceInfo());
456451
then
457452
fail();
458453
end match;
@@ -506,7 +501,7 @@ algorithm
506501
// For equations should have been unrolled here.
507502
case Equation.FOR()
508503
algorithm
509-
assert(false, getInstanceName() + " got a for equation");
504+
Error.assertion(false, getInstanceName() + " got a for equation", sourceInfo());
510505
then
511506
fail();
512507

@@ -645,7 +640,7 @@ algorithm
645640
// For equations should have been unrolled here.
646641
case Equation.FOR()
647642
algorithm
648-
assert(false, getInstanceName() + " got a for equation");
643+
Error.assertion(false, getInstanceName() + " got a for equation", sourceInfo());
649644
then
650645
fail();
651646

@@ -941,7 +936,7 @@ algorithm
941936

942937
else
943938
algorithm
944-
assert(false, getInstanceName() + " got unknown function");
939+
Error.assertion(false, getInstanceName() + " got unknown function", sourceInfo());
945940
then
946941
fail();
947942

@@ -985,7 +980,7 @@ algorithm
985980

986981
else
987982
algorithm
988-
assert(false, getInstanceName() + " got untyped component.");
983+
Error.assertion(false, getInstanceName() + " got untyped component.", sourceInfo());
989984
then
990985
fail();
991986

Compiler/NFFrontEnd/NFDimension.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public
9191
case Type.ENUMERATION() then ENUM(ty);
9292
else
9393
algorithm
94-
assert(false, getInstanceName() + " got invalid typename");
94+
Error.assertion(false, getInstanceName() + " got invalid typename", sourceInfo());
9595
then
9696
fail();
9797
end match;

Compiler/NFFrontEnd/NFEvalFunction.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ encapsulated package NFEvalFunction
3939
TODO:
4040
* Implement evaluation of MetaModelica statements.
4141
* Enable NORETCALL (see comment in evaluateStatement).
42-
* Implement terminate and assert(false, ...).
42+
* Implement terminate and Error.assertion(false, ..., sourceInfo()).
4343
* Arrays of records probably doesn't work yet.
4444
"
4545

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public
433433

434434
else
435435
algorithm
436-
assert(false, getInstanceName() + " got unknown expression.");
436+
Error.assertion(false, getInstanceName() + " got unknown expression.", sourceInfo());
437437
then
438438
fail();
439439

@@ -573,7 +573,7 @@ public
573573

574574
else
575575
algorithm
576-
assert(false, getInstanceName() + " got unknown subscript " + anyString(sub));
576+
Error.assertion(false, getInstanceName() + " got unknown subscript " + anyString(sub), sourceInfo());
577577
then
578578
fail();
579579

@@ -627,14 +627,14 @@ public
627627
list<list<Expression>> partexps;
628628
Integer dimsize;
629629
algorithm
630-
assert(not listEmpty(inDims), "Empty dimension list given in arrayFromList.");
630+
Error.assertion(not listEmpty(inDims), "Empty dimension list given in arrayFromList.", sourceInfo());
631631

632632
ldim::restdims := inDims;
633633
dimsize := Dimension.size(ldim);
634634
ty := Type.liftArrayLeft(elemTy, ldim);
635635

636636
if List.hasOneElement(inDims) then
637-
assert(dimsize == listLength(inExps), "Length mismatch in arrayFromList.");
637+
Error.assertion(dimsize == listLength(inExps), "Length mismatch in arrayFromList.", sourceInfo());
638638
outExp := ARRAY(ty,inExps);
639639
return;
640640
end if;
@@ -880,7 +880,7 @@ public
880880

881881
else
882882
algorithm
883-
assert(false, getInstanceName() + " got unknown expression '" + toString(exp) + "'");
883+
Error.assertion(false, getInstanceName() + " got unknown expression '" + toString(exp) + "'", sourceInfo());
884884
then
885885
fail();
886886

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ algorithm
176176

177177
else
178178
algorithm
179-
assert(false, getInstanceName() + " got non-instantiated component " + ComponentRef.toString(prefix) + "\n");
179+
Error.assertion(false, getInstanceName() + " got non-instantiated component " + ComponentRef.toString(prefix) + "\n", sourceInfo());
180180
then
181181
();
182182

@@ -262,7 +262,7 @@ algorithm
262262

263263
else
264264
algorithm
265-
assert(false, getInstanceName() + " got unknown component");
265+
Error.assertion(false, getInstanceName() + " got unknown component", sourceInfo());
266266
then
267267
fail();
268268

@@ -321,7 +321,7 @@ algorithm
321321

322322
else
323323
algorithm
324-
assert(false, getInstanceName() + " got untyped binding.");
324+
Error.assertion(false, getInstanceName() + " got untyped binding.", sourceInfo());
325325
then
326326
fail();
327327

0 commit comments

Comments
 (0)