GCC Middle and Back End API Reference
input.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "intl.h"
#include "diagnostic.h"
#include "selftest.h"
#include "cpplib.h"
Include dependency graph for input.cc:

Data Structures

class  file_cache_slot
 
class  file_cache_slot::line_info
 
class  auto_cpp_string_vec
 

Macros

#define HAVE_ICONV   0
 

Functions

const char * special_fname_builtin ()
 
static const char * default_charset_callback (const char *)
 
static const char * find_end_of_line (const char *s, size_t len)
 
static expanded_location expand_location_1 (const line_maps *set, location_t loc, bool expansion_point_p, enum location_aspect aspect)
 
static size_t total_lines_num (const char *file_path)
 
char * get_source_text_between (file_cache &fc, location_t start, location_t end)
 
bool is_location_from_builtin_token (location_t loc)
 
expanded_location expand_location (location_t loc)
 
expanded_location expand_location_to_spelling_point (location_t loc, enum location_aspect aspect)
 
expanded_location linemap_client_expand_location_to_spelling_point (const line_maps *set, location_t loc, enum location_aspect aspect)
 
location_t expansion_point_location_if_in_system_header (location_t location)
 
location_t expansion_point_location (location_t location)
 
location_t make_location (location_t caret, location_t start, location_t finish)
 
location_t make_location (location_t caret, source_range src_range)
 
int location_compute_display_column (file_cache &fc, expanded_location exploc, const cpp_char_column_policy &policy)
 
void dump_line_table_statistics (void)
 
static location_t get_end_location (class line_maps *set, line_map_uint_t idx)
 
static void write_digit (FILE *stream, int digit)
 
static void write_digit_row (FILE *stream, int indent, const line_map_ordinary *map, location_t loc, int max_col, int divisor)
 
static void dump_location_range (FILE *stream, location_t start, location_t end)
 
static void dump_labelled_location_range (FILE *stream, const char *name, location_t start, location_t end)
 
void dump_location_info (FILE *stream)
 
static const char * get_substring_ranges_for_loc (cpp_reader *pfile, file_cache &fc, string_concat_db *concats, location_t strloc, enum cpp_ttype type, cpp_substring_ranges &ranges)
 
const char * get_location_within_string (cpp_reader *pfile, file_cache &fc, string_concat_db *concats, location_t strloc, enum cpp_ttype type, int caret_idx, int start_idx, int end_idx, location_t *out_loc)
 
location_t location_with_discriminator (location_t locus, int discriminator)
 
bool has_discriminator (location_t locus)
 
int get_discriminator_from_loc (location_t locus)
 

Variables

location_t input_location = UNKNOWN_LOCATION
 
class line_maps * line_table
 
class line_maps * saved_line_table
 

Macro Definition Documentation

◆ HAVE_ICONV

#define HAVE_ICONV   0
Data and functions related to line maps and input files.
   Copyright (C) 2004-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC 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.

GCC 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 GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   

Function Documentation

◆ default_charset_callback()

static const char * default_charset_callback ( const char * )
static
Input charset configuration.   

Referenced by file_cache::initialize_input_context().

◆ dump_labelled_location_range()

static void dump_labelled_location_range ( FILE * stream,
const char * name,
location_t start,
location_t end )
static
Write a labelled description of a half-closed (START) / half-open (END)
interval of location_t to STREAM.   

References dump_location_range(), and end().

Referenced by dump_location_info().

◆ dump_line_table_statistics()

void dump_line_table_statistics ( void )
Dump statistics to stderr about the memory usage of the line_table
set of line maps.  This also displays some statistics about macro
expansion.   

References line_table, PRsa, and SIZE_AMOUNT.

Referenced by dump_memory_report().

◆ dump_location_info()

void dump_location_info ( FILE * stream)

◆ dump_location_range()

static void dump_location_range ( FILE * stream,
location_t start,
location_t end )
static
Write a half-closed (START) / half-open (END) interval of
location_t to STREAM.   

References end().

Referenced by dump_labelled_location_range(), and dump_location_info().

◆ expand_location()

◆ expand_location_1()

static expanded_location expand_location_1 ( const line_maps * set,
location_t loc,
bool expansion_point_p,
enum location_aspect aspect )
static
Expand the source location LOC into a human readable location.  If
LOC resolves to a builtin location, the file name of the readable
location is set to the string "<built-in>". If EXPANSION_POINT_P is
TRUE and LOC is virtual, then it is resolved to the expansion
point of the involved macro.  Otherwise, it is resolved to the
spelling location of the token.

