summaryrefslogtreecommitdiff
path: root/Examples
diff options
context:
space:
mode:
authorDavid Nadlinger <code@klickverbot.at>2011-03-13 00:32:26 +0000
committerDavid Nadlinger <code@klickverbot.at>2011-03-13 00:32:26 +0000
commitce6516fb4ca0b749b6614dce67302d0cdf1e746e (patch)
tree14a27a24574ccaa1c5607ffbf4c7ca1ef1d58da7 /Examples
parenta63cde3827e6c86ca4de28b25a7d3a29cbebc1ca (diff)
downloadswig-ce6516fb4ca0b749b6614dce67302d0cdf1e746e.tar.gz
[D] nspace support.
As for C# and Java, this doesn't work for free functions/variables yet. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12534 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples')
-rw-r--r--Examples/test-suite/csharp/nspace_runme.cs4
-rw-r--r--Examples/test-suite/d/Makefile.in4
-rw-r--r--Examples/test-suite/d/nspace_extend_runme.1.d32
-rw-r--r--Examples/test-suite/d/nspace_extend_runme.2.d32
-rw-r--r--Examples/test-suite/d/nspace_runme.1.d87
-rw-r--r--Examples/test-suite/d/nspace_runme.2.d77
-rw-r--r--Examples/test-suite/java/nspace_runme.java2
-rw-r--r--Examples/test-suite/nspace.i18
-rw-r--r--Examples/test-suite/nspace_extend.i10
9 files changed, 247 insertions, 19 deletions
diff --git a/Examples/test-suite/csharp/nspace_runme.cs b/Examples/test-suite/csharp/nspace_runme.cs
index 9cf593857..fb6462541 100644
--- a/Examples/test-suite/csharp/nspace_runme.cs
+++ b/Examples/test-suite/csharp/nspace_runme.cs
@@ -2,7 +2,7 @@ using System;
public class runme
{
- static void Main()
+ static void Main()
{
// constructors and destructors
nspaceNamespace.Outer.Inner1.Color color1 = new nspaceNamespace.Outer.Inner1.Color();
@@ -62,7 +62,7 @@ public class runme
throw new ApplicationException("Transmission2 wrong");
// turn feature off / ignoring
- nspaceNamespace.Outer.nspace ns = new nspaceNamespace.Outer.nspace();
+ nspaceNamespace.Outer.namespce ns = new nspaceNamespace.Outer.namespce();
ns.Dispose();
nspaceNamespace.NoNSpacePlease nons = new nspaceNamespace.NoNSpacePlease();
nons.Dispose();
diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in
index 0f5bf8cbb..53b9f2859 100644
--- a/Examples/test-suite/d/Makefile.in
+++ b/Examples/test-suite/d/Makefile.in
@@ -65,13 +65,13 @@ run_testcase = \
cd $*$(VERSIONSUFFIX) && \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
DFLAGS='-of$*_runme' \
- DSRCS='../$(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) $*/*.d' d_compile && \
+ DSRCS='../$(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) `find $* -name *.d`' d_compile && \
env LD_LIBRARY_PATH=".:$$LD_LIBRARY_PATH" $(RUNTOOL) ./$*_runme; \
else \
cd $*$(VERSIONSUFFIX) && \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
DFLAGS='-c' \
- DSRCS='$*/*.d' d_compile && cd .. ; \
+ DSRCS='`find $* -name *.d`' d_compile && cd .. ; \
fi
# Clean: remove testcase directories
diff --git a/Examples/test-suite/d/nspace_extend_runme.1.d b/Examples/test-suite/d/nspace_extend_runme.1.d
new file mode 100644
index 000000000..82ccfec90
--- /dev/null
+++ b/Examples/test-suite/d/nspace_extend_runme.1.d
@@ -0,0 +1,32 @@
+module nspace_extend_runme;
+
+static import oi1c = nspace_extend.Outer.Inner1.Color;
+static import oi2c = nspace_extend.Outer.Inner2.Color;
+
+void main() {
+ {
+ // constructors and destructors
+ scope color1 = new oi1c.Color();
+ scope color = new oi1c.Color(color1);
+
+ // class methods
+ color.colorInstanceMethod(20.0);
+ oi1c.Color.colorStaticMethod(20.0);
+ auto created = oi1c.Color.create();
+ }
+ {
+ // constructors and destructors
+ scope color2 = new oi2c.Color();
+ scope color = new oi2c.Color(color2);
+
+ // class methods
+ color.colorInstanceMethod(20.0);
+ oi2c.Color.colorStaticMethod(20.0);
+ auto created = oi2c.Color.create();
+
+ // Same class different namespaces
+ auto col1 = new oi1c.Color();
+ auto col2 = oi2c.Color.create();
+ col2.colors(col1, col1, col2, col2, col2);
+ }
+}
diff --git a/Examples/test-suite/d/nspace_extend_runme.2.d b/Examples/test-suite/d/nspace_extend_runme.2.d
new file mode 100644
index 000000000..82ccfec90
--- /dev/null
+++ b/Examples/test-suite/d/nspace_extend_runme.2.d
@@ -0,0 +1,32 @@
+module nspace_extend_runme;
+
+static import oi1c = nspace_extend.Outer.Inner1.Color;
+static import oi2c = nspace_extend.Outer.Inner2.Color;
+
+void main() {
+ {
+ // constructors and destructors
+ scope color1 = new oi1c.Color();
+ scope color = new oi1c.Color(color1);
+
+ // class methods
+ color.colorInstanceMethod(20.0);
+ oi1c.Color.colorStaticMethod(20.0);
+ auto created = oi1c.Color.create();
+ }
+ {
+ // constructors and destructors
+ scope color2 = new oi2c.Color();
+ scope color = new oi2c.Color(color2);
+
+ // class methods
+ color.colorInstanceMethod(20.0);
+ oi2c.Color.colorStaticMethod(20.0);
+ auto created = oi2c.Color.create();
+
+ // Same class different namespaces
+ auto col1 = new oi1c.Color();
+ auto col2 = oi2c.Color.create();
+ col2.colors(col1, col1, col2, col2, col2);
+ }
+}
diff --git a/Examples/test-suite/d/nspace_runme.1.d b/Examples/test-suite/d/nspace_runme.1.d
new file mode 100644
index 000000000..8d3b81f76
--- /dev/null
+++ b/Examples/test-suite/d/nspace_runme.1.d
@@ -0,0 +1,87 @@
+module nspace_runme;
+
+import nspace.nspace;
+static import nspace.NoNSpacePlease;
+static import nspace.Outer.namespce;
+static import nspace.Outer.Inner1.Channel;
+static import oi1c = nspace.Outer.Inner1.Color;
+static import nspace.Outer.Inner2.Channel;
+static import nspace.Outer.Inner2.Color;
+static import nspace.Outer.Inner3.Blue;
+static import nspace.Outer.Inner4.Blue;
+static import nspace.Outer.SomeClass;
+
+void main() {
+ // constructors and destructors
+ auto color1 = new oi1c.Color();
+ auto color = new oi1c.Color(color1);
+
+ // class methods
+ color.colorInstanceMethod(20.0);
+ oi1c.Color.colorStaticMethod(20.0);
+ auto created = oi1c.Color.create();
+
+ // class enums
+ auto someClass = new nspace.Outer.SomeClass.SomeClass();
+ auto channel = someClass.GetInner1ColorChannel();
+ if (channel != oi1c.Color.Channel.Transmission) {
+ throw new Exception("Transmission wrong");
+ }
+
+ // class anonymous enums
+ int val1 = oi1c.Color.ColorEnumVal1;
+ int val2 = oi1c.Color.ColorEnumVal2;
+ if (val1 != 0 || val2 != 0x22) {
+ throw new Exception("ColorEnumVal wrong");
+ }
+
+ // instance member variables
+ color.instanceMemberVariable = 123;
+ if (color.instanceMemberVariable != 123) {
+ throw new Exception("instance member variable failed");
+ }
+
+ // static member variables
+ oi1c.Color.staticMemberVariable = 789;
+ if (oi1c.Color.staticMemberVariable != 789) {
+ throw new Exception("static member variable failed");
+ }
+ if (oi1c.Color.staticConstMemberVariable != 222) {
+ throw new Exception("static const member variable failed");
+ }
+ if (oi1c.Color.staticConstEnumMemberVariable != oi1c.Color.Channel.Transmission) {
+ throw new Exception("static const enum member variable failed");
+ }
+
+ // check globals in a namespace don't get mangled with the nspace option
+ nspace.nspace.namespaceFunction(color);
+ nspace.nspace.namespaceVar = 111;
+ if (nspace.nspace.namespaceVar != 111) {
+ throw new Exception("global var failed");
+ }
+
+ // Same class different namespaces
+ auto col1 = new oi1c.Color();
+ auto col2 = nspace.Outer.Inner2.Color.Color.create();
+ col2.colors(col1, col1, col2, col2, col2);
+
+ // global enums
+ auto outerChannel1 = someClass.GetInner1Channel();
+ if (outerChannel1 != nspace.Outer.Inner1.Channel.Channel.Transmission1) {
+ throw new Exception("Transmission1 wrong");
+ }
+ auto outerChannel2 = someClass.GetInner2Channel();
+ if (outerChannel2 != nspace.Outer.Inner2.Channel.Channel.Transmission2) {
+ throw new Exception("Transmission2 wrong");
+ }
+
+ // turn feature off / ignoring
+ auto ns = new nspace.Outer.namespce.namespce();
+ auto nons = new nspace.NoNSpacePlease.NoNSpacePlease();
+
+ // Derived class
+ auto blue3 = new nspace.Outer.Inner3.Blue.Blue();
+ blue3.blueInstanceMethod();
+ auto blue4 = new nspace.Outer.Inner4.Blue.Blue();
+ blue4.blueInstanceMethod();
+}
diff --git a/Examples/test-suite/d/nspace_runme.2.d b/Examples/test-suite/d/nspace_runme.2.d
new file mode 100644
index 000000000..a86e4db9e
--- /dev/null
+++ b/Examples/test-suite/d/nspace_runme.2.d
@@ -0,0 +1,77 @@
+module nspace_runme;
+
+import std.exception;
+import nspace.nspace;
+static import nspace.NoNSpacePlease;
+static import nspace.Outer.namespce;
+static import nspace.Outer.Inner1.Channel;
+static import oi1c = nspace.Outer.Inner1.Color;
+static import nspace.Outer.Inner2.Channel;
+static import nspace.Outer.Inner2.Color;
+static import nspace.Outer.Inner3.Blue;
+static import nspace.Outer.Inner4.Blue;
+static import nspace.Outer.SomeClass;
+
+void main() {
+ // constructors and destructors
+ auto color1 = new oi1c.Color();
+ auto color = new oi1c.Color(color1);
+
+ // class methods
+ color.colorInstanceMethod(20.0);
+ oi1c.Color.colorStaticMethod(20.0);
+ auto created = oi1c.Color.create();
+
+ // class enums
+ auto someClass = new nspace.Outer.SomeClass.SomeClass();
+ auto channel = someClass.GetInner1ColorChannel();
+ enforce(channel == oi1c.Color.Channel.Transmission,
+ "Transmission wrong");
+
+ // class anonymous enums
+ int val1 = oi1c.Color.ColorEnumVal1;
+ int val2 = oi1c.Color.ColorEnumVal2;
+ enforce(val1 == 0 && val2 == 0x22, "ColorEnumVal wrong");
+
+ // instance member variables
+ color.instanceMemberVariable = 123;
+ enforce(color.instanceMemberVariable == 123,
+ "instance member variable failed");
+
+ // static member variables
+ oi1c.Color.staticMemberVariable = 789;
+ enforce(oi1c.Color.staticMemberVariable == 789,
+ "static member variable failed");
+ enforce(oi1c.Color.staticConstMemberVariable == 222,
+ "static const member variable failed");
+ enforce(oi1c.Color.staticConstEnumMemberVariable == oi1c.Color.Channel.Transmission,
+ "static const enum member variable failed");
+
+ // check globals in a namespace don't get mangled with the nspace option
+ nspace.nspace.namespaceFunction(color);
+ nspace.nspace.namespaceVar = 111;
+ enforce(nspace.nspace.namespaceVar == 111, "global var failed");
+
+ // Same class different namespaces
+ auto col1 = new oi1c.Color();
+ auto col2 = nspace.Outer.Inner2.Color.Color.create();
+ col2.colors(col1, col1, col2, col2, col2);
+
+ // global enums
+ auto outerChannel1 = someClass.GetInner1Channel();
+ enforce(outerChannel1 == nspace.Outer.Inner1.Channel.Channel.Transmission1,
+ "Transmission1 wrong");
+ auto outerChannel2 = someClass.GetInner2Channel();
+ enforce(outerChannel2 == nspace.Outer.Inner2.Channel.Channel.Transmission2,
+ "Transmission2 wrong");
+
+ // turn feature off / ignoring
+ auto ns = new nspace.Outer.namespce.namespce();
+ auto nons = new nspace.NoNSpacePlease.NoNSpacePlease();
+
+ // Derived class
+ auto blue3 = new nspace.Outer.Inner3.Blue.Blue();
+ blue3.blueInstanceMethod();
+ auto blue4 = new nspace.Outer.Inner4.Blue.Blue();
+ blue4.blueInstanceMethod();
+}
diff --git a/Examples/test-suite/java/nspace_runme.java b/Examples/test-suite/java/nspace_runme.java
index 9800e79cd..4b58c6b54 100644
--- a/Examples/test-suite/java/nspace_runme.java
+++ b/Examples/test-suite/java/nspace_runme.java
@@ -68,7 +68,7 @@ public class nspace_runme {
throw new RuntimeException("Transmission2 wrong");
// turn feature off / ignoring
- nspacePackage.Outer.nspace ns = new nspacePackage.Outer.nspace();
+ nspacePackage.Outer.namespce ns = new nspacePackage.Outer.namespce();
nspacePackage.NoNSpacePlease nons = new nspacePackage.NoNSpacePlease();
// Derived class
diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i
index 4e4e461c0..89009b939 100644
--- a/Examples/test-suite/nspace.i
+++ b/Examples/test-suite/nspace.i
@@ -2,7 +2,7 @@
%module nspace
// nspace feature only supported by these languages
-#if defined(SWIGJAVA) || defined(SWIGCSHARP)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
%nspace;
%nonspace Outer::Inner2::NoNSpacePlease;
@@ -15,7 +15,7 @@
%inline %{
namespace Outer {
- class nspace {
+ class namespce {
};
namespace Inner1 {
enum Channel { Diffuse, Specular = 0x10, Transmission1 };
@@ -33,12 +33,12 @@ namespace Outer {
static const Channel staticConstEnumMemberVariable = Transmission;
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
- }; // Color
+ }; // Color
int Color::staticMemberVariable = 0;
Color namespaceFunction(Color k) { return k; }
int namespaceVar = 0;
- } // Inner1
+ } // Inner1
namespace Inner2 {
enum Channel { Diffuse, Specular = 0x30, Transmission2 };
@@ -56,12 +56,12 @@ namespace Outer {
static const Channel staticConstEnumMemberVariable = Transmission;
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
- void colors(const Inner1::Color& col1a,
- const Outer::Inner1::Color& col1b,
- const Color &col2a,
- const Inner2::Color& col2b,
+ void colors(const Inner1::Color& col1a,
+ const Outer::Inner1::Color& col1b,
+ const Color &col2a,
+ const Inner2::Color& col2b,
const Outer::Inner2::Color& col2c) {}
- }; // Color
+ }; // Color
int Color::staticMemberVariable = 0;
class NoNSpacePlease {};
} // Inner2
diff --git a/Examples/test-suite/nspace_extend.i b/Examples/test-suite/nspace_extend.i
index 88f40bc69..47ede95d0 100644
--- a/Examples/test-suite/nspace_extend.i
+++ b/Examples/test-suite/nspace_extend.i
@@ -2,7 +2,7 @@
%module nspace_extend
// nspace feature only supported by these languages
-#if defined(SWIGJAVA) || defined(SWIGCSHARP)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
%nspace;
@@ -39,10 +39,10 @@ namespace Outer {
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
- void colors(const Inner1::Color& col1a,
- const Outer::Inner1::Color& col1b,
- const Color &col2a,
- const Inner2::Color& col2b,
+ void colors(const Inner1::Color& col1a,
+ const Outer::Inner1::Color& col1b,
+ const Color &col2a,
+ const Inner2::Color& col2b,
const Outer::Inner2::Color& col2c) {}
}