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. */
40 extern tree
get_file_function_name ();
41 static void grok_function_init
PROTO((tree
, tree
));
42 void import_export_decl ();
43 extern int current_class_depth
;
45 /* A list of virtual function tables we must make sure to write out. */
48 /* A list of static class variables. This is needed, because a
49 static class variable can be declared inside the class without
50 an initializer, and then initialized, staticly, outside the class. */
53 /* A list of functions which were declared inline, but which we
54 may need to emit outline anyway. */
55 static tree saved_inlines
;
57 /* Used to help generate temporary names which are unique within
58 a function. Reset to 0 by start_function. */
60 int temp_name_counter
;
62 /* Same, but not reset. Local temp variables and global temp variables
63 can have the same name. */
64 static int global_temp_name_counter
;
66 /* Flag used when debugging spew.c */
68 extern int spew_debug
;
70 /* Nonzero if we're done parsing and into end-of-file activities. */
74 /* Functions called along with real static constructors and destructors. */
76 tree static_ctors
, static_dtors
;
78 /* C (and C++) language-specific option variables. */
80 /* Nonzero means allow type mismatches in conditional expressions;
81 just make their values `void'. */
83 int flag_cond_mismatch
;
85 /* Nonzero means give `double' the same size as `float'. */
87 int flag_short_double
;
89 /* Nonzero means don't recognize the keyword `asm'. */
93 /* Nonzero means don't recognize any extension keywords. */
95 int flag_no_gnu_keywords
;
97 /* Nonzero means don't recognize the non-ANSI builtin functions. */
101 /* Nonzero means don't recognize the non-ANSI builtin functions.
104 int flag_no_nonansi_builtin
;
106 /* Nonzero means do some things the same way PCC does. Only provided so
107 the compiler will link. */
109 int flag_traditional
;
111 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
113 int flag_signed_bitfields
= 1;
115 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
119 /* Nonzero means enable obscure ANSI features and disable GNU extensions
120 that might cause ANSI-compliant code to be miscompiled. */
124 /* Nonzero means do argument matching for overloading according to the
125 ANSI rules, rather than what g++ used to believe to be correct. */
127 int flag_ansi_overloading
= 1;
129 /* Nonzero means do emit exported implementations of functions even if
130 they can be inlined. */
132 int flag_implement_inlines
= 1;
134 /* Nonzero means do emit exported implementations of templates, instead of
135 multiple static copies in each file that needs a definition. */
137 int flag_external_templates
;
139 /* Nonzero means that the decision to emit or not emit the implementation of a
140 template depends on where the template is instantiated, rather than where
143 int flag_alt_external_templates
;
145 /* Nonzero means that implicit instantiations will be emitted if needed. */
147 int flag_implicit_templates
= 1;
149 /* Nonzero means warn about implicit declarations. */
151 int warn_implicit
= 1;
153 /* Nonzero means warn when all ctors or dtors are private, and the class
156 int warn_ctor_dtor_privacy
= 1;
158 /* True if we want to implement vtables using "thunks".
159 The default is off. */
161 #if defined(NEW_OVER) && defined (__i386__)
162 int flag_vtable_thunks
= 1;
164 int flag_vtable_thunks
;
167 /* True if we want to deal with repository information. */
169 int flag_use_repository
;
171 /* Nonzero means give string constants the type `const char *'
172 to get extra warnings from them. These warnings will be too numerous
173 to be useful, except in thoroughly ANSIfied programs. */
175 int warn_write_strings
;
177 /* Nonzero means warn about pointer casts that can drop a type qualifier
178 from the pointer target type. */
182 /* Nonzero means warn that dbx info for template class methods isn't fully
185 int warn_template_debugging
;
187 /* Nonzero means warn about sizeof(function) or addition/subtraction
188 of function pointers. */
190 int warn_pointer_arith
= 1;
192 /* Nonzero means warn for any function def without prototype decl. */
194 int warn_missing_prototypes
;
196 /* Nonzero means warn about multiple (redundant) decls for the same single
197 variable or function. */
199 int warn_redundant_decls
;
201 /* Warn if initializer is not completely bracketed. */
203 int warn_missing_braces
;
205 /* Warn about comparison of signed and unsigned values. */
207 int warn_sign_compare
;
209 /* Warn about *printf or *scanf format/argument anomalies. */
213 /* Warn about a subscript that has type char. */
215 int warn_char_subscripts
;
217 /* Warn if a type conversion is done that might have confusing results. */
221 /* Warn if adding () is suggested. */
223 int warn_parentheses
;
225 /* Non-zero means warn in function declared in derived class has the
226 same name as a virtual in the base class, but fails to match the
227 type signature of any virtual function in the base class. */
228 int warn_overloaded_virtual
;
230 /* Non-zero means warn when declaring a class that has a non virtual
231 destructor, when it really ought to have a virtual one. */
234 /* Non-zero means warn when a function is declared extern and later inline. */
235 int warn_extern_inline
;
237 /* Non-zero means warn when the compiler will reorder code. */
240 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
243 /* Non-zero means warn when we convert a pointer to member function
244 into a pointer to (void or function). */
245 int warn_pmf2ptr
= 1;
247 /* Nonzero means warn about violation of some Effective C++ style rules. */
251 /* Nonzero means `$' can be in an identifier.
252 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
254 #ifndef DOLLARS_IN_IDENTIFIERS
255 #define DOLLARS_IN_IDENTIFIERS 1
257 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
259 /* Nonzero for -fno-strict-prototype switch: do not consider empty
260 argument prototype to mean function takes no arguments. */
262 int flag_strict_prototype
= 2;
263 int strict_prototype
= 1;
264 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
266 /* Nonzero means that labels can be used as first-class objects */
270 /* Non-zero means to collect statistics which might be expensive
271 and to print them when we are done. */
272 int flag_detailed_statistics
;
274 /* C++ specific flags. */
275 /* Nonzero for -fall-virtual: make every member function (except
276 constructors) lay down in the virtual function table. Calls
277 can then either go through the virtual function table or not,
280 int flag_all_virtual
;
282 /* Zero means that `this' is a *const. This gives nice behavior in the
283 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
284 -2 means we're constructing an object and it has fixed type. */
286 int flag_this_is_variable
;
288 /* Nonzero means memoize our member lookups. */
290 int flag_memoize_lookups
; int flag_save_memoized_contexts
;
292 /* 3 means write out only virtuals function tables `defined'
293 in this implementation file.
294 2 means write out only specific virtual function tables
295 and give them (C) public access.
296 1 means write out virtual function tables and give them
298 0 means write out virtual function tables and give them
299 (C) static access (default).
300 -1 means declare virtual function tables extern. */
304 /* Nonzero means we should attempt to elide constructors when possible. */
306 int flag_elide_constructors
;
308 /* Nonzero means recognize and handle signature language constructs. */
310 int flag_handle_signatures
;
312 /* Nonzero means that member functions defined in class scope are
313 inline by default. */
315 int flag_default_inline
= 1;
317 /* Controls whether enums and ints freely convert.
318 1 means with complete freedom.
319 0 means enums can convert to ints, but not vice-versa. */
320 int flag_int_enum_equivalence
;
322 /* Controls whether compiler generates 'type descriptor' that give
323 run-time type information. */
326 /* Nonzero if we wish to output cross-referencing information
327 for the GNU class browser. */
328 extern int flag_gnu_xref
;
330 /* Nonzero if compiler can make `reasonable' assumptions about
331 references and objects. For example, the compiler must be
332 conservative about the following and not assume that `a' is nonnull:
337 In general, it is `reasonable' to assume that for many programs,
338 and better code can be generated in that case. */
340 int flag_assume_nonnull_objects
= 1;
342 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
345 int flag_huge_objects
;
347 /* Nonzero if we want to conserve space in the .o files. We do this
348 by putting uninitialized data and runtime initialized data into
349 .common instead of .data at the expense of not flagging multiple
352 int flag_conserve_space
;
354 /* Nonzero if we want to obey access control semantics. */
356 int flag_access_control
= 1;
358 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
360 int flag_operator_names
;
362 /* Nonzero if we want to check the return value of new and avoid calling
363 constructors if it is a null pointer. */
367 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
368 initialization variables.
369 0: Old rules, set by -fno-for-scope.
370 2: New ANSI rules, set by -ffor-scope.
371 1: Try to implement new ANSI rules, but with backup compatibility
372 (and warnings). This is the default, for now. */
374 int flag_new_for_scope
= 1;
376 /* Nonzero if we want to emit defined symbols with common-like linkage as
377 weak symbols where possible, in order to conform to C++ semantics.
378 Otherwise, emit them as local symbols. */
382 /* Maximum template instantiation depth. Must be at least 17 for ANSI
385 int max_tinst_depth
= 17;
387 /* Table of language-dependent -f options.
388 STRING is the option name. VARIABLE is the address of the variable.
389 ON_VALUE is the value to store in VARIABLE
390 if `-fSTRING' is seen as an option.
391 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
393 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
395 {"signed-char", &flag_signed_char
, 1},
396 {"unsigned-char", &flag_signed_char
, 0},
397 {"signed-bitfields", &flag_signed_bitfields
, 1},
398 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
399 {"short-enums", &flag_short_enums
, 1},
400 {"short-double", &flag_short_double
, 1},
401 {"cond-mismatch", &flag_cond_mismatch
, 1},
402 {"asm", &flag_no_asm
, 0},
403 {"builtin", &flag_no_builtin
, 0},
404 {"ident", &flag_no_ident
, 0},
405 {"labels-ok", &flag_labels_ok
, 1},
406 {"stats", &flag_detailed_statistics
, 1},
407 {"this-is-variable", &flag_this_is_variable
, 1},
408 {"strict-prototype", &flag_strict_prototype
, 1},
409 {"all-virtual", &flag_all_virtual
, 1},
410 {"memoize-lookups", &flag_memoize_lookups
, 1},
411 {"elide-constructors", &flag_elide_constructors
, 1},
412 {"handle-signatures", &flag_handle_signatures
, 1},
413 {"default-inline", &flag_default_inline
, 1},
414 {"dollars-in-identifiers", &dollars_in_ident
, 1},
415 {"enum-int-equiv", &flag_int_enum_equivalence
, 1},
416 {"rtti", &flag_rtti
, 1},
417 {"xref", &flag_gnu_xref
, 1},
418 {"nonnull-objects", &flag_assume_nonnull_objects
, 1},
419 {"implement-inlines", &flag_implement_inlines
, 1},
420 {"external-templates", &flag_external_templates
, 1},
421 {"implicit-templates", &flag_implicit_templates
, 1},
422 {"ansi-overloading", &flag_ansi_overloading
, 1},
423 {"huge-objects", &flag_huge_objects
, 1},
424 {"conserve-space", &flag_conserve_space
, 1},
425 {"vtable-thunks", &flag_vtable_thunks
, 1},
426 {"access-control", &flag_access_control
, 1},
427 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
428 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
429 {"operator-names", &flag_operator_names
, 1},
430 {"check-new", &flag_check_new
, 1},
431 {"repo", &flag_use_repository
, 1},
432 {"for-scope", &flag_new_for_scope
, 2},
433 {"weak", &flag_weak
, 1}
436 /* Decode the string P as a language-specific option.
437 Return 1 if it is recognized (and handle it);
438 return 0 if not recognized. */
441 lang_decode_option (p
)
444 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
445 dollars_in_ident
= 1, flag_writable_strings
= 1,
446 flag_this_is_variable
= 1, flag_new_for_scope
= 0;
447 /* The +e options are for cfront compatibility. They come in as
448 `-+eN', to kludge around gcc.c's argument handling. */
449 else if (p
[0] == '-' && p
[1] == '+' && p
[2] == 'e')
451 int old_write_virtuals
= write_virtuals
;
454 else if (p
[3] == '0')
456 else if (p
[3] == '2')
458 else error ("invalid +e option");
459 if (old_write_virtuals
!= 0
460 && write_virtuals
!= old_write_virtuals
)
461 error ("conflicting +e options given");
463 else if (p
[0] == '-' && p
[1] == 'f')
465 /* Some kind of -f option.
466 P's value is the option sans `-f'.
467 Search for it in the table of options. */
471 /* Try special -f options. */
473 if (!strcmp (p
, "save-memoized"))
475 flag_memoize_lookups
= 1;
476 flag_save_memoized_contexts
= 1;
479 if (!strcmp (p
, "no-save-memoized"))
481 flag_memoize_lookups
= 0;
482 flag_save_memoized_contexts
= 0;
485 else if (! strcmp (p
, "alt-external-templates"))
487 flag_external_templates
= 1;
488 flag_alt_external_templates
= 1;
491 else if (! strcmp (p
, "no-alt-external-templates"))
493 flag_alt_external_templates
= 0;
496 else if (!strcmp (p
, "repo"))
498 flag_use_repository
= 1;
499 flag_implicit_templates
= 0;
502 else if (!strncmp (p
, "template-depth-", 15))
507 if (*endp
>= '0' && *endp
<= '9')
511 error ("Invalid option `%s'", p
- 2);
512 goto template_depth_lose
;
515 max_tinst_depth
= atoi (p
+ 15);
516 template_depth_lose
: ;
519 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
522 if (!strcmp (p
, lang_f_options
[j
].string
))
524 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
525 /* A goto here would be cleaner,
526 but breaks the vax pcc. */
529 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
530 && ! strcmp (p
+3, lang_f_options
[j
].string
))
532 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
538 else if (p
[0] == '-' && p
[1] == 'W')
542 /* The -W options control the warning behavior of the compiler. */
545 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
548 if (!strcmp (p
, "implicit"))
549 warn_implicit
= setting
;
550 else if (!strcmp (p
, "return-type"))
551 warn_return_type
= setting
;
552 else if (!strcmp (p
, "ctor-dtor-privacy"))
553 warn_ctor_dtor_privacy
= setting
;
554 else if (!strcmp (p
, "write-strings"))
555 warn_write_strings
= setting
;
556 else if (!strcmp (p
, "cast-qual"))
557 warn_cast_qual
= setting
;
558 else if (!strcmp (p
, "char-subscripts"))
559 warn_char_subscripts
= setting
;
560 else if (!strcmp (p
, "pointer-arith"))
561 warn_pointer_arith
= setting
;
562 else if (!strcmp (p
, "missing-prototypes"))
563 warn_missing_prototypes
= setting
;
564 else if (!strcmp (p
, "redundant-decls"))
565 warn_redundant_decls
= setting
;
566 else if (!strcmp (p
, "missing-braces"))
567 warn_missing_braces
= setting
;
568 else if (!strcmp (p
, "sign-compare"))
569 warn_sign_compare
= setting
;
570 else if (!strcmp (p
, "format"))
571 warn_format
= setting
;
572 else if (!strcmp (p
, "conversion"))
573 warn_conversion
= setting
;
574 else if (!strcmp (p
, "parentheses"))
575 warn_parentheses
= setting
;
576 else if (!strcmp (p
, "non-virtual-dtor"))
577 warn_nonvdtor
= setting
;
578 else if (!strcmp (p
, "extern-inline"))
579 warn_extern_inline
= setting
;
580 else if (!strcmp (p
, "reorder"))
581 warn_reorder
= setting
;
582 else if (!strcmp (p
, "synth"))
583 warn_synth
= setting
;
584 else if (!strcmp (p
, "pmf-conversions"))
585 warn_pmf2ptr
= setting
;
586 else if (!strcmp (p
, "effc++"))
588 else if (!strcmp (p
, "comment"))
589 ; /* cpp handles this one. */
590 else if (!strcmp (p
, "comments"))
591 ; /* cpp handles this one. */
592 else if (!strcmp (p
, "trigraphs"))
593 ; /* cpp handles this one. */
594 else if (!strcmp (p
, "import"))
595 ; /* cpp handles this one. */
596 else if (!strcmp (p
, "all"))
598 warn_return_type
= setting
;
599 warn_unused
= setting
;
600 warn_implicit
= setting
;
601 warn_ctor_dtor_privacy
= setting
;
602 warn_switch
= setting
;
603 warn_format
= setting
;
604 warn_parentheses
= setting
;
605 warn_missing_braces
= setting
;
606 warn_sign_compare
= setting
;
607 warn_extern_inline
= setting
;
608 warn_nonvdtor
= setting
;
609 /* We save the value of warn_uninitialized, since if they put
610 -Wuninitialized on the command line, we need to generate a
611 warning about not using it without also specifying -O. */
612 if (warn_uninitialized
!= 1)
613 warn_uninitialized
= (setting
? 2 : 0);
614 warn_template_debugging
= setting
;
615 warn_reorder
= setting
;
618 else if (!strcmp (p
, "overloaded-virtual"))
619 warn_overloaded_virtual
= setting
;
622 else if (!strcmp (p
, "-ansi"))
623 dollars_in_ident
= 0, flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
624 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
626 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
627 it's probably safe to assume no sane person would ever want to use this
628 under normal circumstances. */
629 else if (!strcmp (p
, "-spew-debug"))
638 /* Incorporate `const' and `volatile' qualifiers for member functions.
639 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
640 QUALS is a list of qualifiers. */
643 grok_method_quals (ctype
, function
, quals
)
644 tree ctype
, function
, quals
;
646 tree fntype
= TREE_TYPE (function
);
647 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
651 extern tree ridpointers
[];
653 if (TREE_VALUE (quals
) == ridpointers
[(int)RID_CONST
])
655 if (TYPE_READONLY (ctype
))
656 error ("duplicate `%s' %s",
657 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
658 (TREE_CODE (function
) == FUNCTION_DECL
659 ? "for member function" : "in type declaration"));
660 ctype
= build_type_variant (ctype
, 1, TYPE_VOLATILE (ctype
));
661 build_pointer_type (ctype
);
663 else if (TREE_VALUE (quals
) == ridpointers
[(int)RID_VOLATILE
])
665 if (TYPE_VOLATILE (ctype
))
666 error ("duplicate `%s' %s",
667 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
668 (TREE_CODE (function
) == FUNCTION_DECL
669 ? "for member function" : "in type declaration"));
670 ctype
= build_type_variant (ctype
, TYPE_READONLY (ctype
), 1);
671 build_pointer_type (ctype
);
674 my_friendly_abort (20);
675 quals
= TREE_CHAIN (quals
);
678 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
679 (TREE_CODE (fntype
) == METHOD_TYPE
680 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
681 : TYPE_ARG_TYPES (fntype
)));
683 fntype
= build_exception_variant (fntype
, raises
);
685 TREE_TYPE (function
) = fntype
;
689 #if 0 /* Not used. */
690 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
691 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
692 /* This does not yet work with user defined conversion operators
696 substitute_nice_name (decl
)
699 if (DECL_NAME (decl
) && TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
701 char *n
= decl_as_string (DECL_NAME (decl
), 1);
702 if (n
[strlen (n
) - 1] == ' ')
703 n
[strlen (n
) - 1] = 0;
704 DECL_NAME (decl
) = get_identifier (n
);
709 /* Warn when -fexternal-templates is used and #pragma
710 interface/implementation is not used all the times it should be,
714 warn_if_unknown_interface (decl
)
717 static int already_warned
= 0;
718 if (already_warned
++)
721 if (flag_alt_external_templates
)
723 struct tinst_level
*til
= tinst_for_decl ();
725 char *sf
= input_filename
;
730 input_filename
= til
->file
;
732 cp_warning ("template `%#D' instantiated in file without #pragma interface",
738 cp_warning_at ("template `%#D' defined in file without #pragma interface",
742 /* A subroutine of the parser, to handle a component list. */
745 grok_x_components (specs
, components
)
746 tree specs
, components
;
748 register tree t
, x
, tcode
;
750 /* We just got some friends. They have been recorded elsewhere. */
751 if (components
== void_type_node
)
754 if (components
== NULL_TREE
)
756 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
760 error ("error in component specification");
764 switch (TREE_CODE (t
))
767 /* Static anonymous unions come out as VAR_DECLs. */
768 if (TREE_CODE (TREE_TYPE (t
)) == UNION_TYPE
769 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t
))))
772 /* We return SPECS here, because in the parser it was ending
773 up with not doing anything to $$, which is what SPECS
779 /* This code may be needed for UNION_TYPEs as
781 tcode
= record_type_node
;
782 if (CLASSTYPE_DECLARED_CLASS (t
))
783 tcode
= class_type_node
;
784 else if (IS_SIGNATURE (t
))
785 tcode
= signature_type_node
;
787 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
788 if (TYPE_CONTEXT (t
))
789 CLASSTYPE_NO_GLOBALIZE (t
) = 1;
795 if (TREE_CODE (t
) == UNION_TYPE
)
796 tcode
= union_type_node
;
798 tcode
= enum_type_node
;
800 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
801 if (TREE_CODE (t
) == UNION_TYPE
&& TYPE_CONTEXT (t
))
802 CLASSTYPE_NO_GLOBALIZE (t
) = 1;
803 if (TREE_CODE (t
) == UNION_TYPE
804 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))
806 /* See also shadow_tag. */
808 struct pending_inline
**p
;
810 x
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, t
);
812 /* Wipe out memory of synthesized methods */
813 TYPE_HAS_CONSTRUCTOR (t
) = 0;
814 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
815 TYPE_HAS_INIT_REF (t
) = 0;
816 TYPE_HAS_CONST_INIT_REF (t
) = 0;
817 TYPE_HAS_ASSIGN_REF (t
) = 0;
818 TYPE_HAS_ASSIGNMENT (t
) = 0;
819 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
821 q
= &TYPE_METHODS (t
);
824 if (DECL_ARTIFICIAL (*q
))
825 *q
= TREE_CHAIN (*q
);
827 q
= &TREE_CHAIN (*q
);
829 if (TYPE_METHODS (t
))
830 error ("an anonymous union cannot have function members");
832 p
= &pending_inlines
;
833 for (; *p
; *p
= (*p
)->next
)
834 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
837 else if (TREE_CODE (t
) == ENUMERAL_TYPE
)
838 x
= grok_enum_decls (t
, NULL_TREE
);
845 if (t
!= void_type_node
)
846 error ("empty component declaration");
852 t
= TREE_TYPE (components
);
853 if (TREE_CODE (t
) == ENUMERAL_TYPE
&& TREE_NONLOCAL_FLAG (t
))
854 return grok_enum_decls (t
, components
);
860 /* Classes overload their constituent function names automatically.
861 When a function name is declared in a record structure,
862 its name is changed to it overloaded name. Since names for
863 constructors and destructors can conflict, we place a leading
866 CNAME is the name of the class we are grokking for.
868 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
870 FLAGS contains bits saying what's special about today's
871 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
873 If FUNCTION is a destructor, then we must add the `auto-delete' field
874 as a second parameter. There is some hair associated with the fact
875 that we must "declare" this variable in the manner consistent with the
876 way the rest of the arguments were declared.
878 QUALS are the qualifiers for the this pointer. */
881 grokclassfn (ctype
, cname
, function
, flags
, quals
)
882 tree ctype
, cname
, function
;
883 enum overload_flags flags
;
886 tree fn_name
= DECL_NAME (function
);
890 tree fntype
= TREE_TYPE (function
);
891 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
893 if (fn_name
== NULL_TREE
)
895 error ("name missing for member function");
896 fn_name
= get_identifier ("<anonymous>");
897 DECL_NAME (function
) = fn_name
;
901 qualtype
= grok_method_quals (ctype
, function
, quals
);
905 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
906 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
908 /* Must add the class instance variable up front. */
909 /* Right now we just make this a pointer. But later
910 we may wish to make it special. */
911 tree type
= TREE_VALUE (arg_types
);
914 if ((flag_this_is_variable
> 0)
915 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
918 if (DECL_CONSTRUCTOR_P (function
))
920 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype
))
922 DECL_CONSTRUCTOR_FOR_VBASE_P (function
) = 1;
923 /* In this case we need "in-charge" flag saying whether
924 this constructor is responsible for initialization
925 of virtual baseclasses or not. */
926 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
927 /* Mark the artificial `__in_chrg' parameter as "artificial". */
928 SET_DECL_ARTIFICIAL (parm
);
929 DECL_ARG_TYPE (parm
) = integer_type_node
;
930 TREE_READONLY (parm
) = 1;
931 TREE_CHAIN (parm
) = last_function_parms
;
932 last_function_parms
= parm
;
936 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
937 /* Mark the artificial `this' parameter as "artificial". */
938 SET_DECL_ARTIFICIAL (parm
);
939 DECL_ARG_TYPE (parm
) = type
;
940 /* We can make this a register, so long as we don't
941 accidentally complain if someone tries to take its address. */
942 DECL_REGISTER (parm
) = 1;
944 TREE_READONLY (parm
) = 1;
945 TREE_CHAIN (parm
) = last_function_parms
;
946 last_function_parms
= parm
;
949 if (flags
== DTOR_FLAG
)
952 tree const_integer_type
= build_type_variant (integer_type_node
, 1, 0);
953 int len
= sizeof (DESTRUCTOR_DECL_PREFIX
)-1;
955 arg_types
= hash_tree_chain (const_integer_type
, void_list_node
);
956 TREE_SIDE_EFFECTS (arg_types
) = 1;
957 /* Build the overload name. It will look like `7Example'. */
958 if (IDENTIFIER_TYPE_VALUE (cname
))
959 dbuf
= build_overload_name (IDENTIFIER_TYPE_VALUE (cname
), 1, 1);
960 else if (IDENTIFIER_LOCAL_VALUE (cname
))
961 dbuf
= build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname
)), 1, 1);
963 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
964 it's defined out of the class definition, since poplevel_class wipes
965 it out. This used to be internal error 346. */
966 dbuf
= build_overload_name (ctype
, 1, 1);
967 buf
= (char *) alloca (strlen (dbuf
) + sizeof (DESTRUCTOR_DECL_PREFIX
));
968 bcopy (DESTRUCTOR_DECL_PREFIX
, buf
, len
);
971 DECL_ASSEMBLER_NAME (function
) = get_identifier (buf
);
972 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
973 /* Mark the artificial `__in_chrg' parameter as "artificial". */
974 SET_DECL_ARTIFICIAL (parm
);
975 TREE_READONLY (parm
) = 1;
976 DECL_ARG_TYPE (parm
) = integer_type_node
;
977 /* This is the same chain as DECL_ARGUMENTS (...). */
978 TREE_CHAIN (last_function_parms
) = parm
;
980 fntype
= build_cplus_method_type (qualtype
, void_type_node
,
984 fntype
= build_exception_variant (fntype
, raises
);
986 TREE_TYPE (function
) = fntype
;
987 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
991 tree these_arg_types
;
993 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function
))
995 arg_types
= hash_tree_chain (integer_type_node
,
996 TREE_CHAIN (arg_types
));
997 fntype
= build_cplus_method_type (qualtype
,
998 TREE_TYPE (TREE_TYPE (function
)),
1002 fntype
= build_exception_variant (fntype
, raises
);
1004 TREE_TYPE (function
) = fntype
;
1005 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1008 these_arg_types
= arg_types
;
1010 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
1011 /* Only true for static member functions. */
1012 these_arg_types
= hash_tree_chain (build_pointer_type (qualtype
),
1015 DECL_ASSEMBLER_NAME (function
)
1016 = build_decl_overload (fn_name
, these_arg_types
,
1017 1 + DECL_CONSTRUCTOR_P (function
));
1020 /* This code is going into the compiler, but currently, it makes
1021 libg++/src/Integer.cc not compile. The problem is that the nice name
1022 winds up going into the symbol table, and conversion operations look
1023 for the manged name. */
1024 substitute_nice_name (function
);
1028 DECL_ARGUMENTS (function
) = last_function_parms
;
1029 /* First approximations. */
1030 DECL_CONTEXT (function
) = ctype
;
1031 DECL_CLASS_CONTEXT (function
) = ctype
;
1034 /* Work on the expr used by alignof (this is only called by the parser). */
1043 if (TREE_CODE (expr
) == COMPONENT_REF
1044 && DECL_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1045 error ("`__alignof__' applied to a bit-field");
1047 if (TREE_CODE (expr
) == INDIRECT_REF
)
1049 best
= t
= TREE_OPERAND (expr
, 0);
1050 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1052 while (TREE_CODE (t
) == NOP_EXPR
1053 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1056 t
= TREE_OPERAND (t
, 0);
1057 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1058 if (thisalign
> bestalign
)
1059 best
= t
, bestalign
= thisalign
;
1061 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1065 /* ANSI says arrays and fns are converted inside comma.
1066 But we can't convert them in build_compound_expr
1067 because that would break commas in lvalues.
1068 So do the conversion here if operand was a comma. */
1069 if (TREE_CODE (expr
) == COMPOUND_EXPR
1070 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1071 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1072 expr
= default_conversion (expr
);
1073 return c_alignof (TREE_TYPE (expr
));
1077 /* Create an ARRAY_REF, checking for the user doing things backwards
1081 grok_array_decl (array_expr
, index_exp
)
1082 tree array_expr
, index_exp
;
1084 tree type
= TREE_TYPE (array_expr
);
1085 tree p1
, p2
, i1
, i2
;
1087 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1088 return error_mark_node
;
1089 if (processing_template_decl
)
1090 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
1091 array_expr
, index_exp
);
1093 if (type
== NULL_TREE
)
1095 /* Something has gone very wrong. Assume we are mistakenly reducing
1096 an expression instead of a declaration. */
1097 error ("parser may be lost: is there a '{' missing somewhere?");
1101 if (TREE_CODE (type
) == OFFSET_TYPE
1102 || TREE_CODE (type
) == REFERENCE_TYPE
)
1103 type
= TREE_TYPE (type
);
1105 /* If they have an `operator[]', use that. */
1106 if (TYPE_LANG_SPECIFIC (type
)
1107 && TYPE_OVERLOADS_ARRAY_REF (complete_type (type
)))
1108 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1109 array_expr
, index_exp
, NULL_TREE
);
1111 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1113 if (TREE_CODE (type
) == ARRAY_TYPE
)
1116 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1118 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1121 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1123 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1124 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1126 if ((p1
&& i2
) && (i1
&& p2
))
1127 error ("ambiguous conversion for array subscript");
1130 array_expr
= p1
, index_exp
= i2
;
1132 array_expr
= p2
, index_exp
= i1
;
1135 cp_error ("invalid types `%T[%T]' for array subscript",
1136 type
, TREE_TYPE (index_exp
));
1137 return error_mark_node
;
1140 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1141 error ("ambiguous conversion for array subscript");
1143 return build_array_ref (array_expr
, index_exp
);
1146 /* Given the cast expression EXP, checking out its validity. Either return
1147 an error_mark_node if there was an unavoidable error, return a cast to
1148 void for trying to delete a pointer w/ the value 0, or return the
1149 call to delete. If DOING_VEC is 1, we handle things differently
1150 for doing an array delete. If DOING_VEC is 2, they gave us the
1151 array size as an argument to delete.
1152 Implements ARM $5.3.4. This is called from the parser. */
1155 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1157 int doing_vec
, use_global_delete
;
1161 enum tree_code code
;
1162 /* For a regular vector delete (aka, no size argument) we will pass
1163 this down as a NULL_TREE into build_vec_delete. */
1164 tree maxindex
= NULL_TREE
;
1166 if (exp
== error_mark_node
)
1169 if (processing_template_decl
)
1171 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
1172 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
1173 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
1177 t
= stabilize_reference (convert_from_reference (exp
));
1178 type
= TREE_TYPE (t
);
1179 code
= TREE_CODE (type
);
1184 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1185 pedwarn ("anachronistic use of array size in vector delete");
1190 if (code
!= POINTER_TYPE
)
1192 cp_error ("type `%#T' argument given to `delete', expected pointer",
1194 return error_mark_node
;
1197 /* Deleting a pointer with the value zero is valid and has no effect. */
1198 if (integer_zerop (t
))
1199 return build1 (NOP_EXPR
, void_type_node
, t
);
1202 if (code
== POINTER_TYPE
)
1205 /* As of Valley Forge, you can delete a pointer to constant. */
1206 /* You can't delete a pointer to constant. */
1207 if (TREE_READONLY (TREE_TYPE (type
)))
1209 error ("`const *' cannot be deleted");
1210 return error_mark_node
;
1213 /* You also can't delete functions. */
1214 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1216 error ("cannot delete a function");
1217 return error_mark_node
;
1222 /* If the type has no destructor, then we should build a regular
1223 delete, instead of a vector delete. Otherwise, we would end
1224 up passing a bogus offset into __builtin_delete, which is
1225 not expecting it. */
1227 && TREE_CODE (type
) == POINTER_TYPE
1228 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type
)))
1231 use_global_delete
= 1;
1236 return build_vec_delete (t
, maxindex
, integer_one_node
,
1237 integer_two_node
, use_global_delete
);
1240 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1241 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1243 /* Only do access checking here; we'll be calling op delete
1244 from the destructor. */
1245 tree tmp
= build_opfncall (DELETE_EXPR
, LOOKUP_NORMAL
, t
,
1246 size_zero_node
, NULL_TREE
);
1247 if (tmp
== error_mark_node
)
1248 return error_mark_node
;
1251 return build_delete (type
, t
, integer_three_node
,
1252 LOOKUP_NORMAL
, use_global_delete
);
1256 /* Sanity check: report error if this function FUNCTION is not
1257 really a member of the class (CTYPE) it is supposed to belong to.
1258 CNAME is the same here as it is for grokclassfn above. */
1261 check_classfn (ctype
, function
)
1262 tree ctype
, function
;
1264 tree fn_name
= DECL_NAME (function
);
1266 tree method_vec
= CLASSTYPE_METHOD_VEC (complete_type (ctype
));
1270 if (method_vec
!= 0)
1272 methods
= &TREE_VEC_ELT (method_vec
, 0);
1273 end
= TREE_VEC_END (method_vec
);
1275 /* First suss out ctors and dtors. */
1276 if (*methods
&& fn_name
== DECL_NAME (*methods
)
1277 && DECL_CONSTRUCTOR_P (function
))
1279 if (*++methods
&& fn_name
== DECL_NAME (*methods
)
1280 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
)))
1283 while (++methods
!= end
)
1285 if (fn_name
== DECL_NAME (*methods
))
1291 if (DECL_ASSEMBLER_NAME (function
) == DECL_ASSEMBLER_NAME (fndecl
))
1294 /* This doesn't work for static member functions that are
1295 pretending to be methods. */
1296 /* We have to do more extensive argument checking here, as
1297 the name may have been changed by asm("new_name"). */
1298 if (decls_match (function
, fndecl
))
1301 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1303 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1304 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1306 /* Get rid of the this parameter on functions that become
1308 if (DECL_STATIC_FUNCTION_P (fndecl
)
1309 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1310 p1
= TREE_CHAIN (p1
);
1312 if (comptypes (TREE_TYPE (TREE_TYPE (function
)),
1313 TREE_TYPE (TREE_TYPE (fndecl
)), 1)
1314 && compparms (p1
, p2
, 3))
1318 fndecl
= DECL_CHAIN (fndecl
);
1327 tree fndecl
= *methods
;
1328 cp_error ("prototype for `%#D' does not match any in class `%T'",
1330 cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl
) ? "s are" : " is",
1332 while (fndecl
= DECL_CHAIN (fndecl
), fndecl
)
1333 cp_error_at (" %#D", fndecl
);
1338 cp_error ("no `%#D' member function declared in class `%T'",
1342 /* If we did not find the method in the class, add it to avoid
1344 add_method (ctype
, methods
, function
);
1348 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1349 of a structure component, returning a FIELD_DECL node.
1350 QUALS is a list of type qualifiers for this decl (such as for declaring
1351 const member functions).
1353 This is done during the parsing of the struct declaration.
1354 The FIELD_DECL nodes are chained together and the lot of them
1355 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1359 If class A defines that certain functions in class B are friends, then
1360 the way I have set things up, it is B who is interested in permission
1361 granted by A. However, it is in A's context that these declarations
1362 are parsed. By returning a void_type_node, class A does not attempt
1363 to incorporate the declarations of the friends within its structure.
1365 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1366 CHANGES TO CODE IN `start_method'. */
1369 grokfield (declarator
, declspecs
, init
, asmspec_tree
, attrlist
)
1370 tree declarator
, declspecs
, init
, asmspec_tree
, attrlist
;
1372 register tree value
;
1374 int flags
= LOOKUP_ONLYCONVERTING
;
1376 /* Convert () initializers to = initializers. */
1377 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1378 && TREE_CODE (declarator
) == CALL_EXPR
1379 && TREE_OPERAND (declarator
, 0)
1380 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1381 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1382 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1384 init
= TREE_OPERAND (declarator
, 1);
1385 declarator
= TREE_OPERAND (declarator
, 0);
1389 if (declspecs
== NULL_TREE
1390 && TREE_CODE (declarator
) == SCOPE_REF
1391 && TREE_CODE (TREE_OPERAND (declarator
, 1)) == IDENTIFIER_NODE
)
1393 /* Access declaration */
1394 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
1396 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
1397 pop_nested_class (1);
1398 return do_class_using_decl (declarator
);
1402 && TREE_CODE (init
) == TREE_LIST
1403 && TREE_VALUE (init
) == error_mark_node
1404 && TREE_CHAIN (init
) == NULL_TREE
)
1407 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, NULL_TREE
);
1409 return value
; /* friend or constructor went bad. */
1411 /* Pass friendly classes back. */
1412 if (TREE_CODE (value
) == VOID_TYPE
)
1413 return void_type_node
;
1415 if (DECL_NAME (value
) != NULL_TREE
1416 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1417 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1418 cp_error ("member `%D' conflicts with virtual function table field name", value
);
1420 /* Stash away type declarations. */
1421 if (TREE_CODE (value
) == TYPE_DECL
)
1423 DECL_NONLOCAL (value
) = 1;
1424 DECL_CONTEXT (value
) = current_class_type
;
1425 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1426 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
1428 pushdecl_class_level (value
);
1432 if (IS_SIGNATURE (current_class_type
)
1433 && TREE_CODE (value
) != FUNCTION_DECL
)
1435 error ("field declaration not allowed in signature");
1436 return void_type_node
;
1439 if (DECL_IN_AGGR_P (value
))
1441 cp_error ("`%D' is already defined in the class %T", value
,
1442 DECL_CONTEXT (value
));
1443 return void_type_node
;
1447 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1451 if (IS_SIGNATURE (current_class_type
)
1452 && TREE_CODE (value
) == FUNCTION_DECL
)
1454 error ("function declarations cannot have initializers in signature");
1457 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1459 grok_function_init (value
, init
);
1462 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1463 /* Already complained in grokdeclarator. */
1467 /* We allow initializers to become parameters to base
1469 if (TREE_CODE (init
) == TREE_LIST
)
1471 if (TREE_CHAIN (init
) == NULL_TREE
)
1472 init
= TREE_VALUE (init
);
1474 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1477 if (TREE_CODE (init
) == CONST_DECL
)
1478 init
= DECL_INITIAL (init
);
1479 else if (TREE_READONLY_DECL_P (init
))
1480 init
= decl_constant_value (init
);
1481 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1482 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1483 my_friendly_assert (TREE_PERMANENT (init
), 192);
1484 if (init
== error_mark_node
)
1485 /* We must make this look different than `error_mark_node'
1486 because `decl_const_value' would mis-interpret it
1487 as only meaning that this VAR_DECL is defined. */
1488 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1489 else if (processing_template_decl
)
1491 else if (! TREE_CONSTANT (init
))
1493 /* We can allow references to things that are effectively
1494 static, since references are initialized with the address. */
1495 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1496 || (TREE_STATIC (init
) == 0
1497 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1498 || DECL_EXTERNAL (init
) == 0)))
1500 error ("field initializer is not constant");
1501 init
= error_mark_node
;
1507 /* The corresponding pop_obstacks is in cp_finish_decl. */
1508 push_obstacks_nochange ();
1510 if (processing_template_decl
&& ! current_function_decl
1511 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1512 push_template_decl (value
);
1515 cplus_decl_attributes (value
, TREE_PURPOSE (attrlist
),
1516 TREE_VALUE (attrlist
));
1518 if (TREE_CODE (value
) == VAR_DECL
)
1520 /* We cannot call pushdecl here, because that would
1521 fill in the value of our TREE_CHAIN. Instead, we
1522 modify cp_finish_decl to do the right thing, namely, to
1523 put this decl out straight away. */
1524 if (TREE_PUBLIC (value
))
1526 /* current_class_type can be NULL_TREE in case of error. */
1527 if (asmspec
== 0 && current_class_type
)
1529 TREE_PUBLIC (value
) = 1;
1530 DECL_INITIAL (value
) = error_mark_node
;
1531 DECL_ASSEMBLER_NAME (value
)
1532 = build_static_name (current_class_type
, DECL_NAME (value
));
1534 if (! processing_template_decl
)
1535 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1537 /* Static consts need not be initialized in the class definition. */
1538 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1540 static int explanation
= 0;
1542 error ("initializer invalid for static member with constructor");
1543 if (explanation
++ == 0)
1544 error ("(you really want to initialize it separately)");
1547 /* Force the compiler to know when an uninitialized static
1548 const member is being used. */
1549 if (TYPE_READONLY (value
) && init
== 0)
1550 TREE_USED (value
) = 1;
1552 DECL_INITIAL (value
) = init
;
1553 DECL_IN_AGGR_P (value
) = 1;
1554 DECL_CONTEXT (value
) = current_class_type
;
1555 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1557 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1558 pushdecl_class_level (value
);
1561 if (TREE_CODE (value
) == FIELD_DECL
)
1565 /* This must override the asm specifier which was placed
1566 by grokclassfn. Lay this out fresh. */
1567 DECL_RTL (value
) = NULL_RTX
;
1568 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1570 if (DECL_INITIAL (value
) == error_mark_node
)
1571 init
= error_mark_node
;
1572 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1573 DECL_INITIAL (value
) = init
;
1574 DECL_IN_AGGR_P (value
) = 1;
1577 if (TREE_CODE (value
) == FUNCTION_DECL
)
1579 check_default_args (value
);
1580 if (DECL_CHAIN (value
) != NULL_TREE
)
1582 /* Need a fresh node here so that we don't get circularity
1583 when we link these together. */
1584 value
= copy_node (value
);
1585 /* When does this happen? */
1586 my_friendly_assert (init
== NULL_TREE
, 193);
1590 /* This must override the asm specifier which was placed
1591 by grokclassfn. Lay this out fresh. */
1592 DECL_RTL (value
) = NULL_RTX
;
1593 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1595 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1597 /* Pass friends back this way. */
1598 if (DECL_FRIEND_P (value
))
1599 return void_type_node
;
1601 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1602 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1603 cp_error ("method `%#D' of local class must be defined in class body",
1607 DECL_IN_AGGR_P (value
) = 1;
1610 my_friendly_abort (21);
1615 /* Like `grokfield', but for bitfields.
1616 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1619 grokbitfield (declarator
, declspecs
, width
)
1620 tree declarator
, declspecs
, width
;
1622 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1625 if (! value
) return NULL_TREE
; /* friends went bad. */
1627 /* Pass friendly classes back. */
1628 if (TREE_CODE (value
) == VOID_TYPE
)
1629 return void_type_node
;
1631 if (TREE_CODE (value
) == TYPE_DECL
)
1633 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1637 if (IS_SIGNATURE (current_class_type
))
1639 error ("field declaration not allowed in signature");
1640 return void_type_node
;
1643 if (DECL_IN_AGGR_P (value
))
1645 cp_error ("`%D' is already defined in the class %T", value
,
1646 DECL_CONTEXT (value
));
1647 return void_type_node
;
1650 GNU_xref_member (current_class_name
, value
);
1652 if (TREE_STATIC (value
))
1654 cp_error ("static member `%D' cannot be a bitfield", value
);
1657 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1659 if (width
!= error_mark_node
)
1661 constant_expression_warning (width
);
1662 DECL_INITIAL (value
) = width
;
1663 DECL_BIT_FIELD (value
) = 1;
1666 DECL_IN_AGGR_P (value
) = 1;
1671 grokoptypename (declspecs
, declarator
)
1672 tree declspecs
, declarator
;
1674 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1675 return build_typename_overload (t
);
1678 /* When a function is declared with an initializer,
1679 do the right thing. Currently, there are two possibilities:
1684 // initialization possibility #1.
1685 virtual void f () = 0;
1707 // initialization possibility #2
1714 copy_assignment_arg_p (parmtype
, virtualp
)
1718 if (current_class_type
== NULL_TREE
)
1721 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1722 parmtype
= TREE_TYPE (parmtype
);
1724 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1726 /* Non-standard hack to support old Booch components. */
1727 || (! virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
))
1736 grok_function_init (decl
, init
)
1740 /* An initializer for a function tells how this function should
1742 tree type
= TREE_TYPE (decl
);
1744 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1745 cp_error ("initializer specified for non-member function `%D'", decl
);
1747 /* We'll check for this in finish_struct_1. */
1748 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1749 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1751 else if (integer_zerop (init
))
1754 /* Mark this function as being "defined". */
1755 DECL_INITIAL (decl
) = error_mark_node
;
1756 /* pure virtual destructors must be defined. */
1757 /* pure virtual needs to be defined (as abort) only when put in
1758 vtbl. For wellformed call, it should be itself. pr4737 */
1759 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1761 extern tree abort_fndecl
;
1762 /* Give this node rtl from `abort'. */
1763 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1766 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1767 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1770 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1772 if (copy_assignment_arg_p (parmtype
, 1))
1773 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1776 else if (TREE_CODE (init
) == OFFSET_REF
1777 && TREE_OPERAND (init
, 0) == NULL_TREE
1778 && TREE_CODE (TREE_TYPE (init
)) == METHOD_TYPE
)
1780 tree basetype
= DECL_CLASS_CONTEXT (init
);
1781 tree basefn
= TREE_OPERAND (init
, 1);
1782 if (TREE_CODE (basefn
) != FUNCTION_DECL
)
1783 cp_error ("non-method initializer invalid for method `%D'", decl
);
1784 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn
))))
1785 sorry ("base member function from other than first base class");
1788 tree binfo
= get_binfo (basetype
, TYPE_METHOD_BASETYPE (type
), 1);
1789 if (binfo
== error_mark_node
)
1791 else if (binfo
== 0)
1792 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init
)),
1793 TYPE_METHOD_BASETYPE (type
));
1796 /* Mark this function as being defined,
1797 and give it new rtl. */
1798 DECL_INITIAL (decl
) = error_mark_node
;
1799 DECL_RTL (decl
) = DECL_RTL (basefn
);
1804 cp_error ("invalid initializer for virtual method `%D'", decl
);
1808 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1809 tree decl
, attributes
, prefix_attributes
;
1811 if (decl
== NULL_TREE
|| decl
== void_type_node
)
1814 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1815 decl
= DECL_TEMPLATE_RESULT (decl
);
1817 decl_attributes (decl
, attributes
, prefix_attributes
);
1819 if (TREE_CODE (decl
) == TYPE_DECL
)
1820 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
1823 /* CONSTRUCTOR_NAME:
1824 Return the name for the constructor (or destructor) for the
1825 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1826 IDENTIFIER_NODE. When given a template, this routine doesn't
1827 lose the specialization. */
1830 constructor_name_full (thing
)
1833 if (TREE_CODE (thing
) == TEMPLATE_TYPE_PARM
)
1834 thing
= TYPE_NAME (thing
);
1835 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
1837 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
1838 thing
= DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing
), 0));
1840 thing
= TYPE_NAME (thing
);
1842 if (TREE_CODE (thing
) == TYPE_DECL
1843 || (TREE_CODE (thing
) == TEMPLATE_DECL
1844 && TREE_CODE (DECL_TEMPLATE_RESULT (thing
)) == TYPE_DECL
))
1845 thing
= DECL_NAME (thing
);
1846 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
1850 /* CONSTRUCTOR_NAME:
1851 Return the name for the constructor (or destructor) for the
1852 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1853 IDENTIFIER_NODE. When given a template, return the plain
1854 unspecialized name. */
1857 constructor_name (thing
)
1861 thing
= constructor_name_full (thing
);
1862 t
= IDENTIFIER_TEMPLATE (thing
);
1868 /* Cache the value of this class's main virtual function table pointer
1869 in a register variable. This will save one indirection if a
1870 more than one virtual function call is made this function. */
1875 extern tree base_init_expr
;
1877 if (base_init_expr
== 0
1878 && DECL_CONSTRUCTOR_P (current_function_decl
))
1880 if (processing_template_decl
)
1881 add_tree (build_min_nt
1883 current_member_init_list
, current_base_init_list
));
1885 emit_base_init (current_class_type
, 0);
1889 /* Record the existence of an addressable inline function. */
1892 mark_inline_for_output (decl
)
1895 decl
= DECL_MAIN_VARIANT (decl
);
1896 if (DECL_SAVED_INLINE (decl
))
1898 my_friendly_assert (TREE_PERMANENT (decl
), 363);
1899 DECL_SAVED_INLINE (decl
) = 1;
1901 if (DECL_PENDING_INLINE_INFO (decl
) != 0
1902 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
1904 struct pending_inline
*t
= pending_inlines
;
1905 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
1908 if (t
== DECL_PENDING_INLINE_INFO (decl
))
1914 t
= DECL_PENDING_INLINE_INFO (decl
);
1915 t
->next
= pending_inlines
;
1916 pending_inlines
= t
;
1918 DECL_PENDING_INLINE_INFO (decl
) = 0;
1921 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
1927 temp_name_counter
= 0;
1930 /* Hand off a unique name which can be used for variable we don't really
1931 want to know about anyway, for example, the anonymous variables which
1932 are needed to make references work. Declare this thing so we can use it.
1933 The variable created will be of type TYPE.
1935 STATICP is nonzero if this variable should be static. */
1938 get_temp_name (type
, staticp
)
1942 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
1944 int toplev
= toplevel_bindings_p ();
1946 push_obstacks_nochange ();
1947 if (toplev
|| staticp
)
1949 end_temporary_allocation ();
1950 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
1951 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
1955 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
1956 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
1958 TREE_USED (decl
) = 1;
1959 TREE_STATIC (decl
) = staticp
;
1960 DECL_ARTIFICIAL (decl
) = 1;
1962 /* If this is a local variable, then lay out its rtl now.
1963 Otherwise, callers of this function are responsible for dealing
1964 with this variable's rtl. */
1968 expand_decl_init (decl
);
1975 /* Get a variable which we can use for multiple assignments.
1976 It is not entered into current_binding_level, because
1977 that breaks things when it comes time to do final cleanups
1978 (which take place "outside" the binding contour of the function). */
1981 get_temp_regvar (type
, init
)
1984 static char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20] = { '_' };
1987 sprintf (buf
+1, AUTO_TEMP_FORMAT
, temp_name_counter
++);
1988 decl
= build_decl (VAR_DECL
, get_identifier (buf
), type
);
1989 TREE_USED (decl
) = 1;
1990 DECL_REGISTER (decl
) = 1;
1993 store_init_value (decl
, init
);
1995 /* We can expand these without fear, since they cannot need
1996 constructors or destructors. */
1998 expand_decl_init (decl
);
2003 /* Finish off the processing of a UNION_TYPE structure.
2004 If there are static members, then all members are
2005 static, and must be laid out together. If the
2006 union is an anonymous union, we arrange for that
2007 as well. PUBLIC_P is nonzero if this union is
2008 not declared static. */
2011 finish_anon_union (anon_union_decl
)
2012 tree anon_union_decl
;
2014 tree type
= TREE_TYPE (anon_union_decl
);
2015 tree field
, main_decl
= NULL_TREE
;
2016 tree elems
= NULL_TREE
;
2017 int public_p
= TREE_PUBLIC (anon_union_decl
);
2018 int static_p
= TREE_STATIC (anon_union_decl
);
2019 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2021 if ((field
= TYPE_FIELDS (type
)) == NULL_TREE
)
2026 error ("global anonymous unions must be declared static");
2030 for (; field
; field
= TREE_CHAIN (field
))
2033 if (TREE_CODE (field
) != FIELD_DECL
)
2036 if (TREE_PRIVATE (field
))
2037 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
2038 else if (TREE_PROTECTED (field
))
2039 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
2041 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2042 /* tell `pushdecl' that this is not tentative. */
2043 DECL_INITIAL (decl
) = error_mark_node
;
2044 TREE_PUBLIC (decl
) = public_p
;
2045 TREE_STATIC (decl
) = static_p
;
2046 DECL_EXTERNAL (decl
) = external_p
;
2047 decl
= pushdecl (decl
);
2049 /* Only write out one anon union element--choose the one that
2050 can hold them all. */
2051 if (main_decl
== NULL_TREE
2052 && 1 == simple_cst_equal (DECL_SIZE (decl
),
2053 DECL_SIZE (anon_union_decl
)))
2059 /* ??? This causes there to be no debug info written out
2061 TREE_ASM_WRITTEN (decl
) = 1;
2064 DECL_INITIAL (decl
) = NULL_TREE
;
2065 /* If there's a cleanup to do, it belongs in the
2066 TREE_PURPOSE of the following TREE_LIST. */
2067 elems
= tree_cons (NULL_TREE
, decl
, elems
);
2068 TREE_TYPE (elems
) = type
;
2074 make_decl_rtl (main_decl
, 0, toplevel_bindings_p ());
2075 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2079 warning ("anonymous union with no members");
2084 /* The following call assumes that there are never any cleanups
2085 for anonymous unions--a reasonable assumption. */
2086 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2089 /* Finish and output a table which is generated by the compiler.
2090 NAME is the name to give the table.
2091 TYPE is the type of the table entry.
2092 INIT is all the elements in the table.
2093 PUBLICP is non-zero if this table should be given external access. */
2096 finish_table (name
, type
, init
, publicp
)
2097 tree name
, type
, init
;
2100 tree itype
, atype
, decl
;
2101 static tree empty_table
;
2105 itype
= build_index_type (size_int (list_length (init
) - 1));
2106 atype
= build_cplus_array_type (type
, itype
);
2107 layout_type (atype
);
2109 if (TREE_VALUE (init
) == integer_zero_node
2110 && TREE_CHAIN (init
) == NULL_TREE
)
2113 if (empty_table
== NULL_TREE
)
2116 empty_table
= get_temp_name (atype
, 1);
2117 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2118 TREE_CONSTANT (init
) = 1;
2119 TREE_STATIC (init
) = 1;
2120 DECL_INITIAL (empty_table
) = init
;
2121 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2122 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2123 cp_finish_decl (empty_table
, NULL_TREE
, asmspec
, 0, 0);
2128 if (name
== NULL_TREE
)
2132 decl
= get_temp_name (atype
, 1);
2136 decl
= build_decl (VAR_DECL
, name
, atype
);
2137 decl
= pushdecl (decl
);
2138 TREE_STATIC (decl
) = 1;
2143 TREE_PUBLIC (decl
) = publicp
;
2144 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2145 TREE_CONSTANT (init
) = 1;
2146 TREE_STATIC (init
) = 1;
2147 DECL_INITIAL (decl
) = init
;
2148 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (decl
)),
2149 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2153 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2154 DECL_EXTERNAL (decl
) = 1;
2155 TREE_STATIC (decl
) = 0;
2157 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2158 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2161 cp_finish_decl (decl
, NULL_TREE
, asmspec
, 0, 0);
2165 /* Finish processing a builtin type TYPE. It's name is NAME,
2166 its fields are in the array FIELDS. LEN is the number of elements
2167 in FIELDS minus one, or put another way, it is the maximum subscript
2170 It is given the same alignment as ALIGN_TYPE. */
2173 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2182 TYPE_FIELDS (type
) = fields
[0];
2183 for (i
= 0; i
< len
; i
++)
2185 layout_type (TREE_TYPE (fields
[i
]));
2186 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2187 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2189 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2190 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2191 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2193 #if 0 /* not yet, should get fixed properly later */
2194 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2196 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2198 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
2199 layout_decl (TYPE_NAME (type
), 0);
2202 /* Auxiliary functions to make type signatures for
2203 `operator new' and `operator delete' correspond to
2204 what compiler will be expecting. */
2206 extern tree sizetype
;
2209 coerce_new_type (type
)
2214 if (TREE_CODE (type
) == METHOD_TYPE
)
2215 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2216 if (TREE_TYPE (type
) != ptr_type_node
)
2217 e1
= 1, error ("`operator new' must return type `void *'");
2219 /* Technically the type must be `size_t', but we may not know
2221 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2222 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2223 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type
))) != INTEGER_TYPE
2224 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type
))) != TYPE_PRECISION (sizetype
))
2225 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2227 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2229 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2234 coerce_delete_type (type
)
2237 int e1
= 0, e2
= 0, e3
= 0;
2238 tree arg_types
= TYPE_ARG_TYPES (type
);
2240 if (TREE_CODE (type
) == METHOD_TYPE
)
2242 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2243 arg_types
= TREE_CHAIN (arg_types
);
2246 if (TREE_TYPE (type
) != void_type_node
)
2247 e1
= 1, error ("`operator delete' must return type `void'");
2249 if (arg_types
== NULL_TREE
2250 || TREE_VALUE (arg_types
) != ptr_type_node
)
2251 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2254 && TREE_CHAIN (arg_types
)
2255 && TREE_CHAIN (arg_types
) != void_list_node
)
2257 /* Again, technically this argument must be `size_t', but again
2258 we may not know what that is. */
2259 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2260 if (TREE_CODE (t2
) != INTEGER_TYPE
2261 || TYPE_PRECISION (t2
) != TYPE_PRECISION (sizetype
))
2262 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2263 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2266 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2267 error ("too many arguments in declaration of `operator delete'");
2269 error ("`...' invalid in specification of `operator delete'");
2274 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
,
2275 build_tree_list (NULL_TREE
, sizetype
));
2278 if (arg_types
== NULL_TREE
)
2279 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2281 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2286 type
= build_function_type (void_type_node
, arg_types
);
2291 extern tree abort_fndecl
;
2294 mark_vtable_entries (decl
)
2297 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
2301 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (TREE_CHAIN (entries
))
2302 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2303 tree fn
= TREE_OPERAND (fnaddr
, 0);
2304 TREE_ADDRESSABLE (fn
) = 1;
2307 skip_rtti_stuff (&entries
);
2309 for (; entries
; entries
= TREE_CHAIN (entries
))
2311 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (entries
)
2312 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2313 tree fn
= TREE_OPERAND (fnaddr
, 0);
2314 TREE_ADDRESSABLE (fn
) = 1;
2315 if (DECL_LANG_SPECIFIC (fn
) && DECL_ABSTRACT_VIRTUAL_P (fn
))
2316 TREE_OPERAND (fnaddr
, 0) = fn
= abort_fndecl
;
2317 if (TREE_CODE (fn
) == THUNK_DECL
&& DECL_EXTERNAL (fn
))
2319 DECL_EXTERNAL (fn
) = 0;
2326 /* Set DECL up to have the closest approximation of "initialized common"
2327 linkage available. */
2330 comdat_linkage (decl
)
2334 make_decl_one_only (decl
);
2336 TREE_PUBLIC (decl
) = 0;
2339 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2340 based on TYPE and other static flags.
2342 Note that anything public is tagged TREE_PUBLIC, whether
2343 it's public in this file or in another one. */
2346 import_export_vtable (decl
, type
, final
)
2350 if (DECL_INTERFACE_KNOWN (decl
))
2354 if (write_virtuals
< 2 && write_virtuals
!= 0)
2356 TREE_PUBLIC (decl
) = 1;
2357 if (write_virtuals
< 0)
2358 DECL_EXTERNAL (decl
) = 1;
2359 DECL_INTERFACE_KNOWN (decl
) = 1;
2361 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2363 TREE_PUBLIC (decl
) = 1;
2364 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2365 DECL_INTERFACE_KNOWN (decl
) = 1;
2369 /* We can only wait to decide if we have real non-inline virtual
2370 functions in our class, or if we come from a template. */
2372 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2374 if (! found
&& ! final
)
2377 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
2378 method
= TREE_CHAIN (method
))
2379 if (DECL_VINDEX (method
) != NULL_TREE
2380 && ! DECL_THIS_INLINE (method
)
2381 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2388 if (final
|| ! found
)
2390 comdat_linkage (decl
);
2391 DECL_EXTERNAL (decl
) = 0;
2395 TREE_PUBLIC (decl
) = 1;
2396 DECL_EXTERNAL (decl
) = 1;
2402 import_export_template (type
)
2405 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type
)
2406 && ! flag_implicit_templates
2407 && CLASSTYPE_INTERFACE_UNKNOWN (type
))
2409 SET_CLASSTYPE_INTERFACE_KNOWN (type
);
2410 CLASSTYPE_INTERFACE_ONLY (type
) = 1;
2411 CLASSTYPE_VTABLE_NEEDS_WRITING (type
) = 0;
2416 finish_prevtable_vardecl (prev
, vars
)
2419 tree ctype
= DECL_CONTEXT (vars
);
2420 import_export_template (ctype
);
2422 #ifndef MULTIPLE_SYMBOL_SPACES
2423 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype
) && TYPE_VIRTUAL_P (ctype
)
2424 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2427 for (method
= TYPE_METHODS (ctype
); method
!= NULL_TREE
;
2428 method
= TREE_CHAIN (method
))
2430 if (DECL_VINDEX (method
) != NULL_TREE
2431 && !DECL_THIS_INLINE (method
)
2432 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2434 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2435 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
) = ! DECL_EXTERNAL (method
);
2436 CLASSTYPE_INTERFACE_ONLY (ctype
) = DECL_EXTERNAL (method
);
2443 import_export_vtable (vars
, ctype
, 1);
2448 finish_vtable_vardecl (prev
, vars
)
2451 if (write_virtuals
>= 0
2452 && ! DECL_EXTERNAL (vars
)
2453 && ((TREE_PUBLIC (vars
) && ! DECL_WEAK (vars
) && ! DECL_ONE_ONLY (vars
))
2454 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
))
2455 || (hack_decl_function_context (vars
) && TREE_USED (vars
)))
2456 && ! TREE_ASM_WRITTEN (vars
))
2459 mark_vtable_entries (vars
);
2460 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2461 store_init_value (vars
, DECL_INITIAL (vars
));
2463 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2465 /* Mark the VAR_DECL node representing the vtable itself as a
2466 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2467 It is rather important that such things be ignored because
2468 any effort to actually generate DWARF for them will run
2469 into trouble when/if we encounter code like:
2472 struct S { virtual void member (); };
2474 because the artificial declaration of the vtable itself (as
2475 manufactured by the g++ front end) will say that the vtable
2476 is a static member of `S' but only *after* the debug output
2477 for the definition of `S' has already been output. This causes
2478 grief because the DWARF entry for the definition of the vtable
2479 will try to refer back to an earlier *declaration* of the
2480 vtable as a static member of `S' and there won't be one.
2481 We might be able to arrange to have the "vtable static member"
2482 attached to the member list for `S' before the debug info for
2483 `S' get written (which would solve the problem) but that would
2484 require more intrusive changes to the g++ front end. */
2486 DECL_IGNORED_P (vars
) = 1;
2489 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2492 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars
)))
2493 /* We don't know what to do with this one yet. */
2496 /* We know that PREV must be non-zero here. */
2497 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2502 prune_vtable_vardecl (prev
, vars
)
2505 /* We know that PREV must be non-zero here. */
2506 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2511 walk_vtables (typedecl_fn
, vardecl_fn
)
2512 register void (*typedecl_fn
)();
2513 register int (*vardecl_fn
)();
2518 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2520 register tree type
= TREE_TYPE (vars
);
2522 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2525 flag
|= (*vardecl_fn
) (prev
, vars
);
2527 if (prev
&& TREE_CHAIN (prev
) != vars
)
2530 else if (TREE_CODE (vars
) == TYPE_DECL
2531 && type
!= error_mark_node
2532 && TYPE_LANG_SPECIFIC (type
)
2533 && CLASSTYPE_VSIZE (type
))
2535 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2545 finish_sigtable_vardecl (prev
, vars
)
2548 /* We don't need to mark sigtable entries as addressable here as is done
2549 for vtables. Since sigtables, unlike vtables, are always written out,
2550 that was already done in build_signature_table_constructor. */
2552 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2554 /* We know that PREV must be non-zero here. */
2555 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2559 walk_sigtables (typedecl_fn
, vardecl_fn
)
2560 register void (*typedecl_fn
)();
2561 register void (*vardecl_fn
)();
2565 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2567 register tree type
= TREE_TYPE (vars
);
2569 if (TREE_CODE (vars
) == TYPE_DECL
2570 && type
!= error_mark_node
2571 && IS_SIGNATURE (type
))
2573 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2575 else if (TREE_CODE (vars
) == VAR_DECL
2576 && TREE_TYPE (vars
) != error_mark_node
2577 && IS_SIGNATURE (TREE_TYPE (vars
)))
2579 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2586 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2587 inline function or template instantiation at end-of-file. */
2590 import_export_decl (decl
)
2593 if (DECL_INTERFACE_KNOWN (decl
))
2596 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2598 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2599 if (DECL_IMPLICIT_INSTANTIATION (decl
)
2600 && (flag_implicit_templates
|| DECL_THIS_INLINE (decl
)))
2602 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2603 comdat_linkage (decl
);
2604 /* Dynamically initialized vars go into common. */
2605 else if (DECL_INITIAL (decl
) == NULL_TREE
2606 || DECL_INITIAL (decl
) == error_mark_node
)
2607 DECL_COMMON (decl
) = 1;
2608 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl
)))
2610 DECL_COMMON (decl
) = 1;
2611 DECL_INITIAL (decl
) = error_mark_node
;
2615 /* Statically initialized vars are weak or comdat, if
2618 make_decl_one_only (decl
);
2619 /* else leave vars public so multiple defs will break. */
2623 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2625 else if (DECL_FUNCTION_MEMBER_P (decl
))
2627 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2628 if (CLASSTYPE_INTERFACE_KNOWN (ctype
) && ! DECL_ARTIFICIAL (decl
))
2630 DECL_NOT_REALLY_EXTERN (decl
)
2631 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2632 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2635 comdat_linkage (decl
);
2637 /* tinfo function */
2638 else if (DECL_ARTIFICIAL (decl
) && DECL_MUTABLE_P (decl
))
2640 tree ctype
= TREE_TYPE (DECL_NAME (decl
));
2641 if (IS_AGGR_TYPE (ctype
) && CLASSTYPE_INTERFACE_KNOWN (ctype
)
2642 && TYPE_VIRTUAL_P (ctype
))
2644 DECL_NOT_REALLY_EXTERN (decl
)
2645 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2646 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2648 else if (TYPE_BUILT_IN (ctype
) && ctype
== TYPE_MAIN_VARIANT (ctype
))
2649 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2651 comdat_linkage (decl
);
2653 else if (DECL_C_STATIC (decl
))
2654 TREE_PUBLIC (decl
) = 0;
2656 comdat_linkage (decl
);
2658 DECL_INTERFACE_KNOWN (decl
) = 1;
2662 build_cleanup (decl
)
2666 tree type
= TREE_TYPE (decl
);
2668 if (TREE_CODE (type
) == ARRAY_TYPE
)
2672 mark_addressable (decl
);
2673 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
2675 temp
= build_delete (TREE_TYPE (temp
), temp
,
2677 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2681 extern int parse_time
, varconst_time
;
2682 extern tree pending_templates
;
2683 extern tree maybe_templates
;
2685 extern struct obstack permanent_obstack
;
2686 extern tree
get_id_2 ();
2692 tree sname
= get_id_2 ("__sn", base
);
2693 tree sentry
= IDENTIFIER_GLOBAL_VALUE (sname
);
2696 push_obstacks (&permanent_obstack
, &permanent_obstack
);
2697 sentry
= build_decl (VAR_DECL
, sname
, integer_type_node
);
2698 TREE_PUBLIC (sentry
) = 1;
2699 DECL_ARTIFICIAL (sentry
) = 1;
2700 TREE_STATIC (sentry
) = 1;
2701 TREE_USED (sentry
) = 1;
2702 DECL_COMMON (sentry
) = 1;
2703 pushdecl_top_level (sentry
);
2704 cp_finish_decl (sentry
, NULL_TREE
, NULL_TREE
, 0, 0);
2710 /* This routine is called from the last rule in yyparse ().
2711 Its job is to create all the code needed to initialize and
2712 destroy the global aggregates. We do the destruction
2713 first, since that way we only need to reverse the decls once. */
2719 int start_time
, this_time
;
2723 int needs_cleaning
= 0, needs_messing_up
= 0;
2727 if (flag_detailed_statistics
)
2728 dump_tree_statistics ();
2730 /* Bad parse errors. Just forget about it. */
2731 if (! global_bindings_p () || current_class_type
)
2734 start_time
= get_run_time ();
2736 /* Otherwise, GDB can get confused, because in only knows
2737 about source for LINENO-1 lines. */
2740 interface_unknown
= 1;
2743 for (fnname
= pending_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
2745 tree decl
= TREE_VALUE (fnname
);
2746 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
2748 instantiate_class_template (decl
);
2749 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl
))
2750 for (vars
= TYPE_METHODS (decl
); vars
; vars
= TREE_CHAIN (vars
))
2751 if (! DECL_ARTIFICIAL (vars
))
2752 instantiate_decl (vars
);
2755 instantiate_decl (decl
);
2758 for (fnname
= maybe_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
2760 tree
*args
, fn
, decl
= TREE_VALUE (fnname
);
2762 if (DECL_INITIAL (decl
))
2765 fn
= TREE_PURPOSE (fnname
);
2766 args
= get_bindings (fn
, decl
);
2767 fn
= instantiate_template (fn
, args
);
2769 instantiate_decl (fn
);
2772 /* Push into C language context, because that's all
2774 push_lang_context (lang_name_c
);
2777 /* The reason for pushing garbage onto the global_binding_level is to
2778 ensure that we can slice out _DECLs which pertain to virtual function
2779 tables. If the last thing pushed onto the global_binding_level was a
2780 virtual function table, then slicing it out would slice away all the
2781 decls (i.e., we lose the head of the chain).
2783 There are several ways of getting the same effect, from changing the
2784 way that iterators over the chain treat the elements that pertain to
2785 virtual function tables, moving the implementation of this code to
2786 decl.c (where we can manipulate global_binding_level directly),
2787 popping the garbage after pushing it and slicing away the vtable
2788 stuff, or just leaving it alone. */
2790 /* Make last thing in global scope not be a virtual function table. */
2791 #if 0 /* not yet, should get fixed properly later */
2792 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
2794 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
2796 DECL_IGNORED_P (vars
) = 1;
2797 SET_DECL_ARTIFICIAL (vars
);
2801 /* Walk to mark the inline functions we need, then output them so
2802 that we can pick up any other tdecls that those routines need. */
2803 walk_vtables ((void (*)())0, finish_prevtable_vardecl
);
2805 for (vars
= pending_statics
; vars
; vars
= TREE_CHAIN (vars
))
2807 tree decl
= TREE_VALUE (vars
);
2809 if (DECL_TEMPLATE_INSTANTIATION (decl
)
2810 && ! DECL_IN_AGGR_P (decl
))
2812 import_export_decl (decl
);
2813 DECL_EXTERNAL (decl
) = ! DECL_NOT_REALLY_EXTERN (decl
);
2817 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
2818 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars
)))
2819 rest_of_decl_compilation (TREE_VALUE (vars
), 0, 1, 1);
2820 vars
= static_aggregates
;
2822 if (static_ctors
|| vars
|| exception_table_p ())
2823 needs_messing_up
= 1;
2827 /* See if we really need the hassle. */
2828 while (vars
&& needs_cleaning
== 0)
2830 tree decl
= TREE_VALUE (vars
);
2831 tree type
= TREE_TYPE (decl
);
2832 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
))
2838 vars
= TREE_CHAIN (vars
);
2841 if (needs_cleaning
== 0)
2844 fnname
= get_file_function_name ('D');
2845 start_function (void_list_node
,
2846 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
2849 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2850 store_parm_decls ();
2855 expand_start_bindings (0);
2857 /* These must be done in backward order to destroy,
2858 in which they happen to be! */
2859 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
2861 tree decl
= TREE_VALUE (vars
);
2862 tree type
= TREE_TYPE (decl
);
2863 tree temp
= TREE_PURPOSE (vars
);
2865 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
)
2866 && ! DECL_EXTERNAL (decl
))
2868 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
2869 || DECL_ONE_ONLY (decl
)
2870 || DECL_WEAK (decl
)));
2872 temp
= build_cleanup (decl
);
2876 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
2877 sentry
= build_unary_op (PREDECREMENT_EXPR
, sentry
, 0);
2878 sentry
= build_binary_op (EQ_EXPR
, sentry
, integer_zero_node
, 1);
2879 expand_start_cond (sentry
, 0);
2882 expand_expr_stmt (temp
);
2889 for (; static_dtors
; static_dtors
= TREE_CHAIN (static_dtors
))
2890 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors
),
2893 expand_end_bindings (getdecls (), 1, 0);
2897 finish_function (lineno
, 0, 0);
2899 assemble_destructor (IDENTIFIER_POINTER (fnname
));
2901 /* if it needed cleaning, then it will need messing up: drop through */
2904 /* Must do this while we think we are at the top level. */
2905 vars
= nreverse (static_aggregates
);
2906 if (needs_messing_up
)
2908 fnname
= get_file_function_name ('I');
2909 start_function (void_list_node
,
2910 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
2913 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2914 store_parm_decls ();
2919 expand_start_bindings (0);
2921 if (exception_table_p ())
2922 register_exception_table ();
2926 tree decl
= TREE_VALUE (vars
);
2927 tree init
= TREE_PURPOSE (vars
);
2929 /* If this was a static attribute within some function's scope,
2930 then don't initialize it here. Also, don't bother
2931 with initializers that contain errors. */
2932 if (TREE_STATIC (vars
)
2933 || DECL_EXTERNAL (decl
)
2934 || (init
&& TREE_CODE (init
) == TREE_LIST
2935 && value_member (error_mark_node
, init
)))
2938 if (TREE_CODE (decl
) == VAR_DECL
)
2940 int protect
= (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
2941 || DECL_ONE_ONLY (decl
)
2942 || DECL_WEAK (decl
)));
2944 /* Set these global variables so that GDB at least puts
2945 us near the declaration which required the initialization. */
2946 input_filename
= DECL_SOURCE_FILE (decl
);
2947 lineno
= DECL_SOURCE_LINE (decl
);
2948 emit_note (input_filename
, lineno
);
2950 /* 9.5p5: The initializer of a static member of a class has
2951 the same access rights as a member function. */
2952 DECL_CLASS_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
2953 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
2957 tree sentry
= get_sentry (DECL_ASSEMBLER_NAME (decl
));
2958 sentry
= build_unary_op (PREINCREMENT_EXPR
, sentry
, 0);
2959 sentry
= build_binary_op
2960 (EQ_EXPR
, sentry
, integer_one_node
, 1);
2961 expand_start_cond (sentry
, 0);
2964 expand_start_target_temps ();
2966 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
2967 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
2968 expand_aggr_init (decl
, init
, 0, 0);
2969 else if (TREE_CODE (init
) == TREE_VEC
)
2971 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
2972 TREE_VEC_ELT (init
, 1),
2973 TREE_VEC_ELT (init
, 2), 0),
2974 const0_rtx
, VOIDmode
, 0);
2977 expand_assignment (decl
, init
, 0, 0);
2979 /* Cleanup any temporaries needed for the initial value. */
2980 expand_end_target_temps ();
2985 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
2986 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
2988 else if (decl
== error_mark_node
)
2990 else my_friendly_abort (22);
2993 vars
= TREE_CHAIN (vars
);
2996 for (; static_ctors
; static_ctors
= TREE_CHAIN (static_ctors
))
2997 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors
),
3000 expand_end_bindings (getdecls (), 1, 0);
3004 finish_function (lineno
, 0, 0);
3005 assemble_constructor (IDENTIFIER_POINTER (fnname
));
3008 expand_builtin_throw ();
3010 permanent_allocation (1);
3012 /* Done with C language context needs. */
3013 pop_lang_context ();
3015 /* Now write out any static class variables (which may have since
3016 learned how to be initialized). */
3017 while (pending_statics
)
3019 tree decl
= TREE_VALUE (pending_statics
);
3021 /* Output DWARF debug information. */
3022 #ifdef DWARF_DEBUGGING_INFO
3023 if (write_symbols
== DWARF_DEBUG
)
3024 dwarfout_file_scope_decl (decl
, 1);
3026 #ifdef DWARF2_DEBUGGING_INFO
3027 if (write_symbols
== DWARF2_DEBUG
)
3028 dwarf2out_decl (decl
);
3031 DECL_DEFER_OUTPUT (decl
) = 0;
3032 rest_of_decl_compilation
3033 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3035 pending_statics
= TREE_CHAIN (pending_statics
);
3038 this_time
= get_run_time ();
3039 parse_time
-= this_time
- start_time
;
3040 varconst_time
+= this_time
- start_time
;
3042 start_time
= get_run_time ();
3044 if (flag_handle_signatures
)
3045 walk_sigtables ((void (*)())0, finish_sigtable_vardecl
);
3047 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3049 tree decl
= TREE_VALUE (fnname
);
3050 import_export_decl (decl
);
3053 /* Now write out inline functions which had their addresses taken and
3054 which were not declared virtual and which were not declared `extern
3057 int reconsider
= 1; /* More may be referenced; check again */
3061 tree
*p
= &saved_inlines
;
3064 /* We need to do this each time so that newly completed template
3065 types don't wind up at the front of the list. Sigh. */
3066 vars
= build_decl (TYPE_DECL
, make_anon_name (), integer_type_node
);
3067 DECL_IGNORED_P (vars
) = 1;
3068 SET_DECL_ARTIFICIAL (vars
);
3071 reconsider
|= walk_vtables ((void (*)())0, finish_vtable_vardecl
);
3075 tree decl
= TREE_VALUE (*p
);
3077 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3079 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
3081 if (DECL_MUTABLE_P (decl
))
3082 synthesize_tinfo_fn (decl
);
3084 synthesize_method (decl
);
3088 /* Catch new template instantiations. */
3089 if (decl
!= TREE_VALUE (*p
))
3092 if (TREE_ASM_WRITTEN (decl
)
3093 || (DECL_SAVED_INSNS (decl
) == 0 && ! DECL_ARTIFICIAL (decl
)))
3094 *p
= TREE_CHAIN (*p
);
3095 else if (DECL_INITIAL (decl
) == 0)
3096 p
= &TREE_CHAIN (*p
);
3097 else if ((TREE_PUBLIC (decl
) && ! DECL_WEAK (decl
)
3098 && ! DECL_ONE_ONLY (decl
))
3099 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3100 || flag_keep_inline_functions
)
3102 if (DECL_NOT_REALLY_EXTERN (decl
))
3104 DECL_EXTERNAL (decl
) = 0;
3106 /* We can't inline this function after it's been
3107 emitted, so just disable inlining. We want a
3108 variant of output_inline_function that doesn't
3109 prevent subsequent integration... */
3111 temporary_allocation ();
3112 output_inline_function (decl
);
3113 permanent_allocation (1);
3116 *p
= TREE_CHAIN (*p
);
3119 p
= &TREE_CHAIN (*p
);
3124 /* Now delete from the chain of variables all virtual function tables.
3125 We output them all ourselves, because each will be treated specially. */
3127 walk_vtables ((void (*)())0, prune_vtable_vardecl
);
3129 for (vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
3131 if (TREE_CODE (vars
) == FUNCTION_DECL
3132 && ! DECL_INTERFACE_KNOWN (vars
)
3133 && DECL_C_STATIC (vars
))
3134 TREE_PUBLIC (vars
) = 0;
3137 if (write_virtuals
== 2)
3139 /* Now complain about an virtual function tables promised
3140 but not delivered. */
3141 while (pending_vtables
)
3143 if (TREE_PURPOSE (pending_vtables
) == NULL_TREE
)
3144 error ("virtual function table for `%s' not defined",
3145 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables
)));
3146 pending_vtables
= TREE_CHAIN (pending_vtables
);
3152 this_time
= get_run_time ();
3153 parse_time
-= this_time
- start_time
;
3154 varconst_time
+= this_time
- start_time
;
3156 if (flag_detailed_statistics
)
3157 dump_time_statistics ();
3160 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3161 expr. Since it was parsed like a type, we need to wade through and fix
3162 that. Unfortunately, since operator() is left-associative, we can't use
3163 tail recursion. In the above example, TYPE is `A', and DECL is
3166 Maybe this shouldn't be recursive, but how often will it actually be
3170 reparse_absdcl_as_expr (type
, decl
)
3173 /* do build_functional_cast (type, NULL_TREE) at bottom */
3174 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3175 return build_functional_cast (type
, NULL_TREE
);
3178 decl
= reparse_decl_as_expr (type
, TREE_OPERAND (decl
, 0));
3180 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_ref
);
3182 if (TREE_CODE (decl
) == CALL_EXPR
&& TREE_TYPE (decl
) != void_type_node
)
3183 decl
= require_complete_type (decl
);
3188 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3189 out to be an expr. Since it was parsed like a type, we need to wade
3190 through and fix that. Since casts are right-associative, we are
3191 reversing the order, so we don't have to recurse.
3193 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3197 reparse_absdcl_as_casts (decl
, expr
)
3202 if (TREE_CODE (expr
) == CONSTRUCTOR
3203 && TREE_TYPE (expr
) == 0)
3205 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3206 decl
= TREE_OPERAND (decl
, 0);
3208 if (IS_SIGNATURE (type
))
3210 error ("cast specifies signature type");
3211 return error_mark_node
;
3214 expr
= digest_init (type
, expr
, (tree
*) 0);
3215 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3217 int failure
= complete_array_type (type
, expr
, 1);
3219 my_friendly_abort (78);
3225 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3226 decl
= TREE_OPERAND (decl
, 0);
3227 expr
= build_c_cast (type
, expr
);
3233 /* Given plain tree nodes for an expression, build up the full semantics. */
3236 build_expr_from_tree (t
)
3239 if (t
== NULL_TREE
|| t
== error_mark_node
)
3242 switch (TREE_CODE (t
))
3244 case IDENTIFIER_NODE
:
3245 return do_identifier (t
, 0);
3248 if (LOOKUP_EXPR_GLOBAL (t
))
3249 return do_scoped_id (TREE_OPERAND (t
, 0), 0);
3251 return do_identifier (TREE_OPERAND (t
, 0), 0);
3254 return build_x_indirect_ref
3255 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3258 return build_functional_cast
3259 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3261 case REINTERPRET_CAST_EXPR
:
3262 return build_reinterpret_cast
3263 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3265 case CONST_CAST_EXPR
:
3266 return build_const_cast
3267 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3269 case DYNAMIC_CAST_EXPR
:
3270 return build_dynamic_cast
3271 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3273 case STATIC_CAST_EXPR
:
3274 return build_static_cast
3275 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3277 case PREDECREMENT_EXPR
:
3278 case PREINCREMENT_EXPR
:
3279 case POSTDECREMENT_EXPR
:
3280 case POSTINCREMENT_EXPR
:
3284 case TRUTH_NOT_EXPR
:
3286 case CONVERT_EXPR
: /* Unary + */
3289 return build_x_unary_op (TREE_CODE (t
),
3290 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3295 case TRUNC_DIV_EXPR
:
3297 case FLOOR_DIV_EXPR
:
3298 case ROUND_DIV_EXPR
:
3299 case EXACT_DIV_EXPR
:
3301 case BIT_ANDTC_EXPR
:
3304 case TRUNC_MOD_EXPR
:
3305 case FLOOR_MOD_EXPR
:
3306 case TRUTH_ANDIF_EXPR
:
3307 case TRUTH_ORIF_EXPR
:
3308 case TRUTH_AND_EXPR
:
3323 return build_x_binary_op
3325 build_expr_from_tree (TREE_OPERAND (t
, 0)),
3326 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3329 return build_m_component_ref
3330 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3331 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3334 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
3337 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
3339 return build_parse_node (ARRAY_REF
, NULL_TREE
,
3340 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3341 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3342 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3346 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3347 if (TREE_CODE_CLASS (TREE_CODE (r
)) != 't')
3349 return c_sizeof (r
);
3353 return build_x_modify_expr
3354 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3355 TREE_CODE (TREE_OPERAND (t
, 1)),
3356 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3359 return build_x_arrow
3360 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3364 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3365 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3366 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3367 NEW_EXPR_USE_GLOBAL (t
));
3370 return delete_sanity
3371 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3372 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3373 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
3376 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
3377 return build_x_compound_expr
3378 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3380 my_friendly_abort (42);
3382 case METHOD_CALL_EXPR
:
3383 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3385 tree ref
= TREE_OPERAND (t
, 0);
3386 return build_scoped_method_call
3387 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3388 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3389 TREE_OPERAND (ref
, 1),
3390 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3392 return build_method_call
3393 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3394 TREE_OPERAND (t
, 0),
3395 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3396 NULL_TREE
, LOOKUP_NORMAL
);
3399 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3401 tree ref
= TREE_OPERAND (t
, 0);
3402 return build_member_call
3403 (build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3404 TREE_OPERAND (ref
, 1),
3405 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3409 tree name
= TREE_OPERAND (t
, 0);
3410 if (! really_overloaded_fn (name
))
3411 name
= build_expr_from_tree (name
);
3412 return build_x_function_call
3413 (name
, build_expr_from_tree (TREE_OPERAND (t
, 1)),
3418 return build_x_conditional_expr
3419 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3420 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3421 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3425 tree purpose
, value
, chain
;
3427 if (t
== void_list_node
)
3430 purpose
= TREE_PURPOSE (t
);
3432 purpose
= build_expr_from_tree (purpose
);
3433 value
= TREE_VALUE (t
);
3435 value
= build_expr_from_tree (value
);
3436 chain
= TREE_CHAIN (t
);
3437 if (chain
&& chain
!= void_type_node
)
3438 chain
= build_expr_from_tree (chain
);
3439 return tree_cons (purpose
, value
, chain
);
3443 return build_x_component_ref
3444 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3445 TREE_OPERAND (t
, 1), NULL_TREE
, 1);
3448 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3452 tree r
= build_nt (CONSTRUCTOR
, NULL_TREE
,
3453 build_expr_from_tree (CONSTRUCTOR_ELTS (t
)));
3456 return digest_init (TREE_TYPE (t
), r
, 0);
3461 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
3462 return get_typeid (TREE_OPERAND (t
, 0));
3463 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3466 return convert_from_reference (t
);
3473 /* This is something of the form `int (*a)++' that has turned out to be an
3474 expr. It was only converted into parse nodes, so we need to go through
3475 and build up the semantics. Most of the work is done by
3476 build_expr_from_tree, above.
3478 In the above example, TYPE is `int' and DECL is `*a'. */
3481 reparse_decl_as_expr (type
, decl
)
3484 decl
= build_expr_from_tree (decl
);
3486 return build_functional_cast (type
, build_tree_list (NULL_TREE
, decl
));
3491 /* This is something of the form `int (*a)' that has turned out to be a
3492 decl. It was only converted into parse nodes, so we need to do the
3493 checking that make_{pointer,reference}_declarator do. */
3496 finish_decl_parsing (decl
)
3499 extern int current_class_depth
;
3501 switch (TREE_CODE (decl
))
3503 case IDENTIFIER_NODE
:
3506 return make_pointer_declarator
3507 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3509 return make_reference_declarator
3510 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3512 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3515 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3516 TREE_COMPLEXITY (decl
) = current_class_depth
;
3519 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3522 my_friendly_abort (5);
3528 check_cp_case_value (value
)
3531 if (value
== NULL_TREE
)
3534 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3535 STRIP_TYPE_NOPS (value
);
3537 if (TREE_READONLY_DECL_P (value
))
3539 value
= decl_constant_value (value
);
3540 STRIP_TYPE_NOPS (value
);
3542 value
= fold (value
);
3544 if (TREE_CODE (value
) != INTEGER_CST
3545 && value
!= error_mark_node
)
3547 cp_error ("case label `%E' does not reduce to an integer constant",
3549 value
= error_mark_node
;
3552 /* Promote char or short to int. */
3553 value
= default_conversion (value
);
3555 constant_expression_warning (value
);
3560 tree current_namespace
;
3562 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3563 postfix. Returns 0 if in global namespace. */
3568 tree x
= current_namespace
;
3570 x
= TREE_PURPOSE (x
);
3574 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3577 current_namespace_id (name
)
3580 tree old_id
= get_namespace_id ();
3583 /* Global names retain old encoding. */
3587 buf
= (char *) alloca (8 + IDENTIFIER_LENGTH (old_id
)
3588 + IDENTIFIER_LENGTH (name
));
3589 sprintf (buf
, "__ns_%s_%s", IDENTIFIER_POINTER (old_id
),
3590 IDENTIFIER_POINTER (name
));
3591 return get_identifier (buf
);
3595 do_namespace_alias (alias
, namespace)
3596 tree alias
, namespace;
3598 sorry ("namespace alias");
3602 do_toplevel_using_decl (decl
)
3605 if (decl
== NULL_TREE
|| decl
== error_mark_node
)
3608 if (TREE_CODE (decl
) == SCOPE_REF
)
3609 decl
= resolve_scope_to_name (NULL_TREE
, decl
);
3611 /* Is this the right way to do an id list? */
3612 if (TREE_CODE (decl
) != TREE_LIST
)
3619 pushdecl (TREE_VALUE (decl
));
3620 decl
= TREE_CHAIN (decl
);
3625 do_class_using_decl (decl
)
3630 if (TREE_CODE (decl
) != SCOPE_REF
)
3632 cp_error ("using-declaration for non-member at class scope");
3635 name
= TREE_OPERAND (decl
, 1);
3636 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
3638 cp_error ("using-declaration for destructor");
3642 value
= build_lang_field_decl (USING_DECL
, name
, void_type_node
);
3643 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
3648 do_using_directive (namespace)
3651 sorry ("using directive");
3655 check_default_args (x
)
3658 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
3659 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
3660 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
3662 if (TREE_PURPOSE (arg
))
3666 cp_error ("default argument missing for parameter %P of `%#D'",
3677 TREE_USED (decl
) = 1;
3678 if (processing_template_decl
)
3680 assemble_external (decl
);
3681 /* Is it a synthesized method that needs to be synthesized? */
3682 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CLASS_CONTEXT (decl
)
3683 && DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3684 /* Kludge: don't synthesize for default args. */
3685 && current_function_decl
)
3686 synthesize_method (decl
);
3687 if (DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
))
3688 instantiate_decl (decl
);