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
971b226e
Commit
971b226e
authored
4 years ago
by
pycsham
Browse files
Options
Downloads
Patches
Plain Diff
fixing the issue of ifConditional (could be methodInv, arrayAccess or fieldAccess)
parent
c625d5b8
No related branches found
Branches containing commit
No related tags found
2 merge requests
!26
Array subtype
,
!20
Master
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
AST.py
+2
-0
2 additions, 0 deletions
AST.py
CodeGenUtils.py
+1
-0
1 addition, 0 deletions
CodeGenUtils.py
ExprPrimaryNodes.py
+12
-0
12 additions, 0 deletions
ExprPrimaryNodes.py
with
15 additions
and
0 deletions
AST.py
+
2
−
0
View file @
971b226e
...
...
@@ -17,6 +17,8 @@ class ASTNode():
# reachability: None = not set, True = maybe, False = no
self
.
outMaybe
=
None
# either None or True/False
def
getConstant
(
self
):
return
None
# Do certains actions on every node of the AST tree
# call the same method in each class and its children recursively
...
...
This diff is collapsed.
Click to expand it.
CodeGenUtils.py
+
1
−
0
View file @
971b226e
...
...
@@ -96,6 +96,7 @@ def genMethodInvoke(method):
# generates shorter code for constant value conditionals and comparison conditionals
# cond is either literalNode or ExprNode or NameNode
# cond could also be methodInvNode, arrayAccessNode or fieldAccessNode
def
iffalse
(
cond
,
label
):
result
=
""
if
cond
.
__class__
.
__name__
==
"
NameNode
"
:
...
...
This diff is collapsed.
Click to expand it.
ExprPrimaryNodes.py
+
12
−
0
View file @
971b226e
...
...
@@ -163,6 +163,10 @@ class ArrayAccessNode(ASTNode):
if
not
self
.
index
.
myType
.
isNum
():
raise
Exception
(
"
ERROR: Array index must be a number.
"
)
self
.
myType
=
TypeStruct
(
self
.
array
.
myType
.
name
,
self
.
array
.
myType
.
typePointer
)
def
getIfFalse
(
self
,
label
):
self
.
codeGen
()
return
self
.
code
+
p
(
"
cmp
"
,
"
eax
"
,
"
[G__Zero]
"
)
+
p
(
"
je
"
,
label
)
def
addr
(
self
):
result
=
"
; Start of calculating address for array access
\n
"
+
\
...
...
@@ -872,6 +876,10 @@ class FieldAccessNode(ASTNode):
checkProtected
(
self
.
ID
.
prefixLink
,
self
)
except
:
# where there are no mods
return
def
getIfFalse
(
self
,
label
):
self
.
codeGen
()
return
self
.
code
+
p
(
"
cmp
"
,
"
eax
"
,
"
[G__Zero]
"
)
+
p
(
"
je
"
,
label
)
# generates code that evaluates the address of field access
# result stored in eax (address)
...
...
@@ -1005,6 +1013,10 @@ class MethodInvNode(ASTNode):
self
.
args
.
codeGen
()
self
.
code
+=
self
.
args
.
code
def
getIfFalse
(
self
,
label
):
self
.
codeGen
()
return
self
.
code
+
p
(
"
cmp
"
,
"
eax
"
,
"
[G__Zero]
"
)
+
p
(
"
je
"
,
label
)
def
codeGen
(
self
):
if
hasattr
(
self
,
"
code
"
):
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