1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
38 extern tree grokdeclarator ();
39 extern tree get_file_function_name ();
40 extern tree cleanups_this_call;
41 static void grok_function_init ();
43 /* A list of virtual function tables we must make sure to write out. */
46 /* A list of static class variables. This is needed, because a
47 static class variable can be declared inside the class without
48 an initializer, and then initialized, staticly, outside the class. */
51 /* A list of functions which were declared inline, but which we
52 may need to emit outline anyway. */
53 static tree saved_inlines;
55 /* Used to help generate temporary names which are unique within
56 a function. Reset to 0 by start_function. */
58 static int temp_name_counter;
60 /* Same, but not reset. Local temp variables and global temp variables
61 can have the same name. */
62 static int global_temp_name_counter;
64 /* Flag used when debugging spew.c */
66 extern int spew_debug;
68 /* C (and C++) language-specific option variables. */
70 /* Nonzero means allow type mismatches in conditional expressions;
71 just make their values `void'. */
73 int flag_cond_mismatch;
75 /* Nonzero means give `double' the same size as `float'. */
77 int flag_short_double;
79 /* Nonzero means don't recognize the keyword `asm'. */
83 /* Nonzero means don't recognize the non-ANSI builtin functions. */
87 /* Nonzero means do some things the same way PCC does. */
91 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
93 int flag_signed_bitfields = 1;
95 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
97 int flag_no_ident = 0;
99 /* Nonzero means disable GNU extensions. */
103 /* Nonzero means do emit exported implementations of functions even if
104 they can be inlined. */
106 int flag_implement_inlines = 1;
108 /* Nonzero means do emit exported implementations of templates, instead of
109 multiple static copies in each file that needs a definition. */
111 int flag_external_templates = 0;
113 /* Nonzero means that the decision to emit or not emit the implementation of a
114 template depends on where the template is instantiated, rather than where
117 int flag_alt_external_templates = 0;
119 /* Nonzero means warn about implicit declarations. */
121 int warn_implicit = 1;
123 /* Nonzero means warn when all ctors or dtors are private, and the class
126 int warn_ctor_dtor_privacy = 1;
128 /* True if we want to implement vtbvales using "thunks".
129 The default is off now, but will be on later.
131 Also causes output of vtables to be controlled by whether
132 we seen the class's first non-inline virtual function. */
133 int flag_vtable_thunks = 0;
135 /* Nonzero means give string constants the type `const char *'
136 to get extra warnings from them. These warnings will be too numerous
137 to be useful, except in thoroughly ANSIfied programs. */
139 int warn_write_strings;
141 /* Nonzero means warn about pointer casts that can drop a type qualifier
142 from the pointer target type. */
146 /* Nonzero means warn that dbx info for template class methods isn't fully
149 int warn_template_debugging;
151 /* Warn about traditional constructs whose meanings changed in ANSI C. */
153 int warn_traditional;
155 /* Nonzero means warn about sizeof(function) or addition/subtraction
156 of function pointers. */
158 int warn_pointer_arith;
160 /* Nonzero means warn for non-prototype function decls
161 or non-prototyped defs without previous prototype. */
163 int warn_strict_prototypes;
165 /* Nonzero means warn for any function def without prototype decl. */
167 int warn_missing_prototypes;
169 /* Nonzero means warn about multiple (redundant) decls for the same single
170 variable or function. */
172 int warn_redundant_decls;
174 /* Warn if initializer is not completely bracketed. */
176 int warn_missing_braces;
178 /* Warn about *printf or *scanf format/argument anomalies. */
182 /* Warn about a subscript that has type char. */
184 int warn_char_subscripts;
186 /* Warn if a type conversion is done that might have confusing results. */
190 /* Warn if adding () is suggested. */
192 int warn_parentheses = 1;
194 /* Non-zero means warn in function declared in derived class has the
195 same name as a virtual in the base class, but fails to match the
196 type signature of any virtual function in the base class. */
197 int warn_overloaded_virtual;
199 /* Non-zero means warn when declaring a class that has a non virtual
200 destructor, when it really ought to have a virtual one. */
201 int warn_nonvdtor = 1;
203 /* Non-zero means warn when a function is declared extern and later inline. */
204 int warn_extern_inline;
206 /* Nonzero means `$' can be in an identifier.
207 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
209 #ifndef DOLLARS_IN_IDENTIFIERS
210 #define DOLLARS_IN_IDENTIFIERS 1
212 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
214 /* Nonzero for -no-strict-prototype switch: do not consider empty
215 argument prototype to mean function takes no arguments. */
217 int strict_prototype = 1;
218 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
220 /* Nonzero means that labels can be used as first-class objects */
224 /* Non-zero means to collect statistics which might be expensive
225 and to print them when we are done. */
226 int flag_detailed_statistics;
228 /* C++ specific flags. */
229 /* Nonzero for -fall-virtual: make every member function (except
230 constructors) lay down in the virtual function table. Calls
231 can then either go through the virtual function table or not,
234 int flag_all_virtual;
236 /* Zero means that `this' is a *const. This gives nice behavior in the
237 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
238 -2 means we're constructing an object and it has fixed type. */
240 int flag_this_is_variable;
242 /* Nonzero means memoize our member lookups. */
244 int flag_memoize_lookups; int flag_save_memoized_contexts;
246 /* 3 means write out only virtuals function tables `defined'
247 in this implementation file.
248 2 means write out only specific virtual function tables
249 and give them (C) public access.
250 1 means write out virtual function tables and give them
252 0 means write out virtual function tables and give them
253 (C) static access (default).
254 -1 means declare virtual function tables extern. */
258 /* Nonzero means we should attempt to elide constructors when possible. */
260 int flag_elide_constructors;
262 /* Nonzero means recognize and handle exception handling constructs.
263 Use ansi syntax and semantics. WORK IN PROGRESS! */
265 int flag_handle_exceptions;
267 /* Nonzero means recognize and handle signature language constructs. */
269 int flag_handle_signatures;
271 /* Nonzero means that member functions defined in class scope are
272 inline by default. */
274 int flag_default_inline = 1;
276 /* Controls whether enums and ints freely convert.
277 1 means with complete freedom.
278 0 means enums can convert to ints, but not vice-versa. */
279 int flag_int_enum_equivalence;
281 /* Controls whether compiler is operating under LUCID's Cadillac
282 system. 1 means yes, 0 means no. */
285 /* Controls whether compiler generates code to build objects
286 that can be collected when they become garbage. */
289 /* Controls whether compiler generates 'dossiers' that give
290 run-time type information. */
293 /* Nonzero if we wish to output cross-referencing information
294 for the GNU class browser. */
295 extern int flag_gnu_xref;
297 /* Nonzero if compiler can make `reasonable' assumptions about
298 references and objects. For example, the compiler must be
299 conservative about the following and not assume that `a' is nonnull:
304 In general, it is `reasonable' to assume that for many programs,
305 and better code can be generated in that case. */
307 int flag_assume_nonnull_objects;
309 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
311 int flag_huge_objects;
313 /* Nonzero if we want to conserve space in the .o files. We do this
314 by putting uninitialized data and runtime initialized data into
315 .common instead of .data at the expense of not flaging multiple
317 int flag_conserve_space;
319 /* Table of language-dependent -f options.
320 STRING is the option name. VARIABLE is the address of the variable.
321 ON_VALUE is the value to store in VARIABLE
322 if `-fSTRING' is seen as an option.
323 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
325 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
327 {"signed-char", &flag_signed_char, 1},
328 {"unsigned-char", &flag_signed_char, 0},
329 {"signed-bitfields", &flag_signed_bitfields, 1},
330 {"unsigned-bitfields", &flag_signed_bitfields, 0},
331 {"short-enums", &flag_short_enums, 1},
332 {"short-double", &flag_short_double, 1},
333 {"cond-mismatch", &flag_cond_mismatch, 1},
334 {"asm", &flag_no_asm, 0},
335 {"builtin", &flag_no_builtin, 0},
336 {"ident", &flag_no_ident, 0},
337 {"labels-ok", &flag_labels_ok, 1},
338 {"stats", &flag_detailed_statistics, 1},
339 {"this-is-variable", &flag_this_is_variable, 1},
340 {"strict-prototype", &strict_prototypes_lang_cplusplus, 1},
341 {"all-virtual", &flag_all_virtual, 1},
342 {"memoize-lookups", &flag_memoize_lookups, 1},
343 {"elide-constructors", &flag_elide_constructors, 1},
344 {"handle-exceptions", &flag_handle_exceptions, 1},
345 {"handle-signatures", &flag_handle_signatures, 1},
346 {"default-inline", &flag_default_inline, 1},
347 {"dollars-in-identifiers", &dollars_in_ident, 1},
348 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
350 {"dossier", &flag_dossier, 1},
351 {"xref", &flag_gnu_xref, 1},
352 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
353 {"implement-inlines", &flag_implement_inlines, 1},
354 {"external-templates", &flag_external_templates, 1},
355 {"huge-objects", &flag_huge_objects, 1},
356 {"conserve-space", &flag_conserve_space, 1},
357 {"vtable-thunks", &flag_vtable_thunks, 1},
358 {"short-temps", &flag_short_temps, 1},
361 /* Decode the string P as a language-specific option.
362 Return 1 if it is recognized (and handle it);
363 return 0 if not recognized. */
366 lang_decode_option (p)
369 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
370 flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
371 flag_this_is_variable = 1;
372 /* The +e options are for cfront compatibility. They come in as
373 `-+eN', to kludge around gcc.c's argument handling. */
374 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
376 int old_write_virtuals = write_virtuals;
379 else if (p[3] == '0')
381 else if (p[3] == '2')
383 else error ("invalid +e option");
384 if (old_write_virtuals != 0
385 && write_virtuals != old_write_virtuals)
386 error ("conflicting +e options given");
388 else if (p[0] == '-' && p[1] == 'f')
390 /* Some kind of -f option.
391 P's value is the option sans `-f'.
392 Search for it in the table of options. */
396 /* Try special -f options. */
398 if (!strcmp (p, "save-memoized"))
400 flag_memoize_lookups = 1;
401 flag_save_memoized_contexts = 1;
404 if (!strcmp (p, "no-save-memoized"))
406 flag_memoize_lookups = 0;
407 flag_save_memoized_contexts = 0;
410 else if (! strncmp (p, "cadillac", 8))
412 flag_cadillac = atoi (p+9);
415 else if (! strncmp (p, "no-cadillac", 11))
420 else if (! strcmp (p, "gc"))
423 /* This must come along for the ride. */
427 else if (! strcmp (p, "no-gc"))
430 /* This must come along for the ride. */
434 else if (! strcmp (p, "alt-external-templates"))
436 flag_external_templates = 1;
437 flag_alt_external_templates = 1;
440 else if (! strcmp (p, "no-alt-external-templates"))
442 flag_alt_external_templates = 0;
446 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
449 if (!strcmp (p, lang_f_options[j].string))
451 *lang_f_options[j].variable = lang_f_options[j].on_value;
452 /* A goto here would be cleaner,
453 but breaks the vax pcc. */
456 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
457 && ! strcmp (p+3, lang_f_options[j].string))
459 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
465 else if (p[0] == '-' && p[1] == 'W')
469 /* The -W options control the warning behavior of the compiler. */
472 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
475 if (!strcmp (p, "implicit"))
476 warn_implicit = setting;
477 else if (!strcmp (p, "return-type"))
478 warn_return_type = setting;
479 else if (!strcmp (p, "ctor-dtor-privacy"))
480 warn_ctor_dtor_privacy = setting;
481 else if (!strcmp (p, "write-strings"))
482 warn_write_strings = setting;
483 else if (!strcmp (p, "cast-qual"))
484 warn_cast_qual = setting;
485 else if (!strcmp (p, "traditional"))
486 warn_traditional = setting;
487 else if (!strcmp (p, "char-subscripts"))
488 warn_char_subscripts = setting;
489 else if (!strcmp (p, "pointer-arith"))
490 warn_pointer_arith = setting;
491 else if (!strcmp (p, "strict-prototypes"))
492 warn_strict_prototypes = setting;
493 else if (!strcmp (p, "missing-prototypes"))
494 warn_missing_prototypes = setting;
495 else if (!strcmp (p, "redundant-decls"))
496 warn_redundant_decls = setting;
497 else if (!strcmp (p, "missing-braces"))
498 warn_missing_braces = setting;
499 else if (!strcmp (p, "format"))
500 warn_format = setting;
501 else if (!strcmp (p, "conversion"))
502 warn_conversion = setting;
503 else if (!strcmp (p, "parentheses"))
504 warn_parentheses = setting;
505 else if (!strcmp (p, "extern-inline"))
506 warn_extern_inline = setting;
507 else if (!strcmp (p, "comment"))
508 ; /* cpp handles this one. */
509 else if (!strcmp (p, "comments"))
510 ; /* cpp handles this one. */
511 else if (!strcmp (p, "trigraphs"))
512 ; /* cpp handles this one. */
513 else if (!strcmp (p, "import"))
514 ; /* cpp handles this one. */
515 else if (!strcmp (p, "all"))
517 extra_warnings = setting;
518 warn_return_type = setting;
519 warn_unused = setting;
520 warn_implicit = setting;
521 warn_ctor_dtor_privacy = setting;
522 warn_switch = setting;
523 warn_format = setting;
524 warn_missing_braces = setting;
525 warn_extern_inline = setting;
526 /* We save the value of warn_uninitialized, since if they put
527 -Wuninitialized on the command line, we need to generate a
528 warning about not using it without also specifying -O. */
529 if (warn_uninitialized != 1)
530 warn_uninitialized = (setting ? 2 : 0);
531 warn_template_debugging = setting;
534 else if (!strcmp (p, "overloaded-virtual"))
535 warn_overloaded_virtual = setting;
538 else if (!strcmp (p, "-ansi"))
539 flag_no_asm = 1, dollars_in_ident = 0, flag_ansi = 1;
541 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
542 it's probably safe to assume no sane person would ever want to use this
543 under normal circumstances. */
544 else if (!strcmp (p, "-spew-debug"))
553 /* Incorporate `const' and `volatile' qualifiers for member functions.
554 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
555 QUALS is a list of qualifiers. */
557 grok_method_quals (ctype, function, quals)
558 tree ctype, function, quals;
560 tree fntype = TREE_TYPE (function);
561 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
565 extern tree ridpointers[];
567 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
569 if (TYPE_READONLY (ctype))
570 error ("duplicate `%s' %s",
571 IDENTIFIER_POINTER (TREE_VALUE (quals)),
572 (TREE_CODE (function) == FUNCTION_DECL
573 ? "for member function" : "in type declaration"));
574 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
575 build_pointer_type (ctype);
577 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
579 if (TYPE_VOLATILE (ctype))
580 error ("duplicate `%s' %s",
581 IDENTIFIER_POINTER (TREE_VALUE (quals)),
582 (TREE_CODE (function) == FUNCTION_DECL
583 ? "for member function" : "in type declaration"));
584 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
585 build_pointer_type (ctype);
588 my_friendly_abort (20);
589 quals = TREE_CHAIN (quals);
592 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
593 (TREE_CODE (fntype) == METHOD_TYPE
594 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
595 : TYPE_ARG_TYPES (fntype)));
597 fntype = build_exception_variant (ctype, fntype, raises);
599 TREE_TYPE (function) = fntype;
603 #if 0 /* Not used. */
604 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
605 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
606 /* This does not yet work with user defined conversion operators
609 substitute_nice_name (decl)
612 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
614 char *n = decl_as_string (DECL_NAME (decl), 1);
615 if (n[strlen (n) - 1] == ' ')
616 n[strlen (n) - 1] = 0;
617 DECL_NAME (decl) = get_identifier (n);
622 /* Warn when -fexternal-templates is used and #pragma
623 interface/implementation is not used all the times it should be,
626 warn_if_unknown_interface ()
628 static int already_warned = 0;
629 if (++already_warned == 1)
630 warning ("templates that are built with -fexternal-templates should be in files that have #pragma interface/implementation");
633 /* A subroutine of the parser, to handle a component list. */
635 grok_x_components (specs, components)
636 tree specs, components;
638 register tree t, x, tcode;
640 /* We just got some friends. They have been recorded elsewhere. */
641 if (components == void_type_node)
644 if (components == NULL_TREE)
646 t = groktypename (build_decl_list (specs, NULL_TREE));
650 error ("error in component specification");
654 switch (TREE_CODE (t))
657 /* Static anonymous unions come out as VAR_DECLs. */
658 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
659 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
662 /* We return SPECS here, because in the parser it was ending
663 up with not doing anything to $$, which is what SPECS
669 /* This code may be needed for UNION_TYPEs as
671 tcode = record_type_node;
672 if (CLASSTYPE_DECLARED_CLASS(t))
673 tcode = class_type_node;
674 else if (IS_SIGNATURE(t))
675 tcode = signature_type_node;
676 else if (CLASSTYPE_DECLARED_EXCEPTION(t))
677 tcode = exception_type_node;
679 t = xref_defn_tag(tcode, TYPE_IDENTIFIER(t), NULL_TREE);
681 CLASSTYPE_NO_GLOBALIZE(t) = 1;
682 if (TYPE_LANG_SPECIFIC (t)
683 && CLASSTYPE_DECLARED_EXCEPTION (t))
690 if (TREE_CODE(t) == UNION_TYPE)
691 tcode = union_type_node;
693 tcode = enum_type_node;
695 t = xref_defn_tag(tcode, TYPE_IDENTIFIER(t), NULL_TREE);
696 if (TREE_CODE(t) == UNION_TYPE && TYPE_CONTEXT(t))
697 CLASSTYPE_NO_GLOBALIZE(t) = 1;
698 if (TREE_CODE (t) == UNION_TYPE
699 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
701 struct pending_inline **p;
702 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
704 /* Wipe out memory of synthesized methods */
705 TYPE_HAS_CONSTRUCTOR (t) = 0;
706 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
707 TYPE_HAS_INIT_REF (t) = 0;
708 TYPE_HAS_CONST_INIT_REF (t) = 0;
709 TYPE_HAS_ASSIGN_REF (t) = 0;
710 TYPE_HAS_ASSIGNMENT (t) = 0;
711 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
713 p = &pending_inlines;
714 for (; *p; *p = (*p)->next)
715 if (DECL_CONTEXT ((*p)->fndecl) != t)
718 else if (TREE_CODE (t) == ENUMERAL_TYPE)
719 x = grok_enum_decls (t, NULL_TREE);
726 if (t != void_type_node)
727 error ("empty component declaration");
733 t = TREE_TYPE (components);
734 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
735 return grok_enum_decls (t, components);
741 /* Classes overload their constituent function names automatically.
742 When a function name is declared in a record structure,
743 its name is changed to it overloaded name. Since names for
744 constructors and destructors can conflict, we place a leading
747 CNAME is the name of the class we are grokking for.
749 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
751 FLAGS contains bits saying what's special about today's
752 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
754 If FUNCTION is a destructor, then we must add the `auto-delete' field
755 as a second parameter. There is some hair associated with the fact
756 that we must "declare" this variable in the manner consistent with the
757 way the rest of the arguments were declared.
759 QUALS are the qualifiers for the this pointer. */
762 grokclassfn (ctype, cname, function, flags, quals)
763 tree ctype, cname, function;
764 enum overload_flags flags;
767 tree fn_name = DECL_NAME (function);
772 if (fn_name == NULL_TREE)
774 error ("name missing for member function");
775 fn_name = get_identifier ("<anonymous>");
776 DECL_NAME (function) = fn_name;
780 qualtype = grok_method_quals (ctype, function, quals);
784 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
785 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
787 /* Must add the class instance variable up front. */
788 /* Right now we just make this a pointer. But later
789 we may wish to make it special. */
790 tree type = TREE_VALUE (arg_types);
792 if ((flag_this_is_variable > 0)
793 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
794 type = TYPE_MAIN_VARIANT (type);
796 if (DECL_CONSTRUCTOR_P (function))
798 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
800 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
801 /* In this case we need "in-charge" flag saying whether
802 this constructor is responsible for initialization
803 of virtual baseclasses or not. */
804 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
805 /* Mark the artificial `__in_chrg' parameter as "artificial". */
806 SET_DECL_ARTIFICIAL (parm);
807 DECL_ARG_TYPE (parm) = integer_type_node;
808 DECL_REGISTER (parm) = 1;
809 TREE_CHAIN (parm) = last_function_parms;
810 last_function_parms = parm;
814 parm = build_decl (PARM_DECL, this_identifier, type);
815 /* Mark the artificial `this' parameter as "artificial". */
816 SET_DECL_ARTIFICIAL (parm);
817 DECL_ARG_TYPE (parm) = type;
818 /* We can make this a register, so long as we don't
819 accidentally complain if someone tries to take its address. */
820 DECL_REGISTER (parm) = 1;
821 if (TYPE_READONLY (type))
822 TREE_READONLY (parm) = 1;
823 TREE_CHAIN (parm) = last_function_parms;
824 last_function_parms = parm;
827 if (flags == DTOR_FLAG)
830 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
831 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
833 arg_types = hash_tree_chain (const_integer_type, void_list_node);
834 TREE_SIDE_EFFECTS (arg_types) = 1;
835 /* Build the overload name. It will look like `7Example'. */
836 if (IDENTIFIER_TYPE_VALUE (cname))
837 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
838 else if (IDENTIFIER_LOCAL_VALUE (cname))
839 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
841 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
842 it's defined out of the class definition, since poplevel_class wipes
843 it out. This used to be internal error 346. */
844 dbuf = build_overload_name (ctype, 1, 1);
845 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
846 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
849 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
850 parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
851 /* Mark the artificial `__in_chrg' parameter as "artificial". */
852 SET_DECL_ARTIFICIAL (parm);
853 TREE_USED (parm) = 1;
855 /* We don't need to mark the __in_chrg parameter itself as `const'
856 since its type is already `const int'. In fact we MUST NOT mark
857 it as `const' cuz that will screw up the debug info (causing it
858 to say that the type of __in_chrg is `const const int'). */
859 TREE_READONLY (parm) = 1;
861 DECL_ARG_TYPE (parm) = const_integer_type;
862 /* This is the same chain as DECL_ARGUMENTS (...). */
863 TREE_CHAIN (last_function_parms) = parm;
865 TREE_TYPE (function) = build_cplus_method_type (qualtype, void_type_node,
867 TYPE_HAS_DESTRUCTOR (ctype) = 1;
871 tree these_arg_types;
873 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
875 arg_types = hash_tree_chain (integer_type_node,
876 TREE_CHAIN (arg_types));
878 = build_cplus_method_type (qualtype,
879 TREE_TYPE (TREE_TYPE (function)),
881 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
884 these_arg_types = arg_types;
886 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
887 /* Only true for static member functions. */
888 these_arg_types = hash_tree_chain (TYPE_POINTER_TO (qualtype),
891 DECL_ASSEMBLER_NAME (function)
892 = build_decl_overload (fn_name, these_arg_types,
893 1 + DECL_CONSTRUCTOR_P (function));
896 /* This code is going into the compiler, but currently, it makes
897 libg++/src/Interger.cc not compile. The problem is that the nice name
898 winds up going into the symbol table, and conversion operations look
899 for the manged name. */
900 substitute_nice_name (function);
904 DECL_ARGUMENTS (function) = last_function_parms;
905 /* First approximations. */
906 DECL_CONTEXT (function) = ctype;
907 DECL_CLASS_CONTEXT (function) = ctype;
910 /* Work on the expr used by alignof (this is only called by the parser). */
918 if (TREE_CODE (expr) == COMPONENT_REF
919 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
920 error ("`__alignof__' applied to a bit-field");
922 if (TREE_CODE (expr) == INDIRECT_REF)
924 best = t = TREE_OPERAND (expr, 0);
925 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
927 while (TREE_CODE (t) == NOP_EXPR
928 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
931 t = TREE_OPERAND (t, 0);
932 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
933 if (thisalign > bestalign)
934 best = t, bestalign = thisalign;
936 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
940 /* ANSI says arrays and fns are converted inside comma.
941 But we can't convert them in build_compound_expr
942 because that would break commas in lvalues.
943 So do the conversion here if operand was a comma. */
944 if (TREE_CODE (expr) == COMPOUND_EXPR
945 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
946 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
947 expr = default_conversion (expr);
948 return c_alignof (TREE_TYPE (expr));
952 /* Create an ARRAY_REF, checking for the user doing things backwards
955 grok_array_decl (array_expr, index_exp)
956 tree array_expr, index_exp;
958 tree type = TREE_TYPE (array_expr);
960 if (type == error_mark_node || index_exp == error_mark_node)
961 return error_mark_node;
962 if (type == NULL_TREE)
964 /* Something has gone very wrong. Assume we are mistakenly reducing
965 an expression instead of a declaration. */
966 error ("parser may be lost: is there a '{' missing somewhere?");
970 if (TREE_CODE (type) == OFFSET_TYPE
971 || TREE_CODE (type) == REFERENCE_TYPE)
972 type = TREE_TYPE (type);
974 /* If they have an `operator[]', use that. */
975 if (TYPE_LANG_SPECIFIC (type)
976 && TYPE_OVERLOADS_ARRAY_REF (type))
977 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
978 array_expr, index_exp, NULL_TREE);
980 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
981 if (TREE_CODE (type) == POINTER_TYPE
982 || TREE_CODE (type) == ARRAY_TYPE)
983 return build_array_ref (array_expr, index_exp);
985 /* Woops, looks like they did something like `5[a]' instead of `a[5]'.
986 We don't emit a warning or error for this, since it's allowed
989 type = TREE_TYPE (index_exp);
991 if (TREE_CODE (type) == OFFSET_TYPE
992 || TREE_CODE (type) == REFERENCE_TYPE)
993 type = TREE_TYPE (type);
995 if (TYPE_LANG_SPECIFIC (type)
996 && TYPE_OVERLOADS_ARRAY_REF (type))
997 error ("array expression backwards");
998 else if (TREE_CODE (type) == POINTER_TYPE
999 || TREE_CODE (type) == ARRAY_TYPE)
1000 return build_array_ref (index_exp, array_expr);
1002 error("`[]' applied to non-pointer type");
1004 /* We gave an error, so give an error. Huh? */
1005 return error_mark_node;
1008 /* Given the cast expression EXP, checking out its validity. Either return
1009 an error_mark_node if there was an unavoidable error, return a cast to
1010 void for trying to delete a pointer w/ the value 0, or return the
1011 call to delete. If DOING_VEC is 1, we handle things differently
1012 for doing an array delete. If DOING_VEC is 2, they gave us the
1013 array size as an argument to delete.
1014 Implements ARM $5.3.4. This is called from the parser. */
1016 delete_sanity (exp, size, doing_vec, use_global_delete)
1018 int doing_vec, use_global_delete;
1020 tree t = stabilize_reference (convert_from_reference (exp));
1021 tree type = TREE_TYPE (t);
1022 enum tree_code code = TREE_CODE (type);
1023 /* For a regular vector delete (aka, no size argument) we will pass
1024 this down as a NULL_TREE into build_vec_delete. */
1025 tree maxindex = NULL_TREE;
1026 /* This is used for deleting arrays. */
1032 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1033 if (! flag_traditional)
1034 pedwarn ("anachronistic use of array size in vector delete");
1037 elt_size = c_sizeof (type);
1040 if (code != POINTER_TYPE)
1042 cp_error ("type `%#T' argument given to `delete', expected pointer",
1044 return error_mark_node;
1047 /* Deleting a pointer with the value zero is legal and has no effect. */
1048 if (integer_zerop (t))
1049 return build1 (NOP_EXPR, void_type_node, t);
1052 /* You can't delete a pointer to constant. */
1053 if (code == POINTER_TYPE && TREE_READONLY (TREE_TYPE (type)))
1055 error ("`const *' cannot be deleted");
1056 return error_mark_node;
1060 /* If the type has no destructor, then we should build a regular
1061 delete, instead of a vector delete. Otherwise, we would end
1062 up passing a bogus offset into __builtin_delete, which is
1063 not expecting it. */
1065 && TREE_CODE (type) == POINTER_TYPE
1066 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1069 use_global_delete = 1;
1074 return build_vec_delete (t, maxindex, elt_size, integer_one_node,
1075 integer_two_node, use_global_delete);
1077 return build_delete (type, t, integer_three_node,
1078 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
1082 /* Sanity check: report error if this function FUNCTION is not
1083 really a member of the class (CTYPE) it is supposed to belong to.
1084 CNAME is the same here as it is for grokclassfn above. */
1087 check_classfn (ctype, cname, function)
1088 tree ctype, cname, function;
1090 tree fn_name = DECL_NAME (function);
1092 tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
1096 if (method_vec != 0)
1098 methods = &TREE_VEC_ELT (method_vec, 0);
1099 end = TREE_VEC_END (method_vec);
1101 /* First suss out ctors and dtors. */
1102 if (*methods && fn_name == cname)
1105 while (++methods != end)
1107 if (fn_name == DECL_NAME (*methods))
1113 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1115 fndecl = DECL_CHAIN (fndecl);
1123 cp_error ("argument list for `%D' does not match any in class `%T'",
1128 cp_error ("no `%D' member function declared in class `%T'",
1132 /* If we did not find the method in the class, add it to
1133 avoid spurious errors. */
1134 add_method (ctype, methods, function);
1137 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1138 of a structure component, returning a FIELD_DECL node.
1139 QUALS is a list of type qualifiers for this decl (such as for declaring
1140 const member functions).
1142 This is done during the parsing of the struct declaration.
1143 The FIELD_DECL nodes are chained together and the lot of them
1144 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1148 If class A defines that certain functions in class B are friends, then
1149 the way I have set things up, it is B who is interested in permission
1150 granted by A. However, it is in A's context that these declarations
1151 are parsed. By returning a void_type_node, class A does not attempt
1152 to incorporate the declarations of the friends within its structure.
1154 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1155 CHANGES TO CODE IN `start_method'. */
1158 grokfield (declarator, declspecs, raises, init, asmspec_tree)
1159 tree declarator, declspecs, raises, init, asmspec_tree;
1161 register tree value;
1164 /* Convert () initializers to = initializers. */
1165 if (init == NULL_TREE && declarator != NULL_TREE
1166 && TREE_CODE (declarator) == CALL_EXPR
1167 && TREE_OPERAND (declarator, 0)
1168 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1169 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1170 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1172 init = TREE_OPERAND (declarator, 1);
1173 declarator = TREE_OPERAND (declarator, 0);
1177 && TREE_CODE (init) == TREE_LIST
1178 && TREE_VALUE (init) == error_mark_node
1179 && TREE_CHAIN (init) == NULL_TREE)
1182 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
1184 return NULL_TREE; /* friends went bad. */
1186 /* Pass friendly classes back. */
1187 if (TREE_CODE (value) == VOID_TYPE)
1188 return void_type_node;
1190 if (DECL_NAME (value) != NULL_TREE
1191 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1192 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1193 cp_error ("member `%D' conflicts with virtual function table field name", value);
1195 /* Stash away type declarations. */
1196 if (TREE_CODE (value) == TYPE_DECL)
1198 DECL_NONLOCAL (value) = 1;
1199 DECL_CONTEXT (value) = current_class_type;
1200 DECL_CLASS_CONTEXT (value) = current_class_type;
1201 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1202 pushdecl_class_level (value);
1206 if (IS_SIGNATURE (current_class_type)
1207 && TREE_CODE (value) != FUNCTION_DECL)
1209 error ("field declaration not allowed in signature");
1210 return void_type_node;
1213 if (DECL_IN_AGGR_P (value))
1215 cp_error ("`%D' is already defined in the class %T", value,
1216 DECL_CONTEXT (value));
1217 return void_type_node;
1221 cadillac_start_decl (value);
1224 asmspec = TREE_STRING_POINTER (asmspec_tree);
1228 if (IS_SIGNATURE (current_class_type)
1229 && TREE_CODE (value) == FUNCTION_DECL)
1231 error ("function declarations cannot have initializers in signature");
1234 else if (TREE_CODE (value) == FUNCTION_DECL)
1236 grok_function_init (value, init);
1242 /* Already warned in grokdeclarator. */
1243 if (DECL_NAME (value))
1244 pedwarn ("ANSI C++ forbids initialization of member `%s'",
1245 IDENTIFIER_POINTER (DECL_NAME (value)));
1247 pedwarn ("ANSI C++ forbids initialization of fields");
1253 /* We allow initializers to become parameters to base initializers. */
1254 if (TREE_CODE (init) == TREE_LIST)
1256 if (TREE_CHAIN (init) == NULL_TREE)
1257 init = TREE_VALUE (init);
1259 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1262 if (TREE_CODE (init) == CONST_DECL)
1263 init = DECL_INITIAL (init);
1264 else if (TREE_READONLY_DECL_P (init))
1265 init = decl_constant_value (init);
1266 else if (TREE_CODE (init) == CONSTRUCTOR)
1267 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1268 my_friendly_assert (TREE_PERMANENT (init), 192);
1269 if (init == error_mark_node)
1270 /* We must make this look different than `error_mark_node'
1271 because `decl_const_value' would mis-interpret it
1272 as only meaning that this VAR_DECL is defined. */
1273 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1274 else if (! TREE_CONSTANT (init))
1276 /* We can allow references to things that are effectively
1277 static, since references are initialized with the address. */
1278 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1279 || (TREE_STATIC (init) == 0
1280 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1281 || DECL_EXTERNAL (init) == 0)))
1283 error ("field initializer is not constant");
1284 init = error_mark_node;
1290 /* The corresponding pop_obstacks is in finish_decl. */
1291 push_obstacks_nochange ();
1293 if (TREE_CODE (value) == VAR_DECL)
1295 /* We cannot call pushdecl here, because that would
1296 fill in the value of our TREE_CHAIN. Instead, we
1297 modify finish_decl to do the right thing, namely, to
1298 put this decl out straight away. */
1299 if (TREE_STATIC (value))
1301 /* current_class_type can be NULL_TREE in case of error. */
1302 if (asmspec == 0 && current_class_type)
1307 buf2 = build_overload_name (current_class_type, 1, 1);
1308 buf = (char *)alloca (IDENTIFIER_LENGTH (DECL_NAME (value))
1309 + sizeof (STATIC_NAME_FORMAT)
1311 sprintf (buf, STATIC_NAME_FORMAT, buf2,
1312 IDENTIFIER_POINTER (DECL_NAME (value)));
1313 name = get_identifier (buf);
1314 TREE_PUBLIC (value) = 1;
1315 DECL_INITIAL (value) = error_mark_node;
1316 DECL_ASSEMBLER_NAME (value) = name;
1318 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1320 /* Static consts need not be initialized in the class definition. */
1321 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1323 static int explanation = 0;
1325 error ("initializer invalid for static member with constructor");
1326 if (explanation++ == 0)
1327 error ("(you really want to initialize it separately)");
1330 /* Force the compiler to know when an uninitialized static
1331 const member is being used. */
1332 if (TYPE_READONLY (value) && init == 0)
1333 TREE_USED (value) = 1;
1335 DECL_INITIAL (value) = init;
1336 DECL_IN_AGGR_P (value) = 1;
1338 finish_decl (value, init, asmspec_tree, 1);
1339 pushdecl_class_level (value);
1342 if (TREE_CODE (value) == FIELD_DECL)
1345 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1346 if (DECL_INITIAL (value) == error_mark_node)
1347 init = error_mark_node;
1348 finish_decl (value, init, asmspec_tree, 1);
1349 DECL_INITIAL (value) = init;
1350 DECL_IN_AGGR_P (value) = 1;
1353 if (TREE_CODE (value) == FUNCTION_DECL)
1355 /* grokdeclarator defers setting this. */
1356 TREE_PUBLIC (value) = 1;
1357 if (DECL_CHAIN (value) != NULL_TREE)
1359 /* Need a fresh node here so that we don't get circularity
1360 when we link these together. */
1361 value = copy_node (value);
1362 /* When does this happen? */
1363 my_friendly_assert (init == NULL_TREE, 193);
1365 finish_decl (value, init, asmspec_tree, 1);
1367 /* Pass friends back this way. */
1368 if (DECL_FRIEND_P (value))
1369 return void_type_node;
1371 if (current_function_decl)
1372 cp_error ("method `%#D' of local class must be defined in class body",
1375 DECL_IN_AGGR_P (value) = 1;
1378 my_friendly_abort (21);
1383 /* Like `grokfield', but for bitfields.
1384 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1387 grokbitfield (declarator, declspecs, width)
1388 tree declarator, declspecs, width;
1390 register tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL_TREE);
1392 if (! value) return NULL_TREE; /* friends went bad. */
1394 /* Pass friendly classes back. */
1395 if (TREE_CODE (value) == VOID_TYPE)
1396 return void_type_node;
1398 if (TREE_CODE (value) == TYPE_DECL)
1400 cp_error ("cannot declare `%D' to be a bitfield type", value);
1404 if (IS_SIGNATURE (current_class_type))
1406 error ("field declaration not allowed in signature");
1407 return void_type_node;
1410 if (DECL_IN_AGGR_P (value))
1412 cp_error ("`%D' is already defined in the class %T", value,
1413 DECL_CONTEXT (value));
1414 return void_type_node;
1417 GNU_xref_member (current_class_name, value);
1419 if (TREE_STATIC (value))
1421 cp_error ("static member `%D' cannot be a bitfield", value);
1424 finish_decl (value, NULL_TREE, NULL_TREE, 0);
1426 if (width != error_mark_node)
1428 /* detect invalid field size. */
1429 if (TREE_CODE (width) == CONST_DECL)
1430 width = DECL_INITIAL (width);
1431 else if (TREE_READONLY_DECL_P (width))
1432 width = decl_constant_value (width);
1433 if (TREE_CODE (width) != INTEGER_CST)
1435 cp_error ("structure field `%D' width not an integer constant",
1437 DECL_INITIAL (value) = NULL_TREE;
1441 constant_expression_warning (width);
1442 DECL_INITIAL (value) = width;
1443 DECL_BIT_FIELD (value) = 1;
1447 DECL_IN_AGGR_P (value) = 1;
1452 /* Like GROKFIELD, except that the declarator has been
1453 buried in DECLSPECS. Find the declarator, and
1454 return something that looks like it came from
1457 groktypefield (declspecs, parmlist)
1461 tree spec = declspecs;
1462 tree prev = NULL_TREE;
1464 tree type_id = NULL_TREE;
1465 tree quals = NULL_TREE;
1466 tree lengths = NULL_TREE;
1467 tree decl = NULL_TREE;
1471 register tree id = TREE_VALUE (spec);
1473 if (TREE_CODE (spec) != TREE_LIST)
1474 /* Certain parse errors slip through. For example,
1475 `int class ();' is not caught by the parser. Try
1476 weakly to recover here. */
1479 if (TREE_CODE (id) == TYPE_DECL
1480 || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
1482 /* We have a constructor/destructor or
1483 conversion operator. Use it. */
1485 TREE_CHAIN (prev) = TREE_CHAIN (spec);
1487 declspecs = TREE_CHAIN (spec);
1493 spec = TREE_CHAIN (spec);
1496 /* Nope, we have a conversion operator to a scalar type or something
1497 else, that includes things like constructor declarations for
1502 tree id = TREE_VALUE (spec);
1504 if (TREE_CODE (id) == IDENTIFIER_NODE)
1506 if (id == ridpointers[(int)RID_INT]
1507 || id == ridpointers[(int)RID_DOUBLE]
1508 || id == ridpointers[(int)RID_FLOAT]
1509 || id == ridpointers[(int)RID_WCHAR])
1512 error ("extra `%s' ignored",
1513 IDENTIFIER_POINTER (id));
1517 else if (id == ridpointers[(int)RID_LONG]
1518 || id == ridpointers[(int)RID_SHORT]
1519 || id == ridpointers[(int)RID_CHAR])
1521 lengths = tree_cons (NULL_TREE, id, lengths);
1523 else if (id == ridpointers[(int)RID_VOID])
1526 error ("spurious `void' type ignored");
1528 error ("conversion to `void' type invalid");
1530 else if (id == ridpointers[(int)RID_AUTO]
1531 || id == ridpointers[(int)RID_REGISTER]
1532 || id == ridpointers[(int)RID_TYPEDEF]
1533 || id == ridpointers[(int)RID_CONST]
1534 || id == ridpointers[(int)RID_VOLATILE])
1536 error ("type specifier `%s' used invalidly",
1537 IDENTIFIER_POINTER (id));
1539 else if (id == ridpointers[(int)RID_FRIEND]
1540 || id == ridpointers[(int)RID_VIRTUAL]
1541 || id == ridpointers[(int)RID_INLINE]
1542 || id == ridpointers[(int)RID_UNSIGNED]
1543 || id == ridpointers[(int)RID_SIGNED]
1544 || id == ridpointers[(int)RID_STATIC]
1545 || id == ridpointers[(int)RID_EXTERN])
1547 quals = tree_cons (NULL_TREE, id, quals);
1551 /* Happens when we have a global typedef
1552 and a class-local member function with
1558 else if (TREE_CODE (id) == RECORD_TYPE)
1560 type_id = TYPE_NAME (id);
1561 if (TREE_CODE (type_id) == TYPE_DECL)
1562 type_id = DECL_NAME (type_id);
1563 if (type_id == NULL_TREE)
1564 error ("identifier for aggregate type conversion omitted");
1566 else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't')
1567 error ("`operator' missing on conversion operator or tag missing from type");
1569 my_friendly_abort (194);
1570 spec = TREE_CHAIN (spec);
1574 declspecs = chainon (lengths, quals);
1577 if (TREE_CHAIN (lengths))
1578 error ("multiple length specifiers");
1579 type_id = ridpointers[(int)RID_INT];
1580 declspecs = chainon (lengths, quals);
1584 error ("no type given, defaulting to `operator int ...'");
1585 type_id = ridpointers[(int)RID_INT];
1592 decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
1593 declspecs, FIELD, 0, NULL_TREE);
1594 if (decl == NULL_TREE)
1597 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
1599 /* Need a fresh node here so that we don't get circularity
1600 when we link these together. */
1601 decl = copy_node (decl);
1604 if (decl == void_type_node
1605 || (TREE_CODE (decl) == FUNCTION_DECL
1606 && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
1607 /* bunch of friends. */
1610 if (DECL_IN_AGGR_P (decl))
1612 cp_error ("`%D' already defined in the class ", decl);
1613 return void_type_node;
1616 finish_decl (decl, NULL_TREE, NULL_TREE, 0);
1618 /* If this declaration is common to another declaration
1619 complain about such redundancy, and return NULL_TREE
1620 so that we don't build a circular list. */
1621 if (DECL_CHAIN (decl))
1623 cp_error ("function `%D' declared twice in class %T", decl,
1624 DECL_CONTEXT (decl));
1627 DECL_IN_AGGR_P (decl) = 1;
1633 grokoptypename (declspecs, declarator)
1634 tree declspecs, declarator;
1636 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1637 return build_typename_overload (t);
1640 /* When a function is declared with an initializer,
1641 do the right thing. Currently, there are two possibilities:
1646 // initialization possibility #1.
1647 virtual void f () = 0;
1669 // initialization possibility #2
1676 grok_function_init (decl, init)
1680 /* An initializer for a function tells how this function should
1682 tree type = TREE_TYPE (decl);
1684 if (TREE_CODE (type) == FUNCTION_TYPE)
1685 cp_error ("initializer specified for non-member function `%D'", decl);
1686 else if (DECL_VINDEX (decl) == NULL_TREE)
1687 cp_error ("initializer specified for non-virtual method `%D'", decl);
1688 else if (integer_zerop (init))
1691 /* Mark this function as being "defined". */
1692 DECL_INITIAL (decl) = error_mark_node;
1693 /* pure virtual destructors must be defined. */
1694 /* pure virtual needs to be defined (as abort) only when put in
1695 vtbl. For wellformed call, it should be itself. pr4737 */
1696 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1698 extern tree abort_fndecl;
1699 /* Give this node rtl from `abort'. */
1700 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1703 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1705 else if (TREE_CODE (init) == OFFSET_REF
1706 && TREE_OPERAND (init, 0) == NULL_TREE
1707 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1709 tree basetype = DECL_CLASS_CONTEXT (init);
1710 tree basefn = TREE_OPERAND (init, 1);
1711 if (TREE_CODE (basefn) != FUNCTION_DECL)
1712 cp_error ("non-method initializer invalid for method `%D'", decl);
1713 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1714 sorry ("base member function from other than first base class");
1717 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1718 if (binfo == error_mark_node)
1720 else if (binfo == 0)
1721 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1722 TYPE_METHOD_BASETYPE (type));
1725 /* Mark this function as being defined,
1726 and give it new rtl. */
1727 DECL_INITIAL (decl) = error_mark_node;
1728 DECL_RTL (decl) = DECL_RTL (basefn);
1733 cp_error ("invalid initializer for virtual method `%D'", decl);
1736 /* When we get a declaration of the form
1738 type cname::fname ...
1740 the node for `cname::fname' gets built here in a special way.
1741 Namely, we push into `cname's scope. When this declaration is
1742 processed, we pop back out. */
1744 build_push_scope (cname, name)
1748 extern int current_class_depth;
1752 if (cname == error_mark_node)
1753 return error_mark_node;
1755 ctype = IDENTIFIER_TYPE_VALUE (cname);
1757 if (TREE_CODE (ctype) == TEMPLATE_TYPE_PARM)
1759 else if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
1761 cp_error ("`%T' not defined as aggregate type", cname);
1764 else if (IS_SIGNATURE (ctype))
1766 error ("cannot push into signature scope, scope resolution operator ignored");
1770 rval = build_parse_node (SCOPE_REF, cname, name);
1772 /* Don't need to push the scope if we're already in it.
1773 We also don't need to push the scope for a ptr-to-member/method. */
1775 if (ctype == current_class_type || TREE_CODE (name) != IDENTIFIER_NODE
1779 /* We do need to push the scope in this case, since CTYPE helps
1780 determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;). */
1782 push_nested_class (ctype, 3);
1783 TREE_COMPLEXITY (rval) = current_class_depth;
1787 void cplus_decl_attributes (decl, attributes)
1788 tree decl, attributes;
1790 if (decl && decl != void_type_node)
1791 decl_attributes (decl, attributes);
1794 /* CONSTRUCTOR_NAME:
1795 Return the name for the constructor (or destructor) for the
1796 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1797 IDENTIFIER_NODE. When given a template, this routine doesn't
1798 lose the specialization. */
1800 constructor_name_full (thing)
1803 if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
1804 return DECL_NAME (UPT_TEMPLATE (thing));
1805 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1807 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1808 thing = DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing), 0));
1810 thing = TYPE_NAME (thing);
1812 if (TREE_CODE (thing) == TYPE_DECL
1813 || (TREE_CODE (thing) == TEMPLATE_DECL
1814 && DECL_TEMPLATE_IS_CLASS (thing)))
1815 thing = DECL_NAME (thing);
1816 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1820 /* CONSTRUCTOR_NAME:
1821 Return the name for the constructor (or destructor) for the
1822 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1823 IDENTIFIER_NODE. When given a template, return the plain
1824 unspecialized name. */
1826 constructor_name (thing)
1830 thing = constructor_name_full (thing);
1831 t = IDENTIFIER_TEMPLATE (thing);
1834 t = TREE_PURPOSE (t);
1835 return DECL_NAME (t);
1838 /* Cache the value of this class's main virtual function table pointer
1839 in a register variable. This will save one indirection if a
1840 more than one virtual function call is made this function. */
1844 extern rtx base_init_insns;
1846 if (base_init_insns == 0
1847 && DECL_CONSTRUCTOR_P (current_function_decl))
1848 emit_base_init (current_class_type, 0);
1851 /* This has something a little wrong with it.
1853 On a sun4, code like:
1858 is generated, when the below is used when -O4 is given. The delay
1859 slot it filled with an instruction that is safe, when this isn't
1869 virtual void print() { printf("xxx"); }
1881 And that is why this is disabled for now. (mrs)
1884 if ((flag_this_is_variable & 1) == 0
1886 && current_class_type
1887 && CLASSTYPE_VSIZE (current_class_type)
1888 && ! DECL_STATIC_FUNCTION_P (current_function_decl))
1890 tree vfield = build_vfield_ref (C_C_D, current_class_type);
1891 current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
1892 DECL_RTL (current_vtable_decl) = 0;
1893 DECL_INITIAL (current_vtable_decl) = error_mark_node;
1894 /* Have to cast the initializer, since it may have come from a
1895 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
1896 finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield), 0, 0);
1897 current_vtable_decl = build_indirect_ref (current_vtable_decl, NULL_PTR);
1901 current_vtable_decl = NULL_TREE;
1904 /* Record the existence of an addressable inline function. */
1906 mark_inline_for_output (decl)
1909 if (DECL_SAVED_INLINE (decl))
1911 DECL_SAVED_INLINE (decl) = 1;
1912 if (DECL_PENDING_INLINE_INFO (decl) != 0
1913 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
1915 struct pending_inline *t = pending_inlines;
1916 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
1919 if (t == DECL_PENDING_INLINE_INFO (decl))
1925 t = DECL_PENDING_INLINE_INFO (decl);
1926 t->next = pending_inlines;
1927 pending_inlines = t;
1929 DECL_PENDING_INLINE_INFO (decl) = 0;
1931 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
1937 temp_name_counter = 0;
1940 /* Hand off a unique name which can be used for variable we don't really
1941 want to know about anyway, for example, the anonymous variables which
1942 are needed to make references work. Declare this thing so we can use it.
1943 The variable created will be of type TYPE.
1945 STATICP is nonzero if this variable should be static. */
1948 get_temp_name (type, staticp)
1952 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
1954 int toplev = global_bindings_p ();
1956 push_obstacks_nochange ();
1957 if (toplev || staticp)
1959 end_temporary_allocation ();
1960 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
1961 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
1965 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
1966 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1968 TREE_USED (decl) = 1;
1969 TREE_STATIC (decl) = staticp;
1971 /* If this is a local variable, then lay out its rtl now.
1972 Otherwise, callers of this function are responsible for dealing
1973 with this variable's rtl. */
1977 expand_decl_init (decl);
1984 /* Get a variable which we can use for multiple assignments.
1985 It is not entered into current_binding_level, because
1986 that breaks things when it comes time to do final cleanups
1987 (which take place "outside" the binding contour of the function). */
1989 get_temp_regvar (type, init)
1992 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
1995 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
1996 decl = build_decl (VAR_DECL, get_identifier (buf), type);
1997 TREE_USED (decl) = 1;
1998 DECL_REGISTER (decl) = 1;
2001 store_init_value (decl, init);
2003 /* We can expand these without fear, since they cannot need
2004 constructors or destructors. */
2006 expand_decl_init (decl);
2008 if (type_needs_gc_entry (type))
2009 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
2014 /* Make the macro TEMP_NAME_P available to units which do not
2015 include c-tree.h. */
2020 return TEMP_NAME_P (decl);
2023 /* Finish off the processing of a UNION_TYPE structure.
2024 If there are static members, then all members are
2025 static, and must be laid out together. If the
2026 union is an anonymous union, we arrange for that
2027 as well. PUBLIC_P is nonzero if this union is
2028 not declared static. */
2030 finish_anon_union (anon_union_decl)
2031 tree anon_union_decl;
2033 tree type = TREE_TYPE (anon_union_decl);
2034 tree field, main_decl = NULL_TREE;
2035 tree elems = NULL_TREE;
2036 int public_p = TREE_PUBLIC (anon_union_decl);
2037 int static_p = TREE_STATIC (anon_union_decl);
2038 int external_p = DECL_EXTERNAL (anon_union_decl);
2040 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
2045 error ("global anonymous unions must be declared static");
2051 tree decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2052 /* tell `pushdecl' that this is not tentative. */
2053 DECL_INITIAL (decl) = error_mark_node;
2054 TREE_PUBLIC (decl) = public_p;
2055 TREE_STATIC (decl) = static_p;
2056 DECL_EXTERNAL (decl) = external_p;
2057 decl = pushdecl (decl);
2059 /* Only write out one anon union element--choose the one that
2060 can hold them all. */
2061 if (main_decl == NULL_TREE
2062 && simple_cst_equal (DECL_SIZE (decl), DECL_SIZE (anon_union_decl)))
2068 /* ??? This causes there to be no debug info written out
2070 TREE_ASM_WRITTEN (decl) = 1;
2073 DECL_INITIAL (decl) = NULL_TREE;
2074 /* If there's a cleanup to do, it belongs in the
2075 TREE_PURPOSE of the following TREE_LIST. */
2076 elems = tree_cons (NULL_TREE, decl, elems);
2077 TREE_TYPE (elems) = type;
2078 field = TREE_CHAIN (field);
2082 make_decl_rtl (main_decl, 0, global_bindings_p ());
2083 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2086 /* The following call assumes that there are never any cleanups
2087 for anonymous unions--a reasonable assumption. */
2088 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2091 cadillac_finish_anon_union (anon_union_decl);
2094 /* Finish and output a table which is generated by the compiler.
2095 NAME is the name to give the table.
2096 TYPE is the type of the table entry.
2097 INIT is all the elements in the table.
2098 PUBLICP is non-zero if this table should be given external access. */
2100 finish_table (name, type, init, publicp)
2101 tree name, type, init;
2104 tree itype, atype, decl;
2105 static tree empty_table;
2109 itype = build_index_type (size_int (list_length (init) - 1));
2110 atype = build_cplus_array_type (type, itype);
2111 layout_type (atype);
2113 if (TREE_VALUE (init) == integer_zero_node
2114 && TREE_CHAIN (init) == NULL_TREE)
2116 if (empty_table == NULL_TREE)
2118 empty_table = get_temp_name (atype, 1);
2119 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2120 TREE_CONSTANT (init) = 1;
2121 TREE_STATIC (init) = 1;
2122 DECL_INITIAL (empty_table) = init;
2123 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2124 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2125 finish_decl (empty_table, init, asmspec, 0);
2130 if (name == NULL_TREE)
2134 decl = get_temp_name (atype, 1);
2138 decl = build_decl (VAR_DECL, name, atype);
2139 decl = pushdecl (decl);
2140 TREE_STATIC (decl) = 1;
2145 TREE_PUBLIC (decl) = publicp;
2146 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2147 TREE_CONSTANT (init) = 1;
2148 TREE_STATIC (init) = 1;
2149 DECL_INITIAL (decl) = init;
2150 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2151 IDENTIFIER_POINTER (DECL_NAME (decl)));
2155 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2156 DECL_EXTERNAL (decl) = 1;
2157 TREE_STATIC (decl) = 0;
2159 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2160 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2163 finish_decl (decl, init, asmspec, 0);
2167 /* Finish processing a builtin type TYPE. It's name is NAME,
2168 its fields are in the array FIELDS. LEN is the number of elements
2169 in FIELDS minus one, or put another way, it is the maximum subscript
2172 It is given the same alignment as ALIGN_TYPE. */
2174 finish_builtin_type (type, name, fields, len, align_type)
2183 TYPE_FIELDS (type) = fields[0];
2184 for (i = 0; i < len; i++)
2186 layout_type (TREE_TYPE (fields[i]));
2187 DECL_FIELD_CONTEXT (fields[i]) = type;
2188 TREE_CHAIN (fields[i]) = fields[i+1];
2190 DECL_FIELD_CONTEXT (fields[i]) = type;
2191 DECL_CLASS_CONTEXT (fields[i]) = type;
2192 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2194 #if 0 /* not yet, should get fixed properly later */
2195 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2197 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2199 layout_decl (TYPE_NAME (type), 0);
2202 /* Auxiliary functions to make type signatures for
2203 `operator new' and `operator delete' correspond to
2204 what compiler will be expecting. */
2206 extern tree sizetype;
2209 coerce_new_type (type)
2214 if (TREE_CODE (type) == METHOD_TYPE)
2215 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2216 if (TREE_TYPE (type) != ptr_type_node)
2217 e1 = 1, error ("`operator new' must return type `void *'");
2219 /* Technically the type must be `size_t', but we may not know
2221 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2222 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2223 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2224 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2225 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2227 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2229 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2234 coerce_delete_type (type)
2237 int e1 = 0, e2 = 0, e3 = 0;
2238 tree arg_types = TYPE_ARG_TYPES (type);
2240 if (TREE_CODE (type) == METHOD_TYPE)
2242 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2243 arg_types = TREE_CHAIN (arg_types);
2245 if (TREE_TYPE (type) != void_type_node)
2246 e1 = 1, error ("`operator delete' must return type `void'");
2247 if (arg_types == NULL_TREE
2248 || TREE_VALUE (arg_types) != ptr_type_node)
2249 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2252 && TREE_CHAIN (arg_types)
2253 && TREE_CHAIN (arg_types) != void_list_node)
2255 /* Again, technically this argument must be `size_t', but again
2256 we may not know what that is. */
2257 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2258 if (TREE_CODE (t2) != INTEGER_TYPE
2259 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2260 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2261 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2264 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2265 error ("too many arguments in declaration of `operator delete'");
2267 error ("`...' invalid in specification of `operator delete'");
2271 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
2274 if (arg_types == NULL_TREE)
2275 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2277 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2282 type = build_function_type (void_type_node, arg_types);
2288 mark_vtable_entries (decl)
2291 tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
2294 entries = TREE_CHAIN (entries);
2296 for (; entries; entries = TREE_CHAIN (entries))
2298 tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
2299 tree fn = TREE_OPERAND (fnaddr, 0);
2300 TREE_ADDRESSABLE (fn) = 1;
2301 if (DECL_ABSTRACT_VIRTUAL_P (fn))
2303 extern tree abort_fndecl;
2304 TREE_OPERAND (fnaddr, 0) = abort_fndecl;
2309 /* Set TREE_PUBLIC and/or TREE_EXTERN on the vtable DECL,
2310 based on TYPE and other static flags.
2312 Note that anything public is tagged TREE_PUBLIC, whether
2313 it's public in this file or in another one. */
2316 import_export_vtable (decl, type)
2319 if (write_virtuals >= 2)
2321 if (CLASSTYPE_INTERFACE_KNOWN (type))
2323 TREE_PUBLIC (decl) = 1;
2324 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2327 else if (write_virtuals != 0)
2329 TREE_PUBLIC (decl) = 1;
2330 if (write_virtuals < 0)
2331 DECL_EXTERNAL (decl) = 1;
2336 finish_vtable_vardecl (prev, vars)
2339 tree ctype = DECL_CONTEXT (vars);
2340 import_export_vtable (vars, ctype);
2342 if (flag_vtable_thunks && !CLASSTYPE_INTERFACE_KNOWN (ctype))
2345 for (method = CLASSTYPE_METHODS (ctype); method != NULL_TREE;
2346 method = DECL_NEXT_METHOD (method))
2348 if (DECL_VINDEX (method) != NULL_TREE && !DECL_SAVED_INSNS (method))
2350 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2351 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2352 TREE_PUBLIC (vars) = 1;
2353 DECL_EXTERNAL (vars) = DECL_EXTERNAL (method);
2359 if (write_virtuals >= 0
2360 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
2362 extern tree the_null_vtable_entry;
2364 /* Stuff this virtual function table's size into
2365 `pfn' slot of `the_null_vtable_entry'. */
2366 tree nelts = array_type_nelts (TREE_TYPE (vars));
2367 if (flag_vtable_thunks)
2368 TREE_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))) = nelts;
2370 SET_FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry, nelts);
2371 /* Kick out the dossier before writing out the vtable. */
2373 rest_of_decl_compilation (TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))))), 0), 0, 1, 1);
2376 mark_vtable_entries (vars);
2377 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2378 store_init_value (vars, DECL_INITIAL (vars));
2379 if (flag_vtable_thunks)
2381 tree list = CONSTRUCTOR_ELTS (DECL_INITIAL (vars));
2382 for (; list; list = TREE_CHAIN (list))
2384 tree vfunc = TREE_VALUE (list);
2385 if (TREE_CODE (vfunc) == ADDR_EXPR)
2387 vfunc = TREE_OPERAND (vfunc, 0);
2388 if (TREE_CODE (vfunc) == THUNK_DECL)
2394 #ifdef DWARF_DEBUGGING_INFO
2395 if (write_symbols == DWARF_DEBUG)
2397 /* Mark the VAR_DECL node representing the vtable itself as a
2398 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2399 It is rather important that such things be ignored because
2400 any effort to actually generate DWARF for them will run
2401 into trouble when/if we encounter code like:
2404 struct S { virtual void member (); };
2406 because the artificial declaration of the vtable itself (as
2407 manufactured by the g++ front end) will say that the vtable
2408 is a static member of `S' but only *after* the debug output
2409 for the definition of `S' has already been output. This causes
2410 grief because the DWARF entry for the definition of the vtable
2411 will try to refer back to an earlier *declaration* of the
2412 vtable as a static member of `S' and there won't be one.
2413 We might be able to arrange to have the "vtable static member"
2414 attached to the member list for `S' before the debug info for
2415 `S' get written (which would solve the problem) but that would
2416 require more intrusive changes to the g++ front end. */
2418 DECL_IGNORED_P (vars) = 1;
2420 #endif /* DWARF_DEBUGGING_INFO */
2422 rest_of_decl_compilation (vars, 0, 1, 1);
2424 else if (TREE_USED (vars) && flag_vtable_thunks)
2425 assemble_external (vars);
2426 /* We know that PREV must be non-zero here. */
2427 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2431 walk_vtables (typedecl_fn, vardecl_fn)
2432 register void (*typedecl_fn)();
2433 register void (*vardecl_fn)();
2437 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2439 register tree type = TREE_TYPE (vars);
2441 if (TREE_CODE (vars) == TYPE_DECL
2442 && type != error_mark_node
2443 && TYPE_LANG_SPECIFIC (type)
2444 && CLASSTYPE_VSIZE (type))
2446 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2448 else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2450 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2457 extern int parse_time, varconst_time;
2459 #define TIMEVAR(VAR, BODY) \
2460 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2462 /* This routine is called from the last rule in yyparse ().
2463 Its job is to create all the code needed to initialize and
2464 destroy the global aggregates. We do the destruction
2465 first, since that way we only need to reverse the decls once. */
2471 int start_time, this_time;
2474 tree vars = static_aggregates;
2475 int needs_cleaning = 0, needs_messing_up = 0;
2477 build_exception_table ();
2479 if (flag_detailed_statistics)
2480 dump_tree_statistics ();
2482 /* Bad parse errors. Just forget about it. */
2483 if (! global_bindings_p () || current_class_type)
2486 start_time = get_run_time ();
2488 /* Push into C language context, because that's all
2490 push_lang_context (lang_name_c);
2492 /* Set up the name of the file-level functions we may need. */
2493 /* Use a global object (which is already required to be unique over
2494 the program) rather than the file name (which imposes extra
2495 constraints). -- Raeburn@MIT.EDU, 10 Jan 1990. */
2497 /* See if we really need the hassle. */
2498 while (vars && needs_cleaning == 0)
2500 tree decl = TREE_VALUE (vars);
2501 tree type = TREE_TYPE (decl);
2502 if (TYPE_NEEDS_DESTRUCTOR (type))
2505 needs_messing_up = 1;
2509 needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
2510 vars = TREE_CHAIN (vars);
2512 if (needs_cleaning == 0)
2515 /* Otherwise, GDB can get confused, because in only knows
2516 about source for LINENO-1 lines. */
2519 fnname = get_file_function_name ('D');
2520 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2521 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2522 store_parm_decls ();
2527 expand_start_bindings (0);
2529 /* These must be done in backward order to destroy,
2530 in which they happen to be! */
2533 tree decl = TREE_VALUE (vars);
2534 tree type = TREE_TYPE (decl);
2535 tree temp = TREE_PURPOSE (vars);
2537 if (TYPE_NEEDS_DESTRUCTOR (type))
2539 if (TREE_STATIC (vars))
2540 expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node, 1), 0);
2541 if (TREE_CODE (type) == ARRAY_TYPE)
2545 mark_addressable (decl);
2546 temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
2548 temp = build_delete (TREE_TYPE (temp), temp,
2549 integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2550 expand_expr_stmt (temp);
2552 if (TREE_STATIC (vars))
2555 vars = TREE_CHAIN (vars);
2558 expand_end_bindings (getdecls(), 1, 0);
2562 finish_function (lineno, 0);
2564 assemble_destructor (IDENTIFIER_POINTER (fnname));
2566 /* if it needed cleaning, then it will need messing up: drop through */
2569 /* Must do this while we think we are at the top level. */
2570 vars = nreverse (static_aggregates);
2571 if (vars != NULL_TREE)
2573 fnname = get_file_function_name ('I');
2574 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2575 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2576 store_parm_decls ();
2581 expand_start_bindings (0);
2585 tree decl = TREE_VALUE (vars);
2586 tree init = TREE_PURPOSE (vars);
2587 tree old_cleanups = cleanups_this_call;
2589 /* If this was a static attribute within some function's scope,
2590 then don't initialize it here. Also, don't bother
2591 with initializers that contain errors. */
2592 if (TREE_STATIC (vars)
2593 || (init && TREE_CODE (init) == TREE_LIST
2594 && value_member (error_mark_node, init)))
2596 vars = TREE_CHAIN (vars);
2600 if (TREE_CODE (decl) == VAR_DECL)
2602 /* Set these global variables so that GDB at least puts
2603 us near the declaration which required the initialization. */
2604 input_filename = DECL_SOURCE_FILE (decl);
2605 lineno = DECL_SOURCE_LINE (decl);
2606 emit_note (input_filename, lineno);
2608 /* 9.5p5: The initializer of a static member of a class has
2609 the same acess rights as a member function. */
2610 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2614 if (TREE_CODE (init) == VAR_DECL)
2616 /* This behavior results when there are
2617 multiple declarations of an aggregate,
2618 the last of which defines it. */
2619 if (DECL_RTL (init) == DECL_RTL (decl))
2621 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node
2622 || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
2623 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE),
2625 init = DECL_INITIAL (init);
2626 if (TREE_CODE (init) == CONSTRUCTOR
2627 && CONSTRUCTOR_ELTS (init) == NULL_TREE)
2631 else if (TREE_TYPE (decl) == TREE_TYPE (init))
2634 my_friendly_abort (200);
2636 /* point to real decl's rtl anyway. */
2637 DECL_RTL (init) = DECL_RTL (decl);
2638 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node,
2640 init = DECL_INITIAL (init);
2646 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2648 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2649 expand_aggr_init (decl, init, 0);
2650 else if (TREE_CODE (init) == TREE_VEC)
2652 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2653 TREE_VEC_ELT (init, 1),
2654 TREE_VEC_ELT (init, 2), 0),
2655 const0_rtx, VOIDmode, 0);
2659 expand_assignment (decl, init, 0, 0);
2661 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2663 else if (TREE_CODE (decl) == SAVE_EXPR)
2665 if (! PARM_DECL_EXPR (decl))
2667 /* a `new' expression at top level. */
2668 expand_expr (decl, const0_rtx, VOIDmode, 0);
2670 expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0);
2673 else if (decl == error_mark_node)
2675 else my_friendly_abort (22);
2676 vars = TREE_CHAIN (vars);
2677 /* Cleanup any temporaries needed for the initial value. */
2678 expand_cleanups_to (old_cleanups);
2681 expand_end_bindings (getdecls(), 1, 0);
2685 finish_function (lineno, 0);
2686 assemble_constructor (IDENTIFIER_POINTER (fnname));
2689 /* Done with C language context needs. */
2690 pop_lang_context ();
2692 /* Now write out any static class variables (which may have since
2693 learned how to be initialized). */
2694 while (pending_statics)
2696 tree decl = TREE_VALUE (pending_statics);
2697 if (TREE_USED (decl) == 1
2698 || TREE_READONLY (decl) == 0
2699 || DECL_INITIAL (decl) == 0)
2700 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
2701 pending_statics = TREE_CHAIN (pending_statics);
2704 this_time = get_run_time ();
2705 parse_time -= this_time - start_time;
2706 varconst_time += this_time - start_time;
2708 start_time = get_run_time ();
2710 /* Now delete from the chain of variables all virtual function tables.
2711 We output them all ourselves, because each will be treated specially. */
2714 /* The reason for pushing garbage onto the global_binding_level is to
2715 ensure that we can slice out _DECLs which pertain to virtual function
2716 tables. If the last thing pushed onto the global_binding_level was a
2717 virtual function table, then slicing it out would slice away all the
2718 decls (i.e., we lose the head of the chain).
2720 There are several ways of getting the same effect, from changing the
2721 way that iterators over the chain treat the elements that pertain to
2722 virtual function tables, moving the implementation of this code to
2723 decl.c (where we can manipulate global_binding_level directly),
2724 popping the garbage after pushing it and slicing away the vtable
2725 stuff, or just leaving it alone. */
2727 /* Make last thing in global scope not be a virtual function table. */
2728 #if 0 /* not yet, should get fixed properly later */
2729 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2731 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2733 DECL_IGNORED_P (vars) = 1;
2734 SET_DECL_ARTIFICIAL (vars);
2738 walk_vtables ((void (*)())0, finish_vtable_vardecl);
2740 /* Now write out inline functions which had their addresses taken
2741 and which were not declared virtual and which were not declared
2743 while (saved_inlines)
2745 tree decl = TREE_VALUE (saved_inlines);
2746 saved_inlines = TREE_CHAIN (saved_inlines);
2747 if (TREE_ASM_WRITTEN (decl))
2749 if (DECL_FUNCTION_MEMBER_P (decl) && !TREE_PUBLIC (decl))
2751 tree ctype = DECL_CLASS_CONTEXT (decl);
2752 if (CLASSTYPE_INTERFACE_KNOWN (ctype))
2754 TREE_PUBLIC (decl) = 1;
2755 DECL_EXTERNAL (decl) = CLASSTYPE_INTERFACE_ONLY (ctype);
2758 if (TREE_PUBLIC (decl) || TREE_ADDRESSABLE (decl))
2760 if (DECL_EXTERNAL (decl))
2761 assemble_external (decl);
2764 temporary_allocation ();
2765 output_inline_function (decl);
2766 permanent_allocation (1);
2771 if (write_virtuals == 2)
2773 /* Now complain about an virtual function tables promised
2774 but not delivered. */
2775 while (pending_vtables)
2777 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
2778 error ("virtual function table for `%s' not defined",
2779 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
2780 pending_vtables = TREE_CHAIN (pending_vtables);
2784 permanent_allocation (1);
2785 this_time = get_run_time ();
2786 parse_time -= this_time - start_time;
2787 varconst_time += this_time - start_time;
2789 if (flag_detailed_statistics)
2790 dump_time_statistics ();
2793 /* This is something of the form 'A()()()()()+1' that has turned out to be an
2794 expr. Since it was parsed like a type, we need to wade through and fix
2795 that. Unfortunately, since operator() is left-associative, we can't use
2796 tail recursion. In the above example, TYPE is `A', and DECL is
2799 Maybe this shouldn't be recursive, but how often will it actually be
2802 reparse_absdcl_as_expr (type, decl)
2805 /* do build_functional_cast (type, NULL_TREE) at bottom */
2806 if (TREE_OPERAND (decl, 0) == NULL_TREE)
2807 return build_functional_cast (type, NULL_TREE);
2810 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
2812 decl = build_x_function_call (decl, NULL_TREE, current_class_decl);
2814 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
2815 decl = require_complete_type (decl);
2820 /* This is something of the form `int ((int)(int)(int)1)' that has turned
2821 out to be an expr. Since it was parsed like a type, we need to wade
2822 through and fix that. Since casts are right-associative, we are
2823 reversing the order, so we don't have to recurse.
2825 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
2828 reparse_absdcl_as_casts (decl, expr)
2833 if (TREE_CODE (expr) == CONSTRUCTOR)
2835 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
2836 decl = TREE_OPERAND (decl, 0);
2838 if (IS_SIGNATURE (type))
2840 error ("cast specifies signature type");
2841 return error_mark_node;
2844 expr = digest_init (type, expr, (tree *) 0);
2845 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
2847 int failure = complete_array_type (type, expr, 1);
2849 my_friendly_abort (78);
2855 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
2856 decl = TREE_OPERAND (decl, 0);
2857 expr = build_c_cast (type, expr);
2863 /* Recursive helper function for reparse_decl_as_expr. It may be a good
2864 idea to reimplement this using an explicit stack, rather than recursion. */
2866 reparse_decl_as_expr1 (decl)
2869 switch (TREE_CODE (decl))
2871 case IDENTIFIER_NODE:
2872 return do_identifier (decl);
2874 return build_x_indirect_ref
2875 (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)), "unary *");
2877 return build_x_unary_op (ADDR_EXPR,
2878 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
2880 return build_x_unary_op (BIT_NOT_EXPR,
2881 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
2883 return build_offset_ref (TREE_OPERAND (decl, 0), TREE_OPERAND (decl, 1));
2885 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)),
2886 TREE_OPERAND (decl, 1));
2888 my_friendly_abort (5);
2893 /* This is something of the form `int (*a)++' that has turned out to be an
2894 expr. It was only converted into parse nodes, so we need to go through
2895 and build up the semantics. Most of the work is done by
2896 reparse_decl_as_expr1, above.
2898 In the above example, TYPE is `int' and DECL is `*a'. */
2900 reparse_decl_as_expr (type, decl)
2903 decl = build_tree_list (NULL_TREE, reparse_decl_as_expr1 (decl));
2904 return build_functional_cast (type, decl);
2907 /* This is something of the form `int (*a)' that has turned out to be a
2908 decl. It was only converted into parse nodes, so we need to do the
2909 checking that make_{pointer,reference}_declarator do. */
2912 finish_decl_parsing (decl)
2915 extern int current_class_depth;
2917 switch (TREE_CODE (decl))
2919 case IDENTIFIER_NODE:
2922 return make_pointer_declarator
2923 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
2925 return make_reference_declarator
2926 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
2928 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
2931 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
2932 TREE_COMPLEXITY (decl) = current_class_depth;
2935 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
2938 my_friendly_abort (5);
2944 check_cp_case_value (value)
2947 if (value == NULL_TREE)
2950 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
2951 Strip such NOP_EXPRs. */
2952 if (TREE_CODE (value) == NOP_EXPR
2953 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
2954 value = TREE_OPERAND (value, 0);
2956 if (TREE_READONLY_DECL_P (value))
2958 value = decl_constant_value (value);
2959 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
2960 Strip such NOP_EXPRs. */
2961 if (TREE_CODE (value) == NOP_EXPR
2962 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
2963 value = TREE_OPERAND (value, 0);
2965 value = fold (value);
2967 if (TREE_CODE (value) != INTEGER_CST
2968 && value != error_mark_node)
2970 cp_error ("case label `%E' does not reduce to an integer constant",
2972 value = error_mark_node;
2975 /* Promote char or short to int. */
2976 value = default_conversion (value);
2978 constant_expression_warning (value);