Commit 0501dbd9 by David Malcolm Committed by David Malcolm

libcpp: Replace macro usage with C++ constructs

libcpp/ChangeLog:
	* include/line-map.h (MAX_SOURCE_LOCATION): Convert from a macro
	to a const source_location.
	(RESERVED_LOCATION_COUNT): Likewise.
	(linemap_check_ordinary): Convert from a macro to a pair of inline
	functions, for const/non-const arguments.
	(MAP_START_LOCATION): Likewise.
	(ORDINARY_MAP_STARTING_LINE_NUMBER): Likewise.
	(ORDINARY_MAP_INCLUDER_FILE_INDEX): Likewise.
	(ORDINARY_MAP_IN_SYSTEM_HEADER_P): Likewise.
	(ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): Convert from a macro to a
	pair of inline functions, for const/non-const arguments, where the
	latter is named...
	(SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): New function.
	(ORDINARY_MAP_FILE_NAME): Convert from a macro to a pair of inline
	functions, for const/non-const arguments.
	(MACRO_MAP_MACRO): Likewise.
	(MACRO_MAP_NUM_MACRO_TOKENS): Likewise.
	(MACRO_MAP_LOCATIONS): Likewise.
	(MACRO_MAP_EXPANSION_POINT_LOCATION): Likewise.
	(LINEMAPS_MAP_INFO): Likewise.
	(LINEMAPS_MAPS): Likewise.
	(LINEMAPS_ALLOCATED): Likewise.
	(LINEMAPS_USED): Likewise.
	(LINEMAPS_CACHE): Likewise.
	(LINEMAPS_ORDINARY_CACHE): Likewise.
	(LINEMAPS_MACRO_CACHE): Likewise.
	(LINEMAPS_MAP_AT): Convert from a macro to an inline function.
	(LINEMAPS_LAST_MAP): Likewise.
	(LINEMAPS_LAST_ALLOCATED_MAP): Likewise.
	(LINEMAPS_ORDINARY_MAPS): Likewise.
	(LINEMAPS_ORDINARY_MAP_AT): Likewise.
	(LINEMAPS_ORDINARY_ALLOCATED): Likewise.
	(LINEMAPS_ORDINARY_USED): Likewise.
	(LINEMAPS_LAST_ORDINARY_MAP): Likewise.
	(LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP): Likewise.
	(LINEMAPS_MACRO_MAPS): Likewise.
	(LINEMAPS_MACRO_MAP_AT): Likewise.
	(LINEMAPS_MACRO_ALLOCATED): Likewise.
	(LINEMAPS_MACRO_USED): Likewise.
	(LINEMAPS_MACRO_LOWEST_LOCATION): Likewise.
	(LINEMAPS_LAST_MACRO_MAP): Likewise.
	(LINEMAPS_LAST_ALLOCATED_MACRO_MAP): Likewise.
	(IS_ADHOC_LOC): Likewise.
	(COMBINE_LOCATION_DATA): Likewise.
	(SOURCE_LINE): Likewise.
	(SOURCE_COLUMN): Likewise.
	(LAST_SOURCE_LINE_LOCATION): Likewise.
	(LAST_SOURCE_LINE): Likewise.
	(LAST_SOURCE_COLUMN): Likewise.
	(LAST_SOURCE_LINE_LOCATION)
	(INCLUDED_FROM): Likewise.
	(MAIN_FILE_P): Likewise.
	(LINEMAP_FILE): Likewise.
	(LINEMAP_LINE): Likewise.
	(LINEMAP_SYSP): Likewise.
	(linemap_location_before_p): Likewise.
	* line-map.c (linemap_check_files_exited): Make local "map" const.
	(linemap_add): Use SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS.
	(linemap_line_start): Likewise.

