%import fix for C# enums

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5884 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-04-22 20:56:48 +00:00
commit 9ae5f973d2

View file

@ -802,6 +802,7 @@ class CSHARP : public Language {
virtual int enumDeclaration(Node *n) { virtual int enumDeclaration(Node *n) {
if (!ImportMode) {
if (getCurrentClass() && (cplus_mode != CPLUS_PUBLIC)) return SWIG_NOWRAP; if (getCurrentClass() && (cplus_mode != CPLUS_PUBLIC)) return SWIG_NOWRAP;
enum_code = NewString(""); enum_code = NewString("");
@ -810,7 +811,7 @@ class CSHARP : public Language {
String *enumint_feature = Getattr(n,"feature:cs:enumint"); String *enumint_feature = Getattr(n,"feature:cs:enumint");
bool enumint_feature_flag = enumint_feature && Cmp(enumint_feature, "0") != 0; bool enumint_feature_flag = enumint_feature && Cmp(enumint_feature, "0") != 0;
String *typemap_lookup_type = Getattr(n,"name"); String *typemap_lookup_type = Getattr(n,"name");
if (!enumint_feature_flag && symname) { if (!enumint_feature_flag && symname && typemap_lookup_type) {
// Wrap (non-anonymous) C/C++ enum with a C# enum // Wrap (non-anonymous) C/C++ enum with a C# enum
// Pure C# baseclass and interfaces // Pure C# baseclass and interfaces
@ -833,15 +834,15 @@ class CSHARP : public Language {
" {\n", " {\n",
NIL); NIL);
} else { } else {
// Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums // Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums of any sort
if (symname) if (symname && !Getattr(n,"unnamedinstance"))
Printf(constants_code, " // %s \n", symname); Printf(constants_code, " // %s \n", symname);
} }
// Emit each enum item // Emit each enum item
Language::enumDeclaration(n); Language::enumDeclaration(n);
if (!enumint_feature_flag && symname) { if (!enumint_feature_flag && symname && typemap_lookup_type) {
// Wrap (non-anonymous) C/C++ enum with a C# enum - finish enum declaration. // Wrap (non-anonymous) C/C++ enum with a C# enum - finish enum declaration.
// Typemaps can be used to add extra code to the enum definition in the same manner as proxy classes. // Typemaps can be used to add extra code to the enum definition in the same manner as proxy classes.
Printv(enum_code, Printv(enum_code,
@ -890,6 +891,7 @@ class CSHARP : public Language {
} }
Delete(enum_code); enum_code = NULL; Delete(enum_code); enum_code = NULL;
}
return SWIG_OK; return SWIG_OK;
} }
@ -915,8 +917,7 @@ class CSHARP : public Language {
{ {
String *enumint_feature = Getattr(parentNode(n),"feature:cs:enumint"); String *enumint_feature = Getattr(parentNode(n),"feature:cs:enumint");
bool enumint_feature_flag = enumint_feature && Cmp(enumint_feature, "0") != 0; bool enumint_feature_flag = enumint_feature && Cmp(enumint_feature, "0") != 0;
if (!enumint_feature_flag && Getattr(parentNode(n),"sym:name") && !Getattr(parentNode(n),"unnamedinstance")) {
if (!enumint_feature_flag && Getattr(parentNode(n),"sym:name")) {
// Wrap C/C++ enums with C# enums. Emit the enum item. // Wrap C/C++ enums with C# enums. Emit the enum item.
if (!Getattr(n,"_last")) // Only the first enum item has this attribute set if (!Getattr(n,"_last")) // Only the first enum item has this attribute set
Printf(enum_code, ",\n"); Printf(enum_code, ",\n");
@ -1798,8 +1799,10 @@ class CSHARP : public Language {
String *getOverloadedName(Node *n) { String *getOverloadedName(Node *n) {
/* Although PInvoke functions are designed to handle overloaded functions, a C# IntPtr is used for all classes in the SWIG /* Although PInvoke functions are designed to handle overloaded functions,
* intermediary class. The intermediary class methods are thus mangled when overloaded to give a unique name. */ * a C# IntPtr is used for all classes in the SWIG intermediary class.
* The intermediary class methods are thus mangled when overloaded to give
* a unique name. */
String *overloaded_name = NewStringf("%s", Getattr(n,"sym:name")); String *overloaded_name = NewStringf("%s", Getattr(n,"sym:name"));
if (Getattr(n,"sym:overloaded")) { if (Getattr(n,"sym:overloaded")) {
@ -1998,7 +2001,6 @@ class CSHARP : public Language {
if (!enumint_feature_flag && symname) { if (!enumint_feature_flag && symname) {
// Add in class scope when referencing enum if not a global enum // Add in class scope when referencing enum if not a global enum
String *scopename_prefix = Swig_scopename_prefix(Getattr(n,"name")); String *scopename_prefix = Swig_scopename_prefix(Getattr(n,"name"));
// TODO: remove class scope if it is an enum in this class
String *proxyname = 0; String *proxyname = 0;
if (scopename_prefix) { if (scopename_prefix) {
proxyname = getProxyName(scopename_prefix); proxyname = getProxyName(scopename_prefix);