Fix enum names for renamed typedefs

Also use sym:name even for typedefs for enums themselves, as they can
%renamed as well.

Note that this means that "tdname" itself should probably be never used
at all at this level, but it's still used for structs in C mode, which
is almost certainly wrong.
This commit is contained in:
Vadim Zeitlin 2021-11-30 01:39:34 +01:00
commit 06c651431c

View file

@ -2440,9 +2440,11 @@ public:
}
}
String* const symname = Getattr(n, "sym:name");
// Preserve the typedef if we have it in the input.
String* const tdname = Getattr(n, "tdname");
if (tdname) {
bool const is_typedef = Checkattr(n, "allows_typedef", "1");
if (is_typedef) {
Printv(enum_decl, "typedef ", NIL);
if (cxx_enum_decl)
Printv(cxx_enum_decl, "typedef ", NIL);
@ -2465,10 +2467,10 @@ public:
scoped_dohptr cxx_enumname;
// Unnamed enums may just have no name at all or have a synthesized invalid name of the form "$unnamedN$ which is indicated by "unnamed" attribute.
if (String* const name = Getattr(n, "unnamed") ? NULL : Getattr(n, "sym:name")) {
if (String* const name = Getattr(n, "unnamed") ? NULL : symname) {
// If it's a typedef, its sym:name is the typedef name, but we don't want to use it here (we already use it for the typedef we generate), so use the
// actual C++ name instead.
if (tdname) {
if (is_typedef) {
// But the name may include the containing class, so get rid of it.
enumname = Swig_scopename_last(Getattr(n, "name"));
} else {
@ -2512,10 +2514,10 @@ public:
if (cxx_enum_decl)
Printv(cxx_enum_decl, "\n", cxx_enum_indent, "}", NIL);
if (tdname) {
Printv(enum_decl, " ", enum_prefix_.get(), tdname, NIL);
if (is_typedef) {
Printv(enum_decl, " ", enum_prefix_.get(), symname, NIL);
if (cxx_enum_decl)
Printv(cxx_enum_decl, " ", tdname, NIL);
Printv(cxx_enum_decl, " ", symname, NIL);
}
Printv(enum_decl, ";\n\n", NIL);
if (cxx_enum_decl)