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 grok_function_init PROTO((tree, tree));
56 static int finish_vtable_vardecl PROTO((tree, tree));
57 static int prune_vtable_vardecl PROTO((tree, tree));
58 static void finish_sigtable_vardecl PROTO((tree, tree));
59 static int is_namespace_ancestor PROTO((tree, tree));
60 static void add_using_namespace PROTO((tree, tree, int));
61 static tree ambiguous_decl PROTO((tree, tree, tree,int));
62 static tree build_anon_union_vars PROTO((tree, tree*, int, int));
63 static void check_decl_namespace PROTO((void));
65 extern int current_class_depth;
67 /* A list of virtual function tables we must make sure to write out. */
70 /* A list of static class variables. This is needed, because a
71 static class variable can be declared inside the class without
72 an initializer, and then initialized, staticly, outside the class. */
75 /* A list of functions which were declared inline, but which we
76 may need to emit outline anyway. */
77 static tree saved_inlines;
79 /* Used to help generate temporary names which are unique within
80 a function. Reset to 0 by start_function. */
82 int temp_name_counter;
84 /* Same, but not reset. Local temp variables and global temp variables
85 can have the same name. */
86 static int global_temp_name_counter;
88 /* Flag used when debugging spew.c */
90 extern int spew_debug;
92 /* Nonzero if we're done parsing and into end-of-file activities. */
96 /* Functions called along with real static constructors and destructors. */
98 tree static_ctors, static_dtors;
100 /* The current open namespace, and ::. */
102 tree current_namespace;
103 tree global_namespace;
105 /* The stack for namespaces of current declarations. */
107 static tree decl_namespace_list;
110 /* C (and C++) language-specific option variables. */
112 /* Nonzero means allow type mismatches in conditional expressions;
113 just make their values `void'. */
115 int flag_cond_mismatch;
117 /* Nonzero means give `double' the same size as `float'. */
119 int flag_short_double;
121 /* Nonzero means don't recognize the keyword `asm'. */
125 /* Nonzero means don't recognize any extension keywords. */
127 int flag_no_gnu_keywords;
129 /* Nonzero means don't recognize the non-ANSI builtin functions. */
133 /* Nonzero means don't recognize the non-ANSI builtin functions.
136 int flag_no_nonansi_builtin;
138 /* Nonzero means do some things the same way PCC does. Only provided so
139 the compiler will link. */
141 int flag_traditional;
143 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
145 int flag_signed_bitfields = 1;
147 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
151 /* Nonzero means enable obscure ANSI features and disable GNU extensions
152 that might cause ANSI-compliant code to be miscompiled. */
156 /* Nonzero means do emit exported implementations of functions even if
157 they can be inlined. */
159 int flag_implement_inlines = 1;
161 /* Nonzero means do emit exported implementations of templates, instead of
162 multiple static copies in each file that needs a definition. */
164 int flag_external_templates;
166 /* Nonzero means that the decision to emit or not emit the implementation of a
167 template depends on where the template is instantiated, rather than where
170 int flag_alt_external_templates;
172 /* Nonzero means that implicit instantiations will be emitted if needed. */
174 int flag_implicit_templates = 1;
176 /* Nonzero means allow numerical priorities on constructors. */
178 #ifdef USE_INIT_PRIORITY
179 int flag_init_priority = 1;
181 int flag_init_priority;
184 /* Nonzero means warn about implicit declarations. */
186 int warn_implicit = 1;
188 /* Nonzero means warn about usage of long long when `-pedantic'. */
190 int warn_long_long = 1;
192 /* Nonzero means warn when all ctors or dtors are private, and the class
195 int warn_ctor_dtor_privacy = 1;
197 /* True if we want to implement vtables using "thunks".
198 The default is off. */
200 #ifndef DEFAULT_VTABLE_THUNKS
201 #define DEFAULT_VTABLE_THUNKS 0
203 int flag_vtable_thunks = DEFAULT_VTABLE_THUNKS;
205 /* True if we want to deal with repository information. */
207 int flag_use_repository;
209 /* Nonzero if we want to issue diagnostics that the standard says are not
212 int flag_optional_diags = 1;
214 /* Nonzero means give string constants the type `const char *', as mandated
217 int flag_const_strings = 1;
219 /* Nonzero means warn about deprecated conversion from string constant to
222 int warn_write_strings;
224 /* Nonzero means warn about pointer casts that can drop a type qualifier
225 from the pointer target type. */
229 /* Nonzero means warn about sizeof(function) or addition/subtraction
230 of function pointers. */
232 int warn_pointer_arith = 1;
234 /* Nonzero means warn for any function def without prototype decl. */
236 int warn_missing_prototypes;
238 /* Nonzero means warn about multiple (redundant) decls for the same single
239 variable or function. */
241 int warn_redundant_decls;
243 /* Warn if initializer is not completely bracketed. */
245 int warn_missing_braces;
247 /* Warn about comparison of signed and unsigned values. */
249 int warn_sign_compare;
251 /* Warn about *printf or *scanf format/argument anomalies. */
255 /* Warn about a subscript that has type char. */
257 int warn_char_subscripts;
259 /* Warn if a type conversion is done that might have confusing results. */
263 /* Warn if adding () is suggested. */
265 int warn_parentheses;
267 /* Non-zero means warn in function declared in derived class has the
268 same name as a virtual in the base class, but fails to match the
269 type signature of any virtual function in the base class. */
270 int warn_overloaded_virtual;
272 /* Non-zero means warn when declaring a class that has a non virtual
273 destructor, when it really ought to have a virtual one. */
276 /* Non-zero means warn when a function is declared extern and later inline. */
277 int warn_extern_inline;
279 /* Non-zero means warn when the compiler will reorder code. */
282 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
285 /* Non-zero means warn when we convert a pointer to member function
286 into a pointer to (void or function). */
287 int warn_pmf2ptr = 1;
289 /* Nonzero means warn about violation of some Effective C++ style rules. */
293 /* Nonzero means warn where overload resolution chooses a promotion from
294 unsigned to signed over a conversion to an unsigned of the same size. */
298 /* Nonzero means warn when an old-style cast is used. */
300 int warn_old_style_cast;
302 /* Warn about #pragma directives that are not recognised. */
304 int warn_unknown_pragmas; /* Tri state variable. */
306 /* Nonzero means warn about use of multicharacter literals. */
308 int warn_multichar = 1;
310 /* Nonzero means `$' can be in an identifier. */
312 #ifndef DOLLARS_IN_IDENTIFIERS
313 #define DOLLARS_IN_IDENTIFIERS 1
315 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
317 /* Nonzero for -fno-strict-prototype switch: do not consider empty
318 argument prototype to mean function takes no arguments. */
320 int flag_strict_prototype = 2;
321 int strict_prototype = 1;
322 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
324 /* Nonzero means that labels can be used as first-class objects */
328 /* Non-zero means to collect statistics which might be expensive
329 and to print them when we are done. */
330 int flag_detailed_statistics;
332 /* C++ specific flags. */
333 /* Nonzero for -fall-virtual: make every member function (except
334 constructors) lay down in the virtual function table. Calls
335 can then either go through the virtual function table or not,
338 int flag_all_virtual;
340 /* Zero means that `this' is a *const. This gives nice behavior in the
341 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
342 -2 means we're constructing an object and it has fixed type. */
344 int flag_this_is_variable;
346 /* 3 means write out only virtuals function tables `defined'
347 in this implementation file.
348 0 means write out virtual function tables and give them
349 (C) static access (default). */
353 /* Nonzero means we should attempt to elide constructors when possible. */
355 int flag_elide_constructors = 1;
357 /* Nonzero means recognize and handle signature language constructs. */
359 int flag_handle_signatures;
361 /* Nonzero means that member functions defined in class scope are
362 inline by default. */
364 int flag_default_inline = 1;
366 /* Controls whether enums and ints freely convert.
367 1 means with complete freedom.
368 0 means enums can convert to ints, but not vice-versa. */
369 int flag_int_enum_equivalence;
371 /* Controls whether compiler generates 'type descriptor' that give
372 run-time type information. */
375 /* Nonzero if we wish to output cross-referencing information
376 for the GNU class browser. */
377 extern int flag_gnu_xref;
379 /* Nonzero if compiler can make `reasonable' assumptions about
380 references and objects. For example, the compiler must be
381 conservative about the following and not assume that `a' is nonnull:
386 In general, it is `reasonable' to assume that for many programs,
387 and better code can be generated in that case. */
389 int flag_assume_nonnull_objects = 1;
391 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
394 int flag_huge_objects;
396 /* Nonzero if we want to conserve space in the .o files. We do this
397 by putting uninitialized data and runtime initialized data into
398 .common instead of .data at the expense of not flagging multiple
401 int flag_conserve_space;
403 /* Nonzero if we want to obey access control semantics. */
405 int flag_access_control = 1;
407 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
409 int flag_operator_names;
411 /* Nonzero if we want to check the return value of new and avoid calling
412 constructors if it is a null pointer. */
416 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
417 initialization variables.
418 0: Old rules, set by -fno-for-scope.
419 2: New ANSI rules, set by -ffor-scope.
420 1: Try to implement new ANSI rules, but with backup compatibility
421 (and warnings). This is the default, for now. */
423 int flag_new_for_scope = 1;
425 /* Nonzero if we want to emit defined symbols with common-like linkage as
426 weak symbols where possible, in order to conform to C++ semantics.
427 Otherwise, emit them as local symbols. */
431 /* Nonzero to enable experimental ABI changes. */
435 /* Nonzero to not ignore namespace std. */
439 /* Maximum template instantiation depth. Must be at least 17 for ANSI
442 int max_tinst_depth = 17;
444 /* The name-mangling scheme to use. Must be 1 or greater to support
445 template functions with identical types, but different template
447 int name_mangling_version = 2;
449 /* Nonzero means that guiding declarations are allowed. */
450 int flag_guiding_decls;
452 /* Nonzero if squashed mangling is to be performed.
453 This uses the B and K codes to reference previously seen class types
454 and class qualifiers. */
455 int flag_do_squangling;
458 /* Table of language-dependent -f options.
459 STRING is the option name. VARIABLE is the address of the variable.
460 ON_VALUE is the value to store in VARIABLE
461 if `-fSTRING' is seen as an option.
462 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
464 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
466 {"signed-char", &flag_signed_char, 1},
467 {"unsigned-char", &flag_signed_char, 0},
468 {"signed-bitfields", &flag_signed_bitfields, 1},
469 {"unsigned-bitfields", &flag_signed_bitfields, 0},
470 {"short-enums", &flag_short_enums, 1},
471 {"short-double", &flag_short_double, 1},
472 {"cond-mismatch", &flag_cond_mismatch, 1},
473 {"squangle", &flag_do_squangling, 1},
474 {"asm", &flag_no_asm, 0},
475 {"builtin", &flag_no_builtin, 0},
476 {"ident", &flag_no_ident, 0},
477 {"labels-ok", &flag_labels_ok, 1},
478 {"const-strings", &flag_const_strings, 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 {"elide-constructors", &flag_elide_constructors, 1},
484 {"handle-exceptions", &flag_exceptions, 1},
485 {"handle-signatures", &flag_handle_signatures, 1},
486 {"default-inline", &flag_default_inline, 1},
487 {"dollars-in-identifiers", &dollars_in_ident, 1},
488 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
489 {"honor-std", &flag_honor_std, 1},
490 {"rtti", &flag_rtti, 1},
491 {"xref", &flag_gnu_xref, 1},
492 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
493 {"implement-inlines", &flag_implement_inlines, 1},
494 {"external-templates", &flag_external_templates, 1},
495 {"implicit-templates", &flag_implicit_templates, 1},
496 {"init-priority", &flag_init_priority, 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"))
538 else if (p[0] == '-' && p[1] == 'f')
540 /* Some kind of -f option.
541 P's value is the option sans `-f'.
542 Search for it in the table of options. */
547 /* Try special -f options. */
549 if (!strcmp (p, "handle-exceptions")
550 || !strcmp (p, "no-handle-exceptions"))
551 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
553 if (!strcmp (p, "memoize-lookups")
554 || !strcmp (p, "no-memoize-lookups")
555 || !strcmp (p, "save-memoized")
556 || !strcmp (p, "no-save-memoized"))
561 else if (! strcmp (p, "alt-external-templates"))
563 flag_external_templates = 1;
564 flag_alt_external_templates = 1;
567 else if (! strcmp (p, "no-alt-external-templates"))
569 flag_alt_external_templates = 0;
572 else if (!strcmp (p, "repo"))
574 flag_use_repository = 1;
575 flag_implicit_templates = 0;
578 else if (!strcmp (p, "guiding-decls"))
580 flag_guiding_decls = 1;
581 name_mangling_version = 0;
584 else if (!strcmp (p, "no-guiding-decls"))
586 flag_guiding_decls = 0;
589 else if (!strcmp (p, "ansi-overloading"))
591 else if (!strcmp (p, "no-ansi-overloading"))
593 error ("-fno-ansi-overloading is no longer supported");
596 else if (!strcmp (p, "new-abi"))
599 flag_do_squangling = 1;
601 flag_vtable_thunks = 1;
603 else if (!strcmp (p, "no-new-abi"))
606 flag_do_squangling = 0;
609 else if (!strncmp (p, "template-depth-", 15))
614 if (*endp >= '0' && *endp <= '9')
618 error ("Invalid option `%s'", p - 2);
619 goto template_depth_lose;
622 max_tinst_depth = atoi (p + 15);
623 template_depth_lose: ;
625 else if (!strncmp (p, "name-mangling-version-", 22))
630 if (*endp >= '0' && *endp <= '9')
634 error ("Invalid option `%s'", p - 2);
635 goto mangling_version_lose;
638 name_mangling_version = atoi (p + 22);
639 mangling_version_lose: ;
642 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
645 if (!strcmp (p, lang_f_options[j].string))
647 *lang_f_options[j].variable = lang_f_options[j].on_value;
648 /* A goto here would be cleaner,
649 but breaks the vax pcc. */
652 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
653 && ! strcmp (p+3, lang_f_options[j].string))
655 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
661 else if (p[0] == '-' && p[1] == 'W')
665 /* The -W options control the warning behavior of the compiler. */
668 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
671 if (!strcmp (p, "implicit"))
672 warn_implicit = setting;
673 else if (!strcmp (p, "long-long"))
674 warn_long_long = setting;
675 else if (!strcmp (p, "return-type"))
676 warn_return_type = setting;
677 else if (!strcmp (p, "ctor-dtor-privacy"))
678 warn_ctor_dtor_privacy = setting;
679 else if (!strcmp (p, "write-strings"))
680 warn_write_strings = setting;
681 else if (!strcmp (p, "cast-qual"))
682 warn_cast_qual = setting;
683 else if (!strcmp (p, "char-subscripts"))
684 warn_char_subscripts = setting;
685 else if (!strcmp (p, "pointer-arith"))
686 warn_pointer_arith = setting;
687 else if (!strcmp (p, "missing-prototypes"))
688 warn_missing_prototypes = setting;
689 else if (!strcmp (p, "redundant-decls"))
690 warn_redundant_decls = setting;
691 else if (!strcmp (p, "missing-braces"))
692 warn_missing_braces = setting;
693 else if (!strcmp (p, "sign-compare"))
694 warn_sign_compare = setting;
695 else if (!strcmp (p, "format"))
696 warn_format = setting;
697 else if (!strcmp (p, "conversion"))
698 warn_conversion = setting;
699 else if (!strcmp (p, "parentheses"))
700 warn_parentheses = setting;
701 else if (!strcmp (p, "non-virtual-dtor"))
702 warn_nonvdtor = setting;
703 else if (!strcmp (p, "extern-inline"))
704 warn_extern_inline = setting;
705 else if (!strcmp (p, "reorder"))
706 warn_reorder = setting;
707 else if (!strcmp (p, "synth"))
708 warn_synth = setting;
709 else if (!strcmp (p, "pmf-conversions"))
710 warn_pmf2ptr = setting;
711 else if (!strcmp (p, "effc++"))
713 else if (!strcmp (p, "sign-promo"))
714 warn_sign_promo = setting;
715 else if (!strcmp (p, "old-style-cast"))
716 warn_old_style_cast = setting;
717 else if (!strcmp (p, "overloaded-virtual"))
718 warn_overloaded_virtual = setting;
719 else if (!strcmp (p, "multichar"))
720 warn_multichar = setting;
721 else if (!strcmp (p, "unknown-pragmas"))
722 /* Set to greater than 1, so that even unknown pragmas in
723 system headers will be warned about. */
724 warn_unknown_pragmas = setting * 2;
725 else if (!strcmp (p, "comment"))
726 ; /* cpp handles this one. */
727 else if (!strcmp (p, "comments"))
728 ; /* cpp handles this one. */
729 else if (!strcmp (p, "trigraphs"))
730 ; /* cpp handles this one. */
731 else if (!strcmp (p, "import"))
732 ; /* cpp handles this one. */
733 else if (!strcmp (p, "all"))
735 warn_return_type = setting;
736 warn_unused = setting;
737 warn_implicit = setting;
738 warn_ctor_dtor_privacy = setting;
739 warn_switch = setting;
740 warn_format = setting;
741 warn_parentheses = setting;
742 warn_missing_braces = setting;
743 warn_sign_compare = setting;
744 warn_extern_inline = setting;
745 warn_nonvdtor = setting;
746 warn_multichar = setting;
747 /* We save the value of warn_uninitialized, since if they put
748 -Wuninitialized on the command line, we need to generate a
749 warning about not using it without also specifying -O. */
750 if (warn_uninitialized != 1)
751 warn_uninitialized = (setting ? 2 : 0);
752 warn_reorder = setting;
753 warn_sign_promo = setting;
754 /* Only warn about unknown pragmas that are not in system
756 warn_unknown_pragmas = 1;
758 else return strings_processed;
760 else if (!strcmp (p, "-ansi"))
761 flag_no_nonansi_builtin = 1, flag_ansi = 1,
762 flag_no_gnu_keywords = 1, flag_operator_names = 1;
764 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
765 it's probably safe to assume no sane person would ever want to use this
766 under normal circumstances. */
767 else if (!strcmp (p, "-spew-debug"))
771 return strings_processed;
776 /* Incorporate `const' and `volatile' qualifiers for member functions.
777 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
778 QUALS is a list of qualifiers. */
781 grok_method_quals (ctype, function, quals)
782 tree ctype, function, quals;
784 tree fntype = TREE_TYPE (function);
785 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
789 extern tree ridpointers[];
791 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
793 if (TYPE_READONLY (ctype))
794 error ("duplicate `%s' %s",
795 IDENTIFIER_POINTER (TREE_VALUE (quals)),
796 (TREE_CODE (function) == FUNCTION_DECL
797 ? "for member function" : "in type declaration"));
798 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
799 build_pointer_type (ctype);
801 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
803 if (TYPE_VOLATILE (ctype))
804 error ("duplicate `%s' %s",
805 IDENTIFIER_POINTER (TREE_VALUE (quals)),
806 (TREE_CODE (function) == FUNCTION_DECL
807 ? "for member function" : "in type declaration"));
808 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
809 build_pointer_type (ctype);
812 my_friendly_abort (20);
813 quals = TREE_CHAIN (quals);
816 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
817 (TREE_CODE (fntype) == METHOD_TYPE
818 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
819 : TYPE_ARG_TYPES (fntype)));
821 fntype = build_exception_variant (fntype, raises);
823 TREE_TYPE (function) = fntype;
827 /* Warn when -fexternal-templates is used and #pragma
828 interface/implementation is not used all the times it should be,
832 warn_if_unknown_interface (decl)
835 static int already_warned = 0;
836 if (already_warned++)
839 if (flag_alt_external_templates)
841 struct tinst_level *til = tinst_for_decl ();
843 char *sf = input_filename;
848 input_filename = til->file;
850 cp_warning ("template `%#D' instantiated in file without #pragma interface",
856 cp_warning_at ("template `%#D' defined in file without #pragma interface",
860 /* A subroutine of the parser, to handle a component list. */
863 grok_x_components (specs, components)
864 tree specs, components;
866 register tree t, x, tcode;
868 /* We just got some friends. They have been recorded elsewhere. */
869 if (components == void_type_node)
872 if (components == NULL_TREE)
874 t = groktypename (build_decl_list (specs, NULL_TREE));
878 error ("error in component specification");
882 switch (TREE_CODE (t))
885 /* Static anonymous unions come out as VAR_DECLs. */
886 if (ANON_UNION_TYPE_P (TREE_TYPE (t)))
889 /* We return SPECS here, because in the parser it was ending
890 up with not doing anything to $$, which is what SPECS
897 if (TREE_CODE (t) == UNION_TYPE)
898 tcode = union_type_node;
900 tcode = record_type_node;
901 if (CLASSTYPE_DECLARED_CLASS (t))
902 tcode = class_type_node;
903 else if (IS_SIGNATURE (t))
904 tcode = signature_type_node;
906 if (TYPE_LANG_SPECIFIC (t)
907 && CLASSTYPE_USE_TEMPLATE (t))
908 /* We have already looked up this type. */
912 if (CLASSTYPE_IS_TEMPLATE (t))
913 x = DECL_NAME (CLASSTYPE_TI_TEMPLATE (t));
915 x = TYPE_IDENTIFIER (t);
916 t = xref_tag (tcode, x, 0);
919 if (ANON_UNION_TYPE_P (t))
921 /* See also shadow_tag. */
923 struct pending_inline **p;
925 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
927 /* Wipe out memory of synthesized methods */
928 TYPE_HAS_CONSTRUCTOR (t) = 0;
929 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
930 TYPE_HAS_INIT_REF (t) = 0;
931 TYPE_HAS_CONST_INIT_REF (t) = 0;
932 TYPE_HAS_ASSIGN_REF (t) = 0;
933 TYPE_HAS_ASSIGNMENT (t) = 0;
934 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
936 q = &TYPE_METHODS (t);
939 if (DECL_ARTIFICIAL (*q))
940 *q = TREE_CHAIN (*q);
942 q = &TREE_CHAIN (*q);
944 if (TYPE_METHODS (t))
945 error ("an anonymous union cannot have function members");
947 p = &pending_inlines;
948 for (; *p; *p = (*p)->next)
949 if (DECL_CONTEXT ((*p)->fndecl) != t)
959 tcode = enum_type_node;
960 t = xref_tag (tcode, TYPE_IDENTIFIER (t), 0);
961 x = grok_enum_decls (NULL_TREE);
966 if (t != void_type_node)
967 error ("empty component declaration");
972 /* There may or may not be any enum decls to grok, but
973 grok_enum_decls will just return components, if there aren't
974 any. We used to try to figure out whether or not there were
975 any enum decls based on the type of components, but that's too
976 hard; it might be something like `enum { a } *p;'. */
977 return grok_enum_decls (components);
980 /* Constructors for types with virtual baseclasses need an "in-charge" flag
981 saying whether this constructor is responsible for initialization of
982 virtual baseclasses or not. All destructors also need this "in-charge"
983 flag, which additionally determines whether or not the destructor should
984 free the memory for the object.
986 This function adds the "in-charge" flag to member function FN if
987 appropriate. It is called from grokclassfn and tsubst.
988 FN must be either a constructor or destructor. */
991 maybe_retrofit_in_chrg (fn)
994 tree basetype, arg_types, parms, parm, fntype;
996 if (DECL_CONSTRUCTOR_P (fn)
997 && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CLASS_CONTEXT (fn))
998 && ! DECL_CONSTRUCTOR_FOR_VBASE_P (fn))
1000 else if (! DECL_CONSTRUCTOR_P (fn)
1001 && TREE_CHAIN (DECL_ARGUMENTS (fn)) == NULL_TREE)
1006 if (DECL_CONSTRUCTOR_P (fn))
1007 DECL_CONSTRUCTOR_FOR_VBASE_P (fn) = 1;
1009 /* First add it to DECL_ARGUMENTS... */
1010 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
1011 /* Mark the artificial `__in_chrg' parameter as "artificial". */
1012 SET_DECL_ARTIFICIAL (parm);
1013 DECL_ARG_TYPE (parm) = integer_type_node;
1014 TREE_READONLY (parm) = 1;
1015 parms = DECL_ARGUMENTS (fn);
1016 TREE_CHAIN (parm) = TREE_CHAIN (parms);
1017 TREE_CHAIN (parms) = parm;
1019 /* ...and then to TYPE_ARG_TYPES. */
1020 arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
1021 basetype = TREE_TYPE (TREE_VALUE (arg_types));
1022 arg_types = hash_tree_chain (integer_type_node, TREE_CHAIN (arg_types));
1023 fntype = build_cplus_method_type (basetype, TREE_TYPE (TREE_TYPE (fn)),
1025 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
1026 fntype = build_exception_variant (fntype,
1027 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)));
1028 TREE_TYPE (fn) = fntype;
1031 /* Classes overload their constituent function names automatically.
1032 When a function name is declared in a record structure,
1033 its name is changed to it overloaded name. Since names for
1034 constructors and destructors can conflict, we place a leading
1035 '$' for destructors.
1037 CNAME is the name of the class we are grokking for.
1039 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
1041 FLAGS contains bits saying what's special about today's
1042 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
1044 If FUNCTION is a destructor, then we must add the `auto-delete' field
1045 as a second parameter. There is some hair associated with the fact
1046 that we must "declare" this variable in the manner consistent with the
1047 way the rest of the arguments were declared.
1049 QUALS are the qualifiers for the this pointer. */
1052 grokclassfn (ctype, cname, function, flags, quals)
1053 tree ctype, cname, function;
1054 enum overload_flags flags;
1057 tree fn_name = DECL_NAME (function);
1062 if (fn_name == NULL_TREE)
1064 error ("name missing for member function");
1065 fn_name = get_identifier ("<anonymous>");
1066 DECL_NAME (function) = fn_name;
1070 qualtype = grok_method_quals (ctype, function, quals);
1074 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
1075 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1077 /* Must add the class instance variable up front. */
1078 /* Right now we just make this a pointer. But later
1079 we may wish to make it special. */
1080 tree type = TREE_VALUE (arg_types);
1083 if ((flag_this_is_variable > 0)
1084 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
1087 parm = build_decl (PARM_DECL, this_identifier, type);
1088 /* Mark the artificial `this' parameter as "artificial". */
1089 SET_DECL_ARTIFICIAL (parm);
1090 DECL_ARG_TYPE (parm) = type;
1091 /* We can make this a register, so long as we don't
1092 accidentally complain if someone tries to take its address. */
1093 DECL_REGISTER (parm) = 1;
1095 TREE_READONLY (parm) = 1;
1096 TREE_CHAIN (parm) = last_function_parms;
1097 last_function_parms = parm;
1100 DECL_ARGUMENTS (function) = last_function_parms;
1101 /* First approximations. */
1102 DECL_CONTEXT (function) = ctype;
1103 DECL_CLASS_CONTEXT (function) = ctype;
1105 if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
1107 maybe_retrofit_in_chrg (function);
1108 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
1111 if (flags == DTOR_FLAG)
1113 DECL_ASSEMBLER_NAME (function) = build_destructor_name (ctype);
1114 TYPE_HAS_DESTRUCTOR (ctype) = 1;
1117 set_mangled_name_for_decl (function);
1120 /* Work on the expr used by alignof (this is only called by the parser). */
1129 if (processing_template_decl)
1130 return build_min (ALIGNOF_EXPR, sizetype, expr);
1132 if (TREE_CODE (expr) == COMPONENT_REF
1133 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
1134 error ("`__alignof__' applied to a bit-field");
1136 if (TREE_CODE (expr) == INDIRECT_REF)
1138 best = t = TREE_OPERAND (expr, 0);
1139 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1141 while (TREE_CODE (t) == NOP_EXPR
1142 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1145 t = TREE_OPERAND (t, 0);
1146 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1147 if (thisalign > bestalign)
1148 best = t, bestalign = thisalign;
1150 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1154 /* ANSI says arrays and fns are converted inside comma.
1155 But we can't convert them in build_compound_expr
1156 because that would break commas in lvalues.
1157 So do the conversion here if operand was a comma. */
1158 if (TREE_CODE (expr) == COMPOUND_EXPR
1159 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1160 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1161 expr = default_conversion (expr);
1162 return c_alignof (TREE_TYPE (expr));
1166 /* Create an ARRAY_REF, checking for the user doing things backwards
1170 grok_array_decl (array_expr, index_exp)
1171 tree array_expr, index_exp;
1173 tree type = TREE_TYPE (array_expr);
1174 tree p1, p2, i1, i2;
1176 if (type == error_mark_node || index_exp == error_mark_node)
1177 return error_mark_node;
1178 if (processing_template_decl)
1179 return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE,
1180 array_expr, index_exp);
1182 if (type == NULL_TREE)
1184 /* Something has gone very wrong. Assume we are mistakenly reducing
1185 an expression instead of a declaration. */
1186 error ("parser may be lost: is there a '{' missing somewhere?");
1190 if (TREE_CODE (type) == OFFSET_TYPE
1191 || TREE_CODE (type) == REFERENCE_TYPE)
1192 type = TREE_TYPE (type);
1194 /* If they have an `operator[]', use that. */
1195 if (IS_AGGR_TYPE (type) || IS_AGGR_TYPE (TREE_TYPE (index_exp)))
1196 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1197 array_expr, index_exp, NULL_TREE);
1199 /* Otherwise, create an ARRAY_REF for a pointer or array type. It
1200 is a little-known fact that, if `a' is an array and `i' is an
1201 int, you can write `i[a]', which means the same thing as `a[i]'. */
1203 if (TREE_CODE (type) == ARRAY_TYPE)
1206 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1208 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1211 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1213 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1214 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1216 if ((p1 && i2) && (i1 && p2))
1217 error ("ambiguous conversion for array subscript");
1220 array_expr = p1, index_exp = i2;
1222 array_expr = p2, index_exp = i1;
1225 cp_error ("invalid types `%T[%T]' for array subscript",
1226 type, TREE_TYPE (index_exp));
1227 return error_mark_node;
1230 if (array_expr == error_mark_node || index_exp == error_mark_node)
1231 error ("ambiguous conversion for array subscript");
1233 return build_array_ref (array_expr, index_exp);
1236 /* Given the cast expression EXP, checking out its validity. Either return
1237 an error_mark_node if there was an unavoidable error, return a cast to
1238 void for trying to delete a pointer w/ the value 0, or return the
1239 call to delete. If DOING_VEC is 1, we handle things differently
1240 for doing an array delete. If DOING_VEC is 2, they gave us the
1241 array size as an argument to delete.
1242 Implements ARM $5.3.4. This is called from the parser. */
1245 delete_sanity (exp, size, doing_vec, use_global_delete)
1247 int doing_vec, use_global_delete;
1250 /* For a regular vector delete (aka, no size argument) we will pass
1251 this down as a NULL_TREE into build_vec_delete. */
1252 tree maxindex = NULL_TREE;
1254 if (exp == error_mark_node)
1257 if (processing_template_decl)
1259 t = build_min (DELETE_EXPR, void_type_node, exp, size);
1260 DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
1261 DELETE_EXPR_USE_VEC (t) = doing_vec;
1265 if (TREE_CODE (exp) == OFFSET_REF)
1266 exp = resolve_offset_ref (exp);
1267 exp = convert_from_reference (exp);
1268 t = stabilize_reference (exp);
1269 t = build_expr_type_conversion (WANT_POINTER, t, 1);
1271 if (t == NULL_TREE || t == error_mark_node)
1273 cp_error ("type `%#T' argument given to `delete', expected pointer",
1275 return error_mark_node;
1280 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1281 pedwarn ("anachronistic use of array size in vector delete");
1284 type = TREE_TYPE (t);
1286 /* As of Valley Forge, you can delete a pointer to const. */
1288 /* You can't delete functions. */
1289 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1291 error ("cannot delete a function");
1292 return error_mark_node;
1295 /* An array can't have been allocated by new, so complain. */
1296 if (TREE_CODE (t) == ADDR_EXPR
1297 && TREE_CODE (TREE_OPERAND (t, 0)) == VAR_DECL
1298 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == ARRAY_TYPE)
1299 cp_warning ("deleting array `%#D'", TREE_OPERAND (t, 0));
1301 /* Deleting a pointer with the value zero is valid and has no effect. */
1302 if (integer_zerop (t))
1303 return build1 (NOP_EXPR, void_type_node, t);
1306 return build_vec_delete (t, maxindex, integer_one_node,
1307 integer_two_node, use_global_delete);
1310 if (IS_AGGR_TYPE (TREE_TYPE (type))
1311 && TYPE_GETS_REG_DELETE (TREE_TYPE (type)))
1313 /* Only do access checking here; we'll be calling op delete
1314 from the destructor. */
1315 tree tmp = build_op_delete_call (DELETE_EXPR, t, size_zero_node,
1316 LOOKUP_NORMAL, NULL_TREE);
1317 if (tmp == error_mark_node)
1318 return error_mark_node;
1321 return build_delete (type, t, integer_three_node,
1322 LOOKUP_NORMAL, use_global_delete);
1326 /* Report an error if the indicated template declaration is not the
1327 sort of thing that should be a member template. */
1330 check_member_template (tmpl)
1335 my_friendly_assert (TREE_CODE (tmpl) == TEMPLATE_DECL, 0);
1336 decl = DECL_TEMPLATE_RESULT (tmpl);
1338 if (TREE_CODE (decl) == FUNCTION_DECL
1339 || (TREE_CODE (decl) == TYPE_DECL
1340 && IS_AGGR_TYPE (TREE_TYPE (decl))))
1342 if (current_function_decl)
1343 /* 14.5.2.2 [temp.mem]
1345 A local class shall not have member templates. */
1346 cp_error ("declaration of member template `%#D' in local class",
1349 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
1351 /* 14.5.2.3 [temp.mem]
1353 A member function template shall not be virtual. */
1355 ("invalid use of `virtual' in template declaration of `%#D'",
1357 DECL_VIRTUAL_P (decl) = 0;
1360 /* The debug-information generating code doesn't know what to do
1361 with member templates. */
1362 DECL_IGNORED_P (tmpl) = 1;
1365 cp_error ("template declaration of `%#D'", decl);
1368 /* Return true iff TYPE is a valid Java parameter or return type. */
1371 acceptable_java_type (type)
1374 if (TREE_CODE (type) == VOID_TYPE || TYPE_FOR_JAVA (type))
1376 if (TREE_CODE (type) == POINTER_TYPE)
1378 type = TREE_TYPE (type);
1379 if (TREE_CODE (type) == RECORD_TYPE)
1382 if (! TYPE_FOR_JAVA (type))
1384 if (! CLASSTYPE_TEMPLATE_INFO (type))
1386 args = CLASSTYPE_TI_ARGS (type);
1387 i = TREE_VEC_LENGTH (args);
1390 type = TREE_VEC_ELT (args, i);
1391 if (TREE_CODE (type) == POINTER_TYPE)
1392 type = TREE_TYPE (type);
1393 if (! TYPE_FOR_JAVA (type))
1402 /* For a METHOD in a Java class CTYPE, return 1 if
1403 the parameter and return types are valid Java types.
1404 Otherwise, print appropriate error messages, and return 0. */
1407 check_java_method (ctype, method)
1411 tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
1412 tree ret_type = TREE_TYPE (TREE_TYPE (method));
1413 if (! acceptable_java_type (ret_type))
1415 cp_error ("Java method '%D' has non-Java return type `%T'",
1419 for (; arg_types != NULL_TREE; arg_types = TREE_CHAIN (arg_types))
1421 tree type = TREE_VALUE (arg_types);
1422 if (! acceptable_java_type (type))
1424 cp_error ("Java method '%D' has non-Java parameter type `%T'",
1429 return jerr ? 0 : 1;
1432 /* Sanity check: report error if this function FUNCTION is not
1433 really a member of the class (CTYPE) it is supposed to belong to.
1434 CNAME is the same here as it is for grokclassfn above. */
1437 check_classfn (ctype, function)
1438 tree ctype, function;
1440 tree fn_name = DECL_NAME (function);
1441 tree fndecl, fndecls;
1442 tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype));
1445 tree templates = NULL_TREE;
1447 if (method_vec != 0)
1449 methods = &TREE_VEC_ELT (method_vec, 0);
1450 end = TREE_VEC_END (method_vec);
1452 /* First suss out ctors and dtors. */
1453 if (*methods && fn_name == DECL_NAME (OVL_CURRENT (*methods))
1454 && DECL_CONSTRUCTOR_P (function))
1456 if (*++methods && fn_name == DECL_NAME (OVL_CURRENT (*methods))
1457 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)))
1460 while (++methods != end)
1463 if (fn_name == DECL_NAME (OVL_CURRENT (*methods)))
1466 for (fndecls = *methods; fndecls != NULL_TREE;
1467 fndecls = OVL_NEXT (fndecls))
1469 fndecl = OVL_CURRENT (fndecls);
1470 /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL is
1471 not mangled, so the check below does not work
1472 correctly in that case. */
1473 if (TREE_CODE (function) != TEMPLATE_DECL
1474 && TREE_CODE (fndecl) != TEMPLATE_DECL
1475 && (DECL_ASSEMBLER_NAME (function)
1476 == DECL_ASSEMBLER_NAME (fndecl)))
1479 /* We cannot simply call decls_match because this
1480 doesn't work for static member functions that are
1481 pretending to be methods, and because the name
1482 may have been changed by asm("new_name"). */
1483 if (DECL_NAME (function) == DECL_NAME (fndecl))
1485 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1486 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1488 /* Get rid of the this parameter on functions that become
1490 if (DECL_STATIC_FUNCTION_P (fndecl)
1491 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1492 p1 = TREE_CHAIN (p1);
1494 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1495 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1496 && compparms (p1, p2, 3)
1497 && (DECL_TEMPLATE_SPECIALIZATION (function)
1498 == DECL_TEMPLATE_SPECIALIZATION (fndecl))
1499 && (!DECL_TEMPLATE_SPECIALIZATION (function)
1500 || (DECL_TI_TEMPLATE (function)
1501 == DECL_TI_TEMPLATE (fndecl))))
1504 if (is_member_template (fndecl))
1505 /* This function might be an instantiation
1506 or specialization of fndecl. */
1508 scratch_tree_cons (NULL_TREE, fndecl, templates);
1513 else if (TREE_CODE (fndecl) == TEMPLATE_DECL
1514 && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl))
1515 && IDENTIFIER_TYPENAME_P (fn_name))
1516 /* The method in the class is a member template
1517 conversion operator. We are declaring another
1518 conversion operator. It is possible that even though
1519 the names don't match, there is some specialization
1522 scratch_tree_cons (NULL_TREE, fndecl, templates);
1527 /* This function might be an instantiation or a specialization.
1528 We should verify that this is possible. If it is, we must
1529 somehow add the new declaration to the method vector for the
1530 class. Perhaps we should use add_method? For now, we simply
1531 return NULL_TREE, which lets the caller know that this
1532 function is new, but we don't print an error message. */
1537 tree fndecl = *methods;
1538 cp_error ("prototype for `%#D' does not match any in class `%T'",
1540 cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl) ? "s are" : " is",
1541 OVL_CURRENT (fndecl));
1542 while (fndecl = OVL_NEXT (fndecl), fndecl)
1543 cp_error_at (" %#D", OVL_CURRENT(fndecl));
1548 cp_error ("no `%#D' member function declared in class `%T'",
1552 /* If we did not find the method in the class, add it to avoid
1554 add_method (ctype, methods, function);
1558 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1559 of a structure component, returning a FIELD_DECL node.
1560 QUALS is a list of type qualifiers for this decl (such as for declaring
1561 const member functions).
1563 This is done during the parsing of the struct declaration.
1564 The FIELD_DECL nodes are chained together and the lot of them
1565 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1569 If class A defines that certain functions in class B are friends, then
1570 the way I have set things up, it is B who is interested in permission
1571 granted by A. However, it is in A's context that these declarations
1572 are parsed. By returning a void_type_node, class A does not attempt
1573 to incorporate the declarations of the friends within its structure.
1575 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1576 CHANGES TO CODE IN `start_method'. */
1579 grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
1580 tree declarator, declspecs, init, asmspec_tree, attrlist;
1582 register tree value;
1584 int flags = LOOKUP_ONLYCONVERTING;
1586 /* Convert () initializers to = initializers. */
1587 if (init == NULL_TREE && declarator != NULL_TREE
1588 && TREE_CODE (declarator) == CALL_EXPR
1589 && TREE_OPERAND (declarator, 0)
1590 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1591 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1592 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1594 init = TREE_OPERAND (declarator, 1);
1595 declarator = TREE_OPERAND (declarator, 0);
1599 if (declspecs == NULL_TREE
1600 && TREE_CODE (declarator) == SCOPE_REF
1601 && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE)
1603 /* Access declaration */
1604 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0))))
1606 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
1607 pop_nested_class (1);
1608 return do_class_using_decl (declarator);
1612 && TREE_CODE (init) == TREE_LIST
1613 && TREE_VALUE (init) == error_mark_node
1614 && TREE_CHAIN (init) == NULL_TREE)
1617 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, NULL_TREE);
1619 return value; /* friend or constructor went bad. */
1621 /* Pass friendly classes back. */
1622 if (TREE_CODE (value) == VOID_TYPE)
1623 return void_type_node;
1625 if (DECL_NAME (value) != NULL_TREE
1626 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1627 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1628 cp_error ("member `%D' conflicts with virtual function table field name",
1631 /* Stash away type declarations. */
1632 if (TREE_CODE (value) == TYPE_DECL)
1634 DECL_NONLOCAL (value) = 1;
1635 DECL_CONTEXT (value) = current_class_type;
1636 DECL_CLASS_CONTEXT (value) = current_class_type;
1637 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1639 /* Now that we've updated the context, we need to remangle the
1640 name for this TYPE_DECL. */
1641 DECL_ASSEMBLER_NAME (value) = DECL_NAME (value);
1642 if (!uses_template_parms (value))
1643 DECL_ASSEMBLER_NAME (value) =
1644 get_identifier (build_overload_name (TREE_TYPE (value), 1, 1));
1646 pushdecl_class_level (value);
1650 if (IS_SIGNATURE (current_class_type)
1651 && TREE_CODE (value) != FUNCTION_DECL)
1653 error ("field declaration not allowed in signature");
1654 return void_type_node;
1657 if (DECL_IN_AGGR_P (value))
1659 cp_error ("`%D' is already defined in the class %T", value,
1660 DECL_CONTEXT (value));
1661 return void_type_node;
1665 asmspec = TREE_STRING_POINTER (asmspec_tree);
1669 if (IS_SIGNATURE (current_class_type)
1670 && TREE_CODE (value) == FUNCTION_DECL)
1672 error ("function declarations cannot have initializers in signature");
1675 else if (TREE_CODE (value) == FUNCTION_DECL)
1677 grok_function_init (value, init);
1680 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1681 /* Already complained in grokdeclarator. */
1685 /* We allow initializers to become parameters to base
1687 if (TREE_CODE (init) == TREE_LIST)
1689 if (TREE_CHAIN (init) == NULL_TREE)
1690 init = TREE_VALUE (init);
1692 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1695 if (TREE_CODE (init) == CONST_DECL)
1696 init = DECL_INITIAL (init);
1697 else if (TREE_READONLY_DECL_P (init))
1698 init = decl_constant_value (init);
1699 else if (TREE_CODE (init) == CONSTRUCTOR)
1700 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1701 my_friendly_assert (TREE_PERMANENT (init), 192);
1702 if (init == error_mark_node)
1703 /* We must make this look different than `error_mark_node'
1704 because `decl_const_value' would mis-interpret it
1705 as only meaning that this VAR_DECL is defined. */
1706 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1707 else if (processing_template_decl)
1709 else if (! TREE_CONSTANT (init))
1711 /* We can allow references to things that are effectively
1712 static, since references are initialized with the address. */
1713 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1714 || (TREE_STATIC (init) == 0
1715 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1716 || DECL_EXTERNAL (init) == 0)))
1718 error ("field initializer is not constant");
1719 init = error_mark_node;
1725 /* The corresponding pop_obstacks is in cp_finish_decl. */
1726 push_obstacks_nochange ();
1728 if (processing_template_decl && ! current_function_decl
1729 && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
1730 value = push_template_decl (value);
1732 /* Check to see if a field redeclares a template parameter. */
1733 if (current_template_parms
1734 && TREE_CODE (declarator) == IDENTIFIER_NODE
1735 && IDENTIFIER_LOCAL_VALUE (declarator))
1737 tree olddecl = IDENTIFIER_LOCAL_VALUE (declarator);
1738 if (decl_template_parm_p (olddecl))
1740 cp_error ("redeclaration of template parameter `%T'", declarator);
1741 cp_error_at (" previously declared here `%#D'", olddecl);
1746 cplus_decl_attributes (value, TREE_PURPOSE (attrlist),
1747 TREE_VALUE (attrlist));
1749 if (TREE_CODE (value) == VAR_DECL)
1751 my_friendly_assert (TREE_PUBLIC (value), 0);
1753 /* We cannot call pushdecl here, because that would
1754 fill in the value of our TREE_CHAIN. Instead, we
1755 modify cp_finish_decl to do the right thing, namely, to
1756 put this decl out straight away. */
1757 /* current_class_type can be NULL_TREE in case of error. */
1758 if (asmspec == 0 && current_class_type)
1760 TREE_PUBLIC (value) = 1;
1761 DECL_INITIAL (value) = error_mark_node;
1762 DECL_ASSEMBLER_NAME (value)
1763 = build_static_name (current_class_type, DECL_NAME (value));
1765 if (! processing_template_decl)
1766 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1768 /* Static consts need not be initialized in the class definition. */
1769 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1771 static int explanation = 0;
1773 error ("initializer invalid for static member with constructor");
1774 if (explanation++ == 0)
1775 error ("(you really want to initialize it separately)");
1778 /* Force the compiler to know when an uninitialized static
1779 const member is being used. */
1780 if (TYPE_READONLY (value) && init == 0)
1781 TREE_USED (value) = 1;
1782 DECL_INITIAL (value) = init;
1783 DECL_IN_AGGR_P (value) = 1;
1784 DECL_CONTEXT (value) = current_class_type;
1785 DECL_CLASS_CONTEXT (value) = current_class_type;
1787 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1788 pushdecl_class_level (value);
1791 if (TREE_CODE (value) == FIELD_DECL)
1795 /* This must override the asm specifier which was placed
1796 by grokclassfn. Lay this out fresh. */
1797 DECL_RTL (value) = NULL_RTX;
1798 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1800 if (DECL_INITIAL (value) == error_mark_node)
1801 init = error_mark_node;
1802 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1803 DECL_INITIAL (value) = init;
1804 DECL_IN_AGGR_P (value) = 1;
1807 if (TREE_CODE (value) == FUNCTION_DECL)
1811 /* This must override the asm specifier which was placed
1812 by grokclassfn. Lay this out fresh. */
1813 DECL_RTL (value) = NULL_RTX;
1814 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1816 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1818 /* Pass friends back this way. */
1819 if (DECL_FRIEND_P (value))
1820 return void_type_node;
1822 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1823 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1824 cp_error ("method `%#D' of local class must be defined in class body",
1828 DECL_IN_AGGR_P (value) = 1;
1831 my_friendly_abort (21);
1836 /* Like `grokfield', but for bitfields.
1837 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1840 grokbitfield (declarator, declspecs, width)
1841 tree declarator, declspecs, width;
1843 register tree value = grokdeclarator (declarator, declspecs, BITFIELD,
1846 if (! value) return NULL_TREE; /* friends went bad. */
1848 /* Pass friendly classes back. */
1849 if (TREE_CODE (value) == VOID_TYPE)
1850 return void_type_node;
1852 if (TREE_CODE (value) == TYPE_DECL)
1854 cp_error ("cannot declare `%D' to be a bitfield type", value);
1858 /* Usually, finish_struct_1 catches bitifields with invalid types.
1859 But, in the case of bitfields with function type, we confuse
1860 ourselves into thinking they are member functions, so we must
1862 if (TREE_CODE (value) == FUNCTION_DECL)
1864 cp_error ("cannot declare bitfield `%D' with funcion type",
1869 if (IS_SIGNATURE (current_class_type))
1871 error ("field declaration not allowed in signature");
1872 return void_type_node;
1875 if (DECL_IN_AGGR_P (value))
1877 cp_error ("`%D' is already defined in the class %T", value,
1878 DECL_CONTEXT (value));
1879 return void_type_node;
1882 GNU_xref_member (current_class_name, value);
1884 if (TREE_STATIC (value))
1886 cp_error ("static member `%D' cannot be a bitfield", value);
1889 cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1891 if (width != error_mark_node)
1893 constant_expression_warning (width);
1894 DECL_INITIAL (value) = width;
1895 DECL_BIT_FIELD (value) = 1;
1898 DECL_IN_AGGR_P (value) = 1;
1903 grokoptypename (declspecs, declarator)
1904 tree declspecs, declarator;
1906 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1907 return build_typename_overload (t);
1910 /* When a function is declared with an initializer,
1911 do the right thing. Currently, there are two possibilities:
1916 // initialization possibility #1.
1917 virtual void f () = 0;
1939 // initialization possibility #2
1946 copy_assignment_arg_p (parmtype, virtualp)
1950 if (current_class_type == NULL_TREE)
1953 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1954 parmtype = TREE_TYPE (parmtype);
1956 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1958 /* Non-standard hack to support old Booch components. */
1959 || (! virtualp && DERIVED_FROM_P (parmtype, current_class_type))
1968 grok_function_init (decl, init)
1972 /* An initializer for a function tells how this function should
1974 tree type = TREE_TYPE (decl);
1976 if (TREE_CODE (type) == FUNCTION_TYPE)
1977 cp_error ("initializer specified for non-member function `%D'", decl);
1979 /* We'll check for this in finish_struct_1. */
1980 else if (DECL_VINDEX (decl) == NULL_TREE)
1981 cp_error ("initializer specified for non-virtual method `%D'", decl);
1983 else if (integer_zerop (init))
1986 /* Mark this function as being "defined". */
1987 DECL_INITIAL (decl) = error_mark_node;
1988 /* pure virtual destructors must be defined. */
1989 /* pure virtual needs to be defined (as abort) only when put in
1990 vtbl. For wellformed call, it should be itself. pr4737 */
1991 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1993 extern tree abort_fndecl;
1994 /* Give this node rtl from `abort'. */
1995 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1998 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1999 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
2002 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
2004 if (copy_assignment_arg_p (parmtype, 1))
2005 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
2009 cp_error ("invalid initializer for virtual method `%D'", decl);
2013 cplus_decl_attributes (decl, attributes, prefix_attributes)
2014 tree decl, attributes, prefix_attributes;
2016 if (decl == NULL_TREE || decl == void_type_node)
2019 if (TREE_CODE (decl) == TEMPLATE_DECL)
2020 decl = DECL_TEMPLATE_RESULT (decl);
2022 decl_attributes (decl, attributes, prefix_attributes);
2024 if (TREE_CODE (decl) == TYPE_DECL)
2025 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl));
2028 /* CONSTRUCTOR_NAME:
2029 Return the name for the constructor (or destructor) for the
2030 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2031 IDENTIFIER_NODE. When given a template, this routine doesn't
2032 lose the specialization. */
2035 constructor_name_full (thing)
2038 if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM
2039 || TREE_CODE (thing) == TEMPLATE_TEMPLATE_PARM
2040 || TREE_CODE (thing) == TYPENAME_TYPE)
2041 thing = TYPE_NAME (thing);
2042 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
2044 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
2045 thing = DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0)));
2047 thing = TYPE_NAME (thing);
2049 if (TREE_CODE (thing) == TYPE_DECL
2050 || (TREE_CODE (thing) == TEMPLATE_DECL
2051 && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL))
2052 thing = DECL_NAME (thing);
2053 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
2057 /* CONSTRUCTOR_NAME:
2058 Return the name for the constructor (or destructor) for the
2059 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2060 IDENTIFIER_NODE. When given a template, return the plain
2061 unspecialized name. */
2064 constructor_name (thing)
2068 thing = constructor_name_full (thing);
2069 t = IDENTIFIER_TEMPLATE (thing);
2075 /* Cache the value of this class's main virtual function table pointer
2076 in a register variable. This will save one indirection if a
2077 more than one virtual function call is made this function. */
2082 extern tree base_init_expr;
2084 if (base_init_expr == 0
2085 && DECL_CONSTRUCTOR_P (current_function_decl))
2087 if (processing_template_decl)
2088 add_tree (build_min_nt
2090 current_member_init_list, current_base_init_list));
2092 emit_base_init (current_class_type, 0);
2096 /* Record the existence of an addressable inline function. */
2099 mark_inline_for_output (decl)
2102 decl = DECL_MAIN_VARIANT (decl);
2103 if (DECL_SAVED_INLINE (decl))
2105 my_friendly_assert (TREE_PERMANENT (decl), 363);
2106 DECL_SAVED_INLINE (decl) = 1;
2108 if (DECL_PENDING_INLINE_INFO (decl) != 0
2109 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
2111 struct pending_inline *t = pending_inlines;
2112 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
2115 if (t == DECL_PENDING_INLINE_INFO (decl))
2121 t = DECL_PENDING_INLINE_INFO (decl);
2122 t->next = pending_inlines;
2123 pending_inlines = t;
2125 DECL_PENDING_INLINE_INFO (decl) = 0;
2128 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
2134 temp_name_counter = 0;
2137 /* Hand off a unique name which can be used for variable we don't really
2138 want to know about anyway, for example, the anonymous variables which
2139 are needed to make references work. Declare this thing so we can use it.
2140 The variable created will be of type TYPE.
2142 STATICP is nonzero if this variable should be static. */
2145 get_temp_name (type, staticp)
2149 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
2151 int toplev = toplevel_bindings_p ();
2153 push_obstacks_nochange ();
2154 if (toplev || staticp)
2156 end_temporary_allocation ();
2157 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
2158 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
2162 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
2163 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
2165 TREE_USED (decl) = 1;
2166 TREE_STATIC (decl) = staticp;
2167 DECL_ARTIFICIAL (decl) = 1;
2169 /* If this is a local variable, then lay out its rtl now.
2170 Otherwise, callers of this function are responsible for dealing
2171 with this variable's rtl. */
2175 expand_decl_init (decl);
2182 /* Get a variable which we can use for multiple assignments.
2183 It is not entered into current_binding_level, because
2184 that breaks things when it comes time to do final cleanups
2185 (which take place "outside" the binding contour of the function). */
2188 get_temp_regvar (type, init)
2193 decl = build_decl (VAR_DECL, NULL_TREE, type);
2194 TREE_USED (decl) = 1;
2195 DECL_REGISTER (decl) = 1;
2196 DECL_ARTIFICIAL (decl) = 1;
2198 DECL_RTL (decl) = assign_temp (type, 2, 0, 1);
2199 /* We can expand these without fear, since they cannot need
2200 constructors or destructors. */
2201 expand_expr (build_modify_expr (decl, INIT_EXPR, init),
2202 NULL_RTX, VOIDmode, 0);
2207 /* Hunts through the global anonymous union ANON_DECL, building
2208 appropriate VAR_DECLs. Stores cleanups on the list of ELEMS, and
2209 returns a VAR_DECL whose size is the same as the size of the
2210 ANON_DECL, if one is available. */
2213 build_anon_union_vars (anon_decl, elems, static_p, external_p)
2219 tree type = TREE_TYPE (anon_decl);
2220 tree main_decl = NULL_TREE;
2223 for (field = TYPE_FIELDS (type);
2225 field = TREE_CHAIN (field))
2228 if (TREE_CODE (field) != FIELD_DECL)
2231 if (TREE_PRIVATE (field))
2232 cp_pedwarn_at ("private member `%#D' in anonymous union", field);
2233 else if (TREE_PROTECTED (field))
2234 cp_pedwarn_at ("protected member `%#D' in anonymous union", field);
2236 if (DECL_NAME (field) == NULL_TREE
2237 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
2239 decl = build_anon_union_vars (field, elems, static_p, external_p);
2245 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2246 /* tell `pushdecl' that this is not tentative. */
2247 DECL_INITIAL (decl) = error_mark_node;
2248 TREE_PUBLIC (decl) = 0;
2249 TREE_STATIC (decl) = static_p;
2250 DECL_EXTERNAL (decl) = external_p;
2251 decl = pushdecl (decl);
2252 DECL_INITIAL (decl) = NULL_TREE;
2255 /* Only write out one anon union element--choose the one that
2256 can hold them all. */
2257 if (main_decl == NULL_TREE
2258 && simple_cst_equal (DECL_SIZE (decl),
2259 DECL_SIZE (anon_decl)) == 1)
2262 /* ??? This causes there to be no debug info written out
2264 TREE_ASM_WRITTEN (decl) = 1;
2266 if (DECL_NAME (field) == NULL_TREE
2267 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
2268 /* The remainder of the processing was already done in the
2272 /* If there's a cleanup to do, it belongs in the
2273 TREE_PURPOSE of the following TREE_LIST. */
2274 *elems = scratch_tree_cons (NULL_TREE, decl, *elems);
2275 TREE_TYPE (*elems) = type;
2281 /* Finish off the processing of a UNION_TYPE structure.
2282 If there are static members, then all members are
2283 static, and must be laid out together. If the
2284 union is an anonymous union, we arrange for that
2285 as well. PUBLIC_P is nonzero if this union is
2286 not declared static. */
2289 finish_anon_union (anon_union_decl)
2290 tree anon_union_decl;
2292 tree type = TREE_TYPE (anon_union_decl);
2293 tree elems = NULL_TREE;
2295 int public_p = TREE_PUBLIC (anon_union_decl);
2296 int static_p = TREE_STATIC (anon_union_decl);
2297 int external_p = DECL_EXTERNAL (anon_union_decl);
2299 if (TYPE_FIELDS (type) == NULL_TREE)
2304 error ("global anonymous unions must be declared static");
2308 main_decl = build_anon_union_vars (anon_union_decl, &elems,
2309 static_p, external_p);
2315 make_decl_rtl (main_decl, 0, toplevel_bindings_p ());
2316 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2320 warning ("anonymous union with no members");
2325 /* The following call assumes that there are never any cleanups
2326 for anonymous unions--a reasonable assumption. */
2327 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2330 /* Finish processing a builtin type TYPE. It's name is NAME,
2331 its fields are in the array FIELDS. LEN is the number of elements
2332 in FIELDS minus one, or put another way, it is the maximum subscript
2335 It is given the same alignment as ALIGN_TYPE. */
2338 finish_builtin_type (type, name, fields, len, align_type)
2347 TYPE_FIELDS (type) = fields[0];
2348 for (i = 0; i < len; i++)
2350 layout_type (TREE_TYPE (fields[i]));
2351 DECL_FIELD_CONTEXT (fields[i]) = type;
2352 TREE_CHAIN (fields[i]) = fields[i+1];
2354 DECL_FIELD_CONTEXT (fields[i]) = type;
2355 DECL_CLASS_CONTEXT (fields[i]) = type;
2356 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2358 #if 0 /* not yet, should get fixed properly later */
2359 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2361 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2363 TYPE_STUB_DECL (type) = TYPE_NAME (type);
2364 layout_decl (TYPE_NAME (type), 0);
2367 /* Auxiliary functions to make type signatures for
2368 `operator new' and `operator delete' correspond to
2369 what compiler will be expecting. */
2372 coerce_new_type (type)
2377 if (TREE_CODE (type) == METHOD_TYPE)
2378 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2379 if (TREE_TYPE (type) != ptr_type_node)
2380 e1 = 1, error ("`operator new' must return type `void *'");
2382 /* Technically the type must be `size_t', but we may not know
2384 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2385 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2386 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2387 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2388 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2390 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2392 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2397 coerce_delete_type (type)
2404 tree arg_types = TYPE_ARG_TYPES (type);
2406 if (TREE_CODE (type) == METHOD_TYPE)
2408 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2409 arg_types = TREE_CHAIN (arg_types);
2412 if (TREE_TYPE (type) != void_type_node)
2413 e1 = 1, error ("`operator delete' must return type `void'");
2415 if (arg_types == NULL_TREE
2416 || TREE_VALUE (arg_types) != ptr_type_node)
2417 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2421 && TREE_CHAIN (arg_types)
2422 && TREE_CHAIN (arg_types) != void_list_node)
2424 /* Again, technically this argument must be `size_t', but again
2425 we may not know what that is. */
2426 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2427 if (TREE_CODE (t2) != INTEGER_TYPE
2428 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2429 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2430 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2433 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2434 error ("too many arguments in declaration of `operator delete'");
2436 error ("`...' invalid in specification of `operator delete'");
2441 arg_types = tree_cons (NULL_TREE, ptr_type_node,
2442 build_tree_list (NULL_TREE, sizetype));
2445 if (arg_types == NULL_TREE)
2446 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2448 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2454 arg_types = tree_cons (NULL_TREE, ptr_type_node,
2455 arg_types ? TREE_CHAIN (arg_types): NULL_TREE);
2457 type = build_function_type (void_type_node, arg_types);
2462 extern tree abort_fndecl;
2465 mark_vtable_entries (decl)
2468 tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
2472 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries))
2473 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2474 tree fn = TREE_OPERAND (fnaddr, 0);
2475 TREE_ADDRESSABLE (fn) = 1;
2478 skip_rtti_stuff (&entries);
2480 for (; entries; entries = TREE_CHAIN (entries))
2482 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries)
2483 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2484 tree fn = TREE_OPERAND (fnaddr, 0);
2485 TREE_ADDRESSABLE (fn) = 1;
2486 if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn))
2488 TREE_OPERAND (fnaddr, 0) = fn = copy_node (fn);
2489 DECL_RTL (fn) = DECL_RTL (abort_fndecl);
2490 mark_used (abort_fndecl);
2492 if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn))
2494 DECL_EXTERNAL (fn) = 0;
2501 /* Set DECL up to have the closest approximation of "initialized common"
2502 linkage available. */
2505 comdat_linkage (decl)
2509 make_decl_one_only (decl);
2511 TREE_PUBLIC (decl) = 0;
2513 if (DECL_LANG_SPECIFIC (decl))
2514 DECL_COMDAT (decl) = 1;
2517 /* For win32 we also want to put explicit instantiations in
2518 linkonce sections, so that they will be merged with implicit
2519 instantiations; otherwise we get duplicate symbol errors. */
2522 maybe_make_one_only (decl)
2525 /* This is not necessary on targets that support weak symbols, because
2526 the implicit instantiations will defer to the explicit one. */
2527 if (! supports_one_only () || SUPPORTS_WEAK)
2530 /* We can't set DECL_COMDAT on functions, or finish_file will think
2531 we can get away with not emitting them if they aren't used.
2532 We can't use make_decl_one_only for variables, because their
2533 DECL_INITIAL may not have been set properly yet. */
2535 if (TREE_CODE (decl) == FUNCTION_DECL)
2536 make_decl_one_only (decl);
2538 comdat_linkage (decl);
2541 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2542 based on TYPE and other static flags.
2544 Note that anything public is tagged TREE_PUBLIC, whether
2545 it's public in this file or in another one. */
2548 import_export_vtable (decl, type, final)
2552 if (DECL_INTERFACE_KNOWN (decl))
2555 if (TYPE_FOR_JAVA (type))
2557 TREE_PUBLIC (decl) = 1;
2558 DECL_EXTERNAL (decl) = 1;
2559 DECL_INTERFACE_KNOWN (decl) = 1;
2561 else if (CLASSTYPE_INTERFACE_KNOWN (type))
2563 TREE_PUBLIC (decl) = 1;
2564 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2565 DECL_INTERFACE_KNOWN (decl) = 1;
2567 /* For WIN32 we also want to put explicit instantiations in
2568 linkonce sections. */
2569 if (CLASSTYPE_EXPLICIT_INSTANTIATION (type))
2570 maybe_make_one_only (decl);
2574 /* We can only wait to decide if we have real non-inline virtual
2575 functions in our class, or if we come from a template. */
2577 int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2579 #ifndef MULTIPLE_SYMBOL_SPACES
2580 if (! found && ! final)
2583 for (method = TYPE_METHODS (type); method != NULL_TREE;
2584 method = TREE_CHAIN (method))
2585 if (DECL_VINDEX (method) != NULL_TREE
2586 && ! DECL_THIS_INLINE (method)
2587 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2595 if (final || ! found)
2597 comdat_linkage (decl);
2598 DECL_EXTERNAL (decl) = 0;
2602 TREE_PUBLIC (decl) = 1;
2603 DECL_EXTERNAL (decl) = 1;
2608 /* Determine whether or not we want to specifically import or export CTYPE,
2609 using various heuristics. */
2612 import_export_class (ctype)
2615 /* -1 for imported, 1 for exported. */
2616 int import_export = 0;
2618 if (CLASSTYPE_INTERFACE_KNOWN (ctype))
2621 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2622 /* FIXME this should really use some sort of target-independent macro. */
2623 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype)))
2625 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype)))
2629 /* If we got -fno-implicit-templates, we import template classes that
2630 weren't explicitly instantiated. */
2631 if (import_export == 0
2632 && CLASSTYPE_IMPLICIT_INSTANTIATION (ctype)
2633 && ! flag_implicit_templates)
2636 #ifndef MULTIPLE_SYMBOL_SPACES
2637 /* Base our import/export status on that of the first non-inline,
2638 non-abstract virtual function, if any. */
2639 if (import_export == 0
2640 && TYPE_VIRTUAL_P (ctype)
2641 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2644 for (method = TYPE_METHODS (ctype); method != NULL_TREE;
2645 method = TREE_CHAIN (method))
2647 if (DECL_VINDEX (method) != NULL_TREE
2648 && !DECL_THIS_INLINE (method)
2649 && !DECL_ABSTRACT_VIRTUAL_P (method))
2651 import_export = (DECL_REALLY_EXTERN (method) ? -1 : 1);
2660 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2661 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = (import_export > 0);
2662 CLASSTYPE_INTERFACE_ONLY (ctype) = (import_export < 0);
2667 finish_prevtable_vardecl (prev, vars)
2670 tree ctype = DECL_CONTEXT (vars);
2671 import_export_class (ctype);
2672 import_export_vtable (vars, ctype, 1);
2677 finish_vtable_vardecl (prev, vars)
2680 if (! DECL_EXTERNAL (vars)
2681 && ((TREE_PUBLIC (vars) && ! DECL_WEAK (vars) && ! DECL_ONE_ONLY (vars))
2682 || CLASSTYPE_EXPLICIT_INSTANTIATION (DECL_CONTEXT (vars))
2683 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))
2684 || (hack_decl_function_context (vars) && TREE_USED (vars)))
2685 && ! TREE_ASM_WRITTEN (vars))
2688 mark_vtable_entries (vars);
2689 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2690 store_init_value (vars, DECL_INITIAL (vars));
2692 if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG)
2694 /* Mark the VAR_DECL node representing the vtable itself as a
2695 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2696 It is rather important that such things be ignored because
2697 any effort to actually generate DWARF for them will run
2698 into trouble when/if we encounter code like:
2701 struct S { virtual void member (); };
2703 because the artificial declaration of the vtable itself (as
2704 manufactured by the g++ front end) will say that the vtable
2705 is a static member of `S' but only *after* the debug output
2706 for the definition of `S' has already been output. This causes
2707 grief because the DWARF entry for the definition of the vtable
2708 will try to refer back to an earlier *declaration* of the
2709 vtable as a static member of `S' and there won't be one.
2710 We might be able to arrange to have the "vtable static member"
2711 attached to the member list for `S' before the debug info for
2712 `S' get written (which would solve the problem) but that would
2713 require more intrusive changes to the g++ front end. */
2715 DECL_IGNORED_P (vars) = 1;
2718 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2721 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2722 /* We don't know what to do with this one yet. */
2725 /* We know that PREV must be non-zero here. */
2726 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2731 prune_vtable_vardecl (prev, vars)
2734 /* We know that PREV must be non-zero here. */
2735 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2740 walk_vtables (typedecl_fn, vardecl_fn)
2741 register void (*typedecl_fn) PROTO ((tree, tree));
2742 register int (*vardecl_fn) PROTO ((tree, tree));
2747 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2749 register tree type = TREE_TYPE (vars);
2751 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2754 flag |= (*vardecl_fn) (prev, vars);
2756 if (prev && TREE_CHAIN (prev) != vars)
2759 else if (TREE_CODE (vars) == TYPE_DECL
2760 && type != error_mark_node
2761 && TYPE_LANG_SPECIFIC (type)
2762 && CLASSTYPE_VSIZE (type))
2764 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2774 finish_sigtable_vardecl (prev, vars)
2777 /* We don't need to mark sigtable entries as addressable here as is done
2778 for vtables. Since sigtables, unlike vtables, are always written out,
2779 that was already done in build_signature_table_constructor. */
2781 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2783 /* We know that PREV must be non-zero here. */
2784 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2788 walk_sigtables (typedecl_fn, vardecl_fn)
2789 register void (*typedecl_fn) PROTO((tree, tree));
2790 register void (*vardecl_fn) PROTO((tree, tree));
2794 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2796 register tree type = TREE_TYPE (vars);
2798 if (TREE_CODE (vars) == TYPE_DECL
2799 && type != error_mark_node
2800 && IS_SIGNATURE (type))
2802 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2804 else if (TREE_CODE (vars) == VAR_DECL
2805 && TREE_TYPE (vars) != error_mark_node
2806 && IS_SIGNATURE (TREE_TYPE (vars)))
2808 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2815 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2816 inline function or template instantiation at end-of-file. */
2819 import_export_decl (decl)
2822 if (DECL_INTERFACE_KNOWN (decl))
2825 if (DECL_TEMPLATE_INSTANTIATION (decl))
2827 DECL_NOT_REALLY_EXTERN (decl) = 1;
2828 if (DECL_IMPLICIT_INSTANTIATION (decl)
2829 && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2831 if (!TREE_PUBLIC (decl))
2832 /* Templates are allowed to have internal linkage. See
2835 else if (TREE_CODE (decl) == FUNCTION_DECL)
2836 comdat_linkage (decl);
2838 DECL_COMDAT (decl) = 1;
2841 DECL_NOT_REALLY_EXTERN (decl) = 0;
2843 else if (DECL_FUNCTION_MEMBER_P (decl))
2845 tree ctype = DECL_CLASS_CONTEXT (decl);
2846 if (CLASSTYPE_INTERFACE_KNOWN (ctype)
2847 && (! DECL_ARTIFICIAL (decl) || DECL_VINDEX (decl)))
2849 DECL_NOT_REALLY_EXTERN (decl)
2850 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2851 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2854 comdat_linkage (decl);
2856 /* tinfo function */
2857 else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2859 tree ctype = TREE_TYPE (DECL_NAME (decl));
2860 if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2861 && TYPE_VIRTUAL_P (ctype)
2862 /* If the type is a cv-qualified variant of a type, then we
2863 must emit the tinfo function in this translation unit
2864 since it will not be emitted when the vtable for the type
2865 is output (which is when the unqualified version is
2867 && ctype == TYPE_MAIN_VARIANT (ctype))
2869 DECL_NOT_REALLY_EXTERN (decl)
2870 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2871 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2873 /* For WIN32 we also want to put explicit instantiations in
2874 linkonce sections. */
2875 if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype))
2876 maybe_make_one_only (decl);
2878 else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2879 DECL_NOT_REALLY_EXTERN (decl) = 0;
2881 comdat_linkage (decl);
2884 comdat_linkage (decl);
2886 DECL_INTERFACE_KNOWN (decl) = 1;
2890 build_cleanup (decl)
2894 tree type = TREE_TYPE (decl);
2896 if (TREE_CODE (type) == ARRAY_TYPE)
2900 mark_addressable (decl);
2901 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2903 temp = build_delete (TREE_TYPE (temp), temp,
2905 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2909 extern int parse_time, varconst_time;
2910 extern tree pending_templates;
2911 extern tree maybe_templates;
2917 tree sname = get_id_2 ("__sn", base);
2918 /* For struct X foo __attribute__((weak)), there is a counter
2919 __snfoo. Since base is already an assembler name, sname should
2920 be globally unique */
2921 tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2924 push_obstacks_nochange ();
2925 end_temporary_allocation ();
2926 sentry = build_decl (VAR_DECL, sname, integer_type_node);
2927 TREE_PUBLIC (sentry) = 1;
2928 DECL_ARTIFICIAL (sentry) = 1;
2929 TREE_STATIC (sentry) = 1;
2930 TREE_USED (sentry) = 1;
2931 DECL_COMMON (sentry) = 1;
2932 pushdecl_top_level (sentry);
2933 cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2939 /* A list of objects which have constructors or destructors
2940 which reside in the global scope. The decl is stored in
2941 the TREE_VALUE slot and the initializer is stored
2942 in the TREE_PURPOSE slot. */
2943 extern tree static_aggregates_initp;
2945 /* Set up the static_aggregates* lists for processing. Subroutine of
2946 finish_file. Note that this function changes the format of
2947 static_aggregates_initp, from (priority . decl) to
2948 (priority . ((initializer . decl) ...)). */
2955 if (! flag_init_priority)
2957 for (t = static_aggregates_initp; t; t = TREE_CHAIN (t))
2958 cp_warning ("init_priority for `%#D' ignored without -finit-priority",
2963 /* First, remove any entries from static_aggregates that are also in
2964 static_aggregates_initp, and update the entries in _initp to
2965 include the initializer. */
2966 p = &static_aggregates;
2969 t = value_member (TREE_VALUE (*p), static_aggregates_initp);
2973 TREE_VALUE (t) = *p;
2974 *p = TREE_CHAIN (*p);
2975 TREE_CHAIN (TREE_VALUE (t)) = NULL_TREE;
2978 p = &TREE_CHAIN (*p);
2981 /* Then, group static_aggregates_initp. After this step, there will only
2982 be one entry for each priority, with a chain coming off it. */
2983 t = static_aggregates_initp;
2984 static_aggregates_initp = NULL_TREE;
2986 for (; t; t = next_t)
2988 next_t = TREE_CHAIN (t);
2990 for (p = &static_aggregates_initp; ; p = &TREE_CHAIN (*p))
2993 || tree_int_cst_lt (TREE_PURPOSE (*p), TREE_PURPOSE (t)))
2995 TREE_CHAIN (t) = *p;
2999 else if (tree_int_cst_equal (TREE_PURPOSE (*p), TREE_PURPOSE (t)))
3001 TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (*p);
3002 TREE_VALUE (*p) = TREE_VALUE (t);
3008 /* Reverse each list to preserve the order (currently reverse declaration
3009 order, for destructors). */
3010 for (t = static_aggregates_initp; t; t = TREE_CHAIN (t))
3011 TREE_VALUE (t) = nreverse (TREE_VALUE (t));
3014 /* Start the process of running a particular set of global constructors
3015 or destructors. Subroutine of do_[cd]tors. */
3018 start_objects (method_type, initp)
3019 int method_type, initp;
3024 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
3026 if (flag_init_priority)
3029 initp = DEFAULT_INIT_PRIORITY;
3031 sprintf (type, "%c%c%.5u", method_type, JOINER, initp);
3034 sprintf (type, "%c", method_type);
3036 fnname = get_file_function_name_long (type);
3038 start_function (void_list_node,
3039 make_call_declarator (fnname, void_list_node, NULL_TREE,
3043 store_parm_decls ();
3047 expand_start_bindings (0);
3050 /* Finish the process of running a particular set of global constructors
3051 or destructors. Subroutine of do_[cd]tors. */
3054 finish_objects (method_type, initp)
3055 int method_type, initp;
3061 tree list = (method_type == 'I' ? static_ctors : static_dtors);
3063 if (! current_function_decl && list)
3064 start_objects (method_type, initp);
3066 for (; list; list = TREE_CHAIN (list))
3067 expand_expr_stmt (build_function_call (TREE_VALUE (list), NULL_TREE));
3070 if (! current_function_decl)
3073 fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3076 expand_end_bindings (getdecls (), 1, 0);
3079 finish_function (lineno, 0, 0);
3081 if (! flag_init_priority)
3083 if (method_type == 'I')
3084 assemble_constructor (fnname);
3086 assemble_destructor (fnname);
3089 #ifdef ASM_OUTPUT_SECTION_NAME
3090 /* If we're using init priority we can't use assemble_*tor, but on ELF
3091 targets we can stick the references into named sections for GNU ld
3093 if (flag_init_priority)
3097 initp = DEFAULT_INIT_PRIORITY;
3098 sprintf (buf, ".%ctors.%.5u", method_type == 'I' ? 'c' : 'd',
3099 /* invert the numbering so the linker puts us in the proper
3100 order; constructors are run from right to left, and the
3101 linker sorts in increasing order. */
3102 MAX_INIT_PRIORITY - initp);
3103 named_section (NULL_TREE, buf, 0);
3104 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, fnname),
3105 POINTER_SIZE / BITS_PER_UNIT, 1);
3110 /* Generate a function to run a set of global destructors. START is either
3111 NULL_TREE or a node indicating a set of destructors with the same
3112 init priority. Subroutine of finish_file. */
3123 initp = TREE_INT_CST_LOW (TREE_PURPOSE (start));
3124 vars = TREE_VALUE (start);
3129 vars = static_aggregates;
3132 for (; vars; vars = TREE_CHAIN (vars))
3134 tree decl = TREE_VALUE (vars);
3135 tree type = TREE_TYPE (decl);
3138 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
3139 && ! DECL_EXTERNAL (decl))
3141 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
3142 || DECL_ONE_ONLY (decl)
3143 || DECL_WEAK (decl)));
3145 if (! current_function_decl)
3146 start_objects ('D', initp);
3152 Access control for implicit calls to the constructors,
3153 the conversion functions, or the destructor called to
3154 create and destroy a static data member is per- formed as
3155 if these calls appeared in the scope of the member's
3158 we must convince enforce_access to let us access the
3160 if (member_p (decl))
3162 DECL_CLASS_CONTEXT (current_function_decl)
3163 = DECL_CONTEXT (decl);
3164 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
3167 temp = build_cleanup (decl);
3171 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
3172 sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
3173 sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
3174 expand_start_cond (sentry, 0);
3177 expand_expr_stmt (temp);
3182 /* Now that we're done with DECL we don't need to pretend to
3183 be a member of its class any longer. */
3184 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
3185 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
3189 finish_objects ('D', initp);
3192 /* Generate a function to run a set of global constructors. START is
3193 either NULL_TREE or a node indicating a set of constructors with the
3194 same init priority. Subroutine of finish_file. */
3205 initp = TREE_INT_CST_LOW (TREE_PURPOSE (start));
3206 vars = TREE_VALUE (start);
3211 vars = static_aggregates;
3214 /* Reverse the list so it's in the right order for ctors. */
3215 vars = nreverse (vars);
3217 for (; vars; vars = TREE_CHAIN (vars))
3219 tree decl = TREE_VALUE (vars);
3220 tree init = TREE_PURPOSE (vars);
3222 /* If this was a static attribute within some function's scope,
3223 then don't initialize it here. Also, don't bother
3224 with initializers that contain errors. */
3225 if (TREE_STATIC (vars)
3226 || DECL_EXTERNAL (decl)
3227 || (init && TREE_CODE (init) == TREE_LIST
3228 && value_member (error_mark_node, init)))
3231 if (TREE_CODE (decl) == VAR_DECL)
3233 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
3234 || DECL_ONE_ONLY (decl)
3235 || DECL_WEAK (decl)));
3237 if (! current_function_decl)
3238 start_objects ('I', initp);
3240 /* Set these global variables so that GDB at least puts
3241 us near the declaration which required the initialization. */
3242 input_filename = DECL_SOURCE_FILE (decl);
3243 lineno = DECL_SOURCE_LINE (decl);
3244 emit_note (input_filename, lineno);
3246 /* 9.5p5: The initializer of a static member of a class has
3247 the same access rights as a member function. */
3248 if (member_p (decl))
3250 DECL_CLASS_CONTEXT (current_function_decl)
3251 = DECL_CONTEXT (decl);
3252 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
3257 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
3258 sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
3259 sentry = build_binary_op
3260 (EQ_EXPR, sentry, integer_one_node, 1);
3261 expand_start_cond (sentry, 0);
3264 expand_start_target_temps ();
3266 if (IS_AGGR_TYPE (TREE_TYPE (decl))
3267 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
3268 expand_aggr_init (decl, init, 0, 0);
3269 else if (TREE_CODE (init) == TREE_VEC)
3271 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
3272 TREE_VEC_ELT (init, 1),
3273 TREE_VEC_ELT (init, 2), 0),
3274 const0_rtx, VOIDmode, EXPAND_NORMAL);
3277 expand_assignment (decl, init, 0, 0);
3279 /* The expression might have involved increments and
3283 /* Cleanup any temporaries needed for the initial value. */
3284 expand_end_target_temps ();
3289 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
3290 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
3292 else if (decl == error_mark_node)
3295 my_friendly_abort (22);
3298 finish_objects ('I', initp);
3301 /* This routine is called from the last rule in yyparse ().
3302 Its job is to create all the code needed to initialize and
3303 destroy the global aggregates. We do the destruction
3304 first, since that way we only need to reverse the decls once. */
3310 int start_time, this_time;
3314 int needs_cleaning = 0, needs_messing_up = 0;
3318 /* Bad parse errors. Just forget about it. */
3319 if (! global_bindings_p () || current_class_type)
3322 check_decl_namespace ();
3324 start_time = get_run_time ();
3326 /* Otherwise, GDB can get confused, because in only knows
3327 about source for LINENO-1 lines. */
3330 interface_unknown = 1;
3333 for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
3335 tree srcloc = TREE_PURPOSE (fnname);
3336 tree decl = TREE_VALUE (fnname);
3338 input_filename = SRCLOC_FILE (srcloc);
3339 lineno = SRCLOC_LINE (srcloc);
3341 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
3343 instantiate_class_template (decl);
3344 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
3345 for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
3346 if (! DECL_ARTIFICIAL (vars))
3347 instantiate_decl (vars);
3350 instantiate_decl (decl);
3353 for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
3355 tree args, fn, decl = TREE_VALUE (fnname);
3357 if (DECL_INITIAL (decl))
3360 fn = TREE_PURPOSE (fnname);
3361 args = get_bindings (fn, decl, NULL_TREE);
3362 fn = instantiate_template (fn, args);
3363 instantiate_decl (fn);
3366 cat_namespace_levels();
3368 /* Push into C language context, because that's all
3370 push_lang_context (lang_name_c);
3373 /* The reason for pushing garbage onto the global_binding_level is to
3374 ensure that we can slice out _DECLs which pertain to virtual function
3375 tables. If the last thing pushed onto the global_binding_level was a
3376 virtual function table, then slicing it out would slice away all the
3377 decls (i.e., we lose the head of the chain).
3379 There are several ways of getting the same effect, from changing the
3380 way that iterators over the chain treat the elements that pertain to
3381 virtual function tables, moving the implementation of this code to
3382 decl.c (where we can manipulate global_binding_level directly),
3383 popping the garbage after pushing it and slicing away the vtable
3384 stuff, or just leaving it alone. */
3386 /* Make last thing in global scope not be a virtual function table. */
3387 #if 0 /* not yet, should get fixed properly later */
3388 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
3390 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
3392 DECL_IGNORED_P (vars) = 1;
3393 SET_DECL_ARTIFICIAL (vars);
3397 /* Walk to mark the inline functions we need, then output them so
3398 that we can pick up any other tdecls that those routines need. */
3399 walk_vtables ((void (*) PROTO ((tree, tree))) 0,
3400 finish_prevtable_vardecl);
3402 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
3403 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
3404 rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
3405 vars = static_aggregates;
3407 if (static_ctors || vars)
3408 needs_messing_up = 1;
3409 if (static_dtors || vars)
3414 /* After setup_initp, the aggregates are listed in reverse declaration
3415 order, for cleaning. */
3418 do_dtors (NULL_TREE);
3420 if (flag_init_priority)
3421 for (vars = static_aggregates_initp; vars; vars = TREE_CHAIN (vars))
3425 /* do_ctors will reverse the lists for messing up. */
3426 if (needs_messing_up)
3428 do_ctors (NULL_TREE);
3430 if (flag_init_priority)
3431 for (vars = static_aggregates_initp; vars; vars = TREE_CHAIN (vars))
3435 permanent_allocation (1);
3437 /* Done with C language context needs. */
3438 pop_lang_context ();
3440 /* Now write out any static class variables (which may have since
3441 learned how to be initialized). */
3442 while (pending_statics)
3444 tree decl = TREE_VALUE (pending_statics);
3446 /* Output DWARF debug information. */
3447 #ifdef DWARF_DEBUGGING_INFO
3448 if (write_symbols == DWARF_DEBUG)
3449 dwarfout_file_scope_decl (decl, 1);
3451 #ifdef DWARF2_DEBUGGING_INFO
3452 if (write_symbols == DWARF2_DEBUG)
3453 dwarf2out_decl (decl);
3456 DECL_DEFER_OUTPUT (decl) = 0;
3457 rest_of_decl_compilation
3458 (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3460 pending_statics = TREE_CHAIN (pending_statics);
3463 this_time = get_run_time ();
3464 parse_time -= this_time - start_time;
3465 varconst_time += this_time - start_time;
3467 start_time = get_run_time ();
3469 if (flag_handle_signatures)
3470 walk_sigtables ((void (*) PROTO ((tree, tree))) 0,
3471 finish_sigtable_vardecl);
3473 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3475 tree decl = TREE_VALUE (fnname);
3476 import_export_decl (decl);
3479 mark_all_runtime_matches ();
3481 /* Now write out inline functions which had their addresses taken and
3482 which were not declared virtual and which were not declared `extern
3485 int reconsider = 1; /* More may be referenced; check again */
3489 tree *p = &saved_inlines;
3492 /* We need to do this each time so that newly completed template
3493 types don't wind up at the front of the list. Sigh. */
3494 vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3495 DECL_IGNORED_P (vars) = 1;
3496 SET_DECL_ARTIFICIAL (vars);
3499 reconsider |= walk_vtables ((void (*) PROTO((tree, tree))) 0,
3500 finish_vtable_vardecl);
3504 tree decl = TREE_VALUE (*p);
3506 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3508 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3510 if (DECL_MUTABLE_P (decl))
3511 synthesize_tinfo_fn (decl);
3513 synthesize_method (decl);
3517 /* Catch new template instantiations. */
3518 if (decl != TREE_VALUE (*p))
3521 if (TREE_ASM_WRITTEN (decl)
3522 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3523 *p = TREE_CHAIN (*p);
3524 else if (DECL_INITIAL (decl) == 0)
3525 p = &TREE_CHAIN (*p);
3526 else if ((TREE_PUBLIC (decl) && ! DECL_COMDAT (decl))
3527 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3528 || flag_keep_inline_functions)
3530 if (DECL_NOT_REALLY_EXTERN (decl))
3532 DECL_EXTERNAL (decl) = 0;
3534 /* We can't inline this function after it's been
3535 emitted. We want a variant of
3536 output_inline_function that doesn't prevent
3537 subsequent integration... */
3538 DECL_INLINE (decl) = 0;
3539 output_inline_function (decl);
3540 permanent_allocation (1);
3543 *p = TREE_CHAIN (*p);
3546 p = &TREE_CHAIN (*p);
3550 /* It's possible that some of the remaining inlines will still be
3551 needed. For example, a static inline whose address is used in
3552 the initializer for a file-scope static variable will be
3553 needed. Code in compile_file will handle this, but we mustn't
3554 pretend that there are no definitions for the inlines, or it
3557 FIXME: This won't catch member functions. We should really
3558 unify this stuff with the compile_file stuff. */
3559 for (vars = saved_inlines; vars != NULL_TREE; vars = TREE_CHAIN (vars))
3561 tree decl = TREE_VALUE (vars);
3563 if (DECL_NOT_REALLY_EXTERN (decl)
3564 && !DECL_COMDAT (decl)
3565 && DECL_INITIAL (decl) != NULL_TREE)
3566 DECL_EXTERNAL (decl) = 0;
3570 /* Now delete from the chain of variables all virtual function tables.
3571 We output them all ourselves, because each will be treated specially. */
3573 walk_vtables ((void (*) PROTO((tree, tree))) 0,
3574 prune_vtable_vardecl);
3578 this_time = get_run_time ();
3579 parse_time -= this_time - start_time;
3580 varconst_time += this_time - start_time;
3582 if (flag_detailed_statistics)
3584 dump_tree_statistics ();
3585 dump_time_statistics ();
3589 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3590 expr. Since it was parsed like a type, we need to wade through and fix
3591 that. Unfortunately, since operator() is left-associative, we can't use
3592 tail recursion. In the above example, TYPE is `A', and DECL is
3595 Maybe this shouldn't be recursive, but how often will it actually be
3599 reparse_absdcl_as_expr (type, decl)
3602 /* do build_functional_cast (type, NULL_TREE) at bottom */
3603 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3604 return build_functional_cast (type, NULL_TREE);
3607 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3609 decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3611 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3612 decl = require_complete_type (decl);
3617 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3618 out to be an expr. Since it was parsed like a type, we need to wade
3619 through and fix that. Since casts are right-associative, we are
3620 reversing the order, so we don't have to recurse.
3622 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3626 reparse_absdcl_as_casts (decl, expr)
3631 if (TREE_CODE (expr) == CONSTRUCTOR
3632 && TREE_TYPE (expr) == 0)
3634 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3635 decl = TREE_OPERAND (decl, 0);
3637 if (IS_SIGNATURE (type))
3639 error ("cast specifies signature type");
3640 return error_mark_node;
3643 expr = digest_init (type, expr, (tree *) 0);
3644 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3646 int failure = complete_array_type (type, expr, 1);
3648 my_friendly_abort (78);
3654 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3655 decl = TREE_OPERAND (decl, 0);
3656 expr = build_c_cast (type, expr);
3659 if (warn_old_style_cast)
3660 warning ("use of old-style cast");
3665 /* Given plain tree nodes for an expression, build up the full semantics. */
3668 build_expr_from_tree (t)
3671 if (t == NULL_TREE || t == error_mark_node)
3674 switch (TREE_CODE (t))
3676 case IDENTIFIER_NODE:
3677 return do_identifier (t, 0, NULL_TREE);
3680 if (LOOKUP_EXPR_GLOBAL (t))
3681 return do_scoped_id (TREE_OPERAND (t, 0), 0);
3683 return do_identifier (TREE_OPERAND (t, 0), 0, NULL_TREE);
3685 case TEMPLATE_ID_EXPR:
3686 return (lookup_template_function
3687 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3688 build_expr_from_tree (TREE_OPERAND (t, 1))));
3691 return build_x_indirect_ref
3692 (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3695 return build_functional_cast
3696 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3698 case REINTERPRET_CAST_EXPR:
3699 return build_reinterpret_cast
3700 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3702 case CONST_CAST_EXPR:
3703 return build_const_cast
3704 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3706 case DYNAMIC_CAST_EXPR:
3707 return build_dynamic_cast
3708 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3710 case STATIC_CAST_EXPR:
3711 return build_static_cast
3712 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3714 case PREDECREMENT_EXPR:
3715 case PREINCREMENT_EXPR:
3716 case POSTDECREMENT_EXPR:
3717 case POSTINCREMENT_EXPR:
3721 case TRUTH_NOT_EXPR:
3723 case CONVERT_EXPR: /* Unary + */
3726 return build_x_unary_op (TREE_CODE (t),
3727 build_expr_from_tree (TREE_OPERAND (t, 0)));
3732 case TRUNC_DIV_EXPR:
3734 case FLOOR_DIV_EXPR:
3735 case ROUND_DIV_EXPR:
3736 case EXACT_DIV_EXPR:
3738 case BIT_ANDTC_EXPR:
3741 case TRUNC_MOD_EXPR:
3742 case FLOOR_MOD_EXPR:
3743 case TRUTH_ANDIF_EXPR:
3744 case TRUTH_ORIF_EXPR:
3745 case TRUTH_AND_EXPR:
3760 return build_x_binary_op
3762 build_expr_from_tree (TREE_OPERAND (t, 0)),
3763 build_expr_from_tree (TREE_OPERAND (t, 1)));
3766 return build_m_component_ref
3767 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3768 build_expr_from_tree (TREE_OPERAND (t, 1)));
3771 return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3774 if (TREE_OPERAND (t, 0) == NULL_TREE)
3776 return build_parse_node (ARRAY_REF, NULL_TREE,
3777 build_expr_from_tree (TREE_OPERAND (t, 1)));
3778 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3779 build_expr_from_tree (TREE_OPERAND (t, 1)));
3784 tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3785 if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3787 return TREE_CODE (t) == SIZEOF_EXPR ? c_sizeof (r) : c_alignof (r);
3791 return build_x_modify_expr
3792 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3793 TREE_CODE (TREE_OPERAND (t, 1)),
3794 build_expr_from_tree (TREE_OPERAND (t, 2)));
3797 return build_x_arrow
3798 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3802 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3803 build_expr_from_tree (TREE_OPERAND (t, 1)),
3804 build_expr_from_tree (TREE_OPERAND (t, 2)),
3805 NEW_EXPR_USE_GLOBAL (t));
3808 return delete_sanity
3809 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3810 build_expr_from_tree (TREE_OPERAND (t, 1)),
3811 DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3814 if (TREE_OPERAND (t, 1) == NULL_TREE)
3815 return build_x_compound_expr
3816 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3818 my_friendly_abort (42);
3820 case METHOD_CALL_EXPR:
3821 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3823 tree ref = TREE_OPERAND (t, 0);
3824 return build_scoped_method_call
3825 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3826 build_expr_from_tree (TREE_OPERAND (ref, 0)),
3827 TREE_OPERAND (ref, 1),
3828 build_expr_from_tree (TREE_OPERAND (t, 2)));
3830 return build_method_call
3831 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3832 TREE_OPERAND (t, 0),
3833 build_expr_from_tree (TREE_OPERAND (t, 2)),
3834 NULL_TREE, LOOKUP_NORMAL);
3837 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3839 tree ref = TREE_OPERAND (t, 0);
3840 return build_member_call
3841 (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3842 TREE_OPERAND (ref, 1),
3843 build_expr_from_tree (TREE_OPERAND (t, 1)));
3847 tree name = TREE_OPERAND (t, 0);
3849 tree args = build_expr_from_tree (TREE_OPERAND (t, 1));
3850 if (args != NULL_TREE && TREE_CODE (name) == LOOKUP_EXPR
3851 && !LOOKUP_EXPR_GLOBAL (name)
3852 && TREE_CODE ((id = TREE_OPERAND (name, 0))) == IDENTIFIER_NODE
3853 && (!current_class_type
3854 || !lookup_member (current_class_type, id, 0, 0)))
3856 /* Do Koenig lookup if there are no class members. */
3857 name = do_identifier (id, 0, args);
3859 else if (TREE_CODE (name) == TEMPLATE_ID_EXPR
3860 || ! really_overloaded_fn (name))
3861 name = build_expr_from_tree (name);
3862 return build_x_function_call (name, args, current_class_ref);
3866 return build_x_conditional_expr
3867 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3868 build_expr_from_tree (TREE_OPERAND (t, 1)),
3869 build_expr_from_tree (TREE_OPERAND (t, 2)));
3873 tree purpose, value, chain;
3875 if (t == void_list_node)
3878 purpose = TREE_PURPOSE (t);
3880 purpose = build_expr_from_tree (purpose);
3881 value = TREE_VALUE (t);
3883 value = build_expr_from_tree (value);
3884 chain = TREE_CHAIN (t);
3885 if (chain && chain != void_type_node)
3886 chain = build_expr_from_tree (chain);
3887 return expr_tree_cons (purpose, value, chain);
3891 return build_x_component_ref
3892 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3893 TREE_OPERAND (t, 1), NULL_TREE, 1);
3896 return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3902 /* digest_init will do the wrong thing if we let it. */
3903 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
3906 r = build_nt (CONSTRUCTOR, NULL_TREE,
3907 build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3910 return digest_init (TREE_TYPE (t), r, 0);
3915 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
3916 return get_typeid (TREE_OPERAND (t, 0));
3917 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3920 return convert_from_reference (t);
3927 /* This is something of the form `int (*a)++' that has turned out to be an
3928 expr. It was only converted into parse nodes, so we need to go through
3929 and build up the semantics. Most of the work is done by
3930 build_expr_from_tree, above.
3932 In the above example, TYPE is `int' and DECL is `*a'. */
3935 reparse_decl_as_expr (type, decl)
3938 decl = build_expr_from_tree (decl);
3940 return build_functional_cast (type, build_expr_list (NULL_TREE, decl));
3945 /* This is something of the form `int (*a)' that has turned out to be a
3946 decl. It was only converted into parse nodes, so we need to do the
3947 checking that make_{pointer,reference}_declarator do. */
3950 finish_decl_parsing (decl)
3953 extern int current_class_depth;
3955 switch (TREE_CODE (decl))
3957 case IDENTIFIER_NODE:
3960 return make_pointer_declarator
3961 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3963 return make_reference_declarator
3964 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3966 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3969 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3970 TREE_COMPLEXITY (decl) = current_class_depth;
3973 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3976 my_friendly_abort (5);
3982 check_cp_case_value (value)
3985 if (value == NULL_TREE)
3988 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3989 STRIP_TYPE_NOPS (value);
3991 if (TREE_READONLY_DECL_P (value))
3993 value = decl_constant_value (value);
3994 STRIP_TYPE_NOPS (value);
3996 value = fold (value);
3998 if (TREE_CODE (value) != INTEGER_CST
3999 && value != error_mark_node)
4001 cp_error ("case label `%E' does not reduce to an integer constant",
4003 value = error_mark_node;
4006 /* Promote char or short to int. */
4007 value = default_conversion (value);
4009 constant_expression_warning (value);
4014 /* Return 1 if root encloses child. */
4017 is_namespace_ancestor (root, child)
4022 if (root == global_namespace)
4024 if (child == global_namespace)
4026 return is_namespace_ancestor (root, CP_DECL_CONTEXT (child));
4030 /* Return the namespace that is the common ancestor
4031 of two given namespaces. */
4034 namespace_ancestor (ns1, ns2)
4037 if (is_namespace_ancestor (ns1, ns2))
4039 return namespace_ancestor (CP_DECL_CONTEXT (ns1), ns2);
4042 /* Insert used into the using list of user. Set indirect_flag if this
4043 directive is not directly from the source. Also find the common
4044 ancestor and let our users know about the new namespace */
4046 add_using_namespace (user, used, indirect)
4052 /* Using oneself is a no-op. */
4055 my_friendly_assert (TREE_CODE (user) == NAMESPACE_DECL, 380);
4056 my_friendly_assert (TREE_CODE (used) == NAMESPACE_DECL, 380);
4057 /* Check if we already have this. */
4058 t = purpose_member (used, DECL_NAMESPACE_USING (user));
4062 /* Promote to direct usage. */
4063 TREE_INDIRECT_USING (t) = 0;
4067 /* Add used to the user's using list. */
4068 DECL_NAMESPACE_USING (user)
4069 = perm_tree_cons (used, namespace_ancestor (user, used),
4070 DECL_NAMESPACE_USING (user));
4072 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user)) = indirect;
4074 /* Add user to the used's users list. */
4075 DECL_NAMESPACE_USERS (used)
4076 = perm_tree_cons (user, 0, DECL_NAMESPACE_USERS (used));
4078 /* Recursively add all namespaces used. */
4079 for (t = DECL_NAMESPACE_USING (used); t; t = TREE_CHAIN (t))
4080 /* indirect usage */
4081 add_using_namespace (user, TREE_PURPOSE (t), 1);
4083 /* Tell everyone using us about the new used namespaces. */
4084 for (t = DECL_NAMESPACE_USERS (user); t; t = TREE_CHAIN (t))
4085 add_using_namespace (TREE_PURPOSE (t), used, 1);
4088 /* Combines two sets of overloaded functions into an OVERLOAD chain.
4089 The first list becomes the tail of the result. */
4092 merge_functions (s1, s2)
4096 if (TREE_CODE (s2) == OVERLOAD)
4099 s1 = build_overload (OVL_FUNCTION (s2), s1);
4100 s2 = OVL_CHAIN (s2);
4103 s1 = build_overload (s2, s1);
4107 /* This should return an error not all definitions define functions.
4108 It is not an error if we find two functions with exactly the
4109 same signature, only if these are selected in overload resolution.
4110 old is the current set of bindings, new the freshly-found binding.
4111 XXX Do we want to give *all* candidates in case of ambiguity?
4112 XXX In what way should I treat extern declarations?
4113 XXX I don't want to repeat the entire duplicate_decls here */
4116 ambiguous_decl (name, old, new, flags)
4123 my_friendly_assert (old != NULL_TREE, 393);
4124 /* Copy the value. */
4125 val = BINDING_VALUE (new);
4127 switch (TREE_CODE (val))
4130 /* If we expect types or namespaces, and not templates,
4131 or this is not a template class. */
4132 if (LOOKUP_QUALIFIERS_ONLY (flags)
4133 && (!(flags & LOOKUP_TEMPLATES_EXPECTED)
4134 || !DECL_CLASS_TEMPLATE_P (val)))
4138 if (LOOKUP_NAMESPACES_ONLY (flags))
4141 case NAMESPACE_DECL:
4142 if (LOOKUP_TYPES_ONLY (flags))
4146 if (LOOKUP_QUALIFIERS_ONLY (flags))
4150 if (!BINDING_VALUE (old))
4151 BINDING_VALUE (old) = val;
4152 else if (val && val != BINDING_VALUE (old))
4154 if (is_overloaded_fn (BINDING_VALUE (old))
4155 && is_overloaded_fn (val))
4157 BINDING_VALUE (old) = merge_functions (BINDING_VALUE (old),
4162 /* Some declarations are functions, some are not. */
4163 if (flags & LOOKUP_COMPLAIN)
4165 cp_error ("use of `%D' is ambiguous", name);
4166 cp_error_at (" first declared as `%#D' here",
4167 BINDING_VALUE (old));
4168 cp_error_at (" also declared as `%#D' here", val);
4170 return error_mark_node;
4173 /* ... and copy the type. */
4174 type = BINDING_TYPE (new);
4175 if (LOOKUP_NAMESPACES_ONLY (flags))
4177 if (!BINDING_TYPE (old))
4178 BINDING_TYPE (old) = type;
4179 else if (type && BINDING_TYPE (old) != type)
4181 if (flags & LOOKUP_COMPLAIN)
4183 cp_error ("`%D' denotes an ambiguous type",name);
4184 cp_error_at (" first type here", BINDING_TYPE (old));
4185 cp_error_at (" other type here", type);
4191 /* Add the bindings of name in used namespaces to val.
4192 The using list is defined by usings, and the lookup goes to scope.
4193 Returns zero on errors. */
4196 lookup_using_namespace (name, val, usings, scope, flags)
4197 tree name, val, usings, scope;
4202 /* Iterate over all used namespaces in current, searching for using
4203 directives of scope. */
4204 for (iter = usings; iter; iter = TREE_CHAIN (iter))
4205 if (TREE_VALUE (iter) == scope)
4207 val1 = binding_for_name (name, TREE_PURPOSE (iter));
4208 /* Resolve ambiguities. */
4209 val = ambiguous_decl (name, val, val1, flags);
4211 return val != error_mark_node;
4215 Excepts the name to lookup and its qualifying scope.
4216 Returns the name/type pair found into the CPLUS_BINDING result,
4220 qualified_lookup_using_namespace (name, scope, result, flags)
4226 /* Maintain a list of namespaces visited... */
4227 tree seen = NULL_TREE;
4228 /* ... and a list of namespace yet to see. */
4229 tree todo = NULL_TREE;
4231 while (scope && (result != error_mark_node))
4233 seen = temp_tree_cons (scope, NULL_TREE, seen);
4234 result = ambiguous_decl (name, result,
4235 binding_for_name (name, scope), flags);
4236 if (!BINDING_VALUE (result) && !BINDING_TYPE (result))
4237 /* Consider using directives. */
4238 for (usings = DECL_NAMESPACE_USING (scope); usings;
4239 usings = TREE_CHAIN (usings))
4240 /* If this was a real directive, and we have not seen it. */
4241 if (!TREE_INDIRECT_USING (usings)
4242 && !purpose_member (TREE_PURPOSE (usings), seen))
4243 todo = temp_tree_cons (TREE_PURPOSE (usings), NULL_TREE, todo);
4246 scope = TREE_PURPOSE (todo);
4247 todo = TREE_CHAIN (todo);
4250 scope = NULL_TREE; /* If there never was a todo list. */
4252 return result != error_mark_node;
4255 /* [namespace.memdef]/2 */
4257 /* Set the context of a declaration to scope. Complain if we are not
4261 set_decl_namespace (decl, scope)
4266 if (scope == std_node)
4267 scope = global_namespace;
4268 /* Get rid of namespace aliases. */
4269 scope = ORIGINAL_NAMESPACE (scope);
4271 if (!is_namespace_ancestor (current_namespace, scope))
4272 cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
4274 DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
4275 if (scope != current_namespace)
4277 /* See whether this has been declared in the namespace. */
4278 old = namespace_binding (DECL_NAME (decl), scope);
4280 /* No old declaration at all. */
4282 if (!is_overloaded_fn (decl))
4283 /* Don't compare non-function decls with decls_match here,
4284 since it can't check for the correct constness at this
4285 point. pushdecl will find those errors later. */
4287 /* Since decl is a function, old should contain a function decl. */
4288 if (!is_overloaded_fn (old))
4290 for (; old; old = OVL_NEXT (old))
4291 if (decls_match (decl, OVL_CURRENT (old)))
4297 cp_error ("`%D' should have been declared inside `%D'",
4301 /* Compute the namespace where a declaration is defined. */
4304 decl_namespace (decl)
4307 while (DECL_CONTEXT (decl))
4309 decl = DECL_CONTEXT (decl);
4310 if (TREE_CODE (decl) == NAMESPACE_DECL)
4312 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
4313 decl = TYPE_STUB_DECL (decl);
4314 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', 390);
4317 return global_namespace;
4320 /* Return the namespace where the current declaration is declared. */
4323 current_decl_namespace ()
4326 /* If we have been pushed into a different namespace, use it. */
4327 if (decl_namespace_list)
4328 return TREE_PURPOSE (decl_namespace_list);
4330 if (current_class_type)
4331 result = decl_namespace (TYPE_STUB_DECL (current_class_type));
4332 else if (current_function_decl)
4333 result = decl_namespace (current_function_decl);
4335 result = current_namespace;
4339 /* Temporarily set the namespace for the current declaration. */
4342 push_decl_namespace (decl)
4345 if (TREE_CODE (decl) != NAMESPACE_DECL)
4346 decl = decl_namespace (decl);
4347 decl_namespace_list = tree_cons (decl, NULL_TREE, decl_namespace_list);
4351 pop_decl_namespace ()
4353 decl_namespace_list = TREE_CHAIN (decl_namespace_list);
4357 check_decl_namespace ()
4359 my_friendly_assert (decl_namespace_list == NULL_TREE, 980711);
4362 /* [basic.lookup.koenig] */
4363 /* A non-zero return value in the functions below indicates an error.
4364 All nodes allocated in the procedure are on the scratch obstack. */
4374 static int arg_assoc PROTO((struct arg_lookup*, tree));
4375 static int arg_assoc_args PROTO((struct arg_lookup*, tree));
4377 /* Add a function to the lookup structure.
4378 Returns 1 on error. */
4381 add_function (k, fn)
4382 struct arg_lookup *k;
4385 if (ovl_member (fn, k->functions))
4387 /* We must find only functions, or exactly one non-function. */
4388 if (k->functions && is_overloaded_fn (k->functions)
4389 && is_overloaded_fn (fn))
4390 k->functions = build_overload (fn, k->functions);
4394 tree f1 = OVL_CURRENT (k->functions);
4396 if (is_overloaded_fn (f1))
4398 fn = f1; f1 = f2; f2 = fn;
4400 cp_error_at ("`%D' is not a function,", f1);
4401 cp_error_at (" conflict with `%D'", f2);
4402 cp_error (" in call to `%D'", k->name);
4410 /* Add functions of a namespace to the lookup structure.
4411 Returns 1 on error. */
4414 arg_assoc_namespace (k, scope)
4415 struct arg_lookup *k;
4420 if (purpose_member (scope, k->namespaces))
4422 k->namespaces = tree_cons (scope, NULL_TREE, k->namespaces);
4424 value = namespace_binding (k->name, scope);
4428 for (; value; value = OVL_NEXT (value))
4429 if (add_function (k, OVL_CURRENT (value)))
4435 /* Adds everything associated with class to the lookup structure.
4436 Returns 1 on error. */
4439 arg_assoc_class (k, type)
4440 struct arg_lookup* k;
4443 tree list, friends, context;
4446 if (purpose_member (type, k->classes))
4448 k->classes = tree_cons (type, NULL_TREE, k->classes);
4450 context = decl_namespace (TYPE_MAIN_DECL (type));
4451 if (arg_assoc_namespace (k, context))
4454 /* Process baseclasses. */
4455 for (i = 0; i < CLASSTYPE_N_BASECLASSES (type); i++)
4456 if (arg_assoc_class (k, TYPE_BINFO_BASETYPE (type, i)))
4459 /* Process friends. */
4460 for (list = DECL_FRIENDLIST (TYPE_MAIN_DECL (type)); list;
4461 list = TREE_CHAIN (list))
4462 if (k->name == TREE_PURPOSE (list))
4463 for (friends = TREE_VALUE (list); friends;
4464 friends = TREE_CHAIN (friends))
4465 /* Only interested in global functions with potentially hidden
4466 (i.e. unqualified) declarations. */
4467 if (TREE_PURPOSE (list) == error_mark_node && TREE_VALUE (list)
4468 && decl_namespace (TREE_VALUE (list)) == context)
4469 if (add_function (k, TREE_VALUE (list)))
4472 /* Process template arguments. */
4473 if (CLASSTYPE_TEMPLATE_INFO (type))
4475 list = innermost_args (CLASSTYPE_TI_ARGS (type));
4476 for (i = 0; i < TREE_VEC_LENGTH (list); ++i)
4477 arg_assoc (k, TREE_VEC_ELT (list, i));
4483 /* Adds everything associated with a given type.
4484 Returns 1 on error. */
4487 arg_assoc_type (k, type)
4488 struct arg_lookup *k;
4491 switch (TREE_CODE (type))
4501 if (TYPE_PTRMEMFUNC_P (type))
4502 return arg_assoc_type (k, TYPE_PTRMEMFUNC_FN_TYPE (type));
4503 return arg_assoc_class (k, type);
4505 case REFERENCE_TYPE:
4507 return arg_assoc_type (k, TREE_TYPE (type));
4510 return arg_assoc_namespace (k, decl_namespace (TYPE_MAIN_DECL (type)));
4512 /* Pointer to member: associate class type and value type. */
4513 if (arg_assoc_type (k, TYPE_OFFSET_BASETYPE (type)))
4515 return arg_assoc_type (k, TREE_TYPE (type));
4517 /* The basetype is referenced in the first arg type, so just
4520 /* Associate the parameter types. */
4521 if (arg_assoc_args (k, TYPE_ARG_TYPES (type)))
4523 /* Associate the return type. */
4524 return arg_assoc_type (k, TREE_TYPE (type));
4525 case TEMPLATE_TYPE_PARM:
4528 if (type == unknown_type_node)
4530 /* else fall through */
4532 my_friendly_abort (390);
4537 /* Adds everything associated with arguments. Returns 1 on error. */
4540 arg_assoc_args (k, args)
4541 struct arg_lookup* k;
4544 for (; args; args = TREE_CHAIN (args))
4545 if (arg_assoc (k, TREE_VALUE (args)))
4550 /* Adds everything associated with a given tree_node. Returns 1 on error. */
4554 struct arg_lookup* k;
4557 if (n == error_mark_node)
4560 if (TREE_CODE_CLASS (TREE_CODE (n)) == 't')
4561 return arg_assoc_type (k, n);
4563 if (! type_unknown_p (n))
4564 return arg_assoc_type (k, TREE_TYPE (n));
4566 if (TREE_CODE (n) == ADDR_EXPR)
4567 n = TREE_OPERAND (n, 0);
4568 while (TREE_CODE (n) == TREE_LIST)
4571 my_friendly_assert (TREE_CODE (n) == OVERLOAD, 980715);
4573 for (; n; n = TREE_CHAIN (n))
4574 if (arg_assoc (k, OVL_FUNCTION (n)))
4580 /* Performs Koenig lookup depending on arguments, where fns
4581 are the functions found in normal lookup. */
4584 lookup_arg_dependent (name, fns, args)
4589 struct arg_lookup k;
4592 k.namespaces = NULL_TREE;
4593 k.classes = NULL_TREE;
4595 push_scratch_obstack ();
4596 arg_assoc_args (&k, args);
4601 /* Process a namespace-alias declaration. */
4604 do_namespace_alias (alias, namespace)
4605 tree alias, namespace;
4607 if (TREE_CODE (namespace) != NAMESPACE_DECL)
4609 /* The parser did not find it, so it's not there. */
4610 cp_error ("unknown namespace `%D'", namespace);
4614 namespace = ORIGINAL_NAMESPACE (namespace);
4616 /* Build the alias. */
4617 alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node);
4618 DECL_NAMESPACE_ALIAS (alias) = namespace;
4622 /* Check a non-member using-declaration. Return the name and scope
4623 being used, and the USING_DECL, or NULL_TREE on failure. */
4626 validate_nonmember_using_decl (decl, scope, name)
4631 if (TREE_CODE (decl) == SCOPE_REF
4632 && TREE_OPERAND (decl, 0) == std_node)
4634 if (TREE_CODE (decl) == SCOPE_REF)
4636 *scope = TREE_OPERAND (decl, 0);
4637 *name = TREE_OPERAND (decl, 1);
4639 else if (TREE_CODE (decl) == IDENTIFIER_NODE
4640 || TREE_CODE (decl) == TYPE_DECL)
4642 *scope = global_namespace;
4646 my_friendly_abort (382);
4647 if (TREE_CODE_CLASS (TREE_CODE (*name)) == 'd')
4648 *name = DECL_NAME (*name);
4649 /* Make a USING_DECL. */
4650 return push_using_decl (*scope, *name);
4653 /* Process local and global using-declarations. */
4656 do_nonmember_using_decl (scope, name, oldval, oldtype, newval, newtype)
4658 tree oldval, oldtype;
4659 tree *newval, *newtype;
4662 struct tree_binding _decls;
4664 *newval = *newtype = NULL_TREE;
4665 decls = binding_init (&_decls);
4666 if (!qualified_lookup_using_namespace (name, scope, decls, 0))
4670 if (!BINDING_VALUE (decls) && !BINDING_TYPE (decls))
4672 cp_error ("`%D' not declared", name);
4676 /* Check for using functions. */
4677 if (BINDING_VALUE (decls) && is_overloaded_fn (BINDING_VALUE (decls)))
4681 if (oldval && !is_overloaded_fn (oldval))
4683 duplicate_decls (OVL_CURRENT (BINDING_VALUE (decls)), oldval);
4688 for (tmp = BINDING_VALUE (decls); tmp; tmp = OVL_NEXT (tmp))
4690 /* Compare each new function with each old one.
4691 If the old function was also used, there is no conflict. */
4692 for (tmp1 = oldval; tmp1; tmp1 = OVL_NEXT (tmp1))
4693 if (OVL_CURRENT (tmp) == OVL_CURRENT (tmp1))
4695 else if (OVL_USED (tmp1))
4697 else if (duplicate_decls (OVL_CURRENT (tmp), OVL_CURRENT (tmp1)))
4700 /* Duplicate use, ignore */
4704 *newval = build_overload (OVL_CURRENT (tmp), *newval);
4705 if (TREE_CODE (*newval) != OVERLOAD)
4706 *newval = ovl_cons (*newval, NULL_TREE);
4707 OVL_USED (*newval) = 1;
4712 *newval = BINDING_VALUE (decls);
4714 duplicate_decls (*newval, oldval);
4717 *newtype = BINDING_TYPE (decls);
4718 if (oldtype && *newtype && oldtype != *newtype)
4720 cp_error ("using directive `%D' introduced ambiguous type `%T'",
4726 /* Process a using-declaration not appearing in class or local scope. */
4729 do_toplevel_using_decl (decl)
4732 tree scope, name, binding;
4733 tree oldval, oldtype, newval, newtype;
4735 decl = validate_nonmember_using_decl (decl, &scope, &name);
4736 if (decl == NULL_TREE)
4739 binding = binding_for_name (name, current_namespace);
4741 oldval = BINDING_VALUE (binding);
4742 oldtype = BINDING_TYPE (binding);
4744 do_nonmember_using_decl (scope, name, oldval, oldtype, &newval, &newtype);
4746 /* Copy declarations found. */
4748 BINDING_VALUE (binding) = newval;
4750 BINDING_TYPE (binding) = newtype;
4754 /* Process a using-declaration at function scope. */
4757 do_local_using_decl (decl)
4761 tree oldval, oldtype, newval, newtype;
4763 decl = validate_nonmember_using_decl (decl, &scope, &name);
4764 if (decl == NULL_TREE)
4767 oldval = lookup_name_current_level (name);
4768 oldtype = lookup_type_current_level (name);
4770 do_nonmember_using_decl (scope, name, oldval, oldtype, &newval, &newtype);
4773 set_identifier_local_value (name, newval);
4775 set_identifier_type_value (name, newtype);
4779 do_class_using_decl (decl)
4784 if (TREE_CODE (decl) != SCOPE_REF
4785 || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (decl, 0))) != 't')
4787 cp_error ("using-declaration for non-member at class scope");
4790 name = TREE_OPERAND (decl, 1);
4791 if (TREE_CODE (name) == BIT_NOT_EXPR)
4793 cp_error ("using-declaration for destructor");
4796 if (TREE_CODE (name) == TYPE_DECL)
4797 name = DECL_NAME (name);
4799 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 980716);
4801 value = build_lang_field_decl (USING_DECL, name, void_type_node);
4802 DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
4806 /* Process a using-directive. */
4809 do_using_directive (namespace)
4812 if (namespace == std_node)
4814 /* using namespace A::B::C; */
4815 if (TREE_CODE (namespace) == SCOPE_REF)
4816 namespace = TREE_OPERAND (namespace, 1);
4817 if (TREE_CODE (namespace) == IDENTIFIER_NODE)
4819 /* Lookup in lexer did not find a namespace. */
4820 cp_error ("namespace `%T' undeclared", namespace);
4823 if (TREE_CODE (namespace) != NAMESPACE_DECL)
4825 cp_error ("`%T' is not a namespace", namespace);
4828 namespace = ORIGINAL_NAMESPACE (namespace);
4829 if (!toplevel_bindings_p ())
4830 push_using_directive (namespace);
4833 add_using_namespace (current_namespace, namespace, 0);
4837 check_default_args (x)
4840 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
4841 int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
4842 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
4844 if (TREE_PURPOSE (arg))
4848 cp_error_at ("default argument missing for parameter %P of `%+#D'",
4859 TREE_USED (decl) = 1;
4860 if (processing_template_decl)
4862 assemble_external (decl);
4864 /* Is it a synthesized method that needs to be synthesized? */
4865 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
4866 && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
4867 /* Kludge: don't synthesize for default args. */
4868 && current_function_decl)
4869 synthesize_method (decl);
4871 /* If this is a function or variable that is an instance of some
4872 template, we now know that we will need to actually do the
4873 instantiation. A TEMPLATE_DECL may also have DECL_TEMPLATE_INFO,
4874 if it's a partial instantiation, but there's no need to
4875 instantiate such a thing. We check that DECL is not an explicit
4876 instantiation because that is not checked in instantiate_decl. */
4877 if (TREE_CODE (decl) != TEMPLATE_DECL
4878 && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
4879 && !DECL_EXPLICIT_INSTANTIATION (decl))
4880 instantiate_decl (decl);
4883 /* Helper function for named_class_head_sans_basetype nonterminal. */
4886 handle_class_head (aggr, scope, id)
4887 tree aggr, scope, id;
4889 if (TREE_CODE (id) == TYPE_DECL)
4893 cp_error ("`%T' does not have a nested type named `%D'", scope, id);
4895 cp_error ("no file-scope type named `%D'", id);
4898 (aggr, make_anon_name (), 1);
4899 return TYPE_MAIN_DECL (id);