From 7a77a7feb9c83164478d36eac20659d12aaef89e Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Sun, 27 Nov 2005 02:58:24 +0000 Subject: [PATCH] several clean/speed ups git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7887 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/cwrap.c | 18 ++--- Source/Swig/fragment.c | 6 +- Source/Swig/misc.c | 7 +- Source/Swig/parms.c | 12 +-- Source/Swig/stype.c | 16 ++-- Source/Swig/symbol.c | 148 +++++++++++++++++++------------------ Source/Swig/tree.c | 5 +- Source/Swig/typemap.c | 161 +++++++++++++++++++++++------------------ Source/Swig/typeobj.c | 2 +- Source/Swig/typesys.c | 4 +- Source/Swig/wrapfunc.c | 6 +- 11 files changed, 209 insertions(+), 176 deletions(-) diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index c64d66213..5011aca07 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -254,7 +254,7 @@ String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_ch } /* Now print out function call */ - Printv(fcall,decl,NIL); + Append(fcall,decl); /* A sick hack */ { @@ -333,7 +333,7 @@ Swig_cfunction_call(String_or_char *name, ParmList *parms) { } p = nextSibling(p); } - Printf(func,")"); + Append(func,")"); return func; } @@ -403,7 +403,7 @@ Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self) { } p = nextSibling(p); } - Printf(func,")"); + Append(func,")"); Delete(nname); return func; } @@ -555,7 +555,7 @@ Swig_unref_call(Node *n) { Node *cn = Swig_methodclass(n); String* unref = Swig_rflag_search(cn,"feature:unref","feature:nounref"); if (unref) { - unref = NewStringf("%s",unref); + unref = NewString(unref); Replaceall(unref,"$this",Swig_cparm_name(0,0)); Replaceall(unref,"$self",Swig_cparm_name(0,0)); } @@ -573,7 +573,7 @@ Swig_ref_call(Node *n, const String* lname) { Node *cn = Swig_methodclass(n); String* ref = Swig_rflag_search(cn,"feature:ref","feature:noref"); if (ref) { - ref = NewStringf("%s",ref); + ref = NewString(ref); Replaceall(ref,"$this",lname); Replaceall(ref,"$self",lname); } @@ -815,14 +815,14 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) { if ((SwigType_type(pt) != T_VOID)) { String *pname = Swig_cparm_name(pp,i++); String *rcaststr = SwigType_rcaststr(pt, pname); - Printf(func,"%s", rcaststr); + Append(func,rcaststr); Delete(rcaststr); Delete(pname); pp = nextSibling(pp); if (pp) Append(func,","); } } - Printf(func,")"); + Append(func,")"); Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", func)); } else { Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", Swig_cfunction_call(mangled,p))); @@ -993,7 +993,7 @@ Swig_ConstructorToFunction(Node *n, String *classname, * implemented in the target language, calls to those methods will * generate Swig::DirectorPureVirtualException exceptions. */ - Printv(action, Swig_cresult(type, "result", director_call), NIL); + Append(action, Swig_cresult(type, "result", director_call)); } else { /* (scottm): The code for creating a new director is now a string template that gets passed in via the director_ctor argument. @@ -1002,7 +1002,7 @@ Swig_ConstructorToFunction(Node *n, String *classname, $director_new: Call new for director class $nondirector_new: Call new for non-director class */ - Printv(action, director_ctor, NIL); + Append(action, director_ctor); Replaceall( action, "$comparison", tmp_none_comparison); Replaceall( action, "$director_new", Swig_cresult(type, "result", director_call) ); diff --git a/Source/Swig/fragment.c b/Source/Swig/fragment.c index c23957621..0c1e13920 100644 --- a/Source/Swig/fragment.c +++ b/Source/Swig/fragment.c @@ -40,7 +40,7 @@ Swig_fragment_register(Node* fragment) { if (type) { SwigType *rtype = SwigType_typedef_resolve_all(type); String *mangle = Swig_string_mangle(rtype); - Printf(name,"%s",mangle); + Append(name,mangle); Delete(mangle); Delete(rtype); } @@ -107,8 +107,8 @@ Swig_fragment_emit(Node *n) { pc = char_index(tok,','); if (pc) *pc = 0; while (tok) { - String *name = NewStringf("%s", tok); - if (mangle) Printf(name,"%s",mangle); + String *name = NewString(tok); + if (mangle) Append(name,mangle); code = Getattr(fragments,name); if (debug) Printf(stdout,"looking subfragment %s\n", name); if (code && (Strcmp(code,"ignore") != 0)) { diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index d889e6143..295b9e06d 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -170,7 +170,7 @@ String *Swig_string_typecode(String *s) { Putc(c,tc); } str = SwigType_str(tc,0); - Printf(ns,"%s",str); + Append(ns,str); Delete(str); } else { Putc(c,ns); @@ -251,7 +251,7 @@ String *Swig_string_mangle(const String *s) { if (isalnum((int)c) || (c == '_')) { state = 1; if (space && (space == state)) { - Printf(result,"_SS_"); + Append(result,"_SS_"); } space = 0; Printf(result,"%c",(int)c); @@ -587,4 +587,7 @@ Swig_init() { /* Initialize type system */ SwigType_typesystem_init(); + /* Initialize template system */ + SwigType_template_init(); + } diff --git a/Source/Swig/parms.c b/Source/Swig/parms.c index 645c872a1..73daa16df 100644 --- a/Source/Swig/parms.c +++ b/Source/Swig/parms.c @@ -195,10 +195,10 @@ String *ParmList_str(ParmList *p) { String *out = NewString(""); while(p) { String *pstr = SwigType_str(Getattr(p,"type"), Getattr(p,"name")); - Printf(out,"%s", pstr); + Append(out,pstr); p = nextSibling(p); if (p) { - Printf(out,","); + Append(out,","); } Delete(pstr); } @@ -216,13 +216,13 @@ String *ParmList_str_defaultargs(ParmList *p) { while(p) { String *value = Getattr(p,"value"); String *pstr = SwigType_str(Getattr(p,"type"), Getattr(p,"name")); - Printf(out,"%s", pstr); + Append(out,pstr); if (value) { Printf(out,"=%s", value); } p = nextSibling(p); if (p) { - Printf(out,","); + Append(out,","); } Delete(pstr); } @@ -242,10 +242,10 @@ String *ParmList_protostr(ParmList *p) { p = nextSibling(p); } else { String *pstr = SwigType_str(Getattr(p,"type"), 0); - Printf(out,"%s", pstr); + Append(out,pstr); p = nextSibling(p); if (p) { - Printf(out,","); + Append(out,","); } Delete(pstr); } diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 0a0a7b7a4..a392209f6 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -395,7 +395,7 @@ SwigType *SwigType_default(SwigType *t) { SwigType *nr = Copy(r); SwigType_del_pointer(nr); def = SwigType_isfunction(nr) ? - NewStringf("") : NewStringf("p."); + NewString("") : NewString("p."); SwigType_add_default(def, nr); Delete(nr); #else @@ -407,7 +407,7 @@ SwigType *SwigType_default(SwigType *t) { #ifdef SWIG_NEW_TYPE_DEFAULT SwigType *nr = Copy(r); SwigType_del_reference(nr); - def = NewStringf("r."); + def = NewString("r."); SwigType_add_default(def, nr); Delete(nr); #else @@ -894,7 +894,7 @@ String *SwigType_lcaststr(SwigType *s, const String_or_char *name) { Printf(result,"(%s)", str); Delete(str); if (name) - Printv(result,name,NIL); + Append(result,name); } else if (SwigType_isqualifier(s)) { Printf(result,"(%s)%s", SwigType_lstr(s,0),name); } else { @@ -1006,10 +1006,10 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) { List *tparms = SwigType_parmlist(e); int j; String *nt = SwigType_templateprefix(e); - Printv(nt,"<(",NIL); + Append(nt,"<("); for (j = 0; j < Len(tparms); j++) { SwigType_typename_replace(Getitem(tparms,j), pat, rep); - Printv(nt,Getitem(tparms,j),NIL); + Append(nt,Getitem(tparms,j)); if (j < (Len(tparms)-1)) Putc(',',nt); } tsuffix = SwigType_templatesuffix(e); @@ -1035,13 +1035,13 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) { int j; List *fparms = SwigType_parmlist(e); Clear(e); - Printv(e,"f(",NIL); + Append(e,"f("); for (j = 0; j < Len(fparms); j++) { SwigType_typename_replace(Getitem(fparms,j), pat, rep); - Printv(e,Getitem(fparms,j),NIL); + Append(e,Getitem(fparms,j)); if (j < (Len(fparms)-1)) Putc(',',e); } - Printv(e,").",NIL); + Append(e,")."); Delete(fparms); } else if (SwigType_isarray(e)) { Replace(e,pat,rep, DOH_REPLACE_ID); diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 2d99f8f07..52bc2e5f6 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -175,30 +175,33 @@ static Hash *symtabs = 0; /* Hash of all symbol tables by fully-qualifie static Hash *global_scope = 0; /* Global scope */ /* common attribute keys, to avoid calling find_key all the times */ -static String *k_name = 0; -static String *k_coloncolon = 0; -static String *k_decl = 0; static String *k_cdecl = 0; -static String *k_uname = 0; -static String *k_type = 0; -static String *k_templateparms = 0; -static String *k_symtab = 0; -static String *k_csymtab = 0; -static String *k_using = 0; -static String *k_inherit = 0; -static String *k_value = 0; -static String *k_symboltable = 0; -static String *k_storage = 0; -static String *k_typedef = 0; -static String *k_symname = 0; -static String *k_symsymtab = 0; -static String *k_sympreviousSibling = 0; -static String *k_symnextSibling = 0; -static String *k_symovername = 0; -static String *k_symoverloaded = 0; -static String *k_csympreviousSibling = 0; +static String *k_coloncolon = 0; +static String *k_constructor = 0; static String *k_csymnextSibling = 0; +static String *k_csympreviousSibling = 0; +static String *k_csymtab = 0; +static String *k_decl = 0; static String *k_enumitem = 0; +static String *k_inherit = 0; +static String *k_name = 0; +static String *k_nodetype = 0; +static String *k_parentnode = 0; +static String *k_storage = 0; +static String *k_symboltable = 0; +static String *k_symname = 0; +static String *k_symnextSibling = 0; +static String *k_symoverloaded = 0; +static String *k_symovername = 0; +static String *k_sympreviousSibling = 0; +static String *k_symsymtab = 0; +static String *k_symtab = 0; +static String *k_templateparms = 0; +static String *k_type = 0; +static String *k_typedef = 0; +static String *k_uname = 0; +static String *k_using = 0; +static String *k_value = 0; #if 0 @@ -224,30 +227,33 @@ Swig_symbol_dump_symtable() { void Swig_symbol_init() { - k_name = NewString("name"); - k_coloncolon = NewString("::"); - k_decl = NewString("decl"); k_cdecl = NewString("cdecl"); - k_uname = NewString("uname"); - k_type = NewString("type"); - k_templateparms = NewString("templateparms"); - k_symtab = NewString("symtab"); - k_symsymtab = NewString("sym:symtab"); - k_csymtab = NewString("csymtab"); - k_using = NewString("using"); - k_inherit = NewString("inherit"); - k_value = NewString("value"); - k_symboltable = NewString("symboltable"); - k_storage = NewString("storage"); - k_typedef = NewString("typedef"); - k_symname = NewString("sym:name"); - k_sympreviousSibling = NewString("sym:previousSibling"); - k_symnextSibling = NewString("sym:nextSibling"); - k_symovername = NewString("sym:overname"); - k_symoverloaded = NewString("sym:overloaded"); - k_csympreviousSibling = NewString("csym:previousSibling"); + k_coloncolon = NewString("::"); + k_constructor = NewString("constructor"); k_csymnextSibling = NewString("csym:nextSibling"); + k_csympreviousSibling = NewString("csym:previousSibling"); + k_csymtab = NewString("csymtab"); + k_decl = NewString("decl"); k_enumitem = NewString("enumitem"); + k_inherit = NewString("inherit"); + k_name = NewString("name"); + k_nodetype = NewString("nodeType"); + k_parentnode = NewString("parentNode"); + k_storage = NewString("storage"); + k_symboltable = NewString("symboltable"); + k_symname = NewString("sym:name"); + k_symnextSibling = NewString("sym:nextSibling"); + k_symoverloaded = NewString("sym:overloaded"); + k_symovername = NewString("sym:overname"); + k_sympreviousSibling = NewString("sym:previousSibling"); + k_symsymtab = NewString("sym:symtab"); + k_symtab = NewString("symtab"); + k_templateparms = NewString("templateparms"); + k_type = NewString("type"); + k_typedef = NewString("typedef"); + k_uname = NewString("uname"); + k_using = NewString("using"); + k_value = NewString("value"); current = NewHash(); current_symtab = NewHash(); @@ -320,7 +326,7 @@ Swig_symbol_qualifiedscopename(Symtab *symtab) { Hash *parent; String *name; if (!symtab) symtab = current_symtab; - parent = parentNode(symtab); + parent = Getattr(symtab,k_parentnode); if (parent) { result = Swig_symbol_qualifiedscopename(parent); } @@ -330,9 +336,9 @@ Swig_symbol_qualifiedscopename(Symtab *symtab) { result = NewString(""); } if (Len(result)) { - Printf(result,"::%s",name); + Printv(result,"::",name, NIL); } else { - Printf(result,"%s",name); + Append(result,name); } } return result; @@ -398,7 +404,7 @@ Swig_symbol_setscope(Symtab *sym) { Symtab * Swig_symbol_popscope() { Hash *h = current_symtab; - current_symtab = parentNode(current_symtab); + current_symtab = Getattr(current_symtab, k_parentnode); assert(current_symtab); current = Getattr(current_symtab,k_symtab); assert(current); @@ -589,7 +595,7 @@ Swig_symbol_cadd(String_or_char *name, Node *n) { String *st = Getattr(td1,k_type); String *sn = Getattr(td,k_name); if (st && sn && (Strcmp(st, sn) == 0)) { - Symtab *sc = parentNode(current_symtab); + Symtab *sc = Getattr(current_symtab,k_parentnode); if (sc) td1 = Swig_symbol_clookup(type,sc); } } @@ -945,7 +951,7 @@ symbol_lookup_qualified(String_or_char *name, Symtab *symtab, String *prefix, in Delete(qname); if (!n) { if (!local) { - Node *pn = parentNode(symtab); + Node *pn = Getattr(symtab,k_parentnode); if (pn) n = symbol_lookup_qualified(name,pn, prefix, local,checkfunc); } else { n = 0; @@ -971,7 +977,7 @@ Swig_symbol_clookup(String_or_char *name, Symtab *n) { if (!n) { hsym = current_symtab; } else { - if (Strcmp(nodeType(n),k_symboltable)) { + if (!checkAttribute(n,k_nodetype,k_symboltable)) { n = Getattr(n,k_symsymtab); } assert(n); @@ -1002,7 +1008,7 @@ Swig_symbol_clookup(String_or_char *name, Symtab *n) { while (hsym) { s = symbol_lookup(name,hsym,0); if (s) break; - hsym = parentNode(hsym); + hsym = Getattr(hsym,k_parentnode); if (!hsym) break; } } @@ -1010,7 +1016,7 @@ Swig_symbol_clookup(String_or_char *name, Symtab *n) { return 0; } /* Check if s is a 'using' node */ - while (s && Strcmp(nodeType(s),k_using) == 0) { + while (s && checkAttribute(s,k_nodetype,k_using)) { String *uname = Getattr(s,k_uname); Symtab *un = Getattr(s,k_symsymtab); Node *ss = (Strcmp(name,uname) || (un != n)) ? @@ -1041,7 +1047,7 @@ Swig_symbol_clookup_check(String_or_char *name, Symtab *n, int (*checkfunc)(Node if (!n) { hsym = current_symtab; } else { - if (Strcmp(nodeType(n),k_symboltable)) { + if (!checkAttribute(n,k_nodetype,k_symboltable)) { n = Getattr(n,k_symsymtab); } assert(n); @@ -1072,7 +1078,7 @@ Swig_symbol_clookup_check(String_or_char *name, Symtab *n, int (*checkfunc)(Node while (hsym) { s = symbol_lookup(name,hsym,checkfunc); if (s) break; - hsym = parentNode(hsym); + hsym = Getattr(hsym,k_parentnode); if (!hsym) break; } } @@ -1080,7 +1086,7 @@ Swig_symbol_clookup_check(String_or_char *name, Symtab *n, int (*checkfunc)(Node return 0; } /* Check if s is a 'using' node */ - while (s && Strcmp(nodeType(s),k_using) == 0) { + while (s && checkAttribute(s,k_nodetype,k_using)) { Node *ss; ss = Swig_symbol_clookup(Getattr(s,k_uname), Getattr(s,k_symsymtab)); if (!ss && !checkfunc) { @@ -1104,7 +1110,7 @@ Swig_symbol_clookup_local(String_or_char *name, Symtab *n) { hsym = current_symtab; h = ccurrent; } else { - if (Strcmp(nodeType(n),k_symboltable)) { + if (!checkAttribute(n,k_nodetype,k_symboltable)) { n = Getattr(n,k_symsymtab); } assert(n); @@ -1128,7 +1134,7 @@ Swig_symbol_clookup_local(String_or_char *name, Symtab *n) { } if (!s) return 0; /* Check if s is a 'using' node */ - while (s && Strcmp(nodeType(s),k_using) == 0) { + while (s && checkAttribute(s,k_nodetype,k_using)) { Node *ss = Swig_symbol_clookup_local(Getattr(s,k_uname), Getattr(s,k_symsymtab)); if (!ss) { Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,k_uname)); @@ -1151,7 +1157,7 @@ Swig_symbol_clookup_local_check(String_or_char *name, Symtab *n, int (*checkfunc hsym = current_symtab; h = ccurrent; } else { - if (Strcmp(nodeType(n),k_symboltable)) { + if (!checkAttribute(n,k_nodetype,k_symboltable)) { n = Getattr(n,k_symsymtab); } assert(n); @@ -1175,7 +1181,7 @@ Swig_symbol_clookup_local_check(String_or_char *name, Symtab *n, int (*checkfunc } if (!s) return 0; /* Check if s is a 'using' node */ - while (s && Strcmp(nodeType(s),k_using) == 0) { + while (s && checkAttribute(s,k_nodetype,k_using)) { Node *ss = Swig_symbol_clookup_local_check(Getattr(s,k_uname), Getattr(s,k_symsymtab),checkfunc); if (!ss && !checkfunc) { Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,k_uname)); @@ -1287,7 +1293,7 @@ Swig_symbol_remove(Node *n) { String * Swig_symbol_qualified(Node *n) { Hash *symtab; - if (Strcmp(nodeType(n),k_symboltable) == 0) { + if (checkAttribute(n,k_nodetype,k_symboltable)) { symtab = n; } else { symtab = Getattr(n,k_symsymtab); @@ -1317,11 +1323,10 @@ Swig_symbol_isoverloaded(Node *n) { * ----------------------------------------------------------------------------- */ static int no_constructor(Node *n) { - SwigType *type = nodeType(n); #ifdef SWIG_DEBUG Printf(stderr,"node type %s\n", Getattr(n,k_name), type); #endif - return type ? (Strcmp(type,"constructor") != 0): 1; + return !checkAttribute(n, k_nodetype, k_constructor); } static SwigType * @@ -1493,7 +1498,7 @@ SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab) SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) { SwigType *prefix, *base; Node *n; - + String *nt; base = SwigType_base(ty); prefix = SwigType_prefix(ty); @@ -1517,7 +1522,8 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) { return Copy(ty); } } - if (Strcmp(nodeType(n),k_using) == 0) { + nt = Getattr(n,k_nodetype); + if (Strcmp(nt,k_using) == 0) { String *uname = Getattr(n,k_uname); if (uname) { n = Swig_symbol_clookup(base,Getattr(n,k_symsymtab)); @@ -1531,7 +1537,7 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) { } } } - if (Strcmp(nodeType(n),k_cdecl) == 0) { + if (Strcmp(nt,k_cdecl) == 0) { String *storage = Getattr(n,k_storage); if (storage && (Strcmp(storage,k_typedef) == 0)) { SwigType *decl; @@ -1802,7 +1808,8 @@ SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab) if (n == lastnode) break; lastnode = n; if (n) { - if (Strcmp(nodeType(n),k_enumitem) == 0) { + String *nt = Getattr(n,k_nodetype); + if (Strcmp(nt,k_enumitem) == 0) { /* An enum item. Generate a fully qualified name */ String *qn = Swig_symbol_qualified(n); if (Len(qn)) { @@ -1815,10 +1822,13 @@ SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab) Delete(qn); break; } - } else if ((Strcmp(nodeType(n),k_cdecl) == 0) && (Getattr(n,k_value))) { - Delete(value); - value = Copy(Getattr(n,k_value)); - continue; + } else if ((Strcmp(nt,k_cdecl) == 0)) { + String *nv = Getattr(n,k_value); + if (nv) { + Delete(value); + value = Copy(nv); + continue; + } } } break; diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index c52d5c3f6..1350d7ad4 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -222,10 +222,9 @@ Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) { int checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) { - String *v; - v = Getattr(n,name); + String *v = Getattr(n,name); if (!v) return 0; - if (Cmp(v,value) == 0) return 1; + if (Equal(v,value)) return 1; return 0; } diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index c5d2ae965..44c2f655e 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -85,6 +85,16 @@ static void set_typemap(int tm_scope, SwigType* type, Hash* tm) * * Initialize the typemap system * ----------------------------------------------------------------------------- */ +static String *k_type = 0; +static String *k_code = 0; +static String *k_name = 0; +static String *k_lname = 0; +static String *k_locals = 0; +static String *k_value = 0; +static String *k_tmapmatch = 0; +static String *k_kwargs = 0; +static String *k_SWIGTYPE = 0; +static String *k_one = 0; void Swig_typemap_init() { int i; @@ -93,6 +103,17 @@ void Swig_typemap_init() { } typemaps[0] = NewHash(); tm_scope = 0; + + k_type = NewString("type"); + k_code = NewString("code"); + k_name = NewString("name"); + k_lname = NewString("lname"); + k_locals = NewString("locals"); + k_value = NewString("value"); + k_tmapmatch = NewString("tmap:match"); + k_SWIGTYPE = NewString("SWIGTYPE"); + k_kwargs = NewString("kwargs"); + k_one = NewString("1"); } static String *tmop_name(const String_or_char *op) { @@ -166,8 +187,8 @@ Swig_typemap_register(const String_or_char *op, ParmList *parms, String_or_char /* Register the first type in the parameter list */ - type = Getattr(parms,"type"); - pname = Getattr(parms,"name"); + type = Getattr(parms,k_type); + pname = Getattr(parms,k_name); /* See if this type has been seen before */ tm = get_typemap(tm_scope,type); @@ -234,14 +255,14 @@ Swig_typemap_register(const String_or_char *op, ParmList *parms, String_or_char ParmList *clocals = CopyParmList(locals); ParmList *ckwargs = CopyParmList(kwargs); - Setattr(tm2,"code", code); - Setattr(tm2,"type", type); + Setattr(tm2,k_code, code); + Setattr(tm2,k_type, type); Setattr(tm2,"typemap", typemap); if (pname) { Setattr(tm2,"pname", pname); } - Setattr(tm2,"locals", clocals); - Setattr(tm2,"kwargs", ckwargs); + Setattr(tm2,k_locals, clocals); + Setattr(tm2,k_kwargs, ckwargs); Delete(clocals); Delete(ckwargs); @@ -295,8 +316,8 @@ Swig_typemap_copy(const String_or_char *op, ParmList *srcparms, ParmList *parms) p = srcparms; tmops = NewString(tmop); while (p) { - ptype = Getattr(p,"type"); - pname = Getattr(p,"name"); + ptype = Getattr(p,k_type); + pname = Getattr(p,k_name); /* Lookup the type */ tm = Swig_typemap_get(ptype,pname,ts); @@ -316,7 +337,7 @@ Swig_typemap_copy(const String_or_char *op, ParmList *srcparms, ParmList *parms) if (!p && tm) { /* Got some kind of match */ - Swig_typemap_register(op,parms, Getattr(tm,"code"), Getattr(tm,"locals"),Getattr(tm,"kwargs")); + Swig_typemap_register(op,parms, Getattr(tm,k_code), Getattr(tm,k_locals),Getattr(tm,k_kwargs)); return 0; } ts--; @@ -344,8 +365,8 @@ Swig_typemap_clear(const String_or_char *op, ParmList *parms) { newop = NewString(op); p = parms; while (p) { - type = Getattr(p,"type"); - name = Getattr(p,"name"); + type = Getattr(p,k_type); + name = Getattr(p,k_name); tm = Swig_typemap_get(type,name,tm_scope); if (!tm) return; p = nextSibling(p); @@ -355,9 +376,9 @@ Swig_typemap_clear(const String_or_char *op, ParmList *parms) { if (tm) { tm = Getattr(tm, tmop_name(newop)); if (tm) { - Delattr(tm,"code"); - Delattr(tm,"locals"); - Delattr(tm,"kwargs"); + Delattr(tm,k_code); + Delattr(tm,k_locals); + Delattr(tm,k_kwargs); } } Delete(newop); @@ -405,8 +426,8 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { lastdp = dp; np = nextSibling(p); if (np) { - Printf(ssig,"-%s+%s:", Getattr(p,"type"), Getattr(p,"name")); - Printf(dsig,"-%s+%s:", Getattr(dp,"type"), Getattr(dp,"name")); + Printf(ssig,"-%s+%s:", Getattr(p,k_type), Getattr(p,k_name)); + Printf(dsig,"-%s+%s:", Getattr(dp,k_type), Getattr(dp,k_name)); narg++; } p = np; @@ -414,14 +435,14 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { } /* make sure a typemap node exists for the last destination node */ - type = Getattr(lastdp,"type"); + type = Getattr(lastdp,k_type); tm = get_typemap(tm_scope,type); if (!tm) { tm = NewHash(); set_typemap(tm_scope,type,tm); Delete(tm); } - name = Getattr(lastdp,"name"); + name = Getattr(lastdp,k_name); if (name) { Hash *tm1 = Getattr(tm,name); if (!tm1) { @@ -435,8 +456,8 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { /* This is a little nasty. We need to go searching for all possible typemaps in the source and apply them to the target */ - type = Getattr(lastp,"type"); - name = Getattr(lastp,"name"); + type = Getattr(lastp,k_type); + name = Getattr(lastp,k_name); while (ts >= 0) { @@ -473,15 +494,15 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { /* Make sure the typemap doesn't already exist in the target map */ oldm = Getattr(tm,nkey); - if (!oldm || (!Getattr(tm,"code"))) { + if (!oldm || (!Getattr(tm,k_code))) { String *code; ParmList *locals; ParmList *kwargs; Hash *sm1 = ki.item; - code = Getattr(sm1,"code"); - locals = Getattr(sm1,"locals"); - kwargs = Getattr(sm1,"kwargs"); + code = Getattr(sm1,k_code); + locals = Getattr(sm1,k_locals); + kwargs = Getattr(sm1,k_kwargs); if (code) { Replace(nkey,dsig,"", DOH_REPLACE_ANY); Replace(nkey,"tmap:","", DOH_REPLACE_ANY); @@ -522,17 +543,17 @@ Swig_typemap_clear_apply(Parm *parms) { lastp = p; np = nextSibling(p); if (np) { - Printf(tsig,"-%s+%s:", Getattr(p,"type"), Getattr(p,"name")); + Printf(tsig,"-%s+%s:", Getattr(p,k_type), Getattr(p,k_name)); narg++; } p = np; } - tm = get_typemap(tm_scope,Getattr(lastp,"type")); + tm = get_typemap(tm_scope,Getattr(lastp,k_type)); if (!tm) { Delete(tsig); return; } - name = Getattr(lastp,"name"); + name = Getattr(lastp,k_name); if (name) { tm = Getattr(tm,name); } @@ -600,13 +621,13 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch tm1 = Getattr(tm,cname); if (tm1) { result = Getattr(tm1,tmop); /* See if there is a type-name match */ - if (result && Getattr(result,"code")) goto ret_result; + if (result && Getattr(result,k_code)) goto ret_result; if (result) backup = result; } } if (tm) { result = Getattr(tm,tmop); /* See if there is simply a type match */ - if (result && Getattr(result,"code")) goto ret_result; + if (result && Getattr(result,k_code)) goto ret_result; if (result) backup = result; } isarray = SwigType_isarray(ctype); @@ -621,13 +642,13 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch tm1 = Getattr(tma,cname); if (tm1) { result = Getattr(tm1,tmop); /* type-name match */ - if (result && Getattr(result,"code")) goto ret_result; + if (result && Getattr(result,k_code)) goto ret_result; if (result) backup = result; } } if (tma) { result = Getattr(tma,tmop); /* type match */ - if (result && Getattr(result,"code")) goto ret_result; + if (result && Getattr(result,k_code)) goto ret_result; if (result) backup = result; } Delete(noarrays); @@ -715,20 +736,20 @@ Swig_typemap_search_multi(const String_or_char *op, ParmList *parms, int *nmatch *nmatch = 0; return 0; } - type = Getattr(parms,"type"); - name = Getattr(parms,"name"); + type = Getattr(parms,k_type); + name = Getattr(parms,k_name); /* Try to find a match on the first type */ tm = Swig_typemap_search(op, type, name, &mtype); if (tm) { if (mtype && SwigType_isarray(mtype)) { - Setattr(parms,"tmap:match", mtype); + Setattr(parms,k_tmapmatch, mtype); } Delete(mtype); newop = NewStringf("%s-%s+%s:", op, type,name); tm1 = Swig_typemap_search_multi(newop, nextSibling(parms), nmatch); if (tm1) tm = tm1; - if (Getattr(tm,"code")) { + if (Getattr(tm,k_code)) { *(nmatch) = *nmatch + 1; } else { tm = 0; @@ -750,7 +771,7 @@ static void replace_local_types(ParmList *p, const String *name, const String *rep) { SwigType *t; while (p) { - t = Getattr(p,"type"); + t = Getattr(p,k_type); Replace(t,name,rep,DOH_REPLACE_ANY); p = nextSibling(p); } @@ -783,7 +804,7 @@ void typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType int rep = 0; p = locals; while (p) { - if (Strchr(Getattr(p,"type"),'$')) rep = 1; + if (Strchr(Getattr(p,k_type),'$')) rep = 1; p = nextSibling(p); } if (!rep) locals = 0; @@ -1067,10 +1088,10 @@ static void typemap_locals(DOHString *s, ParmList *l, Wrapper *f, int argnum) { p = l; while (p) { - SwigType *pt = Getattr(p,"type"); + SwigType *pt = Getattr(p,k_type); SwigType *at = SwigType_alttype(pt, 1); - String *pn = Getattr(p,"name"); - String *value = Getattr(p,"value"); + String *pn = Getattr(p,k_name); + String *value = Getattr(p,k_value); if (at) pt = at; if (pn) { if (Len(pn) > 0) { @@ -1133,7 +1154,7 @@ String *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_ tm = Swig_typemap_search(op,type,pname,&mtype); if (!tm) return 0; - s = Getattr(tm,"code"); + s = Getattr(tm,k_code); if (!s) return 0; /* Blocked */ @@ -1141,7 +1162,7 @@ String *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_ s = Copy(s); /* Make a local copy of the typemap code */ - locals = Getattr(tm,"locals"); + locals = Getattr(tm,k_locals); if (locals) locals = CopyParmList(locals); /* This is wrong. It replaces locals in place. Need to fix this */ @@ -1209,10 +1230,10 @@ String *Swig_typemap_lookup_new(const String_or_char *op, Node *node, const Stri sdef = Swig_ref_call(node, lname); } - type = Getattr(node,"type"); + type = Getattr(node,k_type); if (!type) return sdef; - pname = Getattr(node,"name"); + pname = Getattr(node,k_name); #if 0 /* removed for now as it breaks old code and introduces @@ -1253,7 +1274,7 @@ Printf(stdout, "Swig_typemap_lookup %s [%s %s]\n", op, type, pname ? pname : "NO tm = Swig_typemap_search(op,type,pname,&mtype); if (!tm) return sdef; - s = Getattr(tm,"code"); + s = Getattr(tm,k_code); if (!s) return sdef; /* Empty typemap. No match */ @@ -1261,7 +1282,7 @@ Printf(stdout, "Swig_typemap_lookup %s [%s %s]\n", op, type, pname ? pname : "NO s = Copy(s); /* Make a local copy of the typemap code */ - locals = Getattr(tm,"locals"); + locals = Getattr(tm,k_locals); if (locals) locals = CopyParmList(locals); if (pname) { @@ -1304,16 +1325,16 @@ Printf(stdout, "Swig_typemap_lookup %s [%s %s]\n", op, type, pname ? pname : "NO Delete(locals); } - if (checkAttribute(tm,"type","SWIGTYPE")) { + if (checkAttribute(tm,k_type,k_SWIGTYPE)) { sprintf(temp,"%s:SWIGTYPE", Char(op)); - Setattr(node,tmop_name(temp),"1"); + Setattr(node,tmop_name(temp),k_one); } /* Attach kwargs */ - kw = Getattr(tm,"kwargs"); + kw = Getattr(tm,k_kwargs); while (kw) { - String *value = Copy(Getattr(kw,"value")); - String *type = Getattr(kw,"type"); + String *value = Copy(Getattr(kw,k_value)); + String *type = Getattr(kw,k_type); if (type) { SwigType *rtype = SwigType_typedef_resolve_all(type); String *mangle = Swig_string_mangle(rtype); @@ -1321,7 +1342,7 @@ Printf(stdout, "Swig_typemap_lookup %s [%s %s]\n", op, type, pname ? pname : "NO Delete(mangle); Delete(rtype); } - sprintf(temp,"%s:%s",Char(op),Char(Getattr(kw,"name"))); + sprintf(temp,"%s:%s",Char(op),Char(Getattr(kw,k_name))); Setattr(node,tmop_name(temp), value); kw = nextSibling(kw); } @@ -1372,18 +1393,18 @@ Printf(stdout, "Swig_typemap_lookup %s [%s %s]\n", op, type, pname ? pname : "NO void Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p) { String *temp = NewString(""); - Parm *kw = Getattr(tm,"kwargs"); + Parm *kw = Getattr(tm,k_kwargs); while (kw) { - String *value = Copy(Getattr(kw,"value")); - String *type = Getattr(kw,"type"); + String *value = Copy(Getattr(kw,k_value)); + String *type = Getattr(kw,k_type); if (type) { Hash *v = NewHash(); - Setattr(v,"value",value); - Setattr(v,"type",type); + Setattr(v,k_value,value); + Setattr(v,k_type,type); value = v; } Clear(temp); - Printf(temp,"%s:%s",op,Getattr(kw,"name")); + Printf(temp,"%s:%s",op,Getattr(kw,k_name)); Setattr(p,tmop_name(temp),value); kw = nextSibling(kw); } @@ -1444,7 +1465,7 @@ Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f) p = nextSibling(p); continue; } - s = Getattr(tm,"code"); + s = Getattr(tm,k_code); if (!s) { p = nextSibling(p); continue; @@ -1457,7 +1478,7 @@ Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f) } s = Copy(s); - locals = Getattr(tm,"locals"); + locals = Getattr(tm,k_locals); if (locals) locals = CopyParmList(locals); firstp = p; for (i = 0; i < nmatch; i++) { @@ -1466,21 +1487,21 @@ Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f) String *lname; SwigType *mtype; - type = Getattr(p,"type"); - pname = Getattr(p,"name"); - lname = Getattr(p,"lname"); - mtype = Getattr(p,"tmap:match"); + type = Getattr(p,k_type); + pname = Getattr(p,k_name); + lname = Getattr(p,k_lname); + mtype = Getattr(p,k_tmapmatch); if (mtype) { typemap_replace_vars(s,locals,mtype,type,pname,lname,i+1); - Delattr(p,"tmap:match"); + Delattr(p,k_tmapmatch); } else { typemap_replace_vars(s,locals,type,type,pname,lname,i+1); } - if (checkAttribute(tm,"type","SWIGTYPE")) { + if (checkAttribute(tm,k_type,k_SWIGTYPE)) { sprintf(temp,"%s:SWIGTYPE", Char(op)); - Setattr(p,tmop_name(temp),"1"); + Setattr(p,tmop_name(temp),k_one); } p = nextSibling(p); } @@ -1669,9 +1690,9 @@ static void replace_embedded_typemap(String *s) { set_previousSibling(v,p); } p = v; - Setattr(p,"lname",Getattr(p,"name")); - if (Getattr(p,"value")) { - Setattr(p,"name",Getattr(p,"value")); + Setattr(p,k_lname,Getattr(p,k_name)); + if (Getattr(p,k_value)) { + Setattr(p,k_name,Getattr(p,k_value)); } if (!first) first = p; DohIncref(p); diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 23602e110..2be726401 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -663,7 +663,7 @@ SwigType_add_function(SwigType *t, ParmList *parms) { p = parms; for (p = parms; p; p = nextSibling(p)) { if (p != parms) Putc(',',pstr); - Printv(pstr, Getattr(p,"type"), NIL); + Append(pstr, Getattr(p,"type")); } Insert(t,0,pstr); Delete(pstr); diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 9249653c4..0b0673b3e 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -938,7 +938,7 @@ SwigType *SwigType_typedef_qualified(SwigType *t) tprefix = SwigType_templateprefix(e); tsuffix = SwigType_templatesuffix(e); qprefix = SwigType_typedef_qualified(tprefix); - Printv(qprefix,"<(",NIL); + Append(qprefix,"<("); pi = First(parms); while ((p = pi.item)) { String *qt = SwigType_typedef_qualified(p); @@ -1885,7 +1885,7 @@ SwigType_emit_type_table(File *f_forward, File *f_table) { ln = SwigType_lstr(lt,0); rn = SwigType_lstr(rt,0); if (Strcmp(ln,rn) == 0) { - nt = NewStringf("%s", ln); + nt = NewString(ln); } else { nt = NewStringf("%s|%s", rn, ln); } diff --git a/Source/Swig/wrapfunc.c b/Source/Swig/wrapfunc.c index c6bae881b..95f108eea 100644 --- a/Source/Swig/wrapfunc.c +++ b/Source/Swig/wrapfunc.c @@ -77,7 +77,7 @@ Wrapper_pretty_print(String *str, File *f) { int level = 0; int c, i; int empty = 1; - int indent = 4; + int indent = 2; int plevel = 0; int label = 0; @@ -439,7 +439,7 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) { obj = va_arg(ap,void *); while (obj) { - Printv(decl,obj,NIL); + Append(decl,obj); Putc(' ', decl); obj = va_arg(ap, void *); } @@ -514,7 +514,7 @@ Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) { obj = va_arg(ap,void *); while (obj) { - Printv(decl,obj,NIL); + Append(decl,obj); Putc(' ',decl); obj = va_arg(ap, void *); }