1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Process declarations and symbol lookup for C front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
40 extern tree get_file_function_name ();
41 extern tree cleanups_this_call;
42 static void grok_function_init ();
44 /* A list of virtual function tables we must make sure to write out. */
47 /* A list of static class variables. This is needed, because a
48 static class variable can be declared inside the class without
49 an initializer, and then initialized, staticly, outside the class. */
52 /* A list of functions which were declared inline, but which we
53 may need to emit outline anyway. */
54 static tree saved_inlines;
56 /* Used to help generate temporary names which are unique within
57 a function. Reset to 0 by start_function. */
59 int temp_name_counter;
61 /* Same, but not reset. Local temp variables and global temp variables
62 can have the same name. */
63 static int global_temp_name_counter;
65 /* Flag used when debugging spew.c */
67 extern int spew_debug;
69 /* Functions called along with real static constructors and destructors. */
71 tree static_ctors, static_dtors;
73 /* C (and C++) language-specific option variables. */
75 /* Nonzero means allow type mismatches in conditional expressions;
76 just make their values `void'. */
78 int flag_cond_mismatch;
80 /* Nonzero means give `double' the same size as `float'. */
82 int flag_short_double;
84 /* Nonzero means don't recognize the keyword `asm'. */
88 /* Nonzero means don't recognize any extension keywords. */
90 int flag_no_gnu_keywords;
92 /* Nonzero means don't recognize the non-ANSI builtin functions. */
96 /* Nonzero means don't recognize the non-ANSI builtin functions.
99 int flag_no_nonansi_builtin;
101 /* Nonzero means do some things the same way PCC does. */
103 int flag_traditional;
105 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
107 int flag_signed_bitfields = 1;
109 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
113 /* Nonzero means enable obscure ANSI features and disable GNU extensions
114 that might cause ANSI-compliant code to be miscompiled. */
118 /* Nonzero means do emit exported implementations of functions even if
119 they can be inlined. */
121 int flag_implement_inlines = 1;
123 /* Nonzero means do emit exported implementations of templates, instead of
124 multiple static copies in each file that needs a definition. */
126 int flag_external_templates;
128 /* Nonzero means that the decision to emit or not emit the implementation of a
129 template depends on where the template is instantiated, rather than where
132 int flag_alt_external_templates;
134 /* Nonzero means that implicit instantiations will be emitted if needed. */
136 int flag_implicit_templates = 1;
138 /* Nonzero means warn about implicit declarations. */
140 int warn_implicit = 1;
142 /* Nonzero means warn when all ctors or dtors are private, and the class
145 int warn_ctor_dtor_privacy = 1;
147 /* True if we want to implement vtbvales using "thunks".
148 The default is off now, but will be on later. */
150 int flag_vtable_thunks;
152 /* True if we want to deal with repository information. */
154 int flag_use_repository;
156 /* Nonzero means give string constants the type `const char *'
157 to get extra warnings from them. These warnings will be too numerous
158 to be useful, except in thoroughly ANSIfied programs. */
160 int warn_write_strings;
162 /* Nonzero means warn about pointer casts that can drop a type qualifier
163 from the pointer target type. */
167 /* Nonzero means warn that dbx info for template class methods isn't fully
170 int warn_template_debugging;
172 /* Warn about traditional constructs whose meanings changed in ANSI C. */
174 int warn_traditional;
176 /* Nonzero means warn about sizeof(function) or addition/subtraction
177 of function pointers. */
179 int warn_pointer_arith;
181 /* Nonzero means warn for non-prototype function decls
182 or non-prototyped defs without previous prototype. */
184 int warn_strict_prototypes;
186 /* Nonzero means warn for any function def without prototype decl. */
188 int warn_missing_prototypes;
190 /* Nonzero means warn about multiple (redundant) decls for the same single
191 variable or function. */
193 int warn_redundant_decls;
195 /* Warn if initializer is not completely bracketed. */
197 int warn_missing_braces;
199 /* Warn about *printf or *scanf format/argument anomalies. */
203 /* Warn about a subscript that has type char. */
205 int warn_char_subscripts;
207 /* Warn if a type conversion is done that might have confusing results. */
211 /* Warn if adding () is suggested. */
213 int warn_parentheses;
215 /* Non-zero means warn in function declared in derived class has the
216 same name as a virtual in the base class, but fails to match the
217 type signature of any virtual function in the base class. */
218 int warn_overloaded_virtual;
220 /* Non-zero means warn when declaring a class that has a non virtual
221 destructor, when it really ought to have a virtual one. */
224 /* Non-zero means warn when a function is declared extern and later inline. */
225 int warn_extern_inline;
227 /* Non-zero means warn when the compiler will reorder code. */
230 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
233 /* Nonzero means `$' can be in an identifier.
234 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
236 #ifndef DOLLARS_IN_IDENTIFIERS
237 #define DOLLARS_IN_IDENTIFIERS 1
239 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
241 /* Nonzero for -fno-strict-prototype switch: do not consider empty
242 argument prototype to mean function takes no arguments. */
244 int flag_strict_prototype = 2;
245 int strict_prototype = 1;
246 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
248 /* Nonzero means that labels can be used as first-class objects */
252 /* Non-zero means to collect statistics which might be expensive
253 and to print them when we are done. */
254 int flag_detailed_statistics;
256 /* C++ specific flags. */
257 /* Nonzero for -fall-virtual: make every member function (except
258 constructors) lay down in the virtual function table. Calls
259 can then either go through the virtual function table or not,
262 int flag_all_virtual;
264 /* Zero means that `this' is a *const. This gives nice behavior in the
265 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
266 -2 means we're constructing an object and it has fixed type. */
268 int flag_this_is_variable;
270 /* Nonzero means memoize our member lookups. */
272 int flag_memoize_lookups; int flag_save_memoized_contexts;
274 /* 3 means write out only virtuals function tables `defined'
275 in this implementation file.
276 2 means write out only specific virtual function tables
277 and give them (C) public access.
278 1 means write out virtual function tables and give them
280 0 means write out virtual function tables and give them
281 (C) static access (default).
282 -1 means declare virtual function tables extern. */
286 /* Nonzero means we should attempt to elide constructors when possible. */
288 int flag_elide_constructors;
290 /* Nonzero means recognize and handle exception handling constructs.
291 Use ansi syntax and semantics. WORK IN PROGRESS! */
293 int flag_handle_exceptions;
295 /* Nonzero means recognize and handle signature language constructs. */
297 int flag_handle_signatures;
299 /* Nonzero means that member functions defined in class scope are
300 inline by default. */
302 int flag_default_inline = 1;
304 /* Controls whether enums and ints freely convert.
305 1 means with complete freedom.
306 0 means enums can convert to ints, but not vice-versa. */
307 int flag_int_enum_equivalence;
309 /* Controls whether compiler is operating under LUCID's Cadillac
310 system. 1 means yes, 0 means no. */
313 /* Controls whether compiler generates code to build objects
314 that can be collected when they become garbage. */
317 /* Controls whether compiler generates 'type descriptor' that give
318 run-time type information. */
321 /* Nonzero if we wish to output cross-referencing information
322 for the GNU class browser. */
323 extern int flag_gnu_xref;
325 /* Nonzero if compiler can make `reasonable' assumptions about
326 references and objects. For example, the compiler must be
327 conservative about the following and not assume that `a' is nonnull:
332 In general, it is `reasonable' to assume that for many programs,
333 and better code can be generated in that case. */
335 int flag_assume_nonnull_objects = 1;
337 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
340 int flag_huge_objects;
342 /* Nonzero if we want to conserve space in the .o files. We do this
343 by putting uninitialized data and runtime initialized data into
344 .common instead of .data at the expense of not flagging multiple
347 int flag_conserve_space;
349 /* Nonzero if we want to obey access control semantics. */
351 int flag_access_control = 1;
353 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
355 int flag_operator_names;
357 /* Nonzero if we want to check the return value of new and avoid calling
358 constructors if it is a null pointer. */
362 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
363 initialization variables.
364 0: Old rules, set by -fno-for-scope.
365 2: New ANSI rules, set by -ffor-scope.
366 1: Try to implement new ANSI rules, but with backup compatibility
367 (and warnings). This is the default, for now. */
369 int flag_new_for_scope = 1;
371 /* Nonzero if we want to emit defined symbols with common-like linkage as
372 weak symbols where possible, in order to conform to C++ semantics.
373 Otherwise, emit them as local symbols. */
377 /* Table of language-dependent -f options.
378 STRING is the option name. VARIABLE is the address of the variable.
379 ON_VALUE is the value to store in VARIABLE
380 if `-fSTRING' is seen as an option.
381 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
383 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
385 {"signed-char", &flag_signed_char, 1},
386 {"unsigned-char", &flag_signed_char, 0},
387 {"signed-bitfields", &flag_signed_bitfields, 1},
388 {"unsigned-bitfields", &flag_signed_bitfields, 0},
389 {"short-enums", &flag_short_enums, 1},
390 {"short-double", &flag_short_double, 1},
391 {"cond-mismatch", &flag_cond_mismatch, 1},
392 {"asm", &flag_no_asm, 0},
393 {"builtin", &flag_no_builtin, 0},
394 {"ident", &flag_no_ident, 0},
395 {"labels-ok", &flag_labels_ok, 1},
396 {"stats", &flag_detailed_statistics, 1},
397 {"this-is-variable", &flag_this_is_variable, 1},
398 {"strict-prototype", &flag_strict_prototype, 1},
399 {"all-virtual", &flag_all_virtual, 1},
400 {"memoize-lookups", &flag_memoize_lookups, 1},
401 {"elide-constructors", &flag_elide_constructors, 1},
402 {"handle-exceptions", &flag_handle_exceptions, 1},
403 {"handle-signatures", &flag_handle_signatures, 1},
404 {"default-inline", &flag_default_inline, 1},
405 {"dollars-in-identifiers", &dollars_in_ident, 1},
406 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
408 {"rtti", &flag_rtti, 1},
409 {"xref", &flag_gnu_xref, 1},
410 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
411 {"implement-inlines", &flag_implement_inlines, 1},
412 {"external-templates", &flag_external_templates, 1},
413 {"implicit-templates", &flag_implicit_templates, 1},
414 {"huge-objects", &flag_huge_objects, 1},
415 {"conserve-space", &flag_conserve_space, 1},
416 {"vtable-thunks", &flag_vtable_thunks, 1},
417 {"short-temps", &flag_short_temps, 1},
418 {"access-control", &flag_access_control, 1},
419 {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
420 {"gnu-keywords", &flag_no_gnu_keywords, 0},
421 {"operator-names", &flag_operator_names, 1},
422 {"check-new", &flag_check_new, 1},
423 {"repo", &flag_use_repository, 1},
424 {"for-scope", &flag_new_for_scope, 2},
425 {"weak", &flag_weak, 1}
428 /* Decode the string P as a language-specific option.
429 Return 1 if it is recognized (and handle it);
430 return 0 if not recognized. */
433 lang_decode_option (p)
436 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
437 flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
438 flag_this_is_variable = 1, flag_new_for_scope = 0;
439 /* The +e options are for cfront compatibility. They come in as
440 `-+eN', to kludge around gcc.c's argument handling. */
441 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
443 int old_write_virtuals = write_virtuals;
446 else if (p[3] == '0')
448 else if (p[3] == '2')
450 else error ("invalid +e option");
451 if (old_write_virtuals != 0
452 && write_virtuals != old_write_virtuals)
453 error ("conflicting +e options given");
455 else if (p[0] == '-' && p[1] == 'f')
457 /* Some kind of -f option.
458 P's value is the option sans `-f'.
459 Search for it in the table of options. */
463 /* Try special -f options. */
465 if (!strcmp (p, "save-memoized"))
467 flag_memoize_lookups = 1;
468 flag_save_memoized_contexts = 1;
471 if (!strcmp (p, "no-save-memoized"))
473 flag_memoize_lookups = 0;
474 flag_save_memoized_contexts = 0;
477 else if (! strncmp (p, "cadillac", 8))
479 flag_cadillac = atoi (p+9);
482 else if (! strncmp (p, "no-cadillac", 11))
487 else if (! strcmp (p, "gc"))
490 /* This must come along for the ride. */
494 else if (! strcmp (p, "no-gc"))
497 /* This must come along for the ride. */
501 else if (! strcmp (p, "alt-external-templates"))
503 flag_external_templates = 1;
504 flag_alt_external_templates = 1;
507 else if (! strcmp (p, "no-alt-external-templates"))
509 flag_alt_external_templates = 0;
512 else if (!strcmp (p, "ansi-overloading"))
514 warning ("-fansi-overloading is no longer meaningful");
517 else if (!strcmp (p, "repo"))
519 flag_use_repository = 1;
520 flag_implicit_templates = 0;
524 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
527 if (!strcmp (p, lang_f_options[j].string))
529 *lang_f_options[j].variable = lang_f_options[j].on_value;
530 /* A goto here would be cleaner,
531 but breaks the vax pcc. */
534 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
535 && ! strcmp (p+3, lang_f_options[j].string))
537 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
543 else if (p[0] == '-' && p[1] == 'W')
547 /* The -W options control the warning behavior of the compiler. */
550 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
553 if (!strcmp (p, "implicit"))
554 warn_implicit = setting;
555 else if (!strcmp (p, "return-type"))
556 warn_return_type = setting;
557 else if (!strcmp (p, "ctor-dtor-privacy"))
558 warn_ctor_dtor_privacy = setting;
559 else if (!strcmp (p, "write-strings"))
560 warn_write_strings = setting;
561 else if (!strcmp (p, "cast-qual"))
562 warn_cast_qual = setting;
563 else if (!strcmp (p, "traditional"))
564 warn_traditional = setting;
565 else if (!strcmp (p, "char-subscripts"))
566 warn_char_subscripts = setting;
567 else if (!strcmp (p, "pointer-arith"))
568 warn_pointer_arith = setting;
569 else if (!strcmp (p, "strict-prototypes"))
570 warn_strict_prototypes = setting;
571 else if (!strcmp (p, "missing-prototypes"))
572 warn_missing_prototypes = setting;
573 else if (!strcmp (p, "redundant-decls"))
574 warn_redundant_decls = setting;
575 else if (!strcmp (p, "missing-braces"))
576 warn_missing_braces = setting;
577 else if (!strcmp (p, "format"))
578 warn_format = setting;
579 else if (!strcmp (p, "conversion"))
580 warn_conversion = setting;
581 else if (!strcmp (p, "parentheses"))
582 warn_parentheses = setting;
583 else if (!strcmp (p, "non-virtual-dtor"))
584 warn_nonvdtor = setting;
585 else if (!strcmp (p, "extern-inline"))
586 warn_extern_inline = setting;
587 else if (!strcmp (p, "reorder"))
588 warn_reorder = setting;
589 else if (!strcmp (p, "synth"))
590 warn_synth = setting;
591 else if (!strcmp (p, "comment"))
592 ; /* cpp handles this one. */
593 else if (!strcmp (p, "comments"))
594 ; /* cpp handles this one. */
595 else if (!strcmp (p, "trigraphs"))
596 ; /* cpp handles this one. */
597 else if (!strcmp (p, "import"))
598 ; /* cpp handles this one. */
599 else if (!strcmp (p, "all"))
601 extra_warnings = setting;
602 warn_return_type = setting;
603 warn_unused = setting;
604 warn_implicit = setting;
605 warn_ctor_dtor_privacy = setting;
606 warn_switch = setting;
607 warn_format = setting;
608 warn_parentheses = setting;
609 warn_missing_braces = setting;
610 warn_extern_inline = setting;
611 warn_nonvdtor = setting;
612 /* We save the value of warn_uninitialized, since if they put
613 -Wuninitialized on the command line, we need to generate a
614 warning about not using it without also specifying -O. */
615 if (warn_uninitialized != 1)
616 warn_uninitialized = (setting ? 2 : 0);
617 warn_template_debugging = setting;
618 warn_reorder = setting;
621 else if (!strcmp (p, "overloaded-virtual"))
622 warn_overloaded_virtual = setting;
625 else if (!strcmp (p, "-ansi"))
626 dollars_in_ident = 0, flag_no_nonansi_builtin = 1, flag_ansi = 1,
627 flag_no_gnu_keywords = 1, flag_operator_names = 1;
629 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
630 it's probably safe to assume no sane person would ever want to use this
631 under normal circumstances. */
632 else if (!strcmp (p, "-spew-debug"))
641 /* Incorporate `const' and `volatile' qualifiers for member functions.
642 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
643 QUALS is a list of qualifiers. */
645 grok_method_quals (ctype, function, quals)
646 tree ctype, function, quals;
648 tree fntype = TREE_TYPE (function);
649 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
653 extern tree ridpointers[];
655 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
657 if (TYPE_READONLY (ctype))
658 error ("duplicate `%s' %s",
659 IDENTIFIER_POINTER (TREE_VALUE (quals)),
660 (TREE_CODE (function) == FUNCTION_DECL
661 ? "for member function" : "in type declaration"));
662 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
663 build_pointer_type (ctype);
665 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
667 if (TYPE_VOLATILE (ctype))
668 error ("duplicate `%s' %s",
669 IDENTIFIER_POINTER (TREE_VALUE (quals)),
670 (TREE_CODE (function) == FUNCTION_DECL
671 ? "for member function" : "in type declaration"));
672 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
673 build_pointer_type (ctype);
676 my_friendly_abort (20);
677 quals = TREE_CHAIN (quals);
680 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
681 (TREE_CODE (fntype) == METHOD_TYPE
682 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
683 : TYPE_ARG_TYPES (fntype)));
685 fntype = build_exception_variant (fntype, raises);
687 TREE_TYPE (function) = fntype;
691 #if 0 /* Not used. */
692 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
693 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
694 /* This does not yet work with user defined conversion operators
697 substitute_nice_name (decl)
700 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
702 char *n = decl_as_string (DECL_NAME (decl), 1);
703 if (n[strlen (n) - 1] == ' ')
704 n[strlen (n) - 1] = 0;
705 DECL_NAME (decl) = get_identifier (n);
710 /* Warn when -fexternal-templates is used and #pragma
711 interface/implementation is not used all the times it should be,
714 warn_if_unknown_interface (decl)
717 static int already_warned = 0;
718 if (already_warned++)
721 if (flag_alt_external_templates)
723 struct tinst_level *til = tinst_for_decl ();
725 char *sf = input_filename;
730 input_filename = til->file;
732 cp_warning ("template `%#D' instantiated in file without #pragma interface",
738 cp_warning_at ("template `%#D' defined in file without #pragma interface",
742 /* A subroutine of the parser, to handle a component list. */
744 grok_x_components (specs, components)
745 tree specs, components;
747 register tree t, x, tcode;
749 /* We just got some friends. They have been recorded elsewhere. */
750 if (components == void_type_node)
753 if (components == NULL_TREE)
755 t = groktypename (build_decl_list (specs, NULL_TREE));
759 error ("error in component specification");
763 switch (TREE_CODE (t))
766 /* Static anonymous unions come out as VAR_DECLs. */
767 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
768 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
771 /* We return SPECS here, because in the parser it was ending
772 up with not doing anything to $$, which is what SPECS
778 /* This code may be needed for UNION_TYPEs as
780 tcode = record_type_node;
781 if (CLASSTYPE_DECLARED_CLASS(t))
782 tcode = class_type_node;
783 else if (IS_SIGNATURE(t))
784 tcode = signature_type_node;
786 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
788 CLASSTYPE_NO_GLOBALIZE(t) = 1;
794 if (TREE_CODE(t) == UNION_TYPE)
795 tcode = union_type_node;
797 tcode = enum_type_node;
799 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
800 if (TREE_CODE(t) == UNION_TYPE && TYPE_CONTEXT(t))
801 CLASSTYPE_NO_GLOBALIZE(t) = 1;
802 if (TREE_CODE (t) == UNION_TYPE
803 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
805 struct pending_inline **p;
806 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
808 /* Wipe out memory of synthesized methods */
809 TYPE_HAS_CONSTRUCTOR (t) = 0;
810 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
811 TYPE_HAS_INIT_REF (t) = 0;
812 TYPE_HAS_CONST_INIT_REF (t) = 0;
813 TYPE_HAS_ASSIGN_REF (t) = 0;
814 TYPE_HAS_ASSIGNMENT (t) = 0;
815 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
817 p = &pending_inlines;
818 for (; *p; *p = (*p)->next)
819 if (DECL_CONTEXT ((*p)->fndecl) != t)
822 else if (TREE_CODE (t) == ENUMERAL_TYPE)
823 x = grok_enum_decls (t, NULL_TREE);
830 if (t != void_type_node)
831 error ("empty component declaration");
837 t = TREE_TYPE (components);
838 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
839 return grok_enum_decls (t, components);
845 /* Classes overload their constituent function names automatically.
846 When a function name is declared in a record structure,
847 its name is changed to it overloaded name. Since names for
848 constructors and destructors can conflict, we place a leading
851 CNAME is the name of the class we are grokking for.
853 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
855 FLAGS contains bits saying what's special about today's
856 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
858 If FUNCTION is a destructor, then we must add the `auto-delete' field
859 as a second parameter. There is some hair associated with the fact
860 that we must "declare" this variable in the manner consistent with the
861 way the rest of the arguments were declared.
863 QUALS are the qualifiers for the this pointer. */
866 grokclassfn (ctype, cname, function, flags, quals)
867 tree ctype, cname, function;
868 enum overload_flags flags;
871 tree fn_name = DECL_NAME (function);
875 tree fntype = TREE_TYPE (function);
876 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
878 if (fn_name == NULL_TREE)
880 error ("name missing for member function");
881 fn_name = get_identifier ("<anonymous>");
882 DECL_NAME (function) = fn_name;
886 qualtype = grok_method_quals (ctype, function, quals);
890 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
891 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
893 /* Must add the class instance variable up front. */
894 /* Right now we just make this a pointer. But later
895 we may wish to make it special. */
896 tree type = TREE_VALUE (arg_types);
899 if ((flag_this_is_variable > 0)
900 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
903 if (DECL_CONSTRUCTOR_P (function))
905 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
907 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
908 /* In this case we need "in-charge" flag saying whether
909 this constructor is responsible for initialization
910 of virtual baseclasses or not. */
911 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
912 /* Mark the artificial `__in_chrg' parameter as "artificial". */
913 SET_DECL_ARTIFICIAL (parm);
914 DECL_ARG_TYPE (parm) = integer_type_node;
915 TREE_READONLY (parm) = 1;
916 TREE_CHAIN (parm) = last_function_parms;
917 last_function_parms = parm;
921 parm = build_decl (PARM_DECL, this_identifier, type);
922 /* Mark the artificial `this' parameter as "artificial". */
923 SET_DECL_ARTIFICIAL (parm);
924 DECL_ARG_TYPE (parm) = type;
925 /* We can make this a register, so long as we don't
926 accidentally complain if someone tries to take its address. */
927 DECL_REGISTER (parm) = 1;
929 TREE_READONLY (parm) = 1;
930 TREE_CHAIN (parm) = last_function_parms;
931 last_function_parms = parm;
934 if (flags == DTOR_FLAG)
937 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
938 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
940 arg_types = hash_tree_chain (const_integer_type, void_list_node);
941 TREE_SIDE_EFFECTS (arg_types) = 1;
942 /* Build the overload name. It will look like `7Example'. */
943 if (IDENTIFIER_TYPE_VALUE (cname))
944 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
945 else if (IDENTIFIER_LOCAL_VALUE (cname))
946 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
948 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
949 it's defined out of the class definition, since poplevel_class wipes
950 it out. This used to be internal error 346. */
951 dbuf = build_overload_name (ctype, 1, 1);
952 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
953 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
956 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
957 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
958 /* Mark the artificial `__in_chrg' parameter as "artificial". */
959 SET_DECL_ARTIFICIAL (parm);
960 TREE_READONLY (parm) = 1;
961 DECL_ARG_TYPE (parm) = integer_type_node;
962 /* This is the same chain as DECL_ARGUMENTS (...). */
963 TREE_CHAIN (last_function_parms) = parm;
965 fntype = build_cplus_method_type (qualtype, void_type_node,
969 fntype = build_exception_variant (fntype, raises);
971 TREE_TYPE (function) = fntype;
972 TYPE_HAS_DESTRUCTOR (ctype) = 1;
976 tree these_arg_types;
978 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
980 arg_types = hash_tree_chain (integer_type_node,
981 TREE_CHAIN (arg_types));
982 fntype = build_cplus_method_type (qualtype,
983 TREE_TYPE (TREE_TYPE (function)),
987 fntype = build_exception_variant (fntype, raises);
989 TREE_TYPE (function) = fntype;
990 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
993 these_arg_types = arg_types;
995 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
996 /* Only true for static member functions. */
997 these_arg_types = hash_tree_chain (build_pointer_type (qualtype),
1000 DECL_ASSEMBLER_NAME (function)
1001 = build_decl_overload (fn_name, these_arg_types,
1002 1 + DECL_CONSTRUCTOR_P (function));
1005 /* This code is going into the compiler, but currently, it makes
1006 libg++/src/Integer.cc not compile. The problem is that the nice name
1007 winds up going into the symbol table, and conversion operations look
1008 for the manged name. */
1009 substitute_nice_name (function);
1013 DECL_ARGUMENTS (function) = last_function_parms;
1014 /* First approximations. */
1015 DECL_CONTEXT (function) = ctype;
1016 DECL_CLASS_CONTEXT (function) = ctype;
1019 /* Work on the expr used by alignof (this is only called by the parser). */
1027 if (TREE_CODE (expr) == COMPONENT_REF
1028 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
1029 error ("`__alignof__' applied to a bit-field");
1031 if (TREE_CODE (expr) == INDIRECT_REF)
1033 best = t = TREE_OPERAND (expr, 0);
1034 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1036 while (TREE_CODE (t) == NOP_EXPR
1037 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1040 t = TREE_OPERAND (t, 0);
1041 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1042 if (thisalign > bestalign)
1043 best = t, bestalign = thisalign;
1045 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1049 /* ANSI says arrays and fns are converted inside comma.
1050 But we can't convert them in build_compound_expr
1051 because that would break commas in lvalues.
1052 So do the conversion here if operand was a comma. */
1053 if (TREE_CODE (expr) == COMPOUND_EXPR
1054 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1055 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1056 expr = default_conversion (expr);
1057 return c_alignof (TREE_TYPE (expr));
1061 /* Create an ARRAY_REF, checking for the user doing things backwards
1064 grok_array_decl (array_expr, index_exp)
1065 tree array_expr, index_exp;
1067 tree type = TREE_TYPE (array_expr);
1068 tree p1, p2, i1, i2;
1070 if (type == error_mark_node || index_exp == error_mark_node)
1071 return error_mark_node;
1072 if (type == NULL_TREE)
1074 /* Something has gone very wrong. Assume we are mistakenly reducing
1075 an expression instead of a declaration. */
1076 error ("parser may be lost: is there a '{' missing somewhere?");
1080 if (TREE_CODE (type) == OFFSET_TYPE
1081 || TREE_CODE (type) == REFERENCE_TYPE)
1082 type = TREE_TYPE (type);
1084 /* If they have an `operator[]', use that. */
1085 if (TYPE_LANG_SPECIFIC (type)
1086 && TYPE_OVERLOADS_ARRAY_REF (type))
1087 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1088 array_expr, index_exp, NULL_TREE);
1090 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1092 if (TREE_CODE (type) == ARRAY_TYPE)
1095 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1097 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1100 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1102 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1103 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1105 if ((p1 && i2) && (i1 && p2))
1106 error ("ambiguous conversion for array subscript");
1109 array_expr = p1, index_exp = i2;
1111 array_expr = p2, index_exp = i1;
1114 cp_error ("invalid types `%T[%T]' for array subscript",
1115 type, TREE_TYPE (index_exp));
1116 return error_mark_node;
1119 if (array_expr == error_mark_node || index_exp == error_mark_node)
1120 error ("ambiguous conversion for array subscript");
1122 return build_array_ref (array_expr, index_exp);
1125 /* Given the cast expression EXP, checking out its validity. Either return
1126 an error_mark_node if there was an unavoidable error, return a cast to
1127 void for trying to delete a pointer w/ the value 0, or return the
1128 call to delete. If DOING_VEC is 1, we handle things differently
1129 for doing an array delete. If DOING_VEC is 2, they gave us the
1130 array size as an argument to delete.
1131 Implements ARM $5.3.4. This is called from the parser. */
1133 delete_sanity (exp, size, doing_vec, use_global_delete)
1135 int doing_vec, use_global_delete;
1137 tree t = stabilize_reference (convert_from_reference (exp));
1138 tree type = TREE_TYPE (t);
1139 enum tree_code code = TREE_CODE (type);
1140 /* For a regular vector delete (aka, no size argument) we will pass
1141 this down as a NULL_TREE into build_vec_delete. */
1142 tree maxindex = NULL_TREE;
1143 /* This is used for deleting arrays. */
1149 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1150 if (! flag_traditional)
1151 pedwarn ("anachronistic use of array size in vector delete");
1154 elt_size = c_sizeof (type);
1157 if (code != POINTER_TYPE)
1159 cp_error ("type `%#T' argument given to `delete', expected pointer",
1161 return error_mark_node;
1164 /* Deleting a pointer with the value zero is valid and has no effect. */
1165 if (integer_zerop (t))
1166 return build1 (NOP_EXPR, void_type_node, t);
1169 if (code == POINTER_TYPE)
1172 /* As of Valley Forge, you can delete a pointer to constant. */
1173 /* You can't delete a pointer to constant. */
1174 if (TREE_READONLY (TREE_TYPE (type)))
1176 error ("`const *' cannot be deleted");
1177 return error_mark_node;
1180 /* You also can't delete functions. */
1181 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1183 error ("cannot delete a function");
1184 return error_mark_node;
1189 /* If the type has no destructor, then we should build a regular
1190 delete, instead of a vector delete. Otherwise, we would end
1191 up passing a bogus offset into __builtin_delete, which is
1192 not expecting it. */
1194 && TREE_CODE (type) == POINTER_TYPE
1195 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1198 use_global_delete = 1;
1203 return build_vec_delete (t, maxindex, elt_size, integer_one_node,
1204 integer_two_node, use_global_delete);
1207 if (IS_AGGR_TYPE (TREE_TYPE (type))
1208 && TYPE_GETS_REG_DELETE (TREE_TYPE (type)))
1210 /* Only do access checking here; we'll be calling op delete
1211 from the destructor. */
1212 tree tmp = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, t,
1213 size_zero_node, NULL_TREE);
1214 if (tmp == error_mark_node)
1215 return error_mark_node;
1218 return build_delete (type, t, integer_three_node,
1219 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
1224 /* Sanity check: report error if this function FUNCTION is not
1225 really a member of the class (CTYPE) it is supposed to belong to.
1226 CNAME is the same here as it is for grokclassfn above. */
1229 check_classfn (ctype, cname, function)
1230 tree ctype, cname, function;
1232 tree fn_name = DECL_NAME (function);
1234 tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
1238 if (method_vec != 0)
1240 methods = &TREE_VEC_ELT (method_vec, 0);
1241 end = TREE_VEC_END (method_vec);
1243 /* First suss out ctors and dtors. */
1244 if (*methods && fn_name == DECL_NAME (*methods))
1247 while (++methods != end)
1249 if (fn_name == DECL_NAME (*methods))
1255 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1258 /* This should work, but causes libg++ to fail
1260 /* We have to do more extensive argument checking here, as
1261 the name may have been changed by asm("new_name"). */
1262 if (decls_match (function, fndecl))
1265 if (DECL_NAME (function) == DECL_NAME (fndecl))
1267 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1268 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1270 /* Get rid of the this parameter on functions that become
1272 if (DECL_STATIC_FUNCTION_P (fndecl)
1273 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1274 p1 = TREE_CHAIN (p1);
1276 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1277 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1278 && compparms (p1, p2, 3))
1280 if (DECL_STATIC_FUNCTION_P (fndecl)
1281 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1282 revert_static_member_fn (&function, NULL, NULL);
1287 fndecl = DECL_CHAIN (fndecl);
1296 tree fndecl = *methods;
1297 cp_error ("prototype for `%#D' does not match any in class `%T'",
1299 cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl) ? "s are" : " is",
1301 while (fndecl = DECL_CHAIN (fndecl), fndecl)
1302 cp_error_at (" %#D", fndecl);
1307 cp_error ("no `%#D' member function declared in class `%T'",
1311 /* If we did not find the method in the class, add it to
1312 avoid spurious errors. */
1313 add_method (ctype, methods, function);
1317 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1318 of a structure component, returning a FIELD_DECL node.
1319 QUALS is a list of type qualifiers for this decl (such as for declaring
1320 const member functions).
1322 This is done during the parsing of the struct declaration.
1323 The FIELD_DECL nodes are chained together and the lot of them
1324 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1328 If class A defines that certain functions in class B are friends, then
1329 the way I have set things up, it is B who is interested in permission
1330 granted by A. However, it is in A's context that these declarations
1331 are parsed. By returning a void_type_node, class A does not attempt
1332 to incorporate the declarations of the friends within its structure.
1334 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1335 CHANGES TO CODE IN `start_method'. */
1338 grokfield (declarator, declspecs, raises, init, asmspec_tree, attrlist)
1339 tree declarator, declspecs, raises, init, asmspec_tree, attrlist;
1341 register tree value;
1343 int flags = LOOKUP_ONLYCONVERTING;
1345 /* Convert () initializers to = initializers. */
1346 if (init == NULL_TREE && declarator != NULL_TREE
1347 && TREE_CODE (declarator) == CALL_EXPR
1348 && TREE_OPERAND (declarator, 0)
1349 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1350 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1351 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1353 init = TREE_OPERAND (declarator, 1);
1354 declarator = TREE_OPERAND (declarator, 0);
1359 && TREE_CODE (init) == TREE_LIST
1360 && TREE_VALUE (init) == error_mark_node
1361 && TREE_CHAIN (init) == NULL_TREE)
1364 value = grokdeclarator (declarator, declspecs, FIELD, init != 0,
1367 return value; /* friend or constructor went bad. */
1369 /* Pass friendly classes back. */
1370 if (TREE_CODE (value) == VOID_TYPE)
1371 return void_type_node;
1373 if (DECL_NAME (value) != NULL_TREE
1374 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1375 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1376 cp_error ("member `%D' conflicts with virtual function table field name", value);
1378 /* Stash away type declarations. */
1379 if (TREE_CODE (value) == TYPE_DECL)
1381 DECL_NONLOCAL (value) = 1;
1382 DECL_CONTEXT (value) = current_class_type;
1383 DECL_CLASS_CONTEXT (value) = current_class_type;
1384 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1386 /* If we declare a typedef name for something that has no name,
1387 the typedef name is used for linkage. See 7.1.3 p4 94/0158. */
1388 if (TYPE_NAME (TREE_TYPE (value))
1389 && TREE_CODE (TYPE_NAME (TREE_TYPE (value))) == TYPE_DECL
1390 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (value))))
1392 TYPE_NAME (TREE_TYPE (value)) = value;
1393 TYPE_STUB_DECL (TREE_TYPE (value)) = value;
1396 pushdecl_class_level (value);
1400 if (IS_SIGNATURE (current_class_type)
1401 && TREE_CODE (value) != FUNCTION_DECL)
1403 error ("field declaration not allowed in signature");
1404 return void_type_node;
1407 if (DECL_IN_AGGR_P (value))
1409 cp_error ("`%D' is already defined in the class %T", value,
1410 DECL_CONTEXT (value));
1411 return void_type_node;
1415 cadillac_start_decl (value);
1418 asmspec = TREE_STRING_POINTER (asmspec_tree);
1422 if (IS_SIGNATURE (current_class_type)
1423 && TREE_CODE (value) == FUNCTION_DECL)
1425 error ("function declarations cannot have initializers in signature");
1428 else if (TREE_CODE (value) == FUNCTION_DECL)
1430 grok_function_init (value, init);
1433 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1434 /* Already complained in grokdeclarator. */
1438 /* We allow initializers to become parameters to base
1440 if (TREE_CODE (init) == TREE_LIST)
1442 if (TREE_CHAIN (init) == NULL_TREE)
1443 init = TREE_VALUE (init);
1445 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1448 if (TREE_CODE (init) == CONST_DECL)
1449 init = DECL_INITIAL (init);
1450 else if (TREE_READONLY_DECL_P (init))
1451 init = decl_constant_value (init);
1452 else if (TREE_CODE (init) == CONSTRUCTOR)
1453 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1454 my_friendly_assert (TREE_PERMANENT (init), 192);
1455 if (init == error_mark_node)
1456 /* We must make this look different than `error_mark_node'
1457 because `decl_const_value' would mis-interpret it
1458 as only meaning that this VAR_DECL is defined. */
1459 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1460 else if (! TREE_CONSTANT (init))
1462 /* We can allow references to things that are effectively
1463 static, since references are initialized with the address. */
1464 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1465 || (TREE_STATIC (init) == 0
1466 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1467 || DECL_EXTERNAL (init) == 0)))
1469 error ("field initializer is not constant");
1470 init = error_mark_node;
1476 /* The corresponding pop_obstacks is in cp_finish_decl. */
1477 push_obstacks_nochange ();
1479 if (TREE_CODE (value) == VAR_DECL)
1481 /* We cannot call pushdecl here, because that would
1482 fill in the value of our TREE_CHAIN. Instead, we
1483 modify cp_finish_decl to do the right thing, namely, to
1484 put this decl out straight away. */
1485 if (TREE_PUBLIC (value))
1487 /* current_class_type can be NULL_TREE in case of error. */
1488 if (asmspec == 0 && current_class_type)
1490 TREE_PUBLIC (value) = 1;
1491 DECL_INITIAL (value) = error_mark_node;
1492 DECL_ASSEMBLER_NAME (value)
1493 = build_static_name (current_class_type, DECL_NAME (value));
1495 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1497 /* Static consts need not be initialized in the class definition. */
1498 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1500 static int explanation = 0;
1502 error ("initializer invalid for static member with constructor");
1503 if (explanation++ == 0)
1504 error ("(you really want to initialize it separately)");
1507 /* Force the compiler to know when an uninitialized static
1508 const member is being used. */
1509 if (TYPE_READONLY (value) && init == 0)
1510 TREE_USED (value) = 1;
1512 DECL_INITIAL (value) = init;
1513 DECL_IN_AGGR_P (value) = 1;
1515 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1516 pushdecl_class_level (value);
1519 if (TREE_CODE (value) == FIELD_DECL)
1523 /* This must override the asm specifier which was placed
1524 by grokclassfn. Lay this out fresh. */
1525 DECL_RTL (value) = NULL_RTX;
1526 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1528 if (DECL_INITIAL (value) == error_mark_node)
1529 init = error_mark_node;
1530 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1531 DECL_INITIAL (value) = init;
1532 DECL_IN_AGGR_P (value) = 1;
1535 if (TREE_CODE (value) == FUNCTION_DECL)
1537 check_default_args (value);
1538 if (DECL_CHAIN (value) != NULL_TREE)
1540 /* Need a fresh node here so that we don't get circularity
1541 when we link these together. */
1542 value = copy_node (value);
1543 /* When does this happen? */
1544 my_friendly_assert (init == NULL_TREE, 193);
1548 /* This must override the asm specifier which was placed
1549 by grokclassfn. Lay this out fresh. */
1550 DECL_RTL (value) = NULL_RTX;
1551 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1553 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1555 /* Pass friends back this way. */
1556 if (DECL_FRIEND_P (value))
1557 return void_type_node;
1559 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1560 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1561 cp_error ("method `%#D' of local class must be defined in class body",
1565 DECL_IN_AGGR_P (value) = 1;
1568 my_friendly_abort (21);
1573 /* Like `grokfield', but for bitfields.
1574 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1577 grokbitfield (declarator, declspecs, width)
1578 tree declarator, declspecs, width;
1580 register tree value = grokdeclarator (declarator, declspecs, BITFIELD,
1581 0, NULL_TREE, NULL_TREE);
1583 if (! value) return NULL_TREE; /* friends went bad. */
1585 /* Pass friendly classes back. */
1586 if (TREE_CODE (value) == VOID_TYPE)
1587 return void_type_node;
1589 if (TREE_CODE (value) == TYPE_DECL)
1591 cp_error ("cannot declare `%D' to be a bitfield type", value);
1595 if (IS_SIGNATURE (current_class_type))
1597 error ("field declaration not allowed in signature");
1598 return void_type_node;
1601 if (DECL_IN_AGGR_P (value))
1603 cp_error ("`%D' is already defined in the class %T", value,
1604 DECL_CONTEXT (value));
1605 return void_type_node;
1608 GNU_xref_member (current_class_name, value);
1610 if (TREE_STATIC (value))
1612 cp_error ("static member `%D' cannot be a bitfield", value);
1615 cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1617 if (width != error_mark_node)
1619 /* detect invalid field size. */
1620 if (TREE_CODE (width) == CONST_DECL)
1621 width = DECL_INITIAL (width);
1622 else if (TREE_READONLY_DECL_P (width))
1623 width = decl_constant_value (width);
1624 if (TREE_CODE (width) != INTEGER_CST)
1626 cp_error ("structure field `%D' width not an integer constant",
1628 DECL_INITIAL (value) = NULL_TREE;
1632 constant_expression_warning (width);
1633 DECL_INITIAL (value) = width;
1634 DECL_BIT_FIELD (value) = 1;
1638 DECL_IN_AGGR_P (value) = 1;
1643 /* Like GROKFIELD, except that the declarator has been
1644 buried in DECLSPECS. Find the declarator, and
1645 return something that looks like it came from
1648 groktypefield (declspecs, parmlist)
1652 tree spec = declspecs;
1653 tree prev = NULL_TREE;
1655 tree type_id = NULL_TREE;
1656 tree quals = NULL_TREE;
1657 tree lengths = NULL_TREE;
1658 tree decl = NULL_TREE;
1662 register tree id = TREE_VALUE (spec);
1664 if (TREE_CODE (spec) != TREE_LIST)
1665 /* Certain parse errors slip through. For example,
1666 `int class ();' is not caught by the parser. Try
1667 weakly to recover here. */
1670 if (TREE_CODE (id) == TYPE_DECL
1671 || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
1673 /* We have a constructor/destructor or
1674 conversion operator. Use it. */
1676 TREE_CHAIN (prev) = TREE_CHAIN (spec);
1678 declspecs = TREE_CHAIN (spec);
1684 spec = TREE_CHAIN (spec);
1687 /* Nope, we have a conversion operator to a scalar type or something
1688 else, that includes things like constructor declarations for
1693 tree id = TREE_VALUE (spec);
1695 if (TREE_CODE (id) == IDENTIFIER_NODE)
1697 if (id == ridpointers[(int)RID_INT]
1698 || id == ridpointers[(int)RID_DOUBLE]
1699 || id == ridpointers[(int)RID_FLOAT]
1700 || id == ridpointers[(int)RID_WCHAR])
1703 error ("extra `%s' ignored",
1704 IDENTIFIER_POINTER (id));
1708 else if (id == ridpointers[(int)RID_LONG]
1709 || id == ridpointers[(int)RID_SHORT]
1710 || id == ridpointers[(int)RID_CHAR])
1712 lengths = tree_cons (NULL_TREE, id, lengths);
1714 else if (id == ridpointers[(int)RID_VOID])
1717 error ("spurious `void' type ignored");
1719 error ("conversion to `void' type invalid");
1721 else if (id == ridpointers[(int)RID_AUTO]
1722 || id == ridpointers[(int)RID_REGISTER]
1723 || id == ridpointers[(int)RID_TYPEDEF]
1724 || id == ridpointers[(int)RID_CONST]
1725 || id == ridpointers[(int)RID_VOLATILE])
1727 error ("type specifier `%s' used invalidly",
1728 IDENTIFIER_POINTER (id));
1730 else if (id == ridpointers[(int)RID_FRIEND]
1731 || id == ridpointers[(int)RID_VIRTUAL]
1732 || id == ridpointers[(int)RID_INLINE]
1733 || id == ridpointers[(int)RID_UNSIGNED]
1734 || id == ridpointers[(int)RID_SIGNED]
1735 || id == ridpointers[(int)RID_STATIC]
1736 || id == ridpointers[(int)RID_EXTERN])
1738 quals = tree_cons (NULL_TREE, id, quals);
1742 /* Happens when we have a global typedef
1743 and a class-local member function with
1749 else if (TREE_CODE (id) == RECORD_TYPE)
1751 type_id = TYPE_NAME (id);
1752 if (TREE_CODE (type_id) == TYPE_DECL)
1753 type_id = DECL_NAME (type_id);
1754 if (type_id == NULL_TREE)
1755 error ("identifier for aggregate type conversion omitted");
1757 else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't')
1758 error ("`operator' missing on conversion operator or tag missing from type");
1760 my_friendly_abort (194);
1761 spec = TREE_CHAIN (spec);
1765 declspecs = chainon (lengths, quals);
1768 if (TREE_CHAIN (lengths))
1769 error ("multiple length specifiers");
1770 type_id = ridpointers[(int)RID_INT];
1771 declspecs = chainon (lengths, quals);
1775 error ("no type given, defaulting to `operator int ...'");
1776 type_id = ridpointers[(int)RID_INT];
1783 decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
1784 declspecs, FIELD, 0, NULL_TREE, NULL_TREE);
1785 if (decl == NULL_TREE)
1788 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
1790 /* Need a fresh node here so that we don't get circularity
1791 when we link these together. */
1792 decl = copy_node (decl);
1795 if (decl == void_type_node
1796 || (TREE_CODE (decl) == FUNCTION_DECL
1797 && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
1798 /* bunch of friends. */
1801 if (DECL_IN_AGGR_P (decl))
1803 cp_error ("`%D' already defined in the class ", decl);
1804 return void_type_node;
1807 cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0, 0);
1809 /* If this declaration is common to another declaration
1810 complain about such redundancy, and return NULL_TREE
1811 so that we don't build a circular list. */
1812 if (DECL_CHAIN (decl))
1814 cp_error ("function `%D' declared twice in class %T", decl,
1815 DECL_CONTEXT (decl));
1818 DECL_IN_AGGR_P (decl) = 1;
1824 grokoptypename (declspecs, declarator)
1825 tree declspecs, declarator;
1827 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0,
1828 NULL_TREE, NULL_TREE);
1829 return build_typename_overload (t);
1832 /* When a function is declared with an initializer,
1833 do the right thing. Currently, there are two possibilities:
1838 // initialization possibility #1.
1839 virtual void f () = 0;
1861 // initialization possibility #2
1868 copy_assignment_arg_p (parmtype, virtualp)
1872 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1873 parmtype = TREE_TYPE (parmtype);
1875 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1876 || (virtualp && DERIVED_FROM_P (parmtype, current_class_type)))
1883 grok_function_init (decl, init)
1887 /* An initializer for a function tells how this function should
1889 tree type = TREE_TYPE (decl);
1891 if (TREE_CODE (type) == FUNCTION_TYPE)
1892 cp_error ("initializer specified for non-member function `%D'", decl);
1893 else if (DECL_VINDEX (decl) == NULL_TREE)
1894 cp_error ("initializer specified for non-virtual method `%D'", decl);
1895 else if (integer_zerop (init))
1898 /* Mark this function as being "defined". */
1899 DECL_INITIAL (decl) = error_mark_node;
1900 /* pure virtual destructors must be defined. */
1901 /* pure virtual needs to be defined (as abort) only when put in
1902 vtbl. For wellformed call, it should be itself. pr4737 */
1903 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1905 extern tree abort_fndecl;
1906 /* Give this node rtl from `abort'. */
1907 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1910 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1911 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1914 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1916 if (copy_assignment_arg_p (parmtype, 1))
1917 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1920 else if (TREE_CODE (init) == OFFSET_REF
1921 && TREE_OPERAND (init, 0) == NULL_TREE
1922 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1924 tree basetype = DECL_CLASS_CONTEXT (init);
1925 tree basefn = TREE_OPERAND (init, 1);
1926 if (TREE_CODE (basefn) != FUNCTION_DECL)
1927 cp_error ("non-method initializer invalid for method `%D'", decl);
1928 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1929 sorry ("base member function from other than first base class");
1932 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1933 if (binfo == error_mark_node)
1935 else if (binfo == 0)
1936 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1937 TYPE_METHOD_BASETYPE (type));
1940 /* Mark this function as being defined,
1941 and give it new rtl. */
1942 DECL_INITIAL (decl) = error_mark_node;
1943 DECL_RTL (decl) = DECL_RTL (basefn);
1948 cp_error ("invalid initializer for virtual method `%D'", decl);
1951 /* When we get a declaration of the form
1953 type cname::fname ...
1955 the node for `cname::fname' gets built here in a special way.
1956 Namely, we push into `cname's scope. When this declaration is
1957 processed, we pop back out. */
1959 build_push_scope (cname, name)
1963 extern int current_class_depth;
1967 if (cname == error_mark_node)
1968 return error_mark_node;
1970 ctype = IDENTIFIER_TYPE_VALUE (cname);
1972 if (TREE_CODE (ctype) == TEMPLATE_TYPE_PARM)
1974 else if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
1976 cp_error ("`%T' not defined as aggregate type", cname);
1979 else if (IS_SIGNATURE (ctype))
1981 error ("cannot push into signature scope, scope resolution operator ignored");
1985 rval = build_parse_node (SCOPE_REF, cname, name);
1987 /* Don't need to push the scope if we're already in it.
1988 We also don't need to push the scope for a ptr-to-member/method. */
1990 if (ctype == current_class_type || TREE_CODE (name) != IDENTIFIER_NODE
1994 /* We do need to push the scope in this case, since CTYPE helps
1995 determine subsequent initializers (i.e., Foo::Bar x = foo_enum_1;). */
1997 push_nested_class (ctype, 3);
1998 TREE_COMPLEXITY (rval) = current_class_depth;
2003 cplus_decl_attributes (decl, attributes, prefix_attributes)
2004 tree decl, attributes, prefix_attributes;
2006 if (decl == NULL_TREE || decl == void_type_node)
2009 if (TREE_CODE (decl) == TEMPLATE_DECL)
2010 decl = DECL_TEMPLATE_RESULT (decl);
2012 decl_attributes (decl, attributes, prefix_attributes);
2014 if (TREE_CODE (decl) == TYPE_DECL)
2015 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl));
2018 /* CONSTRUCTOR_NAME:
2019 Return the name for the constructor (or destructor) for the
2020 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2021 IDENTIFIER_NODE. When given a template, this routine doesn't
2022 lose the specialization. */
2024 constructor_name_full (thing)
2027 if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
2028 return DECL_NAME (UPT_TEMPLATE (thing));
2029 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
2031 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
2032 thing = DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0));
2034 thing = TYPE_NAME (thing);
2036 if (TREE_CODE (thing) == TYPE_DECL
2037 || (TREE_CODE (thing) == TEMPLATE_DECL
2038 && DECL_TEMPLATE_IS_CLASS (thing)))
2039 thing = DECL_NAME (thing);
2040 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
2044 /* CONSTRUCTOR_NAME:
2045 Return the name for the constructor (or destructor) for the
2046 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2047 IDENTIFIER_NODE. When given a template, return the plain
2048 unspecialized name. */
2050 constructor_name (thing)
2054 thing = constructor_name_full (thing);
2055 t = IDENTIFIER_TEMPLATE (thing);
2058 t = TREE_PURPOSE (t);
2059 return DECL_NAME (t);
2062 /* Cache the value of this class's main virtual function table pointer
2063 in a register variable. This will save one indirection if a
2064 more than one virtual function call is made this function. */
2068 extern tree base_init_expr;
2070 if (base_init_expr == 0
2071 && DECL_CONSTRUCTOR_P (current_function_decl))
2072 emit_base_init (current_class_type, 0);
2075 /* Record the existence of an addressable inline function. */
2077 mark_inline_for_output (decl)
2080 decl = DECL_MAIN_VARIANT (decl);
2081 if (DECL_SAVED_INLINE (decl))
2083 my_friendly_assert (TREE_PERMANENT (decl), 363);
2084 DECL_SAVED_INLINE (decl) = 1;
2086 if (DECL_PENDING_INLINE_INFO (decl) != 0
2087 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
2089 struct pending_inline *t = pending_inlines;
2090 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
2093 if (t == DECL_PENDING_INLINE_INFO (decl))
2099 t = DECL_PENDING_INLINE_INFO (decl);
2100 t->next = pending_inlines;
2101 pending_inlines = t;
2103 DECL_PENDING_INLINE_INFO (decl) = 0;
2106 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
2112 temp_name_counter = 0;
2115 /* Hand off a unique name which can be used for variable we don't really
2116 want to know about anyway, for example, the anonymous variables which
2117 are needed to make references work. Declare this thing so we can use it.
2118 The variable created will be of type TYPE.
2120 STATICP is nonzero if this variable should be static. */
2123 get_temp_name (type, staticp)
2127 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
2129 int toplev = toplevel_bindings_p ();
2131 push_obstacks_nochange ();
2132 if (toplev || staticp)
2134 end_temporary_allocation ();
2135 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
2136 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
2140 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
2141 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
2143 TREE_USED (decl) = 1;
2144 TREE_STATIC (decl) = staticp;
2146 /* If this is a local variable, then lay out its rtl now.
2147 Otherwise, callers of this function are responsible for dealing
2148 with this variable's rtl. */
2152 expand_decl_init (decl);
2159 /* Get a variable which we can use for multiple assignments.
2160 It is not entered into current_binding_level, because
2161 that breaks things when it comes time to do final cleanups
2162 (which take place "outside" the binding contour of the function). */
2164 get_temp_regvar (type, init)
2167 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
2170 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
2171 decl = build_decl (VAR_DECL, get_identifier (buf), type);
2172 TREE_USED (decl) = 1;
2173 DECL_REGISTER (decl) = 1;
2176 store_init_value (decl, init);
2178 /* We can expand these without fear, since they cannot need
2179 constructors or destructors. */
2181 expand_decl_init (decl);
2183 if (type_needs_gc_entry (type))
2184 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
2189 /* Make the macro TEMP_NAME_P available to units which do not
2190 include c-tree.h. */
2195 return TEMP_NAME_P (decl);
2198 /* Finish off the processing of a UNION_TYPE structure.
2199 If there are static members, then all members are
2200 static, and must be laid out together. If the
2201 union is an anonymous union, we arrange for that
2202 as well. PUBLIC_P is nonzero if this union is
2203 not declared static. */
2205 finish_anon_union (anon_union_decl)
2206 tree anon_union_decl;
2208 tree type = TREE_TYPE (anon_union_decl);
2209 tree field, main_decl = NULL_TREE;
2210 tree elems = NULL_TREE;
2211 int public_p = TREE_PUBLIC (anon_union_decl);
2212 int static_p = TREE_STATIC (anon_union_decl);
2213 int external_p = DECL_EXTERNAL (anon_union_decl);
2215 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
2220 error ("global anonymous unions must be declared static");
2224 for (; field; field = TREE_CHAIN (field))
2227 if (TREE_CODE (field) != FIELD_DECL)
2230 if (TREE_PRIVATE (field))
2231 cp_pedwarn_at ("private member `%#D' in anonymous union", field);
2232 else if (TREE_PROTECTED (field))
2233 cp_pedwarn_at ("protected member `%#D' in anonymous union", field);
2235 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2236 /* tell `pushdecl' that this is not tentative. */
2237 DECL_INITIAL (decl) = error_mark_node;
2238 TREE_PUBLIC (decl) = public_p;
2239 TREE_STATIC (decl) = static_p;
2240 DECL_EXTERNAL (decl) = external_p;
2241 decl = pushdecl (decl);
2243 /* Only write out one anon union element--choose the one that
2244 can hold them all. */
2245 if (main_decl == NULL_TREE
2246 && 1 == simple_cst_equal (DECL_SIZE (decl),
2247 DECL_SIZE (anon_union_decl)))
2253 /* ??? This causes there to be no debug info written out
2255 TREE_ASM_WRITTEN (decl) = 1;
2258 DECL_INITIAL (decl) = NULL_TREE;
2259 /* If there's a cleanup to do, it belongs in the
2260 TREE_PURPOSE of the following TREE_LIST. */
2261 elems = tree_cons (NULL_TREE, decl, elems);
2262 TREE_TYPE (elems) = type;
2268 make_decl_rtl (main_decl, 0, toplevel_bindings_p ());
2269 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2273 warning ("anonymous union with no members");
2278 /* The following call assumes that there are never any cleanups
2279 for anonymous unions--a reasonable assumption. */
2280 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2283 cadillac_finish_anon_union (anon_union_decl);
2286 /* Finish and output a table which is generated by the compiler.
2287 NAME is the name to give the table.
2288 TYPE is the type of the table entry.
2289 INIT is all the elements in the table.
2290 PUBLICP is non-zero if this table should be given external access. */
2292 finish_table (name, type, init, publicp)
2293 tree name, type, init;
2296 tree itype, atype, decl;
2297 static tree empty_table;
2301 itype = build_index_type (size_int (list_length (init) - 1));
2302 atype = build_cplus_array_type (type, itype);
2303 layout_type (atype);
2305 if (TREE_VALUE (init) == integer_zero_node
2306 && TREE_CHAIN (init) == NULL_TREE)
2309 if (empty_table == NULL_TREE)
2312 empty_table = get_temp_name (atype, 1);
2313 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2314 TREE_CONSTANT (init) = 1;
2315 TREE_STATIC (init) = 1;
2316 DECL_INITIAL (empty_table) = init;
2317 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2318 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2319 cp_finish_decl (empty_table, NULL_TREE, asmspec, 0, 0);
2324 if (name == NULL_TREE)
2328 decl = get_temp_name (atype, 1);
2332 decl = build_decl (VAR_DECL, name, atype);
2333 decl = pushdecl (decl);
2334 TREE_STATIC (decl) = 1;
2339 TREE_PUBLIC (decl) = publicp;
2340 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2341 TREE_CONSTANT (init) = 1;
2342 TREE_STATIC (init) = 1;
2343 DECL_INITIAL (decl) = init;
2344 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2345 IDENTIFIER_POINTER (DECL_NAME (decl)));
2349 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2350 DECL_EXTERNAL (decl) = 1;
2351 TREE_STATIC (decl) = 0;
2353 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2354 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2357 cp_finish_decl (decl, NULL_TREE, asmspec, 0, 0);
2361 /* Finish processing a builtin type TYPE. It's name is NAME,
2362 its fields are in the array FIELDS. LEN is the number of elements
2363 in FIELDS minus one, or put another way, it is the maximum subscript
2366 It is given the same alignment as ALIGN_TYPE. */
2368 finish_builtin_type (type, name, fields, len, align_type)
2377 TYPE_FIELDS (type) = fields[0];
2378 for (i = 0; i < len; i++)
2380 layout_type (TREE_TYPE (fields[i]));
2381 DECL_FIELD_CONTEXT (fields[i]) = type;
2382 TREE_CHAIN (fields[i]) = fields[i+1];
2384 DECL_FIELD_CONTEXT (fields[i]) = type;
2385 DECL_CLASS_CONTEXT (fields[i]) = type;
2386 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2388 #if 0 /* not yet, should get fixed properly later */
2389 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2391 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2393 layout_decl (TYPE_NAME (type), 0);
2396 /* Auxiliary functions to make type signatures for
2397 `operator new' and `operator delete' correspond to
2398 what compiler will be expecting. */
2400 extern tree sizetype;
2403 coerce_new_type (type)
2408 if (TREE_CODE (type) == METHOD_TYPE)
2409 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2410 if (TREE_TYPE (type) != ptr_type_node)
2411 e1 = 1, error ("`operator new' must return type `void *'");
2413 /* Technically the type must be `size_t', but we may not know
2415 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2416 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2417 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2418 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2419 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2421 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2423 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2428 coerce_delete_type (type)
2431 int e1 = 0, e2 = 0, e3 = 0;
2432 tree arg_types = TYPE_ARG_TYPES (type);
2434 if (TREE_CODE (type) == METHOD_TYPE)
2436 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2437 arg_types = TREE_CHAIN (arg_types);
2439 if (TREE_TYPE (type) != void_type_node)
2440 e1 = 1, error ("`operator delete' must return type `void'");
2441 if (arg_types == NULL_TREE
2442 || TREE_VALUE (arg_types) != ptr_type_node)
2443 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2446 && TREE_CHAIN (arg_types)
2447 && TREE_CHAIN (arg_types) != void_list_node)
2449 /* Again, technically this argument must be `size_t', but again
2450 we may not know what that is. */
2451 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2452 if (TREE_CODE (t2) != INTEGER_TYPE
2453 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2454 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2455 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2458 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2459 error ("too many arguments in declaration of `operator delete'");
2461 error ("`...' invalid in specification of `operator delete'");
2465 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
2468 if (arg_types == NULL_TREE)
2469 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2471 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2476 type = build_function_type (void_type_node, arg_types);
2481 extern tree abort_fndecl;
2484 mark_vtable_entries (decl)
2487 tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
2489 skip_rtti_stuff (&entries);
2491 for (; entries; entries = TREE_CHAIN (entries))
2493 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries)
2494 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2495 tree fn = TREE_OPERAND (fnaddr, 0);
2496 TREE_ADDRESSABLE (fn) = 1;
2497 if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn))
2498 TREE_OPERAND (fnaddr, 0) = fn = abort_fndecl;
2499 assemble_external (fn);
2503 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2504 based on TYPE and other static flags.
2506 Note that anything public is tagged TREE_PUBLIC, whether
2507 it's public in this file or in another one. */
2510 import_export_vtable (decl, type, final)
2514 if (DECL_INTERFACE_KNOWN (decl))
2518 if (write_virtuals < 2 && write_virtuals != 0)
2520 TREE_PUBLIC (decl) = 1;
2521 if (write_virtuals < 0)
2522 DECL_EXTERNAL (decl) = 1;
2523 DECL_INTERFACE_KNOWN (decl) = 1;
2525 else if (CLASSTYPE_INTERFACE_KNOWN (type))
2527 TREE_PUBLIC (decl) = 1;
2528 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2529 DECL_INTERFACE_KNOWN (decl) = 1;
2533 /* We can only wait to decide if we have real non-inline virtual
2534 functions in our class, or if we come from a template. */
2536 int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2538 if (! found && ! final)
2541 for (method = TYPE_METHODS (type); method != NULL_TREE;
2542 method = TREE_CHAIN (method))
2543 if (DECL_VINDEX (method) != NULL_TREE
2544 && ! DECL_THIS_INLINE (method)
2545 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2552 if (final || ! found)
2554 #ifdef ASSEMBLE_EXTERNAL
2555 if (TREE_PUBLIC (decl))
2556 cp_error ("all virtual functions redeclared inline");
2559 DECL_WEAK (decl) = 1;
2561 TREE_PUBLIC (decl) = 0;
2562 DECL_EXTERNAL (decl) = 0;
2566 TREE_PUBLIC (decl) = 1;
2567 DECL_EXTERNAL (decl) = 1;
2573 import_export_template (type)
2576 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2577 && ! flag_implicit_templates
2578 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2580 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2581 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2582 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2587 finish_prevtable_vardecl (prev, vars)
2590 tree ctype = DECL_CONTEXT (vars);
2591 import_export_template (ctype);
2593 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype)
2594 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2597 for (method = TYPE_METHODS (ctype); method != NULL_TREE;
2598 method = TREE_CHAIN (method))
2600 if (DECL_VINDEX (method) != NULL_TREE
2601 && !DECL_THIS_INLINE (method)
2602 && !DECL_ABSTRACT_VIRTUAL_P (method))
2604 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2605 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method);
2606 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2612 import_export_vtable (vars, ctype, 1);
2614 /* We cannot use TREE_USED here, as it may be set by the expanding of a
2615 ctor that is used to build a global object. The long term plan is to
2616 make the TD entries statically initialized and move this to
2617 finish_vtable_vardecl time. */
2618 if (flag_rtti && write_virtuals >= 0
2619 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || 1 || TREE_USED (vars)))
2621 /* Kick out the type descriptor before we dump out global
2622 initializers, as they are initialized at run time and
2623 we have to find them when we scan for things that need initialized
2624 at the top level. */
2625 build_t_desc (ctype, 1);
2630 finish_vtable_vardecl (prev, vars)
2633 if (write_virtuals >= 0
2634 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
2637 /* The long term plan it to make the TD entries statically initialized,
2638 have the entries built and emitted here. When that happens, this
2639 can be enabled, and the other call to build_t_desc removed. */
2640 /* Kick out the type descriptor before writing out the vtable. */
2642 build_t_desc (DECL_CONTEXT (vars), 1);
2646 mark_vtable_entries (vars);
2647 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2648 store_init_value (vars, DECL_INITIAL (vars));
2650 #ifdef DWARF_DEBUGGING_INFO
2651 if (write_symbols == DWARF_DEBUG)
2653 /* Mark the VAR_DECL node representing the vtable itself as a
2654 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2655 It is rather important that such things be ignored because
2656 any effort to actually generate DWARF for them will run
2657 into trouble when/if we encounter code like:
2660 struct S { virtual void member (); };
2662 because the artificial declaration of the vtable itself (as
2663 manufactured by the g++ front end) will say that the vtable
2664 is a static member of `S' but only *after* the debug output
2665 for the definition of `S' has already been output. This causes
2666 grief because the DWARF entry for the definition of the vtable
2667 will try to refer back to an earlier *declaration* of the
2668 vtable as a static member of `S' and there won't be one.
2669 We might be able to arrange to have the "vtable static member"
2670 attached to the member list for `S' before the debug info for
2671 `S' get written (which would solve the problem) but that would
2672 require more intrusive changes to the g++ front end. */
2674 DECL_IGNORED_P (vars) = 1;
2676 #endif /* DWARF_DEBUGGING_INFO */
2678 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2680 else if (! TREE_USED (vars))
2681 /* We don't know what to do with this one yet. */
2684 /* We know that PREV must be non-zero here. */
2685 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2689 prune_vtable_vardecl (prev, vars)
2692 /* We know that PREV must be non-zero here. */
2693 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2697 walk_vtables (typedecl_fn, vardecl_fn)
2698 register void (*typedecl_fn)();
2699 register void (*vardecl_fn)();
2703 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2705 register tree type = TREE_TYPE (vars);
2707 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2709 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2711 if (prev && TREE_CHAIN (prev) != vars)
2714 else if (TREE_CODE (vars) == TYPE_DECL
2715 && type != error_mark_node
2716 && TYPE_LANG_SPECIFIC (type)
2717 && CLASSTYPE_VSIZE (type))
2719 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2727 finish_sigtable_vardecl (prev, vars)
2730 /* We don't need to mark sigtable entries as addressable here as is done
2731 for vtables. Since sigtables, unlike vtables, are always written out,
2732 that was already done in build_signature_table_constructor. */
2734 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2736 /* We know that PREV must be non-zero here. */
2737 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2741 walk_sigtables (typedecl_fn, vardecl_fn)
2742 register void (*typedecl_fn)();
2743 register void (*vardecl_fn)();
2747 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2749 register tree type = TREE_TYPE (vars);
2751 if (TREE_CODE (vars) == TYPE_DECL
2752 && type != error_mark_node
2753 && IS_SIGNATURE (type))
2755 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2757 else if (TREE_CODE (vars) == VAR_DECL
2758 && TREE_TYPE (vars) != error_mark_node
2759 && IS_SIGNATURE (TREE_TYPE (vars)))
2761 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2768 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2769 inline function at end-of-file. */
2772 import_export_inline (decl)
2775 if (DECL_INTERFACE_KNOWN (decl))
2778 if (DECL_TEMPLATE_INSTANTIATION (decl))
2780 if (DECL_IMPLICIT_INSTANTIATION (decl) && flag_implicit_templates)
2783 DECL_WEAK (decl) = 1;
2785 TREE_PUBLIC (decl) = 0;
2788 DECL_NOT_REALLY_EXTERN (decl) = 0;
2790 else if (DECL_FUNCTION_MEMBER_P (decl))
2792 tree ctype = DECL_CLASS_CONTEXT (decl);
2793 if (CLASSTYPE_INTERFACE_KNOWN (ctype) && ! DECL_ARTIFICIAL (decl))
2795 DECL_NOT_REALLY_EXTERN (decl)
2796 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2797 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2800 DECL_WEAK (decl) = 1;
2802 TREE_PUBLIC (decl) = 0;
2804 else if (DECL_C_STATIC (decl))
2805 TREE_PUBLIC (decl) = 0;
2807 DECL_WEAK (decl) = 1;
2809 TREE_PUBLIC (decl) = 0;
2811 DECL_INTERFACE_KNOWN (decl) = 1;
2815 build_cleanup (decl)
2819 tree type = TREE_TYPE (decl);
2821 if (TREE_CODE (type) == ARRAY_TYPE)
2825 mark_addressable (decl);
2826 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2828 temp = build_delete (TREE_TYPE (temp), temp,
2830 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2834 extern int parse_time, varconst_time;
2836 #define TIMEVAR(VAR, BODY) \
2837 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2839 /* This routine is called from the last rule in yyparse ().
2840 Its job is to create all the code needed to initialize and
2841 destroy the global aggregates. We do the destruction
2842 first, since that way we only need to reverse the decls once. */
2848 int start_time, this_time;
2852 int needs_cleaning = 0, needs_messing_up = 0;
2854 if (flag_detailed_statistics)
2855 dump_tree_statistics ();
2857 /* Bad parse errors. Just forget about it. */
2858 if (! global_bindings_p () || current_class_type)
2861 start_time = get_run_time ();
2863 /* Push into C language context, because that's all
2865 push_lang_context (lang_name_c);
2867 /* Otherwise, GDB can get confused, because in only knows
2868 about source for LINENO-1 lines. */
2871 interface_unknown = 1;
2875 /* The reason for pushing garbage onto the global_binding_level is to
2876 ensure that we can slice out _DECLs which pertain to virtual function
2877 tables. If the last thing pushed onto the global_binding_level was a
2878 virtual function table, then slicing it out would slice away all the
2879 decls (i.e., we lose the head of the chain).
2881 There are several ways of getting the same effect, from changing the
2882 way that iterators over the chain treat the elements that pertain to
2883 virtual function tables, moving the implementation of this code to
2884 decl.c (where we can manipulate global_binding_level directly),
2885 popping the garbage after pushing it and slicing away the vtable
2886 stuff, or just leaving it alone. */
2888 /* Make last thing in global scope not be a virtual function table. */
2889 #if 0 /* not yet, should get fixed properly later */
2890 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2892 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2894 DECL_IGNORED_P (vars) = 1;
2895 SET_DECL_ARTIFICIAL (vars);
2899 /* Walk to mark the inline functions we need, then output them so
2900 that we can pick up any other tdecls that those routines need. */
2901 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2903 vars = static_aggregates;
2905 if (static_ctors || vars || might_have_exceptions_p ())
2906 needs_messing_up = 1;
2910 /* See if we really need the hassle. */
2911 while (vars && needs_cleaning == 0)
2913 tree decl = TREE_VALUE (vars);
2914 tree type = TREE_TYPE (decl);
2915 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars))
2921 vars = TREE_CHAIN (vars);
2924 if (needs_cleaning == 0)
2927 fnname = get_file_function_name ('D');
2928 start_function (void_list_node,
2929 build_parse_node (CALL_EXPR, fnname, void_list_node,
2931 NULL_TREE, NULL_TREE, 0);
2932 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2933 store_parm_decls ();
2938 expand_start_bindings (0);
2940 /* These must be done in backward order to destroy,
2941 in which they happen to be! */
2942 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2944 tree decl = TREE_VALUE (vars);
2945 tree type = TREE_TYPE (decl);
2946 tree temp = TREE_PURPOSE (vars);
2948 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars))
2950 temp = build_cleanup (decl);
2951 expand_expr_stmt (temp);
2955 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2956 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2959 expand_end_bindings (getdecls(), 1, 0);
2963 finish_function (lineno, 0, 0);
2965 assemble_destructor (IDENTIFIER_POINTER (fnname));
2967 /* if it needed cleaning, then it will need messing up: drop through */
2970 /* Must do this while we think we are at the top level. */
2971 vars = nreverse (static_aggregates);
2972 if (needs_messing_up)
2974 fnname = get_file_function_name ('I');
2975 start_function (void_list_node,
2976 build_parse_node (CALL_EXPR, fnname,
2977 void_list_node, NULL_TREE),
2978 NULL_TREE, NULL_TREE, 0);
2979 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2980 store_parm_decls ();
2985 expand_start_bindings (0);
2987 if (might_have_exceptions_p ())
2988 register_exception_table ();
2992 extern int temp_slot_level;
2993 extern int target_temp_slot_level;
2994 tree decl = TREE_VALUE (vars);
2995 tree init = TREE_PURPOSE (vars);
2996 tree old_cleanups = cleanups_this_call;
2997 int old_temp_level = target_temp_slot_level;
3000 target_temp_slot_level = temp_slot_level;
3002 /* If this was a static attribute within some function's scope,
3003 then don't initialize it here. Also, don't bother
3004 with initializers that contain errors. */
3005 if (TREE_STATIC (vars)
3006 || (init && TREE_CODE (init) == TREE_LIST
3007 && value_member (error_mark_node, init)))
3009 vars = TREE_CHAIN (vars);
3013 if (TREE_CODE (decl) == VAR_DECL)
3015 /* Set these global variables so that GDB at least puts
3016 us near the declaration which required the initialization. */
3017 input_filename = DECL_SOURCE_FILE (decl);
3018 lineno = DECL_SOURCE_LINE (decl);
3019 emit_note (input_filename, lineno);
3021 /* 9.5p5: The initializer of a static member of a class has
3022 the same access rights as a member function. */
3023 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
3024 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
3026 if (IS_AGGR_TYPE (TREE_TYPE (decl))
3027 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
3028 expand_aggr_init (decl, init, 0, 0);
3029 else if (TREE_CODE (init) == TREE_VEC)
3031 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
3032 TREE_VEC_ELT (init, 1),
3033 TREE_VEC_ELT (init, 2), 0),
3034 const0_rtx, VOIDmode, 0);
3037 expand_assignment (decl, init, 0, 0);
3039 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
3041 else if (TREE_CODE (decl) == SAVE_EXPR)
3043 if (! PARM_DECL_EXPR (decl))
3045 /* a `new' expression at top level. */
3046 expand_expr (decl, const0_rtx, VOIDmode, 0);
3047 if (TREE_CODE (init) == TREE_VEC)
3049 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
3050 TREE_VEC_ELT (init, 1),
3051 TREE_VEC_ELT (init, 2), 0),
3052 const0_rtx, VOIDmode, 0);
3055 expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0, 0);
3058 else if (decl == error_mark_node)
3060 else my_friendly_abort (22);
3062 /* Cleanup any temporaries needed for the initial value. */
3063 expand_cleanups_to (old_cleanups);
3066 target_temp_slot_level = old_temp_level;
3068 vars = TREE_CHAIN (vars);
3071 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
3072 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
3075 expand_end_bindings (getdecls(), 1, 0);
3079 finish_function (lineno, 0, 0);
3080 assemble_constructor (IDENTIFIER_POINTER (fnname));
3083 expand_builtin_throw ();
3085 permanent_allocation (1);
3087 /* Done with C language context needs. */
3088 pop_lang_context ();
3090 /* Now write out any static class variables (which may have since
3091 learned how to be initialized). */
3092 while (pending_statics)
3094 tree decl = TREE_VALUE (pending_statics);
3095 if (TREE_USED (decl) == 1
3096 || TREE_READONLY (decl) == 0
3097 || DECL_INITIAL (decl) == 0)
3098 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3099 pending_statics = TREE_CHAIN (pending_statics);
3102 this_time = get_run_time ();
3103 parse_time -= this_time - start_time;
3104 varconst_time += this_time - start_time;
3106 start_time = get_run_time ();
3108 if (flag_handle_signatures)
3109 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3111 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3113 tree decl = TREE_VALUE (fnname);
3114 import_export_inline (decl);
3115 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3116 && TREE_PUBLIC (decl) && ! DECL_WEAK (decl)
3117 && DECL_NOT_REALLY_EXTERN (decl))
3118 synthesize_method (decl);
3121 /* Now write out inline functions which had their addresses taken and
3122 which were not declared virtual and which were not declared `extern
3125 int reconsider = 1; /* More may be referenced; check again */
3129 tree *p = &saved_inlines;
3132 walk_vtables ((void (*)())0, finish_vtable_vardecl);
3136 tree decl = TREE_VALUE (*p);
3138 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3139 && TREE_USED (decl))
3141 synthesize_method (decl);
3145 if (TREE_ASM_WRITTEN (decl)
3146 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3147 *p = TREE_CHAIN (*p);
3149 p = &TREE_CHAIN (*p);
3153 reconsider = 1; /* More may be referenced; check again */
3156 tree *p = &saved_inlines;
3161 tree decl = TREE_VALUE (*p);
3163 if (TREE_ASM_WRITTEN (decl) || DECL_SAVED_INSNS (decl) == 0)
3164 *p = TREE_CHAIN (*p);
3165 else if ((TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
3166 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3167 || flag_keep_inline_functions)
3169 if (DECL_NOT_REALLY_EXTERN (decl))
3171 DECL_EXTERNAL (decl) = 0;
3173 temporary_allocation ();
3174 output_inline_function (decl);
3175 permanent_allocation (1);
3178 *p = TREE_CHAIN (*p);
3181 p = &TREE_CHAIN (*p);
3186 /* Now delete from the chain of variables all virtual function tables.
3187 We output them all ourselves, because each will be treated specially. */
3189 walk_vtables ((void (*)())0, prune_vtable_vardecl);
3191 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3193 if (TREE_CODE (vars) == THUNK_DECL)
3195 else if (TREE_CODE (vars) == FUNCTION_DECL
3196 && ! DECL_INTERFACE_KNOWN (vars)
3197 && DECL_C_STATIC (vars))
3198 TREE_PUBLIC (vars) = 0;
3201 if (might_have_exceptions_p ())
3202 emit_exception_table ();
3204 if (write_virtuals == 2)
3206 /* Now complain about an virtual function tables promised
3207 but not delivered. */
3208 while (pending_vtables)
3210 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3211 error ("virtual function table for `%s' not defined",
3212 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3213 pending_vtables = TREE_CHAIN (pending_vtables);
3219 this_time = get_run_time ();
3220 parse_time -= this_time - start_time;
3221 varconst_time += this_time - start_time;
3223 if (flag_detailed_statistics)
3224 dump_time_statistics ();
3227 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3228 expr. Since it was parsed like a type, we need to wade through and fix
3229 that. Unfortunately, since operator() is left-associative, we can't use
3230 tail recursion. In the above example, TYPE is `A', and DECL is
3233 Maybe this shouldn't be recursive, but how often will it actually be
3236 reparse_absdcl_as_expr (type, decl)
3239 /* do build_functional_cast (type, NULL_TREE) at bottom */
3240 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3241 return build_functional_cast (type, NULL_TREE);
3244 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3246 decl = build_x_function_call (decl, NULL_TREE, current_class_decl);
3248 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3249 decl = require_complete_type (decl);
3254 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3255 out to be an expr. Since it was parsed like a type, we need to wade
3256 through and fix that. Since casts are right-associative, we are
3257 reversing the order, so we don't have to recurse.
3259 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3262 reparse_absdcl_as_casts (decl, expr)
3267 if (TREE_CODE (expr) == CONSTRUCTOR)
3269 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3270 decl = TREE_OPERAND (decl, 0);
3272 if (IS_SIGNATURE (type))
3274 error ("cast specifies signature type");
3275 return error_mark_node;
3278 expr = digest_init (type, expr, (tree *) 0);
3279 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3281 int failure = complete_array_type (type, expr, 1);
3283 my_friendly_abort (78);
3289 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3290 decl = TREE_OPERAND (decl, 0);
3291 expr = build_c_cast (type, expr, 0);
3297 /* Recursive helper function for reparse_decl_as_expr. It may be a good
3298 idea to reimplement this using an explicit stack, rather than recursion. */
3300 reparse_decl_as_expr1 (decl)
3303 switch (TREE_CODE (decl))
3305 case IDENTIFIER_NODE:
3306 return do_identifier (decl);
3308 return build_x_indirect_ref
3309 (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)), "unary *");
3311 return build_x_unary_op (ADDR_EXPR,
3312 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3314 return build_x_unary_op (BIT_NOT_EXPR,
3315 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3317 return build_offset_ref (TREE_OPERAND (decl, 0), TREE_OPERAND (decl, 1));
3319 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)),
3320 TREE_OPERAND (decl, 1));
3322 my_friendly_abort (5);
3327 /* This is something of the form `int (*a)++' that has turned out to be an
3328 expr. It was only converted into parse nodes, so we need to go through
3329 and build up the semantics. Most of the work is done by
3330 reparse_decl_as_expr1, above.
3332 In the above example, TYPE is `int' and DECL is `*a'. */
3334 reparse_decl_as_expr (type, decl)
3337 decl = reparse_decl_as_expr1 (decl);
3339 return build_functional_cast (type, build_tree_list (NULL_TREE, decl));
3344 /* This is something of the form `int (*a)' that has turned out to be a
3345 decl. It was only converted into parse nodes, so we need to do the
3346 checking that make_{pointer,reference}_declarator do. */
3349 finish_decl_parsing (decl)
3352 extern int current_class_depth;
3354 switch (TREE_CODE (decl))
3356 case IDENTIFIER_NODE:
3359 return make_pointer_declarator
3360 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3362 return make_reference_declarator
3363 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3365 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3368 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3369 TREE_COMPLEXITY (decl) = current_class_depth;
3372 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3375 my_friendly_abort (5);
3381 check_cp_case_value (value)
3384 if (value == NULL_TREE)
3387 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3388 Strip such NOP_EXPRs. */
3389 if (TREE_CODE (value) == NOP_EXPR
3390 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3391 value = TREE_OPERAND (value, 0);
3393 if (TREE_READONLY_DECL_P (value))
3395 value = decl_constant_value (value);
3396 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3397 Strip such NOP_EXPRs. */
3398 if (TREE_CODE (value) == NOP_EXPR
3399 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3400 value = TREE_OPERAND (value, 0);
3402 value = fold (value);
3404 if (TREE_CODE (value) != INTEGER_CST
3405 && value != error_mark_node)
3407 cp_error ("case label `%E' does not reduce to an integer constant",
3409 value = error_mark_node;
3412 /* Promote char or short to int. */
3413 value = default_conversion (value);
3415 constant_expression_warning (value);
3420 tree current_namespace;
3422 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3423 postfix. Returns 0 if in global namespace. */
3427 tree x = current_namespace;
3429 x = TREE_PURPOSE (x);
3433 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3435 current_namespace_id (name)
3438 tree old_id = get_namespace_id ();
3441 /* Global names retain old encoding. */
3445 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3446 + IDENTIFIER_LENGTH (name));
3447 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3448 IDENTIFIER_POINTER (name));
3449 return get_identifier (buf);
3453 do_namespace_alias (alias, namespace)
3454 tree alias, namespace;
3459 do_toplevel_using_decl (decl)
3462 if (decl == NULL_TREE || decl == error_mark_node)
3465 if (TREE_CODE (decl) == SCOPE_REF)
3466 decl = resolve_scope_to_name (NULL_TREE, decl);
3468 /* Is this the right way to do an id list? */
3469 if (TREE_CODE (decl) != TREE_LIST)
3476 pushdecl (TREE_VALUE (decl));
3477 decl = TREE_CHAIN (decl);
3482 do_class_using_decl (decl)
3487 /* Ignore for now, unimplemented. */
3492 do_using_directive (namespace)
3498 check_default_args (x)
3501 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
3502 int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
3503 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
3505 if (TREE_PURPOSE (arg))
3509 cp_error ("default argument missing for parameter %P of `%#D'",
3520 TREE_USED (decl) = 1;
3521 assemble_external (decl);