OSDN Git Service

* cp-tree.def (NEW_EXPR): Add a fourth slot.
[pf3gnuchains/gcc-fork.git] / gcc / cp / lex.c
1 /* Separate lexical analyzer for GNU C++.
2    Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4    Hacked by Michael Tiemann (tiemann@cygnus.com)
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23
24 /* This file is the lexical analyzer for GNU C++.  */
25
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "tm.h"
30 #include "input.h"
31 #include "tree.h"
32 #include "cp-tree.h"
33 #include "cpplib.h"
34 #include "lex.h"
35 #include "flags.h"
36 #include "c-pragma.h"
37 #include "toplev.h"
38 #include "output.h"
39 #include "tm_p.h"
40 #include "timevar.h"
41
42 static int interface_strcmp (const char *);
43 static void init_cp_pragma (void);
44
45 static tree parse_strconst_pragma (const char *, int);
46 static void handle_pragma_vtable (cpp_reader *);
47 static void handle_pragma_unit (cpp_reader *);
48 static void handle_pragma_interface (cpp_reader *);
49 static void handle_pragma_implementation (cpp_reader *);
50 static void handle_pragma_java_exceptions (cpp_reader *);
51
52 static void init_operators (void);
53 static void copy_lang_type (tree);
54
55 /* A constraint that can be tested at compile time.  */
56 #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
57
58 /* Functions and data structures for #pragma interface.
59
60    `#pragma implementation' means that the main file being compiled
61    is considered to implement (provide) the classes that appear in
62    its main body.  I.e., if this is file "foo.cc", and class `bar'
63    is defined in "foo.cc", then we say that "foo.cc implements bar".
64
65    All main input files "implement" themselves automagically.
66
67    `#pragma interface' means that unless this file (of the form "foo.h"
68    is not presently being included by file "foo.cc", the
69    CLASSTYPE_INTERFACE_ONLY bit gets set.  The effect is that none
70    of the vtables nor any of the inline functions defined in foo.h
71    will ever be output.
72
73    There are cases when we want to link files such as "defs.h" and
74    "main.cc".  In this case, we give "defs.h" a `#pragma interface',
75    and "main.cc" has `#pragma implementation "defs.h"'.  */
76
77 struct impl_files
78 {
79   const char *filename;
80   struct impl_files *next;
81 };
82
83 static struct impl_files *impl_file_chain;
84
85 \f
86 int interface_only;             /* whether or not current file is only for
87                                    interface definitions.  */
88 int interface_unknown;          /* whether or not we know this class
89                                    to behave according to #pragma interface.  */
90
91 \f
92 void
93 cxx_finish (void)
94 {
95   c_common_finish ();
96 }
97
98 /* A mapping from tree codes to operator name information.  */
99 operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
100 /* Similar, but for assignment operators.  */
101 operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
102
103 /* Initialize data structures that keep track of operator names.  */
104
105 #define DEF_OPERATOR(NAME, C, M, AR, AP) \
106  CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256);
107 #include "operators.def"
108 #undef DEF_OPERATOR
109
110 static void
111 init_operators (void)
112 {
113   tree identifier;
114   char buffer[256];
115   struct operator_name_info_t *oni;
116
117 #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P)                   \
118   sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \
119   identifier = get_identifier (buffer);                                     \
120   IDENTIFIER_OPNAME_P (identifier) = 1;                                     \
121                                                                             \
122   oni = (ASSN_P                                                             \
123          ? &assignment_operator_name_info[(int) CODE]                       \
124          : &operator_name_info[(int) CODE]);                                \
125   oni->identifier = identifier;                                             \
126   oni->name = NAME;                                                         \
127   oni->mangled_name = MANGLING;                                             \
128   oni->arity = ARITY;
129
130 #include "operators.def"
131 #undef DEF_OPERATOR
132
133   operator_name_info[(int) ERROR_MARK].identifier
134     = get_identifier ("<invalid operator>");
135
136   /* Handle some special cases.  These operators are not defined in
137      the language, but can be produced internally.  We may need them
138      for error-reporting.  (Eventually, we should ensure that this
139      does not happen.  Error messages involving these operators will
140      be confusing to users.)  */
141
142   operator_name_info [(int) INIT_EXPR].name
143     = operator_name_info [(int) MODIFY_EXPR].name;
144   operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)";
145   operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)";
146   operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)";
147   operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)";
148   operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)";
149   operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
150   operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
151   operator_name_info [(int) ABS_EXPR].name = "abs";
152   operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
153   operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
154   operator_name_info [(int) IN_EXPR].name = "in";
155   operator_name_info [(int) RANGE_EXPR].name = "...";
156   operator_name_info [(int) CONVERT_EXPR].name = "+";
157
158   assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
159     = "(exact /=)";
160   assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
161     = "(ceiling /=)";
162   assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
163     = "(floor /=)";
164   assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
165     = "(round /=)";
166   assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
167     = "(ceiling %=)";
168   assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
169     = "(floor %=)";
170   assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
171     = "(round %=)";
172 }
173
174 /* The reserved keyword table.  */
175 struct resword
176 {
177   const char *const word;
178   ENUM_BITFIELD(rid) const rid : 16;
179   const unsigned int disable   : 16;
180 };
181
182 /* Disable mask.  Keywords are disabled if (reswords[i].disable & mask) is
183    _true_.  */
184 #define D_EXT           0x01    /* GCC extension */
185 #define D_ASM           0x02    /* in C99, but has a switch to turn it off */
186
187 CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
188
189 static const struct resword reswords[] =
190 {
191   { "_Complex",         RID_COMPLEX,    0 },
192   { "__FUNCTION__",     RID_FUNCTION_NAME, 0 },
193   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
194   { "__alignof",        RID_ALIGNOF,    0 },
195   { "__alignof__",      RID_ALIGNOF,    0 },
196   { "__asm",            RID_ASM,        0 },
197   { "__asm__",          RID_ASM,        0 },
198   { "__attribute",      RID_ATTRIBUTE,  0 },
199   { "__attribute__",    RID_ATTRIBUTE,  0 },
200   { "__builtin_offsetof", RID_OFFSETOF, 0 },
201   { "__builtin_va_arg", RID_VA_ARG,     0 },
202   { "__complex",        RID_COMPLEX,    0 },
203   { "__complex__",      RID_COMPLEX,    0 },
204   { "__const",          RID_CONST,      0 },
205   { "__const__",        RID_CONST,      0 },
206   { "__extension__",    RID_EXTENSION,  0 },
207   { "__func__",         RID_C99_FUNCTION_NAME,  0 },
208   { "__imag",           RID_IMAGPART,   0 },
209   { "__imag__",         RID_IMAGPART,   0 },
210   { "__inline",         RID_INLINE,     0 },
211   { "__inline__",       RID_INLINE,     0 },
212   { "__label__",        RID_LABEL,      0 },
213   { "__null",           RID_NULL,       0 },
214   { "__real",           RID_REALPART,   0 },
215   { "__real__",         RID_REALPART,   0 },
216   { "__restrict",       RID_RESTRICT,   0 },
217   { "__restrict__",     RID_RESTRICT,   0 },
218   { "__signed",         RID_SIGNED,     0 },
219   { "__signed__",       RID_SIGNED,     0 },
220   { "__thread",         RID_THREAD,     0 },
221   { "__typeof",         RID_TYPEOF,     0 },
222   { "__typeof__",       RID_TYPEOF,     0 },
223   { "__volatile",       RID_VOLATILE,   0 },
224   { "__volatile__",     RID_VOLATILE,   0 },
225   { "asm",              RID_ASM,        D_ASM },
226   { "auto",             RID_AUTO,       0 },
227   { "bool",             RID_BOOL,       0 },
228   { "break",            RID_BREAK,      0 },
229   { "case",             RID_CASE,       0 },
230   { "catch",            RID_CATCH,      0 },
231   { "char",             RID_CHAR,       0 },
232   { "class",            RID_CLASS,      0 },
233   { "const",            RID_CONST,      0 },
234   { "const_cast",       RID_CONSTCAST,  0 },
235   { "continue",         RID_CONTINUE,   0 },
236   { "default",          RID_DEFAULT,    0 },
237   { "delete",           RID_DELETE,     0 },
238   { "do",               RID_DO,         0 },
239   { "double",           RID_DOUBLE,     0 },
240   { "dynamic_cast",     RID_DYNCAST,    0 },
241   { "else",             RID_ELSE,       0 },
242   { "enum",             RID_ENUM,       0 },
243   { "explicit",         RID_EXPLICIT,   0 },
244   { "export",           RID_EXPORT,     0 },
245   { "extern",           RID_EXTERN,     0 },
246   { "false",            RID_FALSE,      0 },
247   { "float",            RID_FLOAT,      0 },
248   { "for",              RID_FOR,        0 },
249   { "friend",           RID_FRIEND,     0 },
250   { "goto",             RID_GOTO,       0 },
251   { "if",               RID_IF,         0 },
252   { "inline",           RID_INLINE,     0 },
253   { "int",              RID_INT,        0 },
254   { "long",             RID_LONG,       0 },
255   { "mutable",          RID_MUTABLE,    0 },
256   { "namespace",        RID_NAMESPACE,  0 },
257   { "new",              RID_NEW,        0 },
258   { "operator",         RID_OPERATOR,   0 },
259   { "private",          RID_PRIVATE,    0 },
260   { "protected",        RID_PROTECTED,  0 },
261   { "public",           RID_PUBLIC,     0 },
262   { "register",         RID_REGISTER,   0 },
263   { "reinterpret_cast", RID_REINTCAST,  0 },
264   { "return",           RID_RETURN,     0 },
265   { "short",            RID_SHORT,      0 },
266   { "signed",           RID_SIGNED,     0 },
267   { "sizeof",           RID_SIZEOF,     0 },
268   { "static",           RID_STATIC,     0 },
269   { "static_cast",      RID_STATCAST,   0 },
270   { "struct",           RID_STRUCT,     0 },
271   { "switch",           RID_SWITCH,     0 },
272   { "template",         RID_TEMPLATE,   0 },
273   { "this",             RID_THIS,       0 },
274   { "throw",            RID_THROW,      0 },
275   { "true",             RID_TRUE,       0 },
276   { "try",              RID_TRY,        0 },
277   { "typedef",          RID_TYPEDEF,    0 },
278   { "typename",         RID_TYPENAME,   0 },
279   { "typeid",           RID_TYPEID,     0 },
280   { "typeof",           RID_TYPEOF,     D_ASM|D_EXT },
281   { "union",            RID_UNION,      0 },
282   { "unsigned",         RID_UNSIGNED,   0 },
283   { "using",            RID_USING,      0 },
284   { "virtual",          RID_VIRTUAL,    0 },
285   { "void",             RID_VOID,       0 },
286   { "volatile",         RID_VOLATILE,   0 },
287   { "wchar_t",          RID_WCHAR,      0 },
288   { "while",            RID_WHILE,      0 },
289
290 };
291
292 void
293 init_reswords (void)
294 {
295   unsigned int i;
296   tree id;
297   int mask = ((flag_no_asm ? D_ASM : 0)
298               | (flag_no_gnu_keywords ? D_EXT : 0));
299
300   ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree));
301   for (i = 0; i < ARRAY_SIZE (reswords); i++)
302     {
303       id = get_identifier (reswords[i].word);
304       C_RID_CODE (id) = reswords[i].rid;
305       ridpointers [(int) reswords[i].rid] = id;
306       if (! (reswords[i].disable & mask))
307         C_IS_RESERVED_WORD (id) = 1;
308     }
309 }
310
311 static void
312 init_cp_pragma (void)
313 {
314   c_register_pragma (0, "vtable", handle_pragma_vtable);
315   c_register_pragma (0, "unit", handle_pragma_unit);
316   c_register_pragma (0, "interface", handle_pragma_interface);
317   c_register_pragma (0, "implementation", handle_pragma_implementation);
318   c_register_pragma ("GCC", "interface", handle_pragma_interface);
319   c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
320   c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions);
321 }
322 \f
323 /* Initialize the C++ front end.  This function is very sensitive to
324    the exact order that things are done here.  It would be nice if the
325    initialization done by this routine were moved to its subroutines,
326    and the ordering dependencies clarified and reduced.  */
327 bool
328 cxx_init (void)
329 {
330   static const enum tree_code stmt_codes[] = {
331     c_common_stmt_codes,
332     cp_stmt_codes
333   };
334
335   INIT_STATEMENT_CODES (stmt_codes);
336
337   /* We cannot just assign to input_filename because it has already
338      been initialized and will be used later as an N_BINCL for stabs+
339      debugging.  */
340   push_srcloc ("<internal>", 0);
341
342   init_reswords ();
343   init_tree ();
344   init_cp_semantics ();
345   init_operators ();
346   init_method ();
347   init_error ();
348
349   current_function_decl = NULL;
350
351   class_type_node = ridpointers[(int) RID_CLASS];
352
353   cxx_init_decl_processing ();
354
355   /* Create the built-in __null node.  */
356   null_node = build_int_2 (0, 0);
357   TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
358   ridpointers[RID_NULL] = null_node;
359
360   interface_unknown = 1;
361
362   if (c_common_init () == false)
363     {
364       pop_srcloc();
365       return false;
366     }
367
368   init_cp_pragma ();
369
370   init_repo (main_input_filename);
371
372   pop_srcloc();
373   return true;
374 }
375 \f
376 /* Helper function to load global variables with interface
377    information.  */
378
379 void
380 extract_interface_info (void)
381 {
382   struct c_fileinfo *finfo;
383
384   finfo = get_fileinfo (input_filename);
385   interface_only = finfo->interface_only;
386   interface_unknown = finfo->interface_unknown;
387 }
388
389 /* Return nonzero if S is not considered part of an
390    INTERFACE/IMPLEMENTATION pair.  Otherwise, return 0.  */
391
392 static int
393 interface_strcmp (const char* s)
394 {
395   /* Set the interface/implementation bits for this scope.  */
396   struct impl_files *ifiles;
397   const char *s1;
398
399   for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
400     {
401       const char *t1 = ifiles->filename;
402       s1 = s;
403
404       if (*s1 != *t1 || *s1 == 0)
405         continue;
406
407       while (*s1 == *t1 && *s1 != 0)
408         s1++, t1++;
409
410       /* A match.  */
411       if (*s1 == *t1)
412         return 0;
413
414       /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc.  */
415       if (strchr (s1, '.') || strchr (t1, '.'))
416         continue;
417
418       if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
419         continue;
420
421       /* A match.  */
422       return 0;
423     }
424
425   /* No matches.  */
426   return 1;
427 }
428
429 \f
430
431 /* Parse a #pragma whose sole argument is a string constant.
432    If OPT is true, the argument is optional.  */
433 static tree
434 parse_strconst_pragma (const char* name, int opt)
435 {
436   tree result, x;
437   enum cpp_ttype t;
438
439   t = c_lex (&x);
440   if (t == CPP_STRING)
441     {
442       result = x;
443       if (c_lex (&x) != CPP_EOF)
444         warning ("junk at end of #pragma %s", name);
445       return result;
446     }
447
448   if (t == CPP_EOF && opt)
449     return 0;
450
451   error ("invalid #pragma %s", name);
452   return (tree)-1;
453 }
454
455 static void
456 handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED )
457 {
458   parse_strconst_pragma ("vtable", 0);
459   sorry ("#pragma vtable no longer supported");
460 }
461
462 static void
463 handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED )
464 {
465   /* Validate syntax, but don't do anything.  */
466   parse_strconst_pragma ("unit", 0);
467 }
468
469 static void
470 handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
471 {
472   tree fname = parse_strconst_pragma ("interface", 1);
473   struct c_fileinfo *finfo;
474   const char *main_filename;
475
476   if (fname == (tree)-1)
477     return;
478   else if (fname == 0)
479     main_filename = lbasename (input_filename);
480   else
481     main_filename = TREE_STRING_POINTER (fname);
482
483   finfo = get_fileinfo (input_filename);
484
485   if (impl_file_chain == 0)
486     {
487       /* If this is zero at this point, then we are
488          auto-implementing.  */
489       if (main_input_filename == 0)
490         main_input_filename = input_filename;
491     }
492
493   interface_only = interface_strcmp (main_filename);
494 #ifdef MULTIPLE_SYMBOL_SPACES
495   if (! interface_only)
496 #endif
497     interface_unknown = 0;
498
499   finfo->interface_only = interface_only;
500   finfo->interface_unknown = interface_unknown;
501 }
502
503 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
504    We used to only allow this at toplevel, but that restriction was buggy
505    in older compilers and it seems reasonable to allow it in the headers
506    themselves, too.  It only needs to precede the matching #p interface.
507
508    We don't touch interface_only or interface_unknown; the user must specify
509    a matching #p interface for this to have any effect.  */
510
511 static void
512 handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
513 {
514   tree fname = parse_strconst_pragma ("implementation", 1);
515   const char *main_filename;
516   struct impl_files *ifiles = impl_file_chain;
517
518   if (fname == (tree)-1)
519     return;
520
521   if (fname == 0)
522     {
523       if (main_input_filename)
524         main_filename = main_input_filename;
525       else
526         main_filename = input_filename;
527       main_filename = lbasename (main_filename);
528     }
529   else
530     {
531       main_filename = TREE_STRING_POINTER (fname);
532       if (cpp_included (parse_in, main_filename))
533         warning ("#pragma implementation for %s appears after file is included",
534                  main_filename);
535     }
536
537   for (; ifiles; ifiles = ifiles->next)
538     {
539       if (! strcmp (ifiles->filename, main_filename))
540         break;
541     }
542   if (ifiles == 0)
543     {
544       ifiles = xmalloc (sizeof (struct impl_files));
545       ifiles->filename = main_filename;
546       ifiles->next = impl_file_chain;
547       impl_file_chain = ifiles;
548     }
549 }
550
551 /* Indicate that this file uses Java-personality exception handling.  */
552 static void
553 handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED )
554 {
555   tree x;
556   if (c_lex (&x) != CPP_EOF)
557     warning ("junk at end of #pragma GCC java_exceptions");
558
559   choose_personality_routine (lang_java);
560 }
561
562 /* Issue an error message indicating that the lookup of NAME (an
563    IDENTIFIER_NODE) failed.  Returns the ERROR_MARK_NODE.  */
564
565 tree
566 unqualified_name_lookup_error (tree name)
567 {
568   if (IDENTIFIER_OPNAME_P (name))
569     {
570       if (name != ansi_opname (ERROR_MARK))
571         error ("`%D' not defined", name);
572     }
573   else
574     {
575       error ("`%D' was not declared in this scope", name);
576       /* Prevent repeated error messages by creating a VAR_DECL with
577          this NAME in the innermost block scope.  */
578       if (current_function_decl)
579         {
580           tree decl;
581           decl = build_decl (VAR_DECL, name, error_mark_node);
582           DECL_CONTEXT (decl) = current_function_decl;
583           push_local_binding (name, decl, 0);
584         }
585     }
586
587   return error_mark_node;
588 }
589
590 /* Like unqualified_name_lookup_error, but NAME is an unqualified-id
591    used as a function.  Returns an appropriate expression for
592    NAME.  */
593
594 tree
595 unqualified_fn_lookup_error (tree name)
596 {
597   if (processing_template_decl)
598     {
599       /* In a template, it is invalid to write "f()" or "f(3)" if no
600          declaration of "f" is available.  Historically, G++ and most
601          other compilers accepted that usage since they deferred all name
602          lookup until instantiation time rather than doing unqualified
603          name lookup at template definition time; explain to the user what 
604          is going wrong.
605
606          Note that we have the exact wording of the following message in
607          the manual (trouble.texi, node "Name lookup"), so they need to
608          be kept in synch.  */
609       pedwarn ("there are no arguments to `%D' that depend on a template "
610                "parameter, so a declaration of `%D' must be available", 
611                name, name);
612       
613       if (!flag_permissive)
614         {
615           static bool hint;
616           if (!hint)
617             {
618               error ("(if you use `-fpermissive', G++ will accept your code, "
619                      "but allowing the use of an undeclared name is "
620                      "deprecated)");
621               hint = true;
622             }
623         }
624       return name;
625     }
626
627   return unqualified_name_lookup_error (name);
628 }
629
630 tree
631 build_lang_decl (enum tree_code code, tree name, tree type)
632 {
633   tree t;
634
635   t = build_decl (code, name, type);
636   retrofit_lang_decl (t);
637
638   return t;
639 }
640
641 /* Add DECL_LANG_SPECIFIC info to T.  Called from build_lang_decl
642    and pushdecl (for functions generated by the backend).  */
643
644 void
645 retrofit_lang_decl (tree t)
646 {
647   struct lang_decl *ld;
648   size_t size;
649
650   if (CAN_HAVE_FULL_LANG_DECL_P (t))
651     size = sizeof (struct lang_decl);
652   else
653     size = sizeof (struct lang_decl_flags);
654
655   ld = ggc_alloc_cleared (size);
656
657   ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
658   ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
659   ld->decl_flags.u2sel = 0;
660   if (ld->decl_flags.can_be_full)
661     ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
662
663   DECL_LANG_SPECIFIC (t) = ld;
664   if (current_lang_name == lang_name_cplusplus
665       || decl_linkage (t) == lk_none)
666     SET_DECL_LANGUAGE (t, lang_cplusplus);
667   else if (current_lang_name == lang_name_c)
668     SET_DECL_LANGUAGE (t, lang_c);
669   else if (current_lang_name == lang_name_java)
670     SET_DECL_LANGUAGE (t, lang_java);
671   else abort ();
672
673 #ifdef GATHER_STATISTICS
674   tree_node_counts[(int)lang_decl] += 1;
675   tree_node_sizes[(int)lang_decl] += size;
676 #endif
677 }
678
679 void
680 cxx_dup_lang_specific_decl (tree node)
681 {
682   int size;
683   struct lang_decl *ld;
684
685   if (! DECL_LANG_SPECIFIC (node))
686     return;
687
688   if (!CAN_HAVE_FULL_LANG_DECL_P (node))
689     size = sizeof (struct lang_decl_flags);
690   else
691     size = sizeof (struct lang_decl);
692   ld = ggc_alloc (size);
693   memcpy (ld, DECL_LANG_SPECIFIC (node), size);
694   DECL_LANG_SPECIFIC (node) = ld;
695
696 #ifdef GATHER_STATISTICS
697   tree_node_counts[(int)lang_decl] += 1;
698   tree_node_sizes[(int)lang_decl] += size;
699 #endif
700 }
701
702 /* Copy DECL, including any language-specific parts.  */
703
704 tree
705 copy_decl (tree decl)
706 {
707   tree copy;
708
709   copy = copy_node (decl);
710   cxx_dup_lang_specific_decl (copy);
711   return copy;
712 }
713
714 /* Replace the shared language-specific parts of NODE with a new copy.  */
715
716 static void
717 copy_lang_type (tree node)
718 {
719   int size;
720   struct lang_type *lt;
721
722   if (! TYPE_LANG_SPECIFIC (node))
723     return;
724
725   if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class)
726     size = sizeof (struct lang_type);
727   else
728     size = sizeof (struct lang_type_ptrmem);
729   lt = ggc_alloc (size);
730   memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
731   TYPE_LANG_SPECIFIC (node) = lt;
732
733 #ifdef GATHER_STATISTICS
734   tree_node_counts[(int)lang_type] += 1;
735   tree_node_sizes[(int)lang_type] += size;
736 #endif
737 }
738
739 /* Copy TYPE, including any language-specific parts.  */
740
741 tree
742 copy_type (tree type)
743 {
744   tree copy;
745
746   copy = copy_node (type);
747   copy_lang_type (copy);
748   return copy;
749 }
750
751 tree
752 cxx_make_type (enum tree_code code)
753 {
754   tree t = make_node (code);
755
756   /* Create lang_type structure.  */
757   if (IS_AGGR_TYPE_CODE (code)
758       || code == BOUND_TEMPLATE_TEMPLATE_PARM)
759     {
760       struct lang_type *pi;
761
762       pi = ggc_alloc_cleared (sizeof (struct lang_type));
763
764       TYPE_LANG_SPECIFIC (t) = pi;
765       pi->u.c.h.is_lang_type_class = 1;
766
767 #ifdef GATHER_STATISTICS
768       tree_node_counts[(int)lang_type] += 1;
769       tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
770 #endif
771     }
772
773   /* Set up some flags that give proper default behavior.  */
774   if (IS_AGGR_TYPE_CODE (code))
775     {
776       SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
777       CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
778
779       /* Make sure this is laid out, for ease of use later.  In the
780          presence of parse errors, the normal was of assuring this
781          might not ever get executed, so we lay it out *immediately*.  */
782       build_pointer_type (t);
783     }
784   else
785     /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits.  But,
786        TYPE_ALIAS_SET is initialized to -1 by default, so we must
787        clear it here.  */
788     TYPE_ALIAS_SET (t) = 0;
789
790   /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
791      since they can be virtual base types, and we then need a
792      canonical binfo for them.  Ideally, this would be done lazily for
793      all types.  */
794   if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM
795       || code == BOUND_TEMPLATE_TEMPLATE_PARM
796       || code == TYPENAME_TYPE)
797     TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
798
799   return t;
800 }
801
802 tree
803 make_aggr_type (enum tree_code code)
804 {
805   tree t = cxx_make_type (code);
806
807   if (IS_AGGR_TYPE_CODE (code))
808     SET_IS_AGGR_TYPE (t, 1);
809
810   return t;
811 }
812
813 /* Return the type-qualifier corresponding to the identifier given by
814    RID.  */
815
816 int
817 cp_type_qual_from_rid (tree rid)
818 {
819   if (rid == ridpointers[(int) RID_CONST])
820     return TYPE_QUAL_CONST;
821   else if (rid == ridpointers[(int) RID_VOLATILE])
822     return TYPE_QUAL_VOLATILE;
823   else if (rid == ridpointers[(int) RID_RESTRICT])
824     return TYPE_QUAL_RESTRICT;
825
826   abort ();
827   return TYPE_UNQUALIFIED;
828 }