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

Commit

Permalink
[NF] Make protected class lookup possible.
Browse files Browse the repository at this point in the history
- Added a flag to Lookup.lookupClassName that allows lookup of a class
  without checking for access violations, so that e.g. protected
  classes can be instantiated by Inst.instClassInProgram.

Belonging to [master]:
  - #2613
  • Loading branch information
perost authored and OpenModelica-Hudson committed Aug 22, 2018
1 parent f558b3b commit 6a4d8d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -118,7 +118,7 @@ algorithm
name := Absyn.pathString(classPath);

// Look up the class to instantiate and mark it as the root class.
cls := Lookup.lookupClassName(classPath, top, Absyn.dummyInfo);
cls := Lookup.lookupClassName(classPath, top, Absyn.dummyInfo, checkAccessViolations = false);
cls := InstNode.setNodeType(InstNodeType.ROOT_CLASS(), cls);

// Initialize the storage for automatically generated inner elements.
Expand Down
16 changes: 10 additions & 6 deletions Compiler/NFFrontEnd/NFLookup.mo
Expand Up @@ -62,11 +62,12 @@ function lookupClassName
input Absyn.Path name;
input InstNode scope;
input SourceInfo info;
input Boolean checkAccessViolations = true;
output InstNode node;
protected
LookupState state;
algorithm
(node, state) := lookupNameWithError(name, scope, info, Error.LOOKUP_ERROR);
(node, state) := lookupNameWithError(name, scope, info, Error.LOOKUP_ERROR, checkAccessViolations);
LookupState.assertClass(state, node, name, info);
end lookupClassName;

Expand Down Expand Up @@ -453,11 +454,12 @@ function lookupNameWithError
input InstNode scope;
input SourceInfo info;
input Error.Message errorType;
input Boolean checkAccessViolations = true;
output InstNode node;
output LookupState state;
algorithm
try
(node, state) := lookupName(name, scope);
(node, state) := lookupName(name, scope, checkAccessViolations);
else
Error.addSourceMessage(errorType, {Absyn.pathString(name), InstNode.scopeName(scope)}, info);
fail();
Expand All @@ -467,6 +469,7 @@ end lookupNameWithError;
function lookupName
input Absyn.Path name;
input InstNode scope;
input Boolean checkAccessViolations;
output InstNode node;
output LookupState state;
algorithm
Expand All @@ -485,7 +488,7 @@ algorithm

// Fully qualified path, start from top scope.
case Absyn.Path.FULLYQUALIFIED()
then lookupName(name.path, InstNode.topScope(scope));
then lookupName(name.path, InstNode.topScope(scope), checkAccessViolations);

end match;
end lookupName;
Expand Down Expand Up @@ -546,6 +549,7 @@ function lookupLocalName
input Absyn.Path name;
input output InstNode node;
input output LookupState state;
input Boolean checkAccessViolations = true;
input Boolean selfReference = false;
algorithm
// Looking something up in a component is only legal when the name begins with
Expand All @@ -565,15 +569,15 @@ algorithm
case Absyn.Path.IDENT()
algorithm
node := lookupLocalSimpleName(name.name, node);
state := LookupState.next(node, state);
state := LookupState.next(node, state, checkAccessViolations);
then
();

case Absyn.Path.QUALIFIED()
algorithm
node := lookupLocalSimpleName(name.name, node);
state := LookupState.next(node, state);
(node, state) := lookupLocalName(name.path, node, state);
state := LookupState.next(node, state, checkAccessViolations);
(node, state) := lookupLocalName(name.path, node, state, checkAccessViolations);
then
();

Expand Down
12 changes: 8 additions & 4 deletions Compiler/NFFrontEnd/NFLookupState.mo
Expand Up @@ -335,15 +335,19 @@ uniontype LookupState
print a (hopefully relevant) error message and fail."
input InstNode node;
input LookupState currentState;
input Boolean checkAccessViolations = true;
output LookupState nextState;
protected
LookupState entry_ty;
SCode.Element el;
algorithm
// Check that the element is allowed to be accessed given its visibility.
checkProtection(node, currentState);
// Check that we're allowed to look in the current scope.
//checkPackageLikeAccess(inCurrentState, el, inEnv);
if checkAccessViolations then
// Check that the element is allowed to be accessed given its visibility.
checkProtection(node, currentState);
// Check that we're allowed to look in the current scope.
//checkPackageLikeAccess(inCurrentState, el, inEnv);
end if;

// Get the state for the found element, and check that the transition to the
// new state is valid.
entry_ty := nodeState(node);
Expand Down

0 comments on commit 6a4d8d1

Please sign in to comment.