LCOV - code coverage report
Current view: top level - gcc/cp - lex.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.1 % 466 434
Test Date: 2025-06-21 16:26:05 Functions: 92.3 % 39 36
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.