xref: /dflybsd-src/contrib/gcc-8.0/gcc/cp/lex.c (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Separate lexical analyzer for GNU C++.
2*38fd1498Szrj    Copyright (C) 1987-2018 Free Software Foundation, Inc.
3*38fd1498Szrj    Hacked by Michael Tiemann (tiemann@cygnus.com)
4*38fd1498Szrj 
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj 
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify
8*38fd1498Szrj it under the terms of the GNU General Public License as published by
9*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option)
10*38fd1498Szrj any later version.
11*38fd1498Szrj 
12*38fd1498Szrj GCC is distributed in the hope that it will be useful,
13*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
14*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*38fd1498Szrj GNU General Public License for more details.
16*38fd1498Szrj 
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
20*38fd1498Szrj 
21*38fd1498Szrj 
22*38fd1498Szrj /* This file is the lexical analyzer for GNU C++.  */
23*38fd1498Szrj 
24*38fd1498Szrj #include "config.h"
25*38fd1498Szrj #include "system.h"
26*38fd1498Szrj #include "coretypes.h"
27*38fd1498Szrj #include "cp-tree.h"
28*38fd1498Szrj #include "stringpool.h"
29*38fd1498Szrj #include "c-family/c-pragma.h"
30*38fd1498Szrj #include "c-family/c-objc.h"
31*38fd1498Szrj 
32*38fd1498Szrj static int interface_strcmp (const char *);
33*38fd1498Szrj static void init_cp_pragma (void);
34*38fd1498Szrj 
35*38fd1498Szrj static tree parse_strconst_pragma (const char *, int);
36*38fd1498Szrj static void handle_pragma_vtable (cpp_reader *);
37*38fd1498Szrj static void handle_pragma_unit (cpp_reader *);
38*38fd1498Szrj static void handle_pragma_interface (cpp_reader *);
39*38fd1498Szrj static void handle_pragma_implementation (cpp_reader *);
40*38fd1498Szrj 
41*38fd1498Szrj static void init_operators (void);
42*38fd1498Szrj static void copy_lang_type (tree);
43*38fd1498Szrj 
44*38fd1498Szrj /* A constraint that can be tested at compile time.  */
45*38fd1498Szrj #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
46*38fd1498Szrj 
47*38fd1498Szrj /* Functions and data structures for #pragma interface.
48*38fd1498Szrj 
49*38fd1498Szrj    `#pragma implementation' means that the main file being compiled
50*38fd1498Szrj    is considered to implement (provide) the classes that appear in
51*38fd1498Szrj    its main body.  I.e., if this is file "foo.cc", and class `bar'
52*38fd1498Szrj    is defined in "foo.cc", then we say that "foo.cc implements bar".
53*38fd1498Szrj 
54*38fd1498Szrj    All main input files "implement" themselves automagically.
55*38fd1498Szrj 
56*38fd1498Szrj    `#pragma interface' means that unless this file (of the form "foo.h"
57*38fd1498Szrj    is not presently being included by file "foo.cc", the
58*38fd1498Szrj    CLASSTYPE_INTERFACE_ONLY bit gets set.  The effect is that none
59*38fd1498Szrj    of the vtables nor any of the inline functions defined in foo.h
60*38fd1498Szrj    will ever be output.
61*38fd1498Szrj 
62*38fd1498Szrj    There are cases when we want to link files such as "defs.h" and
63*38fd1498Szrj    "main.cc".  In this case, we give "defs.h" a `#pragma interface',
64*38fd1498Szrj    and "main.cc" has `#pragma implementation "defs.h"'.  */
65*38fd1498Szrj 
66*38fd1498Szrj struct impl_files
67*38fd1498Szrj {
68*38fd1498Szrj   const char *filename;
69*38fd1498Szrj   struct impl_files *next;
70*38fd1498Szrj };
71*38fd1498Szrj 
72*38fd1498Szrj static struct impl_files *impl_file_chain;
73*38fd1498Szrj 
74*38fd1498Szrj void
cxx_finish(void)75*38fd1498Szrj cxx_finish (void)
76*38fd1498Szrj {
77*38fd1498Szrj   c_common_finish ();
78*38fd1498Szrj }
79*38fd1498Szrj 
80*38fd1498Szrj ovl_op_info_t ovl_op_info[2][OVL_OP_MAX] =
81*38fd1498Szrj   {
82*38fd1498Szrj     {
83*38fd1498Szrj       {NULL_TREE, NULL, NULL, ERROR_MARK, OVL_OP_ERROR_MARK, 0},
84*38fd1498Szrj       {NULL_TREE, NULL, NULL, NOP_EXPR, OVL_OP_NOP_EXPR, 0},
85*38fd1498Szrj #define DEF_OPERATOR(NAME, CODE, MANGLING, FLAGS) \
86*38fd1498Szrj       {NULL_TREE, NAME, MANGLING, CODE, OVL_OP_##CODE, FLAGS},
87*38fd1498Szrj #define OPERATOR_TRANSITION }, {			\
88*38fd1498Szrj       {NULL_TREE, NULL, NULL, ERROR_MARK, OVL_OP_ERROR_MARK, 0},
89*38fd1498Szrj #include "operators.def"
90*38fd1498Szrj     }
91*38fd1498Szrj   };
92*38fd1498Szrj unsigned char ovl_op_mapping[MAX_TREE_CODES];
93*38fd1498Szrj unsigned char ovl_op_alternate[OVL_OP_MAX];
94*38fd1498Szrj 
95*38fd1498Szrj /* Get the name of the kind of identifier T.  */
96*38fd1498Szrj 
97*38fd1498Szrj const char *
get_identifier_kind_name(tree id)98*38fd1498Szrj get_identifier_kind_name (tree id)
99*38fd1498Szrj {
100*38fd1498Szrj   /* Keep in sync with cp_id_kind enumeration.  */
101*38fd1498Szrj   static const char *const names[cik_max] = {
102*38fd1498Szrj     "normal", "keyword", "constructor", "destructor",
103*38fd1498Szrj     "simple-op", "assign-op", "conv-op", "<reserved>udlit-op"
104*38fd1498Szrj   };
105*38fd1498Szrj 
106*38fd1498Szrj   unsigned kind = 0;
107*38fd1498Szrj   kind |= IDENTIFIER_KIND_BIT_2 (id) << 2;
108*38fd1498Szrj   kind |= IDENTIFIER_KIND_BIT_1 (id) << 1;
109*38fd1498Szrj   kind |= IDENTIFIER_KIND_BIT_0 (id) << 0;
110*38fd1498Szrj 
111*38fd1498Szrj   return names[kind];
112*38fd1498Szrj }
113*38fd1498Szrj 
114*38fd1498Szrj /* Set the identifier kind, which we expect to currently be zero.  */
115*38fd1498Szrj 
116*38fd1498Szrj void
set_identifier_kind(tree id,cp_identifier_kind kind)117*38fd1498Szrj set_identifier_kind (tree id, cp_identifier_kind kind)
118*38fd1498Szrj {
119*38fd1498Szrj   gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
120*38fd1498Szrj 		       & !IDENTIFIER_KIND_BIT_1 (id)
121*38fd1498Szrj 		       & !IDENTIFIER_KIND_BIT_0 (id));
122*38fd1498Szrj   IDENTIFIER_KIND_BIT_2 (id) |= (kind >> 2) & 1;
123*38fd1498Szrj   IDENTIFIER_KIND_BIT_1 (id) |= (kind >> 1) & 1;
124*38fd1498Szrj   IDENTIFIER_KIND_BIT_0 (id) |= (kind >> 0) & 1;
125*38fd1498Szrj }
126*38fd1498Szrj 
127*38fd1498Szrj /* Create and tag the internal operator name for the overloaded
128*38fd1498Szrj    operator PTR describes.  */
129*38fd1498Szrj 
130*38fd1498Szrj static tree
set_operator_ident(ovl_op_info_t * ptr)131*38fd1498Szrj set_operator_ident (ovl_op_info_t *ptr)
132*38fd1498Szrj {
133*38fd1498Szrj   char buffer[32];
134*38fd1498Szrj   size_t len = snprintf (buffer, sizeof (buffer), "operator%s%s",
135*38fd1498Szrj 			 &" "[ptr->name[0] && ptr->name[0] != '_'
136*38fd1498Szrj 			      && !ISALPHA (ptr->name[0])],
137*38fd1498Szrj 			 ptr->name);
138*38fd1498Szrj   gcc_checking_assert (len < sizeof (buffer));
139*38fd1498Szrj 
140*38fd1498Szrj   tree ident = get_identifier_with_length (buffer, len);
141*38fd1498Szrj   ptr->identifier = ident;
142*38fd1498Szrj 
143*38fd1498Szrj   return ident;
144*38fd1498Szrj }
145*38fd1498Szrj 
146*38fd1498Szrj /* Initialize data structures that keep track of operator names.  */
147*38fd1498Szrj 
148*38fd1498Szrj static void
init_operators(void)149*38fd1498Szrj init_operators (void)
150*38fd1498Szrj {
151*38fd1498Szrj   /* We rely on both these being zero.  */
152*38fd1498Szrj   gcc_checking_assert (!OVL_OP_ERROR_MARK && !ERROR_MARK);
153*38fd1498Szrj 
154*38fd1498Szrj   /* This loop iterates backwards because we need to move the
155*38fd1498Szrj      assignment operators down to their correct slots.  I.e. morally
156*38fd1498Szrj      equivalent to an overlapping memmove where dest > src.  Slot
157*38fd1498Szrj      zero is for error_mark, so hae no operator. */
158*38fd1498Szrj   for (unsigned ix = OVL_OP_MAX; --ix;)
159*38fd1498Szrj     {
160*38fd1498Szrj       ovl_op_info_t *op_ptr = &ovl_op_info[false][ix];
161*38fd1498Szrj 
162*38fd1498Szrj       if (op_ptr->name)
163*38fd1498Szrj 	{
164*38fd1498Szrj 	  /* Make sure it fits in lang_decl_fn::operator_code. */
165*38fd1498Szrj 	  gcc_checking_assert (op_ptr->ovl_op_code < (1 << 6));
166*38fd1498Szrj 	  tree ident = set_operator_ident (op_ptr);
167*38fd1498Szrj 	  if (unsigned index = IDENTIFIER_CP_INDEX (ident))
168*38fd1498Szrj 	    {
169*38fd1498Szrj 	      ovl_op_info_t *bin_ptr = &ovl_op_info[false][index];
170*38fd1498Szrj 
171*38fd1498Szrj 	      /* They should only differ in unary/binary ness.  */
172*38fd1498Szrj 	      gcc_checking_assert ((op_ptr->flags ^ bin_ptr->flags)
173*38fd1498Szrj 				   == OVL_OP_FLAG_AMBIARY);
174*38fd1498Szrj 	      bin_ptr->flags |= op_ptr->flags;
175*38fd1498Szrj 	      ovl_op_alternate[index] = ix;
176*38fd1498Szrj 	    }
177*38fd1498Szrj 	  else
178*38fd1498Szrj 	    {
179*38fd1498Szrj 	      IDENTIFIER_CP_INDEX (ident) = ix;
180*38fd1498Szrj 	      set_identifier_kind (ident, cik_simple_op);
181*38fd1498Szrj 	    }
182*38fd1498Szrj 	}
183*38fd1498Szrj       if (op_ptr->tree_code)
184*38fd1498Szrj 	{
185*38fd1498Szrj 	  gcc_checking_assert (op_ptr->ovl_op_code == ix
186*38fd1498Szrj 			       && !ovl_op_mapping[op_ptr->tree_code]);
187*38fd1498Szrj 	  ovl_op_mapping[op_ptr->tree_code] = op_ptr->ovl_op_code;
188*38fd1498Szrj 	}
189*38fd1498Szrj 
190*38fd1498Szrj       ovl_op_info_t *as_ptr = &ovl_op_info[true][ix];
191*38fd1498Szrj       if (as_ptr->name)
192*38fd1498Szrj 	{
193*38fd1498Szrj 	  /* These will be placed at the start of the array, move to
194*38fd1498Szrj 	     the correct slot and initialize.  */
195*38fd1498Szrj 	  if (as_ptr->ovl_op_code != ix)
196*38fd1498Szrj 	    {
197*38fd1498Szrj 	      ovl_op_info_t *dst_ptr = &ovl_op_info[true][as_ptr->ovl_op_code];
198*38fd1498Szrj 	      gcc_assert (as_ptr->ovl_op_code > ix && !dst_ptr->tree_code);
199*38fd1498Szrj 	      memcpy (dst_ptr, as_ptr, sizeof (*dst_ptr));
200*38fd1498Szrj 	      memset (as_ptr, 0, sizeof (*as_ptr));
201*38fd1498Szrj 	      as_ptr = dst_ptr;
202*38fd1498Szrj 	    }
203*38fd1498Szrj 
204*38fd1498Szrj 	  tree ident = set_operator_ident (as_ptr);
205*38fd1498Szrj 	  gcc_checking_assert (!IDENTIFIER_CP_INDEX (ident));
206*38fd1498Szrj 	  IDENTIFIER_CP_INDEX (ident) = as_ptr->ovl_op_code;
207*38fd1498Szrj 	  set_identifier_kind (ident, cik_assign_op);
208*38fd1498Szrj 
209*38fd1498Szrj 	  gcc_checking_assert (!ovl_op_mapping[as_ptr->tree_code]
210*38fd1498Szrj 			       || (ovl_op_mapping[as_ptr->tree_code]
211*38fd1498Szrj 				   == as_ptr->ovl_op_code));
212*38fd1498Szrj 	  ovl_op_mapping[as_ptr->tree_code] = as_ptr->ovl_op_code;
213*38fd1498Szrj 	}
214*38fd1498Szrj     }
215*38fd1498Szrj }
216*38fd1498Szrj 
217*38fd1498Szrj /* Initialize the reserved words.  */
218*38fd1498Szrj 
219*38fd1498Szrj void
init_reswords(void)220*38fd1498Szrj init_reswords (void)
221*38fd1498Szrj {
222*38fd1498Szrj   unsigned int i;
223*38fd1498Szrj   tree id;
224*38fd1498Szrj   int mask = 0;
225*38fd1498Szrj 
226*38fd1498Szrj   if (cxx_dialect < cxx11)
227*38fd1498Szrj     mask |= D_CXX11;
228*38fd1498Szrj   if (!flag_concepts)
229*38fd1498Szrj     mask |= D_CXX_CONCEPTS;
230*38fd1498Szrj   if (!flag_tm)
231*38fd1498Szrj     mask |= D_TRANSMEM;
232*38fd1498Szrj   if (flag_no_asm)
233*38fd1498Szrj     mask |= D_ASM | D_EXT;
234*38fd1498Szrj   if (flag_no_gnu_keywords)
235*38fd1498Szrj     mask |= D_EXT;
236*38fd1498Szrj 
237*38fd1498Szrj   /* The Objective-C keywords are all context-dependent.  */
238*38fd1498Szrj   mask |= D_OBJC;
239*38fd1498Szrj 
240*38fd1498Szrj   ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX);
241*38fd1498Szrj   for (i = 0; i < num_c_common_reswords; i++)
242*38fd1498Szrj     {
243*38fd1498Szrj       if (c_common_reswords[i].disable & D_CONLY)
244*38fd1498Szrj 	continue;
245*38fd1498Szrj       id = get_identifier (c_common_reswords[i].word);
246*38fd1498Szrj       C_SET_RID_CODE (id, c_common_reswords[i].rid);
247*38fd1498Szrj       ridpointers [(int) c_common_reswords[i].rid] = id;
248*38fd1498Szrj       if (! (c_common_reswords[i].disable & mask))
249*38fd1498Szrj 	set_identifier_kind (id, cik_keyword);
250*38fd1498Szrj     }
251*38fd1498Szrj 
252*38fd1498Szrj   for (i = 0; i < NUM_INT_N_ENTS; i++)
253*38fd1498Szrj     {
254*38fd1498Szrj       char name[50];
255*38fd1498Szrj       sprintf (name, "__int%d", int_n_data[i].bitsize);
256*38fd1498Szrj       id = get_identifier (name);
257*38fd1498Szrj       C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
258*38fd1498Szrj       set_identifier_kind (id, cik_keyword);
259*38fd1498Szrj     }
260*38fd1498Szrj }
261*38fd1498Szrj 
262*38fd1498Szrj static void
init_cp_pragma(void)263*38fd1498Szrj init_cp_pragma (void)
264*38fd1498Szrj {
265*38fd1498Szrj   c_register_pragma (0, "vtable", handle_pragma_vtable);
266*38fd1498Szrj   c_register_pragma (0, "unit", handle_pragma_unit);
267*38fd1498Szrj   c_register_pragma (0, "interface", handle_pragma_interface);
268*38fd1498Szrj   c_register_pragma (0, "implementation", handle_pragma_implementation);
269*38fd1498Szrj   c_register_pragma ("GCC", "interface", handle_pragma_interface);
270*38fd1498Szrj   c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
271*38fd1498Szrj }
272*38fd1498Szrj 
273*38fd1498Szrj /* TRUE if a code represents a statement.  */
274*38fd1498Szrj 
275*38fd1498Szrj bool statement_code_p[MAX_TREE_CODES];
276*38fd1498Szrj 
277*38fd1498Szrj /* Initialize the C++ front end.  This function is very sensitive to
278*38fd1498Szrj    the exact order that things are done here.  It would be nice if the
279*38fd1498Szrj    initialization done by this routine were moved to its subroutines,
280*38fd1498Szrj    and the ordering dependencies clarified and reduced.  */
281*38fd1498Szrj bool
cxx_init(void)282*38fd1498Szrj cxx_init (void)
283*38fd1498Szrj {
284*38fd1498Szrj   location_t saved_loc;
285*38fd1498Szrj   unsigned int i;
286*38fd1498Szrj   static const enum tree_code stmt_codes[] = {
287*38fd1498Szrj    CTOR_INITIALIZER,	TRY_BLOCK,	HANDLER,
288*38fd1498Szrj    EH_SPEC_BLOCK,	USING_STMT,	TAG_DEFN,
289*38fd1498Szrj    IF_STMT,		CLEANUP_STMT,	FOR_STMT,
290*38fd1498Szrj    RANGE_FOR_STMT,	WHILE_STMT,	DO_STMT,
291*38fd1498Szrj    BREAK_STMT,		CONTINUE_STMT,	SWITCH_STMT,
292*38fd1498Szrj    EXPR_STMT
293*38fd1498Szrj   };
294*38fd1498Szrj 
295*38fd1498Szrj   memset (&statement_code_p, 0, sizeof (statement_code_p));
296*38fd1498Szrj   for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
297*38fd1498Szrj     statement_code_p[stmt_codes[i]] = true;
298*38fd1498Szrj 
299*38fd1498Szrj   saved_loc = input_location;
300*38fd1498Szrj   input_location = BUILTINS_LOCATION;
301*38fd1498Szrj 
302*38fd1498Szrj   init_reswords ();
303*38fd1498Szrj   init_tree ();
304*38fd1498Szrj   init_cp_semantics ();
305*38fd1498Szrj   init_operators ();
306*38fd1498Szrj   init_method ();
307*38fd1498Szrj 
308*38fd1498Szrj   current_function_decl = NULL;
309*38fd1498Szrj 
310*38fd1498Szrj   class_type_node = ridpointers[(int) RID_CLASS];
311*38fd1498Szrj 
312*38fd1498Szrj   cxx_init_decl_processing ();
313*38fd1498Szrj 
314*38fd1498Szrj   if (c_common_init () == false)
315*38fd1498Szrj     {
316*38fd1498Szrj       input_location = saved_loc;
317*38fd1498Szrj       return false;
318*38fd1498Szrj     }
319*38fd1498Szrj 
320*38fd1498Szrj   init_cp_pragma ();
321*38fd1498Szrj 
322*38fd1498Szrj   init_repo ();
323*38fd1498Szrj 
324*38fd1498Szrj   input_location = saved_loc;
325*38fd1498Szrj   return true;
326*38fd1498Szrj }
327*38fd1498Szrj 
328*38fd1498Szrj /* Return nonzero if S is not considered part of an
329*38fd1498Szrj    INTERFACE/IMPLEMENTATION pair.  Otherwise, return 0.  */
330*38fd1498Szrj 
331*38fd1498Szrj static int
interface_strcmp(const char * s)332*38fd1498Szrj interface_strcmp (const char* s)
333*38fd1498Szrj {
334*38fd1498Szrj   /* Set the interface/implementation bits for this scope.  */
335*38fd1498Szrj   struct impl_files *ifiles;
336*38fd1498Szrj   const char *s1;
337*38fd1498Szrj 
338*38fd1498Szrj   for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
339*38fd1498Szrj     {
340*38fd1498Szrj       const char *t1 = ifiles->filename;
341*38fd1498Szrj       s1 = s;
342*38fd1498Szrj 
343*38fd1498Szrj       if (*s1 == 0 || filename_ncmp (s1, t1, 1) != 0)
344*38fd1498Szrj 	continue;
345*38fd1498Szrj 
346*38fd1498Szrj       while (*s1 != 0 && filename_ncmp (s1, t1, 1) == 0)
347*38fd1498Szrj 	s1++, t1++;
348*38fd1498Szrj 
349*38fd1498Szrj       /* A match.  */
350*38fd1498Szrj       if (*s1 == *t1)
351*38fd1498Szrj 	return 0;
352*38fd1498Szrj 
353*38fd1498Szrj       /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc.  */
354*38fd1498Szrj       if (strchr (s1, '.') || strchr (t1, '.'))
355*38fd1498Szrj 	continue;
356*38fd1498Szrj 
357*38fd1498Szrj       if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
358*38fd1498Szrj 	continue;
359*38fd1498Szrj 
360*38fd1498Szrj       /* A match.  */
361*38fd1498Szrj       return 0;
362*38fd1498Szrj     }
363*38fd1498Szrj 
364*38fd1498Szrj   /* No matches.  */
365*38fd1498Szrj   return 1;
366*38fd1498Szrj }
367*38fd1498Szrj 
368*38fd1498Szrj 
369*38fd1498Szrj 
370*38fd1498Szrj /* Parse a #pragma whose sole argument is a string constant.
371*38fd1498Szrj    If OPT is true, the argument is optional.  */
372*38fd1498Szrj static tree
parse_strconst_pragma(const char * name,int opt)373*38fd1498Szrj parse_strconst_pragma (const char* name, int opt)
374*38fd1498Szrj {
375*38fd1498Szrj   tree result, x;
376*38fd1498Szrj   enum cpp_ttype t;
377*38fd1498Szrj 
378*38fd1498Szrj   t = pragma_lex (&result);
379*38fd1498Szrj   if (t == CPP_STRING)
380*38fd1498Szrj     {
381*38fd1498Szrj       if (pragma_lex (&x) != CPP_EOF)
382*38fd1498Szrj 	warning (0, "junk at end of #pragma %s", name);
383*38fd1498Szrj       return result;
384*38fd1498Szrj     }
385*38fd1498Szrj 
386*38fd1498Szrj   if (t == CPP_EOF && opt)
387*38fd1498Szrj     return NULL_TREE;
388*38fd1498Szrj 
389*38fd1498Szrj   error ("invalid #pragma %s", name);
390*38fd1498Szrj   return error_mark_node;
391*38fd1498Szrj }
392*38fd1498Szrj 
393*38fd1498Szrj static void
handle_pragma_vtable(cpp_reader *)394*38fd1498Szrj handle_pragma_vtable (cpp_reader* /*dfile*/)
395*38fd1498Szrj {
396*38fd1498Szrj   parse_strconst_pragma ("vtable", 0);
397*38fd1498Szrj   sorry ("#pragma vtable no longer supported");
398*38fd1498Szrj }
399*38fd1498Szrj 
400*38fd1498Szrj static void
handle_pragma_unit(cpp_reader *)401*38fd1498Szrj handle_pragma_unit (cpp_reader* /*dfile*/)
402*38fd1498Szrj {
403*38fd1498Szrj   /* Validate syntax, but don't do anything.  */
404*38fd1498Szrj   parse_strconst_pragma ("unit", 0);
405*38fd1498Szrj }
406*38fd1498Szrj 
407*38fd1498Szrj static void
handle_pragma_interface(cpp_reader *)408*38fd1498Szrj handle_pragma_interface (cpp_reader* /*dfile*/)
409*38fd1498Szrj {
410*38fd1498Szrj   tree fname = parse_strconst_pragma ("interface", 1);
411*38fd1498Szrj   struct c_fileinfo *finfo;
412*38fd1498Szrj   const char *filename;
413*38fd1498Szrj 
414*38fd1498Szrj   if (fname == error_mark_node)
415*38fd1498Szrj     return;
416*38fd1498Szrj   else if (fname == 0)
417*38fd1498Szrj     filename = lbasename (LOCATION_FILE (input_location));
418*38fd1498Szrj   else
419*38fd1498Szrj     filename = TREE_STRING_POINTER (fname);
420*38fd1498Szrj 
421*38fd1498Szrj   finfo = get_fileinfo (LOCATION_FILE (input_location));
422*38fd1498Szrj 
423*38fd1498Szrj   if (impl_file_chain == 0)
424*38fd1498Szrj     {
425*38fd1498Szrj       /* If this is zero at this point, then we are
426*38fd1498Szrj 	 auto-implementing.  */
427*38fd1498Szrj       if (main_input_filename == 0)
428*38fd1498Szrj 	main_input_filename = LOCATION_FILE (input_location);
429*38fd1498Szrj     }
430*38fd1498Szrj 
431*38fd1498Szrj   finfo->interface_only = interface_strcmp (filename);
432*38fd1498Szrj   /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see
433*38fd1498Szrj      a definition in another file.  */
434*38fd1498Szrj   if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only)
435*38fd1498Szrj     finfo->interface_unknown = 0;
436*38fd1498Szrj }
437*38fd1498Szrj 
438*38fd1498Szrj /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
439*38fd1498Szrj    We used to only allow this at toplevel, but that restriction was buggy
440*38fd1498Szrj    in older compilers and it seems reasonable to allow it in the headers
441*38fd1498Szrj    themselves, too.  It only needs to precede the matching #p interface.
442*38fd1498Szrj 
443*38fd1498Szrj    We don't touch finfo->interface_only or finfo->interface_unknown;
444*38fd1498Szrj    the user must specify a matching #p interface for this to have
445*38fd1498Szrj    any effect.  */
446*38fd1498Szrj 
447*38fd1498Szrj static void
handle_pragma_implementation(cpp_reader *)448*38fd1498Szrj handle_pragma_implementation (cpp_reader* /*dfile*/)
449*38fd1498Szrj {
450*38fd1498Szrj   tree fname = parse_strconst_pragma ("implementation", 1);
451*38fd1498Szrj   const char *filename;
452*38fd1498Szrj   struct impl_files *ifiles = impl_file_chain;
453*38fd1498Szrj 
454*38fd1498Szrj   if (fname == error_mark_node)
455*38fd1498Szrj     return;
456*38fd1498Szrj 
457*38fd1498Szrj   if (fname == 0)
458*38fd1498Szrj     {
459*38fd1498Szrj       if (main_input_filename)
460*38fd1498Szrj 	filename = main_input_filename;
461*38fd1498Szrj       else
462*38fd1498Szrj 	filename = LOCATION_FILE (input_location);
463*38fd1498Szrj       filename = lbasename (filename);
464*38fd1498Szrj     }
465*38fd1498Szrj   else
466*38fd1498Szrj     {
467*38fd1498Szrj       filename = TREE_STRING_POINTER (fname);
468*38fd1498Szrj       if (cpp_included_before (parse_in, filename, input_location))
469*38fd1498Szrj 	warning (0, "#pragma implementation for %qs appears after "
470*38fd1498Szrj 		 "file is included", filename);
471*38fd1498Szrj     }
472*38fd1498Szrj 
473*38fd1498Szrj   for (; ifiles; ifiles = ifiles->next)
474*38fd1498Szrj     {
475*38fd1498Szrj       if (! filename_cmp (ifiles->filename, filename))
476*38fd1498Szrj 	break;
477*38fd1498Szrj     }
478*38fd1498Szrj   if (ifiles == 0)
479*38fd1498Szrj     {
480*38fd1498Szrj       ifiles = XNEW (struct impl_files);
481*38fd1498Szrj       ifiles->filename = xstrdup (filename);
482*38fd1498Szrj       ifiles->next = impl_file_chain;
483*38fd1498Szrj       impl_file_chain = ifiles;
484*38fd1498Szrj     }
485*38fd1498Szrj }
486*38fd1498Szrj 
487*38fd1498Szrj /* Issue an error message indicating that the lookup of NAME (an
488*38fd1498Szrj    IDENTIFIER_NODE) failed.  Returns the ERROR_MARK_NODE.  */
489*38fd1498Szrj 
490*38fd1498Szrj tree
unqualified_name_lookup_error(tree name,location_t loc)491*38fd1498Szrj unqualified_name_lookup_error (tree name, location_t loc)
492*38fd1498Szrj {
493*38fd1498Szrj   if (loc == UNKNOWN_LOCATION)
494*38fd1498Szrj     loc = EXPR_LOC_OR_LOC (name, input_location);
495*38fd1498Szrj 
496*38fd1498Szrj   if (IDENTIFIER_ANY_OP_P (name))
497*38fd1498Szrj     error_at (loc, "%qD not defined", name);
498*38fd1498Szrj   else
499*38fd1498Szrj     {
500*38fd1498Szrj       if (!objc_diagnose_private_ivar (name))
501*38fd1498Szrj 	{
502*38fd1498Szrj 	  error_at (loc, "%qD was not declared in this scope", name);
503*38fd1498Szrj 	  suggest_alternatives_for (loc, name, true);
504*38fd1498Szrj 	}
505*38fd1498Szrj       /* Prevent repeated error messages by creating a VAR_DECL with
506*38fd1498Szrj 	 this NAME in the innermost block scope.  */
507*38fd1498Szrj       if (local_bindings_p ())
508*38fd1498Szrj 	{
509*38fd1498Szrj 	  tree decl = build_decl (loc, VAR_DECL, name, error_mark_node);
510*38fd1498Szrj 	  TREE_USED (decl) = true;
511*38fd1498Szrj 	  pushdecl (decl);
512*38fd1498Szrj 	}
513*38fd1498Szrj     }
514*38fd1498Szrj 
515*38fd1498Szrj   return error_mark_node;
516*38fd1498Szrj }
517*38fd1498Szrj 
518*38fd1498Szrj /* Like unqualified_name_lookup_error, but NAME_EXPR is an unqualified-id
519*38fd1498Szrj    NAME, encapsulated with its location in a CP_EXPR, used as a function.
520*38fd1498Szrj    Returns an appropriate expression for NAME.  */
521*38fd1498Szrj 
522*38fd1498Szrj tree
unqualified_fn_lookup_error(cp_expr name_expr)523*38fd1498Szrj unqualified_fn_lookup_error (cp_expr name_expr)
524*38fd1498Szrj {
525*38fd1498Szrj   tree name = name_expr.get_value ();
526*38fd1498Szrj   location_t loc = name_expr.get_location ();
527*38fd1498Szrj   if (loc == UNKNOWN_LOCATION)
528*38fd1498Szrj     loc = input_location;
529*38fd1498Szrj 
530*38fd1498Szrj   if (processing_template_decl)
531*38fd1498Szrj     {
532*38fd1498Szrj       /* In a template, it is invalid to write "f()" or "f(3)" if no
533*38fd1498Szrj 	 declaration of "f" is available.  Historically, G++ and most
534*38fd1498Szrj 	 other compilers accepted that usage since they deferred all name
535*38fd1498Szrj 	 lookup until instantiation time rather than doing unqualified
536*38fd1498Szrj 	 name lookup at template definition time; explain to the user what
537*38fd1498Szrj 	 is going wrong.
538*38fd1498Szrj 
539*38fd1498Szrj 	 Note that we have the exact wording of the following message in
540*38fd1498Szrj 	 the manual (trouble.texi, node "Name lookup"), so they need to
541*38fd1498Szrj 	 be kept in synch.  */
542*38fd1498Szrj       permerror (loc, "there are no arguments to %qD that depend on a template "
543*38fd1498Szrj 		 "parameter, so a declaration of %qD must be available",
544*38fd1498Szrj 		 name, name);
545*38fd1498Szrj 
546*38fd1498Szrj       if (!flag_permissive)
547*38fd1498Szrj 	{
548*38fd1498Szrj 	  static bool hint;
549*38fd1498Szrj 	  if (!hint)
550*38fd1498Szrj 	    {
551*38fd1498Szrj 	      inform (loc, "(if you use %<-fpermissive%>, G++ will accept your "
552*38fd1498Szrj 		     "code, but allowing the use of an undeclared name is "
553*38fd1498Szrj 		     "deprecated)");
554*38fd1498Szrj 	      hint = true;
555*38fd1498Szrj 	    }
556*38fd1498Szrj 	}
557*38fd1498Szrj       return name;
558*38fd1498Szrj     }
559*38fd1498Szrj 
560*38fd1498Szrj   return unqualified_name_lookup_error (name, loc);
561*38fd1498Szrj }
562*38fd1498Szrj 
563*38fd1498Szrj 
564*38fd1498Szrj /* Hasher for the conversion operator name hash table.  */
565*38fd1498Szrj struct conv_type_hasher : ggc_ptr_hash<tree_node>
566*38fd1498Szrj {
567*38fd1498Szrj   /* Hash NODE, an identifier node in the table.  TYPE_UID is
568*38fd1498Szrj      suitable, as we're not concerned about matching canonicalness
569*38fd1498Szrj      here.  */
hashconv_type_hasher570*38fd1498Szrj   static hashval_t hash (tree node)
571*38fd1498Szrj   {
572*38fd1498Szrj     return (hashval_t) TYPE_UID (TREE_TYPE (node));
573*38fd1498Szrj   }
574*38fd1498Szrj 
575*38fd1498Szrj   /* Compare NODE, an identifier node in the table, against TYPE, an
576*38fd1498Szrj      incoming TYPE being looked up.  */
equalconv_type_hasher577*38fd1498Szrj   static bool equal (tree node, tree type)
578*38fd1498Szrj   {
579*38fd1498Szrj     return TREE_TYPE (node) == type;
580*38fd1498Szrj   }
581*38fd1498Szrj };
582*38fd1498Szrj 
583*38fd1498Szrj /* This hash table maps TYPEs to the IDENTIFIER for a conversion
584*38fd1498Szrj    operator to TYPE.  The nodes are IDENTIFIERs whose TREE_TYPE is the
585*38fd1498Szrj    TYPE.  */
586*38fd1498Szrj 
587*38fd1498Szrj static GTY (()) hash_table<conv_type_hasher> *conv_type_names;
588*38fd1498Szrj 
589*38fd1498Szrj /* Return an identifier for a conversion operator to TYPE.  We can get
590*38fd1498Szrj    from the returned identifier to the type.  We store TYPE, which is
591*38fd1498Szrj    not necessarily the canonical type,  which allows us to report the
592*38fd1498Szrj    form the user used in error messages.  All these identifiers are
593*38fd1498Szrj    not in the identifier hash table, and have the same string name.
594*38fd1498Szrj    These IDENTIFIERS are not in the identifier hash table, and all
595*38fd1498Szrj    have the same IDENTIFIER_STRING.  */
596*38fd1498Szrj 
597*38fd1498Szrj tree
make_conv_op_name(tree type)598*38fd1498Szrj make_conv_op_name (tree type)
599*38fd1498Szrj {
600*38fd1498Szrj   if (type == error_mark_node)
601*38fd1498Szrj     return error_mark_node;
602*38fd1498Szrj 
603*38fd1498Szrj   if (conv_type_names == NULL)
604*38fd1498Szrj     conv_type_names = hash_table<conv_type_hasher>::create_ggc (31);
605*38fd1498Szrj 
606*38fd1498Szrj   tree *slot = conv_type_names->find_slot_with_hash
607*38fd1498Szrj     (type, (hashval_t) TYPE_UID (type), INSERT);
608*38fd1498Szrj   tree identifier = *slot;
609*38fd1498Szrj   if (!identifier)
610*38fd1498Szrj     {
611*38fd1498Szrj       /* Create a raw IDENTIFIER outside of the identifier hash
612*38fd1498Szrj 	 table.  */
613*38fd1498Szrj       identifier = copy_node (conv_op_identifier);
614*38fd1498Szrj 
615*38fd1498Szrj       /* Just in case something managed to bind.  */
616*38fd1498Szrj       IDENTIFIER_BINDING (identifier) = NULL;
617*38fd1498Szrj 
618*38fd1498Szrj       /* Hang TYPE off the identifier so it can be found easily later
619*38fd1498Szrj 	 when performing conversions.  */
620*38fd1498Szrj       TREE_TYPE (identifier) = type;
621*38fd1498Szrj 
622*38fd1498Szrj       *slot = identifier;
623*38fd1498Szrj     }
624*38fd1498Szrj 
625*38fd1498Szrj   return identifier;
626*38fd1498Szrj }
627*38fd1498Szrj 
628*38fd1498Szrj /* Wrapper around build_lang_decl_loc(). Should gradually move to
629*38fd1498Szrj    build_lang_decl_loc() and then rename build_lang_decl_loc() back to
630*38fd1498Szrj    build_lang_decl().  */
631*38fd1498Szrj 
632*38fd1498Szrj tree
build_lang_decl(enum tree_code code,tree name,tree type)633*38fd1498Szrj build_lang_decl (enum tree_code code, tree name, tree type)
634*38fd1498Szrj {
635*38fd1498Szrj   return build_lang_decl_loc (input_location, code, name, type);
636*38fd1498Szrj }
637*38fd1498Szrj 
638*38fd1498Szrj /* Build a decl from CODE, NAME, TYPE declared at LOC, and then add
639*38fd1498Szrj    DECL_LANG_SPECIFIC info to the result.  */
640*38fd1498Szrj 
641*38fd1498Szrj tree
build_lang_decl_loc(location_t loc,enum tree_code code,tree name,tree type)642*38fd1498Szrj build_lang_decl_loc (location_t loc, enum tree_code code, tree name, tree type)
643*38fd1498Szrj {
644*38fd1498Szrj   tree t;
645*38fd1498Szrj 
646*38fd1498Szrj   t = build_decl (loc, code, name, type);
647*38fd1498Szrj   retrofit_lang_decl (t);
648*38fd1498Szrj 
649*38fd1498Szrj   return t;
650*38fd1498Szrj }
651*38fd1498Szrj 
652*38fd1498Szrj /* Maybe add a raw lang_decl to T, a decl.  Return true if it needed
653*38fd1498Szrj    one.  */
654*38fd1498Szrj 
655*38fd1498Szrj static bool
maybe_add_lang_decl_raw(tree t,bool decomp_p)656*38fd1498Szrj maybe_add_lang_decl_raw (tree t, bool decomp_p)
657*38fd1498Szrj {
658*38fd1498Szrj   size_t size;
659*38fd1498Szrj   lang_decl_selector sel;
660*38fd1498Szrj 
661*38fd1498Szrj   if (decomp_p)
662*38fd1498Szrj     sel = lds_decomp, size = sizeof (struct lang_decl_decomp);
663*38fd1498Szrj   else if (TREE_CODE (t) == FUNCTION_DECL)
664*38fd1498Szrj     sel = lds_fn, size = sizeof (struct lang_decl_fn);
665*38fd1498Szrj   else if (TREE_CODE (t) == NAMESPACE_DECL)
666*38fd1498Szrj     sel = lds_ns, size = sizeof (struct lang_decl_ns);
667*38fd1498Szrj   else if (TREE_CODE (t) == PARM_DECL)
668*38fd1498Szrj     sel = lds_parm, size = sizeof (struct lang_decl_parm);
669*38fd1498Szrj   else if (LANG_DECL_HAS_MIN (t))
670*38fd1498Szrj     sel = lds_min, size = sizeof (struct lang_decl_min);
671*38fd1498Szrj   else
672*38fd1498Szrj     return false;
673*38fd1498Szrj 
674*38fd1498Szrj   struct lang_decl *ld
675*38fd1498Szrj     = (struct lang_decl *) ggc_internal_cleared_alloc (size);
676*38fd1498Szrj 
677*38fd1498Szrj   ld->u.base.selector = sel;
678*38fd1498Szrj   DECL_LANG_SPECIFIC (t) = ld;
679*38fd1498Szrj 
680*38fd1498Szrj   if (sel == lds_ns)
681*38fd1498Szrj     /* Who'd create a namespace, only to put nothing in it?  */
682*38fd1498Szrj     ld->u.ns.bindings = hash_table<named_decl_hash>::create_ggc (499);
683*38fd1498Szrj 
684*38fd1498Szrj   if (GATHER_STATISTICS)
685*38fd1498Szrj     {
686*38fd1498Szrj       tree_node_counts[(int)lang_decl] += 1;
687*38fd1498Szrj       tree_node_sizes[(int)lang_decl] += size;
688*38fd1498Szrj     }
689*38fd1498Szrj   return true;
690*38fd1498Szrj }
691*38fd1498Szrj 
692*38fd1498Szrj /* T has just had a decl_lang_specific added.  Initialize its
693*38fd1498Szrj    linkage.  */
694*38fd1498Szrj 
695*38fd1498Szrj static void
set_decl_linkage(tree t)696*38fd1498Szrj set_decl_linkage (tree t)
697*38fd1498Szrj {
698*38fd1498Szrj   if (current_lang_name == lang_name_cplusplus
699*38fd1498Szrj       || decl_linkage (t) == lk_none)
700*38fd1498Szrj     SET_DECL_LANGUAGE (t, lang_cplusplus);
701*38fd1498Szrj   else if (current_lang_name == lang_name_c)
702*38fd1498Szrj     SET_DECL_LANGUAGE (t, lang_c);
703*38fd1498Szrj   else
704*38fd1498Szrj     gcc_unreachable ();
705*38fd1498Szrj }
706*38fd1498Szrj 
707*38fd1498Szrj /* T is a VAR_DECL node that needs to be a decomposition of BASE.  */
708*38fd1498Szrj 
709*38fd1498Szrj void
fit_decomposition_lang_decl(tree t,tree base)710*38fd1498Szrj fit_decomposition_lang_decl (tree t, tree base)
711*38fd1498Szrj {
712*38fd1498Szrj   if (struct lang_decl *orig_ld = DECL_LANG_SPECIFIC (t))
713*38fd1498Szrj     {
714*38fd1498Szrj       if (orig_ld->u.base.selector == lds_min)
715*38fd1498Szrj 	{
716*38fd1498Szrj 	  maybe_add_lang_decl_raw (t, true);
717*38fd1498Szrj 	  memcpy (DECL_LANG_SPECIFIC (t), orig_ld,
718*38fd1498Szrj 		  sizeof (struct lang_decl_min));
719*38fd1498Szrj 	  /* Reset selector, which will have been bashed by the
720*38fd1498Szrj 	     memcpy.  */
721*38fd1498Szrj 	  DECL_LANG_SPECIFIC (t)->u.base.selector = lds_decomp;
722*38fd1498Szrj 	}
723*38fd1498Szrj       else
724*38fd1498Szrj 	gcc_checking_assert (orig_ld->u.base.selector == lds_decomp);
725*38fd1498Szrj     }
726*38fd1498Szrj   else
727*38fd1498Szrj     {
728*38fd1498Szrj       maybe_add_lang_decl_raw (t, true);
729*38fd1498Szrj       set_decl_linkage (t);
730*38fd1498Szrj     }
731*38fd1498Szrj 
732*38fd1498Szrj   DECL_DECOMP_BASE (t) = base;
733*38fd1498Szrj }
734*38fd1498Szrj 
735*38fd1498Szrj /* Add DECL_LANG_SPECIFIC info to T, if it needs one.  Generally
736*38fd1498Szrj    every C++ decl needs one, but C builtins etc do not.   */
737*38fd1498Szrj 
738*38fd1498Szrj void
retrofit_lang_decl(tree t)739*38fd1498Szrj retrofit_lang_decl (tree t)
740*38fd1498Szrj {
741*38fd1498Szrj   if (DECL_LANG_SPECIFIC (t))
742*38fd1498Szrj     return;
743*38fd1498Szrj 
744*38fd1498Szrj   if (maybe_add_lang_decl_raw (t, false))
745*38fd1498Szrj     set_decl_linkage (t);
746*38fd1498Szrj }
747*38fd1498Szrj 
748*38fd1498Szrj void
cxx_dup_lang_specific_decl(tree node)749*38fd1498Szrj cxx_dup_lang_specific_decl (tree node)
750*38fd1498Szrj {
751*38fd1498Szrj   int size;
752*38fd1498Szrj 
753*38fd1498Szrj   if (! DECL_LANG_SPECIFIC (node))
754*38fd1498Szrj     return;
755*38fd1498Szrj 
756*38fd1498Szrj   switch (DECL_LANG_SPECIFIC (node)->u.base.selector)
757*38fd1498Szrj     {
758*38fd1498Szrj     case lds_min:
759*38fd1498Szrj       size = sizeof (struct lang_decl_min);
760*38fd1498Szrj       break;
761*38fd1498Szrj     case lds_fn:
762*38fd1498Szrj       size = sizeof (struct lang_decl_fn);
763*38fd1498Szrj       break;
764*38fd1498Szrj     case lds_ns:
765*38fd1498Szrj       size = sizeof (struct lang_decl_ns);
766*38fd1498Szrj       break;
767*38fd1498Szrj     case lds_parm:
768*38fd1498Szrj       size = sizeof (struct lang_decl_parm);
769*38fd1498Szrj       break;
770*38fd1498Szrj     case lds_decomp:
771*38fd1498Szrj       size = sizeof (struct lang_decl_decomp);
772*38fd1498Szrj       break;
773*38fd1498Szrj     default:
774*38fd1498Szrj       gcc_unreachable ();
775*38fd1498Szrj     }
776*38fd1498Szrj 
777*38fd1498Szrj   struct lang_decl *ld = (struct lang_decl *) ggc_internal_alloc (size);
778*38fd1498Szrj   memcpy (ld, DECL_LANG_SPECIFIC (node), size);
779*38fd1498Szrj   DECL_LANG_SPECIFIC (node) = ld;
780*38fd1498Szrj 
781*38fd1498Szrj   if (GATHER_STATISTICS)
782*38fd1498Szrj     {
783*38fd1498Szrj       tree_node_counts[(int)lang_decl] += 1;
784*38fd1498Szrj       tree_node_sizes[(int)lang_decl] += size;
785*38fd1498Szrj     }
786*38fd1498Szrj }
787*38fd1498Szrj 
788*38fd1498Szrj /* Copy DECL, including any language-specific parts.  */
789*38fd1498Szrj 
790*38fd1498Szrj tree
copy_decl(tree decl MEM_STAT_DECL)791*38fd1498Szrj copy_decl (tree decl MEM_STAT_DECL)
792*38fd1498Szrj {
793*38fd1498Szrj   tree copy;
794*38fd1498Szrj 
795*38fd1498Szrj   copy = copy_node (decl PASS_MEM_STAT);
796*38fd1498Szrj   cxx_dup_lang_specific_decl (copy);
797*38fd1498Szrj   return copy;
798*38fd1498Szrj }
799*38fd1498Szrj 
800*38fd1498Szrj /* Replace the shared language-specific parts of NODE with a new copy.  */
801*38fd1498Szrj 
802*38fd1498Szrj static void
copy_lang_type(tree node)803*38fd1498Szrj copy_lang_type (tree node)
804*38fd1498Szrj {
805*38fd1498Szrj   if (! TYPE_LANG_SPECIFIC (node))
806*38fd1498Szrj     return;
807*38fd1498Szrj 
808*38fd1498Szrj   struct lang_type *lt
809*38fd1498Szrj     = (struct lang_type *) ggc_internal_alloc (sizeof (struct lang_type));
810*38fd1498Szrj 
811*38fd1498Szrj   memcpy (lt, TYPE_LANG_SPECIFIC (node), (sizeof (struct lang_type)));
812*38fd1498Szrj   TYPE_LANG_SPECIFIC (node) = lt;
813*38fd1498Szrj 
814*38fd1498Szrj   if (GATHER_STATISTICS)
815*38fd1498Szrj     {
816*38fd1498Szrj       tree_node_counts[(int)lang_type] += 1;
817*38fd1498Szrj       tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
818*38fd1498Szrj     }
819*38fd1498Szrj }
820*38fd1498Szrj 
821*38fd1498Szrj /* Copy TYPE, including any language-specific parts.  */
822*38fd1498Szrj 
823*38fd1498Szrj tree
copy_type(tree type MEM_STAT_DECL)824*38fd1498Szrj copy_type (tree type MEM_STAT_DECL)
825*38fd1498Szrj {
826*38fd1498Szrj   tree copy;
827*38fd1498Szrj 
828*38fd1498Szrj   copy = copy_node (type PASS_MEM_STAT);
829*38fd1498Szrj   copy_lang_type (copy);
830*38fd1498Szrj   return copy;
831*38fd1498Szrj }
832*38fd1498Szrj 
833*38fd1498Szrj /* Add a raw lang_type to T, a type, should it need one.  */
834*38fd1498Szrj 
835*38fd1498Szrj static bool
maybe_add_lang_type_raw(tree t)836*38fd1498Szrj maybe_add_lang_type_raw (tree t)
837*38fd1498Szrj {
838*38fd1498Szrj   if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t)))
839*38fd1498Szrj     return false;
840*38fd1498Szrj 
841*38fd1498Szrj   TYPE_LANG_SPECIFIC (t)
842*38fd1498Szrj     = (struct lang_type *) (ggc_internal_cleared_alloc
843*38fd1498Szrj 			    (sizeof (struct lang_type)));
844*38fd1498Szrj 
845*38fd1498Szrj   if (GATHER_STATISTICS)
846*38fd1498Szrj     {
847*38fd1498Szrj       tree_node_counts[(int)lang_type] += 1;
848*38fd1498Szrj       tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
849*38fd1498Szrj     }
850*38fd1498Szrj 
851*38fd1498Szrj   return true;
852*38fd1498Szrj }
853*38fd1498Szrj 
854*38fd1498Szrj tree
cxx_make_type(enum tree_code code)855*38fd1498Szrj cxx_make_type (enum tree_code code)
856*38fd1498Szrj {
857*38fd1498Szrj   tree t = make_node (code);
858*38fd1498Szrj 
859*38fd1498Szrj   if (maybe_add_lang_type_raw (t))
860*38fd1498Szrj     {
861*38fd1498Szrj       /* Set up some flags that give proper default behavior.  */
862*38fd1498Szrj       struct c_fileinfo *finfo =
863*38fd1498Szrj 	get_fileinfo (LOCATION_FILE (input_location));
864*38fd1498Szrj       SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
865*38fd1498Szrj       CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
866*38fd1498Szrj     }
867*38fd1498Szrj 
868*38fd1498Szrj   return t;
869*38fd1498Szrj }
870*38fd1498Szrj 
871*38fd1498Szrj tree
make_class_type(enum tree_code code)872*38fd1498Szrj make_class_type (enum tree_code code)
873*38fd1498Szrj {
874*38fd1498Szrj   tree t = cxx_make_type (code);
875*38fd1498Szrj   SET_CLASS_TYPE_P (t, 1);
876*38fd1498Szrj   return t;
877*38fd1498Szrj }
878*38fd1498Szrj 
879*38fd1498Szrj /* Returns true if we are currently in the main source file, or in a
880*38fd1498Szrj    template instantiation started from the main source file.  */
881*38fd1498Szrj 
882*38fd1498Szrj bool
in_main_input_context(void)883*38fd1498Szrj in_main_input_context (void)
884*38fd1498Szrj {
885*38fd1498Szrj   struct tinst_level *tl = outermost_tinst_level();
886*38fd1498Szrj 
887*38fd1498Szrj   if (tl)
888*38fd1498Szrj     return filename_cmp (main_input_filename,
889*38fd1498Szrj 			 LOCATION_FILE (tl->locus)) == 0;
890*38fd1498Szrj   else
891*38fd1498Szrj     return filename_cmp (main_input_filename, LOCATION_FILE (input_location)) == 0;
892*38fd1498Szrj }
893*38fd1498Szrj 
894*38fd1498Szrj #include "gt-cp-lex.h"
895