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 : 96442 : cxx_finish (void)
81 : : {
82 : 96442 : c_common_finish ();
83 : 96442 : }
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 : 25708401 : set_identifier_kind (tree id, cp_identifier_kind kind)
136 : : {
137 : 25708401 : gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
138 : : & !IDENTIFIER_KIND_BIT_1 (id)
139 : : & !IDENTIFIER_KIND_BIT_0 (id));
140 : 25708401 : IDENTIFIER_KIND_BIT_2 (id) |= (kind >> 2) & 1;
141 : 25708401 : IDENTIFIER_KIND_BIT_1 (id) |= (kind >> 1) & 1;
142 : 25708401 : IDENTIFIER_KIND_BIT_0 (id) |= (kind >> 0) & 1;
143 : 25708401 : }
144 : :
145 : : /* Create and tag the internal operator name for the overloaded
146 : : operator PTR describes. */
147 : :
148 : : static tree
149 : 5411504 : set_operator_ident (ovl_op_info_t *ptr)
150 : : {
151 : 5411504 : char buffer[32];
152 : 10823008 : size_t len = snprintf (buffer, sizeof (buffer), "operator%s%s",
153 : 5411504 : &" "[ptr->name[0] && ptr->name[0] != '_'
154 : 5411504 : && !ISALPHA (ptr->name[0])],
155 : 5411504 : ptr->name);
156 : 5411504 : gcc_checking_assert (len < sizeof (buffer));
157 : :
158 : 5411504 : tree ident = get_identifier_with_length (buffer, len);
159 : 5411504 : ptr->identifier = ident;
160 : :
161 : 5411504 : return ident;
162 : : }
163 : :
164 : : /* Initialize data structures that keep track of operator names. */
165 : :
166 : : static void
167 : 96634 : init_operators (void)
168 : : {
169 : : /* We rely on both these being zero. */
170 : 96634 : 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 : 5604772 : for (unsigned ix = OVL_OP_MAX; --ix;)
177 : : {
178 : 5508138 : ovl_op_info_t *op_ptr = &ovl_op_info[false][ix];
179 : :
180 : 5508138 : if (op_ptr->name)
181 : : {
182 : 4348530 : tree ident = set_operator_ident (op_ptr);
183 : 4348530 : if (unsigned index = IDENTIFIER_CP_INDEX (ident))
184 : : {
185 : 579804 : ovl_op_info_t *bin_ptr = &ovl_op_info[false][index];
186 : :
187 : : /* They should only differ in unary/binary ness. */
188 : 579804 : gcc_checking_assert ((op_ptr->flags ^ bin_ptr->flags)
189 : : == OVL_OP_FLAG_AMBIARY);
190 : 579804 : bin_ptr->flags |= op_ptr->flags;
191 : 579804 : ovl_op_alternate[index] = ix;
192 : : }
193 : : else
194 : : {
195 : 3768726 : IDENTIFIER_CP_INDEX (ident) = ix;
196 : 3768726 : set_identifier_kind (ident, cik_simple_op);
197 : : }
198 : : }
199 : 5508138 : if (op_ptr->tree_code)
200 : : {
201 : 5508138 : gcc_checking_assert (op_ptr->ovl_op_code == ix
202 : : && !ovl_op_mapping[op_ptr->tree_code]);
203 : 5508138 : ovl_op_mapping[op_ptr->tree_code] = op_ptr->ovl_op_code;
204 : : }
205 : :
206 : 5508138 : ovl_op_info_t *as_ptr = &ovl_op_info[true][ix];
207 : 5508138 : 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 : 1062974 : if (as_ptr->ovl_op_code != ix)
212 : : {
213 : 966340 : ovl_op_info_t *dst_ptr = &ovl_op_info[true][as_ptr->ovl_op_code];
214 : 966340 : gcc_assert (as_ptr->ovl_op_code > ix && !dst_ptr->tree_code);
215 : 966340 : memcpy (dst_ptr, as_ptr, sizeof (*dst_ptr));
216 : 966340 : memset (as_ptr, 0, sizeof (*as_ptr));
217 : 966340 : as_ptr = dst_ptr;
218 : : }
219 : :
220 : 1062974 : tree ident = set_operator_ident (as_ptr);
221 : 1062974 : gcc_checking_assert (!IDENTIFIER_CP_INDEX (ident));
222 : 1062974 : IDENTIFIER_CP_INDEX (ident) = as_ptr->ovl_op_code;
223 : 1062974 : set_identifier_kind (ident, cik_assign_op);
224 : :
225 : 1062974 : 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 : 1062974 : ovl_op_mapping[as_ptr->tree_code] = as_ptr->ovl_op_code;
229 : : }
230 : : }
231 : 96634 : }
232 : :
233 : : /* Initialize the reserved words. */
234 : :
235 : : void
236 : 96634 : init_reswords (void)
237 : : {
238 : 96634 : unsigned int i;
239 : 96634 : tree id;
240 : 96634 : int mask = 0;
241 : :
242 : 96634 : if (cxx_dialect < cxx11)
243 : 14023 : mask |= D_CXX11;
244 : 96634 : if (cxx_dialect < cxx20)
245 : 65950 : mask |= D_CXX20;
246 : 96634 : if (cxx_dialect < cxx26)
247 : 72960 : mask |= D_CXX26;
248 : 96634 : if (!flag_concepts)
249 : 65757 : mask |= D_CXX_CONCEPTS;
250 : 96634 : if (!flag_coroutines)
251 : 64987 : mask |= D_CXX_COROUTINES;
252 : 96634 : if (!flag_modules)
253 : 92040 : mask |= D_CXX_MODULES;
254 : 96634 : if (!flag_tm)
255 : 96315 : mask |= D_TRANSMEM;
256 : 96634 : if (!flag_char8_t)
257 : 65892 : mask |= D_CXX_CHAR8_T;
258 : 96634 : if (flag_no_asm)
259 : 3 : mask |= D_ASM | D_EXT | D_EXT11;
260 : 96634 : if (flag_no_gnu_keywords)
261 : 50770 : mask |= D_EXT | D_EXT11;
262 : :
263 : : /* The Objective-C keywords are all context-dependent. */
264 : 96634 : mask |= D_OBJC;
265 : :
266 : 96634 : ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
267 : 22129186 : for (i = 0; i < num_c_common_reswords; i++)
268 : : {
269 : 22032552 : if (c_common_reswords[i].disable & D_CONLY)
270 : 4638432 : continue;
271 : 17394120 : id = get_identifier (c_common_reswords[i].word);
272 : 17394120 : C_SET_RID_CODE (id, c_common_reswords[i].rid);
273 : 17394120 : ridpointers [(int) c_common_reswords[i].rid] = id;
274 : 17394120 : if (! (c_common_reswords[i].disable & mask))
275 : 12658951 : set_identifier_kind (id, cik_keyword);
276 : : }
277 : :
278 : 193268 : for (i = 0; i < NUM_INT_N_ENTS; i++)
279 : : {
280 : 96634 : char name[50];
281 : 96634 : sprintf (name, "__int%d", int_n_data[i].bitsize);
282 : 96634 : id = get_identifier (name);
283 : 96634 : C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
284 : 96634 : set_identifier_kind (id, cik_keyword);
285 : :
286 : 96634 : sprintf (name, "__int%d__", int_n_data[i].bitsize);
287 : 96634 : id = get_identifier (name);
288 : 96634 : C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
289 : 96634 : set_identifier_kind (id, cik_keyword);
290 : : }
291 : :
292 : 96634 : if (flag_openmp)
293 : : {
294 : 3860 : id = get_identifier ("omp_all_memory");
295 : 3860 : C_SET_RID_CODE (id, RID_OMP_ALL_MEMORY);
296 : 3860 : set_identifier_kind (id, cik_keyword);
297 : 3860 : ridpointers [RID_OMP_ALL_MEMORY] = id;
298 : : }
299 : 96634 : }
300 : :
301 : : /* Initialize the C++ traits. */
302 : : static void
303 : 96634 : init_cp_traits (void)
304 : : {
305 : 96634 : tree id;
306 : :
307 : 7247550 : for (unsigned int i = 0; i < ARRAY_SIZE (cp_traits); ++i)
308 : : {
309 : 7150916 : id = get_identifier (cp_traits[i].name);
310 : 7150916 : IDENTIFIER_CP_INDEX (id) = cp_traits[i].kind;
311 : 7150916 : set_identifier_kind (id, cik_trait);
312 : : }
313 : :
314 : : /* An alias for __is_same. */
315 : 96634 : id = get_identifier ("__is_same_as");
316 : 96634 : IDENTIFIER_CP_INDEX (id) = CPTK_IS_SAME;
317 : 96634 : set_identifier_kind (id, cik_trait);
318 : 96634 : }
319 : :
320 : : static void
321 : 95225 : init_cp_pragma (void)
322 : : {
323 : 95225 : c_register_pragma (0, "vtable", handle_pragma_vtable);
324 : 95225 : c_register_pragma (0, "unit", handle_pragma_unit);
325 : 95225 : c_register_pragma (0, "interface", handle_pragma_interface);
326 : 95225 : c_register_pragma (0, "implementation", handle_pragma_implementation);
327 : 95225 : c_register_pragma ("GCC", "interface", handle_pragma_interface);
328 : 95225 : c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
329 : 95225 : }
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 : 96634 : cxx_init (void)
341 : : {
342 : 96634 : location_t saved_loc;
343 : 96634 : unsigned int i;
344 : 96634 : 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 : 96634 : memset (&statement_code_p, 0, sizeof (statement_code_p));
354 : 1739412 : for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
355 : 1642778 : statement_code_p[stmt_codes[i]] = true;
356 : :
357 : 96634 : saved_loc = input_location;
358 : 96634 : input_location = BUILTINS_LOCATION;
359 : :
360 : 96634 : init_reswords ();
361 : 96634 : init_cp_traits ();
362 : 96634 : init_tree ();
363 : 96634 : init_cp_semantics ();
364 : 96634 : init_operators ();
365 : 96634 : init_method ();
366 : :
367 : 96634 : current_function_decl = NULL;
368 : :
369 : 96634 : class_type_node = ridpointers[(int) RID_CLASS];
370 : :
371 : 96634 : cxx_init_decl_processing ();
372 : :
373 : 96634 : if (warn_keyword_macro)
374 : : {
375 : 3231877 : 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 : 3217764 : if (c_common_reswords[i].word[0] == '_')
380 : 1453639 : continue;
381 : 1764125 : else if (c_common_reswords[i].disable & (D_TRANSMEM | D_OBJC))
382 : 536294 : continue;
383 : : else
384 : : {
385 : 1227831 : tree id = get_identifier (c_common_reswords[i].word);
386 : 1227831 : if (IDENTIFIER_KEYWORD_P (id)
387 : : /* Don't register keywords with spaces. */
388 : 2375551 : && IDENTIFIER_POINTER (id)[IDENTIFIER_LENGTH (id) - 1] != ' ')
389 : 1143280 : cpp_warn (parse_in, IDENTIFIER_POINTER (id),
390 : 1143280 : IDENTIFIER_LENGTH (id));
391 : : }
392 : 14113 : if (cxx_dialect >= cxx11)
393 : : {
394 : 14112 : cpp_warn (parse_in, "final");
395 : 14112 : cpp_warn (parse_in, "override");
396 : 14112 : cpp_warn (parse_in, "noreturn");
397 : 14112 : if (cxx_dialect < cxx26)
398 : 11 : cpp_warn (parse_in, "carries_dependency");
399 : : }
400 : 14113 : if (cxx_dialect >= cxx14)
401 : 14110 : cpp_warn (parse_in, "deprecated");
402 : 14113 : if (cxx_dialect >= cxx17)
403 : : {
404 : 14108 : cpp_warn (parse_in, "fallthrough");
405 : 14108 : cpp_warn (parse_in, "maybe_unused");
406 : 14108 : cpp_warn (parse_in, "nodiscard");
407 : : }
408 : 14113 : if (cxx_dialect >= cxx20)
409 : : {
410 : 14105 : cpp_warn (parse_in, "likely");
411 : 14105 : cpp_warn (parse_in, "unlikely");
412 : 14105 : cpp_warn (parse_in, "no_unique_address");
413 : : }
414 : 14113 : if (flag_modules)
415 : : {
416 : 1480 : cpp_warn (parse_in, "import");
417 : 1480 : cpp_warn (parse_in, "module");
418 : : }
419 : 14113 : if (cxx_dialect >= cxx23)
420 : 14103 : cpp_warn (parse_in, "assume");
421 : 14113 : if (cxx_dialect >= cxx26)
422 : 14101 : cpp_warn (parse_in, "indeterminate");
423 : : }
424 : :
425 : 96634 : if (c_common_init () == false)
426 : : {
427 : 1371 : input_location = saved_loc;
428 : 1371 : return false;
429 : : }
430 : :
431 : 95225 : init_cp_pragma ();
432 : :
433 : 95225 : input_location = saved_loc;
434 : 95225 : return true;
435 : : }
436 : :
437 : : /* Return nonzero if S is not considered part of an
438 : : INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
439 : :
440 : : static int
441 : 79 : interface_strcmp (const char* s)
442 : : {
443 : : /* Set the interface/implementation bits for this scope. */
444 : 79 : struct impl_files *ifiles;
445 : 79 : const char *s1;
446 : :
447 : 91 : for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
448 : : {
449 : 48 : const char *t1 = ifiles->filename;
450 : 48 : s1 = s;
451 : :
452 : 48 : if (*s1 == 0 || filename_ncmp (s1, t1, 1) != 0)
453 : 6 : continue;
454 : :
455 : 462 : while (*s1 != 0 && filename_ncmp (s1, t1, 1) == 0)
456 : 420 : s1++, t1++;
457 : :
458 : : /* A match. */
459 : 42 : if (*s1 == *t1)
460 : : return 0;
461 : :
462 : : /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
463 : 18 : if (strchr (s1, '.') || strchr (t1, '.'))
464 : 6 : continue;
465 : :
466 : 12 : if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
467 : 0 : continue;
468 : :
469 : : /* A match. */
470 : : return 0;
471 : : }
472 : :
473 : : /* No matches. */
474 : : return 1;
475 : : }
476 : :
477 : : /* We've just read a cpp-token, figure out our next state. Hey, this
478 : : is a hand-coded co-routine! */
479 : :
480 : : struct module_token_filter
481 : : {
482 : : enum state
483 : : {
484 : : idle,
485 : : module_first,
486 : : module_cont,
487 : : module_end,
488 : : };
489 : :
490 : : enum state state : 8;
491 : : bool is_import : 1;
492 : : bool got_export : 1;
493 : : bool got_colon : 1;
494 : : bool want_dot : 1;
495 : :
496 : : location_t token_loc;
497 : : cpp_reader *reader;
498 : : module_state *module;
499 : : module_state *import;
500 : :
501 : 4594 : module_token_filter (cpp_reader *reader)
502 : 4594 : : state (idle), is_import (false),
503 : 4594 : got_export (false), got_colon (false), want_dot (false),
504 : 4594 : token_loc (UNKNOWN_LOCATION),
505 : 4594 : reader (reader), module (NULL), import (NULL)
506 : : {
507 : : };
508 : :
509 : : /* Process the next token. Note we cannot see CPP_EOF inside a
510 : : pragma -- a CPP_PRAGMA_EOL always happens. */
511 : 24683194 : uintptr_t resume (int type, int keyword, tree value, location_t loc)
512 : : {
513 : 24683194 : unsigned res = 0;
514 : :
515 : 24683194 : switch (state)
516 : : {
517 : 24666768 : case idle:
518 : 24666768 : if (type == CPP_KEYWORD)
519 : 4255905 : switch (keyword)
520 : : {
521 : : default:
522 : : break;
523 : :
524 : 2029 : case RID__EXPORT:
525 : 2029 : got_export = true;
526 : 2029 : res = lang_hooks::PT_begin_pragma;
527 : 2029 : break;
528 : :
529 : 2449 : case RID__IMPORT:
530 : 2449 : is_import = true;
531 : : /* FALLTHRU */
532 : 5045 : case RID__MODULE:
533 : 5045 : state = module_first;
534 : 5045 : want_dot = false;
535 : 5045 : got_colon = false;
536 : 5045 : token_loc = loc;
537 : 5045 : import = NULL;
538 : 5045 : if (!got_export)
539 : 5045 : res = lang_hooks::PT_begin_pragma;
540 : : break;
541 : : }
542 : : break;
543 : :
544 : 5060 : case module_first:
545 : 5060 : if (is_import && type == CPP_HEADER_NAME)
546 : : {
547 : : /* A header name. The preprocessor will have already
548 : : done include searching and canonicalization. */
549 : 893 : state = module_end;
550 : 893 : goto header_unit;
551 : : }
552 : :
553 : 4167 : if (type == CPP_PADDING || type == CPP_COMMENT)
554 : : break;
555 : :
556 : 4152 : state = module_cont;
557 : 4152 : if (type == CPP_COLON && module)
558 : : {
559 : 217 : got_colon = true;
560 : 217 : import = module;
561 : 217 : break;
562 : : }
563 : : /* FALLTHROUGH */
564 : :
565 : 9017 : case module_cont:
566 : 9017 : switch (type)
567 : : {
568 : : case CPP_PADDING:
569 : : case CPP_COMMENT:
570 : : break;
571 : :
572 : 4137 : default:
573 : : /* If we ever need to pay attention to attributes for
574 : : header modules, more logic will be needed. */
575 : 4137 : state = module_end;
576 : 4137 : break;
577 : :
578 : 247 : case CPP_COLON:
579 : 247 : if (got_colon)
580 : 0 : state = module_end;
581 : 247 : got_colon = true;
582 : : /* FALLTHROUGH */
583 : 549 : case CPP_DOT:
584 : 549 : if (!want_dot)
585 : 9 : state = module_end;
586 : 549 : want_dot = false;
587 : 549 : break;
588 : :
589 : 6 : case CPP_PRAGMA_EOL:
590 : 6 : goto module_end;
591 : :
592 : 4244 : case CPP_NAME:
593 : 4244 : if (want_dot)
594 : : {
595 : : /* Got name instead of [.:]. */
596 : 0 : state = module_end;
597 : 0 : break;
598 : : }
599 : 4244 : header_unit:
600 : 5137 : import = get_module (value, import, got_colon);
601 : 5137 : want_dot = true;
602 : 5137 : break;
603 : : }
604 : : break;
605 : :
606 : 6284 : case module_end:
607 : 6284 : if (type == CPP_PRAGMA_EOL)
608 : : {
609 : 5039 : module_end:;
610 : : /* End of the directive, handle the name. */
611 : 5045 : if (import && (is_import || !flag_header_unit))
612 : 9230 : if (module_state *m
613 : 4615 : = preprocess_module (import, token_loc, module != NULL,
614 : 4615 : is_import, got_export, reader))
615 : 2148 : if (!module)
616 : 2133 : module = m;
617 : :
618 : 5045 : is_import = got_export = false;
619 : 5045 : state = idle;
620 : : }
621 : : break;
622 : : }
623 : :
624 : 24683194 : return res;
625 : : }
626 : : };
627 : :
628 : : /* Initialize or teardown. */
629 : :
630 : : uintptr_t
631 : 10458 : module_token_cdtor (cpp_reader *pfile, uintptr_t data_)
632 : : {
633 : 10458 : if (module_token_filter *filter = reinterpret_cast<module_token_filter *> (data_))
634 : : {
635 : 4594 : preprocessed_module (pfile);
636 : 4591 : delete filter;
637 : 4591 : data_ = 0;
638 : : }
639 : 5864 : else if (modules_p ())
640 : 4594 : data_ = reinterpret_cast<uintptr_t > (new module_token_filter (pfile));
641 : :
642 : 10455 : return data_;
643 : : }
644 : :
645 : : uintptr_t
646 : 24683194 : module_token_lang (int type, int keyword, tree value, location_t loc,
647 : : uintptr_t data_)
648 : : {
649 : 24683194 : module_token_filter *filter = reinterpret_cast<module_token_filter *> (data_);
650 : 24683194 : return filter->resume (type, keyword, value, loc);
651 : : }
652 : :
653 : : uintptr_t
654 : 761584 : module_token_pre (cpp_reader *pfile, const cpp_token *tok, uintptr_t data_)
655 : : {
656 : 761584 : if (!tok)
657 : 1536 : return module_token_cdtor (pfile, data_);
658 : :
659 : 760048 : int type = tok->type;
660 : 760048 : int keyword = RID_MAX;
661 : 760048 : tree value = NULL_TREE;
662 : :
663 : 760048 : if (tok->type == CPP_NAME)
664 : : {
665 : 323749 : value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
666 : 323749 : if (IDENTIFIER_KEYWORD_P (value))
667 : : {
668 : 126330 : keyword = C_RID_CODE (value);
669 : 126330 : type = CPP_KEYWORD;
670 : : }
671 : : }
672 : 436299 : else if (tok->type == CPP_HEADER_NAME)
673 : 45 : value = build_string (tok->val.str.len, (const char *)tok->val.str.text);
674 : :
675 : 760048 : return module_token_lang (type, keyword, value, tok->src_loc, data_);
676 : : }
677 : :
678 : : /* Parse a #pragma whose sole argument is a string constant.
679 : : If OPT is true, the argument is optional. */
680 : : static tree
681 : 121 : parse_strconst_pragma (const char* name, int opt)
682 : : {
683 : 121 : tree result, x;
684 : 121 : enum cpp_ttype t;
685 : :
686 : 121 : t = pragma_lex (&result);
687 : 121 : if (t == CPP_STRING)
688 : : {
689 : 48 : if (pragma_lex (&x) != CPP_EOF)
690 : 0 : warning (0, "junk at end of %<#pragma %s%>", name);
691 : 48 : return result;
692 : : }
693 : :
694 : 73 : if (t == CPP_EOF && opt)
695 : : return NULL_TREE;
696 : :
697 : 0 : error ("invalid %<#pragma %s%>", name);
698 : 0 : return error_mark_node;
699 : : }
700 : :
701 : : static void
702 : 0 : handle_pragma_vtable (cpp_reader* /*dfile*/)
703 : : {
704 : 0 : parse_strconst_pragma ("vtable", 0);
705 : 0 : sorry ("%<#pragma vtable%> no longer supported");
706 : 0 : }
707 : :
708 : : static void
709 : 0 : handle_pragma_unit (cpp_reader* /*dfile*/)
710 : : {
711 : : /* Validate syntax, but don't do anything. */
712 : 0 : parse_strconst_pragma ("unit", 0);
713 : 0 : }
714 : :
715 : : static void
716 : 79 : handle_pragma_interface (cpp_reader* /*dfile*/)
717 : : {
718 : 79 : tree fname = parse_strconst_pragma ("interface", 1);
719 : 79 : struct c_fileinfo *finfo;
720 : 79 : const char *filename;
721 : :
722 : 79 : if (fname == error_mark_node)
723 : : return;
724 : 79 : else if (fname == 0)
725 : 61 : filename = lbasename (LOCATION_FILE (input_location));
726 : : else
727 : 18 : filename = TREE_STRING_POINTER (fname);
728 : :
729 : 79 : finfo = get_fileinfo (LOCATION_FILE (input_location));
730 : :
731 : 79 : if (impl_file_chain == 0)
732 : : {
733 : : /* If this is zero at this point, then we are
734 : : auto-implementing. */
735 : 34 : if (main_input_filename == 0)
736 : 0 : main_input_filename = LOCATION_FILE (input_location);
737 : : }
738 : :
739 : 79 : finfo->interface_only = interface_strcmp (filename);
740 : : /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see
741 : : a definition in another file. */
742 : 79 : if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only)
743 : 79 : finfo->interface_unknown = 0;
744 : : }
745 : :
746 : : /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
747 : : We used to only allow this at toplevel, but that restriction was buggy
748 : : in older compilers and it seems reasonable to allow it in the headers
749 : : themselves, too. It only needs to precede the matching #p interface.
750 : :
751 : : We don't touch finfo->interface_only or finfo->interface_unknown;
752 : : the user must specify a matching #p interface for this to have
753 : : any effect. */
754 : :
755 : : static void
756 : 42 : handle_pragma_implementation (cpp_reader* /*dfile*/)
757 : : {
758 : 42 : tree fname = parse_strconst_pragma ("implementation", 1);
759 : 42 : const char *filename;
760 : 42 : struct impl_files *ifiles = impl_file_chain;
761 : :
762 : 42 : if (fname == error_mark_node)
763 : : return;
764 : :
765 : 42 : if (fname == 0)
766 : : {
767 : 12 : if (main_input_filename)
768 : : filename = main_input_filename;
769 : : else
770 : 0 : filename = LOCATION_FILE (input_location);
771 : 12 : filename = lbasename (filename);
772 : : }
773 : : else
774 : : {
775 : 30 : filename = TREE_STRING_POINTER (fname);
776 : 30 : if (cpp_included_before (parse_in, filename, input_location))
777 : 3 : warning (0, "%<#pragma implementation%> for %qs appears after "
778 : : "file is included", filename);
779 : : }
780 : :
781 : 45 : for (; ifiles; ifiles = ifiles->next)
782 : : {
783 : 3 : if (! filename_cmp (ifiles->filename, filename))
784 : : break;
785 : : }
786 : 42 : if (ifiles == 0)
787 : : {
788 : 42 : ifiles = XNEW (struct impl_files);
789 : 42 : ifiles->filename = xstrdup (filename);
790 : 42 : ifiles->next = impl_file_chain;
791 : 42 : impl_file_chain = ifiles;
792 : : }
793 : : }
794 : :
795 : : /* Issue an error message indicating that the lookup of NAME (an
796 : : IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */
797 : :
798 : : tree
799 : 1771 : unqualified_name_lookup_error (tree name, location_t loc)
800 : : {
801 : 1771 : if (loc == UNKNOWN_LOCATION)
802 : 1304 : loc = cp_expr_loc_or_input_loc (name);
803 : :
804 : 1771 : if (IDENTIFIER_ANY_OP_P (name))
805 : 9 : error_at (loc, "%qD not defined", name);
806 : 1762 : else if (!flag_concepts && name == ridpointers[(int)RID_REQUIRES])
807 : 0 : error_at (loc, "%<requires%> only available with %<-std=c++20%> or "
808 : : "%<-fconcepts%>");
809 : : else
810 : : {
811 : 1762 : if (!objc_diagnose_private_ivar (name))
812 : : {
813 : 1762 : auto_diagnostic_group d;
814 : 1762 : name_hint hint = suggest_alternatives_for (loc, name, true);
815 : 1762 : if (const char *suggestion = hint.suggestion ())
816 : : {
817 : 255 : gcc_rich_location richloc (loc);
818 : 255 : richloc.add_fixit_replace (suggestion);
819 : 255 : error_at (&richloc,
820 : : "%qD was not declared in this scope; did you mean %qs?",
821 : : name, suggestion);
822 : 255 : }
823 : : else
824 : 1507 : error_at (loc, "%qD was not declared in this scope", name);
825 : 1762 : }
826 : : /* Prevent repeated error messages by creating a VAR_DECL with
827 : : this NAME in the innermost block scope. */
828 : 1762 : if (local_bindings_p ())
829 : : {
830 : 1379 : tree decl = build_decl (loc, VAR_DECL, name, error_mark_node);
831 : 1379 : TREE_USED (decl) = true;
832 : 1379 : pushdecl (decl);
833 : : }
834 : : }
835 : :
836 : 1771 : return error_mark_node;
837 : : }
838 : :
839 : : /* Like unqualified_name_lookup_error, but NAME_EXPR is an unqualified-id
840 : : NAME, encapsulated with its location in a CP_EXPR, used as a function.
841 : : Returns an appropriate expression for NAME. */
842 : :
843 : : tree
844 : 532 : unqualified_fn_lookup_error (cp_expr name_expr)
845 : : {
846 : 532 : tree name = name_expr.get_value ();
847 : 532 : location_t loc = name_expr.get_location ();
848 : 532 : if (loc == UNKNOWN_LOCATION)
849 : 57 : loc = input_location;
850 : :
851 : 532 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
852 : 1 : name = TREE_OPERAND (name, 0);
853 : :
854 : 532 : if (processing_template_decl)
855 : : {
856 : : /* In a template, it is invalid to write "f()" or "f(3)" if no
857 : : declaration of "f" is available. Historically, G++ and most
858 : : other compilers accepted that usage since they deferred all name
859 : : lookup until instantiation time rather than doing unqualified
860 : : name lookup at template definition time; explain to the user what
861 : : is going wrong.
862 : :
863 : : Note that we have the exact wording of the following message in
864 : : the manual (trouble.texi, node "Name lookup"), so they need to
865 : : be kept in synch. */
866 : 65 : auto_diagnostic_group d;
867 : 65 : permerror (loc, "there are no arguments to %qD that depend on a template "
868 : : "parameter, so a declaration of %qD must be available",
869 : : name, name);
870 : :
871 : 65 : if (!flag_permissive)
872 : : {
873 : 47 : static bool hint;
874 : 47 : if (!hint)
875 : : {
876 : 38 : inform (loc, "(if you use %<-fpermissive%>, G++ will accept your "
877 : : "code, but allowing the use of an undeclared name is "
878 : : "deprecated)");
879 : 38 : hint = true;
880 : : }
881 : : }
882 : 65 : return name;
883 : 65 : }
884 : :
885 : 467 : return unqualified_name_lookup_error (name, loc);
886 : : }
887 : :
888 : :
889 : : /* Hasher for the conversion operator name hash table. */
890 : : struct conv_type_hasher : ggc_ptr_hash<tree_node>
891 : : {
892 : : /* Hash NODE, an identifier node in the table. TYPE_UID is
893 : : suitable, as we're not concerned about matching canonicalness
894 : : here. */
895 : 13134627 : static hashval_t hash (tree node)
896 : : {
897 : 13134627 : return (hashval_t) TYPE_UID (TREE_TYPE (node));
898 : : }
899 : :
900 : : /* Compare NODE, an identifier node in the table, against TYPE, an
901 : : incoming TYPE being looked up. */
902 : 15525517 : static bool equal (tree node, tree type)
903 : : {
904 : 15525517 : return TREE_TYPE (node) == type;
905 : : }
906 : : };
907 : :
908 : : /* This hash table maps TYPEs to the IDENTIFIER for a conversion
909 : : operator to TYPE. The nodes are IDENTIFIERs whose TREE_TYPE is the
910 : : TYPE. */
911 : :
912 : : static GTY (()) hash_table<conv_type_hasher> *conv_type_names;
913 : :
914 : : /* Return an identifier for a conversion operator to TYPE. We can get
915 : : from the returned identifier to the type. We store TYPE, which is
916 : : not necessarily the canonical type, which allows us to report the
917 : : form the user used in error messages. All these identifiers are
918 : : not in the identifier hash table, and have the same string name.
919 : : These IDENTIFIERS are not in the identifier hash table, and all
920 : : have the same IDENTIFIER_STRING. */
921 : :
922 : : tree
923 : 2449150 : make_conv_op_name (tree type)
924 : : {
925 : 2449150 : if (type == error_mark_node)
926 : : return error_mark_node;
927 : :
928 : 2449147 : if (conv_type_names == NULL)
929 : 19618 : conv_type_names = hash_table<conv_type_hasher>::create_ggc (31);
930 : :
931 : 2449147 : tree *slot = conv_type_names->find_slot_with_hash
932 : 2449147 : (type, (hashval_t) TYPE_UID (type), INSERT);
933 : 2449147 : tree identifier = *slot;
934 : 2449147 : if (!identifier)
935 : : {
936 : : /* Create a raw IDENTIFIER outside of the identifier hash
937 : : table. */
938 : 940432 : identifier = copy_node (conv_op_identifier);
939 : :
940 : : /* Just in case something managed to bind. */
941 : 940432 : IDENTIFIER_BINDING (identifier) = NULL;
942 : :
943 : : /* Hang TYPE off the identifier so it can be found easily later
944 : : when performing conversions. */
945 : 940432 : TREE_TYPE (identifier) = type;
946 : :
947 : 940432 : *slot = identifier;
948 : : }
949 : :
950 : : return identifier;
951 : : }
952 : :
953 : : /* Wrapper around build_lang_decl_loc(). Should gradually move to
954 : : build_lang_decl_loc() and then rename build_lang_decl_loc() back to
955 : : build_lang_decl(). */
956 : :
957 : : tree
958 : 255859548 : build_lang_decl (enum tree_code code, tree name, tree type)
959 : : {
960 : 255859548 : return build_lang_decl_loc (input_location, code, name, type);
961 : : }
962 : :
963 : : /* Build a decl from CODE, NAME, TYPE declared at LOC, and then add
964 : : DECL_LANG_SPECIFIC info to the result. */
965 : :
966 : : tree
967 : 470473067 : build_lang_decl_loc (location_t loc, enum tree_code code, tree name, tree type)
968 : : {
969 : 470473067 : tree t;
970 : :
971 : 470473067 : t = build_decl (loc, code, name, type);
972 : 470473067 : retrofit_lang_decl (t);
973 : :
974 : 470473067 : return t;
975 : : }
976 : :
977 : : /* Maybe add a raw lang_decl to T, a decl. Return true if it needed
978 : : one. */
979 : :
980 : : bool
981 : 986661789 : maybe_add_lang_decl_raw (tree t, bool decomp_p)
982 : : {
983 : 986661789 : size_t size;
984 : 986661789 : lang_decl_selector sel;
985 : :
986 : 986661789 : if (decomp_p)
987 : : sel = lds_decomp, size = sizeof (struct lang_decl_decomp);
988 : 986395868 : else if (TREE_CODE (t) == FUNCTION_DECL)
989 : : sel = lds_fn, size = sizeof (struct lang_decl_fn);
990 : : else if (TREE_CODE (t) == NAMESPACE_DECL)
991 : : sel = lds_ns, size = sizeof (struct lang_decl_ns);
992 : : else if (TREE_CODE (t) == PARM_DECL)
993 : : sel = lds_parm, size = sizeof (struct lang_decl_parm);
994 : : else if (LANG_DECL_HAS_MIN (t))
995 : : sel = lds_min, size = sizeof (struct lang_decl_min);
996 : : else
997 : : return false;
998 : :
999 : 986661789 : struct lang_decl *ld
1000 : 986661789 : = (struct lang_decl *) ggc_internal_cleared_alloc (size);
1001 : :
1002 : 986661789 : ld->u.base.selector = sel;
1003 : 986661789 : DECL_LANG_SPECIFIC (t) = ld;
1004 : :
1005 : 986661789 : if (sel == lds_ns)
1006 : : /* Who'd create a namespace, only to put nothing in it? */
1007 : 956657 : ld->u.ns.bindings = hash_table<named_decl_hash>::create_ggc (499);
1008 : :
1009 : : if (GATHER_STATISTICS)
1010 : : {
1011 : : tree_node_counts[(int)lang_decl] += 1;
1012 : : tree_node_sizes[(int)lang_decl] += size;
1013 : : }
1014 : : return true;
1015 : : }
1016 : :
1017 : : /* T has just had a decl_lang_specific added. Initialize its
1018 : : linkage. */
1019 : :
1020 : : static void
1021 : 985102621 : set_decl_linkage (tree t)
1022 : : {
1023 : 985102621 : if (current_lang_name == lang_name_cplusplus
1024 : 985102621 : || decl_linkage (t) == lk_none)
1025 : 732191990 : SET_DECL_LANGUAGE (t, lang_cplusplus);
1026 : 252910631 : else if (current_lang_name == lang_name_c)
1027 : 252910631 : SET_DECL_LANGUAGE (t, lang_c);
1028 : : else
1029 : 0 : gcc_unreachable ();
1030 : 985102621 : }
1031 : :
1032 : : /* T is a VAR_DECL node that needs to be a decomposition of BASE. */
1033 : :
1034 : : void
1035 : 539960 : fit_decomposition_lang_decl (tree t, tree base)
1036 : : {
1037 : 539960 : if (struct lang_decl *orig_ld = DECL_LANG_SPECIFIC (t))
1038 : : {
1039 : 276395 : if (orig_ld->u.base.selector == lds_min)
1040 : : {
1041 : 1053 : maybe_add_lang_decl_raw (t, true);
1042 : 1053 : memcpy (DECL_LANG_SPECIFIC (t), orig_ld,
1043 : : sizeof (struct lang_decl_min));
1044 : : /* Reset selector, which will have been bashed by the
1045 : : memcpy. */
1046 : 1053 : DECL_LANG_SPECIFIC (t)->u.base.selector = lds_decomp;
1047 : : }
1048 : : else
1049 : 275342 : gcc_checking_assert (orig_ld->u.base.selector == lds_decomp);
1050 : : }
1051 : : else
1052 : : {
1053 : 263565 : maybe_add_lang_decl_raw (t, true);
1054 : 263565 : set_decl_linkage (t);
1055 : : }
1056 : :
1057 : 539960 : DECL_DECOMP_BASE (t) = base;
1058 : 539960 : }
1059 : :
1060 : : /* Add DECL_LANG_SPECIFIC info to T, if it needs one. Generally
1061 : : every C++ decl needs one, but C builtins etc do not. */
1062 : :
1063 : : void
1064 : 1201756173 : retrofit_lang_decl (tree t)
1065 : : {
1066 : 1201756173 : if (DECL_LANG_SPECIFIC (t))
1067 : : return;
1068 : :
1069 : 984839056 : if (maybe_add_lang_decl_raw (t, false))
1070 : 984839056 : set_decl_linkage (t);
1071 : : }
1072 : :
1073 : : void
1074 : 736427413 : cxx_dup_lang_specific_decl (tree node)
1075 : : {
1076 : 736427413 : int size;
1077 : :
1078 : 736427413 : if (! DECL_LANG_SPECIFIC (node))
1079 : : return;
1080 : :
1081 : 541887784 : switch (DECL_LANG_SPECIFIC (node)->u.base.selector)
1082 : : {
1083 : : case lds_min:
1084 : : size = sizeof (struct lang_decl_min);
1085 : : break;
1086 : : case lds_fn:
1087 : : size = sizeof (struct lang_decl_fn);
1088 : : break;
1089 : : case lds_ns:
1090 : : size = sizeof (struct lang_decl_ns);
1091 : : break;
1092 : : case lds_parm:
1093 : : size = sizeof (struct lang_decl_parm);
1094 : : break;
1095 : : case lds_decomp:
1096 : : size = sizeof (struct lang_decl_decomp);
1097 : : break;
1098 : 0 : default:
1099 : 0 : gcc_unreachable ();
1100 : : }
1101 : :
1102 : 541887784 : struct lang_decl *ld = (struct lang_decl *) ggc_internal_alloc (size);
1103 : 541887784 : memcpy (ld, DECL_LANG_SPECIFIC (node), size);
1104 : 541887784 : DECL_LANG_SPECIFIC (node) = ld;
1105 : :
1106 : : /* Directly clear some flags that do not apply to the copy
1107 : : (module_purview_p still does). */
1108 : 541887784 : ld->u.base.module_entity_p = false;
1109 : 541887784 : ld->u.base.module_import_p = false;
1110 : 541887784 : ld->u.base.module_keyed_decls_p = false;
1111 : :
1112 : 541887784 : if (GATHER_STATISTICS)
1113 : : {
1114 : : tree_node_counts[(int)lang_decl] += 1;
1115 : : tree_node_sizes[(int)lang_decl] += size;
1116 : : }
1117 : : }
1118 : :
1119 : : /* Copy DECL, including any language-specific parts. */
1120 : :
1121 : : tree
1122 : 433255711 : copy_decl (tree decl MEM_STAT_DECL)
1123 : : {
1124 : 433255711 : tree copy;
1125 : :
1126 : 433255711 : copy = copy_node (decl PASS_MEM_STAT);
1127 : 433255711 : cxx_dup_lang_specific_decl (copy);
1128 : 433255711 : return copy;
1129 : : }
1130 : :
1131 : : /* Replace the shared language-specific parts of NODE with a new copy. */
1132 : :
1133 : : static void
1134 : 12896190 : copy_lang_type (tree node)
1135 : : {
1136 : 12896190 : if (! TYPE_LANG_SPECIFIC (node))
1137 : : return;
1138 : :
1139 : 0 : size_t sz = (c_dialect_objc () ? sizeof (struct lang_type)
1140 : : : offsetof (struct lang_type, info));
1141 : 0 : auto *lt = (struct lang_type *) ggc_internal_alloc (sz);
1142 : :
1143 : 0 : memcpy (lt, TYPE_LANG_SPECIFIC (node), sz);
1144 : 0 : TYPE_LANG_SPECIFIC (node) = lt;
1145 : :
1146 : 0 : if (GATHER_STATISTICS)
1147 : : {
1148 : : tree_node_counts[(int)lang_type] += 1;
1149 : : tree_node_sizes[(int)lang_type] += sz;
1150 : : }
1151 : : }
1152 : :
1153 : : /* Copy TYPE, including any language-specific parts. */
1154 : :
1155 : : tree
1156 : 12896190 : copy_type (tree type MEM_STAT_DECL)
1157 : : {
1158 : 12896190 : tree copy;
1159 : :
1160 : 12896190 : copy = copy_node (type PASS_MEM_STAT);
1161 : 12896190 : copy_lang_type (copy);
1162 : 12896190 : return copy;
1163 : : }
1164 : :
1165 : : /* Add a raw lang_type to T, a type, should it need one. */
1166 : :
1167 : : bool
1168 : 703520785 : maybe_add_lang_type_raw (tree t)
1169 : : {
1170 : 703520785 : if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t)))
1171 : : return false;
1172 : :
1173 : 114446061 : size_t sz = (c_dialect_objc () ? sizeof (struct lang_type)
1174 : : : offsetof (struct lang_type, info));
1175 : 114446061 : auto *lt = (struct lang_type *) (ggc_internal_cleared_alloc (sz));
1176 : 114446061 : TYPE_LANG_SPECIFIC (t) = lt;
1177 : :
1178 : 114446061 : if (GATHER_STATISTICS)
1179 : : {
1180 : : tree_node_counts[(int)lang_type] += 1;
1181 : : tree_node_sizes[(int)lang_type] += sz;
1182 : : }
1183 : :
1184 : 114446061 : return true;
1185 : : }
1186 : :
1187 : : tree
1188 : 703408410 : cxx_make_type (enum tree_code code MEM_STAT_DECL)
1189 : : {
1190 : 703408410 : tree t = make_node (code PASS_MEM_STAT);
1191 : :
1192 : 703408410 : if (maybe_add_lang_type_raw (t))
1193 : : {
1194 : : /* Set up some flags that give proper default behavior. */
1195 : 114333686 : struct c_fileinfo *finfo
1196 : 114333686 : = get_fileinfo (LOCATION_FILE (input_location));
1197 : 114333686 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
1198 : 114333686 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
1199 : : }
1200 : :
1201 : 703408410 : if (code == RECORD_TYPE || code == UNION_TYPE)
1202 : 114333686 : TYPE_CXX_ODR_P (t) = 1;
1203 : :
1204 : 703408410 : return t;
1205 : : }
1206 : :
1207 : : /* A wrapper without the memory stats for LANG_HOOKS_MAKE_TYPE. */
1208 : :
1209 : : tree
1210 : 127431 : cxx_make_type_hook (enum tree_code code)
1211 : : {
1212 : 127431 : return cxx_make_type (code);
1213 : : }
1214 : :
1215 : : tree
1216 : 114206237 : make_class_type (enum tree_code code MEM_STAT_DECL)
1217 : : {
1218 : 114206237 : tree t = cxx_make_type (code PASS_MEM_STAT);
1219 : 114206237 : SET_CLASS_TYPE_P (t, 1);
1220 : 114206237 : return t;
1221 : : }
1222 : :
1223 : : /* Returns true if we are currently in the main source file, or in a
1224 : : template instantiation started from the main source file. */
1225 : :
1226 : : bool
1227 : 143 : in_main_input_context (void)
1228 : : {
1229 : 143 : struct tinst_level *tl = outermost_tinst_level();
1230 : :
1231 : 143 : if (tl)
1232 : 9 : return filename_cmp (main_input_filename,
1233 : 18 : LOCATION_FILE (tl->locus)) == 0;
1234 : : else
1235 : 134 : return filename_cmp (main_input_filename, LOCATION_FILE (input_location)) == 0;
1236 : : }
1237 : :
1238 : : #include "gt-cp-lex.h"
|