Merge branch 'fschlimb/using-fixes'

Fixes #655
Fixes #1488
This commit is contained in:
Olly Betts 2022-01-30 11:06:07 +13:00
commit 7b5a615e50
6 changed files with 101 additions and 3 deletions

View file

@ -549,6 +549,7 @@ CPP_TEST_CASES += \
using_directive_and_declaration_forward \
using_extend \
using_inherit \
using_member \
using_namespace \
using_namespace_loop \
using_pointers \

View file

@ -0,0 +1,10 @@
from using_member import *
b = B()
assert b.get(int(1)) == 10
assert b.get(float(1)) == 20
bb = BB()
assert bb.greater(int(1)) == 0
assert bb.greater(float(1)) == 1
assert bb.great(True) == 2

View file

@ -0,0 +1,50 @@
%module using_member
%rename(greater) one::two::three::interface1::AA::great(int);
%rename(greater) one::two::three::interface1::AA::great(float);
%inline %{
namespace interface1
{
struct A
{
int get(int) {return 10;}
};
}
using interface1::A;
struct B : public A
{
using A::get;
int get(double) {return 20;}
};
namespace one {
namespace two {
namespace three {
namespace interface1
{
class AA
{
public:
int great(int) {return 0;}
int great(float) {return 1;}
};
}
using interface1::AA;
}
}
namespace twotwo {
namespace threetwo {
class BB : public two::three::AA
{
public:
using two::three::AA::great;
int great(bool) {return 2;}
int jj() {return 3;}
};
}
}
}
%}

View file

@ -4468,11 +4468,12 @@ 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($$);

View file

@ -221,6 +221,7 @@ 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);

View file

@ -382,6 +382,29 @@ 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()
*
@ -1074,7 +1097,19 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt
Delete(qalloc);
return st;
}
n = symbol_lookup(name, st, checkfunc);
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);
}
}
if (qalloc)
Delete(qalloc);