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
9ee21a5c
Commit
9ee21a5c
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
change class create to use type
parent
2aee38ff
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ExprPrimaryNodes.py
+8
-2
8 additions, 2 deletions
ExprPrimaryNodes.py
MemberNodes.py
+1
-3
1 addition, 3 deletions
MemberNodes.py
TheTypeNode.py
+4
-1
4 additions, 1 deletion
TheTypeNode.py
UnitNodes.py
+2
-1
2 additions, 1 deletion
UnitNodes.py
with
15 additions
and
7 deletions
ExprPrimaryNodes.py
+
8
−
2
View file @
9ee21a5c
...
...
@@ -177,10 +177,16 @@ class ClassCreateNode(ASTNode):
# always list all fields in the init method to show the class structure
def
__init__
(
self
,
parseTree
):
self
.
parseTree
=
parseTree
.
children
[
0
]
# input is classInstanceCreate unqualCreate
self
.
className
=
getParseTreeNodes
([
'
ID
'
,
'
COMPID
'
],
self
.
parseTree
.
children
[
1
])[
0
].
lex
self
.
className
=
TypeNode
(
parseTree
.
children
[
0
].
children
[
1
])
self
.
args
=
ArgsNode
(
self
.
parseTree
.
children
[
3
])
self
.
env
=
None
self
.
children
=
[
self
.
args
]
self
.
children
=
[
self
.
args
,
self
.
className
]
def
checkType
(
self
):
# check class is not abstract
if
'
abstract
'
in
self
.
className
.
myType
.
typePointer
.
mods
:
raise
Exception
(
'
ERROR: Cannot create an instance of abstract class {}.
'
.
format
(
self
.
className
.
myType
.
name
))
# TODO: more type checking
...
...
This diff is collapsed.
Click to expand it.
MemberNodes.py
+
1
−
3
View file @
9ee21a5c
...
...
@@ -27,9 +27,6 @@ class FieldNode(ASTNode):
for
m
in
node
.
children
:
self
.
mods
.
append
(
m
.
lex
)
elif
node
.
name
==
'
type
'
:
self
.
fieldType
=
TypeNode
(
node
)
elif
node
.
name
==
'
variableDcl
'
:
self
.
variableDcl
=
VarDclNode
(
node
)
...
...
@@ -81,6 +78,7 @@ class MethodNode(ASTNode):
self
.
body
=
BlockNode
(
n
)
if
self
.
body
:
self
.
children
.
append
(
self
.
body
)
self
.
children
.
append
(
self
.
methodType
)
def
__eq__
(
self
,
other
):
if
self
.
name
==
other
.
name
and
len
(
self
.
params
)
==
len
(
other
.
params
):
...
...
This diff is collapsed.
Click to expand it.
TheTypeNode.py
+
4
−
1
View file @
9ee21a5c
...
...
@@ -3,6 +3,9 @@ from AST import ASTNode, getParseTreeNodes
# TypeNode: an AST node represents a type
# TypeStruct: a struct holding type information for type checking
# TypeNode represents a parse tree unit that contains a type,
# TypeStruct is not a unit on parseTree, it is just a struct living in different AST nodes to keep track of their type
class
TypeNode
(
ASTNode
):
# always list all fields in the init method to show the class structure
def
__init__
(
self
,
parseTree
):
...
...
@@ -11,7 +14,7 @@ class TypeNode(ASTNode):
self
.
env
=
None
self
.
children
=
[]
self
.
myType
=
""
# empty string or typeStruct
if
parseTree
==
'
VOID
'
:
self
.
myType
=
TypeStruct
(
'
void
'
)
else
:
...
...
This diff is collapsed.
Click to expand it.
UnitNodes.py
+
2
−
1
View file @
9ee21a5c
from
AST
import
ASTNode
,
getParseTreeNodes
from
Environment
import
Env
from
TheTypeNode
import
TypeNode
from
TheTypeNode
import
TypeNode
,
TypeStruct
# LiteralNode
# ParamNode
...
...
@@ -22,6 +22,7 @@ class LiteralNode(ASTNode):
self
.
parseTree
=
parseTree
self
.
name
=
LiteralNode
.
toLiType
.
get
(
parseTree
.
children
[
0
].
name
)
# type of the literal
self
.
value
=
parseTree
.
children
[
0
].
lex
# the value
self
.
myType
=
TypeStruct
(
self
.
name
)
self
.
env
=
None
self
.
children
=
[]
...
...
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