fix friend bug #1323114 and allow the member names to include the class name
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7671 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
badf735534
commit
6bb78221ff
1 changed files with 58 additions and 14 deletions
|
|
@ -197,6 +197,8 @@ static Hash *rename_hash = 0;
|
||||||
static Hash *namewarn_hash = 0;
|
static Hash *namewarn_hash = 0;
|
||||||
static Hash *features_hash = 0;
|
static Hash *features_hash = 0;
|
||||||
|
|
||||||
|
static String *resolve_node_scope(String *cname);
|
||||||
|
|
||||||
Hash *Swig_cparse_features() {
|
Hash *Swig_cparse_features() {
|
||||||
if (!features_hash) features_hash = NewHash();
|
if (!features_hash) features_hash = NewHash();
|
||||||
return features_hash;
|
return features_hash;
|
||||||
|
|
@ -356,6 +358,10 @@ static int is_friend(Node *n) {
|
||||||
return Cmp(Getattr(n,"storage"),"friend") == 0;
|
return Cmp(Getattr(n,"storage"),"friend") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_operator(String *name) {
|
||||||
|
return Strncmp(name,"operator ", 9) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Add declaration list to symbol table */
|
/* Add declaration list to symbol table */
|
||||||
static int add_only_one = 0;
|
static int add_only_one = 0;
|
||||||
|
|
@ -369,9 +375,50 @@ static void add_symbols(Node *n) {
|
||||||
while (n) {
|
while (n) {
|
||||||
String *symname;
|
String *symname;
|
||||||
/* for friends, we need to pop the scope once */
|
/* for friends, we need to pop the scope once */
|
||||||
int isfriend = is_friend(n);
|
String *old_prefix = 0;
|
||||||
Symtab *class_scope = isfriend ? Swig_symbol_popscope() : 0;
|
Symtab *old_scope = 0;
|
||||||
|
int isfriend = inclass && is_friend(n);
|
||||||
|
if (inclass) {
|
||||||
|
String *name = Getattr(n, "name");
|
||||||
|
if (isfriend) {
|
||||||
|
/* for friends, we need to add the scopename if needed */
|
||||||
|
String *prefix = name ? Swig_scopename_prefix(name) : 0;
|
||||||
|
old_prefix = Namespaceprefix;
|
||||||
|
old_scope = Swig_symbol_popscope();
|
||||||
|
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||||
|
if (!prefix) {
|
||||||
|
if (name && Namespaceprefix) {
|
||||||
|
String *nname = NewStringf("%s::%s", Namespaceprefix, name);
|
||||||
|
Setattr(n,"name",nname);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Symtab *st = Swig_symbol_getscope(prefix);
|
||||||
|
String *ns = st ? Getattr(st,"name") : prefix;
|
||||||
|
String *base = Swig_scopename_last(name);
|
||||||
|
String *nname = NewStringf("%s::%s", ns, base);
|
||||||
|
Setattr(n,"name",nname);
|
||||||
|
Delete(base);
|
||||||
|
Delete(prefix);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* for member functions, we need to remove the redundant
|
||||||
|
class scope if provided, as in
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
int Foo::method(int a);
|
||||||
|
};
|
||||||
|
|
||||||
|
*/
|
||||||
|
String *prefix = name ? Swig_scopename_prefix(name) : 0;
|
||||||
|
if (prefix) {
|
||||||
|
if (Classprefix && (Strcmp(prefix,Classprefix) == 0)) {
|
||||||
|
String *base = Swig_scopename_last(name);
|
||||||
|
Setattr(n,"name",base);
|
||||||
|
}
|
||||||
|
Delete(prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!isfriend && inclass && (cplus_mode != CPLUS_PUBLIC)) {
|
if (!isfriend && inclass && (cplus_mode != CPLUS_PUBLIC)) {
|
||||||
int only_csymbol = 1;
|
int only_csymbol = 1;
|
||||||
if (cplus_mode == CPLUS_PROTECTED) {
|
if (cplus_mode == CPLUS_PROTECTED) {
|
||||||
|
|
@ -418,10 +465,6 @@ static void add_symbols(Node *n) {
|
||||||
SwigType *fdecl = Copy(decl);
|
SwigType *fdecl = Copy(decl);
|
||||||
SwigType *fun = SwigType_pop_function(fdecl);
|
SwigType *fun = SwigType_pop_function(fdecl);
|
||||||
|
|
||||||
/* for friends, we need to disable the class prefix */
|
|
||||||
String* class_prefix = isfriend ? Namespaceprefix : 0;
|
|
||||||
if (isfriend) Namespaceprefix = 0;
|
|
||||||
|
|
||||||
symname = make_name(Getattr(n,"name"),fun);
|
symname = make_name(Getattr(n,"name"),fun);
|
||||||
wrn = name_warning(n,symname,fun);
|
wrn = name_warning(n,symname,fun);
|
||||||
|
|
||||||
|
|
@ -429,8 +472,6 @@ static void add_symbols(Node *n) {
|
||||||
Delete(fdecl);
|
Delete(fdecl);
|
||||||
Delete(fun);
|
Delete(fun);
|
||||||
|
|
||||||
/* restore the class prefix if needed */
|
|
||||||
if (isfriend) Namespaceprefix = class_prefix;
|
|
||||||
}
|
}
|
||||||
if (!symname) {
|
if (!symname) {
|
||||||
n = nextSibling(n);
|
n = nextSibling(n);
|
||||||
|
|
@ -500,8 +541,10 @@ static void add_symbols(Node *n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* restore the class scope if needed */
|
/* restore the class scope if needed */
|
||||||
if (isfriend) Swig_symbol_setscope(class_scope);
|
if (isfriend) {
|
||||||
|
Swig_symbol_setscope(old_scope);
|
||||||
|
Namespaceprefix = old_prefix;
|
||||||
|
}
|
||||||
if (add_only_one) return;
|
if (add_only_one) return;
|
||||||
n = nextSibling(n);
|
n = nextSibling(n);
|
||||||
}
|
}
|
||||||
|
|
@ -2667,8 +2710,9 @@ c_decl : storage_class type declarator initializer c_decl_tail {
|
||||||
/* This is a special case. If the scope name of the declaration exactly
|
/* This is a special case. If the scope name of the declaration exactly
|
||||||
matches that of the declaration, then we will allow it. Otherwise, delete. */
|
matches that of the declaration, then we will allow it. Otherwise, delete. */
|
||||||
String *p = Swig_scopename_prefix($3.id);
|
String *p = Swig_scopename_prefix($3.id);
|
||||||
if (p && Namespaceprefix) {
|
if (p) {
|
||||||
if (Strcmp(p,Namespaceprefix) == 0) {
|
if ((Namespaceprefix && Strcmp(p,Namespaceprefix) == 0) ||
|
||||||
|
(inclass && Strcmp(p,Classprefix) == 0)) {
|
||||||
Setattr($$,"name",Swig_scopename_last($3.id));
|
Setattr($$,"name",Swig_scopename_last($3.id));
|
||||||
set_nextSibling($$,$5);
|
set_nextSibling($$,$5);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -3250,7 +3294,7 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para
|
||||||
if ($$) tname = Getattr($$,"name");
|
if ($$) tname = Getattr($$,"name");
|
||||||
|
|
||||||
/* Check if the class is a template specialization */
|
/* Check if the class is a template specialization */
|
||||||
if (($$) && (Strstr(tname,"<")) && (Strncmp(tname,"operator ",9) != 0)) {
|
if (($$) && (Strstr(tname,"<")) && (!is_operator(tname))) {
|
||||||
/* If a specialization. Check if defined. */
|
/* If a specialization. Check if defined. */
|
||||||
Node *tempn = 0;
|
Node *tempn = 0;
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue