1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Process declarations and symbol lookup for C front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
40 extern tree get_file_function_name ();
41 extern tree cleanups_this_call;
42 static void grok_function_init PROTO((tree, tree));
43 void import_export_decl ();
44 extern int current_class_depth;
45 extern int symout_time;
47 /* A list of virtual function tables we must make sure to write out. */
50 /* A list of static class variables. This is needed, because a
51 static class variable can be declared inside the class without
52 an initializer, and then initialized, staticly, outside the class. */
55 /* A list of functions which were declared inline, but which we
56 may need to emit outline anyway. */
57 static tree saved_inlines;
59 /* Used to help generate temporary names which are unique within
60 a function. Reset to 0 by start_function. */
62 int temp_name_counter;
64 /* Same, but not reset. Local temp variables and global temp variables
65 can have the same name. */
66 static int global_temp_name_counter;
68 /* Flag used when debugging spew.c */
70 extern int spew_debug;
72 /* Nonzero if we're done parsing and into end-of-file activities. */
76 /* Functions called along with real static constructors and destructors. */
78 tree static_ctors, static_dtors;
80 /* C (and C++) language-specific option variables. */
82 /* Nonzero means allow type mismatches in conditional expressions;
83 just make their values `void'. */
85 int flag_cond_mismatch;
87 /* Nonzero means give `double' the same size as `float'. */
89 int flag_short_double;
91 /* Nonzero means don't recognize the keyword `asm'. */
95 /* Nonzero means don't recognize any extension keywords. */
97 int flag_no_gnu_keywords;
99 /* Nonzero means don't recognize the non-ANSI builtin functions. */
103 /* Nonzero means don't recognize the non-ANSI builtin functions.
106 int flag_no_nonansi_builtin;
108 /* Nonzero means do some things the same way PCC does. Only provided so
109 the compiler will link. */
111 int flag_traditional;
113 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
115 int flag_signed_bitfields = 1;
117 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
121 /* Nonzero means enable obscure ANSI features and disable GNU extensions
122 that might cause ANSI-compliant code to be miscompiled. */
126 /* Nonzero means do argument matching for overloading according to the
127 ANSI rules, rather than what g++ used to believe to be correct. */
129 int flag_ansi_overloading = 1;
131 /* Nonzero means do emit exported implementations of functions even if
132 they can be inlined. */
134 int flag_implement_inlines = 1;
136 /* Nonzero means do emit exported implementations of templates, instead of
137 multiple static copies in each file that needs a definition. */
139 int flag_external_templates;
141 /* Nonzero means that the decision to emit or not emit the implementation of a
142 template depends on where the template is instantiated, rather than where
145 int flag_alt_external_templates;
147 /* Nonzero means that implicit instantiations will be emitted if needed. */
149 int flag_implicit_templates = 1;
151 /* Nonzero means warn about implicit declarations. */
153 int warn_implicit = 1;
155 /* Nonzero means warn when all ctors or dtors are private, and the class
158 int warn_ctor_dtor_privacy = 1;
160 /* True if we want to implement vtables using "thunks".
161 The default is off. */
163 #if defined(NEW_OVER) && defined (__i386__)
164 int flag_vtable_thunks = 1;
166 int flag_vtable_thunks;
169 /* True if we want to deal with repository information. */
171 int flag_use_repository;
173 /* Nonzero means give string constants the type `const char *'
174 to get extra warnings from them. These warnings will be too numerous
175 to be useful, except in thoroughly ANSIfied programs. */
177 int warn_write_strings;
179 /* Nonzero means warn about pointer casts that can drop a type qualifier
180 from the pointer target type. */
184 /* Nonzero means warn that dbx info for template class methods isn't fully
187 int warn_template_debugging;
189 /* Nonzero means warn about sizeof(function) or addition/subtraction
190 of function pointers. */
192 int warn_pointer_arith = 1;
194 /* Nonzero means warn for any function def without prototype decl. */
196 int warn_missing_prototypes;
198 /* Nonzero means warn about multiple (redundant) decls for the same single
199 variable or function. */
201 int warn_redundant_decls;
203 /* Warn if initializer is not completely bracketed. */
205 int warn_missing_braces;
207 /* Warn about comparison of signed and unsigned values. */
209 int warn_sign_compare;
211 /* Warn about *printf or *scanf format/argument anomalies. */
215 /* Warn about a subscript that has type char. */
217 int warn_char_subscripts;
219 /* Warn if a type conversion is done that might have confusing results. */
223 /* Warn if adding () is suggested. */
225 int warn_parentheses;
227 /* Non-zero means warn in function declared in derived class has the
228 same name as a virtual in the base class, but fails to match the
229 type signature of any virtual function in the base class. */
230 int warn_overloaded_virtual;
232 /* Non-zero means warn when declaring a class that has a non virtual
233 destructor, when it really ought to have a virtual one. */
236 /* Non-zero means warn when a function is declared extern and later inline. */
237 int warn_extern_inline;
239 /* Non-zero means warn when the compiler will reorder code. */
242 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
245 /* Nonzero means `$' can be in an identifier.
246 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
248 #ifndef DOLLARS_IN_IDENTIFIERS
249 #define DOLLARS_IN_IDENTIFIERS 1
251 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
253 /* Nonzero for -fno-strict-prototype switch: do not consider empty
254 argument prototype to mean function takes no arguments. */
256 int flag_strict_prototype = 2;
257 int strict_prototype = 1;
258 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
260 /* Nonzero means that labels can be used as first-class objects */
264 /* Non-zero means to collect statistics which might be expensive
265 and to print them when we are done. */
266 int flag_detailed_statistics;
268 /* C++ specific flags. */
269 /* Nonzero for -fall-virtual: make every member function (except
270 constructors) lay down in the virtual function table. Calls
271 can then either go through the virtual function table or not,
274 int flag_all_virtual;
276 /* Zero means that `this' is a *const. This gives nice behavior in the
277 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
278 -2 means we're constructing an object and it has fixed type. */
280 int flag_this_is_variable;
282 /* Nonzero means memoize our member lookups. */
284 int flag_memoize_lookups; int flag_save_memoized_contexts;
286 /* 3 means write out only virtuals function tables `defined'
287 in this implementation file.
288 2 means write out only specific virtual function tables
289 and give them (C) public access.
290 1 means write out virtual function tables and give them
292 0 means write out virtual function tables and give them
293 (C) static access (default).
294 -1 means declare virtual function tables extern. */
298 /* Nonzero means we should attempt to elide constructors when possible. */
300 int flag_elide_constructors;
302 /* Nonzero means recognize and handle signature language constructs. */
304 int flag_handle_signatures;
306 /* Nonzero means that member functions defined in class scope are
307 inline by default. */
309 int flag_default_inline = 1;
311 /* Controls whether enums and ints freely convert.
312 1 means with complete freedom.
313 0 means enums can convert to ints, but not vice-versa. */
314 int flag_int_enum_equivalence;
316 /* Controls whether compiler generates 'type descriptor' that give
317 run-time type information. */
320 /* Nonzero if we wish to output cross-referencing information
321 for the GNU class browser. */
322 extern int flag_gnu_xref;
324 /* Nonzero if compiler can make `reasonable' assumptions about
325 references and objects. For example, the compiler must be
326 conservative about the following and not assume that `a' is nonnull:
331 In general, it is `reasonable' to assume that for many programs,
332 and better code can be generated in that case. */
334 int flag_assume_nonnull_objects = 1;
336 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
339 int flag_huge_objects;
341 /* Nonzero if we want to conserve space in the .o files. We do this
342 by putting uninitialized data and runtime initialized data into
343 .common instead of .data at the expense of not flagging multiple
346 int flag_conserve_space;
348 /* Nonzero if we want to obey access control semantics. */
350 int flag_access_control = 1;
352 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
354 int flag_operator_names;
356 /* Nonzero if we want to check the return value of new and avoid calling
357 constructors if it is a null pointer. */
361 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
362 initialization variables.
363 0: Old rules, set by -fno-for-scope.
364 2: New ANSI rules, set by -ffor-scope.
365 1: Try to implement new ANSI rules, but with backup compatibility
366 (and warnings). This is the default, for now. */
368 int flag_new_for_scope = 1;
370 /* Nonzero if we want to emit defined symbols with common-like linkage as
371 weak symbols where possible, in order to conform to C++ semantics.
372 Otherwise, emit them as local symbols. */
376 /* Table of language-dependent -f options.
377 STRING is the option name. VARIABLE is the address of the variable.
378 ON_VALUE is the value to store in VARIABLE
379 if `-fSTRING' is seen as an option.
380 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
382 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
384 {"signed-char", &flag_signed_char, 1},
385 {"unsigned-char", &flag_signed_char, 0},
386 {"signed-bitfields", &flag_signed_bitfields, 1},
387 {"unsigned-bitfields", &flag_signed_bitfields, 0},
388 {"short-enums", &flag_short_enums, 1},
389 {"short-double", &flag_short_double, 1},
390 {"cond-mismatch", &flag_cond_mismatch, 1},
391 {"asm", &flag_no_asm, 0},
392 {"builtin", &flag_no_builtin, 0},
393 {"ident", &flag_no_ident, 0},
394 {"labels-ok", &flag_labels_ok, 1},
395 {"stats", &flag_detailed_statistics, 1},
396 {"this-is-variable", &flag_this_is_variable, 1},
397 {"strict-prototype", &flag_strict_prototype, 1},
398 {"all-virtual", &flag_all_virtual, 1},
399 {"memoize-lookups", &flag_memoize_lookups, 1},
400 {"elide-constructors", &flag_elide_constructors, 1},
401 {"handle-signatures", &flag_handle_signatures, 1},
402 {"default-inline", &flag_default_inline, 1},
403 {"dollars-in-identifiers", &dollars_in_ident, 1},
404 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
405 {"rtti", &flag_rtti, 1},
406 {"xref", &flag_gnu_xref, 1},
407 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
408 {"implement-inlines", &flag_implement_inlines, 1},
409 {"external-templates", &flag_external_templates, 1},
410 {"implicit-templates", &flag_implicit_templates, 1},
411 {"ansi-overloading", &flag_ansi_overloading, 1},
412 {"huge-objects", &flag_huge_objects, 1},
413 {"conserve-space", &flag_conserve_space, 1},
414 {"vtable-thunks", &flag_vtable_thunks, 1},
415 {"short-temps", &flag_short_temps, 1},
416 {"access-control", &flag_access_control, 1},
417 {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
418 {"gnu-keywords", &flag_no_gnu_keywords, 0},
419 {"operator-names", &flag_operator_names, 1},
420 {"check-new", &flag_check_new, 1},
421 {"repo", &flag_use_repository, 1},
422 {"for-scope", &flag_new_for_scope, 2},
423 {"weak", &flag_weak, 1}
426 /* Decode the string P as a language-specific option.
427 Return 1 if it is recognized (and handle it);
428 return 0 if not recognized. */
431 lang_decode_option (p)
434 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
435 dollars_in_ident = 1, flag_writable_strings = 1,
436 flag_this_is_variable = 1, flag_new_for_scope = 0;
437 /* The +e options are for cfront compatibility. They come in as
438 `-+eN', to kludge around gcc.c's argument handling. */
439 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
441 int old_write_virtuals = write_virtuals;
444 else if (p[3] == '0')
446 else if (p[3] == '2')
448 else error ("invalid +e option");
449 if (old_write_virtuals != 0
450 && write_virtuals != old_write_virtuals)
451 error ("conflicting +e options given");
453 else if (p[0] == '-' && p[1] == 'f')
455 /* Some kind of -f option.
456 P's value is the option sans `-f'.
457 Search for it in the table of options. */
461 /* Try special -f options. */
463 if (!strcmp (p, "save-memoized"))
465 flag_memoize_lookups = 1;
466 flag_save_memoized_contexts = 1;
469 if (!strcmp (p, "no-save-memoized"))
471 flag_memoize_lookups = 0;
472 flag_save_memoized_contexts = 0;
475 else if (! strcmp (p, "alt-external-templates"))
477 flag_external_templates = 1;
478 flag_alt_external_templates = 1;
481 else if (! strcmp (p, "no-alt-external-templates"))
483 flag_alt_external_templates = 0;
486 else if (!strcmp (p, "repo"))
488 flag_use_repository = 1;
489 flag_implicit_templates = 0;
493 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
496 if (!strcmp (p, lang_f_options[j].string))
498 *lang_f_options[j].variable = lang_f_options[j].on_value;
499 /* A goto here would be cleaner,
500 but breaks the vax pcc. */
503 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
504 && ! strcmp (p+3, lang_f_options[j].string))
506 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
512 else if (p[0] == '-' && p[1] == 'W')
516 /* The -W options control the warning behavior of the compiler. */
519 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
522 if (!strcmp (p, "implicit"))
523 warn_implicit = setting;
524 else if (!strcmp (p, "return-type"))
525 warn_return_type = setting;
526 else if (!strcmp (p, "ctor-dtor-privacy"))
527 warn_ctor_dtor_privacy = setting;
528 else if (!strcmp (p, "write-strings"))
529 warn_write_strings = setting;
530 else if (!strcmp (p, "cast-qual"))
531 warn_cast_qual = setting;
532 else if (!strcmp (p, "char-subscripts"))
533 warn_char_subscripts = setting;
534 else if (!strcmp (p, "pointer-arith"))
535 warn_pointer_arith = setting;
536 else if (!strcmp (p, "missing-prototypes"))
537 warn_missing_prototypes = setting;
538 else if (!strcmp (p, "redundant-decls"))
539 warn_redundant_decls = setting;
540 else if (!strcmp (p, "missing-braces"))
541 warn_missing_braces = setting;
542 else if (!strcmp (p, "sign-compare"))
543 warn_sign_compare = setting;
544 else if (!strcmp (p, "format"))
545 warn_format = setting;
546 else if (!strcmp (p, "conversion"))
547 warn_conversion = setting;
548 else if (!strcmp (p, "parentheses"))
549 warn_parentheses = setting;
550 else if (!strcmp (p, "non-virtual-dtor"))
551 warn_nonvdtor = setting;
552 else if (!strcmp (p, "extern-inline"))
553 warn_extern_inline = setting;
554 else if (!strcmp (p, "reorder"))
555 warn_reorder = setting;
556 else if (!strcmp (p, "synth"))
557 warn_synth = setting;
558 else if (!strcmp (p, "comment"))
559 ; /* cpp handles this one. */
560 else if (!strcmp (p, "comments"))
561 ; /* cpp handles this one. */
562 else if (!strcmp (p, "trigraphs"))
563 ; /* cpp handles this one. */
564 else if (!strcmp (p, "import"))
565 ; /* cpp handles this one. */
566 else if (!strcmp (p, "all"))
568 warn_return_type = setting;
569 warn_unused = setting;
570 warn_implicit = setting;
571 warn_ctor_dtor_privacy = setting;
572 warn_switch = setting;
573 warn_format = setting;
574 warn_parentheses = setting;
575 warn_missing_braces = setting;
576 warn_sign_compare = setting;
577 warn_extern_inline = setting;
578 warn_nonvdtor = setting;
579 /* We save the value of warn_uninitialized, since if they put
580 -Wuninitialized on the command line, we need to generate a
581 warning about not using it without also specifying -O. */
582 if (warn_uninitialized != 1)
583 warn_uninitialized = (setting ? 2 : 0);
584 warn_template_debugging = setting;
585 warn_reorder = setting;
588 else if (!strcmp (p, "overloaded-virtual"))
589 warn_overloaded_virtual = setting;
592 else if (!strcmp (p, "-ansi"))
593 dollars_in_ident = 0, flag_no_nonansi_builtin = 1, flag_ansi = 1,
594 flag_no_gnu_keywords = 1, flag_operator_names = 1;
596 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
597 it's probably safe to assume no sane person would ever want to use this
598 under normal circumstances. */
599 else if (!strcmp (p, "-spew-debug"))
608 /* Incorporate `const' and `volatile' qualifiers for member functions.
609 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
610 QUALS is a list of qualifiers. */
613 grok_method_quals (ctype, function, quals)
614 tree ctype, function, quals;
616 tree fntype = TREE_TYPE (function);
617 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
621 extern tree ridpointers[];
623 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
625 if (TYPE_READONLY (ctype))
626 error ("duplicate `%s' %s",
627 IDENTIFIER_POINTER (TREE_VALUE (quals)),
628 (TREE_CODE (function) == FUNCTION_DECL
629 ? "for member function" : "in type declaration"));
630 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
631 build_pointer_type (ctype);
633 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
635 if (TYPE_VOLATILE (ctype))
636 error ("duplicate `%s' %s",
637 IDENTIFIER_POINTER (TREE_VALUE (quals)),
638 (TREE_CODE (function) == FUNCTION_DECL
639 ? "for member function" : "in type declaration"));
640 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
641 build_pointer_type (ctype);
644 my_friendly_abort (20);
645 quals = TREE_CHAIN (quals);
648 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
649 (TREE_CODE (fntype) == METHOD_TYPE
650 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
651 : TYPE_ARG_TYPES (fntype)));
653 fntype = build_exception_variant (fntype, raises);
655 TREE_TYPE (function) = fntype;
659 #if 0 /* Not used. */
660 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
661 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
662 /* This does not yet work with user defined conversion operators
666 substitute_nice_name (decl)
669 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
671 char *n = decl_as_string (DECL_NAME (decl), 1);
672 if (n[strlen (n) - 1] == ' ')
673 n[strlen (n) - 1] = 0;
674 DECL_NAME (decl) = get_identifier (n);
679 /* Warn when -fexternal-templates is used and #pragma
680 interface/implementation is not used all the times it should be,
684 warn_if_unknown_interface (decl)
687 static int already_warned = 0;
688 if (already_warned++)
691 if (flag_alt_external_templates)
693 struct tinst_level *til = tinst_for_decl ();
695 char *sf = input_filename;
700 input_filename = til->file;
702 cp_warning ("template `%#D' instantiated in file without #pragma interface",
708 cp_warning_at ("template `%#D' defined in file without #pragma interface",
712 /* A subroutine of the parser, to handle a component list. */
715 grok_x_components (specs, components)
716 tree specs, components;
718 register tree t, x, tcode;
720 /* We just got some friends. They have been recorded elsewhere. */
721 if (components == void_type_node)
724 if (components == NULL_TREE)
726 t = groktypename (build_decl_list (specs, NULL_TREE));
730 error ("error in component specification");
734 switch (TREE_CODE (t))
737 /* Static anonymous unions come out as VAR_DECLs. */
738 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
739 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
742 /* We return SPECS here, because in the parser it was ending
743 up with not doing anything to $$, which is what SPECS
749 /* This code may be needed for UNION_TYPEs as
751 tcode = record_type_node;
752 if (CLASSTYPE_DECLARED_CLASS (t))
753 tcode = class_type_node;
754 else if (IS_SIGNATURE (t))
755 tcode = signature_type_node;
757 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
758 if (TYPE_CONTEXT (t))
759 CLASSTYPE_NO_GLOBALIZE (t) = 1;
765 if (TREE_CODE (t) == UNION_TYPE)
766 tcode = union_type_node;
768 tcode = enum_type_node;
770 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
771 if (TREE_CODE (t) == UNION_TYPE && TYPE_CONTEXT (t))
772 CLASSTYPE_NO_GLOBALIZE (t) = 1;
773 if (TREE_CODE (t) == UNION_TYPE
774 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
776 struct pending_inline **p;
777 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
779 /* Wipe out memory of synthesized methods */
780 TYPE_HAS_CONSTRUCTOR (t) = 0;
781 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
782 TYPE_HAS_INIT_REF (t) = 0;
783 TYPE_HAS_CONST_INIT_REF (t) = 0;
784 TYPE_HAS_ASSIGN_REF (t) = 0;
785 TYPE_HAS_ASSIGNMENT (t) = 0;
786 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
788 p = &pending_inlines;
789 for (; *p; *p = (*p)->next)
790 if (DECL_CONTEXT ((*p)->fndecl) != t)
793 else if (TREE_CODE (t) == ENUMERAL_TYPE)
794 x = grok_enum_decls (t, NULL_TREE);
801 if (t != void_type_node)
802 error ("empty component declaration");
808 t = TREE_TYPE (components);
809 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
810 return grok_enum_decls (t, components);
816 /* Classes overload their constituent function names automatically.
817 When a function name is declared in a record structure,
818 its name is changed to it overloaded name. Since names for
819 constructors and destructors can conflict, we place a leading
822 CNAME is the name of the class we are grokking for.
824 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
826 FLAGS contains bits saying what's special about today's
827 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
829 If FUNCTION is a destructor, then we must add the `auto-delete' field
830 as a second parameter. There is some hair associated with the fact
831 that we must "declare" this variable in the manner consistent with the
832 way the rest of the arguments were declared.
834 QUALS are the qualifiers for the this pointer. */
837 grokclassfn (ctype, cname, function, flags, quals)
838 tree ctype, cname, function;
839 enum overload_flags flags;
842 tree fn_name = DECL_NAME (function);
846 tree fntype = TREE_TYPE (function);
847 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
849 if (fn_name == NULL_TREE)
851 error ("name missing for member function");
852 fn_name = get_identifier ("<anonymous>");
853 DECL_NAME (function) = fn_name;
857 qualtype = grok_method_quals (ctype, function, quals);
861 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
862 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
864 /* Must add the class instance variable up front. */
865 /* Right now we just make this a pointer. But later
866 we may wish to make it special. */
867 tree type = TREE_VALUE (arg_types);
870 if ((flag_this_is_variable > 0)
871 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
874 if (DECL_CONSTRUCTOR_P (function))
876 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
878 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
879 /* In this case we need "in-charge" flag saying whether
880 this constructor is responsible for initialization
881 of virtual baseclasses or not. */
882 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
883 /* Mark the artificial `__in_chrg' parameter as "artificial". */
884 SET_DECL_ARTIFICIAL (parm);
885 DECL_ARG_TYPE (parm) = integer_type_node;
886 TREE_READONLY (parm) = 1;
887 TREE_CHAIN (parm) = last_function_parms;
888 last_function_parms = parm;
892 parm = build_decl (PARM_DECL, this_identifier, type);
893 /* Mark the artificial `this' parameter as "artificial". */
894 SET_DECL_ARTIFICIAL (parm);
895 DECL_ARG_TYPE (parm) = type;
896 /* We can make this a register, so long as we don't
897 accidentally complain if someone tries to take its address. */
898 DECL_REGISTER (parm) = 1;
900 TREE_READONLY (parm) = 1;
901 TREE_CHAIN (parm) = last_function_parms;
902 last_function_parms = parm;
905 if (flags == DTOR_FLAG)
908 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
909 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
911 arg_types = hash_tree_chain (const_integer_type, void_list_node);
912 TREE_SIDE_EFFECTS (arg_types) = 1;
913 /* Build the overload name. It will look like `7Example'. */
914 if (IDENTIFIER_TYPE_VALUE (cname))
915 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
916 else if (IDENTIFIER_LOCAL_VALUE (cname))
917 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
919 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
920 it's defined out of the class definition, since poplevel_class wipes
921 it out. This used to be internal error 346. */
922 dbuf = build_overload_name (ctype, 1, 1);
923 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
924 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
927 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
928 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
929 /* Mark the artificial `__in_chrg' parameter as "artificial". */
930 SET_DECL_ARTIFICIAL (parm);
931 TREE_READONLY (parm) = 1;
932 DECL_ARG_TYPE (parm) = integer_type_node;
933 /* This is the same chain as DECL_ARGUMENTS (...). */
934 TREE_CHAIN (last_function_parms) = parm;
936 fntype = build_cplus_method_type (qualtype, void_type_node,
940 fntype = build_exception_variant (fntype, raises);
942 TREE_TYPE (function) = fntype;
943 TYPE_HAS_DESTRUCTOR (ctype) = 1;
947 tree these_arg_types;
949 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
951 arg_types = hash_tree_chain (integer_type_node,
952 TREE_CHAIN (arg_types));
953 fntype = build_cplus_method_type (qualtype,
954 TREE_TYPE (TREE_TYPE (function)),
958 fntype = build_exception_variant (fntype, raises);
960 TREE_TYPE (function) = fntype;
961 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
964 these_arg_types = arg_types;
966 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
967 /* Only true for static member functions. */
968 these_arg_types = hash_tree_chain (build_pointer_type (qualtype),
971 DECL_ASSEMBLER_NAME (function)
972 = build_decl_overload (fn_name, these_arg_types,
973 1 + DECL_CONSTRUCTOR_P (function));
976 /* This code is going into the compiler, but currently, it makes
977 libg++/src/Integer.cc not compile. The problem is that the nice name
978 winds up going into the symbol table, and conversion operations look
979 for the manged name. */
980 substitute_nice_name (function);
984 DECL_ARGUMENTS (function) = last_function_parms;
985 /* First approximations. */
986 DECL_CONTEXT (function) = ctype;
987 DECL_CLASS_CONTEXT (function) = ctype;
990 /* Work on the expr used by alignof (this is only called by the parser). */
999 if (TREE_CODE (expr) == COMPONENT_REF
1000 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
1001 error ("`__alignof__' applied to a bit-field");
1003 if (TREE_CODE (expr) == INDIRECT_REF)
1005 best = t = TREE_OPERAND (expr, 0);
1006 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1008 while (TREE_CODE (t) == NOP_EXPR
1009 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1012 t = TREE_OPERAND (t, 0);
1013 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1014 if (thisalign > bestalign)
1015 best = t, bestalign = thisalign;
1017 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1021 /* ANSI says arrays and fns are converted inside comma.
1022 But we can't convert them in build_compound_expr
1023 because that would break commas in lvalues.
1024 So do the conversion here if operand was a comma. */
1025 if (TREE_CODE (expr) == COMPOUND_EXPR
1026 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1027 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1028 expr = default_conversion (expr);
1029 return c_alignof (TREE_TYPE (expr));
1033 /* Create an ARRAY_REF, checking for the user doing things backwards
1037 grok_array_decl (array_expr, index_exp)
1038 tree array_expr, index_exp;
1040 tree type = TREE_TYPE (array_expr);
1041 tree p1, p2, i1, i2;
1043 if (type == error_mark_node || index_exp == error_mark_node)
1044 return error_mark_node;
1045 if (processing_template_decl)
1046 return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE,
1047 array_expr, index_exp);
1049 if (type == NULL_TREE)
1051 /* Something has gone very wrong. Assume we are mistakenly reducing
1052 an expression instead of a declaration. */
1053 error ("parser may be lost: is there a '{' missing somewhere?");
1057 if (TREE_CODE (type) == OFFSET_TYPE
1058 || TREE_CODE (type) == REFERENCE_TYPE)
1059 type = TREE_TYPE (type);
1061 /* If they have an `operator[]', use that. */
1062 if (TYPE_LANG_SPECIFIC (type)
1063 && TYPE_OVERLOADS_ARRAY_REF (complete_type (type)))
1064 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1065 array_expr, index_exp, NULL_TREE);
1067 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1069 if (TREE_CODE (type) == ARRAY_TYPE)
1072 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1074 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1077 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1079 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1080 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1082 if ((p1 && i2) && (i1 && p2))
1083 error ("ambiguous conversion for array subscript");
1086 array_expr = p1, index_exp = i2;
1088 array_expr = p2, index_exp = i1;
1091 cp_error ("invalid types `%T[%T]' for array subscript",
1092 type, TREE_TYPE (index_exp));
1093 return error_mark_node;
1096 if (array_expr == error_mark_node || index_exp == error_mark_node)
1097 error ("ambiguous conversion for array subscript");
1099 return build_array_ref (array_expr, index_exp);
1102 /* Given the cast expression EXP, checking out its validity. Either return
1103 an error_mark_node if there was an unavoidable error, return a cast to
1104 void for trying to delete a pointer w/ the value 0, or return the
1105 call to delete. If DOING_VEC is 1, we handle things differently
1106 for doing an array delete. If DOING_VEC is 2, they gave us the
1107 array size as an argument to delete.
1108 Implements ARM $5.3.4. This is called from the parser. */
1111 delete_sanity (exp, size, doing_vec, use_global_delete)
1113 int doing_vec, use_global_delete;
1117 enum tree_code code;
1118 /* For a regular vector delete (aka, no size argument) we will pass
1119 this down as a NULL_TREE into build_vec_delete. */
1120 tree maxindex = NULL_TREE;
1122 if (exp == error_mark_node)
1125 if (processing_template_decl)
1127 t = build_min (DELETE_EXPR, void_type_node, exp, size);
1128 DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
1129 DELETE_EXPR_USE_VEC (t) = doing_vec;
1133 t = stabilize_reference (convert_from_reference (exp));
1134 type = TREE_TYPE (t);
1135 code = TREE_CODE (type);
1140 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1141 pedwarn ("anachronistic use of array size in vector delete");
1146 if (code != POINTER_TYPE)
1148 cp_error ("type `%#T' argument given to `delete', expected pointer",
1150 return error_mark_node;
1153 /* Deleting a pointer with the value zero is valid and has no effect. */
1154 if (integer_zerop (t))
1155 return build1 (NOP_EXPR, void_type_node, t);
1158 if (code == POINTER_TYPE)
1161 /* As of Valley Forge, you can delete a pointer to constant. */
1162 /* You can't delete a pointer to constant. */
1163 if (TREE_READONLY (TREE_TYPE (type)))
1165 error ("`const *' cannot be deleted");
1166 return error_mark_node;
1169 /* You also can't delete functions. */
1170 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1172 error ("cannot delete a function");
1173 return error_mark_node;
1178 /* If the type has no destructor, then we should build a regular
1179 delete, instead of a vector delete. Otherwise, we would end
1180 up passing a bogus offset into __builtin_delete, which is
1181 not expecting it. */
1183 && TREE_CODE (type) == POINTER_TYPE
1184 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1187 use_global_delete = 1;
1192 return build_vec_delete (t, maxindex, integer_one_node,
1193 integer_two_node, use_global_delete);
1196 if (IS_AGGR_TYPE (TREE_TYPE (type))
1197 && TYPE_GETS_REG_DELETE (TREE_TYPE (type)))
1199 /* Only do access checking here; we'll be calling op delete
1200 from the destructor. */
1201 tree tmp = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, t,
1202 size_zero_node, NULL_TREE);
1203 if (tmp == error_mark_node)
1204 return error_mark_node;
1207 return build_delete (type, t, integer_three_node,
1208 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
1213 /* Sanity check: report error if this function FUNCTION is not
1214 really a member of the class (CTYPE) it is supposed to belong to.
1215 CNAME is the same here as it is for grokclassfn above. */
1218 check_classfn (ctype, function)
1219 tree ctype, function;
1221 tree fn_name = DECL_NAME (function);
1223 tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype));
1227 if (method_vec != 0)
1229 methods = &TREE_VEC_ELT (method_vec, 0);
1230 end = TREE_VEC_END (method_vec);
1232 /* First suss out ctors and dtors. */
1233 if (*methods && fn_name == DECL_NAME (*methods)
1234 && DECL_CONSTRUCTOR_P (function))
1236 if (*++methods && fn_name == DECL_NAME (*methods)
1237 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)))
1240 while (++methods != end)
1242 if (fn_name == DECL_NAME (*methods))
1248 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1251 /* This doesn't work for static member functions that are
1252 pretending to be methods. */
1253 /* We have to do more extensive argument checking here, as
1254 the name may have been changed by asm("new_name"). */
1255 if (decls_match (function, fndecl))
1258 if (DECL_NAME (function) == DECL_NAME (fndecl))
1260 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1261 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1263 /* Get rid of the this parameter on functions that become
1265 if (DECL_STATIC_FUNCTION_P (fndecl)
1266 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1267 p1 = TREE_CHAIN (p1);
1269 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1270 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1271 && compparms (p1, p2, 3))
1275 fndecl = DECL_CHAIN (fndecl);
1284 tree fndecl = *methods;
1285 cp_error ("prototype for `%#D' does not match any in class `%T'",
1287 cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl) ? "s are" : " is",
1289 while (fndecl = DECL_CHAIN (fndecl), fndecl)
1290 cp_error_at (" %#D", fndecl);
1295 cp_error ("no `%#D' member function declared in class `%T'",
1299 /* If we did not find the method in the class, add it to avoid
1301 add_method (ctype, methods, function);
1305 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1306 of a structure component, returning a FIELD_DECL node.
1307 QUALS is a list of type qualifiers for this decl (such as for declaring
1308 const member functions).
1310 This is done during the parsing of the struct declaration.
1311 The FIELD_DECL nodes are chained together and the lot of them
1312 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1316 If class A defines that certain functions in class B are friends, then
1317 the way I have set things up, it is B who is interested in permission
1318 granted by A. However, it is in A's context that these declarations
1319 are parsed. By returning a void_type_node, class A does not attempt
1320 to incorporate the declarations of the friends within its structure.
1322 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1323 CHANGES TO CODE IN `start_method'. */
1326 grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
1327 tree declarator, declspecs, init, asmspec_tree, attrlist;
1329 register tree value;
1331 int flags = LOOKUP_ONLYCONVERTING;
1333 /* Convert () initializers to = initializers. */
1334 if (init == NULL_TREE && declarator != NULL_TREE
1335 && TREE_CODE (declarator) == CALL_EXPR
1336 && TREE_OPERAND (declarator, 0)
1337 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1338 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1339 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1341 init = TREE_OPERAND (declarator, 1);
1342 declarator = TREE_OPERAND (declarator, 0);
1346 if (declspecs == NULL_TREE
1347 && TREE_CODE (declarator) == SCOPE_REF
1348 && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE)
1350 /* Access declaration */
1351 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0))))
1353 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
1354 pop_nested_class (1);
1355 return do_class_using_decl (declarator);
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, NULL_TREE);
1366 return value; /* friend or constructor went bad. */
1368 /* Pass friendly classes back. */
1369 if (TREE_CODE (value) == VOID_TYPE)
1370 return void_type_node;
1372 if (DECL_NAME (value) != NULL_TREE
1373 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1374 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1375 cp_error ("member `%D' conflicts with virtual function table field name", value);
1377 /* Stash away type declarations. */
1378 if (TREE_CODE (value) == TYPE_DECL)
1380 DECL_NONLOCAL (value) = 1;
1381 DECL_CONTEXT (value) = current_class_type;
1382 DECL_CLASS_CONTEXT (value) = current_class_type;
1383 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1385 pushdecl_class_level (value);
1389 if (IS_SIGNATURE (current_class_type)
1390 && TREE_CODE (value) != FUNCTION_DECL)
1392 error ("field declaration not allowed in signature");
1393 return void_type_node;
1396 if (DECL_IN_AGGR_P (value))
1398 cp_error ("`%D' is already defined in the class %T", value,
1399 DECL_CONTEXT (value));
1400 return void_type_node;
1404 asmspec = TREE_STRING_POINTER (asmspec_tree);
1408 if (IS_SIGNATURE (current_class_type)
1409 && TREE_CODE (value) == FUNCTION_DECL)
1411 error ("function declarations cannot have initializers in signature");
1414 else if (TREE_CODE (value) == FUNCTION_DECL)
1416 grok_function_init (value, init);
1419 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1420 /* Already complained in grokdeclarator. */
1424 /* We allow initializers to become parameters to base
1426 if (TREE_CODE (init) == TREE_LIST)
1428 if (TREE_CHAIN (init) == NULL_TREE)
1429 init = TREE_VALUE (init);
1431 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1434 if (TREE_CODE (init) == CONST_DECL)
1435 init = DECL_INITIAL (init);
1436 else if (TREE_READONLY_DECL_P (init))
1437 init = decl_constant_value (init);
1438 else if (TREE_CODE (init) == CONSTRUCTOR)
1439 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1440 my_friendly_assert (TREE_PERMANENT (init), 192);
1441 if (init == error_mark_node)
1442 /* We must make this look different than `error_mark_node'
1443 because `decl_const_value' would mis-interpret it
1444 as only meaning that this VAR_DECL is defined. */
1445 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1446 else if (processing_template_decl)
1448 else if (! TREE_CONSTANT (init))
1450 /* We can allow references to things that are effectively
1451 static, since references are initialized with the address. */
1452 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1453 || (TREE_STATIC (init) == 0
1454 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1455 || DECL_EXTERNAL (init) == 0)))
1457 error ("field initializer is not constant");
1458 init = error_mark_node;
1464 /* The corresponding pop_obstacks is in cp_finish_decl. */
1465 push_obstacks_nochange ();
1467 if (processing_template_decl && ! current_function_decl
1468 && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
1469 push_template_decl (value);
1472 cplus_decl_attributes (value, TREE_PURPOSE (attrlist),
1473 TREE_VALUE (attrlist));
1475 if (TREE_CODE (value) == VAR_DECL)
1477 /* We cannot call pushdecl here, because that would
1478 fill in the value of our TREE_CHAIN. Instead, we
1479 modify cp_finish_decl to do the right thing, namely, to
1480 put this decl out straight away. */
1481 if (TREE_PUBLIC (value))
1483 /* current_class_type can be NULL_TREE in case of error. */
1484 if (asmspec == 0 && current_class_type)
1486 TREE_PUBLIC (value) = 1;
1487 DECL_INITIAL (value) = error_mark_node;
1488 DECL_ASSEMBLER_NAME (value)
1489 = build_static_name (current_class_type, DECL_NAME (value));
1491 if (! processing_template_decl)
1492 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1494 /* Static consts need not be initialized in the class definition. */
1495 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1497 static int explanation = 0;
1499 error ("initializer invalid for static member with constructor");
1500 if (explanation++ == 0)
1501 error ("(you really want to initialize it separately)");
1504 /* Force the compiler to know when an uninitialized static
1505 const member is being used. */
1506 if (TYPE_READONLY (value) && init == 0)
1507 TREE_USED (value) = 1;
1509 DECL_INITIAL (value) = init;
1510 DECL_IN_AGGR_P (value) = 1;
1511 DECL_CONTEXT (value) = current_class_type;
1512 DECL_CLASS_CONTEXT (value) = current_class_type;
1514 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1515 pushdecl_class_level (value);
1518 if (TREE_CODE (value) == FIELD_DECL)
1522 /* This must override the asm specifier which was placed
1523 by grokclassfn. Lay this out fresh. */
1524 DECL_RTL (value) = NULL_RTX;
1525 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1527 if (DECL_INITIAL (value) == error_mark_node)
1528 init = error_mark_node;
1529 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1530 DECL_INITIAL (value) = init;
1531 DECL_IN_AGGR_P (value) = 1;
1534 if (TREE_CODE (value) == FUNCTION_DECL)
1536 check_default_args (value);
1537 if (DECL_CHAIN (value) != NULL_TREE)
1539 /* Need a fresh node here so that we don't get circularity
1540 when we link these together. */
1541 value = copy_node (value);
1542 /* When does this happen? */
1543 my_friendly_assert (init == NULL_TREE, 193);
1547 /* This must override the asm specifier which was placed
1548 by grokclassfn. Lay this out fresh. */
1549 DECL_RTL (value) = NULL_RTX;
1550 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1552 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1554 /* Pass friends back this way. */
1555 if (DECL_FRIEND_P (value))
1556 return void_type_node;
1558 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1559 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1560 cp_error ("method `%#D' of local class must be defined in class body",
1564 DECL_IN_AGGR_P (value) = 1;
1567 my_friendly_abort (21);
1572 /* Like `grokfield', but for bitfields.
1573 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1576 grokbitfield (declarator, declspecs, width)
1577 tree declarator, declspecs, width;
1579 register tree value = grokdeclarator (declarator, declspecs, BITFIELD,
1582 if (! value) return NULL_TREE; /* friends went bad. */
1584 /* Pass friendly classes back. */
1585 if (TREE_CODE (value) == VOID_TYPE)
1586 return void_type_node;
1588 if (TREE_CODE (value) == TYPE_DECL)
1590 cp_error ("cannot declare `%D' to be a bitfield type", value);
1594 if (IS_SIGNATURE (current_class_type))
1596 error ("field declaration not allowed in signature");
1597 return void_type_node;
1600 if (DECL_IN_AGGR_P (value))
1602 cp_error ("`%D' is already defined in the class %T", value,
1603 DECL_CONTEXT (value));
1604 return void_type_node;
1607 GNU_xref_member (current_class_name, value);
1609 if (TREE_STATIC (value))
1611 cp_error ("static member `%D' cannot be a bitfield", value);
1614 cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1616 if (width != error_mark_node)
1618 constant_expression_warning (width);
1619 DECL_INITIAL (value) = width;
1620 DECL_BIT_FIELD (value) = 1;
1623 DECL_IN_AGGR_P (value) = 1;
1628 grokoptypename (declspecs, declarator)
1629 tree declspecs, declarator;
1631 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1632 return build_typename_overload (t);
1635 /* When a function is declared with an initializer,
1636 do the right thing. Currently, there are two possibilities:
1641 // initialization possibility #1.
1642 virtual void f () = 0;
1664 // initialization possibility #2
1671 copy_assignment_arg_p (parmtype, virtualp)
1675 if (current_class_type == NULL_TREE)
1678 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1679 parmtype = TREE_TYPE (parmtype);
1681 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1682 || (virtualp && DERIVED_FROM_P (parmtype, current_class_type)))
1689 grok_function_init (decl, init)
1693 /* An initializer for a function tells how this function should
1695 tree type = TREE_TYPE (decl);
1697 if (TREE_CODE (type) == FUNCTION_TYPE)
1698 cp_error ("initializer specified for non-member function `%D'", decl);
1700 /* We'll check for this in finish_struct_1. */
1701 else if (DECL_VINDEX (decl) == NULL_TREE)
1702 cp_error ("initializer specified for non-virtual method `%D'", decl);
1704 else if (integer_zerop (init))
1707 /* Mark this function as being "defined". */
1708 DECL_INITIAL (decl) = error_mark_node;
1709 /* pure virtual destructors must be defined. */
1710 /* pure virtual needs to be defined (as abort) only when put in
1711 vtbl. For wellformed call, it should be itself. pr4737 */
1712 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1714 extern tree abort_fndecl;
1715 /* Give this node rtl from `abort'. */
1716 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1719 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1720 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1723 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1725 if (copy_assignment_arg_p (parmtype, 1))
1726 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1729 else if (TREE_CODE (init) == OFFSET_REF
1730 && TREE_OPERAND (init, 0) == NULL_TREE
1731 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1733 tree basetype = DECL_CLASS_CONTEXT (init);
1734 tree basefn = TREE_OPERAND (init, 1);
1735 if (TREE_CODE (basefn) != FUNCTION_DECL)
1736 cp_error ("non-method initializer invalid for method `%D'", decl);
1737 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1738 sorry ("base member function from other than first base class");
1741 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1742 if (binfo == error_mark_node)
1744 else if (binfo == 0)
1745 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1746 TYPE_METHOD_BASETYPE (type));
1749 /* Mark this function as being defined,
1750 and give it new rtl. */
1751 DECL_INITIAL (decl) = error_mark_node;
1752 DECL_RTL (decl) = DECL_RTL (basefn);
1757 cp_error ("invalid initializer for virtual method `%D'", decl);
1761 cplus_decl_attributes (decl, attributes, prefix_attributes)
1762 tree decl, attributes, prefix_attributes;
1764 if (decl == NULL_TREE || decl == void_type_node)
1767 if (TREE_CODE (decl) == TEMPLATE_DECL)
1768 decl = DECL_TEMPLATE_RESULT (decl);
1770 decl_attributes (decl, attributes, prefix_attributes);
1772 if (TREE_CODE (decl) == TYPE_DECL)
1773 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl));
1776 /* CONSTRUCTOR_NAME:
1777 Return the name for the constructor (or destructor) for the
1778 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1779 IDENTIFIER_NODE. When given a template, this routine doesn't
1780 lose the specialization. */
1783 constructor_name_full (thing)
1786 if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM)
1787 thing = TYPE_NAME (thing);
1788 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1790 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1791 thing = DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0));
1793 thing = TYPE_NAME (thing);
1795 if (TREE_CODE (thing) == TYPE_DECL
1796 || (TREE_CODE (thing) == TEMPLATE_DECL
1797 && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL))
1798 thing = DECL_NAME (thing);
1799 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1803 /* CONSTRUCTOR_NAME:
1804 Return the name for the constructor (or destructor) for the
1805 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1806 IDENTIFIER_NODE. When given a template, return the plain
1807 unspecialized name. */
1810 constructor_name (thing)
1814 thing = constructor_name_full (thing);
1815 t = IDENTIFIER_TEMPLATE (thing);
1821 /* Cache the value of this class's main virtual function table pointer
1822 in a register variable. This will save one indirection if a
1823 more than one virtual function call is made this function. */
1828 extern tree base_init_expr;
1830 if (base_init_expr == 0
1831 && DECL_CONSTRUCTOR_P (current_function_decl))
1833 if (processing_template_decl)
1834 add_tree (build_min_nt
1836 current_member_init_list, current_base_init_list));
1838 emit_base_init (current_class_type, 0);
1842 /* Record the existence of an addressable inline function. */
1845 mark_inline_for_output (decl)
1848 decl = DECL_MAIN_VARIANT (decl);
1849 if (DECL_SAVED_INLINE (decl))
1851 my_friendly_assert (TREE_PERMANENT (decl), 363);
1852 DECL_SAVED_INLINE (decl) = 1;
1854 if (DECL_PENDING_INLINE_INFO (decl) != 0
1855 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
1857 struct pending_inline *t = pending_inlines;
1858 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
1861 if (t == DECL_PENDING_INLINE_INFO (decl))
1867 t = DECL_PENDING_INLINE_INFO (decl);
1868 t->next = pending_inlines;
1869 pending_inlines = t;
1871 DECL_PENDING_INLINE_INFO (decl) = 0;
1874 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
1880 temp_name_counter = 0;
1883 /* Hand off a unique name which can be used for variable we don't really
1884 want to know about anyway, for example, the anonymous variables which
1885 are needed to make references work. Declare this thing so we can use it.
1886 The variable created will be of type TYPE.
1888 STATICP is nonzero if this variable should be static. */
1891 get_temp_name (type, staticp)
1895 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
1897 int toplev = toplevel_bindings_p ();
1899 push_obstacks_nochange ();
1900 if (toplev || staticp)
1902 end_temporary_allocation ();
1903 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
1904 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
1908 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
1909 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1911 TREE_USED (decl) = 1;
1912 TREE_STATIC (decl) = staticp;
1913 DECL_ARTIFICIAL (decl) = 1;
1915 /* If this is a local variable, then lay out its rtl now.
1916 Otherwise, callers of this function are responsible for dealing
1917 with this variable's rtl. */
1921 expand_decl_init (decl);
1928 /* Get a variable which we can use for multiple assignments.
1929 It is not entered into current_binding_level, because
1930 that breaks things when it comes time to do final cleanups
1931 (which take place "outside" the binding contour of the function). */
1934 get_temp_regvar (type, init)
1937 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
1940 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
1941 decl = build_decl (VAR_DECL, get_identifier (buf), type);
1942 TREE_USED (decl) = 1;
1943 DECL_REGISTER (decl) = 1;
1946 store_init_value (decl, init);
1948 /* We can expand these without fear, since they cannot need
1949 constructors or destructors. */
1951 expand_decl_init (decl);
1956 /* Make the macro TEMP_NAME_P available to units which do not
1957 include c-tree.h. */
1963 return TEMP_NAME_P (decl);
1966 /* Finish off the processing of a UNION_TYPE structure.
1967 If there are static members, then all members are
1968 static, and must be laid out together. If the
1969 union is an anonymous union, we arrange for that
1970 as well. PUBLIC_P is nonzero if this union is
1971 not declared static. */
1974 finish_anon_union (anon_union_decl)
1975 tree anon_union_decl;
1977 tree type = TREE_TYPE (anon_union_decl);
1978 tree field, main_decl = NULL_TREE;
1979 tree elems = NULL_TREE;
1980 int public_p = TREE_PUBLIC (anon_union_decl);
1981 int static_p = TREE_STATIC (anon_union_decl);
1982 int external_p = DECL_EXTERNAL (anon_union_decl);
1984 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
1989 error ("global anonymous unions must be declared static");
1993 for (; field; field = TREE_CHAIN (field))
1996 if (TREE_CODE (field) != FIELD_DECL)
1999 if (TREE_PRIVATE (field))
2000 cp_pedwarn_at ("private member `%#D' in anonymous union", field);
2001 else if (TREE_PROTECTED (field))
2002 cp_pedwarn_at ("protected member `%#D' in anonymous union", field);
2004 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2005 /* tell `pushdecl' that this is not tentative. */
2006 DECL_INITIAL (decl) = error_mark_node;
2007 TREE_PUBLIC (decl) = public_p;
2008 TREE_STATIC (decl) = static_p;
2009 DECL_EXTERNAL (decl) = external_p;
2010 decl = pushdecl (decl);
2012 /* Only write out one anon union element--choose the one that
2013 can hold them all. */
2014 if (main_decl == NULL_TREE
2015 && 1 == simple_cst_equal (DECL_SIZE (decl),
2016 DECL_SIZE (anon_union_decl)))
2022 /* ??? This causes there to be no debug info written out
2024 TREE_ASM_WRITTEN (decl) = 1;
2027 DECL_INITIAL (decl) = NULL_TREE;
2028 /* If there's a cleanup to do, it belongs in the
2029 TREE_PURPOSE of the following TREE_LIST. */
2030 elems = tree_cons (NULL_TREE, decl, elems);
2031 TREE_TYPE (elems) = type;
2037 make_decl_rtl (main_decl, 0, toplevel_bindings_p ());
2038 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2042 warning ("anonymous union with no members");
2047 /* The following call assumes that there are never any cleanups
2048 for anonymous unions--a reasonable assumption. */
2049 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2052 /* Finish and output a table which is generated by the compiler.
2053 NAME is the name to give the table.
2054 TYPE is the type of the table entry.
2055 INIT is all the elements in the table.
2056 PUBLICP is non-zero if this table should be given external access. */
2059 finish_table (name, type, init, publicp)
2060 tree name, type, init;
2063 tree itype, atype, decl;
2064 static tree empty_table;
2068 itype = build_index_type (size_int (list_length (init) - 1));
2069 atype = build_cplus_array_type (type, itype);
2070 layout_type (atype);
2072 if (TREE_VALUE (init) == integer_zero_node
2073 && TREE_CHAIN (init) == NULL_TREE)
2076 if (empty_table == NULL_TREE)
2079 empty_table = get_temp_name (atype, 1);
2080 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2081 TREE_CONSTANT (init) = 1;
2082 TREE_STATIC (init) = 1;
2083 DECL_INITIAL (empty_table) = init;
2084 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2085 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2086 cp_finish_decl (empty_table, NULL_TREE, asmspec, 0, 0);
2091 if (name == NULL_TREE)
2095 decl = get_temp_name (atype, 1);
2099 decl = build_decl (VAR_DECL, name, atype);
2100 decl = pushdecl (decl);
2101 TREE_STATIC (decl) = 1;
2106 TREE_PUBLIC (decl) = publicp;
2107 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2108 TREE_CONSTANT (init) = 1;
2109 TREE_STATIC (init) = 1;
2110 DECL_INITIAL (decl) = init;
2111 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2112 IDENTIFIER_POINTER (DECL_NAME (decl)));
2116 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2117 DECL_EXTERNAL (decl) = 1;
2118 TREE_STATIC (decl) = 0;
2120 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2121 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2124 cp_finish_decl (decl, NULL_TREE, asmspec, 0, 0);
2128 /* Finish processing a builtin type TYPE. It's name is NAME,
2129 its fields are in the array FIELDS. LEN is the number of elements
2130 in FIELDS minus one, or put another way, it is the maximum subscript
2133 It is given the same alignment as ALIGN_TYPE. */
2136 finish_builtin_type (type, name, fields, len, align_type)
2145 TYPE_FIELDS (type) = fields[0];
2146 for (i = 0; i < len; i++)
2148 layout_type (TREE_TYPE (fields[i]));
2149 DECL_FIELD_CONTEXT (fields[i]) = type;
2150 TREE_CHAIN (fields[i]) = fields[i+1];
2152 DECL_FIELD_CONTEXT (fields[i]) = type;
2153 DECL_CLASS_CONTEXT (fields[i]) = type;
2154 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2156 #if 0 /* not yet, should get fixed properly later */
2157 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2159 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2161 layout_decl (TYPE_NAME (type), 0);
2164 /* Auxiliary functions to make type signatures for
2165 `operator new' and `operator delete' correspond to
2166 what compiler will be expecting. */
2168 extern tree sizetype;
2171 coerce_new_type (type)
2176 if (TREE_CODE (type) == METHOD_TYPE)
2177 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2178 if (TREE_TYPE (type) != ptr_type_node)
2179 e1 = 1, error ("`operator new' must return type `void *'");
2181 /* Technically the type must be `size_t', but we may not know
2183 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2184 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2185 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2186 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2187 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2189 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2191 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2196 coerce_delete_type (type)
2199 int e1 = 0, e2 = 0, e3 = 0;
2200 tree arg_types = TYPE_ARG_TYPES (type);
2202 if (TREE_CODE (type) == METHOD_TYPE)
2204 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2205 arg_types = TREE_CHAIN (arg_types);
2207 if (TREE_TYPE (type) != void_type_node)
2208 e1 = 1, error ("`operator delete' must return type `void'");
2209 if (arg_types == NULL_TREE
2210 || TREE_VALUE (arg_types) != ptr_type_node)
2211 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2214 && TREE_CHAIN (arg_types)
2215 && TREE_CHAIN (arg_types) != void_list_node)
2217 /* Again, technically this argument must be `size_t', but again
2218 we may not know what that is. */
2219 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2220 if (TREE_CODE (t2) != INTEGER_TYPE
2221 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2222 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2223 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2226 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2227 error ("too many arguments in declaration of `operator delete'");
2229 error ("`...' invalid in specification of `operator delete'");
2233 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
2236 if (arg_types == NULL_TREE)
2237 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2239 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2244 type = build_function_type (void_type_node, arg_types);
2249 extern tree abort_fndecl;
2252 mark_vtable_entries (decl)
2255 tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
2259 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries))
2260 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2261 tree fn = TREE_OPERAND (fnaddr, 0);
2262 TREE_ADDRESSABLE (fn) = 1;
2265 skip_rtti_stuff (&entries);
2267 for (; entries; entries = TREE_CHAIN (entries))
2269 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries)
2270 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2271 tree fn = TREE_OPERAND (fnaddr, 0);
2272 TREE_ADDRESSABLE (fn) = 1;
2273 if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn))
2274 TREE_OPERAND (fnaddr, 0) = fn = abort_fndecl;
2275 if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn))
2277 DECL_EXTERNAL (fn) = 0;
2284 /* Set DECL up to have the closest approximation of "initialized common"
2285 linkage available. */
2288 comdat_linkage (decl)
2292 make_decl_one_only (decl);
2294 TREE_PUBLIC (decl) = 0;
2297 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2298 based on TYPE and other static flags.
2300 Note that anything public is tagged TREE_PUBLIC, whether
2301 it's public in this file or in another one. */
2304 import_export_vtable (decl, type, final)
2308 if (DECL_INTERFACE_KNOWN (decl))
2312 if (write_virtuals < 2 && write_virtuals != 0)
2314 TREE_PUBLIC (decl) = 1;
2315 if (write_virtuals < 0)
2316 DECL_EXTERNAL (decl) = 1;
2317 DECL_INTERFACE_KNOWN (decl) = 1;
2319 else if (CLASSTYPE_INTERFACE_KNOWN (type))
2321 TREE_PUBLIC (decl) = 1;
2322 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2323 DECL_INTERFACE_KNOWN (decl) = 1;
2327 /* We can only wait to decide if we have real non-inline virtual
2328 functions in our class, or if we come from a template. */
2330 int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2332 if (! found && ! final)
2335 for (method = TYPE_METHODS (type); method != NULL_TREE;
2336 method = TREE_CHAIN (method))
2337 if (DECL_VINDEX (method) != NULL_TREE
2338 && ! DECL_THIS_INLINE (method)
2339 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2346 if (final || ! found)
2348 comdat_linkage (decl);
2349 DECL_EXTERNAL (decl) = 0;
2353 TREE_PUBLIC (decl) = 1;
2354 DECL_EXTERNAL (decl) = 1;
2360 import_export_template (type)
2363 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2364 && ! flag_implicit_templates
2365 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2367 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2368 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2369 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2374 finish_prevtable_vardecl (prev, vars)
2377 tree ctype = DECL_CONTEXT (vars);
2378 import_export_template (ctype);
2380 #ifndef NO_LINKAGE_HEURISTICS
2381 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype)
2382 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2385 for (method = TYPE_METHODS (ctype); method != NULL_TREE;
2386 method = TREE_CHAIN (method))
2388 if (DECL_VINDEX (method) != NULL_TREE
2389 && !DECL_THIS_INLINE (method)
2390 && !DECL_ABSTRACT_VIRTUAL_P (method))
2392 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2393 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method);
2394 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2401 import_export_vtable (vars, ctype, 1);
2406 finish_vtable_vardecl (prev, vars)
2409 if (write_virtuals >= 0
2410 && ! DECL_EXTERNAL (vars)
2411 && ((TREE_PUBLIC (vars) && ! DECL_WEAK (vars) && ! DECL_ONE_ONLY (vars))
2412 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))
2413 || (hack_decl_function_context (vars) && TREE_USED (vars)))
2414 && ! TREE_ASM_WRITTEN (vars))
2417 mark_vtable_entries (vars);
2418 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2419 store_init_value (vars, DECL_INITIAL (vars));
2421 #ifdef DWARF_DEBUGGING_INFO
2422 if (write_symbols == DWARF_DEBUG)
2424 /* Mark the VAR_DECL node representing the vtable itself as a
2425 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2426 It is rather important that such things be ignored because
2427 any effort to actually generate DWARF for them will run
2428 into trouble when/if we encounter code like:
2431 struct S { virtual void member (); };
2433 because the artificial declaration of the vtable itself (as
2434 manufactured by the g++ front end) will say that the vtable
2435 is a static member of `S' but only *after* the debug output
2436 for the definition of `S' has already been output. This causes
2437 grief because the DWARF entry for the definition of the vtable
2438 will try to refer back to an earlier *declaration* of the
2439 vtable as a static member of `S' and there won't be one.
2440 We might be able to arrange to have the "vtable static member"
2441 attached to the member list for `S' before the debug info for
2442 `S' get written (which would solve the problem) but that would
2443 require more intrusive changes to the g++ front end. */
2445 DECL_IGNORED_P (vars) = 1;
2447 #endif /* DWARF_DEBUGGING_INFO */
2449 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2452 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2453 /* We don't know what to do with this one yet. */
2456 /* We know that PREV must be non-zero here. */
2457 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2462 prune_vtable_vardecl (prev, vars)
2465 /* We know that PREV must be non-zero here. */
2466 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2471 walk_vtables (typedecl_fn, vardecl_fn)
2472 register void (*typedecl_fn)();
2473 register int (*vardecl_fn)();
2478 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2480 register tree type = TREE_TYPE (vars);
2482 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2485 flag |= (*vardecl_fn) (prev, vars);
2487 if (prev && TREE_CHAIN (prev) != vars)
2490 else if (TREE_CODE (vars) == TYPE_DECL
2491 && type != error_mark_node
2492 && TYPE_LANG_SPECIFIC (type)
2493 && CLASSTYPE_VSIZE (type))
2495 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2505 finish_sigtable_vardecl (prev, vars)
2508 /* We don't need to mark sigtable entries as addressable here as is done
2509 for vtables. Since sigtables, unlike vtables, are always written out,
2510 that was already done in build_signature_table_constructor. */
2512 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2514 /* We know that PREV must be non-zero here. */
2515 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2519 walk_sigtables (typedecl_fn, vardecl_fn)
2520 register void (*typedecl_fn)();
2521 register void (*vardecl_fn)();
2525 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2527 register tree type = TREE_TYPE (vars);
2529 if (TREE_CODE (vars) == TYPE_DECL
2530 && type != error_mark_node
2531 && IS_SIGNATURE (type))
2533 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2535 else if (TREE_CODE (vars) == VAR_DECL
2536 && TREE_TYPE (vars) != error_mark_node
2537 && IS_SIGNATURE (TREE_TYPE (vars)))
2539 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2546 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2547 inline function or template instantiation at end-of-file. */
2550 import_export_decl (decl)
2553 if (DECL_INTERFACE_KNOWN (decl))
2556 if (DECL_TEMPLATE_INSTANTIATION (decl))
2558 DECL_NOT_REALLY_EXTERN (decl) = 1;
2559 if (DECL_IMPLICIT_INSTANTIATION (decl)
2560 && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2562 if (TREE_CODE (decl) == FUNCTION_DECL)
2563 comdat_linkage (decl);
2564 /* Dynamically initialized vars go into common. */
2565 else if (DECL_INITIAL (decl) == NULL_TREE
2566 || DECL_INITIAL (decl) == error_mark_node)
2567 DECL_COMMON (decl) = 1;
2568 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
2570 DECL_COMMON (decl) = 1;
2571 DECL_INITIAL (decl) = error_mark_node;
2575 /* Statically initialized vars are weak or comdat, if
2578 make_decl_one_only (decl);
2579 /* else leave vars public so multiple defs will break. */
2583 DECL_NOT_REALLY_EXTERN (decl) = 0;
2585 else if (DECL_FUNCTION_MEMBER_P (decl))
2587 tree ctype = DECL_CLASS_CONTEXT (decl);
2588 if (CLASSTYPE_INTERFACE_KNOWN (ctype) && ! DECL_ARTIFICIAL (decl))
2590 DECL_NOT_REALLY_EXTERN (decl)
2591 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2592 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2595 comdat_linkage (decl);
2597 /* tinfo function */
2598 else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2600 tree ctype = TREE_TYPE (DECL_NAME (decl));
2601 if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2602 && TYPE_VIRTUAL_P (ctype))
2604 DECL_NOT_REALLY_EXTERN (decl)
2605 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2606 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2608 else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2609 DECL_NOT_REALLY_EXTERN (decl) = 0;
2611 comdat_linkage (decl);
2613 else if (DECL_C_STATIC (decl))
2614 TREE_PUBLIC (decl) = 0;
2616 comdat_linkage (decl);
2618 DECL_INTERFACE_KNOWN (decl) = 1;
2622 build_cleanup (decl)
2626 tree type = TREE_TYPE (decl);
2628 if (TREE_CODE (type) == ARRAY_TYPE)
2632 mark_addressable (decl);
2633 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2635 temp = build_delete (TREE_TYPE (temp), temp,
2637 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2641 extern int parse_time, varconst_time;
2642 extern tree pending_templates;
2643 extern tree maybe_templates;
2645 #define TIMEVAR(VAR, BODY) \
2646 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2648 extern struct obstack permanent_obstack;
2649 extern tree get_id_2 ();
2655 tree sname = get_id_2 ("__sn", base);
2656 tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2659 push_obstacks (&permanent_obstack, &permanent_obstack);
2660 sentry = build_decl (VAR_DECL, sname, integer_type_node);
2661 TREE_PUBLIC (sentry) = 1;
2662 DECL_ARTIFICIAL (sentry) = 1;
2663 TREE_STATIC (sentry) = 1;
2664 TREE_USED (sentry) = 1;
2665 DECL_COMMON (sentry) = 1;
2666 pushdecl_top_level (sentry);
2667 cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2673 /* This routine is called from the last rule in yyparse ().
2674 Its job is to create all the code needed to initialize and
2675 destroy the global aggregates. We do the destruction
2676 first, since that way we only need to reverse the decls once. */
2682 int start_time, this_time;
2686 int needs_cleaning = 0, needs_messing_up = 0;
2690 if (flag_detailed_statistics)
2691 dump_tree_statistics ();
2693 /* Bad parse errors. Just forget about it. */
2694 if (! global_bindings_p () || current_class_type)
2697 start_time = get_run_time ();
2699 /* Otherwise, GDB can get confused, because in only knows
2700 about source for LINENO-1 lines. */
2703 interface_unknown = 1;
2706 for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
2708 tree decl = TREE_VALUE (fnname);
2709 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
2711 instantiate_class_template (decl);
2712 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
2713 for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
2714 instantiate_decl (vars);
2717 instantiate_decl (decl);
2720 for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
2722 tree *args, fn, decl = TREE_VALUE (fnname);
2724 if (DECL_INITIAL (decl))
2727 fn = TREE_PURPOSE (fnname);
2728 args = get_bindings (fn, decl);
2729 fn = instantiate_template (fn, args);
2731 instantiate_decl (fn);
2734 /* Push into C language context, because that's all
2736 push_lang_context (lang_name_c);
2739 /* The reason for pushing garbage onto the global_binding_level is to
2740 ensure that we can slice out _DECLs which pertain to virtual function
2741 tables. If the last thing pushed onto the global_binding_level was a
2742 virtual function table, then slicing it out would slice away all the
2743 decls (i.e., we lose the head of the chain).
2745 There are several ways of getting the same effect, from changing the
2746 way that iterators over the chain treat the elements that pertain to
2747 virtual function tables, moving the implementation of this code to
2748 decl.c (where we can manipulate global_binding_level directly),
2749 popping the garbage after pushing it and slicing away the vtable
2750 stuff, or just leaving it alone. */
2752 /* Make last thing in global scope not be a virtual function table. */
2753 #if 0 /* not yet, should get fixed properly later */
2754 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2756 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2758 DECL_IGNORED_P (vars) = 1;
2759 SET_DECL_ARTIFICIAL (vars);
2763 /* Walk to mark the inline functions we need, then output them so
2764 that we can pick up any other tdecls that those routines need. */
2765 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2767 for (vars = pending_statics; vars; vars = TREE_CHAIN (vars))
2769 tree decl = TREE_VALUE (vars);
2771 #ifdef DWARF_DEBUGGING_INFO
2772 /* Output DWARF information for file-scope tentative data object
2775 if (write_symbols == DWARF_DEBUG)
2776 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2778 if (DECL_TEMPLATE_INSTANTIATION (decl)
2779 && ! DECL_IN_AGGR_P (decl))
2781 import_export_decl (decl);
2782 DECL_EXTERNAL (decl) = ! DECL_NOT_REALLY_EXTERN (decl);
2786 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2787 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
2788 rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
2789 vars = static_aggregates;
2791 if (static_ctors || vars || exception_table_p ())
2792 needs_messing_up = 1;
2796 /* See if we really need the hassle. */
2797 while (vars && needs_cleaning == 0)
2799 tree decl = TREE_VALUE (vars);
2800 tree type = TREE_TYPE (decl);
2801 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars))
2807 vars = TREE_CHAIN (vars);
2810 if (needs_cleaning == 0)
2813 fnname = get_file_function_name ('D');
2814 start_function (void_list_node,
2815 make_call_declarator (fnname, void_list_node, NULL_TREE,
2818 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2819 store_parm_decls ();
2824 expand_start_bindings (0);
2826 /* These must be done in backward order to destroy,
2827 in which they happen to be! */
2828 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2830 tree decl = TREE_VALUE (vars);
2831 tree type = TREE_TYPE (decl);
2832 tree temp = TREE_PURPOSE (vars);
2834 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
2835 && ! DECL_EXTERNAL (decl))
2837 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2838 || DECL_ONE_ONLY (decl)
2839 || DECL_WEAK (decl)));
2841 temp = build_cleanup (decl);
2845 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2846 sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
2847 sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
2848 expand_start_cond (sentry, 0);
2851 expand_expr_stmt (temp);
2858 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2859 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2862 expand_end_bindings (getdecls (), 1, 0);
2866 finish_function (lineno, 0, 0);
2868 assemble_destructor (IDENTIFIER_POINTER (fnname));
2870 /* if it needed cleaning, then it will need messing up: drop through */
2873 /* Must do this while we think we are at the top level. */
2874 vars = nreverse (static_aggregates);
2875 if (needs_messing_up)
2877 fnname = get_file_function_name ('I');
2878 start_function (void_list_node,
2879 make_call_declarator (fnname, void_list_node, NULL_TREE,
2882 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2883 store_parm_decls ();
2888 expand_start_bindings (0);
2890 if (exception_table_p ())
2891 register_exception_table ();
2895 extern int temp_slot_level;
2896 extern int target_temp_slot_level;
2897 tree decl = TREE_VALUE (vars);
2898 tree init = TREE_PURPOSE (vars);
2899 tree old_cleanups = cleanups_this_call;
2900 int old_temp_level = target_temp_slot_level;
2903 target_temp_slot_level = temp_slot_level;
2905 /* If this was a static attribute within some function's scope,
2906 then don't initialize it here. Also, don't bother
2907 with initializers that contain errors. */
2908 if (TREE_STATIC (vars)
2909 || DECL_EXTERNAL (decl)
2910 || (init && TREE_CODE (init) == TREE_LIST
2911 && value_member (error_mark_node, init)))
2914 if (TREE_CODE (decl) == VAR_DECL)
2916 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2917 || DECL_ONE_ONLY (decl)
2918 || DECL_WEAK (decl)));
2920 /* Set these global variables so that GDB at least puts
2921 us near the declaration which required the initialization. */
2922 input_filename = DECL_SOURCE_FILE (decl);
2923 lineno = DECL_SOURCE_LINE (decl);
2924 emit_note (input_filename, lineno);
2926 /* 9.5p5: The initializer of a static member of a class has
2927 the same access rights as a member function. */
2928 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2929 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
2933 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2934 sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
2935 sentry = build_binary_op
2936 (EQ_EXPR, sentry, integer_one_node, 1);
2937 expand_start_cond (sentry, 0);
2940 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2941 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2942 expand_aggr_init (decl, init, 0, 0);
2943 else if (TREE_CODE (init) == TREE_VEC)
2945 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2946 TREE_VEC_ELT (init, 1),
2947 TREE_VEC_ELT (init, 2), 0),
2948 const0_rtx, VOIDmode, 0);
2951 expand_assignment (decl, init, 0, 0);
2956 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2957 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
2959 else if (decl == error_mark_node)
2961 else my_friendly_abort (22);
2963 /* Cleanup any temporaries needed for the initial value. */
2964 expand_cleanups_to (old_cleanups);
2968 target_temp_slot_level = old_temp_level;
2970 vars = TREE_CHAIN (vars);
2973 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
2974 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
2977 expand_end_bindings (getdecls (), 1, 0);
2981 finish_function (lineno, 0, 0);
2982 assemble_constructor (IDENTIFIER_POINTER (fnname));
2985 expand_builtin_throw ();
2987 permanent_allocation (1);
2989 /* Done with C language context needs. */
2990 pop_lang_context ();
2992 /* Now write out any static class variables (which may have since
2993 learned how to be initialized). */
2994 while (pending_statics)
2996 tree decl = TREE_VALUE (pending_statics);
2998 if (TREE_USED (decl) == 1
2999 || TREE_READONLY (decl) == 0
3000 || DECL_INITIAL (decl) == 0)
3002 DECL_DEFER_OUTPUT (decl) = 0;
3003 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3005 pending_statics = TREE_CHAIN (pending_statics);
3008 this_time = get_run_time ();
3009 parse_time -= this_time - start_time;
3010 varconst_time += this_time - start_time;
3012 start_time = get_run_time ();
3014 if (flag_handle_signatures)
3015 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3017 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3019 tree decl = TREE_VALUE (fnname);
3020 import_export_decl (decl);
3023 /* Now write out inline functions which had their addresses taken and
3024 which were not declared virtual and which were not declared `extern
3027 int reconsider = 1; /* More may be referenced; check again */
3031 tree *p = &saved_inlines;
3034 /* We need to do this each time so that newly completed template
3035 types don't wind up at the front of the list. Sigh. */
3036 vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3037 DECL_IGNORED_P (vars) = 1;
3038 SET_DECL_ARTIFICIAL (vars);
3041 reconsider |= walk_vtables ((void (*)())0, finish_vtable_vardecl);
3045 tree decl = TREE_VALUE (*p);
3047 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3049 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3051 if (DECL_MUTABLE_P (decl))
3052 synthesize_tinfo_fn (decl);
3054 synthesize_method (decl);
3058 /* Catch new template instantiations. */
3059 if (decl != TREE_VALUE (*p))
3062 if (TREE_ASM_WRITTEN (decl)
3063 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3064 *p = TREE_CHAIN (*p);
3065 else if (DECL_INITIAL (decl) == 0)
3066 p = &TREE_CHAIN (*p);
3067 else if ((TREE_PUBLIC (decl) && ! DECL_WEAK (decl)
3068 && ! DECL_ONE_ONLY (decl))
3069 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3070 || flag_keep_inline_functions)
3072 if (DECL_NOT_REALLY_EXTERN (decl))
3074 DECL_EXTERNAL (decl) = 0;
3076 /* We can't inline this function after it's been
3077 emitted, so just disable inlining. We want a
3078 variant of output_inline_function that doesn't
3079 prevent subsequent integration... */
3081 temporary_allocation ();
3082 output_inline_function (decl);
3083 permanent_allocation (1);
3086 *p = TREE_CHAIN (*p);
3089 p = &TREE_CHAIN (*p);
3094 /* Now delete from the chain of variables all virtual function tables.
3095 We output them all ourselves, because each will be treated specially. */
3097 walk_vtables ((void (*)())0, prune_vtable_vardecl);
3099 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3101 if (TREE_CODE (vars) == FUNCTION_DECL
3102 && ! DECL_INTERFACE_KNOWN (vars)
3103 && DECL_C_STATIC (vars))
3104 TREE_PUBLIC (vars) = 0;
3107 if (write_virtuals == 2)
3109 /* Now complain about an virtual function tables promised
3110 but not delivered. */
3111 while (pending_vtables)
3113 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3114 error ("virtual function table for `%s' not defined",
3115 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3116 pending_vtables = TREE_CHAIN (pending_vtables);
3122 this_time = get_run_time ();
3123 parse_time -= this_time - start_time;
3124 varconst_time += this_time - start_time;
3126 if (flag_detailed_statistics)
3127 dump_time_statistics ();
3130 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3131 expr. Since it was parsed like a type, we need to wade through and fix
3132 that. Unfortunately, since operator() is left-associative, we can't use
3133 tail recursion. In the above example, TYPE is `A', and DECL is
3136 Maybe this shouldn't be recursive, but how often will it actually be
3140 reparse_absdcl_as_expr (type, decl)
3143 /* do build_functional_cast (type, NULL_TREE) at bottom */
3144 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3145 return build_functional_cast (type, NULL_TREE);
3148 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3150 decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3152 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3153 decl = require_complete_type (decl);
3158 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3159 out to be an expr. Since it was parsed like a type, we need to wade
3160 through and fix that. Since casts are right-associative, we are
3161 reversing the order, so we don't have to recurse.
3163 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3167 reparse_absdcl_as_casts (decl, expr)
3172 if (TREE_CODE (expr) == CONSTRUCTOR
3173 && TREE_TYPE (expr) == 0)
3175 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3176 decl = TREE_OPERAND (decl, 0);
3178 if (IS_SIGNATURE (type))
3180 error ("cast specifies signature type");
3181 return error_mark_node;
3184 expr = digest_init (type, expr, (tree *) 0);
3185 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3187 int failure = complete_array_type (type, expr, 1);
3189 my_friendly_abort (78);
3195 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3196 decl = TREE_OPERAND (decl, 0);
3197 expr = build_c_cast (type, expr, 0);
3203 /* Given plain tree nodes for an expression, build up the full semantics. */
3206 build_expr_from_tree (t)
3209 if (t == NULL_TREE || t == error_mark_node)
3212 switch (TREE_CODE (t))
3214 case IDENTIFIER_NODE:
3215 return do_identifier (t, 0);
3218 if (LOOKUP_EXPR_GLOBAL (t))
3219 return do_scoped_id (TREE_OPERAND (t, 0), 0);
3221 return do_identifier (TREE_OPERAND (t, 0), 0);
3224 return build_x_indirect_ref
3225 (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3228 return build_functional_cast
3229 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3231 case REINTERPRET_CAST_EXPR:
3232 return build_reinterpret_cast
3233 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3235 case CONST_CAST_EXPR:
3236 return build_const_cast
3237 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3239 case DYNAMIC_CAST_EXPR:
3240 return build_dynamic_cast
3241 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3243 case STATIC_CAST_EXPR:
3244 return build_static_cast
3245 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3247 case PREDECREMENT_EXPR:
3248 case PREINCREMENT_EXPR:
3249 case POSTDECREMENT_EXPR:
3250 case POSTINCREMENT_EXPR:
3254 case TRUTH_NOT_EXPR:
3256 case CONVERT_EXPR: /* Unary + */
3259 return build_x_unary_op (TREE_CODE (t),
3260 build_expr_from_tree (TREE_OPERAND (t, 0)));
3265 case TRUNC_DIV_EXPR:
3267 case FLOOR_DIV_EXPR:
3268 case ROUND_DIV_EXPR:
3269 case EXACT_DIV_EXPR:
3271 case BIT_ANDTC_EXPR:
3274 case TRUNC_MOD_EXPR:
3275 case FLOOR_MOD_EXPR:
3276 case TRUTH_ANDIF_EXPR:
3277 case TRUTH_ORIF_EXPR:
3278 case TRUTH_AND_EXPR:
3293 return build_x_binary_op
3295 build_expr_from_tree (TREE_OPERAND (t, 0)),
3296 build_expr_from_tree (TREE_OPERAND (t, 1)));
3299 return build_m_component_ref
3300 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3301 build_expr_from_tree (TREE_OPERAND (t, 1)));
3304 return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3307 if (TREE_OPERAND (t, 0) == NULL_TREE)
3309 return build_parse_node (ARRAY_REF, NULL_TREE,
3310 build_expr_from_tree (TREE_OPERAND (t, 1)));
3311 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3312 build_expr_from_tree (TREE_OPERAND (t, 1)));
3316 tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3317 if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3319 return c_sizeof (r);
3323 return build_x_modify_expr
3324 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3325 TREE_CODE (TREE_OPERAND (t, 1)),
3326 build_expr_from_tree (TREE_OPERAND (t, 2)));
3329 return build_x_arrow
3330 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3334 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3335 build_expr_from_tree (TREE_OPERAND (t, 1)),
3336 build_expr_from_tree (TREE_OPERAND (t, 2)),
3337 NEW_EXPR_USE_GLOBAL (t));
3340 return delete_sanity
3341 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3342 build_expr_from_tree (TREE_OPERAND (t, 1)),
3343 DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3346 if (TREE_OPERAND (t, 1) == NULL_TREE)
3347 return build_x_compound_expr
3348 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3350 my_friendly_abort (42);
3352 case METHOD_CALL_EXPR:
3353 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3355 tree ref = TREE_OPERAND (t, 0);
3356 return build_scoped_method_call
3357 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3358 build_expr_from_tree (TREE_OPERAND (ref, 0)),
3359 TREE_OPERAND (ref, 1),
3360 build_expr_from_tree (TREE_OPERAND (t, 2)));
3362 return build_method_call
3363 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3364 TREE_OPERAND (t, 0),
3365 build_expr_from_tree (TREE_OPERAND (t, 2)),
3366 NULL_TREE, LOOKUP_NORMAL);
3369 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3371 tree ref = TREE_OPERAND (t, 0);
3372 return build_member_call
3373 (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3374 TREE_OPERAND (ref, 1),
3375 build_expr_from_tree (TREE_OPERAND (t, 1)));
3379 tree name = TREE_OPERAND (t, 0);
3380 if (! really_overloaded_fn (name))
3381 name = build_expr_from_tree (name);
3382 return build_x_function_call
3383 (name, build_expr_from_tree (TREE_OPERAND (t, 1)),
3388 return build_x_conditional_expr
3389 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3390 build_expr_from_tree (TREE_OPERAND (t, 1)),
3391 build_expr_from_tree (TREE_OPERAND (t, 2)));
3395 tree purpose, value, chain;
3397 if (t == void_list_node)
3400 purpose = TREE_PURPOSE (t);
3402 purpose = build_expr_from_tree (purpose);
3403 value = TREE_VALUE (t);
3405 value = build_expr_from_tree (value);
3406 chain = TREE_CHAIN (t);
3407 if (chain && chain != void_type_node)
3408 chain = build_expr_from_tree (chain);
3409 return tree_cons (purpose, value, chain);
3413 return build_x_component_ref
3414 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3415 TREE_OPERAND (t, 1), NULL_TREE, 1);
3418 return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3422 tree r = build_nt (CONSTRUCTOR, NULL_TREE,
3423 build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3426 return digest_init (TREE_TYPE (t), r, 0);
3431 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3438 /* This is something of the form `int (*a)++' that has turned out to be an
3439 expr. It was only converted into parse nodes, so we need to go through
3440 and build up the semantics. Most of the work is done by
3441 build_expr_from_tree, above.
3443 In the above example, TYPE is `int' and DECL is `*a'. */
3446 reparse_decl_as_expr (type, decl)
3449 decl = build_expr_from_tree (decl);
3451 return build_functional_cast (type, build_tree_list (NULL_TREE, decl));
3456 /* This is something of the form `int (*a)' that has turned out to be a
3457 decl. It was only converted into parse nodes, so we need to do the
3458 checking that make_{pointer,reference}_declarator do. */
3461 finish_decl_parsing (decl)
3464 extern int current_class_depth;
3466 switch (TREE_CODE (decl))
3468 case IDENTIFIER_NODE:
3471 return make_pointer_declarator
3472 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3474 return make_reference_declarator
3475 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3477 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3480 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3481 TREE_COMPLEXITY (decl) = current_class_depth;
3484 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3487 my_friendly_abort (5);
3493 check_cp_case_value (value)
3496 if (value == NULL_TREE)
3499 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3500 STRIP_TYPE_NOPS (value);
3502 if (TREE_READONLY_DECL_P (value))
3504 value = decl_constant_value (value);
3505 STRIP_TYPE_NOPS (value);
3507 value = fold (value);
3509 if (TREE_CODE (value) != INTEGER_CST
3510 && value != error_mark_node)
3512 cp_error ("case label `%E' does not reduce to an integer constant",
3514 value = error_mark_node;
3517 /* Promote char or short to int. */
3518 value = default_conversion (value);
3520 constant_expression_warning (value);
3525 tree current_namespace;
3527 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3528 postfix. Returns 0 if in global namespace. */
3533 tree x = current_namespace;
3535 x = TREE_PURPOSE (x);
3539 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3542 current_namespace_id (name)
3545 tree old_id = get_namespace_id ();
3548 /* Global names retain old encoding. */
3552 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3553 + IDENTIFIER_LENGTH (name));
3554 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3555 IDENTIFIER_POINTER (name));
3556 return get_identifier (buf);
3560 do_namespace_alias (alias, namespace)
3561 tree alias, namespace;
3563 sorry ("namespace alias");
3567 do_toplevel_using_decl (decl)
3570 if (decl == NULL_TREE || decl == error_mark_node)
3573 if (TREE_CODE (decl) == SCOPE_REF)
3574 decl = resolve_scope_to_name (NULL_TREE, decl);
3576 /* Is this the right way to do an id list? */
3577 if (TREE_CODE (decl) != TREE_LIST)
3584 pushdecl (TREE_VALUE (decl));
3585 decl = TREE_CHAIN (decl);
3590 do_class_using_decl (decl)
3595 if (TREE_CODE (decl) != SCOPE_REF)
3597 cp_error ("using-declaration for non-member at class scope");
3600 name = TREE_OPERAND (decl, 1);
3601 if (TREE_CODE (name) == BIT_NOT_EXPR)
3603 cp_error ("using-declaration for destructor");
3607 value = build_lang_field_decl (USING_DECL, name, void_type_node);
3608 DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
3613 do_using_directive (namespace)
3616 sorry ("using directive");
3620 check_default_args (x)
3623 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
3624 int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
3625 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
3627 if (TREE_PURPOSE (arg))
3631 cp_error ("default argument missing for parameter %P of `%#D'",
3642 TREE_USED (decl) = 1;
3643 if (processing_template_decl)
3645 assemble_external (decl);
3646 /* Is it a synthesized method that needs to be synthesized? */
3647 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
3648 && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3649 /* Kludge: don't synthesize for default args. */
3650 && current_function_decl)
3651 synthesize_method (decl);
3652 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
3653 instantiate_decl (decl);