Merge pull request #1 from swig/master

Integrate base
This commit is contained in:
Frederick Parotat 2015-06-15 11:47:24 +02:00
commit 0e60d17863
18 changed files with 217 additions and 65 deletions

View file

@ -54,6 +54,8 @@ matrix:
env: SWIGLANG=python SWIG_FEATURES=-O
- compiler: gcc
env: SWIGLANG=python SWIG_FEATURES=-classic
- compiler: gcc
env: SWIGLANG=r
- compiler: gcc
env: SWIGLANG=ruby
- compiler: gcc
@ -61,6 +63,9 @@ matrix:
- compiler: gcc
env: SWIGLANG=tcl
allow_failures:
# Lots of failing tests currently
- compiler: gcc
env: SWIGLANG=ocaml
# Occasional gcc internal compiler error
- compiler: gcc
env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8
@ -70,9 +75,9 @@ matrix:
# Not quite working yet
- compiler: gcc
env: SWIGLANG=python SWIG_FEATURES=-O
# Lots of failing tests currently
# Runtime errors in Travis environment
- compiler: gcc
env: SWIGLANG=ocaml
env: SWIGLANG=r
before_install:
- date -u
- uname -a
@ -96,6 +101,7 @@ before_install:
- if test "$SWIGLANG" = "python"; then git clone https://github.com/jcrocholl/pep8.git && pushd pep8 && git checkout tags/1.5.7 && python ./setup.py build && sudo python ./setup.py install && popd; fi
- if test "$SWIGLANG" = "python" -a "$PY3" -a -z "$VER"; then sudo apt-get install -qq python3-dev; fi
- if test "$SWIGLANG" = "python" -a "$VER"; then sudo add-apt-repository -y ppa:fkrull/deadsnakes && sudo apt-get -qq update && sudo apt-get -qq install python${VER}-dev && export CONFIGOPTS="--with-python${PY3}=python${VER}"; fi
- if test "$SWIGLANG" = "r"; then sudo apt-get -qq install r-base; fi
- if test "$SWIGLANG" = "scilab"; then sudo apt-get -qq install scilab; fi
- if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi
- $CC --version

View file