When resolving to the spelling location of the token, if the
resulting location is for a built-in location (that is, it has no
associated line/column) in the context of a macro expansion, the
returned location is the first one (while unwinding the macro
location towards its expansion point) that is in real source
code.

ASPECT controls which part of the location to use.   

References BUILTINS_LOCATION, expand_location_1(), gcc_unreachable, get_finish(), get_start(), LOCATION_BLOCK, LOCATION_LOCUS, map, NULL, special_fname_builtin(), and UNKNOWN_LOCATION.

Referenced by expand_location(), expand_location_1(), expand_location_to_spelling_point(), and linemap_client_expand_location_to_spelling_point().

◆ expand_location_to_spelling_point()

expanded_location expand_location_to_spelling_point ( location_t loc,
enum location_aspect aspect )
Expand the source location LOC into a human readable location.  If
LOC is virtual, it resolves to the expansion location of the
relevant macro.  If LOC resolves to a builtin location, the file
name of the readable location is set to the string
"<built-in>".   

References expand_location_1(), and line_table.

Referenced by get_source_text_between(), get_substring_ranges_for_loc(), and maybe_unwind_expanded_macro_loc().

◆ expansion_point_location()

location_t expansion_point_location ( location_t location)
If LOCATION is a virtual location for a token coming from the expansion
of a macro, unwind to the location of the expansion point of the macro.   

References line_table, and NULL.

◆ expansion_point_location_if_in_system_header()

location_t expansion_point_location_if_in_system_header ( location_t location)
If LOCATION is in a system header and if it is a virtual location
for a token coming from the expansion of a macro, unwind it to
the location of the expansion point of the macro.  If the expansion
point is also in a system header return the original LOCATION.
Otherwise, return the location of the expansion point.

This is used for instance when we want to emit diagnostics about a
token that may be located in a macro that is itself defined in a
system header, for example, for the NULL macro.  In such a case, if
LOCATION were passed directly to diagnostic functions such as
warning_at, the diagnostic would be suppressed (unless
-Wsystem-headers).   

References in_system_header_at(), line_table, and NULL.

Referenced by pass_walloca::execute(), gimple_or_expr_nonartificial_location(), gimplify_va_arg_expr(), set_inlining_locations(), tree_inlined_location(), and warn_string_no_nul().

◆ find_end_of_line()

static const char * find_end_of_line ( const char * s,
size_t len )
static
Helper function for file_cache_slot::get_next_line (), to find the end of
the next line.  Returns with the memchr convention, i.e. nullptr if a line
terminator was not found.  We need to determine line endings in the same
manner that libcpp does: any of \n, \r\n, or \r is a line ending.   

References end().

Referenced by file_cache_slot::get_next_line(), and file_cache_slot::set_content().

◆ get_discriminator_from_loc()

int get_discriminator_from_loc ( location_t locus)

◆ get_end_location()

static location_t get_end_location ( class line_maps * set,
line_map_uint_t idx )
static
Get location one beyond the final location in ordinary map IDX.   

Referenced by dump_location_info().

◆ get_location_within_string()

const char * get_location_within_string ( cpp_reader * pfile,
file_cache & fc,
string_concat_db * concats,
location_t strloc,
enum cpp_ttype type,
int caret_idx,
int start_idx,
int end_idx,
location_t * out_loc )
Attempt to populate *OUT_LOC with source location information on the
given characters within the string literal found at STRLOC.
CARET_IDX, START_IDX, and END_IDX refer to offsets within the execution
character set.

For example, given CARET_IDX = 4, START_IDX = 3, END_IDX  = 7
and string literal "012345\n789"
*OUT_LOC is written to with:
  "012345\n789"
      ~^~~~~

If CONCATS is non-NULL, then any string literals that the token at
STRLOC was concatenated with are also considered.

This is implemented by re-parsing the relevant source line(s).

Return NULL if successful, or an error message if any errors occurred.
Error messages are intended for GCC developers (to help debugging) rather
than for end-users.   

References gcc_assert, gcc_checking_assert, get_substring_ranges_for_loc(), make_location(), and NULL.

◆ get_source_text_between()

char * get_source_text_between ( file_cache & fc,
location_t start,
location_t end )
Return a NUL-terminated copy of the source text between two locations, or
NULL if the arguments are invalid.  The caller is responsible for freeing
the return value.   

References end(), expand_location_to_spelling_point(), char_span::get_buffer(), file_cache::get_source_line(), char_span::length(), NULL, obstack, char_span::subspan(), and char_span::xstrdup().

◆ get_substring_ranges_for_loc()

