Do use sym:name for the enum names themselves

Ever since fb4d70027 (Represent enums as themselves in generated code,
2016-04-14) the code used "name" attribute for the enums themselves
instead of "sym:name". The reason for this was documented in the comment
added in f4ee8e536 (Fix names of enums and their elements, 2021-11-04),
but this explanation was only half-correct: although we indeed shouldn't
use sym:name for typedefs, we should use it for the enums themselves, as
otherwise renaming them didn't work and enums were generated in the
wrappers with the wrong names.

Fix this by using sym:name for non typedef'd enums.
This commit is contained in:
Vadim Zeitlin 2021-11-30 00:02:29 +01:00
commit 1c06a43e35

View file

@ -2465,12 +2465,15 @@ 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.
//
// Also note that we use "name" here and not "sym:name" because the latter is the name of typedef if there is one, while we want to use the name of enum
// itself here and, even more importantly, use the enum, and not the typedef, name as prefix for its elements.
if (String* const name = Getattr(n, "unnamed") ? NIL : Getattr(n, "name")) {
// But the name may included the containing class, so get rid of it.
enumname = Swig_scopename_last(name);
if (String* const name = Getattr(n, "unnamed") ? NULL : Getattr(n, "sym:name")) {
// 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) {
// But the name may include the containing class, so get rid of it.
enumname = Swig_scopename_last(Getattr(n, "name"));
} else {
enumname = Copy(name);
}
// C++ enum name shouldn't include the prefix, so make a copy before enumname is modified below.
if (cxx_enum_decl)