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.
This commit is contained in:
parent
3b4d331310
commit
2121e1217e
8 changed files with 30 additions and 14 deletions
|
|
@ -25,9 +25,11 @@ extern "C" {
|
||||||
extern String *cparse_file;
|
extern String *cparse_file;
|
||||||
extern int cparse_line;
|
extern int cparse_line;
|
||||||
extern int cparse_cplusplus;
|
extern int cparse_cplusplus;
|
||||||
|
extern int cparse_cplusplusout;
|
||||||
extern int cparse_start_line;
|
extern int cparse_start_line;
|
||||||
|
|
||||||
extern void Swig_cparse_cplusplus(int);
|
extern void Swig_cparse_cplusplus(int);
|
||||||
|
extern void Swig_cparse_cplusplusout(int);
|
||||||
extern void scanner_file(File *);
|
extern void scanner_file(File *);
|
||||||
extern void scanner_next_token(int);
|
extern void scanner_next_token(int);
|
||||||
extern void skip_balanced(int startchar, int endchar);
|
extern void skip_balanced(int startchar, int endchar);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,9 @@ int cparse_start_line = 0;
|
||||||
/* C++ mode */
|
/* C++ mode */
|
||||||
int cparse_cplusplus = 0;
|
int cparse_cplusplus = 0;
|
||||||
|
|
||||||
|
/* Generate C++ compatible code when wrapping C code */
|
||||||
|
int cparse_cplusplusout = 0;
|
||||||
|
|
||||||
/* Private vars */
|
/* Private vars */
|
||||||
static int scan_init = 0;
|
static int scan_init = 0;
|
||||||
static int num_brace = 0;
|
static int num_brace = 0;
|
||||||
|
|
@ -52,6 +55,14 @@ void Swig_cparse_cplusplus(int v) {
|
||||||
cparse_cplusplus = v;
|
cparse_cplusplus = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* Swig_cparse_cplusplusout()
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void Swig_cparse_cplusplusout(int v) {
|
||||||
|
cparse_cplusplusout = v;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* scanner_init()
|
* scanner_init()
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,6 @@ static int extendmode = 0;
|
||||||
static int compact_default_args = 0;
|
static int compact_default_args = 0;
|
||||||
static int template_reduce = 0;
|
static int template_reduce = 0;
|
||||||
static int cparse_externc = 0;
|
static int cparse_externc = 0;
|
||||||
extern int CPlusPlusOut;
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Assist Functions
|
* Assist Functions
|
||||||
|
|
@ -3446,7 +3445,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
Delete(prefix);
|
Delete(prefix);
|
||||||
inclass = 1;
|
inclass = 1;
|
||||||
currentOuterClass = $<node>$;
|
currentOuterClass = $<node>$;
|
||||||
if (CPlusPlusOut) {
|
if (cparse_cplusplusout) {
|
||||||
/* save the structure declaration to declare it in global scope for C++ to see */
|
/* save the structure declaration to declare it in global scope for C++ to see */
|
||||||
code = get_raw_text_balanced('{', '}');
|
code = get_raw_text_balanced('{', '}');
|
||||||
Setattr($<node>$, "code", code);
|
Setattr($<node>$, "code", code);
|
||||||
|
|
@ -3577,7 +3576,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||||
yyrename = Copy(Getattr($<node>$, "class_rename"));
|
yyrename = Copy(Getattr($<node>$, "class_rename"));
|
||||||
add_symbols($$);
|
add_symbols($$);
|
||||||
if (!CPlusPlusOut)
|
if (!cparse_cplusplusout)
|
||||||
Delattr($$, "nested:outer");
|
Delattr($$, "nested:outer");
|
||||||
Delattr($$, "class_rename");
|
Delattr($$, "class_rename");
|
||||||
$$ = 0;
|
$$ = 0;
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,6 @@
|
||||||
|
|
||||||
static Language *lang = 0; // Language method
|
static Language *lang = 0; // Language method
|
||||||
int CPlusPlus = 0;
|
int CPlusPlus = 0;
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
int CPlusPlusOut = 0; // Generate C++ compatible code when wrapping C code
|
|
||||||
}
|
|
||||||
int Extend = 0; // Extend flag
|
int Extend = 0; // Extend flag
|
||||||
int ForceExtern = 0; // Force extern mode
|
int ForceExtern = 0; // Force extern mode
|
||||||
int GenerateDefault = 1; // Generate default constructors
|
int GenerateDefault = 1; // Generate default constructors
|
||||||
|
|
@ -488,7 +484,8 @@ void SWIG_getoptions(int argc, char *argv[]) {
|
||||||
Swig_cparse_cplusplus(1);
|
Swig_cparse_cplusplus(1);
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i], "-c++out") == 0) {
|
} else if (strcmp(argv[i], "-c++out") == 0) {
|
||||||
CPlusPlusOut = 1;
|
// Undocumented
|
||||||
|
Swig_cparse_cplusplusout(1);
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i], "-fcompact") == 0) {
|
} else if (strcmp(argv[i], "-fcompact") == 0) {
|
||||||
Wrapper_compact_print_mode_set(1);
|
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
|
// Don't check for an input file if -external-runtime is passed
|
||||||
Swig_check_options(external_runtime ? 0 : 1);
|
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);
|
install_opts(argc, argv);
|
||||||
|
|
||||||
// Add language dependent directory to the search path
|
// Add language dependent directory to the search path
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ void Swig_nested_name_unnamed_c_structs(Node *n) {
|
||||||
c = next;
|
c = next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (CPlusPlusOut) {
|
} else if (cparse_cplusplusout) {
|
||||||
if (Getattr(c, "nested:outer")) {
|
if (Getattr(c, "nested:outer")) {
|
||||||
Node *ins = create_insert(c, true);
|
Node *ins = create_insert(c, true);
|
||||||
insertNodeAfter(c, ins);
|
insertNodeAfter(c, ins);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#include "swigmod.h"
|
#include "swigmod.h"
|
||||||
|
#include "cparse.h"
|
||||||
|
|
||||||
static String *global_name = 0;
|
static String *global_name = 0;
|
||||||
static String *op_prefix = 0;
|
static String *op_prefix = 0;
|
||||||
|
|
@ -86,7 +87,6 @@ public:
|
||||||
director_multiple_inheritance = 1;
|
director_multiple_inheritance = 1;
|
||||||
director_language = 1;
|
director_language = 1;
|
||||||
docs = NewHash();
|
docs = NewHash();
|
||||||
CPlusPlusOut = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void main(int argc, char *argv[]) {
|
virtual void main(int argc, char *argv[]) {
|
||||||
|
|
@ -133,6 +133,10 @@ public:
|
||||||
SWIG_config_file("octave.swg");
|
SWIG_config_file("octave.swg");
|
||||||
SWIG_typemap_lang("octave");
|
SWIG_typemap_lang("octave");
|
||||||
allow_overloading();
|
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) {
|
virtual int top(Node *n) {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ extern String *input_file;
|
||||||
extern int line_number;
|
extern int line_number;
|
||||||
extern int start_line;
|
extern int start_line;
|
||||||
extern int CPlusPlus; // C++ mode
|
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 Extend; // Extend mode
|
||||||
extern int Verbose;
|
extern int Verbose;
|
||||||
extern int IsVirtual;
|
extern int IsVirtual;
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,8 @@
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#include "swig.h"
|
#include "swig.h"
|
||||||
|
#include "cparse.h"
|
||||||
|
|
||||||
extern int cparse_cplusplus;
|
|
||||||
extern int CPlusPlusOut;
|
|
||||||
static const char *cresult_variable_name = "result";
|
static const char *cresult_variable_name = "result";
|
||||||
|
|
||||||
static Parm *nonvoid_parms(Parm *p) {
|
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")) {
|
if (!Strstr(type, "enum $unnamed")) {
|
||||||
String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
|
String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
|
||||||
int extra_cast = 0;
|
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.
|
/* 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. */
|
* We could improve this by adding the extra casts just for nested structs rather than all structs. */
|
||||||
String *base = SwigType_base(type);
|
String *base = SwigType_base(type);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue