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. */
38 extern tree
grokdeclarator ();
39 extern tree
get_file_function_name ();
40 extern tree cleanups_this_call
;
41 static void grok_function_init ();
43 /* A list of virtual function tables we must make sure to write out. */
46 /* A list of static class variables. This is needed, because a
47 static class variable can be declared inside the class without
48 an initializer, and then initialized, staticly, outside the class. */
51 /* A list of functions which were declared inline, but which we
52 may need to emit outline anyway. */
53 static tree saved_inlines
;
55 /* Used to help generate temporary names which are unique within
56 a function. Reset to 0 by start_function. */
58 int temp_name_counter
;
60 /* Same, but not reset. Local temp variables and global temp variables
61 can have the same name. */
62 static int global_temp_name_counter
;
64 /* Flag used when debugging spew.c */
66 extern int spew_debug
;
68 /* Functions called along with real static constructors and destructors. */
70 tree static_ctors
, static_dtors
;
72 /* C (and C++) language-specific option variables. */
74 /* Nonzero means allow type mismatches in conditional expressions;
75 just make their values `void'. */
77 int flag_cond_mismatch
;
79 /* Nonzero means give `double' the same size as `float'. */
81 int flag_short_double
;
83 /* Nonzero means don't recognize the keyword `asm'. */
87 /* Nonzero means don't recognize any extension keywords. */
89 int flag_no_gnu_keywords
;
91 /* Nonzero means don't recognize the non-ANSI builtin functions. */
95 /* Nonzero means don't recognize the non-ANSI builtin functions.
98 int flag_no_nonansi_builtin
;
100 /* Nonzero means do some things the same way PCC does. */
102 int flag_traditional
;
104 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
106 int flag_signed_bitfields
= 1;
108 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
112 /* Nonzero means enable obscure ANSI features and disable GNU extensions
113 that might cause ANSI-compliant code to be miscompiled. */
117 /* Nonzero means do emit exported implementations of functions even if
118 they can be inlined. */
120 int flag_implement_inlines
= 1;
122 /* Nonzero means do emit exported implementations of templates, instead of
123 multiple static copies in each file that needs a definition. */
125 int flag_external_templates
;
127 /* Nonzero means that the decision to emit or not emit the implementation of a
128 template depends on where the template is instantiated, rather than where
131 int flag_alt_external_templates
;
133 /* Nonzero means that implicit instantiations will be emitted if needed. */
135 int flag_implicit_templates
= 1;
137 /* Nonzero means warn about implicit declarations. */
139 int warn_implicit
= 1;
141 /* Nonzero means warn when all ctors or dtors are private, and the class
144 int warn_ctor_dtor_privacy
= 1;
146 /* True if we want to implement vtbvales using "thunks".
147 The default is off now, but will be on later. */
149 int flag_vtable_thunks
;
151 /* Nonzero means give string constants the type `const char *'
152 to get extra warnings from them. These warnings will be too numerous
153 to be useful, except in thoroughly ANSIfied programs. */
155 int warn_write_strings
;
157 /* Nonzero means warn about pointer casts that can drop a type qualifier
158 from the pointer target type. */
162 /* Nonzero means warn that dbx info for template class methods isn't fully
165 int warn_template_debugging
;
167 /* Warn about traditional constructs whose meanings changed in ANSI C. */
169 int warn_traditional
;
171 /* Nonzero means warn about sizeof(function) or addition/subtraction
172 of function pointers. */
174 int warn_pointer_arith
;
176 /* Nonzero means warn for non-prototype function decls
177 or non-prototyped defs without previous prototype. */
179 int warn_strict_prototypes
;
181 /* Nonzero means warn for any function def without prototype decl. */
183 int warn_missing_prototypes
;
185 /* Nonzero means warn about multiple (redundant) decls for the same single
186 variable or function. */
188 int warn_redundant_decls
;
190 /* Warn if initializer is not completely bracketed. */
192 int warn_missing_braces
;
194 /* Warn about *printf or *scanf format/argument anomalies. */
198 /* Warn about a subscript that has type char. */
200 int warn_char_subscripts
;
202 /* Warn if a type conversion is done that might have confusing results. */
206 /* Warn if adding () is suggested. */
208 int warn_parentheses
;
210 /* Non-zero means warn in function declared in derived class has the
211 same name as a virtual in the base class, but fails to match the
212 type signature of any virtual function in the base class. */
213 int warn_overloaded_virtual
;
215 /* Non-zero means warn when declaring a class that has a non virtual
216 destructor, when it really ought to have a virtual one. */
219 /* Non-zero means warn when a function is declared extern and later inline. */
220 int warn_extern_inline
;
222 /* Non-zero means warn when the compiler will reorder code. */
225 /* Non-zero means warn when sysnthesis behavior differs from Cfront's. */
228 /* Nonzero means `$' can be in an identifier.
229 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
231 #ifndef DOLLARS_IN_IDENTIFIERS
232 #define DOLLARS_IN_IDENTIFIERS 1
234 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
236 /* Nonzero for -fno-strict-prototype switch: do not consider empty
237 argument prototype to mean function takes no arguments. */
239 int flag_strict_prototype
= 2;
240 int strict_prototype
= 1;
241 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
243 /* Nonzero means that labels can be used as first-class objects */
247 /* Non-zero means to collect statistics which might be expensive
248 and to print them when we are done. */
249 int flag_detailed_statistics
;
251 /* C++ specific flags. */
252 /* Nonzero for -fall-virtual: make every member function (except
253 constructors) lay down in the virtual function table. Calls
254 can then either go through the virtual function table or not,
257 int flag_all_virtual
;
259 /* Zero means that `this' is a *const. This gives nice behavior in the
260 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
261 -2 means we're constructing an object and it has fixed type. */
263 int flag_this_is_variable
;
265 /* Nonzero means memoize our member lookups. */
267 int flag_memoize_lookups
; int flag_save_memoized_contexts
;
269 /* 3 means write out only virtuals function tables `defined'
270 in this implementation file.
271 2 means write out only specific virtual function tables
272 and give them (C) public access.
273 1 means write out virtual function tables and give them
275 0 means write out virtual function tables and give them
276 (C) static access (default).
277 -1 means declare virtual function tables extern. */
281 /* Nonzero means we should attempt to elide constructors when possible. */
283 int flag_elide_constructors
;
285 /* Nonzero means recognize and handle exception handling constructs.
286 Use ansi syntax and semantics. WORK IN PROGRESS! */
288 int flag_handle_exceptions
;
290 /* Nonzero means recognize and handle signature language constructs. */
292 int flag_handle_signatures
;
294 /* Nonzero means that member functions defined in class scope are
295 inline by default. */
297 int flag_default_inline
= 1;
299 /* Controls whether enums and ints freely convert.
300 1 means with complete freedom.
301 0 means enums can convert to ints, but not vice-versa. */
302 int flag_int_enum_equivalence
;
304 /* Controls whether compiler is operating under LUCID's Cadillac
305 system. 1 means yes, 0 means no. */
308 /* Controls whether compiler generates code to build objects
309 that can be collected when they become garbage. */
312 /* Controls whether compiler generates 'type descriptor' that give
313 run-time type information. */
316 /* Nonzero if we wish to output cross-referencing information
317 for the GNU class browser. */
318 extern int flag_gnu_xref
;
320 /* Nonzero if compiler can make `reasonable' assumptions about
321 references and objects. For example, the compiler must be
322 conservative about the following and not assume that `a' is nonnull:
327 In general, it is `reasonable' to assume that for many programs,
328 and better code can be generated in that case. */
330 int flag_assume_nonnull_objects
= 1;
332 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
335 int flag_huge_objects
;
337 /* Nonzero if we want to conserve space in the .o files. We do this
338 by putting uninitialized data and runtime initialized data into
339 .common instead of .data at the expense of not flaging multiple
342 int flag_conserve_space
;
344 /* Nonzero if we want to obey access control semantics. */
346 int flag_access_control
= 1;
348 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
350 int flag_operator_names
;
352 /* Nonzero if we want to check the return value of new and avoid calling
353 constructors if it is a null pointer. */
357 /* Table of language-dependent -f options.
358 STRING is the option name. VARIABLE is the address of the variable.
359 ON_VALUE is the value to store in VARIABLE
360 if `-fSTRING' is seen as an option.
361 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
363 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
365 {"signed-char", &flag_signed_char
, 1},
366 {"unsigned-char", &flag_signed_char
, 0},
367 {"signed-bitfields", &flag_signed_bitfields
, 1},
368 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
369 {"short-enums", &flag_short_enums
, 1},
370 {"short-double", &flag_short_double
, 1},
371 {"cond-mismatch", &flag_cond_mismatch
, 1},
372 {"asm", &flag_no_asm
, 0},
373 {"builtin", &flag_no_builtin
, 0},
374 {"ident", &flag_no_ident
, 0},
375 {"labels-ok", &flag_labels_ok
, 1},
376 {"stats", &flag_detailed_statistics
, 1},
377 {"this-is-variable", &flag_this_is_variable
, 1},
378 {"strict-prototype", &flag_strict_prototype
, 1},
379 {"all-virtual", &flag_all_virtual
, 1},
380 {"memoize-lookups", &flag_memoize_lookups
, 1},
381 {"elide-constructors", &flag_elide_constructors
, 1},
382 {"handle-exceptions", &flag_handle_exceptions
, 1},
383 {"handle-signatures", &flag_handle_signatures
, 1},
384 {"default-inline", &flag_default_inline
, 1},
385 {"dollars-in-identifiers", &dollars_in_ident
, 1},
386 {"enum-int-equiv", &flag_int_enum_equivalence
, 1},
388 {"rtti", &flag_rtti
, 1},
389 {"xref", &flag_gnu_xref
, 1},
390 {"nonnull-objects", &flag_assume_nonnull_objects
, 1},
391 {"implement-inlines", &flag_implement_inlines
, 1},
392 {"external-templates", &flag_external_templates
, 1},
393 {"implicit-templates", &flag_implicit_templates
, 1},
394 {"huge-objects", &flag_huge_objects
, 1},
395 {"conserve-space", &flag_conserve_space
, 1},
396 {"vtable-thunks", &flag_vtable_thunks
, 1},
397 {"short-temps", &flag_short_temps
, 1},
398 {"access-control", &flag_access_control
, 1},
399 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
400 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
401 {"operator-names", &flag_operator_names
, 1},
402 {"check-new", &flag_check_new
, 1}
405 /* Decode the string P as a language-specific option.
406 Return 1 if it is recognized (and handle it);
407 return 0 if not recognized. */
410 lang_decode_option (p
)
413 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
414 flag_traditional
= 1, dollars_in_ident
= 1, flag_writable_strings
= 1,
415 flag_this_is_variable
= 1;
416 /* The +e options are for cfront compatibility. They come in as
417 `-+eN', to kludge around gcc.c's argument handling. */
418 else if (p
[0] == '-' && p
[1] == '+' && p
[2] == 'e')
420 int old_write_virtuals
= write_virtuals
;
423 else if (p
[3] == '0')
425 else if (p
[3] == '2')
427 else error ("invalid +e option");
428 if (old_write_virtuals
!= 0
429 && write_virtuals
!= old_write_virtuals
)
430 error ("conflicting +e options given");
432 else if (p
[0] == '-' && p
[1] == 'f')
434 /* Some kind of -f option.
435 P's value is the option sans `-f'.
436 Search for it in the table of options. */
440 /* Try special -f options. */
442 if (!strcmp (p
, "save-memoized"))
444 flag_memoize_lookups
= 1;
445 flag_save_memoized_contexts
= 1;
448 if (!strcmp (p
, "no-save-memoized"))
450 flag_memoize_lookups
= 0;
451 flag_save_memoized_contexts
= 0;
454 else if (! strncmp (p
, "cadillac", 8))
456 flag_cadillac
= atoi (p
+9);
459 else if (! strncmp (p
, "no-cadillac", 11))
464 else if (! strcmp (p
, "gc"))
467 /* This must come along for the ride. */
471 else if (! strcmp (p
, "no-gc"))
474 /* This must come along for the ride. */
478 else if (! strcmp (p
, "alt-external-templates"))
480 flag_external_templates
= 1;
481 flag_alt_external_templates
= 1;
484 else if (! strcmp (p
, "no-alt-external-templates"))
486 flag_alt_external_templates
= 0;
489 else if (!strcmp (p
, "ansi-overloading"))
491 warning ("-fansi-overloading is no longer meaningful");
494 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
497 if (!strcmp (p
, lang_f_options
[j
].string
))
499 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
500 /* A goto here would be cleaner,
501 but breaks the vax pcc. */
504 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
505 && ! strcmp (p
+3, lang_f_options
[j
].string
))
507 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
513 else if (p
[0] == '-' && p
[1] == 'W')
517 /* The -W options control the warning behavior of the compiler. */
520 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
523 if (!strcmp (p
, "implicit"))
524 warn_implicit
= setting
;
525 else if (!strcmp (p
, "return-type"))
526 warn_return_type
= setting
;
527 else if (!strcmp (p
, "ctor-dtor-privacy"))
528 warn_ctor_dtor_privacy
= setting
;
529 else if (!strcmp (p
, "write-strings"))
530 warn_write_strings
= setting
;
531 else if (!strcmp (p
, "cast-qual"))
532 warn_cast_qual
= setting
;
533 else if (!strcmp (p
, "traditional"))
534 warn_traditional
= setting
;
535 else if (!strcmp (p
, "char-subscripts"))
536 warn_char_subscripts
= setting
;
537 else if (!strcmp (p
, "pointer-arith"))
538 warn_pointer_arith
= setting
;
539 else if (!strcmp (p
, "strict-prototypes"))
540 warn_strict_prototypes
= setting
;
541 else if (!strcmp (p
, "missing-prototypes"))
542 warn_missing_prototypes
= setting
;
543 else if (!strcmp (p
, "redundant-decls"))
544 warn_redundant_decls
= setting
;
545 else if (!strcmp (p
, "missing-braces"))
546 warn_missing_braces
= setting
;
547 else if (!strcmp (p
, "format"))
548 warn_format
= setting
;
549 else if (!strcmp (p
, "conversion"))
550 warn_conversion
= setting
;
551 else if (!strcmp (p
, "parentheses"))
552 warn_parentheses
= setting
;
553 else if (!strcmp (p
, "non-virtual-dtor"))
554 warn_nonvdtor
= setting
;
555 else if (!strcmp (p
, "extern-inline"))
556 warn_extern_inline
= setting
;
557 else if (!strcmp (p
, "reorder"))
558 warn_reorder
= setting
;
559 else if (!strcmp (p
, "synth"))
560 warn_synth
= setting
;
561 else if (!strcmp (p
, "comment"))
562 ; /* cpp handles this one. */
563 else if (!strcmp (p
, "comments"))
564 ; /* cpp handles this one. */
565 else if (!strcmp (p
, "trigraphs"))
566 ; /* cpp handles this one. */
567 else if (!strcmp (p
, "import"))
568 ; /* cpp handles this one. */
569 else if (!strcmp (p
, "all"))
571 extra_warnings
= setting
;
572 warn_return_type
= setting
;
573 warn_unused
= setting
;
574 warn_implicit
= setting
;
575 warn_ctor_dtor_privacy
= setting
;
576 warn_switch
= setting
;
577 warn_format
= setting
;
578 warn_parentheses
= setting
;
579 warn_missing_braces
= setting
;
580 warn_extern_inline
= setting
;
581 warn_nonvdtor
= setting
;
582 /* We save the value of warn_uninitialized, since if they put
583 -Wuninitialized on the command line, we need to generate a
584 warning about not using it without also specifying -O. */
585 if (warn_uninitialized
!= 1)
586 warn_uninitialized
= (setting
? 2 : 0);
587 warn_template_debugging
= setting
;
588 warn_reorder
= setting
;
591 else if (!strcmp (p
, "overloaded-virtual"))
592 warn_overloaded_virtual
= setting
;
595 else if (!strcmp (p
, "-ansi"))
596 dollars_in_ident
= 0, flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
597 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
599 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
600 it's probably safe to assume no sane person would ever want to use this
601 under normal circumstances. */
602 else if (!strcmp (p
, "-spew-debug"))
611 /* Incorporate `const' and `volatile' qualifiers for member functions.
612 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
613 QUALS is a list of qualifiers. */
615 grok_method_quals (ctype
, function
, quals
)
616 tree ctype
, function
, quals
;
618 tree fntype
= TREE_TYPE (function
);
619 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
623 extern tree ridpointers
[];
625 if (TREE_VALUE (quals
) == ridpointers
[(int)RID_CONST
])
627 if (TYPE_READONLY (ctype
))
628 error ("duplicate `%s' %s",
629 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
630 (TREE_CODE (function
) == FUNCTION_DECL
631 ? "for member function" : "in type declaration"));
632 ctype
= build_type_variant (ctype
, 1, TYPE_VOLATILE (ctype
));
633 build_pointer_type (ctype
);
635 else if (TREE_VALUE (quals
) == ridpointers
[(int)RID_VOLATILE
])
637 if (TYPE_VOLATILE (ctype
))
638 error ("duplicate `%s' %s",
639 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
640 (TREE_CODE (function
) == FUNCTION_DECL
641 ? "for member function" : "in type declaration"));
642 ctype
= build_type_variant (ctype
, TYPE_READONLY (ctype
), 1);
643 build_pointer_type (ctype
);
646 my_friendly_abort (20);
647 quals
= TREE_CHAIN (quals
);
650 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
651 (TREE_CODE (fntype
) == METHOD_TYPE
652 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
653 : TYPE_ARG_TYPES (fntype
)));
655 fntype
= build_exception_variant (ctype
, fntype
, raises
);
657 TREE_TYPE (function
) = fntype
;
661 #if 0 /* Not used. */
662 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
663 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
664 /* This does not yet work with user defined conversion operators
667 substitute_nice_name (decl
)
670 if (DECL_NAME (decl
) && TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
672 char *n
= decl_as_string (DECL_NAME (decl
), 1);
673 if (n
[strlen (n
) - 1] == ' ')
674 n
[strlen (n
) - 1] = 0;
675 DECL_NAME (decl
) = get_identifier (n
);
680 /* Warn when -fexternal-templates is used and #pragma
681 interface/implementation is not used all the times it should be,
684 warn_if_unknown_interface (decl
)
687 static int already_warned
= 0;
688 if (already_warned
++)
691 if (flag_alt_external_templates
)
693 struct tinst_level
*til
= tinst_for_decl ();
695 char *sf
= input_filename
;
698 input_filename
= til
->file
;
699 cp_warning ("template `%#D' instantiated in file without #pragma interface",
705 cp_warning_at ("template `%#D' defined in file without #pragma interface",
709 /* A subroutine of the parser, to handle a component list. */
711 grok_x_components (specs
, components
)
712 tree specs
, components
;
714 register tree t
, x
, tcode
;
716 /* We just got some friends. They have been recorded elsewhere. */
717 if (components
== void_type_node
)
720 if (components
== NULL_TREE
)
722 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
726 error ("error in component specification");
730 switch (TREE_CODE (t
))
733 /* Static anonymous unions come out as VAR_DECLs. */
734 if (TREE_CODE (TREE_TYPE (t
)) == UNION_TYPE
735 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t
))))
738 /* We return SPECS here, because in the parser it was ending
739 up with not doing anything to $$, which is what SPECS
745 /* This code may be needed for UNION_TYPEs as
747 tcode
= record_type_node
;
748 if (CLASSTYPE_DECLARED_CLASS(t
))
749 tcode
= class_type_node
;
750 else if (IS_SIGNATURE(t
))
751 tcode
= signature_type_node
;
753 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
755 CLASSTYPE_NO_GLOBALIZE(t
) = 1;
761 if (TREE_CODE(t
) == UNION_TYPE
)
762 tcode
= union_type_node
;
764 tcode
= enum_type_node
;
766 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
767 if (TREE_CODE(t
) == UNION_TYPE
&& TYPE_CONTEXT(t
))
768 CLASSTYPE_NO_GLOBALIZE(t
) = 1;
769 if (TREE_CODE (t
) == UNION_TYPE
770 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))
772 struct pending_inline
**p
;
773 x
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, t
);
775 /* Wipe out memory of synthesized methods */
776 TYPE_HAS_CONSTRUCTOR (t
) = 0;
777 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
778 TYPE_HAS_INIT_REF (t
) = 0;
779 TYPE_HAS_CONST_INIT_REF (t
) = 0;
780 TYPE_HAS_ASSIGN_REF (t
) = 0;
781 TYPE_HAS_ASSIGNMENT (t
) = 0;
782 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
784 p
= &pending_inlines
;
785 for (; *p
; *p
= (*p
)->next
)
786 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
789 else if (TREE_CODE (t
) == ENUMERAL_TYPE
)
790 x
= grok_enum_decls (t
, NULL_TREE
);
797 if (t
!= void_type_node
)
798 error ("empty component declaration");
804 t
= TREE_TYPE (components
);
805 if (TREE_CODE (t
) == ENUMERAL_TYPE
&& TREE_NONLOCAL_FLAG (t
))
806 return grok_enum_decls (t
, components
);
812 /* Classes overload their constituent function names automatically.
813 When a function name is declared in a record structure,
814 its name is changed to it overloaded name. Since names for
815 constructors and destructors can conflict, we place a leading
818 CNAME is the name of the class we are grokking for.
820 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
822 FLAGS contains bits saying what's special about today's
823 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
825 If FUNCTION is a destructor, then we must add the `auto-delete' field
826 as a second parameter. There is some hair associated with the fact
827 that we must "declare" this variable in the manner consistent with the
828 way the rest of the arguments were declared.
830 QUALS are the qualifiers for the this pointer. */
833 grokclassfn (ctype
, cname
, function
, flags
, quals
)
834 tree ctype
, cname
, function
;
835 enum overload_flags flags
;
838 tree fn_name
= DECL_NAME (function
);
843 if (fn_name
== NULL_TREE
)
845 error ("name missing for member function");
846 fn_name
= get_identifier ("<anonymous>");
847 DECL_NAME (function
) = fn_name
;
851 qualtype
= grok_method_quals (ctype
, function
, quals
);
855 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
856 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
858 /* Must add the class instance variable up front. */
859 /* Right now we just make this a pointer. But later
860 we may wish to make it special. */
861 tree type
= TREE_VALUE (arg_types
);
863 if ((flag_this_is_variable
> 0)
864 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
865 type
= TYPE_MAIN_VARIANT (type
);
867 if (DECL_CONSTRUCTOR_P (function
))
869 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype
))
871 DECL_CONSTRUCTOR_FOR_VBASE_P (function
) = 1;
872 /* In this case we need "in-charge" flag saying whether
873 this constructor is responsible for initialization
874 of virtual baseclasses or not. */
875 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
876 /* Mark the artificial `__in_chrg' parameter as "artificial". */
877 SET_DECL_ARTIFICIAL (parm
);
878 DECL_ARG_TYPE (parm
) = integer_type_node
;
879 DECL_REGISTER (parm
) = 1;
880 TREE_CHAIN (parm
) = last_function_parms
;
881 last_function_parms
= parm
;
885 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
886 /* Mark the artificial `this' parameter as "artificial". */
887 SET_DECL_ARTIFICIAL (parm
);
888 DECL_ARG_TYPE (parm
) = type
;
889 /* We can make this a register, so long as we don't
890 accidentally complain if someone tries to take its address. */
891 DECL_REGISTER (parm
) = 1;
892 if (TYPE_READONLY (type
))
893 TREE_READONLY (parm
) = 1;
894 TREE_CHAIN (parm
) = last_function_parms
;
895 last_function_parms
= parm
;
898 if (flags
== DTOR_FLAG
)
901 tree const_integer_type
= build_type_variant (integer_type_node
, 1, 0);
902 int len
= sizeof (DESTRUCTOR_DECL_PREFIX
)-1;
904 arg_types
= hash_tree_chain (const_integer_type
, void_list_node
);
905 TREE_SIDE_EFFECTS (arg_types
) = 1;
906 /* Build the overload name. It will look like `7Example'. */
907 if (IDENTIFIER_TYPE_VALUE (cname
))
908 dbuf
= build_overload_name (IDENTIFIER_TYPE_VALUE (cname
), 1, 1);
909 else if (IDENTIFIER_LOCAL_VALUE (cname
))
910 dbuf
= build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname
)), 1, 1);
912 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
913 it's defined out of the class definition, since poplevel_class wipes
914 it out. This used to be internal error 346. */
915 dbuf
= build_overload_name (ctype
, 1, 1);
916 buf
= (char *) alloca (strlen (dbuf
) + sizeof (DESTRUCTOR_DECL_PREFIX
));
917 bcopy (DESTRUCTOR_DECL_PREFIX
, buf
, len
);
920 DECL_ASSEMBLER_NAME (function
) = get_identifier (buf
);
921 parm
= build_decl (PARM_DECL
, in_charge_identifier
, const_integer_type
);
922 /* Mark the artificial `__in_chrg' parameter as "artificial". */
923 SET_DECL_ARTIFICIAL (parm
);
924 TREE_USED (parm
) = 1;
926 /* We don't need to mark the __in_chrg parameter itself as `const'
927 since its type is already `const int'. In fact we MUST NOT mark
928 it as `const' cuz that will screw up the debug info (causing it
929 to say that the type of __in_chrg is `const const int'). */
930 TREE_READONLY (parm
) = 1;
932 DECL_ARG_TYPE (parm
) = const_integer_type
;
933 /* This is the same chain as DECL_ARGUMENTS (...). */
934 TREE_CHAIN (last_function_parms
) = parm
;
936 TREE_TYPE (function
) = build_cplus_method_type (qualtype
, void_type_node
,
938 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
942 tree these_arg_types
;
944 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function
))
946 arg_types
= hash_tree_chain (integer_type_node
,
947 TREE_CHAIN (arg_types
));
949 = build_cplus_method_type (qualtype
,
950 TREE_TYPE (TREE_TYPE (function
)),
952 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
955 these_arg_types
= arg_types
;
957 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
958 /* Only true for static member functions. */
959 these_arg_types
= hash_tree_chain (TYPE_POINTER_TO (qualtype
),
962 DECL_ASSEMBLER_NAME (function
)
963 = build_decl_overload (fn_name
, these_arg_types
,
964 1 + DECL_CONSTRUCTOR_P (function
));
967 /* This code is going into the compiler, but currently, it makes
968 libg++/src/Interger.cc not compile. The problem is that the nice name
969 winds up going into the symbol table, and conversion operations look
970 for the manged name. */
971 substitute_nice_name (function
);
975 DECL_ARGUMENTS (function
) = last_function_parms
;
976 /* First approximations. */
977 DECL_CONTEXT (function
) = ctype
;
978 DECL_CLASS_CONTEXT (function
) = ctype
;
981 /* Work on the expr used by alignof (this is only called by the parser). */
989 if (TREE_CODE (expr
) == COMPONENT_REF
990 && DECL_BIT_FIELD (TREE_OPERAND (expr
, 1)))
991 error ("`__alignof__' applied to a bit-field");
993 if (TREE_CODE (expr
) == INDIRECT_REF
)
995 best
= t
= TREE_OPERAND (expr
, 0);
996 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
998 while (TREE_CODE (t
) == NOP_EXPR
999 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1002 t
= TREE_OPERAND (t
, 0);
1003 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1004 if (thisalign
> bestalign
)
1005 best
= t
, bestalign
= thisalign
;
1007 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1011 /* ANSI says arrays and fns are converted inside comma.
1012 But we can't convert them in build_compound_expr
1013 because that would break commas in lvalues.
1014 So do the conversion here if operand was a comma. */
1015 if (TREE_CODE (expr
) == COMPOUND_EXPR
1016 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1017 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1018 expr
= default_conversion (expr
);
1019 return c_alignof (TREE_TYPE (expr
));
1023 /* Create an ARRAY_REF, checking for the user doing things backwards
1026 grok_array_decl (array_expr
, index_exp
)
1027 tree array_expr
, index_exp
;
1029 tree type
= TREE_TYPE (array_expr
);
1030 tree p1
, p2
, i1
, i2
;
1032 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1033 return error_mark_node
;
1034 if (type
== NULL_TREE
)
1036 /* Something has gone very wrong. Assume we are mistakenly reducing
1037 an expression instead of a declaration. */
1038 error ("parser may be lost: is there a '{' missing somewhere?");
1042 if (TREE_CODE (type
) == OFFSET_TYPE
1043 || TREE_CODE (type
) == REFERENCE_TYPE
)
1044 type
= TREE_TYPE (type
);
1046 /* If they have an `operator[]', use that. */
1047 if (TYPE_LANG_SPECIFIC (type
)
1048 && TYPE_OVERLOADS_ARRAY_REF (type
))
1049 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1050 array_expr
, index_exp
, NULL_TREE
);
1052 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1054 if (TREE_CODE (type
) == ARRAY_TYPE
)
1057 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1059 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1062 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1064 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1065 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1067 if ((p1
&& i2
) && (i1
&& p2
))
1068 error ("ambiguous conversion for array subscript");
1071 array_expr
= p1
, index_exp
= i2
;
1073 array_expr
= p2
, index_exp
= i1
;
1076 cp_error ("invalid types `%T[%T]' for array subscript",
1077 type
, TREE_TYPE (index_exp
));
1078 return error_mark_node
;
1081 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1082 error ("ambiguous conversion for array subscript");
1084 return build_array_ref (array_expr
, index_exp
);
1087 /* Given the cast expression EXP, checking out its validity. Either return
1088 an error_mark_node if there was an unavoidable error, return a cast to
1089 void for trying to delete a pointer w/ the value 0, or return the
1090 call to delete. If DOING_VEC is 1, we handle things differently
1091 for doing an array delete. If DOING_VEC is 2, they gave us the
1092 array size as an argument to delete.
1093 Implements ARM $5.3.4. This is called from the parser. */
1095 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1097 int doing_vec
, use_global_delete
;
1099 tree t
= stabilize_reference (convert_from_reference (exp
));
1100 tree type
= TREE_TYPE (t
);
1101 enum tree_code code
= TREE_CODE (type
);
1102 /* For a regular vector delete (aka, no size argument) we will pass
1103 this down as a NULL_TREE into build_vec_delete. */
1104 tree maxindex
= NULL_TREE
;
1105 /* This is used for deleting arrays. */
1111 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1112 if (! flag_traditional
)
1113 pedwarn ("anachronistic use of array size in vector delete");
1116 elt_size
= c_sizeof (type
);
1119 if (code
!= POINTER_TYPE
)
1121 cp_error ("type `%#T' argument given to `delete', expected pointer",
1123 return error_mark_node
;
1126 /* Deleting a pointer with the value zero is valid and has no effect. */
1127 if (integer_zerop (t
))
1128 return build1 (NOP_EXPR
, void_type_node
, t
);
1131 if (code
== POINTER_TYPE
)
1134 /* As of Valley Forge, you can delete a pointer to constant. */
1135 /* You can't delete a pointer to constant. */
1136 if (TREE_READONLY (TREE_TYPE (type
)))
1138 error ("`const *' cannot be deleted");
1139 return error_mark_node
;
1142 /* You also can't delete functions. */
1143 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1145 error ("cannot delete a function");
1146 return error_mark_node
;
1151 /* If the type has no destructor, then we should build a regular
1152 delete, instead of a vector delete. Otherwise, we would end
1153 up passing a bogus offset into __builtin_delete, which is
1154 not expecting it. */
1156 && TREE_CODE (type
) == POINTER_TYPE
1157 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type
)))
1160 use_global_delete
= 1;
1165 return build_vec_delete (t
, maxindex
, elt_size
, integer_one_node
,
1166 integer_two_node
, use_global_delete
);
1168 return build_delete (type
, t
, integer_three_node
,
1169 LOOKUP_NORMAL
|LOOKUP_HAS_IN_CHARGE
,
1173 /* Sanity check: report error if this function FUNCTION is not
1174 really a member of the class (CTYPE) it is supposed to belong to.
1175 CNAME is the same here as it is for grokclassfn above. */
1178 check_classfn (ctype
, cname
, function
)
1179 tree ctype
, cname
, function
;
1181 tree fn_name
= DECL_NAME (function
);
1183 tree method_vec
= CLASSTYPE_METHOD_VEC (ctype
);
1187 if (method_vec
!= 0)
1189 methods
= &TREE_VEC_ELT (method_vec
, 0);
1190 end
= TREE_VEC_END (method_vec
);
1192 /* First suss out ctors and dtors. */
1194 && (fn_name
== cname
|| fn_name
== DECL_NAME (*methods
)))
1197 while (++methods
!= end
)
1199 if (fn_name
== DECL_NAME (*methods
))
1205 if (DECL_ASSEMBLER_NAME (function
) == DECL_ASSEMBLER_NAME (fndecl
))
1208 /* This should work, but causes libg++ to fail
1210 /* We have to do more extensive argument checking here, as
1211 the name may have been changed by asm("new_name"). */
1212 if (decls_match (function
, fndecl
))
1215 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1217 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1218 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1220 /* Get rid of the this parameter on functions that become
1222 if (DECL_STATIC_FUNCTION_P (fndecl
)
1223 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1224 p1
= TREE_CHAIN (p1
);
1226 if (comptypes (TREE_TYPE (TREE_TYPE (function
)),
1227 TREE_TYPE (TREE_TYPE (fndecl
)), 1)
1228 && compparms (p1
, p2
, 3))
1232 fndecl
= DECL_CHAIN (fndecl
);
1240 cp_error ("argument list for `%#D' does not match any in class `%T'",
1245 cp_error ("no `%#D' member function declared in class `%T'",
1249 /* If we did not find the method in the class, add it to
1250 avoid spurious errors. */
1251 add_method (ctype
, methods
, function
);
1254 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1255 of a structure component, returning a FIELD_DECL node.
1256 QUALS is a list of type qualifiers for this decl (such as for declaring
1257 const member functions).
1259 This is done during the parsing of the struct declaration.
1260 The FIELD_DECL nodes are chained together and the lot of them
1261 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1265 If class A defines that certain functions in class B are friends, then
1266 the way I have set things up, it is B who is interested in permission
1267 granted by A. However, it is in A's context that these declarations
1268 are parsed. By returning a void_type_node, class A does not attempt
1269 to incorporate the declarations of the friends within its structure.
1271 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1272 CHANGES TO CODE IN `start_method'. */
1275 grokfield (declarator
, declspecs
, raises
, init
, asmspec_tree
)
1276 tree declarator
, declspecs
, raises
, init
, asmspec_tree
;
1278 register tree value
;
1280 int flags
= LOOKUP_ONLYCONVERTING
;
1282 /* Convert () initializers to = initializers. */
1283 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1284 && TREE_CODE (declarator
) == CALL_EXPR
1285 && TREE_OPERAND (declarator
, 0)
1286 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1287 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1288 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1290 init
= TREE_OPERAND (declarator
, 1);
1291 declarator
= TREE_OPERAND (declarator
, 0);
1296 && TREE_CODE (init
) == TREE_LIST
1297 && TREE_VALUE (init
) == error_mark_node
1298 && TREE_CHAIN (init
) == NULL_TREE
)
1301 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, raises
);
1303 return value
; /* friend or constructor went bad. */
1305 /* Pass friendly classes back. */
1306 if (TREE_CODE (value
) == VOID_TYPE
)
1307 return void_type_node
;
1309 if (DECL_NAME (value
) != NULL_TREE
1310 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1311 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1312 cp_error ("member `%D' conflicts with virtual function table field name", value
);
1314 /* Stash away type declarations. */
1315 if (TREE_CODE (value
) == TYPE_DECL
)
1317 DECL_NONLOCAL (value
) = 1;
1318 DECL_CONTEXT (value
) = current_class_type
;
1319 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1320 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
1322 /* If we declare a typedef name for something that has no name,
1323 the typedef name is used for linkage. See 7.1.3 p4 94/0158. */
1324 if (TYPE_NAME (TREE_TYPE (value
))
1325 && TREE_CODE (TYPE_NAME (TREE_TYPE (value
))) == TYPE_DECL
1326 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (value
))))
1328 TYPE_NAME (TREE_TYPE (value
)) = value
;
1329 TYPE_STUB_DECL (TREE_TYPE (value
)) = value
;
1332 pushdecl_class_level (value
);
1336 if (IS_SIGNATURE (current_class_type
)
1337 && TREE_CODE (value
) != FUNCTION_DECL
)
1339 error ("field declaration not allowed in signature");
1340 return void_type_node
;
1343 if (DECL_IN_AGGR_P (value
))
1345 cp_error ("`%D' is already defined in the class %T", value
,
1346 DECL_CONTEXT (value
));
1347 return void_type_node
;
1351 cadillac_start_decl (value
);
1354 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1358 if (IS_SIGNATURE (current_class_type
)
1359 && TREE_CODE (value
) == FUNCTION_DECL
)
1361 error ("function declarations cannot have initializers in signature");
1364 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1366 grok_function_init (value
, init
);
1369 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1370 /* Already complained in grokdeclarator. */
1374 /* We allow initializers to become parameters to base
1376 if (TREE_CODE (init
) == TREE_LIST
)
1378 if (TREE_CHAIN (init
) == NULL_TREE
)
1379 init
= TREE_VALUE (init
);
1381 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1384 if (TREE_CODE (init
) == CONST_DECL
)
1385 init
= DECL_INITIAL (init
);
1386 else if (TREE_READONLY_DECL_P (init
))
1387 init
= decl_constant_value (init
);
1388 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1389 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1390 my_friendly_assert (TREE_PERMANENT (init
), 192);
1391 if (init
== error_mark_node
)
1392 /* We must make this look different than `error_mark_node'
1393 because `decl_const_value' would mis-interpret it
1394 as only meaning that this VAR_DECL is defined. */
1395 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1396 else if (! TREE_CONSTANT (init
))
1398 /* We can allow references to things that are effectively
1399 static, since references are initialized with the address. */
1400 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1401 || (TREE_STATIC (init
) == 0
1402 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1403 || DECL_EXTERNAL (init
) == 0)))
1405 error ("field initializer is not constant");
1406 init
= error_mark_node
;
1412 /* The corresponding pop_obstacks is in finish_decl. */
1413 push_obstacks_nochange ();
1415 if (TREE_CODE (value
) == VAR_DECL
)
1417 /* We cannot call pushdecl here, because that would
1418 fill in the value of our TREE_CHAIN. Instead, we
1419 modify finish_decl to do the right thing, namely, to
1420 put this decl out straight away. */
1421 if (TREE_PUBLIC (value
))
1423 /* current_class_type can be NULL_TREE in case of error. */
1424 if (asmspec
== 0 && current_class_type
)
1426 TREE_PUBLIC (value
) = 1;
1427 DECL_INITIAL (value
) = error_mark_node
;
1428 DECL_ASSEMBLER_NAME (value
)
1429 = build_static_name (current_class_type
, DECL_NAME (value
));
1431 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1433 /* Static consts need not be initialized in the class definition. */
1434 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1436 static int explanation
= 0;
1438 error ("initializer invalid for static member with constructor");
1439 if (explanation
++ == 0)
1440 error ("(you really want to initialize it separately)");
1443 /* Force the compiler to know when an uninitialized static
1444 const member is being used. */
1445 if (TYPE_READONLY (value
) && init
== 0)
1446 TREE_USED (value
) = 1;
1448 DECL_INITIAL (value
) = init
;
1449 DECL_IN_AGGR_P (value
) = 1;
1451 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1452 pushdecl_class_level (value
);
1455 if (TREE_CODE (value
) == FIELD_DECL
)
1459 /* This must override the asm specifier which was placed
1460 by grokclassfn. Lay this out fresh. */
1461 DECL_RTL (value
) = NULL_RTX
;
1462 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1464 if (DECL_INITIAL (value
) == error_mark_node
)
1465 init
= error_mark_node
;
1466 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1467 DECL_INITIAL (value
) = init
;
1468 DECL_IN_AGGR_P (value
) = 1;
1471 if (TREE_CODE (value
) == FUNCTION_DECL
)
1473 if (DECL_CHAIN (value
) != NULL_TREE
)
1475 /* Need a fresh node here so that we don't get circularity
1476 when we link these together. */
1477 value
= copy_node (value
);
1478 /* When does this happen? */
1479 my_friendly_assert (init
== NULL_TREE
, 193);
1483 /* This must override the asm specifier which was placed
1484 by grokclassfn. Lay this out fresh. */
1485 DECL_RTL (value
) = NULL_RTX
;
1486 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1488 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1490 /* Pass friends back this way. */
1491 if (DECL_FRIEND_P (value
))
1492 return void_type_node
;
1494 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1495 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1496 cp_error ("method `%#D' of local class must be defined in class body",
1500 DECL_IN_AGGR_P (value
) = 1;
1503 my_friendly_abort (21);
1508 /* Like `grokfield', but for bitfields.
1509 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1512 grokbitfield (declarator
, declspecs
, width
)
1513 tree declarator
, declspecs
, width
;
1515 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
, 0, NULL_TREE
);
1517 if (! value
) return NULL_TREE
; /* friends went bad. */
1519 /* Pass friendly classes back. */
1520 if (TREE_CODE (value
) == VOID_TYPE
)
1521 return void_type_node
;
1523 if (TREE_CODE (value
) == TYPE_DECL
)
1525 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1529 if (IS_SIGNATURE (current_class_type
))
1531 error ("field declaration not allowed in signature");
1532 return void_type_node
;
1535 if (DECL_IN_AGGR_P (value
))
1537 cp_error ("`%D' is already defined in the class %T", value
,
1538 DECL_CONTEXT (value
));
1539 return void_type_node
;
1542 GNU_xref_member (current_class_name
, value
);
1544 if (TREE_STATIC (value
))
1546 cp_error ("static member `%D' cannot be a bitfield", value
);
1549 finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1551 if (width
!= error_mark_node
)
1553 /* detect invalid field size. */
1554 if (TREE_CODE (width
) == CONST_DECL
)
1555 width
= DECL_INITIAL (width
);
1556 else if (TREE_READONLY_DECL_P (width
))
1557 width
= decl_constant_value (width
);
1558 if (TREE_CODE (width
) != INTEGER_CST
)
1560 cp_error ("structure field `%D' width not an integer constant",
1562 DECL_INITIAL (value
) = NULL_TREE
;
1566 constant_expression_warning (width
);
1567 DECL_INITIAL (value
) = width
;
1568 DECL_BIT_FIELD (value
) = 1;
1572 DECL_IN_AGGR_P (value
) = 1;
1577 /* Like GROKFIELD, except that the declarator has been
1578 buried in DECLSPECS. Find the declarator, and
1579 return something that looks like it came from
1582 groktypefield (declspecs
, parmlist
)
1586 tree spec
= declspecs
;
1587 tree prev
= NULL_TREE
;
1589 tree type_id
= NULL_TREE
;
1590 tree quals
= NULL_TREE
;
1591 tree lengths
= NULL_TREE
;
1592 tree decl
= NULL_TREE
;
1596 register tree id
= TREE_VALUE (spec
);
1598 if (TREE_CODE (spec
) != TREE_LIST
)
1599 /* Certain parse errors slip through. For example,
1600 `int class ();' is not caught by the parser. Try
1601 weakly to recover here. */
1604 if (TREE_CODE (id
) == TYPE_DECL
1605 || (TREE_CODE (id
) == IDENTIFIER_NODE
&& TREE_TYPE (id
)))
1607 /* We have a constructor/destructor or
1608 conversion operator. Use it. */
1610 TREE_CHAIN (prev
) = TREE_CHAIN (spec
);
1612 declspecs
= TREE_CHAIN (spec
);
1618 spec
= TREE_CHAIN (spec
);
1621 /* Nope, we have a conversion operator to a scalar type or something
1622 else, that includes things like constructor declarations for
1627 tree id
= TREE_VALUE (spec
);
1629 if (TREE_CODE (id
) == IDENTIFIER_NODE
)
1631 if (id
== ridpointers
[(int)RID_INT
]
1632 || id
== ridpointers
[(int)RID_DOUBLE
]
1633 || id
== ridpointers
[(int)RID_FLOAT
]
1634 || id
== ridpointers
[(int)RID_WCHAR
])
1637 error ("extra `%s' ignored",
1638 IDENTIFIER_POINTER (id
));
1642 else if (id
== ridpointers
[(int)RID_LONG
]
1643 || id
== ridpointers
[(int)RID_SHORT
]
1644 || id
== ridpointers
[(int)RID_CHAR
])
1646 lengths
= tree_cons (NULL_TREE
, id
, lengths
);
1648 else if (id
== ridpointers
[(int)RID_VOID
])
1651 error ("spurious `void' type ignored");
1653 error ("conversion to `void' type invalid");
1655 else if (id
== ridpointers
[(int)RID_AUTO
]
1656 || id
== ridpointers
[(int)RID_REGISTER
]
1657 || id
== ridpointers
[(int)RID_TYPEDEF
]
1658 || id
== ridpointers
[(int)RID_CONST
]
1659 || id
== ridpointers
[(int)RID_VOLATILE
])
1661 error ("type specifier `%s' used invalidly",
1662 IDENTIFIER_POINTER (id
));
1664 else if (id
== ridpointers
[(int)RID_FRIEND
]
1665 || id
== ridpointers
[(int)RID_VIRTUAL
]
1666 || id
== ridpointers
[(int)RID_INLINE
]
1667 || id
== ridpointers
[(int)RID_UNSIGNED
]
1668 || id
== ridpointers
[(int)RID_SIGNED
]
1669 || id
== ridpointers
[(int)RID_STATIC
]
1670 || id
== ridpointers
[(int)RID_EXTERN
])
1672 quals
= tree_cons (NULL_TREE
, id
, quals
);
1676 /* Happens when we have a global typedef
1677 and a class-local member function with
1683 else if (TREE_CODE (id
) == RECORD_TYPE
)
1685 type_id
= TYPE_NAME (id
);
1686 if (TREE_CODE (type_id
) == TYPE_DECL
)
1687 type_id
= DECL_NAME (type_id
);
1688 if (type_id
== NULL_TREE
)
1689 error ("identifier for aggregate type conversion omitted");
1691 else if (TREE_CODE_CLASS (TREE_CODE (id
)) == 't')
1692 error ("`operator' missing on conversion operator or tag missing from type");
1694 my_friendly_abort (194);
1695 spec
= TREE_CHAIN (spec
);
1699 declspecs
= chainon (lengths
, quals
);
1702 if (TREE_CHAIN (lengths
))
1703 error ("multiple length specifiers");
1704 type_id
= ridpointers
[(int)RID_INT
];
1705 declspecs
= chainon (lengths
, quals
);
1709 error ("no type given, defaulting to `operator int ...'");
1710 type_id
= ridpointers
[(int)RID_INT
];
1717 decl
= grokdeclarator (build_parse_node (CALL_EXPR
, type_id
, parmlist
, NULL_TREE
),
1718 declspecs
, FIELD
, 0, NULL_TREE
);
1719 if (decl
== NULL_TREE
)
1722 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CHAIN (decl
) != NULL_TREE
)
1724 /* Need a fresh node here so that we don't get circularity
1725 when we link these together. */
1726 decl
= copy_node (decl
);
1729 if (decl
== void_type_node
1730 || (TREE_CODE (decl
) == FUNCTION_DECL
1731 && TREE_CODE (TREE_TYPE (decl
)) != METHOD_TYPE
))
1732 /* bunch of friends. */
1735 if (DECL_IN_AGGR_P (decl
))
1737 cp_error ("`%D' already defined in the class ", decl
);
1738 return void_type_node
;
1741 finish_decl (decl
, NULL_TREE
, NULL_TREE
, 0, 0);
1743 /* If this declaration is common to another declaration
1744 complain about such redundancy, and return NULL_TREE
1745 so that we don't build a circular list. */
1746 if (DECL_CHAIN (decl
))
1748 cp_error ("function `%D' declared twice in class %T", decl
,
1749 DECL_CONTEXT (decl
));
1752 DECL_IN_AGGR_P (decl
) = 1;
1758 grokoptypename (declspecs
, declarator
)
1759 tree declspecs
, declarator
;
1761 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1762 return build_typename_overload (t
);
1765 /* When a function is declared with an initializer,
1766 do the right thing. Currently, there are two possibilities:
1771 // initialization possibility #1.
1772 virtual void f () = 0;
1794 // initialization possibility #2
1801 copy_assignment_arg_p (parmtype
, virtualp
)
1805 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1806 parmtype
= TREE_TYPE (parmtype
);
1808 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1809 || (virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
)))
1816 grok_function_init (decl
, init
)
1820 /* An initializer for a function tells how this function should
1822 tree type
= TREE_TYPE (decl
);
1824 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1825 cp_error ("initializer specified for non-member function `%D'", decl
);
1826 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1827 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1828 else if (integer_zerop (init
))
1831 /* Mark this function as being "defined". */
1832 DECL_INITIAL (decl
) = error_mark_node
;
1833 /* pure virtual destructors must be defined. */
1834 /* pure virtual needs to be defined (as abort) only when put in
1835 vtbl. For wellformed call, it should be itself. pr4737 */
1836 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1838 extern tree abort_fndecl
;
1839 /* Give this node rtl from `abort'. */
1840 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1843 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1844 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1847 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1849 if (copy_assignment_arg_p (parmtype
, 1))
1850 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1853 else if (TREE_CODE (init
) == OFFSET_REF
1854 && TREE_OPERAND (init
, 0) == NULL_TREE
1855 && TREE_CODE (TREE_TYPE (init
)) == METHOD_TYPE
)
1857 tree basetype
= DECL_CLASS_CONTEXT (init
);
1858 tree basefn
= TREE_OPERAND (init
, 1);
1859 if (TREE_CODE (basefn
) != FUNCTION_DECL
)
1860 cp_error ("non-method initializer invalid for method `%D'", decl
);
1861 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn
))))
1862 sorry ("base member function from other than first base class");
1865 tree binfo
= get_binfo (basetype
, TYPE_METHOD_BASETYPE (type
), 1);
1866 if (binfo
== error_mark_node
)
1868 else if (binfo
== 0)
1869 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init
)),
1870 TYPE_METHOD_BASETYPE (type
));
1873 /* Mark this function as being defined,
1874 and give it new rtl. */
1875 DECL_INITIAL (decl
) = error_mark_node
;
1876 DECL_RTL (decl
) = DECL_RTL (basefn
);
1881 cp_error ("invalid initializer for virtual method `%D'", decl
);
1884 /* When we get a declaration of the form
1886 type cname::fname ...
1888 the node for `cname::fname' gets built here in a special way.
1889 Namely, we push into `cname's scope. When this declaration is
1890 processed, we pop back out. */
1892 build_push_scope (cname
, name
)
1896 extern int current_class_depth
;
1900 if (cname
== error_mark_node
)
1901 return error_mark_node
;
1903 ctype
= IDENTIFIER_TYPE_VALUE (cname
);
1905 if (TREE_CODE (ctype
) == TEMPLATE_TYPE_PARM
)
1907 else if (ctype
== NULL_TREE
|| ! IS_AGGR_TYPE (ctype
))
1909 cp_error ("`%T' not defined as aggregate type", cname
);
1912 else if (IS_SIGNATURE (ctype
))
1914 error ("cannot push into signature scope, scope resolution operator ignored");
1918 rval
= build_parse_node (SCOPE_REF
, cname
, name
);
1920 /* Don't need to push the scope if we're already in it.
1921 We also don't need to push the scope for a ptr-to-member/method. */
1923 if (ctype
== current_class_type
|| TREE_CODE (name
) != IDENTIFIER_NODE
1927 /* We do need to push the scope in this case, since CTYPE helps
1928 determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;). */
1930 push_nested_class (ctype
, 3);
1931 TREE_COMPLEXITY (rval
) = current_class_depth
;
1936 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1937 tree decl
, attributes
, prefix_attributes
;
1939 if (decl
&& decl
!= void_type_node
)
1940 decl_attributes (decl
, attributes
, prefix_attributes
);
1943 /* CONSTRUCTOR_NAME:
1944 Return the name for the constructor (or destructor) for the
1945 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1946 IDENTIFIER_NODE. When given a template, this routine doesn't
1947 lose the specialization. */
1949 constructor_name_full (thing
)
1952 if (TREE_CODE (thing
) == UNINSTANTIATED_P_TYPE
)
1953 return DECL_NAME (UPT_TEMPLATE (thing
));
1954 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
1956 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
1957 thing
= DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing
), 0));
1959 thing
= TYPE_NAME (thing
);
1961 if (TREE_CODE (thing
) == TYPE_DECL
1962 || (TREE_CODE (thing
) == TEMPLATE_DECL
1963 && DECL_TEMPLATE_IS_CLASS (thing
)))
1964 thing
= DECL_NAME (thing
);
1965 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
1969 /* CONSTRUCTOR_NAME:
1970 Return the name for the constructor (or destructor) for the
1971 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1972 IDENTIFIER_NODE. When given a template, return the plain
1973 unspecialized name. */
1975 constructor_name (thing
)
1979 thing
= constructor_name_full (thing
);
1980 t
= IDENTIFIER_TEMPLATE (thing
);
1983 t
= TREE_PURPOSE (t
);
1984 return DECL_NAME (t
);
1987 /* Cache the value of this class's main virtual function table pointer
1988 in a register variable. This will save one indirection if a
1989 more than one virtual function call is made this function. */
1993 extern rtx base_init_insns
;
1995 if (base_init_insns
== 0
1996 && DECL_CONSTRUCTOR_P (current_function_decl
))
1997 emit_base_init (current_class_type
, 0);
2000 /* This has something a little wrong with it.
2002 On a sun4, code like:
2007 is generated, when the below is used when -O4 is given. The delay
2008 slot it filled with an instruction that is safe, when this isn't
2018 virtual void print() { printf("xxx"); }
2030 And that is why this is disabled for now. (mrs)
2033 if ((flag_this_is_variable
& 1) == 0
2035 && current_class_type
2036 && CLASSTYPE_VSIZE (current_class_type
)
2037 && ! DECL_STATIC_FUNCTION_P (current_function_decl
))
2039 tree vfield
= build_vfield_ref (C_C_D
, current_class_type
);
2040 current_vtable_decl
= CLASSTYPE_VTBL_PTR (current_class_type
);
2041 DECL_RTL (current_vtable_decl
) = 0;
2042 DECL_INITIAL (current_vtable_decl
) = error_mark_node
;
2043 /* Have to cast the initializer, since it may have come from a
2044 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
2045 finish_decl (current_vtable_decl
, convert_force (TREE_TYPE (current_vtable_decl
), vfield
, 0), NULL_TREE
, 0, 0);
2046 current_vtable_decl
= build_indirect_ref (current_vtable_decl
, NULL_PTR
);
2050 current_vtable_decl
= NULL_TREE
;
2053 /* Record the existence of an addressable inline function. */
2055 mark_inline_for_output (decl
)
2058 decl
= DECL_MAIN_VARIANT (decl
);
2059 if (DECL_SAVED_INLINE (decl
))
2061 my_friendly_assert (TREE_PERMANENT (decl
), 363);
2062 DECL_SAVED_INLINE (decl
) = 1;
2063 if (DECL_PENDING_INLINE_INFO (decl
) != 0
2064 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
2066 struct pending_inline
*t
= pending_inlines
;
2067 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
2070 if (t
== DECL_PENDING_INLINE_INFO (decl
))
2076 t
= DECL_PENDING_INLINE_INFO (decl
);
2077 t
->next
= pending_inlines
;
2078 pending_inlines
= t
;
2080 DECL_PENDING_INLINE_INFO (decl
) = 0;
2082 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
2088 temp_name_counter
= 0;
2091 /* Hand off a unique name which can be used for variable we don't really
2092 want to know about anyway, for example, the anonymous variables which
2093 are needed to make references work. Declare this thing so we can use it.
2094 The variable created will be of type TYPE.
2096 STATICP is nonzero if this variable should be static. */
2099 get_temp_name (type
, staticp
)
2103 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2105 int toplev
= global_bindings_p ();
2107 push_obstacks_nochange ();
2108 if (toplev
|| staticp
)
2110 end_temporary_allocation ();
2111 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2112 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2116 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2117 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2119 TREE_USED (decl
) = 1;
2120 TREE_STATIC (decl
) = staticp
;
2122 /* If this is a local variable, then lay out its rtl now.
2123 Otherwise, callers of this function are responsible for dealing
2124 with this variable's rtl. */
2128 expand_decl_init (decl
);
2135 /* Get a variable which we can use for multiple assignments.
2136 It is not entered into current_binding_level, because
2137 that breaks things when it comes time to do final cleanups
2138 (which take place "outside" the binding contour of the function). */
2140 get_temp_regvar (type
, init
)
2143 static char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20] = { '_' };
2146 sprintf (buf
+1, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2147 decl
= build_decl (VAR_DECL
, get_identifier (buf
), type
);
2148 TREE_USED (decl
) = 1;
2149 DECL_REGISTER (decl
) = 1;
2152 store_init_value (decl
, init
);
2154 /* We can expand these without fear, since they cannot need
2155 constructors or destructors. */
2157 expand_decl_init (decl
);
2159 if (type_needs_gc_entry (type
))
2160 DECL_GC_OFFSET (decl
) = size_int (++current_function_obstack_index
);
2165 /* Make the macro TEMP_NAME_P available to units which do not
2166 include c-tree.h. */
2171 return TEMP_NAME_P (decl
);
2174 /* Finish off the processing of a UNION_TYPE structure.
2175 If there are static members, then all members are
2176 static, and must be laid out together. If the
2177 union is an anonymous union, we arrange for that
2178 as well. PUBLIC_P is nonzero if this union is
2179 not declared static. */
2181 finish_anon_union (anon_union_decl
)
2182 tree anon_union_decl
;
2184 tree type
= TREE_TYPE (anon_union_decl
);
2185 tree field
, main_decl
= NULL_TREE
;
2186 tree elems
= NULL_TREE
;
2187 int public_p
= TREE_PUBLIC (anon_union_decl
);
2188 int static_p
= TREE_STATIC (anon_union_decl
);
2189 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2191 if ((field
= TYPE_FIELDS (type
)) == NULL_TREE
)
2196 error ("global anonymous unions must be declared static");
2200 for (; field
; field
= TREE_CHAIN (field
))
2203 if (TREE_CODE (field
) != FIELD_DECL
)
2206 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2207 /* tell `pushdecl' that this is not tentative. */
2208 DECL_INITIAL (decl
) = error_mark_node
;
2209 TREE_PUBLIC (decl
) = public_p
;
2210 TREE_STATIC (decl
) = static_p
;
2211 DECL_EXTERNAL (decl
) = external_p
;
2212 decl
= pushdecl (decl
);
2214 /* Only write out one anon union element--choose the one that
2215 can hold them all. */
2216 if (main_decl
== NULL_TREE
2217 && simple_cst_equal (DECL_SIZE (decl
), DECL_SIZE (anon_union_decl
)))
2223 /* ??? This causes there to be no debug info written out
2225 TREE_ASM_WRITTEN (decl
) = 1;
2228 DECL_INITIAL (decl
) = NULL_TREE
;
2229 /* If there's a cleanup to do, it belongs in the
2230 TREE_PURPOSE of the following TREE_LIST. */
2231 elems
= tree_cons (NULL_TREE
, decl
, elems
);
2232 TREE_TYPE (elems
) = type
;
2238 make_decl_rtl (main_decl
, 0, global_bindings_p ());
2239 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2243 warning ("anonymous union with no members");
2248 /* The following call assumes that there are never any cleanups
2249 for anonymous unions--a reasonable assumption. */
2250 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2253 cadillac_finish_anon_union (anon_union_decl
);
2256 /* Finish and output a table which is generated by the compiler.
2257 NAME is the name to give the table.
2258 TYPE is the type of the table entry.
2259 INIT is all the elements in the table.
2260 PUBLICP is non-zero if this table should be given external access. */
2262 finish_table (name
, type
, init
, publicp
)
2263 tree name
, type
, init
;
2266 tree itype
, atype
, decl
;
2267 static tree empty_table
;
2271 itype
= build_index_type (size_int (list_length (init
) - 1));
2272 atype
= build_cplus_array_type (type
, itype
);
2273 layout_type (atype
);
2275 if (TREE_VALUE (init
) == integer_zero_node
2276 && TREE_CHAIN (init
) == NULL_TREE
)
2279 if (empty_table
== NULL_TREE
)
2282 empty_table
= get_temp_name (atype
, 1);
2283 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2284 TREE_CONSTANT (init
) = 1;
2285 TREE_STATIC (init
) = 1;
2286 DECL_INITIAL (empty_table
) = init
;
2287 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2288 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2289 finish_decl (empty_table
, init
, asmspec
, 0, 0);
2294 if (name
== NULL_TREE
)
2298 decl
= get_temp_name (atype
, 1);
2302 decl
= build_decl (VAR_DECL
, name
, atype
);
2303 decl
= pushdecl (decl
);
2304 TREE_STATIC (decl
) = 1;
2309 TREE_PUBLIC (decl
) = publicp
;
2310 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2311 TREE_CONSTANT (init
) = 1;
2312 TREE_STATIC (init
) = 1;
2313 DECL_INITIAL (decl
) = init
;
2314 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (decl
)),
2315 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2319 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2320 DECL_EXTERNAL (decl
) = 1;
2321 TREE_STATIC (decl
) = 0;
2323 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2324 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2327 finish_decl (decl
, init
, asmspec
, 0, 0);
2331 /* Finish processing a builtin type TYPE. It's name is NAME,
2332 its fields are in the array FIELDS. LEN is the number of elements
2333 in FIELDS minus one, or put another way, it is the maximum subscript
2336 It is given the same alignment as ALIGN_TYPE. */
2338 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2347 TYPE_FIELDS (type
) = fields
[0];
2348 for (i
= 0; i
< len
; i
++)
2350 layout_type (TREE_TYPE (fields
[i
]));
2351 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2352 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2354 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2355 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2356 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2358 #if 0 /* not yet, should get fixed properly later */
2359 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2361 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2363 layout_decl (TYPE_NAME (type
), 0);
2366 /* Auxiliary functions to make type signatures for
2367 `operator new' and `operator delete' correspond to
2368 what compiler will be expecting. */
2370 extern tree sizetype
;
2373 coerce_new_type (type
)
2378 if (TREE_CODE (type
) == METHOD_TYPE
)
2379 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2380 if (TREE_TYPE (type
) != ptr_type_node
)
2381 e1
= 1, error ("`operator new' must return type `void *'");
2383 /* Technically the type must be `size_t', but we may not know
2385 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2386 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2387 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type
))) != INTEGER_TYPE
2388 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type
))) != TYPE_PRECISION (sizetype
))
2389 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2391 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2393 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2398 coerce_delete_type (type
)
2401 int e1
= 0, e2
= 0, e3
= 0;
2402 tree arg_types
= TYPE_ARG_TYPES (type
);
2404 if (TREE_CODE (type
) == METHOD_TYPE
)
2406 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2407 arg_types
= TREE_CHAIN (arg_types
);
2409 if (TREE_TYPE (type
) != void_type_node
)
2410 e1
= 1, error ("`operator delete' must return type `void'");
2411 if (arg_types
== NULL_TREE
2412 || TREE_VALUE (arg_types
) != ptr_type_node
)
2413 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2416 && TREE_CHAIN (arg_types
)
2417 && TREE_CHAIN (arg_types
) != void_list_node
)
2419 /* Again, technically this argument must be `size_t', but again
2420 we may not know what that is. */
2421 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2422 if (TREE_CODE (t2
) != INTEGER_TYPE
2423 || TYPE_PRECISION (t2
) != TYPE_PRECISION (sizetype
))
2424 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2425 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2428 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2429 error ("too many arguments in declaration of `operator delete'");
2431 error ("`...' invalid in specification of `operator delete'");
2435 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, build_tree_list (NULL_TREE
, sizetype
));
2438 if (arg_types
== NULL_TREE
)
2439 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2441 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2446 type
= build_function_type (void_type_node
, arg_types
);
2452 mark_vtable_entries (decl
)
2455 tree entries
= TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl
)));
2457 for (; entries
; entries
= TREE_CHAIN (entries
))
2459 tree fnaddr
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
));
2460 tree fn
= TREE_OPERAND (fnaddr
, 0);
2461 TREE_ADDRESSABLE (fn
) = 1;
2462 if (DECL_ABSTRACT_VIRTUAL_P (fn
))
2464 extern tree abort_fndecl
;
2465 if (flag_vtable_thunks
)
2466 fnaddr
= TREE_VALUE (entries
);
2467 TREE_OPERAND (fnaddr
, 0) = fn
= abort_fndecl
;
2469 if (TREE_PUBLIC (fn
) && ! TREE_ASM_WRITTEN (fn
))
2471 int save_extern
= DECL_EXTERNAL (fn
);
2472 DECL_EXTERNAL (fn
) = 1;
2473 assemble_external (fn
);
2474 DECL_EXTERNAL (fn
) = save_extern
;
2479 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2480 based on TYPE and other static flags.
2482 Note that anything public is tagged TREE_PUBLIC, whether
2483 it's public in this file or in another one. */
2486 import_export_vtable (decl
, type
, final
)
2490 if (DECL_INTERFACE_KNOWN (decl
))
2494 if (write_virtuals
< 2 && write_virtuals
!= 0)
2496 TREE_PUBLIC (decl
) = 1;
2497 if (write_virtuals
< 0)
2498 DECL_EXTERNAL (decl
) = 1;
2499 DECL_INTERFACE_KNOWN (decl
) = 1;
2501 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2503 TREE_PUBLIC (decl
) = 1;
2504 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2505 DECL_INTERFACE_KNOWN (decl
) = 1;
2509 /* We can only wait to decide if we have real non-inline virtual
2510 functions in our class, or if we come from a template. */
2512 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2514 if (! found
&& ! final
)
2516 /* This check only works before the method definitions are seen,
2517 since DECL_INLINE may get bashed. */
2519 for (method
= CLASSTYPE_METHODS (type
); method
!= NULL_TREE
;
2520 method
= DECL_NEXT_METHOD (method
))
2521 if (DECL_VINDEX (method
) != NULL_TREE
&& ! DECL_INLINE (method
)
2522 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2529 if (final
|| ! found
)
2531 TREE_PUBLIC (decl
) = 0;
2532 DECL_EXTERNAL (decl
) = 0;
2533 DECL_INTERFACE_KNOWN (decl
) = 1;
2537 TREE_PUBLIC (decl
) = 1;
2538 DECL_EXTERNAL (decl
) = 1;
2539 DECL_INTERFACE_KNOWN (decl
) = 0;
2545 import_export_template (type
)
2548 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type
)
2549 && ! flag_implicit_templates
2550 && CLASSTYPE_INTERFACE_UNKNOWN (type
))
2552 SET_CLASSTYPE_INTERFACE_KNOWN (type
);
2553 CLASSTYPE_INTERFACE_ONLY (type
) = 1;
2554 CLASSTYPE_VTABLE_NEEDS_WRITING (type
) = 0;
2559 finish_prevtable_vardecl (prev
, vars
)
2562 tree ctype
= DECL_CONTEXT (vars
);
2563 import_export_template (ctype
);
2565 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype
) && TYPE_VIRTUAL_P (ctype
)
2566 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype
))
2569 for (method
= CLASSTYPE_METHODS (ctype
); method
!= NULL_TREE
;
2570 method
= DECL_NEXT_METHOD (method
))
2572 if (DECL_VINDEX (method
) != NULL_TREE
2573 && !DECL_DECLARED_STATIC (method
)
2574 && !DECL_ABSTRACT_VIRTUAL_P (method
))
2576 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2577 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
) = ! DECL_EXTERNAL (method
);
2578 CLASSTYPE_INTERFACE_ONLY (ctype
) = DECL_EXTERNAL (method
);
2584 import_export_vtable (vars
, ctype
, 1);
2586 /* We cannot use TREE_USED here, as it may be set by the expanding of a
2587 ctor that is used to build a global object. The long term plan is to
2588 make the TD entries statically initialized and move this to
2589 finish_vtable_vardecl time. */
2590 if (flag_rtti
&& write_virtuals
>= 0
2591 && ! DECL_EXTERNAL (vars
) && (TREE_PUBLIC (vars
) || 1 || TREE_USED (vars
)))
2593 /* Kick out the type descriptor before we dump out global
2594 initializers, as they are initialized at run time and
2595 we have to find them when we scan for things that need initialized
2596 at the top level. */
2597 build_t_desc (ctype
, 1);
2602 finish_vtable_vardecl (prev
, vars
)
2605 if (write_virtuals
>= 0
2606 && ! DECL_EXTERNAL (vars
) && (TREE_PUBLIC (vars
) || TREE_USED (vars
)))
2609 /* The long term plan it to make the TD entries statically initialized,
2610 have the entries built and emitted here. When that happens, this
2611 can be enabled, and the other call to build_t_desc removed. */
2612 /* Kick out the type descriptor before writing out the vtable. */
2614 build_t_desc (DECL_CONTEXT (vars
), 1);
2618 mark_vtable_entries (vars
);
2619 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2620 store_init_value (vars
, DECL_INITIAL (vars
));
2622 #ifdef DWARF_DEBUGGING_INFO
2623 if (write_symbols
== DWARF_DEBUG
)
2625 /* Mark the VAR_DECL node representing the vtable itself as a
2626 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2627 It is rather important that such things be ignored because
2628 any effort to actually generate DWARF for them will run
2629 into trouble when/if we encounter code like:
2632 struct S { virtual void member (); };
2634 because the artificial declaration of the vtable itself (as
2635 manufactured by the g++ front end) will say that the vtable
2636 is a static member of `S' but only *after* the debug output
2637 for the definition of `S' has already been output. This causes
2638 grief because the DWARF entry for the definition of the vtable
2639 will try to refer back to an earlier *declaration* of the
2640 vtable as a static member of `S' and there won't be one.
2641 We might be able to arrange to have the "vtable static member"
2642 attached to the member list for `S' before the debug info for
2643 `S' get written (which would solve the problem) but that would
2644 require more intrusive changes to the g++ front end. */
2646 DECL_IGNORED_P (vars
) = 1;
2648 #endif /* DWARF_DEBUGGING_INFO */
2650 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2652 else if (! TREE_USED (vars
))
2653 /* We don't know what to do with this one yet. */
2656 /* We know that PREV must be non-zero here. */
2657 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2661 prune_vtable_vardecl (prev
, vars
)
2664 /* We know that PREV must be non-zero here. */
2665 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2669 walk_vtables (typedecl_fn
, vardecl_fn
)
2670 register void (*typedecl_fn
)();
2671 register void (*vardecl_fn
)();
2675 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2677 register tree type
= TREE_TYPE (vars
);
2679 if (TREE_CODE (vars
) == VAR_DECL
&& DECL_VIRTUAL_P (vars
))
2681 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2683 if (prev
&& TREE_CHAIN (prev
) != vars
)
2686 else if (TREE_CODE (vars
) == TYPE_DECL
2687 && type
!= error_mark_node
2688 && TYPE_LANG_SPECIFIC (type
)
2689 && CLASSTYPE_VSIZE (type
))
2691 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2699 finish_sigtable_vardecl (prev
, vars
)
2702 /* We don't need to mark sigtable entries as addressable here as is done
2703 for vtables. Since sigtables, unlike vtables, are always written out,
2704 that was already done in build_signature_table_constructor. */
2706 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2708 /* We know that PREV must be non-zero here. */
2709 TREE_CHAIN (prev
) = TREE_CHAIN (vars
);
2713 walk_sigtables (typedecl_fn
, vardecl_fn
)
2714 register void (*typedecl_fn
)();
2715 register void (*vardecl_fn
)();
2719 for (prev
= 0, vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
2721 register tree type
= TREE_TYPE (vars
);
2723 if (TREE_CODE (vars
) == TYPE_DECL
2724 && type
!= error_mark_node
2725 && IS_SIGNATURE (type
))
2727 if (typedecl_fn
) (*typedecl_fn
) (prev
, vars
);
2729 else if (TREE_CODE (vars
) == VAR_DECL
2730 && TREE_TYPE (vars
) != error_mark_node
2731 && IS_SIGNATURE (TREE_TYPE (vars
)))
2733 if (vardecl_fn
) (*vardecl_fn
) (prev
, vars
);
2740 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2741 inline function at end-of-file. */
2744 import_export_inline (decl
)
2747 if (DECL_INTERFACE_KNOWN (decl
))
2750 DECL_EXTERNAL (decl
) = 0;
2752 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2754 if (DECL_IMPLICIT_INSTANTIATION (decl
) && flag_implicit_templates
)
2755 TREE_PUBLIC (decl
) = 0;
2757 DECL_EXTERNAL (decl
) = 1;
2759 else if (DECL_FUNCTION_MEMBER_P (decl
))
2761 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2762 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2764 DECL_EXTERNAL (decl
)
2765 = (CLASSTYPE_INTERFACE_ONLY (ctype
)
2766 || (DECL_INLINE (decl
) && ! flag_implement_inlines
));
2769 TREE_PUBLIC (decl
) = 0;
2772 TREE_PUBLIC (decl
) = 0;
2775 extern int parse_time
, varconst_time
;
2777 #define TIMEVAR(VAR, BODY) \
2778 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2780 /* This routine is called from the last rule in yyparse ().
2781 Its job is to create all the code needed to initialize and
2782 destroy the global aggregates. We do the destruction
2783 first, since that way we only need to reverse the decls once. */
2789 int start_time
, this_time
;
2792 tree vars
= static_aggregates
;
2793 int needs_cleaning
= 0, needs_messing_up
= 0;
2795 if (flag_detailed_statistics
)
2796 dump_tree_statistics ();
2798 /* Bad parse errors. Just forget about it. */
2799 if (! global_bindings_p () || current_class_type
)
2802 start_time
= get_run_time ();
2804 /* Push into C language context, because that's all
2806 push_lang_context (lang_name_c
);
2808 if (static_ctors
|| vars
|| might_have_exceptions_p ())
2809 needs_messing_up
= 1;
2813 /* See if we really need the hassle. */
2814 while (vars
&& needs_cleaning
== 0)
2816 tree decl
= TREE_VALUE (vars
);
2817 tree type
= TREE_TYPE (decl
);
2818 if (TYPE_NEEDS_DESTRUCTOR (type
))
2821 needs_messing_up
= 1;
2825 needs_messing_up
|= TYPE_NEEDS_CONSTRUCTING (type
);
2826 vars
= TREE_CHAIN (vars
);
2829 /* Otherwise, GDB can get confused, because in only knows
2830 about source for LINENO-1 lines. */
2833 interface_unknown
= 1;
2837 /* The reason for pushing garbage onto the global_binding_level is to
2838 ensure that we can slice out _DECLs which pertain to virtual function
2839 tables. If the last thing pushed onto the global_binding_level was a
2840 virtual function table, then slicing it out would slice away all the
2841 decls (i.e., we lose the head of the chain).
2843 There are several ways of getting the same effect, from changing the
2844 way that iterators over the chain treat the elements that pertain to
2845 virtual function tables, moving the implementation of this code to
2846 decl.c (where we can manipulate global_binding_level directly),
2847 popping the garbage after pushing it and slicing away the vtable
2848 stuff, or just leaving it alone. */
2850 /* Make last thing in global scope not be a virtual function table. */
2851 #if 0 /* not yet, should get fixed properly later */
2852 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
2854 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
2856 DECL_IGNORED_P (vars
) = 1;
2857 SET_DECL_ARTIFICIAL (vars
);
2861 /* Walk to mark the inline functions we need, then output them so
2862 that we can pick up any other tdecls that those routines need. */
2863 walk_vtables ((void (*)())0, finish_prevtable_vardecl
);
2865 if (needs_cleaning
== 0)
2868 fnname
= get_file_function_name ('D');
2869 start_function (void_list_node
, build_parse_node (CALL_EXPR
, fnname
, void_list_node
, NULL_TREE
), 0, 0);
2870 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2871 store_parm_decls ();
2876 expand_start_bindings (0);
2878 /* These must be done in backward order to destroy,
2879 in which they happen to be! */
2880 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
2882 tree decl
= TREE_VALUE (vars
);
2883 tree type
= TREE_TYPE (decl
);
2884 tree temp
= TREE_PURPOSE (vars
);
2886 if (TYPE_NEEDS_DESTRUCTOR (type
))
2888 if (TREE_STATIC (vars
))
2889 expand_start_cond (build_binary_op (NE_EXPR
, temp
, integer_zero_node
, 1), 0);
2890 if (TREE_CODE (type
) == ARRAY_TYPE
)
2894 mark_addressable (decl
);
2895 temp
= build1 (ADDR_EXPR
, TYPE_POINTER_TO (type
), decl
);
2897 temp
= build_delete (TREE_TYPE (temp
), temp
,
2898 integer_two_node
, LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2899 expand_expr_stmt (temp
);
2901 if (TREE_STATIC (vars
))
2906 for (; static_dtors
; static_dtors
= TREE_CHAIN (static_dtors
))
2907 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors
),
2910 expand_end_bindings (getdecls(), 1, 0);
2914 finish_function (lineno
, 0, 0);
2916 assemble_destructor (IDENTIFIER_POINTER (fnname
));
2918 /* if it needed cleaning, then it will need messing up: drop through */
2921 /* Must do this while we think we are at the top level. */
2922 vars
= nreverse (static_aggregates
);
2923 if (needs_messing_up
)
2925 fnname
= get_file_function_name ('I');
2926 start_function (void_list_node
, build_parse_node (CALL_EXPR
, fnname
, void_list_node
, NULL_TREE
), 0, 0);
2927 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2928 store_parm_decls ();
2933 expand_start_bindings (0);
2935 if (might_have_exceptions_p ())
2936 register_exception_table ();
2940 tree decl
= TREE_VALUE (vars
);
2941 tree init
= TREE_PURPOSE (vars
);
2942 tree old_cleanups
= cleanups_this_call
;
2944 /* If this was a static attribute within some function's scope,
2945 then don't initialize it here. Also, don't bother
2946 with initializers that contain errors. */
2947 if (TREE_STATIC (vars
)
2948 || (init
&& TREE_CODE (init
) == TREE_LIST
2949 && value_member (error_mark_node
, init
)))
2951 vars
= TREE_CHAIN (vars
);
2955 if (TREE_CODE (decl
) == VAR_DECL
)
2957 /* Set these global variables so that GDB at least puts
2958 us near the declaration which required the initialization. */
2959 input_filename
= DECL_SOURCE_FILE (decl
);
2960 lineno
= DECL_SOURCE_LINE (decl
);
2961 emit_note (input_filename
, lineno
);
2963 /* 9.5p5: The initializer of a static member of a class has
2964 the same acess rights as a member function. */
2965 DECL_CLASS_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
2966 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
2971 if (TREE_CODE (init
) == VAR_DECL
)
2973 /* This behavior results when there are
2974 multiple declarations of an aggregate,
2975 the last of which defines it. */
2976 if (DECL_RTL (init
) == DECL_RTL (decl
))
2978 my_friendly_assert (DECL_INITIAL (decl
) == error_mark_node
2979 || (TREE_CODE (DECL_INITIAL (decl
)) == CONSTRUCTOR
2980 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl
)) == NULL_TREE
),
2982 init
= DECL_INITIAL (init
);
2983 if (TREE_CODE (init
) == CONSTRUCTOR
2984 && CONSTRUCTOR_ELTS (init
) == NULL_TREE
)
2987 else if (TREE_TYPE (decl
) == TREE_TYPE (init
))
2990 my_friendly_abort (200);
2992 /* point to real decl's rtl anyway. */
2993 DECL_RTL (init
) = DECL_RTL (decl
);
2994 my_friendly_assert (DECL_INITIAL (decl
) == error_mark_node
,
2996 init
= DECL_INITIAL (init
);
3002 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3003 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3004 expand_aggr_init (decl
, init
, 0, 0);
3005 else if (TREE_CODE (init
) == TREE_VEC
)
3007 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3008 TREE_VEC_ELT (init
, 1),
3009 TREE_VEC_ELT (init
, 2), 0),
3010 const0_rtx
, VOIDmode
, 0);
3014 expand_assignment (decl
, init
, 0, 0);
3016 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3018 else if (TREE_CODE (decl
) == SAVE_EXPR
)
3020 if (! PARM_DECL_EXPR (decl
))
3022 /* a `new' expression at top level. */
3023 expand_expr (decl
, const0_rtx
, VOIDmode
, 0);
3025 expand_aggr_init (build_indirect_ref (decl
, NULL_PTR
), init
, 0, 0);
3028 else if (decl
== error_mark_node
)
3030 else my_friendly_abort (22);
3031 vars
= TREE_CHAIN (vars
);
3032 /* Cleanup any temporaries needed for the initial value. */
3033 expand_cleanups_to (old_cleanups
);
3036 for (; static_ctors
; static_ctors
= TREE_CHAIN (static_ctors
))
3037 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors
),
3040 expand_end_bindings (getdecls(), 1, 0);
3044 finish_function (lineno
, 0, 0);
3045 assemble_constructor (IDENTIFIER_POINTER (fnname
));
3048 /* Done with C language context needs. */
3049 pop_lang_context ();
3051 /* Now write out any static class variables (which may have since
3052 learned how to be initialized). */
3053 while (pending_statics
)
3055 tree decl
= TREE_VALUE (pending_statics
);
3056 if (TREE_USED (decl
) == 1
3057 || TREE_READONLY (decl
) == 0
3058 || DECL_INITIAL (decl
) == 0)
3059 rest_of_decl_compilation (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), 1, 1);
3060 pending_statics
= TREE_CHAIN (pending_statics
);
3063 this_time
= get_run_time ();
3064 parse_time
-= this_time
- start_time
;
3065 varconst_time
+= this_time
- start_time
;
3067 start_time
= get_run_time ();
3069 if (flag_handle_signatures
)
3070 walk_sigtables ((void (*)())0, finish_sigtable_vardecl
);
3072 for (fnname
= saved_inlines
; fnname
; fnname
= TREE_CHAIN (fnname
))
3073 import_export_inline (TREE_VALUE (fnname
));
3075 /* Now write out inline functions which had their addresses taken and
3076 which were not declared virtual and which were not declared `extern
3079 int reconsider
= 1; /* More may be referenced; check again */
3080 saved_inlines
= tree_cons (NULL_TREE
, NULL_TREE
, saved_inlines
);
3084 tree last
= saved_inlines
;
3085 tree place
= TREE_CHAIN (saved_inlines
);
3088 walk_vtables ((void (*)())0, finish_vtable_vardecl
);
3090 for (; place
; place
= TREE_CHAIN (place
))
3092 tree decl
= TREE_VALUE (place
);
3094 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
))
3096 if (TREE_USED (decl
)
3097 || (TREE_PUBLIC (decl
) && ! DECL_EXTERNAL (decl
)))
3098 synthesize_method (decl
);
3106 if (TREE_ASM_WRITTEN (decl
) || DECL_SAVED_INSNS (decl
) == 0)
3108 TREE_CHAIN (last
) = TREE_CHAIN (place
);
3112 if (TREE_PUBLIC (decl
)
3113 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
3114 || flag_keep_inline_functions
)
3116 TREE_CHAIN (last
) = TREE_CHAIN (place
);
3118 if (! DECL_EXTERNAL (decl
))
3121 temporary_allocation ();
3122 output_inline_function (decl
);
3123 permanent_allocation (1);
3134 /* Now delete from the chain of variables all virtual function tables.
3135 We output them all ourselves, because each will be treated specially. */
3137 walk_vtables ((void (*)())0, prune_vtable_vardecl
);
3139 for (vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
3141 if (TREE_CODE (vars
) == THUNK_DECL
)
3143 else if (TREE_CODE (vars
) == FUNCTION_DECL
3144 && ! DECL_INTERFACE_KNOWN (vars
)
3145 && DECL_DECLARED_STATIC (vars
))
3146 TREE_PUBLIC (vars
) = 0;
3149 if (might_have_exceptions_p ())
3150 emit_exception_table ();
3152 if (write_virtuals
== 2)
3154 /* Now complain about an virtual function tables promised
3155 but not delivered. */
3156 while (pending_vtables
)
3158 if (TREE_PURPOSE (pending_vtables
) == NULL_TREE
)
3159 error ("virtual function table for `%s' not defined",
3160 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables
)));
3161 pending_vtables
= TREE_CHAIN (pending_vtables
);
3165 permanent_allocation (1);
3166 this_time
= get_run_time ();
3167 parse_time
-= this_time
- start_time
;
3168 varconst_time
+= this_time
- start_time
;
3170 if (flag_detailed_statistics
)
3171 dump_time_statistics ();
3174 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3175 expr. Since it was parsed like a type, we need to wade through and fix
3176 that. Unfortunately, since operator() is left-associative, we can't use
3177 tail recursion. In the above example, TYPE is `A', and DECL is
3180 Maybe this shouldn't be recursive, but how often will it actually be
3183 reparse_absdcl_as_expr (type
, decl
)
3186 /* do build_functional_cast (type, NULL_TREE) at bottom */
3187 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3188 return build_functional_cast (type
, NULL_TREE
);
3191 decl
= reparse_decl_as_expr (type
, TREE_OPERAND (decl
, 0));
3193 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_decl
);
3195 if (TREE_CODE (decl
) == CALL_EXPR
&& TREE_TYPE (decl
) != void_type_node
)
3196 decl
= require_complete_type (decl
);
3201 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3202 out to be an expr. Since it was parsed like a type, we need to wade
3203 through and fix that. Since casts are right-associative, we are
3204 reversing the order, so we don't have to recurse.
3206 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3209 reparse_absdcl_as_casts (decl
, expr
)
3214 if (TREE_CODE (expr
) == CONSTRUCTOR
)
3216 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3217 decl
= TREE_OPERAND (decl
, 0);
3219 if (IS_SIGNATURE (type
))
3221 error ("cast specifies signature type");
3222 return error_mark_node
;
3225 expr
= digest_init (type
, expr
, (tree
*) 0);
3226 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3228 int failure
= complete_array_type (type
, expr
, 1);
3230 my_friendly_abort (78);
3236 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3237 decl
= TREE_OPERAND (decl
, 0);
3238 expr
= build_c_cast (type
, expr
, 0);
3244 /* Recursive helper function for reparse_decl_as_expr. It may be a good
3245 idea to reimplement this using an explicit stack, rather than recursion. */
3247 reparse_decl_as_expr1 (decl
)
3250 switch (TREE_CODE (decl
))
3252 case IDENTIFIER_NODE
:
3253 return do_identifier (decl
);
3255 return build_x_indirect_ref
3256 (reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)), "unary *");
3258 return build_x_unary_op (ADDR_EXPR
,
3259 reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)));
3261 return build_x_unary_op (BIT_NOT_EXPR
,
3262 reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)));
3264 return build_offset_ref (TREE_OPERAND (decl
, 0), TREE_OPERAND (decl
, 1));
3266 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)),
3267 TREE_OPERAND (decl
, 1));
3269 my_friendly_abort (5);
3274 /* This is something of the form `int (*a)++' that has turned out to be an
3275 expr. It was only converted into parse nodes, so we need to go through
3276 and build up the semantics. Most of the work is done by
3277 reparse_decl_as_expr1, above.
3279 In the above example, TYPE is `int' and DECL is `*a'. */
3281 reparse_decl_as_expr (type
, decl
)
3284 decl
= reparse_decl_as_expr1 (decl
);
3286 return build_functional_cast (type
, build_tree_list (NULL_TREE
, decl
));
3291 /* This is something of the form `int (*a)' that has turned out to be a
3292 decl. It was only converted into parse nodes, so we need to do the
3293 checking that make_{pointer,reference}_declarator do. */
3296 finish_decl_parsing (decl
)
3299 extern int current_class_depth
;
3301 switch (TREE_CODE (decl
))
3303 case IDENTIFIER_NODE
:
3306 return make_pointer_declarator
3307 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3309 return make_reference_declarator
3310 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3312 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3315 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3316 TREE_COMPLEXITY (decl
) = current_class_depth
;
3319 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3322 my_friendly_abort (5);
3328 check_cp_case_value (value
)
3331 if (value
== NULL_TREE
)
3334 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3335 Strip such NOP_EXPRs. */
3336 if (TREE_CODE (value
) == NOP_EXPR
3337 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
3338 value
= TREE_OPERAND (value
, 0);
3340 if (TREE_READONLY_DECL_P (value
))
3342 value
= decl_constant_value (value
);
3343 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3344 Strip such NOP_EXPRs. */
3345 if (TREE_CODE (value
) == NOP_EXPR
3346 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
3347 value
= TREE_OPERAND (value
, 0);
3349 value
= fold (value
);
3351 if (TREE_CODE (value
) != INTEGER_CST
3352 && value
!= error_mark_node
)
3354 cp_error ("case label `%E' does not reduce to an integer constant",
3356 value
= error_mark_node
;
3359 /* Promote char or short to int. */
3360 value
= default_conversion (value
);
3362 constant_expression_warning (value
);
3367 static tree current_namespace
;
3369 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3370 postfix. Returns 0 if in global namespace. */
3374 tree x
= current_namespace
;
3376 x
= TREE_PURPOSE (x
);
3380 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3382 current_namespace_id (name
)
3385 tree old_id
= get_namespace_id ();
3388 /* Global names retain old encoding. */
3392 buf
= (char *) alloca (8 + IDENTIFIER_LENGTH (old_id
)
3393 + IDENTIFIER_LENGTH (name
));
3394 sprintf (buf
, "__ns_%s_%s", IDENTIFIER_POINTER (old_id
),
3395 IDENTIFIER_POINTER (name
));
3396 return get_identifier (buf
);
3399 /* Push into the scopre of the NAME namespace. */
3401 push_namespace (name
)
3404 tree old_id
= get_namespace_id ();
3407 current_namespace
= tree_cons (NULL_TREE
, name
, current_namespace
);
3408 buf
= (char *) alloca (4 + (old_id
? IDENTIFIER_LENGTH (old_id
) : 0)
3409 + IDENTIFIER_LENGTH (name
));
3410 sprintf (buf
, "%s%s", old_id
? IDENTIFIER_POINTER (old_id
) : "",
3411 IDENTIFIER_POINTER (name
));
3412 TREE_PURPOSE (current_namespace
) = get_identifier (buf
);
3415 /* Pop from the scope of the current namespace. */
3419 current_namespace
= TREE_CHAIN (current_namespace
);
3423 do_namespace_alias (alias
, namespace)
3424 tree alias
, namespace;
3429 do_using_decl (decl
)
3432 return error_mark_node
;
3436 do_using_directive (namespace)