summaryrefslogtreecommitdiff
path: root/tools/gen_class.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gen_class.py')
-rwxr-xr-xtools/gen_class.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/gen_class.py b/tools/gen_class.py
index ba0a92f..866576c 100755
--- a/tools/gen_class.py
+++ b/tools/gen_class.py
@@ -93,7 +93,7 @@ def parse_class(data):
cp_count, = struct.unpack_from(">H", data, o)
o += 2
utf8 = {} # cp idx -> utf8 string
- cls_names = {} # cp idx -> internal name (for Class constants)
+ cls_ref = {} # cp idx -> utf8 idx (Class constants)
i = 1
while i < cp_count:
tag = data[o]
@@ -111,7 +111,7 @@ def parse_class(data):
elif tag == 7: # Class
idx, = struct.unpack_from(">H", data, o)
o += 2
- cls_names[i] = utf8.get(idx, "")
+ cls_ref[i] = idx # resolve name after full pass
elif tag in (8, 16, 19, 20): # String/MethodType/Module/Package
o += 2
elif tag == 12: # NameAndType (2 indexes = 4 bytes)
@@ -127,6 +127,10 @@ def parse_class(data):
i += 1
access, this, sup = struct.unpack_from(">HHH", data, o)
o += 6
+ # A Class constant's name may sit at a HIGHER pool index than the
+ # constant itself (the pool is not dependency-ordered), so resolve the
+ # names only after the whole pool has been read.
+ cls_names = {ix: utf8.get(r, "") for ix, r in cls_ref.items()}
# Every class named anywhere in the file (this/super/interfaces and
# every method/field/annotation target) is a Class constant, so the
# set of tag-7 names is the complete reference set for the closure.