avoid assert when finding a recursive scope inheritance, emit a warning in the worst case, reported by Nitro

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8832 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-02-17 22:13:37 +00:00
commit cb80d44fa6
4 changed files with 24 additions and 3 deletions

View file

@ -2679,6 +2679,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
for (s = First(bases); s.item; s = Next(s)) {
Symtab *st = Getattr(s.item,k_symtab);
if (st) {
Setfile(st,Getfile(s.item));
Setline(st,Getline(s.item));
Swig_symbol_inherit(st);
}
}
@ -3183,6 +3185,8 @@ cpp_class_decl :
for (s = First(bases); s.item; s = Next(s)) {
Symtab *st = Getattr(s.item,k_symtab);
if (st) {
Setfile(st,Getfile(s.item));
Setline(st,Getline(s.item));
Swig_symbol_inherit(st);
}
}
@ -3784,10 +3788,14 @@ cpp_using_decl : USING idcolon SEMI {
}
if (n) {
if (Strcmp(nodeType(n),"namespace") == 0) {
Symtab *current = Swig_symbol_current();
Symtab *symtab = Getattr(n,k_symtab);
$$ = new_node("using");
Setattr($$,"node",n);
Setattr($$,k_namespace, $3);
Swig_symbol_inherit(Getattr(n,k_symtab));
if (current != symtab) {
Swig_symbol_inherit(symtab);
}
} else {
Swig_error(cparse_file, cparse_line, "'%s' is not a namespace.\n", $3);
$$ = 0;

View file

@ -79,6 +79,7 @@
#define WARN_PARSE_EXPLICIT_TEMPLATE 320
#define WARN_PARSE_BUILTIN_NAME 321
#define WARN_PARSE_REDUNDANT 322
#define WARN_PARSE_REC_INHERITANCE 323
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */

View file

@ -236,10 +236,16 @@ class TypePass : private Dispatcher {
SwigType_inherit_scope(scopes);
}
/* Set up inheritance in the symbol table */
Symtab *s = Swig_symbol_current();
Symtab *st = Getattr(cls,"symtab");
Symtab *bst = Getattr(bclass,"symtab");
if (st == bst) {
Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(cls), Getline(cls),
"Recursive scope inheritance of '%s'.\n", HashGetAttr(cls,k_name));
continue;
}
Symtab *s = Swig_symbol_current();
Swig_symbol_setscope(st);
Swig_symbol_inherit(Getattr(bclass,"symtab"));
Swig_symbol_inherit(bst);
Swig_symbol_setscope(s);
/* Recursively hit base classes */

View file

@ -412,6 +412,12 @@ void Swig_symbol_inherit(Symtab *s) {
Setattr(current_symtab,k_inherit, inherit);
Delete(inherit);
}
if (s == current_symtab) {
Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(s), Getline(s),
"Recursive scope inheritance of '%s'.\n", HashGetAttr(s,k_name));
return;
}
assert(s != current_symtab);
ilen = Len(inherit);
for (i = 0; i < ilen; i++) {