OSDN Git Service

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