Create new and use new print_error that uses printf style formatting.
yyerror is meant to be called by the parser internal code, and it's interface is limited. Instead create and call a new error message routine that allows formatted strings to be used. yyerror uses the new routine so error formatting remains consistent. Signed-of-by: John Bonesio <bones@secretlab.ca> Acked-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
This commit is contained in:
committed by
Grant Likely
parent
8773e12fa9
commit
c0fa2e6d4e
28
dtc-parser.y
28
dtc-parser.y
@@ -27,6 +27,7 @@
|
|||||||
YYLTYPE yylloc;
|
YYLTYPE yylloc;
|
||||||
|
|
||||||
extern int yylex(void);
|
extern int yylex(void);
|
||||||
|
extern void print_error(char const *fmt, ...);
|
||||||
extern void yyerror(char const *s);
|
extern void yyerror(char const *s);
|
||||||
|
|
||||||
extern struct boot_info *the_boot_info;
|
extern struct boot_info *the_boot_info;
|
||||||
@@ -136,8 +137,7 @@ devicetree:
|
|||||||
if (target)
|
if (target)
|
||||||
merge_nodes(target, $3);
|
merge_nodes(target, $3);
|
||||||
else
|
else
|
||||||
yyerror("label does not exist in "
|
print_error("label, '%s' not found", $2);
|
||||||
" node redefinition");
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@@ -200,8 +200,7 @@ propdata:
|
|||||||
|
|
||||||
if ($6 != 0)
|
if ($6 != 0)
|
||||||
if (fseek(f, $6, SEEK_SET) != 0)
|
if (fseek(f, $6, SEEK_SET) != 0)
|
||||||
srcpos_error(&yylloc,
|
print_error("Couldn't seek to offset %llu in \"%s\": %s",
|
||||||
"Couldn't seek to offset %llu in \"%s\": %s",
|
|
||||||
(unsigned long long)$6,
|
(unsigned long long)$6,
|
||||||
$4.val,
|
$4.val,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
@@ -295,7 +294,7 @@ subnodes:
|
|||||||
}
|
}
|
||||||
| subnode propdef
|
| subnode propdef
|
||||||
{
|
{
|
||||||
yyerror("syntax error: properties must precede subnodes");
|
print_error("syntax error: properties must precede subnodes");
|
||||||
YYERROR;
|
YYERROR;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@@ -314,12 +313,21 @@ subnode:
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
void yyerror(char const *s)
|
void print_error(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
srcpos_error(&yylloc, "%s", s);
|
va_list va;
|
||||||
|
|
||||||
|
va_start(va, fmt);
|
||||||
|
srcpos_verror(&yylloc, fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
treesource_error = 1;
|
treesource_error = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void yyerror(char const *s) {
|
||||||
|
print_error("%s", s);
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned long long eval_literal(const char *s, int base, int bits)
|
static unsigned long long eval_literal(const char *s, int base, int bits)
|
||||||
{
|
{
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
@@ -328,11 +336,11 @@ static unsigned long long eval_literal(const char *s, int base, int bits)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
val = strtoull(s, &e, base);
|
val = strtoull(s, &e, base);
|
||||||
if (*e)
|
if (*e)
|
||||||
yyerror("bad characters in literal");
|
print_error("bad characters in literal");
|
||||||
else if ((errno == ERANGE)
|
else if ((errno == ERANGE)
|
||||||
|| ((bits < 64) && (val >= (1ULL << bits))))
|
|| ((bits < 64) && (val >= (1ULL << bits))))
|
||||||
yyerror("literal out of range");
|
print_error("literal out of range");
|
||||||
else if (errno != 0)
|
else if (errno != 0)
|
||||||
yyerror("bad literal");
|
print_error("bad literal");
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|||||||
21
srcpos.c
21
srcpos.c
@@ -208,20 +208,25 @@ srcpos_string(struct srcpos *pos)
|
|||||||
return pos_str;
|
return pos_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
srcpos_verror(struct srcpos *pos, char const *fmt, va_list va)
|
||||||
|
{
|
||||||
|
const char *srcstr;
|
||||||
|
|
||||||
|
srcstr = srcpos_string(pos);
|
||||||
|
|
||||||
|
fprintf(stdout, "Error: %s ", srcstr);
|
||||||
|
vfprintf(stdout, fmt, va);
|
||||||
|
fprintf(stdout, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
srcpos_error(struct srcpos *pos, char const *fmt, ...)
|
srcpos_error(struct srcpos *pos, char const *fmt, ...)
|
||||||
{
|
{
|
||||||
const char *srcstr;
|
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
|
srcpos_verror(pos, fmt, va);
|
||||||
srcstr = srcpos_string(pos);
|
|
||||||
|
|
||||||
fprintf(stderr, "Error: %s ", srcstr);
|
|
||||||
vfprintf(stderr, fmt, va);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
|
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
srcpos.h
2
srcpos.h
@@ -76,6 +76,8 @@ extern struct srcpos *srcpos_copy(struct srcpos *pos);
|
|||||||
extern char *srcpos_string(struct srcpos *pos);
|
extern char *srcpos_string(struct srcpos *pos);
|
||||||
extern void srcpos_dump(struct srcpos *pos);
|
extern void srcpos_dump(struct srcpos *pos);
|
||||||
|
|
||||||
|
extern void srcpos_verror(struct srcpos *pos, char const *, va_list va)
|
||||||
|
__attribute__((format(printf, 2, 0)));
|
||||||
extern void srcpos_error(struct srcpos *pos, char const *, ...)
|
extern void srcpos_error(struct srcpos *pos, char const *, ...)
|
||||||
__attribute__((format(printf, 2, 3)));
|
__attribute__((format(printf, 2, 3)));
|
||||||
extern void srcpos_warn(struct srcpos *pos, char const *, ...)
|
extern void srcpos_warn(struct srcpos *pos, char const *, ...)
|
||||||
|
|||||||
Reference in New Issue
Block a user