1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92-98, 1999 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
;
51 static tree get_sentry
PROTO((tree
));
52 static void mark_vtable_entries
PROTO((tree
));
53 static void grok_function_init
PROTO((tree
, tree
));
54 static int finish_vtable_vardecl
PROTO((tree
, tree
));
55 static int prune_vtable_vardecl
PROTO((tree
, tree
));
56 static void finish_sigtable_vardecl
PROTO((tree
, tree
));
57 static int is_namespace_ancestor
PROTO((tree
, tree
));
58 static void add_using_namespace
PROTO((tree
, tree
, int));
59 static tree ambiguous_decl
PROTO((tree
, tree
, tree
,int));
60 static tree build_anon_union_vars
PROTO((tree
, tree
*, int, int));
61 static int acceptable_java_type
PROTO((tree
));
62 static void output_vtable_inherit
PROTO((tree
));
63 static void setup_initp
PROTO((void));
64 static void start_objects
PROTO((int, int));
65 static void finish_objects
PROTO((int, int));
66 static void do_dtors
PROTO((tree
));
67 static void do_ctors
PROTO((tree
));
68 static tree merge_functions
PROTO((tree
, tree
));
69 static tree decl_namespace
PROTO((tree
));
70 static tree validate_nonmember_using_decl
PROTO((tree
, tree
*, tree
*));
71 static void do_nonmember_using_decl
PROTO((tree
, tree
, tree
, tree
,
74 extern int current_class_depth
;
76 /* A list of virtual function tables we must make sure to write out. */
79 /* A list of static class variables. This is needed, because a
80 static class variable can be declared inside the class without
81 an initializer, and then initialized, staticly, outside the class. */
84 /* A list of functions which were declared inline, but which we
85 may need to emit outline anyway. */
86 static tree saved_inlines
;
88 /* Used to help generate temporary names which are unique within
89 a function. Reset to 0 by start_function. */
91 int temp_name_counter
;
93 /* Same, but not reset. Local temp variables and global temp variables
94 can have the same name. */
95 static int global_temp_name_counter
;
97 /* Flag used when debugging spew.c */
99 extern int spew_debug
;
101 /* Nonzero if we're done parsing and into end-of-file activities. */
105 /* Functions called along with real static constructors and destructors. */
107 tree static_ctors
, static_dtors
;
109 /* The current open namespace, and ::. */
111 tree current_namespace
;
112 tree global_namespace
;
114 /* The stack for namespaces of current declarations. */
116 static tree decl_namespace_list
;
119 /* C (and C++) language-specific option variables. */
121 /* Nonzero means allow type mismatches in conditional expressions;
122 just make their values `void'. */
124 int flag_cond_mismatch
;
126 /* Nonzero means give `double' the same size as `float'. */
128 int flag_short_double
;
130 /* Nonzero means don't recognize the keyword `asm'. */
134 /* Nonzero means don't recognize any extension keywords. */
136 int flag_no_gnu_keywords
;
138 /* Nonzero means don't recognize the non-ANSI builtin functions. */
142 /* Nonzero means don't recognize the non-ANSI builtin functions.
145 int flag_no_nonansi_builtin
;
147 /* Nonzero means do some things the same way PCC does. Only provided so
148 the compiler will link. */
150 int flag_traditional
;
152 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
154 int flag_signed_bitfields
= 1;
156 /* Nonzero means enable obscure ANSI features and disable GNU extensions
157 that might cause ANSI-compliant code to be miscompiled. */
161 /* Nonzero means do emit exported implementations of functions even if
162 they can be inlined. */
164 int flag_implement_inlines
= 1;
166 /* Nonzero means do emit exported implementations of templates, instead of
167 multiple static copies in each file that needs a definition. */
169 int flag_external_templates
;
171 /* Nonzero means that the decision to emit or not emit the implementation of a
172 template depends on where the template is instantiated, rather than where
175 int flag_alt_external_templates
;
177 /* Nonzero means that implicit instantiations will be emitted if needed. */
179 int flag_implicit_templates
= 1;
181 /* Nonzero means that implicit instantiations of inline templates will be
182 emitted if needed, even if instantiations of non-inline templates
185 int flag_implicit_inline_templates
= 1;
187 /* Nonzero means warn about implicit declarations. */
189 int warn_implicit
= 1;
191 /* Nonzero means warn about usage of long long when `-pedantic'. */
193 int warn_long_long
= 1;
195 /* Nonzero means warn when all ctors or dtors are private, and the class
198 int warn_ctor_dtor_privacy
= 1;
200 /* True if we want to implement vtables using "thunks".
201 The default is off. */
203 #ifndef DEFAULT_VTABLE_THUNKS
204 #define DEFAULT_VTABLE_THUNKS 0
206 int flag_vtable_thunks
= DEFAULT_VTABLE_THUNKS
;
208 /* True if we want to deal with repository information. */
210 int flag_use_repository
;
212 /* Nonzero if we want to issue diagnostics that the standard says are not
215 int flag_optional_diags
= 1;
217 /* Nonzero means give string constants the type `const char *', as mandated
220 int flag_const_strings
= 1;
222 /* Nonzero means warn about deprecated conversion from string constant to
225 int warn_write_strings
;
227 /* Nonzero means warn about pointer casts that can drop a type qualifier
228 from the pointer target type. */
232 /* Nonzero means warn about sizeof(function) or addition/subtraction
233 of function pointers. */
235 int warn_pointer_arith
= 1;
237 /* Nonzero means warn for any function def without prototype decl. */
239 int warn_missing_prototypes
;
241 /* Nonzero means warn about multiple (redundant) decls for the same single
242 variable or function. */
244 int warn_redundant_decls
;
246 /* Warn if initializer is not completely bracketed. */
248 int warn_missing_braces
;
250 /* Warn about comparison of signed and unsigned values. */
252 int warn_sign_compare
;
254 /* Warn about *printf or *scanf format/argument anomalies. */
258 /* Warn about a subscript that has type char. */
260 int warn_char_subscripts
;
262 /* Warn if a type conversion is done that might have confusing results. */
266 /* Warn if adding () is suggested. */
268 int warn_parentheses
;
270 /* Non-zero means warn in function declared in derived class has the
271 same name as a virtual in the base class, but fails to match the
272 type signature of any virtual function in the base class. */
273 int warn_overloaded_virtual
;
275 /* Non-zero means warn when declaring a class that has a non virtual
276 destructor, when it really ought to have a virtual one. */
279 /* Non-zero means warn when a function is declared extern and later inline. */
280 int warn_extern_inline
;
282 /* Non-zero means warn when the compiler will reorder code. */
285 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
288 /* Non-zero means warn when we convert a pointer to member function
289 into a pointer to (void or function). */
290 int warn_pmf2ptr
= 1;
292 /* Nonzero means warn about violation of some Effective C++ style rules. */
296 /* Nonzero means warn where overload resolution chooses a promotion from
297 unsigned to signed over a conversion to an unsigned of the same size. */
301 /* Nonzero means warn when an old-style cast is used. */
303 int warn_old_style_cast
;
305 /* Warn about #pragma directives that are not recognised. */
307 int warn_unknown_pragmas
; /* Tri state variable. */
309 /* Nonzero means warn about use of multicharacter literals. */
311 int warn_multichar
= 1;
313 /* Nonzero means warn when non-templatized friend functions are
314 declared within a template */
316 int warn_nontemplate_friend
= 1;
318 /* Nonzero means `$' can be in an identifier. */
320 #ifndef DOLLARS_IN_IDENTIFIERS
321 #define DOLLARS_IN_IDENTIFIERS 1
323 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
325 /* Nonzero for -fno-strict-prototype switch: do not consider empty
326 argument prototype to mean function takes no arguments. */
328 int flag_strict_prototype
= 2;
329 int strict_prototype
= 1;
330 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
332 /* Nonzero means that labels can be used as first-class objects */
336 /* Non-zero means to collect statistics which might be expensive
337 and to print them when we are done. */
338 int flag_detailed_statistics
;
340 /* C++ specific flags. */
341 /* Zero means that `this' is a *const. This gives nice behavior in the
342 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
343 -2 means we're constructing an object and it has fixed type. */
345 int flag_this_is_variable
;
347 /* 3 means write out only virtuals function tables `defined'
348 in this implementation file.
349 0 means write out virtual function tables and give them
350 (C) static access (default). */
354 /* Nonzero means we should attempt to elide constructors when possible. */
356 int flag_elide_constructors
= 1;
358 /* Nonzero means recognize and handle signature language constructs. */
360 int flag_handle_signatures
;
362 /* Nonzero means that member functions defined in class scope are
363 inline by default. */
365 int flag_default_inline
= 1;
367 /* Controls whether compiler generates 'type descriptor' that give
368 run-time type information. */
371 /* Nonzero if we wish to output cross-referencing information
372 for the GNU class browser. */
373 extern int flag_gnu_xref
;
375 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
378 int flag_huge_objects
;
380 /* Nonzero if we want to conserve space in the .o files. We do this
381 by putting uninitialized data and runtime initialized data into
382 .common instead of .data at the expense of not flagging multiple
385 int flag_conserve_space
;
387 /* Nonzero if we want to obey access control semantics. */
389 int flag_access_control
= 1;
391 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
393 int flag_operator_names
;
395 /* Nonzero if we want to check the return value of new and avoid calling
396 constructors if it is a null pointer. */
400 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
401 initialization variables.
402 0: Old rules, set by -fno-for-scope.
403 2: New ANSI rules, set by -ffor-scope.
404 1: Try to implement new ANSI rules, but with backup compatibility
405 (and warnings). This is the default, for now. */
407 int flag_new_for_scope
= 1;
409 /* Nonzero if we want to emit defined symbols with common-like linkage as
410 weak symbols where possible, in order to conform to C++ semantics.
411 Otherwise, emit them as local symbols. */
415 /* Nonzero to enable experimental ABI changes. */
419 /* Nonzero to not ignore namespace std. */
423 /* Maximum template instantiation depth. Must be at least 17 for ANSI
426 int max_tinst_depth
= 17;
428 /* The name-mangling scheme to use. Must be 1 or greater to support
429 template functions with identical types, but different template
431 int name_mangling_version
= 2;
433 /* Nonzero means that guiding declarations are allowed. */
434 int flag_guiding_decls
;
436 /* Nonzero if squashed mangling is to be performed.
437 This uses the B and K codes to reference previously seen class types
438 and class qualifiers. */
439 int flag_do_squangling
;
441 /* Nonzero means output .vtable_{entry,inherit} for use in doing vtable gc. */
445 /* Nonzero means make the default pedwarns warnings instead of errors.
446 The value of this flag is ignored if -pedantic is specified. */
450 /* Table of language-dependent -f options.
451 STRING is the option name. VARIABLE is the address of the variable.
452 ON_VALUE is the value to store in VARIABLE
453 if `-fSTRING' is seen as an option.
454 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
456 static struct { const char *string
; int *variable
; int on_value
;}
460 {"signed-char", &flag_signed_char
, 1},
461 {"unsigned-char", &flag_signed_char
, 0},
462 {"signed-bitfields", &flag_signed_bitfields
, 1},
463 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
464 {"short-enums", &flag_short_enums
, 1},
465 {"short-double", &flag_short_double
, 1},
466 {"cond-mismatch", &flag_cond_mismatch
, 1},
467 {"asm", &flag_no_asm
, 0},
468 {"builtin", &flag_no_builtin
, 0},
470 /* C++-only options. */
471 {"access-control", &flag_access_control
, 1},
472 {"check-new", &flag_check_new
, 1},
473 {"conserve-space", &flag_conserve_space
, 1},
474 {"const-strings", &flag_const_strings
, 1},
475 {"default-inline", &flag_default_inline
, 1},
476 {"dollars-in-identifiers", &dollars_in_ident
, 1},
477 {"elide-constructors", &flag_elide_constructors
, 1},
478 {"external-templates", &flag_external_templates
, 1},
479 {"for-scope", &flag_new_for_scope
, 2},
480 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
481 {"handle-exceptions", &flag_exceptions
, 1},
482 {"handle-signatures", &flag_handle_signatures
, 1},
483 {"honor-std", &flag_honor_std
, 1},
484 {"huge-objects", &flag_huge_objects
, 1},
485 {"implement-inlines", &flag_implement_inlines
, 1},
486 {"implicit-inline-templates", &flag_implicit_inline_templates
, 1},
487 {"implicit-templates", &flag_implicit_templates
, 1},
488 {"labels-ok", &flag_labels_ok
, 1},
489 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
490 {"operator-names", &flag_operator_names
, 1},
491 {"optional-diags", &flag_optional_diags
, 1},
492 {"permissive", &flag_permissive
, 1},
493 {"repo", &flag_use_repository
, 1},
494 {"rtti", &flag_rtti
, 1},
495 {"squangle", &flag_do_squangling
, 1},
496 {"stats", &flag_detailed_statistics
, 1},
497 {"strict-prototype", &flag_strict_prototype
, 1},
498 {"this-is-variable", &flag_this_is_variable
, 1},
499 {"vtable-gc", &flag_vtable_gc
, 1},
500 {"vtable-thunks", &flag_vtable_thunks
, 1},
501 {"weak", &flag_weak
, 1},
502 {"xref", &flag_gnu_xref
, 1}
505 /* Decode the string P as a language-specific option.
506 Return the number of strings consumed for a valid option.
507 Otherwise return 0. */
510 lang_decode_option (argc
, argv
)
519 int strings_processed
;
522 strings_processed
= cpp_handle_option (&parse_in
, argc
, argv
);
524 strings_processed
= 0;
525 #endif /* ! USE_CPPLIB */
527 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
529 else if (p
[0] == '-' && p
[1] == 'f')
531 /* Some kind of -f option.
532 P's value is the option sans `-f'.
533 Search for it in the table of options. */
538 /* Try special -f options. */
540 if (!strcmp (p
, "handle-exceptions")
541 || !strcmp (p
, "no-handle-exceptions"))
542 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
544 if (!strcmp (p
, "memoize-lookups")
545 || !strcmp (p
, "no-memoize-lookups")
546 || !strcmp (p
, "save-memoized")
547 || !strcmp (p
, "no-save-memoized")
548 || !strcmp (p
, "no-all-virtual")
549 || !strcmp (p
, "no-enum-int-equiv")
550 || !strcmp (p
, "nonnull-objects")
551 || !strcmp (p
, "ansi-overloading"))
556 else if (!strcmp (p
, "all-virtual")
557 || !strcmp (p
, "enum-int-equiv")
558 || !strcmp (p
, "no-nonnull-objects")
559 || !strcmp (p
, "no-ansi-overloading"))
561 warning ("-f%s is no longer supported", p
);
564 else if (! strcmp (p
, "alt-external-templates"))
566 flag_external_templates
= 1;
567 flag_alt_external_templates
= 1;
570 else if (! strcmp (p
, "no-alt-external-templates"))
572 flag_alt_external_templates
= 0;
575 else if (!strcmp (p
, "repo"))
577 flag_use_repository
= 1;
578 flag_implicit_templates
= 0;
581 else if (!strcmp (p
, "guiding-decls"))
583 flag_guiding_decls
= 1;
584 name_mangling_version
= 0;
587 else if (!strcmp (p
, "no-guiding-decls"))
589 flag_guiding_decls
= 0;
592 else if (!strcmp (p
, "new-abi"))
595 flag_do_squangling
= 1;
597 flag_vtable_thunks
= 1;
599 else if (!strcmp (p
, "no-new-abi"))
602 flag_do_squangling
= 0;
605 else if (!strncmp (p
, "template-depth-", 15))
608 read_integral_parameter (p
+ 15, p
- 2, max_tinst_depth
);
610 else if (!strncmp (p
, "name-mangling-version-", 22))
612 name_mangling_version
=
613 read_integral_parameter (p
+ 22, p
- 2, name_mangling_version
);
616 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
619 if (!strcmp (p
, lang_f_options
[j
].string
))
621 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
622 /* A goto here would be cleaner,
623 but breaks the vax pcc. */
626 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
627 && ! strcmp (p
+3, lang_f_options
[j
].string
))
629 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
635 else if (p
[0] == '-' && p
[1] == 'W')
639 /* The -W options control the warning behavior of the compiler. */
642 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
645 if (!strcmp (p
, "implicit"))
646 warn_implicit
= setting
;
647 else if (!strcmp (p
, "long-long"))
648 warn_long_long
= setting
;
649 else if (!strcmp (p
, "return-type"))
650 warn_return_type
= setting
;
651 else if (!strcmp (p
, "ctor-dtor-privacy"))
652 warn_ctor_dtor_privacy
= setting
;
653 else if (!strcmp (p
, "write-strings"))
654 warn_write_strings
= setting
;
655 else if (!strcmp (p
, "cast-qual"))
656 warn_cast_qual
= setting
;
657 else if (!strcmp (p
, "char-subscripts"))
658 warn_char_subscripts
= setting
;
659 else if (!strcmp (p
, "pointer-arith"))
660 warn_pointer_arith
= setting
;
661 else if (!strcmp (p
, "missing-prototypes"))
662 warn_missing_prototypes
= setting
;
663 else if (!strcmp (p
, "redundant-decls"))
664 warn_redundant_decls
= setting
;
665 else if (!strcmp (p
, "missing-braces"))
666 warn_missing_braces
= setting
;
667 else if (!strcmp (p
, "sign-compare"))
668 warn_sign_compare
= setting
;
669 else if (!strcmp (p
, "format"))
670 warn_format
= setting
;
671 else if (!strcmp (p
, "conversion"))
672 warn_conversion
= setting
;
673 else if (!strcmp (p
, "parentheses"))
674 warn_parentheses
= setting
;
675 else if (!strcmp (p
, "non-virtual-dtor"))
676 warn_nonvdtor
= setting
;
677 else if (!strcmp (p
, "extern-inline"))
678 warn_extern_inline
= setting
;
679 else if (!strcmp (p
, "reorder"))
680 warn_reorder
= setting
;
681 else if (!strcmp (p
, "synth"))
682 warn_synth
= setting
;
683 else if (!strcmp (p
, "pmf-conversions"))
684 warn_pmf2ptr
= setting
;
685 else if (!strcmp (p
, "effc++"))
687 else if (!strcmp (p
, "sign-promo"))
688 warn_sign_promo
= setting
;
689 else if (!strcmp (p
, "old-style-cast"))
690 warn_old_style_cast
= setting
;
691 else if (!strcmp (p
, "overloaded-virtual"))
692 warn_overloaded_virtual
= setting
;
693 else if (!strcmp (p
, "multichar"))
694 warn_multichar
= setting
;
695 else if (!strcmp (p
, "unknown-pragmas"))
696 /* Set to greater than 1, so that even unknown pragmas in
697 system headers will be warned about. */
698 warn_unknown_pragmas
= setting
* 2;
699 else if (!strcmp (p
, "non-template-friend"))
700 warn_nontemplate_friend
= setting
;
701 else if (!strcmp (p
, "comment"))
702 ; /* cpp handles this one. */
703 else if (!strcmp (p
, "comments"))
704 ; /* cpp handles this one. */
705 else if (!strcmp (p
, "trigraphs"))
706 ; /* cpp handles this one. */
707 else if (!strcmp (p
, "import"))
708 ; /* cpp handles this one. */
709 else if (!strcmp (p
, "all"))
711 warn_return_type
= setting
;
712 warn_unused
= setting
;
713 warn_implicit
= setting
;
714 warn_switch
= setting
;
715 warn_format
= setting
;
716 warn_parentheses
= setting
;
717 warn_missing_braces
= setting
;
718 warn_sign_compare
= setting
;
719 warn_multichar
= setting
;
720 /* We save the value of warn_uninitialized, since if they put
721 -Wuninitialized on the command line, we need to generate a
722 warning about not using it without also specifying -O. */
723 if (warn_uninitialized
!= 1)
724 warn_uninitialized
= (setting
? 2 : 0);
725 /* Only warn about unknown pragmas that are not in system
727 warn_unknown_pragmas
= 1;
729 /* C++-specific warnings. */
730 warn_ctor_dtor_privacy
= setting
;
731 warn_nonvdtor
= setting
;
732 warn_reorder
= setting
;
733 warn_nontemplate_friend
= setting
;
735 else return strings_processed
;
737 else if (!strcmp (p
, "-ansi"))
738 flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
739 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
741 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
742 it's probably safe to assume no sane person would ever want to use this
743 under normal circumstances. */
744 else if (!strcmp (p
, "-spew-debug"))
748 return strings_processed
;
753 /* Incorporate `const' and `volatile' qualifiers for member functions.
754 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
755 QUALS is a list of qualifiers. */
758 grok_method_quals (ctype
, function
, quals
)
759 tree ctype
, function
, quals
;
761 tree fntype
= TREE_TYPE (function
);
762 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
763 int type_quals
= TYPE_UNQUALIFIED
;
764 int dup_quals
= TYPE_UNQUALIFIED
;
768 int tq
= cp_type_qual_from_rid (TREE_VALUE (quals
));
774 quals
= TREE_CHAIN (quals
);
778 if (dup_quals
!= TYPE_UNQUALIFIED
)
779 cp_error ("duplicate type qualifiers in %s declaration",
780 TREE_CODE (function
) == FUNCTION_DECL
781 ? "member function" : "type");
783 ctype
= cp_build_qualified_type (ctype
, type_quals
);
784 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
785 (TREE_CODE (fntype
) == METHOD_TYPE
786 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
787 : TYPE_ARG_TYPES (fntype
)));
789 fntype
= build_exception_variant (fntype
, raises
);
791 TREE_TYPE (function
) = fntype
;
795 /* Warn when -fexternal-templates is used and #pragma
796 interface/implementation is not used all the times it should be,
800 warn_if_unknown_interface (decl
)
803 static int already_warned
= 0;
804 if (already_warned
++)
807 if (flag_alt_external_templates
)
809 struct tinst_level
*til
= tinst_for_decl ();
811 char *sf
= input_filename
;
816 input_filename
= til
->file
;
818 cp_warning ("template `%#D' instantiated in file without #pragma interface",
824 cp_warning_at ("template `%#D' defined in file without #pragma interface",
828 /* A subroutine of the parser, to handle a component list. */
831 grok_x_components (specs
)
834 struct pending_inline
**p
;
837 specs
= strip_attrs (specs
);
839 check_tag_decl (specs
);
840 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
842 /* The only case where we need to do anything additional here is an
843 anonymous union field, e.g.: `struct S { union { int i; }; };'. */
844 if (t
== NULL_TREE
|| !ANON_UNION_TYPE_P (t
))
847 fixup_anonymous_union (t
);
848 finish_member_declaration (build_lang_field_decl (FIELD_DECL
,
852 /* Ignore any inline function definitions in the anonymous union
853 since an anonymous union may not have function members. */
854 p
= &pending_inlines
;
855 for (; *p
; *p
= (*p
)->next
)
856 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
860 /* Constructors for types with virtual baseclasses need an "in-charge" flag
861 saying whether this constructor is responsible for initialization of
862 virtual baseclasses or not. All destructors also need this "in-charge"
863 flag, which additionally determines whether or not the destructor should
864 free the memory for the object.
866 This function adds the "in-charge" flag to member function FN if
867 appropriate. It is called from grokclassfn and tsubst.
868 FN must be either a constructor or destructor. */
871 maybe_retrofit_in_chrg (fn
)
874 tree basetype
, arg_types
, parms
, parm
, fntype
;
876 if (DECL_CONSTRUCTOR_P (fn
)
877 && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CLASS_CONTEXT (fn
))
878 && ! DECL_CONSTRUCTOR_FOR_VBASE_P (fn
))
880 else if (! DECL_CONSTRUCTOR_P (fn
)
881 && TREE_CHAIN (DECL_ARGUMENTS (fn
)) == NULL_TREE
)
886 if (DECL_CONSTRUCTOR_P (fn
))
887 DECL_CONSTRUCTOR_FOR_VBASE_P (fn
) = 1;
889 /* First add it to DECL_ARGUMENTS... */
890 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
891 /* Mark the artificial `__in_chrg' parameter as "artificial". */
892 SET_DECL_ARTIFICIAL (parm
);
893 DECL_ARG_TYPE (parm
) = integer_type_node
;
894 TREE_READONLY (parm
) = 1;
895 parms
= DECL_ARGUMENTS (fn
);
896 TREE_CHAIN (parm
) = TREE_CHAIN (parms
);
897 TREE_CHAIN (parms
) = parm
;
899 /* ...and then to TYPE_ARG_TYPES. */
900 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
901 basetype
= TREE_TYPE (TREE_VALUE (arg_types
));
902 arg_types
= hash_tree_chain (integer_type_node
, TREE_CHAIN (arg_types
));
903 fntype
= build_cplus_method_type (basetype
, TREE_TYPE (TREE_TYPE (fn
)),
905 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)))
906 fntype
= build_exception_variant (fntype
,
907 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)));
908 TREE_TYPE (fn
) = fntype
;
911 /* Classes overload their constituent function names automatically.
912 When a function name is declared in a record structure,
913 its name is changed to it overloaded name. Since names for
914 constructors and destructors can conflict, we place a leading
917 CNAME is the name of the class we are grokking for.
919 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
921 FLAGS contains bits saying what's special about today's
922 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
924 If FUNCTION is a destructor, then we must add the `auto-delete' field
925 as a second parameter. There is some hair associated with the fact
926 that we must "declare" this variable in the manner consistent with the
927 way the rest of the arguments were declared.
929 QUALS are the qualifiers for the this pointer. */
932 grokclassfn (ctype
, function
, flags
, quals
)
933 tree ctype
, function
;
934 enum overload_flags flags
;
937 tree fn_name
= DECL_NAME (function
);
942 if (fn_name
== NULL_TREE
)
944 error ("name missing for member function");
945 fn_name
= get_identifier ("<anonymous>");
946 DECL_NAME (function
) = fn_name
;
950 qualtype
= grok_method_quals (ctype
, function
, quals
);
954 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
955 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
957 /* Must add the class instance variable up front. */
958 /* Right now we just make this a pointer. But later
959 we may wish to make it special. */
960 tree type
= TREE_VALUE (arg_types
);
963 if ((flag_this_is_variable
> 0)
964 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
967 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
968 /* Mark the artificial `this' parameter as "artificial". */
969 SET_DECL_ARTIFICIAL (parm
);
970 DECL_ARG_TYPE (parm
) = type
;
971 /* We can make this a register, so long as we don't
972 accidentally complain if someone tries to take its address. */
973 DECL_REGISTER (parm
) = 1;
975 TREE_READONLY (parm
) = 1;
976 TREE_CHAIN (parm
) = last_function_parms
;
977 last_function_parms
= parm
;
980 DECL_ARGUMENTS (function
) = last_function_parms
;
981 /* First approximations. */
982 DECL_CONTEXT (function
) = ctype
;
983 DECL_CLASS_CONTEXT (function
) = ctype
;
985 if (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
))
987 maybe_retrofit_in_chrg (function
);
988 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
991 if (flags
== DTOR_FLAG
)
993 DECL_ASSEMBLER_NAME (function
) = build_destructor_name (ctype
);
994 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
997 set_mangled_name_for_decl (function
);
1000 /* Work on the expr used by alignof (this is only called by the parser). */
1009 if (processing_template_decl
)
1010 return build_min (ALIGNOF_EXPR
, sizetype
, expr
);
1012 if (TREE_CODE (expr
) == COMPONENT_REF
1013 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1014 error ("`__alignof__' applied to a bit-field");
1016 if (TREE_CODE (expr
) == INDIRECT_REF
)
1018 best
= t
= TREE_OPERAND (expr
, 0);
1019 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1021 while (TREE_CODE (t
) == NOP_EXPR
1022 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1025 t
= TREE_OPERAND (t
, 0);
1026 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1027 if (thisalign
> bestalign
)
1028 best
= t
, bestalign
= thisalign
;
1030 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1034 /* ANSI says arrays and fns are converted inside comma.
1035 But we can't convert them in build_compound_expr
1036 because that would break commas in lvalues.
1037 So do the conversion here if operand was a comma. */
1038 if (TREE_CODE (expr
) == COMPOUND_EXPR
1039 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1040 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1041 expr
= default_conversion (expr
);
1042 return c_alignof (TREE_TYPE (expr
));
1046 /* Create an ARRAY_REF, checking for the user doing things backwards
1050 grok_array_decl (array_expr
, index_exp
)
1051 tree array_expr
, index_exp
;
1053 tree type
= TREE_TYPE (array_expr
);
1054 tree p1
, p2
, i1
, i2
;
1056 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1057 return error_mark_node
;
1058 if (processing_template_decl
)
1059 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
1060 array_expr
, index_exp
);
1062 if (type
== NULL_TREE
)
1064 /* Something has gone very wrong. Assume we are mistakenly reducing
1065 an expression instead of a declaration. */
1066 error ("parser may be lost: is there a '{' missing somewhere?");
1070 if (TREE_CODE (type
) == OFFSET_TYPE
1071 || TREE_CODE (type
) == REFERENCE_TYPE
)
1072 type
= TREE_TYPE (type
);
1074 /* If they have an `operator[]', use that. */
1075 if (IS_AGGR_TYPE (type
) || IS_AGGR_TYPE (TREE_TYPE (index_exp
)))
1076 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1077 array_expr
, index_exp
, NULL_TREE
);
1079 /* Otherwise, create an ARRAY_REF for a pointer or array type. It
1080 is a little-known fact that, if `a' is an array and `i' is an
1081 int, you can write `i[a]', which means the same thing as `a[i]'. */
1083 if (TREE_CODE (type
) == ARRAY_TYPE
)
1086 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1088 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1091 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1093 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1094 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1096 if ((p1
&& i2
) && (i1
&& p2
))
1097 error ("ambiguous conversion for array subscript");
1100 array_expr
= p1
, index_exp
= i2
;
1102 array_expr
= p2
, index_exp
= i1
;
1105 cp_error ("invalid types `%T[%T]' for array subscript",
1106 type
, TREE_TYPE (index_exp
));
1107 return error_mark_node
;
1110 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1111 error ("ambiguous conversion for array subscript");
1113 return build_array_ref (array_expr
, index_exp
);
1116 /* Given the cast expression EXP, checking out its validity. Either return
1117 an error_mark_node if there was an unavoidable error, return a cast to
1118 void for trying to delete a pointer w/ the value 0, or return the
1119 call to delete. If DOING_VEC is 1, we handle things differently
1120 for doing an array delete. If DOING_VEC is 2, they gave us the
1121 array size as an argument to delete.
1122 Implements ARM $5.3.4. This is called from the parser. */
1125 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1127 int doing_vec
, use_global_delete
;
1130 /* For a regular vector delete (aka, no size argument) we will pass
1131 this down as a NULL_TREE into build_vec_delete. */
1132 tree maxindex
= NULL_TREE
;
1134 if (exp
== error_mark_node
)
1137 if (processing_template_decl
)
1139 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
1140 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
1141 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
1145 if (TREE_CODE (exp
) == OFFSET_REF
)
1146 exp
= resolve_offset_ref (exp
);
1147 exp
= convert_from_reference (exp
);
1148 t
= stabilize_reference (exp
);
1149 t
= build_expr_type_conversion (WANT_POINTER
, t
, 1);
1151 if (t
== NULL_TREE
|| t
== error_mark_node
)
1153 cp_error ("type `%#T' argument given to `delete', expected pointer",
1155 return error_mark_node
;
1160 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1161 pedwarn ("anachronistic use of array size in vector delete");
1164 type
= TREE_TYPE (t
);
1166 /* As of Valley Forge, you can delete a pointer to const. */
1168 /* You can't delete functions. */
1169 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1171 error ("cannot delete a function");
1172 return error_mark_node
;
1175 /* An array can't have been allocated by new, so complain. */
1176 if (TREE_CODE (t
) == ADDR_EXPR
1177 && TREE_CODE (TREE_OPERAND (t
, 0)) == VAR_DECL
1178 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == ARRAY_TYPE
)
1179 cp_warning ("deleting array `%#D'", TREE_OPERAND (t
, 0));
1181 /* Deleting a pointer with the value zero is valid and has no effect. */
1182 if (integer_zerop (t
))
1183 return build1 (NOP_EXPR
, void_type_node
, t
);
1186 return build_vec_delete (t
, maxindex
, integer_one_node
,
1187 integer_zero_node
, use_global_delete
);
1190 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1191 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1193 /* Only do access checking here; we'll be calling op delete
1194 from the destructor. */
1195 tree tmp
= build_op_delete_call (DELETE_EXPR
, t
, size_zero_node
,
1196 LOOKUP_NORMAL
, NULL_TREE
);
1197 if (tmp
== error_mark_node
)
1198 return error_mark_node
;
1201 return build_delete (type
, t
, integer_three_node
,
1202 LOOKUP_NORMAL
, use_global_delete
);
1206 /* Report an error if the indicated template declaration is not the
1207 sort of thing that should be a member template. */
1210 check_member_template (tmpl
)
1215 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 0);
1216 decl
= DECL_TEMPLATE_RESULT (tmpl
);
1218 if (TREE_CODE (decl
) == FUNCTION_DECL
1219 || (TREE_CODE (decl
) == TYPE_DECL
1220 && IS_AGGR_TYPE (TREE_TYPE (decl
))))
1222 if (current_function_decl
)
1223 /* 14.5.2.2 [temp.mem]
1225 A local class shall not have member templates. */
1226 cp_error ("declaration of member template `%#D' in local class",
1229 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
1231 /* 14.5.2.3 [temp.mem]
1233 A member function template shall not be virtual. */
1235 ("invalid use of `virtual' in template declaration of `%#D'",
1237 DECL_VIRTUAL_P (decl
) = 0;
1240 /* The debug-information generating code doesn't know what to do
1241 with member templates. */
1242 DECL_IGNORED_P (tmpl
) = 1;
1245 cp_error ("template declaration of `%#D'", decl
);
1248 /* Return true iff TYPE is a valid Java parameter or return type. */
1251 acceptable_java_type (type
)
1254 if (TREE_CODE (type
) == VOID_TYPE
|| TYPE_FOR_JAVA (type
))
1256 if (TREE_CODE (type
) == POINTER_TYPE
)
1258 type
= TREE_TYPE (type
);
1259 if (TREE_CODE (type
) == RECORD_TYPE
)
1262 if (! TYPE_FOR_JAVA (type
))
1264 if (! CLASSTYPE_TEMPLATE_INFO (type
))
1266 args
= CLASSTYPE_TI_ARGS (type
);
1267 i
= TREE_VEC_LENGTH (args
);
1270 type
= TREE_VEC_ELT (args
, i
);
1271 if (TREE_CODE (type
) == POINTER_TYPE
)
1272 type
= TREE_TYPE (type
);
1273 if (! TYPE_FOR_JAVA (type
))
1282 /* For a METHOD in a Java class CTYPE, return 1 if
1283 the parameter and return types are valid Java types.
1284 Otherwise, print appropriate error messages, and return 0. */
1287 check_java_method (method
)
1291 tree arg_types
= TYPE_ARG_TYPES (TREE_TYPE (method
));
1292 tree ret_type
= TREE_TYPE (TREE_TYPE (method
));
1293 if (! acceptable_java_type (ret_type
))
1295 cp_error ("Java method '%D' has non-Java return type `%T'",
1299 for (; arg_types
!= NULL_TREE
; arg_types
= TREE_CHAIN (arg_types
))
1301 tree type
= TREE_VALUE (arg_types
);
1302 if (! acceptable_java_type (type
))
1304 cp_error ("Java method '%D' has non-Java parameter type `%T'",
1309 return jerr
? 0 : 1;
1312 /* Sanity check: report error if this function FUNCTION is not
1313 really a member of the class (CTYPE) it is supposed to belong to.
1314 CNAME is the same here as it is for grokclassfn above. */
1317 check_classfn (ctype
, function
)
1318 tree ctype
, function
;
1320 tree fn_name
= DECL_NAME (function
);
1321 tree fndecl
, fndecls
;
1322 tree method_vec
= CLASSTYPE_METHOD_VEC (complete_type (ctype
));
1326 if (DECL_USE_TEMPLATE (function
)
1327 && is_member_template (DECL_TI_TEMPLATE (function
)))
1328 /* Since this is a specialization of a member template,
1329 we're not going to find the declaration in the class.
1332 struct S { template <typename T> void f(T); };
1333 template <> void S::f(int);
1335 we're not going to find `S::f(int)', but there's no
1336 reason we should, either. We let our callers know we didn't
1337 find the method, but we don't complain. */
1340 if (method_vec
!= 0)
1342 methods
= &TREE_VEC_ELT (method_vec
, 0);
1343 end
= TREE_VEC_END (method_vec
);
1345 /* First suss out ctors and dtors. */
1346 if (*methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1347 && DECL_CONSTRUCTOR_P (function
))
1349 if (*++methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1350 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
)))
1353 while (++methods
!= end
&& *methods
)
1356 if (fn_name
== DECL_NAME (OVL_CURRENT (*methods
)))
1359 for (fndecls
= *methods
; fndecls
!= NULL_TREE
;
1360 fndecls
= OVL_NEXT (fndecls
))
1362 fndecl
= OVL_CURRENT (fndecls
);
1363 /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL, or
1364 for a for member function of a template class, is
1365 not mangled, so the check below does not work
1366 correctly in that case. Since mangled destructor
1367 names do not include the type of the arguments,
1368 we can't use this short-cut for them, either.
1369 (It's not legal to declare arguments for a
1370 destructor, but some people try.) */
1371 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
))
1372 && (DECL_ASSEMBLER_NAME (function
)
1373 != DECL_NAME (function
))
1374 && (DECL_ASSEMBLER_NAME (fndecl
)
1375 != DECL_NAME (fndecl
))
1376 && (DECL_ASSEMBLER_NAME (function
)
1377 == DECL_ASSEMBLER_NAME (fndecl
)))
1380 /* We cannot simply call decls_match because this
1381 doesn't work for static member functions that are
1382 pretending to be methods, and because the name
1383 may have been changed by asm("new_name"). */
1384 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1386 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1387 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1389 /* Get rid of the this parameter on functions that become
1391 if (DECL_STATIC_FUNCTION_P (fndecl
)
1392 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1393 p1
= TREE_CHAIN (p1
);
1395 if (same_type_p (TREE_TYPE (TREE_TYPE (function
)),
1396 TREE_TYPE (TREE_TYPE (fndecl
)))
1397 && compparms (p1
, p2
)
1398 && (DECL_TEMPLATE_SPECIALIZATION (function
)
1399 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
1400 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
1401 || (DECL_TI_TEMPLATE (function
)
1402 == DECL_TI_TEMPLATE (fndecl
))))
1411 if (methods
!= end
&& *methods
)
1413 tree fndecl
= *methods
;
1414 cp_error ("prototype for `%#D' does not match any in class `%T'",
1416 cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl
) ? "s are" : " is",
1417 OVL_CURRENT (fndecl
));
1418 while (fndecl
= OVL_NEXT (fndecl
), fndecl
)
1419 cp_error_at (" %#D", OVL_CURRENT(fndecl
));
1424 if (TYPE_SIZE (ctype
) == 0)
1425 incomplete_type_error (function
, ctype
);
1427 cp_error ("no `%#D' member function declared in class `%T'",
1431 /* If we did not find the method in the class, add it to avoid
1432 spurious errors (unless the CTYPE is not yet defined, in which
1433 case we'll only confuse ourselves when the function is declared
1434 properly within the class. */
1435 if (TYPE_SIZE (ctype
))
1436 add_method (ctype
, methods
, function
);
1440 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1441 of a structure component, returning a FIELD_DECL node.
1442 QUALS is a list of type qualifiers for this decl (such as for declaring
1443 const member functions).
1445 This is done during the parsing of the struct declaration.
1446 The FIELD_DECL nodes are chained together and the lot of them
1447 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1451 If class A defines that certain functions in class B are friends, then
1452 the way I have set things up, it is B who is interested in permission
1453 granted by A. However, it is in A's context that these declarations
1454 are parsed. By returning a void_type_node, class A does not attempt
1455 to incorporate the declarations of the friends within its structure.
1457 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1458 CHANGES TO CODE IN `start_method'. */
1461 grokfield (declarator
, declspecs
, init
, asmspec_tree
, attrlist
)
1462 tree declarator
, declspecs
, init
, asmspec_tree
, attrlist
;
1464 register tree value
;
1466 int flags
= LOOKUP_ONLYCONVERTING
;
1468 /* Convert () initializers to = initializers. */
1469 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1470 && TREE_CODE (declarator
) == CALL_EXPR
1471 && TREE_OPERAND (declarator
, 0)
1472 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1473 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1474 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1476 init
= TREE_OPERAND (declarator
, 1);
1477 declarator
= TREE_OPERAND (declarator
, 0);
1481 if (declspecs
== NULL_TREE
1482 && TREE_CODE (declarator
) == SCOPE_REF
1483 && TREE_CODE (TREE_OPERAND (declarator
, 1)) == IDENTIFIER_NODE
)
1485 /* Access declaration */
1486 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
1488 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
1489 pop_nested_class (1);
1490 return do_class_using_decl (declarator
);
1494 && TREE_CODE (init
) == TREE_LIST
1495 && TREE_VALUE (init
) == error_mark_node
1496 && TREE_CHAIN (init
) == NULL_TREE
)
1499 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, NULL_TREE
);
1500 if (! value
|| value
== error_mark_node
)
1501 /* friend or constructor went bad. */
1504 /* Pass friendly classes back. */
1505 if (TREE_CODE (value
) == VOID_TYPE
)
1506 return void_type_node
;
1508 if (DECL_NAME (value
) != NULL_TREE
1509 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1510 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1511 cp_error ("member `%D' conflicts with virtual function table field name",
1514 /* Stash away type declarations. */
1515 if (TREE_CODE (value
) == TYPE_DECL
)
1517 DECL_NONLOCAL (value
) = 1;
1518 DECL_CONTEXT (value
) = current_class_type
;
1519 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1521 /* Now that we've updated the context, we need to remangle the
1522 name for this TYPE_DECL. */
1523 DECL_ASSEMBLER_NAME (value
) = DECL_NAME (value
);
1524 if (!uses_template_parms (value
))
1525 DECL_ASSEMBLER_NAME (value
) =
1526 get_identifier (build_overload_name (TREE_TYPE (value
), 1, 1));
1528 pushdecl_class_level (value
);
1532 if (IS_SIGNATURE (current_class_type
)
1533 && TREE_CODE (value
) != FUNCTION_DECL
)
1535 error ("field declaration not allowed in signature");
1536 return void_type_node
;
1539 if (DECL_IN_AGGR_P (value
))
1541 cp_error ("`%D' is already defined in `%T'", value
,
1542 DECL_CONTEXT (value
));
1543 return void_type_node
;
1547 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1551 if (IS_SIGNATURE (current_class_type
)
1552 && TREE_CODE (value
) == FUNCTION_DECL
)
1554 error ("function declarations cannot have initializers in signature");
1557 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1559 grok_function_init (value
, init
);
1562 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1563 /* Already complained in grokdeclarator. */
1567 /* We allow initializers to become parameters to base
1569 if (TREE_CODE (init
) == TREE_LIST
)
1571 if (TREE_CHAIN (init
) == NULL_TREE
)
1572 init
= TREE_VALUE (init
);
1574 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1577 if (TREE_CODE (init
) == CONST_DECL
)
1578 init
= DECL_INITIAL (init
);
1579 else if (TREE_READONLY_DECL_P (init
))
1580 init
= decl_constant_value (init
);
1581 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1582 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1583 my_friendly_assert (TREE_PERMANENT (init
), 192);
1584 if (init
== error_mark_node
)
1585 /* We must make this look different than `error_mark_node'
1586 because `decl_const_value' would mis-interpret it
1587 as only meaning that this VAR_DECL is defined. */
1588 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1589 else if (processing_template_decl
)
1591 else if (! TREE_CONSTANT (init
))
1593 /* We can allow references to things that are effectively
1594 static, since references are initialized with the address. */
1595 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1596 || (TREE_STATIC (init
) == 0
1597 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1598 || DECL_EXTERNAL (init
) == 0)))
1600 error ("field initializer is not constant");
1601 init
= error_mark_node
;
1607 /* The corresponding pop_obstacks is in cp_finish_decl. */
1608 push_obstacks_nochange ();
1610 if (processing_template_decl
&& ! current_function_decl
1611 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1612 value
= push_template_decl (value
);
1614 check_template_shadow (value
);
1617 cplus_decl_attributes (value
, TREE_PURPOSE (attrlist
),
1618 TREE_VALUE (attrlist
));
1620 if (TREE_CODE (value
) == VAR_DECL
)
1622 my_friendly_assert (TREE_PUBLIC (value
), 0);
1624 /* We cannot call pushdecl here, because that would
1625 fill in the value of our TREE_CHAIN. Instead, we
1626 modify cp_finish_decl to do the right thing, namely, to
1627 put this decl out straight away. */
1628 /* current_class_type can be NULL_TREE in case of error. */
1629 if (asmspec
== 0 && current_class_type
)
1631 TREE_PUBLIC (value
) = 1;
1632 DECL_INITIAL (value
) = error_mark_node
;
1633 DECL_ASSEMBLER_NAME (value
)
1634 = build_static_name (current_class_type
, DECL_NAME (value
));
1636 if (! processing_template_decl
)
1637 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1639 /* Static consts need not be initialized in the class definition. */
1640 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1642 static int explanation
= 0;
1644 error ("initializer invalid for static member with constructor");
1645 if (explanation
++ == 0)
1646 error ("(you really want to initialize it separately)");
1649 /* Force the compiler to know when an uninitialized static
1650 const member is being used. */
1651 if (CP_TYPE_CONST_P (TREE_TYPE (value
)) && init
== 0)
1652 TREE_USED (value
) = 1;
1653 DECL_INITIAL (value
) = init
;
1654 DECL_IN_AGGR_P (value
) = 1;
1655 DECL_CONTEXT (value
) = current_class_type
;
1656 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1658 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1659 pushdecl_class_level (value
);
1662 if (TREE_CODE (value
) == FIELD_DECL
)
1666 /* This must override the asm specifier which was placed
1667 by grokclassfn. Lay this out fresh. */
1668 DECL_RTL (value
) = NULL_RTX
;
1669 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1671 if (DECL_INITIAL (value
) == error_mark_node
)
1672 init
= error_mark_node
;
1673 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1674 DECL_INITIAL (value
) = init
;
1675 DECL_IN_AGGR_P (value
) = 1;
1678 if (TREE_CODE (value
) == FUNCTION_DECL
)
1682 /* This must override the asm specifier which was placed
1683 by grokclassfn. Lay this out fresh. */
1684 DECL_RTL (value
) = NULL_RTX
;
1685 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1687 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1689 /* Pass friends back this way. */
1690 if (DECL_FRIEND_P (value
))
1691 return void_type_node
;
1693 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1694 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1695 cp_error ("method `%#D' of local class must be defined in class body",
1699 DECL_IN_AGGR_P (value
) = 1;
1702 my_friendly_abort (21);
1707 /* Like `grokfield', but for bitfields.
1708 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1711 grokbitfield (declarator
, declspecs
, width
)
1712 tree declarator
, declspecs
, width
;
1714 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1717 if (! value
) return NULL_TREE
; /* friends went bad. */
1719 /* Pass friendly classes back. */
1720 if (TREE_CODE (value
) == VOID_TYPE
)
1721 return void_type_node
;
1723 if (TREE_CODE (value
) == TYPE_DECL
)
1725 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1729 /* Usually, finish_struct_1 catches bitifields with invalid types.
1730 But, in the case of bitfields with function type, we confuse
1731 ourselves into thinking they are member functions, so we must
1733 if (TREE_CODE (value
) == FUNCTION_DECL
)
1735 cp_error ("cannot declare bitfield `%D' with funcion type",
1740 if (IS_SIGNATURE (current_class_type
))
1742 error ("field declaration not allowed in signature");
1743 return void_type_node
;
1746 if (DECL_IN_AGGR_P (value
))
1748 cp_error ("`%D' is already defined in the class %T", value
,
1749 DECL_CONTEXT (value
));
1750 return void_type_node
;
1753 GNU_xref_member (current_class_name
, value
);
1755 if (TREE_STATIC (value
))
1757 cp_error ("static member `%D' cannot be a bitfield", value
);
1760 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1762 if (width
!= error_mark_node
)
1764 constant_expression_warning (width
);
1765 DECL_INITIAL (value
) = width
;
1766 SET_DECL_C_BIT_FIELD (value
);
1769 DECL_IN_AGGR_P (value
) = 1;
1774 grokoptypename (declspecs
, declarator
)
1775 tree declspecs
, declarator
;
1777 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1778 return build_typename_overload (t
);
1781 /* When a function is declared with an initializer,
1782 do the right thing. Currently, there are two possibilities:
1787 // initialization possibility #1.
1788 virtual void f () = 0;
1810 // initialization possibility #2
1817 copy_assignment_arg_p (parmtype
, virtualp
)
1819 int virtualp ATTRIBUTE_UNUSED
;
1821 if (current_class_type
== NULL_TREE
)
1824 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1825 parmtype
= TREE_TYPE (parmtype
);
1827 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1829 /* Non-standard hack to support old Booch components. */
1830 || (! virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
))
1839 grok_function_init (decl
, init
)
1843 /* An initializer for a function tells how this function should
1845 tree type
= TREE_TYPE (decl
);
1847 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1848 cp_error ("initializer specified for non-member function `%D'", decl
);
1850 /* We'll check for this in finish_struct_1. */
1851 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1852 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1854 else if (integer_zerop (init
))
1857 /* Mark this function as being "defined". */
1858 DECL_INITIAL (decl
) = error_mark_node
;
1859 /* pure virtual destructors must be defined. */
1860 /* pure virtual needs to be defined (as abort) only when put in
1861 vtbl. For wellformed call, it should be itself. pr4737 */
1862 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1864 extern tree abort_fndecl
;
1865 /* Give this node rtl from `abort'. */
1866 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1869 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1870 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1873 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1875 if (copy_assignment_arg_p (parmtype
, 1))
1876 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1880 cp_error ("invalid initializer for virtual method `%D'", decl
);
1884 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1885 tree decl
, attributes
, prefix_attributes
;
1887 if (decl
== NULL_TREE
|| decl
== void_type_node
)
1890 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1891 decl
= DECL_TEMPLATE_RESULT (decl
);
1893 decl_attributes (decl
, attributes
, prefix_attributes
);
1895 if (TREE_CODE (decl
) == TYPE_DECL
)
1896 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
1899 /* CONSTRUCTOR_NAME:
1900 Return the name for the constructor (or destructor) for the
1901 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1902 IDENTIFIER_NODE. When given a template, this routine doesn't
1903 lose the specialization. */
1906 constructor_name_full (thing
)
1909 if (TREE_CODE (thing
) == TEMPLATE_TYPE_PARM
1910 || TREE_CODE (thing
) == TEMPLATE_TEMPLATE_PARM
1911 || TREE_CODE (thing
) == TYPENAME_TYPE
)
1912 thing
= TYPE_NAME (thing
);
1913 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
1915 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
1916 thing
= DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing
), 0)));
1918 thing
= TYPE_NAME (thing
);
1920 if (TREE_CODE (thing
) == TYPE_DECL
1921 || (TREE_CODE (thing
) == TEMPLATE_DECL
1922 && TREE_CODE (DECL_TEMPLATE_RESULT (thing
)) == TYPE_DECL
))
1923 thing
= DECL_NAME (thing
);
1924 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
1928 /* CONSTRUCTOR_NAME:
1929 Return the name for the constructor (or destructor) for the
1930 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1931 IDENTIFIER_NODE. When given a template, return the plain
1932 unspecialized name. */
1935 constructor_name (thing
)
1939 thing
= constructor_name_full (thing
);
1940 t
= IDENTIFIER_TEMPLATE (thing
);
1946 /* Cache the value of this class's main virtual function table pointer
1947 in a register variable. This will save one indirection if a
1948 more than one virtual function call is made this function. */
1953 extern tree base_init_expr
;
1955 if (base_init_expr
== 0
1956 && DECL_CONSTRUCTOR_P (current_function_decl
))
1958 if (processing_template_decl
)
1959 add_tree (build_min_nt
1961 current_member_init_list
, current_base_init_list
));
1963 emit_base_init (current_class_type
, 0);
1967 /* Record the existence of an addressable inline function. */
1970 mark_inline_for_output (decl
)
1973 decl
= DECL_MAIN_VARIANT (decl
);
1974 if (DECL_SAVED_INLINE (decl
))
1976 my_friendly_assert (TREE_PERMANENT (decl
), 363);
1977 DECL_SAVED_INLINE (decl
) = 1;
1979 if (DECL_PENDING_INLINE_INFO (decl
) != 0
1980 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
1982 struct pending_inline
*t
= pending_inlines
;
1983 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
1986 if (t
== DECL_PENDING_INLINE_INFO (decl
))
1992 t
= DECL_PENDING_INLINE_INFO (decl
);
1993 t
->next
= pending_inlines
;
1994 pending_inlines
= t
;
1996 DECL_PENDING_INLINE_INFO (decl
) = 0;
1999 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
2005 temp_name_counter
= 0;
2008 /* Hand off a unique name which can be used for variable we don't really
2009 want to know about anyway, for example, the anonymous variables which
2010 are needed to make references work. Declare this thing so we can use it.
2011 The variable created will be of type TYPE.
2013 STATICP is nonzero if this variable should be static. */
2016 get_temp_name (type
, staticp
)
2020 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2022 int toplev
= toplevel_bindings_p ();
2024 push_obstacks_nochange ();
2025 if (toplev
|| staticp
)
2027 end_temporary_allocation ();
2028 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2029 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2033 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2034 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2036 TREE_USED (decl
) = 1;
2037 TREE_STATIC (decl
) = staticp
;
2038 DECL_ARTIFICIAL (decl
) = 1;
2040 /* If this is a local variable, then lay out its rtl now.
2041 Otherwise, callers of this function are responsible for dealing
2042 with this variable's rtl. */
2046 expand_decl_init (decl
);
2053 /* Get a variable which we can use for multiple assignments.
2054 It is not entered into current_binding_level, because
2055 that breaks things when it comes time to do final cleanups
2056 (which take place "outside" the binding contour of the function). */
2059 get_temp_regvar (type
, init
)
2064 decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
2065 TREE_USED (decl
) = 1;
2066 DECL_REGISTER (decl
) = 1;
2067 DECL_ARTIFICIAL (decl
) = 1;
2069 DECL_RTL (decl
) = assign_temp (type
, 2, 0, 1);
2070 /* We can expand these without fear, since they cannot need
2071 constructors or destructors. */
2072 expand_expr (build_modify_expr (decl
, INIT_EXPR
, init
),
2073 NULL_RTX
, VOIDmode
, 0);
2078 /* Hunts through the global anonymous union ANON_DECL, building
2079 appropriate VAR_DECLs. Stores cleanups on the list of ELEMS, and
2080 returns a VAR_DECL whose size is the same as the size of the
2081 ANON_DECL, if one is available. */
2084 build_anon_union_vars (anon_decl
, elems
, static_p
, external_p
)
2090 tree type
= TREE_TYPE (anon_decl
);
2091 tree main_decl
= NULL_TREE
;
2094 for (field
= TYPE_FIELDS (type
);
2096 field
= TREE_CHAIN (field
))
2100 if (DECL_ARTIFICIAL (field
))
2102 if (TREE_CODE (field
) != FIELD_DECL
)
2104 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
2109 if (TREE_PRIVATE (field
))
2110 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
2111 else if (TREE_PROTECTED (field
))
2112 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
2114 if (DECL_NAME (field
) == NULL_TREE
2115 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2117 decl
= build_anon_union_vars (field
, elems
, static_p
, external_p
);
2121 else if (DECL_NAME (field
) == NULL_TREE
)
2125 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2126 /* tell `pushdecl' that this is not tentative. */
2127 DECL_INITIAL (decl
) = error_mark_node
;
2128 TREE_PUBLIC (decl
) = 0;
2129 TREE_STATIC (decl
) = static_p
;
2130 DECL_EXTERNAL (decl
) = external_p
;
2131 decl
= pushdecl (decl
);
2132 DECL_INITIAL (decl
) = NULL_TREE
;
2135 /* Only write out one anon union element--choose the one that
2136 can hold them all. */
2137 if (main_decl
== NULL_TREE
2138 && simple_cst_equal (DECL_SIZE (decl
),
2139 DECL_SIZE (anon_decl
)) == 1)
2142 /* ??? This causes there to be no debug info written out
2144 TREE_ASM_WRITTEN (decl
) = 1;
2146 if (DECL_NAME (field
) == NULL_TREE
2147 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2148 /* The remainder of the processing was already done in the
2152 /* If there's a cleanup to do, it belongs in the
2153 TREE_PURPOSE of the following TREE_LIST. */
2154 *elems
= scratch_tree_cons (NULL_TREE
, decl
, *elems
);
2155 TREE_TYPE (*elems
) = type
;
2161 /* Finish off the processing of a UNION_TYPE structure.
2162 If there are static members, then all members are
2163 static, and must be laid out together. If the
2164 union is an anonymous union, we arrange for that
2165 as well. PUBLIC_P is nonzero if this union is
2166 not declared static. */
2169 finish_anon_union (anon_union_decl
)
2170 tree anon_union_decl
;
2172 tree type
= TREE_TYPE (anon_union_decl
);
2173 tree elems
= NULL_TREE
;
2175 int public_p
= TREE_PUBLIC (anon_union_decl
);
2176 int static_p
= TREE_STATIC (anon_union_decl
);
2177 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2179 if (TYPE_FIELDS (type
) == NULL_TREE
)
2184 error ("global anonymous unions must be declared static");
2188 main_decl
= build_anon_union_vars (anon_union_decl
, &elems
,
2189 static_p
, external_p
);
2191 if (main_decl
== NULL_TREE
)
2193 warning ("anonymous union with no members");
2199 make_decl_rtl (main_decl
, 0, toplevel_bindings_p ());
2200 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2203 /* The following call assumes that there are never any cleanups
2204 for anonymous unions--a reasonable assumption. */
2205 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2208 /* Finish processing a builtin type TYPE. It's name is NAME,
2209 its fields are in the array FIELDS. LEN is the number of elements
2210 in FIELDS minus one, or put another way, it is the maximum subscript
2213 It is given the same alignment as ALIGN_TYPE. */
2216 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2225 TYPE_FIELDS (type
) = fields
[0];
2226 for (i
= 0; i
< len
; i
++)
2228 layout_type (TREE_TYPE (fields
[i
]));
2229 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2230 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2232 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2233 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2234 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2236 #if 0 /* not yet, should get fixed properly later */
2237 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2239 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2241 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
2242 layout_decl (TYPE_NAME (type
), 0);
2245 /* Auxiliary functions to make type signatures for
2246 `operator new' and `operator delete' correspond to
2247 what compiler will be expecting. */
2250 coerce_new_type (type
)
2255 if (TREE_CODE (type
) == METHOD_TYPE
)
2256 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2257 if (! same_type_p (TREE_TYPE (type
), ptr_type_node
))
2258 e1
= 1, error ("`operator new' must return type `void *'");
2260 /* Technically the type must be `size_t', but we may not know
2262 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2263 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2264 else if (! same_type_p (TREE_VALUE (TYPE_ARG_TYPES (type
)), sizetype
))
2265 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2267 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2269 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2274 coerce_delete_type (type
)
2281 tree arg_types
= TYPE_ARG_TYPES (type
);
2283 if (TREE_CODE (type
) == METHOD_TYPE
)
2285 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2286 arg_types
= TREE_CHAIN (arg_types
);
2289 if (TREE_TYPE (type
) != void_type_node
)
2290 e1
= 1, error ("`operator delete' must return type `void'");
2292 if (arg_types
== NULL_TREE
2293 || ! same_type_p (TREE_VALUE (arg_types
), ptr_type_node
))
2294 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2298 && TREE_CHAIN (arg_types
)
2299 && TREE_CHAIN (arg_types
) != void_list_node
)
2301 /* Again, technically this argument must be `size_t', but again
2302 we may not know what that is. */
2303 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2304 if (! same_type_p (t2
, sizetype
))
2305 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2306 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2309 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2310 error ("too many arguments in declaration of `operator delete'");
2312 error ("`...' invalid in specification of `operator delete'");
2317 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2318 build_tree_list (NULL_TREE
, sizetype
));
2321 if (arg_types
== NULL_TREE
)
2322 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2324 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2330 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2331 arg_types
? TREE_CHAIN (arg_types
): NULL_TREE
);
2333 type
= build_function_type (void_type_node
, arg_types
);
2338 extern tree abort_fndecl
;
2341 mark_vtable_entries (decl
)
2344 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
2348 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (TREE_CHAIN (entries
))
2349 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2350 tree fn
= TREE_OPERAND (fnaddr
, 0);
2351 TREE_ADDRESSABLE (fn
) = 1;
2354 skip_rtti_stuff (&entries
);
2356 for (; entries
; entries
= TREE_CHAIN (entries
))
2358 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (entries
)
2359 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2360 tree fn
= TREE_OPERAND (fnaddr
, 0);
2361 TREE_ADDRESSABLE (fn
) = 1;
2362 if (DECL_LANG_SPECIFIC (fn
) && DECL_ABSTRACT_VIRTUAL_P (fn
))
2364 TREE_OPERAND (fnaddr
, 0) = fn
= copy_node (fn
);
2365 DECL_RTL (fn
) = DECL_RTL (abort_fndecl
);
2366 mark_used (abort_fndecl
);
2368 if (TREE_CODE (fn
) == THUNK_DECL
&& DECL_EXTERNAL (fn
))
2370 DECL_EXTERNAL (fn
) = 0;
2377 /* Set DECL up to have the closest approximation of "initialized common"
2378 linkage available. */
2381 comdat_linkage (decl
)
2385 make_decl_one_only (decl
);
2386 else if (TREE_CODE (decl
) == FUNCTION_DECL
|| DECL_VIRTUAL_P (decl
))
2387 /* We can just emit functions and vtables statically; it doesn't really
2388 matter if we have multiple copies. */
2389 TREE_PUBLIC (decl
) = 0;
2392 /* Static data member template instantiations, however, cannot
2393 have multiple copies. */
2394 if (DECL_INITIAL (decl
) == 0
2395 || DECL_INITIAL (decl
) == error_mark_node
)
2396 DECL_COMMON (decl
) = 1;
2397 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl
)))
2399 DECL_COMMON (decl
) = 1;
2400 DECL_INITIAL (decl
) = error_mark_node
;
2404 /* We can't do anything useful; leave vars for explicit
2406 DECL_EXTERNAL (decl
) = 1;
2407 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2411 if (DECL_LANG_SPECIFIC (decl
))
2412 DECL_COMDAT (decl
) = 1;
2415 /* For win32 we also want to put explicit instantiations in
2416 linkonce sections, so that they will be merged with implicit
2417 instantiations; otherwise we get duplicate symbol errors. */
2420 maybe_make_one_only (decl
)
2423 /* This is not necessary on targets that support weak symbols, because
2424 the implicit instantiations will defer to the explicit one. */
2425 if (! supports_one_only () || SUPPORTS_WEAK
)
2428 /* We can't set DECL_COMDAT on functions, or finish_file will think
2429 we can get away with not emitting them if they aren't used. We need
2430 to for variables so that cp_finish_decl will update their linkage,
2431 because their DECL_INITIAL may not have been set properly yet. */
2433 make_decl_one_only (decl
);
2435 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_LANG_SPECIFIC (decl
))
2436 DECL_COMDAT (decl
) = 1;
2439 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2440 based on TYPE and other static flags.
2442 Note that anything public is tagged TREE_PUBLIC, whether
2443 it's public in this file or in another one. */
2446 import_export_vtable (decl
, type
, final
)
2450 if (DECL_INTERFACE_KNOWN (decl
))
2453 if (TYPE_FOR_JAVA (type
))
2455 TREE_PUBLIC (decl
) = 1;
2456 DECL_EXTERNAL (decl
) = 1;
2457 DECL_INTERFACE_KNOWN (decl
) = 1;
2459 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2461 TREE_PUBLIC (decl
) = 1;
2462 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2463 DECL_INTERFACE_KNOWN (decl
) = 1;
2467 /* We can only wait to decide if we have real non-inline virtual
2468 functions in our class, or if we come from a template. */
2470 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2472 if (! found
&& ! final
)
2475 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
2476 method
= TREE_CHAIN (method
))
2477 if (DECL_VINDEX (method
) != NULL_TREE
2478 && ! DECL_THIS_INLINE (method
)
2479 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2486 if (final
|| ! found
)
2488 comdat_linkage (decl
);
2489 DECL_EXTERNAL (decl
) = 0;
2493 TREE_PUBLIC (decl
) = 1;
2494 DECL_EXTERNAL (decl
) = 1;
2499 /* Determine whether or not we want to specifically import or export CTYPE,
2500 using various heuristics. */
2503 import_export_class (ctype
)
2506 /* -1 for imported, 1 for exported. */
2507 int import_export
= 0;
2509 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2512 /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma interface,
2513 we will have CLASSTYPE_INTERFACE_ONLY set but not
2514 CLASSTYPE_INTERFACE_KNOWN. In that case, we don't want to use this
2515 heuristic because someone will supply a #pragma implementation
2516 elsewhere, and deducing it here would produce a conflict. */
2517 if (CLASSTYPE_INTERFACE_ONLY (ctype
))
2520 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2521 /* FIXME this should really use some sort of target-independent macro. */
2522 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype
)))
2524 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype
)))
2528 /* If we got -fno-implicit-templates, we import template classes that
2529 weren't explicitly instantiated. */
2530 if (import_export
== 0
2531 && CLASSTYPE_IMPLICIT_INSTANTIATION (ctype
)
2532 && ! flag_implicit_templates
)
2535 /* Base our import/export status on that of the first non-inline,
2536 non-abstract virtual function, if any. */
2537 if (import_export
== 0
2538 && TYPE_VIRTUAL_P (ctype
)
2539 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2542 for (method
= TYPE_METHODS (ctype
); method
!= NULL_TREE
;
2543 method
= TREE_CHAIN (method
))
2545 if (DECL_VINDEX (method
) != NULL_TREE
2546 && !DECL_THIS_INLINE (method
)
2547 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2549 import_export
= (DECL_REALLY_EXTERN (method
) ? -1 : 1);
2555 #ifdef MULTIPLE_SYMBOL_SPACES
2556 if (import_export
== -1)
2562 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2563 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
) = (import_export
> 0);
2564 CLASSTYPE_INTERFACE_ONLY (ctype
) = (import_export
< 0);
2568 /* We need to describe to the assembler the relationship between
2569 a vtable and the vtable of the parent class. */
2572 output_vtable_inherit (vars
)
2578 op
[0] = XEXP (DECL_RTL (vars
), 0); /* strip the mem ref */
2580 parent
= binfo_for_vtable (vars
);
2582 if (parent
== TYPE_BINFO (DECL_CONTEXT (vars
)))
2586 parent
= TYPE_BINFO_VTABLE (BINFO_TYPE (parent
));
2587 op
[1] = XEXP (DECL_RTL (parent
), 0); /* strip the mem ref */
2590 my_friendly_abort (980826);
2592 output_asm_insn (".vtable_inherit %c0, %c1", op
);
2596 finish_vtable_vardecl (prev
, vars
)
2599 tree ctype
= DECL_CONTEXT (vars
);
2600 import_export_class (ctype
);
2601 import_export_vtable (vars
, ctype
, 1);
2603 if (! DECL_EXTERNAL (vars
)
2604 && (DECL_INTERFACE_KNOWN (vars
)
2605 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
))
2606 || (hack_decl_function_context (vars
) && TREE_USED (vars
)))
2607 && ! TREE_ASM_WRITTEN (vars
))
2610 mark_vtable_entries (vars
);
2611 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2612 store_init_value (vars
, DECL_INITIAL (vars
));
2614 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2616 /* Mark the VAR_DECL node representing the vtable itself as a
2617 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2618 It is rather important that such things be ignored because
2619 any effort to actually generate DWARF for them will run
2620 into trouble when/if we encounter code like:
2623 struct S { virtual void member (); };
2625 because the artificial declaration of the vtable itself (as
2626 manufactured by the g++ front end) will say that the vtable
2627 is a static member of `S' but only *after* the debug output
2628 for the definition of `S' has already been output. This causes
2629 grief because the DWARF entry for the definition of the vtable
2630 will try to refer back to an earlier *declaration* of the
2631 vtable as a static member of `S' and there won't be one.
2632 We might be able to arrange to have the "vtable static member"
2633 attached to the member list for `S' before the debug info for
2634 `S' get written (which would solve the problem) but that would
2635 require more intrusive changes to the g++ front end. */
2637 DECL_IGNORED_P (vars
) = 1;
2640 /* Always make vtables weak. */
2642 comdat_linkage (vars
);
2644 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2647 output_vtable_inherit (vars
);
2651 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
)))
2652 /* We don't know what to do with this one yet. */
2655 /* We know that PREV must be non-zero here. */
2656 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2661 prune_vtable_vardecl (prev
, vars
)
2664 /* We know that PREV must be non-zero here. */
2665 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2670 walk_vtables (typedecl_fn
, vardecl_fn
)
2671 register void (*typedecl_fn
) PROTO ((tree
, tree
));
2672 register int (*vardecl_fn
) PROTO ((tree
, tree
));
2677 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2679 register tree type
= TREE_TYPE (vars
);
2681 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2684 flag
|= (*vardecl_fn
) (prev
, vars
);
2686 if (prev
&& TREE_CHAIN (prev
) != vars
)
2689 else if (TREE_CODE (vars
) == TYPE_DECL
2690 && type
!= error_mark_node
2691 && TYPE_LANG_SPECIFIC (type
)
2692 && CLASSTYPE_VSIZE (type
))
2694 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2704 finish_sigtable_vardecl (prev
, vars
)
2707 /* We don't need to mark sigtable entries as addressable here as is done
2708 for vtables. Since sigtables, unlike vtables, are always written out,
2709 that was already done in build_signature_table_constructor. */
2711 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2713 /* We know that PREV must be non-zero here. */
2714 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2718 walk_sigtables (typedecl_fn
, vardecl_fn
)
2719 register void (*typedecl_fn
) PROTO((tree
, tree
));
2720 register void (*vardecl_fn
) PROTO((tree
, tree
));
2724 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2726 register tree type
= TREE_TYPE (vars
);
2728 if (TREE_CODE (vars
) == TYPE_DECL
2729 && type
!= error_mark_node
2730 && IS_SIGNATURE (type
))
2732 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2734 else if (TREE_CODE (vars
) == VAR_DECL
2735 && TREE_TYPE (vars
) != error_mark_node
2736 && IS_SIGNATURE (TREE_TYPE (vars
)))
2738 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2745 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2746 inline function or template instantiation at end-of-file. */
2749 import_export_decl (decl
)
2752 if (DECL_INTERFACE_KNOWN (decl
))
2755 if (DECL_TEMPLATE_INSTANTIATION (decl
)
2756 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
))
2758 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2759 if ((DECL_IMPLICIT_INSTANTIATION (decl
)
2760 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
))
2761 && (flag_implicit_templates
2762 || (flag_implicit_inline_templates
&& DECL_THIS_INLINE (decl
))))
2764 if (!TREE_PUBLIC (decl
))
2765 /* Templates are allowed to have internal linkage. See
2769 comdat_linkage (decl
);
2772 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2774 else if (DECL_FUNCTION_MEMBER_P (decl
))
2776 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2777 import_export_class (ctype
);
2778 if (CLASSTYPE_INTERFACE_KNOWN (ctype
)
2779 && (! DECL_ARTIFICIAL (decl
) || DECL_VINDEX (decl
)))
2781 DECL_NOT_REALLY_EXTERN (decl
)
2782 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2783 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2785 /* Always make artificials weak. */
2786 if (DECL_ARTIFICIAL (decl
) && flag_weak
)
2787 comdat_linkage (decl
);
2789 maybe_make_one_only (decl
);
2792 comdat_linkage (decl
);
2794 /* tinfo function */
2795 else if (DECL_ARTIFICIAL (decl
) && DECL_MUTABLE_P (decl
))
2797 tree ctype
= TREE_TYPE (DECL_NAME (decl
));
2799 if (IS_AGGR_TYPE (ctype
))
2800 import_export_class (ctype
);
2802 if (IS_AGGR_TYPE (ctype
) && CLASSTYPE_INTERFACE_KNOWN (ctype
)
2803 && TYPE_VIRTUAL_P (ctype
)
2804 /* If the type is a cv-qualified variant of a type, then we
2805 must emit the tinfo function in this translation unit
2806 since it will not be emitted when the vtable for the type
2807 is output (which is when the unqualified version is
2809 && ctype
== TYPE_MAIN_VARIANT (ctype
))
2811 DECL_NOT_REALLY_EXTERN (decl
)
2812 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2813 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2815 /* Always make artificials weak. */
2817 comdat_linkage (decl
);
2819 else if (TYPE_BUILT_IN (ctype
) && ctype
== TYPE_MAIN_VARIANT (ctype
))
2820 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2822 comdat_linkage (decl
);
2825 comdat_linkage (decl
);
2827 DECL_INTERFACE_KNOWN (decl
) = 1;
2831 build_cleanup (decl
)
2835 tree type
= TREE_TYPE (decl
);
2837 if (TREE_CODE (type
) == ARRAY_TYPE
)
2841 mark_addressable (decl
);
2842 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
2844 temp
= build_delete (TREE_TYPE (temp
), temp
,
2846 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2850 extern int parse_time
, varconst_time
;
2851 extern tree pending_templates
;
2852 extern tree maybe_templates
;
2858 tree sname
= get_id_2 ("__sn", base
);
2859 /* For struct X foo __attribute__((weak)), there is a counter
2860 __snfoo. Since base is already an assembler name, sname should
2861 be globally unique */
2862 tree sentry
= IDENTIFIER_GLOBAL_VALUE (sname
);
2865 push_obstacks_nochange ();
2866 end_temporary_allocation ();
2867 sentry
= build_decl (VAR_DECL
, sname
, integer_type_node
);
2868 TREE_PUBLIC (sentry
) = 1;
2869 DECL_ARTIFICIAL (sentry
) = 1;
2870 TREE_STATIC (sentry
) = 1;
2871 TREE_USED (sentry
) = 1;
2872 DECL_COMMON (sentry
) = 1;
2873 pushdecl_top_level (sentry
);
2874 cp_finish_decl (sentry
, NULL_TREE
, NULL_TREE
, 0, 0);
2880 /* A list of objects which have constructors or destructors
2881 which reside in the global scope. The decl is stored in
2882 the TREE_VALUE slot and the initializer is stored
2883 in the TREE_PURPOSE slot. */
2884 extern tree static_aggregates_initp
;
2886 /* Set up the static_aggregates* lists for processing. Subroutine of
2887 finish_file. Note that this function changes the format of
2888 static_aggregates_initp, from (priority . decl) to
2889 (priority . ((initializer . decl) ...)). */
2895 tree default_pri
= build_int_2 (DEFAULT_INIT_PRIORITY
, 0);
2898 /* First, remove any entries from static_aggregates that are also in
2899 static_aggregates_initp, and update the entries in _initp to include
2900 the initializer. For entries not in static_aggregates_initp, update
2901 them in place to look the same way. */
2902 p
= &static_aggregates
;
2905 t
= value_member (TREE_VALUE (*p
), static_aggregates_initp
);
2909 /* We found an entry in s_a_initp; replace that entry with the
2910 format we want and remove the entry in s_a. */
2911 TREE_VALUE (t
) = *p
;
2912 *p
= TREE_CHAIN (*p
);
2913 TREE_CHAIN (TREE_VALUE (t
)) = NULL_TREE
;
2917 /* We didn't find an entry in s_a_i; replace the entry in s_a
2918 with the format we want. */
2919 *p
= perm_tree_cons (default_pri
, *p
, TREE_CHAIN (*p
));
2920 TREE_CHAIN (TREE_VALUE (*p
)) = NULL_TREE
;
2921 p
= &TREE_CHAIN (*p
);
2925 /* And then attach the two lists. By doing it this way, ctors with an
2926 explicit priority equal to the default are run before ctors with no
2927 explicit priority (i.e. the ones in s_a). */
2928 static_aggregates_initp
= chainon (static_aggregates
,
2929 static_aggregates_initp
);
2930 static_aggregates
= NULL_TREE
;
2932 /* Then, group static_aggregates_initp. After this step, there will only
2933 be one entry for each priority, with a chain coming off it. */
2934 t
= static_aggregates_initp
;
2935 static_aggregates_initp
= NULL_TREE
;
2938 for (; t
; t
= next_t
)
2940 next_t
= TREE_CHAIN (t
);
2941 if (TREE_INT_CST_LOW (TREE_PURPOSE (t
)) == DEFAULT_INIT_PRIORITY
)
2944 for (p
= &static_aggregates_initp
; ; p
= &TREE_CHAIN (*p
))
2947 || tree_int_cst_lt (TREE_PURPOSE (*p
), TREE_PURPOSE (t
)))
2949 TREE_CHAIN (t
) = *p
;
2953 else if (tree_int_cst_equal (TREE_PURPOSE (*p
), TREE_PURPOSE (t
)))
2955 TREE_CHAIN (TREE_VALUE (t
)) = TREE_VALUE (*p
);
2956 TREE_VALUE (*p
) = TREE_VALUE (t
);
2963 static_aggregates_initp
= perm_tree_cons (default_pri
, error_mark_node
,
2964 static_aggregates_initp
);
2966 /* Reverse each list to preserve the order (currently reverse declaration
2967 order, for destructors). */
2968 for (t
= static_aggregates_initp
; t
; t
= TREE_CHAIN (t
))
2969 TREE_VALUE (t
) = nreverse (TREE_VALUE (t
));
2972 /* Start the process of running a particular set of global constructors
2973 or destructors. Subroutine of do_[cd]tors. */
2976 start_objects (method_type
, initp
)
2977 int method_type
, initp
;
2982 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
2984 if (initp
!= DEFAULT_INIT_PRIORITY
)
2994 sprintf (type
, "%c%c%.5u", method_type
, joiner
, initp
);
2997 sprintf (type
, "%c", method_type
);
2999 fnname
= get_file_function_name_long (type
);
3001 start_function (void_list_node
,
3002 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
3006 #if defined(ASM_OUTPUT_CONSTRUCTOR) && defined(ASM_OUTPUT_DESTRUCTOR)
3007 /* It can be a static function as long as collect2 does not have
3008 to scan the object file to find its ctor/dtor routine. */
3009 TREE_PUBLIC (current_function_decl
) = 0;
3012 store_parm_decls ();
3016 expand_start_bindings (0);
3019 /* Finish the process of running a particular set of global constructors
3020 or destructors. Subroutine of do_[cd]tors. */
3023 finish_objects (method_type
, initp
)
3024 int method_type
, initp
;
3028 if (initp
== DEFAULT_INIT_PRIORITY
)
3030 tree list
= (method_type
== 'I' ? static_ctors
: static_dtors
);
3032 if (! current_function_decl
&& list
)
3033 start_objects (method_type
, initp
);
3035 for (; list
; list
= TREE_CHAIN (list
))
3036 expand_expr_stmt (build_function_call (TREE_VALUE (list
), NULL_TREE
));
3039 if (! current_function_decl
)
3042 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
3045 expand_end_bindings (getdecls (), 1, 0);
3048 finish_function (lineno
, 0, 0);
3050 if (initp
== DEFAULT_INIT_PRIORITY
)
3052 if (method_type
== 'I')
3053 assemble_constructor (fnname
);
3055 assemble_destructor (fnname
);
3058 #ifdef ASM_OUTPUT_SECTION_NAME
3059 /* If we're using init priority we can't use assemble_*tor, but on ELF
3060 targets we can stick the references into named sections for GNU ld
3065 sprintf (buf
, ".%ctors.%.5u", method_type
== 'I' ? 'c' : 'd',
3066 /* invert the numbering so the linker puts us in the proper
3067 order; constructors are run from right to left, and the
3068 linker sorts in increasing order. */
3069 MAX_INIT_PRIORITY
- initp
);
3070 named_section (NULL_TREE
, buf
, 0);
3071 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, fnname
),
3072 POINTER_SIZE
/ BITS_PER_UNIT
, 1);
3077 /* Generate a function to run a set of global destructors. START is either
3078 NULL_TREE or a node indicating a set of destructors with the same
3079 init priority. Subroutine of finish_file. */
3088 initp
= TREE_INT_CST_LOW (TREE_PURPOSE (start
));
3089 vars
= TREE_VALUE (start
);
3091 for (; vars
&& vars
!= error_mark_node
; vars
= TREE_CHAIN (vars
))
3093 tree decl
= TREE_VALUE (vars
);
3094 tree type
= TREE_TYPE (decl
);
3097 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
)
3098 && ! DECL_EXTERNAL (decl
))
3100 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
3101 || DECL_ONE_ONLY (decl
)
3102 || DECL_WEAK (decl
)));
3104 if (! current_function_decl
)
3105 start_objects ('D', initp
);
3107 /* Set these global variables so that GDB at least puts
3108 us near the declaration which required the initialization. */
3109 input_filename
= DECL_SOURCE_FILE (decl
);
3110 lineno
= DECL_SOURCE_LINE (decl
);
3111 emit_note (input_filename
, lineno
);
3117 Access control for implicit calls to the constructors,
3118 the conversion functions, or the destructor called to
3119 create and destroy a static data member is performed as
3120 if these calls appeared in the scope of the member's
3123 we must convince enforce_access to let us access the
3125 if (member_p (decl
))
3127 DECL_CLASS_CONTEXT (current_function_decl
)
3128 = DECL_CONTEXT (decl
);
3129 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3132 temp
= build_cleanup (decl
);
3136 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
3137 sentry
= build_unary_op (PREDECREMENT_EXPR
, sentry
, 0);
3138 sentry
= build_binary_op (EQ_EXPR
, sentry
, integer_zero_node
, 1);
3139 expand_start_cond (sentry
, 0);
3142 expand_expr_stmt (temp
);
3147 /* Now that we're done with DECL we don't need to pretend to
3148 be a member of its class any longer. */
3149 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3150 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3154 finish_objects ('D', initp
);
3157 /* Generate a function to run a set of global constructors. START is
3158 either NULL_TREE or a node indicating a set of constructors with the
3159 same init priority. Subroutine of finish_file. */
3168 initp
= TREE_INT_CST_LOW (TREE_PURPOSE (start
));
3169 vars
= TREE_VALUE (start
);
3171 /* Reverse the list so it's in the right order for ctors. */
3172 vars
= nreverse (vars
);
3174 for (; vars
&& vars
!= error_mark_node
; vars
= TREE_CHAIN (vars
))
3176 tree decl
= TREE_VALUE (vars
);
3177 tree init
= TREE_PURPOSE (vars
);
3179 /* If this was a static attribute within some function's scope,
3180 then don't initialize it here. Also, don't bother
3181 with initializers that contain errors. */
3182 if (TREE_STATIC (vars
)
3183 || DECL_EXTERNAL (decl
)
3184 || (init
&& TREE_CODE (init
) == TREE_LIST
3185 && value_member (error_mark_node
, init
)))
3188 if (TREE_CODE (decl
) == VAR_DECL
)
3190 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
3191 || DECL_ONE_ONLY (decl
)
3192 || DECL_WEAK (decl
)));
3194 if (! current_function_decl
)
3195 start_objects ('I', initp
);
3197 /* Set these global variables so that GDB at least puts
3198 us near the declaration which required the initialization. */
3199 input_filename
= DECL_SOURCE_FILE (decl
);
3200 lineno
= DECL_SOURCE_LINE (decl
);
3201 emit_note (input_filename
, lineno
);
3203 /* 9.5p5: The initializer of a static member of a class has
3204 the same access rights as a member function. */
3205 if (member_p (decl
))
3207 DECL_CLASS_CONTEXT (current_function_decl
)
3208 = DECL_CONTEXT (decl
);
3209 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3214 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
3215 sentry
= build_unary_op (PREINCREMENT_EXPR
, sentry
, 0);
3216 sentry
= build_binary_op
3217 (EQ_EXPR
, sentry
, integer_one_node
, 1);
3218 expand_start_cond (sentry
, 0);
3221 expand_start_target_temps ();
3223 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3224 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3225 expand_aggr_init (decl
, init
, 0);
3226 else if (TREE_CODE (init
) == TREE_VEC
)
3228 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3229 TREE_VEC_ELT (init
, 1),
3230 TREE_VEC_ELT (init
, 2), 0),
3231 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3234 expand_assignment (decl
, init
, 0, 0);
3236 /* The expression might have involved increments and
3240 /* Cleanup any temporaries needed for the initial value. */
3241 expand_end_target_temps ();
3246 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3247 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3249 else if (decl
== error_mark_node
)
3252 my_friendly_abort (22);
3255 finish_objects ('I', initp
);
3258 /* This routine is called from the last rule in yyparse ().
3259 Its job is to create all the code needed to initialize and
3260 destroy the global aggregates. We do the destruction
3261 first, since that way we only need to reverse the decls once. */
3267 int start_time
, this_time
;
3271 int needs_cleaning
= 0, needs_messing_up
= 0;
3275 /* Bad parse errors. Just forget about it. */
3276 if (! global_bindings_p () || current_class_type
|| decl_namespace_list
)
3279 start_time
= get_run_time ();
3281 /* Otherwise, GDB can get confused, because in only knows
3282 about source for LINENO-1 lines. */
3285 interface_unknown
= 1;
3288 for (fnname
= pending_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
3290 tree srcloc
= TREE_PURPOSE (fnname
);
3291 tree decl
= TREE_VALUE (fnname
);
3293 input_filename
= SRCLOC_FILE (srcloc
);
3294 lineno
= SRCLOC_LINE (srcloc
);
3296 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
3298 instantiate_class_template (decl
);
3299 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl
))
3300 for (vars
= TYPE_METHODS (decl
); vars
; vars
= TREE_CHAIN (vars
))
3301 if (! DECL_ARTIFICIAL (vars
))
3302 instantiate_decl (vars
);
3305 instantiate_decl (decl
);
3308 for (fnname
= maybe_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
3310 tree args
, fn
, decl
= TREE_VALUE (fnname
);
3312 if (DECL_INITIAL (decl
))
3315 fn
= TREE_PURPOSE (fnname
);
3316 args
= get_bindings (fn
, decl
, NULL_TREE
);
3317 fn
= instantiate_template (fn
, args
);
3318 instantiate_decl (fn
);
3321 cat_namespace_levels();
3323 /* Push into C language context, because that's all
3325 push_lang_context (lang_name_c
);
3328 /* The reason for pushing garbage onto the global_binding_level is to
3329 ensure that we can slice out _DECLs which pertain to virtual function
3330 tables. If the last thing pushed onto the global_binding_level was a
3331 virtual function table, then slicing it out would slice away all the
3332 decls (i.e., we lose the head of the chain).
3334 There are several ways of getting the same effect, from changing the
3335 way that iterators over the chain treat the elements that pertain to
3336 virtual function tables, moving the implementation of this code to
3337 decl.c (where we can manipulate global_binding_level directly),
3338 popping the garbage after pushing it and slicing away the vtable
3339 stuff, or just leaving it alone. */
3341 /* Make last thing in global scope not be a virtual function table. */
3342 #if 0 /* not yet, should get fixed properly later */
3343 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
3345 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
3347 DECL_IGNORED_P (vars
) = 1;
3348 SET_DECL_ARTIFICIAL (vars
);
3352 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
3353 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars
)))
3354 rest_of_decl_compilation (TREE_VALUE (vars
), 0, 1, 1);
3355 vars
= static_aggregates
;
3357 if (static_ctors
|| vars
)
3358 needs_messing_up
= 1;
3359 if (static_dtors
|| vars
)
3364 /* After setup_initp, the aggregates are listed in reverse declaration
3365 order, for cleaning. */
3367 for (vars
= static_aggregates_initp
; vars
; vars
= TREE_CHAIN (vars
))
3370 /* do_ctors will reverse the lists for messing up. */
3371 if (needs_messing_up
)
3372 for (vars
= static_aggregates_initp
; vars
; vars
= TREE_CHAIN (vars
))
3375 permanent_allocation (1);
3377 /* Done with C language context needs. */
3378 pop_lang_context ();
3380 /* Let expand_static_init know it's too late for more ctors. */
3383 /* Now write out any static class variables (which may have since
3384 learned how to be initialized). */
3385 for (; pending_statics
; pending_statics
= TREE_CHAIN (pending_statics
))
3387 tree decl
= TREE_VALUE (pending_statics
);
3389 if (TREE_ASM_WRITTEN (decl
))
3392 /* Output DWARF debug information. */
3393 #ifdef DWARF_DEBUGGING_INFO
3394 if (write_symbols
== DWARF_DEBUG
)
3395 dwarfout_file_scope_decl (decl
, 1);
3397 #ifdef DWARF2_DEBUGGING_INFO
3398 if (write_symbols
== DWARF2_DEBUG
)
3399 dwarf2out_decl (decl
);
3402 /* We currently handle template statics here. We ought to handle
3403 them the same way we do template functions, i.e. only emit them if
3404 the symbol is needed. */
3405 import_export_decl (decl
);
3406 if (DECL_NOT_REALLY_EXTERN (decl
) && ! DECL_IN_AGGR_P (decl
))
3407 DECL_EXTERNAL (decl
) = 0;
3409 rest_of_decl_compilation
3410 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3413 this_time
= get_run_time ();
3414 parse_time
-= this_time
- start_time
;
3415 varconst_time
+= this_time
- start_time
;
3417 start_time
= get_run_time ();
3419 if (flag_handle_signatures
)
3420 walk_sigtables ((void (*) PROTO ((tree
, tree
))) 0,
3421 finish_sigtable_vardecl
);
3423 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3425 tree decl
= TREE_VALUE (fnname
);
3426 import_export_decl (decl
);
3429 mark_all_runtime_matches ();
3431 /* Now write out inline functions which had their addresses taken and
3432 which were not declared virtual and which were not declared `extern
3435 int reconsider
= 1; /* More may be referenced; check again */
3439 tree
*p
= &saved_inlines
;
3442 /* We need to do this each time so that newly completed template
3443 types don't wind up at the front of the list. Sigh. */
3444 vars
= build_decl (TYPE_DECL
, make_anon_name (), integer_type_node
);
3445 DECL_IGNORED_P (vars
) = 1;
3446 SET_DECL_ARTIFICIAL (vars
);
3449 reconsider
|= walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3450 finish_vtable_vardecl
);
3454 tree decl
= TREE_VALUE (*p
);
3456 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3458 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
3460 if (DECL_MUTABLE_P (decl
))
3461 synthesize_tinfo_fn (decl
);
3463 synthesize_method (decl
);
3467 /* Catch new template instantiations. */
3468 if (decl
!= TREE_VALUE (*p
))
3471 if (TREE_ASM_WRITTEN (decl
)
3472 || (DECL_SAVED_INSNS (decl
) == 0
3473 && ! DECL_ARTIFICIAL (decl
)))
3474 *p
= TREE_CHAIN (*p
);
3475 else if (DECL_INITIAL (decl
) == 0)
3476 p
= &TREE_CHAIN (*p
);
3477 else if ((TREE_PUBLIC (decl
) && ! DECL_COMDAT (decl
))
3478 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3479 || flag_keep_inline_functions
)
3481 if (DECL_NOT_REALLY_EXTERN (decl
))
3483 DECL_EXTERNAL (decl
) = 0;
3485 /* We can't inline this function after it's been
3486 emitted. We want a variant of
3487 output_inline_function that doesn't prevent
3488 subsequent integration... */
3489 DECL_INLINE (decl
) = 0;
3490 output_inline_function (decl
);
3491 permanent_allocation (1);
3494 *p
= TREE_CHAIN (*p
);
3497 p
= &TREE_CHAIN (*p
);
3501 /* It's possible that some of the remaining inlines will still be
3502 needed. For example, a static inline whose address is used in
3503 the initializer for a file-scope static variable will be
3504 needed. Code in compile_file will handle this, but we mustn't
3505 pretend that there are no definitions for the inlines, or it
3508 FIXME: This won't catch member functions. We should really
3509 unify this stuff with the compile_file stuff. */
3510 for (vars
= saved_inlines
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
3512 tree decl
= TREE_VALUE (vars
);
3514 if (DECL_NOT_REALLY_EXTERN (decl
)
3515 && !DECL_COMDAT (decl
)
3516 && DECL_INITIAL (decl
) != NULL_TREE
)
3517 DECL_EXTERNAL (decl
) = 0;
3521 /* Now delete from the chain of variables all virtual function tables.
3522 We output them all ourselves, because each will be treated
3525 walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3526 prune_vtable_vardecl
);
3530 this_time
= get_run_time ();
3531 parse_time
-= this_time
- start_time
;
3532 varconst_time
+= this_time
- start_time
;
3534 if (flag_detailed_statistics
)
3536 dump_tree_statistics ();
3537 dump_time_statistics ();
3541 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3542 expr. Since it was parsed like a type, we need to wade through and fix
3543 that. Unfortunately, since operator() is left-associative, we can't use
3544 tail recursion. In the above example, TYPE is `A', and DECL is
3547 Maybe this shouldn't be recursive, but how often will it actually be
3551 reparse_absdcl_as_expr (type
, decl
)
3554 /* do build_functional_cast (type, NULL_TREE) at bottom */
3555 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3556 return build_functional_cast (type
, NULL_TREE
);
3559 decl
= reparse_absdcl_as_expr (type
, TREE_OPERAND (decl
, 0));
3561 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_ref
);
3563 if (TREE_CODE (decl
) == CALL_EXPR
3564 && (! TREE_TYPE (decl
)
3565 || TREE_CODE (TREE_TYPE (decl
)) != VOID_TYPE
))
3566 decl
= require_complete_type (decl
);
3571 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3572 out to be an expr. Since it was parsed like a type, we need to wade
3573 through and fix that. Since casts are right-associative, we are
3574 reversing the order, so we don't have to recurse.
3576 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3580 reparse_absdcl_as_casts (decl
, expr
)
3585 if (TREE_CODE (expr
) == CONSTRUCTOR
3586 && TREE_TYPE (expr
) == 0)
3588 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3589 decl
= TREE_OPERAND (decl
, 0);
3591 if (IS_SIGNATURE (type
))
3593 error ("cast specifies signature type");
3594 return error_mark_node
;
3597 expr
= digest_init (type
, expr
, (tree
*) 0);
3598 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3600 int failure
= complete_array_type (type
, expr
, 1);
3602 my_friendly_abort (78);
3608 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3609 decl
= TREE_OPERAND (decl
, 0);
3610 expr
= build_c_cast (type
, expr
);
3613 if (warn_old_style_cast
)
3614 warning ("use of old-style cast");
3619 /* Given plain tree nodes for an expression, build up the full semantics. */
3622 build_expr_from_tree (t
)
3625 if (t
== NULL_TREE
|| t
== error_mark_node
)
3628 switch (TREE_CODE (t
))
3630 case IDENTIFIER_NODE
:
3631 return do_identifier (t
, 0, NULL_TREE
);
3634 if (LOOKUP_EXPR_GLOBAL (t
))
3635 return do_scoped_id (TREE_OPERAND (t
, 0), 0);
3637 return do_identifier (TREE_OPERAND (t
, 0), 0, NULL_TREE
);
3639 case TEMPLATE_ID_EXPR
:
3640 return (lookup_template_function
3641 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3642 build_expr_from_tree (TREE_OPERAND (t
, 1))));
3645 return build_x_indirect_ref
3646 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3649 return build_functional_cast
3650 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3652 case REINTERPRET_CAST_EXPR
:
3653 return build_reinterpret_cast
3654 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3656 case CONST_CAST_EXPR
:
3657 return build_const_cast
3658 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3660 case DYNAMIC_CAST_EXPR
:
3661 return build_dynamic_cast
3662 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3664 case STATIC_CAST_EXPR
:
3665 return build_static_cast
3666 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3668 case PREDECREMENT_EXPR
:
3669 case PREINCREMENT_EXPR
:
3670 case POSTDECREMENT_EXPR
:
3671 case POSTINCREMENT_EXPR
:
3675 case TRUTH_NOT_EXPR
:
3677 case CONVERT_EXPR
: /* Unary + */
3680 return build_x_unary_op (TREE_CODE (t
),
3681 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3686 case TRUNC_DIV_EXPR
:
3688 case FLOOR_DIV_EXPR
:
3689 case ROUND_DIV_EXPR
:
3690 case EXACT_DIV_EXPR
:
3692 case BIT_ANDTC_EXPR
:
3695 case TRUNC_MOD_EXPR
:
3696 case FLOOR_MOD_EXPR
:
3697 case TRUTH_ANDIF_EXPR
:
3698 case TRUTH_ORIF_EXPR
:
3699 case TRUTH_AND_EXPR
:
3714 return build_x_binary_op
3716 build_expr_from_tree (TREE_OPERAND (t
, 0)),
3717 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3720 return build_m_component_ref
3721 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3722 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3725 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
3728 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
3730 return build_parse_node (ARRAY_REF
, NULL_TREE
,
3731 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3732 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3733 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3738 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3739 if (TREE_CODE_CLASS (TREE_CODE (r
)) != 't')
3741 return TREE_CODE (t
) == SIZEOF_EXPR
? c_sizeof (r
) : c_alignof (r
);
3745 return build_x_modify_expr
3746 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3747 TREE_CODE (TREE_OPERAND (t
, 1)),
3748 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3751 return build_x_arrow
3752 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3756 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3757 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3758 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3759 NEW_EXPR_USE_GLOBAL (t
));
3762 return delete_sanity
3763 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3764 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3765 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
3768 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
3769 return build_x_compound_expr
3770 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3772 my_friendly_abort (42);
3774 case METHOD_CALL_EXPR
:
3775 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3777 tree ref
= TREE_OPERAND (t
, 0);
3778 return build_scoped_method_call
3779 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3780 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3781 TREE_OPERAND (ref
, 1),
3782 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3786 tree fn
= TREE_OPERAND (t
, 0);
3788 /* We can get a TEMPLATE_ID_EXPR here on code like:
3792 so we must resolve that. However, we can also get things
3793 like a BIT_NOT_EXPR here, when referring to a destructor,
3794 and things like that are not correctly resolved by
3795 build_expr_from_tree. So, just use build_expr_from_tree
3796 when we really need it. */
3797 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
3798 fn
= build_expr_from_tree (fn
);
3800 return build_method_call
3801 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3803 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3804 NULL_TREE
, LOOKUP_NORMAL
);
3808 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3810 tree ref
= TREE_OPERAND (t
, 0);
3811 return build_member_call
3812 (build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3813 TREE_OPERAND (ref
, 1),
3814 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3818 tree name
= TREE_OPERAND (t
, 0);
3820 tree args
= build_expr_from_tree (TREE_OPERAND (t
, 1));
3821 if (args
!= NULL_TREE
&& TREE_CODE (name
) == LOOKUP_EXPR
3822 && !LOOKUP_EXPR_GLOBAL (name
)
3823 && TREE_CODE ((id
= TREE_OPERAND (name
, 0))) == IDENTIFIER_NODE
3824 && (!current_class_type
3825 || !lookup_member (current_class_type
, id
, 0, 0)))
3827 /* Do Koenig lookup if there are no class members. */
3828 name
= do_identifier (id
, 0, args
);
3830 else if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
3831 || ! really_overloaded_fn (name
))
3832 name
= build_expr_from_tree (name
);
3833 return build_x_function_call (name
, args
, current_class_ref
);
3837 return build_x_conditional_expr
3838 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3839 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3840 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3844 tree purpose
, value
, chain
;
3846 if (t
== void_list_node
)
3849 purpose
= TREE_PURPOSE (t
);
3851 purpose
= build_expr_from_tree (purpose
);
3852 value
= TREE_VALUE (t
);
3854 value
= build_expr_from_tree (value
);
3855 chain
= TREE_CHAIN (t
);
3856 if (chain
&& chain
!= void_type_node
)
3857 chain
= build_expr_from_tree (chain
);
3858 return expr_tree_cons (purpose
, value
, chain
);
3862 return build_x_component_ref
3863 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3864 TREE_OPERAND (t
, 1), NULL_TREE
, 1);
3867 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3873 /* digest_init will do the wrong thing if we let it. */
3874 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
3877 r
= build_nt (CONSTRUCTOR
, NULL_TREE
,
3878 build_expr_from_tree (CONSTRUCTOR_ELTS (t
)));
3879 TREE_HAS_CONSTRUCTOR (r
) = TREE_HAS_CONSTRUCTOR (t
);
3882 return digest_init (TREE_TYPE (t
), r
, 0);
3887 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
3888 return get_typeid (TREE_OPERAND (t
, 0));
3889 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3892 return convert_from_reference (t
);
3899 /* This is something of the form `int (*a)++' that has turned out to be an
3900 expr. It was only converted into parse nodes, so we need to go through
3901 and build up the semantics. Most of the work is done by
3902 build_expr_from_tree, above.
3904 In the above example, TYPE is `int' and DECL is `*a'. */
3907 reparse_decl_as_expr (type
, decl
)
3910 decl
= build_expr_from_tree (decl
);
3912 return build_functional_cast (type
, build_expr_list (NULL_TREE
, decl
));
3917 /* This is something of the form `int (*a)' that has turned out to be a
3918 decl. It was only converted into parse nodes, so we need to do the
3919 checking that make_{pointer,reference}_declarator do. */
3922 finish_decl_parsing (decl
)
3925 extern int current_class_depth
;
3927 switch (TREE_CODE (decl
))
3929 case IDENTIFIER_NODE
:
3932 return make_pointer_declarator
3933 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3935 return make_reference_declarator
3936 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3938 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3941 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3942 TREE_COMPLEXITY (decl
) = current_class_depth
;
3945 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3948 /* For attribute handling. */
3949 TREE_VALUE (decl
) = finish_decl_parsing (TREE_VALUE (decl
));
3952 my_friendly_abort (5);
3958 check_cp_case_value (value
)
3961 if (value
== NULL_TREE
)
3964 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3965 STRIP_TYPE_NOPS (value
);
3967 if (TREE_READONLY_DECL_P (value
))
3969 value
= decl_constant_value (value
);
3970 STRIP_TYPE_NOPS (value
);
3972 value
= fold (value
);
3974 if (TREE_CODE (value
) != INTEGER_CST
3975 && value
!= error_mark_node
)
3977 cp_error ("case label `%E' does not reduce to an integer constant",
3979 value
= error_mark_node
;
3982 /* Promote char or short to int. */
3983 value
= default_conversion (value
);
3985 constant_expression_warning (value
);
3990 /* Return 1 if root encloses child. */
3993 is_namespace_ancestor (root
, child
)
3998 if (root
== global_namespace
)
4000 if (child
== global_namespace
)
4002 return is_namespace_ancestor (root
, CP_DECL_CONTEXT (child
));
4006 /* Return the namespace that is the common ancestor
4007 of two given namespaces. */
4010 namespace_ancestor (ns1
, ns2
)
4013 if (is_namespace_ancestor (ns1
, ns2
))
4015 return namespace_ancestor (CP_DECL_CONTEXT (ns1
), ns2
);
4018 /* Insert used into the using list of user. Set indirect_flag if this
4019 directive is not directly from the source. Also find the common
4020 ancestor and let our users know about the new namespace */
4022 add_using_namespace (user
, used
, indirect
)
4028 /* Using oneself is a no-op. */
4031 my_friendly_assert (TREE_CODE (user
) == NAMESPACE_DECL
, 380);
4032 my_friendly_assert (TREE_CODE (used
) == NAMESPACE_DECL
, 380);
4033 /* Check if we already have this. */
4034 t
= purpose_member (used
, DECL_NAMESPACE_USING (user
));
4038 /* Promote to direct usage. */
4039 TREE_INDIRECT_USING (t
) = 0;
4043 /* Add used to the user's using list. */
4044 DECL_NAMESPACE_USING (user
)
4045 = perm_tree_cons (used
, namespace_ancestor (user
, used
),
4046 DECL_NAMESPACE_USING (user
));
4048 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user
)) = indirect
;
4050 /* Add user to the used's users list. */
4051 DECL_NAMESPACE_USERS (used
)
4052 = perm_tree_cons (user
, 0, DECL_NAMESPACE_USERS (used
));
4054 /* Recursively add all namespaces used. */
4055 for (t
= DECL_NAMESPACE_USING (used
); t
; t
= TREE_CHAIN (t
))
4056 /* indirect usage */
4057 add_using_namespace (user
, TREE_PURPOSE (t
), 1);
4059 /* Tell everyone using us about the new used namespaces. */
4060 for (t
= DECL_NAMESPACE_USERS (user
); t
; t
= TREE_CHAIN (t
))
4061 add_using_namespace (TREE_PURPOSE (t
), used
, 1);
4064 /* Combines two sets of overloaded functions into an OVERLOAD chain, removing
4065 duplicates. The first list becomes the tail of the result.
4067 The algorithm is O(n^2). We could get this down to O(n log n) by
4068 doing a sort on the addresses of the functions, if that becomes
4072 merge_functions (s1
, s2
)
4076 for (; s2
; s2
= OVL_NEXT (s2
))
4078 tree fn
= OVL_CURRENT (s2
);
4079 if (! ovl_member (fn
, s1
))
4080 s1
= build_overload (fn
, s1
);
4085 /* This should return an error not all definitions define functions.
4086 It is not an error if we find two functions with exactly the
4087 same signature, only if these are selected in overload resolution.
4088 old is the current set of bindings, new the freshly-found binding.
4089 XXX Do we want to give *all* candidates in case of ambiguity?
4090 XXX In what way should I treat extern declarations?
4091 XXX I don't want to repeat the entire duplicate_decls here */
4094 ambiguous_decl (name
, old
, new, flags
)
4101 my_friendly_assert (old
!= NULL_TREE
, 393);
4102 /* Copy the value. */
4103 val
= BINDING_VALUE (new);
4105 switch (TREE_CODE (val
))
4108 /* If we expect types or namespaces, and not templates,
4109 or this is not a template class. */
4110 if (LOOKUP_QUALIFIERS_ONLY (flags
)
4111 && !DECL_CLASS_TEMPLATE_P (val
))
4115 if (LOOKUP_NAMESPACES_ONLY (flags
))
4118 case NAMESPACE_DECL
:
4119 if (LOOKUP_TYPES_ONLY (flags
))
4123 if (LOOKUP_QUALIFIERS_ONLY (flags
))
4127 if (!BINDING_VALUE (old
))
4128 BINDING_VALUE (old
) = val
;
4129 else if (val
&& val
!= BINDING_VALUE (old
))
4131 if (is_overloaded_fn (BINDING_VALUE (old
))
4132 && is_overloaded_fn (val
))
4134 BINDING_VALUE (old
) = merge_functions (BINDING_VALUE (old
),
4139 /* Some declarations are functions, some are not. */
4140 if (flags
& LOOKUP_COMPLAIN
)
4142 /* If we've already given this error for this lookup,
4143 BINDING_VALUE (old) is error_mark_node, so let's not
4144 repeat ourselves. */
4145 if (BINDING_VALUE (old
) != error_mark_node
)
4147 cp_error ("use of `%D' is ambiguous", name
);
4148 cp_error_at (" first declared as `%#D' here",
4149 BINDING_VALUE (old
));
4151 cp_error_at (" also declared as `%#D' here", val
);
4153 return error_mark_node
;
4156 /* ... and copy the type. */
4157 type
= BINDING_TYPE (new);
4158 if (LOOKUP_NAMESPACES_ONLY (flags
))
4160 if (!BINDING_TYPE (old
))
4161 BINDING_TYPE (old
) = type
;
4162 else if (type
&& BINDING_TYPE (old
) != type
)
4164 if (flags
& LOOKUP_COMPLAIN
)
4166 cp_error ("`%D' denotes an ambiguous type",name
);
4167 cp_error_at (" first type here", BINDING_TYPE (old
));
4168 cp_error_at (" other type here", type
);
4174 /* Add the bindings of name in used namespaces to val.
4175 The using list is defined by usings, and the lookup goes to scope.
4176 Returns zero on errors. */
4179 lookup_using_namespace (name
, val
, usings
, scope
, flags
)
4180 tree name
, val
, usings
, scope
;
4185 /* Iterate over all used namespaces in current, searching for using
4186 directives of scope. */
4187 for (iter
= usings
; iter
; iter
= TREE_CHAIN (iter
))
4188 if (TREE_VALUE (iter
) == scope
)
4190 val1
= binding_for_name (name
, TREE_PURPOSE (iter
));
4191 /* Resolve ambiguities. */
4192 val
= ambiguous_decl (name
, val
, val1
, flags
);
4194 return val
!= error_mark_node
;
4198 Excepts the name to lookup and its qualifying scope.
4199 Returns the name/type pair found into the CPLUS_BINDING result,
4203 qualified_lookup_using_namespace (name
, scope
, result
, flags
)
4209 /* Maintain a list of namespaces visited... */
4210 tree seen
= NULL_TREE
;
4211 /* ... and a list of namespace yet to see. */
4212 tree todo
= NULL_TREE
;
4214 while (scope
&& (result
!= error_mark_node
))
4216 seen
= temp_tree_cons (scope
, NULL_TREE
, seen
);
4217 result
= ambiguous_decl (name
, result
,
4218 binding_for_name (name
, scope
), flags
);
4219 if (!BINDING_VALUE (result
) && !BINDING_TYPE (result
))
4220 /* Consider using directives. */
4221 for (usings
= DECL_NAMESPACE_USING (scope
); usings
;
4222 usings
= TREE_CHAIN (usings
))
4223 /* If this was a real directive, and we have not seen it. */
4224 if (!TREE_INDIRECT_USING (usings
)
4225 && !purpose_member (TREE_PURPOSE (usings
), seen
))
4226 todo
= temp_tree_cons (TREE_PURPOSE (usings
), NULL_TREE
, todo
);
4229 scope
= TREE_PURPOSE (todo
);
4230 todo
= TREE_CHAIN (todo
);
4233 scope
= NULL_TREE
; /* If there never was a todo list. */
4235 return result
!= error_mark_node
;
4238 /* [namespace.memdef]/2 */
4240 /* Set the context of a declaration to scope. Complain if we are not
4244 set_decl_namespace (decl
, scope
, friendp
)
4250 if (scope
== std_node
)
4251 scope
= global_namespace
;
4252 /* Get rid of namespace aliases. */
4253 scope
= ORIGINAL_NAMESPACE (scope
);
4255 /* It is ok for friends to be qualified in parallel space. */
4256 if (!friendp
&& !is_namespace_ancestor (current_namespace
, scope
))
4257 cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
4259 DECL_CONTEXT (decl
) = FROB_CONTEXT (scope
);
4260 if (scope
!= current_namespace
)
4262 /* See whether this has been declared in the namespace. */
4263 old
= namespace_binding (DECL_NAME (decl
), scope
);
4265 /* No old declaration at all. */
4267 if (!is_overloaded_fn (decl
))
4268 /* Don't compare non-function decls with decls_match here,
4269 since it can't check for the correct constness at this
4270 point. pushdecl will find those errors later. */
4272 /* Since decl is a function, old should contain a function decl. */
4273 if (!is_overloaded_fn (old
))
4275 for (; old
; old
= OVL_NEXT (old
))
4276 if (decls_match (decl
, OVL_CURRENT (old
)))
4282 cp_error ("`%D' should have been declared inside `%D'",
4286 /* Compute the namespace where a declaration is defined. */
4289 decl_namespace (decl
)
4292 while (DECL_CONTEXT (decl
))
4294 decl
= DECL_CONTEXT (decl
);
4295 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
4297 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
4298 decl
= TYPE_STUB_DECL (decl
);
4299 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd', 390);
4302 return global_namespace
;
4305 /* Return the namespace where the current declaration is declared. */
4308 current_decl_namespace ()
4311 /* If we have been pushed into a different namespace, use it. */
4312 if (decl_namespace_list
)
4313 return TREE_PURPOSE (decl_namespace_list
);
4315 if (current_class_type
)
4316 result
= decl_namespace (TYPE_STUB_DECL (current_class_type
));
4317 else if (current_function_decl
)
4318 result
= decl_namespace (current_function_decl
);
4320 result
= current_namespace
;
4324 /* Temporarily set the namespace for the current declaration. */
4327 push_decl_namespace (decl
)
4330 if (TREE_CODE (decl
) != NAMESPACE_DECL
)
4331 decl
= decl_namespace (decl
);
4332 decl_namespace_list
= tree_cons (decl
, NULL_TREE
, decl_namespace_list
);
4336 pop_decl_namespace ()
4338 decl_namespace_list
= TREE_CHAIN (decl_namespace_list
);
4341 /* Enter a class or namespace scope. */
4347 if (TREE_CODE (t
) == NAMESPACE_DECL
)
4348 push_decl_namespace (t
);
4353 /* Leave scope pushed by push_scope. */
4359 if (TREE_CODE (t
) == NAMESPACE_DECL
)
4360 pop_decl_namespace ();
4365 /* [basic.lookup.koenig] */
4366 /* A non-zero return value in the functions below indicates an error.
4367 All nodes allocated in the procedure are on the scratch obstack. */
4377 static int arg_assoc
PROTO((struct arg_lookup
*, tree
));
4378 static int arg_assoc_args
PROTO((struct arg_lookup
*, tree
));
4379 static int arg_assoc_type
PROTO((struct arg_lookup
*, tree
));
4380 static int add_function
PROTO((struct arg_lookup
*, tree
));
4381 static int arg_assoc_namespace
PROTO((struct arg_lookup
*, tree
));
4382 static int arg_assoc_class
PROTO((struct arg_lookup
*, tree
));
4384 /* Add a function to the lookup structure.
4385 Returns 1 on error. */
4388 add_function (k
, fn
)
4389 struct arg_lookup
*k
;
4392 if (ovl_member (fn
, k
->functions
))
4394 /* We must find only functions, or exactly one non-function. */
4395 if (k
->functions
&& is_overloaded_fn (k
->functions
)
4396 && is_overloaded_fn (fn
))
4397 k
->functions
= build_overload (fn
, k
->functions
);
4401 tree f1
= OVL_CURRENT (k
->functions
);
4403 if (is_overloaded_fn (f1
))
4405 fn
= f1
; f1
= f2
; f2
= fn
;
4407 cp_error_at ("`%D' is not a function,", f1
);
4408 cp_error_at (" conflict with `%D'", f2
);
4409 cp_error (" in call to `%D'", k
->name
);
4417 /* Add functions of a namespace to the lookup structure.
4418 Returns 1 on error. */
4421 arg_assoc_namespace (k
, scope
)
4422 struct arg_lookup
*k
;
4427 if (purpose_member (scope
, k
->namespaces
))
4429 k
->namespaces
= tree_cons (scope
, NULL_TREE
, k
->namespaces
);
4431 value
= namespace_binding (k
->name
, scope
);
4435 for (; value
; value
= OVL_NEXT (value
))
4436 if (add_function (k
, OVL_CURRENT (value
)))
4442 /* Adds everything associated with class to the lookup structure.
4443 Returns 1 on error. */
4446 arg_assoc_class (k
, type
)
4447 struct arg_lookup
* k
;
4450 tree list
, friends
, context
;
4453 if (purpose_member (type
, k
->classes
))
4455 k
->classes
= tree_cons (type
, NULL_TREE
, k
->classes
);
4457 context
= decl_namespace (TYPE_MAIN_DECL (type
));
4458 if (arg_assoc_namespace (k
, context
))
4461 /* Process baseclasses. */
4462 for (i
= 0; i
< CLASSTYPE_N_BASECLASSES (type
); i
++)
4463 if (arg_assoc_class (k
, TYPE_BINFO_BASETYPE (type
, i
)))
4466 /* Process friends. */
4467 for (list
= DECL_FRIENDLIST (TYPE_MAIN_DECL (type
)); list
;
4468 list
= TREE_CHAIN (list
))
4469 if (k
->name
== TREE_PURPOSE (list
))
4470 for (friends
= TREE_VALUE (list
); friends
;
4471 friends
= TREE_CHAIN (friends
))
4472 /* Only interested in global functions with potentially hidden
4473 (i.e. unqualified) declarations. */
4474 if (TREE_PURPOSE (list
) == error_mark_node
&& TREE_VALUE (list
)
4475 && decl_namespace (TREE_VALUE (list
)) == context
)
4476 if (add_function (k
, TREE_VALUE (list
)))
4479 /* Process template arguments. */
4480 if (CLASSTYPE_TEMPLATE_INFO (type
))
4482 list
= innermost_args (CLASSTYPE_TI_ARGS (type
));
4483 for (i
= 0; i
< TREE_VEC_LENGTH (list
); ++i
)
4484 arg_assoc (k
, TREE_VEC_ELT (list
, i
));
4490 /* Adds everything associated with a given type.
4491 Returns 1 on error. */
4494 arg_assoc_type (k
, type
)
4495 struct arg_lookup
*k
;
4498 switch (TREE_CODE (type
))
4508 if (TYPE_PTRMEMFUNC_P (type
))
4509 return arg_assoc_type (k
, TYPE_PTRMEMFUNC_FN_TYPE (type
));
4510 return arg_assoc_class (k
, type
);
4512 case REFERENCE_TYPE
:
4514 return arg_assoc_type (k
, TREE_TYPE (type
));
4517 return arg_assoc_namespace (k
, decl_namespace (TYPE_MAIN_DECL (type
)));
4519 /* Pointer to member: associate class type and value type. */
4520 if (arg_assoc_type (k
, TYPE_OFFSET_BASETYPE (type
)))
4522 return arg_assoc_type (k
, TREE_TYPE (type
));
4524 /* The basetype is referenced in the first arg type, so just
4527 /* Associate the parameter types. */
4528 if (arg_assoc_args (k
, TYPE_ARG_TYPES (type
)))
4530 /* Associate the return type. */
4531 return arg_assoc_type (k
, TREE_TYPE (type
));
4532 case TEMPLATE_TYPE_PARM
:
4533 case TEMPLATE_TEMPLATE_PARM
:
4536 if (type
== unknown_type_node
)
4538 /* else fall through */
4540 my_friendly_abort (390);
4545 /* Adds everything associated with arguments. Returns 1 on error. */
4548 arg_assoc_args (k
, args
)
4549 struct arg_lookup
* k
;
4552 for (; args
; args
= TREE_CHAIN (args
))
4553 if (arg_assoc (k
, TREE_VALUE (args
)))
4558 /* Adds everything associated with a given tree_node. Returns 1 on error. */
4562 struct arg_lookup
* k
;
4565 if (n
== error_mark_node
)
4568 if (TREE_CODE_CLASS (TREE_CODE (n
)) == 't')
4569 return arg_assoc_type (k
, n
);
4571 if (! type_unknown_p (n
))
4572 return arg_assoc_type (k
, TREE_TYPE (n
));
4574 if (TREE_CODE (n
) == ADDR_EXPR
)
4575 n
= TREE_OPERAND (n
, 0);
4576 if (TREE_CODE (n
) == COMPONENT_REF
)
4577 n
= TREE_OPERAND (n
, 1);
4578 while (TREE_CODE (n
) == TREE_LIST
)
4581 if (TREE_CODE (n
) == FUNCTION_DECL
)
4582 return arg_assoc_type (k
, TREE_TYPE (n
));
4583 if (TREE_CODE (n
) == TEMPLATE_ID_EXPR
)
4585 /* [basic.lookup.koenig]
4587 If T is a template-id, its associated namespaces and classes
4588 are the namespace in which the template is defined; for
4589 member templates, the member template's class; the namespaces
4590 and classes associated with the types of the template
4591 arguments provided for template type parameters (excluding
4592 template template parameters); the namespaces in which any
4593 template template arguments are defined; and the classes in
4594 which any member templates used as template template
4595 arguments are defined. [Note: non-type template arguments do
4596 not contribute to the set of associated namespaces. ] */
4597 tree
template = TREE_OPERAND (n
, 0);
4598 tree args
= TREE_OPERAND (n
, 1);
4602 /* First, the template. There may actually be more than one if
4603 this is an overloaded function template. But, in that case,
4604 we only need the first; all the functions will be in the same
4606 template = OVL_CURRENT (template);
4608 ctx
= CP_DECL_CONTEXT (template);
4610 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
4612 if (arg_assoc_namespace (k
, ctx
) == 1)
4615 /* It must be a member template. */
4616 else if (arg_assoc_class (k
, ctx
) == 1)
4619 /* Now the arguments. */
4620 for (arg
= args
; arg
!= NULL_TREE
; arg
= TREE_CHAIN (arg
))
4622 tree t
= TREE_VALUE (arg
);
4624 if (TREE_CODE (t
) == TEMPLATE_DECL
)
4626 ctx
= CP_DECL_CONTEXT (t
);
4627 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
4629 if (arg_assoc_namespace (k
, ctx
) == 1)
4632 else if (arg_assoc_class (k
, ctx
) == 1)
4635 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't'
4636 && arg_assoc_type (k
, t
) == 1)
4642 my_friendly_assert (TREE_CODE (n
) == OVERLOAD
, 980715);
4644 for (; n
; n
= OVL_CHAIN (n
))
4645 if (arg_assoc_type (k
, TREE_TYPE (OVL_FUNCTION (n
))))
4652 /* Performs Koenig lookup depending on arguments, where fns
4653 are the functions found in normal lookup. */
4656 lookup_arg_dependent (name
, fns
, args
)
4661 struct arg_lookup k
;
4664 k
.namespaces
= NULL_TREE
;
4665 k
.classes
= NULL_TREE
;
4667 push_scratch_obstack ();
4668 arg_assoc_args (&k
, args
);
4673 /* Process a namespace-alias declaration. */
4676 do_namespace_alias (alias
, namespace)
4677 tree alias
, namespace;
4679 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4681 /* The parser did not find it, so it's not there. */
4682 cp_error ("unknown namespace `%D'", namespace);
4686 namespace = ORIGINAL_NAMESPACE (namespace);
4688 /* Build the alias. */
4689 alias
= build_lang_decl (NAMESPACE_DECL
, alias
, void_type_node
);
4690 DECL_NAMESPACE_ALIAS (alias
) = namespace;
4694 /* Check a non-member using-declaration. Return the name and scope
4695 being used, and the USING_DECL, or NULL_TREE on failure. */
4698 validate_nonmember_using_decl (decl
, scope
, name
)
4703 if (TREE_CODE (decl
) == SCOPE_REF
4704 && TREE_OPERAND (decl
, 0) == std_node
)
4706 if (namespace_bindings_p ()
4707 && current_namespace
== global_namespace
)
4708 /* There's no need for a using declaration at all, here,
4709 since `std' is the same as `::'. We can't just pass this
4710 on because we'll complain later about declaring something
4711 in the same scope as a using declaration with the same
4712 name. We return NULL_TREE which indicates to the caller
4713 that there's no need to do any further processing. */
4716 *scope
= global_namespace
;
4717 *name
= TREE_OPERAND (decl
, 1);
4719 else if (TREE_CODE (decl
) == SCOPE_REF
)
4721 *scope
= TREE_OPERAND (decl
, 0);
4722 *name
= TREE_OPERAND (decl
, 1);
4724 /* [namespace.udecl]
4726 A using-declaration for a class member shall be a
4727 member-declaration. */
4728 if (TREE_CODE (*scope
) != NAMESPACE_DECL
)
4730 if (TYPE_P (*scope
))
4731 cp_error ("`%T' is not a namespace", *scope
);
4733 cp_error ("`%D' is not a namespace", *scope
);
4737 else if (TREE_CODE (decl
) == IDENTIFIER_NODE
4738 || TREE_CODE (decl
) == TYPE_DECL
4739 || TREE_CODE (decl
) == TEMPLATE_DECL
)
4741 *scope
= global_namespace
;
4745 my_friendly_abort (382);
4746 if (TREE_CODE_CLASS (TREE_CODE (*name
)) == 'd')
4747 *name
= DECL_NAME (*name
);
4748 /* Make a USING_DECL. */
4749 return push_using_decl (*scope
, *name
);
4752 /* Process local and global using-declarations. */
4755 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, newval
, newtype
)
4757 tree oldval
, oldtype
;
4758 tree
*newval
, *newtype
;
4761 struct tree_binding _decls
;
4763 *newval
= *newtype
= NULL_TREE
;
4764 decls
= binding_init (&_decls
);
4765 if (!qualified_lookup_using_namespace (name
, scope
, decls
, 0))
4769 if (!BINDING_VALUE (decls
) && !BINDING_TYPE (decls
))
4771 cp_error ("`%D' not declared", name
);
4775 /* Check for using functions. */
4776 if (BINDING_VALUE (decls
) && is_overloaded_fn (BINDING_VALUE (decls
)))
4780 if (oldval
&& !is_overloaded_fn (oldval
))
4782 duplicate_decls (OVL_CURRENT (BINDING_VALUE (decls
)), oldval
);
4787 for (tmp
= BINDING_VALUE (decls
); tmp
; tmp
= OVL_NEXT (tmp
))
4789 tree new_fn
= OVL_CURRENT (tmp
);
4791 /* [namespace.udecl]
4793 If a function declaration in namespace scope or block
4794 scope has the same name and the same parameter types as a
4795 function introduced by a using declaration the program is
4797 for (tmp1
= oldval
; tmp1
; tmp1
= OVL_NEXT (tmp1
))
4799 tree old_fn
= OVL_CURRENT (tmp1
);
4801 if (!OVL_USED (tmp1
)
4802 && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn
)),
4803 TYPE_ARG_TYPES (TREE_TYPE (old_fn
))))
4805 /* There was already a non-using declaration in
4806 this scope with the same parameter types. */
4807 cp_error ("`%D' is already declared in this scope",
4811 else if (duplicate_decls (new_fn
, old_fn
))
4812 /* We're re-using something we already used
4813 before. We don't need to add it again. */
4817 /* If we broke out of the loop, there's no reason to add
4818 this function to the using declarations for this
4823 *newval
= build_overload (OVL_CURRENT (tmp
), *newval
);
4824 if (TREE_CODE (*newval
) != OVERLOAD
)
4825 *newval
= ovl_cons (*newval
, NULL_TREE
);
4826 OVL_USED (*newval
) = 1;
4831 *newval
= BINDING_VALUE (decls
);
4833 duplicate_decls (*newval
, oldval
);
4836 *newtype
= BINDING_TYPE (decls
);
4837 if (oldtype
&& *newtype
&& oldtype
!= *newtype
)
4839 cp_error ("using directive `%D' introduced ambiguous type `%T'",
4845 /* Process a using-declaration not appearing in class or local scope. */
4848 do_toplevel_using_decl (decl
)
4851 tree scope
, name
, binding
;
4852 tree oldval
, oldtype
, newval
, newtype
;
4854 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
4855 if (decl
== NULL_TREE
)
4858 binding
= binding_for_name (name
, current_namespace
);
4860 oldval
= BINDING_VALUE (binding
);
4861 oldtype
= BINDING_TYPE (binding
);
4863 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
4865 /* Copy declarations found. */
4867 BINDING_VALUE (binding
) = newval
;
4869 BINDING_TYPE (binding
) = newtype
;
4873 /* Process a using-declaration at function scope. */
4876 do_local_using_decl (decl
)
4880 tree oldval
, oldtype
, newval
, newtype
;
4882 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
4883 if (decl
== NULL_TREE
)
4886 oldval
= lookup_name_current_level (name
);
4887 oldtype
= lookup_type_current_level (name
);
4889 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
4893 if (is_overloaded_fn (newval
))
4897 /* We only need to push declarations for those functions
4898 that were not already bound in the current level.
4899 The old value might be NULL_TREE, it might be a single
4900 function, or an OVERLOAD. */
4901 if (oldval
&& TREE_CODE (oldval
) == OVERLOAD
)
4902 term
= OVL_FUNCTION (oldval
);
4905 for (fn
= newval
; fn
&& OVL_CURRENT (fn
) != term
;
4907 push_overloaded_decl (OVL_CURRENT (fn
),
4908 PUSH_LOCAL
| PUSH_USING
);
4911 push_local_binding (name
, newval
, PUSH_USING
);
4914 set_identifier_type_value (name
, newtype
);
4918 do_class_using_decl (decl
)
4923 if (TREE_CODE (decl
) != SCOPE_REF
4924 || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (decl
, 0))) != 't')
4926 cp_error ("using-declaration for non-member at class scope");
4929 name
= TREE_OPERAND (decl
, 1);
4930 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
4932 cp_error ("using-declaration for destructor");
4935 if (TREE_CODE (name
) == TYPE_DECL
)
4936 name
= DECL_NAME (name
);
4938 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 980716);
4940 value
= build_lang_field_decl (USING_DECL
, name
, void_type_node
);
4941 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
4945 /* Process a using-directive. */
4948 do_using_directive (namespace)
4951 if (namespace == std_node
)
4953 /* using namespace A::B::C; */
4954 if (TREE_CODE (namespace) == SCOPE_REF
)
4955 namespace = TREE_OPERAND (namespace, 1);
4956 if (TREE_CODE (namespace) == IDENTIFIER_NODE
)
4958 /* Lookup in lexer did not find a namespace. */
4959 cp_error ("namespace `%T' undeclared", namespace);
4962 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4964 cp_error ("`%T' is not a namespace", namespace);
4967 namespace = ORIGINAL_NAMESPACE (namespace);
4968 if (!toplevel_bindings_p ())
4969 push_using_directive (namespace);
4972 add_using_namespace (current_namespace
, namespace, 0);
4976 check_default_args (x
)
4979 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
4980 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
4981 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
4983 if (TREE_PURPOSE (arg
))
4987 cp_error_at ("default argument missing for parameter %P of `%+#D'",
4998 TREE_USED (decl
) = 1;
4999 if (processing_template_decl
)
5001 assemble_external (decl
);
5003 /* Is it a synthesized method that needs to be synthesized? */
5004 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CLASS_CONTEXT (decl
)
5005 && DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
5006 /* Kludge: don't synthesize for default args. */
5007 && current_function_decl
)
5008 synthesize_method (decl
);
5010 /* If this is a function or variable that is an instance of some
5011 template, we now know that we will need to actually do the
5012 instantiation. A TEMPLATE_DECL may also have DECL_TEMPLATE_INFO,
5013 if it's a partial instantiation, but there's no need to
5014 instantiate such a thing. We check that DECL is not an explicit
5015 instantiation because that is not checked in instantiate_decl. */
5016 if (TREE_CODE (decl
) != TEMPLATE_DECL
5017 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)
5018 && !DECL_EXPLICIT_INSTANTIATION (decl
))
5019 instantiate_decl (decl
);
5022 /* Helper function for named_class_head_sans_basetype nonterminal. */
5025 handle_class_head (aggr
, scope
, id
)
5026 tree aggr
, scope
, id
;
5028 if (TREE_CODE (id
) == TYPE_DECL
)
5030 if (DECL_CLASS_TEMPLATE_P (id
))
5031 return DECL_TEMPLATE_RESULT (id
);
5034 cp_error ("`%T' does not have a nested type named `%D'", scope
, id
);
5036 cp_error ("no file-scope type named `%D'", id
);
5039 (aggr
, make_anon_name (), 1);
5040 return TYPE_MAIN_DECL (id
);