1 /* Separate lexical analyzer for GNU C++.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GCC.
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)
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.
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. */
24 /* This file is the lexical analyzer for GNU C++. */
28 #include "coretypes.h"
42 #include "diagnostic.h"
44 #ifdef MULTIBYTE_CHARS
49 static int interface_strcmp PARAMS ((const char *));
50 static void init_cp_pragma PARAMS ((void));
52 static tree parse_strconst_pragma PARAMS ((const char *, int));
53 static void handle_pragma_vtable PARAMS ((cpp_reader *));
54 static void handle_pragma_unit PARAMS ((cpp_reader *));
55 static void handle_pragma_interface PARAMS ((cpp_reader *));
56 static void handle_pragma_implementation PARAMS ((cpp_reader *));
57 static void handle_pragma_java_exceptions PARAMS ((cpp_reader *));
59 static int is_global PARAMS ((tree));
60 static void init_operators PARAMS ((void));
61 static void copy_lang_type PARAMS ((tree));
63 /* A constraint that can be tested at compile time. */
65 #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
67 #define CONSTRAINT(name, expr) extern int constraint_/**/name [(expr) ? 1 : -1]
72 /* Functions and data structures for #pragma interface.
74 `#pragma implementation' means that the main file being compiled
75 is considered to implement (provide) the classes that appear in
76 its main body. I.e., if this is file "foo.cc", and class `bar'
77 is defined in "foo.cc", then we say that "foo.cc implements bar".
79 All main input files "implement" themselves automagically.
81 `#pragma interface' means that unless this file (of the form "foo.h"
82 is not presently being included by file "foo.cc", the
83 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
84 of the vtables nor any of the inline functions defined in foo.h
87 There are cases when we want to link files such as "defs.h" and
88 "main.cc". In this case, we give "defs.h" a `#pragma interface',
89 and "main.cc" has `#pragma implementation "defs.h"'. */
94 struct impl_files *next;
97 static struct impl_files *impl_file_chain;
100 /* Return something to represent absolute declarators containing a *.
101 TARGET is the absolute declarator that the * contains.
102 CV_QUALIFIERS is a list of modifiers such as const or volatile
103 to apply to the pointer type, represented as identifiers.
105 We return an INDIRECT_REF whose "contents" are TARGET
106 and whose type is the modifier list. */
109 make_pointer_declarator (cv_qualifiers, target)
110 tree cv_qualifiers, target;
112 if (target && TREE_CODE (target) == IDENTIFIER_NODE
113 && ANON_AGGRNAME_P (target))
114 error ("type name expected before `*'");
115 target = build_nt (INDIRECT_REF, target);
116 TREE_TYPE (target) = cv_qualifiers;
120 /* Return something to represent absolute declarators containing a &.
121 TARGET is the absolute declarator that the & contains.
122 CV_QUALIFIERS is a list of modifiers such as const or volatile
123 to apply to the reference type, represented as identifiers.
125 We return an ADDR_EXPR whose "contents" are TARGET
126 and whose type is the modifier list. */
129 make_reference_declarator (cv_qualifiers, target)
130 tree cv_qualifiers, target;
132 target = build_nt (ADDR_EXPR, target);
133 TREE_TYPE (target) = cv_qualifiers;
138 make_call_declarator (target, parms, cv_qualifiers, exception_specification)
139 tree target, parms, cv_qualifiers, exception_specification;
141 target = build_nt (CALL_EXPR, target,
142 tree_cons (parms, cv_qualifiers, NULL_TREE),
143 /* The third operand is really RTL. We
144 shouldn't put anything there. */
146 CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
151 set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
152 tree call_declarator, cv_qualifiers, exception_specification;
154 CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
155 CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
158 int interface_only; /* whether or not current file is only for
159 interface definitions. */
160 int interface_unknown; /* whether or not we know this class
161 to behave according to #pragma interface. */
164 /* Initialization before switch parsing. */
168 c_common_init_options (clk_cplusplus);
170 /* Default exceptions on. */
172 /* By default wrap lines at 80 characters. Is getenv ("COLUMNS")
174 diagnostic_line_cutoff (global_dc) = 80;
175 /* By default, emit location information once for every
176 diagnostic message. */
177 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
186 /* A mapping from tree codes to operator name information. */
187 operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
188 /* Similar, but for assignment operators. */
189 operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
191 /* Initialize data structures that keep track of operator names. */
193 #define DEF_OPERATOR(NAME, C, M, AR, AP) \
194 CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256);
195 #include "operators.def"
203 struct operator_name_info_t *oni;
205 #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \
206 sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \
207 identifier = get_identifier (buffer); \
208 IDENTIFIER_OPNAME_P (identifier) = 1; \
211 ? &assignment_operator_name_info[(int) CODE] \
212 : &operator_name_info[(int) CODE]); \
213 oni->identifier = identifier; \
215 oni->mangled_name = MANGLING; \
218 #include "operators.def"
221 operator_name_info[(int) ERROR_MARK].identifier
222 = get_identifier ("<invalid operator>");
224 /* Handle some special cases. These operators are not defined in
225 the language, but can be produced internally. We may need them
226 for error-reporting. (Eventually, we should ensure that this
227 does not happen. Error messages involving these operators will
228 be confusing to users.) */
230 operator_name_info [(int) INIT_EXPR].name
231 = operator_name_info [(int) MODIFY_EXPR].name;
232 operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)";
233 operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)";
234 operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)";
235 operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)";
236 operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)";
237 operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
238 operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
239 operator_name_info [(int) ABS_EXPR].name = "abs";
240 operator_name_info [(int) FFS_EXPR].name = "ffs";
241 operator_name_info [(int) BIT_ANDTC_EXPR].name = "&~";
242 operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
243 operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
244 operator_name_info [(int) IN_EXPR].name = "in";
245 operator_name_info [(int) RANGE_EXPR].name = "...";
246 operator_name_info [(int) CONVERT_EXPR].name = "+";
248 assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
250 assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
252 assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
254 assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
256 assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
258 assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
260 assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
264 /* The reserved keyword table. */
267 const char *const word;
268 const ENUM_BITFIELD(rid) rid : 16;
269 const unsigned int disable : 16;
272 /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
274 #define D_EXT 0x01 /* GCC extension */
275 #define D_ASM 0x02 /* in C99, but has a switch to turn it off */
277 CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
279 static const struct resword reswords[] =
281 { "_Complex", RID_COMPLEX, 0 },
282 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
283 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
284 { "__alignof", RID_ALIGNOF, 0 },
285 { "__alignof__", RID_ALIGNOF, 0 },
286 { "__asm", RID_ASM, 0 },
287 { "__asm__", RID_ASM, 0 },
288 { "__attribute", RID_ATTRIBUTE, 0 },
289 { "__attribute__", RID_ATTRIBUTE, 0 },
290 { "__builtin_va_arg", RID_VA_ARG, 0 },
291 { "__complex", RID_COMPLEX, 0 },
292 { "__complex__", RID_COMPLEX, 0 },
293 { "__const", RID_CONST, 0 },
294 { "__const__", RID_CONST, 0 },
295 { "__extension__", RID_EXTENSION, 0 },
296 { "__func__", RID_C99_FUNCTION_NAME, 0 },
297 { "__imag", RID_IMAGPART, 0 },
298 { "__imag__", RID_IMAGPART, 0 },
299 { "__inline", RID_INLINE, 0 },
300 { "__inline__", RID_INLINE, 0 },
301 { "__label__", RID_LABEL, 0 },
302 { "__null", RID_NULL, 0 },
303 { "__real", RID_REALPART, 0 },
304 { "__real__", RID_REALPART, 0 },
305 { "__restrict", RID_RESTRICT, 0 },
306 { "__restrict__", RID_RESTRICT, 0 },
307 { "__signed", RID_SIGNED, 0 },
308 { "__signed__", RID_SIGNED, 0 },
309 { "__thread", RID_THREAD, 0 },
310 { "__typeof", RID_TYPEOF, 0 },
311 { "__typeof__", RID_TYPEOF, 0 },
312 { "__volatile", RID_VOLATILE, 0 },
313 { "__volatile__", RID_VOLATILE, 0 },
314 { "asm", RID_ASM, D_ASM },
315 { "auto", RID_AUTO, 0 },
316 { "bool", RID_BOOL, 0 },
317 { "break", RID_BREAK, 0 },
318 { "case", RID_CASE, 0 },
319 { "catch", RID_CATCH, 0 },
320 { "char", RID_CHAR, 0 },
321 { "class", RID_CLASS, 0 },
322 { "const", RID_CONST, 0 },
323 { "const_cast", RID_CONSTCAST, 0 },
324 { "continue", RID_CONTINUE, 0 },
325 { "default", RID_DEFAULT, 0 },
326 { "delete", RID_DELETE, 0 },
328 { "double", RID_DOUBLE, 0 },
329 { "dynamic_cast", RID_DYNCAST, 0 },
330 { "else", RID_ELSE, 0 },
331 { "enum", RID_ENUM, 0 },
332 { "explicit", RID_EXPLICIT, 0 },
333 { "export", RID_EXPORT, 0 },
334 { "extern", RID_EXTERN, 0 },
335 { "false", RID_FALSE, 0 },
336 { "float", RID_FLOAT, 0 },
337 { "for", RID_FOR, 0 },
338 { "friend", RID_FRIEND, 0 },
339 { "goto", RID_GOTO, 0 },
341 { "inline", RID_INLINE, 0 },
342 { "int", RID_INT, 0 },
343 { "long", RID_LONG, 0 },
344 { "mutable", RID_MUTABLE, 0 },
345 { "namespace", RID_NAMESPACE, 0 },
346 { "new", RID_NEW, 0 },
347 { "operator", RID_OPERATOR, 0 },
348 { "private", RID_PRIVATE, 0 },
349 { "protected", RID_PROTECTED, 0 },
350 { "public", RID_PUBLIC, 0 },
351 { "register", RID_REGISTER, 0 },
352 { "reinterpret_cast", RID_REINTCAST, 0 },
353 { "return", RID_RETURN, 0 },
354 { "short", RID_SHORT, 0 },
355 { "signed", RID_SIGNED, 0 },
356 { "sizeof", RID_SIZEOF, 0 },
357 { "static", RID_STATIC, 0 },
358 { "static_cast", RID_STATCAST, 0 },
359 { "struct", RID_STRUCT, 0 },
360 { "switch", RID_SWITCH, 0 },
361 { "template", RID_TEMPLATE, 0 },
362 { "this", RID_THIS, 0 },
363 { "throw", RID_THROW, 0 },
364 { "true", RID_TRUE, 0 },
365 { "try", RID_TRY, 0 },
366 { "typedef", RID_TYPEDEF, 0 },
367 { "typename", RID_TYPENAME, 0 },
368 { "typeid", RID_TYPEID, 0 },
369 { "typeof", RID_TYPEOF, D_ASM|D_EXT },
370 { "union", RID_UNION, 0 },
371 { "unsigned", RID_UNSIGNED, 0 },
372 { "using", RID_USING, 0 },
373 { "virtual", RID_VIRTUAL, 0 },
374 { "void", RID_VOID, 0 },
375 { "volatile", RID_VOLATILE, 0 },
376 { "wchar_t", RID_WCHAR, 0 },
377 { "while", RID_WHILE, 0 },
386 int mask = ((flag_no_asm ? D_ASM : 0)
387 | (flag_no_gnu_keywords ? D_EXT : 0));
389 /* It is not necessary to register ridpointers as a GC root, because
390 all the trees it points to are permanently interned in the
391 get_identifier hash anyway. */
392 ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
393 for (i = 0; i < ARRAY_SIZE (reswords); i++)
395 id = get_identifier (reswords[i].word);
396 C_RID_CODE (id) = reswords[i].rid;
397 ridpointers [(int) reswords[i].rid] = id;
398 if (! (reswords[i].disable & mask))
399 C_IS_RESERVED_WORD (id) = 1;
406 cpp_register_pragma (parse_in, 0, "vtable", handle_pragma_vtable);
407 cpp_register_pragma (parse_in, 0, "unit", handle_pragma_unit);
409 cpp_register_pragma (parse_in, 0, "interface", handle_pragma_interface);
410 cpp_register_pragma (parse_in, 0, "implementation",
411 handle_pragma_implementation);
413 cpp_register_pragma (parse_in, "GCC", "interface", handle_pragma_interface);
414 cpp_register_pragma (parse_in, "GCC", "implementation",
415 handle_pragma_implementation);
416 cpp_register_pragma (parse_in, "GCC", "java_exceptions",
417 handle_pragma_java_exceptions);
420 /* Initialize the C++ front end. This function is very sensitive to
421 the exact order that things are done here. It would be nice if the
422 initialization done by this routine were moved to its subroutines,
423 and the ordering dependencies clarified and reduced. */
426 const char *filename;
428 input_filename = "<internal>";
432 init_cp_semantics ();
437 current_function_decl = NULL;
439 class_type_node = build_int_2 (class_type, 0);
440 TREE_TYPE (class_type_node) = class_type_node;
441 ridpointers[(int) RID_CLASS] = class_type_node;
443 record_type_node = build_int_2 (record_type, 0);
444 TREE_TYPE (record_type_node) = record_type_node;
445 ridpointers[(int) RID_STRUCT] = record_type_node;
447 union_type_node = build_int_2 (union_type, 0);
448 TREE_TYPE (union_type_node) = union_type_node;
449 ridpointers[(int) RID_UNION] = union_type_node;
451 enum_type_node = build_int_2 (enum_type, 0);
452 TREE_TYPE (enum_type_node) = enum_type_node;
453 ridpointers[(int) RID_ENUM] = enum_type_node;
455 cxx_init_decl_processing ();
457 /* Create the built-in __null node. */
458 null_node = build_int_2 (0, 0);
459 TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
460 ridpointers[RID_NULL] = null_node;
462 interface_unknown = 1;
464 filename = c_common_init (filename);
465 if (filename == NULL)
470 init_repo (filename);
475 /* Helper function to load global variables with interface
479 extract_interface_info ()
481 struct c_fileinfo *finfo = 0;
483 if (flag_alt_external_templates)
485 tree til = tinst_for_decl ();
488 finfo = get_fileinfo (TINST_FILE (til));
491 finfo = get_fileinfo (input_filename);
493 interface_only = finfo->interface_only;
494 interface_unknown = finfo->interface_unknown;
497 /* Return nonzero if S is not considered part of an
498 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
504 /* Set the interface/implementation bits for this scope. */
505 struct impl_files *ifiles;
508 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
510 const char *t1 = ifiles->filename;
513 if (*s1 != *t1 || *s1 == 0)
516 while (*s1 == *t1 && *s1 != 0)
523 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
524 if (strchr (s1, '.') || strchr (t1, '.'))
527 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
539 note_got_semicolon (type)
544 if (CLASS_TYPE_P (type))
545 CLASSTYPE_GOT_SEMICOLON (type) = 1;
549 note_list_got_semicolon (declspecs)
554 for (link = declspecs; link; link = TREE_CHAIN (link))
556 tree type = TREE_VALUE (link);
557 if (type && TYPE_P (type))
558 note_got_semicolon (type);
564 /* Parse a #pragma whose sole argument is a string constant.
565 If OPT is true, the argument is optional. */
567 parse_strconst_pragma (name, opt)
578 if (c_lex (&x) != CPP_EOF)
579 warning ("junk at end of #pragma %s", name);
583 if (t == CPP_EOF && opt)
586 error ("invalid #pragma %s", name);
591 handle_pragma_vtable (dfile)
592 cpp_reader *dfile ATTRIBUTE_UNUSED;
594 parse_strconst_pragma ("vtable", 0);
595 sorry ("#pragma vtable no longer supported");
599 handle_pragma_unit (dfile)
600 cpp_reader *dfile ATTRIBUTE_UNUSED;
602 /* Validate syntax, but don't do anything. */
603 parse_strconst_pragma ("unit", 0);
607 handle_pragma_interface (dfile)
608 cpp_reader *dfile ATTRIBUTE_UNUSED;
610 tree fname = parse_strconst_pragma ("interface", 1);
611 struct c_fileinfo *finfo;
612 const char *main_filename;
614 if (fname == (tree)-1)
617 main_filename = lbasename (input_filename);
619 main_filename = TREE_STRING_POINTER (fname);
621 finfo = get_fileinfo (input_filename);
623 if (impl_file_chain == 0)
625 /* If this is zero at this point, then we are
626 auto-implementing. */
627 if (main_input_filename == 0)
628 main_input_filename = input_filename;
631 interface_only = interface_strcmp (main_filename);
632 #ifdef MULTIPLE_SYMBOL_SPACES
633 if (! interface_only)
635 interface_unknown = 0;
637 finfo->interface_only = interface_only;
638 finfo->interface_unknown = interface_unknown;
641 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
642 We used to only allow this at toplevel, but that restriction was buggy
643 in older compilers and it seems reasonable to allow it in the headers
644 themselves, too. It only needs to precede the matching #p interface.
646 We don't touch interface_only or interface_unknown; the user must specify
647 a matching #p interface for this to have any effect. */
650 handle_pragma_implementation (dfile)
651 cpp_reader *dfile ATTRIBUTE_UNUSED;
653 tree fname = parse_strconst_pragma ("implementation", 1);
654 const char *main_filename;
655 struct impl_files *ifiles = impl_file_chain;
657 if (fname == (tree)-1)
662 if (main_input_filename)
663 main_filename = main_input_filename;
665 main_filename = input_filename;
666 main_filename = lbasename (main_filename);
670 main_filename = TREE_STRING_POINTER (fname);
671 if (cpp_included (parse_in, main_filename))
672 warning ("#pragma implementation for %s appears after file is included",
676 for (; ifiles; ifiles = ifiles->next)
678 if (! strcmp (ifiles->filename, main_filename))
683 ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files));
684 ifiles->filename = main_filename;
685 ifiles->next = impl_file_chain;
686 impl_file_chain = ifiles;
690 /* Indicate that this file uses Java-personality exception handling. */
692 handle_pragma_java_exceptions (dfile)
693 cpp_reader *dfile ATTRIBUTE_UNUSED;
696 if (c_lex (&x) != CPP_EOF)
697 warning ("junk at end of #pragma GCC java_exceptions");
699 choose_personality_routine (lang_java);
702 /* Return true if d is in a global scope. */
709 switch (TREE_CODE (d))
714 case OVERLOAD: d = OVL_FUNCTION (d); continue;
715 case TREE_LIST: d = TREE_VALUE (d); continue;
717 my_friendly_assert (DECL_P (d), 980629);
719 return DECL_NAMESPACE_SCOPE_P (d);
723 /* Issue an error message indicating that the lookup of NAME (an
724 IDENTIFIER_NODE) failed. */
727 unqualified_name_lookup_error (tree name)
729 if (IDENTIFIER_OPNAME_P (name))
731 if (name != ansi_opname (ERROR_MARK))
732 error ("`%D' not defined", name);
734 else if (current_function_decl == 0)
735 error ("`%D' was not declared in this scope", name);
738 if (IDENTIFIER_NAMESPACE_VALUE (name) != error_mark_node
739 || IDENTIFIER_ERROR_LOCUS (name) != current_function_decl)
741 static int undeclared_variable_notice;
743 error ("`%D' undeclared (first use this function)", name);
745 if (! undeclared_variable_notice)
747 error ("(Each undeclared identifier is reported only once for each function it appears in.)");
748 undeclared_variable_notice = 1;
751 /* Prevent repeated error messages. */
752 SET_IDENTIFIER_NAMESPACE_VALUE (name, error_mark_node);
753 SET_IDENTIFIER_ERROR_LOCUS (name, current_function_decl);
758 do_identifier (token, args)
764 id = lookup_name (token, 0);
766 /* Do Koenig lookup if appropriate (inside templates we build lookup
767 expressions instead).
769 [basic.lookup.koenig]: If the ordinary unqualified lookup of the name
770 finds the declaration of a class member function, the associated
771 namespaces and classes are not considered. */
773 if (args && !current_template_parms && (!id || is_global (id)))
774 id = lookup_arg_dependent (token, id, args);
776 if (id == error_mark_node)
778 /* lookup_name quietly returns error_mark_node if we're parsing,
779 as we don't want to complain about an identifier that ends up
780 being used as a declarator. So we call it again to get the error
782 id = lookup_name (token, 0);
783 return error_mark_node;
786 if (!id || (TREE_CODE (id) == FUNCTION_DECL
787 && DECL_ANTICIPATED (id)))
789 if (current_template_parms)
790 return build_min_nt (LOOKUP_EXPR, token);
791 else if (IDENTIFIER_TYPENAME_P (token))
792 /* A templated conversion operator might exist. */
796 unqualified_name_lookup_error (token);
797 return error_mark_node;
801 id = check_for_out_of_scope_variable (id);
803 /* TREE_USED is set in `hack_identifier'. */
804 if (TREE_CODE (id) == CONST_DECL)
807 if (IDENTIFIER_CLASS_VALUE (token) == id)
808 enforce_access (CP_DECL_CONTEXT(id), id);
809 if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
810 id = DECL_INITIAL (id);
813 id = hack_identifier (id, token);
815 /* We must look up dependent names when the template is
816 instantiated, not while parsing it. For now, we don't
817 distinguish between dependent and independent names. So, for
818 example, we look up all overloaded functions at
819 instantiation-time, even though in some cases we should just use
820 the DECL we have here. We also use LOOKUP_EXPRs to find things
821 like local variables, rather than creating TEMPLATE_DECLs for the
822 local variables and then finding matching instantiations. */
823 if (current_template_parms
824 && (is_overloaded_fn (id)
825 || (TREE_CODE (id) == VAR_DECL
826 && CP_DECL_CONTEXT (id)
827 && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL)
828 || TREE_CODE (id) == PARM_DECL
829 || TREE_CODE (id) == RESULT_DECL
830 || TREE_CODE (id) == USING_DECL))
831 id = build_min_nt (LOOKUP_EXPR, token);
837 do_scoped_id (token, id)
841 if (!id || (TREE_CODE (id) == FUNCTION_DECL
842 && DECL_ANTICIPATED (id)))
844 if (processing_template_decl)
846 id = build_min_nt (LOOKUP_EXPR, token);
847 LOOKUP_EXPR_GLOBAL (id) = 1;
850 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
851 error ("`::%D' undeclared (first use here)", token);
852 id = error_mark_node;
853 /* Prevent repeated error messages. */
854 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
858 if (TREE_CODE (id) == ADDR_EXPR)
859 mark_used (TREE_OPERAND (id, 0));
860 else if (TREE_CODE (id) != OVERLOAD)
863 if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
865 /* XXX CHS - should we set TREE_USED of the constant? */
866 id = DECL_INITIAL (id);
867 /* This is to prevent an enum whose value is 0
868 from being considered a null pointer constant. */
869 id = build1 (NOP_EXPR, TREE_TYPE (id), id);
870 TREE_CONSTANT (id) = 1;
873 if (processing_template_decl)
875 if (is_overloaded_fn (id))
877 id = build_min_nt (LOOKUP_EXPR, token);
878 LOOKUP_EXPR_GLOBAL (id) = 1;
881 /* else just use the decl */
883 return convert_from_reference (id);
887 identifier_typedecl_value (node)
891 type = IDENTIFIER_TYPE_VALUE (node);
892 if (type == NULL_TREE)
895 if (IDENTIFIER_BINDING (node))
897 t = IDENTIFIER_VALUE (node);
898 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
901 if (IDENTIFIER_NAMESPACE_VALUE (node))
903 t = IDENTIFIER_NAMESPACE_VALUE (node);
904 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
908 /* Will this one ever happen? */
909 if (TYPE_MAIN_DECL (type))
910 return TYPE_MAIN_DECL (type);
912 /* We used to do an internal error of 62 here, but instead we will
913 handle the return of a null appropriately in the callers. */
917 #ifdef GATHER_STATISTICS
918 /* The original for tree_node_kind is in the toplevel tree.c; changes there
919 need to be brought into here, unless this were actually put into a header
921 /* Statistics-gathering stuff. */
942 extern int tree_node_counts[];
943 extern int tree_node_sizes[];
947 build_lang_decl (code, name, type)
954 t = build_decl (code, name, type);
955 retrofit_lang_decl (t);
960 /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
961 and pushdecl (for functions generated by the backend). */
964 retrofit_lang_decl (t)
967 struct lang_decl *ld;
970 if (CAN_HAVE_FULL_LANG_DECL_P (t))
971 size = sizeof (struct lang_decl);
973 size = sizeof (struct lang_decl_flags);
975 ld = (struct lang_decl *) ggc_alloc_cleared (size);
977 ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
978 ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
979 ld->decl_flags.u2sel = 0;
980 if (ld->decl_flags.can_be_full)
981 ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
983 DECL_LANG_SPECIFIC (t) = ld;
984 if (current_lang_name == lang_name_cplusplus)
985 SET_DECL_LANGUAGE (t, lang_cplusplus);
986 else if (current_lang_name == lang_name_c)
987 SET_DECL_LANGUAGE (t, lang_c);
988 else if (current_lang_name == lang_name_java)
989 SET_DECL_LANGUAGE (t, lang_java);
992 #ifdef GATHER_STATISTICS
993 tree_node_counts[(int)lang_decl] += 1;
994 tree_node_sizes[(int)lang_decl] += size;
999 cxx_dup_lang_specific_decl (node)
1003 struct lang_decl *ld;
1005 if (! DECL_LANG_SPECIFIC (node))
1008 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
1009 size = sizeof (struct lang_decl_flags);
1011 size = sizeof (struct lang_decl);
1012 ld = (struct lang_decl *) ggc_alloc (size);
1013 memcpy (ld, DECL_LANG_SPECIFIC (node), size);
1014 DECL_LANG_SPECIFIC (node) = ld;
1016 #ifdef GATHER_STATISTICS
1017 tree_node_counts[(int)lang_decl] += 1;
1018 tree_node_sizes[(int)lang_decl] += size;
1022 /* Copy DECL, including any language-specific parts. */
1030 copy = copy_node (decl);
1031 cxx_dup_lang_specific_decl (copy);
1035 /* Replace the shared language-specific parts of NODE with a new copy. */
1038 copy_lang_type (node)
1042 struct lang_type *lt;
1044 if (! TYPE_LANG_SPECIFIC (node))
1047 if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class)
1048 size = sizeof (struct lang_type);
1050 size = sizeof (struct lang_type_ptrmem);
1051 lt = (struct lang_type *) ggc_alloc (size);
1052 memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
1053 TYPE_LANG_SPECIFIC (node) = lt;
1055 #ifdef GATHER_STATISTICS
1056 tree_node_counts[(int)lang_type] += 1;
1057 tree_node_sizes[(int)lang_type] += size;
1061 /* Copy TYPE, including any language-specific parts. */
1069 copy = copy_node (type);
1070 copy_lang_type (copy);
1075 cxx_make_type (code)
1076 enum tree_code code;
1078 register tree t = make_node (code);
1080 /* Create lang_type structure. */
1081 if (IS_AGGR_TYPE_CODE (code)
1082 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
1084 struct lang_type *pi;
1086 pi = ((struct lang_type *)
1087 ggc_alloc_cleared (sizeof (struct lang_type)));
1089 TYPE_LANG_SPECIFIC (t) = pi;
1090 pi->u.c.h.is_lang_type_class = 1;
1092 #ifdef GATHER_STATISTICS
1093 tree_node_counts[(int)lang_type] += 1;
1094 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
1098 /* Set up some flags that give proper default behavior. */
1099 if (IS_AGGR_TYPE_CODE (code))
1101 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
1102 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1104 /* Make sure this is laid out, for ease of use later. In the
1105 presence of parse errors, the normal was of assuring this
1106 might not ever get executed, so we lay it out *immediately*. */
1107 build_pointer_type (t);
1110 /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
1111 TYPE_ALIAS_SET is initialized to -1 by default, so we must
1113 TYPE_ALIAS_SET (t) = 0;
1115 /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
1116 since they can be virtual base types, and we then need a
1117 canonical binfo for them. Ideally, this would be done lazily for
1119 if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM
1120 || code == BOUND_TEMPLATE_TEMPLATE_PARM
1121 || code == TYPENAME_TYPE)
1122 TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
1128 make_aggr_type (code)
1129 enum tree_code code;
1131 tree t = cxx_make_type (code);
1133 if (IS_AGGR_TYPE_CODE (code))
1134 SET_IS_AGGR_TYPE (t, 1);
1139 /* Return the type-qualifier corresponding to the identifier given by
1143 cp_type_qual_from_rid (rid)
1146 if (rid == ridpointers[(int) RID_CONST])
1147 return TYPE_QUAL_CONST;
1148 else if (rid == ridpointers[(int) RID_VOLATILE])
1149 return TYPE_QUAL_VOLATILE;
1150 else if (rid == ridpointers[(int) RID_RESTRICT])
1151 return TYPE_QUAL_RESTRICT;
1154 return TYPE_UNQUALIFIED;