1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Process declarations and symbol lookup for C front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
43 #include "dwarf2out.h"
48 extern cpp_reader parse_in
;
49 extern cpp_options parse_options
;
50 static int cpp_initialized
;
53 static tree get_sentry
PROTO((tree
));
54 static void mark_vtable_entries
PROTO((tree
));
55 static void grok_function_init
PROTO((tree
, tree
));
56 static int finish_vtable_vardecl
PROTO((tree
, tree
));
57 static int prune_vtable_vardecl
PROTO((tree
, tree
));
58 static void finish_sigtable_vardecl
PROTO((tree
, tree
));
59 static int is_namespace_ancestor
PROTO((tree
, tree
));
60 static void add_using_namespace
PROTO((tree
, tree
, int));
61 static tree ambiguous_decl
PROTO((tree
, tree
, tree
,int));
62 static tree build_anon_union_vars
PROTO((tree
, tree
*, int, int));
63 static void check_decl_namespace
PROTO((void));
65 extern int current_class_depth
;
67 /* A list of virtual function tables we must make sure to write out. */
70 /* A list of static class variables. This is needed, because a
71 static class variable can be declared inside the class without
72 an initializer, and then initialized, staticly, outside the class. */
75 /* A list of functions which were declared inline, but which we
76 may need to emit outline anyway. */
77 static tree saved_inlines
;
79 /* Used to help generate temporary names which are unique within
80 a function. Reset to 0 by start_function. */
82 int temp_name_counter
;
84 /* Same, but not reset. Local temp variables and global temp variables
85 can have the same name. */
86 static int global_temp_name_counter
;
88 /* Flag used when debugging spew.c */
90 extern int spew_debug
;
92 /* Nonzero if we're done parsing and into end-of-file activities. */
96 /* Functions called along with real static constructors and destructors. */
98 tree static_ctors
, static_dtors
;
100 /* The current open namespace, and ::. */
102 tree current_namespace
;
103 tree global_namespace
;
105 /* The stack for namespaces of current declarations. */
107 static tree decl_namespace_list
;
110 /* C (and C++) language-specific option variables. */
112 /* Nonzero means allow type mismatches in conditional expressions;
113 just make their values `void'. */
115 int flag_cond_mismatch
;
117 /* Nonzero means give `double' the same size as `float'. */
119 int flag_short_double
;
121 /* Nonzero means don't recognize the keyword `asm'. */
125 /* Nonzero means don't recognize any extension keywords. */
127 int flag_no_gnu_keywords
;
129 /* Nonzero means don't recognize the non-ANSI builtin functions. */
133 /* Nonzero means don't recognize the non-ANSI builtin functions.
136 int flag_no_nonansi_builtin
;
138 /* Nonzero means do some things the same way PCC does. Only provided so
139 the compiler will link. */
141 int flag_traditional
;
143 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
145 int flag_signed_bitfields
= 1;
147 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
151 /* Nonzero means enable obscure ANSI features and disable GNU extensions
152 that might cause ANSI-compliant code to be miscompiled. */
156 /* Nonzero means do emit exported implementations of functions even if
157 they can be inlined. */
159 int flag_implement_inlines
= 1;
161 /* Nonzero means do emit exported implementations of templates, instead of
162 multiple static copies in each file that needs a definition. */
164 int flag_external_templates
;
166 /* Nonzero means that the decision to emit or not emit the implementation of a
167 template depends on where the template is instantiated, rather than where
170 int flag_alt_external_templates
;
172 /* Nonzero means that implicit instantiations will be emitted if needed. */
174 int flag_implicit_templates
= 1;
176 /* Nonzero means allow numerical priorities on constructors. */
178 #ifdef USE_INIT_PRIORITY
179 int flag_init_priority
= 1;
181 int flag_init_priority
;
184 /* Nonzero means warn about implicit declarations. */
186 int warn_implicit
= 1;
188 /* Nonzero means warn about usage of long long when `-pedantic'. */
190 int warn_long_long
= 1;
192 /* Nonzero means warn when all ctors or dtors are private, and the class
195 int warn_ctor_dtor_privacy
= 1;
197 /* True if we want to implement vtables using "thunks".
198 The default is off. */
200 #ifndef DEFAULT_VTABLE_THUNKS
201 #define DEFAULT_VTABLE_THUNKS 0
203 int flag_vtable_thunks
= DEFAULT_VTABLE_THUNKS
;
205 /* True if we want to deal with repository information. */
207 int flag_use_repository
;
209 /* Nonzero if we want to issue diagnostics that the standard says are not
212 int flag_optional_diags
= 1;
214 /* Nonzero means give string constants the type `const char *'
215 to get extra warnings from them. These warnings will be too numerous
216 to be useful, except in thoroughly ANSIfied programs. */
218 int warn_write_strings
;
220 /* Nonzero means warn about pointer casts that can drop a type qualifier
221 from the pointer target type. */
225 /* Nonzero means warn about sizeof(function) or addition/subtraction
226 of function pointers. */
228 int warn_pointer_arith
= 1;
230 /* Nonzero means warn for any function def without prototype decl. */
232 int warn_missing_prototypes
;
234 /* Nonzero means warn about multiple (redundant) decls for the same single
235 variable or function. */
237 int warn_redundant_decls
;
239 /* Warn if initializer is not completely bracketed. */
241 int warn_missing_braces
;
243 /* Warn about comparison of signed and unsigned values. */
245 int warn_sign_compare
;
247 /* Warn about *printf or *scanf format/argument anomalies. */
251 /* Warn about a subscript that has type char. */
253 int warn_char_subscripts
;
255 /* Warn if a type conversion is done that might have confusing results. */
259 /* Warn if adding () is suggested. */
261 int warn_parentheses
;
263 /* Non-zero means warn in function declared in derived class has the
264 same name as a virtual in the base class, but fails to match the
265 type signature of any virtual function in the base class. */
266 int warn_overloaded_virtual
;
268 /* Non-zero means warn when declaring a class that has a non virtual
269 destructor, when it really ought to have a virtual one. */
272 /* Non-zero means warn when a function is declared extern and later inline. */
273 int warn_extern_inline
;
275 /* Non-zero means warn when the compiler will reorder code. */
278 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
281 /* Non-zero means warn when we convert a pointer to member function
282 into a pointer to (void or function). */
283 int warn_pmf2ptr
= 1;
285 /* Nonzero means warn about violation of some Effective C++ style rules. */
289 /* Nonzero means warn where overload resolution chooses a promotion from
290 unsigned to signed over a conversion to an unsigned of the same size. */
294 /* Nonzero means warn when an old-style cast is used. */
296 int warn_old_style_cast
;
298 /* Warn about #pragma directives that are not recognised. */
300 int warn_unknown_pragmas
; /* Tri state variable. */
302 /* Nonzero means warn about use of multicharacter literals. */
304 int warn_multichar
= 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 /* Nonzero for -fall-virtual: make every member function (except
330 constructors) lay down in the virtual function table. Calls
331 can then either go through the virtual function table or not,
334 int flag_all_virtual
;
336 /* Zero means that `this' is a *const. This gives nice behavior in the
337 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
338 -2 means we're constructing an object and it has fixed type. */
340 int flag_this_is_variable
;
342 /* Nonzero means memoize our member lookups. */
344 int flag_memoize_lookups
; int flag_save_memoized_contexts
;
346 /* 3 means write out only virtuals function tables `defined'
347 in this implementation file.
348 2 means write out only specific virtual function tables
349 and give them (C) public access.
350 1 means write out virtual function tables and give them
352 0 means write out virtual function tables and give them
353 (C) static access (default).
354 -1 means declare virtual function tables extern. */
358 /* Nonzero means we should attempt to elide constructors when possible.
359 FIXME: This flag is obsolete, and should be torn out along with the
360 old overloading code. */
362 int flag_elide_constructors
;
364 /* Nonzero means recognize and handle signature language constructs. */
366 int flag_handle_signatures
;
368 /* Nonzero means that member functions defined in class scope are
369 inline by default. */
371 int flag_default_inline
= 1;
373 /* Controls whether enums and ints freely convert.
374 1 means with complete freedom.
375 0 means enums can convert to ints, but not vice-versa. */
376 int flag_int_enum_equivalence
;
378 /* Controls whether compiler generates 'type descriptor' that give
379 run-time type information. */
382 /* Nonzero if we wish to output cross-referencing information
383 for the GNU class browser. */
384 extern int flag_gnu_xref
;
386 /* Nonzero if compiler can make `reasonable' assumptions about
387 references and objects. For example, the compiler must be
388 conservative about the following and not assume that `a' is nonnull:
393 In general, it is `reasonable' to assume that for many programs,
394 and better code can be generated in that case. */
396 int flag_assume_nonnull_objects
= 1;
398 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
401 int flag_huge_objects
;
403 /* Nonzero if we want to conserve space in the .o files. We do this
404 by putting uninitialized data and runtime initialized data into
405 .common instead of .data at the expense of not flagging multiple
408 int flag_conserve_space
;
410 /* Nonzero if we want to obey access control semantics. */
412 int flag_access_control
= 1;
414 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
416 int flag_operator_names
;
418 /* Nonzero if we want to check the return value of new and avoid calling
419 constructors if it is a null pointer. */
423 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
424 initialization variables.
425 0: Old rules, set by -fno-for-scope.
426 2: New ANSI rules, set by -ffor-scope.
427 1: Try to implement new ANSI rules, but with backup compatibility
428 (and warnings). This is the default, for now. */
430 int flag_new_for_scope
= 1;
432 /* Nonzero if we want to emit defined symbols with common-like linkage as
433 weak symbols where possible, in order to conform to C++ semantics.
434 Otherwise, emit them as local symbols. */
438 /* Nonzero to enable experimental ABI changes. */
442 /* Nonzero to not ignore namespace std. */
446 /* Maximum template instantiation depth. Must be at least 17 for ANSI
449 int max_tinst_depth
= 17;
451 /* The name-mangling scheme to use. Must be 1 or greater to support
452 template functions with identical types, but different template
454 int name_mangling_version
= 2;
456 /* Nonzero means that guiding declarations are allowed. */
457 int flag_guiding_decls
;
459 /* Nonzero if squashed mangling is to be performed.
460 This uses the B and K codes to reference previously seen class types
461 and class qualifiers. */
462 int flag_do_squangling
;
465 /* Table of language-dependent -f options.
466 STRING is the option name. VARIABLE is the address of the variable.
467 ON_VALUE is the value to store in VARIABLE
468 if `-fSTRING' is seen as an option.
469 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
471 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
473 {"signed-char", &flag_signed_char
, 1},
474 {"unsigned-char", &flag_signed_char
, 0},
475 {"signed-bitfields", &flag_signed_bitfields
, 1},
476 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
477 {"short-enums", &flag_short_enums
, 1},
478 {"short-double", &flag_short_double
, 1},
479 {"cond-mismatch", &flag_cond_mismatch
, 1},
480 {"squangle", &flag_do_squangling
, 1},
481 {"asm", &flag_no_asm
, 0},
482 {"builtin", &flag_no_builtin
, 0},
483 {"ident", &flag_no_ident
, 0},
484 {"labels-ok", &flag_labels_ok
, 1},
485 {"stats", &flag_detailed_statistics
, 1},
486 {"this-is-variable", &flag_this_is_variable
, 1},
487 {"strict-prototype", &flag_strict_prototype
, 1},
488 {"all-virtual", &flag_all_virtual
, 1},
489 {"memoize-lookups", &flag_memoize_lookups
, 1},
490 {"elide-constructors", &flag_elide_constructors
, 1},
491 {"handle-exceptions", &flag_exceptions
, 1},
492 {"handle-signatures", &flag_handle_signatures
, 1},
493 {"default-inline", &flag_default_inline
, 1},
494 {"dollars-in-identifiers", &dollars_in_ident
, 1},
495 {"enum-int-equiv", &flag_int_enum_equivalence
, 1},
496 {"honor-std", &flag_honor_std
, 1},
497 {"rtti", &flag_rtti
, 1},
498 {"xref", &flag_gnu_xref
, 1},
499 {"nonnull-objects", &flag_assume_nonnull_objects
, 1},
500 {"implement-inlines", &flag_implement_inlines
, 1},
501 {"external-templates", &flag_external_templates
, 1},
502 {"implicit-templates", &flag_implicit_templates
, 1},
503 {"init-priority", &flag_init_priority
, 1},
504 {"huge-objects", &flag_huge_objects
, 1},
505 {"conserve-space", &flag_conserve_space
, 1},
506 {"vtable-thunks", &flag_vtable_thunks
, 1},
507 {"access-control", &flag_access_control
, 1},
508 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
509 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
510 {"operator-names", &flag_operator_names
, 1},
511 {"optional-diags", &flag_optional_diags
, 1},
512 {"check-new", &flag_check_new
, 1},
513 {"repo", &flag_use_repository
, 1},
514 {"for-scope", &flag_new_for_scope
, 2},
515 {"weak", &flag_weak
, 1}
518 /* Decode the string P as a language-specific option.
519 Return the number of strings consumed for a valid option.
520 Otherwise return 0. */
523 lang_decode_option (argc
, argv
)
528 int strings_processed
;
531 if (! cpp_initialized
)
533 cpp_reader_init (&parse_in
);
534 parse_in
.data
= &parse_options
;
535 cpp_options_init (&parse_options
);
538 strings_processed
= cpp_handle_option (&parse_in
, argc
, argv
);
540 strings_processed
= 0;
541 #endif /* ! USE_CPPLIB */
543 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
545 /* The +e options are for cfront compatibility. They come in as
546 `-+eN', to kludge around gcc.c's argument handling. */
547 else if (p
[0] == '-' && p
[1] == '+' && p
[2] == 'e')
549 int old_write_virtuals
= write_virtuals
;
552 else if (p
[3] == '0')
554 else if (p
[3] == '2')
556 else error ("invalid +e option");
557 if (old_write_virtuals
!= 0
558 && write_virtuals
!= old_write_virtuals
)
559 error ("conflicting +e options given");
561 else if (p
[0] == '-' && p
[1] == 'f')
563 /* Some kind of -f option.
564 P's value is the option sans `-f'.
565 Search for it in the table of options. */
570 /* Try special -f options. */
572 if (!strcmp (p
, "handle-exceptions")
573 || !strcmp (p
, "no-handle-exceptions"))
574 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
576 if (!strcmp (p
, "save-memoized"))
578 flag_memoize_lookups
= 1;
579 flag_save_memoized_contexts
= 1;
582 else if (!strcmp (p
, "no-save-memoized"))
584 flag_memoize_lookups
= 0;
585 flag_save_memoized_contexts
= 0;
588 else if (! strcmp (p
, "alt-external-templates"))
590 flag_external_templates
= 1;
591 flag_alt_external_templates
= 1;
594 else if (! strcmp (p
, "no-alt-external-templates"))
596 flag_alt_external_templates
= 0;
599 else if (!strcmp (p
, "repo"))
601 flag_use_repository
= 1;
602 flag_implicit_templates
= 0;
605 else if (!strcmp (p
, "guiding-decls"))
607 flag_guiding_decls
= 1;
608 name_mangling_version
= 0;
611 else if (!strcmp (p
, "no-guiding-decls"))
613 flag_guiding_decls
= 0;
616 else if (!strcmp (p
, "ansi-overloading"))
618 else if (!strcmp (p
, "no-ansi-overloading"))
620 error ("-fno-ansi-overloading is no longer supported");
623 else if (!strcmp (p
, "new-abi"))
626 flag_do_squangling
= 1;
628 flag_vtable_thunks
= 1;
630 else if (!strcmp (p
, "no-new-abi"))
633 flag_do_squangling
= 0;
636 else if (!strncmp (p
, "template-depth-", 15))
641 if (*endp
>= '0' && *endp
<= '9')
645 error ("Invalid option `%s'", p
- 2);
646 goto template_depth_lose
;
649 max_tinst_depth
= atoi (p
+ 15);
650 template_depth_lose
: ;
652 else if (!strncmp (p
, "name-mangling-version-", 22))
657 if (*endp
>= '0' && *endp
<= '9')
661 error ("Invalid option `%s'", p
- 2);
662 goto mangling_version_lose
;
665 name_mangling_version
= atoi (p
+ 22);
666 mangling_version_lose
: ;
669 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
672 if (!strcmp (p
, lang_f_options
[j
].string
))
674 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
675 /* A goto here would be cleaner,
676 but breaks the vax pcc. */
679 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
680 && ! strcmp (p
+3, lang_f_options
[j
].string
))
682 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
688 else if (p
[0] == '-' && p
[1] == 'W')
692 /* The -W options control the warning behavior of the compiler. */
695 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
698 if (!strcmp (p
, "implicit"))
699 warn_implicit
= setting
;
700 else if (!strcmp (p
, "long-long"))
701 warn_long_long
= setting
;
702 else if (!strcmp (p
, "return-type"))
703 warn_return_type
= setting
;
704 else if (!strcmp (p
, "ctor-dtor-privacy"))
705 warn_ctor_dtor_privacy
= setting
;
706 else if (!strcmp (p
, "write-strings"))
707 warn_write_strings
= setting
;
708 else if (!strcmp (p
, "cast-qual"))
709 warn_cast_qual
= setting
;
710 else if (!strcmp (p
, "char-subscripts"))
711 warn_char_subscripts
= setting
;
712 else if (!strcmp (p
, "pointer-arith"))
713 warn_pointer_arith
= setting
;
714 else if (!strcmp (p
, "missing-prototypes"))
715 warn_missing_prototypes
= setting
;
716 else if (!strcmp (p
, "redundant-decls"))
717 warn_redundant_decls
= setting
;
718 else if (!strcmp (p
, "missing-braces"))
719 warn_missing_braces
= setting
;
720 else if (!strcmp (p
, "sign-compare"))
721 warn_sign_compare
= setting
;
722 else if (!strcmp (p
, "format"))
723 warn_format
= setting
;
724 else if (!strcmp (p
, "conversion"))
725 warn_conversion
= setting
;
726 else if (!strcmp (p
, "parentheses"))
727 warn_parentheses
= setting
;
728 else if (!strcmp (p
, "non-virtual-dtor"))
729 warn_nonvdtor
= setting
;
730 else if (!strcmp (p
, "extern-inline"))
731 warn_extern_inline
= setting
;
732 else if (!strcmp (p
, "reorder"))
733 warn_reorder
= setting
;
734 else if (!strcmp (p
, "synth"))
735 warn_synth
= setting
;
736 else if (!strcmp (p
, "pmf-conversions"))
737 warn_pmf2ptr
= setting
;
738 else if (!strcmp (p
, "effc++"))
740 else if (!strcmp (p
, "sign-promo"))
741 warn_sign_promo
= setting
;
742 else if (!strcmp (p
, "old-style-cast"))
743 warn_old_style_cast
= setting
;
744 else if (!strcmp (p
, "overloaded-virtual"))
745 warn_overloaded_virtual
= setting
;
746 else if (!strcmp (p
, "multichar"))
747 warn_multichar
= setting
;
748 else if (!strcmp (p
, "unknown-pragmas"))
749 /* Set to greater than 1, so that even unknown pragmas in
750 system headers will be warned about. */
751 warn_unknown_pragmas
= setting
* 2;
752 else if (!strcmp (p
, "comment"))
753 ; /* cpp handles this one. */
754 else if (!strcmp (p
, "comments"))
755 ; /* cpp handles this one. */
756 else if (!strcmp (p
, "trigraphs"))
757 ; /* cpp handles this one. */
758 else if (!strcmp (p
, "import"))
759 ; /* cpp handles this one. */
760 else if (!strcmp (p
, "all"))
762 warn_return_type
= setting
;
763 warn_unused
= setting
;
764 warn_implicit
= setting
;
765 warn_ctor_dtor_privacy
= setting
;
766 warn_switch
= setting
;
767 warn_format
= setting
;
768 warn_parentheses
= setting
;
769 warn_missing_braces
= setting
;
770 warn_sign_compare
= setting
;
771 warn_extern_inline
= setting
;
772 warn_nonvdtor
= setting
;
773 warn_multichar
= setting
;
774 /* We save the value of warn_uninitialized, since if they put
775 -Wuninitialized on the command line, we need to generate a
776 warning about not using it without also specifying -O. */
777 if (warn_uninitialized
!= 1)
778 warn_uninitialized
= (setting
? 2 : 0);
779 warn_reorder
= setting
;
780 warn_sign_promo
= setting
;
781 /* Only warn about unknown pragmas that are not in system
783 warn_unknown_pragmas
= 1;
785 else return strings_processed
;
787 else if (!strcmp (p
, "-ansi"))
788 flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
789 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
791 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
792 it's probably safe to assume no sane person would ever want to use this
793 under normal circumstances. */
794 else if (!strcmp (p
, "-spew-debug"))
798 return strings_processed
;
803 /* Incorporate `const' and `volatile' qualifiers for member functions.
804 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
805 QUALS is a list of qualifiers. */
808 grok_method_quals (ctype
, function
, quals
)
809 tree ctype
, function
, quals
;
811 tree fntype
= TREE_TYPE (function
);
812 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
816 extern tree ridpointers
[];
818 if (TREE_VALUE (quals
) == ridpointers
[(int)RID_CONST
])
820 if (TYPE_READONLY (ctype
))
821 error ("duplicate `%s' %s",
822 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
823 (TREE_CODE (function
) == FUNCTION_DECL
824 ? "for member function" : "in type declaration"));
825 ctype
= build_type_variant (ctype
, 1, TYPE_VOLATILE (ctype
));
826 build_pointer_type (ctype
);
828 else if (TREE_VALUE (quals
) == ridpointers
[(int)RID_VOLATILE
])
830 if (TYPE_VOLATILE (ctype
))
831 error ("duplicate `%s' %s",
832 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
833 (TREE_CODE (function
) == FUNCTION_DECL
834 ? "for member function" : "in type declaration"));
835 ctype
= build_type_variant (ctype
, TYPE_READONLY (ctype
), 1);
836 build_pointer_type (ctype
);
839 my_friendly_abort (20);
840 quals
= TREE_CHAIN (quals
);
843 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
844 (TREE_CODE (fntype
) == METHOD_TYPE
845 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
846 : TYPE_ARG_TYPES (fntype
)));
848 fntype
= build_exception_variant (fntype
, raises
);
850 TREE_TYPE (function
) = fntype
;
854 /* Warn when -fexternal-templates is used and #pragma
855 interface/implementation is not used all the times it should be,
859 warn_if_unknown_interface (decl
)
862 static int already_warned
= 0;
863 if (already_warned
++)
866 if (flag_alt_external_templates
)
868 struct tinst_level
*til
= tinst_for_decl ();
870 char *sf
= input_filename
;
875 input_filename
= til
->file
;
877 cp_warning ("template `%#D' instantiated in file without #pragma interface",
883 cp_warning_at ("template `%#D' defined in file without #pragma interface",
887 /* A subroutine of the parser, to handle a component list. */
890 grok_x_components (specs
, components
)
891 tree specs
, components
;
893 register tree t
, x
, tcode
;
895 /* We just got some friends. They have been recorded elsewhere. */
896 if (components
== void_type_node
)
899 if (components
== NULL_TREE
)
901 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
905 error ("error in component specification");
909 switch (TREE_CODE (t
))
912 /* Static anonymous unions come out as VAR_DECLs. */
913 if (ANON_UNION_TYPE_P (TREE_TYPE (t
)))
916 /* We return SPECS here, because in the parser it was ending
917 up with not doing anything to $$, which is what SPECS
924 if (TREE_CODE (t
) == UNION_TYPE
)
925 tcode
= union_type_node
;
927 tcode
= record_type_node
;
928 if (CLASSTYPE_DECLARED_CLASS (t
))
929 tcode
= class_type_node
;
930 else if (IS_SIGNATURE (t
))
931 tcode
= signature_type_node
;
933 if (TYPE_LANG_SPECIFIC (t
)
934 && CLASSTYPE_USE_TEMPLATE (t
))
935 /* We have already looked up this type. */
939 if (CLASSTYPE_IS_TEMPLATE (t
))
940 x
= DECL_NAME (CLASSTYPE_TI_TEMPLATE (t
));
942 x
= TYPE_IDENTIFIER (t
);
943 t
= xref_tag (tcode
, x
, NULL_TREE
, 0);
946 if (ANON_UNION_TYPE_P (t
))
948 /* See also shadow_tag. */
950 struct pending_inline
**p
;
952 x
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, t
);
954 /* Wipe out memory of synthesized methods */
955 TYPE_HAS_CONSTRUCTOR (t
) = 0;
956 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
957 TYPE_HAS_INIT_REF (t
) = 0;
958 TYPE_HAS_CONST_INIT_REF (t
) = 0;
959 TYPE_HAS_ASSIGN_REF (t
) = 0;
960 TYPE_HAS_ASSIGNMENT (t
) = 0;
961 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
963 q
= &TYPE_METHODS (t
);
966 if (DECL_ARTIFICIAL (*q
))
967 *q
= TREE_CHAIN (*q
);
969 q
= &TREE_CHAIN (*q
);
971 if (TYPE_METHODS (t
))
972 error ("an anonymous union cannot have function members");
974 p
= &pending_inlines
;
975 for (; *p
; *p
= (*p
)->next
)
976 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
986 tcode
= enum_type_node
;
987 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
988 x
= grok_enum_decls (NULL_TREE
);
993 if (t
!= void_type_node
)
994 error ("empty component declaration");
999 /* There may or may not be any enum decls to grok, but
1000 grok_enum_decls will just return components, if there aren't
1001 any. We used to try to figure out whether or not there were
1002 any enum decls based on the type of components, but that's too
1003 hard; it might be something like `enum { a } *p;'. */
1004 return grok_enum_decls (components
);
1007 /* Constructors for types with virtual baseclasses need an "in-charge" flag
1008 saying whether this constructor is responsible for initialization of
1009 virtual baseclasses or not. All destructors also need this "in-charge"
1010 flag, which additionally determines whether or not the destructor should
1011 free the memory for the object.
1013 This function adds the "in-charge" flag to member function FN if
1014 appropriate. It is called from grokclassfn and tsubst.
1015 FN must be either a constructor or destructor. */
1018 maybe_retrofit_in_chrg (fn
)
1021 tree basetype
, arg_types
, parms
, parm
, fntype
;
1023 if (DECL_CONSTRUCTOR_P (fn
)
1024 && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CLASS_CONTEXT (fn
))
1025 && ! DECL_CONSTRUCTOR_FOR_VBASE_P (fn
))
1027 else if (! DECL_CONSTRUCTOR_P (fn
)
1028 && TREE_CHAIN (DECL_ARGUMENTS (fn
)) == NULL_TREE
)
1033 if (DECL_CONSTRUCTOR_P (fn
))
1034 DECL_CONSTRUCTOR_FOR_VBASE_P (fn
) = 1;
1036 /* First add it to DECL_ARGUMENTS... */
1037 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
1038 /* Mark the artificial `__in_chrg' parameter as "artificial". */
1039 SET_DECL_ARTIFICIAL (parm
);
1040 DECL_ARG_TYPE (parm
) = integer_type_node
;
1041 TREE_READONLY (parm
) = 1;
1042 parms
= DECL_ARGUMENTS (fn
);
1043 TREE_CHAIN (parm
) = TREE_CHAIN (parms
);
1044 TREE_CHAIN (parms
) = parm
;
1046 /* ...and then to TYPE_ARG_TYPES. */
1047 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1048 basetype
= TREE_TYPE (TREE_VALUE (arg_types
));
1049 arg_types
= hash_tree_chain (integer_type_node
, TREE_CHAIN (arg_types
));
1050 fntype
= build_cplus_method_type (basetype
, TREE_TYPE (TREE_TYPE (fn
)),
1052 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)))
1053 fntype
= build_exception_variant (fntype
,
1054 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)));
1055 TREE_TYPE (fn
) = fntype
;
1058 /* Classes overload their constituent function names automatically.
1059 When a function name is declared in a record structure,
1060 its name is changed to it overloaded name. Since names for
1061 constructors and destructors can conflict, we place a leading
1062 '$' for destructors.
1064 CNAME is the name of the class we are grokking for.
1066 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
1068 FLAGS contains bits saying what's special about today's
1069 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
1071 If FUNCTION is a destructor, then we must add the `auto-delete' field
1072 as a second parameter. There is some hair associated with the fact
1073 that we must "declare" this variable in the manner consistent with the
1074 way the rest of the arguments were declared.
1076 QUALS are the qualifiers for the this pointer. */
1079 grokclassfn (ctype
, cname
, function
, flags
, quals
)
1080 tree ctype
, cname
, function
;
1081 enum overload_flags flags
;
1084 tree fn_name
= DECL_NAME (function
);
1089 if (fn_name
== NULL_TREE
)
1091 error ("name missing for member function");
1092 fn_name
= get_identifier ("<anonymous>");
1093 DECL_NAME (function
) = fn_name
;
1097 qualtype
= grok_method_quals (ctype
, function
, quals
);
1101 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1102 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1104 /* Must add the class instance variable up front. */
1105 /* Right now we just make this a pointer. But later
1106 we may wish to make it special. */
1107 tree type
= TREE_VALUE (arg_types
);
1110 if ((flag_this_is_variable
> 0)
1111 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
1114 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
1115 /* Mark the artificial `this' parameter as "artificial". */
1116 SET_DECL_ARTIFICIAL (parm
);
1117 DECL_ARG_TYPE (parm
) = type
;
1118 /* We can make this a register, so long as we don't
1119 accidentally complain if someone tries to take its address. */
1120 DECL_REGISTER (parm
) = 1;
1122 TREE_READONLY (parm
) = 1;
1123 TREE_CHAIN (parm
) = last_function_parms
;
1124 last_function_parms
= parm
;
1127 DECL_ARGUMENTS (function
) = last_function_parms
;
1128 /* First approximations. */
1129 DECL_CONTEXT (function
) = ctype
;
1130 DECL_CLASS_CONTEXT (function
) = ctype
;
1132 if (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
))
1134 maybe_retrofit_in_chrg (function
);
1135 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1138 if (flags
== DTOR_FLAG
)
1140 DECL_ASSEMBLER_NAME (function
) = build_destructor_name (ctype
);
1141 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
1144 set_mangled_name_for_decl (function
);
1147 /* Work on the expr used by alignof (this is only called by the parser). */
1156 if (processing_template_decl
)
1157 return build_min (ALIGNOF_EXPR
, sizetype
, expr
);
1159 if (TREE_CODE (expr
) == COMPONENT_REF
1160 && DECL_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1161 error ("`__alignof__' applied to a bit-field");
1163 if (TREE_CODE (expr
) == INDIRECT_REF
)
1165 best
= t
= TREE_OPERAND (expr
, 0);
1166 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1168 while (TREE_CODE (t
) == NOP_EXPR
1169 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1172 t
= TREE_OPERAND (t
, 0);
1173 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1174 if (thisalign
> bestalign
)
1175 best
= t
, bestalign
= thisalign
;
1177 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1181 /* ANSI says arrays and fns are converted inside comma.
1182 But we can't convert them in build_compound_expr
1183 because that would break commas in lvalues.
1184 So do the conversion here if operand was a comma. */
1185 if (TREE_CODE (expr
) == COMPOUND_EXPR
1186 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1187 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1188 expr
= default_conversion (expr
);
1189 return c_alignof (TREE_TYPE (expr
));
1193 /* Create an ARRAY_REF, checking for the user doing things backwards
1197 grok_array_decl (array_expr
, index_exp
)
1198 tree array_expr
, index_exp
;
1200 tree type
= TREE_TYPE (array_expr
);
1201 tree p1
, p2
, i1
, i2
;
1203 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1204 return error_mark_node
;
1205 if (processing_template_decl
)
1206 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
1207 array_expr
, index_exp
);
1209 if (type
== NULL_TREE
)
1211 /* Something has gone very wrong. Assume we are mistakenly reducing
1212 an expression instead of a declaration. */
1213 error ("parser may be lost: is there a '{' missing somewhere?");
1217 if (TREE_CODE (type
) == OFFSET_TYPE
1218 || TREE_CODE (type
) == REFERENCE_TYPE
)
1219 type
= TREE_TYPE (type
);
1221 /* If they have an `operator[]', use that. */
1222 if (IS_AGGR_TYPE (type
) || IS_AGGR_TYPE (TREE_TYPE (index_exp
)))
1223 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1224 array_expr
, index_exp
, NULL_TREE
);
1226 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1228 if (TREE_CODE (type
) == ARRAY_TYPE
)
1231 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1233 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1236 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1238 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1239 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1241 if ((p1
&& i2
) && (i1
&& p2
))
1242 error ("ambiguous conversion for array subscript");
1245 array_expr
= p1
, index_exp
= i2
;
1247 array_expr
= p2
, index_exp
= i1
;
1250 cp_error ("invalid types `%T[%T]' for array subscript",
1251 type
, TREE_TYPE (index_exp
));
1252 return error_mark_node
;
1255 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1256 error ("ambiguous conversion for array subscript");
1258 return build_array_ref (array_expr
, index_exp
);
1261 /* Given the cast expression EXP, checking out its validity. Either return
1262 an error_mark_node if there was an unavoidable error, return a cast to
1263 void for trying to delete a pointer w/ the value 0, or return the
1264 call to delete. If DOING_VEC is 1, we handle things differently
1265 for doing an array delete. If DOING_VEC is 2, they gave us the
1266 array size as an argument to delete.
1267 Implements ARM $5.3.4. This is called from the parser. */
1270 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1272 int doing_vec
, use_global_delete
;
1275 /* For a regular vector delete (aka, no size argument) we will pass
1276 this down as a NULL_TREE into build_vec_delete. */
1277 tree maxindex
= NULL_TREE
;
1279 if (exp
== error_mark_node
)
1282 if (processing_template_decl
)
1284 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
1285 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
1286 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
1290 if (TREE_CODE (exp
) == OFFSET_REF
)
1291 exp
= resolve_offset_ref (exp
);
1292 exp
= convert_from_reference (exp
);
1293 t
= stabilize_reference (exp
);
1294 t
= build_expr_type_conversion (WANT_POINTER
, t
, 1);
1296 if (t
== NULL_TREE
|| t
== error_mark_node
)
1298 cp_error ("type `%#T' argument given to `delete', expected pointer",
1300 return error_mark_node
;
1305 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1306 pedwarn ("anachronistic use of array size in vector delete");
1309 type
= TREE_TYPE (t
);
1311 /* As of Valley Forge, you can delete a pointer to const. */
1313 /* You can't delete functions. */
1314 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1316 error ("cannot delete a function");
1317 return error_mark_node
;
1320 /* An array can't have been allocated by new, so complain. */
1321 if (TREE_CODE (t
) == ADDR_EXPR
1322 && TREE_CODE (TREE_OPERAND (t
, 0)) == VAR_DECL
1323 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == ARRAY_TYPE
)
1324 cp_warning ("deleting array `%#D'", TREE_OPERAND (t
, 0));
1326 /* Deleting a pointer with the value zero is valid and has no effect. */
1327 if (integer_zerop (t
))
1328 return build1 (NOP_EXPR
, void_type_node
, t
);
1331 return build_vec_delete (t
, maxindex
, integer_one_node
,
1332 integer_two_node
, use_global_delete
);
1335 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1336 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1338 /* Only do access checking here; we'll be calling op delete
1339 from the destructor. */
1340 tree tmp
= build_op_delete_call (DELETE_EXPR
, t
, size_zero_node
,
1341 LOOKUP_NORMAL
, NULL_TREE
);
1342 if (tmp
== error_mark_node
)
1343 return error_mark_node
;
1346 return build_delete (type
, t
, integer_three_node
,
1347 LOOKUP_NORMAL
, use_global_delete
);
1351 /* Report an error if the indicated template declaration is not the
1352 sort of thing that should be a member template. */
1355 check_member_template (tmpl
)
1360 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 0);
1361 decl
= DECL_TEMPLATE_RESULT (tmpl
);
1363 if (TREE_CODE (decl
) == FUNCTION_DECL
1364 || (TREE_CODE (decl
) == TYPE_DECL
1365 && IS_AGGR_TYPE (TREE_TYPE (decl
))))
1367 if (current_function_decl
)
1368 /* 14.5.2.2 [temp.mem]
1370 A local class shall not have member templates. */
1371 cp_error ("declaration of member template `%#D' in local class",
1374 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
1376 /* 14.5.2.3 [temp.mem]
1378 A member function template shall not be virtual. */
1380 ("invalid use of `virtual' in template declaration of `%#D'",
1382 DECL_VIRTUAL_P (decl
) = 0;
1385 /* The debug-information generating code doesn't know what to do
1386 with member templates. */
1387 DECL_IGNORED_P (tmpl
) = 1;
1390 cp_error ("template declaration of `%#D'", decl
);
1393 /* Return true iff TYPE is a valid Java parameter or return type. */
1396 acceptable_java_type (type
)
1399 if (TREE_CODE (type
) == VOID_TYPE
|| TYPE_FOR_JAVA (type
))
1401 if (TREE_CODE (type
) == POINTER_TYPE
)
1403 type
= TREE_TYPE (type
);
1404 if (TREE_CODE (type
) == RECORD_TYPE
)
1407 if (! TYPE_FOR_JAVA (type
))
1409 if (! CLASSTYPE_TEMPLATE_INFO (type
))
1411 args
= CLASSTYPE_TI_ARGS (type
);
1412 i
= TREE_VEC_LENGTH (args
);
1415 type
= TREE_VEC_ELT (args
, i
);
1416 if (TREE_CODE (type
) == POINTER_TYPE
)
1417 type
= TREE_TYPE (type
);
1418 if (! TYPE_FOR_JAVA (type
))
1427 /* For a METHOD in a Java class CTYPE, return 1 if
1428 the parameter and return types are valid Java types.
1429 Otherwise, print appropriate error messages, and return 0. */
1432 check_java_method (ctype
, method
)
1436 tree arg_types
= TYPE_ARG_TYPES (TREE_TYPE (method
));
1437 tree ret_type
= TREE_TYPE (TREE_TYPE (method
));
1438 if (! acceptable_java_type (ret_type
))
1440 cp_error ("Java method '%D' has non-Java return type `%T'",
1444 for (; arg_types
!= NULL_TREE
; arg_types
= TREE_CHAIN (arg_types
))
1446 tree type
= TREE_VALUE (arg_types
);
1447 if (! acceptable_java_type (type
))
1449 cp_error ("Java method '%D' has non-Java parameter type `%T'",
1454 return jerr
? 0 : 1;
1457 /* Sanity check: report error if this function FUNCTION is not
1458 really a member of the class (CTYPE) it is supposed to belong to.
1459 CNAME is the same here as it is for grokclassfn above. */
1462 check_classfn (ctype
, function
)
1463 tree ctype
, function
;
1465 tree fn_name
= DECL_NAME (function
);
1466 tree fndecl
, fndecls
;
1467 tree method_vec
= CLASSTYPE_METHOD_VEC (complete_type (ctype
));
1470 tree templates
= NULL_TREE
;
1472 if (method_vec
!= 0)
1474 methods
= &TREE_VEC_ELT (method_vec
, 0);
1475 end
= TREE_VEC_END (method_vec
);
1477 /* First suss out ctors and dtors. */
1478 if (*methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1479 && DECL_CONSTRUCTOR_P (function
))
1481 if (*++methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1482 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
)))
1485 while (++methods
!= end
)
1488 if (fn_name
== DECL_NAME (OVL_CURRENT (*methods
)))
1491 for (fndecls
= *methods
; fndecls
!= NULL_TREE
;
1492 fndecls
= OVL_NEXT (fndecls
))
1494 fndecl
= OVL_CURRENT (fndecls
);
1495 /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL is
1496 not mangled, so the check below does not work
1497 correctly in that case. */
1498 if (TREE_CODE (function
) != TEMPLATE_DECL
1499 && TREE_CODE (fndecl
) != TEMPLATE_DECL
1500 && (DECL_ASSEMBLER_NAME (function
)
1501 == DECL_ASSEMBLER_NAME (fndecl
)))
1504 /* We cannot simply call decls_match because this
1505 doesn't work for static member functions that are
1506 pretending to be methods, and because the name
1507 may have been changed by asm("new_name"). */
1508 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1510 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1511 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1513 /* Get rid of the this parameter on functions that become
1515 if (DECL_STATIC_FUNCTION_P (fndecl
)
1516 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1517 p1
= TREE_CHAIN (p1
);
1519 if (comptypes (TREE_TYPE (TREE_TYPE (function
)),
1520 TREE_TYPE (TREE_TYPE (fndecl
)), 1)
1521 && compparms (p1
, p2
, 3)
1522 && (DECL_TEMPLATE_SPECIALIZATION (function
)
1523 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
1524 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
1525 || (DECL_TI_TEMPLATE (function
)
1526 == DECL_TI_TEMPLATE (fndecl
))))
1529 if (is_member_template (fndecl
))
1530 /* This function might be an instantiation
1531 or specialization of fndecl. */
1533 scratch_tree_cons (NULL_TREE
, fndecl
, templates
);
1538 else if (TREE_CODE (fndecl
) == TEMPLATE_DECL
1539 && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl
))
1540 && IDENTIFIER_TYPENAME_P (fn_name
))
1541 /* The method in the class is a member template
1542 conversion operator. We are declaring another
1543 conversion operator. It is possible that even though
1544 the names don't match, there is some specialization
1547 scratch_tree_cons (NULL_TREE
, fndecl
, templates
);
1552 /* This function might be an instantiation or a specialization.
1553 We should verify that this is possible. If it is, we must
1554 somehow add the new declaration to the method vector for the
1555 class. Perhaps we should use add_method? For now, we simply
1556 return NULL_TREE, which lets the caller know that this
1557 function is new, but we don't print an error message. */
1562 tree fndecl
= *methods
;
1563 cp_error ("prototype for `%#D' does not match any in class `%T'",
1565 cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl
) ? "s are" : " is",
1566 OVL_CURRENT (fndecl
));
1567 while (fndecl
= OVL_NEXT (fndecl
), fndecl
)
1568 cp_error_at (" %#D", OVL_CURRENT(fndecl
));
1573 cp_error ("no `%#D' member function declared in class `%T'",
1577 /* If we did not find the method in the class, add it to avoid
1579 add_method (ctype
, methods
, function
);
1583 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1584 of a structure component, returning a FIELD_DECL node.
1585 QUALS is a list of type qualifiers for this decl (such as for declaring
1586 const member functions).
1588 This is done during the parsing of the struct declaration.
1589 The FIELD_DECL nodes are chained together and the lot of them
1590 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1594 If class A defines that certain functions in class B are friends, then
1595 the way I have set things up, it is B who is interested in permission
1596 granted by A. However, it is in A's context that these declarations
1597 are parsed. By returning a void_type_node, class A does not attempt
1598 to incorporate the declarations of the friends within its structure.
1600 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1601 CHANGES TO CODE IN `start_method'. */
1604 grokfield (declarator
, declspecs
, init
, asmspec_tree
, attrlist
)
1605 tree declarator
, declspecs
, init
, asmspec_tree
, attrlist
;
1607 register tree value
;
1609 int flags
= LOOKUP_ONLYCONVERTING
;
1611 /* Convert () initializers to = initializers. */
1612 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1613 && TREE_CODE (declarator
) == CALL_EXPR
1614 && TREE_OPERAND (declarator
, 0)
1615 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1616 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1617 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1619 init
= TREE_OPERAND (declarator
, 1);
1620 declarator
= TREE_OPERAND (declarator
, 0);
1624 if (declspecs
== NULL_TREE
1625 && TREE_CODE (declarator
) == SCOPE_REF
1626 && TREE_CODE (TREE_OPERAND (declarator
, 1)) == IDENTIFIER_NODE
)
1628 /* Access declaration */
1629 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
1631 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
1632 pop_nested_class (1);
1633 return do_class_using_decl (declarator
);
1637 && TREE_CODE (init
) == TREE_LIST
1638 && TREE_VALUE (init
) == error_mark_node
1639 && TREE_CHAIN (init
) == NULL_TREE
)
1642 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, NULL_TREE
);
1644 return value
; /* friend or constructor went bad. */
1646 /* Pass friendly classes back. */
1647 if (TREE_CODE (value
) == VOID_TYPE
)
1648 return void_type_node
;
1650 if (DECL_NAME (value
) != NULL_TREE
1651 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1652 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1653 cp_error ("member `%D' conflicts with virtual function table field name",
1656 /* Stash away type declarations. */
1657 if (TREE_CODE (value
) == TYPE_DECL
)
1659 DECL_NONLOCAL (value
) = 1;
1660 DECL_CONTEXT (value
) = current_class_type
;
1661 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1662 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
1664 /* Now that we've updated the context, we need to remangle the
1665 name for this TYPE_DECL. */
1666 DECL_ASSEMBLER_NAME (value
) = DECL_NAME (value
);
1667 if (!uses_template_parms (value
))
1668 DECL_ASSEMBLER_NAME (value
) =
1669 get_identifier (build_overload_name (TREE_TYPE (value
), 1, 1));
1671 pushdecl_class_level (value
);
1675 if (IS_SIGNATURE (current_class_type
)
1676 && TREE_CODE (value
) != FUNCTION_DECL
)
1678 error ("field declaration not allowed in signature");
1679 return void_type_node
;
1682 if (DECL_IN_AGGR_P (value
))
1684 cp_error ("`%D' is already defined in the class %T", value
,
1685 DECL_CONTEXT (value
));
1686 return void_type_node
;
1690 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1694 if (IS_SIGNATURE (current_class_type
)
1695 && TREE_CODE (value
) == FUNCTION_DECL
)
1697 error ("function declarations cannot have initializers in signature");
1700 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1702 grok_function_init (value
, init
);
1705 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1706 /* Already complained in grokdeclarator. */
1710 /* We allow initializers to become parameters to base
1712 if (TREE_CODE (init
) == TREE_LIST
)
1714 if (TREE_CHAIN (init
) == NULL_TREE
)
1715 init
= TREE_VALUE (init
);
1717 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1720 if (TREE_CODE (init
) == CONST_DECL
)
1721 init
= DECL_INITIAL (init
);
1722 else if (TREE_READONLY_DECL_P (init
))
1723 init
= decl_constant_value (init
);
1724 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1725 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1726 my_friendly_assert (TREE_PERMANENT (init
), 192);
1727 if (init
== error_mark_node
)
1728 /* We must make this look different than `error_mark_node'
1729 because `decl_const_value' would mis-interpret it
1730 as only meaning that this VAR_DECL is defined. */
1731 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1732 else if (processing_template_decl
)
1734 else if (! TREE_CONSTANT (init
))
1736 /* We can allow references to things that are effectively
1737 static, since references are initialized with the address. */
1738 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1739 || (TREE_STATIC (init
) == 0
1740 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1741 || DECL_EXTERNAL (init
) == 0)))
1743 error ("field initializer is not constant");
1744 init
= error_mark_node
;
1750 /* The corresponding pop_obstacks is in cp_finish_decl. */
1751 push_obstacks_nochange ();
1753 if (processing_template_decl
&& ! current_function_decl
1754 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1755 value
= push_template_decl (value
);
1758 cplus_decl_attributes (value
, TREE_PURPOSE (attrlist
),
1759 TREE_VALUE (attrlist
));
1761 if (TREE_CODE (value
) == VAR_DECL
)
1763 my_friendly_assert (TREE_PUBLIC (value
), 0);
1765 /* We cannot call pushdecl here, because that would
1766 fill in the value of our TREE_CHAIN. Instead, we
1767 modify cp_finish_decl to do the right thing, namely, to
1768 put this decl out straight away. */
1769 /* current_class_type can be NULL_TREE in case of error. */
1770 if (asmspec
== 0 && current_class_type
)
1772 TREE_PUBLIC (value
) = 1;
1773 DECL_INITIAL (value
) = error_mark_node
;
1774 DECL_ASSEMBLER_NAME (value
)
1775 = build_static_name (current_class_type
, DECL_NAME (value
));
1777 if (! processing_template_decl
)
1778 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1780 /* Static consts need not be initialized in the class definition. */
1781 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1783 static int explanation
= 0;
1785 error ("initializer invalid for static member with constructor");
1786 if (explanation
++ == 0)
1787 error ("(you really want to initialize it separately)");
1790 /* Force the compiler to know when an uninitialized static
1791 const member is being used. */
1792 if (TYPE_READONLY (value
) && init
== 0)
1793 TREE_USED (value
) = 1;
1794 DECL_INITIAL (value
) = init
;
1795 DECL_IN_AGGR_P (value
) = 1;
1796 DECL_CONTEXT (value
) = current_class_type
;
1797 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1799 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1800 pushdecl_class_level (value
);
1803 if (TREE_CODE (value
) == FIELD_DECL
)
1807 /* This must override the asm specifier which was placed
1808 by grokclassfn. Lay this out fresh. */
1809 DECL_RTL (value
) = NULL_RTX
;
1810 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1812 if (DECL_INITIAL (value
) == error_mark_node
)
1813 init
= error_mark_node
;
1814 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1815 DECL_INITIAL (value
) = init
;
1816 DECL_IN_AGGR_P (value
) = 1;
1819 if (TREE_CODE (value
) == FUNCTION_DECL
)
1823 /* This must override the asm specifier which was placed
1824 by grokclassfn. Lay this out fresh. */
1825 DECL_RTL (value
) = NULL_RTX
;
1826 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1828 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1830 /* Pass friends back this way. */
1831 if (DECL_FRIEND_P (value
))
1832 return void_type_node
;
1834 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1835 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1836 cp_error ("method `%#D' of local class must be defined in class body",
1840 DECL_IN_AGGR_P (value
) = 1;
1843 my_friendly_abort (21);
1848 /* Like `grokfield', but for bitfields.
1849 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1852 grokbitfield (declarator
, declspecs
, width
)
1853 tree declarator
, declspecs
, width
;
1855 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1858 if (! value
) return NULL_TREE
; /* friends went bad. */
1860 /* Pass friendly classes back. */
1861 if (TREE_CODE (value
) == VOID_TYPE
)
1862 return void_type_node
;
1864 if (TREE_CODE (value
) == TYPE_DECL
)
1866 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1870 /* Usually, finish_struct_1 catches bitifields with invalid types.
1871 But, in the case of bitfields with function type, we confuse
1872 ourselves into thinking they are member functions, so we must
1874 if (TREE_CODE (value
) == FUNCTION_DECL
)
1876 cp_error ("cannot declare bitfield `%D' with funcion type",
1881 if (IS_SIGNATURE (current_class_type
))
1883 error ("field declaration not allowed in signature");
1884 return void_type_node
;
1887 if (DECL_IN_AGGR_P (value
))
1889 cp_error ("`%D' is already defined in the class %T", value
,
1890 DECL_CONTEXT (value
));
1891 return void_type_node
;
1894 GNU_xref_member (current_class_name
, value
);
1896 if (TREE_STATIC (value
))
1898 cp_error ("static member `%D' cannot be a bitfield", value
);
1901 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1903 if (width
!= error_mark_node
)
1905 constant_expression_warning (width
);
1906 DECL_INITIAL (value
) = width
;
1907 DECL_BIT_FIELD (value
) = 1;
1910 DECL_IN_AGGR_P (value
) = 1;
1915 grokoptypename (declspecs
, declarator
)
1916 tree declspecs
, declarator
;
1918 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1919 return build_typename_overload (t
);
1922 /* When a function is declared with an initializer,
1923 do the right thing. Currently, there are two possibilities:
1928 // initialization possibility #1.
1929 virtual void f () = 0;
1951 // initialization possibility #2
1958 copy_assignment_arg_p (parmtype
, virtualp
)
1962 if (current_class_type
== NULL_TREE
)
1965 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1966 parmtype
= TREE_TYPE (parmtype
);
1968 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1970 /* Non-standard hack to support old Booch components. */
1971 || (! virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
))
1980 grok_function_init (decl
, init
)
1984 /* An initializer for a function tells how this function should
1986 tree type
= TREE_TYPE (decl
);
1988 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1989 cp_error ("initializer specified for non-member function `%D'", decl
);
1991 /* We'll check for this in finish_struct_1. */
1992 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1993 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1995 else if (integer_zerop (init
))
1998 /* Mark this function as being "defined". */
1999 DECL_INITIAL (decl
) = error_mark_node
;
2000 /* pure virtual destructors must be defined. */
2001 /* pure virtual needs to be defined (as abort) only when put in
2002 vtbl. For wellformed call, it should be itself. pr4737 */
2003 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
2005 extern tree abort_fndecl
;
2006 /* Give this node rtl from `abort'. */
2007 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
2010 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
2011 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
2014 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
2016 if (copy_assignment_arg_p (parmtype
, 1))
2017 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
2021 cp_error ("invalid initializer for virtual method `%D'", decl
);
2025 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
2026 tree decl
, attributes
, prefix_attributes
;
2028 if (decl
== NULL_TREE
|| decl
== void_type_node
)
2031 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2032 decl
= DECL_TEMPLATE_RESULT (decl
);
2034 decl_attributes (decl
, attributes
, prefix_attributes
);
2036 if (TREE_CODE (decl
) == TYPE_DECL
)
2037 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
2040 /* CONSTRUCTOR_NAME:
2041 Return the name for the constructor (or destructor) for the
2042 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2043 IDENTIFIER_NODE. When given a template, this routine doesn't
2044 lose the specialization. */
2047 constructor_name_full (thing
)
2050 if (TREE_CODE (thing
) == TEMPLATE_TYPE_PARM
2051 || TREE_CODE (thing
) == TEMPLATE_TEMPLATE_PARM
2052 || TREE_CODE (thing
) == TYPENAME_TYPE
)
2053 thing
= TYPE_NAME (thing
);
2054 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
2056 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
2057 thing
= DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing
), 0)));
2059 thing
= TYPE_NAME (thing
);
2061 if (TREE_CODE (thing
) == TYPE_DECL
2062 || (TREE_CODE (thing
) == TEMPLATE_DECL
2063 && TREE_CODE (DECL_TEMPLATE_RESULT (thing
)) == TYPE_DECL
))
2064 thing
= DECL_NAME (thing
);
2065 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
2069 /* CONSTRUCTOR_NAME:
2070 Return the name for the constructor (or destructor) for the
2071 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2072 IDENTIFIER_NODE. When given a template, return the plain
2073 unspecialized name. */
2076 constructor_name (thing
)
2080 thing
= constructor_name_full (thing
);
2081 t
= IDENTIFIER_TEMPLATE (thing
);
2087 /* Cache the value of this class's main virtual function table pointer
2088 in a register variable. This will save one indirection if a
2089 more than one virtual function call is made this function. */
2094 extern tree base_init_expr
;
2096 if (base_init_expr
== 0
2097 && DECL_CONSTRUCTOR_P (current_function_decl
))
2099 if (processing_template_decl
)
2100 add_tree (build_min_nt
2102 current_member_init_list
, current_base_init_list
));
2104 emit_base_init (current_class_type
, 0);
2108 /* Record the existence of an addressable inline function. */
2111 mark_inline_for_output (decl
)
2114 decl
= DECL_MAIN_VARIANT (decl
);
2115 if (DECL_SAVED_INLINE (decl
))
2117 my_friendly_assert (TREE_PERMANENT (decl
), 363);
2118 DECL_SAVED_INLINE (decl
) = 1;
2120 if (DECL_PENDING_INLINE_INFO (decl
) != 0
2121 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
2123 struct pending_inline
*t
= pending_inlines
;
2124 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
2127 if (t
== DECL_PENDING_INLINE_INFO (decl
))
2133 t
= DECL_PENDING_INLINE_INFO (decl
);
2134 t
->next
= pending_inlines
;
2135 pending_inlines
= t
;
2137 DECL_PENDING_INLINE_INFO (decl
) = 0;
2140 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
2146 temp_name_counter
= 0;
2149 /* Hand off a unique name which can be used for variable we don't really
2150 want to know about anyway, for example, the anonymous variables which
2151 are needed to make references work. Declare this thing so we can use it.
2152 The variable created will be of type TYPE.
2154 STATICP is nonzero if this variable should be static. */
2157 get_temp_name (type
, staticp
)
2161 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2163 int toplev
= toplevel_bindings_p ();
2165 push_obstacks_nochange ();
2166 if (toplev
|| staticp
)
2168 end_temporary_allocation ();
2169 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2170 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2174 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2175 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2177 TREE_USED (decl
) = 1;
2178 TREE_STATIC (decl
) = staticp
;
2179 DECL_ARTIFICIAL (decl
) = 1;
2181 /* If this is a local variable, then lay out its rtl now.
2182 Otherwise, callers of this function are responsible for dealing
2183 with this variable's rtl. */
2187 expand_decl_init (decl
);
2194 /* Get a variable which we can use for multiple assignments.
2195 It is not entered into current_binding_level, because
2196 that breaks things when it comes time to do final cleanups
2197 (which take place "outside" the binding contour of the function). */
2200 get_temp_regvar (type
, init
)
2205 decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
2206 TREE_USED (decl
) = 1;
2207 DECL_REGISTER (decl
) = 1;
2208 DECL_ARTIFICIAL (decl
) = 1;
2210 DECL_RTL (decl
) = assign_temp (type
, 2, 0, 1);
2211 /* We can expand these without fear, since they cannot need
2212 constructors or destructors. */
2213 expand_expr (build_modify_expr (decl
, INIT_EXPR
, init
),
2214 NULL_RTX
, VOIDmode
, 0);
2219 /* Hunts through the global anonymous union ANON_DECL, building
2220 appropriate VAR_DECLs. Stores cleanups on the list of ELEMS, and
2221 returns a VAR_DECL whose size is the same as the size of the
2222 ANON_DECL, if one is available. */
2225 build_anon_union_vars (anon_decl
, elems
, static_p
, external_p
)
2231 tree type
= TREE_TYPE (anon_decl
);
2232 tree main_decl
= NULL_TREE
;
2235 for (field
= TYPE_FIELDS (type
);
2237 field
= TREE_CHAIN (field
))
2240 if (TREE_CODE (field
) != FIELD_DECL
)
2243 if (TREE_PRIVATE (field
))
2244 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
2245 else if (TREE_PROTECTED (field
))
2246 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
2248 if (DECL_NAME (field
) == NULL_TREE
2249 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2251 decl
= build_anon_union_vars (field
, elems
, static_p
, external_p
);
2257 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2258 /* tell `pushdecl' that this is not tentative. */
2259 DECL_INITIAL (decl
) = error_mark_node
;
2260 TREE_PUBLIC (decl
) = 0;
2261 TREE_STATIC (decl
) = static_p
;
2262 DECL_EXTERNAL (decl
) = external_p
;
2263 decl
= pushdecl (decl
);
2264 DECL_INITIAL (decl
) = NULL_TREE
;
2267 /* Only write out one anon union element--choose the one that
2268 can hold them all. */
2269 if (main_decl
== NULL_TREE
2270 && simple_cst_equal (DECL_SIZE (decl
),
2271 DECL_SIZE (anon_decl
)) == 1)
2274 /* ??? This causes there to be no debug info written out
2276 TREE_ASM_WRITTEN (decl
) = 1;
2278 if (DECL_NAME (field
) == NULL_TREE
2279 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2280 /* The remainder of the processing was already done in the
2284 /* If there's a cleanup to do, it belongs in the
2285 TREE_PURPOSE of the following TREE_LIST. */
2286 *elems
= scratch_tree_cons (NULL_TREE
, decl
, *elems
);
2287 TREE_TYPE (*elems
) = type
;
2293 /* Finish off the processing of a UNION_TYPE structure.
2294 If there are static members, then all members are
2295 static, and must be laid out together. If the
2296 union is an anonymous union, we arrange for that
2297 as well. PUBLIC_P is nonzero if this union is
2298 not declared static. */
2301 finish_anon_union (anon_union_decl
)
2302 tree anon_union_decl
;
2304 tree type
= TREE_TYPE (anon_union_decl
);
2305 tree elems
= NULL_TREE
;
2307 int public_p
= TREE_PUBLIC (anon_union_decl
);
2308 int static_p
= TREE_STATIC (anon_union_decl
);
2309 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2311 if (TYPE_FIELDS (type
) == NULL_TREE
)
2316 error ("global anonymous unions must be declared static");
2320 main_decl
= build_anon_union_vars (anon_union_decl
, &elems
,
2321 static_p
, external_p
);
2327 make_decl_rtl (main_decl
, 0, toplevel_bindings_p ());
2328 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2332 warning ("anonymous union with no members");
2337 /* The following call assumes that there are never any cleanups
2338 for anonymous unions--a reasonable assumption. */
2339 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2342 /* Finish processing a builtin type TYPE. It's name is NAME,
2343 its fields are in the array FIELDS. LEN is the number of elements
2344 in FIELDS minus one, or put another way, it is the maximum subscript
2347 It is given the same alignment as ALIGN_TYPE. */
2350 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2359 TYPE_FIELDS (type
) = fields
[0];
2360 for (i
= 0; i
< len
; i
++)
2362 layout_type (TREE_TYPE (fields
[i
]));
2363 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2364 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2366 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2367 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2368 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2370 #if 0 /* not yet, should get fixed properly later */
2371 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2373 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2375 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
2376 layout_decl (TYPE_NAME (type
), 0);
2379 /* Auxiliary functions to make type signatures for
2380 `operator new' and `operator delete' correspond to
2381 what compiler will be expecting. */
2384 coerce_new_type (type
)
2389 if (TREE_CODE (type
) == METHOD_TYPE
)
2390 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2391 if (TREE_TYPE (type
) != ptr_type_node
)
2392 e1
= 1, error ("`operator new' must return type `void *'");
2394 /* Technically the type must be `size_t', but we may not know
2396 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2397 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2398 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type
))) != INTEGER_TYPE
2399 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type
))) != TYPE_PRECISION (sizetype
))
2400 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2402 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2404 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2409 coerce_delete_type (type
)
2416 tree arg_types
= TYPE_ARG_TYPES (type
);
2418 if (TREE_CODE (type
) == METHOD_TYPE
)
2420 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2421 arg_types
= TREE_CHAIN (arg_types
);
2424 if (TREE_TYPE (type
) != void_type_node
)
2425 e1
= 1, error ("`operator delete' must return type `void'");
2427 if (arg_types
== NULL_TREE
2428 || TREE_VALUE (arg_types
) != ptr_type_node
)
2429 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2433 && TREE_CHAIN (arg_types
)
2434 && TREE_CHAIN (arg_types
) != void_list_node
)
2436 /* Again, technically this argument must be `size_t', but again
2437 we may not know what that is. */
2438 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2439 if (TREE_CODE (t2
) != INTEGER_TYPE
2440 || TYPE_PRECISION (t2
) != TYPE_PRECISION (sizetype
))
2441 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2442 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2445 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2446 error ("too many arguments in declaration of `operator delete'");
2448 error ("`...' invalid in specification of `operator delete'");
2453 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2454 build_tree_list (NULL_TREE
, sizetype
));
2457 if (arg_types
== NULL_TREE
)
2458 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2460 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2466 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2467 arg_types
? TREE_CHAIN (arg_types
): NULL_TREE
);
2469 type
= build_function_type (void_type_node
, arg_types
);
2474 extern tree abort_fndecl
;
2477 mark_vtable_entries (decl
)
2480 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
2484 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (TREE_CHAIN (entries
))
2485 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2486 tree fn
= TREE_OPERAND (fnaddr
, 0);
2487 TREE_ADDRESSABLE (fn
) = 1;
2490 skip_rtti_stuff (&entries
);
2492 for (; entries
; entries
= TREE_CHAIN (entries
))
2494 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (entries
)
2495 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2496 tree fn
= TREE_OPERAND (fnaddr
, 0);
2497 TREE_ADDRESSABLE (fn
) = 1;
2498 if (DECL_LANG_SPECIFIC (fn
) && DECL_ABSTRACT_VIRTUAL_P (fn
))
2500 TREE_OPERAND (fnaddr
, 0) = fn
= copy_node (fn
);
2501 DECL_RTL (fn
) = DECL_RTL (abort_fndecl
);
2502 mark_used (abort_fndecl
);
2504 if (TREE_CODE (fn
) == THUNK_DECL
&& DECL_EXTERNAL (fn
))
2506 DECL_EXTERNAL (fn
) = 0;
2513 /* Set DECL up to have the closest approximation of "initialized common"
2514 linkage available. */
2517 comdat_linkage (decl
)
2521 make_decl_one_only (decl
);
2523 TREE_PUBLIC (decl
) = 0;
2525 if (DECL_LANG_SPECIFIC (decl
))
2526 DECL_COMDAT (decl
) = 1;
2529 /* For win32 we also want to put explicit instantiations in
2530 linkonce sections, so that they will be merged with implicit
2531 instantiations; otherwise we get duplicate symbol errors. */
2534 maybe_make_one_only (decl
)
2537 /* This is not necessary on targets that support weak symbols, because
2538 the implicit instantiations will defer to the explicit one. */
2539 if (! supports_one_only () || SUPPORTS_WEAK
)
2542 /* We can't set DECL_COMDAT on functions, or finish_file will think
2543 we can get away with not emitting them if they aren't used.
2544 We can't use make_decl_one_only for variables, because their
2545 DECL_INITIAL may not have been set properly yet. */
2547 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2548 make_decl_one_only (decl
);
2550 comdat_linkage (decl
);
2553 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2554 based on TYPE and other static flags.
2556 Note that anything public is tagged TREE_PUBLIC, whether
2557 it's public in this file or in another one. */
2560 import_export_vtable (decl
, type
, final
)
2564 if (DECL_INTERFACE_KNOWN (decl
))
2568 if (write_virtuals
< 0 || write_virtuals
== 1 || TYPE_FOR_JAVA (type
))
2570 TREE_PUBLIC (decl
) = 1;
2571 if (write_virtuals
< 0 || TYPE_FOR_JAVA (type
))
2572 DECL_EXTERNAL (decl
) = 1;
2573 DECL_INTERFACE_KNOWN (decl
) = 1;
2575 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2577 TREE_PUBLIC (decl
) = 1;
2578 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2579 DECL_INTERFACE_KNOWN (decl
) = 1;
2581 /* For WIN32 we also want to put explicit instantiations in
2582 linkonce sections. */
2583 if (CLASSTYPE_EXPLICIT_INSTANTIATION (type
))
2584 maybe_make_one_only (decl
);
2588 /* We can only wait to decide if we have real non-inline virtual
2589 functions in our class, or if we come from a template. */
2591 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2593 #ifndef MULTIPLE_SYMBOL_SPACES
2594 if (! found
&& ! final
)
2597 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
2598 method
= TREE_CHAIN (method
))
2599 if (DECL_VINDEX (method
) != NULL_TREE
2600 && ! DECL_THIS_INLINE (method
)
2601 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2609 if (final
|| ! found
)
2611 comdat_linkage (decl
);
2612 DECL_EXTERNAL (decl
) = 0;
2616 TREE_PUBLIC (decl
) = 1;
2617 DECL_EXTERNAL (decl
) = 1;
2622 /* Determine whether or not we want to specifically import or export CTYPE,
2623 using various heuristics. */
2626 import_export_class (ctype
)
2629 /* -1 for imported, 1 for exported. */
2630 int import_export
= 0;
2632 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2635 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2636 /* FIXME this should really use some sort of target-independent macro. */
2637 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype
)))
2639 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype
)))
2643 /* If we got -fno-implicit-templates, we import template classes that
2644 weren't explicitly instantiated. */
2645 if (import_export
== 0
2646 && CLASSTYPE_IMPLICIT_INSTANTIATION (ctype
)
2647 && ! flag_implicit_templates
)
2650 #ifndef MULTIPLE_SYMBOL_SPACES
2651 /* Base our import/export status on that of the first non-inline,
2652 non-abstract virtual function, if any. */
2653 if (import_export
== 0
2654 && TYPE_VIRTUAL_P (ctype
)
2655 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2658 for (method
= TYPE_METHODS (ctype
); method
!= NULL_TREE
;
2659 method
= TREE_CHAIN (method
))
2661 if (DECL_VINDEX (method
) != NULL_TREE
2662 && !DECL_THIS_INLINE (method
)
2663 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2665 import_export
= (DECL_REALLY_EXTERN (method
) ? -1 : 1);
2674 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2675 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
) = (import_export
> 0);
2676 CLASSTYPE_INTERFACE_ONLY (ctype
) = (import_export
< 0);
2681 finish_prevtable_vardecl (prev
, vars
)
2684 tree ctype
= DECL_CONTEXT (vars
);
2685 import_export_class (ctype
);
2686 import_export_vtable (vars
, ctype
, 1);
2691 finish_vtable_vardecl (prev
, vars
)
2694 if (write_virtuals
>= 0
2695 && ! DECL_EXTERNAL (vars
)
2696 && ((TREE_PUBLIC (vars
) && ! DECL_WEAK (vars
) && ! DECL_ONE_ONLY (vars
))
2697 || CLASSTYPE_EXPLICIT_INSTANTIATION (DECL_CONTEXT (vars
))
2698 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
))
2699 || (hack_decl_function_context (vars
) && TREE_USED (vars
)))
2700 && ! TREE_ASM_WRITTEN (vars
))
2703 mark_vtable_entries (vars
);
2704 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2705 store_init_value (vars
, DECL_INITIAL (vars
));
2707 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2709 /* Mark the VAR_DECL node representing the vtable itself as a
2710 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2711 It is rather important that such things be ignored because
2712 any effort to actually generate DWARF for them will run
2713 into trouble when/if we encounter code like:
2716 struct S { virtual void member (); };
2718 because the artificial declaration of the vtable itself (as
2719 manufactured by the g++ front end) will say that the vtable
2720 is a static member of `S' but only *after* the debug output
2721 for the definition of `S' has already been output. This causes
2722 grief because the DWARF entry for the definition of the vtable
2723 will try to refer back to an earlier *declaration* of the
2724 vtable as a static member of `S' and there won't be one.
2725 We might be able to arrange to have the "vtable static member"
2726 attached to the member list for `S' before the debug info for
2727 `S' get written (which would solve the problem) but that would
2728 require more intrusive changes to the g++ front end. */
2730 DECL_IGNORED_P (vars
) = 1;
2733 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2736 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
)))
2737 /* We don't know what to do with this one yet. */
2740 /* We know that PREV must be non-zero here. */
2741 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2746 prune_vtable_vardecl (prev
, vars
)
2749 /* We know that PREV must be non-zero here. */
2750 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2755 walk_vtables (typedecl_fn
, vardecl_fn
)
2756 register void (*typedecl_fn
) PROTO ((tree
, tree
));
2757 register int (*vardecl_fn
) PROTO ((tree
, tree
));
2762 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2764 register tree type
= TREE_TYPE (vars
);
2766 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2769 flag
|= (*vardecl_fn
) (prev
, vars
);
2771 if (prev
&& TREE_CHAIN (prev
) != vars
)
2774 else if (TREE_CODE (vars
) == TYPE_DECL
2775 && type
!= error_mark_node
2776 && TYPE_LANG_SPECIFIC (type
)
2777 && CLASSTYPE_VSIZE (type
))
2779 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2789 finish_sigtable_vardecl (prev
, vars
)
2792 /* We don't need to mark sigtable entries as addressable here as is done
2793 for vtables. Since sigtables, unlike vtables, are always written out,
2794 that was already done in build_signature_table_constructor. */
2796 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2798 /* We know that PREV must be non-zero here. */
2799 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2803 walk_sigtables (typedecl_fn
, vardecl_fn
)
2804 register void (*typedecl_fn
) PROTO((tree
, tree
));
2805 register void (*vardecl_fn
) PROTO((tree
, tree
));
2809 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2811 register tree type
= TREE_TYPE (vars
);
2813 if (TREE_CODE (vars
) == TYPE_DECL
2814 && type
!= error_mark_node
2815 && IS_SIGNATURE (type
))
2817 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2819 else if (TREE_CODE (vars
) == VAR_DECL
2820 && TREE_TYPE (vars
) != error_mark_node
2821 && IS_SIGNATURE (TREE_TYPE (vars
)))
2823 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2830 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2831 inline function or template instantiation at end-of-file. */
2834 import_export_decl (decl
)
2837 if (DECL_INTERFACE_KNOWN (decl
))
2840 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2842 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2843 if (DECL_IMPLICIT_INSTANTIATION (decl
)
2844 && (flag_implicit_templates
|| DECL_THIS_INLINE (decl
)))
2846 if (!TREE_PUBLIC (decl
))
2847 /* Templates are allowed to have internal linkage. See
2850 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2851 comdat_linkage (decl
);
2853 DECL_COMDAT (decl
) = 1;
2856 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2858 else if (DECL_FUNCTION_MEMBER_P (decl
))
2860 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2861 if (CLASSTYPE_INTERFACE_KNOWN (ctype
)
2862 && (! DECL_ARTIFICIAL (decl
) || DECL_VINDEX (decl
)))
2864 DECL_NOT_REALLY_EXTERN (decl
)
2865 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2866 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2869 comdat_linkage (decl
);
2871 /* tinfo function */
2872 else if (DECL_ARTIFICIAL (decl
) && DECL_MUTABLE_P (decl
))
2874 tree ctype
= TREE_TYPE (DECL_NAME (decl
));
2875 if (IS_AGGR_TYPE (ctype
) && CLASSTYPE_INTERFACE_KNOWN (ctype
)
2876 && TYPE_VIRTUAL_P (ctype
)
2877 /* If the type is a cv-qualified variant of a type, then we
2878 must emit the tinfo function in this translation unit
2879 since it will not be emitted when the vtable for the type
2880 is output (which is when the unqualified version is
2882 && ctype
== TYPE_MAIN_VARIANT (ctype
))
2884 DECL_NOT_REALLY_EXTERN (decl
)
2885 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2886 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2888 /* For WIN32 we also want to put explicit instantiations in
2889 linkonce sections. */
2890 if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype
))
2891 maybe_make_one_only (decl
);
2893 else if (TYPE_BUILT_IN (ctype
) && ctype
== TYPE_MAIN_VARIANT (ctype
))
2894 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2896 comdat_linkage (decl
);
2899 comdat_linkage (decl
);
2901 DECL_INTERFACE_KNOWN (decl
) = 1;
2905 build_cleanup (decl
)
2909 tree type
= TREE_TYPE (decl
);
2911 if (TREE_CODE (type
) == ARRAY_TYPE
)
2915 mark_addressable (decl
);
2916 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
2918 temp
= build_delete (TREE_TYPE (temp
), temp
,
2920 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2924 extern int parse_time
, varconst_time
;
2925 extern tree pending_templates
;
2926 extern tree maybe_templates
;
2932 tree sname
= get_id_2 ("__sn", base
);
2933 /* For struct X foo __attribute__((weak)), there is a counter
2934 __snfoo. Since base is already an assembler name, sname should
2935 be globally unique */
2936 tree sentry
= IDENTIFIER_GLOBAL_VALUE (sname
);
2939 push_obstacks_nochange ();
2940 end_temporary_allocation ();
2941 sentry
= build_decl (VAR_DECL
, sname
, integer_type_node
);
2942 TREE_PUBLIC (sentry
) = 1;
2943 DECL_ARTIFICIAL (sentry
) = 1;
2944 TREE_STATIC (sentry
) = 1;
2945 TREE_USED (sentry
) = 1;
2946 DECL_COMMON (sentry
) = 1;
2947 pushdecl_top_level (sentry
);
2948 cp_finish_decl (sentry
, NULL_TREE
, NULL_TREE
, 0, 0);
2954 /* A list of objects which have constructors or destructors
2955 which reside in the global scope. The decl is stored in
2956 the TREE_VALUE slot and the initializer is stored
2957 in the TREE_PURPOSE slot. */
2958 extern tree static_aggregates_initp
;
2960 /* Set up the static_aggregates* lists for processing. Subroutine of
2961 finish_file. Note that this function changes the format of
2962 static_aggregates_initp, from (priority . decl) to
2963 (priority . ((initializer . decl) ...)). */
2970 if (! flag_init_priority
)
2972 for (t
= static_aggregates_initp
; t
; t
= TREE_CHAIN (t
))
2973 cp_warning ("init_priority for `%#D' ignored without -finit-priority",
2978 /* First, remove any entries from static_aggregates that are also in
2979 static_aggregates_initp, and update the entries in _initp to
2980 include the initializer. */
2981 p
= &static_aggregates
;
2984 t
= value_member (TREE_VALUE (*p
), static_aggregates_initp
);
2988 TREE_VALUE (t
) = *p
;
2989 *p
= TREE_CHAIN (*p
);
2990 TREE_CHAIN (TREE_VALUE (t
)) = NULL_TREE
;
2993 p
= &TREE_CHAIN (*p
);
2996 /* Then, group static_aggregates_initp. After this step, there will only
2997 be one entry for each priority, with a chain coming off it. */
2998 t
= static_aggregates_initp
;
2999 static_aggregates_initp
= NULL_TREE
;
3001 for (; t
; t
= next_t
)
3003 next_t
= TREE_CHAIN (t
);
3005 for (p
= &static_aggregates_initp
; ; p
= &TREE_CHAIN (*p
))
3008 || tree_int_cst_lt (TREE_PURPOSE (*p
), TREE_PURPOSE (t
)))
3010 TREE_CHAIN (t
) = *p
;
3014 else if (tree_int_cst_equal (TREE_PURPOSE (*p
), TREE_PURPOSE (t
)))
3016 TREE_CHAIN (TREE_VALUE (t
)) = TREE_VALUE (*p
);
3017 TREE_VALUE (*p
) = TREE_VALUE (t
);
3023 /* Reverse each list to preserve the order (currently reverse declaration
3024 order, for destructors). */
3025 for (t
= static_aggregates_initp
; t
; t
= TREE_CHAIN (t
))
3026 TREE_VALUE (t
) = nreverse (TREE_VALUE (t
));
3029 /* Start the process of running a particular set of global constructors
3030 or destructors. Subroutine of do_[cd]tors. */
3033 start_objects (method_type
, initp
)
3034 int method_type
, initp
;
3039 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
3041 if (flag_init_priority
)
3044 initp
= DEFAULT_INIT_PRIORITY
;
3046 sprintf (type
, "%c%c%.5u", method_type
, JOINER
, initp
);
3049 sprintf (type
, "%c", method_type
);
3051 fnname
= get_file_function_name_long (type
);
3053 start_function (void_list_node
,
3054 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
3058 store_parm_decls ();
3062 expand_start_bindings (0);
3065 /* Finish the process of running a particular set of global constructors
3066 or destructors. Subroutine of do_[cd]tors. */
3069 finish_objects (method_type
, initp
)
3070 int method_type
, initp
;
3076 tree list
= (method_type
== 'I' ? static_ctors
: static_dtors
);
3078 if (! current_function_decl
&& list
)
3079 start_objects (method_type
, initp
);
3081 for (; list
; list
= TREE_CHAIN (list
))
3082 expand_expr_stmt (build_function_call (TREE_VALUE (list
), NULL_TREE
));
3085 if (! current_function_decl
)
3088 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
3091 expand_end_bindings (getdecls (), 1, 0);
3094 finish_function (lineno
, 0, 0);
3096 if (! flag_init_priority
)
3098 if (method_type
== 'I')
3099 assemble_constructor (fnname
);
3101 assemble_destructor (fnname
);
3104 #ifdef ASM_OUTPUT_SECTION_NAME
3105 /* If we're using init priority we can't use assemble_*tor, but on ELF
3106 targets we can stick the references into named sections for GNU ld
3108 if (flag_init_priority
)
3112 initp
= DEFAULT_INIT_PRIORITY
;
3113 sprintf (buf
, ".%ctors.%.5u", method_type
== 'I' ? 'c' : 'd',
3114 /* invert the numbering so the linker puts us in the proper
3115 order; constructors are run from right to left, and the
3116 linker sorts in increasing order. */
3117 MAX_INIT_PRIORITY
- initp
);
3118 named_section (NULL_TREE
, buf
, 0);
3119 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, fnname
),
3120 POINTER_SIZE
/ BITS_PER_UNIT
, 1);
3125 /* Generate a function to run a set of global destructors. START is either
3126 NULL_TREE or a node indicating a set of destructors with the same
3127 init priority. Subroutine of finish_file. */
3138 initp
= TREE_INT_CST_LOW (TREE_PURPOSE (start
));
3139 vars
= TREE_VALUE (start
);
3144 vars
= static_aggregates
;
3147 for (; vars
; vars
= TREE_CHAIN (vars
))
3149 tree decl
= TREE_VALUE (vars
);
3150 tree type
= TREE_TYPE (decl
);
3153 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
)
3154 && ! DECL_EXTERNAL (decl
))
3156 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
3157 || DECL_ONE_ONLY (decl
)
3158 || DECL_WEAK (decl
)));
3160 if (! current_function_decl
)
3161 start_objects ('D', initp
);
3167 Access control for implicit calls to the constructors,
3168 the conversion functions, or the destructor called to
3169 create and destroy a static data member is per- formed as
3170 if these calls appeared in the scope of the member's
3173 we must convince enforce_access to let us access the
3175 if (member_p (decl
))
3177 DECL_CLASS_CONTEXT (current_function_decl
)
3178 = DECL_CONTEXT (decl
);
3179 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3182 temp
= build_cleanup (decl
);
3186 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
3187 sentry
= build_unary_op (PREDECREMENT_EXPR
, sentry
, 0);
3188 sentry
= build_binary_op (EQ_EXPR
, sentry
, integer_zero_node
, 1);
3189 expand_start_cond (sentry
, 0);
3192 expand_expr_stmt (temp
);
3197 /* Now that we're done with DECL we don't need to pretend to
3198 be a member of its class any longer. */
3199 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3200 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3204 finish_objects ('D', initp
);
3207 /* Generate a function to run a set of global constructors. START is
3208 either NULL_TREE or a node indicating a set of constructors with the
3209 same init priority. Subroutine of finish_file. */
3220 initp
= TREE_INT_CST_LOW (TREE_PURPOSE (start
));
3221 vars
= TREE_VALUE (start
);
3226 vars
= static_aggregates
;
3229 /* Reverse the list so it's in the right order for ctors. */
3230 vars
= nreverse (vars
);
3232 for (; vars
; vars
= TREE_CHAIN (vars
))
3234 tree decl
= TREE_VALUE (vars
);
3235 tree init
= TREE_PURPOSE (vars
);
3237 /* If this was a static attribute within some function's scope,
3238 then don't initialize it here. Also, don't bother
3239 with initializers that contain errors. */
3240 if (TREE_STATIC (vars
)
3241 || DECL_EXTERNAL (decl
)
3242 || (init
&& TREE_CODE (init
) == TREE_LIST
3243 && value_member (error_mark_node
, init
)))
3246 if (TREE_CODE (decl
) == VAR_DECL
)
3248 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
3249 || DECL_ONE_ONLY (decl
)
3250 || DECL_WEAK (decl
)));
3252 if (! current_function_decl
)
3253 start_objects ('I', initp
);
3255 /* Set these global variables so that GDB at least puts
3256 us near the declaration which required the initialization. */
3257 input_filename
= DECL_SOURCE_FILE (decl
);
3258 lineno
= DECL_SOURCE_LINE (decl
);
3259 emit_note (input_filename
, lineno
);
3261 /* 9.5p5: The initializer of a static member of a class has
3262 the same access rights as a member function. */
3263 if (member_p (decl
))
3265 DECL_CLASS_CONTEXT (current_function_decl
)
3266 = DECL_CONTEXT (decl
);
3267 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3272 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
3273 sentry
= build_unary_op (PREINCREMENT_EXPR
, sentry
, 0);
3274 sentry
= build_binary_op
3275 (EQ_EXPR
, sentry
, integer_one_node
, 1);
3276 expand_start_cond (sentry
, 0);
3279 expand_start_target_temps ();
3281 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3282 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3283 expand_aggr_init (decl
, init
, 0, 0);
3284 else if (TREE_CODE (init
) == TREE_VEC
)
3286 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3287 TREE_VEC_ELT (init
, 1),
3288 TREE_VEC_ELT (init
, 2), 0),
3289 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3292 expand_assignment (decl
, init
, 0, 0);
3294 /* The expression might have involved increments and
3298 /* Cleanup any temporaries needed for the initial value. */
3299 expand_end_target_temps ();
3304 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3305 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3307 else if (decl
== error_mark_node
)
3310 my_friendly_abort (22);
3313 finish_objects ('I', initp
);
3316 /* This routine is called from the last rule in yyparse ().
3317 Its job is to create all the code needed to initialize and
3318 destroy the global aggregates. We do the destruction
3319 first, since that way we only need to reverse the decls once. */
3325 int start_time
, this_time
;
3329 int needs_cleaning
= 0, needs_messing_up
= 0;
3333 /* Bad parse errors. Just forget about it. */
3334 if (! global_bindings_p () || current_class_type
)
3337 check_decl_namespace ();
3339 start_time
= get_run_time ();
3341 /* Otherwise, GDB can get confused, because in only knows
3342 about source for LINENO-1 lines. */
3345 interface_unknown
= 1;
3348 for (fnname
= pending_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
3350 tree srcloc
= TREE_PURPOSE (fnname
);
3351 tree decl
= TREE_VALUE (fnname
);
3353 input_filename
= SRCLOC_FILE (srcloc
);
3354 lineno
= SRCLOC_LINE (srcloc
);
3356 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
3358 instantiate_class_template (decl
);
3359 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl
))
3360 for (vars
= TYPE_METHODS (decl
); vars
; vars
= TREE_CHAIN (vars
))
3361 if (! DECL_ARTIFICIAL (vars
))
3362 instantiate_decl (vars
);
3365 instantiate_decl (decl
);
3368 for (fnname
= maybe_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
3370 tree args
, fn
, decl
= TREE_VALUE (fnname
);
3372 if (DECL_INITIAL (decl
))
3375 fn
= TREE_PURPOSE (fnname
);
3376 args
= get_bindings (fn
, decl
, NULL_TREE
);
3377 fn
= instantiate_template (fn
, args
);
3378 instantiate_decl (fn
);
3381 cat_namespace_levels();
3383 /* Push into C language context, because that's all
3385 push_lang_context (lang_name_c
);
3388 /* The reason for pushing garbage onto the global_binding_level is to
3389 ensure that we can slice out _DECLs which pertain to virtual function
3390 tables. If the last thing pushed onto the global_binding_level was a
3391 virtual function table, then slicing it out would slice away all the
3392 decls (i.e., we lose the head of the chain).
3394 There are several ways of getting the same effect, from changing the
3395 way that iterators over the chain treat the elements that pertain to
3396 virtual function tables, moving the implementation of this code to
3397 decl.c (where we can manipulate global_binding_level directly),
3398 popping the garbage after pushing it and slicing away the vtable
3399 stuff, or just leaving it alone. */
3401 /* Make last thing in global scope not be a virtual function table. */
3402 #if 0 /* not yet, should get fixed properly later */
3403 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
3405 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
3407 DECL_IGNORED_P (vars
) = 1;
3408 SET_DECL_ARTIFICIAL (vars
);
3412 /* Walk to mark the inline functions we need, then output them so
3413 that we can pick up any other tdecls that those routines need. */
3414 walk_vtables ((void (*) PROTO ((tree
, tree
))) 0,
3415 finish_prevtable_vardecl
);
3417 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
3418 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars
)))
3419 rest_of_decl_compilation (TREE_VALUE (vars
), 0, 1, 1);
3420 vars
= static_aggregates
;
3422 if (static_ctors
|| vars
)
3423 needs_messing_up
= 1;
3424 if (static_dtors
|| vars
)
3429 /* After setup_initp, the aggregates are listed in reverse declaration
3430 order, for cleaning. */
3433 do_dtors (NULL_TREE
);
3435 if (flag_init_priority
)
3436 for (vars
= static_aggregates_initp
; vars
; vars
= TREE_CHAIN (vars
))
3440 /* do_ctors will reverse the lists for messing up. */
3441 if (needs_messing_up
)
3443 do_ctors (NULL_TREE
);
3445 if (flag_init_priority
)
3446 for (vars
= static_aggregates_initp
; vars
; vars
= TREE_CHAIN (vars
))
3450 permanent_allocation (1);
3452 /* Done with C language context needs. */
3453 pop_lang_context ();
3455 /* Now write out any static class variables (which may have since
3456 learned how to be initialized). */
3457 while (pending_statics
)
3459 tree decl
= TREE_VALUE (pending_statics
);
3461 /* Output DWARF debug information. */
3462 #ifdef DWARF_DEBUGGING_INFO
3463 if (write_symbols
== DWARF_DEBUG
)
3464 dwarfout_file_scope_decl (decl
, 1);
3466 #ifdef DWARF2_DEBUGGING_INFO
3467 if (write_symbols
== DWARF2_DEBUG
)
3468 dwarf2out_decl (decl
);
3471 DECL_DEFER_OUTPUT (decl
) = 0;
3472 rest_of_decl_compilation
3473 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3475 pending_statics
= TREE_CHAIN (pending_statics
);
3478 this_time
= get_run_time ();
3479 parse_time
-= this_time
- start_time
;
3480 varconst_time
+= this_time
- start_time
;
3482 start_time
= get_run_time ();
3484 if (flag_handle_signatures
)
3485 walk_sigtables ((void (*) PROTO ((tree
, tree
))) 0,
3486 finish_sigtable_vardecl
);
3488 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3490 tree decl
= TREE_VALUE (fnname
);
3491 import_export_decl (decl
);
3494 mark_all_runtime_matches ();
3496 /* Now write out inline functions which had their addresses taken and
3497 which were not declared virtual and which were not declared `extern
3500 int reconsider
= 1; /* More may be referenced; check again */
3504 tree
*p
= &saved_inlines
;
3507 /* We need to do this each time so that newly completed template
3508 types don't wind up at the front of the list. Sigh. */
3509 vars
= build_decl (TYPE_DECL
, make_anon_name (), integer_type_node
);
3510 DECL_IGNORED_P (vars
) = 1;
3511 SET_DECL_ARTIFICIAL (vars
);
3514 reconsider
|= walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3515 finish_vtable_vardecl
);
3519 tree decl
= TREE_VALUE (*p
);
3521 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3523 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
3525 if (DECL_MUTABLE_P (decl
))
3526 synthesize_tinfo_fn (decl
);
3528 synthesize_method (decl
);
3532 /* Catch new template instantiations. */
3533 if (decl
!= TREE_VALUE (*p
))
3536 if (TREE_ASM_WRITTEN (decl
)
3537 || (DECL_SAVED_INSNS (decl
) == 0 && ! DECL_ARTIFICIAL (decl
)))
3538 *p
= TREE_CHAIN (*p
);
3539 else if (DECL_INITIAL (decl
) == 0)
3540 p
= &TREE_CHAIN (*p
);
3541 else if ((TREE_PUBLIC (decl
) && ! DECL_COMDAT (decl
))
3542 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3543 || flag_keep_inline_functions
)
3545 if (DECL_NOT_REALLY_EXTERN (decl
))
3547 DECL_EXTERNAL (decl
) = 0;
3549 /* We can't inline this function after it's been
3550 emitted. We want a variant of
3551 output_inline_function that doesn't prevent
3552 subsequent integration... */
3553 DECL_INLINE (decl
) = 0;
3554 output_inline_function (decl
);
3555 permanent_allocation (1);
3558 *p
= TREE_CHAIN (*p
);
3561 p
= &TREE_CHAIN (*p
);
3565 /* It's possible that some of the remaining inlines will still be
3566 needed. For example, a static inline whose address is used in
3567 the initializer for a file-scope static variable will be
3568 needed. Code in compile_file will handle this, but we mustn't
3569 pretend that there are no definitions for the inlines, or it
3572 FIXME: This won't catch member functions. We should really
3573 unify this stuff with the compile_file stuff. */
3574 for (vars
= saved_inlines
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
3576 tree decl
= TREE_VALUE (vars
);
3578 if (DECL_NOT_REALLY_EXTERN (decl
)
3579 && !DECL_COMDAT (decl
)
3580 && DECL_INITIAL (decl
) != NULL_TREE
)
3581 DECL_EXTERNAL (decl
) = 0;
3585 /* Now delete from the chain of variables all virtual function tables.
3586 We output them all ourselves, because each will be treated specially. */
3588 walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3589 prune_vtable_vardecl
);
3591 if (write_virtuals
== 2)
3593 /* Now complain about an virtual function tables promised
3594 but not delivered. */
3595 while (pending_vtables
)
3597 if (TREE_PURPOSE (pending_vtables
) == NULL_TREE
)
3598 error ("virtual function table for `%s' not defined",
3599 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables
)));
3600 pending_vtables
= TREE_CHAIN (pending_vtables
);
3606 this_time
= get_run_time ();
3607 parse_time
-= this_time
- start_time
;
3608 varconst_time
+= this_time
- start_time
;
3610 if (flag_detailed_statistics
)
3612 dump_tree_statistics ();
3613 dump_time_statistics ();
3617 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3618 expr. Since it was parsed like a type, we need to wade through and fix
3619 that. Unfortunately, since operator() is left-associative, we can't use
3620 tail recursion. In the above example, TYPE is `A', and DECL is
3623 Maybe this shouldn't be recursive, but how often will it actually be
3627 reparse_absdcl_as_expr (type
, decl
)
3630 /* do build_functional_cast (type, NULL_TREE) at bottom */
3631 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3632 return build_functional_cast (type
, NULL_TREE
);
3635 decl
= reparse_decl_as_expr (type
, TREE_OPERAND (decl
, 0));
3637 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_ref
);
3639 if (TREE_CODE (decl
) == CALL_EXPR
&& TREE_TYPE (decl
) != void_type_node
)
3640 decl
= require_complete_type (decl
);
3645 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3646 out to be an expr. Since it was parsed like a type, we need to wade
3647 through and fix that. Since casts are right-associative, we are
3648 reversing the order, so we don't have to recurse.
3650 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3654 reparse_absdcl_as_casts (decl
, expr
)
3659 if (TREE_CODE (expr
) == CONSTRUCTOR
3660 && TREE_TYPE (expr
) == 0)
3662 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3663 decl
= TREE_OPERAND (decl
, 0);
3665 if (IS_SIGNATURE (type
))
3667 error ("cast specifies signature type");
3668 return error_mark_node
;
3671 expr
= digest_init (type
, expr
, (tree
*) 0);
3672 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3674 int failure
= complete_array_type (type
, expr
, 1);
3676 my_friendly_abort (78);
3682 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3683 decl
= TREE_OPERAND (decl
, 0);
3684 expr
= build_c_cast (type
, expr
);
3687 if (warn_old_style_cast
)
3688 warning ("use of old-style cast");
3693 /* Given plain tree nodes for an expression, build up the full semantics. */
3696 build_expr_from_tree (t
)
3699 if (t
== NULL_TREE
|| t
== error_mark_node
)
3702 switch (TREE_CODE (t
))
3704 case IDENTIFIER_NODE
:
3705 return do_identifier (t
, 0, NULL_TREE
);
3708 if (LOOKUP_EXPR_GLOBAL (t
))
3709 return do_scoped_id (TREE_OPERAND (t
, 0), 0);
3711 return do_identifier (TREE_OPERAND (t
, 0), 0, NULL_TREE
);
3713 case TEMPLATE_ID_EXPR
:
3714 return (lookup_template_function
3715 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3716 build_expr_from_tree (TREE_OPERAND (t
, 1))));
3719 return build_x_indirect_ref
3720 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3723 return build_functional_cast
3724 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3726 case REINTERPRET_CAST_EXPR
:
3727 return build_reinterpret_cast
3728 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3730 case CONST_CAST_EXPR
:
3731 return build_const_cast
3732 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3734 case DYNAMIC_CAST_EXPR
:
3735 return build_dynamic_cast
3736 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3738 case STATIC_CAST_EXPR
:
3739 return build_static_cast
3740 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3742 case PREDECREMENT_EXPR
:
3743 case PREINCREMENT_EXPR
:
3744 case POSTDECREMENT_EXPR
:
3745 case POSTINCREMENT_EXPR
:
3749 case TRUTH_NOT_EXPR
:
3751 case CONVERT_EXPR
: /* Unary + */
3754 return build_x_unary_op (TREE_CODE (t
),
3755 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3760 case TRUNC_DIV_EXPR
:
3762 case FLOOR_DIV_EXPR
:
3763 case ROUND_DIV_EXPR
:
3764 case EXACT_DIV_EXPR
:
3766 case BIT_ANDTC_EXPR
:
3769 case TRUNC_MOD_EXPR
:
3770 case FLOOR_MOD_EXPR
:
3771 case TRUTH_ANDIF_EXPR
:
3772 case TRUTH_ORIF_EXPR
:
3773 case TRUTH_AND_EXPR
:
3788 return build_x_binary_op
3790 build_expr_from_tree (TREE_OPERAND (t
, 0)),
3791 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3794 return build_m_component_ref
3795 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3796 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3799 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
3802 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
3804 return build_parse_node (ARRAY_REF
, NULL_TREE
,
3805 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3806 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3807 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3812 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3813 if (TREE_CODE_CLASS (TREE_CODE (r
)) != 't')
3815 return TREE_CODE (t
) == SIZEOF_EXPR
? c_sizeof (r
) : c_alignof (r
);
3819 return build_x_modify_expr
3820 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3821 TREE_CODE (TREE_OPERAND (t
, 1)),
3822 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3825 return build_x_arrow
3826 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3830 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3831 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3832 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3833 NEW_EXPR_USE_GLOBAL (t
));
3836 return delete_sanity
3837 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3838 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3839 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
3842 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
3843 return build_x_compound_expr
3844 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3846 my_friendly_abort (42);
3848 case METHOD_CALL_EXPR
:
3849 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3851 tree ref
= TREE_OPERAND (t
, 0);
3852 return build_scoped_method_call
3853 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3854 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3855 TREE_OPERAND (ref
, 1),
3856 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3858 return build_method_call
3859 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3860 TREE_OPERAND (t
, 0),
3861 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3862 NULL_TREE
, LOOKUP_NORMAL
);
3865 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3867 tree ref
= TREE_OPERAND (t
, 0);
3868 return build_member_call
3869 (build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3870 TREE_OPERAND (ref
, 1),
3871 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3875 tree name
= TREE_OPERAND (t
, 0);
3877 tree args
= build_expr_from_tree (TREE_OPERAND (t
, 1));
3878 if (args
!= NULL_TREE
&& TREE_CODE (name
) == LOOKUP_EXPR
3879 && !LOOKUP_EXPR_GLOBAL (name
)
3880 && TREE_CODE ((id
= TREE_OPERAND (name
, 0))) == IDENTIFIER_NODE
3881 && (!current_class_type
3882 || !lookup_member (current_class_type
, id
, 0, 0)))
3884 /* Do Koenig lookup if there are no class members. */
3885 name
= do_identifier (id
, 0, args
);
3887 else if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
3888 || ! really_overloaded_fn (name
))
3889 name
= build_expr_from_tree (name
);
3890 return build_x_function_call (name
, args
, current_class_ref
);
3894 return build_x_conditional_expr
3895 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3896 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3897 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3901 tree purpose
, value
, chain
;
3903 if (t
== void_list_node
)
3906 purpose
= TREE_PURPOSE (t
);
3908 purpose
= build_expr_from_tree (purpose
);
3909 value
= TREE_VALUE (t
);
3911 value
= build_expr_from_tree (value
);
3912 chain
= TREE_CHAIN (t
);
3913 if (chain
&& chain
!= void_type_node
)
3914 chain
= build_expr_from_tree (chain
);
3915 return expr_tree_cons (purpose
, value
, chain
);
3919 return build_x_component_ref
3920 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3921 TREE_OPERAND (t
, 1), NULL_TREE
, 1);
3924 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3930 /* digest_init will do the wrong thing if we let it. */
3931 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
3934 r
= build_nt (CONSTRUCTOR
, NULL_TREE
,
3935 build_expr_from_tree (CONSTRUCTOR_ELTS (t
)));
3938 return digest_init (TREE_TYPE (t
), r
, 0);
3943 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
3944 return get_typeid (TREE_OPERAND (t
, 0));
3945 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3948 return convert_from_reference (t
);
3955 /* This is something of the form `int (*a)++' that has turned out to be an
3956 expr. It was only converted into parse nodes, so we need to go through
3957 and build up the semantics. Most of the work is done by
3958 build_expr_from_tree, above.
3960 In the above example, TYPE is `int' and DECL is `*a'. */
3963 reparse_decl_as_expr (type
, decl
)
3966 decl
= build_expr_from_tree (decl
);
3968 return build_functional_cast (type
, build_expr_list (NULL_TREE
, decl
));
3973 /* This is something of the form `int (*a)' that has turned out to be a
3974 decl. It was only converted into parse nodes, so we need to do the
3975 checking that make_{pointer,reference}_declarator do. */
3978 finish_decl_parsing (decl
)
3981 extern int current_class_depth
;
3983 switch (TREE_CODE (decl
))
3985 case IDENTIFIER_NODE
:
3988 return make_pointer_declarator
3989 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3991 return make_reference_declarator
3992 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3994 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3997 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3998 TREE_COMPLEXITY (decl
) = current_class_depth
;
4001 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
4004 my_friendly_abort (5);
4010 check_cp_case_value (value
)
4013 if (value
== NULL_TREE
)
4016 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4017 STRIP_TYPE_NOPS (value
);
4019 if (TREE_READONLY_DECL_P (value
))
4021 value
= decl_constant_value (value
);
4022 STRIP_TYPE_NOPS (value
);
4024 value
= fold (value
);
4026 if (TREE_CODE (value
) != INTEGER_CST
4027 && value
!= error_mark_node
)
4029 cp_error ("case label `%E' does not reduce to an integer constant",
4031 value
= error_mark_node
;
4034 /* Promote char or short to int. */
4035 value
= default_conversion (value
);
4037 constant_expression_warning (value
);
4042 /* Return 1 if root encloses child. */
4045 is_namespace_ancestor (root
, child
)
4050 if (root
== global_namespace
)
4052 if (child
== global_namespace
)
4054 return is_namespace_ancestor (root
, CP_DECL_CONTEXT (child
));
4058 /* Return the namespace that is the common ancestor
4059 of two given namespaces. */
4062 namespace_ancestor (ns1
, ns2
)
4065 if (is_namespace_ancestor (ns1
, ns2
))
4067 return namespace_ancestor (CP_DECL_CONTEXT (ns1
), ns2
);
4070 /* Insert used into the using list of user. Set indirect_flag if this
4071 directive is not directly from the source. Also find the common
4072 ancestor and let our users know about the new namespace */
4074 add_using_namespace (user
, used
, indirect
)
4080 /* Using oneself is a no-op. */
4083 my_friendly_assert (TREE_CODE (user
) == NAMESPACE_DECL
, 380);
4084 my_friendly_assert (TREE_CODE (used
) == NAMESPACE_DECL
, 380);
4085 /* Check if we already have this. */
4086 t
= purpose_member (used
, DECL_NAMESPACE_USING (user
));
4090 /* Promote to direct usage. */
4091 TREE_INDIRECT_USING (t
) = 0;
4095 /* Add used to the user's using list. */
4096 DECL_NAMESPACE_USING (user
)
4097 = perm_tree_cons (used
, namespace_ancestor (user
, used
),
4098 DECL_NAMESPACE_USING (user
));
4100 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user
)) = indirect
;
4102 /* Add user to the used's users list. */
4103 DECL_NAMESPACE_USERS (used
)
4104 = perm_tree_cons (user
, 0, DECL_NAMESPACE_USERS (used
));
4106 /* Recursively add all namespaces used. */
4107 for (t
= DECL_NAMESPACE_USING (used
); t
; t
= TREE_CHAIN (t
))
4108 /* indirect usage */
4109 add_using_namespace (user
, TREE_PURPOSE (t
), 1);
4111 /* Tell everyone using us about the new used namespaces. */
4112 for (t
= DECL_NAMESPACE_USERS (user
); t
; t
= TREE_CHAIN (t
))
4113 add_using_namespace (TREE_PURPOSE (t
), used
, 1);
4116 /* Combines two sets of overloaded functions into an OVERLOAD chain.
4117 The first list becomes the tail of the result. */
4120 merge_functions (s1
, s2
)
4124 if (TREE_CODE (s2
) == OVERLOAD
)
4127 s1
= build_overload (OVL_FUNCTION (s2
), s1
);
4128 s2
= OVL_CHAIN (s2
);
4131 s1
= build_overload (s2
, s1
);
4135 /* This should return an error not all definitions define functions.
4136 It is not an error if we find two functions with exactly the
4137 same signature, only if these are selected in overload resolution.
4138 old is the current set of bindings, new the freshly-found binding.
4139 XXX Do we want to give *all* candidates in case of ambiguity?
4140 XXX In what way should I treat extern declarations?
4141 XXX I don't want to repeat the entire duplicate_decls here */
4144 ambiguous_decl (name
, old
, new, flags
)
4151 my_friendly_assert (old
!= NULL_TREE
, 393);
4152 /* Copy the value. */
4153 val
= BINDING_VALUE (new);
4155 switch (TREE_CODE (val
))
4158 /* If we expect types or namespaces, and not templates,
4159 or this is not a template class. */
4160 if (LOOKUP_QUALIFIERS_ONLY (flags
)
4161 && (!(flags
& LOOKUP_TEMPLATES_EXPECTED
)
4162 || !DECL_CLASS_TEMPLATE_P (val
)))
4166 if (LOOKUP_NAMESPACES_ONLY (flags
))
4169 case NAMESPACE_DECL
:
4170 if (LOOKUP_TYPES_ONLY (flags
))
4174 if (LOOKUP_QUALIFIERS_ONLY (flags
))
4178 if (!BINDING_VALUE (old
))
4179 BINDING_VALUE (old
) = val
;
4180 else if (val
&& val
!= BINDING_VALUE (old
))
4182 if (is_overloaded_fn (BINDING_VALUE (old
))
4183 && is_overloaded_fn (val
))
4185 BINDING_VALUE (old
) = merge_functions (BINDING_VALUE (old
),
4190 /* Some declarations are functions, some are not. */
4191 if (flags
& LOOKUP_COMPLAIN
)
4193 cp_error ("use of `%D' is ambiguous", name
);
4194 cp_error_at (" first declared as `%#D' here",
4195 BINDING_VALUE (old
));
4196 cp_error_at (" also declared as `%#D' here", val
);
4198 return error_mark_node
;
4201 /* ... and copy the type. */
4202 type
= BINDING_TYPE (new);
4203 if (LOOKUP_NAMESPACES_ONLY (flags
))
4205 if (!BINDING_TYPE (old
))
4206 BINDING_TYPE (old
) = type
;
4207 else if (type
&& BINDING_TYPE (old
) != type
)
4209 if (flags
& LOOKUP_COMPLAIN
)
4211 cp_error ("`%D' denotes an ambiguous type",name
);
4212 cp_error_at (" first type here", BINDING_TYPE (old
));
4213 cp_error_at (" other type here", type
);
4219 /* Add the bindings of name in used namespaces to val.
4220 The using list is defined by usings, and the lookup goes to scope.
4221 Returns zero on errors. */
4224 lookup_using_namespace (name
, val
, usings
, scope
, flags
)
4225 tree name
, val
, usings
, scope
;
4230 /* Iterate over all used namespaces in current, searching for using
4231 directives of scope. */
4232 for (iter
= usings
; iter
; iter
= TREE_CHAIN (iter
))
4233 if (TREE_VALUE (iter
) == scope
)
4235 val1
= binding_for_name (name
, TREE_PURPOSE (iter
));
4236 /* Resolve ambiguities. */
4237 val
= ambiguous_decl (name
, val
, val1
, flags
);
4239 return val
!= error_mark_node
;
4243 Excepts the name to lookup and its qualifying scope.
4244 Returns the name/type pair found into the CPLUS_BINDING result,
4248 qualified_lookup_using_namespace (name
, scope
, result
, flags
)
4254 /* Maintain a list of namespaces visited... */
4255 tree seen
= NULL_TREE
;
4256 /* ... and a list of namespace yet to see. */
4257 tree todo
= NULL_TREE
;
4259 while (scope
&& (result
!= error_mark_node
))
4261 seen
= temp_tree_cons (scope
, NULL_TREE
, seen
);
4262 result
= ambiguous_decl (name
, result
,
4263 binding_for_name (name
, scope
), flags
);
4264 if (!BINDING_VALUE (result
) && !BINDING_TYPE (result
))
4265 /* Consider using directives. */
4266 for (usings
= DECL_NAMESPACE_USING (scope
); usings
;
4267 usings
= TREE_CHAIN (usings
))
4268 /* If this was a real directive, and we have not seen it. */
4269 if (!TREE_INDIRECT_USING (usings
)
4270 && !purpose_member (TREE_PURPOSE (usings
), seen
))
4271 todo
= temp_tree_cons (TREE_PURPOSE (usings
), NULL_TREE
, todo
);
4274 scope
= TREE_PURPOSE (todo
);
4275 todo
= TREE_CHAIN (todo
);
4278 scope
= NULL_TREE
; /* If there never was a todo list. */
4280 return result
!= error_mark_node
;
4283 /* [namespace.memdef]/2 */
4285 /* Set the context of a declaration to scope. Complain if we are not
4289 set_decl_namespace (decl
, scope
)
4294 if (scope
== std_node
)
4295 scope
= global_namespace
;
4296 /* Get rid of namespace aliases. */
4297 scope
= ORIGINAL_NAMESPACE (scope
);
4299 if (!is_namespace_ancestor (current_namespace
, scope
))
4300 cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
4302 DECL_CONTEXT (decl
) = FROB_CONTEXT (scope
);
4303 if (scope
!= current_namespace
)
4305 /* See whether this has been declared in the namespace. */
4306 old
= namespace_binding (DECL_NAME (decl
), scope
);
4308 /* No old declaration at all. */
4310 if (!is_overloaded_fn (decl
))
4311 /* Don't compare non-function decls with decls_match here,
4312 since it can't check for the correct constness at this
4313 point. pushdecl will find those errors later. */
4315 /* Since decl is a function, old should contain a function decl. */
4316 if (!is_overloaded_fn (old
))
4318 for (; old
; old
= OVL_NEXT (old
))
4319 if (decls_match (decl
, OVL_CURRENT (old
)))
4325 cp_error ("`%D' should have been declared inside `%D'",
4329 /* Compute the namespace where a declaration is defined. */
4332 decl_namespace (decl
)
4335 while (DECL_CONTEXT (decl
))
4337 decl
= DECL_CONTEXT (decl
);
4338 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
4340 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
4341 decl
= TYPE_STUB_DECL (decl
);
4342 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd', 390);
4345 return global_namespace
;
4348 /* Return the namespace where the current declaration is declared. */
4351 current_decl_namespace ()
4354 /* If we have been pushed into a different namespace, use it. */
4355 if (decl_namespace_list
)
4356 return TREE_PURPOSE (decl_namespace_list
);
4358 if (current_class_type
)
4359 result
= decl_namespace (TYPE_STUB_DECL (current_class_type
));
4360 else if (current_function_decl
)
4361 result
= decl_namespace (current_function_decl
);
4363 result
= current_namespace
;
4367 /* Temporarily set the namespace for the current declaration. */
4370 push_decl_namespace (decl
)
4373 if (TREE_CODE (decl
) != NAMESPACE_DECL
)
4374 decl
= decl_namespace (decl
);
4375 decl_namespace_list
= tree_cons (decl
, NULL_TREE
, decl_namespace_list
);
4379 pop_decl_namespace ()
4381 decl_namespace_list
= TREE_CHAIN (decl_namespace_list
);
4385 check_decl_namespace ()
4387 my_friendly_assert (decl_namespace_list
== NULL_TREE
, 980711);
4390 /* [basic.lookup.koenig] */
4391 /* A non-zero return value in the functions below indicates an error.
4392 All nodes allocated in the procedure are on the scratch obstack. */
4402 static int arg_assoc
PROTO((struct arg_lookup
*, tree
));
4403 static int arg_assoc_args
PROTO((struct arg_lookup
*, tree
));
4405 /* Add a function to the lookup structure.
4406 Returns 1 on error. */
4409 add_function (k
, fn
)
4410 struct arg_lookup
*k
;
4413 if (ovl_member (fn
, k
->functions
))
4415 /* We must find only functions, or exactly one non-function. */
4416 if (k
->functions
&& is_overloaded_fn (k
->functions
)
4417 && is_overloaded_fn (fn
))
4418 k
->functions
= build_overload (fn
, k
->functions
);
4422 tree f1
= OVL_CURRENT (k
->functions
);
4424 if (is_overloaded_fn (f1
))
4426 fn
= f1
; f1
= f2
; f2
= fn
;
4428 cp_error_at ("`%D' is not a function,", f1
);
4429 cp_error_at (" conflict with `%D'", f2
);
4430 cp_error (" in call to `%D'", k
->name
);
4438 /* Add functions of a namespace to the lookup structure.
4439 Returns 1 on error. */
4442 arg_assoc_namespace (k
, scope
)
4443 struct arg_lookup
*k
;
4448 if (purpose_member (scope
, k
->namespaces
))
4450 k
->namespaces
= tree_cons (scope
, NULL_TREE
, k
->namespaces
);
4452 value
= namespace_binding (k
->name
, scope
);
4456 for (; value
; value
= OVL_NEXT (value
))
4457 if (add_function (k
, OVL_CURRENT (value
)))
4463 /* Adds everything associated with class to the lookup structure.
4464 Returns 1 on error. */
4467 arg_assoc_class (k
, type
)
4468 struct arg_lookup
* k
;
4471 tree list
, friends
, context
;
4474 if (purpose_member (type
, k
->classes
))
4476 k
->classes
= tree_cons (type
, NULL_TREE
, k
->classes
);
4478 context
= decl_namespace (TYPE_MAIN_DECL (type
));
4479 if (arg_assoc_namespace (k
, context
))
4482 /* Process baseclasses. */
4483 for (i
= 0; i
< CLASSTYPE_N_BASECLASSES (type
); i
++)
4484 if (arg_assoc_class (k
, TYPE_BINFO_BASETYPE (type
, i
)))
4487 /* Process friends. */
4488 for (list
= DECL_FRIENDLIST (TYPE_MAIN_DECL (type
)); list
;
4489 list
= TREE_CHAIN (list
))
4490 if (k
->name
== TREE_PURPOSE (list
))
4491 for (friends
= TREE_VALUE (list
); friends
;
4492 friends
= TREE_CHAIN (friends
))
4493 /* Only interested in global functions with potentially hidden
4494 (i.e. unqualified) declarations. */
4495 if (TREE_PURPOSE (list
) == error_mark_node
&& TREE_VALUE (list
)
4496 && decl_namespace (TREE_VALUE (list
)) == context
)
4497 if (add_function (k
, TREE_VALUE (list
)))
4500 /* Process template arguments. */
4501 if (CLASSTYPE_TEMPLATE_INFO (type
))
4503 list
= innermost_args (CLASSTYPE_TI_ARGS (type
));
4504 for (i
= 0; i
< TREE_VEC_LENGTH (list
); ++i
)
4505 arg_assoc (k
, TREE_VEC_ELT (list
, i
));
4511 /* Adds everything associated with a given type.
4512 Returns 1 on error. */
4515 arg_assoc_type (k
, type
)
4516 struct arg_lookup
*k
;
4519 switch (TREE_CODE (type
))
4529 if (TYPE_PTRMEMFUNC_P (type
))
4530 return arg_assoc_type (k
, TYPE_PTRMEMFUNC_FN_TYPE (type
));
4531 return arg_assoc_class (k
, type
);
4533 case REFERENCE_TYPE
:
4535 return arg_assoc_type (k
, TREE_TYPE (type
));
4538 return arg_assoc_namespace (k
, decl_namespace (TYPE_MAIN_DECL (type
)));
4540 /* Pointer to member: associate class type and value type. */
4541 if (arg_assoc_type (k
, TYPE_OFFSET_BASETYPE (type
)))
4543 return arg_assoc_type (k
, TREE_TYPE (type
));
4545 /* The basetype is referenced in the first arg type, so just
4548 /* Associate the parameter types. */
4549 if (arg_assoc_args (k
, TYPE_ARG_TYPES (type
)))
4551 /* Associate the return type. */
4552 return arg_assoc_type (k
, TREE_TYPE (type
));
4553 case TEMPLATE_TYPE_PARM
:
4556 if (type
== unknown_type_node
)
4558 /* else fall through */
4560 my_friendly_abort (390);
4565 /* Adds everything associated with arguments. Returns 1 on error. */
4568 arg_assoc_args (k
, args
)
4569 struct arg_lookup
* k
;
4572 for (; args
; args
= TREE_CHAIN (args
))
4573 if (arg_assoc (k
, TREE_VALUE (args
)))
4578 /* Adds everything associated with a given tree_node. Returns 1 on error. */
4582 struct arg_lookup
* k
;
4585 if (n
== error_mark_node
)
4588 if (TREE_CODE_CLASS (TREE_CODE (n
)) == 't')
4589 return arg_assoc_type (k
, n
);
4591 if (! type_unknown_p (n
))
4592 return arg_assoc_type (k
, TREE_TYPE (n
));
4594 if (TREE_CODE (n
) == ADDR_EXPR
)
4595 n
= TREE_OPERAND (n
, 0);
4596 while (TREE_CODE (n
) == TREE_LIST
)
4599 my_friendly_assert (TREE_CODE (n
) == OVERLOAD
, 980715);
4601 for (; n
; n
= TREE_CHAIN (n
))
4602 if (arg_assoc (k
, OVL_FUNCTION (n
)))
4608 /* Performs Koenig lookup depending on arguments, where fns
4609 are the functions found in normal lookup. */
4612 lookup_arg_dependent (name
, fns
, args
)
4617 struct arg_lookup k
;
4620 k
.namespaces
= NULL_TREE
;
4621 k
.classes
= NULL_TREE
;
4623 push_scratch_obstack ();
4624 arg_assoc_args (&k
, args
);
4629 /* Process a namespace-alias declaration. */
4632 do_namespace_alias (alias
, namespace)
4633 tree alias
, namespace;
4635 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4637 /* The parser did not find it, so it's not there. */
4638 cp_error ("unknown namespace `%D'", namespace);
4642 namespace = ORIGINAL_NAMESPACE (namespace);
4644 /* Build the alias. */
4645 alias
= build_lang_decl (NAMESPACE_DECL
, alias
, void_type_node
);
4646 DECL_NAMESPACE_ALIAS (alias
) = namespace;
4650 /* Check a non-member using-declaration. Return the name and scope
4651 being used, and the USING_DECL, or NULL_TREE on failure. */
4654 validate_nonmember_using_decl (decl
, scope
, name
)
4659 if (TREE_CODE (decl
) == SCOPE_REF
4660 && TREE_OPERAND (decl
, 0) == std_node
)
4662 if (TREE_CODE (decl
) == SCOPE_REF
)
4664 *scope
= TREE_OPERAND (decl
, 0);
4665 *name
= TREE_OPERAND (decl
, 1);
4667 else if (TREE_CODE (decl
) == IDENTIFIER_NODE
4668 || TREE_CODE (decl
) == TYPE_DECL
)
4670 *scope
= global_namespace
;
4674 my_friendly_abort (382);
4675 if (TREE_CODE_CLASS (TREE_CODE (*name
)) == 'd')
4676 *name
= DECL_NAME (*name
);
4677 /* Make a USING_DECL. */
4678 return push_using_decl (*scope
, *name
);
4681 /* Process local and global using-declarations. */
4684 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, newval
, newtype
)
4686 tree oldval
, oldtype
;
4687 tree
*newval
, *newtype
;
4690 struct tree_binding _decls
;
4692 *newval
= *newtype
= NULL_TREE
;
4693 decls
= binding_init (&_decls
);
4694 if (!qualified_lookup_using_namespace (name
, scope
, decls
, 0))
4698 if (!BINDING_VALUE (decls
) && !BINDING_TYPE (decls
))
4700 cp_error ("`%D' not declared", name
);
4704 /* Check for using functions. */
4705 if (BINDING_VALUE (decls
) && is_overloaded_fn (BINDING_VALUE (decls
)))
4709 if (oldval
&& !is_overloaded_fn (oldval
))
4711 duplicate_decls (OVL_CURRENT (BINDING_VALUE (decls
)), oldval
);
4716 for (tmp
= BINDING_VALUE (decls
); tmp
; tmp
= OVL_NEXT (tmp
))
4718 /* Compare each new function with each old one.
4719 If the old function was also used, there is no conflict. */
4720 for (tmp1
= oldval
; tmp1
; tmp1
= OVL_NEXT (tmp1
))
4721 if (OVL_CURRENT (tmp
) == OVL_CURRENT (tmp1
))
4723 else if (OVL_USED (tmp1
))
4725 else if (duplicate_decls (OVL_CURRENT (tmp
), OVL_CURRENT (tmp1
)))
4728 /* Duplicate use, ignore */
4732 *newval
= build_overload (OVL_CURRENT (tmp
), *newval
);
4733 if (TREE_CODE (*newval
) != OVERLOAD
)
4734 *newval
= ovl_cons (*newval
, NULL_TREE
);
4735 OVL_USED (*newval
) = 1;
4740 *newval
= BINDING_VALUE (decls
);
4742 duplicate_decls (*newval
, oldval
);
4745 *newtype
= BINDING_TYPE (decls
);
4746 if (oldtype
&& *newtype
&& oldtype
!= *newtype
)
4748 cp_error ("using directive `%D' introduced ambiguous type `%T'",
4754 /* Process a using-declaration not appearing in class or local scope. */
4757 do_toplevel_using_decl (decl
)
4760 tree scope
, name
, binding
;
4761 tree oldval
, oldtype
, newval
, newtype
;
4763 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
4764 if (decl
== NULL_TREE
)
4767 binding
= binding_for_name (name
, current_namespace
);
4769 oldval
= BINDING_VALUE (binding
);
4770 oldtype
= BINDING_TYPE (binding
);
4772 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
4774 /* Copy declarations found. */
4776 BINDING_VALUE (binding
) = newval
;
4778 BINDING_TYPE (binding
) = newtype
;
4782 /* Process a using-declaration at function scope. */
4785 do_local_using_decl (decl
)
4789 tree oldval
, oldtype
, newval
, newtype
;
4791 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
4792 if (decl
== NULL_TREE
)
4795 oldval
= lookup_name_current_level (name
);
4796 oldtype
= lookup_type_current_level (name
);
4798 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
4801 set_identifier_local_value (name
, newval
);
4803 set_identifier_type_value (name
, newtype
);
4807 do_class_using_decl (decl
)
4812 if (TREE_CODE (decl
) != SCOPE_REF
4813 || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (decl
, 0))) != 't')
4815 cp_error ("using-declaration for non-member at class scope");
4818 name
= TREE_OPERAND (decl
, 1);
4819 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
4821 cp_error ("using-declaration for destructor");
4824 if (TREE_CODE (name
) == TYPE_DECL
)
4825 name
= DECL_NAME (name
);
4827 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 980716);
4829 value
= build_lang_field_decl (USING_DECL
, name
, void_type_node
);
4830 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
4834 /* Process a using-directive. */
4837 do_using_directive (namespace)
4840 if (namespace == std_node
)
4842 /* using namespace A::B::C; */
4843 if (TREE_CODE (namespace) == SCOPE_REF
)
4844 namespace = TREE_OPERAND (namespace, 1);
4845 if (TREE_CODE (namespace) == IDENTIFIER_NODE
)
4847 /* Lookup in lexer did not find a namespace. */
4848 cp_error ("namespace `%T' undeclared", namespace);
4851 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4853 cp_error ("`%T' is not a namespace", namespace);
4856 namespace = ORIGINAL_NAMESPACE (namespace);
4857 if (!toplevel_bindings_p ())
4858 push_using_directive (namespace);
4861 add_using_namespace (current_namespace
, namespace, 0);
4865 check_default_args (x
)
4868 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
4869 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
4870 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
4872 if (TREE_PURPOSE (arg
))
4876 cp_error_at ("default argument missing for parameter %P of `%+#D'",
4887 TREE_USED (decl
) = 1;
4888 if (processing_template_decl
)
4890 assemble_external (decl
);
4892 /* Is it a synthesized method that needs to be synthesized? */
4893 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CLASS_CONTEXT (decl
)
4894 && DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
4895 /* Kludge: don't synthesize for default args. */
4896 && current_function_decl
)
4897 synthesize_method (decl
);
4899 /* If this is a function or variable that is an instance of some
4900 template, we now know that we will need to actually do the
4901 instantiation. A TEMPLATE_DECL may also have DECL_TEMPLATE_INFO,
4902 if it's a partial instantiation, but there's no need to
4903 instantiate such a thing. */
4904 if (TREE_CODE (decl
) != TEMPLATE_DECL
4905 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
))
4906 instantiate_decl (decl
);
4909 /* Helper function for named_class_head_sans_basetype nonterminal. */
4912 handle_class_head (aggr
, scope
, id
)
4913 tree aggr
, scope
, id
;
4915 if (TREE_CODE (id
) == TYPE_DECL
)
4919 cp_error ("`%T' does not have a nested type named `%D'", scope
, id
);
4921 cp_error ("no file-scope type named `%D'", id
);
4924 (aggr
, make_anon_name (), NULL_TREE
, 1);
4925 return TYPE_MAIN_DECL (id
);