[U-Boot-Users] [DTC PATCH 1/2] Add yyerrorf() for formatted error messages.

Signed-off-by: Scott Wood scottwood@freescale.com --- dtc-parser.y | 16 ++++++++++++++++ srcpos.h | 1 + 2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/dtc-parser.y b/dtc-parser.y index 002ea7f..4a0181d 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -318,6 +318,22 @@ void yyerror (char const *s) fname, yylloc.first_line, s); }
+void yyerrorf(char const *s, ...) +{ + const char *fname = srcpos_filename_for_num(yylloc.filenum); + va_list va; + va_start(va, s); + + if (strcmp(fname, "-") == 0) + fname = "stdin"; + + fprintf(stderr, "%s:%d ", fname, yylloc.first_line); + vfprintf(stderr, s, va); + fprintf(stderr, "\n"); + + va_end(va); +} + unsigned long long eval_literal(const char *s, int base, int bits) { unsigned long long val; diff --git a/srcpos.h b/srcpos.h index ce7ab5b..e59c788 100644 --- a/srcpos.h +++ b/srcpos.h @@ -63,6 +63,7 @@ typedef struct YYLTYPE {
extern void yyerror(char const *); +extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));
extern int srcpos_filenum;

On Thu, Dec 20, 2007 at 10:48:23AM -0600, Scott Wood wrote:
Signed-off-by: Scott Wood scottwood@freescale.com
No need for a new function. If yyerror() is defined as a varargs function it's still compatible with bison's built-in usage.
Oh, and while you're at it, you can kill off the bogus prototype for yyerror() in treesource.c

On Fri, Dec 21, 2007 at 11:04:39AM +1100, David Gibson wrote:
On Thu, Dec 20, 2007 at 10:48:23AM -0600, Scott Wood wrote:
Signed-off-by: Scott Wood scottwood@freescale.com
No need for a new function. If yyerror() is defined as a varargs function it's still compatible with bison's built-in usage.
Not if yyerror() is called with a percent symbol in the string, which looks possible if a percent token is added and verbose syntax errors are enabled.
-Scott

On Fri, Dec 21, 2007 at 03:28:56PM -0600, Scott Wood wrote:
On Fri, Dec 21, 2007 at 11:04:39AM +1100, David Gibson wrote:
On Thu, Dec 20, 2007 at 10:48:23AM -0600, Scott Wood wrote:
Signed-off-by: Scott Wood scottwood@freescale.com
No need for a new function. If yyerror() is defined as a varargs function it's still compatible with bison's built-in usage.
Not if yyerror() is called with a percent symbol in the string, which looks possible if a percent token is added and verbose syntax errors are enabled.
Ah, yes, I guess so.
However from discussion on the other thread, it looks like this extended yyerror() isn't really what you want. Maybe instead we should look a more general error/warning printing function, and make yyerror() call that.
participants (2)
-
David Gibson
-
Scott Wood