Skip to content

Commit

Permalink
Implement getInheritedClasses in NFApi. (#7905)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Sep 16, 2021
1 parent 1e6f45a commit 9e0e8de
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFInstNode.mo
Expand Up @@ -988,6 +988,7 @@ uniontype InstNode
function scopePath
input InstNode node;
input Boolean includeRoot = false "Whether to include the root class name or not.";
input Boolean ignoreBaseClass = false "Ignore that a class is a base class if true.";
output Absyn.Path path;
algorithm
path := match node
Expand All @@ -997,7 +998,7 @@ uniontype InstNode
case CLASS_NODE(nodeType = it)
then
match it
case InstNodeType.BASE_CLASS() then scopePath(it.parent, includeRoot);
case InstNodeType.BASE_CLASS() guard not ignoreBaseClass then scopePath(it.parent, includeRoot);
else scopePath2(node.parentScope, includeRoot, Absyn.IDENT(node.name));
end match;

Expand Down
4 changes: 4 additions & 0 deletions OMCompiler/Compiler/Script/Interactive.mo
Expand Up @@ -9287,6 +9287,10 @@ public function getInheritedClasses
input Absyn.Path inPath;
output list<Absyn.Path> outPaths;
algorithm
if Flags.isSet(Flags.NF_API) then
outPaths := NFApi.getInheritedClasses(inPath, SymbolTable.getAbsyn());
return;
end if;

try

Expand Down
24 changes: 24 additions & 0 deletions OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -805,5 +805,29 @@ algorithm

end frontEndLookup_dispatch;

public
function getInheritedClasses
input Absyn.Path classPath;
input Absyn.Program program;
output list<Absyn.Path> extendsPaths;
protected
InstNode cls_node;
Class cls;
algorithm
(_, _, cls_node) := frontEndLookup(program, classPath);

if not InstNode.isClass(cls_node) then
extendsPaths := {};
return;
end if;

cls := InstNode.getClass(cls_node);

extendsPaths := match cls
case Class.EXPANDED_DERIVED() then {InstNode.scopePath(cls.baseClass, true, true)};
else list(InstNode.scopePath(e, true, true) for e in ClassTree.getExtends(Class.classTree(cls)));
end match;
end getInheritedClasses;

annotation(__OpenModelica_Interface="backend");
end NFApi;
6 changes: 6 additions & 0 deletions OMCompiler/Compiler/Stubs/NFApi.mo
Expand Up @@ -60,5 +60,11 @@ function mkFullyQual
output Absyn.Path qualPath = pathToQualify;
end mkFullyQual;

function getInheritedClasses
input Absyn.Path classPath;
input Absyn.Program program;
output list<Absyn.Path> extendsPaths;
end getInheritedClasses;

annotation(__OpenModelica_Interface="backend");
end NFApi;

0 comments on commit 9e0e8de

Please sign in to comment.