widl: Add functions to print an error or warning message using location information to enable these to be printed accurately when a check is done after an element is parsed.

Add location information to variable automatically, since this is will 
be useful for type checking of arguments.
This commit is contained in:
Rob Shearman 2008-04-14 11:00:20 +01:00 committed by Alexandre Julliard
parent f728fe168b
commit 0053599688
4 changed files with 44 additions and 7 deletions

View File

@ -1560,6 +1560,9 @@ static var_t *make_var(char *name)
v->type = NULL; v->type = NULL;
v->attrs = NULL; v->attrs = NULL;
v->eval = NULL; v->eval = NULL;
v->loc_info.input_name = input_name ? input_name : "stdin";
v->loc_info.line_number = line_number;
v->loc_info.near_text = parser_text;
return v; return v;
} }

View File

@ -33,6 +33,8 @@
#include "utils.h" #include "utils.h"
#include "parser.h" #include "parser.h"
#define CURRENT_LOCATION { input_name ? input_name : "stdin", line_number, parser_text }
static const int want_near_indication = 0; static const int want_near_indication = 0;
static void make_print(char *str) static void make_print(char *str)
@ -45,17 +47,17 @@ static void make_print(char *str)
} }
} }
static void generic_msg(const char *s, const char *t, const char *n, va_list ap) static void generic_msg(const loc_info_t *loc_info, const char *s, const char *t, va_list ap)
{ {
fprintf(stderr, "%s:%d: %s: ", input_name ? input_name : "stdin", line_number, t); fprintf(stderr, "%s:%d: %s: ", loc_info->input_name, loc_info->line_number, t);
vfprintf(stderr, s, ap); vfprintf(stderr, s, ap);
if (want_near_indication) if (want_near_indication)
{ {
char *cpy; char *cpy;
if(n) if(loc_info->near_text)
{ {
cpy = xstrdup(n); cpy = xstrdup(loc_info->near_text);
make_print(cpy); make_print(cpy);
fprintf(stderr, " near '%s'", cpy); fprintf(stderr, " near '%s'", cpy);
free(cpy); free(cpy);
@ -67,9 +69,10 @@ static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
/* yyerror: yacc assumes this is not newline terminated. */ /* yyerror: yacc assumes this is not newline terminated. */
int parser_error(const char *s, ...) int parser_error(const char *s, ...)
{ {
loc_info_t cur_location = CURRENT_LOCATION;
va_list ap; va_list ap;
va_start(ap, s); va_start(ap, s);
generic_msg(s, "Error", parser_text, ap); generic_msg(&cur_location, s, "Error", ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
va_end(ap); va_end(ap);
exit(1); exit(1);
@ -78,18 +81,29 @@ int parser_error(const char *s, ...)
void error_loc(const char *s, ...) void error_loc(const char *s, ...)
{ {
loc_info_t cur_loc = CURRENT_LOCATION;
va_list ap; va_list ap;
va_start(ap, s); va_start(ap, s);
generic_msg(s, "Error", parser_text, ap); generic_msg(&cur_loc, s, "Error", ap);
va_end(ap);
exit(1);
}
void error_loc_info(const loc_info_t *loc_info, const char *s, ...)
{
va_list ap;
va_start(ap, s);
generic_msg(loc_info, s, "Error", ap);
va_end(ap); va_end(ap);
exit(1); exit(1);
} }
int parser_warning(const char *s, ...) int parser_warning(const char *s, ...)
{ {
loc_info_t cur_loc = CURRENT_LOCATION;
va_list ap; va_list ap;
va_start(ap, s); va_start(ap, s);
generic_msg(s, "Warning", parser_text, ap); generic_msg(&cur_loc, s, "Warning", ap);
va_end(ap); va_end(ap);
return 0; return 0;
} }
@ -113,6 +127,14 @@ void warning(const char *s, ...)
va_end(ap); va_end(ap);
} }
void warning_loc_info(const loc_info_t *loc_info, const char *s, ...)
{
va_list ap;
va_start(ap, s);
generic_msg(loc_info, s, "Warning", ap);
va_end(ap);
}
void chat(const char *s, ...) void chat(const char *s, ...)
{ {
if(debuglevel & DEBUGLEVEL_CHAT) if(debuglevel & DEBUGLEVEL_CHAT)

View File

@ -37,7 +37,9 @@ int parser_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void error_loc(const char *s, ...) __attribute__((format (printf, 1, 2))); void error_loc(const char *s, ...) __attribute__((format (printf, 1, 2)));
void error(const char *s, ...) __attribute__((format (printf, 1, 2))); void error(const char *s, ...) __attribute__((format (printf, 1, 2)));
void error_loc_info(const loc_info_t *, const char *s, ...) __attribute__((format (printf, 2, 3)));
void warning(const char *s, ...) __attribute__((format (printf, 1, 2))); void warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void warning_loc_info(const loc_info_t *, const char *s, ...) __attribute__((format (printf, 2, 3)));
void chat(const char *s, ...) __attribute__((format (printf, 1, 2))); void chat(const char *s, ...) __attribute__((format (printf, 1, 2)));
char *dup_basename(const char *name, const char *ext); char *dup_basename(const char *name, const char *ext);

View File

@ -36,6 +36,7 @@ typedef GUID UUID;
#define RPC_FC_FUNCTION 0xfe #define RPC_FC_FUNCTION 0xfe
typedef struct _loc_info_t loc_info_t;
typedef struct _attr_t attr_t; typedef struct _attr_t attr_t;
typedef struct _expr_t expr_t; typedef struct _expr_t expr_t;
typedef struct _type_t type_t; typedef struct _type_t type_t;
@ -176,6 +177,13 @@ enum type_kind
TKIND_MAX TKIND_MAX
}; };
struct _loc_info_t
{
const char *input_name;
int line_number;
const char *near_text;
};
struct str_list_entry_t struct str_list_entry_t
{ {
char *str; char *str;
@ -240,6 +248,8 @@ struct _var_t {
attr_list_t *attrs; attr_list_t *attrs;
expr_t *eval; expr_t *eval;
struct _loc_info_t loc_info;
/* parser-internal */ /* parser-internal */
struct list entry; struct list entry;
}; };