/* Map logical line numbers to (source file, line number) pairs.
Copyright (C) 2001, 2003, 2004, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING3. If not see
.
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
#ifndef LIBCPP_LINE_MAP_H
#define LIBCPP_LINE_MAP_H
#ifndef GTY
#define GTY(x) /* nothing */
#endif
/* Reason for adding a line change with add_line_map (). LC_ENTER is
when including a new file, e.g. a #include directive in C.
LC_LEAVE is when reaching a file's end. LC_RENAME is when a file
name or line number changes for neither of the above reasons
(e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME
but a filename of "" is not specially interpreted as standard input. */
enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME, LC_RENAME_VERBATIM};
/* The type of line numbers. */
typedef unsigned int linenum_type;
/* A logical line/column number, i.e. an "index" into a line_map. */
typedef unsigned int source_location;
/* Memory allocation function typedef. Works like xrealloc. */
typedef void *(*line_map_realloc) (void *, size_t);
/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
by the logical START_LOCATION. TO_LINE+L at column C is represented by
START_LOCATION+(L*(1<start_location) >> (MAP)->column_bits) + (MAP)->to_line)
#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 LAST_SOURCE_LINE(MAP) \
SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
#define LAST_SOURCE_COLUMN(MAP) \
SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
#define LAST_SOURCE_LINE_LOCATION(MAP) \
((((MAP)[1].start_location - 1 - (MAP)->start_location) \
& ~((1 << (MAP)->column_bits) - 1)) \
+ (MAP)->start_location)
/* Returns the map a given map was included from. */
#define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])
/* Nonzero if the map is at the bottom of the include stack. */
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
/* Set LOC to a source position that is the same line as the most recent
linemap_line_start, but with the specified TO_COLUMN column number. */
#define LINEMAP_POSITION_FOR_COLUMN(LOC, SET, TO_COLUMN) do { \
unsigned int to_column = (TO_COLUMN); \
struct line_maps *set = (SET); \
if (__builtin_expect (to_column >= set->max_column_hint, 0)) \
(LOC) = linemap_position_for_column (set, to_column); \
else { \
source_location r = set->highest_line; \
r = r + to_column; \
if (r >= set->highest_location) \
set->highest_location = r; \
(LOC) = r; \
}} while (0)
extern source_location
linemap_position_for_column (struct line_maps *set, unsigned int to_column);
#endif /* !LIBCPP_LINE_MAP_H */