1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1995 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
38 extern tree grokdeclarator ();
39 extern tree get_file_function_name ();
40 extern tree cleanups_this_call;
41 static void grok_function_init ();
43 /* A list of virtual function tables we must make sure to write out. */
46 /* A list of static class variables. This is needed, because a
47 static class variable can be declared inside the class without
48 an initializer, and then initialized, staticly, outside the class. */
51 /* A list of functions which were declared inline, but which we
52 may need to emit outline anyway. */
53 static tree saved_inlines;
55 /* Used to help generate temporary names which are unique within
56 a function. Reset to 0 by start_function. */
58 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 /* Functions called along with real static constructors and destructors. */
70 tree static_ctors, static_dtors;
72 /* C (and C++) language-specific option variables. */
74 /* Nonzero means allow type mismatches in conditional expressions;
75 just make their values `void'. */
77 int flag_cond_mismatch;
79 /* Nonzero means give `double' the same size as `float'. */
81 int flag_short_double;
83 /* Nonzero means don't recognize the keyword `asm'. */
87 /* Nonzero means don't recognize any extension keywords. */
89 int flag_no_gnu_keywords;
91 /* Nonzero means don't recognize the non-ANSI builtin functions. */
95 /* Nonzero means don't recognize the non-ANSI builtin functions.
98 int flag_no_nonansi_builtin;
100 /* Nonzero means do some things the same way PCC does. */
102 int flag_traditional;
104 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
106 int flag_signed_bitfields = 1;
108 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
112 /* Nonzero means enable obscure ANSI features and disable GNU extensions
113 that might cause ANSI-compliant code to be miscompiled. */
117 /* Nonzero means do emit exported implementations of functions even if
118 they can be inlined. */
120 int flag_implement_inlines = 1;
122 /* Nonzero means do emit exported implementations of templates, instead of
123 multiple static copies in each file that needs a definition. */
125 int flag_external_templates;
127 /* Nonzero means that the decision to emit or not emit the implementation of a
128 template depends on where the template is instantiated, rather than where
131 int flag_alt_external_templates;
133 /* Nonzero means that implicit instantiations will be emitted if needed. */
135 int flag_implicit_templates = 1;
137 /* Nonzero means warn about implicit declarations. */
139 int warn_implicit = 1;
141 /* Nonzero means warn when all ctors or dtors are private, and the class
144 int warn_ctor_dtor_privacy = 1;
146 /* True if we want to implement vtbvales using "thunks".
147 The default is off now, but will be on later.
149 Also causes output of vtables to be controlled by whether
150 we seen the class's first non-inline virtual function. */
151 int flag_vtable_thunks;
153 /* Nonzero means give string constants the type `const char *'
154 to get extra warnings from them. These warnings will be too numerous
155 to be useful, except in thoroughly ANSIfied programs. */
157 int warn_write_strings;
159 /* Nonzero means warn about pointer casts that can drop a type qualifier
160 from the pointer target type. */
164 /* Nonzero means warn that dbx info for template class methods isn't fully
167 int warn_template_debugging;
169 /* Warn about traditional constructs whose meanings changed in ANSI C. */
171 int warn_traditional;
173 /* Nonzero means warn about sizeof(function) or addition/subtraction
174 of function pointers. */
176 int warn_pointer_arith;
178 /* Nonzero means warn for non-prototype function decls
179 or non-prototyped defs without previous prototype. */
181 int warn_strict_prototypes;
183 /* Nonzero means warn for any function def without prototype decl. */
185 int warn_missing_prototypes;
187 /* Nonzero means warn about multiple (redundant) decls for the same single
188 variable or function. */
190 int warn_redundant_decls;
192 /* Warn if initializer is not completely bracketed. */
194 int warn_missing_braces;
196 /* Warn about *printf or *scanf format/argument anomalies. */
200 /* Warn about a subscript that has type char. */
202 int warn_char_subscripts;
204 /* Warn if a type conversion is done that might have confusing results. */
208 /* Warn if adding () is suggested. */
210 int warn_parentheses;
212 /* Non-zero means warn in function declared in derived class has the
213 same name as a virtual in the base class, but fails to match the
214 type signature of any virtual function in the base class. */
215 int warn_overloaded_virtual;
217 /* Non-zero means warn when declaring a class that has a non virtual
218 destructor, when it really ought to have a virtual one. */
221 /* Non-zero means warn when a function is declared extern and later inline. */
222 int warn_extern_inline;
224 /* Non-zero means warn when the compiler will reorder code. */
227 /* Non-zero means warn when sysnthesis behavior differs from Cfront's. */
230 /* Nonzero means `$' can be in an identifier.
231 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
233 #ifndef DOLLARS_IN_IDENTIFIERS
234 #define DOLLARS_IN_IDENTIFIERS 1
236 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
238 /* Nonzero for -fno-strict-prototype switch: do not consider empty
239 argument prototype to mean function takes no arguments. */
241 int flag_strict_prototype = 2;
242 int strict_prototype = 1;
243 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
245 /* Nonzero means that labels can be used as first-class objects */
249 /* Non-zero means to collect statistics which might be expensive
250 and to print them when we are done. */
251 int flag_detailed_statistics;
253 /* C++ specific flags. */
254 /* Nonzero for -fall-virtual: make every member function (except
255 constructors) lay down in the virtual function table. Calls
256 can then either go through the virtual function table or not,
259 int flag_all_virtual;
261 /* Zero means that `this' is a *const. This gives nice behavior in the
262 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
263 -2 means we're constructing an object and it has fixed type. */
265 int flag_this_is_variable;
267 /* Nonzero means memoize our member lookups. */
269 int flag_memoize_lookups; int flag_save_memoized_contexts;
271 /* 3 means write out only virtuals function tables `defined'
272 in this implementation file.
273 2 means write out only specific virtual function tables
274 and give them (C) public access.
275 1 means write out virtual function tables and give them
277 0 means write out virtual function tables and give them
278 (C) static access (default).
279 -1 means declare virtual function tables extern. */
283 /* Nonzero means we should attempt to elide constructors when possible. */
285 int flag_elide_constructors;
287 /* Nonzero means recognize and handle exception handling constructs.
288 Use ansi syntax and semantics. WORK IN PROGRESS! */
290 int flag_handle_exceptions;
292 /* Nonzero means recognize and handle signature language constructs. */
294 int flag_handle_signatures;
296 /* Nonzero means that member functions defined in class scope are
297 inline by default. */
299 int flag_default_inline = 1;
301 /* Controls whether enums and ints freely convert.
302 1 means with complete freedom.
303 0 means enums can convert to ints, but not vice-versa. */
304 int flag_int_enum_equivalence;
306 /* Controls whether compiler is operating under LUCID's Cadillac
307 system. 1 means yes, 0 means no. */
310 /* Controls whether compiler generates code to build objects
311 that can be collected when they become garbage. */
314 /* Controls whether compiler generates 'type descriptor' that give
315 run-time type information. */
318 /* Nonzero if we wish to output cross-referencing information
319 for the GNU class browser. */
320 extern int flag_gnu_xref;
322 /* Nonzero if compiler can make `reasonable' assumptions about
323 references and objects. For example, the compiler must be
324 conservative about the following and not assume that `a' is nonnull:
329 In general, it is `reasonable' to assume that for many programs,
330 and better code can be generated in that case. */
332 int flag_assume_nonnull_objects = 1;
334 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
337 int flag_huge_objects;
339 /* Nonzero if we want to conserve space in the .o files. We do this
340 by putting uninitialized data and runtime initialized data into
341 .common instead of .data at the expense of not flaging multiple
344 int flag_conserve_space;
346 /* Nonzero if we want to obey access control semantics. */
348 int flag_access_control = 1;
350 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
352 int flag_operator_names;
354 /* Nonzero if we want to check the return value of new and avoid calling
355 constructors if it is a null pointer. */
359 /* Table of language-dependent -f options.
360 STRING is the option name. VARIABLE is the address of the variable.
361 ON_VALUE is the value to store in VARIABLE
362 if `-fSTRING' is seen as an option.
363 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
365 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
367 {"signed-char", &flag_signed_char, 1},
368 {"unsigned-char", &flag_signed_char, 0},
369 {"signed-bitfields", &flag_signed_bitfields, 1},
370 {"unsigned-bitfields", &flag_signed_bitfields, 0},
371 {"short-enums", &flag_short_enums, 1},
372 {"short-double", &flag_short_double, 1},
373 {"cond-mismatch", &flag_cond_mismatch, 1},
374 {"asm", &flag_no_asm, 0},
375 {"builtin", &flag_no_builtin, 0},
376 {"ident", &flag_no_ident, 0},
377 {"labels-ok", &flag_labels_ok, 1},
378 {"stats", &flag_detailed_statistics, 1},
379 {"this-is-variable", &flag_this_is_variable, 1},
380 {"strict-prototype", &flag_strict_prototype, 1},
381 {"all-virtual", &flag_all_virtual, 1},
382 {"memoize-lookups", &flag_memoize_lookups, 1},
383 {"elide-constructors", &flag_elide_constructors, 1},
384 {"handle-exceptions", &flag_handle_exceptions, 1},
385 {"handle-signatures", &flag_handle_signatures, 1},
386 {"default-inline", &flag_default_inline, 1},
387 {"dollars-in-identifiers", &dollars_in_ident, 1},
388 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
390 {"rtti", &flag_rtti, 1},
391 {"xref", &flag_gnu_xref, 1},
392 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
393 {"implement-inlines", &flag_implement_inlines, 1},
394 {"external-templates", &flag_external_templates, 1},
395 {"implicit-templates", &flag_implicit_templates, 1},
396 {"huge-objects", &flag_huge_objects, 1},
397 {"conserve-space", &flag_conserve_space, 1},
398 {"vtable-thunks", &flag_vtable_thunks, 1},
399 {"short-temps", &flag_short_temps, 1},
400 {"access-control", &flag_access_control, 1},
401 {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
402 {"gnu-keywords", &flag_no_gnu_keywords, 0},
403 {"operator-names", &flag_operator_names, 1},
404 {"check-new", &flag_check_new, 1}
407 /* Decode the string P as a language-specific option.
408 Return 1 if it is recognized (and handle it);
409 return 0 if not recognized. */
412 lang_decode_option (p)
415 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
416 flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
417 flag_this_is_variable = 1;
418 /* The +e options are for cfront compatibility. They come in as
419 `-+eN', to kludge around gcc.c's argument handling. */
420 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
422 int old_write_virtuals = write_virtuals;
425 else if (p[3] == '0')
427 else if (p[3] == '2')
429 else error ("invalid +e option");
430 if (old_write_virtuals != 0
431 && write_virtuals != old_write_virtuals)
432 error ("conflicting +e options given");
434 else if (p[0] == '-' && p[1] == 'f')
436 /* Some kind of -f option.
437 P's value is the option sans `-f'.
438 Search for it in the table of options. */
442 /* Try special -f options. */
444 if (!strcmp (p, "save-memoized"))
446 flag_memoize_lookups = 1;
447 flag_save_memoized_contexts = 1;
450 if (!strcmp (p, "no-save-memoized"))
452 flag_memoize_lookups = 0;
453 flag_save_memoized_contexts = 0;
456 else if (! strncmp (p, "cadillac", 8))
458 flag_cadillac = atoi (p+9);
461 else if (! strncmp (p, "no-cadillac", 11))
466 else if (! strcmp (p, "gc"))
469 /* This must come along for the ride. */
473 else if (! strcmp (p, "no-gc"))
476 /* This must come along for the ride. */
480 else if (! strcmp (p, "alt-external-templates"))
482 flag_external_templates = 1;
483 flag_alt_external_templates = 1;
486 else if (! strcmp (p, "no-alt-external-templates"))
488 flag_alt_external_templates = 0;
491 else if (!strcmp (p, "ansi-overloading"))
493 warning ("-fansi-overloading is no longer meaningful");
496 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
499 if (!strcmp (p, lang_f_options[j].string))
501 *lang_f_options[j].variable = lang_f_options[j].on_value;
502 /* A goto here would be cleaner,
503 but breaks the vax pcc. */
506 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
507 && ! strcmp (p+3, lang_f_options[j].string))
509 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
515 else if (p[0] == '-' && p[1] == 'W')
519 /* The -W options control the warning behavior of the compiler. */
522 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
525 if (!strcmp (p, "implicit"))
526 warn_implicit = setting;
527 else if (!strcmp (p, "return-type"))
528 warn_return_type = setting;
529 else if (!strcmp (p, "ctor-dtor-privacy"))
530 warn_ctor_dtor_privacy = setting;
531 else if (!strcmp (p, "write-strings"))
532 warn_write_strings = setting;
533 else if (!strcmp (p, "cast-qual"))
534 warn_cast_qual = setting;
535 else if (!strcmp (p, "traditional"))
536 warn_traditional = setting;
537 else if (!strcmp (p, "char-subscripts"))
538 warn_char_subscripts = setting;
539 else if (!strcmp (p, "pointer-arith"))
540 warn_pointer_arith = setting;
541 else if (!strcmp (p, "strict-prototypes"))
542 warn_strict_prototypes = setting;
543 else if (!strcmp (p, "missing-prototypes"))
544 warn_missing_prototypes = setting;
545 else if (!strcmp (p, "redundant-decls"))
546 warn_redundant_decls = setting;
547 else if (!strcmp (p, "missing-braces"))
548 warn_missing_braces = setting;
549 else if (!strcmp (p, "format"))
550 warn_format = setting;
551 else if (!strcmp (p, "conversion"))
552 warn_conversion = setting;
553 else if (!strcmp (p, "parentheses"))
554 warn_parentheses = setting;
555 else if (!strcmp (p, "non-virtual-dtor"))
556 warn_nonvdtor = setting;
557 else if (!strcmp (p, "extern-inline"))
558 warn_extern_inline = setting;
559 else if (!strcmp (p, "reorder"))
560 warn_reorder = setting;
561 else if (!strcmp (p, "synth"))
562 warn_synth = setting;
563 else if (!strcmp (p, "comment"))
564 ; /* cpp handles this one. */
565 else if (!strcmp (p, "comments"))
566 ; /* cpp handles this one. */
567 else if (!strcmp (p, "trigraphs"))
568 ; /* cpp handles this one. */
569 else if (!strcmp (p, "import"))
570 ; /* cpp handles this one. */
571 else if (!strcmp (p, "all"))
573 extra_warnings = setting;
574 warn_return_type = setting;
575 warn_unused = setting;
576 warn_implicit = setting;
577 warn_ctor_dtor_privacy = setting;
578 warn_switch = setting;
579 warn_format = setting;
580 warn_parentheses = setting;
581 warn_missing_braces = setting;
582 warn_extern_inline = setting;
583 warn_nonvdtor = setting;
584 /* We save the value of warn_uninitialized, since if they put
585 -Wuninitialized on the command line, we need to generate a
586 warning about not using it without also specifying -O. */
587 if (warn_uninitialized != 1)
588 warn_uninitialized = (setting ? 2 : 0);
589 warn_template_debugging = setting;
590 warn_reorder = setting;
593 else if (!strcmp (p, "overloaded-virtual"))
594 warn_overloaded_virtual = setting;
597 else if (!strcmp (p, "-ansi"))
598 dollars_in_ident = 0, flag_no_nonansi_builtin = 1, flag_ansi = 1,
599 flag_no_gnu_keywords = 1, flag_operator_names = 1;
601 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
602 it's probably safe to assume no sane person would ever want to use this
603 under normal circumstances. */
604 else if (!strcmp (p, "-spew-debug"))
613 /* Incorporate `const' and `volatile' qualifiers for member functions.
614 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
615 QUALS is a list of qualifiers. */
617 grok_method_quals (ctype, function, quals)
618 tree ctype, function, quals;
620 tree fntype = TREE_TYPE (function);
621 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
625 extern tree ridpointers[];
627 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
629 if (TYPE_READONLY (ctype))
630 error ("duplicate `%s' %s",
631 IDENTIFIER_POINTER (TREE_VALUE (quals)),
632 (TREE_CODE (function) == FUNCTION_DECL
633 ? "for member function" : "in type declaration"));
634 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
635 build_pointer_type (ctype);
637 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
639 if (TYPE_VOLATILE (ctype))
640 error ("duplicate `%s' %s",
641 IDENTIFIER_POINTER (TREE_VALUE (quals)),
642 (TREE_CODE (function) == FUNCTION_DECL
643 ? "for member function" : "in type declaration"));
644 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
645 build_pointer_type (ctype);
648 my_friendly_abort (20);
649 quals = TREE_CHAIN (quals);
652 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
653 (TREE_CODE (fntype) == METHOD_TYPE
654 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
655 : TYPE_ARG_TYPES (fntype)));
657 fntype = build_exception_variant (ctype, fntype, raises);
659 TREE_TYPE (function) = fntype;
663 #if 0 /* Not used. */
664 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
665 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
666 /* This does not yet work with user defined conversion operators
669 substitute_nice_name (decl)
672 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
674 char *n = decl_as_string (DECL_NAME (decl), 1);
675 if (n[strlen (n) - 1] == ' ')
676 n[strlen (n) - 1] = 0;
677 DECL_NAME (decl) = get_identifier (n);
682 /* Warn when -fexternal-templates is used and #pragma
683 interface/implementation is not used all the times it should be,
686 warn_if_unknown_interface (decl)
689 static int already_warned = 0;
690 if (already_warned++)
693 if (flag_alt_external_templates)
695 struct tinst_level *til = tinst_for_decl ();
697 char *sf = input_filename;
700 input_filename = til->file;
701 cp_warning ("template `%#D' instantiated in file without #pragma interface",
707 cp_warning_at ("template `%#D' defined in file without #pragma interface",
711 /* A subroutine of the parser, to handle a component list. */
713 grok_x_components (specs, components)
714 tree specs, components;
716 register tree t, x, tcode;
718 /* We just got some friends. They have been recorded elsewhere. */
719 if (components == void_type_node)
722 if (components == NULL_TREE)
724 t = groktypename (build_decl_list (specs, NULL_TREE));
728 error ("error in component specification");
732 switch (TREE_CODE (t))
735 /* Static anonymous unions come out as VAR_DECLs. */
736 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
737 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
740 /* We return SPECS here, because in the parser it was ending
741 up with not doing anything to $$, which is what SPECS
747 /* This code may be needed for UNION_TYPEs as
749 tcode = record_type_node;
750 if (CLASSTYPE_DECLARED_CLASS(t))
751 tcode = class_type_node;
752 else if (IS_SIGNATURE(t))
753 tcode = signature_type_node;
755 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
757 CLASSTYPE_NO_GLOBALIZE(t) = 1;
763 if (TREE_CODE(t) == UNION_TYPE)
764 tcode = union_type_node;
766 tcode = enum_type_node;
768 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
769 if (TREE_CODE(t) == UNION_TYPE && TYPE_CONTEXT(t))
770 CLASSTYPE_NO_GLOBALIZE(t) = 1;
771 if (TREE_CODE (t) == UNION_TYPE
772 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
774 struct pending_inline **p;
775 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
777 /* Wipe out memory of synthesized methods */
778 TYPE_HAS_CONSTRUCTOR (t) = 0;
779 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
780 TYPE_HAS_INIT_REF (t) = 0;
781 TYPE_HAS_CONST_INIT_REF (t) = 0;
782 TYPE_HAS_ASSIGN_REF (t) = 0;
783 TYPE_HAS_ASSIGNMENT (t) = 0;
784 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
786 p = &pending_inlines;
787 for (; *p; *p = (*p)->next)
788 if (DECL_CONTEXT ((*p)->fndecl) != t)
791 else if (TREE_CODE (t) == ENUMERAL_TYPE)
792 x = grok_enum_decls (t, NULL_TREE);
799 if (t != void_type_node)
800 error ("empty component declaration");
806 t = TREE_TYPE (components);
807 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
808 return grok_enum_decls (t, components);
814 /* Classes overload their constituent function names automatically.
815 When a function name is declared in a record structure,
816 its name is changed to it overloaded name. Since names for
817 constructors and destructors can conflict, we place a leading
820 CNAME is the name of the class we are grokking for.
822 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
824 FLAGS contains bits saying what's special about today's
825 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
827 If FUNCTION is a destructor, then we must add the `auto-delete' field
828 as a second parameter. There is some hair associated with the fact
829 that we must "declare" this variable in the manner consistent with the
830 way the rest of the arguments were declared.
832 QUALS are the qualifiers for the this pointer. */
835 grokclassfn (ctype, cname, function, flags, quals)
836 tree ctype, cname, function;
837 enum overload_flags flags;
840 tree fn_name = DECL_NAME (function);
845 if (fn_name == NULL_TREE)
847 error ("name missing for member function");
848 fn_name = get_identifier ("<anonymous>");
849 DECL_NAME (function) = fn_name;
853 qualtype = grok_method_quals (ctype, function, quals);
857 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
858 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
860 /* Must add the class instance variable up front. */
861 /* Right now we just make this a pointer. But later
862 we may wish to make it special. */
863 tree type = TREE_VALUE (arg_types);
865 if ((flag_this_is_variable > 0)
866 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
867 type = TYPE_MAIN_VARIANT (type);
869 if (DECL_CONSTRUCTOR_P (function))
871 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
873 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
874 /* In this case we need "in-charge" flag saying whether
875 this constructor is responsible for initialization
876 of virtual baseclasses or not. */
877 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
878 /* Mark the artificial `__in_chrg' parameter as "artificial". */
879 SET_DECL_ARTIFICIAL (parm);
880 DECL_ARG_TYPE (parm) = integer_type_node;
881 DECL_REGISTER (parm) = 1;
882 TREE_CHAIN (parm) = last_function_parms;
883 last_function_parms = parm;
887 parm = build_decl (PARM_DECL, this_identifier, type);
888 /* Mark the artificial `this' parameter as "artificial". */
889 SET_DECL_ARTIFICIAL (parm);
890 DECL_ARG_TYPE (parm) = type;
891 /* We can make this a register, so long as we don't
892 accidentally complain if someone tries to take its address. */
893 DECL_REGISTER (parm) = 1;
894 if (TYPE_READONLY (type))
895 TREE_READONLY (parm) = 1;
896 TREE_CHAIN (parm) = last_function_parms;
897 last_function_parms = parm;
900 if (flags == DTOR_FLAG)
903 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
904 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
906 arg_types = hash_tree_chain (const_integer_type, void_list_node);
907 TREE_SIDE_EFFECTS (arg_types) = 1;
908 /* Build the overload name. It will look like `7Example'. */
909 if (IDENTIFIER_TYPE_VALUE (cname))
910 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
911 else if (IDENTIFIER_LOCAL_VALUE (cname))
912 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
914 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
915 it's defined out of the class definition, since poplevel_class wipes
916 it out. This used to be internal error 346. */
917 dbuf = build_overload_name (ctype, 1, 1);
918 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
919 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
922 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
923 parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
924 /* Mark the artificial `__in_chrg' parameter as "artificial". */
925 SET_DECL_ARTIFICIAL (parm);
926 TREE_USED (parm) = 1;
928 /* We don't need to mark the __in_chrg parameter itself as `const'
929 since its type is already `const int'. In fact we MUST NOT mark
930 it as `const' cuz that will screw up the debug info (causing it
931 to say that the type of __in_chrg is `const const int'). */
932 TREE_READONLY (parm) = 1;
934 DECL_ARG_TYPE (parm) = const_integer_type;
935 /* This is the same chain as DECL_ARGUMENTS (...). */
936 TREE_CHAIN (last_function_parms) = parm;
938 TREE_TYPE (function) = build_cplus_method_type (qualtype, void_type_node,
940 TYPE_HAS_DESTRUCTOR (ctype) = 1;
944 tree these_arg_types;
946 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
948 arg_types = hash_tree_chain (integer_type_node,
949 TREE_CHAIN (arg_types));
951 = build_cplus_method_type (qualtype,
952 TREE_TYPE (TREE_TYPE (function)),
954 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
957 these_arg_types = arg_types;
959 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
960 /* Only true for static member functions. */
961 these_arg_types = hash_tree_chain (TYPE_POINTER_TO (qualtype),
964 DECL_ASSEMBLER_NAME (function)
965 = build_decl_overload (fn_name, these_arg_types,
966 1 + DECL_CONSTRUCTOR_P (function));
969 /* This code is going into the compiler, but currently, it makes
970 libg++/src/Interger.cc not compile. The problem is that the nice name
971 winds up going into the symbol table, and conversion operations look
972 for the manged name. */
973 substitute_nice_name (function);
977 DECL_ARGUMENTS (function) = last_function_parms;
978 /* First approximations. */
979 DECL_CONTEXT (function) = ctype;
980 DECL_CLASS_CONTEXT (function) = ctype;
983 /* Work on the expr used by alignof (this is only called by the parser). */
991 if (TREE_CODE (expr) == COMPONENT_REF
992 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
993 error ("`__alignof__' applied to a bit-field");
995 if (TREE_CODE (expr) == INDIRECT_REF)
997 best = t = TREE_OPERAND (expr, 0);
998 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1000 while (TREE_CODE (t) == NOP_EXPR
1001 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1004 t = TREE_OPERAND (t, 0);
1005 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1006 if (thisalign > bestalign)
1007 best = t, bestalign = thisalign;
1009 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1013 /* ANSI says arrays and fns are converted inside comma.
1014 But we can't convert them in build_compound_expr
1015 because that would break commas in lvalues.
1016 So do the conversion here if operand was a comma. */
1017 if (TREE_CODE (expr) == COMPOUND_EXPR
1018 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1019 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1020 expr = default_conversion (expr);
1021 return c_alignof (TREE_TYPE (expr));
1025 /* Create an ARRAY_REF, checking for the user doing things backwards
1028 grok_array_decl (array_expr, index_exp)
1029 tree array_expr, index_exp;
1031 tree type = TREE_TYPE (array_expr);
1033 if (type == error_mark_node || index_exp == error_mark_node)
1034 return error_mark_node;
1035 if (type == NULL_TREE)
1037 /* Something has gone very wrong. Assume we are mistakenly reducing
1038 an expression instead of a declaration. */
1039 error ("parser may be lost: is there a '{' missing somewhere?");
1043 if (TREE_CODE (type) == OFFSET_TYPE
1044 || TREE_CODE (type) == REFERENCE_TYPE)
1045 type = TREE_TYPE (type);
1047 /* If they have an `operator[]', use that. */
1048 if (TYPE_LANG_SPECIFIC (type)
1049 && TYPE_OVERLOADS_ARRAY_REF (type))
1050 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1051 array_expr, index_exp, NULL_TREE);
1053 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1054 if (TREE_CODE (type) == POINTER_TYPE
1055 || TREE_CODE (type) == ARRAY_TYPE)
1056 return build_array_ref (array_expr, index_exp);
1058 /* Woops, looks like they did something like `5[a]' instead of `a[5]'.
1059 We don't emit a warning or error for this, since it's allowed
1062 type = TREE_TYPE (index_exp);
1064 if (TREE_CODE (type) == OFFSET_TYPE
1065 || TREE_CODE (type) == REFERENCE_TYPE)
1066 type = TREE_TYPE (type);
1068 if (TREE_CODE (type) == POINTER_TYPE
1069 || TREE_CODE (type) == ARRAY_TYPE)
1070 return build_array_ref (index_exp, array_expr);
1072 /* The expression E1[E2] is identical (by definition) to *((E1)+(E2)). */
1073 return build_indirect_ref (build_binary_op (PLUS_EXPR, array_expr,
1078 /* Given the cast expression EXP, checking out its validity. Either return
1079 an error_mark_node if there was an unavoidable error, return a cast to
1080 void for trying to delete a pointer w/ the value 0, or return the
1081 call to delete. If DOING_VEC is 1, we handle things differently
1082 for doing an array delete. If DOING_VEC is 2, they gave us the
1083 array size as an argument to delete.
1084 Implements ARM $5.3.4. This is called from the parser. */
1086 delete_sanity (exp, size, doing_vec, use_global_delete)
1088 int doing_vec, use_global_delete;
1090 tree t = stabilize_reference (convert_from_reference (exp));
1091 tree type = TREE_TYPE (t);
1092 enum tree_code code = TREE_CODE (type);
1093 /* For a regular vector delete (aka, no size argument) we will pass
1094 this down as a NULL_TREE into build_vec_delete. */
1095 tree maxindex = NULL_TREE;
1096 /* This is used for deleting arrays. */
1102 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1103 if (! flag_traditional)
1104 pedwarn ("anachronistic use of array size in vector delete");
1107 elt_size = c_sizeof (type);
1110 if (code != POINTER_TYPE)
1112 cp_error ("type `%#T' argument given to `delete', expected pointer",
1114 return error_mark_node;
1117 /* Deleting a pointer with the value zero is valid and has no effect. */
1118 if (integer_zerop (t))
1119 return build1 (NOP_EXPR, void_type_node, t);
1122 if (code == POINTER_TYPE)
1125 /* As of Valley Forge, you can delete a pointer to constant. */
1126 /* You can't delete a pointer to constant. */
1127 if (TREE_READONLY (TREE_TYPE (type)))
1129 error ("`const *' cannot be deleted");
1130 return error_mark_node;
1133 /* You also can't delete functions. */
1134 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1136 error ("cannot delete a function");
1137 return error_mark_node;
1142 /* If the type has no destructor, then we should build a regular
1143 delete, instead of a vector delete. Otherwise, we would end
1144 up passing a bogus offset into __builtin_delete, which is
1145 not expecting it. */
1147 && TREE_CODE (type) == POINTER_TYPE
1148 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1151 use_global_delete = 1;
1156 return build_vec_delete (t, maxindex, elt_size, integer_one_node,
1157 integer_two_node, use_global_delete);
1159 return build_delete (type, t, integer_three_node,
1160 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
1164 /* Sanity check: report error if this function FUNCTION is not
1165 really a member of the class (CTYPE) it is supposed to belong to.
1166 CNAME is the same here as it is for grokclassfn above. */
1169 check_classfn (ctype, cname, function)
1170 tree ctype, cname, function;
1172 tree fn_name = DECL_NAME (function);
1174 tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
1178 if (method_vec != 0)
1180 methods = &TREE_VEC_ELT (method_vec, 0);
1181 end = TREE_VEC_END (method_vec);
1183 /* First suss out ctors and dtors. */
1185 && (fn_name == cname || fn_name == DECL_NAME (*methods)))
1188 while (++methods != end)
1190 if (fn_name == DECL_NAME (*methods))
1196 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1199 /* This should work, but causes libg++ to fail
1201 /* We have to do more extensive argument checking here, as
1202 the name may have been changed by asm("new_name"). */
1203 if (decls_match (function, fndecl))
1206 if (DECL_NAME (function) == DECL_NAME (fndecl))
1208 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1209 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1211 /* Get rid of the this parameter on functions that become
1213 if (DECL_STATIC_FUNCTION_P (fndecl)
1214 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1215 p1 = TREE_CHAIN (p1);
1217 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1218 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1219 && compparms (p1, p2, 3))
1223 fndecl = DECL_CHAIN (fndecl);
1231 cp_error ("argument list for `%#D' does not match any in class `%T'",
1236 cp_error ("no `%#D' member function declared in class `%T'",
1240 /* If we did not find the method in the class, add it to
1241 avoid spurious errors. */
1242 add_method (ctype, methods, function);
1245 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1246 of a structure component, returning a FIELD_DECL node.
1247 QUALS is a list of type qualifiers for this decl (such as for declaring
1248 const member functions).
1250 This is done during the parsing of the struct declaration.
1251 The FIELD_DECL nodes are chained together and the lot of them
1252 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1256 If class A defines that certain functions in class B are friends, then
1257 the way I have set things up, it is B who is interested in permission
1258 granted by A. However, it is in A's context that these declarations
1259 are parsed. By returning a void_type_node, class A does not attempt
1260 to incorporate the declarations of the friends within its structure.
1262 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1263 CHANGES TO CODE IN `start_method'. */
1266 grokfield (declarator, declspecs, raises, init, asmspec_tree)
1267 tree declarator, declspecs, raises, init, asmspec_tree;
1269 register tree value;
1271 int flags = LOOKUP_ONLYCONVERTING;
1273 /* Convert () initializers to = initializers. */
1274 if (init == NULL_TREE && declarator != NULL_TREE
1275 && TREE_CODE (declarator) == CALL_EXPR
1276 && TREE_OPERAND (declarator, 0)
1277 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1278 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1279 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1281 init = TREE_OPERAND (declarator, 1);
1282 declarator = TREE_OPERAND (declarator, 0);
1287 && TREE_CODE (init) == TREE_LIST
1288 && TREE_VALUE (init) == error_mark_node
1289 && TREE_CHAIN (init) == NULL_TREE)
1292 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
1294 return value; /* friend or constructor went bad. */
1296 /* Pass friendly classes back. */
1297 if (TREE_CODE (value) == VOID_TYPE)
1298 return void_type_node;
1300 if (DECL_NAME (value) != NULL_TREE
1301 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1302 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1303 cp_error ("member `%D' conflicts with virtual function table field name", value);
1305 /* Stash away type declarations. */
1306 if (TREE_CODE (value) == TYPE_DECL)
1308 DECL_NONLOCAL (value) = 1;
1309 DECL_CONTEXT (value) = current_class_type;
1310 DECL_CLASS_CONTEXT (value) = current_class_type;
1311 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1313 /* If we declare a typedef name for something that has no name,
1314 the typedef name is used for linkage. See 7.1.3 p4 94/0158. */
1315 if (TYPE_NAME (TREE_TYPE (value))
1316 && TREE_CODE (TYPE_NAME (TREE_TYPE (value))) == TYPE_DECL
1317 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (value))))
1319 TYPE_NAME (TREE_TYPE (value)) = value;
1320 TYPE_STUB_DECL (TREE_TYPE (value)) = value;
1323 pushdecl_class_level (value);
1327 if (IS_SIGNATURE (current_class_type)
1328 && TREE_CODE (value) != FUNCTION_DECL)
1330 error ("field declaration not allowed in signature");
1331 return void_type_node;
1334 if (DECL_IN_AGGR_P (value))
1336 cp_error ("`%D' is already defined in the class %T", value,
1337 DECL_CONTEXT (value));
1338 return void_type_node;
1342 cadillac_start_decl (value);
1345 asmspec = TREE_STRING_POINTER (asmspec_tree);
1349 if (IS_SIGNATURE (current_class_type)
1350 && TREE_CODE (value) == FUNCTION_DECL)
1352 error ("function declarations cannot have initializers in signature");
1355 else if (TREE_CODE (value) == FUNCTION_DECL)
1357 grok_function_init (value, init);
1360 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1361 /* Already complained in grokdeclarator. */
1365 /* We allow initializers to become parameters to base
1367 if (TREE_CODE (init) == TREE_LIST)
1369 if (TREE_CHAIN (init) == NULL_TREE)
1370 init = TREE_VALUE (init);
1372 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1375 if (TREE_CODE (init) == CONST_DECL)
1376 init = DECL_INITIAL (init);
1377 else if (TREE_READONLY_DECL_P (init))
1378 init = decl_constant_value (init);
1379 else if (TREE_CODE (init) == CONSTRUCTOR)
1380 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1381 my_friendly_assert (TREE_PERMANENT (init), 192);
1382 if (init == error_mark_node)
1383 /* We must make this look different than `error_mark_node'
1384 because `decl_const_value' would mis-interpret it
1385 as only meaning that this VAR_DECL is defined. */
1386 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1387 else if (! TREE_CONSTANT (init))
1389 /* We can allow references to things that are effectively
1390 static, since references are initialized with the address. */
1391 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1392 || (TREE_STATIC (init) == 0
1393 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1394 || DECL_EXTERNAL (init) == 0)))
1396 error ("field initializer is not constant");
1397 init = error_mark_node;
1403 /* The corresponding pop_obstacks is in finish_decl. */
1404 push_obstacks_nochange ();
1406 if (TREE_CODE (value) == VAR_DECL)
1408 /* We cannot call pushdecl here, because that would
1409 fill in the value of our TREE_CHAIN. Instead, we
1410 modify finish_decl to do the right thing, namely, to
1411 put this decl out straight away. */
1412 if (TREE_PUBLIC (value))
1414 /* current_class_type can be NULL_TREE in case of error. */
1415 if (asmspec == 0 && current_class_type)
1417 TREE_PUBLIC (value) = 1;
1418 DECL_INITIAL (value) = error_mark_node;
1419 DECL_ASSEMBLER_NAME (value)
1420 = build_static_name (current_class_type, DECL_NAME (value));
1422 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1424 /* Static consts need not be initialized in the class definition. */
1425 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1427 static int explanation = 0;
1429 error ("initializer invalid for static member with constructor");
1430 if (explanation++ == 0)
1431 error ("(you really want to initialize it separately)");
1434 /* Force the compiler to know when an uninitialized static
1435 const member is being used. */
1436 if (TYPE_READONLY (value) && init == 0)
1437 TREE_USED (value) = 1;
1439 DECL_INITIAL (value) = init;
1440 DECL_IN_AGGR_P (value) = 1;
1442 finish_decl (value, init, asmspec_tree, 1, flags);
1443 pushdecl_class_level (value);
1446 if (TREE_CODE (value) == FIELD_DECL)
1450 /* This must override the asm specifier which was placed
1451 by grokclassfn. Lay this out fresh. */
1452 DECL_RTL (value) = NULL_RTX;
1453 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1455 if (DECL_INITIAL (value) == error_mark_node)
1456 init = error_mark_node;
1457 finish_decl (value, init, asmspec_tree, 1, flags);
1458 DECL_INITIAL (value) = init;
1459 DECL_IN_AGGR_P (value) = 1;
1462 if (TREE_CODE (value) == FUNCTION_DECL)
1464 if (DECL_CHAIN (value) != NULL_TREE)
1466 /* Need a fresh node here so that we don't get circularity
1467 when we link these together. */
1468 value = copy_node (value);
1469 /* When does this happen? */
1470 my_friendly_assert (init == NULL_TREE, 193);
1474 /* This must override the asm specifier which was placed
1475 by grokclassfn. Lay this out fresh. */
1476 DECL_RTL (value) = NULL_RTX;
1477 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1479 finish_decl (value, init, asmspec_tree, 1, flags);
1481 /* Pass friends back this way. */
1482 if (DECL_FRIEND_P (value))
1483 return void_type_node;
1485 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1486 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1487 cp_error ("method `%#D' of local class must be defined in class body",
1491 DECL_IN_AGGR_P (value) = 1;
1494 my_friendly_abort (21);
1499 /* Like `grokfield', but for bitfields.
1500 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1503 grokbitfield (declarator, declspecs, width)
1504 tree declarator, declspecs, width;
1506 register tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL_TREE);
1508 if (! value) return NULL_TREE; /* friends went bad. */
1510 /* Pass friendly classes back. */
1511 if (TREE_CODE (value) == VOID_TYPE)
1512 return void_type_node;
1514 if (TREE_CODE (value) == TYPE_DECL)
1516 cp_error ("cannot declare `%D' to be a bitfield type", value);
1520 if (IS_SIGNATURE (current_class_type))
1522 error ("field declaration not allowed in signature");
1523 return void_type_node;
1526 if (DECL_IN_AGGR_P (value))
1528 cp_error ("`%D' is already defined in the class %T", value,
1529 DECL_CONTEXT (value));
1530 return void_type_node;
1533 GNU_xref_member (current_class_name, value);
1535 if (TREE_STATIC (value))
1537 cp_error ("static member `%D' cannot be a bitfield", value);
1540 finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1542 if (width != error_mark_node)
1544 /* detect invalid field size. */
1545 if (TREE_CODE (width) == CONST_DECL)
1546 width = DECL_INITIAL (width);
1547 else if (TREE_READONLY_DECL_P (width))
1548 width = decl_constant_value (width);
1549 if (TREE_CODE (width) != INTEGER_CST)
1551 cp_error ("structure field `%D' width not an integer constant",
1553 DECL_INITIAL (value) = NULL_TREE;
1557 constant_expression_warning (width);
1558 DECL_INITIAL (value) = width;
1559 DECL_BIT_FIELD (value) = 1;
1563 DECL_IN_AGGR_P (value) = 1;
1568 /* Like GROKFIELD, except that the declarator has been
1569 buried in DECLSPECS. Find the declarator, and
1570 return something that looks like it came from
1573 groktypefield (declspecs, parmlist)
1577 tree spec = declspecs;
1578 tree prev = NULL_TREE;
1580 tree type_id = NULL_TREE;
1581 tree quals = NULL_TREE;
1582 tree lengths = NULL_TREE;
1583 tree decl = NULL_TREE;
1587 register tree id = TREE_VALUE (spec);
1589 if (TREE_CODE (spec) != TREE_LIST)
1590 /* Certain parse errors slip through. For example,
1591 `int class ();' is not caught by the parser. Try
1592 weakly to recover here. */
1595 if (TREE_CODE (id) == TYPE_DECL
1596 || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
1598 /* We have a constructor/destructor or
1599 conversion operator. Use it. */
1601 TREE_CHAIN (prev) = TREE_CHAIN (spec);
1603 declspecs = TREE_CHAIN (spec);
1609 spec = TREE_CHAIN (spec);
1612 /* Nope, we have a conversion operator to a scalar type or something
1613 else, that includes things like constructor declarations for
1618 tree id = TREE_VALUE (spec);
1620 if (TREE_CODE (id) == IDENTIFIER_NODE)
1622 if (id == ridpointers[(int)RID_INT]
1623 || id == ridpointers[(int)RID_DOUBLE]
1624 || id == ridpointers[(int)RID_FLOAT]
1625 || id == ridpointers[(int)RID_WCHAR])
1628 error ("extra `%s' ignored",
1629 IDENTIFIER_POINTER (id));
1633 else if (id == ridpointers[(int)RID_LONG]
1634 || id == ridpointers[(int)RID_SHORT]
1635 || id == ridpointers[(int)RID_CHAR])
1637 lengths = tree_cons (NULL_TREE, id, lengths);
1639 else if (id == ridpointers[(int)RID_VOID])
1642 error ("spurious `void' type ignored");
1644 error ("conversion to `void' type invalid");
1646 else if (id == ridpointers[(int)RID_AUTO]
1647 || id == ridpointers[(int)RID_REGISTER]
1648 || id == ridpointers[(int)RID_TYPEDEF]
1649 || id == ridpointers[(int)RID_CONST]
1650 || id == ridpointers[(int)RID_VOLATILE])
1652 error ("type specifier `%s' used invalidly",
1653 IDENTIFIER_POINTER (id));
1655 else if (id == ridpointers[(int)RID_FRIEND]
1656 || id == ridpointers[(int)RID_VIRTUAL]
1657 || id == ridpointers[(int)RID_INLINE]
1658 || id == ridpointers[(int)RID_UNSIGNED]
1659 || id == ridpointers[(int)RID_SIGNED]
1660 || id == ridpointers[(int)RID_STATIC]
1661 || id == ridpointers[(int)RID_EXTERN])
1663 quals = tree_cons (NULL_TREE, id, quals);
1667 /* Happens when we have a global typedef
1668 and a class-local member function with
1674 else if (TREE_CODE (id) == RECORD_TYPE)
1676 type_id = TYPE_NAME (id);
1677 if (TREE_CODE (type_id) == TYPE_DECL)
1678 type_id = DECL_NAME (type_id);
1679 if (type_id == NULL_TREE)
1680 error ("identifier for aggregate type conversion omitted");
1682 else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't')
1683 error ("`operator' missing on conversion operator or tag missing from type");
1685 my_friendly_abort (194);
1686 spec = TREE_CHAIN (spec);
1690 declspecs = chainon (lengths, quals);
1693 if (TREE_CHAIN (lengths))
1694 error ("multiple length specifiers");
1695 type_id = ridpointers[(int)RID_INT];
1696 declspecs = chainon (lengths, quals);
1700 error ("no type given, defaulting to `operator int ...'");
1701 type_id = ridpointers[(int)RID_INT];
1708 decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
1709 declspecs, FIELD, 0, NULL_TREE);
1710 if (decl == NULL_TREE)
1713 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
1715 /* Need a fresh node here so that we don't get circularity
1716 when we link these together. */
1717 decl = copy_node (decl);
1720 if (decl == void_type_node
1721 || (TREE_CODE (decl) == FUNCTION_DECL
1722 && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
1723 /* bunch of friends. */
1726 if (DECL_IN_AGGR_P (decl))
1728 cp_error ("`%D' already defined in the class ", decl);
1729 return void_type_node;
1732 finish_decl (decl, NULL_TREE, NULL_TREE, 0, 0);
1734 /* If this declaration is common to another declaration
1735 complain about such redundancy, and return NULL_TREE
1736 so that we don't build a circular list. */
1737 if (DECL_CHAIN (decl))
1739 cp_error ("function `%D' declared twice in class %T", decl,
1740 DECL_CONTEXT (decl));
1743 DECL_IN_AGGR_P (decl) = 1;
1749 grokoptypename (declspecs, declarator)
1750 tree declspecs, declarator;
1752 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1753 return build_typename_overload (t);
1756 /* When a function is declared with an initializer,
1757 do the right thing. Currently, there are two possibilities:
1762 // initialization possibility #1.
1763 virtual void f () = 0;
1785 // initialization possibility #2
1792 copy_assignment_arg_p (parmtype, virtualp)
1796 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1797 parmtype = TREE_TYPE (parmtype);
1799 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1800 || (virtualp && DERIVED_FROM_P (parmtype, current_class_type)))
1807 grok_function_init (decl, init)
1811 /* An initializer for a function tells how this function should
1813 tree type = TREE_TYPE (decl);
1815 if (TREE_CODE (type) == FUNCTION_TYPE)
1816 cp_error ("initializer specified for non-member function `%D'", decl);
1817 else if (DECL_VINDEX (decl) == NULL_TREE)
1818 cp_error ("initializer specified for non-virtual method `%D'", decl);
1819 else if (integer_zerop (init))
1822 /* Mark this function as being "defined". */
1823 DECL_INITIAL (decl) = error_mark_node;
1824 /* pure virtual destructors must be defined. */
1825 /* pure virtual needs to be defined (as abort) only when put in
1826 vtbl. For wellformed call, it should be itself. pr4737 */
1827 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1829 extern tree abort_fndecl;
1830 /* Give this node rtl from `abort'. */
1831 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1834 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1835 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1838 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1840 if (copy_assignment_arg_p (parmtype, 1))
1841 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1844 else if (TREE_CODE (init) == OFFSET_REF
1845 && TREE_OPERAND (init, 0) == NULL_TREE
1846 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1848 tree basetype = DECL_CLASS_CONTEXT (init);
1849 tree basefn = TREE_OPERAND (init, 1);
1850 if (TREE_CODE (basefn) != FUNCTION_DECL)
1851 cp_error ("non-method initializer invalid for method `%D'", decl);
1852 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1853 sorry ("base member function from other than first base class");
1856 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1857 if (binfo == error_mark_node)
1859 else if (binfo == 0)
1860 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1861 TYPE_METHOD_BASETYPE (type));
1864 /* Mark this function as being defined,
1865 and give it new rtl. */
1866 DECL_INITIAL (decl) = error_mark_node;
1867 DECL_RTL (decl) = DECL_RTL (basefn);
1872 cp_error ("invalid initializer for virtual method `%D'", decl);
1875 /* When we get a declaration of the form
1877 type cname::fname ...
1879 the node for `cname::fname' gets built here in a special way.
1880 Namely, we push into `cname's scope. When this declaration is
1881 processed, we pop back out. */
1883 build_push_scope (cname, name)
1887 extern int current_class_depth;
1891 if (cname == error_mark_node)
1892 return error_mark_node;
1894 ctype = IDENTIFIER_TYPE_VALUE (cname);
1896 if (TREE_CODE (ctype) == TEMPLATE_TYPE_PARM)
1898 else if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
1900 cp_error ("`%T' not defined as aggregate type", cname);
1903 else if (IS_SIGNATURE (ctype))
1905 error ("cannot push into signature scope, scope resolution operator ignored");
1909 rval = build_parse_node (SCOPE_REF, cname, name);
1911 /* Don't need to push the scope if we're already in it.
1912 We also don't need to push the scope for a ptr-to-member/method. */
1914 if (ctype == current_class_type || TREE_CODE (name) != IDENTIFIER_NODE
1918 /* We do need to push the scope in this case, since CTYPE helps
1919 determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;). */
1921 push_nested_class (ctype, 3);
1922 TREE_COMPLEXITY (rval) = current_class_depth;
1926 void cplus_decl_attributes (decl, attributes)
1927 tree decl, attributes;
1929 if (decl && decl != void_type_node)
1930 decl_attributes (decl, attributes);
1933 /* CONSTRUCTOR_NAME:
1934 Return the name for the constructor (or destructor) for the
1935 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1936 IDENTIFIER_NODE. When given a template, this routine doesn't
1937 lose the specialization. */
1939 constructor_name_full (thing)
1942 if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
1943 return DECL_NAME (UPT_TEMPLATE (thing));
1944 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1946 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1947 thing = DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing), 0));
1949 thing = TYPE_NAME (thing);
1951 if (TREE_CODE (thing) == TYPE_DECL
1952 || (TREE_CODE (thing) == TEMPLATE_DECL
1953 && DECL_TEMPLATE_IS_CLASS (thing)))
1954 thing = DECL_NAME (thing);
1955 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1959 /* CONSTRUCTOR_NAME:
1960 Return the name for the constructor (or destructor) for the
1961 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1962 IDENTIFIER_NODE. When given a template, return the plain
1963 unspecialized name. */
1965 constructor_name (thing)
1969 thing = constructor_name_full (thing);
1970 t = IDENTIFIER_TEMPLATE (thing);
1973 t = TREE_PURPOSE (t);
1974 return DECL_NAME (t);
1977 /* Cache the value of this class's main virtual function table pointer
1978 in a register variable. This will save one indirection if a
1979 more than one virtual function call is made this function. */
1983 extern rtx base_init_insns;
1985 if (base_init_insns == 0
1986 && DECL_CONSTRUCTOR_P (current_function_decl))
1987 emit_base_init (current_class_type, 0);
1990 /* This has something a little wrong with it.
1992 On a sun4, code like:
1997 is generated, when the below is used when -O4 is given. The delay
1998 slot it filled with an instruction that is safe, when this isn't
2008 virtual void print() { printf("xxx"); }
2020 And that is why this is disabled for now. (mrs)
2023 if ((flag_this_is_variable & 1) == 0
2025 && current_class_type
2026 && CLASSTYPE_VSIZE (current_class_type)
2027 && ! DECL_STATIC_FUNCTION_P (current_function_decl))
2029 tree vfield = build_vfield_ref (C_C_D, current_class_type);
2030 current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
2031 DECL_RTL (current_vtable_decl) = 0;
2032 DECL_INITIAL (current_vtable_decl) = error_mark_node;
2033 /* Have to cast the initializer, since it may have come from a
2034 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
2035 finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield, 0), NULL_TREE, 0, 0);
2036 current_vtable_decl = build_indirect_ref (current_vtable_decl, NULL_PTR);
2040 current_vtable_decl = NULL_TREE;
2043 /* Record the existence of an addressable inline function. */
2045 mark_inline_for_output (decl)
2048 decl = DECL_MAIN_VARIANT (decl);
2049 if (DECL_SAVED_INLINE (decl))
2051 my_friendly_assert (TREE_PERMANENT (decl), 363);
2052 DECL_SAVED_INLINE (decl) = 1;
2053 if (DECL_PENDING_INLINE_INFO (decl) != 0
2054 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
2056 struct pending_inline *t = pending_inlines;
2057 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
2060 if (t == DECL_PENDING_INLINE_INFO (decl))
2066 t = DECL_PENDING_INLINE_INFO (decl);
2067 t->next = pending_inlines;
2068 pending_inlines = t;
2070 DECL_PENDING_INLINE_INFO (decl) = 0;
2072 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
2078 temp_name_counter = 0;
2081 /* Hand off a unique name which can be used for variable we don't really
2082 want to know about anyway, for example, the anonymous variables which
2083 are needed to make references work. Declare this thing so we can use it.
2084 The variable created will be of type TYPE.
2086 STATICP is nonzero if this variable should be static. */
2089 get_temp_name (type, staticp)
2093 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
2095 int toplev = global_bindings_p ();
2097 push_obstacks_nochange ();
2098 if (toplev || staticp)
2100 end_temporary_allocation ();
2101 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
2102 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
2106 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
2107 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
2109 TREE_USED (decl) = 1;
2110 TREE_STATIC (decl) = staticp;
2112 /* If this is a local variable, then lay out its rtl now.
2113 Otherwise, callers of this function are responsible for dealing
2114 with this variable's rtl. */
2118 expand_decl_init (decl);
2125 /* Get a variable which we can use for multiple assignments.
2126 It is not entered into current_binding_level, because
2127 that breaks things when it comes time to do final cleanups
2128 (which take place "outside" the binding contour of the function). */
2130 get_temp_regvar (type, init)
2133 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
2136 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
2137 decl = build_decl (VAR_DECL, get_identifier (buf), type);
2138 TREE_USED (decl) = 1;
2139 DECL_REGISTER (decl) = 1;
2142 store_init_value (decl, init);
2144 /* We can expand these without fear, since they cannot need
2145 constructors or destructors. */
2147 expand_decl_init (decl);
2149 if (type_needs_gc_entry (type))
2150 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
2155 /* Make the macro TEMP_NAME_P available to units which do not
2156 include c-tree.h. */
2161 return TEMP_NAME_P (decl);
2164 /* Finish off the processing of a UNION_TYPE structure.
2165 If there are static members, then all members are
2166 static, and must be laid out together. If the
2167 union is an anonymous union, we arrange for that
2168 as well. PUBLIC_P is nonzero if this union is
2169 not declared static. */
2171 finish_anon_union (anon_union_decl)
2172 tree anon_union_decl;
2174 tree type = TREE_TYPE (anon_union_decl);
2175 tree field, main_decl = NULL_TREE;
2176 tree elems = NULL_TREE;
2177 int public_p = TREE_PUBLIC (anon_union_decl);
2178 int static_p = TREE_STATIC (anon_union_decl);
2179 int external_p = DECL_EXTERNAL (anon_union_decl);
2181 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
2186 error ("global anonymous unions must be declared static");
2190 for (; field; field = TREE_CHAIN (field))
2193 if (TREE_CODE (field) != FIELD_DECL)
2196 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2197 /* tell `pushdecl' that this is not tentative. */
2198 DECL_INITIAL (decl) = error_mark_node;
2199 TREE_PUBLIC (decl) = public_p;
2200 TREE_STATIC (decl) = static_p;
2201 DECL_EXTERNAL (decl) = external_p;
2202 decl = pushdecl (decl);
2204 /* Only write out one anon union element--choose the one that
2205 can hold them all. */
2206 if (main_decl == NULL_TREE
2207 && simple_cst_equal (DECL_SIZE (decl), DECL_SIZE (anon_union_decl)))
2213 /* ??? This causes there to be no debug info written out
2215 TREE_ASM_WRITTEN (decl) = 1;
2218 DECL_INITIAL (decl) = NULL_TREE;
2219 /* If there's a cleanup to do, it belongs in the
2220 TREE_PURPOSE of the following TREE_LIST. */
2221 elems = tree_cons (NULL_TREE, decl, elems);
2222 TREE_TYPE (elems) = type;
2228 make_decl_rtl (main_decl, 0, global_bindings_p ());
2229 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2233 warning ("anonymous union with no members");
2238 /* The following call assumes that there are never any cleanups
2239 for anonymous unions--a reasonable assumption. */
2240 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2243 cadillac_finish_anon_union (anon_union_decl);
2246 /* Finish and output a table which is generated by the compiler.
2247 NAME is the name to give the table.
2248 TYPE is the type of the table entry.
2249 INIT is all the elements in the table.
2250 PUBLICP is non-zero if this table should be given external access. */
2252 finish_table (name, type, init, publicp)
2253 tree name, type, init;
2256 tree itype, atype, decl;
2257 static tree empty_table;
2261 itype = build_index_type (size_int (list_length (init) - 1));
2262 atype = build_cplus_array_type (type, itype);
2263 layout_type (atype);
2265 if (TREE_VALUE (init) == integer_zero_node
2266 && TREE_CHAIN (init) == NULL_TREE)
2269 if (empty_table == NULL_TREE)
2272 empty_table = get_temp_name (atype, 1);
2273 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2274 TREE_CONSTANT (init) = 1;
2275 TREE_STATIC (init) = 1;
2276 DECL_INITIAL (empty_table) = init;
2277 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2278 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2279 finish_decl (empty_table, init, asmspec, 0, 0);
2284 if (name == NULL_TREE)
2288 decl = get_temp_name (atype, 1);
2292 decl = build_decl (VAR_DECL, name, atype);
2293 decl = pushdecl (decl);
2294 TREE_STATIC (decl) = 1;
2299 TREE_PUBLIC (decl) = publicp;
2300 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2301 TREE_CONSTANT (init) = 1;
2302 TREE_STATIC (init) = 1;
2303 DECL_INITIAL (decl) = init;
2304 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2305 IDENTIFIER_POINTER (DECL_NAME (decl)));
2309 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2310 DECL_EXTERNAL (decl) = 1;
2311 TREE_STATIC (decl) = 0;
2313 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2314 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2317 finish_decl (decl, init, asmspec, 0, 0);
2321 /* Finish processing a builtin type TYPE. It's name is NAME,
2322 its fields are in the array FIELDS. LEN is the number of elements
2323 in FIELDS minus one, or put another way, it is the maximum subscript
2326 It is given the same alignment as ALIGN_TYPE. */
2328 finish_builtin_type (type, name, fields, len, align_type)
2337 TYPE_FIELDS (type) = fields[0];
2338 for (i = 0; i < len; i++)
2340 layout_type (TREE_TYPE (fields[i]));
2341 DECL_FIELD_CONTEXT (fields[i]) = type;
2342 TREE_CHAIN (fields[i]) = fields[i+1];
2344 DECL_FIELD_CONTEXT (fields[i]) = type;
2345 DECL_CLASS_CONTEXT (fields[i]) = type;
2346 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2348 #if 0 /* not yet, should get fixed properly later */
2349 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2351 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2353 layout_decl (TYPE_NAME (type), 0);
2356 /* Auxiliary functions to make type signatures for
2357 `operator new' and `operator delete' correspond to
2358 what compiler will be expecting. */
2360 extern tree sizetype;
2363 coerce_new_type (type)
2368 if (TREE_CODE (type) == METHOD_TYPE)
2369 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2370 if (TREE_TYPE (type) != ptr_type_node)
2371 e1 = 1, error ("`operator new' must return type `void *'");
2373 /* Technically the type must be `size_t', but we may not know
2375 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2376 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2377 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2378 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2379 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2381 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2383 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2388 coerce_delete_type (type)
2391 int e1 = 0, e2 = 0, e3 = 0;
2392 tree arg_types = TYPE_ARG_TYPES (type);
2394 if (TREE_CODE (type) == METHOD_TYPE)
2396 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2397 arg_types = TREE_CHAIN (arg_types);
2399 if (TREE_TYPE (type) != void_type_node)
2400 e1 = 1, error ("`operator delete' must return type `void'");
2401 if (arg_types == NULL_TREE
2402 || TREE_VALUE (arg_types) != ptr_type_node)
2403 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2406 && TREE_CHAIN (arg_types)
2407 && TREE_CHAIN (arg_types) != void_list_node)
2409 /* Again, technically this argument must be `size_t', but again
2410 we may not know what that is. */
2411 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2412 if (TREE_CODE (t2) != INTEGER_TYPE
2413 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2414 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2415 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2418 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2419 error ("too many arguments in declaration of `operator delete'");
2421 error ("`...' invalid in specification of `operator delete'");
2425 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
2428 if (arg_types == NULL_TREE)
2429 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2431 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2436 type = build_function_type (void_type_node, arg_types);
2442 mark_vtable_entries (decl)
2445 tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
2447 for (; entries; entries = TREE_CHAIN (entries))
2449 tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
2450 tree fn = TREE_OPERAND (fnaddr, 0);
2451 TREE_ADDRESSABLE (fn) = 1;
2452 if (DECL_ABSTRACT_VIRTUAL_P (fn))
2454 extern tree abort_fndecl;
2455 if (flag_vtable_thunks)
2456 fnaddr = TREE_VALUE (entries);
2457 TREE_OPERAND (fnaddr, 0) = abort_fndecl;
2462 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2463 based on TYPE and other static flags.
2465 Note that anything public is tagged TREE_PUBLIC, whether
2466 it's public in this file or in another one. */
2469 import_export_vtable (decl, type)
2472 if (write_virtuals >= 2
2473 || CLASSTYPE_TEMPLATE_INSTANTIATION (type))
2475 if (CLASSTYPE_INTERFACE_KNOWN (type))
2477 TREE_PUBLIC (decl) = 1;
2478 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2481 else if (write_virtuals != 0)
2483 TREE_PUBLIC (decl) = 1;
2484 if (write_virtuals < 0)
2485 DECL_EXTERNAL (decl) = 1;
2490 import_export_template (type)
2493 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2494 && ! flag_implicit_templates
2495 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2497 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2498 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2499 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2504 finish_prevtable_vardecl (prev, vars)
2507 tree ctype = DECL_CONTEXT (vars);
2508 import_export_template (ctype);
2509 import_export_vtable (vars, ctype);
2511 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype))
2514 for (method = CLASSTYPE_METHODS (ctype); method != NULL_TREE;
2515 method = DECL_NEXT_METHOD (method))
2517 if (DECL_VINDEX (method) != NULL_TREE && !DECL_SAVED_INSNS (method)
2518 && !DECL_ABSTRACT_VIRTUAL_P (method))
2520 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2521 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method);
2522 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2523 TREE_PUBLIC (vars) = 1;
2524 DECL_EXTERNAL (vars) = DECL_EXTERNAL (method);
2530 if (write_virtuals >= 0
2531 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
2533 extern tree the_null_vtable_entry;
2535 /* Kick out the type descriptor before writing out the vtable. */
2538 build_t_desc (ctype, 1);
2542 mark_vtable_entries (vars);
2547 finish_vtable_vardecl (prev, vars)
2550 tree ctype = DECL_CONTEXT (vars);
2551 import_export_template (ctype);
2552 import_export_vtable (vars, ctype);
2554 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype))
2557 for (method = CLASSTYPE_METHODS (ctype); method != NULL_TREE;
2558 method = DECL_NEXT_METHOD (method))
2560 if (DECL_VINDEX (method) != NULL_TREE && !DECL_SAVED_INSNS (method)
2561 && !DECL_ABSTRACT_VIRTUAL_P (method))
2563 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2564 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method);
2565 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2566 TREE_PUBLIC (vars) = 1;
2567 DECL_EXTERNAL (vars) = DECL_EXTERNAL (method);
2569 cp_warning ("compiler error: rtti entry for `%T' decided too late", ctype);
2575 if (write_virtuals >= 0
2576 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
2578 extern tree the_null_vtable_entry;
2581 mark_vtable_entries (vars);
2582 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2583 store_init_value (vars, DECL_INITIAL (vars));
2585 #ifdef DWARF_DEBUGGING_INFO
2586 if (write_symbols == DWARF_DEBUG)
2588 /* Mark the VAR_DECL node representing the vtable itself as a
2589 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2590 It is rather important that such things be ignored because
2591 any effort to actually generate DWARF for them will run
2592 into trouble when/if we encounter code like:
2595 struct S { virtual void member (); };
2597 because the artificial declaration of the vtable itself (as
2598 manufactured by the g++ front end) will say that the vtable
2599 is a static member of `S' but only *after* the debug output
2600 for the definition of `S' has already been output. This causes
2601 grief because the DWARF entry for the definition of the vtable
2602 will try to refer back to an earlier *declaration* of the
2603 vtable as a static member of `S' and there won't be one.
2604 We might be able to arrange to have the "vtable static member"
2605 attached to the member list for `S' before the debug info for
2606 `S' get written (which would solve the problem) but that would
2607 require more intrusive changes to the g++ front end. */
2609 DECL_IGNORED_P (vars) = 1;
2611 #endif /* DWARF_DEBUGGING_INFO */
2613 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2615 else if (TREE_USED (vars) && flag_vtable_thunks)
2616 assemble_external (vars);
2617 /* We know that PREV must be non-zero here. */
2618 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2622 walk_vtables (typedecl_fn, vardecl_fn)
2623 register void (*typedecl_fn)();
2624 register void (*vardecl_fn)();
2628 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2630 register tree type = TREE_TYPE (vars);
2632 if (TREE_CODE (vars) == TYPE_DECL
2633 && type != error_mark_node
2634 && TYPE_LANG_SPECIFIC (type)
2635 && CLASSTYPE_VSIZE (type))
2637 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2639 else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2641 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2649 finish_sigtable_vardecl (prev, vars)
2652 /* We don't need to mark sigtable entries as addressable here as is done
2653 for vtables. Since sigtables, unlike vtables, are always written out,
2654 that was already done in build_signature_table_constructor. */
2656 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2658 /* We know that PREV must be non-zero here. */
2659 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2663 walk_sigtables (typedecl_fn, vardecl_fn)
2664 register void (*typedecl_fn)();
2665 register void (*vardecl_fn)();
2669 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2671 register tree type = TREE_TYPE (vars);
2673 if (TREE_CODE (vars) == TYPE_DECL
2674 && type != error_mark_node
2675 && IS_SIGNATURE (type))
2677 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2679 else if (TREE_CODE (vars) == VAR_DECL
2680 && TREE_TYPE (vars) != error_mark_node
2681 && IS_SIGNATURE (TREE_TYPE (vars)))
2683 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2690 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2691 inline function at end-of-file. */
2694 import_export_inline (decl)
2697 if (DECL_INTERFACE_KNOWN (decl))
2700 if (DECL_TEMPLATE_INSTANTIATION (decl))
2702 if (DECL_IMPLICIT_INSTANTIATION (decl) && flag_implicit_templates)
2703 TREE_PUBLIC (decl) = 0;
2705 DECL_EXTERNAL (decl) = 1;
2707 else if (DECL_FUNCTION_MEMBER_P (decl))
2709 tree ctype = DECL_CLASS_CONTEXT (decl);
2710 if (CLASSTYPE_INTERFACE_KNOWN (ctype))
2712 DECL_EXTERNAL (decl)
2713 = (CLASSTYPE_INTERFACE_ONLY (ctype)
2714 || (DECL_INLINE (decl) && ! flag_implement_inlines));
2717 TREE_PUBLIC (decl) = 0;
2720 TREE_PUBLIC (decl) = 0;
2723 extern int parse_time, varconst_time;
2725 #define TIMEVAR(VAR, BODY) \
2726 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2728 /* This routine is called from the last rule in yyparse ().
2729 Its job is to create all the code needed to initialize and
2730 destroy the global aggregates. We do the destruction
2731 first, since that way we only need to reverse the decls once. */
2737 int start_time, this_time;
2740 tree vars = static_aggregates;
2741 int needs_cleaning = 0, needs_messing_up = 0;
2742 int have_exception_handlers = build_exception_table ();
2744 if (flag_detailed_statistics)
2745 dump_tree_statistics ();
2747 /* Bad parse errors. Just forget about it. */
2748 if (! global_bindings_p () || current_class_type)
2751 start_time = get_run_time ();
2753 /* Push into C language context, because that's all
2755 push_lang_context (lang_name_c);
2757 if (static_ctors || vars || have_exception_handlers)
2758 needs_messing_up = 1;
2762 /* See if we really need the hassle. */
2763 while (vars && needs_cleaning == 0)
2765 tree decl = TREE_VALUE (vars);
2766 tree type = TREE_TYPE (decl);
2767 if (TYPE_NEEDS_DESTRUCTOR (type))
2770 needs_messing_up = 1;
2774 needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
2775 vars = TREE_CHAIN (vars);
2778 /* Otherwise, GDB can get confused, because in only knows
2779 about source for LINENO-1 lines. */
2782 interface_unknown = 1;
2785 /* Walk to mark the inline functions we need, then output them so
2786 that we can pick up any other tdecls that those routines need. */
2787 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2788 for (vars = saved_inlines; vars; vars = TREE_CHAIN (vars))
2790 tree decl = TREE_VALUE (vars);
2792 if (DECL_ARTIFICIAL (decl)
2793 && ! DECL_INITIAL (decl)
2794 && (TREE_USED (decl) || ! DECL_EXTERNAL (decl)))
2795 synthesize_method (decl);
2797 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2799 if (needs_cleaning == 0)
2802 fnname = get_file_function_name ('D');
2803 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2804 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2805 store_parm_decls ();
2810 expand_start_bindings (0);
2812 /* These must be done in backward order to destroy,
2813 in which they happen to be! */
2814 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2816 tree decl = TREE_VALUE (vars);
2817 tree type = TREE_TYPE (decl);
2818 tree temp = TREE_PURPOSE (vars);
2820 if (TYPE_NEEDS_DESTRUCTOR (type))
2822 if (TREE_STATIC (vars))
2823 expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node, 1), 0);
2824 if (TREE_CODE (type) == ARRAY_TYPE)
2828 mark_addressable (decl);
2829 temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
2831 temp = build_delete (TREE_TYPE (temp), temp,
2832 integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2833 expand_expr_stmt (temp);
2835 if (TREE_STATIC (vars))
2840 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2841 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2844 expand_end_bindings (getdecls(), 1, 0);
2848 finish_function (lineno, 0, 0);
2850 assemble_destructor (IDENTIFIER_POINTER (fnname));
2852 /* if it needed cleaning, then it will need messing up: drop through */
2855 /* Must do this while we think we are at the top level. */
2856 vars = nreverse (static_aggregates);
2857 if (needs_messing_up)
2859 fnname = get_file_function_name ('I');
2860 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2861 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2862 store_parm_decls ();
2867 expand_start_bindings (0);
2869 if (have_exception_handlers)
2870 register_exception_table ();
2874 tree decl = TREE_VALUE (vars);
2875 tree init = TREE_PURPOSE (vars);
2876 tree old_cleanups = cleanups_this_call;
2878 /* If this was a static attribute within some function's scope,
2879 then don't initialize it here. Also, don't bother
2880 with initializers that contain errors. */
2881 if (TREE_STATIC (vars)
2882 || (init && TREE_CODE (init) == TREE_LIST
2883 && value_member (error_mark_node, init)))
2885 vars = TREE_CHAIN (vars);
2889 if (TREE_CODE (decl) == VAR_DECL)
2891 /* Set these global variables so that GDB at least puts
2892 us near the declaration which required the initialization. */
2893 input_filename = DECL_SOURCE_FILE (decl);
2894 lineno = DECL_SOURCE_LINE (decl);
2895 emit_note (input_filename, lineno);
2897 /* 9.5p5: The initializer of a static member of a class has
2898 the same acess rights as a member function. */
2899 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2904 if (TREE_CODE (init) == VAR_DECL)
2906 /* This behavior results when there are
2907 multiple declarations of an aggregate,
2908 the last of which defines it. */
2909 if (DECL_RTL (init) == DECL_RTL (decl))
2911 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node
2912 || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
2913 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE),
2915 init = DECL_INITIAL (init);
2916 if (TREE_CODE (init) == CONSTRUCTOR
2917 && CONSTRUCTOR_ELTS (init) == NULL_TREE)
2920 else if (TREE_TYPE (decl) == TREE_TYPE (init))
2923 my_friendly_abort (200);
2925 /* point to real decl's rtl anyway. */
2926 DECL_RTL (init) = DECL_RTL (decl);
2927 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node,
2929 init = DECL_INITIAL (init);
2935 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2936 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2937 expand_aggr_init (decl, init, 0, 0);
2938 else if (TREE_CODE (init) == TREE_VEC)
2940 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2941 TREE_VEC_ELT (init, 1),
2942 TREE_VEC_ELT (init, 2), 0),
2943 const0_rtx, VOIDmode, 0);
2947 expand_assignment (decl, init, 0, 0);
2949 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2951 else if (TREE_CODE (decl) == SAVE_EXPR)
2953 if (! PARM_DECL_EXPR (decl))
2955 /* a `new' expression at top level. */
2956 expand_expr (decl, const0_rtx, VOIDmode, 0);
2958 expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0, 0);
2961 else if (decl == error_mark_node)
2963 else my_friendly_abort (22);
2964 vars = TREE_CHAIN (vars);
2965 /* Cleanup any temporaries needed for the initial value. */
2966 expand_cleanups_to (old_cleanups);
2969 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
2970 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
2973 expand_end_bindings (getdecls(), 1, 0);
2977 finish_function (lineno, 0, 0);
2978 assemble_constructor (IDENTIFIER_POINTER (fnname));
2981 /* Done with C language context needs. */
2982 pop_lang_context ();
2984 /* Now write out any static class variables (which may have since
2985 learned how to be initialized). */
2986 while (pending_statics)
2988 tree decl = TREE_VALUE (pending_statics);
2989 if (TREE_USED (decl) == 1
2990 || TREE_READONLY (decl) == 0
2991 || DECL_INITIAL (decl) == 0)
2992 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
2993 pending_statics = TREE_CHAIN (pending_statics);
2996 this_time = get_run_time ();
2997 parse_time -= this_time - start_time;
2998 varconst_time += this_time - start_time;
3000 start_time = get_run_time ();
3002 /* Now delete from the chain of variables all virtual function tables.
3003 We output them all ourselves, because each will be treated specially. */
3006 /* The reason for pushing garbage onto the global_binding_level is to
3007 ensure that we can slice out _DECLs which pertain to virtual function
3008 tables. If the last thing pushed onto the global_binding_level was a
3009 virtual function table, then slicing it out would slice away all the
3010 decls (i.e., we lose the head of the chain).
3012 There are several ways of getting the same effect, from changing the
3013 way that iterators over the chain treat the elements that pertain to
3014 virtual function tables, moving the implementation of this code to
3015 decl.c (where we can manipulate global_binding_level directly),
3016 popping the garbage after pushing it and slicing away the vtable
3017 stuff, or just leaving it alone. */
3019 /* Make last thing in global scope not be a virtual function table. */
3020 #if 0 /* not yet, should get fixed properly later */
3021 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
3023 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
3025 DECL_IGNORED_P (vars) = 1;
3026 SET_DECL_ARTIFICIAL (vars);
3030 walk_vtables ((void (*)())0, finish_vtable_vardecl);
3031 if (flag_handle_signatures)
3032 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3034 for (vars = saved_inlines; vars; vars = TREE_CHAIN (vars))
3036 tree decl = TREE_VALUE (vars);
3038 if (DECL_ARTIFICIAL (decl)
3039 && ! DECL_INITIAL (decl)
3040 && TREE_USED (decl))
3041 synthesize_method (decl);
3044 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3046 if (TREE_CODE (vars) == THUNK_DECL)
3048 else if (TREE_CODE (vars) == FUNCTION_DECL
3049 && ! DECL_INTERFACE_KNOWN (vars)
3050 && DECL_DECLARED_STATIC (vars))
3051 TREE_PUBLIC (vars) = 0;
3054 /* Now write out inline functions which had their addresses taken and
3055 which were not declared virtual and which were not declared `extern
3058 int reconsider = 1; /* More may be referenced; check again */
3059 saved_inlines = tree_cons (NULL_TREE, NULL_TREE, saved_inlines);
3063 tree last = saved_inlines;
3064 tree place = TREE_CHAIN (saved_inlines);
3067 for (; place; place = TREE_CHAIN (place))
3069 tree decl = TREE_VALUE (place);
3071 if (TREE_ASM_WRITTEN (decl) || DECL_SAVED_INSNS (decl) == 0)
3073 TREE_CHAIN (last) = TREE_CHAIN (place);
3076 import_export_inline (decl);
3077 if (TREE_PUBLIC (decl)
3078 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3079 || flag_keep_inline_functions)
3081 TREE_CHAIN (last) = TREE_CHAIN (place);
3083 if (DECL_EXTERNAL (decl))
3084 assemble_external (decl);
3088 temporary_allocation ();
3089 output_inline_function (decl);
3090 permanent_allocation (1);
3101 if (write_virtuals == 2)
3103 /* Now complain about an virtual function tables promised
3104 but not delivered. */
3105 while (pending_vtables)
3107 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3108 error ("virtual function table for `%s' not defined",
3109 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3110 pending_vtables = TREE_CHAIN (pending_vtables);
3114 permanent_allocation (1);
3115 this_time = get_run_time ();
3116 parse_time -= this_time - start_time;
3117 varconst_time += this_time - start_time;
3119 if (flag_detailed_statistics)
3120 dump_time_statistics ();
3123 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3124 expr. Since it was parsed like a type, we need to wade through and fix
3125 that. Unfortunately, since operator() is left-associative, we can't use
3126 tail recursion. In the above example, TYPE is `A', and DECL is
3129 Maybe this shouldn't be recursive, but how often will it actually be
3132 reparse_absdcl_as_expr (type, decl)
3135 /* do build_functional_cast (type, NULL_TREE) at bottom */
3136 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3137 return build_functional_cast (type, NULL_TREE);
3140 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3142 decl = build_x_function_call (decl, NULL_TREE, current_class_decl);
3144 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3145 decl = require_complete_type (decl);
3150 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3151 out to be an expr. Since it was parsed like a type, we need to wade
3152 through and fix that. Since casts are right-associative, we are
3153 reversing the order, so we don't have to recurse.
3155 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3158 reparse_absdcl_as_casts (decl, expr)
3163 if (TREE_CODE (expr) == CONSTRUCTOR)
3165 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3166 decl = TREE_OPERAND (decl, 0);
3168 if (IS_SIGNATURE (type))
3170 error ("cast specifies signature type");
3171 return error_mark_node;
3174 expr = digest_init (type, expr, (tree *) 0);
3175 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3177 int failure = complete_array_type (type, expr, 1);
3179 my_friendly_abort (78);
3185 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3186 decl = TREE_OPERAND (decl, 0);
3187 expr = build_c_cast (type, expr, 0);
3193 /* Recursive helper function for reparse_decl_as_expr. It may be a good
3194 idea to reimplement this using an explicit stack, rather than recursion. */
3196 reparse_decl_as_expr1 (decl)
3199 switch (TREE_CODE (decl))
3201 case IDENTIFIER_NODE:
3202 return do_identifier (decl);
3204 return build_x_indirect_ref
3205 (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)), "unary *");
3207 return build_x_unary_op (ADDR_EXPR,
3208 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3210 return build_x_unary_op (BIT_NOT_EXPR,
3211 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3213 return build_offset_ref (TREE_OPERAND (decl, 0), TREE_OPERAND (decl, 1));
3215 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)),
3216 TREE_OPERAND (decl, 1));
3218 my_friendly_abort (5);
3223 /* This is something of the form `int (*a)++' that has turned out to be an
3224 expr. It was only converted into parse nodes, so we need to go through
3225 and build up the semantics. Most of the work is done by
3226 reparse_decl_as_expr1, above.
3228 In the above example, TYPE is `int' and DECL is `*a'. */
3230 reparse_decl_as_expr (type, decl)
3233 decl = build_tree_list (NULL_TREE, reparse_decl_as_expr1 (decl));
3234 return build_functional_cast (type, decl);
3237 /* This is something of the form `int (*a)' that has turned out to be a
3238 decl. It was only converted into parse nodes, so we need to do the
3239 checking that make_{pointer,reference}_declarator do. */
3242 finish_decl_parsing (decl)
3245 extern int current_class_depth;
3247 switch (TREE_CODE (decl))
3249 case IDENTIFIER_NODE:
3252 return make_pointer_declarator
3253 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3255 return make_reference_declarator
3256 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3258 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3261 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3262 TREE_COMPLEXITY (decl) = current_class_depth;
3265 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3268 my_friendly_abort (5);
3274 check_cp_case_value (value)
3277 if (value == NULL_TREE)
3280 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3281 Strip such NOP_EXPRs. */
3282 if (TREE_CODE (value) == NOP_EXPR
3283 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3284 value = TREE_OPERAND (value, 0);
3286 if (TREE_READONLY_DECL_P (value))
3288 value = decl_constant_value (value);
3289 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3290 Strip such NOP_EXPRs. */
3291 if (TREE_CODE (value) == NOP_EXPR
3292 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3293 value = TREE_OPERAND (value, 0);
3295 value = fold (value);
3297 if (TREE_CODE (value) != INTEGER_CST
3298 && value != error_mark_node)
3300 cp_error ("case label `%E' does not reduce to an integer constant",
3302 value = error_mark_node;
3305 /* Promote char or short to int. */
3306 value = default_conversion (value);
3308 constant_expression_warning (value);
3313 static tree current_namespace;
3315 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3316 postfix. Returns 0 if in global namespace. */
3320 tree x = current_namespace;
3322 x = TREE_PURPOSE (x);
3326 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3328 current_namespace_id (name)
3331 tree old_id = get_namespace_id ();
3334 /* Global names retain old encoding. */
3338 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3339 + IDENTIFIER_LENGTH (name));
3340 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3341 IDENTIFIER_POINTER (name));
3342 return get_identifier (buf);
3345 /* Push into the scopre of the NAME namespace. */
3347 push_namespace (name)
3350 tree old_id = get_namespace_id ();
3353 current_namespace = tree_cons (NULL_TREE, name, current_namespace);
3354 buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0)
3355 + IDENTIFIER_LENGTH (name));
3356 sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "",
3357 IDENTIFIER_POINTER (name));
3358 TREE_PURPOSE (current_namespace) = get_identifier (buf);
3361 /* Pop from the scope of the current namespace. */
3365 current_namespace = TREE_CHAIN (current_namespace);
3369 do_namespace_alias (alias, namespace)
3370 tree alias, namespace;
3375 do_using_decl (decl)
3378 return error_mark_node;
3382 do_using_directive (namespace)