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
80f03bdb
Commit
80f03bdb
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
type checking lineNodes, fix classCreate type check
parent
5cca2174
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ExprPrimaryNodes.py
+3
-1
3 additions, 1 deletion
ExprPrimaryNodes.py
LineNodes.py
+39
-1
39 additions, 1 deletion
LineNodes.py
with
42 additions
and
2 deletions
ExprPrimaryNodes.py
+
3
−
1
View file @
80f03bdb
...
@@ -230,7 +230,9 @@ class ClassCreateNode(ASTNode):
...
@@ -230,7 +230,9 @@ class ClassCreateNode(ASTNode):
self
.
cons
=
None
# the constructor used to create the class
self
.
cons
=
None
# the constructor used to create the class
def
checkType
(
self
):
def
checkType
(
self
):
return
# TO REMOVE after name node type checking is done
# return # TO REMOVE after name node type checking is done
self
.
args
.
checkType
()
classDef
=
self
.
className
.
myType
.
typePointer
classDef
=
self
.
className
.
myType
.
typePointer
# check class is not abstract
# check class is not abstract
if
'
abstract
'
in
classDef
.
mods
:
if
'
abstract
'
in
classDef
.
mods
:
...
...
This diff is collapsed.
Click to expand it.
LineNodes.py
+
39
−
1
View file @
80f03bdb
from
AST
import
ASTNode
,
getParseTreeNodes
from
AST
import
ASTNode
,
getParseTreeNodes
from
Environment
import
Env
from
Environment
import
Env
from
ExprPrimaryNodes
import
makeNodeFromExpr
,
makeNodeFromAllPrimary
,
MethodInvNode
from
ExprPrimaryNodes
import
makeNodeFromExpr
,
makeNodeFromAllPrimary
,
MethodInvNode
from
TheTypeNode
import
TypeNode
from
TheTypeNode
import
TypeNode
,
TypeStruct
# Contains:
# Contains:
# block
# block
...
@@ -121,6 +121,14 @@ class VarDclNode(ASTNode):
...
@@ -121,6 +121,14 @@ class VarDclNode(ASTNode):
env
.
addtoEnv
(
self
)
env
.
addtoEnv
(
self
)
return
self
.
env
return
self
.
env
def
checkType1
(
self
):
self
.
myType
=
self
.
dclType
.
myType
if
self
.
variableInit
:
self
.
variableInit
.
checkType
()
if
not
self
.
myType
.
assignable
(
self
.
variableInit
.
myType
):
raise
Exception
(
"
ERROR: Cannot initialize variable of type {} with type {}
"
.
format
(
self
.
myType
.
name
,
self
.
variableInit
.
myType
.
name
))
# ifStatement, ifElseStatement, ifElseStatementNoShortIf
# ifStatement, ifElseStatement, ifElseStatementNoShortIf
# Rules:
# Rules:
# 1. ifStatement IF LPAREN expr RPAREN statement
# 1. ifStatement IF LPAREN expr RPAREN statement
...
@@ -145,6 +153,15 @@ class IfNode(ASTNode):
...
@@ -145,6 +153,15 @@ class IfNode(ASTNode):
self
.
children
.
append
(
self
.
ifBody
)
self
.
children
.
append
(
self
.
ifBody
)
self
.
children
.
append
(
self
.
elseBody
)
self
.
children
.
append
(
self
.
elseBody
)
def
checkType1
(
self
):
self
.
ifConditional
.
checkType
()
if
self
.
ifConditional
.
myType
.
name
!=
'
boolean
'
:
raise
Exception
(
"
ERROR: Cannot use non-boolean type for ifConditional.
"
)
self
.
ifBody
.
checkType
()
if
self
.
elseBody
:
self
.
elseBody
.
checkType
()
# whileStatement, whileStatementNoShortIf
# whileStatement, whileStatementNoShortIf
# Rules:
# Rules:
# 1. whileStatement WHILE LPAREN expr RPAREN statement
# 1. whileStatement WHILE LPAREN expr RPAREN statement
...
@@ -164,6 +181,12 @@ class WhileNode(ASTNode):
...
@@ -164,6 +181,12 @@ class WhileNode(ASTNode):
self
.
children
.
append
(
self
.
whileBound
)
self
.
children
.
append
(
self
.
whileBound
)
self
.
children
.
append
(
self
.
whileBody
)
self
.
children
.
append
(
self
.
whileBody
)
def
checkType1
(
self
):
self
.
whileBound
.
checkType
()
if
self
.
whileBound
.
myType
.
name
!=
'
boolean
'
:
raise
Exception
(
"
ERROR: Cannot use non-boolean type for whileBound.
"
)
self
.
whileBody
.
checkType
()
# returnStatement
# returnStatement
# Rules:
# Rules:
# 1. returnStatement RETURN expr SEMICO
# 1. returnStatement RETURN expr SEMICO
...
@@ -181,6 +204,13 @@ class ReturnNode(ASTNode):
...
@@ -181,6 +204,13 @@ class ReturnNode(ASTNode):
self
.
children
.
append
(
self
.
expr
)
self
.
children
.
append
(
self
.
expr
)
def
checkType1
(
self
):
if
self
.
expr
:
self
.
expr
.
checkType
()
self
.
myType
=
self
.
expr
.
myType
else
:
self
.
myType
=
TypeStruct
(
"
void
"
,
None
)
# forStatement and forStatementNoShortIf
# forStatement and forStatementNoShortIf
# Rules:
# Rules:
# 1. forStatement FOR LPAREN forInit SEMICO forExpr SEMICO forInit RPAREN statement
# 1. forStatement FOR LPAREN forInit SEMICO forExpr SEMICO forInit RPAREN statement
...
@@ -235,3 +265,11 @@ class ForNode(ASTNode):
...
@@ -235,3 +265,11 @@ class ForNode(ASTNode):
self
.
children
.
append
(
self
.
forBound
)
self
.
children
.
append
(
self
.
forBound
)
self
.
children
.
append
(
self
.
forUpdate
)
self
.
children
.
append
(
self
.
forUpdate
)
self
.
children
.
append
(
self
.
bodyStatement
)
self
.
children
.
append
(
self
.
bodyStatement
)
def
checkType1
(
self
):
self
.
forInit
.
checkType
()
self
.
forBound
.
checkType
()
# need resolving var declared in forInit to use it in forBound
if
self
.
forBound
.
myType
.
name
!=
'
boolean
'
:
raise
Exception
(
"
ERROR: Cannot use non-boolean type for forBound.
"
)
self
.
forUpdate
.
checkType
()
self
.
bodyStatement
.
checkType
()
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