diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-13 00:20:35 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-13 00:20:35 +0100 |
| commit | 3b68db126a9ddbf61d4c8c8f28e69942ca2487db (patch) | |
| tree | 0cd3ef3a1324c85a3b5de8acb5e803b065299ec3 /tools | |
| parent | bfdaf99504c3a54557cc550ea06971fa7f573752 (diff) | |
gen_class: Fix class reference resolution
There is no dependency order in the constant table, a class reference
may reference a name with a higher index for example.
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/gen_class.py | 8 |
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. |
