X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fc-lex.c;h=cbd557346f959fcdbf970922d45f343a5f68681a;hb=39c687d57d9f1542f265e51582a97fc145d2cb3f;hp=b6720da2b5bb388a6ce4b56a11565543623a205b;hpb=f0af5a8826645f54448b3b82f1ab364bd8952562;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/c-lex.c b/gcc/c-lex.c index b6720da2b5b..cbd557346f9 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -1,6 +1,6 @@ /* Mainly the interface between cpplib and the C front ends. Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997 - 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of GCC. @@ -42,12 +42,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "splay-tree.h" #include "debug.h" -/* The current line map. */ -static const struct line_map *map; - -/* The line used to refresh the lineno global variable after each token. */ -static unsigned int src_lineno; - /* We may keep statistics about how long which files took to compile. */ static int header_time, body_time; static splay_tree file_info_tree; @@ -195,25 +189,29 @@ cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, lexed token on the line. Used for diagnostic line numbers. */ static void cb_line_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const cpp_token *token, - int parsing_args ATTRIBUTE_UNUSED) + int parsing_args) { - src_lineno = SOURCE_LINE (map, token->line); + if (token->type != CPP_EOF && !parsing_args) + { + source_location loc = token->src_loc; + const struct line_map *map = linemap_lookup (&line_table, loc); + input_line = SOURCE_LINE (map, loc); + } } void fe_file_change (const struct line_map *new_map) { - unsigned int to_line = SOURCE_LINE (new_map, new_map->to_line); + if (new_map == NULL) + return; if (new_map->reason == LC_ENTER) { /* Don't stack the main buffer on the input stack; we already did in compile_file. */ - if (map == NULL) - main_input_filename = new_map->to_file; - else + if (! MAIN_FILE_P (new_map)) { - int included_at = SOURCE_LINE (new_map - 1, new_map->from_line - 1); + int included_at = LAST_SOURCE_LINE (new_map - 1); input_line = included_at; push_srcloc (new_map->to_file, 1); @@ -241,27 +239,27 @@ fe_file_change (const struct line_map *new_map) #endif pop_srcloc (); - (*debug_hooks->end_source_file) (to_line); + (*debug_hooks->end_source_file) (new_map->to_line); } update_header_times (new_map->to_file); in_system_header = new_map->sysp != 0; input_filename = new_map->to_file; - input_line = to_line; - map = new_map; + input_line = new_map->to_line; /* Hook for C++. */ extract_interface_info (); } static void -cb_def_pragma (cpp_reader *pfile, unsigned int line) +cb_def_pragma (cpp_reader *pfile, source_location loc) { /* Issue a warning message if we have been asked to do so. Ignore unknown pragmas in system headers unless an explicit -Wunknown-pragmas has been given. */ if (warn_unknown_pragmas > in_system_header) { + const struct line_map *map = linemap_lookup (&line_table, loc); const unsigned char *space, *name; const cpp_token *s; @@ -275,25 +273,27 @@ cb_def_pragma (cpp_reader *pfile, unsigned int line) name = cpp_token_as_text (pfile, s); } - input_line = SOURCE_LINE (map, line); + input_line = SOURCE_LINE (map, loc); warning ("ignoring #pragma %s %s", space, name); } } /* #define callback for DWARF and DWARF2 debug info. */ static void -cb_define (cpp_reader *pfile, unsigned int line, cpp_hashnode *node) +cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node) { - (*debug_hooks->define) (SOURCE_LINE (map, line), + const struct line_map *map = linemap_lookup (&line_table, loc); + (*debug_hooks->define) (SOURCE_LINE (map, loc), (const char *) cpp_macro_definition (pfile, node)); } /* #undef callback for DWARF and DWARF2 debug info. */ static void -cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, unsigned int line, +cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location loc, cpp_hashnode *node) { - (*debug_hooks->undef) (SOURCE_LINE (map, line), + const struct line_map *map = linemap_lookup (&line_table, loc); + (*debug_hooks->undef) (SOURCE_LINE (map, loc), (const char *) NODE_NAME (node)); } @@ -307,19 +307,15 @@ get_nonpadding_token (void) while (tok->type == CPP_PADDING); timevar_pop (TV_CPP); - /* The C++ front end does horrible things with the current line - number. To ensure an accurate line number, we must reset it - every time we advance a token. */ - input_line = src_lineno; - return tok; } int -c_lex (tree *value) +c_lex_with_flags (tree *value, unsigned char *cpp_flags) { const cpp_token *tok; location_t atloc; + static bool no_more_pch; retry: tok = get_nonpadding_token (); @@ -421,9 +417,23 @@ c_lex (tree *value) break; } + if (! no_more_pch) + { + no_more_pch = true; + c_common_no_more_pch (); + } + + if (cpp_flags) + *cpp_flags = tok->flags; return tok->type; } +int +c_lex (tree *value) +{ + return c_lex_with_flags (value, NULL); +} + /* Returns the narrowest C-visible unsigned type, starting with the minimum specified by FLAGS, that can fit VALUE, or itk_none if there isn't one. */