Fix symbol table bug with combinations of using directives and using declarations

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13190 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-06-25 06:36:29 +00:00
commit 1ce0058256
5 changed files with 146 additions and 0 deletions

View file

@ -4,6 +4,19 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.8 (in progress) Version 2.0.8 (in progress)
=========================== ===========================
2012-06-25: wsfulton
Fix using declarations combined with using directives so that types are correctly found in scope.
Example:
namespace Outer2 {
namespace Space2 {
class Thing2 {};
}
}
using namespace Outer2; // using directive
using Space2::Thing2; // using declaration
void useit2(Thing2 t) {}
2012-05-29: wsfulton 2012-05-29: wsfulton
Fix #3529601 - seg fault when a protected method has the "director" Fix #3529601 - seg fault when a protected method has the "director"
feature but the parent class does not. Also fix similar problems with feature but the parent class does not. Also fix similar problems with

View file

@ -442,6 +442,7 @@ CPP_TEST_CASES += \
using1 \ using1 \
using2 \ using2 \
using_composition \ using_composition \
using_directive_and_declaration \
using_extend \ using_extend \
using_inherit \ using_inherit \
using_namespace \ using_namespace \

View file

@ -0,0 +1,28 @@
import using_directive_and_declaration.*;
public class using_directive_and_declaration_runme {
static {
try {
System.loadLibrary("using_directive_and_declaration");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
using_directive_and_declaration.useit1(new Thing1());
using_directive_and_declaration.useit2(new Thing2());
using_directive_and_declaration.useit3(new Thing3());
using_directive_and_declaration.useit4(new Thing4());
using_directive_and_declaration.useit5(new Thing5());
Thing6a t6a = new Thing6a();
t6a.a();
Thing6 t6b = new Thing6();
t6b.b();
using_directive_and_declaration.useit6(t6a, t6b);
}
}

View file

@ -0,0 +1,85 @@
%module using_directive_and_declaration
// Test using directives combined with using declarations
%inline %{
namespace Outer1 {
namespace Space1 {
class Thing1 {};
}
}
using namespace Outer1::Space1;
using Outer1::Space1::Thing1;
void useit1(Thing1 t) {}
namespace Outer2 {
namespace Space2 {
class Thing2 {};
}
}
using namespace Outer2;
using Space2::Thing2;
void useit2(Thing2 t) {}
namespace Outer3 {
namespace Space3 {
namespace Middle3 {
class Thing3 {};
}
}
}
using namespace Outer3;
using namespace Space3;
using Middle3::Thing3;
void useit3(Thing3 t) {}
namespace Outer4 {
namespace Space4 {
namespace Middle4 {
class Thing4 {};
}
}
}
using namespace Outer4::Space4;
using Middle4::Thing4;
void useit4(Thing4 t) {}
namespace Outer5 {
namespace Space5 {
namespace Middle5 {
namespace More5 {
class Thing5 {};
}
}
}
}
using namespace ::Outer5::Space5;
using namespace Middle5;
using More5::Thing5;
void useit5(Thing5 t) {}
%}
// Same symbol name in different namespaces
%rename(Thing6a) Outer6::Space6a::Thing6;
%inline %{
namespace Outer6 {
namespace Space6a {
struct Thing6 {
void a() {}
};
}
namespace Space6b {
struct Thing6 {
void b() {}
};
}
}
using namespace Outer6::Space6b;
void useit6(Outer6::Space6a::Thing6 ta, Thing6 tb) {}
%}

View file

@ -1053,6 +1053,25 @@ static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symt
Node *pn = Getattr(symtab, "parentNode"); Node *pn = Getattr(symtab, "parentNode");
if (pn) if (pn)
n = symbol_lookup_qualified(name, pn, prefix, local, checkfunc); n = symbol_lookup_qualified(name, pn, prefix, local, checkfunc);
/* Check inherited scopes */
if (!n) {
List *inherit = Getattr(symtab, "inherit");
if (inherit) {
int i, len;
len = Len(inherit);
for (i = 0; i < len; i++) {
Node *prefix_node = symbol_lookup(prefix, Getitem(inherit, i), checkfunc);
if (prefix_node) {
Node *prefix_symtab = Getattr(prefix_node, "symtab");
if (prefix_symtab) {
n = symbol_lookup(name, prefix_symtab, checkfunc);
break;
}
}
}
}
}
} else { } else {
n = 0; n = 0;
} }