static const char * get_substring_ranges_for_loc ( cpp_reader * pfile,
file_cache & fc,
string_concat_db * concats,
location_t strloc,
enum cpp_ttype type,
cpp_substring_ranges & ranges )
static
Attempt to populate RANGES with source location information on the
individual characters within the string literal found at STRLOC.
If CONCATS is non-NULL, then any string literals that the token at
STRLOC  was concatenated with are also added to RANGES.

Return NULL if successful, or an error message if any errors occurred (in
which case RANGES may be only partially populated and should not
be used).

This is implemented by re-parsing the relevant source line(s).   

References expand_location_to_spelling_point(), gcc_assert, file_cache::get_source_line(), string_concat_db::get_string_concatenation(), i, char_span::length(), line_table, NULL, char_span::subspan(), UNKNOWN_LOCATION, and char_span::xstrdup().

Referenced by get_location_within_string().

◆ has_discriminator()

bool has_discriminator ( location_t locus)
Return TRUE if LOCUS represents a location with a discriminator.   

References get_discriminator_from_loc().

Referenced by assign_discriminators().

◆ is_location_from_builtin_token()

bool is_location_from_builtin_token ( location_t loc)
Test if the location originates from the spelling location of a
builtin-tokens.  That is, return TRUE if LOC is a (possibly
virtual) location of a built-in token that appears in the expansion
list of a macro.  Please note that this function also works on
tokens that result from built-in tokens.  For instance, the
function would return true if passed a token "4" that is the result
of the expansion of the built-in __LINE__ macro.   

References BUILTINS_LOCATION, line_table, map, and NULL.

◆ linemap_client_expand_location_to_spelling_point()

expanded_location linemap_client_expand_location_to_spelling_point ( const line_maps * set,
location_t loc,
enum location_aspect aspect )
The rich_location class within libcpp requires a way to expand
location_t instances, and relies on the client code
providing a symbol named
  linemap_client_expand_location_to_spelling_point
to do this.

This is the implementation for libcommon.a (all host binaries),
which simply calls into expand_location_1.   

References expand_location_1().

◆ location_compute_display_column()

int location_compute_display_column ( file_cache & fc,
expanded_location exploc,
const cpp_char_column_policy & policy )
An expanded_location stores the column in byte units.  This function
converts that column to display units.  That requires reading the associated
source line in order to calculate the display width.  If that cannot be done
for any reason, then returns the byte column as a fallback.   

References char_span::get_buffer(), file_cache::get_source_line(), and char_span::length().

Referenced by convert_column_unit(), and sarif_builder::get_sarif_column().

◆ location_with_discriminator()

location_t location_with_discriminator ( location_t locus,
int discriminator )
Associate the DISCRIMINATOR with LOCUS, and return a new locus.  

References get_pure_location(), line_table, LOCATION_BLOCK, and UNKNOWN_LOCATION.

Referenced by lto_location_cache::apply_location_cache(), assign_discriminator(), and assign_discriminators().

◆ make_location() [1/2]

location_t make_location ( location_t caret,
location_t start,
location_t finish )
Construct a location with caret at CARET, ranging from START to
FINISH.

For example, consider:

              11111111112
     12345678901234567890
  522
  523   return foo + bar;
               ~~~~^~~~~
  524

The location's caret is at the "+", line 523 column 15, but starts
earlier, at the "f" of "foo" at column 11.  The finish is at the "r"
of "bar" at column 19.   

References line_table.

Referenced by get_location_within_string().

◆ make_location() [2/2]

location_t make_location ( location_t caret,
source_range src_range )
Same as above, but taking a source range rather than two locations.   

References get_pure_location(), and line_table.

◆ special_fname_builtin()

const char * special_fname_builtin ( )
Returns the translated string referring to the special location.   

References _.

Referenced by expand_location_1(), and diagnostic_column_policy::get_location_text().

◆ total_lines_num()

static size_t total_lines_num ( const char * file_path)
static
Return the total lines number that have been read so far by the
line map (in the preprocessor) so far.  For languages like C++ that
entirely preprocess the input file before starting to parse, this
equals the actual number of lines of the file.   

References expand_location(), gcc_assert, line_table, and r.

Referenced by file_cache_slot::create().

◆ write_digit()

static void write_digit ( FILE * stream,
int digit )
static
Helper function for write_digit_row.   

References fputc().

Referenced by write_digit_row().

◆ write_digit_row()

static void write_digit_row ( FILE * stream,
int indent,
const line_map_ordinary * map,
location_t loc,
int max_col,
int divisor )
static
Helper function for dump_location_info.
Write a row of numbers to STREAM, numbering a source line,
giving the units, tens, hundreds etc of the column number.   

