diff options
author | phython <phython@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-02 18:38:29 +0000 |
---|---|---|
committer | phython <phython@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-02 18:38:29 +0000 |
commit | b991d49eaff458357a19c70fa016ba2a4bb53fb8 (patch) | |
tree | 4295da4da797ffaedddce69661349e32567f4598 /gcc/treelang | |
parent | 4b97c1145e585bf5461fa9bf8e6cd0f604976641 (diff) | |
download | gcc-b991d49eaff458357a19c70fa016ba2a4bb53fb8.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88430 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/treelang')
-rw-r--r-- | gcc/treelang/ChangeLog | 29 | ||||
-rw-r--r-- | gcc/treelang/lex.l | 43 | ||||
-rw-r--r-- | gcc/treelang/parse.y | 129 | ||||
-rw-r--r-- | gcc/treelang/tree1.c | 36 | ||||
-rw-r--r-- | gcc/treelang/treetree.c | 18 |
5 files changed, 142 insertions, 113 deletions
diff --git a/gcc/treelang/ChangeLog b/gcc/treelang/ChangeLog index 21837cd4882..962086311fa 100644 --- a/gcc/treelang/ChangeLog +++ b/gcc/treelang/ChangeLog @@ -1,5 +1,34 @@ 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> + * parse.y: Use gcc_assert and gcc_unreachable instead of abort. * tree1.c: Likewise. * treetree.c: Likewise. diff --git a/gcc/treelang/lex.l b/gcc/treelang/lex.l index 41be1e07ea7..71268ff3f8f 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]); diff --git a/gcc/treelang/parse.y b/gcc/treelang/parse.y index 8a1db64954f..5177c90fcde 100644 --- a/gcc/treelang/parse.y +++ b/gcc/treelang/parse.y @@ -39,7 +39,7 @@ the GCC compiler. */ #include "system.h" #include "coretypes.h" #include "tm.h" -#include "diagnostic.h" +#include "errors.h" #include "timevar.h" #include "treelang.h" @@ -198,16 +198,16 @@ storage typename NAME init_opt SEMICOLON { if (VAR_INIT (prod)) { gcc_assert (((struct prod_token_parm_item*)VAR_INIT (prod))->tp.pro.code); - if (STORAGE_CLASS (prod) == EXTERNAL_REFERENCE_STORAGE) - { - fprintf (stderr, "%s:%i:%i: External reference variables may not have initial value\n", - tok->tp.tok.location.file, - tok->tp.tok.location.line, tok->tp.tok.charno); - print_token (stderr, 0, tok); - errorcount++; - YYERROR; - } + if (STORAGE_CLASS (prod) == EXTERNAL_REFERENCE_STORAGE) + { + error("%HExternal reference variable %q.*s has an initial value.", + &tok->tp.tok.location, tok->tp.tok.length, tok->tp.tok.chars); + YYERROR; + VAR_INIT (prod) = NULL; + } + } + prod->tp.pro.code = tree_code_create_variable (STORAGE_CLASS (prod), ((struct prod_token_parm_item*)SYMBOL_TABLE_NAME (prod))->tp.tok.chars, @@ -276,11 +276,8 @@ storage typename NAME LEFT_PARENTHESIS parameters_opt RIGHT_PARENTHESIS SEMICOLO break; case AUTOMATIC_STORAGE: - fprintf (stderr, "%s:%i:%i: A function cannot be automatic\n", - tok->tp.tok.location.file, - tok->tp.tok.location.line, tok->tp.tok.charno); - print_token (stderr, 0, tok); - errorcount++; + error ("%HFunction %q.*s cannot be automatic.", + &tok->tp.tok.location, tok->tp.tok.length, tok->tp.tok.chars); YYERROR; break; @@ -294,14 +291,13 @@ storage typename NAME LEFT_PARENTHESIS parameters_opt RIGHT_PARENTHESIS SEMICOLO this_parm = this_parm->tp.pro.next) { gcc_assert (this_parm->category == production_category); - this_parm_var = VARIABLE (this_parm); gcc_assert (this_parm_var); gcc_assert (this_parm_var->category == production_category); + gcc_assert (this_parm_var->tp.pro.main_token); this_parms = my_malloc (sizeof (struct prod_token_parm_item)); - gcc_assert (this_parm_var->tp.pro.main_token); this_parms->tp.par.variable_name = this_parm_var->tp.pro.main_token->tp.tok.chars; @@ -343,13 +339,11 @@ NAME LEFT_BRACE { current_function = proto = lookup_tree_name (&search_prod); if (!proto) { - fprintf (stderr, "%s:%i:%i: Function prototype not found\n", - tok->tp.tok.location.file, - tok->tp.tok.location.line, tok->tp.tok.charno); - print_token (stderr, 0, tok); - errorcount++; + error ("%HNo prototype found for %q.*s", &tok->tp.tok.location, + tok->tp.tok.length, tok->tp.tok.chars); YYERROR; } + gcc_assert (proto->tp.pro.code); tree_code_create_function_initial (proto->tp.pro.code, tok->tp.tok.location, @@ -362,7 +356,7 @@ NAME LEFT_BRACE { this_parm = this_parm->tp.pro.next) { gcc_assert ((struct prod_token_parm_item*)VARIABLE (this_parm)); - gcc_assert ((( (struct prod_token_parm_item*)VARIABLE (this_parm))->tp.pro.code)); + gcc_assert (((struct prod_token_parm_item*)VARIABLE (this_parm))->tp.pro.code); } #endif } @@ -522,41 +516,34 @@ LEFT_BRACE variable_defs_opt statements_opt RIGHT_BRACE { return: tl_RETURN expression_opt { struct prod_token_parm_item *type_prod; - struct prod_token_parm_item* ret_tok; - ret_tok = $1; + struct prod_token_parm_item *ret_tok = $1; + struct prod_token_parm_item *exp = $2; + type_prod = EXPRESSION_TYPE (current_function); if (NUMERIC_TYPE (type_prod) == VOID_TYPE) - if ($2 == NULL) + if (exp == NULL) tree_code_generate_return (type_prod->tp.pro.code, NULL); else { - fprintf (stderr, "%s:%i:%i: Redundant expression in return\n", - ret_tok->tp.tok.location.file, - ret_tok->tp.tok.location.line, ret_tok->tp.tok.charno); - errorcount++; + warning ("%HRedundant expression in return.", + &ret_tok->tp.tok.location, ret_tok->tp.tok.length, + ret_tok->tp.tok.chars); tree_code_generate_return (type_prod->tp.pro.code, NULL); } else - if ($2 == NULL) - { - fprintf (stderr, "%s:%i:%i: Expression missing in return\n", - ret_tok->tp.tok.location.file, - ret_tok->tp.tok.location.line, ret_tok->tp.tok.charno); - errorcount++; - } + if (exp == NULL) + error ("%HExpression missing in return.", &ret_tok->tp.tok.location); else { - struct prod_token_parm_item *exp; - exp = $2; /* Check same type. */ - if (check_type_match (NUMERIC_TYPE (type_prod), $2)) + if (check_type_match (NUMERIC_TYPE (type_prod), exp)) { - gcc_assert (type_prod->tp.pro.code); - gcc_assert (exp->tp.pro.code); + gcc_assert (type_prod->tp.pro.code); + gcc_assert (exp->tp.pro.code); /* Generate the code. */ tree_code_generate_return (type_prod->tp.pro.code, - exp->tp.pro.code); + exp->tp.pro.code); } } } @@ -645,11 +632,8 @@ NAME LEFT_PARENTHESIS expressions_with_commas RIGHT_PARENTHESIS { proto = lookup_tree_name (&search_prod); if (!proto) { - fprintf (stderr, "%s:%i:%i: Function prototype not found\n", - tok->tp.tok.location.file, - tok->tp.tok.location.line, tok->tp.tok.charno); - print_token (stderr, 0, tok); - errorcount++; + error ("%HFunction prototype not found for %q.*%s.", + &tok->tp.tok.location, tok->tp.tok.length, tok->tp.tok.chars); YYERROR; } EXPRESSION_TYPE (prod) = EXPRESSION_TYPE (proto); @@ -664,11 +648,8 @@ NAME LEFT_PARENTHESIS expressions_with_commas RIGHT_PARENTHESIS { if (exp_count != exp_proto_count) { - fprintf (stderr, "%s:%i:%i: expression count mismatch with prototype\n", - tok->tp.tok.location.file, - tok->tp.tok.location.line, tok->tp.tok.charno); - print_token (stderr, 0, tok); - errorcount++; + error ("%HExpression count mismatch %q.*s with prototype.", + &tok->tp.tok.location, tok->tp.tok.length, tok->tp.tok.chars); YYERROR; } parms = tree_code_init_parameters (); @@ -726,11 +707,8 @@ NAME { symbol_table_entry = lookup_tree_name (&search_prod); if (!symbol_table_entry) { - fprintf (stderr, "%s:%i:%i: Variable referred to but not defined\n", - tok->tp.tok.location.file, - tok->tp.tok.location.line, tok->tp.tok.charno); - print_token (stderr, 0, tok); - errorcount++; + error ("%HVariable %q.*s not defined.", + &tok->tp.tok.location, tok->tp.tok.length, tok->tp.tok.chars); YYERROR; } @@ -758,6 +736,7 @@ init_opt: init: ASSIGN init_element { + $$ = $2; } ; @@ -779,9 +758,10 @@ print_token (FILE * file, unsigned int type ATTRIBUTE_UNUSED, YYSTYPE value) unsigned int ix; tok = value; - fprintf (file, "%d \"", tok->tp.tok.location.line); + fprintf (file, "%d \"", LOCATION_LINE (tok->tp.tok.location)); for (ix = 0; ix < tok->tp.tok.length; ix++) fprintf (file, "%c", tok->tp.tok.chars[ix]); + fprintf (file, "\""); } @@ -790,19 +770,12 @@ static void yyerror (const char *error_message) { struct prod_token_parm_item *tok; - + tok = yylval; if (tok) - { - fprintf (stderr, "%s:%i:%i: %s\n", tok->tp.tok.location.file, - tok->tp.tok.location.line, tok->tp.tok.charno, error_message); - print_token (stderr, 0, tok); - } + error ("%H%s", &tok->tp.tok.location, error_message); else - fprintf (stderr, "%s\n", error_message); - - errorcount++; - + error ("%s", error_message); } /* Reverse the order of a token list, linked by parse_next, old first @@ -821,6 +794,7 @@ reverse_prod_list (struct prod_token_parm_item *old_first) while (current) { gcc_assert (current->category == production_category); + next = current->tp.pro.next; current->tp.pro.next = prev; prev = current; @@ -835,13 +809,8 @@ static void ensure_not_void (unsigned int type, struct prod_token_parm_item* name) { if (type == VOID_TYPE) - { - fprintf (stderr, "%s:%i:%i: Type must not be void in this context\n", - name->tp.tok.location.file, - name->tp.tok.location.line, name->tp.tok.charno); - print_token (stderr, 0, name); - errorcount++; - } + error ("%HType must not be void in this context.", + &name->tp.tok.location); } /* Check TYPE1 and TYPE2 which are integral types. Return the lowest @@ -932,13 +901,15 @@ make_plus_expression (struct prod_token_parm_item* tok, NUMERIC_TYPE (prod) = type_code; type = tree_code_get_type (type_code); + gcc_assert (type); + OP1 (prod) = op1; OP2 (prod) = op2; - prod->tp.pro.code = tree_code_get_expression - (prod_code, type, op1->tp.pro.code, - op2->tp.pro.code, NULL); + prod->tp.pro.code = tree_code_get_expression (prod_code, type, + op1->tp.pro.code, + op2->tp.pro.code, NULL); return prod; } diff --git a/gcc/treelang/tree1.c b/gcc/treelang/tree1.c index a734615f091..26ef3bc7f98 100644 --- a/gcc/treelang/tree1.c +++ b/gcc/treelang/tree1.c @@ -129,7 +129,6 @@ treelang_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, default: gcc_unreachable (); - } return 1; @@ -140,12 +139,11 @@ treelang_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, bool treelang_init (void) { +#ifndef USE_MAPPED_LOCATION input_filename = main_input_filename; - input_line = 1; - - /* Init decls etc. */ - - treelang_init_decl_processing (); +#else + linemap_add (&line_table, LC_ENTER, false, main_input_filename, 1); +#endif /* This error will not happen from GCC as it will always create a fake input file. */ @@ -167,6 +165,14 @@ treelang_init (void) exit (1); } +#ifdef USE_MAPPED_LOCATION + linemap_add (&line_table, LC_RENAME, false, "<built-in>", 1); + linemap_line_start (&line_table, 0, 1); +#endif + + /* Init decls, etc. */ + treelang_init_decl_processing (); + return true; } @@ -183,9 +189,21 @@ treelang_finish (void) void treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED) { +#ifdef USE_MAPPED_LOCATION + source_location s; + linemap_add (&line_table, LC_RENAME, false, main_input_filename, 1); + s = linemap_line_start (&line_table, 1, 80); + input_location = s; +#else + input_line = 1; +#endif + treelang_debug (); yyparse (); cgraph_finalize_compilation_unit (); +#ifdef USE_MAPPED_LOCATION + linemap_add (&line_table, LC_LEAVE, false, NULL, 0); +#endif cgraph_optimize (); } @@ -257,10 +275,8 @@ insert_tree_name (struct prod_token_parm_item *prod) sanity_check (prod); if (lookup_tree_name (prod)) { - fprintf (stderr, "%s:%i:%i duplicate name %s\n", - tok->tp.tok.location.file, tok->tp.tok.location.line, - tok->tp.tok.charno, tok->tp.tok.chars); - errorcount++; + error ("%HDuplicate name %q.*s.", &tok->tp.tok.location, + tok->tp.tok.length, tok->tp.tok.chars); return 1; } prod->tp.pro.next = symbol_table; diff --git a/gcc/treelang/treetree.c b/gcc/treelang/treetree.c index ade0d9d99c7..adcda4398a8 100644 --- a/gcc/treelang/treetree.c +++ b/gcc/treelang/treetree.c @@ -686,7 +686,9 @@ tree_code_get_expression (unsigned int exp_type, gcc_assert (op1 && op2); operator = MODIFY_EXPR; ret1 = fold (build2 (operator, void_type_node, op1, - fold (build1 (CONVERT_EXPR, TREE_TYPE (op1), op2)))); + fold (build1 (CONVERT_EXPR, TREE_TYPE (op1), + op2)))); + break; case EXP_PLUS: @@ -837,24 +839,22 @@ tree_mark_addressable (tree exp) { if (TREE_PUBLIC (x)) { - error ("global register variable `%s' used in nested function", - IDENTIFIER_POINTER (DECL_NAME (x))); + error ("Global register variable %qD used in nested function.", + x); return 0; } - pedwarn ("register variable `%s' used in nested function", - IDENTIFIER_POINTER (DECL_NAME (x))); + pedwarn ("Register variable %qD used in nested function.", x); } else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)) { if (TREE_PUBLIC (x)) { - error ("address of global register variable `%s' requested", - IDENTIFIER_POINTER (DECL_NAME (x))); + error ("Address of global register variable %qD requested.", + x); return 0; } - pedwarn ("address of register variable `%s' requested", - IDENTIFIER_POINTER (DECL_NAME (x))); + pedwarn ("Address of register variable %qD requested.", x); } /* drops in */ |