GCC Middle and Back End API Reference
substring_loc Class Reference

#include <substring-locations.h>

Public Member Functions

 substring_loc (location_t fmt_string_loc, tree string_type, int caret_idx, int start_idx, int end_idx)
 
void set_caret_index (int caret_idx)
 
const char * get_location (location_t *out_loc) const
 
location_t get_fmt_string_loc () const
 
tree get_string_type () const
 
int get_caret_idx () const
 
int get_start_idx () const
 
int get_end_idx () const
 

Private Attributes

location_t m_fmt_string_loc
 
tree m_string_type
 
int m_caret_idx
 
int m_start_idx
 
int m_end_idx
 

Detailed Description

Source locations within string literals. Copyright (C) 2016-2025 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/>.
The substring_loc class encapsulates information on the source location of a range of characters within a STRING_CST. If needed by a diagnostic, the actual location_t of the substring_loc can be calculated by calling its get_location method. This calls a langhook, since this is inherently frontend-specific. For the C family of frontends, it calls back into libcpp to reparse the strings. This gets the location information "on demand", rather than storing the location information in the initial lex for every string. Thus the substring_loc can also be thought of as a deferred call into libcpp, to allow the non-trivial work of reparsing the string to be delayed until we actually need it (to emit a diagnostic for a particular range of characters). substring_loc::get_location returns NULL if it succeeds, or an error message if it fails. Error messages are intended for GCC developers (to help debugging) rather than for end-users. The easiest way to use a substring_loc is via the format_warning_* APIs, which gracefully handle failure of substring_loc::get_location by using the location of the string as a whole if substring-information is unavailable.

Constructor & Destructor Documentation

◆ substring_loc()

substring_loc::substring_loc ( location_t fmt_string_loc,
tree string_type,
int caret_idx,
int start_idx,
int end_idx )
inline

Member Function Documentation

◆ get_caret_idx()

int substring_loc::get_caret_idx ( ) const
inline

References m_caret_idx.

◆ get_end_idx()

int substring_loc::get_end_idx ( ) const
inline

References m_end_idx.

◆ get_fmt_string_loc()

location_t substring_loc::get_fmt_string_loc ( ) const
inline

References m_fmt_string_loc.

◆ get_location()

const char * substring_loc::get_location ( location_t * out_loc) const
Attempt to determine the source location of the substring. If successful, return NULL and write the source location to *OUT_LOC. Otherwise return an error message. Error messages are intended for GCC developers (to help debugging) rather than for end-users.

References gcc_assert, and lang_hooks::get_substring_location.

◆ get_start_idx()

int substring_loc::get_start_idx ( ) const
inline

References m_start_idx.

◆ get_string_type()

tree substring_loc::get_string_type ( ) const
inline

References m_string_type.

◆ set_caret_index()

void substring_loc::set_caret_index ( int caret_idx)
inline

References m_caret_idx.

Field Documentation

◆ m_caret_idx

int substring_loc::m_caret_idx
private

◆ m_end_idx

int substring_loc::m_end_idx
private

Referenced by get_end_idx(), and substring_loc().

◆ m_fmt_string_loc

location_t substring_loc::m_fmt_string_loc
private

◆ m_start_idx

int substring_loc::m_start_idx
private

Referenced by get_start_idx(), and substring_loc().

◆ m_string_type

tree substring_loc::m_string_type
private

Referenced by get_string_type(), and substring_loc().


The documentation for this class was generated from the following files: