add support for smart pointers + %extend
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6819 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
ee3e53c9cd
commit
d0fad62e2c
5 changed files with 75 additions and 36 deletions
|
|
@ -10,6 +10,8 @@ b = Bar(f)
|
||||||
b.y = 2
|
b.y = 2
|
||||||
|
|
||||||
if f.y != 2:
|
if f.y != 2:
|
||||||
|
print f.y
|
||||||
|
print b.y
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
if b.x != f.x:
|
if b.x != f.x:
|
||||||
|
|
@ -17,3 +19,6 @@ if b.x != f.x:
|
||||||
|
|
||||||
if b.z != f.z:
|
if b.z != f.z:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
if b.extension() != f.extension():
|
||||||
|
raise RuntimeError
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,43 @@
|
||||||
%module smart_pointer_member
|
%module smart_pointer_member
|
||||||
|
|
||||||
|
|
||||||
|
%extend Foo
|
||||||
|
{
|
||||||
|
int extension(int i, int j) { return i; }
|
||||||
|
int extension(int i) { return i; }
|
||||||
|
int extension() { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
int x[4];
|
int x[4];
|
||||||
int y;
|
int y;
|
||||||
static const int z;
|
static const int z;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Bar {
|
class Bar {
|
||||||
Foo *f;
|
Foo *f;
|
||||||
public:
|
public:
|
||||||
Bar(Foo *f) : f(f) { }
|
Bar(Foo *f) : f(f) { }
|
||||||
Foo *operator->() {
|
Foo *operator->() {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int get_y(Bar *b)
|
int get_y(Bar *b)
|
||||||
{
|
{
|
||||||
return (*b)->y;
|
return (*b)->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_z(Bar *b)
|
int get_z(Bar *b)
|
||||||
{
|
{
|
||||||
return (*b)->z;
|
return (*b)->z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
const int Foo::z = 3;
|
const int Foo::z = 3;
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -259,16 +259,17 @@ class Allocate : public Dispatcher {
|
||||||
|
|
||||||
Node *c = firstChild(cls);
|
Node *c = firstChild(cls);
|
||||||
String *kind = Getattr(cls,"kind");
|
String *kind = Getattr(cls,"kind");
|
||||||
int mode;
|
int mode = PUBLIC;
|
||||||
if (Strcmp(kind,"class") == 0) mode = PRIVATE;
|
if (kind && (Strcmp(kind,"class") == 0)) mode = PRIVATE;
|
||||||
else mode = PUBLIC;
|
|
||||||
|
|
||||||
while (c) {
|
while (c) {
|
||||||
if (Getattr(c,"error") || Getattr(c,"feature:ignore")) {
|
if (Getattr(c,"error") || Getattr(c,"feature:ignore")) {
|
||||||
c = nextSibling(c);
|
c = nextSibling(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Strcmp(nodeType(c),"cdecl") == 0) {
|
if (Strcmp(nodeType(c),"extend") == 0) {
|
||||||
|
Append(methods,c);
|
||||||
|
} else if (Strcmp(nodeType(c),"cdecl") == 0) {
|
||||||
if (!Getattr(c,"feature:ignore")) {
|
if (!Getattr(c,"feature:ignore")) {
|
||||||
String *storage = Getattr(c,"storage");
|
String *storage = Getattr(c,"storage");
|
||||||
if (!((Cmp(storage,"typedef") == 0))) {
|
if (!((Cmp(storage,"typedef") == 0))) {
|
||||||
|
|
|
||||||
|
|
@ -1055,6 +1055,9 @@ Language::memberfunctionHandler(Node *n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
String *fname = Swig_name_member(ClassPrefix, symname);
|
String *fname = Swig_name_member(ClassPrefix, symname);
|
||||||
|
if (Extend && SmartPointer) {
|
||||||
|
Setattr(n,"classname",Getattr(CurrentClass,"allocate:smartpointerbase"));
|
||||||
|
}
|
||||||
/* Transformation */
|
/* Transformation */
|
||||||
Swig_MethodToFunction(n,ClassType, Getattr(n,"template") ? 0 : Extend | SmartPointer);
|
Swig_MethodToFunction(n,ClassType, Getattr(n,"template") ? 0 : Extend | SmartPointer);
|
||||||
Setattr(n,"sym:name",fname);
|
Setattr(n,"sym:name",fname);
|
||||||
|
|
|
||||||
|
|
@ -295,8 +295,12 @@ Swig_cfunction_call(String_or_char *name, ParmList *parms) {
|
||||||
if ((SwigType_type(pt) != T_VOID)) {
|
if ((SwigType_type(pt) != T_VOID)) {
|
||||||
String *pname = Swig_cparm_name(p,i);
|
String *pname = Swig_cparm_name(p,i);
|
||||||
String *rcaststr = SwigType_rcaststr(pt, pname);
|
String *rcaststr = SwigType_rcaststr(pt, pname);
|
||||||
if (comma) Printf(func,",");
|
if (comma) {
|
||||||
Printf(func,"%s", rcaststr);
|
Printf(func, ",%s", rcaststr);
|
||||||
|
} else {
|
||||||
|
Printf(func, "%s", rcaststr);
|
||||||
|
}
|
||||||
|
Delete(pname);
|
||||||
Delete(rcaststr);
|
Delete(rcaststr);
|
||||||
comma = 1;
|
comma = 1;
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -716,7 +720,8 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
|
||||||
|
|
||||||
String *defaultargs = Getattr(n,"defaultargs");
|
String *defaultargs = Getattr(n,"defaultargs");
|
||||||
String *code = Getattr(n,"code");
|
String *code = Getattr(n,"code");
|
||||||
String *membername = Swig_name_member(classname, name);
|
String *cname = Getattr(n,"classname") ? Getattr(n,"classname") : classname;
|
||||||
|
String *membername = Swig_name_member(cname, name);
|
||||||
String *mangled = Swig_name_mangle(membername);
|
String *mangled = Swig_name_mangle(membername);
|
||||||
|
|
||||||
type = Getattr(n,"type");
|
type = Getattr(n,"type");
|
||||||
|
|
@ -739,9 +744,27 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
|
||||||
Delete(tmp);
|
Delete(tmp);
|
||||||
Delete(body);
|
Delete(body);
|
||||||
}
|
}
|
||||||
|
if (flags & CWRAP_SMART_POINTER) {
|
||||||
Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", Swig_cfunction_call(mangled,p)));
|
int i = 0;
|
||||||
|
Parm *pp = p;
|
||||||
|
String *func = NewStringf("%s((%s*)(%s)->operator ->()", mangled, cname,
|
||||||
|
Swig_cparm_name(pp,i++));
|
||||||
|
while ((pp = nextSibling(pp))) {
|
||||||
|
SwigType *pt = Getattr(pp,"type");
|
||||||
|
if ((SwigType_type(pt) != T_VOID)) {
|
||||||
|
String *pname = Swig_cparm_name(pp,i++);
|
||||||
|
String *rcaststr = SwigType_rcaststr(pt, pname);
|
||||||
|
Printf(func,",%s", rcaststr);
|
||||||
|
Delete(rcaststr);
|
||||||
|
Delete(pname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Printf(func,")");
|
||||||
|
Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", func));
|
||||||
|
} else {
|
||||||
|
Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", Swig_cfunction_call(mangled,p)));
|
||||||
|
}
|
||||||
|
|
||||||
Delete(membername);
|
Delete(membername);
|
||||||
Delete(mangled);
|
Delete(mangled);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue