OSDN Git Service

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