From 3f36157b3942e4aa9ea34a989067db0e5640c569 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 20 Feb 2022 11:12:16 +0000 Subject: [PATCH 1/4] Revert recent using-declarations code changes Reverts code changes from 7b5a615e50548ab9c512b384a8f0b8d56bc45bd1 merge commit in preparation for better fix. Issue #655 and issue #1488. --- Source/CParse/parser.y | 5 ++--- Source/Swig/swig.h | 1 - Source/Swig/symbol.c | 37 +------------------------------------ 3 files changed, 3 insertions(+), 40 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index aafec5cbb..dfbfa43b6 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -4468,12 +4468,11 @@ templateparameterstail : COMMA templateparameter templateparameterstail { /* Namespace support */ cpp_using_decl : USING idcolon SEMI { - String *uname = Swig_symbol_type_qualify($2,0); + String *uname = Swig_symbol_type_qualify($2,0); String *name = Swig_scopename_last($2); - $$ = new_node("using"); + $$ = new_node("using"); Setattr($$,"uname",uname); Setattr($$,"name", name); - Swig_symbol_add_using(name, uname, $$); Delete(uname); Delete(name); add_symbols($$); diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 9f7b2cbca..76691269e 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -221,7 +221,6 @@ extern "C" { extern void Swig_symbol_print_tables_summary(void); extern void Swig_symbol_print_symbols(void); extern void Swig_symbol_print_csymbols(void); - extern void Swig_symbol_add_using(String *name, String *uname, Node *n); extern void Swig_symbol_init(void); extern void Swig_symbol_setscopename(const_String_or_char_ptr name); extern String *Swig_symbol_getscopename(void); diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 66c73ae02..aacaf24be 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -382,29 +382,6 @@ String *Swig_symbol_qualified_language_scopename(Symtab *n) { return result; } -/* ----------------------------------------------------------------------------- - * Swig_symbol_add_using() - * - * Adds a node to the C symbol table for a using declaration. - * Used for using-declarations within classes/structs. - * ----------------------------------------------------------------------------- */ - -void Swig_symbol_add_using(String *name, String *uname, Node *n) { - Hash *h; - h = Swig_symbol_clookup(uname, 0); - if (h && (checkAttribute(h, "kind", "class") || checkAttribute(h, "kind", "struct"))) { - String *qcurrent = Swig_symbol_qualifiedscopename(0); - if (qcurrent) { - Append(qcurrent, "::"); - Append(qcurrent, name); - } else { - qcurrent = NewString(name); - } - Setattr(symtabs, qcurrent, n); - Delete(qcurrent); - } -} - /* ----------------------------------------------------------------------------- * Swig_symbol_newscope() * @@ -1097,19 +1074,7 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt Delete(qalloc); return st; } - if (checkAttribute(st, "nodeType", "using")) { - String *uname = Getattr(st, "uname"); - if (uname) { - st = Getattr(symtabs, uname); - if (st) { - n = symbol_lookup(name, st, checkfunc); - } else { - fprintf(stderr, "Error: Found corrupt 'using' node\n"); - } - } - } else if (Getattr(st, "csymtab")) { - n = symbol_lookup(name, st, checkfunc); - } + n = symbol_lookup(name, st, checkfunc); } if (qalloc) Delete(qalloc); From cb963a14401b05af36a58a2b76eba3f368354ffd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 20 Feb 2022 13:30:58 +0000 Subject: [PATCH 2/4] Using declarations fix in symbol tables Implementation is very similar to typedef implementation. Issue #655 and closes #1488. Testcase using_member.i. Better implementation to that reverted in previous commit 3f36157b. Symbol tables shown with -debug-csymbols and -debug-symbols now correct and are similar to when using a typedef. --- Source/Swig/symbol.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index aacaf24be..74b4c698d 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -641,10 +641,11 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) { { Node *td = n; - while (td && Checkattr(td, "nodeType", "cdecl") && Checkattr(td, "storage", "typedef")) { + while (td && ((Equal(nodeType(td), "cdecl") && Checkattr(td, "storage", "typedef")) || (Equal(nodeType(td), "using") && !Getattr(n, "namespace")))) { SwigType *type; Node *td1; - type = Copy(Getattr(td, "type")); + int using_not_typedef = Equal(nodeType(td), "using"); + type = Copy(Getattr(td, using_not_typedef ? "uname" : "type")); SwigType_push(type, Getattr(td, "decl")); td1 = Swig_symbol_clookup(type, 0); @@ -665,9 +666,13 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) { ie, when Foo -> FooBar -> Foo, jump one scope up when possible. */ - if (td1 && Checkattr(td1, "storage", "typedef")) { - String *st = Getattr(td1, "type"); + if (td1) { + String *st = 0; String *sn = Getattr(td, "name"); + if (Equal(nodeType(td1), "cdecl") && Checkattr(td1, "storage", "typedef")) + st = Getattr(td1, "type"); + else if (Equal(nodeType(td1), "using") && !Getattr(td1, "namespace")) + st = Getattr(td1, "uname"); if (st && sn && Equal(st, sn)) { Symtab *sc = Getattr(current_symtab, "parentNode"); if (sc) From 9b131a03d52a47dfd2b5b21ad1b76224495cd0bd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 20 Feb 2022 16:45:00 +0000 Subject: [PATCH 3/4] Fix warning suppression for WARN_PARSE_USING_UNDEF New warnings for unknown using declarations since fix in previous commit --- CHANGES.current | 3 +++ Examples/test-suite/using2.i | 2 +- Source/Swig/symbol.c | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index feb058706..b9bbbfe5b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-02-20: wsfulton + Fix %warnfilter warning suppress for warning 315 SWIGWARN_PARSE_USING_UNDEF. + 2022-01-29: dontpanic92 #676 Fix code generated for a C++ class with a non-capitalised name. diff --git a/Examples/test-suite/using2.i b/Examples/test-suite/using2.i index 1f3dc46f5..1c471c1e5 100644 --- a/Examples/test-suite/using2.i +++ b/Examples/test-suite/using2.i @@ -1,6 +1,6 @@ %module using2 -%warnfilter(SWIGWARN_PARSE_USING_UNDEF); +%warnfilter(SWIGWARN_PARSE_USING_UNDEF) ::baz; using ::baz; diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 74b4c698d..d3bc720ff 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -12,7 +12,7 @@ * ----------------------------------------------------------------------------- */ #include "swig.h" -#include "swigwarn.h" +#include "cparse.h" #include /* #define SWIG_DEBUG*/ @@ -1182,7 +1182,9 @@ Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) { Symtab *un = Getattr(s, "sym:symtab"); Node *ss = (!Equal(name, uname) || (un != n)) ? Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */ if (!ss) { + SWIG_WARN_NODE_BEGIN(s); Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname"))); + SWIG_WARN_NODE_END(s); } s = ss; } @@ -1254,7 +1256,9 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (* Node *ss; ss = Swig_symbol_clookup(Getattr(s, "uname"), Getattr(s, "sym:symtab")); if (!ss && !checkfunc) { + SWIG_WARN_NODE_BEGIN(s); Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname"))); + SWIG_WARN_NODE_END(s); } s = ss; } @@ -1305,7 +1309,9 @@ Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) { while (s && Checkattr(s, "nodeType", "using")) { Node *ss = Swig_symbol_clookup_local(Getattr(s, "uname"), Getattr(s, "sym:symtab")); if (!ss) { + SWIG_WARN_NODE_BEGIN(s); Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname"))); + SWIG_WARN_NODE_END(s); } s = ss; } @@ -1353,7 +1359,9 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n, while (s && Checkattr(s, "nodeType", "using")) { Node *ss = Swig_symbol_clookup_local_check(Getattr(s, "uname"), Getattr(s, "sym:symtab"), checkfunc); if (!ss && !checkfunc) { + SWIG_WARN_NODE_BEGIN(s); Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname"))); + SWIG_WARN_NODE_END(s); } s = ss; } From 1b0a9ccfc5463777dae7205bec1fb6ab39622803 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 20 Feb 2022 13:54:39 +0000 Subject: [PATCH 4/4] Typo fixes --- Source/CParse/parser.y | 2 +- Source/Modules/javascript.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index dfbfa43b6..759f5259c 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1863,7 +1863,7 @@ extend_directive : EXTEND options classkeyopt idcolon LBRACE { } else { /* Previous typedef class definition. Use its symbol table. Deprecated, just the real name should be used. - Note that %extend before the class typedef never worked, only %extend after the class typdef. */ + Note that %extend before the class typedef never worked, only %extend after the class typedef. */ prev_symtab = Swig_symbol_setscope(Getattr(cls, "symtab")); current_class = cls; SWIG_WARN_NODE_BEGIN(cls); diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index 2d6535972..e80910a41 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -1143,7 +1143,7 @@ int JSEmitter::emitConstant(Node *n) { String *rawval = Getattr(n, "rawval"); String *value = rawval ? rawval : Getattr(n, "value"); - // HACK: forcing usage of cppvalue for v8 (which turned out to fix typdef_struct.i, et. al) + // HACK: forcing usage of cppvalue for v8 (which turned out to fix typedef_struct.i, et. al) if (State::IsSet(state.globals(FORCE_CPP)) && Getattr(n, "cppvalue") != NULL) { value = Getattr(n, "cppvalue"); }