Simplify code dealing with enum prefix
Use enum_prefix_, ending with "_" if it's not empty, as it can be used unconditionally instead of having to check whether it's null every time first. No real changes, this is just a simplification.
This commit is contained in:
parent
30bbb6ae1c
commit
e8cb7cc952
1 changed files with 7 additions and 16 deletions
|
|
@ -1022,8 +1022,8 @@ class C:public Language {
|
||||||
// Name of the output header, set in top().
|
// Name of the output header, set in top().
|
||||||
String *outfile_h;
|
String *outfile_h;
|
||||||
|
|
||||||
// Used only while generating wrappers for an enum and contains the prefix to use for enum elements if non-null.
|
// Used only while generating wrappers for an enum and contains the prefix, ending with underscore, to use for enum elements or is empty.
|
||||||
String *enum_prefix;
|
scoped_dohptr enum_prefix_;
|
||||||
|
|
||||||
// Used only while generating wrappers for an enum, as we don't know if enum will have any elements or not in advance and we must not generate an empty enum,
|
// Used only while generating wrappers for an enum, as we don't know if enum will have any elements or not in advance and we must not generate an empty enum,
|
||||||
// so we accumulate the full declaration here and then write it to sect_wrappers_types at once only if there are any elements.
|
// so we accumulate the full declaration here and then write it to sect_wrappers_types at once only if there are any elements.
|
||||||
|
|
@ -2416,6 +2416,7 @@ public:
|
||||||
}
|
}
|
||||||
Printv(enum_decl, "enum", NIL);
|
Printv(enum_decl, "enum", NIL);
|
||||||
|
|
||||||
|
String* enum_prefix;
|
||||||
if (Node* const klass = getCurrentClass()) {
|
if (Node* const klass = getCurrentClass()) {
|
||||||
enum_prefix = get_c_proxy_name(klass);
|
enum_prefix = get_c_proxy_name(klass);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2444,6 +2445,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum_prefix_ = enum_prefix ? NewStringf("%s_", enum_prefix) : NewStringEmpty();
|
||||||
|
|
||||||
Printv(enum_decl, " {\n", NIL);
|
Printv(enum_decl, " {\n", NIL);
|
||||||
|
|
||||||
int const len_orig = Len(enum_decl);
|
int const len_orig = Len(enum_decl);
|
||||||
|
|
@ -2456,18 +2459,13 @@ public:
|
||||||
Printv(enum_decl, "\n}", NIL);
|
Printv(enum_decl, "\n}", NIL);
|
||||||
|
|
||||||
if (tdname) {
|
if (tdname) {
|
||||||
if (enum_prefix) {
|
Printv(enum_decl, " ", enum_prefix_.get(), tdname, NIL);
|
||||||
Printv(enum_decl, " ", enum_prefix, "_", tdname, NIL);
|
|
||||||
} else {
|
|
||||||
Printv(enum_decl, " ", tdname, NIL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Printv(enum_decl, ";\n\n", NIL);
|
Printv(enum_decl, ";\n\n", NIL);
|
||||||
|
|
||||||
Append(sect_wrappers_types, enum_decl);
|
Append(sect_wrappers_types, enum_decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum_prefix = NULL;
|
|
||||||
Delete(enum_decl);
|
Delete(enum_decl);
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
|
|
@ -2485,15 +2483,8 @@ public:
|
||||||
if (!GetFlag(n, "firstenumitem"))
|
if (!GetFlag(n, "firstenumitem"))
|
||||||
Printv(enum_decl, ",\n", NIL);
|
Printv(enum_decl, ",\n", NIL);
|
||||||
|
|
||||||
maybe_owned_dohptr wname;
|
|
||||||
|
|
||||||
String* const symname = Getattr(n, "sym:name");
|
String* const symname = Getattr(n, "sym:name");
|
||||||
if (enum_prefix) {
|
Printv(enum_decl, cindent, enum_prefix_.get(), symname, NIL);
|
||||||
wname.assign_owned(NewStringf("%s_%s", enum_prefix, symname));
|
|
||||||
} else {
|
|
||||||
wname.assign_non_owned(symname);
|
|
||||||
}
|
|
||||||
Printv(enum_decl, cindent, wname.get(), NIL);
|
|
||||||
|
|
||||||
// We only use "enumvalue", which comes from the input, and not "enumvalueex" synthesized by SWIG itself because C should use the correct value for the enum
|
// We only use "enumvalue", which comes from the input, and not "enumvalueex" synthesized by SWIG itself because C should use the correct value for the enum
|
||||||
// items without an explicit one anyhow (and "enumvalueex" can't be always used as is in C code for enum elements inside a class or even a namespace).
|
// items without an explicit one anyhow (and "enumvalueex" can't be always used as is in C code for enum elements inside a class or even a namespace).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue