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 = 0
16431644 while j < names.length
16441645 if names[j] == iname
16451646 if j < types.length
1646- return types[j]
1647+ own_t = types[j]
1648+ else
1649+ own_t = "int"
16471650 end
1648- return "int"
1651+ break
16491652 end
16501653 j = j + 1
16511654 end
1655+ parent_t = ""
16521656 if @cls_parents[ci] != ""
16531657 pi = find_class_idx(@cls_parents[ci])
1654- if pi >= 0
1655- return cls_ivar_type(pi, iname)
1658+ if pi >= 0 && ivar_in_chain(pi, iname) == 1
1659+ parent_t = cls_ivar_type(pi, iname)
16561660 end
16571661 end
1662+ # The struct embeds parent ivars at the parent's recorded type
1663+ # (`emit_class_fields` skips own copies that are also in the
1664+ # parent chain). When the parent has the same ivar, the parent's
1665+ # type is what the C struct field actually has — so any access
1666+ # through `self->iv_X` must agree with that, regardless of what
1667+ # this child's own table happened to record. Defer to the parent
1668+ # type when both classes know the ivar.
1669+ if parent_t != ""
1670+ return parent_t
1671+ end
1672+ if own_t != ""
1673+ return own_t
1674+ end
16581675 "int"
16591676 end
16601677