Add improved namespace support - the nspace feature, working for Java only at the moment.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11896 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-03-04 21:27:23 +00:00
commit 1253657bb4
23 changed files with 645 additions and 266 deletions

View file

@ -242,6 +242,7 @@ CPP_TEST_CASES += \
namespace_typemap \
namespace_union \
namespace_virtual_method \
nspace \
naturalvar \
nested_class \
nested_comment \

View file

@ -37,26 +37,27 @@ CPP_TEST_CASES = \
include $(srcdir)/../common.mk
# Overridden variables here
SWIGOPT += -package $*
JAVA_PACKAGE = $*
SWIGOPT += -package $(JAVA_PACKAGE)
INTERFACEDIR = ../../
# Custom tests - tests with additional commandline options
# none!
nspace.%: JAVA_PACKAGE = $*Package
# Rules for the different types of tests
%.cpptest:
$(setup)
+(cd $* && $(swig_and_compile_cpp))
+(cd $(JAVA_PACKAGE) && $(swig_and_compile_cpp))
$(run_testcase)
%.ctest:
$(setup)
+(cd $* && $(swig_and_compile_c))
+(cd $(JAVA_PACKAGE) && $(swig_and_compile_c))
$(run_testcase)
%.multicpptest:
$(setup)
+(cd $* && $(swig_and_compile_multi_cpp))
+(cd $(JAVA_PACKAGE) && $(swig_and_compile_multi_cpp))
$(run_testcase)
# Makes a directory for the testcase if it does not exist
@ -66,24 +67,24 @@ setup = \
else \
echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
fi; \
if [ ! -d $* ]; then \
mkdir $*; \
if [ ! -d $(JAVA_PACKAGE) ]; then \
mkdir $(JAVA_PACKAGE); \
fi
# Compiles java files then runs the testcase. A testcase is only run if
# a file is found which has _runme.java appended after the testcase name.
# Note Java uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows, SHLIB_PATH on HPUX and DYLD_LIBRARY_PATH on Mac OS X.
run_testcase = \
cd $* && $(COMPILETOOL) $(JAVAC) -classpath . *.java && cd .. && \
cd $(JAVA_PACKAGE) && $(COMPILETOOL) $(JAVAC) -classpath . `find . -name "*.java"` && cd .. && \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(COMPILETOOL) $(JAVAC) -classpath . -d . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_LIBRARY_PATH="$*:$$DYLD_LIBRARY_PATH" $(RUNTOOL) $(JAVA) -classpath . $*_runme; \
env LD_LIBRARY_PATH="$(JAVA_PACKAGE):$$LD_LIBRARY_PATH" PATH="$(JAVA_PACKAGE):$$PATH" SHLIB_PATH="$(JAVA_PACKAGE):$$SHLIB_PATH" DYLD_LIBRARY_PATH="$(JAVA_PACKAGE):$$DYLD_LIBRARY_PATH" $(RUNTOOL) $(JAVA) -classpath . $*_runme; \
fi
# Clean: remove testcase directories
%.clean:
@if [ -d $* ]; then \
rm -rf $*; \
@if [ -d $(JAVA_PACKAGE) ]; then \
rm -rf $(JAVA_PACKAGE); \
fi
clean:

View file

@ -0,0 +1,93 @@
// Test the nspace feature
%module nspace
#if defined(SWIGJAVA)
SWIG_JAVABODY_METHODS(public, public, SWIGTYPE)
%pragma(java) jniclassclassmodifiers = "public class"
%feature("nspace");
%feature("nspace", "0") Outer::Inner2::NoNSpacePlease;
%copyctor;
%ignore Outer::Inner2::Color::Color();
%inline %{
namespace Outer {
class nspace {
};
namespace Inner1 {
enum Channel {
Diffuse,
Specular = 0x10,
Transmission1
};
struct Color {
static Color* create() { return new Color(); }
enum Channel {
Diffuse,
Specular = 0x20,
Transmission
};
int instanceMemberVariable;
static int staticMemberVariable;
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
}; // Color
int Color::staticMemberVariable = 0;
Color namespaceFunction(Color k) { return k; }
int namespaceVar = 0;
} // Inner1
namespace Inner2 {
enum Channel {
Diffuse,
Specular /* = 0x30*/,
Transmission2
};
struct Color {
Color() : instanceMemberVariable(0) {}
static Color* create() { return new Color(); }
enum Channel {
Diffuse,
Specular/* = 0x40*/,
Transmission
};
int instanceMemberVariable;
static int staticMemberVariable;
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
}; // Color
int Color::staticMemberVariable = 0;
class NoNSpacePlease {};
} // Inner2
class SomeClass {
public:
Inner1::Color::Channel GetInner1ColorChannel() { return Inner1::Color::Transmission; }
Inner2::Color::Channel GetInner2ColorChannel() { return Inner2::Color::Transmission; }
Inner1::Channel GetInner1Channel() { return Inner1::Transmission1; }
Inner2::Channel GetInner2Channel() { return Inner2::Transmission2; }
}; // SomeClass
} // Outer
namespace Outer {
struct MyWorldPart2 {};
}
struct GlobalClass {
void gmethod() {}
};
void test_classes(Outer::SomeClass c, Outer::Inner2::Color cc) {}
%}
#endif