Commit fc89c7ae

fc89c7aeb0e6Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

codegen: namespace-qualify class names in --emit-symbol-map

The symbol-map's ruby field built the class name from the leaf C name via class_ruby_name_into (_->::), which dropped the enclosing module (Tep::Url#save? came out Url#save?) and would mangle a colliding-class name. Use the enclosing-class chain (class_ruby_name) for the qualified path; for a name already qualified by the colliding-class pass (#1425), which encodes the full Mod__Leaf path, demangle __->:: directly (its enclosing_class still points at the module, so a chain walk would double-count). Operator / predicate / bang methods stay exact (the forward map, not a demangle).

Verified: Tep::Url#save? / #<=> / #[] / .find, deep A::B::C#m, and colliding Web::Response / Chat::Response (no Web::Web__Response).

Fixes #1334

Details

Commit
fc89c7aeb0e6
Parent
3c009ddea7bd

src/codegen.cmodifiedView file

@@ -1795,7 +1795,22 @@
17951795 buf_puts(&rb, s->name);
17961796 }
17971797 else {
1798- class_ruby_name_into(&rb, c->classes[s->class_id].name);
1798+ /* the namespace-qualified Ruby class path (Tep::Url). A class renamed by
1799+ the colliding-class pass (#1425) already encodes its full path as
1800+ `Mod__Leaf`, and its enclosing_class still points at the module, so a
1801+ chain walk would double-count -- demangle `__`->`::` instead. Otherwise
1802+ walk the enclosing-class chain (the leaf C name drops the module). */
1803+ const char *cn = c->classes[s->class_id].name;
1804+ if (cn && strstr(cn, "__")) {
1805+ for (const char *p = cn; *p; ) {
1806+ if (p[0] == '_' && p[1] == '_') { buf_puts(&rb, "::"); p += 2; }
1807+ else { buf_printf(&rb, "%c", (int)*p); p++; }
1808+ }
1809+ }
1810+ else {
1811+ const char *qn = class_ruby_name(c, s->class_id);
1812+ buf_puts(&rb, qn ? qn : (cn ? cn : ""));
1813+ }
17991814 buf_puts(&rb, s->is_cmethod ? "." : "#");
18001815 buf_puts(&rb, s->name);
18011816 kind = s->is_cmethod ? "cmeth" : "imeth";