Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs444
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Yang
cs444
Commits
7ea527ab
Commit
7ea527ab
authored
5 years ago
by
Nicholas Robinson
Browse files
Options
Downloads
Patches
Plain Diff
check protected
parent
bf32e63a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
NameNode.py
+32
-3
32 additions, 3 deletions
NameNode.py
with
32 additions
and
3 deletions
NameNode.py
+
32
−
3
View file @
7ea527ab
from
AST
import
ASTNode
,
getParseTreeNodes
from
TheTypeNode
import
TypeStruct
from
TheTypeNode
import
TypeStruct
,
getSupers
import
MemberNodes
import
TypeNodes
from
Environment
import
Env
...
...
@@ -127,7 +127,22 @@ class NameNode(ASTNode):
self
.
prefix
=
currPrefix
+
"
.
"
+
staticFieldName
self
.
IDs
=
self
.
IDs
[
index
+
2
:]
# if protected, check if we have access to it
if
"
protected
"
in
typeFieldNode
.
mods
:
# get typeFieldNode's class it was declared in
typeFieldNodeClass
=
typeFieldNode
.
env
.
getNode
(
typeFieldNode
.
typeName
,
"
type
"
).
canonName
# get current class we're in
curClass
=
self
.
env
.
getNode
(
self
.
typeName
,
"
type
"
)
# check to see if typeFieldNode's class is in the current class' super list
if
typeFieldNodeClass
!=
curClass
.
canonName
and
typeFieldNodeClass
not
in
getSupers
(
curClass
):
raise
Exception
(
"
ERROR: Class {} is attempting to access a protected field from class {}
"
.
format
(
curClass
.
canonName
,
typeFieldNodeClass
))
return
True
return
False
elif
self
.
methodInvoke
and
index
+
1
==
len
(
self
.
IDs
)
-
1
:
# TODO set the most recent? is this the correct implementation we want?
...
...
@@ -196,8 +211,22 @@ class NameNode(ASTNode):
curType
=
curType
.
env
.
getNode
(
self
.
IDs
[
0
],
'
fieldDcl
'
)
# at this stage, all newly resolved field should be non static:
if
curType
.
__class__
.
__name__
==
'
FieldNode
'
and
'
static
'
in
curType
.
mods
:
raise
Exception
(
"
ERROR: Non-static access of static field {}
"
.
format
(
curType
.
name
))
if
curType
.
__class__
.
__name__
==
'
FieldNode
'
:
if
'
static
'
in
curType
.
mods
:
raise
Exception
(
"
ERROR: Non-static access of static field {}
"
.
format
(
curType
.
name
))
# if protected, check if we have access to it
if
"
protected
"
in
curType
.
mods
:
# get curType's class it was declared in
typeFieldNodeClass
=
curType
.
env
.
getNode
(
curType
.
typeName
,
"
type
"
).
canonName
# get current class we're in
curClass
=
self
.
env
.
getNode
(
self
.
typeName
,
"
type
"
)
# check to see if curType's class is in the current class' super list
if
typeFieldNodeClass
!=
curClass
.
canonName
and
typeFieldNodeClass
not
in
getSupers
(
curClass
):
raise
Exception
(
"
ERROR: Class {} is attempting to access a protected field from class {}
"
.
format
(
curClass
.
canonName
,
typeFieldNodeClass
))
self
.
prefix
=
self
.
prefix
+
"
.
"
+
self
.
IDs
[
0
]
self
.
IDs
.
pop
(
0
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment