add Swig_scopename_split

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7907 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-12-01 00:07:07 +00:00
commit 42a2d35e9a
4 changed files with 82 additions and 26 deletions

View file

@ -362,6 +362,58 @@ String *Swig_string_mangle(const String *s) {
* In this case, "A::B". Returns NULL if there is no base.
* ----------------------------------------------------------------------------- */
void
Swig_scopename_split(String *s, String **rprefix, String **rlast) {
char *tmp = Char(s);
char *c = tmp;
char *cc = c;
char *co = 0;
if (!strstr(c,"::")) {
*rprefix = 0;
*rlast = Copy(s);
}
if ((co = strstr(cc,"operator "))) {
if (co == cc) {
*rprefix = 0;
*rlast = Copy(s);
return;
} else {
*rprefix = NewStringWithSize(cc, co - cc - 2);
*rlast = NewString(co);
return;
}
}
while (*c) {
if ((*c == ':') && (*(c+1) == ':')) {
cc = c;
c += 2;
} else {
if (*c == '<') {
int level = 1;
c++;
while (*c && level) {
if (*c == '<') level++;
if (*c == '>') level--;
c++;
}
} else {
c++;
}
}
}
if (cc != tmp) {
*rprefix = NewStringWithSize(tmp, cc - tmp);
*rlast = NewString(cc + 2);
return;
} else {
*rprefix = 0;
*rlast = Copy(s);
}
}
String *
Swig_scopename_prefix(String *s) {
char *tmp = Char(s);

View file

@ -433,6 +433,7 @@ extern char *Swig_copy_string(const char *c);
extern void Swig_banner(File *f);
extern String *Swig_string_escape(String *s);
extern String *Swig_string_mangle(const String *s);
extern void Swig_scopename_split(String *s, String **prefix, String **last);
extern String *Swig_scopename_prefix(String *s);
extern String *Swig_scopename_last(String *s);
extern String *Swig_scopename_first(String *s);

View file

@ -961,8 +961,7 @@ symbol_lookup_qualified(String_or_char *name, Symtab *symtab, String *prefix, in
Node *n;
String *bname;
String *prefix;
bname = Swig_scopename_last(name);
prefix = Swig_scopename_prefix(name);
Swig_scopename_split(name, &prefix, &bname);
n = symbol_lookup_qualified(bname,symtab,prefix,local,checkfunc);
Delete(bname);
Delete(prefix);
@ -971,24 +970,31 @@ symbol_lookup_qualified(String_or_char *name, Symtab *symtab, String *prefix, in
Symtab *st;
Node *n = 0;
/* Make qualified name of current scope */
String *qalloc = 0;
String *qname = Swig_symbol_qualifiedscopename(symtab);
if (qname && StringLen(qname)) {
if (prefix && StringLen(prefix)) {
StringAppend(qname,k_coloncolon);
StringAppend(qname,prefix);
if (qname){
if (StringLen(qname)) {
if (prefix && StringLen(prefix)) {
Printv(qname,k_coloncolon,prefix,NIL);
}
} else {
StringAppend(qname, prefix);
}
qalloc = qname;
} else {
Delete(qname);
qname = Copy(prefix);
qname = prefix;
}
st = HashGetAttr(symtabs,qname);
/* Found a scope match */
if (st) {
if (!name) return st;
if (!name) {
if (qalloc) Delete(qalloc);
return st;
}
n = symbol_lookup(name, st,checkfunc);
}
if (qalloc) Delete(qalloc);
Delete(qname);
if (!n) {
if (!local) {
Node *pn = HashGetAttr(symtab,k_parentnode);
@ -1423,13 +1429,13 @@ Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
List *elements;
String *result;
int i,len;
Iterator pe;
result = NewStringEmpty();
elements = SwigType_split(t);
len = Len(elements);
for (i = 0; i < len; i++) {
String *e = Getitem(elements,i);
for (pe = First(elements); pe.item; pe = Next(pe)) {
String *e = pe.item;
if (SwigType_issimple(e)) {
Node *n = Swig_symbol_clookup_check(e,st,no_constructor);
if (n) {
@ -1744,14 +1750,13 @@ SwigType*
Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) {
String *result = NewStringEmpty();
List *elements = SwigType_split(type);
int len = Len(elements);
int i;
Iterator pe;
#ifdef SWIG_DEBUG
Printf(stderr,"finding deftype %s\n", type);
#endif
for (i = 0; i < len; i++) {
String *e = Getitem(elements,i);
for (pe = First(elements); pe.item; pe = Next(pe)) {
String *e = pe.item;
if (SwigType_isfunction(e)) {
String *s = NewString("f(");
List *parms = SwigType_parmlist(e);

View file

@ -606,7 +606,7 @@ SwigType *SwigType_typedef_resolve(SwigType *t) {
/* Didn't find in this scope. We need to do a little more searching */
if (Swig_scopename_check(base)) {
/* A qualified name. */
nameprefix = Swig_scopename_prefix(base);
Swig_scopename_split(base, &nameprefix, &namebase);
#ifdef SWIG_DEBUG
Printf(stdout,"nameprefix = '%s'\n", nameprefix);
#endif
@ -617,12 +617,12 @@ SwigType *SwigType_typedef_resolve(SwigType *t) {
/* Couldn't locate a scope for the type. */
if (!s) {
Delete(base);
Delete(namebase);
Delete(nameprefix);
r = 0;
goto return_result;
}
/* Try to locate the name starting in the scope */
namebase = Swig_scopename_last(base);
#ifdef SWIG_DEBUG
Printf(stdout,"namebase = '%s'\n", namebase);
#endif
@ -714,8 +714,6 @@ SwigType *SwigType_typedef_resolve(SwigType *t) {
}
if (namebase) Delete(namebase);
if (nameprefix) Delete(nameprefix);
namebase = 0;
nameprefix = 0;
} else {
if (SwigType_isfunction(base)) {
List *parms;
@ -888,18 +886,18 @@ SwigType *SwigType_typedef_qualified(SwigType *t)
}
} else {
if (Swig_scopename_check(e)) {
String *tqname;
String *qlast;
String *qname = Swig_scopename_prefix(e);
String *qname;
Swig_scopename_split(e, &qname, &qlast);
if (qname) {
qlast = Swig_scopename_last(e);
tqname = SwigType_typedef_qualified(qname);
String *tqname = SwigType_typedef_qualified(qname);
Clear(e);
Printf(e,"%s::%s", tqname, qlast);
Delete(qname);
Delete(qlast);
Delete(tqname);
}
Delete(qlast);
/* Automatic template instantiation might go here??? */
} else {
/* It's a bare name. It's entirely possible, that the