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

Commit 16e0883

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Implement getInstanceName().
Belonging to [master]: - #2438 - OpenModelica/OpenModelica-testsuite#947
1 parent 803cabd commit 16e0883

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ uniontype Call
395395
case "diagonal" then typeDiagonalCall(call, origin, info);
396396
case "edge" then typeEdgeCall(call, origin, info);
397397
case "fill" then typeFillCall(call, origin, info);
398+
case "getInstanceName" then typeGetInstanceName(call);
398399
case "initial" then typeDiscreteCall(call, origin, info);
399400
case "isRoot" then typeIsRootCall(call, origin, info);
400401
case "matrix" then typeMatrixCall(call, origin, info);
@@ -2648,6 +2649,18 @@ protected
26482649
callExp := Expression.CALL(makeBuiltinCall2(fn, {arg}, ty, variability));
26492650
end typeNoEventCall;
26502651

2652+
function typeGetInstanceName
2653+
input Call call;
2654+
output Expression result;
2655+
output Type ty = Type.STRING();
2656+
output Variability var = Variability.CONSTANT;
2657+
protected
2658+
InstNode scope;
2659+
algorithm
2660+
Call.UNTYPED_CALL(call_scope = scope) := call;
2661+
result := Expression.STRING(Absyn.pathString(InstNode.scopePath(scope, includeRoot = true)));
2662+
end typeGetInstanceName;
2663+
26512664
function unboxArgs
26522665
input output Call call;
26532666
algorithm

Compiler/NFFrontEnd/NFFunction.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ uniontype Function
10371037
case "edge" then true;
10381038
// can have variable number of arguments
10391039
case "fill" then true;
1040+
case "getInstanceName" then true;
10401041
// Always discrete.
10411042
case "initial" then true;
10421043
case "isRoot" then true;

Compiler/NFFrontEnd/NFInstNode.mo

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ uniontype InstNode
789789

790790
function scopePath
791791
input InstNode node;
792+
input Boolean includeRoot = false "Whether to include the root class name or not.";
792793
output Absyn.Path path;
793794
algorithm
794795
path := match node
@@ -798,12 +799,12 @@ uniontype InstNode
798799
case CLASS_NODE(nodeType = it)
799800
then
800801
match it
801-
case InstNodeType.BASE_CLASS() then scopePath(it.parent);
802-
else scopePath2(node.parentScope, Absyn.IDENT(node.name));
802+
case InstNodeType.BASE_CLASS() then scopePath(it.parent, includeRoot);
803+
else scopePath2(node.parentScope, includeRoot, Absyn.IDENT(node.name));
803804
end match;
804805

805-
case COMPONENT_NODE() then scopePath2(node.parent, Absyn.IDENT(node.name));
806-
case IMPLICIT_SCOPE() then scopePath(node.parentScope);
806+
case COMPONENT_NODE() then scopePath2(node.parent, includeRoot, Absyn.IDENT(node.name));
807+
case IMPLICIT_SCOPE() then scopePath(node.parentScope, includeRoot);
807808

808809
// For debugging.
809810
else Absyn.IDENT(name(node));
@@ -812,6 +813,7 @@ uniontype InstNode
812813

813814
function scopePath2
814815
input InstNode node;
816+
input Boolean includeRoot;
815817
input Absyn.Path accumPath;
816818
output Absyn.Path path;
817819
algorithm
@@ -823,16 +825,18 @@ uniontype InstNode
823825
then
824826
match it
825827
case InstNodeType.NORMAL_CLASS()
826-
then scopePath2(node.parentScope, Absyn.QUALIFIED(node.name, accumPath));
828+
then scopePath2(node.parentScope, includeRoot, Absyn.QUALIFIED(node.name, accumPath));
827829
case InstNodeType.BASE_CLASS()
828-
then scopePath2(it.parent, accumPath);
830+
then scopePath2(it.parent, includeRoot, accumPath);
829831
case InstNodeType.BUILTIN_CLASS()
830832
then Absyn.QUALIFIED(node.name, accumPath);
833+
case InstNodeType.ROOT_CLASS()
834+
then if includeRoot then Absyn.QUALIFIED(node.name, accumPath) else accumPath;
831835
else accumPath;
832836
end match;
833837

834838
case COMPONENT_NODE()
835-
then scopePath2(node.parent, Absyn.QUALIFIED(node.name, accumPath));
839+
then scopePath2(node.parent, includeRoot, Absyn.QUALIFIED(node.name, accumPath));
836840

837841
else accumPath;
838842
end match;

0 commit comments

Comments
 (0)