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 extern tree cleanups_this_call
;
42 static void grok_function_init
PROTO((tree
, tree
));
43 void import_export_decl ();
44 extern int current_class_depth
;
46 /* A list of virtual function tables we must make sure to write out. */
49 /* A list of static class variables. This is needed, because a
50 static class variable can be declared inside the class without
51 an initializer, and then initialized, staticly, outside the class. */
54 /* A list of functions which were declared inline, but which we
55 may need to emit outline anyway. */
56 static tree saved_inlines
;
58 /* Used to help generate temporary names which are unique within
59 a function. Reset to 0 by start_function. */
61 int temp_name_counter
;
63 /* Same, but not reset. Local temp variables and global temp variables
64 can have the same name. */
65 static int global_temp_name_counter
;
67 /* Flag used when debugging spew.c */
69 extern int spew_debug
;
71 /* Nonzero if we're done parsing and into end-of-file activities. */
75 /* Functions called along with real static constructors and destructors. */
77 tree static_ctors
, static_dtors
;
79 /* C (and C++) language-specific option variables. */
81 /* Nonzero means allow type mismatches in conditional expressions;
82 just make their values `void'. */
84 int flag_cond_mismatch
;
86 /* Nonzero means give `double' the same size as `float'. */
88 int flag_short_double
;
90 /* Nonzero means don't recognize the keyword `asm'. */
94 /* Nonzero means don't recognize any extension keywords. */
96 int flag_no_gnu_keywords
;
98 /* Nonzero means don't recognize the non-ANSI builtin functions. */
102 /* Nonzero means don't recognize the non-ANSI builtin functions.
105 int flag_no_nonansi_builtin
;
107 /* Nonzero means do some things the same way PCC does. */
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 emit exported implementations of functions even if
125 they can be inlined. */
127 int flag_implement_inlines
= 1;
129 /* Nonzero means do emit exported implementations of templates, instead of
130 multiple static copies in each file that needs a definition. */
132 int flag_external_templates
;
134 /* Nonzero means that the decision to emit or not emit the implementation of a
135 template depends on where the template is instantiated, rather than where
138 int flag_alt_external_templates
;
140 /* Nonzero means that implicit instantiations will be emitted if needed. */
142 int flag_implicit_templates
= 1;
144 /* Nonzero means warn about implicit declarations. */
146 int warn_implicit
= 1;
148 /* Nonzero means warn when all ctors or dtors are private, and the class
151 int warn_ctor_dtor_privacy
= 1;
153 /* True if we want to implement vtbvales using "thunks".
154 The default is off now, but will be on later. */
156 int flag_vtable_thunks
;
158 /* True if we want to deal with repository information. */
160 int flag_use_repository
;
162 /* Nonzero means give string constants the type `const char *'
163 to get extra warnings from them. These warnings will be too numerous
164 to be useful, except in thoroughly ANSIfied programs. */
166 int warn_write_strings
;
168 /* Nonzero means warn about pointer casts that can drop a type qualifier
169 from the pointer target type. */
173 /* Nonzero means warn that dbx info for template class methods isn't fully
176 int warn_template_debugging
;
178 /* Warn about traditional constructs whose meanings changed in ANSI C. */
180 int warn_traditional
;
182 /* Nonzero means warn about sizeof(function) or addition/subtraction
183 of function pointers. */
185 int warn_pointer_arith
= 1;
187 /* Nonzero means warn for non-prototype function decls
188 or non-prototyped defs without previous prototype. */
190 int warn_strict_prototypes
;
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 /* Nonzero means `$' can be in an identifier.
244 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
246 #ifndef DOLLARS_IN_IDENTIFIERS
247 #define DOLLARS_IN_IDENTIFIERS 1
249 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
251 /* Nonzero for -fno-strict-prototype switch: do not consider empty
252 argument prototype to mean function takes no arguments. */
254 int flag_strict_prototype
= 2;
255 int strict_prototype
= 1;
256 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
258 /* Nonzero means that labels can be used as first-class objects */
262 /* Non-zero means to collect statistics which might be expensive
263 and to print them when we are done. */
264 int flag_detailed_statistics
;
266 /* C++ specific flags. */
267 /* Nonzero for -fall-virtual: make every member function (except
268 constructors) lay down in the virtual function table. Calls
269 can then either go through the virtual function table or not,
272 int flag_all_virtual
;
274 /* Zero means that `this' is a *const. This gives nice behavior in the
275 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
276 -2 means we're constructing an object and it has fixed type. */
278 int flag_this_is_variable
;
280 /* Nonzero means memoize our member lookups. */
282 int flag_memoize_lookups
; int flag_save_memoized_contexts
;
284 /* 3 means write out only virtuals function tables `defined'
285 in this implementation file.
286 2 means write out only specific virtual function tables
287 and give them (C) public access.
288 1 means write out virtual function tables and give them
290 0 means write out virtual function tables and give them
291 (C) static access (default).
292 -1 means declare virtual function tables extern. */
296 /* Nonzero means we should attempt to elide constructors when possible. */
298 int flag_elide_constructors
;
300 /* Nonzero means recognize and handle exception handling constructs.
301 Use ansi syntax and semantics. WORK IN PROGRESS! */
303 int flag_handle_exceptions
;
305 /* Nonzero means recognize and handle signature language constructs. */
307 int flag_handle_signatures
;
309 /* Nonzero means that member functions defined in class scope are
310 inline by default. */
312 int flag_default_inline
= 1;
314 /* Controls whether enums and ints freely convert.
315 1 means with complete freedom.
316 0 means enums can convert to ints, but not vice-versa. */
317 int flag_int_enum_equivalence
;
319 /* Controls whether compiler generates 'type descriptor' that give
320 run-time type information. */
323 /* Nonzero if we wish to output cross-referencing information
324 for the GNU class browser. */
325 extern int flag_gnu_xref
;
327 /* Nonzero if compiler can make `reasonable' assumptions about
328 references and objects. For example, the compiler must be
329 conservative about the following and not assume that `a' is nonnull:
334 In general, it is `reasonable' to assume that for many programs,
335 and better code can be generated in that case. */
337 int flag_assume_nonnull_objects
= 1;
339 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
342 int flag_huge_objects
;
344 /* Nonzero if we want to conserve space in the .o files. We do this
345 by putting uninitialized data and runtime initialized data into
346 .common instead of .data at the expense of not flagging multiple
349 int flag_conserve_space
;
351 /* Nonzero if we want to obey access control semantics. */
353 int flag_access_control
= 1;
355 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
357 int flag_operator_names
;
359 /* Nonzero if we want to check the return value of new and avoid calling
360 constructors if it is a null pointer. */
364 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
365 initialization variables.
366 0: Old rules, set by -fno-for-scope.
367 2: New ANSI rules, set by -ffor-scope.
368 1: Try to implement new ANSI rules, but with backup compatibility
369 (and warnings). This is the default, for now. */
371 int flag_new_for_scope
= 1;
373 /* Nonzero if we want to emit defined symbols with common-like linkage as
374 weak symbols where possible, in order to conform to C++ semantics.
375 Otherwise, emit them as local symbols. */
379 /* Table of language-dependent -f options.
380 STRING is the option name. VARIABLE is the address of the variable.
381 ON_VALUE is the value to store in VARIABLE
382 if `-fSTRING' is seen as an option.
383 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
385 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
387 {"signed-char", &flag_signed_char
, 1},
388 {"unsigned-char", &flag_signed_char
, 0},
389 {"signed-bitfields", &flag_signed_bitfields
, 1},
390 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
391 {"short-enums", &flag_short_enums
, 1},
392 {"short-double", &flag_short_double
, 1},
393 {"cond-mismatch", &flag_cond_mismatch
, 1},
394 {"asm", &flag_no_asm
, 0},
395 {"builtin", &flag_no_builtin
, 0},
396 {"ident", &flag_no_ident
, 0},
397 {"labels-ok", &flag_labels_ok
, 1},
398 {"stats", &flag_detailed_statistics
, 1},
399 {"this-is-variable", &flag_this_is_variable
, 1},
400 {"strict-prototype", &flag_strict_prototype
, 1},
401 {"all-virtual", &flag_all_virtual
, 1},
402 {"memoize-lookups", &flag_memoize_lookups
, 1},
403 {"elide-constructors", &flag_elide_constructors
, 1},
404 {"handle-exceptions", &flag_handle_exceptions
, 1},
405 {"handle-signatures", &flag_handle_signatures
, 1},
406 {"default-inline", &flag_default_inline
, 1},
407 {"dollars-in-identifiers", &dollars_in_ident
, 1},
408 {"enum-int-equiv", &flag_int_enum_equivalence
, 1},
409 {"rtti", &flag_rtti
, 1},
410 {"xref", &flag_gnu_xref
, 1},
411 {"nonnull-objects", &flag_assume_nonnull_objects
, 1},
412 {"implement-inlines", &flag_implement_inlines
, 1},
413 {"external-templates", &flag_external_templates
, 1},
414 {"implicit-templates", &flag_implicit_templates
, 1},
415 {"huge-objects", &flag_huge_objects
, 1},
416 {"conserve-space", &flag_conserve_space
, 1},
417 {"vtable-thunks", &flag_vtable_thunks
, 1},
418 {"short-temps", &flag_short_temps
, 1},
419 {"access-control", &flag_access_control
, 1},
420 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
421 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
422 {"operator-names", &flag_operator_names
, 1},
423 {"check-new", &flag_check_new
, 1},
424 {"repo", &flag_use_repository
, 1},
425 {"for-scope", &flag_new_for_scope
, 2},
426 {"weak", &flag_weak
, 1}
429 /* Decode the string P as a language-specific option.
430 Return 1 if it is recognized (and handle it);
431 return 0 if not recognized. */
434 lang_decode_option (p
)
437 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
438 flag_traditional
= 1, dollars_in_ident
= 1, flag_writable_strings
= 1,
439 flag_this_is_variable
= 1, flag_new_for_scope
= 0;
440 /* The +e options are for cfront compatibility. They come in as
441 `-+eN', to kludge around gcc.c's argument handling. */
442 else if (p
[0] == '-' && p
[1] == '+' && p
[2] == 'e')
444 int old_write_virtuals
= write_virtuals
;
447 else if (p
[3] == '0')
449 else if (p
[3] == '2')
451 else error ("invalid +e option");
452 if (old_write_virtuals
!= 0
453 && write_virtuals
!= old_write_virtuals
)
454 error ("conflicting +e options given");
456 else if (p
[0] == '-' && p
[1] == 'f')
458 /* Some kind of -f option.
459 P's value is the option sans `-f'.
460 Search for it in the table of options. */
464 /* Try special -f options. */
466 if (!strcmp (p
, "save-memoized"))
468 flag_memoize_lookups
= 1;
469 flag_save_memoized_contexts
= 1;
472 if (!strcmp (p
, "no-save-memoized"))
474 flag_memoize_lookups
= 0;
475 flag_save_memoized_contexts
= 0;
478 else if (! strcmp (p
, "alt-external-templates"))
480 flag_external_templates
= 1;
481 flag_alt_external_templates
= 1;
484 else if (! strcmp (p
, "no-alt-external-templates"))
486 flag_alt_external_templates
= 0;
489 else if (!strcmp (p
, "ansi-overloading"))
491 warning ("-fansi-overloading is no longer meaningful");
494 else if (!strcmp (p
, "repo"))
496 flag_use_repository
= 1;
497 flag_implicit_templates
= 0;
501 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
504 if (!strcmp (p
, lang_f_options
[j
].string
))
506 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
507 /* A goto here would be cleaner,
508 but breaks the vax pcc. */
511 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
512 && ! strcmp (p
+3, lang_f_options
[j
].string
))
514 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
520 else if (p
[0] == '-' && p
[1] == 'W')
524 /* The -W options control the warning behavior of the compiler. */
527 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
530 if (!strcmp (p
, "implicit"))
531 warn_implicit
= setting
;
532 else if (!strcmp (p
, "return-type"))
533 warn_return_type
= setting
;
534 else if (!strcmp (p
, "ctor-dtor-privacy"))
535 warn_ctor_dtor_privacy
= setting
;
536 else if (!strcmp (p
, "write-strings"))
537 warn_write_strings
= setting
;
538 else if (!strcmp (p
, "cast-qual"))
539 warn_cast_qual
= setting
;
540 else if (!strcmp (p
, "traditional"))
541 warn_traditional
= setting
;
542 else if (!strcmp (p
, "char-subscripts"))
543 warn_char_subscripts
= setting
;
544 else if (!strcmp (p
, "pointer-arith"))
545 warn_pointer_arith
= setting
;
546 else if (!strcmp (p
, "strict-prototypes"))
547 warn_strict_prototypes
= setting
;
548 else if (!strcmp (p
, "missing-prototypes"))
549 warn_missing_prototypes
= setting
;
550 else if (!strcmp (p
, "redundant-decls"))
551 warn_redundant_decls
= setting
;
552 else if (!strcmp (p
, "missing-braces"))
553 warn_missing_braces
= setting
;
554 else if (!strcmp (p
, "sign-compare"))
555 warn_sign_compare
= setting
;
556 else if (!strcmp (p
, "format"))
557 warn_format
= setting
;
558 else if (!strcmp (p
, "conversion"))
559 warn_conversion
= setting
;
560 else if (!strcmp (p
, "parentheses"))
561 warn_parentheses
= setting
;
562 else if (!strcmp (p
, "non-virtual-dtor"))
563 warn_nonvdtor
= setting
;
564 else if (!strcmp (p
, "extern-inline"))
565 warn_extern_inline
= setting
;
566 else if (!strcmp (p
, "reorder"))
567 warn_reorder
= setting
;
568 else if (!strcmp (p
, "synth"))
569 warn_synth
= setting
;
570 else if (!strcmp (p
, "comment"))
571 ; /* cpp handles this one. */
572 else if (!strcmp (p
, "comments"))
573 ; /* cpp handles this one. */
574 else if (!strcmp (p
, "trigraphs"))
575 ; /* cpp handles this one. */
576 else if (!strcmp (p
, "import"))
577 ; /* cpp handles this one. */
578 else if (!strcmp (p
, "all"))
580 warn_return_type
= setting
;
581 warn_unused
= setting
;
582 warn_implicit
= setting
;
583 warn_ctor_dtor_privacy
= setting
;
584 warn_switch
= setting
;
585 warn_format
= setting
;
586 warn_parentheses
= setting
;
587 warn_missing_braces
= setting
;
588 warn_sign_compare
= setting
;
589 warn_extern_inline
= setting
;
590 warn_nonvdtor
= setting
;
591 /* We save the value of warn_uninitialized, since if they put
592 -Wuninitialized on the command line, we need to generate a
593 warning about not using it without also specifying -O. */
594 if (warn_uninitialized
!= 1)
595 warn_uninitialized
= (setting
? 2 : 0);
596 warn_template_debugging
= setting
;
597 warn_reorder
= setting
;
600 else if (!strcmp (p
, "overloaded-virtual"))
601 warn_overloaded_virtual
= setting
;
604 else if (!strcmp (p
, "-ansi"))
605 dollars_in_ident
= 0, flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
606 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
608 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
609 it's probably safe to assume no sane person would ever want to use this
610 under normal circumstances. */
611 else if (!strcmp (p
, "-spew-debug"))
620 /* Incorporate `const' and `volatile' qualifiers for member functions.
621 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
622 QUALS is a list of qualifiers. */
624 grok_method_quals (ctype
, function
, quals
)
625 tree ctype
, function
, quals
;
627 tree fntype
= TREE_TYPE (function
);
628 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
632 extern tree ridpointers
[];
634 if (TREE_VALUE (quals
) == ridpointers
[(int)RID_CONST
])
636 if (TYPE_READONLY (ctype
))
637 error ("duplicate `%s' %s",
638 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
639 (TREE_CODE (function
) == FUNCTION_DECL
640 ? "for member function" : "in type declaration"));
641 ctype
= build_type_variant (ctype
, 1, TYPE_VOLATILE (ctype
));
642 build_pointer_type (ctype
);
644 else if (TREE_VALUE (quals
) == ridpointers
[(int)RID_VOLATILE
])
646 if (TYPE_VOLATILE (ctype
))
647 error ("duplicate `%s' %s",
648 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
649 (TREE_CODE (function
) == FUNCTION_DECL
650 ? "for member function" : "in type declaration"));
651 ctype
= build_type_variant (ctype
, TYPE_READONLY (ctype
), 1);
652 build_pointer_type (ctype
);
655 my_friendly_abort (20);
656 quals
= TREE_CHAIN (quals
);
659 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
660 (TREE_CODE (fntype
) == METHOD_TYPE
661 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
662 : TYPE_ARG_TYPES (fntype
)));
664 fntype
= build_exception_variant (fntype
, raises
);
666 TREE_TYPE (function
) = fntype
;
670 #if 0 /* Not used. */
671 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
672 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
673 /* This does not yet work with user defined conversion operators
676 substitute_nice_name (decl
)
679 if (DECL_NAME (decl
) && TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
681 char *n
= decl_as_string (DECL_NAME (decl
), 1);
682 if (n
[strlen (n
) - 1] == ' ')
683 n
[strlen (n
) - 1] = 0;
684 DECL_NAME (decl
) = get_identifier (n
);
689 /* Warn when -fexternal-templates is used and #pragma
690 interface/implementation is not used all the times it should be,
693 warn_if_unknown_interface (decl
)
696 static int already_warned
= 0;
697 if (already_warned
++)
700 if (flag_alt_external_templates
)
702 struct tinst_level
*til
= tinst_for_decl ();
704 char *sf
= input_filename
;
709 input_filename
= til
->file
;
711 cp_warning ("template `%#D' instantiated in file without #pragma interface",
717 cp_warning_at ("template `%#D' defined in file without #pragma interface",
721 /* A subroutine of the parser, to handle a component list. */
723 grok_x_components (specs
, components
)
724 tree specs
, components
;
726 register tree t
, x
, tcode
;
728 /* We just got some friends. They have been recorded elsewhere. */
729 if (components
== void_type_node
)
732 if (components
== NULL_TREE
)
734 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
738 error ("error in component specification");
742 switch (TREE_CODE (t
))
745 /* Static anonymous unions come out as VAR_DECLs. */
746 if (TREE_CODE (TREE_TYPE (t
)) == UNION_TYPE
747 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t
))))
750 /* We return SPECS here, because in the parser it was ending
751 up with not doing anything to $$, which is what SPECS
757 /* This code may be needed for UNION_TYPEs as
759 tcode
= record_type_node
;
760 if (CLASSTYPE_DECLARED_CLASS (t
))
761 tcode
= class_type_node
;
762 else if (IS_SIGNATURE (t
))
763 tcode
= signature_type_node
;
765 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
766 if (TYPE_CONTEXT (t
))
767 CLASSTYPE_NO_GLOBALIZE (t
) = 1;
773 if (TREE_CODE (t
) == UNION_TYPE
)
774 tcode
= union_type_node
;
776 tcode
= enum_type_node
;
778 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
779 if (TREE_CODE (t
) == UNION_TYPE
&& TYPE_CONTEXT (t
))
780 CLASSTYPE_NO_GLOBALIZE (t
) = 1;
781 if (TREE_CODE (t
) == UNION_TYPE
782 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))
784 struct pending_inline
**p
;
785 x
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, t
);
787 /* Wipe out memory of synthesized methods */
788 TYPE_HAS_CONSTRUCTOR (t
) = 0;
789 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
790 TYPE_HAS_INIT_REF (t
) = 0;
791 TYPE_HAS_CONST_INIT_REF (t
) = 0;
792 TYPE_HAS_ASSIGN_REF (t
) = 0;
793 TYPE_HAS_ASSIGNMENT (t
) = 0;
794 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
796 p
= &pending_inlines
;
797 for (; *p
; *p
= (*p
)->next
)
798 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
801 else if (TREE_CODE (t
) == ENUMERAL_TYPE
)
802 x
= grok_enum_decls (t
, NULL_TREE
);
809 if (t
!= void_type_node
)
810 error ("empty component declaration");
816 t
= TREE_TYPE (components
);
817 if (TREE_CODE (t
) == ENUMERAL_TYPE
&& TREE_NONLOCAL_FLAG (t
))
818 return grok_enum_decls (t
, components
);
824 /* Classes overload their constituent function names automatically.
825 When a function name is declared in a record structure,
826 its name is changed to it overloaded name. Since names for
827 constructors and destructors can conflict, we place a leading
830 CNAME is the name of the class we are grokking for.
832 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
834 FLAGS contains bits saying what's special about today's
835 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
837 If FUNCTION is a destructor, then we must add the `auto-delete' field
838 as a second parameter. There is some hair associated with the fact
839 that we must "declare" this variable in the manner consistent with the
840 way the rest of the arguments were declared.
842 QUALS are the qualifiers for the this pointer. */
845 grokclassfn (ctype
, cname
, function
, flags
, quals
)
846 tree ctype
, cname
, function
;
847 enum overload_flags flags
;
850 tree fn_name
= DECL_NAME (function
);
854 tree fntype
= TREE_TYPE (function
);
855 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
857 if (fn_name
== NULL_TREE
)
859 error ("name missing for member function");
860 fn_name
= get_identifier ("<anonymous>");
861 DECL_NAME (function
) = fn_name
;
865 qualtype
= grok_method_quals (ctype
, function
, quals
);
869 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
870 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
872 /* Must add the class instance variable up front. */
873 /* Right now we just make this a pointer. But later
874 we may wish to make it special. */
875 tree type
= TREE_VALUE (arg_types
);
878 if ((flag_this_is_variable
> 0)
879 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
882 if (DECL_CONSTRUCTOR_P (function
))
884 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype
))
886 DECL_CONSTRUCTOR_FOR_VBASE_P (function
) = 1;
887 /* In this case we need "in-charge" flag saying whether
888 this constructor is responsible for initialization
889 of virtual baseclasses or not. */
890 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
891 /* Mark the artificial `__in_chrg' parameter as "artificial". */
892 SET_DECL_ARTIFICIAL (parm
);
893 DECL_ARG_TYPE (parm
) = integer_type_node
;
894 TREE_READONLY (parm
) = 1;
895 TREE_CHAIN (parm
) = last_function_parms
;
896 last_function_parms
= parm
;
900 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
901 /* Mark the artificial `this' parameter as "artificial". */
902 SET_DECL_ARTIFICIAL (parm
);
903 DECL_ARG_TYPE (parm
) = type
;
904 /* We can make this a register, so long as we don't
905 accidentally complain if someone tries to take its address. */
906 DECL_REGISTER (parm
) = 1;
908 TREE_READONLY (parm
) = 1;
909 TREE_CHAIN (parm
) = last_function_parms
;
910 last_function_parms
= parm
;
913 if (flags
== DTOR_FLAG
)
916 tree const_integer_type
= build_type_variant (integer_type_node
, 1, 0);
917 int len
= sizeof (DESTRUCTOR_DECL_PREFIX
)-1;
919 arg_types
= hash_tree_chain (const_integer_type
, void_list_node
);
920 TREE_SIDE_EFFECTS (arg_types
) = 1;
921 /* Build the overload name. It will look like `7Example'. */
922 if (IDENTIFIER_TYPE_VALUE (cname
))
923 dbuf
= build_overload_name (IDENTIFIER_TYPE_VALUE (cname
), 1, 1);
924 else if (IDENTIFIER_LOCAL_VALUE (cname
))
925 dbuf
= build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname
)), 1, 1);
927 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
928 it's defined out of the class definition, since poplevel_class wipes
929 it out. This used to be internal error 346. */
930 dbuf
= build_overload_name (ctype
, 1, 1);
931 buf
= (char *) alloca (strlen (dbuf
) + sizeof (DESTRUCTOR_DECL_PREFIX
));
932 bcopy (DESTRUCTOR_DECL_PREFIX
, buf
, len
);
935 DECL_ASSEMBLER_NAME (function
) = get_identifier (buf
);
936 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
937 /* Mark the artificial `__in_chrg' parameter as "artificial". */
938 SET_DECL_ARTIFICIAL (parm
);
939 TREE_READONLY (parm
) = 1;
940 DECL_ARG_TYPE (parm
) = integer_type_node
;
941 /* This is the same chain as DECL_ARGUMENTS (...). */
942 TREE_CHAIN (last_function_parms
) = parm
;
944 fntype
= build_cplus_method_type (qualtype
, void_type_node
,
948 fntype
= build_exception_variant (fntype
, raises
);
950 TREE_TYPE (function
) = fntype
;
951 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
955 tree these_arg_types
;
957 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function
))
959 arg_types
= hash_tree_chain (integer_type_node
,
960 TREE_CHAIN (arg_types
));
961 fntype
= build_cplus_method_type (qualtype
,
962 TREE_TYPE (TREE_TYPE (function
)),
966 fntype
= build_exception_variant (fntype
, raises
);
968 TREE_TYPE (function
) = fntype
;
969 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
972 these_arg_types
= arg_types
;
974 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
975 /* Only true for static member functions. */
976 these_arg_types
= hash_tree_chain (build_pointer_type (qualtype
),
979 DECL_ASSEMBLER_NAME (function
)
980 = build_decl_overload (fn_name
, these_arg_types
,
981 1 + DECL_CONSTRUCTOR_P (function
));
984 /* This code is going into the compiler, but currently, it makes
985 libg++/src/Integer.cc not compile. The problem is that the nice name
986 winds up going into the symbol table, and conversion operations look
987 for the manged name. */
988 substitute_nice_name (function
);
992 DECL_ARGUMENTS (function
) = last_function_parms
;
993 /* First approximations. */
994 DECL_CONTEXT (function
) = ctype
;
995 DECL_CLASS_CONTEXT (function
) = ctype
;
998 /* Work on the expr used by alignof (this is only called by the parser). */
1006 if (TREE_CODE (expr
) == COMPONENT_REF
1007 && DECL_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1008 error ("`__alignof__' applied to a bit-field");
1010 if (TREE_CODE (expr
) == INDIRECT_REF
)
1012 best
= t
= TREE_OPERAND (expr
, 0);
1013 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1015 while (TREE_CODE (t
) == NOP_EXPR
1016 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1019 t
= TREE_OPERAND (t
, 0);
1020 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1021 if (thisalign
> bestalign
)
1022 best
= t
, bestalign
= thisalign
;
1024 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1028 /* ANSI says arrays and fns are converted inside comma.
1029 But we can't convert them in build_compound_expr
1030 because that would break commas in lvalues.
1031 So do the conversion here if operand was a comma. */
1032 if (TREE_CODE (expr
) == COMPOUND_EXPR
1033 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1034 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1035 expr
= default_conversion (expr
);
1036 return c_alignof (TREE_TYPE (expr
));
1040 /* Create an ARRAY_REF, checking for the user doing things backwards
1043 grok_array_decl (array_expr
, index_exp
)
1044 tree array_expr
, index_exp
;
1046 tree type
= TREE_TYPE (array_expr
);
1047 tree p1
, p2
, i1
, i2
;
1049 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1050 return error_mark_node
;
1051 if (current_template_parms
)
1052 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
1053 array_expr
, index_exp
);
1055 if (type
== NULL_TREE
)
1057 /* Something has gone very wrong. Assume we are mistakenly reducing
1058 an expression instead of a declaration. */
1059 error ("parser may be lost: is there a '{' missing somewhere?");
1063 if (TREE_CODE (type
) == OFFSET_TYPE
1064 || TREE_CODE (type
) == REFERENCE_TYPE
)
1065 type
= TREE_TYPE (type
);
1067 /* If they have an `operator[]', use that. */
1068 if (TYPE_LANG_SPECIFIC (type
)
1069 && TYPE_OVERLOADS_ARRAY_REF (complete_type (type
)))
1070 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1071 array_expr
, index_exp
, NULL_TREE
);
1073 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1075 if (TREE_CODE (type
) == ARRAY_TYPE
)
1078 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1080 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1083 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1085 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1086 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1088 if ((p1
&& i2
) && (i1
&& p2
))
1089 error ("ambiguous conversion for array subscript");
1092 array_expr
= p1
, index_exp
= i2
;
1094 array_expr
= p2
, index_exp
= i1
;
1097 cp_error ("invalid types `%T[%T]' for array subscript",
1098 type
, TREE_TYPE (index_exp
));
1099 return error_mark_node
;
1102 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1103 error ("ambiguous conversion for array subscript");
1105 return build_array_ref (array_expr
, index_exp
);
1108 /* Given the cast expression EXP, checking out its validity. Either return
1109 an error_mark_node if there was an unavoidable error, return a cast to
1110 void for trying to delete a pointer w/ the value 0, or return the
1111 call to delete. If DOING_VEC is 1, we handle things differently
1112 for doing an array delete. If DOING_VEC is 2, they gave us the
1113 array size as an argument to delete.
1114 Implements ARM $5.3.4. This is called from the parser. */
1116 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1118 int doing_vec
, use_global_delete
;
1122 enum tree_code code
;
1123 /* For a regular vector delete (aka, no size argument) we will pass
1124 this down as a NULL_TREE into build_vec_delete. */
1125 tree maxindex
= NULL_TREE
;
1127 if (exp
== error_mark_node
)
1130 if (current_template_parms
)
1132 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
1133 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
1134 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
1138 t
= stabilize_reference (convert_from_reference (exp
));
1139 type
= TREE_TYPE (t
);
1140 code
= TREE_CODE (type
);
1145 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1146 if (! flag_traditional
)
1147 pedwarn ("anachronistic use of array size in vector delete");
1152 if (code
!= POINTER_TYPE
)
1154 cp_error ("type `%#T' argument given to `delete', expected pointer",
1156 return error_mark_node
;
1159 /* Deleting a pointer with the value zero is valid and has no effect. */
1160 if (integer_zerop (t
))
1161 return build1 (NOP_EXPR
, void_type_node
, t
);
1164 if (code
== POINTER_TYPE
)
1167 /* As of Valley Forge, you can delete a pointer to constant. */
1168 /* You can't delete a pointer to constant. */
1169 if (TREE_READONLY (TREE_TYPE (type
)))
1171 error ("`const *' cannot be deleted");
1172 return error_mark_node
;
1175 /* You also can't delete functions. */
1176 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1178 error ("cannot delete a function");
1179 return error_mark_node
;
1184 /* If the type has no destructor, then we should build a regular
1185 delete, instead of a vector delete. Otherwise, we would end
1186 up passing a bogus offset into __builtin_delete, which is
1187 not expecting it. */
1189 && TREE_CODE (type
) == POINTER_TYPE
1190 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type
)))
1193 use_global_delete
= 1;
1198 return build_vec_delete (t
, maxindex
, integer_one_node
,
1199 integer_two_node
, use_global_delete
);
1202 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1203 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1205 /* Only do access checking here; we'll be calling op delete
1206 from the destructor. */
1207 tree tmp
= build_opfncall (DELETE_EXPR
, LOOKUP_NORMAL
, t
,
1208 size_zero_node
, NULL_TREE
);
1209 if (tmp
== error_mark_node
)
1210 return error_mark_node
;
1213 return build_delete (type
, t
, integer_three_node
,
1214 LOOKUP_NORMAL
|LOOKUP_HAS_IN_CHARGE
,
1219 /* Sanity check: report error if this function FUNCTION is not
1220 really a member of the class (CTYPE) it is supposed to belong to.
1221 CNAME is the same here as it is for grokclassfn above. */
1224 check_classfn (ctype
, function
)
1225 tree ctype
, function
;
1227 tree fn_name
= DECL_NAME (function
);
1229 tree method_vec
= CLASSTYPE_METHOD_VEC (complete_type (ctype
));
1233 if (method_vec
!= 0)
1235 methods
= &TREE_VEC_ELT (method_vec
, 0);
1236 end
= TREE_VEC_END (method_vec
);
1238 /* First suss out ctors and dtors. */
1239 if (*methods
&& fn_name
== DECL_NAME (*methods
)
1240 && DECL_CONSTRUCTOR_P (function
))
1242 if (*++methods
&& fn_name
== DECL_NAME (*methods
)
1243 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function
)))
1246 while (++methods
!= end
)
1248 if (fn_name
== DECL_NAME (*methods
))
1254 if (DECL_ASSEMBLER_NAME (function
) == DECL_ASSEMBLER_NAME (fndecl
))
1257 /* This doesn't work for static member functions that are
1258 pretending to be methods. */
1259 /* We have to do more extensive argument checking here, as
1260 the name may have been changed by asm("new_name"). */
1261 if (decls_match (function
, fndecl
))
1264 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1266 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1267 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1269 /* Get rid of the this parameter on functions that become
1271 if (DECL_STATIC_FUNCTION_P (fndecl
)
1272 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1273 p1
= TREE_CHAIN (p1
);
1275 if (comptypes (TREE_TYPE (TREE_TYPE (function
)),
1276 TREE_TYPE (TREE_TYPE (fndecl
)), 1)
1277 && compparms (p1
, p2
, 3))
1281 fndecl
= DECL_CHAIN (fndecl
);
1290 tree fndecl
= *methods
;
1291 cp_error ("prototype for `%#D' does not match any in class `%T'",
1293 cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl
) ? "s are" : " is",
1295 while (fndecl
= DECL_CHAIN (fndecl
), fndecl
)
1296 cp_error_at (" %#D", fndecl
);
1301 cp_error ("no `%#D' member function declared in class `%T'",
1305 /* If we did not find the method in the class, add it to avoid
1307 add_method (ctype
, methods
, function
);
1311 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1312 of a structure component, returning a FIELD_DECL node.
1313 QUALS is a list of type qualifiers for this decl (such as for declaring
1314 const member functions).
1316 This is done during the parsing of the struct declaration.
1317 The FIELD_DECL nodes are chained together and the lot of them
1318 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1322 If class A defines that certain functions in class B are friends, then
1323 the way I have set things up, it is B who is interested in permission
1324 granted by A. However, it is in A's context that these declarations
1325 are parsed. By returning a void_type_node, class A does not attempt
1326 to incorporate the declarations of the friends within its structure.
1328 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1329 CHANGES TO CODE IN `start_method'. */
1332 grokfield (declarator
, declspecs
, raises
, init
, asmspec_tree
, attrlist
)
1333 tree declarator
, declspecs
, raises
, init
, asmspec_tree
, attrlist
;
1335 register tree value
;
1337 int flags
= LOOKUP_ONLYCONVERTING
;
1339 /* Convert () initializers to = initializers. */
1340 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1341 && TREE_CODE (declarator
) == CALL_EXPR
1342 && TREE_OPERAND (declarator
, 0)
1343 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1344 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1345 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1347 init
= TREE_OPERAND (declarator
, 1);
1348 declarator
= TREE_OPERAND (declarator
, 0);
1352 if (declspecs
== NULL_TREE
1353 && TREE_CODE (declarator
) == SCOPE_REF
)
1355 /* Access declaration */
1356 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
1358 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
1359 pop_nested_class (1);
1360 return do_class_using_decl (declarator
);
1364 && TREE_CODE (init
) == TREE_LIST
1365 && TREE_VALUE (init
) == error_mark_node
1366 && TREE_CHAIN (init
) == NULL_TREE
)
1369 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0,
1372 return value
; /* friend or constructor went bad. */
1374 /* Pass friendly classes back. */
1375 if (TREE_CODE (value
) == VOID_TYPE
)
1376 return void_type_node
;
1378 if (DECL_NAME (value
) != NULL_TREE
1379 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1380 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1381 cp_error ("member `%D' conflicts with virtual function table field name", value
);
1383 /* Stash away type declarations. */
1384 if (TREE_CODE (value
) == TYPE_DECL
)
1386 DECL_NONLOCAL (value
) = 1;
1387 DECL_CONTEXT (value
) = current_class_type
;
1388 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1389 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
1391 pushdecl_class_level (value
);
1395 if (IS_SIGNATURE (current_class_type
)
1396 && TREE_CODE (value
) != FUNCTION_DECL
)
1398 error ("field declaration not allowed in signature");
1399 return void_type_node
;
1402 if (DECL_IN_AGGR_P (value
))
1404 cp_error ("`%D' is already defined in the class %T", value
,
1405 DECL_CONTEXT (value
));
1406 return void_type_node
;
1410 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1414 if (IS_SIGNATURE (current_class_type
)
1415 && TREE_CODE (value
) == FUNCTION_DECL
)
1417 error ("function declarations cannot have initializers in signature");
1420 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1422 grok_function_init (value
, init
);
1425 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1426 /* Already complained in grokdeclarator. */
1430 /* We allow initializers to become parameters to base
1432 if (TREE_CODE (init
) == TREE_LIST
)
1434 if (TREE_CHAIN (init
) == NULL_TREE
)
1435 init
= TREE_VALUE (init
);
1437 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1440 if (TREE_CODE (init
) == CONST_DECL
)
1441 init
= DECL_INITIAL (init
);
1442 else if (TREE_READONLY_DECL_P (init
))
1443 init
= decl_constant_value (init
);
1444 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1445 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1446 my_friendly_assert (TREE_PERMANENT (init
), 192);
1447 if (init
== error_mark_node
)
1448 /* We must make this look different than `error_mark_node'
1449 because `decl_const_value' would mis-interpret it
1450 as only meaning that this VAR_DECL is defined. */
1451 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1452 else if (current_template_parms
)
1454 else if (! TREE_CONSTANT (init
))
1456 /* We can allow references to things that are effectively
1457 static, since references are initialized with the address. */
1458 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1459 || (TREE_STATIC (init
) == 0
1460 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1461 || DECL_EXTERNAL (init
) == 0)))
1463 error ("field initializer is not constant");
1464 init
= error_mark_node
;
1470 /* The corresponding pop_obstacks is in cp_finish_decl. */
1471 push_obstacks_nochange ();
1473 if (current_template_parms
&& ! current_function_decl
1474 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1475 push_template_decl (value
);
1478 cplus_decl_attributes (value
, TREE_PURPOSE (attrlist
),
1479 TREE_VALUE (attrlist
));
1481 if (TREE_CODE (value
) == VAR_DECL
)
1483 /* We cannot call pushdecl here, because that would
1484 fill in the value of our TREE_CHAIN. Instead, we
1485 modify cp_finish_decl to do the right thing, namely, to
1486 put this decl out straight away. */
1487 if (TREE_PUBLIC (value
))
1489 /* current_class_type can be NULL_TREE in case of error. */
1490 if (asmspec
== 0 && current_class_type
)
1492 TREE_PUBLIC (value
) = 1;
1493 DECL_INITIAL (value
) = error_mark_node
;
1494 DECL_ASSEMBLER_NAME (value
)
1495 = build_static_name (current_class_type
, DECL_NAME (value
));
1497 if (! current_template_parms
)
1498 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1500 /* Static consts need not be initialized in the class definition. */
1501 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1503 static int explanation
= 0;
1505 error ("initializer invalid for static member with constructor");
1506 if (explanation
++ == 0)
1507 error ("(you really want to initialize it separately)");
1510 /* Force the compiler to know when an uninitialized static
1511 const member is being used. */
1512 if (TYPE_READONLY (value
) && init
== 0)
1513 TREE_USED (value
) = 1;
1515 DECL_INITIAL (value
) = init
;
1516 DECL_IN_AGGR_P (value
) = 1;
1517 DECL_CONTEXT (value
) = current_class_type
;
1518 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1520 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1521 pushdecl_class_level (value
);
1524 if (TREE_CODE (value
) == FIELD_DECL
)
1528 /* This must override the asm specifier which was placed
1529 by grokclassfn. Lay this out fresh. */
1530 DECL_RTL (value
) = NULL_RTX
;
1531 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1533 if (DECL_INITIAL (value
) == error_mark_node
)
1534 init
= error_mark_node
;
1535 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1536 DECL_INITIAL (value
) = init
;
1537 DECL_IN_AGGR_P (value
) = 1;
1540 if (TREE_CODE (value
) == FUNCTION_DECL
)
1542 check_default_args (value
);
1543 if (DECL_CHAIN (value
) != NULL_TREE
)
1545 /* Need a fresh node here so that we don't get circularity
1546 when we link these together. */
1547 value
= copy_node (value
);
1548 /* When does this happen? */
1549 my_friendly_assert (init
== NULL_TREE
, 193);
1553 /* This must override the asm specifier which was placed
1554 by grokclassfn. Lay this out fresh. */
1555 DECL_RTL (value
) = NULL_RTX
;
1556 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1558 cp_finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1560 /* Pass friends back this way. */
1561 if (DECL_FRIEND_P (value
))
1562 return void_type_node
;
1564 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1565 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1566 cp_error ("method `%#D' of local class must be defined in class body",
1570 DECL_IN_AGGR_P (value
) = 1;
1573 my_friendly_abort (21);
1578 /* Like `grokfield', but for bitfields.
1579 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1582 grokbitfield (declarator
, declspecs
, width
)
1583 tree declarator
, declspecs
, width
;
1585 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1586 0, NULL_TREE
, NULL_TREE
);
1588 if (! value
) return NULL_TREE
; /* friends went bad. */
1590 /* Pass friendly classes back. */
1591 if (TREE_CODE (value
) == VOID_TYPE
)
1592 return void_type_node
;
1594 if (TREE_CODE (value
) == TYPE_DECL
)
1596 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1600 if (IS_SIGNATURE (current_class_type
))
1602 error ("field declaration not allowed in signature");
1603 return void_type_node
;
1606 if (DECL_IN_AGGR_P (value
))
1608 cp_error ("`%D' is already defined in the class %T", value
,
1609 DECL_CONTEXT (value
));
1610 return void_type_node
;
1613 GNU_xref_member (current_class_name
, value
);
1615 if (TREE_STATIC (value
))
1617 cp_error ("static member `%D' cannot be a bitfield", value
);
1620 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1622 if (width
!= error_mark_node
)
1624 constant_expression_warning (width
);
1625 DECL_INITIAL (value
) = width
;
1626 DECL_BIT_FIELD (value
) = 1;
1629 DECL_IN_AGGR_P (value
) = 1;
1634 /* Like GROKFIELD, except that the declarator has been
1635 buried in DECLSPECS. Find the declarator, and
1636 return something that looks like it came from
1639 groktypefield (declspecs
, parmlist
)
1643 tree spec
= declspecs
;
1644 tree prev
= NULL_TREE
;
1646 tree type_id
= NULL_TREE
;
1647 tree quals
= NULL_TREE
;
1648 tree lengths
= NULL_TREE
;
1649 tree decl
= NULL_TREE
;
1653 register tree id
= TREE_VALUE (spec
);
1655 if (TREE_CODE (spec
) != TREE_LIST
)
1656 /* Certain parse errors slip through. For example,
1657 `int class ();' is not caught by the parser. Try
1658 weakly to recover here. */
1661 if (TREE_CODE (id
) == TYPE_DECL
1662 || (TREE_CODE (id
) == IDENTIFIER_NODE
&& TREE_TYPE (id
)))
1664 /* We have a constructor/destructor or
1665 conversion operator. Use it. */
1667 TREE_CHAIN (prev
) = TREE_CHAIN (spec
);
1669 declspecs
= TREE_CHAIN (spec
);
1675 spec
= TREE_CHAIN (spec
);
1678 /* Nope, we have a conversion operator to a scalar type or something
1679 else, that includes things like constructor declarations for
1684 tree id
= TREE_VALUE (spec
);
1686 if (TREE_CODE (id
) == IDENTIFIER_NODE
)
1688 if (id
== ridpointers
[(int)RID_INT
]
1689 || id
== ridpointers
[(int)RID_DOUBLE
]
1690 || id
== ridpointers
[(int)RID_FLOAT
]
1691 || id
== ridpointers
[(int)RID_WCHAR
])
1694 error ("extra `%s' ignored",
1695 IDENTIFIER_POINTER (id
));
1699 else if (id
== ridpointers
[(int)RID_LONG
]
1700 || id
== ridpointers
[(int)RID_SHORT
]
1701 || id
== ridpointers
[(int)RID_CHAR
])
1703 lengths
= tree_cons (NULL_TREE
, id
, lengths
);
1705 else if (id
== ridpointers
[(int)RID_VOID
])
1708 error ("spurious `void' type ignored");
1710 error ("conversion to `void' type invalid");
1712 else if (id
== ridpointers
[(int)RID_AUTO
]
1713 || id
== ridpointers
[(int)RID_REGISTER
]
1714 || id
== ridpointers
[(int)RID_TYPEDEF
]
1715 || id
== ridpointers
[(int)RID_CONST
]
1716 || id
== ridpointers
[(int)RID_VOLATILE
])
1718 error ("type specifier `%s' used invalidly",
1719 IDENTIFIER_POINTER (id
));
1721 else if (id
== ridpointers
[(int)RID_FRIEND
]
1722 || id
== ridpointers
[(int)RID_VIRTUAL
]
1723 || id
== ridpointers
[(int)RID_INLINE
]
1724 || id
== ridpointers
[(int)RID_UNSIGNED
]
1725 || id
== ridpointers
[(int)RID_SIGNED
]
1726 || id
== ridpointers
[(int)RID_STATIC
]
1727 || id
== ridpointers
[(int)RID_EXTERN
])
1729 quals
= tree_cons (NULL_TREE
, id
, quals
);
1733 /* Happens when we have a global typedef
1734 and a class-local member function with
1740 else if (TREE_CODE (id
) == RECORD_TYPE
)
1742 type_id
= TYPE_NAME (id
);
1743 if (TREE_CODE (type_id
) == TYPE_DECL
)
1744 type_id
= DECL_NAME (type_id
);
1745 if (type_id
== NULL_TREE
)
1746 error ("identifier for aggregate type conversion omitted");
1748 else if (TREE_CODE_CLASS (TREE_CODE (id
)) == 't')
1749 error ("`operator' missing on conversion operator or tag missing from type");
1751 my_friendly_abort (194);
1752 spec
= TREE_CHAIN (spec
);
1756 declspecs
= chainon (lengths
, quals
);
1759 if (TREE_CHAIN (lengths
))
1760 error ("multiple length specifiers");
1761 type_id
= ridpointers
[(int)RID_INT
];
1762 declspecs
= chainon (lengths
, quals
);
1766 error ("no type given, defaulting to `operator int ...'");
1767 type_id
= ridpointers
[(int)RID_INT
];
1774 decl
= grokdeclarator (build_parse_node (CALL_EXPR
, type_id
, parmlist
, NULL_TREE
),
1775 declspecs
, FIELD
, 0, NULL_TREE
, NULL_TREE
);
1776 if (decl
== NULL_TREE
)
1779 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CHAIN (decl
) != NULL_TREE
)
1781 /* Need a fresh node here so that we don't get circularity
1782 when we link these together. */
1783 decl
= copy_node (decl
);
1786 if (decl
== void_type_node
1787 || (TREE_CODE (decl
) == FUNCTION_DECL
1788 && TREE_CODE (TREE_TYPE (decl
)) != METHOD_TYPE
))
1789 /* bunch of friends. */
1792 if (DECL_IN_AGGR_P (decl
))
1794 cp_error ("`%D' already defined in the class ", decl
);
1795 return void_type_node
;
1798 cp_finish_decl (decl
, NULL_TREE
, NULL_TREE
, 0, 0);
1800 /* If this declaration is common to another declaration
1801 complain about such redundancy, and return NULL_TREE
1802 so that we don't build a circular list. */
1803 if (DECL_CHAIN (decl
))
1805 cp_error ("function `%D' declared twice in class %T", decl
,
1806 DECL_CONTEXT (decl
));
1809 DECL_IN_AGGR_P (decl
) = 1;
1815 grokoptypename (declspecs
, declarator
)
1816 tree declspecs
, declarator
;
1818 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0,
1819 NULL_TREE
, NULL_TREE
);
1820 return build_typename_overload (t
);
1823 /* When a function is declared with an initializer,
1824 do the right thing. Currently, there are two possibilities:
1829 // initialization possibility #1.
1830 virtual void f () = 0;
1852 // initialization possibility #2
1859 copy_assignment_arg_p (parmtype
, virtualp
)
1863 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1864 parmtype
= TREE_TYPE (parmtype
);
1866 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1867 || (virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
)))
1874 grok_function_init (decl
, init
)
1878 /* An initializer for a function tells how this function should
1880 tree type
= TREE_TYPE (decl
);
1882 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1883 cp_error ("initializer specified for non-member function `%D'", decl
);
1885 /* We'll check for this in finish_struct_1. */
1886 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1887 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1889 else if (integer_zerop (init
))
1892 /* Mark this function as being "defined". */
1893 DECL_INITIAL (decl
) = error_mark_node
;
1894 /* pure virtual destructors must be defined. */
1895 /* pure virtual needs to be defined (as abort) only when put in
1896 vtbl. For wellformed call, it should be itself. pr4737 */
1897 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1899 extern tree abort_fndecl
;
1900 /* Give this node rtl from `abort'. */
1901 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1904 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1905 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1908 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1910 if (copy_assignment_arg_p (parmtype
, 1))
1911 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1914 else if (TREE_CODE (init
) == OFFSET_REF
1915 && TREE_OPERAND (init
, 0) == NULL_TREE
1916 && TREE_CODE (TREE_TYPE (init
)) == METHOD_TYPE
)
1918 tree basetype
= DECL_CLASS_CONTEXT (init
);
1919 tree basefn
= TREE_OPERAND (init
, 1);
1920 if (TREE_CODE (basefn
) != FUNCTION_DECL
)
1921 cp_error ("non-method initializer invalid for method `%D'", decl
);
1922 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn
))))
1923 sorry ("base member function from other than first base class");
1926 tree binfo
= get_binfo (basetype
, TYPE_METHOD_BASETYPE (type
), 1);
1927 if (binfo
== error_mark_node
)
1929 else if (binfo
== 0)
1930 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init
)),
1931 TYPE_METHOD_BASETYPE (type
));
1934 /* Mark this function as being defined,
1935 and give it new rtl. */
1936 DECL_INITIAL (decl
) = error_mark_node
;
1937 DECL_RTL (decl
) = DECL_RTL (basefn
);
1942 cp_error ("invalid initializer for virtual method `%D'", decl
);
1946 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1947 tree decl
, attributes
, prefix_attributes
;
1949 if (decl
== NULL_TREE
|| decl
== void_type_node
)
1952 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1953 decl
= DECL_TEMPLATE_RESULT (decl
);
1955 decl_attributes (decl
, attributes
, prefix_attributes
);
1957 if (TREE_CODE (decl
) == TYPE_DECL
)
1958 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
1961 /* CONSTRUCTOR_NAME:
1962 Return the name for the constructor (or destructor) for the
1963 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1964 IDENTIFIER_NODE. When given a template, this routine doesn't
1965 lose the specialization. */
1967 constructor_name_full (thing
)
1970 if (TREE_CODE (thing
) == TEMPLATE_TYPE_PARM
)
1971 thing
= TYPE_NAME (thing
);
1972 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
1974 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
1975 thing
= DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing
), 0));
1977 thing
= TYPE_NAME (thing
);
1979 if (TREE_CODE (thing
) == TYPE_DECL
1980 || (TREE_CODE (thing
) == TEMPLATE_DECL
1981 && TREE_CODE (DECL_TEMPLATE_RESULT (thing
)) == TYPE_DECL
))
1982 thing
= DECL_NAME (thing
);
1983 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
1987 /* CONSTRUCTOR_NAME:
1988 Return the name for the constructor (or destructor) for the
1989 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1990 IDENTIFIER_NODE. When given a template, return the plain
1991 unspecialized name. */
1993 constructor_name (thing
)
1997 thing
= constructor_name_full (thing
);
1998 t
= IDENTIFIER_TEMPLATE (thing
);
2004 /* Cache the value of this class's main virtual function table pointer
2005 in a register variable. This will save one indirection if a
2006 more than one virtual function call is made this function. */
2010 extern tree base_init_expr
;
2012 if (base_init_expr
== 0
2013 && DECL_CONSTRUCTOR_P (current_function_decl
))
2015 if (current_template_parms
)
2016 add_tree (build_min_nt
2018 current_member_init_list
, current_base_init_list
));
2020 emit_base_init (current_class_type
, 0);
2024 /* Record the existence of an addressable inline function. */
2026 mark_inline_for_output (decl
)
2029 decl
= DECL_MAIN_VARIANT (decl
);
2030 if (DECL_SAVED_INLINE (decl
))
2032 my_friendly_assert (TREE_PERMANENT (decl
), 363);
2033 DECL_SAVED_INLINE (decl
) = 1;
2035 if (DECL_PENDING_INLINE_INFO (decl
) != 0
2036 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
2038 struct pending_inline
*t
= pending_inlines
;
2039 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
2042 if (t
== DECL_PENDING_INLINE_INFO (decl
))
2048 t
= DECL_PENDING_INLINE_INFO (decl
);
2049 t
->next
= pending_inlines
;
2050 pending_inlines
= t
;
2052 DECL_PENDING_INLINE_INFO (decl
) = 0;
2055 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
2061 temp_name_counter
= 0;
2064 /* Hand off a unique name which can be used for variable we don't really
2065 want to know about anyway, for example, the anonymous variables which
2066 are needed to make references work. Declare this thing so we can use it.
2067 The variable created will be of type TYPE.
2069 STATICP is nonzero if this variable should be static. */
2072 get_temp_name (type
, staticp
)
2076 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2078 int toplev
= toplevel_bindings_p ();
2080 push_obstacks_nochange ();
2081 if (toplev
|| staticp
)
2083 end_temporary_allocation ();
2084 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2085 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2089 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2090 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2092 TREE_USED (decl
) = 1;
2093 TREE_STATIC (decl
) = staticp
;
2094 DECL_ARTIFICIAL (decl
) = 1;
2096 /* If this is a local variable, then lay out its rtl now.
2097 Otherwise, callers of this function are responsible for dealing
2098 with this variable's rtl. */
2102 expand_decl_init (decl
);
2109 /* Get a variable which we can use for multiple assignments.
2110 It is not entered into current_binding_level, because
2111 that breaks things when it comes time to do final cleanups
2112 (which take place "outside" the binding contour of the function). */
2114 get_temp_regvar (type
, init
)
2117 static char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20] = { '_' };
2120 sprintf (buf
+1, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2121 decl
= build_decl (VAR_DECL
, get_identifier (buf
), type
);
2122 TREE_USED (decl
) = 1;
2123 DECL_REGISTER (decl
) = 1;
2126 store_init_value (decl
, init
);
2128 /* We can expand these without fear, since they cannot need
2129 constructors or destructors. */
2131 expand_decl_init (decl
);
2136 /* Make the macro TEMP_NAME_P available to units which do not
2137 include c-tree.h. */
2142 return TEMP_NAME_P (decl
);
2145 /* Finish off the processing of a UNION_TYPE structure.
2146 If there are static members, then all members are
2147 static, and must be laid out together. If the
2148 union is an anonymous union, we arrange for that
2149 as well. PUBLIC_P is nonzero if this union is
2150 not declared static. */
2152 finish_anon_union (anon_union_decl
)
2153 tree anon_union_decl
;
2155 tree type
= TREE_TYPE (anon_union_decl
);
2156 tree field
, main_decl
= NULL_TREE
;
2157 tree elems
= NULL_TREE
;
2158 int public_p
= TREE_PUBLIC (anon_union_decl
);
2159 int static_p
= TREE_STATIC (anon_union_decl
);
2160 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2162 if ((field
= TYPE_FIELDS (type
)) == NULL_TREE
)
2167 error ("global anonymous unions must be declared static");
2171 for (; field
; field
= TREE_CHAIN (field
))
2174 if (TREE_CODE (field
) != FIELD_DECL
)
2177 if (TREE_PRIVATE (field
))
2178 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
2179 else if (TREE_PROTECTED (field
))
2180 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
2182 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2183 /* tell `pushdecl' that this is not tentative. */
2184 DECL_INITIAL (decl
) = error_mark_node
;
2185 TREE_PUBLIC (decl
) = public_p
;
2186 TREE_STATIC (decl
) = static_p
;
2187 DECL_EXTERNAL (decl
) = external_p
;
2188 decl
= pushdecl (decl
);
2190 /* Only write out one anon union element--choose the one that
2191 can hold them all. */
2192 if (main_decl
== NULL_TREE
2193 && 1 == simple_cst_equal (DECL_SIZE (decl
),
2194 DECL_SIZE (anon_union_decl
)))
2200 /* ??? This causes there to be no debug info written out
2202 TREE_ASM_WRITTEN (decl
) = 1;
2205 DECL_INITIAL (decl
) = NULL_TREE
;
2206 /* If there's a cleanup to do, it belongs in the
2207 TREE_PURPOSE of the following TREE_LIST. */
2208 elems
= tree_cons (NULL_TREE
, decl
, elems
);
2209 TREE_TYPE (elems
) = type
;
2215 make_decl_rtl (main_decl
, 0, toplevel_bindings_p ());
2216 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2220 warning ("anonymous union with no members");
2225 /* The following call assumes that there are never any cleanups
2226 for anonymous unions--a reasonable assumption. */
2227 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2230 /* Finish and output a table which is generated by the compiler.
2231 NAME is the name to give the table.
2232 TYPE is the type of the table entry.
2233 INIT is all the elements in the table.
2234 PUBLICP is non-zero if this table should be given external access. */
2236 finish_table (name
, type
, init
, publicp
)
2237 tree name
, type
, init
;
2240 tree itype
, atype
, decl
;
2241 static tree empty_table
;
2245 itype
= build_index_type (size_int (list_length (init
) - 1));
2246 atype
= build_cplus_array_type (type
, itype
);
2247 layout_type (atype
);
2249 if (TREE_VALUE (init
) == integer_zero_node
2250 && TREE_CHAIN (init
) == NULL_TREE
)
2253 if (empty_table
== NULL_TREE
)
2256 empty_table
= get_temp_name (atype
, 1);
2257 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2258 TREE_CONSTANT (init
) = 1;
2259 TREE_STATIC (init
) = 1;
2260 DECL_INITIAL (empty_table
) = init
;
2261 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2262 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2263 cp_finish_decl (empty_table
, NULL_TREE
, asmspec
, 0, 0);
2268 if (name
== NULL_TREE
)
2272 decl
= get_temp_name (atype
, 1);
2276 decl
= build_decl (VAR_DECL
, name
, atype
);
2277 decl
= pushdecl (decl
);
2278 TREE_STATIC (decl
) = 1;
2283 TREE_PUBLIC (decl
) = publicp
;
2284 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2285 TREE_CONSTANT (init
) = 1;
2286 TREE_STATIC (init
) = 1;
2287 DECL_INITIAL (decl
) = init
;
2288 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (decl
)),
2289 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2293 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2294 DECL_EXTERNAL (decl
) = 1;
2295 TREE_STATIC (decl
) = 0;
2297 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2298 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2301 cp_finish_decl (decl
, NULL_TREE
, asmspec
, 0, 0);
2305 /* Finish processing a builtin type TYPE. It's name is NAME,
2306 its fields are in the array FIELDS. LEN is the number of elements
2307 in FIELDS minus one, or put another way, it is the maximum subscript
2310 It is given the same alignment as ALIGN_TYPE. */
2312 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2321 TYPE_FIELDS (type
) = fields
[0];
2322 for (i
= 0; i
< len
; i
++)
2324 layout_type (TREE_TYPE (fields
[i
]));
2325 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2326 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2328 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2329 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2330 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2332 #if 0 /* not yet, should get fixed properly later */
2333 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2335 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2337 layout_decl (TYPE_NAME (type
), 0);
2340 /* Auxiliary functions to make type signatures for
2341 `operator new' and `operator delete' correspond to
2342 what compiler will be expecting. */
2344 extern tree sizetype
;
2347 coerce_new_type (type
)
2352 if (TREE_CODE (type
) == METHOD_TYPE
)
2353 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2354 if (TREE_TYPE (type
) != ptr_type_node
)
2355 e1
= 1, error ("`operator new' must return type `void *'");
2357 /* Technically the type must be `size_t', but we may not know
2359 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2360 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2361 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type
))) != INTEGER_TYPE
2362 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type
))) != TYPE_PRECISION (sizetype
))
2363 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2365 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2367 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2372 coerce_delete_type (type
)
2375 int e1
= 0, e2
= 0, e3
= 0;
2376 tree arg_types
= TYPE_ARG_TYPES (type
);
2378 if (TREE_CODE (type
) == METHOD_TYPE
)
2380 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2381 arg_types
= TREE_CHAIN (arg_types
);
2383 if (TREE_TYPE (type
) != void_type_node
)
2384 e1
= 1, error ("`operator delete' must return type `void'");
2385 if (arg_types
== NULL_TREE
2386 || TREE_VALUE (arg_types
) != ptr_type_node
)
2387 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2390 && TREE_CHAIN (arg_types
)
2391 && TREE_CHAIN (arg_types
) != void_list_node
)
2393 /* Again, technically this argument must be `size_t', but again
2394 we may not know what that is. */
2395 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2396 if (TREE_CODE (t2
) != INTEGER_TYPE
2397 || TYPE_PRECISION (t2
) != TYPE_PRECISION (sizetype
))
2398 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2399 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2402 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2403 error ("too many arguments in declaration of `operator delete'");
2405 error ("`...' invalid in specification of `operator delete'");
2409 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, build_tree_list (NULL_TREE
, sizetype
));
2412 if (arg_types
== NULL_TREE
)
2413 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2415 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2420 type
= build_function_type (void_type_node
, arg_types
);
2425 extern tree abort_fndecl
;
2428 mark_vtable_entries (decl
)
2431 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
2435 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (TREE_CHAIN (entries
))
2436 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2437 tree fn
= TREE_OPERAND (fnaddr
, 0);
2438 TREE_ADDRESSABLE (fn
) = 1;
2441 skip_rtti_stuff (&entries
);
2443 for (; entries
; entries
= TREE_CHAIN (entries
))
2445 tree fnaddr
= (flag_vtable_thunks
? TREE_VALUE (entries
)
2446 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2447 tree fn
= TREE_OPERAND (fnaddr
, 0);
2448 TREE_ADDRESSABLE (fn
) = 1;
2449 if (DECL_LANG_SPECIFIC (fn
) && DECL_ABSTRACT_VIRTUAL_P (fn
))
2450 TREE_OPERAND (fnaddr
, 0) = fn
= abort_fndecl
;
2455 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2456 based on TYPE and other static flags.
2458 Note that anything public is tagged TREE_PUBLIC, whether
2459 it's public in this file or in another one. */
2462 import_export_vtable (decl
, type
, final
)
2466 if (DECL_INTERFACE_KNOWN (decl
))
2470 if (write_virtuals
< 2 && write_virtuals
!= 0)
2472 TREE_PUBLIC (decl
) = 1;
2473 if (write_virtuals
< 0)
2474 DECL_EXTERNAL (decl
) = 1;
2475 DECL_INTERFACE_KNOWN (decl
) = 1;
2477 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2479 TREE_PUBLIC (decl
) = 1;
2480 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2481 DECL_INTERFACE_KNOWN (decl
) = 1;
2485 /* We can only wait to decide if we have real non-inline virtual
2486 functions in our class, or if we come from a template. */
2488 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2490 if (! found
&& ! final
)
2493 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
2494 method
= TREE_CHAIN (method
))
2495 if (DECL_VINDEX (method
) != NULL_TREE
2496 && ! DECL_THIS_INLINE (method
)
2497 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2504 if (final
|| ! found
)
2506 #ifdef ASSEMBLE_EXTERNAL
2507 if (TREE_PUBLIC (decl
))
2508 cp_error ("all virtual functions redeclared inline");
2512 TREE_PUBLIC (decl
) = 1;
2513 DECL_WEAK (decl
) = 1;
2516 TREE_PUBLIC (decl
) = 0;
2517 DECL_EXTERNAL (decl
) = 0;
2521 TREE_PUBLIC (decl
) = 1;
2522 DECL_EXTERNAL (decl
) = 1;
2528 import_export_template (type
)
2531 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type
)
2532 && ! flag_implicit_templates
2533 && CLASSTYPE_INTERFACE_UNKNOWN (type
))
2535 SET_CLASSTYPE_INTERFACE_KNOWN (type
);
2536 CLASSTYPE_INTERFACE_ONLY (type
) = 1;
2537 CLASSTYPE_VTABLE_NEEDS_WRITING (type
) = 0;
2542 finish_prevtable_vardecl (prev
, vars
)
2545 tree ctype
= DECL_CONTEXT (vars
);
2546 import_export_template (ctype
);
2548 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype
) && TYPE_VIRTUAL_P (ctype
)
2549 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2552 for (method
= TYPE_METHODS (ctype
); method
!= NULL_TREE
;
2553 method
= TREE_CHAIN (method
))
2555 if (DECL_VINDEX (method
) != NULL_TREE
2556 && !DECL_THIS_INLINE (method
)
2557 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2559 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2560 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
) = ! DECL_EXTERNAL (method
);
2561 CLASSTYPE_INTERFACE_ONLY (ctype
) = DECL_EXTERNAL (method
);
2562 #ifdef ADJUST_VTABLE_LINKAGE
2563 ADJUST_VTABLE_LINKAGE (vars
, method
);
2570 import_export_vtable (vars
, ctype
, 1);
2575 finish_vtable_vardecl (prev
, vars
)
2578 if (write_virtuals
>= 0
2579 && ! DECL_EXTERNAL (vars
) && (TREE_PUBLIC (vars
) || TREE_USED (vars
))
2580 && ! TREE_ASM_WRITTEN (vars
))
2583 mark_vtable_entries (vars
);
2584 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2585 store_init_value (vars
, DECL_INITIAL (vars
));
2587 #ifdef DWARF_DEBUGGING_INFO
2588 if (write_symbols
== DWARF_DEBUG
)
2590 /* Mark the VAR_DECL node representing the vtable itself as a
2591 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2592 It is rather important that such things be ignored because
2593 any effort to actually generate DWARF for them will run
2594 into trouble when/if we encounter code like:
2597 struct S { virtual void member (); };
2599 because the artificial declaration of the vtable itself (as
2600 manufactured by the g++ front end) will say that the vtable
2601 is a static member of `S' but only *after* the debug output
2602 for the definition of `S' has already been output. This causes
2603 grief because the DWARF entry for the definition of the vtable
2604 will try to refer back to an earlier *declaration* of the
2605 vtable as a static member of `S' and there won't be one.
2606 We might be able to arrange to have the "vtable static member"
2607 attached to the member list for `S' before the debug info for
2608 `S' get written (which would solve the problem) but that would
2609 require more intrusive changes to the g++ front end. */
2611 DECL_IGNORED_P (vars
) = 1;
2613 #endif /* DWARF_DEBUGGING_INFO */
2615 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2618 else if (! TREE_USED (vars
))
2619 /* We don't know what to do with this one yet. */
2622 /* We know that PREV must be non-zero here. */
2623 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2628 prune_vtable_vardecl (prev
, vars
)
2631 /* We know that PREV must be non-zero here. */
2632 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2637 walk_vtables (typedecl_fn
, vardecl_fn
)
2638 register void (*typedecl_fn
)();
2639 register int (*vardecl_fn
)();
2644 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2646 register tree type
= TREE_TYPE (vars
);
2648 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2651 flag
|= (*vardecl_fn
) (prev
, vars
);
2653 if (prev
&& TREE_CHAIN (prev
) != vars
)
2656 else if (TREE_CODE (vars
) == TYPE_DECL
2657 && type
!= error_mark_node
2658 && TYPE_LANG_SPECIFIC (type
)
2659 && CLASSTYPE_VSIZE (type
))
2661 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2671 finish_sigtable_vardecl (prev
, vars
)
2674 /* We don't need to mark sigtable entries as addressable here as is done
2675 for vtables. Since sigtables, unlike vtables, are always written out,
2676 that was already done in build_signature_table_constructor. */
2678 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2680 /* We know that PREV must be non-zero here. */
2681 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2685 walk_sigtables (typedecl_fn
, vardecl_fn
)
2686 register void (*typedecl_fn
)();
2687 register void (*vardecl_fn
)();
2691 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2693 register tree type
= TREE_TYPE (vars
);
2695 if (TREE_CODE (vars
) == TYPE_DECL
2696 && type
!= error_mark_node
2697 && IS_SIGNATURE (type
))
2699 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2701 else if (TREE_CODE (vars
) == VAR_DECL
2702 && TREE_TYPE (vars
) != error_mark_node
2703 && IS_SIGNATURE (TREE_TYPE (vars
)))
2705 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2712 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2713 inline function or template instantiation at end-of-file. */
2716 import_export_decl (decl
)
2719 if (DECL_INTERFACE_KNOWN (decl
))
2722 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2724 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2725 if (DECL_IMPLICIT_INSTANTIATION (decl
) && flag_implicit_templates
)
2727 /* For now, leave vars public so multiple defs will break. */
2728 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2731 DECL_WEAK (decl
) = 1;
2733 TREE_PUBLIC (decl
) = 0;
2737 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2739 else if (DECL_FUNCTION_MEMBER_P (decl
))
2741 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2742 if (CLASSTYPE_INTERFACE_KNOWN (ctype
) && ! DECL_ARTIFICIAL (decl
))
2744 DECL_NOT_REALLY_EXTERN (decl
)
2745 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2746 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2749 DECL_WEAK (decl
) = 1;
2751 TREE_PUBLIC (decl
) = 0;
2753 /* tinfo function */
2754 else if (DECL_ARTIFICIAL (decl
) && DECL_MUTABLE_P (decl
))
2756 tree ctype
= TREE_TYPE (DECL_NAME (decl
));
2757 if (IS_AGGR_TYPE (ctype
) && CLASSTYPE_INTERFACE_KNOWN (ctype
))
2759 DECL_NOT_REALLY_EXTERN (decl
)
2760 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2761 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2763 else if (TYPE_BUILT_IN (ctype
) && ctype
== TYPE_MAIN_VARIANT (ctype
))
2764 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2766 DECL_WEAK (decl
) = 1;
2768 TREE_PUBLIC (decl
) = 0;
2770 else if (DECL_C_STATIC (decl
))
2771 TREE_PUBLIC (decl
) = 0;
2773 DECL_WEAK (decl
) = 1;
2775 TREE_PUBLIC (decl
) = 0;
2777 DECL_INTERFACE_KNOWN (decl
) = 1;
2781 build_cleanup (decl
)
2785 tree type
= TREE_TYPE (decl
);
2787 if (TREE_CODE (type
) == ARRAY_TYPE
)
2791 mark_addressable (decl
);
2792 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
2794 temp
= build_delete (TREE_TYPE (temp
), temp
,
2796 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2800 extern int parse_time
, varconst_time
;
2801 extern tree pending_templates
;
2803 #define TIMEVAR(VAR, BODY) \
2804 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2806 /* This routine is called from the last rule in yyparse ().
2807 Its job is to create all the code needed to initialize and
2808 destroy the global aggregates. We do the destruction
2809 first, since that way we only need to reverse the decls once. */
2815 int start_time
, this_time
;
2819 int needs_cleaning
= 0, needs_messing_up
= 0;
2823 if (flag_detailed_statistics
)
2824 dump_tree_statistics ();
2826 /* Bad parse errors. Just forget about it. */
2827 if (! global_bindings_p () || current_class_type
)
2830 start_time
= get_run_time ();
2832 /* Otherwise, GDB can get confused, because in only knows
2833 about source for LINENO-1 lines. */
2836 interface_unknown
= 1;
2839 for (fnname
= pending_templates
; fnname
; fnname
= TREE_CHAIN (fnname
))
2841 tree decl
= TREE_VALUE (fnname
);
2842 instantiate_decl (decl
);
2845 /* Push into C language context, because that's all
2847 push_lang_context (lang_name_c
);
2850 /* The reason for pushing garbage onto the global_binding_level is to
2851 ensure that we can slice out _DECLs which pertain to virtual function
2852 tables. If the last thing pushed onto the global_binding_level was a
2853 virtual function table, then slicing it out would slice away all the
2854 decls (i.e., we lose the head of the chain).
2856 There are several ways of getting the same effect, from changing the
2857 way that iterators over the chain treat the elements that pertain to
2858 virtual function tables, moving the implementation of this code to
2859 decl.c (where we can manipulate global_binding_level directly),
2860 popping the garbage after pushing it and slicing away the vtable
2861 stuff, or just leaving it alone. */
2863 /* Make last thing in global scope not be a virtual function table. */
2864 #if 0 /* not yet, should get fixed properly later */
2865 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
2867 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
2869 DECL_IGNORED_P (vars
) = 1;
2870 SET_DECL_ARTIFICIAL (vars
);
2874 /* Walk to mark the inline functions we need, then output them so
2875 that we can pick up any other tdecls that those routines need. */
2876 walk_vtables ((void (*)())0, finish_prevtable_vardecl
);
2878 vars
= static_aggregates
;
2880 if (static_ctors
|| vars
|| might_have_exceptions_p ())
2881 needs_messing_up
= 1;
2885 /* See if we really need the hassle. */
2886 while (vars
&& needs_cleaning
== 0)
2888 tree decl
= TREE_VALUE (vars
);
2889 tree type
= TREE_TYPE (decl
);
2890 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
))
2896 vars
= TREE_CHAIN (vars
);
2899 if (needs_cleaning
== 0)
2902 fnname
= get_file_function_name ('D');
2903 start_function (void_list_node
,
2904 build_parse_node (CALL_EXPR
, fnname
, void_list_node
,
2906 NULL_TREE
, NULL_TREE
, 0);
2907 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2908 store_parm_decls ();
2913 expand_start_bindings (0);
2915 /* These must be done in backward order to destroy,
2916 in which they happen to be! */
2917 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
2919 tree decl
= TREE_VALUE (vars
);
2920 tree type
= TREE_TYPE (decl
);
2921 tree temp
= TREE_PURPOSE (vars
);
2923 if (TYPE_NEEDS_DESTRUCTOR (type
) && ! TREE_STATIC (vars
))
2925 temp
= build_cleanup (decl
);
2926 expand_expr_stmt (temp
);
2930 for (; static_dtors
; static_dtors
= TREE_CHAIN (static_dtors
))
2931 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors
),
2934 expand_end_bindings (getdecls (), 1, 0);
2938 finish_function (lineno
, 0, 0);
2940 assemble_destructor (IDENTIFIER_POINTER (fnname
));
2942 /* if it needed cleaning, then it will need messing up: drop through */
2945 /* Must do this while we think we are at the top level. */
2946 vars
= nreverse (static_aggregates
);
2947 if (needs_messing_up
)
2949 fnname
= get_file_function_name ('I');
2950 start_function (void_list_node
,
2951 build_parse_node (CALL_EXPR
, fnname
,
2952 void_list_node
, NULL_TREE
),
2953 NULL_TREE
, NULL_TREE
, 0);
2954 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2955 store_parm_decls ();
2960 expand_start_bindings (0);
2962 if (might_have_exceptions_p ())
2963 register_exception_table ();
2967 extern int temp_slot_level
;
2968 extern int target_temp_slot_level
;
2969 tree decl
= TREE_VALUE (vars
);
2970 tree init
= TREE_PURPOSE (vars
);
2971 tree old_cleanups
= cleanups_this_call
;
2972 int old_temp_level
= target_temp_slot_level
;
2975 target_temp_slot_level
= temp_slot_level
;
2977 /* If this was a static attribute within some function's scope,
2978 then don't initialize it here. Also, don't bother
2979 with initializers that contain errors. */
2980 if (TREE_STATIC (vars
)
2981 || (init
&& TREE_CODE (init
) == TREE_LIST
2982 && value_member (error_mark_node
, init
)))
2984 vars
= TREE_CHAIN (vars
);
2988 if (TREE_CODE (decl
) == VAR_DECL
)
2990 /* Set these global variables so that GDB at least puts
2991 us near the declaration which required the initialization. */
2992 input_filename
= DECL_SOURCE_FILE (decl
);
2993 lineno
= DECL_SOURCE_LINE (decl
);
2994 emit_note (input_filename
, lineno
);
2996 /* 9.5p5: The initializer of a static member of a class has
2997 the same access rights as a member function. */
2998 DECL_CLASS_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
2999 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3001 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3002 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3003 expand_aggr_init (decl
, init
, 0, 0);
3004 else if (TREE_CODE (init
) == TREE_VEC
)
3006 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3007 TREE_VEC_ELT (init
, 1),
3008 TREE_VEC_ELT (init
, 2), 0),
3009 const0_rtx
, VOIDmode
, 0);
3012 expand_assignment (decl
, init
, 0, 0);
3014 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3015 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3017 else if (TREE_CODE (decl
) == SAVE_EXPR
)
3019 if (! PARM_DECL_EXPR (decl
))
3021 /* a `new' expression at top level. */
3022 expand_expr (decl
, const0_rtx
, VOIDmode
, 0);
3023 if (TREE_CODE (init
) == TREE_VEC
)
3025 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3026 TREE_VEC_ELT (init
, 1),
3027 TREE_VEC_ELT (init
, 2), 0),
3028 const0_rtx
, VOIDmode
, 0);
3031 expand_aggr_init (build_indirect_ref (decl
, NULL_PTR
), init
, 0, 0);
3034 else if (decl
== error_mark_node
)
3036 else my_friendly_abort (22);
3038 /* Cleanup any temporaries needed for the initial value. */
3039 expand_cleanups_to (old_cleanups
);
3042 target_temp_slot_level
= old_temp_level
;
3044 vars
= TREE_CHAIN (vars
);
3047 for (; static_ctors
; static_ctors
= TREE_CHAIN (static_ctors
))
3048 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors
),
3051 expand_end_bindings (getdecls (), 1, 0);
3055 finish_function (lineno
, 0, 0);
3056 assemble_constructor (IDENTIFIER_POINTER (fnname
));
3059 expand_builtin_throw ();
3061 permanent_allocation (1);
3063 /* Done with C language context needs. */
3064 pop_lang_context ();
3066 /* Now write out any static class variables (which may have since
3067 learned how to be initialized). */
3068 while (pending_statics
)
3070 tree decl
= TREE_VALUE (pending_statics
);
3072 if (DECL_TEMPLATE_INSTANTIATION (decl
)
3073 && ! DECL_IN_AGGR_P (decl
))
3075 import_export_decl (decl
);
3076 DECL_EXTERNAL (decl
) = ! DECL_NOT_REALLY_EXTERN (decl
);
3079 if (TREE_USED (decl
) == 1
3080 || TREE_READONLY (decl
) == 0
3081 || DECL_INITIAL (decl
) == 0)
3083 DECL_DEFER_OUTPUT (decl
) = 0;
3084 rest_of_decl_compilation (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3086 pending_statics
= TREE_CHAIN (pending_statics
);
3089 this_time
= get_run_time ();
3090 parse_time
-= this_time
- start_time
;
3091 varconst_time
+= this_time
- start_time
;
3093 start_time
= get_run_time ();
3095 if (flag_handle_signatures
)
3096 walk_sigtables ((void (*)())0, finish_sigtable_vardecl
);
3098 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3100 tree decl
= TREE_VALUE (fnname
);
3101 import_export_decl (decl
);
3104 /* Now write out inline functions which had their addresses taken and
3105 which were not declared virtual and which were not declared `extern
3108 int reconsider
= 1; /* More may be referenced; check again */
3112 tree
*p
= &saved_inlines
;
3115 /* We need to do this each time so that newly completed template
3116 types don't wind up at the front of the list. Sigh. */
3117 vars
= build_decl (TYPE_DECL
, make_anon_name (), integer_type_node
);
3118 DECL_IGNORED_P (vars
) = 1;
3119 SET_DECL_ARTIFICIAL (vars
);
3122 reconsider
|= walk_vtables ((void (*)())0, finish_vtable_vardecl
);
3126 tree decl
= TREE_VALUE (*p
);
3128 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3130 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
3132 if (DECL_MUTABLE_P (decl
))
3133 synthesize_tinfo_fn (decl
);
3135 synthesize_method (decl
);
3139 if (decl
!= TREE_VALUE (*p
))
3141 else if (TREE_ASM_WRITTEN (decl
)
3142 || (DECL_SAVED_INSNS (decl
) == 0
3143 && ! DECL_ARTIFICIAL (decl
)))
3144 *p
= TREE_CHAIN (*p
);
3146 p
= &TREE_CHAIN (*p
);
3150 reconsider
= 1; /* More may be referenced; check again */
3153 tree
*p
= &saved_inlines
;
3158 tree decl
= TREE_VALUE (*p
);
3160 if (TREE_ASM_WRITTEN (decl
) || DECL_SAVED_INSNS (decl
) == 0)
3161 *p
= TREE_CHAIN (*p
);
3162 else if ((TREE_PUBLIC (decl
) && ! DECL_WEAK (decl
))
3163 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3164 || flag_keep_inline_functions
)
3166 if (DECL_NOT_REALLY_EXTERN (decl
))
3168 DECL_EXTERNAL (decl
) = 0;
3170 temporary_allocation ();
3171 output_inline_function (decl
);
3172 permanent_allocation (1);
3175 *p
= TREE_CHAIN (*p
);
3178 p
= &TREE_CHAIN (*p
);
3183 /* Now delete from the chain of variables all virtual function tables.
3184 We output them all ourselves, because each will be treated specially. */
3186 walk_vtables ((void (*)())0, prune_vtable_vardecl
);
3188 for (vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
3190 if (TREE_CODE (vars
) == THUNK_DECL
)
3192 else if (TREE_CODE (vars
) == FUNCTION_DECL
3193 && ! DECL_INTERFACE_KNOWN (vars
)
3194 && DECL_C_STATIC (vars
))
3195 TREE_PUBLIC (vars
) = 0;
3198 if (might_have_exceptions_p ())
3199 emit_exception_table ();
3201 if (write_virtuals
== 2)
3203 /* Now complain about an virtual function tables promised
3204 but not delivered. */
3205 while (pending_vtables
)
3207 if (TREE_PURPOSE (pending_vtables
) == NULL_TREE
)
3208 error ("virtual function table for `%s' not defined",
3209 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables
)));
3210 pending_vtables
= TREE_CHAIN (pending_vtables
);
3216 this_time
= get_run_time ();
3217 parse_time
-= this_time
- start_time
;
3218 varconst_time
+= this_time
- start_time
;
3220 if (flag_detailed_statistics
)
3221 dump_time_statistics ();
3224 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3225 expr. Since it was parsed like a type, we need to wade through and fix
3226 that. Unfortunately, since operator() is left-associative, we can't use
3227 tail recursion. In the above example, TYPE is `A', and DECL is
3230 Maybe this shouldn't be recursive, but how often will it actually be
3233 reparse_absdcl_as_expr (type
, decl
)
3236 /* do build_functional_cast (type, NULL_TREE) at bottom */
3237 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3238 return build_functional_cast (type
, NULL_TREE
);
3241 decl
= reparse_decl_as_expr (type
, TREE_OPERAND (decl
, 0));
3243 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_decl
);
3245 if (TREE_CODE (decl
) == CALL_EXPR
&& TREE_TYPE (decl
) != void_type_node
)
3246 decl
= require_complete_type (decl
);
3251 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3252 out to be an expr. Since it was parsed like a type, we need to wade
3253 through and fix that. Since casts are right-associative, we are
3254 reversing the order, so we don't have to recurse.
3256 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3259 reparse_absdcl_as_casts (decl
, expr
)
3264 if (TREE_CODE (expr
) == CONSTRUCTOR
)
3266 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3267 decl
= TREE_OPERAND (decl
, 0);
3269 if (IS_SIGNATURE (type
))
3271 error ("cast specifies signature type");
3272 return error_mark_node
;
3275 expr
= digest_init (type
, expr
, (tree
*) 0);
3276 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3278 int failure
= complete_array_type (type
, expr
, 1);
3280 my_friendly_abort (78);
3286 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3287 decl
= TREE_OPERAND (decl
, 0);
3288 expr
= build_c_cast (type
, expr
, 0);
3294 /* Given plain tree nodes for an expression, build up the full semantics. */
3297 build_expr_from_tree (t
)
3300 if (t
== NULL_TREE
|| t
== error_mark_node
)
3303 switch (TREE_CODE (t
))
3305 case IDENTIFIER_NODE
:
3306 return do_identifier (t
, 0);
3309 if (LOOKUP_EXPR_GLOBAL (t
))
3310 return do_scoped_id (TREE_OPERAND (t
, 0), 0);
3312 return do_identifier (TREE_OPERAND (t
, 0), 0);
3315 return build_x_indirect_ref
3316 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3319 return build_functional_cast
3320 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3322 case REINTERPRET_CAST_EXPR
:
3323 return build_reinterpret_cast
3324 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3326 case PREDECREMENT_EXPR
:
3327 case PREINCREMENT_EXPR
:
3328 case POSTDECREMENT_EXPR
:
3329 case POSTINCREMENT_EXPR
:
3333 case TRUTH_NOT_EXPR
:
3335 case CONVERT_EXPR
: /* Unary + */
3338 return build_x_unary_op (TREE_CODE (t
),
3339 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3344 case TRUNC_DIV_EXPR
:
3346 case FLOOR_DIV_EXPR
:
3347 case ROUND_DIV_EXPR
:
3348 case EXACT_DIV_EXPR
:
3350 case BIT_ANDTC_EXPR
:
3353 case TRUNC_MOD_EXPR
:
3354 case FLOOR_MOD_EXPR
:
3355 case TRUTH_ANDIF_EXPR
:
3356 case TRUTH_ORIF_EXPR
:
3357 case TRUTH_AND_EXPR
:
3372 return build_x_binary_op
3374 build_expr_from_tree (TREE_OPERAND (t
, 0)),
3375 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3378 return build_m_component_ref
3379 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3380 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3383 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
3386 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
3388 return build_parse_node (ARRAY_REF
, NULL_TREE
,
3389 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3390 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3391 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3395 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3396 if (TREE_CODE_CLASS (TREE_CODE (r
)) != 't')
3398 return c_sizeof (r
);
3402 return build_x_modify_expr
3403 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3404 TREE_CODE (TREE_OPERAND (t
, 1)),
3405 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3408 return build_x_arrow
3409 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3413 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3414 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3415 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3416 NEW_EXPR_USE_GLOBAL (t
));
3419 return delete_sanity
3420 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3421 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3422 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
3425 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
3426 return build_x_compound_expr
3427 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3429 my_friendly_abort (42);
3431 case METHOD_CALL_EXPR
:
3432 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3434 tree ref
= TREE_OPERAND (t
, 0);
3435 return build_scoped_method_call
3436 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3437 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3438 TREE_OPERAND (ref
, 1),
3439 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3441 return build_method_call
3442 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3443 TREE_OPERAND (t
, 0),
3444 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3445 NULL_TREE
, LOOKUP_NORMAL
);
3448 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3450 tree ref
= TREE_OPERAND (t
, 0);
3451 return build_member_call
3452 (build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3453 TREE_OPERAND (ref
, 1),
3454 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3458 tree name
= TREE_OPERAND (t
, 0);
3459 if (! really_overloaded_fn (name
))
3460 name
= build_expr_from_tree (name
);
3461 return build_x_function_call
3462 (name
, build_expr_from_tree (TREE_OPERAND (t
, 1)),
3463 current_class_decl
);
3467 return build_x_conditional_expr
3468 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3469 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3470 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3474 tree purpose
, value
, chain
;
3476 if (t
== void_list_node
)
3479 purpose
= TREE_PURPOSE (t
);
3481 purpose
= build_expr_from_tree (purpose
);
3482 value
= TREE_VALUE (t
);
3484 value
= build_expr_from_tree (value
);
3485 chain
= TREE_CHAIN (t
);
3486 if (chain
&& chain
!= void_type_node
)
3487 chain
= build_expr_from_tree (chain
);
3488 return tree_cons (purpose
, value
, chain
);
3492 return build_component_ref
3493 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3494 TREE_OPERAND (t
, 1), NULL_TREE
, 1);
3497 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3504 /* This is something of the form `int (*a)++' that has turned out to be an
3505 expr. It was only converted into parse nodes, so we need to go through
3506 and build up the semantics. Most of the work is done by
3507 build_expr_from_tree, above.
3509 In the above example, TYPE is `int' and DECL is `*a'. */
3511 reparse_decl_as_expr (type
, decl
)
3514 decl
= build_expr_from_tree (decl
);
3516 return build_functional_cast (type
, build_tree_list (NULL_TREE
, decl
));
3521 /* This is something of the form `int (*a)' that has turned out to be a
3522 decl. It was only converted into parse nodes, so we need to do the
3523 checking that make_{pointer,reference}_declarator do. */
3526 finish_decl_parsing (decl
)
3529 extern int current_class_depth
;
3531 switch (TREE_CODE (decl
))
3533 case IDENTIFIER_NODE
:
3536 return make_pointer_declarator
3537 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3539 return make_reference_declarator
3540 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3542 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3545 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3546 TREE_COMPLEXITY (decl
) = current_class_depth
;
3549 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3552 my_friendly_abort (5);
3558 check_cp_case_value (value
)
3561 if (value
== NULL_TREE
)
3564 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3565 STRIP_TYPE_NOPS (value
);
3567 if (TREE_READONLY_DECL_P (value
))
3569 value
= decl_constant_value (value
);
3570 STRIP_TYPE_NOPS (value
);
3572 value
= fold (value
);
3574 if (TREE_CODE (value
) != INTEGER_CST
3575 && value
!= error_mark_node
)
3577 cp_error ("case label `%E' does not reduce to an integer constant",
3579 value
= error_mark_node
;
3582 /* Promote char or short to int. */
3583 value
= default_conversion (value
);
3585 constant_expression_warning (value
);
3590 tree current_namespace
;
3592 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3593 postfix. Returns 0 if in global namespace. */
3597 tree x
= current_namespace
;
3599 x
= TREE_PURPOSE (x
);
3603 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3605 current_namespace_id (name
)
3608 tree old_id
= get_namespace_id ();
3611 /* Global names retain old encoding. */
3615 buf
= (char *) alloca (8 + IDENTIFIER_LENGTH (old_id
)
3616 + IDENTIFIER_LENGTH (name
));
3617 sprintf (buf
, "__ns_%s_%s", IDENTIFIER_POINTER (old_id
),
3618 IDENTIFIER_POINTER (name
));
3619 return get_identifier (buf
);
3623 do_namespace_alias (alias
, namespace)
3624 tree alias
, namespace;
3626 sorry ("namespace alias");
3630 do_toplevel_using_decl (decl
)
3633 if (decl
== NULL_TREE
|| decl
== error_mark_node
)
3636 if (TREE_CODE (decl
) == SCOPE_REF
)
3637 decl
= resolve_scope_to_name (NULL_TREE
, decl
);
3639 /* Is this the right way to do an id list? */
3640 if (TREE_CODE (decl
) != TREE_LIST
)
3647 pushdecl (TREE_VALUE (decl
));
3648 decl
= TREE_CHAIN (decl
);
3653 do_class_using_decl (decl
)
3658 if (TREE_CODE (decl
) != SCOPE_REF
)
3660 cp_error ("using-declaration for non-member at class scope");
3663 name
= TREE_OPERAND (decl
, 1);
3664 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
3666 cp_error ("using-declaration for destructor");
3670 value
= build_lang_field_decl (USING_DECL
, name
, void_type_node
);
3671 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
3676 do_using_directive (namespace)
3679 sorry ("using directive");
3683 check_default_args (x
)
3686 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
3687 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
3688 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
3690 if (TREE_PURPOSE (arg
))
3694 cp_error ("default argument missing for parameter %P of `%#D'",
3705 TREE_USED (decl
) = 1;
3706 if (current_template_parms
)
3708 assemble_external (decl
);
3709 if (DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
))
3710 instantiate_decl (decl
);