diff --git a/SWIG/Source/CParse/parser.y b/SWIG/Source/CParse/parser.y index a45d0e299..e5f1a9258 100644 --- a/SWIG/Source/CParse/parser.y +++ b/SWIG/Source/CParse/parser.y @@ -87,10 +87,12 @@ static Node *new_node(const String_or_char *tag) { static Node *copy_node(Node *n) { Node *nn; String *key; + Iterator k; nn = NewHash(); Setfile(nn,Getfile(n)); Setline(nn,Getline(n)); - for (key = Firstkey(n); key; key = Nextkey(n)) { + for (k = First(n); k.key; k = Next(k)) { + key = k.key; if ((Strcmp(key,"nextSibling") == 0) || (Strcmp(key,"previousSibling") == 0) || (Strcmp(key,"parentNode") == 0) || @@ -102,7 +104,7 @@ static Node *copy_node(Node *n) { if ((Strcmp(key,"sym:name") == 0) || (Strcmp(key,"sym:weak") == 0) || (Strcmp(key,"sym:typename") == 0)) { - Setattr(nn,key, Copy(Getattr(n,key))); + Setattr(nn,key, Copy(k.item)); continue; } if (Strcmp(key,"sym:symtab") == 0) { @@ -115,7 +117,7 @@ static Node *copy_node(Node *n) { /* If children. We copy them recursively using this function */ if (Strcmp(key,"firstChild") == 0) { /* Copy children */ - Node *cn = Getattr(n,key); + Node *cn = k.item; while (cn) { appendChild(nn,copy_node(cn)); cn = nextSibling(cn); @@ -135,11 +137,11 @@ static Node *copy_node(Node *n) { continue; } if ((Strcmp(key,"parms") == 0) || (Strcmp(key,"pattern") == 0) || (Strcmp(key,"throws") == 0)) { - Setattr(nn,key,CopyParmList(Getattr(n,key))); + Setattr(nn,key,CopyParmList(k.item)); continue; } /* Looks okay. Just copy the data using Copy */ - Setattr(nn, key, Copy(Getattr(n,key))); + Setattr(nn, key, Copy(k.item)); } return nn; } @@ -527,12 +529,12 @@ static void merge_extensions(Node *cls, Node *am) { extensions for templates */ static void check_extensions() { - String *key; + Iterator ki; + if (!extendhash) return; - for (key = Firstkey(extendhash); key; key = Nextkey(extendhash)) { - Node *n = Getattr(extendhash,key); - if (!Strstr(key,"<")) { - Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(n), Getline(n), "%%extend defined for an undeclared class %s.\n", key); + for (ki = First(extendhash); ki.key; ki = Next(ki)) { + if (!Strstr(ki.key,"<")) { + Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(ki.item), Getline(ki.item), "%%extend defined for an undeclared class %s.\n", ki.key); } } } @@ -1851,6 +1853,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va if (ns) { List *scopes; String *sname; + Iterator si; String *name = NewString(prefix); scopes = NewList(); while (name) { @@ -1861,9 +1864,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Delete(name); name = tprefix; } - for (sname = Firstitem(scopes); sname; sname = Nextitem(scopes)) { + for (si = First(scopes); si.item; si = Next(si)) { Node *ns1,*ns2; - + sname = si.item; ns1 = Swig_symbol_clookup(sname,0); assert(ns1); if (Strcmp(nodeType(ns1),"namespace") == 0) { @@ -1987,9 +1990,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va if (baselist) { List *bases = make_inherit_list(Getattr($$,"name"),baselist); if (bases) { - Node *s; - for (s = Firstitem(bases); s; s = Nextitem(bases)) { - Symtab *st = Getattr(s,"symtab"); + Iterator s; + for (s = First(bases); s.item; s = Next(s)) { + Symtab *st = Getattr(s.item,"symtab"); if (st) { Swig_symbol_inherit(st); } @@ -2342,9 +2345,9 @@ cpp_class_decl : Swig_symbol_newscope(); Swig_symbol_setscopename($3); if (bases) { - Node *s; - for (s = Firstitem(bases); s; s = Nextitem(bases)) { - Symtab *st = Getattr(s,"symtab"); + Iterator s; + for (s = First(bases); s.item; s = Next(s)) { + Symtab *st = Getattr(s.item,"symtab"); if (st) { Swig_symbol_inherit(st); } @@ -2714,16 +2717,16 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para } /* Patch argument names with typedef */ { - SwigType *tt; + Iterator tt; List *tparms = SwigType_parmlist(fname); ffname = SwigType_templateprefix(fname); Append(ffname,"<("); - for (tt = Firstitem(tparms); tt; ) { - SwigType *ttr = Swig_symbol_typedef_reduce(tt,0); + for (tt = First(tparms); tt.item; ) { + SwigType *ttr = Swig_symbol_typedef_reduce(tt.item,0); ttr = Swig_symbol_type_qualify(ttr,0); Append(ffname,ttr); - tt = Nextitem(tparms); - if (tt) Putc(',',ffname); + tt = Next(tt); + if (tt.item) Putc(',',ffname); } Append(ffname,")>"); } @@ -2747,16 +2750,16 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para /* This needs to be rewritten */ List *tparms; String *fname; - SwigType *tt; + Iterator tt; fname = SwigType_templateprefix(tname); tparms = SwigType_parmlist(tname); Append(fname,"<("); - for (tt = Firstitem(tparms); tt; ) { - SwigType *ttr = Swig_symbol_typedef_reduce(tt,0); + for (tt = First(tparms); tt.item; ) { + SwigType *ttr = Swig_symbol_typedef_reduce(tt.item,0); ttr = Swig_symbol_type_qualify(ttr,0); Append(fname,ttr); - tt = Nextitem(tparms); - if (tt) Putc(',',fname); + tt = Next(tt); + if (tt.item) Putc(',',fname); } Append(fname,")>"); Swig_symbol_cadd(fname,$$); diff --git a/SWIG/Source/CParse/templ.c b/SWIG/Source/CParse/templ.c index 5739cc2b2..c978a2044 100644 --- a/SWIG/Source/CParse/templ.c +++ b/SWIG/Source/CParse/templ.c @@ -361,11 +361,11 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms) { { List *bases = Getattr(n,"baselist"); if (bases) { - String *b; - for (b = Firstitem(bases); b; b = Nextitem(bases)) { - String *qn = Swig_symbol_type_qualify(b,0); - Clear(b); - Append(b,qn); + Iterator b; + for (b = First(bases); b.item; b = Next(b)) { + String *qn = Swig_symbol_type_qualify(b.item,0); + Clear(b.item); + Append(b.item,qn); } } } @@ -473,12 +473,13 @@ Swig_cparse_template_locate(String *name, Parm *tparms) { char tmp[32]; int i; List *partials; - String *s, *ss; + String *ss; + Iterator pi; partials = Getattr(templ,"partials"); if (partials) { - for (s = Firstitem(partials); s; s= Nextitem(partials)) { - ss = Copy(s); + for (pi = First(partials); pi.item; pi = Next(pi)) { + ss = Copy(pi.item); p = parms; i = 1; while (p) { @@ -497,10 +498,10 @@ Swig_cparse_template_locate(String *name, Parm *tparms) { p = nextSibling(p); } if (template_debug) { - Printf(stdout," searching: '%s' (partial specialization - %s)\n", ss, s); + Printf(stdout," searching: '%s' (partial specialization - %s)\n", ss, pi.item); } if ((Strcmp(ss,tname) == 0) || (Strcmp(ss,rname) == 0)) { - Append(mpartials,s); + Append(mpartials,pi.item); } Delete(ss); } diff --git a/SWIG/Source/DOH/README b/SWIG/Source/DOH/README index 53ac4b705..18ef7da9c 100644 --- a/SWIG/Source/DOH/README +++ b/SWIG/Source/DOH/README @@ -31,6 +31,8 @@ First(obj) Return first object (iterator) Next(obj) Return next object Dump(obj,out) Serialize on out Load(in) Unserialize from in +First(obj) Iterator +Next(iter) Next iterator Mapping Operations (for hash table behavior) -------------------------------------------- diff --git a/SWIG/Source/DOH/base.c b/SWIG/Source/DOH/base.c index c17f32824..0abd6cba4 100644 --- a/SWIG/Source/DOH/base.c +++ b/SWIG/Source/DOH/base.c @@ -192,6 +192,51 @@ DohCmp(const DOH *obj1, const DOH *obj2) { return 1; } +/* ----------------------------------------------------------------------------- + * DohFirst() + * ----------------------------------------------------------------------------- */ + +DohIterator +DohFirst(DOH *obj) { + DohIterator iter; + DohBase *b; + DohObjInfo *binfo; + + b = (DohBase *) obj; + if (DohCheck(b)) { + binfo = b->type; + if (binfo->doh_first) { + return (binfo->doh_first)(b); + } + } + iter.object = 0; + iter.item = 0; + iter.key = 0; + return iter; +} + +/* ----------------------------------------------------------------------------- + * DohNext() + * ----------------------------------------------------------------------------- */ + +DohIterator +DohNext(DohIterator iter) { + DohIterator niter; + + if (iter.object) { + DohBase *b; + DohObjInfo *binfo; + + b = (DohBase *) iter.object; + binfo = b->type; + if (binfo->doh_next) { + return (binfo->doh_next)(iter); + } + } + niter = iter; + return niter; +} + /* ----------------------------------------------------------------------------- * DohIsMapping() * ----------------------------------------------------------------------------- */ @@ -249,35 +294,7 @@ DohDelattr(DOH *obj, const DOH *name) { } /* ----------------------------------------------------------------------------- - * DohFirstkey() - * ----------------------------------------------------------------------------- */ - -DOH * -DohFirstkey(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohObjInfo *objinfo = b->type; - if (objinfo->doh_hash && objinfo->doh_hash->doh_firstkey) { - return (objinfo->doh_hash->doh_firstkey)(b); - } - return 0; -} - -/* ----------------------------------------------------------------------------- - * DohNextkey() - * ----------------------------------------------------------------------------- */ - -DOH * -DohNextkey(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohObjInfo *objinfo = b->type; - if (objinfo && objinfo->doh_hash->doh_nextkey) { - return (objinfo->doh_hash->doh_nextkey)(b); - } - return 0; -} - -/* ----------------------------------------------------------------------------- - * DohNextkey() + * DohKeys() * ----------------------------------------------------------------------------- */ DOH * @@ -474,34 +491,6 @@ DohDelslice(DOH *obj, int sindex, int eindex) { return -1; } -/* ----------------------------------------------------------------------------- - * DohFirstitem() - * ----------------------------------------------------------------------------- */ - -DOH * -DohFirstitem(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohObjInfo *objinfo = b->type; - if (objinfo->doh_list && objinfo->doh_list->doh_firstitem) { - return (objinfo->doh_list->doh_firstitem)(b); - } - return 0; -} - -/* ----------------------------------------------------------------------------- - * DohNextitem() - * ----------------------------------------------------------------------------- */ - -DOH * -DohNextitem(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohObjInfo *objinfo = b->type; - if (objinfo->doh_list && objinfo->doh_list->doh_nextitem) { - return (objinfo->doh_list->doh_nextitem)(b); - } - return 0; -} - /* ----------------------------------------------------------------------------- * DohIsFile() * ----------------------------------------------------------------------------- */ diff --git a/SWIG/Source/DOH/doh.h b/SWIG/Source/DOH/doh.h index b807a4bd5..b3543bf77 100644 --- a/SWIG/Source/DOH/doh.h +++ b/SWIG/Source/DOH/doh.h @@ -44,8 +44,6 @@ #define DohGetattr DOH_NAMESPACE(Getattr) #define DohSetattr DOH_NAMESPACE(Setattr) #define DohDelattr DOH_NAMESPACE(Delattr) -#define DohFirstkey DOH_NAMESPACE(Firstkey) -#define DohNextkey DOH_NAMESPACE(Nextkey) #define DohKeys DOH_NAMESPACE(Keys) #define DohGetInt DOH_NAMESPACE(GetInt) #define DohGetDouble DOH_NAMESPACE(GetDouble) @@ -60,8 +58,6 @@ #define DohDelitem DOH_NAMESPACE(Delitem) #define DohInsertitem DOH_NAMESPACE(Insertitem) #define DohDelslice DOH_NAMESPACE(Delslice) -#define DohFirstitem DOH_NAMESPACE(Firstitem) -#define DohNextitem DOH_NAMESPACE(Nextitem) #define DohWrite DOH_NAMESPACE(Write) #define DohRead DOH_NAMESPACE(Read) #define DohSeek DOH_NAMESPACE(Seek) @@ -113,7 +109,9 @@ #define DohHashType DOH_NAMESPACE(HashType) #define DohFileType DOH_NAMESPACE(FileType) #define DohVoidType DOH_NAMESPACE(VoidType) - +#define DohIterator DOH_NAMESPACE(Iterator) +#define DohFirst DOH_NAMESPACE(First) +#define DohNext DOH_NAMESPACE(Next) #endif #include @@ -143,6 +141,16 @@ typedef void DOH; #define DOH_CUR -3 #define DOH_CURRENT -3 +/* Iterator objects */ + +typedef struct { + void *key; /* Current key (if any) */ + void *item; /* Current item */ + void *object; /* Object being iterated over */ + void *_current; /* Internal use */ + int _index; /* Internal use */ +} DohIterator; + /* Memory management */ #ifndef DohMalloc @@ -176,8 +184,6 @@ extern void DohIncref(DOH *obj); extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name); extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char *value); extern int DohDelattr(DOH *obj, const DOHString_or_char *name); -extern DOH *DohFirstkey(DOH *obj); -extern DOH *DohNextkey(DOH *obj); extern DOH *DohKeys(DOH *obj); extern int DohGetInt(DOH *obj, const DOHString_or_char *name); extern double DohGetDouble(DOH *obj, const DOHString_or_char *name); @@ -194,8 +200,6 @@ extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value extern int DohDelitem(DOH *obj, int index); extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value); extern int DohDelslice(DOH *obj, int sindex, int eindex); -extern DOH *DohFirstitem(DOH *obj); -extern DOH *DohNextitem(DOH *obj); /* File methods */ @@ -207,7 +211,11 @@ extern int DohGetc(DOHFile *obj); extern int DohPutc(int ch, DOHFile *obj); extern int DohUngetc(int ch, DOHFile *obj); - /* Positional */ +/* Iterators */ +extern DohIterator DohFirst(DOH *obj); +extern DohIterator DohNext(DohIterator x); + +/* Positional */ extern int DohGetline(DOH *obj); extern void DohSetline(DOH *obj, int line); @@ -321,8 +329,6 @@ extern void DohMemoryDebug(void); #define Append(s,x) DohInsertitem(s,DOH_END,x) #define Push(s,x) DohInsertitem(s,DOH_BEGIN,x) #define Len DohLen -#define Firstkey DohFirstkey -#define Nextkey DohNextkey #define Data DohData #define Char (char *) Data #define Cmp DohCmp @@ -349,8 +355,6 @@ extern void DohMemoryDebug(void); #define SetDouble DohSetDouble #define SetChar DohSetattr #define SetVoid DohSetVoid -#define Firstitem DohFirstitem -#define Nextitem DohNextitem #define Readline DohReadline #define Replace DohReplace #define Chop DohChop @@ -378,6 +382,9 @@ extern void DohMemoryDebug(void); #define Getmark DohGetmark #define None DohNone #define Call DohCall +#define First DohFirst +#define Next DohNext +#define Iterator DohIterator #endif #ifdef NIL diff --git a/SWIG/Source/DOH/dohint.h b/SWIG/Source/DOH/dohint.h index 5af5f60b1..0c39aec7a 100644 --- a/SWIG/Source/DOH/dohint.h +++ b/SWIG/Source/DOH/dohint.h @@ -29,20 +29,16 @@ typedef struct { DOH *(*doh_getattr)(DOH *obj, DOH *name); /* Get attribute */ int (*doh_setattr)(DOH *obj, DOH *name, DOH *value); /* Set attribute */ int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */ - DOH *(*doh_firstkey)(DOH *obj); /* First key */ - DOH *(*doh_nextkey)(DOH *obj); /* Next key */ DOH *(*doh_keys)(DOH *obj); /* All keys as a list */ } DohHashMethods; /* List objects */ typedef struct { - DOH *(*doh_getitem)(DOH *obj, int index); /* Get item */ - int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */ - int (*doh_delitem)(DOH *obj, int index); /* Delete item */ - int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */ - int (*doh_delslice)(DOH *obj, int sindex, int eindex); /* Delete slice */ - DOH *(*doh_firstitem)(DOH *obj); /* Iterators */ - DOH *(*doh_nextitem)(DOH *obj); + DOH *(*doh_getitem)(DOH *obj, int index); /* Get item */ + int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */ + int (*doh_delitem)(DOH *obj, int index); /* Delete item */ + int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */ + int (*doh_delslice)(DOH *obj, int sindex, int eindex); /* Delete slice */ } DohListMethods; /* File methods */ @@ -87,6 +83,10 @@ typedef struct DohObjInfo { /* Compare */ int (*doh_cmp)(DOH *obj1, DOH *obj2); + /* Iterators */ + DohIterator (*doh_first)(DOH *obj); + DohIterator (*doh_next)(DohIterator ); + /* Positional */ void (*doh_setfile)(DOH *obj, DOHString_or_char *file); DOH *(*doh_getfile)(DOH *obj); @@ -105,14 +105,15 @@ typedef struct { void *data; /* Data pointer */ DohObjInfo *type; void *meta; /* Meta data */ - int flag_intern : 1; /* Interned object */ - int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */ - int flag_user : 1; /* User flag */ - int flag_usermark : 1; /* User marked */ - int refcount : 28; /* Reference count (max 16 million) */ + int flag_intern : 1; /* Interned object */ + int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */ + int flag_user : 1; /* User flag */ + int flag_usermark : 1; /* User marked */ + int refcount : 28; /* Reference count (max 16 million) */ } DohBase; /* Macros for decrefing and increfing (safe for null objects). */ + #define Decref(a) if (a) ((DohBase *) a)->refcount-- #define Incref(a) if (a) ((DohBase *) a)->refcount++ #define Refcount(a) ((DohBase *) a)->refcount @@ -124,7 +125,7 @@ typedef struct { #define ObjType(a) ((DohBase *)a)->type extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */ -extern void DohObjFree(DOH *ptr); /* Free a DOH object */ +extern void DohObjFree(DOH *ptr); /* Free a DOH object */ #endif /* DOHINT_H */ diff --git a/SWIG/Source/DOH/file.c b/SWIG/Source/DOH/file.c index 70e8c3d4e..11b8911aa 100644 --- a/SWIG/Source/DOH/file.c +++ b/SWIG/Source/DOH/file.c @@ -214,6 +214,8 @@ static DohObjInfo DohFileType = { 0, /* doh_len */ 0, /* doh_hash */ 0, /* doh_cmp */ + 0, /* doh_first */ + 0, /* doh_next */ 0, /* doh_setfile */ 0, /* doh_getfile */ 0, /* doh_setline */ diff --git a/SWIG/Source/DOH/hash.c b/SWIG/Source/DOH/hash.c index 4738a2312..7647f363a 100644 --- a/SWIG/Source/DOH/hash.c +++ b/SWIG/Source/DOH/hash.c @@ -28,9 +28,7 @@ typedef struct Hash { int line; HashNode **hashtable; int hashsize; - int currentindex; int nitems; - HashNode *current; } Hash; /* Key interning structure */ @@ -288,11 +286,6 @@ Hash_delattr(DOH *ho, DOH *k) { } else { h->hashtable[hv] = n->next; } - /* Need to check for iterator location */ - if (n == h->current) { - h->current = prev; /* Move back to previous node. When next is called, will move to next node */ - if (!h->current) h->currentindex--; /* No previous node. Move back one slot */ - } DelNode(n); h->nitems--; return 1; @@ -303,63 +296,53 @@ Hash_delattr(DOH *ho, DOH *k) { return 0; } -/* General purpose iterators */ -static HashNode * -hash_first(DOH *ho) { - Hash *h = (Hash *) ObjData(ho); - h->currentindex = 0; - h->current = 0; - while ((h->currentindex < h->hashsize) && !h->hashtable[h->currentindex]) - h->currentindex++; - if (h->currentindex >= h->hashsize) return 0; - h->current = h->hashtable[h->currentindex]; - return h->current; +static DohIterator +Hash_firstiter(DOH *ho) { + DohIterator iter; + Hash *h = (Hash *) ObjData(ho); + iter.object = ho; + iter._current = 0; + iter.item = 0; + iter.key = 0; + iter._index = 0; /* Index in hash table */ + while ((iter._index < h->hashsize) && !h->hashtable[iter._index]) + iter._index++; + + if (iter._index >= h->hashsize) { + return iter; + } + iter._current = h->hashtable[iter._index]; + iter.item = ((HashNode *) iter._current)->object; + iter.key = ((HashNode *) iter._current)->key; + + /* Actually save the next slot in the hash. This makes it possible to + delete the item being iterated over without trashing the universe */ + iter._current = ((HashNode*)iter._current)->next; + return iter; } -static HashNode * -hash_next(DOH *ho) { - Hash *h = (Hash *) ObjData(ho); - if (h->currentindex < 0) return hash_first(ho); - - /* Try to move to the next entry */ - if (h->current) { - h->current = h->current->next; +static DohIterator +Hash_nextiter(DohIterator iter) { + Hash *h = (Hash *) ObjData(iter.object); + if (!iter._current) { + iter._index++; + while ((iter._index < h->hashsize) && !h->hashtable[iter._index]) { + iter._index++; } - if (h->current) { - return h->current; + if (iter._index >= h->hashsize) { + iter.item = 0; + iter.key = 0; + iter._current = 0; + return iter; } - h->currentindex++; - while ((h->currentindex < h->hashsize) && !h->hashtable[h->currentindex]) - h->currentindex++; - if (h->currentindex >= h->hashsize) return 0; - h->current = h->hashtable[h->currentindex]; - return h->current; -} + iter._current = h->hashtable[iter._index]; + } + iter.key = ((HashNode *) iter._current)->key; + iter.item = ((HashNode *) iter._current)->object; -/* ----------------------------------------------------------------------------- - * Hash_firstkey() - * - * Return first hash-table key. - * ----------------------------------------------------------------------------- */ - -static DOH * -Hash_firstkey(DOH *ho) { - HashNode *hn = hash_first(ho); - if (hn) return hn->key; - return 0; -} - -/* ----------------------------------------------------------------------------- - * Hash_nextkey() - * - * Return next hash table key. - * ----------------------------------------------------------------------------- */ - -static DOH * -Hash_nextkey(DOH *ho) { - HashNode *hn = hash_next(ho); - if (hn) return hn->key; - return 0; + /* Store the next node to iterator on */ + iter._current = ((HashNode*)iter._current)->next; + return iter; } /* ----------------------------------------------------------------------------- @@ -371,13 +354,11 @@ Hash_nextkey(DOH *ho) { static DOH * Hash_keys(DOH *so) { DOH *keys; - DOH *k; + Iterator i; keys = NewList(); - k = Firstkey(so); - while (k) { - Append(keys,k); - k = Nextkey(so); + for (i = First(so); i.key; i = Next(i)) { + Append(keys,i.key); } return keys; } @@ -451,8 +432,6 @@ CopyHash(DOH *ho) { for (i = 0; i < nh->hashsize; i++) { nh->hashtable[i] = 0; } - nh->currentindex = -1; - nh->current = 0; nh->nitems = 0; nh->line = h->line; nh->file = h->file; @@ -512,8 +491,6 @@ static DohHashMethods HashHashMethods = { Hash_getattr, Hash_setattr, Hash_delattr, - Hash_firstkey, - Hash_nextkey, Hash_keys, }; @@ -528,6 +505,8 @@ DohObjInfo DohHashType = { Hash_len, /* doh_len */ 0, /* doh_hash */ 0, /* doh_cmp */ + Hash_firstiter, /* doh_first */ + Hash_nextiter, /* doh_next */ Hash_setfile, /* doh_setfile */ Hash_getfile, /* doh_getfile */ Hash_setline, /* doh_setline */ @@ -556,8 +535,6 @@ DohNewHash() { for (i = 0; i < h->hashsize; i++) { h->hashtable[i] = 0; } - h->currentindex = -1; - h->current = 0; h->nitems = 0; h->file = 0; h->line = 0; diff --git a/SWIG/Source/DOH/list.c b/SWIG/Source/DOH/list.c index cf7dbb304..fb80c3b92 100644 --- a/SWIG/Source/DOH/list.c +++ b/SWIG/Source/DOH/list.c @@ -16,7 +16,6 @@ char cvsroot_list_c[] = "$Header$"; typedef struct List { int maxitems; /* Max size */ int nitems; /* Num items */ - int iter; /* Iterator */ DOH *file; int line; DOH **items; @@ -46,7 +45,6 @@ CopyList(DOH *lo) { nl->nitems = l->nitems; nl->maxitems = l->maxitems; nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *)); - nl->iter = 0; for (i = 0; i < l->nitems; i++) { nl->items[i] = l->items[i]; Incref(nl->items[i]); @@ -195,12 +193,19 @@ List_set(DOH *lo, int n, DOH *val) { * Return the first item in the list. * ----------------------------------------------------------------------------- */ -static DOH * +static DohIterator List_first(DOH *lo) { - List *l = (List *) ObjData(lo); - l->iter = 0; - if (l->iter >= l->nitems) return 0; - return l->items[l->iter]; + DohIterator iter; + List *l = (List *) ObjData(lo); + iter.object = lo; + iter._index = 0; + iter.key = 0; + if (l->nitems > 0) { + iter.item = l->items[0]; + } else { + iter.item = 0; + } + return iter; } /* ----------------------------------------------------------------------------- @@ -209,12 +214,17 @@ List_first(DOH *lo) { * Return the next item in the list. * ----------------------------------------------------------------------------- */ -static DOH * -List_next(DOH *lo) { - List *l = (List *) ObjData(lo); - l->iter++; - if (l->iter >= l->nitems) return 0; - return l->items[l->iter]; +static DohIterator +List_next(DohIterator iter) { + List *l = (List *) ObjData(iter.object); + iter._index = iter._index + 1; + if (iter._index >= l->nitems) { + iter.item = 0; + iter.key = 0; + } else { + iter.item = l->items[iter._index]; + } + return iter; } /* ----------------------------------------------------------------------------- @@ -300,8 +310,6 @@ static DohListMethods ListListMethods = { List_remove, List_insert, 0, /* delslice */ - List_first, - List_next, }; DohObjInfo DohListType = { @@ -315,6 +323,8 @@ DohObjInfo DohListType = { List_len, /* doh_len */ 0, /* doh_hash */ 0, /* doh_cmp */ + List_first, /* doh_first */ + List_next, /* doh_next */ List_setfile, /* doh_setfile */ List_getfile, /* doh_getfile */ List_setline, /* doh_setline */ @@ -346,7 +356,6 @@ DohNewList() { for (i = 0; i < MAXLISTITEMS; i++) { l->items[i] = 0; } - l->iter = 0; l->file = 0; l->line = 0; return DohObjMalloc(&DohListType,l); diff --git a/SWIG/Source/DOH/string.c b/SWIG/Source/DOH/string.c index 7b87acbfe..b866714de 100644 --- a/SWIG/Source/DOH/string.c +++ b/SWIG/Source/DOH/string.c @@ -874,8 +874,6 @@ static DohListMethods StringListMethods = { String_delitem, /* doh_delitem */ String_insert, /* doh_insitem */ String_delslice, /* doh_delslice */ - 0, /* doh_first */ - 0, /* doh_next */ }; static DohFileMethods StringFileMethods = { @@ -905,6 +903,8 @@ DohObjInfo DohStringType = { String_len, /* doh_len */ String_hash, /* doh_hash */ String_cmp, /* doh_cmp */ + 0, /* doh_first */ + 0, /* doh_next */ String_setfile, /* doh_setfile */ String_getfile, /* doh_getfile */ String_setline, /* doh_setline */ diff --git a/SWIG/Source/DOH/void.c b/SWIG/Source/DOH/void.c index 387062e1f..90b85d8ec 100644 --- a/SWIG/Source/DOH/void.c +++ b/SWIG/Source/DOH/void.c @@ -69,6 +69,8 @@ static DohObjInfo DohVoidType = { 0, /* doh_len */ 0, /* doh_hash */ 0, /* doh_cmp */ + 0, /* doh_first */ + 0, /* doh_next */ 0, /* doh_setfile */ 0, /* doh_getfile */ 0, /* doh_setline */ diff --git a/SWIG/Source/Modules/browser.cxx b/SWIG/Source/Modules/browser.cxx index 2607562ef..009654a89 100644 --- a/SWIG/Source/Modules/browser.cxx +++ b/SWIG/Source/Modules/browser.cxx @@ -41,8 +41,10 @@ class Browser : public Dispatcher { if (!Getmeta(obj,"visible")) return; String *os = NewString(""); String *k; - k = Firstkey(obj); - while (k) { + Iterator ki; + ki = First(obj); + while (ki.key) { + k = ki.key; if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) || (Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) || (Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) { @@ -71,7 +73,7 @@ class Browser : public Dispatcher { Printf(os,"? %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k)); } } - k = Nextkey(obj); + ki = Next(ki); } Printf(out,"
\n%s
\n", Char(os)); Delete(os); @@ -241,10 +243,12 @@ void raw_data(FILE *out, Node *obj) { if (!obj) return; if (DohIsMapping(obj)) { String *k; + Iterator ki; String *os = NewString(""); Printf(os,"Hash {\n"); - k = Firstkey(obj); - while (k) { + ki = First(obj); + while (ki.key) { + k = ki.key; DOH *o; const char *trunc = ""; if (DohIsString(Getattr(obj,k))) { @@ -258,7 +262,7 @@ void raw_data(FILE *out, Node *obj) { } else { Printf(os," ? %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k)); } - k = Nextkey(obj); + ki = Next(ki); } Printf(os,"}\n"); Printf(out,"
\n%s
\n", Char(os)); diff --git a/SWIG/Source/Modules/chicken.cxx b/SWIG/Source/Modules/chicken.cxx index e98d0b7de..ae61d7d36 100644 --- a/SWIG/Source/Modules/chicken.cxx +++ b/SWIG/Source/Modules/chicken.cxx @@ -1369,18 +1369,18 @@ CHICKEN::classHandler(Node *n) String *base_class = NewString("<"); List *baselist = Getattr(n,"bases"); if (baselist && Len(baselist)) { - Node *base = Firstitem(baselist); - while (base) { - String *bname = Copy(Getattr(base, "chicken:proxy")); + Iterator base = First(baselist); + while (base.item) { + String *bname = Copy(Getattr(base.item, "chicken:proxy")); if (!bname) { - base = Nextitem(baselist); + base = Next(base); continue; } namify(bname); Printv(base_class,bname,NIL); Delete(bname); - base = Nextitem(baselist); - if (base) { + base = Next(base); + if (base.item) { Printf(base_class, "> <"); } } @@ -1879,12 +1879,12 @@ CHICKEN::chickenCode(String *code, const String *indent) { List *clist = DohSplit(temp,'\n',-1); Delete(temp); int initial = 0; - String *s; + Iterator s; /* Get the initial indentation */ - for (s = Firstitem(clist); s; s = Nextitem(clist)) { - if (Len(s)) { - char *c = Char(s); + for (s = First(clist); s.item; s = Next(s)) { + if (Len(s.item)) { + char *c = Char(s.item); while (*c) { if (!isspace(*c)) break; initial++; @@ -1896,15 +1896,15 @@ CHICKEN::chickenCode(String *code, const String *indent) { } } } - while (s) { - if (Len(s) > initial) { - char *c = Char(s); + while (s.item) { + if (Len(s.item) > initial) { + char *c = Char(s.item); c += initial; Printv(out,indent,c,"\n",NIL); } else { Printv(out,"\n",NIL); } - s = Nextitem(clist); + s = Next(s); } Delete(clist); return out; @@ -1939,11 +1939,11 @@ CHICKEN::recurseSearch(const char *typemap, char *argname, Node *n) /* recurse through base classes */ List *baselist = Getattr(n,"bases"); if (baselist && Len(baselist)) { - Node *base = Firstitem(baselist); - while (base) { - tm = recurseSearch(typemap, argname, base); + Iterator base = First(baselist); + while (base.item) { + tm = recurseSearch(typemap, argname, base.item); if (tm) break; - base = Nextitem(baselist); + base = Next(base); } } return tm; diff --git a/SWIG/Source/Modules/contract.cxx b/SWIG/Source/Modules/contract.cxx index a2f83b631..afb60e448 100644 --- a/SWIG/Source/Modules/contract.cxx +++ b/SWIG/Source/Modules/contract.cxx @@ -261,7 +261,7 @@ int Contracts::InheritAssertAppend(Node *n, Node *bases) { } int Contracts::AssertModify(Node *n, int flag) { - String *str_assert, *expr, *tag_sync; + String *str_assert, *expr = 0, *tag_sync; List *list_assert; if (flag == 1) { /* preassert */ @@ -286,7 +286,10 @@ int Contracts::AssertModify(Node *n, int flag) { /* build up new assertion */ str_assert = NewString(""); - for (expr = Firstitem(list_assert); expr; expr = Nextitem(list_assert)) { + Iterator ei; + + for (ei = First(list_assert); ei.item; ei = Next(ei)) { + expr = ei.item; if (Len(expr)) { /* All sync staff are not complete and only experimental */ if (Strstr(expr, SWIG_BEFORE)) { /* before sync assertion */ @@ -324,7 +327,6 @@ int Contracts::AssertModify(Node *n, int flag) { Delete(str_assert); Delete(list_assert); - Delete(expr); return SWIG_OK; } diff --git a/SWIG/Source/Modules/csharp.cxx b/SWIG/Source/Modules/csharp.cxx index ace719f8e..8e6330b49 100644 --- a/SWIG/Source/Modules/csharp.cxx +++ b/SWIG/Source/Modules/csharp.cxx @@ -338,8 +338,8 @@ class CSHARP : public Language { Printf(f_wrappers,"#endif\n"); // Output a C# type wrapper class for each SWIG type - for (String *swig_type = Firstkey(swig_types_hash); swig_type; swig_type = Nextkey(swig_types_hash)) { - emitTypeWrapperClass(swig_type, Getattr(swig_types_hash, swig_type)); + for (Iterator swig_type = First(swig_types_hash); swig_type.key; swig_type = Next(swig_type)) { + emitTypeWrapperClass(swig_type.key, swig_type.item); } Delete(swig_types_hash); swig_types_hash = NULL; @@ -948,16 +948,16 @@ class CSHARP : public Language { /* Deal with inheritance */ List *baselist = Getattr(n,"bases"); if (baselist) { - Node *base = Firstitem(baselist); - c_baseclassname = Getattr(base,"name"); + Iterator base = First(baselist); + c_baseclassname = Getattr(base.item,"name"); baseclass = Copy(getProxyName(c_baseclassname)); if (baseclass){ - c_baseclass = SwigType_namestr(Getattr(base,"name")); + c_baseclass = SwigType_namestr(Getattr(base.item,"name")); } - base = Nextitem(baselist); - if (base) { + base = Next(base); + if (base.item) { Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", classDeclarationName, Getattr(base,"name")); + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", classDeclarationName, Getattr(base.item,"name")); } } @@ -1951,8 +1951,8 @@ class CSHARP : public Language { // Add the exception classes to the node throws list, but don't duplicate if already in list if (temp_classes_list && Len(temp_classes_list) > 0) { - for (String *cls = Firstitem(temp_classes_list); cls; cls = Nextitem(temp_classes_list)) { - String *exception_class = NewString(cls); + for (Iterator cls = First(temp_classes_list); cls.item; cls = Next(cls)) { + String *exception_class = NewString(cls.item); Replaceall(exception_class," ",""); // remove spaces Replaceall(exception_class,"\t",""); // remove tabs if (Len(exception_class) > 0) { @@ -1962,8 +1962,8 @@ class CSHARP : public Language { // Don't duplicate the C# exception class in the throws clause bool found_flag = false; - for (String *item = Firstitem(throws_list); item; item = Nextitem(throws_list)) { - if (Strcmp(item, exception_class) == 0) + for (Iterator item = First(throws_list); item.item; item = Next(item)) { + if (Strcmp(item.item, exception_class) == 0) found_flag = true; } if (!found_flag) @@ -1985,10 +1985,10 @@ class CSHARP : public Language { // Add the throws clause into code List *throws_list = Getattr(n,"csharp:throwslist"); if (throws_list) { - String *cls = Firstitem(throws_list); - Printf(code, " throws %s", cls); - while ( (cls = Nextitem(throws_list)) ) - Printf(code, ", %s", cls); + Iterator cls = First(throws_list); + Printf(code, " throws %s", cls.item); + while ( (cls = Next(cls)).item) + Printf(code, ", %s", cls.item); } } diff --git a/SWIG/Source/Modules/java.cxx b/SWIG/Source/Modules/java.cxx index 651b80a90..007d9bfb9 100644 --- a/SWIG/Source/Modules/java.cxx +++ b/SWIG/Source/Modules/java.cxx @@ -518,8 +518,8 @@ class JAVA : public Language { Printf(f_wrappers,"#endif\n"); // Output a Java type wrapper class for each SWIG type - for (String *swig_type = Firstkey(swig_types_hash); swig_type; swig_type = Nextkey(swig_types_hash)) { - emitTypeWrapperClass(swig_type, Getattr(swig_types_hash, swig_type)); + for (Iterator swig_type = First(swig_types_hash); swig_type.key; swig_type = Next(swig_type)) { + emitTypeWrapperClass(swig_type.key, swig_type.item); } /* Close all of the files */ @@ -602,17 +602,18 @@ class JAVA : public Language { UpcallData *udata; String *methodno; Hash *new_udata; - + Iterator ui; + /* Do we know about this director class already? */ if ((udata = Getattr(dmethods_table, director_class)) != NULL) return Getattr(udata, "methodoff"); /* Clearly not, so make sure we don't already know about the Java method and field descriptor signature */ - for (udata = Firstitem(dmethods_seq); udata != NULL; udata = Nextitem(dmethods_seq)) { - if (!Cmp(Getattr(udata, "method"), method) && !Cmp(Getattr(udata, "fdesc"), signature)) { - Setattr(dmethods_table, director_class, udata); - return Getattr(udata, "methodoff"); + for (ui = First(dmethods_seq); ui.item; ui = Next(ui)) { + if (!Cmp(Getattr(ui.item, "method"), method) && !Cmp(Getattr(ui.item, "fdesc"), signature)) { + Setattr(dmethods_table, director_class, ui.item); + return Getattr(ui.item, "methodoff"); } } @@ -1472,16 +1473,16 @@ class JAVA : public Language { /* Deal with inheritance */ List *baselist = Getattr(n,"bases"); if (baselist) { - Node *base = Firstitem(baselist); - c_baseclassname = Getattr(base,"name"); + Iterator base = First(baselist); + c_baseclassname = Getattr(base.item,"name"); baseclass = Copy(getProxyName(c_baseclassname)); if (baseclass){ - c_baseclass = SwigType_namestr(Getattr(base,"name")); + c_baseclass = SwigType_namestr(Getattr(base.item,"name")); } - base = Nextitem(baselist); - if (base) { + base = Next(base); + if (base.item) { Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", classDeclarationName, Getattr(base,"name")); + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", classDeclarationName, Getattr(base.item,"name")); } } @@ -2422,8 +2423,8 @@ class JAVA : public Language { // Add the exception classes to the node throws list, but don't duplicate if already in list if (temp_classes_list && Len(temp_classes_list) > 0) { - for (String *cls = Firstitem(temp_classes_list); cls; cls = Nextitem(temp_classes_list)) { - String *exception_class = NewString(cls); + for (Iterator cls = First(temp_classes_list); cls.item; cls = Next(cls)) { + String *exception_class = NewString(cls.item); Replaceall(exception_class," ",""); // remove spaces Replaceall(exception_class,"\t",""); // remove tabs if (Len(exception_class) > 0) { @@ -2433,8 +2434,8 @@ class JAVA : public Language { // Don't duplicate the Java exception class in the throws clause bool found_flag = false; - for (String *item = Firstitem(throws_list); item; item = Nextitem(throws_list)) { - if (Strcmp(item, exception_class) == 0) + for (Iterator item = First(throws_list); item.item; item = Next(item)) { + if (Strcmp(item.item, exception_class) == 0) found_flag = true; } if (!found_flag) @@ -2456,10 +2457,10 @@ class JAVA : public Language { // Add the throws clause into code List *throws_list = Getattr(n,"java:throwslist"); if (throws_list) { - String *cls = Firstitem(throws_list); - Printf(code, " throws %s", cls); - while ( (cls = Nextitem(throws_list)) ) - Printf(code, ", %s", cls); + Iterator cls = First(throws_list); + Printf(code, " throws %s", cls.item); + while ( (cls = Next(cls)).item) + Printf(code, ", %s", cls.item); } } @@ -2506,6 +2507,7 @@ class JAVA : public Language { Wrapper *w = NewWrapper(); String *jni_imclass_name = makeValidJniName(imclass_name); UpcallData *udata; + Iterator ui; Printf(f_runtime, "static jclass __SWIG_jclass_%s = NULL;\n", imclass_name); Printf(f_runtime, "static jmethodID __SWIG_director_methids[%d];\n", n_dmethods); @@ -2517,11 +2519,11 @@ class JAVA : public Language { Printf(w->code, " const char *signature;\n"); Printf(w->code, "} methods[%d] = {\n", n_dmethods); - udata = Firstitem(dmethods_seq); - while ( udata) { - Printf(w->code, " { \"%s\", \"%s\" }", Getattr(udata, "method"), Getattr(udata, "fdesc")); - udata = Nextitem(dmethods_seq); - if (udata) + ui = First(dmethods_seq); + while ( ui.item) { + Printf(w->code, " { \"%s\", \"%s\" }", Getattr(ui.item, "method"), Getattr(ui.item, "fdesc")); + ui = Next(ui); + if (ui.item) Putc(',', w->code); Putc('\n', w->code); } diff --git a/SWIG/Source/Modules/lang.cxx b/SWIG/Source/Modules/lang.cxx index b4edb9fa4..dd65bf208 100644 --- a/SWIG/Source/Modules/lang.cxx +++ b/SWIG/Source/Modules/lang.cxx @@ -1392,9 +1392,9 @@ int Language::unrollVirtualMethods(Node *n, // recurse through all base classes to build the vtable List* bl = Getattr(n, "bases"); if (bl) { - Node* bi; - for (bi = Firstitem(bl); bi; bi = Nextitem(bl)) { - unrollVirtualMethods(bi, parent, vm, default_director, virtual_destructor); + Iterator bi; + for (bi = First(bl); bi.item; bi = Next(bi)) { + unrollVirtualMethods(bi.item, parent, vm, default_director, virtual_destructor); } } // find the methods that need directors @@ -1503,9 +1503,10 @@ int Language::classDirectorConstructors(Node *n) { int Language::classDirectorMethods(Node *n) { Node *vtable = Getattr(n, "vtable"); Node *item; - String *key; - for (key = Firstkey(vtable); key != 0; key = Nextkey(vtable)) { - item = Getattr(vtable, key); + Iterator k; + + for (k = First(vtable); k.key; k = Next(k)) { + item = k.item; String *method = Getattr(item, "methodNode"); String *fqname = Getattr(item, "fqName"); if (classDirectorMethod(method, n, fqname) == SWIG_OK) { @@ -1656,9 +1657,9 @@ int Language::classHandler(Node *n) { List *methods = Getattr(n,"allocate:smartpointer"); cplus_mode = CPLUS_PUBLIC; SmartPointer = CWRAP_SMART_POINTER; - Node *c; - for (c = Firstitem(methods); c; c= Nextitem(methods)) { - emit_one(c); + Iterator c; + for (c = First(methods); c.item; c= Next(c)) { + emit_one(c.item); } SmartPointer = 0; } diff --git a/SWIG/Source/Modules/main.cxx b/SWIG/Source/Modules/main.cxx index b6bd8b3bc..d1e75667d 100644 --- a/SWIG/Source/Modules/main.cxx +++ b/SWIG/Source/Modules/main.cxx @@ -517,9 +517,9 @@ int SWIG_main(int argc, char *argv[], Language *l) { if (Verbose) { printf ("LibDir: %s\n", LibDir); List *sp = Swig_search_path(); - String *s; - for (s = Firstitem(sp); s; s = Nextitem(sp)) { - Printf(stdout," %s\n", s); + Iterator s; + for (s = First(sp); s.item; s = Next(s)) { + Printf(stdout," %s\n", s.item); } } @@ -648,9 +648,9 @@ int SWIG_main(int argc, char *argv[], Language *l) { if (classes) { Printf(stdout,"Classes\n"); Printf(stdout,"------------\n"); - String *key; - for (key = Firstkey(classes); key; key = Nextkey(classes)) { - Printf(stdout,"%s\n", key); + Iterator ki; + for (ki = First(classes); ki.key; ki = Next(ki)) { + Printf(stdout,"%s\n", ki.key); } } } diff --git a/SWIG/Source/Modules/ocaml.cxx b/SWIG/Source/Modules/ocaml.cxx index e8cf9af02..25b05afba 100755 --- a/SWIG/Source/Modules/ocaml.cxx +++ b/SWIG/Source/Modules/ocaml.cxx @@ -1338,19 +1338,19 @@ public: /* Handle up-casts in a nice way */ List *baselist = Getattr(n,"bases"); if (baselist && Len(baselist)) { - Node *base = Firstitem(baselist); - while (base) { - String *bname = Getattr(base, "ocaml:ctor"); - if (bname) { - Printv(f_class_ctors, - " \"::",bname,"\", (fun args -> " - "create_",bname,"_from_ptr raw_ptr) ;\n",NIL); - Printv( base_classes, "create_", bname, "_from_ptr ;\n", - NIL ); - } - - base = Nextitem(baselist); + Iterator b; + b = First(baselist); + while (b.item) { + String *bname = Getattr(b.item, "ocaml:ctor"); + if (bname) { + Printv(f_class_ctors, + " \"::",bname,"\", (fun args -> " + "create_",bname,"_from_ptr raw_ptr) ;\n",NIL); + Printv( base_classes, "create_", bname, "_from_ptr ;\n", + NIL ); } + b = Next(b); + } } Replaceall(this_class_def,"$classname",classname); diff --git a/SWIG/Source/Modules/perl5.cxx b/SWIG/Source/Modules/perl5.cxx index 75ceb9cf1..ece63ca1e 100644 --- a/SWIG/Source/Modules/perl5.cxx +++ b/SWIG/Source/Modules/perl5.cxx @@ -315,16 +315,16 @@ public: /* Patch the type table to reflect the names used by shadow classes */ if (blessed) { - Node *cls; - for (cls = Firstitem(classlist); cls; cls = Nextitem(classlist)) { - if (Getattr(cls,"perl5:proxy")) { - SwigType *type = Copy(Getattr(cls,"classtype")); + Iterator cls; + for (cls = First(classlist); cls.item; cls = Next(cls)) { + if (Getattr(cls.item,"perl5:proxy")) { + SwigType *type = Copy(Getattr(cls.item,"classtype")); if (!type) continue; /* If unnamed class, no type will be found */ SwigType_add_pointer(type); String *mangle = NewStringf("\"%s\"", SwigType_manglestr(type)); - String *rep = NewStringf("\"%s\"", Getattr(cls,"perl5:proxy")); + String *rep = NewStringf("\"%s\"", Getattr(cls.item,"perl5:proxy")); Replaceall(type_table,mangle,rep); Delete(mangle); Delete(rep); @@ -1139,9 +1139,9 @@ public: if (have_operators) { Printf(pm, "use overload\n"); - DOH *key; - for (key = Firstkey(operators); key; key = Nextkey(operators)) { - char *name = Char(key); + Iterator ki; + for (ki = First(operators); ki.key; ki = Next(ki)) { + char *name = Char(ki.key); // fprintf(stderr,"found name: <%s>\n", name); if (strstr(name, "operator_equal_to")) { Printv(pm, tab4, "\"==\" => sub { $_[0]->operator_equal_to($_[1])},\n",NIL); @@ -1162,15 +1162,16 @@ public: /* Handle inheritance */ List *baselist = Getattr(n,"bases"); if (baselist && Len(baselist)) { - Node *base = Firstitem(baselist); - while (base) { - String *bname = Getattr(base, "perl5:proxy"); + Iterator b; + b = First(baselist); + while (b.item) { + String *bname = Getattr(b.item, "perl5:proxy"); if (!bname) { - base = Nextitem(baselist); + b = Next(b); continue; } Printv(pm," ", bname, NIL); - base = Nextitem(baselist); + b = Next(b); } } Printf(pm, " );\n"); diff --git a/SWIG/Source/Modules/php4.cxx b/SWIG/Source/Modules/php4.cxx index 2d8bd0e10..fc05b8f76 100644 --- a/SWIG/Source/Modules/php4.cxx +++ b/SWIG/Source/Modules/php4.cxx @@ -143,15 +143,17 @@ static const char *php_header = void SwigPHP_emit_resource_registrations() { DOH *key; + Iterator ki; String *destructor=0; String *classname=0; String *shadow_classname=0; if (!zend_types) return; - key = Firstkey(zend_types); - if (key) Printf(s_oinit,"\n/* Register resource destructors for pointer types */\n"); - while (key) if (1 /* is pointer type*/) { + ki = First(zend_types); + if (ki.key) Printf(s_oinit,"\n/* Register resource destructors for pointer types */\n"); + while (ki.key) if (1 /* is pointer type*/) { + key = ki.key; Node *class_node; if ((class_node=Getattr(zend_types,key))) { // Write out destructor function header @@ -187,7 +189,7 @@ SwigPHP_emit_resource_registrations() { Printf(s_oinit,"SWIG_TypeClientData(SWIGTYPE%s,&le_swig_%s);\n", key,key); } - key = Nextkey(zend_types); + ki = Next(ki); } } @@ -1458,24 +1460,23 @@ public: if(baselist) { int class_count = 0; - Node *base = Firstitem(baselist); + Iterator base = First(baselist); + while(base.item && Getattr(base.item,"feature:ignore")) base = Next(base); - while(base && Getattr(base,"feature:ignore")) base = Nextitem(baselist); - - if (base && is_shadow(Getattr(base, "name"))) { + if (base.item && is_shadow(Getattr(base.item, "name"))) { class_count++; - Printf(this_shadow_baseclass, "%s", Getattr(base, "name")); + Printf(this_shadow_baseclass, "%s", Getattr(base.item, "name")); } - if (base) for(base = Nextitem(baselist); base; base = Nextitem(baselist)) { - if (Getattr(base,"feature:ignore")) continue; - if(is_shadow(Getattr(base, "name"))) { + if (base.item) for(base = Next(base); base.item; base = Next(base)) { + if (Getattr(base.item,"feature:ignore")) continue; + if(is_shadow(Getattr(base.item, "name"))) { class_count++; - Printf(this_shadow_multinherit, "%s ", Getattr(base, "name")); + Printf(this_shadow_multinherit, "%s ", Getattr(base.item, "name")); } } - if(class_count > 1) Printf(stderr, "Error: %s inherits from multiple base classes(%s %s). Multiple inheritance is not directly supported by PHP4, SWIG may support it at some point in the future.\n", shadow_classname, base, this_shadow_multinherit); + if(class_count > 1) Printf(stderr, "Error: %s inherits from multiple base classes(%s %s). Multiple inheritance is not directly supported by PHP4, SWIG may support it at some point in the future.\n", shadow_classname, base.item, this_shadow_multinherit); } /* Write out class init code */ @@ -1493,7 +1494,8 @@ public: String *s_propget=NewString(""); String *s_propset=NewString(""); List *baselist = Getattr(n, "bases"); - Node *base = NULL; + Iterator ki, base; + // If no constructor was generated (abstract class) we had better // generate a constructor that raises an error about instantiating @@ -1526,20 +1528,22 @@ public: Printf(s_header,"static int _propset_%s(zend_property_reference *property_reference, pval *value);\n", shadow_classname); Printf(s_propset,"static int _propset_%s(zend_property_reference *property_reference, pval *value) {\n", shadow_classname); - if (baselist) base=Firstitem(baselist); - else base=NULL; - while(base && Getattr(base,"feature:ignore")) base = Nextitem(baselist); - key = Firstkey(shadow_set_vars); + + if (baselist) base=First(baselist); + else base.item = NULL; + while(base.item && Getattr(base.item,"feature:ignore")) base = Next(base); + ki = First(shadow_set_vars); + key = ki.key; // Print function header; we only need to find property name if there // are properties for this class to look up... - if (key || ! base) { // or if we are base class and set it ourselves + if (key || ! base.item) { // or if we are base class and set it ourselves Printf(s_propset," /* get the property name */\n" " zend_llist_element *element = property_reference->elements_list->head;\n" " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n" " char *propname=Z_STRVAL_P(&(property->element));\n"); } else { - if (base) { + if (base.item) { Printf(s_propset," /* No extra properties for subclass %s */\n",shadow_classname); } else { Printf(s_propset," /* No properties for base class %s */\n",shadow_classname); @@ -1547,27 +1551,28 @@ public: } scount=0; - while (key) { + while (ki.key) { + key = ki.key; if (scount++) Printf(s_propset," else"); Printf(s_propset," if (strcmp(propname,\"%s\")==0) {\n" " return _wrap_%s(property_reference, value);\n" " }",Getattr(shadow_set_vars,key),key); - key=Nextkey(shadow_set_vars); + ki=Next(ki); } if (scount) Printf(s_propset," else"); // If there is a base class then chain it's handler else set directly // try each base class handler, else set directly... - if (base) { + if (base.item) { Printf(s_propset, " {\n /* chain to base class */\n"); - while(base) { + while(base.item) { Printf(s_propset," if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", - GetChar(base, "sym:name")); + GetChar(base.item, "sym:name")); - base=Nextitem(baselist); - while (base && Getattr(base,"feature:ignore")) base=Nextitem(baselist); + base=Next(base); + while (base.item && Getattr(base.item,"feature:ignore")) base=Next(base); } Printf(s_propset," }\n"); } @@ -1597,20 +1602,22 @@ public: Printf(s_header,"static int _propget_%s(zend_property_reference *property_reference, pval *value);\n", shadow_classname); Printf(s_propget,"static int _propget_%s(zend_property_reference *property_reference, pval *value) {\n", shadow_classname); - if (baselist) base=Firstitem(baselist); - else base=NULL; - while(base && Getattr(base,"feature:ignore")) base = Nextitem(baselist); - key = Firstkey(shadow_get_vars); + if (baselist) base=First(baselist); + else base.item=NULL; + while(base.item && Getattr(base.item,"feature:ignore")) base = Next(base); + ki = First(shadow_get_vars); + + key = ki.key; // Print function header; we only need to find property name if there // are properties for this class to look up... - if (key || !base ) { // or if we are base class... + if (key || !base.item ) { // or if we are base class... Printf(s_propget," /* get the property name */\n" " zend_llist_element *element = property_reference->elements_list->head;\n" " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n" " char *propname=Z_STRVAL_P(&(property->element));\n"); } else { - if (base) { + if (base.item) { Printf(s_propget," /* No extra properties for subclass %s */\n",shadow_classname); } else { Printf(s_propget," /* No properties for base class %s */\n",shadow_classname); @@ -1618,27 +1625,28 @@ public: } gcount=0; - while (key) { + while (ki.key) { + key = ki.key; if (gcount++) Printf(s_propget," else"); Printf(s_propget," if (strcmp(propname,\"%s\")==0) {\n" " *value=_wrap_%s(property_reference);\n" " return SUCCESS;\n" " }",Getattr(shadow_get_vars,key),key); - key=Nextkey(shadow_get_vars); + ki=Next(ki); } if (gcount) Printf(s_propget," else"); // If there is a base class then chain it's handler else return null - if (base) { + if (base.item) { Printf(s_propget, " {\n /* chain to base class */\n"); - while(base) { + while(base.item) { Printf(s_propget," if (_propget_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", - GetChar(base, "sym:name")); + GetChar(base.item, "sym:name")); - base=Nextitem(baselist); - while (base && Getattr(base,"feature:ignore")) base=Nextitem(baselist); + base=Next(base); + while (base.item && Getattr(base.item,"feature:ignore")) base=Next(base); } Printf(s_propget," }\n"); } @@ -1651,13 +1659,13 @@ public: Printv(s_wrappers,s_propget,s_propset,NIL); // Save class in class table - if (baselist) base=Firstitem(baselist); - else base=NULL; - while(base && Getattr(base,"feature:ignore")) base = Nextitem(baselist); + if (baselist) base=First(baselist); + else base.item=NULL; + while(base.item && Getattr(base.item,"feature:ignore")) base = Next(base); - if (base) { + if (base.item) { Printf(s_oinit,"if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,&ce_swig_%s,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n", - shadow_classname,shadow_classname,GetChar(base, "sym:name"), shadow_classname); + shadow_classname,shadow_classname,GetChar(base.item, "sym:name"), shadow_classname); } else { Printf(s_oinit,"if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,NULL,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n", shadow_classname,shadow_classname, shadow_classname); diff --git a/SWIG/Source/Modules/pike.cxx b/SWIG/Source/Modules/pike.cxx index 22867bedc..aa89631ff 100644 --- a/SWIG/Source/Modules/pike.cxx +++ b/SWIG/Source/Modules/pike.cxx @@ -642,9 +642,9 @@ public: /* Handle inheritance */ List *baselist = Getattr(n,"bases"); if (baselist && Len(baselist) > 0) { - Node *base = Firstitem(baselist); - while (base) { - String *basename = Getattr(base,"name"); + Iterator base = First(baselist); + while (base.item) { + String *basename = Getattr(base.item,"name"); SwigType *basetype = NewString(basename); SwigType_add_pointer(basetype); SwigType_remember(basetype); @@ -652,7 +652,7 @@ public: Printf(f_classInit, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle); Delete(basemangle); Delete(basetype); - base = Nextitem(baselist); + base = Next(base); } } else { Printf(f_classInit, "ADD_STORAGE(swig_object_wrapper);\n"); @@ -729,19 +729,19 @@ public: void membervariableAccessors(List *membervariables) { String *name; - Node *n; + Iterator i; bool need_setter; String *funcname; /* If at least one of them is mutable, we need a setter */ need_setter = false; - n = Firstitem(membervariables); - while (n) { - if (!Getattr(n, "feature:immutable")) { + i = First(membervariables); + while (i.item) { + if (!Getattr(i.item, "feature:immutable")) { need_setter = true; break; } - n = Nextitem(membervariables); + i = Next(i); } /* Create a function to set the values of the (mutable) variables */ @@ -752,10 +752,10 @@ public: Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL); Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n"); - n = Firstitem(membervariables); - while (n) { - if (!Getattr(n, "feature:immutable")) { - name = Getattr(n, "name"); + i = First(membervariables); + while (i.item) { + if (!Getattr(i.item, "feature:immutable")) { + name = Getattr(i.item, "name"); funcname = Swig_name_wrapper(Swig_name_set(Swig_name_member(getClassPrefix(), name))); Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name); Printf(wrapper->code, "%s(args);\n", funcname); @@ -763,7 +763,7 @@ public: Printf(wrapper->code, "}\n"); Delete(funcname); } - n = Nextitem(membervariables); + i = Next(i); } /* Close the function */ @@ -775,7 +775,7 @@ public: /* Register it with Pike */ String *description = NewString("tStr tFloat, tVoid"); - add_method(Firstitem(membervariables), "`->=", wname, description); + add_method(First(membervariables).item, "`->=", wname, description); Delete(description); /* Clean up */ @@ -791,16 +791,16 @@ public: Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL); Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n"); - n = Firstitem(membervariables); - while (n) { - name = Getattr(n, "name"); + i = First(membervariables); + while (i.item) { + name = Getattr(i.item, "name"); funcname = Swig_name_wrapper(Swig_name_get(Swig_name_member(getClassPrefix(), name))); Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name); Printf(wrapper->code, "%s(args);\n", funcname); Printf(wrapper->code, "return;\n"); Printf(wrapper->code, "}\n"); Delete(funcname); - n = Nextitem(membervariables); + i = Next(i); } /* Close the function */ @@ -812,7 +812,7 @@ public: /* Register it with Pike */ String *description = NewString("tStr, tMix"); - add_method(Firstitem(membervariables), "`->", wname, description); + add_method(First(membervariables).item, "`->", wname, description); Delete(description); /* Clean up */ diff --git a/SWIG/Source/Modules/python.cxx b/SWIG/Source/Modules/python.cxx index 4ef2bd979..5bf33f74c 100644 --- a/SWIG/Source/Modules/python.cxx +++ b/SWIG/Source/Modules/python.cxx @@ -1781,16 +1781,17 @@ public: String *base_class = NewString(""); List *baselist = Getattr(n,"bases"); if (baselist && Len(baselist)) { - Node *base = Firstitem(baselist); - while (base) { - String *bname = Getattr(base, "python:proxy"); + Iterator b; + b = First(baselist); + while (b.item) { + String *bname = Getattr(b.item, "python:proxy"); if (!bname) { - base = Nextitem(baselist); + b = Next(b); continue; } Printv(base_class,bname,NIL); - base = Nextitem(baselist); - if (base) { + b = Next(b); + if (b.item) { Putc(',',base_class); } } @@ -2149,10 +2150,12 @@ public: List *clist = DohSplit(temp,'\n',-1); Delete(temp); int initial = 0; - String *s; - - /* Get the initial indentation */ - for (s = Firstitem(clist); s; s = Nextitem(clist)) { + String *s = 0; + Iterator si; + /* Get the initial indentation */ + + for (si = First(clist); si.item; si = Next(si)) { + s = si.item; if (Len(s)) { char *c = Char(s); while (*c) { @@ -2166,7 +2169,8 @@ public: } } } - while (s) { + while (si.item) { + s = si.item; if (Len(s) > initial) { char *c = Char(s); c += initial; @@ -2174,7 +2178,7 @@ public: } else { Printv(out,"\n",NIL); } - s = Nextitem(clist); + si = Next(si); } Delete(clist); return out; diff --git a/SWIG/Source/Modules/ruby.cxx b/SWIG/Source/Modules/ruby.cxx index e5be68176..924a00906 100644 --- a/SWIG/Source/Modules/ruby.cxx +++ b/SWIG/Source/Modules/ruby.cxx @@ -511,19 +511,20 @@ public: List *modules = Split(module,':',INT_MAX); if (modules != 0 && Len(modules) > 0) { String *mv = 0; - String *m = Firstitem(modules); - while (m != 0) { - if (Len(m) > 0) { + Iterator m; + m = First(modules); + while (m.item) { + if (Len(m.item) > 0) { if (mv != 0) { Printv(f_init, tab4, modvar, - " = rb_define_module_under(", modvar, ", \"", m, "\");\n", NIL); + " = rb_define_module_under(", modvar, ", \"", m.item, "\");\n", NIL); } else { Printv(f_init, tab4, modvar, - " = rb_define_module(\"", m, "\");\n", NIL); + " = rb_define_module(\"", m.item, "\");\n", NIL); mv = NewString(modvar); } } - m = Nextitem(modules); + m = Next(m); } Delete(mv); Delete(modules); @@ -767,18 +768,18 @@ public: List *modules = Split(mod_name,':',INT_MAX); if (modules != 0 && Len(modules) > 0) { String *last = 0; - String *m = Firstitem(modules); - while (m != 0) { - if (Len(m) > 0) { - String *cap = NewString(m); + Iterator m = First(modules); + while (m.item) { + if (Len(m.item) > 0) { + String *cap = NewString(m.item); (Char(cap))[0] = toupper((Char(cap))[0]); if (last != 0) { Append(module, "::"); } Append(module, cap); - last = m; + last = m.item; } - m = Nextitem(modules); + m = Next(m); } if (feature == 0) { feature = Copy(last); @@ -809,12 +810,12 @@ public: if (aliasv) { List *aliases = Split(aliasv,',',INT_MAX); if (aliases && Len(aliases) > 0) { - String *alias = Firstitem(aliases); - while (alias) { - if (Len(alias) > 0) { - Printv(klass->init, tab4, "rb_define_alias(", klass->vname, ", \"", alias, "\", \"", iname, "\");\n", NIL); + Iterator alias = First(aliases); + while (alias.item) { + if (Len(alias.item) > 0) { + Printv(klass->init, tab4, "rb_define_alias(", klass->vname, ", \"", alias.item, "\", \"", iname, "\");\n", NIL); } - alias = Nextitem(aliases); + alias = Next(alias); } } Delete(aliases); @@ -1707,12 +1708,12 @@ public: if (mixin) { List *modules = Split(mixin,',',INT_MAX); if (modules && Len(modules) > 0) { - String *mod = Firstitem(modules); - while (mod) { - if (Len(mod) > 0) { - Printf(klass->init, "rb_include_module(%s, rb_eval_string(\"%s\"));\n", klass->vname, mod); + Iterator mod = First(modules); + while (mod.item) { + if (Len(mod.item) > 0) { + Printf(klass->init, "rb_include_module(%s, rb_eval_string(\"%s\"));\n", klass->vname, mod.item); } - mod = Nextitem(modules); + mod = Next(mod); } } Delete(modules); @@ -1722,9 +1723,9 @@ public: void handleBaseClasses(Node *n) { List *baselist = Getattr(n,"bases"); if (baselist && Len(baselist)) { - Node *base = Firstitem(baselist); - while (base) { - String *basename = Getattr(base,"name"); + Iterator base = First(baselist); + while (base.item) { + String *basename = Getattr(base.item,"name"); String *basenamestr = SwigType_namestr(basename); RClass *super = RCLASS(classes, Char(basenamestr)); Delete(basenamestr); @@ -1747,14 +1748,14 @@ public: } Delete(btype); } - base = Nextitem(baselist); + base = Next(base); if (!multipleInheritance) { /* Warn about multiple inheritance for additional base class(es) listed */ - while (base) { + while (base.item) { basename = Getattr(n,"name"); Swig_warning(WARN_RUBY_MULTIPLE_INHERITANCE, input_file, line_number, "Warning for %s: Base %s ignored. Multiple inheritance is not supported in Ruby.\n", basename, basename); - base = Nextitem(baselist); + base = Next(base); } } } diff --git a/SWIG/Source/Modules/s-exp.cxx b/SWIG/Source/Modules/s-exp.cxx index 2a2edd3ee..bd3970a25 100644 --- a/SWIG/Source/Modules/s-exp.cxx +++ b/SWIG/Source/Modules/s-exp.cxx @@ -258,13 +258,13 @@ public: open_paren(NIL); for (; obj; obj = nextSibling(obj)) { if (DohIsMapping(obj)) { - DOH *k; + Iterator k; open_paren(NIL); - for (k = Firstkey(obj); k; k = Nextkey(obj)) { - if (!internal_key_p(k)) { - DOH *value = Getattr(obj, k); - Sexp_print_as_keyword(k); - Sexp_print_value_of_key(value, k); + for (k = First(obj); k.key; k = Next(k)) { + if (!internal_key_p(k.key)) { + DOH *value = Getattr(obj, k.key); + Sexp_print_as_keyword(k.key); + Sexp_print_value_of_key(value, k.key); print_lazy_whitespace(); } } @@ -295,16 +295,16 @@ public: } else if (DohIsMapping(obj)) { - DOH *k; + Iterator k; open_paren(NIL); - for (k = Firstkey(obj); k; k = Nextkey(obj)) { - if (!internal_key_p(k)) { - DOH *value = Getattr(obj, k); + for (k = First(obj); k.key; k = Next(k)) { + if (!internal_key_p(k.key)) { + DOH *value = Getattr(obj, k.key); flush_parens(); open_paren(NIL); - Sexp_print_doh(k); + Sexp_print_doh(k.key); Printf(out, " . "); - Sexp_print_value_of_key(value, k); + Sexp_print_value_of_key(value, k.key); close_paren(); } } @@ -341,18 +341,18 @@ public: void Sexp_print_plist_noparens(DOH *obj) { /* attributes map names to objects */ - String *k; + Iterator k; bool first; - for (k = Firstkey(obj), first = true; k; k = Nextkey(obj), first=false) { - if (!internal_key_p(k)) { - DOH *value = Getattr(obj, k); + for (k = First(obj), first = true; k.key; k = Next(k), first=false) { + if (!internal_key_p(k.key)) { + DOH *value = Getattr(obj, k.key); flush_parens(); if (!first) { Printf(out, " "); } - Sexp_print_as_keyword(k); + Sexp_print_as_keyword(k.key); /* Print value */ - Sexp_print_value_of_key(value, k); + Sexp_print_value_of_key(value, k.key); } } } diff --git a/SWIG/Source/Modules/tcl8.cxx b/SWIG/Source/Modules/tcl8.cxx index b4d1acec8..c4f34e345 100644 --- a/SWIG/Source/Modules/tcl8.cxx +++ b/SWIG/Source/Modules/tcl8.cxx @@ -661,17 +661,18 @@ public: String *base_class = NewString(""); List *baselist = Getattr(n,"bases"); if (baselist && Len(baselist)) { - Node *base = Firstitem(baselist); - while (base) { - String *bname = Getattr(base, "name"); - if ((!bname) || Getattr(base,"feature:ignore") || (!Getattr(base,"module"))) { - base = Nextitem(baselist); + Iterator b; + b = First(baselist); + while (b.item) { + String *bname = Getattr(b.item, "name"); + if ((!bname) || Getattr(b.item,"feature:ignore") || (!Getattr(b.item,"module"))) { + b = Next(b); continue; } String *bmangle = Swig_name_mangle(bname); Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL); Printf(base_class,"&_wrap_class_%s",bmangle); - base = Nextitem(baselist); + b = Next(b); Putc(',',base_class); Delete(bmangle); } diff --git a/SWIG/Source/Modules/typepass.cxx b/SWIG/Source/Modules/typepass.cxx index 665cf5fb2..f76cb0858 100644 --- a/SWIG/Source/Modules/typepass.cxx +++ b/SWIG/Source/Modules/typepass.cxx @@ -121,9 +121,9 @@ class TypePass : public Dispatcher { while (nn) { Swig_symbol_setscope(nn->symtab); SwigType_set_scope(nn->typescope); - SwigType *t; - for (t = Firstitem(nn->normallist); t; t = Nextitem(nn->normallist)) { - normalize_type(t); + Iterator t; + for (t = First(nn->normallist); t.item; t = Next(t)) { + normalize_type(t.item); } Delete(nn->normallist); np = nn->next; diff --git a/SWIG/Source/Modules/xml.cxx b/SWIG/Source/Modules/xml.cxx index d53695dfb..1318e88c2 100644 --- a/SWIG/Source/Modules/xml.cxx +++ b/SWIG/Source/Modules/xml.cxx @@ -137,10 +137,10 @@ public: print_indent(0); Printf( out, "\n", ++id, obj ); indent_level += 4; - - k = Firstkey(obj); - while (k) - { + Iterator ki; + ki = First(obj); + while (ki.key) { + k = ki.key; if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) @@ -202,7 +202,7 @@ public: Delete(ck); } } - k = Nextkey(obj); + ki = Next(ki); } indent_level -= 4; print_indent(0); @@ -261,11 +261,11 @@ public: print_indent(0); Printf( out, "\n", ++id, p ); indent_level += 4; - String *s; - for (s = Firstitem(p); s; s = Nextitem(p)) + Iterator s; + for (s = First(p); s.item; s = Next(s)) { print_indent(0); - Printf( out, "\n", s, ++id, s ); + Printf( out, "\n", s.item, ++id, s.item ); } indent_level -= 4; print_indent(0); @@ -304,16 +304,16 @@ public: Printf( out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p ); Xml_print_attributes( p ); indent_level += 4; - Node * n = Firstitem( p ); - while(n) + Iterator n = First(p); + while(n.key) { print_indent(0); - Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n ); - Xml_print_attributes( n ); + Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item ); + Xml_print_attributes( n.item ); Printf( out, "\n", markup ); print_indent(0); Printf( out, " />\n" ); - n = Nextkey(p); + n = Next(n); } indent_level -= 4; print_indent(0); diff --git a/SWIG/Source/Preprocessor/cpp.c b/SWIG/Source/Preprocessor/cpp.c index 3eb35fb35..fdbd33205 100644 --- a/SWIG/Source/Preprocessor/cpp.c +++ b/SWIG/Source/Preprocessor/cpp.c @@ -725,13 +725,12 @@ expand_macro(String_or_char *name, List *args) * ----------------------------------------------------------------------------- */ List *evaluate_args(List *x) { - String *a; + Iterator i; String *Preprocessor_replace(String *); - List *nl = NewList(); - - for (a = Firstitem(x); a; a = Nextitem(x)) { - Append(nl,Preprocessor_replace(a)); + + for (i = First(x); i.item; i = Next(i)) { + Append(nl,Preprocessor_replace(i.item)); } return nl; } diff --git a/SWIG/Source/Swig/naming.c b/SWIG/Source/Swig/naming.c index 8f7c380ef..259cab30f 100644 --- a/SWIG/Source/Swig/naming.c +++ b/SWIG/Source/Swig/naming.c @@ -44,7 +44,7 @@ static int name_mangle(String *r) { Replaceall(r,"::","_"); c = Char(r); while (*c) { - if (!isalnum(*c) && (*c != '_')) { + if (!isalnum((int) *c) && (*c != '_')) { special = 1; switch(*c) { case '+': @@ -480,7 +480,7 @@ Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *dec void Swig_name_object_inherit(Hash *namehash, String *base, String *derived) { - String *key; + Iterator ki; String *bprefix; String *dprefix; char *cbprefix; @@ -492,23 +492,23 @@ Swig_name_object_inherit(Hash *namehash, String *base, String *derived) { dprefix = NewStringf("%s::",derived); cbprefix = Char(bprefix); plen = strlen(cbprefix); - for (key = Firstkey(namehash); key; key = Nextkey(namehash)) { - char *k = Char(key); + for (ki = First(namehash); ki.key; ki = Next(ki)) { + char *k = Char(ki.key); if (strncmp(k,cbprefix,plen) == 0) { Hash *n, *newh; - String *nkey, *okey; - + String *nkey; + Iterator oi; + nkey = NewStringf("%s%s",dprefix,k+plen); - n = Getattr(namehash,key); + n = ki.item; newh = Getattr(namehash,nkey); if (!newh) { newh = NewHash(); Setattr(namehash,nkey,newh); } - for (okey = Firstkey(n); okey; okey = Nextkey(n)) { - String *ovalue = Getattr(n,okey); - if (!Getattr(newh,okey)) { - Setattr(newh,okey,Copy(ovalue)); + for (oi = First(n); oi.key; oi = Next(oi)) { + if (!Getattr(newh,oi.key)) { + Setattr(newh,oi.key,Copy(oi.item)); } } } @@ -522,13 +522,14 @@ Swig_name_object_inherit(Hash *namehash, String *base, String *derived) { * ----------------------------------------------------------------------------- */ static void merge_features(Hash *features, Node *n) { - String *key; + Iterator ki; + if (!features) return; - for (key = Firstkey(features); key; key = Nextkey(features)) { - if (Getattr(n,key)) { + for (ki = First(features); ki.key; ki = Next(ki)) { + if (Getattr(n,ki.key)) { continue; } - Setattr(n,key,Copy(Getattr(features,key))); + Setattr(n,ki.key,Copy(ki.item)); } } diff --git a/SWIG/Source/Swig/symbol.c b/SWIG/Source/Swig/symbol.c index 60d0732ca..ddf2d72e7 100644 --- a/SWIG/Source/Swig/symbol.c +++ b/SWIG/Source/Swig/symbol.c @@ -1118,15 +1118,15 @@ Swig_symbol_type_qualify(SwigType *t, Symtab *st) { String *tprefix, *tsuffix; SwigType *qprefix; List *targs; - String *tparm; + Iterator ti; tprefix = SwigType_templateprefix(e); tsuffix = SwigType_templatesuffix(e); qprefix = Swig_symbol_type_qualify(tprefix,st); targs = SwigType_parmlist(e); Printf(qprefix,"<("); - for (tparm = Firstitem(targs); tparm;) { - String *qparm = Swig_symbol_type_qualify(tparm,st); - /* Printf(stdout,"qparm = '%s', tparm = '%s'\n", qparm, tparm);*/ + for (ti = First(targs); ti.item;) { + String *qparm = Swig_symbol_type_qualify(ti.item,st); + /* Printf(stdout,"qparm = '%s', tparm = '%s'\n", qparm, ti.item);*/ while (1) { /* It is possible for an integer to show up here. If so, we need to evaluate it */ { @@ -1155,8 +1155,8 @@ Swig_symbol_type_qualify(SwigType *t, Symtab *st) { } } Append(qprefix,qparm); - tparm = Nextitem(targs); - if (tparm) { + ti = Next(ti); + if (ti.item) { Putc(',',qprefix); } Delete(qparm); @@ -1175,14 +1175,14 @@ Swig_symbol_type_qualify(SwigType *t, Symtab *st) { } Append(result,e); } else if (SwigType_isfunction(e)) { + Iterator pi; List *parms = SwigType_parmlist(e); String *s = NewString("f("); - String *p; - p = Firstitem(parms); - while (p) { - Append(s,Swig_symbol_type_qualify(p,st)); - p = Nextitem(parms); - if (p) { + pi = First(parms); + while (pi.item) { + Append(s,Swig_symbol_type_qualify(pi.item,st)); + pi = Next(pi); + if (pi.item) { Append(s,","); } } @@ -1269,7 +1269,7 @@ Swig_symbol_string_qualify(String *s, Symtab *st) { r = NewString(""); c = Char(s); while (*c) { - if (isalpha(*c) || (*c == '_') || (*c == ':')) { + if (isalpha((int)*c) || (*c == '_') || (*c == ':')) { Putc(*c,id); have_id = 1; } else { diff --git a/SWIG/Source/Swig/tree.c b/SWIG/Source/Swig/tree.c index 3107e4dcf..fe262fe5c 100644 --- a/SWIG/Source/Swig/tree.c +++ b/SWIG/Source/Swig/tree.c @@ -70,13 +70,14 @@ static void print_indent(int l) { void Swig_print_node(Node *obj) { - String *k; + Iterator ki; Node *cobj; print_indent(0); Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj)); - k = Firstkey(obj); - while (k) { + ki = First(obj); + while (ki.key) { + String *k = ki.key; if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) || (Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) || (Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) { @@ -99,7 +100,7 @@ Swig_print_node(Node *obj) { Printf(stdout,"%-12s - 0x%x\n", k, Getattr(obj,k)); } } - k = Nextkey(obj); + ki = Next(ki); } cobj = firstChild(obj); if (cobj) { @@ -187,13 +188,11 @@ deleteNode(Node *n) { Node * copyNode(Node *n) { - String *key; - DOH *v; + Iterator ki; Node *c = NewHash(); - for (key = Firstkey(n); key; key = Nextkey(n)) { - v = Getattr(n,key); - if (DohIsString(v)) { - Setattr(c,key,Copy(v)); + for (ki = First(n); ki.key; ki = Next(ki)) { + if (DohIsString(ki.item)) { + Setattr(c,ki.key,Copy(ki.item)); } } Setfile(c,Getfile(n)); @@ -336,11 +335,11 @@ Swig_save(const char *ns, Node *n, ...) { void Swig_restore(Node *n) { - String *key; char temp[512]; int len; List *l; String *ns; + Iterator ki; ns = Getattr(n,"view"); assert(ns); @@ -351,15 +350,15 @@ Swig_restore(Node *n) { strcat(temp,":"); len = strlen(temp); - for (key = Firstkey(n); key; key = Nextkey(n)) { - if (Strncmp(temp,key,len) == 0) { - Append(l,key); + for (ki = First(n); ki.key; ki = Next(ki)) { + if (Strncmp(temp,ki.key,len) == 0) { + Append(l,ki.key); } } - for (key = Firstitem(l); key; key = Nextitem(l)) { - DOH *obj = Getattr(n,key); - Setattr(n,Char(key)+len,obj); - Delattr(n,key); + for (ki = First(l); ki.item; ki = Next(ki)) { + DOH *obj = Getattr(n,ki.item); + Setattr(n,Char(ki.item)+len,obj); + Delattr(n,ki.item); } Delete(l); } diff --git a/SWIG/Source/Swig/typemap.c b/SWIG/Source/Swig/typemap.c index 02bafeccc..6af9224ae 100644 --- a/SWIG/Source/Swig/typemap.c +++ b/SWIG/Source/Swig/typemap.c @@ -397,15 +397,14 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { if (sm) { /* Got a typemap. Need to only merge attributes for methods that match our signature */ - String *key; - + Iterator ki; match = 1; - for (key = Firstkey(sm); key; key = Nextkey(sm)) { + for (ki = First(sm); ki.key; ki = Next(ki)) { /* Check for a signature match with the source signature */ - if ((count_args(key) == narg) && (Strstr(key,ssig))) { + if ((count_args(ki.key) == narg) && (Strstr(ki.key,ssig))) { String *oldm; /* A typemap we have to copy */ - String *nkey = Copy(key); + String *nkey = Copy(ki.key); Replace(nkey,ssig,dsig,DOH_REPLACE_ANY); /* Make sure the typemap doesn't already exist in the target map */ @@ -415,7 +414,7 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { String *code; ParmList *locals; ParmList *kwargs; - Hash *sm1 = Getattr(sm,key); + Hash *sm1 = ki.item; code = Getattr(sm1,"code"); locals = Getattr(sm1,"locals"); @@ -474,14 +473,15 @@ Swig_typemap_clear_apply(Parm *parms) { } if (tm) { /* Clear typemaps that match our signature */ - String *key, *key2; - for (key = Firstkey(tm); key; key = Nextkey(tm)) { - if (Strncmp(key,"tmap:",5) == 0) { - int na = count_args(key); - if ((na == narg) && Strstr(key,tsig)) { - Hash *h = Getattr(tm,key); - for (key2 = Firstkey(h); key2; key2 = Nextkey(h)) { - Delattr(h,key2); + Iterator ki, ki2; + + for (ki = First(tm); ki.key; ki = Next(ki)) { + if (Strncmp(ki.key,"tmap:",5) == 0) { + int na = count_args(ki.key); + if ((na == narg) && Strstr(ki.key,tsig)) { + Hash *h = ki.item; + for (ki2 = First(h); ki2.key; ki2 = Next(ki2)) { + Delattr(h,ki2.key); } } } @@ -1427,8 +1427,8 @@ static List *split_embedded(String *s) { } if (*c == '(') level++; if (*c == ')') level--; - if (isspace(*c) && leading) start++; - if (!isspace(*c)) leading = 0; + if (isspace((int)*c) && leading) start++; + if (!isspace((int)*c)) leading = 0; c++; } return args; @@ -1449,7 +1449,7 @@ static void split_var(String *s, String **name, String **value) { *name = NewStringWithSize(c,eq-c); /* Look for $n variables */ - if (isdigit(*(c))) { + if (isdigit((int)*(c))) { /* Parse the value as a type */ String *v; Parm *p; @@ -1552,9 +1552,9 @@ void replace_embedded_typemap(String *s, Wrapper *f) { if (!Getattr(first,attr)) { /* Should be no more matches. Hack??? */ /* Replace all of the remaining variables */ - String *key; - for (key = Firstkey(vars); key; key = Nextkey(vars)) { - Replace(tm,key,Getattr(vars,key), DOH_REPLACE_ANY); + Iterator ki; + for (ki = First(vars); ki.key; ki = Next(ki)) { + Replace(tm,ki.key,ki.item, DOH_REPLACE_ANY); } /* Do the replacement */ Replace(s,tmp,tm, DOH_REPLACE_ANY); diff --git a/SWIG/Source/Swig/typeobj.c b/SWIG/Source/Swig/typeobj.c index ee3a2bde2..2de48be0f 100644 --- a/SWIG/Source/Swig/typeobj.c +++ b/SWIG/Source/Swig/typeobj.c @@ -695,9 +695,10 @@ ParmList * SwigType_function_parms(SwigType *t) { List *l = SwigType_parmlist(t); Hash *p, *pp = 0, *firstp = 0; - DOH *obj; - for (obj = Firstitem(l); obj; obj = Nextitem(l)) { - p = NewParm(obj,0); + Iterator o; + + for (o = First(l); o.item; o = Next(o)) { + p = NewParm(o.item,0); if (!firstp) firstp = p; if (pp) { set_nextSibling(pp,p); @@ -963,7 +964,7 @@ SwigType_strip_qualifiers(SwigType *t) { static Hash *memoize_stripped = 0; SwigType *r; List *l; - SwigType *e; + Iterator ei; if (!memoize_stripped) memoize_stripped = NewHash(); r = Getattr(memoize_stripped,t); @@ -971,9 +972,10 @@ SwigType_strip_qualifiers(SwigType *t) { l = SwigType_split(t); r = NewString(""); - for (e = Firstitem(l); e; e = Nextitem(l)) { - if (SwigType_isqualifier(e)) continue; - Append(r,e); + + for (ei = First(l);ei.item; ei = Next(ei)) { + if (SwigType_isqualifier(ei.item)) continue; + Append(r,ei.item); } Delete(l); { diff --git a/SWIG/Source/Swig/typesys.c b/SWIG/Source/Swig/typesys.c index f1820c8fa..a1f6a70e5 100644 --- a/SWIG/Source/Swig/typesys.c +++ b/SWIG/Source/Swig/typesys.c @@ -366,27 +366,26 @@ SwigType_attach_symtab(Symtab *sym) { * ----------------------------------------------------------------------------- */ void SwigType_print_scope(Typetab *t) { - String *key; Hash *ttab; - String *tkey; + Iterator i,j; - for (tkey = Firstkey(scopes); tkey; tkey = Nextkey(scopes)) { - t = Getattr(scopes,tkey); - ttab = Getattr(t,"typetab"); + for (i = First(scopes); i.key; i = Next(i)) { + t = i.item; + ttab = Getattr(i.item,"typetab"); - Printf(stdout,"Type scope '%s' (%x)\n", tkey, t); + Printf(stdout,"Type scope '%s' (%x)\n", i.key, i.item); { - List *inherit = Getattr(t,"inherit"); + List *inherit = Getattr(i.item,"inherit"); if (inherit) { - Typetab *it; - for (it = Firstitem(inherit); it; it = Nextitem(inherit)) { - Printf(stdout," Inherits from '%s' (%x)\n", Getattr(it,"qname"), it); + Iterator j; + for (j = First(inherit); j.item; j = Next(j)) { + Printf(stdout," Inherits from '%s' (%x)\n", Getattr(j.item,"qname"), j.item); } } } Printf(stdout,"-------------------------------------------------------------\n"); - for (key = Firstkey(ttab); key; key = Nextkey(ttab)) { - Printf(stdout,"%40s -> %s\n", key, Getattr(ttab,key)); + for (j = First(ttab); j.key; j = Next(j)) { + Printf(stdout,"%40s -> %s\n", j.key, j.item); } } } @@ -860,14 +859,15 @@ SwigType *SwigType_typedef_qualified(SwigType *t) /* Template. We need to qualify template parameters as well as the template itself */ String *tprefix, *qprefix; String *tsuffix; + Iterator pi; Parm *p; List *parms = SwigType_parmlist(e); tprefix = SwigType_templateprefix(e); tsuffix = SwigType_templatesuffix(e); qprefix = SwigType_typedef_qualified(tprefix); Printv(qprefix,"<(",NIL); - p = Firstitem(parms); - while (p) { + pi = First(parms); + while ((p = pi.item)) { String *qt = SwigType_typedef_qualified(p); if ((Strcmp(qt,p) == 0)) { /* && (!Swig_scopename_check(qt))) { */ /* No change in value. It is entirely possible that the parameter is an integer value. @@ -911,8 +911,8 @@ SwigType *SwigType_typedef_qualified(SwigType *t) Append(qprefix,qt); } Delete(qt); - p= Nextitem(parms); - if (p) { + pi= Next(pi); + if (pi.item) { Append(qprefix,","); } } @@ -933,14 +933,14 @@ SwigType *SwigType_typedef_qualified(SwigType *t) } else if (SwigType_isfunction(e)) { List *parms = SwigType_parmlist(e); String *s = NewString("f("); - String *p; - p = Firstitem(parms); - while (p) { - String *pq = SwigType_typedef_qualified(p); + Iterator pi; + pi = First(parms); + while (pi.item) { + String *pq = SwigType_typedef_qualified(pi.item); Append(s,pq); Delete(pq); - p = Nextitem(parms); - if (p) { + pi = Next(pi); + if (pi.item) { Append(s,","); } } @@ -1350,26 +1350,26 @@ List *SwigType_equivalent_mangle(String *ms, Hash *checked, Hash *found) { Setattr(ch, ms, "1"); mh = Getattr(r_mangled,ms); if (mh) { - String *key; - key = Firstkey(mh); - while (key) { + Iterator ki; + ki = First(mh); + while (ki.key) { Hash *rh; - if (Getattr(ch,key)) { - key = Nextkey(mh); + if (Getattr(ch,ki.key)) { + ki = Next(ki); continue; } - Setattr(ch,key,"1"); - rh = Getattr(r_resolved,key); + Setattr(ch,ki.key,"1"); + rh = Getattr(r_resolved,ki.key); if (rh) { - String *rkey; - rkey = Firstkey(rh); - while (rkey) { - Setattr(h,rkey,"1"); - SwigType_equivalent_mangle(rkey,ch,h); - rkey = Nextkey(rh); + Iterator rk; + rk = First(rh); + while (rk.key) { + Setattr(h,rk.key,"1"); + SwigType_equivalent_mangle(rk.key,ch,h); + rk = Next(rk); } } - key = Nextkey(mh); + ki = Next(ki); } } check_exit: @@ -1404,24 +1404,24 @@ String *SwigType_clientdata_collect(String *ms, Hash *checked) { Setattr(ch, ms, "1"); mh = Getattr(r_mangled,ms); if (mh) { - String *key; - key = Firstkey(mh); - while (key) { + Iterator ki; + ki = First(mh); + while (ki.key) { Hash *rh; - Setattr(ch,key,"1"); - clientdata = Getattr(r_clientdata,key); + Setattr(ch,ki.key,"1"); + clientdata = Getattr(r_clientdata,ki.key); if (clientdata) goto check_exit; - rh = Getattr(r_resolved,key); + rh = Getattr(r_resolved,ki.key); if (rh) { - String *rkey; - rkey = Firstkey(rh); - while (rkey) { - clientdata = SwigType_clientdata_collect(rkey,ch); + Iterator rk; + rk = First(rh); + while (rk.key) { + clientdata = SwigType_clientdata_collect(rk.key,ch); if (clientdata) goto check_exit; - rkey = Nextkey(rh); + rk = Next(rk); } } - key = Nextkey(mh); + ki = Next(ki); } } check_exit: @@ -1515,48 +1515,49 @@ SwigType_issubtype(SwigType *t1, SwigType *t2) { * ----------------------------------------------------------------------------- */ void SwigType_inherit_equiv(File *out) { - String *rkey, *bkey, *ckey; + String *ckey; String *prefix, *base; Hash *sub; Hash *rh; List *rlist; + Iterator rk, bk, ck; if (!conversions) conversions = NewHash(); if (!subclass) subclass = NewHash(); - rkey = Firstkey(r_resolved); - while (rkey) { + rk = First(r_resolved); + while (rk.key) { /* rkey is a fully qualified type. We strip all of the type constructors off of it just to get the base */ - base = SwigType_base(rkey); + base = SwigType_base(rk.key); /* Check to see whether the base is recorded in the subclass table */ sub = Getattr(subclass,base); Delete(base); if (!sub) { - rkey = Nextkey(r_resolved); + rk = Next(rk); continue; } /* This type has subclasses. We now need to walk through these subtypes and generate pointer converion functions */ - rh = Getattr(r_resolved, rkey); + rh = Getattr(r_resolved, rk.key); rlist = NewList(); - for (ckey = Firstkey(rh); ckey; ckey = Nextkey(rh)) { - Append(rlist,ckey); + for (ck = First(rh); ck.key; ck = Next(ck)) { + Append(rlist,ck.key); } - /* Printf(stdout,"rkey = '%s'\n", rkey); + /* Printf(stdout,"rk.key = '%s'\n", rk.key); Printf(stdout,"rh = %x '%s'\n", rh,rh); */ - bkey = Firstkey(sub); - while (bkey) { - prefix= SwigType_prefix(rkey); - Append(prefix,bkey); + bk = First(sub); + while (bk.key) { + prefix= SwigType_prefix(rk.key); + Append(prefix,bk.key); /* Printf(stdout,"set %x = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */ Setattr(rh,SwigType_manglestr(prefix),prefix); - ckey = NewStringf("%s+%s",SwigType_manglestr(prefix), SwigType_manglestr(rkey)); + ckey = NewStringf("%s+%s",SwigType_manglestr(prefix), SwigType_manglestr(rk.key)); if (!Getattr(conversions,ckey)) { - String *convname = NewStringf("%sTo%s", SwigType_manglestr(prefix), SwigType_manglestr(rkey)); + String *convname = NewStringf("%sTo%s", SwigType_manglestr(prefix), SwigType_manglestr(rk.key)); Printf(out,"static void *%s(void *x) {\n", convname); - Printf(out," return (void *)((%s) %s ((%s) x));\n", SwigType_lstr(rkey,0), Getattr(sub,bkey), SwigType_lstr(prefix,0)); + Printf(out," return (void *)((%s) %s ((%s) x));\n", SwigType_lstr(rk.key,0), Getattr(sub,bk.key), SwigType_lstr(prefix,0)); Printf(out,"}\n"); Setattr(conversions,ckey,convname); Delete(ckey); @@ -1565,39 +1566,40 @@ void SwigType_inherit_equiv(File *out) { { Hash *r = Getattr(r_resolved, prefix); if (r) { - String *rrkey = Firstkey(r); - while (rrkey) { - String *rlkey; + Iterator rrk; + rrk=First(r); + while (rrk.key) { + Iterator rlk; String *rkeymangle; /* Make sure this name equivalence is not due to inheritance */ - if (Cmp(prefix, Getattr(r,rrkey)) == 0) { - rkeymangle = SwigType_manglestr(rkey); - ckey = NewStringf("%s+%s", rrkey, rkeymangle); + if (Cmp(prefix, Getattr(r,rrk.key)) == 0) { + rkeymangle = SwigType_manglestr(rk.key); + ckey = NewStringf("%s+%s", rrk.key, rkeymangle); if (!Getattr(conversions, ckey)) { Setattr(conversions, ckey, convname); } Delete(ckey); - for (rlkey = Firstitem(rlist); rlkey; rlkey = Nextitem(rlist)) { - ckey = NewStringf("%s+%s", rrkey, rlkey); + for (rlk = First(rlist); rlk.item; rlk = Next(rlk)) { + ckey = NewStringf("%s+%s", rrk.key, rlk.item); Setattr(conversions, ckey, convname); Delete(ckey); } Delete(rkeymangle); /* This is needed to pick up other alternative names for the same type. Needed to make templates work */ - Setattr(rh,rrkey,Getattr(r,rrkey)); + Setattr(rh,rrk.key,rrk.item); } - rrkey = Nextkey(r); + rrk = Next(rrk); } } } Delete(convname); } Delete(prefix); - bkey = Nextkey(sub); + bk = Next(bk); } - rkey = Nextkey(r_resolved); + rk = Next(rk); } } @@ -1609,7 +1611,7 @@ void SwigType_inherit_equiv(File *out) { void SwigType_emit_type_table(File *f_forward, File *f_table) { - DOH *key; + Iterator ki; String *types, *table; int i = 0; @@ -1643,36 +1645,37 @@ SwigType_emit_type_table(File *f_forward, File *f_table) { table = NewString(""); types = NewString(""); Printf(table,"static swig_type_info *swig_types_initial[] = {\n"); - key = Firstkey(r_mangled); + + ki = First(r_mangled); Printf(f_forward,"\n/* -------- TYPES TABLE (BEGIN) -------- */\n\n"); - while (key) { + while (ki.key) { List *el; - String *en; + Iterator ei; String *cd; - Printf(f_forward,"#define SWIGTYPE%s swig_types[%d] \n", key, i); - Printv(types,"static swig_type_info _swigt_", key, "[] = {", NIL); + Printf(f_forward,"#define SWIGTYPE%s swig_types[%d] \n", ki.key, i); + Printv(types,"static swig_type_info _swigt_", ki.key, "[] = {", NIL); - cd = SwigType_clientdata_collect(key,0); + cd = SwigType_clientdata_collect(ki.key,0); if (!cd) cd = "0"; - Printv(types,"{\"", key, "\", 0, \"", SwigType_str(Getattr(r_ltype,key),0),"\", ", cd, "},", NIL); - el = SwigType_equivalent_mangle(key,0,0); - for (en = Firstitem(el); en; en = Nextitem(el)) { + Printv(types,"{\"", ki.key, "\", 0, \"", SwigType_str(Getattr(r_ltype,ki.key),0),"\", ", cd, "},", NIL); + el = SwigType_equivalent_mangle(ki.key,0,0); + for (ei = First(el); ei.item; ei = Next(ei)) { String *ckey; String *conv; - ckey = NewStringf("%s+%s", en, key); + ckey = NewStringf("%s+%s", ei.item, ki.key); conv = Getattr(conversions,ckey); if (conv) { - Printf(types,"{\"%s\", %s},", en, conv); + Printf(types,"{\"%s\", %s},", ei.item, conv); } else { - Printf(types,"{\"%s\"},", en); + Printf(types,"{\"%s\"},", ei.item); } Delete(ckey); } Delete(el); Printf(types,"{0}};\n"); - Printv(table, "_swigt_", key, ", \n", NIL); - key = Nextkey(r_mangled); + Printv(table, "_swigt_", ki.key, ", \n", NIL); + ki = Next(ki); i++; }