Skip to content

Commit d2e9b80

Browse files
committed
Merge branch 'using-declarations' into upstream-master
* using-declarations: Typo fixes Fix warning suppression for WARN_PARSE_USING_UNDEF Using declarations fix in symbol tables Revert recent using-declarations code changes Conflicts: CHANGES.current
2 parents 1707d6b + 1b0a9cc commit d2e9b80

File tree

6 files changed

+27
-48
lines changed

6 files changed

+27
-48
lines changed

CHANGES.current

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.0 (in progress)
88
===========================
99

10+
2022-02-20: wsfulton
11+
Fix %warnfilter warning suppress for warning 315 SWIGWARN_PARSE_USING_UNDEF.
12+
1013
2022-02-17: olly
1114
[PHP] https://sourceforge.net/p/swig/bugs/1211/
1215
Fix to call cleanup code in exception situations and not to invoke

Examples/test-suite/using2.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%module using2
22

3-
%warnfilter(SWIGWARN_PARSE_USING_UNDEF);
3+
%warnfilter(SWIGWARN_PARSE_USING_UNDEF) ::baz;
44

55
using ::baz;
66

Source/CParse/parser.y

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ extend_directive : EXTEND options classkeyopt idcolon LBRACE {
18631863
} else {
18641864
/* Previous typedef class definition. Use its symbol table.
18651865
Deprecated, just the real name should be used.
1866-
Note that %extend before the class typedef never worked, only %extend after the class typdef. */
1866+
Note that %extend before the class typedef never worked, only %extend after the class typedef. */
18671867
prev_symtab = Swig_symbol_setscope(Getattr(cls, "symtab"));
18681868
current_class = cls;
18691869
SWIG_WARN_NODE_BEGIN(cls);
@@ -4481,12 +4481,11 @@ templateparameterstail : COMMA templateparameter templateparameterstail {
44814481
/* Namespace support */
44824482

44834483
cpp_using_decl : USING idcolon SEMI {
4484-
String *uname = Swig_symbol_type_qualify($2,0);
4484+
String *uname = Swig_symbol_type_qualify($2,0);
44854485
String *name = Swig_scopename_last($2);
4486-
$$ = new_node("using");
4486+
$$ = new_node("using");
44874487
Setattr($$,"uname",uname);
44884488
Setattr($$,"name", name);
4489-
Swig_symbol_add_using(name, uname, $$);
44904489
Delete(uname);
44914490
Delete(name);
44924491
add_symbols($$);

Source/Modules/javascript.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ int JSEmitter::emitConstant(Node *n) {
11431143
String *rawval = Getattr(n, "rawval");
11441144
String *value = rawval ? rawval : Getattr(n, "value");
11451145

1146-
// HACK: forcing usage of cppvalue for v8 (which turned out to fix typdef_struct.i, et. al)
1146+
// HACK: forcing usage of cppvalue for v8 (which turned out to fix typedef_struct.i, et. al)
11471147
if (State::IsSet(state.globals(FORCE_CPP)) && Getattr(n, "cppvalue") != NULL) {
11481148
value = Getattr(n, "cppvalue");
11491149
}

Source/Swig/swig.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ extern "C" {
221221
extern void Swig_symbol_print_tables_summary(void);
222222
extern void Swig_symbol_print_symbols(void);
223223
extern void Swig_symbol_print_csymbols(void);
224-
extern void Swig_symbol_add_using(String *name, String *uname, Node *n);
225224
extern void Swig_symbol_init(void);
226225
extern void Swig_symbol_setscopename(const_String_or_char_ptr name);
227226
extern String *Swig_symbol_getscopename(void);

Source/Swig/symbol.c

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* ----------------------------------------------------------------------------- */
1313

1414
#include "swig.h"
15-
#include "swigwarn.h"
15+
#include "cparse.h"
1616
#include <ctype.h>
1717

1818
/* #define SWIG_DEBUG*/
@@ -382,29 +382,6 @@ String *Swig_symbol_qualified_language_scopename(Symtab *n) {
382382
return result;
383383
}
384384

385-
/* -----------------------------------------------------------------------------
386-
* Swig_symbol_add_using()
387-
*
388-
* Adds a node to the C symbol table for a using declaration.
389-
* Used for using-declarations within classes/structs.
390-
* ----------------------------------------------------------------------------- */
391-
392-
void Swig_symbol_add_using(String *name, String *uname, Node *n) {
393-
Hash *h;
394-
h = Swig_symbol_clookup(uname, 0);
395-
if (h && (checkAttribute(h, "kind", "class") || checkAttribute(h, "kind", "struct"))) {
396-
String *qcurrent = Swig_symbol_qualifiedscopename(0);
397-
if (qcurrent) {
398-
Append(qcurrent, "::");
399-
Append(qcurrent, name);
400-
} else {
401-
qcurrent = NewString(name);
402-
}
403-
Setattr(symtabs, qcurrent, n);
404-
Delete(qcurrent);
405-
}
406-
}
407-
408385
/* -----------------------------------------------------------------------------
409386
* Swig_symbol_newscope()
410387
*
@@ -664,10 +641,11 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
664641

665642
{
666643
Node *td = n;
667-
while (td && Checkattr(td, "nodeType", "cdecl") && Checkattr(td, "storage", "typedef")) {
644+
while (td && ((Equal(nodeType(td), "cdecl") && Checkattr(td, "storage", "typedef")) || (Equal(nodeType(td), "using") && !Getattr(n, "namespace")))) {
668645
SwigType *type;
669646
Node *td1;
670-
type = Copy(Getattr(td, "type"));
647+
int using_not_typedef = Equal(nodeType(td), "using");
648+
type = Copy(Getattr(td, using_not_typedef ? "uname" : "type"));
671649
SwigType_push(type, Getattr(td, "decl"));
672650
td1 = Swig_symbol_clookup(type, 0);
673651

@@ -688,9 +666,13 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
688666
ie, when Foo -> FooBar -> Foo, jump one scope up when possible.
689667
690668
*/
691-
if (td1 && Checkattr(td1, "storage", "typedef")) {
692-
String *st = Getattr(td1, "type");
669+
if (td1) {
670+
String *st = 0;
693671
String *sn = Getattr(td, "name");
672+
if (Equal(nodeType(td1), "cdecl") && Checkattr(td1, "storage", "typedef"))
673+
st = Getattr(td1, "type");
674+
else if (Equal(nodeType(td1), "using") && !Getattr(td1, "namespace"))
675+
st = Getattr(td1, "uname");
694676
if (st && sn && Equal(st, sn)) {
695677
Symtab *sc = Getattr(current_symtab, "parentNode");
696678
if (sc)
@@ -1097,19 +1079,7 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt
10971079
Delete(qalloc);
10981080
return st;
10991081
}
1100-
if (checkAttribute(st, "nodeType", "using")) {
1101-
String *uname = Getattr(st, "uname");
1102-
if (uname) {
1103-
st = Getattr(symtabs, uname);
1104-
if (st) {
1105-
n = symbol_lookup(name, st, checkfunc);
1106-
} else {
1107-
fprintf(stderr, "Error: Found corrupt 'using' node\n");
1108-
}
1109-
}
1110-
} else if (Getattr(st, "csymtab")) {
1111-
n = symbol_lookup(name, st, checkfunc);
1112-
}
1082+
n = symbol_lookup(name, st, checkfunc);
11131083
}
11141084
if (qalloc)
11151085
Delete(qalloc);
@@ -1212,7 +1182,9 @@ Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) {
12121182
Symtab *un = Getattr(s, "sym:symtab");
12131183
Node *ss = (!Equal(name, uname) || (un != n)) ? Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */
12141184
if (!ss) {
1185+
SWIG_WARN_NODE_BEGIN(s);
12151186
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
1187+
SWIG_WARN_NODE_END(s);
12161188
}
12171189
s = ss;
12181190
}
@@ -1284,7 +1256,9 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (*
12841256
Node *ss;
12851257
ss = Swig_symbol_clookup(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
12861258
if (!ss && !checkfunc) {
1259+
SWIG_WARN_NODE_BEGIN(s);
12871260
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
1261+
SWIG_WARN_NODE_END(s);
12881262
}
12891263
s = ss;
12901264
}
@@ -1335,7 +1309,9 @@ Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) {
13351309
while (s && Checkattr(s, "nodeType", "using")) {
13361310
Node *ss = Swig_symbol_clookup_local(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
13371311
if (!ss) {
1312+
SWIG_WARN_NODE_BEGIN(s);
13381313
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
1314+
SWIG_WARN_NODE_END(s);
13391315
}
13401316
s = ss;
13411317
}
@@ -1383,7 +1359,9 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n,
13831359
while (s && Checkattr(s, "nodeType", "using")) {
13841360
Node *ss = Swig_symbol_clookup_local_check(Getattr(s, "uname"), Getattr(s, "sym:symtab"), checkfunc);
13851361
if (!ss && !checkfunc) {
1362+
SWIG_WARN_NODE_BEGIN(s);
13861363
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
1364+
SWIG_WARN_NODE_END(s);
13871365
}
13881366
s = ss;
13891367
}

0 commit comments

Comments
 (0)