summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Nadlinger <code@klickverbot.at>2010-11-18 00:24:02 +0000
committerDavid Nadlinger <code@klickverbot.at>2010-11-18 00:24:02 +0000
commit03aefbc6e95d094a6de231e1f5264c0946e209a3 (patch)
tree94dff73a4aa3c27366f29f36712bde78317c5776
parenta355d2d46af56c655816c37f24bb59fa6bade43f (diff)
downloadswig-03aefbc6e95d094a6de231e1f5264c0946e209a3.tar.gz
Added support for the D programming languge.
It is still a bit rough around some edges, particularly with regard to multi-threading and operator overloading, and there are some documentation bits missing, but it should be fine for basic use. The test-suite should build and run fine with the current versions of DMD, LDC and Tango (at least) on Linux x86_64 and Mac OS X 10.6. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12299 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--Doc/Manual/D.html401
-rw-r--r--Doc/Manual/Sections.html1
-rw-r--r--Doc/Manual/chapters1
-rw-r--r--Examples/Makefile.in89
-rw-r--r--Examples/d/callback/Makefile28
-rw-r--r--Examples/d/callback/d1/runme.d36
-rw-r--r--Examples/d/callback/d2/runme.d36
-rw-r--r--Examples/d/callback/example.cxx4
-rw-r--r--Examples/d/callback/example.h24
-rw-r--r--Examples/d/callback/example.i13
-rw-r--r--Examples/d/check.list9
-rw-r--r--Examples/d/class/Makefile28
-rw-r--r--Examples/d/class/d1/runme.d58
-rw-r--r--Examples/d/class/d2/runme.d58
-rw-r--r--Examples/d/class/example.cxx28
-rw-r--r--Examples/d/class/example.h34
-rw-r--r--Examples/d/class/example.i10
-rw-r--r--Examples/d/constants/Makefile28
-rw-r--r--Examples/d/constants/d1/runme.d28
-rw-r--r--Examples/d/constants/d2/runme.d28
-rw-r--r--Examples/d/constants/example.d23
-rw-r--r--Examples/d/constants/example.i32
-rw-r--r--Examples/d/enum/Makefile28
-rw-r--r--Examples/d/enum/d1/runme.d28
-rw-r--r--Examples/d/enum/d2/runme.d28
-rw-r--r--Examples/d/enum/example.cxx37
-rw-r--r--Examples/d/enum/example.h13
-rw-r--r--Examples/d/enum/example.i11
-rw-r--r--Examples/d/extend/Makefile28
-rw-r--r--Examples/d/extend/d1/runme.d75
-rw-r--r--Examples/d/extend/d2/runme.d75
-rw-r--r--Examples/d/extend/example.cxx4
-rw-r--r--Examples/d/extend/example.h56
-rw-r--r--Examples/d/extend/example.i14
-rw-r--r--Examples/d/funcptr/Makefile28
-rw-r--r--Examples/d/funcptr/d1/runme.d34
-rw-r--r--Examples/d/funcptr/d2/runme.d34
-rw-r--r--Examples/d/funcptr/example.c19
-rw-r--r--Examples/d/funcptr/example.h9
-rw-r--r--Examples/d/funcptr/example.i16
-rw-r--r--Examples/d/simple/Makefile28
-rw-r--r--Examples/d/simple/d1/runme.d27
-rw-r--r--Examples/d/simple/d2/runme.d27
-rw-r--r--Examples/d/simple/example.c18
-rw-r--r--Examples/d/simple/example.i7
-rw-r--r--Examples/d/variables/Makefile28
-rw-r--r--Examples/d/variables/d1/runme.d71
-rw-r--r--Examples/d/variables/d2/runme.d71
-rw-r--r--Examples/d/variables/example.c91
-rw-r--r--Examples/d/variables/example.h6
-rw-r--r--Examples/d/variables/example.i49
-rw-r--r--Examples/test-suite/d/Makefile.in80
-rw-r--r--Examples/test-suite/d/README7
-rw-r--r--Examples/test-suite/d/aggregate_runme.1.d25
-rw-r--r--Examples/test-suite/d/aggregate_runme.2.d25
-rw-r--r--Examples/test-suite/d/allprotected_runme.1.d65
-rw-r--r--Examples/test-suite/d/allprotected_runme.2.d65
-rw-r--r--Examples/test-suite/d/apply_strings_runme.1.d12
-rw-r--r--Examples/test-suite/d/apply_strings_runme.2.d12
-rw-r--r--Examples/test-suite/d/bools_runme.1.d20
-rw-r--r--Examples/test-suite/d/bools_runme.2.d20
-rw-r--r--Examples/test-suite/d/catches_runme.1.d33
-rw-r--r--Examples/test-suite/d/catches_runme.2.d33
-rw-r--r--Examples/test-suite/d/char_strings_runme.1.d151
-rw-r--r--Examples/test-suite/d/char_strings_runme.2.d123
-rw-r--r--Examples/test-suite/d/constover_runme.1.d31
-rw-r--r--Examples/test-suite/d/constover_runme.2.d16
-rw-r--r--Examples/test-suite/d/d_nativepointers_runme.1.d23
-rw-r--r--Examples/test-suite/d/d_nativepointers_runme.2.d23
-rw-r--r--Examples/test-suite/d/default_args_runme.1.d127
-rw-r--r--Examples/test-suite/d/default_args_runme.2.d84
-rw-r--r--Examples/test-suite/d/default_constructor_runme.1.d30
-rw-r--r--Examples/test-suite/d/default_constructor_runme.2.d25
-rw-r--r--Examples/test-suite/d/director_basic_runme.1.d59
-rw-r--r--Examples/test-suite/d/director_basic_runme.2.d46
-rw-r--r--Examples/test-suite/d/director_classes_runme.1.d168
-rw-r--r--Examples/test-suite/d/director_classes_runme.2.d169
-rw-r--r--Examples/test-suite/d/director_classic_runme.1.d207
-rw-r--r--Examples/test-suite/d/director_classic_runme.2.d202
-rw-r--r--Examples/test-suite/d/director_ignore_runme.1.d39
-rw-r--r--Examples/test-suite/d/director_ignore_runme.2.d38
-rw-r--r--Examples/test-suite/d/director_primitives_runme.1.d122
-rw-r--r--Examples/test-suite/d/director_primitives_runme.2.d123
-rw-r--r--Examples/test-suite/d/director_protected_runme.1.d50
-rw-r--r--Examples/test-suite/d/director_protected_runme.2.d36
-rw-r--r--Examples/test-suite/d/director_string_runme.1.d46
-rw-r--r--Examples/test-suite/d/director_string_runme.2.d42
-rw-r--r--Examples/test-suite/d/enum_thorough_runme.1.d424
-rw-r--r--Examples/test-suite/d/enum_thorough_runme.2.d425
-rw-r--r--Examples/test-suite/d/inherit_target_language_runme.1.d29
-rw-r--r--Examples/test-suite/d/inherit_target_language_runme.2.d29
-rw-r--r--Examples/test-suite/d/li_attribute_runme.1.d75
-rw-r--r--Examples/test-suite/d/li_attribute_runme.2.d58
-rw-r--r--Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d21
-rw-r--r--Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d19
-rw-r--r--Examples/test-suite/d/li_boost_shared_ptr_runme.1.d604
-rw-r--r--Examples/test-suite/d/li_boost_shared_ptr_runme.2.d602
-rw-r--r--Examples/test-suite/d/li_std_except_runme.1.d40
-rw-r--r--Examples/test-suite/d/li_std_except_runme.2.d34
-rw-r--r--Examples/test-suite/d/li_std_string_runme.1.d97
-rw-r--r--Examples/test-suite/d/li_std_string_runme.2.d86
-rw-r--r--Examples/test-suite/d/li_std_vector_runme.1.d219
-rw-r--r--Examples/test-suite/d/li_std_vector_runme.2.d207
-rw-r--r--Examples/test-suite/d/li_typemaps_runme.1.d94
-rw-r--r--Examples/test-suite/d/li_typemaps_runme.2.d91
-rw-r--r--Examples/test-suite/d/long_long_runme.1.d35
-rw-r--r--Examples/test-suite/d/long_long_runme.2.d32
-rw-r--r--Examples/test-suite/d/member_pointer_runme.1.d43
-rw-r--r--Examples/test-suite/d/member_pointer_runme.2.d42
-rw-r--r--Examples/test-suite/d/overload_complicated_runme.1.d50
-rw-r--r--Examples/test-suite/d/overload_complicated_runme.2.d34
-rw-r--r--Examples/test-suite/d/overload_template_runme.1.d146
-rw-r--r--Examples/test-suite/d/overload_template_runme.2.d80
-rw-r--r--Examples/test-suite/d/pointer_reference_runme.1.d13
-rw-r--r--Examples/test-suite/d/pointer_reference_runme.2.d14
-rw-r--r--Examples/test-suite/d/preproc_constants_c_runme.1.d63
-rw-r--r--Examples/test-suite/d/preproc_constants_c_runme.2.d63
-rw-r--r--Examples/test-suite/d/preproc_constants_runme.1.d62
-rw-r--r--Examples/test-suite/d/preproc_constants_runme.2.d62
-rw-r--r--Examples/test-suite/d/sizet_runme.1.d15
-rw-r--r--Examples/test-suite/d/sizet_runme.2.d14
-rw-r--r--Examples/test-suite/d/sneaky1_runme.1.d21
-rw-r--r--Examples/test-suite/d/sneaky1_runme.2.d11
-rw-r--r--Examples/test-suite/d/special_variable_macros_runme.1.d39
-rw-r--r--Examples/test-suite/d/special_variable_macros_runme.2.d21
-rw-r--r--Examples/test-suite/d/threads_runme.1.d70
-rw-r--r--Examples/test-suite/d/threads_runme.2.d55
-rw-r--r--Examples/test-suite/d/throw_exception_runme.1.d30
-rw-r--r--Examples/test-suite/d/throw_exception_runme.2.d30
-rw-r--r--Examples/test-suite/d/typemap_namespace_runme.1.d13
-rw-r--r--Examples/test-suite/d/typemap_namespace_runme.2.d9
-rw-r--r--Examples/test-suite/d/typemap_out_optimal_runme.1.d9
-rw-r--r--Examples/test-suite/d/typemap_out_optimal_runme.2.d9
-rw-r--r--Examples/test-suite/d/varargs_runme.1.d20
-rw-r--r--Examples/test-suite/d/varargs_runme.2.d13
-rw-r--r--Examples/test-suite/d/virtual_poly_runme.1.d27
-rw-r--r--Examples/test-suite/d/virtual_poly_runme.2.d22
-rw-r--r--Examples/test-suite/d_nativepointers.i18
-rw-r--r--Lib/allkw.swg1
-rw-r--r--Lib/d/boost_shared_ptr.i201
-rw-r--r--Lib/d/carrays.i111
-rw-r--r--Lib/d/cpointer.i171
-rw-r--r--Lib/d/d.swg46
-rw-r--r--Lib/d/dclassgen.swg172
-rw-r--r--Lib/d/ddirectives.swg11
-rw-r--r--Lib/d/denums.swg60
-rw-r--r--Lib/d/dexception.swg30
-rw-r--r--Lib/d/dhead.swg310
-rw-r--r--Lib/d/director.swg46
-rw-r--r--Lib/d/dkw.swg126
-rw-r--r--Lib/d/dmemberfunctionpointers.swg92
-rw-r--r--Lib/d/doperators.swg77
-rw-r--r--Lib/d/dprimitives.swg158
-rw-r--r--Lib/d/dstrings.swg80
-rw-r--r--Lib/d/dswigtype.swg177
-rw-r--r--Lib/d/dvoid.swg18
-rw-r--r--Lib/d/std_common.i5
-rw-r--r--Lib/d/std_deque.i1
-rw-r--r--Lib/d/std_except.i30
-rw-r--r--Lib/d/std_map.i59
-rw-r--r--Lib/d/std_pair.i34
-rw-r--r--Lib/d/std_shared_ptr.i2
-rw-r--r--Lib/d/std_string.i98
-rw-r--r--Lib/d/std_vector.i591
-rw-r--r--Lib/d/stl.i12
-rw-r--r--Lib/d/typemaps.i298
-rw-r--r--Lib/d/wrapperloader.swg303
-rw-r--r--Lib/exception.i36
-rw-r--r--Lib/std_except.i2
-rw-r--r--Lib/swig.swg4
-rw-r--r--Makefile.in17
-rw-r--r--Source/Include/swigwarn.h21
-rw-r--r--Source/Makefile.am1
-rw-r--r--Source/Modules/d.cxx4359
-rw-r--r--Source/Modules/swigmain.cxx2
-rw-r--r--configure.in43
176 files changed, 16449 insertions, 29 deletions
diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html
new file mode 100644
index 000000000..2b563788f
--- /dev/null
+++ b/Doc/Manual/D.html
@@ -0,0 +1,401 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>SWIG and D</title>
+<link rel="stylesheet" type="text/css" href="style.css">
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+</head>
+<body bgcolor="#FFFFFF">
+<H1><a name="D"></a>20 SWIG and D</H1>
+<!-- INDEX -->
+<div class="sectiontoc">
+<ul>
+<li><a href="#D_introduction">Introduction</a>
+<li><a href="#D_command_line_invocation">Command line invocation</a>
+<li><a href="#D_typemaps">Typemaps</a>
+<ul>
+<li><a href="#D_typemap_name_comparison">C# &lt;-&gt; D name comparison</a>
+<li><a href="#D_cwtype_dwtype_dptype">cwtype, dwtype, dptype</a>
+<li><a href="#D_in_out_directorin_direcetorout">in, out, directorin, directorout</a>
+<li><a href="#D_din_dout_ddirectorin_ddirectorout">din, dout, ddirectorin, ddirectorout</a>
+<li><a href="#D_typecheck_typemaps">typecheck typemaps</a>
+<li><a href="#D_code_injection_typemaps">Code injection typemaps</a>
+<li><a href="#D_special_variables">Special variable macros</a>
+</ul>
+<li><a href="#D_features"><tt>%feature</tt>s</a>
+<li><a href="#D_pragmas">Pragmas</a>
+<li><a href="#D_exceptions">D Exceptions</a>
+<li><a href="#D_directors">D Directors</a>
+<li><a href="#D_other_features">Other features</a>
+<li><a href="#D_typemap_examples">D Typemap examples</a>
+<li><a href="#D_planned_features">Work in progress and planned features</a>
+</ul>
+</div>
+<!-- INDEX -->
+
+
+
+<H2><a name="D_introduction"></a>20.1 Introduction</H2>
+
+
+<p>From the <a href="http://www.digitalmars.com/d/">D Programming Language</a> web site: <em>»D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. […] The D language is statically typed and compiles directly to machine code.«</em> As such, it is not very surprising that D is able to directly <a href="http://www.digitalmars.com/d/1.0/interfaceToC.html">interface with C libraries</a>. Why would a SWIG module for D be needed then in the first place?</p>
+
+<p>Well, besides the obvious downside that the C header files have to be manually converted to D modules for this to work, there is one major inconvenience with this approach: D code usually is on a higher abstraction level than C, and many of the features that make D interesting are simply not available when dealing with C libraries, requiring you e.g. to manually convert strings between pointers to <tt>\0</tt>-terminated char arrays and D char arrays, making the algorithms from the D2 standard library unusable with C arrays and data structures, and so on.</p>
+
+<p>While these issues can be worked around relatively easy by hand-coding a thin wrapper layer around the C library in question, there is another issue where writing wrapper code per hand is not feasible: C++ libraries. D did not support interfacing to C++ in version 1 at all, and even if <tt>extern(C++)</tt> has been added to D2, the support is still very limited, and a custom wrapper layer is still required in many cases. </p>
+
+<p>To help addressing these issues, the SWIG C# module has been forked to support D. Is has evolved quite a lot since then, but there are still many similarities, so if you do not find what you are looking for on this page, it might be worth having a look at the chapter on <a href="CSharp.html">C#</a> (and also on <a href="Java.html">Java</a>, since the C# module was in turn forked from it).</p>
+
+
+<H2><a name="D_command_line_invocation"></a>20.2 Command line invocation</H2>
+
+
+<p>To activate the D module, pass the <tt>-d</tt> option to SWIG at the command line. The same standard command line switches as with any other language module are available, plus the following D specific ones:</p>
+
+<dl>
+ <dt id="D_splitproxy"><tt>-splitproxy</tt></dt>
+ <dd>
+ <p>By default, SWIG generates two D modules: the <em>proxy</em> module, named like the source module (either specified via the <tt>%module</tt> directive or via the <tt>module</tt> command line switch), which contains all the proxy classes, functions, enums, etc., and the <em>wrap</em> module (named like the proxy module, but suffixed with <tt>_wrap</tt>), which contains all the <tt>extern(C)</tt> function declarations and other private parts only used internally by the proxy module.</p>
+ <p>If the split proxy mode is enabled by passing this switch at the command line, all proxy classes and enums are emitted to their own D module instead. The main proxy module only contains free functions and constants in this case.</p>
+ </dd>
+
+ <dt><tt>-package &lt;pkg&gt;</tt></dt>
+ <dd>
+ <p>By default, the proxy D modules and the wrap D module are written to the root package. Using this option, you can specify another target package instead.</p>
+ </dd>
+
+ <dt><tt>-wrapperlibrary &lt;wl&gt;</tt></dt>
+ <dd>
+ <p>The code SWIG generates to dynamically load the C/C++ wrapper layer looks for a library called <tt>$module_wrap</tt>, just like the wrap D module is. With this switch, you can override the name of the file the wrapper code loads at runtime (the <tt>lib</tt> prefix and the suffix for shared libraries are appended automatically, depending on the OS).</p>
+ <p>This might especially be useful if you want to invoke SWIG several times on separate modules, but compile the resulting code into a single shared library.</p>
+ </dd>
+</dl>
+
+
+<H2><a name="D_typemaps"></a>20.3 Typemaps</H2>
+
+
+<H3><a name="D_typemap_name_comparison"></a>20.3.1 C# &lt;-&gt; D name comparison</H3>
+
+
+<div class="diagram"><pre>
+ ctype &lt;-&gt; cwtype
+ imtype &lt;-&gt; dwtype
+ cstype &lt;-&gt; dptype
+ csin &lt;-&gt; din
+ csout &lt;-&gt; dout
+ csdirectorin &lt;-&gt; ddirectorin
+ csdirectorout &lt;-&gt; ddirectorout
+ csinterfaces &lt;-&gt; dinterfaces
+ csinterfaces_derived &lt;-&gt; dinterfaces_derived
+ csbase &lt;-&gt; dbase
+ csclassmodifiers &lt;-&gt; dclassmodifiers
+ cscode &lt;-&gt; dcode
+ csimports &lt;-&gt; dimports
+ csbody &lt;-&gt; dbody
+ csfinalize &lt;-&gt; ddestructor
+ csdestruct &lt;-&gt; ddispose
+ csdestruct_derived &lt;-&gt; ddispose_derived
+</pre></div>
+
+
+<H3><a name="D_cwtype_dwtype_dptype"></a>20.3.2 cwtype, dwtype, dptype</H3>
+
+
+<p>Mapping of types between the C/C++ library, the C/C++ library wrapper exposing the C functions, the D wrapper module importing these functions and the D proxy code.</p>
+
+<p>The <tt>cwtype</tt> typemap is used to determine the types to use in the C wrapper functions. The types from the <tt>dwtype</tt> typemap are used in the extern(C) declarations of these functions in the D wrap module. The <tt>dptype</tt> typemap contains the D types used in the D proxy module/class.</p>
+
+
+<H3><a name="D_in_out_directorin_direcetorout"></a>20.3.3 in, out, directorin, directorout</H3>
+
+
+<p>Used for converting between the types for C/C++ and D when generating the code for the wrapper functions (on the C++ side).</p>
+
+<p>The code from the <tt>in</tt> typemap is used to convert arguments to the C wrapper function to the type used in the wrapped code (<tt>cwtype</tt>->original C++ type), the <tt>out</tt> typemap is utilized to convert values from the wrapped code to wrapper function return types (original C++ type-><tt>cwtype</tt>).</p>
+
+<p>The <tt>directorin</tt> typemap is used to convert parameters to the type used in the D director callback function, its return value is processed by <tt>directorout</tt> (see below).</p>
+
+
+<H3><a name="D_din_dout_ddirectorin_ddirectorout"></a>20.3.4 din, dout, ddirectorin, ddirectorout</H3>
+
+
+<p>Typemaps for code generation in D proxy and type wrapper classes.</p>
+
+<p id="D_din">The <tt>din</tt> typemap is used for converting function parameter types from the type used in the proxy module or class to the type used in the D wrap module (the <a href="D.html#D_dinput"><tt>$dinput</tt></a> macro is replaced).</p>
+
+<p id="D_dout">The <tt>dout</tt> typemap is used for converting function return values from the return type used in the wrap D module to the type returned by the proxy function. The <tt>$excode</tt> special variable in <tt>dout</tt> typemaps is replaced by the <tt>excode</tt> typemap attribute code if the method can throw any exceptions from unmanaged code, otherwise by nothing (the <a href="D.html#D_wcall"><tt>$wcall</tt> and <tt>$owner</tt></a> macros are replaced).</p>
+
+<p id="D_ddirectorinout">The code from the <tt>ddirectorin</tt> and <tt>ddirectorout</tt> typemaps is used for conversion in director callback functions. Arguments are converted to the type used in the proxy class method they are calling by using the code from <tt>ddirectorin</tt>, the proxy class method return value is converted to the type the C++ code expects via the <tt>ddirectorout</tt> typemap (the <a href="D.html#D_dpcall"><tt>$dpcall</tt> and <tt>$winput</tt></a> macros are replaced).</p>
+
+<p>The full chain of type conversions when a director callback is invoked looks like this:</p>
+
+ <div class="diagram"><pre> type CPPClass::method(type a)
+ ↑ ↓
+ &lt;directorout&gt; &lt;directorin&gt;
+ ↑ ↓
+ cwtype methodCallback(cwtype a) C++
+ ::::::::::::::::::::::::::::::::::::::::::
+ dwtype methodCallback(dwtype a) D
+ ↑ ↓
+ &lt;ddirectorout&gt; &lt;ddirectorin&gt;
+ ↑ ↓
+ dptype DClass.method(dptype a)</pre></div>
+
+
+<H3><a name="D_typecheck_typemaps"></a>20.3.5 typecheck typemaps</H3>
+
+
+<p>Because, unlike many scripting languages supported by SWIG, D does not need any dynamic dispatch helper to access an overloaded function, the purpose of these is merely to issue a warning for overloaded C++ functions that cannot be overloaded in D (as more than one C++ type maps to a single D type).</p>
+
+
+<H3><a name="D_code_injection_typemaps"></a>20.3.6 Code injection typemaps</H3>
+
+
+<p>These typemaps are used for generating the skeleton of proxy classes for C++ types.</p>
+
+<p>By overriding <tt>dbase</tt>, <tt>dinterfaces</tt> or <tt>dinterfaces_derived</tt>, the inheritance chain of the generated proxy class for a type can be modified. <tt>dclassmodifiers</tt> allows you to add any custom modifiers around the class keyword.</p>
+
+<p>Using <tt>dcode</tt> and <tt>dimports</tt>, you can specify additional D code which will be emitted into the class body respectively the imports section of the D module the class is written to.</p>
+
+<p id="D_class_code_typemaps"><tt>dconstructor</tt>, <tt>ddestructor</tt>, <tt>ddispose</tt> and <tt>ddispose_derived</tt> are used to generate the class constructor, destructor and <tt>dispose()</tt> method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in <tt>dbody</tt> and <tt>dbody_derived</tt>. You can override them for specific types.</p>
+
+
+<H3><a name="D_special_variables"></a>20.3.7 Special variable macros</H3>
+
+
+<p>The standard SWIG special variables are available for use within typemaps as described in the <a href="Typemaps.html#Typemaps">Typemaps documentation</a>, for example <tt>$1</tt>, <tt>$input</tt>, <tt>$result</tt> etc.</p>
+
+<p>When generating D wrappers, a few additional macros are available:</p>
+<dl>
+ <dt><tt>$dclassname</tt> (C#: <tt>$csclassname</tt>)</dt>
+ <dd>
+ <p>This special variable works similar to <a href="Typemaps.html#Typemaps_special_variables"><tt>$n_type</tt></a> in that it returns the name of a type – it expands to the D proxy class name of the type being wrapped. If the type does not have an associated proxy class, it expands to the type wrapper class name, for example, <tt>SWIGTYPE_p_p_SomeCppClass</tt> is generated when wrapping <tt>SomeCppClass **</tt>.</p>
+ <p>There are two other variants available, <tt>$&amp;dclassname</tt> and <tt>$*dclassname</tt>. The former adds a level of indirection, while the latter removes one. For instance, when wrapping <tt>Foo **</tt>, <tt>$*dclassname</tt> would be replaced by the proxy class name corresponding to <tt>Foo *</tt>.</p>
+ </dd>
+
+ <dt><tt>$null</tt></dt>
+ <dd><p>In code inserted into the generated C/C++ wrapper functions, this variable is replaced by either <tt>0</tt> or nothing at all, depending on whether the function has a return value or not. It can be used to bail out early e.g. in case of errors (<tt>return $null;</tt>).</p></dd>
+
+ <dt id="D_dinput"><tt>$dinput</tt> (C#: <tt>$csinput</tt>)</dt>
+ <dd>
+ <p>This variable is used in <tt><a href="D.html#D_din">din</a></tt> typemaps and is replaced by the expression which is to be passed to C/C++.</p>
+ <p>For example, this input</p>
+ <div class="code"><pre>
+%typemap(din) SomeClass * "SomeClass.getCPointer($dinput)"
+
+%inline %{
+ class SomeClass {};
+ void foo(SomeClass *arg);
+%}</pre></div>
+ <p>leads to the following D proxy code being generated:</p>
+<div class="targetlang"><pre>
+void foo(SomeClass arg) {
+ example_wrap.foo(SomeClass.getCPointer(arg));
+}</pre></div></dd>
+
+ <dt id="D_wcall"><tt>$wcall</tt> and <tt>$owner</tt> (C#: <tt>$imcall</tt>)</dt>
+ <dd>
+ <p>These variables are used in <tt><a href="D.html#D_dout">dout</a></tt> typemaps. <tt>$wcall</tt> contains the call to the wrapper layer which provides the value to be used, and <tt>$owner</tt> signals if the caller is responsible for managing the object lifetime (that is, if the called method is a constructor or has been marked via <tt>%newobject</tt>).</p>
+ <p>Consider the following example:</p>
+<div class="code"><pre>
+%typemap(dout) SomeClass * {
+ return new SomeClass($wcall, $owner);
+}
+
+%inline %{
+ class SomeClass;
+ SomeClass *foo();
+
+ %newobject bar();
+ SomeClass *bar();
+%}</pre></div>
+ <p>The code generated for <tt>foo()</tt> and <tt>bar()</tt> looks like this:</p>
+<div class="targetlang"><pre>
+SomeClass foo() {
+ return new SomeClass(example_wrap.foo(), false);
+}
+
+SomeClass bar() {
+ return new SomeClass(example_wrap.bar(), true);
+}
+</pre></div>
+ </dd>
+
+ <dt><tt>$dpcall</tt> and <tt>$winput</tt> (C#: <tt>$cscall</tt>, <tt>$iminput</tt>)</dt>
+ <dd id="D_dpcall"><p>These variables are used in the director-specific typemaps <a href="D.html#D_ddirectorinout"><tt>ddirectorin</tt></a> and <a href="D.html#D_ddirectorinout"><tt>ddirectorout</tt></a>. They are more or less the reverse of the <tt>$wcall</tt> and <tt>$dinput</tt> macros: <tt>$dpcall</tt> contains the invocation of the D proxy method of which the return value is to be passed back to C++, <tt>$winput</tt> contains the parameter value from C++.</p></dd>
+
+ <dt><tt>$excode</tt></dt>
+ <dd><p>This variable is used in <tt>dout</tt> and <tt>dconstructor</tt> typemaps and is filled with the contents of the <tt>excode</tt> typemap attribute if an exception could be thrown from the C++ side. See the <a href="CSharp.html#CSharp_exceptions">C# documentation</a> for details.</p></dd>
+
+ <dt><tt>$dbaseclass</tt></dt>
+ <dd><p>Currently for internal use only, it contains the D name of the C++ base class (if any) inside proxy classes.</p></dd>
+
+ <dt><tt>$directorconnect</tt></dt>
+ <dd>
+ <p>This macro is only valid inside the <tt><a href="D.html#D_class_code_typemaps">dconstructor</a></tt> typemap and contains the value of the <tt>dconstructor</tt> typemap attribute if the currently wrapped class has directors enabled.</p>
+ <p>This is how the default <tt>dconstructor</tt> typemap looks like (you usually do not want to specify a custom one):</p>
+<div class="code"><pre>
+%typemap(dconstructor, excode=SWIGEXCODE,directorconnect="\n swigDirectorConnect();") SWIGTYPE {
+ this($wcall, true);$excode$directorconnect
+}
+</pre></div>
+ </dd>
+
+ <dt id="D_importtype"><tt>$importtype(SomeDType)</tt></dt>
+ <dd>
+ <p>This macro is used in the <tt>dimports</tt> typemap if a dependency on another D type generated by SWIG is added by a custom typemap.</p>
+ <p>Consider the following code snippet:</p>
+<div class="code"><pre>
+%typemap(dinterfaces) SomeClass "AnInterface, AnotherInterface";
+</pre></div>
+ <p>This causes SWIG to add <tt>AnInterface</tt> and <tt>AnotherInterface</tt> to the base class list of <tt>SomeClass</tt>:</p>
+<div class="targetlang"><pre>
+class SomeClass : AnInterface, AnotherInterface {
+ …
+}
+</pre></div>
+ <p>For this to work, <tt>AnInterface</tt> and <tt>AnotherInterface</tt> have to be in scope. If SWIG is not in split proxy mode, this is already the case, but it it is, they have to be added to the import list via the <tt>dimports</tt> typemap. Additionally, the import statement depends on the package SWIG is configured to emit the modules to.</p>
+ <p>The <tt>$importtype</tt> macro helps you to elegantly solve this problem:</p>
+<div class="code"><pre>
+%typemap(dimports) RemoteMpe %{
+$importtype(AnInterface)
+$importtype(AnotherInterface)
+%}
+</pre></div>
+ <p>If SWIG is in split proxy mode, it expands to an <tt>import</tt> statement for the specified type, to nothing if not.</p>
+ </dd>
+
+ <dt><tt>$module</tt></dt>
+ <dd><p>Expands to the name of the main proxy D module.</p></dd>
+
+ <dt><tt>$wrapdmodule</tt></dt>
+ <dd><p>Contains the fully qualified name of the wrap D module.</p></dd>
+</dl>
+
+
+<H2><a name="D_features"></a>20.4 <tt>%feature</tt>s</H2>
+
+
+<p>The D module defines a number of directives which modify the <a href="Customization.html#Customization_features">SWIG features</a> set globally or for a specific declaration:</p>
+
+
+<dl>
+ <dt><tt>%dnativeconst</tt> and <tt>%dconstvalue(value)</tt></dt>
+ <dd>
+ <p>Out of the box, SWIG generates accessor methods for C <tt>#defines</tt> and C++ constants. The <tt>%dnativeconst</tt> directive enables wrapping these constants as D manifest constants (<tt>const</tt> in D1, <tt>enum</tt> in D2).</p>
+ <p>For this to work, the C/C++ code for the constant value must directly compile as D code, though. If this is not the case, you can manually override the expression written to the D wrapper using the <tt>%dconstvalue</tt> directive, passing the new value as parameter.</p>
+ <p>For <tt>enum</tt>s, again <tt>%dconstvalue</tt> can be used to override the value of an enum item if the initializer should not compile in D.</p>
+ </dd>
+
+ <dt><tt>%dmethodmodifiers</tt></dt>
+ <dd>
+ <p>This directive can be used to override the modifiers for a proxy function. For instance, you could make a <tt>public</tt> C++ member function <tt>private</tt> in D like this:</p>
+<div class="code"><pre>
+%dmethodmodifiers A::foo "private";
+
+%inline %{
+struct A {
+ void foo();
+};
+%}
+</pre></div>
+ </dd>
+</dl>
+
+
+<H2><a name="D_pragmas"></a>20.5 Pragmas</H2>
+
+
+<p>There are a few SWIG pragmas specific to the D module, which you can use to influence the D code SWIG generates:</p>
+
+<dl>
+ <dt><tt>%pragma(d) wrapdmodulecode</tt></dt>
+ <dd><p>The passed text (D code) is copied verbatim to the wrap D module. For example, it can be (and is, internally) used to emit additional private helper code for the use by proxy typemaps.</p></dd>
+
+ <dt><tt>%pragma(d) wrapdmoduleimports</tt></dt>
+ <dd><p>Additional code to be emitted to the imports section of the wrap D module (the <a href="D.html#D_importtype">$importtype</a> macro can be used here). You probably want to use this in conjunction with the <tt>wrapdmodulecode</tt> pragma.</p></dd>
+
+ <dt><tt>%pragma(d) proxydmodulecode</tt></dt>
+ <dd><p>Just like <tt>proxydmodulecode</tt>, the argument is copied to the proxy D module (if SWIG is in <a href="D.html#D_splitproxy">split proxy mode</a>, it is emitted to the main proxy D module only).</p></dd>
+
+ <dt><tt>%pragma(d) globalproxyimports</tt></dt>
+ <dd>
+ <p>The D module currently does not support specifying dependencies on external modules (e.g. from the standard library) for the D typemaps. To add the import statements to the proxy modules (resp. to <em>all</em> proxy modules if in split proxy mode), you can use the <tt>globalproxyimports</tt> directive.</p>
+ <p>For example:</p>
+<div class="code"><pre>
+%typemap(din) char[] "($dinput ? tango.stdc.stringz.toStringz($dinput) : null)"
+%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
+</pre></div>
+ </dd>
+
+ <dt><tt>%pragma(d) wrapperloadercode</tt></dt>
+ <dd>
+ <p>The D code for loading the wrapper library (it is copied to the wrap D module). The <tt>$wrapperloaderbindcode</tt> variable is replaced by the list of commands for binding the functions from the wrapper library to the symbols in the wrap D module.</p>
+ <p>Each time this pragma is specified, the previous value is overwritten.</p>
+ </dd>
+
+ <dt><tt>%pragma(d) wrapperloaderbindcommand</tt></dt>
+ <dd>
+ <p>The D command to use for binding the wrapper functions from the C/C++ library to the symbols in the wrap D module. The <tt>$function</tt> variable contains the name of the D function in the wrap module, the <tt>$symbol</tt> variable is replaced by the name of the symbol in the library.</p>
+ <p>Each time this pragma is specified, the previous value is overwritten.</p>
+ </dd>
+</dl>
+
+
+<H2><a name="D_exceptions"></a>20.6 D Exceptions</H2>
+
+
+<p>Out of the box, C++ exceptions are fundamentally incompatible to their equivalent in the D world and cannot simply be propagated to a calling D method. There is, however, an easy way to solve this problem: Just catch the exception in the C/C++ wrapper layer, pass the contents to D, and make the wrapper code rethrow the exception in the D world.</p>
+
+<p>The implementation details of this are a bit crude, but the SWIG D module automatically takes care of this, as long as it is able to detect that an exception could potentially be thrown (e.g. because the C++ method has a <tt>throw(…)</tt> exception specification).</p>
+
+<p>As this feature is implemented in exactly the same way it is for C#, please see the <a href="CSharp.html#CSharp_exceptions">C# documentation</a> for a more detailed explanation.</p>
+
+
+<H2><a name="D_directors"></a>20.7 D Directors</H2>
+
+
+<p>When the directors feature is activated, SWIG generates extra code on both the C++ and the D side to enable cross-language polymorphism. Essentially, this means that if you subclass a proxy class in D, C++ code can access any overridden virtual methods just as if you created a derived class in C++.</p>
+
+<p>There is no D specific documentation yet, but the way the feature is implemented is very similar to how it is done in <a href="Java.html#Java_directors">Java</a> and <a href="CSharp.html#CSharp_directors">C#</a>.
+</p>
+
+
+<H2><a name="D_other_features"></a>20.8 Other features</H2>
+
+
+<p>The <a href="SWIGPlus.html#SWIGPlus_nspace"><tt>nspace</tt></a> feature of SWIG is not yet supported for D – all class modules are written to the same package, regardless of which C++ namespace they are in.</p>
+
+<p>Support of pointers to primitive types.</p>
+
+
+<H2><a name="D_typemap_examples"></a>20.9 D Typemap examples</H2>
+
+
+<p>There are no D-specific typemap examples yet. However, with the above <a href="D.html#D_typemap_name_comparison">name comparison table</a>, you should be able to get an idea what can be done by looking at the <a href="CSharp.html#CSharp_typemap_examples">corresponding C# section</a>.</p>
+
+
+
+<H2><a name="D_planned_features"></a>20.10 Work in progress and planned features</H2>
+
+
+<p>There are a couple of features which are not implemented yet, but would be very useful and might be added in the near future:</p>
+
+<ul>
+ <li><em>Static linking:</em> Currently, the C wrapper code is compiled into a dynamic library, out of which the symbol addresses are looked up at runtime by the D part. If statically linking the different languages into one binary was supported, a tool-chain capable of performing IPO at link time could inline the wrapping code, effectively reducing the overhead for simple calls to zero.</li>
+ <li><em>C array handling:</em> Many data structures in some C/C++ libraries contain array containing of a pointer to the first element and the element count. Currently, one must manually writing wrapper code to be able to access these from D. It should be possible to add a set of SWIG macros to semi-automatically generate conversion code.</li>
+ <li><em>Operator overloading:</em> Currently, operator overloading is supported only to a very limited extent – many C++ operators are just ignored with a warning. The problem here is that the way D handles operator overloading differs quite a lot from the way C++ does it, both syntactically and semantically, and even more so since the advent of template-based operator overloading in D2.</li>
+</ul>
+
+<p>Some generated code might also be a bit rough around the edges, particularly in the following areas:</p>
+
+<ul>
+ <li><em>Memory management:</em> Although the currently generated wrapper code works fine with regard to the GC for the test-suite, there might be issues coming up in real-world multi-threaded usage.</li>
+ <li><em>D2 support</em>: Originally, the module has been developed for the use with D1, D2/Phobos support has been added in later. The basic features should work equally well for both, but there <em>could</em> be issues concerning const-correctness etc.</li>
+</ul>
+
+
+</body>
+</html>
+
diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html
index 855244790..a44571992 100644
--- a/Doc/Manual/Sections.html
+++ b/Doc/Manual/Sections.html
@@ -52,6 +52,7 @@ Last update : SWIG-2.0.2 (in progress)
<li><a href="R.html#R">R support</a></li>
<li><a href="Ruby.html#Ruby">Ruby support</a></li>
<li><a href="Tcl.html#Tcl">Tcl support</a></li>
+<li><a href="D.html#D">D support</a></li>
</ul>
<H3>Developer Documentation</H3>
diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters
index e918e234a..924c8cfde 100644
--- a/Doc/Manual/chapters
+++ b/Doc/Manual/chapters
@@ -17,6 +17,7 @@ CCache.html
Allegrocl.html
CSharp.html
Chicken.html
+D.html
Go.html
Guile.html
Java.html
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index 582c75f29..5d5590311 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -69,7 +69,7 @@ IOBJS = $(IWRAP:.i=.@OBJEXT@)
CPP_DLLIBS = #-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
-# Solaris workshop 5.0
+# Solaris workshop 5.0
# CPP_DLLIBS = -L/opt/SUNWspro/lib -lCrun
# Symbols used for using shared libraries
@@ -159,7 +159,7 @@ tcl_cpp: $(SRCS)
# -----------------------------------------------------------------
tcl_clean:
- rm -f *_wrap* *~ .~* mytclsh@EXEEXT@
+ rm -f *_wrap* *~ .~* mytclsh@EXEEXT@
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
@@ -296,9 +296,9 @@ python_static_cpp: $(SRCS)
$(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \
$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)
-# -----------------------------------------------------------------
+# -----------------------------------------------------------------
# Running a Python example
-# -----------------------------------------------------------------
+# -----------------------------------------------------------------
ifeq (,$(PY3))
PYSCRIPT = runme.py
@@ -313,7 +313,7 @@ python_run: $(PYSCRIPT)
runme3.py: runme.py
cp $< $@
- $(PY2TO3) -w $@ >/dev/null 2>&1
+ $(PY2TO3) -w $@ >/dev/null 2>&1
# -----------------------------------------------------------------
# Cleaning the python examples
@@ -332,7 +332,7 @@ python_clean:
# Make sure these locate your Octave installation
OCTAVE_INCLUDE= $(DEFS) @OCTAVEEXT@
-OCTAVE_LIB =
+OCTAVE_LIB =
# Extra Octave specific dynamic linking options
OCTAVE_DLNK = @OCTAVEDYNAMICLINKING@
@@ -548,14 +548,14 @@ mzscheme: $(SRCS)
mzscheme_cpp: $(SRCS)
$(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACEPATH)
$(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS)
- $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS)
+ $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS)
# -----------------------------------------------------------------
# Cleaning the mzscheme examples
# -----------------------------------------------------------------
mzscheme_clean:
- rm -f *_wrap* *~ .~*
+ rm -f *_wrap* *~ .~*
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
@@ -643,7 +643,7 @@ ocaml_static_cpp: $(SRCS)
$(INTERFACE:%.i=%.cmo) \
$(PROGFILE:%.ml=%.cmo) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
- -cclib "$(LIBS)" -cc '$(CXX)'
+ -cclib "$(LIBS)" -cc '$(CXX)'
ocaml_static_cpp_toplevel: $(SRCS)
$(OCAMLCORE)
@@ -661,7 +661,7 @@ ocaml_static_cpp_toplevel: $(SRCS)
-g -ccopt -g -cclib -g -custom -o $(TARGET)_top \
$(INTERFACE:%.i=%.cmo) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
- -cclib "$(LIBS)" -cc '$(CXX)'
+ -cclib "$(LIBS)" -cc '$(CXX)'
ocaml_dynamic_cpp: $(SRCS)
$(OCAMLCORE)
@@ -844,7 +844,7 @@ pike_cpp_static: $(SRCS)
# -----------------------------------------------------------------
pike_clean:
- rm -f *_wrap* *~ .~* mypike@EXEEXT@
+ rm -f *_wrap* *~ .~* mypike@EXEEXT@
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
@@ -861,7 +861,7 @@ CHICKEN_CFLAGS = @CHICKENOPTS@
CHICKENOPTS = -quiet
CHICKEN_MAIN =
-# SWIG produces $(ISRCS) (the C wrapper file)
+# SWIG produces $(ISRCS) (the C wrapper file)
# and $(CHICKEN_GENERATED_SCHEME) (the Scheme wrapper file):
CHICKEN_GENERATED_SCHEME = $(INTERFACE:.i=.scm)
CHICKEN_COMPILED_SCHEME = $(INTERFACE:.i=_chicken.c)
@@ -1053,12 +1053,12 @@ lua_clean:
allegrocl: $(SRCS)
$(SWIG) -allegrocl -cwrap $(SWIGOPT) $(INTERFACEPATH)
- $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
+ $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
allegrocl_cpp: $(SRCS)
$(SWIG) -c++ -allegrocl $(SWIGOPT) $(INTERFACEPATH)
- $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
allegrocl_clean:
@@ -1087,12 +1087,12 @@ clisp_clean:
cffi: $(SRCS)
$(SWIG) -cffi $(SWIGOPT) $(INTERFACEPATH)
-# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
+# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
# $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
cffi_cpp: $(SRCS)
$(SWIG) -c++ -cffi $(SWIGOPT) $(INTERFACEPATH)
- $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
cffi_clean:
@@ -1106,12 +1106,12 @@ cffi_clean:
uffi: $(SRCS)
$(SWIG) -uffi $(SWIGOPT) $(INTERFACEPATH)
-# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
+# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
# $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
uffi_cpp: $(SRCS)
$(SWIG) -c++ -uffi $(SWIGOPT) $(INTERFACEPATH)
-# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
+# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
# $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
uffi_clean:
@@ -1212,3 +1212,56 @@ go_clean:
rm -f *_wrap* *_gc* .~* runme
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *.[568] *.a *@SO@
+
+##################################################################
+##### D ######
+##################################################################
+
+DLIBPREFIX = @DLIBPREFIX@
+
+ifeq (2,$(D_VERSION))
+ SWIGD = $(SWIG) -d -d2
+ DCOMPILER = @D2COMPILER@
+else
+ SWIGD = $(SWIG) -d
+ DCOMPILER = @D1COMPILER@
+endif
+
+ifeq (dmd,$(DCOMPILER))
+ # DMD is 32bit only by now
+ CFLAGS += -m32
+endif
+
+# ----------------------------------------------------------------
+# Build a dynamically loadable D wrapper for a C module
+# ----------------------------------------------------------------
+
+d: $(SRCS)
+ $(SWIGD) $(SWIGOPT) $(INTERFACEPATH)
+ $(CC) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES)
+ $(LDSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
+
+# ----------------------------------------------------------------
+# Build a dynamically loadable D wrapper for a C++ module
+# ----------------------------------------------------------------
+
+d_cpp: $(SRCS)
+ $(SWIGD) -c++ $(SWIGOPT) $(INTERFACEPATH)
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES)
+ $(CXXSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
+
+# ----------------------------------------------------------------
+# Compile D files
+# ----------------------------------------------------------------
+
+d_compile: $(SRCS)
+ $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS)
+
+# -----------------------------------------------------------------
+# Clean the D examples
+# -----------------------------------------------------------------
+
+d_clean:
+ rm -f *_wrap* *~ .~* runme runme.exe `find . -name \*.d | grep -v runme.d`
+ rm -f core @EXTRA_CLEAN@
+ rm -f *.@OBJEXT@ *@SO@
diff --git a/Examples/d/callback/Makefile b/Examples/d/callback/Makefile
new file mode 100644
index 000000000..bc16dd0fc
--- /dev/null
+++ b/Examples/d/callback/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/callback/d1/runme.d b/Examples/d/callback/d1/runme.d
new file mode 100644
index 000000000..e34e09603
--- /dev/null
+++ b/Examples/d/callback/d1/runme.d
@@ -0,0 +1,36 @@
+module runme;
+
+import tango.io.Stdout;
+import example;
+
+public class DCallback : Callback {
+ public override void run() {
+ Stdout( "DCallback.run()" ).newline;
+ }
+}
+
+void main() {
+ auto caller = new Caller();
+
+ Stdout( "Adding and calling a normal C++ callback" ).newline;
+ Stdout( "----------------------------------------" ).newline;
+ {
+ scope auto callback = new Callback();
+ caller.setCallback(callback);
+ caller.call();
+ caller.resetCallback();
+ }
+
+ Stdout.newline;
+ Stdout( "Adding and calling a D callback" ).newline;
+ Stdout( "-------------------------------" ).newline;
+ {
+ scope auto callback = new DCallback();
+ caller.setCallback(callback);
+ caller.call();
+ caller.resetCallback();
+ }
+
+ Stdout.newline;
+ Stdout( "D exit" ).newline;
+}
diff --git a/Examples/d/callback/d2/runme.d b/Examples/d/callback/d2/runme.d
new file mode 100644
index 000000000..88ffcdefd
--- /dev/null
+++ b/Examples/d/callback/d2/runme.d
@@ -0,0 +1,36 @@
+module runme;
+
+import std.stdio;
+import example;
+
+public class DCallback : Callback {
+ public override void run() {
+ writeln( "DCallback.run()" );
+ }
+}
+
+void main() {
+ auto caller = new Caller();
+
+ writeln( "Adding and calling a normal C++ callback" );
+ writeln( "----------------------------------------" );
+ {
+ scope auto callback = new Callback();
+ caller.setCallback(callback);
+ caller.call();
+ caller.resetCallback();
+ }
+
+ writeln();
+ writeln( "Adding and calling a D callback" );
+ writeln( "-------------------------------" );
+ {
+ scope auto callback = new DCallback();
+ caller.setCallback(callback);
+ caller.call();
+ caller.resetCallback();
+ }
+
+ writeln();
+ writeln( "D exit" );
+}
diff --git a/Examples/d/callback/example.cxx b/Examples/d/callback/example.cxx
new file mode 100644
index 000000000..450d75608
--- /dev/null
+++ b/Examples/d/callback/example.cxx
@@ -0,0 +1,4 @@
+/* File : example.cxx */
+
+#include "example.h"
+
diff --git a/Examples/d/callback/example.h b/Examples/d/callback/example.h
new file mode 100644
index 000000000..38d25a043
--- /dev/null
+++ b/Examples/d/callback/example.h
@@ -0,0 +1,24 @@
+/* File : example.h */
+
+#include <cstdio>
+#include <iostream>
+
+class Callback {
+public:
+ virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
+ virtual void run() { std::cout << "Callback::run()" << std::endl; }
+};
+
+
+class Caller {
+private:
+ Callback *_callback;
+public:
+ Caller(): _callback(0) {}
+ ~Caller() { delCallback(); }
+ void delCallback() { delete _callback; _callback = 0; }
+ void setCallback(Callback *cb) { delCallback(); _callback = cb; }
+ void resetCallback() { _callback = 0; }
+ void call() { if (_callback) _callback->run(); }
+};
+
diff --git a/Examples/d/callback/example.i b/Examples/d/callback/example.i
new file mode 100644
index 000000000..90beda01a
--- /dev/null
+++ b/Examples/d/callback/example.i
@@ -0,0 +1,13 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+%include "std_string.i"
+
+/* turn on director wrapping Callback */
+%feature("director") Callback;
+
+%include "example.h"
+
diff --git a/Examples/d/check.list b/Examples/d/check.list
new file mode 100644
index 000000000..010e7bbfc
--- /dev/null
+++ b/Examples/d/check.list
@@ -0,0 +1,9 @@
+# See top-level Makefile.in.
+callback
+class
+constants
+enum
+extend
+funcptr
+simple
+variables
diff --git a/Examples/d/class/Makefile b/Examples/d/class/Makefile
new file mode 100644
index 000000000..bc16dd0fc
--- /dev/null
+++ b/Examples/d/class/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/class/d1/runme.d b/Examples/d/class/d1/runme.d
new file mode 100644
index 000000000..b0c4263a2
--- /dev/null
+++ b/Examples/d/class/d1/runme.d
@@ -0,0 +1,58 @@
+// This example illustrates how C++ classes can be used from D using SWIG.
+// The D class gets mapped onto the C++ class and behaves as if it is a D class.
+module runme;
+
+import tango.io.Stdout;
+import example;
+
+void main() {
+ // ----- Object creation -----
+
+ Stdout( "Creating some objects:" ).newline;
+
+ {
+ scope Square s = new Square(10);
+ scope Circle c = new Circle(10);
+
+ // ----- Access a static member -----
+ Stdout.format( "{} shapes were created.", Shape.nshapes ).newline;
+
+ // ----- Member data access -----
+
+ // Notice how we can do this using functions specific to
+ // the 'Circle' class.
+ c.x = 20;
+ c.y = 30;
+
+ // Now use the same functions in the base class
+ Shape shape = s;
+ shape.x = -10;
+ shape.y = 5;
+
+ Stdout( "\nHere is their current position:" ).newline;
+ Stdout.format( " Circle = ( {}, {} )", c.x, c.y ).newline;
+ Stdout.format( " Square = ( {}, {} )", s.x, s.y ).newline;
+
+ // ----- Call some methods -----
+
+ Stdout( "\nHere are some properties of the shapes:" ).newline;
+ Shape[] shapes = [ cast(Shape) c, cast(Shape) s ];
+ foreach ( currentShape; shapes )
+ {
+ Stdout.format( " {}", currentShape.classinfo.name ).newline;
+ Stdout.format( " area = {}", currentShape.area() ).newline;
+ Stdout.format( " perimeter = {}", currentShape.perimeter() ).newline;
+ }
+
+ // Notice how the area() and perimeter() functions really
+ // invoke the appropriate virtual method on each object.
+
+ // ----- Delete everything -----
+ Stdout( "\nGuess I'll clean up now:" ).newline;
+ // Note: when this using scope is exited the D destructors are called which
+ // in turn call the C++ destructors.
+ }
+
+ Stdout.format( "{} shapes remain", Shape.nshapes ).newline;
+ Stdout( "\nGoodbye!" ).newline;
+}
diff --git a/Examples/d/class/d2/runme.d b/Examples/d/class/d2/runme.d
new file mode 100644
index 000000000..2e86c5fc7
--- /dev/null
+++ b/Examples/d/class/d2/runme.d
@@ -0,0 +1,58 @@
+// This example illustrates how C++ classes can be used from D using SWIG.
+// The D class gets mapped onto the C++ class and behaves as if it is a D class.
+module runme;
+
+import std.stdio;
+import example;
+
+void main() {
+ // ----- Object creation -----
+
+ writeln( "Creating some objects:" );
+
+ {
+ scope Square s = new Square(10);
+ scope Circle c = new Circle(10);
+
+ // ----- Access a static member -----
+ writefln( "%s shapes were created.", Shape.nshapes );
+
+ // ----- Member data access -----
+
+ // Notice how we can do this using functions specific to
+ // the 'Circle' class.
+ c.x = 20;
+ c.y = 30;
+
+ // Now use the same functions in the base class
+ Shape shape = s;
+ shape.x = -10;
+ shape.y = 5;
+
+ writeln( "\nHere is their current position:" );
+ writefln( " Circle = ( %s, %s )", c.x, c.y );
+ writefln( " Square = ( %s, %s )", s.x, s.y );
+
+ // ----- Call some methods -----
+
+ writeln( "\nHere are some properties of the shapes:" );
+ Shape[] shapes = [ cast(Shape) c, cast(Shape) s ];
+ foreach ( currentShape; shapes )
+ {
+ writefln( " %s", currentShape.classinfo.name );
+ writefln( " area = %s", currentShape.area() );
+ writefln( " perimeter = %s", currentShape.perimeter() );
+ }
+
+ // Notice how the area() and perimeter() functions really
+ // invoke the appropriate virtual method on each object.
+
+ // ----- Delete everything -----
+ writeln( "\nGuess I'll clean up now:" );
+ // Note: when this using scope is exited the D destructors are called which
+ // in turn call the C++ destructors.
+ }
+
+ writefln( "%s shapes remain", Shape.nshapes );
+ writeln( "\nGoodbye!" );
+}
diff --git a/Examples/d/class/example.cxx b/Examples/d/class/example.cxx
new file mode 100644
index 000000000..1e8e203dd
--- /dev/null
+++ b/Examples/d/class/example.cxx
@@ -0,0 +1,28 @@
+/* File : example.c */
+
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
diff --git a/Examples/d/class/example.h b/Examples/d/class/example.h
new file mode 100644
index 000000000..0d4527e92
--- /dev/null
+++ b/Examples/d/class/example.h
@@ -0,0 +1,34 @@
+/* File : example.h */
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ };
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
diff --git a/Examples/d/class/example.i b/Examples/d/class/example.i
new file mode 100644
index 000000000..75700b305
--- /dev/null
+++ b/Examples/d/class/example.i
@@ -0,0 +1,10 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/d/constants/Makefile b/Examples/d/constants/Makefile
new file mode 100644
index 000000000..ce17134ec
--- /dev/null
+++ b/Examples/d/constants/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ example_wrap.c
+EXTRA_LDFLAGS = example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/constants/d1/runme.d b/Examples/d/constants/d1/runme.d
new file mode 100644
index 000000000..47362cbf3
--- /dev/null
+++ b/Examples/d/constants/d1/runme.d
@@ -0,0 +1,28 @@
+module runme;
+
+import tango.io.Stdout;
+static import example;
+
+void main() {
+ Stdout.formatln("ICONST = {} (should be 42)", example.ICONST);
+ Stdout.formatln("FCONST = {} (should be 2.18)", example.FCONST);
+ Stdout.formatln("CCONST = {} (should be 'x')", example.CCONST);
+ Stdout.formatln("CCONST2 = {} (this should be on a new line)", example.CCONST2);
+ Stdout.formatln("SCONST = {} (should be 'Hello World')", example.SCONST);
+ Stdout.formatln("SCONST2 = {} (should be '\"Hello World\"')", example.SCONST2);
+ Stdout.formatln("EXPR = {} (should be 48.55)", example.EXPR);
+ Stdout.formatln("iconst = {} (should be 37)", example.iconst);
+ Stdout.formatln("fconst = {} (should be 3.14)", example.fconst);
+
+ static if (is(typeof(example.EXTERN))) {
+ Stdout.formatln("EXTERN should not be defined, but is: {}.", example.EXTERN );
+ } else {
+ Stdout.formatln("EXTERN isn't defined (good)");
+ }
+
+ static if (is(typeof(example.FOO))) {
+ Stdout.formatln("FOO should not be defined, but is: {}.", example.FOO);
+ } else {
+ Stdout.formatln("FOO isn't defined (good)");
+ }
+}
diff --git a/Examples/d/constants/d2/runme.d b/Examples/d/constants/d2/runme.d
new file mode 100644
index 000000000..4be510d16
--- /dev/null
+++ b/Examples/d/constants/d2/runme.d
@@ -0,0 +1,28 @@
+module runme;
+
+import std.stdio;
+static import example;
+
+void main() {
+ writefln("ICONST = %s (should be 42)", example.ICONST);
+ writefln("FCONST = %s (should be 2.1828)", example.FCONST);
+ writefln("CCONST = %s (should be 'x')", example.CCONST);
+ writefln("CCONST2 = %s (this should be on a new line)", example.CCONST2);
+ writefln("SCONST = %s (should be 'Hello World')", example.SCONST);
+ writefln("SCONST2 = %s (should be '\"Hello World\"')", example.SCONST2);
+ writefln("EXPR = %s (should be 48.5484)", example.EXPR);
+ writefln("iconst = %s (should be 37)", example.iconst);
+ writefln("fconst = %s (should be 3.14)", example.fconst);
+
+ static if (is(typeof(example.EXTERN))) {
+ writefln("EXTERN should not be defined, but is: %s.", example.EXTERN );
+ } else {
+ writeln("EXTERN isn't defined (good)");
+ }
+
+ static if (is(typeof(example.FOO))) {
+ writefln("FOO should not be defined, but is: %s.", example.FOO);
+ } else {
+ writeln("FOO isn't defined (good)");
+ }
+}
diff --git a/Examples/d/constants/example.d b/Examples/d/constants/example.d
new file mode 100644
index 000000000..7448d0ad9
--- /dev/null
+++ b/Examples/d/constants/example.d
@@ -0,0 +1,23 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.41
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+module example;
+
+static import example_wrap;
+
+static import tango.stdc.stringz;
+
+public const int ICONST = 42;
+public const double FCONST = 2.1828;
+public const char CCONST = 'x';
+public const char CCONST2 = '\n';
+public const char[] SCONST = "Hello World";
+public const char[] SCONST2 = "\"Hello World\"";
+public const double EXPR = 42+3*(2.1828);
+public const int iconst = 37;
+public const double fconst = 3.14;
diff --git a/Examples/d/constants/example.i b/Examples/d/constants/example.i
new file mode 100644
index 000000000..5eb541919
--- /dev/null
+++ b/Examples/d/constants/example.i
@@ -0,0 +1,32 @@
+/* File : example.i */
+%module example
+
+/* Force the generated D code to use the C constant values rather than
+ retrieving them at runtime. You can also try disabling the feature and
+ compare the generated code. */
+%dnativeconst;
+
+
+/* A few preprocessor macros */
+
+#define ICONST 42
+#define FCONST 2.1828
+#define CCONST 'x'
+#define CCONST2 '\n'
+#define SCONST "Hello World"
+#define SCONST2 "\"Hello World\""
+
+/* This should work just fine */
+#define EXPR ICONST + 3*(FCONST)
+
+/* This shouldn't do anything */
+#define EXTERN extern
+
+/* Neither should this (BAR isn't defined) */
+#define FOO (ICONST + BAR)
+
+
+/* The following directives also produce constants */
+
+%constant int iconst = 37;
+%constant double fconst = 3.14;
diff --git a/Examples/d/enum/Makefile b/Examples/d/enum/Makefile
new file mode 100644
index 000000000..bc16dd0fc
--- /dev/null
+++ b/Examples/d/enum/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/enum/d1/runme.d b/Examples/d/enum/d1/runme.d
new file mode 100644
index 000000000..d986986d1
--- /dev/null
+++ b/Examples/d/enum/d1/runme.d
@@ -0,0 +1,28 @@
+module runme;
+
+import tango.io.Stdout;
+import example;
+
+void main() {
+ Stdout( "Printing out some enum values:" ).newline;
+ Stdout(" color:").newline;
+ Stdout.formatln(" {} = {}", color.RED, cast(int)color.RED);
+ Stdout.formatln(" {} = {}", color.BLUE, cast(int)color.BLUE);
+ Stdout.formatln(" {} = {}", color.GREEN, cast(int)color.GREEN);
+
+ Stdout("\n Foo.speed:").newline;
+ Stdout.formatln(" Foo.{} = {}", Foo.speed.IMPULSE, cast(int)Foo.speed.IMPULSE);
+ Stdout.formatln(" Foo.{} = {}", Foo.speed.WARP, cast(int)Foo.speed.WARP);
+ Stdout.formatln(" Foo.{} = {}", Foo.speed.LUDICROUS , cast(int)Foo.speed.LUDICROUS);
+
+ Stdout("\nTesting use of enums with functions:").newline;
+ example.enum_test(color.RED, Foo.speed.IMPULSE);
+ example.enum_test(color.BLUE, Foo.speed.WARP);
+ example.enum_test(color.GREEN, Foo.speed.LUDICROUS);
+
+ Stdout( "\nTesting use of enum with class method:" ).newline;
+ scope f = new Foo();
+ f.enum_test(Foo.speed.IMPULSE);
+ f.enum_test(Foo.speed.WARP);
+ f.enum_test(Foo.speed.LUDICROUS);
+}
diff --git a/Examples/d/enum/d2/runme.d b/Examples/d/enum/d2/runme.d
new file mode 100644
index 000000000..acaec8ae8
--- /dev/null
+++ b/Examples/d/enum/d2/runme.d
@@ -0,0 +1,28 @@
+module runme;
+
+import std.stdio;
+import example;
+
+void main() {
+ writeln( "Printing out some enum values:" );
+ writeln(" color:");
+ writefln(" %s = %s", color.RED, cast(int)color.RED);
+ writefln(" %s = %s", color.BLUE, cast(int)color.BLUE);
+ writefln(" %s = %s", color.GREEN, cast(int)color.GREEN);
+
+ writeln("\n Foo.speed:");
+ writefln(" Foo.%s = %s", Foo.speed.IMPULSE, cast(int)Foo.speed.IMPULSE);
+ writefln(" Foo.%s = %s", Foo.speed.WARP, cast(int)Foo.speed.WARP);
+ writefln(" Foo.%s = %s", Foo.speed.LUDICROUS , cast(int)Foo.speed.LUDICROUS);
+
+ writeln("\nTesting use of enums with functions:");
+ example.enum_test(color.RED, Foo.speed.IMPULSE);
+ example.enum_test(color.BLUE, Foo.speed.WARP);
+ example.enum_test(color.GREEN, Foo.speed.LUDICROUS);
+
+ writeln( "\nTesting use of enum with class method:" );
+ scope f = new Foo();
+ f.enum_test(Foo.speed.IMPULSE);
+ f.enum_test(Foo.speed.WARP);
+ f.enum_test(Foo.speed.LUDICROUS);
+}
diff --git a/Examples/d/enum/example.cxx b/Examples/d/enum/example.cxx
new file mode 100644
index 000000000..df7bb6328
--- /dev/null
+++ b/Examples/d/enum/example.cxx
@@ -0,0 +1,37 @@
+/* File : example.cxx */
+
+#include "example.h"
+#include <stdio.h>
+
+void Foo::enum_test(speed s) {
+ if (s == IMPULSE) {
+ printf("IMPULSE speed\n");
+ } else if (s == WARP) {
+ printf("WARP speed\n");
+ } else if (s == LUDICROUS) {
+ printf("LUDICROUS speed\n");
+ } else {
+ printf("Unknown speed\n");
+ }
+}
+
+void enum_test(color c, Foo::speed s) {
+ if (c == RED) {
+ printf("color = RED, ");
+ } else if (c == BLUE) {
+ printf("color = BLUE, ");
+ } else if (c == GREEN) {
+ printf("color = GREEN, ");
+ } else {
+ printf("color = Unknown color!, ");
+ }
+ if (s == Foo::IMPULSE) {
+ printf("speed = IMPULSE speed\n");
+ } else if (s == Foo::WARP) {
+ printf("speed = WARP speed\n");
+ } else if (s == Foo::LUDICROUS) {
+ printf("speed = LUDICROUS speed\n");
+ } else {
+ printf("speed = Unknown speed!\n");
+ }
+}
diff --git a/Examples/d/enum/example.h b/Examples/d/enum/example.h
new file mode 100644
index 000000000..9119cd9fc
--- /dev/null
+++ b/Examples/d/enum/example.h
@@ -0,0 +1,13 @@
+/* File : example.h */
+
+enum color { RED, BLUE, GREEN };
+
+class Foo {
+ public:
+ Foo() { }
+ enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 };
+ void enum_test(speed s);
+};
+
+void enum_test(color c, Foo::speed s);
+
diff --git a/Examples/d/enum/example.i b/Examples/d/enum/example.i
new file mode 100644
index 000000000..23ee8a822
--- /dev/null
+++ b/Examples/d/enum/example.i
@@ -0,0 +1,11 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+
+%include "example.h"
+
diff --git a/Examples/d/extend/Makefile b/Examples/d/extend/Makefile
new file mode 100644
index 000000000..bc16dd0fc
--- /dev/null
+++ b/Examples/d/extend/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/extend/d1/runme.d b/Examples/d/extend/d1/runme.d
new file mode 100644
index 000000000..96501d1a4
--- /dev/null
+++ b/Examples/d/extend/d1/runme.d
@@ -0,0 +1,75 @@
+/// This file illustrates the cross language polymorphism using directors.
+module runme;
+
+import example;
+import tango.io.Stdout;
+
+// CEO class, which overrides Employee.getPosition().
+class CEO : Manager {
+public:
+ this( char[] name ) {
+ super( name );
+ }
+
+ override char[] getPosition() {
+ return "CEO";
+ }
+
+ // Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory.
+ void disownMemory() {
+ swigCMemOwn = false;
+ }
+}
+
+void main() {
+ // Create an instance of CEO, a class derived from the D proxy of the
+ // underlying C++ class. The calls to getName() and getPosition() are standard,
+ // the call to getTitle() uses the director wrappers to call CEO.getPosition().
+
+ auto e = new CEO( "Alice" );
+ Stdout.formatln( "{} is a {}.", e.getName(), e.getPosition() );
+ Stdout.formatln( "Just call her '{}'.", e.getTitle() );
+ Stdout( "----------------------" ).newline;
+
+ {
+ // Create a new EmployeeList instance. This class does not have a C++
+ // director wrapper, but can be used freely with other classes that do.
+ scope auto list = new EmployeeList();
+
+ // EmployeeList owns its items, so we must surrender ownership of objects we add.
+ e.disownMemory();
+ list.addEmployee(e);
+ Stdout( "----------------------" ).newline;
+
+ // Now we access the first four items in list (three are C++ objects that
+ // EmployeeList's constructor adds, the last is our CEO). The virtual
+ // methods of all these instances are treated the same. For items 0, 1, and
+ // 2, all methods resolve in C++. For item 3, our CEO, getTitle calls
+ // getPosition which resolves in D. The call to getPosition is
+ // slightly different, however, because of the overidden getPosition() call, since
+ // now the object reference has been "laundered" by passing through
+ // EmployeeList as an Employee*. Previously, D resolved the call
+ // immediately in CEO, but now D thinks the object is an instance of
+ // class Employee. So the call passes through the
+ // Employee proxy class and on to the C wrappers and C++ director,
+ // eventually ending up back at the D CEO implementation of getPosition().
+ // The call to getTitle() for item 3 runs the C++ Employee::getTitle()
+ // method, which in turn calls getPosition(). This virtual method call
+ // passes down through the C++ director class to the D implementation
+ // in CEO. All this routing takes place transparently.
+
+ Stdout( "(position, title) for items 0-3:" ).newline;
+ Stdout.formatln( " {}, '{}'", list.getItem(0).getPosition(), list.getItem(0).getTitle() );
+ Stdout.formatln( " {}, '{}'", list.getItem(1).getPosition(), list.getItem(1).getTitle() );
+ Stdout.formatln( " {}, '{}'", list.getItem(2).getPosition(), list.getItem(2).getTitle() );
+ Stdout.formatln( " {}, '{}'", list.getItem(3).getPosition(), list.getItem(3).getTitle() );
+ Stdout( "----------------------" ).newline;
+
+ // All Employees will be destroyed when the EmployeeList goes out of scope,
+ // including the CEO instance.
+ }
+ Stdout( "----------------------" ).newline;
+
+ // All done.
+ Stdout( "Exiting cleanly from D code." ).newline;
+}
diff --git a/Examples/d/extend/d2/runme.d b/Examples/d/extend/d2/runme.d
new file mode 100644
index 000000000..1ea6dfd21
--- /dev/null
+++ b/Examples/d/extend/d2/runme.d
@@ -0,0 +1,75 @@
+/// This file illustrates the cross language polymorphism using directors.
+module runme;
+
+import std.stdio;
+import example;
+
+// CEO class, which overrides Employee.getPosition().
+class CEO : Manager {
+public:
+ this( string name ) {
+ super( name );
+ }
+
+ override string getPosition() const {
+ return "CEO";
+ }
+
+ // Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory.
+ void disownMemory() {
+ swigCMemOwn = false;
+ }
+}
+
+void main() {
+ // Create an instance of CEO, a class derived from the D proxy of the
+ // underlying C++ class. The calls to getName() and getPosition() are standard,
+ // the call to getTitle() uses the director wrappers to call CEO.getPosition().
+
+ auto e = new CEO( "Alice" );
+ writefln( "%s is a %s.", e.getName(), e.getPosition() );
+ writefln( "Just call her '%s'.", e.getTitle() );
+ writeln( "----------------------" );
+
+ {
+ // Create a new EmployeeList instance. This class does not have a C++
+ // director wrapper, but can be used freely with other classes that do.
+ scope auto list = new EmployeeList();
+
+ // EmployeeList owns its items, so we must surrender ownership of objects we add.
+ e.disownMemory();
+ list.addEmployee(e);
+ writeln( "----------------------" );
+
+ // Now we access the first four items in list (three are C++ objects that
+ // EmployeeList's constructor adds, the last is our CEO). The virtual
+ // methods of all these instances are treated the same. For items 0, 1, and
+ // 2, all methods resolve in C++. For item 3, our CEO, getTitle calls
+ // getPosition which resolves in D. The call to getPosition is
+ // slightly different, however, because of the overidden getPosition() call, since
+ // now the object reference has been "laundered" by passing through
+ // EmployeeList as an Employee*. Previously, D resolved the call
+ // immediately in CEO, but now D thinks the object is an instance of
+ // class Employee. So the call passes through the
+ // Employee proxy class and on to the C wrappers and C++ director,
+ // eventually ending up back at the D CEO implementation of getPosition().
+ // The call to getTitle() for item 3 runs the C++ Employee::getTitle()
+ // method, which in turn calls getPosition(). This virtual method call
+ // passes down through the C++ director class to the D implementation
+ // in CEO. All this routing takes place transparently.
+
+ writeln( "(position, title) for items 0-3:" );
+ writefln( " %s, '%s'", list.getItem(0).getPosition(), list.getItem(0).getTitle() );
+ writefln( " %s, '%s'", list.getItem(1).getPosition(), list.getItem(1).getTitle() );
+ writefln( " %s, '%s'", list.getItem(2).getPosition(), list.getItem(2).getTitle() );
+ writefln( " %s, '%s'", list.getItem(3).getPosition(), list.getItem(3).getTitle() );
+ writeln( "----------------------" );
+
+ // All Employees will be destroyed when the EmployeeList goes out of scope,
+ // including the CEO instance.
+ }
+ writeln( "----------------------" );
+
+ // All done.
+ writeln( "Exiting cleanly from D code." );
+}
diff --git a/Examples/d/extend/example.cxx b/Examples/d/extend/example.cxx
new file mode 100644
index 000000000..450d75608
--- /dev/null
+++ b/Examples/d/extend/example.cxx
@@ -0,0 +1,4 @@
+/* File : example.cxx */
+
+#include "example.h"
+
diff --git a/Examples/d/extend/example.h b/Examples/d/extend/example.h
new file mode 100644
index 000000000..7ad93fbc1
--- /dev/null
+++ b/Examples/d/extend/example.h
@@ -0,0 +1,56 @@
+/* File : example.h */
+
+#include <cstdio>
+#include <iostream>
+#include <vector>
+#include <string>
+#include <cmath>
+
+class Employee {
+private:
+ std::string name;
+public:
+ Employee(const char* n): name(n) {}
+ virtual std::string getTitle() { return getPosition() + " " + getName(); }
+ virtual std::string getName() { return name; }
+ virtual std::string getPosition() const { return "Employee"; }
+ virtual ~Employee() { printf("~Employee() @ %p\n", this); }
+};
+
+
+class Manager: public Employee {
+public:
+ Manager(const char* n): Employee(n) {}
+ virtual std::string getPosition() const { return "Manager"; }
+};
+
+
+class EmployeeList {
+ std::vector<Employee*> list;
+public:
+ EmployeeList() {
+ list.push_back(new Employee("Bob"));
+ list.push_back(new Employee("Jane"));
+ list.push_back(new Manager("Ted"));
+ }
+ void addEmployee(Employee *p) {
+ list.push_back(p);
+ std::cout << "New employee added. Current employees are:" << std::endl;
+ std::vector<Employee*>::iterator i;
+ for (i=list.begin(); i!=list.end(); i++) {
+ std::cout << " " << (*i)->getTitle() << std::endl;
+ }
+ }
+ const Employee *getItem(int i) {
+ return list[i];
+ }
+ ~EmployeeList() {
+ std::vector<Employee*>::iterator i;
+ std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
+ for (i=list.begin(); i!=list.end(); i++) {
+ delete *i;
+ }
+ std::cout << "~EmployeeList empty." << std::endl;
+ }
+};
+
diff --git a/Examples/d/extend/example.i b/Examples/d/extend/example.i
new file mode 100644
index 000000000..0647e1319
--- /dev/null
+++ b/Examples/d/extend/example.i
@@ -0,0 +1,14 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+%include "std_string.i"
+
+/* turn on director wrapping for Manager */
+%feature("director") Employee;
+%feature("director") Manager;
+
+%include "example.h"
+
diff --git a/Examples/d/funcptr/Makefile b/Examples/d/funcptr/Makefile
new file mode 100644
index 000000000..616102926
--- /dev/null
+++ b/Examples/d/funcptr/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/funcptr/d1/runme.d b/Examples/d/funcptr/d1/runme.d
new file mode 100644
index 000000000..2947602a5
--- /dev/null
+++ b/Examples/d/funcptr/d1/runme.d
@@ -0,0 +1,34 @@
+module runme;
+
+import tango.io.Stdout;
+static import example;
+
+extern(C) int add(int a, int b) {
+ return a + b;
+}
+
+extern(C) int sub(int a, int b) {
+ return a - b;
+}
+
+extern(C) int mul(int a, int b) {
+ return a * b;
+}
+
+void main() {
+ int a = 37;
+ int b = 42;
+
+ Stdout( "a = " )( a ).newline;
+ Stdout( "b = " )( b ).newline;
+
+ Stdout( "Trying some C callback functions:" ).newline;
+ Stdout( " ADD(a,b) = " )( example.do_op( a, b, example.ADD ) ).newline;
+ Stdout( " SUB(a,b) = " )( example.do_op( a, b, example.SUB ) ).newline;
+ Stdout( " MUL(a,b) = " )( example.do_op( a, b, example.MUL ) ).newline;
+
+ Stdout( "Now the same with callback functions defined in D:" ).newline;
+ Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline;
+ Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline;
+ Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline;
+}
diff --git a/Examples/d/funcptr/d2/runme.d b/Examples/d/funcptr/d2/runme.d
new file mode 100644
index 000000000..929911d6c
--- /dev/null
+++ b/Examples/d/funcptr/d2/runme.d
@@ -0,0 +1,34 @@
+module runme;
+
+import std.stdio;
+static import example;
+
+extern(C) int add(int a, int b) {
+ return a + b;
+}
+
+extern(C) int sub(int a, int b) {
+ return a - b;
+}
+
+extern(C) int mul(int a, int b) {
+ return a * b;
+}
+
+void main() {
+ int a = 37;
+ int b = 42;
+
+ writefln( "a = %s", a );
+ writefln( "b = %s", b );
+
+ writeln( "Trying some C callback functions:" );
+ writefln( " ADD(a,b) = %s", example.do_op( a, b, example.ADD ) );
+ writefln( " SUB(a,b) = %s", example.do_op( a, b, example.SUB ) );
+ writefln( " MUL(a,b) = %s", example.do_op( a, b, example.MUL ) );
+
+ writeln( "Now the same with callback functions defined in D:" );
+ writefln( " add(a,b) = %s", example.do_op( a, b, &add ) );
+ writefln( " sub(a,b) = %s", example.do_op( a, b, &sub ) );
+ writefln( " mul(a,b) = %s", example.do_op( a, b, &mul ) );
+}
diff --git a/Examples/d/funcptr/example.c b/Examples/d/funcptr/example.c
new file mode 100644
index 000000000..5c4a3dabf
--- /dev/null
+++ b/Examples/d/funcptr/example.c
@@ -0,0 +1,19 @@
+/* File : example.c */
+
+int do_op(int a, int b, int (*op)(int,int)) {
+ return (*op)(a,b);
+}
+
+int add(int a, int b) {
+ return a+b;
+}
+
+int sub(int a, int b) {
+ return a-b;
+}
+
+int mul(int a, int b) {
+ return a*b;
+}
+
+int (*funcvar)(int,int) = add;
diff --git a/Examples/d/funcptr/example.h b/Examples/d/funcptr/example.h
new file mode 100644
index 000000000..9936e24fc
--- /dev/null
+++ b/Examples/d/funcptr/example.h
@@ -0,0 +1,9 @@
+/* file: example.h */
+
+extern int do_op(int,int, int (*op)(int,int));
+extern int add(int,int);
+extern int sub(int,int);
+extern int mul(int,int);
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/d/funcptr/example.i b/Examples/d/funcptr/example.i
new file mode 100644
index 000000000..8b3bef678
--- /dev/null
+++ b/Examples/d/funcptr/example.i
@@ -0,0 +1,16 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Wrap a function taking a pointer to a function */
+extern int do_op(int a, int b, int (*op)(int, int));
+
+/* Now install a bunch of "ops" as constants */
+%constant int (*ADD)(int,int) = add;
+%constant int (*SUB)(int,int) = sub;
+%constant int (*MUL)(int,int) = mul;
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/d/simple/Makefile b/Examples/d/simple/Makefile
new file mode 100644
index 000000000..312e6a9e9
--- /dev/null
+++ b/Examples/d/simple/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/simple/d1/runme.d b/Examples/d/simple/d1/runme.d
new file mode 100644
index 000000000..1293f1839
--- /dev/null
+++ b/Examples/d/simple/d1/runme.d
@@ -0,0 +1,27 @@
+module runme;
+
+import tango.io.Stdout;
+static import example;
+
+void main() {
+ /*
+ * Call our gcd() function.
+ */
+ int x = 42;
+ int y = 105;
+ int g = example.gcd( x, y );
+ Stdout.format( "The gcd of {} and {} is {}.", x, y, g ).newline;
+
+ /*
+ * Manipulate the Foo global variable.
+ */
+
+ // Output its current value
+ Stdout.format( "Foo = {}", example.Foo ).newline;
+
+ // Change its value
+ example.Foo = 3.1415926;
+
+ // See if the change took effect
+ Stdout.format( "Foo = {}", example.Foo ).newline;
+}
diff --git a/Examples/d/simple/d2/runme.d b/Examples/d/simple/d2/runme.d
new file mode 100644
index 000000000..7f278923b
--- /dev/null
+++ b/Examples/d/simple/d2/runme.d
@@ -0,0 +1,27 @@
+module runme;
+
+import std.stdio;
+static import example;
+
+void main() {
+ /*
+ * Call our gcd() function.
+ */
+ int x = 42;
+ int y = 105;
+ int g = example.gcd(x, y);
+ writefln("The gcd of %s and %s is %s.", x, y, g);
+
+ /*
+ * Manipulate the Foo global variable.
+ */
+
+ // Output its current value
+ writefln("Foo = %s", example.Foo);
+
+ // Change its value
+ example.Foo = 3.1415926;
+
+ // See if the change took effect
+ writefln("Foo = %s", example.Foo);
+}
diff --git a/Examples/d/simple/example.c b/Examples/d/simple/example.c
new file mode 100644
index 000000000..1c2af789c
--- /dev/null
+++ b/Examples/d/simple/example.c
@@ -0,0 +1,18 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/d/simple/example.i b/Examples/d/simple/example.i
new file mode 100644
index 000000000..24093b9bf
--- /dev/null
+++ b/Examples/d/simple/example.i
@@ -0,0 +1,7 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}
diff --git a/Examples/d/variables/Makefile b/Examples/d/variables/Makefile
new file mode 100644
index 000000000..312e6a9e9
--- /dev/null
+++ b/Examples/d/variables/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/variables/d1/runme.d b/Examples/d/variables/d1/runme.d
new file mode 100644
index 000000000..35c896bdc
--- /dev/null
+++ b/Examples/d/variables/d1/runme.d
@@ -0,0 +1,71 @@
+// This example illustrates global variable access from C#.
+module runme;
+
+import tango.io.Stdout;
+static import example;
+
+void main() {
+ // Try to set the values of some global variables
+ example.ivar = 42;
+ example.svar = -31000;
+ example.lvar = 65537;
+ example.uivar = 123456;
+ example.usvar = 61000;
+ example.ulvar = 654321;
+ example.scvar = -13;
+ example.ucvar = 251;
+ example.cvar = 'S';
+ example.fvar = 3.14159f;
+ example.dvar = 2.1828;
+ example.strvar = "Hello World";
+ example.iptrvar = example.new_int(37);
+ example.ptptr = example.new_Point(37,42);
+ example.name = "Bill";
+
+ // Now print out the values of the variables
+ Stdout.formatln( "Variables (printed from D):" );
+ Stdout.formatln( "ivar = {}", example.ivar );
+ Stdout.formatln( "svar = {}", example.svar );
+ Stdout.formatln( "lvar = {}", example.lvar );
+ Stdout.formatln( "uivar = {}", example.uivar );
+ Stdout.formatln( "usvar = {}", example.usvar );
+ Stdout.formatln( "ulvar = {}", example.ulvar );
+ Stdout.formatln( "scvar = {}", example.scvar );
+ Stdout.formatln( "ucvar = {}", example.ucvar );
+ Stdout.formatln( "fvar = {}", example.fvar );
+ Stdout.formatln( "dvar = {}", example.dvar );
+ Stdout.formatln( "cvar = {}", example.cvar );
+ Stdout.formatln( "strvar = {}", example.strvar );
+ Stdout.formatln( "cstrvar = {}", example.cstrvar );
+ Stdout.formatln( "iptrvar = {}", example.iptrvar );
+ Stdout.formatln( "name = {}", example.name );
+ Stdout.formatln( "ptptr = {} {}", example.ptptr, example.Point_print(example.ptptr) );
+ Stdout.formatln( "pt = {} {}", example.pt, example.Point_print(example.pt) );
+ Stdout.formatln( "status = {}", example.status );
+
+ Stdout.formatln( "\nVariables (printed from the C library):" );
+ example.print_vars();
+
+ Stdout.formatln( "\nNow I'm going to try and modify some read only variables:" );
+ Stdout.formatln( "Checking that the read only variables are readonly..." );
+
+ Stdout( " 'path'..." );
+ static if ( is( typeof( example.path = "a" ) ) )
+ Stdout.formatln("Oh dear, this variable is not read only!");
+ else
+ Stdout.formatln("Good.");
+
+ Stdout( " 'status'..." );
+ static if ( is( typeof( example.status = 2 ) ) )
+ Stdout.formatln("Oh dear, this variable is not read only!");
+ else
+ Stdout.formatln("Good.");
+
+ Stdout.formatln( "\nI'm going to try and update a structure variable:" );
+
+ example.pt = example.ptptr;
+
+ Stdout( "The new value is " ).flush;
+ example.pt_print();
+ Stdout.formatln( "You should see the value {}", example.Point_print(example.ptptr) );
+}
diff --git a/Examples/d/variables/d2/runme.d b/Examples/d/variables/d2/runme.d
new file mode 100644
index 000000000..f80b81819
--- /dev/null
+++ b/Examples/d/variables/d2/runme.d
@@ -0,0 +1,71 @@
+// This example illustrates global variable access from C#.
+module runme;
+
+import std.stdio;
+static import example;
+
+void main() {
+ // Try to set the values of some global variables
+ example.ivar = 42;
+ example.svar = -31000;
+ example.lvar = 65537;
+ example.uivar = 123456;
+ example.usvar = 61000;
+ example.ulvar = 654321;
+ example.scvar = -13;
+ example.ucvar = 251;
+ example.cvar = 'S';
+ example.fvar = 3.14159f;
+ example.dvar = 2.1828;
+ example.strvar = "Hello World";
+ example.iptrvar = example.new_int(37);
+ example.ptptr = example.new_Point(37,42);
+ example.name = "Bill";
+
+ // Now print out the values of the variables
+ writefln( "Variables (printed from D):" );
+ writefln( "ivar = %s", example.ivar );
+ writefln( "svar = %s", example.svar );
+ writefln( "lvar = %s", example.lvar );
+ writefln( "uivar = %s", example.uivar );
+ writefln( "usvar = %s", example.usvar );
+ writefln( "ulvar = %s", example.ulvar );
+ writefln( "scvar = %s", example.scvar );
+ writefln( "ucvar = %s", example.ucvar );
+ writefln( "fvar = %s", example.fvar );
+ writefln( "dvar = %s", example.dvar );
+ writefln( "cvar = %s", example.cvar );
+ writefln( "strvar = %s", example.strvar );
+ writefln( "cstrvar = %s", example.cstrvar );
+ writefln( "iptrvar = %s", example.iptrvar );
+ writefln( "name = %s", example.name );
+ writefln( "ptptr = %s %s", example.ptptr, example.Point_print(example.ptptr) );
+ writefln( "pt = %s %s", example.pt, example.Point_print(example.pt) );
+ writefln( "status = %s", example.status );
+
+ writefln( "\nVariables (printed from the C library):" );
+ example.print_vars();
+
+ writefln( "\nNow I'm going to try and modify some read only variables:" );
+ writefln( "Checking that the read only variables are readonly..." );
+
+ writeln( " 'path'..." );
+ static if ( is( typeof( example.path = "a" ) ) )
+ writefln("Oh dear, this variable is not read only!");
+ else
+ writefln("Good.");
+
+ writeln( " 'status'..." );
+ static if ( is( typeof( example.status = 2 ) ) )
+ writefln("Oh dear, this variable is not read only!");
+ else
+ writefln("Good.");
+
+ writefln( "\nI'm going to try and update a structure variable:" );
+
+ example.pt = example.ptptr;
+
+ write( "The new value is " );
+ example.pt_print();
+ writefln( "You should see the value %s", example.Point_print(example.ptptr) );
+}
diff --git a/Examples/d/variables/example.c b/Examples/d/variables/example.c
new file mode 100644
index 000000000..1bf9c120f
--- /dev/null
+++ b/Examples/d/variables/example.c
@@ -0,0 +1,91 @@
+/* File : example.c */
+
+/* I'm a file containing some C global variables */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "example.h"
+
+int ivar = 0;
+short svar = 0;
+long lvar = 0;
+unsigned int uivar = 0;
+unsigned short usvar = 0;
+unsigned long ulvar = 0;
+signed char scvar = 0;
+unsigned char ucvar = 0;
+char cvar = 0;
+float fvar = 0;
+double dvar = 0;
+char *strvar = 0;
+const char cstrvar[] = "Goodbye";
+int *iptrvar = 0;
+char name[256] = "Dave";
+char path[256] = "/home/beazley";
+
+
+/* Global variables involving a structure */
+Point *ptptr = 0;
+Point pt = { 10, 20 };
+
+/* A variable that we will make read-only in the interface */
+int status = 1;
+
+/* A debugging function to print out their values */
+
+void print_vars() {
+ printf("ivar = %d\n", ivar);
+ printf("svar = %d\n", svar);
+ printf("lvar = %ld\n", lvar);
+ printf("uivar = %u\n", uivar);
+ printf("usvar = %u\n", usvar);
+ printf("ulvar = %lu\n", ulvar);
+ printf("scvar = %d\n", scvar);
+ printf("ucvar = %u\n", ucvar);
+ printf("fvar = %g\n", fvar);
+ printf("dvar = %g\n", dvar);
+ printf("cvar = %c\n", cvar);
+ printf("strvar = %s\n", strvar ? strvar : "(null)");
+ printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
+ printf("iptrvar = %p\n", iptrvar);
+ printf("name = %s\n", name);
+ printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
+ printf("pt = (%d, %d)\n", pt.x, pt.y);
+ printf("status = %d\n", status);
+}
+
+/* A function to create an integer (to test iptrvar) */
+
+int *new_int(int value) {
+ int *ip = (int *) malloc(sizeof(int));
+ *ip = value;
+ return ip;
+}
+
+/* A function to create a point */
+
+Point *new_Point(int x, int y) {
+ Point *p = (Point *) malloc(sizeof(Point));
+ p->x = x;
+ p->y = y;
+ return p;
+}
+
+char * Point_print(Point *p) {
+ static char buffer[256];
+ if (p) {
+ sprintf(buffer,"(%d, %d)", p->x,p->y);
+ } else {
+ sprintf(buffer,"null");
+ }
+ return buffer;
+}
+
+void pt_print() {
+ printf("(%d, %d)\n", pt.x, pt.y);
+}
diff --git a/Examples/d/variables/example.h b/Examples/d/variables/example.h
new file mode 100644
index 000000000..0f7e89594
--- /dev/null
+++ b/Examples/d/variables/example.h
@@ -0,0 +1,6 @@
+/* File: example.h */
+
+typedef struct {
+ int x,y;
+} Point;
+
diff --git a/Examples/d/variables/example.i b/Examples/d/variables/example.i
new file mode 100644
index 000000000..591b871ed
--- /dev/null
+++ b/Examples/d/variables/example.i
@@ -0,0 +1,49 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Some global variable declarations */
+%inline %{
+extern int ivar;
+extern short svar;
+extern long lvar;
+extern unsigned int uivar;
+extern unsigned short usvar;
+extern unsigned long ulvar;
+extern signed char scvar;
+extern unsigned char ucvar;
+extern char cvar;
+extern float fvar;
+extern double dvar;
+extern char *strvar;
+extern const char cstrvar[];
+extern int *iptrvar;
+extern char name[256];
+
+extern Point *ptptr;
+extern Point pt;
+%}
+
+
+/* Some read-only variables */
+
+%immutable;
+
+%inline %{
+extern int status;
+extern char path[256];
+%}
+
+%mutable;
+
+/* Some helper functions to make it easier to test */
+%inline %{
+extern void print_vars();
+extern int *new_int(int value);
+extern Point *new_Point(int x, int y);
+extern char *Point_print(Point *p);
+extern void pt_print();
+%}
+
diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in
new file mode 100644
index 000000000..2e9eb827f
--- /dev/null
+++ b/Examples/test-suite/d/Makefile.in
@@ -0,0 +1,80 @@
+#######################################################################
+# Makefile for D test-suite
+#######################################################################
+
+LANGUAGE = d
+srcdir = @srcdir@
+top_srcdir = ../@top_srcdir@
+top_builddir = ../@top_builddir@
+
+ifeq (2,$(D_VERSION))
+ VERSIONSUFFIX = .2
+else
+ VERSIONSUFFIX = .1
+endif
+
+TESTSUFFIX = _runme$(VERSIONSUFFIX).d
+
+CPP_TEST_CASES = \
+ d_nativepointers \
+ exception_partial_info
+
+include $(srcdir)/../common.mk
+
+# Override some variables from common.mk:
+
+TARGETSUFFIX = _wrap
+
+SWIGOPT+=-splitproxy -package $*
+
+# Rules for the different types of tests
+%.cpptest:
+ $(setup)
+ +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_cpp))
+ +$(run_testcase)
+
+%.ctest:
+ $(setup)
+ +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_c))
+ +$(run_testcase)
+
+%.multicpptest:
+ $(setup)
+ +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_multi_cpp))
+ +$(run_testcase)
+
+# Makes a directory for the testcase if it does not exist
+setup = \
+ if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \
+ echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \
+ else \
+ echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
+ fi; \
+ if [ ! -d $*$(VERSIONSUFFIX) ]; then \
+ mkdir $*$(VERSIONSUFFIX); \
+ fi; \
+ if [ ! -d $*$(VERSIONSUFFIX)/$* ]; then \
+ mkdir $*$(VERSIONSUFFIX)/$*; \
+ fi
+
+# Compiles D files then runs the testcase. A testcase is only run if
+# a file is found which has _runme.d appended after the testcase name.
+run_testcase = \
+ if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \
+ cd $*$(VERSIONSUFFIX) && \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
+ DFLAGS='-of$*_runme' \
+ DSRCS='../$(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) $*/*.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 .. ; \
+ fi
+
+# Clean: remove testcase directories
+%.clean:
+ @if [ -d $* ]; then \
+ rm -rf $*; \
+ fi
diff --git a/Examples/test-suite/d/README b/Examples/test-suite/d/README
new file mode 100644
index 000000000..bb5372882
--- /dev/null
+++ b/Examples/test-suite/d/README
@@ -0,0 +1,7 @@
+D language module testsuite
+---------------------------
+
+Please see ../README for the common readme file.
+
+By default the D1 version is built, set D_VERSION=2 (in the environment or at
+the make command line) to run it for D2 instead.
diff --git a/Examples/test-suite/d/aggregate_runme.1.d b/Examples/test-suite/d/aggregate_runme.1.d
new file mode 100644
index 000000000..a00d34c25
--- /dev/null
+++ b/Examples/test-suite/d/aggregate_runme.1.d
@@ -0,0 +1,25 @@
+module aggregate_runme;
+
+import aggregate.aggregate;
+
+void main() {
+ // Confirm that move() returns correct results under normal use.
+ int result = move(UP);
+ if (result != UP) throw new Exception("UP failed");
+
+ result = move(DOWN);
+ if (result != DOWN) throw new Exception("DOWN failed");
+
+ result = move(LEFT);
+ if (result != LEFT) throw new Exception("LEFT failed");
+
+ result = move(RIGHT);
+ if (result != RIGHT) throw new Exception("RIGHT failed");
+
+ // Confirm that move() raises an exception when the contract is violated.
+ try {
+ move(0);
+ throw new Exception("0 test failed");
+ }
+ catch (Exception e) {}
+}
diff --git a/Examples/test-suite/d/aggregate_runme.2.d b/Examples/test-suite/d/aggregate_runme.2.d
new file mode 100644
index 000000000..a00d34c25
--- /dev/null
+++ b/Examples/test-suite/d/aggregate_runme.2.d
@@ -0,0 +1,25 @@
+module aggregate_runme;
+
+import aggregate.aggregate;
+
+void main() {
+ // Confirm that move() returns correct results under normal use.
+ int result = move(UP);
+ if (result != UP) throw new Exception("UP failed");
+
+ result = move(DOWN);
+ if (result != DOWN) throw new Exception("DOWN failed");
+
+ result = move(LEFT);
+ if (result != LEFT) throw new Exception("LEFT failed");
+
+ result = move(RIGHT);
+ if (result != RIGHT) throw new Exception("RIGHT failed");
+
+ // Confirm that move() raises an exception when the contract is violated.
+ try {
+ move(0);
+ throw new Exception("0 test failed");
+ }
+ catch (Exception e) {}
+}
diff --git a/Examples/test-suite/d/allprotected_runme.1.d b/Examples/test-suite/d/allprotected_runme.1.d
new file mode 100644
index 000000000..82a180e66
--- /dev/null
+++ b/Examples/test-suite/d/allprotected_runme.1.d
@@ -0,0 +1,65 @@
+module allprotected_runme;
+
+import allprotected.Klass;
+import allprotected.ProtectedBase;
+
+void main() {
+ auto mpb = new MyProtectedBase("MyProtectedBase");
+ mpb.accessProtected();
+}
+
+class MyProtectedBase : ProtectedBase {
+public:
+ this(char[] name) {
+ super(name);
+ }
+
+ void accessProtected() {
+ char[] s = virtualMethod();
+ if (s != "ProtectedBase")
+ throw new Exception("Failed");
+
+ Klass k = instanceMethod(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = instanceOverloaded(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = instanceOverloaded(new Klass("xyz"), "abc");
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ k = staticMethod(new Klass("abc"));
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ k = staticOverloaded(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = staticOverloaded(new Klass("xyz"), "abc");
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ instanceMemberVariable = 30;
+ int i = instanceMemberVariable;
+ if (i != 30)
+ throw new Exception("Failed");
+
+ staticMemberVariable = 40;
+ i = staticMemberVariable;
+ if (i != 40)
+ throw new Exception("Failed");
+
+ i = staticConstMemberVariable;
+ if (i != 20)
+ throw new Exception("Failed");
+
+ anEnum = ProtectedBase.AnEnum.EnumVal1;
+ ProtectedBase.AnEnum ae = anEnum;
+ if (ae != ProtectedBase.AnEnum.EnumVal1)
+ throw new Exception("Failed");
+ }
+}
diff --git a/Examples/test-suite/d/allprotected_runme.2.d b/Examples/test-suite/d/allprotected_runme.2.d
new file mode 100644
index 000000000..799230291
--- /dev/null
+++ b/Examples/test-suite/d/allprotected_runme.2.d
@@ -0,0 +1,65 @@
+module allprotected_runme;
+
+import allprotected.Klass;
+import allprotected.ProtectedBase;
+
+void main() {
+ auto mpb = new MyProtectedBase("MyProtectedBase");
+ mpb.accessProtected();
+}
+
+class MyProtectedBase : ProtectedBase {
+public:
+ this(string name) {
+ super(name);
+ }
+
+ void accessProtected() {
+ string s = virtualMethod();
+ if (s != "ProtectedBase")
+ throw new Exception("Failed");
+
+ Klass k = instanceMethod(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = instanceOverloaded(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = instanceOverloaded(new Klass("xyz"), "abc");
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ k = staticMethod(new Klass("abc"));
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ k = staticOverloaded(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = staticOverloaded(new Klass("xyz"), "abc");
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ instanceMemberVariable = 30;
+ int i = instanceMemberVariable;
+ if (i != 30)
+ throw new Exception("Failed");
+
+ staticMemberVariable = 40;
+ i = staticMemberVariable;
+ if (i != 40)
+ throw new Exception("Failed");
+
+ i = staticConstMemberVariable;
+ if (i != 20)
+ throw new Exception("Failed");
+
+ anEnum = ProtectedBase.AnEnum.EnumVal1;
+ ProtectedBase.AnEnum ae = anEnum;
+ if (ae != ProtectedBase.AnEnum.EnumVal1)
+ throw new Exception("Failed");
+ }
+}
diff --git a/Examples/test-suite/d/apply_strings_runme.1.d b/Examples/test-suite/d/apply_strings_runme.1.d
new file mode 100644
index 000000000..960caa4ca
--- /dev/null
+++ b/Examples/test-suite/d/apply_strings_runme.1.d
@@ -0,0 +1,12 @@
+module apply_strings_runme;
+
+import apply_strings.apply_strings;
+
+const char[] TEST_MESSAGE = "A message from target language to the C++ world and back again.";
+
+void main() {
+ if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed");
+ if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed");
+ auto pChar = CharFunction(null);
+ if (pChar !is null) throw new Exception("CharFunction failed");
+}
diff --git a/Examples/test-suite/d/apply_strings_runme.2.d b/Examples/test-suite/d/apply_strings_runme.2.d
new file mode 100644
index 000000000..86183f8a3
--- /dev/null
+++ b/Examples/test-suite/d/apply_strings_runme.2.d
@@ -0,0 +1,12 @@
+module apply_strings_runme;
+
+import apply_strings.apply_strings;
+
+enum string TEST_MESSAGE = "A message from target language to the C++ world and back again.";
+
+void main() {
+ if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed");
+ if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed");
+ auto pChar = CharFunction(null);
+ if (pChar !is null) throw new Exception("CharFunction failed");
+}
diff --git a/Examples/test-suite/d/bools_runme.1.d b/Examples/test-suite/d/bools_runme.1.d
new file mode 100644
index 000000000..f501b0762
--- /dev/null
+++ b/Examples/test-suite/d/bools_runme.1.d
@@ -0,0 +1,20 @@
+/// This is the bool runtime testcase. It checks that the C++ bool type works.
+module bools_runme;
+
+import bools.bools;
+
+void main() {
+ bool t = true;
+ bool f = false;
+
+ check_bo(f);
+ check_bo(t);
+}
+
+void check_bo(bool input) {
+ for (int i = 0; i < 1000; ++i) {
+ if (bo(input) != input) {
+ throw new Exception("Runtime test check_bo failed.");
+ }
+ }
+}
diff --git a/Examples/test-suite/d/bools_runme.2.d b/Examples/test-suite/d/bools_runme.2.d
new file mode 100644
index 000000000..f501b0762
--- /dev/null
+++ b/Examples/test-suite/d/bools_runme.2.d
@@ -0,0 +1,20 @@
+/// This is the bool runtime testcase. It checks that the C++ bool type works.
+module bools_runme;
+
+import bools.bools;
+
+void main() {
+ bool t = true;
+ bool f = false;
+
+ check_bo(f);
+ check_bo(t);
+}
+
+void check_bo(bool input) {
+ for (int i = 0; i < 1000; ++i) {
+ if (bo(input) != input) {
+ throw new Exception("Runtime test check_bo failed.");
+ }
+ }
+}
diff --git a/Examples/test-suite/d/catches_runme.1.d b/Examples/test-suite/d/catches_runme.1.d
new file mode 100644
index 000000000..55b18132d
--- /dev/null
+++ b/Examples/test-suite/d/catches_runme.1.d
@@ -0,0 +1,33 @@
+module catches_runme;
+
+import catches.catches;
+
+void main() {
+ test({ test_catches(1); }, "C++ int exception thrown, value: 1");
+ test({ test_catches(2); }, "two");
+ test({ test_catches(3); }, "C++ ThreeException const & exception thrown");
+
+ test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1");
+ test({ test_exception_specification(2); }, "unknown exception");
+ test({ test_exception_specification(3); }, "unknown exception");
+
+ test({ test_catches_all(1); }, "unknown exception");
+}
+
+void test(void delegate() command, char[] expectedMessage) {
+ bool didntThrow;
+ try {
+ command();
+ didntThrow = true;
+ } catch (Exception e) {
+ if (e.msg != expectedMessage) {
+ throw new Exception("Failed to propagate C++ exception. Expected '" ~
+ expectedMessage ~ "', but received '" ~ e.msg ~ "'.");
+ }
+ }
+
+ if (didntThrow) {
+ throw new Exception("Failed to propagate C++ exception. Expected '" ~
+ expectedMessage ~ "', but no exception was thrown.");
+ }
+}
diff --git a/Examples/test-suite/d/catches_runme.2.d b/Examples/test-suite/d/catches_runme.2.d
new file mode 100644
index 000000000..508558485
--- /dev/null
+++ b/Examples/test-suite/d/catches_runme.2.d
@@ -0,0 +1,33 @@
+module catches_runme;
+
+import catches.catches;
+
+void main() {
+ test({ test_catches(1); }, "C++ int exception thrown, value: 1");
+ test({ test_catches(2); }, "two");
+ test({ test_catches(3); }, "C++ ThreeException const & exception thrown");
+
+ test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1");
+ test({ test_exception_specification(2); }, "unknown exception");
+ test({ test_exception_specification(3); }, "unknown exception");
+
+ test({ test_catches_all(1); }, "unknown exception");
+}
+
+void test(void delegate() command, string expectedMessage) {
+ bool didntThrow;
+ try {
+ command();
+ didntThrow = true;
+ } catch (Exception e) {
+ if (e.msg != expectedMessage) {
+ throw new Exception("Failed to propagate C++ exception. Expected '" ~
+ expectedMessage ~ "', but received '" ~ e.msg ~ "'.");
+ }
+ }
+
+ if (didntThrow) {
+ throw new Exception("Failed to propagate C++ exception. Expected '" ~
+ expectedMessage ~ "', but no exception was thrown.");
+ }
+}
diff --git a/Examples/test-suite/d/char_strings_runme.1.d b/Examples/test-suite/d/char_strings_runme.1.d
new file mode 100644
index 000000000..cde6fe0f7
--- /dev/null
+++ b/Examples/test-suite/d/char_strings_runme.1.d
@@ -0,0 +1,151 @@
+module char_strings_runme;
+
+import tango.text.convert.Integer;
+import char_strings.char_strings;
+
+const char[] CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
+const char[] OTHERLAND_MSG = "Little message from the safe world.";
+
+void main() {
+ const uint count = 10000;
+ uint i = 0;
+
+ // get functions
+ for (i=0; i<count; i++) {
+ char[] str = GetCharHeapString();
+ if (str != CPLUSPLUS_MSG)
+ throw new Exception("Test char get 1 failed, iteration " ~ toString(i));
+ DeleteCharHeapString();
+ }
+
+ for (i=0; i<count; i++) {
+ char[] str = GetConstCharProgramCodeString();
+ if (str != CPLUSPLUS_MSG)
+ throw new Exception("Test char get 2 failed, iteration " ~ toString(i));
+ DeleteCharHeapString();
+ }
+
+ for (i=0; i<count; i++) {
+ char[] str = GetCharStaticString();
+ if (str != CPLUSPLUS_MSG)
+ throw new Exception("Test char get 3 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ char[] str = GetCharStaticStringFixed();
+ if (str != CPLUSPLUS_MSG)
+ throw new Exception("Test char get 4 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ char[] str = GetConstCharStaticStringFixed();
+ if (str != CPLUSPLUS_MSG)
+ throw new Exception("Test char get 5 failed, iteration " ~ toString(i));
+ }
+
+ // set functions
+ for (i=0; i<count; i++) {
+ if (!SetCharHeapString(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char set 1 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetCharStaticString(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char set 2 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char set 3 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetConstCharHeapString(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char set 4 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetConstCharStaticString(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char set 5 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetConstCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char set 6 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetCharConstStaticString(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char set 7 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetConstCharConstStaticString(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char set 8 failed, iteration " ~ toString(i));
+ }
+
+ // get set function
+ for (i=0; i<count*10; i++) {
+ char[] ping = OTHERLAND_MSG ~ toString(i);
+ char[] pong = CharPingPong(ping);
+ if (ping != pong)
+ throw new Exception("Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong);
+ }
+
+ // variables
+ for (i=0; i<count; i++) {
+ global_char = OTHERLAND_MSG ~ toString(i);
+ if (global_char != OTHERLAND_MSG ~ toString(i))
+ throw new Exception("Test variables 1 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ global_char_array1 = OTHERLAND_MSG ~ toString(i);
+ if (global_char_array1 != OTHERLAND_MSG ~ toString(i))
+ throw new Exception("Test variables 2 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ global_char_array2 = OTHERLAND_MSG ~ toString(i);
+ if (global_char_array2 != OTHERLAND_MSG ~ toString(i))
+ throw new Exception("Test variables 3 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (global_const_char != CPLUSPLUS_MSG)
+ throw new Exception("Test variables 4 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (global_const_char_array1 != CPLUSPLUS_MSG)
+ throw new Exception("Test variables 5 failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (global_const_char_array2 != CPLUSPLUS_MSG)
+ throw new Exception("Test variables 6 failed, iteration " ~ toString(i));
+ }
+
+ // char *& tests
+ for (i=0; i<count; i++) {
+ char[] str = GetCharPointerRef();
+ if (str != CPLUSPLUS_MSG)
+ throw new Exception("Test char pointer ref get failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetCharPointerRef(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test char pointer ref set failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ char[] str = GetConstCharPointerRef();
+ if (str != CPLUSPLUS_MSG)
+ throw new Exception("Test const char pointer ref get failed, iteration " ~ toString(i));
+ }
+
+ for (i=0; i<count; i++) {
+ if (!SetConstCharPointerRef(OTHERLAND_MSG ~ toString(i), i))
+ throw new Exception("Test const char pointer ref set failed, iteration " ~ toString(i));
+ }
+}
diff --git a/Examples/test-suite/d/char_strings_runme.2.d b/Examples/test-suite/d/char_strings_runme.2.d
new file mode 100644
index 000000000..5fe28e995
--- /dev/null
+++ b/Examples/test-suite/d/char_strings_runme.2.d
@@ -0,0 +1,123 @@
+module char_strings_runme;
+
+import std.conv;
+import std.exception;
+import std.range;
+import char_strings.char_strings;
+
+enum CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
+enum OTHERLAND_MSG = "Little message from the safe world.";
+enum TEST_RANGE = iota(0, 10000);
+
+void main() {
+ // get functions
+ foreach (i; TEST_RANGE) {
+ enforce(GetCharHeapString() == CPLUSPLUS_MSG, "Test char get 1 failed, iteration " ~ to!string(i));
+ DeleteCharHeapString();
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(GetConstCharProgramCodeString() == CPLUSPLUS_MSG, "Test char get 2 failed, iteration " ~ to!string(i));
+ DeleteCharHeapString();
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(GetCharStaticString() == CPLUSPLUS_MSG, "Test char get 3 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(GetCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 4 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(GetConstCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 5 failed, iteration " ~ to!string(i));
+ }
+
+ // set functions
+ foreach (i; TEST_RANGE) {
+ enforce(SetCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 1 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 2 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 3 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetConstCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 4 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetConstCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 5 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetConstCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 6 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 7 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetConstCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 8 failed, iteration " ~ to!string(i));
+ }
+
+ // get set function
+ foreach (i; TEST_RANGE) {
+ string ping = OTHERLAND_MSG ~ to!string(i);
+ string pong = CharPingPong(ping);
+ enforce(ping == pong, "Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong);
+ }
+
+ // variables
+ foreach (i; TEST_RANGE) {
+ const msg = OTHERLAND_MSG ~ to!string(i);
+ global_char = msg;
+ enforce(global_char == msg, "Test variables 1 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ const msg = OTHERLAND_MSG ~ to!string(i);
+ global_char_array1 = msg;
+ enforce(global_char_array1 == msg, "Test variables 2 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ const msg = OTHERLAND_MSG ~ to!string(i);
+ global_char_array2 = msg;
+ enforce(global_char_array2 == msg, "Test variables 2 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(global_const_char == CPLUSPLUS_MSG, "Test variables 4 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(global_const_char_array1 == CPLUSPLUS_MSG, "Test variables 5 failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(global_const_char_array2 == CPLUSPLUS_MSG, "Test variables 6 failed, iteration " ~ to!string(i));
+ }
+
+ // char *& tests
+ foreach (i; TEST_RANGE) {
+ enforce(GetCharPointerRef() == CPLUSPLUS_MSG, "Test char pointer ref get failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test char pointer ref set failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(GetConstCharPointerRef() == CPLUSPLUS_MSG, "Test const char pointer ref get failed, iteration " ~ to!string(i));
+ }
+
+ foreach (i; TEST_RANGE) {
+ enforce(SetConstCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test const char pointer ref set failed, iteration " ~ to!string(i));
+ }
+}
diff --git a/Examples/test-suite/d/constover_runme.1.d b/Examples/test-suite/d/constover_runme.1.d
new file mode 100644
index 000000000..ead67319e
--- /dev/null
+++ b/Examples/test-suite/d/constover_runme.1.d
@@ -0,0 +1,31 @@
+module constover_runme;
+
+import constover.constover;
+import constover.Foo;
+
+void main() {
+ char[] p = test("test");
+ if (p != "test")
+ throw new Exception("test failed!");
+
+ p = test_pconst("test");
+ if (p != "test_pconst")
+ throw new Exception("test_pconst failed!");
+
+ auto f = new Foo();
+ p = f.test("test");
+ if (p != "test")
+ throw new Exception("member-test failed!");
+
+ p = f.test_pconst("test");
+ if (p != "test_pconst")
+ throw new Exception("member-test_pconst failed!");
+
+ p = f.test_constm("test");
+ if (p != "test_constmethod")
+ throw new Exception("member-test_constm failed!");
+
+ p = f.test_pconstm("test");
+ if (p != "test_pconstmethod")
+ throw new Exception("member-test_pconstm failed!");
+}
diff --git a/Examples/test-suite/d/constover_runme.2.d b/Examples/test-suite/d/constover_runme.2.d
new file mode 100644
index 000000000..68f7f207a
--- /dev/null
+++ b/Examples/test-suite/d/constover_runme.2.d
@@ -0,0 +1,16 @@
+module constover_runme;
+
+import std.exception;
+import constover.constover;
+import constover.Foo;
+
+void main() {
+ enforce(test("test") == "test", "test failed!");
+ enforce(test_pconst("test") == "test_pconst", "test_pconst failed!");
+
+ auto f = new Foo();
+ enforce(f.test("test") == "test", "member-test failed!");
+ enforce(f.test_pconst("test") == "test_pconst", "member-test_pconst failed!");
+ enforce(f.test_constm("test") == "test_constmethod", "member-test_constm failed!");
+ enforce(f.test_pconstm("test") == "test_pconstmethod", "member-test_pconstm failed!");
+}
diff --git a/Examples/test-suite/d/d_nativepointers_runme.1.d b/Examples/test-suite/d/d_nativepointers_runme.1.d
new file mode 100644
index 000000000..00407c1db
--- /dev/null
+++ b/Examples/test-suite/d/d_nativepointers_runme.1.d
@@ -0,0 +1,23 @@
+module d_nativepointers_runnme;
+
+import d_nativepointers.d_nativepointers;
+import d_nativepointers.SomeClass;
+import d_nativepointers.SWIGTYPE_p_OpaqueClass;
+import d_nativepointers.SWIGTYPE_p_p_SomeClass;
+import d_nativepointers.SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void;
+
+void main() {
+ check!(a, int*);
+ check!(b, float**);
+ check!(c, char***);
+ check!(d, SomeClass);
+ check!(e, SWIGTYPE_p_p_SomeClass);
+ check!(f, SWIGTYPE_p_OpaqueClass);
+ check!(g, void function(int**, char***));
+ check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void);
+}
+
+void check(alias F, T)() {
+ static assert(is(T function(T) == typeof(&F)));
+ assert(F(null) is null);
+}
diff --git a/Examples/test-suite/d/d_nativepointers_runme.2.d b/Examples/test-suite/d/d_nativepointers_runme.2.d
new file mode 100644
index 000000000..00407c1db
--- /dev/null
+++ b/Examples/test-suite/d/d_nativepointers_runme.2.d
@@ -0,0 +1,23 @@
+module d_nativepointers_runnme;
+
+import d_nativepointers.d_nativepointers;
+import d_nativepointers.SomeClass;
+import d_nativepointers.SWIGTYPE_p_OpaqueClass;
+import d_nativepointers.SWIGTYPE_p_p_SomeClass;
+import d_nativepointers.SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void;
+
+void main() {
+ check!(a, int*);
+ check!(b, float**);
+ check!(c, char***);
+ check!(d, SomeClass);
+ check!(e, SWIGTYPE_p_p_SomeClass);
+ check!(f, SWIGTYPE_p_OpaqueClass);
+ check!(g, void function(int**, char***));
+ check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void);
+}
+
+void check(alias F, T)() {
+ static assert(is(T function(T) == typeof(&F)));
+ assert(F(null) is null);
+}
diff --git a/Examples/test-suite/d/default_args_runme.1.d b/Examples/test-suite/d/default_args_runme.1.d
new file mode 100644
index 000000000..0ad63b7c2
--- /dev/null
+++ b/Examples/test-suite/d/default_args_runme.1.d
@@ -0,0 +1,127 @@
+module default_args_runme;
+
+import default_args.default_args;
+import default_args.ConstMethods;
+import default_args.EnumClass;
+import default_args.Except;
+import default_args.Foo;
+import default_args.Klass;
+import default_args.Statics;
+import default_args.Tricky;
+
+void main() {
+ if (anonymous() != 7771)
+ throw new Exception("anonymous (1) failed");
+ if (anonymous(1234) != 1234)
+ throw new Exception("anonymous (2) failed");
+
+ if (booltest() != true)
+ throw new Exception("booltest (1) failed");
+ if (booltest(true) != true)
+ throw new Exception("booltest (2) failed");
+ if (booltest(false) != false)
+ throw new Exception("booltest (3) failed");
+
+ auto ec = new EnumClass();
+ if (ec.blah() != true)
+ throw new Exception("EnumClass failed");
+
+ if (casts1() != null)
+ throw new Exception("casts1 failed");
+
+ if (casts2() != "Hello")
+ throw new Exception("casts2 failed");
+
+ if (casts1("Ciao") != "Ciao")
+ throw new Exception("casts1 not default failed");
+
+ if (chartest1() != 'x')
+ throw new Exception("chartest1 failed");
+
+ if (chartest2() != '\0')
+ throw new Exception("chartest2 failed");
+
+ if (chartest1('y') != 'y')
+ throw new Exception("chartest1 not default failed");
+
+ if (chartest1('y') != 'y')
+ throw new Exception("chartest1 not default failed");
+
+ if (reftest1() != 42)
+ throw new Exception("reftest1 failed");
+
+ if (reftest1(400) != 400)
+ throw new Exception("reftest1 not default failed");
+
+ if (reftest2() != "hello")
+ throw new Exception("reftest2 failed");
+
+ // rename
+ auto foo = new Foo();
+ foo.newname();
+ foo.newname(10);
+ foo.renamed3arg(10, 10.0);
+ foo.renamed2arg(10);
+ foo.renamed1arg();
+
+ // exception specifications
+ testException( { exceptionspec(); }, "exceptionspec 1" );
+ testException( { exceptionspec(-1); }, "exceptionspec 2" );
+ testException( { exceptionspec(100); }, "exceptionspec 3" );
+
+ auto ex = new Except(false);
+ testException( { ex.exspec(); }, "exspec 1" );
+ testException( { ex.exspec(-1); }, "exspec 2" );
+ testException( { ex.exspec(100); }, "exspec 3" );
+ testException( { ex = new Except(true); }, "Except constructor 1" );
+ testException( { ex = new Except(true, -2); }, "Except constructor 2" );
+
+ // Default parameters in static class methods
+ if (Statics.staticmethod() != 10+20+30)
+ throw new Exception("staticmethod 1 failed");
+ if (Statics.staticmethod(100) != 100+20+30)
+ throw new Exception("staticmethod 2 failed");
+ if (Statics.staticmethod(100,200,300) != 100+200+300)
+ throw new Exception("staticmethod 3 failed");
+
+
+ auto tricky = new Tricky();
+ if (tricky.privatedefault() != 200)
+ throw new Exception("privatedefault failed");
+ if (tricky.protectedint() != 2000)
+ throw new Exception("protectedint failed");
+ if (tricky.protecteddouble() != 987.654)
+ throw new Exception("protecteddouble failed");
+ if (tricky.functiondefault() != 500)
+ throw new Exception("functiondefault failed");
+ if (tricky.contrived() != 'X')
+ throw new Exception("contrived failed");
+
+ if (constructorcall().val != -1)
+ throw new Exception("constructorcall test 1 failed");
+
+ if (constructorcall(new Klass(2222)).val != 2222)
+ throw new Exception("constructorcall test 2 failed");
+
+ if (constructorcall(new Klass()).val != -1)
+ throw new Exception("constructorcall test 3 failed");
+
+ // const methods
+ auto cm = new ConstMethods();
+ if (cm.coo() != 20)
+ throw new Exception("coo test 1 failed");
+ if (cm.coo(1.0) != 20)
+ throw new Exception("coo test 2 failed");
+}
+
+void testException(void delegate() command, char[] testName) {
+ bool didntThrow;
+ try {
+ command();
+ didntThrow = true;
+ } catch (Exception e) {}
+
+ if (didntThrow) {
+ throw new Exception(testName ~ " failed");
+ }
+}
diff --git a/Examples/test-suite/d/default_args_runme.2.d b/Examples/test-suite/d/default_args_runme.2.d
new file mode 100644
index 000000000..15688aec8
--- /dev/null
+++ b/Examples/test-suite/d/default_args_runme.2.d
@@ -0,0 +1,84 @@
+module default_args_runme;
+
+import std.exception;
+import default_args.default_args;
+import default_args.ConstMethods;
+import default_args.EnumClass;
+import default_args.Except;
+import default_args.Foo;
+import default_args.Klass;
+import default_args.Statics;
+import default_args.Tricky;
+
+void main() {
+ enforce(anonymous() == 7771, "anonymous (1) failed");
+ enforce(anonymous(1234) == 1234,"anonymous (2) failed");
+ enforce(booltest() == true, "booltest (1) failed");
+ enforce(booltest(true) == true, "booltest (2) failed");
+ enforce(booltest(false) == false, "booltest (3) failed");
+ enforce((new EnumClass()).blah() == true, "EnumClass failed");
+ enforce(casts1() == null, "casts1 failed");
+ enforce(casts2() == "Hello", "casts2 failed");
+ enforce(casts1("Ciao") == "Ciao", "casts1 not default failed");
+ enforce(chartest1() == 'x', "chartest1 failed");
+ enforce(chartest2() == '\0', "chartest2 failed");
+ enforce(chartest1('y') == 'y', "chartest1 not default failed");
+ enforce(chartest1('y') == 'y', "chartest1 not default failed");
+ enforce(reftest1() == 42, "reftest1 failed");
+ enforce(reftest1(400) == 400, "reftest1 not default failed");
+ enforce(reftest2() == "hello", "reftest2 failed");
+
+ // rename
+ auto foo = new Foo();
+ foo.newname();
+ foo.newname(10);
+ foo.renamed3arg(10, 10.0);
+ foo.renamed2arg(10);
+ foo.renamed1arg();
+
+ // exception specifications
+ enforceThrows( (){ exceptionspec(); }, "exceptionspec 1" );
+ enforceThrows( (){ exceptionspec(-1); }, "exceptionspec 2" );
+ enforceThrows( (){ exceptionspec(100); }, "exceptionspec 3" );
+
+ auto ex = new Except(false);
+ enforceThrows( (){ ex.exspec(); }, "exspec 1" );
+ enforceThrows( (){ ex.exspec(-1); }, "exspec 2" );
+ enforceThrows( (){ ex.exspec(100); }, "exspec 3" );
+ enforceThrows( (){ ex = new Except(true); }, "Except constructor 1" );
+ enforceThrows( (){ ex = new Except(true, -2); }, "Except constructor 2" );
+
+ // Default parameters in static class methods
+ enforce(Statics.staticmethod() == 10+20+30, "staticmethod 1 failed");
+ enforce(Statics.staticmethod(100) == 100+20+30, "staticmethod 2 failed");
+ enforce(Statics.staticmethod(100,200,300) == 100+200+300, "staticmethod 3 failed");
+
+ auto tricky = new Tricky();
+ enforce(tricky.privatedefault() == 200, "privatedefault failed");
+ enforce(tricky.protectedint() == 2000, "protectedint failed");
+ enforce(tricky.protecteddouble() == 987.654, "protecteddouble failed");
+ enforce(tricky.functiondefault() == 500, "functiondefault failed");
+ enforce(tricky.contrived() == 'X', "contrived failed");
+
+ enforce(constructorcall().val == -1, "constructorcall test 1 failed");
+ enforce(constructorcall(new Klass(2222)).val == 2222, "constructorcall test 2 failed");
+ enforce(constructorcall(new Klass()).val == -1, "constructorcall test 3 failed");
+
+ // const methods
+ const cm = new ConstMethods();
+ enforce(cm.coo() == 20, "coo test 1 failed");
+ enforce(cm.coo(1.0) == 20, "coo test 2 failed");
+}
+
+private void enforceThrows(void delegate() dg, string errorMessage) {
+ bool hasThrown;
+ try {
+ dg();
+ } catch (Exception) {
+ hasThrown = true;
+ } finally {
+ if (!hasThrown) {
+ throw new Exception(errorMessage);
+ }
+ }
+}
diff --git a/Examples/test-suite/d/default_constructor_runme.1.d b/Examples/test-suite/d/default_constructor_runme.1.d
new file mode 100644
index 000000000..3640218ae
--- /dev/null
+++ b/Examples/test-suite/d/default_constructor_runme.1.d
@@ -0,0 +1,30 @@
+module default_constructor_runme;
+
+import default_constructor.FFF;
+import default_constructor.G;
+
+void main() {
+ // Protected destructor test.
+ try {
+ {
+ scope g = new G();
+ }
+ throw new Exception("Protected destructor exception should have been thrown");
+ } catch (Exception e) {
+ if (e.msg != "C++ destructor does not have public access") {
+ throw e;
+ }
+ }
+
+ // Private destructor test.
+ try {
+ {
+ scope f = new FFF();
+ }
+ throw new Exception("Private destructor exception should have been thrown");
+ } catch (Exception e) {
+ if (e.msg != "C++ destructor does not have public access") {
+ throw e;
+ }
+ }
+}
diff --git a/Examples/test-suite/d/default_constructor_runme.2.d b/Examples/test-suite/d/default_constructor_runme.2.d
new file mode 100644
index 000000000..22f5bffd2
--- /dev/null
+++ b/Examples/test-suite/d/default_constructor_runme.2.d
@@ -0,0 +1,25 @@
+module default_constructor_runme;
+
+import default_constructor.FFF;
+import default_constructor.G;
+
+void main() {
+ // D2 does not support something akin to D1/Tango dispose() for deterministic
+ // destruction yet.
+
+ // enforceThrows((){ scope g = new G(); }, "Protected destructor exception should have been thrown");
+ // enforceThrows((){ scope f = new FFF(); }, "Private destructor exception should have been thrown");
+}
+
+private void enforceThrows(void delegate() dg, string errorMessage) {
+ bool hasThrown;
+ try {
+ dg();
+ } catch (Exception) {
+ hasThrown = true;
+ } finally {
+ if (!hasThrown) {
+ throw new Exception(errorMessage);
+ }
+ }
+}
diff --git a/Examples/test-suite/d/director_basic_runme.1.d b/Examples/test-suite/d/director_basic_runme.1.d
new file mode 100644
index 000000000..58a54835e
--- /dev/null
+++ b/Examples/test-suite/d/director_basic_runme.1.d
@@ -0,0 +1,59 @@
+module director_basic_runme;
+
+import director_basic.A1;
+import director_basic.Bar;
+import director_basic.Foo;
+import director_basic.MyClass;
+
+void main() {
+ auto a = new director_basic_MyFoo();
+ if (a.ping() != "director_basic_MyFoo::ping()") {
+ throw new Exception("a.ping()");
+ }
+ if (a.pong() != "Foo::pong();director_basic_MyFoo::ping()") {
+ throw new Exception("a.pong()");
+ }
+
+ auto b = new Foo();
+ if (b.ping() != "Foo::ping()") {
+ throw new Exception("b.ping()");
+ }
+ if (b.pong() != "Foo::pong();Foo::ping()") {
+ throw new Exception("b.pong()");
+ }
+
+ {
+ scope a1 = new A1(1, false);
+ }
+
+ {
+ auto my = new MyOverriddenClass();
+
+ my.expectNull = true;
+ if (MyClass.call_pmethod(my, null) !is null)
+ throw new Exception("null pointer conversion problem");
+
+ auto myBar = new Bar();
+ my.expectNull = false;
+ auto myNewBar = MyClass.call_pmethod(my, myBar);
+ if (myNewBar is null)
+ throw new Exception("non-null pointer conversion problem");
+ myNewBar.x = 10;
+ }
+}
+
+class director_basic_MyFoo : Foo {
+ public override char[] ping() {
+ return "director_basic_MyFoo::ping()";
+ }
+}
+
+class MyOverriddenClass : MyClass {
+ public bool expectNull = false;
+ public bool nonNullReceived = false;
+ public override Bar pmethod(Bar b) {
+ if (expectNull && (b !is null))
+ throw new Exception("null not received as expected");
+ return b;
+ }
+}
diff --git a/Examples/test-suite/d/director_basic_runme.2.d b/Examples/test-suite/d/director_basic_runme.2.d
new file mode 100644
index 000000000..877fcbc47
--- /dev/null
+++ b/Examples/test-suite/d/director_basic_runme.2.d
@@ -0,0 +1,46 @@
+module director_basic_runme;
+
+import std.exception;
+import director_basic.A1;
+import director_basic.Bar;
+import director_basic.Foo;
+import director_basic.MyClass;
+
+void main() {
+ auto a = new director_basic_MyFoo();
+ enforce(a.ping() == "director_basic_MyFoo::ping()", "a.ping()");
+ enforce(a.pong() == "Foo::pong();director_basic_MyFoo::ping()", "a.pong()");
+
+ auto b = new Foo();
+ enforce(b.ping() == "Foo::ping()", "b.ping()");
+ enforce(b.pong() == "Foo::pong();Foo::ping()", "b.pong()");
+
+ {
+ scope a1 = new A1(1, false);
+ }
+
+ auto my = new MyOverriddenClass();
+ my.expectNull = true;
+ enforce(MyClass.call_pmethod(my, null) is null, "null pointer conversion problem");
+ auto myBar = new Bar();
+ my.expectNull = false;
+ auto myNewBar = MyClass.call_pmethod(my, myBar);
+ enforce(myNewBar !is null, "non-null pointer conversion problem");
+ myNewBar.x = 10;
+}
+
+class director_basic_MyFoo : Foo {
+ public override string ping() {
+ return "director_basic_MyFoo::ping()";
+ }
+}
+
+class MyOverriddenClass : MyClass {
+ public bool expectNull = false;
+ public bool nonNullReceived = false;
+ public override Bar pmethod(Bar b) {
+ if (expectNull && (b !is null))
+ throw new Exception("null not received as expected");
+ return b;
+ }
+}
diff --git a/Examples/test-suite/d/director_classes_runme.1.d b/Examples/test-suite/d/director_classes_runme.1.d
new file mode 100644
index 000000000..9c34db82a
--- /dev/null
+++ b/Examples/test-suite/d/director_classes_runme.1.d
@@ -0,0 +1,168 @@
+/**
+ * This test demonstrates director classes when the types are classes. Shown are
+ * virtual function calls which use classes passed by
+ * - Value
+ * - Reference
+ * - Pointer
+ * as both parameters and return values
+ *
+ * The test also demonstrates directors used with:
+ * - method overloading
+ * - default parameters
+ *
+ * Note: Methods with default parameters that call up from C++ cannot call the
+ * overloaded D methods, see DefaultParms method.
+
+ * Expected output if PrintDebug enabled:
+ * ------------ Start ------------
+ * Base - Val(444.555)
+ * Base - Ref(444.555)
+ * Base - Ptr(444.555)
+ * Base - FullyOverloaded(int 10)
+ * Base - FullyOverloaded(bool 1)
+ * Base - SemiOverloaded(int -678)
+ * Base - SemiOverloaded(bool 1)
+ * Base - DefaultParms(10, 2.2)
+ * Base - DefaultParms(10, 1.1)
+ * --------------------------------
+ * Derived - Val(444.555)
+ * Derived - Ref(444.555)
+ * Derived - Ptr(444.555)
+ * Derived - FullyOverloaded(int 10)
+ * Derived - FullyOverloaded(bool 1)
+ * Derived - SemiOverloaded(int -678)
+ * Base - SemiOverloaded(bool 1)
+ * Derived - DefaultParms(10, 2.2)
+ * Derived - DefaultParms(10, 1.1)
+ * --------------------------------
+ * DDerived - Val(444.555)
+ * DDerived - Ref(444.555)
+ * DDerived - Ptr(444.555)
+ * DDerived - FullyOverloaded(int 10)
+ * DDerived - FullyOverloaded(bool True)
+ * DDerived - SemiOverloaded(-678)
+ * Base - SemiOverloaded(bool 1)
+ * DDerived - DefaultParms(10, 2.2)
+ * DDerived - DefaultParms(10, 1.1)
+ * ------------ Finish ------------
+ */
+module director_classes_runme;
+
+import tango.io.Stdout;
+import tango.text.Util;
+import director_classes.director_classes;
+import director_classes.Caller;
+import director_classes.Base;
+import director_classes.Derived;
+import director_classes.DoubleHolder;
+
+void main() {
+ if (PrintDebug) Stdout.formatln("------------ Start ------------ ");
+
+ auto myCaller = new Caller();
+
+ // Test C++ base class.
+ {
+ scope myBase = new Base(100.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) Stdout.formatln("--------------------------------");
+
+ // Test vanilla C++ wrapped derived class.
+ {
+ scope myBase = new Derived(200.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) Stdout.formatln("--------------------------------");
+
+ // Test director / D derived class.
+ {
+ scope myBase = new DDerived(300.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) Stdout.formatln("------------ Finish ------------ ");
+}
+
+void makeCalls(Caller myCaller, Base myBase) {
+ char[] myBaseType = myBase.classinfo.name.split(".")[$-1];
+ myCaller.set(myBase);
+
+ DoubleHolder dh = new DoubleHolder(444.555);
+
+ // Class pointer, reference and pass by value tests
+ if (myCaller.ValCall(dh).val != dh.val) throw new Exception("[1] failed");
+ if (myCaller.RefCall(dh).val != dh.val) throw new Exception("[2] failed");
+ if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("[3] failed");
+
+ // Fully overloaded method test (all methods in base class are overloaded)
+ if (myCaller.FullyOverloadedCall(10) != myBaseType ~ "::FullyOverloaded(int)") throw new Exception("[4] failed");
+ if (myCaller.FullyOverloadedCall(true) != myBaseType ~ "::FullyOverloaded(bool)") throw new Exception("[5] failed");
+
+ // Semi overloaded method test (some methods in base class are overloaded)
+ if (myCaller.SemiOverloadedCall(-678) != myBaseType ~ "::SemiOverloaded(int)") throw new Exception("[6] failed");
+ if (myCaller.SemiOverloadedCall(true) != "Base" ~ "::SemiOverloaded(bool)") throw new Exception("[7] failed");
+
+ // Default parameters methods test
+ if (myCaller.DefaultParmsCall(10, 2.2) != myBaseType ~ "::DefaultParms(int, double)") throw new Exception("[8] failed");
+ if (myBase.classinfo == DDerived.classinfo) { // special handling for D derived classes, there is no way to do this any other way
+ if (myCaller.DefaultParmsCall(10) != myBaseType ~ "::DefaultParms(int, double)") throw new Exception("[9] failed");
+ } else {
+ if (myCaller.DefaultParmsCall(10) != myBaseType ~ "::DefaultParms(int)") throw new Exception("[10] failed");
+ }
+
+ myCaller.reset();
+}
+
+public class DDerived : Base {
+ public this(double dd) {
+ super(dd);
+ }
+
+ public override DoubleHolder Val(DoubleHolder x) {
+ if (PrintDebug) Stdout.formatln("DDerived - Val({0:d3})", x.val);
+ return x;
+ }
+
+ public override DoubleHolder Ref(DoubleHolder x) {
+ if (PrintDebug) Stdout.formatln("DDerived - Ref({0:d3})", x.val);
+ return x;
+ }
+
+ public override DoubleHolder Ptr(DoubleHolder x) {
+ if (PrintDebug) Stdout.formatln("DDerived - Ptr({0:d3})", x.val);
+ return x;
+ }
+
+ public override char[] FullyOverloaded(int x) {
+ if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(int {0})", x);
+ return "DDerived::FullyOverloaded(int)";
+ }
+
+ public override char[] FullyOverloaded(bool x) {
+ if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(bool {0})", x);
+ return "DDerived::FullyOverloaded(bool)";
+ }
+
+ public override char[] SemiOverloaded(int x) {
+ char[] ret = "DDerived::SemiOverloaded(int)";
+ if (PrintDebug) Stdout.formatln("DDerived - SemiOverloaded({0})", x);
+ return ret;
+ }
+ alias Base.SemiOverloaded SemiOverloaded; // Alias in SemiOverloaded(bool x).
+
+ public override char[] DefaultParms(int x, double y) {
+ char[] ret = "DDerived::DefaultParms(int, double)";
+ if (PrintDebug) Stdout.formatln("DDerived - DefaultParms({0}, {1:d1})", x, y);
+ return ret;
+ }
+ // This method will never be called from C++ code because the two-parameter
+ // DefaultParams() has a default value for the second parameter there. It is
+ // only here to ensure consistent behavior for calls from C++ and D code.
+ public override char[] DefaultParms(int x) {
+ if (PrintDebug) Stdout.formatln("DDerived - DefaultParms({0})", x);
+ return DefaultParms(x, 1.1/*use C++ default here*/);
+ }
+}
diff --git a/Examples/test-suite/d/director_classes_runme.2.d b/Examples/test-suite/d/director_classes_runme.2.d
new file mode 100644
index 000000000..98e27b3cd
--- /dev/null
+++ b/Examples/test-suite/d/director_classes_runme.2.d
@@ -0,0 +1,169 @@
+/**
+ * This test demonstrates director classes when the types are classes. Shown are
+ * virtual function calls which use classes passed by
+ * - Value
+ * - Reference
+ * - Pointer
+ * as both parameters and return values
+ *
+ * The test also demonstrates directors used with:
+ * - method overloading
+ * - default parameters
+ *
+ * Note: Methods with default parameters that call up from C++ cannot call the
+ * overloaded D methods, see DefaultParms method.
+
+ * Expected output if PrintDebug enabled:
+ * ------------ Start ------------
+ * Base - Val(444.555)
+ * Base - Ref(444.555)
+ * Base - Ptr(444.555)
+ * Base - FullyOverloaded(int 10)
+ * Base - FullyOverloaded(bool 1)
+ * Base - SemiOverloaded(int -678)
+ * Base - SemiOverloaded(bool 1)
+ * Base - DefaultParms(10, 2.2)
+ * Base - DefaultParms(10, 1.1)
+ * --------------------------------
+ * Derived - Val(444.555)
+ * Derived - Ref(444.555)
+ * Derived - Ptr(444.555)
+ * Derived - FullyOverloaded(int 10)
+ * Derived - FullyOverloaded(bool 1)
+ * Derived - SemiOverloaded(int -678)
+ * Base - SemiOverloaded(bool 1)
+ * Derived - DefaultParms(10, 2.2)
+ * Derived - DefaultParms(10, 1.1)
+ * --------------------------------
+ * DDerived - Val(444.555)
+ * DDerived - Ref(444.555)
+ * DDerived - Ptr(444.555)
+ * DDerived - FullyOverloaded(int 10)
+ * DDerived - FullyOverloaded(bool true)
+ * DDerived - SemiOverloaded(-678)
+ * Base - SemiOverloaded(bool 1)
+ * DDerived - DefaultParms(10, 2.2)
+ * DDerived - DefaultParms(10, 1.1)
+ * ------------ Finish ------------
+ */
+module director_classes_runme;
+
+import std.exception;
+import std.stdio;
+import std.string;
+import director_classes.director_classes;
+import director_classes.Caller;
+import director_classes.Base;
+import director_classes.Derived;
+import director_classes.DoubleHolder;
+
+void main() {
+ if (PrintDebug) writeln("------------ Start ------------ ");
+
+ auto myCaller = new Caller();
+
+ // Test C++ base class.
+ {
+ scope myBase = new Base(100.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) writeln("--------------------------------");
+
+ // Test vanilla C++ wrapped derived class.
+ {
+ scope myBase = new Derived(200.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) writeln("--------------------------------");
+
+ // Test director / D derived class.
+ {
+ scope myBase = new DDerived(300.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) writeln("------------ Finish ------------ ");
+}
+
+void makeCalls(Caller myCaller, Base myBase) {
+ string myBaseType = myBase.classinfo.name.split(".")[$-1];
+ myCaller.set(myBase);
+
+ DoubleHolder dh = new DoubleHolder(444.555);
+
+ // Class pointer, reference and pass by value tests
+ enforce(myCaller.ValCall(dh).val == dh.val, "[1] failed");
+ enforce(myCaller.RefCall(dh).val == dh.val, "[2] failed");
+ enforce(myCaller.PtrCall(dh).val == dh.val, "[3] failed");
+
+ // Fully overloaded method test (all methods in base class are overloaded)
+ enforce(myCaller.FullyOverloadedCall(10) == myBaseType ~ "::FullyOverloaded(int)", "[4] failed");
+ enforce(myCaller.FullyOverloadedCall(true) == myBaseType ~ "::FullyOverloaded(bool)", "[5] failed");
+
+ // Semi overloaded method test (some methods in base class are overloaded)
+ enforce(myCaller.SemiOverloadedCall(-678) == myBaseType ~ "::SemiOverloaded(int)", "[6] failed");
+ enforce(myCaller.SemiOverloadedCall(true) == "Base" ~ "::SemiOverloaded(bool)", "[7] failed");
+
+ // Default parameters methods test
+ enforce(myCaller.DefaultParmsCall(10, 2.2) == myBaseType ~ "::DefaultParms(int, double)", "[8] failed");
+ if (myBase.classinfo == DDerived.classinfo) { // special handling for D derived classes, there is no other way to do this
+ enforce(myCaller.DefaultParmsCall(10) == myBaseType ~ "::DefaultParms(int, double)", "[9] failed");
+ } else {
+ enforce(myCaller.DefaultParmsCall(10) == myBaseType ~ "::DefaultParms(int)", "[10] failed");
+ }
+
+ myCaller.reset();
+}
+
+public class DDerived : Base {
+ public this(double dd) {
+ super(dd);
+ }
+
+ public override DoubleHolder Val(DoubleHolder x) {
+ if (PrintDebug) writefln("DDerived - Val(%s)", x.val);
+ return x;
+ }
+
+ public override DoubleHolder Ref(DoubleHolder x) {
+ if (PrintDebug) writefln("DDerived - Ref(%s)", x.val);
+ return x;
+ }
+
+ public override DoubleHolder Ptr(DoubleHolder x) {
+ if (PrintDebug) writefln("DDerived - Ptr(%s)", x.val);
+ return x;
+ }
+
+ public override string FullyOverloaded(int x) {
+ if (PrintDebug) writefln("DDerived - FullyOverloaded(int %s)", x);
+ return "DDerived::FullyOverloaded(int)";
+ }
+
+ public override string FullyOverloaded(bool x) {
+ if (PrintDebug) writefln("DDerived - FullyOverloaded(bool %s)", x);
+ return "DDerived::FullyOverloaded(bool)";
+ }
+
+ public override string SemiOverloaded(int x) {
+ string ret = "DDerived::SemiOverloaded(int)";
+ if (PrintDebug) writefln("DDerived - SemiOverloaded(%s)", x);
+ return ret;
+ }
+ alias Base.SemiOverloaded SemiOverloaded; // Alias in SemiOverloaded(bool x).
+
+ public override string DefaultParms(int x, double y) {
+ string ret = "DDerived::DefaultParms(int, double)";
+ if (PrintDebug) writefln("DDerived - DefaultParms(%s, %s)", x, y);
+ return ret;
+ }
+ // This method will never be called from C++ code because the two-parameter
+ // DefaultParams() has a default value for the second parameter there. It is
+ // only here to ensure consistent behavior for calls from C++ and D code.
+ public override string DefaultParms(int x) {
+ if (PrintDebug) writefln("DDerived - DefaultParms(%s)", x);
+ return DefaultParms(x, 1.1/*use C++ default here*/);
+ }
+}
diff --git a/Examples/test-suite/d/director_classic_runme.1.d b/Examples/test-suite/d/director_classic_runme.1.d
new file mode 100644
index 000000000..33be80618
--- /dev/null
+++ b/Examples/test-suite/d/director_classic_runme.1.d
@@ -0,0 +1,207 @@
+module director_classic_runme;
+
+import tango.io.Stdout;
+import director_classic.Caller;
+import director_classic.Person;
+import director_classic.Child;
+import director_classic.GrandChild;
+import director_classic.OrphanPerson;
+import director_classic.OrphanChild;
+
+const bool TRACE = false;
+
+void main() {
+ {
+ scope person = new Person();
+ check(person, "Person");
+ }
+ {
+ scope person = new Child();
+ check(person, "Child");
+ }
+ {
+ scope person = new GrandChild();
+ check(person, "GrandChild");
+ }
+ {
+ scope person = new TargetLangPerson();
+ check(person, "TargetLangPerson");
+ }
+ {
+ scope person = new TargetLangChild();
+ check(person, "TargetLangChild");
+ }
+ {
+ scope person = new TargetLangGrandChild();
+ check(person, "TargetLangGrandChild");
+ }
+
+ // Semis - don't override id() in target language
+ {
+ scope person = new TargetLangSemiPerson();
+ check(person, "Person");
+ }
+ {
+ scope person = new TargetLangSemiChild();
+ check(person, "Child");
+ }
+ {
+ scope person = new TargetLangSemiGrandChild();
+ check(person, "GrandChild");
+ }
+
+ // Orphans - don't override id() in C++
+ {
+ scope person = new OrphanPerson();
+ check(person, "Person");
+ }
+ {
+ scope person = new OrphanChild();
+ check(person, "Child");
+ }
+ {
+ scope person = new TargetLangOrphanPerson();
+ check(person, "TargetLangOrphanPerson");
+ }
+ {
+ scope person = new TargetLangOrphanChild();
+ check(person, "TargetLangOrphanChild");
+ }
+
+ // Duals - id() makes an upcall to the base id()
+ {
+ scope person = new TargetLangDualPerson();
+ check(person, "TargetLangDualPerson + Person");
+ }
+ {
+ scope person = new TargetLangDualChild();
+ check(person, "TargetLangDualChild + Child");
+ }
+ {
+ scope person = new TargetLangDualGrandChild();
+ check(person, "TargetLangDualGrandChild + GrandChild");
+ }
+
+ // Mix Orphans and Duals
+ {
+ scope person = new TargetLangDualOrphanPerson();
+ check(person, "TargetLangDualOrphanPerson + Person");
+ }
+ {
+ scope person = new TargetLangDualOrphanChild();
+ check(person, "TargetLangDualOrphanChild + Child");
+ }
+}
+
+void check(Person person, char[] expected) {
+ char[] ret;
+ // Normal D polymorphic call.
+ ret = person.id();
+ if (TRACE)
+ Stdout(ret).newline;
+ if (ret != expected)
+ throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected);
+
+ // Polymorphic call from C++.
+ Caller caller = new Caller();
+ caller.setCallback(person);
+ ret = caller.call();
+ if (TRACE)
+ Stdout(ret).newline;
+ if (ret != expected)
+ throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected);
+
+ // Polymorphic call of object created in D and passed to C++ and back again.
+ Person baseclass = caller.baseClass();
+ ret = baseclass.id();
+ if (TRACE)
+ Stdout(ret).newline;
+ if (ret != expected)
+ throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected);
+
+ caller.resetCallback();
+ if (TRACE)
+ Stdout("----------------------------------------").newline;
+}
+
+
+// »Full« target language persons.
+class TargetLangPerson : Person {
+ public override char[] id() {
+ return "TargetLangPerson";
+ }
+}
+
+class TargetLangChild : Child {
+ public override char[] id() {
+ return "TargetLangChild";
+ }
+}
+
+class TargetLangGrandChild : GrandChild {
+ public override char[] id() {
+ return "TargetLangGrandChild";
+ }
+}
+
+
+// Semis - don't override id() in target language
+class TargetLangSemiPerson : Person {
+ // No id() override
+}
+
+class TargetLangSemiChild : Child {
+ // No id() override
+}
+
+class TargetLangSemiGrandChild : GrandChild {
+ // No id() override
+}
+
+
+// Orphans - don't override id() in C++
+class TargetLangOrphanPerson : OrphanPerson {
+ public override char[] id() {
+ return "TargetLangOrphanPerson";
+ }
+}
+
+class TargetLangOrphanChild : OrphanChild {
+ public override char[] id() {
+ return "TargetLangOrphanChild";
+ }
+}
+
+
+// Duals - id() makes an upcall to the base id()
+class TargetLangDualPerson : Person {
+ public override char[] id() {
+ return "TargetLangDualPerson + " ~ super.id();
+ }
+}
+
+class TargetLangDualChild : Child {
+ public override char[] id() {
+ return "TargetLangDualChild + " ~ super.id();
+ }
+}
+
+class TargetLangDualGrandChild : GrandChild {
+ public override char[] id() {
+ return "TargetLangDualGrandChild + " ~ super.id();
+ }
+}
+
+
+// Mix Orphans and Duals
+class TargetLangDualOrphanPerson : OrphanPerson {
+ public override char[] id() {
+ return "TargetLangDualOrphanPerson + " ~ super.id();
+ }
+}
+
+class TargetLangDualOrphanChild : OrphanChild {
+ public override char[] id() {
+ return "TargetLangDualOrphanChild + " ~ super.id();
+ }
+}
diff --git a/Examples/test-suite/d/director_classic_runme.2.d b/Examples/test-suite/d/director_classic_runme.2.d
new file mode 100644
index 000000000..c50781b07
--- /dev/null
+++ b/Examples/test-suite/d/director_classic_runme.2.d
@@ -0,0 +1,202 @@
+module director_classic_runme;
+
+import std.exception;
+import std.stdio;
+import director_classic.Caller;
+import director_classic.Person;
+import director_classic.Child;
+import director_classic.GrandChild;
+import director_classic.OrphanPerson;
+import director_classic.OrphanChild;
+
+enum TRACE = false;
+
+void main() {
+ {
+ scope person = new Person();
+ check(person, "Person");
+ }
+ {
+ scope person = new Child();
+ check(person, "Child");
+ }
+ {
+ scope person = new GrandChild();
+ check(person, "GrandChild");
+ }
+ {
+ scope person = new TargetLangPerson();
+ check(person, "TargetLangPerson");
+ }
+ {
+ scope person = new TargetLangChild();
+ check(person, "TargetLangChild");
+ }
+ {
+ scope person = new TargetLangGrandChild();
+ check(person, "TargetLangGrandChild");
+ }
+
+ // Semis - don't override id() in target language
+ {
+ scope person = new TargetLangSemiPerson();
+ check(person, "Person");
+ }
+ {
+ scope person = new TargetLangSemiChild();
+ check(person, "Child");
+ }
+ {
+ scope person = new TargetLangSemiGrandChild();
+ check(person, "GrandChild");
+ }
+
+ // Orphans - don't override id() in C++
+ {
+ scope person = new OrphanPerson();
+ check(person, "Person");
+ }
+ {
+ scope person = new OrphanChild();
+ check(person, "Child");
+ }
+ {
+ scope person = new TargetLangOrphanPerson();
+ check(person, "TargetLangOrphanPerson");
+ }
+ {
+ scope person = new TargetLangOrphanChild();
+ check(person, "TargetLangOrphanChild");
+ }
+
+ // Duals - id() makes an upcall to the base id()
+ {
+ scope person = new TargetLangDualPerson();
+ check(person, "TargetLangDualPerson + Person");
+ }
+ {
+ scope person = new TargetLangDualChild();
+ check(person, "TargetLangDualChild + Child");
+ }
+ {
+ scope person = new TargetLangDualGrandChild();
+ check(person, "TargetLangDualGrandChild + GrandChild");
+ }
+
+ // Mix Orphans and Duals
+ {
+ scope person = new TargetLangDualOrphanPerson();
+ check(person, "TargetLangDualOrphanPerson + Person");
+ }
+ {
+ scope person = new TargetLangDualOrphanChild();
+ check(person, "TargetLangDualOrphanChild + Child");
+ }
+}
+
+void check(Person person, string expected) {
+ string ret;
+ // Normal D polymorphic call.
+ ret = person.id();
+ if (TRACE) writeln(ret);
+ enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected);
+
+ // Polymorphic call from C++.
+ auto caller = new Caller();
+ caller.setCallback(person);
+ ret = caller.call();
+ if (TRACE) writeln(ret);
+ enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected);
+
+ // Polymorphic call of object created in D and passed to C++ and back again.
+ Person baseclass = caller.baseClass();
+ ret = baseclass.id();
+ if (TRACE) writeln(ret);
+ enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected);
+
+ caller.resetCallback();
+ if (TRACE)
+ writeln("----------------------------------------");
+}
+
+
+// »Full« target language persons.
+class TargetLangPerson : Person {
+ public override string id() {
+ return "TargetLangPerson";
+ }
+}
+
+class TargetLangChild : Child {
+ public override string id() {
+ return "TargetLangChild";
+ }
+}
+
+class TargetLangGrandChild : GrandChild {
+ public override string id() {
+ return "TargetLangGrandChild";
+ }
+}
+
+
+// Semis - don't override id() in target language
+class TargetLangSemiPerson : Person {
+ // No id() override
+}
+
+class TargetLangSemiChild : Child {
+ // No id() override
+}
+
+class TargetLangSemiGrandChild : GrandChild {
+ // No id() override
+}
+
+
+// Orphans - don't override id() in C++
+class TargetLangOrphanPerson : OrphanPerson {
+ public override string id() {
+ return "TargetLangOrphanPerson";
+ }
+}
+
+class TargetLangOrphanChild : OrphanChild {
+ public override string id() {
+ return "TargetLangOrphanChild";
+ }
+}
+
+
+// Duals - id() makes an upcall to the base id()
+class TargetLangDualPerson : Person {
+ public override string id() {
+ return "TargetLangDualPerson + " ~ super.id();
+ }
+}
+
+class TargetLangDualChild : Child {
+ public override string id() {
+ return "TargetLangDualChild + " ~ super.id();
+ }
+}
+
+class TargetLangDualGrandChild : GrandChild {
+ public override string id() {
+ return "TargetLangDualGrandChild + " ~ super.id();
+ }
+}
+
+
+// Mix Orphans and Duals
+class TargetLangDualOrphanPerson : OrphanPerson {
+ public override string id() {
+ return "TargetLangDualOrphanPerson + " ~ super.id();
+ }
+}
+
+class TargetLangDualOrphanChild : OrphanChild {
+ public override string id() {
+ return "TargetLangDualOrphanChild + " ~ super.id();
+ }
+}
diff --git a/Examples/test-suite/d/director_ignore_runme.1.d b/Examples/test-suite/d/director_ignore_runme.1.d
new file mode 100644
index 000000000..797d2fddf
--- /dev/null
+++ b/Examples/test-suite/d/director_ignore_runme.1.d
@@ -0,0 +1,39 @@
+module director_ignore_runme;
+
+import director_ignore.DIgnores;
+import director_ignore.DAbstractIgnores;
+
+void main() {
+ // Just check the classes can be instantiated and other methods work as expected
+ auto a = new DIgnoresDerived();
+ if (a.Triple(5) != 15)
+ throw new Exception("Triple failed");
+
+ auto b = new DAbstractIgnoresDerived();
+ if (b.Quadruple(5) != 20)
+ throw new Exception("Quadruple failed");
+}
+
+class DIgnoresDerived : DIgnores {
+public:
+ // These will give a warning if the %ignore is not working
+ int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; }
+ int OverloadedMethod(int n, int xoffset) { return 0; }
+ int OverloadedMethod(int n) { return 0; }
+
+ int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; }
+ int OverloadedProtectedMethod(int n, int xoffset) { return 0; }
+ int OverloadedProtectedMethod(int n) { return 0; }
+}
+
+class DAbstractIgnoresDerived : DAbstractIgnores {
+public:
+ // These will give a warning if the %ignore is not working
+ int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; }
+ int OverloadedMethod(int n, int xoffset) { return 0; }
+ int OverloadedMethod(int n) { return 0; }
+
+ int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; }
+ int OverloadedProtectedMethod(int n, int xoffset) { return 0; }
+ int OverloadedProtectedMethod(int n) { return 0; }
+}
diff --git a/Examples/test-suite/d/director_ignore_runme.2.d b/Examples/test-suite/d/director_ignore_runme.2.d
new file mode 100644
index 000000000..b3e29b48d
--- /dev/null
+++ b/Examples/test-suite/d/director_ignore_runme.2.d
@@ -0,0 +1,38 @@
+module director_ignore_runme;
+
+import std.exception;
+import director_ignore.DIgnores;
+import director_ignore.DAbstractIgnores;
+
+void main() {
+ // Just check the classes can be instantiated and other methods work as expected
+ auto a = new DIgnoresDerived();
+ enforce(a.Triple(5) == 15, "Triple failed");
+
+ auto b = new DAbstractIgnoresDerived();
+ enforce(b.Quadruple(5) == 20, "Quadruple failed");
+}
+
+class DIgnoresDerived : DIgnores {
+public:
+ // These will give a warning if the %ignore is not working
+ int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; }
+ int OverloadedMethod(int n, int xoffset) { return 0; }
+ int OverloadedMethod(int n) { return 0; }
+
+ int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; }
+ int OverloadedProtectedMethod(int n, int xoffset) { return 0; }
+ int OverloadedProtectedMethod(int n) { return 0; }
+}
+
+class DAbstractIgnoresDerived : DAbstractIgnores {
+public:
+ // These will give a warning if the %ignore is not working
+ int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; }
+ int OverloadedMethod(int n, int xoffset) { return 0; }
+ int OverloadedMethod(int n) { return 0; }
+
+ int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; }
+ int OverloadedProtectedMethod(int n, int xoffset) { return 0; }
+ int OverloadedProtectedMethod(int n) { return 0; }
+}
diff --git a/Examples/test-suite/d/director_primitives_runme.1.d b/Examples/test-suite/d/director_primitives_runme.1.d
new file mode 100644
index 000000000..f19e86f59
--- /dev/null
+++ b/Examples/test-suite/d/director_primitives_runme.1.d
@@ -0,0 +1,122 @@
+/**
+ * This test program shows a D class DDerived inheriting from Base.
+ *
+ * Three types of classes are created and the virtual methods called to
+ * demonstrate:
+ * - Wide variety of primitive types
+ * - Calling methods with zero, one or more parameters
+ * - Director methods that are not overridden in D
+ * - Director classes that are not overridden at all in D, i.e. non-director
+ * behaviour is as expected for director classes
+ * - Inheritance hierarchy using director methods
+ * - Return types working as well as parameters
+ *
+ * The Caller class is a tester class which calls the virtual functions from C++.
+ */
+module director_primitives_runme;
+
+import tango.io.Stdout;
+import director_primitives.director_primitives;
+import director_primitives.Base;
+import director_primitives.Caller;
+import director_primitives.Derived;
+import director_primitives.HShadowMode;
+
+void main() {
+ PrintDebug = false;
+ if (PrintDebug) Stdout("------------ Start ------------ ").newline;
+
+ Caller myCaller = new Caller();
+
+ // Test C++ base class.
+ {
+ scope myBase = new Base(100.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) Stdout("--------------------------------").newline;
+
+ // Test vanilla C++ wrapped derived class.
+ {
+ scope Base myBase = new Derived(100.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) Stdout("--------------------------------").newline;
+
+ // Test director/D derived class.
+ {
+ scope Base myBase = new DDerived(300.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) Stdout("------------ Finish ------------ ").newline;
+}
+
+void makeCalls(Caller myCaller, Base myBase) {
+ myCaller.set(myBase);
+
+ myCaller.NoParmsMethodCall();
+ if (myCaller.BoolMethodCall(true) != true) throw new Exception("failed");
+ if (myCaller.BoolMethodCall(false) != false) throw new Exception("failed");
+ if (myCaller.IntMethodCall(-123) != -123) throw new Exception("failed");
+ if (myCaller.UIntMethodCall(123) != 123) throw new Exception("failed");
+ if (myCaller.FloatMethodCall(-123.456f) != -123.456f) throw new Exception("failed");
+ if (myCaller.CharPtrMethodCall("test string") != "test string") throw new Exception("failed");
+ if (myCaller.ConstCharPtrMethodCall("another string") != "another string") throw new Exception("failed");
+ if (myCaller.EnumMethodCall(HShadowMode.HShadowHard) != HShadowMode.HShadowHard) throw new Exception("failed");
+ myCaller.ManyParmsMethodCall(true, -123, 123, 123.456f, "test string", "another string", HShadowMode.HShadowHard);
+ myCaller.NotOverriddenMethodCall();
+
+ myCaller.reset();
+}
+
+class DDerived : Base {
+public:
+ this(double dd) {
+ super(dd);
+ }
+
+ override void NoParmsMethod() {
+ if (PrintDebug) Stdout("DDerived - NoParmsMethod()").newline;
+ }
+
+ override bool BoolMethod(bool x) {
+ if (PrintDebug) Stdout.formatln("DDerived - BoolMethod({0})", x);
+ return x;
+ }
+
+ override int IntMethod(int x) {
+ if (PrintDebug) Stdout.formatln("DDerived - IntMethod({0})", x);
+ return x;
+ }
+
+ override uint UIntMethod(uint x) {
+ if (PrintDebug) Stdout.formatln("DDerived - UIntMethod({0})", x);
+ return x;
+ }
+
+ override float FloatMethod(float x) {
+ if (PrintDebug) Stdout.formatln("DDerived - FloatMethod({0})", x);
+ return x;
+ }
+
+ override char[] CharPtrMethod(char[] x) {
+ if (PrintDebug) Stdout.formatln("DDerived - CharPtrMethod({0})", x);
+ return x;
+ }
+
+ override char[] ConstCharPtrMethod(char[] x) {
+ if (PrintDebug) Stdout.formatln("DDerived - ConstCharPtrMethod({0})", x);
+ return x;
+ }
+
+ override HShadowMode EnumMethod(HShadowMode x) {
+ if (PrintDebug) Stdout.formatln("DDerived - EnumMethod({0})", x);
+ return x;
+ }
+
+ override void ManyParmsMethod(bool b, int i, uint u, float f, char[] c, char[] cc, HShadowMode h) {
+ if (PrintDebug) Stdout.formatln("DDerived - ManyParmsMethod({0}, {1}, {2}, {3:d3}, {4}, {5}, {6})", b, i, u, f, c, cc, h);
+ }
+}
diff --git a/Examples/test-suite/d/director_primitives_runme.2.d b/Examples/test-suite/d/director_primitives_runme.2.d
new file mode 100644
index 000000000..e0e307330
--- /dev/null
+++ b/Examples/test-suite/d/director_primitives_runme.2.d
@@ -0,0 +1,123 @@
+/**
+ * This test program shows a D class DDerived inheriting from Base.
+ *
+ * Three types of classes are created and the virtual methods called to
+ * demonstrate:
+ * - Wide variety of primitive types
+ * - Calling methods with zero, one or more parameters
+ * - Director methods that are not overridden in D
+ * - Director classes that are not overridden at all in D, i.e. non-director
+ * behaviour is as expected for director classes
+ * - Inheritance hierarchy using director methods
+ * - Return types working as well as parameters
+ *
+ * The Caller class is a tester class which calls the virtual functions from C++.
+ */
+module director_primitives_runme;
+
+import std.exception;
+import std.stdio;
+import director_primitives.director_primitives;
+import director_primitives.Base;
+import director_primitives.Caller;
+import director_primitives.Derived;
+import director_primitives.HShadowMode;
+
+void main() {
+ PrintDebug = false;
+ if (PrintDebug) writeln("------------ Start ------------ ");
+
+ auto myCaller = new Caller();
+
+ // Test C++ base class.
+ {
+ scope myBase = new Base(100.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) writeln("--------------------------------");
+
+ // Test vanilla C++ wrapped derived class.
+ {
+ scope Base myBase = new Derived(100.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) writeln("--------------------------------");
+
+ // Test director/D derived class.
+ {
+ scope Base myBase = new DDerived(300.0);
+ makeCalls(myCaller, myBase);
+ }
+
+ if (PrintDebug) writeln("------------ Finish ------------ ");
+}
+
+void makeCalls(Caller myCaller, Base myBase) {
+ myCaller.set(myBase);
+
+ myCaller.NoParmsMethodCall();
+ enforce(myCaller.BoolMethodCall(true) == true, "failed");
+ enforce(myCaller.BoolMethodCall(false) == false, "failed");
+ enforce(myCaller.IntMethodCall(-123) == -123, "failed");
+ enforce(myCaller.UIntMethodCall(123) == 123, "failed");
+ enforce(myCaller.FloatMethodCall(-123.456f) == -123.456f, "failed");
+ enforce(myCaller.CharPtrMethodCall("test string") == "test string", "failed");
+ enforce(myCaller.ConstCharPtrMethodCall("another string") == "another string", "failed");
+ enforce(myCaller.EnumMethodCall(HShadowMode.HShadowHard) == HShadowMode.HShadowHard, "failed");
+ myCaller.ManyParmsMethodCall(true, -123, 123, 123.456f, "test string", "another string", HShadowMode.HShadowHard);
+ myCaller.NotOverriddenMethodCall();
+
+ myCaller.reset();
+}
+
+class DDerived : Base {
+public:
+ this(double dd) {
+ super(dd);
+ }
+
+ override void NoParmsMethod() {
+ if (PrintDebug) writeln("DDerived - NoParmsMethod()");
+ }
+
+ override bool BoolMethod(bool x) {
+ if (PrintDebug) writefln("DDerived - BoolMethod(%s)", x);
+ return x;
+ }
+
+ override int IntMethod(int x) {
+ if (PrintDebug) writefln("DDerived - IntMethod(%s)", x);
+ return x;
+ }
+
+ override uint UIntMethod(uint x) {
+ if (PrintDebug) writefln("DDerived - UIntMethod(%s)", x);
+ return x;
+ }
+
+ override float FloatMethod(float x) {
+ if (PrintDebug) writefln("DDerived - FloatMethod(%s)", x);
+ return x;
+ }
+
+ override string CharPtrMethod(string x) {
+ if (PrintDebug) writefln("DDerived - CharPtrMethod(%s)", x);
+ return x;
+ }
+
+ override string ConstCharPtrMethod(string x) {
+ if (PrintDebug) writefln("DDerived - ConstCharPtrMethod(%s)", x);
+ return x;
+ }
+
+ override HShadowMode EnumMethod(HShadowMode x) {
+ if (PrintDebug) writefln("DDerived - EnumMethod(%s)", x);
+ return x;
+ }
+
+ override void ManyParmsMethod(bool b, int i, uint u, float f, string c, string cc, HShadowMode h) {
+ if (PrintDebug) writefln("DDerived - ManyParmsMethod(%s, %s, %s, %s, %s, %s, %s)", b, i, u, f, c, cc, h);
+ }
+}
diff --git a/Examples/test-suite/d/director_protected_runme.1.d b/Examples/test-suite/d/director_protected_runme.1.d
new file mode 100644
index 000000000..81447b73b
--- /dev/null
+++ b/Examples/test-suite/d/director_protected_runme.1.d
@@ -0,0 +1,50 @@
+module director_protected_runme;
+
+import director_protected.Foo;
+import director_protected.Bar;
+
+void main() {
+ Bar b = new Bar();
+ Foo f = b.create();
+ auto fb = new FooBar();
+ auto fb2 = new FooBar2();
+
+ char[] s;
+ s = fb.used();
+ if ( s != ("Foo::pang();Bar::pong();Foo::pong();FooBar::ping();"))
+ throw new Exception("bad FooBar::used" ~ " - " ~ s);
+
+ s = fb2.used();
+ if ( s != ("FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();"))
+ throw new Exception("bad FooBar2::used");
+
+ s = b.pong();
+ if ( s != ("Bar::pong();Foo::pong();Bar::ping();"))
+ throw new Exception("bad Bar::pong");
+
+ s = f.pong();
+ if ( s != ("Bar::pong();Foo::pong();Bar::ping();"))
+ throw new Exception("bad Foo::pong");
+
+ s = fb.pong();
+ if ( s != ("Bar::pong();Foo::pong();FooBar::ping();"))
+ throw new Exception("bad FooBar::pong");
+}
+
+class FooBar : Bar {
+protected:
+ override char[] ping() {
+ return "FooBar::ping();";
+ }
+}
+
+class FooBar2 : Bar{
+protected:
+ override char[] ping() {
+ return "FooBar2::ping();";
+ }
+
+ override char[] pang() {
+ return "FooBar2::pang();";
+ }
+}
diff --git a/Examples/test-suite/d/director_protected_runme.2.d b/Examples/test-suite/d/director_protected_runme.2.d
new file mode 100644
index 000000000..9beeecd23
--- /dev/null
+++ b/Examples/test-suite/d/director_protected_runme.2.d
@@ -0,0 +1,36 @@
+module director_protected_runme;
+
+import std.exception;
+import director_protected.Foo;
+import director_protected.Bar;
+
+void main() {
+ Bar b = new Bar();
+ Foo f = b.create();
+ auto fb = new FooBar();
+ scope fb2 = new FooBar2();
+
+ enforce(fb.used() == "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();", "bad FooBar::used" ~ " - " ~ fb.used());
+ enforce(fb2.used() == "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();", "bad FooBar2::used");
+ enforce(b.pong() == "Bar::pong();Foo::pong();Bar::ping();", "bad Bar::pong");
+ enforce(f.pong() == "Bar::pong();Foo::pong();Bar::ping();", "bad Foo::pong");
+ enforce(fb.pong() == "Bar::pong();Foo::pong();FooBar::ping();", "bad FooBar::pong");
+}
+
+class FooBar : Bar {
+protected:
+ override string ping() {
+ return "FooBar::ping();";
+ }
+}
+
+class FooBar2 : Bar {
+protected:
+ override string ping() {
+ return "FooBar2::ping();";
+ }
+
+ override string pang() {
+ return "FooBar2::pang();";
+ }
+}
diff --git a/Examples/test-suite/d/director_string_runme.1.d b/Examples/test-suite/d/director_string_runme.1.d
new file mode 100644
index 000000000..4e750791a
--- /dev/null
+++ b/Examples/test-suite/d/director_string_runme.1.d
@@ -0,0 +1,46 @@
+module director_string_runme;
+
+import Integer = tango.text.convert.Integer;
+import director_string.A;
+
+void main() {
+ char[] s;
+
+ auto c = new director_string_A("hi");
+ for (int i=0; i<3; ++i) {
+ s = c.call_get(i);
+ if (s != Integer.toString(i)) throw new Exception("director_string_A.get(" ~ Integer.toString(i) ~ ") failed. Got:" ~ s);
+ }
+
+ auto b = new director_string_B("hello");
+
+ s = b.call_get_first();
+ if (s != "director_string_B.get_first") throw new Exception("call_get_first() failed");
+
+ s = b.call_get(0);
+ if (s != "director_string_B.get: hello") throw new Exception("get(0) failed");
+}
+
+class director_string_B : A {
+public:
+ this(char[] first) {
+ super(first);
+ }
+ override char[] get_first() {
+ return "director_string_B.get_first";
+ }
+
+ override char[] get(int n) {
+ return "director_string_B.get: " ~ super.get(n);
+ }
+}
+
+class director_string_A : A {
+public:
+ this(char[] first) {
+ super(first);
+ }
+ override char[] get(int n) {
+ return Integer.toString(n);
+ }
+}
diff --git a/Examples/test-suite/d/director_string_runme.2.d b/Examples/test-suite/d/director_string_runme.2.d
new file mode 100644
index 000000000..950a34072
--- /dev/null
+++ b/Examples/test-suite/d/director_string_runme.2.d
@@ -0,0 +1,42 @@
+module director_string_runme;
+
+import std.conv;
+import std.exception;
+import director_string.A;
+
+void main() {
+ auto c = new director_string_A("hi");
+ for (int i=0; i<3; ++i) {
+ auto s = c.call_get(i);
+ auto expected = to!string(i);
+ enforce(s == expected, "director_string_A.get(" ~ expected ~ ") failed. Got:" ~ s);
+ }
+
+ auto b = new director_string_B("hello");
+ enforce(b.call_get_first() == "director_string_B.get_first", "call_get_first() failed");
+ enforce(b.call_get(0) == "director_string_B.get: hello", "get(0) failed");
+}
+
+class director_string_B : A {
+public:
+ this(string first) {
+ super(first);
+ }
+ override string get_first() const {
+ return "director_string_B.get_first";
+ }
+
+ override string get(int n) const {
+ return "director_string_B.get: " ~ super.get(n);
+ }
+}
+
+class director_string_A : A {
+public:
+ this(string first) {
+ super(first);
+ }
+ override string get(int n) const {
+ return to!string(n);
+ }
+}
diff --git a/Examples/test-suite/d/enum_thorough_runme.1.d b/Examples/test-suite/d/enum_thorough_runme.1.d
new file mode 100644
index 000000000..b76bfdd93
--- /dev/null
+++ b/Examples/test-suite/d/enum_thorough_runme.1.d
@@ -0,0 +1,424 @@
+module enum_thorough_runme;
+
+import enum_thorough.enum_thorough;
+import enum_thorough.AnonStruct;
+import enum_thorough.colour;
+import enum_thorough.FirStruct;
+import enum_thorough.HairStruct;
+import enum_thorough.IgnoreTest;
+import enum_thorough.Instances;
+import enum_thorough.namedanon;
+import enum_thorough.namedanonspace;
+import enum_thorough.newname;
+import enum_thorough.NewNameStruct;
+import enum_thorough.repeat;
+import enum_thorough.SpeedClass;
+import enum_thorough.TClassInt;
+import enum_thorough.TemplateClassInt;
+import enum_thorough.TreesClass;
+import enum_thorough.twonames;
+import enum_thorough.TwoNamesStruct;
+
+void main() {
+ {
+ // Anonymous enums
+ int i = AnonEnum1;
+ if (ReallyAnInteger != 200) throw new Exception("Test Anon 1 failed");
+ i += AnonSpaceEnum1;
+ i += AnonStruct.AnonStructEnum1;
+ }
+ {
+ auto red = colour.red;
+ colourTest1(red);
+ colourTest2(red);
+ colourTest3(red);
+ colourTest4(red);
+ myColour = red;
+ }
+ {
+ auto s = new SpeedClass();
+ auto speed = SpeedClass.speed.slow;
+ if (s.speedTest1(speed) != speed) throw new Exception("speedTest 1 failed");
+ if (s.speedTest2(speed) != speed) throw new Exception("speedTest 2 failed");
+ if (s.speedTest3(speed) != speed) throw new Exception("speedTest 3 failed");
+ if (s.speedTest4(speed) != speed) throw new Exception("speedTest 4 failed");
+ if (s.speedTest5(speed) != speed) throw new Exception("speedTest 5 failed");
+ if (s.speedTest6(speed) != speed) throw new Exception("speedTest 6 failed");
+ if (s.speedTest7(speed) != speed) throw new Exception("speedTest 7 failed");
+ if (s.speedTest8(speed) != speed) throw new Exception("speedTest 8 failed");
+
+ if (speedTest1(speed) != speed) throw new Exception("speedTest Global 1 failed");
+ if (speedTest2(speed) != speed) throw new Exception("speedTest Global 2 failed");
+ if (speedTest3(speed) != speed) throw new Exception("speedTest Global 3 failed");
+ if (speedTest4(speed) != speed) throw new Exception("speedTest Global 4 failed");
+ if (speedTest5(speed) != speed) throw new Exception("speedTest Global 5 failed");
+ }
+ {
+ auto s = new SpeedClass();
+ auto slow = SpeedClass.speed.slow;
+ auto lightning = SpeedClass.speed.lightning;
+
+ if (s.mySpeedtd1 != slow) throw new Exception("mySpeedtd1 1 failed");
+ if (cast(int)s.mySpeedtd1 != 10) throw new Exception("mySpeedtd1 2 failed");
+
+ s.mySpeedtd1 = lightning;
+ if (s.mySpeedtd1 != lightning) throw new Exception("mySpeedtd1 3 failed");
+ if (cast(int)s.mySpeedtd1 != 31) throw new Exception("mySpeedtd1 4 failed");
+ }
+ {
+ if (namedanonTest1(namedanon.NamedAnon2) != namedanon.NamedAnon2) throw new Exception("namedanonTest 1 failed");
+ }
+ {
+ auto val = twonames.TwoNames2;
+ if (twonamesTest1(val) != val) throw new Exception("twonamesTest 1 failed");
+ if (twonamesTest2(val) != val) throw new Exception("twonamesTest 2 failed");
+ if (twonamesTest3(val) != val) throw new Exception("twonamesTest 3 failed");
+ }
+ {
+ auto t = new TwoNamesStruct();
+ auto val = TwoNamesStruct.twonames.TwoNamesStruct1;
+ if (t.twonamesTest1(val) != val) throw new Exception("twonamesTest 1 failed");
+ if (t.twonamesTest2(val) != val) throw new Exception("twonamesTest 2 failed");
+ if (t.twonamesTest3(val) != val) throw new Exception("twonamesTest 3 failed");
+ }
+ {
+ auto val = namedanonspace.NamedAnonSpace2;
+ if (namedanonspaceTest1(val) != val) throw new Exception("namedanonspaceTest 1 failed");
+ if (namedanonspaceTest2(val) != val) throw new Exception("namedanonspaceTest 2 failed");
+ if (namedanonspaceTest3(val) != val) throw new Exception("namedanonspaceTest 3 failed");
+ if (namedanonspaceTest4(val) != val) throw new Exception("namedanonspaceTest 4 failed");
+ }
+ {
+ auto t = new TemplateClassInt();
+ auto galileo = TemplateClassInt.scientists.galileo;
+ if (t.scientistsTest1(galileo) != galileo) throw new Exception("scientistsTest 1 failed");
+ if (t.scientistsTest2(galileo) != galileo) throw new Exception("scientistsTest 2 failed");
+ if (t.scientistsTest3(galileo) != galileo) throw new Exception("scientistsTest 3 failed");
+ if (t.scientistsTest4(galileo) != galileo) throw new Exception("scientistsTest 4 failed");
+ if (t.scientistsTest5(galileo) != galileo) throw new Exception("scientistsTest 5 failed");
+ if (t.scientistsTest6(galileo) != galileo) throw new Exception("scientistsTest 6 failed");
+ if (t.scientistsTest7(galileo) != galileo) throw new Exception("scientistsTest 7 failed");
+ if (t.scientistsTest8(galileo) != galileo) throw new Exception("scientistsTest 8 failed");
+ if (t.scientistsTest9(galileo) != galileo) throw new Exception("scientistsTest 9 failed");
+// if (t.scientistsTestA(galileo) != galileo) throw new Exception("scientistsTest A failed");
+ if (t.scientistsTestB(galileo) != galileo) throw new Exception("scientistsTest B failed");
+// if (t.scientistsTestC(galileo) != galileo) throw new Exception("scientistsTest C failed");
+ if (t.scientistsTestD(galileo) != galileo) throw new Exception("scientistsTest D failed");
+ if (t.scientistsTestE(galileo) != galileo) throw new Exception("scientistsTest E failed");
+ if (t.scientistsTestF(galileo) != galileo) throw new Exception("scientistsTest F failed");
+ if (t.scientistsTestG(galileo) != galileo) throw new Exception("scientistsTest G failed");
+ if (t.scientistsTestH(galileo) != galileo) throw new Exception("scientistsTest H failed");
+ if (t.scientistsTestI(galileo) != galileo) throw new Exception("scientistsTest I failed");
+ if (t.scientistsTestJ(galileo) != galileo) throw new Exception("scientistsTest J failed");
+
+ if (scientistsTest1(galileo) != galileo) throw new Exception("scientistsTest Global 1 failed");
+ if (scientistsTest2(galileo) != galileo) throw new Exception("scientistsTest Global 2 failed");
+ if (scientistsTest3(galileo) != galileo) throw new Exception("scientistsTest Global 3 failed");
+ if (scientistsTest4(galileo) != galileo) throw new Exception("scientistsTest Global 4 failed");
+ if (scientistsTest5(galileo) != galileo) throw new Exception("scientistsTest Global 5 failed");
+ if (scientistsTest6(galileo) != galileo) throw new Exception("scientistsTest Global 6 failed");
+ if (scientistsTest7(galileo) != galileo) throw new Exception("scientistsTest Global 7 failed");
+ if (scientistsTest8(galileo) != galileo) throw new Exception("scientistsTest Global 8 failed");
+ }
+ {
+ auto t = new TClassInt();
+ auto bell = TClassInt.scientists.bell;
+ auto galileo = TemplateClassInt.scientists.galileo;
+ if (t.scientistsNameTest1(bell) != bell) throw new Exception("scientistsNameTest 1 failed");
+ if (t.scientistsNameTest2(bell) != bell) throw new Exception("scientistsNameTest 2 failed");
+ if (t.scientistsNameTest3(bell) != bell) throw new Exception("scientistsNameTest 3 failed");
+ if (t.scientistsNameTest4(bell) != bell) throw new Exception("scientistsNameTest 4 failed");
+ if (t.scientistsNameTest5(bell) != bell) throw new Exception("scientistsNameTest 5 failed");
+ if (t.scientistsNameTest6(bell) != bell) throw new Exception("scientistsNameTest 6 failed");
+ if (t.scientistsNameTest7(bell) != bell) throw new Exception("scientistsNameTest 7 failed");
+ if (t.scientistsNameTest8(bell) != bell) throw new Exception("scientistsNameTest 8 failed");
+ if (t.scientistsNameTest9(bell) != bell) throw new Exception("scientistsNameTest 9 failed");
+// if (t.scientistsNameTestA(bell) != bell) throw new Exception("scientistsNameTest A failed");
+ if (t.scientistsNameTestB(bell) != bell) throw new Exception("scientistsNameTest B failed");
+// if (t.scientistsNameTestC(bell) != bell) throw new Exception("scientistsNameTest C failed");
+ if (t.scientistsNameTestD(bell) != bell) throw new Exception("scientistsNameTest D failed");
+ if (t.scientistsNameTestE(bell) != bell) throw new Exception("scientistsNameTest E failed");
+ if (t.scientistsNameTestF(bell) != bell) throw new Exception("scientistsNameTest F failed");
+ if (t.scientistsNameTestG(bell) != bell) throw new Exception("scientistsNameTest G failed");
+ if (t.scientistsNameTestH(bell) != bell) throw new Exception("scientistsNameTest H failed");
+ if (t.scientistsNameTestI(bell) != bell) throw new Exception("scientistsNameTest I failed");
+
+ if (t.scientistsNameSpaceTest1(bell) != bell) throw new Exception("scientistsNameSpaceTest 1 failed");
+ if (t.scientistsNameSpaceTest2(bell) != bell) throw new Exception("scientistsNameSpaceTest 2 failed");
+ if (t.scientistsNameSpaceTest3(bell) != bell) throw new Exception("scientistsNameSpaceTest 3 failed");
+ if (t.scientistsNameSpaceTest4(bell) != bell) throw new Exception("scientistsNameSpaceTest 4 failed");
+ if (t.scientistsNameSpaceTest5(bell) != bell) throw new Exception("scientistsNameSpaceTest 5 failed");
+ if (t.scientistsNameSpaceTest6(bell) != bell) throw new Exception("scientistsNameSpaceTest 6 failed");
+ if (t.scientistsNameSpaceTest7(bell) != bell) throw new Exception("scientistsNameSpaceTest 7 failed");
+
+ if (t.scientistsOtherTest1(galileo) != galileo) throw new Exception("scientistsOtherTest 1 failed");
+ if (t.scientistsOtherTest2(galileo) != galileo) throw new Exception("scientistsOtherTest 2 failed");
+ if (t.scientistsOtherTest3(galileo) != galileo) throw new Exception("scientistsOtherTest 3 failed");
+ if (t.scientistsOtherTest4(galileo) != galileo) throw new Exception("scientistsOtherTest 4 failed");
+ if (t.scientistsOtherTest5(galileo) != galileo) throw new Exception("scientistsOtherTest 5 failed");
+ if (t.scientistsOtherTest6(galileo) != galileo) throw new Exception("scientistsOtherTest 6 failed");
+ if (t.scientistsOtherTest7(galileo) != galileo) throw new Exception("scientistsOtherTest 7 failed");
+
+ if (scientistsNameTest1(bell) != bell) throw new Exception("scientistsNameTest Global 1 failed");
+ if (scientistsNameTest2(bell) != bell) throw new Exception("scientistsNameTest Global 2 failed");
+ if (scientistsNameTest3(bell) != bell) throw new Exception("scientistsNameTest Global 3 failed");
+ if (scientistsNameTest4(bell) != bell) throw new Exception("scientistsNameTest Global 4 failed");
+ if (scientistsNameTest5(bell) != bell) throw new Exception("scientistsNameTest Global 5 failed");
+ if (scientistsNameTest6(bell) != bell) throw new Exception("scientistsNameTest Global 6 failed");
+ if (scientistsNameTest7(bell) != bell) throw new Exception("scientistsNameTest Global 7 failed");
+
+ if (scientistsNameSpaceTest1(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 1 failed");
+ if (scientistsNameSpaceTest2(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 2 failed");
+ if (scientistsNameSpaceTest3(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 3 failed");
+ if (scientistsNameSpaceTest4(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 4 failed");
+ if (scientistsNameSpaceTest5(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 5 failed");
+ if (scientistsNameSpaceTest6(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 6 failed");
+ if (scientistsNameSpaceTest7(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 7 failed");
+
+ if (scientistsNameSpaceTest8(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 8 failed");
+ if (scientistsNameSpaceTest9(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 9 failed");
+ if (scientistsNameSpaceTestA(bell) != bell) throw new Exception("scientistsNameSpaceTest Global A failed");
+ if (scientistsNameSpaceTestB(bell) != bell) throw new Exception("scientistsNameSpaceTest Global B failed");
+ if (scientistsNameSpaceTestC(bell) != bell) throw new Exception("scientistsNameSpaceTest Global C failed");
+ if (scientistsNameSpaceTestD(bell) != bell) throw new Exception("scientistsNameSpaceTest Global D failed");
+ if (scientistsNameSpaceTestE(bell) != bell) throw new Exception("scientistsNameSpaceTest Global E failed");
+
+ if (scientistsNameSpaceTestF(bell) != bell) throw new Exception("scientistsNameSpaceTest Global F failed");
+ if (scientistsNameSpaceTestG(bell) != bell) throw new Exception("scientistsNameSpaceTest Global G failed");
+ if (scientistsNameSpaceTestH(bell) != bell) throw new Exception("scientistsNameSpaceTest Global H failed");
+ if (scientistsNameSpaceTestI(bell) != bell) throw new Exception("scientistsNameSpaceTest Global I failed");
+ if (scientistsNameSpaceTestJ(bell) != bell) throw new Exception("scientistsNameSpaceTest Global J failed");
+ if (scientistsNameSpaceTestK(bell) != bell) throw new Exception("scientistsNameSpaceTest Global K failed");
+ if (scientistsNameSpaceTestL(bell) != bell) throw new Exception("scientistsNameSpaceTest Global L failed");
+ }
+ {
+ auto val = newname.argh;
+ if (renameTest1(val) != val) throw new Exception("renameTest Global 1 failed");
+ if (renameTest2(val) != val) throw new Exception("renameTest Global 2 failed");
+ }
+ {
+ auto n = new NewNameStruct();
+ if (n.renameTest1(NewNameStruct.enumeration.bang) != NewNameStruct.enumeration.bang) throw new Exception("renameTest 1 failed");
+ if (n.renameTest2(NewNameStruct.enumeration.bang) != NewNameStruct.enumeration.bang) throw new Exception("renameTest 2 failed");
+ if (n.renameTest3(NewNameStruct.simplerenamed.simple1) != NewNameStruct.simplerenamed.simple1) throw new Exception("renameTest 3 failed");
+ if (n.renameTest4(NewNameStruct.doublenamerenamed.doublename1) != NewNameStruct.doublenamerenamed.doublename1) throw new Exception("renameTest 4 failed");
+ if (n.renameTest5(NewNameStruct.doublenamerenamed.doublename1) != NewNameStruct.doublenamerenamed.doublename1) throw new Exception("renameTest 5 failed");
+ if (n.renameTest6(NewNameStruct.singlenamerenamed.singlename1) != NewNameStruct.singlenamerenamed.singlename1) throw new Exception("renameTest 6 failed");
+ }
+ {
+ if (renameTest3(NewNameStruct.enumeration.bang) != NewNameStruct.enumeration.bang) throw new Exception("renameTest Global 3 failed");
+ if (renameTest4(NewNameStruct.simplerenamed.simple1) != NewNameStruct.simplerenamed.simple1) throw new Exception("renameTest Global 4 failed");
+ if (renameTest5(NewNameStruct.doublenamerenamed.doublename1) != NewNameStruct.doublenamerenamed.doublename1) throw new Exception("renameTest Global 5 failed");
+ if (renameTest6(NewNameStruct.doublenamerenamed.doublename1) != NewNameStruct.doublenamerenamed.doublename1) throw new Exception("renameTest Global 6 failed");
+ if (renameTest7(NewNameStruct.singlenamerenamed.singlename1) != NewNameStruct.singlenamerenamed.singlename1) throw new Exception("renameTest Global 7 failed");
+ }
+ {
+ auto t = new TreesClass();
+ auto pine = TreesClass.trees.pine;
+
+ if (t.treesTest1(pine) != pine) throw new Exception("treesTest 1 failed");
+ if (t.treesTest2(pine) != pine) throw new Exception("treesTest 2 failed");
+ if (t.treesTest3(pine) != pine) throw new Exception("treesTest 3 failed");
+ if (t.treesTest4(pine) != pine) throw new Exception("treesTest 4 failed");
+ if (t.treesTest5(pine) != pine) throw new Exception("treesTest 5 failed");
+ if (t.treesTest6(pine) != pine) throw new Exception("treesTest 6 failed");
+ if (t.treesTest7(pine) != pine) throw new Exception("treesTest 7 failed");
+ if (t.treesTest8(pine) != pine) throw new Exception("treesTest 8 failed");
+ if (t.treesTest9(pine) != pine) throw new Exception("treesTest 9 failed");
+ if (t.treesTestA(pine) != pine) throw new Exception("treesTest A failed");
+ if (t.treesTestB(pine) != pine) throw new Exception("treesTest B failed");
+ if (t.treesTestC(pine) != pine) throw new Exception("treesTest C failed");
+ if (t.treesTestD(pine) != pine) throw new Exception("treesTest D failed");
+ if (t.treesTestE(pine) != pine) throw new Exception("treesTest E failed");
+ if (t.treesTestF(pine) != pine) throw new Exception("treesTest F failed");
+ if (t.treesTestG(pine) != pine) throw new Exception("treesTest G failed");
+ if (t.treesTestH(pine) != pine) throw new Exception("treesTest H failed");
+ if (t.treesTestI(pine) != pine) throw new Exception("treesTest I failed");
+ if (t.treesTestJ(pine) != pine) throw new Exception("treesTest J failed");
+ if (t.treesTestK(pine) != pine) throw new Exception("treesTest K failed");
+ if (t.treesTestL(pine) != pine) throw new Exception("treesTest L failed");
+ if (t.treesTestM(pine) != pine) throw new Exception("treesTest M failed");
+ if (t.treesTestN(pine) != pine) throw new Exception("treesTest N failed");
+ if (t.treesTestO(pine) != pine) throw new Exception("treesTest O failed");
+
+ if (treesTest1(pine) != pine) throw new Exception("treesTest Global 1 failed");
+ if (treesTest2(pine) != pine) throw new Exception("treesTest Global 2 failed");
+ if (treesTest3(pine) != pine) throw new Exception("treesTest Global 3 failed");
+ if (treesTest4(pine) != pine) throw new Exception("treesTest Global 4 failed");
+ if (treesTest5(pine) != pine) throw new Exception("treesTest Global 5 failed");
+ if (treesTest6(pine) != pine) throw new Exception("treesTest Global 6 failed");
+ if (treesTest7(pine) != pine) throw new Exception("treesTest Global 7 failed");
+ if (treesTest8(pine) != pine) throw new Exception("treesTest Global 8 failed");
+ if (treesTest9(pine) != pine) throw new Exception("treesTest Global 9 failed");
+ if (treesTestA(pine) != pine) throw new Exception("treesTest Global A failed");
+ if (treesTestB(pine) != pine) throw new Exception("treesTest Global B failed");
+ if (treesTestC(pine) != pine) throw new Exception("treesTest Global C failed");
+ if (treesTestD(pine) != pine) throw new Exception("treesTest Global D failed");
+ if (treesTestE(pine) != pine) throw new Exception("treesTest Global E failed");
+ if (treesTestF(pine) != pine) throw new Exception("treesTest Global F failed");
+ if (treesTestG(pine) != pine) throw new Exception("treesTest Global G failed");
+ if (treesTestH(pine) != pine) throw new Exception("treesTest Global H failed");
+ if (treesTestI(pine) != pine) throw new Exception("treesTest Global I failed");
+ if (treesTestJ(pine) != pine) throw new Exception("treesTest Global J failed");
+ if (treesTestK(pine) != pine) throw new Exception("treesTest Global K failed");
+ if (treesTestL(pine) != pine) throw new Exception("treesTest Global L failed");
+ if (treesTestM(pine) != pine) throw new Exception("treesTest Global M failed");
+// if (treesTestN(pine) != pine) throw new Exception("treesTest Global N failed");
+ if (treesTestO(pine) != pine) throw new Exception("treesTest Global O failed");
+ if (treesTestP(pine) != pine) throw new Exception("treesTest Global P failed");
+ if (treesTestQ(pine) != pine) throw new Exception("treesTest Global Q failed");
+ if (treesTestR(pine) != pine) throw new Exception("treesTest Global R failed");
+ }
+ {
+ auto h = new HairStruct();
+ auto ginger = HairStruct.hair.ginger;
+
+ if (h.hairTest1(ginger) != ginger) throw new Exception("hairTest 1 failed");
+ if (h.hairTest2(ginger) != ginger) throw new Exception("hairTest 2 failed");
+ if (h.hairTest3(ginger) != ginger) throw new Exception("hairTest 3 failed");
+ if (h.hairTest4(ginger) != ginger) throw new Exception("hairTest 4 failed");
+ if (h.hairTest5(ginger) != ginger) throw new Exception("hairTest 5 failed");
+ if (h.hairTest6(ginger) != ginger) throw new Exception("hairTest 6 failed");
+ if (h.hairTest7(ginger) != ginger) throw new Exception("hairTest 7 failed");
+ if (h.hairTest8(ginger) != ginger) throw new Exception("hairTest 8 failed");
+ if (h.hairTest9(ginger) != ginger) throw new Exception("hairTest 9 failed");
+ if (h.hairTestA(ginger) != ginger) throw new Exception("hairTest A failed");
+ if (h.hairTestB(ginger) != ginger) throw new Exception("hairTest B failed");
+
+ auto red = colour.red;
+ if (h.colourTest1(red) != red) throw new Exception("colourTest HairStruct 1 failed");
+ if (h.colourTest2(red) != red) throw new Exception("colourTest HairStruct 2 failed");
+ if (h.namedanonTest1(namedanon.NamedAnon2) != namedanon.NamedAnon2) throw new Exception("namedanonTest HairStruct 1 failed");
+ if (h.namedanonspaceTest1(namedanonspace.NamedAnonSpace2) != namedanonspace.NamedAnonSpace2) throw new Exception("namedanonspaceTest HairStruct 1 failed");
+
+ auto fir = TreesClass.trees.fir;
+ if (h.treesGlobalTest1(fir) != fir) throw new Exception("treesGlobalTest1 HairStruct 1 failed");
+ if (h.treesGlobalTest2(fir) != fir) throw new Exception("treesGlobalTest1 HairStruct 2 failed");
+ if (h.treesGlobalTest3(fir) != fir) throw new Exception("treesGlobalTest1 HairStruct 3 failed");
+ if (h.treesGlobalTest4(fir) != fir) throw new Exception("treesGlobalTest1 HairStruct 4 failed");
+ }
+ {
+ auto blonde = HairStruct.hair.blonde;
+ if (hairTest1(blonde) != blonde) throw new Exception("hairTest Global 1 failed");
+ if (hairTest2(blonde) != blonde) throw new Exception("hairTest Global 2 failed");
+ if (hairTest3(blonde) != blonde) throw new Exception("hairTest Global 3 failed");
+ if (hairTest4(blonde) != blonde) throw new Exception("hairTest Global 4 failed");
+ if (hairTest5(blonde) != blonde) throw new Exception("hairTest Global 5 failed");
+ if (hairTest6(blonde) != blonde) throw new Exception("hairTest Global 6 failed");
+ if (hairTest7(blonde) != blonde) throw new Exception("hairTest Global 7 failed");
+ if (hairTest8(blonde) != blonde) throw new Exception("hairTest Global 8 failed");
+ if (hairTest9(blonde) != blonde) throw new Exception("hairTest Global 9 failed");
+ if (hairTestA(blonde) != blonde) throw new Exception("hairTest Global A failed");
+ if (hairTestB(blonde) != blonde) throw new Exception("hairTest Global B failed");
+ if (hairTestC(blonde) != blonde) throw new Exception("hairTest Global C failed");
+
+ if (hairTestA1(blonde) != blonde) throw new Exception("hairTest Global A1 failed");
+ if (hairTestA2(blonde) != blonde) throw new Exception("hairTest Global A2 failed");
+ if (hairTestA3(blonde) != blonde) throw new Exception("hairTest Global A3 failed");
+ if (hairTestA4(blonde) != blonde) throw new Exception("hairTest Global A4 failed");
+ if (hairTestA5(blonde) != blonde) throw new Exception("hairTest Global A5 failed");
+ if (hairTestA6(blonde) != blonde) throw new Exception("hairTest Global A6 failed");
+ if (hairTestA7(blonde) != blonde) throw new Exception("hairTest Global A7 failed");
+ if (hairTestA8(blonde) != blonde) throw new Exception("hairTest Global A8 failed");
+ if (hairTestA9(blonde) != blonde) throw new Exception("hairTest Global A9 failed");
+ if (hairTestAA(blonde) != blonde) throw new Exception("hairTest Global AA failed");
+ if (hairTestAB(blonde) != blonde) throw new Exception("hairTest Global AB failed");
+ if (hairTestAC(blonde) != blonde) throw new Exception("hairTest Global AC failed");
+
+ if (hairTestB1(blonde) != blonde) throw new Exception("hairTest Global B1 failed");
+ if (hairTestB2(blonde) != blonde) throw new Exception("hairTest Global B2 failed");
+ if (hairTestB3(blonde) != blonde) throw new Exception("hairTest Global B3 failed");
+ if (hairTestB4(blonde) != blonde) throw new Exception("hairTest Global B4 failed");
+ if (hairTestB5(blonde) != blonde) throw new Exception("hairTest Global B5 failed");
+ if (hairTestB6(blonde) != blonde) throw new Exception("hairTest Global B6 failed");
+ if (hairTestB7(blonde) != blonde) throw new Exception("hairTest Global B7 failed");
+ if (hairTestB8(blonde) != blonde) throw new Exception("hairTest Global B8 failed");
+ if (hairTestB9(blonde) != blonde) throw new Exception("hairTest Global B9 failed");
+ if (hairTestBA(blonde) != blonde) throw new Exception("hairTest Global BA failed");
+ if (hairTestBB(blonde) != blonde) throw new Exception("hairTest Global BB failed");
+ if (hairTestBC(blonde) != blonde) throw new Exception("hairTest Global BC failed");
+
+ if (hairTestC1(blonde) != blonde) throw new Exception("hairTest Global C1 failed");
+ if (hairTestC2(blonde) != blonde) throw new Exception("hairTest Global C2 failed");
+ if (hairTestC3(blonde) != blonde) throw new Exception("hairTest Global C3 failed");
+ if (hairTestC4(blonde) != blonde) throw new Exception("hairTest Global C4 failed");
+ if (hairTestC5(blonde) != blonde) throw new Exception("hairTest Global C5 failed");
+ if (hairTestC6(blonde) != blonde) throw new Exception("hairTest Global C6 failed");
+ if (hairTestC7(blonde) != blonde) throw new Exception("hairTest Global C7 failed");
+ if (hairTestC8(blonde) != blonde) throw new Exception("hairTest Global C8 failed");
+ if (hairTestC9(blonde) != blonde) throw new Exception("hairTest Global C9 failed");
+ if (hairTestCA(blonde) != blonde) throw new Exception("hairTest Global CA failed");
+ if (hairTestCB(blonde) != blonde) throw new Exception("hairTest Global CB failed");
+ if (hairTestCC(blonde) != blonde) throw new Exception("hairTest Global CC failed");
+ }
+ {
+ auto f = new FirStruct();
+ auto blonde = HairStruct.hair.blonde;
+
+ if (f.hairTestFir1(blonde) != blonde) throw new Exception("hairTestFir 1 failed");
+ if (f.hairTestFir2(blonde) != blonde) throw new Exception("hairTestFir 2 failed");
+ if (f.hairTestFir3(blonde) != blonde) throw new Exception("hairTestFir 3 failed");
+ if (f.hairTestFir4(blonde) != blonde) throw new Exception("hairTestFir 4 failed");
+ if (f.hairTestFir5(blonde) != blonde) throw new Exception("hairTestFir 5 failed");
+ if (f.hairTestFir6(blonde) != blonde) throw new Exception("hairTestFir 6 failed");
+ if (f.hairTestFir7(blonde) != blonde) throw new Exception("hairTestFir 7 failed");
+ if (f.hairTestFir8(blonde) != blonde) throw new Exception("hairTestFir 8 failed");
+ if (f.hairTestFir9(blonde) != blonde) throw new Exception("hairTestFir 9 failed");
+ if (f.hairTestFirA(blonde) != blonde) throw new Exception("hairTestFir A failed");
+ }
+ {
+ GlobalInstance = globalinstance2;
+ if (GlobalInstance != globalinstance2) throw new Exception("GlobalInstance 1 failed");
+
+ auto i = new Instances();
+ i.MemberInstance = Instances.memberinstance3;
+ if (i.MemberInstance != Instances.memberinstance3) throw new Exception("MemberInstance 1 failed");
+ }
+ // ignore enum item tests start
+ {
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero) != 0) throw new Exception("ignoreATest 0 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_three) != 3) throw new Exception("ignoreATest 3 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten) != 10) throw new Exception("ignoreATest 10 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven) != 11) throw new Exception("ignoreATest 11 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen) != 13) throw new Exception("ignoreATest 13 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen) != 14) throw new Exception("ignoreATest 14 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty) != 20) throw new Exception("ignoreATest 20 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty) != 30) throw new Exception("ignoreATest 30 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two) != 32) throw new Exception("ignoreATest 32 failed");
+ if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three) != 33) throw new Exception("ignoreATest 33 failed");
+ }
+ {
+ if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven) != 11) throw new Exception("ignoreBTest 11 failed");
+ if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve) != 12) throw new Exception("ignoreBTest 12 failed");
+ if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one) != 31) throw new Exception("ignoreBTest 31 failed");
+ if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two) != 32) throw new Exception("ignoreBTest 32 failed");
+ if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one) != 41) throw new Exception("ignoreBTest 41 failed");
+ if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two) != 42) throw new Exception("ignoreBTest 42 failed");
+ }
+ {
+ if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten) != 10) throw new Exception("ignoreCTest 10 failed");
+ if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve) != 12) throw new Exception("ignoreCTest 12 failed");
+ if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty) != 30) throw new Exception("ignoreCTest 30 failed");
+ if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two) != 32) throw new Exception("ignoreCTest 32 failed");
+ if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty) != 40) throw new Exception("ignoreCTest 40 failed");
+ if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two) != 42) throw new Exception("ignoreCTest 42 failed");
+ }
+ {
+ if (cast(int)ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one) != 21) throw new Exception("ignoreDTest 21 failed");
+ if (cast(int)ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two) != 22) throw new Exception("ignoreDTest 22 failed");
+ }
+ {
+ if (cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero) != 0) throw new Exception("ignoreETest 0 failed");
+ if (cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one) != 21) throw new Exception("ignoreETest 21 failed");
+ if (cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two) != 22) throw new Exception("ignoreETest 22 failed");
+ }
+ // ignore enum item tests end
+ {
+ if (cast(int)repeatTest(repeat.one) != 1) throw new Exception("repeatTest 1 failed");
+ if (cast(int)repeatTest(repeat.initial) != 1) throw new Exception("repeatTest 2 failed");
+ if (cast(int)repeatTest(repeat.two) != 2) throw new Exception("repeatTest 3 failed");
+ if (cast(int)repeatTest(repeat.three) != 3) throw new Exception("repeatTest 4 failed");
+ if (cast(int)repeatTest(repeat.llast) != 3) throw new Exception("repeatTest 5 failed");
+ if (cast(int)repeatTest(repeat.end) != 3) throw new Exception("repeatTest 6 failed");
+ }
+}
diff --git a/Examples/test-suite/d/enum_thorough_runme.2.d b/Examples/test-suite/d/enum_thorough_runme.2.d
new file mode 100644
index 000000000..d8b2a2ad9
--- /dev/null
+++ b/Examples/test-suite/d/enum_thorough_runme.2.d
@@ -0,0 +1,425 @@
+module enum_thorough_runme;
+
+import std.exception;
+import enum_thorough.enum_thorough;
+import enum_thorough.AnonStruct;
+import enum_thorough.colour;
+import enum_thorough.FirStruct;
+import enum_thorough.HairStruct;
+import enum_thorough.IgnoreTest;
+import enum_thorough.Instances;
+import enum_thorough.namedanon;
+import enum_thorough.namedanonspace;
+import enum_thorough.newname;
+import enum_thorough.NewNameStruct;
+import enum_thorough.repeat;
+import enum_thorough.SpeedClass;
+import enum_thorough.TClassInt;
+import enum_thorough.TemplateClassInt;
+import enum_thorough.TreesClass;
+import enum_thorough.twonames;
+import enum_thorough.TwoNamesStruct;
+
+void main() {
+ {
+ // Anonymous enums
+ int i = AnonEnum1;
+ enforce(ReallyAnInteger == 200, "Test Anon 1 failed");
+ i += AnonSpaceEnum1;
+ i += AnonStruct.AnonStructEnum1;
+ }
+ {
+ auto red = colour.red;
+ colourTest1(red);
+ colourTest2(red);
+ colourTest3(red);
+ colourTest4(red);
+ myColour = red;
+ }
+ {
+ auto s = new SpeedClass();
+ auto speed = SpeedClass.speed.slow;
+ enforce(s.speedTest1(speed) == speed, "speedTest 1 failed");
+ enforce(s.speedTest2(speed) == speed, "speedTest 2 failed");
+ enforce(s.speedTest3(speed) == speed, "speedTest 3 failed");
+ enforce(s.speedTest4(speed) == speed, "speedTest 4 failed");
+ enforce(s.speedTest5(speed) == speed, "speedTest 5 failed");
+ enforce(s.speedTest6(speed) == speed, "speedTest 6 failed");
+ enforce(s.speedTest7(speed) == speed, "speedTest 7 failed");
+ enforce(s.speedTest8(speed) == speed, "speedTest 8 failed");
+
+ enforce(speedTest1(speed) == speed, "speedTest Global 1 failed");
+ enforce(speedTest2(speed) == speed, "speedTest Global 2 failed");
+ enforce(speedTest3(speed) == speed, "speedTest Global 3 failed");
+ enforce(speedTest4(speed) == speed, "speedTest Global 4 failed");
+ enforce(speedTest5(speed) == speed, "speedTest Global 5 failed");
+ }
+ {
+ auto s = new SpeedClass();
+ auto slow = SpeedClass.speed.slow;
+ auto lightning = SpeedClass.speed.lightning;
+
+ enforce(s.mySpeedtd1 == slow, "mySpeedtd1 1 failed");
+ enforce(cast(int)s.mySpeedtd1 == 10, "mySpeedtd1 2 failed");
+
+ s.mySpeedtd1 = lightning;
+ enforce(s.mySpeedtd1 == lightning, "mySpeedtd1 3 failed");
+ enforce(cast(int)s.mySpeedtd1 == 31, "mySpeedtd1 4 failed");
+ }
+ {
+ enforce(namedanonTest1(namedanon.NamedAnon2) == namedanon.NamedAnon2, "namedanonTest 1 failed");
+ }
+ {
+ auto val = twonames.TwoNames2;
+ enforce(twonamesTest1(val) == val, "twonamesTest 1 failed");
+ enforce(twonamesTest2(val) == val, "twonamesTest 2 failed");
+ enforce(twonamesTest3(val) == val, "twonamesTest 3 failed");
+ }
+ {
+ auto t = new TwoNamesStruct();
+ auto val = TwoNamesStruct.twonames.TwoNamesStruct1;
+ enforce(t.twonamesTest1(val) == val, "twonamesTest 1 failed");
+ enforce(t.twonamesTest2(val) == val, "twonamesTest 2 failed");
+ enforce(t.twonamesTest3(val) == val, "twonamesTest 3 failed");
+ }
+ {
+ auto val = namedanonspace.NamedAnonSpace2;
+ enforce(namedanonspaceTest1(val) == val, "namedanonspaceTest 1 failed");
+ enforce(namedanonspaceTest2(val) == val, "namedanonspaceTest 2 failed");
+ enforce(namedanonspaceTest3(val) == val, "namedanonspaceTest 3 failed");
+ enforce(namedanonspaceTest4(val) == val, "namedanonspaceTest 4 failed");
+ }
+ {
+ auto t = new TemplateClassInt();
+ auto galileo = TemplateClassInt.scientists.galileo;
+ enforce(t.scientistsTest1(galileo) == galileo, "scientistsTest 1 failed");
+ enforce(t.scientistsTest2(galileo) == galileo, "scientistsTest 2 failed");
+ enforce(t.scientistsTest3(galileo) == galileo, "scientistsTest 3 failed");
+ enforce(t.scientistsTest4(galileo) == galileo, "scientistsTest 4 failed");
+ enforce(t.scientistsTest5(galileo) == galileo, "scientistsTest 5 failed");
+ enforce(t.scientistsTest6(galileo) == galileo, "scientistsTest 6 failed");
+ enforce(t.scientistsTest7(galileo) == galileo, "scientistsTest 7 failed");
+ enforce(t.scientistsTest8(galileo) == galileo, "scientistsTest 8 failed");
+ enforce(t.scientistsTest9(galileo) == galileo, "scientistsTest 9 failed");
+// enforce(t.scientistsTestA(galileo) == galileo, "scientistsTest A failed");
+ enforce(t.scientistsTestB(galileo) == galileo, "scientistsTest B failed");
+// enforce(t.scientistsTestC(galileo) == galileo, "scientistsTest C failed");
+ enforce(t.scientistsTestD(galileo) == galileo, "scientistsTest D failed");
+ enforce(t.scientistsTestE(galileo) == galileo, "scientistsTest E failed");
+ enforce(t.scientistsTestF(galileo) == galileo, "scientistsTest F failed");
+ enforce(t.scientistsTestG(galileo) == galileo, "scientistsTest G failed");
+ enforce(t.scientistsTestH(galileo) == galileo, "scientistsTest H failed");
+ enforce(t.scientistsTestI(galileo) == galileo, "scientistsTest I failed");
+ enforce(t.scientistsTestJ(galileo) == galileo, "scientistsTest J failed");
+
+ enforce(scientistsTest1(galileo) == galileo, "scientistsTest Global 1 failed");
+ enforce(scientistsTest2(galileo) == galileo, "scientistsTest Global 2 failed");
+ enforce(scientistsTest3(galileo) == galileo, "scientistsTest Global 3 failed");
+ enforce(scientistsTest4(galileo) == galileo, "scientistsTest Global 4 failed");
+ enforce(scientistsTest5(galileo) == galileo, "scientistsTest Global 5 failed");
+ enforce(scientistsTest6(galileo) == galileo, "scientistsTest Global 6 failed");
+ enforce(scientistsTest7(galileo) == galileo, "scientistsTest Global 7 failed");
+ enforce(scientistsTest8(galileo) == galileo, "scientistsTest Global 8 failed");
+ }
+ {
+ auto t = new TClassInt();
+ auto bell = TClassInt.scientists.bell;
+ auto galileo = TemplateClassInt.scientists.galileo;
+ enforce(t.scientistsNameTest1(bell) == bell, "scientistsNameTest 1 failed");
+ enforce(t.scientistsNameTest2(bell) == bell, "scientistsNameTest 2 failed");
+ enforce(t.scientistsNameTest3(bell) == bell, "scientistsNameTest 3 failed");
+ enforce(t.scientistsNameTest4(bell) == bell, "scientistsNameTest 4 failed");
+ enforce(t.scientistsNameTest5(bell) == bell, "scientistsNameTest 5 failed");
+ enforce(t.scientistsNameTest6(bell) == bell, "scientistsNameTest 6 failed");
+ enforce(t.scientistsNameTest7(bell) == bell, "scientistsNameTest 7 failed");
+ enforce(t.scientistsNameTest8(bell) == bell, "scientistsNameTest 8 failed");
+ enforce(t.scientistsNameTest9(bell) == bell, "scientistsNameTest 9 failed");
+// enforce(t.scientistsNameTestA(bell) == bell, "scientistsNameTest A failed");
+ enforce(t.scientistsNameTestB(bell) == bell, "scientistsNameTest B failed");
+// enforce(t.scientistsNameTestC(bell) == bell, "scientistsNameTest C failed");
+ enforce(t.scientistsNameTestD(bell) == bell, "scientistsNameTest D failed");
+ enforce(t.scientistsNameTestE(bell) == bell, "scientistsNameTest E failed");
+ enforce(t.scientistsNameTestF(bell) == bell, "scientistsNameTest F failed");
+ enforce(t.scientistsNameTestG(bell) == bell, "scientistsNameTest G failed");
+ enforce(t.scientistsNameTestH(bell) == bell, "scientistsNameTest H failed");
+ enforce(t.scientistsNameTestI(bell) == bell, "scientistsNameTest I failed");
+
+ enforce(t.scientistsNameSpaceTest1(bell) == bell, "scientistsNameSpaceTest 1 failed");
+ enforce(t.scientistsNameSpaceTest2(bell) == bell, "scientistsNameSpaceTest 2 failed");
+ enforce(t.scientistsNameSpaceTest3(bell) == bell, "scientistsNameSpaceTest 3 failed");
+ enforce(t.scientistsNameSpaceTest4(bell) == bell, "scientistsNameSpaceTest 4 failed");
+ enforce(t.scientistsNameSpaceTest5(bell) == bell, "scientistsNameSpaceTest 5 failed");
+ enforce(t.scientistsNameSpaceTest6(bell) == bell, "scientistsNameSpaceTest 6 failed");
+ enforce(t.scientistsNameSpaceTest7(bell) == bell, "scientistsNameSpaceTest 7 failed");
+
+ enforce(t.scientistsOtherTest1(galileo) == galileo, "scientistsOtherTest 1 failed");
+ enforce(t.scientistsOtherTest2(galileo) == galileo, "scientistsOtherTest 2 failed");
+ enforce(t.scientistsOtherTest3(galileo) == galileo, "scientistsOtherTest 3 failed");
+ enforce(t.scientistsOtherTest4(galileo) == galileo, "scientistsOtherTest 4 failed");
+ enforce(t.scientistsOtherTest5(galileo) == galileo, "scientistsOtherTest 5 failed");
+ enforce(t.scientistsOtherTest6(galileo) == galileo, "scientistsOtherTest 6 failed");
+ enforce(t.scientistsOtherTest7(galileo) == galileo, "scientistsOtherTest 7 failed");
+
+ enforce(scientistsNameTest1(bell) == bell, "scientistsNameTest Global 1 failed");
+ enforce(scientistsNameTest2(bell) == bell, "scientistsNameTest Global 2 failed");
+ enforce(scientistsNameTest3(bell) == bell, "scientistsNameTest Global 3 failed");
+ enforce(scientistsNameTest4(bell) == bell, "scientistsNameTest Global 4 failed");
+ enforce(scientistsNameTest5(bell) == bell, "scientistsNameTest Global 5 failed");
+ enforce(scientistsNameTest6(bell) == bell, "scientistsNameTest Global 6 failed");
+ enforce(scientistsNameTest7(bell) == bell, "scientistsNameTest Global 7 failed");
+
+ enforce(scientistsNameSpaceTest1(bell) == bell, "scientistsNameSpaceTest Global 1 failed");
+ enforce(scientistsNameSpaceTest2(bell) == bell, "scientistsNameSpaceTest Global 2 failed");
+ enforce(scientistsNameSpaceTest3(bell) == bell, "scientistsNameSpaceTest Global 3 failed");
+ enforce(scientistsNameSpaceTest4(bell) == bell, "scientistsNameSpaceTest Global 4 failed");
+ enforce(scientistsNameSpaceTest5(bell) == bell, "scientistsNameSpaceTest Global 5 failed");
+ enforce(scientistsNameSpaceTest6(bell) == bell, "scientistsNameSpaceTest Global 6 failed");
+ enforce(scientistsNameSpaceTest7(bell) == bell, "scientistsNameSpaceTest Global 7 failed");
+
+ enforce(scientistsNameSpaceTest8(bell) == bell, "scientistsNameSpaceTest Global 8 failed");
+ enforce(scientistsNameSpaceTest9(bell) == bell, "scientistsNameSpaceTest Global 9 failed");
+ enforce(scientistsNameSpaceTestA(bell) == bell, "scientistsNameSpaceTest Global A failed");
+ enforce(scientistsNameSpaceTestB(bell) == bell, "scientistsNameSpaceTest Global B failed");
+ enforce(scientistsNameSpaceTestC(bell) == bell, "scientistsNameSpaceTest Global C failed");
+ enforce(scientistsNameSpaceTestD(bell) == bell, "scientistsNameSpaceTest Global D failed");
+ enforce(scientistsNameSpaceTestE(bell) == bell, "scientistsNameSpaceTest Global E failed");
+
+ enforce(scientistsNameSpaceTestF(bell) == bell, "scientistsNameSpaceTest Global F failed");
+ enforce(scientistsNameSpaceTestG(bell) == bell, "scientistsNameSpaceTest Global G failed");
+ enforce(scientistsNameSpaceTestH(bell) == bell, "scientistsNameSpaceTest Global H failed");
+ enforce(scientistsNameSpaceTestI(bell) == bell, "scientistsNameSpaceTest Global I failed");
+ enforce(scientistsNameSpaceTestJ(bell) == bell, "scientistsNameSpaceTest Global J failed");
+ enforce(scientistsNameSpaceTestK(bell) == bell, "scientistsNameSpaceTest Global K failed");
+ enforce(scientistsNameSpaceTestL(bell) == bell, "scientistsNameSpaceTest Global L failed");
+ }
+ {
+ auto val = newname.argh;
+ enforce(renameTest1(val) == val, "renameTest Global 1 failed");
+ enforce(renameTest2(val) == val, "renameTest Global 2 failed");
+ }
+ {
+ auto n = new NewNameStruct();
+ enforce(n.renameTest1(NewNameStruct.enumeration.bang) == NewNameStruct.enumeration.bang, "renameTest 1 failed");
+ enforce(n.renameTest2(NewNameStruct.enumeration.bang) == NewNameStruct.enumeration.bang, "renameTest 2 failed");
+ enforce(n.renameTest3(NewNameStruct.simplerenamed.simple1) == NewNameStruct.simplerenamed.simple1, "renameTest 3 failed");
+ enforce(n.renameTest4(NewNameStruct.doublenamerenamed.doublename1) == NewNameStruct.doublenamerenamed.doublename1, "renameTest 4 failed");
+ enforce(n.renameTest5(NewNameStruct.doublenamerenamed.doublename1) == NewNameStruct.doublenamerenamed.doublename1, "renameTest 5 failed");
+ enforce(n.renameTest6(NewNameStruct.singlenamerenamed.singlename1) == NewNameStruct.singlenamerenamed.singlename1, "renameTest 6 failed");
+ }
+ {
+ enforce(renameTest3(NewNameStruct.enumeration.bang) == NewNameStruct.enumeration.bang, "renameTest Global 3 failed");
+ enforce(renameTest4(NewNameStruct.simplerenamed.simple1) == NewNameStruct.simplerenamed.simple1, "renameTest Global 4 failed");
+ enforce(renameTest5(NewNameStruct.doublenamerenamed.doublename1) == NewNameStruct.doublenamerenamed.doublename1, "renameTest Global 5 failed");
+ enforce(renameTest6(NewNameStruct.doublenamerenamed.doublename1) == NewNameStruct.doublenamerenamed.doublename1, "renameTest Global 6 failed");
+ enforce(renameTest7(NewNameStruct.singlenamerenamed.singlename1) == NewNameStruct.singlenamerenamed.singlename1, "renameTest Global 7 failed");
+ }
+ {
+ auto t = new TreesClass();
+ auto pine = TreesClass.trees.pine;
+
+ enforce(t.treesTest1(pine) == pine, "treesTest 1 failed");
+ enforce(t.treesTest2(pine) == pine, "treesTest 2 failed");
+ enforce(t.treesTest3(pine) == pine, "treesTest 3 failed");
+ enforce(t.treesTest4(pine) == pine, "treesTest 4 failed");
+ enforce(t.treesTest5(pine) == pine, "treesTest 5 failed");
+ enforce(t.treesTest6(pine) == pine, "treesTest 6 failed");
+ enforce(t.treesTest7(pine) == pine, "treesTest 7 failed");
+ enforce(t.treesTest8(pine) == pine, "treesTest 8 failed");
+ enforce(t.treesTest9(pine) == pine, "treesTest 9 failed");
+ enforce(t.treesTestA(pine) == pine, "treesTest A failed");
+ enforce(t.treesTestB(pine) == pine, "treesTest B failed");
+ enforce(t.treesTestC(pine) == pine, "treesTest C failed");
+ enforce(t.treesTestD(pine) == pine, "treesTest D failed");
+ enforce(t.treesTestE(pine) == pine, "treesTest E failed");
+ enforce(t.treesTestF(pine) == pine, "treesTest F failed");
+ enforce(t.treesTestG(pine) == pine, "treesTest G failed");
+ enforce(t.treesTestH(pine) == pine, "treesTest H failed");
+ enforce(t.treesTestI(pine) == pine, "treesTest I failed");
+ enforce(t.treesTestJ(pine) == pine, "treesTest J failed");
+ enforce(t.treesTestK(pine) == pine, "treesTest K failed");
+ enforce(t.treesTestL(pine) == pine, "treesTest L failed");
+ enforce(t.treesTestM(pine) == pine, "treesTest M failed");
+ enforce(t.treesTestN(pine) == pine, "treesTest N failed");
+ enforce(t.treesTestO(pine) == pine, "treesTest O failed");
+
+ enforce(treesTest1(pine) == pine, "treesTest Global 1 failed");
+ enforce(treesTest2(pine) == pine, "treesTest Global 2 failed");
+ enforce(treesTest3(pine) == pine, "treesTest Global 3 failed");
+ enforce(treesTest4(pine) == pine, "treesTest Global 4 failed");
+ enforce(treesTest5(pine) == pine, "treesTest Global 5 failed");
+ enforce(treesTest6(pine) == pine, "treesTest Global 6 failed");
+ enforce(treesTest7(pine) == pine, "treesTest Global 7 failed");
+ enforce(treesTest8(pine) == pine, "treesTest Global 8 failed");
+ enforce(treesTest9(pine) == pine, "treesTest Global 9 failed");
+ enforce(treesTestA(pine) == pine, "treesTest Global A failed");
+ enforce(treesTestB(pine) == pine, "treesTest Global B failed");
+ enforce(treesTestC(pine) == pine, "treesTest Global C failed");
+ enforce(treesTestD(pine) == pine, "treesTest Global D failed");
+ enforce(treesTestE(pine) == pine, "treesTest Global E failed");
+ enforce(treesTestF(pine) == pine, "treesTest Global F failed");
+ enforce(treesTestG(pine) == pine, "treesTest Global G failed");
+ enforce(treesTestH(pine) == pine, "treesTest Global H failed");
+ enforce(treesTestI(pine) == pine, "treesTest Global I failed");
+ enforce(treesTestJ(pine) == pine, "treesTest Global J failed");
+ enforce(treesTestK(pine) == pine, "treesTest Global K failed");
+ enforce(treesTestL(pine) == pine, "treesTest Global L failed");
+ enforce(treesTestM(pine) == pine, "treesTest Global M failed");
+// enforce(treesTestN(pine) == pine, "treesTest Global N failed");
+ enforce(treesTestO(pine) == pine, "treesTest Global O failed");
+ enforce(treesTestP(pine) == pine, "treesTest Global P failed");
+ enforce(treesTestQ(pine) == pine, "treesTest Global Q failed");
+ enforce(treesTestR(pine) == pine, "treesTest Global R failed");
+ }
+ {
+ auto h = new HairStruct();
+ auto ginger = HairStruct.hair.ginger;
+
+ enforce(h.hairTest1(ginger) == ginger, "hairTest 1 failed");
+ enforce(h.hairTest2(ginger) == ginger, "hairTest 2 failed");
+ enforce(h.hairTest3(ginger) == ginger, "hairTest 3 failed");
+ enforce(h.hairTest4(ginger) == ginger, "hairTest 4 failed");
+ enforce(h.hairTest5(ginger) == ginger, "hairTest 5 failed");
+ enforce(h.hairTest6(ginger) == ginger, "hairTest 6 failed");
+ enforce(h.hairTest7(ginger) == ginger, "hairTest 7 failed");
+ enforce(h.hairTest8(ginger) == ginger, "hairTest 8 failed");
+ enforce(h.hairTest9(ginger) == ginger, "hairTest 9 failed");
+ enforce(h.hairTestA(ginger) == ginger, "hairTest A failed");
+ enforce(h.hairTestB(ginger) == ginger, "hairTest B failed");
+
+ auto red = colour.red;
+ enforce(h.colourTest1(red) == red, "colourTest HairStruct 1 failed");
+ enforce(h.colourTest2(red) == red, "colourTest HairStruct 2 failed");
+ enforce(h.namedanonTest1(namedanon.NamedAnon2) == namedanon.NamedAnon2, "namedanonTest HairStruct 1 failed");
+ enforce(h.namedanonspaceTest1(namedanonspace.NamedAnonSpace2) == namedanonspace.NamedAnonSpace2, "namedanonspaceTest HairStruct 1 failed");
+
+ auto fir = TreesClass.trees.fir;
+ enforce(h.treesGlobalTest1(fir) == fir, "treesGlobalTest1 HairStruct 1 failed");
+ enforce(h.treesGlobalTest2(fir) == fir, "treesGlobalTest1 HairStruct 2 failed");
+ enforce(h.treesGlobalTest3(fir) == fir, "treesGlobalTest1 HairStruct 3 failed");
+ enforce(h.treesGlobalTest4(fir) == fir, "treesGlobalTest1 HairStruct 4 failed");
+ }
+ {
+ auto blonde = HairStruct.hair.blonde;
+ enforce(hairTest1(blonde) == blonde, "hairTest Global 1 failed");
+ enforce(hairTest2(blonde) == blonde, "hairTest Global 2 failed");
+ enforce(hairTest3(blonde) == blonde, "hairTest Global 3 failed");
+ enforce(hairTest4(blonde) == blonde, "hairTest Global 4 failed");
+ enforce(hairTest5(blonde) == blonde, "hairTest Global 5 failed");
+ enforce(hairTest6(blonde) == blonde, "hairTest Global 6 failed");
+ enforce(hairTest7(blonde) == blonde, "hairTest Global 7 failed");
+ enforce(hairTest8(blonde) == blonde, "hairTest Global 8 failed");
+ enforce(hairTest9(blonde) == blonde, "hairTest Global 9 failed");
+ enforce(hairTestA(blonde) == blonde, "hairTest Global A failed");
+ enforce(hairTestB(blonde) == blonde, "hairTest Global B failed");
+ enforce(hairTestC(blonde) == blonde, "hairTest Global C failed");
+
+ enforce(hairTestA1(blonde) == blonde, "hairTest Global A1 failed");
+ enforce(hairTestA2(blonde) == blonde, "hairTest Global A2 failed");
+ enforce(hairTestA3(blonde) == blonde, "hairTest Global A3 failed");
+ enforce(hairTestA4(blonde) == blonde, "hairTest Global A4 failed");
+ enforce(hairTestA5(blonde) == blonde, "hairTest Global A5 failed");
+ enforce(hairTestA6(blonde) == blonde, "hairTest Global A6 failed");
+ enforce(hairTestA7(blonde) == blonde, "hairTest Global A7 failed");
+ enforce(hairTestA8(blonde) == blonde, "hairTest Global A8 failed");
+ enforce(hairTestA9(blonde) == blonde, "hairTest Global A9 failed");
+ enforce(hairTestAA(blonde) == blonde, "hairTest Global AA failed");
+ enforce(hairTestAB(blonde) == blonde, "hairTest Global AB failed");
+ enforce(hairTestAC(blonde) == blonde, "hairTest Global AC failed");
+
+ enforce(hairTestB1(blonde) == blonde, "hairTest Global B1 failed");
+ enforce(hairTestB2(blonde) == blonde, "hairTest Global B2 failed");
+ enforce(hairTestB3(blonde) == blonde, "hairTest Global B3 failed");
+ enforce(hairTestB4(blonde) == blonde, "hairTest Global B4 failed");
+ enforce(hairTestB5(blonde) == blonde, "hairTest Global B5 failed");
+ enforce(hairTestB6(blonde) == blonde, "hairTest Global B6 failed");
+ enforce(hairTestB7(blonde) == blonde, "hairTest Global B7 failed");
+ enforce(hairTestB8(blonde) == blonde, "hairTest Global B8 failed");
+ enforce(hairTestB9(blonde) == blonde, "hairTest Global B9 failed");
+ enforce(hairTestBA(blonde) == blonde, "hairTest Global BA failed");
+ enforce(hairTestBB(blonde) == blonde, "hairTest Global BB failed");
+ enforce(hairTestBC(blonde) == blonde, "hairTest Global BC failed");
+
+ enforce(hairTestC1(blonde) == blonde, "hairTest Global C1 failed");
+ enforce(hairTestC2(blonde) == blonde, "hairTest Global C2 failed");
+ enforce(hairTestC3(blonde) == blonde, "hairTest Global C3 failed");
+ enforce(hairTestC4(blonde) == blonde, "hairTest Global C4 failed");
+ enforce(hairTestC5(blonde) == blonde, "hairTest Global C5 failed");
+ enforce(hairTestC6(blonde) == blonde, "hairTest Global C6 failed");
+ enforce(hairTestC7(blonde) == blonde, "hairTest Global C7 failed");
+ enforce(hairTestC8(blonde) == blonde, "hairTest Global C8 failed");
+ enforce(hairTestC9(blonde) == blonde, "hairTest Global C9 failed");
+ enforce(hairTestCA(blonde) == blonde, "hairTest Global CA failed");
+ enforce(hairTestCB(blonde) == blonde, "hairTest Global CB failed");
+ enforce(hairTestCC(blonde) == blonde, "hairTest Global CC failed");
+ }
+ {
+ auto f = new FirStruct();
+ auto blonde = HairStruct.hair.blonde;
+
+ enforce(f.hairTestFir1(blonde) == blonde, "hairTestFir 1 failed");
+ enforce(f.hairTestFir2(blonde) == blonde, "hairTestFir 2 failed");
+ enforce(f.hairTestFir3(blonde) == blonde, "hairTestFir 3 failed");
+ enforce(f.hairTestFir4(blonde) == blonde, "hairTestFir 4 failed");
+ enforce(f.hairTestFir5(blonde) == blonde, "hairTestFir 5 failed");
+ enforce(f.hairTestFir6(blonde) == blonde, "hairTestFir 6 failed");
+ enforce(f.hairTestFir7(blonde) == blonde, "hairTestFir 7 failed");
+ enforce(f.hairTestFir8(blonde) == blonde, "hairTestFir 8 failed");
+ enforce(f.hairTestFir9(blonde) == blonde, "hairTestFir 9 failed");
+ enforce(f.hairTestFirA(blonde) == blonde, "hairTestFir A failed");
+ }
+ {
+ GlobalInstance = globalinstance2;
+ enforce(GlobalInstance == globalinstance2, "GlobalInstance 1 failed");
+
+ auto i = new Instances();
+ i.MemberInstance = Instances.memberinstance3;
+ enforce(i.MemberInstance == Instances.memberinstance3, "MemberInstance 1 failed");
+ }
+ // ignore enum item tests start
+ {
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero) == 0, "ignoreATest 0 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_three) == 3, "ignoreATest 3 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten) == 10, "ignoreATest 10 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven) == 11, "ignoreATest 11 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen) == 13, "ignoreATest 13 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen) == 14, "ignoreATest 14 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty) == 20, "ignoreATest 20 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty) == 30, "ignoreATest 30 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two) == 32, "ignoreATest 32 failed");
+ enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three) == 33, "ignoreATest 33 failed");
+ }
+ {
+ enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven) == 11, "ignoreBTest 11 failed");
+ enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve) == 12, "ignoreBTest 12 failed");
+ enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one) == 31, "ignoreBTest 31 failed");
+ enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two) == 32, "ignoreBTest 32 failed");
+ enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one) == 41, "ignoreBTest 41 failed");
+ enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two) == 42, "ignoreBTest 42 failed");
+ }
+ {
+ enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten), "ignoreCTest 10 failed");
+ enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve) == 12, "ignoreCTest 12 failed");
+ enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty) == 30, "ignoreCTest 30 failed");
+ enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two) == 32, "ignoreCTest 32 failed");
+ enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty) == 40, "ignoreCTest 40 failed");
+ enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two) == 42, "ignoreCTest 42 failed");
+ }
+ {
+ enforce(cast(int)ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one) == 21, "ignoreDTest 21 failed");
+ enforce(cast(int)ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two) == 22, "ignoreDTest 22 failed");
+ }
+ {
+ enforce(cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero) == 0, "ignoreETest 0 failed");
+ enforce(cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one) == 21, "ignoreETest 21 failed");
+ enforce(cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two) == 22, "ignoreETest 22 failed");
+ }
+ // ignore enum item tests end
+ {
+ enforce(cast(int)repeatTest(repeat.one) == 1, "repeatTest 1 failed");
+ enforce(cast(int)repeatTest(repeat.initial) == 1, "repeatTest 2 failed");
+ enforce(cast(int)repeatTest(repeat.two) == 2, "repeatTest 3 failed");
+ enforce(cast(int)repeatTest(repeat.three) == 3, "repeatTest 4 failed");
+ enforce(cast(int)repeatTest(repeat.llast) == 3, "repeatTest 5 failed");
+ enforce(cast(int)repeatTest(repeat.end) == 3, "repeatTest 6 failed");
+ }
+}
diff --git a/Examples/test-suite/d/inherit_target_language_runme.1.d b/Examples/test-suite/d/inherit_target_language_runme.1.d
new file mode 100644
index 000000000..8a13caca4
--- /dev/null
+++ b/Examples/test-suite/d/inherit_target_language_runme.1.d
@@ -0,0 +1,29 @@
+module inherit_target_language_runme;
+
+import inherit_target_language.BaseX;
+import inherit_target_language.Derived1;
+import inherit_target_language.Derived2;
+import inherit_target_language.DerivedX;
+import inherit_target_language.MultipleDerived1;
+import inherit_target_language.MultipleDerived2;
+import inherit_target_language.MultipleDerived3;
+import inherit_target_language.MultipleDerived4;
+
+void main() {
+ (new Derived1()).targetLanguageBaseMethod();
+ (new Derived2()).targetLanguageBaseMethod();
+
+ (new MultipleDerived1()).targetLanguageBaseMethod();
+ (new MultipleDerived2()).targetLanguageBaseMethod();
+ (new MultipleDerived3()).f();
+ (new MultipleDerived4()).g();
+
+ auto baseX = new BaseX();
+ baseX.basex();
+ baseX.targetLanguageBase2Method();
+
+ auto derivedX = new DerivedX();
+ derivedX.basex();
+ derivedX.derivedx();
+ derivedX.targetLanguageBase2Method();
+}
diff --git a/Examples/test-suite/d/inherit_target_language_runme.2.d b/Examples/test-suite/d/inherit_target_language_runme.2.d
new file mode 100644
index 000000000..8a13caca4
--- /dev/null
+++ b/Examples/test-suite/d/inherit_target_language_runme.2.d
@@ -0,0 +1,29 @@
+module inherit_target_language_runme;
+
+import inherit_target_language.BaseX;
+import inherit_target_language.Derived1;
+import inherit_target_language.Derived2;
+import inherit_target_language.DerivedX;
+import inherit_target_language.MultipleDerived1;
+import inherit_target_language.MultipleDerived2;
+import inherit_target_language.MultipleDerived3;
+import inherit_target_language.MultipleDerived4;
+
+void main() {
+ (new Derived1()).targetLanguageBaseMethod();
+ (new Derived2()).targetLanguageBaseMethod();
+
+ (new MultipleDerived1()).targetLanguageBaseMethod();
+ (new MultipleDerived2()).targetLanguageBaseMethod();
+ (new MultipleDerived3()).f();
+ (new MultipleDerived4()).g();
+
+ auto baseX = new BaseX();
+ baseX.basex();
+ baseX.targetLanguageBase2Method();
+
+ auto derivedX = new DerivedX();
+ derivedX.basex();
+ derivedX.derivedx();
+ derivedX.targetLanguageBase2Method();
+}
diff --git a/Examples/test-suite/d/li_attribute_runme.1.d b/Examples/test-suite/d/li_attribute_runme.1.d
new file mode 100644
index 000000000..ada3ed8d8
--- /dev/null
+++ b/Examples/test-suite/d/li_attribute_runme.1.d
@@ -0,0 +1,75 @@
+module li_attribute_runme;
+
+import li_attribute.A;
+import li_attribute.B;
+import li_attribute.MyClass;
+import li_attribute.MyClassVal;
+import li_attribute.MyStringyClass;
+import li_attribute.MyFoo;
+import li_attribute.Param_i;
+
+void main() {
+ auto aa = new A(1,2,3);
+
+ if (aa.a != 1)
+ throw new Exception("error");
+ aa.a = 3;
+ if (aa.a != 3)
+ throw new Exception("error");
+
+ if (aa.b != 2)
+ throw new Exception("error");
+ aa.b = 5;
+ if (aa.b != 5)
+ throw new Exception("error");
+
+ if (aa.d != aa.b)
+ throw new Exception("error");
+
+ if (aa.c != 3)
+ throw new Exception("error");
+
+ auto pi = new Param_i(7);
+ if (pi.value != 7)
+ throw new Exception("error");
+
+ pi.value=3;
+ if (pi.value != 3)
+ throw new Exception("error");
+
+ auto b = new B(aa);
+ if (b.a.c != 3)
+ throw new Exception("error");
+
+ // class/struct attribute with get/set methods using return/pass by reference
+ auto myFoo = new MyFoo();
+ myFoo.x = 8;
+ auto myClass = new MyClass();
+ myClass.Foo = myFoo;
+ if (myClass.Foo.x != 8)
+ throw new Exception("error");
+
+ // class/struct attribute with get/set methods using return/pass by value
+ auto myClassVal = new MyClassVal();
+ if (myClassVal.ReadWriteFoo.x != -1)
+ throw new Exception("error");
+ if (myClassVal.ReadOnlyFoo.x != -1)
+ throw new Exception("error");
+ myClassVal.ReadWriteFoo = myFoo;
+ if (myClassVal.ReadWriteFoo.x != 8)
+ throw new Exception("error");
+ if (myClassVal.ReadOnlyFoo.x != 8)
+ throw new Exception("error");
+
+ // string attribute with get/set methods using return/pass by value
+ auto myStringClass = new MyStringyClass("initial string");
+ if (myStringClass.ReadWriteString != "initial string")
+ throw new Exception("error");
+ if (myStringClass.ReadOnlyString != "initial string")
+ throw new Exception("error");
+ myStringClass.ReadWriteString = "changed string";
+ if (myStringClass.ReadWriteString != "changed string")
+ throw new Exception("error");
+ if (myStringClass.ReadOnlyString != "changed string")
+ throw new Exception("error");
+}
diff --git a/Examples/test-suite/d/li_attribute_runme.2.d b/Examples/test-suite/d/li_attribute_runme.2.d
new file mode 100644
index 000000000..4e0ea58ff
--- /dev/null
+++ b/Examples/test-suite/d/li_attribute_runme.2.d
@@ -0,0 +1,58 @@
+module li_attribute_runme;
+
+import std.exception;
+import li_attribute.A;
+import li_attribute.B;
+import li_attribute.MyClass;
+import li_attribute.MyClassVal;
+import li_attribute.MyStringyClass;
+import li_attribute.MyFoo;
+import li_attribute.Param_i;
+
+void main() {
+ auto aa = new A(1,2,3);
+
+ enforce(aa.a == 1);
+ aa.a = 3;
+ enforce(aa.a == 3);
+
+ enforce(aa.b == 2);
+ aa.b = 5;
+ enforce(aa.b == 5);
+
+ enforce(aa.d == aa.b);
+
+ enforce(aa.c == 3);
+
+ auto pi = new Param_i(7);
+ enforce(pi.value == 7);
+
+ pi.value=3;
+ enforce(pi.value == 3);
+
+ auto b = new B(aa);
+ enforce(b.a.c == 3);
+
+ // class/struct attribute with get/set methods using return/pass by reference
+ auto myFoo = new MyFoo();
+ myFoo.x = 8;
+ auto myClass = new MyClass();
+ myClass.Foo = myFoo;
+ enforce(myClass.Foo.x == 8);
+
+ // class/struct attribute with get/set methods using return/pass by value
+ auto myClassVal = new MyClassVal();
+ enforce(myClassVal.ReadWriteFoo.x == -1);
+ enforce(myClassVal.ReadOnlyFoo.x == -1);
+ myClassVal.ReadWriteFoo = myFoo;
+ enforce(myClassVal.ReadWriteFoo.x == 8);
+ enforce(myClassVal.ReadOnlyFoo.x == 8);
+
+ // string attribute with get/set methods using return/pass by value
+ auto myStringClass = new MyStringyClass("initial string");
+ enforce(myStringClass.ReadWriteString == "initial string");
+ enforce(myStringClass.ReadOnlyString == "initial string");
+ myStringClass.ReadWriteString = "changed string";
+ enforce(myStringClass.ReadWriteString == "changed string");
+ enforce(myStringClass.ReadOnlyString == "changed string");
+}
diff --git a/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d b/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d
new file mode 100644
index 000000000..098570b95
--- /dev/null
+++ b/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d
@@ -0,0 +1,21 @@
+module li_boost_shared_ptr_runme_bits;
+
+import li_boost_shared_ptr_bits.li_boost_shared_ptr_bits;
+import li_boost_shared_ptr_bits.HiddenDestructor;
+import li_boost_shared_ptr_bits.IntHolder;
+import li_boost_shared_ptr_bits.VectorIntHolder;
+
+void main() {
+ auto v = new VectorIntHolder();
+ v ~= new IntHolder(11);
+ v ~= new IntHolder(22);
+ v ~= new IntHolder(33);
+
+ if (sum(v) != 66) {
+ throw new Exception("sum is wrong");
+ }
+
+ {
+ scope hidden = HiddenDestructor.create();
+ }
+}
diff --git a/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d b/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d
new file mode 100644
index 000000000..4891b7673
--- /dev/null
+++ b/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d
@@ -0,0 +1,19 @@
+module li_boost_shared_ptr_runme_bits;
+
+import std.exception;
+import li_boost_shared_ptr_bits.li_boost_shared_ptr_bits;
+import li_boost_shared_ptr_bits.HiddenDestructor;
+import li_boost_shared_ptr_bits.IntHolder;
+import li_boost_shared_ptr_bits.VectorIntHolder;
+
+void main() {
+ auto v = new VectorIntHolder();
+ v ~= new IntHolder(11);
+ v ~= new IntHolder(22);
+ v ~= new IntHolder(33);
+ enforce(sum(v) == 66, "sum is wrong");
+
+ {
+ scope hidden = HiddenDestructor.create();
+ }
+}
diff --git a/Examples/test-suite/d/li_boost_shared_ptr_runme.1.d b/Examples/test-suite/d/li_boost_shared_ptr_runme.1.d
new file mode 100644
index 000000000..ed55cd302
--- /dev/null
+++ b/Examples/test-suite/d/li_boost_shared_ptr_runme.1.d
@@ -0,0 +1,604 @@
+module li_boost_shared_ptr_runme;
+
+import tango.io.Stdout;
+import tango.core.Exception;
+import tango.core.Memory;
+import tango.core.Thread;
+import tango.text.convert.Integer;
+import li_boost_shared_ptr.li_boost_shared_ptr;
+import li_boost_shared_ptr.Klass;
+import li_boost_shared_ptr.KlassDerived;
+import li_boost_shared_ptr.Klass3rdDerived;
+import li_boost_shared_ptr.MemberVariables;
+import li_boost_shared_ptr.PairIntDouble;
+
+// Debugging flag
+const bool TRACE = false;
+
+void main() {
+ if (TRACE)
+ Stdout("---> STARTED <---").newline;
+
+ debug_shared=TRACE;
+
+ // Change loop count to run for a long time to monitor memory
+ const int LOOP_COUNT = 1; // 50000;
+ for (int i = 0; i < LOOP_COUNT; ++i) {
+ runTest();
+ GC.collect();
+ }
+
+ if (TRACE)
+ Stdout("---> NEARLY FINISHED <---").newline;
+
+ // Try to get the GC to collect everything not referenced anymore.
+ int countdown = 100;
+ while (--countdown) {
+ GC.collect();
+ if (Klass.getTotal_count() == 1)
+ break;
+ Thread.sleep(0.01);
+ }
+
+ // A single remaining instance expected: the global variable (GlobalValue).
+ if (Klass.getTotal_count() != 1)
+ throw new Exception("Klass.total_count=" ~ toString(Klass.getTotal_count()));
+
+ // A single remaining instance expected: the global variable (GlobalSmartValue).
+ int wrapper_count = shared_ptr_wrapper_count();
+ if (wrapper_count != NOT_COUNTING)
+ if (wrapper_count != 1)
+ throw new Exception("shared_ptr wrapper count=" ~ toString(wrapper_count));
+
+ if (TRACE)
+ Stdout("---> FINISHED <---").newline;
+}
+
+void runTest() {
+ // simple shared_ptr usage - created in C++
+ {
+ auto k = new Klass("me oh my");
+ char[] val = k.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(1, k);
+ }
+
+ // simple shared_ptr usage - not created in C++
+ {
+ auto k = factorycreate();
+ char[] val = k.getValue();
+ verifyValue("factorycreate", val);
+ verifyCount(1, k);
+ }
+
+ // pass by shared_ptr
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointertest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerpointertest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerreftest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr pointer reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerpointerreftest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointerpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by value
+ {
+ auto k = new Klass("me oh my");
+ auto kret = valuetest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my valuetest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = pointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my pointertest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = reftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my reftest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = pointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my pointerreftest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // null tests
+ {
+ Klass k = null;
+
+ // TODO: add in const versions too
+ if (smartpointertest(k) !is null)
+ throw new Exception("return was not null");
+
+ if (smartpointerpointertest(k) !is null)
+ throw new Exception("return was not null");
+
+ if (smartpointerreftest(k) !is null)
+ throw new Exception("return was not null");
+
+ if (smartpointerpointerreftest(k) !is null)
+ throw new Exception("return was not null");
+
+ if (nullsmartpointerpointertest(null) != "null pointer")
+ throw new Exception("not null smartpointer pointer");
+
+ try { valuetest(k); throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+
+ if (pointertest(k) !is null)
+ throw new Exception("return was not null");
+
+ try { reftest(k); throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+ }
+
+ // $owner
+ {
+ auto k = pointerownertest();
+ char[] val = k.getValue();
+ verifyValue("pointerownertest", val);
+ verifyCount(1, k);
+ }
+ {
+ auto k = smartpointerpointerownertest();
+ char[] val = k.getValue();
+ verifyValue("smartpointerpointerownertest", val);
+ verifyCount(1, k);
+ }
+
+ ////////////////////////////////// Derived classes ////////////////////////////////////////
+ // derived pass by shared_ptr
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrtest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrtest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr pointer
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrpointertest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrreftest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr pointer ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by pointer
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedpointertest-Derived", val);
+ verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
+ verifyCount(2, kret);
+ }
+ // derived pass by ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedreftest-Derived", val);
+ verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
+ verifyCount(2, kret);
+ }
+
+ ////////////////////////////////// Derived and base class mixed ////////////////////////////////////////
+ // pass by shared_ptr (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointertest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr pointer (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerpointertest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr reference (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerreftest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr pointer reference (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerpointerreftest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by value (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = valuetest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my valuetest", val); // note slicing
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = pointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my pointertest-Derived", val);
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // pass by ref (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = reftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my reftest-Derived", val);
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // 3rd derived class
+ {
+ auto k = new Klass3rdDerived("me oh my");
+ char[] val = k.getValue();
+ verifyValue("me oh my-3rdDerived", val);
+ verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values
+ val = test3rdupcast(k);
+ verifyValue("me oh my-3rdDerived", val);
+ verifyCount(3, k);
+ }
+
+ ////////////////////////////////// Member variables ////////////////////////////////////////
+ // smart pointer by value
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member value");
+ m.SmartMemberValue = k;
+ char[] val = k.getValue();
+ verifyValue("smart member value", val);
+ verifyCount(2, k);
+
+ auto kmember = m.SmartMemberValue;
+ val = kmember.getValue();
+ verifyValue("smart member value", val);
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+
+ delete m;
+
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+ }
+ // smart pointer by pointer
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member pointer");
+ m.SmartMemberPointer = k;
+ char[] val = k.getValue();
+ verifyValue("smart member pointer", val);
+ verifyCount(1, k);
+
+ auto kmember = m.SmartMemberPointer;
+ val = kmember.getValue();
+ verifyValue("smart member pointer", val);
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+
+ delete m;
+
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+ }
+ // smart pointer by reference
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member reference");
+ m.SmartMemberReference = k;
+ char[] val = k.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(2, k);
+
+ auto kmember = m.SmartMemberReference;
+ val = kmember.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+
+ // The C++ reference refers to SmartMemberValue...
+ auto kmemberVal = m.SmartMemberValue;
+ val = kmember.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(4, kmemberVal);
+ verifyCount(4, kmember);
+ verifyCount(4, k);
+
+ delete m;
+
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+ }
+ // plain by value
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member value");
+ m.MemberValue = k;
+ char[] val = k.getValue();
+ verifyValue("plain member value", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberValue;
+ val = kmember.getValue();
+ verifyValue("plain member value", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+ // plain by pointer
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member pointer");
+ m.MemberPointer = k;
+ char[] val = k.getValue();
+ verifyValue("plain member pointer", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberPointer;
+ val = kmember.getValue();
+ verifyValue("plain member pointer", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+ // plain by reference
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member reference");
+ m.MemberReference = k;
+ char[] val = k.getValue();
+ verifyValue("plain member reference", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberReference;
+ val = kmember.getValue();
+ verifyValue("plain member reference", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+
+ // null member variables
+ {
+ auto m = new MemberVariables();
+
+ // shared_ptr by value
+ auto k = m.SmartMemberValue;
+ if (k !is null)
+ throw new Exception("expected null");
+ m.SmartMemberValue = null;
+ k = m.SmartMemberValue;
+ if (k !is null)
+ throw new Exception("expected null");
+ verifyCount(0, k);
+
+ // plain by value
+ try { m.MemberValue = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+ }
+
+ ////////////////////////////////// Global variables ////////////////////////////////////////
+ // smart pointer
+ {
+ auto kglobal = GlobalSmartValue;
+ if (kglobal !is null)
+ throw new Exception("expected null");
+
+ auto k = new Klass("smart global value");
+ GlobalSmartValue = k;
+ verifyCount(2, k);
+
+ kglobal = GlobalSmartValue;
+ char[] val = kglobal.getValue();
+ verifyValue("smart global value", val);
+ verifyCount(3, kglobal);
+ verifyCount(3, k);
+ verifyValue("smart global value", GlobalSmartValue.getValue());
+ GlobalSmartValue = null;
+ }
+ // plain value
+ {
+ Klass kglobal;
+
+ auto k = new Klass("global value");
+ GlobalValue = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalValue;
+ char[] val = kglobal.getValue();
+ verifyValue("global value", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+ verifyValue("global value", GlobalValue.getValue());
+
+ try { GlobalValue = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+ }
+ // plain pointer
+ {
+ auto kglobal = GlobalPointer;
+ if (kglobal !is null)
+ throw new Exception("expected null");
+
+ auto k = new Klass("global pointer");
+ GlobalPointer = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalPointer;
+ char[] val = kglobal.getValue();
+ verifyValue("global pointer", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+ GlobalPointer = null;
+ }
+ // plain reference
+ {
+ Klass kglobal;
+
+ auto k = new Klass("global reference");
+ GlobalReference = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalReference;
+ char[] val = kglobal.getValue();
+ verifyValue("global reference", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+
+ try { GlobalReference = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+ }
+
+ ////////////////////////////////// Templates ////////////////////////////////////////
+ {
+ PairIntDouble pid = new PairIntDouble(10, 20.2);
+ if (pid.baseVal1 != 20 || pid.baseVal2 != 40.4)
+ throw new Exception("Base values wrong");
+ if (pid.val1 != 10 || pid.val2 != 20.2)
+ throw new Exception("Derived Values wrong");
+ }
+}
+
+private void verifyValue(char[] expected, char[] got) {
+ if (expected != got)
+ throw new Exception("verify value failed. Expected: " ~ expected ~ " Got: " ~ got);
+}
+
+private void verifyCount(int expected, Klass k) {
+ // We deliberately call the use_count(Klass) overload also for objects which
+ // are instances of a subclass of Klass (due to static dispatch); things still
+ // have to work.
+ int got = use_count(k);
+ if (expected != got)
+ throw new Exception("verify use_count failed. Expected: " ~ toString(expected) ~ " Got: " ~ toString(got));
+}
diff --git a/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d
new file mode 100644
index 000000000..773ae74d5
--- /dev/null
+++ b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d
@@ -0,0 +1,602 @@
+module li_boost_shared_ptr_runme;
+
+import core.memory;
+import core.thread;
+import std.conv;
+import std.exception;
+import std.stdio;
+import li_boost_shared_ptr.li_boost_shared_ptr;
+import li_boost_shared_ptr.Klass;
+import li_boost_shared_ptr.KlassDerived;
+import li_boost_shared_ptr.Klass3rdDerived;
+import li_boost_shared_ptr.MemberVariables;
+import li_boost_shared_ptr.PairIntDouble;
+
+// Debugging flag
+enum TRACE = false;
+
+void main() {
+ if (TRACE)
+ writeln("---> STARTED <---");
+
+ debug_shared = TRACE;
+
+ // Change loop count to run for a long time to monitor memory
+ enum LOOP_COUNT = 1; // 50000;
+ for (int i = 0; i < LOOP_COUNT; ++i) {
+ runTest();
+ GC.collect();
+ }
+
+ if (TRACE)
+ writeln("---> NEARLY FINISHED <---");
+
+ // Try to get the GC to collect everything not referenced anymore.
+ int countdown = 100;
+ while (--countdown) {
+ GC.collect();
+ if (Klass.getTotal_count() == 1)
+ break;
+ Thread.sleep(100);
+ }
+
+ // A single remaining instance expected: the global variable (GlobalValue).
+ if (Klass.getTotal_count() != 1)
+ throw new Exception("Klass.total_count=" ~ to!string(Klass.getTotal_count()));
+
+ // A single remaining instance expected: the global variable (GlobalSmartValue).
+ int wrapper_count = shared_ptr_wrapper_count();
+ if (wrapper_count != NOT_COUNTING)
+ if (wrapper_count != 1)
+ throw new Exception("shared_ptr wrapper count=" ~ to!string(wrapper_count));
+
+ if (TRACE)
+ writeln("---> FINISHED <---");
+}
+
+void runTest() {
+ // simple shared_ptr usage - created in C++
+ {
+ auto k = new Klass("me oh my");
+ string val = k.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(1, k);
+ }
+
+ // simple shared_ptr usage - not created in C++
+ {
+ auto k = factorycreate();
+ string val = k.getValue();
+ verifyValue("factorycreate", val);
+ verifyCount(1, k);
+ }
+
+ // pass by shared_ptr
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointertest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerpointertest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerreftest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr pointer reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerpointerreftest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointerpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by value
+ {
+ auto k = new Klass("me oh my");
+ auto kret = valuetest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my valuetest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = pointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my pointertest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = reftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my reftest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = pointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my pointerreftest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // null tests
+ {
+ Klass k = null;
+
+ // TODO: add in const versions too
+ enforce(smartpointertest(k) is null, "return was not null");
+ enforce(smartpointerpointertest(k) is null, "return was not null");
+ enforce(smartpointerreftest(k) is null, "return was not null");
+ enforce(smartpointerpointerreftest(k) is null, "return was not null");
+ enforce(nullsmartpointerpointertest(null) == "null pointer",
+ "not null smartpointer pointer");
+
+ enforceThrows( (){ valuetest(k); }, "Failed to catch null pointer");
+ enforce(pointertest(k) is null, "return was not null");
+ enforceThrows( (){ reftest(k); }, "Failed to catch null pointer");
+ }
+
+ // $owner
+ {
+ auto k = pointerownertest();
+ string val = k.getValue();
+ verifyValue("pointerownertest", val);
+ verifyCount(1, k);
+ }
+ {
+ auto k = smartpointerpointerownertest();
+ string val = k.getValue();
+ verifyValue("smartpointerpointerownertest", val);
+ verifyCount(1, k);
+ }
+
+ ////////////////////////////////// Derived classes ////////////////////////////////////////
+ // derived pass by shared_ptr
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrtest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrtest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr pointer
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrpointertest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrreftest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr pointer ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by pointer
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedpointertest-Derived", val);
+ verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
+ verifyCount(2, kret);
+ }
+ // derived pass by ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedreftest-Derived", val);
+ verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
+ verifyCount(2, kret);
+ }
+
+ ////////////////////////////////// Derived and base class mixed ////////////////////////////////////////
+ // pass by shared_ptr (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointertest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr pointer (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerpointertest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr reference (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerreftest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr pointer reference (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerpointerreftest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by value (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = valuetest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my valuetest", val); // note slicing
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = pointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my pointertest-Derived", val);
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // pass by ref (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = reftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my reftest-Derived", val);
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // 3rd derived class
+ {
+ auto k = new Klass3rdDerived("me oh my");
+ string val = k.getValue();
+ verifyValue("me oh my-3rdDerived", val);
+ verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values
+ val = test3rdupcast(k);
+ verifyValue("me oh my-3rdDerived", val);
+ verifyCount(3, k);
+ }
+
+ ////////////////////////////////// Member variables ////////////////////////////////////////
+ // smart pointer by value
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member value");
+ m.SmartMemberValue = k;
+ string val = k.getValue();
+ verifyValue("smart member value", val);
+ verifyCount(2, k);
+
+ auto kmember = m.SmartMemberValue;
+ val = kmember.getValue();
+ verifyValue("smart member value", val);
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+
+ delete m;
+
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+ }
+ // smart pointer by pointer
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member pointer");
+ m.SmartMemberPointer = k;
+ string val = k.getValue();
+ verifyValue("smart member pointer", val);
+ verifyCount(1, k);
+
+ auto kmember = m.SmartMemberPointer;
+ val = kmember.getValue();
+ verifyValue("smart member pointer", val);
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+
+ delete m;
+
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+ }
+ // smart pointer by reference
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member reference");
+ m.SmartMemberReference = k;
+ string val = k.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(2, k);
+
+ auto kmember = m.SmartMemberReference;
+ val = kmember.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+
+ // The C++ reference refers to SmartMemberValue...
+ auto kmemberVal = m.SmartMemberValue;
+ val = kmember.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(4, kmemberVal);
+ verifyCount(4, kmember);
+ verifyCount(4, k);
+
+ delete m;
+
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+ }
+ // plain by value
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member value");
+ m.MemberValue = k;
+ string val = k.getValue();
+ verifyValue("plain member value", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberValue;
+ val = kmember.getValue();
+ verifyValue("plain member value", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+ // plain by pointer
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member pointer");
+ m.MemberPointer = k;
+ string val = k.getValue();
+ verifyValue("plain member pointer", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberPointer;
+ val = kmember.getValue();
+ verifyValue("plain member pointer", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+ // plain by reference
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member reference");
+ m.MemberReference = k;
+ string val = k.getValue();
+ verifyValue("plain member reference", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberReference;
+ val = kmember.getValue();
+ verifyValue("plain member reference", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+
+ // null member variables
+ {
+ auto m = new MemberVariables();
+
+ // shared_ptr by value
+ auto k = m.SmartMemberValue;
+ if (k !is null)
+ throw new Exception("expected null");
+ m.SmartMemberValue = null;
+ k = m.SmartMemberValue;
+ if (k !is null)
+ throw new Exception("expected null");
+ verifyCount(0, k);
+
+ // plain by value
+ enforceThrows( (){ m.MemberValue = null; }, "Failed to catch null pointer");
+ }
+
+ ////////////////////////////////// Global variables ////////////////////////////////////////
+ // smart pointer
+ {
+ auto kglobal = GlobalSmartValue;
+ enforce(kglobal is null, "expected null");
+
+ auto k = new Klass("smart global value");
+ GlobalSmartValue = k;
+ verifyCount(2, k);
+
+ kglobal = GlobalSmartValue;
+ string val = kglobal.getValue();
+ verifyValue("smart global value", val);
+ verifyCount(3, kglobal);
+ verifyCount(3, k);
+ verifyValue("smart global value", GlobalSmartValue.getValue());
+ GlobalSmartValue = null;
+ }
+ // plain value
+ {
+ Klass kglobal;
+
+ auto k = new Klass("global value");
+ GlobalValue = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalValue;
+ string val = kglobal.getValue();
+ verifyValue("global value", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+ verifyValue("global value", GlobalValue.getValue());
+
+ enforceThrows((){ GlobalValue = null; }, "Failed to catch null pointer");
+ }
+ // plain pointer
+ {
+ auto kglobal = GlobalPointer;
+ enforce(kglobal is null, "expected null");
+
+ auto k = new Klass("global pointer");
+ GlobalPointer = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalPointer;
+ string val = kglobal.getValue();
+ verifyValue("global pointer", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+ GlobalPointer = null;
+ }
+ // plain reference
+ {
+ Klass kglobal;
+
+ auto k = new Klass("global reference");
+ GlobalReference = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalReference;
+ string val = kglobal.getValue();
+ verifyValue("global reference", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+
+ enforceThrows((){ GlobalReference = null; }, "Failed to catch null pointer");
+ }
+
+ ////////////////////////////////// Templates ////////////////////////////////////////
+ {
+ auto pid = new PairIntDouble(10, 20.2);
+ enforce(pid.baseVal1 == 20 && pid.baseVal2== 40.4, "Base values wrong");
+ enforce(pid.val1 == 10 && pid.val2 == 20.2, "Derived Values wrong");
+ }
+}
+
+private void verifyValue(string expected, string got) {
+ if (expected != got)
+ throw new Exception("verify value failed. Expected: " ~ expected ~ " Got: " ~ got);
+}
+
+private void verifyCount(int expected, Klass k) {
+ // We deliberately call the use_count(Klass) overload also for objects which
+ // are instances of a subclass of Klass (due to static dispatch); things still
+ // have to work.
+ int got = use_count(k);
+ if (expected != got)
+ throw new Exception("verify use_count failed. Expected: " ~ to!string(expected) ~ " Got: " ~ to!string(got));
+}
+
+private void enforceThrows(void delegate() dg, string errorMessage) {
+ bool hasThrown;
+ try {
+ dg();
+ } catch (Exception) {
+ hasThrown = true;
+ } finally {
+ if (!hasThrown) {
+ throw new Exception(errorMessage);
+ }
+ }
+}
diff --git a/Examples/test-suite/d/li_std_except_runme.1.d b/Examples/test-suite/d/li_std_except_runme.1.d
new file mode 100644
index 000000000..39f3bb202
--- /dev/null
+++ b/Examples/test-suite/d/li_std_except_runme.1.d
@@ -0,0 +1,40 @@
+module li_std_except_runme;
+
+import tango.core.Exception;
+import tango.io.Console;
+import li_std_except.Test;
+
+void main() {
+ with (new Test()) {
+ mixin(test("Exception", "throw_bad_exception"));
+ mixin(test("Exception", "throw_domain_error"));
+ mixin(test("Exception", "throw_exception"));
+ mixin(test("IllegalArgumentException", "throw_invalid_argument"));
+ mixin(test("NoSuchElementException", "throw_length_error"));
+ mixin(test("Exception", "throw_logic_error"));
+ mixin(test("NoSuchElementException", "throw_out_of_range"));
+ mixin(test("Exception", "throw_overflow_error"));
+ mixin(test("Exception", "throw_range_error"));
+ mixin(test("Exception", "throw_runtime_error"));
+ mixin(test("Exception", "throw_underflow_error"));
+ }
+}
+
+char[] test(char[] e, char[] f) {
+ return "if (!works!(" ~ e ~ ")(&" ~ f ~ ")) {\n" ~
+ "throw new Exception(\"" ~ f ~ " failed\");\n" ~
+ "}";
+}
+
+bool works(alias E, F)(F f) {
+ try {
+ try {
+ f();
+ } catch(E) {
+ return true;
+ }
+ } catch(Exception e) {
+ Cerr( "Received wrong exception: " ~ e.classinfo.name ).newline;
+ }
+ return false;
+}
diff --git a/Examples/test-suite/d/li_std_except_runme.2.d b/Examples/test-suite/d/li_std_except_runme.2.d
new file mode 100644
index 000000000..f2b4b672c
--- /dev/null
+++ b/Examples/test-suite/d/li_std_except_runme.2.d
@@ -0,0 +1,34 @@
+module li_std_except_runme;
+
+import std.exception;
+import std.stdio;
+import li_std_except.Test;
+
+void main() {
+ with (new Test()) {
+ enforce(works!(Exception)(&throw_bad_exception));
+ enforce(works!(Exception)(&throw_domain_error));
+ enforce(works!(Exception)(&throw_exception));
+ enforce(works!(Exception)(&throw_invalid_argument));
+ enforce(works!(Exception)(&throw_length_error));
+ enforce(works!(Exception)(&throw_logic_error));
+ enforce(works!(Exception)(&throw_out_of_range));
+ enforce(works!(Exception)(&throw_overflow_error));
+ enforce(works!(Exception)(&throw_range_error));
+ enforce(works!(Exception)(&throw_runtime_error));
+ enforce(works!(Exception)(&throw_underflow_error));
+ }
+}
+
+bool works(alias E, F)(F f) {
+ try {
+ try {
+ f();
+ } catch(E) {
+ return true;
+ }
+ } catch(Exception e) {
+ writefln( "Received wrong exception: %s", e.classinfo.name );
+ }
+ return false;
+}
diff --git a/Examples/test-suite/d/li_std_string_runme.1.d b/Examples/test-suite/d/li_std_string_runme.1.d
new file mode 100644
index 000000000..b5bbb51c0
--- /dev/null
+++ b/Examples/test-suite/d/li_std_string_runme.1.d
@@ -0,0 +1,97 @@
+module li_std_string_runme;
+
+import tango.core.Exception;
+import li_std_string.li_std_string;
+import li_std_string.Structure;
+import li_std_string.SWIGTYPE_p_std__string;
+
+
+void main() {
+ // Checking expected use of %typemap(in) std::string {}
+ test_value("Fee");
+
+ // Checking expected result of %typemap(out) std::string {}
+ if (test_value("Fi") != "Fi")
+ throw new Exception("Test 1 failed");
+
+ // Verify type-checking for %typemap(in) std::string {}
+ try {
+ test_value(null);
+ throw new Exception("Test 2 failed");
+ } catch (IllegalArgumentException) {
+ }
+
+ // Checking expected use of %typemap(in) const std::string & {}
+ test_const_reference("Fo");
+
+ // Checking expected result of %typemap(out) const std::string& {}
+ if (test_const_reference("Fum") != "Fum")
+ throw new Exception("Test 3 failed");
+
+ // Verify type-checking for %typemap(in) const std::string & {}
+ try {
+ test_const_reference(null);
+ throw new Exception("Test 4 failed");
+ } catch (IllegalArgumentException) {
+ }
+
+ // Input and output typemaps for pointers and non-const references to
+ // std::string are *not* supported; the following tests confirm
+ // that none of these cases are slipping through.
+
+ SWIGTYPE_p_std__string stringPtr = null;
+
+ stringPtr = test_pointer_out();
+ test_pointer(stringPtr);
+
+ stringPtr = test_const_pointer_out();
+ test_const_pointer(stringPtr);
+
+ stringPtr = test_reference_out();
+ test_reference(stringPtr);
+
+ // Check throw exception specification
+ try {
+ test_throw();
+ throw new Exception("test 5 failed!");
+ } catch (Exception e) {
+ if (e.msg != "test_throw message")
+ throw new Exception("Test 5 string check: " ~ e.msg);
+ }
+ try {
+ test_const_reference_throw();
+ throw new Exception("test 6 failed!");
+ } catch (Exception e) {
+ if (e.msg != "test_const_reference_throw message")
+ throw new Exception("Test 6 string check: " ~ e.msg);
+ }
+
+ // Global variables.
+ const char[] s = "initial string";
+ if (GlobalString2 != "global string 2")
+ throw new Exception("GlobalString2 test 1");
+ GlobalString2 = s;
+ if (GlobalString2 != s)
+ throw new Exception("GlobalString2 test 2");
+ if (ConstGlobalString != "const global string")
+ throw new Exception("ConstGlobalString test");
+
+ // Member variables.
+ auto myStructure = new Structure();
+ if (myStructure.MemberString2 != "member string 2")
+ throw new Exception("MemberString2 test 1");
+ myStructure.MemberString2 = s;
+ if (myStructure.MemberString2 != s)
+ throw new Exception("MemberString2 test 2");
+ if (myStructure.ConstMemberString != "const member string")
+ throw new Exception("ConstMemberString test");
+
+ // Static member variables.
+ if (Structure.StaticMemberString2 != "static member string 2")
+ throw new Exception("StaticMemberString2 test 1");
+ Structure.StaticMemberString2 = s;
+ if (Structure.StaticMemberString2 != s)
+ throw new Exception("StaticMemberString2 test 2");
+ if (Structure.ConstStaticMemberString != "const static member string")
+ throw new Exception("ConstStaticMemberString test");
+}
diff --git a/Examples/test-suite/d/li_std_string_runme.2.d b/Examples/test-suite/d/li_std_string_runme.2.d
new file mode 100644
index 000000000..395c2f7ff
--- /dev/null
+++ b/Examples/test-suite/d/li_std_string_runme.2.d
@@ -0,0 +1,86 @@
+module li_std_string_runme;
+
+import std.exception;
+import li_std_string.li_std_string;
+import li_std_string.Structure;
+import li_std_string.SWIGTYPE_p_std__string;
+
+void main() {
+ // Checking expected use of %typemap(in) std::string {}
+ test_value("Fee");
+
+ // Checking expected result of %typemap(out) std::string {}
+ enforce(test_value("Fi") == "Fi", "Test 1 failed");
+
+ // Verify type-checking for %typemap(in) std::string {}
+ enforceThrows( (){ test_value(null); }, "Test 2 failed.");
+
+ // Checking expected use of %typemap(in) const std::string & {}
+ test_const_reference("Fo");
+
+ // Checking expected result of %typemap(out) const std::string& {}
+ enforce(test_const_reference("Fum") == "Fum", "Test 3 failed");
+
+ // Verify type-checking for %typemap(in) const std::string & {}
+ enforceThrows( (){ test_const_reference(null); }, "Test 4 failed.");
+
+ // Input and output typemaps for pointers and non-const references to
+ // std::string are *not* supported; the following tests confirm
+ // that none of these cases are slipping through.
+
+ SWIGTYPE_p_std__string stringPtr = null;
+
+ stringPtr = test_pointer_out();
+ test_pointer(stringPtr);
+
+ stringPtr = test_const_pointer_out();
+ test_const_pointer(stringPtr);
+
+ stringPtr = test_reference_out();
+ test_reference(stringPtr);
+
+ // Check throw exception specification
+ try {
+ test_throw();
+ throw new Exception("test 5 failed!");
+ } catch (Exception e) {
+ enforce(e.msg == "test_throw message", "Test 5 string check: " ~ e.msg);
+ }
+ try {
+ test_const_reference_throw();
+ throw new Exception("test 6 failed!");
+ } catch (Exception e) {
+ enforce(e.msg == "test_const_reference_throw message", "Test 6 string check: " ~ e.msg);
+ }
+
+ // Global variables.
+ const string s = "initial string";
+ enforce(GlobalString2 == "global string 2", "GlobalString2 test 1");
+ GlobalString2 = s;
+ enforce(GlobalString2 == s, "GlobalString2 test 2");
+ enforce(ConstGlobalString == "const global string", "ConstGlobalString test");
+
+ // Member variables.
+ auto myStructure = new Structure();
+ enforce(myStructure.MemberString2 == "member string 2", "MemberString2 test 1");
+ myStructure.MemberString2 = s;
+ enforce(myStructure.MemberString2 == s, "MemberString2 test 2");
+ enforce(myStructure.ConstMemberString == "const member string", "ConstMemberString test");
+
+ // Static member variables.
+ enforce(Structure.StaticMemberString2 == "static member string 2", "StaticMemberString2 test 1");
+ Structure.StaticMemberString2 = s;
+ enforce(Structure.StaticMemberString2 == s, "StaticMemberString2 test 2");
+ enforce(Structure.ConstStaticMemberString == "const static member string", "ConstStaticMemberString test");
+}
+
+private void enforceThrows(void delegate() dg, string errorMessage) {
+ bool hasThrown;
+ try {
+ dg();
+ } catch (Exception) {
+ hasThrown = true;
+ } finally {
+ enforce(hasThrown, errorMessage);
+ }
+}
diff --git a/Examples/test-suite/d/li_std_vector_runme.1.d b/Examples/test-suite/d/li_std_vector_runme.1.d
new file mode 100644
index 000000000..895fb450f
--- /dev/null
+++ b/Examples/test-suite/d/li_std_vector_runme.1.d
@@ -0,0 +1,219 @@
+module li_std_vector_runme;
+
+import tango.core.Exception;
+import tango.io.Stdout;
+import Integer = tango.text.convert.Integer;
+import li_std_vector.li_std_vector;
+import li_std_vector.DoubleVector;
+import li_std_vector.IntVector;
+import li_std_vector.IntPtrVector;
+import li_std_vector.IntConstPtrVector;
+import li_std_vector.RealVector;
+import li_std_vector.Struct;
+import li_std_vector.StructVector;
+import li_std_vector.StructPtrVector;
+import li_std_vector.StructConstPtrVector;
+
+const size_t SIZE = 20;
+
+void main() {
+ // Basic functionality tests.
+ {
+ auto vector = new IntVector();
+ for (size_t i = 0; i < SIZE; ++i) {
+ vector ~= i * 10;
+ }
+
+ if (vector.length != SIZE) {
+ throw new Exception("length test failed.");
+ }
+
+ vector[0] = 200;
+ if (vector[0] != 200) {
+ throw new Exception("indexing test failed");
+ }
+ vector[0] = 0 * 10;
+
+ try {
+ vector[vector.length] = 777;
+ throw new Exception("out of range test failed");
+ } catch (NoSuchElementException) {
+ }
+
+ foreach (i, value; vector) {
+ if (value != (i * 10)) {
+ throw new Exception("foreach test failed, i: " ~ Integer.toString(i));
+ }
+ }
+
+ vector.clear();
+ if (vector.size != 0) {
+ throw new Exception("clear test failed");
+ }
+ }
+
+ // Slice tests.
+ {
+ auto dVector = new DoubleVector();
+ for (size_t i = 0; i < SIZE; ++i) {
+ dVector ~= i * 10.1f;
+ }
+
+ double[] dArray = dVector[];
+ foreach (i, value; dArray) {
+ if (dVector[i] != value) {
+ throw new Exception("slice test 1 failed, i: " ~ Integer.toString(i));
+ }
+ }
+
+
+ auto sVector = new StructVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ sVector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = sVector[];
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(sVector[i]);
+ if (aPtr != vPtr) {
+ throw new Exception("slice test 2 failed, i: " ~
+ Integer.toString(i));
+ }
+ }
+ }
+
+ // remove() tests.
+ {
+ auto iVector = new IntVector();
+ for (int i = 0; i < SIZE; i++) {
+ iVector ~= i;
+ }
+
+ iVector.remove(iVector.length - 1);
+ iVector.remove(SIZE / 2);
+ iVector.remove(0);
+
+ try {
+ iVector.remove(iVector.size);
+ throw new Exception("remove test failed");
+ } catch (NoSuchElementException) {
+ }
+ }
+
+ // Capacity tests.
+ {
+ auto dv = new DoubleVector(10);
+ if ((dv.capacity != 10) || (dv.length != 0)) {
+ throw new Exception("constructor setting capacity test failed");
+ }
+
+ // TODO: Is this really required (and spec'ed) behavior?
+ dv.capacity = 20;
+ if (dv.capacity != 20) {
+ throw new Exception("capacity test 1 failed");
+ }
+
+ dv ~= 1.11;
+ try {
+ dv.capacity = dv.length - 1;
+ throw new Exception("capacity test 2 failed");
+ } catch (IllegalArgumentException) {
+ }
+ }
+
+ // Test the methods being wrapped.
+ {
+ auto iv = new IntVector();
+ for (int i=0; i<4; i++) {
+ iv ~= i;
+ }
+
+ double x = average(iv);
+ x += average(new IntVector([1, 2, 3, 4]));
+ RealVector rv = half(new RealVector([10.0f, 10.5f, 11.0f, 11.5f]));
+
+ auto dv = new DoubleVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ dv ~= i / 2.0;
+ }
+ halve_in_place(dv);
+
+ RealVector v0 = vecreal(new RealVector());
+ float flo = 123.456f;
+ v0 ~= flo;
+ flo = v0[0];
+
+ IntVector v1 = vecintptr(new IntVector());
+ IntPtrVector v2 = vecintptr(new IntPtrVector());
+ IntConstPtrVector v3 = vecintconstptr(new IntConstPtrVector());
+
+ v1 ~= 123;
+ v2.clear();
+ v3.clear();
+
+ StructVector v4 = vecstruct(new StructVector());
+ StructPtrVector v5 = vecstructptr(new StructPtrVector());
+ StructConstPtrVector v6 = vecstructconstptr(new StructConstPtrVector());
+
+ v4 ~= new Struct(123);
+ v5 ~= new Struct(123);
+ v6 ~= new Struct(123);
+ }
+
+ // Test vectors of pointers.
+ {
+ auto vector = new StructPtrVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ vector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = vector[];
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(vector[i]);
+ if (aPtr != vPtr) {
+ throw new Exception("StructPtrVector test 1 failed, i: " ~
+ Integer.toString(i));
+ }
+ }
+ }
+
+ // Test vectors of const pointers.
+ {
+ auto vector = new StructConstPtrVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ vector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = vector[];
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(vector[i]);
+ if (aPtr != vPtr) {
+ throw new Exception("StructConstPtrVector test 1 failed, i: " ~
+ Integer.toString(i));
+ }
+ }
+ }
+
+ // Test vectors destroyed via dispose().
+ {
+ {
+ scope vector = new StructVector();
+ vector ~= new Struct(0.0);
+ vector ~= new Struct(11.1);
+ }
+ {
+ scope vector = new DoubleVector();
+ vector ~= 0.0;
+ vector ~= 11.1;
+ }
+ }
+}
diff --git a/Examples/test-suite/d/li_std_vector_runme.2.d b/Examples/test-suite/d/li_std_vector_runme.2.d
new file mode 100644
index 000000000..7860ad6fc
--- /dev/null
+++ b/Examples/test-suite/d/li_std_vector_runme.2.d
@@ -0,0 +1,207 @@
+module li_std_vector_runme;
+
+import std.algorithm;
+import std.array;
+import std.conv;
+import std.exception;
+import std.stdio;
+import li_std_vector.li_std_vector;
+import li_std_vector.DoubleVector;
+import li_std_vector.IntVector;
+import li_std_vector.IntPtrVector;
+import li_std_vector.IntConstPtrVector;
+import li_std_vector.RealVector;
+import li_std_vector.Struct;
+import li_std_vector.StructVector;
+import li_std_vector.StructPtrVector;
+import li_std_vector.StructConstPtrVector;
+
+const size_t SIZE = 20;
+
+void main() {
+ // Basic functionality tests.
+ {
+ auto vector = new IntVector();
+ for (size_t i = 0; i < SIZE; ++i) {
+ vector ~= i * 10;
+ }
+
+ enforce(vector.length == SIZE, "length test failed.");
+
+ vector[0] = 200;
+ enforce(vector[0] == 200, "indexing test failed");
+ vector[0] = 0 * 10;
+
+ enforceThrows((){ vector[vector.length] = 777; }, "out of range test failed" );
+
+ foreach (i, value; vector) {
+ enforce(value == (i * 10), "foreach test failed, i: " ~ to!string(i));
+ }
+
+ enforce(canFind!`a == 0 * 10`(vector[]), "canFind test 1 failed");
+ enforce(canFind!`a == 10 * 10`(vector[]), "canFind test 2 failed");
+ enforce(canFind!`a == 19 * 10`(vector[]), "canFind test 3 failed");
+ enforce(!canFind!`a == 20 * 10`(vector[]), "canFind test 4 failed");
+
+ foreach (i, _; vector) {
+ enforce(indexOf(vector[], i * 10) == i, "indexOf test failed, i: " ~ to!string(i));
+ }
+
+ enforce(indexOf(vector[], 42) == -1, "non-existant item indexOf test failed");
+
+ vector.clear();
+ enforce(vector.length == 0, "clear test failed");
+ }
+
+ // To array conversion tests.
+ {
+ auto dVector = new DoubleVector();
+ for (size_t i = 0; i < SIZE; ++i) {
+ dVector ~= i * 10.1f;
+ }
+
+ double[] dArray = array(dVector[]);
+ foreach (i, value; dArray) {
+ enforce(dVector[i] == value, "slice test 1 failed, i: " ~ to!string(i));
+ }
+
+
+ auto sVector = new StructVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ sVector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] sArray = array(sVector[]);
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(sArray[i]);
+ void* vPtr = Struct.swigGetCPtr(sVector[i]);
+ enforce(aPtr == vPtr, "slice test 2 failed, i: " ~ to!string(i));
+ }
+ }
+
+ // remove() tests.
+ {
+ auto iVector = new IntVector();
+ for (int i = 0; i < SIZE; i++) {
+ iVector ~= i;
+ }
+
+ iVector.remove(iVector.length - 1);
+ iVector.remove(SIZE / 2);
+ iVector.remove(0);
+
+ enforceThrows((){ iVector.remove(iVector.length); }, "remove test failed");
+ }
+
+ // Capacity tests.
+ {
+ auto dv = new DoubleVector(10);
+ enforce(dv.capacity == 10, "constructor setting capacity test failed (1)");
+ enforce(dv.length == 0, "constructor setting capacity test failed (1)");
+
+ dv.reserve(20);
+ enforce(dv.capacity == 20, "capacity test failed");
+ }
+
+ // Test the methods being wrapped.
+ {
+ auto iv = new IntVector();
+ for (int i=0; i<4; i++) {
+ iv ~= i;
+ }
+
+ double x = average(iv);
+ x += average(new IntVector([1, 2, 3, 4]));
+ RealVector rv = half(new RealVector([10.0f, 10.5f, 11.0f, 11.5f]));
+
+ auto dv = new DoubleVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ dv ~= i / 2.0;
+ }
+ halve_in_place(dv);
+
+ RealVector v0 = vecreal(new RealVector());
+ float flo = 123.456f;
+ v0 ~= flo;
+ flo = v0[0];
+
+ IntVector v1 = vecintptr(new IntVector());
+ IntPtrVector v2 = vecintptr(new IntPtrVector());
+ IntConstPtrVector v3 = vecintconstptr(new IntConstPtrVector());
+
+ v1 ~= 123;
+ v2.clear();
+ v3.clear();
+
+ StructVector v4 = vecstruct(new StructVector());
+ StructPtrVector v5 = vecstructptr(new StructPtrVector());
+ StructConstPtrVector v6 = vecstructconstptr(new StructConstPtrVector());
+
+ v4 ~= new Struct(123);
+ v5 ~= new Struct(123);
+ v6 ~= new Struct(123);
+ }
+
+ // Test vectors of pointers.
+ {
+ auto vector = new StructPtrVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ vector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = array(vector[]);
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(vector[i]);
+ enforce(aPtr == vPtr, "StructConstPtrVector test 1 failed, i: " ~ to!string(i));
+ }
+ }
+
+ // Test vectors of const pointers.
+ {
+ auto vector = new StructConstPtrVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ vector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = array(vector[]);
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(vector[i]);
+ enforce(aPtr == vPtr, "StructConstPtrVector test 1 failed, i: " ~ to!string(i));
+ }
+ }
+
+ // Test vectors destroyed via scope.
+ {
+ {
+ scope vector = new StructVector();
+ vector ~= new Struct(0.0);
+ vector ~= new Struct(11.1);
+ }
+ {
+ scope vector = new DoubleVector();
+ vector ~= 0.0;
+ vector ~= 11.1;
+ }
+ }
+}
+
+private void enforceThrows(void delegate() dg, string errorMessage) {
+ bool hasThrown;
+ try {
+ dg();
+ } catch (Exception) {
+ hasThrown = true;
+ } finally {
+ if (!hasThrown) {
+ throw new Exception(errorMessage);
+ }
+ }
+}
diff --git a/Examples/test-suite/d/li_typemaps_runme.1.d b/Examples/test-suite/d/li_typemaps_runme.1.d
new file mode 100644
index 000000000..e37b12bc2
--- /dev/null
+++ b/Examples/test-suite/d/li_typemaps_runme.1.d
@@ -0,0 +1,94 @@
+/// Tests correct handling of a few INPUT/OUTPUT/INOUT-typemapped functions.
+module li_typemaps_runme;
+
+import li_typemaps.li_typemaps;
+
+void main() {
+ // Check double INPUT typemaps
+ if (in_double(22.22) != 22.22) raiseError("in_double");
+ if (inr_double(22.22) != 22.22) raiseError("inr_double");
+
+ // Check double OUTPUT typemaps
+ {
+ double var = 44.44;
+ out_double(22.22, var);
+ if (var != 22.22) raiseError("out_double");
+ }
+ {
+ double var = 44.44;
+ outr_double(22.22, var);
+ if (var != 22.22) raiseError("outr_double");
+ }
+
+ // Check double INOUT typemaps
+ {
+ double var = 44.44;
+ inout_double(var);
+ if (var != 44.44) raiseError("inout_double");
+ }
+ {
+ double var = 44.44;
+ inoutr_double(var);
+ if (var != 44.44) raiseError("inoutr_double");
+ }
+
+ // Check unsigned long long INPUT typemaps
+ if (in_ulonglong(20) != 20) raiseError("in_ulonglong");
+ if (inr_ulonglong(20) != 20) raiseError("inr_ulonglong");
+
+ // Check unsigned long long OUTPUT typemaps
+ {
+ ulong var = 40;
+ out_ulonglong(20, var);
+ if (var != 20) raiseError("out_ulonglong");
+ }
+ {
+ ulong var = 40;
+ outr_ulonglong(20, var);
+ if (var != 20) raiseError("outr_ulonglong");
+ }
+
+ // Check unsigned long long INOUT typemaps
+ {
+ ulong var = 40;
+ inout_ulonglong(var);
+ if (var != 40) raiseError("inout_ulonglong");
+ }
+ {
+ ulong var = 40;
+ inoutr_ulonglong(var);
+ if (var != 40) raiseError("inoutr_ulonglong");
+ }
+
+ // Check unsigned bool INPUT typemaps
+ if (in_bool(false) != false) raiseError("in_bool");
+ if (inr_bool(false) != false) raiseError("inr_bool");
+
+ // Check unsigned bool OUTPUT typemaps
+ {
+ bool var = false;
+ out_bool(true, var);
+ if (var != true) raiseError("out_bool");
+ }
+ {
+ bool var = false;
+ outr_bool(true, var);
+ if (var != true) raiseError("outr_bool");
+ }
+
+ // Check unsigned bool INOUT typemaps
+ {
+ bool var = false;
+ inout_bool(var);
+ if (var != false) raiseError("inout_bool");
+ }
+ {
+ bool var = false;
+ inoutr_bool(var);
+ if (var != false) raiseError("inoutr_bool");
+ }
+}
+
+void raiseError(char[] funcName) {
+ throw new Exception("Test FAILED for function " ~ funcName);
+}
diff --git a/Examples/test-suite/d/li_typemaps_runme.2.d b/Examples/test-suite/d/li_typemaps_runme.2.d
new file mode 100644
index 000000000..de515b0ff
--- /dev/null
+++ b/Examples/test-suite/d/li_typemaps_runme.2.d
@@ -0,0 +1,91 @@
+/// Tests correct handling of a few INPUT/OUTPUT/INOUT-typemapped functions.
+module li_typemaps_runme;
+
+import std.exception;
+import li_typemaps.li_typemaps;
+
+void main() {
+ // Check double INPUT typemaps
+ enforce(in_double(22.22) == 22.22, "in_double");
+ enforce(inr_double(22.22) == 22.22, "inr_double");
+
+ // Check double OUTPUT typemaps
+ {
+ double var = 44.44;
+ out_double(22.22, var);
+ enforce(var == 22.22, "out_double");
+ }
+ {
+ double var = 44.44;
+ outr_double(22.22, var);
+ enforce(var == 22.22, "outr_double");
+ }
+
+ // Check double INOUT typemaps
+ {
+ double var = 44.44;
+ inout_double(var);
+ enforce(var == 44.44, "inout_double");
+ }
+ {
+ double var = 44.44;
+ inoutr_double(var);
+ enforce(var == 44.44, "inoutr_double");
+ }
+
+ // Check unsigned long long INPUT typemaps
+ enforce(in_ulonglong(20) == 20, "in_ulonglong");
+ enforce(inr_ulonglong(20) == 20, "inr_ulonglong");
+
+ // Check unsigned long long OUTPUT typemaps
+ {
+ ulong var = 40;
+ out_ulonglong(20, var);
+ enforce(var == 20, "out_ulonglong");
+ }
+ {
+ ulong var = 40;
+ outr_ulonglong(20, var);
+ enforce(var == 20, "outr_ulonglong");
+ }
+
+ // Check unsigned long long INOUT typemaps
+ {
+ ulong var = 40;
+ inout_ulonglong(var);
+ enforce(var == 40, "inout_ulonglong");
+ }
+ {
+ ulong var = 40;
+ inoutr_ulonglong(var);
+ enforce(var == 40, "inoutr_ulonglong");
+ }
+
+ // Check unsigned bool INPUT typemaps
+ enforce(in_bool(false) == false, "in_bool");
+ enforce(inr_bool(false) == false, "inr_bool");
+
+ // Check unsigned bool OUTPUT typemaps
+ {
+ bool var = false;
+ out_bool(true, var);
+ enforce(var == true, "out_bool");
+ }
+ {
+ bool var = false;
+ outr_bool(true, var);
+ enforce(var == true, "outr_bool");
+ }
+
+ // Check unsigned bool INOUT typemaps
+ {
+ bool var = false;
+ inout_bool(var);
+ enforce(var == false, "inout_bool");
+ }
+ {
+ bool var = false;
+ inoutr_bool(var);
+ enforce(var == false, "inoutr_bool");
+ }
+}
diff --git a/Examples/test-suite/d/long_long_runme.1.d b/Examples/test-suite/d/long_long_runme.1.d
new file mode 100644
index 000000000..a6d5448bc
--- /dev/null
+++ b/Examples/test-suite/d/long_long_runme.1.d
@@ -0,0 +1,35 @@
+// Checks if the long long and unsigned long long types work.
+module long_long_runme;
+
+import Integer = tango.text.convert.Integer;
+import long_long.long_long;
+
+void main() {
+ check_ll(0L);
+ check_ll(0x7FFFFFFFFFFFFFFFL);
+ check_ll(-10L);
+
+ check_ull(0u);
+ check_ull(127u);
+ check_ull(128u);
+ check_ull(9223372036854775807u); //0x7FFFFFFFFFFFFFFFL
+ check_ull(18446744073709551615u); //0xFFFFFFFFFFFFFFFFL
+}
+
+void check_ll(long value) {
+ ll = value;
+ long value_check = ll;
+ if (value != value_check) {
+ throw new Exception("Runtime test using long long failed: expected: " ~
+ Integer.toString(value) ~ ", got: " ~ Integer.toString(value_check));
+ }
+}
+
+void check_ull(ulong value) {
+ ull = value;
+ ulong value_check = ull;
+ if (value != value_check) {
+ throw new Exception( "Runtime test using unsigned long long failed: expected: " ~
+ Integer.toString(value) ~ ", ll_check=" ~ Integer.toString(value_check));
+ }
+}
diff --git a/Examples/test-suite/d/long_long_runme.2.d b/Examples/test-suite/d/long_long_runme.2.d
new file mode 100644
index 000000000..a082171b4
--- /dev/null
+++ b/Examples/test-suite/d/long_long_runme.2.d
@@ -0,0 +1,32 @@
+// Checks if the long long and unsigned long long types work.
+module long_long_runme;
+
+import std.conv;
+import std.exception;
+import long_long.long_long;
+
+void main() {
+ check_ll(0L);
+ check_ll(0x7FFFFFFFFFFFFFFFL);
+ check_ll(-10L);
+
+ check_ull(0u);
+ check_ull(127u);
+ check_ull(128u);
+ check_ull(9223372036854775807u); //0x7FFFFFFFFFFFFFFFL
+ check_ull(18446744073709551615u); //0xFFFFFFFFFFFFFFFFL
+}
+
+void check_ll(long value) {
+ ll = value;
+ long value_check = ll;
+ enforce(value == value_check, "Runtime test using long long failed: expected: " ~
+ to!string(value) ~ ", got: " ~ to!string(value_check));
+}
+
+void check_ull(ulong value) {
+ ull = value;
+ ulong value_check = ull;
+ enforce(value == value_check, "Runtime test using unsigned long long failed: expected: " ~
+ to!string(value) ~ ", ll_check=" ~ to!string(value_check));
+}
diff --git a/Examples/test-suite/d/member_pointer_runme.1.d b/Examples/test-suite/d/member_pointer_runme.1.d
new file mode 100644
index 000000000..c1f8d33b8
--- /dev/null
+++ b/Examples/test-suite/d/member_pointer_runme.1.d
@@ -0,0 +1,43 @@
+module member_pointer_runme;
+
+import Float = tango.text.convert.Float;
+import member_pointer.member_pointer;
+import member_pointer.Square;
+import member_pointer.SWIGTYPE_m_Shape__f_void__double;
+
+void main() {
+ auto s = new Square(10);
+
+ // Do some calculations
+ auto area_pt = areapt();
+ auto perim_pt = perimeterpt();
+ check("Square area ", 100.0, do_op(s, area_pt));
+ check("Square perim", 40.0, do_op(s, perim_pt));
+
+ SWIGTYPE_m_Shape__f_void__double memberPtr = null;
+ memberPtr = areavar;
+ memberPtr = perimetervar;
+
+ // Try the variables
+ check("Square area ", 100.0, do_op(s, areavar));
+ check("Square perim", 40.0, do_op(s, perimetervar));
+
+ // Modify one of the variables
+ areavar = perim_pt;
+ check("Square perimeter", 40.0, do_op(s,areavar));
+
+ // Try the constants
+ memberPtr = AREAPT;
+ memberPtr = PERIMPT;
+ memberPtr = NULLPT;
+
+ check("Square area", 100.0, do_op(s, AREAPT));
+ check("Square perim", 40.0, do_op(s, PERIMPT));
+}
+
+void check(char[] what, double expected, double actual) {
+ if (expected != actual) {
+ throw new Exception("Failed: " ~ what ~ ": expected "
+ ~ Float.toString(expected) ~ ", but got " ~ Float.toString(actual));
+ }
+}
diff --git a/Examples/test-suite/d/member_pointer_runme.2.d b/Examples/test-suite/d/member_pointer_runme.2.d
new file mode 100644
index 000000000..a5c293cd0
--- /dev/null
+++ b/Examples/test-suite/d/member_pointer_runme.2.d
@@ -0,0 +1,42 @@
+module member_pointer_runme;
+
+import std.conv;
+import std.exception;
+import member_pointer.member_pointer;
+import member_pointer.Square;
+import member_pointer.SWIGTYPE_m_Shape__f_void__double;
+
+void main() {
+ auto s = new Square(10);
+
+ // Do some calculations
+ auto area_pt = areapt();
+ auto perim_pt = perimeterpt();
+ check("Square area", 100.0, do_op(s, area_pt));
+ check("Square perim", 40.0, do_op(s, perim_pt));
+
+ SWIGTYPE_m_Shape__f_void__double memberPtr = null;
+ memberPtr = areavar;
+ memberPtr = perimetervar;
+
+ // Try the variables
+ check("Square area", 100.0, do_op(s, areavar));
+ check("Square perim", 40.0, do_op(s, perimetervar));
+
+ // Modify one of the variables
+ areavar = perim_pt;
+ check("Square perimeter", 40.0, do_op(s,areavar));
+
+ // Try the constants
+ memberPtr = AREAPT;
+ memberPtr = PERIMPT;
+ memberPtr = NULLPT;
+
+ check("Square area", 100.0, do_op(s, AREAPT));
+ check("Square perim", 40.0, do_op(s, PERIMPT));
+}
+
+void check(string what, double expected, double actual) {
+ enforce(expected == actual, "Failed: " ~ what ~ ": expected " ~
+ to!string(expected) ~ ", but got " ~ to!string(actual));
+}
diff --git a/Examples/test-suite/d/overload_complicated_runme.1.d b/Examples/test-suite/d/overload_complicated_runme.1.d
new file mode 100644
index 000000000..03d1bf1e6
--- /dev/null
+++ b/Examples/test-suite/d/overload_complicated_runme.1.d
@@ -0,0 +1,50 @@
+module overload_complicated_runme;
+
+import overload_complicated;
+
+void main() {
+ SWIGTYPE_p_int pInt = null;
+
+ // Check the correct constructors are available
+ Pop p = new Pop(pInt);
+
+ p = new Pop(pInt, false);
+
+ // Check overloaded in const only and pointers/references which target languages cannot disambiguate
+ if (p.hip(false) != 701)
+ throw new Exception("Test 1 failed");
+
+ if (p.hip(pInt) != 702)
+ throw new Exception("Test 2 failed");
+
+ // Reverse the order for the above
+ if (p.hop(pInt) != 805)
+ throw new Exception("Test 3 failed");
+
+ if (p.hop(false) != 801)
+ throw new Exception("Test 4 failed");
+
+ // Few more variations and order shuffled
+ if (p.pop(false) != 901)
+ throw new Exception("Test 5 failed");
+
+ if (p.pop(pInt) != 902)
+ throw new Exception("Test 6 failed");
+
+ if (p.pop() != 905)
+ throw new Exception("Test 7 failed");
+
+ // Overload on const only
+ if (p.bop(pInt) != 1001)
+ throw new Exception("Test 8 failed");
+
+ if (p.bip(pInt) != 2001)
+ throw new Exception("Test 9 failed");
+
+ // Globals
+ if (muzak(false) != 3001)
+ throw new Exception("Test 10 failed");
+
+ if (muzak(pInt) != 3002)
+ throw new Exception("Test 11 failed");
+}
diff --git a/Examples/test-suite/d/overload_complicated_runme.2.d b/Examples/test-suite/d/overload_complicated_runme.2.d
new file mode 100644
index 000000000..9d03ec5e6
--- /dev/null
+++ b/Examples/test-suite/d/overload_complicated_runme.2.d
@@ -0,0 +1,34 @@
+module overload_complicated_runme;
+
+import std.exception;
+import overload_complicated.overload_complicated;
+import overload_complicated.Pop;
+
+void main() {
+ int* pInt = new int;
+
+ // Check the correct constructors are available
+ auto p = new Pop(pInt);
+ p = new Pop(pInt, false);
+
+ // Check overloaded in const only and pointers/references which target languages cannot disambiguate
+ enforce(p.hip(false) == 701, "Test 1 failed");
+ enforce(p.hip(pInt) == 702, "Test 2 failed");
+
+ // Reverse the order for the above
+ enforce(p.hop(pInt) == 805, "Test 3 failed");
+ enforce(p.hop(false) == 801, "Test 4 failed");
+
+ // Few more variations and order shuffled
+ enforce(p.pop(false) == 901, "Test 5 failed");
+ enforce(p.pop(pInt) == 902, "Test 6 failed");
+ enforce(p.pop() == 905, "Test 7 failed");
+
+ // Overload on const only
+ enforce(p.bop(pInt) == 1001, "Test 8 failed");
+ enforce(p.bip(pInt) == 2001, "Test 9 failed");
+
+ // Globals
+ enforce(muzak(false) == 3001, "Test 10 failed");
+ enforce(muzak(pInt) == 3002, "Test 11 failed");
+}
diff --git a/Examples/test-suite/d/overload_template_runme.1.d b/Examples/test-suite/d/overload_template_runme.1.d
new file mode 100644
index 000000000..a1fe8012f
--- /dev/null
+++ b/Examples/test-suite/d/overload_template_runme.1.d
@@ -0,0 +1,146 @@
+module overload_template_runme;
+
+import overload_template.overload_template;
+import overload_template.Klass;
+
+void main() {
+ int f = foo();
+
+ f += maximum(3,4);
+ double b = maximum(3.4,5.2);
+ b++; // warning suppression
+
+ // mix 1
+ if (mix1("hi") != 101)
+ throw new Exception ("mix1(const char*)");
+
+ if (mix1(1.0, 1.0) != 102)
+ throw new Exception ("mix1(double, const double &)");
+
+ if (mix1(1.0) != 103)
+ throw new Exception ("mix1(double)");
+
+ // mix 2
+ if (mix2("hi") != 101)
+ throw new Exception ("mix2(const char*)");
+
+ if (mix2(1.0, 1.0) != 102)
+ throw new Exception ("mix2(double, const double &)");
+
+ if (mix2(1.0) != 103)
+ throw new Exception ("mix2(double)");
+
+ // mix 3
+ if (mix3("hi") != 101)
+ throw new Exception ("mix3(const char*)");
+
+ if (mix3(1.0, 1.0) != 102)
+ throw new Exception ("mix3(double, const double &)");
+
+ if (mix3(1.0) != 103)
+ throw new Exception ("mix3(double)");
+
+ // Combination 1
+ if (overtparams1(100) != 10)
+ throw new Exception ("overtparams1(int)");
+
+ if (overtparams1(100.0, 100) != 20)
+ throw new Exception ("overtparams1(double, int)");
+
+ // Combination 2
+ if (overtparams2(100.0, 100) != 40)
+ throw new Exception ("overtparams2(double, int)");
+
+ // Combination 3
+ if (overloaded() != 60)
+ throw new Exception ("overloaded()");
+
+ if (overloaded(100.0, 100) != 70)
+ throw new Exception ("overloaded(double, int)");
+
+ // Combination 4
+ if (overloadedagain("hello") != 80)
+ throw new Exception ("overloadedagain(const char *)");
+
+ if (overloadedagain() != 90)
+ throw new Exception ("overloadedagain(double)");
+
+ // specializations
+ if (specialization(10) != 202)
+ throw new Exception ("specialization(int)");
+
+ if (specialization(10.0) != 203)
+ throw new Exception ("specialization(double)");
+
+ if (specialization(10, 10) != 204)
+ throw new Exception ("specialization(int, int)");
+
+ if (specialization(10.0, 10.0) != 205)
+ throw new Exception ("specialization(double, double)");
+
+ if (specialization("hi", "hi") != 201)
+ throw new Exception ("specialization(const char *, const char *)");
+
+ // simple specialization
+ xyz();
+ xyz_int();
+ xyz_double();
+
+ // a bit of everything
+ if (overload("hi") != 0)
+ throw new Exception ("overload()");
+
+ if (overload(1) != 10)
+ throw new Exception ("overload(int t)");
+
+ if (overload(1, 1) != 20)
+ throw new Exception ("overload(int t, const int &)");
+
+ if (overload(1, "hello") != 30)
+ throw new Exception ("overload(int t, const char *)");
+
+ auto k = new Klass();
+ if (overload(k) != 10)
+ throw new Exception ("overload(Klass t)");
+
+ if (overload(k, k) != 20)
+ throw new Exception ("overload(Klass t, const Klass &)");
+
+ if (overload(k, "hello") != 30)
+ throw new Exception ("overload(Klass t, const char *)");
+
+ if (overload(10.0, "hi") != 40)
+ throw new Exception ("overload(double t, const char *)");
+
+ if (overload() != 50)
+ throw new Exception ("overload(const char *)");
+
+
+ // everything put in a namespace
+ if (nsoverload("hi") != 1000)
+ throw new Exception ("nsoverload()");
+
+ if (nsoverload(1) != 1010)
+ throw new Exception ("nsoverload(int t)");
+
+ if (nsoverload(1, 1) != 1020)
+ throw new Exception ("nsoverload(int t, const int &)");
+
+ if (nsoverload(1, "hello") != 1030)
+ throw new Exception ("nsoverload(int t, const char *)");
+
+ if (nsoverload(k) != 1010)
+ throw new Exception ("nsoverload(Klass t)");
+
+ if (nsoverload(k, k) != 1020)
+ throw new Exception ("nsoverload(Klass t, const Klass &)");
+
+ if (nsoverload(k, "hello") != 1030)
+ throw new Exception ("nsoverload(Klass t, const char *)");
+
+ if (nsoverload(10.0, "hi") != 1040)
+ throw new Exception ("nsoverload(double t, const char *)");
+
+ if (nsoverload() != 1050)
+ throw new Exception ("nsoverload(const char *)");
+}
diff --git a/Examples/test-suite/d/overload_template_runme.2.d b/Examples/test-suite/d/overload_template_runme.2.d
new file mode 100644
index 000000000..9fe6eb2cf
--- /dev/null
+++ b/Examples/test-suite/d/overload_template_runme.2.d
@@ -0,0 +1,80 @@
+module overload_template_runme;
+
+import std.exception;
+import overload_template.overload_template;
+import overload_template.Klass;
+
+void main() {
+ int f = foo();
+
+ f += maximum(3,4);
+ double b = maximum(3.4,5.2);
+ b++; // warning suppression
+
+ // mix 1
+ enforce(mix1("hi") == 101, "mix1(const char*)");
+ enforce(mix1(1.0, 1.0) == 102, "mix1(double, const double &)");
+ enforce(mix1(1.0) == 103, "mix1(double)");
+
+ // mix 2
+ enforce(mix2("hi") == 101, "mix2(const char*)");
+ enforce(mix2(1.0, 1.0) == 102, "mix2(double, const double &)");
+ enforce(mix2(1.0) == 103, "mix2(double)");
+
+ // mix 3
+ enforce(mix3("hi") == 101, "mix3(const char*)");
+ enforce(mix3(1.0, 1.0) == 102, "mix3(double, const double &)");
+ enforce(mix3(1.0) == 103, "mix3(double)");
+
+ // Combination 1
+ enforce(overtparams1(100) == 10, "overtparams1(int)");
+ enforce(overtparams1(100.0, 100) == 20, "overtparams1(double, int)");
+
+ // Combination 2
+ enforce(overtparams2(100.0, 100) == 40, "overtparams2(double, int)");
+
+ // Combination 3
+ enforce(overloaded() == 60, "overloaded()");
+ enforce(overloaded(100.0, 100) == 70, "overloaded(double, int)");
+
+ // Combination 4
+ enforce(overloadedagain("hello") == 80, "overloadedagain(const char *)");
+ enforce(overloadedagain() == 90, "overloadedagain(double)");
+
+ // specializations
+ enforce(specialization(10) == 202, "specialization(int)");
+ enforce(specialization(10.0) == 203, "specialization(double)");
+ enforce(specialization(10, 10) == 204, "specialization(int, int)");
+ enforce(specialization(10.0, 10.0) == 205, "specialization(double, double)");
+ enforce(specialization("hi", "hi") == 201, "specialization(const char *, const char *)");
+
+ // simple specialization
+ xyz();
+ xyz_int();
+ xyz_double();
+
+ // a bit of everything
+ enforce(overload("hi") == 0, "overload()");
+ enforce(overload(1) == 10, "overload(int t)");
+ enforce(overload(1, 1) == 20, "overload(int t, const int &)");
+ enforce(overload(1, "hello") == 30, "overload(int t, const char *)");
+
+ auto k = new Klass();
+ enforce(overload(k) == 10, "overload(Klass t)");
+ enforce(overload(k, k) == 20, "overload(Klass t, const Klass &)");
+ enforce(overload(k, "hello") == 30, "overload(Klass t, const char *)");
+ enforce(overload(10.0, "hi") == 40, "overload(double t, const char *)");
+ enforce(overload() == 50, "overload(const char *)");
+
+
+ // everything put in a namespace
+ enforce(nsoverload("hi") == 1000, "nsoverload()");
+ enforce(nsoverload(1) == 1010, "nsoverload(int t)");
+ enforce(nsoverload(1, 1) == 1020, "nsoverload(int t, const int &)");
+ enforce(nsoverload(1, "hello") == 1030, "nsoverload(int t, const char *)");
+ enforce(nsoverload(k) == 1010, "nsoverload(Klass t)");
+ enforce(nsoverload(k, k) == 1020, "nsoverload(Klass t, const Klass &)");
+ enforce(nsoverload(k, "hello") == 1030, "nsoverload(Klass t, const char *)");
+ enforce(nsoverload(10.0, "hi") == 1040, "nsoverload(double t, const char *)");
+ enforce(nsoverload() == 1050, "nsoverload(const char *)");
+}
diff --git a/Examples/test-suite/d/pointer_reference_runme.1.d b/Examples/test-suite/d/pointer_reference_runme.1.d
new file mode 100644
index 000000000..c593b939c
--- /dev/null
+++ b/Examples/test-suite/d/pointer_reference_runme.1.d
@@ -0,0 +1,13 @@
+module pointer_reference_runme;
+
+import pointer_reference.pointer_reference;
+import pointer_reference.Struct;
+
+void main() {
+ Struct s = get();
+ if (s.value != 10) throw new Exception("get test failed");
+
+ Struct ss = new Struct(20);
+ set(ss);
+ if (Struct.instance.value != 20) throw new Exception("set test failed");
+}
diff --git a/Examples/test-suite/d/pointer_reference_runme.2.d b/Examples/test-suite/d/pointer_reference_runme.2.d
new file mode 100644
index 000000000..8f287dfbd
--- /dev/null
+++ b/Examples/test-suite/d/pointer_reference_runme.2.d
@@ -0,0 +1,14 @@
+module pointer_reference_runme;
+
+import std.exception;
+import pointer_reference.pointer_reference;
+import pointer_reference.Struct;
+
+void main() {
+ Struct s = get();
+ enforce(s.value == 10, "get test failed");
+
+ auto ss = new Struct(20);
+ set(ss);
+ enforce(Struct.instance.value == 20, "set test failed");
+}
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.1.d b/Examples/test-suite/d/preproc_constants_c_runme.1.d
new file mode 100644
index 000000000..f25bbfdee
--- /dev/null
+++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d
@@ -0,0 +1,63 @@
+module preproc_constants_c_runme;
+
+import preproc_constants_c.preproc_constants_c;
+
+// Same as preproc_constants.i testcase, but bool types are int instead.
+void main() {
+ static assert(is(int == typeof(CONST_INT1())));
+ static assert(is(int == typeof(CONST_INT2())));
+ static assert(is(uint == typeof(CONST_UINT1())));
+ static assert(is(uint == typeof(CONST_UINT2())));
+ static assert(is(uint == typeof(CONST_UINT3())));
+ static assert(is(uint == typeof(CONST_UINT4())));
+ static assert(is(int == typeof(CONST_LONG1())));
+ static assert(is(int == typeof(CONST_LONG2())));
+ static assert(is(int == typeof(CONST_LONG3())));
+ static assert(is(int == typeof(CONST_LONG4())));
+ static assert(is(long == typeof(CONST_LLONG1())));
+ static assert(is(long == typeof(CONST_LLONG2())));
+ static assert(is(long == typeof(CONST_LLONG3())));
+ static assert(is(long == typeof(CONST_LLONG4())));
+ static assert(is(ulong == typeof(CONST_ULLONG1())));
+ static assert(is(ulong == typeof(CONST_ULLONG2())));
+ static assert(is(ulong == typeof(CONST_ULLONG3())));
+ static assert(is(ulong == typeof(CONST_ULLONG4())));
+ static assert(is(double == typeof(CONST_DOUBLE1())));
+ static assert(is(double == typeof(CONST_DOUBLE2())));
+ static assert(is(double == typeof(CONST_DOUBLE3())));
+ static assert(is(double == typeof(CONST_DOUBLE4())));
+ static assert(is(double == typeof(CONST_DOUBLE5())));
+ static assert(is(double == typeof(CONST_DOUBLE6())));
+ static assert(is(int == typeof(CONST_BOOL1())));
+ static assert(is(int == typeof(CONST_BOOL2())));
+ static assert(is(char == typeof(CONST_CHAR())));
+ static assert(is(char[] == typeof(CONST_STRING1())));
+ static assert(is(char[] == typeof(CONST_STRING2())));
+
+ static assert(is(int == typeof(INT_AND_BOOL())));
+// static assert(is(int == typeof(INT_AND_CHAR())));
+ static assert(is(int == typeof(INT_AND_INT())));
+ static assert(is(uint == typeof(INT_AND_UINT())));
+ static assert(is(int == typeof(INT_AND_LONG())));
+ static assert(is(uint == typeof(INT_AND_ULONG())));
+ static assert(is(long == typeof(INT_AND_LLONG())));
+ static assert(is(ulong == typeof(INT_AND_ULLONG())));
+ static assert(is(int == typeof(BOOL_AND_BOOL())));
+
+ static assert(is(int == typeof(EXPR_MULTIPLY())));
+ static assert(is(int == typeof(EXPR_DIVIDE())));
+ static assert(is(int == typeof(EXPR_PLUS())));
+ static assert(is(int == typeof(EXPR_MINUS())));
+ static assert(is(int == typeof(EXPR_LSHIFT())));
+ static assert(is(int == typeof(EXPR_RSHIFT())));
+ static assert(is(int == typeof(EXPR_LTE())));
+ static assert(is(int == typeof(EXPR_GTE())));
+ static assert(is(int == typeof(EXPR_INEQUALITY())));
+ static assert(is(int == typeof(EXPR_EQUALITY())));
+ static assert(is(int == typeof(EXPR_AND())));
+ static assert(is(int == typeof(EXPR_XOR())));
+ static assert(is(int == typeof(EXPR_OR())));
+ static assert(is(int == typeof(EXPR_LAND())));
+ static assert(is(int == typeof(EXPR_LOR())));
+ static assert(is(double == typeof(EXPR_CONDITIONAL())));
+}
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.2.d b/Examples/test-suite/d/preproc_constants_c_runme.2.d
new file mode 100644
index 000000000..07d6ac53d
--- /dev/null
+++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d
@@ -0,0 +1,63 @@
+module preproc_constants_c_runme;
+
+import preproc_constants_c.preproc_constants_c;
+
+// Same as preproc_constants.i testcase, but bool types are int instead.
+void main() {
+ static assert(is(int == typeof(CONST_INT1())));
+ static assert(is(int == typeof(CONST_INT2())));
+ static assert(is(uint == typeof(CONST_UINT1())));
+ static assert(is(uint == typeof(CONST_UINT2())));
+ static assert(is(uint == typeof(CONST_UINT3())));
+ static assert(is(uint == typeof(CONST_UINT4())));
+ static assert(is(int == typeof(CONST_LONG1())));
+ static assert(is(int == typeof(CONST_LONG2())));
+ static assert(is(int == typeof(CONST_LONG3())));
+ static assert(is(int == typeof(CONST_LONG4())));
+ static assert(is(long == typeof(CONST_LLONG1())));
+ static assert(is(long == typeof(CONST_LLONG2())));
+ static assert(is(long == typeof(CONST_LLONG3())));
+ static assert(is(long == typeof(CONST_LLONG4())));
+ static assert(is(ulong == typeof(CONST_ULLONG1())));
+ static assert(is(ulong == typeof(CONST_ULLONG2())));
+ static assert(is(ulong == typeof(CONST_ULLONG3())));
+ static assert(is(ulong == typeof(CONST_ULLONG4())));
+ static assert(is(double == typeof(CONST_DOUBLE1())));
+ static assert(is(double == typeof(CONST_DOUBLE2())));
+ static assert(is(double == typeof(CONST_DOUBLE3())));
+ static assert(is(double == typeof(CONST_DOUBLE4())));
+ static assert(is(double == typeof(CONST_DOUBLE5())));
+ static assert(is(double == typeof(CONST_DOUBLE6())));
+ static assert(is(int == typeof(CONST_BOOL1())));
+ static assert(is(int == typeof(CONST_BOOL2())));
+ static assert(is(char == typeof(CONST_CHAR())));
+ static assert(is(string == typeof(CONST_STRING1())));
+ static assert(is(string == typeof(CONST_STRING2())));
+
+ static assert(is(int == typeof(INT_AND_BOOL())));
+// static assert(is(int == typeof(INT_AND_CHAR())));
+ static assert(is(int == typeof(INT_AND_INT())));
+ static assert(is(uint == typeof(INT_AND_UINT())));
+ static assert(is(int == typeof(INT_AND_LONG())));
+ static assert(is(uint == typeof(INT_AND_ULONG())));
+ static assert(is(long == typeof(INT_AND_LLONG())));
+ static assert(is(ulong == typeof(INT_AND_ULLONG())));
+ static assert(is(int == typeof(BOOL_AND_BOOL())));
+
+ static assert(is(int == typeof(EXPR_MULTIPLY())));
+ static assert(is(int == typeof(EXPR_DIVIDE())));
+ static assert(is(int == typeof(EXPR_PLUS())));
+ static assert(is(int == typeof(EXPR_MINUS())));
+ static assert(is(int == typeof(EXPR_LSHIFT())));
+ static assert(is(int == typeof(EXPR_RSHIFT())));
+ static assert(is(int == typeof(EXPR_LTE())));
+ static assert(is(int == typeof(EXPR_GTE())));
+ static assert(is(int == typeof(EXPR_INEQUALITY())));
+ static assert(is(int == typeof(EXPR_EQUALITY())));
+ static assert(is(int == typeof(EXPR_AND())));
+ static assert(is(int == typeof(EXPR_XOR())));
+ static assert(is(int == typeof(EXPR_OR())));
+ static assert(is(int == typeof(EXPR_LAND())));
+ static assert(is(int == typeof(EXPR_LOR())));
+ static assert(is(double == typeof(EXPR_CONDITIONAL())));
+}
diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d
new file mode 100644
index 000000000..a2aaa8fcd
--- /dev/null
+++ b/Examples/test-suite/d/preproc_constants_runme.1.d
@@ -0,0 +1,62 @@
+module preproc_constants_runme;
+
+import preproc_constants.preproc_constants;
+
+void main() {
+ static assert(is(int == typeof(CONST_INT1())));
+ static assert(is(int == typeof(CONST_INT2())));
+ static assert(is(uint == typeof(CONST_UINT1())));
+ static assert(is(uint == typeof(CONST_UINT2())));
+ static assert(is(uint == typeof(CONST_UINT3())));
+ static assert(is(uint == typeof(CONST_UINT4())));
+ static assert(is(int == typeof(CONST_LONG1())));
+ static assert(is(int == typeof(CONST_LONG2())));
+ static assert(is(int == typeof(CONST_LONG3())));
+ static assert(is(int == typeof(CONST_LONG4())));
+ static assert(is(long == typeof(CONST_LLONG1())));
+ static assert(is(long == typeof(CONST_LLONG2())));
+ static assert(is(long == typeof(CONST_LLONG3())));
+ static assert(is(long == typeof(CONST_LLONG4())));
+ static assert(is(ulong == typeof(CONST_ULLONG1())));
+ static assert(is(ulong == typeof(CONST_ULLONG2())));
+ static assert(is(ulong == typeof(CONST_ULLONG3())));
+ static assert(is(ulong == typeof(CONST_ULLONG4())));
+ static assert(is(double == typeof(CONST_DOUBLE1())));
+ static assert(is(double == typeof(CONST_DOUBLE2())));
+ static assert(is(double == typeof(CONST_DOUBLE3())));
+ static assert(is(double == typeof(CONST_DOUBLE4())));
+ static assert(is(double == typeof(CONST_DOUBLE5())));
+ static assert(is(double == typeof(CONST_DOUBLE6())));
+ static assert(is(bool == typeof(CONST_BOOL1())));
+ static assert(is(bool == typeof(CONST_BOOL2())));
+ static assert(is(char == typeof(CONST_CHAR())));
+ static assert(is(char[] == typeof(CONST_STRING1())));
+ static assert(is(char[] == typeof(CONST_STRING2())));
+
+ static assert(is(int == typeof(INT_AND_BOOL())));
+// static assert(is(int == typeof(INT_AND_CHAR())));
+ static assert(is(int == typeof(INT_AND_INT())));
+ static assert(is(uint == typeof(INT_AND_UINT())));
+ static assert(is(int == typeof(INT_AND_LONG())));
+ static assert(is(uint == typeof(INT_AND_ULONG())));
+ static assert(is(long == typeof(INT_AND_LLONG())));
+ static assert(is(ulong == typeof(INT_AND_ULLONG())));
+ static assert(is(int == typeof(BOOL_AND_BOOL())));
+
+ static assert(is(int == typeof(EXPR_MULTIPLY())));
+ static assert(is(int == typeof(EXPR_DIVIDE())));
+ static assert(is(int == typeof(EXPR_PLUS())));
+ static assert(is(int == typeof(EXPR_MINUS())));
+ static assert(is(int == typeof(EXPR_LSHIFT())));
+ static assert(is(int == typeof(EXPR_RSHIFT())));
+ static assert(is(bool == typeof(EXPR_LTE())));
+ static assert(is(bool == typeof(EXPR_GTE())));
+ static assert(is(bool == typeof(EXPR_INEQUALITY())));
+ static assert(is(bool == typeof(EXPR_EQUALITY())));
+ static assert(is(int == typeof(EXPR_AND())));
+ static assert(is(int == typeof(EXPR_XOR())));
+ static assert(is(int == typeof(EXPR_OR())));
+ static assert(is(bool == typeof(EXPR_LAND())));
+ static assert(is(bool == typeof(EXPR_LOR())));
+ static assert(is(double == typeof(EXPR_CONDITIONAL())));
+}
diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d
new file mode 100644
index 000000000..e2eab2c46
--- /dev/null
+++ b/Examples/test-suite/d/preproc_constants_runme.2.d
@@ -0,0 +1,62 @@
+module preproc_constants_runme;
+
+import preproc_constants.preproc_constants;
+
+void main() {
+ static assert(is(int == typeof(CONST_INT1())));
+ static assert(is(int == typeof(CONST_INT2())));
+ static assert(is(uint == typeof(CONST_UINT1())));
+ static assert(is(uint == typeof(CONST_UINT2())));
+ static assert(is(uint == typeof(CONST_UINT3())));
+ static assert(is(uint == typeof(CONST_UINT4())));
+ static assert(is(int == typeof(CONST_LONG1())));
+ static assert(is(int == typeof(CONST_LONG2())));
+ static assert(is(int == typeof(CONST_LONG3())));
+ static assert(is(int == typeof(CONST_LONG4())));
+ static assert(is(long == typeof(CONST_LLONG1())));
+ static assert(is(long == typeof(CONST_LLONG2())));
+ static assert(is(long == typeof(CONST_LLONG3())));
+ static assert(is(long == typeof(CONST_LLONG4())));
+ static assert(is(ulong == typeof(CONST_ULLONG1())));
+ static assert(is(ulong == typeof(CONST_ULLONG2())));
+ static assert(is(ulong == typeof(CONST_ULLONG3())));
+ static assert(is(ulong == typeof(CONST_ULLONG4())));
+ static assert(is(double == typeof(CONST_DOUBLE1())));
+ static assert(is(double == typeof(CONST_DOUBLE2())));
+ static assert(is(double == typeof(CONST_DOUBLE3())));
+ static assert(is(double == typeof(CONST_DOUBLE4())));
+ static assert(is(double == typeof(CONST_DOUBLE5())));
+ static assert(is(double == typeof(CONST_DOUBLE6())));
+ static assert(is(bool == typeof(CONST_BOOL1())));
+ static assert(is(bool == typeof(CONST_BOOL2())));
+ static assert(is(char == typeof(CONST_CHAR())));
+ static assert(is(string == typeof(CONST_STRING1())));
+ static assert(is(string == typeof(CONST_STRING2())));
+
+ static assert(is(int == typeof(INT_AND_BOOL())));
+// static assert(is(int == typeof(INT_AND_CHAR())));
+ static assert(is(int == typeof(INT_AND_INT())));
+ static assert(is(uint == typeof(INT_AND_UINT())));
+ static assert(is(int == typeof(INT_AND_LONG())));
+ static assert(is(uint == typeof(INT_AND_ULONG())));
+ static assert(is(long == typeof(INT_AND_LLONG())));
+ static assert(is(ulong == typeof(INT_AND_ULLONG())));
+ static assert(is(int == typeof(BOOL_AND_BOOL())));
+
+ static assert(is(int == typeof(EXPR_MULTIPLY())));
+ static assert(is(int == typeof(EXPR_DIVIDE())));
+ static assert(is(int == typeof(EXPR_PLUS())));
+ static assert(is(int == typeof(EXPR_MINUS())));
+ static assert(is(int == typeof(EXPR_LSHIFT())));
+ static assert(is(int == typeof(EXPR_RSHIFT())));
+ static assert(is(bool == typeof(EXPR_LTE())));
+ static assert(is(bool == typeof(EXPR_GTE())));
+ static assert(is(bool == typeof(EXPR_INEQUALITY())));
+ static assert(is(bool == typeof(EXPR_EQUALITY())));
+ static assert(is(int == typeof(EXPR_AND())));
+ static assert(is(int == typeof(EXPR_XOR())));
+ static assert(is(int == typeof(EXPR_OR())));
+ static assert(is(bool == typeof(EXPR_LAND())));
+ static assert(is(bool == typeof(EXPR_LOR())));
+ static assert(is(double == typeof(EXPR_CONDITIONAL())));
+}
diff --git a/Examples/test-suite/d/sizet_runme.1.d b/Examples/test-suite/d/sizet_runme.1.d
new file mode 100644
index 000000000..ae42e20e5
--- /dev/null
+++ b/Examples/test-suite/d/sizet_runme.1.d
@@ -0,0 +1,15 @@
+module sizet_runme;
+
+import sizet.sizet;
+
+void main() {
+ size_t s = 2000;
+ s = test1(s+1);
+ s = test2(s+1);
+ s = test3(s+1);
+ s = test4(s+1);
+
+ if (s != 2004) {
+ throw new Exception("failed");
+ }
+}
diff --git a/Examples/test-suite/d/sizet_runme.2.d b/Examples/test-suite/d/sizet_runme.2.d
new file mode 100644
index 000000000..63eb03b21
--- /dev/null
+++ b/Examples/test-suite/d/sizet_runme.2.d
@@ -0,0 +1,14 @@
+module sizet_runme;
+
+import std.exception;
+import sizet.sizet;
+
+void main() {
+ size_t s = 2000;
+ s = test1(s+1);
+ s = test2(s+1);
+ s = test3(s+1);
+ s = test4(s+1);
+
+ enforce(s == 2004, "failed");
+}
diff --git a/Examples/test-suite/d/sneaky1_runme.1.d b/Examples/test-suite/d/sneaky1_runme.1.d
new file mode 100644
index 000000000..b293b4972
--- /dev/null
+++ b/Examples/test-suite/d/sneaky1_runme.1.d
@@ -0,0 +1,21 @@
+module sneaky1_runme;
+
+import sneaky1.sneaky1;
+
+void main() {
+ if (add(30, 2) != 32) {
+ throw new Exception("add test failed");
+ }
+
+ if (subtract(20, 2) != 18) {
+ throw new Exception("subtract test failed");
+ }
+
+ if (mul(20, 2) != 40) {
+ throw new Exception("mul test failed");
+ }
+
+ if (divide(20, 2) != 10) {
+ throw new Exception("div test failed");
+ }
+}
diff --git a/Examples/test-suite/d/sneaky1_runme.2.d b/Examples/test-suite/d/sneaky1_runme.2.d
new file mode 100644
index 000000000..84e51e74d
--- /dev/null
+++ b/Examples/test-suite/d/sneaky1_runme.2.d
@@ -0,0 +1,11 @@
+module sneaky1_runme;
+
+import std.exception;
+import sneaky1.sneaky1;
+
+void main() {
+ enforce(add(30, 2) == 32, "add test failed");
+ enforce(subtract(20, 2) == 18, "subtract test failed");
+ enforce(mul(20, 2) == 40, "mul test failed");
+ enforce(divide(20, 2) == 10, "div test failed");
+}
diff --git a/Examples/test-suite/d/special_variable_macros_runme.1.d b/Examples/test-suite/d/special_variable_macros_runme.1.d
new file mode 100644
index 000000000..12491eef5
--- /dev/null
+++ b/Examples/test-suite/d/special_variable_macros_runme.1.d
@@ -0,0 +1,39 @@
+module special_variable_macros_runme;
+
+import special_variable_macros.special_variable_macros;
+import special_variable_macros.Name;
+import special_variable_macros.NewName;
+import special_variable_macros.PairIntBool;
+
+void main() {
+ auto name = new Name();
+
+ if (testFred(name) != "none") {
+ throw new Exception("test failed");
+ }
+
+ if (testJack(name) != "$specialname") {
+ throw new Exception("test failed");
+ }
+
+ if (testJill(name) != "jilly") {
+ throw new Exception("test failed");
+ }
+
+ if (testMary(name) != "SWIGTYPE_p_NameWrap") {
+ throw new Exception("test failed");
+ }
+
+ if (testJim(name) != "multiname num") {
+ throw new Exception("test failed");
+ }
+
+ if (testJohn(new PairIntBool(10, false)) != 123) {
+ throw new Exception("test failed");
+ }
+
+ auto newName = NewName.factory("factoryname");
+ if (newName.getStoredName().getName() != "factoryname") {
+ throw new Exception("test failed");
+ }
+}
diff --git a/Examples/test-suite/d/special_variable_macros_runme.2.d b/Examples/test-suite/d/special_variable_macros_runme.2.d
new file mode 100644
index 000000000..128e5870f
--- /dev/null
+++ b/Examples/test-suite/d/special_variable_macros_runme.2.d
@@ -0,0 +1,21 @@
+module special_variable_macros_runme;
+
+import std.exception;
+import special_variable_macros.special_variable_macros;
+import special_variable_macros.Name;
+import special_variable_macros.NewName;
+import special_variable_macros.PairIntBool;
+
+void main() {
+ auto name = new Name();
+ enforce(testFred(name) == "none");
+ enforce(testJack(name) == "$specialname");
+ enforce(testJill(name) == "jilly");
+ enforce(testMary(name) == "SWIGTYPE_p_NameWrap");
+ enforce(testJim(name) == "multiname num");
+
+ enforce(testJohn(new PairIntBool(10, false)) == 123);
+
+ auto newName = NewName.factory("factoryname");
+ enforce(newName.getStoredName().getName() == "factoryname");
+}
diff --git a/Examples/test-suite/d/threads_runme.1.d b/Examples/test-suite/d/threads_runme.1.d
new file mode 100644
index 000000000..206875824
--- /dev/null
+++ b/Examples/test-suite/d/threads_runme.1.d
@@ -0,0 +1,70 @@
+module threads_runme;
+
+import tango.core.Thread;
+import tango.io.Console;
+import Integer = tango.text.convert.Integer;
+import threads.Kerfuffle;
+
+// Spawn 8 threads.
+const uint NUM_THREADS = 8;
+
+// Run test for a few seconds on a 1GHz machine.
+const uint WORKER_LOOP_PASSES = 30000;
+
+void main() {
+ auto kerf = new Kerfuffle();
+ TestThread[] threads;
+
+ // Invoke the threads.
+ for (uint i = 0; i < NUM_THREADS; i++) {
+ auto thread = new TestThread(kerf);
+ threads ~= thread;
+ thread.name = Integer.toString(i);
+ thread.start();
+ }
+
+ // Wait for the threads to finish.
+ foreach(thread; threads) {
+ thread.join();
+ }
+
+ // Check if any thread has failed.
+ foreach(thread; threads) {
+ if (thread.failed) throw new Exception("Test failed.");
+ }
+}
+
+class TestThread : Thread {
+public:
+ this(Kerfuffle kerf) {
+ super(&run);
+ m_kerf = kerf;
+ }
+
+ void run() {
+ failed = false;
+ try {
+ for (uint i = 0; i < WORKER_LOOP_PASSES; i++) {
+ char[] given = "This is the test char[] that should come back. A number: " ~ Integer.toString(i);
+ char[] received = m_kerf.StdString(given);
+ if (received != given) {
+ throw new Exception("StdString char[] does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'.");
+ }
+ }
+ for (uint i = 0; i < WORKER_LOOP_PASSES; i++) {
+ char[] given = "This is the test char[] that should come back. A number: " ~ Integer.toString(i);
+ char[] received = m_kerf.CharString(given);
+ if (received != given) {
+ throw new Exception("StdString char[] does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'.");
+ }
+ }
+ } catch (Exception e) {
+ Cerr("Test failed (thread " ~ name() ~ "): " ~ e.msg).newline;
+ failed = true;
+ }
+ }
+
+ bool failed;
+private:
+ Kerfuffle m_kerf;
+}
diff --git a/Examples/test-suite/d/threads_runme.2.d b/Examples/test-suite/d/threads_runme.2.d
new file mode 100644
index 000000000..3ac27a5a8
--- /dev/null
+++ b/Examples/test-suite/d/threads_runme.2.d
@@ -0,0 +1,55 @@
+module threads_runme;
+
+import core.thread;
+import std.conv;
+import std.exception;
+import std.range;
+import std.stdio;
+import threads.Kerfuffle;
+
+// Spawn 8 threads.
+enum THREADS = iota(0, 9);
+
+// Run test for a few seconds on a 1GHz machine.
+enum WORK_RANGE = iota(0, 30000);
+
+void main() {
+ auto kerf = new Kerfuffle();
+ TestThread[] threads;
+
+ // Invoke the threads.
+ foreach (i; THREADS) {
+ auto thread = new TestThread(kerf);
+ threads ~= thread;
+ thread.name = to!string(i);
+ thread.start();
+ }
+
+ // Wait for the threads to finish.
+ foreach (i, thread; threads) {
+ thread.join(true);
+ }
+}
+
+class TestThread : Thread {
+ this(Kerfuffle kerf) {
+ super(&run);
+ m_kerf = kerf;
+ }
+
+ void run() {
+ foreach (i; WORK_RANGE) {
+ string given = "This is the test string that should come back. A number: " ~ to!string(i);
+ string received = m_kerf.StdString(given);
+ enforce(received == given, "StdString string does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'.");
+ }
+ foreach (i; WORK_RANGE) {
+ string given = "This is the test string that should come back. A number: " ~ to!string(i);
+ string received = m_kerf.CharString(given);
+ enforce(received == given, "CharString string does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'.");
+ }
+ }
+
+private:
+ Kerfuffle m_kerf;
+}
diff --git a/Examples/test-suite/d/throw_exception_runme.1.d b/Examples/test-suite/d/throw_exception_runme.1.d
new file mode 100644
index 000000000..f2397a202
--- /dev/null
+++ b/Examples/test-suite/d/throw_exception_runme.1.d
@@ -0,0 +1,30 @@
+module throw_exception_runme;
+
+import throw_exception.Foo;
+
+void main() {
+ test!("test_int");
+ test!("test_msg");
+ test!("test_cls");
+ test!("test_cls_ptr");
+ test!("test_cls_ref");
+ test!("test_cls_td");
+ test!("test_cls_ptr_td");
+ test!("test_cls_ref_td");
+ test!("test_array");
+ test!("test_enum");
+}
+
+void test(char[] methodName)() {
+ auto foo = new Foo();
+
+ bool didntThrow;
+ try {
+ mixin("foo." ~ methodName ~ "();");
+ didntThrow = true;
+ } catch (Exception) {}
+
+ if (didntThrow) {
+ throw new Exception(methodName ~ " failed");
+ }
+}
diff --git a/Examples/test-suite/d/throw_exception_runme.2.d b/Examples/test-suite/d/throw_exception_runme.2.d
new file mode 100644
index 000000000..6fc82a93d
--- /dev/null
+++ b/Examples/test-suite/d/throw_exception_runme.2.d
@@ -0,0 +1,30 @@
+module throw_exception_runme;
+
+import throw_exception.Foo;
+
+void main() {
+ test!("test_int");
+ test!("test_msg");
+ test!("test_cls");
+ test!("test_cls_ptr");
+ test!("test_cls_ref");
+ test!("test_cls_td");
+ test!("test_cls_ptr_td");
+ test!("test_cls_ref_td");
+ test!("test_array");
+ test!("test_enum");
+}
+
+void test(string methodName)() {
+ auto foo = new Foo();
+
+ bool didntThrow;
+ try {
+ mixin("foo." ~ methodName ~ "();");
+ didntThrow = true;
+ } catch (Exception) {}
+
+ if (didntThrow) {
+ throw new Exception(methodName ~ " failed");
+ }
+}
diff --git a/Examples/test-suite/d/typemap_namespace_runme.1.d b/Examples/test-suite/d/typemap_namespace_runme.1.d
new file mode 100644
index 000000000..3a5ca1a9f
--- /dev/null
+++ b/Examples/test-suite/d/typemap_namespace_runme.1.d
@@ -0,0 +1,13 @@
+module typemap_namespace_runme;
+
+import typemap_namespace.typemap_namespace;
+
+void main() {
+ if (test1("hello") != "hello") {
+ throw new Exception("test1 failed");
+ }
+
+ if (test2("hello") != "hello") {
+ throw new Exception("test2 failed");
+ }
+}
diff --git a/Examples/test-suite/d/typemap_namespace_runme.2.d b/Examples/test-suite/d/typemap_namespace_runme.2.d
new file mode 100644
index 000000000..2281e403b
--- /dev/null
+++ b/Examples/test-suite/d/typemap_namespace_runme.2.d
@@ -0,0 +1,9 @@
+module typemap_namespace_runme;
+
+import std.exception;
+import typemap_namespace.typemap_namespace;
+
+void main() {
+ enforce(test1("hello") == "hello", "test1 failed");
+ enforce(test2("hello") == "hello", "test2 failed");
+}
diff --git a/Examples/test-suite/d/typemap_out_optimal_runme.1.d b/Examples/test-suite/d/typemap_out_optimal_runme.1.d
new file mode 100644
index 000000000..16aab3cff
--- /dev/null
+++ b/Examples/test-suite/d/typemap_out_optimal_runme.1.d
@@ -0,0 +1,9 @@
+module typemap_out_optimal_runme;
+
+import typemap_out_optimal.XX;
+
+void main() {
+ XX x;
+ XX.trace = false;
+ x = XX.create();
+}
diff --git a/Examples/test-suite/d/typemap_out_optimal_runme.2.d b/Examples/test-suite/d/typemap_out_optimal_runme.2.d
new file mode 100644
index 000000000..16aab3cff
--- /dev/null
+++ b/Examples/test-suite/d/typemap_out_optimal_runme.2.d
@@ -0,0 +1,9 @@
+module typemap_out_optimal_runme;
+
+import typemap_out_optimal.XX;
+
+void main() {
+ XX x;
+ XX.trace = false;
+ x = XX.create();
+}
diff --git a/Examples/test-suite/d/varargs_runme.1.d b/Examples/test-suite/d/varargs_runme.1.d
new file mode 100644
index 000000000..53f76d075
--- /dev/null
+++ b/Examples/test-suite/d/varargs_runme.1.d
@@ -0,0 +1,20 @@
+module varargs_runme;
+
+import varargs.varargs;
+import varargs.Foo;
+
+void main() {
+ if (test("Hello") != "Hello") {
+ throw new Exception("Test 1 failed");
+ }
+
+ auto f = new Foo("Greetings");
+
+ if (f.str != "Greetings") {
+ throw new Exception("Test 2 failed");
+ }
+
+ if (f.test("Hello") != "Hello") {
+ throw new Exception("Test 3 failed");
+ }
+}
diff --git a/Examples/test-suite/d/varargs_runme.2.d b/Examples/test-suite/d/varargs_runme.2.d
new file mode 100644
index 000000000..b2b5ceddc
--- /dev/null
+++ b/Examples/test-suite/d/varargs_runme.2.d
@@ -0,0 +1,13 @@
+module varargs_runme;
+
+import std.exception;
+import varargs.varargs;
+import varargs.Foo;
+
+void main() {
+ enforce(test("Hello") == "Hello", "Test 1 failed");
+
+ auto f = new Foo("Greetings");
+ enforce(f.str == "Greetings", "Test 2 failed");
+ enforce(f.test("Hello") == "Hello", "Test 3 failed");
+}
diff --git a/Examples/test-suite/d/virtual_poly_runme.1.d b/Examples/test-suite/d/virtual_poly_runme.1.d
new file mode 100644
index 000000000..fb2e7814d
--- /dev/null
+++ b/Examples/test-suite/d/virtual_poly_runme.1.d
@@ -0,0 +1,27 @@
+module virtual_poly_runme;
+
+import virtual_poly.NDouble;
+import virtual_poly.NInt;
+import virtual_poly.NNumber;
+
+void main() {
+ // D supports covariant (polymorphic) return types, so this should work like
+ // in C++.
+ auto d = new NDouble(3.5);
+ NDouble dc = d.copy();
+ if (d.get() != dc.get()) {
+ throw new Exception("Test 1 failed.");
+ }
+
+ auto i = new NInt(2);
+ NInt ic = i.copy();
+ if (i.get() != ic.get()) {
+ throw new Exception("Test 2 failed.");
+ }
+
+ NNumber n = d;
+ auto nd = cast(NDouble) n.copy();
+ if (nd.get() != d.get()) {
+ throw new Exception("Test 3 failed.");
+ }
+}
diff --git a/Examples/test-suite/d/virtual_poly_runme.2.d b/Examples/test-suite/d/virtual_poly_runme.2.d
new file mode 100644
index 000000000..f749ee236
--- /dev/null
+++ b/Examples/test-suite/d/virtual_poly_runme.2.d
@@ -0,0 +1,22 @@
+module virtual_poly_runme;
+
+import std.exception;
+import virtual_poly.NDouble;
+import virtual_poly.NInt;
+import virtual_poly.NNumber;
+
+void main() {
+ // D supports covariant (polymorphic) return types, so this should work like
+ // in C++.
+ auto d = new NDouble(3.5);
+ NDouble dc = d.copy();
+ enforce(d.get() == dc.get(), "Test 1 failed.");
+
+ auto i = new NInt(2);
+ NInt ic = i.copy();
+ enforce(i.get() == ic.get(), "Test 2 failed.");
+
+ NNumber n = d;
+ auto nd = cast(NDouble) n.copy();
+ enforce(nd.get() == d.get(), "Test 3 failed.");
+}
diff --git a/Examples/test-suite/d_nativepointers.i b/Examples/test-suite/d_nativepointers.i
new file mode 100644
index 000000000..b681844f5
--- /dev/null
+++ b/Examples/test-suite/d_nativepointers.i
@@ -0,0 +1,18 @@
+%module d_nativepointers;
+
+%inline %{
+ class SomeClass {
+ };
+ class OpaqueClass;
+ typedef void (*FuncA)(int **x, char ***y);
+ typedef void (*FuncB)(int **x, SomeClass *y);
+
+ int *a( int *value ){ return value; }
+ float **b( float **value ){ return value; }
+ char ***c( char ***value ){ return value; }
+ SomeClass *d( SomeClass *value ){ return value; }
+ SomeClass **e( SomeClass **value ){ return value; }
+ OpaqueClass *f( OpaqueClass *value ){ return value; }
+ FuncA g( FuncA value ){ return value; }
+ FuncB* h( FuncB* value ){ return value; }
+%}
diff --git a/Lib/allkw.swg b/Lib/allkw.swg
index fb76ff287..2e0dad6cf 100644
--- a/Lib/allkw.swg
+++ b/Lib/allkw.swg
@@ -18,6 +18,7 @@
%include <chicken/chickenkw.swg>
%include <csharp/csharpkw.swg>
+%include <d/dkw.swg>
%include <java/javakw.swg>
%include <php/phpkw.swg>
%include <pike/pikekw.swg>
diff --git a/Lib/d/boost_shared_ptr.i b/Lib/d/boost_shared_ptr.i
new file mode 100644
index 000000000..97feee5cb
--- /dev/null
+++ b/Lib/d/boost_shared_ptr.i
@@ -0,0 +1,201 @@
+%include <shared_ptr.i>
+
+%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
+
+%naturalvar TYPE;
+%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
+
+// destructor mods
+%feature("unref") TYPE
+//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ((*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\"))) << \"]\" << endl << flush; }\n"
+ "(void)arg1; delete smartarg1;"
+
+
+// plain value
+%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{
+ argp = ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0;
+ if (!argp) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
+ return $null;
+ }
+ $1 = *argp; %}
+%typemap(out) CONST TYPE
+%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
+
+// plain pointer
+%typemap(in, canthrow=1) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
+ smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input;
+ $1 = (TYPE *)(smartarg ? smartarg->get() : 0); %}
+%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
+ $result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
+%}
+
+// plain reference
+%typemap(in, canthrow=1) CONST TYPE & %{
+ $1 = ($1_ltype)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
+ if (!$1) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type reference is null");
+ return $null;
+ } %}
+%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
+%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
+
+// plain pointer by reference
+%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
+%{ temp = (TYPE *)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
+ $1 = &temp; %}
+%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
+%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
+
+// shared_ptr by value
+%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
+%{ if ($input) $1 = *($&1_ltype)$input; %}
+%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
+%{ $result = $1 ? new $1_ltype($1) : 0; %}
+
+// shared_ptr by reference
+%typemap(in, canthrow=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & ($*1_ltype tempnull)
+%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
+%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &
+%{ $result = *$1 ? new $*1_ltype(*$1) : 0; %}
+
+// shared_ptr by pointer
+%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
+%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
+%typemap(out, fragment="SWIG_null_deleter") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
+%{ $result = ($1 && *$1) ? new $*1_ltype(*($1_ltype)$1) : 0;
+ if ($owner) delete $1; %}
+
+// shared_ptr by pointer reference
+%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempnull, $*1_ltype temp = 0)
+%{ temp = $input ? *($1_ltype)&$input : &tempnull;
+ $1 = &temp; %}
+%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
+%{ *($1_ltype)&$result = (*$1 && **$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %}
+
+// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
+%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
+#error "typemaps for $1_type not available"
+%}
+%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
+#error "typemaps for $1_type not available"
+%}
+
+
+%typemap (cwtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void *"
+%typemap (dwtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void*"
+%typemap (dptype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dptype, TYPE)"
+
+%typemap(din) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dptype, TYPE).swigGetCPtr($dinput)"
+
+%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+
+
+%typemap(dout, excode=SWIGEXCODE) CONST TYPE {
+ auto ret = new $typemap(dptype, TYPE)($wcall, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) CONST TYPE & {
+ auto ret = new $typemap(dptype, TYPE)($wcall, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) CONST TYPE * {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) TYPE *CONST& {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+
+// For shared pointers, both the derived and the base class have to »own« their
+// pointer; otherwise the reference count is not decreased properly on destruction.
+%typemap(dbody) SWIGTYPE %{
+private void* swigCPtr;
+private bool swigCMemOwn;
+
+public this(void* cObject, bool ownCObject) {
+ swigCPtr = cObject;
+ swigCMemOwn = ownCObject;
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+%typemap(dbody_derived) SWIGTYPE %{
+private void* swigCPtr;
+private bool swigCMemOwn;
+
+public this(void* cObject, bool ownCObject) {
+ super($wrapdmodule.$dclassnameSmartPtrUpcast(cObject), ownCObject);
+ swigCPtr = cObject;
+ swigCMemOwn = ownCObject;
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+%typemap(ddispose, methodname="dispose", methodmodifiers="public") TYPE {
+ synchronized(this) {
+ if (swigCPtr !is null) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $wcall;
+ }
+ swigCPtr = null;
+ }
+ }
+}
+
+%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") TYPE {
+ synchronized(this) {
+ if (swigCPtr !is null) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $wcall;
+ }
+ swigCPtr = null;
+ super.dispose();
+ }
+ }
+}
+
+%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
+%enddef
diff --git a/Lib/d/carrays.i b/Lib/d/carrays.i
new file mode 100644
index 000000000..9893d09e5
--- /dev/null
+++ b/Lib/d/carrays.i
@@ -0,0 +1,111 @@
+/* -----------------------------------------------------------------------------
+ * carrays.i
+ *
+ * D-specific version of ../carrays.i.
+ * ----------------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * %array_functions(TYPE,NAME)
+ *
+ * Generates functions for creating and accessing elements of a C array
+ * (as pointers). Creates the following functions:
+ *
+ * TYPE *new_NAME(int nelements)
+ * void delete_NAME(TYPE *);
+ * TYPE NAME_getitem(TYPE *, int index);
+ * void NAME_setitem(TYPE *, int index, TYPE value);
+ *
+ * ----------------------------------------------------------------------------- */
+
+%define %array_functions(TYPE,NAME)
+%{
+static TYPE *new_##NAME(int nelements) { %}
+#ifdef __cplusplus
+%{ return new TYPE[nelements]; %}
+#else
+%{ return (TYPE *) calloc(nelements,sizeof(TYPE)); %}
+#endif
+%{}
+
+static void delete_##NAME(TYPE *ary) { %}
+#ifdef __cplusplus
+%{ delete [] ary; %}
+#else
+%{ free(ary); %}
+#endif
+%{}
+
+static TYPE NAME##_getitem(TYPE *ary, int index) {
+ return ary[index];
+}
+static void NAME##_setitem(TYPE *ary, int index, TYPE value) {
+ ary[index] = value;
+}
+%}
+
+TYPE *new_##NAME(int nelements);
+void delete_##NAME(TYPE *ary);
+TYPE NAME##_getitem(TYPE *ary, int index);
+void NAME##_setitem(TYPE *ary, int index, TYPE value);
+
+%enddef
+
+
+/* -----------------------------------------------------------------------------
+ * %array_class(TYPE,NAME)
+ *
+ * Generates a class wrapper around a C array. The class has the following
+ * interface:
+ *
+ * struct NAME {
+ * NAME(int nelements);
+ * ~NAME();
+ * TYPE getitem(int index);
+ * void setitem(int index, TYPE value);
+ * TYPE * ptr();
+ * static NAME *frompointer(TYPE *t);
+ * }
+ *
+ * ----------------------------------------------------------------------------- */
+
+%define %array_class(TYPE,NAME)
+%{
+typedef TYPE NAME;
+%}
+
+typedef struct NAME {} NAME;
+
+%extend NAME {
+#ifdef __cplusplus
+ NAME(int nelements) {
+ return new TYPE[nelements];
+ }
+ ~NAME() {
+ delete [] self;
+ }
+#else
+ NAME(int nelements) {
+ return (TYPE *) calloc(nelements,sizeof(TYPE));
+ }
+ ~NAME() {
+ free(self);
+ }
+#endif
+
+ TYPE getitem(int index) {
+ return self[index];
+ }
+ void setitem(int index, TYPE value) {
+ self[index] = value;
+ }
+ TYPE * ptr() {
+ return self;
+ }
+ static NAME *frompointer(TYPE *t) {
+ return (NAME *) t;
+ }
+};
+
+%types(NAME = TYPE);
+
+%enddef
diff --git a/Lib/d/cpointer.i b/Lib/d/cpointer.i
new file mode 100644
index 000000000..75e610f67
--- /dev/null
+++ b/Lib/d/cpointer.i
@@ -0,0 +1,171 @@
+/* -----------------------------------------------------------------------------
+ * cpointer.i
+ *
+ * D-specific version of ../cpointer.i.
+ * ----------------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * %pointer_class(type,name)
+ *
+ * Places a simple proxy around a simple type like 'int', 'float', or whatever.
+ * The proxy provides this interface:
+ *
+ * class type {
+ * public:
+ * type();
+ * ~type();
+ * type value();
+ * void assign(type value);
+ * };
+ *
+ * Example:
+ *
+ * %pointer_class(int, intp);
+ *
+ * int add(int *x, int *y) { return *x + *y; }
+ *
+ * In python (with proxies)
+ *
+ * >>> a = intp()
+ * >>> a.assign(10)
+ * >>> a.value()
+ * 10
+ * >>> b = intp()
+ * >>> b.assign(20)
+ * >>> print add(a,b)
+ * 30
+ *
+ * As a general rule, this macro should not be used on class/structures that
+ * are already defined in the interface.
+ * ----------------------------------------------------------------------------- */
+
+
+%define %pointer_class(TYPE, NAME)
+%{
+typedef TYPE NAME;
+%}
+
+typedef struct {
+} NAME;
+
+%extend NAME {
+#ifdef __cplusplus
+NAME() {
+ return new TYPE();
+}
+~NAME() {
+ if (self) delete self;
+}
+#else
+NAME() {
+ return (TYPE *) calloc(1,sizeof(TYPE));
+}
+~NAME() {
+ if (self) free(self);
+}
+#endif
+}
+
+%extend NAME {
+
+void assign(TYPE value) {
+ *self = value;
+}
+TYPE value() {
+ return *self;
+}
+TYPE * ptr() {
+ return self;
+}
+static NAME * frompointer(TYPE *t) {
+ return (NAME *) t;
+}
+
+}
+
+%types(NAME = TYPE);
+
+%enddef
+
+/* -----------------------------------------------------------------------------
+ * %pointer_functions(type,name)
+ *
+ * Create functions for allocating/deallocating pointers. This can be used
+ * if you don't want to create a proxy class or if the pointer is complex.
+ *
+ * %pointer_functions(int, intp)
+ *
+ * int add(int *x, int *y) { return *x + *y; }
+ *
+ * In python (with proxies)
+ *
+ * >>> a = copy_intp(10)
+ * >>> intp_value(a)
+ * 10
+ * >>> b = new_intp()
+ * >>> intp_assign(b,20)
+ * >>> print add(a,b)
+ * 30
+ * >>> delete_intp(a)
+ * >>> delete_intp(b)
+ *
+ * ----------------------------------------------------------------------------- */
+
+%define %pointer_functions(TYPE,NAME)
+%{
+static TYPE *new_##NAME() { %}
+#ifdef __cplusplus
+%{ return new TYPE(); %}
+#else
+%{ return (TYPE *) calloc(1,sizeof(TYPE)); %}
+#endif
+%{}
+
+static TYPE *copy_##NAME(TYPE value) { %}
+#ifdef __cplusplus
+%{ return new TYPE(value); %}
+#else
+%{ TYPE *self = (TYPE *) calloc(1,sizeof(TYPE));
+ *self = value;
+ return self; %}
+#endif
+%{}
+
+static void delete_##NAME(TYPE *self) { %}
+#ifdef __cplusplus
+%{ if (self) delete self; %}
+#else
+%{ if (self) free(self); %}
+#endif
+%{}
+
+static void NAME ##_assign(TYPE *self, TYPE value) {
+ *self = value;
+}
+
+static TYPE NAME ##_value(TYPE *self) {
+ return *self;
+}
+%}
+
+TYPE *new_##NAME();
+TYPE *copy_##NAME(TYPE value);
+void delete_##NAME(TYPE *self);
+void NAME##_assign(TYPE *self, TYPE value);
+TYPE NAME##_value(TYPE *self);
+
+%enddef
+
+/* -----------------------------------------------------------------------------
+ * %pointer_cast(type1,type2,name)
+ *
+ * Generates a pointer casting function.
+ * ----------------------------------------------------------------------------- */
+
+%define %pointer_cast(TYPE1,TYPE2,NAME)
+%inline %{
+TYPE2 NAME(TYPE1 x) {
+ return (TYPE2) x;
+}
+%}
+%enddef
diff --git a/Lib/d/d.swg b/Lib/d/d.swg
new file mode 100644
index 000000000..f5bb4596c
--- /dev/null
+++ b/Lib/d/d.swg
@@ -0,0 +1,46 @@
+/* -----------------------------------------------------------------------------
+ * d.swg
+ *
+ * Main library file for the D language module. See the D chapter in the SWIG
+ * manual for explanation on the typemaps, pragmas, etc. used.
+ * ----------------------------------------------------------------------------- */
+
+// Typemaps for exception handling.
+%include <dexception.swg>
+
+// Typemaps for primitive types.
+%include <dprimitives.swg>
+
+// Typemaps for non-primitive types (C/C++ classes and structs).
+%include <dswigtype.swg>
+
+// Typemaps for enumeration types.
+%include <denums.swg>
+
+// Typemaps for member function pointers.
+%include <dmemberfunctionpointers.swg>
+
+// Typemaps for wrapping pointers to/arrays of C chars as D strings.
+%include <dstrings.swg>
+
+// Typemaps for handling void function return types and empty parameter lists.
+%include <dvoid.swg>
+
+// Typemaps containing D code used when generating D proxy classes.
+%include <dclassgen.swg>
+
+// Mapping of C++ operator overloading methods to D.
+%include <doperators.swg>
+
+// Helper code string and exception handling.
+%include <dhead.swg>
+
+// Wrapper loader code for dynamically linking the C wrapper library from the D
+// wrapper module.
+%include <wrapperloader.swg>
+
+// List of all reserved D keywords.
+%include <dkw.swg>
+
+// D-specific directives.
+%include <ddirectives.swg>
diff --git a/Lib/d/dclassgen.swg b/Lib/d/dclassgen.swg
new file mode 100644
index 000000000..bc73d7b6a
--- /dev/null
+++ b/Lib/d/dclassgen.swg
@@ -0,0 +1,172 @@
+/* -----------------------------------------------------------------------------
+ * dclassgen.swg
+ *
+ * Typemaps containing D code used when generating D proxy classes.
+ * ----------------------------------------------------------------------------- */
+
+%typemap(dbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(dclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "class"
+%typemap(dcode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(dimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(dinterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(dinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+
+// See <denums.swg>.
+%typemap(dclassmodifiers) enum SWIGTYPE "enum"
+%typemap(dcode) enum SWIGTYPE ""
+
+
+/*
+ * Proxy classes.
+ */
+
+%typemap(dconstructor, excode=SWIGEXCODE,directorconnect="\n swigDirectorConnect();") SWIGTYPE {
+ this($wcall, true);$excode$directorconnect
+}
+
+%typemap(ddestructor) SWIGTYPE %{
+~this() {
+ dispose();
+}
+%}
+
+// We do not use »override« attribute for generated dispose() methods to stay
+// somewhat compatible to Phobos and older Tango versions where Object.dispose()
+// does not exist.
+%typemap(ddispose, methodname="dispose", methodmodifiers="public") SWIGTYPE {
+ synchronized(this) {
+ if (swigCPtr !is null) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $wcall;
+ }
+ swigCPtr = null;
+ }
+ }
+}
+
+%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") SWIGTYPE {
+ synchronized(this) {
+ if (swigCPtr !is null) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $wcall;
+ }
+ swigCPtr = null;
+ super.dispose();
+ }
+ }
+}
+
+%define SWIGD_CLASS_BODIES(OP_EQUALS_RETURN)
+// Unfortunately, the »package« visibility attribute does not work in D when the
+// module in question is in the root package (happens if no -package is specified
+// at the SWIG command line), so we are stuck with public visibility for
+// swigGetCPtr().
+%typemap(dbody) SWIGTYPE %{
+private void* swigCPtr;
+protected bool swigCMemOwn;
+
+public this(void* cObject, bool ownCObject) {
+ swigCPtr = cObject;
+ swigCMemOwn = ownCObject;
+}
+
+public override OP_EQUALS_RETURN opEquals(Object rhs) {
+ if (auto other = cast($dclassname)rhs) {
+ return (swigCPtr == other.swigCPtr);
+ }
+ return super.opEquals(rhs);
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+%typemap(dbody_derived) SWIGTYPE %{
+private void* swigCPtr;
+
+public this(void* cObject, bool ownCObject) {
+ super($wrapdmodule.$dclassnameUpcast(cObject), ownCObject);
+ swigCPtr = cObject;
+}
+
+public override OP_EQUALS_RETURN opEquals(Object rhs) {
+ if (auto other = cast($dclassname)rhs) {
+ return (swigCPtr == other.swigCPtr);
+ }
+ return super.opEquals(rhs);
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+
+/*
+ * Type wrapper classes.
+ */
+
+%typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
+private void* swigCPtr;
+
+public this(void* cObject, bool futureUse) {
+ swigCPtr = cObject;
+}
+
+protected this() {
+ swigCPtr = null;
+}
+
+public override OP_EQUALS_RETURN opEquals(Object rhs) {
+ if (auto other = cast($dclassname)rhs) {
+ return (swigCPtr == other.swigCPtr);
+ }
+ return super.opEquals(rhs);
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+
+/*
+ * Member function pointer wrapper classes (see <dmemberfunctionpointers.swg>).
+ */
+
+%typemap(dbody) SWIGTYPE (CLASS::*) %{
+private char* m_swigCMemberPtr;
+
+public this(char* cMemberPtr, bool futureUse) {
+ m_swigCMemberPtr = cMemberPtr;
+}
+
+protected this() {
+ m_swigCMemberPtr = null;
+}
+
+public override OP_EQUALS_RETURN opEquals(Object rhs) {
+ if (auto other = cast($dclassname)rhs) {
+ return (m_swigCMemberPtr == other.m_swigCMemberPtr);
+ }
+ return super.opEquals(rhs);
+}
+
+
+package static char* swigGetCMemberPtr($dclassname obj) {
+ return (obj is null) ? null : obj.m_swigCMemberPtr;
+}
+%}
+%enddef
+
+
+#if SWIG_D_VERSION == 1
+ SWIGD_CLASS_BODIES(int)
+#else
+ SWIGD_CLASS_BODIES(bool)
+#endif
+
+#undef SWIGD_CLASS_BODIES
diff --git a/Lib/d/ddirectives.swg b/Lib/d/ddirectives.swg
new file mode 100644
index 000000000..2b6ad77e2
--- /dev/null
+++ b/Lib/d/ddirectives.swg
@@ -0,0 +1,11 @@
+/* -----------------------------------------------------------------------------
+ * ddirectives.swg
+ *
+ * D-specifiv directives.
+ * ----------------------------------------------------------------------------- */
+
+#define %dnativeconst %feature("d:nativeconst")
+#define %dconstvalue(value) %feature("d:constvalue",value)
+#define %dmethodmodifiers %feature("d:methodmodifiers")
+#define %dstripprefix %feature("d:stripprefix")
+#define %dnothrowexception %feature("except")
diff --git a/Lib/d/denums.swg b/Lib/d/denums.swg
new file mode 100644
index 000000000..2632679ba
--- /dev/null
+++ b/Lib/d/denums.swg
@@ -0,0 +1,60 @@
+/* -----------------------------------------------------------------------------
+ * denums.swg
+ *
+ * Typemaps for enumerations.
+ * ----------------------------------------------------------------------------- */
+
+
+/*
+ * Typemaps for enumeration types.
+ */
+
+%typemap(cwtype) enum SWIGTYPE "int"
+%typemap(dwtype) enum SWIGTYPE "int"
+%typemap(dptype, cprimitive="1") enum SWIGTYPE "$dclassname"
+
+%typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
+
+%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
+%typemap(out) enum SWIGTYPE %{ $result = $1; %}
+
+%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
+%typemap(directorin) enum SWIGTYPE "$input = $1;"
+%typemap(ddirectorin) enum SWIGTYPE "cast($dclassname)$winput"
+%typemap(ddirectorout) enum SWIGTYPE "cast(int)$dpcall"
+
+%typemap(din) enum SWIGTYPE "cast(int)$dinput"
+%typemap(dout, excode=SWIGEXCODE) enum SWIGTYPE {
+ $dclassname ret = cast($dclassname)$wcall;$excode
+ return ret;
+}
+
+
+/*
+ * Typemaps for (const) references to enumeration types.
+ */
+
+%typemap(cwtype) const enum SWIGTYPE & "int"
+%typemap(dwtype) const enum SWIGTYPE & "int"
+%typemap(dptype) const enum SWIGTYPE & "$*dclassname"
+
+%typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
+
+%typemap(in) const enum SWIGTYPE & ($*1_ltype temp)
+%{ temp = ($*1_ltype)$input;
+ $1 = &temp; %}
+%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %}
+
+%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
+%{ static $*1_ltype temp = ($*1_ltype)$input;
+ $result = &temp; %}
+
+%typemap(ddirectorin) const enum SWIGTYPE & "cast($*dclassname)$winput"
+%typemap(ddirectorout) const enum SWIGTYPE & "cast(int)$dpcall"
+
+%typemap(din) const enum SWIGTYPE & "cast(int)$dinput"
+%typemap(dout, excode=SWIGEXCODE) const enum SWIGTYPE & {
+ $*dclassname ret = cast($*dclassname)$wcall;$excode
+ return ret;
+}
diff --git a/Lib/d/dexception.swg b/Lib/d/dexception.swg
new file mode 100644
index 000000000..f45cf7bfb
--- /dev/null
+++ b/Lib/d/dexception.swg
@@ -0,0 +1,30 @@
+/* -----------------------------------------------------------------------------
+ * dexception.swg
+ *
+ * Typemaps used for propagating C++ exceptions to D.
+ * ----------------------------------------------------------------------------- */
+
+// Code which is inserted into the dout typemaps and class constructors via
+// excode if exceptions can be thrown.
+%define SWIGEXCODE "\n if ($wrapdmodule.SwigPendingException.isPending) throw $wrapdmodule.SwigPendingException.retrieve();" %enddef
+
+%typemap(throws, canthrow=1) int,
+ long,
+ short,
+ unsigned int,
+ unsigned long,
+ unsigned short
+%{ char error_msg[256];
+ sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
+ SWIG_DSetPendingException(SWIG_DException, error_msg);
+ return $null; %}
+
+%typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY],
+ enum SWIGTYPE, const enum SWIGTYPE &
+%{ (void)$1;
+ SWIG_DSetPendingException(SWIG_DException, "C++ $1_type exception thrown");
+ return $null; %}
+
+%typemap(throws, canthrow=1) char *
+%{ SWIG_DSetPendingException(SWIG_DException, $1);
+ return $null; %}
diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg
new file mode 100644
index 000000000..e05bc7728
--- /dev/null
+++ b/Lib/d/dhead.swg
@@ -0,0 +1,310 @@
+/* -----------------------------------------------------------------------------
+ * dhead.swg
+ *
+ * Support code for exceptions if the SWIG_D_NO_EXCEPTION_HELPER is not defined
+ * Support code for strings if the SWIG_D_NO_STRING_HELPER is not defined
+ * ----------------------------------------------------------------------------- */
+
+%insert(runtime) %{
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+%}
+
+
+#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
+%insert(runtime) %{
+// Support for throwing D exceptions from C/C++.
+typedef enum {
+ SWIG_DException = 0,
+ SWIG_DIllegalArgumentException,
+ SWIG_DIllegalElementException,
+ SWIG_DIOException,
+ SWIG_DNoSuchElementException,
+} SWIG_DExceptionCodes;
+
+typedef void (SWIGSTDCALL* SWIG_DExceptionCallback_t)(const char *);
+
+typedef struct {
+ SWIG_DExceptionCodes code;
+ SWIG_DExceptionCallback_t callback;
+} SWIG_DException_t;
+
+static SWIG_DException_t SWIG_d_exceptions[] = {
+ { SWIG_DException, NULL },
+ { SWIG_DIllegalArgumentException, NULL },
+ { SWIG_DIllegalElementException, NULL },
+ { SWIG_DIOException, NULL },
+ { SWIG_DNoSuchElementException, NULL }
+};
+
+static void SWIGUNUSED SWIG_DSetPendingException(SWIG_DExceptionCodes code, const char *msg) {
+ if ((size_t)code < sizeof(SWIG_d_exceptions)/sizeof(SWIG_DException_t)) {
+ SWIG_d_exceptions[code].callback(msg);
+ } else {
+ SWIG_d_exceptions[SWIG_DException].callback(msg);
+ }
+}
+
+#ifdef __cplusplus
+extern "C"
+#endif
+SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(
+ SWIG_DExceptionCallback_t exceptionCallback,
+ SWIG_DExceptionCallback_t illegalArgumentCallback,
+ SWIG_DExceptionCallback_t illegalElementCallback,
+ SWIG_DExceptionCallback_t ioCallback,
+ SWIG_DExceptionCallback_t noSuchElementCallback) {
+ SWIG_d_exceptions[SWIG_DException].callback = exceptionCallback;
+ SWIG_d_exceptions[SWIG_DIllegalArgumentException].callback = illegalArgumentCallback;
+ SWIG_d_exceptions[SWIG_DIllegalElementException].callback = illegalElementCallback;
+ SWIG_d_exceptions[SWIG_DIOException].callback = ioCallback;
+ SWIG_d_exceptions[SWIG_DNoSuchElementException].callback = noSuchElementCallback;
+}
+%}
+
+#if (SWIG_D_VERSION == 1)
+%pragma(d) wrapdmoduleimports=%{
+// Exception throwing support currently requires Tango, but there is no reason
+// why it could not support Phobos.
+static import tango.core.Exception;
+static import tango.core.Thread;
+static import tango.stdc.stringz;
+%}
+
+%pragma(d) wrapdmodulecode=%{
+private class SwigExceptionHelper {
+ static this() {
+ swigRegisterExceptionCallbacks(
+ &setException,
+ &setIllegalArgumentException,
+ &setIllegalElementException,
+ &setIOException,
+ &setNoSuchElementException);
+ }
+
+ static void setException(char* message) {
+ auto exception = new Exception(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+
+ static void setIllegalArgumentException(char* message) {
+ auto exception = new tango.core.Exception.IllegalArgumentException(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+
+ static void setIllegalElementException(char* message) {
+ auto exception = new tango.core.Exception.IllegalElementException(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+
+ static void setIOException(char* message) {
+ auto exception = new tango.core.Exception.IOException(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+
+ static void setNoSuchElementException(char* message) {
+ auto exception = new tango.core.Exception.NoSuchElementException(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+}
+
+package class SwigPendingException {
+public:
+ static this() {
+ m_sPendingCount = 0;
+ m_sPendingException = new ThreadLocalData(null);
+ }
+
+ static bool isPending() {
+ bool pending = false;
+ if (m_sPendingCount > 0) {
+ if (m_sPendingException.val !is null) {
+ pending = true;
+ }
+ }
+ return pending;
+ }
+
+ static void set(Exception e) {
+ if (m_sPendingException.val !is null) {
+ throw new Exception("FATAL: An earlier pending exception from C/C++ code " ~
+ "was missed and thus not thrown (" ~ m_sPendingException.val.classinfo.name ~
+ ": " ~ m_sPendingException.val.msg ~ ")!", e);
+ }
+
+ m_sPendingException.val = e;
+ synchronized {
+ ++m_sPendingCount;
+ }
+ }
+
+ static Exception retrieve() {
+ Exception e = null;
+ if (m_sPendingCount > 0) {
+ if (m_sPendingException.val !is null) {
+ e = m_sPendingException.val;
+ m_sPendingException.val = null;
+ synchronized {
+ --m_sPendingCount;
+ }
+ }
+ }
+ return e;
+ }
+
+private:
+ // The pending exception counter is stored thread-global.
+ static int m_sPendingCount;
+
+ // The reference to the pending exception (if any) is stored thread-local.
+ alias tango.core.Thread.ThreadLocal!(Exception) ThreadLocalData;
+ static ThreadLocalData m_sPendingException;
+}
+alias void function(char* message) SwigExceptionCallback;
+%}
+#else
+%pragma(d) wrapdmoduleimports=%{
+static import std.conv;
+%}
+
+%pragma(d) wrapdmodulecode=%{
+private class SwigExceptionHelper {
+ static this() {
+ // The D1/Tango version maps C++ exceptions to multiple exception types.
+ swigRegisterExceptionCallbacks(
+ &setException,
+ &setException,
+ &setException,
+ &setException,
+ &setException
+ );
+ }
+
+ static void setException(char* message) {
+ auto exception = new Exception(std.conv.to!string(message).idup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+}
+
+package struct SwigPendingException {
+public:
+ static this() {
+ m_sPendingCount = 0;
+ m_sPendingException = null;
+ }
+
+ static bool isPending() {
+ bool pending = false;
+ if (m_sPendingCount > 0) {
+ if (m_sPendingException !is null) {
+ pending = true;
+ }
+ }
+ return pending;
+ }
+
+ static void set(Exception e) {
+ if (m_sPendingException !is null) {
+ throw new Exception("FATAL: An earlier pending exception from C/C++ code " ~
+ "was missed and thus not thrown (" ~ m_sPendingException.classinfo.name ~
+ ": " ~ m_sPendingException.msg ~ ")!", e);
+ }
+
+ m_sPendingException = e;
+ synchronized {
+ ++m_sPendingCount;
+ }
+ }
+
+ static Exception retrieve() {
+ Exception e = null;
+ if (m_sPendingCount > 0) {
+ if (m_sPendingException !is null) {
+ e = m_sPendingException;
+ m_sPendingException = null;
+ synchronized {
+ --m_sPendingCount;
+ }
+ }
+ }
+ return e;
+ }
+
+private:
+ // The pending exception counter is stored thread-global.
+ static shared int m_sPendingCount;
+
+ // The reference to the pending exception (if any) is stored thread-local.
+ static Exception m_sPendingException;
+}
+alias void function(const char* message) SwigExceptionCallback;
+%}
+#endif
+// Callback registering function in wrapperloader.swg.
+#endif // SWIG_D_NO_EXCEPTION_HELPER
+
+#if !defined(SWIG_D_NO_STRING_HELPER)
+%insert(runtime) %{
+// Callback for returning strings to D without leaking memory.
+typedef char * (SWIGSTDCALL* SWIG_DStringHelperCallback)(const char *);
+static SWIG_DStringHelperCallback SWIG_d_string_callback = NULL;
+
+#ifdef __cplusplus
+extern "C"
+#endif
+SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_DStringHelperCallback callback) {
+ SWIG_d_string_callback = callback;
+}
+%}
+
+#if (SWIG_D_VERSION == 1)
+%pragma(d) wrapdmoduleimports = "static import tango.stdc.stringz;";
+
+%pragma(d) wrapdmodulecode = %{
+private class SwigStringHelper {
+ static this() {
+ swigRegisterStringCallback(&createString);
+ }
+
+ static char* createString(char* cString) {
+ // We are effectively dup'ing the string here.
+ return tango.stdc.stringz.toStringz(tango.stdc.stringz.fromStringz(cString));
+ }
+}
+alias char* function(char* cString) SwigStringCallback;
+%}
+#else
+%pragma(d) wrapdmoduleimports = %{
+static import std.conv;
+static import std.string;
+%}
+
+%pragma(d) wrapdmodulecode = %{
+private class SwigStringHelper {
+ static this() {
+ swigRegisterStringCallback(&createString);
+ }
+
+ static const(char)* createString(const(char*) cString) {
+ // We are effectively dup'ing the string here.
+ // TODO: Is this also correct for D2/Phobos?
+ return std.string.toStringz(std.conv.to!string(cString));
+ }
+}
+alias const(char)* function(const(char*) cString) SwigStringCallback;
+%}
+#endif
+// Callback registering function in wrapperloader.swg.
+#endif // SWIG_D_NO_STRING_HELPER
+
+%insert(runtime) %{
+/* Contract support. */
+#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else
+%}
diff --git a/Lib/d/director.swg b/Lib/d/director.swg
new file mode 100644
index 000000000..9692e03c1
--- /dev/null
+++ b/Lib/d/director.swg
@@ -0,0 +1,46 @@
+/* -----------------------------------------------------------------------------
+ * director.swg
+ *
+ * This file contains support for director classes so that D proxy
+ * methods can be called from C++.
+ * ----------------------------------------------------------------------------- */
+
+#ifdef __cplusplus
+
+#if defined(DEBUG_DIRECTOR_OWNED)
+#include <iostream>
+#endif
+#include <string>
+
+namespace Swig {
+ // Director base class – not used in D directors.
+ class Director {
+ };
+
+ // Base class for director exceptions.
+ class DirectorException {
+ protected:
+ std::string swig_msg;
+
+ public:
+ DirectorException(const char* msg) : swig_msg(msg) {
+ }
+ DirectorException(const std::string &msg) : swig_msg(msg) {
+ }
+ const std::string& what() const {
+ return swig_msg;
+ }
+ virtual ~DirectorException() {
+ }
+ };
+
+ // Exception which is thrown when attempting to call a pure virtual method
+ // from D code thorugh the director layer.
+ class DirectorPureVirtualException : public Swig::DirectorException {
+ public:
+ DirectorPureVirtualException(const char* msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) {
+ }
+ };
+}
+
+#endif /* __cplusplus */
diff --git a/Lib/d/dkw.swg b/Lib/d/dkw.swg
new file mode 100644
index 000000000..5091f02cc
--- /dev/null
+++ b/Lib/d/dkw.swg
@@ -0,0 +1,126 @@
+#ifndef D_DKW_SWG_
+#define D_DKW_SWG_
+
+/* Warnings for D keywords */
+#define DKEYWORD(x) %keywordwarn("'" `x` "' is a D keyword, renaming to '_" `x` "'",rename="_%s") `x`
+
+// Source: http://www.digitalmars.com/d/{1.0,2.0}/lex.html and
+DKEYWORD(Object);
+DKEYWORD(__FILE__);
+DKEYWORD(__LINE__);
+DKEYWORD(__gshared);
+DKEYWORD(__thread);
+DKEYWORD(__traits);
+DKEYWORD(abstract);
+DKEYWORD(alias);
+DKEYWORD(align);
+DKEYWORD(asm);
+DKEYWORD(assert);
+DKEYWORD(auto);
+DKEYWORD(body);
+DKEYWORD(bool);
+DKEYWORD(break);
+DKEYWORD(byte);
+DKEYWORD(case);
+DKEYWORD(cast);
+DKEYWORD(catch);
+DKEYWORD(cdouble);
+DKEYWORD(cent);
+DKEYWORD(cfloat);
+DKEYWORD(char);
+DKEYWORD(class);
+DKEYWORD(const);
+DKEYWORD(continue);
+DKEYWORD(creal);
+DKEYWORD(dchar);
+DKEYWORD(debug);
+DKEYWORD(default);
+DKEYWORD(delegate);
+DKEYWORD(delete);
+DKEYWORD(deprecated);
+DKEYWORD(do);
+DKEYWORD(double);
+DKEYWORD(dstring);
+DKEYWORD(else);
+DKEYWORD(enum);
+DKEYWORD(export);
+DKEYWORD(extern);
+DKEYWORD(false);
+DKEYWORD(final);
+DKEYWORD(finally);
+DKEYWORD(float);
+DKEYWORD(for);
+DKEYWORD(foreach);
+DKEYWORD(foreach_reverse);
+DKEYWORD(function);
+DKEYWORD(goto);
+DKEYWORD(idouble);
+DKEYWORD(if);
+DKEYWORD(ifloat);
+DKEYWORD(immutable);
+DKEYWORD(import);
+DKEYWORD(in);
+DKEYWORD(inout);
+DKEYWORD(int);
+DKEYWORD(interface);
+DKEYWORD(invariant);
+DKEYWORD(ireal);
+DKEYWORD(is);
+DKEYWORD(lazy);
+DKEYWORD(long);
+DKEYWORD(macro);
+DKEYWORD(mixin);
+DKEYWORD(module);
+DKEYWORD(new);
+DKEYWORD(nothrow);
+DKEYWORD(null);
+DKEYWORD(out);
+DKEYWORD(override);
+DKEYWORD(package);
+DKEYWORD(pragma);
+DKEYWORD(private);
+DKEYWORD(protected);
+DKEYWORD(public);
+DKEYWORD(pure);
+DKEYWORD(real);
+DKEYWORD(ref);
+DKEYWORD(return);
+DKEYWORD(scope);
+DKEYWORD(shared);
+DKEYWORD(short);
+DKEYWORD(static);
+DKEYWORD(string);
+DKEYWORD(struct);
+DKEYWORD(super);
+DKEYWORD(switch);
+DKEYWORD(synchronized);
+DKEYWORD(template);
+DKEYWORD(this);
+DKEYWORD(throw);
+DKEYWORD(true);
+DKEYWORD(try);
+DKEYWORD(typedef);
+DKEYWORD(typeid);
+DKEYWORD(typeof);
+DKEYWORD(ubyte);
+DKEYWORD(ucent);
+DKEYWORD(uint);
+DKEYWORD(ulong);
+DKEYWORD(union);
+DKEYWORD(unittest);
+DKEYWORD(ushort);
+DKEYWORD(version);
+DKEYWORD(void);
+DKEYWORD(volatile);
+DKEYWORD(wchar);
+DKEYWORD(while);
+DKEYWORD(with);
+DKEYWORD(wstring);
+
+// Not really a keyword, but dispose() methods are generated in proxy classes
+// and it's a special method name for D1/Tango.
+DKEYWORD(dispose);
+
+#undef DKEYWORD
+
+#endif //D_DKW_SWG_
diff --git a/Lib/d/dmemberfunctionpointers.swg b/Lib/d/dmemberfunctionpointers.swg
new file mode 100644
index 000000000..2774858f4
--- /dev/null
+++ b/Lib/d/dmemberfunctionpointers.swg
@@ -0,0 +1,92 @@
+/* -----------------------------------------------------------------------------
+ * dmemberfunctionpointers.swg
+ *
+ * Typemaps for member function pointers.
+ * ----------------------------------------------------------------------------- */
+
+
+%typemap(cwtype) SWIGTYPE (CLASS::*) "char *"
+%typemap(dwtype) SWIGTYPE (CLASS::*) "char*"
+%typemap(dptype) SWIGTYPE (CLASS::*) "$dclassname"
+
+%typecheck(SWIG_TYPECHECK_POINTER)
+ SWIGTYPE (CLASS::*)
+ ""
+
+
+/*
+ * Conversion generation typemaps.
+ */
+
+%typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) %{
+ SWIG_UnpackData($input, (void *)&$1, sizeof($1));
+%}
+%typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
+ char buf[128];
+ char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
+ *data = '\0';
+ $result = SWIG_d_string_callback(buf);
+%}
+
+%typemap(directorin) SWIGTYPE (CLASS::*) "$input = (void *) $1;"
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*)
+ "$result = ($1_ltype)$input;"
+
+%typemap(ddirectorin) SWIGTYPE (CLASS::*)
+ "($winput is null) ? null : new $dclassname($winput, false)"
+%typemap(ddirectorout) SWIGTYPE (CLASS::*) "$dclassname.swigGetCPtr($dpcall)"
+
+%typemap(din) SWIGTYPE (CLASS::*) "$dclassname.swigGetCMemberPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE (CLASS::*) {
+ char* cMemberPtr = $wcall;
+ $dclassname ret = (cMemberPtr is null) ? null : new $dclassname(cMemberPtr, $owner);$excode
+ return ret;
+}
+
+
+/*
+ * Helper functions to pack/unpack arbitrary binary data (member function
+ * pointers in this case) into a string.
+ */
+
+%fragment("SWIG_PackData", "header") {
+/* Pack binary data into a string */
+SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
+ static const char hex[17] = "0123456789abcdef";
+ register const unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register unsigned char uu = *u;
+ *(c++) = hex[(uu & 0xf0) >> 4];
+ *(c++) = hex[uu & 0xf];
+ }
+ return c;
+}
+}
+
+%fragment("SWIG_UnPackData", "header") {
+/* Unpack binary data from a string */
+SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
+ register unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register char d = *(c++);
+ register unsigned char uu;
+ if ((d >= '0') && (d <= '9'))
+ uu = ((d - '0') << 4);
+ else if ((d >= 'a') && (d <= 'f'))
+ uu = ((d - ('a'-10)) << 4);
+ else
+ return (char *) 0;
+ d = *(c++);
+ if ((d >= '0') && (d <= '9'))
+ uu |= (d - '0');
+ else if ((d >= 'a') && (d <= 'f'))
+ uu |= (d - ('a'-10));
+ else
+ return (char *) 0;
+ *u = uu;
+ }
+ return c;
+}
+}
diff --git a/Lib/d/doperators.swg b/Lib/d/doperators.swg
new file mode 100644
index 000000000..b3d8d7257
--- /dev/null
+++ b/Lib/d/doperators.swg
@@ -0,0 +1,77 @@
+/* -----------------------------------------------------------------------------
+ * doperators.swg
+ *
+ * Mapping of C++ operator overloading methods to D.
+ * ----------------------------------------------------------------------------- */
+
+#ifdef __cplusplus
+
+#if (SWIG_D_VERSION == 1)
+
+%rename(opAdd) *::operator+;
+%rename(opPos) *::operator+();
+%rename(opAddAssign) *::operator+=;
+%rename(opSub) *::operator-;
+%rename(opNeg) *::operator-();
+%rename(opSubAssign) *::operator-=;
+%rename(opMul) *::operator*;
+%rename(opMulAssign) *::operator*=;
+%rename(opDiv) *::operator/;
+%rename(opDivAssign) *::operator/=;
+%rename(opMod) *::operator%;
+%rename(opModAssign) *::operator%=;
+
+%rename(opCom) *::operator~();
+%rename(opAnd) *::operator&;
+%rename(opAndAssign) *::operator&=;
+%rename(opOr) *::operator|;
+%rename(opOrAssign) *::operator|=;
+%rename(opXor) *::operator^;
+%rename(opXorAssign) *::operator^=;
+%rename(opShl) *::operator<<;
+%rename(opShlAssign) *::operator<<=;
+%rename(opShr) *::operator>>;
+%rename(opShrAssign) *::operator>>=;
+
+%rename(opIndex) *::operator[](unsigned) const;
+%rename(opIndexAssign) *::operator[](unsigned);
+%rename(opCall) *::operator();
+
+// !a is not overrideable in D1.
+%ignoreoperator(LNOT) operator!;
+
+// a != b is rewritten as !a.opEquals(b) in D.
+// For now, just ignore both of them, since there would be quite a bit of magic
+// needed to correctly generate a wrapper method for non-primitives types (there is
+// only one opEquals overload with an Object parameter in D).
+%ignoreoperator(EQ) operator==;
+%ignoreoperator(NOTEQUAL) operator!=;
+
+// opCmp is used in D.
+%ignoreoperator(LT) operator<;
+%ignoreoperator(LTEQUAL) operator<=;
+%ignoreoperator(GT) operator>;
+%ignoreoperator(GTEQUAL) operator>=;
+
+// The logic operators are not overrideable in D.
+%ignoreoperator(LAND) operator&&;
+%ignoreoperator(LOR) operator||;
+
+// ++/--a is rewritten as a +/-= 1 in D.
+%ignoreoperator(PLUSPLUS) operator++();
+%ignoreoperator(MINUSMINUS) operator--();
+%ignoreoperator(PLUSPLUS) operator++(int);
+%ignoreoperator(MINUSMINUS) operator--(int);
+
+// The C++ assignment operator does not translate well to D where custom types
+// have reference semantics.
+%ignoreoperator(EQ) operator=;
+
+#else
+
+// Operator overloading works completely different in D2, proper support will
+// probably need fairly extensive code generation support.
+
+#endif
+
+#endif
diff --git a/Lib/d/dprimitives.swg b/Lib/d/dprimitives.swg
new file mode 100644
index 000000000..94999af2c
--- /dev/null
+++ b/Lib/d/dprimitives.swg
@@ -0,0 +1,158 @@
+/* -----------------------------------------------------------------------------
+ * dprimitves.swg
+ *
+ * Typemaps for primitive types.
+ * ----------------------------------------------------------------------------- */
+
+/*
+ * The SWIG_D_PRIMITIVE macro is used to define the typemaps for the primitive
+ * types, because are more or less the same for all of them. The few special
+ * cases are handeled below.
+ */
+%define SWIG_D_PRIMITIVE(TYPE, DTYPE)
+%typemap(cwtype) TYPE, const TYPE & "TYPE"
+%typemap(dwtype) TYPE, const TYPE & "DTYPE"
+%typemap(dptype, cprimitive="1") TYPE, const TYPE & "DTYPE"
+
+%typemap(in) TYPE "$1 = ($1_ltype)$input;"
+%typemap(out) TYPE "$result = $1;"
+%typemap(directorin) TYPE "$input = $1;"
+%typemap(directorout) TYPE "$result = ($1_ltype)$input;"
+%typemap(ddirectorin) TYPE "$winput"
+%typemap(ddirectorout) TYPE "$dpcall"
+
+%typemap(in) const TYPE & ($*1_ltype temp)
+%{ temp = ($*1_ltype)$input;
+ $1 = &temp; %}
+%typemap(out) const TYPE & "$result = *$1;"
+%typemap(directorin) const TYPE & "$input = $1_name;"
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const TYPE &
+%{ static $*1_ltype temp;
+ temp = ($*1_ltype)$input;
+ $result = &temp; %}
+%typemap(ddirectorin) const TYPE & "$winput"
+%typemap(ddirectorout) const TYPE & "$dpcall"
+
+%typemap(din) TYPE, const TYPE & "$dinput"
+%typemap(dout, excode=SWIGEXCODE) TYPE, const TYPE & {
+ auto ret = $wcall;$excode
+ return ret;
+}
+%enddef
+
+
+SWIG_D_PRIMITIVE(bool, bool)
+SWIG_D_PRIMITIVE(char, char)
+SWIG_D_PRIMITIVE(signed char, byte)
+SWIG_D_PRIMITIVE(unsigned char, ubyte)
+SWIG_D_PRIMITIVE(short, short)
+SWIG_D_PRIMITIVE(unsigned short, ushort)
+SWIG_D_PRIMITIVE(int, int)
+SWIG_D_PRIMITIVE(unsigned int, uint)
+SWIG_D_PRIMITIVE(long, int)
+SWIG_D_PRIMITIVE(unsigned long, uint)
+SWIG_D_PRIMITIVE(size_t, size_t)
+SWIG_D_PRIMITIVE(long long, long)
+SWIG_D_PRIMITIVE(unsigned long long, ulong)
+SWIG_D_PRIMITIVE(float, float)
+SWIG_D_PRIMITIVE(double, double)
+
+
+// The C++ boolean type needs some special casing since it is not part of the
+// C standard and is thus represented as unsigned int in the C wrapper layer.
+%typemap(cwtype) bool, const bool & "unsigned int"
+%typemap(dwtype) bool, const bool & "uint"
+
+%typemap(in) bool "$1 = $input ? true : false;"
+%typemap(in) const bool & ($*1_ltype temp)
+%{ temp = $input ? true : false;
+ $1 = &temp; %}
+
+%typemap(directorout) bool
+ "$result = $input ? true : false;"
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool &
+%{ static $*1_ltype temp;
+ temp = $input ? true : false;
+ $result = &temp; %}
+
+%typemap(ddirectorin) bool "($winput ? true : false)"
+
+%typemap(dout, excode=SWIGEXCODE) bool, const bool & {
+ bool ret = $wcall ? true : false;$excode
+ return ret;
+}
+
+
+// Judging from the history of the C# module, the explicit casts are needed for
+// certain versions of VC++.
+%typemap(out) unsigned long "$result = (unsigned long)$1;"
+%typemap(out) const unsigned long & "$result = (unsigned long)*$1;"
+
+
+/*
+ * Typecheck typemaps.
+ */
+
+%typecheck(SWIG_TYPECHECK_BOOL)
+ bool,
+ const bool &
+ ""
+
+%typecheck(SWIG_TYPECHECK_CHAR)
+ char,
+ const char &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT8)
+ signed char,
+ const signed char &
+ ""
+
+%typecheck(SWIG_TYPECHECK_UINT8)
+ unsigned char,
+ const unsigned char &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT16)
+ short,
+ const short &
+ ""
+
+%typecheck(SWIG_TYPECHECK_UINT16)
+ unsigned short,
+ const unsigned short &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT32)
+ int,
+ long,
+ const int &,
+ const long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_UINT32)
+ unsigned int,
+ unsigned long,
+ const unsigned int &,
+ const unsigned long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT64)
+ long long,
+ const long long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_UINT64)
+ unsigned long long,
+ const unsigned long long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_FLOAT)
+ float,
+ const float &
+ ""
+
+%typecheck(SWIG_TYPECHECK_DOUBLE)
+ double,
+ const double &
+ ""
diff --git a/Lib/d/dstrings.swg b/Lib/d/dstrings.swg
new file mode 100644
index 000000000..a145c8d75
--- /dev/null
+++ b/Lib/d/dstrings.swg
@@ -0,0 +1,80 @@
+/* -----------------------------------------------------------------------------
+ * dstrings.swg
+ *
+ * Typemaps for wrapping pointers to/arrays of C chars as D strings.
+ * ----------------------------------------------------------------------------- */
+
+%define SWIGD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
+%typemap(cwtype) char *, char *&, char[ANY], char[] "char *"
+%typemap(dwtype) char *, char *&, char[ANY], char[] #DW_STRING_TYPE
+%typemap(dptype) char *, char *&, char[ANY], char[] #DP_STRING_TYPE
+
+
+/*
+ * char* typemaps.
+ */
+
+%typemap(in) char * %{ $1 = ($1_ltype)$input; %}
+%typemap(out) char * %{ $result = SWIG_d_string_callback((const char *)$1); %}
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %}
+%typemap(directorin) char * %{ $input = SWIG_d_string_callback((const char *)$1); %}
+%typemap(ddirectorin) char * "FROM_STRINGZ($winput)"
+%typemap(ddirectorout) char * "TO_STRINGZ($dpcall)"
+
+
+/*
+ * char*& typemaps.
+ */
+
+%typemap(in) char *& ($*1_ltype temp = 0) %{
+ temp = ($*1_ltype)$input;
+ $1 = &temp;
+%}
+%typemap(out) char *& %{ if ($1) $result = SWIG_d_string_callback((const char *)*$1); %}
+
+
+/*
+ * char array typemaps.
+ */
+
+%typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %}
+%typemap(out) char[ANY], char[] %{ $result = SWIG_d_string_callback((const char *)$1); %}
+
+%typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %}
+%typemap(directorin) char[ANY], char[] %{ $input = SWIG_d_string_callback((const char *)$1); %}
+
+%typemap(ddirectorin) char[ANY], char[] "$winput"
+%typemap(ddirectorout) char[ANY], char[] "$dpcall"
+
+
+%typemap(din) char *, char *&, char[ANY], char[] "($dinput ? TO_STRINGZ($dinput) : null)"
+%typemap(dout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
+ DP_STRING_TYPE ret = FROM_STRINGZ ## ($wcall);$excode
+ return ret;
+}
+
+%typecheck(SWIG_TYPECHECK_STRING)
+ char *,
+ char *&,
+ char[ANY],
+ char[]
+ ""
+%enddef
+
+
+// We need to have the \0-terminated string conversion functions available in
+// the D proxy modules.
+#if (SWIG_D_VERSION == 1)
+// Could be easily extended to support Phobos as well.
+SWIGD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
+
+%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
+#else
+SWIGD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
+
+%pragma(d) globalproxyimports = %{
+static import std.conv;
+static import std.string;
+%}
+#endif
+#undef SWIGD_STRING_TYPEMAPS
diff --git a/Lib/d/dswigtype.swg b/Lib/d/dswigtype.swg
new file mode 100644
index 000000000..ed2fb531d
--- /dev/null
+++ b/Lib/d/dswigtype.swg
@@ -0,0 +1,177 @@
+/* -----------------------------------------------------------------------------
+ * dswigtype.swg
+ *
+ * Typemaps for non-primitive types (C/C++ classes and structs).
+ * ----------------------------------------------------------------------------- */
+
+%typemap(cwtype) SWIGTYPE "void *"
+%typemap(dwtype) SWIGTYPE "void*"
+%typemap(dptype) SWIGTYPE "$&dclassname"
+
+%typemap(cwtype) SWIGTYPE [] "void *"
+%typemap(dwtype) SWIGTYPE [] "void*"
+%typemap(dptype) SWIGTYPE [] "$dclassname"
+
+%typemap(cwtype) SWIGTYPE * "void *"
+%typemap(dwtype) SWIGTYPE * "void*"
+%typemap(dptype, nativepointer="$dptype") SWIGTYPE * "$dclassname"
+
+%typemap(cwtype) SWIGTYPE & "void *"
+%typemap(dwtype) SWIGTYPE & "void*"
+%typemap(dptype) SWIGTYPE & "$dclassname"
+
+%typemap(cwtype) SWIGTYPE *const& "void *"
+%typemap(dwtype) SWIGTYPE *const& "void*"
+%typemap(dptype) SWIGTYPE *const& "$*dclassname"
+
+%typecheck(SWIG_TYPECHECK_POINTER)
+ SWIGTYPE,
+ SWIGTYPE *,
+ SWIGTYPE &,
+ SWIGTYPE [],
+ SWIGTYPE *const&
+ ""
+
+
+/*
+ * By-value conversion typemaps (parameter is converted to a pointer).
+ */
+
+%typemap(in, canthrow=1) SWIGTYPE ($&1_type argp)
+%{ argp = ($&1_ltype)$input;
+ if (!argp) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
+ return $null;
+ }
+ $1 = *argp; %}
+
+%typemap(out) SWIGTYPE
+#ifdef __cplusplus
+%{ $result = new $1_ltype((const $1_ltype &)$1); %}
+#else
+{
+ $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
+ memmove($1ptr, &$1, sizeof($1_type));
+ $result = $1ptr;
+}
+#endif
+
+%typemap(directorin) SWIGTYPE
+ "$input = (void *)&$1;"
+%typemap(directorout) SWIGTYPE
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
+ return $null;
+ }
+ $result = *($&1_ltype)$input; %}
+
+%typemap(ddirectorin) SWIGTYPE "new $&dclassname($winput, false)"
+%typemap(ddirectorout) SWIGTYPE "$&dclassname.swigGetCPtr($dpcall)"
+
+%typemap(din) SWIGTYPE "$&dclassname.swigGetCPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE {
+ $&dclassname ret = new $&dclassname($wcall, true);$excode
+ return ret;
+}
+
+
+/*
+ * Pointer conversion typemaps.
+ */
+
+%typemap(in) SWIGTYPE * "$1 = ($1_ltype)$input;"
+%typemap(out) SWIGTYPE * "$result = (void *)$1;"
+
+%typemap(directorin) SWIGTYPE *
+ "$input = (void *) $1;"
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *
+ "$result = ($1_ltype)$input;"
+
+%typemap(ddirectorin,
+ nativepointer="cast($dptype)$winput"
+) SWIGTYPE * "($winput is null) ? null : new $dclassname($winput, false)"
+
+%typemap(ddirectorout,
+ nativepointer="cast(void*)$dpcall"
+) SWIGTYPE * "$dclassname.swigGetCPtr($dpcall)"
+
+%typemap(din,
+ nativepointer="cast(void*)$dinput"
+) SWIGTYPE * "$dclassname.swigGetCPtr($dinput)"
+
+%typemap(dout, excode=SWIGEXCODE,
+ nativepointer="{\n auto ret = cast($dptype)$wcall;$excode\n return ret;\n}"
+) SWIGTYPE * {
+ void* cPtr = $wcall;
+ $dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode
+ return ret;
+}
+
+// Use the same typemaps for const pointers.
+%apply SWIGTYPE * { SWIGTYPE *const }
+
+
+/*
+ * Reference conversion typemaps.
+ */
+
+%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
+ if (!$1) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
+ return $null;
+ } %}
+%typemap(out) SWIGTYPE & "$result = (void *)$1;"
+
+%typemap(directorin) SWIGTYPE &
+ "$input = ($1_ltype) &$1;"
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
+ return $null;
+ }
+ $result = ($1_ltype)$input; %}
+
+%typemap(ddirectorin) SWIGTYPE & "new $dclassname($winput, false)"
+%typemap(ddirectorout) SWIGTYPE & "$dclassname.swigGetCPtr($dpcall)"
+
+%typemap(din) SWIGTYPE & "$dclassname.swigGetCPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE & {
+ $dclassname ret = new $dclassname($wcall, $owner);$excode
+ return ret;
+}
+
+
+/*
+ * Array conversion typemaps.
+ */
+
+%typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %}
+%typemap(out) SWIGTYPE [] %{ $result = $1; %}
+
+%typemap(din) SWIGTYPE [] "$dclassname.swigGetCPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE [] {
+ void* cPtr = $wcall;
+ $dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode
+ return ret;
+}
+
+// Treat references to arrays like like references to a single element.
+%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
+
+
+/*
+ * Pointer reference conversion typemaps.
+ */
+
+%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
+%{ temp = ($*1_ltype)$input;
+ $1 = ($1_ltype)&temp; %}
+%typemap(out) SWIGTYPE *const&
+%{ $result = (void *)*$1; %}
+
+%typemap(din) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE *const& {
+ void* cPtr = $wcall;
+ $*dclassname ret = (cPtr is null) ? null : new $*dclassname(cPtr, $owner);$excode
+ return ret;
+}
diff --git a/Lib/d/dvoid.swg b/Lib/d/dvoid.swg
new file mode 100644
index 000000000..a08da5e32
--- /dev/null
+++ b/Lib/d/dvoid.swg
@@ -0,0 +1,18 @@
+/* -----------------------------------------------------------------------------
+ * dvoid.swg
+ *
+ * Typemaps for handling void function return types and empty parameter lists.
+ * ----------------------------------------------------------------------------- */
+
+%typemap(cwtype) void "void"
+%typemap(dwtype) void "void"
+%typemap(dptype, cprimitive="1") void "void"
+
+%typemap(out, null="") void ""
+%typemap(ddirectorin) void "$winput"
+%typemap(ddirectorout) void "$dpcall"
+%typemap(directorin) void ""
+
+%typemap(dout, excode=SWIGEXCODE) void {
+ $wcall;$excode
+}
diff --git a/Lib/d/std_common.i b/Lib/d/std_common.i
new file mode 100644
index 000000000..cee11e8ca
--- /dev/null
+++ b/Lib/d/std_common.i
@@ -0,0 +1,5 @@
+%include <std_except.i>
+
+%apply size_t { std::size_t };
+%apply const size_t& { const std::size_t& };
+
diff --git a/Lib/d/std_deque.i b/Lib/d/std_deque.i
new file mode 100644
index 000000000..cb98f6c2f
--- /dev/null
+++ b/Lib/d/std_deque.i
@@ -0,0 +1 @@
+%include <std/_std_deque.i>
diff --git a/Lib/d/std_except.i b/Lib/d/std_except.i
new file mode 100644
index 000000000..2b557e5fc
--- /dev/null
+++ b/Lib/d/std_except.i
@@ -0,0 +1,30 @@
+/* -----------------------------------------------------------------------------
+ * std_except.i
+ *
+ * Typemaps used by the STL wrappers that throw exceptions. These typemaps are
+ * used when methods are declared with an STL exception specification, such as
+ * size_t at() const throw (std::out_of_range);
+ * ----------------------------------------------------------------------------- */
+
+%{
+#include <stdexcept>
+%}
+
+namespace std
+{
+ %ignore exception;
+ struct exception {};
+}
+
+%typemap(throws, canthrow=1) std::bad_exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::domain_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::invalid_argument "SWIG_DSetPendingException(SWIG_DIllegalArgumentException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::length_error "SWIG_DSetPendingException(SWIG_DNoSuchElementException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::logic_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::out_of_range "SWIG_DSetPendingException(SWIG_DNoSuchElementException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::overflow_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::range_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::runtime_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::underflow_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+
diff --git a/Lib/d/std_map.i b/Lib/d/std_map.i
new file mode 100644
index 000000000..0e8574b8a
--- /dev/null
+++ b/Lib/d/std_map.i
@@ -0,0 +1,59 @@
+/* -----------------------------------------------------------------------------
+ * std_map.i
+ *
+ * SWIG typemaps for std::map
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+
+// ------------------------------------------------------------------------
+// std::map
+// ------------------------------------------------------------------------
+
+%{
+#include <map>
+#include <algorithm>
+#include <stdexcept>
+%}
+
+// exported class
+
+namespace std {
+ template<class K, class T> class map {
+ // add typemaps here
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef K key_type;
+ typedef T mapped_type;
+ map();
+ map(const map<K,T> &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+ %extend {
+ const T& get(const K& key) throw (std::out_of_range) {
+ std::map<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ return i->second;
+ else
+ throw std::out_of_range("key not found");
+ }
+ void set(const K& key, const T& x) {
+ (*self)[key] = x;
+ }
+ void del(const K& key) throw (std::out_of_range) {
+ std::map<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ self->erase(i);
+ else
+ throw std::out_of_range("key not found");
+ }
+ bool has_key(const K& key) {
+ std::map<K,T >::iterator i = self->find(key);
+ return i != self->end();
+ }
+ }
+ };
+}
diff --git a/Lib/d/std_pair.i b/Lib/d/std_pair.i
new file mode 100644
index 000000000..0712ad762
--- /dev/null
+++ b/Lib/d/std_pair.i
@@ -0,0 +1,34 @@
+/* -----------------------------------------------------------------------------
+ * std_pair.i
+ *
+ * SWIG typemaps for std::pair
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+%include <exception.i>
+
+// ------------------------------------------------------------------------
+// std::pair
+// ------------------------------------------------------------------------
+
+%{
+#include <utility>
+%}
+
+namespace std {
+
+ template<class T, class U> struct pair {
+
+ pair();
+ pair(T t, U u);
+ pair(const pair& p);
+
+ template <class U1, class U2> pair(const pair<U1, U2> &p);
+
+ T first;
+ U second;
+ };
+
+ // add specializations here
+
+}
diff --git a/Lib/d/std_shared_ptr.i b/Lib/d/std_shared_ptr.i
new file mode 100644
index 000000000..df873679c
--- /dev/null
+++ b/Lib/d/std_shared_ptr.i
@@ -0,0 +1,2 @@
+#define SWIG_SHARED_PTR_NAMESPACE std
+%include <boost_shared_ptr.i>
diff --git a/Lib/d/std_string.i b/Lib/d/std_string.i
new file mode 100644
index 000000000..4938cfdf7
--- /dev/null
+++ b/Lib/d/std_string.i
@@ -0,0 +1,98 @@
+/* -----------------------------------------------------------------------------
+ * std_string.i
+ *
+ * Typemaps for std::string and const std::string&
+ * These are mapped to a D char[] and are passed around by value.
+ *
+ * To use non-const std::string references, use the following %apply. Note
+ * that they are passed by value.
+ * %apply const std::string & {std::string &};
+ * ----------------------------------------------------------------------------- */
+
+%{
+#include <string>
+%}
+
+namespace std {
+
+%naturalvar string;
+
+class string;
+
+%define SWIGD_STD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
+// string
+%typemap(cwtype) string, const string & "char *"
+%typemap(dwtype) string, const string & #DW_STRING_TYPE
+%typemap(dptype) string, const string & #DP_STRING_TYPE
+
+%typemap(in, canthrow=1) string, const string &
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
+ return $null;
+ }
+ $1.assign($input); %}
+%typemap(in, canthrow=1) const string &
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
+ return $null;
+ }
+ std::string $1_str($input);
+ $1 = &$1_str; %}
+
+%typemap(out) string %{ $result = SWIG_d_string_callback($1.c_str()); %}
+%typemap(out) const string & %{ $result = SWIG_d_string_callback($1->c_str()); %}
+
+%typemap(din) string, const string & "($dinput ? TO_STRINGZ($dinput) : null)"
+%typemap(dout, excode=SWIGEXCODE) string, const string & {
+ DP_STRING_TYPE ret = FROM_STRINGZ($wcall);$excode
+ return ret;
+}
+
+%typemap(directorin) string, const string & %{ $input = SWIG_d_string_callback($1.c_str()); %}
+
+%typemap(directorout, canthrow=1) string
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
+ return $null;
+ }
+ $result.assign($input); %}
+
+%typemap(directorout, canthrow=1, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
+ return $null;
+ }
+ /* possible thread/reentrant code problem */
+ static std::string $1_str;
+ $1_str = $input;
+ $result = &$1_str; %}
+
+%typemap(ddirectorin) string, const string & "FROM_STRINGZ($winput)"
+%typemap(ddirectorout) string, const string & "TO_STRINGZ($dpcall)"
+
+%typemap(throws, canthrow=1) string, const string &
+%{ SWIG_DSetPendingException(SWIG_DException, $1.c_str());
+ return $null; %}
+
+%typemap(typecheck) string, const string & = char *;
+%enddef
+
+// We need to have the \0-terminated string conversion functions available in
+// the D proxy modules.
+#if (SWIG_D_VERSION == 1)
+// Could be easily extended to support Phobos as well.
+SWIGD_STD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
+
+%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
+#else
+SWIGD_STD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
+
+%pragma(d) globalproxyimports = %{
+static import std.conv;
+static import std.string;
+%}
+#endif
+
+#undef SWIGD_STD_STRING_TYPEMAPS
+
+} // namespace std
diff --git a/Lib/d/std_vector.i b/Lib/d/std_vector.i
new file mode 100644
index 000000000..cdaf1e30b
--- /dev/null
+++ b/Lib/d/std_vector.i
@@ -0,0 +1,591 @@
+/* -----------------------------------------------------------------------------
+ * std_vector.i
+ *
+ * SWIG typemaps for std::vector<T>, D implementation.
+ *
+ * The D wrapper is made to loosely resemble a tango.util.container.more.Vector
+ * and to provide built-in array-like access.
+ *
+ * If T does define an operator==, then use the SWIG_STD_VECTOR_ENHANCED
+ * macro to obtain enhanced functionality (none yet), for example:
+ *
+ * SWIG_STD_VECTOR_ENHANCED(SomeNamespace::Klass)
+ * %template(VectKlass) std::vector<SomeNamespace::Klass>;
+ *
+ * Warning: heavy macro usage in this file. Use swig -E to get a sane view on
+ * the real file contents!
+ * ----------------------------------------------------------------------------- */
+
+// Warning: Use the typemaps here in the expectation that the macros they are in will change name.
+
+%include <std_common.i>
+
+// MACRO for use within the std::vector class body
+%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE, CWTYPE...)
+#if (SWIG_D_VERSION == 1)
+%typemap(dimports) std::vector< CWTYPE > "static import tango.core.Exception;"
+%typemap(dcode) std::vector< CWTYPE > %{
+public this($typemap(dptype, CWTYPE)[] values) {
+ this();
+ append(values);
+}
+
+alias push_back add;
+alias push_back push;
+alias push_back opCatAssign;
+alias size length;
+alias opSlice slice;
+
+public $typemap(dptype, CWTYPE) opIndexAssign($typemap(dptype, CWTYPE) value, size_t index) {
+ if (index >= size()) {
+ throw new tango.core.Exception.NoSuchElementException("Tried to assign to element out of vector bounds.");
+ }
+ setElement(index, value);
+ return value;
+}
+
+public $typemap(dptype, CWTYPE) opIndex(size_t index) {
+ if (index >= size()) {
+ throw new tango.core.Exception.NoSuchElementException("Tried to read from element out of vector bounds.");
+ }
+ return getElement(index);
+}
+
+public void append($typemap(dptype, CWTYPE)[] value...) {
+ foreach (v; value) {
+ add(v);
+ }
+}
+
+public $typemap(dptype, CWTYPE)[] opSlice() {
+ $typemap(dptype, CWTYPE)[] array = new $typemap(dptype, CWTYPE)[size()];
+ foreach (i, ref value; array) {
+ value = getElement(i);
+ }
+ return array;
+}
+
+public int opApply(int delegate(ref $typemap(dptype, CWTYPE) value) dg) {
+ int result;
+
+ size_t currentSize = size();
+ for (size_t i = 0; i < currentSize; ++i) {
+ auto value = getElement(i);
+ result = dg(value);
+ setElement(i, value);
+ }
+ return result;
+}
+
+public int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) dg) {
+ int result;
+
+ size_t currentSize = size();
+ for (size_t i = 0; i < currentSize; ++i) {
+ auto value = getElement(i);
+
+ // Workaround for http://d.puremagic.com/issues/show_bug.cgi?id=2443.
+ auto index = i;
+
+ result = dg(index, value);
+ setElement(i, value);
+ }
+ return result;
+}
+
+public void capacity(size_t value) {
+ if (value < size()) {
+ throw new tango.core.Exception.IllegalArgumentException("Tried to make the capacity of a vector smaller than its size.");
+ }
+
+ reserve(value);
+}
+%}
+
+ public:
+ typedef size_t size_type;
+ typedef CWTYPE value_type;
+ typedef CONST_REFERENCE const_reference;
+ void clear();
+ void push_back(CWTYPE const& x);
+ size_type size() const;
+ size_type capacity() const;
+ void reserve(size_type n) throw (std::length_error);
+ vector();
+ vector(const vector &other);
+ %extend {
+ vector(size_type capacity) throw (std::length_error) {
+ std::vector< CWTYPE >* pv = 0;
+ pv = new std::vector< CWTYPE >();
+
+ // Might throw std::length_error.
+ pv->reserve(capacity);
+
+ return pv;
+ }
+
+ size_type unused() const {
+ return $self->capacity() - $self->size();
+ }
+
+ const_reference remove() throw (std::out_of_range) {
+ if ($self->empty()) {
+ throw std::out_of_range("Tried to remove last element from empty vector.");
+ }
+
+ std::vector< CWTYPE >::const_reference value = $self->back();
+ $self->pop_back();
+ return value;
+ }
+
+ const_reference remove(size_type index) throw (std::out_of_range) {
+ if (index >= $self->size()) {
+ throw std::out_of_range("Tried to remove element with invalid index.");
+ }
+
+ std::vector< CWTYPE >::iterator it = $self->begin() + index;
+ std::vector< CWTYPE >::const_reference value = *it;
+ $self->erase(it);
+ return value;
+ }
+ }
+
+ // Wrappers for setting/getting items with the possibly thrown exception
+ // specified (important for SWIG wrapper generation).
+ %extend {
+ const_reference getElement(size_type index) throw (std::out_of_range) {
+ if ((index < 0) || ($self->size() <= index)) {
+ throw std::out_of_range("Tried to get value of element with invalid index.");
+ }
+ return (*$self)[index];
+ }
+ }
+
+ // Use CWTYPE const& instead of const_reference to work around SWIG code
+ // generation issue when using const pointers as vector elements (like
+ // std::vector< const int* >).
+ %extend {
+ void setElement(size_type index, CWTYPE const& val) throw (std::out_of_range) {
+ if ((index < 0) || ($self->size() <= index)) {
+ throw std::out_of_range("Tried to set value of element with invalid index.");
+ }
+ (*$self)[index] = val;
+ }
+ }
+
+%dmethodmodifiers std::vector::getElement "private"
+%dmethodmodifiers std::vector::setElement "private"
+%dmethodmodifiers std::vector::reserve "private"
+
+#else
+
+%typemap(dimports) std::vector< CWTYPE > %{
+static import std.algorithm;
+static import std.exception;
+static import std.range;
+static import std.traits;
+%}
+%typemap(dcode) std::vector< CWTYPE > %{
+alias size_t KeyType;
+alias $typemap(dptype, CWTYPE) ValueType;
+
+this(ValueType[] values...) {
+ this();
+ reserve(values.length);
+ foreach (e; values) {
+ this ~= e;
+ }
+}
+
+struct Range {
+ private $typemap(dptype, std::vector< CWTYPE >) _outer;
+ private size_t _a, _b;
+
+ this($typemap(dptype, std::vector< CWTYPE >) data, size_t a, size_t b) {
+ _outer = data;
+ _a = a;
+ _b = b;
+ }
+
+ @property bool empty() const {
+ assert((cast($typemap(dptype, std::vector< CWTYPE >))_outer).length >= _b);
+ return _a >= _b;
+ }
+
+ @property Range save() {
+ return this;
+ }
+
+ @property ValueType front() {
+ std.exception.enforce(!empty);
+ return _outer[_a];
+ }
+
+ @property void front(ValueType value) {
+ std.exception.enforce(!empty);
+ _outer[_a] = std.algorithm.move(value);
+ }
+
+ void popFront() {
+ std.exception.enforce(!empty);
+ ++_a;
+ }
+
+ void opIndexAssign(ValueType value, size_t i) {
+ i += _a;
+ std.exception.enforce(i < _b && _b <= _outer.length);
+ _outer[i] = value;
+ }
+
+ void opIndexOpAssign(string op)(ValueType value, size_t i) {
+ std.exception.enforce(_outer && _a + i < _b && _b <= _outer.length);
+ auto element = _outer[i];
+ mixin("element "~op~"= value;");
+ _outer[i] = element;
+ }
+}
+
+// TODO: dup?
+
+Range opSlice() {
+ return Range(this, 0, length);
+}
+
+Range opSlice(size_t a, size_t b) {
+ std.exception.enforce(a <= b && b <= length);
+ return Range(this, a, b);
+}
+
+size_t opDollar() const {
+ return length;
+}
+
+@property ValueType front() {
+ std.exception.enforce(!empty);
+ return getElement(0);
+}
+
+@property void front(ValueType value) {
+ std.exception.enforce(!empty);
+ setElement(0, value);
+}
+
+@property ValueType back() {
+ std.exception.enforce(!empty);
+ return getElement(length - 1);
+}
+
+@property void back(ValueType value) {
+ std.exception.enforce(!empty);
+ setElement(length - 1, value);
+}
+
+ValueType opIndex(size_t i) {
+ return getElement(i);
+}
+
+void opIndexAssign(ValueType value, size_t i) {
+ setElement(i, value);
+}
+
+void opIndexOpAssign(string op)(ValueType value, size_t i) {
+ auto element = this[i];
+ mixin("element "~op~"= value;");
+ this[i] = element;
+}
+
+ValueType[] opBinary(string op, Stuff)(Stuff stuff) if (op == "~") {
+ ValueType[] result;
+ result ~= this[];
+ assert(result.length == length);
+ result ~= stuff[];
+ return result;
+}
+
+void opOpAssign(string op, Stuff)(Stuff stuff) if (op == "~") {
+ static if (is(typeof(insertBack(stuff)))) {
+ insertBack(stuff);
+ } else if (is(typeof(insertBack(stuff[])))) {
+ insertBack(stuff[]);
+ } else {
+ static assert(false, "Cannot append " ~ Stuff.stringof ~ " to " ~ typeof(this).stringof);
+ }
+}
+
+alias size length;
+
+alias remove removeAny;
+alias removeAny stableRemoveAny;
+
+size_t insertBack(Stuff)(Stuff stuff)
+if (std.traits.isImplicitlyConvertible!(Stuff, ValueType)){
+ push_back(stuff);
+ return 1;
+}
+size_t insertBack(Stuff)(Stuff stuff)
+if (std.range.isInputRange!Stuff &&
+ std.traits.isImplicitlyConvertible!(std.range.ElementType!Stuff, ValueType)) {
+ size_t itemCount;
+ foreach(item; stuff) {
+ insertBack(item);
+ ++itemCount;
+ }
+ return itemCount;
+}
+alias insertBack insert;
+
+alias pop_back removeBack;
+alias pop_back stableRemoveBack;
+
+size_t insertBefore(Stuff)(Range r, Stuff stuff)
+if (std.traits.isImplicitlyConvertible!(Stuff, ValueType)) {
+ std.exception.enforce(r._outer.swigCPtr == swigCPtr && r._a < length);
+ insertAt(r._a, stuff);
+ return 1;
+}
+
+size_t insertBefore(Stuff)(Range r, Stuff stuff)
+if (std.range.isInputRange!Stuff && std.traits.isImplicitlyConvertible!(ElementType!Stuff, ValueType)) {
+ std.exception.enforce(r._outer.swigCPtr == swigCPtr && r._a <= length);
+
+ size_t insertCount;
+ foreach(i, item; stuff) {
+ insertAt(r._a + i, item);
+ ++insertCount;
+ }
+
+ return insertCount;
+}
+
+size_t insertAfter(Stuff)(Range r, Stuff stuff) {
+ // TODO: optimize
+ immutable offset = r._a + r.length;
+ std.exception.enforce(offset <= length);
+ auto result = insertBack(stuff);
+ std.algorithm.bringToFront(this[offset .. length - result],
+ this[length - result .. length]);
+ return result;
+}
+
+size_t replace(Stuff)(Range r, Stuff stuff)
+if (std.range.isInputRange!Stuff &&
+ std.traits.isImplicitlyConvertible!(ElementType!Stuff, ValueType)) {
+ immutable offset = r._a;
+ std.exception.enforce(offset <= length);
+ size_t result;
+ for (; !stuff.empty; stuff.popFront()) {
+ if (r.empty) {
+ // append the rest
+ return result + insertBack(stuff);
+ }
+ r.front = stuff.front;
+ r.popFront();
+ ++result;
+ }
+ // Remove remaining stuff in r
+ remove(r);
+ return result;
+}
+
+size_t replace(Stuff)(Range r, Stuff stuff)
+if (std.traits.isImplicitlyConvertible!(Stuff, ValueType))
+{
+ if (r.empty)
+ {
+ insertBefore(r, stuff);
+ }
+ else
+ {
+ r.front = stuff;
+ r.popFront();
+ remove(r);
+ }
+ return 1;
+}
+
+Range linearRemove(Range r) {
+ std.exception.enforce(r._a <= r._b && r._b <= length);
+ immutable tailLength = length - r._b;
+ linearRemove(r._a, r._b);
+ return this[length - tailLength .. length];
+}
+alias remove stableLinearRemove;
+
+int opApply(int delegate(ref $typemap(dptype, CWTYPE) value) dg) {
+ int result;
+
+ size_t currentSize = size();
+ for (size_t i = 0; i < currentSize; ++i) {
+ auto value = getElement(i);
+ result = dg(value);
+ setElement(i, value);
+ }
+ return result;
+}
+
+int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) dg) {
+ int result;
+
+ size_t currentSize = size();
+ for (size_t i = 0; i < currentSize; ++i) {
+ auto value = getElement(i);
+
+ // Workaround for http://d.puremagic.com/issues/show_bug.cgi?id=2443.
+ auto index = i;
+
+ result = dg(index, value);
+ setElement(i, value);
+ }
+ return result;
+}
+%}
+
+ public:
+ typedef size_t size_type;
+ typedef CWTYPE value_type;
+ typedef CONST_REFERENCE const_reference;
+ bool empty() const;
+ void clear();
+ void push_back(CWTYPE const& x);
+ void pop_back();
+ size_type size() const;
+ size_type capacity() const;
+ void reserve(size_type n) throw (std::length_error);
+ vector();
+ vector(const vector &other);
+ %extend {
+ vector(size_type capacity) throw (std::length_error) {
+ std::vector< CWTYPE >* pv = 0;
+ pv = new std::vector< CWTYPE >();
+
+ // Might throw std::length_error.
+ pv->reserve(capacity);
+
+ return pv;
+ }
+
+ const_reference remove() throw (std::out_of_range) {
+ if ($self->empty()) {
+ throw std::out_of_range("Tried to remove last element from empty vector.");
+ }
+
+ std::vector< CWTYPE >::const_reference value = $self->back();
+ $self->pop_back();
+ return value;
+ }
+
+ const_reference remove(size_type index) throw (std::out_of_range) {
+ if (index >= $self->size()) {
+ throw std::out_of_range("Tried to remove element with invalid index.");
+ }
+
+ std::vector< CWTYPE >::iterator it = $self->begin() + index;
+ std::vector< CWTYPE >::const_reference value = *it;
+ $self->erase(it);
+ return value;
+ }
+
+ void removeBack(size_type how_many) throw (std::out_of_range) {
+ std::vector< CWTYPE >::iterator end = $self->end();
+ std::vector< CWTYPE >::iterator start = end - how_many;
+ $self->erase(start, end);
+ }
+
+ void linearRemove(size_type start_index, size_type end_index) throw (std::out_of_range) {
+ std::vector< CWTYPE >::iterator start = $self->begin() + start_index;
+ std::vector< CWTYPE >::iterator end = $self->begin() + end_index;
+ $self->erase(start, end);
+ }
+
+ void insertAt(size_type index, CWTYPE const& x) throw (std::out_of_range) {
+ std::vector< CWTYPE >::iterator it = $self->begin() + index;
+ $self->insert(it, x);
+ }
+ }
+
+ // Wrappers for setting/getting items with the possibly thrown exception
+ // specified (important for SWIG wrapper generation).
+ %extend {
+ const_reference getElement(size_type index) throw (std::out_of_range) {
+ if ((index < 0) || ($self->size() <= index)) {
+ throw std::out_of_range("Tried to get value of element with invalid index.");
+ }
+ return (*$self)[index];
+ }
+ }
+ // Use CWTYPE const& instead of const_reference to work around SWIG code
+ // generation issue when using const pointers as vector elements (like
+ // std::vector< const int* >).
+ %extend {
+ void setElement(size_type index, CWTYPE const& val) throw (std::out_of_range) {
+ if ((index < 0) || ($self->size() <= index)) {
+ throw std::out_of_range("Tried to set value of element with invalid index.");
+ }
+ (*$self)[index] = val;
+ }
+ }
+
+%dmethodmodifiers std::vector::getElement "private"
+%dmethodmodifiers std::vector::setElement "private"
+#endif
+%enddef
+
+// Extra methods added to the collection class if operator== is defined for the class being wrapped
+// The class will then implement IList<>, which adds extra functionality
+%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CWTYPE...)
+ %extend {
+ }
+%enddef
+
+// For vararg handling in macros, from swigmacros.swg
+#define %arg(X...) X
+
+// Macros for std::vector class specializations/enhancements
+%define SWIG_STD_VECTOR_ENHANCED(CWTYPE...)
+namespace std {
+ template<> class vector<CWTYPE > {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(%arg(CWTYPE const&), %arg(CWTYPE))
+ SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CWTYPE)
+ };
+}
+%enddef
+
+%{
+#include <vector>
+#include <stdexcept>
+%}
+
+namespace std {
+ // primary (unspecialized) class template for std::vector
+ // does not require operator== to be defined
+ template<class T> class vector {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(T const&, T)
+ };
+ // specializations for pointers
+ template<class T> class vector<T *> {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(T *const&, T *)
+ SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *)
+ };
+ // bool is a bit different in the C++ standard - const_reference in particular
+ template<> class vector<bool> {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(bool, bool)
+ SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool)
+ };
+}
+
+// template specializations for std::vector
+// these provide extra collections methods as operator== is defined
+SWIG_STD_VECTOR_ENHANCED(char)
+SWIG_STD_VECTOR_ENHANCED(signed char)
+SWIG_STD_VECTOR_ENHANCED(unsigned char)
+SWIG_STD_VECTOR_ENHANCED(short)
+SWIG_STD_VECTOR_ENHANCED(unsigned short)
+SWIG_STD_VECTOR_ENHANCED(int)
+SWIG_STD_VECTOR_ENHANCED(unsigned int)
+SWIG_STD_VECTOR_ENHANCED(long)
+SWIG_STD_VECTOR_ENHANCED(unsigned long)
+SWIG_STD_VECTOR_ENHANCED(long long)
+SWIG_STD_VECTOR_ENHANCED(unsigned long long)
+SWIG_STD_VECTOR_ENHANCED(float)
+SWIG_STD_VECTOR_ENHANCED(double)
+SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include <std_string.i>
diff --git a/Lib/d/stl.i b/Lib/d/stl.i
new file mode 100644
index 000000000..9d2e91eee
--- /dev/null
+++ b/Lib/d/stl.i
@@ -0,0 +1,12 @@
+/* -----------------------------------------------------------------------------
+ * stl.i
+ *
+ * Initial STL definition. extended as needed in each language
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+%include <std_string.i>
+%include <std_vector.i>
+%include <std_map.i>
+%include <std_pair.i>
+
diff --git a/Lib/d/typemaps.i b/Lib/d/typemaps.i
new file mode 100644
index 000000000..cd5636562
--- /dev/null
+++ b/Lib/d/typemaps.i
@@ -0,0 +1,298 @@
+/* -----------------------------------------------------------------------------
+ * typemaps.i
+ *
+ * Pointer and reference handling typemap library
+ *
+ * These mappings provide support for input/output arguments and common
+ * uses for C/C++ pointers and C++ references.
+ * ----------------------------------------------------------------------------- */
+
+/*
+INPUT typemaps
+--------------
+
+These typemaps are used for pointer/reference parameters that are input only
+and are mapped to a D input parameter.
+
+The following typemaps can be applied to turn a pointer or reference into a simple
+input value. That is, instead of passing a pointer or reference to an object,
+you would use a real value instead.
+
+ bool *INPUT, bool &INPUT
+ signed char *INPUT, signed char &INPUT
+ unsigned char *INPUT, unsigned char &INPUT
+ short *INPUT, short &INPUT
+ unsigned short *INPUT, unsigned short &INPUT
+ int *INPUT, int &INPUT
+ unsigned int *INPUT, unsigned int &INPUT
+ long *INPUT, long &INPUT
+ unsigned long *INPUT, unsigned long &INPUT
+ long long *INPUT, long long &INPUT
+ unsigned long long *INPUT, unsigned long long &INPUT
+ float *INPUT, float &INPUT
+ double *INPUT, double &INPUT
+
+To use these, suppose you had a C function like this :
+
+ double fadd(double *a, double *b) {
+ return *a+*b;
+ }
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ double fadd(double *INPUT, double *INPUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *INPUT { double *a, double *b };
+ double fadd(double *a, double *b);
+
+In D you could then use it like this:
+ double answer = fadd(10.0, 20.0);
+*/
+
+%define INPUT_TYPEMAP(TYPE, CWTYPE, DTYPE)
+%typemap(cwtype) TYPE *INPUT, TYPE &INPUT "CWTYPE"
+%typemap(dwtype) TYPE *INPUT, TYPE &INPUT "DTYPE"
+%typemap(dptype) TYPE *INPUT, TYPE &INPUT "DTYPE"
+%typemap(din) TYPE *INPUT, TYPE &INPUT "$dinput"
+%typemap(ddirectorin) TYPE *INPUT, TYPE &INPUT "$winput"
+%typemap(ddirectorout) TYPE *INPUT, TYPE &INPUT "$dpcall"
+
+%typemap(in) TYPE *INPUT, TYPE &INPUT
+%{ $1 = ($1_ltype)&$input; %}
+
+%typemap(directorout) TYPE *INPUT, TYPE &INPUT
+%{ $result = ($1_ltype)&$input; %}
+
+%typemap(directorin) TYPE &INPUT
+%{ $input = (CWTYPE *)$1; %}
+
+%typemap(directorin) TYPE *INPUT
+%{ $input = (CWTYPE *)$1; %}
+
+%typemap(typecheck) TYPE *INPUT = TYPE;
+%typemap(typecheck) TYPE &INPUT = TYPE;
+%enddef
+
+INPUT_TYPEMAP(bool, unsigned int, bool)
+//INPUT_TYPEMAP(char, char, char) // Why was this commented out?
+INPUT_TYPEMAP(signed char, signed char, byte)
+INPUT_TYPEMAP(unsigned char, unsigned char, ubyte)
+INPUT_TYPEMAP(short, short, short)
+INPUT_TYPEMAP(unsigned short, unsigned short, ushort)
+INPUT_TYPEMAP(int, int, int)
+INPUT_TYPEMAP(unsigned int, unsigned int, uint)
+INPUT_TYPEMAP(long, long, int)
+INPUT_TYPEMAP(unsigned long, unsigned long, uint)
+INPUT_TYPEMAP(long long, long long, long)
+INPUT_TYPEMAP(unsigned long long, unsigned long long, ulong)
+INPUT_TYPEMAP(float, float, float)
+INPUT_TYPEMAP(double, double, double)
+
+INPUT_TYPEMAP(enum SWIGTYPE, unsigned int, int)
+%typemap(dptype) enum SWIGTYPE *INPUT, enum SWIGTYPE &INPUT "$*dclassname"
+
+#undef INPUT_TYPEMAP
+
+
+/*
+OUTPUT typemaps
+---------------
+
+These typemaps are used for pointer/reference parameters that are output only and
+are mapped to a D output parameter.
+
+The following typemaps can be applied to turn a pointer or reference into an
+"output" value. When calling a function, no input value would be given for
+a parameter, but an output value would be returned. In D, the 'out' keyword is
+used when passing the parameter to a function that takes an output parameter.
+
+ bool *OUTPUT, bool &OUTPUT
+ signed char *OUTPUT, signed char &OUTPUT
+ unsigned char *OUTPUT, unsigned char &OUTPUT
+ short *OUTPUT, short &OUTPUT
+ unsigned short *OUTPUT, unsigned short &OUTPUT
+ int *OUTPUT, int &OUTPUT
+ unsigned int *OUTPUT, unsigned int &OUTPUT
+ long *OUTPUT, long &OUTPUT
+ unsigned long *OUTPUT, unsigned long &OUTPUT
+ long long *OUTPUT, long long &OUTPUT
+ unsigned long long *OUTPUT, unsigned long long &OUTPUT
+ float *OUTPUT, float &OUTPUT
+ double *OUTPUT, double &OUTPUT
+
+For example, suppose you were trying to wrap the modf() function in the
+C math library which splits x into integral and fractional parts (and
+returns the integer part in one of its parameters):
+
+ double modf(double x, double *ip);
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ double modf(double x, double *OUTPUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *OUTPUT { double *ip };
+ double modf(double x, double *ip);
+
+The D output of the function would be the function return value and the
+value returned in the second output parameter. In D you would use it like this:
+
+ double dptr;
+ double fraction = modf(5, dptr);
+*/
+
+%define OUTPUT_TYPEMAP(TYPE, CWTYPE, DTYPE, TYPECHECKPRECEDENCE)
+%typemap(cwtype) TYPE *OUTPUT, TYPE &OUTPUT "CWTYPE *"
+%typemap(dwtype) TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
+%typemap(dptype) TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
+%typemap(din) TYPE *OUTPUT, TYPE &OUTPUT "$dinput"
+%typemap(ddirectorin) TYPE *OUTPUT, TYPE &OUTPUT "$winput"
+%typemap(ddirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$dpcall"
+
+
+%typemap(in) TYPE *OUTPUT, TYPE &OUTPUT
+%{ $1 = ($1_ltype)$input; %}
+
+%typemap(directorout,warning="Need to provide TYPE *OUTPUT directorout typemap") TYPE *OUTPUT, TYPE &OUTPUT {
+}
+
+%typemap(directorin) TYPE &OUTPUT
+%{ $input = &$1; %}
+
+%typemap(directorin,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT
+{
+}
+
+
+%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *OUTPUT, TYPE &OUTPUT ""
+%enddef
+
+OUTPUT_TYPEMAP(bool, unsigned int, bool, BOOL_PTR)
+//OUTPUT_TYPEMAP(char, char, char, CHAR_PTR) // Why was this commented out?
+OUTPUT_TYPEMAP(signed char, signed char, ubyte, INT8_PTR)
+OUTPUT_TYPEMAP(unsigned char, unsigned char, byte, UINT8_PTR)
+OUTPUT_TYPEMAP(short, short, short, INT16_PTR)
+OUTPUT_TYPEMAP(unsigned short, unsigned short, ushort, UINT16_PTR)
+OUTPUT_TYPEMAP(int, int, int, INT32_PTR)
+OUTPUT_TYPEMAP(unsigned int, unsigned int, uint, UINT32_PTR)
+OUTPUT_TYPEMAP(long, long, int, INT32_PTR)
+OUTPUT_TYPEMAP(unsigned long, unsigned long, uint, UINT32_PTR)
+OUTPUT_TYPEMAP(long long, long long, long, INT64_PTR)
+OUTPUT_TYPEMAP(unsigned long long, unsigned long long, ulong, UINT64_PTR)
+OUTPUT_TYPEMAP(float, float, float, FLOAT_PTR)
+OUTPUT_TYPEMAP(double, double, double, DOUBLE_PTR)
+
+OUTPUT_TYPEMAP(enum SWIGTYPE, unsigned int, int, INT32_PTR)
+%typemap(dptype) enum SWIGTYPE *OUTPUT, enum SWIGTYPE &OUTPUT "out $*dclassname"
+
+#undef OUTPUT_TYPEMAP
+
+%typemap(in) bool *OUTPUT, bool &OUTPUT
+%{ *$input = 0;
+ $1 = ($1_ltype)$input; %}
+
+
+/*
+INOUT typemaps
+--------------
+
+These typemaps are for pointer/reference parameters that are both input and
+output and are mapped to a D reference parameter.
+
+The following typemaps can be applied to turn a pointer or reference into a
+reference parameters, that is the parameter is both an input and an output.
+In D, the 'ref' keyword is used for reference parameters.
+
+ bool *INOUT, bool &INOUT
+ signed char *INOUT, signed char &INOUT
+ unsigned char *INOUT, unsigned char &INOUT
+ short *INOUT, short &INOUT
+ unsigned short *INOUT, unsigned short &INOUT
+ int *INOUT, int &INOUT
+ unsigned int *INOUT, unsigned int &INOUT
+ long *INOUT, long &INOUT
+ unsigned long *INOUT, unsigned long &INOUT
+ long long *INOUT, long long &INOUT
+ unsigned long long *INOUT, unsigned long long &INOUT
+ float *INOUT, float &INOUT
+ double *INOUT, double &INOUT
+
+For example, suppose you were trying to wrap the following function :
+
+ void neg(double *x) {
+ *x = -(*x);
+ }
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ void neg(double *INOUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *INOUT { double *x };
+ void neg(double *x);
+
+The D output of the function would be the new value returned by the
+reference parameter. In D you would use it like this:
+
+
+ double x = 5.0;
+ neg(x);
+
+The implementation of the OUTPUT and INOUT typemaps is different to the scripting
+languages in that the scripting languages will return the output value as part
+of the function return value.
+*/
+
+%define INOUT_TYPEMAP(TYPE, CWTYPE, DTYPE, TYPECHECKPRECEDENCE)
+%typemap(cwtype) TYPE *INOUT, TYPE &INOUT "CWTYPE *"
+%typemap(dwtype) TYPE *INOUT, TYPE &INOUT "ref DTYPE"
+%typemap(dptype) TYPE *INOUT, TYPE &INOUT "ref DTYPE"
+%typemap(din) TYPE *INOUT, TYPE &INOUT "$dinput"
+%typemap(ddirectorin) TYPE *INOUT, TYPE &INOUT "$winput"
+%typemap(ddirectorout) TYPE *INOUT, TYPE &INOUT "$dpcall"
+
+%typemap(in) TYPE *INOUT, TYPE &INOUT
+%{ $1 = ($1_ltype)$input; %}
+
+%typemap(directorout,warning="Need to provide TYPE *INOUT directorout typemap") TYPE *INOUT, TYPE &INOUT {
+}
+
+%typemap(directorin) TYPE &INOUT
+%{ $input = &$1; %}
+
+%typemap(directorin,warning="Need to provide TYPE *INOUT directorin typemap, TYPE array length is unknown") TYPE *INOUT, TYPE &INOUT
+{
+}
+
+%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *INOUT, TYPE &INOUT ""
+%enddef
+
+INOUT_TYPEMAP(bool, unsigned int, bool, BOOL_PTR)
+//INOUT_TYPEMAP(char, char, char, CHAR_PTR)
+INOUT_TYPEMAP(signed char, signed char, ubyte, INT8_PTR)
+INOUT_TYPEMAP(unsigned char, unsigned char, byte, UINT8_PTR)
+INOUT_TYPEMAP(short, short, short, INT16_PTR)
+INOUT_TYPEMAP(unsigned short, unsigned short, ushort, UINT16_PTR)
+INOUT_TYPEMAP(int, int, int, INT32_PTR)
+INOUT_TYPEMAP(unsigned int, unsigned int, uint, UINT32_PTR)
+INOUT_TYPEMAP(long, long, int, INT32_PTR)
+INOUT_TYPEMAP(unsigned long, unsigned long, uint, UINT32_PTR)
+INOUT_TYPEMAP(long long, long long, long, INT64_PTR)
+INOUT_TYPEMAP(unsigned long long, unsigned long long, ulong, UINT64_PTR)
+INOUT_TYPEMAP(float, float, float, FLOAT_PTR)
+INOUT_TYPEMAP(double, double, double, DOUBLE_PTR)
+
+INOUT_TYPEMAP(enum SWIGTYPE, unsigned int, int, INT32_PTR)
+%typemap(dptype) enum SWIGTYPE *INOUT, enum SWIGTYPE &INOUT "ref $*dclassname"
+
+#undef INOUT_TYPEMAP
diff --git a/Lib/d/wrapperloader.swg b/Lib/d/wrapperloader.swg
new file mode 100644
index 000000000..9336843af
--- /dev/null
+++ b/Lib/d/wrapperloader.swg
@@ -0,0 +1,303 @@
+/* -----------------------------------------------------------------------------
+ * wrapperloader.swg
+ *
+ * Support code for dynamically linking the C wrapper library from the D
+ * wrapper module.
+ *
+ * The loading code was adapted from the Derelict project and is used with
+ * permission from Michael Parker, the original author.
+ * ----------------------------------------------------------------------------- */
+
+%pragma(d) wrapperloadercode = %{
+private {
+ version(linux) {
+ version = Nix;
+ } else version(darwin) {
+ version = Nix;
+ } else version(OSX) {
+ version = Nix;
+ } else version(FreeBSD) {
+ version = Nix;
+ version = freebsd;
+ } else version(freebsd) {
+ version = Nix;
+ } else version(Unix) {
+ version = Nix;
+ } else version(Posix) {
+ version = Nix;
+ }
+
+ version(Tango) {
+ static import tango.stdc.string;
+ static import tango.stdc.stringz;
+
+ version (PhobosCompatibility) {
+ } else {
+ alias char[] string;
+ alias wchar[] wstring;
+ alias dchar[] dstring;
+ }
+ } else {
+ version(D_Version2) {
+ static import std.conv;
+ }
+ static import std.string;
+ static import std.c.string;
+ }
+
+ version(D_Version2) {
+ mixin("alias const(char)* CCPTR;");
+ } else {
+ alias char* CCPTR;
+ }
+
+ CCPTR swigToCString(string str) {
+ version(Tango) {
+ return tango.stdc.stringz.toStringz(str);
+ } else {
+ return std.string.toStringz(str);
+ }
+ }
+
+ string swigToDString(CCPTR cstr) {
+ version(Tango) {
+ return tango.stdc.stringz.fromStringz(cstr);
+ } else {
+ version(D_Version2) {
+ mixin("return std.conv.to!string(cstr);");
+ } else {
+ return std.c.string.toString(cstr);
+ }
+ }
+ }
+}
+
+class SwigSwigSharedLibLoadException : Exception {
+ this(in string[] libNames, in string[] reasons) {
+ string msg = "Failed to load one or more shared libraries:";
+ foreach(i, n; libNames) {
+ msg ~= "\n\t" ~ n ~ " - ";
+ if(i < reasons.length)
+ msg ~= reasons[i];
+ else
+ msg ~= "Unknown";
+ }
+ super(msg);
+ }
+}
+
+class SwigSymbolLoadException : Exception {
+ this(string SwigSharedLibName, string symbolName) {
+ super("Failed to load symbol " ~ symbolName ~ " from shared library " ~ SwigSharedLibName);
+ _symbolName = symbolName;
+ }
+
+ string symbolName() {
+ return _symbolName;
+ }
+
+private:
+ string _symbolName;
+}
+
+private {
+ version(Nix) {
+ version(freebsd) {
+ // the dl* functions are in libc on FreeBSD
+ }
+ else {
+ pragma(lib, "dl");
+ }
+
+ version(Tango) {
+ import tango.sys.Common;
+ } else version(linux) {
+ import std.c.linux.linux;
+ } else {
+ extern(C) {
+ const RTLD_NOW = 2;
+
+ void *dlopen(CCPTR file, int mode);
+ int dlclose(void* handle);
+ void *dlsym(void* handle, CCPTR name);
+ CCPTR dlerror();
+ }
+ }
+
+ alias void* SwigSharedLibHandle;
+
+ SwigSharedLibHandle swigLoadSharedLib(string libName) {
+ return dlopen(swigToCString(libName), RTLD_NOW);
+ }
+
+ void swigUnloadSharedLib(SwigSharedLibHandle hlib) {
+ dlclose(hlib);
+ }
+
+ void* swigGetSymbol(SwigSharedLibHandle hlib, string symbolName) {
+ return dlsym(hlib, swigToCString(symbolName));
+ }
+
+ string swigGetErrorStr() {
+ CCPTR err = dlerror();
+ if (err is null) {
+ return "Unknown Error";
+ }
+ return swigToDString(err);
+ }
+ } else version(Windows) {
+ alias uint DWORD;
+ alias CCPTR LPCSTR;
+ alias void* HMODULE;
+ alias void* HLOCAL;
+ alias int function() FARPROC;
+ struct VA_LIST {}
+
+ extern (Windows) {
+ HMODULE LoadLibraryA(LPCSTR);
+ FARPROC GetProcAddress(HMODULE, LPCSTR);
+ void FreeLibrary(HMODULE);
+ DWORD GetLastError();
+ DWORD FormatMessageA(DWORD, in void*, DWORD, DWORD, LPCSTR, DWORD, VA_LIST*);
+ HLOCAL LocalFree(HLOCAL);
+ }
+
+ enum {
+ LANG_NEUTRAL = 0,
+ SUBLANG_DEFAULT = 1,
+ FORMAT_MESSAGE_ALLOCATE_BUFFER = 256,
+ FORMAT_MESSAGE_IGNORE_INSERTS = 512,
+ FORMAT_MESSAGE_FROM_SYSTEM = 4096
+ }
+
+ alias HMODULE SwigSharedLibHandle;
+
+ SwigSharedLibHandle swigLoadSharedLib(string libName) {
+ return LoadLibraryA(swigToCString(libName));
+ }
+
+ void swigUnloadSharedLib(SwigSharedLibHandle hlib) {
+ FreeLibrary(hlib);
+ }
+
+ void* swigGetSymbol(SwigSharedLibHandle hlib, string symbolName) {
+ return GetProcAddress(hlib, swigToCString(symbolName));
+ }
+
+ string swigGetErrorStr() {
+ DWORD errcode = GetLastError();
+
+ LPCSTR msgBuf;
+ DWORD i = FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ null,
+ errcode,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ cast(LPCSTR)&msgBuf,
+ 0,
+ null);
+
+ string text = swigToDString(msgBuf);
+ LocalFree(cast(HLOCAL)msgBuf);
+
+ if (i >= 2) {
+ i -= 2;
+ }
+ return text[0 .. i];
+ }
+ } else {
+ static assert(0, "Operating system not supported by the wrapper loading code.");
+ }
+
+ final class SwigSharedLib {
+ void load(string[] names) {
+ if (_hlib !is null) return;
+
+ string[] failedLibs;
+ string[] reasons;
+
+ foreach(n; names) {
+ _hlib = swigLoadSharedLib(n);
+ if (_hlib is null) {
+ failedLibs ~= n;
+ reasons ~= swigGetErrorStr();
+ continue;
+ }
+ _name = n;
+ break;
+ }
+
+ if (_hlib is null) {
+ throw new SwigSwigSharedLibLoadException(failedLibs, reasons);
+ }
+ }
+
+ void* loadSymbol(string symbolName, bool doThrow = true) {
+ void* sym = swigGetSymbol(_hlib, symbolName);
+ if(doThrow && (sym is null)) {
+ throw new SwigSymbolLoadException(_name, symbolName);
+ }
+ return sym;
+ }
+
+ void unload() {
+ if(_hlib !is null) {
+ swigUnloadSharedLib(_hlib);
+ _hlib = null;
+ }
+ }
+
+ private:
+ string _name;
+ SwigSharedLibHandle _hlib;
+ }
+}
+
+static this() {
+ string[] possibleFileNames;
+ version (Posix) {
+ version (OSX) {
+ possibleFileNames ~= ["lib$wraplibrary.dylib", "lib$wraplibrary.bundle"];
+ }
+ possibleFileNames ~= ["lib$wraplibrary.so"];
+ } else version (Windows) {
+ possibleFileNames ~= ["$wraplibrary.dll", "lib$wraplibrary.so"];
+ } else {
+ static assert(false, "Operating system not supported by the wrapper loading code.");
+ }
+
+ auto library = new SwigSharedLib;
+ library.load(possibleFileNames);
+
+ string bindCode(string functionPointer, string symbol) {
+ return functionPointer ~ " = cast(typeof(" ~ functionPointer ~
+ "))library.loadSymbol(`" ~ symbol ~ "`);";
+ }
+
+ //#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
+ mixin(bindCode("swigRegisterExceptionCallbacks", "SWIGRegisterExceptionCallbacks_$module"));
+ //#endif // SWIG_D_NO_EXCEPTION_HELPER
+ //#if !defined(SWIG_D_NO_STRING_HELPER)
+ mixin(bindCode("swigRegisterStringCallback", "SWIGRegisterStringCallback_$module"));
+ //#endif // SWIG_D_NO_STRING_HELPER
+ $wrapperloaderbindcode
+}
+
+//#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
+extern(C) void function(
+ SwigExceptionCallback exceptionCallback,
+ SwigExceptionCallback illegalArgumentCallback,
+ SwigExceptionCallback illegalElementCallback,
+ SwigExceptionCallback ioCallback,
+ SwigExceptionCallback noSuchElementCallback) swigRegisterExceptionCallbacks;
+//#endif // SWIG_D_NO_EXCEPTION_HELPER
+
+//#if !defined(SWIG_D_NO_STRING_HELPER)
+extern(C) void function(SwigStringCallback callback) swigRegisterStringCallback;
+//#endif // SWIG_D_NO_STRING_HELPER
+%}
+
+%pragma(d) wrapperloaderbindcommand = %{
+ mixin(bindCode("$function", "$symbol"));%}
diff --git a/Lib/exception.i b/Lib/exception.i
index 2bc86b458..8d8df33dd 100644
--- a/Lib/exception.i
+++ b/Lib/exception.i
@@ -209,6 +209,40 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
#endif // SWIGLUA
+#ifdef SWIGD
+%{
+SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
+ SWIG_DExceptionCodes exception_code;
+ switch(code) {
+ case SWIG_IndexError:
+ exception_code = SWIG_DNoSuchElementException;
+ break;
+ case SWIG_IOError:
+ exception_code = SWIG_DIOException;
+ break;
+ case SWIG_ValueError:
+ exception_code = SWIG_DIllegalArgumentException;
+ break;
+ case SWIG_DivisionByZero:
+ case SWIG_MemoryError:
+ case SWIG_OverflowError:
+ case SWIG_RuntimeError:
+ case SWIG_TypeError:
+ case SWIG_SyntaxError:
+ case SWIG_SystemError:
+ case SWIG_UnknownError:
+ default:
+ exception_code = SWIG_DException;
+ break;
+ }
+ SWIG_DSetPendingException(exception_code, msg);
+}
+%}
+
+#define SWIG_exception(code, msg)\
+{ SWIG_DThrowException(code, msg); return $null; }
+#endif // SWIGD
+
#ifdef __cplusplus
/*
You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
@@ -259,7 +293,7 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
/* rethrow the unknown exception */
-#ifdef SWIGCSHARP
+#if defined(SWIGCSHARP) || defined(SWIGD)
%typemap(throws,noblock=1, canthrow=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
diff --git a/Lib/std_except.i b/Lib/std_except.i
index 769a68995..a4a7a85ac 100644
--- a/Lib/std_except.i
+++ b/Lib/std_except.i
@@ -19,7 +19,7 @@
* a new std_except.i file in the target library directory.
* ----------------------------------------------------------------------------- */
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGUILE) || defined(SWIGUTL)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGUILE) || defined(SWIGUTL) || defined(SWIGD)
#error "This version of std_except.i should not be used"
#endif
diff --git a/Lib/swig.swg b/Lib/swig.swg
index 4ec3d35e6..e7c01823e 100644
--- a/Lib/swig.swg
+++ b/Lib/swig.swg
@@ -77,7 +77,7 @@
#define %clearoldnodefault %feature("oldnodefault","")
/* the %exception directive */
-#ifdef SWIGCSHARP
+#if defined(SWIGCSHARP) || defined(SWIGD)
#define %exception %feature("except", canthrow=1)
#else
#define %exception %feature("except")
@@ -95,7 +95,7 @@
to set/get variable methods. You don't need to use the
%allowexception directive when using %exceptionvar.
*/
-#ifdef SWIGCSHARP
+#if defined(SWIGCSHARP) || defined(SWIGD)
#define %exceptionvar %feature("exceptvar", canthrow=1)
#else
#define %exceptionvar %feature("exceptvar")
diff --git a/Makefile.in b/Makefile.in
index e1f06d0c5..a12366e12 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -76,6 +76,7 @@ skip-cffi = test -n "@SKIP_CFFI@"
skip-uffi = test -n "@SKIP_UFFI@"
skip-r = test -n "@SKIP_R@"
skip-go = test -n "@SKIP_GO@"
+skip-d = test -n "@SKIP_D@"
# Additional dependencies for some tests
skip-gcj = test -n "@SKIP_GCJ@"
@@ -112,6 +113,7 @@ check-aliveness:
@$(skip-lua) || ./$(TARGET) -lua -help
@$(skip-r) || ./$(TARGET) -r -help
@$(skip-go) || ./$(TARGET) -go -help
+ @$(skip-d) || ./$(TARGET) -d -help
check-ccache:
test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) check)
@@ -138,7 +140,8 @@ check-examples: \
check-uffi-examples \
check-cffi-examples \
check-r-examples \
- check-go-examples
+ check-go-examples \
+ check-d-examples
tcl_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/tcl/check.list)
perl5_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/perl5/check.list)
@@ -161,6 +164,7 @@ uffi_examples :=
cffi_examples :=
r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list)
go_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/go/check.list)
+d_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/d/check.list)
# all examples
check-%-examples :
@@ -213,7 +217,8 @@ check-test-suite: \
check-cffi-test-suite \
check-chicken-test-suite \
check-r-test-suite \
- check-go-test-suite
+ check-go-test-suite \
+ check-d-test-suite
check-%-test-suite:
@if test -z "$(skip-$*)"; then \
@@ -265,7 +270,8 @@ all-test-suite: \
all-cffi-test-suite \
all-chicken-test-suite \
all-r-test-suite \
- all-go-test-suite
+ all-go-test-suite \
+ all-d-test-suite
all-%-test-suite:
@$(MAKE) -k -s check-$*-test-suite ACTION=all
@@ -293,7 +299,8 @@ broken-test-suite: \
broken-cffi-test-suite \
broken-chicken-test-suite \
broken-r-test-suite \
- broken-go-test-suite
+ broken-go-test-suite \
+ broken-d-test-suite
broken-%-test-suite:
@$(MAKE) -k -s check-$*-test-suite ACTION=broken
@@ -410,7 +417,7 @@ install-main:
@$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/`echo $(TARGET_NOEXE) | sed '$(transform)'`@EXEEXT@
lib-languages = gcj typemaps tcl perl5 python guile java mzscheme ruby php ocaml octave \
- pike chicken csharp modula3 allegrocl clisp lua cffi uffi r go
+ pike chicken csharp modula3 allegrocl clisp lua cffi uffi r go d
lib-modules = std
diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h
index 5db30e6e9..d7d11b368 100644
--- a/Source/Include/swigwarn.h
+++ b/Source/Include/swigwarn.h
@@ -1,5 +1,5 @@
-/* -----------------------------------------------------------------------------
- * This file is part of SWIG, which is licensed as a whole under version 3
+/* -----------------------------------------------------------------------------
+ * This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
@@ -201,6 +201,23 @@
/* Feel free to claim any number in this space that's not currently being used. Just make sure you
add an entry here */
+#define WARN_D_TYPEMAP_CWTYPE_UNDEF 700
+#define WARN_D_TYPEMAP_DWTYPE_UNDEF 701
+#define WARN_D_TYPEMAP_DPTYPE_UNDEF 702
+#define WARN_D_MULTIPLE_INHERITANCE 703
+#define WARN_D_TYPEMAP_CLASSMOD_UNDEF 704
+#define WARN_D_TYPEMAP_DBODY_UNDEF 705
+#define WARN_D_TYPEMAP_DOUT_UNDEF 706
+#define WARN_D_TYPEMAP_DIN_UNDEF 707
+#define WARN_D_TYPEMAP_DDIRECTORIN_UNDEF 708
+#define WARN_D_TYPEMAP_DCONSTRUCTOR_UNDEF 709
+#define WARN_D_EXCODE_MISSING 710
+#define WARN_D_CANTHROW_MISSING 711
+#define WARN_D_NO_DIRECTORCONNECT_ATTR 712
+#define WARN_D_NAME_COLLISION 713
+
+/* please leave 700-719 free for D */
+
#define WARN_RUBY_WRONG_NAME 801
#define WARN_RUBY_MULTIPLE_INHERITANCE 802
diff --git a/Source/Makefile.am b/Source/Makefile.am
index ddf8018ec..984b9c268 100644
--- a/Source/Makefile.am
+++ b/Source/Makefile.am
@@ -42,6 +42,7 @@ eswig_SOURCES = CParse/cscanner.c \
Modules/clisp.cxx \
Modules/contract.cxx \
Modules/csharp.cxx \
+ Modules/d.cxx \
Modules/directors.cxx \
Modules/emit.cxx \
Modules/go.cxx \
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
new file mode 100644
index 000000000..e3e1d9759
--- /dev/null
+++ b/Source/Modules/d.cxx
@@ -0,0 +1,4359 @@
+/* -----------------------------------------------------------------------------
+ * This file is part of SWIG, which is licensed as a whole under version 3
+ * (or any later version) of the GNU General Public License. Some additional
+ * terms also apply to certain portions of SWIG. The full details of the SWIG
+ * license and copyrights can be found in the LICENSE and COPYRIGHT files
+ * included with the SWIG source code as distributed by the SWIG developers
+ * and at http://www.swig.org/legal.html.
+ *
+ * d.cxx
+ *
+ * D language module for SWIG.
+ * ----------------------------------------------------------------------------- */
+
+char cvsroot_d_cxx[] = "$Id$";
+
+#include "swigmod.h"
+#include "cparse.h"
+#include <ctype.h>
+
+// Hash type used for storing information about director callbacks for a class.
+typedef DOH UpcallData;
+
+class D : public Language {
+ static const char *usage;
+ const String *empty_string;
+ const String *public_string;
+ const String *protected_string;
+ const String *static_string;
+
+ /*
+ * Files and file sections containing C/C++ code.
+ */
+ File *f_begin;
+ File *f_runtime;
+ File *f_runtime_h;
+ File *f_header;
+ File *f_wrappers;
+ File *f_init;
+ File *f_directors;
+ File *f_directors_h;
+ List *filenames_list;
+
+ /*
+ * Command line-set modes of operation.
+ */
+ // Whether a single proxy D module is generated or classes and enums are
+ // written to their own files.
+ bool split_proxy_dmodule;
+
+ // The major D version targeted (currently 1 or 2).
+ unsigned short d_version;
+
+ /*
+ * State variables which indicate what is being wrapped at the moment.
+ * This is probably not the most elegant way of handling state, but it has
+ * proven to work in the C# and Java modules.
+ */
+ // Indicates if wrapping a native function.
+ bool native_function_flag;
+
+ // Indicates if wrapping a static functions or member variables
+ bool static_flag;
+
+ // Indicates if wrapping a nonstatic member variable
+ bool variable_wrapper_flag;
+
+ // Indicates if wrapping a member variable/enum/const.
+ bool wrapping_member_flag;
+
+ // Indicates if wrapping a global variable.
+ bool global_variable_flag;
+
+ // Name of a variable being wrapped.
+ String *variable_name;
+
+ /*
+ * Variables temporarily holding the generated C++ code.
+ */
+ // C++ code for the generated wrapper functions for casts up the C++
+ // for inheritance hierarchies.
+ String *upcasts_code;
+
+ // Function pointer typedefs for handling director callbacks on the C++ side.
+ String *director_callback_typedefs;
+
+ // Variables for storing the function pointers to the director callbacks on
+ // the C++ side.
+ String *director_callback_pointers;
+
+ /*
+ * Names of generated D entities.
+ */
+ // The name of the D module containing the interface to the C wrapper.
+ String *wrap_dmodule_name;
+
+ // The fully qualified name of the wrap D module (package name included).
+ String *wrap_dmodule_fq_name;
+
+ // The name of the proxy module which exposes the (SWIG) module contents as a
+ // D module.
+ String *proxy_dmodule_name;
+
+ // The fully qualified name of the proxy D module.
+ String *proxy_dmodule_fq_name;
+
+ // Optional: Package the D modules are placed in (set via the -package
+ // command line option).
+ String *package;
+
+ // The directory the generated D module files are written to. Is constructed
+ // from the package path if a target package is set, points to the general
+ // output directory otherwise.
+ String *dmodule_directory;
+
+ // The name of the library which contains the C wrapper (used when generating
+ // the dynamic library loader). Can be overridden via the -wrapperlibrary
+ // command line flag.
+ String *wrap_library_name;
+
+ /*
+ * Variables temporarily holding the generated D code.
+ */
+ // Import statements written to the wrap D module header set via
+ // %pragma(d) wrapdmoduleimports.
+ String *wrap_dmodule_imports;
+
+ // The code for the wrap D module body.
+ String *wrap_dmodule_code;
+
+ // Import statements for all proxy modules (the main proxy module and, if in
+ // split proxy module mode, the proxy class modules) from
+ // %pragma(d) globalproxyimports.
+ String *global_proxy_imports;
+
+ // Imports written to the proxy D module header from global_proxy_imports
+ // and, if in split proxy module mode, from D::requireDType().
+ String *proxy_dmodule_imports;
+
+ // The D code for proxy functions/classes which is written to the proxy D
+ // module. If not in split proxy mode, this contains the whole proxy code.
+ String *proxy_dmodule_code;
+
+ // The D code generated for the currently wrapped enum.
+ String *proxy_enum_code;
+
+ /*
+ * D data for the current proxy class.
+ */
+ // The name of the current proxy class.
+ String *proxy_class_name;
+
+ // The import directives for the current proxy class. They are written to the
+ // same D module the proxy class is written to.
+ String *proxy_class_imports;
+
+ // Code for enumerations nested in the current proxy class. Is emitted earlier
+ // than the rest of the body to work around forward referencing-issues.
+ String *proxy_class_enums_code;
+
+ // The generated D code making up the body of the current proxy class.
+ String *proxy_class_body_code;
+
+ // D code which is emitted right after the proxy class.
+ String *proxy_class_epilogue_code;
+
+ // The full code for the current proxy class, including the epilogue.
+ String* proxy_class_code;
+
+ // Contains a D call to the function wrapping C++ the destructor of the
+ // current class (if there is a public C++ destructor).
+ String *destructor_call;
+
+ // D code for the director callbacks generated for the current class.
+ String *director_dcallbacks_code;
+
+ /*
+ * Code for dynamically loading the wrapper library on the D side.
+ */
+ // D code which is inserted into the wrapper module if dynamic linking is used.
+ String *wrapper_loader_code;
+
+ // The D code to bind a function pointer to a library symbol.
+ String *wrapper_loader_bind_command;
+
+ // The cumulated binding commands binding all wrapper functions to the C/C++
+ // library symbols.
+ String *wrapper_loader_bind_code;
+
+ /*
+ * Director data.
+ */
+ List *dmethods_seq;
+ Hash *dmethods_table;
+ int n_dmethods;
+ int first_class_dmethod;
+ int curr_class_dmethod;
+
+ /*
+ * SWIG types data.
+ */
+ // Collects information about encountered types SWIG does not know about (e.g.
+ // incomplete types). This is used later to generate type wrapper proxy
+ // classes for the unknown types.
+ Hash *unknown_types;
+
+
+public:
+ /* ---------------------------------------------------------------------------
+ * D::D()
+ * --------------------------------------------------------------------------- */
+ D():empty_string(NewString("")),
+ public_string(NewString("public")),
+ protected_string(NewString("protected")),
+ f_begin(NULL),
+ f_runtime(NULL),
+ f_runtime_h(NULL),
+ f_header(NULL),
+ f_wrappers(NULL),
+ f_init(NULL),
+ f_directors(NULL),
+ f_directors_h(NULL),
+ filenames_list(NULL),
+ split_proxy_dmodule(false),
+ d_version(1),
+ native_function_flag(false),
+ static_flag(false),
+ variable_wrapper_flag(false),
+ wrapping_member_flag(false),
+ global_variable_flag(false),
+ variable_name(NULL),
+ upcasts_code(NULL),
+ director_callback_typedefs(NULL),
+ director_callback_pointers(NULL),
+ wrap_dmodule_name(NULL),
+ wrap_dmodule_fq_name(NULL),
+ proxy_dmodule_name(NULL),
+ proxy_dmodule_fq_name(NULL),
+ package(NULL),
+ dmodule_directory(NULL),
+ wrap_library_name(NULL),
+ wrap_dmodule_imports(NULL),
+ wrap_dmodule_code(NULL),
+ global_proxy_imports(NULL),
+ proxy_dmodule_imports(NULL),
+ proxy_dmodule_code(NULL),
+ proxy_enum_code(NULL),
+ proxy_class_name(NULL),
+ proxy_class_imports(NULL),
+ proxy_class_enums_code(NULL),
+ proxy_class_body_code(NULL),
+ proxy_class_epilogue_code(NULL),
+ proxy_class_code(NULL),
+ destructor_call(NULL),
+ director_dcallbacks_code(NULL),
+ wrapper_loader_code(NULL),
+ wrapper_loader_bind_command(NULL),
+ wrapper_loader_bind_code(NULL),
+ dmethods_seq(NULL),
+ dmethods_table(NULL),
+ n_dmethods(0),
+ unknown_types(NULL) {
+
+ // For now, multiple inheritance with directors is not possible. It should be
+ // easy to implement though.
+ director_multiple_inheritance = 0;
+ director_language = 1;
+
+ // Not used:
+ Delete(none_comparison);
+ none_comparison = NewString("");
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::main()
+ * --------------------------------------------------------------------------- */
+ virtual void main(int argc, char *argv[]) {
+ SWIG_library_directory("d");
+
+ // Look for certain command line options
+ for (int i = 1; i < argc; i++) {
+ if (argv[i]) {
+ if ((strcmp(argv[i], "-d2") == 0)) {
+ Swig_mark_arg(i);
+ d_version = 2;
+ } else if (strcmp(argv[i], "-wrapperlibrary") == 0) {
+ if (argv[i + 1]) {
+ wrap_library_name = NewString("");
+ Printf(wrap_library_name, argv[i + 1]);
+ Swig_mark_arg(i);
+ Swig_mark_arg(i + 1);
+ i++;
+ } else {
+ Swig_arg_error();
+ }
+ } else if (strcmp(argv[i], "-package") == 0) {
+ if (argv[i + 1]) {
+ package = NewString("");
+ Printf(package, argv[i + 1]);
+ Swig_mark_arg(i);
+ Swig_mark_arg(i + 1);
+ i++;
+ } else {
+ Swig_arg_error();
+ }
+ } else if ((strcmp(argv[i], "-splitproxy") == 0)) {
+ Swig_mark_arg(i);
+ split_proxy_dmodule = true;
+ } else if (strcmp(argv[i], "-help") == 0) {
+ Printf(stdout, "%s\n", usage);
+ }
+ }
+ }
+
+ // Add a symbol to the parser for conditional compilation
+ Preprocessor_define("SWIGD 1", 0);
+
+ // Also make the target D version available as preprocessor symbol for
+ // use in our library files.
+ String *version_define = NewStringf("SWIG_D_VERSION %u", d_version);
+ Preprocessor_define(version_define, 0);
+ Delete(version_define);
+
+ // Add typemap definitions
+ SWIG_typemap_lang("d");
+ SWIG_config_file("d.swg");
+
+ allow_overloading();
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::top()
+ * --------------------------------------------------------------------------- */
+ virtual int top(Node *n) {
+ // Get any options set in the module directive
+ Node *optionsnode = Getattr(Getattr(n, "module"), "options");
+
+ if (optionsnode) {
+ if (Getattr(optionsnode, "wrapdmodulename")) {
+ wrap_dmodule_name = Copy(Getattr(optionsnode, "wrapdmodulename"));
+ }
+
+ if (Getattr(optionsnode, "directors")) {
+ // Check if directors are enabled for this module. Note: This is a
+ // "master switch", if it is not set, not director code will be emitted
+ // at all. %feature("director") statements are also required to enable
+ // directors for individual classes or methods.
+ //
+ // Use the »directors« attributte of the %module directive to enable
+ // director generation (e.g. »%module(directors="1") modulename«).
+ allow_directors();
+ }
+
+ if (Getattr(optionsnode, "dirprot")) {
+ allow_dirprot();
+ }
+
+ allow_allprotected(GetFlag(optionsnode, "allprotected"));
+ }
+
+ /* Initialize all of the output files */
+ String *outfile = Getattr(n, "outfile");
+ String *outfile_h = Getattr(n, "outfile_h");
+
+ if (!outfile) {
+ Printf(stderr, "Unable to determine outfile\n");
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ f_begin = NewFile(outfile, "w", SWIG_output_files());
+ if (!f_begin) {
+ FileErrorDisplay(outfile);
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ if (directorsEnabled()) {
+ if (!outfile_h) {
+ Printf(stderr, "Unable to determine outfile_h\n");
+ SWIG_exit(EXIT_FAILURE);
+ }
+ f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files());
+ if (!f_runtime_h) {
+ FileErrorDisplay(outfile_h);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ }
+
+ f_runtime = NewString("");
+ f_init = NewString("");
+ f_header = NewString("");
+ f_wrappers = NewString("");
+ f_directors_h = NewString("");
+ f_directors = NewString("");
+
+ /* Register file targets with the SWIG file handler */
+ Swig_register_filebyname("header", f_header);
+ Swig_register_filebyname("wrapper", f_wrappers);
+ Swig_register_filebyname("begin", f_begin);
+ Swig_register_filebyname("runtime", f_runtime);
+ Swig_register_filebyname("init", f_init);
+ Swig_register_filebyname("director", f_directors);
+ Swig_register_filebyname("director_h", f_directors_h);
+
+ unknown_types = NewHash();
+ filenames_list = NewList();
+
+ // Make the package name and the resulting module output path.
+ if (package) {
+ // Append a dot so we can prepend the package variable directly to the
+ // module names in the rest of the code.
+ Printv(package, ".", NIL);
+ } else {
+ // Write the generated D modules to the »root« package by default.
+ package = NewString("");
+ }
+
+ dmodule_directory = Copy(SWIG_output_directory());
+ if (Len(package) > 0) {
+ String *package_directory = Copy(package);
+ Replaceall(package_directory, ".", SWIG_FILE_DELIMITER);
+ Printv(dmodule_directory, package_directory, NIL);
+ Delete(package_directory);
+ }
+
+ // Make the wrap and proxy D module names.
+ // The wrap module name can be set in the module directive.
+ if (!wrap_dmodule_name) {
+ wrap_dmodule_name = NewStringf("%s_wrap", Getattr(n, "name"));
+ }
+ wrap_dmodule_fq_name = NewStringf("%s%s", package, wrap_dmodule_name);
+ proxy_dmodule_name = Copy(Getattr(n, "name"));
+ proxy_dmodule_fq_name = NewStringf("%s%s", package, proxy_dmodule_name);
+
+ wrap_dmodule_code = NewString("");
+ proxy_class_imports = NewString("");
+ proxy_class_enums_code = NewString("");
+ proxy_class_body_code = NewString("");
+ proxy_class_epilogue_code = NewString("");
+ proxy_class_code = NewString("");
+ destructor_call = NewString("");
+ proxy_dmodule_code = NewString("");
+ proxy_dmodule_imports = NewString("");
+ wrap_dmodule_imports = NewString("");
+ upcasts_code = NewString("");
+ global_proxy_imports = NewString("");
+ wrapper_loader_code = NewString("");
+ wrapper_loader_bind_command = NewString("");
+ wrapper_loader_bind_code = NewString("");
+ dmethods_seq = NewList();
+ dmethods_table = NewHash();
+ n_dmethods = 0;
+
+ // By default, expect the dynamically loaded wrapper library to be named
+ // like the wrapper D module (i.e. [lib]<module>_wrap[.so/.dll] unless the
+ // user overrides it).
+ if (!wrap_library_name)
+ wrap_library_name = Copy(wrap_dmodule_name);
+
+ Swig_banner(f_begin);
+
+ Printf(f_runtime, "\n");
+ Printf(f_runtime, "#define SWIGD\n");
+
+ if (directorsEnabled()) {
+ Printf(f_runtime, "#define SWIG_DIRECTORS\n");
+
+ /* Emit initial director header and director code: */
+ Swig_banner(f_directors_h);
+ Printf(f_directors_h, "\n");
+ Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", proxy_dmodule_name);
+ Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", proxy_dmodule_name);
+
+ Printf(f_directors, "\n\n");
+ Printf(f_directors, "/* ---------------------------------------------------\n");
+ Printf(f_directors, " * C++ director class methods\n");
+ Printf(f_directors, " * --------------------------------------------------- */\n\n");
+ if (outfile_h)
+ Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
+ }
+
+ Printf(f_runtime, "\n");
+
+ Swig_name_register("wrapper", "D_%f");
+
+ Printf(f_wrappers, "\n#ifdef __cplusplus\n");
+ Printf(f_wrappers, "extern \"C\" {\n");
+ Printf(f_wrappers, "#endif\n\n");
+
+ // Emit all the wrapper code.
+ Language::top(n);
+
+ if (directorsEnabled()) {
+ // Insert director runtime into the f_runtime file (before %header section).
+ Swig_insert_file("director.swg", f_runtime);
+ }
+
+ // Generate the wrap D module.
+ // TODO: Add support for »static« linking.
+ {
+ String *filen = NewStringf("%s%s.d", dmodule_directory, wrap_dmodule_name);
+ File *wrap_d_file = NewFile(filen, "w", SWIG_output_files());
+ if (!wrap_d_file) {
+ FileErrorDisplay(filen);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filen));
+ Delete(filen);
+ filen = NULL;
+
+ // Start writing out the intermediary class file.
+ emitBanner(wrap_d_file);
+
+ Printf(wrap_d_file, "module %s;\n", wrap_dmodule_fq_name);
+
+ Printv(wrap_d_file, wrap_dmodule_imports, "\n", NIL);
+
+ Replaceall(wrapper_loader_code, "$wraplibrary", wrap_library_name);
+ Replaceall(wrapper_loader_code, "$wrapperloaderbindcode", wrapper_loader_bind_code);
+ Replaceall(wrapper_loader_code, "$module", proxy_dmodule_name);
+ Printf(wrap_d_file, "%s\n", wrapper_loader_code);
+
+ // Add the wrapper function declarations.
+ replaceModuleVariables(wrap_dmodule_code);
+ Printv(wrap_d_file, wrap_dmodule_code, NIL);
+
+ Close(wrap_d_file);
+ }
+
+ // Generate the D proxy module for the wrapped module.
+ {
+ String *filen = NewStringf("%s%s.d", dmodule_directory, proxy_dmodule_name);
+ File *proxy_d_file = NewFile(filen, "w", SWIG_output_files());
+ if (!proxy_d_file) {
+ FileErrorDisplay(filen);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filen));
+ Delete(filen);
+ filen = NULL;
+
+ emitBanner(proxy_d_file);
+
+ Printf(proxy_d_file, "module %s;\n", proxy_dmodule_fq_name);
+ Printf(proxy_d_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+ Printv(proxy_d_file, global_proxy_imports, NIL);
+ Printv(proxy_d_file, proxy_dmodule_imports, NIL);
+ Printv(proxy_d_file, "\n", NIL);
+
+ // Write a D type wrapper class for each SWIG type to the proxy module code.
+ for (Iterator swig_type = First(unknown_types); swig_type.key; swig_type = Next(swig_type)) {
+ writeTypeWrapperClass(swig_type.key, swig_type.item);
+ }
+
+ // Add the proxy functions (and classes, if they are not written to a
+ // seperate file).
+ replaceModuleVariables(proxy_dmodule_code);
+ Printv(proxy_d_file, proxy_dmodule_code, NIL);
+
+ Close(proxy_d_file);
+ }
+
+ if (upcasts_code)
+ Printv(f_wrappers, upcasts_code, NIL);
+
+ Printf(f_wrappers, "#ifdef __cplusplus\n");
+ Printf(f_wrappers, "}\n");
+ Printf(f_wrappers, "#endif\n");
+
+ // Check for overwriting file problems on filesystems that are case insensitive
+ Iterator it1;
+ Iterator it2;
+ for (it1 = First(filenames_list); it1.item; it1 = Next(it1)) {
+ String *item1_lower = Swig_string_lower(it1.item);
+ for (it2 = Next(it1); it2.item; it2 = Next(it2)) {
+ String *item2_lower = Swig_string_lower(it2.item);
+ if (it1.item && it2.item) {
+ if (Strcmp(item1_lower, item2_lower) == 0) {
+ Swig_warning(WARN_LANG_PORTABILITY_FILENAME, input_file, line_number,
+ "Portability warning: File %s will be overwritten by %s on case insensitive filesystems such as "
+ "Windows' FAT32 and NTFS unless the class/module name is renamed\n", it1.item, it2.item);
+ }
+ }
+ Delete(item2_lower);
+ }
+ Delete(item1_lower);
+ }
+
+ Delete(unknown_types);
+ unknown_types = NULL;
+ Delete(filenames_list);
+ filenames_list = NULL;
+ Delete(wrap_dmodule_name);
+ wrap_dmodule_name = NULL;
+ Delete(wrap_dmodule_fq_name);
+ wrap_dmodule_fq_name = NULL;
+ Delete(wrap_dmodule_code);
+ wrap_dmodule_code = NULL;
+ Delete(proxy_class_imports);
+ proxy_class_imports = NULL;
+ Delete(proxy_class_enums_code);
+ proxy_class_enums_code = NULL;
+ Delete(proxy_class_body_code);
+ proxy_class_body_code = NULL;
+ Delete(proxy_class_epilogue_code);
+ proxy_class_epilogue_code = NULL;
+ Delete(proxy_class_code);
+ proxy_class_code = NULL;
+ Delete(destructor_call);
+ destructor_call = NULL;
+ Delete(proxy_dmodule_name);
+ proxy_dmodule_name = NULL;
+ Delete(proxy_dmodule_fq_name);
+ proxy_dmodule_fq_name = NULL;
+ Delete(proxy_dmodule_code);
+ proxy_dmodule_code = NULL;
+ Delete(proxy_dmodule_imports);
+ proxy_dmodule_imports = NULL;
+ Delete(wrap_dmodule_imports);
+ wrap_dmodule_imports = NULL;
+ Delete(upcasts_code);
+ upcasts_code = NULL;
+ Delete(global_proxy_imports);
+ global_proxy_imports = NULL;
+ Delete(wrapper_loader_code);
+ wrapper_loader_code = NULL;
+ Delete(wrapper_loader_bind_code);
+ wrapper_loader_bind_code = NULL;
+ Delete(wrapper_loader_bind_command);
+ wrapper_loader_bind_command = NULL;
+ Delete(dmethods_seq);
+ dmethods_seq = NULL;
+ Delete(dmethods_table);
+ dmethods_table = NULL;
+ Delete(package);
+ package = NULL;
+ Delete(dmodule_directory);
+ dmodule_directory = NULL;
+ n_dmethods = 0;
+
+ // Merge all the generated C/C++ code and close the output files.
+ Dump(f_runtime, f_begin);
+ Dump(f_header, f_begin);
+
+ if (directorsEnabled()) {
+ Dump(f_directors, f_begin);
+ Dump(f_directors_h, f_runtime_h);
+
+ Printf(f_runtime_h, "\n");
+ Printf(f_runtime_h, "#endif\n");
+
+ Close(f_runtime_h);
+ Delete(f_runtime_h);
+ f_runtime_h = NULL;
+ Delete(f_directors);
+ f_directors = NULL;
+ Delete(f_directors_h);
+ f_directors_h = NULL;
+ }
+
+ Dump(f_wrappers, f_begin);
+ Wrapper_pretty_print(f_init, f_begin);
+ Delete(f_header);
+ Delete(f_wrappers);
+ Delete(f_init);
+ Close(f_begin);
+ Delete(f_runtime);
+ Delete(f_begin);
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::insertDirective()
+ * --------------------------------------------------------------------------- */
+ virtual int insertDirective(Node *n) {
+ String *code = Getattr(n, "code");
+ replaceModuleVariables(code);
+ return Language::insertDirective(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::pragmaDirective()
+ *
+ * Valid Pragmas:
+ * wrapdmodulecode - text (D code) is copied verbatim to the wrap module
+ * wrapdmoduleimports - import statements for the wrap module
+ *
+ * proxydmodulecode - text (D code) is copied verbatim to the proxy module
+ * (the main proxy module if in split proxy mode).
+ * globalproxyimports - import statements inserted into _all_ proxy modules.
+ *
+ * wrapperloadercode - D code for loading the wrapper library (is copied to
+ * the wrap D module).
+ * wrapperloaderbindcommand - D code for binding a symbol from the wrapper
+ * library to the declaration in the wrap D module.
+ * --------------------------------------------------------------------------- */
+ virtual int pragmaDirective(Node *n) {
+ if (!ImportMode) {
+ String *lang = Getattr(n, "lang");
+ String *code = Getattr(n, "name");
+ String *value = Getattr(n, "value");
+
+ if (Strcmp(lang, "d") == 0) {
+ String *strvalue = NewString(value);
+ Replaceall(strvalue, "\\\"", "\"");
+
+ if (Strcmp(code, "wrapdmodulecode") == 0) {
+ Printf(wrap_dmodule_code, "%s\n", strvalue);
+ } else if (Strcmp(code, "wrapdmoduleimports") == 0) {
+ replaceImportTypeMacros(strvalue);
+ Chop(strvalue);
+ Printf(wrap_dmodule_imports, "%s\n", strvalue);
+ } else if (Strcmp(code, "proxydmodulecode") == 0) {
+ Printf(proxy_dmodule_code, "%s\n", strvalue);
+ } else if (Strcmp(code, "globalproxyimports") == 0) {
+ replaceImportTypeMacros(strvalue);
+ Chop(strvalue);
+ Printf(global_proxy_imports, "%s\n", strvalue);
+ } else if (Strcmp(code, "wrapperloadercode") == 0) {
+ Delete(wrapper_loader_code);
+ wrapper_loader_code = Copy(strvalue);
+ } else if (Strcmp(code, "wrapperloaderbindcommand") == 0) {
+ Delete(wrapper_loader_bind_command);
+ wrapper_loader_bind_command = Copy(strvalue);
+ } else {
+ Swig_error(input_file, line_number, "Unrecognized pragma.\n");
+ }
+ Delete(strvalue);
+ }
+ }
+ return Language::pragmaDirective(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::enumDeclaration()
+ *
+ * Wraps C/C++ enums as D enums.
+ * --------------------------------------------------------------------------- */
+ virtual int enumDeclaration(Node *n) {
+ if (ImportMode)
+ return SWIG_OK;
+
+ if (getCurrentClass() && (cplus_mode != PUBLIC))
+ return SWIG_NOWRAP;
+
+ proxy_enum_code = NewString("");
+ String *symname = Getattr(n, "sym:name");
+ String *typemap_lookup_type = Getattr(n, "name");
+
+ // Emit the enum declaration.
+ if (typemap_lookup_type) {
+ const String *enummodifiers = lookupCodeTypemap(n, "dclassmodifiers", typemap_lookup_type, WARN_D_TYPEMAP_CLASSMOD_UNDEF);
+ Printv(proxy_enum_code, "\n", enummodifiers, " ", symname, " {\n", NIL);
+ } else {
+ // Handle anonymous enums.
+ Printv(proxy_enum_code, "\nenum {\n", NIL);
+ }
+
+ // Emit each enum item.
+ Language::enumDeclaration(n);
+
+ if (!GetFlag(n, "nonempty")) {
+ // Do not wrap empty enums; the resulting D code would be illegal.
+ Delete(proxy_enum_code);
+ return SWIG_NOWRAP;
+ }
+
+ // Finish the enum.
+ if (typemap_lookup_type) {
+ Printv(proxy_enum_code,
+ lookupCodeTypemap(n, "dcode", typemap_lookup_type, WARN_NONE), // Extra D code
+ "\n}\n", NIL);
+ } else {
+ // Handle anonymous enums.
+ Printv(proxy_enum_code, "\n}\n", NIL);
+ }
+
+ Replaceall(proxy_enum_code, "$dclassname", symname);
+
+ const String* imports =
+ lookupCodeTypemap(n, "dimports", typemap_lookup_type, WARN_NONE);
+ String* imports_trimmed;
+ if (Len(imports) > 0) {
+ imports_trimmed = Copy(imports);
+ Chop(imports_trimmed);
+ replaceImportTypeMacros(imports_trimmed);
+ Printv(imports_trimmed, "\n", NIL);
+ } else {
+ imports_trimmed = NewString("");
+ }
+
+ if (is_wrapping_class()) {
+ // Enums defined within the C++ class are written into the proxy
+ // class.
+ Printv(proxy_class_imports, imports_trimmed, NIL);
+ Printv(proxy_class_enums_code, proxy_enum_code, NIL);
+ } else {
+ // Write non-anonymous enums to their own file if in split proxy module
+ // mode.
+ if (split_proxy_dmodule && typemap_lookup_type) {
+ assertClassNameValidity(proxy_class_name);
+
+ String *filename = NewStringf("%s%s.d", dmodule_directory, symname);
+ File *class_file = NewFile(filename, "w", SWIG_output_files());
+ if (!class_file) {
+ FileErrorDisplay(filename);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filename));
+ Delete(filename);
+
+ emitBanner(class_file);
+ Printf(class_file, "module %s%s;\n", package, symname);
+ Printv(class_file, imports_trimmed, NIL);
+
+ Printv(class_file, proxy_enum_code, NIL);
+
+ Close(class_file);
+ Delete(class_file);
+ } else {
+ Printv(proxy_dmodule_imports, imports, NIL);
+ Printv(proxy_dmodule_code, proxy_enum_code, NIL);
+ }
+ }
+
+ Delete(imports_trimmed);
+
+ Delete(proxy_enum_code);
+ proxy_enum_code = NULL;
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::enumvalueDeclaration()
+ * --------------------------------------------------------------------------- */
+ virtual int enumvalueDeclaration(Node *n) {
+ if (getCurrentClass() && (cplus_mode != PUBLIC))
+ return SWIG_NOWRAP;
+
+ Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL);
+ String *value = Getattr(n, "value");
+ String *name = Getattr(n, "name");
+ Node *parent = parentNode(n);
+ String *tmpValue;
+
+ // Strange hack from parent method.
+ // RESEARCH: What is this doing?
+ if (value)
+ tmpValue = NewString(value);
+ else
+ tmpValue = NewString(name);
+ // Note that this is used in enumValue() amongst other places
+ Setattr(n, "value", tmpValue);
+
+ String *proxy_name = Getattr(n, "sym:name");
+
+ // Emit the enum item.
+ {
+ if (!GetFlag(n, "firstenumitem"))
+ Printf(proxy_enum_code, ",\n");
+
+ Printf(proxy_enum_code, " %s", proxy_name);
+
+ // Check for the %dconstvalue feature
+ String *value = Getattr(n, "feature:d:constvalue");
+
+ // Note that in D, enum values must be compile-time constants. Thus,
+ // %dnativeconst(0) (getting the enum values at runtime) is not supported.
+ value = value ? value : Getattr(n, "enumvalue");
+ if (value) {
+ Printf(proxy_enum_code, " = %s", value);
+ }
+
+ // Keep track that the currently processed enum has at least one value.
+ SetFlag(parent, "nonempty");
+ }
+
+ Delete(tmpValue);
+ Swig_restore(n);
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::memberfunctionHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int memberfunctionHandler(Node *n) {
+ Language::memberfunctionHandler(n);
+
+ String *overloaded_name = getOverloadedName(n);
+ String *intermediary_function_name =
+ Swig_name_member(NSPACE_TODO,proxy_class_name, overloaded_name);
+ Setattr(n, "imfuncname", intermediary_function_name);
+
+ String *proxy_func_name = Getattr(n, "sym:name");
+ Setattr(n, "proxyfuncname", proxy_func_name);
+ if (split_proxy_dmodule &&
+ Len(Getattr(n, "parms")) == 0 &&
+ Strncmp(proxy_func_name, package, Len(proxy_func_name)) == 0) {
+ // If we are in split proxy mode and the function is named like the
+ // target package, the D compiler is unable to resolve the ambiguity
+ // between the package name and an argument-less function call.
+ Swig_warning(WARN_D_NAME_COLLISION, input_file, line_number,
+ "%s::%s might collide with the package name, consider using %%rename to resolve the ambiguity.\n",
+ proxy_class_name, proxy_func_name);
+ }
+
+ writeProxyClassFunction(n);
+
+ Delete(overloaded_name);
+
+ // For each function, look if we have to alias in the parent class function
+ // for the overload resolution process to work as expected from C++
+ // (http://www.digitalmars.com/d/2.0/function.html#function-inheritance).
+ // For multiple overloads, only emit the alias directive once (for the
+ // last method, »sym:nextSibling« is null then).
+ // Smart pointer classes do not mirror the inheritance hierarchy of the
+ // underlying types, so aliasing the base class methods in is not required
+ // for them.
+ // DMD BUG: We have to emit the alias after the last function becasue
+ // taking a delegate in the overload checking code fails otherwise
+ // (http://d.puremagic.com/issues/show_bug.cgi?id=4860).
+ if (!Getattr(n, "sym:nextSibling") && !is_smart_pointer() &&
+ !areAllOverloadsOverridden(n)) {
+ String *name = Getattr(n, "sym:name");
+ Printf(proxy_class_body_code, "\nalias $dbaseclass.%s %s;\n", name, name);
+ }
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::staticmemberfunctionHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int staticmemberfunctionHandler(Node *n) {
+ static_flag = true;
+
+ Language::staticmemberfunctionHandler(n);
+
+ String *overloaded_name = getOverloadedName(n);
+ String *intermediary_function_name =
+ Swig_name_member(NSPACE_TODO,proxy_class_name, overloaded_name);
+ Setattr(n, "proxyfuncname", Getattr(n, "sym:name"));
+ Setattr(n, "imfuncname", intermediary_function_name);
+ writeProxyClassFunction(n);
+ Delete(overloaded_name);
+
+ static_flag = false;
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::globalvariableHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int globalvariableHandler(Node *n) {
+ variable_name = Getattr(n, "sym:name");
+ global_variable_flag = true;
+ int ret = Language::globalvariableHandler(n);
+ global_variable_flag = false;
+
+ return ret;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::membervariableHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int membervariableHandler(Node *n) {
+ variable_name = Getattr(n, "sym:name");
+ wrapping_member_flag = true;
+ variable_wrapper_flag = true;
+ Language::membervariableHandler(n);
+ wrapping_member_flag = false;
+ variable_wrapper_flag = false;
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::staticmembervariableHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int staticmembervariableHandler(Node *n) {
+ if (GetFlag(n, "feature:d:nativeconst") != 1) {
+ Delattr(n, "value");
+ }
+
+ variable_name = Getattr(n, "sym:name");
+ wrapping_member_flag = true;
+ static_flag = true;
+ Language::staticmembervariableHandler(n);
+ wrapping_member_flag = false;
+ static_flag = false;
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::memberconstantHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int memberconstantHandler(Node *n) {
+ variable_name = Getattr(n, "sym:name");
+ wrapping_member_flag = true;
+ Language::memberconstantHandler(n);
+ wrapping_member_flag = false;
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::constructorHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int constructorHandler(Node *n) {
+ Language::constructorHandler(n);
+
+ // Wrappers not wanted for some methods where the parameters cannot be overloaded in D.
+ if (Getattr(n, "overload:ignore")) {
+ return SWIG_OK;
+ }
+
+ ParmList *l = Getattr(n, "parms");
+ String *tm;
+ String *proxy_constructor_code = NewString("");
+
+ // Holds code for the constructor helper method generated only when the din
+ // typemap has code in the pre or post attributes.
+ String *helper_code = NewString("");
+ String *helper_args = NewString("");
+ String *pre_code = NewString("");
+ String *post_code = NewString("");
+ String *terminator_code = NewString("");
+ NewString("");
+
+ String *overloaded_name = getOverloadedName(n);
+ String *mangled_overname = Swig_name_construct(NSPACE_TODO,overloaded_name);
+ String *imcall = NewString("");
+
+ const String *methodmods = Getattr(n, "feature:d:methodmodifiers");
+ methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
+
+ // Typemaps were attached earlier to the node, get the return type of the
+ // call to the C++ constructor wrapper.
+ const String *wrapper_return_type = lookupDTypemap(n, "dwtype", true);
+
+ String *dwtypeout = Getattr(n, "tmap:dwtype:out");
+ if (dwtypeout) {
+ // The type in the dwtype typemap's out attribute overrides the type in
+ // the typemap itself.
+ wrapper_return_type = dwtypeout;
+ }
+
+ Printf(proxy_constructor_code, "\n%s this(", methodmods);
+ Printf(helper_code, "static private %s SwigConstruct%s(",
+ wrapper_return_type, proxy_class_name);
+
+ Printv(imcall, wrap_dmodule_fq_name, ".", mangled_overname, "(", NIL);
+
+ /* Attach the non-standard typemaps to the parameter list */
+ Swig_typemap_attach_parms("in", l, NULL);
+ Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("din", l, NULL);
+
+ emit_mark_varargs(l);
+
+ int gencomma = 0;
+
+ /* Output each parameter */
+ Parm *p = l;
+ for (unsigned int i = 0; p; i++) {
+ if (checkAttribute(p, "varargs:ignore", "1")) {
+ // Skip ignored varargs.
+ p = nextSibling(p);
+ continue;
+ }
+
+ if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ // Skip ignored parameters.
+ p = Getattr(p, "tmap:in:next");
+ continue;
+ }
+
+ SwigType *pt = Getattr(p, "type");
+ String *param_type = NewString("");
+
+ // Get the D parameter type.
+ if ((tm = lookupDTypemap(p, "dptype", true))) {
+ const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ Printf(param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ if (gencomma)
+ Printf(imcall, ", ");
+
+ String *arg = makeParameterName(n, p, i, false);
+ String *parmtype = 0;
+
+ // Get the D code to convert the parameter value to the type used in the
+ // wrapper D module.
+ if ((tm = lookupDTypemap(p, "din"))) {
+ Replaceall(tm, "$dinput", arg);
+ String *pre = Getattr(p, "tmap:din:pre");
+ if (pre) {
+ replaceClassname(pre, pt);
+ Replaceall(pre, "$dinput", arg);
+ if (Len(pre_code) > 0)
+ Printf(pre_code, "\n");
+ Printv(pre_code, pre, NIL);
+ }
+ String *post = Getattr(p, "tmap:din:post");
+ if (post) {
+ replaceClassname(post, pt);
+ Replaceall(post, "$dinput", arg);
+ if (Len(post_code) > 0)
+ Printf(post_code, "\n");
+ Printv(post_code, post, NIL);
+ }
+ String *terminator = Getattr(p, "tmap:din:terminator");
+ if (terminator) {
+ replaceClassname(terminator, pt);
+ Replaceall(terminator, "$dinput", arg);
+ if (Len(terminator_code) > 0)
+ Insert(terminator_code, 0, "\n");
+ Insert(terminator_code, 0, terminator);
+ }
+ parmtype = Getattr(p, "tmap:din:parmtype");
+ if (parmtype)
+ Replaceall(parmtype, "$dinput", arg);
+ Printv(imcall, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DIN_UNDEF, input_file, line_number,
+ "No din typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ /* Add parameter to proxy function */
+ if (gencomma) {
+ Printf(proxy_constructor_code, ", ");
+ Printf(helper_code, ", ");
+ Printf(helper_args, ", ");
+ }
+ Printf(proxy_constructor_code, "%s %s", param_type, arg);
+ Printf(helper_code, "%s %s", param_type, arg);
+ Printf(helper_args, "%s", parmtype ? parmtype : arg);
+ ++gencomma;
+
+ Delete(parmtype);
+ Delete(arg);
+ Delete(param_type);
+ p = Getattr(p, "tmap:in:next");
+ }
+
+ Printf(imcall, ")");
+
+ Printf(proxy_constructor_code, ")");
+ Printf(helper_code, ")");
+
+ // Insert the dconstructor typemap (replacing $directorconnect as needed).
+ Hash *attributes = NewHash();
+ String *construct_tm = Copy(lookupCodeTypemap(n, "dconstructor",
+ Getattr(n, "name"), WARN_D_TYPEMAP_DCONSTRUCTOR_UNDEF, attributes));
+ if (construct_tm) {
+ const bool use_director = (parentNode(n) && Swig_directorclass(n));
+ if (!use_director) {
+ Replaceall(construct_tm, "$directorconnect", "");
+ } else {
+ String *connect_attr = Getattr(attributes, "tmap:dconstructor:directorconnect");
+
+ if (connect_attr) {
+ Replaceall(construct_tm, "$directorconnect", connect_attr);
+ } else {
+ Swig_warning(WARN_D_NO_DIRECTORCONNECT_ATTR, input_file, line_number,
+ "\"directorconnect\" attribute missing in %s \"dconstructor\" typemap.\n",
+ Getattr(n, "name"));
+ Replaceall(construct_tm, "$directorconnect", "");
+ }
+ }
+
+ Printv(proxy_constructor_code, " ", construct_tm, NIL);
+ }
+
+ replaceExcode(n, proxy_constructor_code, "dconstructor", attributes);
+
+ bool is_pre_code = Len(pre_code) > 0;
+ bool is_post_code = Len(post_code) > 0;
+ bool is_terminator_code = Len(terminator_code) > 0;
+ if (is_pre_code || is_post_code || is_terminator_code) {
+ Printf(helper_code, " {\n");
+ if (is_pre_code) {
+ Printv(helper_code, pre_code, "\n", NIL);
+ }
+ if (is_post_code) {
+ Printf(helper_code, " try {\n");
+ Printv(helper_code, " return ", imcall, ";\n", NIL);
+ Printv(helper_code, " } finally {\n", post_code, "\n }", NIL);
+ } else {
+ Printv(helper_code, " return ", imcall, ";", NIL);
+ }
+ if (is_terminator_code) {
+ Printv(helper_code, "\n", terminator_code, NIL);
+ }
+ Printf(helper_code, "\n}\n");
+ String *helper_name = NewStringf("%s.SwigConstruct%s(%s)",
+ proxy_class_name, proxy_class_name, helper_args);
+ Replaceall(proxy_constructor_code, "$wcall", helper_name);
+ Delete(helper_name);
+ } else {
+ Replaceall(proxy_constructor_code, "$wcall", imcall);
+ }
+
+ Printv(proxy_class_body_code, proxy_constructor_code, "\n", NIL);
+
+ Delete(helper_args);
+ Delete(pre_code);
+ Delete(post_code);
+ Delete(terminator_code);
+ Delete(construct_tm);
+ Delete(attributes);
+ Delete(overloaded_name);
+ Delete(imcall);
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::destructorHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int destructorHandler(Node *n) {
+ Language::destructorHandler(n);
+ String *symname = Getattr(n, "sym:name");
+ Printv(destructor_call, wrap_dmodule_fq_name, ".", Swig_name_destroy(NSPACE_TODO,symname), "(cast(void*)swigCPtr)", NIL);
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int classHandler(Node *n) {
+ File *class_file = NULL;
+
+ proxy_class_name = Copy(Getattr(n, "sym:name"));
+
+ if (!addSymbol(proxy_class_name, n)) {
+ return SWIG_ERROR;
+ }
+
+ assertClassNameValidity(proxy_class_name);
+
+ if (split_proxy_dmodule) {
+ String *filename = NewStringf("%s%s.d", dmodule_directory, proxy_class_name);
+ class_file = NewFile(filename, "w", SWIG_output_files());
+ if (!class_file) {
+ FileErrorDisplay(filename);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filename));
+ Delete(filename);
+
+ emitBanner(class_file);
+ Printf(class_file, "module %s%s;\n", package, proxy_class_name);
+ Printf(class_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+ }
+
+ Clear(proxy_class_imports);
+ Clear(proxy_class_enums_code);
+ Clear(proxy_class_body_code);
+ Clear(proxy_class_epilogue_code);
+ Clear(proxy_class_code);
+ Clear(destructor_call);
+
+
+ Language::classHandler(n);
+
+
+ writeProxyClassAndUpcasts(n);
+ writeDirectorConnectWrapper(n);
+
+ Replaceall(proxy_class_code, "$dclassname", proxy_class_name);
+
+ if (split_proxy_dmodule) {
+ Printv(class_file, global_proxy_imports, NIL);
+ Printv(class_file, proxy_class_imports, NIL);
+
+ replaceModuleVariables(proxy_class_code);
+ Printv(class_file, proxy_class_code, NIL);
+
+ Close(class_file);
+ Delete(class_file);
+ } else {
+ Printv(proxy_dmodule_imports, proxy_class_imports, NIL);
+ Printv(proxy_dmodule_code, proxy_class_code, NIL);
+ }
+
+ Delete(proxy_class_name);
+ proxy_class_name = NULL;
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::constantWrapper()
+ *
+ * Used for wrapping constants declared by #define or %constant and also for
+ * (primitive) static member constants initialised inline.
+ *
+ * If the %dnativeconst feature is used, the C/C++ constant value is used to
+ * initialize a D »const«. If not, a »getter« method is generated which
+ * retrieves the value via a call to the C wrapper. However, if there is a
+ * %dconstvalue specified, it overrides all other settings.
+ * --------------------------------------------------------------------------- */
+ virtual int constantWrapper(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ if (!addSymbol(symname, n))
+ return SWIG_ERROR;
+
+ // The %dnativeconst feature determines if a D const or a getter function is
+ // created.
+ if (GetFlag(n, "feature:d:nativeconst") != 1) {
+ // Default constant handling will work with any type of C constant. It
+ // generates a getter function (which is the same as a read only property
+ // in D) which retrieves the value via by calling the C wrapper.
+ // Note that this is only called for global constants, static member
+ // constants are already handeled in staticmemberfunctionHandler().
+
+ Swig_save("constantWrapper", n, "value", NIL);
+
+ // Add the stripped quotes back in.
+ String *old_value = Getattr(n, "value");
+ SwigType *t = Getattr(n, "type");
+ if (SwigType_type(t) == T_STRING) {
+ Setattr(n, "value", NewStringf("\"%s\"", old_value));
+ Delete(old_value);
+ } else if (SwigType_type(t) == T_CHAR) {
+ Setattr(n, "value", NewStringf("\'%s\'", old_value));
+ Delete(old_value);
+ }
+
+ int result = globalvariableHandler(n);
+
+ Swig_restore(n);
+ return result;
+ }
+
+ String *constants_code = NewString("");
+ SwigType *t = Getattr(n, "type");
+ ParmList *l = Getattr(n, "parms");
+
+ // Attach the non-standard typemaps to the parameter list.
+ Swig_typemap_attach_parms("dptype", l, NULL);
+
+ // Get D return type.
+ String *return_type = NewString("");
+ String *tm;
+ if ((tm = lookupDTypemap(n, "dptype"))) {
+ String *dptypeout = Getattr(n, "tmap:dptype:out");
+ if (dptypeout) {
+ // The type in the out attribute of the typemap overrides the type
+ // in the dptype typemap.
+ tm = dptypeout;
+ replaceClassname(tm, t);
+ }
+ Printf(return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ const String *itemname = wrapping_member_flag ? variable_name : symname;
+
+ String *attributes = Getattr(n, "feature:d:methodmodifiers");
+ if (attributes) {
+ attributes = Copy(attributes);
+ } else {
+ attributes = Copy(is_public(n) ? public_string : protected_string);
+ }
+
+ if (d_version == 1) {
+ if (static_flag) {
+ Printv(attributes, " static", NIL);
+ }
+ Printf(constants_code, "\n%s const %s %s = ", attributes, return_type, itemname);
+ } else {
+ Printf(constants_code, "\n%s enum %s %s = ", attributes, return_type, itemname);
+ }
+ Delete(attributes);
+
+ // Retrive the override value set via %dconstvalue, if any.
+ String *override_value = Getattr(n, "feature:d:constvalue");
+ if (override_value) {
+ Printf(constants_code, "%s;\n", override_value);
+ } else {
+ // Just take the value from the C definition and hope it compiles in D.
+ String* value = Getattr(n, "wrappedasconstant") ?
+ Getattr(n, "staticmembervariableHandler:value") : Getattr(n, "value");
+
+ // Add the stripped quotes back in.
+ if (SwigType_type(t) == T_STRING) {
+ Printf(constants_code, "\"%s\";\n", value);
+ } else if (SwigType_type(t) == T_CHAR) {
+ Printf(constants_code, "\'%s\';\n", value);
+ } else {
+ Printf(constants_code, "%s;\n", value);
+ }
+ }
+
+ // Emit the generated code to appropriate place.
+ if (wrapping_member_flag) {
+ Printv(proxy_class_body_code, constants_code, NIL);
+ } else {
+ Printv(proxy_dmodule_code, constants_code, NIL);
+ }
+
+ // Cleanup.
+ Delete(return_type);
+ Delete(constants_code);
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::functionWrapper()
+ *
+ * Generates the C wrapper code for a function and the corresponding
+ * declaration in the wrap D module.
+ * --------------------------------------------------------------------------- */
+ virtual int functionWrapper(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ SwigType *t = Getattr(n, "type");
+ ParmList *l = Getattr(n, "parms");
+ String *tm;
+ Parm *p;
+ int i;
+ String *c_return_type = NewString("");
+ String *im_return_type = NewString("");
+ String *cleanup = NewString("");
+ String *outarg = NewString("");
+ String *body = NewString("");
+ int num_arguments = 0;
+ int num_required = 0;
+ bool is_void_return;
+ String *overloaded_name = getOverloadedName(n);
+
+ if (!Getattr(n, "sym:overloaded")) {
+ if (!addSymbol(Getattr(n, "sym:name"), n))
+ return SWIG_ERROR;
+ }
+
+ // A new wrapper function object
+ Wrapper *f = NewWrapper();
+
+ // Make a wrapper name for this function
+ String *wname = Swig_name_wrapper(overloaded_name);
+
+ /* Attach the non-standard typemaps to the parameter list. */
+ Swig_typemap_attach_parms("cwtype", l, f);
+ Swig_typemap_attach_parms("dwtype", l, f);
+
+ /* Get return types */
+ if ((tm = lookupDTypemap(n, "cwtype"))) {
+ String *cwtypeout = Getattr(n, "tmap:cwtype:out");
+ if (cwtypeout) {
+ // The type in the cwtype typemap's out attribute overrides the type in
+ // the typemap itself.
+ tm = cwtypeout;
+ }
+ Printf(c_return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
+ "No cwtype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ if ((tm = lookupDTypemap(n, "dwtype"))) {
+ String *dwtypeout = Getattr(n, "tmap:dwtype:out");
+ if (dwtypeout) {
+ // The type in the dwtype typemap's out attribute overrides the type in
+ // the typemap itself.
+ tm = dwtypeout;
+ }
+ Printf(im_return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number, "No dwtype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ is_void_return = (Cmp(c_return_type, "void") == 0);
+ if (!is_void_return)
+ Wrapper_add_localv(f, "jresult", c_return_type, "jresult", NIL);
+
+ Printv(f->def, " SWIGEXPORT ", c_return_type, " SWIGSTDCALL ", wname, "(", NIL);
+
+ // Emit all of the local variables for holding arguments.
+ emit_parameter_variables(l, f);
+
+ /* Attach the standard typemaps */
+ emit_attach_parmmaps(l, f);
+
+ // Parameter overloading
+ Setattr(n, "wrap:parms", l);
+ Setattr(n, "wrap:name", wname);
+
+ // Wrappers not wanted for some methods where the parameters cannot be overloaded in D
+ if (Getattr(n, "sym:overloaded")) {
+ // Emit warnings for the few cases that can't be overloaded in D and give up on generating wrapper
+ Swig_overload_check(n);
+ if (Getattr(n, "overload:ignore"))
+ return SWIG_OK;
+ }
+
+ // Collect the parameter list for the wrap D module declaration of the
+ // generated wrapper function.
+ String *wrap_dmodule_parameters = NewString("(");
+
+ /* Get number of required and total arguments */
+ num_arguments = emit_num_arguments(l);
+ num_required = emit_num_required(l);
+ int gencomma = 0;
+
+ // Now walk the function parameter list and generate code to get arguments
+ for (i = 0, p = l; i < num_arguments; i++) {
+
+ while (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ }
+
+ SwigType *pt = Getattr(p, "type");
+ String *ln = Getattr(p, "lname");
+ String *im_param_type = NewString("");
+ String *c_param_type = NewString("");
+ String *arg = NewString("");
+
+ Printf(arg, "j%s", ln);
+
+ /* Get the cwtype types of the parameter */
+ if ((tm = lookupDTypemap(p, "cwtype", true))) {
+ Printv(c_param_type, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number, "No cwtype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ /* Get the intermediary class parameter types of the parameter */
+ if ((tm = lookupDTypemap(p, "dwtype", true))) {
+ const String *inattributes = Getattr(p, "tmap:dwtype:inattributes");
+ Printf(im_param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number, "No dwtype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ /* Add parameter to intermediary class method */
+ if (gencomma)
+ Printf(wrap_dmodule_parameters, ", ");
+ Printf(wrap_dmodule_parameters, "%s %s", im_param_type, arg);
+
+ // Add parameter to C function
+ Printv(f->def, gencomma ? ", " : "", c_param_type, " ", arg, NIL);
+
+ gencomma = 1;
+
+ // Get typemap for this argument
+ if ((tm = Getattr(p, "tmap:in"))) {
+ canThrow(n, "in", p);
+ Replaceall(tm, "$input", arg);
+ Setattr(p, "emit:input", arg);
+ Printf(f->code, "%s\n", tm);
+ p = Getattr(p, "tmap:in:next");
+ } else {
+ Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
+ p = nextSibling(p);
+ }
+ Delete(im_param_type);
+ Delete(c_param_type);
+ Delete(arg);
+ }
+
+ /* Insert constraint checking code */
+ for (p = l; p;) {
+ if ((tm = Getattr(p, "tmap:check"))) {
+ canThrow(n, "check", p);
+ Replaceall(tm, "$input", Getattr(p, "emit:input"));
+ Printv(f->code, tm, "\n", NIL);
+ p = Getattr(p, "tmap:check:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ /* Insert cleanup code */
+ for (p = l; p;) {
+ if ((tm = Getattr(p, "tmap:freearg"))) {
+ canThrow(n, "freearg", p);
+ Replaceall(tm, "$input", Getattr(p, "emit:input"));
+ Printv(cleanup, tm, "\n", NIL);
+ p = Getattr(p, "tmap:freearg:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ /* Insert argument output code */
+ for (p = l; p;) {
+ if ((tm = Getattr(p, "tmap:argout"))) {
+ canThrow(n, "argout", p);
+ Replaceall(tm, "$result", "jresult");
+ Replaceall(tm, "$input", Getattr(p, "emit:input"));
+ Printv(outarg, tm, "\n", NIL);
+ p = Getattr(p, "tmap:argout:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ // Look for usage of throws typemap and the canthrow flag
+ ParmList *throw_parm_list = NULL;
+ if ((throw_parm_list = Getattr(n, "catchlist"))) {
+ Swig_typemap_attach_parms("throws", throw_parm_list, f);
+ for (p = throw_parm_list; p; p = nextSibling(p)) {
+ if ((tm = Getattr(p, "tmap:throws"))) {
+ canThrow(n, "throws", p);
+ }
+ }
+ }
+
+ String *null_attribute = 0;
+ // Now write code to make the function call
+ if (!native_function_flag) {
+ if (Cmp(nodeType(n), "constant") == 0) {
+ // Wrapping a constant hack
+ Swig_save("functionWrapper", n, "wrap:action", NIL);
+
+ // below based on Swig_VargetToFunction()
+ SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n));
+ Setattr(n, "wrap:action", NewStringf("result = (%s) %s;", SwigType_lstr(ty, 0), Getattr(n, "value")));
+ }
+
+ Swig_director_emit_dynamic_cast(n, f);
+ String *actioncode = emit_action(n);
+
+ if (Cmp(nodeType(n), "constant") == 0)
+ Swig_restore(n);
+
+ /* Return value if necessary */
+ if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
+ canThrow(n, "out", n);
+ Replaceall(tm, "$result", "jresult");
+
+ if (GetFlag(n, "feature:new"))
+ Replaceall(tm, "$owner", "1");
+ else
+ Replaceall(tm, "$owner", "0");
+
+ Printf(f->code, "%s", tm);
+ null_attribute = Getattr(n, "tmap:out:null");
+ if (Len(tm))
+ Printf(f->code, "\n");
+ } else {
+ Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), Getattr(n, "name"));
+ }
+ emit_return_variable(n, t, f);
+ }
+
+ /* Output argument output code */
+ Printv(f->code, outarg, NIL);
+
+ /* Output cleanup code */
+ Printv(f->code, cleanup, NIL);
+
+ /* Look to see if there is any newfree cleanup code */
+ if (GetFlag(n, "feature:new")) {
+ if ((tm = Swig_typemap_lookup("newfree", n, "result", 0))) {
+ canThrow(n, "newfree", n);
+ Printf(f->code, "%s\n", tm);
+ }
+ }
+
+ /* See if there is any return cleanup code */
+ if (!native_function_flag) {
+ if ((tm = Swig_typemap_lookup("ret", n, "result", 0))) {
+ canThrow(n, "ret", n);
+ Printf(f->code, "%s\n", tm);
+ }
+ }
+
+ // Complete D wrapper parameter list and emit the declaration/binding code.
+ Printv(wrap_dmodule_parameters, ")", NIL);
+ writeWrapDModuleFunction(overloaded_name, im_return_type,
+ wrap_dmodule_parameters, wname);
+ Delete(wrap_dmodule_parameters);
+
+ // Finish C function header.
+ Printf(f->def, ") {");
+
+ if (!is_void_return)
+ Printv(f->code, " return jresult;\n", NIL);
+ Printf(f->code, "}\n");
+
+ /* Substitute the cleanup code */
+ Replaceall(f->code, "$cleanup", cleanup);
+
+ /* Substitute the function name */
+ Replaceall(f->code, "$symname", symname);
+
+ /* Contract macro modification */
+ if (Replaceall(f->code, "SWIG_contract_assert(", "SWIG_contract_assert($null, ") > 0) {
+ Setattr(n, "d:canthrow", "1");
+ }
+
+ if (!null_attribute)
+ Replaceall(f->code, "$null", "0");
+ else
+ Replaceall(f->code, "$null", null_attribute);
+
+ /* Dump the function out */
+ if (!native_function_flag) {
+ Wrapper_print(f, f_wrappers);
+
+ // Handle %exception which sets the canthrow attribute.
+ if (Getattr(n, "feature:except:canthrow")) {
+ Setattr(n, "d:canthrow", "1");
+ }
+
+ // A very simple check (it is not foolproof) to assist typemap writers
+ // with setting the correct features when the want to throw D exceptions
+ // from C++ code. It checks for the common methods which set
+ // a pending D exception and issues a warning if one of them has been found
+ // in the typemap, but the »canthrow« attribute/feature is not set.
+ if (!Getattr(n, "d:canthrow")) {
+ if (Strstr(f->code, "SWIG_exception")) {
+ Swig_warning(WARN_D_CANTHROW_MISSING, input_file, line_number,
+ "C code contains a call to SWIG_exception and D code does not handle pending exceptions via the canthrow attribute.\n");
+ } else if (Strstr(f->code, "SWIG_DSetPendingException")) {
+ Swig_warning(WARN_D_CANTHROW_MISSING, input_file, line_number,
+ "C code contains a call to a SWIG_DSetPendingException method and D code does not handle pending exceptions via the canthrow attribute.\n");
+ }
+ }
+ }
+
+ // If we are not processing an enum or constant, and we were not generating
+ // a wrapper function which will be accessed via a proxy class, write a
+ // function to the proxy D module.
+ if (!is_wrapping_class()) {
+ writeProxyDModuleFunction(n);
+ }
+
+ // If we are processing a public member variable, write the property-style
+ // member function to the proxy class.
+ if (wrapping_member_flag) {
+ Setattr(n, "proxyfuncname", variable_name);
+ Setattr(n, "imfuncname", symname);
+
+ writeProxyClassFunction(n);
+ }
+
+ Delete(c_return_type);
+ Delete(im_return_type);
+ Delete(cleanup);
+ Delete(outarg);
+ Delete(body);
+ Delete(overloaded_name);
+ DelWrapper(f);
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::nativeWrapper()
+ * --------------------------------------------------------------------------- */
+ virtual int nativeWrapper(Node *n) {
+ String *wrapname = Getattr(n, "wrap:name");
+
+ if (!addSymbol(wrapname, n))
+ return SWIG_ERROR;
+
+ if (Getattr(n, "type")) {
+ Swig_save("nativeWrapper", n, "name", NIL);
+ Setattr(n, "name", wrapname);
+ native_function_flag = true;
+ functionWrapper(n);
+ Swig_restore(n);
+ native_function_flag = false;
+ } else {
+ Swig_error(input_file, line_number, "No return type for %%native method %s.\n", Getattr(n, "wrap:name"));
+ }
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirector()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirector(Node *n) {
+ proxy_class_name = NewString(Getattr(n, "sym:name"));
+
+ int success = Language::classDirector(n);
+
+ Delete(proxy_class_name);
+ proxy_class_name = NULL;
+
+ return success;
+ }
+
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorInit()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorInit(Node *n) {
+ Delete(director_ctor_code);
+ director_ctor_code = NewString("$director_new");
+
+ // Write C++ director class declaration, for example:
+ // class SwigDirector_myclass : public myclass, public Swig::Director {
+ String *classname = Swig_class_name(n);
+ String *directorname = NewStringf("SwigDirector_%s", classname);
+ String *declaration = Swig_class_declaration(n, directorname);
+ const String *base = Getattr(n, "classtype");
+
+ Printf(f_directors_h,
+ "%s : public %s, public Swig::Director {\n", declaration, base);
+ Printf(f_directors_h, "\npublic:\n");
+
+ Delete(declaration);
+ Delete(directorname);
+ Delete(classname);
+
+ // Stash for later.
+ Setattr(n, "director:ctor", NewString("Swig::Director()"));
+
+ // Keep track of the director methods for this class.
+ first_class_dmethod = curr_class_dmethod = n_dmethods;
+
+ director_callback_typedefs = NewString("");
+ director_callback_pointers = NewString("");
+ director_dcallbacks_code = NewString("");
+
+ return Language::classDirectorInit(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorMethod()
+ *
+ * Emit a virtual director method to pass a method call on to the
+ * underlying D object.
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorMethod(Node *n, Node *parent, String *super) {
+ String *empty_str = NewString("");
+ String *classname = Getattr(parent, "sym:name");
+ String *c_classname = Getattr(parent, "name");
+ String *name = Getattr(n, "name");
+ String *symname = Getattr(n, "sym:name");
+ SwigType *type = Getattr(n, "type");
+ SwigType *returntype = Getattr(n, "returntype");
+ String *overloaded_name = getOverloadedName(n);
+ String *storage = Getattr(n, "storage");
+ String *value = Getattr(n, "value");
+ String *decl = Getattr(n, "decl");
+ String *declaration = NewString("");
+ String *tm;
+ Parm *p;
+ int i;
+ Wrapper *w = NewWrapper();
+ ParmList *l = Getattr(n, "parms");
+ bool is_void = !(Cmp(returntype, "void"));
+ String *qualified_return = NewString("");
+ bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0")));
+ int status = SWIG_OK;
+ bool output_director = true;
+ String *dirclassname = getDirectorClassName(parent);
+ String *qualified_name = NewStringf("%s::%s", dirclassname, name);
+ SwigType *c_ret_type = NULL;
+ String *dcallback_call_args = NewString("");
+ String *imclass_dmethod;
+ String *callback_typedef_parms = NewString("");
+ String *delegate_parms = NewString("");
+ String *proxy_method_param_list = NewString("");
+ String *proxy_callback_return_type = NewString("");
+ String *callback_def = NewString("");
+ String *callback_code = NewString("");
+ String *imcall_args = NewString("");
+ int gencomma = 0;
+ bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
+
+ // Kludge Alert: functionWrapper sets sym:overload properly, but it
+ // isn't at this point, so we have to manufacture it ourselves. At least
+ // we're consistent with the sym:overload name in functionWrapper. (?? when
+ // does the overloaded method name get set?)
+
+ imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(NSPACE_TODO,classname, overloaded_name));
+
+ if (returntype) {
+ qualified_return = SwigType_rcaststr(returntype, "c_result");
+
+ if (!is_void && !ignored_method) {
+ if (!SwigType_isclass(returntype)) {
+ if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
+ String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
+ Delete(construct_result);
+ } else {
+ String *base_typename = SwigType_base(returntype);
+ String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
+ Symtab *symtab = Getattr(n, "sym:symtab");
+ Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
+
+ if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) {
+ /* initialize pointers to something sane. Same for abstract
+ classes when a reference is returned. */
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
+ } else {
+ /* If returning a reference, initialize the pointer to a sane
+ default - if a D exception occurs, then the pointer returns
+ something other than a NULL-initialized reference. */
+ String *non_ref_type = Copy(returntype);
+
+ /* Remove reference and const qualifiers */
+ Replaceall(non_ref_type, "r.", "");
+ Replaceall(non_ref_type, "q(const).", "");
+ Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
+
+ Delete(non_ref_type);
+ }
+
+ Delete(base_typename);
+ Delete(resolved_typename);
+ }
+ } else {
+ SwigType *vt;
+
+ vt = cplus_value_type(returntype);
+ if (!vt) {
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
+ } else {
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
+ Delete(vt);
+ }
+ }
+ }
+
+ /* Create the intermediate class wrapper */
+ Parm *tp = NewParm(returntype, empty_str, n);
+
+ tm = lookupDTypemap(tp, "dwtype");
+ if (tm) {
+ String *dwtypeout = Getattr(tp, "tmap:dwtype:out");
+ if (dwtypeout) {
+ // The type in the dwtype typemap's out attribute overrides the type
+ // in the typemap.
+ tm = dwtypeout;
+ }
+ Printf(callback_def, "\nprivate extern(C) %s swigDirectorCallback_%s_%s(void* dObject", tm, classname, overloaded_name);
+ Printv(proxy_callback_return_type, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number,
+ "No dwtype typemap defined for %s\n", SwigType_str(returntype, 0));
+ }
+
+ Parm *retpm = NewParm(returntype, empty_str, n);
+
+ if ((c_ret_type = Swig_typemap_lookup("cwtype", retpm, "", 0))) {
+ if (!is_void && !ignored_method) {
+ String *jretval_decl = NewStringf("%s jresult", c_ret_type);
+ Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
+ Delete(jretval_decl);
+ }
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
+ "No cwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ }
+
+ Delete(retpm);
+ }
+
+ /* Go through argument list, attach lnames for arguments */
+ for (i = 0, p = l; p; p = nextSibling(p), ++i) {
+ String *arg = Getattr(p, "name");
+ String *lname = NewString("");
+
+ if (!arg && Cmp(Getattr(p, "type"), "void")) {
+ lname = NewStringf("arg%d", i);
+ Setattr(p, "name", lname);
+ } else
+ lname = arg;
+
+ Setattr(p, "lname", lname);
+ }
+
+ // Attach the standard typemaps.
+ Swig_typemap_attach_parms("out", l, 0);
+ Swig_typemap_attach_parms("cwtype", l, 0);
+ Swig_typemap_attach_parms("dwtype", l, 0);
+ Swig_typemap_attach_parms("dptype", l, 0);
+ Swig_typemap_attach_parms("directorin", l, 0);
+ Swig_typemap_attach_parms("ddirectorin", l, 0);
+
+ // Preamble code.
+ if (!ignored_method)
+ Printf(w->code, "if (!swig_callback_%s) {\n", overloaded_name);
+
+ if (!pure_virtual) {
+ String *super_call = Swig_method_call(super, l);
+ if (is_void) {
+ Printf(w->code, "%s;\n", super_call);
+ if (!ignored_method)
+ Printf(w->code, "return;\n");
+ } else {
+ Printf(w->code, "return %s;\n", super_call);
+ }
+ Delete(super_call);
+ } else {
+ Printf(w->code, " throw Swig::DirectorPureVirtualException(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
+ }
+
+ if (!ignored_method)
+ Printf(w->code, "} else {\n");
+
+ // Go through argument list.
+ for (p = l; p; /* empty */) {
+ /* Is this superfluous? */
+ while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
+ p = Getattr(p, "tmap:directorin:next");
+ }
+
+ SwigType *pt = Getattr(p, "type");
+ String *ln = Copy(Getattr(p, "name"));
+ String *c_param_type = NULL;
+ String *c_decl = NewString("");
+ String *arg = NewString("");
+
+ Printf(arg, "j%s", ln);
+
+ // Add each parameter to the D callback invocation arguments.
+ Printf(dcallback_call_args, ", %s", arg);
+
+ /* Get parameter's intermediary C type */
+ if ((c_param_type = lookupDTypemap(p, "cwtype", true))) {
+ String *cwtypeout = Getattr(p, "tmap:cwtype:out");
+ if (cwtypeout) {
+ // The type in the cwtype typemap's out attribute overrides the type
+ // in the typemap itself.
+ c_param_type = cwtypeout;
+ }
+
+ Parm *tp = NewParm(c_param_type, empty_str, n);
+ String *desc_tm = NULL;
+
+ /* Add to local variables */
+ Printf(c_decl, "%s %s", c_param_type, arg);
+ if (!ignored_method)
+ Wrapper_add_localv(w, arg, c_decl, (!(SwigType_ispointer(pt) || SwigType_isreference(pt)) ? "" : "= 0"), NIL);
+
+ /* Add input marshalling code */
+ if ((desc_tm = Swig_typemap_lookup("directorin", tp, "", 0))
+ && (tm = Getattr(p, "tmap:directorin"))) {
+
+ Replaceall(tm, "$input", arg);
+ Replaceall(tm, "$owner", "0");
+
+ if (Len(tm))
+ if (!ignored_method)
+ Printf(w->code, "%s\n", tm);
+
+ Delete(tm);
+
+ // Add parameter type to the C typedef for the D callback function.
+ Printf(callback_typedef_parms, ", %s", c_param_type);
+
+ /* Add parameter to the intermediate class code if generating the
+ * intermediate's upcall code */
+ if ((tm = lookupDTypemap(p, "dwtype", true))) {
+ String *dwtypeout = Getattr(p, "tmap:dwtype:out");
+ if (dwtypeout) {
+ // The type in the dwtype typemap's out attribute overrides the
+ // type in the typemap itself.
+ tm = dwtypeout;
+ }
+ const String *im_directorinattributes = Getattr(p, "tmap:dwtype:directorinattributes");
+
+ // TODO: Is this copy really needed?
+ String *din = Copy(lookupDTypemap(p, "ddirectorin", true));
+
+ if (din) {
+ Replaceall(din, "$winput", ln);
+
+ Printf(delegate_parms, ", ");
+ if (gencomma > 0) {
+ Printf(proxy_method_param_list, ", ");
+ Printf(imcall_args, ", ");
+ }
+ Printf(delegate_parms, "%s%s %s", im_directorinattributes ? im_directorinattributes : empty_string, tm, ln);
+
+ if (Cmp(din, ln)) {
+ Printv(imcall_args, din, NIL);
+ } else {
+ Printv(imcall_args, ln, NIL);
+ }
+
+ Delete(din);
+
+ // Get the parameter type in the proxy D class (used later when
+ // generating the overload checking code for the directorConnect
+ // function).
+ if ((tm = lookupDTypemap(p, "dptype", true))) {
+ Printf(proxy_method_param_list, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
+ "No ddirectorin typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ }
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number,
+ "No dwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ }
+
+ p = Getattr(p, "tmap:directorin:next");
+
+ Delete(desc_tm);
+ } else {
+ if (!desc_tm) {
+ Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
+ "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(c_param_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ p = nextSibling(p);
+ } else if (!tm) {
+ Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
+ "No or improper directorin typemap defined for argument %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ p = nextSibling(p);
+ }
+
+ output_director = false;
+ }
+
+ Delete(tp);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
+ "No cwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ p = nextSibling(p);
+ }
+
+ gencomma++;
+ Delete(arg);
+ Delete(c_decl);
+ Delete(c_param_type);
+ }
+
+ /* header declaration, start wrapper definition */
+ String *target;
+ SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
+ target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
+ Printf(w->def, "%s", target);
+ Delete(qualified_name);
+ Delete(target);
+ target = Swig_method_decl(rtype, decl, name, l, 0, 1);
+ Printf(declaration, " virtual %s", target);
+ Delete(target);
+
+ // Add any exception specifications to the methods in the director class
+ ParmList *throw_parm_list = NULL;
+ if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
+ int gencomma = 0;
+
+ Append(w->def, " throw(");
+ Append(declaration, " throw(");
+
+ if (throw_parm_list)
+ Swig_typemap_attach_parms("throws", throw_parm_list, 0);
+ for (p = throw_parm_list; p; p = nextSibling(p)) {
+ if ((tm = Getattr(p, "tmap:throws"))) {
+ if (gencomma++) {
+ Append(w->def, ", ");
+ Append(declaration, ", ");
+ }
+ Printf(w->def, "%s", SwigType_str(Getattr(p, "type"), 0));
+ Printf(declaration, "%s", SwigType_str(Getattr(p, "type"), 0));
+ }
+ }
+
+ Append(w->def, ")");
+ Append(declaration, ")");
+ }
+
+ Append(w->def, " {");
+ Append(declaration, ";\n");
+
+ // Finish the callback function declaraction.
+ Printf(callback_def, "%s)", delegate_parms);
+ Printf(callback_def, " {\n");
+
+ /* Emit the intermediate class's upcall to the actual class */
+
+ String *upcall = NewStringf("(cast(%s)dObject).%s(%s)", classname, symname, imcall_args);
+
+ if (!is_void) {
+ Parm *tp = NewParm(returntype, empty_str, n);
+
+ // RESEARCH: What happens if there is no ddirectorout typemap?
+ if ((tm = lookupDTypemap(tp, "ddirectorout"))) {
+ Replaceall(tm, "$dpcall", upcall);
+
+ Printf(callback_code, " return %s;\n", tm);
+ }
+
+ Delete(tm);
+ Delete(tp);
+ } else {
+ Printf(callback_code, " %s;\n", upcall);
+ }
+
+ Printf(callback_code, "}\n");
+ Delete(upcall);
+
+ if (!ignored_method) {
+ if (!is_void)
+ Printf(w->code, "jresult = (%s) ", c_ret_type);
+
+ Printf(w->code, "swig_callback_%s(d_object%s);\n", overloaded_name, dcallback_call_args);
+
+ if (!is_void) {
+ String *jresult_str = NewString("jresult");
+ String *result_str = NewString("c_result");
+ Parm *tp = NewParm(returntype, result_str, n);
+
+ /* Copy jresult into c_result... */
+ // FIXME: lookupDTypemap?
+ if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) {
+ Replaceall(tm, "$input", jresult_str);
+ Replaceall(tm, "$result", result_str);
+ Printf(w->code, "%s\n", tm);
+ } else {
+ Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
+ "Unable to use return type %s used in %s::%s (skipping director method)\n",
+ SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ }
+
+ Delete(tp);
+ Delete(jresult_str);
+ Delete(result_str);
+ }
+
+ /* Terminate wrapper code */
+ Printf(w->code, "}\n");
+ if (!is_void)
+ Printf(w->code, "return %s;", qualified_return);
+ }
+
+ Printf(w->code, "}");
+
+ // We expose virtual protected methods via an extra public inline method which makes a straight call to the wrapped class' method
+ String *inline_extra_method = NewString("");
+ if (dirprot_mode() && !is_public(n) && !pure_virtual) {
+ Printv(inline_extra_method, declaration, NIL);
+ String *extra_method_name = NewStringf("%sSwigPublic", name);
+ Replaceall(inline_extra_method, name, extra_method_name);
+ Replaceall(inline_extra_method, ";\n", " {\n ");
+ if (!is_void)
+ Printf(inline_extra_method, "return ");
+ String *methodcall = Swig_method_call(super, l);
+ Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
+ Delete(methodcall);
+ Delete(extra_method_name);
+ }
+
+ /* emit code */
+ if (status == SWIG_OK && output_director) {
+ if (!is_void) {
+ Replaceall(w->code, "$null", qualified_return);
+ } else {
+ Replaceall(w->code, "$null", "");
+ }
+ if (!ignored_method)
+ Printv(director_dcallbacks_code, callback_def, callback_code, NIL);
+ if (!Getattr(n, "defaultargs")) {
+ Wrapper_print(w, f_directors);
+ Printv(f_directors_h, declaration, NIL);
+ Printv(f_directors_h, inline_extra_method, NIL);
+ }
+ }
+
+ if (!ignored_method) {
+ // Register the upcall method so that the callback registering code can
+ // be written later.
+
+ // We cannot directly use n here because its »type« attribute does not
+ // the full return type any longer after Language::functionHandler has
+ // returned.
+ Parm *tp = NewParm(returntype, empty_str, n);
+ String *dp_return_type = lookupDTypemap(tp, "dptype");
+ if (dp_return_type) {
+ String *dptypeout = Getattr(n, "tmap:dptype:out");
+ if (dptypeout) {
+ // The type in the dptype typemap's out attribute overrides the type
+ // in the typemap itself.
+ dp_return_type = dptypeout;
+ replaceClassname(dp_return_type, returntype);
+ }
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(type, 0));
+ dp_return_type = NewString("");
+ }
+
+ UpcallData *udata = addUpcallMethod(imclass_dmethod, symname, decl, overloaded_name, dp_return_type, proxy_method_param_list);
+ Delete(dp_return_type);
+
+ // Write the global callback function pointer on the C code.
+ String *methid = Getattr(udata, "class_methodidx");
+
+ Printf(director_callback_typedefs, " typedef %s (SWIGSTDCALL* SWIG_Callback%s_t)", c_ret_type, methid);
+ Printf(director_callback_typedefs, "(void *dobj%s);\n", callback_typedef_parms);
+ Printf(director_callback_pointers, " SWIG_Callback%s_t swig_callback_%s;\n", methid, overloaded_name);
+
+ // Write the type alias for the callback to the wrap D module.
+ String* proxy_callback_type = NewString("");
+ Printf(proxy_callback_type, "SwigDirector_%s_Callback%s", classname, methid);
+ Printf(wrap_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type);
+ Delete(proxy_callback_type);
+ }
+
+ Delete(qualified_return);
+ Delete(c_ret_type);
+ Delete(declaration);
+ Delete(callback_typedef_parms);
+ Delete(delegate_parms);
+ Delete(proxy_method_param_list);
+ Delete(callback_def);
+ Delete(callback_code);
+ DelWrapper(w);
+
+ return status;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorConstructor()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorConstructor(Node *n) {
+ Node *parent = parentNode(n);
+ String *decl = Getattr(n, "decl");;
+ String *supername = Swig_class_name(parent);
+ String *classname = getDirectorClassName(parent);
+ String *sub = NewString("");
+ Parm *p;
+ ParmList *superparms = Getattr(n, "parms");
+ ParmList *parms;
+ int argidx = 0;
+
+ /* Assign arguments to superclass's parameters, if not already done */
+ for (p = superparms; p; p = nextSibling(p)) {
+ String *pname = Getattr(p, "name");
+
+ if (!pname) {
+ pname = NewStringf("arg%d", argidx++);
+ Setattr(p, "name", pname);
+ }
+ }
+
+ // TODO: Is this copy needed?
+ parms = CopyParmList(superparms);
+
+ if (!Getattr(n, "defaultargs")) {
+ /* constructor */
+ {
+ String *basetype = Getattr(parent, "classtype");
+ String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
+ String *call = Swig_csuperclass_call(0, basetype, superparms);
+ String *classtype = SwigType_namestr(Getattr(n, "name"));
+
+ Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor"));
+ Printf(f_directors, " swig_init_callbacks();\n");
+ Printf(f_directors, "}\n\n");
+
+ Delete(classtype);
+ Delete(target);
+ Delete(call);
+ }
+
+ /* constructor header */
+ {
+ String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
+ Printf(f_directors_h, " %s;\n", target);
+ Delete(target);
+ }
+ }
+
+ Delete(sub);
+ Delete(supername);
+ Delete(parms);
+ return Language::classDirectorConstructor(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorDefaultConstructor()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorDefaultConstructor(Node *n) {
+ String *classname = Swig_class_name(n);
+ String *classtype = SwigType_namestr(Getattr(n, "name"));
+ Wrapper *w = NewWrapper();
+
+ Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor"));
+ Printf(w->code, "}\n");
+ Wrapper_print(w, f_directors);
+
+ Printf(f_directors_h, " SwigDirector_%s();\n", classname);
+ DelWrapper(w);
+ Delete(classtype);
+ Delete(classname);
+ return Language::classDirectorDefaultConstructor(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorDestructor()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorDestructor(Node *n) {
+ Node *current_class = getCurrentClass();
+ String *classname = Swig_class_name(current_class);
+ Wrapper *w = NewWrapper();
+
+ if (Getattr(n, "throw")) {
+ Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname);
+ Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname);
+ } else {
+ Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname);
+ Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname);
+ }
+
+ Printv(w->code, "}\n", NIL);
+
+ Wrapper_print(w, f_directors);
+
+ DelWrapper(w);
+ Delete(classname);
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorEnd()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorEnd(Node *n) {
+ int i;
+ String *director_classname = getDirectorClassName(n);
+
+ Wrapper *w = NewWrapper();
+
+ if (Len(director_callback_typedefs) > 0) {
+ Printf(f_directors_h, "\n%s", director_callback_typedefs);
+ }
+
+ Printf(f_directors_h, " void swig_connect_director(void* dobj");
+
+ Printf(w->def, "void %s::swig_connect_director(void* dobj", director_classname);
+ Printf(w->code, "d_object = dobj;");
+
+ for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *methid = Getattr(udata, "class_methodidx");
+ String *overname = Getattr(udata, "overname");
+
+ Printf(f_directors_h, ", SWIG_Callback%s_t callback%s", methid, overname);
+ Printf(w->def, ", SWIG_Callback%s_t callback_%s", methid, overname);
+ Printf(w->code, "swig_callback_%s = callback_%s;\n", overname, overname);
+ }
+
+ Printf(f_directors_h, ");\n");
+ Printf(w->def, ") {");
+
+ Printf(f_directors_h, "\nprivate:\n");
+ Printf(f_directors_h, " void swig_init_callbacks();\n");
+ Printf(f_directors_h, " void *d_object;\n");
+ if (Len(director_callback_typedefs) > 0) {
+ Printf(f_directors_h, "%s", director_callback_pointers);
+ }
+ Printf(f_directors_h, "};\n\n");
+ Printf(w->code, "}\n\n");
+
+ Printf(w->code, "void %s::swig_init_callbacks() {\n", director_classname);
+ for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *overname = Getattr(udata, "overname");
+ Printf(w->code, "swig_callback_%s = 0;\n", overname);
+ }
+ Printf(w->code, "}");
+
+ Wrapper_print(w, f_directors);
+
+ DelWrapper(w);
+
+ return Language::classDirectorEnd(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorDisown()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorDisown(Node *n) {
+ (void) n;
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceSpecialVariables()
+ * --------------------------------------------------------------------------- */
+ virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm) {
+ (void)method;
+ SwigType *type = Getattr(parm, "type");
+
+ // Just assume that this goes to the proxy class, we cannot know.
+ replaceClassname(tm, type);
+ }
+
+protected:
+ /* ---------------------------------------------------------------------------
+ * D::extraDirectorProtectedCPPMethodsRequired()
+ * --------------------------------------------------------------------------- */
+ virtual bool extraDirectorProtectedCPPMethodsRequired() const {
+ return false;
+ }
+
+private:
+ /* ---------------------------------------------------------------------------
+ * D::writeWrapDModuleFunction()
+ *
+ * Writes a function declaration for the given (C) wrapper function to the
+ * wrap D module.
+ *
+ * d_name - The name the function in the D wrap module will get.
+ * wrapper_function_name - The name of the exported function in the C wrapper
+ * (usually d_name prefixed by »D_«).
+ * --------------------------------------------------------------------------- */
+ void writeWrapDModuleFunction(const_String_or_char_ptr d_name,
+ const_String_or_char_ptr return_type, const_String_or_char_ptr parameters,
+ const_String_or_char_ptr wrapper_function_name) {
+
+ // TODO: Add support for static linking here.
+ Printf(wrap_dmodule_code, "extern(C) %s function%s %s;\n", return_type,
+ parameters, d_name);
+ Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL);
+ Replaceall(wrapper_loader_bind_code, "$function", d_name);
+ Replaceall(wrapper_loader_bind_code, "$symbol", wrapper_function_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeProxyClassFunction()
+ *
+ * Creates a D proxy function for a C++ function in the wrapped class. Used
+ * for both static and non-static C++ class functions.
+ *
+ * The Node must contain two extra attributes.
+ * - "proxyfuncname": The name of the D proxy function.
+ * - "imfuncname": The corresponding function in the wrap D module.
+ * --------------------------------------------------------------------------- */
+ void writeProxyClassFunction(Node *n) {
+ SwigType *t = Getattr(n, "type");
+ ParmList *l = Getattr(n, "parms");
+ String *intermediary_function_name = Getattr(n, "imfuncname");
+ String *proxy_function_name = Getattr(n, "proxyfuncname");
+ String *tm;
+ Parm *p;
+ int i;
+ String *imcall = NewString("");
+ String *return_type = NewString("");
+ String *function_code = NewString("");
+ bool setter_flag = false;
+ String *pre_code = NewString("");
+ String *post_code = NewString("");
+ String *terminator_code = NewString("");
+
+ // Wrappers not wanted for some methods where the parameters cannot be
+ // overloaded in D.
+ if (Getattr(n, "overload:ignore"))
+ return;
+
+ // Don't generate proxy method for additional explicitcall method used in
+ // directors.
+ if (GetFlag(n, "explicitcall"))
+ return;
+
+ // RESEARCH: What is this good for?
+ if (l) {
+ if (SwigType_type(Getattr(l, "type")) == T_VOID) {
+ l = nextSibling(l);
+ }
+ }
+
+ /* Attach the non-standard typemaps to the parameter list */
+ Swig_typemap_attach_parms("in", l, NULL);
+ Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("din", l, NULL);
+
+ // Get return types.
+ if ((tm = lookupDTypemap(n, "dptype"))) {
+ String *dptypeout = Getattr(n, "tmap:dptype:out");
+ if (dptypeout) {
+ // The type in the dptype typemap's out attribute overrides the type in
+ // the typemap.
+ tm = dptypeout;
+ replaceClassname(tm, t);
+ }
+ Printf(return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ if (wrapping_member_flag) {
+ // Check if this is a setter method for a public member.
+ setter_flag = (Cmp(Getattr(n, "sym:name"),
+ Swig_name_set(NSPACE_TODO,Swig_name_member(NSPACE_TODO,proxy_class_name, variable_name))) == 0);
+ }
+
+ // Write function modifiers.
+ {
+ String *modifiers;
+
+ const String *mods_override = Getattr(n, "feature:d:methodmodifiers");
+ if (mods_override) {
+ modifiers = Copy(mods_override);
+ } else {
+ modifiers = Copy(is_public(n) ? public_string : protected_string);
+
+ if (Getattr(n, "override")) {
+ Printf(modifiers, " override");
+ }
+ }
+
+ if (is_smart_pointer()) {
+ // Smart pointer classes do not mirror the inheritance hierarchy of the
+ // underlying pointer type, so no override required.
+ Replaceall(modifiers, "override", "");
+ }
+
+ Chop(modifiers);
+
+ if (static_flag) {
+ Printf(modifiers, " static");
+ }
+
+ Printf(function_code, "%s ", modifiers);
+ Delete(modifiers);
+ }
+
+ // Complete the function declaration up to the parameter list.
+ Printf(function_code, "%s %s(", return_type, proxy_function_name);
+
+ // Write the wrapper function call up to the parameter list.
+ Printv(imcall, wrap_dmodule_fq_name, ".$imfuncname(", NIL);
+ if (!static_flag) {
+ Printf(imcall, "cast(void*)swigCPtr");
+ }
+
+ // Write the parameter list for the proxy function declaration and the
+ // wrapper function call.
+ emit_mark_varargs(l);
+ int gencomma = !static_flag;
+ for (i = 0, p = l; p; i++) {
+ // Ignored varargs.
+ if (checkAttribute(p, "varargs:ignore", "1")) {
+ p = nextSibling(p);
+ continue;
+ }
+
+ // Ignored parameters.
+ if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ continue;
+ }
+
+ // Ignore the 'this' argument for variable wrappers.
+ if (!(variable_wrapper_flag && i == 0)) {
+ String *param_name = makeParameterName(n, p, i, setter_flag);
+ SwigType *pt = Getattr(p, "type");
+
+ // Write the wrapper function call argument.
+ {
+ if (gencomma) {
+ Printf(imcall, ", ");
+ }
+
+ if ((tm = lookupDTypemap(p, "din", true))) {
+ Replaceall(tm, "$dinput", param_name);
+ String *pre = Getattr(p, "tmap:din:pre");
+ if (pre) {
+ replaceClassname(pre, pt);
+ Replaceall(pre, "$dinput", param_name);
+ if (Len(pre_code) > 0)
+ Printf(pre_code, "\n");
+ Printv(pre_code, pre, NIL);
+ }
+ String *post = Getattr(p, "tmap:din:post");
+ if (post) {
+ replaceClassname(post, pt);
+ Replaceall(post, "$dinput", param_name);
+ if (Len(post_code) > 0)
+ Printf(post_code, "\n");
+ Printv(post_code, post, NIL);
+ }
+ String *terminator = Getattr(p, "tmap:din:terminator");
+ if (terminator) {
+ replaceClassname(terminator, pt);
+ Replaceall(terminator, "$dinput", param_name);
+ if (Len(terminator_code) > 0)
+ Insert(terminator_code, 0, "\n");
+ Insert(terminator_code, 0, terminator);
+ }
+ Printv(imcall, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DIN_UNDEF, input_file, line_number,
+ "No din typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+ }
+
+ // Write the D proxy function parameter.
+ {
+ String *proxy_type = NewString("");
+
+ if ((tm = lookupDTypemap(p, "dptype"))) {
+ const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ Printf(proxy_type, "%s%s", inattributes ? inattributes : empty_string, tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ if (gencomma >= 2)
+ Printf(function_code, ", ");
+ gencomma = 2;
+ Printf(function_code, "%s %s", proxy_type, param_name);
+
+ Delete(proxy_type);
+ }
+
+ Delete(param_name);
+ }
+ p = Getattr(p, "tmap:in:next");
+ }
+
+ Printf(imcall, ")");
+ Printf(function_code, ") ");
+
+ if (d_version > 1 && wrapping_member_flag) {
+ Printf(function_code, "@property ");
+ }
+
+ if (wrapMemberFunctionAsDConst(n)) {
+ Printf(function_code, "const ");
+ }
+
+ // Lookup the code used to convert the wrapper return value to the proxy
+ // function return type.
+ if ((tm = lookupDTypemap(n, "dout"))) {
+ replaceExcode(n, tm, "dout", n);
+ bool is_pre_code = Len(pre_code) > 0;
+ bool is_post_code = Len(post_code) > 0;
+ bool is_terminator_code = Len(terminator_code) > 0;
+ if (is_pre_code || is_post_code || is_terminator_code) {
+ if (is_post_code) {
+ Insert(tm, 0, "\n try ");
+ Printv(tm, " finally {\n", post_code, "\n }", NIL);
+ } else {
+ Insert(tm, 0, "\n ");
+ }
+ if (is_pre_code) {
+ Insert(tm, 0, pre_code);
+ Insert(tm, 0, "\n");
+ }
+ if (is_terminator_code) {
+ Printv(tm, "\n", terminator_code, NIL);
+ }
+ Insert(tm, 0, "{");
+ Printv(tm, "}", NIL);
+ }
+ if (GetFlag(n, "feature:new"))
+ Replaceall(tm, "$owner", "true");
+ else
+ Replaceall(tm, "$owner", "false");
+ replaceClassname(tm, t);
+
+ // For director methods: generate code to selectively make a normal
+ // polymorphic call or an explicit method call. Needed to prevent infinite
+ // recursion when calling director methods.
+ Node *explicit_n = Getattr(n, "explicitcallnode");
+ if (explicit_n) {
+ String *ex_overloaded_name = getOverloadedName(explicit_n);
+ String *ex_intermediary_function_name = Swig_name_member(NSPACE_TODO,proxy_class_name, ex_overloaded_name);
+
+ String *ex_imcall = Copy(imcall);
+ Replaceall(ex_imcall, "$imfuncname", ex_intermediary_function_name);
+ Replaceall(imcall, "$imfuncname", intermediary_function_name);
+
+ String *excode = NewString("");
+ if (!Cmp(return_type, "void"))
+ Printf(excode, "if (this.classinfo == %s.classinfo) %s; else %s", proxy_class_name, imcall, ex_imcall);
+ else
+ Printf(excode, "((this.classinfo == %s.classinfo) ? %s : %s)", proxy_class_name, imcall, ex_imcall);
+
+ Clear(imcall);
+ Printv(imcall, excode, NIL);
+ Delete(ex_overloaded_name);
+ Delete(excode);
+ } else {
+ Replaceall(imcall, "$imfuncname", intermediary_function_name);
+ }
+ Replaceall(tm, "$wcall", imcall);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
+ "No dout typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ // The whole function body is now in stored tm (if there was a matching type
+ // map, of course), so simply append it to the code buffer. The braces are
+ // included in the typemap.
+ Printv(function_code, tm, NIL);
+
+ // Write function code buffer to the class code.
+ Printv(proxy_class_body_code, "\n", function_code, "\n", NIL);
+
+ Delete(pre_code);
+ Delete(post_code);
+ Delete(terminator_code);
+ Delete(function_code);
+ Delete(return_type);
+ Delete(imcall);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeProxyDModuleFunction()
+ * --------------------------------------------------------------------------- */
+ void writeProxyDModuleFunction(Node *n) {
+ SwigType *t = Getattr(n, "type");
+ ParmList *l = Getattr(n, "parms");
+ String *tm;
+ Parm *p;
+ int i;
+ String *imcall = NewString("");
+ String *return_type = NewString("");
+ String *function_code = NewString("");
+ int num_arguments = 0;
+ int num_required = 0;
+ String *overloaded_name = getOverloadedName(n);
+ String *func_name = NULL;
+ String *pre_code = NewString("");
+ String *post_code = NewString("");
+ String *terminator_code = NewString("");
+
+ // RESEARCH: What is this good for?
+ if (l) {
+ if (SwigType_type(Getattr(l, "type")) == T_VOID) {
+ l = nextSibling(l);
+ }
+ }
+
+ /* Attach the non-standard typemaps to the parameter list */
+ Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("din", l, NULL);
+
+ /* Get return types */
+ if ((tm = lookupDTypemap(n, "dptype"))) {
+ String *dptypeout = Getattr(n, "tmap:dptype:out");
+ if (dptypeout) {
+ // The type in the dptype typemap's out attribute overrides the type in
+ // the typemap.
+ tm = dptypeout;
+ replaceClassname(tm, t);
+ }
+ Printf(return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ /* Change function name for global variables */
+ if (global_variable_flag) {
+ // RESEARCH: Is the Copy() needed here?
+ func_name = Copy(variable_name);
+ } else {
+ func_name = Copy(Getattr(n, "sym:name"));
+ }
+
+ /* Start generating the function */
+ const String *outattributes = Getattr(n, "tmap:dptype:outattributes");
+ if (outattributes)
+ Printf(function_code, " %s\n", outattributes);
+
+ const String *methodmods = Getattr(n, "feature:d:methodmodifiers");
+ // TODO: Check if is_public(n) could possibly make any sense here
+ // (private global functions would be useless anyway?).
+ methodmods = methodmods ? methodmods : empty_string;
+
+ Printf(function_code, "\n%s%s %s(", methodmods, return_type, func_name);
+ Printv(imcall, wrap_dmodule_fq_name, ".", overloaded_name, "(", NIL);
+
+ /* Get number of required and total arguments */
+ num_arguments = emit_num_arguments(l);
+ num_required = emit_num_required(l);
+
+ int gencomma = 0;
+
+ /* Output each parameter */
+ for (i = 0, p = l; i < num_arguments; i++) {
+
+ /* Ignored parameters */
+ while (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ }
+
+ SwigType *pt = Getattr(p, "type");
+ String *param_type = NewString("");
+
+ // Get the D parameter type.
+ if ((tm = lookupDTypemap(p, "dptype", true))) {
+ const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ Printf(param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ if (gencomma)
+ Printf(imcall, ", ");
+
+ const bool generating_setter = global_variable_flag || wrapping_member_flag;
+ String *arg = makeParameterName(n, p, i, generating_setter);
+
+ // Get the D code to convert the parameter value to the type used in the
+ // wrapper D module.
+ if ((tm = lookupDTypemap(p, "din", true))) {
+ Replaceall(tm, "$dinput", arg);
+ String *pre = Getattr(p, "tmap:din:pre");
+ if (pre) {
+ replaceClassname(pre, pt);
+ Replaceall(pre, "$dinput", arg);
+ if (Len(pre_code) > 0)
+ Printf(pre_code, "\n");
+ Printv(pre_code, pre, NIL);
+ }
+ String *post = Getattr(p, "tmap:din:post");
+ if (post) {
+ replaceClassname(post, pt);
+ Replaceall(post, "$dinput", arg);
+ if (Len(post_code) > 0)
+ Printf(post_code, "\n");
+ Printv(post_code, post, NIL);
+ }
+ String *terminator = Getattr(p, "tmap:din:terminator");
+ if (terminator) {
+ replaceClassname(terminator, pt);
+ Replaceall(terminator, "$dinput", arg);
+ if (Len(terminator_code) > 0)
+ Insert(terminator_code, 0, "\n");
+ Insert(terminator_code, 0, terminator);
+ }
+ Printv(imcall, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DIN_UNDEF, input_file, line_number,
+ "No din typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ /* Add parameter to module class function */
+ if (gencomma >= 2)
+ Printf(function_code, ", ");
+ gencomma = 2;
+ Printf(function_code, "%s %s", param_type, arg);
+
+ p = Getattr(p, "tmap:in:next");
+ Delete(arg);
+ Delete(param_type);
+ }
+
+ Printf(imcall, ")");
+ Printf(function_code, ") ");
+
+ if (global_variable_flag && (d_version > 1)) {
+ Printf(function_code, "@property ");
+ }
+
+ // Lookup the code used to convert the wrapper return value to the proxy
+ // function return type.
+ if ((tm = lookupDTypemap(n, "dout"))) {
+ replaceExcode(n, tm, "dout", n);
+ bool is_pre_code = Len(pre_code) > 0;
+ bool is_post_code = Len(post_code) > 0;
+ bool is_terminator_code = Len(terminator_code) > 0;
+ if (is_pre_code || is_post_code || is_terminator_code) {
+ if (is_post_code) {
+ Insert(tm, 0, "\n try ");
+ Printv(tm, " finally {\n", post_code, "\n }", NIL);
+ } else {
+ Insert(tm, 0, "\n ");
+ }
+ if (is_pre_code) {
+ Insert(tm, 0, pre_code);
+ Insert(tm, 0, "\n");
+ }
+ if (is_terminator_code) {
+ Printv(tm, "\n", terminator_code, NIL);
+ }
+ Insert(tm, 0, " {");
+ Printf(tm, "\n}");
+ }
+ if (GetFlag(n, "feature:new"))
+ Replaceall(tm, "$owner", "true");
+ else
+ Replaceall(tm, "$owner", "false");
+ replaceClassname(tm, t);
+ Replaceall(tm, "$wcall", imcall);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
+ "No dout typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ // The whole function code is now stored in tm (if there was a matching
+ // type map, of course), so simply append it to the code buffer.
+ Printf(function_code, "%s\n", tm ? (const String *) tm : empty_string);
+ Printv(proxy_dmodule_code, function_code, NIL);
+
+ Delete(pre_code);
+ Delete(post_code);
+ Delete(terminator_code);
+ Delete(function_code);
+ Delete(return_type);
+ Delete(imcall);
+ Delete(func_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeProxyClassAndUpcasts()
+ * --------------------------------------------------------------------------- */
+ void writeProxyClassAndUpcasts(Node *n) {
+ SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
+
+ /*
+ * Handle inheriting from D and C++ classes.
+ */
+
+ String *c_classname = SwigType_namestr(Getattr(n, "name"));
+ String *c_baseclass = NULL;
+ String *baseclass = NULL;
+ String *c_baseclassname = NULL;
+
+ // Inheritance from pure D classes.
+ Node *attributes = NewHash();
+ const String *pure_baseclass =
+ lookupCodeTypemap(n, "dbase", typemap_lookup_type, WARN_NONE, attributes);
+ bool purebase_replace = GetFlag(attributes, "tmap:dbase:replace") ? true : false;
+ bool purebase_notderived = GetFlag(attributes, "tmap:dbase:notderived") ? true : false;
+ Delete(attributes);
+
+ // C++ inheritance.
+ if (!purebase_replace) {
+ List *baselist = Getattr(n, "bases");
+ if (baselist) {
+ Iterator base = First(baselist);
+ while (base.item && GetFlag(base.item, "feature:ignore")) {
+ base = Next(base);
+ }
+ if (base.item) {
+ c_baseclassname = Getattr(base.item, "name");
+ baseclass = Copy(getProxyName(c_baseclassname));
+ if (baseclass)
+ c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
+ base = Next(base);
+ /* Warn about multiple inheritance for additional base class(es) */
+ while (base.item) {
+ if (GetFlag(base.item, "feature:ignore")) {
+ base = Next(base);
+ continue;
+ }
+ String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
+ String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
+ Swig_warning(WARN_D_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
+ "Base %s of class %s ignored: multiple inheritance is not supported in D.\n", baseclassname, proxyclassname);
+ base = Next(base);
+ }
+ }
+ }
+ }
+
+ bool derived = baseclass && getProxyName(c_baseclassname);
+
+ if (derived && purebase_notderived) {
+ pure_baseclass = empty_string;
+ }
+ const String *wanted_base = baseclass ? baseclass : pure_baseclass;
+
+ if (purebase_replace) {
+ wanted_base = pure_baseclass;
+ derived = false;
+ Delete(baseclass);
+ baseclass = NULL;
+ if (purebase_notderived) {
+ Swig_error(Getfile(n), Getline(n),
+ "The dbase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n",
+ typemap_lookup_type);
+ }
+ } else if (baseclass && Len(pure_baseclass) > 0) {
+ Swig_warning(WARN_D_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
+ "Warning for %s proxy: Base class %s ignored. Multiple inheritance is not supported in D. "
+ "Perhaps you need one of the 'replace' or 'notderived' attributes in the dbase typemap?\n", typemap_lookup_type, pure_baseclass);
+ }
+
+ // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy)
+ if (derived) {
+ writeClassUpcast(n, proxy_class_name, c_classname, c_baseclass);
+ }
+
+ /*
+ * Write needed imports.
+ */
+ // If this class is derived from a C++ class, we need to have the D class
+ // generated for it in scope.
+ if (derived) {
+ requireDType(baseclass);
+
+ if (split_proxy_dmodule) {
+ // Fully qualify the baseclass name.
+ String *module = NewStringf("%s%s.", package, baseclass);
+ Insert(baseclass, 0, module);
+ Delete(module);
+ }
+ }
+
+ // Write any custom import statements to the proxy module header.
+ const String *imports = lookupCodeTypemap(n, "dimports", typemap_lookup_type, WARN_NONE);
+ if (Len(imports) > 0) {
+ String* imports_trimmed = Copy(imports);
+ Chop(imports_trimmed);
+ replaceImportTypeMacros(imports_trimmed);
+ Printv(proxy_class_imports, imports_trimmed, "\n", NIL);
+ Delete(imports_trimmed);
+ }
+
+ /*
+ * Write the proxy class header.
+ */
+ // Class modifiers.
+ const String *modifiers =
+ lookupCodeTypemap(n, "dclassmodifiers", typemap_lookup_type, WARN_D_TYPEMAP_CLASSMOD_UNDEF);
+
+ // User-defined interfaces.
+ const String *interfaces =
+ lookupCodeTypemap(n, derived ? "dinterfaces_derived" : "dinterfaces", typemap_lookup_type, WARN_NONE);
+
+ Printv(proxy_class_code,
+ "\n",
+ modifiers,
+ " $dclassname",
+ (*Char(wanted_base) || *Char(interfaces)) ? " : " : "", wanted_base,
+ (*Char(wanted_base) && *Char(interfaces)) ? ", " : "", interfaces, " {",
+ NIL);
+
+ /*
+ * Write the proxy class body.
+ */
+ String* body = NewString("");
+
+ // Default class body.
+ const String *dbody;
+ if (derived) {
+ dbody = lookupCodeTypemap(n, "dbody_derived", typemap_lookup_type, WARN_D_TYPEMAP_DBODY_UNDEF);
+ } else {
+ dbody = lookupCodeTypemap(n, "dbody", typemap_lookup_type, WARN_D_TYPEMAP_DBODY_UNDEF);
+ }
+
+ Printv(body, dbody, NIL);
+
+ // Destructor and dispose().
+ // If the C++ destructor is accessible (public), it is wrapped by the
+ // dispose() method which is also called by the emitted D constructor. If it
+ // is not accessible, no D destructor is written and the generated dispose()
+ // method throws an exception.
+ // This enables C++ classes with protected or private destructors to be used
+ // in D as it would be used in C++ (GC finalization is a no-op then because
+ // of the empty D destructor) while preventing usage in »scope« variables.
+ // The method name for the dispose() method is specified in a typemap
+ // attribute called »methodname«.
+ const String *tm = NULL;
+
+ String *dispose_methodname;
+ String *dispose_methodmodifiers;
+ attributes = NewHash();
+ if (derived) {
+ tm = lookupCodeTypemap(n, "ddispose_derived", typemap_lookup_type, WARN_NONE, attributes);
+ dispose_methodname = Getattr(attributes, "tmap:ddispose_derived:methodname");
+ dispose_methodmodifiers = Getattr(attributes, "tmap:ddispose_derived:methodmodifiers");
+ } else {
+ tm = lookupCodeTypemap(n, "ddispose", typemap_lookup_type, WARN_NONE, attributes);
+ dispose_methodname = Getattr(attributes, "tmap:ddispose:methodname");
+ dispose_methodmodifiers = Getattr(attributes, "tmap:ddispose:methodmodifiers");
+ }
+
+ if (tm && *Char(tm)) {
+ if (!dispose_methodname) {
+ Swig_error(Getfile(n), Getline(n),
+ "No methodname attribute defined in the ddispose%s typemap for %s\n",
+ (derived ? "_derived" : ""), proxy_class_name);
+ }
+ if (!dispose_methodmodifiers) {
+ Swig_error(Getfile(n), Getline(n),
+ "No methodmodifiers attribute defined in ddispose%s typemap for %s.\n",
+ (derived ? "_derived" : ""), proxy_class_name);
+ }
+ }
+
+ if (tm) {
+ // Write the destructor if the C++ one is accessible.
+ if (*Char(destructor_call)) {
+ Printv(body,
+ lookupCodeTypemap(n, "ddestructor", typemap_lookup_type, WARN_NONE), NIL);
+ }
+
+ // Write the dispose() method.
+ String *dispose_code = NewString("");
+ Printv(dispose_code, tm, NIL);
+
+ if (*Char(destructor_call)) {
+ Replaceall(dispose_code, "$wcall", destructor_call);
+ } else {
+ Replaceall(dispose_code, "$wcall", "throw new Exception(\"C++ destructor does not have public access\")");
+ }
+
+ if (*Char(dispose_code)) {
+ Printv(body, "\n", dispose_methodmodifiers,
+ (derived ? " override" : ""), " void ", dispose_methodname, "() ",
+ dispose_code, "\n", NIL);
+ }
+ }
+
+ if (Swig_directorclass(n)) {
+ // If directors are enabled for the current class, generate the
+ // director connect helper function which is called from the constructor
+ // and write it to the class body.
+ writeDirectorConnectProxy();
+ }
+
+ // Write all constants and enumerations first to prevent forward reference
+ // errors.
+ Printv(body, proxy_class_enums_code, NIL);
+
+ // Write the code generated in other methods to the class body.
+ Printv(body, proxy_class_body_code, NIL);
+
+ // Append extra user D code to the class body.
+ Printv(body,
+ lookupCodeTypemap(n, "dcode", typemap_lookup_type, WARN_NONE), "\n", NIL);
+
+ // Write the class body and the curly bracket closing the class definition
+ // to the proxy module.
+ indentCode(body);
+ Replaceall(body, "$dbaseclass", baseclass);
+ Delete(baseclass);
+
+ Printv(proxy_class_code, body, "\n}\n", NIL);
+ Delete(body);
+
+ // Write the epilogue code if there is any.
+ Printv(proxy_class_code, proxy_class_epilogue_code, NIL);
+ }
+
+
+ /* ---------------------------------------------------------------------------
+ * D::writeClassUpcast()
+ * --------------------------------------------------------------------------- */
+ void writeClassUpcast(Node *n, const String* d_class_name,
+ String* c_class_name, String* c_base_name) {
+
+ String *smartptr = Getattr(n, "feature:smartptr");
+ String *upcast_name = NewString("");
+ Printv(upcast_name, d_class_name,
+ (smartptr != 0 ? "SmartPtrUpcast" : "Upcast"), NIL);
+
+ String *upcast_wrapper_name = Swig_name_wrapper(upcast_name);
+
+ writeWrapDModuleFunction(upcast_name, "void*", "(void* objectRef)",
+ upcast_wrapper_name);
+
+ if (smartptr) {
+ SwigType *spt = Swig_cparse_type(smartptr);
+ if (spt) {
+ SwigType *smart = SwigType_typedef_resolve_all(spt);
+ Delete(spt);
+ SwigType *bsmart = Copy(smart);
+ SwigType *rclassname = SwigType_typedef_resolve_all(c_class_name);
+ SwigType *rbaseclass = SwigType_typedef_resolve_all(c_base_name);
+ Replaceall(bsmart, rclassname, rbaseclass);
+ Delete(rclassname);
+ Delete(rbaseclass);
+ String *smartnamestr = SwigType_namestr(smart);
+ String *bsmartnamestr = SwigType_namestr(bsmart);
+ Printv(upcasts_code,
+ "SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", upcast_wrapper_name,
+ "(", smartnamestr, " *objectRef) {\n",
+ " return objectRef ? new ", bsmartnamestr, "(*objectRef) : 0;\n"
+ "}\n",
+ "\n", NIL);
+ Delete(bsmartnamestr);
+ Delete(smartnamestr);
+ Delete(bsmart);
+ } else {
+ Swig_error(Getfile(n), Getline(n),
+ "Invalid type (%s) in 'smartptr' feature for class %s.\n",
+ smartptr, c_class_name);
+ }
+ } else {
+ Printv(upcasts_code,
+ "SWIGEXPORT ", c_base_name, " * SWIGSTDCALL ", upcast_wrapper_name,
+ "(", c_base_name, " *objectRef) {\n",
+ " return (", c_base_name, " *)objectRef;\n"
+ "}\n",
+ "\n", NIL);
+ }
+
+ Replaceall(upcasts_code, "$cclass", c_class_name);
+ Replaceall(upcasts_code, "$cbaseclass", c_base_name);
+
+ Delete(upcast_name);
+ Delete(upcast_wrapper_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeTypeWrapperClass()
+ * --------------------------------------------------------------------------- */
+ void writeTypeWrapperClass(String *classname, SwigType *type) {
+ Node *n = NewHash();
+ Setfile(n, input_file);
+ Setline(n, line_number);
+
+ assertClassNameValidity(classname);
+
+ String* imports_target;
+ String* code_target;
+ File *class_file = NULL;
+ if (split_proxy_dmodule) {
+ String *filename = NewStringf("%s%s.d", dmodule_directory, classname);
+ class_file = NewFile(filename, "w", SWIG_output_files());
+ if (!class_file) {
+ FileErrorDisplay(filename);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filename));
+ Delete(filename);
+
+ emitBanner(class_file);
+ Printf(class_file, "module %s%s;\n", package, classname);
+ Printf(class_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+
+ imports_target = NewString("");
+ code_target = NewString("");
+ } else {
+ imports_target = proxy_dmodule_imports;
+ code_target = proxy_dmodule_code;
+ }
+
+ // Import statements.
+ const String *imports = lookupCodeTypemap(n, "dimports", type, WARN_NONE);
+ if (Len(imports) > 0) {
+ String *imports_trimmed = Copy(imports);
+ Chop(imports_trimmed);
+ replaceImportTypeMacros(imports_trimmed);
+ Printv(imports_target, imports_trimmed, "\n", NIL);
+ Delete(imports_trimmed);
+ }
+
+ // Pure D baseclass and interfaces (no C++ inheritance possible.
+ const String *pure_baseclass = lookupCodeTypemap(n, "dbase", type, WARN_NONE);
+ const String *pure_interfaces = lookupCodeTypemap(n, "dinterfaces", type, WARN_NONE);
+
+ // Emit the class.
+ Printv(code_target,
+ "\n",
+ lookupCodeTypemap(n, "dclassmodifiers", type, WARN_D_TYPEMAP_CLASSMOD_UNDEF),
+ " $dclassname",
+ (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass,
+ ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? ", " : "", pure_interfaces,
+ " {", NIL);
+
+ String* body = NewString("");
+ Printv(body, lookupCodeTypemap(n, "dbody", type, WARN_D_TYPEMAP_DBODY_UNDEF),
+ lookupCodeTypemap(n, "dcode", type, WARN_NONE), NIL);
+ indentCode(body);
+ Printv(code_target, body, "\n}\n", NIL);
+ Delete(body);
+
+ Replaceall(code_target, "$dclassname", classname);
+
+ if (split_proxy_dmodule) {
+ Printv(class_file, imports_target, NIL);
+ Delete(imports_target);
+
+ replaceModuleVariables(code_target);
+ Printv(class_file, code_target, NIL);
+ Delete(code_target);
+
+ Close(class_file);
+ Delete(class_file);
+ }
+
+ Delete(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeDirectorConnectProxy()
+ *
+ * Writes the helper method which registers the director callbacks by calling
+ * the director connect function from the D side to the proxy class.
+ * --------------------------------------------------------------------------- */
+ void writeDirectorConnectProxy() {
+ Printf(proxy_class_body_code, "\nprivate void swigDirectorConnect() {\n");
+
+ int i;
+ for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *method = Getattr(udata, "method");
+ String *overloaded_name = Getattr(udata, "overname");
+ String *return_type = Getattr(udata, "return_type");
+ String *param_list = Getattr(udata, "param_list");
+ String *methid = Getattr(udata, "class_methodidx");
+ Printf(proxy_class_body_code, " %s.SwigDirector_%s_Callback%s callback%s;\n", wrap_dmodule_fq_name, proxy_class_name, methid, methid);
+ Printf(proxy_class_body_code, " if (swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) {\n", return_type, param_list, return_type, param_list, method);
+ Printf(proxy_class_body_code, " callback%s = &swigDirectorCallback_%s_%s;\n", methid, proxy_class_name, overloaded_name);
+ Printf(proxy_class_body_code, " }\n\n");
+ }
+ Printf(proxy_class_body_code, " %s.%s_director_connect(cast(void*)swigCPtr, cast(void*)this", wrap_dmodule_fq_name, proxy_class_name);
+ for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *methid = Getattr(udata, "class_methodidx");
+ Printf(proxy_class_body_code, ", callback%s", methid);
+ }
+ Printf(proxy_class_body_code, ");\n");
+ Printf(proxy_class_body_code, "}\n");
+
+ // Helper function to determine if a method has been overridden in a
+ // subclass of the wrapped class. If not, we just pass null to the
+ // director_connect_function since the method from the C++ class should
+ // be called as usual (see above).
+ // Only emit it if the proxy class has at least one method.
+ if (first_class_dmethod < curr_class_dmethod) {
+ Printf(proxy_class_body_code, "\n");
+ Printf(proxy_class_body_code, "private bool swigIsMethodOverridden(DelegateType, FunctionType, alias fn)() {\n");
+ Printf(proxy_class_body_code, " DelegateType dg = &fn;\n");
+ Printf(proxy_class_body_code, " return dg.funcptr != SwigNonVirtualAddressOf!(FunctionType, fn);\n");
+ Printf(proxy_class_body_code, "}\n");
+ Printf(proxy_class_body_code, "\n");
+ Printf(proxy_class_body_code, "private static Function SwigNonVirtualAddressOf(Function, alias fn)() {\n");
+ Printf(proxy_class_body_code, " return cast(Function) &fn;\n");
+ Printf(proxy_class_body_code, "}\n");
+ }
+
+ if (Len(director_dcallbacks_code) > 0) {
+ Printv(proxy_class_epilogue_code, director_dcallbacks_code, NIL);
+ }
+
+ Delete(director_callback_typedefs);
+ director_callback_typedefs = NULL;
+ Delete(director_callback_pointers);
+ director_callback_pointers = NULL;
+ Delete(director_dcallbacks_code);
+ director_dcallbacks_code = NULL;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeDirectorConnectWrapper()
+ *
+ * Writes the director connect function and the corresponding declaration to
+ * the C++ wrapper respectively the D wrapper.
+ * --------------------------------------------------------------------------- */
+ void writeDirectorConnectWrapper(Node *n) {
+ if (!Swig_directorclass(n))
+ return;
+
+ // Output the director connect method.
+ String *norm_name = SwigType_namestr(Getattr(n, "name"));
+ String *connect_name = NewStringf("%s_director_connect", proxy_class_name);
+ String *sym_name = Getattr(n, "sym:name");
+ Wrapper *code_wrap;
+
+ Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL);
+ Replaceall(wrapper_loader_bind_code, "$function", connect_name);
+ Replaceall(wrapper_loader_bind_code, "$symbol", Swig_name_wrapper(connect_name));
+
+ Printf(wrap_dmodule_code, "extern(C) void function(void* cObject, void* dObject");
+
+ code_wrap = NewWrapper();
+ Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL D_%s(void *objarg, void *dobj", connect_name);
+
+ Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
+ Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast<SwigDirector_%s *>(obj);\n", sym_name, sym_name);
+
+ Printf(code_wrap->code, " if (director) {\n");
+ Printf(code_wrap->code, " director->swig_connect_director(dobj");
+
+ for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *methid = Getattr(udata, "class_methodidx");
+
+ Printf(code_wrap->def, ", SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid);
+ Printf(code_wrap->code, ", callback%s", methid);
+ Printf(wrap_dmodule_code, ", SwigDirector_%s_Callback%s callback%s", sym_name, methid, methid);
+ }
+
+ Printf(code_wrap->def, ") {\n");
+ Printf(code_wrap->code, ");\n");
+ Printf(wrap_dmodule_code, ") %s;\n", connect_name);
+ Printf(code_wrap->code, " }\n");
+ Printf(code_wrap->code, "}\n");
+
+ Wrapper_print(code_wrap, f_wrappers);
+ DelWrapper(code_wrap);
+
+ Delete(connect_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::requireDType()
+ *
+ * Adds an import statement for the given module to the header of current
+ * module. This is only used for dependencies created in generated code, user-
+ * (read: typemap-) specified import statements are handeled seperately.
+ * --------------------------------------------------------------------------- */
+ void requireDType(const String *dmodule_name) {
+ String *import = createImportStatement(dmodule_name);
+ Append(import, "\n");
+ if (is_wrapping_class()) {
+ addImportStatement(proxy_class_imports, import);
+ } else {
+ addImportStatement(proxy_dmodule_imports, import);
+ }
+ Delete(import);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::addImportStatement()
+ *
+ * Adds the given import statement to the given list of import statements if
+ * there is no statement importing that module present yet.
+ * --------------------------------------------------------------------------- */
+ void addImportStatement(String *target, const String *import) const {
+ char *position = Strstr(target, import);
+ if (position) {
+ // If the import statement has been found in the target string, we have to
+ // check if the previous import was static, which would lead to problems
+ // if this import is not.
+ // Thus, we check if the seven characters in front of the occurence are
+ // »static «. If the import string passed is also static, the checks fail
+ // even if the found statement is also static because the last seven
+ // characters would be part of the previous import statement then.
+
+ if (position - Char(target) < 7) {
+ return;
+ }
+ if (strncmp(position - 7, "static ", 7)) {
+ return;
+ }
+ }
+
+ Printv(target, import, NIL);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::createImportStatement()
+ *
+ * Creates a string containing an import statement for the given module if it
+ * is needed in the currently generated proxy D module (i.e. if it is not the
+ * current module itself).
+ * --------------------------------------------------------------------------- */
+ String *createImportStatement(const String *dmodule_name,
+ bool static_import = true) const {
+
+ if (inProxyModule(dmodule_name)) {
+ return NewStringf("");
+ } else {
+ if (static_import) {
+ return NewStringf("static import %s%s;", package, dmodule_name);
+ } else {
+ return NewStringf("import %s%s;", package, dmodule_name);
+ }
+ }
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::inProxyModule()
+ *
+ * Determines if the specified proxy class is decleared in the currently
+ * processed proxy D module.
+ *
+ * This function is used to determine if fully qualified type names have to be
+ * used (package, module and type name). This is never the case if the split
+ * proxy mode is not used, all proxy types are written to the same module then.
+ * --------------------------------------------------------------------------- */
+ bool inProxyModule(const String *type_name) const {
+ if (!split_proxy_dmodule) {
+ // If we are not in split proxy module mode, proxy code is always written
+ // to the same module.
+ return true;
+ }
+
+ if (!Len(proxy_class_name)) {
+ return false;
+ }
+
+ return (Strcmp(proxy_class_name, type_name) == 0);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::addUpcallMethod()
+ *
+ * Adds new director upcall signature.
+ * --------------------------------------------------------------------------- */
+ UpcallData *addUpcallMethod(String *imclass_method, String *class_method,
+ String *decl, String *overloaded_name, String *return_type, String *param_list) {
+
+ UpcallData *udata;
+ String *imclass_methodidx;
+ String *class_methodidx;
+ Hash *new_udata;
+ String *key = NewStringf("%s|%s", imclass_method, decl);
+
+ ++curr_class_dmethod;
+
+ /* Do we know about this director class already? */
+ if ((udata = Getattr(dmethods_table, key))) {
+ Delete(key);
+ return Getattr(udata, "methodoff");
+ }
+
+ imclass_methodidx = NewStringf("%d", n_dmethods);
+ class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
+ n_dmethods++;
+
+ new_udata = NewHash();
+ Append(dmethods_seq, new_udata);
+ Setattr(dmethods_table, key, new_udata);
+
+ Setattr(new_udata, "method", Copy(class_method));
+ Setattr(new_udata, "class_methodidx", class_methodidx);
+ Setattr(new_udata, "decl", Copy(decl));
+ Setattr(new_udata, "overname", Copy(overloaded_name));
+ Setattr(new_udata, "return_type", Copy(return_type));
+ Setattr(new_udata, "param_list", Copy(param_list));
+
+ Delete(key);
+ return new_udata;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::assertClassNameValidity()
+ * --------------------------------------------------------------------------- */
+ void assertClassNameValidity(const String* class_name) const {
+ if (split_proxy_dmodule) {
+ if (Cmp(class_name, wrap_dmodule_name) == 0) {
+ Swig_error(input_file, line_number, "Class name cannot be equal to wrap D module name: %s\n",
+ class_name);
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ if (Cmp(class_name, proxy_dmodule_name) == 0) {
+ Swig_error(input_file, line_number, "Class name cannot be equal to proxy D module name: %s\n",
+ class_name);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ }
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::getPrimitiveDptype()
+ *
+ * Returns the D proxy type for the passed type if it is a primitive type in
+ * both C and D.
+ * --------------------------------------------------------------------------- */
+ String *getPrimitiveDptype(Node *node, SwigType *type) {
+ SwigType *stripped_type = SwigType_typedef_resolve_all(type);
+
+ // A reference can only be the »outermost element« of a typ.
+ bool mutable_ref = false;
+ if (SwigType_isreference(stripped_type)) {
+ SwigType_del_reference(stripped_type);
+
+ if (SwigType_isconst(stripped_type)) {
+ SwigType_del_qualifier(stripped_type);
+ } else {
+ mutable_ref = true;
+ }
+ }
+
+ // Strip all the pointers from the type.
+ int indirection_count = 0;
+ while (SwigType_ispointer(stripped_type)) {
+ ++indirection_count;
+ SwigType_del_pointer(stripped_type);
+ }
+
+ // Now that we got rid of the pointers, see if we are dealing with a
+ // primitive type.
+ String *dptype = 0;
+ if (SwigType_isfunction(stripped_type) && indirection_count > 0) {
+ // type was a function pointer, split it up.
+ SwigType_add_pointer(stripped_type);
+ --indirection_count;
+
+ SwigType *return_type = Copy(stripped_type);
+ SwigType *params_type = SwigType_functionpointer_decompose(return_type);
+ String *return_dtype = getPrimitiveDptype(node, return_type);
+ Delete(return_type);
+ if (!return_dtype) {
+ return 0;
+ }
+
+ List *parms = SwigType_parmlist(params_type);
+ List *param_dtypes = NewList();
+ for (Iterator it = First(parms); it.item; it = Next(it)) {
+ String *current_dtype = getPrimitiveDptype(node, it.item);
+ if (Cmp(current_dtype, "void") == 0) {
+ // void somefunc(void) is legal syntax in C, but not in D, so simply
+ // skip the void parameter.
+ Delete(current_dtype);
+ continue;
+ }
+ if (!current_dtype) {
+ Delete(return_dtype);
+ Delete(param_dtypes);
+ return 0;
+ }
+ Append(param_dtypes, current_dtype);
+ }
+
+ String *param_list = NewString("");
+ {
+ bool gen_comma = false;
+ for (Iterator it = First(param_dtypes); it.item; it = Next(it)) {
+ if (gen_comma) {
+ Append(param_list, ", ");
+ }
+ Append(param_list, it.item);
+ Delete(it.item);
+ gen_comma = true;
+ }
+ }
+
+ dptype = NewStringf("%s function(%s)", return_dtype, param_list);
+ Delete(param_list);
+ Delete(param_dtypes);
+ Delete(return_dtype);
+ } else {
+ Hash *attributes = NewHash();
+ const String *tm =
+ lookupCodeTypemap(node, "dptype", stripped_type, WARN_NONE, attributes);
+ if(!GetFlag(attributes, "tmap:dptype:cprimitive")) {
+ dptype = 0;
+ } else {
+ dptype = Copy(tm);
+
+ // We need to call replaceClassname here with the stripped type to avoid
+ // $dclassname in the enum typemaps being replaced later with the full
+ // type.
+ replaceClassname(dptype, stripped_type);
+ }
+ Delete(attributes);
+ }
+ Delete(stripped_type);
+
+ if (!dptype) {
+ // The type passed is no primitive type.
+ return 0;
+ }
+
+ // The type is ultimately a primitive type, now append the right number of
+ // indirection levels (pointers).
+ for (int i = 0; i < indirection_count; ++i) {
+ Append(dptype, "*");
+ }
+
+ // Add a level of indirection for a mutable reference since it is wrapped
+ // as a pointer.
+ if (mutable_ref) {
+ Append(dptype, "*");
+ }
+
+ return dptype;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::lookupCodeTypemap()
+ *
+ * Looks up a D code fragment for generating the wrapper class for the given
+ * type.
+ *
+ * n - for input only and must contain info for Getfile(n) and Getline(n) to work
+ * tmap_method - typemap method name
+ * type - typemap type to lookup
+ * warning - warning number to issue if no typemaps found
+ * typemap_attributes - the typemap attributes are attached to this node and will
+ * also be used for temporary storage if non null
+ * return is never NULL, unlike Swig_typemap_lookup()
+ * --------------------------------------------------------------------------- */
+ const String *lookupCodeTypemap(Node *n, const_String_or_char_ptr tmap_method,
+ SwigType *type, int warning, Node *typemap_attributes = 0) const {
+
+ Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
+ Setattr(node, "type", type);
+ Setfile(node, Getfile(n));
+ Setline(node, Getline(n));
+ const String *tm = Swig_typemap_lookup(tmap_method, node, "", 0);
+ if (!tm) {
+ tm = empty_string;
+ if (warning != WARN_NONE) {
+ Swig_warning(warning, Getfile(n), Getline(n),
+ "No %s typemap defined for %s\n", tmap_method, SwigType_str(type, 0));
+ }
+ }
+ if (!typemap_attributes) {
+ Delete(node);
+ }
+
+ return tm;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::lookupDTypemap()
+ *
+ * Looks up a D typemap for the given node, replacing D-specific special
+ * variables as needed.
+ *
+ * The method parameter specifies the typemap method to use. If attached is
+ * true, the value is just fetched from the tmap:<method> node attribute,
+ * Swig_typemap_lookup is used otherwise.
+ * --------------------------------------------------------------------------- */
+ String *lookupDTypemap(Node *n, const_String_or_char_ptr method, bool attached = false) {
+ String *result = 0;
+
+ if (attached) {
+ String *attr_name = NewStringf("tmap:%s", method);
+ result = Getattr(n, attr_name);
+ Delete(attr_name);
+ } else {
+ // FIXME: As a workaround for a bug so far only surfacing in the
+ // smart_pointer_const_overload test case, remove the nativepointer
+ // typemap attribute since it seems to be already there from a dout
+ // typemap of a different type in that test.
+ String *np_key = NewStringf("tmap:%s:nativepointer", method);
+ Delattr(n, np_key);
+ Delete(np_key);
+
+ result = Swig_typemap_lookup(method, n, "", 0);
+ }
+
+ if (!result) {
+ return 0;
+ }
+
+ // Check if the passed node actually has type information attached. This
+ // is not the case e.g. in constructorWrapper.
+ SwigType *type = Getattr(n, "type");
+ if (type) {
+ String *np_key = NewStringf("tmap:%s:nativepointer", method);
+ String *np_value = Getattr(n, np_key);
+ Delete(np_key);
+ String *dptype;
+ if (np_value && (dptype = getPrimitiveDptype(n, type))) {
+ // If the typemap in question has a »nativepointer« attribute and we
+ // are dealing with a primitive type, use it instead.
+ result = Copy(np_value);
+ Replaceall(result, "$dptype", dptype);
+ }
+
+ replaceClassname(result, type);
+ }
+
+ return result;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceClassname()
+ *
+ * Replaces the special variable $dclassname with the proxy class name for
+ * classes/structs/unions SWIG knows about. Also substitutes the enumeration
+ * name for non-anonymous enums. Otherwise, $classname is replaced with a
+ * $descriptor(type)-like name.
+ *
+ * $*dclassname and $&classname work like with descriptors (see manual section
+ * 10.4.3), they remove a prointer from respectively add a pointer to the type.
+ *
+ * Inputs:
+ * tm - String to perform the substitution at (will usually come from a
+ * typemap.
+ * pt - The type to substitute for the variables.
+ * Outputs:
+ * tm - String with the variables substituted.
+ * Return:
+ * substitution_performed - flag indicating if a substitution was performed
+ * --------------------------------------------------------------------------- */
+ bool replaceClassname(String *tm, SwigType *pt) {
+ bool substitution_performed = false;
+ SwigType *type = Copy(SwigType_typedef_resolve_all(pt));
+ SwigType *strippedtype = SwigType_strip_qualifiers(type);
+
+ if (Strstr(tm, "$dclassname")) {
+ SwigType *classnametype = Copy(strippedtype);
+ replaceClassnameVariable(tm, "$dclassname", classnametype);
+ substitution_performed = true;
+ Delete(classnametype);
+ }
+ if (Strstr(tm, "$*dclassname")) {
+ SwigType *classnametype = Copy(strippedtype);
+ Delete(SwigType_pop(classnametype));
+ replaceClassnameVariable(tm, "$*dclassname", classnametype);
+ substitution_performed = true;
+ Delete(classnametype);
+ }
+ if (Strstr(tm, "$&dclassname")) {
+ SwigType *classnametype = Copy(strippedtype);
+ SwigType_add_pointer(classnametype);
+ replaceClassnameVariable(tm, "$&dclassname", classnametype);
+ substitution_performed = true;
+ Delete(classnametype);
+ }
+
+ Delete(strippedtype);
+ Delete(type);
+
+ return substitution_performed;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceClassnameVariable()
+ *
+ * See D::replaceClassname().
+ * --------------------------------------------------------------------------- */
+ void replaceClassnameVariable(String *target, const char *variable, SwigType *type) {
+ // TODO: Fix const-correctness of methods called in here and make type const.
+
+ // We make use of the fact that this function is called at least once for
+ // every type encountered which is written to a seperate file, which allows
+ // us to handle imports here.
+ // When working in split proxy module mode, each generated proxy class/enum
+ // is written to a seperate module. This requires us to add a corresponding
+ // import when a type is used in another generated module. If we are not
+ // working in split proxy module mode, this is not relevant and the
+ // generated module name is discarded.
+ String *import_name;
+
+ String *qualified_type_name;
+ if (SwigType_isenum(type)) {
+ // RESEARCH: Make sure that we really cannot get here for anonymous enums.
+ Node *n = enumLookup(type);
+ const String *symname = Getattr(n, "sym:name");
+
+ // Add in class scope when referencing enum if not a global enum.
+ const String *parent_name = NULL;
+ String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name"));
+ if (scopename_prefix) {
+ parent_name = getProxyName(scopename_prefix);
+ Delete(scopename_prefix);
+ }
+
+ if (parent_name) {
+ qualified_type_name = createQualifiedName(parent_name);
+ Printv(qualified_type_name, ".", symname, NIL);
+
+ // An enum nested in a class is not written to a seperate module (this
+ // would not even be possible in D), so just import the parent.
+ import_name = Copy(parent_name);
+ } else {
+ qualified_type_name = createQualifiedName(symname);
+
+ // A non-nested enum is written to a seperate module, import it.
+ import_name = Copy(symname);
+ }
+ } else {
+ const String *class_name = getProxyName(type);
+ if (class_name) {
+ // This is something wrapped as a proxy class (getProxyName() works for
+ // pointers to classes too).
+ qualified_type_name = createQualifiedName(class_name);
+ import_name = Copy(class_name);
+ } else {
+ // SWIG does not know anything about the type (after resolving typedefs).
+ // Just mangle the type name string like $descriptor(type) would do.
+ String *descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(type));
+ qualified_type_name = createQualifiedName(descriptor);
+ import_name = Copy(descriptor);
+
+ // Add to hash table so that a type wrapper class can be created later.
+ Setattr(unknown_types, descriptor, type);
+
+ Delete(descriptor);
+ }
+ }
+
+ Replaceall(target, variable, qualified_type_name);
+ Delete(qualified_type_name);
+
+ requireDType(import_name);
+ Delete(import_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::createQualifiedName()
+ * --------------------------------------------------------------------------- */
+ String *createQualifiedName(const String *class_name) const {
+ if (inProxyModule(class_name)) {
+ return Copy(class_name);
+ } else {
+ return NewStringf("%s%s.%s", package, class_name, class_name);
+ }
+}
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceModuleVariables()
+ *
+ * Replaces the $wrapdmodule and $module variables with their values in the
+ * target string.
+ * --------------------------------------------------------------------------- */
+ void replaceModuleVariables(String *target) const {
+ Replaceall(target, "$wrapdmodule", wrap_dmodule_fq_name);
+ Replaceall(target, "$module", proxy_dmodule_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceExcode()
+ *
+ * If a C++ method can throw a exception, additional code is added to the
+ * proxy method to check if an exception is pending so that it can be
+ * rethrown on the D side.
+ *
+ * This method replaces the $excode variable with the exception handling code
+ * in the excode typemap attribute if it »canthrow« an exception.
+ * --------------------------------------------------------------------------- */
+ void replaceExcode(Node *n, String *code, const String *typemap, Node *parameter) const {
+ String *excode_attribute = NewStringf("tmap:%s:excode", typemap);
+ String *excode = Getattr(parameter, excode_attribute);
+ if (Getattr(n, "d:canthrow")) {
+ int count = Replaceall(code, "$excode", excode);
+ if (count < 1 || !excode) {
+ Swig_warning(WARN_D_EXCODE_MISSING, input_file, line_number,
+ "D exception may not be thrown – no $excode or excode attribute in '%s' typemap.\n",
+ typemap);
+ }
+ } else {
+ Replaceall(code, "$excode", "");
+ }
+ Delete(excode_attribute);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceImportTypeMacros()
+ *
+ * Replaces the $importtype(SomeDClass) macro with an import statement if it
+ * is required to get SomeDClass in scope for the currently generated proxy
+ * D module.
+ * --------------------------------------------------------------------------- */
+ void replaceImportTypeMacros(String *target) const {
+ // Code from replace_embedded_typemap.
+ char *start = 0;
+ while ((start = Strstr(target, "$importtype("))) {
+ char *end = 0;
+ char *param_start = 0;
+ char *param_end = 0;
+ int level = 0;
+ char *c = start;
+ while (*c) {
+ if (*c == '(') {
+ if (level == 0) {
+ param_start = c + 1;
+ }
+ level++;
+ }
+ if (*c == ')') {
+ level--;
+ if (level == 0) {
+ param_end = c;
+ end = c + 1;
+ break;
+ }
+ }
+ c++;
+ }
+
+ if (end) {
+ String *current_macro = NewStringWithSize(start, (end - start));
+ String *current_param = NewStringWithSize(param_start, (param_end - param_start));
+
+ String *import = createImportStatement(current_param, false);
+ Replace(target, current_macro, import, DOH_REPLACE_ANY);
+ Delete(import);
+
+ Delete(current_param);
+ Delete(current_macro);
+ } else {
+ String *current_macro = NewStringWithSize(start, (c - start));
+ Swig_error(Getfile(target), Getline(target), "Syntax error in: %s\n", current_macro);
+ Replace(target, current_macro, "<error in $importtype macro>", DOH_REPLACE_ANY);
+ Delete(current_macro);
+ }
+ }
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::getOverloadedName()
+ * --------------------------------------------------------------------------- */
+ String *getOverloadedName(Node *n) const {
+ // A void* parameter is used for all wrapped classes in the wrapper code.
+ // Thus, the wrapper function names for overloaded functions are postfixed
+ // with a counter string to make them unique.
+ String *overloaded_name = Copy(Getattr(n, "sym:name"));
+
+ if (Getattr(n, "sym:overloaded")) {
+ Append(overloaded_name, Getattr(n, "sym:overname"));
+ }
+
+ return overloaded_name;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::getProxyName()
+ *
+ * Returns the D class name if a type corresponds to something wrapped with a
+ * proxy class, NULL otherwise.
+ * --------------------------------------------------------------------------- */
+ const String *getProxyName(SwigType *t) {
+ Node *n = classLookup(t);
+ if (n) {
+ return Getattr(n, "sym:name");
+ } else {
+ return NULL;
+ }
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::directorClassName()
+ * --------------------------------------------------------------------------- */
+ String *getDirectorClassName(Node *n) const {
+ String *dirclassname;
+ const char *attrib = "director:classname";
+
+ if (!(dirclassname = Getattr(n, attrib))) {
+ String *classname = Getattr(n, "sym:name");
+
+ dirclassname = NewStringf("SwigDirector_%s", classname);
+ Setattr(n, attrib, dirclassname);
+ }
+
+ return dirclassname;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::makeParameterName()
+ *
+ * Inputs:
+ * n - Node
+ * p - parameter node
+ * arg_num - parameter argument number
+ * setter - set this flag when wrapping variables
+ * Return:
+ * arg - a unique parameter name
+ * --------------------------------------------------------------------------- */
+ String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter) const {
+ String *arg = 0;
+ String *pn = Getattr(p, "name");
+
+ // Use C parameter name unless it is a duplicate or an empty parameter name
+ int count = 0;
+ ParmList *plist = Getattr(n, "parms");
+ while (plist) {
+ if ((Cmp(pn, Getattr(plist, "name")) == 0))
+ count++;
+ plist = nextSibling(plist);
+ }
+ String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0;
+ arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn);
+
+ if (setter && Cmp(arg, "self") != 0) {
+ // In theory, we could use the normal parameter name for setter functions.
+ // Unfortunately, it is set to "Class::VariableName" for static public
+ // members by the parser, which is not legal D syntax. Thus, we just force
+ // it to "value".
+ Delete(arg);
+ arg = NewString("value");
+ }
+
+ if (split_proxy_dmodule && Strncmp(arg, package, Len(arg)) == 0) {
+ // If we are in split proxy mode and the argument is named like the target
+ // package, we append an underscore to its name to avoid clashes.
+ Append(arg, "_");
+ }
+
+ return arg;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::canThrow()
+ *
+ * Determines whether the code in the typemap can throw a D exception.
+ * If so, note it for later when excodeSubstitute() is called.
+ * --------------------------------------------------------------------------- */
+ void canThrow(Node *n, const String *typemap, Node *parameter) const {
+ String *canthrow_attribute = NewStringf("tmap:%s:canthrow", typemap);
+ String *canthrow = Getattr(parameter, canthrow_attribute);
+ if (canthrow)
+ Setattr(n, "d:canthrow", "1");
+ Delete(canthrow_attribute);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::wrapMemberFunctionAsDConst()
+ *
+ * Determines whether the member function represented by the passed node is
+ * wrapped as D »const« or not.
+ * --------------------------------------------------------------------------- */
+ bool wrapMemberFunctionAsDConst(Node *n) const {
+ if (d_version == 1) return false;
+ if (static_flag) return false; // Never emit »const« for static member functions.
+ return GetFlag(n, "memberget") || SwigType_isconst(Getattr(n, "decl"));
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::areAllOverloadsOverridden()
+ *
+ * Determines whether the class the passed function node belongs to overrides
+ * all the overlaods for the passed function node defined somewhere up the
+ * inheritance hierachy.
+ * --------------------------------------------------------------------------- */
+ bool areAllOverloadsOverridden(Node *n) const {
+ List *base_list = Getattr(parentNode(n), "bases");
+ if (!base_list) {
+ // If the class which contains n is not derived from any other class,
+ // there cannot be any not-overridden overloads.
+ return true;
+ }
+
+ // In case of multiple base classes, skip to the one which has not been
+ // ignored.
+ // RESEARCH: Also emit a warning in case of multiple inheritance here?
+ Iterator it = First(base_list);
+ while (it.item && GetFlag(it.item, "feature:ignore")) {
+ it = Next(it);
+ }
+ Node *base_class = it.item;
+
+ if (!base_class) {
+ // If all base classes have been ignored, there cannot be one either.
+ return true;
+ }
+
+ // We try to find at least a single overload which exists in the base class
+ // so we can progress up the inheritance hierachy even if there have been
+ // new overloads introduced after the topmost class.
+ Node *base_function = NULL;
+ for (Node *tmp = firstChild(base_class); tmp; tmp = nextSibling(tmp)) {
+ if (Strcmp(Getattr(tmp, "sym:name"), Getattr(n, "sym:name")) == 0) {
+ base_function = tmp;
+ break;
+ }
+ }
+
+ if (!base_function) {
+ // If there is no overload which also exists in the super class, there
+ // cannot be any base class overloads not overridden.
+ return true;
+ }
+
+ size_t base_overload_count = 0;
+ for (Node *tmp = firstSibling(base_function); tmp; tmp = Getattr(tmp, "sym:nextSibling")) {
+ if (is_protected(base_function) &&
+ !(Swig_director_mode() && Swig_director_protected_mode() && Swig_all_protected_mode())) {
+ // If the base class function is »protected« and were are not in
+ // director mode, it is not emitted to the base class and thus we do
+ // not count it. Otherwise, we would run into issues if the visiblity
+ // of some functions was changed from protected to public in a child
+ // class with the using directive.
+ continue;
+ }
+ ++base_overload_count;
+ }
+
+ return ((base_overload_count <= overridingOverloadCount(n)) &&
+ areAllOverloadsOverridden(base_function));
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::overridingOverloadCount()
+ *
+ * Given a member function node, this function counts how many of the
+ * overloads of the function (including itself) override a function in the
+ * base class.
+ * --------------------------------------------------------------------------- */
+ size_t overridingOverloadCount(Node *n) const {
+ size_t result = 0;
+
+ Node *tmp = firstSibling(n);
+ do {
+ // KLUDGE: We also have to count the function if the access attribute is
+ // not present, since this means that it has been promoted into another
+ // protection level in the base class with the C++ »using« directive, and
+ // is thus taken into account when counting the base class overloads, even
+ // if it is not marked as »override« by the SWIG parser.
+ if (Getattr(n, "override") || !Getattr(n, "access")) {
+ ++result;
+ }
+ } while((tmp = Getattr(tmp, "sym:nextSibling")));
+
+ return result;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::firstSibling()
+ *
+ * Returns the first sibling of the passed node.
+ * --------------------------------------------------------------------------- */
+ Node *firstSibling(Node *n) const {
+ Node *result = n;
+ while (Node *tmp = Getattr(result, "sym:previousSibling")) {
+ result = tmp;
+ }
+ return result;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::indentCode()
+ *
+ * Helper function to indent a code (string) by one level.
+ * --------------------------------------------------------------------------- */
+ void indentCode(String* code) const {
+ Replaceall(code, "\n", "\n ");
+ Replaceall(code, " \n", "\n");
+ Chop(code);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::emitBanner()
+ * --------------------------------------------------------------------------- */
+ void emitBanner(File *f) const {
+ Printf(f, "/* ----------------------------------------------------------------------------\n");
+ Swig_banner_target_lang(f, " *");
+ Printf(f, " * ----------------------------------------------------------------------------- */\n\n");
+ }
+};
+
+static Language *new_swig_d() {
+ return new D();
+}
+
+/* -----------------------------------------------------------------------------
+ * swig_d() - Instantiate module
+ * ----------------------------------------------------------------------------- */
+extern "C" Language *swig_d(void) {
+ return new_swig_d();
+}
+
+/* -----------------------------------------------------------------------------
+ * Usage information displayed at the command line.
+ * ----------------------------------------------------------------------------- */
+const char *D::usage = (char *) "\
+D Options (available with -d)\n\
+ -splitproxy - Write each D type to a dedicated file instead of\n\
+ generating a single proxy D module.\n\
+ -noproxy - Generate the low-level functional interface instead\n\
+ of proxy classes\n\
+ -package <pkg> - Write generated D modules into package <pkg>\n\
+ -wrapperlibrary <wl> - Sets the name of the wrapper library to <wl>\n\
+\n";
diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx
index 86cccdf88..01ab1b79f 100644
--- a/Source/Modules/swigmain.cxx
+++ b/Source/Modules/swigmain.cxx
@@ -52,6 +52,7 @@ extern "C" {
Language *swig_uffi(void);
Language *swig_r(void);
Language *swig_go(void);
+ Language *swig_d(void);
}
struct swig_module {
@@ -70,6 +71,7 @@ static swig_module modules[] = {
{"-clisp", swig_clisp, "CLISP"},
{"-cffi", swig_cffi, "CFFI"},
{"-csharp", swig_csharp, "C#"},
+ {"-d", swig_d, "D"},
{"-go", swig_go, "Go"},
{"-guile", swig_guile, "Guile"},
{"-java", swig_java, "Java"},
diff --git a/configure.in b/configure.in
index 36337b41d..5383c40c7 100644
--- a/configure.in
+++ b/configure.in
@@ -2017,6 +2017,42 @@ AC_SUBST(GOGCC)
AC_SUBST(GO)
#----------------------------------------------------------------
+# Look for D
+#----------------------------------------------------------------
+
+AC_ARG_WITH(d, AS_HELP_STRING([--without-d], [Disable D]), [with_d="$withval"], [with_d=yes])
+AC_ARG_WITH(d1-compiler, [ --with-d1-compiler=path Set location of D1 compiler (DMD compatible)],[D1COMPILERBIN="$withval"], [D1COMPILERBIN=])
+AC_ARG_WITH(d2-compiler, [ --with-d2-compiler=path Set location of D2 compiler (DMD compatible)],[D2COMPILERBIN="$withval"], [D2COMPILERBIN=])
+
+# First, check for "--without-d" or "--with-d=no".
+if test x"${with_d}" = xno -o x"${with_alllang}" = xno ; then
+ AC_MSG_NOTICE([Disabling D])
+ D1COMPILER=
+ D2COMPILER=
+else
+ if test -z "$D1COMPILERBIN" ; then
+ AC_CHECK_PROGS(D1COMPILER, dmd ldmd gdmd)
+ else
+ D1COMPILER="$D1COMPILERBIN"
+ fi
+ if test -z "$D2COMPILERBIN" ; then
+ AC_CHECK_PROGS(D2COMPILER, dmd gdmd)
+ else
+ D2COMPILER="$D2COMPILERBIN"
+ fi
+fi
+
+# Do not prefix library file names with "lib" on Windows.
+case $host in
+*-*-cygwin* | *-*-mingw*) DLIBPREFIX="";;
+*)DLIBPREFIX="lib";;
+esac
+
+AC_SUBST(D1COMPILER)
+AC_SUBST(D2COMPILER)
+AC_SUBST(DLIBPREFIX)
+
+#----------------------------------------------------------------
# Determine which languages to use for examples/test-suite
#----------------------------------------------------------------
@@ -2172,6 +2208,12 @@ if test -z "$GO" ; then
fi
AC_SUBST(SKIP_GO)
+SKIP_D=
+if test -z "$D1COMPILER" && test -z "$D2COMPILER" ; then
+ SKIP_D="1"
+fi
+AC_SUBST(SKIP_D)
+
#----------------------------------------------------------------
# Additional language dependencies
#----------------------------------------------------------------
@@ -2232,6 +2274,7 @@ AC_CONFIG_FILES([ \
Examples/xml/Makefile \
Examples/test-suite/chicken/Makefile \
Examples/test-suite/csharp/Makefile \
+ Examples/test-suite/d/Makefile \
Examples/test-suite/guile/Makefile \
Examples/test-suite/guilescm/Makefile \
Examples/test-suite/java/Makefile \