Apply patch #3066958 from Mikael Johansson to fix default smart pointer handling when the smart pointer contains both a const and non-const operator->.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12240 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-10-03 13:12:00 +00:00
commit 3219746776
9 changed files with 343 additions and 12 deletions

View file

@ -824,9 +824,12 @@ Allocate():
int isconst = 0;
Delete(SwigType_pop(type));
if (SwigType_isconst(type)) {
isconst = 1;
isconst = !Getattr(inclass, "allocate:smartpointermutable");
Setattr(inclass, "allocate:smartpointerconst", "1");
}
else {
Setattr(inclass, "allocate:smartpointermutable", "1");
}
List *methods = smart_pointer_methods(sc, 0, isconst);
Setattr(inclass, "allocate:smartpointer", methods);
Setattr(inclass, "allocate:smartpointerbase", base);
@ -834,7 +837,6 @@ Allocate():
/* Hmmm. The return value is not a pointer. If the type is a value
or reference. We're going to chase it to see if another operator->()
can be found */
if ((SwigType_check_decl(type, "")) || (SwigType_check_decl(type, "r."))) {
Node *nn = Swig_symbol_clookup((char *) "operator ->", Getattr(sc, "symtab"));
if (nn) {

View file

@ -1344,7 +1344,7 @@ int Language::variableHandler(Node *n) {
Swig_save("variableHandler", n, "feature:immutable", NIL);
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:smartpointermutable")) {
SetFlag(n, "feature:immutable");
}
}
@ -1391,7 +1391,7 @@ int Language::membervariableHandler(Node *n) {
int assignable = is_assignable(n);
if (SmartPointer) {
if (Getattr(CurrentClass, "allocate:smartpointerconst")) {
if (!Getattr(CurrentClass, "allocate:smartpointermutable")) {
assignable = 0;
}
}
@ -2443,6 +2443,9 @@ int Language::classHandler(Node *n) {
List *methods = Getattr(n, "allocate:smartpointer");
cplus_mode = PUBLIC;
SmartPointer = CWRAP_SMART_POINTER;
if (Getattr(n, "allocate:smartpointerconst") && Getattr(n, "allocate:smartpointermutable")) {
SmartPointer |= CWRAP_SMART_POINTER_OVERLOAD;
}
Iterator c;
for (c = First(methods); c.item; c = Next(c)) {
emit_one(c.item);

View file

@ -783,15 +783,32 @@ int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parm
* ----------------------------------------------------------------------------- */
int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int flags, SwigType *director_type, int is_director) {
String *name, *qualifier;
String *name;
ParmList *parms;
SwigType *type;
Parm *p;
String *self = 0;
/* If smart pointer, change self dereferencing */
int is_smart_pointer_overload = 0;
String *qualifier = Getattr(n, "qualifier");
/* If smart pointer without const overload or mutable method, change self dereferencing */
if (flags & CWRAP_SMART_POINTER) {
self = NewString("(*this)->");
if (flags & CWRAP_SMART_POINTER_OVERLOAD) {
String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname;
if (qualifier && strncmp(Char(qualifier), "q(const)", 8) == 0) {
self = NewString("(*(this))->");
is_smart_pointer_overload = 1;
}
else if (Cmp(Getattr(n, "storage"), "static") == 0) {
self = NewStringf("(*(%s const *)this)->", cname);
is_smart_pointer_overload = 1;
}
else {
self = NewString("(*this)->");
}
} else {
self = NewString("(*this)->");
}
}
/* If node is a member template expansion, we don't allow added code */
@ -799,7 +816,6 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
flags &= ~(CWRAP_EXTEND);
name = Getattr(n, "name");
qualifier = Getattr(n, "qualifier");
parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
type = NewString(classname);
@ -921,10 +937,16 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
if (Cmp(Getattr(n, "storage"), "static") != 0) {
String *pname = Swig_cparm_name(pp, i);
String *ctname = SwigType_namestr(cname);
String *fadd = NewStringf("(%s*)(%s)->operator ->()", ctname, pname);
String *ctname = SwigType_namestr(cname);
String *fadd = 0;
if (is_smart_pointer_overload) {
fadd = NewStringf("(%s const *)((%s const *)%s)->operator ->()", ctname, classname, pname);
}
else {
fadd = NewStringf("(%s*)(%s)->operator ->()", ctname, pname);
}
Append(func, fadd);
Delete(ctname);
Delete(ctname);
Delete(fadd);
Delete(pname);
pp = nextSibling(pp);
@ -1310,6 +1332,8 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) {
Node *sn = Getattr(n, "cplus:staticbase");
String *base = Getattr(sn, "name");
self = NewStringf("%s::", base);
} else if (flags & CWRAP_SMART_POINTER_OVERLOAD) {
self = NewStringf("(*(%s const *)this)->", classname);
} else {
self = NewString("(*this)->");
}

View file

@ -370,6 +370,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
#define CWRAP_DIRECTOR_ONE_CALL 0x08
#define CWRAP_DIRECTOR_TWO_CALLS 0x10
#define CWRAP_ALL_PROTECTED_ACCESS 0x20
#define CWRAP_SMART_POINTER_OVERLOAD 0x40
/* --- Director Helpers --- */
extern Node *Swig_methodclass(Node *n);