diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2009-12-08 14:24:42 +1100 |
---|---|---|
committer | Jon Loeliger <jdl@jdl.com> | 2010-01-14 07:52:48 -0600 |
commit | 728c5e87c655c17c2fbc1d5386b12ff328e0fc76 (patch) | |
tree | 9650c3532d9d0225f6a5e415a86567502ba12890 /dtc-lexer.l | |
parent | d68cb36b0bebc7711ada9b750f3c19398c44efb7 (diff) | |
download | dtc-728c5e87c655c17c2fbc1d5386b12ff328e0fc76.tar.gz |
dtc: Cleanup line number tracking, add column number tracking
Our YYLTYPE current carries around first and last line and first and
last column information. However, of these, on the first line
information is actually filled in properly.
Furthermore, filling in the line number information from yylineno is
kind of clunky: we have to copy its value to the srcfile stack and
back to handle include file positioning correctly.
This patch cleans this up. We turn off flex's yylineno option and
instead track the line and column number ourselves from
YY_USER_ACTION. The line and column number are stored directly inside
the srcfile_state structure, so it's automatically a per-file
quantity. We now also fill in all the yylloc from YY_USER_ACTION.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'dtc-lexer.l')
-rw-r--r-- | dtc-lexer.l | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/dtc-lexer.l b/dtc-lexer.l index 12467c0..9021231 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -18,7 +18,7 @@ * USA */ -%option noyywrap nounput noinput yylineno +%option noyywrap nounput noinput %x INCLUDE %x BYTESTRING @@ -38,10 +38,11 @@ LINECOMMENT "//".*\n #include "srcpos.h" #include "dtc-parser.tab.h" + +/* CAUTION: this will stop working if we ever use yyless() or yyunput() */ #define YY_USER_ACTION \ { \ - yylloc.file = current_srcfile; \ - yylloc.first_line = yylineno; \ + srcpos_update(&yylloc, yytext, yyleng); \ } /*#define LEXDEBUG 1*/ @@ -169,12 +170,9 @@ static void push_input_file(const char *filename) { assert(filename); - current_srcfile->lineno = yylineno; - srcfile_push(filename); yyin = current_srcfile->f; - yylineno = 1; yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE)); } @@ -186,7 +184,6 @@ static int pop_input_file(void) return 0; yypop_buffer_state(); - yylineno = current_srcfile->lineno; yyin = current_srcfile->f; return 1; |