Commit 3149d272 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

widl: Print the import stack and context in messages.

parent 472b2eca
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
int parser_parse(void); int parser_parse(void);
extern void generic_msg( const struct location *where, const char *s, const char *t, va_list ap ); extern void parser_warning( const struct location *where, const char *message );
extern void parser_error( const struct location *where, const char *message ); extern void parser_error( const struct location *where, const char *message );
extern void init_location( struct location *copy, const struct location *begin, const struct location *end ); extern void init_location( struct location *copy, const struct location *begin, const struct location *end );
......
...@@ -461,6 +461,22 @@ SAFEARRAY{ws}*/\( return tSAFEARRAY; ...@@ -461,6 +461,22 @@ SAFEARRAY{ws}*/\( return tSAFEARRAY;
} }
%% %%
static void print_imports(void)
{
struct import_state *state, *next;
if (list_empty( &import_stack )) return;
fprintf( stderr, "In file included from " );
LIST_FOR_EACH_ENTRY_SAFE_REV( state, next, &import_stack, struct import_state, entry )
{
if (&next->entry == &import_stack) break;
fprintf( stderr, "%s:%d,\n", state->input_name, state->where.first_line );
fprintf( stderr, " from ");
}
fprintf( stderr, "%s:%d:\n", state->input_name, state->where.first_line );
}
void pop_import( struct location *where ) void pop_import( struct location *where )
{ {
struct list *entry = list_head( &import_stack ); struct list *entry = list_head( &import_stack );
...@@ -551,18 +567,6 @@ static void end_of_line( struct location *where ) ...@@ -551,18 +567,6 @@ static void end_of_line( struct location *where )
where->last_column = 1; where->last_column = 1;
} }
static const int want_near_indication = 0;
static void make_print(char *str)
{
while(*str)
{
if(!isprint(*str))
*str = ' ';
str++;
}
}
void init_location( struct location *where, const struct location *begin, const struct location *end ) void init_location( struct location *where, const struct location *begin, const struct location *end )
{ {
if (!begin) begin = &previous_location; if (!begin) begin = &previous_location;
...@@ -580,30 +584,39 @@ void init_location( struct location *where, const struct location *begin, const ...@@ -580,30 +584,39 @@ void init_location( struct location *where, const struct location *begin, const
} }
} }
void generic_msg( const struct location *where, const char *s, const char *t, va_list ap ) static void diagnostic( const struct location *where, const char *type, const char *message )
{ {
char buffer[1024], *line = NULL;
FILE *file;
int i;
if (!where) where = &previous_location; if (!where) where = &previous_location;
fprintf( stderr, "%s:%d: %s: ", where->input_name, where->first_line, t ); print_imports();
vfprintf( stderr, s, ap );
if (want_near_indication) fprintf( stderr, "%s:%d:%d: %s: %s\n", where->input_name, where->first_line, where->first_column, type, message );
{
char *cpy; if (!where->input_name || !(file = fopen( where->input_name, "r" ))) return;
if (where->near_text) for (i = 0; i < where->first_line; i++) if (!(line = fgets( buffer, sizeof(buffer), file ))) break;
{ fclose( file );
cpy = xstrdup( where->near_text ); if (!line) return;
make_print( cpy ); fprintf( stderr, "%s", line );
fprintf( stderr, " near '%s'", cpy );
free( cpy ); line = buffer;
} for (i = 0; i < where->first_column - 1; i++) line += sprintf( line, " " );
} line += sprintf( line, "^" );
for (i = where->first_column + 1; i < where->last_column; i++) line += sprintf( line, "~" );
fprintf( stderr, "%s\n", buffer );
} }
/* yyerror: yacc assumes this is not newline terminated. */
void parser_error( const struct location *where, const char *message ) void parser_error( const struct location *where, const char *message )
{ {
error_at( where, "%s\n", message ); diagnostic( where, "error", message );
}
void parser_warning( const struct location *where, const char *message )
{
diagnostic( where, "warning", message );
} }
static void warning_disable(int warning) static void warning_disable(int warning)
......
...@@ -34,10 +34,14 @@ ...@@ -34,10 +34,14 @@
void error_at( const struct location *where, const char *s, ... ) void error_at( const struct location *where, const char *s, ... )
{ {
char buffer[1024];
va_list ap; va_list ap;
va_start( ap, s ); va_start( ap, s );
generic_msg( where, s, "error", ap ); vsnprintf( buffer, sizeof(buffer), s, ap );
va_end( ap ); va_end( ap );
parser_error( where, buffer );
exit( 1 ); exit( 1 );
} }
...@@ -62,10 +66,14 @@ void warning(const char *s, ...) ...@@ -62,10 +66,14 @@ void warning(const char *s, ...)
void warning_at( const struct location *where, const char *s, ... ) void warning_at( const struct location *where, const char *s, ... )
{ {
char buffer[1024];
va_list ap; va_list ap;
va_start( ap, s ); va_start( ap, s );
generic_msg( where, s, "warning", ap ); vsnprintf( buffer, sizeof(buffer), s, ap );
va_end( ap ); va_end( ap );
parser_warning( where, buffer );
} }
void chat(const char *s, ...) void chat(const char *s, ...)
......
...@@ -313,7 +313,6 @@ enum type_basic_type ...@@ -313,7 +313,6 @@ enum type_basic_type
struct location struct location
{ {
const char *input_name; const char *input_name;
const char *near_text;
int first_line; int first_line;
int last_line; int last_line;
int first_column; int first_column;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment