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,9 +1154,7 @@ public:
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
String *getEnumName(Node *n) { String *getEnumName(Node *n) {
String *enumname = NULL; String *enumname = Getattr(n, "enumname");
if (n) {
enumname = Getattr(n, "enumname");
if (!enumname) { if (!enumname) {
String *symname = Getattr(n, "sym:name"); String *symname = Getattr(n, "sym:name");
if (symname) { if (symname) {
@ -1179,7 +1177,6 @@ public:
Delete(enumname); Delete(enumname);
} }
} }
}
return enumname; return 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.