From 599d64e188a643cefaff370f6762d6a7d66e2306 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 9 Nov 2006 22:32:28 +0000 Subject: [PATCH] Fix director operator pointer casts git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9536 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/Modules/csharp.cxx | 24 +++------ SWIG/Source/Modules/directors.cxx | 81 ++++++++++++++++++------------- SWIG/Source/Modules/java.cxx | 24 +++------ SWIG/Source/Modules/ocaml.cxx | 21 +++----- SWIG/Source/Modules/python.cxx | 21 +++----- SWIG/Source/Modules/ruby.cxx | 21 +++----- SWIG/Source/Modules/swigmod.h | 2 +- 7 files changed, 83 insertions(+), 111 deletions(-) diff --git a/SWIG/Source/Modules/csharp.cxx b/SWIG/Source/Modules/csharp.cxx index 619a837c9..fd26ab908 100644 --- a/SWIG/Source/Modules/csharp.cxx +++ b/SWIG/Source/Modules/csharp.cxx @@ -3252,23 +3252,13 @@ public: /* header declaration, start wrapper definition */ String *target; - - target = Swig_method_decl(decl, qualified_name, l, 0, 0); - String *rtype = SwigType_str(type, 0); - - if (Getattr(n, "conversion_operator")) - Printf(w->def, "%s", target); - else - Printf(w->def, "%s %s", rtype, target); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s", target); Delete(qualified_name); Delete(target); - - target = Swig_method_decl(decl, name, l, 0, 1); - if (Getattr(n, "conversion_operator")) - Printf(declaration, " virtual %s", target); - else - Printf(declaration, " virtual %s %s", rtype, target); - Delete(rtype); + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s", target); Delete(target); // Get any Java exception classes in the throws typemap @@ -3462,7 +3452,7 @@ public: /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); @@ -3477,7 +3467,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } diff --git a/SWIG/Source/Modules/directors.cxx b/SWIG/Source/Modules/directors.cxx index d8881a5a7..fd8fdf865 100644 --- a/SWIG/Source/Modules/directors.cxx +++ b/SWIG/Source/Modules/directors.cxx @@ -128,7 +128,7 @@ String *Swig_method_call(String_or_char *name, ParmList *parms) { * */ -String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int strip, int values) { +String *Swig_method_decl(SwigType *returntype, SwigType *decl, const String_or_char *id, List *args, int strip, int values) { String *result; List *elements; String *element = 0, *nextelement; @@ -143,7 +143,7 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int result = NewString(""); } - elements = SwigType_split(s); + elements = SwigType_split(decl); nelements = Len(elements); if (nelements > 0) { element = Getitem(elements, 0); @@ -172,31 +172,6 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int } Delete(q); } - } else if (SwigType_ispointer(element)) { - Insert(result, 0, "*"); - if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result, 0, "("); - Append(result, ")"); - } - } else if (SwigType_ismemberpointer(element)) { - String *q; - q = SwigType_parm(element); - Insert(result, 0, "::*"); - Insert(result, 0, q); - if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result, 0, "("); - Append(result, ")"); - } - Delete(q); - } else if (SwigType_isreference(element)) { - Insert(result, 0, "&"); - } else if (SwigType_isarray(element)) { - DOH *size; - Append(result, "["); - size = SwigType_parm(element); - Append(result, size); - Append(result, "]"); - Delete(size); } else if (SwigType_isfunction(element)) { Parm *parm; String *p; @@ -224,19 +199,48 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int Append(result, ", "); } Append(result, ")"); - } else { - if (Strcmp(element, "v(...)") == 0) { - Insert(result, 0, "..."); + } else if (returntype) { // This check is intended for conversion operators to a pointer/reference which needs the pointer/reference ignoring in the declaration + if (SwigType_ispointer(element)) { + Insert(result, 0, "*"); + if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { + Insert(result, 0, "("); + Append(result, ")"); + } + } else if (SwigType_ismemberpointer(element)) { + String *q; + q = SwigType_parm(element); + Insert(result, 0, "::*"); + Insert(result, 0, q); + if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { + Insert(result, 0, "("); + Append(result, ")"); + } + Delete(q); + } else if (SwigType_isreference(element)) { + Insert(result, 0, "&"); + } else if (SwigType_isarray(element)) { + DOH *size; + Append(result, "["); + size = SwigType_parm(element); + Append(result, size); + Append(result, "]"); + Delete(size); } else { - String *bs = SwigType_namestr(element); - Insert(result, 0, " "); - Insert(result, 0, bs); - Delete(bs); + if (Strcmp(element, "v(...)") == 0) { + Insert(result, 0, "..."); + } else { + String *bs = SwigType_namestr(element); + Insert(result, 0, " "); + Insert(result, 0, bs); + Delete(bs); + } } } element = nextelement; } + Delete(elements); + if (is_const) { if (is_func) { Append(result, " "); @@ -245,6 +249,15 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int Insert(result, 0, "const "); } } + Chop(result); + + if (returntype) { + Insert(result, 0, " "); + String *rtype = SwigType_str(returntype, 0); + Insert(result, 0, rtype); + Delete(rtype); + } + return result; } diff --git a/SWIG/Source/Modules/java.cxx b/SWIG/Source/Modules/java.cxx index 4430a29bf..4e53316e3 100644 --- a/SWIG/Source/Modules/java.cxx +++ b/SWIG/Source/Modules/java.cxx @@ -3370,23 +3370,13 @@ public: /* header declaration, start wrapper definition */ String *target; - - target = Swig_method_decl(decl, qualified_name, l, 0, 0); - String *rtype = SwigType_str(type, 0); - - if (Getattr(n, "conversion_operator")) - Printf(w->def, "%s", target); - else - Printf(w->def, "%s %s", rtype, target); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s", target); Delete(qualified_name); Delete(target); - - target = Swig_method_decl(decl, name, l, 0, 1); - if (Getattr(n, "conversion_operator")) - Printf(declaration, " virtual %s", target); - else - Printf(declaration, " virtual %s %s", rtype, target); - Delete(rtype); + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s", target); Delete(target); // Get any Java exception classes in the throws typemap @@ -3613,7 +3603,7 @@ public: /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); @@ -3627,7 +3617,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } diff --git a/SWIG/Source/Modules/ocaml.cxx b/SWIG/Source/Modules/ocaml.cxx index cac8f42ef..0c1964556 100755 --- a/SWIG/Source/Modules/ocaml.cxx +++ b/SWIG/Source/Modules/ocaml.cxx @@ -1440,20 +1440,14 @@ public: String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - target = Swig_method_decl(decl, qualified_name, l, 0, 0); - String *rtype = SwigType_str(type, 0); - if (Getattr(n, "conversion_operator")) - Printf(w->def, "%s {", target); - else - Printf(w->def, "%s %s {", rtype, target); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s {", target); Delete(qualified_name); Delete(target); /* header declaration */ - target = Swig_method_decl(decl, name, l, 0, 1); - if (Getattr(n, "conversion_operator")) - Printf(declaration, " virtual %s;", target); - else - Printf(declaration, " virtual %s %s;\n", rtype, target); + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s;", target); Delete(target); /* declare method return value @@ -1715,7 +1709,6 @@ public: /* clean up */ Delete(wrap_args); - Delete(rtype); Delete(return_type); Delete(pclassname); DelWrapper(w); @@ -1751,7 +1744,7 @@ public: Wrapper *w = NewWrapper(); String *call; String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); call = Swig_csuperclass_call(0, basetype, superparms); Printf(w->def, "%s::%s: %s, Swig::Director(self) { }", classname, target, call); Delete(target); @@ -1762,7 +1755,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } diff --git a/SWIG/Source/Modules/python.cxx b/SWIG/Source/Modules/python.cxx index 1327a3d3b..37a183322 100644 --- a/SWIG/Source/Modules/python.cxx +++ b/SWIG/Source/Modules/python.cxx @@ -2362,7 +2362,7 @@ public: Wrapper *w = NewWrapper(); String *call; String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); call = Swig_csuperclass_call(0, basetype, superparms); Printf(w->def, "%s::%s: %s, Swig::Director(self) { \n", classname, target, call); Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype); @@ -2375,7 +2375,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -3305,20 +3305,14 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - target = Swig_method_decl(decl, qualified_name, l, 0, 0); - String *rtype = SwigType_str(type, 0); - if (Getattr(n, "conversion_operator")) - Printf(w->def, "%s", target); - else - Printf(w->def, "%s %s", rtype, target); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s", target); Delete(qualified_name); Delete(target); /* header declaration */ - target = Swig_method_decl(decl, name, l, 0, 1); - if (Getattr(n, "conversion_operator")) - Printf(declaration, " virtual %s", target); - else - Printf(declaration, " virtual %s %s", rtype, target); + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s", target); Delete(target); // Get any exception classes in the throws typemap @@ -3737,7 +3731,6 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { /* clean up */ Delete(wrap_args); - Delete(rtype); Delete(return_type); Delete(pclassname); DelWrapper(w); diff --git a/SWIG/Source/Modules/ruby.cxx b/SWIG/Source/Modules/ruby.cxx index 1292cfbf0..a3bac2f24 100644 --- a/SWIG/Source/Modules/ruby.cxx +++ b/SWIG/Source/Modules/ruby.cxx @@ -2073,7 +2073,7 @@ public: Wrapper *w = NewWrapper(); String *call; String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); call = Swig_csuperclass_call(0, basetype, superparms); Printf(w->def, "%s::%s: %s, Swig::Director(self) { }", classname, target, call); Delete(target); @@ -2084,7 +2084,7 @@ public: /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); + String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -2264,20 +2264,14 @@ public: String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - target = Swig_method_decl(decl, qualified_name, l, 0, 0); - String *rtype = SwigType_str(type, 0); - if (Getattr(n, "conversion_operator")) - Printf(w->def, "%s", target); - else - Printf(w->def, "%s %s", rtype, target); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s", target); Delete(qualified_name); Delete(target); /* header declaration */ - target = Swig_method_decl(decl, name, l, 0, 1); - if (Getattr(n, "conversion_operator")) - Printf(declaration, " virtual %s", target); - else - Printf(declaration, " virtual %s %s", rtype, target); + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s", target); Delete(target); // Get any exception classes in the throws typemap @@ -2579,7 +2573,6 @@ public: /* clean up */ Delete(wrap_args); - Delete(rtype); Delete(return_type); Delete(pclassname); DelWrapper(w); diff --git a/SWIG/Source/Modules/swigmod.h b/SWIG/Source/Modules/swigmod.h index a95d55f22..7dd8d8c76 100644 --- a/SWIG/Source/Modules/swigmod.h +++ b/SWIG/Source/Modules/swigmod.h @@ -321,7 +321,7 @@ String *Swig_csuperclass_call(String *base, String *method, ParmList *l); String *Swig_class_declaration(Node *n, String *name); String *Swig_class_name(Node *n); String *Swig_method_call(String_or_char *name, ParmList *parms); -String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int strip, int values); +String *Swig_method_decl(SwigType *rtype, SwigType *decl, const String_or_char *id, List *args, int strip, int values); String *Swig_director_declaration(Node *n); /* directors.cxx end */