OSDN Git Service

* cp-tree.h (cp_id_kind): New type.
[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 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 /* Return something to represent absolute declarators containing a *.
87    TARGET is the absolute declarator that the * contains.
88    CV_QUALIFIERS is a list of modifiers such as const or volatile
89    to apply to the pointer type, represented as identifiers.
90
91    We return an INDIRECT_REF whose "contents" are TARGET
92    and whose type is the modifier list.  */
93
94 tree
95 make_pointer_declarator (tree cv_qualifiers, tree target)
96 {
97   if (target && TREE_CODE (target) == IDENTIFIER_NODE
98       && ANON_AGGRNAME_P (target))
99     error ("type name expected before `*'");
100   target = build_nt (INDIRECT_REF, target);
101   TREE_TYPE (target) = cv_qualifiers;
102   return target;
103 }
104
105 /* Return something to represent absolute declarators containing a &.
106    TARGET is the absolute declarator that the & contains.
107    CV_QUALIFIERS is a list of modifiers such as const or volatile
108    to apply to the reference type, represented as identifiers.
109
110    We return an ADDR_EXPR whose "contents" are TARGET
111    and whose type is the modifier list.  */
112
113 tree
114 make_reference_declarator (tree cv_qualifiers, tree target)
115 {
116   target = build_nt (ADDR_EXPR, target);
117   TREE_TYPE (target) = cv_qualifiers;
118   return target;
119 }
120
121 tree
122 make_call_declarator (tree target, tree parms, tree cv_qualifiers, 
123                       tree exception_specification)
124 {
125   target = build_nt (CALL_EXPR, target,
126                      tree_cons (parms, cv_qualifiers, NULL_TREE),
127                      /* The third operand is really RTL.  We
128                         shouldn't put anything there.  */
129                      NULL_TREE);
130   CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
131   return target;
132 }
133
134 void
135 set_quals_and_spec (tree call_declarator, tree cv_qualifiers, 
136                     tree exception_specification)
137 {
138   CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
139   CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
140 }
141 \f
142 int interface_only;             /* whether or not current file is only for
143                                    interface definitions.  */
144 int interface_unknown;          /* whether or not we know this class
145                                    to behave according to #pragma interface.  */
146
147 \f
148 void
149 cxx_finish (void)
150 {
151   c_common_finish ();
152 }
153
154 /* A mapping from tree codes to operator name information.  */
155 operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
156 /* Similar, but for assignment operators.  */
157 operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
158
159 /* Initialize data structures that keep track of operator names.  */
160
161 #define DEF_OPERATOR(NAME, C, M, AR, AP) \
162  CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256);
163 #include "operators.def"
164 #undef DEF_OPERATOR
165
166 static void
167 init_operators (void)
168 {
169   tree identifier;
170   char buffer[256];
171   struct operator_name_info_t *oni;
172
173 #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P)                   \
174   sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \
175   identifier = get_identifier (buffer);                                     \
176   IDENTIFIER_OPNAME_P (identifier) = 1;                                     \
177                                                                             \
178   oni = (ASSN_P                                                             \
179          ? &assignment_operator_name_info[(int) CODE]                       \
180          : &operator_name_info[(int) CODE]);                                \
181   oni->identifier = identifier;                                             \
182   oni->name = NAME;                                                         \
183   oni->mangled_name = MANGLING;                                             \
184   oni->arity = ARITY;
185
186 #include "operators.def"
187 #undef DEF_OPERATOR
188
189   operator_name_info[(int) ERROR_MARK].identifier
190     = get_identifier ("<invalid operator>");
191
192   /* Handle some special cases.  These operators are not defined in
193      the language, but can be produced internally.  We may need them
194      for error-reporting.  (Eventually, we should ensure that this
195      does not happen.  Error messages involving these operators will
196      be confusing to users.)  */
197
198   operator_name_info [(int) INIT_EXPR].name
199     = operator_name_info [(int) MODIFY_EXPR].name;
200   operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)";
201   operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)";
202   operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)";
203   operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)";
204   operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)";
205   operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
206   operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
207   operator_name_info [(int) ABS_EXPR].name = "abs";
208   operator_name_info [(int) FFS_EXPR].name = "ffs";
209   operator_name_info [(int) BIT_ANDTC_EXPR].name = "&~";
210   operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
211   operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
212   operator_name_info [(int) IN_EXPR].name = "in";
213   operator_name_info [(int) RANGE_EXPR].name = "...";
214   operator_name_info [(int) CONVERT_EXPR].name = "+";
215
216   assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
217     = "(exact /=)";
218   assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
219     = "(ceiling /=)";
220   assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
221     = "(floor /=)";
222   assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
223     = "(round /=)";
224   assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
225     = "(ceiling %=)";
226   assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
227     = "(floor %=)";
228   assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
229     = "(round %=)";
230 }
231
232 /* The reserved keyword table.  */
233 struct resword
234 {
235   const char *const word;
236   const ENUM_BITFIELD(rid) rid : 16;
237   const unsigned int disable   : 16;
238 };
239
240 /* Disable mask.  Keywords are disabled if (reswords[i].disable & mask) is
241    _true_.  */
242 #define D_EXT           0x01    /* GCC extension */
243 #define D_ASM           0x02    /* in C99, but has a switch to turn it off */
244
245 CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
246
247 static const struct resword reswords[] =
248 {
249   { "_Complex",         RID_COMPLEX,    0 },
250   { "__FUNCTION__",     RID_FUNCTION_NAME, 0 },
251   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
252   { "__alignof",        RID_ALIGNOF,    0 },
253   { "__alignof__",      RID_ALIGNOF,    0 },
254   { "__asm",            RID_ASM,        0 },
255   { "__asm__",          RID_ASM,        0 },
256   { "__attribute",      RID_ATTRIBUTE,  0 },
257   { "__attribute__",    RID_ATTRIBUTE,  0 },
258   { "__builtin_va_arg", RID_VA_ARG,     0 },
259   { "__complex",        RID_COMPLEX,    0 },
260   { "__complex__",      RID_COMPLEX,    0 },
261   { "__const",          RID_CONST,      0 },
262   { "__const__",        RID_CONST,      0 },
263   { "__extension__",    RID_EXTENSION,  0 },
264   { "__func__",         RID_C99_FUNCTION_NAME,  0 },
265   { "__imag",           RID_IMAGPART,   0 },
266   { "__imag__",         RID_IMAGPART,   0 },
267   { "__inline",         RID_INLINE,     0 },
268   { "__inline__",       RID_INLINE,     0 },
269   { "__label__",        RID_LABEL,      0 },
270   { "__null",           RID_NULL,       0 },
271   { "__real",           RID_REALPART,   0 },
272   { "__real__",         RID_REALPART,   0 },
273   { "__restrict",       RID_RESTRICT,   0 },
274   { "__restrict__",     RID_RESTRICT,   0 },
275   { "__signed",         RID_SIGNED,     0 },
276   { "__signed__",       RID_SIGNED,     0 },
277   { "__thread",         RID_THREAD,     0 },
278   { "__typeof",         RID_TYPEOF,     0 },
279   { "__typeof__",       RID_TYPEOF,     0 },
280   { "__volatile",       RID_VOLATILE,   0 },
281   { "__volatile__",     RID_VOLATILE,   0 },
282   { "asm",              RID_ASM,        D_ASM },
283   { "auto",             RID_AUTO,       0 },
284   { "bool",             RID_BOOL,       0 },
285   { "break",            RID_BREAK,      0 },
286   { "case",             RID_CASE,       0 },
287   { "catch",            RID_CATCH,      0 },
288   { "char",             RID_CHAR,       0 },
289   { "class",            RID_CLASS,      0 },
290   { "const",            RID_CONST,      0 },
291   { "const_cast",       RID_CONSTCAST,  0 },
292   { "continue",         RID_CONTINUE,   0 },
293   { "default",          RID_DEFAULT,    0 },
294   { "delete",           RID_DELETE,     0 },
295   { "do",               RID_DO,         0 },
296   { "double",           RID_DOUBLE,     0 },
297   { "dynamic_cast",     RID_DYNCAST,    0 },
298   { "else",             RID_ELSE,       0 },
299   { "enum",             RID_ENUM,       0 },
300   { "explicit",         RID_EXPLICIT,   0 },
301   { "export",           RID_EXPORT,     0 },
302   { "extern",           RID_EXTERN,     0 },
303   { "false",            RID_FALSE,      0 },
304   { "float",            RID_FLOAT,      0 },
305   { "for",              RID_FOR,        0 },
306   { "friend",           RID_FRIEND,     0 },
307   { "goto",             RID_GOTO,       0 },
308   { "if",               RID_IF,         0 },
309   { "inline",           RID_INLINE,     0 },
310   { "int",              RID_INT,        0 },
311   { "long",             RID_LONG,       0 },
312   { "mutable",          RID_MUTABLE,    0 },
313   { "namespace",        RID_NAMESPACE,  0 },
314   { "new",              RID_NEW,        0 },
315   { "operator",         RID_OPERATOR,   0 },
316   { "private",          RID_PRIVATE,    0 },
317   { "protected",        RID_PROTECTED,  0 },
318   { "public",           RID_PUBLIC,     0 },
319   { "register",         RID_REGISTER,   0 },
320   { "reinterpret_cast", RID_REINTCAST,  0 },
321   { "return",           RID_RETURN,     0 },
322   { "short",            RID_SHORT,      0 },
323   { "signed",           RID_SIGNED,     0 },
324   { "sizeof",           RID_SIZEOF,     0 },
325   { "static",           RID_STATIC,     0 },
326   { "static_cast",      RID_STATCAST,   0 },
327   { "struct",           RID_STRUCT,     0 },
328   { "switch",           RID_SWITCH,     0 },
329   { "template",         RID_TEMPLATE,   0 },
330   { "this",             RID_THIS,       0 },
331   { "throw",            RID_THROW,      0 },
332   { "true",             RID_TRUE,       0 },
333   { "try",              RID_TRY,        0 },
334   { "typedef",          RID_TYPEDEF,    0 },
335   { "typename",         RID_TYPENAME,   0 },
336   { "typeid",           RID_TYPEID,     0 },
337   { "typeof",           RID_TYPEOF,     D_ASM|D_EXT },
338   { "union",            RID_UNION,      0 },
339   { "unsigned",         RID_UNSIGNED,   0 },
340   { "using",            RID_USING,      0 },
341   { "virtual",          RID_VIRTUAL,    0 },
342   { "void",             RID_VOID,       0 },
343   { "volatile",         RID_VOLATILE,   0 },
344   { "wchar_t",          RID_WCHAR,      0 },
345   { "while",            RID_WHILE,      0 },
346
347 };
348
349 void
350 init_reswords (void)
351 {
352   unsigned int i;
353   tree id;
354   int mask = ((flag_no_asm ? D_ASM : 0)
355               | (flag_no_gnu_keywords ? D_EXT : 0));
356
357   ridpointers = (tree *) ggc_calloc ((int) RID_MAX, sizeof (tree));
358   for (i = 0; i < ARRAY_SIZE (reswords); i++)
359     {
360       id = get_identifier (reswords[i].word);
361       C_RID_CODE (id) = reswords[i].rid;
362       ridpointers [(int) reswords[i].rid] = id;
363       if (! (reswords[i].disable & mask))
364         C_IS_RESERVED_WORD (id) = 1;
365     }
366 }
367
368 static void
369 init_cp_pragma (void)
370 {
371   c_register_pragma (0, "vtable", handle_pragma_vtable);
372   c_register_pragma (0, "unit", handle_pragma_unit);
373   c_register_pragma (0, "interface", handle_pragma_interface);
374   c_register_pragma (0, "implementation", handle_pragma_implementation);
375   c_register_pragma ("GCC", "interface", handle_pragma_interface);
376   c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
377   c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions);
378 }
379 \f
380 /* Initialize the C++ front end.  This function is very sensitive to
381    the exact order that things are done here.  It would be nice if the
382    initialization done by this routine were moved to its subroutines,
383    and the ordering dependencies clarified and reduced.  */
384 bool
385 cxx_init (void)
386 {
387   static const enum tree_code stmt_codes[] = {
388     c_common_stmt_codes,
389     cp_stmt_codes
390   };
391
392   INIT_STATEMENT_CODES (stmt_codes);
393
394   /* We cannot just assign to input_filename because it has already
395      been initialized and will be used later as an N_BINCL for stabs+
396      debugging.  */
397   push_srcloc ("<internal>", 0);
398
399   init_reswords ();
400   init_tree ();
401   init_cp_semantics ();
402   init_operators ();
403   init_method ();
404   init_error ();
405
406   current_function_decl = NULL;
407
408   class_type_node = build_int_2 (class_type, 0);
409   TREE_TYPE (class_type_node) = class_type_node;
410   ridpointers[(int) RID_CLASS] = class_type_node;
411
412   record_type_node = build_int_2 (record_type, 0);
413   TREE_TYPE (record_type_node) = record_type_node;
414   ridpointers[(int) RID_STRUCT] = record_type_node;
415
416   union_type_node = build_int_2 (union_type, 0);
417   TREE_TYPE (union_type_node) = union_type_node;
418   ridpointers[(int) RID_UNION] = union_type_node;
419
420   enum_type_node = build_int_2 (enum_type, 0);
421   TREE_TYPE (enum_type_node) = enum_type_node;
422   ridpointers[(int) RID_ENUM] = enum_type_node;
423
424   cxx_init_decl_processing ();
425
426   /* Create the built-in __null node.  */
427   null_node = build_int_2 (0, 0);
428   TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
429   ridpointers[RID_NULL] = null_node;
430
431   interface_unknown = 1;
432
433   if (c_common_init () == false)
434     {
435       pop_srcloc();
436       return false;
437     }
438
439   init_cp_pragma ();
440
441   init_repo (main_input_filename);
442
443   pop_srcloc();
444   return true;
445 }
446 \f
447 /* Helper function to load global variables with interface
448    information.  */
449
450 void
451 extract_interface_info (void)
452 {
453   struct c_fileinfo *finfo = 0;
454
455   if (flag_alt_external_templates)
456     {
457       tree til = tinst_for_decl ();
458
459       if (til)
460         finfo = get_fileinfo (TINST_FILE (til));
461     }
462   if (!finfo)
463     finfo = get_fileinfo (input_filename);
464
465   interface_only = finfo->interface_only;
466   interface_unknown = finfo->interface_unknown;
467 }
468
469 /* Return nonzero if S is not considered part of an
470    INTERFACE/IMPLEMENTATION pair.  Otherwise, return 0.  */
471
472 static int
473 interface_strcmp (const char* s)
474 {
475   /* Set the interface/implementation bits for this scope.  */
476   struct impl_files *ifiles;
477   const char *s1;
478
479   for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
480     {
481       const char *t1 = ifiles->filename;
482       s1 = s;
483
484       if (*s1 != *t1 || *s1 == 0)
485         continue;
486
487       while (*s1 == *t1 && *s1 != 0)
488         s1++, t1++;
489
490       /* A match.  */
491       if (*s1 == *t1)
492         return 0;
493
494       /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc.  */
495       if (strchr (s1, '.') || strchr (t1, '.'))
496         continue;
497
498       if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
499         continue;
500
501       /* A match.  */
502       return 0;
503     }
504
505   /* No matches.  */
506   return 1;
507 }
508
509 void
510 note_got_semicolon (tree type)
511 {
512   if (!TYPE_P (type))
513     abort ();
514   if (CLASS_TYPE_P (type))
515     CLASSTYPE_GOT_SEMICOLON (type) = 1;
516 }
517
518 void
519 note_list_got_semicolon (tree declspecs)
520 {
521   tree link;
522
523   for (link = declspecs; link; link = TREE_CHAIN (link))
524     {
525       tree type = TREE_VALUE (link);
526       if (type && TYPE_P (type))
527         note_got_semicolon (type);
528     }
529   clear_anon_tags ();
530 }
531 \f
532
533 /* Parse a #pragma whose sole argument is a string constant.
534    If OPT is true, the argument is optional.  */
535 static tree
536 parse_strconst_pragma (const char* name, int opt)
537 {
538   tree result, x;
539   enum cpp_ttype t;
540
541   t = c_lex (&x);
542   if (t == CPP_STRING)
543     {
544       result = x;
545       if (c_lex (&x) != CPP_EOF)
546         warning ("junk at end of #pragma %s", name);
547       return result;
548     }
549
550   if (t == CPP_EOF && opt)
551     return 0;
552
553   error ("invalid #pragma %s", name);
554   return (tree)-1;
555 }
556
557 static void
558 handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED )
559 {
560   parse_strconst_pragma ("vtable", 0);
561   sorry ("#pragma vtable no longer supported");
562 }
563
564 static void
565 handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED )
566 {
567   /* Validate syntax, but don't do anything.  */
568   parse_strconst_pragma ("unit", 0);
569 }
570
571 static void
572 handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
573 {
574   tree fname = parse_strconst_pragma ("interface", 1);
575   struct c_fileinfo *finfo;
576   const char *main_filename;
577
578   if (fname == (tree)-1)
579     return;
580   else if (fname == 0)
581     main_filename = lbasename (input_filename);
582   else
583     main_filename = TREE_STRING_POINTER (fname);
584
585   finfo = get_fileinfo (input_filename);
586
587   if (impl_file_chain == 0)
588     {
589       /* If this is zero at this point, then we are
590          auto-implementing.  */
591       if (main_input_filename == 0)
592         main_input_filename = input_filename;
593     }
594
595   interface_only = interface_strcmp (main_filename);
596 #ifdef MULTIPLE_SYMBOL_SPACES
597   if (! interface_only)
598 #endif
599     interface_unknown = 0;
600
601   finfo->interface_only = interface_only;
602   finfo->interface_unknown = interface_unknown;
603 }
604
605 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
606    We used to only allow this at toplevel, but that restriction was buggy
607    in older compilers and it seems reasonable to allow it in the headers
608    themselves, too.  It only needs to precede the matching #p interface.
609
610    We don't touch interface_only or interface_unknown; the user must specify
611    a matching #p interface for this to have any effect.  */
612
613 static void
614 handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
615 {
616   tree fname = parse_strconst_pragma ("implementation", 1);
617   const char *main_filename;
618   struct impl_files *ifiles = impl_file_chain;
619
620   if (fname == (tree)-1)
621     return;
622
623   if (fname == 0)
624     {
625       if (main_input_filename)
626         main_filename = main_input_filename;
627       else
628         main_filename = input_filename;
629       main_filename = lbasename (main_filename);
630     }
631   else
632     {
633       main_filename = TREE_STRING_POINTER (fname);
634       if (cpp_included (parse_in, main_filename))
635         warning ("#pragma implementation for %s appears after file is included",
636                  main_filename);
637     }
638
639   for (; ifiles; ifiles = ifiles->next)
640     {
641       if (! strcmp (ifiles->filename, main_filename))
642         break;
643     }
644   if (ifiles == 0)
645     {
646       ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files));
647       ifiles->filename = main_filename;
648       ifiles->next = impl_file_chain;
649       impl_file_chain = ifiles;
650     }
651 }
652
653 /* Indicate that this file uses Java-personality exception handling.  */
654 static void
655 handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED )
656 {
657   tree x;
658   if (c_lex (&x) != CPP_EOF)
659     warning ("junk at end of #pragma GCC java_exceptions");
660
661   choose_personality_routine (lang_java);
662 }
663
664 /* Issue an error message indicating that the lookup of NAME (an
665    IDENTIFIER_NODE) failed.  Returns the ERROR_MARK_NODE.  */
666
667 tree
668 unqualified_name_lookup_error (tree name)
669 {
670   if (IDENTIFIER_OPNAME_P (name))
671     {
672       if (name != ansi_opname (ERROR_MARK))
673         error ("`%D' not defined", name);
674     }
675   else if (current_function_decl == 0)
676     error ("`%D' was not declared in this scope", name);
677   else
678     {
679       if (IDENTIFIER_NAMESPACE_VALUE (name) != error_mark_node
680           || IDENTIFIER_ERROR_LOCUS (name) != current_function_decl)
681         {
682           static int undeclared_variable_notice;
683
684           error ("`%D' undeclared (first use this function)", name);
685
686           if (! undeclared_variable_notice)
687             {
688               error ("(Each undeclared identifier is reported only once for each function it appears in.)");
689               undeclared_variable_notice = 1;
690             }
691         }
692       /* Prevent repeated error messages.  */
693       SET_IDENTIFIER_NAMESPACE_VALUE (name, error_mark_node);
694       SET_IDENTIFIER_ERROR_LOCUS (name, current_function_decl);
695     }
696
697   return error_mark_node;
698 }
699
700 /* Like unqualified_name_lookup_error, but NAME is an unqualified-id
701    used as a function.  Returns an appropriate expression for
702    NAME.  */
703
704 tree
705 unqualified_fn_lookup_error (tree name)
706 {
707   if (processing_template_decl)
708     {
709       /* In a template, it is invalid to write "f()" or "f(3)" if no
710          declaration of "f" is available.  Historically, G++ and most
711          other compilers accepted that usage; explain to the user what
712          is going wrong.  */
713       (flag_permissive ? warning : error)
714         ("there are no arguments to `%D' that depend on a template "
715          "parameter, so a declaration of `%D' must be available", name,
716          name);
717       
718       if (!flag_permissive)
719         {
720           static bool hint;
721           if (!hint)
722             {
723               error ("(if you use `-fpermissive', G++ will accept your code, "
724                      "but allowing the use of an undeclared name is "
725                      "deprecated)");
726               hint = true;
727             }
728         }
729       return build_min_nt (LOOKUP_EXPR, name);
730     }
731
732   return unqualified_name_lookup_error (name);
733 }
734
735 #ifdef GATHER_STATISTICS
736 /* The original for tree_node_kind is in the toplevel tree.c; changes there
737    need to be brought into here, unless this were actually put into a header
738    instead.  */
739 /* Statistics-gathering stuff.  */
740 typedef enum
741 {
742   d_kind,
743   t_kind,
744   b_kind,
745   s_kind,
746   r_kind,
747   e_kind,
748   c_kind,
749   id_kind,
750   op_id_kind,
751   perm_list_kind,
752   temp_list_kind,
753   vec_kind,
754   x_kind,
755   lang_decl,
756   lang_type,
757   all_kinds
758 } tree_node_kind;
759
760 extern int tree_node_counts[];
761 extern int tree_node_sizes[];
762 #endif
763
764 tree
765 build_lang_decl (enum tree_code code, tree name, tree type)
766 {
767   tree t;
768
769   t = build_decl (code, name, type);
770   retrofit_lang_decl (t);
771
772   return t;
773 }
774
775 /* Add DECL_LANG_SPECIFIC info to T.  Called from build_lang_decl
776    and pushdecl (for functions generated by the backend).  */
777
778 void
779 retrofit_lang_decl (tree t)
780 {
781   struct lang_decl *ld;
782   size_t size;
783
784   if (CAN_HAVE_FULL_LANG_DECL_P (t))
785     size = sizeof (struct lang_decl);
786   else
787     size = sizeof (struct lang_decl_flags);
788
789   ld = (struct lang_decl *) ggc_alloc_cleared (size);
790
791   ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
792   ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
793   ld->decl_flags.u2sel = 0;
794   if (ld->decl_flags.can_be_full)
795     ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
796
797   DECL_LANG_SPECIFIC (t) = ld;
798   if (current_lang_name == lang_name_cplusplus)
799     SET_DECL_LANGUAGE (t, lang_cplusplus);
800   else if (current_lang_name == lang_name_c)
801     SET_DECL_LANGUAGE (t, lang_c);
802   else if (current_lang_name == lang_name_java)
803     SET_DECL_LANGUAGE (t, lang_java);
804   else abort ();
805
806 #ifdef GATHER_STATISTICS
807   tree_node_counts[(int)lang_decl] += 1;
808   tree_node_sizes[(int)lang_decl] += size;
809 #endif
810 }
811
812 void
813 cxx_dup_lang_specific_decl (tree node)
814 {
815   int size;
816   struct lang_decl *ld;
817
818   if (! DECL_LANG_SPECIFIC (node))
819     return;
820
821   if (!CAN_HAVE_FULL_LANG_DECL_P (node))
822     size = sizeof (struct lang_decl_flags);
823   else
824     size = sizeof (struct lang_decl);
825   ld = (struct lang_decl *) ggc_alloc (size);
826   memcpy (ld, DECL_LANG_SPECIFIC (node), size);
827   DECL_LANG_SPECIFIC (node) = ld;
828
829 #ifdef GATHER_STATISTICS
830   tree_node_counts[(int)lang_decl] += 1;
831   tree_node_sizes[(int)lang_decl] += size;
832 #endif
833 }
834
835 /* Copy DECL, including any language-specific parts.  */
836
837 tree
838 copy_decl (tree decl)
839 {
840   tree copy;
841
842   copy = copy_node (decl);
843   cxx_dup_lang_specific_decl (copy);
844   return copy;
845 }
846
847 /* Replace the shared language-specific parts of NODE with a new copy.  */
848
849 static void
850 copy_lang_type (tree node)
851 {
852   int size;
853   struct lang_type *lt;
854
855   if (! TYPE_LANG_SPECIFIC (node))
856     return;
857
858   if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class)
859     size = sizeof (struct lang_type);
860   else
861     size = sizeof (struct lang_type_ptrmem);
862   lt = (struct lang_type *) ggc_alloc (size);
863   memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
864   TYPE_LANG_SPECIFIC (node) = lt;
865
866 #ifdef GATHER_STATISTICS
867   tree_node_counts[(int)lang_type] += 1;
868   tree_node_sizes[(int)lang_type] += size;
869 #endif
870 }
871
872 /* Copy TYPE, including any language-specific parts.  */
873
874 tree
875 copy_type (tree type)
876 {
877   tree copy;
878
879   copy = copy_node (type);
880   copy_lang_type (copy);
881   return copy;
882 }
883
884 tree
885 cxx_make_type (enum tree_code code)
886 {
887   register tree t = make_node (code);
888
889   /* Create lang_type structure.  */
890   if (IS_AGGR_TYPE_CODE (code)
891       || code == BOUND_TEMPLATE_TEMPLATE_PARM)
892     {
893       struct lang_type *pi;
894
895       pi = ((struct lang_type *)
896             ggc_alloc_cleared (sizeof (struct lang_type)));
897
898       TYPE_LANG_SPECIFIC (t) = pi;
899       pi->u.c.h.is_lang_type_class = 1;
900
901 #ifdef GATHER_STATISTICS
902       tree_node_counts[(int)lang_type] += 1;
903       tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
904 #endif
905     }
906
907   /* Set up some flags that give proper default behavior.  */
908   if (IS_AGGR_TYPE_CODE (code))
909     {
910       SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
911       CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
912
913       /* Make sure this is laid out, for ease of use later.  In the
914          presence of parse errors, the normal was of assuring this
915          might not ever get executed, so we lay it out *immediately*.  */
916       build_pointer_type (t);
917     }
918   else
919     /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits.  But,
920        TYPE_ALIAS_SET is initialized to -1 by default, so we must
921        clear it here.  */
922     TYPE_ALIAS_SET (t) = 0;
923
924   /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
925      since they can be virtual base types, and we then need a
926      canonical binfo for them.  Ideally, this would be done lazily for
927      all types.  */
928   if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM
929       || code == BOUND_TEMPLATE_TEMPLATE_PARM
930       || code == TYPENAME_TYPE)
931     TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
932
933   return t;
934 }
935
936 tree
937 make_aggr_type (enum tree_code code)
938 {
939   tree t = cxx_make_type (code);
940
941   if (IS_AGGR_TYPE_CODE (code))
942     SET_IS_AGGR_TYPE (t, 1);
943
944   return t;
945 }
946
947 /* Return the type-qualifier corresponding to the identifier given by
948    RID.  */
949
950 int
951 cp_type_qual_from_rid (tree rid)
952 {
953   if (rid == ridpointers[(int) RID_CONST])
954     return TYPE_QUAL_CONST;
955   else if (rid == ridpointers[(int) RID_VOLATILE])
956     return TYPE_QUAL_VOLATILE;
957   else if (rid == ridpointers[(int) RID_RESTRICT])
958     return TYPE_QUAL_RESTRICT;
959
960   abort ();
961   return TYPE_UNQUALIFIED;
962 }