GCC Middle and Back End API Reference
input.h
Go to the documentation of this file.
1/* Declarations for variables relating to reading the source file.
2 Used by parsers, lexical analyzers, and error message routines.
3 Copyright (C) 1993-2026 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_INPUT_H
22#define GCC_INPUT_H
23
24#include "line-map.h"
25
26namespace diagnostics { class file_cache; }
27
28extern GTY(()) class line_maps *line_table;
29extern GTY(()) class line_maps *saved_line_table;
30
31/* A value which will never be used to represent a real location. */
32#define UNKNOWN_LOCATION ((location_t) 0)
33
34/* The location for declarations in "<built-in>" */
35#define BUILTINS_LOCATION ((location_t) 1)
36
37/* Returns the translated string referring to the special location. */
38const char *special_fname_builtin ();
39
40/* line-map.cc reserves RESERVED_LOCATION_COUNT to the user. Ensure
41 both UNKNOWN_LOCATION and BUILTINS_LOCATION fit into that. */
42STATIC_ASSERT (BUILTINS_LOCATION < RESERVED_LOCATION_COUNT);
43
44/* Hasher for 'location_t' values satisfying '!RESERVED_LOCATION_P', thus able
45 to use 'UNKNOWN_LOCATION'/'BUILTINS_LOCATION' as spare values for
46 'Empty'/'Deleted'. */
47/* Per PR103157 "'gengtype': 'typedef' causing infinite-recursion code to be
48 generated", don't use
49 typedef int_hash<location_t, UNKNOWN_LOCATION, BUILTINS_LOCATION>
50 location_hash;
51 here.
52
53 It works for a single-use case, but when using a 'struct'-based variant
54 struct location_hash
55 : int_hash<location_t, UNKNOWN_LOCATION, BUILTINS_LOCATION> {};
56 in more than one place, 'gengtype' generates duplicate functions (thus:
57 "error: redefinition of 'void gt_ggc_mx(location_hash&)'" etc.).
58 Attempting to mark that one up with GTY options, we run into a 'gengtype'
59 "parse error: expected '{', have '<'", which probably falls into category
60 "understanding of C++ is limited", as documented in 'gcc/doc/gty.texi'.
61
62 Thus, use a plain ol' '#define':
63*/
64#define location_hash int_hash<location_t, UNKNOWN_LOCATION, BUILTINS_LOCATION>
65
66extern bool is_location_from_builtin_token (location_t);
67extern expanded_location expand_location (location_t);
68
69class cpp_char_column_policy;
70
71extern int
73 expanded_location exploc,
74 const cpp_char_column_policy &policy);
75
76extern char *
77get_source_text_between (diagnostics::file_cache &, location_t, location_t);
78
79extern expanded_location
81 enum location_aspect aspect
82 = location_aspect::caret);
83extern location_t expansion_point_location_if_in_system_header (location_t);
84extern location_t expansion_point_location (location_t);
85
86extern location_t input_location;
87
88extern location_t location_with_discriminator (location_t, int);
89extern bool has_discriminator (location_t);
90extern int get_discriminator_from_loc (location_t);
91
92/* Hierarchical discriminator support for AutoFDO.
93Discriminator format: [Base:8][Multiplicity:7][CopyID:11][Unused:6]
94- Base discriminator (bits 0-7): Distinguishes instructions at same line
95- Multiplicity (bits 8-14): Duplication factor for unrolling/vectorization
96- CopyID (bits 15-25): Unique identifier for code copies
97- Unused (bits 26-31): Reserved. */
98
99/* Discriminator bit layout constants. */
100#define DISCR_BASE_BITS 8
101#define DISCR_MULTIPLICITY_BITS 7
102#define DISCR_COPYID_BITS 11
103#define DISCR_UNUSED_BITS 6
104
105#define DISCR_BASE_MASK ((1u << DISCR_BASE_BITS) - 1)
106#define DISCR_MULTIPLICITY_MASK ((1u << DISCR_MULTIPLICITY_BITS) - 1)
107#define DISCR_COPYID_MASK ((1u << DISCR_COPYID_BITS) - 1)
108
109#define DISCR_BASE_SHIFT 0
110#define DISCR_MULTIPLICITY_SHIFT DISCR_BASE_BITS
111#define DISCR_COPYID_SHIFT (DISCR_BASE_BITS + DISCR_MULTIPLICITY_BITS)
112
113/* Maximum values for each discriminator field. */
114#define DISCR_BASE_MAX DISCR_BASE_MASK
115#define DISCR_MULTIPLICITY_MAX DISCR_MULTIPLICITY_MASK
116#define DISCR_COPYID_MAX DISCR_COPYID_MASK
117
118/* Structure to hold hierarchical discriminator components. */
120{
121 unsigned int base; /* Front-end discriminator (bits 0-7). */
122 unsigned int multiplicity; /* Duplication factor (bits 8-14). */
123 unsigned int copyid; /* Copy identifier (bits 15-25). */
124};
125
126/* Create location with hierarchical discriminator. */
127extern location_t
130
131/* Get discriminator components from location. */
134
135#define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
136#define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
137#define LOCATION_COLUMN(LOC)((expand_location (LOC)).column)
138#define LOCATION_LOCUS(LOC) \
139 ((IS_ADHOC_LOC (LOC)) ? get_location_from_adhoc_loc (line_table, LOC) \
140 : (LOC))
141#define LOCATION_BLOCK(LOC) \
142 ((tree) ((IS_ADHOC_LOC (LOC)) ? get_data_from_adhoc_loc (line_table, (LOC)) \
143 : NULL))
144#define RESERVED_LOCATION_P(LOC) \
145 (LOCATION_LOCUS (LOC) < RESERVED_LOCATION_COUNT)
146
147/* Return a positive value if LOCATION is the locus of a token that is
148 located in a system header, O otherwise. It returns 1 if LOCATION
149 is the locus of a token that is located in a system header, and 2
150 if LOCATION is the locus of a token located in a C system header
151 that therefore needs to be extern "C" protected in C++.
152
153 Note that this function returns 1 if LOCATION belongs to a token
154 that is part of a macro replacement-list defined in a system
155 header, but expanded in a non-system file. */
156
157inline int
158in_system_header_at (location_t loc)
159{
160 return linemap_location_in_system_header_p (line_table, loc);
161}
162
163/* Return true if LOCATION is the locus of a token that
164 comes from a macro expansion, false otherwise. */
165
166inline bool
168{
169 return linemap_location_from_macro_expansion_p (line_table, loc);
170}
171
172/* Return true if LOCATION is the locus of a token that comes from
173 a macro definition, false otherwise. This differs from from_macro_expansion_at
174 in its treatment of macro arguments, for which this returns false. */
175
176inline bool
178{
179 return linemap_location_from_macro_definition_p (line_table, loc);
180}
181
182inline location_t
183get_pure_location (location_t loc)
184{
185 return get_pure_location (line_table, loc);
186}
187
188/* Get the start of any range encoded within location LOC. */
189
190inline location_t
191get_start (location_t loc)
192{
193 return get_range_from_loc (line_table, loc).m_start;
194}
195
196/* Get the endpoint of any range encoded within location LOC. */
197
198inline location_t
199get_finish (location_t loc)
200{
201 return get_range_from_loc (line_table, loc).m_finish;
202}
203
204extern location_t make_location (location_t caret,
205 location_t start, location_t finish);
206extern location_t make_location (location_t caret, source_range src_range);
207
209
210void dump_location_info (FILE *stream);
211
213{
214public:
215 string_concat (int num, location_t *locs);
216
217 int m_num;
218 location_t * GTY ((atomic)) m_locs;
219};
220
222{
223 public:
225 void record_string_concatenation (int num, location_t *locs);
226
227 bool get_string_concatenation (location_t loc,
228 int *out_num,
229 location_t **out_locs);
230
231 private:
232 static location_t get_key_loc (location_t loc);
233
234 /* For the fields to be private, we must grant access to the
235 generated code in gtype-desc.cc. */
236
237 friend void ::gt_ggc_mx_string_concat_db (void *x_p);
238 friend void ::gt_pch_nx_string_concat_db (void *x_p);
239 friend void ::gt_pch_p_16string_concat_db (void *this_obj, void *x_p,
241 void *cookie);
242
243 hash_map <location_hash, string_concat *> *m_table;
244};
245
246#endif
Definition file-cache.h:82
void record_string_concatenation(int num, location_t *locs)
Definition input.cc:748
string_concat_db()
Definition input.cc:738
bool get_string_concatenation(location_t loc, int *out_num, location_t **out_locs)
Definition input.cc:774
static location_t get_key_loc(location_t loc)
Definition input.cc:802
hash_map< location_hash, string_concat * > * m_table
Definition input.h:243
string_concat(int num, location_t *locs)
Definition input.cc:728
int m_num
Definition input.h:217
location_t * m_locs
Definition input.h:218
#define GTY(x)
Definition coretypes.h:41
void(* gt_pointer_operator)(void *, void *, void *)
Definition coretypes.h:490
static class line_maps * line_table
Definition genmatch.cc:65
class line_maps * saved_line_table
Definition input.cc:50
location_t input_location
Definition input.cc:41
location_t get_start(location_t loc)
Definition input.h:191
int in_system_header_at(location_t loc)
Definition input.h:158
STATIC_ASSERT(BUILTINS_LOCATION< RESERVED_LOCATION_COUNT)
int location_compute_display_column(diagnostics::file_cache &fc, expanded_location exploc, const cpp_char_column_policy &policy)
Definition input.cc:368
location_t location_with_discriminator(location_t, int)
Definition input.cc:1048
bool is_location_from_builtin_token(location_t)
Definition input.cc:244
#define BUILTINS_LOCATION
Definition input.h:35
location_t location_with_discriminator_components(location_t, const discriminator_components &)
Definition input.cc:1080
void dump_line_table_statistics(void)
Definition input.cc:386
bool from_macro_definition_at(location_t loc)
Definition input.h:177
void dump_location_info(FILE *stream)
Definition input.cc:517
bool has_discriminator(location_t)
Definition input.cc:1064
location_t make_location(location_t caret, location_t start, location_t finish)
Definition input.cc:348
location_t expansion_point_location(location_t)
Definition input.cc:325
location_t expansion_point_location_if_in_system_header(location_t)
Definition input.cc:310
const char * special_fname_builtin()
Definition input.cc:34
discriminator_components get_discriminator_components_from_loc(location_t)
Definition input.cc:1095
expanded_location expand_location(location_t)
Definition input.cc:258
bool from_macro_expansion_at(location_t loc)
Definition input.h:167
char * get_source_text_between(diagnostics::file_cache &, location_t, location_t)
Definition input.cc:147
expanded_location expand_location_to_spelling_point(location_t, enum location_aspect aspect=location_aspect::caret)
Definition input.cc:271
int get_discriminator_from_loc(location_t)
Definition input.cc:1072
location_t get_finish(location_t loc)
Definition input.h:199
location_t get_pure_location(location_t loc)
Definition input.h:183
Definition cfghooks.h:26
Definition input.h:120
unsigned int copyid
Definition input.h:123
unsigned int base
Definition input.h:121
unsigned int multiplicity
Definition input.h:122