From 6f1e04f7bb790c9cbd2276d93776ec8d4d7377be Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Sun, 16 Mar 2003 03:57:07 +0000 Subject: [PATCH] smart-pointer const fix git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4551 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/Modules/allocate.cxx | 31 +++++++++++++++++++++++++++---- SWIG/Source/Modules/lang.cxx | 10 ++++++++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/SWIG/Source/Modules/allocate.cxx b/SWIG/Source/Modules/allocate.cxx index 31ed23c88..bef7a740b 100644 --- a/SWIG/Source/Modules/allocate.cxx +++ b/SWIG/Source/Modules/allocate.cxx @@ -229,7 +229,7 @@ class Allocate : public Dispatcher { /* Grab methods used by smart pointers */ - List *smart_pointer_methods(Node *cls, List *methods) { + List *smart_pointer_methods(Node *cls, List *methods, int isconst) { if (!methods) { methods = NewList(); } @@ -273,7 +273,23 @@ class Allocate : public Dispatcher { if (!match) { Node *cc = c; while (cc) { - Append(methods,cc); + /* If constant, we have to be careful */ + if (isconst) { + SwigType *decl = Getattr(cc,"decl"); + if (decl) { + if (SwigType_isfunction(decl)) { /* If method, we only add if it's a const method */ + if (SwigType_isconst(decl)) { + Append(methods,cc); + } + } else { + Append(methods,cc); + } + } else { + Append(methods,cc); + } + } else { + Append(methods,cc); + } cc = Getattr(cc,"sym:nextSibling"); } } @@ -294,7 +310,7 @@ class Allocate : public Dispatcher { Node *bases = Getattr(cls,"bases"); int k; for (k = 0; k < Len(bases); k++) { - smart_pointer_methods(Getitem(bases,k),methods); + smart_pointer_methods(Getitem(bases,k),methods,isconst); } } /* Remove protected/private members */ @@ -496,7 +512,14 @@ public: Node *sc = Swig_symbol_clookup(base, 0); if ((sc) && (Strcmp(nodeType(sc),"class") == 0)) { if (SwigType_check_decl(type,"p.")) { - List *methods = smart_pointer_methods(sc,0); + /* Need to check if type is a const pointer */ + int isconst = 0; + SwigType_pop(type); + if (SwigType_isconst(type)) { + isconst = 1; + Setattr(inclass,"allocate:smartpointerconst","1"); + } + List *methods = smart_pointer_methods(sc,0,isconst); Setattr(inclass,"allocate:smartpointer",methods); break; } else { diff --git a/SWIG/Source/Modules/lang.cxx b/SWIG/Source/Modules/lang.cxx index 71988035d..9ad706c09 100644 --- a/SWIG/Source/Modules/lang.cxx +++ b/SWIG/Source/Modules/lang.cxx @@ -1058,7 +1058,7 @@ int Language::membervariableHandler(Node *n) { Swig_require("membervariableHandler",n,"*name","*sym:name","*type",NIL); - Swig_save("membervariableHandler",n,"parms",NIL); + Swig_save("membervariableHandler",n,"parms","feature:immutable",NIL); String *name = Getattr(n,"name"); String *symname = Getattr(n,"sym:name"); @@ -1073,6 +1073,13 @@ Language::membervariableHandler(Node *n) { Delattr(n,"feature:except"); } + /* If a smart-pointer and it's a constant access, we have to set immutable */ + if (SmartPointer) { + if (Getattr(CurrentClass,"allocate:smartpointerconst")) { + Setattr(n,"feature:immutable","1"); + } + } + if (!AttributeFunctionGet) { String *mrename_get, *mrename_set; @@ -1672,7 +1679,6 @@ int Language::classHandler(Node *n) { SmartPointer = CWRAP_SMART_POINTER; Node *c; for (c = Firstitem(methods); c; c= Nextitem(methods)) { - /* Swig_print_node(c); */ emit_one(c); } SmartPointer = 0;