more smart_pointer fixes + cases
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6844 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f91144e004
commit
d6760d4889
6 changed files with 87 additions and 26 deletions
|
|
@ -11,9 +11,14 @@ b = CBase()
|
||||||
d = CDerived()
|
d = CDerived()
|
||||||
p = CPtr()
|
p = CPtr()
|
||||||
|
|
||||||
|
if b.bar() != p.bar():
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
if d.foo() != p.foo():
|
if d.foo() != p.foo():
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
if b.hello() != p.hello():
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,3 +19,12 @@ if b.x != f.x:
|
||||||
|
|
||||||
if b.z != f.z:
|
if b.z != f.z:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
if Foo.z == Bar.z:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,51 @@
|
||||||
%module smart_pointer_extend
|
%module smart_pointer_extend
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
namespace hi
|
||||||
|
{
|
||||||
|
struct CBase
|
||||||
|
{
|
||||||
|
static int hello()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class CBase
|
class CDerived : public CBase
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
class CDerived : public CBase
|
class CPtr
|
||||||
{
|
{
|
||||||
};
|
public:
|
||||||
|
CDerived* operator->(void) {return 0;};
|
||||||
|
};
|
||||||
|
|
||||||
class CPtr
|
int get_hello(CPtr ptr)
|
||||||
{
|
{
|
||||||
public:
|
return ptr->hello();
|
||||||
CDerived* operator->(void) {return 0;};
|
}
|
||||||
};
|
|
||||||
|
class CPtrConst
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CDerived* operator->(void) const {return 0;};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%extend CBase {
|
%extend hi::CBase {
|
||||||
|
int foo(void) {return 1;};
|
||||||
|
int bar(void) {return 2;};
|
||||||
|
int boo(int i) {return i;};
|
||||||
|
}
|
||||||
|
|
||||||
|
%extend hi::CDerived {
|
||||||
int foo(void) {return 1;};
|
int foo(void) {return 1;};
|
||||||
}
|
}
|
||||||
|
|
||||||
%extend CDerived {
|
|
||||||
int foo(void) {return 2;};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
%extend Foo
|
%extend Foo
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@
|
||||||
int x[4];
|
int x[4];
|
||||||
int y;
|
int y;
|
||||||
static const int z;
|
static const int z;
|
||||||
|
|
||||||
|
static int boo() { return 0;}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Bar {
|
class Bar {
|
||||||
|
|
@ -18,6 +21,17 @@
|
||||||
Foo *operator->() {
|
Foo *operator->() {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int bua() { return 0;}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CBar {
|
||||||
|
Foo *f;
|
||||||
|
public:
|
||||||
|
CBar(Foo *f) : f(f) { }
|
||||||
|
Foo *operator->() const {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int get_y(Bar *b)
|
int get_y(Bar *b)
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,8 @@ class Allocate : public Dispatcher {
|
||||||
|
|
||||||
/* Grab methods used by smart pointers */
|
/* Grab methods used by smart pointers */
|
||||||
|
|
||||||
List *smart_pointer_methods(Node *cls, List *methods, int isconst) {
|
List *smart_pointer_methods(Node *cls, List *methods, int isconst,
|
||||||
|
String *classname=0) {
|
||||||
if (!methods) {
|
if (!methods) {
|
||||||
methods = NewList();
|
methods = NewList();
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +267,7 @@ class Allocate : public Dispatcher {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!isconst && (Strcmp(nodeType(c),"extend") == 0)) {
|
if (!isconst && (Strcmp(nodeType(c),"extend") == 0)) {
|
||||||
methods = smart_pointer_methods(c, methods, isconst);
|
methods = smart_pointer_methods(c, methods, isconst, Getattr(cls,"name"));
|
||||||
} else if (Strcmp(nodeType(c),"cdecl") == 0) {
|
} 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");
|
||||||
|
|
@ -296,23 +297,30 @@ class Allocate : public Dispatcher {
|
||||||
if (!match) {
|
if (!match) {
|
||||||
Node *cc = c;
|
Node *cc = c;
|
||||||
while (cc) {
|
while (cc) {
|
||||||
|
Node *cp = cc;
|
||||||
|
if (classname) {
|
||||||
|
Setattr(cp,"classname",classname);
|
||||||
|
}
|
||||||
|
Setattr(cp,"allocate:smartpointeraccess","1");
|
||||||
/* If constant, we have to be careful */
|
/* If constant, we have to be careful */
|
||||||
if (isconst) {
|
if (isconst) {
|
||||||
SwigType *decl = Getattr(cc,"decl");
|
SwigType *decl = Getattr(cp,"decl");
|
||||||
if (decl) {
|
if (decl) {
|
||||||
if (SwigType_isfunction(decl)) { /* If method, we only add if it's a const method */
|
if (SwigType_isfunction(decl)) { /* If method, we only add if it's a const method */
|
||||||
if (SwigType_isconst(decl)) {
|
if (SwigType_isconst(decl)) {
|
||||||
Append(methods,cc);
|
Append(methods,cp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Append(methods,cc);
|
Append(methods,cp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Append(methods,cc);
|
Setattr(cp,"feature:immutable","1");
|
||||||
|
Append(methods,cp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Append(methods,cc);
|
Append(methods,cp);
|
||||||
}
|
}
|
||||||
|
Delete(cp);
|
||||||
cc = Getattr(cc,"sym:nextSibling");
|
cc = Getattr(cc,"sym:nextSibling");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -899,7 +899,8 @@ Language::functionHandler(Node *n) {
|
||||||
globalfunctionHandler(n);
|
globalfunctionHandler(n);
|
||||||
} else {
|
} else {
|
||||||
String *storage = Getattr(n,"storage");
|
String *storage = Getattr(n,"storage");
|
||||||
if (Cmp(storage,"static") == 0) {
|
if (Cmp(storage,"static") == 0 &&
|
||||||
|
!(SmartPointer && Getattr(n,"allocate:smartpointeraccess"))) {
|
||||||
staticmemberfunctionHandler(n);
|
staticmemberfunctionHandler(n);
|
||||||
} else if (Cmp(storage,"friend") == 0) {
|
} else if (Cmp(storage,"friend") == 0) {
|
||||||
globalfunctionHandler(n);
|
globalfunctionHandler(n);
|
||||||
|
|
@ -1049,7 +1050,9 @@ Language::memberfunctionHandler(Node *n) {
|
||||||
|
|
||||||
String *fname = Swig_name_member(ClassPrefix, symname);
|
String *fname = Swig_name_member(ClassPrefix, symname);
|
||||||
if (Extend && SmartPointer) {
|
if (Extend && SmartPointer) {
|
||||||
Setattr(n,"classname",Getattr(CurrentClass,"allocate:smartpointerbase"));
|
if (!Getattr(n,"classname")) {
|
||||||
|
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);
|
||||||
|
|
@ -1133,14 +1136,15 @@ Language::variableHandler(Node *n) {
|
||||||
String *storage = Getattr(n,"storage");
|
String *storage = Getattr(n,"storage");
|
||||||
Swig_save("variableHandler",n,"feature:immutable",NIL);
|
Swig_save("variableHandler",n,"feature:immutable",NIL);
|
||||||
if (SmartPointer) {
|
if (SmartPointer) {
|
||||||
|
/* If a smart-pointer and it's a constant access, we have to set immutable */
|
||||||
if (Getattr(CurrentClass,"allocate:smartpointerconst")) {
|
if (Getattr(CurrentClass,"allocate:smartpointerconst")) {
|
||||||
Setattr(n,"feature:immutable","1");
|
Setattr(n,"feature:immutable","1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((Cmp(storage,"static") == 0)) {
|
if ((Cmp(storage,"static") == 0)
|
||||||
|
&& !(SmartPointer && Getattr(n,"allocate:smartpointeraccess"))) {
|
||||||
staticmembervariableHandler(n);
|
staticmembervariableHandler(n);
|
||||||
} else {
|
} else {
|
||||||
/* If a smart-pointer and it's a constant access, we have to set immutable */
|
|
||||||
membervariableHandler(n);
|
membervariableHandler(n);
|
||||||
}
|
}
|
||||||
Swig_restore(n);
|
Swig_restore(n);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue