minor rewrite of enum value handling
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11690 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7df94f65e5
commit
4ebb9b0db2
3 changed files with 30 additions and 27 deletions
|
|
@ -3127,8 +3127,8 @@ c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI {
|
||||||
if (unnamedinstance) {
|
if (unnamedinstance) {
|
||||||
SwigType *cty = NewString("enum ");
|
SwigType *cty = NewString("enum ");
|
||||||
Setattr($$,"type",cty);
|
Setattr($$,"type",cty);
|
||||||
Setattr($$,"unnamedinstance","1");
|
SetFlag($$,"unnamedinstance");
|
||||||
Setattr(n,"unnamedinstance","1");
|
SetFlag(n,"unnamedinstance");
|
||||||
Delete(cty);
|
Delete(cty);
|
||||||
}
|
}
|
||||||
if ($8) {
|
if ($8) {
|
||||||
|
|
|
||||||
|
|
@ -1211,6 +1211,9 @@ public:
|
||||||
String *symname = Getattr(n, "sym:name");
|
String *symname = Getattr(n, "sym:name");
|
||||||
String *value = Getattr(n, "value");
|
String *value = Getattr(n, "value");
|
||||||
String *name = Getattr(n, "name");
|
String *name = Getattr(n, "name");
|
||||||
|
Node *parent = parentNode(n);
|
||||||
|
int unnamedinstance = GetFlag(parent, "unnamedinstance");
|
||||||
|
String *parent_name = Getattr(parent, "name");
|
||||||
String *tmpValue;
|
String *tmpValue;
|
||||||
|
|
||||||
// Strange hack from parent method
|
// Strange hack from parent method
|
||||||
|
|
@ -1222,9 +1225,9 @@ public:
|
||||||
Setattr(n, "value", tmpValue);
|
Setattr(n, "value", tmpValue);
|
||||||
|
|
||||||
{
|
{
|
||||||
EnumFeature enum_feature = decodeEnumFeature(parentNode(n));
|
EnumFeature enum_feature = decodeEnumFeature(parent);
|
||||||
|
|
||||||
if ((enum_feature == ProperEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
|
if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) {
|
||||||
// Wrap (non-anonymous) C/C++ enum with a proper C# enum
|
// Wrap (non-anonymous) C/C++ enum with a proper C# enum
|
||||||
// Emit the enum item.
|
// Emit the enum item.
|
||||||
if (!GetFlag(n, "firstenumitem"))
|
if (!GetFlag(n, "firstenumitem"))
|
||||||
|
|
@ -1241,21 +1244,16 @@ public:
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
|
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
|
||||||
const String *parent_name = Getattr(parentNode(n), "name");
|
String *type = Getattr(n, "type"); /* should be int unless explicitly specified in a C++0x enum class */
|
||||||
String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int");
|
SwigType *typemap_lookup_type = parent_name ? parent_name : type;
|
||||||
const String *tm = typemapLookup(n, "cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF);
|
const String *tm = typemapLookup(n, "cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF);
|
||||||
|
|
||||||
String *return_type = Copy(tm);
|
String *return_type = Copy(tm);
|
||||||
Delete(typemap_lookup_type);
|
|
||||||
typemap_lookup_type = NULL;
|
|
||||||
|
|
||||||
// The %csconst feature determines how the constant value is obtained
|
|
||||||
int const_feature_flag = GetFlag(n, "feature:cs:const");
|
|
||||||
|
|
||||||
const String *methodmods = Getattr(n, "feature:cs:methodmodifiers");
|
const String *methodmods = Getattr(n, "feature:cs:methodmodifiers");
|
||||||
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
|
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
|
||||||
|
|
||||||
if ((enum_feature == TypesafeEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
|
if ((enum_feature == TypesafeEnum) && parent_name && !unnamedinstance) {
|
||||||
// Wrap (non-anonymouse) enum using the typesafe enum pattern
|
// Wrap (non-anonymous) enum using the typesafe enum pattern
|
||||||
if (Getattr(n, "enumvalue")) {
|
if (Getattr(n, "enumvalue")) {
|
||||||
String *value = enumValue(n);
|
String *value = enumValue(n);
|
||||||
Printf(enum_code, " %s static readonly %s %s = new %s(\"%s\", %s);\n", methodmods, return_type, symname, return_type, symname, value);
|
Printf(enum_code, " %s static readonly %s %s = new %s(\"%s\", %s);\n", methodmods, return_type, symname, return_type, symname, value);
|
||||||
|
|
@ -1267,6 +1265,10 @@ public:
|
||||||
// Simple integer constants
|
// Simple integer constants
|
||||||
// Note these are always generated for anonymous enums, no matter what enum_feature is specified
|
// Note these are always generated for anonymous enums, no matter what enum_feature is specified
|
||||||
// Code generated is the same for SimpleEnum and TypeunsafeEnum -> the class it is generated into is determined later
|
// Code generated is the same for SimpleEnum and TypeunsafeEnum -> the class it is generated into is determined later
|
||||||
|
|
||||||
|
// The %csconst feature determines how the constant value is obtained
|
||||||
|
int const_feature_flag = GetFlag(n, "feature:cs:const");
|
||||||
|
|
||||||
const char *const_readonly = const_feature_flag ? "const" : "static readonly";
|
const char *const_readonly = const_feature_flag ? "const" : "static readonly";
|
||||||
String *value = enumValue(n);
|
String *value = enumValue(n);
|
||||||
Printf(enum_code, " %s %s %s %s = %s;\n", methodmods, const_readonly, return_type, symname, value);
|
Printf(enum_code, " %s %s %s %s = %s;\n", methodmods, const_readonly, return_type, symname, value);
|
||||||
|
|
@ -1275,9 +1277,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the enum value to the comma separated list being constructed in the enum declaration.
|
// Add the enum value to the comma separated list being constructed in the enum declaration.
|
||||||
String *enumvalues = Getattr(parentNode(n), "enumvalues");
|
String *enumvalues = Getattr(parent, "enumvalues");
|
||||||
if (!enumvalues)
|
if (!enumvalues)
|
||||||
Setattr(parentNode(n), "enumvalues", Copy(symname));
|
Setattr(parent, "enumvalues", Copy(symname));
|
||||||
else
|
else
|
||||||
Printv(enumvalues, ", ", symname, NIL);
|
Printv(enumvalues, ", ", symname, NIL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1267,6 +1267,9 @@ public:
|
||||||
String *symname = Getattr(n, "sym:name");
|
String *symname = Getattr(n, "sym:name");
|
||||||
String *value = Getattr(n, "value");
|
String *value = Getattr(n, "value");
|
||||||
String *name = Getattr(n, "name");
|
String *name = Getattr(n, "name");
|
||||||
|
Node *parent = parentNode(n);
|
||||||
|
int unnamedinstance = GetFlag(parent, "unnamedinstance");
|
||||||
|
String *parent_name = Getattr(parent, "name");
|
||||||
String *tmpValue;
|
String *tmpValue;
|
||||||
|
|
||||||
// Strange hack from parent method
|
// Strange hack from parent method
|
||||||
|
|
@ -1278,9 +1281,9 @@ public:
|
||||||
Setattr(n, "value", tmpValue);
|
Setattr(n, "value", tmpValue);
|
||||||
|
|
||||||
{
|
{
|
||||||
EnumFeature enum_feature = decodeEnumFeature(parentNode(n));
|
EnumFeature enum_feature = decodeEnumFeature(parent);
|
||||||
|
|
||||||
if ((enum_feature == ProperEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
|
if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) {
|
||||||
// Wrap (non-anonymous) C/C++ enum with a proper Java enum
|
// Wrap (non-anonymous) C/C++ enum with a proper Java enum
|
||||||
// Emit the enum item.
|
// Emit the enum item.
|
||||||
if (!GetFlag(n, "firstenumitem"))
|
if (!GetFlag(n, "firstenumitem"))
|
||||||
|
|
@ -1293,18 +1296,16 @@ public:
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
|
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
|
||||||
const String *parent_name = Getattr(parentNode(n), "name");
|
String *type = Getattr(n, "type"); /* should be int unless explicitly specified in a C++0x enum class */
|
||||||
String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int");
|
SwigType *typemap_lookup_type = parent_name ? parent_name : type;
|
||||||
const String *tm = typemapLookup(n, "jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF);
|
const String *tm = typemapLookup(n, "jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF);
|
||||||
String *return_type = Copy(tm);
|
|
||||||
Delete(typemap_lookup_type);
|
|
||||||
typemap_lookup_type = NULL;
|
|
||||||
|
|
||||||
|
String *return_type = Copy(tm);
|
||||||
const String *methodmods = Getattr(n, "feature:java:methodmodifiers");
|
const String *methodmods = Getattr(n, "feature:java:methodmodifiers");
|
||||||
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
|
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
|
||||||
|
|
||||||
if ((enum_feature == TypesafeEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
|
if ((enum_feature == TypesafeEnum) && parent_name && !unnamedinstance) {
|
||||||
// Wrap (non-anonymouse) enum using the typesafe enum pattern
|
// Wrap (non-anonymous) enum using the typesafe enum pattern
|
||||||
if (Getattr(n, "enumvalue")) {
|
if (Getattr(n, "enumvalue")) {
|
||||||
String *value = enumValue(n);
|
String *value = enumValue(n);
|
||||||
Printf(enum_code, " %s final static %s %s = new %s(\"%s\", %s);\n", methodmods, return_type, symname, return_type, symname, value);
|
Printf(enum_code, " %s final static %s %s = new %s(\"%s\", %s);\n", methodmods, return_type, symname, return_type, symname, value);
|
||||||
|
|
@ -1323,9 +1324,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the enum value to the comma separated list being constructed in the enum declaration.
|
// Add the enum value to the comma separated list being constructed in the enum declaration.
|
||||||
String *enumvalues = Getattr(parentNode(n), "enumvalues");
|
String *enumvalues = Getattr(parent, "enumvalues");
|
||||||
if (!enumvalues)
|
if (!enumvalues)
|
||||||
Setattr(parentNode(n), "enumvalues", Copy(symname));
|
Setattr(parent, "enumvalues", Copy(symname));
|
||||||
else
|
else
|
||||||
Printv(enumvalues, ", ", symname, NIL);
|
Printv(enumvalues, ", ", symname, NIL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue