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
9bc45ca0
Commit
9bc45ca0
authored
5 years ago
by
Nicholas Robinson
Browse files
Options
Downloads
Patches
Plain Diff
ClassNode Hierarchy Checks
parent
9d05dc14
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
AST.py
+3
-0
3 additions, 0 deletions
AST.py
AstBuilding.py
+6
-0
6 additions, 0 deletions
AstBuilding.py
TypeNodes.py
+36
-2
36 additions, 2 deletions
TypeNodes.py
with
45 additions
and
2 deletions
AST.py
+
3
−
0
View file @
9bc45ca0
...
...
@@ -34,6 +34,9 @@ class ASTNode():
def
linkType
(
self
):
pass
def
checkHierarchy
(
self
):
pass
def
printNodePretty
(
self
,
prefix
=
0
):
pp
=
pprint
.
PrettyPrinter
(
indent
=
prefix
)
pp
.
pprint
(
self
.
__class__
.
__name__
)
...
...
This diff is collapsed.
Click to expand it.
AstBuilding.py
+
6
−
0
View file @
9bc45ca0
...
...
@@ -30,6 +30,12 @@ def buildEnvAndLink(ASTs):
# t[1].buildEnvFromImports(globalEnv)
t
[
1
].
recurseAction
(
"
linkType
"
)
# hierarchy checking
print
(
'
--------->>> hierarchy checking time!
'
)
for
t
in
ASTs
:
# t[1].buildEnvFromImports(globalEnv)
t
[
1
].
recurseAction
(
"
checkHierarchy
"
)
#######################################################
# # ast: Node
...
...
This diff is collapsed.
Click to expand it.
TypeNodes.py
+
36
−
2
View file @
9bc45ca0
...
...
@@ -66,14 +66,40 @@ class ClassNode(ASTNode):
# to use: self.env.getNode(name, namespace)
# print('hello here we go we are in classNode {}'.format(self.name))
if
self
.
env
is
not
None
:
if
self
.
superClass
is
not
''
:
if
self
.
superClass
:
newSuperClass
=
self
.
env
.
getNode
(
self
.
superClass
,
'
type
'
)
self
.
superClass
=
newSuperClass
if
self
.
superInter
is
not
[]
:
if
self
.
superInter
:
for
(
index
,
inter
)
in
enumerate
(
self
.
superInter
):
newSuperInter
=
self
.
env
.
getNode
(
inter
,
'
type
'
)
self
.
superInter
[
index
]
=
newSuperInter
def
checkHierarchy
(
self
):
if
self
.
superClass
:
# A class must not extend an interface.
if
isinstance
(
self
.
superClass
,
InterNode
):
raise
Exception
(
"
ERROR: Class {} extends interface {}
"
.
format
(
self
.
name
,
self
.
superClass
.
name
))
# A class must not extend a final class.
if
'
final
'
in
self
.
superClass
.
mods
:
raise
Exception
(
"
ERROR: Class {} extends final class {}
"
.
format
(
self
.
name
,
self
.
superClass
.
name
))
# A class must not implement a class.
if
self
.
superInter
:
for
inter
in
self
.
superInter
:
if
isinstance
(
inter
,
ClassNode
):
raise
Exception
(
"
ERROR: Class {} implements class {}
"
.
format
(
self
.
name
,
inter
.
name
))
# A class or interface must not declare two methods with the same signature (name and parameter types).
uniqueMethods
=
[]
for
method
in
self
.
methods
:
key
=
(
method
.
name
,
method
.
paramTypes
)
if
key
in
uniqueMethods
:
raise
Exception
(
"
ERROR: Class {} declares 2 methods with the same signature {}
"
.
format
(
self
.
name
,
key
[
0
]))
uniqueMethods
.
append
(
key
)
# A class or interface must not contain (declare or inherit) two methods with the same signature but different return types
# A class must not declare two constructors with the same parameter types
# A class that contains (declares or inherits) any abstract methods must be abstract.
def
getConstructor
(
self
,
argTypes
):
for
c
in
self
.
constructors
:
if
c
.
paramTypes
==
argTypes
:
...
...
@@ -113,3 +139,11 @@ class InterNode(ASTNode):
env
.
addtoEnv
(
c
)
self
.
env
=
env
return
env
def
linkType
(
self
):
# link types to the actual nodes fom the environment (envs already created)
if
self
.
env
is
not
None
:
if
self
.
superInter
:
for
(
index
,
inter
)
in
enumerate
(
self
.
superInter
):
newSuperInter
=
self
.
env
.
getNode
(
inter
,
'
type
'
)
self
.
superInter
[
index
]
=
newSuperInter
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