Branch data Line data Source code
1 : : /* Separate lexical analyzer for GNU C++.
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : : Hacked by Michael Tiemann (tiemann@cygnus.com)
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify
8 : : it under the terms of the GNU General Public License as published by
9 : : the Free Software Foundation; either version 3, or (at your option)
10 : : any later version.
11 : :
12 : : GCC is distributed in the hope that it will be useful,
13 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : : GNU General Public License for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : :
22 : : /* This file is the lexical analyzer for GNU C++. */
23 : :
24 : : #include "config.h"
25 : : /* For use with name_hint. */
26 : : #include "system.h"
27 : : #include "coretypes.h"
28 : : #include "cp-tree.h"
29 : : #include "stringpool.h"
30 : : #include "c-family/c-pragma.h"
31 : : #include "c-family/c-objc.h"
32 : : #include "gcc-rich-location.h"
33 : : #include "cp-name-hint.h"
34 : : #include "langhooks.h"
35 : :
36 : : static int interface_strcmp (const char *);
37 : : static void init_cp_traits (void);
38 : : static void init_cp_pragma (void);
39 : :
40 : : static tree parse_strconst_pragma (const char *, int);
41 : : static void handle_pragma_vtable (cpp_reader *);
42 : : static void handle_pragma_unit (cpp_reader *);
43 : : static void handle_pragma_interface (cpp_reader *);
44 : : static void handle_pragma_implementation (cpp_reader *);
45 : :
46 : : static void init_operators (void);
47 : : static void copy_lang_type (tree);
48 : :
49 : : /* A constraint that can be tested at compile time. */
50 : : #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
51 : :
52 : : /* Functions and data structures for #pragma interface.
53 : :
54 : : `#pragma implementation' means that the main file being compiled
55 : : is considered to implement (provide) the classes that appear in
56 : : its main body. I.e., if this is file "foo.cc", and class `bar'
57 : : is defined in "foo.cc", then we say that "foo.cc implements bar".
58 : :
59 : : All main input files "implement" themselves automagically.
60 : :
61 : : `#pragma interface' means that unless this file (of the form "foo.h"
62 : : is not presently being included by file "foo.cc", the
63 : : CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
64 : : of the vtables nor any of the inline functions defined in foo.h
65 : : will ever be output.
66 : :
67 : : There are cases when we want to link files such as "defs.h" and
68 : : "main.cc". In this case, we give "defs.h" a `#pragma interface',
69 : : and "main.cc" has `#pragma implementation "defs.h"'. */
70 : :
71 : : struct impl_files
72 : : {
73 : : const char *filename;
74 : : struct impl_files *next;
75 : : };
76 : :
77 : : static struct impl_files *impl_file_chain;
78 : :
79 : : void
80 : 96279 : cxx_finish (void)
81 : : {
82 : 96279 : c_common_finish ();
83 : 96279 : }
84 : :
85 : : ovl_op_info_t ovl_op_info[2][OVL_OP_MAX] =
86 : : {
87 : : {
88 : : {NULL_TREE, NULL, NULL, ERROR_MARK, OVL_OP_ERROR_MARK, 0},
89 : : {NULL_TREE, NULL, NULL, NOP_EXPR, OVL_OP_NOP_EXPR, 0},
90 : : #define DEF_OPERATOR(NAME, CODE, MANGLING, FLAGS) \
91 : : {NULL_TREE, NAME, MANGLING, CODE, OVL_OP_##CODE, FLAGS},
92 : : #define OPERATOR_TRANSITION }, { \
93 : : {NULL_TREE, NULL, NULL, ERROR_MARK, OVL_OP_ERROR_MARK, 0},
94 : : #include "operators.def"
95 : : }
96 : : };
97 : : unsigned char ovl_op_mapping[MAX_TREE_CODES];
98 : : unsigned char ovl_op_alternate[OVL_OP_MAX];
99 : :
100 : : /* The trait table, declared in cp-tree.h. */
101 : : const cp_trait cp_traits[] =
102 : : {
103 : : #define DEFTRAIT(TCC, CODE, NAME, ARITY) \
104 : : { NAME, CPTK_##CODE, ARITY, (TCC == tcc_type) },
105 : : #include "cp-trait.def"
106 : : #undef DEFTRAIT
107 : : };
108 : : /* The trait table cannot have more than 255 (addr_space_t) entries since
109 : : the index is retrieved through IDENTIFIER_CP_INDEX. */
110 : : static_assert(ARRAY_SIZE (cp_traits) <= 255,
111 : : "cp_traits array cannot have more than 255 entries");
112 : :
113 : : /* Get the name of the kind of identifier T. */
114 : :
115 : : const char *
116 : 0 : get_identifier_kind_name (tree id)
117 : : {
118 : : /* Keep in sync with cp_id_kind enumeration. */
119 : 0 : static const char *const names[cik_max] = {
120 : : "normal", "keyword", "constructor", "destructor",
121 : : "simple-op", "assign-op", "conv-op", "<reserved>udlit-op"
122 : : };
123 : :
124 : 0 : unsigned kind = 0;
125 : 0 : kind |= IDENTIFIER_KIND_BIT_2 (id) << 2;
126 : 0 : kind |= IDENTIFIER_KIND_BIT_1 (id) << 1;
127 : 0 : kind |= IDENTIFIER_KIND_BIT_0 (id) << 0;
128 : :
129 : 0 : return names[kind];
130 : : }
131 : :
132 : : /* Set the identifier kind, which we expect to currently be zero. */
133 : :
134 : : void
135 : 25857125 : set_identifier_kind (tree id, cp_identifier_kind kind)
136 : : {
137 : 25857125 : gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
138 : : & !IDENTIFIER_KIND_BIT_1 (id)
139 : : & !IDENTIFIER_KIND_BIT_0 (id));
140 : 25857125 : IDENTIFIER_KIND_BIT_2 (id) |= (kind >> 2) & 1;
141 : 25857125 : IDENTIFIER_KIND_BIT_1 (id) |= (kind >> 1) & 1;
142 : 25857125 : IDENTIFIER_KIND_BIT_0 (id) |= (kind >> 0) & 1;
143 : 25857125 : }
144 : :
145 : : /* Create and tag the internal operator name for the overloaded
146 : : operator PTR describes. */
147 : :
148 : : static tree
149 : 5402376 : set_operator_ident (ovl_op_info_t *ptr)
150 : : {
151 : 5402376 : char buffer[32];
152 : 10804752 : size_t len = snprintf (buffer, sizeof (buffer), "operator%s%s",
153 : 5402376 : &" "[ptr->name[0] && ptr->name[0] != '_'
154 : 5402376 : && !ISALPHA (ptr->name[0])],
155 : 5402376 : ptr->name);
156 : 5402376 : gcc_checking_assert (len < sizeof (buffer));
157 : :
158 : 5402376 : tree ident = get_identifier_with_length (buffer, len);
159 : 5402376 : ptr->identifier = ident;
160 : :
161 : 5402376 : return ident;
162 : : }
163 : :
164 : : /* Initialize data structures that keep track of operator names. */
165 : :
166 : : static void
167 : 96471 : init_operators (void)
168 : : {
169 : : /* We rely on both these being zero. */
170 : 96471 : gcc_checking_assert (!OVL_OP_ERROR_MARK && !ERROR_MARK);
171 : :
172 : : /* This loop iterates backwards because we need to move the
173 : : assignment operators down to their correct slots. I.e. morally
174 : : equivalent to an overlapping memmove where dest > src. Slot
175 : : zero is for error_mark, so has no operator. */
176 : 5595318 : for (unsigned ix = OVL_OP_MAX; --ix;)
177 : : {
178 : 5498847 : ovl_op_info_t *op_ptr = &ovl_op_info[false][ix];
179 : :
180 : 5498847 : if (op_ptr->name)
181 : : {
182 : 4341195 : tree ident = set_operator_ident (op_ptr);
183 : 4341195 : if (unsigned index = IDENTIFIER_CP_INDEX (ident))
184 : : {
185 : 578826 : ovl_op_info_t *bin_ptr = &ovl_op_info[false][index];
186 : :
187 : : /* They should only differ in unary/binary ness. */
188 : 578826 : gcc_checking_assert ((op_ptr->flags ^ bin_ptr->flags)
189 : : == OVL_OP_FLAG_AMBIARY);
190 : 578826 : bin_ptr->flags |= op_ptr->flags;
191 : 578826 : ovl_op_alternate[index] = ix;
192 : : }
193 : : else
194 : : {
195 : 3762369 : IDENTIFIER_CP_INDEX (ident) = ix;
196 : 3762369 : set_identifier_kind (ident, cik_simple_op);
197 : : }
198 : : }
199 : 5498847 : if (op_ptr->tree_code)
200 : : {
201 : 5498847 : gcc_checking_assert (op_ptr->ovl_op_code == ix
202 : : && !ovl_op_mapping[op_ptr->tree_code]);
203 : 5498847 : ovl_op_mapping[op_ptr->tree_code] = op_ptr->ovl_op_code;
204 : : }
205 : :
206 : 5498847 : ovl_op_info_t *as_ptr = &ovl_op_info[true][ix];
207 : 5498847 : if (as_ptr->name)
208 : : {
209 : : /* These will be placed at the start of the array, move to
210 : : the correct slot and initialize. */
211 : 1061181 : if (as_ptr->ovl_op_code != ix)
212 : : {
213 : 964710 : ovl_op_info_t *dst_ptr = &ovl_op_info[true][as_ptr->ovl_op_code];
214 : 964710 : gcc_assert (as_ptr->ovl_op_code > ix && !dst_ptr->tree_code);
215 : 964710 : memcpy (dst_ptr, as_ptr, sizeof (*dst_ptr));
216 : 964710 : memset (as_ptr, 0, sizeof (*as_ptr));
217 : 964710 : as_ptr = dst_ptr;
218 : : }
219 : :
220 : 1061181 : tree ident = set_operator_ident (as_ptr);
221 : 1061181 : gcc_checking_assert (!IDENTIFIER_CP_INDEX (ident));
222 : 1061181 : IDENTIFIER_CP_INDEX (ident) = as_ptr->ovl_op_code;
223 : 1061181 : set_identifier_kind (ident, cik_assign_op);
224 : :
225 : 1061181 : gcc_checking_assert (!ovl_op_mapping[as_ptr->tree_code]
226 : : || (ovl_op_mapping[as_ptr->tree_code]
227 : : == as_ptr->ovl_op_code));
228 : 1061181 : ovl_op_mapping[as_ptr->tree_code] = as_ptr->ovl_op_code;
229 : : }
230 : : }
231 : 96471 : }
232 : :
233 : : /* Initialize the reserved words. */
234 : :
235 : : void
236 : 96471 : init_reswords (void)
237 : : {
238 : 96471 : unsigned int i;
239 : 96471 : tree id;
240 : 96471 : int mask = 0;
241 : :
242 : 96471 : if (cxx_dialect < cxx11)
243 : 13989 : mask |= D_CXX11;
244 : 96471 : if (cxx_dialect < cxx20)
245 : 65925 : mask |= D_CXX20;
246 : 96471 : if (cxx_dialect < cxx26)
247 : 72884 : mask |= D_CXX26;
248 : 96471 : if (!flag_concepts)
249 : 65734 : mask |= D_CXX_CONCEPTS;
250 : 96471 : if (!flag_coroutines)
251 : 64962 : mask |= D_CXX_COROUTINES;
252 : 96471 : if (!flag_modules)
253 : 91982 : mask |= D_CXX_MODULES;
254 : 96471 : if (!flag_tm)
255 : 96144 : mask |= D_TRANSMEM;
256 : 96471 : if (!flag_char8_t)
257 : 65867 : mask |= D_CXX_CHAR8_T;
258 : 96471 : if (flag_no_asm)
259 : 3 : mask |= D_ASM | D_EXT | D_EXT11;
260 : 96471 : if (flag_no_gnu_keywords)
261 : 50649 : mask |= D_EXT | D_EXT11;
262 : :
263 : : /* The Objective-C keywords are all context-dependent. */
264 : 96471 : mask |= D_OBJC;
265 : :
266 : 96471 : ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
267 : 22091859 : for (i = 0; i < num_c_common_reswords; i++)
268 : : {
269 : 21995388 : if (c_common_reswords[i].disable & D_CONLY)
270 : 4630608 : continue;
271 : 17364780 : id = get_identifier (c_common_reswords[i].word);
272 : 17364780 : C_SET_RID_CODE (id, c_common_reswords[i].rid);
273 : 17364780 : ridpointers [(int) c_common_reswords[i].rid] = id;
274 : 17364780 : if (! (c_common_reswords[i].disable & mask))
275 : 12636744 : set_identifier_kind (id, cik_keyword);
276 : : }
277 : :
278 : 192942 : for (i = 0; i < NUM_INT_N_ENTS; i++)
279 : : {
280 : 96471 : char name[50];
281 : 96471 : sprintf (name, "__int%d", int_n_data[i].bitsize);
282 : 96471 : id = get_identifier (name);
283 : 96471 : C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
284 : 96471 : set_identifier_kind (id, cik_keyword);
285 : :
286 : 96471 : sprintf (name, "__int%d__", int_n_data[i].bitsize);
287 : 96471 : id = get_identifier (name);
288 : 96471 : C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
289 : 96471 : set_identifier_kind (id, cik_keyword);
290 : : }
291 : :
292 : 96471 : if (flag_openmp)
293 : : {
294 : 3854 : id = get_identifier ("omp_all_memory");
295 : 3854 : C_SET_RID_CODE (id, RID_OMP_ALL_MEMORY);
296 : 3854 : set_identifier_kind (id, cik_keyword);
297 : 3854 : ridpointers [RID_OMP_ALL_MEMORY] = id;
298 : : }
299 : 96471 : }
300 : :
301 : : /* Initialize the C++ traits. */
302 : : static void
303 : 96471 : init_cp_traits (void)
304 : : {
305 : 96471 : tree id;
306 : :
307 : 7428267 : for (unsigned int i = 0; i < ARRAY_SIZE (cp_traits); ++i)
308 : : {
309 : 7331796 : id = get_identifier (cp_traits[i].name);
310 : 7331796 : IDENTIFIER_CP_INDEX (id) = cp_traits[i].kind;
311 : 7331796 : set_identifier_kind (id, cik_trait);
312 : : }
313 : :
314 : : /* An alias for __is_same. */
315 : 96471 : id = get_identifier ("__is_same_as");
316 : 96471 : IDENTIFIER_CP_INDEX (id) = CPTK_IS_SAME;
317 : 96471 : set_identifier_kind (id, cik_trait);
318 : 96471 : }
319 : :
320 : : static void
321 : 95078 : init_cp_pragma (void)
322 : : {
323 : 95078 : c_register_pragma (0, "vtable", handle_pragma_vtable);
324 : 95078 : c_register_pragma (0, "unit", handle_pragma_unit);
325 : 95078 : c_register_pragma (0, "interface", handle_pragma_interface);
326 : 95078 : c_register_pragma (0, "implementation", handle_pragma_implementation);
327 : 95078 : c_register_pragma ("GCC", "interface", handle_pragma_interface);
328 : 95078 : c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
329 : 95078 : }
330 : :
331 : : /* TRUE if a code represents a statement. */
332 : :
333 : : bool statement_code_p[MAX_TREE_CODES];
334 : :
335 : : /* Initialize the C++ front end. This function is very sensitive to
336 : : the exact order that things are done here. It would be nice if the
337 : : initialization done by this routine were moved to its subroutines,
338 : : and the ordering dependencies clarified and reduced. */
339 : : bool
340 : 96471 : cxx_init (void)
341 : : {
342 : 96471 : location_t saved_loc;
343 : 96471 : unsigned int i;
344 : 96471 : static const enum tree_code stmt_codes[] = {
345 : : CTOR_INITIALIZER, TRY_BLOCK, HANDLER,
346 : : EH_SPEC_BLOCK, USING_STMT, TAG_DEFN,
347 : : IF_STMT, CLEANUP_STMT, FOR_STMT,
348 : : RANGE_FOR_STMT, WHILE_STMT, DO_STMT,
349 : : BREAK_STMT, CONTINUE_STMT, SWITCH_STMT,
350 : : EXPR_STMT, OMP_DEPOBJ
351 : : };
352 : :
353 : 96471 : memset (&statement_code_p, 0, sizeof (statement_code_p));
354 : 1736478 : for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
355 : 1640007 : statement_code_p[stmt_codes[i]] = true;
356 : :
357 : 96471 : saved_loc = input_location;
358 : 96471 : input_location = BUILTINS_LOCATION;
359 : :
360 : 96471 : init_reswords ();
361 : 96471 : init_cp_traits ();
362 : 96471 : init_tree ();
363 : 96471 : init_cp_semantics ();
364 : 96471 : init_operators ();
365 : 96471 : init_method ();
366 : :
367 : 96471 : current_function_decl = NULL;
368 : :
369 : 96471 : class_type_node = ridpointers[(int) RID_CLASS];
370 : :
371 : 96471 : cxx_init_decl_processing ();
372 : :
373 : 96471 : if (warn_keyword_macro)
374 : : {
375 : 3222717 : for (unsigned int i = 0; i < num_c_common_reswords; ++i)
376 : : /* For C++ none of the keywords in [lex.key] starts with underscore,
377 : : don't register anything like that. Don't complain about
378 : : ObjC or Transactional Memory keywords. */
379 : 3208644 : if (c_common_reswords[i].word[0] == '_')
380 : 1449519 : continue;
381 : 1759125 : else if (c_common_reswords[i].disable & (D_TRANSMEM | D_OBJC))
382 : 534774 : continue;
383 : : else
384 : : {
385 : 1224351 : tree id = get_identifier (c_common_reswords[i].word);
386 : 1224351 : if (IDENTIFIER_KEYWORD_P (id)
387 : : /* Don't register keywords with spaces. */
388 : 2368729 : && IDENTIFIER_POINTER (id)[IDENTIFIER_LENGTH (id) - 1] != ' ')
389 : 1140037 : cpp_warn (parse_in, IDENTIFIER_POINTER (id),
390 : 1140037 : IDENTIFIER_LENGTH (id));
391 : : }
392 : 14073 : if (cxx_dialect >= cxx11)
393 : : {
394 : 14072 : cpp_warn (parse_in, "final");
395 : 14072 : cpp_warn (parse_in, "override");
396 : 14072 : cpp_warn (parse_in, "noreturn");
397 : 14072 : if (cxx_dialect < cxx26)
398 : 12 : cpp_warn (parse_in, "carries_dependency");
399 : : }
400 : 14073 : if (cxx_dialect >= cxx14)
401 : 14070 : cpp_warn (parse_in, "deprecated");
402 : 14073 : if (cxx_dialect >= cxx17)
403 : : {
404 : 14068 : cpp_warn (parse_in, "fallthrough");
405 : 14068 : cpp_warn (parse_in, "maybe_unused");
406 : 14068 : cpp_warn (parse_in, "nodiscard");
407 : : }
408 : 14073 : if (cxx_dialect >= cxx20)
409 : : {
410 : 14065 : cpp_warn (parse_in, "likely");
411 : 14065 : cpp_warn (parse_in, "unlikely");
412 : 14065 : cpp_warn (parse_in, "no_unique_address");
413 : : }
414 : 14073 : if (flag_modules)
415 : : {
416 : 1447 : cpp_warn (parse_in, "import");
417 : 1447 : cpp_warn (parse_in, "module");
418 : : }
419 : 14073 : if (cxx_dialect >= cxx23)
420 : 14062 : cpp_warn (parse_in, "assume");
421 : 14073 : if (cxx_dialect >= cxx26)
422 : : {
423 : 14060 : cpp_warn (parse_in, "replaceable_if_eligible");
424 : 14060 : cpp_warn (parse_in, "trivially_relocatable_if_eligible");
425 : : }
426 : : }
427 : :
428 : 96471 : if (c_common_init () == false)
429 : : {
430 : 1355 : input_location = saved_loc;
431 : 1355 : return false;
432 : : }
433 : :
434 : 95078 : init_cp_pragma ();
435 : :
436 : 95078 : input_location = saved_loc;
437 : 95078 : return true;
438 : : }
439 : :
440 : : /* Return nonzero if S is not considered part of an
441 : : INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
442 : :
443 : : static int
444 : 79 : interface_strcmp (const char* s)
445 : : {
446 : : /* Set the interface/implementation bits for this scope. */
447 : 79 : struct impl_files *ifiles;
448 : 79 : const char *s1;
449 : :
450 : 91 : for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
451 : : {
452 : 48 : const char *t1 = ifiles->filename;
453 : 48 : s1 = s;
454 : :
455 : 48 : if (*s1 == 0 || filename_ncmp (s1, t1, 1) != 0)
456 : 6 : continue;
457 : :
458 : 462 : while (*s1 != 0 && filename_ncmp (s1, t1, 1) == 0)
459 : 420 : s1++, t1++;
460 : :
461 : : /* A match. */
462 : 42 : if (*s1 == *t1)
463 : : return 0;
464 : :
465 : : /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
466 : 18 : if (strchr (s1, '.') || strchr (t1, '.'))
467 : 6 : continue;
468 : :
469 : 12 : if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
470 : 0 : continue;
471 : :
472 : : /* A match. */
473 : : return 0;
474 : : }
475 : :
476 : : /* No matches. */
477 : : return 1;
478 : : }
479 : :
480 : : /* We've just read a cpp-token, figure out our next state. Hey, this
481 : : is a hand-coded co-routine! */
482 : :
483 : : struct module_token_filter
484 : : {
485 : : enum state
486 : : {
487 : : idle,
488 : : module_first,
489 : : module_cont,
490 : : module_end,
491 : : };
492 : :
493 : : enum state state : 8;
494 : : bool is_import : 1;
495 : : bool got_export : 1;
496 : : bool got_colon : 1;
497 : : bool want_dot : 1;
498 : :
499 : : location_t token_loc;
500 : : cpp_reader *reader;
501 : : module_state *module;
502 : : module_state *import;
503 : :
504 : 4489 : module_token_filter (cpp_reader *reader)
505 : 4489 : : state (idle), is_import (false),
506 : 4489 : got_export (false), got_colon (false), want_dot (false),
507 : 4489 : token_loc (UNKNOWN_LOCATION),
508 : 4489 : reader (reader), module (NULL), import (NULL)
509 : : {
510 : : };
511 : :
512 : : /* Process the next token. Note we cannot see CPP_EOF inside a
513 : : pragma -- a CPP_PRAGMA_EOL always happens. */
514 : 24626911 : uintptr_t resume (int type, int keyword, tree value, location_t loc)
515 : : {
516 : 24626911 : unsigned res = 0;
517 : :
518 : 24626911 : switch (state)
519 : : {
520 : 24610848 : case idle:
521 : 24610848 : if (type == CPP_KEYWORD)
522 : 4244615 : switch (keyword)
523 : : {
524 : : default:
525 : : break;
526 : :
527 : 1984 : case RID__EXPORT:
528 : 1984 : got_export = true;
529 : 1984 : res = lang_hooks::PT_begin_pragma;
530 : 1984 : break;
531 : :
532 : 2398 : case RID__IMPORT:
533 : 2398 : is_import = true;
534 : : /* FALLTHRU */
535 : 4925 : case RID__MODULE:
536 : 4925 : state = module_first;
537 : 4925 : want_dot = false;
538 : 4925 : got_colon = false;
539 : 4925 : token_loc = loc;
540 : 4925 : import = NULL;
541 : 4925 : if (!got_export)
542 : 4925 : res = lang_hooks::PT_begin_pragma;
543 : : break;
544 : : }
545 : : break;
546 : :
547 : 4940 : case module_first:
548 : 4940 : if (is_import && type == CPP_HEADER_NAME)
549 : : {
550 : : /* A header name. The preprocessor will have already
551 : : done include searching and canonicalization. */
552 : 884 : state = module_end;
553 : 884 : goto header_unit;
554 : : }
555 : :
556 : 4056 : if (type == CPP_PADDING || type == CPP_COMMENT)
557 : : break;
558 : :
559 : 4041 : state = module_cont;
560 : 4041 : if (type == CPP_COLON && module)
561 : : {
562 : 211 : got_colon = true;
563 : 211 : import = module;
564 : 211 : break;
565 : : }
566 : : /* FALLTHROUGH */
567 : :
568 : 8798 : case module_cont:
569 : 8798 : switch (type)
570 : : {
571 : : case CPP_PADDING:
572 : : case CPP_COMMENT:
573 : : break;
574 : :
575 : 4026 : default:
576 : : /* If we ever need to pay attention to attributes for
577 : : header modules, more logic will be needed. */
578 : 4026 : state = module_end;
579 : 4026 : break;
580 : :
581 : 241 : case CPP_COLON:
582 : 241 : if (got_colon)
583 : 0 : state = module_end;
584 : 241 : got_colon = true;
585 : : /* FALLTHROUGH */
586 : 543 : case CPP_DOT:
587 : 543 : if (!want_dot)
588 : 9 : state = module_end;
589 : 543 : want_dot = false;
590 : 543 : break;
591 : :
592 : 6 : case CPP_PRAGMA_EOL:
593 : 6 : goto module_end;
594 : :
595 : 4142 : case CPP_NAME:
596 : 4142 : if (want_dot)
597 : : {
598 : : /* Got name instead of [.:]. */
599 : 0 : state = module_end;
600 : 0 : break;
601 : : }
602 : 4142 : header_unit:
603 : 5026 : import = get_module (value, import, got_colon);
604 : 5026 : want_dot = true;
605 : 5026 : break;
606 : : }
607 : : break;
608 : :
609 : 6155 : case module_end:
610 : 6155 : if (type == CPP_PRAGMA_EOL)
611 : : {
612 : 4919 : module_end:;
613 : : /* End of the directive, handle the name. */
614 : 4925 : if (import && (is_import || !flag_header_unit))
615 : 9020 : if (module_state *m
616 : 4510 : = preprocess_module (import, token_loc, module != NULL,
617 : 4510 : is_import, got_export, reader))
618 : 2094 : if (!module)
619 : 2079 : module = m;
620 : :
621 : 4925 : is_import = got_export = false;
622 : 4925 : state = idle;
623 : : }
624 : : break;
625 : : }
626 : :
627 : 24626911 : return res;
628 : : }
629 : : };
630 : :
631 : : /* Initialize or teardown. */
632 : :
633 : : uintptr_t
634 : 10232 : module_token_cdtor (cpp_reader *pfile, uintptr_t data_)
635 : : {
636 : 10232 : if (module_token_filter *filter = reinterpret_cast<module_token_filter *> (data_))
637 : : {
638 : 4489 : preprocessed_module (pfile);
639 : 4486 : delete filter;
640 : 4486 : data_ = 0;
641 : : }
642 : 5743 : else if (modules_p ())
643 : 4489 : data_ = reinterpret_cast<uintptr_t > (new module_token_filter (pfile));
644 : :
645 : 10229 : return data_;
646 : : }
647 : :
648 : : uintptr_t
649 : 24626911 : module_token_lang (int type, int keyword, tree value, location_t loc,
650 : : uintptr_t data_)
651 : : {
652 : 24626911 : module_token_filter *filter = reinterpret_cast<module_token_filter *> (data_);
653 : 24626911 : return filter->resume (type, keyword, value, loc);
654 : : }
655 : :
656 : : uintptr_t
657 : 758768 : module_token_pre (cpp_reader *pfile, const cpp_token *tok, uintptr_t data_)
658 : : {
659 : 758768 : if (!tok)
660 : 1520 : return module_token_cdtor (pfile, data_);
661 : :
662 : 757248 : int type = tok->type;
663 : 757248 : int keyword = RID_MAX;
664 : 757248 : tree value = NULL_TREE;
665 : :
666 : 757248 : if (tok->type == CPP_NAME)
667 : : {
668 : 322584 : value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
669 : 322584 : if (IDENTIFIER_KEYWORD_P (value))
670 : : {
671 : 125911 : keyword = C_RID_CODE (value);
672 : 125911 : type = CPP_KEYWORD;
673 : : }
674 : : }
675 : 434664 : else if (tok->type == CPP_HEADER_NAME)
676 : 45 : value = build_string (tok->val.str.len, (const char *)tok->val.str.text);
677 : :
678 : 757248 : return module_token_lang (type, keyword, value, tok->src_loc, data_);
679 : : }
680 : :
681 : : /* Parse a #pragma whose sole argument is a string constant.
682 : : If OPT is true, the argument is optional. */
683 : : static tree
684 : 121 : parse_strconst_pragma (const char* name, int opt)
685 : : {
686 : 121 : tree result, x;
687 : 121 : enum cpp_ttype t;
688 : :
689 : 121 : t = pragma_lex (&result);
690 : 121 : if (t == CPP_STRING)
691 : : {
692 : 48 : if (pragma_lex (&x) != CPP_EOF)
693 : 0 : warning (0, "junk at end of %<#pragma %s%>", name);
694 : 48 : return result;
695 : : }
696 : :
697 : 73 : if (t == CPP_EOF && opt)
698 : : return NULL_TREE;
699 : :
700 : 0 : error ("invalid %<#pragma %s%>", name);
701 : 0 : return error_mark_node;
702 : : }
703 : :
704 : : static void
705 : 0 : handle_pragma_vtable (cpp_reader* /*dfile*/)
706 : : {
707 : 0 : parse_strconst_pragma ("vtable", 0);
708 : 0 : sorry ("%<#pragma vtable%> no longer supported");
709 : 0 : }
710 : :
711 : : static void
712 : 0 : handle_pragma_unit (cpp_reader* /*dfile*/)
713 : : {
714 : : /* Validate syntax, but don't do anything. */
715 : 0 : parse_strconst_pragma ("unit", 0);
716 : 0 : }
717 : :
718 : : static void
719 : 79 : handle_pragma_interface (cpp_reader* /*dfile*/)
720 : : {
721 : 79 : tree fname = parse_strconst_pragma ("interface", 1);
722 : 79 : struct c_fileinfo *finfo;
723 : 79 : const char *filename;
724 : :
725 : 79 : if (fname == error_mark_node)
726 : : return;
727 : 79 : else if (fname == 0)
728 : 61 : filename = lbasename (LOCATION_FILE (input_location));
729 : : else
730 : 18 : filename = TREE_STRING_POINTER (fname);
731 : :
732 : 79 : finfo = get_fileinfo (LOCATION_FILE (input_location));
733 : :
734 : 79 : if (impl_file_chain == 0)
735 : : {
736 : : /* If this is zero at this point, then we are
737 : : auto-implementing. */
738 : 34 : if (main_input_filename == 0)
739 : 0 : main_input_filename = LOCATION_FILE (input_location);
740 : : }
741 : :
742 : 79 : finfo->interface_only = interface_strcmp (filename);
743 : : /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see
744 : : a definition in another file. */
745 : 79 : if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only)
746 : 79 : finfo->interface_unknown = 0;
747 : : }
748 : :
749 : : /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
750 : : We used to only allow this at toplevel, but that restriction was buggy
751 : : in older compilers and it seems reasonable to allow it in the headers
752 : : themselves, too. It only needs to precede the matching #p interface.
753 : :
754 : : We don't touch finfo->interface_only or finfo->interface_unknown;
755 : : the user must specify a matching #p interface for this to have
756 : : any effect. */
757 : :
758 : : static void
759 : 42 : handle_pragma_implementation (cpp_reader* /*dfile*/)
760 : : {
761 : 42 : tree fname = parse_strconst_pragma ("implementation", 1);
762 : 42 : const char *filename;
763 : 42 : struct impl_files *ifiles = impl_file_chain;
764 : :
765 : 42 : if (fname == error_mark_node)
766 : : return;
767 : :
768 : 42 : if (fname == 0)
769 : : {
770 : 12 : if (main_input_filename)
771 : : filename = main_input_filename;
772 : : else
773 : 0 : filename = LOCATION_FILE (input_location);
774 : 12 : filename = lbasename (filename);
775 : : }
776 : : else
777 : : {
778 : 30 : filename = TREE_STRING_POINTER (fname);
779 : 30 : if (cpp_included_before (parse_in, filename, input_location))
780 : 3 : warning (0, "%<#pragma implementation%> for %qs appears after "
781 : : "file is included", filename);
782 : : }
783 : :
784 : 45 : for (; ifiles; ifiles = ifiles->next)
785 : : {
786 : 3 : if (! filename_cmp (ifiles->filename, filename))
787 : : break;
788 : : }
789 : 42 : if (ifiles == 0)
790 : : {
791 : 42 : ifiles = XNEW (struct impl_files);
792 : 42 : ifiles->filename = xstrdup (filename);
793 : 42 : ifiles->next = impl_file_chain;
794 : 42 : impl_file_chain = ifiles;
795 : : }
796 : : }
797 : :
798 : : /* Issue an error message indicating that the lookup of NAME (an
799 : : IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */
800 : :
801 : : tree
802 : 1767 : unqualified_name_lookup_error (tree name, location_t loc)
803 : : {
804 : 1767 : if (loc == UNKNOWN_LOCATION)
805 : 1303 : loc = cp_expr_loc_or_input_loc (name);
806 : :
807 : 1767 : if (IDENTIFIER_ANY_OP_P (name))
808 : 9 : error_at (loc, "%qD not defined", name);
809 : 1758 : else if (!flag_concepts && name == ridpointers[(int)RID_REQUIRES])
810 : 0 : error_at (loc, "%<requires%> only available with %<-std=c++20%> or "
811 : : "%<-fconcepts%>");
812 : : else
813 : : {
814 : 1758 : if (!objc_diagnose_private_ivar (name))
815 : : {
816 : 1758 : auto_diagnostic_group d;
817 : 1758 : name_hint hint = suggest_alternatives_for (loc, name, true);
818 : 1758 : if (const char *suggestion = hint.suggestion ())
819 : : {
820 : 250 : gcc_rich_location richloc (loc);
821 : 250 : richloc.add_fixit_replace (suggestion);
822 : 250 : error_at (&richloc,
823 : : "%qD was not declared in this scope; did you mean %qs?",
824 : : name, suggestion);
825 : 250 : }
826 : : else
827 : 1508 : error_at (loc, "%qD was not declared in this scope", name);
828 : 1758 : }
829 : : /* Prevent repeated error messages by creating a VAR_DECL with
830 : : this NAME in the innermost block scope. */
831 : 1758 : if (local_bindings_p ())
832 : : {
833 : 1376 : tree decl = build_decl (loc, VAR_DECL, name, error_mark_node);
834 : 1376 : TREE_USED (decl) = true;
835 : 1376 : pushdecl (decl);
836 : : }
837 : : }
838 : :
839 : 1767 : return error_mark_node;
840 : : }
841 : :
842 : : /* Like unqualified_name_lookup_error, but NAME_EXPR is an unqualified-id
843 : : NAME, encapsulated with its location in a CP_EXPR, used as a function.
844 : : Returns an appropriate expression for NAME. */
845 : :
846 : : tree
847 : 529 : unqualified_fn_lookup_error (cp_expr name_expr)
848 : : {
849 : 529 : tree name = name_expr.get_value ();
850 : 529 : location_t loc = name_expr.get_location ();
851 : 529 : if (loc == UNKNOWN_LOCATION)
852 : 57 : loc = input_location;
853 : :
854 : 529 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
855 : 1 : name = TREE_OPERAND (name, 0);
856 : :
857 : 529 : if (processing_template_decl)
858 : : {
859 : : /* In a template, it is invalid to write "f()" or "f(3)" if no
860 : : declaration of "f" is available. Historically, G++ and most
861 : : other compilers accepted that usage since they deferred all name
862 : : lookup until instantiation time rather than doing unqualified
863 : : name lookup at template definition time; explain to the user what
864 : : is going wrong.
865 : :
866 : : Note that we have the exact wording of the following message in
867 : : the manual (trouble.texi, node "Name lookup"), so they need to
868 : : be kept in synch. */
869 : 65 : auto_diagnostic_group d;
870 : 65 : permerror (loc, "there are no arguments to %qD that depend on a template "
871 : : "parameter, so a declaration of %qD must be available",
872 : : name, name);
873 : :
874 : 65 : if (!flag_permissive)
875 : : {
876 : 47 : static bool hint;
877 : 47 : if (!hint)
878 : : {
879 : 38 : inform (loc, "(if you use %<-fpermissive%>, G++ will accept your "
880 : : "code, but allowing the use of an undeclared name is "
881 : : "deprecated)");
882 : 38 : hint = true;
883 : : }
884 : : }
885 : 65 : return name;
886 : 65 : }
887 : :
888 : 464 : return unqualified_name_lookup_error (name, loc);
889 : : }
890 : :
891 : :
892 : : /* Hasher for the conversion operator name hash table. */
893 : : struct conv_type_hasher : ggc_ptr_hash<tree_node>
894 : : {
895 : : /* Hash NODE, an identifier node in the table. TYPE_UID is
896 : : suitable, as we're not concerned about matching canonicalness
897 : : here. */
898 : 12837425 : static hashval_t hash (tree node)
899 : : {
900 : 12837425 : return (hashval_t) TYPE_UID (TREE_TYPE (node));
901 : : }
902 : :
903 : : /* Compare NODE, an identifier node in the table, against TYPE, an
904 : : incoming TYPE being looked up. */
905 : 15097718 : static bool equal (tree node, tree type)
906 : : {
907 : 15097718 : return TREE_TYPE (node) == type;
908 : : }
909 : : };
910 : :
911 : : /* This hash table maps TYPEs to the IDENTIFIER for a conversion
912 : : operator to TYPE. The nodes are IDENTIFIERs whose TREE_TYPE is the
913 : : TYPE. */
914 : :
915 : : static GTY (()) hash_table<conv_type_hasher> *conv_type_names;
916 : :
917 : : /* Return an identifier for a conversion operator to TYPE. We can get
918 : : from the returned identifier to the type. We store TYPE, which is
919 : : not necessarily the canonical type, which allows us to report the
920 : : form the user used in error messages. All these identifiers are
921 : : not in the identifier hash table, and have the same string name.
922 : : These IDENTIFIERS are not in the identifier hash table, and all
923 : : have the same IDENTIFIER_STRING. */
924 : :
925 : : tree
926 : 2427742 : make_conv_op_name (tree type)
927 : : {
928 : 2427742 : if (type == error_mark_node)
929 : : return error_mark_node;
930 : :
931 : 2427739 : if (conv_type_names == NULL)
932 : 19419 : conv_type_names = hash_table<conv_type_hasher>::create_ggc (31);
933 : :
934 : 2427739 : tree *slot = conv_type_names->find_slot_with_hash
935 : 2427739 : (type, (hashval_t) TYPE_UID (type), INSERT);
936 : 2427739 : tree identifier = *slot;
937 : 2427739 : if (!identifier)
938 : : {
939 : : /* Create a raw IDENTIFIER outside of the identifier hash
940 : : table. */
941 : 931757 : identifier = copy_node (conv_op_identifier);
942 : :
943 : : /* Just in case something managed to bind. */
944 : 931757 : IDENTIFIER_BINDING (identifier) = NULL;
945 : :
946 : : /* Hang TYPE off the identifier so it can be found easily later
947 : : when performing conversions. */
948 : 931757 : TREE_TYPE (identifier) = type;
949 : :
950 : 931757 : *slot = identifier;
951 : : }
952 : :
953 : : return identifier;
954 : : }
955 : :
956 : : /* Wrapper around build_lang_decl_loc(). Should gradually move to
957 : : build_lang_decl_loc() and then rename build_lang_decl_loc() back to
958 : : build_lang_decl(). */
959 : :
960 : : tree
961 : 253723569 : build_lang_decl (enum tree_code code, tree name, tree type)
962 : : {
963 : 253723569 : return build_lang_decl_loc (input_location, code, name, type);
964 : : }
965 : :
966 : : /* Build a decl from CODE, NAME, TYPE declared at LOC, and then add
967 : : DECL_LANG_SPECIFIC info to the result. */
968 : :
969 : : tree
970 : 466546380 : build_lang_decl_loc (location_t loc, enum tree_code code, tree name, tree type)
971 : : {
972 : 466546380 : tree t;
973 : :
974 : 466546380 : t = build_decl (loc, code, name, type);
975 : 466546380 : retrofit_lang_decl (t);
976 : :
977 : 466546380 : return t;
978 : : }
979 : :
980 : : /* Maybe add a raw lang_decl to T, a decl. Return true if it needed
981 : : one. */
982 : :
983 : : bool
984 : 979655554 : maybe_add_lang_decl_raw (tree t, bool decomp_p)
985 : : {
986 : 979655554 : size_t size;
987 : 979655554 : lang_decl_selector sel;
988 : :
989 : 979655554 : if (decomp_p)
990 : : sel = lds_decomp, size = sizeof (struct lang_decl_decomp);
991 : 979391472 : else if (TREE_CODE (t) == FUNCTION_DECL)
992 : : sel = lds_fn, size = sizeof (struct lang_decl_fn);
993 : : else if (TREE_CODE (t) == NAMESPACE_DECL)
994 : : sel = lds_ns, size = sizeof (struct lang_decl_ns);
995 : : else if (TREE_CODE (t) == PARM_DECL)
996 : : sel = lds_parm, size = sizeof (struct lang_decl_parm);
997 : : else if (LANG_DECL_HAS_MIN (t))
998 : : sel = lds_min, size = sizeof (struct lang_decl_min);
999 : : else
1000 : : return false;
1001 : :
1002 : 979655554 : struct lang_decl *ld
1003 : 979655554 : = (struct lang_decl *) ggc_internal_cleared_alloc (size);
1004 : :
1005 : 979655554 : ld->u.base.selector = sel;
1006 : 979655554 : DECL_LANG_SPECIFIC (t) = ld;
1007 : :
1008 : 979655554 : if (sel == lds_ns)
1009 : : /* Who'd create a namespace, only to put nothing in it? */
1010 : 951126 : ld->u.ns.bindings = hash_table<named_decl_hash>::create_ggc (499);
1011 : :
1012 : : if (GATHER_STATISTICS)
1013 : : {
1014 : : tree_node_counts[(int)lang_decl] += 1;
1015 : : tree_node_sizes[(int)lang_decl] += size;
1016 : : }
1017 : : return true;
1018 : : }
1019 : :
1020 : : /* T has just had a decl_lang_specific added. Initialize its
1021 : : linkage. */
1022 : :
1023 : : static void
1024 : 978095627 : set_decl_linkage (tree t)
1025 : : {
1026 : 978095627 : if (current_lang_name == lang_name_cplusplus
1027 : 978095627 : || decl_linkage (t) == lk_none)
1028 : 725774973 : SET_DECL_LANGUAGE (t, lang_cplusplus);
1029 : 252320654 : else if (current_lang_name == lang_name_c)
1030 : 252320654 : SET_DECL_LANGUAGE (t, lang_c);
1031 : : else
1032 : 0 : gcc_unreachable ();
1033 : 978095627 : }
1034 : :
1035 : : /* T is a VAR_DECL node that needs to be a decomposition of BASE. */
1036 : :
1037 : : void
1038 : 536321 : fit_decomposition_lang_decl (tree t, tree base)
1039 : : {
1040 : 536321 : if (struct lang_decl *orig_ld = DECL_LANG_SPECIFIC (t))
1041 : : {
1042 : 274595 : if (orig_ld->u.base.selector == lds_min)
1043 : : {
1044 : 1053 : maybe_add_lang_decl_raw (t, true);
1045 : 1053 : memcpy (DECL_LANG_SPECIFIC (t), orig_ld,
1046 : : sizeof (struct lang_decl_min));
1047 : : /* Reset selector, which will have been bashed by the
1048 : : memcpy. */
1049 : 1053 : DECL_LANG_SPECIFIC (t)->u.base.selector = lds_decomp;
1050 : : }
1051 : : else
1052 : 273542 : gcc_checking_assert (orig_ld->u.base.selector == lds_decomp);
1053 : : }
1054 : : else
1055 : : {
1056 : 261726 : maybe_add_lang_decl_raw (t, true);
1057 : 261726 : set_decl_linkage (t);
1058 : : }
1059 : :
1060 : 536321 : DECL_DECOMP_BASE (t) = base;
1061 : 536321 : }
1062 : :
1063 : : /* Add DECL_LANG_SPECIFIC info to T, if it needs one. Generally
1064 : : every C++ decl needs one, but C builtins etc do not. */
1065 : :
1066 : : void
1067 : 1192938205 : retrofit_lang_decl (tree t)
1068 : : {
1069 : 1192938205 : if (DECL_LANG_SPECIFIC (t))
1070 : : return;
1071 : :
1072 : 977833901 : if (maybe_add_lang_decl_raw (t, false))
1073 : 977833901 : set_decl_linkage (t);
1074 : : }
1075 : :
1076 : : void
1077 : 728340699 : cxx_dup_lang_specific_decl (tree node)
1078 : : {
1079 : 728340699 : int size;
1080 : :
1081 : 728340699 : if (! DECL_LANG_SPECIFIC (node))
1082 : : return;
1083 : :
1084 : 535850742 : switch (DECL_LANG_SPECIFIC (node)->u.base.selector)
1085 : : {
1086 : : case lds_min:
1087 : : size = sizeof (struct lang_decl_min);
1088 : : break;
1089 : : case lds_fn:
1090 : : size = sizeof (struct lang_decl_fn);
1091 : : break;
1092 : : case lds_ns:
1093 : : size = sizeof (struct lang_decl_ns);
1094 : : break;
1095 : : case lds_parm:
1096 : : size = sizeof (struct lang_decl_parm);
1097 : : break;
1098 : : case lds_decomp:
1099 : : size = sizeof (struct lang_decl_decomp);
1100 : : break;
1101 : 0 : default:
1102 : 0 : gcc_unreachable ();
1103 : : }
1104 : :
1105 : 535850742 : struct lang_decl *ld = (struct lang_decl *) ggc_internal_alloc (size);
1106 : 535850742 : memcpy (ld, DECL_LANG_SPECIFIC (node), size);
1107 : 535850742 : DECL_LANG_SPECIFIC (node) = ld;
1108 : :
1109 : : /* Directly clear some flags that do not apply to the copy
1110 : : (module_purview_p still does). */
1111 : 535850742 : ld->u.base.module_entity_p = false;
1112 : 535850742 : ld->u.base.module_import_p = false;
1113 : 535850742 : ld->u.base.module_keyed_decls_p = false;
1114 : :
1115 : 535850742 : if (GATHER_STATISTICS)
1116 : : {
1117 : : tree_node_counts[(int)lang_decl] += 1;
1118 : : tree_node_sizes[(int)lang_decl] += size;
1119 : : }
1120 : : }
1121 : :
1122 : : /* Copy DECL, including any language-specific parts. */
1123 : :
1124 : : tree
1125 : 428217323 : copy_decl (tree decl MEM_STAT_DECL)
1126 : : {
1127 : 428217323 : tree copy;
1128 : :
1129 : 428217323 : copy = copy_node (decl PASS_MEM_STAT);
1130 : 428217323 : cxx_dup_lang_specific_decl (copy);
1131 : 428217323 : return copy;
1132 : : }
1133 : :
1134 : : /* Replace the shared language-specific parts of NODE with a new copy. */
1135 : :
1136 : : static void
1137 : 12756664 : copy_lang_type (tree node)
1138 : : {
1139 : 12756664 : if (! TYPE_LANG_SPECIFIC (node))
1140 : : return;
1141 : :
1142 : 0 : size_t sz = (c_dialect_objc () ? sizeof (struct lang_type)
1143 : : : offsetof (struct lang_type, info));
1144 : 0 : auto *lt = (struct lang_type *) ggc_internal_alloc (sz);
1145 : :
1146 : 0 : memcpy (lt, TYPE_LANG_SPECIFIC (node), sz);
1147 : 0 : TYPE_LANG_SPECIFIC (node) = lt;
1148 : :
1149 : 0 : if (GATHER_STATISTICS)
1150 : : {
1151 : : tree_node_counts[(int)lang_type] += 1;
1152 : : tree_node_sizes[(int)lang_type] += sz;
1153 : : }
1154 : : }
1155 : :
1156 : : /* Copy TYPE, including any language-specific parts. */
1157 : :
1158 : : tree
1159 : 12756664 : copy_type (tree type MEM_STAT_DECL)
1160 : : {
1161 : 12756664 : tree copy;
1162 : :
1163 : 12756664 : copy = copy_node (type PASS_MEM_STAT);
1164 : 12756664 : copy_lang_type (copy);
1165 : 12756664 : return copy;
1166 : : }
1167 : :
1168 : : /* Add a raw lang_type to T, a type, should it need one. */
1169 : :
1170 : : bool
1171 : 696551035 : maybe_add_lang_type_raw (tree t)
1172 : : {
1173 : 696551035 : if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t)))
1174 : : return false;
1175 : :
1176 : 113161945 : size_t sz = (c_dialect_objc () ? sizeof (struct lang_type)
1177 : : : offsetof (struct lang_type, info));
1178 : 113161945 : auto *lt = (struct lang_type *) (ggc_internal_cleared_alloc (sz));
1179 : 113161945 : TYPE_LANG_SPECIFIC (t) = lt;
1180 : :
1181 : 113161945 : if (GATHER_STATISTICS)
1182 : : {
1183 : : tree_node_counts[(int)lang_type] += 1;
1184 : : tree_node_sizes[(int)lang_type] += sz;
1185 : : }
1186 : :
1187 : 113161945 : return true;
1188 : : }
1189 : :
1190 : : tree
1191 : 696438834 : cxx_make_type (enum tree_code code MEM_STAT_DECL)
1192 : : {
1193 : 696438834 : tree t = make_node (code PASS_MEM_STAT);
1194 : :
1195 : 696438834 : if (maybe_add_lang_type_raw (t))
1196 : : {
1197 : : /* Set up some flags that give proper default behavior. */
1198 : 113049744 : struct c_fileinfo *finfo
1199 : 113049744 : = get_fileinfo (LOCATION_FILE (input_location));
1200 : 113049744 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
1201 : 113049744 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
1202 : : }
1203 : :
1204 : 696438834 : if (code == RECORD_TYPE || code == UNION_TYPE)
1205 : 113049744 : TYPE_CXX_ODR_P (t) = 1;
1206 : :
1207 : 696438834 : return t;
1208 : : }
1209 : :
1210 : : /* A wrapper without the memory stats for LANG_HOOKS_MAKE_TYPE. */
1211 : :
1212 : : tree
1213 : 127549 : cxx_make_type_hook (enum tree_code code)
1214 : : {
1215 : 127549 : return cxx_make_type (code);
1216 : : }
1217 : :
1218 : : tree
1219 : 112922177 : make_class_type (enum tree_code code MEM_STAT_DECL)
1220 : : {
1221 : 112922177 : tree t = cxx_make_type (code PASS_MEM_STAT);
1222 : 112922177 : SET_CLASS_TYPE_P (t, 1);
1223 : 112922177 : return t;
1224 : : }
1225 : :
1226 : : /* Returns true if we are currently in the main source file, or in a
1227 : : template instantiation started from the main source file. */
1228 : :
1229 : : bool
1230 : 143 : in_main_input_context (void)
1231 : : {
1232 : 143 : struct tinst_level *tl = outermost_tinst_level();
1233 : :
1234 : 143 : if (tl)
1235 : 9 : return filename_cmp (main_input_filename,
1236 : 18 : LOCATION_FILE (tl->locus)) == 0;
1237 : : else
1238 : 134 : return filename_cmp (main_input_filename, LOCATION_FILE (input_location)) == 0;
1239 : : }
1240 : :
1241 : : #include "gt-cp-lex.h"
|