summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2014-01-03 23:23:23 +1100
committerDavid Gibson <david@gibson.dropbear.id.au>2014-01-04 10:04:20 +1100
commitc854434dc2e955d2053bccb6c763dcfb75d0842b (patch)
tree3dd9d74a0a73f96b72a0afcacd5a0656b473426c
parent6a15eb2350426d285130e4c9d84c0bdb6575547a (diff)
downloaddevice-tree-compiler-c854434dc2e955d2053bccb6c763dcfb75d0842b.tar.gz
Correct locations in parser error messaes
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@gibson.dropbear.id.au>
-rw-r--r--dtc-parser.y26
1 files 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);
}