1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Process declarations and symbol lookup for C front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
43 #include "dwarf2out.h"
48 extern cpp_reader parse_in
;
49 extern cpp_options parse_options
;
50 static int cpp_initialized
;
53 static tree get_sentry
PROTO((tree
));
54 static void mark_vtable_entries
PROTO((tree
));
55 static void import_export_template
PROTO((tree
));
56 static void grok_function_init
PROTO((tree
, tree
));
57 static int finish_vtable_vardecl
PROTO((tree
, tree
));
58 static int prune_vtable_vardecl
PROTO((tree
, tree
));
59 static void finish_sigtable_vardecl
PROTO((tree
, tree
));
60 static int is_namespace_ancestor
PROTO((tree
, tree
));
61 static tree namespace_ancestor
PROTO((tree
, tree
));
62 static void add_using_namespace
PROTO((tree
, tree
, int));
63 static tree ambiguous_decl
PROTO((tree
, tree
, tree
));
64 static tree build_anon_union_vars
PROTO((tree
, tree
*, int, int));
66 extern int current_class_depth
;
68 /* A list of virtual function tables we must make sure to write out. */
71 /* A list of static class variables. This is needed, because a
72 static class variable can be declared inside the class without
73 an initializer, and then initialized, staticly, outside the class. */
76 /* A list of functions which were declared inline, but which we
77 may need to emit outline anyway. */
78 static tree saved_inlines
;
80 /* Used to help generate temporary names which are unique within
81 a function. Reset to 0 by start_function. */
83 int temp_name_counter
;
85 /* Same, but not reset. Local temp variables and global temp variables
86 can have the same name. */
87 static int global_temp_name_counter
;
89 /* Flag used when debugging spew.c */
91 extern int spew_debug
;
93 /* Nonzero if we're done parsing and into end-of-file activities. */
97 /* Functions called along with real static constructors and destructors. */
99 tree static_ctors
, static_dtors
;
101 /* The current open namespace, and ::. */
103 tree current_namespace
;
104 tree global_namespace
;
106 /* The stack for namespaces of current declarations. */
108 static tree decl_namespace_list
;
111 /* C (and C++) language-specific option variables. */
113 /* Nonzero means allow type mismatches in conditional expressions;
114 just make their values `void'. */
116 int flag_cond_mismatch
;
118 /* Nonzero means give `double' the same size as `float'. */
120 int flag_short_double
;
122 /* Nonzero means don't recognize the keyword `asm'. */
126 /* Nonzero means don't recognize any extension keywords. */
128 int flag_no_gnu_keywords
;
130 /* Nonzero means don't recognize the non-ANSI builtin functions. */
134 /* Nonzero means don't recognize the non-ANSI builtin functions.
137 int flag_no_nonansi_builtin
;
139 /* Nonzero means do some things the same way PCC does. Only provided so
140 the compiler will link. */
142 int flag_traditional
;
144 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
146 int flag_signed_bitfields
= 1;
148 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
152 /* Nonzero means enable obscure ANSI features and disable GNU extensions
153 that might cause ANSI-compliant code to be miscompiled. */
157 /* Nonzero means do emit exported implementations of functions even if
158 they can be inlined. */
160 int flag_implement_inlines
= 1;
162 /* Nonzero means do emit exported implementations of templates, instead of
163 multiple static copies in each file that needs a definition. */
165 int flag_external_templates
;
167 /* Nonzero means that the decision to emit or not emit the implementation of a
168 template depends on where the template is instantiated, rather than where
171 int flag_alt_external_templates
;
173 /* Nonzero means that implicit instantiations will be emitted if needed. */
175 int flag_implicit_templates
= 1;
177 /* Nonzero means warn about implicit declarations. */
179 int warn_implicit
= 1;
181 /* Nonzero means warn when all ctors or dtors are private, and the class
184 int warn_ctor_dtor_privacy
= 1;
186 /* True if we want to implement vtables using "thunks".
187 The default is off. */
189 #ifndef DEFAULT_VTABLE_THUNKS
190 #define DEFAULT_VTABLE_THUNKS 0
192 int flag_vtable_thunks
= DEFAULT_VTABLE_THUNKS
;
194 /* True if we want to deal with repository information. */
196 int flag_use_repository
;
198 /* Nonzero means give string constants the type `const char *'
199 to get extra warnings from them. These warnings will be too numerous
200 to be useful, except in thoroughly ANSIfied programs. */
202 int warn_write_strings
;
204 /* Nonzero means warn about pointer casts that can drop a type qualifier
205 from the pointer target type. */
209 /* Nonzero means warn that dbx info for template class methods isn't fully
212 int warn_template_debugging
;
214 /* Nonzero means warn about sizeof(function) or addition/subtraction
215 of function pointers. */
217 int warn_pointer_arith
= 1;
219 /* Nonzero means warn for any function def without prototype decl. */
221 int warn_missing_prototypes
;
223 /* Nonzero means warn about multiple (redundant) decls for the same single
224 variable or function. */
226 int warn_redundant_decls
;
228 /* Warn if initializer is not completely bracketed. */
230 int warn_missing_braces
;
232 /* Warn about comparison of signed and unsigned values. */
234 int warn_sign_compare
;
236 /* Warn about *printf or *scanf format/argument anomalies. */
240 /* Warn about a subscript that has type char. */
242 int warn_char_subscripts
;
244 /* Warn if a type conversion is done that might have confusing results. */
248 /* Warn if adding () is suggested. */
250 int warn_parentheses
;
252 /* Non-zero means warn in function declared in derived class has the
253 same name as a virtual in the base class, but fails to match the
254 type signature of any virtual function in the base class. */
255 int warn_overloaded_virtual
;
257 /* Non-zero means warn when declaring a class that has a non virtual
258 destructor, when it really ought to have a virtual one. */
261 /* Non-zero means warn when a function is declared extern and later inline. */
262 int warn_extern_inline
;
264 /* Non-zero means warn when the compiler will reorder code. */
267 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
270 /* Non-zero means warn when we convert a pointer to member function
271 into a pointer to (void or function). */
272 int warn_pmf2ptr
= 1;
274 /* Nonzero means warn about violation of some Effective C++ style rules. */
278 /* Nonzero means warn where overload resolution chooses a promotion from
279 unsigned to signed over a conversion to an unsigned of the same size. */
283 /* Nonzero means warn when an old-style cast is used. */
285 int warn_old_style_cast
;
287 /* Warn about #pragma directives that are not recognised. */
289 int warn_unknown_pragmas
= 0; /* Tri state variable. */
291 /* Nonzero means `$' can be in an identifier. */
293 #ifndef DOLLARS_IN_IDENTIFIERS
294 #define DOLLARS_IN_IDENTIFIERS 1
296 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
298 /* Nonzero for -fno-strict-prototype switch: do not consider empty
299 argument prototype to mean function takes no arguments. */
301 int flag_strict_prototype
= 2;
302 int strict_prototype
= 1;
303 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
305 /* Nonzero means that labels can be used as first-class objects */
309 /* Non-zero means to collect statistics which might be expensive
310 and to print them when we are done. */
311 int flag_detailed_statistics
;
313 /* C++ specific flags. */
314 /* Nonzero for -fall-virtual: make every member function (except
315 constructors) lay down in the virtual function table. Calls
316 can then either go through the virtual function table or not,
319 int flag_all_virtual
;
321 /* Zero means that `this' is a *const. This gives nice behavior in the
322 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
323 -2 means we're constructing an object and it has fixed type. */
325 int flag_this_is_variable
;
327 /* Nonzero means memoize our member lookups. */
329 int flag_memoize_lookups
; int flag_save_memoized_contexts
;
331 /* 3 means write out only virtuals function tables `defined'
332 in this implementation file.
333 2 means write out only specific virtual function tables
334 and give them (C) public access.
335 1 means write out virtual function tables and give them
337 0 means write out virtual function tables and give them
338 (C) static access (default).
339 -1 means declare virtual function tables extern. */
343 /* Nonzero means we should attempt to elide constructors when possible.
344 FIXME: This flag is obsolete, and should be torn out along with the
345 old overloading code. */
347 int flag_elide_constructors
;
349 /* Nonzero means recognize and handle signature language constructs. */
351 int flag_handle_signatures
;
353 /* Nonzero means that member functions defined in class scope are
354 inline by default. */
356 int flag_default_inline
= 1;
358 /* Controls whether enums and ints freely convert.
359 1 means with complete freedom.
360 0 means enums can convert to ints, but not vice-versa. */
361 int flag_int_enum_equivalence
;
363 /* Controls whether compiler generates 'type descriptor' that give
364 run-time type information. */
367 /* Nonzero if we wish to output cross-referencing information
368 for the GNU class browser. */
369 extern int flag_gnu_xref
;
371 /* Nonzero if compiler can make `reasonable' assumptions about
372 references and objects. For example, the compiler must be
373 conservative about the following and not assume that `a' is nonnull:
378 In general, it is `reasonable' to assume that for many programs,
379 and better code can be generated in that case. */
381 int flag_assume_nonnull_objects
= 1;
383 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
386 int flag_huge_objects
;
388 /* Nonzero if we want to conserve space in the .o files. We do this
389 by putting uninitialized data and runtime initialized data into
390 .common instead of .data at the expense of not flagging multiple
393 int flag_conserve_space
;
395 /* Nonzero if we want to obey access control semantics. */
397 int flag_access_control
= 1;
399 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
401 int flag_operator_names
;
403 /* Nonzero if we want to check the return value of new and avoid calling
404 constructors if it is a null pointer. */
408 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
409 initialization variables.
410 0: Old rules, set by -fno-for-scope.
411 2: New ANSI rules, set by -ffor-scope.
412 1: Try to implement new ANSI rules, but with backup compatibility
413 (and warnings). This is the default, for now. */
415 int flag_new_for_scope
= 1;
417 /* Nonzero if we want to emit defined symbols with common-like linkage as
418 weak symbols where possible, in order to conform to C++ semantics.
419 Otherwise, emit them as local symbols. */
423 /* Nonzero to enable experimental ABI changes. */
427 /* Nonzero to not ignore namespace std. */
431 /* Maximum template instantiation depth. Must be at least 17 for ANSI
434 int max_tinst_depth
= 17;
436 /* The name-mangling scheme to use. Must be 1 or greater to support
437 template functions with identical types, but different template
439 int name_mangling_version
= 2;
441 /* Nonzero means that guiding declarations are allowed. */
442 int flag_guiding_decls
;
444 /* Nonzero if squashed mangling is to be performed.
445 This uses the B and K codes to reference previously seen class types
446 and class qualifiers. */
447 int flag_do_squangling
;
450 /* Table of language-dependent -f options.
451 STRING is the option name. VARIABLE is the address of the variable.
452 ON_VALUE is the value to store in VARIABLE
453 if `-fSTRING' is seen as an option.
454 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
456 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
458 {"signed-char", &flag_signed_char
, 1},
459 {"unsigned-char", &flag_signed_char
, 0},
460 {"signed-bitfields", &flag_signed_bitfields
, 1},
461 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
462 {"short-enums", &flag_short_enums
, 1},
463 {"short-double", &flag_short_double
, 1},
464 {"cond-mismatch", &flag_cond_mismatch
, 1},
465 {"squangle", &flag_do_squangling
, 1},
466 {"asm", &flag_no_asm
, 0},
467 {"builtin", &flag_no_builtin
, 0},
468 {"ident", &flag_no_ident
, 0},
469 {"labels-ok", &flag_labels_ok
, 1},
470 {"stats", &flag_detailed_statistics
, 1},
471 {"this-is-variable", &flag_this_is_variable
, 1},
472 {"strict-prototype", &flag_strict_prototype
, 1},
473 {"all-virtual", &flag_all_virtual
, 1},
474 {"memoize-lookups", &flag_memoize_lookups
, 1},
475 {"elide-constructors", &flag_elide_constructors
, 1},
476 {"handle-exceptions", &flag_exceptions
, 1},
477 {"handle-signatures", &flag_handle_signatures
, 1},
478 {"default-inline", &flag_default_inline
, 1},
479 {"dollars-in-identifiers", &dollars_in_ident
, 1},
480 {"enum-int-equiv", &flag_int_enum_equivalence
, 1},
481 {"honor-std", &flag_honor_std
, 1},
482 {"rtti", &flag_rtti
, 1},
483 {"xref", &flag_gnu_xref
, 1},
484 {"nonnull-objects", &flag_assume_nonnull_objects
, 1},
485 {"implement-inlines", &flag_implement_inlines
, 1},
486 {"external-templates", &flag_external_templates
, 1},
487 {"implicit-templates", &flag_implicit_templates
, 1},
488 {"huge-objects", &flag_huge_objects
, 1},
489 {"conserve-space", &flag_conserve_space
, 1},
490 {"vtable-thunks", &flag_vtable_thunks
, 1},
491 {"access-control", &flag_access_control
, 1},
492 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
493 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
494 {"operator-names", &flag_operator_names
, 1},
495 {"check-new", &flag_check_new
, 1},
496 {"repo", &flag_use_repository
, 1},
497 {"for-scope", &flag_new_for_scope
, 2},
498 {"weak", &flag_weak
, 1}
501 /* Decode the string P as a language-specific option.
502 Return the number of strings consumed for a valid option.
503 Otherwise return 0. */
506 lang_decode_option (argc
, argv
)
511 int strings_processed
;
514 if (! cpp_initialized
)
516 cpp_reader_init (&parse_in
);
517 parse_in
.data
= &parse_options
;
518 cpp_options_init (&parse_options
);
521 strings_processed
= cpp_handle_option (&parse_in
, argc
, argv
);
523 strings_processed
= 0;
524 #endif /* ! USE_CPPLIB */
526 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
527 flag_writable_strings
= 1,
528 flag_this_is_variable
= 1, flag_new_for_scope
= 0;
529 /* The +e options are for cfront compatibility. They come in as
530 `-+eN', to kludge around gcc.c's argument handling. */
531 else if (p
[0] == '-' && p
[1] == '+' && p
[2] == 'e')
533 int old_write_virtuals
= write_virtuals
;
536 else if (p
[3] == '0')
538 else if (p
[3] == '2')
540 else error ("invalid +e option");
541 if (old_write_virtuals
!= 0
542 && write_virtuals
!= old_write_virtuals
)
543 error ("conflicting +e options given");
545 else if (p
[0] == '-' && p
[1] == 'f')
547 /* Some kind of -f option.
548 P's value is the option sans `-f'.
549 Search for it in the table of options. */
554 /* Try special -f options. */
556 if (!strcmp (p
, "handle-exceptions")
557 || !strcmp (p
, "no-handle-exceptions"))
558 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
560 if (!strcmp (p
, "save-memoized"))
562 flag_memoize_lookups
= 1;
563 flag_save_memoized_contexts
= 1;
566 else if (!strcmp (p
, "no-save-memoized"))
568 flag_memoize_lookups
= 0;
569 flag_save_memoized_contexts
= 0;
572 else if (! strcmp (p
, "alt-external-templates"))
574 flag_external_templates
= 1;
575 flag_alt_external_templates
= 1;
578 else if (! strcmp (p
, "no-alt-external-templates"))
580 flag_alt_external_templates
= 0;
583 else if (!strcmp (p
, "repo"))
585 flag_use_repository
= 1;
586 flag_implicit_templates
= 0;
589 else if (!strcmp (p
, "guiding-decls"))
591 flag_guiding_decls
= 1;
592 name_mangling_version
= 0;
595 else if (!strcmp (p
, "no-guiding-decls"))
597 flag_guiding_decls
= 0;
600 else if (!strcmp (p
, "ansi-overloading"))
602 else if (!strcmp (p
, "no-ansi-overloading"))
604 error ("-fno-ansi-overloading is no longer supported");
607 else if (!strcmp (p
, "new-abi"))
610 flag_do_squangling
= 1;
612 flag_vtable_thunks
= 1;
614 else if (!strcmp (p
, "no-new-abi"))
617 flag_do_squangling
= 0;
620 else if (!strncmp (p
, "template-depth-", 15))
625 if (*endp
>= '0' && *endp
<= '9')
629 error ("Invalid option `%s'", p
- 2);
630 goto template_depth_lose
;
633 max_tinst_depth
= atoi (p
+ 15);
634 template_depth_lose
: ;
636 else if (!strncmp (p
, "name-mangling-version-", 22))
641 if (*endp
>= '0' && *endp
<= '9')
645 error ("Invalid option `%s'", p
- 2);
646 goto mangling_version_lose
;
649 name_mangling_version
= atoi (p
+ 22);
650 mangling_version_lose
: ;
653 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
656 if (!strcmp (p
, lang_f_options
[j
].string
))
658 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
659 /* A goto here would be cleaner,
660 but breaks the vax pcc. */
663 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
664 && ! strcmp (p
+3, lang_f_options
[j
].string
))
666 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
672 else if (p
[0] == '-' && p
[1] == 'W')
676 /* The -W options control the warning behavior of the compiler. */
679 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
682 if (!strcmp (p
, "implicit"))
683 warn_implicit
= setting
;
684 else if (!strcmp (p
, "return-type"))
685 warn_return_type
= setting
;
686 else if (!strcmp (p
, "ctor-dtor-privacy"))
687 warn_ctor_dtor_privacy
= setting
;
688 else if (!strcmp (p
, "write-strings"))
689 warn_write_strings
= setting
;
690 else if (!strcmp (p
, "cast-qual"))
691 warn_cast_qual
= setting
;
692 else if (!strcmp (p
, "char-subscripts"))
693 warn_char_subscripts
= setting
;
694 else if (!strcmp (p
, "pointer-arith"))
695 warn_pointer_arith
= setting
;
696 else if (!strcmp (p
, "missing-prototypes"))
697 warn_missing_prototypes
= setting
;
698 else if (!strcmp (p
, "redundant-decls"))
699 warn_redundant_decls
= setting
;
700 else if (!strcmp (p
, "missing-braces"))
701 warn_missing_braces
= setting
;
702 else if (!strcmp (p
, "sign-compare"))
703 warn_sign_compare
= setting
;
704 else if (!strcmp (p
, "format"))
705 warn_format
= setting
;
706 else if (!strcmp (p
, "conversion"))
707 warn_conversion
= setting
;
708 else if (!strcmp (p
, "parentheses"))
709 warn_parentheses
= setting
;
710 else if (!strcmp (p
, "non-virtual-dtor"))
711 warn_nonvdtor
= setting
;
712 else if (!strcmp (p
, "extern-inline"))
713 warn_extern_inline
= setting
;
714 else if (!strcmp (p
, "reorder"))
715 warn_reorder
= setting
;
716 else if (!strcmp (p
, "synth"))
717 warn_synth
= setting
;
718 else if (!strcmp (p
, "pmf-conversions"))
719 warn_pmf2ptr
= setting
;
720 else if (!strcmp (p
, "effc++"))
722 else if (!strcmp (p
, "sign-promo"))
723 warn_sign_promo
= setting
;
724 else if (!strcmp (p
, "old-style-cast"))
725 warn_old_style_cast
= setting
;
726 else if (!strcmp (p
, "unknown-pragmas"))
727 /* Set to greater than 1, so that even unknown pragmas in
728 system headers will be warned about. */
729 warn_unknown_pragmas
= setting
* 2;
730 else if (!strcmp (p
, "comment"))
731 ; /* cpp handles this one. */
732 else if (!strcmp (p
, "comments"))
733 ; /* cpp handles this one. */
734 else if (!strcmp (p
, "trigraphs"))
735 ; /* cpp handles this one. */
736 else if (!strcmp (p
, "import"))
737 ; /* cpp handles this one. */
738 else if (!strcmp (p
, "all"))
740 warn_return_type
= setting
;
741 warn_unused
= setting
;
742 warn_implicit
= setting
;
743 warn_ctor_dtor_privacy
= setting
;
744 warn_switch
= setting
;
745 warn_format
= setting
;
746 warn_parentheses
= setting
;
747 warn_missing_braces
= setting
;
748 warn_sign_compare
= setting
;
749 warn_extern_inline
= setting
;
750 warn_nonvdtor
= setting
;
751 /* We save the value of warn_uninitialized, since if they put
752 -Wuninitialized on the command line, we need to generate a
753 warning about not using it without also specifying -O. */
754 if (warn_uninitialized
!= 1)
755 warn_uninitialized
= (setting
? 2 : 0);
756 warn_template_debugging
= setting
;
757 warn_reorder
= setting
;
758 warn_sign_promo
= setting
;
759 /* Only warn about unknown pragmas that are not in system
761 warn_unknown_pragmas
= 1;
764 else if (!strcmp (p
, "overloaded-virtual"))
765 warn_overloaded_virtual
= setting
;
766 else return strings_processed
;
768 else if (!strcmp (p
, "-ansi"))
769 flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
770 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
772 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
773 it's probably safe to assume no sane person would ever want to use this
774 under normal circumstances. */
775 else if (!strcmp (p
, "-spew-debug"))
779 return strings_processed
;
784 /* Incorporate `const' and `volatile' qualifiers for member functions.
785 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
786 QUALS is a list of qualifiers. */
789 grok_method_quals (ctype
, function
, quals
)
790 tree ctype
, function
, quals
;
792 tree fntype
= TREE_TYPE (function
);
793 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
797 extern tree ridpointers
[];
799 if (TREE_VALUE (quals
) == ridpointers
[(int)RID_CONST
])
801 if (TYPE_READONLY (ctype
))
802 error ("duplicate `%s' %s",
803 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
804 (TREE_CODE (function
) == FUNCTION_DECL
805 ? "for member function" : "in type declaration"));
806 ctype
= build_type_variant (ctype
, 1, TYPE_VOLATILE (ctype
));
807 build_pointer_type (ctype
);
809 else if (TREE_VALUE (quals
) == ridpointers
[(int)RID_VOLATILE
])
811 if (TYPE_VOLATILE (ctype
))
812 error ("duplicate `%s' %s",
813 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
814 (TREE_CODE (function
) == FUNCTION_DECL
815 ? "for member function" : "in type declaration"));
816 ctype
= build_type_variant (ctype
, TYPE_READONLY (ctype
), 1);
817 build_pointer_type (ctype
);
820 my_friendly_abort (20);
821 quals
= TREE_CHAIN (quals
);
824 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
825 (TREE_CODE (fntype
) == METHOD_TYPE
826 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
827 : TYPE_ARG_TYPES (fntype
)));
829 fntype
= build_exception_variant (fntype
, raises
);
831 TREE_TYPE (function
) = fntype
;
835 /* Warn when -fexternal-templates is used and #pragma
836 interface/implementation is not used all the times it should be,
840 warn_if_unknown_interface (decl
)
843 static int already_warned
= 0;
844 if (already_warned
++)
847 if (flag_alt_external_templates
)
849 struct tinst_level
*til
= tinst_for_decl ();
851 char *sf
= input_filename
;
856 input_filename
= til
->file
;
858 cp_warning ("template `%#D' instantiated in file without #pragma interface",
864 cp_warning_at ("template `%#D' defined in file without #pragma interface",
868 /* A subroutine of the parser, to handle a component list. */
871 grok_x_components (specs
, components
)
872 tree specs
, components
;
874 register tree t
, x
, tcode
;
876 /* We just got some friends. They have been recorded elsewhere. */
877 if (components
== void_type_node
)
880 if (components
== NULL_TREE
)
882 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
886 error ("error in component specification");
890 switch (TREE_CODE (t
))
893 /* Static anonymous unions come out as VAR_DECLs. */
894 if (ANON_UNION_TYPE_P (TREE_TYPE (t
)))
897 /* We return SPECS here, because in the parser it was ending
898 up with not doing anything to $$, which is what SPECS
904 /* This code may be needed for UNION_TYPEs as
906 tcode
= record_type_node
;
907 if (CLASSTYPE_DECLARED_CLASS (t
))
908 tcode
= class_type_node
;
909 else if (IS_SIGNATURE (t
))
910 tcode
= signature_type_node
;
912 if (CLASSTYPE_IS_TEMPLATE (t
))
913 /* In this case, the TYPE_IDENTIFIER will be something
914 like S<T>, rather than S, so to get the correct name we
915 look at the template. */
916 x
= DECL_NAME (CLASSTYPE_TI_TEMPLATE (t
));
918 x
= TYPE_IDENTIFIER (t
);
920 t
= xref_tag (tcode
, x
, NULL_TREE
, 0);
926 if (TREE_CODE (t
) == UNION_TYPE
)
927 tcode
= union_type_node
;
929 tcode
= enum_type_node
;
931 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
932 if (ANON_UNION_TYPE_P (t
))
934 /* See also shadow_tag. */
936 struct pending_inline
**p
;
938 x
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, t
);
940 /* Wipe out memory of synthesized methods */
941 TYPE_HAS_CONSTRUCTOR (t
) = 0;
942 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
943 TYPE_HAS_INIT_REF (t
) = 0;
944 TYPE_HAS_CONST_INIT_REF (t
) = 0;
945 TYPE_HAS_ASSIGN_REF (t
) = 0;
946 TYPE_HAS_ASSIGNMENT (t
) = 0;
947 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
949 q
= &TYPE_METHODS (t
);
952 if (DECL_ARTIFICIAL (*q
))
953 *q
= TREE_CHAIN (*q
);
955 q
= &TREE_CHAIN (*q
);
957 if (TYPE_METHODS (t
))
958 error ("an anonymous union cannot have function members");
960 p
= &pending_inlines
;
961 for (; *p
; *p
= (*p
)->next
)
962 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
965 else if (TREE_CODE (t
) == ENUMERAL_TYPE
)
966 x
= grok_enum_decls (NULL_TREE
);
973 if (t
!= void_type_node
)
974 error ("empty component declaration");
979 /* There may or may not be any enum decls to grok, but
980 grok_enum_decls will just return components, if there aren't
981 any. We used to try to figure out whether or not there were
982 any enum decls based on the type of components, but that's too
983 hard; it might be something like `enum { a } *p;'. */
984 return grok_enum_decls (components
);
987 /* Constructors for types with virtual baseclasses need an "in-charge" flag
988 saying whether this constructor is responsible for initialization of
989 virtual baseclasses or not. All destructors also need this "in-charge"
990 flag, which additionally determines whether or not the destructor should
991 free the memory for the object.
993 This function adds the "in-charge" flag to member function FN if
994 appropriate. It is called from grokclassfn and tsubst.
995 FN must be either a constructor or destructor. */
998 maybe_retrofit_in_chrg (fn
)
1001 tree basetype
, arg_types
, parms
, parm
, fntype
;
1003 if (DECL_CONSTRUCTOR_P (fn
)
1004 && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CLASS_CONTEXT (fn
))
1005 && ! DECL_CONSTRUCTOR_FOR_VBASE_P (fn
))
1007 else if (! DECL_CONSTRUCTOR_P (fn
)
1008 && TREE_CHAIN (DECL_ARGUMENTS (fn
)) == NULL_TREE
)
1013 if (DECL_CONSTRUCTOR_P (fn
))
1014 DECL_CONSTRUCTOR_FOR_VBASE_P (fn
) = 1;
1016 /* First add it to DECL_ARGUMENTS... */
1017 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
1018 /* Mark the artificial `__in_chrg' parameter as "artificial". */
1019 SET_DECL_ARTIFICIAL (parm
);
1020 DECL_ARG_TYPE (parm
) = integer_type_node
;
1021 TREE_READONLY (parm
) = 1;
1022 parms
= DECL_ARGUMENTS (fn
);
1023 TREE_CHAIN (parm
) = TREE_CHAIN (parms
);
1024 TREE_CHAIN (parms
) = parm
;
1026 /* ...and then to TYPE_ARG_TYPES. */
1027 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1028 basetype
= TREE_TYPE (TREE_VALUE (arg_types
));
1029 arg_types
= hash_tree_chain (integer_type_node
, TREE_CHAIN (arg_types
));
1030 fntype
= build_cplus_method_type (basetype
, TREE_TYPE (TREE_TYPE (fn
)),
1032 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)))
1033 fntype
= build_exception_variant (fntype
,
1034 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)));
1035 TREE_TYPE (fn
) = fntype
;
1038 /* Classes overload their constituent function names automatically.
1039 When a function name is declared in a record structure,
1040 its name is changed to it overloaded name. Since names for
1041 constructors and destructors can conflict, we place a leading
1042 '$' for destructors.
1044 CNAME is the name of the class we are grokking for.
1046 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
1048 FLAGS contains bits saying what's special about today's
1049 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
1051 If FUNCTION is a destructor, then we must add the `auto-delete' field
1052 as a second parameter. There is some hair associated with the fact
1053 that we must "declare" this variable in the manner consistent with the
1054 way the rest of the arguments were declared.
1056 QUALS are the qualifiers for the this pointer. */
1059 grokclassfn (ctype
, cname
, function
, flags
, quals
)
1060 tree ctype
, cname
, function
;
1061 enum overload_flags flags
;
1064 tree fn_name
= DECL_NAME (function
);
1069 if (fn_name
== NULL_TREE
)
1071 error ("name missing for member function");
1072 fn_name
= get_identifier ("<anonymous>");
1073 DECL_NAME (function
) = fn_name
;
1077 qualtype
= grok_method_quals (ctype
, function
, quals
);
1081 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1082 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1084 /* Must add the class instance variable up front. */
1085 /* Right now we just make this a pointer. But later
1086 we may wish to make it special. */
1087 tree type
= TREE_VALUE (arg_types
);
1090 if ((flag_this_is_variable
> 0)
1091 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
1094 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
1095 /* Mark the artificial `this' parameter as "artificial". */
1096 SET_DECL_ARTIFICIAL (parm
);
1097 DECL_ARG_TYPE (parm
) = type
;
1098 /* We can make this a register, so long as we don't
1099 accidentally complain if someone tries to take its address. */
1100 DECL_REGISTER (parm
) = 1;
1102 TREE_READONLY (parm
) = 1;
1103 TREE_CHAIN (parm
) = last_function_parms
;
1104 last_function_parms
= parm
;
1107 DECL_ARGUMENTS (function
) = last_function_parms
;
1108 /* First approximations. */
1109 DECL_CONTEXT (function
) = ctype
;
1110 DECL_CLASS_CONTEXT (function
) = ctype
;
1112 if (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
))
1114 maybe_retrofit_in_chrg (function
);
1115 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1118 if (flags
== DTOR_FLAG
)
1120 DECL_ASSEMBLER_NAME (function
) = build_destructor_name (ctype
);
1121 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
1125 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
1126 /* Only true for static member functions. */
1127 arg_types
= hash_tree_chain (build_pointer_type (qualtype
),
1130 DECL_ASSEMBLER_NAME (function
)
1131 = build_decl_overload (fn_name
, arg_types
,
1132 1 + DECL_CONSTRUCTOR_P (function
));
1136 /* Work on the expr used by alignof (this is only called by the parser). */
1145 if (processing_template_decl
)
1146 return build_min (ALIGNOF_EXPR
, sizetype
, expr
);
1148 if (TREE_CODE (expr
) == COMPONENT_REF
1149 && DECL_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1150 error ("`__alignof__' applied to a bit-field");
1152 if (TREE_CODE (expr
) == INDIRECT_REF
)
1154 best
= t
= TREE_OPERAND (expr
, 0);
1155 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1157 while (TREE_CODE (t
) == NOP_EXPR
1158 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1161 t
= TREE_OPERAND (t
, 0);
1162 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1163 if (thisalign
> bestalign
)
1164 best
= t
, bestalign
= thisalign
;
1166 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1170 /* ANSI says arrays and fns are converted inside comma.
1171 But we can't convert them in build_compound_expr
1172 because that would break commas in lvalues.
1173 So do the conversion here if operand was a comma. */
1174 if (TREE_CODE (expr
) == COMPOUND_EXPR
1175 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1176 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1177 expr
= default_conversion (expr
);
1178 return c_alignof (TREE_TYPE (expr
));
1182 /* Create an ARRAY_REF, checking for the user doing things backwards
1186 grok_array_decl (array_expr
, index_exp
)
1187 tree array_expr
, index_exp
;
1189 tree type
= TREE_TYPE (array_expr
);
1190 tree p1
, p2
, i1
, i2
;
1192 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1193 return error_mark_node
;
1194 if (processing_template_decl
)
1195 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
1196 array_expr
, index_exp
);
1198 if (type
== NULL_TREE
)
1200 /* Something has gone very wrong. Assume we are mistakenly reducing
1201 an expression instead of a declaration. */
1202 error ("parser may be lost: is there a '{' missing somewhere?");
1206 if (TREE_CODE (type
) == OFFSET_TYPE
1207 || TREE_CODE (type
) == REFERENCE_TYPE
)
1208 type
= TREE_TYPE (type
);
1210 /* If they have an `operator[]', use that. */
1211 if (IS_AGGR_TYPE (type
) || IS_AGGR_TYPE (TREE_TYPE (index_exp
)))
1212 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1213 array_expr
, index_exp
, NULL_TREE
);
1215 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1217 if (TREE_CODE (type
) == ARRAY_TYPE
)
1220 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1222 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1225 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1227 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1228 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1230 if ((p1
&& i2
) && (i1
&& p2
))
1231 error ("ambiguous conversion for array subscript");
1234 array_expr
= p1
, index_exp
= i2
;
1236 array_expr
= p2
, index_exp
= i1
;
1239 cp_error ("invalid types `%T[%T]' for array subscript",
1240 type
, TREE_TYPE (index_exp
));
1241 return error_mark_node
;
1244 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1245 error ("ambiguous conversion for array subscript");
1247 return build_array_ref (array_expr
, index_exp
);
1250 /* Given the cast expression EXP, checking out its validity. Either return
1251 an error_mark_node if there was an unavoidable error, return a cast to
1252 void for trying to delete a pointer w/ the value 0, or return the
1253 call to delete. If DOING_VEC is 1, we handle things differently
1254 for doing an array delete. If DOING_VEC is 2, they gave us the
1255 array size as an argument to delete.
1256 Implements ARM $5.3.4. This is called from the parser. */
1259 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1261 int doing_vec
, use_global_delete
;
1264 /* For a regular vector delete (aka, no size argument) we will pass
1265 this down as a NULL_TREE into build_vec_delete. */
1266 tree maxindex
= NULL_TREE
;
1268 if (exp
== error_mark_node
)
1271 if (processing_template_decl
)
1273 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
1274 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
1275 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
1279 if (TREE_CODE (exp
) == OFFSET_REF
)
1280 exp
= resolve_offset_ref (exp
);
1281 exp
= convert_from_reference (exp
);
1282 t
= stabilize_reference (exp
);
1283 t
= build_expr_type_conversion (WANT_POINTER
, t
, 1);
1285 if (t
== NULL_TREE
|| t
== error_mark_node
)
1287 cp_error ("type `%#T' argument given to `delete', expected pointer",
1289 return error_mark_node
;
1294 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1295 pedwarn ("anachronistic use of array size in vector delete");
1298 type
= TREE_TYPE (t
);
1300 /* As of Valley Forge, you can delete a pointer to const. */
1302 /* You can't delete functions. */
1303 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1305 error ("cannot delete a function");
1306 return error_mark_node
;
1309 /* An array can't have been allocated by new, so complain. */
1310 if (TREE_CODE (t
) == ADDR_EXPR
1311 && TREE_CODE (TREE_OPERAND (t
, 0)) == VAR_DECL
1312 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == ARRAY_TYPE
)
1313 cp_warning ("deleting array `%#D'", TREE_OPERAND (t
, 0));
1315 /* Deleting a pointer with the value zero is valid and has no effect. */
1316 if (integer_zerop (t
))
1317 return build1 (NOP_EXPR
, void_type_node
, t
);
1320 return build_vec_delete (t
, maxindex
, integer_one_node
,
1321 integer_two_node
, use_global_delete
);
1324 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1325 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1327 /* Only do access checking here; we'll be calling op delete
1328 from the destructor. */
1329 tree tmp
= build_op_delete_call (DELETE_EXPR
, t
, size_zero_node
,
1330 LOOKUP_NORMAL
, NULL_TREE
);
1331 if (tmp
== error_mark_node
)
1332 return error_mark_node
;
1335 return build_delete (type
, t
, integer_three_node
,
1336 LOOKUP_NORMAL
, use_global_delete
);
1340 /* Report an error if the indicated template declaration is not the
1341 sort of thing that should be a member template. */
1344 check_member_template (tmpl
)
1349 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 0);
1350 decl
= DECL_TEMPLATE_RESULT (tmpl
);
1352 if (TREE_CODE (decl
) == FUNCTION_DECL
1353 || (TREE_CODE (decl
) == TYPE_DECL
1354 && IS_AGGR_TYPE (TREE_TYPE (decl
))))
1356 if (current_function_decl
)
1357 /* 14.5.2.2 [temp.mem]
1359 A local class shall not have member templates. */
1360 cp_error ("declaration of member template `%#D' in local class",
1363 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
1365 /* 14.5.2.3 [temp.mem]
1367 A member function template shall not be virtual. */
1369 ("invalid use of `virtual' in template declaration of `%#D'",
1371 DECL_VIRTUAL_P (decl
) = 0;
1374 /* The debug-information generating code doesn't know what to do
1375 with member templates. */
1376 DECL_IGNORED_P (tmpl
) = 1;
1379 cp_error ("template declaration of `%#D'", decl
);
1382 /* Return true iff TYPE is a valid Java parameter or return type. */
1385 acceptable_java_type (type
)
1388 if (TREE_CODE (type
) == VOID_TYPE
|| TYPE_FOR_JAVA (type
))
1390 if (TREE_CODE (type
) == POINTER_TYPE
)
1392 type
= TREE_TYPE (type
);
1393 if (TREE_CODE (type
) == RECORD_TYPE
)
1395 complete_type (type
);
1396 return TYPE_FOR_JAVA (type
);
1402 /* For a METHOD in a Java class CTYPE, return 1 if
1403 the parameter and return types are valid Java types.
1404 Otherwise, print appropriate error messages, and return 0. */
1407 check_java_method (ctype
, method
)
1411 tree arg_types
= TYPE_ARG_TYPES (TREE_TYPE (method
));
1412 tree ret_type
= TREE_TYPE (TREE_TYPE (method
));
1413 if (! acceptable_java_type (ret_type
))
1415 cp_error ("Java method '%D' has non-Java return type `%T'",
1419 for (; arg_types
!= NULL_TREE
; arg_types
= TREE_CHAIN (arg_types
))
1421 tree type
= TREE_VALUE (arg_types
);
1422 if (! acceptable_java_type (type
))
1424 cp_error ("Java method '%D' has non-Java parameter type `%T'",
1429 return jerr
? 0 : 1;
1432 /* Sanity check: report error if this function FUNCTION is not
1433 really a member of the class (CTYPE) it is supposed to belong to.
1434 CNAME is the same here as it is for grokclassfn above. */
1437 check_classfn (ctype
, function
)
1438 tree ctype
, function
;
1440 tree fn_name
= DECL_NAME (function
);
1441 tree fndecl
, fndecls
;
1442 tree method_vec
= CLASSTYPE_METHOD_VEC (complete_type (ctype
));
1445 tree templates
= NULL_TREE
;
1447 if (method_vec
!= 0)
1449 methods
= &TREE_VEC_ELT (method_vec
, 0);
1450 end
= TREE_VEC_END (method_vec
);
1452 /* First suss out ctors and dtors. */
1453 if (*methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1454 && DECL_CONSTRUCTOR_P (function
))
1456 if (*++methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1457 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
)))
1460 while (++methods
!= end
)
1463 if (fn_name
== DECL_NAME (OVL_CURRENT (*methods
)))
1466 for (fndecls
= *methods
; fndecls
!= NULL_TREE
;
1467 fndecls
= OVL_NEXT (fndecls
))
1469 fndecl
= OVL_CURRENT (fndecls
);
1470 /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL is
1471 not mangled, so the check below does not work
1472 correctly in that case. */
1473 if (TREE_CODE (function
) != TEMPLATE_DECL
1474 && TREE_CODE (fndecl
) != TEMPLATE_DECL
1475 && (DECL_ASSEMBLER_NAME (function
)
1476 == DECL_ASSEMBLER_NAME (fndecl
)))
1479 /* We cannot simply call decls_match because this
1480 doesn't work for static member functions that are
1481 pretending to be methods, and because the name
1482 may have been changed by asm("new_name"). */
1483 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1485 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1486 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1488 /* Get rid of the this parameter on functions that become
1490 if (DECL_STATIC_FUNCTION_P (fndecl
)
1491 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1492 p1
= TREE_CHAIN (p1
);
1494 if (comptypes (TREE_TYPE (TREE_TYPE (function
)),
1495 TREE_TYPE (TREE_TYPE (fndecl
)), 1)
1496 && compparms (p1
, p2
, 3)
1497 && (DECL_TEMPLATE_SPECIALIZATION (function
)
1498 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
1499 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
1500 || (DECL_TI_TEMPLATE (function
)
1501 == DECL_TI_TEMPLATE (fndecl
))))
1504 if (is_member_template (fndecl
))
1505 /* This function might be an instantiation
1506 or specialization of fndecl. */
1508 scratch_tree_cons (NULL_TREE
, fndecl
, templates
);
1513 else if (TREE_CODE (fndecl
) == TEMPLATE_DECL
1514 && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl
))
1515 && IDENTIFIER_TYPENAME_P (fn_name
))
1516 /* The method in the class is a member template
1517 conversion operator. We are declaring another
1518 conversion operator. It is possible that even though
1519 the names don't match, there is some specialization
1522 scratch_tree_cons (NULL_TREE
, fndecl
, templates
);
1527 /* This function might be an instantiation or a specialization.
1528 We should verify that this is possible. If it is, we must
1529 somehow add the new declaration to the method vector for the
1530 class. Perhaps we should use add_method? For now, we simply
1531 return NULL_TREE, which lets the caller know that this
1532 function is new, but we don't print an error message. */
1537 tree fndecl
= *methods
;
1538 cp_error ("prototype for `%#D' does not match any in class `%T'",
1540 cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl
) ? "s are" : " is",
1541 OVL_CURRENT (fndecl
));
1542 while (fndecl
= OVL_NEXT (fndecl
), fndecl
)
1543 cp_error_at (" %#D", OVL_CURRENT(fndecl
));
1548 cp_error ("no `%#D' member function declared in class `%T'",
1552 /* If we did not find the method in the class, add it to avoid
1554 add_method (ctype
, methods
, function
);
1558 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1559 of a structure component, returning a FIELD_DECL node.
1560 QUALS is a list of type qualifiers for this decl (such as for declaring
1561 const member functions).
1563 This is done during the parsing of the struct declaration.
1564 The FIELD_DECL nodes are chained together and the lot of them
1565 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1569 If class A defines that certain functions in class B are friends, then
1570 the way I have set things up, it is B who is interested in permission
1571 granted by A. However, it is in A's context that these declarations
1572 are parsed. By returning a void_type_node, class A does not attempt
1573 to incorporate the declarations of the friends within its structure.
1575 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1576 CHANGES TO CODE IN `start_method'. */
1579 grokfield (declarator
, declspecs
, init
, asmspec_tree
, attrlist
)
1580 tree declarator
, declspecs
, init
, asmspec_tree
, attrlist
;
1582 register tree value
;
1584 int flags
= LOOKUP_ONLYCONVERTING
;
1586 /* Convert () initializers to = initializers. */
1587 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1588 && TREE_CODE (declarator
) == CALL_EXPR
1589 && TREE_OPERAND (declarator
, 0)
1590 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1591 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1592 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1594 init
= TREE_OPERAND (declarator
, 1);
1595 declarator
= TREE_OPERAND (declarator
, 0);
1599 if (declspecs
== NULL_TREE
1600 && TREE_CODE (declarator
) == SCOPE_REF
1601 && TREE_CODE (TREE_OPERAND (declarator
, 1)) == IDENTIFIER_NODE
)
1603 /* Access declaration */
1604 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
1606 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
1607 pop_nested_class (1);
1608 return do_class_using_decl (declarator
);
1612 && TREE_CODE (init
) == TREE_LIST
1613 && TREE_VALUE (init
) == error_mark_node
1614 && TREE_CHAIN (init
) == NULL_TREE
)
1617 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, NULL_TREE
);
1619 return value
; /* friend or constructor went bad. */
1621 /* Pass friendly classes back. */
1622 if (TREE_CODE (value
) == VOID_TYPE
)
1623 return void_type_node
;
1625 if (DECL_NAME (value
) != NULL_TREE
1626 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1627 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1628 cp_error ("member `%D' conflicts with virtual function table field name",
1631 /* Stash away type declarations. */
1632 if (TREE_CODE (value
) == TYPE_DECL
)
1634 DECL_NONLOCAL (value
) = 1;
1635 DECL_CONTEXT (value
) = current_class_type
;
1636 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1637 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
1639 /* Now that we've updated the context, we need to remangle the
1640 name for this TYPE_DECL. */
1641 DECL_ASSEMBLER_NAME (value
) = DECL_NAME (value
);
1642 DECL_ASSEMBLER_NAME (value
) =
1643 get_identifier (build_overload_name (TREE_TYPE (value
), 1, 1));
1645 pushdecl_class_level (value
);
1649 if (IS_SIGNATURE (current_class_type
)
1650 && TREE_CODE (value
) != FUNCTION_DECL
)
1652 error ("field declaration not allowed in signature");
1653 return void_type_node
;
1656 if (DECL_IN_AGGR_P (value
))
1658 cp_error ("`%D' is already defined in the class %T", value
,
1659 DECL_CONTEXT (value
));
1660 return void_type_node
;
1664 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1668 if (IS_SIGNATURE (current_class_type
)
1669 && TREE_CODE (value
) == FUNCTION_DECL
)
1671 error ("function declarations cannot have initializers in signature");
1674 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1676 grok_function_init (value
, init
);
1679 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1680 /* Already complained in grokdeclarator. */
1684 /* We allow initializers to become parameters to base
1686 if (TREE_CODE (init
) == TREE_LIST
)
1688 if (TREE_CHAIN (init
) == NULL_TREE
)
1689 init
= TREE_VALUE (init
);
1691 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1694 if (TREE_CODE (init
) == CONST_DECL
)
1695 init
= DECL_INITIAL (init
);
1696 else if (TREE_READONLY_DECL_P (init
))
1697 init
= decl_constant_value (init
);
1698 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1699 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1700 my_friendly_assert (TREE_PERMANENT (init
), 192);
1701 if (init
== error_mark_node
)
1702 /* We must make this look different than `error_mark_node'
1703 because `decl_const_value' would mis-interpret it
1704 as only meaning that this VAR_DECL is defined. */
1705 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1706 else if (processing_template_decl
)
1708 else if (! TREE_CONSTANT (init
))
1710 /* We can allow references to things that are effectively
1711 static, since references are initialized with the address. */
1712 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1713 || (TREE_STATIC (init
) == 0
1714 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1715 || DECL_EXTERNAL (init
) == 0)))
1717 error ("field initializer is not constant");
1718 init
= error_mark_node
;
1724 /* The corresponding pop_obstacks is in cp_finish_decl. */
1725 push_obstacks_nochange ();
1727 if (processing_template_decl
&& ! current_function_decl
1728 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1729 value
= push_template_decl (value
);
1732 cplus_decl_attributes (value
, TREE_PURPOSE (attrlist
),
1733 TREE_VALUE (attrlist
));
1735 if (TREE_CODE (value
) == VAR_DECL
)
1737 my_friendly_assert (TREE_PUBLIC (value
), 0);
1739 /* We cannot call pushdecl here, because that would
1740 fill in the value of our TREE_CHAIN. Instead, we
1741 modify cp_finish_decl to do the right thing, namely, to
1742 put this decl out straight away. */
1743 /* current_class_type can be NULL_TREE in case of error. */
1744 if (asmspec
== 0 && current_class_type
)
1746 TREE_PUBLIC (value
) = 1;
1747 DECL_INITIAL (value
) = error_mark_node
;
1748 DECL_ASSEMBLER_NAME (value
)
1749 = build_static_name (current_class_type
, DECL_NAME (value
));
1751 if (! processing_template_decl
)
1752 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1754 /* Static consts need not be initialized in the class definition. */
1755 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1757 static int explanation
= 0;
1759 error ("initializer invalid for static member with constructor");
1760 if (explanation
++ == 0)
1761 error ("(you really want to initialize it separately)");
1764 /* Force the compiler to know when an uninitialized static
1765 const member is being used. */
1766 if (TYPE_READONLY (value
) && init
== 0)
1767 TREE_USED (value
) = 1;
1768 DECL_INITIAL (value
) = init
;
1769 DECL_IN_AGGR_P (value
) = 1;
1770 DECL_CONTEXT (value
) = current_class_type
;
1771 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1773 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1774 pushdecl_class_level (value
);
1777 if (TREE_CODE (value
) == FIELD_DECL
)
1781 /* This must override the asm specifier which was placed
1782 by grokclassfn. Lay this out fresh. */
1783 DECL_RTL (value
) = NULL_RTX
;
1784 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1786 if (DECL_INITIAL (value
) == error_mark_node
)
1787 init
= error_mark_node
;
1788 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1789 DECL_INITIAL (value
) = init
;
1790 DECL_IN_AGGR_P (value
) = 1;
1793 if (TREE_CODE (value
) == FUNCTION_DECL
)
1797 /* This must override the asm specifier which was placed
1798 by grokclassfn. Lay this out fresh. */
1799 DECL_RTL (value
) = NULL_RTX
;
1800 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1802 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1804 /* Pass friends back this way. */
1805 if (DECL_FRIEND_P (value
))
1806 return void_type_node
;
1808 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1809 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1810 cp_error ("method `%#D' of local class must be defined in class body",
1814 DECL_IN_AGGR_P (value
) = 1;
1817 my_friendly_abort (21);
1822 /* Like `grokfield', but for bitfields.
1823 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1826 grokbitfield (declarator
, declspecs
, width
)
1827 tree declarator
, declspecs
, width
;
1829 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1832 if (! value
) return NULL_TREE
; /* friends went bad. */
1834 /* Pass friendly classes back. */
1835 if (TREE_CODE (value
) == VOID_TYPE
)
1836 return void_type_node
;
1838 if (TREE_CODE (value
) == TYPE_DECL
)
1840 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1844 if (IS_SIGNATURE (current_class_type
))
1846 error ("field declaration not allowed in signature");
1847 return void_type_node
;
1850 if (DECL_IN_AGGR_P (value
))
1852 cp_error ("`%D' is already defined in the class %T", value
,
1853 DECL_CONTEXT (value
));
1854 return void_type_node
;
1857 GNU_xref_member (current_class_name
, value
);
1859 if (TREE_STATIC (value
))
1861 cp_error ("static member `%D' cannot be a bitfield", value
);
1864 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1866 if (width
!= error_mark_node
)
1868 constant_expression_warning (width
);
1869 DECL_INITIAL (value
) = width
;
1870 DECL_BIT_FIELD (value
) = 1;
1873 DECL_IN_AGGR_P (value
) = 1;
1878 grokoptypename (declspecs
, declarator
)
1879 tree declspecs
, declarator
;
1881 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1882 return build_typename_overload (t
);
1885 /* When a function is declared with an initializer,
1886 do the right thing. Currently, there are two possibilities:
1891 // initialization possibility #1.
1892 virtual void f () = 0;
1914 // initialization possibility #2
1921 copy_assignment_arg_p (parmtype
, virtualp
)
1925 if (current_class_type
== NULL_TREE
)
1928 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1929 parmtype
= TREE_TYPE (parmtype
);
1931 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1933 /* Non-standard hack to support old Booch components. */
1934 || (! virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
))
1943 grok_function_init (decl
, init
)
1947 /* An initializer for a function tells how this function should
1949 tree type
= TREE_TYPE (decl
);
1951 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1952 cp_error ("initializer specified for non-member function `%D'", decl
);
1954 /* We'll check for this in finish_struct_1. */
1955 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1956 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1958 else if (integer_zerop (init
))
1961 /* Mark this function as being "defined". */
1962 DECL_INITIAL (decl
) = error_mark_node
;
1963 /* pure virtual destructors must be defined. */
1964 /* pure virtual needs to be defined (as abort) only when put in
1965 vtbl. For wellformed call, it should be itself. pr4737 */
1966 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1968 extern tree abort_fndecl
;
1969 /* Give this node rtl from `abort'. */
1970 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1973 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1974 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1977 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1979 if (copy_assignment_arg_p (parmtype
, 1))
1980 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1984 cp_error ("invalid initializer for virtual method `%D'", decl
);
1988 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1989 tree decl
, attributes
, prefix_attributes
;
1991 if (decl
== NULL_TREE
|| decl
== void_type_node
)
1994 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1995 decl
= DECL_TEMPLATE_RESULT (decl
);
1997 decl_attributes (decl
, attributes
, prefix_attributes
);
1999 if (TREE_CODE (decl
) == TYPE_DECL
)
2000 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
2003 /* CONSTRUCTOR_NAME:
2004 Return the name for the constructor (or destructor) for the
2005 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2006 IDENTIFIER_NODE. When given a template, this routine doesn't
2007 lose the specialization. */
2010 constructor_name_full (thing
)
2013 if (TREE_CODE (thing
) == TEMPLATE_TYPE_PARM
2014 || TREE_CODE (thing
) == TEMPLATE_TEMPLATE_PARM
2015 || TREE_CODE (thing
) == TYPENAME_TYPE
)
2016 thing
= TYPE_NAME (thing
);
2017 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
2019 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
2020 thing
= DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing
), 0)));
2022 thing
= TYPE_NAME (thing
);
2024 if (TREE_CODE (thing
) == TYPE_DECL
2025 || (TREE_CODE (thing
) == TEMPLATE_DECL
2026 && TREE_CODE (DECL_TEMPLATE_RESULT (thing
)) == TYPE_DECL
))
2027 thing
= DECL_NAME (thing
);
2028 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
2032 /* CONSTRUCTOR_NAME:
2033 Return the name for the constructor (or destructor) for the
2034 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2035 IDENTIFIER_NODE. When given a template, return the plain
2036 unspecialized name. */
2039 constructor_name (thing
)
2043 thing
= constructor_name_full (thing
);
2044 t
= IDENTIFIER_TEMPLATE (thing
);
2050 /* Cache the value of this class's main virtual function table pointer
2051 in a register variable. This will save one indirection if a
2052 more than one virtual function call is made this function. */
2057 extern tree base_init_expr
;
2059 if (base_init_expr
== 0
2060 && DECL_CONSTRUCTOR_P (current_function_decl
))
2062 if (processing_template_decl
)
2063 add_tree (build_min_nt
2065 current_member_init_list
, current_base_init_list
));
2067 emit_base_init (current_class_type
, 0);
2071 /* Record the existence of an addressable inline function. */
2074 mark_inline_for_output (decl
)
2077 decl
= DECL_MAIN_VARIANT (decl
);
2078 if (DECL_SAVED_INLINE (decl
))
2080 my_friendly_assert (TREE_PERMANENT (decl
), 363);
2081 DECL_SAVED_INLINE (decl
) = 1;
2083 if (DECL_PENDING_INLINE_INFO (decl
) != 0
2084 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
2086 struct pending_inline
*t
= pending_inlines
;
2087 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
2090 if (t
== DECL_PENDING_INLINE_INFO (decl
))
2096 t
= DECL_PENDING_INLINE_INFO (decl
);
2097 t
->next
= pending_inlines
;
2098 pending_inlines
= t
;
2100 DECL_PENDING_INLINE_INFO (decl
) = 0;
2103 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
2109 temp_name_counter
= 0;
2112 /* Hand off a unique name which can be used for variable we don't really
2113 want to know about anyway, for example, the anonymous variables which
2114 are needed to make references work. Declare this thing so we can use it.
2115 The variable created will be of type TYPE.
2117 STATICP is nonzero if this variable should be static. */
2120 get_temp_name (type
, staticp
)
2124 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2126 int toplev
= toplevel_bindings_p ();
2128 push_obstacks_nochange ();
2129 if (toplev
|| staticp
)
2131 end_temporary_allocation ();
2132 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2133 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2137 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2138 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2140 TREE_USED (decl
) = 1;
2141 TREE_STATIC (decl
) = staticp
;
2142 DECL_ARTIFICIAL (decl
) = 1;
2144 /* If this is a local variable, then lay out its rtl now.
2145 Otherwise, callers of this function are responsible for dealing
2146 with this variable's rtl. */
2150 expand_decl_init (decl
);
2157 /* Get a variable which we can use for multiple assignments.
2158 It is not entered into current_binding_level, because
2159 that breaks things when it comes time to do final cleanups
2160 (which take place "outside" the binding contour of the function). */
2163 get_temp_regvar (type
, init
)
2168 decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
2169 TREE_USED (decl
) = 1;
2170 DECL_REGISTER (decl
) = 1;
2171 DECL_ARTIFICIAL (decl
) = 1;
2173 DECL_RTL (decl
) = assign_temp (type
, 2, 0, 1);
2174 /* We can expand these without fear, since they cannot need
2175 constructors or destructors. */
2176 expand_expr (build_modify_expr (decl
, INIT_EXPR
, init
),
2177 NULL_RTX
, VOIDmode
, 0);
2182 /* Hunts through the global anonymous union ANON_DECL, building
2183 appropriate VAR_DECLs. Stores cleanups on the list of ELEMS, and
2184 returns a VAR_DECL whose size is the same as the size of the
2185 ANON_DECL, if one is available. */
2188 build_anon_union_vars (anon_decl
, elems
, static_p
, external_p
)
2194 tree type
= TREE_TYPE (anon_decl
);
2195 tree main_decl
= NULL_TREE
;
2198 for (field
= TYPE_FIELDS (type
);
2200 field
= TREE_CHAIN (field
))
2203 if (TREE_CODE (field
) != FIELD_DECL
)
2206 if (TREE_PRIVATE (field
))
2207 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
2208 else if (TREE_PROTECTED (field
))
2209 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
2211 if (DECL_NAME (field
) == NULL_TREE
2212 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2214 decl
= build_anon_union_vars (field
, elems
, static_p
, external_p
);
2220 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2221 /* tell `pushdecl' that this is not tentative. */
2222 DECL_INITIAL (decl
) = error_mark_node
;
2223 TREE_PUBLIC (decl
) = 0;
2224 TREE_STATIC (decl
) = static_p
;
2225 DECL_EXTERNAL (decl
) = external_p
;
2226 decl
= pushdecl (decl
);
2227 DECL_INITIAL (decl
) = NULL_TREE
;
2230 /* Only write out one anon union element--choose the one that
2231 can hold them all. */
2232 if (main_decl
== NULL_TREE
2233 && simple_cst_equal (DECL_SIZE (decl
),
2234 DECL_SIZE (anon_decl
)) == 1)
2237 /* ??? This causes there to be no debug info written out
2239 TREE_ASM_WRITTEN (decl
) = 1;
2241 if (DECL_NAME (field
) == NULL_TREE
2242 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2243 /* The remainder of the processing was already done in the
2247 /* If there's a cleanup to do, it belongs in the
2248 TREE_PURPOSE of the following TREE_LIST. */
2249 *elems
= scratch_tree_cons (NULL_TREE
, decl
, *elems
);
2250 TREE_TYPE (*elems
) = type
;
2256 /* Finish off the processing of a UNION_TYPE structure.
2257 If there are static members, then all members are
2258 static, and must be laid out together. If the
2259 union is an anonymous union, we arrange for that
2260 as well. PUBLIC_P is nonzero if this union is
2261 not declared static. */
2264 finish_anon_union (anon_union_decl
)
2265 tree anon_union_decl
;
2267 tree type
= TREE_TYPE (anon_union_decl
);
2268 tree elems
= NULL_TREE
;
2270 int public_p
= TREE_PUBLIC (anon_union_decl
);
2271 int static_p
= TREE_STATIC (anon_union_decl
);
2272 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2274 if (TYPE_FIELDS (type
) == NULL_TREE
)
2279 error ("global anonymous unions must be declared static");
2283 main_decl
= build_anon_union_vars (anon_union_decl
, &elems
,
2284 static_p
, external_p
);
2290 make_decl_rtl (main_decl
, 0, toplevel_bindings_p ());
2291 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2295 warning ("anonymous union with no members");
2300 /* The following call assumes that there are never any cleanups
2301 for anonymous unions--a reasonable assumption. */
2302 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2305 /* Finish processing a builtin type TYPE. It's name is NAME,
2306 its fields are in the array FIELDS. LEN is the number of elements
2307 in FIELDS minus one, or put another way, it is the maximum subscript
2310 It is given the same alignment as ALIGN_TYPE. */
2313 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2322 TYPE_FIELDS (type
) = fields
[0];
2323 for (i
= 0; i
< len
; i
++)
2325 layout_type (TREE_TYPE (fields
[i
]));
2326 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2327 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2329 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2330 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2331 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2333 #if 0 /* not yet, should get fixed properly later */
2334 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2336 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2338 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
2339 layout_decl (TYPE_NAME (type
), 0);
2342 /* Auxiliary functions to make type signatures for
2343 `operator new' and `operator delete' correspond to
2344 what compiler will be expecting. */
2347 coerce_new_type (type
)
2352 if (TREE_CODE (type
) == METHOD_TYPE
)
2353 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2354 if (TREE_TYPE (type
) != ptr_type_node
)
2355 e1
= 1, error ("`operator new' must return type `void *'");
2357 /* Technically the type must be `size_t', but we may not know
2359 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2360 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2361 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type
))) != INTEGER_TYPE
2362 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type
))) != TYPE_PRECISION (sizetype
))
2363 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2365 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2367 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2372 coerce_delete_type (type
)
2379 tree arg_types
= TYPE_ARG_TYPES (type
);
2381 if (TREE_CODE (type
) == METHOD_TYPE
)
2383 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2384 arg_types
= TREE_CHAIN (arg_types
);
2387 if (TREE_TYPE (type
) != void_type_node
)
2388 e1
= 1, error ("`operator delete' must return type `void'");
2390 if (arg_types
== NULL_TREE
2391 || TREE_VALUE (arg_types
) != ptr_type_node
)
2392 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2396 && TREE_CHAIN (arg_types
)
2397 && TREE_CHAIN (arg_types
) != void_list_node
)
2399 /* Again, technically this argument must be `size_t', but again
2400 we may not know what that is. */
2401 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2402 if (TREE_CODE (t2
) != INTEGER_TYPE
2403 || TYPE_PRECISION (t2
) != TYPE_PRECISION (sizetype
))
2404 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2405 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2408 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2409 error ("too many arguments in declaration of `operator delete'");
2411 error ("`...' invalid in specification of `operator delete'");
2416 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2417 build_tree_list (NULL_TREE
, sizetype
));
2420 if (arg_types
== NULL_TREE
)
2421 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2423 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2429 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2430 arg_types
? TREE_CHAIN (arg_types
): NULL_TREE
);
2432 type
= build_function_type (void_type_node
, arg_types
);
2437 extern tree abort_fndecl
;
2440 mark_vtable_entries (decl
)
2443 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
2447 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (TREE_CHAIN (entries
))
2448 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2449 tree fn
= TREE_OPERAND (fnaddr
, 0);
2450 TREE_ADDRESSABLE (fn
) = 1;
2453 skip_rtti_stuff (&entries
);
2455 for (; entries
; entries
= TREE_CHAIN (entries
))
2457 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (entries
)
2458 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2459 tree fn
= TREE_OPERAND (fnaddr
, 0);
2460 TREE_ADDRESSABLE (fn
) = 1;
2461 if (DECL_LANG_SPECIFIC (fn
) && DECL_ABSTRACT_VIRTUAL_P (fn
))
2463 TREE_OPERAND (fnaddr
, 0) = fn
= copy_node (fn
);
2464 DECL_RTL (fn
) = DECL_RTL (abort_fndecl
);
2465 mark_used (abort_fndecl
);
2467 if (TREE_CODE (fn
) == THUNK_DECL
&& DECL_EXTERNAL (fn
))
2469 DECL_EXTERNAL (fn
) = 0;
2476 /* Set DECL up to have the closest approximation of "initialized common"
2477 linkage available. */
2480 comdat_linkage (decl
)
2484 make_decl_one_only (decl
);
2486 TREE_PUBLIC (decl
) = 0;
2488 if (DECL_LANG_SPECIFIC (decl
))
2489 DECL_COMDAT (decl
) = 1;
2492 /* For win32 we also want to put explicit instantiations in
2493 linkonce sections, so that they will be merged with implicit
2494 instantiations; otherwise we get duplicate symbol errors. */
2497 maybe_make_one_only (decl
)
2500 /* This is not necessary on targets that support weak symbols, because
2501 the implicit instantiations will defer to the explicit one. */
2502 if (! supports_one_only () || SUPPORTS_WEAK
)
2505 /* We can't set DECL_COMDAT on functions, or finish_file will think
2506 we can get away with not emitting them if they aren't used.
2507 We can't use make_decl_one_only for variables, because their
2508 DECL_INITIAL may not have been set properly yet. */
2510 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2511 make_decl_one_only (decl
);
2513 comdat_linkage (decl
);
2516 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2517 based on TYPE and other static flags.
2519 Note that anything public is tagged TREE_PUBLIC, whether
2520 it's public in this file or in another one. */
2523 import_export_vtable (decl
, type
, final
)
2527 if (DECL_INTERFACE_KNOWN (decl
))
2531 if (write_virtuals
< 2 && write_virtuals
!= 0)
2533 TREE_PUBLIC (decl
) = 1;
2534 if (write_virtuals
< 0)
2535 DECL_EXTERNAL (decl
) = 1;
2536 DECL_INTERFACE_KNOWN (decl
) = 1;
2538 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2540 TREE_PUBLIC (decl
) = 1;
2541 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2542 DECL_INTERFACE_KNOWN (decl
) = 1;
2544 /* For WIN32 we also want to put explicit instantiations in
2545 linkonce sections. */
2546 if (CLASSTYPE_EXPLICIT_INSTANTIATION (type
))
2547 maybe_make_one_only (decl
);
2551 /* We can only wait to decide if we have real non-inline virtual
2552 functions in our class, or if we come from a template. */
2554 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2556 #ifndef MULTIPLE_SYMBOL_SPACES
2557 if (! found
&& ! final
)
2560 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
2561 method
= TREE_CHAIN (method
))
2562 if (DECL_VINDEX (method
) != NULL_TREE
2563 && ! DECL_THIS_INLINE (method
)
2564 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2572 if (final
|| ! found
)
2574 comdat_linkage (decl
);
2575 DECL_EXTERNAL (decl
) = 0;
2579 TREE_PUBLIC (decl
) = 1;
2580 DECL_EXTERNAL (decl
) = 1;
2586 import_export_template (type
)
2589 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type
)
2590 && ! flag_implicit_templates
2591 && CLASSTYPE_INTERFACE_UNKNOWN (type
))
2593 SET_CLASSTYPE_INTERFACE_KNOWN (type
);
2594 CLASSTYPE_INTERFACE_ONLY (type
) = 1;
2595 CLASSTYPE_VTABLE_NEEDS_WRITING (type
) = 0;
2600 finish_prevtable_vardecl (prev
, vars
)
2603 tree ctype
= DECL_CONTEXT (vars
);
2604 import_export_template (ctype
);
2606 #ifndef MULTIPLE_SYMBOL_SPACES
2607 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype
) && TYPE_VIRTUAL_P (ctype
)
2608 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2611 for (method
= TYPE_METHODS (ctype
); method
!= NULL_TREE
;
2612 method
= TREE_CHAIN (method
))
2614 if (DECL_VINDEX (method
) != NULL_TREE
2615 && !DECL_THIS_INLINE (method
)
2616 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2618 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2619 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
)
2620 = ! DECL_REALLY_EXTERN (method
);
2621 CLASSTYPE_INTERFACE_ONLY (ctype
) = DECL_REALLY_EXTERN (method
);
2628 import_export_vtable (vars
, ctype
, 1);
2633 finish_vtable_vardecl (prev
, vars
)
2636 if (write_virtuals
>= 0
2637 && ! DECL_EXTERNAL (vars
)
2638 && ((TREE_PUBLIC (vars
) && ! DECL_WEAK (vars
) && ! DECL_ONE_ONLY (vars
))
2639 || CLASSTYPE_EXPLICIT_INSTANTIATION (DECL_CONTEXT (vars
))
2640 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
))
2641 || (hack_decl_function_context (vars
) && TREE_USED (vars
)))
2642 && ! TREE_ASM_WRITTEN (vars
))
2645 mark_vtable_entries (vars
);
2646 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2647 store_init_value (vars
, DECL_INITIAL (vars
));
2649 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2651 /* Mark the VAR_DECL node representing the vtable itself as a
2652 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2653 It is rather important that such things be ignored because
2654 any effort to actually generate DWARF for them will run
2655 into trouble when/if we encounter code like:
2658 struct S { virtual void member (); };
2660 because the artificial declaration of the vtable itself (as
2661 manufactured by the g++ front end) will say that the vtable
2662 is a static member of `S' but only *after* the debug output
2663 for the definition of `S' has already been output. This causes
2664 grief because the DWARF entry for the definition of the vtable
2665 will try to refer back to an earlier *declaration* of the
2666 vtable as a static member of `S' and there won't be one.
2667 We might be able to arrange to have the "vtable static member"
2668 attached to the member list for `S' before the debug info for
2669 `S' get written (which would solve the problem) but that would
2670 require more intrusive changes to the g++ front end. */
2672 DECL_IGNORED_P (vars
) = 1;
2675 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2678 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
)))
2679 /* We don't know what to do with this one yet. */
2682 /* We know that PREV must be non-zero here. */
2683 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2688 prune_vtable_vardecl (prev
, vars
)
2691 /* We know that PREV must be non-zero here. */
2692 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2697 walk_vtables (typedecl_fn
, vardecl_fn
)
2698 register void (*typedecl_fn
) PROTO ((tree
, tree
));
2699 register int (*vardecl_fn
) PROTO ((tree
, tree
));
2704 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2706 register tree type
= TREE_TYPE (vars
);
2708 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2711 flag
|= (*vardecl_fn
) (prev
, vars
);
2713 if (prev
&& TREE_CHAIN (prev
) != vars
)
2716 else if (TREE_CODE (vars
) == TYPE_DECL
2717 && type
!= error_mark_node
2718 && TYPE_LANG_SPECIFIC (type
)
2719 && CLASSTYPE_VSIZE (type
))
2721 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2731 finish_sigtable_vardecl (prev
, vars
)
2734 /* We don't need to mark sigtable entries as addressable here as is done
2735 for vtables. Since sigtables, unlike vtables, are always written out,
2736 that was already done in build_signature_table_constructor. */
2738 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2740 /* We know that PREV must be non-zero here. */
2741 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2745 walk_sigtables (typedecl_fn
, vardecl_fn
)
2746 register void (*typedecl_fn
) PROTO((tree
, tree
));
2747 register void (*vardecl_fn
) PROTO((tree
, tree
));
2751 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2753 register tree type
= TREE_TYPE (vars
);
2755 if (TREE_CODE (vars
) == TYPE_DECL
2756 && type
!= error_mark_node
2757 && IS_SIGNATURE (type
))
2759 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2761 else if (TREE_CODE (vars
) == VAR_DECL
2762 && TREE_TYPE (vars
) != error_mark_node
2763 && IS_SIGNATURE (TREE_TYPE (vars
)))
2765 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2772 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2773 inline function or template instantiation at end-of-file. */
2776 import_export_decl (decl
)
2779 if (DECL_INTERFACE_KNOWN (decl
))
2782 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2784 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2785 if (DECL_IMPLICIT_INSTANTIATION (decl
)
2786 && (flag_implicit_templates
|| DECL_THIS_INLINE (decl
)))
2788 if (!TREE_PUBLIC (decl
))
2789 /* Templates are allowed to have internal linkage. See
2792 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2793 comdat_linkage (decl
);
2795 DECL_COMDAT (decl
) = 1;
2798 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2800 else if (DECL_FUNCTION_MEMBER_P (decl
))
2802 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2803 if (CLASSTYPE_INTERFACE_KNOWN (ctype
)
2804 && (! DECL_ARTIFICIAL (decl
) || DECL_VINDEX (decl
)))
2806 DECL_NOT_REALLY_EXTERN (decl
)
2807 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2808 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2811 comdat_linkage (decl
);
2813 /* tinfo function */
2814 else if (DECL_ARTIFICIAL (decl
) && DECL_MUTABLE_P (decl
))
2816 tree ctype
= TREE_TYPE (DECL_NAME (decl
));
2817 if (IS_AGGR_TYPE (ctype
) && CLASSTYPE_INTERFACE_KNOWN (ctype
)
2818 && TYPE_VIRTUAL_P (ctype
))
2820 /* If the type is a cv-qualified variant of a type, then we
2821 must emit the tinfo function in this translation unit
2822 since it will not be emitted when the vtable for the type
2823 is output (which is when the unqualified version is
2825 DECL_NOT_REALLY_EXTERN (decl
)
2826 = TYPE_READONLY (ctype
)
2827 || TYPE_VOLATILE (ctype
)
2828 || ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2829 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2831 /* For WIN32 we also want to put explicit instantiations in
2832 linkonce sections. */
2833 if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype
))
2834 maybe_make_one_only (decl
);
2836 else if (TYPE_BUILT_IN (ctype
) && ctype
== TYPE_MAIN_VARIANT (ctype
))
2837 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2839 comdat_linkage (decl
);
2842 comdat_linkage (decl
);
2844 DECL_INTERFACE_KNOWN (decl
) = 1;
2848 build_cleanup (decl
)
2852 tree type
= TREE_TYPE (decl
);
2854 if (TREE_CODE (type
) == ARRAY_TYPE
)
2858 mark_addressable (decl
);
2859 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
2861 temp
= build_delete (TREE_TYPE (temp
), temp
,
2863 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2867 extern int parse_time
, varconst_time
;
2868 extern tree pending_templates
;
2869 extern tree maybe_templates
;
2875 tree sname
= get_id_2 ("__sn", base
);
2876 /* For struct X foo __attribute__((weak)), there is a counter
2877 __snfoo. Since base is already an assembler name, sname should
2878 be globally unique */
2879 tree sentry
= IDENTIFIER_GLOBAL_VALUE (sname
);
2882 push_obstacks_nochange ();
2883 end_temporary_allocation ();
2884 sentry
= build_decl (VAR_DECL
, sname
, integer_type_node
);
2885 TREE_PUBLIC (sentry
) = 1;
2886 DECL_ARTIFICIAL (sentry
) = 1;
2887 TREE_STATIC (sentry
) = 1;
2888 TREE_USED (sentry
) = 1;
2889 DECL_COMMON (sentry
) = 1;
2890 pushdecl_top_level (sentry
);
2891 cp_finish_decl (sentry
, NULL_TREE
, NULL_TREE
, 0, 0);
2897 /* Start the process of running a particular set of global constructors
2898 or destructors. Subroutine of do_[cd]tors. */
2901 start_objects (method_type
)
2906 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
2908 fnname
= get_file_function_name (method_type
);
2910 start_function (void_list_node
,
2911 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
2915 store_parm_decls ();
2919 expand_start_bindings (0);
2922 /* Finish the process of running a particular set of global constructors
2923 or destructors. Subroutine of do_[cd]tors. */
2926 finish_objects (method_type
)
2931 tree list
= (method_type
== 'I' ? static_ctors
: static_dtors
);
2933 if (! current_function_decl
&& list
)
2934 start_objects (method_type
);
2936 for (; list
; list
= TREE_CHAIN (list
))
2937 expand_expr_stmt (build_function_call (TREE_VALUE (list
), NULL_TREE
));
2939 if (! current_function_decl
)
2942 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
2945 expand_end_bindings (getdecls (), 1, 0);
2948 finish_function (lineno
, 0, 0);
2950 if (method_type
== 'I')
2951 assemble_constructor (fnname
);
2953 assemble_destructor (fnname
);
2956 /* Generate a function to run a set of global destructors. Subroutine of
2962 tree vars
= static_aggregates
;
2964 for (; vars
; vars
= TREE_CHAIN (vars
))
2966 tree decl
= TREE_VALUE (vars
);
2967 tree type
= TREE_TYPE (decl
);
2970 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
)
2971 && ! DECL_EXTERNAL (decl
))
2973 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
2974 || DECL_ONE_ONLY (decl
)
2975 || DECL_WEAK (decl
)));
2977 if (! current_function_decl
)
2978 start_objects ('D');
2980 temp
= build_cleanup (decl
);
2984 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
2985 sentry
= build_unary_op (PREDECREMENT_EXPR
, sentry
, 0);
2986 sentry
= build_binary_op (EQ_EXPR
, sentry
, integer_zero_node
, 1);
2987 expand_start_cond (sentry
, 0);
2990 expand_expr_stmt (temp
);
2997 finish_objects ('D');
3000 /* Generate a function to run a set of global constructors. Subroutine of
3006 tree vars
= static_aggregates
;
3008 /* Reverse the list so it's in the right order for ctors. */
3009 vars
= nreverse (vars
);
3011 for (; vars
; vars
= TREE_CHAIN (vars
))
3013 tree decl
= TREE_VALUE (vars
);
3014 tree init
= TREE_PURPOSE (vars
);
3016 /* If this was a static attribute within some function's scope,
3017 then don't initialize it here. Also, don't bother
3018 with initializers that contain errors. */
3019 if (TREE_STATIC (vars
)
3020 || DECL_EXTERNAL (decl
)
3021 || (init
&& TREE_CODE (init
) == TREE_LIST
3022 && value_member (error_mark_node
, init
)))
3025 if (TREE_CODE (decl
) == VAR_DECL
)
3027 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
3028 || DECL_ONE_ONLY (decl
)
3029 || DECL_WEAK (decl
)));
3031 if (! current_function_decl
)
3032 start_objects ('I');
3034 /* Set these global variables so that GDB at least puts
3035 us near the declaration which required the initialization. */
3036 input_filename
= DECL_SOURCE_FILE (decl
);
3037 lineno
= DECL_SOURCE_LINE (decl
);
3038 emit_note (input_filename
, lineno
);
3040 /* 9.5p5: The initializer of a static member of a class has
3041 the same access rights as a member function. */
3042 if (member_p (decl
))
3044 DECL_CLASS_CONTEXT (current_function_decl
)
3045 = DECL_CONTEXT (decl
);
3046 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3051 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
3052 sentry
= build_unary_op (PREINCREMENT_EXPR
, sentry
, 0);
3053 sentry
= build_binary_op
3054 (EQ_EXPR
, sentry
, integer_one_node
, 1);
3055 expand_start_cond (sentry
, 0);
3058 expand_start_target_temps ();
3060 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3061 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3062 expand_aggr_init (decl
, init
, 0, 0);
3063 else if (TREE_CODE (init
) == TREE_VEC
)
3065 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3066 TREE_VEC_ELT (init
, 1),
3067 TREE_VEC_ELT (init
, 2), 0),
3068 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3071 expand_assignment (decl
, init
, 0, 0);
3073 /* The expression might have involved increments and
3077 /* Cleanup any temporaries needed for the initial value. */
3078 expand_end_target_temps ();
3083 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3084 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3086 else if (decl
== error_mark_node
)
3089 my_friendly_abort (22);
3092 finish_objects ('I');
3095 /* This routine is called from the last rule in yyparse ().
3096 Its job is to create all the code needed to initialize and
3097 destroy the global aggregates. We do the destruction
3098 first, since that way we only need to reverse the decls once. */
3104 int start_time
, this_time
;
3108 int needs_cleaning
= 0, needs_messing_up
= 0;
3112 /* Bad parse errors. Just forget about it. */
3113 if (! global_bindings_p () || current_class_type
)
3116 start_time
= get_run_time ();
3118 /* Otherwise, GDB can get confused, because in only knows
3119 about source for LINENO-1 lines. */
3122 interface_unknown
= 1;
3125 for (fnname
= pending_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
3127 tree srcloc
= TREE_PURPOSE (fnname
);
3128 tree decl
= TREE_VALUE (fnname
);
3130 input_filename
= SRCLOC_FILE (srcloc
);
3131 lineno
= SRCLOC_LINE (srcloc
);
3133 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
3135 instantiate_class_template (decl
);
3136 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl
))
3137 for (vars
= TYPE_METHODS (decl
); vars
; vars
= TREE_CHAIN (vars
))
3138 if (! DECL_ARTIFICIAL (vars
))
3139 instantiate_decl (vars
);
3142 instantiate_decl (decl
);
3145 for (fnname
= maybe_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
3147 tree args
, fn
, decl
= TREE_VALUE (fnname
);
3149 if (DECL_INITIAL (decl
))
3152 fn
= TREE_PURPOSE (fnname
);
3153 args
= get_bindings (fn
, decl
, NULL_TREE
);
3154 fn
= instantiate_template (fn
, args
);
3155 instantiate_decl (fn
);
3158 cat_namespace_levels();
3160 /* Push into C language context, because that's all
3162 push_lang_context (lang_name_c
);
3165 /* The reason for pushing garbage onto the global_binding_level is to
3166 ensure that we can slice out _DECLs which pertain to virtual function
3167 tables. If the last thing pushed onto the global_binding_level was a
3168 virtual function table, then slicing it out would slice away all the
3169 decls (i.e., we lose the head of the chain).
3171 There are several ways of getting the same effect, from changing the
3172 way that iterators over the chain treat the elements that pertain to
3173 virtual function tables, moving the implementation of this code to
3174 decl.c (where we can manipulate global_binding_level directly),
3175 popping the garbage after pushing it and slicing away the vtable
3176 stuff, or just leaving it alone. */
3178 /* Make last thing in global scope not be a virtual function table. */
3179 #if 0 /* not yet, should get fixed properly later */
3180 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
3182 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
3184 DECL_IGNORED_P (vars
) = 1;
3185 SET_DECL_ARTIFICIAL (vars
);
3189 /* Walk to mark the inline functions we need, then output them so
3190 that we can pick up any other tdecls that those routines need. */
3191 walk_vtables ((void (*) PROTO ((tree
, tree
))) 0,
3192 finish_prevtable_vardecl
);
3194 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
3195 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars
)))
3196 rest_of_decl_compilation (TREE_VALUE (vars
), 0, 1, 1);
3197 vars
= static_aggregates
;
3199 if (static_ctors
|| vars
)
3200 needs_messing_up
= 1;
3201 if (static_dtors
|| vars
)
3204 /* The aggregates are listed in reverse declaration order, for cleaning. */
3210 /* do_ctors will reverse the lists for messing up. */
3211 if (needs_messing_up
)
3216 permanent_allocation (1);
3218 /* Done with C language context needs. */
3219 pop_lang_context ();
3221 /* Now write out any static class variables (which may have since
3222 learned how to be initialized). */
3223 while (pending_statics
)
3225 tree decl
= TREE_VALUE (pending_statics
);
3227 /* Output DWARF debug information. */
3228 #ifdef DWARF_DEBUGGING_INFO
3229 if (write_symbols
== DWARF_DEBUG
)
3230 dwarfout_file_scope_decl (decl
, 1);
3232 #ifdef DWARF2_DEBUGGING_INFO
3233 if (write_symbols
== DWARF2_DEBUG
)
3234 dwarf2out_decl (decl
);
3237 DECL_DEFER_OUTPUT (decl
) = 0;
3238 rest_of_decl_compilation
3239 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3241 pending_statics
= TREE_CHAIN (pending_statics
);
3244 this_time
= get_run_time ();
3245 parse_time
-= this_time
- start_time
;
3246 varconst_time
+= this_time
- start_time
;
3248 start_time
= get_run_time ();
3250 if (flag_handle_signatures
)
3251 walk_sigtables ((void (*) PROTO ((tree
, tree
))) 0,
3252 finish_sigtable_vardecl
);
3254 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3256 tree decl
= TREE_VALUE (fnname
);
3257 import_export_decl (decl
);
3260 mark_all_runtime_matches ();
3262 /* Now write out inline functions which had their addresses taken and
3263 which were not declared virtual and which were not declared `extern
3266 int reconsider
= 1; /* More may be referenced; check again */
3270 tree
*p
= &saved_inlines
;
3273 /* We need to do this each time so that newly completed template
3274 types don't wind up at the front of the list. Sigh. */
3275 vars
= build_decl (TYPE_DECL
, make_anon_name (), integer_type_node
);
3276 DECL_IGNORED_P (vars
) = 1;
3277 SET_DECL_ARTIFICIAL (vars
);
3280 reconsider
|= walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3281 finish_vtable_vardecl
);
3285 tree decl
= TREE_VALUE (*p
);
3287 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3289 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
3291 if (DECL_MUTABLE_P (decl
))
3292 synthesize_tinfo_fn (decl
);
3294 synthesize_method (decl
);
3298 /* Catch new template instantiations. */
3299 if (decl
!= TREE_VALUE (*p
))
3302 if (TREE_ASM_WRITTEN (decl
)
3303 || (DECL_SAVED_INSNS (decl
) == 0 && ! DECL_ARTIFICIAL (decl
)))
3304 *p
= TREE_CHAIN (*p
);
3305 else if (DECL_INITIAL (decl
) == 0)
3306 p
= &TREE_CHAIN (*p
);
3307 else if ((TREE_PUBLIC (decl
) && ! DECL_COMDAT (decl
))
3308 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3309 || flag_keep_inline_functions
)
3311 if (DECL_NOT_REALLY_EXTERN (decl
))
3313 DECL_EXTERNAL (decl
) = 0;
3315 /* We can't inline this function after it's been
3316 emitted. We want a variant of
3317 output_inline_function that doesn't prevent
3318 subsequent integration... */
3319 DECL_INLINE (decl
) = 0;
3320 output_inline_function (decl
);
3321 permanent_allocation (1);
3324 *p
= TREE_CHAIN (*p
);
3327 p
= &TREE_CHAIN (*p
);
3331 /* It's possible that some of the remaining inlines will still be
3332 needed. For example, a static inline whose address is used in
3333 the initializer for a file-scope static variable will be
3334 needed. Code in compile_file will handle this, but we mustn't
3335 pretend that there are no definitions for the inlines, or it
3338 FIXME: This won't catch member functions. We should really
3339 unify this stuff with the compile_file stuff. */
3340 for (vars
= saved_inlines
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
3342 tree decl
= TREE_VALUE (vars
);
3344 if (DECL_NOT_REALLY_EXTERN (decl
)
3345 && !DECL_COMDAT (decl
)
3346 && DECL_INITIAL (decl
) != NULL_TREE
)
3347 DECL_EXTERNAL (decl
) = 0;
3351 /* Now delete from the chain of variables all virtual function tables.
3352 We output them all ourselves, because each will be treated specially. */
3354 walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3355 prune_vtable_vardecl
);
3357 if (write_virtuals
== 2)
3359 /* Now complain about an virtual function tables promised
3360 but not delivered. */
3361 while (pending_vtables
)
3363 if (TREE_PURPOSE (pending_vtables
) == NULL_TREE
)
3364 error ("virtual function table for `%s' not defined",
3365 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables
)));
3366 pending_vtables
= TREE_CHAIN (pending_vtables
);
3372 this_time
= get_run_time ();
3373 parse_time
-= this_time
- start_time
;
3374 varconst_time
+= this_time
- start_time
;
3376 if (flag_detailed_statistics
)
3378 dump_tree_statistics ();
3379 dump_time_statistics ();
3383 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3384 expr. Since it was parsed like a type, we need to wade through and fix
3385 that. Unfortunately, since operator() is left-associative, we can't use
3386 tail recursion. In the above example, TYPE is `A', and DECL is
3389 Maybe this shouldn't be recursive, but how often will it actually be
3393 reparse_absdcl_as_expr (type
, decl
)
3396 /* do build_functional_cast (type, NULL_TREE) at bottom */
3397 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3398 return build_functional_cast (type
, NULL_TREE
);
3401 decl
= reparse_decl_as_expr (type
, TREE_OPERAND (decl
, 0));
3403 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_ref
);
3405 if (TREE_CODE (decl
) == CALL_EXPR
&& TREE_TYPE (decl
) != void_type_node
)
3406 decl
= require_complete_type (decl
);
3411 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3412 out to be an expr. Since it was parsed like a type, we need to wade
3413 through and fix that. Since casts are right-associative, we are
3414 reversing the order, so we don't have to recurse.
3416 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3420 reparse_absdcl_as_casts (decl
, expr
)
3425 if (TREE_CODE (expr
) == CONSTRUCTOR
3426 && TREE_TYPE (expr
) == 0)
3428 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3429 decl
= TREE_OPERAND (decl
, 0);
3431 if (IS_SIGNATURE (type
))
3433 error ("cast specifies signature type");
3434 return error_mark_node
;
3437 expr
= digest_init (type
, expr
, (tree
*) 0);
3438 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3440 int failure
= complete_array_type (type
, expr
, 1);
3442 my_friendly_abort (78);
3448 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3449 decl
= TREE_OPERAND (decl
, 0);
3450 expr
= build_c_cast (type
, expr
);
3453 if (warn_old_style_cast
)
3454 warning ("use of old-style cast");
3459 /* Given plain tree nodes for an expression, build up the full semantics. */
3462 build_expr_from_tree (t
)
3465 if (t
== NULL_TREE
|| t
== error_mark_node
)
3468 switch (TREE_CODE (t
))
3470 case IDENTIFIER_NODE
:
3471 return do_identifier (t
, 0);
3474 if (LOOKUP_EXPR_GLOBAL (t
))
3475 return do_scoped_id (TREE_OPERAND (t
, 0), 0);
3477 return do_identifier (TREE_OPERAND (t
, 0), 0);
3479 case TEMPLATE_ID_EXPR
:
3480 return (lookup_template_function
3481 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3482 build_expr_from_tree (TREE_OPERAND (t
, 1))));
3485 return build_x_indirect_ref
3486 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3489 return build_functional_cast
3490 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3492 case REINTERPRET_CAST_EXPR
:
3493 return build_reinterpret_cast
3494 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3496 case CONST_CAST_EXPR
:
3497 return build_const_cast
3498 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3500 case DYNAMIC_CAST_EXPR
:
3501 return build_dynamic_cast
3502 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3504 case STATIC_CAST_EXPR
:
3505 return build_static_cast
3506 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3508 case PREDECREMENT_EXPR
:
3509 case PREINCREMENT_EXPR
:
3510 case POSTDECREMENT_EXPR
:
3511 case POSTINCREMENT_EXPR
:
3515 case TRUTH_NOT_EXPR
:
3517 case CONVERT_EXPR
: /* Unary + */
3520 return build_x_unary_op (TREE_CODE (t
),
3521 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3526 case TRUNC_DIV_EXPR
:
3528 case FLOOR_DIV_EXPR
:
3529 case ROUND_DIV_EXPR
:
3530 case EXACT_DIV_EXPR
:
3532 case BIT_ANDTC_EXPR
:
3535 case TRUNC_MOD_EXPR
:
3536 case FLOOR_MOD_EXPR
:
3537 case TRUTH_ANDIF_EXPR
:
3538 case TRUTH_ORIF_EXPR
:
3539 case TRUTH_AND_EXPR
:
3554 return build_x_binary_op
3556 build_expr_from_tree (TREE_OPERAND (t
, 0)),
3557 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3560 return build_m_component_ref
3561 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3562 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3565 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
3568 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
3570 return build_parse_node (ARRAY_REF
, NULL_TREE
,
3571 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3572 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3573 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3578 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3579 if (TREE_CODE_CLASS (TREE_CODE (r
)) != 't')
3581 return TREE_CODE (t
) == SIZEOF_EXPR
? c_sizeof (r
) : c_alignof (r
);
3585 return build_x_modify_expr
3586 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3587 TREE_CODE (TREE_OPERAND (t
, 1)),
3588 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3591 return build_x_arrow
3592 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3596 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3597 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3598 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3599 NEW_EXPR_USE_GLOBAL (t
));
3602 return delete_sanity
3603 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3604 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3605 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
3608 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
3609 return build_x_compound_expr
3610 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3612 my_friendly_abort (42);
3614 case METHOD_CALL_EXPR
:
3615 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3617 tree ref
= TREE_OPERAND (t
, 0);
3618 return build_scoped_method_call
3619 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3620 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3621 TREE_OPERAND (ref
, 1),
3622 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3624 return build_method_call
3625 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3626 TREE_OPERAND (t
, 0),
3627 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3628 NULL_TREE
, LOOKUP_NORMAL
);
3631 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3633 tree ref
= TREE_OPERAND (t
, 0);
3634 return build_member_call
3635 (build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3636 TREE_OPERAND (ref
, 1),
3637 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3641 tree name
= TREE_OPERAND (t
, 0);
3642 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
3643 || ! really_overloaded_fn (name
))
3644 name
= build_expr_from_tree (name
);
3645 return build_x_function_call
3646 (name
, build_expr_from_tree (TREE_OPERAND (t
, 1)),
3651 return build_x_conditional_expr
3652 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3653 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3654 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3658 tree purpose
, value
, chain
;
3660 if (t
== void_list_node
)
3663 purpose
= TREE_PURPOSE (t
);
3665 purpose
= build_expr_from_tree (purpose
);
3666 value
= TREE_VALUE (t
);
3668 value
= build_expr_from_tree (value
);
3669 chain
= TREE_CHAIN (t
);
3670 if (chain
&& chain
!= void_type_node
)
3671 chain
= build_expr_from_tree (chain
);
3672 return expr_tree_cons (purpose
, value
, chain
);
3676 return build_x_component_ref
3677 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3678 TREE_OPERAND (t
, 1), NULL_TREE
, 1);
3681 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3687 /* digest_init will do the wrong thing if we let it. */
3688 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
3691 r
= build_nt (CONSTRUCTOR
, NULL_TREE
,
3692 build_expr_from_tree (CONSTRUCTOR_ELTS (t
)));
3695 return digest_init (TREE_TYPE (t
), r
, 0);
3700 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
3701 return get_typeid (TREE_OPERAND (t
, 0));
3702 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3705 return convert_from_reference (t
);
3712 /* This is something of the form `int (*a)++' that has turned out to be an
3713 expr. It was only converted into parse nodes, so we need to go through
3714 and build up the semantics. Most of the work is done by
3715 build_expr_from_tree, above.
3717 In the above example, TYPE is `int' and DECL is `*a'. */
3720 reparse_decl_as_expr (type
, decl
)
3723 decl
= build_expr_from_tree (decl
);
3725 return build_functional_cast (type
, build_expr_list (NULL_TREE
, decl
));
3730 /* This is something of the form `int (*a)' that has turned out to be a
3731 decl. It was only converted into parse nodes, so we need to do the
3732 checking that make_{pointer,reference}_declarator do. */
3735 finish_decl_parsing (decl
)
3738 extern int current_class_depth
;
3740 switch (TREE_CODE (decl
))
3742 case IDENTIFIER_NODE
:
3745 return make_pointer_declarator
3746 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3748 return make_reference_declarator
3749 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3751 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3754 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3755 TREE_COMPLEXITY (decl
) = current_class_depth
;
3758 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3761 my_friendly_abort (5);
3767 check_cp_case_value (value
)
3770 if (value
== NULL_TREE
)
3773 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3774 STRIP_TYPE_NOPS (value
);
3776 if (TREE_READONLY_DECL_P (value
))
3778 value
= decl_constant_value (value
);
3779 STRIP_TYPE_NOPS (value
);
3781 value
= fold (value
);
3783 if (TREE_CODE (value
) != INTEGER_CST
3784 && value
!= error_mark_node
)
3786 cp_error ("case label `%E' does not reduce to an integer constant",
3788 value
= error_mark_node
;
3791 /* Promote char or short to int. */
3792 value
= default_conversion (value
);
3794 constant_expression_warning (value
);
3799 /* Return 1 if root encloses child. */
3802 is_namespace_ancestor (root
, child
)
3807 if (root
== global_namespace
)
3809 if (child
== global_namespace
)
3811 return is_namespace_ancestor (root
, CP_DECL_CONTEXT (child
));
3815 /* Return the namespace that is the common ancestor
3816 of two given namespaces. */
3819 namespace_ancestor (ns1
, ns2
)
3822 if (is_namespace_ancestor (ns1
, ns2
))
3824 return namespace_ancestor (DECL_CONTEXT (ns1
), ns2
);
3827 /* Insert used into the using list of user. Set indirect_flag if this
3828 directive is not directly from the source. Also find the common
3829 ancestor and let our users know about the new namespace */
3831 add_using_namespace (user
, used
, indirect
)
3837 /* Using oneself is a no-op. */
3840 my_friendly_assert (TREE_CODE (user
) == NAMESPACE_DECL
, 380);
3841 my_friendly_assert (TREE_CODE (used
) == NAMESPACE_DECL
, 380);
3842 /* Check if we already have this. */
3843 if (purpose_member (used
, DECL_NAMESPACE_USING (user
)) != NULL_TREE
)
3846 /* Add used to the user's using list. */
3847 DECL_NAMESPACE_USING (user
)
3848 = perm_tree_cons (used
, namespace_ancestor (user
, used
),
3849 DECL_NAMESPACE_USING (user
));
3851 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user
)) = indirect
;
3853 /* Add user to the used's users list. */
3854 DECL_NAMESPACE_USERS (used
)
3855 = perm_tree_cons (user
, 0, DECL_NAMESPACE_USERS (used
));
3857 for (iter
= DECL_NAMESPACE_USERS (user
); iter
; iter
= TREE_CHAIN (iter
))
3858 /* indirect usage */
3859 add_using_namespace (TREE_PURPOSE (iter
), used
, 1);
3862 /* Combines two sets of overloaded functions into an OVERLOAD chain.
3863 The first list becomes the tail of the result. */
3866 merge_functions (s1
, s2
)
3870 if (TREE_CODE (s2
) == OVERLOAD
)
3873 s1
= build_overload (OVL_FUNCTION (s2
), s1
);
3874 s2
= OVL_CHAIN (s2
);
3877 s1
= build_overload (s2
, s1
);
3881 /* This should return an error not all definitions define functions.
3882 It is not an error if we find two functions with exactly the
3883 same signature, only if these are selected in overload resolution.
3884 old is the current set of bindings, new the freshly-found binding.
3885 XXX Do we want to give *all* candidates in case of ambiguity?
3886 XXX In what way should I treat extern declarations?
3887 XXX I don't want to repeat the entire duplicate_decls here */
3890 ambiguous_decl (name
, old
, new)
3895 my_friendly_assert (old
!= NULL_TREE
, 393);
3896 /* Copy the value. */
3897 if (!BINDING_VALUE (old
))
3898 BINDING_VALUE (old
) = BINDING_VALUE (new);
3899 else if (BINDING_VALUE (new)
3900 && BINDING_VALUE (new) != BINDING_VALUE (old
))
3902 if (is_overloaded_fn (BINDING_VALUE (old
))
3903 && is_overloaded_fn (BINDING_VALUE (new)))
3905 BINDING_VALUE (old
) = merge_functions (BINDING_VALUE (old
),
3906 BINDING_VALUE (new));
3910 /* Some declarations are functions, some are not. */
3911 cp_error ("ambiguous definition `%D' used", name
);
3912 cp_error_at ("first definition here", BINDING_VALUE (old
));
3913 cp_error_at ("other definition here", BINDING_VALUE (new));
3914 return error_mark_node
;
3917 /* ... and copy the type. */
3918 if (!BINDING_TYPE (old
))
3919 BINDING_TYPE (old
) = BINDING_TYPE (new);
3920 else if(BINDING_TYPE (new)
3921 && BINDING_TYPE (old
) != BINDING_TYPE (new))
3923 cp_error ("`%D' denotes an ambiguous type",name
);
3924 cp_error_at ("first type here", BINDING_TYPE (old
));
3925 cp_error_at ("other type here", BINDING_TYPE (new));
3930 /* Add the bindings of name in used namespaces to val.
3931 The using list is defined by current, and the lookup goes to scope.
3932 Returns zero on errors. */
3935 lookup_using_namespace (name
, val
, current
, scope
)
3936 tree name
, val
, current
, scope
;
3940 /* Iterate over all namespaces from current to scope. */
3941 while (val
!= error_mark_node
)
3943 /* Iterate over all used namespaces in current, searching for
3944 using directives of scope. */
3945 for (iter
= DECL_NAMESPACE_USING (current
);
3946 iter
; iter
= TREE_CHAIN (iter
))
3947 if (TREE_VALUE (iter
) == scope
)
3949 val1
= binding_for_name (name
, TREE_PURPOSE (iter
));
3950 /* Resolve ambiguities. */
3951 val
= ambiguous_decl (name
, val
, val1
);
3953 if (current
== scope
)
3955 current
= CP_DECL_CONTEXT (current
);
3957 return val
!= error_mark_node
;
3961 Excepts the name to lookup and its qualifying scope.
3962 Returns the name/type pair found into the CPLUS_BINDING result,
3966 qualified_lookup_using_namespace (name
, scope
, result
)
3971 /* Maintain a list of namespaces visited... */
3972 tree seen
= NULL_TREE
;
3973 /* ... and a list of namespace yet to see. */
3974 tree todo
= NULL_TREE
;
3976 while (scope
&& (result
!= error_mark_node
))
3978 seen
= temp_tree_cons (scope
, NULL_TREE
, seen
);
3979 result
= ambiguous_decl (name
, result
, binding_for_name (name
, scope
));
3980 if (!BINDING_VALUE (result
) && !BINDING_TYPE (result
))
3981 /* Consider using directives. */
3982 for (usings
= DECL_NAMESPACE_USING (scope
); usings
;
3983 usings
= TREE_CHAIN (usings
))
3984 /* If this was a real directive, and we have not seen it. */
3985 if (!TREE_INDIRECT_USING (usings
)
3986 && !purpose_member (seen
, TREE_PURPOSE (usings
)))
3987 todo
= temp_tree_cons (TREE_PURPOSE (usings
), NULL_TREE
, todo
);
3990 scope
= TREE_PURPOSE (todo
);
3991 todo
= TREE_CHAIN (todo
);
3994 scope
= NULL_TREE
; /* If there never was a todo list. */
3996 return result
!= error_mark_node
;
3999 /* [namespace.memdef]/2 */
4001 /* Set the context of a declaration to scope. Complain if we are not
4005 set_decl_namespace (decl
, scope
)
4010 if (scope
== std_node
)
4011 scope
= global_namespace
;
4012 /* Get rid of namespace aliases. */
4013 scope
= ORIGINAL_NAMESPACE (scope
);
4015 if (!is_namespace_ancestor (current_namespace
, scope
))
4016 cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
4018 DECL_CONTEXT (decl
) = FROB_CONTEXT (scope
);
4019 if (scope
!= current_namespace
)
4021 /* See whether this has been declared in the namespace. */
4022 old
= namespace_binding (DECL_NAME (decl
), scope
);
4024 /* No old declaration at all. */
4026 if (!is_overloaded_fn (decl
))
4027 /* Don't compare non-function decls with decls_match here,
4028 since it can't check for the correct constness at this
4029 point. pushdecl will find those errors later. */
4031 /* Since decl is a function, old should contain a function decl. */
4032 if (!is_overloaded_fn (old
))
4034 for (; old
; old
= OVL_NEXT (old
))
4035 if (decls_match (decl
, OVL_CURRENT (old
)))
4041 cp_error ("`%D' should have been declared inside `%D'",
4045 /* Compute the namespace where a declaration is defined. */
4048 decl_namespace (decl
)
4051 while (DECL_CONTEXT (decl
))
4053 decl
= DECL_CONTEXT (decl
);
4054 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
4056 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
4057 decl
= TYPE_STUB_DECL (decl
);
4058 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd', 390);
4061 return global_namespace
;
4064 /* Return the namespace where the current declaration is declared. */
4067 current_decl_namespace ()
4070 /* If we have been pushed into a different namespace, use it. */
4071 if (decl_namespace_list
)
4072 return TREE_PURPOSE (decl_namespace_list
);
4074 if (current_class_type
)
4075 if (CLASSTYPE_USE_TEMPLATE (current_class_type
))
4076 result
= decl_namespace (CLASSTYPE_TI_TEMPLATE (current_class_type
));
4078 result
= decl_namespace (TYPE_STUB_DECL (current_class_type
));
4079 else if (current_function_decl
)
4080 if (DECL_USE_TEMPLATE (current_function_decl
))
4081 result
= decl_namespace (DECL_TI_TEMPLATE (current_function_decl
));
4083 result
= decl_namespace (current_function_decl
);
4085 result
= current_namespace
;
4089 /* Temporarily set the namespace for the current declaration. */
4092 push_decl_namespace (decl
)
4095 if (TREE_CODE (decl
) != NAMESPACE_DECL
)
4096 decl
= decl_namespace (decl
);
4097 decl_namespace_list
= tree_cons (decl
, NULL_TREE
, decl_namespace_list
);
4101 pop_decl_namespace ()
4103 decl_namespace_list
= TREE_CHAIN (decl_namespace_list
);
4106 /* [basic.lookup.koenig] */
4107 /* A non-zero return value in the functions below indicates an error.
4108 All nodes allocated in the procedure are on the scratch obstack. */
4118 static int arg_assoc
PROTO((struct arg_lookup
*, tree
));
4119 static int arg_assoc_args
PROTO((struct arg_lookup
*, tree
));
4121 /* Add a function to the lookup structure. */
4124 add_function (k
, fn
)
4125 struct arg_lookup
*k
;
4128 if (ovl_member (fn
, k
->functions
))
4130 k
->functions
= build_overload (fn
, k
->functions
);
4134 /* Add functions of a namespace to the lookup structure. */
4137 arg_assoc_namespace (k
, scope
)
4138 struct arg_lookup
*k
;
4143 if (purpose_member (scope
, k
->namespaces
))
4145 k
->namespaces
= tree_cons (scope
, NULL_TREE
, k
->namespaces
);
4147 value
= namespace_binding (k
->name
, scope
);
4151 if (!is_overloaded_fn (value
))
4153 cp_error_at ("`%D' is not a function", value
);
4154 cp_error ("in call to `%D'", k
->name
);
4158 for (; value
; value
= OVL_NEXT (value
))
4159 if (add_function (k
, OVL_CURRENT (value
)))
4165 /* Adds everything associated with class to the lookup structure. */
4168 arg_assoc_class (k
, type
)
4169 struct arg_lookup
* k
;
4172 tree list
, friends
, context
;
4175 if (purpose_member (type
, k
->classes
))
4177 k
->classes
= tree_cons (type
, NULL_TREE
, k
->classes
);
4179 context
= decl_namespace (TYPE_MAIN_DECL (type
));
4180 if (arg_assoc_namespace (k
, context
))
4183 /* Process baseclasses. */
4184 for (i
= 0; i
< CLASSTYPE_N_BASECLASSES (type
); i
++)
4185 if (arg_assoc_class (k
, TYPE_BINFO_BASETYPE (type
, i
)))
4188 /* Process friends. */
4189 for (list
= DECL_FRIENDLIST (TYPE_MAIN_DECL (type
)); list
;
4190 list
= TREE_CHAIN (list
))
4191 if (k
->name
== TREE_PURPOSE (list
))
4192 for (friends
= TREE_VALUE (list
); friends
;
4193 friends
= TREE_CHAIN (friends
))
4194 /* Only interested in global functions with potentially hidden
4195 (i.e. unqualified) declarations. */
4196 if (TREE_PURPOSE (list
) == error_mark_node
&& TREE_VALUE (list
)
4197 && decl_namespace (TREE_VALUE (list
)) == context
)
4198 if (add_function (k
, TREE_VALUE (list
)))
4203 /* Adds everything associated with a given type. */
4206 arg_assoc_type (k
, type
)
4207 struct arg_lookup
*k
;
4210 switch (TREE_CODE (type
))
4220 if (TYPE_PTRMEMFUNC_P (type
))
4221 return arg_assoc_type (k
, TYPE_PTRMEMFUNC_FN_TYPE (type
));
4222 return arg_assoc_class (k
, type
);
4224 case REFERENCE_TYPE
:
4226 return arg_assoc_type (k
, TREE_TYPE (type
));
4229 return arg_assoc_namespace (k
, decl_namespace (TYPE_MAIN_DECL (type
)));
4231 /* Pointer to member: associate class type and value type. */
4232 if (arg_assoc_type (k
, TYPE_OFFSET_BASETYPE (type
)))
4234 return arg_assoc_type (k
, TREE_TYPE (type
));
4236 /* Associate the class of the method. */
4237 if (arg_assoc_type (k
, TYPE_METHOD_BASETYPE (type
)))
4241 /* Associate the parameter types. */
4242 if (arg_assoc_args (k
, TYPE_ARG_TYPES (type
)))
4244 /* Associate the return type. */
4245 return arg_assoc_type (k
, TREE_TYPE (type
));
4247 if (type
== unknown_type_node
)
4249 /* else fall through */
4251 my_friendly_abort (390);
4256 /* Adds everything associated with arguments. */
4259 arg_assoc_args (k
, args
)
4260 struct arg_lookup
* k
;
4263 for (; args
; args
= TREE_CHAIN (args
))
4264 if (arg_assoc (k
, TREE_VALUE (args
)))
4269 /* Adds everything associated with a given tree_node. */
4273 struct arg_lookup
* k
;
4276 switch (TREE_CODE_CLASS (TREE_CODE (n
)))
4279 return arg_assoc_type (k
, n
);
4285 return arg_assoc_type (k
, TREE_TYPE (n
));
4287 switch (TREE_CODE (n
))
4290 /* special processing */
4293 return arg_assoc_type (k
, TREE_TYPE (n
));
4300 switch (TREE_CODE (n
))
4302 case CONST_DECL
: /* 'd' */
4306 return arg_assoc_type (k
, TREE_TYPE (n
));
4307 case ADDR_EXPR
: /* 'e' */
4308 /* We can't use the TREE_TYPE, as the type of an overloaded function
4309 will be useless here. */
4310 n
= TREE_OPERAND (n
, 0);
4312 case OVERLOAD
: /* 'x' */
4313 if (arg_assoc (k
, OVL_CURRENT (n
)))
4317 case TREE_LIST
: /* 'x' */
4318 /* XXX Overloaded member, should get an OVERLOAD directly, here. */
4321 case FUNCTION_DECL
: /* 'd' */
4322 if (arg_assoc_args (k
, FUNCTION_ARG_CHAIN (n
)))
4324 if (DECL_FUNCTION_MEMBER_P (n
))
4325 if (arg_assoc_type (k
, DECL_CLASS_CONTEXT (n
)))
4329 cp_error ("sorry, Koenig lookup for `%s' of type `%T' failed",
4330 tree_code_name
[(int)TREE_CODE (n
)], TREE_TYPE (n
));
4331 my_friendly_abort (391);
4336 /* Performs Koenig lookup depending on arguments, where fns
4337 are the functions found in normal lookup. */
4340 lookup_arg_dependent (name
, fns
, args
)
4345 struct arg_lookup k
;
4348 k
.namespaces
= NULL_TREE
;
4349 k
.classes
= NULL_TREE
;
4351 push_scratch_obstack ();
4352 arg_assoc_args (&k
, args
);
4357 /* Process a namespace-alias declaration. */
4360 do_namespace_alias (alias
, namespace)
4361 tree alias
, namespace;
4366 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4368 /* The parser did not find it, so it's not there. */
4369 cp_error ("unknown namespace `%D'", namespace);
4373 namespace = ORIGINAL_NAMESPACE (namespace);
4375 binding
= binding_for_name (alias
, current_namespace
);
4376 old
= BINDING_VALUE (binding
);
4379 if (TREE_CODE (old
) == NAMESPACE_DECL
4380 && DECL_NAMESPACE_ALIAS (old
) == namespace)
4381 /* Ok: redeclaration. */
4383 cp_error ("invalid namespace alias `%D'", alias
);
4384 cp_error_at ("`%D' previously declared here", old
);
4388 /* Build the alias. */
4389 alias
= build_lang_decl (NAMESPACE_DECL
, alias
, void_type_node
);
4390 DECL_NAMESPACE_ALIAS (alias
) = namespace;
4391 DECL_CONTEXT (alias
) = FROB_CONTEXT (current_namespace
);
4392 BINDING_VALUE (binding
) = alias
;
4396 /* Process a using-declaration not appearing in class or local scope. */
4399 do_toplevel_using_decl (decl
)
4402 tree scope
, name
, binding
, decls
, newval
, newtype
;
4403 struct tree_binding _decls
;
4405 if (TREE_CODE (decl
) == SCOPE_REF
4406 && TREE_OPERAND (decl
, 0) == std_node
)
4408 if (TREE_CODE (decl
) == SCOPE_REF
)
4410 scope
= TREE_OPERAND (decl
, 0);
4411 name
= TREE_OPERAND (decl
, 1);
4413 else if (TREE_CODE (decl
) == IDENTIFIER_NODE
4414 || TREE_CODE (decl
) == TYPE_DECL
)
4416 scope
= global_namespace
;
4420 my_friendly_abort (382);
4421 if (TREE_CODE_CLASS (TREE_CODE (name
)) == 'd')
4422 name
= DECL_NAME (name
);
4423 /* Make a USING_DECL. */
4424 decl
= push_using_decl (scope
, name
);
4428 binding
= binding_for_name (name
, current_namespace
);
4429 decls
= binding_init (&_decls
);
4430 if (!qualified_lookup_using_namespace (name
, scope
, decls
))
4434 if (!BINDING_VALUE (decls
) && !BINDING_TYPE (decls
))
4436 cp_error ("`%D' not declared", name
);
4439 newval
= newtype
= NULL_TREE
;
4441 /* Check for using functions. */
4442 if (BINDING_VALUE (decls
) && is_overloaded_fn (BINDING_VALUE (decls
)))
4444 tree oldval
= BINDING_VALUE (binding
);
4447 for (tmp
= BINDING_VALUE (decls
); tmp
; tmp
= OVL_NEXT (tmp
))
4450 /* Compare each new function with each old one.
4451 If the old function was also used, there is no conflict. */
4452 for (tmp1
= oldval
; tmp1
; tmp1
= OVL_NEXT (tmp1
))
4453 if (OVL_CURRENT (tmp
) == OVL_CURRENT (tmp1
))
4455 else if (OVL_USED (tmp1
))
4457 else if (duplicate_decls (OVL_CURRENT (tmp
), OVL_CURRENT (tmp1
)))
4460 /* Duplicate use, ignore */
4464 newval
= build_overload (OVL_CURRENT (tmp
), newval
);
4465 if (TREE_CODE (newval
) != OVERLOAD
)
4466 newval
= ovl_cons (newval
, NULL_TREE
);
4467 OVL_USED (newval
) = 1;
4472 tree oldval
= BINDING_VALUE (binding
);
4473 newval
= BINDING_VALUE (decls
);
4474 if (oldval
&& oldval
!= newval
&& !duplicate_decls (newval
, oldval
))
4478 newtype
= BINDING_TYPE (decls
);
4479 if (BINDING_TYPE (binding
) && newtype
&& BINDING_TYPE (binding
) != newtype
)
4481 cp_error ("using directive `%D' introduced ambiguous type `%T'",
4482 name
, BINDING_TYPE (decls
));
4485 /* Copy declarations found. */
4487 BINDING_VALUE (binding
) = newval
;
4489 BINDING_TYPE (binding
) = newtype
;
4494 do_class_using_decl (decl
)
4499 if (TREE_CODE (decl
) != SCOPE_REF
4500 || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (decl
, 0))) != 't')
4502 cp_error ("using-declaration for non-member at class scope");
4505 name
= TREE_OPERAND (decl
, 1);
4506 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
4508 cp_error ("using-declaration for destructor");
4512 value
= build_lang_field_decl (USING_DECL
, name
, void_type_node
);
4513 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
4517 /* Process a using-directive. */
4520 do_using_directive (namespace)
4523 if (namespace == std_node
)
4525 if (!toplevel_bindings_p ())
4527 sorry ("using directives inside functions");
4530 /* using namespace A::B::C; */
4531 if (TREE_CODE (namespace) == SCOPE_REF
)
4532 namespace = TREE_OPERAND (namespace, 1);
4533 if (TREE_CODE (namespace) == IDENTIFIER_NODE
)
4535 /* Lookup in lexer did not find a namespace. */
4536 cp_error ("namespace `%T' undeclared", namespace);
4539 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4541 cp_error ("`%T' is not a namespace", namespace);
4544 namespace = ORIGINAL_NAMESPACE (namespace);
4546 add_using_namespace (current_namespace
, namespace, 0);
4550 check_default_args (x
)
4553 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
4554 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
4555 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
4557 if (TREE_PURPOSE (arg
))
4561 cp_error_at ("default argument missing for parameter %P of `%+#D'",
4572 TREE_USED (decl
) = 1;
4573 if (processing_template_decl
)
4575 assemble_external (decl
);
4576 /* Is it a synthesized method that needs to be synthesized? */
4577 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CLASS_CONTEXT (decl
)
4578 && DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
4579 /* Kludge: don't synthesize for default args. */
4580 && current_function_decl
)
4581 synthesize_method (decl
);
4582 if (DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
))
4583 instantiate_decl (decl
);
4586 /* Helper function for named_class_head_sans_basetype nonterminal. */
4589 handle_class_head (aggr
, scope
, id
)
4590 tree aggr
, scope
, id
;
4592 if (TREE_CODE (id
) == TYPE_DECL
)
4596 cp_error ("`%T' does not have a nested type named `%D'", scope
, id
);
4598 cp_error ("no file-scope type named `%D'", id
);
4601 (aggr
, make_anon_name (), NULL_TREE
, 1);
4602 return TYPE_MAIN_DECL (id
);