From 1bb64668d0fbb2abfa3583918a256420028eea30 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Mon, 21 Jul 2008 09:33:38 +0000 Subject: [PATCH] line-map.h (linenum_type): New typedef. 2008-07-21 Manuel Lopez-Ibanez * include/line-map.h (linenum_type): New typedef. (struct line_map): Use it. (SOURCE_LINE): Second arguments is a LOCATION not a LINE. (SOURCE_COLUMN): Likewise. * macro.c (_cpp_builtin_macro_text): Use linenum_type. Don't store source_location values in a variable of type linenum_type. * directives.c (struct if_stack): Use linenum_type. (strtoul_for_line): Rename as strtolinenum. (do_line): Use linenum_type. (do_linemarker): Use linenum_type and strtolinenum. (_cpp_do_file_change): Use linenum_t. * line-map.c (linemap_add): Likewise. (linemap_line_start): Likewise. * traditional.c (struct fun_macro): 'line' is a source_location. * errors.c (print_location): Use linenum_type. * directives-only.c (_cpp_preprocess_dir_only): Likewise. * internal.h (CPP_INCREMENT_LINE): Likewise. * lex.c (_cpp_skip_block_comment): Use source_location. From-SVN: r138026 --- libcpp/ChangeLog | 21 +++++++++++++++++++++ libcpp/directives-only.c | 3 ++- libcpp/directives.c | 24 ++++++++++++------------ libcpp/errors.c | 2 +- libcpp/include/line-map.h | 17 ++++++++++------- libcpp/internal.h | 4 ++-- libcpp/lex.c | 2 +- libcpp/line-map.c | 6 +++--- libcpp/macro.c | 11 +++++------ libcpp/traditional.c | 2 +- 10 files changed, 58 insertions(+), 34 deletions(-) diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 9b3b53e25de..f8ec058a47a 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,24 @@ +2008-07-21 Manuel Lopez-Ibanez + + * include/line-map.h (linenum_type): New typedef. + (struct line_map): Use it. + (SOURCE_LINE): Second arguments is a LOCATION not a LINE. + (SOURCE_COLUMN): Likewise. + * macro.c (_cpp_builtin_macro_text): Use linenum_type. Don't store + source_location values in a variable of type linenum_type. + * directives.c (struct if_stack): Use linenum_type. + (strtoul_for_line): Rename as strtolinenum. + (do_line): Use linenum_type. + (do_linemarker): Use linenum_type and strtolinenum. + (_cpp_do_file_change): Use linenum_t. + * line-map.c (linemap_add): Likewise. + (linemap_line_start): Likewise. + * traditional.c (struct fun_macro): 'line' is a source_location. + * errors.c (print_location): Use linenum_type. + * directives-only.c (_cpp_preprocess_dir_only): Likewise. + * internal.h (CPP_INCREMENT_LINE): Likewise. + * lex.c (_cpp_skip_block_comment): Use source_location. + 2008-07-14 Ben Elliston * include/cpplib.h (NODE_CONDITIONAL): New. diff --git a/libcpp/directives-only.c b/libcpp/directives-only.c index d50cebbdae3..addd9a755dc 100644 --- a/libcpp/directives-only.c +++ b/libcpp/directives-only.c @@ -42,7 +42,8 @@ _cpp_preprocess_dir_only (cpp_reader *pfile, const unsigned char *cur, *base, *next_line, *rlimit; cppchar_t c, last_c; unsigned flags; - int lines, col; + linenum_type lines; + int col; source_location loc; restart: diff --git a/libcpp/directives.c b/libcpp/directives.c index 370f4ff5b0d..90933eb4807 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -32,7 +32,7 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ struct if_stack { struct if_stack *next; - unsigned int line; /* Line where condition started. */ + linenum_type line; /* Line where condition started. */ const cpp_hashnode *mi_cmacro;/* macro name for #ifndef around entire file */ bool skip_elses; /* Can future #else / #elif be skipped? */ bool was_skipping; /* If were skipping on entry. */ @@ -102,7 +102,7 @@ static char *glue_header_name (cpp_reader *); static const char *parse_include (cpp_reader *, int *, const cpp_token ***); static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *); static unsigned int read_flag (cpp_reader *, unsigned int); -static int strtoul_for_line (const uchar *, unsigned int, unsigned long *); +static int strtolinenum (const uchar *, unsigned int, linenum_type *); static void do_diagnostic (cpp_reader *, int, int); static cpp_hashnode *lex_macro_node (cpp_reader *, bool); static int undefine_macros (cpp_reader *, cpp_hashnode *, void *); @@ -840,9 +840,9 @@ read_flag (cpp_reader *pfile, unsigned int last) of length LEN, to binary; store it in NUMP, and return 0 if the number was well-formed, 1 if not. Temporary, hopefully. */ static int -strtoul_for_line (const uchar *str, unsigned int len, long unsigned int *nump) +strtolinenum (const uchar *str, unsigned int len, linenum_type *nump) { - unsigned long reg = 0; + linenum_type reg = 0; uchar c; while (len--) { @@ -871,16 +871,16 @@ do_line (cpp_reader *pfile) unsigned char map_sysp = map->sysp; const cpp_token *token; const char *new_file = map->to_file; - unsigned long new_lineno; + linenum_type new_lineno; /* C99 raised the minimum limit on #line numbers. */ - unsigned int cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767; + linenum_type cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767; /* #line commands expand macros. */ token = cpp_get_token (pfile); if (token->type != CPP_NUMBER - || strtoul_for_line (token->val.str.text, token->val.str.len, - &new_lineno)) + || strtolinenum (token->val.str.text, token->val.str.len, + &new_lineno)) { if (token->type == CPP_EOF) cpp_error (pfile, CPP_DL_ERROR, "unexpected end of file after #line"); @@ -925,7 +925,7 @@ do_linemarker (cpp_reader *pfile) const struct line_map *map = &line_table->maps[line_table->used - 1]; const cpp_token *token; const char *new_file = map->to_file; - unsigned long new_lineno; + linenum_type new_lineno; unsigned int new_sysp = map->sysp; enum lc_reason reason = LC_RENAME; int flag; @@ -938,8 +938,8 @@ do_linemarker (cpp_reader *pfile) /* #line commands expand macros. */ token = cpp_get_token (pfile); if (token->type != CPP_NUMBER - || strtoul_for_line (token->val.str.text, token->val.str.len, - &new_lineno)) + || strtolinenum (token->val.str.text, token->val.str.len, + &new_lineno)) { /* Unlike #line, there does not seem to be a way to get an EOF here. So, it should be safe to always spell the token. */ @@ -999,7 +999,7 @@ do_linemarker (cpp_reader *pfile) and zero otherwise. */ void _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, - const char *to_file, unsigned int file_line, + const char *to_file, linenum_type file_line, unsigned int sysp) { const struct line_map *map = linemap_add (pfile->line_table, reason, sysp, diff --git a/libcpp/errors.c b/libcpp/errors.c index 5e8e637276d..e3d56292848 100644 --- a/libcpp/errors.c +++ b/libcpp/errors.c @@ -42,7 +42,7 @@ print_location (cpp_reader *pfile, source_location line, unsigned int col) else { const struct line_map *map; - unsigned int lin; + linenum_type lin; map = linemap_lookup (pfile->line_table, line); linemap_print_containing_files (pfile->line_table, map); diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 3378315238f..81e888bc20f 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -34,6 +34,9 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. (e.g. a #line directive in C). */ enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME}; +/* The type of line numbers. */ +typedef unsigned int linenum_type; + /* A logical line/column number, i.e. an "index" into a line_map. */ /* Long-term, we want to use this to replace struct location_s (in input.h), and effectively typedef source_location location_t. */ @@ -57,7 +60,7 @@ typedef void *(*line_map_realloc) (void *, size_t); struct line_map GTY(()) { const char *to_file; - unsigned int to_line; + linenum_type to_line; source_location start_location; int included_from; ENUM_BITFIELD (lc_reason) reason : CHAR_BIT; @@ -119,7 +122,7 @@ extern void linemap_check_files_exited (struct line_maps *); the highest_location). */ extern source_location linemap_line_start -(struct line_maps *set, unsigned int to_line, unsigned int max_column_hint); +(struct line_maps *set, linenum_type to_line, unsigned int max_column_hint); /* Add a mapping of logical source line to physical source file and line number. @@ -134,7 +137,7 @@ extern source_location linemap_line_start maps, so any stored line_map pointers should not be used. */ extern const struct line_map *linemap_add (struct line_maps *, enum lc_reason, unsigned int sysp, - const char *to_file, unsigned int to_line); + const char *to_file, linenum_type to_line); /* Given a logical line, returns the map from which the corresponding (source file, line) pair can be deduced. */ @@ -148,11 +151,11 @@ extern void linemap_print_containing_files (struct line_maps *, const struct line_map *); /* Converts a map and a source_location to source line. */ -#define SOURCE_LINE(MAP, LINE) \ - ((((LINE) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line) +#define SOURCE_LINE(MAP, LOC) \ + ((((LOC) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line) -#define SOURCE_COLUMN(MAP, LINE) \ - (((LINE) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1)) +#define SOURCE_COLUMN(MAP, LOC) \ + (((LOC) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1)) /* Returns the last source line within a map. This is the (last) line of the #include, or other directive, that caused a map change. */ diff --git a/libcpp/internal.h b/libcpp/internal.h index 4fb4e431b81..c5bf35eab84 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -68,7 +68,7 @@ struct cset_converter #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \ const struct line_maps *line_table = PFILE->line_table; \ const struct line_map *map = &line_table->maps[line_table->used-1]; \ - unsigned int line = SOURCE_LINE (map, line_table->highest_line); \ + linenum_type line = SOURCE_LINE (map, line_table->highest_line); \ linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \ } while (0) @@ -585,7 +585,7 @@ extern int _cpp_do__Pragma (cpp_reader *); extern void _cpp_init_directives (cpp_reader *); extern void _cpp_init_internal_pragmas (cpp_reader *); extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *, - unsigned int, unsigned int); + linenum_type, unsigned int); extern void _cpp_pop_buffer (cpp_reader *); /* In directives.c */ diff --git a/libcpp/lex.c b/libcpp/lex.c index c1e009da06b..2eb66bd6342 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -384,7 +384,7 @@ static int skip_line_comment (cpp_reader *pfile) { cpp_buffer *buffer = pfile->buffer; - unsigned int orig_line = pfile->line_table->highest_line; + source_location orig_line = pfile->line_table->highest_line; while (*buffer->cur != '\n') buffer->cur++; diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 2c6d2510e61..964a7cd9a77 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -85,7 +85,7 @@ linemap_free (struct line_maps *set) const struct line_map * linemap_add (struct line_maps *set, enum lc_reason reason, - unsigned int sysp, const char *to_file, unsigned int to_line) + unsigned int sysp, const char *to_file, linenum_type to_line) { struct line_map *map; source_location start_location = set->highest_location + 1; @@ -182,13 +182,13 @@ linemap_add (struct line_maps *set, enum lc_reason reason, } source_location -linemap_line_start (struct line_maps *set, unsigned int to_line, +linemap_line_start (struct line_maps *set, linenum_type to_line, unsigned int max_column_hint) { struct line_map *map = &set->maps[set->used - 1]; source_location highest = set->highest_location; source_location r; - unsigned int last_line = SOURCE_LINE (map, set->highest_line); + linenum_type last_line = SOURCE_LINE (map, set->highest_line); int line_delta = to_line - last_line; bool add_map = false; if (line_delta < 0 diff --git a/libcpp/macro.c b/libcpp/macro.c index 1563d780d6f..9a470ef460b 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -118,7 +118,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) { const struct line_map *map; const uchar *result = NULL; - unsigned int number = 1; + linenum_type number = 1; switch (node->value.builtin) { @@ -200,11 +200,10 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) /* If __LINE__ is embedded in a macro, it must expand to the line of the macro's invocation, not its definition. Otherwise things like assert() will not work properly. */ - if (CPP_OPTION (pfile, traditional)) - number = pfile->line_table->highest_line; - else - number = pfile->cur_token[-1].src_loc; - number = SOURCE_LINE (map, number); + number = SOURCE_LINE (map, + CPP_OPTION (pfile, traditional) + ? pfile->line_table->highest_line + : pfile->cur_token[-1].src_loc); break; /* __STDC__ has the value 1 under normal circumstances. diff --git a/libcpp/traditional.c b/libcpp/traditional.c index 1a384253a90..d23fffe72ca 100644 --- a/libcpp/traditional.c +++ b/libcpp/traditional.c @@ -60,7 +60,7 @@ struct fun_macro size_t offset; /* The line the macro name appeared on. */ - unsigned int line; + source_location line; /* Zero-based index of argument being currently lexed. */ unsigned int argc; -- 2.30.2