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 static tree get_sentry
PROTO((tree
));
44 static void mark_vtable_entries
PROTO((tree
));
45 static void import_export_template
PROTO((tree
));
46 static void grok_function_init
PROTO((tree
, tree
));
47 static int finish_vtable_vardecl
PROTO((tree
, tree
));
48 static int prune_vtable_vardecl
PROTO((tree
, tree
));
49 static void finish_sigtable_vardecl
PROTO((tree
, tree
));
51 extern int current_class_depth
;
53 /* A list of virtual function tables we must make sure to write out. */
56 /* A list of static class variables. This is needed, because a
57 static class variable can be declared inside the class without
58 an initializer, and then initialized, staticly, outside the class. */
61 /* A list of functions which were declared inline, but which we
62 may need to emit outline anyway. */
63 static tree saved_inlines
;
65 /* Used to help generate temporary names which are unique within
66 a function. Reset to 0 by start_function. */
68 int temp_name_counter
;
70 /* Same, but not reset. Local temp variables and global temp variables
71 can have the same name. */
72 static int global_temp_name_counter
;
74 /* Flag used when debugging spew.c */
76 extern int spew_debug
;
78 /* Nonzero if we're done parsing and into end-of-file activities. */
82 /* Functions called along with real static constructors and destructors. */
84 tree static_ctors
, static_dtors
;
86 /* The current open namespace, and :: */
88 tree current_namespace
;
89 tree global_namespace
;
92 /* C (and C++) language-specific option variables. */
94 /* Nonzero means allow type mismatches in conditional expressions;
95 just make their values `void'. */
97 int flag_cond_mismatch
;
99 /* Nonzero means give `double' the same size as `float'. */
101 int flag_short_double
;
103 /* Nonzero means don't recognize the keyword `asm'. */
107 /* Nonzero means don't recognize any extension keywords. */
109 int flag_no_gnu_keywords
;
111 /* Nonzero means don't recognize the non-ANSI builtin functions. */
115 /* Nonzero means don't recognize the non-ANSI builtin functions.
118 int flag_no_nonansi_builtin
;
120 /* Nonzero means do some things the same way PCC does. Only provided so
121 the compiler will link. */
123 int flag_traditional
;
125 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
127 int flag_signed_bitfields
= 1;
129 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
133 /* Nonzero means enable obscure ANSI features and disable GNU extensions
134 that might cause ANSI-compliant code to be miscompiled. */
138 /* Nonzero means do emit exported implementations of functions even if
139 they can be inlined. */
141 int flag_implement_inlines
= 1;
143 /* Nonzero means do emit exported implementations of templates, instead of
144 multiple static copies in each file that needs a definition. */
146 int flag_external_templates
;
148 /* Nonzero means that the decision to emit or not emit the implementation of a
149 template depends on where the template is instantiated, rather than where
152 int flag_alt_external_templates
;
154 /* Nonzero means that implicit instantiations will be emitted if needed. */
156 int flag_implicit_templates
= 1;
158 /* Nonzero means warn about implicit declarations. */
160 int warn_implicit
= 1;
162 /* Nonzero means warn when all ctors or dtors are private, and the class
165 int warn_ctor_dtor_privacy
= 1;
167 /* True if we want to implement vtables using "thunks".
168 The default is off. */
170 #ifndef DEFAULT_VTABLE_THUNKS
171 #define DEFAULT_VTABLE_THUNKS 0
173 int flag_vtable_thunks
= DEFAULT_VTABLE_THUNKS
;
175 /* True if we want to deal with repository information. */
177 int flag_use_repository
;
179 /* Nonzero means give string constants the type `const char *'
180 to get extra warnings from them. These warnings will be too numerous
181 to be useful, except in thoroughly ANSIfied programs. */
183 int warn_write_strings
;
185 /* Nonzero means warn about pointer casts that can drop a type qualifier
186 from the pointer target type. */
190 /* Nonzero means warn that dbx info for template class methods isn't fully
193 int warn_template_debugging
;
195 /* Nonzero means warn about sizeof(function) or addition/subtraction
196 of function pointers. */
198 int warn_pointer_arith
= 1;
200 /* Nonzero means warn for any function def without prototype decl. */
202 int warn_missing_prototypes
;
204 /* Nonzero means warn about multiple (redundant) decls for the same single
205 variable or function. */
207 int warn_redundant_decls
;
209 /* Warn if initializer is not completely bracketed. */
211 int warn_missing_braces
;
213 /* Warn about comparison of signed and unsigned values. */
215 int warn_sign_compare
;
217 /* Warn about *printf or *scanf format/argument anomalies. */
221 /* Warn about a subscript that has type char. */
223 int warn_char_subscripts
;
225 /* Warn if a type conversion is done that might have confusing results. */
229 /* Warn if adding () is suggested. */
231 int warn_parentheses
;
233 /* Non-zero means warn in function declared in derived class has the
234 same name as a virtual in the base class, but fails to match the
235 type signature of any virtual function in the base class. */
236 int warn_overloaded_virtual
;
238 /* Non-zero means warn when declaring a class that has a non virtual
239 destructor, when it really ought to have a virtual one. */
242 /* Non-zero means warn when a function is declared extern and later inline. */
243 int warn_extern_inline
;
245 /* Non-zero means warn when the compiler will reorder code. */
248 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
251 /* Non-zero means warn when we convert a pointer to member function
252 into a pointer to (void or function). */
253 int warn_pmf2ptr
= 1;
255 /* Nonzero means warn about violation of some Effective C++ style rules. */
259 /* Nonzero means warn where overload resolution chooses a promotion from
260 unsigned to signed over a conversion to an unsigned of the same size. */
264 /* Nonzero means warn when an old-style cast is used. */
266 int warn_old_style_cast
;
268 /* Warn about #pragma directives that are not recognised. */
270 int warn_unknown_pragmas
= 0; /* Tri state variable. */
272 /* Nonzero means `$' can be in an identifier. */
274 #ifndef DOLLARS_IN_IDENTIFIERS
275 #define DOLLARS_IN_IDENTIFIERS 1
277 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
279 /* Nonzero for -fno-strict-prototype switch: do not consider empty
280 argument prototype to mean function takes no arguments. */
282 int flag_strict_prototype
= 2;
283 int strict_prototype
= 1;
284 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
286 /* Nonzero means that labels can be used as first-class objects */
290 /* Non-zero means to collect statistics which might be expensive
291 and to print them when we are done. */
292 int flag_detailed_statistics
;
294 /* C++ specific flags. */
295 /* Nonzero for -fall-virtual: make every member function (except
296 constructors) lay down in the virtual function table. Calls
297 can then either go through the virtual function table or not,
300 int flag_all_virtual
;
302 /* Zero means that `this' is a *const. This gives nice behavior in the
303 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
304 -2 means we're constructing an object and it has fixed type. */
306 int flag_this_is_variable
;
308 /* Nonzero means memoize our member lookups. */
310 int flag_memoize_lookups
; int flag_save_memoized_contexts
;
312 /* 3 means write out only virtuals function tables `defined'
313 in this implementation file.
314 2 means write out only specific virtual function tables
315 and give them (C) public access.
316 1 means write out virtual function tables and give them
318 0 means write out virtual function tables and give them
319 (C) static access (default).
320 -1 means declare virtual function tables extern. */
324 /* Nonzero means we should attempt to elide constructors when possible.
325 FIXME: This flag is obsolete, and should be torn out along with the
326 old overloading code. */
328 int flag_elide_constructors
;
330 /* Nonzero means recognize and handle signature language constructs. */
332 int flag_handle_signatures
;
334 /* Nonzero means that member functions defined in class scope are
335 inline by default. */
337 int flag_default_inline
= 1;
339 /* Controls whether enums and ints freely convert.
340 1 means with complete freedom.
341 0 means enums can convert to ints, but not vice-versa. */
342 int flag_int_enum_equivalence
;
344 /* Controls whether compiler generates 'type descriptor' that give
345 run-time type information. */
348 /* Nonzero if we wish to output cross-referencing information
349 for the GNU class browser. */
350 extern int flag_gnu_xref
;
352 /* Nonzero if compiler can make `reasonable' assumptions about
353 references and objects. For example, the compiler must be
354 conservative about the following and not assume that `a' is nonnull:
359 In general, it is `reasonable' to assume that for many programs,
360 and better code can be generated in that case. */
362 int flag_assume_nonnull_objects
= 1;
364 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
367 int flag_huge_objects
;
369 /* Nonzero if we want to conserve space in the .o files. We do this
370 by putting uninitialized data and runtime initialized data into
371 .common instead of .data at the expense of not flagging multiple
374 int flag_conserve_space
;
376 /* Nonzero if we want to obey access control semantics. */
378 int flag_access_control
= 1;
380 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
382 int flag_operator_names
;
384 /* Nonzero if we want to check the return value of new and avoid calling
385 constructors if it is a null pointer. */
389 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
390 initialization variables.
391 0: Old rules, set by -fno-for-scope.
392 2: New ANSI rules, set by -ffor-scope.
393 1: Try to implement new ANSI rules, but with backup compatibility
394 (and warnings). This is the default, for now. */
396 int flag_new_for_scope
= 1;
398 /* Nonzero if we want to emit defined symbols with common-like linkage as
399 weak symbols where possible, in order to conform to C++ semantics.
400 Otherwise, emit them as local symbols. */
404 /* Maximum template instantiation depth. Must be at least 17 for ANSI
407 int max_tinst_depth
= 17;
409 /* The name-mangling scheme to use. Must be 1 or greater to support
410 template functions with identical types, but different template
412 int name_mangling_version
= 2;
414 /* Nonzero means that guiding declarations are allowed. */
415 int flag_guiding_decls
;
417 /* Nonzero if squashed mangling is to be performed.
418 This uses the B and K codes to reference previously seen class types
419 and class qualifiers. */
420 int flag_do_squangling
;
423 /* Table of language-dependent -f options.
424 STRING is the option name. VARIABLE is the address of the variable.
425 ON_VALUE is the value to store in VARIABLE
426 if `-fSTRING' is seen as an option.
427 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
429 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
431 {"signed-char", &flag_signed_char
, 1},
432 {"unsigned-char", &flag_signed_char
, 0},
433 {"signed-bitfields", &flag_signed_bitfields
, 1},
434 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
435 {"short-enums", &flag_short_enums
, 1},
436 {"short-double", &flag_short_double
, 1},
437 {"cond-mismatch", &flag_cond_mismatch
, 1},
438 {"squangle", &flag_do_squangling
, 1},
439 {"asm", &flag_no_asm
, 0},
440 {"builtin", &flag_no_builtin
, 0},
441 {"ident", &flag_no_ident
, 0},
442 {"labels-ok", &flag_labels_ok
, 1},
443 {"stats", &flag_detailed_statistics
, 1},
444 {"this-is-variable", &flag_this_is_variable
, 1},
445 {"strict-prototype", &flag_strict_prototype
, 1},
446 {"all-virtual", &flag_all_virtual
, 1},
447 {"memoize-lookups", &flag_memoize_lookups
, 1},
448 {"elide-constructors", &flag_elide_constructors
, 1},
449 {"handle-exceptions", &flag_exceptions
, 1},
450 {"handle-signatures", &flag_handle_signatures
, 1},
451 {"default-inline", &flag_default_inline
, 1},
452 {"dollars-in-identifiers", &dollars_in_ident
, 1},
453 {"enum-int-equiv", &flag_int_enum_equivalence
, 1},
454 {"rtti", &flag_rtti
, 1},
455 {"xref", &flag_gnu_xref
, 1},
456 {"nonnull-objects", &flag_assume_nonnull_objects
, 1},
457 {"implement-inlines", &flag_implement_inlines
, 1},
458 {"external-templates", &flag_external_templates
, 1},
459 {"implicit-templates", &flag_implicit_templates
, 1},
460 {"huge-objects", &flag_huge_objects
, 1},
461 {"conserve-space", &flag_conserve_space
, 1},
462 {"vtable-thunks", &flag_vtable_thunks
, 1},
463 {"access-control", &flag_access_control
, 1},
464 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
465 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
466 {"operator-names", &flag_operator_names
, 1},
467 {"check-new", &flag_check_new
, 1},
468 {"repo", &flag_use_repository
, 1},
469 {"for-scope", &flag_new_for_scope
, 2},
470 {"weak", &flag_weak
, 1}
473 /* Decode the string P as a language-specific option.
474 Return 1 if it is recognized (and handle it);
475 return 0 if not recognized. */
478 lang_decode_option (p
)
481 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
482 flag_writable_strings
= 1,
483 flag_this_is_variable
= 1, flag_new_for_scope
= 0;
484 /* The +e options are for cfront compatibility. They come in as
485 `-+eN', to kludge around gcc.c's argument handling. */
486 else if (p
[0] == '-' && p
[1] == '+' && p
[2] == 'e')
488 int old_write_virtuals
= write_virtuals
;
491 else if (p
[3] == '0')
493 else if (p
[3] == '2')
495 else error ("invalid +e option");
496 if (old_write_virtuals
!= 0
497 && write_virtuals
!= old_write_virtuals
)
498 error ("conflicting +e options given");
500 else if (p
[0] == '-' && p
[1] == 'f')
502 /* Some kind of -f option.
503 P's value is the option sans `-f'.
504 Search for it in the table of options. */
509 /* Try special -f options. */
511 if (!strcmp (p
, "handle-exceptions")
512 || !strcmp (p
, "no-handle-exceptions"))
513 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
515 if (!strcmp (p
, "save-memoized"))
517 flag_memoize_lookups
= 1;
518 flag_save_memoized_contexts
= 1;
521 else if (!strcmp (p
, "no-save-memoized"))
523 flag_memoize_lookups
= 0;
524 flag_save_memoized_contexts
= 0;
527 else if (! strcmp (p
, "alt-external-templates"))
529 flag_external_templates
= 1;
530 flag_alt_external_templates
= 1;
533 else if (! strcmp (p
, "no-alt-external-templates"))
535 flag_alt_external_templates
= 0;
538 else if (!strcmp (p
, "repo"))
540 flag_use_repository
= 1;
541 flag_implicit_templates
= 0;
544 else if (!strcmp (p
, "guiding-decls"))
546 flag_guiding_decls
= 1;
547 name_mangling_version
= 0;
550 else if (!strcmp (p
, "no-guiding-decls"))
552 flag_guiding_decls
= 0;
555 else if (!strcmp (p
, "ansi-overloading"))
557 else if (!strcmp (p
, "no-ansi-overloading"))
559 error ("-fno-ansi-overloading is no longer supported");
562 else if (!strncmp (p
, "template-depth-", 15))
567 if (*endp
>= '0' && *endp
<= '9')
571 error ("Invalid option `%s'", p
- 2);
572 goto template_depth_lose
;
575 max_tinst_depth
= atoi (p
+ 15);
576 template_depth_lose
: ;
578 else if (!strncmp (p
, "name-mangling-version-", 22))
583 if (*endp
>= '0' && *endp
<= '9')
587 error ("Invalid option `%s'", p
- 2);
588 goto mangling_version_lose
;
591 name_mangling_version
= atoi (p
+ 22);
592 mangling_version_lose
: ;
595 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
598 if (!strcmp (p
, lang_f_options
[j
].string
))
600 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
601 /* A goto here would be cleaner,
602 but breaks the vax pcc. */
605 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
606 && ! strcmp (p
+3, lang_f_options
[j
].string
))
608 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
614 else if (p
[0] == '-' && p
[1] == 'W')
618 /* The -W options control the warning behavior of the compiler. */
621 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
624 if (!strcmp (p
, "implicit"))
625 warn_implicit
= setting
;
626 else if (!strcmp (p
, "return-type"))
627 warn_return_type
= setting
;
628 else if (!strcmp (p
, "ctor-dtor-privacy"))
629 warn_ctor_dtor_privacy
= setting
;
630 else if (!strcmp (p
, "write-strings"))
631 warn_write_strings
= setting
;
632 else if (!strcmp (p
, "cast-qual"))
633 warn_cast_qual
= setting
;
634 else if (!strcmp (p
, "char-subscripts"))
635 warn_char_subscripts
= setting
;
636 else if (!strcmp (p
, "pointer-arith"))
637 warn_pointer_arith
= setting
;
638 else if (!strcmp (p
, "missing-prototypes"))
639 warn_missing_prototypes
= setting
;
640 else if (!strcmp (p
, "redundant-decls"))
641 warn_redundant_decls
= setting
;
642 else if (!strcmp (p
, "missing-braces"))
643 warn_missing_braces
= setting
;
644 else if (!strcmp (p
, "sign-compare"))
645 warn_sign_compare
= setting
;
646 else if (!strcmp (p
, "format"))
647 warn_format
= setting
;
648 else if (!strcmp (p
, "conversion"))
649 warn_conversion
= setting
;
650 else if (!strcmp (p
, "parentheses"))
651 warn_parentheses
= setting
;
652 else if (!strcmp (p
, "non-virtual-dtor"))
653 warn_nonvdtor
= setting
;
654 else if (!strcmp (p
, "extern-inline"))
655 warn_extern_inline
= setting
;
656 else if (!strcmp (p
, "reorder"))
657 warn_reorder
= setting
;
658 else if (!strcmp (p
, "synth"))
659 warn_synth
= setting
;
660 else if (!strcmp (p
, "pmf-conversions"))
661 warn_pmf2ptr
= setting
;
662 else if (!strcmp (p
, "effc++"))
664 else if (!strcmp (p
, "sign-promo"))
665 warn_sign_promo
= setting
;
666 else if (!strcmp (p
, "old-style-cast"))
667 warn_old_style_cast
= setting
;
668 else if (!strcmp (p
, "unknown-pragmas"))
669 /* Set to greater than 1, so that even unknown pragmas in
670 system headers will be warned about. */
671 warn_unknown_pragmas
= setting
* 2;
672 else if (!strcmp (p
, "comment"))
673 ; /* cpp handles this one. */
674 else if (!strcmp (p
, "comments"))
675 ; /* cpp handles this one. */
676 else if (!strcmp (p
, "trigraphs"))
677 ; /* cpp handles this one. */
678 else if (!strcmp (p
, "import"))
679 ; /* cpp handles this one. */
680 else if (!strcmp (p
, "all"))
682 warn_return_type
= setting
;
683 warn_unused
= setting
;
684 warn_implicit
= setting
;
685 warn_ctor_dtor_privacy
= setting
;
686 warn_switch
= setting
;
687 warn_format
= setting
;
688 warn_parentheses
= setting
;
689 warn_missing_braces
= setting
;
690 warn_sign_compare
= setting
;
691 warn_extern_inline
= setting
;
692 warn_nonvdtor
= setting
;
693 /* We save the value of warn_uninitialized, since if they put
694 -Wuninitialized on the command line, we need to generate a
695 warning about not using it without also specifying -O. */
696 if (warn_uninitialized
!= 1)
697 warn_uninitialized
= (setting
? 2 : 0);
698 warn_template_debugging
= setting
;
699 warn_reorder
= setting
;
700 warn_sign_promo
= setting
;
701 /* Only warn about unknown pragmas that are not in system
703 warn_unknown_pragmas
= 1;
706 else if (!strcmp (p
, "overloaded-virtual"))
707 warn_overloaded_virtual
= setting
;
710 else if (!strcmp (p
, "-ansi"))
711 flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
712 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
714 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
715 it's probably safe to assume no sane person would ever want to use this
716 under normal circumstances. */
717 else if (!strcmp (p
, "-spew-debug"))
726 /* Incorporate `const' and `volatile' qualifiers for member functions.
727 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
728 QUALS is a list of qualifiers. */
731 grok_method_quals (ctype
, function
, quals
)
732 tree ctype
, function
, quals
;
734 tree fntype
= TREE_TYPE (function
);
735 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
739 extern tree ridpointers
[];
741 if (TREE_VALUE (quals
) == ridpointers
[(int)RID_CONST
])
743 if (TYPE_READONLY (ctype
))
744 error ("duplicate `%s' %s",
745 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
746 (TREE_CODE (function
) == FUNCTION_DECL
747 ? "for member function" : "in type declaration"));
748 ctype
= build_type_variant (ctype
, 1, TYPE_VOLATILE (ctype
));
749 build_pointer_type (ctype
);
751 else if (TREE_VALUE (quals
) == ridpointers
[(int)RID_VOLATILE
])
753 if (TYPE_VOLATILE (ctype
))
754 error ("duplicate `%s' %s",
755 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
756 (TREE_CODE (function
) == FUNCTION_DECL
757 ? "for member function" : "in type declaration"));
758 ctype
= build_type_variant (ctype
, TYPE_READONLY (ctype
), 1);
759 build_pointer_type (ctype
);
762 my_friendly_abort (20);
763 quals
= TREE_CHAIN (quals
);
766 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
767 (TREE_CODE (fntype
) == METHOD_TYPE
768 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
769 : TYPE_ARG_TYPES (fntype
)));
771 fntype
= build_exception_variant (fntype
, raises
);
773 TREE_TYPE (function
) = fntype
;
777 /* Warn when -fexternal-templates is used and #pragma
778 interface/implementation is not used all the times it should be,
782 warn_if_unknown_interface (decl
)
785 static int already_warned
= 0;
786 if (already_warned
++)
789 if (flag_alt_external_templates
)
791 struct tinst_level
*til
= tinst_for_decl ();
793 char *sf
= input_filename
;
798 input_filename
= til
->file
;
800 cp_warning ("template `%#D' instantiated in file without #pragma interface",
806 cp_warning_at ("template `%#D' defined in file without #pragma interface",
810 /* A subroutine of the parser, to handle a component list. */
813 grok_x_components (specs
, components
)
814 tree specs
, components
;
816 register tree t
, x
, tcode
;
818 /* We just got some friends. They have been recorded elsewhere. */
819 if (components
== void_type_node
)
822 if (components
== NULL_TREE
)
824 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
828 error ("error in component specification");
832 switch (TREE_CODE (t
))
835 /* Static anonymous unions come out as VAR_DECLs. */
836 if (TREE_CODE (TREE_TYPE (t
)) == UNION_TYPE
837 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t
))))
840 /* We return SPECS here, because in the parser it was ending
841 up with not doing anything to $$, which is what SPECS
847 /* This code may be needed for UNION_TYPEs as
849 tcode
= record_type_node
;
850 if (CLASSTYPE_DECLARED_CLASS (t
))
851 tcode
= class_type_node
;
852 else if (IS_SIGNATURE (t
))
853 tcode
= signature_type_node
;
855 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
861 if (TREE_CODE (t
) == UNION_TYPE
)
862 tcode
= union_type_node
;
864 tcode
= enum_type_node
;
866 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
867 if (TREE_CODE (t
) == UNION_TYPE
868 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))
870 /* See also shadow_tag. */
872 struct pending_inline
**p
;
874 x
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, t
);
876 /* Wipe out memory of synthesized methods */
877 TYPE_HAS_CONSTRUCTOR (t
) = 0;
878 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
879 TYPE_HAS_INIT_REF (t
) = 0;
880 TYPE_HAS_CONST_INIT_REF (t
) = 0;
881 TYPE_HAS_ASSIGN_REF (t
) = 0;
882 TYPE_HAS_ASSIGNMENT (t
) = 0;
883 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
885 q
= &TYPE_METHODS (t
);
888 if (DECL_ARTIFICIAL (*q
))
889 *q
= TREE_CHAIN (*q
);
891 q
= &TREE_CHAIN (*q
);
893 if (TYPE_METHODS (t
))
894 error ("an anonymous union cannot have function members");
896 p
= &pending_inlines
;
897 for (; *p
; *p
= (*p
)->next
)
898 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
901 else if (TREE_CODE (t
) == ENUMERAL_TYPE
)
902 x
= grok_enum_decls (NULL_TREE
);
909 if (t
!= void_type_node
)
910 error ("empty component declaration");
915 /* There may or may not be any enum decls to grok, but
916 grok_enum_decls will just return components, if there aren't
917 any. We used to try to figure out whether or not there were
918 any enum decls based on the type of components, but that's too
919 hard; it might be something like `enum { a } *p;'. */
920 return grok_enum_decls (components
);
923 /* Classes overload their constituent function names automatically.
924 When a function name is declared in a record structure,
925 its name is changed to it overloaded name. Since names for
926 constructors and destructors can conflict, we place a leading
929 CNAME is the name of the class we are grokking for.
931 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
933 FLAGS contains bits saying what's special about today's
934 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
936 If FUNCTION is a destructor, then we must add the `auto-delete' field
937 as a second parameter. There is some hair associated with the fact
938 that we must "declare" this variable in the manner consistent with the
939 way the rest of the arguments were declared.
941 QUALS are the qualifiers for the this pointer. */
944 grokclassfn (ctype
, cname
, function
, flags
, quals
)
945 tree ctype
, cname
, function
;
946 enum overload_flags flags
;
949 tree fn_name
= DECL_NAME (function
);
953 tree fntype
= TREE_TYPE (function
);
954 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
956 if (fn_name
== NULL_TREE
)
958 error ("name missing for member function");
959 fn_name
= get_identifier ("<anonymous>");
960 DECL_NAME (function
) = fn_name
;
964 qualtype
= grok_method_quals (ctype
, function
, quals
);
968 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
969 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
971 /* Must add the class instance variable up front. */
972 /* Right now we just make this a pointer. But later
973 we may wish to make it special. */
974 tree type
= TREE_VALUE (arg_types
);
977 if ((flag_this_is_variable
> 0)
978 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
981 if (DECL_CONSTRUCTOR_P (function
))
983 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype
))
985 DECL_CONSTRUCTOR_FOR_VBASE_P (function
) = 1;
986 /* In this case we need "in-charge" flag saying whether
987 this constructor is responsible for initialization
988 of virtual baseclasses or not. */
989 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
990 /* Mark the artificial `__in_chrg' parameter as "artificial". */
991 SET_DECL_ARTIFICIAL (parm
);
992 DECL_ARG_TYPE (parm
) = integer_type_node
;
993 TREE_READONLY (parm
) = 1;
994 TREE_CHAIN (parm
) = last_function_parms
;
995 last_function_parms
= parm
;
999 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
1000 /* Mark the artificial `this' parameter as "artificial". */
1001 SET_DECL_ARTIFICIAL (parm
);
1002 DECL_ARG_TYPE (parm
) = type
;
1003 /* We can make this a register, so long as we don't
1004 accidentally complain if someone tries to take its address. */
1005 DECL_REGISTER (parm
) = 1;
1007 TREE_READONLY (parm
) = 1;
1008 TREE_CHAIN (parm
) = last_function_parms
;
1009 last_function_parms
= parm
;
1012 if (flags
== DTOR_FLAG
)
1015 int len
= sizeof (DESTRUCTOR_DECL_PREFIX
)-1;
1017 arg_types
= hash_tree_chain (integer_type_node
, void_list_node
);
1018 TREE_SIDE_EFFECTS (arg_types
) = 1;
1019 /* Build the overload name. It will look like `7Example'. */
1020 if (IDENTIFIER_TYPE_VALUE (cname
))
1021 dbuf
= build_overload_name (IDENTIFIER_TYPE_VALUE (cname
), 1, 1);
1022 else if (IDENTIFIER_LOCAL_VALUE (cname
))
1023 dbuf
= build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname
)),
1026 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
1027 it's defined out of the class definition, since poplevel_class wipes
1028 it out. This used to be internal error 346. */
1029 dbuf
= build_overload_name (ctype
, 1, 1);
1030 buf
= (char *) alloca (strlen (dbuf
) + sizeof (DESTRUCTOR_DECL_PREFIX
));
1031 bcopy (DESTRUCTOR_DECL_PREFIX
, buf
, len
);
1034 DECL_ASSEMBLER_NAME (function
) = get_identifier (buf
);
1035 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
1036 /* Mark the artificial `__in_chrg' parameter as "artificial". */
1037 SET_DECL_ARTIFICIAL (parm
);
1038 TREE_READONLY (parm
) = 1;
1039 DECL_ARG_TYPE (parm
) = integer_type_node
;
1040 /* This is the same chain as DECL_ARGUMENTS (...). */
1041 TREE_CHAIN (last_function_parms
) = parm
;
1043 fntype
= build_cplus_method_type (qualtype
, void_type_node
,
1047 fntype
= build_exception_variant (fntype
, raises
);
1049 TREE_TYPE (function
) = fntype
;
1050 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
1054 tree these_arg_types
;
1056 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function
))
1058 arg_types
= hash_tree_chain (integer_type_node
,
1059 TREE_CHAIN (arg_types
));
1060 fntype
= build_cplus_method_type (qualtype
,
1061 TREE_TYPE (TREE_TYPE (function
)),
1065 fntype
= build_exception_variant (fntype
, raises
);
1067 TREE_TYPE (function
) = fntype
;
1068 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1071 these_arg_types
= arg_types
;
1073 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
1074 /* Only true for static member functions. */
1075 these_arg_types
= hash_tree_chain (build_pointer_type (qualtype
),
1078 DECL_ASSEMBLER_NAME (function
)
1079 = build_decl_overload (fn_name
, these_arg_types
,
1080 1 + DECL_CONSTRUCTOR_P (function
));
1083 DECL_ARGUMENTS (function
) = last_function_parms
;
1084 /* First approximations. */
1085 DECL_CONTEXT (function
) = ctype
;
1086 DECL_CLASS_CONTEXT (function
) = ctype
;
1089 /* Work on the expr used by alignof (this is only called by the parser). */
1098 if (processing_template_decl
)
1099 return build_min (ALIGNOF_EXPR
, sizetype
, expr
);
1101 if (TREE_CODE (expr
) == COMPONENT_REF
1102 && DECL_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1103 error ("`__alignof__' applied to a bit-field");
1105 if (TREE_CODE (expr
) == INDIRECT_REF
)
1107 best
= t
= TREE_OPERAND (expr
, 0);
1108 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1110 while (TREE_CODE (t
) == NOP_EXPR
1111 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1114 t
= TREE_OPERAND (t
, 0);
1115 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1116 if (thisalign
> bestalign
)
1117 best
= t
, bestalign
= thisalign
;
1119 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1123 /* ANSI says arrays and fns are converted inside comma.
1124 But we can't convert them in build_compound_expr
1125 because that would break commas in lvalues.
1126 So do the conversion here if operand was a comma. */
1127 if (TREE_CODE (expr
) == COMPOUND_EXPR
1128 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1129 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1130 expr
= default_conversion (expr
);
1131 return c_alignof (TREE_TYPE (expr
));
1135 /* Create an ARRAY_REF, checking for the user doing things backwards
1139 grok_array_decl (array_expr
, index_exp
)
1140 tree array_expr
, index_exp
;
1142 tree type
= TREE_TYPE (array_expr
);
1143 tree p1
, p2
, i1
, i2
;
1145 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1146 return error_mark_node
;
1147 if (processing_template_decl
)
1148 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
1149 array_expr
, index_exp
);
1151 if (type
== NULL_TREE
)
1153 /* Something has gone very wrong. Assume we are mistakenly reducing
1154 an expression instead of a declaration. */
1155 error ("parser may be lost: is there a '{' missing somewhere?");
1159 if (TREE_CODE (type
) == OFFSET_TYPE
1160 || TREE_CODE (type
) == REFERENCE_TYPE
)
1161 type
= TREE_TYPE (type
);
1163 /* If they have an `operator[]', use that. */
1164 if (IS_AGGR_TYPE (type
) || IS_AGGR_TYPE (TREE_TYPE (index_exp
)))
1165 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1166 array_expr
, index_exp
, NULL_TREE
);
1168 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1170 if (TREE_CODE (type
) == ARRAY_TYPE
)
1173 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1175 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1178 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1180 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1181 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1183 if ((p1
&& i2
) && (i1
&& p2
))
1184 error ("ambiguous conversion for array subscript");
1187 array_expr
= p1
, index_exp
= i2
;
1189 array_expr
= p2
, index_exp
= i1
;
1192 cp_error ("invalid types `%T[%T]' for array subscript",
1193 type
, TREE_TYPE (index_exp
));
1194 return error_mark_node
;
1197 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1198 error ("ambiguous conversion for array subscript");
1200 return build_array_ref (array_expr
, index_exp
);
1203 /* Given the cast expression EXP, checking out its validity. Either return
1204 an error_mark_node if there was an unavoidable error, return a cast to
1205 void for trying to delete a pointer w/ the value 0, or return the
1206 call to delete. If DOING_VEC is 1, we handle things differently
1207 for doing an array delete. If DOING_VEC is 2, they gave us the
1208 array size as an argument to delete.
1209 Implements ARM $5.3.4. This is called from the parser. */
1212 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1214 int doing_vec
, use_global_delete
;
1218 enum tree_code code
;
1219 /* For a regular vector delete (aka, no size argument) we will pass
1220 this down as a NULL_TREE into build_vec_delete. */
1221 tree maxindex
= NULL_TREE
;
1223 if (exp
== error_mark_node
)
1226 if (processing_template_decl
)
1228 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
1229 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
1230 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
1235 if (TREE_CODE (t
) == OFFSET_REF
)
1236 t
= resolve_offset_ref (t
);
1237 t
= stabilize_reference (convert_from_reference (t
));
1238 type
= TREE_TYPE (t
);
1239 code
= TREE_CODE (type
);
1244 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1245 pedwarn ("anachronistic use of array size in vector delete");
1250 if (code
!= POINTER_TYPE
)
1252 cp_error ("type `%#T' argument given to `delete', expected pointer",
1254 return error_mark_node
;
1257 /* Deleting a pointer with the value zero is valid and has no effect. */
1258 if (integer_zerop (t
))
1259 return build1 (NOP_EXPR
, void_type_node
, t
);
1262 if (code
== POINTER_TYPE
)
1265 /* As of Valley Forge, you can delete a pointer to const. */
1266 if (TREE_READONLY (TREE_TYPE (type
)))
1268 error ("`const *' cannot be deleted");
1269 return error_mark_node
;
1272 /* You can't delete functions. */
1273 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1275 error ("cannot delete a function");
1276 return error_mark_node
;
1281 /* If the type has no destructor, then we should build a regular
1282 delete, instead of a vector delete. Otherwise, we would end
1283 up passing a bogus offset into __builtin_delete, which is
1284 not expecting it. */
1286 && TREE_CODE (type
) == POINTER_TYPE
1287 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type
)))
1290 use_global_delete
= 1;
1295 return build_vec_delete (t
, maxindex
, integer_one_node
,
1296 integer_two_node
, use_global_delete
);
1299 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1300 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1302 /* Only do access checking here; we'll be calling op delete
1303 from the destructor. */
1304 tree tmp
= build_op_delete_call (DELETE_EXPR
, t
,
1305 size_zero_node
, LOOKUP_NORMAL
);
1306 if (tmp
== error_mark_node
)
1307 return error_mark_node
;
1310 return build_delete (type
, t
, integer_three_node
,
1311 LOOKUP_NORMAL
, use_global_delete
);
1315 /* Report an error if the indicated template declaration is not the
1316 sort of thing that should be a member template. */
1319 check_member_template (tmpl
)
1324 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 0);
1325 decl
= DECL_TEMPLATE_RESULT (tmpl
);
1327 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1329 if (current_function_decl
)
1330 /* 14.5.2.2 [temp.mem]
1332 A local class shall not have member templates. */
1333 cp_error ("declaration of of member template `%#D' in local class",
1336 if (DECL_VIRTUAL_P (decl
))
1338 /* 14.5.2.3 [temp.mem]
1340 A member function template shall not be virtual. */
1342 ("invalid use of `virtual' in template declaration of `%#D'",
1344 DECL_VIRTUAL_P (decl
) = 0;
1347 /* The debug-information generating code doesn't know what to do
1348 with member templates. */
1349 DECL_IGNORED_P (tmpl
) = 1;
1351 else if (TREE_CODE (decl
) == TYPE_DECL
1352 && IS_AGGR_TYPE (TREE_TYPE (decl
)))
1354 if (current_function_decl
)
1355 /* 14.5.2.2 [temp.mem]
1357 A local class shall not have member templates. */
1358 cp_error ("declaration of of member template `%#D' in local class",
1362 cp_error ("template declaration of `%#D'", decl
);
1365 /* Sanity check: report error if this function FUNCTION is not
1366 really a member of the class (CTYPE) it is supposed to belong to.
1367 CNAME is the same here as it is for grokclassfn above. */
1370 check_classfn (ctype
, function
)
1371 tree ctype
, function
;
1373 tree fn_name
= DECL_NAME (function
);
1375 tree method_vec
= CLASSTYPE_METHOD_VEC (complete_type (ctype
));
1378 tree templates
= NULL_TREE
;
1380 if (method_vec
!= 0)
1382 methods
= &TREE_VEC_ELT (method_vec
, 0);
1383 end
= TREE_VEC_END (method_vec
);
1385 /* First suss out ctors and dtors. */
1386 if (*methods
&& fn_name
== DECL_NAME (*methods
)
1387 && DECL_CONSTRUCTOR_P (function
))
1389 if (*++methods
&& fn_name
== DECL_NAME (*methods
)
1390 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
)))
1393 while (++methods
!= end
)
1396 if (fn_name
== DECL_NAME (*methods
))
1399 for (fndecl
= *methods
; fndecl
!= NULL_TREE
;
1400 fndecl
= DECL_CHAIN (fndecl
))
1402 /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL is
1403 not mangled, so the check below does not work
1404 correctly in that case. */
1405 if (TREE_CODE (function
) != TEMPLATE_DECL
1406 && TREE_CODE (fndecl
) != TEMPLATE_DECL
1407 && (DECL_ASSEMBLER_NAME (function
)
1408 == DECL_ASSEMBLER_NAME (fndecl
)))
1411 /* We cannot simply call decls_match because this
1412 doesn't work for static member functions that are
1413 pretending to be methods, and because the name
1414 may have been changed by asm("new_name"). */
1415 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1417 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1418 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1420 /* Get rid of the this parameter on functions that become
1422 if (DECL_STATIC_FUNCTION_P (fndecl
)
1423 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1424 p1
= TREE_CHAIN (p1
);
1426 if (comptypes (TREE_TYPE (TREE_TYPE (function
)),
1427 TREE_TYPE (TREE_TYPE (fndecl
)), 1)
1428 && compparms (p1
, p2
, 3)
1429 && (DECL_TEMPLATE_SPECIALIZATION (function
)
1430 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
1431 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
1432 || (DECL_TI_TEMPLATE (function
)
1433 == DECL_TI_TEMPLATE (fndecl
))))
1436 if (is_member_template (fndecl
))
1437 /* This function might be an instantiation
1438 or specialization of fndecl. */
1440 scratch_tree_cons (NULL_TREE
, fndecl
, templates
);
1445 else if (TREE_CODE (fndecl
) == TEMPLATE_DECL
1446 && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl
))
1447 && IDENTIFIER_TYPENAME_P (fn_name
))
1448 /* The method in the class is a member template
1449 conversion operator. We are declaring another
1450 conversion operator. It is possible that even though
1451 the names don't match, there is some specialization
1454 scratch_tree_cons (NULL_TREE
, fndecl
, templates
);
1459 /* This function might be an instantiation or a specialization.
1460 We should verify that this is possible. If it is, we must
1461 somehow add the new declaration to the method vector for the
1462 class. Perhaps we should use add_method? For now, we simply
1463 return NULL_TREE, which lets the caller know that this
1464 function is new, but we don't print an error message. */
1469 tree fndecl
= *methods
;
1470 cp_error ("prototype for `%#D' does not match any in class `%T'",
1472 cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl
) ? "s are" : " is",
1474 while (fndecl
= DECL_CHAIN (fndecl
), fndecl
)
1475 cp_error_at (" %#D", fndecl
);
1480 cp_error ("no `%#D' member function declared in class `%T'",
1484 /* If we did not find the method in the class, add it to avoid
1486 add_method (ctype
, methods
, function
);
1490 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1491 of a structure component, returning a FIELD_DECL node.
1492 QUALS is a list of type qualifiers for this decl (such as for declaring
1493 const member functions).
1495 This is done during the parsing of the struct declaration.
1496 The FIELD_DECL nodes are chained together and the lot of them
1497 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1501 If class A defines that certain functions in class B are friends, then
1502 the way I have set things up, it is B who is interested in permission
1503 granted by A. However, it is in A's context that these declarations
1504 are parsed. By returning a void_type_node, class A does not attempt
1505 to incorporate the declarations of the friends within its structure.
1507 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1508 CHANGES TO CODE IN `start_method'. */
1511 grokfield (declarator
, declspecs
, init
, asmspec_tree
, attrlist
)
1512 tree declarator
, declspecs
, init
, asmspec_tree
, attrlist
;
1514 register tree value
;
1516 int flags
= LOOKUP_ONLYCONVERTING
;
1518 /* Convert () initializers to = initializers. */
1519 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1520 && TREE_CODE (declarator
) == CALL_EXPR
1521 && TREE_OPERAND (declarator
, 0)
1522 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1523 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1524 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1526 init
= TREE_OPERAND (declarator
, 1);
1527 declarator
= TREE_OPERAND (declarator
, 0);
1531 if (declspecs
== NULL_TREE
1532 && TREE_CODE (declarator
) == SCOPE_REF
1533 && TREE_CODE (TREE_OPERAND (declarator
, 1)) == IDENTIFIER_NODE
)
1535 /* Access declaration */
1536 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
1538 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
1539 pop_nested_class (1);
1540 return do_class_using_decl (declarator
);
1544 && TREE_CODE (init
) == TREE_LIST
1545 && TREE_VALUE (init
) == error_mark_node
1546 && TREE_CHAIN (init
) == NULL_TREE
)
1549 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, NULL_TREE
);
1551 return value
; /* friend or constructor went bad. */
1553 /* Pass friendly classes back. */
1554 if (TREE_CODE (value
) == VOID_TYPE
)
1555 return void_type_node
;
1557 if (DECL_NAME (value
) != NULL_TREE
1558 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1559 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1560 cp_error ("member `%D' conflicts with virtual function table field name",
1563 /* Stash away type declarations. */
1564 if (TREE_CODE (value
) == TYPE_DECL
)
1566 DECL_NONLOCAL (value
) = 1;
1567 DECL_CONTEXT (value
) = current_class_type
;
1568 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1569 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
1571 pushdecl_class_level (value
);
1575 if (IS_SIGNATURE (current_class_type
)
1576 && TREE_CODE (value
) != FUNCTION_DECL
)
1578 error ("field declaration not allowed in signature");
1579 return void_type_node
;
1582 if (DECL_IN_AGGR_P (value
))
1584 cp_error ("`%D' is already defined in the class %T", value
,
1585 DECL_CONTEXT (value
));
1586 return void_type_node
;
1590 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1594 if (IS_SIGNATURE (current_class_type
)
1595 && TREE_CODE (value
) == FUNCTION_DECL
)
1597 error ("function declarations cannot have initializers in signature");
1600 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1602 grok_function_init (value
, init
);
1605 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1606 /* Already complained in grokdeclarator. */
1610 /* We allow initializers to become parameters to base
1612 if (TREE_CODE (init
) == TREE_LIST
)
1614 if (TREE_CHAIN (init
) == NULL_TREE
)
1615 init
= TREE_VALUE (init
);
1617 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1620 if (TREE_CODE (init
) == CONST_DECL
)
1621 init
= DECL_INITIAL (init
);
1622 else if (TREE_READONLY_DECL_P (init
))
1623 init
= decl_constant_value (init
);
1624 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1625 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1626 my_friendly_assert (TREE_PERMANENT (init
), 192);
1627 if (init
== error_mark_node
)
1628 /* We must make this look different than `error_mark_node'
1629 because `decl_const_value' would mis-interpret it
1630 as only meaning that this VAR_DECL is defined. */
1631 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1632 else if (processing_template_decl
)
1634 else if (! TREE_CONSTANT (init
))
1636 /* We can allow references to things that are effectively
1637 static, since references are initialized with the address. */
1638 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1639 || (TREE_STATIC (init
) == 0
1640 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1641 || DECL_EXTERNAL (init
) == 0)))
1643 error ("field initializer is not constant");
1644 init
= error_mark_node
;
1650 /* The corresponding pop_obstacks is in cp_finish_decl. */
1651 push_obstacks_nochange ();
1653 if (processing_template_decl
&& ! current_function_decl
1654 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1655 value
= push_template_decl (value
);
1658 cplus_decl_attributes (value
, TREE_PURPOSE (attrlist
),
1659 TREE_VALUE (attrlist
));
1661 if (TREE_CODE (value
) == VAR_DECL
)
1663 my_friendly_assert (TREE_PUBLIC (value
), 0);
1665 /* We cannot call pushdecl here, because that would
1666 fill in the value of our TREE_CHAIN. Instead, we
1667 modify cp_finish_decl to do the right thing, namely, to
1668 put this decl out straight away. */
1669 /* current_class_type can be NULL_TREE in case of error. */
1670 if (asmspec
== 0 && current_class_type
)
1672 TREE_PUBLIC (value
) = 1;
1673 DECL_INITIAL (value
) = error_mark_node
;
1674 DECL_ASSEMBLER_NAME (value
)
1675 = build_static_name (current_class_type
, DECL_NAME (value
));
1677 if (! processing_template_decl
)
1678 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1680 /* Static consts need not be initialized in the class definition. */
1681 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1683 static int explanation
= 0;
1685 error ("initializer invalid for static member with constructor");
1686 if (explanation
++ == 0)
1687 error ("(you really want to initialize it separately)");
1690 /* Force the compiler to know when an uninitialized static
1691 const member is being used. */
1692 if (TYPE_READONLY (value
) && init
== 0)
1693 TREE_USED (value
) = 1;
1694 DECL_INITIAL (value
) = init
;
1695 DECL_IN_AGGR_P (value
) = 1;
1696 DECL_CONTEXT (value
) = current_class_type
;
1697 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1699 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1700 pushdecl_class_level (value
);
1703 if (TREE_CODE (value
) == FIELD_DECL
)
1707 /* This must override the asm specifier which was placed
1708 by grokclassfn. Lay this out fresh. */
1709 DECL_RTL (value
) = NULL_RTX
;
1710 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1712 if (DECL_INITIAL (value
) == error_mark_node
)
1713 init
= error_mark_node
;
1714 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1715 DECL_INITIAL (value
) = init
;
1716 DECL_IN_AGGR_P (value
) = 1;
1719 if (TREE_CODE (value
) == FUNCTION_DECL
)
1721 check_default_args (value
);
1722 if (DECL_CHAIN (value
) != NULL_TREE
)
1724 /* Need a fresh node here so that we don't get circularity
1725 when we link these together. */
1726 value
= copy_node (value
);
1727 /* When does this happen? */
1728 my_friendly_assert (init
== NULL_TREE
, 193);
1732 /* This must override the asm specifier which was placed
1733 by grokclassfn. Lay this out fresh. */
1734 DECL_RTL (value
) = NULL_RTX
;
1735 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1737 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1739 /* Pass friends back this way. */
1740 if (DECL_FRIEND_P (value
))
1741 return void_type_node
;
1743 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1744 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1745 cp_error ("method `%#D' of local class must be defined in class body",
1749 DECL_IN_AGGR_P (value
) = 1;
1752 my_friendly_abort (21);
1757 /* Like `grokfield', but for bitfields.
1758 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1761 grokbitfield (declarator
, declspecs
, width
)
1762 tree declarator
, declspecs
, width
;
1764 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1767 if (! value
) return NULL_TREE
; /* friends went bad. */
1769 /* Pass friendly classes back. */
1770 if (TREE_CODE (value
) == VOID_TYPE
)
1771 return void_type_node
;
1773 if (TREE_CODE (value
) == TYPE_DECL
)
1775 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1779 if (IS_SIGNATURE (current_class_type
))
1781 error ("field declaration not allowed in signature");
1782 return void_type_node
;
1785 if (DECL_IN_AGGR_P (value
))
1787 cp_error ("`%D' is already defined in the class %T", value
,
1788 DECL_CONTEXT (value
));
1789 return void_type_node
;
1792 GNU_xref_member (current_class_name
, value
);
1794 if (TREE_STATIC (value
))
1796 cp_error ("static member `%D' cannot be a bitfield", value
);
1799 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1801 if (width
!= error_mark_node
)
1803 constant_expression_warning (width
);
1804 DECL_INITIAL (value
) = width
;
1805 DECL_BIT_FIELD (value
) = 1;
1808 DECL_IN_AGGR_P (value
) = 1;
1813 grokoptypename (declspecs
, declarator
)
1814 tree declspecs
, declarator
;
1816 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1817 return build_typename_overload (t
);
1820 /* When a function is declared with an initializer,
1821 do the right thing. Currently, there are two possibilities:
1826 // initialization possibility #1.
1827 virtual void f () = 0;
1849 // initialization possibility #2
1856 copy_assignment_arg_p (parmtype
, virtualp
)
1860 if (current_class_type
== NULL_TREE
)
1863 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1864 parmtype
= TREE_TYPE (parmtype
);
1866 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1868 /* Non-standard hack to support old Booch components. */
1869 || (! virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
))
1878 grok_function_init (decl
, init
)
1882 /* An initializer for a function tells how this function should
1884 tree type
= TREE_TYPE (decl
);
1886 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1887 cp_error ("initializer specified for non-member function `%D'", decl
);
1889 /* We'll check for this in finish_struct_1. */
1890 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1891 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1893 else if (integer_zerop (init
))
1896 /* Mark this function as being "defined". */
1897 DECL_INITIAL (decl
) = error_mark_node
;
1898 /* pure virtual destructors must be defined. */
1899 /* pure virtual needs to be defined (as abort) only when put in
1900 vtbl. For wellformed call, it should be itself. pr4737 */
1901 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1903 extern tree abort_fndecl
;
1904 /* Give this node rtl from `abort'. */
1905 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1908 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1909 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1912 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1914 if (copy_assignment_arg_p (parmtype
, 1))
1915 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1919 cp_error ("invalid initializer for virtual method `%D'", decl
);
1923 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1924 tree decl
, attributes
, prefix_attributes
;
1926 if (decl
== NULL_TREE
|| decl
== void_type_node
)
1929 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1930 decl
= DECL_TEMPLATE_RESULT (decl
);
1932 decl_attributes (decl
, attributes
, prefix_attributes
);
1934 if (TREE_CODE (decl
) == TYPE_DECL
)
1935 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
1938 /* CONSTRUCTOR_NAME:
1939 Return the name for the constructor (or destructor) for the
1940 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1941 IDENTIFIER_NODE. When given a template, this routine doesn't
1942 lose the specialization. */
1945 constructor_name_full (thing
)
1948 if (TREE_CODE (thing
) == TEMPLATE_TYPE_PARM
1949 || TREE_CODE (thing
) == TEMPLATE_TEMPLATE_PARM
1950 || TREE_CODE (thing
) == TYPENAME_TYPE
)
1951 thing
= TYPE_NAME (thing
);
1952 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
1954 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
1955 thing
= DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing
), 0));
1957 thing
= TYPE_NAME (thing
);
1959 if (TREE_CODE (thing
) == TYPE_DECL
1960 || (TREE_CODE (thing
) == TEMPLATE_DECL
1961 && TREE_CODE (DECL_TEMPLATE_RESULT (thing
)) == TYPE_DECL
))
1962 thing
= DECL_NAME (thing
);
1963 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
1967 /* CONSTRUCTOR_NAME:
1968 Return the name for the constructor (or destructor) for the
1969 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1970 IDENTIFIER_NODE. When given a template, return the plain
1971 unspecialized name. */
1974 constructor_name (thing
)
1978 thing
= constructor_name_full (thing
);
1979 t
= IDENTIFIER_TEMPLATE (thing
);
1985 /* Cache the value of this class's main virtual function table pointer
1986 in a register variable. This will save one indirection if a
1987 more than one virtual function call is made this function. */
1992 extern tree base_init_expr
;
1994 if (base_init_expr
== 0
1995 && DECL_CONSTRUCTOR_P (current_function_decl
))
1997 if (processing_template_decl
)
1998 add_tree (build_min_nt
2000 current_member_init_list
, current_base_init_list
));
2002 emit_base_init (current_class_type
, 0);
2006 /* Record the existence of an addressable inline function. */
2009 mark_inline_for_output (decl
)
2012 decl
= DECL_MAIN_VARIANT (decl
);
2013 if (DECL_SAVED_INLINE (decl
))
2015 my_friendly_assert (TREE_PERMANENT (decl
), 363);
2016 DECL_SAVED_INLINE (decl
) = 1;
2018 if (DECL_PENDING_INLINE_INFO (decl
) != 0
2019 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
2021 struct pending_inline
*t
= pending_inlines
;
2022 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
2025 if (t
== DECL_PENDING_INLINE_INFO (decl
))
2031 t
= DECL_PENDING_INLINE_INFO (decl
);
2032 t
->next
= pending_inlines
;
2033 pending_inlines
= t
;
2035 DECL_PENDING_INLINE_INFO (decl
) = 0;
2038 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
2044 temp_name_counter
= 0;
2047 /* Hand off a unique name which can be used for variable we don't really
2048 want to know about anyway, for example, the anonymous variables which
2049 are needed to make references work. Declare this thing so we can use it.
2050 The variable created will be of type TYPE.
2052 STATICP is nonzero if this variable should be static. */
2055 get_temp_name (type
, staticp
)
2059 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2061 int toplev
= toplevel_bindings_p ();
2063 push_obstacks_nochange ();
2064 if (toplev
|| staticp
)
2066 end_temporary_allocation ();
2067 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2068 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2072 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2073 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2075 TREE_USED (decl
) = 1;
2076 TREE_STATIC (decl
) = staticp
;
2077 DECL_ARTIFICIAL (decl
) = 1;
2079 /* If this is a local variable, then lay out its rtl now.
2080 Otherwise, callers of this function are responsible for dealing
2081 with this variable's rtl. */
2085 expand_decl_init (decl
);
2092 /* Get a variable which we can use for multiple assignments.
2093 It is not entered into current_binding_level, because
2094 that breaks things when it comes time to do final cleanups
2095 (which take place "outside" the binding contour of the function). */
2098 get_temp_regvar (type
, init
)
2103 decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
2104 TREE_USED (decl
) = 1;
2105 DECL_REGISTER (decl
) = 1;
2106 DECL_ARTIFICIAL (decl
) = 1;
2108 DECL_RTL (decl
) = assign_temp (type
, 2, 0, 1);
2109 /* We can expand these without fear, since they cannot need
2110 constructors or destructors. */
2111 expand_expr (build_modify_expr (decl
, INIT_EXPR
, init
),
2112 NULL_RTX
, VOIDmode
, 0);
2117 /* Finish off the processing of a UNION_TYPE structure.
2118 If there are static members, then all members are
2119 static, and must be laid out together. If the
2120 union is an anonymous union, we arrange for that
2121 as well. PUBLIC_P is nonzero if this union is
2122 not declared static. */
2125 finish_anon_union (anon_union_decl
)
2126 tree anon_union_decl
;
2128 tree type
= TREE_TYPE (anon_union_decl
);
2129 tree field
, main_decl
= NULL_TREE
;
2130 tree elems
= NULL_TREE
;
2131 int public_p
= TREE_PUBLIC (anon_union_decl
);
2132 int static_p
= TREE_STATIC (anon_union_decl
);
2133 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2135 if ((field
= TYPE_FIELDS (type
)) == NULL_TREE
)
2140 error ("global anonymous unions must be declared static");
2144 for (; field
; field
= TREE_CHAIN (field
))
2147 if (TREE_CODE (field
) != FIELD_DECL
)
2150 if (TREE_PRIVATE (field
))
2151 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
2152 else if (TREE_PROTECTED (field
))
2153 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
2155 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2156 /* tell `pushdecl' that this is not tentative. */
2157 DECL_INITIAL (decl
) = error_mark_node
;
2158 TREE_PUBLIC (decl
) = public_p
;
2159 TREE_STATIC (decl
) = static_p
;
2160 DECL_EXTERNAL (decl
) = external_p
;
2161 decl
= pushdecl (decl
);
2163 /* Only write out one anon union element--choose the one that
2164 can hold them all. */
2165 if (main_decl
== NULL_TREE
2166 && 1 == simple_cst_equal (DECL_SIZE (decl
),
2167 DECL_SIZE (anon_union_decl
)))
2173 /* ??? This causes there to be no debug info written out
2175 TREE_ASM_WRITTEN (decl
) = 1;
2178 DECL_INITIAL (decl
) = NULL_TREE
;
2179 /* If there's a cleanup to do, it belongs in the
2180 TREE_PURPOSE of the following TREE_LIST. */
2181 elems
= scratch_tree_cons (NULL_TREE
, decl
, elems
);
2182 TREE_TYPE (elems
) = type
;
2188 make_decl_rtl (main_decl
, 0, toplevel_bindings_p ());
2189 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2193 warning ("anonymous union with no members");
2198 /* The following call assumes that there are never any cleanups
2199 for anonymous unions--a reasonable assumption. */
2200 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2203 /* Finish processing a builtin type TYPE. It's name is NAME,
2204 its fields are in the array FIELDS. LEN is the number of elements
2205 in FIELDS minus one, or put another way, it is the maximum subscript
2208 It is given the same alignment as ALIGN_TYPE. */
2211 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2220 TYPE_FIELDS (type
) = fields
[0];
2221 for (i
= 0; i
< len
; i
++)
2223 layout_type (TREE_TYPE (fields
[i
]));
2224 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2225 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2227 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2228 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2229 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2231 #if 0 /* not yet, should get fixed properly later */
2232 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2234 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2236 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
2237 layout_decl (TYPE_NAME (type
), 0);
2240 /* Auxiliary functions to make type signatures for
2241 `operator new' and `operator delete' correspond to
2242 what compiler will be expecting. */
2245 coerce_new_type (type
)
2250 if (TREE_CODE (type
) == METHOD_TYPE
)
2251 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2252 if (TREE_TYPE (type
) != ptr_type_node
)
2253 e1
= 1, error ("`operator new' must return type `void *'");
2255 /* Technically the type must be `size_t', but we may not know
2257 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2258 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2259 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type
))) != INTEGER_TYPE
2260 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type
))) != TYPE_PRECISION (sizetype
))
2261 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2263 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2265 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2270 coerce_delete_type (type
)
2277 tree arg_types
= TYPE_ARG_TYPES (type
);
2279 if (TREE_CODE (type
) == METHOD_TYPE
)
2281 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2282 arg_types
= TREE_CHAIN (arg_types
);
2285 if (TREE_TYPE (type
) != void_type_node
)
2286 e1
= 1, error ("`operator delete' must return type `void'");
2288 if (arg_types
== NULL_TREE
2289 || TREE_VALUE (arg_types
) != ptr_type_node
)
2290 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2294 && TREE_CHAIN (arg_types
)
2295 && TREE_CHAIN (arg_types
) != void_list_node
)
2297 /* Again, technically this argument must be `size_t', but again
2298 we may not know what that is. */
2299 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2300 if (TREE_CODE (t2
) != INTEGER_TYPE
2301 || TYPE_PRECISION (t2
) != TYPE_PRECISION (sizetype
))
2302 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2303 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2306 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2307 error ("too many arguments in declaration of `operator delete'");
2309 error ("`...' invalid in specification of `operator delete'");
2314 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2315 build_tree_list (NULL_TREE
, sizetype
));
2318 if (arg_types
== NULL_TREE
)
2319 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2321 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2327 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2328 arg_types
? TREE_CHAIN (arg_types
): NULL_TREE
);
2330 type
= build_function_type (void_type_node
, arg_types
);
2335 extern tree abort_fndecl
;
2338 mark_vtable_entries (decl
)
2341 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
2345 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (TREE_CHAIN (entries
))
2346 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2347 tree fn
= TREE_OPERAND (fnaddr
, 0);
2348 TREE_ADDRESSABLE (fn
) = 1;
2351 skip_rtti_stuff (&entries
);
2353 for (; entries
; entries
= TREE_CHAIN (entries
))
2355 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (entries
)
2356 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2357 tree fn
= TREE_OPERAND (fnaddr
, 0);
2358 TREE_ADDRESSABLE (fn
) = 1;
2359 if (DECL_LANG_SPECIFIC (fn
) && DECL_ABSTRACT_VIRTUAL_P (fn
))
2361 TREE_OPERAND (fnaddr
, 0) = fn
= copy_node (fn
);
2362 DECL_RTL (fn
) = DECL_RTL (abort_fndecl
);
2363 mark_used (abort_fndecl
);
2365 if (TREE_CODE (fn
) == THUNK_DECL
&& DECL_EXTERNAL (fn
))
2367 DECL_EXTERNAL (fn
) = 0;
2374 /* Set DECL up to have the closest approximation of "initialized common"
2375 linkage available. */
2378 comdat_linkage (decl
)
2382 make_decl_one_only (decl
);
2384 TREE_PUBLIC (decl
) = 0;
2386 if (DECL_LANG_SPECIFIC (decl
))
2387 DECL_COMDAT (decl
) = 1;
2390 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2391 based on TYPE and other static flags.
2393 Note that anything public is tagged TREE_PUBLIC, whether
2394 it's public in this file or in another one. */
2397 import_export_vtable (decl
, type
, final
)
2401 if (DECL_INTERFACE_KNOWN (decl
))
2405 if (write_virtuals
< 2 && write_virtuals
!= 0)
2407 TREE_PUBLIC (decl
) = 1;
2408 if (write_virtuals
< 0)
2409 DECL_EXTERNAL (decl
) = 1;
2410 DECL_INTERFACE_KNOWN (decl
) = 1;
2412 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2414 TREE_PUBLIC (decl
) = 1;
2415 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2416 DECL_INTERFACE_KNOWN (decl
) = 1;
2418 /* For WIN32 we also want to put explicit instantiations in
2419 linkonce sections. */
2420 if (CLASSTYPE_EXPLICIT_INSTANTIATION (type
)
2421 && supports_one_only () && ! SUPPORTS_WEAK
)
2422 make_decl_one_only (decl
);
2426 /* We can only wait to decide if we have real non-inline virtual
2427 functions in our class, or if we come from a template. */
2429 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2431 #ifndef MULTIPLE_SYMBOL_SPACES
2432 if (! found
&& ! final
)
2435 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
2436 method
= TREE_CHAIN (method
))
2437 if (DECL_VINDEX (method
) != NULL_TREE
2438 && ! DECL_THIS_INLINE (method
)
2439 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2447 if (final
|| ! found
)
2449 comdat_linkage (decl
);
2450 DECL_EXTERNAL (decl
) = 0;
2454 TREE_PUBLIC (decl
) = 1;
2455 DECL_EXTERNAL (decl
) = 1;
2461 import_export_template (type
)
2464 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type
)
2465 && ! flag_implicit_templates
2466 && CLASSTYPE_INTERFACE_UNKNOWN (type
))
2468 SET_CLASSTYPE_INTERFACE_KNOWN (type
);
2469 CLASSTYPE_INTERFACE_ONLY (type
) = 1;
2470 CLASSTYPE_VTABLE_NEEDS_WRITING (type
) = 0;
2475 finish_prevtable_vardecl (prev
, vars
)
2478 tree ctype
= DECL_CONTEXT (vars
);
2479 import_export_template (ctype
);
2481 #ifndef MULTIPLE_SYMBOL_SPACES
2482 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype
) && TYPE_VIRTUAL_P (ctype
)
2483 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2486 for (method
= TYPE_METHODS (ctype
); method
!= NULL_TREE
;
2487 method
= TREE_CHAIN (method
))
2489 if (DECL_VINDEX (method
) != NULL_TREE
2490 && !DECL_THIS_INLINE (method
)
2491 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2493 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2494 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
)
2495 = ! DECL_REALLY_EXTERN (method
);
2496 CLASSTYPE_INTERFACE_ONLY (ctype
) = DECL_REALLY_EXTERN (method
);
2503 import_export_vtable (vars
, ctype
, 1);
2508 finish_vtable_vardecl (prev
, vars
)
2511 if (write_virtuals
>= 0
2512 && ! DECL_EXTERNAL (vars
)
2513 && ((TREE_PUBLIC (vars
) && ! DECL_WEAK (vars
) && ! DECL_ONE_ONLY (vars
))
2514 || CLASSTYPE_EXPLICIT_INSTANTIATION (DECL_CONTEXT (vars
))
2515 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
))
2516 || (hack_decl_function_context (vars
) && TREE_USED (vars
)))
2517 && ! TREE_ASM_WRITTEN (vars
))
2520 mark_vtable_entries (vars
);
2521 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2522 store_init_value (vars
, DECL_INITIAL (vars
));
2524 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2526 /* Mark the VAR_DECL node representing the vtable itself as a
2527 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2528 It is rather important that such things be ignored because
2529 any effort to actually generate DWARF for them will run
2530 into trouble when/if we encounter code like:
2533 struct S { virtual void member (); };
2535 because the artificial declaration of the vtable itself (as
2536 manufactured by the g++ front end) will say that the vtable
2537 is a static member of `S' but only *after* the debug output
2538 for the definition of `S' has already been output. This causes
2539 grief because the DWARF entry for the definition of the vtable
2540 will try to refer back to an earlier *declaration* of the
2541 vtable as a static member of `S' and there won't be one.
2542 We might be able to arrange to have the "vtable static member"
2543 attached to the member list for `S' before the debug info for
2544 `S' get written (which would solve the problem) but that would
2545 require more intrusive changes to the g++ front end. */
2547 DECL_IGNORED_P (vars
) = 1;
2550 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2553 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
)))
2554 /* We don't know what to do with this one yet. */
2557 /* We know that PREV must be non-zero here. */
2558 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2563 prune_vtable_vardecl (prev
, vars
)
2566 /* We know that PREV must be non-zero here. */
2567 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2572 walk_vtables (typedecl_fn
, vardecl_fn
)
2573 register void (*typedecl_fn
) PROTO ((tree
, tree
));
2574 register int (*vardecl_fn
) PROTO ((tree
, tree
));
2579 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2581 register tree type
= TREE_TYPE (vars
);
2583 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2586 flag
|= (*vardecl_fn
) (prev
, vars
);
2588 if (prev
&& TREE_CHAIN (prev
) != vars
)
2591 else if (TREE_CODE (vars
) == TYPE_DECL
2592 && type
!= error_mark_node
2593 && TYPE_LANG_SPECIFIC (type
)
2594 && CLASSTYPE_VSIZE (type
))
2596 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2606 finish_sigtable_vardecl (prev
, vars
)
2609 /* We don't need to mark sigtable entries as addressable here as is done
2610 for vtables. Since sigtables, unlike vtables, are always written out,
2611 that was already done in build_signature_table_constructor. */
2613 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2615 /* We know that PREV must be non-zero here. */
2616 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2620 walk_sigtables (typedecl_fn
, vardecl_fn
)
2621 register void (*typedecl_fn
) PROTO((tree
, tree
));
2622 register void (*vardecl_fn
) PROTO((tree
, tree
));
2626 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2628 register tree type
= TREE_TYPE (vars
);
2630 if (TREE_CODE (vars
) == TYPE_DECL
2631 && type
!= error_mark_node
2632 && IS_SIGNATURE (type
))
2634 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2636 else if (TREE_CODE (vars
) == VAR_DECL
2637 && TREE_TYPE (vars
) != error_mark_node
2638 && IS_SIGNATURE (TREE_TYPE (vars
)))
2640 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2647 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2648 inline function or template instantiation at end-of-file. */
2651 import_export_decl (decl
)
2654 if (DECL_INTERFACE_KNOWN (decl
))
2657 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2659 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2660 if (DECL_IMPLICIT_INSTANTIATION (decl
)
2661 && (flag_implicit_templates
|| DECL_THIS_INLINE (decl
)))
2663 if (!TREE_PUBLIC (decl
))
2664 /* Templates are allowed to have internal linkage. See
2667 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2668 comdat_linkage (decl
);
2670 DECL_COMDAT (decl
) = 1;
2673 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2675 else if (DECL_FUNCTION_MEMBER_P (decl
))
2677 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2678 if (CLASSTYPE_INTERFACE_KNOWN (ctype
)
2679 && (! DECL_ARTIFICIAL (decl
) || DECL_VINDEX (decl
)))
2681 DECL_NOT_REALLY_EXTERN (decl
)
2682 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2683 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2686 comdat_linkage (decl
);
2688 /* tinfo function */
2689 else if (DECL_ARTIFICIAL (decl
) && DECL_MUTABLE_P (decl
))
2691 tree ctype
= TREE_TYPE (DECL_NAME (decl
));
2692 if (IS_AGGR_TYPE (ctype
) && CLASSTYPE_INTERFACE_KNOWN (ctype
)
2693 && TYPE_VIRTUAL_P (ctype
))
2695 /* If the type is a cv-qualified variant of a type, then we
2696 must emit the tinfo function in this translation unit
2697 since it will not be emitted when the vtable for the type
2698 is output (which is when the unqualified version is
2700 DECL_NOT_REALLY_EXTERN (decl
)
2701 = TYPE_READONLY (ctype
)
2702 || TYPE_VOLATILE (ctype
)
2703 || ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2704 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2706 /* For WIN32 we also want to put explicit instantiations in
2707 linkonce sections. */
2708 if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype
)
2709 && supports_one_only () && ! SUPPORTS_WEAK
)
2710 make_decl_one_only (decl
);
2712 else if (TYPE_BUILT_IN (ctype
) && ctype
== TYPE_MAIN_VARIANT (ctype
))
2713 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2715 comdat_linkage (decl
);
2718 comdat_linkage (decl
);
2720 DECL_INTERFACE_KNOWN (decl
) = 1;
2724 build_cleanup (decl
)
2728 tree type
= TREE_TYPE (decl
);
2730 if (TREE_CODE (type
) == ARRAY_TYPE
)
2734 mark_addressable (decl
);
2735 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
2737 temp
= build_delete (TREE_TYPE (temp
), temp
,
2739 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2743 extern int parse_time
, varconst_time
;
2744 extern tree pending_templates
;
2745 extern tree maybe_templates
;
2747 extern struct obstack permanent_obstack
;
2753 tree sname
= get_id_2 ("__sn", base
);
2754 /* for struct X foo __attribute__((weak)), there is a counter
2755 __snfoo. Since base is already an assembler name, sname should
2756 be globally unique */
2757 tree sentry
= IDENTIFIER_GLOBAL_VALUE (sname
);
2760 push_obstacks (&permanent_obstack
, &permanent_obstack
);
2761 sentry
= build_decl (VAR_DECL
, sname
, integer_type_node
);
2762 TREE_PUBLIC (sentry
) = 1;
2763 DECL_ARTIFICIAL (sentry
) = 1;
2764 TREE_STATIC (sentry
) = 1;
2765 TREE_USED (sentry
) = 1;
2766 DECL_COMMON (sentry
) = 1;
2767 pushdecl_top_level (sentry
);
2768 cp_finish_decl (sentry
, NULL_TREE
, NULL_TREE
, 0, 0);
2774 /* This routine is called from the last rule in yyparse ().
2775 Its job is to create all the code needed to initialize and
2776 destroy the global aggregates. We do the destruction
2777 first, since that way we only need to reverse the decls once. */
2783 int start_time
, this_time
;
2787 int needs_cleaning
= 0, needs_messing_up
= 0;
2791 /* Bad parse errors. Just forget about it. */
2792 if (! global_bindings_p () || current_class_type
)
2795 start_time
= get_run_time ();
2797 /* Otherwise, GDB can get confused, because in only knows
2798 about source for LINENO-1 lines. */
2801 interface_unknown
= 1;
2804 for (fnname
= pending_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
2806 tree decl
= TREE_VALUE (fnname
);
2807 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
2809 instantiate_class_template (decl
);
2810 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl
))
2811 for (vars
= TYPE_METHODS (decl
); vars
; vars
= TREE_CHAIN (vars
))
2812 if (! DECL_ARTIFICIAL (vars
))
2813 instantiate_decl (vars
);
2816 instantiate_decl (decl
);
2819 for (fnname
= maybe_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
2821 tree args
, fn
, decl
= TREE_VALUE (fnname
);
2823 if (DECL_INITIAL (decl
))
2826 fn
= TREE_PURPOSE (fnname
);
2827 args
= get_bindings (fn
, decl
, NULL_TREE
);
2828 fn
= instantiate_template (fn
, args
);
2829 instantiate_decl (fn
);
2832 /* Push into C language context, because that's all
2834 push_lang_context (lang_name_c
);
2837 /* The reason for pushing garbage onto the global_binding_level is to
2838 ensure that we can slice out _DECLs which pertain to virtual function
2839 tables. If the last thing pushed onto the global_binding_level was a
2840 virtual function table, then slicing it out would slice away all the
2841 decls (i.e., we lose the head of the chain).
2843 There are several ways of getting the same effect, from changing the
2844 way that iterators over the chain treat the elements that pertain to
2845 virtual function tables, moving the implementation of this code to
2846 decl.c (where we can manipulate global_binding_level directly),
2847 popping the garbage after pushing it and slicing away the vtable
2848 stuff, or just leaving it alone. */
2850 /* Make last thing in global scope not be a virtual function table. */
2851 #if 0 /* not yet, should get fixed properly later */
2852 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
2854 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
2856 DECL_IGNORED_P (vars
) = 1;
2857 SET_DECL_ARTIFICIAL (vars
);
2861 /* Walk to mark the inline functions we need, then output them so
2862 that we can pick up any other tdecls that those routines need. */
2863 walk_vtables ((void (*) PROTO ((tree
, tree
))) 0,
2864 finish_prevtable_vardecl
);
2866 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
2867 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars
)))
2868 rest_of_decl_compilation (TREE_VALUE (vars
), 0, 1, 1);
2869 vars
= static_aggregates
;
2871 if (static_ctors
|| vars
)
2872 needs_messing_up
= 1;
2876 /* See if we really need the hassle. */
2877 while (vars
&& needs_cleaning
== 0)
2879 tree decl
= TREE_VALUE (vars
);
2880 tree type
= TREE_TYPE (decl
);
2881 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
))
2887 vars
= TREE_CHAIN (vars
);
2890 if (needs_cleaning
== 0)
2893 fnname
= get_file_function_name ('D');
2894 start_function (void_list_node
,
2895 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
2898 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2899 store_parm_decls ();
2904 expand_start_bindings (0);
2906 /* These must be done in backward order to destroy,
2907 in which they happen to be! */
2908 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
2910 tree decl
= TREE_VALUE (vars
);
2911 tree type
= TREE_TYPE (decl
);
2912 tree temp
= TREE_PURPOSE (vars
);
2914 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
)
2915 && ! DECL_EXTERNAL (decl
))
2917 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
2918 || DECL_ONE_ONLY (decl
)
2919 || DECL_WEAK (decl
)));
2921 temp
= build_cleanup (decl
);
2925 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
2926 sentry
= build_unary_op (PREDECREMENT_EXPR
, sentry
, 0);
2927 sentry
= build_binary_op (EQ_EXPR
, sentry
, integer_zero_node
, 1);
2928 expand_start_cond (sentry
, 0);
2931 expand_expr_stmt (temp
);
2938 for (; static_dtors
; static_dtors
= TREE_CHAIN (static_dtors
))
2939 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors
),
2942 expand_end_bindings (getdecls (), 1, 0);
2946 finish_function (lineno
, 0, 0);
2948 assemble_destructor (IDENTIFIER_POINTER (fnname
));
2950 /* if it needed cleaning, then it will need messing up: drop through */
2953 /* Must do this while we think we are at the top level. */
2954 vars
= nreverse (static_aggregates
);
2955 if (needs_messing_up
)
2957 fnname
= get_file_function_name ('I');
2958 start_function (void_list_node
,
2959 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
2962 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2963 store_parm_decls ();
2968 expand_start_bindings (0);
2972 tree decl
= TREE_VALUE (vars
);
2973 tree init
= TREE_PURPOSE (vars
);
2975 /* If this was a static attribute within some function's scope,
2976 then don't initialize it here. Also, don't bother
2977 with initializers that contain errors. */
2978 if (TREE_STATIC (vars
)
2979 || DECL_EXTERNAL (decl
)
2980 || (init
&& TREE_CODE (init
) == TREE_LIST
2981 && value_member (error_mark_node
, init
)))
2984 if (TREE_CODE (decl
) == VAR_DECL
)
2986 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
2987 || DECL_ONE_ONLY (decl
)
2988 || DECL_WEAK (decl
)));
2990 /* Set these global variables so that GDB at least puts
2991 us near the declaration which required the initialization. */
2992 input_filename
= DECL_SOURCE_FILE (decl
);
2993 lineno
= DECL_SOURCE_LINE (decl
);
2994 emit_note (input_filename
, lineno
);
2996 /* 9.5p5: The initializer of a static member of a class has
2997 the same access rights as a member function. */
2998 if (member_p (decl
))
3000 DECL_CLASS_CONTEXT (current_function_decl
)
3001 = DECL_CONTEXT (decl
);
3002 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3007 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
3008 sentry
= build_unary_op (PREINCREMENT_EXPR
, sentry
, 0);
3009 sentry
= build_binary_op
3010 (EQ_EXPR
, sentry
, integer_one_node
, 1);
3011 expand_start_cond (sentry
, 0);
3014 expand_start_target_temps ();
3016 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3017 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3018 expand_aggr_init (decl
, init
, 0, 0);
3019 else if (TREE_CODE (init
) == TREE_VEC
)
3021 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3022 TREE_VEC_ELT (init
, 1),
3023 TREE_VEC_ELT (init
, 2), 0),
3024 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3027 expand_assignment (decl
, init
, 0, 0);
3029 /* The expression might have involved increments and
3033 /* Cleanup any temporaries needed for the initial value. */
3034 expand_end_target_temps ();
3039 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3040 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3042 else if (decl
== error_mark_node
)
3044 else my_friendly_abort (22);
3047 vars
= TREE_CHAIN (vars
);
3050 for (; static_ctors
; static_ctors
= TREE_CHAIN (static_ctors
))
3051 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors
),
3054 expand_end_bindings (getdecls (), 1, 0);
3058 finish_function (lineno
, 0, 0);
3059 assemble_constructor (IDENTIFIER_POINTER (fnname
));
3062 permanent_allocation (1);
3064 /* Done with C language context needs. */
3065 pop_lang_context ();
3067 /* Now write out any static class variables (which may have since
3068 learned how to be initialized). */
3069 while (pending_statics
)
3071 tree decl
= TREE_VALUE (pending_statics
);
3073 /* Output DWARF debug information. */
3074 #ifdef DWARF_DEBUGGING_INFO
3075 if (write_symbols
== DWARF_DEBUG
)
3076 dwarfout_file_scope_decl (decl
, 1);
3078 #ifdef DWARF2_DEBUGGING_INFO
3079 if (write_symbols
== DWARF2_DEBUG
)
3080 dwarf2out_decl (decl
);
3083 DECL_DEFER_OUTPUT (decl
) = 0;
3084 rest_of_decl_compilation
3085 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3087 pending_statics
= TREE_CHAIN (pending_statics
);
3090 this_time
= get_run_time ();
3091 parse_time
-= this_time
- start_time
;
3092 varconst_time
+= this_time
- start_time
;
3094 start_time
= get_run_time ();
3096 if (flag_handle_signatures
)
3097 walk_sigtables ((void (*) PROTO ((tree
, tree
))) 0,
3098 finish_sigtable_vardecl
);
3100 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3102 tree decl
= TREE_VALUE (fnname
);
3103 import_export_decl (decl
);
3106 /* Now write out inline functions which had their addresses taken and
3107 which were not declared virtual and which were not declared `extern
3110 int reconsider
= 1; /* More may be referenced; check again */
3114 tree
*p
= &saved_inlines
;
3117 /* We need to do this each time so that newly completed template
3118 types don't wind up at the front of the list. Sigh. */
3119 vars
= build_decl (TYPE_DECL
, make_anon_name (), integer_type_node
);
3120 DECL_IGNORED_P (vars
) = 1;
3121 SET_DECL_ARTIFICIAL (vars
);
3124 reconsider
|= walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3125 finish_vtable_vardecl
);
3129 tree decl
= TREE_VALUE (*p
);
3131 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3133 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
3135 if (DECL_MUTABLE_P (decl
))
3136 synthesize_tinfo_fn (decl
);
3138 synthesize_method (decl
);
3142 /* Catch new template instantiations. */
3143 if (decl
!= TREE_VALUE (*p
))
3146 if (TREE_ASM_WRITTEN (decl
)
3147 || (DECL_SAVED_INSNS (decl
) == 0 && ! DECL_ARTIFICIAL (decl
)))
3148 *p
= TREE_CHAIN (*p
);
3149 else if (DECL_INITIAL (decl
) == 0)
3150 p
= &TREE_CHAIN (*p
);
3151 else if ((TREE_PUBLIC (decl
) && ! DECL_COMDAT (decl
))
3152 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3153 || flag_keep_inline_functions
)
3155 if (DECL_NOT_REALLY_EXTERN (decl
))
3157 DECL_EXTERNAL (decl
) = 0;
3159 /* We can't inline this function after it's been
3160 emitted. We want a variant of
3161 output_inline_function that doesn't prevent
3162 subsequent integration... */
3163 DECL_INLINE (decl
) = 0;
3164 output_inline_function (decl
);
3165 permanent_allocation (1);
3168 *p
= TREE_CHAIN (*p
);
3171 p
= &TREE_CHAIN (*p
);
3175 /* It's possible that some of the remaining inlines will still be
3176 needed. For example, a static inline whose address is used in
3177 the initializer for a file-scope static variable will be
3178 needed. Code in compile_file will handle this, but we mustn't
3179 pretend that there are no definitions for the inlines, or it
3182 FIXME: This won't catch member functions. We should really
3183 unify this stuff with the compile_file stuff. */
3184 for (vars
= saved_inlines
; vars
!= NULL_TREE
; vars
= TREE_CHAIN (vars
))
3186 tree decl
= TREE_VALUE (vars
);
3188 if (DECL_NOT_REALLY_EXTERN (decl
)
3189 && !DECL_COMDAT (decl
)
3190 && DECL_INITIAL (decl
) != NULL_TREE
)
3191 DECL_EXTERNAL (decl
) = 0;
3195 /* Now delete from the chain of variables all virtual function tables.
3196 We output them all ourselves, because each will be treated specially. */
3198 walk_vtables ((void (*) PROTO((tree
, tree
))) 0,
3199 prune_vtable_vardecl
);
3201 if (write_virtuals
== 2)
3203 /* Now complain about an virtual function tables promised
3204 but not delivered. */
3205 while (pending_vtables
)
3207 if (TREE_PURPOSE (pending_vtables
) == NULL_TREE
)
3208 error ("virtual function table for `%s' not defined",
3209 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables
)));
3210 pending_vtables
= TREE_CHAIN (pending_vtables
);
3216 this_time
= get_run_time ();
3217 parse_time
-= this_time
- start_time
;
3218 varconst_time
+= this_time
- start_time
;
3220 if (flag_detailed_statistics
)
3222 dump_tree_statistics ();
3223 dump_time_statistics ();
3227 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3228 expr. Since it was parsed like a type, we need to wade through and fix
3229 that. Unfortunately, since operator() is left-associative, we can't use
3230 tail recursion. In the above example, TYPE is `A', and DECL is
3233 Maybe this shouldn't be recursive, but how often will it actually be
3237 reparse_absdcl_as_expr (type
, decl
)
3240 /* do build_functional_cast (type, NULL_TREE) at bottom */
3241 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3242 return build_functional_cast (type
, NULL_TREE
);
3245 decl
= reparse_decl_as_expr (type
, TREE_OPERAND (decl
, 0));
3247 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_ref
);
3249 if (TREE_CODE (decl
) == CALL_EXPR
&& TREE_TYPE (decl
) != void_type_node
)
3250 decl
= require_complete_type (decl
);
3255 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3256 out to be an expr. Since it was parsed like a type, we need to wade
3257 through and fix that. Since casts are right-associative, we are
3258 reversing the order, so we don't have to recurse.
3260 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3264 reparse_absdcl_as_casts (decl
, expr
)
3269 if (TREE_CODE (expr
) == CONSTRUCTOR
3270 && TREE_TYPE (expr
) == 0)
3272 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3273 decl
= TREE_OPERAND (decl
, 0);
3275 if (IS_SIGNATURE (type
))
3277 error ("cast specifies signature type");
3278 return error_mark_node
;
3281 expr
= digest_init (type
, expr
, (tree
*) 0);
3282 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3284 int failure
= complete_array_type (type
, expr
, 1);
3286 my_friendly_abort (78);
3292 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3293 decl
= TREE_OPERAND (decl
, 0);
3294 expr
= build_c_cast (type
, expr
);
3297 if (warn_old_style_cast
)
3298 warning ("use of old-style cast");
3303 /* Given plain tree nodes for an expression, build up the full semantics. */
3306 build_expr_from_tree (t
)
3309 if (t
== NULL_TREE
|| t
== error_mark_node
)
3312 switch (TREE_CODE (t
))
3314 case IDENTIFIER_NODE
:
3315 return do_identifier (t
, 0);
3318 if (LOOKUP_EXPR_GLOBAL (t
))
3319 return do_scoped_id (TREE_OPERAND (t
, 0), 0);
3321 return do_identifier (TREE_OPERAND (t
, 0), 0);
3323 case TEMPLATE_ID_EXPR
:
3324 return (lookup_template_function
3325 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3326 build_expr_from_tree (TREE_OPERAND (t
, 1))));
3329 return build_x_indirect_ref
3330 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3333 return build_functional_cast
3334 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3336 case REINTERPRET_CAST_EXPR
:
3337 return build_reinterpret_cast
3338 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3340 case CONST_CAST_EXPR
:
3341 return build_const_cast
3342 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3344 case DYNAMIC_CAST_EXPR
:
3345 return build_dynamic_cast
3346 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3348 case STATIC_CAST_EXPR
:
3349 return build_static_cast
3350 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3352 case PREDECREMENT_EXPR
:
3353 case PREINCREMENT_EXPR
:
3354 case POSTDECREMENT_EXPR
:
3355 case POSTINCREMENT_EXPR
:
3359 case TRUTH_NOT_EXPR
:
3361 case CONVERT_EXPR
: /* Unary + */
3364 return build_x_unary_op (TREE_CODE (t
),
3365 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3370 case TRUNC_DIV_EXPR
:
3372 case FLOOR_DIV_EXPR
:
3373 case ROUND_DIV_EXPR
:
3374 case EXACT_DIV_EXPR
:
3376 case BIT_ANDTC_EXPR
:
3379 case TRUNC_MOD_EXPR
:
3380 case FLOOR_MOD_EXPR
:
3381 case TRUTH_ANDIF_EXPR
:
3382 case TRUTH_ORIF_EXPR
:
3383 case TRUTH_AND_EXPR
:
3398 return build_x_binary_op
3400 build_expr_from_tree (TREE_OPERAND (t
, 0)),
3401 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3404 return build_m_component_ref
3405 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3406 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3409 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
3412 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
3414 return build_parse_node (ARRAY_REF
, NULL_TREE
,
3415 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3416 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3417 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3422 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3423 if (TREE_CODE_CLASS (TREE_CODE (r
)) != 't')
3425 return TREE_CODE (t
) == SIZEOF_EXPR
? c_sizeof (r
) : c_alignof (r
);
3429 return build_x_modify_expr
3430 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3431 TREE_CODE (TREE_OPERAND (t
, 1)),
3432 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3435 return build_x_arrow
3436 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3440 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3441 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3442 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3443 NEW_EXPR_USE_GLOBAL (t
));
3446 return delete_sanity
3447 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3448 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3449 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
3452 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
3453 return build_x_compound_expr
3454 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3456 my_friendly_abort (42);
3458 case METHOD_CALL_EXPR
:
3459 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3461 tree ref
= TREE_OPERAND (t
, 0);
3462 return build_scoped_method_call
3463 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3464 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3465 TREE_OPERAND (ref
, 1),
3466 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3468 return build_method_call
3469 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3470 TREE_OPERAND (t
, 0),
3471 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3472 NULL_TREE
, LOOKUP_NORMAL
);
3475 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3477 tree ref
= TREE_OPERAND (t
, 0);
3478 return build_member_call
3479 (build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3480 TREE_OPERAND (ref
, 1),
3481 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3485 tree name
= TREE_OPERAND (t
, 0);
3486 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
3487 || ! really_overloaded_fn (name
))
3488 name
= build_expr_from_tree (name
);
3489 return build_x_function_call
3490 (name
, build_expr_from_tree (TREE_OPERAND (t
, 1)),
3495 return build_x_conditional_expr
3496 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3497 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3498 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3502 tree purpose
, value
, chain
;
3504 if (t
== void_list_node
)
3507 purpose
= TREE_PURPOSE (t
);
3509 purpose
= build_expr_from_tree (purpose
);
3510 value
= TREE_VALUE (t
);
3512 value
= build_expr_from_tree (value
);
3513 chain
= TREE_CHAIN (t
);
3514 if (chain
&& chain
!= void_type_node
)
3515 chain
= build_expr_from_tree (chain
);
3516 return expr_tree_cons (purpose
, value
, chain
);
3520 return build_x_component_ref
3521 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3522 TREE_OPERAND (t
, 1), NULL_TREE
, 1);
3525 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3529 tree r
= build_nt (CONSTRUCTOR
, NULL_TREE
,
3530 build_expr_from_tree (CONSTRUCTOR_ELTS (t
)));
3533 return digest_init (TREE_TYPE (t
), r
, 0);
3538 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
3539 return get_typeid (TREE_OPERAND (t
, 0));
3540 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3543 return convert_from_reference (t
);
3550 /* This is something of the form `int (*a)++' that has turned out to be an
3551 expr. It was only converted into parse nodes, so we need to go through
3552 and build up the semantics. Most of the work is done by
3553 build_expr_from_tree, above.
3555 In the above example, TYPE is `int' and DECL is `*a'. */
3558 reparse_decl_as_expr (type
, decl
)
3561 decl
= build_expr_from_tree (decl
);
3563 return build_functional_cast (type
, build_expr_list (NULL_TREE
, decl
));
3568 /* This is something of the form `int (*a)' that has turned out to be a
3569 decl. It was only converted into parse nodes, so we need to do the
3570 checking that make_{pointer,reference}_declarator do. */
3573 finish_decl_parsing (decl
)
3576 extern int current_class_depth
;
3578 switch (TREE_CODE (decl
))
3580 case IDENTIFIER_NODE
:
3583 return make_pointer_declarator
3584 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3586 return make_reference_declarator
3587 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3589 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3592 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3593 TREE_COMPLEXITY (decl
) = current_class_depth
;
3596 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3599 my_friendly_abort (5);
3605 check_cp_case_value (value
)
3608 if (value
== NULL_TREE
)
3611 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3612 STRIP_TYPE_NOPS (value
);
3614 if (TREE_READONLY_DECL_P (value
))
3616 value
= decl_constant_value (value
);
3617 STRIP_TYPE_NOPS (value
);
3619 value
= fold (value
);
3621 if (TREE_CODE (value
) != INTEGER_CST
3622 && value
!= error_mark_node
)
3624 cp_error ("case label `%E' does not reduce to an integer constant",
3626 value
= error_mark_node
;
3629 /* Promote char or short to int. */
3630 value
= default_conversion (value
);
3632 constant_expression_warning (value
);
3637 /* return 1 if root encloses child */
3639 is_namespace_ancestor (root
, child
)
3644 if (root
== global_namespace
)
3646 if (child
== global_namespace
)
3648 return is_namespace_ancestor (root
, DECL_NAMESPACE (child
));
3652 /* return the namespace that is the common ancestor
3653 of two given namespaces */
3655 namespace_ancestor (ns1
, ns2
)
3658 if (is_namespace_ancestor (ns1
, ns2
))
3660 return namespace_ancestor (DECL_NAMESPACE (ns1
), ns2
);
3663 /* Insert used into the using list of user. Set indirect_flag if this
3664 directive is not directly from the source. Also find the common
3665 ancestor and let our users know about the new namespace */
3667 add_using_namespace (user
, used
, indirect
)
3673 /* using oneself is a no-op */
3676 my_friendly_assert (TREE_CODE (user
) == NAMESPACE_DECL
, 380);
3677 my_friendly_assert (TREE_CODE (used
) == NAMESPACE_DECL
, 380);
3678 /* check if we already have this */
3679 if (purpose_member (used
, DECL_NAMESPACE_USING (user
)) != NULL_TREE
)
3682 /* add used to the user's using list */
3683 DECL_NAMESPACE_USING (user
)
3684 = perm_tree_cons (used
, namespace_ancestor (user
, used
),
3685 DECL_NAMESPACE_USING (user
));
3687 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user
)) = indirect
;
3689 /* add user to the used's users list */
3690 DECL_NAMESPACE_USERS (used
)
3691 = perm_tree_cons (user
, 0, DECL_NAMESPACE_USERS (used
));
3693 for (iter
= DECL_NAMESPACE_USERS (user
); iter
; iter
= TREE_CHAIN (iter
))
3694 /* indirect usage */
3695 add_using_namespace (TREE_PURPOSE (iter
), used
, 1);
3698 /* This should return an error not all definitions define functions.
3699 It is not an error if we find two functions with exactly the
3700 same signature, only if these are selected in overload resolution.
3701 XXX Do we want to give *all* candidates in case of ambiguity?
3702 XXX In what way should I treat extern declarations?
3703 XXX I don't want to repeat the entire duplicate_decls here */
3705 ambiguous_decl (name
, val1
, val2
)
3709 my_friendly_assert (val1
!= val2
, 376);
3710 if (is_overloaded_fn (val1
) && is_overloaded_fn (val1
))
3712 /* now built a joint list of all overloaded declarations */
3713 /* XXX if I chain'em together, they will be always considered
3715 sorry ("overloaded functions used from different namespaces");
3717 cp_error ("ambiguous definition `%D' used", name
);
3718 cp_error_at ("first definition here", val1
);
3719 cp_error_at ("other definition here", val2
);
3720 return error_mark_node
;
3723 /* add the bindings of name in used namespaces to val
3724 the using list is defined by current, and the lookup goes to scope */
3726 lookup_using_namespace (name
, val
, current
, scope
)
3727 tree name
, val
, current
, scope
;
3731 /* iterate over all namespaces from current to scope */
3734 /* iterate over all used namespaces in current, searching for
3735 using directives of scope */
3736 for (iter
= DECL_NAMESPACE_USING (current
);
3737 iter
; iter
= TREE_CHAIN (iter
))
3738 if (TREE_VALUE (iter
) == scope
)
3740 val1
= NAMESPACE_BINDING (name
, TREE_PURPOSE (iter
));
3741 /* name not found in this space */
3744 /* first definition ever */
3750 /* Hmmm. Ambiguity. As long as both are overloaded functions,
3752 val
= ambiguous_decl (name
, val
, val1
);
3753 if (val
== error_mark_node
)
3756 if (current
== scope
)
3758 current
= DECL_NAMESPACE (current
);
3763 /* [namespace.qual] */
3765 qualified_lookup_using_namespace (name
, scope
)
3769 tree val
= NULL_TREE
;
3771 /* maintain a list of namespaces visited */
3772 tree seen
= NULL_TREE
;
3773 /* and a list of namespace yet to see */
3774 tree todo
= NULL_TREE
;
3778 seen
= temp_tree_cons (scope
, NULL_TREE
, seen
);
3779 val1
= NAMESPACE_BINDING (name
, scope
);
3784 val
= ambiguous_decl (name
, val
, val1
);
3791 /* consider using directives */
3792 for (usings
= DECL_NAMESPACE_USING (scope
); usings
;
3793 usings
= TREE_CHAIN (usings
))
3794 /* if this was a real directive, and we have not seen it */
3795 if (!TREE_INDIRECT_USING (usings
)
3796 && !purpose_member (seen
, TREE_PURPOSE (usings
)))
3797 todo
= temp_tree_cons (TREE_PURPOSE (usings
), NULL_TREE
, todo
);
3800 scope
= TREE_PURPOSE (todo
);
3801 todo
= TREE_CHAIN (todo
);
3804 scope
= NULL_TREE
; /* if there never was a todo list */
3810 /* this is broken and should not be called anymore */
3811 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3812 postfix. Returns 0 if in global namespace. */
3817 tree x
= current_namespace
;
3819 x
= TREE_PURPOSE (x
);
3823 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3826 current_namespace_id (name
)
3829 tree old_id
= get_namespace_id ();
3832 /* Global names retain old encoding. */
3836 buf
= (char *) alloca (8 + IDENTIFIER_LENGTH (old_id
)
3837 + IDENTIFIER_LENGTH (name
));
3838 sprintf (buf
, "__ns_%s_%s", IDENTIFIER_POINTER (old_id
),
3839 IDENTIFIER_POINTER (name
));
3840 return get_identifier (buf
);
3845 do_namespace_alias (alias
, namespace)
3846 tree alias
, namespace;
3850 if (TREE_CODE (namespace) == IDENTIFIER_NODE
)
3851 ns
= lookup_name (namespace, 1);
3854 if (TREE_CODE (ns
) != NAMESPACE_DECL
)
3856 cp_error ("`%D' is not a namespace", namespace);
3859 binding
= binding_for_name (alias
, current_namespace
);
3860 if (BINDING_VALUE (binding
) && BINDING_VALUE (binding
) != namespace)
3862 cp_error ("invalid namespace alias `%D'", alias
);
3863 cp_error_at ("`%D' previously declared here", alias
);
3867 /* XXX the alias is not exactly identical to the name space,
3868 it must not be used in a using directive or namespace alias */
3869 BINDING_VALUE (binding
) = ns
;
3874 do_toplevel_using_decl (decl
)
3878 if (TREE_CODE (decl
) == SCOPE_REF
3879 && TREE_OPERAND (decl
, 0) == std_node
)
3881 sorry ("using-declaration");
3883 if (decl
== NULL_TREE
|| decl
== error_mark_node
)
3886 if (TREE_CODE (decl
) == SCOPE_REF
)
3887 decl
= resolve_scope_to_name (NULL_TREE
, decl
);
3889 /* Is this the right way to do an id list? */
3890 if (TREE_CODE (decl
) != TREE_LIST
)
3897 pushdecl (TREE_VALUE (decl
));
3898 decl
= TREE_CHAIN (decl
);
3904 do_class_using_decl (decl
)
3909 if (TREE_CODE (decl
) != SCOPE_REF
)
3911 cp_error ("using-declaration for non-member at class scope");
3914 name
= TREE_OPERAND (decl
, 1);
3915 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
3917 cp_error ("using-declaration for destructor");
3921 value
= build_lang_field_decl (USING_DECL
, name
, void_type_node
);
3922 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
3927 do_using_directive (namespace)
3930 if (namespace == std_node
)
3932 /* using A::B::C; */
3933 if (TREE_CODE (namespace) == SCOPE_REF
)
3934 namespace = TREE_OPERAND (namespace, 1);
3936 add_using_namespace (current_namespace
, namespace, 0);
3940 check_default_args (x
)
3943 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
3944 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
3945 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
3947 if (TREE_PURPOSE (arg
))
3951 cp_error ("default argument missing for parameter %P of `%#D'",
3962 TREE_USED (decl
) = 1;
3963 if (processing_template_decl
)
3965 assemble_external (decl
);
3966 /* Is it a synthesized method that needs to be synthesized? */
3967 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CLASS_CONTEXT (decl
)
3968 && DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3969 /* Kludge: don't synthesize for default args. */
3970 && current_function_decl
)
3971 synthesize_method (decl
);
3972 if (DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
))
3973 instantiate_decl (decl
);
3976 /* Helper function for named_class_head_sans_basetype nonterminal. */
3979 handle_class_head (aggr
, scope
, id
)
3980 tree aggr
, scope
, id
;
3982 if (TREE_CODE (id
) == TYPE_DECL
)
3986 cp_error ("`%T' does not have a nested type named `%D'", scope
, id
);
3988 cp_error ("no file-scope type named `%D'", id
);
3991 (aggr
, make_anon_name (), NULL_TREE
, 1);
3992 return TYPE_MAIN_DECL (id
);