Commit 2edd194a authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

widl: Move diagnostic and location functions to parser.l.

parent be1e3082
......@@ -21,16 +21,19 @@
#ifndef __WIDL_PARSER_H
#define __WIDL_PARSER_H
#include "widltypes.h"
int parser_parse(void);
extern void generic_msg( const struct location *where, const char *s, const char *t, va_list ap );
extern void parser_error( const char *message );
extern void init_location( struct location *where );
extern FILE *parser_in;
extern char *parser_text;
extern int parser_debug;
extern int yy_flex_debug;
extern int parse_only;
void push_import( char *import_name );
void pop_import(void);
int is_type(const char *name);
......
......@@ -78,6 +78,7 @@ struct import
struct list entry;
};
static struct list imports = LIST_INIT( imports );
static int line_number = 1;
/* converts an integer in string form to an unsigned long and prints an error
* on overflow */
......@@ -511,6 +512,56 @@ static void switch_to_acf(void)
yy_switch_to_buffer( yy_create_buffer( file, YY_BUF_SIZE ) );
}
#define CURRENT_LOCATION { input_name ? input_name : "stdin", parser_text, line_number, 0, line_number, 0 }
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 )
{
where->input_name = input_name ? input_name : "stdin";
where->near_text = parser_text;
where->first_line = line_number;
where->last_line = line_number;
}
void generic_msg( const struct location *where, const char *s, const char *t, va_list ap )
{
struct location cur_loc = CURRENT_LOCATION;
if (!where) where = &cur_loc;
fprintf( stderr, "%s:%d: %s: ", where->input_name, where->first_line, t );
vfprintf( stderr, s, ap );
if (want_near_indication)
{
char *cpy;
if (where->near_text)
{
cpy = xstrdup( where->near_text );
make_print( cpy );
fprintf( stderr, " near '%s'", cpy );
free( cpy );
}
}
}
/* yyerror: yacc assumes this is not newline terminated. */
void parser_error( const char *message )
{
error_loc( "%s\n", message );
}
static void warning_disable(int warning)
{
warning_t *warning_entry;
......
......@@ -125,6 +125,8 @@ static typelib_t *current_typelib;
{
int parser_lex( PARSER_STYPE *yylval );
void push_import( char *input_name );
void pop_import(void);
}
......@@ -3389,14 +3391,6 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s
return list;
}
void init_location( struct location *where )
{
where->input_name = input_name ? input_name : "stdin";
where->near_text = parser_text;
where->first_line = line_number;
where->last_line = line_number;
}
type_t *find_parameterized_type(type_t *type, typeref_list_t *params)
{
char *name = format_parameterized_type_name(type, params);
......
......@@ -32,51 +32,11 @@
#include "utils.h"
#include "parser.h"
#define CURRENT_LOCATION { input_name ? input_name : "stdin", parser_text, line_number, 0, line_number, 0 }
static const int want_near_indication = 0;
static void make_print(char *str)
{
while(*str)
{
if(!isprint(*str))
*str = ' ';
str++;
}
}
static void generic_msg( const struct location *where, const char *s, const char *t, va_list ap )
{
fprintf( stderr, "%s:%d: %s: ", where->input_name, where->first_line, t );
vfprintf( stderr, s, ap );
if (want_near_indication)
{
char *cpy;
if (where->near_text)
{
cpy = xstrdup( where->near_text );
make_print( cpy );
fprintf( stderr, " near '%s'", cpy );
free( cpy );
}
}
}
/* yyerror: yacc assumes this is not newline terminated. */
void parser_error(const char *s)
{
error_loc("%s\n", s);
}
void error_at( const struct location *where, const char *s, ... )
{
struct location cur_loc = CURRENT_LOCATION;
va_list ap;
va_start( ap, s );
generic_msg( where ? where : &cur_loc, s, "error", ap );
generic_msg( where, s, "error", ap );
va_end( ap );
exit( 1 );
}
......@@ -102,10 +62,9 @@ void warning(const char *s, ...)
void warning_at( const struct location *where, const char *s, ... )
{
struct location cur_loc = CURRENT_LOCATION;
va_list ap;
va_start( ap, s );
generic_msg( where ? where : &cur_loc, s, "warning", ap );
generic_msg( where, s, "warning", ap );
va_end( ap );
}
......
......@@ -22,8 +22,8 @@
#define __WIDL_UTILS_H
#include "widltypes.h"
#include "parser.h"
void parser_error(const char *s) __attribute__((noreturn));
void error(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn));
void error_at( const struct location *, const char *s, ... ) __attribute__((format( printf, 2, 3 ))) __attribute__((noreturn));
#define error_loc( ... ) error_at( NULL, ## __VA_ARGS__ )
......
......@@ -140,8 +140,6 @@ static struct strarray dlldirs;
static char *output_name;
static const char *sysroot = "";
int line_number = 1;
static FILE *idfile;
unsigned int pointer_size = 0;
......
......@@ -72,9 +72,6 @@ extern const char *prefix_server;
extern unsigned int pointer_size;
extern time_t now;
extern int line_number;
extern int char_number;
enum stub_mode
{
MODE_Os, /* inline stubs */
......
......@@ -656,8 +656,6 @@ type_t *reg_type(type_t *type, const char *name, struct namespace *namespace, in
var_t *make_var(char *name);
var_list_t *append_var(var_list_t *list, var_t *var);
void init_location( struct location * );
char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix,
const char *abi_prefix);
char *format_parameterized_type_name(type_t *type, typeref_list_t *params);
......
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