Skip to content

Commit

Permalink
[NF] Use Error.assertion() instead of assert()
Browse files Browse the repository at this point in the history
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]:
  - OpenModelica/OMCompiler#2080
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Dec 15, 2017
1 parent 62af4e6 commit 64d4bf1
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 124 deletions.
20 changes: 10 additions & 10 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -142,7 +142,7 @@ uniontype Call
case Absyn.FOR_ITER_FARG() then instIteratorCall(functionName, functionArgs, scope, info);
else
algorithm
assert(false, getInstanceName() + " got unknown call type");
Error.assertion(false, getInstanceName() + " got unknown call type", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -194,7 +194,7 @@ uniontype Call

else
algorithm
assert(false, getInstanceName() + " got unknown function args");
Error.assertion(false, getInstanceName() + " got unknown function args", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -356,7 +356,7 @@ uniontype Call
case "zeros" then typeZerosOnesCall(call, origin, info);
else
algorithm
assert(false, getInstanceName() + " got unhandled builtin function");
Error.assertion(false, getInstanceName() + " got unhandled builtin function", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -412,7 +412,7 @@ uniontype Call
case UNTYPED_MAP_CALL(ref = ComponentRef.CREF(node = fn_node)) algorithm
// Fetch the cached function(s).
fnl := typeCachedFunctions(call.ref);
assert(listLength(fnl) == 1, getInstanceName() + " overloaded functions in mapping functions not handled yet.");
Error.assertion(listLength(fnl) == 1, getInstanceName() + " overloaded functions in mapping functions not handled yet.", sourceInfo());
fn := listHead(fnl);

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

else algorithm
assert(false, getInstanceName() + " got invalid function call expression");
Error.assertion(false, getInstanceName() + " got invalid function call expression", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -462,7 +462,7 @@ uniontype Call
typeArgs(call, origin, info);

else algorithm
assert(false, getInstanceName() + " got invalid function call expression");
Error.assertion(false, getInstanceName() + " got invalid function call expression", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -494,7 +494,7 @@ uniontype Call

else
algorithm
assert(false, getInstanceName() + " got invalid function call reference");
Error.assertion(false, getInstanceName() + " got invalid function call reference", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -537,7 +537,7 @@ uniontype Call
(TYPED_CALL(fn, ty, args, ca), ty, variability);

else algorithm
assert(false, getInstanceName() + " got invalid function call expression");
Error.assertion(false, getInstanceName() + " got invalid function call expression", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -758,7 +758,7 @@ protected

else
algorithm
assert(false, getInstanceName() + " got untyped call");
Error.assertion(false, getInstanceName() + " got untyped call", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -839,7 +839,7 @@ protected
case TYPED_MAP_CALL() then call.fn;
else
algorithm
assert(false, getInstanceName() + " got untyped function");
Error.assertion(false, getInstanceName() + " got untyped function", sourceInfo());
then
fail();
end match;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -126,7 +126,7 @@ algorithm

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

case Expression.CALL(call = call as Call.TYPED_CALL())
Expand Down Expand Up @@ -226,7 +226,7 @@ algorithm
originExp;
else
algorithm
assert(false, getInstanceName() + " failed on untyped binding");
Error.assertion(false, getInstanceName() + " failed on untyped binding", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -280,7 +280,7 @@ algorithm

else
algorithm
assert(false, getInstanceName() + " got invalid typename");
Error.assertion(false, getInstanceName() + " got invalid typename", sourceInfo());
then
fail();

Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -281,7 +281,7 @@ uniontype Class
();
else
algorithm
assert(false, getInstanceName() + " got non-modifiable class");
Error.assertion(false, getInstanceName() + " got non-modifiable class", sourceInfo());
then
fail();
end match;
Expand Down
14 changes: 7 additions & 7 deletions Compiler/NFFrontEnd/NFClassTree.mo
Expand Up @@ -400,7 +400,7 @@ public

else
algorithm
assert(false, getInstanceName() + " got invalid component");
Error.assertion(false, getInstanceName() + " got invalid component", sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -556,8 +556,8 @@ public
end for;

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

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

else
algorithm
assert(false, getInstanceName() + " got invalid class");
Error.assertion(false, getInstanceName() + " got invalid class", sourceInfo());
then
fail();

Expand Down Expand Up @@ -945,7 +945,7 @@ public
node := resolveEntry(entry.entry, tree);
end if;
else
assert(false, getInstanceName() + " failed on " + name);
Error.assertion(false, getInstanceName() + " failed on " + name, sourceInfo());
end try;
end getRedeclaredNode;

Expand Down Expand Up @@ -1137,13 +1137,13 @@ public
end for;

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

else
algorithm
assert(false, getInstanceName() + " got invalid entry");
Error.assertion(false, getInstanceName() + " got invalid entry", sourceInfo());
then
fail();

Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFComponentRef.mo
Expand Up @@ -345,7 +345,7 @@ public

else
algorithm
assert(false, getInstanceName() + " failed");
Error.assertion(false, getInstanceName() + " failed", sourceInfo());
then
fail();
end match;
Expand Down
31 changes: 13 additions & 18 deletions Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -255,8 +255,7 @@ algorithm
// unknown attributes here.
else
algorithm
assert(false, getInstanceName() + " got unknown type attribute " +
Modifier.name(m));
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -286,8 +285,7 @@ algorithm
// unknown attributes here.
else
algorithm
assert(false, getInstanceName() + " got unknown type attribute " +
Modifier.name(m));
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
then
fail();
end match;
Expand All @@ -314,8 +312,7 @@ algorithm
// unknown attributes here.
else
algorithm
assert(false, getInstanceName() + " got unknown type attribute " +
Modifier.name(m));
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
then
fail();
end match;
Expand All @@ -342,8 +339,7 @@ algorithm
// unknown attributes here.
else
algorithm
assert(false, getInstanceName() + " got unknown type attribute " +
Modifier.name(m));
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -372,8 +368,7 @@ algorithm
// unknown attributes here.
else
algorithm
assert(false, getInstanceName() + " got unknown type attribute " +
Modifier.name(m));
Error.assertion(false, getInstanceName() + " got unknown type attribute " + Modifier.name(m), sourceInfo());
then
fail();
end match;
Expand All @@ -396,7 +391,7 @@ algorithm

else
algorithm
assert(false, getInstanceName() + " got untyped binding");
Error.assertion(false, getInstanceName() + " got untyped binding", sourceInfo());
then
fail();

Expand Down Expand Up @@ -427,13 +422,13 @@ algorithm

case Modifier.MODIFIER(binding = Binding.TYPED_BINDING())
algorithm
assert(false, getInstanceName() + " got non StateSelect value");
Error.assertion(false, getInstanceName() + " got non StateSelect value", sourceInfo());
then
fail();

else
algorithm
assert(false, getInstanceName() + " got untyped binding");
Error.assertion(false, getInstanceName() + " got untyped binding", sourceInfo());
then
fail();

Expand All @@ -452,7 +447,7 @@ algorithm
case "always" then DAE.StateSelect.ALWAYS();
else
algorithm
assert(false, getInstanceName() + " got unknown StateSelect literal " + name);
Error.assertion(false, getInstanceName() + " got unknown StateSelect literal " + name, sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -506,7 +501,7 @@ algorithm
// For equations should have been unrolled here.
case Equation.FOR()
algorithm
assert(false, getInstanceName() + " got a for equation");
Error.assertion(false, getInstanceName() + " got a for equation", sourceInfo());
then
fail();

Expand Down Expand Up @@ -645,7 +640,7 @@ algorithm
// For equations should have been unrolled here.
case Equation.FOR()
algorithm
assert(false, getInstanceName() + " got a for equation");
Error.assertion(false, getInstanceName() + " got a for equation", sourceInfo());
then
fail();

Expand Down Expand Up @@ -941,7 +936,7 @@ algorithm

else
algorithm
assert(false, getInstanceName() + " got unknown function");
Error.assertion(false, getInstanceName() + " got unknown function", sourceInfo());
then
fail();

Expand Down Expand Up @@ -985,7 +980,7 @@ algorithm

else
algorithm
assert(false, getInstanceName() + " got untyped component.");
Error.assertion(false, getInstanceName() + " got untyped component.", sourceInfo());
then
fail();

Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFDimension.mo
Expand Up @@ -91,7 +91,7 @@ public
case Type.ENUMERATION() then ENUM(ty);
else
algorithm
assert(false, getInstanceName() + " got invalid typename");
Error.assertion(false, getInstanceName() + " got invalid typename", sourceInfo());
then
fail();
end match;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFEvalFunction.mo
Expand Up @@ -39,7 +39,7 @@ encapsulated package NFEvalFunction
TODO:
* Implement evaluation of MetaModelica statements.
* Enable NORETCALL (see comment in evaluateStatement).
* Implement terminate and assert(false, ...).
* Implement terminate and Error.assertion(false, ..., sourceInfo()).
* Arrays of records probably doesn't work yet.
"

Expand Down
10 changes: 5 additions & 5 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -433,7 +433,7 @@ public

else
algorithm
assert(false, getInstanceName() + " got unknown expression.");
Error.assertion(false, getInstanceName() + " got unknown expression.", sourceInfo());
then
fail();

Expand Down Expand Up @@ -573,7 +573,7 @@ public

else
algorithm
assert(false, getInstanceName() + " got unknown subscript " + anyString(sub));
Error.assertion(false, getInstanceName() + " got unknown subscript " + anyString(sub), sourceInfo());
then
fail();

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

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

if List.hasOneElement(inDims) then
assert(dimsize == listLength(inExps), "Length mismatch in arrayFromList.");
Error.assertion(dimsize == listLength(inExps), "Length mismatch in arrayFromList.", sourceInfo());
outExp := ARRAY(ty,inExps);
return;
end if;
Expand Down Expand Up @@ -880,7 +880,7 @@ public

else
algorithm
assert(false, getInstanceName() + " got unknown expression '" + toString(exp) + "'");
Error.assertion(false, getInstanceName() + " got unknown expression '" + toString(exp) + "'", sourceInfo());
then
fail();

Expand Down
6 changes: 3 additions & 3 deletions Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -176,7 +176,7 @@ algorithm

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

Expand Down Expand Up @@ -262,7 +262,7 @@ algorithm

else
algorithm
assert(false, getInstanceName() + " got unknown component");
Error.assertion(false, getInstanceName() + " got unknown component", sourceInfo());
then
fail();

Expand Down Expand Up @@ -321,7 +321,7 @@ algorithm

else
algorithm
assert(false, getInstanceName() + " got untyped binding.");
Error.assertion(false, getInstanceName() + " got untyped binding.", sourceInfo());
then
fail();

Expand Down

0 comments on commit 64d4bf1

Please sign in to comment.