#include "system.h"
#include "coretypes.h"
#include "tm.h"
-#include "diagnostic.h"
+#include "input.h"
+#include "errors.h"
#include "tree.h"
/* Token defs. */
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);
{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
%%
{
- /* 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;
}
[^\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]);
}
%%
/* 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++;
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]);
#include "system.h"
#include "coretypes.h"
#include "tm.h"
-#include "diagnostic.h"
+#include "errors.h"
#include "timevar.h"
#include "treelang.h"
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,
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;
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;
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,
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
}
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);
}
}
}
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);
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 ();
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;
}
init:
ASSIGN init_element {
+ $$ = $2;
}
;
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, "\"");
}
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
while (current)
{
gcc_assert (current->category == production_category);
+
next = current->tp.pro.next;
current->tp.pro.next = prev;
prev = current;
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
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;
}
default:
gcc_unreachable ();
-
}
return 1;
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. */
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;
}
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 ();
}
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;