Skip to content

Commit

Permalink
Stop at root classes in InstNode.scopePathClass (#9307)
Browse files Browse the repository at this point in the history
- Stop when reaching a root class in InstNode.scopePathClass to conform
  to the definition of fully qualified name used for getInstanceName in
  the specification.
  • Loading branch information
perost committed Aug 18, 2022
1 parent 7ff3a83 commit f1476ee
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 37 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFBuiltinCall.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ protected
InstNode scope;
algorithm
Call.UNTYPED_CALL(call_scope = scope) := call;
result := Expression.STRING(AbsynUtil.pathString(InstNode.scopePath(scope, includeRoot = true)));
result := Expression.STRING(AbsynUtil.pathString(InstNode.rootPath(scope)));
end typeGetInstanceName;

function typeClockCall
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFCeval.mo
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ algorithm
args := arg :: args;
end for;

exp := Expression.makeRecord(InstNode.scopePath(recordNode, includeRoot = true), recordType, args);
exp := Expression.makeRecord(InstNode.fullPath(recordNode), recordType, args);
end makeRecordBindingExp;

function evalTypename
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFClass.mo
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ constant Prefixes DEFAULT_PREFIXES = Prefixes.PREFIXES(
ty as Type.COMPLEX(complexTy = ComplexType.RECORD(ty_node)) := getType(cls, clsNode);
fields := ClassTree.getComponents(classTree(cls));
args := list(Binding.getExp(Component.getImplicitBinding(InstNode.component(f))) for f in fields);
exp := Expression.makeRecord(InstNode.scopePath(ty_node, includeRoot = true), ty, args);
exp := Expression.makeRecord(InstNode.fullPath(ty_node), ty, args);
end makeRecordExp;

function toFlatStream
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFEvalFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ algorithm
UnorderedMap.apply(local_map, function applyBindingReplacement(map = local_map));
bindings := UnorderedMap.valueList(local_map);
then
Expression.makeRecord(InstNode.scopePath(cls_node, includeRoot = true), cls.ty, bindings);
Expression.makeRecord(InstNode.fullPath(cls_node), cls.ty, bindings);

case Class.TYPED_DERIVED() then buildRecordBinding(cls.baseClass, map, mutableParams);
end match;
Expand Down Expand Up @@ -1441,7 +1441,7 @@ algorithm
expl := getExternalOutputResult(c, map) :: expl;
end for;

exp := Expression.makeRecord(InstNode.scopePath(cls_node, includeRoot = true),
exp := Expression.makeRecord(InstNode.fullPath(cls_node),
InstNode.getType(cls_node), listReverseInPlace(expl));
else
Error.assertion(false, getInstanceName() +
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ uniontype Function
case CachedData.FUNCTION() then ();
else
algorithm
node := instFunction2(InstNode.scopePath(node, includeRoot = true), node, context, info);
node := instFunction2(InstNode.fullPath(node), node, context, info);
then
();
end match;
Expand Down
6 changes: 2 additions & 4 deletions OMCompiler/Compiler/NFFrontEnd/NFInst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2182,11 +2182,9 @@ algorithm
InstNode.cacheInitFunc(node);

if SCodeUtil.isOperatorRecord(InstNode.definition(node)) then
OperatorOverloading.instConstructor(
InstNode.scopePath(node, includeRoot = true), node, context, InstNode.info(node));
OperatorOverloading.instConstructor(InstNode.fullPath(node), node, context, InstNode.info(node));
else
Record.instDefaultConstructor(
InstNode.scopePath(node, includeRoot = true), node, context, InstNode.info(node));
Record.instDefaultConstructor(InstNode.fullPath(node), node, context, InstNode.info(node));
end if;
then
();
Expand Down
62 changes: 40 additions & 22 deletions OMCompiler/Compiler/NFFrontEnd/NFInstNode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1078,9 +1078,27 @@ uniontype InstNode
end match;
end scopeListClass;

type ScopeType = enumeration(
RELATIVE "Stops at a root class and doesn't include the root",
INCLUDING_ROOT "Stops at a root class and includes the root",
FULL "Stops at the top scope"
);

function rootPath
input InstNode node;
input Boolean ignoreBaseClass = false "Ignore that a class is a base class if true.";
output Absyn.Path path = scopePath(node, ScopeType.INCLUDING_ROOT, ignoreBaseClass);
end rootPath;

function fullPath
input InstNode node;
input Boolean ignoreBaseClass = false "Ignore that a class is a base class if true.";
output Absyn.Path path = scopePath(node, ScopeType.FULL, ignoreBaseClass);
end fullPath;

function scopePath
input InstNode node;
input Boolean includeRoot = false "Whether to include the root class name or not.";
input ScopeType scopeType = ScopeType.RELATIVE;
input Boolean ignoreBaseClass = false "Ignore that a class is a base class if true.";
output Absyn.Path path;
algorithm
Expand All @@ -1091,12 +1109,12 @@ uniontype InstNode
case CLASS_NODE(nodeType = it)
then
match it
case InstNodeType.BASE_CLASS() guard not ignoreBaseClass then scopePath(it.parent, includeRoot);
else scopePath2(node.parentScope, includeRoot, Absyn.IDENT(node.name));
case InstNodeType.BASE_CLASS() guard not ignoreBaseClass then scopePath(it.parent, scopeType);
else scopePath2(node.parentScope, scopeType, Absyn.IDENT(node.name));
end match;

case COMPONENT_NODE() then scopePath2(node.parent, includeRoot, Absyn.IDENT(node.name));
case IMPLICIT_SCOPE() then scopePath(node.parentScope, includeRoot);
case COMPONENT_NODE() then scopePath2(node.parent, scopeType, Absyn.IDENT(node.name));
case IMPLICIT_SCOPE() then scopePath(node.parentScope, scopeType);

// For debugging.
else Absyn.IDENT(name(node));
Expand All @@ -1105,44 +1123,46 @@ uniontype InstNode

function scopePath2
input InstNode node;
input Boolean includeRoot;
input ScopeType scopeType;
input Absyn.Path accumPath;
output Absyn.Path path;
algorithm
path := match node
case CLASS_NODE() then scopePathClass(node, node.nodeType, includeRoot, accumPath);
case COMPONENT_NODE() then scopePath2(node.parent, includeRoot, Absyn.QUALIFIED(node.name, accumPath));
case CLASS_NODE() then scopePathClass(node, node.nodeType, scopeType, accumPath);
case COMPONENT_NODE() then scopePath2(node.parent, scopeType, Absyn.QUALIFIED(node.name, accumPath));
else accumPath;
end match;
end scopePath2;

function scopePathClass
input InstNode node;
input InstNodeType ty;
input Boolean includeRoot;
input ScopeType scopeType;
input Absyn.Path accumPath;
output Absyn.Path path;
algorithm
path := match ty
case InstNodeType.NORMAL_CLASS()
then scopePath2(classParent(node), includeRoot, Absyn.QUALIFIED(className(node), accumPath));
then scopePath2(classParent(node), scopeType, Absyn.QUALIFIED(className(node), accumPath));
case InstNodeType.BASE_CLASS()
then scopePath2(ty.parent, includeRoot, accumPath);
then scopePath2(ty.parent, scopeType, accumPath);
case InstNodeType.DERIVED_CLASS()
then scopePathClass(node, ty.ty, includeRoot, accumPath);
then scopePathClass(node, ty.ty, scopeType, accumPath);
case InstNodeType.BUILTIN_CLASS()
then Absyn.QUALIFIED(className(node), accumPath);
case InstNodeType.TOP_SCOPE()
then accumPath;
case InstNodeType.ROOT_CLASS()
then if includeRoot then
scopePath2(classParent(node), includeRoot, Absyn.QUALIFIED(className(node), accumPath))
else
accumPath;
then if scopeType == ScopeType.FULL then
scopePath2(classParent(node), scopeType, Absyn.QUALIFIED(className(node), accumPath))
elseif scopeType == ScopeType.INCLUDING_ROOT then
Absyn.QUALIFIED(className(node), accumPath)
else
accumPath;
case InstNodeType.REDECLARED_CLASS()
then scopePath2(ty.parent, includeRoot, Absyn.QUALIFIED(className(node), accumPath));
then scopePath2(ty.parent, scopeType, Absyn.QUALIFIED(className(node), accumPath));
case InstNodeType.IMPLICIT_SCOPE()
then scopePath2(classParent(node), includeRoot, accumPath);
then scopePath2(classParent(node), scopeType, accumPath);
else
algorithm
Error.assertion(false, getInstanceName() + " got unknown node type", sourceInfo());
Expand Down Expand Up @@ -1648,8 +1668,7 @@ uniontype InstNode

else
algorithm
state := Restriction.toDAE(Class.restriction(cls),
scopePath(clsNode, includeRoot = true));
state := Restriction.toDAE(Class.restriction(cls), fullPath(clsNode));
then
DAE.Type.T_COMPLEX(state, {}, NONE());

Expand Down Expand Up @@ -1691,8 +1710,7 @@ uniontype InstNode

else
algorithm
state := Restriction.toDAE(Class.restriction(cls),
scopePath(clsNode, includeRoot = true));
state := Restriction.toDAE(Class.restriction(cls), fullPath(clsNode));
vars := ConvertDAE.makeTypeVars(clsNode);
outType := DAE.Type.T_COMPLEX(state, vars, NONE());
Pointer.update(clsNode.cls, Class.DAE_TYPE(outType));
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFOperatorOverloading.mo
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public
// If it has an overloaded constructor, instantiate it and add the
// function(s) to the record node.
(_, ctor_node) := Function.instFunctionRef(ctor_ref, context, info);
ctor_path := InstNode.scopePath(ctor_node, includeRoot = true);
ctor_path := InstNode.fullPath(ctor_node);

for f in Function.getCachedFuncs(ctor_node) loop
checkOperatorConstructorOutput(f, Class.lastBaseClass(recordNode), ctor_path, info);
Expand Down Expand Up @@ -124,7 +124,7 @@ public
algorithm
if not SCodeUtil.isElementEncapsulated(InstNode.definition(operatorNode)) then
Error.addSourceMessage(Error.OPERATOR_NOT_ENCAPSULATED,
{AbsynUtil.pathString(InstNode.scopePath(operatorNode, includeRoot = true))},
{AbsynUtil.pathString(InstNode.fullPath(operatorNode))},
InstNode.info(operatorNode));
fail();
end if;
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/Script/NFApi.mo
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ algorithm
cls := Lookup.lookupClassName(pathToQualify, expanded_cls, NFInstContext.RELAXED, AbsynUtil.dummyInfo, checkAccessViolations = false);
end if;

qualPath := InstNode.scopePath(cls, true);
qualPath := InstNode.fullPath(cls);

if not Flags.isSet(Flags.NF_API_NOISE) then
ErrorExt.rollBack("NFApi.mkFullyQual");
Expand Down Expand Up @@ -820,8 +820,8 @@ algorithm
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)));
case Class.EXPANDED_DERIVED() then {InstNode.fullPath(cls.baseClass, true)};
else list(InstNode.fullPath(e, true) for e in ClassTree.getExtends(Class.classTree(cls)));
end match;
end getInheritedClasses;

Expand Down

0 comments on commit f1476ee

Please sign in to comment.