Skip to content

Commit

Permalink
Add qualifyPath() API call (#10617)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Apr 26, 2023
1 parent f9dfd5f commit d238ab6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -4460,6 +4460,16 @@ annotation(preferredView="text",Documentation(info="<html>
</html>"));
end restoreAST;

function qualifyPath
input TypeName classPath;
input TypeName path;
output TypeName qualifiedPath;
external "builtin";
annotation(preferredView="text",Documentation(info="<html>
<p>Returns the fully qualified path for the given path in a class.</p>
</html>"));
end qualifyPath;

// OMSimulator API calls
type oms_system = enumeration(oms_system_none,oms_system_tlm, oms_system_wc,oms_system_sc);
type oms_causality = enumeration(oms_causality_input, oms_causality_output, oms_causality_parameter, oms_causality_bidir, oms_causality_undefined);
Expand Down
10 changes: 10 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo
Expand Up @@ -4713,6 +4713,16 @@ annotation(preferredView="text",Documentation(info="<html>
</html>"));
end restoreAST;

function qualifyPath
input TypeName classPath;
input TypeName path;
output TypeName qualifiedPath;
external "builtin";
annotation(preferredView="text",Documentation(info="<html>
<p>Returns the fully qualified path for the given path in a class.</p>
</html>"));
end qualifyPath;

// OMSimulator API calls
type oms_system = enumeration(oms_system_none,oms_system_tlm, oms_system_wc,oms_system_sc);
type oms_causality = enumeration(oms_causality_input, oms_causality_output, oms_causality_parameter, oms_causality_bidir, oms_causality_undefined);
Expand Down
3 changes: 3 additions & 0 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -3111,6 +3111,9 @@ algorithm
case ("restoreAST", {Values.INTEGER(integer = n)})
then Values.BOOL(SymbolTable.restoreAST(n));
case ("qualifyPath", {Values.CODE(Absyn.C_TYPENAME(classpath)), Values.CODE(Absyn.C_TYPENAME(path))})
then Values.STRING(AbsynUtil.pathString(NFApi.mkFullyQual(SymbolTable.getAbsyn(), classpath, path)));
end matchcontinue;
end cevalInteractiveFunctions4;
Expand Down
1 change: 1 addition & 0 deletions testsuite/openmodelica/instance-API/Makefile
Expand Up @@ -54,6 +54,7 @@ GetModelInstanceReplaceable3.mos \
GetModelInstanceReplaceable4.mos \
GetModelInstanceStateMachine1.mos \
ModifierToJSON1.mos \
QualifyPath1.mos \


# test that currently fail. Move up when fixed.
Expand Down
26 changes: 26 additions & 0 deletions testsuite/openmodelica/instance-API/QualifyPath1.mos
@@ -0,0 +1,26 @@
// name: QualifyPath1
// keywords:
// status: correct
// cflags: -d=newInst
//
//

loadString("
package P
model A
end A;

model B
A a;
end B;
end P;
");

qualifyPath(P.B, A);
getErrorString();

// Result:
// true
// "P.A"
// ""
// endResult

0 comments on commit d238ab6

Please sign in to comment.