From d85b463e0bd39ce5866c249db429bab815e34c08 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 18 Nov 2003 20:21:39 +0000 Subject: [PATCH] Common director support functions moved to new file directors.cxx git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5335 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Makefile.am | 1 + Source/Modules/directors.cxx | 246 ++++++++++++++++++++++++++++++ Source/Modules/java.cxx | 50 +----- Source/Modules/ocaml.cxx | 15 +- Source/Modules/python.cxx | 255 +------------------------------ Source/Modules/ruby.cxx | 287 +++-------------------------------- 6 files changed, 279 insertions(+), 575 deletions(-) create mode 100644 Source/Modules/directors.cxx diff --git a/Source/Makefile.am b/Source/Makefile.am index 0a2492ace..c0c30b03c 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -45,6 +45,7 @@ eswig_SOURCES = CParse/cscanner.c \ Modules/chicken.cxx \ Modules/contract.cxx \ Modules/csharp.cxx \ + Modules/directors.cxx \ Modules/emit.cxx \ Modules/guile.cxx \ Modules/java.cxx \ diff --git a/Source/Modules/directors.cxx b/Source/Modules/directors.cxx new file mode 100644 index 000000000..19384c12a --- /dev/null +++ b/Source/Modules/directors.cxx @@ -0,0 +1,246 @@ +/* ----------------------------------------------------------------------------- + * directors.cxx + * + * Director support functions. + * + * Not all of these may be necessary, and some may duplicate existing functionality + * in SWIG. --MR + * + * Author(s) : Mark Rose + * + * Copyright (C) 1999-2000. The University of Chicago + * See the file LICENSE for information on usage and redistribution. + * ----------------------------------------------------------------------------- */ + +char cvsroot_directors_cxx[] = "$Header"; + +#include "swigmod.h" + +/* Swig_csuperclass_call() + * + * Generates a fully qualified method call, including the full parameter list. + * e.g. "base::method(i, j)" + * + */ + +String *Swig_csuperclass_call(String* base, String* method, ParmList* l) { + String *call = NewString(""); + Parm *p; + if (base) { + Printf(call, "%s::", base); + } + Printf(call, "%s(", method); + for (p=l; p; p = nextSibling(p)) { + String *pname = Getattr(p, "name"); + if (p != l) Printf(call, ", "); + Printv(call, pname, NIL); + } + Printf(call, ")"); + return call; +} + +/* Swig_class_declaration() + * + * Generate the start of a class/struct declaration. + * e.g. "class myclass" + * + */ + +String *Swig_class_declaration(Node *n, String *name) { + if (!name) { + name = Getattr(n, "sym:name"); + } + String *result = NewString(""); + String *kind = Getattr(n, "kind"); + Printf(result, "%s %s", kind, name); + return result; +} + +String *Swig_class_name(Node *n) { + String *name; + name = Copy(Getattr(n, "sym:name")); + return name; +} + +/* Swig_director_declaration() + * + * Generate the full director class declaration, complete with base classes. + * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" + * + */ + +String *Swig_director_declaration(Node *n) { + String* classname = Swig_class_name(n); + String *directorname = NewStringf("SwigDirector_%s", classname); + 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); + return declaration; +} + + +String *Swig_method_call(String_or_char *name, ParmList *parms) { + String *func; + int i = 0; + int comma = 0; + Parm *p = parms; + SwigType *pt; + String *nname; + + func = NewString(""); + nname = SwigType_namestr(name); + Printf(func,"%s(", nname); + while (p) { + String *pname; + pt = Getattr(p,"type"); + if ((SwigType_type(pt) != T_VOID)) { + if (comma) Printf(func,","); + pname = Getattr(p, "name"); + Printf(func,"%s", pname); + comma = 1; + i++; + } + p = nextSibling(p); + } + Printf(func,")"); + return func; +} + +/* Swig_method_decl + * + * Misnamed and misappropriated! Taken from SWIG's type string manipulation utilities + * and modified to generate full (or partial) type qualifiers for method declarations, + * local variable declarations, and return value casting. More importantly, it merges + * parameter type information with actual parameter names to produce a complete method + * declaration that fully mirrors the original method declaration. + * + * There is almost certainly a saner way to do this. + * + * This function needs to be cleaned up and possibly split into several smaller + * functions. For instance, attaching default names to parameters should be done in a + * separate function. + * + */ + +String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int strip, int values) { + String *result; + List *elements; + String *element = 0, *nextelement; + int is_const = 0; + int nelements, i; + int is_func = 0; + int arg_idx = 0; + + if (id) { + result = NewString(Char(id)); + } else { + result = NewString(""); + } + + elements = SwigType_split(s); + nelements = Len(elements); + if (nelements > 0) { + element = Getitem(elements, 0); + } + for (i = 0; i < nelements; i++) { + if (i < (nelements - 1)) { + nextelement = Getitem(elements, i+1); + } else { + nextelement = 0; + } + if (SwigType_isqualifier(element)) { + int skip = 0; + DOH *q = 0; + if (!strip) { + q = SwigType_parm(element); + if (!Cmp(q, "const")) { + is_const = 1; + is_func = SwigType_isfunction(nextelement); + if (is_func) skip = 1; + skip = 1; + } + if (!skip) { + Insert(result,0," "); + Insert(result,0,q); + } + 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; + Append(result,"("); + parm = args; + while (parm != 0) { + String *type = Getattr(parm, "type"); + String* name = Getattr(parm, "name"); + if (!name && Cmp(type, "void")) { + name = NewString(""); + Printf(name, "arg%d", arg_idx++); + Setattr(parm, "name", name); + } + if (!name) { + name = NewString(""); + } + p = SwigType_str(type, name); + Append(result,p); + String* value = Getattr(parm, "value"); + if (values && (value != 0)) { + Printf(result, " = %s", value); + } + parm = nextSibling(parm); + if (parm != 0) Append(result,", "); + } + Append(result,")"); + } else { + 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, " "); + Append(result, "const"); + } else { + Insert(result, 0, "const "); + } + } + Chop(result); + return result; +} + diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 84ff1b18c..db6425b77 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -22,48 +22,6 @@ char cvsroot_java_cxx[] = "$Header$"; /* Hash type used for JNI upcall data */ typedef DOH UpcallData; -extern SwigType *cplus_value_type(SwigType *t); - -/* External functions borrowed from python.cxx module: */ - -extern String *Swig_csuperclass_call(String* base, String* method, ParmList* l); -extern String *Swig_class_declaration(Node *n, String *name); -extern String *Swig_class_name(Node *n); -extern String *Swig_director_declaration(Node *n); -extern String *Swig_method_call(String_or_char *name, ParmList *parms); -extern String *method_decl(SwigType *s, const String_or_char *id, List *args, int strip, int values); - -/* ----------------------------------------------------------------------------- -* SwigType_director_type() -* -* Generate the director type name for a given input type, class and director -* class names. -* ----------------------------------------------------------------------------- */ - -String * SwigType_director_type(String *intype, String *classname, String *director_classname) { - String *base_type = SwigType_base(intype); - String *director_type = SwigType_typedef_resolve(base_type); - int is_pointer = SwigType_ispointer(intype); - String *retval; - - if (director_type == NULL) - director_type = Copy(intype); - - if (SwigType_isreference(director_type)) - SwigType_del_reference(director_type); - if (!is_pointer) - SwigType_add_pointer(director_type); - - Replaceall(director_type, classname, director_classname); - retval = SwigType_str(director_type, ""); - - Delete(base_type); - Delete(director_type); - - return retval; -} - -//------------------------------------------------------------------------ class JAVA : public Language { static const char *usage; @@ -2877,14 +2835,14 @@ class JAVA : public Language { /* header declaration, start wrapper definition */ String *target; - target = method_decl(decl, qualified_name, l, 0, 0); + target = Swig_method_decl(decl, qualified_name, l, 0, 0); String *rtype = SwigType_str(type, 0); Printf(w->def, "%s %s", rtype, target); Delete(qualified_name); Delete(target); - target = method_decl(decl, name, l, 0, 1); + target = Swig_method_decl(decl, name, l, 0, 1); Printf(declaration, " virtual %s %s", rtype, target); Delete(rtype); Delete(target); @@ -3087,7 +3045,7 @@ class JAVA : public Language { /* constructor */ { String *basetype = Getattr(parent, "classtype"); - String *target = method_decl(decl, classname, parms, 0, 0); + String *target = Swig_method_decl(decl, classname, parms, 0, 0); String *call = Swig_csuperclass_call(0, basetype, superparms); String *classtype = SwigType_namestr(Getattr(n, "name")); String *dirclass_type = SwigType_namestr(Getattr(n, "sym:name")); @@ -3103,7 +3061,7 @@ class JAVA : public Language { /* constructor header */ { - String *target = method_decl(decl, classname, parms, 0, 1); + String *target = Swig_method_decl(decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 8fa1a0173..3e248b351 100755 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -64,13 +64,6 @@ static File *f_class_ctors_end = 0; static File *f_enum_to_int = 0; static File *f_int_to_enum = 0; -extern String *method_decl(SwigType *s, const String_or_char *id, List *args, - int strip, int values); -extern String *Swig_method_call(String_or_char *name, ParmList *parms); -extern String *Swig_csuperclass_call(String* base, String* method, - ParmList* l); -extern String *Swig_class_declaration(Node *n, String *name); - class OCAML : public Language { public: @@ -1353,13 +1346,13 @@ public: String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - target = method_decl(decl, qualified_name, l, 0, 0); + target = Swig_method_decl(decl, qualified_name, l, 0, 0); String *rtype = SwigType_str(type, 0); Printf(w->def, "%s %s {", rtype, target); Delete(qualified_name); Delete(target); /* header declaration */ - target = method_decl(decl, name, l, 0, 1); + target = Swig_method_decl(decl, name, l, 0, 1); Printf(declaration, " virtual %s %s;\n", rtype, target); Delete(target); @@ -1636,7 +1629,7 @@ public: Wrapper *w = NewWrapper(); String *call; String *basetype = Getattr(parent, "classtype"); - String *target = method_decl(decl, classname, parms, + String *target = Swig_method_decl(decl, classname, parms, 0, 0); call = Swig_csuperclass_call(0, basetype, superparms); Printf( w->def, @@ -1650,7 +1643,7 @@ public: /* constructor header */ { - String *target = method_decl(decl, classname, + String *target = Swig_method_decl(decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index dbc927508..9a4ffd162 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -19,253 +19,6 @@ char cvsroot_python_cxx[] = "$Header$"; #include -/********************************************************************************** - * - * TYPE UTILITY FUNCTIONS - * - * These ultimately belong elsewhere, but for now I'm leaving them here to - * make it easier to keep an eye on them during testing. Not all of these may - * be necessary, and some may duplicate existing functionality in SWIG. --MR - * - **********************************************************************************/ - -/* Swig_csuperclass_call() - * - * Generates a fully qualified method call, including the full parameter list. - * e.g. "base::method(i, j)" - * - */ - -String *Swig_csuperclass_call(String* base, String* method, ParmList* l) { - String *call = NewString(""); - Parm *p; - if (base) { - Printf(call, "%s::", base); - } - Printf(call, "%s(", method); - for (p=l; p; p = nextSibling(p)) { - String *pname = Getattr(p, "name"); - if (p != l) Printf(call, ", "); - Printv(call, pname, NIL); - } - Printf(call, ")"); - return call; -} - -/* Swig_class_declaration() - * - * Generate the start of a class/struct declaration. - * e.g. "class myclass" - * - */ - -String *Swig_class_declaration(Node *n, String *name) { - if (!name) { - name = Getattr(n, "sym:name"); - } - String *result = NewString(""); - String *kind = Getattr(n, "kind"); - Printf(result, "%s %s", kind, name); - return result; -} - -String *Swig_class_name(Node *n) { - String *name; - name = Copy(Getattr(n, "sym:name")); - return name; -} - -/* Swig_director_declaration() - * - * Generate the full director class declaration, complete with base classes. - * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" - * - */ - -String *Swig_director_declaration(Node *n) { - String* classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); - 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); - return declaration; -} - - -String * -Swig_method_call(String_or_char *name, ParmList *parms) { - String *func; - int i = 0; - int comma = 0; - Parm *p = parms; - SwigType *pt; - String *nname; - - func = NewString(""); - nname = SwigType_namestr(name); - Printf(func,"%s(", nname); - while (p) { - String *pname; - pt = Getattr(p,"type"); - if ((SwigType_type(pt) != T_VOID)) { - if (comma) Printf(func,","); - pname = Getattr(p, "name"); - Printf(func,"%s", pname); - comma = 1; - i++; - } - p = nextSibling(p); - } - Printf(func,")"); - return func; -} - -/* method_decl - * - * Misnamed and misappropriated! Taken from SWIG's type string manipulation utilities - * and modified to generate full (or partial) type qualifiers for method declarations, - * local variable declarations, and return value casting. More importantly, it merges - * parameter type information with actual parameter names to produce a complete method - * declaration that fully mirrors the original method declaration. - * - * There is almost certainly a saner way to do this. - * - * This function needs to be cleaned up and possibly split into several smaller - * functions. For instance, attaching default names to parameters should be done in a - * separate function. - * - */ - -String *method_decl(SwigType *s, const String_or_char *id, List *args, int strip, int values) { - String *result; - List *elements; - String *element = 0, *nextelement; - int is_const = 0; - int nelements, i; - int is_func = 0; - int arg_idx = 0; - - if (id) { - result = NewString(Char(id)); - } else { - result = NewString(""); - } - - elements = SwigType_split(s); - nelements = Len(elements); - if (nelements > 0) { - element = Getitem(elements, 0); - } - for (i = 0; i < nelements; i++) { - if (i < (nelements - 1)) { - nextelement = Getitem(elements, i+1); - } else { - nextelement = 0; - } - if (SwigType_isqualifier(element)) { - int skip = 0; - DOH *q = 0; - if (!strip) { - q = SwigType_parm(element); - if (!Cmp(q, "const")) { - is_const = 1; - is_func = SwigType_isfunction(nextelement); - if (is_func) skip = 1; - skip = 1; - } - if (!skip) { - Insert(result,0," "); - Insert(result,0,q); - } - 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; - Append(result,"("); - parm = args; - while (parm != 0) { - String *type = Getattr(parm, "type"); - String* name = Getattr(parm, "name"); - if (!name && Cmp(type, "void")) { - name = NewString(""); - Printf(name, "arg%d", arg_idx++); - Setattr(parm, "name", name); - } - if (!name) { - name = NewString(""); - } - p = SwigType_str(type, name); - Append(result,p); - String* value = Getattr(parm, "value"); - if (values && (value != 0)) { - Printf(result, " = %s", value); - } - parm = nextSibling(parm); - if (parm != 0) Append(result,", "); - } - Append(result,")"); - } else { - 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, " "); - Append(result, "const"); - } else { - Insert(result, 0, "const "); - } - } - Chop(result); - return result; -} - - -/********************************************************************************** - * - * END OF TYPE UTILITY FUNCTIONS - * - **********************************************************************************/ - - #define PYSHADOW_MEMBER 0x2 static String *const_code = 0; @@ -1401,13 +1154,13 @@ public: String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - target = method_decl(decl, qualified_name, l, 0, 0); + target = Swig_method_decl(decl, qualified_name, l, 0, 0); String *rtype = SwigType_str(type, 0); Printf(w->def, "%s %s {", rtype, target); Delete(qualified_name); Delete(target); /* header declaration */ - target = method_decl(decl, name, l, 0, 1); + target = Swig_method_decl(decl, name, l, 0, 1); Printf(declaration, " virtual %s %s;\n", rtype, target); Delete(target); @@ -1730,7 +1483,7 @@ public: Wrapper *w = NewWrapper(); String *call; String *basetype = Getattr(parent, "classtype"); - String *target = method_decl(decl, classname, parms, 0, 0); + String *target = Swig_method_decl(decl, classname, parms, 0, 0); call = Swig_csuperclass_call(0, basetype, superparms); Printf(w->def, "%s::%s: %s, Swig::Director(self, disown) { }", classname, target, call); Delete(target); @@ -1741,7 +1494,7 @@ public: /* constructor header */ { - String *target = method_decl(decl, classname, parms, 0, 1); + String *target = Swig_method_decl(decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index a54efa342..175c6e498 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -22,268 +22,6 @@ char cvsroot_ruby_cxx[] = "$Header$"; #include #include /* for INT_MAX */ -/********************************************************************************** - * - * TYPE UTILITY FUNCTIONS - * - * These ultimately belong elsewhere, but for now I'm leaving them here to - * make it easier to keep an eye on them during testing. Not all of these may - * be necessary, and some may duplicate existing functionality in SWIG. --MR - * - **********************************************************************************/ - -/* Swig_csuperclass_call() - * - * Generates a fully qualified method call, including the full parameter list. - * e.g. "base::method(i, j)" - * - */ - -static String *Swig_csuperclass_call(String* base, String* method, ParmList* l) { - String *call = NewString(""); - Parm *p; - if (base) { - Printf(call, "%s::", base); - } - Printf(call, "%s(", method); - for (p=l; p; p = nextSibling(p)) { - String *pname = Getattr(p, "name"); - if (p != l) Printf(call, ", "); - Printv(call, pname, NIL); - } - Printf(call, ")"); - return call; -} - -/* Swig_class_declaration() - * - * Generate the start of a class/struct declaration. - * e.g. "class myclass" - * - */ - -static String *Swig_class_declaration(Node *n, String *name) { - if (!name) { - name = Getattr(n, "sym:name"); - } - String *result = NewString(""); - String *kind = Getattr(n, "kind"); - Printf(result, "%s %s", kind, name); - return result; -} - -static String *Swig_class_name(Node *n) { - String *name; - name = Copy(Getattr(n, "sym:name")); - return name; -} - -/* Swig_director_declaration() - * - * Generate the full director class declaration, complete with base classes. - * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" - * - */ - -static String *Swig_director_declaration(Node *n) { - String* classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); - 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); - return declaration; -} - - -static String *Swig_method_call(String_or_char *name, ParmList *parms) { - String *func; - int i = 0; - int comma = 0; - Parm *p = parms; - SwigType *pt; - String *nname; - - func = NewString(""); - nname = SwigType_namestr(name); - Printf(func,"%s(", nname); - while (p) { - String *pname; - pt = Getattr(p,"type"); - if ((SwigType_type(pt) != T_VOID)) { - if (comma) Printf(func,","); - pname = Getattr(p, "name"); - Printf(func,"%s", pname); - comma = 1; - i++; - } - p = nextSibling(p); - } - Printf(func,")"); - return func; -} - -/* method_decl - * - * Misnamed and misappropriated! Taken from SWIG's type string manipulation utilities - * and modified to generate full (or partial) type qualifiers for method declarations, - * local variable declarations, and return value casting. More importantly, it merges - * parameter type information with actual parameter names to produce a complete method - * declaration that fully mirrors the original method declaration. - * - * There is almost certainly a saner way to do this. - * - * This function needs to be cleaned up and possibly split into several smaller - * functions. For instance, attaching default names to parameters should be done in a - * separate function. - * - */ - -static String *method_decl(SwigType *s, const String_or_char *id, List *args, int strip, int values) { - String *result; - List *elements; - String *element = 0, *nextelement; - int is_const = 0; - int nelements, i; - int is_func = 0; - int arg_idx = 0; - - if (id) { - result = NewString(Char(id)); - } else { - result = NewString(""); - } - - elements = SwigType_split(s); - nelements = Len(elements); - if (nelements > 0) { - element = Getitem(elements, 0); - } - for (i = 0; i < nelements; i++) { - if (i < (nelements - 1)) { - nextelement = Getitem(elements, i+1); - } else { - nextelement = 0; - } - if (SwigType_isqualifier(element)) { - int skip = 0; - DOH *q = 0; - if (!strip) { - q = SwigType_parm(element); - if (!Cmp(q, "const")) { - is_const = 1; - is_func = SwigType_isfunction(nextelement); - if (is_func) skip = 1; - skip = 1; - } - if (!skip) { - Insert(result,0," "); - Insert(result,0,q); - } - 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; - Append(result,"("); - parm = args; - while (parm != 0) { - String *type = Getattr(parm, "type"); - String* name = Getattr(parm, "name"); - if (!name && Cmp(type, "void")) { - name = NewString(""); - Printf(name, "arg%d", arg_idx++); - Setattr(parm, "name", name); - } - if (!name) { - name = NewString(""); - } - p = SwigType_str(type, name); - Append(result,p); - String* value = Getattr(parm, "value"); - if (values && (value != 0)) { - Printf(result, " = %s", value); - } - parm = nextSibling(parm); - if (parm != 0) Append(result,", "); - } - Append(result,")"); - } else { - 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, " "); - Append(result, "const"); - } else { - Insert(result, 0, "const "); - } - } - Chop(result); - return result; -} - - -static void -Swig_typemap_copy_pname_to_lname(ParmList *parms) -{ - Parm *p; - String *pname; - String *lname; - - p = parms; - while (p) { - pname = Getattr(p,"name"); - lname = Copy(pname); - Setattr(p,"lname",lname); - p = nextSibling(p); - } -} - - -/********************************************************************************** - * - * END OF TYPE UTILITY FUNCTIONS - * - **********************************************************************************/ - class RClass { private: String *temp; @@ -2098,7 +1836,7 @@ public: Wrapper *w = NewWrapper(); String *call; String *basetype = Getattr(parent, "classtype"); - String *target = method_decl(decl, classname, parms, 0, 0); + String *target = Swig_method_decl(decl, classname, parms, 0, 0); call = Swig_csuperclass_call(0, basetype, superparms); Printf(w->def, "%s::%s: %s, Swig::Director(self, disown) { }", classname, target, call); Delete(target); @@ -2109,7 +1847,7 @@ public: /* constructor header */ { - String *target = method_decl(decl, classname, parms, 0, 1); + String *target = Swig_method_decl(decl, classname, parms, 0, 1); Printf(f_directors_h, " %s;\n", target); Delete(target); } @@ -2278,13 +2016,13 @@ public: String *target; String *pclassname = NewStringf("SwigDirector_%s", classname); String *qualified_name = NewStringf("%s::%s", pclassname, name); - target = method_decl(decl, qualified_name, l, 0, 0); + target = Swig_method_decl(decl, qualified_name, l, 0, 0); String *rtype = SwigType_str(type, 0); Printf(w->def, "%s %s {", rtype, target); Delete(qualified_name); Delete(target); /* header declaration */ - target = method_decl(decl, name, l, 0, 1); + target = Swig_method_decl(decl, name, l, 0, 1); Printf(declaration, " virtual %s %s;\n", rtype, target); Delete(target); @@ -2298,7 +2036,7 @@ public: * the right thing when it sees strings like "$1" in your "directorin" typemaps. * Not sure if it's OK to leave it like this, but seems OK so far. */ - Swig_typemap_copy_pname_to_lname(l); + typemap_copy_pname_to_lname(l); Swig_typemap_attach_parms("in", l, w); Swig_typemap_attach_parms("directorin", l, w); @@ -2548,6 +2286,21 @@ public: virtual int classDirectorDisown(Node *n) { return Language::classDirectorDisown(n); } + + void typemap_copy_pname_to_lname(ParmList *parms) + { + Parm *p; + String *pname; + String *lname; + + p = parms; + while (p) { + pname = Getattr(p,"name"); + lname = Copy(pname); + Setattr(p,"lname",lname); + p = nextSibling(p); + } + } }; /* class RUBY */ /* -----------------------------------------------------------------------------