diff --git a/CHANGES.current b/CHANGES.current index 542f6c1a5..1b5d1f095 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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. diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index ba49fa004..0c0d98c0e 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -13,6 +13,9 @@
+Differences to the Java module+The following table lists the additional commandline options available for the C# module. They can also be seen by using: +
+ ++swig -csharp -help +
| C# specific options | +|
|---|---|
| -dllimport <dl> | +Override DllImport attribute name to <dl> | +
| -namespace <nm> | +Generate wrappers into C# namespace <nm> | +
| -noproxy | +Generate the low-level functional interface instead of proxy classes | +
| -oldvarnames | +Old intermediary method names for variable wrappers | +
| -outfile <file> | +Write all C# into a single <file> located in the output directory + | +
+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 -outfile for large projects. +
+
diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
index b251ff892..38afc7357 100644
--- a/Source/Modules/csharp.cxx
+++ b/Source/Modules/csharp.cxx
@@ -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:
+ *