Fix constructors in named typedef class declarations

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12784 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-08-25 19:27:38 +00:00
parent c794d08597
commit 30206f975c
14 changed files with 86 additions and 38 deletions

View File

@ -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.

View File

@ -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;

View File

@ -0,0 +1,12 @@
%module xxx
struct R {};
struct S {
R() {}
};
typedef struct U {
UU() {}
} UU;

View File

@ -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.

View File

@ -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

View File

@ -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;
%}

View File

@ -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;
%}

View File

@ -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 {

View File

@ -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

View File

@ -4,7 +4,7 @@
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__;
%inline %{
typedef struct NAME {
typedef struct {
TYPE *el;
} NAME;
%}

View File

@ -72,7 +72,7 @@ typedef TYPE NAME;
%}
typedef struct NAME {
typedef struct {
} NAME;
%extend NAME {

View File

@ -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);

View File

@ -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;
}

View File

@ -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