From 2acc32946bdbe57f58b66b176849a9ecd78dc6ba Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Mon, 5 Dec 2005 22:10:37 +0000 Subject: [PATCH] add option/pragma erroraswarn, which force (or not) to treat the cpp #error directive as a #warning instead git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7926 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/main.cxx | 13 +++++++++++++ Source/Preprocessor/cpp.c | 16 ++++++++++++++-- Source/Preprocessor/preprocessor.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 950d2bf31..c6fa3e934 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -67,6 +67,7 @@ static const char *usage1 = (const char*)"\ -ignoremissing - Ignore missing include files\n\ -importall - Follow all #include statements as imports\n\ -includeall - Follow all #include statements\n\ + -erroraswarn - Treat (or not) the CPP #error statement as #warning instead\n\ -l - Include SWIG library file \n\ -M - List all dependencies \n\ -MD - Is equivalent to `-M -MF ', except `-E' is not implied\n\ @@ -517,6 +518,18 @@ void SWIG_getoptions(int argc, char *argv[]) } else if (strcmp(argv[i],"-ignoremissing") == 0) { Preprocessor_ignore_missing(1); Swig_mark_arg(i); + } else if (strcmp(argv[i],"-erroraswarn") == 0) { + String *erroraswarn = 0; + Swig_mark_arg(i); + if (argv[i+1]) { + erroraswarn = NewString(argv[i+1]); + Swig_mark_arg(i+1); + } + if (!erroraswarn) { + Swig_arg_error(); + } else { + Preprocessor_error_as_warning(atoi(Char(erroraswarn))); + } } else if (strcmp(argv[i],"-tm_debug") == 0) { tm_debug = 1; Swig_mark_arg(i); diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 6e12da1c1..43f6a730d 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -30,6 +30,7 @@ static int single_include = 1; /* Only include each file once */ static Hash *included_files = 0; static List *dependencies = 0; static SwigScanner *id_scan = 0; +static int error_as_warning = 0; /* Understand the cpp #error directive as a #warning */ /* Test a character to see if it starts an identifier */ #define isidentifier(c) ((isalpha(c)) || (c == '_') || (c == '$')) @@ -247,6 +248,10 @@ void Preprocessor_ignore_missing(int a) { ignore_missing = a; } +void Preprocessor_error_as_warning(int a) { + error_as_warning = a; +} + /* ----------------------------------------------------------------------------- * Preprocessor_define() @@ -1520,7 +1525,11 @@ Preprocessor_parse(String *s) } } else if (StringEqual(id,k_error)) { if (allow) { - Swig_error(Getfile(s),Getline(id),"%s\n",value); + if (error_as_warning) { + Swig_warning(WARN_PP_CPP_WARNING,Getfile(s),Getline(id),"%s\n", value); + } else { + Swig_error(Getfile(s),Getline(id),"%s\n",value); + } } } else if (StringEqual(id,k_line)) { } else if (StringEqual(id,k_include)) { @@ -1568,9 +1577,12 @@ Preprocessor_parse(String *s) char *c = Char(value)+5; while (*c && (isspace((int)*c))) c++; if (*c) { - if (Strncmp(c,"nowarn=",7) == 0) { + if (strncmp(c,"nowarn=",7) == 0) { Swig_warnfilter(c+7,1); } + else if (strncmp(c,"erroraswarn=",7) == 0) { + error_as_warning = atoi(c+12); + } } } } else if (StringEqual(id,k_level)) { diff --git a/Source/Preprocessor/preprocessor.h b/Source/Preprocessor/preprocessor.h index 778c1c912..894f257d3 100644 --- a/Source/Preprocessor/preprocessor.h +++ b/Source/Preprocessor/preprocessor.h @@ -29,6 +29,7 @@ extern String *Preprocessor_parse(String *s); extern void Preprocessor_include_all(int); extern void Preprocessor_import_all(int); extern void Preprocessor_ignore_missing(int); +extern void Preprocessor_error_as_warning(int); extern List *Preprocessor_depend(void); extern void Preprocessor_expr_init(void); extern void Preprocessor_expr_delete(void);