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 /* True if we want to deal with repository information. */
153 int flag_use_repository
;
155 /* Nonzero means give string constants the type `const char *'
156 to get extra warnings from them. These warnings will be too numerous
157 to be useful, except in thoroughly ANSIfied programs. */
159 int warn_write_strings
;
161 /* Nonzero means warn about pointer casts that can drop a type qualifier
162 from the pointer target type. */
166 /* Nonzero means warn that dbx info for template class methods isn't fully
169 int warn_template_debugging
;
171 /* Warn about traditional constructs whose meanings changed in ANSI C. */
173 int warn_traditional
;
175 /* Nonzero means warn about sizeof(function) or addition/subtraction
176 of function pointers. */
178 int warn_pointer_arith
;
180 /* Nonzero means warn for non-prototype function decls
181 or non-prototyped defs without previous prototype. */
183 int warn_strict_prototypes
;
185 /* Nonzero means warn for any function def without prototype decl. */
187 int warn_missing_prototypes
;
189 /* Nonzero means warn about multiple (redundant) decls for the same single
190 variable or function. */
192 int warn_redundant_decls
;
194 /* Warn if initializer is not completely bracketed. */
196 int warn_missing_braces
;
198 /* Warn about *printf or *scanf format/argument anomalies. */
202 /* Warn about a subscript that has type char. */
204 int warn_char_subscripts
;
206 /* Warn if a type conversion is done that might have confusing results. */
210 /* Warn if adding () is suggested. */
212 int warn_parentheses
;
214 /* Non-zero means warn in function declared in derived class has the
215 same name as a virtual in the base class, but fails to match the
216 type signature of any virtual function in the base class. */
217 int warn_overloaded_virtual
;
219 /* Non-zero means warn when declaring a class that has a non virtual
220 destructor, when it really ought to have a virtual one. */
223 /* Non-zero means warn when a function is declared extern and later inline. */
224 int warn_extern_inline
;
226 /* Non-zero means warn when the compiler will reorder code. */
229 /* Non-zero means warn when sysnthesis behavior differs from Cfront's. */
232 /* Nonzero means `$' can be in an identifier.
233 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
235 #ifndef DOLLARS_IN_IDENTIFIERS
236 #define DOLLARS_IN_IDENTIFIERS 1
238 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
240 /* Nonzero for -fno-strict-prototype switch: do not consider empty
241 argument prototype to mean function takes no arguments. */
243 int flag_strict_prototype
= 2;
244 int strict_prototype
= 1;
245 int strict_prototypes_lang_c
, strict_prototypes_lang_cplusplus
= 1;
247 /* Nonzero means that labels can be used as first-class objects */
251 /* Non-zero means to collect statistics which might be expensive
252 and to print them when we are done. */
253 int flag_detailed_statistics
;
255 /* C++ specific flags. */
256 /* Nonzero for -fall-virtual: make every member function (except
257 constructors) lay down in the virtual function table. Calls
258 can then either go through the virtual function table or not,
261 int flag_all_virtual
;
263 /* Zero means that `this' is a *const. This gives nice behavior in the
264 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
265 -2 means we're constructing an object and it has fixed type. */
267 int flag_this_is_variable
;
269 /* Nonzero means memoize our member lookups. */
271 int flag_memoize_lookups
; int flag_save_memoized_contexts
;
273 /* 3 means write out only virtuals function tables `defined'
274 in this implementation file.
275 2 means write out only specific virtual function tables
276 and give them (C) public access.
277 1 means write out virtual function tables and give them
279 0 means write out virtual function tables and give them
280 (C) static access (default).
281 -1 means declare virtual function tables extern. */
285 /* Nonzero means we should attempt to elide constructors when possible. */
287 int flag_elide_constructors
;
289 /* Nonzero means recognize and handle exception handling constructs.
290 Use ansi syntax and semantics. WORK IN PROGRESS! */
292 int flag_handle_exceptions
;
294 /* Nonzero means recognize and handle signature language constructs. */
296 int flag_handle_signatures
;
298 /* Nonzero means that member functions defined in class scope are
299 inline by default. */
301 int flag_default_inline
= 1;
303 /* Controls whether enums and ints freely convert.
304 1 means with complete freedom.
305 0 means enums can convert to ints, but not vice-versa. */
306 int flag_int_enum_equivalence
;
308 /* Controls whether compiler is operating under LUCID's Cadillac
309 system. 1 means yes, 0 means no. */
312 /* Controls whether compiler generates code to build objects
313 that can be collected when they become garbage. */
316 /* Controls whether compiler generates 'type descriptor' that give
317 run-time type information. */
320 /* Nonzero if we wish to output cross-referencing information
321 for the GNU class browser. */
322 extern int flag_gnu_xref
;
324 /* Nonzero if compiler can make `reasonable' assumptions about
325 references and objects. For example, the compiler must be
326 conservative about the following and not assume that `a' is nonnull:
331 In general, it is `reasonable' to assume that for many programs,
332 and better code can be generated in that case. */
334 int flag_assume_nonnull_objects
= 1;
336 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
339 int flag_huge_objects
;
341 /* Nonzero if we want to conserve space in the .o files. We do this
342 by putting uninitialized data and runtime initialized data into
343 .common instead of .data at the expense of not flaging multiple
346 int flag_conserve_space
;
348 /* Nonzero if we want to obey access control semantics. */
350 int flag_access_control
= 1;
352 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
354 int flag_operator_names
;
356 /* Nonzero if we want to check the return value of new and avoid calling
357 constructors if it is a null pointer. */
361 /* Table of language-dependent -f options.
362 STRING is the option name. VARIABLE is the address of the variable.
363 ON_VALUE is the value to store in VARIABLE
364 if `-fSTRING' is seen as an option.
365 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
367 static struct { char *string
; int *variable
; int on_value
;} lang_f_options
[] =
369 {"signed-char", &flag_signed_char
, 1},
370 {"unsigned-char", &flag_signed_char
, 0},
371 {"signed-bitfields", &flag_signed_bitfields
, 1},
372 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
373 {"short-enums", &flag_short_enums
, 1},
374 {"short-double", &flag_short_double
, 1},
375 {"cond-mismatch", &flag_cond_mismatch
, 1},
376 {"asm", &flag_no_asm
, 0},
377 {"builtin", &flag_no_builtin
, 0},
378 {"ident", &flag_no_ident
, 0},
379 {"labels-ok", &flag_labels_ok
, 1},
380 {"stats", &flag_detailed_statistics
, 1},
381 {"this-is-variable", &flag_this_is_variable
, 1},
382 {"strict-prototype", &flag_strict_prototype
, 1},
383 {"all-virtual", &flag_all_virtual
, 1},
384 {"memoize-lookups", &flag_memoize_lookups
, 1},
385 {"elide-constructors", &flag_elide_constructors
, 1},
386 {"handle-exceptions", &flag_handle_exceptions
, 1},
387 {"handle-signatures", &flag_handle_signatures
, 1},
388 {"default-inline", &flag_default_inline
, 1},
389 {"dollars-in-identifiers", &dollars_in_ident
, 1},
390 {"enum-int-equiv", &flag_int_enum_equivalence
, 1},
392 {"rtti", &flag_rtti
, 1},
393 {"xref", &flag_gnu_xref
, 1},
394 {"nonnull-objects", &flag_assume_nonnull_objects
, 1},
395 {"implement-inlines", &flag_implement_inlines
, 1},
396 {"external-templates", &flag_external_templates
, 1},
397 {"implicit-templates", &flag_implicit_templates
, 1},
398 {"huge-objects", &flag_huge_objects
, 1},
399 {"conserve-space", &flag_conserve_space
, 1},
400 {"vtable-thunks", &flag_vtable_thunks
, 1},
401 {"short-temps", &flag_short_temps
, 1},
402 {"access-control", &flag_access_control
, 1},
403 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
404 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
405 {"operator-names", &flag_operator_names
, 1},
406 {"check-new", &flag_check_new
, 1},
407 {"repo", &flag_use_repository
, 1}
410 /* Decode the string P as a language-specific option.
411 Return 1 if it is recognized (and handle it);
412 return 0 if not recognized. */
415 lang_decode_option (p
)
418 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
419 flag_traditional
= 1, dollars_in_ident
= 1, flag_writable_strings
= 1,
420 flag_this_is_variable
= 1;
421 /* The +e options are for cfront compatibility. They come in as
422 `-+eN', to kludge around gcc.c's argument handling. */
423 else if (p
[0] == '-' && p
[1] == '+' && p
[2] == 'e')
425 int old_write_virtuals
= write_virtuals
;
428 else if (p
[3] == '0')
430 else if (p
[3] == '2')
432 else error ("invalid +e option");
433 if (old_write_virtuals
!= 0
434 && write_virtuals
!= old_write_virtuals
)
435 error ("conflicting +e options given");
437 else if (p
[0] == '-' && p
[1] == 'f')
439 /* Some kind of -f option.
440 P's value is the option sans `-f'.
441 Search for it in the table of options. */
445 /* Try special -f options. */
447 if (!strcmp (p
, "save-memoized"))
449 flag_memoize_lookups
= 1;
450 flag_save_memoized_contexts
= 1;
453 if (!strcmp (p
, "no-save-memoized"))
455 flag_memoize_lookups
= 0;
456 flag_save_memoized_contexts
= 0;
459 else if (! strncmp (p
, "cadillac", 8))
461 flag_cadillac
= atoi (p
+9);
464 else if (! strncmp (p
, "no-cadillac", 11))
469 else if (! strcmp (p
, "gc"))
472 /* This must come along for the ride. */
476 else if (! strcmp (p
, "no-gc"))
479 /* This must come along for the ride. */
483 else if (! strcmp (p
, "alt-external-templates"))
485 flag_external_templates
= 1;
486 flag_alt_external_templates
= 1;
489 else if (! strcmp (p
, "no-alt-external-templates"))
491 flag_alt_external_templates
= 0;
494 else if (!strcmp (p
, "ansi-overloading"))
496 warning ("-fansi-overloading is no longer meaningful");
499 !found
&& j
< sizeof (lang_f_options
) / sizeof (lang_f_options
[0]);
502 if (!strcmp (p
, lang_f_options
[j
].string
))
504 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
505 /* A goto here would be cleaner,
506 but breaks the vax pcc. */
509 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
510 && ! strcmp (p
+3, lang_f_options
[j
].string
))
512 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
518 else if (p
[0] == '-' && p
[1] == 'W')
522 /* The -W options control the warning behavior of the compiler. */
525 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
528 if (!strcmp (p
, "implicit"))
529 warn_implicit
= setting
;
530 else if (!strcmp (p
, "return-type"))
531 warn_return_type
= setting
;
532 else if (!strcmp (p
, "ctor-dtor-privacy"))
533 warn_ctor_dtor_privacy
= setting
;
534 else if (!strcmp (p
, "write-strings"))
535 warn_write_strings
= setting
;
536 else if (!strcmp (p
, "cast-qual"))
537 warn_cast_qual
= setting
;
538 else if (!strcmp (p
, "traditional"))
539 warn_traditional
= setting
;
540 else if (!strcmp (p
, "char-subscripts"))
541 warn_char_subscripts
= setting
;
542 else if (!strcmp (p
, "pointer-arith"))
543 warn_pointer_arith
= setting
;
544 else if (!strcmp (p
, "strict-prototypes"))
545 warn_strict_prototypes
= setting
;
546 else if (!strcmp (p
, "missing-prototypes"))
547 warn_missing_prototypes
= setting
;
548 else if (!strcmp (p
, "redundant-decls"))
549 warn_redundant_decls
= setting
;
550 else if (!strcmp (p
, "missing-braces"))
551 warn_missing_braces
= setting
;
552 else if (!strcmp (p
, "format"))
553 warn_format
= setting
;
554 else if (!strcmp (p
, "conversion"))
555 warn_conversion
= setting
;
556 else if (!strcmp (p
, "parentheses"))
557 warn_parentheses
= setting
;
558 else if (!strcmp (p
, "non-virtual-dtor"))
559 warn_nonvdtor
= setting
;
560 else if (!strcmp (p
, "extern-inline"))
561 warn_extern_inline
= setting
;
562 else if (!strcmp (p
, "reorder"))
563 warn_reorder
= setting
;
564 else if (!strcmp (p
, "synth"))
565 warn_synth
= setting
;
566 else if (!strcmp (p
, "comment"))
567 ; /* cpp handles this one. */
568 else if (!strcmp (p
, "comments"))
569 ; /* cpp handles this one. */
570 else if (!strcmp (p
, "trigraphs"))
571 ; /* cpp handles this one. */
572 else if (!strcmp (p
, "import"))
573 ; /* cpp handles this one. */
574 else if (!strcmp (p
, "all"))
576 extra_warnings
= setting
;
577 warn_return_type
= setting
;
578 warn_unused
= setting
;
579 warn_implicit
= setting
;
580 warn_ctor_dtor_privacy
= setting
;
581 warn_switch
= setting
;
582 warn_format
= setting
;
583 warn_parentheses
= setting
;
584 warn_missing_braces
= setting
;
585 warn_extern_inline
= setting
;
586 warn_nonvdtor
= setting
;
587 /* We save the value of warn_uninitialized, since if they put
588 -Wuninitialized on the command line, we need to generate a
589 warning about not using it without also specifying -O. */
590 if (warn_uninitialized
!= 1)
591 warn_uninitialized
= (setting
? 2 : 0);
592 warn_template_debugging
= setting
;
593 warn_reorder
= setting
;
596 else if (!strcmp (p
, "overloaded-virtual"))
597 warn_overloaded_virtual
= setting
;
600 else if (!strcmp (p
, "-ansi"))
601 dollars_in_ident
= 0, flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
602 flag_no_gnu_keywords
= 1, flag_operator_names
= 1;
604 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
605 it's probably safe to assume no sane person would ever want to use this
606 under normal circumstances. */
607 else if (!strcmp (p
, "-spew-debug"))
616 /* Incorporate `const' and `volatile' qualifiers for member functions.
617 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
618 QUALS is a list of qualifiers. */
620 grok_method_quals (ctype
, function
, quals
)
621 tree ctype
, function
, quals
;
623 tree fntype
= TREE_TYPE (function
);
624 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
628 extern tree ridpointers
[];
630 if (TREE_VALUE (quals
) == ridpointers
[(int)RID_CONST
])
632 if (TYPE_READONLY (ctype
))
633 error ("duplicate `%s' %s",
634 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
635 (TREE_CODE (function
) == FUNCTION_DECL
636 ? "for member function" : "in type declaration"));
637 ctype
= build_type_variant (ctype
, 1, TYPE_VOLATILE (ctype
));
638 build_pointer_type (ctype
);
640 else if (TREE_VALUE (quals
) == ridpointers
[(int)RID_VOLATILE
])
642 if (TYPE_VOLATILE (ctype
))
643 error ("duplicate `%s' %s",
644 IDENTIFIER_POINTER (TREE_VALUE (quals
)),
645 (TREE_CODE (function
) == FUNCTION_DECL
646 ? "for member function" : "in type declaration"));
647 ctype
= build_type_variant (ctype
, TYPE_READONLY (ctype
), 1);
648 build_pointer_type (ctype
);
651 my_friendly_abort (20);
652 quals
= TREE_CHAIN (quals
);
655 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
656 (TREE_CODE (fntype
) == METHOD_TYPE
657 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
658 : TYPE_ARG_TYPES (fntype
)));
660 fntype
= build_exception_variant (ctype
, fntype
, raises
);
662 TREE_TYPE (function
) = fntype
;
666 #if 0 /* Not used. */
667 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
668 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
669 /* This does not yet work with user defined conversion operators
672 substitute_nice_name (decl
)
675 if (DECL_NAME (decl
) && TREE_CODE (DECL_NAME (decl
)) == IDENTIFIER_NODE
)
677 char *n
= decl_as_string (DECL_NAME (decl
), 1);
678 if (n
[strlen (n
) - 1] == ' ')
679 n
[strlen (n
) - 1] = 0;
680 DECL_NAME (decl
) = get_identifier (n
);
685 /* Warn when -fexternal-templates is used and #pragma
686 interface/implementation is not used all the times it should be,
689 warn_if_unknown_interface (decl
)
692 static int already_warned
= 0;
693 if (already_warned
++)
696 if (flag_alt_external_templates
)
698 struct tinst_level
*til
= tinst_for_decl ();
700 char *sf
= input_filename
;
703 input_filename
= til
->file
;
704 cp_warning ("template `%#D' instantiated in file without #pragma interface",
710 cp_warning_at ("template `%#D' defined in file without #pragma interface",
714 /* A subroutine of the parser, to handle a component list. */
716 grok_x_components (specs
, components
)
717 tree specs
, components
;
719 register tree t
, x
, tcode
;
721 /* We just got some friends. They have been recorded elsewhere. */
722 if (components
== void_type_node
)
725 if (components
== NULL_TREE
)
727 t
= groktypename (build_decl_list (specs
, NULL_TREE
));
731 error ("error in component specification");
735 switch (TREE_CODE (t
))
738 /* Static anonymous unions come out as VAR_DECLs. */
739 if (TREE_CODE (TREE_TYPE (t
)) == UNION_TYPE
740 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t
))))
743 /* We return SPECS here, because in the parser it was ending
744 up with not doing anything to $$, which is what SPECS
750 /* This code may be needed for UNION_TYPEs as
752 tcode
= record_type_node
;
753 if (CLASSTYPE_DECLARED_CLASS(t
))
754 tcode
= class_type_node
;
755 else if (IS_SIGNATURE(t
))
756 tcode
= signature_type_node
;
758 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
760 CLASSTYPE_NO_GLOBALIZE(t
) = 1;
766 if (TREE_CODE(t
) == UNION_TYPE
)
767 tcode
= union_type_node
;
769 tcode
= enum_type_node
;
771 t
= xref_tag (tcode
, TYPE_IDENTIFIER (t
), NULL_TREE
, 0);
772 if (TREE_CODE(t
) == UNION_TYPE
&& TYPE_CONTEXT(t
))
773 CLASSTYPE_NO_GLOBALIZE(t
) = 1;
774 if (TREE_CODE (t
) == UNION_TYPE
775 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))
777 struct pending_inline
**p
;
778 x
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, t
);
780 /* Wipe out memory of synthesized methods */
781 TYPE_HAS_CONSTRUCTOR (t
) = 0;
782 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
783 TYPE_HAS_INIT_REF (t
) = 0;
784 TYPE_HAS_CONST_INIT_REF (t
) = 0;
785 TYPE_HAS_ASSIGN_REF (t
) = 0;
786 TYPE_HAS_ASSIGNMENT (t
) = 0;
787 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
789 p
= &pending_inlines
;
790 for (; *p
; *p
= (*p
)->next
)
791 if (DECL_CONTEXT ((*p
)->fndecl
) != t
)
794 else if (TREE_CODE (t
) == ENUMERAL_TYPE
)
795 x
= grok_enum_decls (t
, NULL_TREE
);
802 if (t
!= void_type_node
)
803 error ("empty component declaration");
809 t
= TREE_TYPE (components
);
810 if (TREE_CODE (t
) == ENUMERAL_TYPE
&& TREE_NONLOCAL_FLAG (t
))
811 return grok_enum_decls (t
, components
);
817 /* Classes overload their constituent function names automatically.
818 When a function name is declared in a record structure,
819 its name is changed to it overloaded name. Since names for
820 constructors and destructors can conflict, we place a leading
823 CNAME is the name of the class we are grokking for.
825 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
827 FLAGS contains bits saying what's special about today's
828 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
830 If FUNCTION is a destructor, then we must add the `auto-delete' field
831 as a second parameter. There is some hair associated with the fact
832 that we must "declare" this variable in the manner consistent with the
833 way the rest of the arguments were declared.
835 QUALS are the qualifiers for the this pointer. */
838 grokclassfn (ctype
, cname
, function
, flags
, quals
)
839 tree ctype
, cname
, function
;
840 enum overload_flags flags
;
843 tree fn_name
= DECL_NAME (function
);
848 if (fn_name
== NULL_TREE
)
850 error ("name missing for member function");
851 fn_name
= get_identifier ("<anonymous>");
852 DECL_NAME (function
) = fn_name
;
856 qualtype
= grok_method_quals (ctype
, function
, quals
);
860 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
861 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
863 /* Must add the class instance variable up front. */
864 /* Right now we just make this a pointer. But later
865 we may wish to make it special. */
866 tree type
= TREE_VALUE (arg_types
);
868 if ((flag_this_is_variable
> 0)
869 && (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
)))
870 type
= TYPE_MAIN_VARIANT (type
);
872 if (DECL_CONSTRUCTOR_P (function
))
874 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype
))
876 DECL_CONSTRUCTOR_FOR_VBASE_P (function
) = 1;
877 /* In this case we need "in-charge" flag saying whether
878 this constructor is responsible for initialization
879 of virtual baseclasses or not. */
880 parm
= build_decl (PARM_DECL
, in_charge_identifier
, integer_type_node
);
881 /* Mark the artificial `__in_chrg' parameter as "artificial". */
882 SET_DECL_ARTIFICIAL (parm
);
883 DECL_ARG_TYPE (parm
) = integer_type_node
;
884 DECL_REGISTER (parm
) = 1;
885 TREE_CHAIN (parm
) = last_function_parms
;
886 last_function_parms
= parm
;
890 parm
= build_decl (PARM_DECL
, this_identifier
, type
);
891 /* Mark the artificial `this' parameter as "artificial". */
892 SET_DECL_ARTIFICIAL (parm
);
893 DECL_ARG_TYPE (parm
) = type
;
894 /* We can make this a register, so long as we don't
895 accidentally complain if someone tries to take its address. */
896 DECL_REGISTER (parm
) = 1;
897 if (TYPE_READONLY (type
))
898 TREE_READONLY (parm
) = 1;
899 TREE_CHAIN (parm
) = last_function_parms
;
900 last_function_parms
= parm
;
903 if (flags
== DTOR_FLAG
)
906 tree const_integer_type
= build_type_variant (integer_type_node
, 1, 0);
907 int len
= sizeof (DESTRUCTOR_DECL_PREFIX
)-1;
909 arg_types
= hash_tree_chain (const_integer_type
, void_list_node
);
910 TREE_SIDE_EFFECTS (arg_types
) = 1;
911 /* Build the overload name. It will look like `7Example'. */
912 if (IDENTIFIER_TYPE_VALUE (cname
))
913 dbuf
= build_overload_name (IDENTIFIER_TYPE_VALUE (cname
), 1, 1);
914 else if (IDENTIFIER_LOCAL_VALUE (cname
))
915 dbuf
= build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname
)), 1, 1);
917 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
918 it's defined out of the class definition, since poplevel_class wipes
919 it out. This used to be internal error 346. */
920 dbuf
= build_overload_name (ctype
, 1, 1);
921 buf
= (char *) alloca (strlen (dbuf
) + sizeof (DESTRUCTOR_DECL_PREFIX
));
922 bcopy (DESTRUCTOR_DECL_PREFIX
, buf
, len
);
925 DECL_ASSEMBLER_NAME (function
) = get_identifier (buf
);
926 parm
= build_decl (PARM_DECL
, in_charge_identifier
, const_integer_type
);
927 /* Mark the artificial `__in_chrg' parameter as "artificial". */
928 SET_DECL_ARTIFICIAL (parm
);
929 TREE_USED (parm
) = 1;
931 /* We don't need to mark the __in_chrg parameter itself as `const'
932 since its type is already `const int'. In fact we MUST NOT mark
933 it as `const' cuz that will screw up the debug info (causing it
934 to say that the type of __in_chrg is `const const int'). */
935 TREE_READONLY (parm
) = 1;
937 DECL_ARG_TYPE (parm
) = const_integer_type
;
938 /* This is the same chain as DECL_ARGUMENTS (...). */
939 TREE_CHAIN (last_function_parms
) = parm
;
941 TREE_TYPE (function
) = build_cplus_method_type (qualtype
, void_type_node
,
943 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
947 tree these_arg_types
;
949 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function
))
951 arg_types
= hash_tree_chain (integer_type_node
,
952 TREE_CHAIN (arg_types
));
954 = build_cplus_method_type (qualtype
,
955 TREE_TYPE (TREE_TYPE (function
)),
957 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (function
));
960 these_arg_types
= arg_types
;
962 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
963 /* Only true for static member functions. */
964 these_arg_types
= hash_tree_chain (TYPE_POINTER_TO (qualtype
),
967 DECL_ASSEMBLER_NAME (function
)
968 = build_decl_overload (fn_name
, these_arg_types
,
969 1 + DECL_CONSTRUCTOR_P (function
));
972 /* This code is going into the compiler, but currently, it makes
973 libg++/src/Interger.cc not compile. The problem is that the nice name
974 winds up going into the symbol table, and conversion operations look
975 for the manged name. */
976 substitute_nice_name (function
);
980 DECL_ARGUMENTS (function
) = last_function_parms
;
981 /* First approximations. */
982 DECL_CONTEXT (function
) = ctype
;
983 DECL_CLASS_CONTEXT (function
) = ctype
;
986 /* Work on the expr used by alignof (this is only called by the parser). */
994 if (TREE_CODE (expr
) == COMPONENT_REF
995 && DECL_BIT_FIELD (TREE_OPERAND (expr
, 1)))
996 error ("`__alignof__' applied to a bit-field");
998 if (TREE_CODE (expr
) == INDIRECT_REF
)
1000 best
= t
= TREE_OPERAND (expr
, 0);
1001 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1003 while (TREE_CODE (t
) == NOP_EXPR
1004 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1007 t
= TREE_OPERAND (t
, 0);
1008 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1009 if (thisalign
> bestalign
)
1010 best
= t
, bestalign
= thisalign
;
1012 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1016 /* ANSI says arrays and fns are converted inside comma.
1017 But we can't convert them in build_compound_expr
1018 because that would break commas in lvalues.
1019 So do the conversion here if operand was a comma. */
1020 if (TREE_CODE (expr
) == COMPOUND_EXPR
1021 && (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
1022 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
1023 expr
= default_conversion (expr
);
1024 return c_alignof (TREE_TYPE (expr
));
1028 /* Create an ARRAY_REF, checking for the user doing things backwards
1031 grok_array_decl (array_expr
, index_exp
)
1032 tree array_expr
, index_exp
;
1034 tree type
= TREE_TYPE (array_expr
);
1035 tree p1
, p2
, i1
, i2
;
1037 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1038 return error_mark_node
;
1039 if (type
== NULL_TREE
)
1041 /* Something has gone very wrong. Assume we are mistakenly reducing
1042 an expression instead of a declaration. */
1043 error ("parser may be lost: is there a '{' missing somewhere?");
1047 if (TREE_CODE (type
) == OFFSET_TYPE
1048 || TREE_CODE (type
) == REFERENCE_TYPE
)
1049 type
= TREE_TYPE (type
);
1051 /* If they have an `operator[]', use that. */
1052 if (TYPE_LANG_SPECIFIC (type
)
1053 && TYPE_OVERLOADS_ARRAY_REF (type
))
1054 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1055 array_expr
, index_exp
, NULL_TREE
);
1057 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1059 if (TREE_CODE (type
) == ARRAY_TYPE
)
1062 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1064 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1067 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1069 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1070 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1072 if ((p1
&& i2
) && (i1
&& p2
))
1073 error ("ambiguous conversion for array subscript");
1076 array_expr
= p1
, index_exp
= i2
;
1078 array_expr
= p2
, index_exp
= i1
;
1081 cp_error ("invalid types `%T[%T]' for array subscript",
1082 type
, TREE_TYPE (index_exp
));
1083 return error_mark_node
;
1086 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1087 error ("ambiguous conversion for array subscript");
1089 return build_array_ref (array_expr
, index_exp
);
1092 /* Given the cast expression EXP, checking out its validity. Either return
1093 an error_mark_node if there was an unavoidable error, return a cast to
1094 void for trying to delete a pointer w/ the value 0, or return the
1095 call to delete. If DOING_VEC is 1, we handle things differently
1096 for doing an array delete. If DOING_VEC is 2, they gave us the
1097 array size as an argument to delete.
1098 Implements ARM $5.3.4. This is called from the parser. */
1100 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1102 int doing_vec
, use_global_delete
;
1104 tree t
= stabilize_reference (convert_from_reference (exp
));
1105 tree type
= TREE_TYPE (t
);
1106 enum tree_code code
= TREE_CODE (type
);
1107 /* For a regular vector delete (aka, no size argument) we will pass
1108 this down as a NULL_TREE into build_vec_delete. */
1109 tree maxindex
= NULL_TREE
;
1110 /* This is used for deleting arrays. */
1116 maxindex
= build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
1117 if (! flag_traditional
)
1118 pedwarn ("anachronistic use of array size in vector delete");
1121 elt_size
= c_sizeof (type
);
1124 if (code
!= POINTER_TYPE
)
1126 cp_error ("type `%#T' argument given to `delete', expected pointer",
1128 return error_mark_node
;
1131 /* Deleting a pointer with the value zero is valid and has no effect. */
1132 if (integer_zerop (t
))
1133 return build1 (NOP_EXPR
, void_type_node
, t
);
1136 if (code
== POINTER_TYPE
)
1139 /* As of Valley Forge, you can delete a pointer to constant. */
1140 /* You can't delete a pointer to constant. */
1141 if (TREE_READONLY (TREE_TYPE (type
)))
1143 error ("`const *' cannot be deleted");
1144 return error_mark_node
;
1147 /* You also can't delete functions. */
1148 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1150 error ("cannot delete a function");
1151 return error_mark_node
;
1156 /* If the type has no destructor, then we should build a regular
1157 delete, instead of a vector delete. Otherwise, we would end
1158 up passing a bogus offset into __builtin_delete, which is
1159 not expecting it. */
1161 && TREE_CODE (type
) == POINTER_TYPE
1162 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type
)))
1165 use_global_delete
= 1;
1170 return build_vec_delete (t
, maxindex
, elt_size
, integer_one_node
,
1171 integer_two_node
, use_global_delete
);
1173 return build_delete (type
, t
, integer_three_node
,
1174 LOOKUP_NORMAL
|LOOKUP_HAS_IN_CHARGE
,
1178 /* Sanity check: report error if this function FUNCTION is not
1179 really a member of the class (CTYPE) it is supposed to belong to.
1180 CNAME is the same here as it is for grokclassfn above. */
1183 check_classfn (ctype
, cname
, function
)
1184 tree ctype
, cname
, function
;
1186 tree fn_name
= DECL_NAME (function
);
1188 tree method_vec
= CLASSTYPE_METHOD_VEC (ctype
);
1192 if (method_vec
!= 0)
1194 methods
= &TREE_VEC_ELT (method_vec
, 0);
1195 end
= TREE_VEC_END (method_vec
);
1197 /* First suss out ctors and dtors. */
1199 && (fn_name
== cname
|| fn_name
== DECL_NAME (*methods
)))
1202 while (++methods
!= end
)
1204 if (fn_name
== DECL_NAME (*methods
))
1210 if (DECL_ASSEMBLER_NAME (function
) == DECL_ASSEMBLER_NAME (fndecl
))
1213 /* This should work, but causes libg++ to fail
1215 /* We have to do more extensive argument checking here, as
1216 the name may have been changed by asm("new_name"). */
1217 if (decls_match (function
, fndecl
))
1220 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1222 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1223 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1225 /* Get rid of the this parameter on functions that become
1227 if (DECL_STATIC_FUNCTION_P (fndecl
)
1228 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1229 p1
= TREE_CHAIN (p1
);
1231 if (comptypes (TREE_TYPE (TREE_TYPE (function
)),
1232 TREE_TYPE (TREE_TYPE (fndecl
)), 1)
1233 && compparms (p1
, p2
, 3))
1237 fndecl
= DECL_CHAIN (fndecl
);
1245 cp_error ("argument list for `%#D' does not match any in class `%T'",
1250 cp_error ("no `%#D' member function declared in class `%T'",
1254 /* If we did not find the method in the class, add it to
1255 avoid spurious errors. */
1256 add_method (ctype
, methods
, function
);
1259 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1260 of a structure component, returning a FIELD_DECL node.
1261 QUALS is a list of type qualifiers for this decl (such as for declaring
1262 const member functions).
1264 This is done during the parsing of the struct declaration.
1265 The FIELD_DECL nodes are chained together and the lot of them
1266 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1270 If class A defines that certain functions in class B are friends, then
1271 the way I have set things up, it is B who is interested in permission
1272 granted by A. However, it is in A's context that these declarations
1273 are parsed. By returning a void_type_node, class A does not attempt
1274 to incorporate the declarations of the friends within its structure.
1276 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1277 CHANGES TO CODE IN `start_method'. */
1280 grokfield (declarator
, declspecs
, raises
, init
, asmspec_tree
)
1281 tree declarator
, declspecs
, raises
, init
, asmspec_tree
;
1283 register tree value
;
1285 int flags
= LOOKUP_ONLYCONVERTING
;
1287 /* Convert () initializers to = initializers. */
1288 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1289 && TREE_CODE (declarator
) == CALL_EXPR
1290 && TREE_OPERAND (declarator
, 0)
1291 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1292 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1293 && parmlist_is_exprlist (TREE_OPERAND (declarator
, 1)))
1295 init
= TREE_OPERAND (declarator
, 1);
1296 declarator
= TREE_OPERAND (declarator
, 0);
1301 && TREE_CODE (init
) == TREE_LIST
1302 && TREE_VALUE (init
) == error_mark_node
1303 && TREE_CHAIN (init
) == NULL_TREE
)
1306 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, raises
);
1308 return value
; /* friend or constructor went bad. */
1310 /* Pass friendly classes back. */
1311 if (TREE_CODE (value
) == VOID_TYPE
)
1312 return void_type_node
;
1314 if (DECL_NAME (value
) != NULL_TREE
1315 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1316 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1317 cp_error ("member `%D' conflicts with virtual function table field name", value
);
1319 /* Stash away type declarations. */
1320 if (TREE_CODE (value
) == TYPE_DECL
)
1322 DECL_NONLOCAL (value
) = 1;
1323 DECL_CONTEXT (value
) = current_class_type
;
1324 DECL_CLASS_CONTEXT (value
) = current_class_type
;
1325 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
1327 /* If we declare a typedef name for something that has no name,
1328 the typedef name is used for linkage. See 7.1.3 p4 94/0158. */
1329 if (TYPE_NAME (TREE_TYPE (value
))
1330 && TREE_CODE (TYPE_NAME (TREE_TYPE (value
))) == TYPE_DECL
1331 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (value
))))
1333 TYPE_NAME (TREE_TYPE (value
)) = value
;
1334 TYPE_STUB_DECL (TREE_TYPE (value
)) = value
;
1337 pushdecl_class_level (value
);
1341 if (IS_SIGNATURE (current_class_type
)
1342 && TREE_CODE (value
) != FUNCTION_DECL
)
1344 error ("field declaration not allowed in signature");
1345 return void_type_node
;
1348 if (DECL_IN_AGGR_P (value
))
1350 cp_error ("`%D' is already defined in the class %T", value
,
1351 DECL_CONTEXT (value
));
1352 return void_type_node
;
1356 cadillac_start_decl (value
);
1359 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1363 if (IS_SIGNATURE (current_class_type
)
1364 && TREE_CODE (value
) == FUNCTION_DECL
)
1366 error ("function declarations cannot have initializers in signature");
1369 else if (TREE_CODE (value
) == FUNCTION_DECL
)
1371 grok_function_init (value
, init
);
1374 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1375 /* Already complained in grokdeclarator. */
1379 /* We allow initializers to become parameters to base
1381 if (TREE_CODE (init
) == TREE_LIST
)
1383 if (TREE_CHAIN (init
) == NULL_TREE
)
1384 init
= TREE_VALUE (init
);
1386 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1389 if (TREE_CODE (init
) == CONST_DECL
)
1390 init
= DECL_INITIAL (init
);
1391 else if (TREE_READONLY_DECL_P (init
))
1392 init
= decl_constant_value (init
);
1393 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1394 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1395 my_friendly_assert (TREE_PERMANENT (init
), 192);
1396 if (init
== error_mark_node
)
1397 /* We must make this look different than `error_mark_node'
1398 because `decl_const_value' would mis-interpret it
1399 as only meaning that this VAR_DECL is defined. */
1400 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1401 else if (! TREE_CONSTANT (init
))
1403 /* We can allow references to things that are effectively
1404 static, since references are initialized with the address. */
1405 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1406 || (TREE_STATIC (init
) == 0
1407 && (TREE_CODE_CLASS (TREE_CODE (init
)) != 'd'
1408 || DECL_EXTERNAL (init
) == 0)))
1410 error ("field initializer is not constant");
1411 init
= error_mark_node
;
1417 /* The corresponding pop_obstacks is in finish_decl. */
1418 push_obstacks_nochange ();
1420 if (TREE_CODE (value
) == VAR_DECL
)
1422 /* We cannot call pushdecl here, because that would
1423 fill in the value of our TREE_CHAIN. Instead, we
1424 modify finish_decl to do the right thing, namely, to
1425 put this decl out straight away. */
1426 if (TREE_PUBLIC (value
))
1428 /* current_class_type can be NULL_TREE in case of error. */
1429 if (asmspec
== 0 && current_class_type
)
1431 TREE_PUBLIC (value
) = 1;
1432 DECL_INITIAL (value
) = error_mark_node
;
1433 DECL_ASSEMBLER_NAME (value
)
1434 = build_static_name (current_class_type
, DECL_NAME (value
));
1436 pending_statics
= perm_tree_cons (NULL_TREE
, value
, pending_statics
);
1438 /* Static consts need not be initialized in the class definition. */
1439 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value
)))
1441 static int explanation
= 0;
1443 error ("initializer invalid for static member with constructor");
1444 if (explanation
++ == 0)
1445 error ("(you really want to initialize it separately)");
1448 /* Force the compiler to know when an uninitialized static
1449 const member is being used. */
1450 if (TYPE_READONLY (value
) && init
== 0)
1451 TREE_USED (value
) = 1;
1453 DECL_INITIAL (value
) = init
;
1454 DECL_IN_AGGR_P (value
) = 1;
1456 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1457 pushdecl_class_level (value
);
1460 if (TREE_CODE (value
) == FIELD_DECL
)
1464 /* This must override the asm specifier which was placed
1465 by grokclassfn. Lay this out fresh. */
1466 DECL_RTL (value
) = NULL_RTX
;
1467 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1469 if (DECL_INITIAL (value
) == error_mark_node
)
1470 init
= error_mark_node
;
1471 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1472 DECL_INITIAL (value
) = init
;
1473 DECL_IN_AGGR_P (value
) = 1;
1476 if (TREE_CODE (value
) == FUNCTION_DECL
)
1478 if (DECL_CHAIN (value
) != NULL_TREE
)
1480 /* Need a fresh node here so that we don't get circularity
1481 when we link these together. */
1482 value
= copy_node (value
);
1483 /* When does this happen? */
1484 my_friendly_assert (init
== NULL_TREE
, 193);
1488 /* This must override the asm specifier which was placed
1489 by grokclassfn. Lay this out fresh. */
1490 DECL_RTL (value
) = NULL_RTX
;
1491 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1493 finish_decl (value
, init
, asmspec_tree
, 1, flags
);
1495 /* Pass friends back this way. */
1496 if (DECL_FRIEND_P (value
))
1497 return void_type_node
;
1499 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1500 if (current_function_decl
&& ! IS_SIGNATURE (current_class_type
))
1501 cp_error ("method `%#D' of local class must be defined in class body",
1505 DECL_IN_AGGR_P (value
) = 1;
1508 my_friendly_abort (21);
1513 /* Like `grokfield', but for bitfields.
1514 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1517 grokbitfield (declarator
, declspecs
, width
)
1518 tree declarator
, declspecs
, width
;
1520 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
, 0, NULL_TREE
);
1522 if (! value
) return NULL_TREE
; /* friends went bad. */
1524 /* Pass friendly classes back. */
1525 if (TREE_CODE (value
) == VOID_TYPE
)
1526 return void_type_node
;
1528 if (TREE_CODE (value
) == TYPE_DECL
)
1530 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1534 if (IS_SIGNATURE (current_class_type
))
1536 error ("field declaration not allowed in signature");
1537 return void_type_node
;
1540 if (DECL_IN_AGGR_P (value
))
1542 cp_error ("`%D' is already defined in the class %T", value
,
1543 DECL_CONTEXT (value
));
1544 return void_type_node
;
1547 GNU_xref_member (current_class_name
, value
);
1549 if (TREE_STATIC (value
))
1551 cp_error ("static member `%D' cannot be a bitfield", value
);
1554 finish_decl (value
, NULL_TREE
, NULL_TREE
, 0, 0);
1556 if (width
!= error_mark_node
)
1558 /* detect invalid field size. */
1559 if (TREE_CODE (width
) == CONST_DECL
)
1560 width
= DECL_INITIAL (width
);
1561 else if (TREE_READONLY_DECL_P (width
))
1562 width
= decl_constant_value (width
);
1563 if (TREE_CODE (width
) != INTEGER_CST
)
1565 cp_error ("structure field `%D' width not an integer constant",
1567 DECL_INITIAL (value
) = NULL_TREE
;
1571 constant_expression_warning (width
);
1572 DECL_INITIAL (value
) = width
;
1573 DECL_BIT_FIELD (value
) = 1;
1577 DECL_IN_AGGR_P (value
) = 1;
1582 /* Like GROKFIELD, except that the declarator has been
1583 buried in DECLSPECS. Find the declarator, and
1584 return something that looks like it came from
1587 groktypefield (declspecs
, parmlist
)
1591 tree spec
= declspecs
;
1592 tree prev
= NULL_TREE
;
1594 tree type_id
= NULL_TREE
;
1595 tree quals
= NULL_TREE
;
1596 tree lengths
= NULL_TREE
;
1597 tree decl
= NULL_TREE
;
1601 register tree id
= TREE_VALUE (spec
);
1603 if (TREE_CODE (spec
) != TREE_LIST
)
1604 /* Certain parse errors slip through. For example,
1605 `int class ();' is not caught by the parser. Try
1606 weakly to recover here. */
1609 if (TREE_CODE (id
) == TYPE_DECL
1610 || (TREE_CODE (id
) == IDENTIFIER_NODE
&& TREE_TYPE (id
)))
1612 /* We have a constructor/destructor or
1613 conversion operator. Use it. */
1615 TREE_CHAIN (prev
) = TREE_CHAIN (spec
);
1617 declspecs
= TREE_CHAIN (spec
);
1623 spec
= TREE_CHAIN (spec
);
1626 /* Nope, we have a conversion operator to a scalar type or something
1627 else, that includes things like constructor declarations for
1632 tree id
= TREE_VALUE (spec
);
1634 if (TREE_CODE (id
) == IDENTIFIER_NODE
)
1636 if (id
== ridpointers
[(int)RID_INT
]
1637 || id
== ridpointers
[(int)RID_DOUBLE
]
1638 || id
== ridpointers
[(int)RID_FLOAT
]
1639 || id
== ridpointers
[(int)RID_WCHAR
])
1642 error ("extra `%s' ignored",
1643 IDENTIFIER_POINTER (id
));
1647 else if (id
== ridpointers
[(int)RID_LONG
]
1648 || id
== ridpointers
[(int)RID_SHORT
]
1649 || id
== ridpointers
[(int)RID_CHAR
])
1651 lengths
= tree_cons (NULL_TREE
, id
, lengths
);
1653 else if (id
== ridpointers
[(int)RID_VOID
])
1656 error ("spurious `void' type ignored");
1658 error ("conversion to `void' type invalid");
1660 else if (id
== ridpointers
[(int)RID_AUTO
]
1661 || id
== ridpointers
[(int)RID_REGISTER
]
1662 || id
== ridpointers
[(int)RID_TYPEDEF
]
1663 || id
== ridpointers
[(int)RID_CONST
]
1664 || id
== ridpointers
[(int)RID_VOLATILE
])
1666 error ("type specifier `%s' used invalidly",
1667 IDENTIFIER_POINTER (id
));
1669 else if (id
== ridpointers
[(int)RID_FRIEND
]
1670 || id
== ridpointers
[(int)RID_VIRTUAL
]
1671 || id
== ridpointers
[(int)RID_INLINE
]
1672 || id
== ridpointers
[(int)RID_UNSIGNED
]
1673 || id
== ridpointers
[(int)RID_SIGNED
]
1674 || id
== ridpointers
[(int)RID_STATIC
]
1675 || id
== ridpointers
[(int)RID_EXTERN
])
1677 quals
= tree_cons (NULL_TREE
, id
, quals
);
1681 /* Happens when we have a global typedef
1682 and a class-local member function with
1688 else if (TREE_CODE (id
) == RECORD_TYPE
)
1690 type_id
= TYPE_NAME (id
);
1691 if (TREE_CODE (type_id
) == TYPE_DECL
)
1692 type_id
= DECL_NAME (type_id
);
1693 if (type_id
== NULL_TREE
)
1694 error ("identifier for aggregate type conversion omitted");
1696 else if (TREE_CODE_CLASS (TREE_CODE (id
)) == 't')
1697 error ("`operator' missing on conversion operator or tag missing from type");
1699 my_friendly_abort (194);
1700 spec
= TREE_CHAIN (spec
);
1704 declspecs
= chainon (lengths
, quals
);
1707 if (TREE_CHAIN (lengths
))
1708 error ("multiple length specifiers");
1709 type_id
= ridpointers
[(int)RID_INT
];
1710 declspecs
= chainon (lengths
, quals
);
1714 error ("no type given, defaulting to `operator int ...'");
1715 type_id
= ridpointers
[(int)RID_INT
];
1722 decl
= grokdeclarator (build_parse_node (CALL_EXPR
, type_id
, parmlist
, NULL_TREE
),
1723 declspecs
, FIELD
, 0, NULL_TREE
);
1724 if (decl
== NULL_TREE
)
1727 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_CHAIN (decl
) != NULL_TREE
)
1729 /* Need a fresh node here so that we don't get circularity
1730 when we link these together. */
1731 decl
= copy_node (decl
);
1734 if (decl
== void_type_node
1735 || (TREE_CODE (decl
) == FUNCTION_DECL
1736 && TREE_CODE (TREE_TYPE (decl
)) != METHOD_TYPE
))
1737 /* bunch of friends. */
1740 if (DECL_IN_AGGR_P (decl
))
1742 cp_error ("`%D' already defined in the class ", decl
);
1743 return void_type_node
;
1746 finish_decl (decl
, NULL_TREE
, NULL_TREE
, 0, 0);
1748 /* If this declaration is common to another declaration
1749 complain about such redundancy, and return NULL_TREE
1750 so that we don't build a circular list. */
1751 if (DECL_CHAIN (decl
))
1753 cp_error ("function `%D' declared twice in class %T", decl
,
1754 DECL_CONTEXT (decl
));
1757 DECL_IN_AGGR_P (decl
) = 1;
1763 grokoptypename (declspecs
, declarator
)
1764 tree declspecs
, declarator
;
1766 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1767 return build_typename_overload (t
);
1770 /* When a function is declared with an initializer,
1771 do the right thing. Currently, there are two possibilities:
1776 // initialization possibility #1.
1777 virtual void f () = 0;
1799 // initialization possibility #2
1806 copy_assignment_arg_p (parmtype
, virtualp
)
1810 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1811 parmtype
= TREE_TYPE (parmtype
);
1813 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1814 || (virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
)))
1821 grok_function_init (decl
, init
)
1825 /* An initializer for a function tells how this function should
1827 tree type
= TREE_TYPE (decl
);
1829 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1830 cp_error ("initializer specified for non-member function `%D'", decl
);
1831 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1832 cp_error ("initializer specified for non-virtual method `%D'", decl
);
1833 else if (integer_zerop (init
))
1836 /* Mark this function as being "defined". */
1837 DECL_INITIAL (decl
) = error_mark_node
;
1838 /* pure virtual destructors must be defined. */
1839 /* pure virtual needs to be defined (as abort) only when put in
1840 vtbl. For wellformed call, it should be itself. pr4737 */
1841 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1843 extern tree abort_fndecl
;
1844 /* Give this node rtl from `abort'. */
1845 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1848 DECL_ABSTRACT_VIRTUAL_P (decl
) = 1;
1849 if (DECL_NAME (decl
) == ansi_opname
[(int) MODIFY_EXPR
])
1852 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1854 if (copy_assignment_arg_p (parmtype
, 1))
1855 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
1858 else if (TREE_CODE (init
) == OFFSET_REF
1859 && TREE_OPERAND (init
, 0) == NULL_TREE
1860 && TREE_CODE (TREE_TYPE (init
)) == METHOD_TYPE
)
1862 tree basetype
= DECL_CLASS_CONTEXT (init
);
1863 tree basefn
= TREE_OPERAND (init
, 1);
1864 if (TREE_CODE (basefn
) != FUNCTION_DECL
)
1865 cp_error ("non-method initializer invalid for method `%D'", decl
);
1866 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn
))))
1867 sorry ("base member function from other than first base class");
1870 tree binfo
= get_binfo (basetype
, TYPE_METHOD_BASETYPE (type
), 1);
1871 if (binfo
== error_mark_node
)
1873 else if (binfo
== 0)
1874 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init
)),
1875 TYPE_METHOD_BASETYPE (type
));
1878 /* Mark this function as being defined,
1879 and give it new rtl. */
1880 DECL_INITIAL (decl
) = error_mark_node
;
1881 DECL_RTL (decl
) = DECL_RTL (basefn
);
1886 cp_error ("invalid initializer for virtual method `%D'", decl
);
1889 /* When we get a declaration of the form
1891 type cname::fname ...
1893 the node for `cname::fname' gets built here in a special way.
1894 Namely, we push into `cname's scope. When this declaration is
1895 processed, we pop back out. */
1897 build_push_scope (cname
, name
)
1901 extern int current_class_depth
;
1905 if (cname
== error_mark_node
)
1906 return error_mark_node
;
1908 ctype
= IDENTIFIER_TYPE_VALUE (cname
);
1910 if (TREE_CODE (ctype
) == TEMPLATE_TYPE_PARM
)
1912 else if (ctype
== NULL_TREE
|| ! IS_AGGR_TYPE (ctype
))
1914 cp_error ("`%T' not defined as aggregate type", cname
);
1917 else if (IS_SIGNATURE (ctype
))
1919 error ("cannot push into signature scope, scope resolution operator ignored");
1923 rval
= build_parse_node (SCOPE_REF
, cname
, name
);
1925 /* Don't need to push the scope if we're already in it.
1926 We also don't need to push the scope for a ptr-to-member/method. */
1928 if (ctype
== current_class_type
|| TREE_CODE (name
) != IDENTIFIER_NODE
1932 /* We do need to push the scope in this case, since CTYPE helps
1933 determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;). */
1935 push_nested_class (ctype
, 3);
1936 TREE_COMPLEXITY (rval
) = current_class_depth
;
1941 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
1942 tree decl
, attributes
, prefix_attributes
;
1944 if (decl
&& decl
!= void_type_node
)
1945 decl_attributes (decl
, attributes
, prefix_attributes
);
1948 /* CONSTRUCTOR_NAME:
1949 Return the name for the constructor (or destructor) for the
1950 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1951 IDENTIFIER_NODE. When given a template, this routine doesn't
1952 lose the specialization. */
1954 constructor_name_full (thing
)
1957 if (TREE_CODE (thing
) == UNINSTANTIATED_P_TYPE
)
1958 return DECL_NAME (UPT_TEMPLATE (thing
));
1959 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
1961 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
1962 thing
= DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing
), 0));
1964 thing
= TYPE_NAME (thing
);
1966 if (TREE_CODE (thing
) == TYPE_DECL
1967 || (TREE_CODE (thing
) == TEMPLATE_DECL
1968 && DECL_TEMPLATE_IS_CLASS (thing
)))
1969 thing
= DECL_NAME (thing
);
1970 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
1974 /* CONSTRUCTOR_NAME:
1975 Return the name for the constructor (or destructor) for the
1976 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1977 IDENTIFIER_NODE. When given a template, return the plain
1978 unspecialized name. */
1980 constructor_name (thing
)
1984 thing
= constructor_name_full (thing
);
1985 t
= IDENTIFIER_TEMPLATE (thing
);
1988 t
= TREE_PURPOSE (t
);
1989 return DECL_NAME (t
);
1992 /* Cache the value of this class's main virtual function table pointer
1993 in a register variable. This will save one indirection if a
1994 more than one virtual function call is made this function. */
1998 extern rtx base_init_insns
;
2000 if (base_init_insns
== 0
2001 && DECL_CONSTRUCTOR_P (current_function_decl
))
2002 emit_base_init (current_class_type
, 0);
2005 /* This has something a little wrong with it.
2007 On a sun4, code like:
2012 is generated, when the below is used when -O4 is given. The delay
2013 slot it filled with an instruction that is safe, when this isn't
2023 virtual void print() { printf("xxx"); }
2035 And that is why this is disabled for now. (mrs)
2038 if ((flag_this_is_variable
& 1) == 0
2040 && current_class_type
2041 && CLASSTYPE_VSIZE (current_class_type
)
2042 && ! DECL_STATIC_FUNCTION_P (current_function_decl
))
2044 tree vfield
= build_vfield_ref (C_C_D
, current_class_type
);
2045 current_vtable_decl
= CLASSTYPE_VTBL_PTR (current_class_type
);
2046 DECL_RTL (current_vtable_decl
) = 0;
2047 DECL_INITIAL (current_vtable_decl
) = error_mark_node
;
2048 /* Have to cast the initializer, since it may have come from a
2049 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
2050 finish_decl (current_vtable_decl
, convert_force (TREE_TYPE (current_vtable_decl
), vfield
, 0), NULL_TREE
, 0, 0);
2051 current_vtable_decl
= build_indirect_ref (current_vtable_decl
, NULL_PTR
);
2055 current_vtable_decl
= NULL_TREE
;
2058 /* Record the existence of an addressable inline function. */
2060 mark_inline_for_output (decl
)
2063 decl
= DECL_MAIN_VARIANT (decl
);
2064 if (DECL_SAVED_INLINE (decl
))
2066 my_friendly_assert (TREE_PERMANENT (decl
), 363);
2067 DECL_SAVED_INLINE (decl
) = 1;
2068 if (DECL_PENDING_INLINE_INFO (decl
) != 0
2069 && ! DECL_PENDING_INLINE_INFO (decl
)->deja_vu
)
2071 struct pending_inline
*t
= pending_inlines
;
2072 my_friendly_assert (DECL_SAVED_INSNS (decl
) == 0, 198);
2075 if (t
== DECL_PENDING_INLINE_INFO (decl
))
2081 t
= DECL_PENDING_INLINE_INFO (decl
);
2082 t
->next
= pending_inlines
;
2083 pending_inlines
= t
;
2085 DECL_PENDING_INLINE_INFO (decl
) = 0;
2087 saved_inlines
= perm_tree_cons (NULL_TREE
, decl
, saved_inlines
);
2093 temp_name_counter
= 0;
2096 /* Hand off a unique name which can be used for variable we don't really
2097 want to know about anyway, for example, the anonymous variables which
2098 are needed to make references work. Declare this thing so we can use it.
2099 The variable created will be of type TYPE.
2101 STATICP is nonzero if this variable should be static. */
2104 get_temp_name (type
, staticp
)
2108 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2110 int toplev
= global_bindings_p ();
2112 push_obstacks_nochange ();
2113 if (toplev
|| staticp
)
2115 end_temporary_allocation ();
2116 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2117 decl
= pushdecl_top_level (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2121 sprintf (buf
, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2122 decl
= pushdecl (build_decl (VAR_DECL
, get_identifier (buf
), type
));
2124 TREE_USED (decl
) = 1;
2125 TREE_STATIC (decl
) = staticp
;
2127 /* If this is a local variable, then lay out its rtl now.
2128 Otherwise, callers of this function are responsible for dealing
2129 with this variable's rtl. */
2133 expand_decl_init (decl
);
2140 /* Get a variable which we can use for multiple assignments.
2141 It is not entered into current_binding_level, because
2142 that breaks things when it comes time to do final cleanups
2143 (which take place "outside" the binding contour of the function). */
2145 get_temp_regvar (type
, init
)
2148 static char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20] = { '_' };
2151 sprintf (buf
+1, AUTO_TEMP_FORMAT
, temp_name_counter
++);
2152 decl
= build_decl (VAR_DECL
, get_identifier (buf
), type
);
2153 TREE_USED (decl
) = 1;
2154 DECL_REGISTER (decl
) = 1;
2157 store_init_value (decl
, init
);
2159 /* We can expand these without fear, since they cannot need
2160 constructors or destructors. */
2162 expand_decl_init (decl
);
2164 if (type_needs_gc_entry (type
))
2165 DECL_GC_OFFSET (decl
) = size_int (++current_function_obstack_index
);
2170 /* Make the macro TEMP_NAME_P available to units which do not
2171 include c-tree.h. */
2176 return TEMP_NAME_P (decl
);
2179 /* Finish off the processing of a UNION_TYPE structure.
2180 If there are static members, then all members are
2181 static, and must be laid out together. If the
2182 union is an anonymous union, we arrange for that
2183 as well. PUBLIC_P is nonzero if this union is
2184 not declared static. */
2186 finish_anon_union (anon_union_decl
)
2187 tree anon_union_decl
;
2189 tree type
= TREE_TYPE (anon_union_decl
);
2190 tree field
, main_decl
= NULL_TREE
;
2191 tree elems
= NULL_TREE
;
2192 int public_p
= TREE_PUBLIC (anon_union_decl
);
2193 int static_p
= TREE_STATIC (anon_union_decl
);
2194 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2196 if ((field
= TYPE_FIELDS (type
)) == NULL_TREE
)
2201 error ("global anonymous unions must be declared static");
2205 for (; field
; field
= TREE_CHAIN (field
))
2208 if (TREE_CODE (field
) != FIELD_DECL
)
2211 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2212 /* tell `pushdecl' that this is not tentative. */
2213 DECL_INITIAL (decl
) = error_mark_node
;
2214 TREE_PUBLIC (decl
) = public_p
;
2215 TREE_STATIC (decl
) = static_p
;
2216 DECL_EXTERNAL (decl
) = external_p
;
2217 decl
= pushdecl (decl
);
2219 /* Only write out one anon union element--choose the one that
2220 can hold them all. */
2221 if (main_decl
== NULL_TREE
2222 && simple_cst_equal (DECL_SIZE (decl
), DECL_SIZE (anon_union_decl
)))
2228 /* ??? This causes there to be no debug info written out
2230 TREE_ASM_WRITTEN (decl
) = 1;
2233 DECL_INITIAL (decl
) = NULL_TREE
;
2234 /* If there's a cleanup to do, it belongs in the
2235 TREE_PURPOSE of the following TREE_LIST. */
2236 elems
= tree_cons (NULL_TREE
, decl
, elems
);
2237 TREE_TYPE (elems
) = type
;
2243 make_decl_rtl (main_decl
, 0, global_bindings_p ());
2244 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2248 warning ("anonymous union with no members");
2253 /* The following call assumes that there are never any cleanups
2254 for anonymous unions--a reasonable assumption. */
2255 expand_anon_union_decl (anon_union_decl
, NULL_TREE
, elems
);
2258 cadillac_finish_anon_union (anon_union_decl
);
2261 /* Finish and output a table which is generated by the compiler.
2262 NAME is the name to give the table.
2263 TYPE is the type of the table entry.
2264 INIT is all the elements in the table.
2265 PUBLICP is non-zero if this table should be given external access. */
2267 finish_table (name
, type
, init
, publicp
)
2268 tree name
, type
, init
;
2271 tree itype
, atype
, decl
;
2272 static tree empty_table
;
2276 itype
= build_index_type (size_int (list_length (init
) - 1));
2277 atype
= build_cplus_array_type (type
, itype
);
2278 layout_type (atype
);
2280 if (TREE_VALUE (init
) == integer_zero_node
2281 && TREE_CHAIN (init
) == NULL_TREE
)
2284 if (empty_table
== NULL_TREE
)
2287 empty_table
= get_temp_name (atype
, 1);
2288 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2289 TREE_CONSTANT (init
) = 1;
2290 TREE_STATIC (init
) = 1;
2291 DECL_INITIAL (empty_table
) = init
;
2292 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2293 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2294 finish_decl (empty_table
, init
, asmspec
, 0, 0);
2299 if (name
== NULL_TREE
)
2303 decl
= get_temp_name (atype
, 1);
2307 decl
= build_decl (VAR_DECL
, name
, atype
);
2308 decl
= pushdecl (decl
);
2309 TREE_STATIC (decl
) = 1;
2314 TREE_PUBLIC (decl
) = publicp
;
2315 init
= build (CONSTRUCTOR
, atype
, NULL_TREE
, init
);
2316 TREE_CONSTANT (init
) = 1;
2317 TREE_STATIC (init
) = 1;
2318 DECL_INITIAL (decl
) = init
;
2319 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (decl
)),
2320 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2324 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2325 DECL_EXTERNAL (decl
) = 1;
2326 TREE_STATIC (decl
) = 0;
2328 asmspec
= build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table
)),
2329 IDENTIFIER_POINTER (DECL_NAME (empty_table
)));
2332 finish_decl (decl
, init
, asmspec
, 0, 0);
2336 /* Finish processing a builtin type TYPE. It's name is NAME,
2337 its fields are in the array FIELDS. LEN is the number of elements
2338 in FIELDS minus one, or put another way, it is the maximum subscript
2341 It is given the same alignment as ALIGN_TYPE. */
2343 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2352 TYPE_FIELDS (type
) = fields
[0];
2353 for (i
= 0; i
< len
; i
++)
2355 layout_type (TREE_TYPE (fields
[i
]));
2356 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2357 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2359 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2360 DECL_CLASS_CONTEXT (fields
[i
]) = type
;
2361 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2363 #if 0 /* not yet, should get fixed properly later */
2364 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2366 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2368 layout_decl (TYPE_NAME (type
), 0);
2371 /* Auxiliary functions to make type signatures for
2372 `operator new' and `operator delete' correspond to
2373 what compiler will be expecting. */
2375 extern tree sizetype
;
2378 coerce_new_type (type
)
2383 if (TREE_CODE (type
) == METHOD_TYPE
)
2384 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
2385 if (TREE_TYPE (type
) != ptr_type_node
)
2386 e1
= 1, error ("`operator new' must return type `void *'");
2388 /* Technically the type must be `size_t', but we may not know
2390 if (TYPE_ARG_TYPES (type
) == NULL_TREE
)
2391 e1
= 1, error ("`operator new' takes type `size_t' parameter");
2392 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type
))) != INTEGER_TYPE
2393 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type
))) != TYPE_PRECISION (sizetype
))
2394 e2
= 1, error ("`operator new' takes type `size_t' as first parameter");
2396 type
= build_function_type (ptr_type_node
, tree_cons (NULL_TREE
, sizetype
, TREE_CHAIN (TYPE_ARG_TYPES (type
))));
2398 type
= build_function_type (ptr_type_node
, TYPE_ARG_TYPES (type
));
2403 coerce_delete_type (type
)
2406 int e1
= 0, e2
= 0, e3
= 0;
2407 tree arg_types
= TYPE_ARG_TYPES (type
);
2409 if (TREE_CODE (type
) == METHOD_TYPE
)
2411 type
= build_function_type (TREE_TYPE (type
), TREE_CHAIN (arg_types
));
2412 arg_types
= TREE_CHAIN (arg_types
);
2414 if (TREE_TYPE (type
) != void_type_node
)
2415 e1
= 1, error ("`operator delete' must return type `void'");
2416 if (arg_types
== NULL_TREE
2417 || TREE_VALUE (arg_types
) != ptr_type_node
)
2418 e2
= 1, error ("`operator delete' takes type `void *' as first parameter");
2421 && TREE_CHAIN (arg_types
)
2422 && TREE_CHAIN (arg_types
) != void_list_node
)
2424 /* Again, technically this argument must be `size_t', but again
2425 we may not know what that is. */
2426 tree t2
= TREE_VALUE (TREE_CHAIN (arg_types
));
2427 if (TREE_CODE (t2
) != INTEGER_TYPE
2428 || TYPE_PRECISION (t2
) != TYPE_PRECISION (sizetype
))
2429 e3
= 1, error ("second argument to `operator delete' must be of type `size_t'");
2430 else if (TREE_CHAIN (TREE_CHAIN (arg_types
)) != void_list_node
)
2433 if (TREE_CHAIN (TREE_CHAIN (arg_types
)))
2434 error ("too many arguments in declaration of `operator delete'");
2436 error ("`...' invalid in specification of `operator delete'");
2440 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, build_tree_list (NULL_TREE
, sizetype
));
2443 if (arg_types
== NULL_TREE
)
2444 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
2446 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, TREE_CHAIN (arg_types
));
2451 type
= build_function_type (void_type_node
, arg_types
);
2457 mark_vtable_entries (decl
)
2460 tree entries
= TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl
)));
2462 for (; entries
; entries
= TREE_CHAIN (entries
))
2464 tree fnaddr
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
));
2465 tree fn
= TREE_OPERAND (fnaddr
, 0);
2466 TREE_ADDRESSABLE (fn
) = 1;
2467 if (DECL_ABSTRACT_VIRTUAL_P (fn
))
2469 extern tree abort_fndecl
;
2470 if (flag_vtable_thunks
)
2471 fnaddr
= TREE_VALUE (entries
);
2472 TREE_OPERAND (fnaddr
, 0) = fn
= abort_fndecl
;
2474 assemble_external (fn
);
2478 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2479 based on TYPE and other static flags.
2481 Note that anything public is tagged TREE_PUBLIC, whether
2482 it's public in this file or in another one. */
2485 import_export_vtable (decl
, type
, final
)
2489 if (DECL_INTERFACE_KNOWN (decl
))
2493 if (write_virtuals
< 2 && write_virtuals
!= 0)
2495 TREE_PUBLIC (decl
) = 1;
2496 if (write_virtuals
< 0)
2497 DECL_EXTERNAL (decl
) = 1;
2498 DECL_INTERFACE_KNOWN (decl
) = 1;
2500 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2502 TREE_PUBLIC (decl
) = 1;
2503 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2504 DECL_INTERFACE_KNOWN (decl
) = 1;
2508 /* We can only wait to decide if we have real non-inline virtual
2509 functions in our class, or if we come from a template. */
2511 int found
= CLASSTYPE_TEMPLATE_INSTANTIATION (type
);
2513 if (! found
&& ! final
)
2516 for (method
= CLASSTYPE_METHODS (type
); method
!= NULL_TREE
;
2517 method
= DECL_NEXT_METHOD (method
))
2518 if (DECL_VINDEX (method
) != NULL_TREE
2519 && ! DECL_THIS_INLINE (method
)
2520 && ! DECL_ABSTRACT_VIRTUAL_P (method
))
2527 if (final
|| ! found
)
2529 #ifdef ASSEMBLE_EXTERNAL
2530 if (TREE_PUBLIC (decl
))
2531 cp_error ("all virtual functions redeclared inline");
2533 TREE_PUBLIC (decl
) = 0;
2534 DECL_EXTERNAL (decl
) = 0;
2538 TREE_PUBLIC (decl
) = 1;
2539 DECL_EXTERNAL (decl
) = 1;
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_THIS_INLINE (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 if (DECL_TEMPLATE_INSTANTIATION (decl
))
2752 if (DECL_IMPLICIT_INSTANTIATION (decl
) && flag_implicit_templates
)
2753 TREE_PUBLIC (decl
) = 0;
2755 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2757 else if (DECL_FUNCTION_MEMBER_P (decl
))
2759 tree ctype
= DECL_CLASS_CONTEXT (decl
);
2760 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2762 DECL_NOT_REALLY_EXTERN (decl
)
2763 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2764 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
));
2767 TREE_PUBLIC (decl
) = 0;
2770 TREE_PUBLIC (decl
) = 0;
2773 extern int parse_time
, varconst_time
;
2775 #define TIMEVAR(VAR, BODY) \
2776 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2778 /* This routine is called from the last rule in yyparse ().
2779 Its job is to create all the code needed to initialize and
2780 destroy the global aggregates. We do the destruction
2781 first, since that way we only need to reverse the decls once. */
2787 int start_time
, this_time
;
2790 tree vars
= static_aggregates
;
2791 int needs_cleaning
= 0, needs_messing_up
= 0;
2793 if (flag_detailed_statistics
)
2794 dump_tree_statistics ();
2796 /* Bad parse errors. Just forget about it. */
2797 if (! global_bindings_p () || current_class_type
)
2800 start_time
= get_run_time ();
2802 /* Push into C language context, because that's all
2804 push_lang_context (lang_name_c
);
2806 if (static_ctors
|| vars
|| might_have_exceptions_p ())
2807 needs_messing_up
= 1;
2811 /* See if we really need the hassle. */
2812 while (vars
&& needs_cleaning
== 0)
2814 tree decl
= TREE_VALUE (vars
);
2815 tree type
= TREE_TYPE (decl
);
2816 if (TYPE_NEEDS_DESTRUCTOR (type
))
2819 needs_messing_up
= 1;
2823 needs_messing_up
|= TYPE_NEEDS_CONSTRUCTING (type
);
2824 vars
= TREE_CHAIN (vars
);
2827 /* Otherwise, GDB can get confused, because in only knows
2828 about source for LINENO-1 lines. */
2831 interface_unknown
= 1;
2835 /* The reason for pushing garbage onto the global_binding_level is to
2836 ensure that we can slice out _DECLs which pertain to virtual function
2837 tables. If the last thing pushed onto the global_binding_level was a
2838 virtual function table, then slicing it out would slice away all the
2839 decls (i.e., we lose the head of the chain).
2841 There are several ways of getting the same effect, from changing the
2842 way that iterators over the chain treat the elements that pertain to
2843 virtual function tables, moving the implementation of this code to
2844 decl.c (where we can manipulate global_binding_level directly),
2845 popping the garbage after pushing it and slicing away the vtable
2846 stuff, or just leaving it alone. */
2848 /* Make last thing in global scope not be a virtual function table. */
2849 #if 0 /* not yet, should get fixed properly later */
2850 vars
= make_type_decl (get_identifier (" @%$#@!"), integer_type_node
);
2852 vars
= build_decl (TYPE_DECL
, get_identifier (" @%$#@!"), integer_type_node
);
2854 DECL_IGNORED_P (vars
) = 1;
2855 SET_DECL_ARTIFICIAL (vars
);
2859 /* Walk to mark the inline functions we need, then output them so
2860 that we can pick up any other tdecls that those routines need. */
2861 walk_vtables ((void (*)())0, finish_prevtable_vardecl
);
2863 if (needs_cleaning
== 0)
2866 fnname
= get_file_function_name ('D');
2867 start_function (void_list_node
, build_parse_node (CALL_EXPR
, fnname
, void_list_node
, NULL_TREE
), 0, 0);
2868 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2869 store_parm_decls ();
2874 expand_start_bindings (0);
2876 /* These must be done in backward order to destroy,
2877 in which they happen to be! */
2878 for (vars
= static_aggregates
; vars
; vars
= TREE_CHAIN (vars
))
2880 tree decl
= TREE_VALUE (vars
);
2881 tree type
= TREE_TYPE (decl
);
2882 tree temp
= TREE_PURPOSE (vars
);
2884 if (TYPE_NEEDS_DESTRUCTOR (type
))
2886 if (TREE_STATIC (vars
))
2887 expand_start_cond (build_binary_op (NE_EXPR
, temp
, integer_zero_node
, 1), 0);
2888 if (TREE_CODE (type
) == ARRAY_TYPE
)
2892 mark_addressable (decl
);
2893 temp
= build1 (ADDR_EXPR
, TYPE_POINTER_TO (type
), decl
);
2895 temp
= build_delete (TREE_TYPE (temp
), temp
,
2896 integer_two_node
, LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2897 expand_expr_stmt (temp
);
2899 if (TREE_STATIC (vars
))
2904 for (; static_dtors
; static_dtors
= TREE_CHAIN (static_dtors
))
2905 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors
),
2908 expand_end_bindings (getdecls(), 1, 0);
2912 finish_function (lineno
, 0, 0);
2914 assemble_destructor (IDENTIFIER_POINTER (fnname
));
2916 /* if it needed cleaning, then it will need messing up: drop through */
2919 /* Must do this while we think we are at the top level. */
2920 vars
= nreverse (static_aggregates
);
2921 if (needs_messing_up
)
2923 fnname
= get_file_function_name ('I');
2924 start_function (void_list_node
, build_parse_node (CALL_EXPR
, fnname
, void_list_node
, NULL_TREE
), 0, 0);
2925 fnname
= DECL_ASSEMBLER_NAME (current_function_decl
);
2926 store_parm_decls ();
2931 expand_start_bindings (0);
2933 if (might_have_exceptions_p ())
2934 register_exception_table ();
2938 tree decl
= TREE_VALUE (vars
);
2939 tree init
= TREE_PURPOSE (vars
);
2940 tree old_cleanups
= cleanups_this_call
;
2942 /* If this was a static attribute within some function's scope,
2943 then don't initialize it here. Also, don't bother
2944 with initializers that contain errors. */
2945 if (TREE_STATIC (vars
)
2946 || (init
&& TREE_CODE (init
) == TREE_LIST
2947 && value_member (error_mark_node
, init
)))
2949 vars
= TREE_CHAIN (vars
);
2953 if (TREE_CODE (decl
) == VAR_DECL
)
2955 /* Set these global variables so that GDB at least puts
2956 us near the declaration which required the initialization. */
2957 input_filename
= DECL_SOURCE_FILE (decl
);
2958 lineno
= DECL_SOURCE_LINE (decl
);
2959 emit_note (input_filename
, lineno
);
2961 /* 9.5p5: The initializer of a static member of a class has
2962 the same acess rights as a member function. */
2963 DECL_CLASS_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
2964 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
2969 if (TREE_CODE (init
) == VAR_DECL
)
2971 /* This behavior results when there are
2972 multiple declarations of an aggregate,
2973 the last of which defines it. */
2974 if (DECL_RTL (init
) == DECL_RTL (decl
))
2976 my_friendly_assert (DECL_INITIAL (decl
) == error_mark_node
2977 || (TREE_CODE (DECL_INITIAL (decl
)) == CONSTRUCTOR
2978 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl
)) == NULL_TREE
),
2980 init
= DECL_INITIAL (init
);
2981 if (TREE_CODE (init
) == CONSTRUCTOR
2982 && CONSTRUCTOR_ELTS (init
) == NULL_TREE
)
2985 else if (TREE_TYPE (decl
) == TREE_TYPE (init
))
2988 my_friendly_abort (200);
2990 /* point to real decl's rtl anyway. */
2991 DECL_RTL (init
) = DECL_RTL (decl
);
2992 my_friendly_assert (DECL_INITIAL (decl
) == error_mark_node
,
2994 init
= DECL_INITIAL (init
);
3000 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3001 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3002 expand_aggr_init (decl
, init
, 0, 0);
3003 else if (TREE_CODE (init
) == TREE_VEC
)
3005 expand_expr (expand_vec_init (decl
, TREE_VEC_ELT (init
, 0),
3006 TREE_VEC_ELT (init
, 1),
3007 TREE_VEC_ELT (init
, 2), 0),
3008 const0_rtx
, VOIDmode
, 0);
3012 expand_assignment (decl
, init
, 0, 0);
3014 DECL_CLASS_CONTEXT (current_function_decl
) = NULL_TREE
;
3016 else if (TREE_CODE (decl
) == SAVE_EXPR
)
3018 if (! PARM_DECL_EXPR (decl
))
3020 /* a `new' expression at top level. */
3021 expand_expr (decl
, const0_rtx
, VOIDmode
, 0);
3023 expand_aggr_init (build_indirect_ref (decl
, NULL_PTR
), init
, 0, 0);
3026 else if (decl
== error_mark_node
)
3028 else my_friendly_abort (22);
3029 vars
= TREE_CHAIN (vars
);
3030 /* Cleanup any temporaries needed for the initial value. */
3031 expand_cleanups_to (old_cleanups
);
3034 for (; static_ctors
; static_ctors
= TREE_CHAIN (static_ctors
))
3035 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors
),
3038 expand_end_bindings (getdecls(), 1, 0);
3042 finish_function (lineno
, 0, 0);
3043 assemble_constructor (IDENTIFIER_POINTER (fnname
));
3046 permanent_allocation (1);
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_NOT_REALLY_EXTERN (decl
))
3120 DECL_EXTERNAL (decl
) = 0;
3122 temporary_allocation ();
3123 output_inline_function (decl
);
3124 permanent_allocation (1);
3135 /* Now delete from the chain of variables all virtual function tables.
3136 We output them all ourselves, because each will be treated specially. */
3138 walk_vtables ((void (*)())0, prune_vtable_vardecl
);
3140 for (vars
= getdecls (); vars
; vars
= TREE_CHAIN (vars
))
3142 if (TREE_CODE (vars
) == THUNK_DECL
)
3144 else if (TREE_CODE (vars
) == FUNCTION_DECL
3145 && ! DECL_INTERFACE_KNOWN (vars
)
3146 && DECL_C_STATIC (vars
))
3147 TREE_PUBLIC (vars
) = 0;
3150 if (might_have_exceptions_p ())
3151 emit_exception_table ();
3153 if (write_virtuals
== 2)
3155 /* Now complain about an virtual function tables promised
3156 but not delivered. */
3157 while (pending_vtables
)
3159 if (TREE_PURPOSE (pending_vtables
) == NULL_TREE
)
3160 error ("virtual function table for `%s' not defined",
3161 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables
)));
3162 pending_vtables
= TREE_CHAIN (pending_vtables
);
3168 this_time
= get_run_time ();
3169 parse_time
-= this_time
- start_time
;
3170 varconst_time
+= this_time
- start_time
;
3172 if (flag_detailed_statistics
)
3173 dump_time_statistics ();
3176 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3177 expr. Since it was parsed like a type, we need to wade through and fix
3178 that. Unfortunately, since operator() is left-associative, we can't use
3179 tail recursion. In the above example, TYPE is `A', and DECL is
3182 Maybe this shouldn't be recursive, but how often will it actually be
3185 reparse_absdcl_as_expr (type
, decl
)
3188 /* do build_functional_cast (type, NULL_TREE) at bottom */
3189 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3190 return build_functional_cast (type
, NULL_TREE
);
3193 decl
= reparse_decl_as_expr (type
, TREE_OPERAND (decl
, 0));
3195 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_decl
);
3197 if (TREE_CODE (decl
) == CALL_EXPR
&& TREE_TYPE (decl
) != void_type_node
)
3198 decl
= require_complete_type (decl
);
3203 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3204 out to be an expr. Since it was parsed like a type, we need to wade
3205 through and fix that. Since casts are right-associative, we are
3206 reversing the order, so we don't have to recurse.
3208 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3211 reparse_absdcl_as_casts (decl
, expr
)
3216 if (TREE_CODE (expr
) == CONSTRUCTOR
)
3218 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3219 decl
= TREE_OPERAND (decl
, 0);
3221 if (IS_SIGNATURE (type
))
3223 error ("cast specifies signature type");
3224 return error_mark_node
;
3227 expr
= digest_init (type
, expr
, (tree
*) 0);
3228 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_SIZE (type
) == 0)
3230 int failure
= complete_array_type (type
, expr
, 1);
3232 my_friendly_abort (78);
3238 type
= groktypename (TREE_VALUE (TREE_OPERAND (decl
, 1)));
3239 decl
= TREE_OPERAND (decl
, 0);
3240 expr
= build_c_cast (type
, expr
, 0);
3246 /* Recursive helper function for reparse_decl_as_expr. It may be a good
3247 idea to reimplement this using an explicit stack, rather than recursion. */
3249 reparse_decl_as_expr1 (decl
)
3252 switch (TREE_CODE (decl
))
3254 case IDENTIFIER_NODE
:
3255 return do_identifier (decl
);
3257 return build_x_indirect_ref
3258 (reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)), "unary *");
3260 return build_x_unary_op (ADDR_EXPR
,
3261 reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)));
3263 return build_x_unary_op (BIT_NOT_EXPR
,
3264 reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)));
3266 return build_offset_ref (TREE_OPERAND (decl
, 0), TREE_OPERAND (decl
, 1));
3268 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl
, 0)),
3269 TREE_OPERAND (decl
, 1));
3271 my_friendly_abort (5);
3276 /* This is something of the form `int (*a)++' that has turned out to be an
3277 expr. It was only converted into parse nodes, so we need to go through
3278 and build up the semantics. Most of the work is done by
3279 reparse_decl_as_expr1, above.
3281 In the above example, TYPE is `int' and DECL is `*a'. */
3283 reparse_decl_as_expr (type
, decl
)
3286 decl
= reparse_decl_as_expr1 (decl
);
3288 return build_functional_cast (type
, build_tree_list (NULL_TREE
, decl
));
3293 /* This is something of the form `int (*a)' that has turned out to be a
3294 decl. It was only converted into parse nodes, so we need to do the
3295 checking that make_{pointer,reference}_declarator do. */
3298 finish_decl_parsing (decl
)
3301 extern int current_class_depth
;
3303 switch (TREE_CODE (decl
))
3305 case IDENTIFIER_NODE
:
3308 return make_pointer_declarator
3309 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3311 return make_reference_declarator
3312 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3314 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3317 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3318 TREE_COMPLEXITY (decl
) = current_class_depth
;
3321 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3324 my_friendly_abort (5);
3330 check_cp_case_value (value
)
3333 if (value
== NULL_TREE
)
3336 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3337 Strip such NOP_EXPRs. */
3338 if (TREE_CODE (value
) == NOP_EXPR
3339 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
3340 value
= TREE_OPERAND (value
, 0);
3342 if (TREE_READONLY_DECL_P (value
))
3344 value
= decl_constant_value (value
);
3345 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3346 Strip such NOP_EXPRs. */
3347 if (TREE_CODE (value
) == NOP_EXPR
3348 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
3349 value
= TREE_OPERAND (value
, 0);
3351 value
= fold (value
);
3353 if (TREE_CODE (value
) != INTEGER_CST
3354 && value
!= error_mark_node
)
3356 cp_error ("case label `%E' does not reduce to an integer constant",
3358 value
= error_mark_node
;
3361 /* Promote char or short to int. */
3362 value
= default_conversion (value
);
3364 constant_expression_warning (value
);
3369 static tree current_namespace
;
3371 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3372 postfix. Returns 0 if in global namespace. */
3376 tree x
= current_namespace
;
3378 x
= TREE_PURPOSE (x
);
3382 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3384 current_namespace_id (name
)
3387 tree old_id
= get_namespace_id ();
3390 /* Global names retain old encoding. */
3394 buf
= (char *) alloca (8 + IDENTIFIER_LENGTH (old_id
)
3395 + IDENTIFIER_LENGTH (name
));
3396 sprintf (buf
, "__ns_%s_%s", IDENTIFIER_POINTER (old_id
),
3397 IDENTIFIER_POINTER (name
));
3398 return get_identifier (buf
);
3401 /* Push into the scopre of the NAME namespace. */
3403 push_namespace (name
)
3406 tree old_id
= get_namespace_id ();
3409 current_namespace
= tree_cons (NULL_TREE
, name
, current_namespace
);
3410 buf
= (char *) alloca (4 + (old_id
? IDENTIFIER_LENGTH (old_id
) : 0)
3411 + IDENTIFIER_LENGTH (name
));
3412 sprintf (buf
, "%s%s", old_id
? IDENTIFIER_POINTER (old_id
) : "",
3413 IDENTIFIER_POINTER (name
));
3414 TREE_PURPOSE (current_namespace
) = get_identifier (buf
);
3417 /* Pop from the scope of the current namespace. */
3421 current_namespace
= TREE_CHAIN (current_namespace
);
3425 do_namespace_alias (alias
, namespace)
3426 tree alias
, namespace;
3431 do_using_decl (decl
)
3434 return error_mark_node
;
3438 do_using_directive (namespace)