diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2011-08-25 19:27:38 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2011-08-25 19:27:38 +0000 |
commit | 30206f975c3c3fbd6e702499727375b4321b490e (patch) | |
tree | 7d963727883b9b71cf1e03fa6021a42571afbcce | |
parent | c794d08597e6f0c0b54cd70438f3374ccff43201 (diff) | |
download | swig-30206f975c3c3fbd6e702499727375b4321b490e.tar.gz |
Fix constructors in named typedef class declarations
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12784 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | CHANGES.current | 12 | ||||
-rw-r--r-- | Examples/test-suite/cpp_typedef.i | 4 | ||||
-rw-r--r-- | Examples/test-suite/errors/cpp_no_return_type.i | 12 | ||||
-rw-r--r-- | Examples/test-suite/errors/expected.log | 4 | ||||
-rwxr-xr-x | Examples/test-suite/errors/make.sh | 1 | ||||
-rw-r--r-- | Examples/test-suite/typedef_class.i | 16 | ||||
-rw-r--r-- | Examples/test-suite/typedef_struct.i | 11 | ||||
-rw-r--r-- | Lib/carrays.i | 3 | ||||
-rw-r--r-- | Lib/d/carrays.i | 2 | ||||
-rw-r--r-- | Lib/python/carrays.i | 2 | ||||
-rw-r--r-- | Lib/typemaps/carrays.swg | 2 | ||||
-rw-r--r-- | Source/Modules/allegrocl.cxx | 7 | ||||
-rw-r--r-- | Source/Modules/lang.cxx | 22 | ||||
-rw-r--r-- | Source/Modules/modula3.cxx | 26 |
14 files changed, 86 insertions, 38 deletions
diff --git a/CHANGES.current b/CHANGES.current index b59952e27..68bf51a06 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,18 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.5 (in progress) =========================== +2011-08-25: wsfulton + Fix constructors in named typedef class declarations as reported by Gregory Bronner: + + typedef struct A { + A(){} // Constructor which was not accepted by SWIG + B(){} // NOT a constructor --illegal, but was accepted by SWIG + } B; + + For C code, the fix now results in use the use of 'struct A *' instead of just 'B *' in + the generated code when wrapping members in A, but ultimately this does not matter, as + they are the same thing. + 2011-08-23: wsfulton Fix %newobject when used in conjunction with %feature("ref") as reported by Jan Becker. The code from the "ref" feature was not always being generated for the function specified by %newobject. diff --git a/Examples/test-suite/cpp_typedef.i b/Examples/test-suite/cpp_typedef.i index f869f4d9c..b782a3bd3 100644 --- a/Examples/test-suite/cpp_typedef.i +++ b/Examples/test-suite/cpp_typedef.i @@ -26,9 +26,13 @@ public: // Test that the correct types are used for typedef struct declarations typedef struct { + int something; + void m() {} } UnnamedStruct; typedef struct NamedStruct { + int something; + void m() {} } TypedefNamedStruct; typedef TypedefNamedStruct DoubleTypedef; diff --git a/Examples/test-suite/errors/cpp_no_return_type.i b/Examples/test-suite/errors/cpp_no_return_type.i new file mode 100644 index 000000000..3327e1d0a --- /dev/null +++ b/Examples/test-suite/errors/cpp_no_return_type.i @@ -0,0 +1,12 @@ +%module xxx + +struct R {}; + +struct S { + R() {} +}; + +typedef struct U { + UU() {} +} UU; + diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 8ac1534cb..9e4052bea 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -281,6 +281,10 @@ cpp_nested.i:12: Warning 325: Nested class not currently supported (Grok ignored :::::::::::::::::::::::::::::::: cpp_no_access.i ::::::::::::::::::::::::::::::::::: cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored). +:::::::::::::::::::::::::::::::: cpp_no_return_type.i ::::::::::::::::::::::::::::::::::: +cpp_no_return_type.i:6: Warning 504: Function R must have a return type. Ignored. +cpp_no_return_type.i:10: Warning 504: Function UU must have a return type. Ignored. + :::::::::::::::::::::::::::::::: cpp_nobase.i ::::::::::::::::::::::::::::::::::: cpp_nobase.i:3: Warning 401: Nothing known about base class 'Bar'. Ignored. cpp_nobase.i:6: Warning 401: Nothing known about base class 'Bar< int >'. Ignored. diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index f45f435aa..009b581c1 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -74,6 +74,7 @@ cpp_namespace_aliasnot cpp_namespace_aliasundef cpp_nested cpp_no_access +cpp_no_return_type cpp_nobase cpp_overload cpp_overload_const diff --git a/Examples/test-suite/typedef_class.i b/Examples/test-suite/typedef_class.i index 5a75305c9..dad7f7099 100644 --- a/Examples/test-suite/typedef_class.i +++ b/Examples/test-suite/typedef_class.i @@ -13,4 +13,20 @@ class B typedef RealA A2; int testA (const A2& a) {return a.a;} }; + +namespace Space { + typedef class AAA { + public: + AAA() {} + } BBB; +} + +typedef class AA { +public: + AA() {} + AA(int x) {} + int aa_var; + int *aa_method(double d) { return 0; } + static int *aa_static_method(bool b) { return 0; } +} BB; %} diff --git a/Examples/test-suite/typedef_struct.i b/Examples/test-suite/typedef_struct.i index 800d93b27..4380156d1 100644 --- a/Examples/test-suite/typedef_struct.i +++ b/Examples/test-suite/typedef_struct.i @@ -41,3 +41,14 @@ B_t make_b() { return make_a(); } %} + + +%inline %{ + +typedef struct _Foo { + enum { NONAME1, NONAME2 } enumvar; + int foovar; + void (*fptr)(int); +} Foo; + +%} diff --git a/Lib/carrays.i b/Lib/carrays.i index 5fc78877c..f125105aa 100644 --- a/Lib/carrays.i +++ b/Lib/carrays.i @@ -73,9 +73,8 @@ void NAME##_setitem(TYPE *ary, int index, TYPE value); %{ typedef TYPE NAME; %} -typedef struct NAME { +typedef struct { /* Put language specific enhancements here */ - } NAME; %extend NAME { diff --git a/Lib/d/carrays.i b/Lib/d/carrays.i index 9893d09e5..37b59c871 100644 --- a/Lib/d/carrays.i +++ b/Lib/d/carrays.i @@ -73,7 +73,7 @@ void NAME##_setitem(TYPE *ary, int index, TYPE value); typedef TYPE NAME; %} -typedef struct NAME {} NAME; +typedef struct {} NAME; %extend NAME { #ifdef __cplusplus diff --git a/Lib/python/carrays.i b/Lib/python/carrays.i index 8a881fd0b..e578c80dc 100644 --- a/Lib/python/carrays.i +++ b/Lib/python/carrays.i @@ -4,7 +4,7 @@ %feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__; %inline %{ -typedef struct NAME { +typedef struct { TYPE *el; } NAME; %} diff --git a/Lib/typemaps/carrays.swg b/Lib/typemaps/carrays.swg index cdeab36b7..462d60bc2 100644 --- a/Lib/typemaps/carrays.swg +++ b/Lib/typemaps/carrays.swg @@ -72,7 +72,7 @@ typedef TYPE NAME; %} -typedef struct NAME { +typedef struct { } NAME; %extend NAME { diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 70096a226..b75762feb 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -343,7 +343,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, String *val; String *ns_list = listify_namespace(ns); String *templated = n ? Getattr(n, "template") : 0; - String *cDeclName = n ? Getattr(n, "classDeclaration:name") : 0; + String *cDeclName = n ? Getattr(n, "name") : 0; #ifdef ALLEGROCL_CLASS_DEBUG Printf(stderr, "IN A-D-F-T. (n=%x, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns); @@ -3084,11 +3084,6 @@ int ALLEGROCL::cClassHandler(Node *n) { #ifdef ALLEGROCL_TYPE_DEBUG Printf(stderr, "In cClassHandler\n"); #endif - // String *cDeclName = Getattr(n,"classDeclaration:name"); - // String *name= Getattr(n, "sym:name"); - // String *kind = Getattr(n,"kind"); - // Node *c; - /* Add this structure to the known lisp types */ // Printf(stderr, "Adding %s foreign type\n", name); String *ns = listify_namespace(current_namespace); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 9f155fd02..1b7ab6840 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2333,14 +2333,12 @@ int Language::classDeclaration(Node *n) { String *kind = Getattr(n, "kind"); String *name = Getattr(n, "name"); String *tdname = Getattr(n, "tdname"); + String *unnamed = Getattr(n, "unnamed"); String *symname = Getattr(n, "sym:name"); - char *classname = tdname ? Char(tdname) : Char(name); - char *iname = Char(symname); - int strip = (tdname || CPlusPlus) ? 1 : 0; + int strip = CPlusPlus ? 1 : unnamed && tdname; - - if (!classname) { + if (!name) { Swig_warning(WARN_LANG_CLASS_UNNAMED, input_file, line_number, "Can't generate wrappers for unnamed struct/class.\n"); return SWIG_NOWRAP; } @@ -2351,21 +2349,18 @@ int Language::classDeclaration(Node *n) { return SWIG_NOWRAP; } - Swig_save("classDeclaration", n, "name", NIL); - Setattr(n, "name", classname); - if (Cmp(kind, "class") == 0) { cplus_mode = PRIVATE; } else { cplus_mode = PUBLIC; } - ClassName = NewString(classname); - ClassPrefix = NewString(iname); + ClassName = Copy(name); + ClassPrefix = Copy(symname); if (strip) { - ClassType = NewString(classname); + ClassType = Copy(name); } else { - ClassType = NewStringf("%s %s", kind, classname); + ClassType = NewStringf("%s %s", kind, name); } Setattr(n, "classtypeobj", Copy(ClassType)); Setattr(n, "classtype", SwigType_namestr(ClassType)); @@ -2435,7 +2430,6 @@ int Language::classDeclaration(Node *n) { ClassName = 0; Delete(DirectorClassName); DirectorClassName = 0; - Swig_restore(n); return SWIG_OK; } @@ -2611,7 +2605,7 @@ int Language::constructorDeclaration(Node *n) { } } else { if (name && (Cmp(Swig_scopename_last(name), Swig_scopename_last(ClassName))) && !(Getattr(n, "template"))) { - Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type.\n", SwigType_namestr(name)); + Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", SwigType_namestr(name)); Swig_restore(n); return SWIG_NOWRAP; } diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index 00d4ed97a..5a3cf1d24 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -2209,7 +2209,7 @@ MODULA3(): String *c_baseclass = NULL; String *baseclass = NULL; String *c_baseclassname = NULL; - String *classDeclarationName = Getattr(n, "classDeclaration:name"); + String *name = Getattr(n, "name"); /* Deal with inheritance */ List *baselist = Getattr(n, "bases"); @@ -2224,7 +2224,7 @@ MODULA3(): if (base.item != NIL) { Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", - classDeclarationName, Getattr(base.item, "name")); + name, Getattr(base.item, "name")); } } @@ -2233,22 +2233,22 @@ MODULA3(): baseclass = NewString(""); // Inheritance from pure Modula 3 classes - const String *pure_baseclass = typemapLookup(n, "m3base", classDeclarationName, WARN_NONE); + const String *pure_baseclass = typemapLookup(n, "m3base", name, WARN_NONE); if (hasContent(pure_baseclass) && hasContent(baseclass)) { Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", classDeclarationName, pure_baseclass); + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", name, pure_baseclass); } // Pure Modula 3 interfaces const String *pure_interfaces = typemapLookup(n, derived ? "m3interfaces_derived" : "m3interfaces", - classDeclarationName, WARN_NONE); + name, WARN_NONE); // Start writing the proxy class - Printv(proxy_class_def, typemapLookup(n, "m3imports", classDeclarationName, WARN_NONE), // Import statements - "\n", typemapLookup(n, "m3classmodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers + Printv(proxy_class_def, typemapLookup(n, "m3imports", name, WARN_NONE), // Import statements + "\n", typemapLookup(n, "m3classmodifiers", name, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers " class $m3classname", // Class name and bases (derived || *Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", baseclass, pure_baseclass, ((derived || *Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces ", " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", // Member variables for memory handling - derived ? "" : " protected bool swigCMemOwn;\n", "\n", " ", typemapLookup(n, "m3ptrconstructormodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers + derived ? "" : " protected bool swigCMemOwn;\n", "\n", " ", typemapLookup(n, "m3ptrconstructormodifiers", name, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers " $m3classname(IntPtr cPtr, bool cMemoryOwn) ", // Constructor used for wrapping pointers derived ? ": base($imclassname.$m3classnameTo$baseclass(cPtr), cMemoryOwn) {\n" @@ -2264,10 +2264,10 @@ MODULA3(): Node *attributes = NewHash(); String *destruct_methodname = NULL; if (derived) { - tm = typemapLookup(n, "m3destruct_derived", classDeclarationName, WARN_NONE, attributes); + tm = typemapLookup(n, "m3destruct_derived", name, WARN_NONE, attributes); destruct_methodname = Getattr(attributes, "tmap:m3destruct_derived:methodname"); } else { - tm = typemapLookup(n, "m3destruct", classDeclarationName, WARN_NONE, attributes); + tm = typemapLookup(n, "m3destruct", name, WARN_NONE, attributes); destruct_methodname = Getattr(attributes, "tmap:m3destruct:methodname"); } if (!destruct_methodname) { @@ -2277,7 +2277,7 @@ MODULA3(): if (tm) { // Finalize method if (*Char(destructor_call)) { - Printv(proxy_class_def, typemapLookup(n, "m3finalize", classDeclarationName, WARN_NONE), NIL); + Printv(proxy_class_def, typemapLookup(n, "m3finalize", name, WARN_NONE), NIL); } // Dispose method Printv(destruct, tm, NIL); @@ -2292,8 +2292,8 @@ MODULA3(): Delete(destruct); // Emit various other methods - Printv(proxy_class_def, typemapLookup(n, "m3getcptr", classDeclarationName, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method - typemapLookup(n, "m3code", classDeclarationName, WARN_NONE), // extra Modula 3 code + Printv(proxy_class_def, typemapLookup(n, "m3getcptr", name, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method + typemapLookup(n, "m3code", name, WARN_NONE), // extra Modula 3 code "\n", NIL); // Substitute various strings into the above template |