Fix #2933129 - typemaps not being found when the unary scope operator (::) is used to denote global scope

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11827 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-01-22 20:39:54 +00:00
commit f112e4bac1
10 changed files with 290 additions and 30 deletions

View file

@ -893,7 +893,11 @@ String *Swig_scopename_suffix(const String *s) {
/* -----------------------------------------------------------------------------
* Swig_scopename_check()
*
* Checks to see if a name is qualified with a scope name
* Checks to see if a name is qualified with a scope name, examples:
* foo -> 0
* ::foo -> 1
* foo::bar -> 1
* foo< ::bar > -> 0
* ----------------------------------------------------------------------------- */
int Swig_scopename_check(const String *s) {

View file

@ -1094,6 +1094,25 @@ void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
Delete(elem);
}
/* -----------------------------------------------------------------------------
* SwigType_remove_global_scope_prefix()
*
* Removes the unary scope operator (::) prefix indicating global scope in all
* components of the type
* ----------------------------------------------------------------------------- */
SwigType *SwigType_remove_global_scope_prefix(const SwigType *t) {
SwigType *result;
const char *type = Char(t);
if (strncmp(type, "::", 2) == 0)
type += 2;
result = NewString(type);
Replaceall(result, ".::", ".");
Replaceall(result, "(::", "(");
Replaceall(result, "enum ::", "enum ");
return result;
}
/* -----------------------------------------------------------------------------
* SwigType_check_decl()
*

View file

@ -166,6 +166,7 @@ extern "C" {
extern SwigType *SwigType_array_type(SwigType *t);
extern String *SwigType_default(SwigType *t);
extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep);
extern SwigType *SwigType_remove_global_scope_prefix(const SwigType *t);
extern SwigType *SwigType_alttype(SwigType *t, int ltmap);
extern void SwigType_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl);

View file

@ -62,47 +62,53 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper
static Hash *typemaps[MAX_SCOPE];
static int tm_scope = 0;
static Hash *get_typemap(int tm_scope, SwigType *type) {
static Hash *get_typemap(int tm_scope, const SwigType *type) {
Hash *tm = 0;
SwigType *dtype = 0;
SwigType *hashtype;
if (SwigType_istemplate(type)) {
String *ty = Swig_symbol_template_deftype(type, 0);
dtype = Swig_symbol_type_qualify(ty, 0);
/* Printf(stderr,"gettm %s %s\n", type, dtype); */
type = dtype;
Delete(ty);
}
tm = Getattr(typemaps[tm_scope], type);
/* remove unary scope operator (::) prefix indicating global scope for looking up in the hashmap */
hashtype = SwigType_remove_global_scope_prefix(type);
tm = Getattr(typemaps[tm_scope], hashtype);
if (dtype) {
if (!tm) {
String *t_name = SwigType_templateprefix(type);
if (!Equal(t_name, type)) {
String *t_name = SwigType_templateprefix(hashtype);
if (!Equal(t_name, hashtype)) {
tm = Getattr(typemaps[tm_scope], t_name);
}
Delete(t_name);
}
Delete(dtype);
}
Delete(hashtype);
return tm;
}
static void set_typemap(int tm_scope, SwigType *type, Hash *tm) {
SwigType *dtype = 0;
static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) {
SwigType *hashtype = 0;
if (SwigType_istemplate(type)) {
String *ty = Swig_symbol_template_deftype(type, 0);
dtype = Swig_symbol_type_qualify(ty, 0);
/* Printf(stderr,"settm %s %s\n", type, dtype); */
type = dtype;
String *tyq = Swig_symbol_type_qualify(ty, 0);
hashtype = SwigType_remove_global_scope_prefix(tyq);
Delete(tyq);
Delete(ty);
} else {
dtype = Copy(type);
type = dtype;
hashtype = SwigType_remove_global_scope_prefix(type);
}
Setattr(typemaps[tm_scope], type, tm);
Delete(dtype);
/* note that the unary scope operator (::) prefix indicating global scope has been removed for storing in the hashmap */
Setattr(typemaps[tm_scope], hashtype, tm);
Delete(hashtype);
}

View file

@ -840,7 +840,8 @@ SwigType *SwigType_typedef_resolve_all(SwigType *t) {
*
* Given a type declaration, this function tries to fully qualify it according to
* typedef scope rules.
* Inconsistency to be fixed: ::Foo returns ::Foo, whereas ::Foo * returns Foo *
* If the unary scope operator (::) is used as a prefix to the type to denote global
* scope, it is left in place.
* ----------------------------------------------------------------------------- */
SwigType *SwigType_typedef_qualified(SwigType *t) {
@ -848,10 +849,6 @@ SwigType *SwigType_typedef_qualified(SwigType *t) {
String *result;
int i, len;
if (strncmp(Char(t), "::", 2) == 0) {
return Copy(t);
}
if (!typedef_qualified_cache)
typedef_qualified_cache = NewHash();
result = Getattr(typedef_qualified_cache, t);
@ -999,10 +996,6 @@ SwigType *SwigType_typedef_qualified(SwigType *t) {
Delete(qprefix);
Delete(parms);
}
if (strncmp(Char(e), "::", 2) == 0) {
Delitem(e, 0);
Delitem(e, 0);
}
Append(result, e);
Delete(ty);
} else if (SwigType_isfunction(e)) {