aboutsummaryrefslogtreecommitdiff
path: root/gcc/treelang/lex.l
diff options
context:
space:
mode:
authorJames A. Morrison <phython@gcc.gnu.org>2004-10-02 18:38:29 +0000
committerJames A. Morrison <phython@gcc.gnu.org>2004-10-02 18:38:29 +0000
commit34c4f8c7d8dedd5dd5ac7185d402b6c10003da19 (patch)
tree4295da4da797ffaedddce69661349e32567f4598 /gcc/treelang/lex.l
parent039784fa0d28b1d5f816cdf66d9567208f6546f1 (diff)
downloadgcc-34c4f8c7d8dedd5dd5ac7185d402b6c10003da19.zip
gcc-34c4f8c7d8dedd5dd5ac7185d402b6c10003da19.tar.gz
gcc-34c4f8c7d8dedd5dd5ac7185d402b6c10003da19.tar.bz2
re PR treelang/17762 (treelang doesn't use mapped locations)
2004-10-02 James A. Morrison <phython@gcc.gnu.org> PR other/17762 * lex.l: Include input.h and errors.h (lineno): New variable. (LINEMAP_POSITION_FOR_COLUMN): Define as noop when USE_MAPPED_LOCATION is not defined. Set column position with LINEMAP_POSITION_FOR_COLUMN. Use error instead of fprintf. Set input_location with the value returned by linemap_start_line when USE_MAPPED_LOCATION is defined. (dump_lex_value): Use LOCATION_LINE. * parse.y: Include errors.h. Use error and warning instead of fprintf. (return): Move exp to rule scope and always set to $2. Test against exp instead of $2. (init): Set $$ to $2. (print_token): Use LOCATION_LINE. * tree1.c (treelang_init): Call treelang_init_decl_processing last. Call linemap_add to set input_filename when USE_MAPPED_LOCATION is defined. (treelang_parse_file): Always start at line one. Rename input_filename to main_input_filename when USE_MAPPED_LOCATION is defined. Leave main_input_filename when done parsing the input. (insert_tree_name): Use error instead of fprintf. * treetree.c (tree_code_get_expression): Wrap long line. (tree_mark_addressable): Use %qD to print out DECLs. 2004-10-02 James A. Morrison <phython@gcc.gnu.org> * compile/autofunc.tree: New File. * compile/badchar.tree: New File. * compile/externvar.tree: New File. * compile/mismatch.tree: New File. * compile/noproto.tree: New File. * compile/novar.tree: New File. * compile/var_defs.tree: Add duplicate variable. From-SVN: r88430
Diffstat (limited to 'gcc/treelang/lex.l')
-rw-r--r--gcc/treelang/lex.l43
1 files changed, 28 insertions, 15 deletions
diff --git a/gcc/treelang/lex.l b/gcc/treelang/lex.l
index 41be1e0..71268ff 100644
--- a/gcc/treelang/lex.l
+++ b/gcc/treelang/lex.l
@@ -36,7 +36,8 @@
#include "system.h"
#include "coretypes.h"
#include "tm.h"
-#include "diagnostic.h"
+#include "input.h"
+#include "errors.h"
#include "tree.h"
/* Token defs. */
@@ -50,6 +51,7 @@ int yylex (void);
void update_yylval (int a);
static int next_tree_charno = 1;
+static int lineno = 1;
static void update_lineno_charno (void);
static void dump_lex_value (int lexret);
@@ -58,7 +60,9 @@ static void dump_lex_value (int lexret);
{fprintf (stderr, "\nlexer returning"); dump_lex_value (a);} return a;}
#define NOT_RETURN(a) {update_yylval (a); if (option_lexer_trace)\
{fprintf (stderr, "\nlexer swallowing"); dump_lex_value (a);}}
-
+#ifndef USE_MAPPED_LOCATION
+#define LINEMAP_POSITION_FOR_COLUMN(INPUT, LINETABLE, COL)
+#endif
%}
%option nostack
@@ -70,8 +74,10 @@ static void dump_lex_value (int lexret);
%%
{
- /* Should really allocate only what we need. lll;. */
+ /* ??? Should really allocate only what we need. */
yylval = my_malloc (sizeof (struct prod_token_parm_item));
+ LINEMAP_POSITION_FOR_COLUMN (input_location, &line_table,
+ next_tree_charno);
((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
}
@@ -210,11 +216,9 @@ static void dump_lex_value (int lexret);
[^\n] {
update_lineno_charno ();
- fprintf (stderr, "%s:%i:%i: Unrecognized character %c\n",
- ((struct prod_token_parm_item *)yylval)->tp.tok.location.file,
- ((struct prod_token_parm_item *)yylval)->tp.tok.location.line,
- ((struct prod_token_parm_item *)yylval)->tp.tok.charno, yytext[0]);
- errorcount++;
+ error ("%HUnrecognized character %qc.",
+ &((struct prod_token_parm_item *)yylval)->tp.tok.location,
+ yytext[0]);
}
%%
@@ -229,17 +233,23 @@ update_lineno_charno (void)
/* Update the values we send to caller in case we sometimes don't
tell them about all the 'tokens' eg comments etc. */
int yyl;
+ LINEMAP_POSITION_FOR_COLUMN (input_location, &line_table,
+ next_tree_charno);
((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
- if (input_line == 0)
- input_line = 1;
for ( yyl = 0; yyl < yyleng; ++yyl )
{
if ( yytext[yyl] == '\n' )
{
- ++input_line;
- next_tree_charno = 1;
+#ifdef USE_MAPPED_LOCATION
+ source_location s = linemap_line_start (&line_table, ++lineno,
+ 80);
+ input_location = s;
+#else
+ input_line = ++lineno;
+#endif
+ next_tree_charno = 1;
}
else
next_tree_charno++;
@@ -269,10 +279,13 @@ static void
dump_lex_value (int lexret)
{
int ix;
+
fprintf (stderr, " %d l:%d c:%d ln:%d text=", lexret,
- ((struct prod_token_parm_item *) yylval)->tp.tok.location.line,
- ((struct prod_token_parm_item *) yylval)->tp.tok.charno,
- ((struct prod_token_parm_item *) yylval)->tp.tok.length);
+ LOCATION_LINE (((struct prod_token_parm_item *)
+ yylval)->tp.tok.location),
+ ((struct prod_token_parm_item *) yylval)->tp.tok.charno,
+ ((struct prod_token_parm_item *) yylval)->tp.tok.length);
+
for (ix = 0; ix < yyleng; ix++)
{
fprintf (stderr, "%c", yytext[ix]);