Clean up parser error messages

Generally edit parser error messages for brevity and clarity.  Replace
the print_error() function with a a new macro for brevity and clarity in
the source.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2014-01-03 23:57:39 +11:00
parent c854434dc2
commit fa3f3f0ebd

View file

@ -24,8 +24,12 @@
#include "srcpos.h" #include "srcpos.h"
extern int yylex(void); extern int yylex(void);
extern void print_error(YYLTYPE *loc, char const *fmt, ...);
extern void yyerror(char const *s); extern void yyerror(char const *s);
#define ERROR(loc, ...) \
do { \
srcpos_error((loc), "Error", __VA_ARGS__); \
treesource_error = true; \
} while (0)
extern struct boot_info *the_boot_info; extern struct boot_info *the_boot_info;
extern bool treesource_error; extern bool treesource_error;
@ -145,17 +149,18 @@ devicetree:
if (target) if (target)
merge_nodes(target, $3); merge_nodes(target, $3);
else else
print_error(&@2, "label or path, '%s', not found", $2); ERROR(&@2, "Label or path %s not found", $2);
$$ = $1; $$ = $1;
} }
| devicetree DT_DEL_NODE DT_REF ';' | devicetree DT_DEL_NODE DT_REF ';'
{ {
struct node *target = get_node_by_ref($1, $3); struct node *target = get_node_by_ref($1, $3);
if (!target) if (target)
print_error(&@3, "label or path, '%s', not found", $3);
else
delete_node(target); delete_node(target);
else
ERROR(&@3, "Label or path %s not found", $3);
$$ = $1; $$ = $1;
} }
@ -271,10 +276,9 @@ arrayprefix:
bits = $2; bits = $2;
if ((bits != 8) && (bits != 16) && if ((bits != 8) && (bits != 16) &&
(bits != 32) && (bits != 64)) (bits != 32) && (bits != 64)) {
{ ERROR(&@2, "Array elements must be"
print_error(&@2, "Only 8, 16, 32 and 64-bit elements" " 8, 16, 32 or 64-bits");
" are currently supported");
bits = 32; bits = 32;
} }
@ -299,9 +303,8 @@ arrayprefix:
* mask), all bits are one. * mask), all bits are one.
*/ */
if (($2 > mask) && (($2 | mask) != -1ULL)) if (($2 > mask) && (($2 | mask) != -1ULL))
print_error(&@2, ERROR(&@2, "Value out of range for"
"integer value out of range " " %d-bit array element", $1.bits);
"%016lx (%d bits)", $1.bits);
} }
$$.data = data_append_integer($1.data, $2, $1.bits); $$.data = data_append_integer($1.data, $2, $1.bits);
@ -315,7 +318,7 @@ arrayprefix:
REF_PHANDLE, REF_PHANDLE,
$2); $2);
else else
print_error(&@2, "References are only allowed in " ERROR(&@2, "References are only allowed in "
"arrays with 32-bit elements."); "arrays with 32-bit elements.");
$$.data = data_append_integer($1.data, val, $1.bits); $$.data = data_append_integer($1.data, val, $1.bits);
@ -435,7 +438,7 @@ subnodes:
} }
| subnode propdef | subnode propdef
{ {
print_error(&@2, "syntax error: properties must precede subnodes"); ERROR(&@2, "Properties must precede subnodes");
YYERROR; YYERROR;
} }
; ;
@ -458,18 +461,7 @@ subnode:
%% %%
void print_error(YYLTYPE *loc, char const *fmt, ...)
{
va_list va;
va_start(va, fmt);
srcpos_verror(loc, "Error", fmt, va);
va_end(va);
treesource_error = true;
}
void yyerror(char const *s) void yyerror(char const *s)
{ {
print_error(&yylloc, "%s", s); ERROR(&yylloc, "%s", s);
} }