Merge pull request #522 from vadz/drop-tm-scope

Remove unused support for typemap scopes
This commit is contained in:
William S Fulton 2015-09-15 23:06:37 +01:00
commit d20de7bcfc
2 changed files with 157 additions and 217 deletions

View file

@ -409,8 +409,6 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f); extern String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f);
extern String *Swig_typemap_lookup_out(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f, String *actioncode); extern String *Swig_typemap_lookup_out(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f, String *actioncode);
extern void Swig_typemap_new_scope(void);
extern Hash *Swig_typemap_pop_scope(void);
extern void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *parms, Wrapper *f); extern void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *parms, Wrapper *f);

View file

@ -59,13 +59,9 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper
* *
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
#define MAX_SCOPE 32 static Hash *typemaps;
static Hash *get_typemap(const SwigType *type) {
static Hash *typemaps[MAX_SCOPE];
static int tm_scope = 0;
static Hash *get_typemap(int tm_scope, const SwigType *type) {
Hash *tm = 0; Hash *tm = 0;
SwigType *dtype = 0; SwigType *dtype = 0;
SwigType *hashtype; SwigType *hashtype;
@ -79,7 +75,7 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) {
/* remove unary scope operator (::) prefix indicating global scope for looking up in the hashmap */ /* remove unary scope operator (::) prefix indicating global scope for looking up in the hashmap */
hashtype = SwigType_remove_global_scope_prefix(type); hashtype = SwigType_remove_global_scope_prefix(type);
tm = Getattr(typemaps[tm_scope], hashtype); tm = Getattr(typemaps, hashtype);
Delete(dtype); Delete(dtype);
Delete(hashtype); Delete(hashtype);
@ -87,7 +83,7 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) {
return tm; return tm;
} }
static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) { static void set_typemap(const SwigType *type, Hash **tmhash) {
SwigType *hashtype = 0; SwigType *hashtype = 0;
Hash *new_tm = 0; Hash *new_tm = 0;
assert(*tmhash == 0); assert(*tmhash == 0);
@ -96,7 +92,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
String *ty = Swig_symbol_template_deftype(rty, 0); String *ty = Swig_symbol_template_deftype(rty, 0);
String *tyq = Swig_symbol_type_qualify(ty, 0); String *tyq = Swig_symbol_type_qualify(ty, 0);
hashtype = SwigType_remove_global_scope_prefix(tyq); hashtype = SwigType_remove_global_scope_prefix(tyq);
*tmhash = Getattr(typemaps[tm_scope], hashtype); *tmhash = Getattr(typemaps, hashtype);
Delete(rty); Delete(rty);
Delete(tyq); Delete(tyq);
Delete(ty); Delete(ty);
@ -111,7 +107,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
} }
/* note that the unary scope operator (::) prefix indicating global scope has been removed from the type */ /* note that the unary scope operator (::) prefix indicating global scope has been removed from the type */
Setattr(typemaps[tm_scope], hashtype, *tmhash); Setattr(typemaps, hashtype, *tmhash);
Delete(hashtype); Delete(hashtype);
Delete(new_tm); Delete(new_tm);
@ -125,12 +121,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void Swig_typemap_init() { void Swig_typemap_init() {
int i; typemaps = NewHash();
for (i = 0; i < MAX_SCOPE; i++) {
typemaps[i] = 0;
}
typemaps[0] = NewHash();
tm_scope = 0;
} }
static String *typemap_method_name(const_String_or_char_ptr tmap_method) { static String *typemap_method_name(const_String_or_char_ptr tmap_method) {
@ -160,32 +151,6 @@ static String *typemap_method_name(const_String_or_char_ptr tmap_method) {
return s; return s;
} }
#if 0
/* -----------------------------------------------------------------------------
* Swig_typemap_new_scope()
*
* Create a new typemap scope
* ----------------------------------------------------------------------------- */
void Swig_typemap_new_scope() {
tm_scope++;
typemaps[tm_scope] = NewHash();
}
/* -----------------------------------------------------------------------------
* Swig_typemap_pop_scope()
*
* Pop the last typemap scope off
* ----------------------------------------------------------------------------- */
Hash *Swig_typemap_pop_scope() {
if (tm_scope > 0) {
return typemaps[tm_scope--];
}
return 0;
}
#endif
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* typemap_register() * typemap_register()
* *
@ -216,9 +181,9 @@ static void typemap_register(const_String_or_char_ptr tmap_method, ParmList *par
pname = Getattr(parms, "name"); pname = Getattr(parms, "name");
/* See if this type has been seen before */ /* See if this type has been seen before */
tm = get_typemap(tm_scope, type); tm = get_typemap(type);
if (!tm) { if (!tm) {
set_typemap(tm_scope, type, &tm); set_typemap(type, &tm);
} }
if (pname) { if (pname) {
/* See if parameter has been seen before */ /* See if parameter has been seen before */
@ -311,15 +276,12 @@ void Swig_typemap_register(const_String_or_char_ptr tmap_method, ParmList *parms
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* typemap_get() * typemap_get()
* *
* Retrieve typemap information from current scope. * Retrieve typemap information.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static Hash *typemap_get(SwigType *type, const_String_or_char_ptr name, int scope) { static Hash *typemap_get(SwigType *type, const_String_or_char_ptr name) {
Hash *tm, *tm1; Hash *tm, *tm1;
/* See if this type has been seen before */ tm = get_typemap(type);
if ((scope < 0) || (scope > tm_scope))
return 0;
tm = get_typemap(scope, type);
if (!tm) { if (!tm) {
return 0; return 0;
} }
@ -342,13 +304,11 @@ int Swig_typemap_copy(const_String_or_char_ptr tmap_method, ParmList *srcparms,
Parm *p; Parm *p;
String *pname; String *pname;
SwigType *ptype; SwigType *ptype;
int ts = tm_scope;
String *tm_methods, *multi_tmap_method; String *tm_methods, *multi_tmap_method;
if (ParmList_len(parms) != ParmList_len(srcparms)) if (ParmList_len(parms) != ParmList_len(srcparms))
return -1; return -1;
tm_method = typemap_method_name(tmap_method); tm_method = typemap_method_name(tmap_method);
while (ts >= 0) {
p = srcparms; p = srcparms;
tm_methods = NewString(tm_method); tm_methods = NewString(tm_method);
while (p) { while (p) {
@ -356,7 +316,7 @@ int Swig_typemap_copy(const_String_or_char_ptr tmap_method, ParmList *srcparms,
pname = Getattr(p, "name"); pname = Getattr(p, "name");
/* Lookup the type */ /* Lookup the type */
tm = typemap_get(ptype, pname, ts); tm = typemap_get(ptype, pname);
if (!tm) if (!tm)
break; break;
@ -385,8 +345,7 @@ int Swig_typemap_copy(const_String_or_char_ptr tmap_method, ParmList *srcparms,
Delete(parms_str); Delete(parms_str);
return 0; return 0;
} }
ts--;
}
/* Not found */ /* Not found */
return -1; return -1;
@ -411,7 +370,7 @@ void Swig_typemap_clear(const_String_or_char_ptr tmap_method, ParmList *parms) {
while (p) { while (p) {
type = Getattr(p, "type"); type = Getattr(p, "type");
name = Getattr(p, "name"); name = Getattr(p, "name");
tm = typemap_get(type, name, tm_scope); tm = typemap_get(type, name);
if (!tm) if (!tm)
return; return;
p = nextSibling(p); p = nextSibling(p);
@ -452,7 +411,6 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
String *ssig, *dsig; String *ssig, *dsig;
Parm *p, *np, *lastp, *dp, *lastdp = 0; Parm *p, *np, *lastp, *dp, *lastdp = 0;
int narg = 0; int narg = 0;
int ts = tm_scope;
SwigType *type = 0, *name; SwigType *type = 0, *name;
Hash *tm, *sm; Hash *tm, *sm;
int match = 0; int match = 0;
@ -480,9 +438,9 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
/* make sure a typemap node exists for the last destination node */ /* make sure a typemap node exists for the last destination node */
type = Getattr(lastdp, "type"); type = Getattr(lastdp, "type");
tm = get_typemap(tm_scope, type); tm = get_typemap(type);
if (!tm) { if (!tm) {
set_typemap(tm_scope, type, &tm); set_typemap(type, &tm);
} }
name = Getattr(lastdp, "name"); name = Getattr(lastdp, "name");
if (name) { if (name) {
@ -501,10 +459,8 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
type = Getattr(lastp, "type"); type = Getattr(lastp, "type");
name = Getattr(lastp, "name"); name = Getattr(lastp, "name");
while (ts >= 0) {
/* See if there is a matching typemap in this scope */ /* See if there is a matching typemap in this scope */
sm = typemap_get(type, name, ts); sm = typemap_get(type, name);
/* if there is not matching, look for a typemap in the /* if there is not matching, look for a typemap in the
original typedef, if any, like in: original typedef, if any, like in:
@ -516,7 +472,7 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
if (!sm) { if (!sm) {
SwigType *ntype = SwigType_typedef_resolve(type); SwigType *ntype = SwigType_typedef_resolve(type);
if (ntype && (Cmp(ntype, type) != 0)) { if (ntype && (Cmp(ntype, type) != 0)) {
sm = typemap_get(ntype, name, ts); sm = typemap_get(ntype, name);
} }
Delete(ntype); Delete(ntype);
} }
@ -563,8 +519,6 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
} }
} }
} }
ts--;
}
Delete(ssig); Delete(ssig);
Delete(dsig); Delete(dsig);
return match; return match;
@ -597,7 +551,7 @@ void Swig_typemap_clear_apply(Parm *parms) {
} }
p = np; p = np;
} }
tm = get_typemap(tm_scope, Getattr(lastp, "type")); tm = get_typemap(Getattr(lastp, "type"));
if (!tm) { if (!tm) {
Delete(tsig); Delete(tsig);
return; return;
@ -711,7 +665,6 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
SwigType *primitive = 0; SwigType *primitive = 0;
SwigType *ctype = 0; SwigType *ctype = 0;
SwigType *ctype_unstripped = 0; SwigType *ctype_unstripped = 0;
int ts;
int isarray; int isarray;
const String *cname = 0; const String *cname = 0;
const String *cqualifiedname = 0; const String *cqualifiedname = 0;
@ -722,19 +675,17 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
cname = name; cname = name;
if ((qualifiedname) && Len(qualifiedname)) if ((qualifiedname) && Len(qualifiedname))
cqualifiedname = qualifiedname; cqualifiedname = qualifiedname;
ts = tm_scope;
if (debug_display) { if (debug_display) {
String *typestr = SwigType_str(type, cqualifiedname ? cqualifiedname : cname); String *typestr = SwigType_str(type, cqualifiedname ? cqualifiedname : cname);
Swig_diagnostic(Getfile(node), Getline(node), "Searching for a suitable '%s' typemap for: %s\n", tmap_method, typestr); Swig_diagnostic(Getfile(node), Getline(node), "Searching for a suitable '%s' typemap for: %s\n", tmap_method, typestr);
Delete(typestr); Delete(typestr);
} }
while (ts >= 0) {
ctype = Copy(type); ctype = Copy(type);
ctype_unstripped = Copy(ctype); ctype_unstripped = Copy(ctype);
while (ctype) { while (ctype) {
/* Try to get an exact type-match */ /* Try to get an exact type-match */
tm = get_typemap(ts, ctype); tm = get_typemap(ctype);
result = typemap_search_helper(debug_display, tm, tm_method, ctype, cqualifiedname, cname, &backup); result = typemap_search_helper(debug_display, tm, tm_method, ctype, cqualifiedname, cname, &backup);
if (result && Getattr(result, "code")) if (result && Getattr(result, "code"))
goto ret_result; goto ret_result;
@ -743,7 +694,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
/* Look for the type reduced to just the template prefix - for templated types without the template parameter list being specified */ /* Look for the type reduced to just the template prefix - for templated types without the template parameter list being specified */
SwigType *template_prefix = SwigType_istemplate_only_templateprefix(ctype); SwigType *template_prefix = SwigType_istemplate_only_templateprefix(ctype);
if (template_prefix) { if (template_prefix) {
tm = get_typemap(ts, template_prefix); tm = get_typemap(template_prefix);
result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup); result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup);
Delete(template_prefix); Delete(template_prefix);
if (result && Getattr(result, "code")) if (result && Getattr(result, "code"))
@ -757,7 +708,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
/* If working with arrays, strip away all of the dimensions and replace with "ANY". /* If working with arrays, strip away all of the dimensions and replace with "ANY".
See if that generates a match */ See if that generates a match */
SwigType *noarrays = strip_arrays(ctype); SwigType *noarrays = strip_arrays(ctype);
tm = get_typemap(ts, noarrays); tm = get_typemap(noarrays);
result = typemap_search_helper(debug_display, tm, tm_method, noarrays, cqualifiedname, cname, &backup); result = typemap_search_helper(debug_display, tm, tm_method, noarrays, cqualifiedname, cname, &backup);
Delete(noarrays); Delete(noarrays);
if (result && Getattr(result, "code")) if (result && Getattr(result, "code"))
@ -790,7 +741,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
primitive = SwigType_default_create(type); primitive = SwigType_default_create(type);
while (primitive) { while (primitive) {
tm = get_typemap(ts, primitive); tm = get_typemap(primitive);
result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup); result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup);
if (result && Getattr(result, "code")) if (result && Getattr(result, "code"))
goto ret_result; goto ret_result;
@ -805,8 +756,6 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
Delete(ctype); Delete(ctype);
ctype = 0; ctype = 0;
} }
ts--; /* Hmmm. Nothing found in this scope. Guess we'll go try another scope */
}
result = backup; result = backup;
ret_result: ret_result:
@ -2110,16 +2059,9 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void Swig_typemap_debug() { void Swig_typemap_debug() {
int ts;
int nesting_level = 2; int nesting_level = 2;
Printf(stdout, "---[ typemaps ]--------------------------------------------------------------\n"); Printf(stdout, "---[ typemaps ]--------------------------------------------------------------\n");
Swig_print(typemaps, nesting_level);
ts = tm_scope;
while (ts >= 0) {
Printf(stdout, "::: scope %d\n\n", ts);
Swig_print(typemaps[ts], nesting_level);
ts--;
}
Printf(stdout, "-----------------------------------------------------------------------------\n"); Printf(stdout, "-----------------------------------------------------------------------------\n");
} }