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)
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 static int interface_strcmp (const char *);
43 static void init_cp_pragma (void);
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 *);
52 static void init_operators (void);
53 static void copy_lang_type (tree);
55 /* A constraint that can be tested at compile time. */
56 #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
58 /* Functions and data structures for #pragma interface.
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".
65 All main input files "implement" themselves automagically.
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
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"'. */
80 struct impl_files *next;
83 static struct impl_files *impl_file_chain;
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.
91 We return an INDIRECT_REF whose "contents" are TARGET
92 and whose type is the modifier list. */
95 make_pointer_declarator (tree cv_qualifiers, tree target)
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;
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.
110 We return an ADDR_EXPR whose "contents" are TARGET
111 and whose type is the modifier list. */
114 make_reference_declarator (tree cv_qualifiers, tree target)
116 target = build_nt (ADDR_EXPR, target);
117 TREE_TYPE (target) = cv_qualifiers;
122 make_call_declarator (tree target, tree parms, tree cv_qualifiers,
123 tree exception_specification)
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. */
130 CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
135 set_quals_and_spec (tree call_declarator, tree cv_qualifiers,
136 tree exception_specification)
138 CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
139 CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
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. */
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];
159 /* Initialize data structures that keep track of operator names. */
161 #define DEF_OPERATOR(NAME, C, M, AR, AP) \
162 CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256);
163 #include "operators.def"
167 init_operators (void)
171 struct operator_name_info_t *oni;
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; \
179 ? &assignment_operator_name_info[(int) CODE] \
180 : &operator_name_info[(int) CODE]); \
181 oni->identifier = identifier; \
183 oni->mangled_name = MANGLING; \
186 #include "operators.def"
189 operator_name_info[(int) ERROR_MARK].identifier
190 = get_identifier ("<invalid operator>");
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.) */
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 = "+";
214 assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
216 assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
218 assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
220 assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
222 assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
224 assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
226 assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
230 /* The reserved keyword table. */
233 const char *const word;
234 const ENUM_BITFIELD(rid) rid : 16;
235 const unsigned int disable : 16;
238 /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
240 #define D_EXT 0x01 /* GCC extension */
241 #define D_ASM 0x02 /* in C99, but has a switch to turn it off */
243 CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
245 static const struct resword reswords[] =
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_va_arg", RID_VA_ARG, 0 },
257 { "__complex", RID_COMPLEX, 0 },
258 { "__complex__", RID_COMPLEX, 0 },
259 { "__const", RID_CONST, 0 },
260 { "__const__", RID_CONST, 0 },
261 { "__extension__", RID_EXTENSION, 0 },
262 { "__func__", RID_C99_FUNCTION_NAME, 0 },
263 { "__imag", RID_IMAGPART, 0 },
264 { "__imag__", RID_IMAGPART, 0 },
265 { "__inline", RID_INLINE, 0 },
266 { "__inline__", RID_INLINE, 0 },
267 { "__label__", RID_LABEL, 0 },
268 { "__null", RID_NULL, 0 },
269 { "__real", RID_REALPART, 0 },
270 { "__real__", RID_REALPART, 0 },
271 { "__restrict", RID_RESTRICT, 0 },
272 { "__restrict__", RID_RESTRICT, 0 },
273 { "__signed", RID_SIGNED, 0 },
274 { "__signed__", RID_SIGNED, 0 },
275 { "__thread", RID_THREAD, 0 },
276 { "__typeof", RID_TYPEOF, 0 },
277 { "__typeof__", RID_TYPEOF, 0 },
278 { "__volatile", RID_VOLATILE, 0 },
279 { "__volatile__", RID_VOLATILE, 0 },
280 { "asm", RID_ASM, D_ASM },
281 { "auto", RID_AUTO, 0 },
282 { "bool", RID_BOOL, 0 },
283 { "break", RID_BREAK, 0 },
284 { "case", RID_CASE, 0 },
285 { "catch", RID_CATCH, 0 },
286 { "char", RID_CHAR, 0 },
287 { "class", RID_CLASS, 0 },
288 { "const", RID_CONST, 0 },
289 { "const_cast", RID_CONSTCAST, 0 },
290 { "continue", RID_CONTINUE, 0 },
291 { "default", RID_DEFAULT, 0 },
292 { "delete", RID_DELETE, 0 },
294 { "double", RID_DOUBLE, 0 },
295 { "dynamic_cast", RID_DYNCAST, 0 },
296 { "else", RID_ELSE, 0 },
297 { "enum", RID_ENUM, 0 },
298 { "explicit", RID_EXPLICIT, 0 },
299 { "export", RID_EXPORT, 0 },
300 { "extern", RID_EXTERN, 0 },
301 { "false", RID_FALSE, 0 },
302 { "float", RID_FLOAT, 0 },
303 { "for", RID_FOR, 0 },
304 { "friend", RID_FRIEND, 0 },
305 { "goto", RID_GOTO, 0 },
307 { "inline", RID_INLINE, 0 },
308 { "int", RID_INT, 0 },
309 { "long", RID_LONG, 0 },
310 { "mutable", RID_MUTABLE, 0 },
311 { "namespace", RID_NAMESPACE, 0 },
312 { "new", RID_NEW, 0 },
313 { "operator", RID_OPERATOR, 0 },
314 { "private", RID_PRIVATE, 0 },
315 { "protected", RID_PROTECTED, 0 },
316 { "public", RID_PUBLIC, 0 },
317 { "register", RID_REGISTER, 0 },
318 { "reinterpret_cast", RID_REINTCAST, 0 },
319 { "return", RID_RETURN, 0 },
320 { "short", RID_SHORT, 0 },
321 { "signed", RID_SIGNED, 0 },
322 { "sizeof", RID_SIZEOF, 0 },
323 { "static", RID_STATIC, 0 },
324 { "static_cast", RID_STATCAST, 0 },
325 { "struct", RID_STRUCT, 0 },
326 { "switch", RID_SWITCH, 0 },
327 { "template", RID_TEMPLATE, 0 },
328 { "this", RID_THIS, 0 },
329 { "throw", RID_THROW, 0 },
330 { "true", RID_TRUE, 0 },
331 { "try", RID_TRY, 0 },
332 { "typedef", RID_TYPEDEF, 0 },
333 { "typename", RID_TYPENAME, 0 },
334 { "typeid", RID_TYPEID, 0 },
335 { "typeof", RID_TYPEOF, D_ASM|D_EXT },
336 { "union", RID_UNION, 0 },
337 { "unsigned", RID_UNSIGNED, 0 },
338 { "using", RID_USING, 0 },
339 { "virtual", RID_VIRTUAL, 0 },
340 { "void", RID_VOID, 0 },
341 { "volatile", RID_VOLATILE, 0 },
342 { "wchar_t", RID_WCHAR, 0 },
343 { "while", RID_WHILE, 0 },
352 int mask = ((flag_no_asm ? D_ASM : 0)
353 | (flag_no_gnu_keywords ? D_EXT : 0));
355 ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree));
356 for (i = 0; i < ARRAY_SIZE (reswords); i++)
358 id = get_identifier (reswords[i].word);
359 C_RID_CODE (id) = reswords[i].rid;
360 ridpointers [(int) reswords[i].rid] = id;
361 if (! (reswords[i].disable & mask))
362 C_IS_RESERVED_WORD (id) = 1;
367 init_cp_pragma (void)
369 c_register_pragma (0, "vtable", handle_pragma_vtable);
370 c_register_pragma (0, "unit", handle_pragma_unit);
371 c_register_pragma (0, "interface", handle_pragma_interface);
372 c_register_pragma (0, "implementation", handle_pragma_implementation);
373 c_register_pragma ("GCC", "interface", handle_pragma_interface);
374 c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
375 c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions);
378 /* Initialize the C++ front end. This function is very sensitive to
379 the exact order that things are done here. It would be nice if the
380 initialization done by this routine were moved to its subroutines,
381 and the ordering dependencies clarified and reduced. */
385 static const enum tree_code stmt_codes[] = {
390 INIT_STATEMENT_CODES (stmt_codes);
392 /* We cannot just assign to input_filename because it has already
393 been initialized and will be used later as an N_BINCL for stabs+
395 push_srcloc ("<internal>", 0);
399 init_cp_semantics ();
404 current_function_decl = NULL;
406 class_type_node = build_int_2 (class_type, 0);
407 TREE_TYPE (class_type_node) = class_type_node;
408 ridpointers[(int) RID_CLASS] = class_type_node;
410 record_type_node = build_int_2 (record_type, 0);
411 TREE_TYPE (record_type_node) = record_type_node;
412 ridpointers[(int) RID_STRUCT] = record_type_node;
414 union_type_node = build_int_2 (union_type, 0);
415 TREE_TYPE (union_type_node) = union_type_node;
416 ridpointers[(int) RID_UNION] = union_type_node;
418 enum_type_node = build_int_2 (enum_type, 0);
419 TREE_TYPE (enum_type_node) = enum_type_node;
420 ridpointers[(int) RID_ENUM] = enum_type_node;
422 cxx_init_decl_processing ();
424 /* Create the built-in __null node. */
425 null_node = build_int_2 (0, 0);
426 TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
427 ridpointers[RID_NULL] = null_node;
429 interface_unknown = 1;
431 if (c_common_init () == false)
439 init_repo (main_input_filename);
445 /* Helper function to load global variables with interface
449 extract_interface_info (void)
451 struct c_fileinfo *finfo = 0;
453 if (flag_alt_external_templates)
455 tree til = tinst_for_decl ();
458 finfo = get_fileinfo (TINST_FILE (til));
461 finfo = get_fileinfo (input_filename);
463 interface_only = finfo->interface_only;
464 interface_unknown = finfo->interface_unknown;
467 /* Return nonzero if S is not considered part of an
468 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
471 interface_strcmp (const char* s)
473 /* Set the interface/implementation bits for this scope. */
474 struct impl_files *ifiles;
477 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
479 const char *t1 = ifiles->filename;
482 if (*s1 != *t1 || *s1 == 0)
485 while (*s1 == *t1 && *s1 != 0)
492 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
493 if (strchr (s1, '.') || strchr (t1, '.'))
496 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
509 /* Parse a #pragma whose sole argument is a string constant.
510 If OPT is true, the argument is optional. */
512 parse_strconst_pragma (const char* name, int opt)
521 if (c_lex (&x) != CPP_EOF)
522 warning ("junk at end of #pragma %s", name);
526 if (t == CPP_EOF && opt)
529 error ("invalid #pragma %s", name);
534 handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED )
536 parse_strconst_pragma ("vtable", 0);
537 sorry ("#pragma vtable no longer supported");
541 handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED )
543 /* Validate syntax, but don't do anything. */
544 parse_strconst_pragma ("unit", 0);
548 handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
550 tree fname = parse_strconst_pragma ("interface", 1);
551 struct c_fileinfo *finfo;
552 const char *main_filename;
554 if (fname == (tree)-1)
557 main_filename = lbasename (input_filename);
559 main_filename = TREE_STRING_POINTER (fname);
561 finfo = get_fileinfo (input_filename);
563 if (impl_file_chain == 0)
565 /* If this is zero at this point, then we are
566 auto-implementing. */
567 if (main_input_filename == 0)
568 main_input_filename = input_filename;
571 interface_only = interface_strcmp (main_filename);
572 #ifdef MULTIPLE_SYMBOL_SPACES
573 if (! interface_only)
575 interface_unknown = 0;
577 finfo->interface_only = interface_only;
578 finfo->interface_unknown = interface_unknown;
581 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
582 We used to only allow this at toplevel, but that restriction was buggy
583 in older compilers and it seems reasonable to allow it in the headers
584 themselves, too. It only needs to precede the matching #p interface.
586 We don't touch interface_only or interface_unknown; the user must specify
587 a matching #p interface for this to have any effect. */
590 handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
592 tree fname = parse_strconst_pragma ("implementation", 1);
593 const char *main_filename;
594 struct impl_files *ifiles = impl_file_chain;
596 if (fname == (tree)-1)
601 if (main_input_filename)
602 main_filename = main_input_filename;
604 main_filename = input_filename;
605 main_filename = lbasename (main_filename);
609 main_filename = TREE_STRING_POINTER (fname);
610 if (cpp_included (parse_in, main_filename))
611 warning ("#pragma implementation for %s appears after file is included",
615 for (; ifiles; ifiles = ifiles->next)
617 if (! strcmp (ifiles->filename, main_filename))
622 ifiles = xmalloc (sizeof (struct impl_files));
623 ifiles->filename = main_filename;
624 ifiles->next = impl_file_chain;
625 impl_file_chain = ifiles;
629 /* Indicate that this file uses Java-personality exception handling. */
631 handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED )
634 if (c_lex (&x) != CPP_EOF)
635 warning ("junk at end of #pragma GCC java_exceptions");
637 choose_personality_routine (lang_java);
640 /* Issue an error message indicating that the lookup of NAME (an
641 IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */
644 unqualified_name_lookup_error (tree name)
646 if (IDENTIFIER_OPNAME_P (name))
648 if (name != ansi_opname (ERROR_MARK))
649 error ("`%D' not defined", name);
651 else if (current_function_decl == 0)
652 error ("`%D' was not declared in this scope", name);
655 if (IDENTIFIER_NAMESPACE_VALUE (name) != error_mark_node
656 || IDENTIFIER_ERROR_LOCUS (name) != current_function_decl)
658 static int undeclared_variable_notice;
660 error ("`%D' undeclared (first use this function)", name);
662 if (! undeclared_variable_notice)
664 error ("(Each undeclared identifier is reported only once for each function it appears in.)");
665 undeclared_variable_notice = 1;
668 /* Prevent repeated error messages. */
669 SET_IDENTIFIER_NAMESPACE_VALUE (name, error_mark_node);
670 SET_IDENTIFIER_ERROR_LOCUS (name, current_function_decl);
673 return error_mark_node;
676 /* Like unqualified_name_lookup_error, but NAME is an unqualified-id
677 used as a function. Returns an appropriate expression for
681 unqualified_fn_lookup_error (tree name)
683 if (processing_template_decl)
685 /* In a template, it is invalid to write "f()" or "f(3)" if no
686 declaration of "f" is available. Historically, G++ and most
687 other compilers accepted that usage since they deferred all name
688 lookup until instantiation time rather than doing unqualified
689 name lookup at template definition time; explain to the user what
692 Note that we have the exact wording of the following message in
693 the manual (trouble.texi, node "Name lookup"), so they need to
695 pedwarn ("there are no arguments to `%D' that depend on a template "
696 "parameter, so a declaration of `%D' must be available",
699 if (!flag_permissive)
704 error ("(if you use `-fpermissive', G++ will accept your code, "
705 "but allowing the use of an undeclared name is "
713 return unqualified_name_lookup_error (name);
717 build_lang_decl (enum tree_code code, tree name, tree type)
721 t = build_decl (code, name, type);
722 retrofit_lang_decl (t);
727 /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
728 and pushdecl (for functions generated by the backend). */
731 retrofit_lang_decl (tree t)
733 struct lang_decl *ld;
736 if (CAN_HAVE_FULL_LANG_DECL_P (t))
737 size = sizeof (struct lang_decl);
739 size = sizeof (struct lang_decl_flags);
741 ld = ggc_alloc_cleared (size);
743 ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
744 ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
745 ld->decl_flags.u2sel = 0;
746 if (ld->decl_flags.can_be_full)
747 ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
749 DECL_LANG_SPECIFIC (t) = ld;
750 if (current_lang_name == lang_name_cplusplus)
751 SET_DECL_LANGUAGE (t, lang_cplusplus);
752 else if (current_lang_name == lang_name_c)
753 SET_DECL_LANGUAGE (t, lang_c);
754 else if (current_lang_name == lang_name_java)
755 SET_DECL_LANGUAGE (t, lang_java);
758 #ifdef GATHER_STATISTICS
759 tree_node_counts[(int)lang_decl] += 1;
760 tree_node_sizes[(int)lang_decl] += size;
765 cxx_dup_lang_specific_decl (tree node)
768 struct lang_decl *ld;
770 if (! DECL_LANG_SPECIFIC (node))
773 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
774 size = sizeof (struct lang_decl_flags);
776 size = sizeof (struct lang_decl);
777 ld = ggc_alloc (size);
778 memcpy (ld, DECL_LANG_SPECIFIC (node), size);
779 DECL_LANG_SPECIFIC (node) = ld;
781 #ifdef GATHER_STATISTICS
782 tree_node_counts[(int)lang_decl] += 1;
783 tree_node_sizes[(int)lang_decl] += size;
787 /* Copy DECL, including any language-specific parts. */
790 copy_decl (tree decl)
794 copy = copy_node (decl);
795 cxx_dup_lang_specific_decl (copy);
799 /* Replace the shared language-specific parts of NODE with a new copy. */
802 copy_lang_type (tree node)
805 struct lang_type *lt;
807 if (! TYPE_LANG_SPECIFIC (node))
810 if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class)
811 size = sizeof (struct lang_type);
813 size = sizeof (struct lang_type_ptrmem);
814 lt = ggc_alloc (size);
815 memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
816 TYPE_LANG_SPECIFIC (node) = lt;
818 #ifdef GATHER_STATISTICS
819 tree_node_counts[(int)lang_type] += 1;
820 tree_node_sizes[(int)lang_type] += size;
824 /* Copy TYPE, including any language-specific parts. */
827 copy_type (tree type)
831 copy = copy_node (type);
832 copy_lang_type (copy);
837 cxx_make_type (enum tree_code code)
839 register tree t = make_node (code);
841 /* Create lang_type structure. */
842 if (IS_AGGR_TYPE_CODE (code)
843 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
845 struct lang_type *pi;
847 pi = ggc_alloc_cleared (sizeof (struct lang_type));
849 TYPE_LANG_SPECIFIC (t) = pi;
850 pi->u.c.h.is_lang_type_class = 1;
852 #ifdef GATHER_STATISTICS
853 tree_node_counts[(int)lang_type] += 1;
854 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
858 /* Set up some flags that give proper default behavior. */
859 if (IS_AGGR_TYPE_CODE (code))
861 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
862 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
864 /* Make sure this is laid out, for ease of use later. In the
865 presence of parse errors, the normal was of assuring this
866 might not ever get executed, so we lay it out *immediately*. */
867 build_pointer_type (t);
870 /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
871 TYPE_ALIAS_SET is initialized to -1 by default, so we must
873 TYPE_ALIAS_SET (t) = 0;
875 /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
876 since they can be virtual base types, and we then need a
877 canonical binfo for them. Ideally, this would be done lazily for
879 if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM
880 || code == BOUND_TEMPLATE_TEMPLATE_PARM
881 || code == TYPENAME_TYPE)
882 TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
888 make_aggr_type (enum tree_code code)
890 tree t = cxx_make_type (code);
892 if (IS_AGGR_TYPE_CODE (code))
893 SET_IS_AGGR_TYPE (t, 1);
898 /* Return the type-qualifier corresponding to the identifier given by
902 cp_type_qual_from_rid (tree rid)
904 if (rid == ridpointers[(int) RID_CONST])
905 return TYPE_QUAL_CONST;
906 else if (rid == ridpointers[(int) RID_VOLATILE])
907 return TYPE_QUAL_VOLATILE;
908 else if (rid == ridpointers[(int) RID_RESTRICT])
909 return TYPE_QUAL_RESTRICT;
912 return TYPE_UNQUALIFIED;