diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2013-12-12 20:44:08 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2013-12-12 20:52:44 +0000 |
commit | 2121e1217eae19a0a3e852fc52c89f55faf7e20a (patch) | |
tree | 2ec3b78d0b5252b5ce76b048336afe3920608b20 /Source | |
parent | 3b4d33131096949e5dc3800a96760e096555db6b (diff) | |
download | swig-2121e1217eae19a0a3e852fc52c89f55faf7e20a.tar.gz |
Ensure -c++out is not used with -c++
Error checking for this combination implemented as well as correcting
Octave
Also refactor, replacing CPlusPlusOut variable with cparse_cplusplusout
for an implementation which more closely resembles cparse_cplusplus which
is also required in both .c and .cxx files.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CParse/cparse.h | 2 | ||||
-rw-r--r-- | Source/CParse/cscanner.c | 11 | ||||
-rw-r--r-- | Source/CParse/parser.y | 5 | ||||
-rw-r--r-- | Source/Modules/main.cxx | 12 | ||||
-rw-r--r-- | Source/Modules/nested.cxx | 2 | ||||
-rw-r--r-- | Source/Modules/octave.cxx | 6 | ||||
-rw-r--r-- | Source/Modules/swigmod.h | 1 | ||||
-rw-r--r-- | Source/Swig/cwrap.c | 5 |
8 files changed, 30 insertions, 14 deletions
diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index 19bf3f3f0..6d7342a45 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -25,9 +25,11 @@ extern "C" { extern String *cparse_file; extern int cparse_line; extern int cparse_cplusplus; + extern int cparse_cplusplusout; extern int cparse_start_line; extern void Swig_cparse_cplusplus(int); + extern void Swig_cparse_cplusplusout(int); extern void scanner_file(File *); extern void scanner_next_token(int); extern void skip_balanced(int startchar, int endchar); diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index ee2c49cd4..2dfc2c479 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -37,6 +37,9 @@ int cparse_start_line = 0; /* C++ mode */ int cparse_cplusplus = 0; +/* Generate C++ compatible code when wrapping C code */ +int cparse_cplusplusout = 0; + /* Private vars */ static int scan_init = 0; static int num_brace = 0; @@ -52,6 +55,14 @@ void Swig_cparse_cplusplus(int v) { cparse_cplusplus = v; } +/* ----------------------------------------------------------------------------- + * Swig_cparse_cplusplusout() + * ----------------------------------------------------------------------------- */ + +void Swig_cparse_cplusplusout(int v) { + cparse_cplusplusout = v; +} + /* ---------------------------------------------------------------------------- * scanner_init() * diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 8e34833e2..9b1cec387 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -59,7 +59,6 @@ static int extendmode = 0; static int compact_default_args = 0; static int template_reduce = 0; static int cparse_externc = 0; -extern int CPlusPlusOut; /* ----------------------------------------------------------------------------- * Assist Functions @@ -3446,7 +3445,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delete(prefix); inclass = 1; currentOuterClass = $<node>$; - if (CPlusPlusOut) { + if (cparse_cplusplusout) { /* save the structure declaration to declare it in global scope for C++ to see */ code = get_raw_text_balanced('{', '}'); Setattr($<node>$, "code", code); @@ -3577,7 +3576,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Namespaceprefix = Swig_symbol_qualifiedscopename(0); yyrename = Copy(Getattr($<node>$, "class_rename")); add_symbols($$); - if (!CPlusPlusOut) + if (!cparse_cplusplusout) Delattr($$, "nested:outer"); Delattr($$, "class_rename"); $$ = 0; diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index aa7e83ef8..f3aff2349 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -29,10 +29,6 @@ static Language *lang = 0; // Language method int CPlusPlus = 0; -extern "C" -{ - int CPlusPlusOut = 0; // Generate C++ compatible code when wrapping C code -} int Extend = 0; // Extend flag int ForceExtern = 0; // Force extern mode int GenerateDefault = 1; // Generate default constructors @@ -488,7 +484,8 @@ void SWIG_getoptions(int argc, char *argv[]) { Swig_cparse_cplusplus(1); Swig_mark_arg(i); } else if (strcmp(argv[i], "-c++out") == 0) { - CPlusPlusOut = 1; + // Undocumented + Swig_cparse_cplusplusout(1); Swig_mark_arg(i); } else if (strcmp(argv[i], "-fcompact") == 0) { Wrapper_compact_print_mode_set(1); @@ -955,6 +952,11 @@ int SWIG_main(int argc, char *argv[], Language *l) { // Don't check for an input file if -external-runtime is passed Swig_check_options(external_runtime ? 0 : 1); + if (CPlusPlus && cparse_cplusplusout) { + Printf(stderr, "The -c++out option is for C input but C++ input has been requested via -c++\n"); + SWIG_exit(EXIT_FAILURE); + } + install_opts(argc, argv); // Add language dependent directory to the search path diff --git a/Source/Modules/nested.cxx b/Source/Modules/nested.cxx index ff563b3ba..a62a9e9da 100644 --- a/Source/Modules/nested.cxx +++ b/Source/Modules/nested.cxx @@ -400,7 +400,7 @@ void Swig_nested_name_unnamed_c_structs(Node *n) { c = next; continue; } - } else if (CPlusPlusOut) { + } else if (cparse_cplusplusout) { if (Getattr(c, "nested:outer")) { Node *ins = create_insert(c, true); insertNodeAfter(c, ins); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 1c0192d07..14118972d 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include "swigmod.h" +#include "cparse.h" static String *global_name = 0; static String *op_prefix = 0; @@ -86,7 +87,6 @@ public: director_multiple_inheritance = 1; director_language = 1; docs = NewHash(); - CPlusPlusOut = 1; } virtual void main(int argc, char *argv[]) { @@ -133,6 +133,10 @@ public: SWIG_config_file("octave.swg"); SWIG_typemap_lang("octave"); allow_overloading(); + + // Octave API is C++, so output must be C++ compatibile even when wrapping C code + if (!cparse_cplusplus) + Swig_cparse_cplusplusout(1); } virtual int top(Node *n) { diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 41ef44e41..9e76b4d10 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -32,7 +32,6 @@ extern String *input_file; extern int line_number; extern int start_line; extern int CPlusPlus; // C++ mode -extern "C" int CPlusPlusOut; // generate C++ declarations for C code (currently used for Octave) extern int Extend; // Extend mode extern int Verbose; extern int IsVirtual; diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 03020bb72..04845f3cf 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -13,9 +13,8 @@ * ----------------------------------------------------------------------------- */ #include "swig.h" +#include "cparse.h" -extern int cparse_cplusplus; -extern int CPlusPlusOut; static const char *cresult_variable_name = "result"; static Parm *nonvoid_parms(Parm *p) { @@ -777,7 +776,7 @@ String *Swig_cmemberset_call(const_String_or_char_ptr name, SwigType *type, Stri if (!Strstr(type, "enum $unnamed")) { String *dref = Swig_wrapped_var_deref(type, pname1, varcref); int extra_cast = 0; - if (CPlusPlusOut) { + if (cparse_cplusplusout) { /* Required for C nested structs compiled as C++ as a duplicate of the nested struct is put into the global namespace. * We could improve this by adding the extra casts just for nested structs rather than all structs. */ String *base = SwigType_base(type); |