1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1995 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
39 extern tree
grokdeclarator ();
40 extern tree
get_file_function_name ();
41 extern tree cleanups_this_call
;
42 static void grok_function_init ();
44 /* A list of virtual function tables we must make sure to write out. */
47 /* A list of static class variables. This is needed, because a
48 static class variable can be declared inside the class without
49 an initializer, and then initialized, staticly, outside the class. */
52 /* A list of functions which were declared inline, but which we
53 may need to emit outline anyway. */
54 static tree saved_inlines
;
56 /* Used to help generate temporary names which are unique within
57 a function. Reset to 0 by start_function. */
59 int temp_name_counter
;
61 /* Same, but not reset. Local temp variables and global temp variables
62 can have the same name. */
63 static int global_temp_name_counter
;
65 /* Flag used when debugging spew.c */
67 extern int spew_debug
;
69 /* Functions called along with real static constructors and destructors. */
71 tree static_ctors
, static_dtors
;
73 /* C (and C++) language-specific option variables. */
75 /* Nonzero means allow type mismatches in conditional expressions;
76 just make their values `void'. */
78 int flag_cond_mismatch
;
80 /* Nonzero means give `double' the same size as `float'. */
82 int flag_short_double
;
84 /* Nonzero means don't recognize the keyword `asm'. */
88 /* Nonzero means don't recognize any extension keywords. */
90 int flag_no_gnu_keywords
;
92 /* Nonzero means don't recognize the non-ANSI builtin functions. */
96 /* Nonzero means don't recognize the non-ANSI builtin functions.
99 int flag_no_nonansi_builtin
;
101 /* Nonzero means do some things the same way PCC does. */
103 int flag_traditional
;
105 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
107 int flag_signed_bitfields
= 1;
109 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
113 /* Nonzero means enable obscure ANSI features and disable GNU extensions
114 that might cause ANSI-compliant code to be miscompiled. */
118 /* Nonzero means do emit exported implementations of functions even if
119 they can be inlined. */
121 int flag_implement_inlines
= 1;
123 /* Nonzero means do emit exported implementations of templates, instead of
124 multiple static copies in each file that needs a definition. */
126 int flag_external_templates
;
128 /* Nonzero means that the decision to emit or not emit the implementation of a
129 template depends on where the template is instantiated, rather than where
132 int flag_alt_external_templates
;
134 /* Nonzero means that implicit instantiations will be emitted if needed. */
136 int flag_implicit_templates
= 1;
138 /* Nonzero means warn about implicit declarations. */
140 int warn_implicit
= 1;
142 /* Nonzero means warn when all ctors or dtors are private, and the class
145 int warn_ctor_dtor_privacy
= 1;
147 /* True if we want to implement vtbvales using "thunks".
148 The default is off now, but will be on later. */
150 int flag_vtable_thunks
;
152 /* True if we want to deal with repository information. */
154 int flag_use_repository
;
156 /* Nonzero means give string constants the type `const char *'
157 to get extra warnings from them. These warnings will be too numerous
158 to be useful, except in thoroughly ANSIfied programs. */
160 int warn_write_strings
;
162 /* Nonzero means warn about pointer casts that can drop a type qualifier
163 from the pointer target type. */
167 /* Nonzero means warn that dbx info for template class methods isn't fully
170 int warn_template_debugging
;
172 /* Warn about traditional constructs whose meanings changed in ANSI C. */
174 int warn_traditional
;
176 /* Nonzero means warn about sizeof(function) or addition/subtraction
177 of function pointers. */
179 int warn_pointer_arith
;
181 /* Nonzero means warn for non-prototype function decls
182 or non-prototyped defs without previous prototype. */
184 int warn_strict_prototypes
;
186 /* Nonzero means warn for any function def without prototype decl. */
188 int warn_missing_prototypes
;
190 /* Nonzero means warn about multiple (redundant) decls for the same single
191 variable or function. */
193 int warn_redundant_decls
;
195 /* Warn if initializer is not completely bracketed. */
197 int warn_missing_braces
;
199 /* Warn about *printf or *scanf format/argument anomalies. */
203 /* Warn about a subscript that has type char. */
205 int warn_char_subscripts
;
207 /* Warn if a type conversion is done that might have confusing results. */
211 /* Warn if adding () is suggested. */
213 int warn_parentheses
;
215 /* Non-zero means warn in function declared in derived class has the
216 same name as a virtual in the base class, but fails to match the
217 type signature of any virtual function in the base class. */
218 int warn_overloaded_virtual
;
220 /* Non-zero means warn when declaring a class that has a non virtual
221 destructor, when it really ought to have a virtual one. */
224 /* Non-zero means warn when a function is declared extern and later inline. */
225 int warn_extern_inline
;
227 /* Non-zero means warn when the compiler will reorder code. */
230 /* Non-zero means warn when sysnthesis behavior differs from Cfront's. */
233 /* Nonzero means `$' can be in an identifier.
234 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
236 #ifndef DOLLARS_IN_IDENTIFIERS
237 #define DOLLARS_IN_IDENTIFIERS 1
239 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
241 /* Nonzero for -fno-strict-prototype switch: do not consider empty
242 argument prototype to mean function takes no arguments. */
244 int flag_strict_prototype
= 2;
245 int strict_prototype
= 1;
246 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
248 /* Nonzero means that labels can be used as first-class objects */
252 /* Non-zero means to collect statistics which might be expensive
253 and to print them when we are done. */
254 int flag_detailed_statistics
;
256 /* C++ specific flags. */
257 /* Nonzero for -fall-virtual: make every member function (except
258 constructors) lay down in the virtual function table. Calls
259 can then either go through the virtual function table or not,
262 int flag_all_virtual
;
264 /* Zero means that `this' is a *const. This gives nice behavior in the
265 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
266 -2 means we're constructing an object and it has fixed type. */
268 int flag_this_is_variable
;
270 /* Nonzero means memoize our member lookups. */
272 int flag_memoize_lookups
; int flag_save_memoized_contexts
;
274 /* 3 means write out only virtuals function tables `defined'
275 in this implementation file.
276 2 means write out only specific virtual function tables
277 and give them (C) public access.
278 1 means write out virtual function tables and give them
280 0 means write out virtual function tables and give them
281 (C) static access (default).
282 -1 means declare virtual function tables extern. */
286 /* Nonzero means we should attempt to elide constructors when possible. */
288 int flag_elide_constructors
;
290 /* Nonzero means recognize and handle exception handling constructs.
291 Use ansi syntax and semantics. WORK IN PROGRESS! */
293 int flag_handle_exceptions
;
295 /* Nonzero means recognize and handle signature language constructs. */
297 int flag_handle_signatures
;
299 /* Nonzero means that member functions defined in class scope are
300 inline by default. */
302 int flag_default_inline
= 1;
304 /* Controls whether enums and ints freely convert.
305 1 means with complete freedom.
306 0 means enums can convert to ints, but not vice-versa. */
307 int flag_int_enum_equivalence
;
309 /* Controls whether compiler is operating under LUCID's Cadillac
310 system. 1 means yes, 0 means no. */
313 /* Controls whether compiler generates code to build objects
314 that can be collected when they become garbage. */
317 /* Controls whether compiler generates 'type descriptor' that give
318 run-time type information. */
321 /* Nonzero if we wish to output cross-referencing information
322 for the GNU class browser. */
323 extern int flag_gnu_xref
;
325 /* Nonzero if compiler can make `reasonable' assumptions about
326 references and objects. For example, the compiler must be
327 conservative about the following and not assume that `a' is nonnull:
332 In general, it is `reasonable' to assume that for many programs,
333 and better code can be generated in that case. */
335 int flag_assume_nonnull_objects
= 1;
337 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
340 int flag_huge_objects
;
342 /* Nonzero if we want to conserve space in the .o files. We do this
343 by putting uninitialized data and runtime initialized data into
344 .common instead of .data at the expense of not flaging multiple
347 int flag_conserve_space
;
349 /* Nonzero if we want to obey access control semantics. */
351 int flag_access_control
= 1;
353 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
355 int flag_operator_names
;
357 /* Nonzero if we want to check the return value of new and avoid calling
358 constructors if it is a null pointer. */
362 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
363 initialization variables. Default to on. */
365 int flag_new_for_scope
= 1;
367 /* Table of language-dependent -f options.
368 STRING is the option name. VARIABLE is the address of the variable.
369 ON_VALUE is the value to store in VARIABLE
370 if `-fSTRING' is seen as an option.
371 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
373 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
375 {"signed-char", &flag_signed_char
, 1},
376 {"unsigned-char", &flag_signed_char
, 0},
377 {"signed-bitfields", &flag_signed_bitfields
, 1},
378 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
379 {"short-enums", &flag_short_enums
, 1},
380 {"short-double", &flag_short_double
, 1},
381 {"cond-mismatch", &flag_cond_mismatch
, 1},
382 {"asm", &flag_no_asm
, 0},
383 {"builtin", &flag_no_builtin
, 0},
384 {"ident", &flag_no_ident
, 0},
385 {"labels-ok", &flag_labels_ok
, 1},
386 {"stats", &flag_detailed_statistics
, 1},
387 {"this-is-variable", &flag_this_is_variable
, 1},
388 {"strict-prototype", &flag_strict_prototype
, 1},
389 {"all-virtual", &flag_all_virtual
, 1},
390 {"memoize-lookups", &flag_memoize_lookups
, 1},
391 {"elide-constructors", &flag_elide_constructors
, 1},
392 {"handle-exceptions", &flag_handle_exceptions
, 1},
393 {"handle-signatures", &flag_handle_signatures
, 1},
394 {"default-inline", &flag_default_inline
, 1},
395 {"dollars-in-identifiers", &dollars_in_ident
, 1},
396 {"enum-int-equiv", &flag_int_enum_equivalence
, 1},
398 {"rtti", &flag_rtti
, 1},
399 {"xref", &flag_gnu_xref
, 1},
400 {"nonnull-objects", &flag_assume_nonnull_objects
, 1},
401 {"implement-inlines", &flag_implement_inlines
, 1},
402 {"external-templates", &flag_external_templates
, 1},
403 {"implicit-templates", &flag_implicit_templates
, 1},
404 {"huge-objects", &flag_huge_objects
, 1},
405 {"conserve-space", &flag_conserve_space
, 1},
406 {"vtable-thunks", &flag_vtable_thunks
, 1},
407 {"short-temps", &flag_short_temps
, 1},
408 {"access-control", &flag_access_control
, 1},
409 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
410 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
411 {"operator-names", &flag_operator_names
, 1},
412 {"check-new", &flag_check_new
, 1},
413 {"repo", &flag_use_repository
, 1},
414 {"for-scope", &flag_new_for_scope
, 1}
417 /* Decode the string P as a language-specific option.
418 Return 1 if it is recognized (and handle it);
419 return 0 if not recognized. */
422 lang_decode_option (p
)
425 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
426 flag_traditional
= 1, dollars_in_ident
= 1, flag_writable_strings
= 1,
427 flag_this_is_variable
= 1, flag_new_for_scope
= 0;
428 /* The +e options are for cfront compatibility. They come in as
429 `-+eN', to kludge around gcc.c's argument handling. */
430 else if (p
[0] == '-' && p
[1] == '+' && p
[2] == 'e')
432 int old_write_virtuals
= write_virtuals
;
435 else if (p
[3] == '0')
437 else if (p
[3] == '2')
439 else error ("invalid +e option");
440 if (old_write_virtuals
!= 0
441 && write_virtuals
!= old_write_virtuals
)
442 error ("conflicting +e options given");
444 else if (p
[0] == '-' && p
[1] == 'f')
446 /* Some kind of -f option.
447 P's value is the option sans `-f'.
448 Search for it in the table of options. */
452 /* Try special -f options. */
454 if (!strcmp (p
, "save-memoized"))
456 flag_memoize_lookups
= 1;
457 flag_save_memoized_contexts
= 1;
460 if (!strcmp (p
, "no-save-memoized"))
462 flag_memoize_lookups
= 0;
463 flag_save_memoized_contexts
= 0;
466 else if (! strncmp (p
, "cadillac", 8))
468 flag_cadillac
= atoi (p
+9);
471 else if (! strncmp (p
, "no-cadillac", 11))
476 else if (! strcmp (p
, "gc"))
479 /* This must come along for the ride. */
483 else if (! strcmp (p
, "no-gc"))
486 /* This must come along for the ride. */
490 else if (! strcmp (p
, "alt-external-templates"))
492 flag_external_templates
= 1;
493 flag_alt_external_templates
= 1;
496 else if (! strcmp (p
, "no-alt-external-templates"))
498 flag_alt_external_templates
= 0;
501 else if (!strcmp (p
, "ansi-overloading"))
503 warning ("-fansi-overloading is no longer meaningful");
506 else if (!strcmp (p
, "repo"))
508 flag_use_repository
= 1;
509 flag_implicit_templates
= 0;
513 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
516 if (!strcmp (p
, lang_f_options
[j
].string
))
518 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
519 /* A goto here would be cleaner,
520 but breaks the vax pcc. */
523 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
524 && ! strcmp (p
+3, lang_f_options
[j
].string
))
526 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
532 else if (p
[0] == '-' && p
[1] == 'W')
536 /* The -W options control the warning behavior of the compiler. */
539 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
542 if (!strcmp (p
, "implicit"))
543 warn_implicit
= setting
;
544 else if (!strcmp (p
, "return-type"))
545 warn_return_type
= setting
;
546 else if (!strcmp (p
, "ctor-dtor-privacy"))
547 warn_ctor_dtor_privacy
= setting
;
548 else if (!strcmp (p
, "write-strings"))
549 warn_write_strings
= setting
;
550 else if (!strcmp (p
, "cast-qual"))
551 warn_cast_qual
= setting
;
552 else if (!strcmp (p
, "traditional"))
553 warn_traditional
= setting
;
554 else if (!strcmp (p
, "char-subscripts"))
555 warn_char_subscripts
= setting
;
556 else if (!strcmp (p
, "pointer-arith"))
557 warn_pointer_arith
= setting
;
558 else if (!strcmp (p
, "strict-prototypes"))
559 warn_strict_prototypes
= setting
;
560 else if (!strcmp (p
, "missing-prototypes"))
561 warn_missing_prototypes
= setting
;
562 else if (!strcmp (p
, "redundant-decls"))
563 warn_redundant_decls
= setting
;
564 else if (!strcmp (p
, "missing-braces"))
565 warn_missing_braces
= setting
;
566 else if (!strcmp (p
, "format"))
567 warn_format
= setting
;
568 else if (!strcmp (p
, "conversion"))
569 warn_conversion
= setting
;
570 else if (!strcmp (p
, "parentheses"))
571 warn_parentheses
= setting
;
572 else if (!strcmp (p
, "non-virtual-dtor"))
573 warn_nonvdtor
= setting
;
574 else if (!strcmp (p
, "extern-inline"))
575 warn_extern_inline
= setting
;
576 else if (!strcmp (p
, "reorder"))
577 warn_reorder
= setting
;
578 else if (!strcmp (p
, "synth"))
579 warn_synth
= setting
;
580 else if (!strcmp (p
, "comment"))
581 ; /* cpp handles this one. */
582 else if (!strcmp (p
, "comments"))
583 ; /* cpp handles this one. */
584 else if (!strcmp (p
, "trigraphs"))
585 ; /* cpp handles this one. */
586 else if (!strcmp (p
, "import"))
587 ; /* cpp handles this one. */
588 else if (!strcmp (p
, "all"))
590 extra_warnings
= setting
;
591 warn_return_type
= setting
;
592 warn_unused
= setting
;
593 warn_implicit
= setting
;
594 warn_ctor_dtor_privacy
= setting
;
595 warn_switch
= setting
;
596 warn_format
= setting
;
597 warn_parentheses
= setting
;
598 warn_missing_braces
= setting
;
599 warn_extern_inline
= setting
;
600 warn_nonvdtor
= setting
;
601 /* We save the value of warn_uninitialized, since if they put
602 -Wuninitialized on the command line, we need to generate a
603 warning about not using it without also specifying -O. */
604 if (warn_uninitialized
!= 1)
605 warn_uninitialized
= (setting
? 2 : 0);
606 warn_template_debugging
= setting
;
607 warn_reorder
= setting
;
610 else if (!strcmp (p
, "overloaded-virtual"))
611 warn_overloaded_virtual
= setting
;
614 else if (!strcmp (p
, "-ansi"))
615 dollars_in_ident
= 0, flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
616 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
618 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
619 it's probably safe to assume no sane person would ever want to use this
620 under normal circumstances. */
621 else if (!strcmp (p
, "-spew-debug"))
630 /* Incorporate `const' and `volatile' qualifiers for member functions.
631 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
632 QUALS is a list of qualifiers. */
634 grok_method_quals (ctype
, function
, quals
)
635 tree ctype
, function
, quals
;
637 tree fntype
= TREE_TYPE (function
);
638 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
642 extern tree ridpointers
[];
644 if (TREE_VALUE (quals
) == ridpointers
[(int)RID_CONST
])
646 if (TYPE_READONLY (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
, 1, TYPE_VOLATILE (ctype
));
652 build_pointer_type (ctype
);
654 else if (TREE_VALUE (quals
) == ridpointers
[(int)RID_VOLATILE
])
656 if (TYPE_VOLATILE (ctype
))
657 error ("duplicate `%s' %s",
658 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
659 (TREE_CODE (function
) == FUNCTION_DECL
660 ? "for member function" : "in type declaration"));
661 ctype
= build_type_variant (ctype
, TYPE_READONLY (ctype
), 1);
662 build_pointer_type (ctype
);
665 my_friendly_abort (20);
666 quals
= TREE_CHAIN (quals
);
669 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
670 (TREE_CODE (fntype
) == METHOD_TYPE
671 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
672 : TYPE_ARG_TYPES (fntype
)));
674 fntype
= build_exception_variant (ctype
, fntype
, raises
);
676 TREE_TYPE (function
) = fntype
;
680 #if 0 /* Not used. */
681 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
682 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
683 /* This does not yet work with user defined conversion operators
686 substitute_nice_name (decl
)
689 if (DECL_NAME (decl
) && TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
691 char *n
= decl_as_string (DECL_NAME (decl
), 1);
692 if (n
[strlen (n
) - 1] == ' ')
693 n
[strlen (n
) - 1] = 0;
694 DECL_NAME (decl
) = get_identifier (n
);
699 /* Warn when -fexternal-templates is used and #pragma
700 interface/implementation is not used all the times it should be,
703 warn_if_unknown_interface (decl
)
706 static int already_warned
= 0;
707 if (already_warned
++)
710 if (flag_alt_external_templates
)
712 struct tinst_level
*til
= tinst_for_decl ();
714 char *sf
= input_filename
;
717 input_filename
= til
->file
;
718 cp_warning ("template `%#D' instantiated in file without #pragma interface",
724 cp_warning_at ("template `%#D' defined in file without #pragma interface",
728 /* A subroutine of the parser, to handle a component list. */
730 grok_x_components (specs
, components
)
731 tree specs
, components
;
733 register tree t
, x
, tcode
;
735 /* We just got some friends. They have been recorded elsewhere. */
736 if (components
== void_type_node
)
739 if (components
== NULL_TREE
)
741 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
745 error ("error in component specification");
749 switch (TREE_CODE (t
))
752 /* Static anonymous unions come out as VAR_DECLs. */
753 if (TREE_CODE (TREE_TYPE (t
)) == UNION_TYPE
754 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t
))))
757 /* We return SPECS here, because in the parser it was ending
758 up with not doing anything to $$, which is what SPECS
764 /* This code may be needed for UNION_TYPEs as
766 tcode
= record_type_node
;
767 if (CLASSTYPE_DECLARED_CLASS(t
))
768 tcode
= class_type_node
;
769 else if (IS_SIGNATURE(t
))
770 tcode
= signature_type_node
;
772 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
774 CLASSTYPE_NO_GLOBALIZE(t
) = 1;
780 if (TREE_CODE(t
) == UNION_TYPE
)
781 tcode
= union_type_node
;
783 tcode
= enum_type_node
;
785 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
786 if (TREE_CODE(t
) == UNION_TYPE
&& TYPE_CONTEXT(t
))
787 CLASSTYPE_NO_GLOBALIZE(t
) = 1;
788 if (TREE_CODE (t
) == UNION_TYPE
789 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))
791 struct pending_inline
**p
;
792 x
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, t
);
794 /* Wipe out memory of synthesized methods */
795 TYPE_HAS_CONSTRUCTOR (t
) = 0;
796 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
797 TYPE_HAS_INIT_REF (t
) = 0;
798 TYPE_HAS_CONST_INIT_REF (t
) = 0;
799 TYPE_HAS_ASSIGN_REF (t
) = 0;
800 TYPE_HAS_ASSIGNMENT (t
) = 0;
801 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
803 p
= &pending_inlines
;
804 for (; *p
; *p
= (*p
)->next
)
805 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
808 else if (TREE_CODE (t
) == ENUMERAL_TYPE
)
809 x
= grok_enum_decls (t
, NULL_TREE
);
816 if (t
!= void_type_node
)
817 error ("empty component declaration");
823 t
= TREE_TYPE (components
);
824 if (TREE_CODE (t
) == ENUMERAL_TYPE
&& TREE_NONLOCAL_FLAG (t
))
825 return grok_enum_decls (t
, components
);
831 /* Classes overload their constituent function names automatically.
832 When a function name is declared in a record structure,
833 its name is changed to it overloaded name. Since names for
834 constructors and destructors can conflict, we place a leading
837 CNAME is the name of the class we are grokking for.
839 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
841 FLAGS contains bits saying what's special about today's
842 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
844 If FUNCTION is a destructor, then we must add the `auto-delete' field
845 as a second parameter. There is some hair associated with the fact
846 that we must "declare" this variable in the manner consistent with the
847 way the rest of the arguments were declared.
849 QUALS are the qualifiers for the this pointer. */
852 grokclassfn (ctype
, cname
, function
, flags
, quals
)
853 tree ctype
, cname
, function
;
854 enum overload_flags flags
;
857 tree fn_name
= DECL_NAME (function
);
862 if (fn_name
== NULL_TREE
)
864 error ("name missing for member function");
865 fn_name
= get_identifier ("<anonymous>");
866 DECL_NAME (function
) = fn_name
;
870 qualtype
= grok_method_quals (ctype
, function
, quals
);
874 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
875 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
877 /* Must add the class instance variable up front. */
878 /* Right now we just make this a pointer. But later
879 we may wish to make it special. */
880 tree type
= TREE_VALUE (arg_types
);
883 if ((flag_this_is_variable
> 0)
884 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
887 if (DECL_CONSTRUCTOR_P (function
))
889 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype
))
891 DECL_CONSTRUCTOR_FOR_VBASE_P (function
) = 1;
892 /* In this case we need "in-charge" flag saying whether
893 this constructor is responsible for initialization
894 of virtual baseclasses or not. */
895 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
896 /* Mark the artificial `__in_chrg' parameter as "artificial". */
897 SET_DECL_ARTIFICIAL (parm
);
898 DECL_ARG_TYPE (parm
) = integer_type_node
;
899 DECL_REGISTER (parm
) = 1;
900 TREE_CHAIN (parm
) = last_function_parms
;
901 last_function_parms
= parm
;
905 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
906 /* Mark the artificial `this' parameter as "artificial". */
907 SET_DECL_ARTIFICIAL (parm
);
908 DECL_ARG_TYPE (parm
) = type
;
909 /* We can make this a register, so long as we don't
910 accidentally complain if someone tries to take its address. */
911 DECL_REGISTER (parm
) = 1;
913 TREE_READONLY (parm
) = 1;
914 TREE_CHAIN (parm
) = last_function_parms
;
915 last_function_parms
= parm
;
918 if (flags
== DTOR_FLAG
)
921 tree const_integer_type
= build_type_variant (integer_type_node
, 1, 0);
922 int len
= sizeof (DESTRUCTOR_DECL_PREFIX
)-1;
924 arg_types
= hash_tree_chain (const_integer_type
, void_list_node
);
925 TREE_SIDE_EFFECTS (arg_types
) = 1;
926 /* Build the overload name. It will look like `7Example'. */
927 if (IDENTIFIER_TYPE_VALUE (cname
))
928 dbuf
= build_overload_name (IDENTIFIER_TYPE_VALUE (cname
), 1, 1);
929 else if (IDENTIFIER_LOCAL_VALUE (cname
))
930 dbuf
= build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname
)), 1, 1);
932 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
933 it's defined out of the class definition, since poplevel_class wipes
934 it out. This used to be internal error 346. */
935 dbuf
= build_overload_name (ctype
, 1, 1);
936 buf
= (char *) alloca (strlen (dbuf
) + sizeof (DESTRUCTOR_DECL_PREFIX
));
937 bcopy (DESTRUCTOR_DECL_PREFIX
, buf
, len
);
940 DECL_ASSEMBLER_NAME (function
) = get_identifier (buf
);
941 parm
= build_decl (PARM_DECL
, in_charge_identifier
, const_integer_type
);
942 /* Mark the artificial `__in_chrg' parameter as "artificial". */
943 SET_DECL_ARTIFICIAL (parm
);
944 TREE_USED (parm
) = 1;
946 /* We don't need to mark the __in_chrg parameter itself as `const'
947 since its type is already `const int'. In fact we MUST NOT mark
948 it as `const' cuz that will screw up the debug info (causing it
949 to say that the type of __in_chrg is `const const int'). */
950 TREE_READONLY (parm
) = 1;
952 DECL_ARG_TYPE (parm
) = const_integer_type
;
953 /* This is the same chain as DECL_ARGUMENTS (...). */
954 TREE_CHAIN (last_function_parms
) = parm
;
956 TREE_TYPE (function
) = build_cplus_method_type (qualtype
, void_type_node
,
958 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
962 tree these_arg_types
;
964 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function
))
966 arg_types
= hash_tree_chain (integer_type_node
,
967 TREE_CHAIN (arg_types
));
969 = build_cplus_method_type (qualtype
,
970 TREE_TYPE (TREE_TYPE (function
)),
972 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
975 these_arg_types
= arg_types
;
977 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
978 /* Only true for static member functions. */
979 these_arg_types
= hash_tree_chain (TYPE_POINTER_TO (qualtype
),
982 DECL_ASSEMBLER_NAME (function
)
983 = build_decl_overload (fn_name
, these_arg_types
,
984 1 + DECL_CONSTRUCTOR_P (function
));
987 /* This code is going into the compiler, but currently, it makes
988 libg++/src/Interger.cc not compile. The problem is that the nice name
989 winds up going into the symbol table, and conversion operations look
990 for the manged name. */
991 substitute_nice_name (function
);
995 DECL_ARGUMENTS (function
) = last_function_parms
;
996 /* First approximations. */
997 DECL_CONTEXT (function
) = ctype
;
998 DECL_CLASS_CONTEXT (function
) = ctype
;
1001 /* Work on the expr used by alignof (this is only called by the parser). */
1009 if (TREE_CODE (expr
) == COMPONENT_REF
1010 && DECL_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1011 error ("`__alignof__' applied to a bit-field");
1013 if (TREE_CODE (expr
) == INDIRECT_REF
)
1015 best
= t
= TREE_OPERAND (expr
, 0);
1016 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1018 while (TREE_CODE (t
) == NOP_EXPR
1019 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1022 t
= TREE_OPERAND (t
, 0);
1023 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1024 if (thisalign
> bestalign
)
1025 best
= t
, bestalign
= thisalign
;
1027 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1031 /* ANSI says arrays and fns are converted inside comma.
1032 But we can't convert them in build_compound_expr
1033 because that would break commas in lvalues.
1034 So do the conversion here if operand was a comma. */
1035 if (TREE_CODE (expr
) == COMPOUND_EXPR
1036 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1037 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1038 expr
= default_conversion (expr
);
1039 return c_alignof (TREE_TYPE (expr
));
1043 /* Create an ARRAY_REF, checking for the user doing things backwards
1046 grok_array_decl (array_expr
, index_exp
)
1047 tree array_expr
, index_exp
;
1049 tree type
= TREE_TYPE (array_expr
);
1050 tree p1
, p2
, i1
, i2
;
1052 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1053 return error_mark_node
;
1054 if (type
== NULL_TREE
)
1056 /* Something has gone very wrong. Assume we are mistakenly reducing
1057 an expression instead of a declaration. */
1058 error ("parser may be lost: is there a '{' missing somewhere?");
1062 if (TREE_CODE (type
) == OFFSET_TYPE
1063 || TREE_CODE (type
) == REFERENCE_TYPE
)
1064 type
= TREE_TYPE (type
);
1066 /* If they have an `operator[]', use that. */
1067 if (TYPE_LANG_SPECIFIC (type
)
1068 && TYPE_OVERLOADS_ARRAY_REF (type
))
1069 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1070 array_expr
, index_exp
, NULL_TREE
);
1072 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1074 if (TREE_CODE (type
) == ARRAY_TYPE
)
1077 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1079 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1082 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1084 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1085 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1087 if ((p1
&& i2
) && (i1
&& p2
))
1088 error ("ambiguous conversion for array subscript");
1091 array_expr
= p1
, index_exp
= i2
;
1093 array_expr
= p2
, index_exp
= i1
;
1096 cp_error ("invalid types `%T[%T]' for array subscript",
1097 type
, TREE_TYPE (index_exp
));
1098 return error_mark_node
;
1101 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1102 error ("ambiguous conversion for array subscript");
1104 return build_array_ref (array_expr
, index_exp
);
1107 /* Given the cast expression EXP, checking out its validity. Either return
1108 an error_mark_node if there was an unavoidable error, return a cast to
1109 void for trying to delete a pointer w/ the value 0, or return the
1110 call to delete. If DOING_VEC is 1, we handle things differently
1111 for doing an array delete. If DOING_VEC is 2, they gave us the
1112 array size as an argument to delete.
1113 Implements ARM $5.3.4. This is called from the parser. */
1115 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1117 int doing_vec
, use_global_delete
;
1119 tree t
= stabilize_reference (convert_from_reference (exp
));
1120 tree type
= TREE_TYPE (t
);
1121 enum tree_code code
= TREE_CODE (type
);
1122 /* For a regular vector delete (aka, no size argument) we will pass
1123 this down as a NULL_TREE into build_vec_delete. */
1124 tree maxindex
= NULL_TREE
;
1125 /* This is used for deleting arrays. */
1131 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1132 if (! flag_traditional
)
1133 pedwarn ("anachronistic use of array size in vector delete");
1136 elt_size
= c_sizeof (type
);
1139 if (code
!= POINTER_TYPE
)
1141 cp_error ("type `%#T' argument given to `delete', expected pointer",
1143 return error_mark_node
;
1146 /* Deleting a pointer with the value zero is valid and has no effect. */
1147 if (integer_zerop (t
))
1148 return build1 (NOP_EXPR
, void_type_node
, t
);
1151 if (code
== POINTER_TYPE
)
1154 /* As of Valley Forge, you can delete a pointer to constant. */
1155 /* You can't delete a pointer to constant. */
1156 if (TREE_READONLY (TREE_TYPE (type
)))
1158 error ("`const *' cannot be deleted");
1159 return error_mark_node
;
1162 /* You also can't delete functions. */
1163 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1165 error ("cannot delete a function");
1166 return error_mark_node
;
1171 /* If the type has no destructor, then we should build a regular
1172 delete, instead of a vector delete. Otherwise, we would end
1173 up passing a bogus offset into __builtin_delete, which is
1174 not expecting it. */
1176 && TREE_CODE (type
) == POINTER_TYPE
1177 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type
)))
1180 use_global_delete
= 1;
1185 return build_vec_delete (t
, maxindex
, elt_size
, integer_one_node
,
1186 integer_two_node
, use_global_delete
);
1189 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1190 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1192 /* Only do access checking here; we'll be calling op delete
1193 from the destructor. */
1194 tree tmp
= build_opfncall (DELETE_EXPR
, LOOKUP_NORMAL
, t
,
1195 size_zero_node
, NULL_TREE
);
1196 if (tmp
== error_mark_node
)
1197 return error_mark_node
;
1200 return build_delete (type
, t
, integer_three_node
,
1201 LOOKUP_NORMAL
|LOOKUP_HAS_IN_CHARGE
,
1206 /* Sanity check: report error if this function FUNCTION is not
1207 really a member of the class (CTYPE) it is supposed to belong to.
1208 CNAME is the same here as it is for grokclassfn above. */
1211 check_classfn (ctype
, cname
, function
)
1212 tree ctype
, cname
, function
;
1214 tree fn_name
= DECL_NAME (function
);
1216 tree method_vec
= CLASSTYPE_METHOD_VEC (ctype
);
1220 if (method_vec
!= 0)
1222 methods
= &TREE_VEC_ELT (method_vec
, 0);
1223 end
= TREE_VEC_END (method_vec
);
1225 /* First suss out ctors and dtors. */
1227 && (fn_name
== cname
|| fn_name
== DECL_NAME (*methods
)))
1230 while (++methods
!= end
)
1232 if (fn_name
== DECL_NAME (*methods
))
1238 if (DECL_ASSEMBLER_NAME (function
) == DECL_ASSEMBLER_NAME (fndecl
))
1241 /* This should work, but causes libg++ to fail
1243 /* We have to do more extensive argument checking here, as
1244 the name may have been changed by asm("new_name"). */
1245 if (decls_match (function
, fndecl
))
1248 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1250 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1251 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1253 /* Get rid of the this parameter on functions that become
1255 if (DECL_STATIC_FUNCTION_P (fndecl
)
1256 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1257 p1
= TREE_CHAIN (p1
);
1259 if (comptypes (TREE_TYPE (TREE_TYPE (function
)),
1260 TREE_TYPE (TREE_TYPE (fndecl
)), 1)
1261 && compparms (p1
, p2
, 3))
1265 fndecl
= DECL_CHAIN (fndecl
);
1273 cp_error ("argument list for `%#D' does not match any in class `%T'",
1278 cp_error ("no `%#D' member function declared in class `%T'",
1282 /* If we did not find the method in the class, add it to
1283 avoid spurious errors. */
1284 add_method (ctype
, methods
, function
);
1287 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1288 of a structure component, returning a FIELD_DECL node.
1289 QUALS is a list of type qualifiers for this decl (such as for declaring
1290 const member functions).
1292 This is done during the parsing of the struct declaration.
1293 The FIELD_DECL nodes are chained together and the lot of them
1294 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1298 If class A defines that certain functions in class B are friends, then
1299 the way I have set things up, it is B who is interested in permission
1300 granted by A. However, it is in A's context that these declarations
1301 are parsed. By returning a void_type_node, class A does not attempt
1302 to incorporate the declarations of the friends within its structure.
1304 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1305 CHANGES TO CODE IN `start_method'. */
1308 grokfield (declarator
, declspecs
, raises
, init
, asmspec_tree
)
1309 tree declarator
, declspecs
, raises
, init
, asmspec_tree
;
1311 register tree value
;
1313 int flags
= LOOKUP_ONLYCONVERTING
;
1315 /* Convert () initializers to = initializers. */
1316 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1317 && TREE_CODE (declarator
) == CALL_EXPR
1318 && TREE_OPERAND (declarator
, 0)
1319 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1320 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1321 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1323 init
= TREE_OPERAND (declarator
, 1);
1324 declarator
= TREE_OPERAND (declarator
, 0);
1329 && TREE_CODE (init
) == TREE_LIST
1330 && TREE_VALUE (init
) == error_mark_node
1331 && TREE_CHAIN (init
) == NULL_TREE
)
1334 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, raises
);
1336 return value
; /* friend or constructor went bad. */
1338 /* Pass friendly classes back. */
1339 if (TREE_CODE (value
) == VOID_TYPE
)
1340 return void_type_node
;
1342 if (DECL_NAME (value
) != NULL_TREE
1343 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1344 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1345 cp_error ("member `%D' conflicts with virtual function table field name", value
);
1347 /* Stash away type declarations. */
1348 if (TREE_CODE (value
) == TYPE_DECL
)
1350 DECL_NONLOCAL (value
) = 1;
1351 DECL_CONTEXT (value
) = current_class_type
;
1352 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1353 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
1355 /* If we declare a typedef name for something that has no name,
1356 the typedef name is used for linkage. See 7.1.3 p4 94/0158. */
1357 if (TYPE_NAME (TREE_TYPE (value
))
1358 && TREE_CODE (TYPE_NAME (TREE_TYPE (value
))) == TYPE_DECL
1359 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (value
))))
1361 TYPE_NAME (TREE_TYPE (value
)) = value
;
1362 TYPE_STUB_DECL (TREE_TYPE (value
)) = value
;
1365 pushdecl_class_level (value
);
1369 if (IS_SIGNATURE (current_class_type
)
1370 && TREE_CODE (value
) != FUNCTION_DECL
)
1372 error ("field declaration not allowed in signature");
1373 return void_type_node
;
1376 if (DECL_IN_AGGR_P (value
))
1378 cp_error ("`%D' is already defined in the class %T", value
,
1379 DECL_CONTEXT (value
));
1380 return void_type_node
;
1384 cadillac_start_decl (value
);
1387 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1391 if (IS_SIGNATURE (current_class_type
)
1392 && TREE_CODE (value
) == FUNCTION_DECL
)
1394 error ("function declarations cannot have initializers in signature");
1397 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1399 grok_function_init (value
, init
);
1402 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1403 /* Already complained in grokdeclarator. */
1407 /* We allow initializers to become parameters to base
1409 if (TREE_CODE (init
) == TREE_LIST
)
1411 if (TREE_CHAIN (init
) == NULL_TREE
)
1412 init
= TREE_VALUE (init
);
1414 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1417 if (TREE_CODE (init
) == CONST_DECL
)
1418 init
= DECL_INITIAL (init
);
1419 else if (TREE_READONLY_DECL_P (init
))
1420 init
= decl_constant_value (init
);
1421 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1422 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1423 my_friendly_assert (TREE_PERMANENT (init
), 192);
1424 if (init
== error_mark_node
)
1425 /* We must make this look different than `error_mark_node'
1426 because `decl_const_value' would mis-interpret it
1427 as only meaning that this VAR_DECL is defined. */
1428 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1429 else if (! TREE_CONSTANT (init
))
1431 /* We can allow references to things that are effectively
1432 static, since references are initialized with the address. */
1433 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1434 || (TREE_STATIC (init
) == 0
1435 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1436 || DECL_EXTERNAL (init
) == 0)))
1438 error ("field initializer is not constant");
1439 init
= error_mark_node
;
1445 /* The corresponding pop_obstacks is in finish_decl. */
1446 push_obstacks_nochange ();
1448 if (TREE_CODE (value
) == VAR_DECL
)
1450 /* We cannot call pushdecl here, because that would
1451 fill in the value of our TREE_CHAIN. Instead, we
1452 modify finish_decl to do the right thing, namely, to
1453 put this decl out straight away. */
1454 if (TREE_PUBLIC (value
))
1456 /* current_class_type can be NULL_TREE in case of error. */
1457 if (asmspec
== 0 && current_class_type
)
1459 TREE_PUBLIC (value
) = 1;
1460 DECL_INITIAL (value
) = error_mark_node
;
1461 DECL_ASSEMBLER_NAME (value
)
1462 = build_static_name (current_class_type
, DECL_NAME (value
));
1464 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1466 /* Static consts need not be initialized in the class definition. */
1467 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1469 static int explanation
= 0;
1471 error ("initializer invalid for static member with constructor");
1472 if (explanation
++ == 0)
1473 error ("(you really want to initialize it separately)");
1476 /* Force the compiler to know when an uninitialized static
1477 const member is being used. */
1478 if (TYPE_READONLY (value
) && init
== 0)
1479 TREE_USED (value
) = 1;
1481 DECL_INITIAL (value
) = init
;
1482 DECL_IN_AGGR_P (value
) = 1;
1484 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1485 pushdecl_class_level (value
);
1488 if (TREE_CODE (value
) == FIELD_DECL
)
1492 /* This must override the asm specifier which was placed
1493 by grokclassfn. Lay this out fresh. */
1494 DECL_RTL (value
) = NULL_RTX
;
1495 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1497 if (DECL_INITIAL (value
) == error_mark_node
)
1498 init
= error_mark_node
;
1499 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1500 DECL_INITIAL (value
) = init
;
1501 DECL_IN_AGGR_P (value
) = 1;
1504 if (TREE_CODE (value
) == FUNCTION_DECL
)
1506 if (DECL_CHAIN (value
) != NULL_TREE
)
1508 /* Need a fresh node here so that we don't get circularity
1509 when we link these together. */
1510 value
= copy_node (value
);
1511 /* When does this happen? */
1512 my_friendly_assert (init
== NULL_TREE
, 193);
1516 /* This must override the asm specifier which was placed
1517 by grokclassfn. Lay this out fresh. */
1518 DECL_RTL (value
) = NULL_RTX
;
1519 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1521 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1523 /* Pass friends back this way. */
1524 if (DECL_FRIEND_P (value
))
1525 return void_type_node
;
1527 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1528 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1529 cp_error ("method `%#D' of local class must be defined in class body",
1533 DECL_IN_AGGR_P (value
) = 1;
1536 my_friendly_abort (21);
1541 /* Like `grokfield', but for bitfields.
1542 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1545 grokbitfield (declarator
, declspecs
, width
)
1546 tree declarator
, declspecs
, width
;
1548 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
, 0, NULL_TREE
);
1550 if (! value
) return NULL_TREE
; /* friends went bad. */
1552 /* Pass friendly classes back. */
1553 if (TREE_CODE (value
) == VOID_TYPE
)
1554 return void_type_node
;
1556 if (TREE_CODE (value
) == TYPE_DECL
)
1558 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1562 if (IS_SIGNATURE (current_class_type
))
1564 error ("field declaration not allowed in signature");
1565 return void_type_node
;
1568 if (DECL_IN_AGGR_P (value
))
1570 cp_error ("`%D' is already defined in the class %T", value
,
1571 DECL_CONTEXT (value
));
1572 return void_type_node
;
1575 GNU_xref_member (current_class_name
, value
);
1577 if (TREE_STATIC (value
))
1579 cp_error ("static member `%D' cannot be a bitfield", value
);
1582 finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1584 if (width
!= error_mark_node
)
1586 /* detect invalid field size. */
1587 if (TREE_CODE (width
) == CONST_DECL
)
1588 width
= DECL_INITIAL (width
);
1589 else if (TREE_READONLY_DECL_P (width
))
1590 width
= decl_constant_value (width
);
1591 if (TREE_CODE (width
) != INTEGER_CST
)
1593 cp_error ("structure field `%D' width not an integer constant",
1595 DECL_INITIAL (value
) = NULL_TREE
;
1599 constant_expression_warning (width
);
1600 DECL_INITIAL (value
) = width
;
1601 DECL_BIT_FIELD (value
) = 1;
1605 DECL_IN_AGGR_P (value
) = 1;
1610 /* Like GROKFIELD, except that the declarator has been
1611 buried in DECLSPECS. Find the declarator, and
1612 return something that looks like it came from
1615 groktypefield (declspecs
, parmlist
)
1619 tree spec
= declspecs
;
1620 tree prev
= NULL_TREE
;
1622 tree type_id
= NULL_TREE
;
1623 tree quals
= NULL_TREE
;
1624 tree lengths
= NULL_TREE
;
1625 tree decl
= NULL_TREE
;
1629 register tree id
= TREE_VALUE (spec
);
1631 if (TREE_CODE (spec
) != TREE_LIST
)
1632 /* Certain parse errors slip through. For example,
1633 `int class ();' is not caught by the parser. Try
1634 weakly to recover here. */
1637 if (TREE_CODE (id
) == TYPE_DECL
1638 || (TREE_CODE (id
) == IDENTIFIER_NODE
&& TREE_TYPE (id
)))
1640 /* We have a constructor/destructor or
1641 conversion operator. Use it. */
1643 TREE_CHAIN (prev
) = TREE_CHAIN (spec
);
1645 declspecs
= TREE_CHAIN (spec
);
1651 spec
= TREE_CHAIN (spec
);
1654 /* Nope, we have a conversion operator to a scalar type or something
1655 else, that includes things like constructor declarations for
1660 tree id
= TREE_VALUE (spec
);
1662 if (TREE_CODE (id
) == IDENTIFIER_NODE
)
1664 if (id
== ridpointers
[(int)RID_INT
]
1665 || id
== ridpointers
[(int)RID_DOUBLE
]
1666 || id
== ridpointers
[(int)RID_FLOAT
]
1667 || id
== ridpointers
[(int)RID_WCHAR
])
1670 error ("extra `%s' ignored",
1671 IDENTIFIER_POINTER (id
));
1675 else if (id
== ridpointers
[(int)RID_LONG
]
1676 || id
== ridpointers
[(int)RID_SHORT
]
1677 || id
== ridpointers
[(int)RID_CHAR
])
1679 lengths
= tree_cons (NULL_TREE
, id
, lengths
);
1681 else if (id
== ridpointers
[(int)RID_VOID
])
1684 error ("spurious `void' type ignored");
1686 error ("conversion to `void' type invalid");
1688 else if (id
== ridpointers
[(int)RID_AUTO
]
1689 || id
== ridpointers
[(int)RID_REGISTER
]
1690 || id
== ridpointers
[(int)RID_TYPEDEF
]
1691 || id
== ridpointers
[(int)RID_CONST
]
1692 || id
== ridpointers
[(int)RID_VOLATILE
])
1694 error ("type specifier `%s' used invalidly",
1695 IDENTIFIER_POINTER (id
));
1697 else if (id
== ridpointers
[(int)RID_FRIEND
]
1698 || id
== ridpointers
[(int)RID_VIRTUAL
]
1699 || id
== ridpointers
[(int)RID_INLINE
]
1700 || id
== ridpointers
[(int)RID_UNSIGNED
]
1701 || id
== ridpointers
[(int)RID_SIGNED
]
1702 || id
== ridpointers
[(int)RID_STATIC
]
1703 || id
== ridpointers
[(int)RID_EXTERN
])
1705 quals
= tree_cons (NULL_TREE
, id
, quals
);
1709 /* Happens when we have a global typedef
1710 and a class-local member function with
1716 else if (TREE_CODE (id
) == RECORD_TYPE
)
1718 type_id
= TYPE_NAME (id
);
1719 if (TREE_CODE (type_id
) == TYPE_DECL
)
1720 type_id
= DECL_NAME (type_id
);
1721 if (type_id
== NULL_TREE
)
1722 error ("identifier for aggregate type conversion omitted");
1724 else if (TREE_CODE_CLASS (TREE_CODE (id
)) == 't')
1725 error ("`operator' missing on conversion operator or tag missing from type");
1727 my_friendly_abort (194);
1728 spec
= TREE_CHAIN (spec
);
1732 declspecs
= chainon (lengths
, quals
);
1735 if (TREE_CHAIN (lengths
))
1736 error ("multiple length specifiers");
1737 type_id
= ridpointers
[(int)RID_INT
];
1738 declspecs
= chainon (lengths
, quals
);
1742 error ("no type given, defaulting to `operator int ...'");
1743 type_id
= ridpointers
[(int)RID_INT
];
1750 decl
= grokdeclarator (build_parse_node (CALL_EXPR
, type_id
, parmlist
, NULL_TREE
),
1751 declspecs
, FIELD
, 0, NULL_TREE
);
1752 if (decl
== NULL_TREE
)
1755 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CHAIN (decl
) != NULL_TREE
)
1757 /* Need a fresh node here so that we don't get circularity
1758 when we link these together. */
1759 decl
= copy_node (decl
);
1762 if (decl
== void_type_node
1763 || (TREE_CODE (decl
) == FUNCTION_DECL
1764 && TREE_CODE (TREE_TYPE (decl
)) != METHOD_TYPE
))
1765 /* bunch of friends. */
1768 if (DECL_IN_AGGR_P (decl
))
1770 cp_error ("`%D' already defined in the class ", decl
);
1771 return void_type_node
;
1774 finish_decl (decl
, NULL_TREE
, NULL_TREE
, 0, 0);
1776 /* If this declaration is common to another declaration
1777 complain about such redundancy, and return NULL_TREE
1778 so that we don't build a circular list. */
1779 if (DECL_CHAIN (decl
))
1781 cp_error ("function `%D' declared twice in class %T", decl
,
1782 DECL_CONTEXT (decl
));
1785 DECL_IN_AGGR_P (decl
) = 1;
1791 grokoptypename (declspecs
, declarator
)
1792 tree declspecs
, declarator
;
1794 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1795 return build_typename_overload (t
);
1798 /* When a function is declared with an initializer,
1799 do the right thing. Currently, there are two possibilities:
1804 // initialization possibility #1.
1805 virtual void f () = 0;
1827 // initialization possibility #2
1834 copy_assignment_arg_p (parmtype
, virtualp
)
1838 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1839 parmtype
= TREE_TYPE (parmtype
);
1841 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1842 || (virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
)))
1849 grok_function_init (decl
, init
)
1853 /* An initializer for a function tells how this function should
1855 tree type
= TREE_TYPE (decl
);
1857 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1858 cp_error ("initializer specified for non-member function `%D'", decl
);
1859 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1860 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1861 else if (integer_zerop (init
))
1864 /* Mark this function as being "defined". */
1865 DECL_INITIAL (decl
) = error_mark_node
;
1866 /* pure virtual destructors must be defined. */
1867 /* pure virtual needs to be defined (as abort) only when put in
1868 vtbl. For wellformed call, it should be itself. pr4737 */
1869 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1871 extern tree abort_fndecl
;
1872 /* Give this node rtl from `abort'. */
1873 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1876 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1877 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1880 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1882 if (copy_assignment_arg_p (parmtype
, 1))
1883 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1886 else if (TREE_CODE (init
) == OFFSET_REF
1887 && TREE_OPERAND (init
, 0) == NULL_TREE
1888 && TREE_CODE (TREE_TYPE (init
)) == METHOD_TYPE
)
1890 tree basetype
= DECL_CLASS_CONTEXT (init
);
1891 tree basefn
= TREE_OPERAND (init
, 1);
1892 if (TREE_CODE (basefn
) != FUNCTION_DECL
)
1893 cp_error ("non-method initializer invalid for method `%D'", decl
);
1894 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn
))))
1895 sorry ("base member function from other than first base class");
1898 tree binfo
= get_binfo (basetype
, TYPE_METHOD_BASETYPE (type
), 1);
1899 if (binfo
== error_mark_node
)
1901 else if (binfo
== 0)
1902 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init
)),
1903 TYPE_METHOD_BASETYPE (type
));
1906 /* Mark this function as being defined,
1907 and give it new rtl. */
1908 DECL_INITIAL (decl
) = error_mark_node
;
1909 DECL_RTL (decl
) = DECL_RTL (basefn
);
1914 cp_error ("invalid initializer for virtual method `%D'", decl
);
1917 /* When we get a declaration of the form
1919 type cname::fname ...
1921 the node for `cname::fname' gets built here in a special way.
1922 Namely, we push into `cname's scope. When this declaration is
1923 processed, we pop back out. */
1925 build_push_scope (cname
, name
)
1929 extern int current_class_depth
;
1933 if (cname
== error_mark_node
)
1934 return error_mark_node
;
1936 ctype
= IDENTIFIER_TYPE_VALUE (cname
);
1938 if (TREE_CODE (ctype
) == TEMPLATE_TYPE_PARM
)
1940 else if (ctype
== NULL_TREE
|| ! IS_AGGR_TYPE (ctype
))
1942 cp_error ("`%T' not defined as aggregate type", cname
);
1945 else if (IS_SIGNATURE (ctype
))
1947 error ("cannot push into signature scope, scope resolution operator ignored");
1951 rval
= build_parse_node (SCOPE_REF
, cname
, name
);
1953 /* Don't need to push the scope if we're already in it.
1954 We also don't need to push the scope for a ptr-to-member/method. */
1956 if (ctype
== current_class_type
|| TREE_CODE (name
) != IDENTIFIER_NODE
1960 /* We do need to push the scope in this case, since CTYPE helps
1961 determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;). */
1963 push_nested_class (ctype
, 3);
1964 TREE_COMPLEXITY (rval
) = current_class_depth
;
1969 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1970 tree decl
, attributes
, prefix_attributes
;
1972 if (decl
== NULL_TREE
|| decl
== void_type_node
)
1975 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1976 decl
= DECL_TEMPLATE_RESULT (decl
);
1978 decl_attributes (decl
, attributes
, prefix_attributes
);
1980 if (TREE_CODE (decl
) == TYPE_DECL
)
1981 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
1984 /* CONSTRUCTOR_NAME:
1985 Return the name for the constructor (or destructor) for the
1986 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1987 IDENTIFIER_NODE. When given a template, this routine doesn't
1988 lose the specialization. */
1990 constructor_name_full (thing
)
1993 if (TREE_CODE (thing
) == UNINSTANTIATED_P_TYPE
)
1994 return DECL_NAME (UPT_TEMPLATE (thing
));
1995 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
1997 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
1998 thing
= DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing
), 0));
2000 thing
= TYPE_NAME (thing
);
2002 if (TREE_CODE (thing
) == TYPE_DECL
2003 || (TREE_CODE (thing
) == TEMPLATE_DECL
2004 && DECL_TEMPLATE_IS_CLASS (thing
)))
2005 thing
= DECL_NAME (thing
);
2006 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
2010 /* CONSTRUCTOR_NAME:
2011 Return the name for the constructor (or destructor) for the
2012 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2013 IDENTIFIER_NODE. When given a template, return the plain
2014 unspecialized name. */
2016 constructor_name (thing
)
2020 thing
= constructor_name_full (thing
);
2021 t
= IDENTIFIER_TEMPLATE (thing
);
2024 t
= TREE_PURPOSE (t
);
2025 return DECL_NAME (t
);
2028 /* Cache the value of this class's main virtual function table pointer
2029 in a register variable. This will save one indirection if a
2030 more than one virtual function call is made this function. */
2034 extern rtx base_init_insns
;
2036 if (base_init_insns
== 0
2037 && DECL_CONSTRUCTOR_P (current_function_decl
))
2038 emit_base_init (current_class_type
, 0);
2041 /* This has something a little wrong with it.
2043 On a sun4, code like:
2048 is generated, when the below is used when -O4 is given. The delay
2049 slot it filled with an instruction that is safe, when this isn't
2059 virtual void print() { printf("xxx"); }
2071 And that is why this is disabled for now. (mrs)
2074 if ((flag_this_is_variable
& 1) == 0
2076 && current_class_type
2077 && CLASSTYPE_VSIZE (current_class_type
)
2078 && ! DECL_STATIC_FUNCTION_P (current_function_decl
))
2080 tree vfield
= build_vfield_ref (C_C_D
, current_class_type
);
2081 current_vtable_decl
= CLASSTYPE_VTBL_PTR (current_class_type
);
2082 DECL_RTL (current_vtable_decl
) = 0;
2083 DECL_INITIAL (current_vtable_decl
) = error_mark_node
;
2084 /* Have to cast the initializer, since it may have come from a
2085 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
2086 finish_decl (current_vtable_decl
, convert_force (TREE_TYPE (current_vtable_decl
), vfield
, 0), NULL_TREE
, 0, 0);
2087 current_vtable_decl
= build_indirect_ref (current_vtable_decl
, NULL_PTR
);
2091 current_vtable_decl
= NULL_TREE
;
2094 /* Record the existence of an addressable inline function. */
2096 mark_inline_for_output (decl
)
2099 decl
= DECL_MAIN_VARIANT (decl
);
2100 if (DECL_SAVED_INLINE (decl
))
2102 my_friendly_assert (TREE_PERMANENT (decl
), 363);
2103 DECL_SAVED_INLINE (decl
) = 1;
2105 if (DECL_PENDING_INLINE_INFO (decl
) != 0
2106 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
2108 struct pending_inline
*t
= pending_inlines
;
2109 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
2112 if (t
== DECL_PENDING_INLINE_INFO (decl
))
2118 t
= DECL_PENDING_INLINE_INFO (decl
);
2119 t
->next
= pending_inlines
;
2120 pending_inlines
= t
;
2122 DECL_PENDING_INLINE_INFO (decl
) = 0;
2125 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
2131 temp_name_counter
= 0;
2134 /* Hand off a unique name which can be used for variable we don't really
2135 want to know about anyway, for example, the anonymous variables which
2136 are needed to make references work. Declare this thing so we can use it.
2137 The variable created will be of type TYPE.
2139 STATICP is nonzero if this variable should be static. */
2142 get_temp_name (type
, staticp
)
2146 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2148 int toplev
= global_bindings_p ();
2150 push_obstacks_nochange ();
2151 if (toplev
|| staticp
)
2153 end_temporary_allocation ();
2154 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2155 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2159 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2160 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2162 TREE_USED (decl
) = 1;
2163 TREE_STATIC (decl
) = staticp
;
2165 /* If this is a local variable, then lay out its rtl now.
2166 Otherwise, callers of this function are responsible for dealing
2167 with this variable's rtl. */
2171 expand_decl_init (decl
);
2178 /* Get a variable which we can use for multiple assignments.
2179 It is not entered into current_binding_level, because
2180 that breaks things when it comes time to do final cleanups
2181 (which take place "outside" the binding contour of the function). */
2183 get_temp_regvar (type
, init
)
2186 static char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20] = { '_' };
2189 sprintf (buf
+1, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2190 decl
= build_decl (VAR_DECL
, get_identifier (buf
), type
);
2191 TREE_USED (decl
) = 1;
2192 DECL_REGISTER (decl
) = 1;
2195 store_init_value (decl
, init
);
2197 /* We can expand these without fear, since they cannot need
2198 constructors or destructors. */
2200 expand_decl_init (decl
);
2202 if (type_needs_gc_entry (type
))
2203 DECL_GC_OFFSET (decl
) = size_int (++current_function_obstack_index
);
2208 /* Make the macro TEMP_NAME_P available to units which do not
2209 include c-tree.h. */
2214 return TEMP_NAME_P (decl
);
2217 /* Finish off the processing of a UNION_TYPE structure.
2218 If there are static members, then all members are
2219 static, and must be laid out together. If the
2220 union is an anonymous union, we arrange for that
2221 as well. PUBLIC_P is nonzero if this union is
2222 not declared static. */
2224 finish_anon_union (anon_union_decl
)
2225 tree anon_union_decl
;
2227 tree type
= TREE_TYPE (anon_union_decl
);
2228 tree field
, main_decl
= NULL_TREE
;
2229 tree elems
= NULL_TREE
;
2230 int public_p
= TREE_PUBLIC (anon_union_decl
);
2231 int static_p
= TREE_STATIC (anon_union_decl
);
2232 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2234 if ((field
= TYPE_FIELDS (type
)) == NULL_TREE
)
2239 error ("global anonymous unions must be declared static");
2243 for (; field
; field
= TREE_CHAIN (field
))
2246 if (TREE_CODE (field
) != FIELD_DECL
)
2249 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2250 /* tell `pushdecl' that this is not tentative. */
2251 DECL_INITIAL (decl
) = error_mark_node
;
2252 TREE_PUBLIC (decl
) = public_p
;
2253 TREE_STATIC (decl
) = static_p
;
2254 DECL_EXTERNAL (decl
) = external_p
;
2255 decl
= pushdecl (decl
);
2257 /* Only write out one anon union element--choose the one that
2258 can hold them all. */
2259 if (main_decl
== NULL_TREE
2260 && simple_cst_equal (DECL_SIZE (decl
), DECL_SIZE (anon_union_decl
)))
2266 /* ??? This causes there to be no debug info written out
2268 TREE_ASM_WRITTEN (decl
) = 1;
2271 DECL_INITIAL (decl
) = NULL_TREE
;
2272 /* If there's a cleanup to do, it belongs in the
2273 TREE_PURPOSE of the following TREE_LIST. */
2274 elems
= tree_cons (NULL_TREE
, decl
, elems
);
2275 TREE_TYPE (elems
) = type
;
2281 make_decl_rtl (main_decl
, 0, global_bindings_p ());
2282 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2286 warning ("anonymous union with no members");
2291 /* The following call assumes that there are never any cleanups
2292 for anonymous unions--a reasonable assumption. */
2293 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2296 cadillac_finish_anon_union (anon_union_decl
);
2299 /* Finish and output a table which is generated by the compiler.
2300 NAME is the name to give the table.
2301 TYPE is the type of the table entry.
2302 INIT is all the elements in the table.
2303 PUBLICP is non-zero if this table should be given external access. */
2305 finish_table (name
, type
, init
, publicp
)
2306 tree name
, type
, init
;
2309 tree itype
, atype
, decl
;
2310 static tree empty_table
;
2314 itype
= build_index_type (size_int (list_length (init
) - 1));
2315 atype
= build_cplus_array_type (type
, itype
);
2316 layout_type (atype
);
2318 if (TREE_VALUE (init
) == integer_zero_node
2319 && TREE_CHAIN (init
) == NULL_TREE
)
2322 if (empty_table
== NULL_TREE
)
2325 empty_table
= get_temp_name (atype
, 1);
2326 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2327 TREE_CONSTANT (init
) = 1;
2328 TREE_STATIC (init
) = 1;
2329 DECL_INITIAL (empty_table
) = init
;
2330 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2331 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2332 finish_decl (empty_table
, NULL_TREE
, asmspec
, 0, 0);
2337 if (name
== NULL_TREE
)
2341 decl
= get_temp_name (atype
, 1);
2345 decl
= build_decl (VAR_DECL
, name
, atype
);
2346 decl
= pushdecl (decl
);
2347 TREE_STATIC (decl
) = 1;
2352 TREE_PUBLIC (decl
) = publicp
;
2353 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2354 TREE_CONSTANT (init
) = 1;
2355 TREE_STATIC (init
) = 1;
2356 DECL_INITIAL (decl
) = init
;
2357 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (decl
)),
2358 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2362 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2363 DECL_EXTERNAL (decl
) = 1;
2364 TREE_STATIC (decl
) = 0;
2366 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2367 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2370 finish_decl (decl
, NULL_TREE
, asmspec
, 0, 0);
2374 /* Finish processing a builtin type TYPE. It's name is NAME,
2375 its fields are in the array FIELDS. LEN is the number of elements
2376 in FIELDS minus one, or put another way, it is the maximum subscript
2379 It is given the same alignment as ALIGN_TYPE. */
2381 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2390 TYPE_FIELDS (type
) = fields
[0];
2391 for (i
= 0; i
< len
; i
++)
2393 layout_type (TREE_TYPE (fields
[i
]));
2394 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2395 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2397 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2398 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2399 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2401 #if 0 /* not yet, should get fixed properly later */
2402 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2404 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2406 layout_decl (TYPE_NAME (type
), 0);
2409 /* Auxiliary functions to make type signatures for
2410 `operator new' and `operator delete' correspond to
2411 what compiler will be expecting. */
2413 extern tree sizetype
;
2416 coerce_new_type (type
)
2421 if (TREE_CODE (type
) == METHOD_TYPE
)
2422 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2423 if (TREE_TYPE (type
) != ptr_type_node
)
2424 e1
= 1, error ("`operator new' must return type `void *'");
2426 /* Technically the type must be `size_t', but we may not know
2428 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2429 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2430 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type
))) != INTEGER_TYPE
2431 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type
))) != TYPE_PRECISION (sizetype
))
2432 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2434 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2436 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2441 coerce_delete_type (type
)
2444 int e1
= 0, e2
= 0, e3
= 0;
2445 tree arg_types
= TYPE_ARG_TYPES (type
);
2447 if (TREE_CODE (type
) == METHOD_TYPE
)
2449 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2450 arg_types
= TREE_CHAIN (arg_types
);
2452 if (TREE_TYPE (type
) != void_type_node
)
2453 e1
= 1, error ("`operator delete' must return type `void'");
2454 if (arg_types
== NULL_TREE
2455 || TREE_VALUE (arg_types
) != ptr_type_node
)
2456 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2459 && TREE_CHAIN (arg_types
)
2460 && TREE_CHAIN (arg_types
) != void_list_node
)
2462 /* Again, technically this argument must be `size_t', but again
2463 we may not know what that is. */
2464 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2465 if (TREE_CODE (t2
) != INTEGER_TYPE
2466 || TYPE_PRECISION (t2
) != TYPE_PRECISION (sizetype
))
2467 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2468 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2471 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2472 error ("too many arguments in declaration of `operator delete'");
2474 error ("`...' invalid in specification of `operator delete'");
2478 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, build_tree_list (NULL_TREE
, sizetype
));
2481 if (arg_types
== NULL_TREE
)
2482 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2484 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2489 type
= build_function_type (void_type_node
, arg_types
);
2495 mark_vtable_entries (decl
)
2498 tree entries
= TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl
)));
2500 for (; entries
; entries
= TREE_CHAIN (entries
))
2502 tree fnaddr
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
));
2503 tree fn
= TREE_OPERAND (fnaddr
, 0);
2504 TREE_ADDRESSABLE (fn
) = 1;
2505 if (DECL_ABSTRACT_VIRTUAL_P (fn
))
2507 extern tree abort_fndecl
;
2508 if (flag_vtable_thunks
)
2509 fnaddr
= TREE_VALUE (entries
);
2510 TREE_OPERAND (fnaddr
, 0) = fn
= abort_fndecl
;
2512 assemble_external (fn
);
2516 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2517 based on TYPE and other static flags.
2519 Note that anything public is tagged TREE_PUBLIC, whether
2520 it's public in this file or in another one. */
2523 import_export_vtable (decl
, type
, final
)
2527 if (DECL_INTERFACE_KNOWN (decl
))
2531 if (write_virtuals
< 2 && write_virtuals
!= 0)
2533 TREE_PUBLIC (decl
) = 1;
2534 if (write_virtuals
< 0)
2535 DECL_EXTERNAL (decl
) = 1;
2536 DECL_INTERFACE_KNOWN (decl
) = 1;
2538 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2540 TREE_PUBLIC (decl
) = 1;
2541 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2542 DECL_INTERFACE_KNOWN (decl
) = 1;
2546 /* We can only wait to decide if we have real non-inline virtual
2547 functions in our class, or if we come from a template. */
2549 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2551 if (! found
&& ! final
)
2554 for (method
= CLASSTYPE_METHODS (type
); method
!= NULL_TREE
;
2555 method
= DECL_NEXT_METHOD (method
))
2556 if (DECL_VINDEX (method
) != NULL_TREE
2557 && ! DECL_THIS_INLINE (method
)
2558 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2565 if (final
|| ! found
)
2567 #ifdef ASSEMBLE_EXTERNAL
2568 if (TREE_PUBLIC (decl
))
2569 cp_error ("all virtual functions redeclared inline");
2571 TREE_PUBLIC (decl
) = 0;
2572 DECL_EXTERNAL (decl
) = 0;
2576 TREE_PUBLIC (decl
) = 1;
2577 DECL_EXTERNAL (decl
) = 1;
2583 import_export_template (type
)
2586 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type
)
2587 && ! flag_implicit_templates
2588 && CLASSTYPE_INTERFACE_UNKNOWN (type
))
2590 SET_CLASSTYPE_INTERFACE_KNOWN (type
);
2591 CLASSTYPE_INTERFACE_ONLY (type
) = 1;
2592 CLASSTYPE_VTABLE_NEEDS_WRITING (type
) = 0;
2597 finish_prevtable_vardecl (prev
, vars
)
2600 tree ctype
= DECL_CONTEXT (vars
);
2601 import_export_template (ctype
);
2603 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype
) && TYPE_VIRTUAL_P (ctype
)
2604 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2607 for (method
= CLASSTYPE_METHODS (ctype
); method
!= NULL_TREE
;
2608 method
= DECL_NEXT_METHOD (method
))
2610 if (DECL_VINDEX (method
) != NULL_TREE
2611 && !DECL_THIS_INLINE (method
)
2612 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2614 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2615 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
) = ! DECL_EXTERNAL (method
);
2616 CLASSTYPE_INTERFACE_ONLY (ctype
) = DECL_EXTERNAL (method
);
2622 import_export_vtable (vars
, ctype
, 1);
2624 /* We cannot use TREE_USED here, as it may be set by the expanding of a
2625 ctor that is used to build a global object. The long term plan is to
2626 make the TD entries statically initialized and move this to
2627 finish_vtable_vardecl time. */
2628 if (flag_rtti
&& write_virtuals
>= 0
2629 && ! DECL_EXTERNAL (vars
) && (TREE_PUBLIC (vars
) || 1 || TREE_USED (vars
)))
2631 /* Kick out the type descriptor before we dump out global
2632 initializers, as they are initialized at run time and
2633 we have to find them when we scan for things that need initialized
2634 at the top level. */
2635 build_t_desc (ctype
, 1);
2640 finish_vtable_vardecl (prev
, vars
)
2643 if (write_virtuals
>= 0
2644 && ! DECL_EXTERNAL (vars
) && (TREE_PUBLIC (vars
) || TREE_USED (vars
)))
2647 /* The long term plan it to make the TD entries statically initialized,
2648 have the entries built and emitted here. When that happens, this
2649 can be enabled, and the other call to build_t_desc removed. */
2650 /* Kick out the type descriptor before writing out the vtable. */
2652 build_t_desc (DECL_CONTEXT (vars
), 1);
2656 mark_vtable_entries (vars
);
2657 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2658 store_init_value (vars
, DECL_INITIAL (vars
));
2660 #ifdef DWARF_DEBUGGING_INFO
2661 if (write_symbols
== DWARF_DEBUG
)
2663 /* Mark the VAR_DECL node representing the vtable itself as a
2664 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2665 It is rather important that such things be ignored because
2666 any effort to actually generate DWARF for them will run
2667 into trouble when/if we encounter code like:
2670 struct S { virtual void member (); };
2672 because the artificial declaration of the vtable itself (as
2673 manufactured by the g++ front end) will say that the vtable
2674 is a static member of `S' but only *after* the debug output
2675 for the definition of `S' has already been output. This causes
2676 grief because the DWARF entry for the definition of the vtable
2677 will try to refer back to an earlier *declaration* of the
2678 vtable as a static member of `S' and there won't be one.
2679 We might be able to arrange to have the "vtable static member"
2680 attached to the member list for `S' before the debug info for
2681 `S' get written (which would solve the problem) but that would
2682 require more intrusive changes to the g++ front end. */
2684 DECL_IGNORED_P (vars
) = 1;
2686 #endif /* DWARF_DEBUGGING_INFO */
2688 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2690 else if (! TREE_USED (vars
))
2691 /* We don't know what to do with this one yet. */
2694 /* We know that PREV must be non-zero here. */
2695 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2699 prune_vtable_vardecl (prev
, vars
)
2702 /* We know that PREV must be non-zero here. */
2703 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2707 walk_vtables (typedecl_fn
, vardecl_fn
)
2708 register void (*typedecl_fn
)();
2709 register void (*vardecl_fn
)();
2713 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2715 register tree type
= TREE_TYPE (vars
);
2717 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2719 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2721 if (prev
&& TREE_CHAIN (prev
) != vars
)
2724 else if (TREE_CODE (vars
) == TYPE_DECL
2725 && type
!= error_mark_node
2726 && TYPE_LANG_SPECIFIC (type
)
2727 && CLASSTYPE_VSIZE (type
))
2729 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2737 finish_sigtable_vardecl (prev
, vars
)
2740 /* We don't need to mark sigtable entries as addressable here as is done
2741 for vtables. Since sigtables, unlike vtables, are always written out,
2742 that was already done in build_signature_table_constructor. */
2744 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2746 /* We know that PREV must be non-zero here. */
2747 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2751 walk_sigtables (typedecl_fn
, vardecl_fn
)
2752 register void (*typedecl_fn
)();
2753 register void (*vardecl_fn
)();
2757 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2759 register tree type
= TREE_TYPE (vars
);
2761 if (TREE_CODE (vars
) == TYPE_DECL
2762 && type
!= error_mark_node
2763 && IS_SIGNATURE (type
))
2765 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2767 else if (TREE_CODE (vars
) == VAR_DECL
2768 && TREE_TYPE (vars
) != error_mark_node
2769 && IS_SIGNATURE (TREE_TYPE (vars
)))
2771 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2778 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2779 inline function at end-of-file. */
2782 import_export_inline (decl
)
2785 if (DECL_INTERFACE_KNOWN (decl
))
2788 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2790 if (DECL_IMPLICIT_INSTANTIATION (decl
) && flag_implicit_templates
)
2791 TREE_PUBLIC (decl
) = 0;
2793 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2795 else if (DECL_FUNCTION_MEMBER_P (decl
))
2797 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2798 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2800 DECL_NOT_REALLY_EXTERN (decl
)
2801 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2802 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2805 TREE_PUBLIC (decl
) = 0;
2808 TREE_PUBLIC (decl
) = 0;
2810 DECL_INTERFACE_KNOWN (decl
) = 1;
2813 extern int parse_time
, varconst_time
;
2815 #define TIMEVAR(VAR, BODY) \
2816 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2818 /* This routine is called from the last rule in yyparse ().
2819 Its job is to create all the code needed to initialize and
2820 destroy the global aggregates. We do the destruction
2821 first, since that way we only need to reverse the decls once. */
2827 int start_time
, this_time
;
2831 int needs_cleaning
= 0, needs_messing_up
= 0;
2833 if (flag_detailed_statistics
)
2834 dump_tree_statistics ();
2836 /* Bad parse errors. Just forget about it. */
2837 if (! global_bindings_p () || current_class_type
)
2840 start_time
= get_run_time ();
2842 /* Push into C language context, because that's all
2844 push_lang_context (lang_name_c
);
2846 /* Otherwise, GDB can get confused, because in only knows
2847 about source for LINENO-1 lines. */
2850 interface_unknown
= 1;
2854 /* The reason for pushing garbage onto the global_binding_level is to
2855 ensure that we can slice out _DECLs which pertain to virtual function
2856 tables. If the last thing pushed onto the global_binding_level was a
2857 virtual function table, then slicing it out would slice away all the
2858 decls (i.e., we lose the head of the chain).
2860 There are several ways of getting the same effect, from changing the
2861 way that iterators over the chain treat the elements that pertain to
2862 virtual function tables, moving the implementation of this code to
2863 decl.c (where we can manipulate global_binding_level directly),
2864 popping the garbage after pushing it and slicing away the vtable
2865 stuff, or just leaving it alone. */
2867 /* Make last thing in global scope not be a virtual function table. */
2868 #if 0 /* not yet, should get fixed properly later */
2869 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
2871 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
2873 DECL_IGNORED_P (vars
) = 1;
2874 SET_DECL_ARTIFICIAL (vars
);
2878 /* Walk to mark the inline functions we need, then output them so
2879 that we can pick up any other tdecls that those routines need. */
2880 walk_vtables ((void (*)())0, finish_prevtable_vardecl
);
2882 vars
= static_aggregates
;
2884 if (static_ctors
|| vars
|| might_have_exceptions_p ())
2885 needs_messing_up
= 1;
2889 /* See if we really need the hassle. */
2890 while (vars
&& needs_cleaning
== 0)
2892 tree decl
= TREE_VALUE (vars
);
2893 tree type
= TREE_TYPE (decl
);
2894 if (TYPE_NEEDS_DESTRUCTOR (type
))
2897 needs_messing_up
= 1;
2901 needs_messing_up
|= TYPE_NEEDS_CONSTRUCTING (type
);
2902 vars
= TREE_CHAIN (vars
);
2905 if (needs_cleaning
== 0)
2908 fnname
= get_file_function_name ('D');
2909 start_function (void_list_node
, build_parse_node (CALL_EXPR
, fnname
, void_list_node
, NULL_TREE
), 0, 0);
2910 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2911 store_parm_decls ();
2916 expand_start_bindings (0);
2918 /* These must be done in backward order to destroy,
2919 in which they happen to be! */
2920 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
2922 tree decl
= TREE_VALUE (vars
);
2923 tree type
= TREE_TYPE (decl
);
2924 tree temp
= TREE_PURPOSE (vars
);
2926 if (TYPE_NEEDS_DESTRUCTOR (type
))
2928 if (TREE_STATIC (vars
))
2929 expand_start_cond (build_binary_op (NE_EXPR
, temp
, integer_zero_node
, 1), 0);
2930 if (TREE_CODE (type
) == ARRAY_TYPE
)
2934 mark_addressable (decl
);
2935 temp
= build1 (ADDR_EXPR
, TYPE_POINTER_TO (type
), decl
);
2937 temp
= build_delete (TREE_TYPE (temp
), temp
,
2938 integer_two_node
, LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2939 expand_expr_stmt (temp
);
2941 if (TREE_STATIC (vars
))
2946 for (; static_dtors
; static_dtors
= TREE_CHAIN (static_dtors
))
2947 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors
),
2950 expand_end_bindings (getdecls(), 1, 0);
2954 finish_function (lineno
, 0, 0);
2956 assemble_destructor (IDENTIFIER_POINTER (fnname
));
2958 /* if it needed cleaning, then it will need messing up: drop through */
2961 /* Must do this while we think we are at the top level. */
2962 vars
= nreverse (static_aggregates
);
2963 if (needs_messing_up
)
2965 fnname
= get_file_function_name ('I');
2966 start_function (void_list_node
, build_parse_node (CALL_EXPR
, fnname
, void_list_node
, NULL_TREE
), 0, 0);
2967 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2968 store_parm_decls ();
2973 expand_start_bindings (0);
2975 if (might_have_exceptions_p ())
2976 register_exception_table ();
2980 tree decl
= TREE_VALUE (vars
);
2981 tree init
= TREE_PURPOSE (vars
);
2982 tree old_cleanups
= cleanups_this_call
;
2984 /* If this was a static attribute within some function's scope,
2985 then don't initialize it here. Also, don't bother
2986 with initializers that contain errors. */
2987 if (TREE_STATIC (vars
)
2988 || (init
&& TREE_CODE (init
) == TREE_LIST
2989 && value_member (error_mark_node
, init
)))
2991 vars
= TREE_CHAIN (vars
);
2995 if (TREE_CODE (decl
) == VAR_DECL
)
2997 /* Set these global variables so that GDB at least puts
2998 us near the declaration which required the initialization. */
2999 input_filename
= DECL_SOURCE_FILE (decl
);
3000 lineno
= DECL_SOURCE_LINE (decl
);
3001 emit_note (input_filename
, lineno
);
3003 /* 9.5p5: The initializer of a static member of a class has
3004 the same acess rights as a member function. */
3005 DECL_CLASS_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
3006 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3011 if (TREE_CODE (init
) == VAR_DECL
)
3013 /* This behavior results when there are
3014 multiple declarations of an aggregate,
3015 the last of which defines it. */
3016 if (DECL_RTL (init
) == DECL_RTL (decl
))
3018 my_friendly_assert (DECL_INITIAL (decl
) == error_mark_node
3019 || (TREE_CODE (DECL_INITIAL (decl
)) == CONSTRUCTOR
3020 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl
)) == NULL_TREE
),
3022 init
= DECL_INITIAL (init
);
3023 if (TREE_CODE (init
) == CONSTRUCTOR
3024 && CONSTRUCTOR_ELTS (init
) == NULL_TREE
)
3027 else if (TREE_TYPE (decl
) == TREE_TYPE (init
))
3030 my_friendly_abort (200);
3032 /* point to real decl's rtl anyway. */
3033 DECL_RTL (init
) = DECL_RTL (decl
);
3034 my_friendly_assert (DECL_INITIAL (decl
) == error_mark_node
,
3036 init
= DECL_INITIAL (init
);
3042 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3043 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3044 expand_aggr_init (decl
, init
, 0, 0);
3045 else if (TREE_CODE (init
) == TREE_VEC
)
3047 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3048 TREE_VEC_ELT (init
, 1),
3049 TREE_VEC_ELT (init
, 2), 0),
3050 const0_rtx
, VOIDmode
, 0);
3054 expand_assignment (decl
, init
, 0, 0);
3056 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3058 else if (TREE_CODE (decl
) == SAVE_EXPR
)
3060 if (! PARM_DECL_EXPR (decl
))
3062 /* a `new' expression at top level. */
3063 expand_expr (decl
, const0_rtx
, VOIDmode
, 0);
3065 expand_aggr_init (build_indirect_ref (decl
, NULL_PTR
), init
, 0, 0);
3068 else if (decl
== error_mark_node
)
3070 else my_friendly_abort (22);
3071 vars
= TREE_CHAIN (vars
);
3072 /* Cleanup any temporaries needed for the initial value. */
3073 expand_cleanups_to (old_cleanups
);
3076 for (; static_ctors
; static_ctors
= TREE_CHAIN (static_ctors
))
3077 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors
),
3080 expand_end_bindings (getdecls(), 1, 0);
3084 finish_function (lineno
, 0, 0);
3085 assemble_constructor (IDENTIFIER_POINTER (fnname
));
3088 permanent_allocation (1);
3090 /* Done with C language context needs. */
3091 pop_lang_context ();
3093 /* Now write out any static class variables (which may have since
3094 learned how to be initialized). */
3095 while (pending_statics
)
3097 tree decl
= TREE_VALUE (pending_statics
);
3098 if (TREE_USED (decl
) == 1
3099 || TREE_READONLY (decl
) == 0
3100 || DECL_INITIAL (decl
) == 0)
3101 rest_of_decl_compilation (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3102 pending_statics
= TREE_CHAIN (pending_statics
);
3105 this_time
= get_run_time ();
3106 parse_time
-= this_time
- start_time
;
3107 varconst_time
+= this_time
- start_time
;
3109 start_time
= get_run_time ();
3111 if (flag_handle_signatures
)
3112 walk_sigtables ((void (*)())0, finish_sigtable_vardecl
);
3114 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3116 tree decl
= TREE_VALUE (fnname
);
3117 import_export_inline (decl
);
3118 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3119 && TREE_PUBLIC (decl
) && DECL_NOT_REALLY_EXTERN (decl
))
3120 synthesize_method (decl
);
3123 /* Now write out inline functions which had their addresses taken and
3124 which were not declared virtual and which were not declared `extern
3127 int reconsider
= 1; /* More may be referenced; check again */
3131 tree last
= saved_inlines
= tree_cons (NULL_TREE
, NULL_TREE
,
3133 tree last_head
= last
;
3134 tree place
= TREE_CHAIN (saved_inlines
);
3137 walk_vtables ((void (*)())0, finish_vtable_vardecl
);
3139 for (; place
; place
= TREE_CHAIN (place
))
3141 tree decl
= TREE_VALUE (place
);
3143 /* Slice out the empty elements put in just above in the
3144 previous reconsidering. */
3145 if (decl
== NULL_TREE
)
3147 TREE_CHAIN (last
) = TREE_CHAIN (place
);
3151 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
))
3153 if (TREE_USED (decl
))
3155 synthesize_method (decl
);
3156 if (TREE_ASM_WRITTEN (decl
))
3166 if (TREE_ASM_WRITTEN (decl
) || DECL_SAVED_INSNS (decl
) == 0)
3168 TREE_CHAIN (last
) = TREE_CHAIN (place
);
3172 if (TREE_PUBLIC (decl
)
3173 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3174 || flag_keep_inline_functions
)
3176 TREE_CHAIN (last
) = TREE_CHAIN (place
);
3178 if (DECL_NOT_REALLY_EXTERN (decl
))
3180 DECL_EXTERNAL (decl
) = 0;
3182 temporary_allocation ();
3183 output_inline_function (decl
);
3184 permanent_allocation (1);
3195 /* Now delete from the chain of variables all virtual function tables.
3196 We output them all ourselves, because each will be treated specially. */
3198 walk_vtables ((void (*)())0, prune_vtable_vardecl
);
3200 for (vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
3202 if (TREE_CODE (vars
) == THUNK_DECL
)
3204 else if (TREE_CODE (vars
) == FUNCTION_DECL
3205 && ! DECL_INTERFACE_KNOWN (vars
)
3206 && DECL_C_STATIC (vars
))
3207 TREE_PUBLIC (vars
) = 0;
3210 if (might_have_exceptions_p ())
3211 emit_exception_table ();
3213 if (write_virtuals
== 2)
3215 /* Now complain about an virtual function tables promised
3216 but not delivered. */
3217 while (pending_vtables
)
3219 if (TREE_PURPOSE (pending_vtables
) == NULL_TREE
)
3220 error ("virtual function table for `%s' not defined",
3221 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables
)));
3222 pending_vtables
= TREE_CHAIN (pending_vtables
);
3228 this_time
= get_run_time ();
3229 parse_time
-= this_time
- start_time
;
3230 varconst_time
+= this_time
- start_time
;
3232 if (flag_detailed_statistics
)
3233 dump_time_statistics ();
3236 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3237 expr. Since it was parsed like a type, we need to wade through and fix
3238 that. Unfortunately, since operator() is left-associative, we can't use
3239 tail recursion. In the above example, TYPE is `A', and DECL is
3242 Maybe this shouldn't be recursive, but how often will it actually be
3245 reparse_absdcl_as_expr (type
, decl
)
3248 /* do build_functional_cast (type, NULL_TREE) at bottom */
3249 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3250 return build_functional_cast (type
, NULL_TREE
);
3253 decl
= reparse_decl_as_expr (type
, TREE_OPERAND (decl
, 0));
3255 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_decl
);
3257 if (TREE_CODE (decl
) == CALL_EXPR
&& TREE_TYPE (decl
) != void_type_node
)
3258 decl
= require_complete_type (decl
);
3263 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3264 out to be an expr. Since it was parsed like a type, we need to wade
3265 through and fix that. Since casts are right-associative, we are
3266 reversing the order, so we don't have to recurse.
3268 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3271 reparse_absdcl_as_casts (decl
, expr
)
3276 if (TREE_CODE (expr
) == CONSTRUCTOR
)
3278 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3279 decl
= TREE_OPERAND (decl
, 0);
3281 if (IS_SIGNATURE (type
))
3283 error ("cast specifies signature type");
3284 return error_mark_node
;
3287 expr
= digest_init (type
, expr
, (tree
*) 0);
3288 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3290 int failure
= complete_array_type (type
, expr
, 1);
3292 my_friendly_abort (78);
3298 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3299 decl
= TREE_OPERAND (decl
, 0);
3300 expr
= build_c_cast (type
, expr
, 0);
3306 /* Recursive helper function for reparse_decl_as_expr. It may be a good
3307 idea to reimplement this using an explicit stack, rather than recursion. */
3309 reparse_decl_as_expr1 (decl
)
3312 switch (TREE_CODE (decl
))
3314 case IDENTIFIER_NODE
:
3315 return do_identifier (decl
);
3317 return build_x_indirect_ref
3318 (reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)), "unary *");
3320 return build_x_unary_op (ADDR_EXPR
,
3321 reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)));
3323 return build_x_unary_op (BIT_NOT_EXPR
,
3324 reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)));
3326 return build_offset_ref (TREE_OPERAND (decl
, 0), TREE_OPERAND (decl
, 1));
3328 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)),
3329 TREE_OPERAND (decl
, 1));
3331 my_friendly_abort (5);
3336 /* This is something of the form `int (*a)++' that has turned out to be an
3337 expr. It was only converted into parse nodes, so we need to go through
3338 and build up the semantics. Most of the work is done by
3339 reparse_decl_as_expr1, above.
3341 In the above example, TYPE is `int' and DECL is `*a'. */
3343 reparse_decl_as_expr (type
, decl
)
3346 decl
= reparse_decl_as_expr1 (decl
);
3348 return build_functional_cast (type
, build_tree_list (NULL_TREE
, decl
));
3353 /* This is something of the form `int (*a)' that has turned out to be a
3354 decl. It was only converted into parse nodes, so we need to do the
3355 checking that make_{pointer,reference}_declarator do. */
3358 finish_decl_parsing (decl
)
3361 extern int current_class_depth
;
3363 switch (TREE_CODE (decl
))
3365 case IDENTIFIER_NODE
:
3368 return make_pointer_declarator
3369 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3371 return make_reference_declarator
3372 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3374 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3377 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3378 TREE_COMPLEXITY (decl
) = current_class_depth
;
3381 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3384 my_friendly_abort (5);
3390 check_cp_case_value (value
)
3393 if (value
== NULL_TREE
)
3396 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3397 Strip such NOP_EXPRs. */
3398 if (TREE_CODE (value
) == NOP_EXPR
3399 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
3400 value
= TREE_OPERAND (value
, 0);
3402 if (TREE_READONLY_DECL_P (value
))
3404 value
= decl_constant_value (value
);
3405 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3406 Strip such NOP_EXPRs. */
3407 if (TREE_CODE (value
) == NOP_EXPR
3408 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
3409 value
= TREE_OPERAND (value
, 0);
3411 value
= fold (value
);
3413 if (TREE_CODE (value
) != INTEGER_CST
3414 && value
!= error_mark_node
)
3416 cp_error ("case label `%E' does not reduce to an integer constant",
3418 value
= error_mark_node
;
3421 /* Promote char or short to int. */
3422 value
= default_conversion (value
);
3424 constant_expression_warning (value
);
3429 static tree current_namespace
;
3431 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3432 postfix. Returns 0 if in global namespace. */
3436 tree x
= current_namespace
;
3438 x
= TREE_PURPOSE (x
);
3442 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3444 current_namespace_id (name
)
3447 tree old_id
= get_namespace_id ();
3450 /* Global names retain old encoding. */
3454 buf
= (char *) alloca (8 + IDENTIFIER_LENGTH (old_id
)
3455 + IDENTIFIER_LENGTH (name
));
3456 sprintf (buf
, "__ns_%s_%s", IDENTIFIER_POINTER (old_id
),
3457 IDENTIFIER_POINTER (name
));
3458 return get_identifier (buf
);
3461 /* Push into the scopre of the NAME namespace. */
3463 push_namespace (name
)
3466 tree old_id
= get_namespace_id ();
3469 current_namespace
= tree_cons (NULL_TREE
, name
, current_namespace
);
3470 buf
= (char *) alloca (4 + (old_id
? IDENTIFIER_LENGTH (old_id
) : 0)
3471 + IDENTIFIER_LENGTH (name
));
3472 sprintf (buf
, "%s%s", old_id
? IDENTIFIER_POINTER (old_id
) : "",
3473 IDENTIFIER_POINTER (name
));
3474 TREE_PURPOSE (current_namespace
) = get_identifier (buf
);
3477 /* Pop from the scope of the current namespace. */
3481 current_namespace
= TREE_CHAIN (current_namespace
);
3485 do_namespace_alias (alias
, namespace)
3486 tree alias
, namespace;
3491 do_using_decl (decl
)
3494 return error_mark_node
;
3498 do_using_directive (namespace)