* [DTC PATCH 1/2] Add yyerrorf() for formatted error messages.
@ 2007-12-20 16:48 Scott Wood
2007-12-21 0:04 ` David Gibson
0 siblings, 1 reply; 4+ messages in thread
From: Scott Wood @ 2007-12-20 16:48 UTC (permalink / raw)
To: jdl; +Cc: linuxppc-dev, u-boot-users
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;
--
1.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [DTC PATCH 1/2] Add yyerrorf() for formatted error messages.
2007-12-20 16:48 [DTC PATCH 1/2] Add yyerrorf() for formatted error messages Scott Wood
@ 2007-12-21 0:04 ` David Gibson
2007-12-21 21:28 ` Scott Wood
0 siblings, 1 reply; 4+ messages in thread
From: David Gibson @ 2007-12-21 0:04 UTC (permalink / raw)
To: Scott Wood; +Cc: linuxppc-dev, jdl, u-boot-users
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
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [DTC PATCH 1/2] Add yyerrorf() for formatted error messages.
2007-12-21 0:04 ` David Gibson
@ 2007-12-21 21:28 ` Scott Wood
2007-12-22 2:43 ` David Gibson
0 siblings, 1 reply; 4+ messages in thread
From: Scott Wood @ 2007-12-21 21:28 UTC (permalink / raw)
To: jdl, linuxppc-dev, u-boot-users
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [DTC PATCH 1/2] Add yyerrorf() for formatted error messages.
2007-12-21 21:28 ` Scott Wood
@ 2007-12-22 2:43 ` David Gibson
0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2007-12-22 2:43 UTC (permalink / raw)
To: Scott Wood; +Cc: linuxppc-dev, jdl, u-boot-users
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.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-12-22 2:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-20 16:48 [DTC PATCH 1/2] Add yyerrorf() for formatted error messages Scott Wood
2007-12-21 0:04 ` David Gibson
2007-12-21 21:28 ` Scott Wood
2007-12-22 2:43 ` David Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).