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
2b8b7207
Commit
2b8b7207
authored
4 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
array cast instance of
parent
031c4751
No related branches found
Branches containing commit
No related tags found
2 merge requests
!26
Array subtype
,
!20
Master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ExprPrimaryNodes.py
+5
-4
5 additions, 4 deletions
ExprPrimaryNodes.py
TypeNodes.py
+3
-11
3 additions, 11 deletions
TypeNodes.py
with
8 additions
and
15 deletions
ExprPrimaryNodes.py
+
5
−
4
View file @
2b8b7207
...
...
@@ -387,8 +387,9 @@ class CastNode(ASTNode):
self
.
code
+=
self
.
right
.
code
# subtype test:
if
not
self
.
left
.
myType
.
isPrimitive
:
# only test if right is not primitive (primitive types would be correctly static tested already)
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
...
...
@@ -578,8 +579,8 @@ class ExprNode(ASTNode):
self
.
left
.
codeGen
()
self
.
code
+=
self
.
left
.
code
# only test if non-primitive
if
not
self
.
right
.
myType
.
isPrimitive
:
# 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
:
offset
=
self
.
right
.
myType
.
typePointer
.
subTypeOffset
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax]
"
)
# access class tag of left object
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax + 4]
"
)
# access subtype testing column
...
...
This diff is collapsed.
Click to expand it.
TypeNodes.py
+
3
−
11
View file @
2b8b7207
...
...
@@ -19,8 +19,7 @@ class ClassInterNode(ASTNode):
self
.
SITsize
=
0
self
.
subTypeSize
=
0
self
.
subTypeOffset
=
0
self
.
arrayTypeOffset
=
0
# only array assignable classes will have this field set
# sets
self
.
inherits
=
[]
self
.
super
=
[]
...
...
@@ -308,13 +307,6 @@ class ClassNode(ClassInterNode):
# Calculating the size of objects of this class
self
.
size
+=
(
len
(
self
.
fieldOffset
))
*
4
assignable
=
dict
({
"
java.lang.Object
"
:
4
,
"
java.lang.Cloneable
"
:
8
,
"
java.io.Serializable
"
:
12
})
# fix offsets for array assignable classes, 0 row is reserve for all the non assignable ones
if
self
.
canonName
in
assignable
.
keys
():
self
.
arrayTypeOffset
=
assignable
[
self
.
canonName
]
# Populating method offset and creating class memory layout
def
populateMethodOffset
(
self
):
if
hasattr
(
self
,
"
data
"
):
...
...
@@ -392,7 +384,7 @@ class ClassNode(ClassInterNode):
self
.
data
+=
p
(
"
dd
"
,
"
42
"
)
# Layout subtype testing column
self
.
data
+=
pLabel
(
"
subT_
"
+
self
.
name
,
"
inter
"
)
self
.
data
+=
pLabel
(
"
subT_
"
+
self
.
name
,
"
array
"
)
for
i
in
range
(
self
.
subTypeSize
):
self
.
data
+=
pLabel
(
"
subT_
"
+
str
(
i
),
"
inter
"
)
self
.
data
+=
p
(
"
dd
"
,
"
0
"
)
# 0 for False, 1 for True
...
...
@@ -451,7 +443,7 @@ class ClassNode(ClassInterNode):
# fill in subtype testing column
self
.
code
+=
"
\n
; Filling in subtype testing
\n
"
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
I_subT_spot_
"
+
self
.
name
)
self
.
code
+=
p
(
"
mov
"
,
"
[eax]
"
,
"
dword
I
_subT_
"
+
self
.
name
)
self
.
code
+=
p
(
"
mov
"
,
"
[eax]
"
,
"
dword
A
_subT_
"
+
self
.
name
)
for
t
in
getSupers
(
self
):
# getSupers includes self
dlabel
=
"
I_subT_
"
+
str
(
t
.
subTypeOffset
//
4
)
...
...
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