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'."
This commit is contained in:
parent
9ca6f78b07
commit
04715f74e2
6 changed files with 29 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
7
Examples/test-suite/errors/pp_unknowndirective.i
Normal file
7
Examples/test-suite/errors/pp_unknowndirective.i
Normal file
|
|
@ -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;
|
||||
1
Examples/test-suite/errors/pp_unknowndirective.stderr
Normal file
1
Examples/test-suite/errors/pp_unknowndirective.stderr
Normal file
|
|
@ -0,0 +1 @@
|
|||
c_unknowndirective.i:7: Error: Unknown directive '%remane'.
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue