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:
parent
f728fe168b
commit
0053599688
|
@ -1560,6 +1560,9 @@ static var_t *make_var(char *name)
|
|||
v->type = NULL;
|
||||
v->attrs = 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include "utils.h"
|
||||
#include "parser.h"
|
||||
|
||||
#define CURRENT_LOCATION { input_name ? input_name : "stdin", line_number, parser_text }
|
||||
|
||||
static const int want_near_indication = 0;
|
||||
|
||||
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);
|
||||
|
||||
if (want_near_indication)
|
||||
{
|
||||
char *cpy;
|
||||
if(n)
|
||||
if(loc_info->near_text)
|
||||
{
|
||||
cpy = xstrdup(n);
|
||||
cpy = xstrdup(loc_info->near_text);
|
||||
make_print(cpy);
|
||||
fprintf(stderr, " near '%s'", 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. */
|
||||
int parser_error(const char *s, ...)
|
||||
{
|
||||
loc_info_t cur_location = CURRENT_LOCATION;
|
||||
va_list ap;
|
||||
va_start(ap, s);
|
||||
generic_msg(s, "Error", parser_text, ap);
|
||||
generic_msg(&cur_location, s, "Error", ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
exit(1);
|
||||
|
@ -78,18 +81,29 @@ int parser_error(const char *s, ...)
|
|||
|
||||
void error_loc(const char *s, ...)
|
||||
{
|
||||
loc_info_t cur_loc = CURRENT_LOCATION;
|
||||
va_list ap;
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int parser_warning(const char *s, ...)
|
||||
{
|
||||
loc_info_t cur_loc = CURRENT_LOCATION;
|
||||
va_list ap;
|
||||
va_start(ap, s);
|
||||
generic_msg(s, "Warning", parser_text, ap);
|
||||
generic_msg(&cur_loc, s, "Warning", ap);
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
|
@ -113,6 +127,14 @@ void warning(const char *s, ...)
|
|||
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, ...)
|
||||
{
|
||||
if(debuglevel & DEBUGLEVEL_CHAT)
|
||||
|
|
|
@ -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)));
|
||||
void error_loc(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_loc_info(const loc_info_t *, const char *s, ...) __attribute__((format (printf, 2, 3)));
|
||||
void chat(const char *s, ...) __attribute__((format (printf, 1, 2)));
|
||||
|
||||
char *dup_basename(const char *name, const char *ext);
|
||||
|
|
|
@ -36,6 +36,7 @@ typedef GUID UUID;
|
|||
|
||||
#define RPC_FC_FUNCTION 0xfe
|
||||
|
||||
typedef struct _loc_info_t loc_info_t;
|
||||
typedef struct _attr_t attr_t;
|
||||
typedef struct _expr_t expr_t;
|
||||
typedef struct _type_t type_t;
|
||||
|
@ -176,6 +177,13 @@ enum type_kind
|
|||
TKIND_MAX
|
||||
};
|
||||
|
||||
struct _loc_info_t
|
||||
{
|
||||
const char *input_name;
|
||||
int line_number;
|
||||
const char *near_text;
|
||||
};
|
||||
|
||||
struct str_list_entry_t
|
||||
{
|
||||
char *str;
|
||||
|
@ -240,6 +248,8 @@ struct _var_t {
|
|||
attr_list_t *attrs;
|
||||
expr_t *eval;
|
||||
|
||||
struct _loc_info_t loc_info;
|
||||
|
||||
/* parser-internal */
|
||||
struct list entry;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue