Skip to content

Commit c71de65

Browse files
authored
Allow checkModel of external object structors (#11164)
Fixes #11008
1 parent 200011b commit c71de65

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

OMCompiler/Compiler/NFFrontEnd/NFInst.mo

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,38 @@ function lookupRootClass
325325
input InstNode topScope;
326326
input InstContext.Type context;
327327
output InstNode clsNode;
328+
protected
329+
InstContext.Type next_context;
330+
String last;
331+
ComplexType cty;
328332
algorithm
329-
clsNode := Lookup.lookupClassName(path, topScope, InstContext.set(context, NFInstContext.RELAXED),
330-
AbsynUtil.dummyInfo, checkAccessViolations = false);
333+
next_context := InstContext.set(context, NFInstContext.RELAXED);
334+
335+
ErrorExt.setCheckpoint(getInstanceName());
336+
try
337+
clsNode := Lookup.lookupClassName(path, topScope, next_context, AbsynUtil.dummyInfo, checkAccessViolations = false);
338+
ErrorExt.delCheckpoint(getInstanceName());
339+
else
340+
// Allow lookup of structor functions in ExternalObject:s (to allow e.g.
341+
// checkModel on them). These are stored in the ComplexType of the node
342+
// instead of in the class tree like normal elements.
343+
try
344+
last := AbsynUtil.pathLastIdent(path);
345+
true := last == "constructor" or last == "destructor";
346+
clsNode := Lookup.lookupName(AbsynUtil.stripLast(path), topScope, next_context, checkAccessViolations = false);
347+
Type.COMPLEX(complexTy = cty) := InstNode.getType(clsNode);
348+
349+
if last == "constructor" then
350+
ComplexType.EXTERNAL_OBJECT(constructor = clsNode) := cty;
351+
else
352+
ComplexType.EXTERNAL_OBJECT(destructor = clsNode) := cty;
353+
end if;
354+
ErrorExt.rollBack(getInstanceName());
355+
else
356+
ErrorExt.delCheckpoint(getInstanceName());
357+
end try;
358+
end try;
359+
331360
clsNode := InstUtil.mergeScalars(clsNode, path);
332361
checkInstanceRestriction(clsNode, path, context);
333362
clsNode := InstNode.setNodeType(InstNodeType.ROOT_CLASS(InstNode.EMPTY_NODE()), clsNode);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// name: CheckModelExtObj1
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
7+
loadString("
8+
class ExternalObject1
9+
extends ExternalObject;
10+
11+
function constructor
12+
output ExternalObject1 obj;
13+
external \"C\" obj = initObject();
14+
end constructor;
15+
16+
function destructor
17+
input ExternalObject1 obj;
18+
external \"C\" destroyObject(obj);
19+
end destructor;
20+
end ExternalObject1;
21+
");
22+
23+
checkModel(ExternalObject1.constructor);
24+
checkModel(ExternalObject1.destructor);
25+
checkModel(ExternalObject1);
26+
getErrorString();
27+
28+
// Result:
29+
// true
30+
// "Check of ExternalObject1.constructor completed successfully.
31+
// Class ExternalObject1.constructor has 0 equation(s) and 0 variable(s).
32+
// 0 of these are trivial equation(s)."
33+
// "Check of ExternalObject1.destructor completed successfully.
34+
// Class ExternalObject1.destructor has 0 equation(s) and 0 variable(s).
35+
// 0 of these are trivial equation(s)."
36+
// "Check of ExternalObject1 completed successfully.
37+
// Class ExternalObject1 has 0 equation(s) and 0 variable(s).
38+
// 0 of these are trivial equation(s)."
39+
// ""
40+
// endResult

testsuite/openmodelica/interactive-API/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Bug4209.mos \
1717
Bug4248.mos \
1818
Buildings.PartialFlowMachine.mos \
1919
checkAllModelsRecursive1.mos \
20+
CheckModelExtObj1.mos \
2021
choicesAllMatching.mos \
2122
ConnectionList.mos \
2223
ConversionVersions.mos \

0 commit comments

Comments
 (0)