annotate gcc/input.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Declarations for variables relating to reading the source file.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 Used by parsers, lexical analyzers, and error message routines.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3 Copyright (C) 1993-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #ifndef GCC_INPUT_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #define GCC_INPUT_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "line-map.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 extern GTY(()) struct line_maps *line_table;
111
kono
parents: 67
diff changeset
27 extern GTY(()) struct line_maps *saved_line_table;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 /* A value which will never be used to represent a real location. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #define UNKNOWN_LOCATION ((source_location) 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 /* The location for declarations in "<built-in>" */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
33 #define BUILTINS_LOCATION ((source_location) 1)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
34
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
35 /* line-map.c reserves RESERVED_LOCATION_COUNT to the user. Ensure
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
36 both UNKNOWN_LOCATION and BUILTINS_LOCATION fit into that. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
37 STATIC_ASSERT (BUILTINS_LOCATION < RESERVED_LOCATION_COUNT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
111
kono
parents: 67
diff changeset
39 extern bool is_location_from_builtin_token (source_location);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 extern expanded_location expand_location (source_location);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
41
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
42 /* A class capturing the bounds of a buffer, to allow for run-time
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
43 bounds-checking in a checked build. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
44
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
45 class char_span
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
46 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
47 public:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
48 char_span (const char *ptr, size_t n_elts) : m_ptr (ptr), m_n_elts (n_elts) {}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
49
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
50 /* Test for a non-NULL pointer. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 operator bool() const { return m_ptr; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
53 /* Get length, not including any 0-terminator (which may not be,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
54 in fact, present). */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
55 size_t length () const { return m_n_elts; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 const char *get_buffer () const { return m_ptr; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
58
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
59 char operator[] (int idx) const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
60 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
61 gcc_assert (idx >= 0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
62 gcc_assert ((size_t)idx < m_n_elts);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
63 return m_ptr[idx];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
64 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
66 char_span subspan (int offset, int n_elts) const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
67 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
68 gcc_assert (offset >= 0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69 gcc_assert (offset < (int)m_n_elts);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
70 gcc_assert (n_elts >= 0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
71 gcc_assert (offset + n_elts <= (int)m_n_elts);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
72 return char_span (m_ptr + offset, n_elts);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
73 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
74
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
75 char *xstrdup () const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
76 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
77 return ::xstrndup (m_ptr, m_n_elts);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
78 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
79
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
80 private:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
81 const char *m_ptr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
82 size_t m_n_elts;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
83 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
84
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
85 extern char_span location_get_source_line (const char *file_path, int line);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86
111
kono
parents: 67
diff changeset
87 extern bool location_missing_trailing_newline (const char *file_path);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88 extern expanded_location
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
89 expand_location_to_spelling_point (source_location,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
90 enum location_aspect aspect
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
91 = LOCATION_ASPECT_CARET);
111
kono
parents: 67
diff changeset
92 extern source_location expansion_point_location_if_in_system_header (source_location);
kono
parents: 67
diff changeset
93 extern source_location expansion_point_location (source_location);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 /* Historically GCC used location_t, while cpp used source_location.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 This could be removed but it hardly seems worth the effort. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 typedef source_location location_t;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 extern location_t input_location;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 #define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 #define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
111
kono
parents: 67
diff changeset
103 #define LOCATION_COLUMN(LOC)((expand_location (LOC)).column)
kono
parents: 67
diff changeset
104 #define LOCATION_LOCUS(LOC) \
kono
parents: 67
diff changeset
105 ((IS_ADHOC_LOC (LOC)) ? get_location_from_adhoc_loc (line_table, LOC) \
kono
parents: 67
diff changeset
106 : (LOC))
kono
parents: 67
diff changeset
107 #define LOCATION_BLOCK(LOC) \
kono
parents: 67
diff changeset
108 ((tree) ((IS_ADHOC_LOC (LOC)) ? get_data_from_adhoc_loc (line_table, (LOC)) \
kono
parents: 67
diff changeset
109 : NULL))
kono
parents: 67
diff changeset
110 #define RESERVED_LOCATION_P(LOC) \
kono
parents: 67
diff changeset
111 (LOCATION_LOCUS (LOC) < RESERVED_LOCATION_COUNT)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
111
kono
parents: 67
diff changeset
113 /* Return a positive value if LOCATION is the locus of a token that is
kono
parents: 67
diff changeset
114 located in a system header, O otherwise. It returns 1 if LOCATION
kono
parents: 67
diff changeset
115 is the locus of a token that is located in a system header, and 2
kono
parents: 67
diff changeset
116 if LOCATION is the locus of a token located in a C system header
kono
parents: 67
diff changeset
117 that therefore needs to be extern "C" protected in C++.
kono
parents: 67
diff changeset
118
kono
parents: 67
diff changeset
119 Note that this function returns 1 if LOCATION belongs to a token
kono
parents: 67
diff changeset
120 that is part of a macro replacement-list defined in a system
kono
parents: 67
diff changeset
121 header, but expanded in a non-system file. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
122
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
123 static inline int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
124 in_system_header_at (location_t loc)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
125 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
126 return linemap_location_in_system_header_p (line_table, loc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
127 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
128
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
129 /* Return true if LOCATION is the locus of a token that
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
130 comes from a macro expansion, false otherwise. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
132 static inline bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
133 from_macro_expansion_at (location_t loc)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
134 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135 return linemap_location_from_macro_expansion_p (line_table, loc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
136 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 /* Return true if LOCATION is the locus of a token that comes from
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
139 a macro definition, false otherwise. This differs from from_macro_expansion_at
111
kono
parents: 67
diff changeset
140 in its treatment of macro arguments, for which this returns false. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
141
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
142 static inline bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143 from_macro_definition_at (location_t loc)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
144 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
145 return linemap_location_from_macro_definition_p (line_table, loc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
146 }
111
kono
parents: 67
diff changeset
147
kono
parents: 67
diff changeset
148 static inline location_t
kono
parents: 67
diff changeset
149 get_pure_location (location_t loc)
kono
parents: 67
diff changeset
150 {
kono
parents: 67
diff changeset
151 return get_pure_location (line_table, loc);
kono
parents: 67
diff changeset
152 }
kono
parents: 67
diff changeset
153
kono
parents: 67
diff changeset
154 /* Get the start of any range encoded within location LOC. */
kono
parents: 67
diff changeset
155
kono
parents: 67
diff changeset
156 static inline location_t
kono
parents: 67
diff changeset
157 get_start (location_t loc)
kono
parents: 67
diff changeset
158 {
kono
parents: 67
diff changeset
159 return get_range_from_loc (line_table, loc).m_start;
kono
parents: 67
diff changeset
160 }
kono
parents: 67
diff changeset
161
kono
parents: 67
diff changeset
162 /* Get the endpoint of any range encoded within location LOC. */
kono
parents: 67
diff changeset
163
kono
parents: 67
diff changeset
164 static inline location_t
kono
parents: 67
diff changeset
165 get_finish (location_t loc)
kono
parents: 67
diff changeset
166 {
kono
parents: 67
diff changeset
167 return get_range_from_loc (line_table, loc).m_finish;
kono
parents: 67
diff changeset
168 }
kono
parents: 67
diff changeset
169
kono
parents: 67
diff changeset
170 extern location_t make_location (location_t caret,
kono
parents: 67
diff changeset
171 location_t start, location_t finish);
kono
parents: 67
diff changeset
172 extern location_t make_location (location_t caret, source_range src_range);
kono
parents: 67
diff changeset
173
kono
parents: 67
diff changeset
174 void dump_line_table_statistics (void);
kono
parents: 67
diff changeset
175
kono
parents: 67
diff changeset
176 void dump_location_info (FILE *stream);
kono
parents: 67
diff changeset
177
kono
parents: 67
diff changeset
178 void diagnostics_file_cache_fini (void);
kono
parents: 67
diff changeset
179
kono
parents: 67
diff changeset
180 void diagnostics_file_cache_forcibly_evict_file (const char *file_path);
kono
parents: 67
diff changeset
181
kono
parents: 67
diff changeset
182 struct GTY(()) string_concat
kono
parents: 67
diff changeset
183 {
kono
parents: 67
diff changeset
184 string_concat (int num, location_t *locs);
kono
parents: 67
diff changeset
185
kono
parents: 67
diff changeset
186 int m_num;
kono
parents: 67
diff changeset
187 location_t * GTY ((atomic)) m_locs;
kono
parents: 67
diff changeset
188 };
kono
parents: 67
diff changeset
189
kono
parents: 67
diff changeset
190 struct location_hash : int_hash <location_t, UNKNOWN_LOCATION> { };
kono
parents: 67
diff changeset
191
kono
parents: 67
diff changeset
192 class GTY(()) string_concat_db
kono
parents: 67
diff changeset
193 {
kono
parents: 67
diff changeset
194 public:
kono
parents: 67
diff changeset
195 string_concat_db ();
kono
parents: 67
diff changeset
196 void record_string_concatenation (int num, location_t *locs);
kono
parents: 67
diff changeset
197
kono
parents: 67
diff changeset
198 bool get_string_concatenation (location_t loc,
kono
parents: 67
diff changeset
199 int *out_num,
kono
parents: 67
diff changeset
200 location_t **out_locs);
kono
parents: 67
diff changeset
201
kono
parents: 67
diff changeset
202 private:
kono
parents: 67
diff changeset
203 static location_t get_key_loc (location_t loc);
kono
parents: 67
diff changeset
204
kono
parents: 67
diff changeset
205 /* For the fields to be private, we must grant access to the
kono
parents: 67
diff changeset
206 generated code in gtype-desc.c. */
kono
parents: 67
diff changeset
207
kono
parents: 67
diff changeset
208 friend void ::gt_ggc_mx_string_concat_db (void *x_p);
kono
parents: 67
diff changeset
209 friend void ::gt_pch_nx_string_concat_db (void *x_p);
kono
parents: 67
diff changeset
210 friend void ::gt_pch_p_16string_concat_db (void *this_obj, void *x_p,
kono
parents: 67
diff changeset
211 gt_pointer_operator op,
kono
parents: 67
diff changeset
212 void *cookie);
kono
parents: 67
diff changeset
213
kono
parents: 67
diff changeset
214 hash_map <location_hash, string_concat *> *m_table;
kono
parents: 67
diff changeset
215 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 #endif