From cc46b7bb77cd7eb0be7ff8462db88e88b9488a98 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Sun, 24 Dec 2000 04:04:01 +0000 Subject: [PATCH] Numerous bug fixes. Improvements to C++ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@967 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/LParse/cscanner.c | 2 + SWIG/Source/LParse/parser.y | 41 +++---- SWIG/Source/Modules1.1/generate.cxx | 181 +++++++++++++++++++++++----- SWIG/Source/Modules1.1/lang.cxx | 2 +- SWIG/Source/Modules1.1/perl5.cxx | 4 +- SWIG/Source/Modules1.1/perl5.h | 2 +- SWIG/Source/Modules1.1/python.cxx | 4 +- SWIG/Source/Modules1.1/python.h | 4 +- SWIG/Source/Modules1.1/ruby.cxx | 2 +- SWIG/Source/Modules1.1/ruby.h | 2 +- SWIG/Source/Modules1.1/swig11.h | 3 +- SWIG/Source/Modules1.1/tcl8.cxx | 47 ++++++-- SWIG/Source/Modules1.1/tcl8.h | 2 + SWIG/Source/Swig/misc.c | 9 +- SWIG/Source/Swig/stype.c | 24 ++-- SWIG/Source/Swig/swig.h | 13 +- SWIG/Source/Swig/typemap.c | 16 ++- 17 files changed, 255 insertions(+), 103 deletions(-) diff --git a/SWIG/Source/LParse/cscanner.c b/SWIG/Source/LParse/cscanner.c index df4380bdd..95fc4d490 100644 --- a/SWIG/Source/LParse/cscanner.c +++ b/SWIG/Source/LParse/cscanner.c @@ -321,6 +321,8 @@ yylex1(void) { } if ((l1 == STRING) || (l1 == CHARCONST)) { yylval.tok.text = NewString(yytext+1); + Setfile(yylval.tok.text,yylval.tok.filename); + Setline(yylval.tok.text,yylval.tok.line); Delitem(yylval.tok.text,DOH_END); } if ((l1 == HBLOCK) || (l1 == NUM_INT) || (l1 == NUM_FLOAT) || (l1 == NUM_UNSIGNED) || (l1 == NUM_LONG) || (l1 == NUM_ULONG)) { diff --git a/SWIG/Source/LParse/parser.y b/SWIG/Source/LParse/parser.y index 95d1f5392..5c1d19d87 100644 --- a/SWIG/Source/LParse/parser.y +++ b/SWIG/Source/LParse/parser.y @@ -149,23 +149,6 @@ static int pure_virtual = 0; return o; } - /* Take a parameter list and produce a type object */ - static DOH *parmstotype(DOH *parms) { - DOH *p, *r; - DOHList *ty; - - ty = NewList(); - p = parms; - while (p) { - Append(ty,Getattr(p,ATTR_TYPE)); - p = Getattr(p,ATTR_NEXT); - } - r = NewString(""); - SwigType_add_function(r,ty); - Delete(ty); - return r; - } - #ifdef NEED_ALLOC void *alloca(unsigned n) { return((void *) malloc(n)); @@ -428,8 +411,20 @@ scope_directive: SCOPE LBRACE interface RBRACE { } ; -echo_directive: ECHO HBLOCK { Printf(stderr,"%s\n", $2.text); } - | ECHO STRING { Printf(stderr,"%s\n", $2.text); } +echo_directive: ECHO HBLOCK { + char line[32]; + sprintf(line,"%d",Getline($2.text)); + Replace($2.text,"$file",Getfile($2.text),DOH_REPLACE_ANY); + Replace($2.text,"$line",line, DOH_REPLACE_ANY); + Printf(stderr,"%s\n", $2.text); + } + | ECHO STRING { + char line[32]; + sprintf(line,"%d",Getline($2.text)); + Replace($2.text,"$file",Getfile($2.text),DOH_REPLACE_ANY); + Replace($2.text,"$line",line, DOH_REPLACE_ANY); + Printf(stderr,"%s\n", $2.text); + } ; /* -- File inclusion directives -- */ @@ -1050,7 +1045,7 @@ typedef_decl : TYPEDEF type declaration array2 typedeflist SEMI { | TYPEDEF type LPAREN stars pname RPAREN LPAREN parms RPAREN SEMI { $$ = new_node("c:typedef", $1.filename,$1.line); - SwigType_push($2,parmstotype($8)); + SwigType_add_function($2,$8); SwigType_push($2,$4); if ($5.array) SwigType_push($2,$5.array); @@ -1063,7 +1058,7 @@ typedef_decl : TYPEDEF type declaration array2 typedeflist SEMI { | TYPEDEF type stars LPAREN stars pname RPAREN LPAREN parms RPAREN SEMI { $$ = new_node("c:typedef", $1.filename,$1.line); SwigType_push($2,$3); - SwigType_push($2,parmstotype($9)); + SwigType_add_function($2,$9); SwigType_push($2,$5); if ($6.array) SwigType_push($2,$6.array); @@ -1420,7 +1415,7 @@ parm : type pname { } | type LPAREN stars pname RPAREN LPAREN parms RPAREN { $$ = new_node("parm",$2.filename, $2.line); - SwigType_push($1,parmstotype($7)); + SwigType_add_function($1,$7); SwigType_push($1,$3); if ($4.array) SwigType_push($1,$4.array); @@ -1432,7 +1427,7 @@ parm : type pname { | type stars LPAREN stars pname RPAREN LPAREN parms RPAREN { $$ = new_node("parm",$3.filename, $3.line); SwigType_push($1,$2); - SwigType_push($1,parmstotype($8)); + SwigType_add_function($1,$8); SwigType_push($1,$4); if ($5.array) SwigType_push($1,$5.array); diff --git a/SWIG/Source/Modules1.1/generate.cxx b/SWIG/Source/Modules1.1/generate.cxx index b51753192..51b885ed4 100644 --- a/SWIG/Source/Modules1.1/generate.cxx +++ b/SWIG/Source/Modules1.1/generate.cxx @@ -121,6 +121,8 @@ static DOH *class_types = 0; /* Types defined within this class */ static String *construct_name = 0; /* Expected name of a constructor */ int AddMethods = 0; /* Set when in addmethods mode */ int Abstract = 0; /* Set when the class is determined to be abstract */ +static int have_destructor = 0; +static int have_constructor = 0; /* Check for abstract classes */ @@ -162,10 +164,19 @@ void cplus_build_symbols(DOH *node) { return; } +/* Inherit certain types of declarations from another class */ + + + /* Add a class type */ static void -class_addtype(String *name) { - String *s = NewStringf("%s::%s", class_name, name); +class_addtype(String *name, String *cname) { + String *s; + if (!cname) + s = NewStringf("%s::%s", class_name, name); + else + s = NewStringf("%s::%s", cname, name); + if (!class_types) class_types = NewHash(); Setattr(class_types,name,s); } @@ -174,6 +185,7 @@ class_addtype(String *name) { static void class_update_type(String *type) { String *base, *rep; + if (!type) return; base = SwigType_base(type); if (!class_types) return; rep = Getattr(class_types,base); @@ -192,6 +204,54 @@ class_update_parms(ParmList *p) { } } +/* Traverse the inheritance hierarchy of a class */ +void +cplus_walk_inherit(DOH *cls, void (*action)(DOH *base, void *clientdata), void *clientdata) { + DOH *base; + List *bases; + int i, nbase; + + bases = Getattr(cls,"bases"); + if (bases) { + nbase = Len(bases); + for (i = 0; i < nbase; i++) { + base = Getattr(class_hash, Getitem(bases,i)); + if (base) { + (*action)(base,clientdata); + + } + } + } +} + +/* Action for inheriting type definitions */ +static void inherit_types(DOH *cls, void *clientdata) { + DOH *ty; + ty = Getattr(cls,"types"); + if (ty) { + String *key; + SwigType_merge_scope(ty,0); + for (key = Firstkey(ty); key; key = Nextkey(ty)) { + class_addtype(key, Getname(cls)); + } + } + cplus_walk_inherit(cls,inherit_types,clientdata); +} + +/* Action for inheriting typemaps */ +static void inherit_typemaps(DOH *cls, void *clientdata) { + DOH *ty; + + cplus_walk_inherit(cls,inherit_typemaps,clientdata); + ty = Getattr(cls,"typemaps"); + if (ty) { + if (!clientdata) + Swig_typemap_new_scope(ty); + else + Swig_typemap_pop_scope(); + } +} + extern "C" { int swig11_unknown(DOH *node, void *clientdata) { Printf(stdout,"::: Unknown tag - '%s'\n", Getattr(node,"tag")); @@ -241,18 +301,28 @@ int swig11_file(DOH *node, void *clientdata) { int swig11_scope(DOH *node, void *clientdata) { DOH *c; String *name; - int oldnative = Native; + c = Getchild(node); name = Getname(node); - if (name && (Cmp(name,"native") == 0)) { - Native = 1; - Swig_emit_all(c,clientdata); - Native = oldnative; - return 0; + + Swig_typemap_new_scope(0); + if (name) { + if (Cmp(name,"native") == 0) { + int oldnative = Native; + Native = 1; + Swig_emit_all(c,clientdata); + Native = oldnative; + } else if (Cmp(name,"readonly") == 0) { + int oldro = ReadOnly; + ReadOnly = 1; + Swig_emit_all(c,clientdata); + ReadOnly = oldro; + } else { + Swig_emit_all(c,clientdata); + } } - Swig_typemap_new_scope(); - Swig_emit_all(c,clientdata); - Swig_typemap_pop_scope(); + Hash *scp = Swig_typemap_pop_scope(); + Setattr(node,"typemaps", scp); return 0; } @@ -309,10 +379,6 @@ int swig11_pragma(DOH *node, void *clientdata) { name = Getname(node); value = Getvalue(node); - Printf(stdout,"::: Pragma\n"); - Printf(stdout," name = '%s'\n", name); - Printf(stdout," value = '%s'\n", value); - if (Cmp(name,"readonly") == 0) { ReadOnly = 1; } else if (Cmp(name,"readwrite") == 0) { @@ -344,6 +410,11 @@ int swig11_typemap(DOH *node, void *clientdata) { code = Getattr(node,"code"); parms = Getparms(node); + if (current_class) { + class_update_type(type); + class_update_type(parms); + } + if (code) { Swig_typemap_register(method,type,name,code,parms); } else { @@ -451,10 +522,13 @@ int swig11_function(DOH *node, void *clientdata) { if (current_class) { /* Function has been declared inside a class definition. */ class_update_parms(Getparms(node)); + class_update_type(Gettype(node)); String *name = Getname(node); if (Cmp(name,construct_name) == 0) { - if (!Abstract) + have_constructor =1; + if (!Abstract) { lang->cpp_constructor(node); + } } else { if (is_static) lang->cpp_staticfunction(node); else lang->cpp_memberfunction(node); @@ -533,8 +607,10 @@ int swig11_typedef(DOH *node, void *clientdata) { name = Getname(node); SwigType_typedef(type,name); + if (current_class) { + class_addtype(name,0); + } lang->add_typedef(type, Char(name)); - return 0; } @@ -555,7 +631,7 @@ int swig11_enum(DOH *node, void *clientdata) { /* Add a typedef */ String *t = NewStringf("enum %s", name); SwigType_typedef(t,name); - class_addtype(name); + class_addtype(name,0); Delete(t); } c = Getchild(node); @@ -594,6 +670,7 @@ int swig11_enumvalue(DOH *node, void *clientdata) { int swig11_class(DOH *node, void *clientdata) { DOH *c; + List *bases; /* Save the class */ String *name = Getname(node); @@ -607,14 +684,27 @@ int swig11_class(DOH *node, void *clientdata) { set_scriptname(node); class_name = name; + class_types = 0; - /* Create a new type scope for this class */ - - SwigType_new_scope(); + have_destructor = 0; + have_constructor = 0; + + /* Need to merge in data from other scopes. For typemaps, can include scopes + for each base class one after the other. For types, need to merge type information */ + + SwigType_new_scope(); if (name) { SwigType_set_scope_name(name); } - class_types = 0; + + cplus_walk_inherit(node, inherit_types, 0); + + /* Merge in typemaps */ + cplus_walk_inherit(node, inherit_typemaps, 0); + + /* Create a typemap scope for this class */ + Swig_typemap_new_scope(0); + cplus_build_symbols(node); lang->cpp_open_class(node); current_class = node; @@ -629,18 +719,49 @@ int swig11_class(DOH *node, void *clientdata) { Abstract = cplus_check_abstract(c); Swig_emit_all(c,clientdata); - - List *bases = Getattr(node,"bases"); + + bases = Getattr(node,"bases"); if (bases) { - lang->cpp_inherit(bases,INHERIT_ALL); + String *b; + lang->cpp_inherit(bases); + b = Firstitem(bases); + while (b) { + SwigType_inherit(Getname(current_class),b); + b = Nextitem(bases); + } } + + /* Check for constructors and destructors */ + + if (CPlusPlus) { + if (!have_constructor && !Abstract) { + DOH *cn = NewHash(); + Setname(cn, Getname(current_class)); + Setattr(cn,"scriptname", Getname(current_class)); + lang->cpp_constructor(cn); + } + if (!have_destructor) { + DOH *dn = NewHash(); + Setname(dn, Getname(current_class)); + Setattr(dn,"scriptname", Getname(current_class)); + lang->cpp_destructor(dn); + } + } + lang->cpp_close_class(); /* Pop the type scope and save with the class */ - Hash *scp = SwigType_pop_scope(); - Setattr(node,"typescope",scp); - Setattr(node,"types",class_types); + Hash *scp = SwigType_pop_scope(); + Setattr(node,"types",scp); + + scp = Swig_typemap_pop_scope(); + Setattr(node,"typemaps",scp); + Setattr(node,"classtypes",class_types); + + /* Pop off all of the typemap scopes we added */ + cplus_walk_inherit(node,inherit_typemaps, (void *) 1); + current_class = 0; construct_name = 0; class_name = 0; @@ -689,6 +810,7 @@ int swig11_destructor(DOH *node, void *clientdata) { set_scriptname(node); lang->cpp_destructor(node); + have_destructor = 1; return 0; } @@ -780,7 +902,8 @@ void generate(DOH *node) { Swig_emit_all(c,0); lang->close(); - Swig_dump_tags(node,0); + /* Swig_dump_tags(node,0); */ } + diff --git a/SWIG/Source/Modules1.1/lang.cxx b/SWIG/Source/Modules1.1/lang.cxx index 76468a47f..faf69918f 100644 --- a/SWIG/Source/Modules1.1/lang.cxx +++ b/SWIG/Source/Modules1.1/lang.cxx @@ -242,7 +242,7 @@ void Language::cpp_destructor(DOH *node) { * Language::cpp_inherit() * ----------------------------------------------------------------------------- */ -void Language::cpp_inherit(List *bases, int mode) { +void Language::cpp_inherit(List *bases) { if (!bases) return; /* diff --git a/SWIG/Source/Modules1.1/perl5.cxx b/SWIG/Source/Modules1.1/perl5.cxx index 5573b4c96..fb04cafdd 100644 --- a/SWIG/Source/Modules1.1/perl5.cxx +++ b/SWIG/Source/Modules1.1/perl5.cxx @@ -1811,7 +1811,7 @@ PERL5::cpp_staticfunction(DOH *node) { * PERL5::cpp_inherit() * ------------------------------------------------------------------------------ */ void -PERL5::cpp_inherit(List *bases, int) { +PERL5::cpp_inherit(List *bases) { String *base; char *bc; int have_first = 0; @@ -1823,7 +1823,7 @@ PERL5::cpp_inherit(List *bases, int) { /* Inherit variables and constants from base classes, but not functions (since Perl can handle that okay). */ - this->Language::cpp_inherit(bases, INHERIT_CONST | INHERIT_VAR); + this->Language::cpp_inherit(bases); /* Now tell the Perl5 module that we're inheriting from base classes */ diff --git a/SWIG/Source/Modules1.1/perl5.h b/SWIG/Source/Modules1.1/perl5.h index 2d48a8125..90b35f8e6 100644 --- a/SWIG/Source/Modules1.1/perl5.h +++ b/SWIG/Source/Modules1.1/perl5.h @@ -41,7 +41,7 @@ public : virtual void cpp_variable(DOH *); virtual void cpp_constructor(DOH *); virtual void cpp_destructor(DOH *); - virtual void cpp_inherit(List *bases, int mode = INHERIT_ALL); + virtual void cpp_inherit(List *bases); virtual void cpp_constant(DOH *); virtual void cpp_class_decl(DOH *); virtual void add_typedef(SwigType *t, String *name); diff --git a/SWIG/Source/Modules1.1/python.cxx b/SWIG/Source/Modules1.1/python.cxx index 31ec2e84d..c58fae78a 100644 --- a/SWIG/Source/Modules1.1/python.cxx +++ b/SWIG/Source/Modules1.1/python.cxx @@ -1443,7 +1443,7 @@ PYTHON::cpp_close_class() { * PYTHON::cpp_inherit() - Handle inheritance * ----------------------------------------------------------------------------- */ void -PYTHON::cpp_inherit(List *bases,int) { +PYTHON::cpp_inherit(List *bases) { char *bc; String *base; int first_base = 0; @@ -1454,7 +1454,7 @@ PYTHON::cpp_inherit(List *bases,int) { } /* We'll inherit variables and constants, but not methods */ - this->Language::cpp_inherit(bases, INHERIT_VAR); + this->Language::cpp_inherit(bases); if (!bases) return; base_class = NewString(""); diff --git a/SWIG/Source/Modules1.1/python.h b/SWIG/Source/Modules1.1/python.h index d56070dfc..16b0eef1e 100644 --- a/SWIG/Source/Modules1.1/python.h +++ b/SWIG/Source/Modules1.1/python.h @@ -34,7 +34,7 @@ public : virtual void initialize(String *); virtual void function(DOH *node); virtual void variable(DOH *node); - virtual void constant(DOH *node); + virtual void constant(DOH *node); virtual void nativefunction(DOH *); virtual void close(void); virtual void create_command(String *, String *); @@ -47,7 +47,7 @@ public : virtual void cpp_destructor(DOH *); virtual void cpp_open_class(DOH *); virtual void cpp_close_class(); - virtual void cpp_inherit(List *bases, int mode = INHERIT_ALL); + virtual void cpp_inherit(List *bases); virtual void cpp_variable(DOH *); virtual void cpp_constant(DOH *); virtual void cpp_class_decl(DOH *); diff --git a/SWIG/Source/Modules1.1/ruby.cxx b/SWIG/Source/Modules1.1/ruby.cxx index 0513f1b4e..ffb64a876 100644 --- a/SWIG/Source/Modules1.1/ruby.cxx +++ b/SWIG/Source/Modules1.1/ruby.cxx @@ -1220,7 +1220,7 @@ void RUBY::cpp_close_class() { * --------------------------------------------------------------------- */ -void RUBY::cpp_inherit(List *bases, int mode) { +void RUBY::cpp_inherit(List *bases) { if (!bases) return; String *base; for (base = Firstitem(bases); base; base = Nextitem(bases)) { diff --git a/SWIG/Source/Modules1.1/ruby.h b/SWIG/Source/Modules1.1/ruby.h index bd1b026df..8844945ea 100644 --- a/SWIG/Source/Modules1.1/ruby.h +++ b/SWIG/Source/Modules1.1/ruby.h @@ -35,7 +35,7 @@ class RUBY : public Language { virtual void cpp_destructor(DOH *); virtual void cpp_open_class(DOH *); virtual void cpp_close_class(); - virtual void cpp_inherit(List *bases, int mode = INHERIT_ALL); + virtual void cpp_inherit(List *bases); virtual void cpp_variable(DOH *); virtual void cpp_staticfunction(DOH *); virtual void cpp_constant(DOH *); diff --git a/SWIG/Source/Modules1.1/swig11.h b/SWIG/Source/Modules1.1/swig11.h index 57e363ed6..cfc222861 100644 --- a/SWIG/Source/Modules1.1/swig11.h +++ b/SWIG/Source/Modules1.1/swig11.h @@ -79,7 +79,7 @@ public: virtual void cpp_close_class(); virtual void cpp_class_decl(DOH *node); - virtual void cpp_inherit(List *bases, int mode = INHERIT_ALL); + virtual void cpp_inherit(List *bases); /* Miscellaneous features */ @@ -106,6 +106,7 @@ extern void SWIG_config_file(const String_or_char *); /* C++ utility functions */ extern int cplus_check_abstract(DOH *node); +extern void cplus_walk_inherit(DOH *cls, void (*action)(DOH *base, void *clientdata), void *clientdata); extern Language *lang; diff --git a/SWIG/Source/Modules1.1/tcl8.cxx b/SWIG/Source/Modules1.1/tcl8.cxx index cc17274c3..7f2913082 100644 --- a/SWIG/Source/Modules1.1/tcl8.cxx +++ b/SWIG/Source/Modules1.1/tcl8.cxx @@ -40,6 +40,8 @@ static int have_destructor; static String *class_name = 0; static String *class_type = 0; static String *real_classname = 0; +static Hash *class_methods = 0; +static Hash *class_attributes = 0; static Hash *repeatcmd = 0; @@ -97,9 +99,9 @@ TCL8::initialize(String *modname) { mod_init = NewString(""); cmd_info = NewString(""); var_info = NewString(""); - methods = NewString(""); - attributes = NewString(""); repeatcmd = NewHash(); + class_methods = NewHash(); + class_attributes = NewHash(); Swig_banner(f_runtime); @@ -962,13 +964,13 @@ TCL8::cpp_open_class(DOH *node) { included_object = 1; } - Clear(attributes); - Printf(attributes, "static swig_attribute swig_"); - Printv(attributes, classname, "_attributes[] = {\n", 0); + attributes = NewString(""); + /* Printf(attributes, "static swig_attribute swig_"); + Printv(attributes, classname, "_attributes[] = {\n", 0); */ - Clear(methods); - Printf(methods,"static swig_method swig_"); - Printv(methods, classname, "_methods[] = {\n", 0); + methods = NewString(""); + /* Printf(methods,"static swig_method swig_"); + Printv(methods, classname, "_methods[] = {\n", 0); */ have_constructor = 0; have_destructor = 0; @@ -1003,12 +1005,18 @@ TCL8::cpp_close_class() { Printf(code,"}\n"); } - Printf(methods, " {0,0}\n};\n"); + Printf(code,"static swig_method swig_"); + Printv(code, real_classname, "_methods[] = {\n", 0); Printv(code,methods,0); + Printf(code, " {0,0}\n};\n"); + Setattr(class_methods,real_classname,methods); - Printf(attributes, " {0,0,0}\n};\n"); + Printf(code, "static swig_attribute swig_"); + Printv(code, real_classname, "_attributes[] = {\n", 0); Printv(code,attributes,0); - + Printf(code, " {0,0,0}\n};\n"); + Setattr(class_attributes,real_classname,attributes); + Printv(code, "static swig_class _wrap_class_", class_name, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",",0); @@ -1093,3 +1101,20 @@ TCL8::cpp_destructor(DOH *node) { this->Language::cpp_destructor(node); have_destructor = 1; } + +void +TCL8::cpp_inherit(List *bases) { + String *b; + Printf(stdout,"bases = %s\n", bases); + for (b = Firstitem(bases); b; b = Nextitem(bases)) { + Printf(stdout,"base: %s\n", b); + String *s = Getattr(class_methods,b); + if (s) { + Append(methods,s); + } + s = Getattr(class_attributes,b); + if (s) { + Append(attributes,s); + } + } +} diff --git a/SWIG/Source/Modules1.1/tcl8.h b/SWIG/Source/Modules1.1/tcl8.h index 8e5701c79..4bafbab6e 100644 --- a/SWIG/Source/Modules1.1/tcl8.h +++ b/SWIG/Source/Modules1.1/tcl8.h @@ -42,6 +42,8 @@ public : virtual void cpp_variable(DOH *); virtual void cpp_constructor(DOH *); virtual void cpp_destructor(DOH *); + virtual void cpp_inherit(List *bases); + }; diff --git a/SWIG/Source/Swig/misc.c b/SWIG/Source/Swig/misc.c index b86d5af79..7899e4e37 100644 --- a/SWIG/Source/Swig/misc.c +++ b/SWIG/Source/Swig/misc.c @@ -171,23 +171,16 @@ Swig_proto_cmp(const String_or_char *pat, DOH *node) { SwigType *ty; SwigType *ct; ParmList *p; - List *tl; int r; ty = Gettype(node); p = Getparms(node); if (!ty || !p) return -1; ct = Copy(ty); - tl = NewList(); - while (p) { - Append(tl,Gettype(p)); - p = Getnext(p); - } - SwigType_add_function(ct,tl); + SwigType_add_function(ct,p); SwigType_strip_qualifiers(ct); r = Cmp(pat,ct); Delete(ct); - Delete(tl); return r; } diff --git a/SWIG/Source/Swig/stype.c b/SWIG/Source/Swig/stype.c index 494ee8a58..64ff0ceab 100644 --- a/SWIG/Source/Swig/stype.c +++ b/SWIG/Source/Swig/stype.c @@ -199,16 +199,16 @@ SwigType_add_qualifier(SwigType *t, String *qual) { * ----------------------------------------------------------------------------- */ void -SwigType_add_function(SwigType *t, List *parms) { +SwigType_add_function(SwigType *t, ParmList *parms) { String *pstr; - int i,l; Insert(t,0,")."); pstr = NewString("f("); - l = Len(parms); - for (i = 0; i < l; i++) { - Printf(pstr,"%s",Getitem(parms,i)); - if (i < (l-1)) + + while (parms) { + Printf(pstr,"%s",Gettype(parms)); + parms = Getnext(parms); + if (parms) Putc(',',pstr); } Insert(t,0,pstr); @@ -1107,7 +1107,7 @@ int SwigType_typedef(SwigType *type, String_or_char *name) { qname = NewString(name); while (i >= 0) { String *sname; - Printf(stdout,"Adding typedef [%d] : '%s' -> '%s'\n", i, qname, type); + /* Printf(stdout,"Adding typedef [%d] : '%s' -> '%s'\n", i, qname, type); */ Setattr(scopes[i],qname,type); if (i > 0) { sname = scopenames[i]; @@ -1177,7 +1177,7 @@ void SwigType_set_scope_name(String_or_char *name) { * Merges the contents of one scope into the current scope. * ----------------------------------------------------------------------------- */ -void SwigType_merge_scope(Hash *scope, String_or_char *prefix) { +void SwigType_merge_scope(Hash *scope, String *prefix) { String *name; String *key; String *type; @@ -1191,7 +1191,7 @@ void SwigType_merge_scope(Hash *scope, String_or_char *prefix) { } else { name = NewString(key); } - Setattr(scopes[scope_level],name,type); + SwigType_typedef(type,name); key = Nextkey(scope); } } @@ -1209,9 +1209,9 @@ Hash *SwigType_pop_scope() { if (scope_level == 0) return 0; prefix = scopenames[scope_level]; s = scopes[scope_level--]; - /* SwigType_merge_scope(s,prefix); */ - /* Printf(stdout,"****\n%s\n", scopes[scope_level]); */ - return s; + if (Len(s)) return s; + Delete(s); + return 0; } /* ----------------------------------------------------------------------------- diff --git a/SWIG/Source/Swig/swig.h b/SWIG/Source/Swig/swig.h index d81f030c4..f1bebc566 100644 --- a/SWIG/Source/Swig/swig.h +++ b/SWIG/Source/Swig/swig.h @@ -29,6 +29,9 @@ typedef DOH Hash; typedef DOH List; typedef DOH String_or_char; typedef DOH File; +typedef DOH Parm; +typedef DOH ParmList; +typedef DOH Node; /* --- Legacy DataType interface. These type codes are provided solely for backwards compatibility with older modules --- */ @@ -167,7 +170,7 @@ extern void SwigType_del_pointer(SwigType *t); extern void SwigType_add_array(SwigType *t, String_or_char *size); extern void SwigType_add_reference(SwigType *t); extern void SwigType_add_qualifier(SwigType *t, String_or_char *qual); -extern void SwigType_add_function(SwigType *t, List *parms); +extern void SwigType_add_function(SwigType *t, ParmList *parms); extern List *SwigType_split(SwigType *t); extern String *SwigType_pop(SwigType *t); extern void SwigType_push(SwigType *t, SwigType *s); @@ -195,7 +198,7 @@ extern void SwigType_inherit(String *subclass, String *baseclass); extern void SwigType_new_scope(); extern void SwigType_reset_scopes(); extern void SwigType_set_scope_name(String_or_char *name); -extern void SwigType_merge_scope(Hash *scope, String_or_char *prefix); +extern void SwigType_merge_scope(Hash *scope, String *prefix); extern Hash *SwigType_pop_scope(); extern SwigType *SwigType_typedef_resolve(SwigType *t); extern SwigType *SwigType_typedef_resolve_all(SwigType *t); @@ -215,12 +218,10 @@ extern void SwigType_strip_qualifiers(SwigType *t); /* Parameters are really just hidden behind a DOH object. The following interface will probably be simplified even further. */ -typedef DOH Parm; - extern Parm *NewParm(SwigType *type, String_or_char *n); extern Parm *CopyParm(Parm *p); -typedef DOH ParmList; + extern ParmList *CopyParmList(ParmList *); extern int ParmList_len(ParmList *); @@ -391,7 +392,7 @@ extern void Swig_typemap_clear_apply(SwigType *type, String_or_char *pname); extern void Swig_typemap_debug(); extern Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, String_or_char *pname); extern char *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_char *pname, String_or_char *source, String_or_char *target, Wrapper *f); -extern void Swig_typemap_new_scope(); +extern void Swig_typemap_new_scope(Hash *); extern Hash *Swig_typemap_pop_scope(); /* --- Legacy %except directive API --- */ diff --git a/SWIG/Source/Swig/typemap.c b/SWIG/Source/Swig/typemap.c index 20cacab83..3d68dd4fd 100644 --- a/SWIG/Source/Swig/typemap.c +++ b/SWIG/Source/Swig/typemap.c @@ -45,9 +45,14 @@ static char *parm_key(String_or_char *pname) { * Create a new typemap scope * ----------------------------------------------------------------------------- */ -void Swig_typemap_new_scope() { +void Swig_typemap_new_scope(Hash *oldscope) { tm_scope++; - typemaps[tm_scope] = NewHash(); + if (!oldscope) { + typemaps[tm_scope] = NewHash(); + } else { + typemaps[tm_scope] = oldscope; + DohIncref(oldscope); + } } /* ----------------------------------------------------------------------------- @@ -59,7 +64,12 @@ void Swig_typemap_new_scope() { Hash * Swig_typemap_pop_scope() { if (tm_scope > 0) { - return Swig_temp_result(typemaps[tm_scope--]); + if (Len(typemaps[tm_scope])) { + return typemaps[tm_scope--]; + } else { + Delete(typemaps[tm_scope--]); + return 0; + } } return 0; }