From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Subject: [PATCH 09/10] Correct locations in parser error messaes
Date: Sat, 4 Jan 2014 00:24:42 +1100 [thread overview]
Message-ID: <1388755483-27008-10-git-send-email-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <1388755483-27008-1-git-send-email-david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
The print_error() function used in several places in the parser uses the
location information in yylloc to describe the location of the error.
This is not correct in most cases. yylloc gives the location of the
lookahead token, whereas the error is generally associated with one of
the already parsed non-terminals.
This patch corrects this, adding a location parameter to print_error() and
supplying it with the appropriate bison @N symbols.
This probably breaks yacc compatiblity, but too bad - accurate error
messages are more important.
Signed-off-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
---
dtc-parser.y | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/dtc-parser.y b/dtc-parser.y
index bed857e..7ee436f 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -17,17 +17,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
-
%{
#include <stdio.h>
#include "dtc.h"
#include "srcpos.h"
-YYLTYPE yylloc;
-
extern int yylex(void);
-extern void print_error(char const *fmt, ...);
+extern void print_error(YYLTYPE *loc, char const *fmt, ...);
extern void yyerror(char const *s);
extern struct boot_info *the_boot_info;
@@ -148,7 +145,7 @@ devicetree:
if (target)
merge_nodes(target, $3);
else
- print_error("label or path, '%s', not found", $2);
+ print_error(&@2, "label or path, '%s', not found", $2);
$$ = $1;
}
| devicetree DT_DEL_NODE DT_REF ';'
@@ -156,7 +153,7 @@ devicetree:
struct node *target = get_node_by_ref($1, $3);
if (!target)
- print_error("label or path, '%s', not found", $3);
+ print_error(&@3, "label or path, '%s', not found", $3);
else
delete_node(target);
@@ -276,7 +273,7 @@ arrayprefix:
if ((bits != 8) && (bits != 16) &&
(bits != 32) && (bits != 64))
{
- print_error("Only 8, 16, 32 and 64-bit elements"
+ print_error(&@2, "Only 8, 16, 32 and 64-bit elements"
" are currently supported");
bits = 32;
}
@@ -302,7 +299,7 @@ arrayprefix:
* mask), all bits are one.
*/
if (($2 > mask) && (($2 | mask) != -1ULL))
- print_error(
+ print_error(&@2,
"integer value out of range "
"%016lx (%d bits)", $1.bits);
}
@@ -318,7 +315,7 @@ arrayprefix:
REF_PHANDLE,
$2);
else
- print_error("References are only allowed in "
+ print_error(&@2, "References are only allowed in "
"arrays with 32-bit elements.");
$$.data = data_append_integer($1.data, val, $1.bits);
@@ -438,7 +435,7 @@ subnodes:
}
| subnode propdef
{
- print_error("syntax error: properties must precede subnodes");
+ print_error(&@2, "syntax error: properties must precede subnodes");
YYERROR;
}
;
@@ -461,17 +458,18 @@ subnode:
%%
-void print_error(char const *fmt, ...)
+void print_error(YYLTYPE *loc, char const *fmt, ...)
{
va_list va;
va_start(va, fmt);
- srcpos_verror(&yylloc, "Error", fmt, va);
+ srcpos_verror(loc, "Error", fmt, va);
va_end(va);
treesource_error = true;
}
-void yyerror(char const *s) {
- print_error("%s", s);
+void yyerror(char const *s)
+{
+ print_error(&yylloc, "%s", s);
}
--
1.8.4.2
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-01-03 13:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-03 13:24 [0/10] dtc: Assorted parsing and error reporting cleanups David Gibson
[not found] ` <1388755483-27008-1-git-send-email-david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
2014-01-03 13:24 ` [PATCH 01/10] Remove unused srcpos_warn() function David Gibson
2014-01-03 13:24 ` [PATCH 02/10] Fix typo in type of srcpos_verror() et al David Gibson
2014-01-03 13:24 ` [PATCH 03/10] Fix indentation of srcpos_verror() David Gibson
2014-01-03 13:24 ` [PATCH 04/10] Fix memory leak in srcpos_verror() David Gibson
2014-01-03 13:24 ` [PATCH 05/10] Make srcpos_{v,}error() more widely useful David Gibson
2014-01-03 13:24 ` [PATCH 06/10] Move integer literal processing back to the lexer David Gibson
2014-01-03 13:24 ` [PATCH 07/10] Move character literal processing " David Gibson
2014-01-03 13:24 ` [PATCH 08/10] Die on failed /incbin/ seeks David Gibson
2014-01-03 13:24 ` David Gibson [this message]
2014-01-03 13:24 ` [PATCH 10/10] Clean up parser error messages David Gibson
2014-01-03 19:51 ` [0/10] dtc: Assorted parsing and error reporting cleanups Jon Loeliger
[not found] ` <E1VzAmD-0001xi-DA-CYoMK+44s/E@public.gmane.org>
2014-01-16 9:54 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1388755483-27008-10-git-send-email-david@gibson.dropbear.id.au \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).