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
|
||||
|
||||
if f.y != 2:
|
||||
print f.y
|
||||
print b.y
|
||||
raise RuntimeError
|
||||
|
||||
if b.x != f.x:
|
||||
|
|
@ -17,3 +19,6 @@ if b.x != f.x:
|
|||
|
||||
if b.z != f.z:
|
||||
raise RuntimeError
|
||||
|
||||
if b.extension() != f.extension():
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -1,36 +1,43 @@
|
|||
%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 %{
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
int x[4];
|
||||
int y;
|
||||
static const int z;
|
||||
};
|
||||
|
||||
class Bar {
|
||||
Foo *f;
|
||||
public:
|
||||
Bar(Foo *f) : f(f) { }
|
||||
Foo *operator->() {
|
||||
class Foo {
|
||||
public:
|
||||
int x[4];
|
||||
int y;
|
||||
static const int z;
|
||||
};
|
||||
|
||||
class Bar {
|
||||
Foo *f;
|
||||
public:
|
||||
Bar(Foo *f) : f(f) { }
|
||||
Foo *operator->() {
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
int get_y(Bar *b)
|
||||
{
|
||||
return (*b)->y;
|
||||
}
|
||||
|
||||
int get_z(Bar *b)
|
||||
{
|
||||
return (*b)->z;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
int get_y(Bar *b)
|
||||
{
|
||||
return (*b)->y;
|
||||
}
|
||||
|
||||
int get_z(Bar *b)
|
||||
{
|
||||
return (*b)->z;
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
%{
|
||||
const int Foo::z = 3;
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -259,16 +259,17 @@ class Allocate : public Dispatcher {
|
|||
|
||||
Node *c = firstChild(cls);
|
||||
String *kind = Getattr(cls,"kind");
|
||||
int mode;
|
||||
if (Strcmp(kind,"class") == 0) mode = PRIVATE;
|
||||
else mode = PUBLIC;
|
||||
int mode = PUBLIC;
|
||||
if (kind && (Strcmp(kind,"class") == 0)) mode = PRIVATE;
|
||||
|
||||
while (c) {
|
||||
if (Getattr(c,"error") || Getattr(c,"feature:ignore")) {
|
||||
c = nextSibling(c);
|
||||
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")) {
|
||||
String *storage = Getattr(c,"storage");
|
||||
if (!((Cmp(storage,"typedef") == 0))) {
|
||||
|
|
|
|||
|
|
@ -1055,6 +1055,9 @@ Language::memberfunctionHandler(Node *n) {
|
|||
}
|
||||
|
||||
String *fname = Swig_name_member(ClassPrefix, symname);
|
||||
if (Extend && SmartPointer) {
|
||||
Setattr(n,"classname",Getattr(CurrentClass,"allocate:smartpointerbase"));
|
||||
}
|
||||
/* Transformation */
|
||||
Swig_MethodToFunction(n,ClassType, Getattr(n,"template") ? 0 : Extend | SmartPointer);
|
||||
Setattr(n,"sym:name",fname);
|
||||
|
|
|
|||
|
|
@ -295,8 +295,12 @@ Swig_cfunction_call(String_or_char *name, ParmList *parms) {
|
|||
if ((SwigType_type(pt) != T_VOID)) {
|
||||
String *pname = Swig_cparm_name(p,i);
|
||||
String *rcaststr = SwigType_rcaststr(pt, pname);
|
||||
if (comma) Printf(func,",");
|
||||
Printf(func,"%s", rcaststr);
|
||||
if (comma) {
|
||||
Printf(func, ",%s", rcaststr);
|
||||
} else {
|
||||
Printf(func, "%s", rcaststr);
|
||||
}
|
||||
Delete(pname);
|
||||
Delete(rcaststr);
|
||||
comma = 1;
|
||||
i++;
|
||||
|
|
@ -716,7 +720,8 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
|
|||
|
||||
String *defaultargs = Getattr(n,"defaultargs");
|
||||
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);
|
||||
|
||||
type = Getattr(n,"type");
|
||||
|
|
@ -739,9 +744,27 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
|
|||
Delete(tmp);
|
||||
Delete(body);
|
||||
}
|
||||
|
||||
Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", Swig_cfunction_call(mangled,p)));
|
||||
|
||||
if (flags & CWRAP_SMART_POINTER) {
|
||||
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(mangled);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue