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
c62c25f3
Commit
c62c25f3
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
some nodes
parent
1640c9da
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CompNode.py
+12
-13
12 additions, 13 deletions
CompNode.py
LineNodes.py
+22
-22
22 additions, 22 deletions
LineNodes.py
MemberNodes.py
+2
-1
2 additions, 1 deletion
MemberNodes.py
TypeNodes.py
+11
-2
11 additions, 2 deletions
TypeNodes.py
with
47 additions
and
38 deletions
CompNode.py
+
12
−
13
View file @
c62c25f3
...
...
@@ -35,18 +35,17 @@ class CompNode(ASTNode):
def
buildEnv
(
self
,
parentEnv
):
env
=
Env
(
None
)
# global environment is not the parent Env, each file don't have access to all the stuff in global env
env
.
addtoEnv
(
self
.
typeDcl
)
# add imports
for
i
in
self
.
importNames
:
pName
=
i
.
split
(
'
.*
'
)
# check if it's import all
if
len
(
pName
)
==
2
:
nodes
=
parentEnv
.
getNodesByPackage
(
pName
[
0
])
for
k
,
v
in
nodes
:
if
k
in
env
.
map
:
raise
Exception
(
'
ERROR: Declaration of {} is already in current Environment, cannot import it again
'
.
format
(
pName
+
'
.
'
+
typeDcl
.
name
))
env
.
map
[
k
]
=
v
else
:
node
=
parentEnv
.
getNode
(
pName
[
0
])
env
.
addtoEnv
(
node
)
# # add imports
# for i in self.importNames:
# pName = i.split('.*') # check if it's import all
# if len(pName) == 2:
# nodes = parentEnv.getNodesByPackage(pName[0])
# for k, v in nodes:
# if k in env.map:
# raise Exception('ERROR: Declaration of {} is already in current Environment, cannot import it again'.format(pName + '.' + typeDcl.name))
# env.map[k] = v
# else:
# node = parentEnv.getNode(pName[0])
# env.addtoEnv(node)
self
.
env
=
env
return
env
This diff is collapsed.
Click to expand it.
LineNodes.py
+
22
−
22
View file @
c62c25f3
from
AST
import
ASTNode
,
getParseTreeNodes
,
getTypeName
from
Environment
import
Env
from
WordNodes
import
ExprNode
# expr
class
ExprNode
(
ASTNode
):
# containing line level nodes: block, for/while/if, declaration
# block
class
BlockNode
(
ASTNode
):
# always list all fields in the init method to show the class structure
def
__init__
(
self
,
parseTree
):
self
.
parseTree
=
parseTree
self
.
statements
=
StatementsNode
(
parseTree
.
children
[
1
])
# block LBRACK statements RBRACK
self
.
env
=
None
self
.
children
=
self
.
statements
# a wrapper around statementsNode use to check double declaration within a block
class
VarDclNode
(
ASTNode
):
# always list all fields in the init method to show the class structure
def
__init__
(
self
,
parseTree
):
self
.
parseTree
=
parseTree
self
.
left
=
''
self
.
op
=
''
self
.
right
=
None
# another expr
self
.
dclType
=
''
self
.
name
=
''
self
.
assign
=
None
# AssignNode, can be None
self
.
statements
=
[]
# list of nodes representing statements in a block
self
.
env
=
None
self
.
children
=
[]
# input is : statement type variableDcl SEMICO
# def buildEnv(self, parentEnv):
# env = Env(parentEnv)
# # env.addtoEnv()
#
#
# self.env = env
# return env
# block
class
Block
Node
(
ASTNode
):
class
For
Node
(
ASTNode
):
# always list all fields in the init method to show the class structure
def
__init__
(
self
,
parseTree
):
self
.
parseTree
=
parseTree
self
.
statements
=
[]
# list of statements in a block
self
.
statements
=
[]
# list of
nodes representing
statements in a block
self
.
env
=
None
self
.
children
=
[]
# def buildEnv(self, parentEnv):
# env = Env(parentEnv)
# # env.addtoEnv()
#
# self.env = env
# return env
This diff is collapsed.
Click to expand it.
MemberNodes.py
+
2
−
1
View file @
c62c25f3
from
AST
import
ASTNode
,
getParseTreeNodes
,
getTypeName
from
LineNodes
import
ExprNode
,
BlockNode
from
LineNodes
import
BlockNode
from
WordNodes
import
ExprNode
from
Environment
import
Env
from
collections
import
OrderedDict
...
...
This diff is collapsed.
Click to expand it.
TypeNodes.py
+
11
−
2
View file @
c62c25f3
...
...
@@ -52,11 +52,20 @@ class ClassNode(ASTNode):
def
buildEnv
(
self
,
parentEnv
):
env
=
Env
(
parentEnv
)
for
c
in
self
.
children
:
env
.
addtoEnv
(
c
)
for
m
in
self
.
methods
:
env
.
addtoEnv
(
m
)
for
f
in
self
.
fields
:
env
.
addtoEnv
(
f
)
# not adding constructor to the environment, since it's in the type namespace
# when looking for a constructor, look for a class with the same name, and look in its constructors field
self
.
env
=
env
return
env
def
getConstructor
(
self
,
argTypes
):
for
c
in
self
.
constructors
:
if
c
.
paramTypes
==
argTypes
:
return
c
#####################################################################
# interface
class
InterNode
(
ASTNode
):
...
...
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