Commit 9eb374b6
9eb374b60f6bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #254 from mame/pr/cls-ivar-type-parent-defer
fix(codegen): cls_ivar_type defers to parent's recorded type
Details
- Commit
- 9eb374b60f6b
- Parent
- 0a9dceefe1bc
- Merge parent
- 7f22768e2e4f
spinel_codegen.rbmodifiedView file
@@ -1639,22 +1639,39 @@
16391639
def cls_ivar_type(ci, iname)16401640
names = @cls_ivar_names[ci].split(";")16411641
types = @cls_ivar_types[ci].split(";")1642+
own_t = ""16421643
j = 016431644
while j < names.length16441645
if names[j] == iname16451646
if j < types.length1646-
return types[j]1647+
own_t = types[j]1648+
else1649+
own_t = "int"16471650
end1648-
return "int"1651+
break16491652
end16501653
j = j + 116511654
end1655+
parent_t = ""16521656
if @cls_parents[ci] != ""16531657
pi = find_class_idx(@cls_parents[ci])1654-
if pi >= 01655-
return cls_ivar_type(pi, iname)1658+
if pi >= 0 && ivar_in_chain(pi, iname) == 11659+
parent_t = cls_ivar_type(pi, iname)16561660
end16571661
end1662+
# The struct embeds parent ivars at the parent's recorded type1663+
# (`emit_class_fields` skips own copies that are also in the1664+
# parent chain). When the parent has the same ivar, the parent's1665+
# type is what the C struct field actually has — so any access1666+
# through `self->iv_X` must agree with that, regardless of what1667+
# this child's own table happened to record. Defer to the parent1668+
# type when both classes know the ivar.1669+
if parent_t != ""1670+
return parent_t1671+
end1672+
if own_t != ""1673+
return own_t1674+
end16581675
"int"16591676
end16601677
test/cls_ivar_type_parent_defer.rbaddedView file
Loading diff…