@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.6 (in progress)
===========================
2015-06-12: wsfulton
[R] Fix #430 - call to SWIG_createNewRef in copyToC was incorrectly named.
2015-06-11: sghirate
[C#] Patch #427 adds in new command line option -outfile to combine all the
generated C# code into a single file.
2015-06-09: wsfulton
Fix seg fault processing C++11 type aliasing. Issue #424.
2015-05-28: wsfulton
[Python] Add new feature "python:cdefaultargs" to control default argument
code generation. By default, SWIG attempts to convert C/C++ default argument values

View file

@ -14,7 +14,7 @@
<li><a href="#CSharp_introduction_swig2_compatibility">SWIG 2 Compatibility</a>
</ul>
<ul>
<li><a href="#CSharp_introduction_command_line_options">C# Command Line Options</a>
<li><a href="#CSharp_commandline">Additional command line options</a>
</ul
<li><a href="#CSharp_differences_java">Differences to the Java module</a>
<li><a href="#CSharp_void_pointers">Void pointers</a>
@ -37,7 +37,7 @@
<li><a href="#CSharp_directors_implementation">Directors implementation</a>
<li><a href="#CSharp_director_caveats">Director caveats</a>
</ul>
<li><a href="#CSharp_multiple_modules">Multiples modules</a>
<li><a href="#CSharp_multiple_modules">Multiple modules</a>
<li><a href="#CSharp_typemap_examples">C# Typemap examples</a>
<ul>
<li><a href="#CSharp_memory_management_member_variables">Memory management when returning references to member variables</a>
@ -82,26 +82,58 @@ Monodoc, available from the Mono project, has a very useful section titled <a hr
In order to minimize name collisions between names generated based on input to SWIG and names used in the generated code from the .NET framework, SWIG 3 fully qualifies the use of all .NET types. Furthermore, SWIG 3 avoids <tt>using</tt> directives in generated code. This breaks backwards compatibility with typemaps, pragmas, etc written for use with SWIG 2 that assume the presence of <tt>using System;</tt> or <tt>using System.Runtime.InteropServices;</tt> directives in the intermediate class imports, module imports, or proxy imports. SWIG 3 supports backwards compatibility though the use of the <tt>SWIG2_CSHARP</tt> macro. If <tt>SWIG2_CSHARP</tt> is defined, SWIG 3 generates <tt>using</tt> directives in the intermediate class, module class, and proxy class code similar to those generated by SWIG 2. This can be done without modifying any of the input code by passing the <tt>-DSWIG2_CSHARP</tt> commandline parameter when executing <tt>swig</tt>.
</p>
<H3><a name="CSharp_introduction_command_line_options"></a>20.1.2 C# Command Line Options</H3>
<p>Additional command line options that can be used to control code generation:</p>
<H3><a name="CSharp_commandline"></a>20.1.2 Additional command line options</H3>
<p>
<b><tt>-outfile &lt;filename&gt;</tt></b><br>
This command line will instruct the C# module to write all generated C# code to &lt;filename&gt; (located in the output directory) instead of creating separate files for generated classes.<br/>
Caveats:
<ul>
The following table lists the additional commandline options available for the C# module. They can also be seen by using:
</p>
<li>
The file extension (.cs) will not be automatically be added and needs to be provided.
</li>
<div class="code"><pre>
swig -csharp -help
</pre></div>
<li>
Due to possible compiler limits it is not advisable to use <tt>-outfile</tt> when generating wrappers for big projects.
</li>
<p></p>
</ul>
<table summary="C# specific options">
<tr>
<th>C# specific options</th>
</tr>
<tr>
<td>-dllimport &lt;dl&gt;</td>
<td>Override DllImport attribute name to &lt;dl&gt;</td>
</tr>
<tr>
<td>-namespace &lt;nm&gt;</td>
<td>Generate wrappers into C# namespace &lt;nm&gt;</td>
</tr>
<tr>
<td>-noproxy</td>
<td>Generate the low-level functional interface instead of proxy classes</td>
</tr>
<tr>
<td>-oldvarnames</td>
<td>Old intermediary method names for variable wrappers</td>
</tr>
<tr>
<td>-outfile &lt;file&gt;</td>
<td>Write all C# into a single &lt;file&gt; located in the output directory
</td>
</tr>
</table>
<p>
The -outfile option combines all the generated C# code into a single output file instead of creating multiple C# files.
The default, when this option is not provided, is to generate separate .cs files for the module class,
intermediary class and each of the generated proxy and type wrapper classes.
Note that the file extension (.cs) will not be automatically added and needs to be provided.
Due to possible compiler limits it is not advisable to use <tt>-outfile</tt> for large projects.
</p>
<H2><a name="CSharp_differences_java"></a>20.2 Differences to the Java module</H2>
@ -1707,7 +1739,7 @@ However, a call from C# to <tt>CSharpDefaults.DefaultMethod()</tt> will of cours
should pass the call on to <tt>CSharpDefaults.DefaultMethod(int)</tt>using the C++ default value, as shown above.
</p>
<H2><a name="CSharp_multiple_modules"></a>20.7 Multiples modules</H2>
<H2><a name="CSharp_multiple_modules"></a>20.7 Multiple modules</H2>
<p>

View file

@ -457,6 +457,12 @@ be used on any platform. Again, this is an important part of staying out
of the programmer's way----the last thing any developer wants to do is
to spend their time debugging the output of a tool that relies on
non-portable or unreliable programming features.
Dependencies are often a source of incompatibilities and problems and so
additional third party libraries are not used in the generated code.
SWIG will also generally avoid generating code that introduces a dependency
on the C++ Standard Template Library (STL).
SWIG will generate code that depends on the C libraries though.
</p>
</body>
</html>

View file

@ -146,7 +146,8 @@ can be obtained by typing <tt>swig -help</tt> or <tt>swig
-I<em>dir</em> Add a directory to the file include path
-l<em>file</em> Include a SWIG library file.
-module <em>name</em> Set the name of the SWIG module
-o <em>outfile</em> Name of output file
-o <em>outfile</em> Set name of C/C++ output file to &lt;outfile&gt;
-oh <em>headfile</em> Set name of C++ output header file for directors to &lt;headfile&gt;
-outcurrentdir Set default output dir to current dir instead of input file's path
-outdir <em>dir</em> Set language specific files output directory
-pcreversion Display PCRE version information
@ -212,7 +213,7 @@ additional files depending on the target language. By default, an input file
with the name <tt>file.i</tt> is transformed into a file
<tt>file_wrap.c</tt> or <tt>file_wrap.cxx</tt> (depending on whether
or not the <tt>-c++</tt> option has been used). The name of the
output file can be changed using the <tt>-o</tt> option. In certain
output C/C++ file can be changed using the <tt>-o</tt> option. In certain
cases, file suffixes are used by the compiler to determine the source
language (C, C++, etc.). Therefore, you have to use the
<tt>-o</tt> option to change the suffix of the SWIG-generated wrapper

View file

@ -543,6 +543,7 @@ CPP11_TEST_CASES = \
cpp11_template_explicit \
cpp11_template_typedefs \
cpp11_type_traits \
cpp11_type_aliasing \
cpp11_uniform_initialization \
cpp11_unrestricted_unions \
cpp11_userdefined_literals \

View file

@ -0,0 +1,46 @@
%module cpp11_type_aliasing
// Type aliasing seg fault : Github issue #424
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Target;
%inline %{
namespace Halide {
struct Target {
int bits;
Target(int bits=32) : bits(bits) {}
};
class NamesInterface {
public:
using Target = Halide::Target;
};
Target get_host_target() {
return Target();
}
namespace Internal {
template <typename T> class GeneratorParam {
T value;
public:
GeneratorParam(const char *name, const T &v) : value(v) {}
T getValue() {
return value;
}
};
class GeneratorBase : public NamesInterface {
public:
GeneratorParam<Target> target{ "target", Halide::get_host_target() };
};
}
}
%}
%template(Halide_Target) Halide::Internal::GeneratorParam<Halide::Target>;

View file

@ -0,0 +1,13 @@
%module cpp_using_type_aliasing
namespace Space {
template<typename T> struct Okay {
};
struct User {
protected:
using OkayInt = Okay<int>;
};
struct Derived : User {
Okay<OkayInt> ff();
};
};

View file

@ -0,0 +1,3 @@
cpp_using_type_aliasing.i:8: Warning 341: The 'using' keyword in type aliasing is not fully supported yet.
cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'.
cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'.

View file

@ -0,0 +1,20 @@
import cpp11_type_aliasing.*;
public class cpp11_type_aliasing_runme {
static {
try {
System.loadLibrary("cpp11_type_aliasing");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) {
Halide_Target ht = new GeneratorBase().getTarget();
Target x = ht.getValue();
if (x.getBits() != 32)
throw new RuntimeException("Incorrect bits");
}
}

View file

@ -3,6 +3,7 @@
*/
#define RKW(x) %keywordwarn("'" `x` "' is a R keyword, renaming to '_" `x`"'", rename="_%s") `x`
#define RSWIGKW(x) %keywordwarn("'" `x` "' is a SWIG R reserved parameter name, renaming to '_" `x`"'", rename="_%s") `x`
/*
Warnings for R reserved words taken from
@ -29,4 +30,7 @@ RKW(NA_real_);
RKW(NA_complex_);
RKW(NA_character_);
RSWIGKW(self);
#undef RKW
#undef RSWIGKW

View file

@ -62,7 +62,7 @@ function(className, ..., append = TRUE)
if(!isGeneric("copyToC"))
setGeneric("copyToC",
function(value, obj = RSWIG_createNewRef(class(value)))
function(value, obj = SWIG_createNewRef(class(value)))
standardGeneric("copyToC"
))
@ -147,4 +147,4 @@ function(fun, userData = NULL)
}
#######################################################################
#######################################################################

View file

@ -2850,10 +2850,10 @@ c_declaration : c_decl {
Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line, "Lambda expressions and closures are not fully supported yet.\n");
SWIG_WARN_NODE_END($$);
}
| USING idcolon EQUAL {
skip_decl();
| USING idcolon EQUAL idcolon {
$$ = new_node("using");
Setattr($$,"name",$2);
Setattr($$,"uname",$4);
add_symbols($$);
SWIG_WARN_NODE_BEGIN($$);
Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line, "The 'using' keyword in type aliasing is not fully supported yet.\n");

View file

@ -248,16 +248,16 @@ public:
} else if (strcmp(argv[i], "-oldvarnames") == 0) {
Swig_mark_arg(i);
old_variable_names = true;
} else if (strcmp(argv[i], "-outfile") == 0) {
if (argv[i + 1]) {
output_file = NewString("");
Printf(output_file, argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-outfile") == 0) {
if (argv[i + 1]) {
output_file = NewString("");
Printf(output_file, argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-help") == 0) {
Printf(stdout, "%s\n", usage);
}
@ -465,7 +465,7 @@ public:
Printf(f_im, "}\n");
addCloseNamespace(0, f_im);
if(f_im != f_single_out)
if (f_im != f_single_out)
Delete(f_im);
f_im = NULL;
}
@ -508,7 +508,7 @@ public:
Printf(f_module, "}\n");
addCloseNamespace(0, f_module);
if(f_module != f_single_out)
if (f_module != f_single_out)
Delete(f_module);
f_module = NULL;
}
@ -609,7 +609,7 @@ public:
f_directors_h = NULL;
}
if(f_single_out) {
if (f_single_out) {
Dump(f_single_out, f_begin);
Delete(f_single_out);
f_single_out = NULL;
@ -636,7 +636,7 @@ public:
Swig_banner_target_lang(f, "//");
Printf(f, "//------------------------------------------------------------------------------\n\n");
}
/* -----------------------------------------------------------------------------
* getOutputFile()
*
@ -649,12 +649,12 @@ public:
* <dir>/<name>.cs
* ----------------------------------------------------------------------------- */
File *getOutputFile(const String* dir, String* name) {
if(output_file) {
if(!f_single_out) {
File *getOutputFile(const String *dir, const String *name) {
if (output_file) {
if (!f_single_out) {
String *filen = NewStringf("%s%s", SWIG_output_directory(), output_file);
f_single_out = NewFile(filen, "w", SWIG_output_files());
if(!f_single_out) {
if (!f_single_out) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
@ -668,7 +668,7 @@ public:
} else {
String *filen = NewStringf("%s%s.cs", dir, name);
File *f = NewFile(filen, "w", SWIG_output_files());
if(!f) {
if (!f) {
FileErrorDisplay(f);
SWIG_exit(EXIT_FAILURE);
}
@ -1132,7 +1132,7 @@ public:
scope = NewString("");
if (nspace)
Printf(scope, "%s", nspace);
if (Node* cls = getCurrentClass()) {
if (Node *cls = getCurrentClass()) {
if (Node *outer = Getattr(cls, "nested:outer")) {
String *outerClassesPrefix = Copy(Getattr(outer, "sym:name"));
for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) {
@ -1252,7 +1252,7 @@ public:
"\n", enum_code, "\n", NIL);
addCloseNamespace(nspace, f_enum);
if(f_enum != f_single_out)
if (f_enum != f_single_out)
Delete(f_enum);
f_enum = NULL;
Delete(output_directory);
@ -1954,7 +1954,6 @@ public:
}
}
// Each outer proxy class goes into a separate file
if (!has_outerclass) {
String *output_directory = outputDirectory(nspace);
f_proxy = getOutputFile(output_directory, proxy_class_name);
@ -2017,7 +2016,7 @@ public:
if (!has_outerclass) {
Printf(f_proxy, "}\n");
addCloseNamespace(nspace, f_proxy);
if(f_proxy != f_single_out)
if (f_proxy != f_single_out)
Delete(f_proxy);
f_proxy = NULL;
} else {
@ -3278,7 +3277,7 @@ public:
Printv(f_swigtype, swigtype, NIL);
addCloseNamespace(0, f_swigtype);
if(f_swigtype != f_single_out)
if (f_swigtype != f_single_out)
Delete(f_swigtype);
f_swigtype = NULL;
Delete(swigtype);
@ -3376,7 +3375,7 @@ public:
/* -----------------------------------------------------------------------------
* outputDirectory()
*
* Return the directory to use for generating Java classes/enums and create the
* Return the directory to use for generating C# classes/enums and create the
* subdirectory (does not create if language specific outdir does not exist).
* ----------------------------------------------------------------------------- */
@ -3516,7 +3515,7 @@ public:
* classDirectorMethod()
*
* Emit a virtual director method to pass a method call on to the
* underlying Java object.
* underlying C# object.
*
* --------------------------------------------------------------- */
@ -3677,7 +3676,7 @@ public:
if (!ignored_method)
Printf(w->code, "} else {\n");
/* Go through argument list, convert from native to Java */
/* Go through argument list, convert from native to C# */
for (i = 0, p = l; p; ++i) {
/* Is this superfluous? */
while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
@ -4297,10 +4296,10 @@ extern "C" Language *swig_csharp(void) {
const char *CSHARP::usage = "\
C# Options (available with -csharp)\n\
-dllimport <dl> - Override DllImport attribute name to <dl>\n\
-namespace <nm> - Generate wrappers into C# namespace <nm>\n\
-noproxy - Generate the low-level functional interface instead\n\
of proxy classes\n\
-oldvarnames - Old intermediary method names for variable wrappers\n\
-outfile <filename> - Write all C# to a single file <filename> located in the output directory\n\
-dllimport <dl> - Override DllImport attribute name to <dl>\n\
-namespace <nm> - Generate wrappers into C# namespace <nm>\n\
-noproxy - Generate the low-level functional interface instead\n\
of proxy classes\n\
-oldvarnames - Old intermediary method names for variable wrappers\n\
-outfile <file> - Write all C# into a single <file> located in the output directory\n\
\n";

View file

@ -131,8 +131,8 @@ static const char *usage3 = (const char *) "\
static const char *usage4 = (const char *) "\
-O - Enable the optimization options: \n\
-fastdispatch -fvirtual \n\
-o <outfile> - Set name of the output file to <outfile>\n\
-oh <headfile> - Set name of the output header file to <headfile>\n\
-o <outfile> - Set name of C/C++ output file to <outfile>\n\
-oh <headfile> - Set name of C++ output header file for directors to <headfile>\n\
-outcurrentdir - Set default output dir to current dir instead of input file's path\n\
-outdir <dir> - Set language specific files output directory to <dir>\n\
-pcreversion - Display PCRE version information\n\

View file

@ -281,6 +281,7 @@ public:
void dispatchFunction(Node *n);
int functionWrapper(Node *n);
int constantWrapper(Node *n);
int variableWrapper(Node *n);
int classDeclaration(Node *n);
@ -2181,6 +2182,16 @@ int R::functionWrapper(Node *n) {
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* R::constantWrapper()
* ---------------------------------------------------------------------- */
int R::constantWrapper(Node *n) {
(void) n;
// TODO
return SWIG_OK;
}
/*****************************************************
Add the specified routine name to the collection of
generated routines that are called from R functions.

View file

@ -1149,7 +1149,7 @@ Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) {
Symtab *un = Getattr(s, "sym:symtab");
Node *ss = (!Equal(name, uname) || (un != n)) ? Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */
if (!ss) {
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
}
s = ss;
}
@ -1221,7 +1221,7 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (*
Node *ss;
ss = Swig_symbol_clookup(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
if (!ss && !checkfunc) {
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
}
s = ss;
}
@ -1272,7 +1272,7 @@ Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) {
while (s && Checkattr(s, "nodeType", "using")) {
Node *ss = Swig_symbol_clookup_local(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
if (!ss) {
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
}
s = ss;
}
@ -1320,7 +1320,7 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n,
while (s && Checkattr(s, "nodeType", "using")) {
Node *ss = Swig_symbol_clookup_local_check(Getattr(s, "uname"), Getattr(s, "sym:symtab"), checkfunc);
if (!ss && !checkfunc) {
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
}
s = ss;
}

View file

@ -1,5 +1,5 @@
os:
- Unstable
- Windows Server 2012 R2
platform:
- x86