OSDN Git Service

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