diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2013-01-11 23:12:06 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2013-01-11 23:12:06 +0000 |
commit | 5889d7bfdd46a63886ebd87ce427e3bb73eaa254 (patch) | |
tree | 03e2e90113a8cd231e7cdebdf6d03138f2025277 | |
parent | 1fe1bb254373ef324408eb08ddad92e020988625 (diff) | |
parent | e1a59ae2c78e46d2593cdbe965da3330e3914494 (diff) | |
download | swig-5889d7bfdd46a63886ebd87ce427e3bb73eaa254.tar.gz |
Merge branch 'SFbug1299' of https://github.com/BrantKyser/swig into BrantKyser-SFbug1299
-rw-r--r-- | Examples/test-suite/common.mk | 1 | ||||
-rw-r--r-- | Examples/test-suite/director_nspace_director_name_collision.i | 66 | ||||
-rw-r--r-- | Examples/test-suite/java/Makefile.in | 1 | ||||
-rw-r--r-- | Source/Modules/csharp.cxx | 58 | ||||
-rw-r--r-- | Source/Modules/d.cxx | 82 | ||||
-rw-r--r-- | Source/Modules/directors.cxx | 10 | ||||
-rw-r--r-- | Source/Modules/java.cxx | 59 | ||||
-rw-r--r-- | Source/Modules/lang.cxx | 23 | ||||
-rw-r--r-- | Source/Modules/swigmod.h | 2 | ||||
-rw-r--r-- | Source/Swig/cwrap.c | 20 |
10 files changed, 198 insertions, 124 deletions
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index ececf84fd..23988404d 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -178,6 +178,7 @@ CPP_TEST_CASES += \ director_keywords \ director_namespace_clash \ director_nspace \ + director_nspace_director_name_collision \ director_nested \ director_overload \ director_overload2 \ diff --git a/Examples/test-suite/director_nspace_director_name_collision.i b/Examples/test-suite/director_nspace_director_name_collision.i new file mode 100644 index 000000000..5ef2509f8 --- /dev/null +++ b/Examples/test-suite/director_nspace_director_name_collision.i @@ -0,0 +1,66 @@ +%module(directors="1") director_nspace_director_name_collision + +#ifdef SWIGJAVA +SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) +SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) +#endif + +%{ +#include <string> + +namespace TopLevel +{ + namespace A + { + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "TopLevel::A::Foo::ping()"; } + }; + } + + namespace B + { + class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "TopLevel::B:Foo::ping()"; } + }; + } +} + +%} + +%include <std_string.i> + +// nspace feature only supported by these languages +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) +%nspace TopLevel::A::Foo; +%nspace TopLevel::B::Foo; +#else +#warning nspace feature not yet supported in this target language +#endif + +%feature("director") TopLevel::A::Foo; +%feature("director") TopLevel::B::Foo; + +namespace TopLevel +{ + namespace A + { + class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + }; + } + + namespace B + { + class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + }; + } +} diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 0b3f7babb..f8da8e6cc 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -46,6 +46,7 @@ SWIGOPT += -package $(JAVA_PACKAGE) nspace.%: JAVA_PACKAGE = $*Package nspace_extend.%: JAVA_PACKAGE = $*Package director_nspace.%: JAVA_PACKAGE = $*Package +director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests %.cpptest: diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 81b3b3f8b..c31d070be 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -198,24 +198,6 @@ public: return proxyname; } - /* ----------------------------------------------------------------------------- - * directorClassName() - * ----------------------------------------------------------------------------- */ - - String *directorClassName(Node *n) { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ @@ -3407,6 +3389,7 @@ public: String *sym_name = Getattr(n, "sym:name"); String *qualified_classname = Copy(sym_name); String *nspace = getNSpace(); + String *dirClassName = directorClassName(n); if (nspace) Insert(qualified_classname, 0, NewStringf("%s.", nspace)); @@ -3418,7 +3401,7 @@ public: Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname); Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); // TODO: if statement not needed?? - Java too Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director("); @@ -3430,7 +3413,7 @@ public: Printf(code_wrap->def, ", "); if (i != first_class_dmethod) Printf(code_wrap->code, ", "); - Printf(code_wrap->def, "SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid); + Printf(code_wrap->def, "%s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid); Printf(code_wrap->code, "callback%s", methid); Printf(imclass_class_code, ", %s.SwigDelegate%s_%s delegate%s", qualified_classname, sym_name, methid, methid); } @@ -3447,6 +3430,7 @@ public: Delete(wname); Delete(swig_director_connect); Delete(qualified_classname); + Delete(dirClassName); } /* --------------------------------------------------------------- @@ -3958,7 +3942,7 @@ public: Node *parent = parentNode(n); String *decl = Getattr(n, "decl"); String *supername = Swig_class_name(parent); - String *classname = directorClassName(parent); + String *dirclassname = directorClassName(parent); String *sub = NewString(""); Parm *p; ParmList *superparms = Getattr(n, "parms"); @@ -3982,11 +3966,11 @@ public: /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); - Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); + Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor")); Printf(f_directors, " swig_init_callbacks();\n"); Printf(f_directors, "}\n\n"); @@ -3997,7 +3981,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -4006,6 +3990,7 @@ public: Delete(sub); Delete(supername); Delete(parms); + Delete(dirclassname); return Language::classDirectorConstructor(n); } @@ -4014,18 +3999,18 @@ public: * ------------------------------------------------------------ */ int classDirectorDefaultConstructor(Node *n) { - String *classname = Swig_class_name(n); + String *dirclassname = directorClassName(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s() : %s {", dirclassname, dirclassname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s();\n", classname); + Printf(f_directors_h, " %s();\n", dirclassname); DelWrapper(w); Delete(classtype); - Delete(classname); + Delete(dirclassname); return Language::classDirectorDefaultConstructor(n); } @@ -4066,15 +4051,15 @@ public: int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); - String *classname = Swig_class_name(current_class); + String *dirclassname = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname); + Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", dirclassname); + Printf(w->def, "%s::~%s() {\n", dirclassname, dirclassname); } Printv(w->code, "}\n", NIL); @@ -4082,7 +4067,7 @@ public: Wrapper_print(w, f_directors); DelWrapper(w); - Delete(classname); + Delete(dirclassname); return SWIG_OK; } @@ -4172,8 +4157,7 @@ public: String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director()"); - String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); Printf(declaration, " : public %s, public Swig::Director", base); @@ -4181,6 +4165,8 @@ public: // Stash stuff for later. Setattr(n, "director:decl", declaration); Setattr(n, "director:ctor", class_ctor); + + Delete(directorname); } }; /* class CSHARP */ diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 560835751..3fffd8e33 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1897,7 +1897,7 @@ public: // Write C++ director class declaration, for example: // class SwigDirector_myclass : public myclass, public Swig::Director { String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); const String *base = Getattr(n, "classtype"); @@ -1949,7 +1949,7 @@ public: bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); int status = SWIG_OK; bool output_director = true; - String *dirclassname = getDirectorClassName(parent); + String *dirclassname = directorClassName(parent); String *qualified_name = NewStringf("%s::%s", dirclassname, name); SwigType *c_ret_type = NULL; String *dcallback_call_args = NewString(""); @@ -2373,10 +2373,12 @@ public: Printf(director_callback_pointers, " SWIG_Callback%s_t swig_callback_%s;\n", methid, overloaded_name); // Write the type alias for the callback to the intermediary D module. - String* proxy_callback_type = NewString(""); - Printf(proxy_callback_type, "SwigDirector_%s_Callback%s", classname, methid); + String *proxy_callback_type = NewString(""); + String *dirClassName = directorClassName(parent); + Printf(proxy_callback_type, "%s_Callback%s", dirClassName, methid); Printf(im_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type); Delete(proxy_callback_type); + Delete(dirClassName); } Delete(qualified_return); @@ -2399,7 +2401,7 @@ public: Node *parent = parentNode(n); String *decl = Getattr(n, "decl");; String *supername = Swig_class_name(parent); - String *classname = getDirectorClassName(parent); + String *dirclassname = directorClassName(parent); String *sub = NewString(""); Parm *p; ParmList *superparms = Getattr(n, "parms"); @@ -2423,11 +2425,11 @@ public: /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); - Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); + Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor")); Printf(f_directors, " swig_init_callbacks();\n"); Printf(f_directors, "}\n\n"); @@ -2438,7 +2440,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -2447,6 +2449,7 @@ public: Delete(sub); Delete(supername); Delete(parms); + Delete(dirclassname); return Language::classDirectorConstructor(n); } @@ -2454,18 +2457,18 @@ public: * D::classDirectorDefaultConstructor() * --------------------------------------------------------------------------- */ virtual int classDirectorDefaultConstructor(Node *n) { - String *classname = Swig_class_name(n); + String *dirclassname = directorClassName(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s() : %s {", dirclassname, dirclassname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s();\n", classname); + Printf(f_directors_h, " %s();\n", dirclassname); DelWrapper(w); Delete(classtype); - Delete(classname); + Delete(dirclassname); return Language::classDirectorDefaultConstructor(n); } @@ -2474,15 +2477,15 @@ public: * --------------------------------------------------------------------------- */ virtual int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); - String *classname = Swig_class_name(current_class); + String *dirclassname = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname); + Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", dirclassname); + Printf(w->def, "%s::~%s() {\n", dirclassname, dirclassname); } Printv(w->code, "}\n", NIL); @@ -2490,7 +2493,7 @@ public: Wrapper_print(w, f_directors); DelWrapper(w); - Delete(classname); + Delete(dirclassname); return SWIG_OK; } @@ -2499,7 +2502,7 @@ public: * --------------------------------------------------------------------------- */ virtual int classDirectorEnd(Node *n) { int i; - String *director_classname = getDirectorClassName(n); + String *director_classname = directorClassName(n); Wrapper *w = NewWrapper(); @@ -3308,7 +3311,7 @@ private: // If directors are enabled for the current class, generate the // director connect helper function which is called from the constructor // and write it to the class body. - writeDirectorConnectProxy(); + writeDirectorConnectProxy(n); } // Write all constants and enumerations first to prevent forward reference @@ -3475,12 +3478,15 @@ private: } /* --------------------------------------------------------------------------- - * D::writeDirectorConnectProxy() + * D::writeDirectorConnectProxy(Node *classNode) * * Writes the helper method which registers the director callbacks by calling * the director connect function from the D side to the proxy class. * --------------------------------------------------------------------------- */ - void writeDirectorConnectProxy() { + void writeDirectorConnectProxy(Node* classNode) { + String *dirClassName = directorClassName(classNode); + String *connect_name = Swig_name_member(getNSpace(), + proxy_class_name, "director_connect"); Printf(proxy_class_body_code, "\nprivate void swigDirectorConnect() {\n"); int i; @@ -3491,12 +3497,12 @@ private: String *return_type = Getattr(udata, "return_type"); String *param_list = Getattr(udata, "param_list"); String *methid = Getattr(udata, "class_methodidx"); - Printf(proxy_class_body_code, " %s.SwigDirector_%s_Callback%s callback%s;\n", im_dmodule_fq_name, proxy_class_name, methid, methid); + Printf(proxy_class_body_code, " %s.%s_Callback%s callback%s;\n", im_dmodule_fq_name, dirClassName, methid, methid); Printf(proxy_class_body_code, " if (swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) {\n", return_type, param_list, return_type, param_list, method); Printf(proxy_class_body_code, " callback%s = &swigDirectorCallback_%s_%s;\n", methid, proxy_class_name, overloaded_name); Printf(proxy_class_body_code, " }\n\n"); } - Printf(proxy_class_body_code, " %s.%s_director_connect(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, proxy_class_name); + Printf(proxy_class_body_code, " %s.%s(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, connect_name); for (i = first_class_dmethod; i < curr_class_dmethod; ++i) { UpcallData *udata = Getitem(dmethods_seq, i); String *methid = Getattr(udata, "class_methodidx"); @@ -3532,6 +3538,8 @@ private: director_callback_pointers = NULL; Delete(director_dcallbacks_code); director_dcallbacks_code = NULL; + Delete(dirClassName); + Delete(connect_name); } /* --------------------------------------------------------------------------- @@ -3548,7 +3556,7 @@ private: String *norm_name = SwigType_namestr(Getattr(n, "name")); String *connect_name = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); - String *sym_name = Getattr(n, "sym:name"); + String *dirClassName = directorClassName(n); Wrapper *code_wrap; Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL); @@ -3561,7 +3569,7 @@ private: Printf(code_wrap->def, "SWIGEXPORT void D_%s(void *objarg, void *dobj", connect_name); Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director(dobj"); @@ -3570,9 +3578,9 @@ private: UpcallData *udata = Getitem(dmethods_seq, i); String *methid = Getattr(udata, "class_methodidx"); - Printf(code_wrap->def, ", SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid); + Printf(code_wrap->def, ", %s::SWIG_Callback%s_t callback%s", dirClassName, methid, methid); Printf(code_wrap->code, ", callback%s", methid); - Printf(im_dmodule_code, ", SwigDirector_%s_Callback%s callback%s", sym_name, methid, methid); + Printf(im_dmodule_code, ", %s_Callback%s callback%s", dirClassName, methid, methid); } Printf(code_wrap->def, ") {\n"); @@ -3585,6 +3593,7 @@ private: DelWrapper(code_wrap); Delete(connect_name); + Delete(dirClassName); } /* --------------------------------------------------------------------------- @@ -4299,23 +4308,6 @@ private: } /* --------------------------------------------------------------------------- - * D::directorClassName() - * --------------------------------------------------------------------------- */ - String *getDirectorClassName(Node *n) const { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - - /* --------------------------------------------------------------------------- * D::makeParameterName() * * Inputs: diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx index 7f4c8d9d1..4b23a52bb 100644 --- a/Source/Modules/directors.cxx +++ b/Source/Modules/directors.cxx @@ -78,9 +78,10 @@ String *Swig_class_name(Node *n) { String *Swig_director_declaration(Node *n) { String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = Language::instance()->directorClassName(n); String *base = Getattr(n, "classtype"); String *declaration = Swig_class_declaration(n, directorname); + Printf(declaration, " : public %s, public Swig::Director {\n", base); Delete(classname); Delete(directorname); @@ -280,9 +281,10 @@ void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f) { checkAttribute(n, "storage", "static")) && !Equal(nodeType(n), "constructor"))) { Node *parent = Getattr(n, "parentNode"); - String *symname = Getattr(parent, "sym:name"); - String *dirname = NewStringf("SwigDirector_%s", symname); - String *dirdecl = NewStringf("%s *darg = 0", dirname); + String *dirname; + String *dirdecl; + dirname = Language::instance()->directorClassName(parent); + dirdecl = NewStringf("%s *darg = 0", dirname); Wrapper_add_local(f, "darg", dirdecl); Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n", dirname); Delete(dirname); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 0b34d10e7..b4703bd3e 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -204,24 +204,6 @@ public: return valid_jni_name; } - /* ----------------------------------------------------------------------------- - * directorClassName() - * ----------------------------------------------------------------------------- */ - - String *directorClassName(Node *n) { - String *dirclassname; - const char *attrib = "director:classname"; - - if (!(dirclassname = Getattr(n, attrib))) { - String *classname = Getattr(n, "sym:name"); - - dirclassname = NewStringf("SwigDirector_%s", classname); - Setattr(n, attrib, dirclassname); - } - - return dirclassname; - } - /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ @@ -2008,7 +1990,7 @@ public: Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); Printf(dcast_wrap->code, " if (obj) director = dynamic_cast<Swig::Director *>(obj);\n"); - Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n"); + Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self);\n"); Printf(dcast_wrap->code, " return jresult;\n"); Printf(dcast_wrap->code, "}\n"); @@ -3380,8 +3362,8 @@ public: String *norm_name = SwigType_namestr(Getattr(n, "name")); String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); String *swig_director_connect_jni = makeValidJniName(swig_director_connect); - String *sym_name = Getattr(n, "sym:name"); String *smartptr_feature = Getattr(n, "feature:smartptr"); + String *dirClassName = directorClassName(n); Wrapper *code_wrap; Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n", @@ -3401,12 +3383,12 @@ public: Printf(code_wrap->code, " // raw pointer alive. This is done instead of using the smart pointer's dynamic cast\n"); Printf(code_wrap->code, " // feature since different smart pointer implementations have differently named dynamic\n"); Printf(code_wrap->code, " // cast mechanisms.\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj->operator->());\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName); } else { Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); Printf(code_wrap->code, " (void)jcls;\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); } Printf(code_wrap->code, " if (director) {\n"); @@ -3432,7 +3414,7 @@ public: "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release) {\n", jnipackage, jni_imclass_name, changeown_jnimethod_name); Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name); + Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName); Printf(code_wrap->code, " (void)jcls;\n"); Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);\n"); @@ -3445,6 +3427,7 @@ public: Delete(changeown_method_name); Delete(changeown_jnimethod_name); Delete(norm_name); + Delete(dirClassName); Delete(jni_imclass_name); } @@ -3583,7 +3566,7 @@ public: // we're consistent with the sym:overload name in functionWrapper. (?? when // does the overloaded method name get set?) - imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name)); + imclass_dmethod = NewStringf("%s", Swig_name_member(getNSpace(), dirclassname, overloaded_name)); qualified_return = SwigType_rcaststr(returntype, "c_result"); @@ -4116,7 +4099,7 @@ public: Node *parent = parentNode(n); String *decl = Getattr(n, "decl"); String *supername = Swig_class_name(parent); - String *classname = directorClassName(parent); + String *dirclassname = directorClassName(parent); String *sub = NewString(""); Parm *p; ParmList *superparms = Getattr(n, "parms"); @@ -4148,11 +4131,11 @@ public: /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); - Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); + Printf(f_directors, "%s::%s : %s, %s {\n", dirclassname, target, call, Getattr(parent, "director:ctor")); Printf(f_directors, "}\n\n"); Delete(classtype); @@ -4162,7 +4145,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, dirclassname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -4172,6 +4155,7 @@ public: Delete(supername); Delete(jenv_type); Delete(parms); + Delete(dirclassname); return Language::classDirectorConstructor(n); } @@ -4182,16 +4166,18 @@ public: int classDirectorDefaultConstructor(Node *n) { String *classname = Swig_class_name(n); String *classtype = SwigType_namestr(Getattr(n, "name")); + String *dirClassName = directorClassName(n); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s(JNIEnv *jenv) : %s {", classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "%s::%s(JNIEnv *jenv) : %s {", dirClassName, dirClassName, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); - Printf(f_directors_h, " SwigDirector_%s(JNIEnv *jenv);\n", classname); + Printf(f_directors_h, " %s(JNIEnv *jenv);\n", dirClassName); DelWrapper(w); Delete(classtype); Delete(classname); + Delete(dirClassName); directorPrefixArgs(n); return Language::classDirectorDefaultConstructor(n); } @@ -4228,14 +4214,15 @@ public: Node *current_class = getCurrentClass(); String *full_classname = Getattr(current_class, "name"); String *classname = Swig_class_name(current_class); + String *dirClassName = directorClassName(current_class); Wrapper *w = NewWrapper(); if (Getattr(n, "throw")) { - Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s() throw ();\n", dirClassName); + Printf(w->def, "%s::~%s() throw () {\n", dirClassName, dirClassName); } else { - Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname); - Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname); + Printf(f_directors_h, " virtual ~%s();\n", dirClassName); + Printf(w->def, "%s::~%s() {\n", dirClassName, dirClassName); } /* Ensure that correct directordisconnect typemap's method name is called @@ -4254,6 +4241,7 @@ public: DelWrapper(w); Delete(disconn_attr); Delete(classname); + Delete(dirClassName); return SWIG_OK; } @@ -4400,8 +4388,7 @@ public: String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director(jenv)"); - String *classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); + String *directorname = directorClassName(n); String *declaration = Swig_class_declaration(n, directorname); Printf(declaration, " : public %s, public Swig::Director", base); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 8e5a91dbe..dc21d7f96 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -347,6 +347,27 @@ Language::~Language() { this_ = 0; } + /* ----------------------------------------------------------------------------- + * directorClassName() + * ----------------------------------------------------------------------------- */ + + String *Language::directorClassName(Node *n) { + String *dirclassname; + String *nspace = NewString(Getattr(n, "sym:nspace")); + const char *attrib = "director:classname"; + String *classname = Getattr(n, "sym:name"); + + Replace(nspace, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY); + if (Len(nspace) > 0) + dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname); + else + dirclassname = NewStringf("SwigDirector_%s", classname); + Setattr(n, attrib, dirclassname); + + Delete(nspace); + return dirclassname; + } + /* ---------------------------------------------------------------------- emit_one() ---------------------------------------------------------------------- */ @@ -2405,7 +2426,7 @@ int Language::classDeclaration(Node *n) { } if (dir) { - DirectorClassName = NewStringf("SwigDirector_%s", symname); + DirectorClassName = directorClassName(n); classDirector(n); } /* check for abstract after resolving directors */ diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 4a65444fc..b3722af40 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -120,6 +120,8 @@ public: virtual ~Language(); virtual int emit_one(Node *n); + String *directorClassName(Node *n); + /* Parse command line options */ virtual void main(int argc, char *argv[]); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 063ab9858..38787fc63 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -855,6 +855,9 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas String *self = 0; int is_smart_pointer_overload = 0; String *qualifier = Getattr(n, "qualifier"); + String *directorScope = NewString(nspace); + + Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY); /* If smart pointer without const overload or mutable method, change self dereferencing */ if (flags & CWRAP_SMART_POINTER) { @@ -937,7 +940,10 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas /* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */ String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); explicitcall_name = NewStringf("%sSwigPublic", name); - explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp); + if (Len(directorScope) > 0) + explicit_qualifier = NewStringf("SwigDirector_%s_%s", directorScope, explicit_qualifier_tmp); + else + explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp); Delete(explicit_qualifier_tmp); } else { explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname")); @@ -1057,6 +1063,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas Delete(p); Delete(self); Delete(parms); + Delete(directorScope); return SWIG_OK; } @@ -1107,6 +1114,9 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String ParmList *directorparms; SwigType *type; int use_director; + String *directorScope = NewString(nspace); + + Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY); use_director = Swig_directorclass(n); @@ -1167,12 +1177,17 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String Node *parent = Swig_methodclass(n); int abstract = Getattr(parent, "abstracts") != 0; String *name = Getattr(parent, "sym:name"); - String *directorname = NewStringf("SwigDirector_%s", name); + String *directorname; String *action = NewStringEmpty(); String *tmp_none_comparison = Copy(none_comparison); String *director_call; String *nodirector_call; + if (Len(directorScope) > 0) + directorname = NewStringf("SwigDirector_%s_%s", directorScope, name); + else + directorname = NewStringf("SwigDirector_%s", name); + Replaceall(tmp_none_comparison, "$arg", "arg1"); director_call = Swig_cppconstructor_director_call(directorname, directorparms); @@ -1233,6 +1248,7 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String if (directorparms != parms) Delete(directorparms); Delete(parms); + Delete(directorScope); return SWIG_OK; } |