+2008-07-21 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ * 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 <bje@au.ibm.com>
* include/cpplib.h (NODE_CONDITIONAL): New.
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:
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. */
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 *);
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--)
{
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");
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;
/* #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. */
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,
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);
(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. */
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;
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.
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. */
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. */
#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)
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 */
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++;
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;
}
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
{
const struct line_map *map;
const uchar *result = NULL;
- unsigned int number = 1;
+ linenum_type number = 1;
switch (node->value.builtin)
{
/* 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.
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;