D: Emit empty enums as int aliases instead of omitting them.

This fixes test-suite/enum_forward.i.
This commit is contained in:
David Nadlinger 2014-10-30 08:30:29 +01:00
commit a8cdd1798e

View file

@ -803,24 +803,24 @@ public:
// Emit each enum item. // Emit each enum item.
Language::enumDeclaration(n); Language::enumDeclaration(n);
if (!GetFlag(n, "nonempty")) { if (GetFlag(n, "nonempty")) {
// Do not wrap empty enums; the resulting D code would be illegal. // Finish the enum.
Delete(proxy_enum_code); if (typemap_lookup_type) {
return SWIG_NOWRAP; Printv(proxy_enum_code,
} lookupCodeTypemap(n, "dcode", typemap_lookup_type, WARN_NONE), // Extra D code
"\n}\n", NIL);
// Finish the enum. } else {
if (typemap_lookup_type) { // Handle anonymous enums.
Printv(proxy_enum_code, Printv(proxy_enum_code, "\n}\n", NIL);
lookupCodeTypemap(n, "dcode", typemap_lookup_type, WARN_NONE), // Extra D code }
"\n}\n", NIL); Replaceall(proxy_enum_code, "$dclassname", symname);
} else { } else {
// Handle anonymous enums. // D enum declarations must have at least one member to be legal, so emit
Printv(proxy_enum_code, "\n}\n", NIL); // an alias to int instead (their ctype/imtype is always int).
Delete(proxy_enum_code);
proxy_enum_code = NewStringf("\nalias int %s;\n", symname);
} }
Replaceall(proxy_enum_code, "$dclassname", symname);
const String* imports = const String* imports =
lookupCodeTypemap(n, "dimports", typemap_lookup_type, WARN_NONE); lookupCodeTypemap(n, "dimports", typemap_lookup_type, WARN_NONE);
String* imports_trimmed; String* imports_trimmed;