Don't call getEnumName() with NULL node

No real changes, just a tiny refactoring in preparation for the upcoming
changes.

This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
Vadim Zeitlin 2021-11-29 21:40:27 +01:00
commit 815c7c0361

View file

@ -1154,30 +1154,27 @@ public:
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
String *getEnumName(Node *n) { String *getEnumName(Node *n) {
String *enumname = NULL; String *enumname = Getattr(n, "enumname");
if (n) { if (!enumname) {
enumname = Getattr(n, "enumname"); String *symname = Getattr(n, "sym:name");
if (!enumname) { if (symname) {
String *symname = Getattr(n, "sym:name"); // Add in class scope when referencing enum if not a global enum
if (symname) { String *proxyname = 0;
// Add in class scope when referencing enum if not a global enum if (String *name = Getattr(n, "name")) {
String *proxyname = 0; if (String *scopename_prefix = Swig_scopename_prefix(name)) {
if (String *name = Getattr(n, "name")) { proxyname = getClassProxyName(scopename_prefix);
if (String *scopename_prefix = Swig_scopename_prefix(name)) { Delete(scopename_prefix);
proxyname = getClassProxyName(scopename_prefix);
Delete(scopename_prefix);
}
} }
if (proxyname) { }
enumname = NewStringf("%s_%s", proxyname, symname); if (proxyname) {
Delete(proxyname); enumname = NewStringf("%s_%s", proxyname, symname);
} else { Delete(proxyname);
// global enum or enum in a namespace } else {
enumname = Copy(get_c_proxy_name(n)); // global enum or enum in a namespace
} enumname = Copy(get_c_proxy_name(n));
Setattr(n, "enumname", enumname); }
Delete(enumname); Setattr(n, "enumname", enumname);
} Delete(enumname);
} }
} }
@ -1199,14 +1196,15 @@ public:
return; return;
} }
scoped_dohptr btype(SwigType_base(classnametype));
if (SwigType_isenum(classnametype)) { if (SwigType_isenum(classnametype)) {
String *enumname = getEnumName(enumLookup(classnametype)); Node* const enum_node = enumLookup(btype);
String* const enumname = enum_node ? getEnumName(enum_node) : NULL;
if (enumname) if (enumname)
Replaceall(tm, classnamespecialvariable, enumname); Replaceall(tm, classnamespecialvariable, enumname);
else else
Replaceall(tm, classnamespecialvariable, NewStringf("int")); Replaceall(tm, classnamespecialvariable, NewStringf("int"));
} else { } else {
scoped_dohptr btype(SwigType_base(classnametype));
String* typestr = NIL; String* typestr = NIL;
if (current_output == output_wrapper_def || Cmp(btype, "SwigObj") == 0) { if (current_output == output_wrapper_def || Cmp(btype, "SwigObj") == 0) {
// Special case, just leave it unchanged. // Special case, just leave it unchanged.