diff --git a/CHANGES.current b/CHANGES.current index a5b700cf4..115a1b511 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.4 (in progress) =========================== +2015-01-08: olly + Improve error message when an unknown SWIG directive is used - this + previously gave the cryptic "Error: Syntax error in input(1).", but + now gives "Error: Unknown directive '%foo'." + 2015-01-08: olly Provide -cppext as a general command line option for setting the extension used for generated C++ files (previously it was specific diff --git a/Examples/test-suite/errors/pp_unknowndirective.i b/Examples/test-suite/errors/pp_unknowndirective.i new file mode 100644 index 000000000..659a997d3 --- /dev/null +++ b/Examples/test-suite/errors/pp_unknowndirective.i @@ -0,0 +1,7 @@ +%module xxx + +/* This used to give the rather cryptic "Syntax error in input(1)." prior to + * SWIG 3.0.4. This testcase checks that the improved message is actually + * issued. + */ +%remane("typo") tyop; diff --git a/Examples/test-suite/errors/pp_unknowndirective.stderr b/Examples/test-suite/errors/pp_unknowndirective.stderr new file mode 100644 index 000000000..4506c5cf4 --- /dev/null +++ b/Examples/test-suite/errors/pp_unknowndirective.stderr @@ -0,0 +1 @@ +c_unknowndirective.i:7: Error: Unknown directive '%remane'. diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index 5a0d52d23..84a486fb7 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -27,6 +27,7 @@ extern "C" { extern int cparse_cplusplus; extern int cparse_cplusplusout; extern int cparse_start_line; + extern String *cparse_unknown_directive; extern void Swig_cparse_cplusplus(int); extern void Swig_cparse_cplusplusout(int); diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index d9a17b874..d86c4590a 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -40,6 +40,9 @@ int cparse_cplusplus = 0; /* Generate C++ compatible code when wrapping C code */ int cparse_cplusplusout = 0; +/* To allow better error reporting */ +String *cparse_unknown_directive = 0; + /* Private vars */ static int scan_init = 0; static int num_brace = 0; @@ -801,8 +804,11 @@ int yylex(void) { if (strcmp(yytext, "inline") == 0) return (yylex()); - /* SWIG directives */ } else { + Delete(cparse_unknown_directive); + cparse_unknown_directive = NULL; + + /* SWIG directives */ if (strcmp(yytext, "%module") == 0) return (MODULE); if (strcmp(yytext, "%insert") == 0) @@ -878,6 +884,9 @@ int yylex(void) { } if (strcmp(yytext, "%warn") == 0) return (WARN); + + /* Note down the apparently unknown directive for error reporting. */ + cparse_unknown_directive = Swig_copy_string(yytext); } /* Have an unknown identifier, as a last step, we'll do a typedef lookup on it. */ diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1566bafec..4bee5f127 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1510,7 +1510,11 @@ declaration : swig_directive { $$ = $1; } | SEMI { $$ = 0; } | error { $$ = 0; - Swig_error(cparse_file, cparse_line,"Syntax error in input(1).\n"); + if (cparse_unknown_directive) { + Swig_error(cparse_file, cparse_line, "Unknown directive '%s'.\n", cparse_unknown_directive); + } else { + Swig_error(cparse_file, cparse_line, "Syntax error in input(1).\n"); + } exit(1); } /* Out of class constructor/destructor declarations */