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
f5e58d69
Commit
f5e58d69
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
staticThis
parent
bf32e63a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MemberNodes.py
+22
-0
22 additions, 0 deletions
MemberNodes.py
NameNode.py
+3
-0
3 additions, 0 deletions
NameNode.py
with
25 additions
and
0 deletions
MemberNodes.py
+
22
−
0
View file @
f5e58d69
...
@@ -139,6 +139,13 @@ class MethodNode(ASTNode):
...
@@ -139,6 +139,13 @@ class MethodNode(ASTNode):
if
not
self
.
body
:
if
not
self
.
body
:
return
return
# check no use of this in static method
if
'
static
'
in
self
.
mods
:
names
=
getNameNodes
(
self
.
body
)
for
n
in
names
:
if
n
.
pointToThis
and
n
.
prefixLink
.
__class__
.
__name__
in
[
'
MethodNode
'
,
'
FieldNode
'
]
and
'
static
'
not
in
n
.
prefixLink
.
mods
:
raise
Exception
(
"
ERROR: Cannot use non-static member {} in static method {} in class {}
"
.
format
(
n
.
name
,
self
.
name
,
self
.
typeName
))
# With method body
# With method body
returnNodes
=
getASTNode
([
"
ReturnNode
"
],
self
.
body
)
returnNodes
=
getASTNode
([
"
ReturnNode
"
],
self
.
body
)
...
@@ -177,3 +184,18 @@ def getForwardRefNames(node):
...
@@ -177,3 +184,18 @@ def getForwardRefNames(node):
result
.
extend
(
getForwardRefNames
(
c
))
result
.
extend
(
getForwardRefNames
(
c
))
return
result
return
result
# Input: AST Node
# Output: A list of names to be check
def
getNameNodes
(
node
):
if
not
node
:
return
[]
if
node
.
__class__
.
__name__
==
'
NameNode
'
:
return
[
node
]
result
=
[]
for
c
in
node
.
children
:
result
.
extend
(
getNameNodes
(
c
))
return
result
This diff is collapsed.
Click to expand it.
NameNode.py
+
3
−
0
View file @
f5e58d69
...
@@ -34,6 +34,7 @@ class NameNode(ASTNode):
...
@@ -34,6 +34,7 @@ class NameNode(ASTNode):
self
.
children
=
[]
self
.
children
=
[]
self
.
myType
=
None
# will become TypeStruct to tell us what the whole is/returns
self
.
myType
=
None
# will become TypeStruct to tell us what the whole is/returns
self
.
shouldBeStatic
=
False
self
.
shouldBeStatic
=
False
self
.
pointToThis
=
False
self
.
name
=
getParseTreeNodes
([
"
ID
"
,
"
COMPID
"
],
parseTree
)[
0
].
lex
self
.
name
=
getParseTreeNodes
([
"
ID
"
,
"
COMPID
"
],
parseTree
)[
0
].
lex
...
@@ -148,6 +149,7 @@ class NameNode(ASTNode):
...
@@ -148,6 +149,7 @@ class NameNode(ASTNode):
def
disambigName
(
self
):
def
disambigName
(
self
):
# Checking if a1 is "this"
# Checking if a1 is "this"
if
self
.
checkThis
():
if
self
.
checkThis
():
self
.
pointToThis
=
True
return
return
# Checking if a1 is a local variable
# Checking if a1 is a local variable
...
@@ -156,6 +158,7 @@ class NameNode(ASTNode):
...
@@ -156,6 +158,7 @@ class NameNode(ASTNode):
# Checking if a1 is in contains set
# Checking if a1 is in contains set
if
self
.
checkContains
():
if
self
.
checkContains
():
self
.
pointToThis
=
True
return
return
...
...
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