Skip to content

Commit

Permalink
[NF] Use correct origin in Typing.typeCref.
Browse files Browse the repository at this point in the history
- Base the origin on where the component is declared when typing a cref
  node, rather than where it's used.

Belonging to [master]:
  - OpenModelica/OMCompiler#2697
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 5, 2018
1 parent d59074e commit dad3995
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -298,7 +298,7 @@ protected
Option<Expression> start_exp;
Integer pcount;
algorithm
exp_origin := if Class.isFunction(InstNode.getClass(InstNode.parent(node)))
exp_origin := if InstNode.isFunction(InstNode.explicitParent(node))
then ExpOrigin.FUNCTION else ExpOrigin.CLASS;

Typing.typeComponentBinding(node, exp_origin);
Expand Down
27 changes: 27 additions & 0 deletions Compiler/NFFrontEnd/NFInstNode.mo
Expand Up @@ -347,6 +347,16 @@ uniontype InstNode
end match;
end isUserdefinedClass;

function isFunction
input InstNode node;
output Boolean isFunc;
algorithm
isFunc := match node
case CLASS_NODE() then Class.isFunction(Pointer.access(node.cls));
else false;
end match;
end isFunction;

function isComponent
input InstNode node;
output Boolean isComponent;
Expand Down Expand Up @@ -503,6 +513,11 @@ uniontype InstNode
end match;
end parent;

function explicitParent
input InstNode node;
output InstNode parentNode = explicitScope(parent(node));
end explicitParent;

function classParent
input InstNode node;
output InstNode parent;
Expand Down Expand Up @@ -1121,6 +1136,18 @@ uniontype InstNode
end match;
end openImplicitScope;

function explicitScope
"Returns the first parent of the node that's not an implicit scope, or the
node itself if it's not an implicit scope."
input InstNode node;
output InstNode scope;
algorithm
scope := match node
case IMPLICIT_SCOPE() then explicitScope(node.parentScope);
else node;
end match;
end explicitScope;

function addIterator
input InstNode iterator;
input output InstNode scope;
Expand Down
9 changes: 8 additions & 1 deletion Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -1279,6 +1279,7 @@ algorithm
Type node_ty;
list<Subscript> subs;
Variability subs_var, rest_var;
ExpOrigin.Type node_origin;

case ComponentRef.CREF(origin = Origin.SCOPE)
algorithm
Expand All @@ -1288,7 +1289,13 @@ algorithm

case ComponentRef.CREF(node = InstNode.COMPONENT_NODE())
algorithm
node_ty := typeComponent(cref.node, origin);
// The origin used when typing a component node depends on where the
// component was declared, not where it's used. This can be different to
// the given origin, e.g. for package constants used in a function.
node_origin := if InstNode.isFunction(InstNode.explicitParent(cref.node)) then
ExpOrigin.FUNCTION else ExpOrigin.CLASS;
node_ty := typeComponent(cref.node, node_origin);

(subs, subs_var) := typeSubscripts(cref.subscripts, node_ty, cref, origin, info);
(rest_cr, rest_var) := typeCref2(cref.restCref, origin, info);
subsVariability := Prefixes.variabilityMax(subs_var, rest_var);
Expand Down

0 comments on commit dad3995

Please sign in to comment.