Factor out the common code within typemap_search() into typemap_search_helper()

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11838 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-02-01 20:23:34 +00:00
commit 590567d57f

View file

@ -630,6 +630,56 @@ static void debug_search_result_display(Node *tm) {
Printf(stdout, " None found\n");
}
/* -----------------------------------------------------------------------------
* typemap_search_helper()
*
* Helper function for typemap_search to see if there is a type match in the typemap
* tm. A match is sought in this order:
* %typemap(tm_method) ctype cqualifiedname
* %typemap(tm_method) ctype cname
* %typemap(tm_method) ctype
* ----------------------------------------------------------------------------- */
static Hash *typemap_search_helper(int debug_display, Hash *tm, const String *tm_method, SwigType *ctype, const String *cqualifiedname, const String *cname, Hash **backup) {
Hash *result = 0;
Hash *tm1;
if (debug_display && cqualifiedname)
Printf(stdout, " Looking for: %s\n", SwigType_str(ctype, cqualifiedname));
if (tm && cqualifiedname) {
tm1 = Getattr(tm, cqualifiedname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - qualified name match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
*backup = result;
}
}
if (debug_display && cname)
Printf(stdout, " Looking for: %s\n", SwigType_str(ctype, cname));
if (tm && cname) {
tm1 = Getattr(tm, cname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - name match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
*backup = result;
}
}
if (debug_display)
Printf(stdout, " Looking for: %s\n", SwigType_str(ctype, 0));
if (tm) {
result = Getattr(tm, tm_method); /* See if there is simply a type match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
*backup = result;
}
ret_result:
return result;
}
/* -----------------------------------------------------------------------------
* typemap_search()
*
@ -639,12 +689,11 @@ static void debug_search_result_display(Node *tm) {
* ----------------------------------------------------------------------------- */
static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type, const_String_or_char_ptr name, const_String_or_char_ptr qualifiedname, SwigType **matchtype, Node *node) {
Hash *result = 0, *tm, *tm1, *tma;
Hash *result = 0;
Hash *tm;
Hash *backup = 0;
SwigType *noarrays = 0;
SwigType *primitive = 0;
SwigType *ctype = 0;
SwigType *template_prefix = 0;
int ts;
int isarray;
const String *cname = 0;
@ -669,77 +718,19 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
while (ctype) {
/* Try to get an exact type-match */
tm = get_typemap(ts, ctype);
if (debug_display && cqualifiedname)
Printf(stdout, " Looking for: %s\n", SwigType_str(ctype, cqualifiedname));
if (tm && cqualifiedname) {
tm1 = Getattr(tm, cqualifiedname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - qualified name match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
backup = result;
}
}
if (debug_display && cname)
Printf(stdout, " Looking for: %s\n", SwigType_str(ctype, cname));
if (tm && cname) {
tm1 = Getattr(tm, cname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - name match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
backup = result;
}
}
if (debug_display)
Printf(stdout, " Looking for: %s\n", SwigType_str(ctype, 0));
if (tm) {
result = Getattr(tm, tm_method); /* See if there is simply a type match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
backup = result;
}
result = typemap_search_helper(debug_display, tm, tm_method, ctype, cqualifiedname, cname, &backup);
if (result)
goto ret_result;
/* look for the type reduced to just the template prefix */
Delete(template_prefix);
template_prefix = SwigType_istemplate_templateprefix(ctype);
if (template_prefix) {
tm = get_typemap(ts, template_prefix);
if (debug_display && cqualifiedname)
Printf(stdout, " Looking for: %s\n", SwigType_str(template_prefix, cqualifiedname));
if (tm && cqualifiedname) {
tm1 = Getattr(tm, cqualifiedname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - qualified name match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
backup = result;
}
}
if (debug_display && cname)
Printf(stdout, " Looking for: %s\n", SwigType_str(template_prefix, cname));
if (tm && cname) {
tm1 = Getattr(tm, cname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - name match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
backup = result;
}
}
if (debug_display)
Printf(stdout, " Looking for: %s\n", SwigType_str(template_prefix, 0));
if (tm) {
result = Getattr(tm, tm_method); /* See if there is simply a type match */
if (result && Getattr(result, "code"))
goto ret_result;
{
/* Look for the type reduced to just the template prefix */
SwigType *template_prefix = SwigType_istemplate_templateprefix(ctype);
if (template_prefix) {
tm = get_typemap(ts, template_prefix);
result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup);
Delete(template_prefix);
if (result)
backup = result;
goto ret_result;
}
}
@ -748,45 +739,12 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
if (isarray) {
/* If working with arrays, strip away all of the dimensions and replace with "ANY".
See if that generates a match */
if (!noarrays) {
noarrays = strip_arrays(ctype);
}
tma = get_typemap(ts, noarrays);
if (debug_display && cqualifiedname)
Printf(stdout, " Looking for: %s\n", SwigType_str(noarrays, cqualifiedname));
if (tma && cqualifiedname) {
tm1 = Getattr(tma, cqualifiedname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - qualified name match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
backup = result;
}
}
if (debug_display && cname)
Printf(stdout, " Looking for: %s\n", SwigType_str(noarrays, cname));
if (tma && cname) {
tm1 = Getattr(tma, cname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - name match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
backup = result;
}
}
if (debug_display)
Printf(stdout, " Looking for: %s\n", SwigType_str(noarrays, 0));
if (tma) {
result = Getattr(tma, tm_method); /* See if there is a type match */
if (result && Getattr(result, "code"))
goto ret_result;
if (result)
backup = result;
}
SwigType *noarrays = strip_arrays(ctype);
tm = get_typemap(ts, noarrays);
result = typemap_search_helper(debug_display, tm, tm_method, noarrays, cqualifiedname, cname, &backup);
Delete(noarrays);
noarrays = 0;
if (result)
goto ret_result;
}
/* No match so far. If the type is unstripped, we'll strip its
@ -820,33 +778,10 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
primitive = SwigType_default(type);
while (primitive) {
tm = get_typemap(ts, primitive);
if (debug_display && cqualifiedname)
Printf(stdout, " Looking for: %s\n", SwigType_str(primitive, cqualifiedname));
if (tm && cqualifiedname) {
tm1 = Getattr(tm, cqualifiedname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - qualified name match */
if (result)
goto ret_result;
}
}
if (debug_display && cname)
Printf(stdout, " Looking for: %s\n", SwigType_str(primitive, cname));
if (tm && cname) {
tm1 = Getattr(tm, cname);
if (tm1) {
result = Getattr(tm1, tm_method); /* See if there is a type - name match */
if (result)
goto ret_result;
}
}
if (debug_display)
Printf(stdout, " Looking for: %s\n", SwigType_str(primitive, 0));
if (tm) {
result = Getattr(tm, tm_method); /* See if there is simply a type match */
if (result)
goto ret_result;
}
result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup);
if (result)
goto ret_result;
{
SwigType *nprim = SwigType_default(primitive);
Delete(primitive);
@ -862,8 +797,6 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
result = backup;
ret_result:
Delete(template_prefix);
Delete(noarrays);
Delete(primitive);
if ((unstripped) && (unstripped != type))
Delete(unstripped);