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));
62 extern int current_class_depth
;
64 /* A list of virtual function tables we must make sure to write out. */
67 /* A list of static class variables. This is needed, because a
68 static class variable can be declared inside the class without
69 an initializer, and then initialized, staticly, outside the class. */
72 /* A list of functions which were declared inline, but which we
73 may need to emit outline anyway. */
74 static tree saved_inlines
;
76 /* Used to help generate temporary names which are unique within
77 a function. Reset to 0 by start_function. */
79 int temp_name_counter
;
81 /* Same, but not reset. Local temp variables and global temp variables
82 can have the same name. */
83 static int global_temp_name_counter
;
85 /* Flag used when debugging spew.c */
87 extern int spew_debug
;
89 /* Nonzero if we're done parsing and into end-of-file activities. */
93 /* Functions called along with real static constructors and destructors. */
95 tree static_ctors
, static_dtors
;
97 /* The current open namespace, and ::. */
99 tree current_namespace
;
100 tree global_namespace
;
102 /* The stack for namespaces of current declarations. */
104 static tree decl_namespace_list
;
107 /* C (and C++) language-specific option variables. */
109 /* Nonzero means allow type mismatches in conditional expressions;
110 just make their values `void'. */
112 int flag_cond_mismatch
;
114 /* Nonzero means give `double' the same size as `float'. */
116 int flag_short_double
;
118 /* Nonzero means don't recognize the keyword `asm'. */
122 /* Nonzero means don't recognize any extension keywords. */
124 int flag_no_gnu_keywords
;
126 /* Nonzero means don't recognize the non-ANSI builtin functions. */
130 /* Nonzero means don't recognize the non-ANSI builtin functions.
133 int flag_no_nonansi_builtin
;
135 /* Nonzero means do some things the same way PCC does. Only provided so
136 the compiler will link. */
138 int flag_traditional
;
140 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
142 int flag_signed_bitfields
= 1;
144 /* Nonzero means enable obscure ANSI features and disable GNU extensions
145 that might cause ANSI-compliant code to be miscompiled. */
149 /* Nonzero means do emit exported implementations of functions even if
150 they can be inlined. */
152 int flag_implement_inlines
= 1;
154 /* Nonzero means do emit exported implementations of templates, instead of
155 multiple static copies in each file that needs a definition. */
157 int flag_external_templates
;
159 /* Nonzero means that the decision to emit or not emit the implementation of a
160 template depends on where the template is instantiated, rather than where
163 int flag_alt_external_templates
;
165 /* Nonzero means that implicit instantiations will be emitted if needed. */
167 int flag_implicit_templates
= 1;
169 /* Nonzero means that implicit instantiations of inline templates will be
170 emitted if needed, even if instantiations of non-inline templates
173 int flag_implicit_inline_templates
= 1;
175 /* Nonzero means warn about implicit declarations. */
177 int warn_implicit
= 1;
179 /* Nonzero means warn about usage of long long when `-pedantic'. */
181 int warn_long_long
= 1;
183 /* Nonzero means warn when all ctors or dtors are private, and the class
186 int warn_ctor_dtor_privacy
= 1;
188 /* True if we want to implement vtables using "thunks".
189 The default is off. */
191 #ifndef DEFAULT_VTABLE_THUNKS
192 #define DEFAULT_VTABLE_THUNKS 0
194 int flag_vtable_thunks
= DEFAULT_VTABLE_THUNKS
;
196 /* True if we want to deal with repository information. */
198 int flag_use_repository
;
200 /* Nonzero if we want to issue diagnostics that the standard says are not
203 int flag_optional_diags
= 1;
205 /* Nonzero means give string constants the type `const char *', as mandated
208 int flag_const_strings
= 1;
210 /* Nonzero means warn about deprecated conversion from string constant to
213 int warn_write_strings
;
215 /* Nonzero means warn about pointer casts that can drop a type qualifier
216 from the pointer target type. */
220 /* Nonzero means warn about sizeof(function) or addition/subtraction
221 of function pointers. */
223 int warn_pointer_arith
= 1;
225 /* Nonzero means warn for any function def without prototype decl. */
227 int warn_missing_prototypes
;
229 /* Nonzero means warn about multiple (redundant) decls for the same single
230 variable or function. */
232 int warn_redundant_decls
;
234 /* Warn if initializer is not completely bracketed. */
236 int warn_missing_braces
;
238 /* Warn about comparison of signed and unsigned values. */
240 int warn_sign_compare
;
242 /* Warn about *printf or *scanf format/argument anomalies. */
246 /* Warn about a subscript that has type char. */
248 int warn_char_subscripts
;
250 /* Warn if a type conversion is done that might have confusing results. */
254 /* Warn if adding () is suggested. */
256 int warn_parentheses
;
258 /* Non-zero means warn in function declared in derived class has the
259 same name as a virtual in the base class, but fails to match the
260 type signature of any virtual function in the base class. */
261 int warn_overloaded_virtual
;
263 /* Non-zero means warn when declaring a class that has a non virtual
264 destructor, when it really ought to have a virtual one. */
267 /* Non-zero means warn when a function is declared extern and later inline. */
268 int warn_extern_inline
;
270 /* Non-zero means warn when the compiler will reorder code. */
273 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
276 /* Non-zero means warn when we convert a pointer to member function
277 into a pointer to (void or function). */
278 int warn_pmf2ptr
= 1;
280 /* Nonzero means warn about violation of some Effective C++ style rules. */
284 /* Nonzero means warn where overload resolution chooses a promotion from
285 unsigned to signed over a conversion to an unsigned of the same size. */
289 /* Nonzero means warn when an old-style cast is used. */
291 int warn_old_style_cast
;
293 /* Warn about #pragma directives that are not recognised. */
295 int warn_unknown_pragmas
; /* Tri state variable. */
297 /* Nonzero means warn about use of multicharacter literals. */
299 int warn_multichar
= 1;
301 /* Nonzero means warn when non-templatized friend functions are
302 declared within a template */
304 int warn_nontemplate_friend
= 1;
306 /* Nonzero means `$' can be in an identifier. */
308 #ifndef DOLLARS_IN_IDENTIFIERS
309 #define DOLLARS_IN_IDENTIFIERS 1
311 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
313 /* Nonzero for -fno-strict-prototype switch: do not consider empty
314 argument prototype to mean function takes no arguments. */
316 int flag_strict_prototype
= 2;
317 int strict_prototype
= 1;
318 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
320 /* Nonzero means that labels can be used as first-class objects */
324 /* Non-zero means to collect statistics which might be expensive
325 and to print them when we are done. */
326 int flag_detailed_statistics
;
328 /* C++ specific flags. */
329 /* Zero means that `this' is a *const. This gives nice behavior in the
330 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
331 -2 means we're constructing an object and it has fixed type. */
333 int flag_this_is_variable
;
335 /* 3 means write out only virtuals function tables `defined'
336 in this implementation file.
337 0 means write out virtual function tables and give them
338 (C) static access (default). */
342 /* Nonzero means we should attempt to elide constructors when possible. */
344 int flag_elide_constructors
= 1;
346 /* Nonzero means recognize and handle signature language constructs. */
348 int flag_handle_signatures
;
350 /* Nonzero means that member functions defined in class scope are
351 inline by default. */
353 int flag_default_inline
= 1;
355 /* Controls whether compiler generates 'type descriptor' that give
356 run-time type information. */
359 /* Nonzero if we wish to output cross-referencing information
360 for the GNU class browser. */
361 extern int flag_gnu_xref
;
363 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
366 int flag_huge_objects
;
368 /* Nonzero if we want to conserve space in the .o files. We do this
369 by putting uninitialized data and runtime initialized data into
370 .common instead of .data at the expense of not flagging multiple
373 int flag_conserve_space
;
375 /* Nonzero if we want to obey access control semantics. */
377 int flag_access_control
= 1;
379 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
381 int flag_operator_names
;
383 /* Nonzero if we want to check the return value of new and avoid calling
384 constructors if it is a null pointer. */
388 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
389 initialization variables.
390 0: Old rules, set by -fno-for-scope.
391 2: New ANSI rules, set by -ffor-scope.
392 1: Try to implement new ANSI rules, but with backup compatibility
393 (and warnings). This is the default, for now. */
395 int flag_new_for_scope
= 1;
397 /* Nonzero if we want to emit defined symbols with common-like linkage as
398 weak symbols where possible, in order to conform to C++ semantics.
399 Otherwise, emit them as local symbols. */
403 /* Nonzero to enable experimental ABI changes. */
407 /* Nonzero to not ignore namespace std. */
411 /* Maximum template instantiation depth. Must be at least 17 for ANSI
414 int max_tinst_depth
= 17;
416 /* The name-mangling scheme to use. Must be 1 or greater to support
417 template functions with identical types, but different template
419 int name_mangling_version
= 2;
421 /* Nonzero means that guiding declarations are allowed. */
422 int flag_guiding_decls
;
424 /* Nonzero if squashed mangling is to be performed.
425 This uses the B and K codes to reference previously seen class types
426 and class qualifiers. */
427 int flag_do_squangling
;
429 /* Nonzero means output .vtable_{entry,inherit} for use in doing vtable gc. */
433 /* Nonzero means make the default pedwarns warnings instead of errors.
434 The value of this flag is ignored if -pedantic is specified. */
438 /* Table of language-dependent -f options.
439 STRING is the option name. VARIABLE is the address of the variable.
440 ON_VALUE is the value to store in VARIABLE
441 if `-fSTRING' is seen as an option.
442 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
444 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
447 {"signed-char", &flag_signed_char
, 1},
448 {"unsigned-char", &flag_signed_char
, 0},
449 {"signed-bitfields", &flag_signed_bitfields
, 1},
450 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
451 {"short-enums", &flag_short_enums
, 1},
452 {"short-double", &flag_short_double
, 1},
453 {"cond-mismatch", &flag_cond_mismatch
, 1},
454 {"asm", &flag_no_asm
, 0},
455 {"builtin", &flag_no_builtin
, 0},
457 /* C++-only options. */
458 {"access-control", &flag_access_control
, 1},
459 {"check-new", &flag_check_new
, 1},
460 {"conserve-space", &flag_conserve_space
, 1},
461 {"const-strings", &flag_const_strings
, 1},
462 {"default-inline", &flag_default_inline
, 1},
463 {"dollars-in-identifiers", &dollars_in_ident
, 1},
464 {"elide-constructors", &flag_elide_constructors
, 1},
465 {"external-templates", &flag_external_templates
, 1},
466 {"for-scope", &flag_new_for_scope
, 2},
467 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
468 {"handle-exceptions", &flag_exceptions
, 1},
469 {"handle-signatures", &flag_handle_signatures
, 1},
470 {"honor-std", &flag_honor_std
, 1},
471 {"huge-objects", &flag_huge_objects
, 1},
472 {"implement-inlines", &flag_implement_inlines
, 1},
473 {"implicit-inline-templates", &flag_implicit_inline_templates
, 1},
474 {"implicit-templates", &flag_implicit_templates
, 1},
475 {"labels-ok", &flag_labels_ok
, 1},
476 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
477 {"operator-names", &flag_operator_names
, 1},
478 {"optional-diags", &flag_optional_diags
, 1},
479 {"permissive", &flag_permissive
, 1},
480 {"repo", &flag_use_repository
, 1},
481 {"rtti", &flag_rtti
, 1},
482 {"squangle", &flag_do_squangling
, 1},
483 {"stats", &flag_detailed_statistics
, 1},
484 {"strict-prototype", &flag_strict_prototype
, 1},
485 {"this-is-variable", &flag_this_is_variable
, 1},
486 {"vtable-gc", &flag_vtable_gc
, 1},
487 {"vtable-thunks", &flag_vtable_thunks
, 1},
488 {"weak", &flag_weak
, 1},
489 {"xref", &flag_gnu_xref
, 1}
492 /* Decode the string P as a language-specific option.
493 Return the number of strings consumed for a valid option.
494 Otherwise return 0. */
497 lang_decode_option (argc
, argv
)
506 int strings_processed
;
509 strings_processed
= cpp_handle_option (&parse_in
, argc
, argv
);
511 strings_processed
= 0;
512 #endif /* ! USE_CPPLIB */
514 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
516 else if (p
[0] == '-' && p
[1] == 'f')
518 /* Some kind of -f option.
519 P's value is the option sans `-f'.
520 Search for it in the table of options. */
525 /* Try special -f options. */
527 if (!strcmp (p
, "handle-exceptions")
528 || !strcmp (p
, "no-handle-exceptions"))
529 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
531 if (!strcmp (p
, "memoize-lookups")
532 || !strcmp (p
, "no-memoize-lookups")
533 || !strcmp (p
, "save-memoized")
534 || !strcmp (p
, "no-save-memoized")
535 || !strcmp (p
, "no-all-virtual")
536 || !strcmp (p
, "no-enum-int-equiv")
537 || !strcmp (p
, "nonnull-objects")
538 || !strcmp (p
, "ansi-overloading"))
543 else if (!strcmp (p
, "all-virtual")
544 || !strcmp (p
, "enum-int-equiv")
545 || !strcmp (p
, "no-nonnull-objects")
546 || !strcmp (p
, "no-ansi-overloading"))
548 warning ("-f%s is no longer supported", p
);
551 else if (! strcmp (p
, "alt-external-templates"))
553 flag_external_templates
= 1;
554 flag_alt_external_templates
= 1;
557 else if (! strcmp (p
, "no-alt-external-templates"))
559 flag_alt_external_templates
= 0;
562 else if (!strcmp (p
, "repo"))
564 flag_use_repository
= 1;
565 flag_implicit_templates
= 0;
568 else if (!strcmp (p
, "guiding-decls"))
570 flag_guiding_decls
= 1;
571 name_mangling_version
= 0;
574 else if (!strcmp (p
, "no-guiding-decls"))
576 flag_guiding_decls
= 0;
579 else if (!strcmp (p
, "new-abi"))
582 flag_do_squangling
= 1;
584 flag_vtable_thunks
= 1;
586 else if (!strcmp (p
, "no-new-abi"))
589 flag_do_squangling
= 0;
592 else if (!strncmp (p
, "template-depth-", 15))
595 read_integral_parameter (p
+ 15, p
- 2, max_tinst_depth
);
597 else if (!strncmp (p
, "name-mangling-version-", 22))
599 name_mangling_version
=
600 read_integral_parameter (p
+ 22, p
- 2, name_mangling_version
);
603 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
606 if (!strcmp (p
, lang_f_options
[j
].string
))
608 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
609 /* A goto here would be cleaner,
610 but breaks the vax pcc. */
613 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
614 && ! strcmp (p
+3, lang_f_options
[j
].string
))
616 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
622 else if (p
[0] == '-' && p
[1] == 'W')
626 /* The -W options control the warning behavior of the compiler. */
629 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
632 if (!strcmp (p
, "implicit"))
633 warn_implicit
= setting
;
634 else if (!strcmp (p
, "long-long"))
635 warn_long_long
= setting
;
636 else if (!strcmp (p
, "return-type"))
637 warn_return_type
= setting
;
638 else if (!strcmp (p
, "ctor-dtor-privacy"))
639 warn_ctor_dtor_privacy
= setting
;
640 else if (!strcmp (p
, "write-strings"))
641 warn_write_strings
= setting
;
642 else if (!strcmp (p
, "cast-qual"))
643 warn_cast_qual
= setting
;
644 else if (!strcmp (p
, "char-subscripts"))
645 warn_char_subscripts
= setting
;
646 else if (!strcmp (p
, "pointer-arith"))
647 warn_pointer_arith
= setting
;
648 else if (!strcmp (p
, "missing-prototypes"))
649 warn_missing_prototypes
= setting
;
650 else if (!strcmp (p
, "redundant-decls"))
651 warn_redundant_decls
= setting
;
652 else if (!strcmp (p
, "missing-braces"))
653 warn_missing_braces
= setting
;
654 else if (!strcmp (p
, "sign-compare"))
655 warn_sign_compare
= setting
;
656 else if (!strcmp (p
, "format"))
657 warn_format
= setting
;
658 else if (!strcmp (p
, "conversion"))
659 warn_conversion
= setting
;
660 else if (!strcmp (p
, "parentheses"))
661 warn_parentheses
= setting
;
662 else if (!strcmp (p
, "non-virtual-dtor"))
663 warn_nonvdtor
= setting
;
664 else if (!strcmp (p
, "extern-inline"))
665 warn_extern_inline
= setting
;
666 else if (!strcmp (p
, "reorder"))
667 warn_reorder
= setting
;
668 else if (!strcmp (p
, "synth"))
669 warn_synth
= setting
;
670 else if (!strcmp (p
, "pmf-conversions"))
671 warn_pmf2ptr
= setting
;
672 else if (!strcmp (p
, "effc++"))
674 else if (!strcmp (p
, "sign-promo"))
675 warn_sign_promo
= setting
;
676 else if (!strcmp (p
, "old-style-cast"))
677 warn_old_style_cast
= setting
;
678 else if (!strcmp (p
, "overloaded-virtual"))
679 warn_overloaded_virtual
= setting
;
680 else if (!strcmp (p
, "multichar"))
681 warn_multichar
= setting
;
682 else if (!strcmp (p
, "unknown-pragmas"))
683 /* Set to greater than 1, so that even unknown pragmas in
684 system headers will be warned about. */
685 warn_unknown_pragmas
= setting
* 2;
686 else if (!strcmp (p
, "non-template-friend"))
687 warn_nontemplate_friend
= setting
;
688 else if (!strcmp (p
, "comment"))
689 ; /* cpp handles this one. */
690 else if (!strcmp (p
, "comments"))
691 ; /* cpp handles this one. */
692 else if (!strcmp (p
, "trigraphs"))
693 ; /* cpp handles this one. */
694 else if (!strcmp (p
, "import"))
695 ; /* cpp handles this one. */
696 else if (!strcmp (p
, "all"))
698 warn_return_type
= setting
;
699 warn_unused
= setting
;
700 warn_implicit
= setting
;
701 warn_ctor_dtor_privacy
= setting
;
702 warn_switch
= setting
;
703 warn_format
= setting
;
704 warn_parentheses
= setting
;
705 warn_missing_braces
= setting
;
706 warn_sign_compare
= setting
;
707 warn_extern_inline
= setting
;
708 warn_nonvdtor
= setting
;
709 warn_multichar
= setting
;
710 /* We save the value of warn_uninitialized, since if they put
711 -Wuninitialized on the command line, we need to generate a
712 warning about not using it without also specifying -O. */
713 if (warn_uninitialized
!= 1)
714 warn_uninitialized
= (setting
? 2 : 0);
715 warn_reorder
= setting
;
716 warn_sign_promo
= setting
;
717 /* Only warn about unknown pragmas that are not in system
719 warn_unknown_pragmas
= 1;
720 warn_nontemplate_friend
= setting
;
722 else return strings_processed
;
724 else if (!strcmp (p
, "-ansi"))
725 flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
726 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
728 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
729 it's probably safe to assume no sane person would ever want to use this
730 under normal circumstances. */
731 else if (!strcmp (p
, "-spew-debug"))
735 return strings_processed
;
740 /* Incorporate `const' and `volatile' qualifiers for member functions.
741 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
742 QUALS is a list of qualifiers. */
745 grok_method_quals (ctype
, function
, quals
)
746 tree ctype
, function
, quals
;
748 tree fntype
= TREE_TYPE (function
);
749 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
750 int type_quals
= TYPE_UNQUALIFIED
;
751 int dup_quals
= TYPE_UNQUALIFIED
;
755 int tq
= cp_type_qual_from_rid (TREE_VALUE (quals
));
761 quals
= TREE_CHAIN (quals
);
765 if (dup_quals
!= TYPE_UNQUALIFIED
)
766 cp_error ("duplicate type qualifiers in %s declaration",
767 TREE_CODE (function
) == FUNCTION_DECL
768 ? "member function" : "type");
770 ctype
= cp_build_qualified_type (ctype
, type_quals
);
771 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
772 (TREE_CODE (fntype
) == METHOD_TYPE
773 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
774 : TYPE_ARG_TYPES (fntype
)));
776 fntype
= build_exception_variant (fntype
, raises
);
778 TREE_TYPE (function
) = fntype
;
782 /* Warn when -fexternal-templates is used and #pragma
783 interface/implementation is not used all the times it should be,
787 warn_if_unknown_interface (decl
)
790 static int already_warned
= 0;
791 if (already_warned
++)
794 if (flag_alt_external_templates
)
796 struct tinst_level
*til
= tinst_for_decl ();
798 char *sf
= input_filename
;
803 input_filename
= til
->file
;
805 cp_warning ("template `%#D' instantiated in file without #pragma interface",
811 cp_warning_at ("template `%#D' defined in file without #pragma interface",
815 /* A subroutine of the parser, to handle a component list. */
818 grok_x_components (specs
)
821 struct pending_inline
**p
;
824 specs
= strip_attrs (specs
);
826 check_tag_decl (specs
);
827 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
829 /* The only case where we need to do anything additional here is an
830 anonymous union field, e.g.: `struct S { union { int i; }; };'. */
831 if (t
== NULL_TREE
|| !ANON_UNION_TYPE_P (t
))
834 fixup_anonymous_union (t
);
835 finish_member_declaration (build_lang_field_decl (FIELD_DECL
,
839 /* Ignore any inline function definitions in the anonymous union
840 since an anonymous union may not have function members. */
841 p
= &pending_inlines
;
842 for (; *p
; *p
= (*p
)->next
)
843 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
847 /* Constructors for types with virtual baseclasses need an "in-charge" flag
848 saying whether this constructor is responsible for initialization of
849 virtual baseclasses or not. All destructors also need this "in-charge"
850 flag, which additionally determines whether or not the destructor should
851 free the memory for the object.
853 This function adds the "in-charge" flag to member function FN if
854 appropriate. It is called from grokclassfn and tsubst.
855 FN must be either a constructor or destructor. */
858 maybe_retrofit_in_chrg (fn
)
861 tree basetype
, arg_types
, parms
, parm
, fntype
;
863 if (DECL_CONSTRUCTOR_P (fn
)
864 && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CLASS_CONTEXT (fn
))
865 && ! DECL_CONSTRUCTOR_FOR_VBASE_P (fn
))
867 else if (! DECL_CONSTRUCTOR_P (fn
)
868 && TREE_CHAIN (DECL_ARGUMENTS (fn
)) == NULL_TREE
)
873 if (DECL_CONSTRUCTOR_P (fn
))
874 DECL_CONSTRUCTOR_FOR_VBASE_P (fn
) = 1;
876 /* First add it to DECL_ARGUMENTS... */
877 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
878 /* Mark the artificial `__in_chrg' parameter as "artificial". */
879 SET_DECL_ARTIFICIAL (parm
);
880 DECL_ARG_TYPE (parm
) = integer_type_node
;
881 TREE_READONLY (parm
) = 1;
882 parms
= DECL_ARGUMENTS (fn
);
883 TREE_CHAIN (parm
) = TREE_CHAIN (parms
);
884 TREE_CHAIN (parms
) = parm
;
886 /* ...and then to TYPE_ARG_TYPES. */
887 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
888 basetype
= TREE_TYPE (TREE_VALUE (arg_types
));
889 arg_types
= hash_tree_chain (integer_type_node
, TREE_CHAIN (arg_types
));
890 fntype
= build_cplus_method_type (basetype
, TREE_TYPE (TREE_TYPE (fn
)),
892 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)))
893 fntype
= build_exception_variant (fntype
,
894 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)));
895 TREE_TYPE (fn
) = fntype
;
898 /* Classes overload their constituent function names automatically.
899 When a function name is declared in a record structure,
900 its name is changed to it overloaded name. Since names for
901 constructors and destructors can conflict, we place a leading
904 CNAME is the name of the class we are grokking for.
906 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
908 FLAGS contains bits saying what's special about today's
909 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
911 If FUNCTION is a destructor, then we must add the `auto-delete' field
912 as a second parameter. There is some hair associated with the fact
913 that we must "declare" this variable in the manner consistent with the
914 way the rest of the arguments were declared.
916 QUALS are the qualifiers for the this pointer. */
919 grokclassfn (ctype
, function
, flags
, quals
)
920 tree ctype
, function
;
921 enum overload_flags flags
;
924 tree fn_name
= DECL_NAME (function
);
929 if (fn_name
== NULL_TREE
)
931 error ("name missing for member function");
932 fn_name
= get_identifier ("<anonymous>");
933 DECL_NAME (function
) = fn_name
;
937 qualtype
= grok_method_quals (ctype
, function
, quals
);
941 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
942 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
944 /* Must add the class instance variable up front. */
945 /* Right now we just make this a pointer. But later
946 we may wish to make it special. */
947 tree type
= TREE_VALUE (arg_types
);
950 if ((flag_this_is_variable
> 0)
951 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
954 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
955 /* Mark the artificial `this' parameter as "artificial". */
956 SET_DECL_ARTIFICIAL (parm
);
957 DECL_ARG_TYPE (parm
) = type
;
958 /* We can make this a register, so long as we don't
959 accidentally complain if someone tries to take its address. */
960 DECL_REGISTER (parm
) = 1;
962 TREE_READONLY (parm
) = 1;
963 TREE_CHAIN (parm
) = last_function_parms
;
964 last_function_parms
= parm
;
967 DECL_ARGUMENTS (function
) = last_function_parms
;
968 /* First approximations. */
969 DECL_CONTEXT (function
) = ctype
;
970 DECL_CLASS_CONTEXT (function
) = ctype
;
972 if (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
))
974 maybe_retrofit_in_chrg (function
);
975 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
978 if (flags
== DTOR_FLAG
)
980 DECL_ASSEMBLER_NAME (function
) = build_destructor_name (ctype
);
981 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
984 set_mangled_name_for_decl (function
);
987 /* Work on the expr used by alignof (this is only called by the parser). */
996 if (processing_template_decl
)
997 return build_min (ALIGNOF_EXPR
, sizetype
, expr
);
999 if (TREE_CODE (expr
) == COMPONENT_REF
1000 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1001 error ("`__alignof__' applied to a bit-field");
1003 if (TREE_CODE (expr
) == INDIRECT_REF
)
1005 best
= t
= TREE_OPERAND (expr
, 0);
1006 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1008 while (TREE_CODE (t
) == NOP_EXPR
1009 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1012 t
= TREE_OPERAND (t
, 0);
1013 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1014 if (thisalign
> bestalign
)
1015 best
= t
, bestalign
= thisalign
;
1017 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1021 /* ANSI says arrays and fns are converted inside comma.
1022 But we can't convert them in build_compound_expr
1023 because that would break commas in lvalues.
1024 So do the conversion here if operand was a comma. */
1025 if (TREE_CODE (expr
) == COMPOUND_EXPR
1026 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1027 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1028 expr
= default_conversion (expr
);
1029 return c_alignof (TREE_TYPE (expr
));
1033 /* Create an ARRAY_REF, checking for the user doing things backwards
1037 grok_array_decl (array_expr
, index_exp
)
1038 tree array_expr
, index_exp
;
1040 tree type
= TREE_TYPE (array_expr
);
1041 tree p1
, p2
, i1
, i2
;
1043 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1044 return error_mark_node
;
1045 if (processing_template_decl
)
1046 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
1047 array_expr
, index_exp
);
1049 if (type
== NULL_TREE
)
1051 /* Something has gone very wrong. Assume we are mistakenly reducing
1052 an expression instead of a declaration. */
1053 error ("parser may be lost: is there a '{' missing somewhere?");
1057 if (TREE_CODE (type
) == OFFSET_TYPE
1058 || TREE_CODE (type
) == REFERENCE_TYPE
)
1059 type
= TREE_TYPE (type
);
1061 /* If they have an `operator[]', use that. */
1062 if (IS_AGGR_TYPE (type
) || IS_AGGR_TYPE (TREE_TYPE (index_exp
)))
1063 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1064 array_expr
, index_exp
, NULL_TREE
);
1066 /* Otherwise, create an ARRAY_REF for a pointer or array type. It
1067 is a little-known fact that, if `a' is an array and `i' is an
1068 int, you can write `i[a]', which means the same thing as `a[i]'. */
1070 if (TREE_CODE (type
) == ARRAY_TYPE
)
1073 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1075 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1078 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1080 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1081 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1083 if ((p1
&& i2
) && (i1
&& p2
))
1084 error ("ambiguous conversion for array subscript");
1087 array_expr
= p1
, index_exp
= i2
;
1089 array_expr
= p2
, index_exp
= i1
;
1092 cp_error ("invalid types `%T[%T]' for array subscript",
1093 type
, TREE_TYPE (index_exp
));
1094 return error_mark_node
;
1097 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1098 error ("ambiguous conversion for array subscript");
1100 return build_array_ref (array_expr
, index_exp
);
1103 /* Given the cast expression EXP, checking out its validity. Either return
1104 an error_mark_node if there was an unavoidable error, return a cast to
1105 void for trying to delete a pointer w/ the value 0, or return the
1106 call to delete. If DOING_VEC is 1, we handle things differently
1107 for doing an array delete. If DOING_VEC is 2, they gave us the
1108 array size as an argument to delete.
1109 Implements ARM $5.3.4. This is called from the parser. */
1112 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1114 int doing_vec
, use_global_delete
;
1117 /* For a regular vector delete (aka, no size argument) we will pass
1118 this down as a NULL_TREE into build_vec_delete. */
1119 tree maxindex
= NULL_TREE
;
1121 if (exp
== error_mark_node
)
1124 if (processing_template_decl
)
1126 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
1127 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
1128 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
1132 if (TREE_CODE (exp
) == OFFSET_REF
)
1133 exp
= resolve_offset_ref (exp
);
1134 exp
= convert_from_reference (exp
);
1135 t
= stabilize_reference (exp
);
1136 t
= build_expr_type_conversion (WANT_POINTER
, t
, 1);
1138 if (t
== NULL_TREE
|| t
== error_mark_node
)
1140 cp_error ("type `%#T' argument given to `delete', expected pointer",
1142 return error_mark_node
;
1147 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1148 pedwarn ("anachronistic use of array size in vector delete");
1151 type
= TREE_TYPE (t
);
1153 /* As of Valley Forge, you can delete a pointer to const. */
1155 /* You can't delete functions. */
1156 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1158 error ("cannot delete a function");
1159 return error_mark_node
;
1162 /* An array can't have been allocated by new, so complain. */
1163 if (TREE_CODE (t
) == ADDR_EXPR
1164 && TREE_CODE (TREE_OPERAND (t
, 0)) == VAR_DECL
1165 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == ARRAY_TYPE
)
1166 cp_warning ("deleting array `%#D'", TREE_OPERAND (t
, 0));
1168 /* Deleting a pointer with the value zero is valid and has no effect. */
1169 if (integer_zerop (t
))
1170 return build1 (NOP_EXPR
, void_type_node
, t
);
1173 return build_vec_delete (t
, maxindex
, integer_one_node
,
1174 integer_zero_node
, use_global_delete
);
1177 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1178 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1180 /* Only do access checking here; we'll be calling op delete
1181 from the destructor. */
1182 tree tmp
= build_op_delete_call (DELETE_EXPR
, t
, size_zero_node
,
1183 LOOKUP_NORMAL
, NULL_TREE
);
1184 if (tmp
== error_mark_node
)
1185 return error_mark_node
;
1188 return build_delete (type
, t
, integer_three_node
,
1189 LOOKUP_NORMAL
, use_global_delete
);
1193 /* Report an error if the indicated template declaration is not the
1194 sort of thing that should be a member template. */
1197 check_member_template (tmpl
)
1202 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 0);
1203 decl
= DECL_TEMPLATE_RESULT (tmpl
);
1205 if (TREE_CODE (decl
) == FUNCTION_DECL
1206 || (TREE_CODE (decl
) == TYPE_DECL
1207 && IS_AGGR_TYPE (TREE_TYPE (decl
))))
1209 if (current_function_decl
)
1210 /* 14.5.2.2 [temp.mem]
1212 A local class shall not have member templates. */
1213 cp_error ("declaration of member template `%#D' in local class",
1216 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
1218 /* 14.5.2.3 [temp.mem]
1220 A member function template shall not be virtual. */
1222 ("invalid use of `virtual' in template declaration of `%#D'",
1224 DECL_VIRTUAL_P (decl
) = 0;
1227 /* The debug-information generating code doesn't know what to do
1228 with member templates. */
1229 DECL_IGNORED_P (tmpl
) = 1;
1232 cp_error ("template declaration of `%#D'", decl
);
1235 /* Return true iff TYPE is a valid Java parameter or return type. */
1238 acceptable_java_type (type
)
1241 if (TREE_CODE (type
) == VOID_TYPE
|| TYPE_FOR_JAVA (type
))
1243 if (TREE_CODE (type
) == POINTER_TYPE
)
1245 type
= TREE_TYPE (type
);
1246 if (TREE_CODE (type
) == RECORD_TYPE
)
1249 if (! TYPE_FOR_JAVA (type
))
1251 if (! CLASSTYPE_TEMPLATE_INFO (type
))
1253 args
= CLASSTYPE_TI_ARGS (type
);
1254 i
= TREE_VEC_LENGTH (args
);
1257 type
= TREE_VEC_ELT (args
, i
);
1258 if (TREE_CODE (type
) == POINTER_TYPE
)
1259 type
= TREE_TYPE (type
);
1260 if (! TYPE_FOR_JAVA (type
))
1269 /* For a METHOD in a Java class CTYPE, return 1 if
1270 the parameter and return types are valid Java types.
1271 Otherwise, print appropriate error messages, and return 0. */
1274 check_java_method (method
)
1278 tree arg_types
= TYPE_ARG_TYPES (TREE_TYPE (method
));
1279 tree ret_type
= TREE_TYPE (TREE_TYPE (method
));
1280 if (! acceptable_java_type (ret_type
))
1282 cp_error ("Java method '%D' has non-Java return type `%T'",
1286 for (; arg_types
!= NULL_TREE
; arg_types
= TREE_CHAIN (arg_types
))
1288 tree type
= TREE_VALUE (arg_types
);
1289 if (! acceptable_java_type (type
))
1291 cp_error ("Java method '%D' has non-Java parameter type `%T'",
1296 return jerr
? 0 : 1;
1299 /* Sanity check: report error if this function FUNCTION is not
1300 really a member of the class (CTYPE) it is supposed to belong to.
1301 CNAME is the same here as it is for grokclassfn above. */
1304 check_classfn (ctype
, function
)
1305 tree ctype
, function
;
1307 tree fn_name
= DECL_NAME (function
);
1308 tree fndecl
, fndecls
;
1309 tree method_vec
= CLASSTYPE_METHOD_VEC (complete_type (ctype
));
1313 if (DECL_USE_TEMPLATE (function
)
1314 && is_member_template (DECL_TI_TEMPLATE (function
)))
1315 /* Since this is a specialization of a member template,
1316 we're not going to find the declaration in the class.
1319 struct S { template <typename T> void f(T); };
1320 template <> void S::f(int);
1322 we're not going to find `S::f(int)', but there's no
1323 reason we should, either. We let our callers know we didn't
1324 find the method, but we don't complain. */
1327 if (method_vec
!= 0)
1329 methods
= &TREE_VEC_ELT (method_vec
, 0);
1330 end
= TREE_VEC_END (method_vec
);
1332 /* First suss out ctors and dtors. */
1333 if (*methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1334 && DECL_CONSTRUCTOR_P (function
))
1336 if (*++methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1337 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
)))
1340 while (++methods
!= end
&& *methods
)
1343 if (fn_name
== DECL_NAME (OVL_CURRENT (*methods
)))
1346 for (fndecls
= *methods
; fndecls
!= NULL_TREE
;
1347 fndecls
= OVL_NEXT (fndecls
))
1349 fndecl
= OVL_CURRENT (fndecls
);
1350 /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL, or
1351 for a for member function of a template class, is
1352 not mangled, so the check below does not work
1353 correctly in that case. Since mangled destructor
1354 names do not include the type of the arguments,
1355 we can't use this short-cut for them, either.
1356 (It's not legal to declare arguments for a
1357 destructor, but some people try.) */
1358 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
))
1359 && (DECL_ASSEMBLER_NAME (function
)
1360 != DECL_NAME (function
))
1361 && (DECL_ASSEMBLER_NAME (fndecl
)
1362 != DECL_NAME (fndecl
))
1363 && (DECL_ASSEMBLER_NAME (function
)
1364 == DECL_ASSEMBLER_NAME (fndecl
)))
1367 /* We cannot simply call decls_match because this
1368 doesn't work for static member functions that are
1369 pretending to be methods, and because the name
1370 may have been changed by asm("new_name"). */
1371 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1373 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1374 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1376 /* Get rid of the this parameter on functions that become
1378 if (DECL_STATIC_FUNCTION_P (fndecl
)
1379 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1380 p1
= TREE_CHAIN (p1
);
1382 if (same_type_p (TREE_TYPE (TREE_TYPE (function
)),
1383 TREE_TYPE (TREE_TYPE (fndecl
)))
1384 && compparms (p1
, p2
)
1385 && (DECL_TEMPLATE_SPECIALIZATION (function
)
1386 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
1387 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
1388 || (DECL_TI_TEMPLATE (function
)
1389 == DECL_TI_TEMPLATE (fndecl
))))
1398 if (methods
!= end
&& *methods
)
1400 tree fndecl
= *methods
;
1401 cp_error ("prototype for `%#D' does not match any in class `%T'",
1403 cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl
) ? "s are" : " is",
1404 OVL_CURRENT (fndecl
));
1405 while (fndecl
= OVL_NEXT (fndecl
), fndecl
)
1406 cp_error_at (" %#D", OVL_CURRENT(fndecl
));
1411 if (TYPE_SIZE (ctype
) == 0)
1412 incomplete_type_error (function
, ctype
);
1414 cp_error ("no `%#D' member function declared in class `%T'",
1418 /* If we did not find the method in the class, add it to avoid
1419 spurious errors (unless the CTYPE is not yet defined, in which
1420 case we'll only confuse ourselves when the function is declared
1421 properly within the class. */
1422 if (TYPE_SIZE (ctype
))
1423 add_method (ctype
, methods
, function
);
1427 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1428 of a structure component, returning a FIELD_DECL node.
1429 QUALS is a list of type qualifiers for this decl (such as for declaring
1430 const member functions).
1432 This is done during the parsing of the struct declaration.
1433 The FIELD_DECL nodes are chained together and the lot of them
1434 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1438 If class A defines that certain functions in class B are friends, then
1439 the way I have set things up, it is B who is interested in permission
1440 granted by A. However, it is in A's context that these declarations
1441 are parsed. By returning a void_type_node, class A does not attempt
1442 to incorporate the declarations of the friends within its structure.
1444 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1445 CHANGES TO CODE IN `start_method'. */
1448 grokfield (declarator
, declspecs
, init
, asmspec_tree
, attrlist
)
1449 tree declarator
, declspecs
, init
, asmspec_tree
, attrlist
;
1451 register tree value
;
1453 int flags
= LOOKUP_ONLYCONVERTING
;
1455 /* Convert () initializers to = initializers. */
1456 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1457 && TREE_CODE (declarator
) == CALL_EXPR
1458 && TREE_OPERAND (declarator
, 0)
1459 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1460 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1461 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1463 init
= TREE_OPERAND (declarator
, 1);
1464 declarator
= TREE_OPERAND (declarator
, 0);
1468 if (declspecs
== NULL_TREE
1469 && TREE_CODE (declarator
) == SCOPE_REF
1470 && TREE_CODE (TREE_OPERAND (declarator
, 1)) == IDENTIFIER_NODE
)
1472 /* Access declaration */
1473 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
1475 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
1476 pop_nested_class (1);
1477 return do_class_using_decl (declarator
);
1481 && TREE_CODE (init
) == TREE_LIST
1482 && TREE_VALUE (init
) == error_mark_node
1483 && TREE_CHAIN (init
) == NULL_TREE
)
1486 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, NULL_TREE
);
1487 if (! value
|| value
== error_mark_node
)
1488 /* friend or constructor went bad. */
1491 /* Pass friendly classes back. */
1492 if (TREE_CODE (value
) == VOID_TYPE
)
1493 return void_type_node
;
1495 if (DECL_NAME (value
) != NULL_TREE
1496 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1497 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1498 cp_error ("member `%D' conflicts with virtual function table field name",
1501 /* Stash away type declarations. */
1502 if (TREE_CODE (value
) == TYPE_DECL
)
1504 DECL_NONLOCAL (value
) = 1;
1505 DECL_CONTEXT (value
) = current_class_type
;
1506 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1508 /* Now that we've updated the context, we need to remangle the
1509 name for this TYPE_DECL. */
1510 DECL_ASSEMBLER_NAME (value
) = DECL_NAME (value
);
1511 if (!uses_template_parms (value
))
1512 DECL_ASSEMBLER_NAME (value
) =
1513 get_identifier (build_overload_name (TREE_TYPE (value
), 1, 1));
1515 pushdecl_class_level (value
);
1519 if (IS_SIGNATURE (current_class_type
)
1520 && TREE_CODE (value
) != FUNCTION_DECL
)
1522 error ("field declaration not allowed in signature");
1523 return void_type_node
;
1526 if (DECL_IN_AGGR_P (value
))
1528 cp_error ("`%D' is already defined in `%T'", value
,
1529 DECL_CONTEXT (value
));
1530 return void_type_node
;
1534 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1538 if (IS_SIGNATURE (current_class_type
)
1539 && TREE_CODE (value
) == FUNCTION_DECL
)
1541 error ("function declarations cannot have initializers in signature");
1544 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1546 grok_function_init (value
, init
);
1549 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1550 /* Already complained in grokdeclarator. */
1554 /* We allow initializers to become parameters to base
1556 if (TREE_CODE (init
) == TREE_LIST
)
1558 if (TREE_CHAIN (init
) == NULL_TREE
)
1559 init
= TREE_VALUE (init
);
1561 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1564 if (TREE_CODE (init
) == CONST_DECL
)
1565 init
= DECL_INITIAL (init
);
1566 else if (TREE_READONLY_DECL_P (init
))
1567 init
= decl_constant_value (init
);
1568 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1569 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1570 my_friendly_assert (TREE_PERMANENT (init
), 192);
1571 if (init
== error_mark_node
)
1572 /* We must make this look different than `error_mark_node'
1573 because `decl_const_value' would mis-interpret it
1574 as only meaning that this VAR_DECL is defined. */
1575 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1576 else if (processing_template_decl
)
1578 else if (! TREE_CONSTANT (init
))
1580 /* We can allow references to things that are effectively
1581 static, since references are initialized with the address. */
1582 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1583 || (TREE_STATIC (init
) == 0
1584 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1585 || DECL_EXTERNAL (init
) == 0)))
1587 error ("field initializer is not constant");
1588 init
= error_mark_node
;
1594 /* The corresponding pop_obstacks is in cp_finish_decl. */
1595 push_obstacks_nochange ();
1597 if (processing_template_decl
&& ! current_function_decl
1598 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1599 value
= push_template_decl (value
);
1601 check_template_shadow (value
);
1604 cplus_decl_attributes (value
, TREE_PURPOSE (attrlist
),
1605 TREE_VALUE (attrlist
));
1607 if (TREE_CODE (value
) == VAR_DECL
)
1609 my_friendly_assert (TREE_PUBLIC (value
), 0);
1611 /* We cannot call pushdecl here, because that would
1612 fill in the value of our TREE_CHAIN. Instead, we
1613 modify cp_finish_decl to do the right thing, namely, to
1614 put this decl out straight away. */
1615 /* current_class_type can be NULL_TREE in case of error. */
1616 if (asmspec
== 0 && current_class_type
)
1618 TREE_PUBLIC (value
) = 1;
1619 DECL_INITIAL (value
) = error_mark_node
;
1620 DECL_ASSEMBLER_NAME (value
)
1621 = build_static_name (current_class_type
, DECL_NAME (value
));
1623 if (! processing_template_decl
)
1624 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1626 /* Static consts need not be initialized in the class definition. */
1627 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1629 static int explanation
= 0;
1631 error ("initializer invalid for static member with constructor");
1632 if (explanation
++ == 0)
1633 error ("(you really want to initialize it separately)");
1636 /* Force the compiler to know when an uninitialized static
1637 const member is being used. */
1638 if (CP_TYPE_CONST_P (TREE_TYPE (value
)) && init
== 0)
1639 TREE_USED (value
) = 1;
1640 DECL_INITIAL (value
) = init
;
1641 DECL_IN_AGGR_P (value
) = 1;
1642 DECL_CONTEXT (value
) = current_class_type
;
1643 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1645 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1646 pushdecl_class_level (value
);
1649 if (TREE_CODE (value
) == FIELD_DECL
)
1653 /* This must override the asm specifier which was placed
1654 by grokclassfn. Lay this out fresh. */
1655 DECL_RTL (value
) = NULL_RTX
;
1656 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1658 if (DECL_INITIAL (value
) == error_mark_node
)
1659 init
= error_mark_node
;
1660 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1661 DECL_INITIAL (value
) = init
;
1662 DECL_IN_AGGR_P (value
) = 1;
1665 if (TREE_CODE (value
) == FUNCTION_DECL
)
1669 /* This must override the asm specifier which was placed
1670 by grokclassfn. Lay this out fresh. */
1671 DECL_RTL (value
) = NULL_RTX
;
1672 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1674 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1676 /* Pass friends back this way. */
1677 if (DECL_FRIEND_P (value
))
1678 return void_type_node
;
1680 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1681 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1682 cp_error ("method `%#D' of local class must be defined in class body",
1686 DECL_IN_AGGR_P (value
) = 1;
1689 my_friendly_abort (21);
1694 /* Like `grokfield', but for bitfields.
1695 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1698 grokbitfield (declarator
, declspecs
, width
)
1699 tree declarator
, declspecs
, width
;
1701 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1704 if (! value
) return NULL_TREE
; /* friends went bad. */
1706 /* Pass friendly classes back. */
1707 if (TREE_CODE (value
) == VOID_TYPE
)
1708 return void_type_node
;
1710 if (TREE_CODE (value
) == TYPE_DECL
)
1712 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1716 /* Usually, finish_struct_1 catches bitifields with invalid types.
1717 But, in the case of bitfields with function type, we confuse
1718 ourselves into thinking they are member functions, so we must
1720 if (TREE_CODE (value
) == FUNCTION_DECL
)
1722 cp_error ("cannot declare bitfield `%D' with funcion type",
1727 if (IS_SIGNATURE (current_class_type
))
1729 error ("field declaration not allowed in signature");
1730 return void_type_node
;
1733 if (DECL_IN_AGGR_P (value
))
1735 cp_error ("`%D' is already defined in the class %T", value
,
1736 DECL_CONTEXT (value
));
1737 return void_type_node
;
1740 GNU_xref_member (current_class_name
, value
);
1742 if (TREE_STATIC (value
))
1744 cp_error ("static member `%D' cannot be a bitfield", value
);
1747 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1749 if (width
!= error_mark_node
)
1751 constant_expression_warning (width
);
1752 DECL_INITIAL (value
) = width
;
1753 SET_DECL_C_BIT_FIELD (value
);
1756 DECL_IN_AGGR_P (value
) = 1;
1761 grokoptypename (declspecs
, declarator
)
1762 tree declspecs
, declarator
;
1764 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1765 return build_typename_overload (t
);
1768 /* When a function is declared with an initializer,
1769 do the right thing. Currently, there are two possibilities:
1774 // initialization possibility #1.
1775 virtual void f () = 0;
1797 // initialization possibility #2
1804 copy_assignment_arg_p (parmtype
, virtualp
)
1806 int virtualp ATTRIBUTE_UNUSED
;
1808 if (current_class_type
== NULL_TREE
)
1811 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1812 parmtype
= TREE_TYPE (parmtype
);
1814 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1816 /* Non-standard hack to support old Booch components. */
1817 || (! virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
))
1826 grok_function_init (decl
, init
)
1830 /* An initializer for a function tells how this function should
1832 tree type
= TREE_TYPE (decl
);
1834 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1835 cp_error ("initializer specified for non-member function `%D'", decl
);
1837 /* We'll check for this in finish_struct_1. */
1838 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1839 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1841 else if (integer_zerop (init
))
1844 /* Mark this function as being "defined". */
1845 DECL_INITIAL (decl
) = error_mark_node
;
1846 /* pure virtual destructors must be defined. */
1847 /* pure virtual needs to be defined (as abort) only when put in
1848 vtbl. For wellformed call, it should be itself. pr4737 */
1849 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1851 extern tree abort_fndecl
;
1852 /* Give this node rtl from `abort'. */
1853 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1856 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1857 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1860 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1862 if (copy_assignment_arg_p (parmtype
, 1))
1863 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1867 cp_error ("invalid initializer for virtual method `%D'", decl
);
1871 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1872 tree decl
, attributes
, prefix_attributes
;
1874 if (decl
== NULL_TREE
|| decl
== void_type_node
)
1877 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1878 decl
= DECL_TEMPLATE_RESULT (decl
);
1880 decl_attributes (decl
, attributes
, prefix_attributes
);
1882 if (TREE_CODE (decl
) == TYPE_DECL
)
1883 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
1886 /* CONSTRUCTOR_NAME:
1887 Return the name for the constructor (or destructor) for the
1888 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1889 IDENTIFIER_NODE. When given a template, this routine doesn't
1890 lose the specialization. */
1893 constructor_name_full (thing
)
1896 if (TREE_CODE (thing
) == TEMPLATE_TYPE_PARM
1897 || TREE_CODE (thing
) == TEMPLATE_TEMPLATE_PARM
1898 || TREE_CODE (thing
) == TYPENAME_TYPE
)
1899 thing
= TYPE_NAME (thing
);
1900 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
1902 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
1903 thing
= DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing
), 0)));
1905 thing
= TYPE_NAME (thing
);
1907 if (TREE_CODE (thing
) == TYPE_DECL
1908 || (TREE_CODE (thing
) == TEMPLATE_DECL
1909 && TREE_CODE (DECL_TEMPLATE_RESULT (thing
)) == TYPE_DECL
))
1910 thing
= DECL_NAME (thing
);
1911 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
1915 /* CONSTRUCTOR_NAME:
1916 Return the name for the constructor (or destructor) for the
1917 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1918 IDENTIFIER_NODE. When given a template, return the plain
1919 unspecialized name. */
1922 constructor_name (thing
)
1926 thing
= constructor_name_full (thing
);
1927 t
= IDENTIFIER_TEMPLATE (thing
);
1933 /* Cache the value of this class's main virtual function table pointer
1934 in a register variable. This will save one indirection if a
1935 more than one virtual function call is made this function. */
1940 extern tree base_init_expr
;
1942 if (base_init_expr
== 0
1943 && DECL_CONSTRUCTOR_P (current_function_decl
))
1945 if (processing_template_decl
)
1946 add_tree (build_min_nt
1948 current_member_init_list
, current_base_init_list
));
1950 emit_base_init (current_class_type
, 0);
1954 /* Record the existence of an addressable inline function. */
1957 mark_inline_for_output (decl
)
1960 decl
= DECL_MAIN_VARIANT (decl
);
1961 if (DECL_SAVED_INLINE (decl
))
1963 my_friendly_assert (TREE_PERMANENT (decl
), 363);
1964 DECL_SAVED_INLINE (decl
) = 1;
1966 if (DECL_PENDING_INLINE_INFO (decl
) != 0
1967 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
1969 struct pending_inline
*t
= pending_inlines
;
1970 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
1973 if (t
== DECL_PENDING_INLINE_INFO (decl
))
1979 t
= DECL_PENDING_INLINE_INFO (decl
);
1980 t
->next
= pending_inlines
;
1981 pending_inlines
= t
;
1983 DECL_PENDING_INLINE_INFO (decl
) = 0;
1986 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
1992 temp_name_counter
= 0;
1995 /* Hand off a unique name which can be used for variable we don't really
1996 want to know about anyway, for example, the anonymous variables which
1997 are needed to make references work. Declare this thing so we can use it.
1998 The variable created will be of type TYPE.
2000 STATICP is nonzero if this variable should be static. */
2003 get_temp_name (type
, staticp
)
2007 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2009 int toplev
= toplevel_bindings_p ();
2011 push_obstacks_nochange ();
2012 if (toplev
|| staticp
)
2014 end_temporary_allocation ();
2015 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2016 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2020 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2021 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2023 TREE_USED (decl
) = 1;
2024 TREE_STATIC (decl
) = staticp
;
2025 DECL_ARTIFICIAL (decl
) = 1;
2027 /* If this is a local variable, then lay out its rtl now.
2028 Otherwise, callers of this function are responsible for dealing
2029 with this variable's rtl. */
2033 expand_decl_init (decl
);
2040 /* Get a variable which we can use for multiple assignments.
2041 It is not entered into current_binding_level, because
2042 that breaks things when it comes time to do final cleanups
2043 (which take place "outside" the binding contour of the function). */
2046 get_temp_regvar (type
, init
)
2051 decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
2052 TREE_USED (decl
) = 1;
2053 DECL_REGISTER (decl
) = 1;
2054 DECL_ARTIFICIAL (decl
) = 1;
2056 DECL_RTL (decl
) = assign_temp (type
, 2, 0, 1);
2057 /* We can expand these without fear, since they cannot need
2058 constructors or destructors. */
2059 expand_expr (build_modify_expr (decl
, INIT_EXPR
, init
),
2060 NULL_RTX
, VOIDmode
, 0);
2065 /* Hunts through the global anonymous union ANON_DECL, building
2066 appropriate VAR_DECLs. Stores cleanups on the list of ELEMS, and
2067 returns a VAR_DECL whose size is the same as the size of the
2068 ANON_DECL, if one is available. */
2071 build_anon_union_vars (anon_decl
, elems
, static_p
, external_p
)
2077 tree type
= TREE_TYPE (anon_decl
);
2078 tree main_decl
= NULL_TREE
;
2081 for (field
= TYPE_FIELDS (type
);
2083 field
= TREE_CHAIN (field
))
2087 if (DECL_ARTIFICIAL (field
))
2089 if (TREE_CODE (field
) != FIELD_DECL
)
2091 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
2096 if (TREE_PRIVATE (field
))
2097 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
2098 else if (TREE_PROTECTED (field
))
2099 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
2101 if (DECL_NAME (field
) == NULL_TREE
2102 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2104 decl
= build_anon_union_vars (field
, elems
, static_p
, external_p
);
2108 else if (DECL_NAME (field
) == NULL_TREE
)
2112 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2113 /* tell `pushdecl' that this is not tentative. */
2114 DECL_INITIAL (decl
) = error_mark_node
;
2115 TREE_PUBLIC (decl
) = 0;
2116 TREE_STATIC (decl
) = static_p
;
2117 DECL_EXTERNAL (decl
) = external_p
;
2118 decl
= pushdecl (decl
);
2119 DECL_INITIAL (decl
) = NULL_TREE
;
2122 /* Only write out one anon union element--choose the one that
2123 can hold them all. */
2124 if (main_decl
== NULL_TREE
2125 && simple_cst_equal (DECL_SIZE (decl
),
2126 DECL_SIZE (anon_decl
)) == 1)
2129 /* ??? This causes there to be no debug info written out
2131 TREE_ASM_WRITTEN (decl
) = 1;
2133 if (DECL_NAME (field
) == NULL_TREE
2134 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2135 /* The remainder of the processing was already done in the
2139 /* If there's a cleanup to do, it belongs in the
2140 TREE_PURPOSE of the following TREE_LIST. */
2141 *elems
= scratch_tree_cons (NULL_TREE
, decl
, *elems
);
2142 TREE_TYPE (*elems
) = type
;
2148 /* Finish off the processing of a UNION_TYPE structure.
2149 If there are static members, then all members are
2150 static, and must be laid out together. If the
2151 union is an anonymous union, we arrange for that
2152 as well. PUBLIC_P is nonzero if this union is
2153 not declared static. */
2156 finish_anon_union (anon_union_decl
)
2157 tree anon_union_decl
;
2159 tree type
= TREE_TYPE (anon_union_decl
);
2160 tree elems
= NULL_TREE
;
2162 int public_p
= TREE_PUBLIC (anon_union_decl
);
2163 int static_p
= TREE_STATIC (anon_union_decl
);
2164 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2166 if (TYPE_FIELDS (type
) == NULL_TREE
)
2171 error ("global anonymous unions must be declared static");
2175 main_decl
= build_anon_union_vars (anon_union_decl
, &elems
,
2176 static_p
, external_p
);
2178 if (main_decl
== NULL_TREE
)
2180 warning ("anonymous union with no members");
2186 make_decl_rtl (main_decl
, 0, toplevel_bindings_p ());
2187 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2190 /* The following call assumes that there are never any cleanups
2191 for anonymous unions--a reasonable assumption. */
2192 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2195 /* Finish processing a builtin type TYPE. It's name is NAME,
2196 its fields are in the array FIELDS. LEN is the number of elements
2197 in FIELDS minus one, or put another way, it is the maximum subscript
2200 It is given the same alignment as ALIGN_TYPE. */
2203 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2212 TYPE_FIELDS (type
) = fields
[0];
2213 for (i
= 0; i
< len
; i
++)
2215 layout_type (TREE_TYPE (fields
[i
]));
2216 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2217 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2219 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2220 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2221 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2223 #if 0 /* not yet, should get fixed properly later */
2224 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2226 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2228 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
2229 layout_decl (TYPE_NAME (type
), 0);
2232 /* Auxiliary functions to make type signatures for
2233 `operator new' and `operator delete' correspond to
2234 what compiler will be expecting. */
2237 coerce_new_type (type
)
2242 if (TREE_CODE (type
) == METHOD_TYPE
)
2243 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2244 if (! same_type_p (TREE_TYPE (type
), ptr_type_node
))
2245 e1
= 1, error ("`operator new' must return type `void *'");
2247 /* Technically the type must be `size_t', but we may not know
2249 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2250 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2251 else if (! same_type_p (TREE_VALUE (TYPE_ARG_TYPES (type
)), sizetype
))
2252 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2254 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2256 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2261 coerce_delete_type (type
)
2268 tree arg_types
= TYPE_ARG_TYPES (type
);
2270 if (TREE_CODE (type
) == METHOD_TYPE
)
2272 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2273 arg_types
= TREE_CHAIN (arg_types
);
2276 if (TREE_TYPE (type
) != void_type_node
)
2277 e1
= 1, error ("`operator delete' must return type `void'");
2279 if (arg_types
== NULL_TREE
2280 || ! same_type_p (TREE_VALUE (arg_types
), ptr_type_node
))
2281 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2285 && TREE_CHAIN (arg_types
)
2286 && TREE_CHAIN (arg_types
) != void_list_node
)
2288 /* Again, technically this argument must be `size_t', but again
2289 we may not know what that is. */
2290 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2291 if (! same_type_p (t2
, sizetype
))
2292 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2293 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2296 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2297 error ("too many arguments in declaration of `operator delete'");
2299 error ("`...' invalid in specification of `operator delete'");
2304 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2305 build_tree_list (NULL_TREE
, sizetype
));
2308 if (arg_types
== NULL_TREE
)
2309 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2311 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2317 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2318 arg_types
? TREE_CHAIN (arg_types
): NULL_TREE
);
2320 type
= build_function_type (void_type_node
, arg_types
);
2325 extern tree abort_fndecl
;
2328 mark_vtable_entries (decl
)
2331 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
2335 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (TREE_CHAIN (entries
))
2336 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2337 tree fn
= TREE_OPERAND (fnaddr
, 0);
2338 TREE_ADDRESSABLE (fn
) = 1;
2341 skip_rtti_stuff (&entries
);
2343 for (; entries
; entries
= TREE_CHAIN (entries
))
2345 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (entries
)
2346 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2347 tree fn
= TREE_OPERAND (fnaddr
, 0);
2348 TREE_ADDRESSABLE (fn
) = 1;
2349 if (DECL_LANG_SPECIFIC (fn
) && DECL_ABSTRACT_VIRTUAL_P (fn
))
2351 TREE_OPERAND (fnaddr
, 0) = fn
= copy_node (fn
);
2352 DECL_RTL (fn
) = DECL_RTL (abort_fndecl
);
2353 mark_used (abort_fndecl
);
2355 if (TREE_CODE (fn
) == THUNK_DECL
&& DECL_EXTERNAL (fn
))
2357 DECL_EXTERNAL (fn
) = 0;
2364 /* Set DECL up to have the closest approximation of "initialized common"
2365 linkage available. */
2368 comdat_linkage (decl
)
2372 make_decl_one_only (decl
);
2374 TREE_PUBLIC (decl
) = 0;
2376 if (DECL_LANG_SPECIFIC (decl
))
2377 DECL_COMDAT (decl
) = 1;
2380 /* For win32 we also want to put explicit instantiations in
2381 linkonce sections, so that they will be merged with implicit
2382 instantiations; otherwise we get duplicate symbol errors. */
2385 maybe_make_one_only (decl
)
2388 /* This is not necessary on targets that support weak symbols, because
2389 the implicit instantiations will defer to the explicit one. */
2390 if (! supports_one_only () || SUPPORTS_WEAK
)
2393 /* We can't set DECL_COMDAT on functions, or finish_file will think
2394 we can get away with not emitting them if they aren't used.
2395 We can't use make_decl_one_only for variables, because their
2396 DECL_INITIAL may not have been set properly yet. */
2398 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2399 make_decl_one_only (decl
);
2401 comdat_linkage (decl
);
2404 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2405 based on TYPE and other static flags.
2407 Note that anything public is tagged TREE_PUBLIC, whether
2408 it's public in this file or in another one. */
2411 import_export_vtable (decl
, type
, final
)
2415 if (DECL_INTERFACE_KNOWN (decl
))
2418 if (TYPE_FOR_JAVA (type
))
2420 TREE_PUBLIC (decl
) = 1;
2421 DECL_EXTERNAL (decl
) = 1;
2422 DECL_INTERFACE_KNOWN (decl
) = 1;
2424 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2426 TREE_PUBLIC (decl
) = 1;
2427 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2428 DECL_INTERFACE_KNOWN (decl
) = 1;
2432 /* We can only wait to decide if we have real non-inline virtual
2433 functions in our class, or if we come from a template. */
2435 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2437 if (! found
&& ! final
)
2440 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
2441 method
= TREE_CHAIN (method
))
2442 if (DECL_VINDEX (method
) != NULL_TREE
2443 && ! DECL_THIS_INLINE (method
)
2444 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2451 if (final
|| ! found
)
2453 comdat_linkage (decl
);
2454 DECL_EXTERNAL (decl
) = 0;
2458 TREE_PUBLIC (decl
) = 1;
2459 DECL_EXTERNAL (decl
) = 1;
2464 /* Determine whether or not we want to specifically import or export CTYPE,
2465 using various heuristics. */
2468 import_export_class (ctype
)
2471 /* -1 for imported, 1 for exported. */
2472 int import_export
= 0;
2474 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2477 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2478 /* FIXME this should really use some sort of target-independent macro. */
2479 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype
)))
2481 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype
)))
2485 /* If we got -fno-implicit-templates, we import template classes that
2486 weren't explicitly instantiated. */
2487 if (import_export
== 0
2488 && CLASSTYPE_IMPLICIT_INSTANTIATION (ctype
)
2489 && ! flag_implicit_templates
)
2492 /* Base our import/export status on that of the first non-inline,
2493 non-abstract virtual function, if any. */
2494 if (import_export
== 0
2495 && TYPE_VIRTUAL_P (ctype
)
2496 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2499 for (method
= TYPE_METHODS (ctype
); method
!= NULL_TREE
;
2500 method
= TREE_CHAIN (method
))
2502 if (DECL_VINDEX (method
) != NULL_TREE
2503 && !DECL_THIS_INLINE (method
)
2504 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2506 import_export
= (DECL_REALLY_EXTERN (method
) ? -1 : 1);
2512 #ifdef MULTIPLE_SYMBOL_SPACES
2513 if (import_export
== -1)
2519 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2520 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
) = (import_export
> 0);
2521 CLASSTYPE_INTERFACE_ONLY (ctype
) = (import_export
< 0);
2525 /* We need to describe to the assembler the relationship between
2526 a vtable and the vtable of the parent class. */
2529 output_vtable_inherit (vars
)
2535 op
[0] = XEXP (DECL_RTL (vars
), 0); /* strip the mem ref */
2537 parent
= binfo_for_vtable (vars
);
2539 if (parent
== TYPE_BINFO (DECL_CONTEXT (vars
)))
2543 parent
= TYPE_BINFO_VTABLE (BINFO_TYPE (parent
));
2544 op
[1] = XEXP (DECL_RTL (parent
), 0); /* strip the mem ref */
2547 my_friendly_abort (980826);
2549 output_asm_insn (".vtable_inherit %c0, %c1", op
);
2553 finish_vtable_vardecl (prev
, vars
)
2556 tree ctype
= DECL_CONTEXT (vars
);
2557 import_export_class (ctype
);
2558 import_export_vtable (vars
, ctype
, 1);
2560 if (! DECL_EXTERNAL (vars
)
2561 && (DECL_INTERFACE_KNOWN (vars
)
2562 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
))
2563 || (hack_decl_function_context (vars
) && TREE_USED (vars
)))
2564 && ! TREE_ASM_WRITTEN (vars
))
2567 mark_vtable_entries (vars
);
2568 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2569 store_init_value (vars
, DECL_INITIAL (vars
));
2571 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2573 /* Mark the VAR_DECL node representing the vtable itself as a
2574 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2575 It is rather important that such things be ignored because
2576 any effort to actually generate DWARF for them will run
2577 into trouble when/if we encounter code like:
2580 struct S { virtual void member (); };
2582 because the artificial declaration of the vtable itself (as
2583 manufactured by the g++ front end) will say that the vtable
2584 is a static member of `S' but only *after* the debug output
2585 for the definition of `S' has already been output. This causes
2586 grief because the DWARF entry for the definition of the vtable
2587 will try to refer back to an earlier *declaration* of the
2588 vtable as a static member of `S' and there won't be one.
2589 We might be able to arrange to have the "vtable static member"
2590 attached to the member list for `S' before the debug info for
2591 `S' get written (which would solve the problem) but that would
2592 require more intrusive changes to the g++ front end. */
2594 DECL_IGNORED_P (vars
) = 1;
2597 /* Always make vtables weak. */
2599 comdat_linkage (vars
);
2601 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2604 output_vtable_inherit (vars
);
2608 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
)))
2609 /* We don't know what to do with this one yet. */
2612 /* We know that PREV must be non-zero here. */
2613 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2618 prune_vtable_vardecl (prev
, vars
)
2621 /* We know that PREV must be non-zero here. */
2622 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2627 walk_vtables (typedecl_fn
, vardecl_fn
)
2628 register void (*typedecl_fn
) PROTO ((tree
, tree
));
2629 register int (*vardecl_fn
) PROTO ((tree
, tree
));
2634 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2636 register tree type
= TREE_TYPE (vars
);
2638 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2641 flag
|= (*vardecl_fn
) (prev
, vars
);
2643 if (prev
&& TREE_CHAIN (prev
) != vars
)
2646 else if (TREE_CODE (vars
) == TYPE_DECL
2647 && type
!= error_mark_node
2648 && TYPE_LANG_SPECIFIC (type
)
2649 && CLASSTYPE_VSIZE (type
))
2651 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2661 finish_sigtable_vardecl (prev
, vars
)
2664 /* We don't need to mark sigtable entries as addressable here as is done
2665 for vtables. Since sigtables, unlike vtables, are always written out,
2666 that was already done in build_signature_table_constructor. */
2668 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2670 /* We know that PREV must be non-zero here. */
2671 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2675 walk_sigtables (typedecl_fn
, vardecl_fn
)
2676 register void (*typedecl_fn
) PROTO((tree
, tree
));
2677 register void (*vardecl_fn
) PROTO((tree
, tree
));
2681 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2683 register tree type
= TREE_TYPE (vars
);
2685 if (TREE_CODE (vars
) == TYPE_DECL
2686 && type
!= error_mark_node
2687 && IS_SIGNATURE (type
))
2689 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2691 else if (TREE_CODE (vars
) == VAR_DECL
2692 && TREE_TYPE (vars
) != error_mark_node
2693 && IS_SIGNATURE (TREE_TYPE (vars
)))
2695 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2702 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2703 inline function or template instantiation at end-of-file. */
2706 import_export_decl (decl
)
2709 if (DECL_INTERFACE_KNOWN (decl
))
2712 if (DECL_TEMPLATE_INSTANTIATION (decl
)
2713 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
))
2715 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2716 if ((DECL_IMPLICIT_INSTANTIATION (decl
)
2717 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
))
2718 && (flag_implicit_templates
2719 || (flag_implicit_inline_templates
&& DECL_THIS_INLINE (decl
))))
2721 if (!TREE_PUBLIC (decl
))
2722 /* Templates are allowed to have internal linkage. See
2725 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2726 comdat_linkage (decl
);
2728 DECL_COMDAT (decl
) = 1;
2731 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2733 else if (DECL_FUNCTION_MEMBER_P (decl
))
2735 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2736 import_export_class (ctype
);
2737 if (CLASSTYPE_INTERFACE_KNOWN (ctype
)
2738 && (! DECL_ARTIFICIAL (decl
) || DECL_VINDEX (decl
)))
2740 DECL_NOT_REALLY_EXTERN (decl
)
2741 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2742 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2744 /* Always make artificials weak. */
2745 if (DECL_ARTIFICIAL (decl
) && flag_weak
)
2746 comdat_linkage (decl
);
2748 maybe_make_one_only (decl
);
2751 comdat_linkage (decl
);
2753 /* tinfo function */
2754 else if (DECL_ARTIFICIAL (decl
) && DECL_MUTABLE_P (decl
))
2756 tree ctype
= TREE_TYPE (DECL_NAME (decl
));
2758 if (IS_AGGR_TYPE (ctype
))
2759 import_export_class (ctype
);
2761 if (IS_AGGR_TYPE (ctype
) && CLASSTYPE_INTERFACE_KNOWN (ctype
)
2762 && TYPE_VIRTUAL_P (ctype
)
2763 /* If the type is a cv-qualified variant of a type, then we
2764 must emit the tinfo function in this translation unit
2765 since it will not be emitted when the vtable for the type
2766 is output (which is when the unqualified version is
2768 && ctype
== TYPE_MAIN_VARIANT (ctype
))
2770 DECL_NOT_REALLY_EXTERN (decl
)
2771 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2772 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2774 /* Always make artificials weak. */
2776 comdat_linkage (decl
);
2778 else if (TYPE_BUILT_IN (ctype
) && ctype
== TYPE_MAIN_VARIANT (ctype
))
2779 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2781 comdat_linkage (decl
);
2784 comdat_linkage (decl
);
2786 DECL_INTERFACE_KNOWN (decl
) = 1;
2790 build_cleanup (decl
)
2794 tree type
= TREE_TYPE (decl
);
2796 if (TREE_CODE (type
) == ARRAY_TYPE
)
2800 mark_addressable (decl
);
2801 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
2803 temp
= build_delete (TREE_TYPE (temp
), temp
,
2805 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2809 extern int parse_time
, varconst_time
;
2810 extern tree pending_templates
;
2811 extern tree maybe_templates
;
2817 tree sname
= get_id_2 ("__sn", base
);
2818 /* For struct X foo __attribute__((weak)), there is a counter
2819 __snfoo. Since base is already an assembler name, sname should
2820 be globally unique */
2821 tree sentry
= IDENTIFIER_GLOBAL_VALUE (sname
);
2824 push_obstacks_nochange ();
2825 end_temporary_allocation ();
2826 sentry
= build_decl (VAR_DECL
, sname
, integer_type_node
);
2827 TREE_PUBLIC (sentry
) = 1;
2828 DECL_ARTIFICIAL (sentry
) = 1;
2829 TREE_STATIC (sentry
) = 1;
2830 TREE_USED (sentry
) = 1;
2831 DECL_COMMON (sentry
) = 1;
2832 pushdecl_top_level (sentry
);
2833 cp_finish_decl (sentry
, NULL_TREE
, NULL_TREE
, 0, 0);
2839 /* A list of objects which have constructors or destructors
2840 which reside in the global scope. The decl is stored in
2841 the TREE_VALUE slot and the initializer is stored
2842 in the TREE_PURPOSE slot. */
2843 extern tree static_aggregates_initp
;
2845 /* Set up the static_aggregates* lists for processing. Subroutine of
2846 finish_file. Note that this function changes the format of
2847 static_aggregates_initp, from (priority . decl) to
2848 (priority . ((initializer . decl) ...)). */
2855 /* First, remove any entries from static_aggregates that are also in
2856 static_aggregates_initp, and update the entries in _initp to
2857 include the initializer. */
2858 p
= &static_aggregates
;
2861 t
= value_member (TREE_VALUE (*p
), static_aggregates_initp
);
2865 TREE_VALUE (t
) = *p
;
2866 *p
= TREE_CHAIN (*p
);
2867 TREE_CHAIN (TREE_VALUE (t
)) = NULL_TREE
;
2870 p
= &TREE_CHAIN (*p
);
2873 /* Then, group static_aggregates_initp. After this step, there will only
2874 be one entry for each priority, with a chain coming off it. */
2875 t
= static_aggregates_initp
;
2876 static_aggregates_initp
= NULL_TREE
;
2878 for (; t
; t
= next_t
)
2880 next_t
= TREE_CHAIN (t
);
2882 for (p
= &static_aggregates_initp
; ; p
= &TREE_CHAIN (*p
))
2885 || tree_int_cst_lt (TREE_PURPOSE (*p
), TREE_PURPOSE (t
)))
2887 TREE_CHAIN (t
) = *p
;
2891 else if (tree_int_cst_equal (TREE_PURPOSE (*p
), TREE_PURPOSE (t
)))
2893 TREE_CHAIN (TREE_VALUE (t
)) = TREE_VALUE (*p
);
2894 TREE_VALUE (*p
) = TREE_VALUE (t
);
2900 /* Reverse each list to preserve the order (currently reverse declaration
2901 order, for destructors). */
2902 for (t
= static_aggregates_initp
; t
; t
= TREE_CHAIN (t
))
2903 TREE_VALUE (t
) = nreverse (TREE_VALUE (t
));
2906 /* Start the process of running a particular set of global constructors
2907 or destructors. Subroutine of do_[cd]tors. */
2910 start_objects (method_type
, initp
)
2911 int method_type
, initp
;
2916 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
2918 if (initp
!= DEFAULT_INIT_PRIORITY
)
2928 sprintf (type
, "%c%c%.5u", method_type
, joiner
, initp
);
2931 sprintf (type
, "%c", method_type
);
2933 fnname
= get_file_function_name_long (type
);
2935 start_function (void_list_node
,
2936 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
2940 #if defined(ASM_OUTPUT_CONSTRUCTOR) && defined(ASM_OUTPUT_DESTRUCTOR)
2941 /* It can be a static function as long as collect2 does not have
2942 to scan the object file to find its ctor/dtor routine. */
2943 TREE_PUBLIC (current_function_decl
) = 0;
2946 store_parm_decls ();
2950 expand_start_bindings (0);
2953 /* Finish the process of running a particular set of global constructors
2954 or destructors. Subroutine of do_[cd]tors. */
2957 finish_objects (method_type
, initp
)
2958 int method_type
, initp
;
2962 if (initp
== DEFAULT_INIT_PRIORITY
)
2964 tree list
= (method_type
== 'I' ? static_ctors
: static_dtors
);
2966 if (! current_function_decl
&& list
)
2967 start_objects (method_type
, initp
);
2969 for (; list
; list
= TREE_CHAIN (list
))
2970 expand_expr_stmt (build_function_call (TREE_VALUE (list
), NULL_TREE
));
2973 if (! current_function_decl
)
2976 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
2979 expand_end_bindings (getdecls (), 1, 0);
2982 finish_function (lineno
, 0, 0);
2984 if (initp
== DEFAULT_INIT_PRIORITY
)
2986 if (method_type
== 'I')
2987 assemble_constructor (fnname
);
2989 assemble_destructor (fnname
);
2992 #ifdef ASM_OUTPUT_SECTION_NAME
2993 /* If we're using init priority we can't use assemble_*tor, but on ELF
2994 targets we can stick the references into named sections for GNU ld
2999 sprintf (buf
, ".%ctors.%.5u", method_type
== 'I' ? 'c' : 'd',
3000 /* invert the numbering so the linker puts us in the proper
3001 order; constructors are run from right to left, and the
3002 linker sorts in increasing order. */
3003 MAX_INIT_PRIORITY
- initp
);
3004 named_section (NULL_TREE
, buf
, 0);
3005 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, fnname
),
3006 POINTER_SIZE
/ BITS_PER_UNIT
, 1);
3011 /* Generate a function to run a set of global destructors. START is either
3012 NULL_TREE or a node indicating a set of destructors with the same
3013 init priority. Subroutine of finish_file. */
3024 initp
= TREE_INT_CST_LOW (TREE_PURPOSE (start
));
3025 vars
= TREE_VALUE (start
);
3029 initp
= DEFAULT_INIT_PRIORITY
;
3030 vars
= static_aggregates
;
3033 for (; vars
; vars
= TREE_CHAIN (vars
))
3035 tree decl
= TREE_VALUE (vars
);
3036 tree type
= TREE_TYPE (decl
);
3039 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
)
3040 && ! DECL_EXTERNAL (decl
))
3042 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
3043 || DECL_ONE_ONLY (decl
)
3044 || DECL_WEAK (decl
)));
3046 if (! current_function_decl
)
3047 start_objects ('D', initp
);
3049 /* Set these global variables so that GDB at least puts
3050 us near the declaration which required the initialization. */
3051 input_filename
= DECL_SOURCE_FILE (decl
);
3052 lineno
= DECL_SOURCE_LINE (decl
);
3053 emit_note (input_filename
, lineno
);
3059 Access control for implicit calls to the constructors,
3060 the conversion functions, or the destructor called to
3061 create and destroy a static data member is performed as
3062 if these calls appeared in the scope of the member's
3065 we must convince enforce_access to let us access the
3067 if (member_p (decl
))
3069 DECL_CLASS_CONTEXT (current_function_decl
)
3070 = DECL_CONTEXT (decl
);
3071 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3074 temp
= build_cleanup (decl
);
3078 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
3079 sentry
= build_unary_op (PREDECREMENT_EXPR
, sentry
, 0);
3080 sentry
= build_binary_op (EQ_EXPR
, sentry
, integer_zero_node
, 1);
3081 expand_start_cond (sentry
, 0);
3084 expand_expr_stmt (temp
);
3089 /* Now that we're done with DECL we don't need to pretend to
3090 be a member of its class any longer. */
3091 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3092 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3096 finish_objects ('D', initp
);
3099 /* Generate a function to run a set of global constructors. START is
3100 either NULL_TREE or a node indicating a set of constructors with the
3101 same init priority. Subroutine of finish_file. */
3112 initp
= TREE_INT_CST_LOW (TREE_PURPOSE (start
));
3113 vars
= TREE_VALUE (start
);
3117 initp
= DEFAULT_INIT_PRIORITY
;
3118 vars
= static_aggregates
;
3121 /* Reverse the list so it's in the right order for ctors. */
3122 vars
= nreverse (vars
);
3124 for (; vars
; vars
= TREE_CHAIN (vars
))
3126 tree decl
= TREE_VALUE (vars
);
3127 tree init
= TREE_PURPOSE (vars
);
3129 /* If this was a static attribute within some function's scope,
3130 then don't initialize it here. Also, don't bother
3131 with initializers that contain errors. */
3132 if (TREE_STATIC (vars
)
3133 || DECL_EXTERNAL (decl
)
3134 || (init
&& TREE_CODE (init
) == TREE_LIST
3135 && value_member (error_mark_node
, init
)))
3138 if (TREE_CODE (decl
) == VAR_DECL
)
3140 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
3141 || DECL_ONE_ONLY (decl
)
3142 || DECL_WEAK (decl
)));
3144 if (! current_function_decl
)
3145 start_objects ('I', initp
);
3147 /* Set these global variables so that GDB at least puts
3148 us near the declaration which required the initialization. */
3149 input_filename
= DECL_SOURCE_FILE (decl
);
3150 lineno
= DECL_SOURCE_LINE (decl
);
3151 emit_note (input_filename
, lineno
);
3153 /* 9.5p5: The initializer of a static member of a class has
3154 the same access rights as a member function. */
3155 if (member_p (decl
))
3157 DECL_CLASS_CONTEXT (current_function_decl
)
3158 = DECL_CONTEXT (decl
);
3159 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3164 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
3165 sentry
= build_unary_op (PREINCREMENT_EXPR
, sentry
, 0);
3166 sentry
= build_binary_op
3167 (EQ_EXPR
, sentry
, integer_one_node
, 1);
3168 expand_start_cond (sentry
, 0);
3171 expand_start_target_temps ();
3173 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3174 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3175 expand_aggr_init (decl
, init
, 0);
3176 else if (TREE_CODE (init
) == TREE_VEC
)
3178 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3179 TREE_VEC_ELT (init
, 1),
3180 TREE_VEC_ELT (init
, 2), 0),
3181 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3184 expand_assignment (decl
, init
, 0, 0);
3186 /* The expression might have involved increments and
3190 /* Cleanup any temporaries needed for the initial value. */
3191 expand_end_target_temps ();
3196 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3197 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3199 else if (decl
== error_mark_node
)
3202 my_friendly_abort (22);
3205 finish_objects ('I', initp
);
3208 /* This routine is called from the last rule in yyparse ().
3209 Its job is to create all the code needed to initialize and
3210 destroy the global aggregates. We do the destruction
3211 first, since that way we only need to reverse the decls once. */
3217 int start_time
, this_time
;
3221 int needs_cleaning
= 0, needs_messing_up
= 0;
3225 /* Bad parse errors. Just forget about it. */
3226 if (! global_bindings_p () || current_class_type
|| decl_namespace_list
)
3229 start_time
= get_run_time ();
3231 /* Otherwise, GDB can get confused, because in only knows
3232 about source for LINENO-1 lines. */
3235 interface_unknown
= 1;
3238 for (fnname
= pending_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
3240 tree srcloc
= TREE_PURPOSE (fnname
);
3241 tree decl
= TREE_VALUE (fnname
);
3243 input_filename
= SRCLOC_FILE (srcloc
);
3244 lineno
= SRCLOC_LINE (srcloc
);
3246 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
3248 instantiate_class_template (decl
);
3249 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl
))
3250 for (vars
= TYPE_METHODS (decl
); vars
; vars
= TREE_CHAIN (vars
))
3251 if (! DECL_ARTIFICIAL (vars
))
3252 instantiate_decl (vars
);
3255 instantiate_decl (decl
);
3258 for (fnname
= maybe_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
3260 tree args
, fn
, decl
= TREE_VALUE (fnname
);
3262 if (DECL_INITIAL (decl
))
3265 fn
= TREE_PURPOSE (fnname
);
3266 args
= get_bindings (fn
, decl
, NULL_TREE
);
3267 fn
= instantiate_template (fn
, args
);
3268 instantiate_decl (fn
);
3271 cat_namespace_levels();
3273 /* Push into C language context, because that's all
3275 push_lang_context (lang_name_c
);
3278 /* The reason for pushing garbage onto the global_binding_level is to
3279 ensure that we can slice out _DECLs which pertain to virtual function
3280 tables. If the last thing pushed onto the global_binding_level was a
3281 virtual function table, then slicing it out would slice away all the
3282 decls (i.e., we lose the head of the chain).
3284 There are several ways of getting the same effect, from changing the
3285 way that iterators over the chain treat the elements that pertain to
3286 virtual function tables, moving the implementation of this code to
3287 decl.c (where we can manipulate global_binding_level directly),
3288 popping the garbage after pushing it and slicing away the vtable
3289 stuff, or just leaving it alone. */
3291 /* Make last thing in global scope not be a virtual function table. */
3292 #if 0 /* not yet, should get fixed properly later */
3293 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
3295 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
3297 DECL_IGNORED_P (vars
) = 1;
3298 SET_DECL_ARTIFICIAL (vars
);
3302 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
3303 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars
)))
3304 rest_of_decl_compilation (TREE_VALUE (vars
), 0, 1, 1);
3305 vars
= static_aggregates
;
3307 if (static_ctors
|| vars
)
3308 needs_messing_up
= 1;
3309 if (static_dtors
|| vars
)
3314 /* After setup_initp, the aggregates are listed in reverse declaration
3315 order, for cleaning. */
3318 do_dtors (NULL_TREE
);
3320 for (vars
= static_aggregates_initp
; vars
; vars
= TREE_CHAIN (vars
))
3324 /* do_ctors will reverse the lists for messing up. */
3325 if (needs_messing_up
)
3327 do_ctors (NULL_TREE
);
3329 for (vars
= static_aggregates_initp
; vars
; vars
= TREE_CHAIN (vars
))
3333 permanent_allocation (1);
3335 /* Done with C language context needs. */
3336 pop_lang_context ();
3338 /* Now write out any static class variables (which may have since
3339 learned how to be initialized). */
3340 while (pending_statics
)
3342 tree decl
= TREE_VALUE (pending_statics
);
3344 /* Output DWARF debug information. */
3345 #ifdef DWARF_DEBUGGING_INFO
3346 if (write_symbols
== DWARF_DEBUG
)
3347 dwarfout_file_scope_decl (decl
, 1);
3349 #ifdef DWARF2_DEBUGGING_INFO
3350 if (write_symbols
== DWARF2_DEBUG
)
3351 dwarf2out_decl (decl
);
3354 DECL_DEFER_OUTPUT (decl
) = 0;
3355 rest_of_decl_compilation
3356 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3358 pending_statics
= TREE_CHAIN (pending_statics
);
3361 this_time
= get_run_time ();
3362 parse_time
-= this_time
- start_time
;
3363 varconst_time
+= this_time
- start_time
;
3365 start_time
= get_run_time ();
3367 if (flag_handle_signatures
)
3368 walk_sigtables ((void (*) PROTO ((tree
, tree
))) 0,
3369 finish_sigtable_vardecl
);
3371 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3373 tree decl
= TREE_VALUE (fnname
);
3374 import_export_decl (decl
);
3377 mark_all_runtime_matches ();
3379 /* Now write out inline functions which had their addresses taken and
3380 which were not declared virtual and which were not declared `extern
3383 int reconsider
= 1; /* More may be referenced; check again */
3387 tree
*p
= &saved_inlines
;
3390 /* We need to do this each time so that newly completed template
3391 types don't wind up at the front of the list. Sigh. */
3392 vars
= build_decl (TYPE_DECL
, make_anon_name (), integer_type_node
);
3393 DECL_IGNORED_P (vars
) = 1;
3394 SET_DECL_ARTIFICIAL (vars
);
3397 reconsider
|= walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3398 finish_vtable_vardecl
);
3402 tree decl
= TREE_VALUE (*p
);
3404 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3406 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
3408 if (DECL_MUTABLE_P (decl
))
3409 synthesize_tinfo_fn (decl
);
3411 synthesize_method (decl
);
3415 /* Catch new template instantiations. */
3416 if (decl
!= TREE_VALUE (*p
))
3419 if (TREE_ASM_WRITTEN (decl
)
3420 || (DECL_SAVED_INSNS (decl
) == 0 && ! DECL_ARTIFICIAL (decl
)))
3421 *p
= TREE_CHAIN (*p
);
3422 else if (DECL_INITIAL (decl
) == 0)
3423 p
= &TREE_CHAIN (*p
);
3424 else if ((TREE_PUBLIC (decl
) && ! DECL_COMDAT (decl
))
3425 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3426 || flag_keep_inline_functions
)
3428 if (DECL_NOT_REALLY_EXTERN (decl
))
3430 DECL_EXTERNAL (decl
) = 0;
3432 /* We can't inline this function after it's been
3433 emitted. We want a variant of
3434 output_inline_function that doesn't prevent
3435 subsequent integration... */
3436 DECL_INLINE (decl
) = 0;
3437 output_inline_function (decl
);
3438 permanent_allocation (1);
3441 *p
= TREE_CHAIN (*p
);
3444 p
= &TREE_CHAIN (*p
);
3448 /* It's possible that some of the remaining inlines will still be
3449 needed. For example, a static inline whose address is used in
3450 the initializer for a file-scope static variable will be
3451 needed. Code in compile_file will handle this, but we mustn't
3452 pretend that there are no definitions for the inlines, or it
3455 FIXME: This won't catch member functions. We should really
3456 unify this stuff with the compile_file stuff. */
3457 for (vars
= saved_inlines
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
3459 tree decl
= TREE_VALUE (vars
);
3461 if (DECL_NOT_REALLY_EXTERN (decl
)
3462 && !DECL_COMDAT (decl
)
3463 && DECL_INITIAL (decl
) != NULL_TREE
)
3464 DECL_EXTERNAL (decl
) = 0;
3468 /* Now delete from the chain of variables all virtual function tables.
3469 We output them all ourselves, because each will be treated specially. */
3471 walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3472 prune_vtable_vardecl
);
3476 this_time
= get_run_time ();
3477 parse_time
-= this_time
- start_time
;
3478 varconst_time
+= this_time
- start_time
;
3480 if (flag_detailed_statistics
)
3482 dump_tree_statistics ();
3483 dump_time_statistics ();
3487 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3488 expr. Since it was parsed like a type, we need to wade through and fix
3489 that. Unfortunately, since operator() is left-associative, we can't use
3490 tail recursion. In the above example, TYPE is `A', and DECL is
3493 Maybe this shouldn't be recursive, but how often will it actually be
3497 reparse_absdcl_as_expr (type
, decl
)
3500 /* do build_functional_cast (type, NULL_TREE) at bottom */
3501 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3502 return build_functional_cast (type
, NULL_TREE
);
3505 decl
= reparse_absdcl_as_expr (type
, TREE_OPERAND (decl
, 0));
3507 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_ref
);
3509 if (TREE_CODE (decl
) == CALL_EXPR
3510 && (! TREE_TYPE (decl
)
3511 || TREE_CODE (TREE_TYPE (decl
)) != VOID_TYPE
))
3512 decl
= require_complete_type (decl
);
3517 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3518 out to be an expr. Since it was parsed like a type, we need to wade
3519 through and fix that. Since casts are right-associative, we are
3520 reversing the order, so we don't have to recurse.
3522 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3526 reparse_absdcl_as_casts (decl
, expr
)
3531 if (TREE_CODE (expr
) == CONSTRUCTOR
3532 && TREE_TYPE (expr
) == 0)
3534 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3535 decl
= TREE_OPERAND (decl
, 0);
3537 if (IS_SIGNATURE (type
))
3539 error ("cast specifies signature type");
3540 return error_mark_node
;
3543 expr
= digest_init (type
, expr
, (tree
*) 0);
3544 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3546 int failure
= complete_array_type (type
, expr
, 1);
3548 my_friendly_abort (78);
3554 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3555 decl
= TREE_OPERAND (decl
, 0);
3556 expr
= build_c_cast (type
, expr
);
3559 if (warn_old_style_cast
)
3560 warning ("use of old-style cast");
3565 /* Given plain tree nodes for an expression, build up the full semantics. */
3568 build_expr_from_tree (t
)
3571 if (t
== NULL_TREE
|| t
== error_mark_node
)
3574 switch (TREE_CODE (t
))
3576 case IDENTIFIER_NODE
:
3577 return do_identifier (t
, 0, NULL_TREE
);
3580 if (LOOKUP_EXPR_GLOBAL (t
))
3581 return do_scoped_id (TREE_OPERAND (t
, 0), 0);
3583 return do_identifier (TREE_OPERAND (t
, 0), 0, NULL_TREE
);
3585 case TEMPLATE_ID_EXPR
:
3586 return (lookup_template_function
3587 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3588 build_expr_from_tree (TREE_OPERAND (t
, 1))));
3591 return build_x_indirect_ref
3592 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3595 return build_functional_cast
3596 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3598 case REINTERPRET_CAST_EXPR
:
3599 return build_reinterpret_cast
3600 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3602 case CONST_CAST_EXPR
:
3603 return build_const_cast
3604 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3606 case DYNAMIC_CAST_EXPR
:
3607 return build_dynamic_cast
3608 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3610 case STATIC_CAST_EXPR
:
3611 return build_static_cast
3612 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3614 case PREDECREMENT_EXPR
:
3615 case PREINCREMENT_EXPR
:
3616 case POSTDECREMENT_EXPR
:
3617 case POSTINCREMENT_EXPR
:
3621 case TRUTH_NOT_EXPR
:
3623 case CONVERT_EXPR
: /* Unary + */
3626 return build_x_unary_op (TREE_CODE (t
),
3627 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3632 case TRUNC_DIV_EXPR
:
3634 case FLOOR_DIV_EXPR
:
3635 case ROUND_DIV_EXPR
:
3636 case EXACT_DIV_EXPR
:
3638 case BIT_ANDTC_EXPR
:
3641 case TRUNC_MOD_EXPR
:
3642 case FLOOR_MOD_EXPR
:
3643 case TRUTH_ANDIF_EXPR
:
3644 case TRUTH_ORIF_EXPR
:
3645 case TRUTH_AND_EXPR
:
3660 return build_x_binary_op
3662 build_expr_from_tree (TREE_OPERAND (t
, 0)),
3663 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3666 return build_m_component_ref
3667 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3668 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3671 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
3674 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
3676 return build_parse_node (ARRAY_REF
, NULL_TREE
,
3677 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3678 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3679 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3684 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3685 if (TREE_CODE_CLASS (TREE_CODE (r
)) != 't')
3687 return TREE_CODE (t
) == SIZEOF_EXPR
? c_sizeof (r
) : c_alignof (r
);
3691 return build_x_modify_expr
3692 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3693 TREE_CODE (TREE_OPERAND (t
, 1)),
3694 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3697 return build_x_arrow
3698 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3702 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3703 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3704 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3705 NEW_EXPR_USE_GLOBAL (t
));
3708 return delete_sanity
3709 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3710 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3711 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
3714 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
3715 return build_x_compound_expr
3716 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3718 my_friendly_abort (42);
3720 case METHOD_CALL_EXPR
:
3721 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3723 tree ref
= TREE_OPERAND (t
, 0);
3724 return build_scoped_method_call
3725 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3726 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3727 TREE_OPERAND (ref
, 1),
3728 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3732 tree fn
= TREE_OPERAND (t
, 0);
3734 /* We can get a TEMPLATE_ID_EXPR here on code like:
3738 so we must resolve that. However, we can also get things
3739 like a BIT_NOT_EXPR here, when referring to a destructor,
3740 and things like that are not correctly resolved by
3741 build_expr_from_tree. So, just use build_expr_from_tree
3742 when we really need it. */
3743 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
3744 fn
= build_expr_from_tree (fn
);
3746 return build_method_call
3747 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3749 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3750 NULL_TREE
, LOOKUP_NORMAL
);
3754 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3756 tree ref
= TREE_OPERAND (t
, 0);
3757 return build_member_call
3758 (build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3759 TREE_OPERAND (ref
, 1),
3760 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3764 tree name
= TREE_OPERAND (t
, 0);
3766 tree args
= build_expr_from_tree (TREE_OPERAND (t
, 1));
3767 if (args
!= NULL_TREE
&& TREE_CODE (name
) == LOOKUP_EXPR
3768 && !LOOKUP_EXPR_GLOBAL (name
)
3769 && TREE_CODE ((id
= TREE_OPERAND (name
, 0))) == IDENTIFIER_NODE
3770 && (!current_class_type
3771 || !lookup_member (current_class_type
, id
, 0, 0)))
3773 /* Do Koenig lookup if there are no class members. */
3774 name
= do_identifier (id
, 0, args
);
3776 else if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
3777 || ! really_overloaded_fn (name
))
3778 name
= build_expr_from_tree (name
);
3779 return build_x_function_call (name
, args
, current_class_ref
);
3783 return build_x_conditional_expr
3784 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3785 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3786 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3790 tree purpose
, value
, chain
;
3792 if (t
== void_list_node
)
3795 purpose
= TREE_PURPOSE (t
);
3797 purpose
= build_expr_from_tree (purpose
);
3798 value
= TREE_VALUE (t
);
3800 value
= build_expr_from_tree (value
);
3801 chain
= TREE_CHAIN (t
);
3802 if (chain
&& chain
!= void_type_node
)
3803 chain
= build_expr_from_tree (chain
);
3804 return expr_tree_cons (purpose
, value
, chain
);
3808 return build_x_component_ref
3809 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3810 TREE_OPERAND (t
, 1), NULL_TREE
, 1);
3813 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3819 /* digest_init will do the wrong thing if we let it. */
3820 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
3823 r
= build_nt (CONSTRUCTOR
, NULL_TREE
,
3824 build_expr_from_tree (CONSTRUCTOR_ELTS (t
)));
3825 TREE_HAS_CONSTRUCTOR (r
) = TREE_HAS_CONSTRUCTOR (t
);
3828 return digest_init (TREE_TYPE (t
), r
, 0);
3833 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
3834 return get_typeid (TREE_OPERAND (t
, 0));
3835 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3838 return convert_from_reference (t
);
3845 /* This is something of the form `int (*a)++' that has turned out to be an
3846 expr. It was only converted into parse nodes, so we need to go through
3847 and build up the semantics. Most of the work is done by
3848 build_expr_from_tree, above.
3850 In the above example, TYPE is `int' and DECL is `*a'. */
3853 reparse_decl_as_expr (type
, decl
)
3856 decl
= build_expr_from_tree (decl
);
3858 return build_functional_cast (type
, build_expr_list (NULL_TREE
, decl
));
3863 /* This is something of the form `int (*a)' that has turned out to be a
3864 decl. It was only converted into parse nodes, so we need to do the
3865 checking that make_{pointer,reference}_declarator do. */
3868 finish_decl_parsing (decl
)
3871 extern int current_class_depth
;
3873 switch (TREE_CODE (decl
))
3875 case IDENTIFIER_NODE
:
3878 return make_pointer_declarator
3879 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3881 return make_reference_declarator
3882 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3884 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3887 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3888 TREE_COMPLEXITY (decl
) = current_class_depth
;
3891 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3894 /* For attribute handling. */
3895 TREE_VALUE (decl
) = finish_decl_parsing (TREE_VALUE (decl
));
3898 my_friendly_abort (5);
3904 check_cp_case_value (value
)
3907 if (value
== NULL_TREE
)
3910 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3911 STRIP_TYPE_NOPS (value
);
3913 if (TREE_READONLY_DECL_P (value
))
3915 value
= decl_constant_value (value
);
3916 STRIP_TYPE_NOPS (value
);
3918 value
= fold (value
);
3920 if (TREE_CODE (value
) != INTEGER_CST
3921 && value
!= error_mark_node
)
3923 cp_error ("case label `%E' does not reduce to an integer constant",
3925 value
= error_mark_node
;
3928 /* Promote char or short to int. */
3929 value
= default_conversion (value
);
3931 constant_expression_warning (value
);
3936 /* Return 1 if root encloses child. */
3939 is_namespace_ancestor (root
, child
)
3944 if (root
== global_namespace
)
3946 if (child
== global_namespace
)
3948 return is_namespace_ancestor (root
, CP_DECL_CONTEXT (child
));
3952 /* Return the namespace that is the common ancestor
3953 of two given namespaces. */
3956 namespace_ancestor (ns1
, ns2
)
3959 if (is_namespace_ancestor (ns1
, ns2
))
3961 return namespace_ancestor (CP_DECL_CONTEXT (ns1
), ns2
);
3964 /* Insert used into the using list of user. Set indirect_flag if this
3965 directive is not directly from the source. Also find the common
3966 ancestor and let our users know about the new namespace */
3968 add_using_namespace (user
, used
, indirect
)
3974 /* Using oneself is a no-op. */
3977 my_friendly_assert (TREE_CODE (user
) == NAMESPACE_DECL
, 380);
3978 my_friendly_assert (TREE_CODE (used
) == NAMESPACE_DECL
, 380);
3979 /* Check if we already have this. */
3980 t
= purpose_member (used
, DECL_NAMESPACE_USING (user
));
3984 /* Promote to direct usage. */
3985 TREE_INDIRECT_USING (t
) = 0;
3989 /* Add used to the user's using list. */
3990 DECL_NAMESPACE_USING (user
)
3991 = perm_tree_cons (used
, namespace_ancestor (user
, used
),
3992 DECL_NAMESPACE_USING (user
));
3994 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user
)) = indirect
;
3996 /* Add user to the used's users list. */
3997 DECL_NAMESPACE_USERS (used
)
3998 = perm_tree_cons (user
, 0, DECL_NAMESPACE_USERS (used
));
4000 /* Recursively add all namespaces used. */
4001 for (t
= DECL_NAMESPACE_USING (used
); t
; t
= TREE_CHAIN (t
))
4002 /* indirect usage */
4003 add_using_namespace (user
, TREE_PURPOSE (t
), 1);
4005 /* Tell everyone using us about the new used namespaces. */
4006 for (t
= DECL_NAMESPACE_USERS (user
); t
; t
= TREE_CHAIN (t
))
4007 add_using_namespace (TREE_PURPOSE (t
), used
, 1);
4010 /* Combines two sets of overloaded functions into an OVERLOAD chain, removing
4011 duplicates. The first list becomes the tail of the result.
4013 The algorithm is O(n^2). We could get this down to O(n log n) by
4014 doing a sort on the addresses of the functions, if that becomes
4018 merge_functions (s1
, s2
)
4022 for (; s2
; s2
= OVL_NEXT (s2
))
4024 tree fn
= OVL_CURRENT (s2
);
4025 if (! ovl_member (fn
, s1
))
4026 s1
= build_overload (fn
, s1
);
4031 /* This should return an error not all definitions define functions.
4032 It is not an error if we find two functions with exactly the
4033 same signature, only if these are selected in overload resolution.
4034 old is the current set of bindings, new the freshly-found binding.
4035 XXX Do we want to give *all* candidates in case of ambiguity?
4036 XXX In what way should I treat extern declarations?
4037 XXX I don't want to repeat the entire duplicate_decls here */
4040 ambiguous_decl (name
, old
, new, flags
)
4047 my_friendly_assert (old
!= NULL_TREE
, 393);
4048 /* Copy the value. */
4049 val
= BINDING_VALUE (new);
4051 switch (TREE_CODE (val
))
4054 /* If we expect types or namespaces, and not templates,
4055 or this is not a template class. */
4056 if (LOOKUP_QUALIFIERS_ONLY (flags
)
4057 && (!(flags
& LOOKUP_TEMPLATES_EXPECTED
)
4058 || !DECL_CLASS_TEMPLATE_P (val
)))
4062 if (LOOKUP_NAMESPACES_ONLY (flags
))
4065 case NAMESPACE_DECL
:
4066 if (LOOKUP_TYPES_ONLY (flags
))
4070 if (LOOKUP_QUALIFIERS_ONLY (flags
))
4074 if (!BINDING_VALUE (old
))
4075 BINDING_VALUE (old
) = val
;
4076 else if (val
&& val
!= BINDING_VALUE (old
))
4078 if (is_overloaded_fn (BINDING_VALUE (old
))
4079 && is_overloaded_fn (val
))
4081 BINDING_VALUE (old
) = merge_functions (BINDING_VALUE (old
),
4086 /* Some declarations are functions, some are not. */
4087 if (flags
& LOOKUP_COMPLAIN
)
4089 /* If we've already given this error for this lookup,
4090 BINDING_VALUE (old) is error_mark_node, so let's not
4091 repeat ourselves. */
4092 if (BINDING_VALUE (old
) != error_mark_node
)
4094 cp_error ("use of `%D' is ambiguous", name
);
4095 cp_error_at (" first declared as `%#D' here",
4096 BINDING_VALUE (old
));
4098 cp_error_at (" also declared as `%#D' here", val
);
4100 return error_mark_node
;
4103 /* ... and copy the type. */
4104 type
= BINDING_TYPE (new);
4105 if (LOOKUP_NAMESPACES_ONLY (flags
))
4107 if (!BINDING_TYPE (old
))
4108 BINDING_TYPE (old
) = type
;
4109 else if (type
&& BINDING_TYPE (old
) != type
)
4111 if (flags
& LOOKUP_COMPLAIN
)
4113 cp_error ("`%D' denotes an ambiguous type",name
);
4114 cp_error_at (" first type here", BINDING_TYPE (old
));
4115 cp_error_at (" other type here", type
);
4121 /* Add the bindings of name in used namespaces to val.
4122 The using list is defined by usings, and the lookup goes to scope.
4123 Returns zero on errors. */
4126 lookup_using_namespace (name
, val
, usings
, scope
, flags
)
4127 tree name
, val
, usings
, scope
;
4132 /* Iterate over all used namespaces in current, searching for using
4133 directives of scope. */
4134 for (iter
= usings
; iter
; iter
= TREE_CHAIN (iter
))
4135 if (TREE_VALUE (iter
) == scope
)
4137 val1
= binding_for_name (name
, TREE_PURPOSE (iter
));
4138 /* Resolve ambiguities. */
4139 val
= ambiguous_decl (name
, val
, val1
, flags
);
4141 return val
!= error_mark_node
;
4145 Excepts the name to lookup and its qualifying scope.
4146 Returns the name/type pair found into the CPLUS_BINDING result,
4150 qualified_lookup_using_namespace (name
, scope
, result
, flags
)
4156 /* Maintain a list of namespaces visited... */
4157 tree seen
= NULL_TREE
;
4158 /* ... and a list of namespace yet to see. */
4159 tree todo
= NULL_TREE
;
4161 while (scope
&& (result
!= error_mark_node
))
4163 seen
= temp_tree_cons (scope
, NULL_TREE
, seen
);
4164 result
= ambiguous_decl (name
, result
,
4165 binding_for_name (name
, scope
), flags
);
4166 if (!BINDING_VALUE (result
) && !BINDING_TYPE (result
))
4167 /* Consider using directives. */
4168 for (usings
= DECL_NAMESPACE_USING (scope
); usings
;
4169 usings
= TREE_CHAIN (usings
))
4170 /* If this was a real directive, and we have not seen it. */
4171 if (!TREE_INDIRECT_USING (usings
)
4172 && !purpose_member (TREE_PURPOSE (usings
), seen
))
4173 todo
= temp_tree_cons (TREE_PURPOSE (usings
), NULL_TREE
, todo
);
4176 scope
= TREE_PURPOSE (todo
);
4177 todo
= TREE_CHAIN (todo
);
4180 scope
= NULL_TREE
; /* If there never was a todo list. */
4182 return result
!= error_mark_node
;
4185 /* [namespace.memdef]/2 */
4187 /* Set the context of a declaration to scope. Complain if we are not
4191 set_decl_namespace (decl
, scope
, friendp
)
4197 if (scope
== std_node
)
4198 scope
= global_namespace
;
4199 /* Get rid of namespace aliases. */
4200 scope
= ORIGINAL_NAMESPACE (scope
);
4202 /* It is ok for friends to be qualified in parallel space. */
4203 if (!friendp
&& !is_namespace_ancestor (current_namespace
, scope
))
4204 cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
4206 DECL_CONTEXT (decl
) = FROB_CONTEXT (scope
);
4207 if (scope
!= current_namespace
)
4209 /* See whether this has been declared in the namespace. */
4210 old
= namespace_binding (DECL_NAME (decl
), scope
);
4212 /* No old declaration at all. */
4214 if (!is_overloaded_fn (decl
))
4215 /* Don't compare non-function decls with decls_match here,
4216 since it can't check for the correct constness at this
4217 point. pushdecl will find those errors later. */
4219 /* Since decl is a function, old should contain a function decl. */
4220 if (!is_overloaded_fn (old
))
4222 for (; old
; old
= OVL_NEXT (old
))
4223 if (decls_match (decl
, OVL_CURRENT (old
)))
4229 cp_error ("`%D' should have been declared inside `%D'",
4233 /* Compute the namespace where a declaration is defined. */
4236 decl_namespace (decl
)
4239 while (DECL_CONTEXT (decl
))
4241 decl
= DECL_CONTEXT (decl
);
4242 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
4244 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
4245 decl
= TYPE_STUB_DECL (decl
);
4246 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd', 390);
4249 return global_namespace
;
4252 /* Return the namespace where the current declaration is declared. */
4255 current_decl_namespace ()
4258 /* If we have been pushed into a different namespace, use it. */
4259 if (decl_namespace_list
)
4260 return TREE_PURPOSE (decl_namespace_list
);
4262 if (current_class_type
)
4263 result
= decl_namespace (TYPE_STUB_DECL (current_class_type
));
4264 else if (current_function_decl
)
4265 result
= decl_namespace (current_function_decl
);
4267 result
= current_namespace
;
4271 /* Temporarily set the namespace for the current declaration. */
4274 push_decl_namespace (decl
)
4277 if (TREE_CODE (decl
) != NAMESPACE_DECL
)
4278 decl
= decl_namespace (decl
);
4279 decl_namespace_list
= tree_cons (decl
, NULL_TREE
, decl_namespace_list
);
4283 pop_decl_namespace ()
4285 decl_namespace_list
= TREE_CHAIN (decl_namespace_list
);
4288 /* Enter a class or namespace scope. */
4294 if (TREE_CODE (t
) == NAMESPACE_DECL
)
4295 push_decl_namespace (t
);
4300 /* Leave scope pushed by push_scope. */
4306 if (TREE_CODE (t
) == NAMESPACE_DECL
)
4307 pop_decl_namespace ();
4312 /* [basic.lookup.koenig] */
4313 /* A non-zero return value in the functions below indicates an error.
4314 All nodes allocated in the procedure are on the scratch obstack. */
4324 static int arg_assoc
PROTO((struct arg_lookup
*, tree
));
4325 static int arg_assoc_args
PROTO((struct arg_lookup
*, tree
));
4326 static int arg_assoc_type
PROTO((struct arg_lookup
*, tree
));
4328 /* Add a function to the lookup structure.
4329 Returns 1 on error. */
4332 add_function (k
, fn
)
4333 struct arg_lookup
*k
;
4336 if (ovl_member (fn
, k
->functions
))
4338 /* We must find only functions, or exactly one non-function. */
4339 if (k
->functions
&& is_overloaded_fn (k
->functions
)
4340 && is_overloaded_fn (fn
))
4341 k
->functions
= build_overload (fn
, k
->functions
);
4345 tree f1
= OVL_CURRENT (k
->functions
);
4347 if (is_overloaded_fn (f1
))
4349 fn
= f1
; f1
= f2
; f2
= fn
;
4351 cp_error_at ("`%D' is not a function,", f1
);
4352 cp_error_at (" conflict with `%D'", f2
);
4353 cp_error (" in call to `%D'", k
->name
);
4361 /* Add functions of a namespace to the lookup structure.
4362 Returns 1 on error. */
4365 arg_assoc_namespace (k
, scope
)
4366 struct arg_lookup
*k
;
4371 if (purpose_member (scope
, k
->namespaces
))
4373 k
->namespaces
= tree_cons (scope
, NULL_TREE
, k
->namespaces
);
4375 value
= namespace_binding (k
->name
, scope
);
4379 for (; value
; value
= OVL_NEXT (value
))
4380 if (add_function (k
, OVL_CURRENT (value
)))
4386 /* Adds everything associated with class to the lookup structure.
4387 Returns 1 on error. */
4390 arg_assoc_class (k
, type
)
4391 struct arg_lookup
* k
;
4394 tree list
, friends
, context
;
4397 if (purpose_member (type
, k
->classes
))
4399 k
->classes
= tree_cons (type
, NULL_TREE
, k
->classes
);
4401 context
= decl_namespace (TYPE_MAIN_DECL (type
));
4402 if (arg_assoc_namespace (k
, context
))
4405 /* Process baseclasses. */
4406 for (i
= 0; i
< CLASSTYPE_N_BASECLASSES (type
); i
++)
4407 if (arg_assoc_class (k
, TYPE_BINFO_BASETYPE (type
, i
)))
4410 /* Process friends. */
4411 for (list
= DECL_FRIENDLIST (TYPE_MAIN_DECL (type
)); list
;
4412 list
= TREE_CHAIN (list
))
4413 if (k
->name
== TREE_PURPOSE (list
))
4414 for (friends
= TREE_VALUE (list
); friends
;
4415 friends
= TREE_CHAIN (friends
))
4416 /* Only interested in global functions with potentially hidden
4417 (i.e. unqualified) declarations. */
4418 if (TREE_PURPOSE (list
) == error_mark_node
&& TREE_VALUE (list
)
4419 && decl_namespace (TREE_VALUE (list
)) == context
)
4420 if (add_function (k
, TREE_VALUE (list
)))
4423 /* Process template arguments. */
4424 if (CLASSTYPE_TEMPLATE_INFO (type
))
4426 list
= innermost_args (CLASSTYPE_TI_ARGS (type
));
4427 for (i
= 0; i
< TREE_VEC_LENGTH (list
); ++i
)
4428 arg_assoc (k
, TREE_VEC_ELT (list
, i
));
4434 /* Adds everything associated with a given type.
4435 Returns 1 on error. */
4438 arg_assoc_type (k
, type
)
4439 struct arg_lookup
*k
;
4442 switch (TREE_CODE (type
))
4452 if (TYPE_PTRMEMFUNC_P (type
))
4453 return arg_assoc_type (k
, TYPE_PTRMEMFUNC_FN_TYPE (type
));
4454 return arg_assoc_class (k
, type
);
4456 case REFERENCE_TYPE
:
4458 return arg_assoc_type (k
, TREE_TYPE (type
));
4461 return arg_assoc_namespace (k
, decl_namespace (TYPE_MAIN_DECL (type
)));
4463 /* Pointer to member: associate class type and value type. */
4464 if (arg_assoc_type (k
, TYPE_OFFSET_BASETYPE (type
)))
4466 return arg_assoc_type (k
, TREE_TYPE (type
));
4468 /* The basetype is referenced in the first arg type, so just
4471 /* Associate the parameter types. */
4472 if (arg_assoc_args (k
, TYPE_ARG_TYPES (type
)))
4474 /* Associate the return type. */
4475 return arg_assoc_type (k
, TREE_TYPE (type
));
4476 case TEMPLATE_TYPE_PARM
:
4477 case TEMPLATE_TEMPLATE_PARM
:
4480 if (type
== unknown_type_node
)
4482 /* else fall through */
4484 my_friendly_abort (390);
4489 /* Adds everything associated with arguments. Returns 1 on error. */
4492 arg_assoc_args (k
, args
)
4493 struct arg_lookup
* k
;
4496 for (; args
; args
= TREE_CHAIN (args
))
4497 if (arg_assoc (k
, TREE_VALUE (args
)))
4502 /* Adds everything associated with a given tree_node. Returns 1 on error. */
4506 struct arg_lookup
* k
;
4509 if (n
== error_mark_node
)
4512 if (TREE_CODE_CLASS (TREE_CODE (n
)) == 't')
4513 return arg_assoc_type (k
, n
);
4515 if (! type_unknown_p (n
))
4516 return arg_assoc_type (k
, TREE_TYPE (n
));
4518 if (TREE_CODE (n
) == ADDR_EXPR
)
4519 n
= TREE_OPERAND (n
, 0);
4520 if (TREE_CODE (n
) == COMPONENT_REF
)
4521 n
= TREE_OPERAND (n
, 1);
4522 while (TREE_CODE (n
) == TREE_LIST
)
4525 if (TREE_CODE (n
) == FUNCTION_DECL
)
4526 return arg_assoc_type (k
, TREE_TYPE (n
));
4527 if (TREE_CODE (n
) == TEMPLATE_ID_EXPR
)
4529 /* [basic.lookup.koenig]
4531 If T is a template-id, its associated namespaces and classes
4532 are the namespace in which the template is defined; for
4533 member templates, the member template's class; the namespaces
4534 and classes associated with the types of the template
4535 arguments provided for template type parameters (excluding
4536 template template parameters); the namespaces in which any
4537 template template arguments are defined; and the classes in
4538 which any member templates used as template template
4539 arguments are defined. [Note: non-type template arguments do
4540 not contribute to the set of associated namespaces. ] */
4541 tree
template = TREE_OPERAND (n
, 0);
4542 tree args
= TREE_OPERAND (n
, 1);
4546 /* First, the template. There may actually be more than one if
4547 this is an overloaded function template. But, in that case,
4548 we only need the first; all the functions will be in the same
4550 template = OVL_CURRENT (template);
4552 ctx
= CP_DECL_CONTEXT (template);
4554 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
4556 if (arg_assoc_namespace (k
, ctx
) == 1)
4559 /* It must be a member template. */
4560 else if (arg_assoc_class (k
, ctx
) == 1)
4563 /* Now the arguments. */
4564 for (arg
= args
; arg
!= NULL_TREE
; arg
= TREE_CHAIN (arg
))
4566 tree t
= TREE_VALUE (arg
);
4568 if (TREE_CODE (t
) == TEMPLATE_DECL
)
4570 ctx
= CP_DECL_CONTEXT (t
);
4571 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
4573 if (arg_assoc_namespace (k
, ctx
) == 1)
4576 else if (arg_assoc_class (k
, ctx
) == 1)
4579 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't'
4580 && arg_assoc_type (k
, t
) == 1)
4586 my_friendly_assert (TREE_CODE (n
) == OVERLOAD
, 980715);
4588 for (; n
; n
= OVL_CHAIN (n
))
4589 if (arg_assoc_type (k
, TREE_TYPE (OVL_FUNCTION (n
))))
4596 /* Performs Koenig lookup depending on arguments, where fns
4597 are the functions found in normal lookup. */
4600 lookup_arg_dependent (name
, fns
, args
)
4605 struct arg_lookup k
;
4608 k
.namespaces
= NULL_TREE
;
4609 k
.classes
= NULL_TREE
;
4611 push_scratch_obstack ();
4612 arg_assoc_args (&k
, args
);
4617 /* Process a namespace-alias declaration. */
4620 do_namespace_alias (alias
, namespace)
4621 tree alias
, namespace;
4623 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4625 /* The parser did not find it, so it's not there. */
4626 cp_error ("unknown namespace `%D'", namespace);
4630 namespace = ORIGINAL_NAMESPACE (namespace);
4632 /* Build the alias. */
4633 alias
= build_lang_decl (NAMESPACE_DECL
, alias
, void_type_node
);
4634 DECL_NAMESPACE_ALIAS (alias
) = namespace;
4638 /* Check a non-member using-declaration. Return the name and scope
4639 being used, and the USING_DECL, or NULL_TREE on failure. */
4642 validate_nonmember_using_decl (decl
, scope
, name
)
4647 if (TREE_CODE (decl
) == SCOPE_REF
4648 && TREE_OPERAND (decl
, 0) == std_node
)
4650 if (namespace_bindings_p ()
4651 && current_namespace
== global_namespace
)
4652 /* There's no need for a using declaration at all, here,
4653 since `std' is the same as `::'. We can't just pass this
4654 on because we'll complain later about declaring something
4655 in the same scope as a using declaration with the same
4656 name. We return NULL_TREE which indicates to the caller
4657 that there's no need to do any further processing. */
4660 *scope
= global_namespace
;
4661 *name
= TREE_OPERAND (decl
, 1);
4663 else if (TREE_CODE (decl
) == SCOPE_REF
)
4665 *scope
= TREE_OPERAND (decl
, 0);
4666 *name
= TREE_OPERAND (decl
, 1);
4668 /* [namespace.udecl]
4670 A using-declaration for a class member shall be a
4671 member-declaration. */
4672 if (TREE_CODE (*scope
) != NAMESPACE_DECL
)
4674 cp_error ("`%D' is not a namespace", *scope
);
4678 else if (TREE_CODE (decl
) == IDENTIFIER_NODE
4679 || TREE_CODE (decl
) == TYPE_DECL
4680 || TREE_CODE (decl
) == TEMPLATE_DECL
)
4682 *scope
= global_namespace
;
4686 my_friendly_abort (382);
4687 if (TREE_CODE_CLASS (TREE_CODE (*name
)) == 'd')
4688 *name
= DECL_NAME (*name
);
4689 /* Make a USING_DECL. */
4690 return push_using_decl (*scope
, *name
);
4693 /* Process local and global using-declarations. */
4696 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, newval
, newtype
)
4698 tree oldval
, oldtype
;
4699 tree
*newval
, *newtype
;
4702 struct tree_binding _decls
;
4704 *newval
= *newtype
= NULL_TREE
;
4705 decls
= binding_init (&_decls
);
4706 if (!qualified_lookup_using_namespace (name
, scope
, decls
, 0))
4710 if (!BINDING_VALUE (decls
) && !BINDING_TYPE (decls
))
4712 cp_error ("`%D' not declared", name
);
4716 /* Check for using functions. */
4717 if (BINDING_VALUE (decls
) && is_overloaded_fn (BINDING_VALUE (decls
)))
4721 if (oldval
&& !is_overloaded_fn (oldval
))
4723 duplicate_decls (OVL_CURRENT (BINDING_VALUE (decls
)), oldval
);
4728 for (tmp
= BINDING_VALUE (decls
); tmp
; tmp
= OVL_NEXT (tmp
))
4730 tree new_fn
= OVL_CURRENT (tmp
);
4732 /* [namespace.udecl]
4734 If a function declaration in namespace scope or block
4735 scope has the same name and the same parameter types as a
4736 function introduced by a using declaration the program is
4738 for (tmp1
= oldval
; tmp1
; tmp1
= OVL_NEXT (tmp1
))
4740 tree old_fn
= OVL_CURRENT (tmp1
);
4742 if (!OVL_USED (tmp1
)
4743 && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn
)),
4744 TYPE_ARG_TYPES (TREE_TYPE (old_fn
))))
4746 /* There was already a non-using declaration in
4747 this scope with the same parameter types. */
4748 cp_error ("`%D' is already declared in this scope",
4752 else if (duplicate_decls (new_fn
, old_fn
))
4753 /* We're re-using something we already used
4754 before. We don't need to add it again. */
4758 /* If we broke out of the loop, there's no reason to add
4759 this function to the using declarations for this
4764 *newval
= build_overload (OVL_CURRENT (tmp
), *newval
);
4765 if (TREE_CODE (*newval
) != OVERLOAD
)
4766 *newval
= ovl_cons (*newval
, NULL_TREE
);
4767 OVL_USED (*newval
) = 1;
4772 *newval
= BINDING_VALUE (decls
);
4774 duplicate_decls (*newval
, oldval
);
4777 *newtype
= BINDING_TYPE (decls
);
4778 if (oldtype
&& *newtype
&& oldtype
!= *newtype
)
4780 cp_error ("using directive `%D' introduced ambiguous type `%T'",
4786 /* Process a using-declaration not appearing in class or local scope. */
4789 do_toplevel_using_decl (decl
)
4792 tree scope
, name
, binding
;
4793 tree oldval
, oldtype
, newval
, newtype
;
4795 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
4796 if (decl
== NULL_TREE
)
4799 binding
= binding_for_name (name
, current_namespace
);
4801 oldval
= BINDING_VALUE (binding
);
4802 oldtype
= BINDING_TYPE (binding
);
4804 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
4806 /* Copy declarations found. */
4808 BINDING_VALUE (binding
) = newval
;
4810 BINDING_TYPE (binding
) = newtype
;
4814 /* Process a using-declaration at function scope. */
4817 do_local_using_decl (decl
)
4821 tree oldval
, oldtype
, newval
, newtype
;
4823 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
4824 if (decl
== NULL_TREE
)
4827 oldval
= lookup_name_current_level (name
);
4828 oldtype
= lookup_type_current_level (name
);
4830 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
4834 if (is_overloaded_fn (newval
))
4838 /* We only need to push declarations for those functions
4839 that were not already bound in the current level.
4840 The old value might be NULL_TREE, it might be a single
4841 function, or an OVERLOAD. */
4842 if (oldval
&& TREE_CODE (oldval
) == OVERLOAD
)
4843 term
= OVL_FUNCTION (oldval
);
4846 for (fn
= newval
; fn
&& OVL_CURRENT (fn
) != term
;
4848 push_overloaded_decl (OVL_CURRENT (fn
),
4849 PUSH_LOCAL
| PUSH_USING
);
4852 push_local_binding (name
, newval
, PUSH_USING
);
4855 set_identifier_type_value (name
, newtype
);
4859 do_class_using_decl (decl
)
4864 if (TREE_CODE (decl
) != SCOPE_REF
4865 || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (decl
, 0))) != 't')
4867 cp_error ("using-declaration for non-member at class scope");
4870 name
= TREE_OPERAND (decl
, 1);
4871 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
4873 cp_error ("using-declaration for destructor");
4876 if (TREE_CODE (name
) == TYPE_DECL
)
4877 name
= DECL_NAME (name
);
4879 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 980716);
4881 value
= build_lang_field_decl (USING_DECL
, name
, void_type_node
);
4882 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
4886 /* Process a using-directive. */
4889 do_using_directive (namespace)
4892 if (namespace == std_node
)
4894 /* using namespace A::B::C; */
4895 if (TREE_CODE (namespace) == SCOPE_REF
)
4896 namespace = TREE_OPERAND (namespace, 1);
4897 if (TREE_CODE (namespace) == IDENTIFIER_NODE
)
4899 /* Lookup in lexer did not find a namespace. */
4900 cp_error ("namespace `%T' undeclared", namespace);
4903 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4905 cp_error ("`%T' is not a namespace", namespace);
4908 namespace = ORIGINAL_NAMESPACE (namespace);
4909 if (!toplevel_bindings_p ())
4910 push_using_directive (namespace);
4913 add_using_namespace (current_namespace
, namespace, 0);
4917 check_default_args (x
)
4920 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
4921 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
4922 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
4924 if (TREE_PURPOSE (arg
))
4928 cp_error_at ("default argument missing for parameter %P of `%+#D'",
4939 TREE_USED (decl
) = 1;
4940 if (processing_template_decl
)
4942 assemble_external (decl
);
4944 /* Is it a synthesized method that needs to be synthesized? */
4945 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CLASS_CONTEXT (decl
)
4946 && DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
4947 /* Kludge: don't synthesize for default args. */
4948 && current_function_decl
)
4949 synthesize_method (decl
);
4951 /* If this is a function or variable that is an instance of some
4952 template, we now know that we will need to actually do the
4953 instantiation. A TEMPLATE_DECL may also have DECL_TEMPLATE_INFO,
4954 if it's a partial instantiation, but there's no need to
4955 instantiate such a thing. We check that DECL is not an explicit
4956 instantiation because that is not checked in instantiate_decl. */
4957 if (TREE_CODE (decl
) != TEMPLATE_DECL
4958 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)
4959 && !DECL_EXPLICIT_INSTANTIATION (decl
))
4960 instantiate_decl (decl
);
4963 /* Helper function for named_class_head_sans_basetype nonterminal. */
4966 handle_class_head (aggr
, scope
, id
)
4967 tree aggr
, scope
, id
;
4969 if (TREE_CODE (id
) == TYPE_DECL
)
4971 if (DECL_CLASS_TEMPLATE_P (id
))
4972 return DECL_TEMPLATE_RESULT (id
);
4975 cp_error ("`%T' does not have a nested type named `%D'", scope
, id
);
4977 cp_error ("no file-scope type named `%D'", id
);
4980 (aggr
, make_anon_name (), 1);
4981 return TYPE_MAIN_DECL (id
);