From-SVN: r223152
parent 39ba2a0e
2015-05-13 David Malcolm <dmalcolm@redhat.com>
* include/line-map.h (MAX_SOURCE_LOCATION): Convert from a macro
to a const source_location.
(RESERVED_LOCATION_COUNT): Likewise.
(linemap_check_ordinary): Convert from a macro to a pair of inline
functions, for const/non-const arguments.
(MAP_START_LOCATION): Likewise.
(ORDINARY_MAP_STARTING_LINE_NUMBER): Likewise.
(ORDINARY_MAP_INCLUDER_FILE_INDEX): Likewise.
(ORDINARY_MAP_IN_SYSTEM_HEADER_P): Likewise.
(ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): Convert from a macro to a
pair of inline functions, for const/non-const arguments, where the
latter is named...
(SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): New function.
(ORDINARY_MAP_FILE_NAME): Convert from a macro to a pair of inline
functions, for const/non-const arguments.
(MACRO_MAP_MACRO): Likewise.
(MACRO_MAP_NUM_MACRO_TOKENS): Likewise.
(MACRO_MAP_LOCATIONS): Likewise.
(MACRO_MAP_EXPANSION_POINT_LOCATION): Likewise.
(LINEMAPS_MAP_INFO): Likewise.
(LINEMAPS_MAPS): Likewise.
(LINEMAPS_ALLOCATED): Likewise.
(LINEMAPS_USED): Likewise.
(LINEMAPS_CACHE): Likewise.
(LINEMAPS_ORDINARY_CACHE): Likewise.
(LINEMAPS_MACRO_CACHE): Likewise.
(LINEMAPS_MAP_AT): Convert from a macro to an inline function.
(LINEMAPS_LAST_MAP): Likewise.
(LINEMAPS_LAST_ALLOCATED_MAP): Likewise.
(LINEMAPS_ORDINARY_MAPS): Likewise.
(LINEMAPS_ORDINARY_MAP_AT): Likewise.
(LINEMAPS_ORDINARY_ALLOCATED): Likewise.
(LINEMAPS_ORDINARY_USED): Likewise.
(LINEMAPS_LAST_ORDINARY_MAP): Likewise.
(LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP): Likewise.
(LINEMAPS_MACRO_MAPS): Likewise.
(LINEMAPS_MACRO_MAP_AT): Likewise.
(LINEMAPS_MACRO_ALLOCATED): Likewise.
(LINEMAPS_MACRO_USED): Likewise.
(LINEMAPS_MACRO_LOWEST_LOCATION): Likewise.
(LINEMAPS_LAST_MACRO_MAP): Likewise.
(LINEMAPS_LAST_ALLOCATED_MACRO_MAP): Likewise.
(IS_ADHOC_LOC): Likewise.
(COMBINE_LOCATION_DATA): Likewise.
(SOURCE_LINE): Likewise.
(SOURCE_COLUMN): Likewise.
(LAST_SOURCE_LINE_LOCATION): Likewise.
(LAST_SOURCE_LINE): Likewise.
(LAST_SOURCE_COLUMN): Likewise.
(LAST_SOURCE_LINE_LOCATION)
(INCLUDED_FROM): Likewise.
(MAIN_FILE_P): Likewise.
(LINEMAP_FILE): Likewise.
(LINEMAP_LINE): Likewise.
(LINEMAP_SYSP): Likewise.
(linemap_location_before_p): Likewise.
* line-map.c (linemap_check_files_exited): Make local "map" const.
(linemap_add): Use SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS.
(linemap_line_start): Likewise.
2015-05-13 Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com> 2015-05-13 Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
* aclocal.m4: Regenerated with automake-1.11.6. * aclocal.m4: Regenerated with automake-1.11.6.
......
...@@ -155,7 +155,7 @@ struct GTY(()) line_map_ordinary { ...@@ -155,7 +155,7 @@ struct GTY(()) line_map_ordinary {
/* This is the highest possible source location encoded within an /* This is the highest possible source location encoded within an
ordinary or macro map. */ ordinary or macro map. */
#define MAX_SOURCE_LOCATION 0x7FFFFFFF const source_location MAX_SOURCE_LOCATION = 0x7FFFFFFF;
struct cpp_hashnode; struct cpp_hashnode;
...@@ -298,16 +298,10 @@ struct GTY(()) line_map { ...@@ -298,16 +298,10 @@ struct GTY(()) line_map {
#define linemap_assert_fails(EXPR) __extension__ \ #define linemap_assert_fails(EXPR) __extension__ \
({linemap_assert (EXPR); false;}) ({linemap_assert (EXPR); false;})
/* Assert that MAP encodes locations of tokens that are not part of
the replacement-list of a macro expansion. */
#define linemap_check_ordinary(LINE_MAP) __extension__ \
({linemap_assert (!linemap_macro_expansion_map_p (LINE_MAP)); \
(LINE_MAP);})
#else #else
/* Include EXPR, so that unused variable warnings do not occur. */ /* Include EXPR, so that unused variable warnings do not occur. */
#define linemap_assert(EXPR) ((void)(0 && (EXPR))) #define linemap_assert(EXPR) ((void)(0 && (EXPR)))
#define linemap_assert_fails(EXPR) (! (EXPR)) #define linemap_assert_fails(EXPR) (! (EXPR))
#define linemap_check_ordinary(LINE_MAP) (LINE_MAP)
#endif #endif
/* Return TRUE if MAP encodes locations coming from a macro /* Return TRUE if MAP encodes locations coming from a macro
...@@ -315,30 +309,196 @@ struct GTY(()) line_map { ...@@ -315,30 +309,196 @@ struct GTY(()) line_map {
bool bool
linemap_macro_expansion_map_p (const struct line_map *); linemap_macro_expansion_map_p (const struct line_map *);
#define MAP_START_LOCATION(MAP) (MAP)->start_location /* Assert that MAP encodes locations of tokens that are not part of
the replacement-list of a macro expansion. */
inline struct line_map *
linemap_check_ordinary (struct line_map *map)
{
linemap_assert (!linemap_macro_expansion_map_p (map));
return map;
}
/* Assert that MAP encodes locations of tokens that are not part of
the replacement-list of a macro expansion. */
inline const struct line_map *
linemap_check_ordinary (const struct line_map *map)
{
linemap_assert (!linemap_macro_expansion_map_p (map));
return map;
}
/* Read the start location of MAP, as an rvalue. */
inline source_location
MAP_START_LOCATION (const line_map *map)
{
return map->start_location;
}
/* Access the start location of MAP as a reference
(e.g. as an lvalue). */
inline source_location&
MAP_START_LOCATION (line_map *map)
{
return map->start_location;
}
/* Get the starting line number of ordinary map MAP. */
inline linenum_type
ORDINARY_MAP_STARTING_LINE_NUMBER (const line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.to_line;
}
/* Access the starting line number of ordinary map MAP by
reference (e.g. as an lvalue). */
inline linenum_type&
ORDINARY_MAP_STARTING_LINE_NUMBER (line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.to_line;
}
/* Get the index of the ordinary map at whose end
ordinary map MAP was included.
File(s) at the bottom of the include stack have this set. */
inline int
ORDINARY_MAP_INCLUDER_FILE_INDEX (const line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.included_from;
}
/* As above, but by reference (e.g. as an lvalue). */
inline int&
ORDINARY_MAP_INCLUDER_FILE_INDEX (line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.included_from;
}
/* Return a positive value if map encodes locations from a system
header, 0 otherwise. Returns 1 if ordinary map MAP encodes locations
in a system header and 2 if it encodes locations in a C system header
that therefore needs to be extern "C" protected in C++. */
inline unsigned char
ORDINARY_MAP_IN_SYSTEM_HEADER_P (const line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.sysp;
}
/* As above, but by reference (e.g. as an lvalue). */
inline unsigned char &
ORDINARY_MAP_IN_SYSTEM_HEADER_P (line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.sysp;
}
/* Get the number of the low-order source_location bits used for a
column number within ordinary map MAP. */
inline unsigned char
ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (const line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.column_bits;
}
/* Set the number of the low-order source_location bits used for a
column number within ordinary map MAP. */
inline void
SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (line_map *map, int col_bits)
{
linemap_check_ordinary (map)->d.ordinary.column_bits = col_bits;
}
/* Get the filename of ordinary map MAP. */
inline const char *
ORDINARY_MAP_FILE_NAME (const line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.to_file;
}
/* As above, but by reference (e.g. as an lvalue). */
inline const char * &
ORDINARY_MAP_FILE_NAME (line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.to_file;
}
/* Get the cpp macro whose expansion gave birth to macro map MAP. */
inline cpp_hashnode *
MACRO_MAP_MACRO (const line_map *map)
{
return map->d.macro.macro;
}
#define ORDINARY_MAP_FILE_NAME(MAP) \ /* As above, but by reference (e.g. as an lvalue). */
linemap_check_ordinary (MAP)->d.ordinary.to_file
#define ORDINARY_MAP_STARTING_LINE_NUMBER(MAP) \ inline cpp_hashnode * &
linemap_check_ordinary (MAP)->d.ordinary.to_line MACRO_MAP_MACRO (line_map *map)
{
return map->d.macro.macro;
}
#define ORDINARY_MAP_INCLUDER_FILE_INDEX(MAP) \ /* Get the number of tokens inside the replacement-list of the macro
linemap_check_ordinary (MAP)->d.ordinary.included_from that led to macro map MAP. */
#define ORDINARY_MAP_IN_SYSTEM_HEADER_P(MAP) \ inline unsigned int
linemap_check_ordinary (MAP)->d.ordinary.sysp MACRO_MAP_NUM_MACRO_TOKENS (const line_map *map)
{
return map->d.macro.n_tokens;
}
#define ORDINARY_MAP_NUMBER_OF_COLUMN_BITS(MAP) \ /* As above, but by reference (e.g. as an lvalue). */
linemap_check_ordinary (MAP)->d.ordinary.column_bits
#define MACRO_MAP_MACRO(MAP) (MAP)->d.macro.macro inline unsigned int &
MACRO_MAP_NUM_MACRO_TOKENS (line_map *map)
{
return map->d.macro.n_tokens;
}
#define MACRO_MAP_NUM_MACRO_TOKENS(MAP) (MAP)->d.macro.n_tokens /* Get the array of pairs of locations within macro map MAP.
See the declaration of line_map_macro for more information. */
#define MACRO_MAP_LOCATIONS(MAP) (MAP)->d.macro.macro_locations inline source_location *
MACRO_MAP_LOCATIONS (const line_map *map)
{
return map->d.macro.macro_locations;
}
#define MACRO_MAP_EXPANSION_POINT_LOCATION(MAP) (MAP)->d.macro.expansion /* As above, but by reference (e.g. as an lvalue). */
inline source_location * &
MACRO_MAP_LOCATIONS (line_map *map)
{
return map->d.macro.macro_locations;
}
/* Get the location of the expansion point of the macro map MAP. */
inline source_location
MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map *map)
{
return map->d.macro.expansion;
}
/* As above, but by reference (e.g. as an lvalue). */
inline source_location &
MACRO_MAP_EXPANSION_POINT_LOCATION (line_map *map)
{
return map->d.macro.expansion;
}
/* The abstraction of a set of location maps. There can be several /* The abstraction of a set of location maps. There can be several
types of location maps. This abstraction contains the attributes types of location maps. This abstraction contains the attributes
...@@ -430,119 +590,248 @@ struct GTY(()) line_maps { ...@@ -430,119 +590,248 @@ struct GTY(()) line_maps {
/* Returns the pointer to the memory region where information about /* Returns the pointer to the memory region where information about
maps are stored in the line table SET. MACRO_MAP_P is a flag maps are stored in the line table SET. MACRO_MAP_P is a flag
telling if we want macro or ordinary maps. */ telling if we want macro or ordinary maps. */
#define LINEMAPS_MAP_INFO(SET, MACRO_MAP_P) \ inline struct maps_info *
((MACRO_MAP_P) \ LINEMAPS_MAP_INFO (line_maps *set, bool macro_map_p)
? &((SET)->info_macro) \ {
: &((SET)->info_ordinary)) return (macro_map_p
? &(set->info_macro)
: &(set->info_ordinary));
}
/* As above, but preserving constness. */
inline const struct maps_info *
LINEMAPS_MAP_INFO (const line_maps *set, bool macro_map_p)
{
return (macro_map_p
? &(set->info_macro)
: &(set->info_ordinary));
}
/* Returns the pointer to the memory region where maps are stored in /* Returns the pointer to the memory region where maps are stored in
the line table SET. MAP_KIND shall be TRUE if we are interested in the line table SET. MAP_KIND shall be TRUE if we are interested in
macro maps false otherwise. */ macro maps false otherwise. */
#define LINEMAPS_MAPS(SET, MAP_KIND) \ inline line_map *
(LINEMAPS_MAP_INFO (SET, MAP_KIND))->maps LINEMAPS_MAPS (const line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->maps;
}
/* As above, but by reference (e.g. as an lvalue). */
inline line_map * &
LINEMAPS_MAPS (line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->maps;
}
/* Returns the number of allocated maps so far. MAP_KIND shall be TRUE /* Returns the number of allocated maps so far. MAP_KIND shall be TRUE
if we are interested in macro maps, FALSE otherwise. */ if we are interested in macro maps, FALSE otherwise. */
#define LINEMAPS_ALLOCATED(SET, MAP_KIND) \ inline unsigned int
(LINEMAPS_MAP_INFO (SET, MAP_KIND))->allocated LINEMAPS_ALLOCATED (const line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->allocated;
}
/* As above, but by reference (e.g. as an lvalue). */
inline unsigned int &
LINEMAPS_ALLOCATED (line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->allocated;
}
/* Returns the number of used maps so far. MAP_KIND shall be TRUE if /* Returns the number of used maps so far. MAP_KIND shall be TRUE if
we are interested in macro maps, FALSE otherwise.*/ we are interested in macro maps, FALSE otherwise.*/
#define LINEMAPS_USED(SET, MAP_KIND) \ inline unsigned int
(LINEMAPS_MAP_INFO (SET, MAP_KIND))->used LINEMAPS_USED (const line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->used;
}
/* As above, but by reference (e.g. as an lvalue). */
inline unsigned int &
LINEMAPS_USED (line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->used;
}
/* Returns the index of the last map that was looked up with /* Returns the index of the last map that was looked up with
linemap_lookup. MAP_KIND shall be TRUE if we are interested in linemap_lookup. MAP_KIND shall be TRUE if we are interested in
macro maps, FALSE otherwise. */ macro maps, FALSE otherwise. */
#define LINEMAPS_CACHE(SET, MAP_KIND) \ inline unsigned int
(LINEMAPS_MAP_INFO (SET, MAP_KIND))->cache LINEMAPS_CACHE (const line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->cache;
}
/* As above, but by reference (e.g. as an lvalue). */
inline unsigned int &
LINEMAPS_CACHE (line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->cache;
}
/* Return the map at a given index. */ /* Return the map at a given index. */
#define LINEMAPS_MAP_AT(SET, MAP_KIND, INDEX) \ inline line_map *
(&((LINEMAPS_MAPS (SET, MAP_KIND))[(INDEX)])) LINEMAPS_MAP_AT (const line_maps *set, bool map_kind, int index)
{
return &(LINEMAPS_MAPS (set, map_kind)[index]);
}
/* Returns the last map used in the line table SET. MAP_KIND /* Returns the last map used in the line table SET. MAP_KIND
shall be TRUE if we are interested in macro maps, FALSE shall be TRUE if we are interested in macro maps, FALSE
otherwise.*/ otherwise.*/
#define LINEMAPS_LAST_MAP(SET, MAP_KIND) \ inline line_map *
LINEMAPS_MAP_AT (SET, MAP_KIND, (LINEMAPS_USED (SET, MAP_KIND) - 1)) LINEMAPS_LAST_MAP (const line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_AT (set, map_kind,
LINEMAPS_USED (set, map_kind) - 1);
}
/* Returns the last map that was allocated in the line table SET. /* Returns the last map that was allocated in the line table SET.
MAP_KIND shall be TRUE if we are interested in macro maps, FALSE MAP_KIND shall be TRUE if we are interested in macro maps, FALSE
otherwise.*/ otherwise.*/
#define LINEMAPS_LAST_ALLOCATED_MAP(SET, MAP_KIND) \ inline line_map *
LINEMAPS_MAP_AT (SET, MAP_KIND, LINEMAPS_ALLOCATED (SET, MAP_KIND) - 1) LINEMAPS_LAST_ALLOCATED_MAP (const line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_AT (set, map_kind,
LINEMAPS_ALLOCATED (set, map_kind) - 1);
}
/* Returns a pointer to the memory region where ordinary maps are /* Returns a pointer to the memory region where ordinary maps are
allocated in the line table SET. */ allocated in the line table SET. */
#define LINEMAPS_ORDINARY_MAPS(SET) \ inline line_map *
LINEMAPS_MAPS (SET, false) LINEMAPS_ORDINARY_MAPS (const line_maps *set)
{
return LINEMAPS_MAPS (set, false);
}
/* Returns the INDEXth ordinary map. */ /* Returns the INDEXth ordinary map. */
#define LINEMAPS_ORDINARY_MAP_AT(SET, INDEX) \ inline line_map *
LINEMAPS_MAP_AT (SET, false, INDEX) LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index)
{
return LINEMAPS_MAP_AT (set, false, index);
}
/* Return the number of ordinary maps allocated in the line table /* Return the number of ordinary maps allocated in the line table
SET. */ SET. */
#define LINEMAPS_ORDINARY_ALLOCATED(SET) \ inline unsigned int
LINEMAPS_ALLOCATED(SET, false) LINEMAPS_ORDINARY_ALLOCATED (const line_maps *set)
{
return LINEMAPS_ALLOCATED (set, false);
}
/* Return the number of ordinary maps used in the line table SET. */ /* Return the number of ordinary maps used in the line table SET. */
#define LINEMAPS_ORDINARY_USED(SET) \ inline unsigned int
LINEMAPS_USED(SET, false) LINEMAPS_ORDINARY_USED (const line_maps *set)
{
return LINEMAPS_USED (set, false);
}
/* Return the index of the last ordinary map that was looked up with /* Return the index of the last ordinary map that was looked up with
linemap_lookup. */ linemap_lookup. */
#define LINEMAPS_ORDINARY_CACHE(SET) \ inline unsigned int
LINEMAPS_CACHE(SET, false) LINEMAPS_ORDINARY_CACHE (const line_maps *set)
{
return LINEMAPS_CACHE (set, false);
}
/* As above, but by reference (e.g. as an lvalue). */
inline unsigned int &
LINEMAPS_ORDINARY_CACHE (line_maps *set)
{
return LINEMAPS_CACHE (set, false);
}
/* Returns a pointer to the last ordinary map used in the line table /* Returns a pointer to the last ordinary map used in the line table
SET. */ SET. */
#define LINEMAPS_LAST_ORDINARY_MAP(SET) \ inline line_map *
LINEMAPS_LAST_MAP(SET, false) LINEMAPS_LAST_ORDINARY_MAP (const line_maps *set)
{
return LINEMAPS_LAST_MAP (set, false);
}
/* Returns a pointer to the last ordinary map allocated the line table /* Returns a pointer to the last ordinary map allocated the line table
SET. */ SET. */
#define LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP(SET) \ inline line_map *
LINEMAPS_LAST_ALLOCATED_MAP(SET, false) LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP (const line_maps *set)
{
return LINEMAPS_LAST_ALLOCATED_MAP (set, false);
}
/* Returns a pointer to the beginning of the region where macro maps /* Returns a pointer to the beginning of the region where macro maps
are allcoated. */ are allcoated. */
#define LINEMAPS_MACRO_MAPS(SET) \ inline line_map *
LINEMAPS_MAPS(SET, true) LINEMAPS_MACRO_MAPS (const line_maps *set)
{
return LINEMAPS_MAPS (set, true);
}
/* Returns the INDEXth macro map. */ /* Returns the INDEXth macro map. */
#define LINEMAPS_MACRO_MAP_AT(SET, INDEX) \ inline line_map *
LINEMAPS_MAP_AT (SET, true, INDEX) LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index)
{
return LINEMAPS_MAP_AT (set, true, index);
}
/* Returns the number of macro maps that were allocated in the line /* Returns the number of macro maps that were allocated in the line
table SET. */ table SET. */
#define LINEMAPS_MACRO_ALLOCATED(SET) \ inline unsigned int
LINEMAPS_ALLOCATED(SET, true) LINEMAPS_MACRO_ALLOCATED (const line_maps *set)
{
return LINEMAPS_ALLOCATED (set, true);
}
/* Returns the number of macro maps used in the line table SET. */ /* Returns the number of macro maps used in the line table SET. */
#define LINEMAPS_MACRO_USED(SET) \ inline unsigned int
LINEMAPS_USED(SET, true) LINEMAPS_MACRO_USED (const line_maps *set)
{
return LINEMAPS_USED (set, true);
}
/* Returns the index of the last macro map looked up with /* Returns the index of the last macro map looked up with
linemap_lookup. */ linemap_lookup. */
#define LINEMAPS_MACRO_CACHE(SET) \ inline unsigned int
LINEMAPS_CACHE(SET, true) LINEMAPS_MACRO_CACHE (const line_maps *set)
{
return LINEMAPS_CACHE (set, true);
}
/* Returns the lowest location [of a token resulting from macro /* As above, but by reference (e.g. as an lvalue). */
expansion] encoded in this line table. */
#define LINEMAPS_MACRO_LOWEST_LOCATION(SET) \ inline unsigned int &
(LINEMAPS_MACRO_USED (set) \ LINEMAPS_MACRO_CACHE (line_maps *set)
? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set)) \ {
: MAX_SOURCE_LOCATION) return LINEMAPS_CACHE (set, true);
}
/* Returns the last macro map used in the line table SET. */ /* Returns the last macro map used in the line table SET. */
#define LINEMAPS_LAST_MACRO_MAP(SET) \ inline line_map *
LINEMAPS_LAST_MAP (SET, true) LINEMAPS_LAST_MACRO_MAP (const line_maps *set)
{
return LINEMAPS_LAST_MAP (set, true);
}
/* Returns the lowest location [of a token resulting from macro
expansion] encoded in this line table. */
inline source_location
LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set)
{
return LINEMAPS_MACRO_USED (set)
? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))
: MAX_SOURCE_LOCATION;
}
/* Returns the last macro map allocated in the line table SET. */ /* Returns the last macro map allocated in the line table SET. */
#define LINEMAPS_LAST_ALLOCATED_MACRO_MAP(SET) \ inline line_map *
LINEMAPS_LAST_ALLOCATED_MAP (SET, true) LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set)
{
return LINEMAPS_LAST_ALLOCATED_MAP (set, true);
}
extern void location_adhoc_data_fini (struct line_maps *); extern void location_adhoc_data_fini (struct line_maps *);
extern source_location get_combined_adhoc_loc (struct line_maps *, extern source_location get_combined_adhoc_loc (struct line_maps *,
...@@ -551,9 +840,23 @@ extern void *get_data_from_adhoc_loc (struct line_maps *, source_location); ...@@ -551,9 +840,23 @@ extern void *get_data_from_adhoc_loc (struct line_maps *, source_location);
extern source_location get_location_from_adhoc_loc (struct line_maps *, extern source_location get_location_from_adhoc_loc (struct line_maps *,
source_location); source_location);
#define IS_ADHOC_LOC(LOC) (((LOC) & MAX_SOURCE_LOCATION) != (LOC)) /* Get whether location LOC is an ad-hoc location. */
#define COMBINE_LOCATION_DATA(SET, LOC, BLOCK) \
get_combined_adhoc_loc ((SET), (LOC), (BLOCK)) inline bool
IS_ADHOC_LOC (source_location loc)
{
return (loc & MAX_SOURCE_LOCATION) != loc;
}
/* Combine LOC and BLOCK, giving a combined adhoc location. */
inline source_location
COMBINE_LOCATION_DATA (struct line_maps *set,
source_location loc,
void *block)
{
return get_combined_adhoc_loc (set, loc, block);
}
extern void rebuild_location_adhoc_htab (struct line_maps *); extern void rebuild_location_adhoc_htab (struct line_maps *);
...@@ -631,47 +934,72 @@ bool linemap_location_from_macro_expansion_p (const struct line_maps *, ...@@ -631,47 +934,72 @@ bool linemap_location_from_macro_expansion_p (const struct line_maps *,
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will /* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
be reserved for libcpp user as special values, no token from libcpp be reserved for libcpp user as special values, no token from libcpp
will contain any of those locations. */ will contain any of those locations. */
#define RESERVED_LOCATION_COUNT 2 const int RESERVED_LOCATION_COUNT = 2;
/* Converts a map and a source_location to source line. */ /* Converts a map and a source_location to source line. */
#define SOURCE_LINE(MAP, LOC) \ inline linenum_type
(((((LOC) - linemap_check_ordinary (MAP)->start_location) \ SOURCE_LINE (const struct line_map *map, source_location loc)
>> (MAP)->d.ordinary.column_bits) + (MAP)->d.ordinary.to_line)) {
return ((loc - linemap_check_ordinary (map)->start_location)
>> map->d.ordinary.column_bits) + map->d.ordinary.to_line;
}
/* Convert a map and source_location to source column number. */ /* Convert a map and source_location to source column number. */
#define SOURCE_COLUMN(MAP, LOC) \ inline linenum_type
((((LOC) - linemap_check_ordinary (MAP)->start_location) \ SOURCE_COLUMN (const struct line_map *map, source_location loc)
& ((1 << (MAP)->d.ordinary.column_bits) - 1))) {
return ((loc - linemap_check_ordinary (map)->start_location)
& ((1 << map->d.ordinary.column_bits) - 1));
}
/* Return the location of the last source line within an ordinary
map. */
inline source_location
LAST_SOURCE_LINE_LOCATION (const struct line_map *map)
{
return (((linemap_check_ordinary (map)[1].start_location - 1
- map->start_location)
& ~((1 << map->d.ordinary.column_bits) - 1))
+ map->start_location);
}
/* Returns the last source line number within an ordinary map. This /* Returns the last source line number within an ordinary map. This
is the (last) line of the #include, or other directive, that caused is the (last) line of the #include, or other directive, that caused
a map change. */ a map change. */
#define LAST_SOURCE_LINE(MAP) \
SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP)) inline linenum_type
LAST_SOURCE_LINE (const struct line_map *map)
{
return SOURCE_LINE (map, LAST_SOURCE_LINE_LOCATION (map));
}
/* Return the last column number within an ordinary map. */ /* Return the last column number within an ordinary map. */
#define LAST_SOURCE_COLUMN(MAP) \
SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
/* Return the location of the last source line within an ordinary inline linenum_type
map. */ LAST_SOURCE_COLUMN (const struct line_map *map)
#define LAST_SOURCE_LINE_LOCATION(MAP) \ {
((((linemap_check_ordinary (MAP)[1].start_location - 1 \ return SOURCE_COLUMN (map, LAST_SOURCE_LINE_LOCATION (map));
- (MAP)->start_location) \ }
& ~((1 << (MAP)->d.ordinary.column_bits) - 1)) \
+ (MAP)->start_location))
/* Returns the map a given map was included from, or NULL if the map /* Returns the map a given map was included from, or NULL if the map
belongs to the main file, i.e, a file that wasn't included by belongs to the main file, i.e, a file that wasn't included by
another one. */ another one. */
#define INCLUDED_FROM(SET, MAP) \
((linemap_check_ordinary (MAP)->d.ordinary.included_from == -1) \
? NULL \
: (&LINEMAPS_ORDINARY_MAPS (SET)[(MAP)->d.ordinary.included_from]))
/* Nonzero if the map is at the bottom of the include stack. */ inline struct line_map *
#define MAIN_FILE_P(MAP) \ INCLUDED_FROM (struct line_maps *set, const struct line_map *map)
((linemap_check_ordinary (MAP)->d.ordinary.included_from < 0)) {
return ((linemap_check_ordinary (map)->d.ordinary.included_from == -1)
? NULL
: (&LINEMAPS_ORDINARY_MAPS (set)[(map)->d.ordinary.included_from]));
}
/* True if the map is at the bottom of the include stack. */
inline bool
MAIN_FILE_P (const struct line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.included_from < 0;
}
/* Encode and return a source_location from a column number. The /* Encode and return a source_location from a column number. The
source line considered is the last source line used to call source line considered is the last source line used to call
...@@ -695,19 +1023,28 @@ linemap_position_for_loc_and_offset (struct line_maps *set, ...@@ -695,19 +1023,28 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
unsigned int offset); unsigned int offset);
/* Return the file this map is for. */ /* Return the file this map is for. */
#define LINEMAP_FILE(MAP) \ inline const char *
(linemap_check_ordinary (MAP)->d.ordinary.to_file) LINEMAP_FILE (const struct line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.to_file;
}
/* Return the line number this map started encoding location from. */ /* Return the line number this map started encoding location from. */
#define LINEMAP_LINE(MAP) \ inline linenum_type
(linemap_check_ordinary (MAP)->d.ordinary.to_line) LINEMAP_LINE (const struct line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.to_line;
}
/* Return a positive value if map encodes locations from a system /* Return a positive value if map encodes locations from a system
header, 0 otherwise. Returns 1 if MAP encodes locations in a header, 0 otherwise. Returns 1 if MAP encodes locations in a
system header and 2 if it encodes locations in a C system header system header and 2 if it encodes locations in a C system header
that therefore needs to be extern "C" protected in C++. */ that therefore needs to be extern "C" protected in C++. */
#define LINEMAP_SYSP(MAP) \ inline unsigned char
(linemap_check_ordinary (MAP)->d.ordinary.sysp) LINEMAP_SYSP (const struct line_map *map)
{
return linemap_check_ordinary (map)->d.ordinary.sysp;
}
/* Return a positive value if PRE denotes the location of a token that /* Return a positive value if PRE denotes the location of a token that
comes before the token of POST, 0 if PRE denotes the location of comes before the token of POST, 0 if PRE denotes the location of
...@@ -720,8 +1057,13 @@ int linemap_compare_locations (struct line_maps *set, ...@@ -720,8 +1057,13 @@ int linemap_compare_locations (struct line_maps *set,
/* Return TRUE if LOC_A denotes the location a token that comes /* Return TRUE if LOC_A denotes the location a token that comes
topogically before the token denoted by location LOC_B, or if they topogically before the token denoted by location LOC_B, or if they
are equal. */ are equal. */
#define linemap_location_before_p(SET, LOC_A, LOC_B) \ inline bool
(linemap_compare_locations ((SET), (LOC_A), (LOC_B)) >= 0) linemap_location_before_p (struct line_maps *set,
source_location loc_a,
source_location loc_b)
{
return linemap_compare_locations (set, loc_a, loc_b) >= 0;
}
typedef struct typedef struct
{ {
......
...@@ -191,7 +191,7 @@ linemap_init (struct line_maps *set, ...@@ -191,7 +191,7 @@ linemap_init (struct line_maps *set,
void void
linemap_check_files_exited (struct line_maps *set) linemap_check_files_exited (struct line_maps *set)
{ {
struct line_map *map; const struct line_map *map;
/* Depending upon whether we are handling preprocessed input or /* Depending upon whether we are handling preprocessed input or
not, this can be a user error or an ICE. */ not, this can be a user error or an ICE. */
for (map = LINEMAPS_LAST_ORDINARY_MAP (set); for (map = LINEMAPS_LAST_ORDINARY_MAP (set);
...@@ -371,7 +371,7 @@ linemap_add (struct line_maps *set, enum lc_reason reason, ...@@ -371,7 +371,7 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
ORDINARY_MAP_FILE_NAME (map) = to_file; ORDINARY_MAP_FILE_NAME (map) = to_file;
ORDINARY_MAP_STARTING_LINE_NUMBER (map) = to_line; ORDINARY_MAP_STARTING_LINE_NUMBER (map) = to_line;
LINEMAPS_ORDINARY_CACHE (set) = LINEMAPS_ORDINARY_USED (set) - 1; LINEMAPS_ORDINARY_CACHE (set) = LINEMAPS_ORDINARY_USED (set) - 1;
ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map) = 0; SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map, 0);
set->highest_location = start_location; set->highest_location = start_location;
set->highest_line = start_location; set->highest_line = start_location;
set->max_column_hint = 0; set->max_column_hint = 0;
...@@ -564,7 +564,7 @@ linemap_line_start (struct line_maps *set, linenum_type to_line, ...@@ -564,7 +564,7 @@ linemap_line_start (struct line_maps *set, linenum_type to_line,
(map), (map),
ORDINARY_MAP_FILE_NAME (map), ORDINARY_MAP_FILE_NAME (map),
to_line); to_line);
ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map) = column_bits; SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map, column_bits);
r = (MAP_START_LOCATION (map) r = (MAP_START_LOCATION (map)
+ ((to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) + ((to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
<< column_bits)); << column_bits));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment