+2003-05-06 Nathan Sidwell <nathan@codesourcery.com>
+
+ * Make-lang.in (treelang/tree1.o): Depends on input.h
+ (treelang/treetree.o, treelang/parse.o, treelang/lex.o): Likewise.
+ * treelang.h: #include input.h.
+ (in_fname): Remove.
+ (struct token_part): Remove lineno, add location.
+ * lex.l (next_tree_lineno): Remove.
+ (update_lineno_charno): Adjust.
+ (dump_lex_value): Adjust.
+ * parse.y (variable_def, function_prototype, function, statement,
+ if_statement, return, function_invocation, variable_ref): Adjust.
+ (print_token, yyerror, ensure_not_void): Adjust.
+ tree1.c (in_fname): Remove.
+ (treelang_init): Setup input_location.
+ (lookup_tree_name): Adjust.
+ (insert_tree_name): Adjust.
+ * treetree.c (tree_code_if_start): Replace filename and lineno
+ parms with loc. Adjust.
+ (tree_code_if_else, tree_code_if_end,
+ tree_code_create_function_prototype,
+ tree_code_create_function_initial,
+ tree_code_create_function_wrapup, tree_code_create_variable,
+ tree_code_output_expression_statement): Likewise.
+ * treetree.h (tree_code_if_start): Replace filename and lineno
+ parms with loc.
+ (tree_code_if_else, tree_code_if_end,
+ tree_code_create_function_prototype,
+ tree_code_create_function_initial,
+ tree_code_create_function_wrapup, tree_code_create_variable,
+ tree_code_output_expression_statement): Likewise.
+
2003-05-01 Nathan Sidwell <nathan@codesourcery.com>
* tree1.c (treelang_init): Rename lineno to input_line.
treelang/tree1.o: treelang/tree1.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
flags.h toplev.h $(GGC_H) $(TREE_H) diagnostic.h treelang/treelang.h \
- treelang/treetree.h \
+ input.h treelang/treetree.h \
treelang/treetree.h gt-treelang-tree1.h gtype-treelang.h
treelang/treetree.o: treelang/treetree.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(TREE_H) flags.h output.h $(C_TREE_H) $(RTL_H) $(GGC_H) toplev.h \
- varray.h $(LANGHOOKS_DEF_H) langhooks.h treelang/treelang.h \
+ varray.h $(LANGHOOKS_DEF_H) langhooks.h treelang/treelang.h input.h \
treelang/treetree.h treelang/parse.h
treelang/parse.o: treelang/parse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
- $(TM_H) diagnostic.h treelang/treelang.h treelang/treetree.h
+ $(TM_H) diagnostic.h treelang/treelang.h input.h treelang/treetree.h
treelang/lex.o: treelang/lex.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
- $(TM_H) diagnostic.h $(TREE_H) treelang/treelang.h treelang/parse.h
+ $(TM_H) diagnostic.h $(TREE_H) treelang/treelang.h input.h treelang/parse.h
# generated files the files from lex and yacc are put into the source
# directory in case someone wants to build but does not have
int yylex (void);
void update_yylval (int a);
-static int next_tree_lineno=1;
static int next_tree_charno=1;
static void update_lineno_charno (void);
{
/* Should really allocate only what we need. lll;. */
yylval = my_malloc (sizeof (struct prod_token_parm_item));
- ((struct prod_token_parm_item *)yylval)->tp.tok.lineno = next_tree_lineno;
+ ((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", in_fname,
- ((struct prod_token_parm_item *)yylval)->tp.tok.lineno,
- ((struct prod_token_parm_item *)yylval)->tp.tok.charno, yytext[0]);
+ 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++;
}
/* Update the values we send to caller in case we sometimes don't
tell them about all the 'tokens' eg comments etc. */
int yyl;
- ((struct prod_token_parm_item *)yylval)->tp.tok.lineno = next_tree_lineno;
+ ((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
for ( yyl = 0; yyl < yyleng; ++yyl )
{
if ( yytext[yyl] == '\n' )
{
- ++next_tree_lineno;
+ ++input_line;
next_tree_charno = 1;
}
else
{
int ix;
fprintf (stderr, " %d l:%d c:%d ln:%d text=", lexret,
- ((struct prod_token_parm_item *) yylval)->tp.tok.lineno,
+ ((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);
for (ix = 0; ix < yyleng; ix++)
abort ();
if (STORAGE_CLASS (prod) == EXTERNAL_REFERENCE_STORAGE)
{
- fprintf (stderr, "%s:%i:%i: External reference variables may not have initial value\n", in_fname,
- tok->tp.tok.lineno, tok->tp.tok.charno);
+ 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;
((struct prod_token_parm_item*)SYMBOL_TABLE_NAME (prod))->tp.tok.length,
NUMERIC_TYPE (prod),
VAR_INIT (prod)? ((struct prod_token_parm_item*)VAR_INIT (prod))->tp.pro.code:NULL,
- in_fname,
- tok->tp.tok.lineno);
+ tok->tp.tok.location);
if (!prod->tp.pro.code)
abort ();
}
break;
case AUTOMATIC_STORAGE:
- fprintf (stderr, "%s:%i:%i: A function cannot be automatic\n", in_fname,
- tok->tp.tok.lineno, tok->tp.tok.charno);
+ 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++;
YYERROR;
prod->tp.pro.code = tree_code_create_function_prototype
(tok->tp.tok.chars, STORAGE_CLASS (prod), NUMERIC_TYPE (type),
- first_parms, in_fname, tok->tp.tok.lineno);
-
+ first_parms, tok->tp.tok.location);
}
;
current_function = proto = lookup_tree_name (&search_prod);
if (!proto)
{
- fprintf (stderr, "%s:%i:%i: Function prototype not found\n", in_fname,
- tok->tp.tok.lineno, tok->tp.tok.charno);
+ 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++;
YYERROR;
if (!proto->tp.pro.code)
abort ();
tree_code_create_function_initial
- (proto->tp.pro.code, in_fname, tok->tp.tok.lineno,
+ (proto->tp.pro.code, tok->tp.tok.location,
FIRST_PARMS (current_function));
/* Check all the parameters have code. */
variable_defs_opt statements_opt RIGHT_BRACE {
struct prod_token_parm_item* tok;
tok = $1;
- tree_code_create_function_wrapup (in_fname, tok->tp.tok.lineno);
+ tree_code_create_function_wrapup (tok->tp.tok.location);
current_function = NULL;
}
;
expression SEMICOLON {
struct prod_token_parm_item *exp;
exp = $1;
- tree_code_output_expression_statement (exp->tp.pro.code, in_fname, exp->tp.pro.main_token->tp.tok.lineno);
+ tree_code_output_expression_statement (exp->tp.pro.code,
+ exp->tp.pro.main_token->tp.tok.location);
}
|return SEMICOLON {
/* Nothing to do. */
tok = $1;
exp = $3;
ensure_not_void (NUMERIC_TYPE (exp), exp->tp.pro.main_token);
- tree_code_if_start (exp->tp.pro.code, in_fname, tok->tp.tok.lineno);
+ tree_code_if_start (exp->tp.pro.code, tok->tp.tok.location);
}
LEFT_BRACE statements_opt RIGHT_BRACE {
/* Just let the statements flow. */
ELSE {
struct prod_token_parm_item* tok;
tok = $1;
- tree_code_if_else (in_fname, tok->tp.tok.lineno);
+ tree_code_if_else (tok->tp.tok.location);
}
LEFT_BRACE statements_opt RIGHT_BRACE {
struct prod_token_parm_item* tok;
tok = $12;
- tree_code_if_end (in_fname, tok->tp.tok.lineno);
+ tree_code_if_end (tok->tp.tok.location);
}
;
tree_code_generate_return (type_prod->tp.pro.code, NULL);
else
{
- fprintf (stderr, "%s:%i:%i: Redundant expression in return\n", in_fname,
- ret_tok->tp.tok.lineno, ret_tok->tp.tok.charno);
+ 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);
print_token (stderr, 0, ret_tok);
errorcount++;
tree_code_generate_return (type_prod->tp.pro.code, NULL);
else
if ($2 == NULL)
{
- fprintf (stderr, "%s:%i:%i: Expression missing in return\n", in_fname,
- ret_tok->tp.tok.lineno, ret_tok->tp.tok.charno);
+ 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);
print_token (stderr, 0, ret_tok);
errorcount++;
}
proto = lookup_tree_name (&search_prod);
if (!proto)
{
- fprintf (stderr, "%s:%i:%i: Function prototype not found\n", in_fname,
- tok->tp.tok.lineno, tok->tp.tok.charno);
+ 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++;
YYERROR;
if (exp_count != exp_proto_count)
{
- fprintf (stderr, "%s:%i:%i: expression count mismatch with prototype\n", in_fname,
- tok->tp.tok.lineno, tok->tp.tok.charno);
+ 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++;
YYERROR;
symbol_table_entry = lookup_tree_name (&search_prod);
if (!symbol_table_entry)
{
- fprintf (stderr, "%s:%i:%i: Variable referred to but not defined\n", in_fname,
- tok->tp.tok.lineno, tok->tp.tok.charno);
+ 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++;
YYERROR;
unsigned int ix;
tok = value;
- fprintf (file, "%d \"", tok->tp.tok.lineno);
+ fprintf (file, "%d \"", tok->tp.tok.location.line);
for (ix = 0; ix < tok->tp.tok.length; ix++)
fprintf (file, "%c", tok->tp.tok.chars[ix]);
fprintf (file, "\"");
tok = yylval;
if (tok)
{
- fprintf (stderr, "%s:%i:%i: %s\n", in_fname, tok->tp.tok.lineno, tok->tp.tok.charno, error_message);
+ 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);
}
else
{
if (type == VOID)
{
- fprintf (stderr, "%s:%i:%i: Type must not be void in this context\n", in_fname,
- name->tp.tok.lineno, name->tp.tok.charno);
+ 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++;
}
/* Local variables. */
-const char *in_fname; /* Input file name. */
-
/* This is 1 if we have output the version string. */
static int version_done = 0;
bool
treelang_init ()
{
- in_fname = main_input_filename;
-
- /* Set up the declarations needed for this front end. */
+ input_filename = main_input_filename;
input_line = 0;
/* Init decls etc. */
/* This error will not happen from GCC as it will always create a
fake input file. */
- if (!in_fname || in_fname[0] == ' ' || !in_fname[0])
+ if (!input_filename || input_filename[0] == ' ' || !input_filename[0])
{
if (!version_done)
{
return false;
}
- yyin = fopen (in_fname, "r");
+ yyin = fopen (input_filename, "r");
if (!yyin)
{
- fprintf (stderr, "Unable to open input file %s\n", in_fname);
+ fprintf (stderr, "Unable to open input file %s\n", input_filename);
exit (1);
}
if (memcmp (tok->tp.tok.chars, this_tok->tp.tok.chars, this_tok->tp.tok.length))
continue;
if (option_parser_trace)
- fprintf (stderr, "Found symbol %s (%i:%i) as %i \n", tok->tp.tok.chars,
- tok->tp.tok.lineno, tok->tp.tok.charno, NUMERIC_TYPE (this));
+ fprintf (stderr, "Found symbol %s (%i:%i) as %i \n",
+ tok->tp.tok.chars,
+ tok->tp.tok.location.line, tok->tp.tok.charno,
+ NUMERIC_TYPE (this));
return this;
}
if (option_parser_trace)
- fprintf (stderr, "Not found symbol %s (%i:%i) as %i \n", tok->tp.tok.chars,
- tok->tp.tok.lineno, tok->tp.tok.charno, tok->type);
+ fprintf (stderr, "Not found symbol %s (%i:%i) as %i \n",
+ tok->tp.tok.chars,
+ tok->tp.tok.location.line, tok->tp.tok.charno, tok->type);
return NULL;
}
sanity_check (prod);
if (lookup_tree_name (prod))
{
- fprintf (stderr, "%s:%i:%i duplicate name %s\n", in_fname, tok->tp.tok.lineno,
+ 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++;
return 1;
*/
+#include "input.h"
+
/* Parse structure type. */
enum category_enum
{ /* These values less likely to be there by chance unlike 0/1,
parameter_category = 333
};
-/* Input file name and FILE. */
-extern const char* in_fname;
+/* Input file FILE. */
extern FILE* yyin;
/* Forward references to satisfy mutually recursive definitions. */
struct token_part GTY(())
{
- unsigned int lineno;
+ location_t location;
unsigned int charno;
unsigned int length; /* The value. */
unsigned char* chars;
LINENO in file FILENAME. */
void
-tree_code_if_start (tree exp, const char* filename, int lineno)
+tree_code_if_start (tree exp, location_t loc)
{
tree cond_exp;
cond_exp = build (NE_EXPR,
TREE_TYPE (exp),
exp,
build1 (CONVERT_EXPR, TREE_TYPE (exp), integer_zero_node));
- emit_line_note (filename, lineno); /* Output the line number information. */
+ emit_line_note (loc.file, loc.line); /* Output the line number information. */
expand_start_cond (cond_exp, /* Exit-able if nonzero. */ 0);
}
at line LINENO in file FILENAME. */
void
-tree_code_if_else (const char* filename, int lineno)
+tree_code_if_else (location_t loc)
{
- emit_line_note (filename, lineno); /* Output the line number information. */
+ emit_line_note (loc.file, loc.line); /* Output the line number information. */
expand_start_else ();
}
at line LINENO in file FILENAME. */
void
-tree_code_if_end (const char* filename, int lineno)
+tree_code_if_end (location_t loc)
{
- emit_line_note (filename, lineno); /* Output the line number information. */
+ emit_line_note (loc.file, loc.line); /* Output the line number information. */
expand_end_cond ();
}
tree
tree_code_create_function_prototype (unsigned char* chars,
- unsigned int storage_class,
- unsigned int ret_type,
- struct prod_token_parm_item* parms,
- const char* filename,
- int lineno)
+ unsigned int storage_class,
+ unsigned int ret_type,
+ struct prod_token_parm_item* parms,
+ location_t loc)
{
tree id;
fn_decl = build_decl (FUNCTION_DECL, id, fn_type);
DECL_CONTEXT (fn_decl) = NULL_TREE; /* Nested functions not supported here. */
- DECL_SOURCE_FILE (fn_decl) = filename;
- /* if (lineno > 1000000)
- ; */ /* Probably the line # is rubbish because someone forgot to set
- the line number - and unfortunately impossible line #s are used as
- magic flags at various times. The longest known function for
- example is about 550,000 lines (it was written in COBOL). */
- DECL_SOURCE_LINE (fn_decl) = lineno;
+ DECL_SOURCE_LOCATION (fn_decl) = loc;
TREE_USED (fn_decl) = 1;
parameter details are in the lists PARMS. Returns nothing. */
void
tree_code_create_function_initial (tree prev_saved,
- const char* filename,
- int lineno,
- struct prod_token_parm_item* parms)
+ location_t loc,
+ struct prod_token_parm_item* parms)
{
tree fn_decl;
tree param_decl;
current_function_decl = fn_decl;
DECL_INITIAL (fn_decl) = error_mark_node;
- DECL_SOURCE_FILE (fn_decl) = filename;
- DECL_SOURCE_LINE (fn_decl) = lineno;
+ DECL_SOURCE_LOCATION (fn_decl) = loc;
/* Prepare creation of rtl for a new function. */
resultdecl = DECL_RESULT (fn_decl) = build_decl (RESULT_DECL, NULL_TREE, TREE_TYPE (TREE_TYPE (fn_decl)));
DECL_CONTEXT (DECL_RESULT (fn_decl)) = fn_decl;
- DECL_SOURCE_FILE (resultdecl) = filename;
- DECL_SOURCE_LINE (resultdecl) = lineno;
+ DECL_SOURCE_LOCATION (resultdecl) = loc;
+
/* Work out the size. ??? is this needed. */
layout_decl (DECL_RESULT (fn_decl), 0);
if (!fn_decl)
abort ();
DECL_CONTEXT (parm_decl) = fn_decl;
- DECL_SOURCE_FILE (parm_decl) = filename;
- DECL_SOURCE_LINE (parm_decl) = lineno;
+ DECL_SOURCE_LOCATION (parm_decl) = loc;
parm_list = chainon (parm_decl, parm_list);
}
make_decl_rtl (fn_decl, NULL);
/* Use filename/lineno from above. */
- init_function_start (fn_decl, filename, lineno);
+ init_function_start (fn_decl, loc.file, loc.line);
/* Create rtl for startup code of function, such as saving registers. */
expand_start_bindings (0);
- emit_line_note (filename, lineno); /* Output the line number information. */
+ emit_line_note (loc.file, loc.line); /* Output the line number information. */
}
/* Wrapup a function contained in file FILENAME, ending at line LINENO. */
void
-tree_code_create_function_wrapup (const char* filename,
- int lineno)
+tree_code_create_function_wrapup (location_t loc)
{
tree block;
tree fn_decl;
fn_decl = current_function_decl;
- emit_line_note (filename, lineno); /* Output the line number information. */
+ emit_line_note (loc.file, loc.line); /* Output the line number information. */
/* Get completely built level from debugger symbol table. */
/* Emit rtl for end of function. */
- expand_function_end (filename, lineno, 0);
+ expand_function_end (loc.file, loc.line, 0);
/* Pop the level. */
tree
tree_code_create_variable (unsigned int storage_class,
- unsigned char* chars,
- unsigned int length,
- unsigned int expression_type,
- tree init,
- const char* filename,
- int lineno)
+ unsigned char* chars,
+ unsigned int length,
+ unsigned int expression_type,
+ tree init,
+ location_t loc)
{
tree var_type;
tree var_id;
DECL_CONTEXT (var_decl) = current_function_decl;
- DECL_SOURCE_FILE (var_decl) = filename;
- DECL_SOURCE_LINE (var_decl) = lineno;
+ DECL_SOURCE_LOCATION (var_decl) = loc;
/* Set the storage mode and whether only visible in the same file. */
switch (storage_class)
void
tree_code_output_expression_statement (tree code,
- const char* filename, int lineno)
+ location_t loc)
{
/* Output the line number information. */
- emit_line_note (filename, lineno);
+ emit_line_note (loc.file, loc.line);
TREE_USED (code) = 1;
TREE_SIDE_EFFECTS (code) = 1;
expand_expr_stmt (code);
tree tree_code_get_expression (unsigned int exp_type, tree type, tree op1, tree op2, tree op3);
tree tree_code_get_numeric_type (unsigned int size1, unsigned int sign1);
void tree_code_create_function_initial (tree prev_saved,
- const char* filename, int lineno,
- struct prod_token_parm_item* parms);
-void tree_code_create_function_wrapup (const char* filename, int lineno);
+ location_t loc,
+ struct prod_token_parm_item* parms);
+void tree_code_create_function_wrapup (location_t loc);
tree tree_code_create_function_prototype (unsigned char* chars,
- unsigned int storage_class,
- unsigned int ret_type,
- struct prod_token_parm_item* parms,
- const char* filename,
- int lineno);
+ unsigned int storage_class,
+ unsigned int ret_type,
+ struct prod_token_parm_item* parms,
+ location_t loc);
tree tree_code_create_variable (unsigned int storage_class,
- unsigned char* chars,
- unsigned int length,
- unsigned int expression_type,
- tree init,
- const char* filename,
- int lineno);
-void tree_code_output_expression_statement (tree code, const char* filename, int lineno);
+ unsigned char* chars,
+ unsigned int length,
+ unsigned int expression_type,
+ tree init,
+ location_t loc);
+void tree_code_output_expression_statement (tree code,
+ location_t loc);
tree get_type_for_numeric_type (unsigned int numeric_type);
-void tree_code_if_start (tree exp, const char* filename, int lineno);
-void tree_code_if_else (const char* filename, int lineno);
-void tree_code_if_end (const char* filename, int lineno);
+void tree_code_if_start (tree exp, location_t loc);
+void tree_code_if_else (location_t loc);
+void tree_code_if_end (location_t loc);
tree tree_code_get_type (int type_num);
void treelang_init_decl_processing (void);
void treelang_finish (void);