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-2025 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#define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
93#define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
94#define LOCATION_COLUMN(LOC)((expand_location (LOC)).column)
95#define LOCATION_LOCUS(LOC) \
96 ((IS_ADHOC_LOC (LOC)) ? get_location_from_adhoc_loc (line_table, LOC) \
97 : (LOC))
98#define LOCATION_BLOCK(LOC) \
99 ((tree) ((IS_ADHOC_LOC (LOC)) ? get_data_from_adhoc_loc (line_table, (LOC)) \
100 : NULL))
101#define RESERVED_LOCATION_P(LOC) \
102 (LOCATION_LOCUS (LOC) < RESERVED_LOCATION_COUNT)
103
104/* Return a positive value if LOCATION is the locus of a token that is
105 located in a system header, O otherwise. It returns 1 if LOCATION
106 is the locus of a token that is located in a system header, and 2
107 if LOCATION is the locus of a token located in a C system header
108 that therefore needs to be extern "C" protected in C++.
109
110 Note that this function returns 1 if LOCATION belongs to a token
111 that is part of a macro replacement-list defined in a system
112 header, but expanded in a non-system file. */
113
114inline int
115in_system_header_at (location_t loc)
116{
117 return linemap_location_in_system_header_p (line_table, loc);
118}
119
120/* Return true if LOCATION is the locus of a token that
121 comes from a macro expansion, false otherwise. */
122
123inline bool
125{
126 return linemap_location_from_macro_expansion_p (line_table, loc);
127}
128
129/* Return true if LOCATION is the locus of a token that comes from
130 a macro definition, false otherwise. This differs from from_macro_expansion_at
131 in its treatment of macro arguments, for which this returns false. */
132
133inline bool
135{
136 return linemap_location_from_macro_definition_p (line_table, loc);
137}
138
139inline location_t
140get_pure_location (location_t loc)
141{
142 return get_pure_location (line_table, loc);
143}
144
145/* Get the start of any range encoded within location LOC. */
146
147inline location_t
148get_start (location_t loc)
149{
150 return get_range_from_loc (line_table, loc).m_start;
151}
152
153/* Get the endpoint of any range encoded within location LOC. */
154
155inline location_t
156get_finish (location_t loc)
157{
158 return get_range_from_loc (line_table, loc).m_finish;
159}
160
161extern location_t make_location (location_t caret,
162 location_t start, location_t finish);
163extern location_t make_location (location_t caret, source_range src_range);
164
166
167void dump_location_info (FILE *stream);
168
170{
171public:
172 string_concat (int num, location_t *locs);
173
174 int m_num;
175 location_t * GTY ((atomic)) m_locs;
176};
177
179{
180 public:
182 void record_string_concatenation (int num, location_t *locs);
183
184 bool get_string_concatenation (location_t loc,
185 int *out_num,
186 location_t **out_locs);
187
188 private:
189 static location_t get_key_loc (location_t loc);
190
191 /* For the fields to be private, we must grant access to the
192 generated code in gtype-desc.cc. */
193
194 friend void ::gt_ggc_mx_string_concat_db (void *x_p);
195 friend void ::gt_pch_nx_string_concat_db (void *x_p);
196 friend void ::gt_pch_p_16string_concat_db (void *this_obj, void *x_p,
198 void *cookie);
199
200 hash_map <location_hash, string_concat *> *m_table;
201};
202
203#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:200
string_concat(int num, location_t *locs)
Definition input.cc:728
int m_num
Definition input.h:174
location_t * m_locs
Definition input.h:175
#define GTY(x)
Definition coretypes.h:41
void(* gt_pointer_operator)(void *, void *, void *)
Definition coretypes.h:475
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:148
int in_system_header_at(location_t loc)
Definition input.h:115
expanded_location expand_location_to_spelling_point(location_t, enum location_aspect aspect=LOCATION_ASPECT_CARET)
Definition input.cc:271
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
void dump_line_table_statistics(void)
Definition input.cc:386
bool from_macro_definition_at(location_t loc)
Definition input.h:134
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
expanded_location expand_location(location_t)
Definition input.cc:258
bool from_macro_expansion_at(location_t loc)
Definition input.h:124
char * get_source_text_between(diagnostics::file_cache &, location_t, location_t)
Definition input.cc:147
int get_discriminator_from_loc(location_t)
Definition input.cc:1072
location_t get_finish(location_t loc)
Definition input.h:156
location_t get_pure_location(location_t loc)
Definition input.h:140
Definition coretypes.h:167