1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Process declarations and symbol lookup for C front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
40 extern tree get_file_function_name ();
41 static void grok_function_init PROTO((tree, tree));
42 void import_export_decl ();
43 extern int current_class_depth;
45 /* A list of virtual function tables we must make sure to write out. */
48 /* A list of static class variables. This is needed, because a
49 static class variable can be declared inside the class without
50 an initializer, and then initialized, staticly, outside the class. */
53 /* A list of functions which were declared inline, but which we
54 may need to emit outline anyway. */
55 static tree saved_inlines;
57 /* Used to help generate temporary names which are unique within
58 a function. Reset to 0 by start_function. */
60 int temp_name_counter;
62 /* Same, but not reset. Local temp variables and global temp variables
63 can have the same name. */
64 static int global_temp_name_counter;
66 /* Flag used when debugging spew.c */
68 extern int spew_debug;
70 /* Nonzero if we're done parsing and into end-of-file activities. */
74 /* Functions called along with real static constructors and destructors. */
76 tree static_ctors, static_dtors;
78 /* C (and C++) language-specific option variables. */
80 /* Nonzero means allow type mismatches in conditional expressions;
81 just make their values `void'. */
83 int flag_cond_mismatch;
85 /* Nonzero means give `double' the same size as `float'. */
87 int flag_short_double;
89 /* Nonzero means don't recognize the keyword `asm'. */
93 /* Nonzero means don't recognize any extension keywords. */
95 int flag_no_gnu_keywords;
97 /* Nonzero means don't recognize the non-ANSI builtin functions. */
101 /* Nonzero means don't recognize the non-ANSI builtin functions.
104 int flag_no_nonansi_builtin;
106 /* Nonzero means do some things the same way PCC does. Only provided so
107 the compiler will link. */
109 int flag_traditional;
111 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
113 int flag_signed_bitfields = 1;
115 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
119 /* Nonzero means enable obscure ANSI features and disable GNU extensions
120 that might cause ANSI-compliant code to be miscompiled. */
124 /* Nonzero means do argument matching for overloading according to the
125 ANSI rules, rather than what g++ used to believe to be correct. */
127 int flag_ansi_overloading = 1;
129 /* Nonzero means do emit exported implementations of functions even if
130 they can be inlined. */
132 int flag_implement_inlines = 1;
134 /* Nonzero means do emit exported implementations of templates, instead of
135 multiple static copies in each file that needs a definition. */
137 int flag_external_templates;
139 /* Nonzero means that the decision to emit or not emit the implementation of a
140 template depends on where the template is instantiated, rather than where
143 int flag_alt_external_templates;
145 /* Nonzero means that implicit instantiations will be emitted if needed. */
147 int flag_implicit_templates = 1;
149 /* Nonzero means warn about implicit declarations. */
151 int warn_implicit = 1;
153 /* Nonzero means warn when all ctors or dtors are private, and the class
156 int warn_ctor_dtor_privacy = 1;
158 /* True if we want to implement vtables using "thunks".
159 The default is off. */
161 #if defined(NEW_OVER) && defined (__i386__)
162 int flag_vtable_thunks = 1;
164 int flag_vtable_thunks;
167 /* True if we want to deal with repository information. */
169 int flag_use_repository;
171 /* Nonzero means give string constants the type `const char *'
172 to get extra warnings from them. These warnings will be too numerous
173 to be useful, except in thoroughly ANSIfied programs. */
175 int warn_write_strings;
177 /* Nonzero means warn about pointer casts that can drop a type qualifier
178 from the pointer target type. */
182 /* Nonzero means warn that dbx info for template class methods isn't fully
185 int warn_template_debugging;
187 /* Nonzero means warn about sizeof(function) or addition/subtraction
188 of function pointers. */
190 int warn_pointer_arith = 1;
192 /* Nonzero means warn for any function def without prototype decl. */
194 int warn_missing_prototypes;
196 /* Nonzero means warn about multiple (redundant) decls for the same single
197 variable or function. */
199 int warn_redundant_decls;
201 /* Warn if initializer is not completely bracketed. */
203 int warn_missing_braces;
205 /* Warn about comparison of signed and unsigned values. */
207 int warn_sign_compare;
209 /* Warn about *printf or *scanf format/argument anomalies. */
213 /* Warn about a subscript that has type char. */
215 int warn_char_subscripts;
217 /* Warn if a type conversion is done that might have confusing results. */
221 /* Warn if adding () is suggested. */
223 int warn_parentheses;
225 /* Non-zero means warn in function declared in derived class has the
226 same name as a virtual in the base class, but fails to match the
227 type signature of any virtual function in the base class. */
228 int warn_overloaded_virtual;
230 /* Non-zero means warn when declaring a class that has a non virtual
231 destructor, when it really ought to have a virtual one. */
234 /* Non-zero means warn when a function is declared extern and later inline. */
235 int warn_extern_inline;
237 /* Non-zero means warn when the compiler will reorder code. */
240 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
243 /* Non-zero means warn when we convert a pointer to member function
244 into a pointer to (void or function). */
245 int warn_pmf2ptr = 1;
247 /* Nonzero means `$' can be in an identifier.
248 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
250 #ifndef DOLLARS_IN_IDENTIFIERS
251 #define DOLLARS_IN_IDENTIFIERS 1
253 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
255 /* Nonzero for -fno-strict-prototype switch: do not consider empty
256 argument prototype to mean function takes no arguments. */
258 int flag_strict_prototype = 2;
259 int strict_prototype = 1;
260 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
262 /* Nonzero means that labels can be used as first-class objects */
266 /* Non-zero means to collect statistics which might be expensive
267 and to print them when we are done. */
268 int flag_detailed_statistics;
270 /* C++ specific flags. */
271 /* Nonzero for -fall-virtual: make every member function (except
272 constructors) lay down in the virtual function table. Calls
273 can then either go through the virtual function table or not,
276 int flag_all_virtual;
278 /* Zero means that `this' is a *const. This gives nice behavior in the
279 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
280 -2 means we're constructing an object and it has fixed type. */
282 int flag_this_is_variable;
284 /* Nonzero means memoize our member lookups. */
286 int flag_memoize_lookups; int flag_save_memoized_contexts;
288 /* 3 means write out only virtuals function tables `defined'
289 in this implementation file.
290 2 means write out only specific virtual function tables
291 and give them (C) public access.
292 1 means write out virtual function tables and give them
294 0 means write out virtual function tables and give them
295 (C) static access (default).
296 -1 means declare virtual function tables extern. */
300 /* Nonzero means we should attempt to elide constructors when possible. */
302 int flag_elide_constructors;
304 /* Nonzero means recognize and handle signature language constructs. */
306 int flag_handle_signatures;
308 /* Nonzero means that member functions defined in class scope are
309 inline by default. */
311 int flag_default_inline = 1;
313 /* Controls whether enums and ints freely convert.
314 1 means with complete freedom.
315 0 means enums can convert to ints, but not vice-versa. */
316 int flag_int_enum_equivalence;
318 /* Controls whether compiler generates 'type descriptor' that give
319 run-time type information. */
322 /* Nonzero if we wish to output cross-referencing information
323 for the GNU class browser. */
324 extern int flag_gnu_xref;
326 /* Nonzero if compiler can make `reasonable' assumptions about
327 references and objects. For example, the compiler must be
328 conservative about the following and not assume that `a' is nonnull:
333 In general, it is `reasonable' to assume that for many programs,
334 and better code can be generated in that case. */
336 int flag_assume_nonnull_objects = 1;
338 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
341 int flag_huge_objects;
343 /* Nonzero if we want to conserve space in the .o files. We do this
344 by putting uninitialized data and runtime initialized data into
345 .common instead of .data at the expense of not flagging multiple
348 int flag_conserve_space;
350 /* Nonzero if we want to obey access control semantics. */
352 int flag_access_control = 1;
354 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
356 int flag_operator_names;
358 /* Nonzero if we want to check the return value of new and avoid calling
359 constructors if it is a null pointer. */
363 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
364 initialization variables.
365 0: Old rules, set by -fno-for-scope.
366 2: New ANSI rules, set by -ffor-scope.
367 1: Try to implement new ANSI rules, but with backup compatibility
368 (and warnings). This is the default, for now. */
370 int flag_new_for_scope = 1;
372 /* Nonzero if we want to emit defined symbols with common-like linkage as
373 weak symbols where possible, in order to conform to C++ semantics.
374 Otherwise, emit them as local symbols. */
378 /* Maximum template instantiation depth. Must be at least 17 for ANSI
381 int max_tinst_depth = 17;
383 /* Table of language-dependent -f options.
384 STRING is the option name. VARIABLE is the address of the variable.
385 ON_VALUE is the value to store in VARIABLE
386 if `-fSTRING' is seen as an option.
387 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
389 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
391 {"signed-char", &flag_signed_char, 1},
392 {"unsigned-char", &flag_signed_char, 0},
393 {"signed-bitfields", &flag_signed_bitfields, 1},
394 {"unsigned-bitfields", &flag_signed_bitfields, 0},
395 {"short-enums", &flag_short_enums, 1},
396 {"short-double", &flag_short_double, 1},
397 {"cond-mismatch", &flag_cond_mismatch, 1},
398 {"asm", &flag_no_asm, 0},
399 {"builtin", &flag_no_builtin, 0},
400 {"ident", &flag_no_ident, 0},
401 {"labels-ok", &flag_labels_ok, 1},
402 {"stats", &flag_detailed_statistics, 1},
403 {"this-is-variable", &flag_this_is_variable, 1},
404 {"strict-prototype", &flag_strict_prototype, 1},
405 {"all-virtual", &flag_all_virtual, 1},
406 {"memoize-lookups", &flag_memoize_lookups, 1},
407 {"elide-constructors", &flag_elide_constructors, 1},
408 {"handle-signatures", &flag_handle_signatures, 1},
409 {"default-inline", &flag_default_inline, 1},
410 {"dollars-in-identifiers", &dollars_in_ident, 1},
411 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
412 {"rtti", &flag_rtti, 1},
413 {"xref", &flag_gnu_xref, 1},
414 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
415 {"implement-inlines", &flag_implement_inlines, 1},
416 {"external-templates", &flag_external_templates, 1},
417 {"implicit-templates", &flag_implicit_templates, 1},
418 {"ansi-overloading", &flag_ansi_overloading, 1},
419 {"huge-objects", &flag_huge_objects, 1},
420 {"conserve-space", &flag_conserve_space, 1},
421 {"vtable-thunks", &flag_vtable_thunks, 1},
422 {"access-control", &flag_access_control, 1},
423 {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
424 {"gnu-keywords", &flag_no_gnu_keywords, 0},
425 {"operator-names", &flag_operator_names, 1},
426 {"check-new", &flag_check_new, 1},
427 {"repo", &flag_use_repository, 1},
428 {"for-scope", &flag_new_for_scope, 2},
429 {"weak", &flag_weak, 1}
432 /* Decode the string P as a language-specific option.
433 Return 1 if it is recognized (and handle it);
434 return 0 if not recognized. */
437 lang_decode_option (p)
440 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
441 dollars_in_ident = 1, flag_writable_strings = 1,
442 flag_this_is_variable = 1, flag_new_for_scope = 0;
443 /* The +e options are for cfront compatibility. They come in as
444 `-+eN', to kludge around gcc.c's argument handling. */
445 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
447 int old_write_virtuals = write_virtuals;
450 else if (p[3] == '0')
452 else if (p[3] == '2')
454 else error ("invalid +e option");
455 if (old_write_virtuals != 0
456 && write_virtuals != old_write_virtuals)
457 error ("conflicting +e options given");
459 else if (p[0] == '-' && p[1] == 'f')
461 /* Some kind of -f option.
462 P's value is the option sans `-f'.
463 Search for it in the table of options. */
467 /* Try special -f options. */
469 if (!strcmp (p, "save-memoized"))
471 flag_memoize_lookups = 1;
472 flag_save_memoized_contexts = 1;
475 if (!strcmp (p, "no-save-memoized"))
477 flag_memoize_lookups = 0;
478 flag_save_memoized_contexts = 0;
481 else if (! strcmp (p, "alt-external-templates"))
483 flag_external_templates = 1;
484 flag_alt_external_templates = 1;
487 else if (! strcmp (p, "no-alt-external-templates"))
489 flag_alt_external_templates = 0;
492 else if (!strcmp (p, "repo"))
494 flag_use_repository = 1;
495 flag_implicit_templates = 0;
498 else if (!strncmp (p, "template-depth-", 15))
503 if (*endp >= '0' && *endp <= '9')
507 error ("Invalid option `%s'", p - 2);
508 goto template_depth_lose;
511 max_tinst_depth = atoi (p + 15);
512 template_depth_lose: ;
515 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
518 if (!strcmp (p, lang_f_options[j].string))
520 *lang_f_options[j].variable = lang_f_options[j].on_value;
521 /* A goto here would be cleaner,
522 but breaks the vax pcc. */
525 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
526 && ! strcmp (p+3, lang_f_options[j].string))
528 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
534 else if (p[0] == '-' && p[1] == 'W')
538 /* The -W options control the warning behavior of the compiler. */
541 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
544 if (!strcmp (p, "implicit"))
545 warn_implicit = setting;
546 else if (!strcmp (p, "return-type"))
547 warn_return_type = setting;
548 else if (!strcmp (p, "ctor-dtor-privacy"))
549 warn_ctor_dtor_privacy = setting;
550 else if (!strcmp (p, "write-strings"))
551 warn_write_strings = setting;
552 else if (!strcmp (p, "cast-qual"))
553 warn_cast_qual = setting;
554 else if (!strcmp (p, "char-subscripts"))
555 warn_char_subscripts = setting;
556 else if (!strcmp (p, "pointer-arith"))
557 warn_pointer_arith = setting;
558 else if (!strcmp (p, "missing-prototypes"))
559 warn_missing_prototypes = setting;
560 else if (!strcmp (p, "redundant-decls"))
561 warn_redundant_decls = setting;
562 else if (!strcmp (p, "missing-braces"))
563 warn_missing_braces = setting;
564 else if (!strcmp (p, "sign-compare"))
565 warn_sign_compare = setting;
566 else if (!strcmp (p, "format"))
567 warn_format = setting;
568 else if (!strcmp (p, "conversion"))
569 warn_conversion = setting;
570 else if (!strcmp (p, "parentheses"))
571 warn_parentheses = setting;
572 else if (!strcmp (p, "non-virtual-dtor"))
573 warn_nonvdtor = setting;
574 else if (!strcmp (p, "extern-inline"))
575 warn_extern_inline = setting;
576 else if (!strcmp (p, "reorder"))
577 warn_reorder = setting;
578 else if (!strcmp (p, "synth"))
579 warn_synth = setting;
580 else if (!strcmp (p, "pmf-conversions"))
581 warn_pmf2ptr = setting;
582 else if (!strcmp (p, "comment"))
583 ; /* cpp handles this one. */
584 else if (!strcmp (p, "comments"))
585 ; /* cpp handles this one. */
586 else if (!strcmp (p, "trigraphs"))
587 ; /* cpp handles this one. */
588 else if (!strcmp (p, "import"))
589 ; /* cpp handles this one. */
590 else if (!strcmp (p, "all"))
592 warn_return_type = setting;
593 warn_unused = setting;
594 warn_implicit = setting;
595 warn_ctor_dtor_privacy = setting;
596 warn_switch = setting;
597 warn_format = setting;
598 warn_parentheses = setting;
599 warn_missing_braces = setting;
600 warn_sign_compare = setting;
601 warn_extern_inline = setting;
602 warn_nonvdtor = setting;
603 /* We save the value of warn_uninitialized, since if they put
604 -Wuninitialized on the command line, we need to generate a
605 warning about not using it without also specifying -O. */
606 if (warn_uninitialized != 1)
607 warn_uninitialized = (setting ? 2 : 0);
608 warn_template_debugging = setting;
609 warn_reorder = setting;
612 else if (!strcmp (p, "overloaded-virtual"))
613 warn_overloaded_virtual = setting;
616 else if (!strcmp (p, "-ansi"))
617 dollars_in_ident = 0, flag_no_nonansi_builtin = 1, flag_ansi = 1,
618 flag_no_gnu_keywords = 1, flag_operator_names = 1;
620 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
621 it's probably safe to assume no sane person would ever want to use this
622 under normal circumstances. */
623 else if (!strcmp (p, "-spew-debug"))
632 /* Incorporate `const' and `volatile' qualifiers for member functions.
633 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
634 QUALS is a list of qualifiers. */
637 grok_method_quals (ctype, function, quals)
638 tree ctype, function, quals;
640 tree fntype = TREE_TYPE (function);
641 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
645 extern tree ridpointers[];
647 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
649 if (TYPE_READONLY (ctype))
650 error ("duplicate `%s' %s",
651 IDENTIFIER_POINTER (TREE_VALUE (quals)),
652 (TREE_CODE (function) == FUNCTION_DECL
653 ? "for member function" : "in type declaration"));
654 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
655 build_pointer_type (ctype);
657 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
659 if (TYPE_VOLATILE (ctype))
660 error ("duplicate `%s' %s",
661 IDENTIFIER_POINTER (TREE_VALUE (quals)),
662 (TREE_CODE (function) == FUNCTION_DECL
663 ? "for member function" : "in type declaration"));
664 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
665 build_pointer_type (ctype);
668 my_friendly_abort (20);
669 quals = TREE_CHAIN (quals);
672 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
673 (TREE_CODE (fntype) == METHOD_TYPE
674 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
675 : TYPE_ARG_TYPES (fntype)));
677 fntype = build_exception_variant (fntype, raises);
679 TREE_TYPE (function) = fntype;
683 #if 0 /* Not used. */
684 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
685 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
686 /* This does not yet work with user defined conversion operators
690 substitute_nice_name (decl)
693 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
695 char *n = decl_as_string (DECL_NAME (decl), 1);
696 if (n[strlen (n) - 1] == ' ')
697 n[strlen (n) - 1] = 0;
698 DECL_NAME (decl) = get_identifier (n);
703 /* Warn when -fexternal-templates is used and #pragma
704 interface/implementation is not used all the times it should be,
708 warn_if_unknown_interface (decl)
711 static int already_warned = 0;
712 if (already_warned++)
715 if (flag_alt_external_templates)
717 struct tinst_level *til = tinst_for_decl ();
719 char *sf = input_filename;
724 input_filename = til->file;
726 cp_warning ("template `%#D' instantiated in file without #pragma interface",
732 cp_warning_at ("template `%#D' defined in file without #pragma interface",
736 /* A subroutine of the parser, to handle a component list. */
739 grok_x_components (specs, components)
740 tree specs, components;
742 register tree t, x, tcode;
744 /* We just got some friends. They have been recorded elsewhere. */
745 if (components == void_type_node)
748 if (components == NULL_TREE)
750 t = groktypename (build_decl_list (specs, NULL_TREE));
754 error ("error in component specification");
758 switch (TREE_CODE (t))
761 /* Static anonymous unions come out as VAR_DECLs. */
762 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
763 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
766 /* We return SPECS here, because in the parser it was ending
767 up with not doing anything to $$, which is what SPECS
773 /* This code may be needed for UNION_TYPEs as
775 tcode = record_type_node;
776 if (CLASSTYPE_DECLARED_CLASS (t))
777 tcode = class_type_node;
778 else if (IS_SIGNATURE (t))
779 tcode = signature_type_node;
781 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
782 if (TYPE_CONTEXT (t))
783 CLASSTYPE_NO_GLOBALIZE (t) = 1;
789 if (TREE_CODE (t) == UNION_TYPE)
790 tcode = union_type_node;
792 tcode = enum_type_node;
794 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
795 if (TREE_CODE (t) == UNION_TYPE && TYPE_CONTEXT (t))
796 CLASSTYPE_NO_GLOBALIZE (t) = 1;
797 if (TREE_CODE (t) == UNION_TYPE
798 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
800 /* See also shadow_tag. */
802 struct pending_inline **p;
804 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
806 /* Wipe out memory of synthesized methods */
807 TYPE_HAS_CONSTRUCTOR (t) = 0;
808 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
809 TYPE_HAS_INIT_REF (t) = 0;
810 TYPE_HAS_CONST_INIT_REF (t) = 0;
811 TYPE_HAS_ASSIGN_REF (t) = 0;
812 TYPE_HAS_ASSIGNMENT (t) = 0;
813 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
815 q = &TYPE_METHODS (t);
818 if (DECL_ARTIFICIAL (*q))
819 *q = TREE_CHAIN (*q);
821 q = &TREE_CHAIN (*q);
823 if (TYPE_METHODS (t))
824 error ("an anonymous union cannot have function members");
826 p = &pending_inlines;
827 for (; *p; *p = (*p)->next)
828 if (DECL_CONTEXT ((*p)->fndecl) != t)
831 else if (TREE_CODE (t) == ENUMERAL_TYPE)
832 x = grok_enum_decls (t, NULL_TREE);
839 if (t != void_type_node)
840 error ("empty component declaration");
846 t = TREE_TYPE (components);
847 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
848 return grok_enum_decls (t, components);
854 /* Classes overload their constituent function names automatically.
855 When a function name is declared in a record structure,
856 its name is changed to it overloaded name. Since names for
857 constructors and destructors can conflict, we place a leading
860 CNAME is the name of the class we are grokking for.
862 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
864 FLAGS contains bits saying what's special about today's
865 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
867 If FUNCTION is a destructor, then we must add the `auto-delete' field
868 as a second parameter. There is some hair associated with the fact
869 that we must "declare" this variable in the manner consistent with the
870 way the rest of the arguments were declared.
872 QUALS are the qualifiers for the this pointer. */
875 grokclassfn (ctype, cname, function, flags, quals)
876 tree ctype, cname, function;
877 enum overload_flags flags;
880 tree fn_name = DECL_NAME (function);
884 tree fntype = TREE_TYPE (function);
885 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
887 if (fn_name == NULL_TREE)
889 error ("name missing for member function");
890 fn_name = get_identifier ("<anonymous>");
891 DECL_NAME (function) = fn_name;
895 qualtype = grok_method_quals (ctype, function, quals);
899 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
900 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
902 /* Must add the class instance variable up front. */
903 /* Right now we just make this a pointer. But later
904 we may wish to make it special. */
905 tree type = TREE_VALUE (arg_types);
908 if ((flag_this_is_variable > 0)
909 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
912 if (DECL_CONSTRUCTOR_P (function))
914 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
916 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
917 /* In this case we need "in-charge" flag saying whether
918 this constructor is responsible for initialization
919 of virtual baseclasses or not. */
920 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
921 /* Mark the artificial `__in_chrg' parameter as "artificial". */
922 SET_DECL_ARTIFICIAL (parm);
923 DECL_ARG_TYPE (parm) = integer_type_node;
924 TREE_READONLY (parm) = 1;
925 TREE_CHAIN (parm) = last_function_parms;
926 last_function_parms = parm;
930 parm = build_decl (PARM_DECL, this_identifier, type);
931 /* Mark the artificial `this' parameter as "artificial". */
932 SET_DECL_ARTIFICIAL (parm);
933 DECL_ARG_TYPE (parm) = type;
934 /* We can make this a register, so long as we don't
935 accidentally complain if someone tries to take its address. */
936 DECL_REGISTER (parm) = 1;
938 TREE_READONLY (parm) = 1;
939 TREE_CHAIN (parm) = last_function_parms;
940 last_function_parms = parm;
943 if (flags == DTOR_FLAG)
946 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
947 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
949 arg_types = hash_tree_chain (const_integer_type, void_list_node);
950 TREE_SIDE_EFFECTS (arg_types) = 1;
951 /* Build the overload name. It will look like `7Example'. */
952 if (IDENTIFIER_TYPE_VALUE (cname))
953 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
954 else if (IDENTIFIER_LOCAL_VALUE (cname))
955 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
957 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
958 it's defined out of the class definition, since poplevel_class wipes
959 it out. This used to be internal error 346. */
960 dbuf = build_overload_name (ctype, 1, 1);
961 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
962 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
965 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
966 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
967 /* Mark the artificial `__in_chrg' parameter as "artificial". */
968 SET_DECL_ARTIFICIAL (parm);
969 TREE_READONLY (parm) = 1;
970 DECL_ARG_TYPE (parm) = integer_type_node;
971 /* This is the same chain as DECL_ARGUMENTS (...). */
972 TREE_CHAIN (last_function_parms) = parm;
974 fntype = build_cplus_method_type (qualtype, void_type_node,
978 fntype = build_exception_variant (fntype, raises);
980 TREE_TYPE (function) = fntype;
981 TYPE_HAS_DESTRUCTOR (ctype) = 1;
985 tree these_arg_types;
987 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
989 arg_types = hash_tree_chain (integer_type_node,
990 TREE_CHAIN (arg_types));
991 fntype = build_cplus_method_type (qualtype,
992 TREE_TYPE (TREE_TYPE (function)),
996 fntype = build_exception_variant (fntype, raises);
998 TREE_TYPE (function) = fntype;
999 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
1002 these_arg_types = arg_types;
1004 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
1005 /* Only true for static member functions. */
1006 these_arg_types = hash_tree_chain (build_pointer_type (qualtype),
1009 DECL_ASSEMBLER_NAME (function)
1010 = build_decl_overload (fn_name, these_arg_types,
1011 1 + DECL_CONSTRUCTOR_P (function));
1014 /* This code is going into the compiler, but currently, it makes
1015 libg++/src/Integer.cc not compile. The problem is that the nice name
1016 winds up going into the symbol table, and conversion operations look
1017 for the manged name. */
1018 substitute_nice_name (function);
1022 DECL_ARGUMENTS (function) = last_function_parms;
1023 /* First approximations. */
1024 DECL_CONTEXT (function) = ctype;
1025 DECL_CLASS_CONTEXT (function) = ctype;
1028 /* Work on the expr used by alignof (this is only called by the parser). */
1037 if (TREE_CODE (expr) == COMPONENT_REF
1038 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
1039 error ("`__alignof__' applied to a bit-field");
1041 if (TREE_CODE (expr) == INDIRECT_REF)
1043 best = t = TREE_OPERAND (expr, 0);
1044 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1046 while (TREE_CODE (t) == NOP_EXPR
1047 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1050 t = TREE_OPERAND (t, 0);
1051 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1052 if (thisalign > bestalign)
1053 best = t, bestalign = thisalign;
1055 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1059 /* ANSI says arrays and fns are converted inside comma.
1060 But we can't convert them in build_compound_expr
1061 because that would break commas in lvalues.
1062 So do the conversion here if operand was a comma. */
1063 if (TREE_CODE (expr) == COMPOUND_EXPR
1064 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1065 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1066 expr = default_conversion (expr);
1067 return c_alignof (TREE_TYPE (expr));
1071 /* Create an ARRAY_REF, checking for the user doing things backwards
1075 grok_array_decl (array_expr, index_exp)
1076 tree array_expr, index_exp;
1078 tree type = TREE_TYPE (array_expr);
1079 tree p1, p2, i1, i2;
1081 if (type == error_mark_node || index_exp == error_mark_node)
1082 return error_mark_node;
1083 if (processing_template_decl)
1084 return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE,
1085 array_expr, index_exp);
1087 if (type == NULL_TREE)
1089 /* Something has gone very wrong. Assume we are mistakenly reducing
1090 an expression instead of a declaration. */
1091 error ("parser may be lost: is there a '{' missing somewhere?");
1095 if (TREE_CODE (type) == OFFSET_TYPE
1096 || TREE_CODE (type) == REFERENCE_TYPE)
1097 type = TREE_TYPE (type);
1099 /* If they have an `operator[]', use that. */
1100 if (TYPE_LANG_SPECIFIC (type)
1101 && TYPE_OVERLOADS_ARRAY_REF (complete_type (type)))
1102 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1103 array_expr, index_exp, NULL_TREE);
1105 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1107 if (TREE_CODE (type) == ARRAY_TYPE)
1110 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1112 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1115 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1117 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1118 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1120 if ((p1 && i2) && (i1 && p2))
1121 error ("ambiguous conversion for array subscript");
1124 array_expr = p1, index_exp = i2;
1126 array_expr = p2, index_exp = i1;
1129 cp_error ("invalid types `%T[%T]' for array subscript",
1130 type, TREE_TYPE (index_exp));
1131 return error_mark_node;
1134 if (array_expr == error_mark_node || index_exp == error_mark_node)
1135 error ("ambiguous conversion for array subscript");
1137 return build_array_ref (array_expr, index_exp);
1140 /* Given the cast expression EXP, checking out its validity. Either return
1141 an error_mark_node if there was an unavoidable error, return a cast to
1142 void for trying to delete a pointer w/ the value 0, or return the
1143 call to delete. If DOING_VEC is 1, we handle things differently
1144 for doing an array delete. If DOING_VEC is 2, they gave us the
1145 array size as an argument to delete.
1146 Implements ARM $5.3.4. This is called from the parser. */
1149 delete_sanity (exp, size, doing_vec, use_global_delete)
1151 int doing_vec, use_global_delete;
1155 enum tree_code code;
1156 /* For a regular vector delete (aka, no size argument) we will pass
1157 this down as a NULL_TREE into build_vec_delete. */
1158 tree maxindex = NULL_TREE;
1160 if (exp == error_mark_node)
1163 if (processing_template_decl)
1165 t = build_min (DELETE_EXPR, void_type_node, exp, size);
1166 DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
1167 DELETE_EXPR_USE_VEC (t) = doing_vec;
1171 t = stabilize_reference (convert_from_reference (exp));
1172 type = TREE_TYPE (t);
1173 code = TREE_CODE (type);
1178 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1179 pedwarn ("anachronistic use of array size in vector delete");
1184 if (code != POINTER_TYPE)
1186 cp_error ("type `%#T' argument given to `delete', expected pointer",
1188 return error_mark_node;
1191 /* Deleting a pointer with the value zero is valid and has no effect. */
1192 if (integer_zerop (t))
1193 return build1 (NOP_EXPR, void_type_node, t);
1196 if (code == POINTER_TYPE)
1199 /* As of Valley Forge, you can delete a pointer to constant. */
1200 /* You can't delete a pointer to constant. */
1201 if (TREE_READONLY (TREE_TYPE (type)))
1203 error ("`const *' cannot be deleted");
1204 return error_mark_node;
1207 /* You also can't delete functions. */
1208 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1210 error ("cannot delete a function");
1211 return error_mark_node;
1216 /* If the type has no destructor, then we should build a regular
1217 delete, instead of a vector delete. Otherwise, we would end
1218 up passing a bogus offset into __builtin_delete, which is
1219 not expecting it. */
1221 && TREE_CODE (type) == POINTER_TYPE
1222 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1225 use_global_delete = 1;
1230 return build_vec_delete (t, maxindex, integer_one_node,
1231 integer_two_node, use_global_delete);
1234 if (IS_AGGR_TYPE (TREE_TYPE (type))
1235 && TYPE_GETS_REG_DELETE (TREE_TYPE (type)))
1237 /* Only do access checking here; we'll be calling op delete
1238 from the destructor. */
1239 tree tmp = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, t,
1240 size_zero_node, NULL_TREE);
1241 if (tmp == error_mark_node)
1242 return error_mark_node;
1245 return build_delete (type, t, integer_three_node,
1246 LOOKUP_NORMAL, use_global_delete);
1250 /* Sanity check: report error if this function FUNCTION is not
1251 really a member of the class (CTYPE) it is supposed to belong to.
1252 CNAME is the same here as it is for grokclassfn above. */
1255 check_classfn (ctype, function)
1256 tree ctype, function;
1258 tree fn_name = DECL_NAME (function);
1260 tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype));
1264 if (method_vec != 0)
1266 methods = &TREE_VEC_ELT (method_vec, 0);
1267 end = TREE_VEC_END (method_vec);
1269 /* First suss out ctors and dtors. */
1270 if (*methods && fn_name == DECL_NAME (*methods)
1271 && DECL_CONSTRUCTOR_P (function))
1273 if (*++methods && fn_name == DECL_NAME (*methods)
1274 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)))
1277 while (++methods != end)
1279 if (fn_name == DECL_NAME (*methods))
1285 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1288 /* This doesn't work for static member functions that are
1289 pretending to be methods. */
1290 /* We have to do more extensive argument checking here, as
1291 the name may have been changed by asm("new_name"). */
1292 if (decls_match (function, fndecl))
1295 if (DECL_NAME (function) == DECL_NAME (fndecl))
1297 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1298 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1300 /* Get rid of the this parameter on functions that become
1302 if (DECL_STATIC_FUNCTION_P (fndecl)
1303 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1304 p1 = TREE_CHAIN (p1);
1306 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1307 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1308 && compparms (p1, p2, 3))
1312 fndecl = DECL_CHAIN (fndecl);
1321 tree fndecl = *methods;
1322 cp_error ("prototype for `%#D' does not match any in class `%T'",
1324 cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl) ? "s are" : " is",
1326 while (fndecl = DECL_CHAIN (fndecl), fndecl)
1327 cp_error_at (" %#D", fndecl);
1332 cp_error ("no `%#D' member function declared in class `%T'",
1336 /* If we did not find the method in the class, add it to avoid
1338 add_method (ctype, methods, function);
1342 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1343 of a structure component, returning a FIELD_DECL node.
1344 QUALS is a list of type qualifiers for this decl (such as for declaring
1345 const member functions).
1347 This is done during the parsing of the struct declaration.
1348 The FIELD_DECL nodes are chained together and the lot of them
1349 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1353 If class A defines that certain functions in class B are friends, then
1354 the way I have set things up, it is B who is interested in permission
1355 granted by A. However, it is in A's context that these declarations
1356 are parsed. By returning a void_type_node, class A does not attempt
1357 to incorporate the declarations of the friends within its structure.
1359 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1360 CHANGES TO CODE IN `start_method'. */
1363 grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
1364 tree declarator, declspecs, init, asmspec_tree, attrlist;
1366 register tree value;
1368 int flags = LOOKUP_ONLYCONVERTING;
1370 /* Convert () initializers to = initializers. */
1371 if (init == NULL_TREE && declarator != NULL_TREE
1372 && TREE_CODE (declarator) == CALL_EXPR
1373 && TREE_OPERAND (declarator, 0)
1374 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1375 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1376 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1378 init = TREE_OPERAND (declarator, 1);
1379 declarator = TREE_OPERAND (declarator, 0);
1383 if (declspecs == NULL_TREE
1384 && TREE_CODE (declarator) == SCOPE_REF
1385 && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE)
1387 /* Access declaration */
1388 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0))))
1390 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
1391 pop_nested_class (1);
1392 return do_class_using_decl (declarator);
1396 && TREE_CODE (init) == TREE_LIST
1397 && TREE_VALUE (init) == error_mark_node
1398 && TREE_CHAIN (init) == NULL_TREE)
1401 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, NULL_TREE);
1403 return value; /* friend or constructor went bad. */
1405 /* Pass friendly classes back. */
1406 if (TREE_CODE (value) == VOID_TYPE)
1407 return void_type_node;
1409 if (DECL_NAME (value) != NULL_TREE
1410 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1411 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1412 cp_error ("member `%D' conflicts with virtual function table field name", value);
1414 /* Stash away type declarations. */
1415 if (TREE_CODE (value) == TYPE_DECL)
1417 DECL_NONLOCAL (value) = 1;
1418 DECL_CONTEXT (value) = current_class_type;
1419 DECL_CLASS_CONTEXT (value) = current_class_type;
1420 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1422 pushdecl_class_level (value);
1426 if (IS_SIGNATURE (current_class_type)
1427 && TREE_CODE (value) != FUNCTION_DECL)
1429 error ("field declaration not allowed in signature");
1430 return void_type_node;
1433 if (DECL_IN_AGGR_P (value))
1435 cp_error ("`%D' is already defined in the class %T", value,
1436 DECL_CONTEXT (value));
1437 return void_type_node;
1441 asmspec = TREE_STRING_POINTER (asmspec_tree);
1445 if (IS_SIGNATURE (current_class_type)
1446 && TREE_CODE (value) == FUNCTION_DECL)
1448 error ("function declarations cannot have initializers in signature");
1451 else if (TREE_CODE (value) == FUNCTION_DECL)
1453 grok_function_init (value, init);
1456 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1457 /* Already complained in grokdeclarator. */
1461 /* We allow initializers to become parameters to base
1463 if (TREE_CODE (init) == TREE_LIST)
1465 if (TREE_CHAIN (init) == NULL_TREE)
1466 init = TREE_VALUE (init);
1468 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1471 if (TREE_CODE (init) == CONST_DECL)
1472 init = DECL_INITIAL (init);
1473 else if (TREE_READONLY_DECL_P (init))
1474 init = decl_constant_value (init);
1475 else if (TREE_CODE (init) == CONSTRUCTOR)
1476 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1477 my_friendly_assert (TREE_PERMANENT (init), 192);
1478 if (init == error_mark_node)
1479 /* We must make this look different than `error_mark_node'
1480 because `decl_const_value' would mis-interpret it
1481 as only meaning that this VAR_DECL is defined. */
1482 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1483 else if (processing_template_decl)
1485 else if (! TREE_CONSTANT (init))
1487 /* We can allow references to things that are effectively
1488 static, since references are initialized with the address. */
1489 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1490 || (TREE_STATIC (init) == 0
1491 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1492 || DECL_EXTERNAL (init) == 0)))
1494 error ("field initializer is not constant");
1495 init = error_mark_node;
1501 /* The corresponding pop_obstacks is in cp_finish_decl. */
1502 push_obstacks_nochange ();
1504 if (processing_template_decl && ! current_function_decl
1505 && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
1506 push_template_decl (value);
1509 cplus_decl_attributes (value, TREE_PURPOSE (attrlist),
1510 TREE_VALUE (attrlist));
1512 if (TREE_CODE (value) == VAR_DECL)
1514 /* We cannot call pushdecl here, because that would
1515 fill in the value of our TREE_CHAIN. Instead, we
1516 modify cp_finish_decl to do the right thing, namely, to
1517 put this decl out straight away. */
1518 if (TREE_PUBLIC (value))
1520 /* current_class_type can be NULL_TREE in case of error. */
1521 if (asmspec == 0 && current_class_type)
1523 TREE_PUBLIC (value) = 1;
1524 DECL_INITIAL (value) = error_mark_node;
1525 DECL_ASSEMBLER_NAME (value)
1526 = build_static_name (current_class_type, DECL_NAME (value));
1528 if (! processing_template_decl)
1529 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1531 /* Static consts need not be initialized in the class definition. */
1532 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1534 static int explanation = 0;
1536 error ("initializer invalid for static member with constructor");
1537 if (explanation++ == 0)
1538 error ("(you really want to initialize it separately)");
1541 /* Force the compiler to know when an uninitialized static
1542 const member is being used. */
1543 if (TYPE_READONLY (value) && init == 0)
1544 TREE_USED (value) = 1;
1546 DECL_INITIAL (value) = init;
1547 DECL_IN_AGGR_P (value) = 1;
1548 DECL_CONTEXT (value) = current_class_type;
1549 DECL_CLASS_CONTEXT (value) = current_class_type;
1551 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1552 pushdecl_class_level (value);
1555 if (TREE_CODE (value) == FIELD_DECL)
1559 /* This must override the asm specifier which was placed
1560 by grokclassfn. Lay this out fresh. */
1561 DECL_RTL (value) = NULL_RTX;
1562 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1564 if (DECL_INITIAL (value) == error_mark_node)
1565 init = error_mark_node;
1566 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1567 DECL_INITIAL (value) = init;
1568 DECL_IN_AGGR_P (value) = 1;
1571 if (TREE_CODE (value) == FUNCTION_DECL)
1573 check_default_args (value);
1574 if (DECL_CHAIN (value) != NULL_TREE)
1576 /* Need a fresh node here so that we don't get circularity
1577 when we link these together. */
1578 value = copy_node (value);
1579 /* When does this happen? */
1580 my_friendly_assert (init == NULL_TREE, 193);
1584 /* This must override the asm specifier which was placed
1585 by grokclassfn. Lay this out fresh. */
1586 DECL_RTL (value) = NULL_RTX;
1587 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1589 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1591 /* Pass friends back this way. */
1592 if (DECL_FRIEND_P (value))
1593 return void_type_node;
1595 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1596 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1597 cp_error ("method `%#D' of local class must be defined in class body",
1601 DECL_IN_AGGR_P (value) = 1;
1604 my_friendly_abort (21);
1609 /* Like `grokfield', but for bitfields.
1610 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1613 grokbitfield (declarator, declspecs, width)
1614 tree declarator, declspecs, width;
1616 register tree value = grokdeclarator (declarator, declspecs, BITFIELD,
1619 if (! value) return NULL_TREE; /* friends went bad. */
1621 /* Pass friendly classes back. */
1622 if (TREE_CODE (value) == VOID_TYPE)
1623 return void_type_node;
1625 if (TREE_CODE (value) == TYPE_DECL)
1627 cp_error ("cannot declare `%D' to be a bitfield type", value);
1631 if (IS_SIGNATURE (current_class_type))
1633 error ("field declaration not allowed in signature");
1634 return void_type_node;
1637 if (DECL_IN_AGGR_P (value))
1639 cp_error ("`%D' is already defined in the class %T", value,
1640 DECL_CONTEXT (value));
1641 return void_type_node;
1644 GNU_xref_member (current_class_name, value);
1646 if (TREE_STATIC (value))
1648 cp_error ("static member `%D' cannot be a bitfield", value);
1651 cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1653 if (width != error_mark_node)
1655 constant_expression_warning (width);
1656 DECL_INITIAL (value) = width;
1657 DECL_BIT_FIELD (value) = 1;
1660 DECL_IN_AGGR_P (value) = 1;
1665 grokoptypename (declspecs, declarator)
1666 tree declspecs, declarator;
1668 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1669 return build_typename_overload (t);
1672 /* When a function is declared with an initializer,
1673 do the right thing. Currently, there are two possibilities:
1678 // initialization possibility #1.
1679 virtual void f () = 0;
1701 // initialization possibility #2
1708 copy_assignment_arg_p (parmtype, virtualp)
1712 if (current_class_type == NULL_TREE)
1715 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1716 parmtype = TREE_TYPE (parmtype);
1718 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1720 /* Non-standard hack to support old Booch components. */
1721 || (! virtualp && DERIVED_FROM_P (parmtype, current_class_type))
1730 grok_function_init (decl, init)
1734 /* An initializer for a function tells how this function should
1736 tree type = TREE_TYPE (decl);
1738 if (TREE_CODE (type) == FUNCTION_TYPE)
1739 cp_error ("initializer specified for non-member function `%D'", decl);
1741 /* We'll check for this in finish_struct_1. */
1742 else if (DECL_VINDEX (decl) == NULL_TREE)
1743 cp_error ("initializer specified for non-virtual method `%D'", decl);
1745 else if (integer_zerop (init))
1748 /* Mark this function as being "defined". */
1749 DECL_INITIAL (decl) = error_mark_node;
1750 /* pure virtual destructors must be defined. */
1751 /* pure virtual needs to be defined (as abort) only when put in
1752 vtbl. For wellformed call, it should be itself. pr4737 */
1753 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1755 extern tree abort_fndecl;
1756 /* Give this node rtl from `abort'. */
1757 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1760 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1761 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1764 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1766 if (copy_assignment_arg_p (parmtype, 1))
1767 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1770 else if (TREE_CODE (init) == OFFSET_REF
1771 && TREE_OPERAND (init, 0) == NULL_TREE
1772 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1774 tree basetype = DECL_CLASS_CONTEXT (init);
1775 tree basefn = TREE_OPERAND (init, 1);
1776 if (TREE_CODE (basefn) != FUNCTION_DECL)
1777 cp_error ("non-method initializer invalid for method `%D'", decl);
1778 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1779 sorry ("base member function from other than first base class");
1782 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1783 if (binfo == error_mark_node)
1785 else if (binfo == 0)
1786 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1787 TYPE_METHOD_BASETYPE (type));
1790 /* Mark this function as being defined,
1791 and give it new rtl. */
1792 DECL_INITIAL (decl) = error_mark_node;
1793 DECL_RTL (decl) = DECL_RTL (basefn);
1798 cp_error ("invalid initializer for virtual method `%D'", decl);
1802 cplus_decl_attributes (decl, attributes, prefix_attributes)
1803 tree decl, attributes, prefix_attributes;
1805 if (decl == NULL_TREE || decl == void_type_node)
1808 if (TREE_CODE (decl) == TEMPLATE_DECL)
1809 decl = DECL_TEMPLATE_RESULT (decl);
1811 decl_attributes (decl, attributes, prefix_attributes);
1813 if (TREE_CODE (decl) == TYPE_DECL)
1814 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl));
1817 /* CONSTRUCTOR_NAME:
1818 Return the name for the constructor (or destructor) for the
1819 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1820 IDENTIFIER_NODE. When given a template, this routine doesn't
1821 lose the specialization. */
1824 constructor_name_full (thing)
1827 if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM)
1828 thing = TYPE_NAME (thing);
1829 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1831 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1832 thing = DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0));
1834 thing = TYPE_NAME (thing);
1836 if (TREE_CODE (thing) == TYPE_DECL
1837 || (TREE_CODE (thing) == TEMPLATE_DECL
1838 && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL))
1839 thing = DECL_NAME (thing);
1840 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1844 /* CONSTRUCTOR_NAME:
1845 Return the name for the constructor (or destructor) for the
1846 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1847 IDENTIFIER_NODE. When given a template, return the plain
1848 unspecialized name. */
1851 constructor_name (thing)
1855 thing = constructor_name_full (thing);
1856 t = IDENTIFIER_TEMPLATE (thing);
1862 /* Cache the value of this class's main virtual function table pointer
1863 in a register variable. This will save one indirection if a
1864 more than one virtual function call is made this function. */
1869 extern tree base_init_expr;
1871 if (base_init_expr == 0
1872 && DECL_CONSTRUCTOR_P (current_function_decl))
1874 if (processing_template_decl)
1875 add_tree (build_min_nt
1877 current_member_init_list, current_base_init_list));
1879 emit_base_init (current_class_type, 0);
1883 /* Record the existence of an addressable inline function. */
1886 mark_inline_for_output (decl)
1889 decl = DECL_MAIN_VARIANT (decl);
1890 if (DECL_SAVED_INLINE (decl))
1892 my_friendly_assert (TREE_PERMANENT (decl), 363);
1893 DECL_SAVED_INLINE (decl) = 1;
1895 if (DECL_PENDING_INLINE_INFO (decl) != 0
1896 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
1898 struct pending_inline *t = pending_inlines;
1899 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
1902 if (t == DECL_PENDING_INLINE_INFO (decl))
1908 t = DECL_PENDING_INLINE_INFO (decl);
1909 t->next = pending_inlines;
1910 pending_inlines = t;
1912 DECL_PENDING_INLINE_INFO (decl) = 0;
1915 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
1921 temp_name_counter = 0;
1924 /* Hand off a unique name which can be used for variable we don't really
1925 want to know about anyway, for example, the anonymous variables which
1926 are needed to make references work. Declare this thing so we can use it.
1927 The variable created will be of type TYPE.
1929 STATICP is nonzero if this variable should be static. */
1932 get_temp_name (type, staticp)
1936 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
1938 int toplev = toplevel_bindings_p ();
1940 push_obstacks_nochange ();
1941 if (toplev || staticp)
1943 end_temporary_allocation ();
1944 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
1945 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
1949 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
1950 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1952 TREE_USED (decl) = 1;
1953 TREE_STATIC (decl) = staticp;
1954 DECL_ARTIFICIAL (decl) = 1;
1956 /* If this is a local variable, then lay out its rtl now.
1957 Otherwise, callers of this function are responsible for dealing
1958 with this variable's rtl. */
1962 expand_decl_init (decl);
1969 /* Get a variable which we can use for multiple assignments.
1970 It is not entered into current_binding_level, because
1971 that breaks things when it comes time to do final cleanups
1972 (which take place "outside" the binding contour of the function). */
1975 get_temp_regvar (type, init)
1978 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
1981 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
1982 decl = build_decl (VAR_DECL, get_identifier (buf), type);
1983 TREE_USED (decl) = 1;
1984 DECL_REGISTER (decl) = 1;
1987 store_init_value (decl, init);
1989 /* We can expand these without fear, since they cannot need
1990 constructors or destructors. */
1992 expand_decl_init (decl);
1997 /* Finish off the processing of a UNION_TYPE structure.
1998 If there are static members, then all members are
1999 static, and must be laid out together. If the
2000 union is an anonymous union, we arrange for that
2001 as well. PUBLIC_P is nonzero if this union is
2002 not declared static. */
2005 finish_anon_union (anon_union_decl)
2006 tree anon_union_decl;
2008 tree type = TREE_TYPE (anon_union_decl);
2009 tree field, main_decl = NULL_TREE;
2010 tree elems = NULL_TREE;
2011 int public_p = TREE_PUBLIC (anon_union_decl);
2012 int static_p = TREE_STATIC (anon_union_decl);
2013 int external_p = DECL_EXTERNAL (anon_union_decl);
2015 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
2020 error ("global anonymous unions must be declared static");
2024 for (; field; field = TREE_CHAIN (field))
2027 if (TREE_CODE (field) != FIELD_DECL)
2030 if (TREE_PRIVATE (field))
2031 cp_pedwarn_at ("private member `%#D' in anonymous union", field);
2032 else if (TREE_PROTECTED (field))
2033 cp_pedwarn_at ("protected member `%#D' in anonymous union", field);
2035 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2036 /* tell `pushdecl' that this is not tentative. */
2037 DECL_INITIAL (decl) = error_mark_node;
2038 TREE_PUBLIC (decl) = public_p;
2039 TREE_STATIC (decl) = static_p;
2040 DECL_EXTERNAL (decl) = external_p;
2041 decl = pushdecl (decl);
2043 /* Only write out one anon union element--choose the one that
2044 can hold them all. */
2045 if (main_decl == NULL_TREE
2046 && 1 == simple_cst_equal (DECL_SIZE (decl),
2047 DECL_SIZE (anon_union_decl)))
2053 /* ??? This causes there to be no debug info written out
2055 TREE_ASM_WRITTEN (decl) = 1;
2058 DECL_INITIAL (decl) = NULL_TREE;
2059 /* If there's a cleanup to do, it belongs in the
2060 TREE_PURPOSE of the following TREE_LIST. */
2061 elems = tree_cons (NULL_TREE, decl, elems);
2062 TREE_TYPE (elems) = type;
2068 make_decl_rtl (main_decl, 0, toplevel_bindings_p ());
2069 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2073 warning ("anonymous union with no members");
2078 /* The following call assumes that there are never any cleanups
2079 for anonymous unions--a reasonable assumption. */
2080 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2083 /* Finish and output a table which is generated by the compiler.
2084 NAME is the name to give the table.
2085 TYPE is the type of the table entry.
2086 INIT is all the elements in the table.
2087 PUBLICP is non-zero if this table should be given external access. */
2090 finish_table (name, type, init, publicp)
2091 tree name, type, init;
2094 tree itype, atype, decl;
2095 static tree empty_table;
2099 itype = build_index_type (size_int (list_length (init) - 1));
2100 atype = build_cplus_array_type (type, itype);
2101 layout_type (atype);
2103 if (TREE_VALUE (init) == integer_zero_node
2104 && TREE_CHAIN (init) == NULL_TREE)
2107 if (empty_table == NULL_TREE)
2110 empty_table = get_temp_name (atype, 1);
2111 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2112 TREE_CONSTANT (init) = 1;
2113 TREE_STATIC (init) = 1;
2114 DECL_INITIAL (empty_table) = init;
2115 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2116 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2117 cp_finish_decl (empty_table, NULL_TREE, asmspec, 0, 0);
2122 if (name == NULL_TREE)
2126 decl = get_temp_name (atype, 1);
2130 decl = build_decl (VAR_DECL, name, atype);
2131 decl = pushdecl (decl);
2132 TREE_STATIC (decl) = 1;
2137 TREE_PUBLIC (decl) = publicp;
2138 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2139 TREE_CONSTANT (init) = 1;
2140 TREE_STATIC (init) = 1;
2141 DECL_INITIAL (decl) = init;
2142 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2143 IDENTIFIER_POINTER (DECL_NAME (decl)));
2147 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2148 DECL_EXTERNAL (decl) = 1;
2149 TREE_STATIC (decl) = 0;
2151 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2152 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2155 cp_finish_decl (decl, NULL_TREE, asmspec, 0, 0);
2159 /* Finish processing a builtin type TYPE. It's name is NAME,
2160 its fields are in the array FIELDS. LEN is the number of elements
2161 in FIELDS minus one, or put another way, it is the maximum subscript
2164 It is given the same alignment as ALIGN_TYPE. */
2167 finish_builtin_type (type, name, fields, len, align_type)
2176 TYPE_FIELDS (type) = fields[0];
2177 for (i = 0; i < len; i++)
2179 layout_type (TREE_TYPE (fields[i]));
2180 DECL_FIELD_CONTEXT (fields[i]) = type;
2181 TREE_CHAIN (fields[i]) = fields[i+1];
2183 DECL_FIELD_CONTEXT (fields[i]) = type;
2184 DECL_CLASS_CONTEXT (fields[i]) = type;
2185 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2187 #if 0 /* not yet, should get fixed properly later */
2188 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2190 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2192 TYPE_STUB_DECL (type) = TYPE_NAME (type);
2193 layout_decl (TYPE_NAME (type), 0);
2196 /* Auxiliary functions to make type signatures for
2197 `operator new' and `operator delete' correspond to
2198 what compiler will be expecting. */
2200 extern tree sizetype;
2203 coerce_new_type (type)
2208 if (TREE_CODE (type) == METHOD_TYPE)
2209 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2210 if (TREE_TYPE (type) != ptr_type_node)
2211 e1 = 1, error ("`operator new' must return type `void *'");
2213 /* Technically the type must be `size_t', but we may not know
2215 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2216 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2217 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2218 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2219 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2221 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2223 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2228 coerce_delete_type (type)
2231 int e1 = 0, e2 = 0, e3 = 0;
2232 tree arg_types = TYPE_ARG_TYPES (type);
2234 if (TREE_CODE (type) == METHOD_TYPE)
2236 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2237 arg_types = TREE_CHAIN (arg_types);
2240 if (TREE_TYPE (type) != void_type_node)
2241 e1 = 1, error ("`operator delete' must return type `void'");
2243 if (arg_types == NULL_TREE
2244 || TREE_VALUE (arg_types) != ptr_type_node)
2245 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2248 && TREE_CHAIN (arg_types)
2249 && TREE_CHAIN (arg_types) != void_list_node)
2251 /* Again, technically this argument must be `size_t', but again
2252 we may not know what that is. */
2253 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2254 if (TREE_CODE (t2) != INTEGER_TYPE
2255 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2256 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2257 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2260 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2261 error ("too many arguments in declaration of `operator delete'");
2263 error ("`...' invalid in specification of `operator delete'");
2268 arg_types = tree_cons (NULL_TREE, ptr_type_node,
2269 build_tree_list (NULL_TREE, sizetype));
2272 if (arg_types == NULL_TREE)
2273 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2275 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2280 type = build_function_type (void_type_node, arg_types);
2285 extern tree abort_fndecl;
2288 mark_vtable_entries (decl)
2291 tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
2295 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries))
2296 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2297 tree fn = TREE_OPERAND (fnaddr, 0);
2298 TREE_ADDRESSABLE (fn) = 1;
2301 skip_rtti_stuff (&entries);
2303 for (; entries; entries = TREE_CHAIN (entries))
2305 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries)
2306 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2307 tree fn = TREE_OPERAND (fnaddr, 0);
2308 TREE_ADDRESSABLE (fn) = 1;
2309 if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn))
2310 TREE_OPERAND (fnaddr, 0) = fn = abort_fndecl;
2311 if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn))
2313 DECL_EXTERNAL (fn) = 0;
2320 /* Set DECL up to have the closest approximation of "initialized common"
2321 linkage available. */
2324 comdat_linkage (decl)
2328 make_decl_one_only (decl);
2330 TREE_PUBLIC (decl) = 0;
2333 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2334 based on TYPE and other static flags.
2336 Note that anything public is tagged TREE_PUBLIC, whether
2337 it's public in this file or in another one. */
2340 import_export_vtable (decl, type, final)
2344 if (DECL_INTERFACE_KNOWN (decl))
2348 if (write_virtuals < 2 && write_virtuals != 0)
2350 TREE_PUBLIC (decl) = 1;
2351 if (write_virtuals < 0)
2352 DECL_EXTERNAL (decl) = 1;
2353 DECL_INTERFACE_KNOWN (decl) = 1;
2355 else if (CLASSTYPE_INTERFACE_KNOWN (type))
2357 TREE_PUBLIC (decl) = 1;
2358 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2359 DECL_INTERFACE_KNOWN (decl) = 1;
2363 /* We can only wait to decide if we have real non-inline virtual
2364 functions in our class, or if we come from a template. */
2366 int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2368 if (! found && ! final)
2371 for (method = TYPE_METHODS (type); method != NULL_TREE;
2372 method = TREE_CHAIN (method))
2373 if (DECL_VINDEX (method) != NULL_TREE
2374 && ! DECL_THIS_INLINE (method)
2375 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2382 if (final || ! found)
2384 comdat_linkage (decl);
2385 DECL_EXTERNAL (decl) = 0;
2389 TREE_PUBLIC (decl) = 1;
2390 DECL_EXTERNAL (decl) = 1;
2396 import_export_template (type)
2399 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2400 && ! flag_implicit_templates
2401 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2403 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2404 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2405 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2410 finish_prevtable_vardecl (prev, vars)
2413 tree ctype = DECL_CONTEXT (vars);
2414 import_export_template (ctype);
2416 #ifndef NO_LINKAGE_HEURISTICS
2417 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype)
2418 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2421 for (method = TYPE_METHODS (ctype); method != NULL_TREE;
2422 method = TREE_CHAIN (method))
2424 if (DECL_VINDEX (method) != NULL_TREE
2425 && !DECL_THIS_INLINE (method)
2426 && !DECL_ABSTRACT_VIRTUAL_P (method))
2428 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2429 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method);
2430 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2437 import_export_vtable (vars, ctype, 1);
2442 finish_vtable_vardecl (prev, vars)
2445 if (write_virtuals >= 0
2446 && ! DECL_EXTERNAL (vars)
2447 && ((TREE_PUBLIC (vars) && ! DECL_WEAK (vars) && ! DECL_ONE_ONLY (vars))
2448 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))
2449 || (hack_decl_function_context (vars) && TREE_USED (vars)))
2450 && ! TREE_ASM_WRITTEN (vars))
2453 mark_vtable_entries (vars);
2454 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2455 store_init_value (vars, DECL_INITIAL (vars));
2457 if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG)
2459 /* Mark the VAR_DECL node representing the vtable itself as a
2460 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2461 It is rather important that such things be ignored because
2462 any effort to actually generate DWARF for them will run
2463 into trouble when/if we encounter code like:
2466 struct S { virtual void member (); };
2468 because the artificial declaration of the vtable itself (as
2469 manufactured by the g++ front end) will say that the vtable
2470 is a static member of `S' but only *after* the debug output
2471 for the definition of `S' has already been output. This causes
2472 grief because the DWARF entry for the definition of the vtable
2473 will try to refer back to an earlier *declaration* of the
2474 vtable as a static member of `S' and there won't be one.
2475 We might be able to arrange to have the "vtable static member"
2476 attached to the member list for `S' before the debug info for
2477 `S' get written (which would solve the problem) but that would
2478 require more intrusive changes to the g++ front end. */
2480 DECL_IGNORED_P (vars) = 1;
2483 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2486 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2487 /* We don't know what to do with this one yet. */
2490 /* We know that PREV must be non-zero here. */
2491 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2496 prune_vtable_vardecl (prev, vars)
2499 /* We know that PREV must be non-zero here. */
2500 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2505 walk_vtables (typedecl_fn, vardecl_fn)
2506 register void (*typedecl_fn)();
2507 register int (*vardecl_fn)();
2512 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2514 register tree type = TREE_TYPE (vars);
2516 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2519 flag |= (*vardecl_fn) (prev, vars);
2521 if (prev && TREE_CHAIN (prev) != vars)
2524 else if (TREE_CODE (vars) == TYPE_DECL
2525 && type != error_mark_node
2526 && TYPE_LANG_SPECIFIC (type)
2527 && CLASSTYPE_VSIZE (type))
2529 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2539 finish_sigtable_vardecl (prev, vars)
2542 /* We don't need to mark sigtable entries as addressable here as is done
2543 for vtables. Since sigtables, unlike vtables, are always written out,
2544 that was already done in build_signature_table_constructor. */
2546 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2548 /* We know that PREV must be non-zero here. */
2549 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2553 walk_sigtables (typedecl_fn, vardecl_fn)
2554 register void (*typedecl_fn)();
2555 register void (*vardecl_fn)();
2559 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2561 register tree type = TREE_TYPE (vars);
2563 if (TREE_CODE (vars) == TYPE_DECL
2564 && type != error_mark_node
2565 && IS_SIGNATURE (type))
2567 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2569 else if (TREE_CODE (vars) == VAR_DECL
2570 && TREE_TYPE (vars) != error_mark_node
2571 && IS_SIGNATURE (TREE_TYPE (vars)))
2573 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2580 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2581 inline function or template instantiation at end-of-file. */
2584 import_export_decl (decl)
2587 if (DECL_INTERFACE_KNOWN (decl))
2590 if (DECL_TEMPLATE_INSTANTIATION (decl))
2592 DECL_NOT_REALLY_EXTERN (decl) = 1;
2593 if (DECL_IMPLICIT_INSTANTIATION (decl)
2594 && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2596 if (TREE_CODE (decl) == FUNCTION_DECL)
2597 comdat_linkage (decl);
2598 /* Dynamically initialized vars go into common. */
2599 else if (DECL_INITIAL (decl) == NULL_TREE
2600 || DECL_INITIAL (decl) == error_mark_node)
2601 DECL_COMMON (decl) = 1;
2602 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
2604 DECL_COMMON (decl) = 1;
2605 DECL_INITIAL (decl) = error_mark_node;
2609 /* Statically initialized vars are weak or comdat, if
2612 make_decl_one_only (decl);
2613 /* else leave vars public so multiple defs will break. */
2617 DECL_NOT_REALLY_EXTERN (decl) = 0;
2619 else if (DECL_FUNCTION_MEMBER_P (decl))
2621 tree ctype = DECL_CLASS_CONTEXT (decl);
2622 if (CLASSTYPE_INTERFACE_KNOWN (ctype) && ! DECL_ARTIFICIAL (decl))
2624 DECL_NOT_REALLY_EXTERN (decl)
2625 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2626 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2629 comdat_linkage (decl);
2631 /* tinfo function */
2632 else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2634 tree ctype = TREE_TYPE (DECL_NAME (decl));
2635 if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2636 && TYPE_VIRTUAL_P (ctype))
2638 DECL_NOT_REALLY_EXTERN (decl)
2639 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2640 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2642 else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2643 DECL_NOT_REALLY_EXTERN (decl) = 0;
2645 comdat_linkage (decl);
2647 else if (DECL_C_STATIC (decl))
2648 TREE_PUBLIC (decl) = 0;
2650 comdat_linkage (decl);
2652 DECL_INTERFACE_KNOWN (decl) = 1;
2656 build_cleanup (decl)
2660 tree type = TREE_TYPE (decl);
2662 if (TREE_CODE (type) == ARRAY_TYPE)
2666 mark_addressable (decl);
2667 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2669 temp = build_delete (TREE_TYPE (temp), temp,
2671 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2675 extern int parse_time, varconst_time;
2676 extern tree pending_templates;
2677 extern tree maybe_templates;
2679 extern struct obstack permanent_obstack;
2680 extern tree get_id_2 ();
2686 tree sname = get_id_2 ("__sn", base);
2687 tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2690 push_obstacks (&permanent_obstack, &permanent_obstack);
2691 sentry = build_decl (VAR_DECL, sname, integer_type_node);
2692 TREE_PUBLIC (sentry) = 1;
2693 DECL_ARTIFICIAL (sentry) = 1;
2694 TREE_STATIC (sentry) = 1;
2695 TREE_USED (sentry) = 1;
2696 DECL_COMMON (sentry) = 1;
2697 pushdecl_top_level (sentry);
2698 cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2704 /* This routine is called from the last rule in yyparse ().
2705 Its job is to create all the code needed to initialize and
2706 destroy the global aggregates. We do the destruction
2707 first, since that way we only need to reverse the decls once. */
2713 int start_time, this_time;
2717 int needs_cleaning = 0, needs_messing_up = 0;
2721 if (flag_detailed_statistics)
2722 dump_tree_statistics ();
2724 /* Bad parse errors. Just forget about it. */
2725 if (! global_bindings_p () || current_class_type)
2728 start_time = get_run_time ();
2730 /* Otherwise, GDB can get confused, because in only knows
2731 about source for LINENO-1 lines. */
2734 interface_unknown = 1;
2737 for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
2739 tree decl = TREE_VALUE (fnname);
2740 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
2742 instantiate_class_template (decl);
2743 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
2744 for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
2745 if (! DECL_ARTIFICIAL (vars))
2746 instantiate_decl (vars);
2749 instantiate_decl (decl);
2752 for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
2754 tree *args, fn, decl = TREE_VALUE (fnname);
2756 if (DECL_INITIAL (decl))
2759 fn = TREE_PURPOSE (fnname);
2760 args = get_bindings (fn, decl);
2761 fn = instantiate_template (fn, args);
2763 instantiate_decl (fn);
2766 /* Push into C language context, because that's all
2768 push_lang_context (lang_name_c);
2771 /* The reason for pushing garbage onto the global_binding_level is to
2772 ensure that we can slice out _DECLs which pertain to virtual function
2773 tables. If the last thing pushed onto the global_binding_level was a
2774 virtual function table, then slicing it out would slice away all the
2775 decls (i.e., we lose the head of the chain).
2777 There are several ways of getting the same effect, from changing the
2778 way that iterators over the chain treat the elements that pertain to
2779 virtual function tables, moving the implementation of this code to
2780 decl.c (where we can manipulate global_binding_level directly),
2781 popping the garbage after pushing it and slicing away the vtable
2782 stuff, or just leaving it alone. */
2784 /* Make last thing in global scope not be a virtual function table. */
2785 #if 0 /* not yet, should get fixed properly later */
2786 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2788 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2790 DECL_IGNORED_P (vars) = 1;
2791 SET_DECL_ARTIFICIAL (vars);
2795 /* Walk to mark the inline functions we need, then output them so
2796 that we can pick up any other tdecls that those routines need. */
2797 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2799 for (vars = pending_statics; vars; vars = TREE_CHAIN (vars))
2801 tree decl = TREE_VALUE (vars);
2803 if (DECL_TEMPLATE_INSTANTIATION (decl)
2804 && ! DECL_IN_AGGR_P (decl))
2806 import_export_decl (decl);
2807 DECL_EXTERNAL (decl) = ! DECL_NOT_REALLY_EXTERN (decl);
2811 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2812 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
2813 rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
2814 vars = static_aggregates;
2816 if (static_ctors || vars || exception_table_p ())
2817 needs_messing_up = 1;
2821 /* See if we really need the hassle. */
2822 while (vars && needs_cleaning == 0)
2824 tree decl = TREE_VALUE (vars);
2825 tree type = TREE_TYPE (decl);
2826 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars))
2832 vars = TREE_CHAIN (vars);
2835 if (needs_cleaning == 0)
2838 fnname = get_file_function_name ('D');
2839 start_function (void_list_node,
2840 make_call_declarator (fnname, void_list_node, NULL_TREE,
2843 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2844 store_parm_decls ();
2849 expand_start_bindings (0);
2851 /* These must be done in backward order to destroy,
2852 in which they happen to be! */
2853 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2855 tree decl = TREE_VALUE (vars);
2856 tree type = TREE_TYPE (decl);
2857 tree temp = TREE_PURPOSE (vars);
2859 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
2860 && ! DECL_EXTERNAL (decl))
2862 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2863 || DECL_ONE_ONLY (decl)
2864 || DECL_WEAK (decl)));
2866 temp = build_cleanup (decl);
2870 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2871 sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
2872 sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
2873 expand_start_cond (sentry, 0);
2876 expand_expr_stmt (temp);
2883 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2884 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2887 expand_end_bindings (getdecls (), 1, 0);
2891 finish_function (lineno, 0, 0);
2893 assemble_destructor (IDENTIFIER_POINTER (fnname));
2895 /* if it needed cleaning, then it will need messing up: drop through */
2898 /* Must do this while we think we are at the top level. */
2899 vars = nreverse (static_aggregates);
2900 if (needs_messing_up)
2902 fnname = get_file_function_name ('I');
2903 start_function (void_list_node,
2904 make_call_declarator (fnname, void_list_node, NULL_TREE,
2907 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2908 store_parm_decls ();
2913 expand_start_bindings (0);
2915 if (exception_table_p ())
2916 register_exception_table ();
2920 tree decl = TREE_VALUE (vars);
2921 tree init = TREE_PURPOSE (vars);
2923 /* If this was a static attribute within some function's scope,
2924 then don't initialize it here. Also, don't bother
2925 with initializers that contain errors. */
2926 if (TREE_STATIC (vars)
2927 || DECL_EXTERNAL (decl)
2928 || (init && TREE_CODE (init) == TREE_LIST
2929 && value_member (error_mark_node, init)))
2932 if (TREE_CODE (decl) == VAR_DECL)
2934 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2935 || DECL_ONE_ONLY (decl)
2936 || DECL_WEAK (decl)));
2938 /* Set these global variables so that GDB at least puts
2939 us near the declaration which required the initialization. */
2940 input_filename = DECL_SOURCE_FILE (decl);
2941 lineno = DECL_SOURCE_LINE (decl);
2942 emit_note (input_filename, lineno);
2944 /* 9.5p5: The initializer of a static member of a class has
2945 the same access rights as a member function. */
2946 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2947 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
2951 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2952 sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
2953 sentry = build_binary_op
2954 (EQ_EXPR, sentry, integer_one_node, 1);
2955 expand_start_cond (sentry, 0);
2958 expand_start_target_temps ();
2960 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2961 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2962 expand_aggr_init (decl, init, 0, 0);
2963 else if (TREE_CODE (init) == TREE_VEC)
2965 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2966 TREE_VEC_ELT (init, 1),
2967 TREE_VEC_ELT (init, 2), 0),
2968 const0_rtx, VOIDmode, 0);
2971 expand_assignment (decl, init, 0, 0);
2973 /* Cleanup any temporaries needed for the initial value. */
2974 expand_end_target_temps ();
2979 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2980 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
2982 else if (decl == error_mark_node)
2984 else my_friendly_abort (22);
2987 vars = TREE_CHAIN (vars);
2990 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
2991 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
2994 expand_end_bindings (getdecls (), 1, 0);
2998 finish_function (lineno, 0, 0);
2999 assemble_constructor (IDENTIFIER_POINTER (fnname));
3002 expand_builtin_throw ();
3004 permanent_allocation (1);
3006 /* Done with C language context needs. */
3007 pop_lang_context ();
3009 /* Now write out any static class variables (which may have since
3010 learned how to be initialized). */
3011 while (pending_statics)
3013 tree decl = TREE_VALUE (pending_statics);
3015 /* Output DWARF debug information. */
3016 #ifdef DWARF_DEBUGGING_INFO
3017 if (write_symbols == DWARF_DEBUG)
3018 dwarfout_file_scope_decl (decl, 1);
3020 #ifdef DWARF2_DEBUGGING_INFO
3021 if (write_symbols == DWARF2_DEBUG)
3022 dwarf2out_decl (decl);
3025 DECL_DEFER_OUTPUT (decl) = 0;
3026 rest_of_decl_compilation
3027 (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3029 pending_statics = TREE_CHAIN (pending_statics);
3032 this_time = get_run_time ();
3033 parse_time -= this_time - start_time;
3034 varconst_time += this_time - start_time;
3036 start_time = get_run_time ();
3038 if (flag_handle_signatures)
3039 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3041 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3043 tree decl = TREE_VALUE (fnname);
3044 import_export_decl (decl);
3047 /* Now write out inline functions which had their addresses taken and
3048 which were not declared virtual and which were not declared `extern
3051 int reconsider = 1; /* More may be referenced; check again */
3055 tree *p = &saved_inlines;
3058 /* We need to do this each time so that newly completed template
3059 types don't wind up at the front of the list. Sigh. */
3060 vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3061 DECL_IGNORED_P (vars) = 1;
3062 SET_DECL_ARTIFICIAL (vars);
3065 reconsider |= walk_vtables ((void (*)())0, finish_vtable_vardecl);
3069 tree decl = TREE_VALUE (*p);
3071 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3073 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3075 if (DECL_MUTABLE_P (decl))
3076 synthesize_tinfo_fn (decl);
3078 synthesize_method (decl);
3082 /* Catch new template instantiations. */
3083 if (decl != TREE_VALUE (*p))
3086 if (TREE_ASM_WRITTEN (decl)
3087 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3088 *p = TREE_CHAIN (*p);
3089 else if (DECL_INITIAL (decl) == 0)
3090 p = &TREE_CHAIN (*p);
3091 else if ((TREE_PUBLIC (decl) && ! DECL_WEAK (decl)
3092 && ! DECL_ONE_ONLY (decl))
3093 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3094 || flag_keep_inline_functions)
3096 if (DECL_NOT_REALLY_EXTERN (decl))
3098 DECL_EXTERNAL (decl) = 0;
3100 /* We can't inline this function after it's been
3101 emitted, so just disable inlining. We want a
3102 variant of output_inline_function that doesn't
3103 prevent subsequent integration... */
3105 temporary_allocation ();
3106 output_inline_function (decl);
3107 permanent_allocation (1);
3110 *p = TREE_CHAIN (*p);
3113 p = &TREE_CHAIN (*p);
3118 /* Now delete from the chain of variables all virtual function tables.
3119 We output them all ourselves, because each will be treated specially. */
3121 walk_vtables ((void (*)())0, prune_vtable_vardecl);
3123 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3125 if (TREE_CODE (vars) == FUNCTION_DECL
3126 && ! DECL_INTERFACE_KNOWN (vars)
3127 && DECL_C_STATIC (vars))
3128 TREE_PUBLIC (vars) = 0;
3131 if (write_virtuals == 2)
3133 /* Now complain about an virtual function tables promised
3134 but not delivered. */
3135 while (pending_vtables)
3137 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3138 error ("virtual function table for `%s' not defined",
3139 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3140 pending_vtables = TREE_CHAIN (pending_vtables);
3146 this_time = get_run_time ();
3147 parse_time -= this_time - start_time;
3148 varconst_time += this_time - start_time;
3150 if (flag_detailed_statistics)
3151 dump_time_statistics ();
3154 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3155 expr. Since it was parsed like a type, we need to wade through and fix
3156 that. Unfortunately, since operator() is left-associative, we can't use
3157 tail recursion. In the above example, TYPE is `A', and DECL is
3160 Maybe this shouldn't be recursive, but how often will it actually be
3164 reparse_absdcl_as_expr (type, decl)
3167 /* do build_functional_cast (type, NULL_TREE) at bottom */
3168 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3169 return build_functional_cast (type, NULL_TREE);
3172 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3174 decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3176 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3177 decl = require_complete_type (decl);
3182 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3183 out to be an expr. Since it was parsed like a type, we need to wade
3184 through and fix that. Since casts are right-associative, we are
3185 reversing the order, so we don't have to recurse.
3187 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3191 reparse_absdcl_as_casts (decl, expr)
3196 if (TREE_CODE (expr) == CONSTRUCTOR
3197 && TREE_TYPE (expr) == 0)
3199 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3200 decl = TREE_OPERAND (decl, 0);
3202 if (IS_SIGNATURE (type))
3204 error ("cast specifies signature type");
3205 return error_mark_node;
3208 expr = digest_init (type, expr, (tree *) 0);
3209 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3211 int failure = complete_array_type (type, expr, 1);
3213 my_friendly_abort (78);
3219 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3220 decl = TREE_OPERAND (decl, 0);
3221 expr = build_c_cast (type, expr);
3227 /* Given plain tree nodes for an expression, build up the full semantics. */
3230 build_expr_from_tree (t)
3233 if (t == NULL_TREE || t == error_mark_node)
3236 switch (TREE_CODE (t))
3238 case IDENTIFIER_NODE:
3239 return do_identifier (t, 0);
3242 if (LOOKUP_EXPR_GLOBAL (t))
3243 return do_scoped_id (TREE_OPERAND (t, 0), 0);
3245 return do_identifier (TREE_OPERAND (t, 0), 0);
3248 return build_x_indirect_ref
3249 (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3252 return build_functional_cast
3253 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3255 case REINTERPRET_CAST_EXPR:
3256 return build_reinterpret_cast
3257 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3259 case CONST_CAST_EXPR:
3260 return build_const_cast
3261 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3263 case DYNAMIC_CAST_EXPR:
3264 return build_dynamic_cast
3265 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3267 case STATIC_CAST_EXPR:
3268 return build_static_cast
3269 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3271 case PREDECREMENT_EXPR:
3272 case PREINCREMENT_EXPR:
3273 case POSTDECREMENT_EXPR:
3274 case POSTINCREMENT_EXPR:
3278 case TRUTH_NOT_EXPR:
3280 case CONVERT_EXPR: /* Unary + */
3283 return build_x_unary_op (TREE_CODE (t),
3284 build_expr_from_tree (TREE_OPERAND (t, 0)));
3289 case TRUNC_DIV_EXPR:
3291 case FLOOR_DIV_EXPR:
3292 case ROUND_DIV_EXPR:
3293 case EXACT_DIV_EXPR:
3295 case BIT_ANDTC_EXPR:
3298 case TRUNC_MOD_EXPR:
3299 case FLOOR_MOD_EXPR:
3300 case TRUTH_ANDIF_EXPR:
3301 case TRUTH_ORIF_EXPR:
3302 case TRUTH_AND_EXPR:
3317 return build_x_binary_op
3319 build_expr_from_tree (TREE_OPERAND (t, 0)),
3320 build_expr_from_tree (TREE_OPERAND (t, 1)));
3323 return build_m_component_ref
3324 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3325 build_expr_from_tree (TREE_OPERAND (t, 1)));
3328 return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3331 if (TREE_OPERAND (t, 0) == NULL_TREE)
3333 return build_parse_node (ARRAY_REF, NULL_TREE,
3334 build_expr_from_tree (TREE_OPERAND (t, 1)));
3335 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3336 build_expr_from_tree (TREE_OPERAND (t, 1)));
3340 tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3341 if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3343 return c_sizeof (r);
3347 return build_x_modify_expr
3348 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3349 TREE_CODE (TREE_OPERAND (t, 1)),
3350 build_expr_from_tree (TREE_OPERAND (t, 2)));
3353 return build_x_arrow
3354 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3358 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3359 build_expr_from_tree (TREE_OPERAND (t, 1)),
3360 build_expr_from_tree (TREE_OPERAND (t, 2)),
3361 NEW_EXPR_USE_GLOBAL (t));
3364 return delete_sanity
3365 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3366 build_expr_from_tree (TREE_OPERAND (t, 1)),
3367 DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3370 if (TREE_OPERAND (t, 1) == NULL_TREE)
3371 return build_x_compound_expr
3372 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3374 my_friendly_abort (42);
3376 case METHOD_CALL_EXPR:
3377 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3379 tree ref = TREE_OPERAND (t, 0);
3380 return build_scoped_method_call
3381 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3382 build_expr_from_tree (TREE_OPERAND (ref, 0)),
3383 TREE_OPERAND (ref, 1),
3384 build_expr_from_tree (TREE_OPERAND (t, 2)));
3386 return build_method_call
3387 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3388 TREE_OPERAND (t, 0),
3389 build_expr_from_tree (TREE_OPERAND (t, 2)),
3390 NULL_TREE, LOOKUP_NORMAL);
3393 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3395 tree ref = TREE_OPERAND (t, 0);
3396 return build_member_call
3397 (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3398 TREE_OPERAND (ref, 1),
3399 build_expr_from_tree (TREE_OPERAND (t, 1)));
3403 tree name = TREE_OPERAND (t, 0);
3404 if (! really_overloaded_fn (name))
3405 name = build_expr_from_tree (name);
3406 return build_x_function_call
3407 (name, build_expr_from_tree (TREE_OPERAND (t, 1)),
3412 return build_x_conditional_expr
3413 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3414 build_expr_from_tree (TREE_OPERAND (t, 1)),
3415 build_expr_from_tree (TREE_OPERAND (t, 2)));
3419 tree purpose, value, chain;
3421 if (t == void_list_node)
3424 purpose = TREE_PURPOSE (t);
3426 purpose = build_expr_from_tree (purpose);
3427 value = TREE_VALUE (t);
3429 value = build_expr_from_tree (value);
3430 chain = TREE_CHAIN (t);
3431 if (chain && chain != void_type_node)
3432 chain = build_expr_from_tree (chain);
3433 return tree_cons (purpose, value, chain);
3437 return build_x_component_ref
3438 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3439 TREE_OPERAND (t, 1), NULL_TREE, 1);
3442 return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3446 tree r = build_nt (CONSTRUCTOR, NULL_TREE,
3447 build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3450 return digest_init (TREE_TYPE (t), r, 0);
3455 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
3456 return get_typeid (TREE_OPERAND (t, 0));
3457 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3460 return convert_from_reference (t);
3467 /* This is something of the form `int (*a)++' that has turned out to be an
3468 expr. It was only converted into parse nodes, so we need to go through
3469 and build up the semantics. Most of the work is done by
3470 build_expr_from_tree, above.
3472 In the above example, TYPE is `int' and DECL is `*a'. */
3475 reparse_decl_as_expr (type, decl)
3478 decl = build_expr_from_tree (decl);
3480 return build_functional_cast (type, build_tree_list (NULL_TREE, decl));
3485 /* This is something of the form `int (*a)' that has turned out to be a
3486 decl. It was only converted into parse nodes, so we need to do the
3487 checking that make_{pointer,reference}_declarator do. */
3490 finish_decl_parsing (decl)
3493 extern int current_class_depth;
3495 switch (TREE_CODE (decl))
3497 case IDENTIFIER_NODE:
3500 return make_pointer_declarator
3501 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3503 return make_reference_declarator
3504 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3506 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3509 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3510 TREE_COMPLEXITY (decl) = current_class_depth;
3513 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3516 my_friendly_abort (5);
3522 check_cp_case_value (value)
3525 if (value == NULL_TREE)
3528 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3529 STRIP_TYPE_NOPS (value);
3531 if (TREE_READONLY_DECL_P (value))
3533 value = decl_constant_value (value);
3534 STRIP_TYPE_NOPS (value);
3536 value = fold (value);
3538 if (TREE_CODE (value) != INTEGER_CST
3539 && value != error_mark_node)
3541 cp_error ("case label `%E' does not reduce to an integer constant",
3543 value = error_mark_node;
3546 /* Promote char or short to int. */
3547 value = default_conversion (value);
3549 constant_expression_warning (value);
3554 tree current_namespace;
3556 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3557 postfix. Returns 0 if in global namespace. */
3562 tree x = current_namespace;
3564 x = TREE_PURPOSE (x);
3568 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3571 current_namespace_id (name)
3574 tree old_id = get_namespace_id ();
3577 /* Global names retain old encoding. */
3581 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3582 + IDENTIFIER_LENGTH (name));
3583 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3584 IDENTIFIER_POINTER (name));
3585 return get_identifier (buf);
3589 do_namespace_alias (alias, namespace)
3590 tree alias, namespace;
3592 sorry ("namespace alias");
3596 do_toplevel_using_decl (decl)
3599 if (decl == NULL_TREE || decl == error_mark_node)
3602 if (TREE_CODE (decl) == SCOPE_REF)
3603 decl = resolve_scope_to_name (NULL_TREE, decl);
3605 /* Is this the right way to do an id list? */
3606 if (TREE_CODE (decl) != TREE_LIST)
3613 pushdecl (TREE_VALUE (decl));
3614 decl = TREE_CHAIN (decl);
3619 do_class_using_decl (decl)
3624 if (TREE_CODE (decl) != SCOPE_REF)
3626 cp_error ("using-declaration for non-member at class scope");
3629 name = TREE_OPERAND (decl, 1);
3630 if (TREE_CODE (name) == BIT_NOT_EXPR)
3632 cp_error ("using-declaration for destructor");
3636 value = build_lang_field_decl (USING_DECL, name, void_type_node);
3637 DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
3642 do_using_directive (namespace)
3645 sorry ("using directive");
3649 check_default_args (x)
3652 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
3653 int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
3654 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
3656 if (TREE_PURPOSE (arg))
3660 cp_error ("default argument missing for parameter %P of `%#D'",
3671 TREE_USED (decl) = 1;
3672 if (processing_template_decl)
3674 assemble_external (decl);
3675 /* Is it a synthesized method that needs to be synthesized? */
3676 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
3677 && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3678 /* Kludge: don't synthesize for default args. */
3679 && current_function_decl)
3680 synthesize_method (decl);
3681 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
3682 instantiate_decl (decl);