References map, and write_digit().

Referenced by dump_location_info().

Variable Documentation

◆ input_location

location_t input_location = UNKNOWN_LOCATION
Current position in real source file.   

Referenced by add_new_plugin(), add_sysrooted_hdrs_prefix(), add_sysrooted_prefix(), cgraph_node::analyze(), analyze_functions(), array_type_nelts_top(), asan_global_struct(), asm_clobber_reg_is_valid(), assemble_asm(), assign_assembler_name_if_needed(), build_cxa_dtor_registrations(), build_fn_decl(), c_strlen(), cgraph_build_static_cdtor_1(), check_global_declaration(), close_at_file(), collect_execute(), collect_wait(), compare_debug_dump_opt_spec_function(), compare_debug_self_opt_spec_function(), compare_version_strings(), compile_images_for_offload_targets(), compile_offload_image(), compute_branch_probabilities(), construct_exit_block(), copy_file(), copy_phis_for_bb(), create_tmp_var_raw(), cgraph_node::create_version_clone_with_body(), debug_level_greater_than_spec_func(), decl_attributes(), default_plugin_dir_name(), do_merge(), do_merge_stream(), do_rewrite(), do_self_spec(), do_spec_1(), do_wait(), driver_handle_option(), dumps_spec_func(), dwarf_version_greater_than_spec_func(), dynamic_object_sizes_execute_one(), error(), eval_spec_function(), execute(), cgraph_node::expand(), expand_asm_stmt(), expand_call_inline(), expand_function_end(), expand_gimple_stmt(), expand_ifn_va_arg_1(), expand_omp(), expand_thunk(), finalize(), finalize_record_size(), find_crtoffloadtable(), fixup_call_stmt_edges_1(), fold_builtin_next_arg(), fold_builtin_strlen(), fold_undefer_overflow_warnings(), force_gimple_operand_1(), gcov_output_files(), general_init(), varpool_node::get_constructor(), get_coverage_counts(), get_file_function_name(), cgraph_node::get_untransformed_body(), getenv_spec_function(), ggc_pch_finish(), ggc_pch_read(), ggc_pch_write_object(), gimplify_adjust_omp_clauses_1(), gimplify_asm_expr(), gimplify_body(), gimplify_call_expr(), gimplify_expr(), gimplify_omp_for(), gimplify_omp_taskloop_expr(), driver::global_initializations(), gt_pch_restore(), gt_pch_save(), handle_braces(), handle_ignored_attributes_option(), handle_spec_function(), input_offload_tables(), input_symtab(), instrument_object_size(), internal_error(), internal_error_no_backtrace(), internal_get_tmp_var(), ipa_fn_summary_read(), ipa_reference_read_optimization_summary(), lang_dependent_init(), load_specs(), location_for_asm(), lookup_compiler(), lower_omp(), lower_omp_1(), lower_omp_target(), lto_check_version(), lto_input_ts_poly_tree_pointers(), lto_section_overrun(), lto_value_range_error(), main(), main(), make_node(), driver::maybe_print_and_exit(), driver::maybe_run_linker(), maybe_run_lto_and_relink(), maybe_unlink(), merge_and_complain(), merge_profile_summaries(), new_omp_context(), open_at_file(), open_auxiliary_file(), open_graph_file(), used_arg_t::operator()(), parse_options_from_collect_gcc_options(), place_field(), poly_int_read_common(), driver::prepare_infiles(), print_multilib_info(), process_brace_body(), process_command(), process_options(), read_specs(), gcc::pass_manager::register_pass(), remap_gimple_stmt(), run_attempt(), run_gcc(), toplev::run_self_tests(), scan_omp(), scan_omp_1_stmt(), scan_prog_file(), self_referential_size(), set_multilib_dir(), setup_core_dumping(), shortcut_cond_expr(), size_in_bytes(), sorry(), std_gimplify_va_arg_expr(), thunk_adjust(), tree_function_versioning(), ubsan_create_data(), ubsan_get_source_location_type(), ubsan_get_type_descriptor_type(), ubsan_instrument_float_cast(), unpack_ts_function_decl_value_fields(), version_compare_spec_function(), walk_gimple_stmt(), warning(), and write_pch_globals().

◆ line_table

◆ saved_line_table

class line_maps* saved_line_table
A stashed copy of "line_table" for use by selftest::line_table_test.
This needs to be a global so that it can be a GC root, and thus
prevent the stashed copy from being garbage-collected if the GC runs
during a line_table_test.