1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Process declarations and symbol lookup for C front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
43 #include "dwarf2out.h"
48 extern cpp_reader parse_in;
49 extern cpp_options parse_options;
50 static int cpp_initialized;
53 static tree get_sentry PROTO((tree));
54 static void mark_vtable_entries PROTO((tree));
55 static void import_export_template PROTO((tree));
56 static void grok_function_init PROTO((tree, tree));
57 static int finish_vtable_vardecl PROTO((tree, tree));
58 static int prune_vtable_vardecl PROTO((tree, tree));
59 static void finish_sigtable_vardecl PROTO((tree, tree));
60 static int is_namespace_ancestor PROTO((tree, tree));
61 static tree namespace_ancestor PROTO((tree, tree));
62 static void add_using_namespace PROTO((tree, tree, int));
63 static tree ambiguous_decl PROTO((tree, tree, tree));
64 static tree build_anon_union_vars PROTO((tree, tree*, int, int));
65 static void check_decl_namespace PROTO((void));
67 extern int current_class_depth;
69 /* A list of virtual function tables we must make sure to write out. */
72 /* A list of static class variables. This is needed, because a
73 static class variable can be declared inside the class without
74 an initializer, and then initialized, staticly, outside the class. */
77 /* A list of functions which were declared inline, but which we
78 may need to emit outline anyway. */
79 static tree saved_inlines;
81 /* Used to help generate temporary names which are unique within
82 a function. Reset to 0 by start_function. */
84 int temp_name_counter;
86 /* Same, but not reset. Local temp variables and global temp variables
87 can have the same name. */
88 static int global_temp_name_counter;
90 /* Flag used when debugging spew.c */
92 extern int spew_debug;
94 /* Nonzero if we're done parsing and into end-of-file activities. */
98 /* Functions called along with real static constructors and destructors. */
100 tree static_ctors, static_dtors;
102 /* The current open namespace, and ::. */
104 tree current_namespace;
105 tree global_namespace;
107 /* The stack for namespaces of current declarations. */
109 static tree decl_namespace_list;
112 /* C (and C++) language-specific option variables. */
114 /* Nonzero means allow type mismatches in conditional expressions;
115 just make their values `void'. */
117 int flag_cond_mismatch;
119 /* Nonzero means give `double' the same size as `float'. */
121 int flag_short_double;
123 /* Nonzero means don't recognize the keyword `asm'. */
127 /* Nonzero means don't recognize any extension keywords. */
129 int flag_no_gnu_keywords;
131 /* Nonzero means don't recognize the non-ANSI builtin functions. */
135 /* Nonzero means don't recognize the non-ANSI builtin functions.
138 int flag_no_nonansi_builtin;
140 /* Nonzero means do some things the same way PCC does. Only provided so
141 the compiler will link. */
143 int flag_traditional;
145 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
147 int flag_signed_bitfields = 1;
149 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
153 /* Nonzero means enable obscure ANSI features and disable GNU extensions
154 that might cause ANSI-compliant code to be miscompiled. */
158 /* Nonzero means do emit exported implementations of functions even if
159 they can be inlined. */
161 int flag_implement_inlines = 1;
163 /* Nonzero means do emit exported implementations of templates, instead of
164 multiple static copies in each file that needs a definition. */
166 int flag_external_templates;
168 /* Nonzero means that the decision to emit or not emit the implementation of a
169 template depends on where the template is instantiated, rather than where
172 int flag_alt_external_templates;
174 /* Nonzero means that implicit instantiations will be emitted if needed. */
176 int flag_implicit_templates = 1;
178 /* Nonzero means warn about implicit declarations. */
180 int warn_implicit = 1;
182 /* Nonzero means warn about usage of long long when `-pedantic'. */
184 int warn_long_long = 1;
186 /* Nonzero means warn when all ctors or dtors are private, and the class
189 int warn_ctor_dtor_privacy = 1;
191 /* True if we want to implement vtables using "thunks".
192 The default is off. */
194 #ifndef DEFAULT_VTABLE_THUNKS
195 #define DEFAULT_VTABLE_THUNKS 0
197 int flag_vtable_thunks = DEFAULT_VTABLE_THUNKS;
199 /* True if we want to deal with repository information. */
201 int flag_use_repository;
203 /* Nonzero if we want to issue diagnostics that the standard says are not
206 int flag_optional_diags = 1;
208 /* Nonzero means give string constants the type `const char *'
209 to get extra warnings from them. These warnings will be too numerous
210 to be useful, except in thoroughly ANSIfied programs. */
212 int warn_write_strings;
214 /* Nonzero means warn about pointer casts that can drop a type qualifier
215 from the pointer target type. */
219 /* Nonzero means warn about sizeof(function) or addition/subtraction
220 of function pointers. */
222 int warn_pointer_arith = 1;
224 /* Nonzero means warn for any function def without prototype decl. */
226 int warn_missing_prototypes;
228 /* Nonzero means warn about multiple (redundant) decls for the same single
229 variable or function. */
231 int warn_redundant_decls;
233 /* Warn if initializer is not completely bracketed. */
235 int warn_missing_braces;
237 /* Warn about comparison of signed and unsigned values. */
239 int warn_sign_compare;
241 /* Warn about *printf or *scanf format/argument anomalies. */
245 /* Warn about a subscript that has type char. */
247 int warn_char_subscripts;
249 /* Warn if a type conversion is done that might have confusing results. */
253 /* Warn if adding () is suggested. */
255 int warn_parentheses;
257 /* Non-zero means warn in function declared in derived class has the
258 same name as a virtual in the base class, but fails to match the
259 type signature of any virtual function in the base class. */
260 int warn_overloaded_virtual;
262 /* Non-zero means warn when declaring a class that has a non virtual
263 destructor, when it really ought to have a virtual one. */
266 /* Non-zero means warn when a function is declared extern and later inline. */
267 int warn_extern_inline;
269 /* Non-zero means warn when the compiler will reorder code. */
272 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
275 /* Non-zero means warn when we convert a pointer to member function
276 into a pointer to (void or function). */
277 int warn_pmf2ptr = 1;
279 /* Nonzero means warn about violation of some Effective C++ style rules. */
283 /* Nonzero means warn where overload resolution chooses a promotion from
284 unsigned to signed over a conversion to an unsigned of the same size. */
288 /* Nonzero means warn when an old-style cast is used. */
290 int warn_old_style_cast;
292 /* Warn about #pragma directives that are not recognised. */
294 int warn_unknown_pragmas; /* Tri state variable. */
296 /* Nonzero means warn about use of multicharacter literals. */
298 int warn_multichar = 1;
300 /* Nonzero means `$' can be in an identifier. */
302 #ifndef DOLLARS_IN_IDENTIFIERS
303 #define DOLLARS_IN_IDENTIFIERS 1
305 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
307 /* Nonzero for -fno-strict-prototype switch: do not consider empty
308 argument prototype to mean function takes no arguments. */
310 int flag_strict_prototype = 2;
311 int strict_prototype = 1;
312 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
314 /* Nonzero means that labels can be used as first-class objects */
318 /* Non-zero means to collect statistics which might be expensive
319 and to print them when we are done. */
320 int flag_detailed_statistics;
322 /* C++ specific flags. */
323 /* Nonzero for -fall-virtual: make every member function (except
324 constructors) lay down in the virtual function table. Calls
325 can then either go through the virtual function table or not,
328 int flag_all_virtual;
330 /* Zero means that `this' is a *const. This gives nice behavior in the
331 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
332 -2 means we're constructing an object and it has fixed type. */
334 int flag_this_is_variable;
336 /* Nonzero means memoize our member lookups. */
338 int flag_memoize_lookups; int flag_save_memoized_contexts;
340 /* 3 means write out only virtuals function tables `defined'
341 in this implementation file.
342 2 means write out only specific virtual function tables
343 and give them (C) public access.
344 1 means write out virtual function tables and give them
346 0 means write out virtual function tables and give them
347 (C) static access (default).
348 -1 means declare virtual function tables extern. */
352 /* Nonzero means we should attempt to elide constructors when possible.
353 FIXME: This flag is obsolete, and should be torn out along with the
354 old overloading code. */
356 int flag_elide_constructors;
358 /* Nonzero means recognize and handle signature language constructs. */
360 int flag_handle_signatures;
362 /* Nonzero means that member functions defined in class scope are
363 inline by default. */
365 int flag_default_inline = 1;
367 /* Controls whether enums and ints freely convert.
368 1 means with complete freedom.
369 0 means enums can convert to ints, but not vice-versa. */
370 int flag_int_enum_equivalence;
372 /* Controls whether compiler generates 'type descriptor' that give
373 run-time type information. */
376 /* Nonzero if we wish to output cross-referencing information
377 for the GNU class browser. */
378 extern int flag_gnu_xref;
380 /* Nonzero if compiler can make `reasonable' assumptions about
381 references and objects. For example, the compiler must be
382 conservative about the following and not assume that `a' is nonnull:
387 In general, it is `reasonable' to assume that for many programs,
388 and better code can be generated in that case. */
390 int flag_assume_nonnull_objects = 1;
392 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
395 int flag_huge_objects;
397 /* Nonzero if we want to conserve space in the .o files. We do this
398 by putting uninitialized data and runtime initialized data into
399 .common instead of .data at the expense of not flagging multiple
402 int flag_conserve_space;
404 /* Nonzero if we want to obey access control semantics. */
406 int flag_access_control = 1;
408 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
410 int flag_operator_names;
412 /* Nonzero if we want to check the return value of new and avoid calling
413 constructors if it is a null pointer. */
417 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
418 initialization variables.
419 0: Old rules, set by -fno-for-scope.
420 2: New ANSI rules, set by -ffor-scope.
421 1: Try to implement new ANSI rules, but with backup compatibility
422 (and warnings). This is the default, for now. */
424 int flag_new_for_scope = 1;
426 /* Nonzero if we want to emit defined symbols with common-like linkage as
427 weak symbols where possible, in order to conform to C++ semantics.
428 Otherwise, emit them as local symbols. */
432 /* Nonzero to enable experimental ABI changes. */
436 /* Nonzero to not ignore namespace std. */
440 /* Maximum template instantiation depth. Must be at least 17 for ANSI
443 int max_tinst_depth = 17;
445 /* The name-mangling scheme to use. Must be 1 or greater to support
446 template functions with identical types, but different template
448 int name_mangling_version = 2;
450 /* Nonzero means that guiding declarations are allowed. */
451 int flag_guiding_decls;
453 /* Nonzero if squashed mangling is to be performed.
454 This uses the B and K codes to reference previously seen class types
455 and class qualifiers. */
456 int flag_do_squangling;
459 /* Table of language-dependent -f options.
460 STRING is the option name. VARIABLE is the address of the variable.
461 ON_VALUE is the value to store in VARIABLE
462 if `-fSTRING' is seen as an option.
463 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
465 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
467 {"signed-char", &flag_signed_char, 1},
468 {"unsigned-char", &flag_signed_char, 0},
469 {"signed-bitfields", &flag_signed_bitfields, 1},
470 {"unsigned-bitfields", &flag_signed_bitfields, 0},
471 {"short-enums", &flag_short_enums, 1},
472 {"short-double", &flag_short_double, 1},
473 {"cond-mismatch", &flag_cond_mismatch, 1},
474 {"squangle", &flag_do_squangling, 1},
475 {"asm", &flag_no_asm, 0},
476 {"builtin", &flag_no_builtin, 0},
477 {"ident", &flag_no_ident, 0},
478 {"labels-ok", &flag_labels_ok, 1},
479 {"stats", &flag_detailed_statistics, 1},
480 {"this-is-variable", &flag_this_is_variable, 1},
481 {"strict-prototype", &flag_strict_prototype, 1},
482 {"all-virtual", &flag_all_virtual, 1},
483 {"memoize-lookups", &flag_memoize_lookups, 1},
484 {"elide-constructors", &flag_elide_constructors, 1},
485 {"handle-exceptions", &flag_exceptions, 1},
486 {"handle-signatures", &flag_handle_signatures, 1},
487 {"default-inline", &flag_default_inline, 1},
488 {"dollars-in-identifiers", &dollars_in_ident, 1},
489 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
490 {"honor-std", &flag_honor_std, 1},
491 {"rtti", &flag_rtti, 1},
492 {"xref", &flag_gnu_xref, 1},
493 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
494 {"implement-inlines", &flag_implement_inlines, 1},
495 {"external-templates", &flag_external_templates, 1},
496 {"implicit-templates", &flag_implicit_templates, 1},
497 {"huge-objects", &flag_huge_objects, 1},
498 {"conserve-space", &flag_conserve_space, 1},
499 {"vtable-thunks", &flag_vtable_thunks, 1},
500 {"access-control", &flag_access_control, 1},
501 {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
502 {"gnu-keywords", &flag_no_gnu_keywords, 0},
503 {"operator-names", &flag_operator_names, 1},
504 {"optional-diags", &flag_optional_diags, 1},
505 {"check-new", &flag_check_new, 1},
506 {"repo", &flag_use_repository, 1},
507 {"for-scope", &flag_new_for_scope, 2},
508 {"weak", &flag_weak, 1}
511 /* Decode the string P as a language-specific option.
512 Return the number of strings consumed for a valid option.
513 Otherwise return 0. */
516 lang_decode_option (argc, argv)
521 int strings_processed;
524 if (! cpp_initialized)
526 cpp_reader_init (&parse_in);
527 parse_in.data = &parse_options;
528 cpp_options_init (&parse_options);
531 strings_processed = cpp_handle_option (&parse_in, argc, argv);
533 strings_processed = 0;
534 #endif /* ! USE_CPPLIB */
536 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
537 flag_writable_strings = 1,
538 flag_this_is_variable = 1, flag_new_for_scope = 0;
539 /* The +e options are for cfront compatibility. They come in as
540 `-+eN', to kludge around gcc.c's argument handling. */
541 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
543 int old_write_virtuals = write_virtuals;
546 else if (p[3] == '0')
548 else if (p[3] == '2')
550 else error ("invalid +e option");
551 if (old_write_virtuals != 0
552 && write_virtuals != old_write_virtuals)
553 error ("conflicting +e options given");
555 else if (p[0] == '-' && p[1] == 'f')
557 /* Some kind of -f option.
558 P's value is the option sans `-f'.
559 Search for it in the table of options. */
564 /* Try special -f options. */
566 if (!strcmp (p, "handle-exceptions")
567 || !strcmp (p, "no-handle-exceptions"))
568 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
570 if (!strcmp (p, "save-memoized"))
572 flag_memoize_lookups = 1;
573 flag_save_memoized_contexts = 1;
576 else if (!strcmp (p, "no-save-memoized"))
578 flag_memoize_lookups = 0;
579 flag_save_memoized_contexts = 0;
582 else if (! strcmp (p, "alt-external-templates"))
584 flag_external_templates = 1;
585 flag_alt_external_templates = 1;
588 else if (! strcmp (p, "no-alt-external-templates"))
590 flag_alt_external_templates = 0;
593 else if (!strcmp (p, "repo"))
595 flag_use_repository = 1;
596 flag_implicit_templates = 0;
599 else if (!strcmp (p, "guiding-decls"))
601 flag_guiding_decls = 1;
602 name_mangling_version = 0;
605 else if (!strcmp (p, "no-guiding-decls"))
607 flag_guiding_decls = 0;
610 else if (!strcmp (p, "ansi-overloading"))
612 else if (!strcmp (p, "no-ansi-overloading"))
614 error ("-fno-ansi-overloading is no longer supported");
617 else if (!strcmp (p, "new-abi"))
620 flag_do_squangling = 1;
622 flag_vtable_thunks = 1;
624 else if (!strcmp (p, "no-new-abi"))
627 flag_do_squangling = 0;
630 else if (!strncmp (p, "template-depth-", 15))
635 if (*endp >= '0' && *endp <= '9')
639 error ("Invalid option `%s'", p - 2);
640 goto template_depth_lose;
643 max_tinst_depth = atoi (p + 15);
644 template_depth_lose: ;
646 else if (!strncmp (p, "name-mangling-version-", 22))
651 if (*endp >= '0' && *endp <= '9')
655 error ("Invalid option `%s'", p - 2);
656 goto mangling_version_lose;
659 name_mangling_version = atoi (p + 22);
660 mangling_version_lose: ;
663 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
666 if (!strcmp (p, lang_f_options[j].string))
668 *lang_f_options[j].variable = lang_f_options[j].on_value;
669 /* A goto here would be cleaner,
670 but breaks the vax pcc. */
673 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
674 && ! strcmp (p+3, lang_f_options[j].string))
676 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
682 else if (p[0] == '-' && p[1] == 'W')
686 /* The -W options control the warning behavior of the compiler. */
689 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
692 if (!strcmp (p, "implicit"))
693 warn_implicit = setting;
694 else if (!strcmp (p, "long-long"))
695 warn_long_long = setting;
696 else if (!strcmp (p, "return-type"))
697 warn_return_type = setting;
698 else if (!strcmp (p, "ctor-dtor-privacy"))
699 warn_ctor_dtor_privacy = setting;
700 else if (!strcmp (p, "write-strings"))
701 warn_write_strings = setting;
702 else if (!strcmp (p, "cast-qual"))
703 warn_cast_qual = setting;
704 else if (!strcmp (p, "char-subscripts"))
705 warn_char_subscripts = setting;
706 else if (!strcmp (p, "pointer-arith"))
707 warn_pointer_arith = setting;
708 else if (!strcmp (p, "missing-prototypes"))
709 warn_missing_prototypes = setting;
710 else if (!strcmp (p, "redundant-decls"))
711 warn_redundant_decls = setting;
712 else if (!strcmp (p, "missing-braces"))
713 warn_missing_braces = setting;
714 else if (!strcmp (p, "sign-compare"))
715 warn_sign_compare = setting;
716 else if (!strcmp (p, "format"))
717 warn_format = setting;
718 else if (!strcmp (p, "conversion"))
719 warn_conversion = setting;
720 else if (!strcmp (p, "parentheses"))
721 warn_parentheses = setting;
722 else if (!strcmp (p, "non-virtual-dtor"))
723 warn_nonvdtor = setting;
724 else if (!strcmp (p, "extern-inline"))
725 warn_extern_inline = setting;
726 else if (!strcmp (p, "reorder"))
727 warn_reorder = setting;
728 else if (!strcmp (p, "synth"))
729 warn_synth = setting;
730 else if (!strcmp (p, "pmf-conversions"))
731 warn_pmf2ptr = setting;
732 else if (!strcmp (p, "effc++"))
734 else if (!strcmp (p, "sign-promo"))
735 warn_sign_promo = setting;
736 else if (!strcmp (p, "old-style-cast"))
737 warn_old_style_cast = setting;
738 else if (!strcmp (p, "overloaded-virtual"))
739 warn_overloaded_virtual = setting;
740 else if (!strcmp (p, "multichar"))
741 warn_multichar = setting;
742 else if (!strcmp (p, "unknown-pragmas"))
743 /* Set to greater than 1, so that even unknown pragmas in
744 system headers will be warned about. */
745 warn_unknown_pragmas = setting * 2;
746 else if (!strcmp (p, "comment"))
747 ; /* cpp handles this one. */
748 else if (!strcmp (p, "comments"))
749 ; /* cpp handles this one. */
750 else if (!strcmp (p, "trigraphs"))
751 ; /* cpp handles this one. */
752 else if (!strcmp (p, "import"))
753 ; /* cpp handles this one. */
754 else if (!strcmp (p, "all"))
756 warn_return_type = setting;
757 warn_unused = setting;
758 warn_implicit = setting;
759 warn_ctor_dtor_privacy = setting;
760 warn_switch = setting;
761 warn_format = setting;
762 warn_parentheses = setting;
763 warn_missing_braces = setting;
764 warn_sign_compare = setting;
765 warn_extern_inline = setting;
766 warn_nonvdtor = setting;
767 warn_multichar = setting;
768 /* We save the value of warn_uninitialized, since if they put
769 -Wuninitialized on the command line, we need to generate a
770 warning about not using it without also specifying -O. */
771 if (warn_uninitialized != 1)
772 warn_uninitialized = (setting ? 2 : 0);
773 warn_reorder = setting;
774 warn_sign_promo = setting;
775 /* Only warn about unknown pragmas that are not in system
777 warn_unknown_pragmas = 1;
779 else return strings_processed;
781 else if (!strcmp (p, "-ansi"))
782 flag_no_nonansi_builtin = 1, flag_ansi = 1,
783 flag_no_gnu_keywords = 1, flag_operator_names = 1;
785 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
786 it's probably safe to assume no sane person would ever want to use this
787 under normal circumstances. */
788 else if (!strcmp (p, "-spew-debug"))
792 return strings_processed;
797 /* Incorporate `const' and `volatile' qualifiers for member functions.
798 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
799 QUALS is a list of qualifiers. */
802 grok_method_quals (ctype, function, quals)
803 tree ctype, function, quals;
805 tree fntype = TREE_TYPE (function);
806 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
810 extern tree ridpointers[];
812 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
814 if (TYPE_READONLY (ctype))
815 error ("duplicate `%s' %s",
816 IDENTIFIER_POINTER (TREE_VALUE (quals)),
817 (TREE_CODE (function) == FUNCTION_DECL
818 ? "for member function" : "in type declaration"));
819 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
820 build_pointer_type (ctype);
822 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
824 if (TYPE_VOLATILE (ctype))
825 error ("duplicate `%s' %s",
826 IDENTIFIER_POINTER (TREE_VALUE (quals)),
827 (TREE_CODE (function) == FUNCTION_DECL
828 ? "for member function" : "in type declaration"));
829 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
830 build_pointer_type (ctype);
833 my_friendly_abort (20);
834 quals = TREE_CHAIN (quals);
837 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
838 (TREE_CODE (fntype) == METHOD_TYPE
839 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
840 : TYPE_ARG_TYPES (fntype)));
842 fntype = build_exception_variant (fntype, raises);
844 TREE_TYPE (function) = fntype;
848 /* Warn when -fexternal-templates is used and #pragma
849 interface/implementation is not used all the times it should be,
853 warn_if_unknown_interface (decl)
856 static int already_warned = 0;
857 if (already_warned++)
860 if (flag_alt_external_templates)
862 struct tinst_level *til = tinst_for_decl ();
864 char *sf = input_filename;
869 input_filename = til->file;
871 cp_warning ("template `%#D' instantiated in file without #pragma interface",
877 cp_warning_at ("template `%#D' defined in file without #pragma interface",
881 /* A subroutine of the parser, to handle a component list. */
884 grok_x_components (specs, components)
885 tree specs, components;
887 register tree t, x, tcode;
889 /* We just got some friends. They have been recorded elsewhere. */
890 if (components == void_type_node)
893 if (components == NULL_TREE)
895 t = groktypename (build_decl_list (specs, NULL_TREE));
899 error ("error in component specification");
903 switch (TREE_CODE (t))
906 /* Static anonymous unions come out as VAR_DECLs. */
907 if (ANON_UNION_TYPE_P (TREE_TYPE (t)))
910 /* We return SPECS here, because in the parser it was ending
911 up with not doing anything to $$, which is what SPECS
917 /* This code may be needed for UNION_TYPEs as
919 tcode = record_type_node;
920 if (CLASSTYPE_DECLARED_CLASS (t))
921 tcode = class_type_node;
922 else if (IS_SIGNATURE (t))
923 tcode = signature_type_node;
925 if (CLASSTYPE_IS_TEMPLATE (t))
926 /* In this case, the TYPE_IDENTIFIER will be something
927 like S<T>, rather than S, so to get the correct name we
928 look at the template. */
929 x = DECL_NAME (CLASSTYPE_TI_TEMPLATE (t));
931 x = TYPE_IDENTIFIER (t);
933 t = xref_tag (tcode, x, NULL_TREE, 0);
939 if (TREE_CODE (t) == UNION_TYPE)
940 tcode = union_type_node;
942 tcode = enum_type_node;
944 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
945 if (ANON_UNION_TYPE_P (t))
947 /* See also shadow_tag. */
949 struct pending_inline **p;
951 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
953 /* Wipe out memory of synthesized methods */
954 TYPE_HAS_CONSTRUCTOR (t) = 0;
955 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
956 TYPE_HAS_INIT_REF (t) = 0;
957 TYPE_HAS_CONST_INIT_REF (t) = 0;
958 TYPE_HAS_ASSIGN_REF (t) = 0;
959 TYPE_HAS_ASSIGNMENT (t) = 0;
960 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
962 q = &TYPE_METHODS (t);
965 if (DECL_ARTIFICIAL (*q))
966 *q = TREE_CHAIN (*q);
968 q = &TREE_CHAIN (*q);
970 if (TYPE_METHODS (t))
971 error ("an anonymous union cannot have function members");
973 p = &pending_inlines;
974 for (; *p; *p = (*p)->next)
975 if (DECL_CONTEXT ((*p)->fndecl) != t)
978 else if (TREE_CODE (t) == ENUMERAL_TYPE)
979 x = grok_enum_decls (NULL_TREE);
986 if (t != void_type_node)
987 error ("empty component declaration");
992 /* There may or may not be any enum decls to grok, but
993 grok_enum_decls will just return components, if there aren't
994 any. We used to try to figure out whether or not there were
995 any enum decls based on the type of components, but that's too
996 hard; it might be something like `enum { a } *p;'. */
997 return grok_enum_decls (components);
1000 /* Constructors for types with virtual baseclasses need an "in-charge" flag
1001 saying whether this constructor is responsible for initialization of
1002 virtual baseclasses or not. All destructors also need this "in-charge"
1003 flag, which additionally determines whether or not the destructor should
1004 free the memory for the object.
1006 This function adds the "in-charge" flag to member function FN if
1007 appropriate. It is called from grokclassfn and tsubst.
1008 FN must be either a constructor or destructor. */
1011 maybe_retrofit_in_chrg (fn)
1014 tree basetype, arg_types, parms, parm, fntype;
1016 if (DECL_CONSTRUCTOR_P (fn)
1017 && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CLASS_CONTEXT (fn))
1018 && ! DECL_CONSTRUCTOR_FOR_VBASE_P (fn))
1020 else if (! DECL_CONSTRUCTOR_P (fn)
1021 && TREE_CHAIN (DECL_ARGUMENTS (fn)) == NULL_TREE)
1026 if (DECL_CONSTRUCTOR_P (fn))
1027 DECL_CONSTRUCTOR_FOR_VBASE_P (fn) = 1;
1029 /* First add it to DECL_ARGUMENTS... */
1030 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
1031 /* Mark the artificial `__in_chrg' parameter as "artificial". */
1032 SET_DECL_ARTIFICIAL (parm);
1033 DECL_ARG_TYPE (parm) = integer_type_node;
1034 TREE_READONLY (parm) = 1;
1035 parms = DECL_ARGUMENTS (fn);
1036 TREE_CHAIN (parm) = TREE_CHAIN (parms);
1037 TREE_CHAIN (parms) = parm;
1039 /* ...and then to TYPE_ARG_TYPES. */
1040 arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
1041 basetype = TREE_TYPE (TREE_VALUE (arg_types));
1042 arg_types = hash_tree_chain (integer_type_node, TREE_CHAIN (arg_types));
1043 fntype = build_cplus_method_type (basetype, TREE_TYPE (TREE_TYPE (fn)),
1045 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
1046 fntype = build_exception_variant (fntype,
1047 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)));
1048 TREE_TYPE (fn) = fntype;
1051 /* Classes overload their constituent function names automatically.
1052 When a function name is declared in a record structure,
1053 its name is changed to it overloaded name. Since names for
1054 constructors and destructors can conflict, we place a leading
1055 '$' for destructors.
1057 CNAME is the name of the class we are grokking for.
1059 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
1061 FLAGS contains bits saying what's special about today's
1062 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
1064 If FUNCTION is a destructor, then we must add the `auto-delete' field
1065 as a second parameter. There is some hair associated with the fact
1066 that we must "declare" this variable in the manner consistent with the
1067 way the rest of the arguments were declared.
1069 QUALS are the qualifiers for the this pointer. */
1072 grokclassfn (ctype, cname, function, flags, quals)
1073 tree ctype, cname, function;
1074 enum overload_flags flags;
1077 tree fn_name = DECL_NAME (function);
1082 if (fn_name == NULL_TREE)
1084 error ("name missing for member function");
1085 fn_name = get_identifier ("<anonymous>");
1086 DECL_NAME (function) = fn_name;
1090 qualtype = grok_method_quals (ctype, function, quals);
1094 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
1095 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1097 /* Must add the class instance variable up front. */
1098 /* Right now we just make this a pointer. But later
1099 we may wish to make it special. */
1100 tree type = TREE_VALUE (arg_types);
1103 if ((flag_this_is_variable > 0)
1104 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
1107 parm = build_decl (PARM_DECL, this_identifier, type);
1108 /* Mark the artificial `this' parameter as "artificial". */
1109 SET_DECL_ARTIFICIAL (parm);
1110 DECL_ARG_TYPE (parm) = type;
1111 /* We can make this a register, so long as we don't
1112 accidentally complain if someone tries to take its address. */
1113 DECL_REGISTER (parm) = 1;
1115 TREE_READONLY (parm) = 1;
1116 TREE_CHAIN (parm) = last_function_parms;
1117 last_function_parms = parm;
1120 DECL_ARGUMENTS (function) = last_function_parms;
1121 /* First approximations. */
1122 DECL_CONTEXT (function) = ctype;
1123 DECL_CLASS_CONTEXT (function) = ctype;
1125 if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
1127 maybe_retrofit_in_chrg (function);
1128 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
1131 if (flags == DTOR_FLAG)
1133 DECL_ASSEMBLER_NAME (function) = build_destructor_name (ctype);
1134 TYPE_HAS_DESTRUCTOR (ctype) = 1;
1138 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
1139 /* Only true for static member functions. */
1140 arg_types = hash_tree_chain (build_pointer_type (qualtype),
1143 DECL_ASSEMBLER_NAME (function)
1144 = build_decl_overload (fn_name, arg_types,
1145 1 + DECL_CONSTRUCTOR_P (function));
1149 /* Work on the expr used by alignof (this is only called by the parser). */
1158 if (processing_template_decl)
1159 return build_min (ALIGNOF_EXPR, sizetype, expr);
1161 if (TREE_CODE (expr) == COMPONENT_REF
1162 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
1163 error ("`__alignof__' applied to a bit-field");
1165 if (TREE_CODE (expr) == INDIRECT_REF)
1167 best = t = TREE_OPERAND (expr, 0);
1168 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1170 while (TREE_CODE (t) == NOP_EXPR
1171 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1174 t = TREE_OPERAND (t, 0);
1175 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1176 if (thisalign > bestalign)
1177 best = t, bestalign = thisalign;
1179 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1183 /* ANSI says arrays and fns are converted inside comma.
1184 But we can't convert them in build_compound_expr
1185 because that would break commas in lvalues.
1186 So do the conversion here if operand was a comma. */
1187 if (TREE_CODE (expr) == COMPOUND_EXPR
1188 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1189 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1190 expr = default_conversion (expr);
1191 return c_alignof (TREE_TYPE (expr));
1195 /* Create an ARRAY_REF, checking for the user doing things backwards
1199 grok_array_decl (array_expr, index_exp)
1200 tree array_expr, index_exp;
1202 tree type = TREE_TYPE (array_expr);
1203 tree p1, p2, i1, i2;
1205 if (type == error_mark_node || index_exp == error_mark_node)
1206 return error_mark_node;
1207 if (processing_template_decl)
1208 return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE,
1209 array_expr, index_exp);
1211 if (type == NULL_TREE)
1213 /* Something has gone very wrong. Assume we are mistakenly reducing
1214 an expression instead of a declaration. */
1215 error ("parser may be lost: is there a '{' missing somewhere?");
1219 if (TREE_CODE (type) == OFFSET_TYPE
1220 || TREE_CODE (type) == REFERENCE_TYPE)
1221 type = TREE_TYPE (type);
1223 /* If they have an `operator[]', use that. */
1224 if (IS_AGGR_TYPE (type) || IS_AGGR_TYPE (TREE_TYPE (index_exp)))
1225 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1226 array_expr, index_exp, NULL_TREE);
1228 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1230 if (TREE_CODE (type) == ARRAY_TYPE)
1233 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1235 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1238 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1240 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1241 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1243 if ((p1 && i2) && (i1 && p2))
1244 error ("ambiguous conversion for array subscript");
1247 array_expr = p1, index_exp = i2;
1249 array_expr = p2, index_exp = i1;
1252 cp_error ("invalid types `%T[%T]' for array subscript",
1253 type, TREE_TYPE (index_exp));
1254 return error_mark_node;
1257 if (array_expr == error_mark_node || index_exp == error_mark_node)
1258 error ("ambiguous conversion for array subscript");
1260 return build_array_ref (array_expr, index_exp);
1263 /* Given the cast expression EXP, checking out its validity. Either return
1264 an error_mark_node if there was an unavoidable error, return a cast to
1265 void for trying to delete a pointer w/ the value 0, or return the
1266 call to delete. If DOING_VEC is 1, we handle things differently
1267 for doing an array delete. If DOING_VEC is 2, they gave us the
1268 array size as an argument to delete.
1269 Implements ARM $5.3.4. This is called from the parser. */
1272 delete_sanity (exp, size, doing_vec, use_global_delete)
1274 int doing_vec, use_global_delete;
1277 /* For a regular vector delete (aka, no size argument) we will pass
1278 this down as a NULL_TREE into build_vec_delete. */
1279 tree maxindex = NULL_TREE;
1281 if (exp == error_mark_node)
1284 if (processing_template_decl)
1286 t = build_min (DELETE_EXPR, void_type_node, exp, size);
1287 DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
1288 DELETE_EXPR_USE_VEC (t) = doing_vec;
1292 if (TREE_CODE (exp) == OFFSET_REF)
1293 exp = resolve_offset_ref (exp);
1294 exp = convert_from_reference (exp);
1295 t = stabilize_reference (exp);
1296 t = build_expr_type_conversion (WANT_POINTER, t, 1);
1298 if (t == NULL_TREE || t == error_mark_node)
1300 cp_error ("type `%#T' argument given to `delete', expected pointer",
1302 return error_mark_node;
1307 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1308 pedwarn ("anachronistic use of array size in vector delete");
1311 type = TREE_TYPE (t);
1313 /* As of Valley Forge, you can delete a pointer to const. */
1315 /* You can't delete functions. */
1316 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1318 error ("cannot delete a function");
1319 return error_mark_node;
1322 /* An array can't have been allocated by new, so complain. */
1323 if (TREE_CODE (t) == ADDR_EXPR
1324 && TREE_CODE (TREE_OPERAND (t, 0)) == VAR_DECL
1325 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == ARRAY_TYPE)
1326 cp_warning ("deleting array `%#D'", TREE_OPERAND (t, 0));
1328 /* Deleting a pointer with the value zero is valid and has no effect. */
1329 if (integer_zerop (t))
1330 return build1 (NOP_EXPR, void_type_node, t);
1333 return build_vec_delete (t, maxindex, integer_one_node,
1334 integer_two_node, use_global_delete);
1337 if (IS_AGGR_TYPE (TREE_TYPE (type))
1338 && TYPE_GETS_REG_DELETE (TREE_TYPE (type)))
1340 /* Only do access checking here; we'll be calling op delete
1341 from the destructor. */
1342 tree tmp = build_op_delete_call (DELETE_EXPR, t, size_zero_node,
1343 LOOKUP_NORMAL, NULL_TREE);
1344 if (tmp == error_mark_node)
1345 return error_mark_node;
1348 return build_delete (type, t, integer_three_node,
1349 LOOKUP_NORMAL, use_global_delete);
1353 /* Report an error if the indicated template declaration is not the
1354 sort of thing that should be a member template. */
1357 check_member_template (tmpl)
1362 my_friendly_assert (TREE_CODE (tmpl) == TEMPLATE_DECL, 0);
1363 decl = DECL_TEMPLATE_RESULT (tmpl);
1365 if (TREE_CODE (decl) == FUNCTION_DECL
1366 || (TREE_CODE (decl) == TYPE_DECL
1367 && IS_AGGR_TYPE (TREE_TYPE (decl))))
1369 if (current_function_decl)
1370 /* 14.5.2.2 [temp.mem]
1372 A local class shall not have member templates. */
1373 cp_error ("declaration of member template `%#D' in local class",
1376 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
1378 /* 14.5.2.3 [temp.mem]
1380 A member function template shall not be virtual. */
1382 ("invalid use of `virtual' in template declaration of `%#D'",
1384 DECL_VIRTUAL_P (decl) = 0;
1387 /* The debug-information generating code doesn't know what to do
1388 with member templates. */
1389 DECL_IGNORED_P (tmpl) = 1;
1392 cp_error ("template declaration of `%#D'", decl);
1395 /* Return true iff TYPE is a valid Java parameter or return type. */
1398 acceptable_java_type (type)
1401 if (TREE_CODE (type) == VOID_TYPE || TYPE_FOR_JAVA (type))
1403 if (TREE_CODE (type) == POINTER_TYPE)
1405 type = TREE_TYPE (type);
1406 if (TREE_CODE (type) == RECORD_TYPE)
1408 complete_type (type);
1409 return TYPE_FOR_JAVA (type);
1415 /* For a METHOD in a Java class CTYPE, return 1 if
1416 the parameter and return types are valid Java types.
1417 Otherwise, print appropriate error messages, and return 0. */
1420 check_java_method (ctype, method)
1424 tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
1425 tree ret_type = TREE_TYPE (TREE_TYPE (method));
1426 if (! acceptable_java_type (ret_type))
1428 cp_error ("Java method '%D' has non-Java return type `%T'",
1432 for (; arg_types != NULL_TREE; arg_types = TREE_CHAIN (arg_types))
1434 tree type = TREE_VALUE (arg_types);
1435 if (! acceptable_java_type (type))
1437 cp_error ("Java method '%D' has non-Java parameter type `%T'",
1442 return jerr ? 0 : 1;
1445 /* Sanity check: report error if this function FUNCTION is not
1446 really a member of the class (CTYPE) it is supposed to belong to.
1447 CNAME is the same here as it is for grokclassfn above. */
1450 check_classfn (ctype, function)
1451 tree ctype, function;
1453 tree fn_name = DECL_NAME (function);
1454 tree fndecl, fndecls;
1455 tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype));
1458 tree templates = NULL_TREE;
1460 if (method_vec != 0)
1462 methods = &TREE_VEC_ELT (method_vec, 0);
1463 end = TREE_VEC_END (method_vec);
1465 /* First suss out ctors and dtors. */
1466 if (*methods && fn_name == DECL_NAME (OVL_CURRENT (*methods))
1467 && DECL_CONSTRUCTOR_P (function))
1469 if (*++methods && fn_name == DECL_NAME (OVL_CURRENT (*methods))
1470 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)))
1473 while (++methods != end)
1476 if (fn_name == DECL_NAME (OVL_CURRENT (*methods)))
1479 for (fndecls = *methods; fndecls != NULL_TREE;
1480 fndecls = OVL_NEXT (fndecls))
1482 fndecl = OVL_CURRENT (fndecls);
1483 /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL is
1484 not mangled, so the check below does not work
1485 correctly in that case. */
1486 if (TREE_CODE (function) != TEMPLATE_DECL
1487 && TREE_CODE (fndecl) != TEMPLATE_DECL
1488 && (DECL_ASSEMBLER_NAME (function)
1489 == DECL_ASSEMBLER_NAME (fndecl)))
1492 /* We cannot simply call decls_match because this
1493 doesn't work for static member functions that are
1494 pretending to be methods, and because the name
1495 may have been changed by asm("new_name"). */
1496 if (DECL_NAME (function) == DECL_NAME (fndecl))
1498 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1499 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1501 /* Get rid of the this parameter on functions that become
1503 if (DECL_STATIC_FUNCTION_P (fndecl)
1504 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1505 p1 = TREE_CHAIN (p1);
1507 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1508 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1509 && compparms (p1, p2, 3)
1510 && (DECL_TEMPLATE_SPECIALIZATION (function)
1511 == DECL_TEMPLATE_SPECIALIZATION (fndecl))
1512 && (!DECL_TEMPLATE_SPECIALIZATION (function)
1513 || (DECL_TI_TEMPLATE (function)
1514 == DECL_TI_TEMPLATE (fndecl))))
1517 if (is_member_template (fndecl))
1518 /* This function might be an instantiation
1519 or specialization of fndecl. */
1521 scratch_tree_cons (NULL_TREE, fndecl, templates);
1526 else if (TREE_CODE (fndecl) == TEMPLATE_DECL
1527 && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl))
1528 && IDENTIFIER_TYPENAME_P (fn_name))
1529 /* The method in the class is a member template
1530 conversion operator. We are declaring another
1531 conversion operator. It is possible that even though
1532 the names don't match, there is some specialization
1535 scratch_tree_cons (NULL_TREE, fndecl, templates);
1540 /* This function might be an instantiation or a specialization.
1541 We should verify that this is possible. If it is, we must
1542 somehow add the new declaration to the method vector for the
1543 class. Perhaps we should use add_method? For now, we simply
1544 return NULL_TREE, which lets the caller know that this
1545 function is new, but we don't print an error message. */
1550 tree fndecl = *methods;
1551 cp_error ("prototype for `%#D' does not match any in class `%T'",
1553 cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl) ? "s are" : " is",
1554 OVL_CURRENT (fndecl));
1555 while (fndecl = OVL_NEXT (fndecl), fndecl)
1556 cp_error_at (" %#D", OVL_CURRENT(fndecl));
1561 cp_error ("no `%#D' member function declared in class `%T'",
1565 /* If we did not find the method in the class, add it to avoid
1567 add_method (ctype, methods, function);
1571 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1572 of a structure component, returning a FIELD_DECL node.
1573 QUALS is a list of type qualifiers for this decl (such as for declaring
1574 const member functions).
1576 This is done during the parsing of the struct declaration.
1577 The FIELD_DECL nodes are chained together and the lot of them
1578 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1582 If class A defines that certain functions in class B are friends, then
1583 the way I have set things up, it is B who is interested in permission
1584 granted by A. However, it is in A's context that these declarations
1585 are parsed. By returning a void_type_node, class A does not attempt
1586 to incorporate the declarations of the friends within its structure.
1588 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1589 CHANGES TO CODE IN `start_method'. */
1592 grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
1593 tree declarator, declspecs, init, asmspec_tree, attrlist;
1595 register tree value;
1597 int flags = LOOKUP_ONLYCONVERTING;
1599 /* Convert () initializers to = initializers. */
1600 if (init == NULL_TREE && declarator != NULL_TREE
1601 && TREE_CODE (declarator) == CALL_EXPR
1602 && TREE_OPERAND (declarator, 0)
1603 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1604 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1605 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1607 init = TREE_OPERAND (declarator, 1);
1608 declarator = TREE_OPERAND (declarator, 0);
1612 if (declspecs == NULL_TREE
1613 && TREE_CODE (declarator) == SCOPE_REF
1614 && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE)
1616 /* Access declaration */
1617 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0))))
1619 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
1620 pop_nested_class (1);
1621 return do_class_using_decl (declarator);
1625 && TREE_CODE (init) == TREE_LIST
1626 && TREE_VALUE (init) == error_mark_node
1627 && TREE_CHAIN (init) == NULL_TREE)
1630 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, NULL_TREE);
1632 return value; /* friend or constructor went bad. */
1634 /* Pass friendly classes back. */
1635 if (TREE_CODE (value) == VOID_TYPE)
1636 return void_type_node;
1638 if (DECL_NAME (value) != NULL_TREE
1639 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1640 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1641 cp_error ("member `%D' conflicts with virtual function table field name",
1644 /* Stash away type declarations. */
1645 if (TREE_CODE (value) == TYPE_DECL)
1647 DECL_NONLOCAL (value) = 1;
1648 DECL_CONTEXT (value) = current_class_type;
1649 DECL_CLASS_CONTEXT (value) = current_class_type;
1650 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1652 /* Now that we've updated the context, we need to remangle the
1653 name for this TYPE_DECL. */
1654 DECL_ASSEMBLER_NAME (value) = DECL_NAME (value);
1655 DECL_ASSEMBLER_NAME (value) =
1656 get_identifier (build_overload_name (TREE_TYPE (value), 1, 1));
1658 pushdecl_class_level (value);
1662 if (IS_SIGNATURE (current_class_type)
1663 && TREE_CODE (value) != FUNCTION_DECL)
1665 error ("field declaration not allowed in signature");
1666 return void_type_node;
1669 if (DECL_IN_AGGR_P (value))
1671 cp_error ("`%D' is already defined in the class %T", value,
1672 DECL_CONTEXT (value));
1673 return void_type_node;
1677 asmspec = TREE_STRING_POINTER (asmspec_tree);
1681 if (IS_SIGNATURE (current_class_type)
1682 && TREE_CODE (value) == FUNCTION_DECL)
1684 error ("function declarations cannot have initializers in signature");
1687 else if (TREE_CODE (value) == FUNCTION_DECL)
1689 grok_function_init (value, init);
1692 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1693 /* Already complained in grokdeclarator. */
1697 /* We allow initializers to become parameters to base
1699 if (TREE_CODE (init) == TREE_LIST)
1701 if (TREE_CHAIN (init) == NULL_TREE)
1702 init = TREE_VALUE (init);
1704 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1707 if (TREE_CODE (init) == CONST_DECL)
1708 init = DECL_INITIAL (init);
1709 else if (TREE_READONLY_DECL_P (init))
1710 init = decl_constant_value (init);
1711 else if (TREE_CODE (init) == CONSTRUCTOR)
1712 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1713 my_friendly_assert (TREE_PERMANENT (init), 192);
1714 if (init == error_mark_node)
1715 /* We must make this look different than `error_mark_node'
1716 because `decl_const_value' would mis-interpret it
1717 as only meaning that this VAR_DECL is defined. */
1718 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1719 else if (processing_template_decl)
1721 else if (! TREE_CONSTANT (init))
1723 /* We can allow references to things that are effectively
1724 static, since references are initialized with the address. */
1725 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1726 || (TREE_STATIC (init) == 0
1727 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1728 || DECL_EXTERNAL (init) == 0)))
1730 error ("field initializer is not constant");
1731 init = error_mark_node;
1737 /* The corresponding pop_obstacks is in cp_finish_decl. */
1738 push_obstacks_nochange ();
1740 if (processing_template_decl && ! current_function_decl
1741 && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
1742 value = push_template_decl (value);
1745 cplus_decl_attributes (value, TREE_PURPOSE (attrlist),
1746 TREE_VALUE (attrlist));
1748 if (TREE_CODE (value) == VAR_DECL)
1750 my_friendly_assert (TREE_PUBLIC (value), 0);
1752 /* We cannot call pushdecl here, because that would
1753 fill in the value of our TREE_CHAIN. Instead, we
1754 modify cp_finish_decl to do the right thing, namely, to
1755 put this decl out straight away. */
1756 /* current_class_type can be NULL_TREE in case of error. */
1757 if (asmspec == 0 && current_class_type)
1759 TREE_PUBLIC (value) = 1;
1760 DECL_INITIAL (value) = error_mark_node;
1761 DECL_ASSEMBLER_NAME (value)
1762 = build_static_name (current_class_type, DECL_NAME (value));
1764 if (! processing_template_decl)
1765 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1767 /* Static consts need not be initialized in the class definition. */
1768 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1770 static int explanation = 0;
1772 error ("initializer invalid for static member with constructor");
1773 if (explanation++ == 0)
1774 error ("(you really want to initialize it separately)");
1777 /* Force the compiler to know when an uninitialized static
1778 const member is being used. */
1779 if (TYPE_READONLY (value) && init == 0)
1780 TREE_USED (value) = 1;
1781 DECL_INITIAL (value) = init;
1782 DECL_IN_AGGR_P (value) = 1;
1783 DECL_CONTEXT (value) = current_class_type;
1784 DECL_CLASS_CONTEXT (value) = current_class_type;
1786 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1787 pushdecl_class_level (value);
1790 if (TREE_CODE (value) == FIELD_DECL)
1794 /* This must override the asm specifier which was placed
1795 by grokclassfn. Lay this out fresh. */
1796 DECL_RTL (value) = NULL_RTX;
1797 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1799 if (DECL_INITIAL (value) == error_mark_node)
1800 init = error_mark_node;
1801 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1802 DECL_INITIAL (value) = init;
1803 DECL_IN_AGGR_P (value) = 1;
1806 if (TREE_CODE (value) == FUNCTION_DECL)
1810 /* This must override the asm specifier which was placed
1811 by grokclassfn. Lay this out fresh. */
1812 DECL_RTL (value) = NULL_RTX;
1813 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1815 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1817 /* Pass friends back this way. */
1818 if (DECL_FRIEND_P (value))
1819 return void_type_node;
1821 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1822 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1823 cp_error ("method `%#D' of local class must be defined in class body",
1827 DECL_IN_AGGR_P (value) = 1;
1830 my_friendly_abort (21);
1835 /* Like `grokfield', but for bitfields.
1836 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1839 grokbitfield (declarator, declspecs, width)
1840 tree declarator, declspecs, width;
1842 register tree value = grokdeclarator (declarator, declspecs, BITFIELD,
1845 if (! value) return NULL_TREE; /* friends went bad. */
1847 /* Pass friendly classes back. */
1848 if (TREE_CODE (value) == VOID_TYPE)
1849 return void_type_node;
1851 if (TREE_CODE (value) == TYPE_DECL)
1853 cp_error ("cannot declare `%D' to be a bitfield type", value);
1857 if (IS_SIGNATURE (current_class_type))
1859 error ("field declaration not allowed in signature");
1860 return void_type_node;
1863 if (DECL_IN_AGGR_P (value))
1865 cp_error ("`%D' is already defined in the class %T", value,
1866 DECL_CONTEXT (value));
1867 return void_type_node;
1870 GNU_xref_member (current_class_name, value);
1872 if (TREE_STATIC (value))
1874 cp_error ("static member `%D' cannot be a bitfield", value);
1877 cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1879 if (width != error_mark_node)
1881 constant_expression_warning (width);
1882 DECL_INITIAL (value) = width;
1883 DECL_BIT_FIELD (value) = 1;
1886 DECL_IN_AGGR_P (value) = 1;
1891 grokoptypename (declspecs, declarator)
1892 tree declspecs, declarator;
1894 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1895 return build_typename_overload (t);
1898 /* When a function is declared with an initializer,
1899 do the right thing. Currently, there are two possibilities:
1904 // initialization possibility #1.
1905 virtual void f () = 0;
1927 // initialization possibility #2
1934 copy_assignment_arg_p (parmtype, virtualp)
1938 if (current_class_type == NULL_TREE)
1941 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1942 parmtype = TREE_TYPE (parmtype);
1944 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1946 /* Non-standard hack to support old Booch components. */
1947 || (! virtualp && DERIVED_FROM_P (parmtype, current_class_type))
1956 grok_function_init (decl, init)
1960 /* An initializer for a function tells how this function should
1962 tree type = TREE_TYPE (decl);
1964 if (TREE_CODE (type) == FUNCTION_TYPE)
1965 cp_error ("initializer specified for non-member function `%D'", decl);
1967 /* We'll check for this in finish_struct_1. */
1968 else if (DECL_VINDEX (decl) == NULL_TREE)
1969 cp_error ("initializer specified for non-virtual method `%D'", decl);
1971 else if (integer_zerop (init))
1974 /* Mark this function as being "defined". */
1975 DECL_INITIAL (decl) = error_mark_node;
1976 /* pure virtual destructors must be defined. */
1977 /* pure virtual needs to be defined (as abort) only when put in
1978 vtbl. For wellformed call, it should be itself. pr4737 */
1979 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1981 extern tree abort_fndecl;
1982 /* Give this node rtl from `abort'. */
1983 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1986 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1987 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1990 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1992 if (copy_assignment_arg_p (parmtype, 1))
1993 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1997 cp_error ("invalid initializer for virtual method `%D'", decl);
2001 cplus_decl_attributes (decl, attributes, prefix_attributes)
2002 tree decl, attributes, prefix_attributes;
2004 if (decl == NULL_TREE || decl == void_type_node)
2007 if (TREE_CODE (decl) == TEMPLATE_DECL)
2008 decl = DECL_TEMPLATE_RESULT (decl);
2010 decl_attributes (decl, attributes, prefix_attributes);
2012 if (TREE_CODE (decl) == TYPE_DECL)
2013 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl));
2016 /* CONSTRUCTOR_NAME:
2017 Return the name for the constructor (or destructor) for the
2018 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2019 IDENTIFIER_NODE. When given a template, this routine doesn't
2020 lose the specialization. */
2023 constructor_name_full (thing)
2026 if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM
2027 || TREE_CODE (thing) == TEMPLATE_TEMPLATE_PARM
2028 || TREE_CODE (thing) == TYPENAME_TYPE)
2029 thing = TYPE_NAME (thing);
2030 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
2032 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
2033 thing = DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0)));
2035 thing = TYPE_NAME (thing);
2037 if (TREE_CODE (thing) == TYPE_DECL
2038 || (TREE_CODE (thing) == TEMPLATE_DECL
2039 && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL))
2040 thing = DECL_NAME (thing);
2041 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
2045 /* CONSTRUCTOR_NAME:
2046 Return the name for the constructor (or destructor) for the
2047 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2048 IDENTIFIER_NODE. When given a template, return the plain
2049 unspecialized name. */
2052 constructor_name (thing)
2056 thing = constructor_name_full (thing);
2057 t = IDENTIFIER_TEMPLATE (thing);
2063 /* Cache the value of this class's main virtual function table pointer
2064 in a register variable. This will save one indirection if a
2065 more than one virtual function call is made this function. */
2070 extern tree base_init_expr;
2072 if (base_init_expr == 0
2073 && DECL_CONSTRUCTOR_P (current_function_decl))
2075 if (processing_template_decl)
2076 add_tree (build_min_nt
2078 current_member_init_list, current_base_init_list));
2080 emit_base_init (current_class_type, 0);
2084 /* Record the existence of an addressable inline function. */
2087 mark_inline_for_output (decl)
2090 decl = DECL_MAIN_VARIANT (decl);
2091 if (DECL_SAVED_INLINE (decl))
2093 my_friendly_assert (TREE_PERMANENT (decl), 363);
2094 DECL_SAVED_INLINE (decl) = 1;
2096 if (DECL_PENDING_INLINE_INFO (decl) != 0
2097 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
2099 struct pending_inline *t = pending_inlines;
2100 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
2103 if (t == DECL_PENDING_INLINE_INFO (decl))
2109 t = DECL_PENDING_INLINE_INFO (decl);
2110 t->next = pending_inlines;
2111 pending_inlines = t;
2113 DECL_PENDING_INLINE_INFO (decl) = 0;
2116 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
2122 temp_name_counter = 0;
2125 /* Hand off a unique name which can be used for variable we don't really
2126 want to know about anyway, for example, the anonymous variables which
2127 are needed to make references work. Declare this thing so we can use it.
2128 The variable created will be of type TYPE.
2130 STATICP is nonzero if this variable should be static. */
2133 get_temp_name (type, staticp)
2137 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
2139 int toplev = toplevel_bindings_p ();
2141 push_obstacks_nochange ();
2142 if (toplev || staticp)
2144 end_temporary_allocation ();
2145 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
2146 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
2150 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
2151 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
2153 TREE_USED (decl) = 1;
2154 TREE_STATIC (decl) = staticp;
2155 DECL_ARTIFICIAL (decl) = 1;
2157 /* If this is a local variable, then lay out its rtl now.
2158 Otherwise, callers of this function are responsible for dealing
2159 with this variable's rtl. */
2163 expand_decl_init (decl);
2170 /* Get a variable which we can use for multiple assignments.
2171 It is not entered into current_binding_level, because
2172 that breaks things when it comes time to do final cleanups
2173 (which take place "outside" the binding contour of the function). */
2176 get_temp_regvar (type, init)
2181 decl = build_decl (VAR_DECL, NULL_TREE, type);
2182 TREE_USED (decl) = 1;
2183 DECL_REGISTER (decl) = 1;
2184 DECL_ARTIFICIAL (decl) = 1;
2186 DECL_RTL (decl) = assign_temp (type, 2, 0, 1);
2187 /* We can expand these without fear, since they cannot need
2188 constructors or destructors. */
2189 expand_expr (build_modify_expr (decl, INIT_EXPR, init),
2190 NULL_RTX, VOIDmode, 0);
2195 /* Hunts through the global anonymous union ANON_DECL, building
2196 appropriate VAR_DECLs. Stores cleanups on the list of ELEMS, and
2197 returns a VAR_DECL whose size is the same as the size of the
2198 ANON_DECL, if one is available. */
2201 build_anon_union_vars (anon_decl, elems, static_p, external_p)
2207 tree type = TREE_TYPE (anon_decl);
2208 tree main_decl = NULL_TREE;
2211 for (field = TYPE_FIELDS (type);
2213 field = TREE_CHAIN (field))
2216 if (TREE_CODE (field) != FIELD_DECL)
2219 if (TREE_PRIVATE (field))
2220 cp_pedwarn_at ("private member `%#D' in anonymous union", field);
2221 else if (TREE_PROTECTED (field))
2222 cp_pedwarn_at ("protected member `%#D' in anonymous union", field);
2224 if (DECL_NAME (field) == NULL_TREE
2225 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
2227 decl = build_anon_union_vars (field, elems, static_p, external_p);
2233 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2234 /* tell `pushdecl' that this is not tentative. */
2235 DECL_INITIAL (decl) = error_mark_node;
2236 TREE_PUBLIC (decl) = 0;
2237 TREE_STATIC (decl) = static_p;
2238 DECL_EXTERNAL (decl) = external_p;
2239 decl = pushdecl (decl);
2240 DECL_INITIAL (decl) = NULL_TREE;
2243 /* Only write out one anon union element--choose the one that
2244 can hold them all. */
2245 if (main_decl == NULL_TREE
2246 && simple_cst_equal (DECL_SIZE (decl),
2247 DECL_SIZE (anon_decl)) == 1)
2250 /* ??? This causes there to be no debug info written out
2252 TREE_ASM_WRITTEN (decl) = 1;
2254 if (DECL_NAME (field) == NULL_TREE
2255 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
2256 /* The remainder of the processing was already done in the
2260 /* If there's a cleanup to do, it belongs in the
2261 TREE_PURPOSE of the following TREE_LIST. */
2262 *elems = scratch_tree_cons (NULL_TREE, decl, *elems);
2263 TREE_TYPE (*elems) = type;
2269 /* Finish off the processing of a UNION_TYPE structure.
2270 If there are static members, then all members are
2271 static, and must be laid out together. If the
2272 union is an anonymous union, we arrange for that
2273 as well. PUBLIC_P is nonzero if this union is
2274 not declared static. */
2277 finish_anon_union (anon_union_decl)
2278 tree anon_union_decl;
2280 tree type = TREE_TYPE (anon_union_decl);
2281 tree elems = NULL_TREE;
2283 int public_p = TREE_PUBLIC (anon_union_decl);
2284 int static_p = TREE_STATIC (anon_union_decl);
2285 int external_p = DECL_EXTERNAL (anon_union_decl);
2287 if (TYPE_FIELDS (type) == NULL_TREE)
2292 error ("global anonymous unions must be declared static");
2296 main_decl = build_anon_union_vars (anon_union_decl, &elems,
2297 static_p, external_p);
2303 make_decl_rtl (main_decl, 0, toplevel_bindings_p ());
2304 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2308 warning ("anonymous union with no members");
2313 /* The following call assumes that there are never any cleanups
2314 for anonymous unions--a reasonable assumption. */
2315 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2318 /* Finish processing a builtin type TYPE. It's name is NAME,
2319 its fields are in the array FIELDS. LEN is the number of elements
2320 in FIELDS minus one, or put another way, it is the maximum subscript
2323 It is given the same alignment as ALIGN_TYPE. */
2326 finish_builtin_type (type, name, fields, len, align_type)
2335 TYPE_FIELDS (type) = fields[0];
2336 for (i = 0; i < len; i++)
2338 layout_type (TREE_TYPE (fields[i]));
2339 DECL_FIELD_CONTEXT (fields[i]) = type;
2340 TREE_CHAIN (fields[i]) = fields[i+1];
2342 DECL_FIELD_CONTEXT (fields[i]) = type;
2343 DECL_CLASS_CONTEXT (fields[i]) = type;
2344 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2346 #if 0 /* not yet, should get fixed properly later */
2347 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2349 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2351 TYPE_STUB_DECL (type) = TYPE_NAME (type);
2352 layout_decl (TYPE_NAME (type), 0);
2355 /* Auxiliary functions to make type signatures for
2356 `operator new' and `operator delete' correspond to
2357 what compiler will be expecting. */
2360 coerce_new_type (type)
2365 if (TREE_CODE (type) == METHOD_TYPE)
2366 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2367 if (TREE_TYPE (type) != ptr_type_node)
2368 e1 = 1, error ("`operator new' must return type `void *'");
2370 /* Technically the type must be `size_t', but we may not know
2372 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2373 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2374 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2375 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2376 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2378 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2380 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2385 coerce_delete_type (type)
2392 tree arg_types = TYPE_ARG_TYPES (type);
2394 if (TREE_CODE (type) == METHOD_TYPE)
2396 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2397 arg_types = TREE_CHAIN (arg_types);
2400 if (TREE_TYPE (type) != void_type_node)
2401 e1 = 1, error ("`operator delete' must return type `void'");
2403 if (arg_types == NULL_TREE
2404 || TREE_VALUE (arg_types) != ptr_type_node)
2405 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2409 && TREE_CHAIN (arg_types)
2410 && TREE_CHAIN (arg_types) != void_list_node)
2412 /* Again, technically this argument must be `size_t', but again
2413 we may not know what that is. */
2414 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2415 if (TREE_CODE (t2) != INTEGER_TYPE
2416 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2417 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2418 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2421 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2422 error ("too many arguments in declaration of `operator delete'");
2424 error ("`...' invalid in specification of `operator delete'");
2429 arg_types = tree_cons (NULL_TREE, ptr_type_node,
2430 build_tree_list (NULL_TREE, sizetype));
2433 if (arg_types == NULL_TREE)
2434 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2436 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2442 arg_types = tree_cons (NULL_TREE, ptr_type_node,
2443 arg_types ? TREE_CHAIN (arg_types): NULL_TREE);
2445 type = build_function_type (void_type_node, arg_types);
2450 extern tree abort_fndecl;
2453 mark_vtable_entries (decl)
2456 tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
2460 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries))
2461 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2462 tree fn = TREE_OPERAND (fnaddr, 0);
2463 TREE_ADDRESSABLE (fn) = 1;
2466 skip_rtti_stuff (&entries);
2468 for (; entries; entries = TREE_CHAIN (entries))
2470 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries)
2471 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2472 tree fn = TREE_OPERAND (fnaddr, 0);
2473 TREE_ADDRESSABLE (fn) = 1;
2474 if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn))
2476 TREE_OPERAND (fnaddr, 0) = fn = copy_node (fn);
2477 DECL_RTL (fn) = DECL_RTL (abort_fndecl);
2478 mark_used (abort_fndecl);
2480 if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn))
2482 DECL_EXTERNAL (fn) = 0;
2489 /* Set DECL up to have the closest approximation of "initialized common"
2490 linkage available. */
2493 comdat_linkage (decl)
2497 make_decl_one_only (decl);
2499 TREE_PUBLIC (decl) = 0;
2501 if (DECL_LANG_SPECIFIC (decl))
2502 DECL_COMDAT (decl) = 1;
2505 /* For win32 we also want to put explicit instantiations in
2506 linkonce sections, so that they will be merged with implicit
2507 instantiations; otherwise we get duplicate symbol errors. */
2510 maybe_make_one_only (decl)
2513 /* This is not necessary on targets that support weak symbols, because
2514 the implicit instantiations will defer to the explicit one. */
2515 if (! supports_one_only () || SUPPORTS_WEAK)
2518 /* We can't set DECL_COMDAT on functions, or finish_file will think
2519 we can get away with not emitting them if they aren't used.
2520 We can't use make_decl_one_only for variables, because their
2521 DECL_INITIAL may not have been set properly yet. */
2523 if (TREE_CODE (decl) == FUNCTION_DECL)
2524 make_decl_one_only (decl);
2526 comdat_linkage (decl);
2529 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2530 based on TYPE and other static flags.
2532 Note that anything public is tagged TREE_PUBLIC, whether
2533 it's public in this file or in another one. */
2536 import_export_vtable (decl, type, final)
2540 if (DECL_INTERFACE_KNOWN (decl))
2544 if (write_virtuals < 2 && write_virtuals != 0)
2546 TREE_PUBLIC (decl) = 1;
2547 if (write_virtuals < 0)
2548 DECL_EXTERNAL (decl) = 1;
2549 DECL_INTERFACE_KNOWN (decl) = 1;
2551 else if (CLASSTYPE_INTERFACE_KNOWN (type))
2553 TREE_PUBLIC (decl) = 1;
2554 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2555 DECL_INTERFACE_KNOWN (decl) = 1;
2557 /* For WIN32 we also want to put explicit instantiations in
2558 linkonce sections. */
2559 if (CLASSTYPE_EXPLICIT_INSTANTIATION (type))
2560 maybe_make_one_only (decl);
2564 /* We can only wait to decide if we have real non-inline virtual
2565 functions in our class, or if we come from a template. */
2567 int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2569 #ifndef MULTIPLE_SYMBOL_SPACES
2570 if (! found && ! final)
2573 for (method = TYPE_METHODS (type); method != NULL_TREE;
2574 method = TREE_CHAIN (method))
2575 if (DECL_VINDEX (method) != NULL_TREE
2576 && ! DECL_THIS_INLINE (method)
2577 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2585 if (final || ! found)
2587 comdat_linkage (decl);
2588 DECL_EXTERNAL (decl) = 0;
2592 TREE_PUBLIC (decl) = 1;
2593 DECL_EXTERNAL (decl) = 1;
2599 import_export_template (type)
2602 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2603 && ! flag_implicit_templates
2604 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2606 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2607 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2608 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2613 finish_prevtable_vardecl (prev, vars)
2616 tree ctype = DECL_CONTEXT (vars);
2617 import_export_template (ctype);
2619 #ifndef MULTIPLE_SYMBOL_SPACES
2620 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype)
2621 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2624 for (method = TYPE_METHODS (ctype); method != NULL_TREE;
2625 method = TREE_CHAIN (method))
2627 if (DECL_VINDEX (method) != NULL_TREE
2628 && !DECL_THIS_INLINE (method)
2629 && !DECL_ABSTRACT_VIRTUAL_P (method))
2631 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2632 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
2633 = ! DECL_REALLY_EXTERN (method);
2634 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_REALLY_EXTERN (method);
2641 import_export_vtable (vars, ctype, 1);
2646 finish_vtable_vardecl (prev, vars)
2649 if (write_virtuals >= 0
2650 && ! DECL_EXTERNAL (vars)
2651 && ((TREE_PUBLIC (vars) && ! DECL_WEAK (vars) && ! DECL_ONE_ONLY (vars))
2652 || CLASSTYPE_EXPLICIT_INSTANTIATION (DECL_CONTEXT (vars))
2653 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))
2654 || (hack_decl_function_context (vars) && TREE_USED (vars)))
2655 && ! TREE_ASM_WRITTEN (vars))
2658 mark_vtable_entries (vars);
2659 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2660 store_init_value (vars, DECL_INITIAL (vars));
2662 if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG)
2664 /* Mark the VAR_DECL node representing the vtable itself as a
2665 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2666 It is rather important that such things be ignored because
2667 any effort to actually generate DWARF for them will run
2668 into trouble when/if we encounter code like:
2671 struct S { virtual void member (); };
2673 because the artificial declaration of the vtable itself (as
2674 manufactured by the g++ front end) will say that the vtable
2675 is a static member of `S' but only *after* the debug output
2676 for the definition of `S' has already been output. This causes
2677 grief because the DWARF entry for the definition of the vtable
2678 will try to refer back to an earlier *declaration* of the
2679 vtable as a static member of `S' and there won't be one.
2680 We might be able to arrange to have the "vtable static member"
2681 attached to the member list for `S' before the debug info for
2682 `S' get written (which would solve the problem) but that would
2683 require more intrusive changes to the g++ front end. */
2685 DECL_IGNORED_P (vars) = 1;
2688 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2691 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2692 /* We don't know what to do with this one yet. */
2695 /* We know that PREV must be non-zero here. */
2696 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2701 prune_vtable_vardecl (prev, vars)
2704 /* We know that PREV must be non-zero here. */
2705 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2710 walk_vtables (typedecl_fn, vardecl_fn)
2711 register void (*typedecl_fn) PROTO ((tree, tree));
2712 register int (*vardecl_fn) PROTO ((tree, tree));
2717 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2719 register tree type = TREE_TYPE (vars);
2721 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2724 flag |= (*vardecl_fn) (prev, vars);
2726 if (prev && TREE_CHAIN (prev) != vars)
2729 else if (TREE_CODE (vars) == TYPE_DECL
2730 && type != error_mark_node
2731 && TYPE_LANG_SPECIFIC (type)
2732 && CLASSTYPE_VSIZE (type))
2734 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2744 finish_sigtable_vardecl (prev, vars)
2747 /* We don't need to mark sigtable entries as addressable here as is done
2748 for vtables. Since sigtables, unlike vtables, are always written out,
2749 that was already done in build_signature_table_constructor. */
2751 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2753 /* We know that PREV must be non-zero here. */
2754 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2758 walk_sigtables (typedecl_fn, vardecl_fn)
2759 register void (*typedecl_fn) PROTO((tree, tree));
2760 register void (*vardecl_fn) PROTO((tree, tree));
2764 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2766 register tree type = TREE_TYPE (vars);
2768 if (TREE_CODE (vars) == TYPE_DECL
2769 && type != error_mark_node
2770 && IS_SIGNATURE (type))
2772 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2774 else if (TREE_CODE (vars) == VAR_DECL
2775 && TREE_TYPE (vars) != error_mark_node
2776 && IS_SIGNATURE (TREE_TYPE (vars)))
2778 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2785 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2786 inline function or template instantiation at end-of-file. */
2789 import_export_decl (decl)
2792 if (DECL_INTERFACE_KNOWN (decl))
2795 if (DECL_TEMPLATE_INSTANTIATION (decl))
2797 DECL_NOT_REALLY_EXTERN (decl) = 1;
2798 if (DECL_IMPLICIT_INSTANTIATION (decl)
2799 && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2801 if (!TREE_PUBLIC (decl))
2802 /* Templates are allowed to have internal linkage. See
2805 else if (TREE_CODE (decl) == FUNCTION_DECL)
2806 comdat_linkage (decl);
2808 DECL_COMDAT (decl) = 1;
2811 DECL_NOT_REALLY_EXTERN (decl) = 0;
2813 else if (DECL_FUNCTION_MEMBER_P (decl))
2815 tree ctype = DECL_CLASS_CONTEXT (decl);
2816 if (CLASSTYPE_INTERFACE_KNOWN (ctype)
2817 && (! DECL_ARTIFICIAL (decl) || DECL_VINDEX (decl)))
2819 DECL_NOT_REALLY_EXTERN (decl)
2820 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2821 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2824 comdat_linkage (decl);
2826 /* tinfo function */
2827 else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2829 tree ctype = TREE_TYPE (DECL_NAME (decl));
2830 if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2831 && TYPE_VIRTUAL_P (ctype))
2833 /* If the type is a cv-qualified variant of a type, then we
2834 must emit the tinfo function in this translation unit
2835 since it will not be emitted when the vtable for the type
2836 is output (which is when the unqualified version is
2838 DECL_NOT_REALLY_EXTERN (decl)
2839 = TYPE_READONLY (ctype)
2840 || TYPE_VOLATILE (ctype)
2841 || ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2842 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2844 /* For WIN32 we also want to put explicit instantiations in
2845 linkonce sections. */
2846 if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype))
2847 maybe_make_one_only (decl);
2849 else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2850 DECL_NOT_REALLY_EXTERN (decl) = 0;
2852 comdat_linkage (decl);
2855 comdat_linkage (decl);
2857 DECL_INTERFACE_KNOWN (decl) = 1;
2861 build_cleanup (decl)
2865 tree type = TREE_TYPE (decl);
2867 if (TREE_CODE (type) == ARRAY_TYPE)
2871 mark_addressable (decl);
2872 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2874 temp = build_delete (TREE_TYPE (temp), temp,
2876 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2880 extern int parse_time, varconst_time;
2881 extern tree pending_templates;
2882 extern tree maybe_templates;
2888 tree sname = get_id_2 ("__sn", base);
2889 /* For struct X foo __attribute__((weak)), there is a counter
2890 __snfoo. Since base is already an assembler name, sname should
2891 be globally unique */
2892 tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2895 push_obstacks_nochange ();
2896 end_temporary_allocation ();
2897 sentry = build_decl (VAR_DECL, sname, integer_type_node);
2898 TREE_PUBLIC (sentry) = 1;
2899 DECL_ARTIFICIAL (sentry) = 1;
2900 TREE_STATIC (sentry) = 1;
2901 TREE_USED (sentry) = 1;
2902 DECL_COMMON (sentry) = 1;
2903 pushdecl_top_level (sentry);
2904 cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2910 /* Start the process of running a particular set of global constructors
2911 or destructors. Subroutine of do_[cd]tors. */
2914 start_objects (method_type)
2919 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
2921 fnname = get_file_function_name (method_type);
2923 start_function (void_list_node,
2924 make_call_declarator (fnname, void_list_node, NULL_TREE,
2928 store_parm_decls ();
2932 expand_start_bindings (0);
2935 /* Finish the process of running a particular set of global constructors
2936 or destructors. Subroutine of do_[cd]tors. */
2939 finish_objects (method_type)
2944 tree list = (method_type == 'I' ? static_ctors : static_dtors);
2946 if (! current_function_decl && list)
2947 start_objects (method_type);
2949 for (; list; list = TREE_CHAIN (list))
2950 expand_expr_stmt (build_function_call (TREE_VALUE (list), NULL_TREE));
2952 if (! current_function_decl)
2955 fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2958 expand_end_bindings (getdecls (), 1, 0);
2961 finish_function (lineno, 0, 0);
2963 if (method_type == 'I')
2964 assemble_constructor (fnname);
2966 assemble_destructor (fnname);
2969 /* Generate a function to run a set of global destructors. Subroutine of
2975 tree vars = static_aggregates;
2977 for (; vars; vars = TREE_CHAIN (vars))
2979 tree decl = TREE_VALUE (vars);
2980 tree type = TREE_TYPE (decl);
2983 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
2984 && ! DECL_EXTERNAL (decl))
2986 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2987 || DECL_ONE_ONLY (decl)
2988 || DECL_WEAK (decl)));
2990 if (! current_function_decl)
2991 start_objects ('D');
2993 temp = build_cleanup (decl);
2997 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2998 sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
2999 sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
3000 expand_start_cond (sentry, 0);
3003 expand_expr_stmt (temp);
3010 finish_objects ('D');
3013 /* Generate a function to run a set of global constructors. Subroutine of
3019 tree vars = static_aggregates;
3021 /* Reverse the list so it's in the right order for ctors. */
3022 vars = nreverse (vars);
3024 for (; vars; vars = TREE_CHAIN (vars))
3026 tree decl = TREE_VALUE (vars);
3027 tree init = TREE_PURPOSE (vars);
3029 /* If this was a static attribute within some function's scope,
3030 then don't initialize it here. Also, don't bother
3031 with initializers that contain errors. */
3032 if (TREE_STATIC (vars)
3033 || DECL_EXTERNAL (decl)
3034 || (init && TREE_CODE (init) == TREE_LIST
3035 && value_member (error_mark_node, init)))
3038 if (TREE_CODE (decl) == VAR_DECL)
3040 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
3041 || DECL_ONE_ONLY (decl)
3042 || DECL_WEAK (decl)));
3044 if (! current_function_decl)
3045 start_objects ('I');
3047 /* Set these global variables so that GDB at least puts
3048 us near the declaration which required the initialization. */
3049 input_filename = DECL_SOURCE_FILE (decl);
3050 lineno = DECL_SOURCE_LINE (decl);
3051 emit_note (input_filename, lineno);
3053 /* 9.5p5: The initializer of a static member of a class has
3054 the same access rights as a member function. */
3055 if (member_p (decl))
3057 DECL_CLASS_CONTEXT (current_function_decl)
3058 = DECL_CONTEXT (decl);
3059 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
3064 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
3065 sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
3066 sentry = build_binary_op
3067 (EQ_EXPR, sentry, integer_one_node, 1);
3068 expand_start_cond (sentry, 0);
3071 expand_start_target_temps ();
3073 if (IS_AGGR_TYPE (TREE_TYPE (decl))
3074 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
3075 expand_aggr_init (decl, init, 0, 0);
3076 else if (TREE_CODE (init) == TREE_VEC)
3078 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
3079 TREE_VEC_ELT (init, 1),
3080 TREE_VEC_ELT (init, 2), 0),
3081 const0_rtx, VOIDmode, EXPAND_NORMAL);
3084 expand_assignment (decl, init, 0, 0);
3086 /* The expression might have involved increments and
3090 /* Cleanup any temporaries needed for the initial value. */
3091 expand_end_target_temps ();
3096 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
3097 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
3099 else if (decl == error_mark_node)
3102 my_friendly_abort (22);
3105 finish_objects ('I');
3108 /* This routine is called from the last rule in yyparse ().
3109 Its job is to create all the code needed to initialize and
3110 destroy the global aggregates. We do the destruction
3111 first, since that way we only need to reverse the decls once. */
3117 int start_time, this_time;
3121 int needs_cleaning = 0, needs_messing_up = 0;
3125 /* Bad parse errors. Just forget about it. */
3126 if (! global_bindings_p () || current_class_type)
3129 check_decl_namespace ();
3131 start_time = get_run_time ();
3133 /* Otherwise, GDB can get confused, because in only knows
3134 about source for LINENO-1 lines. */
3137 interface_unknown = 1;
3140 for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
3142 tree srcloc = TREE_PURPOSE (fnname);
3143 tree decl = TREE_VALUE (fnname);
3145 input_filename = SRCLOC_FILE (srcloc);
3146 lineno = SRCLOC_LINE (srcloc);
3148 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
3150 instantiate_class_template (decl);
3151 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
3152 for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
3153 if (! DECL_ARTIFICIAL (vars))
3154 instantiate_decl (vars);
3157 instantiate_decl (decl);
3160 for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
3162 tree args, fn, decl = TREE_VALUE (fnname);
3164 if (DECL_INITIAL (decl))
3167 fn = TREE_PURPOSE (fnname);
3168 args = get_bindings (fn, decl, NULL_TREE);
3169 fn = instantiate_template (fn, args);
3170 instantiate_decl (fn);
3173 cat_namespace_levels();
3175 /* Push into C language context, because that's all
3177 push_lang_context (lang_name_c);
3180 /* The reason for pushing garbage onto the global_binding_level is to
3181 ensure that we can slice out _DECLs which pertain to virtual function
3182 tables. If the last thing pushed onto the global_binding_level was a
3183 virtual function table, then slicing it out would slice away all the
3184 decls (i.e., we lose the head of the chain).
3186 There are several ways of getting the same effect, from changing the
3187 way that iterators over the chain treat the elements that pertain to
3188 virtual function tables, moving the implementation of this code to
3189 decl.c (where we can manipulate global_binding_level directly),
3190 popping the garbage after pushing it and slicing away the vtable
3191 stuff, or just leaving it alone. */
3193 /* Make last thing in global scope not be a virtual function table. */
3194 #if 0 /* not yet, should get fixed properly later */
3195 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
3197 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
3199 DECL_IGNORED_P (vars) = 1;
3200 SET_DECL_ARTIFICIAL (vars);
3204 /* Walk to mark the inline functions we need, then output them so
3205 that we can pick up any other tdecls that those routines need. */
3206 walk_vtables ((void (*) PROTO ((tree, tree))) 0,
3207 finish_prevtable_vardecl);
3209 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
3210 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
3211 rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
3212 vars = static_aggregates;
3214 if (static_ctors || vars)
3215 needs_messing_up = 1;
3216 if (static_dtors || vars)
3219 /* The aggregates are listed in reverse declaration order, for cleaning. */
3225 /* do_ctors will reverse the lists for messing up. */
3226 if (needs_messing_up)
3231 permanent_allocation (1);
3233 /* Done with C language context needs. */
3234 pop_lang_context ();
3236 /* Now write out any static class variables (which may have since
3237 learned how to be initialized). */
3238 while (pending_statics)
3240 tree decl = TREE_VALUE (pending_statics);
3242 /* Output DWARF debug information. */
3243 #ifdef DWARF_DEBUGGING_INFO
3244 if (write_symbols == DWARF_DEBUG)
3245 dwarfout_file_scope_decl (decl, 1);
3247 #ifdef DWARF2_DEBUGGING_INFO
3248 if (write_symbols == DWARF2_DEBUG)
3249 dwarf2out_decl (decl);
3252 DECL_DEFER_OUTPUT (decl) = 0;
3253 rest_of_decl_compilation
3254 (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3256 pending_statics = TREE_CHAIN (pending_statics);
3259 this_time = get_run_time ();
3260 parse_time -= this_time - start_time;
3261 varconst_time += this_time - start_time;
3263 start_time = get_run_time ();
3265 if (flag_handle_signatures)
3266 walk_sigtables ((void (*) PROTO ((tree, tree))) 0,
3267 finish_sigtable_vardecl);
3269 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3271 tree decl = TREE_VALUE (fnname);
3272 import_export_decl (decl);
3275 mark_all_runtime_matches ();
3277 /* Now write out inline functions which had their addresses taken and
3278 which were not declared virtual and which were not declared `extern
3281 int reconsider = 1; /* More may be referenced; check again */
3285 tree *p = &saved_inlines;
3288 /* We need to do this each time so that newly completed template
3289 types don't wind up at the front of the list. Sigh. */
3290 vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3291 DECL_IGNORED_P (vars) = 1;
3292 SET_DECL_ARTIFICIAL (vars);
3295 reconsider |= walk_vtables ((void (*) PROTO((tree, tree))) 0,
3296 finish_vtable_vardecl);
3300 tree decl = TREE_VALUE (*p);
3302 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3304 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3306 if (DECL_MUTABLE_P (decl))
3307 synthesize_tinfo_fn (decl);
3309 synthesize_method (decl);
3313 /* Catch new template instantiations. */
3314 if (decl != TREE_VALUE (*p))
3317 if (TREE_ASM_WRITTEN (decl)
3318 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3319 *p = TREE_CHAIN (*p);
3320 else if (DECL_INITIAL (decl) == 0)
3321 p = &TREE_CHAIN (*p);
3322 else if ((TREE_PUBLIC (decl) && ! DECL_COMDAT (decl))
3323 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3324 || flag_keep_inline_functions)
3326 if (DECL_NOT_REALLY_EXTERN (decl))
3328 DECL_EXTERNAL (decl) = 0;
3330 /* We can't inline this function after it's been
3331 emitted. We want a variant of
3332 output_inline_function that doesn't prevent
3333 subsequent integration... */
3334 DECL_INLINE (decl) = 0;
3335 output_inline_function (decl);
3336 permanent_allocation (1);
3339 *p = TREE_CHAIN (*p);
3342 p = &TREE_CHAIN (*p);
3346 /* It's possible that some of the remaining inlines will still be
3347 needed. For example, a static inline whose address is used in
3348 the initializer for a file-scope static variable will be
3349 needed. Code in compile_file will handle this, but we mustn't
3350 pretend that there are no definitions for the inlines, or it
3353 FIXME: This won't catch member functions. We should really
3354 unify this stuff with the compile_file stuff. */
3355 for (vars = saved_inlines; vars != NULL_TREE; vars = TREE_CHAIN (vars))
3357 tree decl = TREE_VALUE (vars);
3359 if (DECL_NOT_REALLY_EXTERN (decl)
3360 && !DECL_COMDAT (decl)
3361 && DECL_INITIAL (decl) != NULL_TREE)
3362 DECL_EXTERNAL (decl) = 0;
3366 /* Now delete from the chain of variables all virtual function tables.
3367 We output them all ourselves, because each will be treated specially. */
3369 walk_vtables ((void (*) PROTO((tree, tree))) 0,
3370 prune_vtable_vardecl);
3372 if (write_virtuals == 2)
3374 /* Now complain about an virtual function tables promised
3375 but not delivered. */
3376 while (pending_vtables)
3378 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3379 error ("virtual function table for `%s' not defined",
3380 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3381 pending_vtables = TREE_CHAIN (pending_vtables);
3387 this_time = get_run_time ();
3388 parse_time -= this_time - start_time;
3389 varconst_time += this_time - start_time;
3391 if (flag_detailed_statistics)
3393 dump_tree_statistics ();
3394 dump_time_statistics ();
3398 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3399 expr. Since it was parsed like a type, we need to wade through and fix
3400 that. Unfortunately, since operator() is left-associative, we can't use
3401 tail recursion. In the above example, TYPE is `A', and DECL is
3404 Maybe this shouldn't be recursive, but how often will it actually be
3408 reparse_absdcl_as_expr (type, decl)
3411 /* do build_functional_cast (type, NULL_TREE) at bottom */
3412 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3413 return build_functional_cast (type, NULL_TREE);
3416 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3418 decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3420 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3421 decl = require_complete_type (decl);
3426 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3427 out to be an expr. Since it was parsed like a type, we need to wade
3428 through and fix that. Since casts are right-associative, we are
3429 reversing the order, so we don't have to recurse.
3431 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3435 reparse_absdcl_as_casts (decl, expr)
3440 if (TREE_CODE (expr) == CONSTRUCTOR
3441 && TREE_TYPE (expr) == 0)
3443 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3444 decl = TREE_OPERAND (decl, 0);
3446 if (IS_SIGNATURE (type))
3448 error ("cast specifies signature type");
3449 return error_mark_node;
3452 expr = digest_init (type, expr, (tree *) 0);
3453 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3455 int failure = complete_array_type (type, expr, 1);
3457 my_friendly_abort (78);
3463 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3464 decl = TREE_OPERAND (decl, 0);
3465 expr = build_c_cast (type, expr);
3468 if (warn_old_style_cast)
3469 warning ("use of old-style cast");
3474 /* Given plain tree nodes for an expression, build up the full semantics. */
3477 build_expr_from_tree (t)
3480 if (t == NULL_TREE || t == error_mark_node)
3483 switch (TREE_CODE (t))
3485 case IDENTIFIER_NODE:
3486 return do_identifier (t, 0, NULL_TREE);
3489 if (LOOKUP_EXPR_GLOBAL (t))
3490 return do_scoped_id (TREE_OPERAND (t, 0), 0);
3492 return do_identifier (TREE_OPERAND (t, 0), 0, NULL_TREE);
3494 case TEMPLATE_ID_EXPR:
3495 return (lookup_template_function
3496 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3497 build_expr_from_tree (TREE_OPERAND (t, 1))));
3500 return build_x_indirect_ref
3501 (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3504 return build_functional_cast
3505 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3507 case REINTERPRET_CAST_EXPR:
3508 return build_reinterpret_cast
3509 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3511 case CONST_CAST_EXPR:
3512 return build_const_cast
3513 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3515 case DYNAMIC_CAST_EXPR:
3516 return build_dynamic_cast
3517 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3519 case STATIC_CAST_EXPR:
3520 return build_static_cast
3521 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3523 case PREDECREMENT_EXPR:
3524 case PREINCREMENT_EXPR:
3525 case POSTDECREMENT_EXPR:
3526 case POSTINCREMENT_EXPR:
3530 case TRUTH_NOT_EXPR:
3532 case CONVERT_EXPR: /* Unary + */
3535 return build_x_unary_op (TREE_CODE (t),
3536 build_expr_from_tree (TREE_OPERAND (t, 0)));
3541 case TRUNC_DIV_EXPR:
3543 case FLOOR_DIV_EXPR:
3544 case ROUND_DIV_EXPR:
3545 case EXACT_DIV_EXPR:
3547 case BIT_ANDTC_EXPR:
3550 case TRUNC_MOD_EXPR:
3551 case FLOOR_MOD_EXPR:
3552 case TRUTH_ANDIF_EXPR:
3553 case TRUTH_ORIF_EXPR:
3554 case TRUTH_AND_EXPR:
3569 return build_x_binary_op
3571 build_expr_from_tree (TREE_OPERAND (t, 0)),
3572 build_expr_from_tree (TREE_OPERAND (t, 1)));
3575 return build_m_component_ref
3576 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3577 build_expr_from_tree (TREE_OPERAND (t, 1)));
3580 return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3583 if (TREE_OPERAND (t, 0) == NULL_TREE)
3585 return build_parse_node (ARRAY_REF, NULL_TREE,
3586 build_expr_from_tree (TREE_OPERAND (t, 1)));
3587 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3588 build_expr_from_tree (TREE_OPERAND (t, 1)));
3593 tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3594 if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3596 return TREE_CODE (t) == SIZEOF_EXPR ? c_sizeof (r) : c_alignof (r);
3600 return build_x_modify_expr
3601 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3602 TREE_CODE (TREE_OPERAND (t, 1)),
3603 build_expr_from_tree (TREE_OPERAND (t, 2)));
3606 return build_x_arrow
3607 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3611 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3612 build_expr_from_tree (TREE_OPERAND (t, 1)),
3613 build_expr_from_tree (TREE_OPERAND (t, 2)),
3614 NEW_EXPR_USE_GLOBAL (t));
3617 return delete_sanity
3618 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3619 build_expr_from_tree (TREE_OPERAND (t, 1)),
3620 DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3623 if (TREE_OPERAND (t, 1) == NULL_TREE)
3624 return build_x_compound_expr
3625 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3627 my_friendly_abort (42);
3629 case METHOD_CALL_EXPR:
3630 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3632 tree ref = TREE_OPERAND (t, 0);
3633 return build_scoped_method_call
3634 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3635 build_expr_from_tree (TREE_OPERAND (ref, 0)),
3636 TREE_OPERAND (ref, 1),
3637 build_expr_from_tree (TREE_OPERAND (t, 2)));
3639 return build_method_call
3640 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3641 TREE_OPERAND (t, 0),
3642 build_expr_from_tree (TREE_OPERAND (t, 2)),
3643 NULL_TREE, LOOKUP_NORMAL);
3646 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3648 tree ref = TREE_OPERAND (t, 0);
3649 return build_member_call
3650 (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3651 TREE_OPERAND (ref, 1),
3652 build_expr_from_tree (TREE_OPERAND (t, 1)));
3656 tree name = TREE_OPERAND (t, 0);
3658 tree args = build_expr_from_tree (TREE_OPERAND (t, 1));
3659 if (args != NULL_TREE && TREE_CODE (name) == LOOKUP_EXPR
3660 && !LOOKUP_EXPR_GLOBAL (name)
3661 && TREE_CODE ((id = TREE_OPERAND (name, 0))) == IDENTIFIER_NODE
3662 && (!current_class_type
3663 || !lookup_member (current_class_type, id, 0, 0)))
3665 /* Do Koenig lookup if there are no class members. */
3666 name = do_identifier (id, 0, args);
3668 else if (TREE_CODE (name) == TEMPLATE_ID_EXPR
3669 || ! really_overloaded_fn (name))
3670 name = build_expr_from_tree (name);
3671 return build_x_function_call (name, args, current_class_ref);
3675 return build_x_conditional_expr
3676 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3677 build_expr_from_tree (TREE_OPERAND (t, 1)),
3678 build_expr_from_tree (TREE_OPERAND (t, 2)));
3682 tree purpose, value, chain;
3684 if (t == void_list_node)
3687 purpose = TREE_PURPOSE (t);
3689 purpose = build_expr_from_tree (purpose);
3690 value = TREE_VALUE (t);
3692 value = build_expr_from_tree (value);
3693 chain = TREE_CHAIN (t);
3694 if (chain && chain != void_type_node)
3695 chain = build_expr_from_tree (chain);
3696 return expr_tree_cons (purpose, value, chain);
3700 return build_x_component_ref
3701 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3702 TREE_OPERAND (t, 1), NULL_TREE, 1);
3705 return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3711 /* digest_init will do the wrong thing if we let it. */
3712 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
3715 r = build_nt (CONSTRUCTOR, NULL_TREE,
3716 build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3719 return digest_init (TREE_TYPE (t), r, 0);
3724 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
3725 return get_typeid (TREE_OPERAND (t, 0));
3726 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3729 return convert_from_reference (t);
3736 /* This is something of the form `int (*a)++' that has turned out to be an
3737 expr. It was only converted into parse nodes, so we need to go through
3738 and build up the semantics. Most of the work is done by
3739 build_expr_from_tree, above.
3741 In the above example, TYPE is `int' and DECL is `*a'. */
3744 reparse_decl_as_expr (type, decl)
3747 decl = build_expr_from_tree (decl);
3749 return build_functional_cast (type, build_expr_list (NULL_TREE, decl));
3754 /* This is something of the form `int (*a)' that has turned out to be a
3755 decl. It was only converted into parse nodes, so we need to do the
3756 checking that make_{pointer,reference}_declarator do. */
3759 finish_decl_parsing (decl)
3762 extern int current_class_depth;
3764 switch (TREE_CODE (decl))
3766 case IDENTIFIER_NODE:
3769 return make_pointer_declarator
3770 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3772 return make_reference_declarator
3773 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3775 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3778 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3779 TREE_COMPLEXITY (decl) = current_class_depth;
3782 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3785 my_friendly_abort (5);
3791 check_cp_case_value (value)
3794 if (value == NULL_TREE)
3797 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3798 STRIP_TYPE_NOPS (value);
3800 if (TREE_READONLY_DECL_P (value))
3802 value = decl_constant_value (value);
3803 STRIP_TYPE_NOPS (value);
3805 value = fold (value);
3807 if (TREE_CODE (value) != INTEGER_CST
3808 && value != error_mark_node)
3810 cp_error ("case label `%E' does not reduce to an integer constant",
3812 value = error_mark_node;
3815 /* Promote char or short to int. */
3816 value = default_conversion (value);
3818 constant_expression_warning (value);
3823 /* Return 1 if root encloses child. */
3826 is_namespace_ancestor (root, child)
3831 if (root == global_namespace)
3833 if (child == global_namespace)
3835 return is_namespace_ancestor (root, CP_DECL_CONTEXT (child));
3839 /* Return the namespace that is the common ancestor
3840 of two given namespaces. */
3843 namespace_ancestor (ns1, ns2)
3846 if (is_namespace_ancestor (ns1, ns2))
3848 return namespace_ancestor (DECL_CONTEXT (ns1), ns2);
3851 /* Insert used into the using list of user. Set indirect_flag if this
3852 directive is not directly from the source. Also find the common
3853 ancestor and let our users know about the new namespace */
3855 add_using_namespace (user, used, indirect)
3861 /* Using oneself is a no-op. */
3864 my_friendly_assert (TREE_CODE (user) == NAMESPACE_DECL, 380);
3865 my_friendly_assert (TREE_CODE (used) == NAMESPACE_DECL, 380);
3866 /* Check if we already have this. */
3867 if (purpose_member (used, DECL_NAMESPACE_USING (user)) != NULL_TREE)
3870 /* Add used to the user's using list. */
3871 DECL_NAMESPACE_USING (user)
3872 = perm_tree_cons (used, namespace_ancestor (user, used),
3873 DECL_NAMESPACE_USING (user));
3875 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user)) = indirect;
3877 /* Add user to the used's users list. */
3878 DECL_NAMESPACE_USERS (used)
3879 = perm_tree_cons (user, 0, DECL_NAMESPACE_USERS (used));
3881 for (iter = DECL_NAMESPACE_USERS (user); iter; iter = TREE_CHAIN (iter))
3882 /* indirect usage */
3883 add_using_namespace (TREE_PURPOSE (iter), used, 1);
3886 /* Combines two sets of overloaded functions into an OVERLOAD chain.
3887 The first list becomes the tail of the result. */
3890 merge_functions (s1, s2)
3894 if (TREE_CODE (s2) == OVERLOAD)
3897 s1 = build_overload (OVL_FUNCTION (s2), s1);
3898 s2 = OVL_CHAIN (s2);
3901 s1 = build_overload (s2, s1);
3905 /* This should return an error not all definitions define functions.
3906 It is not an error if we find two functions with exactly the
3907 same signature, only if these are selected in overload resolution.
3908 old is the current set of bindings, new the freshly-found binding.
3909 XXX Do we want to give *all* candidates in case of ambiguity?
3910 XXX In what way should I treat extern declarations?
3911 XXX I don't want to repeat the entire duplicate_decls here */
3914 ambiguous_decl (name, old, new)
3919 my_friendly_assert (old != NULL_TREE, 393);
3920 /* Copy the value. */
3921 if (!BINDING_VALUE (old))
3922 BINDING_VALUE (old) = BINDING_VALUE (new);
3923 else if (BINDING_VALUE (new)
3924 && BINDING_VALUE (new) != BINDING_VALUE (old))
3926 if (is_overloaded_fn (BINDING_VALUE (old))
3927 && is_overloaded_fn (BINDING_VALUE (new)))
3929 BINDING_VALUE (old) = merge_functions (BINDING_VALUE (old),
3930 BINDING_VALUE (new));
3934 /* Some declarations are functions, some are not. */
3935 cp_error ("ambiguous definition `%D' used", name);
3936 cp_error_at ("first definition here", BINDING_VALUE (old));
3937 cp_error_at ("other definition here", BINDING_VALUE (new));
3938 return error_mark_node;
3941 /* ... and copy the type. */
3942 if (!BINDING_TYPE (old))
3943 BINDING_TYPE (old) = BINDING_TYPE (new);
3944 else if(BINDING_TYPE (new)
3945 && BINDING_TYPE (old) != BINDING_TYPE (new))
3947 cp_error ("`%D' denotes an ambiguous type",name);
3948 cp_error_at ("first type here", BINDING_TYPE (old));
3949 cp_error_at ("other type here", BINDING_TYPE (new));
3954 /* Add the bindings of name in used namespaces to val.
3955 The using list is defined by usings, and the lookup goes to scope.
3956 Returns zero on errors. */
3959 lookup_using_namespace (name, val, usings, scope)
3960 tree name, val, usings, scope;
3964 /* Iterate over all used namespaces in current, searching for using
3965 directives of scope. */
3966 for (iter = usings; iter; iter = TREE_CHAIN (iter))
3967 if (TREE_VALUE (iter) == scope)
3969 val1 = binding_for_name (name, TREE_PURPOSE (iter));
3970 /* Resolve ambiguities. */
3971 val = ambiguous_decl (name, val, val1);
3973 return val != error_mark_node;
3977 Excepts the name to lookup and its qualifying scope.
3978 Returns the name/type pair found into the CPLUS_BINDING result,
3982 qualified_lookup_using_namespace (name, scope, result)
3987 /* Maintain a list of namespaces visited... */
3988 tree seen = NULL_TREE;
3989 /* ... and a list of namespace yet to see. */
3990 tree todo = NULL_TREE;
3992 while (scope && (result != error_mark_node))
3994 seen = temp_tree_cons (scope, NULL_TREE, seen);
3995 result = ambiguous_decl (name, result, binding_for_name (name, scope));
3996 if (!BINDING_VALUE (result) && !BINDING_TYPE (result))
3997 /* Consider using directives. */
3998 for (usings = DECL_NAMESPACE_USING (scope); usings;
3999 usings = TREE_CHAIN (usings))
4000 /* If this was a real directive, and we have not seen it. */
4001 if (!TREE_INDIRECT_USING (usings)
4002 && !purpose_member (TREE_PURPOSE (usings), seen))
4003 todo = temp_tree_cons (TREE_PURPOSE (usings), NULL_TREE, todo);
4006 scope = TREE_PURPOSE (todo);
4007 todo = TREE_CHAIN (todo);
4010 scope = NULL_TREE; /* If there never was a todo list. */
4012 return result != error_mark_node;
4015 /* [namespace.memdef]/2 */
4017 /* Set the context of a declaration to scope. Complain if we are not
4021 set_decl_namespace (decl, scope)
4026 if (scope == std_node)
4027 scope = global_namespace;
4028 /* Get rid of namespace aliases. */
4029 scope = ORIGINAL_NAMESPACE (scope);
4031 if (!is_namespace_ancestor (current_namespace, scope))
4032 cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
4034 DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
4035 if (scope != current_namespace)
4037 /* See whether this has been declared in the namespace. */
4038 old = namespace_binding (DECL_NAME (decl), scope);
4040 /* No old declaration at all. */
4042 if (!is_overloaded_fn (decl))
4043 /* Don't compare non-function decls with decls_match here,
4044 since it can't check for the correct constness at this
4045 point. pushdecl will find those errors later. */
4047 /* Since decl is a function, old should contain a function decl. */
4048 if (!is_overloaded_fn (old))
4050 for (; old; old = OVL_NEXT (old))
4051 if (decls_match (decl, OVL_CURRENT (old)))
4057 cp_error ("`%D' should have been declared inside `%D'",
4061 /* Compute the namespace where a declaration is defined. */
4064 decl_namespace (decl)
4067 while (DECL_CONTEXT (decl))
4069 decl = DECL_CONTEXT (decl);
4070 if (TREE_CODE (decl) == NAMESPACE_DECL)
4072 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
4073 decl = TYPE_STUB_DECL (decl);
4074 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', 390);
4077 return global_namespace;
4080 /* Return the namespace where the current declaration is declared. */
4083 current_decl_namespace ()
4086 /* If we have been pushed into a different namespace, use it. */
4087 if (decl_namespace_list)
4088 return TREE_PURPOSE (decl_namespace_list);
4090 if (current_class_type)
4091 if (CLASSTYPE_USE_TEMPLATE (current_class_type))
4092 result = decl_namespace (CLASSTYPE_TI_TEMPLATE (current_class_type));
4094 result = decl_namespace (TYPE_STUB_DECL (current_class_type));
4095 else if (current_function_decl)
4096 if (DECL_USE_TEMPLATE (current_function_decl))
4097 result = decl_namespace (DECL_TI_TEMPLATE (current_function_decl));
4099 result = decl_namespace (current_function_decl);
4101 result = current_namespace;
4105 /* Temporarily set the namespace for the current declaration. */
4108 push_decl_namespace (decl)
4111 if (TREE_CODE (decl) != NAMESPACE_DECL)
4112 decl = decl_namespace (decl);
4113 decl_namespace_list = tree_cons (decl, NULL_TREE, decl_namespace_list);
4117 pop_decl_namespace ()
4119 decl_namespace_list = TREE_CHAIN (decl_namespace_list);
4123 check_decl_namespace ()
4125 my_friendly_assert (decl_namespace_list == NULL_TREE, 980711);
4128 /* [basic.lookup.koenig] */
4129 /* A non-zero return value in the functions below indicates an error.
4130 All nodes allocated in the procedure are on the scratch obstack. */
4140 static int arg_assoc PROTO((struct arg_lookup*, tree));
4141 static int arg_assoc_args PROTO((struct arg_lookup*, tree));
4143 /* Add a function to the lookup structure. */
4146 add_function (k, fn)
4147 struct arg_lookup *k;
4150 if (ovl_member (fn, k->functions))
4152 k->functions = build_overload (fn, k->functions);
4156 /* Add functions of a namespace to the lookup structure. */
4159 arg_assoc_namespace (k, scope)
4160 struct arg_lookup *k;
4165 if (purpose_member (scope, k->namespaces))
4167 k->namespaces = tree_cons (scope, NULL_TREE, k->namespaces);
4169 value = namespace_binding (k->name, scope);
4173 if (!is_overloaded_fn (value))
4175 cp_error_at ("`%D' is not a function", value);
4176 cp_error ("in call to `%D'", k->name);
4180 for (; value; value = OVL_NEXT (value))
4181 if (add_function (k, OVL_CURRENT (value)))
4187 /* Adds everything associated with class to the lookup structure. */
4190 arg_assoc_class (k, type)
4191 struct arg_lookup* k;
4194 tree list, friends, context;
4197 if (purpose_member (type, k->classes))
4199 k->classes = tree_cons (type, NULL_TREE, k->classes);
4201 context = decl_namespace (TYPE_MAIN_DECL (type));
4202 if (arg_assoc_namespace (k, context))
4205 /* Process baseclasses. */
4206 for (i = 0; i < CLASSTYPE_N_BASECLASSES (type); i++)
4207 if (arg_assoc_class (k, TYPE_BINFO_BASETYPE (type, i)))
4210 /* Process friends. */
4211 for (list = DECL_FRIENDLIST (TYPE_MAIN_DECL (type)); list;
4212 list = TREE_CHAIN (list))
4213 if (k->name == TREE_PURPOSE (list))
4214 for (friends = TREE_VALUE (list); friends;
4215 friends = TREE_CHAIN (friends))
4216 /* Only interested in global functions with potentially hidden
4217 (i.e. unqualified) declarations. */
4218 if (TREE_PURPOSE (list) == error_mark_node && TREE_VALUE (list)
4219 && decl_namespace (TREE_VALUE (list)) == context)
4220 if (add_function (k, TREE_VALUE (list)))
4225 /* Adds everything associated with a given type. */
4228 arg_assoc_type (k, type)
4229 struct arg_lookup *k;
4232 switch (TREE_CODE (type))
4242 if (TYPE_PTRMEMFUNC_P (type))
4243 return arg_assoc_type (k, TYPE_PTRMEMFUNC_FN_TYPE (type));
4244 return arg_assoc_class (k, type);
4246 case REFERENCE_TYPE:
4248 return arg_assoc_type (k, TREE_TYPE (type));
4251 return arg_assoc_namespace (k, decl_namespace (TYPE_MAIN_DECL (type)));
4253 /* Pointer to member: associate class type and value type. */
4254 if (arg_assoc_type (k, TYPE_OFFSET_BASETYPE (type)))
4256 return arg_assoc_type (k, TREE_TYPE (type));
4258 /* Associate the class of the method. */
4259 if (arg_assoc_type (k, TYPE_METHOD_BASETYPE (type)))
4263 /* Associate the parameter types. */
4264 if (arg_assoc_args (k, TYPE_ARG_TYPES (type)))
4266 /* Associate the return type. */
4267 return arg_assoc_type (k, TREE_TYPE (type));
4269 if (type == unknown_type_node)
4271 /* else fall through */
4273 my_friendly_abort (390);
4278 /* Adds everything associated with arguments. */
4281 arg_assoc_args (k, args)
4282 struct arg_lookup* k;
4285 for (; args; args = TREE_CHAIN (args))
4286 if (arg_assoc (k, TREE_VALUE (args)))
4291 /* Adds everything associated with a given tree_node. */
4295 struct arg_lookup* k;
4298 switch (TREE_CODE_CLASS (TREE_CODE (n)))
4301 return arg_assoc_type (k, n);
4307 return arg_assoc_type (k, TREE_TYPE (n));
4309 switch (TREE_CODE (n))
4312 /* special processing */
4315 return arg_assoc_type (k, TREE_TYPE (n));
4322 switch (TREE_CODE (n))
4324 case CONST_DECL: /* 'd' */
4328 return arg_assoc_type (k, TREE_TYPE (n));
4329 case ADDR_EXPR: /* 'e' */
4330 /* We can't use the TREE_TYPE, as the type of an overloaded function
4331 will be useless here. */
4332 n = TREE_OPERAND (n, 0);
4334 case OVERLOAD: /* 'x' */
4335 if (arg_assoc (k, OVL_CURRENT (n)))
4339 case TREE_LIST: /* 'x' */
4340 /* XXX Overloaded member, should get an OVERLOAD directly, here. */
4343 case FUNCTION_DECL: /* 'd' */
4344 if (arg_assoc_args (k, FUNCTION_ARG_CHAIN (n)))
4346 if (DECL_FUNCTION_MEMBER_P (n))
4347 if (arg_assoc_type (k, DECL_CLASS_CONTEXT (n)))
4351 /* XXX Type of a function template in the context of Koenig lookup?
4352 Assume that template parameters are non-deduced for the moment. */
4353 n = DECL_RESULT (n);
4358 cp_error ("sorry, Koenig lookup for `%s' of type `%T' failed",
4359 tree_code_name [(int)TREE_CODE (n)], TREE_TYPE (n));
4360 my_friendly_abort (391);
4365 /* Performs Koenig lookup depending on arguments, where fns
4366 are the functions found in normal lookup. */
4369 lookup_arg_dependent (name, fns, args)
4374 struct arg_lookup k;
4377 k.namespaces = NULL_TREE;
4378 k.classes = NULL_TREE;
4380 push_scratch_obstack ();
4381 arg_assoc_args (&k, args);
4386 /* Process a namespace-alias declaration. */
4389 do_namespace_alias (alias, namespace)
4390 tree alias, namespace;
4395 if (TREE_CODE (namespace) != NAMESPACE_DECL)
4397 /* The parser did not find it, so it's not there. */
4398 cp_error ("unknown namespace `%D'", namespace);
4402 namespace = ORIGINAL_NAMESPACE (namespace);
4404 binding = binding_for_name (alias, current_namespace);
4405 old = BINDING_VALUE (binding);
4408 if (TREE_CODE (old) == NAMESPACE_DECL
4409 && DECL_NAMESPACE_ALIAS (old) == namespace)
4410 /* Ok: redeclaration. */
4412 cp_error ("invalid namespace alias `%D'", alias);
4413 cp_error_at ("`%D' previously declared here", old);
4417 /* Build the alias. */
4418 alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node);
4419 DECL_NAMESPACE_ALIAS (alias) = namespace;
4420 DECL_CONTEXT (alias) = FROB_CONTEXT (current_namespace);
4421 BINDING_VALUE (binding) = alias;
4425 /* Check a non-member using-declaration. Return the name and scope
4426 being used, and the USING_DECL, or NULL_TREE on failure. */
4429 validate_nonmember_using_decl (decl, scope, name)
4434 if (TREE_CODE (decl) == SCOPE_REF
4435 && TREE_OPERAND (decl, 0) == std_node)
4437 if (TREE_CODE (decl) == SCOPE_REF)
4439 *scope = TREE_OPERAND (decl, 0);
4440 *name = TREE_OPERAND (decl, 1);
4442 else if (TREE_CODE (decl) == IDENTIFIER_NODE
4443 || TREE_CODE (decl) == TYPE_DECL)
4445 *scope = global_namespace;
4449 my_friendly_abort (382);
4450 if (TREE_CODE_CLASS (TREE_CODE (*name)) == 'd')
4451 *name = DECL_NAME (*name);
4452 /* Make a USING_DECL. */
4453 return push_using_decl (*scope, *name);
4456 /* Process local and global using-declarations. */
4459 do_nonmember_using_decl (scope, name, oldval, oldtype, newval, newtype)
4461 tree oldval, oldtype;
4462 tree *newval, *newtype;
4465 struct tree_binding _decls;
4467 *newval = *newtype = NULL_TREE;
4468 decls = binding_init (&_decls);
4469 if (!qualified_lookup_using_namespace (name, scope, decls))
4473 if (!BINDING_VALUE (decls) && !BINDING_TYPE (decls))
4475 cp_error ("`%D' not declared", name);
4479 /* Check for using functions. */
4480 if (BINDING_VALUE (decls) && is_overloaded_fn (BINDING_VALUE (decls)))
4484 for (tmp = BINDING_VALUE (decls); tmp; tmp = OVL_NEXT (tmp))
4487 /* Compare each new function with each old one.
4488 If the old function was also used, there is no conflict. */
4489 for (tmp1 = oldval; tmp1; tmp1 = OVL_NEXT (tmp1))
4490 if (OVL_CURRENT (tmp) == OVL_CURRENT (tmp1))
4492 else if (OVL_USED (tmp1))
4494 else if (duplicate_decls (OVL_CURRENT (tmp), OVL_CURRENT (tmp1)))
4497 /* Duplicate use, ignore */
4501 *newval = build_overload (OVL_CURRENT (tmp), *newval);
4502 if (TREE_CODE (*newval) != OVERLOAD)
4503 *newval = ovl_cons (*newval, NULL_TREE);
4504 OVL_USED (*newval) = 1;
4509 *newval = BINDING_VALUE (decls);
4510 if (oldval && oldval != *newval && !duplicate_decls (*newval, oldval))
4514 *newtype = BINDING_TYPE (decls);
4515 if (oldtype && *newtype && oldtype != *newtype)
4517 cp_error ("using directive `%D' introduced ambiguous type `%T'",
4523 /* Process a using-declaration not appearing in class or local scope. */
4526 do_toplevel_using_decl (decl)
4529 tree scope, name, binding;
4530 tree oldval, oldtype, newval, newtype;
4532 decl = validate_nonmember_using_decl (decl, &scope, &name);
4533 if (decl == NULL_TREE)
4536 binding = binding_for_name (name, current_namespace);
4538 oldval = BINDING_VALUE (binding);
4539 oldtype = BINDING_TYPE (binding);
4541 do_nonmember_using_decl (scope, name, oldval, oldtype, &newval, &newtype);
4543 /* Copy declarations found. */
4545 BINDING_VALUE (binding) = newval;
4547 BINDING_TYPE (binding) = newtype;
4552 do_local_using_decl (decl)
4556 tree oldval, oldtype, newval, newtype;
4557 decl = validate_nonmember_using_decl (decl, &scope, &name);
4558 if (decl == NULL_TREE)
4561 /* XXX nested values */
4562 oldval = IDENTIFIER_LOCAL_VALUE (name);
4563 /* XXX get local type */
4564 oldtype = NULL_TREE;
4566 do_nonmember_using_decl (scope, name, oldval, oldtype, &newval, &newtype);
4569 /* XXX update bindings */
4570 IDENTIFIER_LOCAL_VALUE (name) = newval;
4575 do_class_using_decl (decl)
4580 if (TREE_CODE (decl) != SCOPE_REF
4581 || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (decl, 0))) != 't')
4583 cp_error ("using-declaration for non-member at class scope");
4586 name = TREE_OPERAND (decl, 1);
4587 if (TREE_CODE (name) == BIT_NOT_EXPR)
4589 cp_error ("using-declaration for destructor");
4593 value = build_lang_field_decl (USING_DECL, name, void_type_node);
4594 DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
4598 /* Process a using-directive. */
4601 do_using_directive (namespace)
4604 if (namespace == std_node)
4606 /* using namespace A::B::C; */
4607 if (TREE_CODE (namespace) == SCOPE_REF)
4608 namespace = TREE_OPERAND (namespace, 1);
4609 if (TREE_CODE (namespace) == IDENTIFIER_NODE)
4611 /* Lookup in lexer did not find a namespace. */
4612 cp_error ("namespace `%T' undeclared", namespace);
4615 if (TREE_CODE (namespace) != NAMESPACE_DECL)
4617 cp_error ("`%T' is not a namespace", namespace);
4620 namespace = ORIGINAL_NAMESPACE (namespace);
4621 if (!toplevel_bindings_p ())
4622 push_using_directive
4623 (namespace, namespace_ancestor (current_decl_namespace(),
4624 current_namespace));
4627 add_using_namespace (current_namespace, namespace, 0);
4631 check_default_args (x)
4634 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
4635 int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
4636 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
4638 if (TREE_PURPOSE (arg))
4642 cp_error_at ("default argument missing for parameter %P of `%+#D'",
4653 TREE_USED (decl) = 1;
4654 if (processing_template_decl)
4656 assemble_external (decl);
4657 /* Is it a synthesized method that needs to be synthesized? */
4658 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
4659 && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
4660 /* Kludge: don't synthesize for default args. */
4661 && current_function_decl)
4662 synthesize_method (decl);
4663 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
4664 instantiate_decl (decl);
4667 /* Helper function for named_class_head_sans_basetype nonterminal. */
4670 handle_class_head (aggr, scope, id)
4671 tree aggr, scope, id;
4673 if (TREE_CODE (id) == TYPE_DECL)
4677 cp_error ("`%T' does not have a nested type named `%D'", scope, id);
4679 cp_error ("no file-scope type named `%D'", id);
4682 (aggr, make_anon_name (), NULL_TREE, 1);
4683 return TYPE_MAIN_DECL (id);