Merge branch 'Sghirate-master' - C# -outfile option

* Sghirate-master:
  changes file update for -outfile
  Add in all C# command line options to the docs
  C# -outfile cosmetic code fixes
  [C#] Single file mode (fixes)
  [C#] Single file mode (minor fix)
  [C#] Single file mode

Conflicts:
	CHANGES.current
This commit is contained in:
William S Fulton 2015-06-11 07:53:30 +01:00
commit 6ab1ab57dd
3 changed files with 148 additions and 70 deletions

View file

@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.6 (in progress)
===========================
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.

View file

@ -13,6 +13,9 @@
<ul>
<li><a href="#CSharp_introduction_swig2_compatibility">SWIG 2 Compatibility</a>
</ul>
<ul>
<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>
<li><a href="#CSharp_arrays">C# Arrays</a>
@ -34,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>
@ -79,6 +82,60 @@ 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_commandline"></a>20.1.2 Additional command line options</H3>
<p>
The following table lists the additional commandline options available for the C# module. They can also be seen by using:
</p>
<div class="code"><pre>
swig -csharp -help
</pre></div>
<p></p>
<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>
@ -1682,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

@ -34,6 +34,7 @@ class CSHARP:public Language {
File *f_init;
File *f_directors;
File *f_directors_h;
File *f_single_out;
List *filenames_list;
bool proxy_flag; // Flag for generating proxy classes
@ -78,6 +79,7 @@ class CSHARP:public Language {
String *director_method_types; // Director method types
String *director_connect_parms; // Director delegates parameter list for director connect call
String *destructor_call; //C++ destructor call if any
String *output_file; // File name for single file mode. If set all generated code will be written to this file
// Director method stuff:
List *dmethods_seq;
@ -108,6 +110,7 @@ public:
f_init(NULL),
f_directors(NULL),
f_directors_h(NULL),
f_single_out(NULL),
filenames_list(NULL),
proxy_flag(true),
native_function_flag(false),
@ -150,6 +153,7 @@ public:
director_method_types(NULL),
director_connect_parms(NULL),
destructor_call(NULL),
output_file(NULL),
dmethods_seq(NULL),
dmethods_table(NULL),
n_dmethods(0),
@ -244,6 +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], "-help") == 0) {
Printf(stdout, "%s\n", usage);
}
@ -423,18 +437,7 @@ public:
}
// Generate the intermediary class
{
String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), imclass_name);
File *f_im = NewFile(filen, "w", SWIG_output_files());
if (!f_im) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
Append(filenames_list, Copy(filen));
Delete(filen);
filen = NULL;
// Start writing out the intermediary class file
emitBanner(f_im);
File *f_im = getOutputFile(SWIG_output_directory(), imclass_name);
addOpenNamespace(0, f_im);
@ -462,23 +465,14 @@ public:
Printf(f_im, "}\n");
addCloseNamespace(0, f_im);
Delete(f_im);
if (f_im != f_single_out)
Delete(f_im);
f_im = NULL;
}
// Generate the C# module class
{
String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), module_class_name);
File *f_module = NewFile(filen, "w", SWIG_output_files());
if (!f_module) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
Append(filenames_list, Copy(filen));
Delete(filen);
filen = NULL;
// Start writing out the module class file
emitBanner(f_module);
File *f_module = getOutputFile(SWIG_output_directory(), module_class_name);
addOpenNamespace(0, f_module);
@ -514,7 +508,9 @@ public:
Printf(f_module, "}\n");
addCloseNamespace(0, f_module);
Delete(f_module);
if (f_module != f_single_out)
Delete(f_module);
f_module = NULL;
}
if (upcasts_code)
@ -613,6 +609,12 @@ public:
f_directors_h = NULL;
}
if (f_single_out) {
Dump(f_single_out, f_begin);
Delete(f_single_out);
f_single_out = NULL;
}
Dump(f_wrappers, f_begin);
Wrapper_pretty_print(f_init, f_begin);
Delete(f_header);
@ -634,6 +636,50 @@ public:
Swig_banner_target_lang(f, "//");
Printf(f, "//------------------------------------------------------------------------------\n\n");
}
/* -----------------------------------------------------------------------------
* getOutputFile()
*
* Prepares a File object by creating the file in the file system and
* writing the banner for auto-generated files to it (emitBanner).
* If '-outfile' is provided (single file mode) the supplied parameters will
* be ignored and the returned file will always be:
* <outdir>/<outfile>
* Otherwise the file will be:
* <dir>/<name>.cs
* ----------------------------------------------------------------------------- */
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) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
Append(filenames_list, Copy(filen));
Delete(filen);
filen = NULL;
emitBanner(f_single_out);
}
return f_single_out;
} else {
String *filen = NewStringf("%s%s.cs", dir, name);
File *f = NewFile(filen, "w", SWIG_output_files());
if (!f) {
FileErrorDisplay(f);
SWIG_exit(EXIT_FAILURE);
}
Append(filenames_list, Copy(filen));
Delete(filen);
filen = NULL;
emitBanner(f);
return f;
}
}
/*-----------------------------------------------------------------------
* Add new director upcall signature
@ -1086,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")) {
@ -1198,18 +1244,7 @@ public:
} else {
// Global enums are defined in their own file
String *output_directory = outputDirectory(nspace);
String *filen = NewStringf("%s%s.cs", output_directory, symname);
File *f_enum = NewFile(filen, "w", SWIG_output_files());
if (!f_enum) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
Append(filenames_list, Copy(filen));
Delete(filen);
filen = NULL;
// Start writing out the enum file
emitBanner(f_enum);
File *f_enum = getOutputFile(output_directory, symname);
addOpenNamespace(nspace, f_enum);
@ -1217,7 +1252,9 @@ public:
"\n", enum_code, "\n", NIL);
addCloseNamespace(nspace, f_enum);
Delete(f_enum);
if (f_enum != f_single_out)
Delete(f_enum);
f_enum = NULL;
Delete(output_directory);
}
} else {
@ -1917,21 +1954,9 @@ public:
}
}
// Each outer proxy class goes into a separate file
if (!has_outerclass) {
String *output_directory = outputDirectory(nspace);
String *filen = NewStringf("%s%s.cs", output_directory, proxy_class_name);
f_proxy = NewFile(filen, "w", SWIG_output_files());
if (!f_proxy) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
Append(filenames_list, Copy(filen));
Delete(filen);
filen = NULL;
// Start writing out the proxy class file
emitBanner(f_proxy);
f_proxy = getOutputFile(output_directory, proxy_class_name);
addOpenNamespace(nspace, f_proxy);
}
@ -1991,7 +2016,8 @@ public:
if (!has_outerclass) {
Printf(f_proxy, "}\n");
addCloseNamespace(nspace, f_proxy);
Delete(f_proxy);
if (f_proxy != f_single_out)
Delete(f_proxy);
f_proxy = NULL;
} else {
for (int i = 0; i < nesting_depth; ++i)
@ -3216,18 +3242,7 @@ public:
Setline(n, line_number);
String *swigtype = NewString("");
String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), classname);
File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
if (!f_swigtype) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
Append(filenames_list, Copy(filen));
Delete(filen);
filen = NULL;
// Start writing out the type wrapper class file
emitBanner(f_swigtype);
File *f_swigtype = getOutputFile(SWIG_output_directory(), classname);
addOpenNamespace(0, f_swigtype);
@ -3262,8 +3277,9 @@ public:
Printv(f_swigtype, swigtype, NIL);
addCloseNamespace(0, f_swigtype);
Delete(f_swigtype);
if (f_swigtype != f_single_out)
Delete(f_swigtype);
f_swigtype = NULL;
Delete(swigtype);
Delete(n);
}
@ -4285,4 +4301,5 @@ C# Options (available with -csharp)\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";