mirror of https://github.com/swig/swig
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:
parent
c794d08597
commit
30206f975c
|
@ -5,6 +5,18 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.5 (in progress)
|
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
|
2011-08-23: wsfulton
|
||||||
Fix %newobject when used in conjunction with %feature("ref") as reported by Jan Becker. The
|
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.
|
code from the "ref" feature was not always being generated for the function specified by %newobject.
|
||||||
|
|
|
@ -26,9 +26,13 @@ public:
|
||||||
|
|
||||||
// Test that the correct types are used for typedef struct declarations
|
// Test that the correct types are used for typedef struct declarations
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
int something;
|
||||||
|
void m() {}
|
||||||
} UnnamedStruct;
|
} UnnamedStruct;
|
||||||
|
|
||||||
typedef struct NamedStruct {
|
typedef struct NamedStruct {
|
||||||
|
int something;
|
||||||
|
void m() {}
|
||||||
} TypedefNamedStruct;
|
} TypedefNamedStruct;
|
||||||
|
|
||||||
typedef TypedefNamedStruct DoubleTypedef;
|
typedef TypedefNamedStruct DoubleTypedef;
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
%module xxx
|
||||||
|
|
||||||
|
struct R {};
|
||||||
|
|
||||||
|
struct S {
|
||||||
|
R() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct U {
|
||||||
|
UU() {}
|
||||||
|
} UU;
|
||||||
|
|
|
@ -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 :::::::::::::::::::::::::::::::::::
|
||||||
cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored).
|
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 :::::::::::::::::::::::::::::::::::
|
||||||
cpp_nobase.i:3: Warning 401: Nothing known about base class 'Bar'. Ignored.
|
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.
|
cpp_nobase.i:6: Warning 401: Nothing known about base class 'Bar< int >'. Ignored.
|
||||||
|
|
|
@ -74,6 +74,7 @@ cpp_namespace_aliasnot
|
||||||
cpp_namespace_aliasundef
|
cpp_namespace_aliasundef
|
||||||
cpp_nested
|
cpp_nested
|
||||||
cpp_no_access
|
cpp_no_access
|
||||||
|
cpp_no_return_type
|
||||||
cpp_nobase
|
cpp_nobase
|
||||||
cpp_overload
|
cpp_overload
|
||||||
cpp_overload_const
|
cpp_overload_const
|
||||||
|
|
|
@ -13,4 +13,20 @@ class B
|
||||||
typedef RealA A2;
|
typedef RealA A2;
|
||||||
int testA (const A2& a) {return a.a;}
|
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;
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -41,3 +41,14 @@ B_t make_b() {
|
||||||
return make_a();
|
return make_a();
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
typedef struct _Foo {
|
||||||
|
enum { NONAME1, NONAME2 } enumvar;
|
||||||
|
int foovar;
|
||||||
|
void (*fptr)(int);
|
||||||
|
} Foo;
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
|
@ -73,9 +73,8 @@ void NAME##_setitem(TYPE *ary, int index, TYPE value);
|
||||||
%{
|
%{
|
||||||
typedef TYPE NAME;
|
typedef TYPE NAME;
|
||||||
%}
|
%}
|
||||||
typedef struct NAME {
|
typedef struct {
|
||||||
/* Put language specific enhancements here */
|
/* Put language specific enhancements here */
|
||||||
|
|
||||||
} NAME;
|
} NAME;
|
||||||
|
|
||||||
%extend NAME {
|
%extend NAME {
|
||||||
|
|
|
@ -73,7 +73,7 @@ void NAME##_setitem(TYPE *ary, int index, TYPE value);
|
||||||
typedef TYPE NAME;
|
typedef TYPE NAME;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
typedef struct NAME {} NAME;
|
typedef struct {} NAME;
|
||||||
|
|
||||||
%extend NAME {
|
%extend NAME {
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__;
|
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__;
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
typedef struct NAME {
|
typedef struct {
|
||||||
TYPE *el;
|
TYPE *el;
|
||||||
} NAME;
|
} NAME;
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -72,7 +72,7 @@ typedef TYPE NAME;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
typedef struct NAME {
|
typedef struct {
|
||||||
} NAME;
|
} NAME;
|
||||||
|
|
||||||
%extend NAME {
|
%extend NAME {
|
||||||
|
|
|
@ -343,7 +343,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
|
||||||
String *val;
|
String *val;
|
||||||
String *ns_list = listify_namespace(ns);
|
String *ns_list = listify_namespace(ns);
|
||||||
String *templated = n ? Getattr(n, "template") : 0;
|
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
|
#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);
|
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
|
#ifdef ALLEGROCL_TYPE_DEBUG
|
||||||
Printf(stderr, "In cClassHandler\n");
|
Printf(stderr, "In cClassHandler\n");
|
||||||
#endif
|
#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 */
|
/* Add this structure to the known lisp types */
|
||||||
// Printf(stderr, "Adding %s foreign type\n", name);
|
// Printf(stderr, "Adding %s foreign type\n", name);
|
||||||
String *ns = listify_namespace(current_namespace);
|
String *ns = listify_namespace(current_namespace);
|
||||||
|
|
|
@ -2333,14 +2333,12 @@ int Language::classDeclaration(Node *n) {
|
||||||
String *kind = Getattr(n, "kind");
|
String *kind = Getattr(n, "kind");
|
||||||
String *name = Getattr(n, "name");
|
String *name = Getattr(n, "name");
|
||||||
String *tdname = Getattr(n, "tdname");
|
String *tdname = Getattr(n, "tdname");
|
||||||
|
String *unnamed = Getattr(n, "unnamed");
|
||||||
String *symname = Getattr(n, "sym:name");
|
String *symname = Getattr(n, "sym:name");
|
||||||
|
|
||||||
char *classname = tdname ? Char(tdname) : Char(name);
|
int strip = CPlusPlus ? 1 : unnamed && tdname;
|
||||||
char *iname = Char(symname);
|
|
||||||
int strip = (tdname || CPlusPlus) ? 1 : 0;
|
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
if (!classname) {
|
|
||||||
Swig_warning(WARN_LANG_CLASS_UNNAMED, input_file, line_number, "Can't generate wrappers for unnamed struct/class.\n");
|
Swig_warning(WARN_LANG_CLASS_UNNAMED, input_file, line_number, "Can't generate wrappers for unnamed struct/class.\n");
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
}
|
}
|
||||||
|
@ -2351,21 +2349,18 @@ int Language::classDeclaration(Node *n) {
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
Swig_save("classDeclaration", n, "name", NIL);
|
|
||||||
Setattr(n, "name", classname);
|
|
||||||
|
|
||||||
if (Cmp(kind, "class") == 0) {
|
if (Cmp(kind, "class") == 0) {
|
||||||
cplus_mode = PRIVATE;
|
cplus_mode = PRIVATE;
|
||||||
} else {
|
} else {
|
||||||
cplus_mode = PUBLIC;
|
cplus_mode = PUBLIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassName = NewString(classname);
|
ClassName = Copy(name);
|
||||||
ClassPrefix = NewString(iname);
|
ClassPrefix = Copy(symname);
|
||||||
if (strip) {
|
if (strip) {
|
||||||
ClassType = NewString(classname);
|
ClassType = Copy(name);
|
||||||
} else {
|
} else {
|
||||||
ClassType = NewStringf("%s %s", kind, classname);
|
ClassType = NewStringf("%s %s", kind, name);
|
||||||
}
|
}
|
||||||
Setattr(n, "classtypeobj", Copy(ClassType));
|
Setattr(n, "classtypeobj", Copy(ClassType));
|
||||||
Setattr(n, "classtype", SwigType_namestr(ClassType));
|
Setattr(n, "classtype", SwigType_namestr(ClassType));
|
||||||
|
@ -2435,7 +2430,6 @@ int Language::classDeclaration(Node *n) {
|
||||||
ClassName = 0;
|
ClassName = 0;
|
||||||
Delete(DirectorClassName);
|
Delete(DirectorClassName);
|
||||||
DirectorClassName = 0;
|
DirectorClassName = 0;
|
||||||
Swig_restore(n);
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2611,7 +2605,7 @@ int Language::constructorDeclaration(Node *n) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (name && (Cmp(Swig_scopename_last(name), Swig_scopename_last(ClassName))) && !(Getattr(n, "template"))) {
|
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);
|
Swig_restore(n);
|
||||||
return SWIG_NOWRAP;
|
return SWIG_NOWRAP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2209,7 +2209,7 @@ MODULA3():
|
||||||
String *c_baseclass = NULL;
|
String *c_baseclass = NULL;
|
||||||
String *baseclass = NULL;
|
String *baseclass = NULL;
|
||||||
String *c_baseclassname = NULL;
|
String *c_baseclassname = NULL;
|
||||||
String *classDeclarationName = Getattr(n, "classDeclaration:name");
|
String *name = Getattr(n, "name");
|
||||||
|
|
||||||
/* Deal with inheritance */
|
/* Deal with inheritance */
|
||||||
List *baselist = Getattr(n, "bases");
|
List *baselist = Getattr(n, "bases");
|
||||||
|
@ -2224,7 +2224,7 @@ MODULA3():
|
||||||
if (base.item != NIL) {
|
if (base.item != NIL) {
|
||||||
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
|
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",
|
"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("");
|
baseclass = NewString("");
|
||||||
|
|
||||||
// Inheritance from pure Modula 3 classes
|
// 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)) {
|
if (hasContent(pure_baseclass) && hasContent(baseclass)) {
|
||||||
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
|
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
|
// Pure Modula 3 interfaces
|
||||||
const String *pure_interfaces = typemapLookup(n, derived ? "m3interfaces_derived" : "m3interfaces",
|
const String *pure_interfaces = typemapLookup(n, derived ? "m3interfaces_derived" : "m3interfaces",
|
||||||
classDeclarationName, WARN_NONE);
|
name, WARN_NONE);
|
||||||
|
|
||||||
// Start writing the proxy class
|
// Start writing the proxy class
|
||||||
Printv(proxy_class_def, typemapLookup(n, "m3imports", classDeclarationName, WARN_NONE), // Import statements
|
Printv(proxy_class_def, typemapLookup(n, "m3imports", name, WARN_NONE), // Import statements
|
||||||
"\n", typemapLookup(n, "m3classmodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
"\n", typemapLookup(n, "m3classmodifiers", name, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
||||||
" class $m3classname", // Class name and bases
|
" class $m3classname", // Class name and bases
|
||||||
(derived || *Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", baseclass, pure_baseclass, ((derived || *Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
|
(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
|
", " : "", 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
|
" $m3classname(IntPtr cPtr, bool cMemoryOwn) ", // Constructor used for wrapping pointers
|
||||||
derived ?
|
derived ?
|
||||||
": base($imclassname.$m3classnameTo$baseclass(cPtr), cMemoryOwn) {\n"
|
": base($imclassname.$m3classnameTo$baseclass(cPtr), cMemoryOwn) {\n"
|
||||||
|
@ -2264,10 +2264,10 @@ MODULA3():
|
||||||
Node *attributes = NewHash();
|
Node *attributes = NewHash();
|
||||||
String *destruct_methodname = NULL;
|
String *destruct_methodname = NULL;
|
||||||
if (derived) {
|
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");
|
destruct_methodname = Getattr(attributes, "tmap:m3destruct_derived:methodname");
|
||||||
} else {
|
} else {
|
||||||
tm = typemapLookup(n, "m3destruct", classDeclarationName, WARN_NONE, attributes);
|
tm = typemapLookup(n, "m3destruct", name, WARN_NONE, attributes);
|
||||||
destruct_methodname = Getattr(attributes, "tmap:m3destruct:methodname");
|
destruct_methodname = Getattr(attributes, "tmap:m3destruct:methodname");
|
||||||
}
|
}
|
||||||
if (!destruct_methodname) {
|
if (!destruct_methodname) {
|
||||||
|
@ -2277,7 +2277,7 @@ MODULA3():
|
||||||
if (tm) {
|
if (tm) {
|
||||||
// Finalize method
|
// Finalize method
|
||||||
if (*Char(destructor_call)) {
|
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
|
// Dispose method
|
||||||
Printv(destruct, tm, NIL);
|
Printv(destruct, tm, NIL);
|
||||||
|
@ -2292,8 +2292,8 @@ MODULA3():
|
||||||
Delete(destruct);
|
Delete(destruct);
|
||||||
|
|
||||||
// Emit various other methods
|
// Emit various other methods
|
||||||
Printv(proxy_class_def, typemapLookup(n, "m3getcptr", classDeclarationName, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
|
Printv(proxy_class_def, typemapLookup(n, "m3getcptr", name, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
|
||||||
typemapLookup(n, "m3code", classDeclarationName, WARN_NONE), // extra Modula 3 code
|
typemapLookup(n, "m3code", name, WARN_NONE), // extra Modula 3 code
|
||||||
"\n", NIL);
|
"\n", NIL);
|
||||||
|
|
||||||
// Substitute various strings into the above template
|
// Substitute various strings into the above template
|
||||||
|
|
Loading…
Reference in New Issue