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
4a8fb3c0
"README.md" did not exist on "46cdd56fc94e8165c0cf8308e28a28d600029902"
Commit
4a8fb3c0
authored
4 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
fix array cast check
parent
a9969f2d
No related branches found
No related tags found
2 merge requests
!30
New new string
,
!20
Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ExprPrimaryNodes.py
+37
-19
37 additions, 19 deletions
ExprPrimaryNodes.py
with
37 additions
and
19 deletions
ExprPrimaryNodes.py
+
37
−
19
View file @
4a8fb3c0
...
@@ -414,17 +414,24 @@ class CastNode(ASTNode):
...
@@ -414,17 +414,24 @@ class CastNode(ASTNode):
self
.
code
+=
self
.
right
.
code
self
.
code
+=
self
.
right
.
code
# subtype test:
# subtype test:
if
(
not
self
.
left
.
myType
.
isPrimitive
)
and
self
.
right
.
myType
.
isArray
==
self
.
left
.
myType
.
isArray
:
# only test if not primitive, both are array or both non array
# cast would've exception if array is casting to non-array and not Object
offset
=
self
.
left
.
myType
.
typePointer
.
subTypeOffset
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[eax]
"
,
"
start subtype test
"
)
# access class tag of left object
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx + 4]
"
)
# access subtype testing column
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx +
"
+
str
(
offset
)
+
"
]
"
)
# ebx has isSubtype
# exception if not subtype, else do nothing (object is already in eax)
# only test if not primitive
self
.
code
+=
p
(
"
cmp
"
,
"
[G__Zero]
"
,
"
ebx
"
)
if
self
.
right
.
myType
.
isArray
==
self
.
left
.
myType
.
isArray
:
self
.
code
+=
p
(
"
je
"
,
"
H__Throw_Exception
"
)
if
(
not
self
.
left
.
myType
.
isPrimitive
):
# cast would've exception if array is casting to non-array and not Object
offset
=
self
.
left
.
myType
.
typePointer
.
subTypeOffset
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[eax]
"
,
"
start subtype test
"
)
# access class tag of left object
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx + 4]
"
)
# access subtype testing column
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx +
"
+
str
(
offset
)
+
"
]
"
)
# ebx has isSubtype
# exception if not subtype, else do nothing (object is already in eax)
self
.
code
+=
p
(
"
cmp
"
,
"
[G__Zero]
"
,
"
ebx
"
)
self
.
code
+=
p
(
"
je
"
,
"
H__Throw_Exception
"
)
else
:
# one is array, one is Object/Serializable/Cloneable
# make sure cast only one way
if
self
.
left
.
myType
.
isArray
:
self
.
code
+=
p
(
"
jmp
"
,
"
H__Throw_Exception
"
)
self
.
code
+=
"
; end of casting
\n
"
self
.
code
+=
"
; end of casting
\n
"
###################################################################################
###################################################################################
...
@@ -667,16 +674,27 @@ class ExprNode(ASTNode):
...
@@ -667,16 +674,27 @@ class ExprNode(ASTNode):
self
.
code
+=
self
.
left
.
code
self
.
code
+=
self
.
left
.
code
# only test if non-primitive, both arrays or both non arrays
# only test if non-primitive, both arrays or both non arrays
if
(
not
self
.
right
.
myType
.
isPrimitive
)
and
self
.
right
.
myType
.
isArray
==
self
.
left
.
myType
.
isArray
:
if
self
.
right
.
myType
.
isArray
==
self
.
left
.
myType
.
isArray
:
offset
=
self
.
right
.
myType
.
typePointer
.
subTypeOffset
if
not
self
.
right
.
myType
.
isPrimitive
:
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax]
"
)
# access class tag of left object
offset
=
self
.
right
.
myType
.
typePointer
.
subTypeOffset
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax + 4]
"
)
# access subtype testing column
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax]
"
)
# access class tag of left object
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax +
"
+
str
(
offset
)
+
"
]
"
)
# subType column stores 0 or 1 already
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax + 4]
"
)
# access subtype testing column
else
:
# primitive type can be staticly evaluated
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax +
"
+
str
(
offset
)
+
"
]
"
)
# subType column stores 0 or 1 already
if
self
.
right
.
myType
.
assignable
(
self
.
left
.
myType
):
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
1
"
)
else
:
# primitive type can be staticly evaluated
else
:
if
self
.
right
.
myType
.
assignable
(
self
.
left
.
myType
):
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
1
"
)
else
:
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
0
"
)
else
:
# non array is never an instance of array, array could be non array
if
self
.
right
.
myType
.
isArray
:
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
0
"
)
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
0
"
)
else
:
if
self
.
right
.
myType
.
assignable
(
self
.
left
.
myType
):
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
1
"
)
else
:
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
0
"
)
self
.
code
+=
(
"
; end of instanceof
\n
"
)
self
.
code
+=
(
"
; end of instanceof
\n
"
)
return
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