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;
46 /* A list of virtual function tables we must make sure to write out. */
49 /* A list of static class variables. This is needed, because a
50 static class variable can be declared inside the class without
51 an initializer, and then initialized, staticly, outside the class. */
54 /* A list of functions which were declared inline, but which we
55 may need to emit outline anyway. */
56 static tree saved_inlines;
58 /* Used to help generate temporary names which are unique within
59 a function. Reset to 0 by start_function. */
61 int temp_name_counter;
63 /* Same, but not reset. Local temp variables and global temp variables
64 can have the same name. */
65 static int global_temp_name_counter;
67 /* Flag used when debugging spew.c */
69 extern int spew_debug;
71 /* Nonzero if we're done parsing and into end-of-file activities. */
75 /* Functions called along with real static constructors and destructors. */
77 tree static_ctors, static_dtors;
79 /* C (and C++) language-specific option variables. */
81 /* Nonzero means allow type mismatches in conditional expressions;
82 just make their values `void'. */
84 int flag_cond_mismatch;
86 /* Nonzero means give `double' the same size as `float'. */
88 int flag_short_double;
90 /* Nonzero means don't recognize the keyword `asm'. */
94 /* Nonzero means don't recognize any extension keywords. */
96 int flag_no_gnu_keywords;
98 /* Nonzero means don't recognize the non-ANSI builtin functions. */
102 /* Nonzero means don't recognize the non-ANSI builtin functions.
105 int flag_no_nonansi_builtin;
107 /* Nonzero means do some things the same way PCC does. Only provided so
108 the compiler will link. */
110 int flag_traditional;
112 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
114 int flag_signed_bitfields = 1;
116 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
120 /* Nonzero means enable obscure ANSI features and disable GNU extensions
121 that might cause ANSI-compliant code to be miscompiled. */
125 /* Nonzero means do argument matching for overloading according to the
126 ANSI rules, rather than what g++ used to believe to be correct. */
128 int flag_ansi_overloading = 1;
130 /* Nonzero means do emit exported implementations of functions even if
131 they can be inlined. */
133 int flag_implement_inlines = 1;
135 /* Nonzero means do emit exported implementations of templates, instead of
136 multiple static copies in each file that needs a definition. */
138 int flag_external_templates;
140 /* Nonzero means that the decision to emit or not emit the implementation of a
141 template depends on where the template is instantiated, rather than where
144 int flag_alt_external_templates;
146 /* Nonzero means that implicit instantiations will be emitted if needed. */
148 int flag_implicit_templates = 1;
150 /* Nonzero means warn about implicit declarations. */
152 int warn_implicit = 1;
154 /* Nonzero means warn when all ctors or dtors are private, and the class
157 int warn_ctor_dtor_privacy = 1;
159 /* True if we want to implement vtables using "thunks".
160 The default is off. */
162 #if defined(NEW_OVER) && defined (__i386__)
163 int flag_vtable_thunks = 1;
165 int flag_vtable_thunks;
168 /* True if we want to deal with repository information. */
170 int flag_use_repository;
172 /* Nonzero means give string constants the type `const char *'
173 to get extra warnings from them. These warnings will be too numerous
174 to be useful, except in thoroughly ANSIfied programs. */
176 int warn_write_strings;
178 /* Nonzero means warn about pointer casts that can drop a type qualifier
179 from the pointer target type. */
183 /* Nonzero means warn that dbx info for template class methods isn't fully
186 int warn_template_debugging;
188 /* Nonzero means warn about sizeof(function) or addition/subtraction
189 of function pointers. */
191 int warn_pointer_arith = 1;
193 /* Nonzero means warn for any function def without prototype decl. */
195 int warn_missing_prototypes;
197 /* Nonzero means warn about multiple (redundant) decls for the same single
198 variable or function. */
200 int warn_redundant_decls;
202 /* Warn if initializer is not completely bracketed. */
204 int warn_missing_braces;
206 /* Warn about comparison of signed and unsigned values. */
208 int warn_sign_compare;
210 /* Warn about *printf or *scanf format/argument anomalies. */
214 /* Warn about a subscript that has type char. */
216 int warn_char_subscripts;
218 /* Warn if a type conversion is done that might have confusing results. */
222 /* Warn if adding () is suggested. */
224 int warn_parentheses;
226 /* Non-zero means warn in function declared in derived class has the
227 same name as a virtual in the base class, but fails to match the
228 type signature of any virtual function in the base class. */
229 int warn_overloaded_virtual;
231 /* Non-zero means warn when declaring a class that has a non virtual
232 destructor, when it really ought to have a virtual one. */
235 /* Non-zero means warn when a function is declared extern and later inline. */
236 int warn_extern_inline;
238 /* Non-zero means warn when the compiler will reorder code. */
241 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
244 /* Non-zero means warn when we convert a pointer to member function
245 into a pointer to (void or function). */
246 int warn_pmf2ptr = 1;
248 /* Nonzero means `$' can be in an identifier.
249 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
251 #ifndef DOLLARS_IN_IDENTIFIERS
252 #define DOLLARS_IN_IDENTIFIERS 1
254 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
256 /* Nonzero for -fno-strict-prototype switch: do not consider empty
257 argument prototype to mean function takes no arguments. */
259 int flag_strict_prototype = 2;
260 int strict_prototype = 1;
261 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
263 /* Nonzero means that labels can be used as first-class objects */
267 /* Non-zero means to collect statistics which might be expensive
268 and to print them when we are done. */
269 int flag_detailed_statistics;
271 /* C++ specific flags. */
272 /* Nonzero for -fall-virtual: make every member function (except
273 constructors) lay down in the virtual function table. Calls
274 can then either go through the virtual function table or not,
277 int flag_all_virtual;
279 /* Zero means that `this' is a *const. This gives nice behavior in the
280 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
281 -2 means we're constructing an object and it has fixed type. */
283 int flag_this_is_variable;
285 /* Nonzero means memoize our member lookups. */
287 int flag_memoize_lookups; int flag_save_memoized_contexts;
289 /* 3 means write out only virtuals function tables `defined'
290 in this implementation file.
291 2 means write out only specific virtual function tables
292 and give them (C) public access.
293 1 means write out virtual function tables and give them
295 0 means write out virtual function tables and give them
296 (C) static access (default).
297 -1 means declare virtual function tables extern. */
301 /* Nonzero means we should attempt to elide constructors when possible. */
303 int flag_elide_constructors;
305 /* Nonzero means recognize and handle signature language constructs. */
307 int flag_handle_signatures;
309 /* Nonzero means that member functions defined in class scope are
310 inline by default. */
312 int flag_default_inline = 1;
314 /* Controls whether enums and ints freely convert.
315 1 means with complete freedom.
316 0 means enums can convert to ints, but not vice-versa. */
317 int flag_int_enum_equivalence;
319 /* Controls whether compiler generates 'type descriptor' that give
320 run-time type information. */
323 /* Nonzero if we wish to output cross-referencing information
324 for the GNU class browser. */
325 extern int flag_gnu_xref;
327 /* Nonzero if compiler can make `reasonable' assumptions about
328 references and objects. For example, the compiler must be
329 conservative about the following and not assume that `a' is nonnull:
334 In general, it is `reasonable' to assume that for many programs,
335 and better code can be generated in that case. */
337 int flag_assume_nonnull_objects = 1;
339 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
342 int flag_huge_objects;
344 /* Nonzero if we want to conserve space in the .o files. We do this
345 by putting uninitialized data and runtime initialized data into
346 .common instead of .data at the expense of not flagging multiple
349 int flag_conserve_space;
351 /* Nonzero if we want to obey access control semantics. */
353 int flag_access_control = 1;
355 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
357 int flag_operator_names;
359 /* Nonzero if we want to check the return value of new and avoid calling
360 constructors if it is a null pointer. */
364 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
365 initialization variables.
366 0: Old rules, set by -fno-for-scope.
367 2: New ANSI rules, set by -ffor-scope.
368 1: Try to implement new ANSI rules, but with backup compatibility
369 (and warnings). This is the default, for now. */
371 int flag_new_for_scope = 1;
373 /* Nonzero if we want to emit defined symbols with common-like linkage as
374 weak symbols where possible, in order to conform to C++ semantics.
375 Otherwise, emit them as local symbols. */
379 /* Table of language-dependent -f options.
380 STRING is the option name. VARIABLE is the address of the variable.
381 ON_VALUE is the value to store in VARIABLE
382 if `-fSTRING' is seen as an option.
383 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
385 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
387 {"signed-char", &flag_signed_char, 1},
388 {"unsigned-char", &flag_signed_char, 0},
389 {"signed-bitfields", &flag_signed_bitfields, 1},
390 {"unsigned-bitfields", &flag_signed_bitfields, 0},
391 {"short-enums", &flag_short_enums, 1},
392 {"short-double", &flag_short_double, 1},
393 {"cond-mismatch", &flag_cond_mismatch, 1},
394 {"asm", &flag_no_asm, 0},
395 {"builtin", &flag_no_builtin, 0},
396 {"ident", &flag_no_ident, 0},
397 {"labels-ok", &flag_labels_ok, 1},
398 {"stats", &flag_detailed_statistics, 1},
399 {"this-is-variable", &flag_this_is_variable, 1},
400 {"strict-prototype", &flag_strict_prototype, 1},
401 {"all-virtual", &flag_all_virtual, 1},
402 {"memoize-lookups", &flag_memoize_lookups, 1},
403 {"elide-constructors", &flag_elide_constructors, 1},
404 {"handle-signatures", &flag_handle_signatures, 1},
405 {"default-inline", &flag_default_inline, 1},
406 {"dollars-in-identifiers", &dollars_in_ident, 1},
407 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
408 {"rtti", &flag_rtti, 1},
409 {"xref", &flag_gnu_xref, 1},
410 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
411 {"implement-inlines", &flag_implement_inlines, 1},
412 {"external-templates", &flag_external_templates, 1},
413 {"implicit-templates", &flag_implicit_templates, 1},
414 {"ansi-overloading", &flag_ansi_overloading, 1},
415 {"huge-objects", &flag_huge_objects, 1},
416 {"conserve-space", &flag_conserve_space, 1},
417 {"vtable-thunks", &flag_vtable_thunks, 1},
418 {"short-temps", &flag_short_temps, 1},
419 {"access-control", &flag_access_control, 1},
420 {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
421 {"gnu-keywords", &flag_no_gnu_keywords, 0},
422 {"operator-names", &flag_operator_names, 1},
423 {"check-new", &flag_check_new, 1},
424 {"repo", &flag_use_repository, 1},
425 {"for-scope", &flag_new_for_scope, 2},
426 {"weak", &flag_weak, 1}
429 /* Decode the string P as a language-specific option.
430 Return 1 if it is recognized (and handle it);
431 return 0 if not recognized. */
434 lang_decode_option (p)
437 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
438 dollars_in_ident = 1, flag_writable_strings = 1,
439 flag_this_is_variable = 1, flag_new_for_scope = 0;
440 /* The +e options are for cfront compatibility. They come in as
441 `-+eN', to kludge around gcc.c's argument handling. */
442 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
444 int old_write_virtuals = write_virtuals;
447 else if (p[3] == '0')
449 else if (p[3] == '2')
451 else error ("invalid +e option");
452 if (old_write_virtuals != 0
453 && write_virtuals != old_write_virtuals)
454 error ("conflicting +e options given");
456 else if (p[0] == '-' && p[1] == 'f')
458 /* Some kind of -f option.
459 P's value is the option sans `-f'.
460 Search for it in the table of options. */
464 /* Try special -f options. */
466 if (!strcmp (p, "save-memoized"))
468 flag_memoize_lookups = 1;
469 flag_save_memoized_contexts = 1;
472 if (!strcmp (p, "no-save-memoized"))
474 flag_memoize_lookups = 0;
475 flag_save_memoized_contexts = 0;
478 else if (! strcmp (p, "alt-external-templates"))
480 flag_external_templates = 1;
481 flag_alt_external_templates = 1;
484 else if (! strcmp (p, "no-alt-external-templates"))
486 flag_alt_external_templates = 0;
489 else if (!strcmp (p, "repo"))
491 flag_use_repository = 1;
492 flag_implicit_templates = 0;
496 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
499 if (!strcmp (p, lang_f_options[j].string))
501 *lang_f_options[j].variable = lang_f_options[j].on_value;
502 /* A goto here would be cleaner,
503 but breaks the vax pcc. */
506 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
507 && ! strcmp (p+3, lang_f_options[j].string))
509 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
515 else if (p[0] == '-' && p[1] == 'W')
519 /* The -W options control the warning behavior of the compiler. */
522 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
525 if (!strcmp (p, "implicit"))
526 warn_implicit = setting;
527 else if (!strcmp (p, "return-type"))
528 warn_return_type = setting;
529 else if (!strcmp (p, "ctor-dtor-privacy"))
530 warn_ctor_dtor_privacy = setting;
531 else if (!strcmp (p, "write-strings"))
532 warn_write_strings = setting;
533 else if (!strcmp (p, "cast-qual"))
534 warn_cast_qual = setting;
535 else if (!strcmp (p, "char-subscripts"))
536 warn_char_subscripts = setting;
537 else if (!strcmp (p, "pointer-arith"))
538 warn_pointer_arith = setting;
539 else if (!strcmp (p, "missing-prototypes"))
540 warn_missing_prototypes = setting;
541 else if (!strcmp (p, "redundant-decls"))
542 warn_redundant_decls = setting;
543 else if (!strcmp (p, "missing-braces"))
544 warn_missing_braces = setting;
545 else if (!strcmp (p, "sign-compare"))
546 warn_sign_compare = setting;
547 else if (!strcmp (p, "format"))
548 warn_format = setting;
549 else if (!strcmp (p, "conversion"))
550 warn_conversion = setting;
551 else if (!strcmp (p, "parentheses"))
552 warn_parentheses = setting;
553 else if (!strcmp (p, "non-virtual-dtor"))
554 warn_nonvdtor = setting;
555 else if (!strcmp (p, "extern-inline"))
556 warn_extern_inline = setting;
557 else if (!strcmp (p, "reorder"))
558 warn_reorder = setting;
559 else if (!strcmp (p, "synth"))
560 warn_synth = setting;
561 else if (!strcmp (p, "pmf-conversions"))
562 warn_pmf2ptr = setting;
563 else if (!strcmp (p, "comment"))
564 ; /* cpp handles this one. */
565 else if (!strcmp (p, "comments"))
566 ; /* cpp handles this one. */
567 else if (!strcmp (p, "trigraphs"))
568 ; /* cpp handles this one. */
569 else if (!strcmp (p, "import"))
570 ; /* cpp handles this one. */
571 else if (!strcmp (p, "all"))
573 warn_return_type = setting;
574 warn_unused = setting;
575 warn_implicit = setting;
576 warn_ctor_dtor_privacy = setting;
577 warn_switch = setting;
578 warn_format = setting;
579 warn_parentheses = setting;
580 warn_missing_braces = setting;
581 warn_sign_compare = setting;
582 warn_extern_inline = setting;
583 warn_nonvdtor = setting;
584 /* We save the value of warn_uninitialized, since if they put
585 -Wuninitialized on the command line, we need to generate a
586 warning about not using it without also specifying -O. */
587 if (warn_uninitialized != 1)
588 warn_uninitialized = (setting ? 2 : 0);
589 warn_template_debugging = setting;
590 warn_reorder = setting;
593 else if (!strcmp (p, "overloaded-virtual"))
594 warn_overloaded_virtual = setting;
597 else if (!strcmp (p, "-ansi"))
598 dollars_in_ident = 0, flag_no_nonansi_builtin = 1, flag_ansi = 1,
599 flag_no_gnu_keywords = 1, flag_operator_names = 1;
601 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
602 it's probably safe to assume no sane person would ever want to use this
603 under normal circumstances. */
604 else if (!strcmp (p, "-spew-debug"))
613 /* Incorporate `const' and `volatile' qualifiers for member functions.
614 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
615 QUALS is a list of qualifiers. */
618 grok_method_quals (ctype, function, quals)
619 tree ctype, function, quals;
621 tree fntype = TREE_TYPE (function);
622 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
626 extern tree ridpointers[];
628 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
630 if (TYPE_READONLY (ctype))
631 error ("duplicate `%s' %s",
632 IDENTIFIER_POINTER (TREE_VALUE (quals)),
633 (TREE_CODE (function) == FUNCTION_DECL
634 ? "for member function" : "in type declaration"));
635 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
636 build_pointer_type (ctype);
638 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
640 if (TYPE_VOLATILE (ctype))
641 error ("duplicate `%s' %s",
642 IDENTIFIER_POINTER (TREE_VALUE (quals)),
643 (TREE_CODE (function) == FUNCTION_DECL
644 ? "for member function" : "in type declaration"));
645 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
646 build_pointer_type (ctype);
649 my_friendly_abort (20);
650 quals = TREE_CHAIN (quals);
653 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
654 (TREE_CODE (fntype) == METHOD_TYPE
655 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
656 : TYPE_ARG_TYPES (fntype)));
658 fntype = build_exception_variant (fntype, raises);
660 TREE_TYPE (function) = fntype;
664 #if 0 /* Not used. */
665 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
666 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
667 /* This does not yet work with user defined conversion operators
671 substitute_nice_name (decl)
674 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
676 char *n = decl_as_string (DECL_NAME (decl), 1);
677 if (n[strlen (n) - 1] == ' ')
678 n[strlen (n) - 1] = 0;
679 DECL_NAME (decl) = get_identifier (n);
684 /* Warn when -fexternal-templates is used and #pragma
685 interface/implementation is not used all the times it should be,
689 warn_if_unknown_interface (decl)
692 static int already_warned = 0;
693 if (already_warned++)
696 if (flag_alt_external_templates)
698 struct tinst_level *til = tinst_for_decl ();
700 char *sf = input_filename;
705 input_filename = til->file;
707 cp_warning ("template `%#D' instantiated in file without #pragma interface",
713 cp_warning_at ("template `%#D' defined in file without #pragma interface",
717 /* A subroutine of the parser, to handle a component list. */
720 grok_x_components (specs, components)
721 tree specs, components;
723 register tree t, x, tcode;
725 /* We just got some friends. They have been recorded elsewhere. */
726 if (components == void_type_node)
729 if (components == NULL_TREE)
731 t = groktypename (build_decl_list (specs, NULL_TREE));
735 error ("error in component specification");
739 switch (TREE_CODE (t))
742 /* Static anonymous unions come out as VAR_DECLs. */
743 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
744 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
747 /* We return SPECS here, because in the parser it was ending
748 up with not doing anything to $$, which is what SPECS
754 /* This code may be needed for UNION_TYPEs as
756 tcode = record_type_node;
757 if (CLASSTYPE_DECLARED_CLASS (t))
758 tcode = class_type_node;
759 else if (IS_SIGNATURE (t))
760 tcode = signature_type_node;
762 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
763 if (TYPE_CONTEXT (t))
764 CLASSTYPE_NO_GLOBALIZE (t) = 1;
770 if (TREE_CODE (t) == UNION_TYPE)
771 tcode = union_type_node;
773 tcode = enum_type_node;
775 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
776 if (TREE_CODE (t) == UNION_TYPE && TYPE_CONTEXT (t))
777 CLASSTYPE_NO_GLOBALIZE (t) = 1;
778 if (TREE_CODE (t) == UNION_TYPE
779 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
781 struct pending_inline **p;
782 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
784 /* Wipe out memory of synthesized methods */
785 TYPE_HAS_CONSTRUCTOR (t) = 0;
786 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
787 TYPE_HAS_INIT_REF (t) = 0;
788 TYPE_HAS_CONST_INIT_REF (t) = 0;
789 TYPE_HAS_ASSIGN_REF (t) = 0;
790 TYPE_HAS_ASSIGNMENT (t) = 0;
791 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
793 p = &pending_inlines;
794 for (; *p; *p = (*p)->next)
795 if (DECL_CONTEXT ((*p)->fndecl) != t)
798 else if (TREE_CODE (t) == ENUMERAL_TYPE)
799 x = grok_enum_decls (t, NULL_TREE);
806 if (t != void_type_node)
807 error ("empty component declaration");
813 t = TREE_TYPE (components);
814 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
815 return grok_enum_decls (t, components);
821 /* Classes overload their constituent function names automatically.
822 When a function name is declared in a record structure,
823 its name is changed to it overloaded name. Since names for
824 constructors and destructors can conflict, we place a leading
827 CNAME is the name of the class we are grokking for.
829 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
831 FLAGS contains bits saying what's special about today's
832 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
834 If FUNCTION is a destructor, then we must add the `auto-delete' field
835 as a second parameter. There is some hair associated with the fact
836 that we must "declare" this variable in the manner consistent with the
837 way the rest of the arguments were declared.
839 QUALS are the qualifiers for the this pointer. */
842 grokclassfn (ctype, cname, function, flags, quals)
843 tree ctype, cname, function;
844 enum overload_flags flags;
847 tree fn_name = DECL_NAME (function);
851 tree fntype = TREE_TYPE (function);
852 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
854 if (fn_name == NULL_TREE)
856 error ("name missing for member function");
857 fn_name = get_identifier ("<anonymous>");
858 DECL_NAME (function) = fn_name;
862 qualtype = grok_method_quals (ctype, function, quals);
866 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
867 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
869 /* Must add the class instance variable up front. */
870 /* Right now we just make this a pointer. But later
871 we may wish to make it special. */
872 tree type = TREE_VALUE (arg_types);
875 if ((flag_this_is_variable > 0)
876 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
879 if (DECL_CONSTRUCTOR_P (function))
881 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
883 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
884 /* In this case we need "in-charge" flag saying whether
885 this constructor is responsible for initialization
886 of virtual baseclasses or not. */
887 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
888 /* Mark the artificial `__in_chrg' parameter as "artificial". */
889 SET_DECL_ARTIFICIAL (parm);
890 DECL_ARG_TYPE (parm) = integer_type_node;
891 TREE_READONLY (parm) = 1;
892 TREE_CHAIN (parm) = last_function_parms;
893 last_function_parms = parm;
897 parm = build_decl (PARM_DECL, this_identifier, type);
898 /* Mark the artificial `this' parameter as "artificial". */
899 SET_DECL_ARTIFICIAL (parm);
900 DECL_ARG_TYPE (parm) = type;
901 /* We can make this a register, so long as we don't
902 accidentally complain if someone tries to take its address. */
903 DECL_REGISTER (parm) = 1;
905 TREE_READONLY (parm) = 1;
906 TREE_CHAIN (parm) = last_function_parms;
907 last_function_parms = parm;
910 if (flags == DTOR_FLAG)
913 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
914 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
916 arg_types = hash_tree_chain (const_integer_type, void_list_node);
917 TREE_SIDE_EFFECTS (arg_types) = 1;
918 /* Build the overload name. It will look like `7Example'. */
919 if (IDENTIFIER_TYPE_VALUE (cname))
920 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
921 else if (IDENTIFIER_LOCAL_VALUE (cname))
922 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
924 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
925 it's defined out of the class definition, since poplevel_class wipes
926 it out. This used to be internal error 346. */
927 dbuf = build_overload_name (ctype, 1, 1);
928 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
929 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
932 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
933 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
934 /* Mark the artificial `__in_chrg' parameter as "artificial". */
935 SET_DECL_ARTIFICIAL (parm);
936 TREE_READONLY (parm) = 1;
937 DECL_ARG_TYPE (parm) = integer_type_node;
938 /* This is the same chain as DECL_ARGUMENTS (...). */
939 TREE_CHAIN (last_function_parms) = parm;
941 fntype = build_cplus_method_type (qualtype, void_type_node,
945 fntype = build_exception_variant (fntype, raises);
947 TREE_TYPE (function) = fntype;
948 TYPE_HAS_DESTRUCTOR (ctype) = 1;
952 tree these_arg_types;
954 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
956 arg_types = hash_tree_chain (integer_type_node,
957 TREE_CHAIN (arg_types));
958 fntype = build_cplus_method_type (qualtype,
959 TREE_TYPE (TREE_TYPE (function)),
963 fntype = build_exception_variant (fntype, raises);
965 TREE_TYPE (function) = fntype;
966 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
969 these_arg_types = arg_types;
971 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
972 /* Only true for static member functions. */
973 these_arg_types = hash_tree_chain (build_pointer_type (qualtype),
976 DECL_ASSEMBLER_NAME (function)
977 = build_decl_overload (fn_name, these_arg_types,
978 1 + DECL_CONSTRUCTOR_P (function));
981 /* This code is going into the compiler, but currently, it makes
982 libg++/src/Integer.cc not compile. The problem is that the nice name
983 winds up going into the symbol table, and conversion operations look
984 for the manged name. */
985 substitute_nice_name (function);
989 DECL_ARGUMENTS (function) = last_function_parms;
990 /* First approximations. */
991 DECL_CONTEXT (function) = ctype;
992 DECL_CLASS_CONTEXT (function) = ctype;
995 /* Work on the expr used by alignof (this is only called by the parser). */
1004 if (TREE_CODE (expr) == COMPONENT_REF
1005 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
1006 error ("`__alignof__' applied to a bit-field");
1008 if (TREE_CODE (expr) == INDIRECT_REF)
1010 best = t = TREE_OPERAND (expr, 0);
1011 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1013 while (TREE_CODE (t) == NOP_EXPR
1014 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1017 t = TREE_OPERAND (t, 0);
1018 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1019 if (thisalign > bestalign)
1020 best = t, bestalign = thisalign;
1022 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1026 /* ANSI says arrays and fns are converted inside comma.
1027 But we can't convert them in build_compound_expr
1028 because that would break commas in lvalues.
1029 So do the conversion here if operand was a comma. */
1030 if (TREE_CODE (expr) == COMPOUND_EXPR
1031 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1032 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1033 expr = default_conversion (expr);
1034 return c_alignof (TREE_TYPE (expr));
1038 /* Create an ARRAY_REF, checking for the user doing things backwards
1042 grok_array_decl (array_expr, index_exp)
1043 tree array_expr, index_exp;
1045 tree type = TREE_TYPE (array_expr);
1046 tree p1, p2, i1, i2;
1048 if (type == error_mark_node || index_exp == error_mark_node)
1049 return error_mark_node;
1050 if (processing_template_decl)
1051 return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE,
1052 array_expr, index_exp);
1054 if (type == NULL_TREE)
1056 /* Something has gone very wrong. Assume we are mistakenly reducing
1057 an expression instead of a declaration. */
1058 error ("parser may be lost: is there a '{' missing somewhere?");
1062 if (TREE_CODE (type) == OFFSET_TYPE
1063 || TREE_CODE (type) == REFERENCE_TYPE)
1064 type = TREE_TYPE (type);
1066 /* If they have an `operator[]', use that. */
1067 if (TYPE_LANG_SPECIFIC (type)
1068 && TYPE_OVERLOADS_ARRAY_REF (complete_type (type)))
1069 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1070 array_expr, index_exp, NULL_TREE);
1072 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1074 if (TREE_CODE (type) == ARRAY_TYPE)
1077 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1079 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1082 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1084 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1085 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1087 if ((p1 && i2) && (i1 && p2))
1088 error ("ambiguous conversion for array subscript");
1091 array_expr = p1, index_exp = i2;
1093 array_expr = p2, index_exp = i1;
1096 cp_error ("invalid types `%T[%T]' for array subscript",
1097 type, TREE_TYPE (index_exp));
1098 return error_mark_node;
1101 if (array_expr == error_mark_node || index_exp == error_mark_node)
1102 error ("ambiguous conversion for array subscript");
1104 return build_array_ref (array_expr, index_exp);
1107 /* Given the cast expression EXP, checking out its validity. Either return
1108 an error_mark_node if there was an unavoidable error, return a cast to
1109 void for trying to delete a pointer w/ the value 0, or return the
1110 call to delete. If DOING_VEC is 1, we handle things differently
1111 for doing an array delete. If DOING_VEC is 2, they gave us the
1112 array size as an argument to delete.
1113 Implements ARM $5.3.4. This is called from the parser. */
1116 delete_sanity (exp, size, doing_vec, use_global_delete)
1118 int doing_vec, use_global_delete;
1122 enum tree_code code;
1123 /* For a regular vector delete (aka, no size argument) we will pass
1124 this down as a NULL_TREE into build_vec_delete. */
1125 tree maxindex = NULL_TREE;
1127 if (exp == error_mark_node)
1130 if (processing_template_decl)
1132 t = build_min (DELETE_EXPR, void_type_node, exp, size);
1133 DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
1134 DELETE_EXPR_USE_VEC (t) = doing_vec;
1138 t = stabilize_reference (convert_from_reference (exp));
1139 type = TREE_TYPE (t);
1140 code = TREE_CODE (type);
1145 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1146 pedwarn ("anachronistic use of array size in vector delete");
1151 if (code != POINTER_TYPE)
1153 cp_error ("type `%#T' argument given to `delete', expected pointer",
1155 return error_mark_node;
1158 /* Deleting a pointer with the value zero is valid and has no effect. */
1159 if (integer_zerop (t))
1160 return build1 (NOP_EXPR, void_type_node, t);
1163 if (code == POINTER_TYPE)
1166 /* As of Valley Forge, you can delete a pointer to constant. */
1167 /* You can't delete a pointer to constant. */
1168 if (TREE_READONLY (TREE_TYPE (type)))
1170 error ("`const *' cannot be deleted");
1171 return error_mark_node;
1174 /* You also can't delete functions. */
1175 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1177 error ("cannot delete a function");
1178 return error_mark_node;
1183 /* If the type has no destructor, then we should build a regular
1184 delete, instead of a vector delete. Otherwise, we would end
1185 up passing a bogus offset into __builtin_delete, which is
1186 not expecting it. */
1188 && TREE_CODE (type) == POINTER_TYPE
1189 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1192 use_global_delete = 1;
1197 return build_vec_delete (t, maxindex, integer_one_node,
1198 integer_two_node, use_global_delete);
1201 if (IS_AGGR_TYPE (TREE_TYPE (type))
1202 && TYPE_GETS_REG_DELETE (TREE_TYPE (type)))
1204 /* Only do access checking here; we'll be calling op delete
1205 from the destructor. */
1206 tree tmp = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, t,
1207 size_zero_node, NULL_TREE);
1208 if (tmp == error_mark_node)
1209 return error_mark_node;
1212 return build_delete (type, t, integer_three_node,
1213 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
1218 /* Sanity check: report error if this function FUNCTION is not
1219 really a member of the class (CTYPE) it is supposed to belong to.
1220 CNAME is the same here as it is for grokclassfn above. */
1223 check_classfn (ctype, function)
1224 tree ctype, function;
1226 tree fn_name = DECL_NAME (function);
1228 tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype));
1232 if (method_vec != 0)
1234 methods = &TREE_VEC_ELT (method_vec, 0);
1235 end = TREE_VEC_END (method_vec);
1237 /* First suss out ctors and dtors. */
1238 if (*methods && fn_name == DECL_NAME (*methods)
1239 && DECL_CONSTRUCTOR_P (function))
1241 if (*++methods && fn_name == DECL_NAME (*methods)
1242 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)))
1245 while (++methods != end)
1247 if (fn_name == DECL_NAME (*methods))
1253 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1256 /* This doesn't work for static member functions that are
1257 pretending to be methods. */
1258 /* We have to do more extensive argument checking here, as
1259 the name may have been changed by asm("new_name"). */
1260 if (decls_match (function, fndecl))
1263 if (DECL_NAME (function) == DECL_NAME (fndecl))
1265 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1266 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1268 /* Get rid of the this parameter on functions that become
1270 if (DECL_STATIC_FUNCTION_P (fndecl)
1271 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1272 p1 = TREE_CHAIN (p1);
1274 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1275 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1276 && compparms (p1, p2, 3))
1280 fndecl = DECL_CHAIN (fndecl);
1289 tree fndecl = *methods;
1290 cp_error ("prototype for `%#D' does not match any in class `%T'",
1292 cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl) ? "s are" : " is",
1294 while (fndecl = DECL_CHAIN (fndecl), fndecl)
1295 cp_error_at (" %#D", fndecl);
1300 cp_error ("no `%#D' member function declared in class `%T'",
1304 /* If we did not find the method in the class, add it to avoid
1306 add_method (ctype, methods, function);
1310 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1311 of a structure component, returning a FIELD_DECL node.
1312 QUALS is a list of type qualifiers for this decl (such as for declaring
1313 const member functions).
1315 This is done during the parsing of the struct declaration.
1316 The FIELD_DECL nodes are chained together and the lot of them
1317 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1321 If class A defines that certain functions in class B are friends, then
1322 the way I have set things up, it is B who is interested in permission
1323 granted by A. However, it is in A's context that these declarations
1324 are parsed. By returning a void_type_node, class A does not attempt
1325 to incorporate the declarations of the friends within its structure.
1327 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1328 CHANGES TO CODE IN `start_method'. */
1331 grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
1332 tree declarator, declspecs, init, asmspec_tree, attrlist;
1334 register tree value;
1336 int flags = LOOKUP_ONLYCONVERTING;
1338 /* Convert () initializers to = initializers. */
1339 if (init == NULL_TREE && declarator != NULL_TREE
1340 && TREE_CODE (declarator) == CALL_EXPR
1341 && TREE_OPERAND (declarator, 0)
1342 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1343 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1344 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1346 init = TREE_OPERAND (declarator, 1);
1347 declarator = TREE_OPERAND (declarator, 0);
1351 if (declspecs == NULL_TREE
1352 && TREE_CODE (declarator) == SCOPE_REF
1353 && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE)
1355 /* Access declaration */
1356 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0))))
1358 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
1359 pop_nested_class (1);
1360 return do_class_using_decl (declarator);
1364 && TREE_CODE (init) == TREE_LIST
1365 && TREE_VALUE (init) == error_mark_node
1366 && TREE_CHAIN (init) == NULL_TREE)
1369 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, NULL_TREE);
1371 return value; /* friend or constructor went bad. */
1373 /* Pass friendly classes back. */
1374 if (TREE_CODE (value) == VOID_TYPE)
1375 return void_type_node;
1377 if (DECL_NAME (value) != NULL_TREE
1378 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1379 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1380 cp_error ("member `%D' conflicts with virtual function table field name", value);
1382 /* Stash away type declarations. */
1383 if (TREE_CODE (value) == TYPE_DECL)
1385 DECL_NONLOCAL (value) = 1;
1386 DECL_CONTEXT (value) = current_class_type;
1387 DECL_CLASS_CONTEXT (value) = current_class_type;
1388 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1390 pushdecl_class_level (value);
1394 if (IS_SIGNATURE (current_class_type)
1395 && TREE_CODE (value) != FUNCTION_DECL)
1397 error ("field declaration not allowed in signature");
1398 return void_type_node;
1401 if (DECL_IN_AGGR_P (value))
1403 cp_error ("`%D' is already defined in the class %T", value,
1404 DECL_CONTEXT (value));
1405 return void_type_node;
1409 asmspec = TREE_STRING_POINTER (asmspec_tree);
1413 if (IS_SIGNATURE (current_class_type)
1414 && TREE_CODE (value) == FUNCTION_DECL)
1416 error ("function declarations cannot have initializers in signature");
1419 else if (TREE_CODE (value) == FUNCTION_DECL)
1421 grok_function_init (value, init);
1424 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1425 /* Already complained in grokdeclarator. */
1429 /* We allow initializers to become parameters to base
1431 if (TREE_CODE (init) == TREE_LIST)
1433 if (TREE_CHAIN (init) == NULL_TREE)
1434 init = TREE_VALUE (init);
1436 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1439 if (TREE_CODE (init) == CONST_DECL)
1440 init = DECL_INITIAL (init);
1441 else if (TREE_READONLY_DECL_P (init))
1442 init = decl_constant_value (init);
1443 else if (TREE_CODE (init) == CONSTRUCTOR)
1444 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1445 my_friendly_assert (TREE_PERMANENT (init), 192);
1446 if (init == error_mark_node)
1447 /* We must make this look different than `error_mark_node'
1448 because `decl_const_value' would mis-interpret it
1449 as only meaning that this VAR_DECL is defined. */
1450 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1451 else if (processing_template_decl)
1453 else if (! TREE_CONSTANT (init))
1455 /* We can allow references to things that are effectively
1456 static, since references are initialized with the address. */
1457 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1458 || (TREE_STATIC (init) == 0
1459 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1460 || DECL_EXTERNAL (init) == 0)))
1462 error ("field initializer is not constant");
1463 init = error_mark_node;
1469 /* The corresponding pop_obstacks is in cp_finish_decl. */
1470 push_obstacks_nochange ();
1472 if (processing_template_decl && ! current_function_decl
1473 && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
1474 push_template_decl (value);
1477 cplus_decl_attributes (value, TREE_PURPOSE (attrlist),
1478 TREE_VALUE (attrlist));
1480 if (TREE_CODE (value) == VAR_DECL)
1482 /* We cannot call pushdecl here, because that would
1483 fill in the value of our TREE_CHAIN. Instead, we
1484 modify cp_finish_decl to do the right thing, namely, to
1485 put this decl out straight away. */
1486 if (TREE_PUBLIC (value))
1488 /* current_class_type can be NULL_TREE in case of error. */
1489 if (asmspec == 0 && current_class_type)
1491 TREE_PUBLIC (value) = 1;
1492 DECL_INITIAL (value) = error_mark_node;
1493 DECL_ASSEMBLER_NAME (value)
1494 = build_static_name (current_class_type, DECL_NAME (value));
1496 if (! processing_template_decl)
1497 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1499 /* Static consts need not be initialized in the class definition. */
1500 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1502 static int explanation = 0;
1504 error ("initializer invalid for static member with constructor");
1505 if (explanation++ == 0)
1506 error ("(you really want to initialize it separately)");
1509 /* Force the compiler to know when an uninitialized static
1510 const member is being used. */
1511 if (TYPE_READONLY (value) && init == 0)
1512 TREE_USED (value) = 1;
1514 DECL_INITIAL (value) = init;
1515 DECL_IN_AGGR_P (value) = 1;
1516 DECL_CONTEXT (value) = current_class_type;
1517 DECL_CLASS_CONTEXT (value) = current_class_type;
1519 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1520 pushdecl_class_level (value);
1523 if (TREE_CODE (value) == FIELD_DECL)
1527 /* This must override the asm specifier which was placed
1528 by grokclassfn. Lay this out fresh. */
1529 DECL_RTL (value) = NULL_RTX;
1530 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1532 if (DECL_INITIAL (value) == error_mark_node)
1533 init = error_mark_node;
1534 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1535 DECL_INITIAL (value) = init;
1536 DECL_IN_AGGR_P (value) = 1;
1539 if (TREE_CODE (value) == FUNCTION_DECL)
1541 check_default_args (value);
1542 if (DECL_CHAIN (value) != NULL_TREE)
1544 /* Need a fresh node here so that we don't get circularity
1545 when we link these together. */
1546 value = copy_node (value);
1547 /* When does this happen? */
1548 my_friendly_assert (init == NULL_TREE, 193);
1552 /* This must override the asm specifier which was placed
1553 by grokclassfn. Lay this out fresh. */
1554 DECL_RTL (value) = NULL_RTX;
1555 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1557 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1559 /* Pass friends back this way. */
1560 if (DECL_FRIEND_P (value))
1561 return void_type_node;
1563 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1564 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1565 cp_error ("method `%#D' of local class must be defined in class body",
1569 DECL_IN_AGGR_P (value) = 1;
1572 my_friendly_abort (21);
1577 /* Like `grokfield', but for bitfields.
1578 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1581 grokbitfield (declarator, declspecs, width)
1582 tree declarator, declspecs, width;
1584 register tree value = grokdeclarator (declarator, declspecs, BITFIELD,
1587 if (! value) return NULL_TREE; /* friends went bad. */
1589 /* Pass friendly classes back. */
1590 if (TREE_CODE (value) == VOID_TYPE)
1591 return void_type_node;
1593 if (TREE_CODE (value) == TYPE_DECL)
1595 cp_error ("cannot declare `%D' to be a bitfield type", value);
1599 if (IS_SIGNATURE (current_class_type))
1601 error ("field declaration not allowed in signature");
1602 return void_type_node;
1605 if (DECL_IN_AGGR_P (value))
1607 cp_error ("`%D' is already defined in the class %T", value,
1608 DECL_CONTEXT (value));
1609 return void_type_node;
1612 GNU_xref_member (current_class_name, value);
1614 if (TREE_STATIC (value))
1616 cp_error ("static member `%D' cannot be a bitfield", value);
1619 cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1621 if (width != error_mark_node)
1623 constant_expression_warning (width);
1624 DECL_INITIAL (value) = width;
1625 DECL_BIT_FIELD (value) = 1;
1628 DECL_IN_AGGR_P (value) = 1;
1633 grokoptypename (declspecs, declarator)
1634 tree declspecs, declarator;
1636 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1637 return build_typename_overload (t);
1640 /* When a function is declared with an initializer,
1641 do the right thing. Currently, there are two possibilities:
1646 // initialization possibility #1.
1647 virtual void f () = 0;
1669 // initialization possibility #2
1676 copy_assignment_arg_p (parmtype, virtualp)
1680 if (current_class_type == NULL_TREE)
1683 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1684 parmtype = TREE_TYPE (parmtype);
1686 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1687 || (virtualp && DERIVED_FROM_P (parmtype, current_class_type)))
1694 grok_function_init (decl, init)
1698 /* An initializer for a function tells how this function should
1700 tree type = TREE_TYPE (decl);
1702 if (TREE_CODE (type) == FUNCTION_TYPE)
1703 cp_error ("initializer specified for non-member function `%D'", decl);
1705 /* We'll check for this in finish_struct_1. */
1706 else if (DECL_VINDEX (decl) == NULL_TREE)
1707 cp_error ("initializer specified for non-virtual method `%D'", decl);
1709 else if (integer_zerop (init))
1712 /* Mark this function as being "defined". */
1713 DECL_INITIAL (decl) = error_mark_node;
1714 /* pure virtual destructors must be defined. */
1715 /* pure virtual needs to be defined (as abort) only when put in
1716 vtbl. For wellformed call, it should be itself. pr4737 */
1717 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1719 extern tree abort_fndecl;
1720 /* Give this node rtl from `abort'. */
1721 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1724 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1725 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1728 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1730 if (copy_assignment_arg_p (parmtype, 1))
1731 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1734 else if (TREE_CODE (init) == OFFSET_REF
1735 && TREE_OPERAND (init, 0) == NULL_TREE
1736 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1738 tree basetype = DECL_CLASS_CONTEXT (init);
1739 tree basefn = TREE_OPERAND (init, 1);
1740 if (TREE_CODE (basefn) != FUNCTION_DECL)
1741 cp_error ("non-method initializer invalid for method `%D'", decl);
1742 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1743 sorry ("base member function from other than first base class");
1746 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1747 if (binfo == error_mark_node)
1749 else if (binfo == 0)
1750 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1751 TYPE_METHOD_BASETYPE (type));
1754 /* Mark this function as being defined,
1755 and give it new rtl. */
1756 DECL_INITIAL (decl) = error_mark_node;
1757 DECL_RTL (decl) = DECL_RTL (basefn);
1762 cp_error ("invalid initializer for virtual method `%D'", decl);
1766 cplus_decl_attributes (decl, attributes, prefix_attributes)
1767 tree decl, attributes, prefix_attributes;
1769 if (decl == NULL_TREE || decl == void_type_node)
1772 if (TREE_CODE (decl) == TEMPLATE_DECL)
1773 decl = DECL_TEMPLATE_RESULT (decl);
1775 decl_attributes (decl, attributes, prefix_attributes);
1777 if (TREE_CODE (decl) == TYPE_DECL)
1778 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl));
1781 /* CONSTRUCTOR_NAME:
1782 Return the name for the constructor (or destructor) for the
1783 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1784 IDENTIFIER_NODE. When given a template, this routine doesn't
1785 lose the specialization. */
1788 constructor_name_full (thing)
1791 if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM)
1792 thing = TYPE_NAME (thing);
1793 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1795 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1796 thing = DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0));
1798 thing = TYPE_NAME (thing);
1800 if (TREE_CODE (thing) == TYPE_DECL
1801 || (TREE_CODE (thing) == TEMPLATE_DECL
1802 && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL))
1803 thing = DECL_NAME (thing);
1804 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1808 /* CONSTRUCTOR_NAME:
1809 Return the name for the constructor (or destructor) for the
1810 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1811 IDENTIFIER_NODE. When given a template, return the plain
1812 unspecialized name. */
1815 constructor_name (thing)
1819 thing = constructor_name_full (thing);
1820 t = IDENTIFIER_TEMPLATE (thing);
1826 /* Cache the value of this class's main virtual function table pointer
1827 in a register variable. This will save one indirection if a
1828 more than one virtual function call is made this function. */
1833 extern tree base_init_expr;
1835 if (base_init_expr == 0
1836 && DECL_CONSTRUCTOR_P (current_function_decl))
1838 if (processing_template_decl)
1839 add_tree (build_min_nt
1841 current_member_init_list, current_base_init_list));
1843 emit_base_init (current_class_type, 0);
1847 /* Record the existence of an addressable inline function. */
1850 mark_inline_for_output (decl)
1853 decl = DECL_MAIN_VARIANT (decl);
1854 if (DECL_SAVED_INLINE (decl))
1856 my_friendly_assert (TREE_PERMANENT (decl), 363);
1857 DECL_SAVED_INLINE (decl) = 1;
1859 if (DECL_PENDING_INLINE_INFO (decl) != 0
1860 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
1862 struct pending_inline *t = pending_inlines;
1863 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
1866 if (t == DECL_PENDING_INLINE_INFO (decl))
1872 t = DECL_PENDING_INLINE_INFO (decl);
1873 t->next = pending_inlines;
1874 pending_inlines = t;
1876 DECL_PENDING_INLINE_INFO (decl) = 0;
1879 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
1885 temp_name_counter = 0;
1888 /* Hand off a unique name which can be used for variable we don't really
1889 want to know about anyway, for example, the anonymous variables which
1890 are needed to make references work. Declare this thing so we can use it.
1891 The variable created will be of type TYPE.
1893 STATICP is nonzero if this variable should be static. */
1896 get_temp_name (type, staticp)
1900 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
1902 int toplev = toplevel_bindings_p ();
1904 push_obstacks_nochange ();
1905 if (toplev || staticp)
1907 end_temporary_allocation ();
1908 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
1909 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
1913 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
1914 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1916 TREE_USED (decl) = 1;
1917 TREE_STATIC (decl) = staticp;
1918 DECL_ARTIFICIAL (decl) = 1;
1920 /* If this is a local variable, then lay out its rtl now.
1921 Otherwise, callers of this function are responsible for dealing
1922 with this variable's rtl. */
1926 expand_decl_init (decl);
1933 /* Get a variable which we can use for multiple assignments.
1934 It is not entered into current_binding_level, because
1935 that breaks things when it comes time to do final cleanups
1936 (which take place "outside" the binding contour of the function). */
1939 get_temp_regvar (type, init)
1942 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
1945 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
1946 decl = build_decl (VAR_DECL, get_identifier (buf), type);
1947 TREE_USED (decl) = 1;
1948 DECL_REGISTER (decl) = 1;
1951 store_init_value (decl, init);
1953 /* We can expand these without fear, since they cannot need
1954 constructors or destructors. */
1956 expand_decl_init (decl);
1961 /* Make the macro TEMP_NAME_P available to units which do not
1962 include c-tree.h. */
1968 return TEMP_NAME_P (decl);
1971 /* Finish off the processing of a UNION_TYPE structure.
1972 If there are static members, then all members are
1973 static, and must be laid out together. If the
1974 union is an anonymous union, we arrange for that
1975 as well. PUBLIC_P is nonzero if this union is
1976 not declared static. */
1979 finish_anon_union (anon_union_decl)
1980 tree anon_union_decl;
1982 tree type = TREE_TYPE (anon_union_decl);
1983 tree field, main_decl = NULL_TREE;
1984 tree elems = NULL_TREE;
1985 int public_p = TREE_PUBLIC (anon_union_decl);
1986 int static_p = TREE_STATIC (anon_union_decl);
1987 int external_p = DECL_EXTERNAL (anon_union_decl);
1989 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
1994 error ("global anonymous unions must be declared static");
1998 for (; field; field = TREE_CHAIN (field))
2001 if (TREE_CODE (field) != FIELD_DECL)
2004 if (TREE_PRIVATE (field))
2005 cp_pedwarn_at ("private member `%#D' in anonymous union", field);
2006 else if (TREE_PROTECTED (field))
2007 cp_pedwarn_at ("protected member `%#D' in anonymous union", field);
2009 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2010 /* tell `pushdecl' that this is not tentative. */
2011 DECL_INITIAL (decl) = error_mark_node;
2012 TREE_PUBLIC (decl) = public_p;
2013 TREE_STATIC (decl) = static_p;
2014 DECL_EXTERNAL (decl) = external_p;
2015 decl = pushdecl (decl);
2017 /* Only write out one anon union element--choose the one that
2018 can hold them all. */
2019 if (main_decl == NULL_TREE
2020 && 1 == simple_cst_equal (DECL_SIZE (decl),
2021 DECL_SIZE (anon_union_decl)))
2027 /* ??? This causes there to be no debug info written out
2029 TREE_ASM_WRITTEN (decl) = 1;
2032 DECL_INITIAL (decl) = NULL_TREE;
2033 /* If there's a cleanup to do, it belongs in the
2034 TREE_PURPOSE of the following TREE_LIST. */
2035 elems = tree_cons (NULL_TREE, decl, elems);
2036 TREE_TYPE (elems) = type;
2042 make_decl_rtl (main_decl, 0, toplevel_bindings_p ());
2043 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2047 warning ("anonymous union with no members");
2052 /* The following call assumes that there are never any cleanups
2053 for anonymous unions--a reasonable assumption. */
2054 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2057 /* Finish and output a table which is generated by the compiler.
2058 NAME is the name to give the table.
2059 TYPE is the type of the table entry.
2060 INIT is all the elements in the table.
2061 PUBLICP is non-zero if this table should be given external access. */
2064 finish_table (name, type, init, publicp)
2065 tree name, type, init;
2068 tree itype, atype, decl;
2069 static tree empty_table;
2073 itype = build_index_type (size_int (list_length (init) - 1));
2074 atype = build_cplus_array_type (type, itype);
2075 layout_type (atype);
2077 if (TREE_VALUE (init) == integer_zero_node
2078 && TREE_CHAIN (init) == NULL_TREE)
2081 if (empty_table == NULL_TREE)
2084 empty_table = get_temp_name (atype, 1);
2085 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2086 TREE_CONSTANT (init) = 1;
2087 TREE_STATIC (init) = 1;
2088 DECL_INITIAL (empty_table) = init;
2089 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2090 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2091 cp_finish_decl (empty_table, NULL_TREE, asmspec, 0, 0);
2096 if (name == NULL_TREE)
2100 decl = get_temp_name (atype, 1);
2104 decl = build_decl (VAR_DECL, name, atype);
2105 decl = pushdecl (decl);
2106 TREE_STATIC (decl) = 1;
2111 TREE_PUBLIC (decl) = publicp;
2112 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2113 TREE_CONSTANT (init) = 1;
2114 TREE_STATIC (init) = 1;
2115 DECL_INITIAL (decl) = init;
2116 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2117 IDENTIFIER_POINTER (DECL_NAME (decl)));
2121 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2122 DECL_EXTERNAL (decl) = 1;
2123 TREE_STATIC (decl) = 0;
2125 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2126 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2129 cp_finish_decl (decl, NULL_TREE, asmspec, 0, 0);
2133 /* Finish processing a builtin type TYPE. It's name is NAME,
2134 its fields are in the array FIELDS. LEN is the number of elements
2135 in FIELDS minus one, or put another way, it is the maximum subscript
2138 It is given the same alignment as ALIGN_TYPE. */
2141 finish_builtin_type (type, name, fields, len, align_type)
2150 TYPE_FIELDS (type) = fields[0];
2151 for (i = 0; i < len; i++)
2153 layout_type (TREE_TYPE (fields[i]));
2154 DECL_FIELD_CONTEXT (fields[i]) = type;
2155 TREE_CHAIN (fields[i]) = fields[i+1];
2157 DECL_FIELD_CONTEXT (fields[i]) = type;
2158 DECL_CLASS_CONTEXT (fields[i]) = type;
2159 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2161 #if 0 /* not yet, should get fixed properly later */
2162 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2164 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2166 layout_decl (TYPE_NAME (type), 0);
2169 /* Auxiliary functions to make type signatures for
2170 `operator new' and `operator delete' correspond to
2171 what compiler will be expecting. */
2173 extern tree sizetype;
2176 coerce_new_type (type)
2181 if (TREE_CODE (type) == METHOD_TYPE)
2182 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2183 if (TREE_TYPE (type) != ptr_type_node)
2184 e1 = 1, error ("`operator new' must return type `void *'");
2186 /* Technically the type must be `size_t', but we may not know
2188 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2189 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2190 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2191 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2192 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2194 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2196 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2201 coerce_delete_type (type)
2204 int e1 = 0, e2 = 0, e3 = 0;
2205 tree arg_types = TYPE_ARG_TYPES (type);
2207 if (TREE_CODE (type) == METHOD_TYPE)
2209 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2210 arg_types = TREE_CHAIN (arg_types);
2212 if (TREE_TYPE (type) != void_type_node)
2213 e1 = 1, error ("`operator delete' must return type `void'");
2214 if (arg_types == NULL_TREE
2215 || TREE_VALUE (arg_types) != ptr_type_node)
2216 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2219 && TREE_CHAIN (arg_types)
2220 && TREE_CHAIN (arg_types) != void_list_node)
2222 /* Again, technically this argument must be `size_t', but again
2223 we may not know what that is. */
2224 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2225 if (TREE_CODE (t2) != INTEGER_TYPE
2226 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2227 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2228 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2231 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2232 error ("too many arguments in declaration of `operator delete'");
2234 error ("`...' invalid in specification of `operator delete'");
2238 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
2241 if (arg_types == NULL_TREE)
2242 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2244 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2249 type = build_function_type (void_type_node, arg_types);
2254 extern tree abort_fndecl;
2257 mark_vtable_entries (decl)
2260 tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
2264 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries))
2265 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2266 tree fn = TREE_OPERAND (fnaddr, 0);
2267 TREE_ADDRESSABLE (fn) = 1;
2270 skip_rtti_stuff (&entries);
2272 for (; entries; entries = TREE_CHAIN (entries))
2274 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries)
2275 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2276 tree fn = TREE_OPERAND (fnaddr, 0);
2277 TREE_ADDRESSABLE (fn) = 1;
2278 if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn))
2279 TREE_OPERAND (fnaddr, 0) = fn = abort_fndecl;
2280 if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn))
2282 DECL_EXTERNAL (fn) = 0;
2289 /* Set DECL up to have the closest approximation of "initialized common"
2290 linkage available. */
2293 comdat_linkage (decl)
2297 make_decl_one_only (decl);
2299 TREE_PUBLIC (decl) = 0;
2302 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2303 based on TYPE and other static flags.
2305 Note that anything public is tagged TREE_PUBLIC, whether
2306 it's public in this file or in another one. */
2309 import_export_vtable (decl, type, final)
2313 if (DECL_INTERFACE_KNOWN (decl))
2317 if (write_virtuals < 2 && write_virtuals != 0)
2319 TREE_PUBLIC (decl) = 1;
2320 if (write_virtuals < 0)
2321 DECL_EXTERNAL (decl) = 1;
2322 DECL_INTERFACE_KNOWN (decl) = 1;
2324 else if (CLASSTYPE_INTERFACE_KNOWN (type))
2326 TREE_PUBLIC (decl) = 1;
2327 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2328 DECL_INTERFACE_KNOWN (decl) = 1;
2332 /* We can only wait to decide if we have real non-inline virtual
2333 functions in our class, or if we come from a template. */
2335 int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2337 if (! found && ! final)
2340 for (method = TYPE_METHODS (type); method != NULL_TREE;
2341 method = TREE_CHAIN (method))
2342 if (DECL_VINDEX (method) != NULL_TREE
2343 && ! DECL_THIS_INLINE (method)
2344 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2351 if (final || ! found)
2353 comdat_linkage (decl);
2354 DECL_EXTERNAL (decl) = 0;
2358 TREE_PUBLIC (decl) = 1;
2359 DECL_EXTERNAL (decl) = 1;
2365 import_export_template (type)
2368 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2369 && ! flag_implicit_templates
2370 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2372 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2373 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2374 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2379 finish_prevtable_vardecl (prev, vars)
2382 tree ctype = DECL_CONTEXT (vars);
2383 import_export_template (ctype);
2385 #ifndef NO_LINKAGE_HEURISTICS
2386 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype)
2387 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2390 for (method = TYPE_METHODS (ctype); method != NULL_TREE;
2391 method = TREE_CHAIN (method))
2393 if (DECL_VINDEX (method) != NULL_TREE
2394 && !DECL_THIS_INLINE (method)
2395 && !DECL_ABSTRACT_VIRTUAL_P (method))
2397 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2398 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method);
2399 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2406 import_export_vtable (vars, ctype, 1);
2411 finish_vtable_vardecl (prev, vars)
2414 if (write_virtuals >= 0
2415 && ! DECL_EXTERNAL (vars)
2416 && ((TREE_PUBLIC (vars) && ! DECL_WEAK (vars) && ! DECL_ONE_ONLY (vars))
2417 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))
2418 || (hack_decl_function_context (vars) && TREE_USED (vars)))
2419 && ! TREE_ASM_WRITTEN (vars))
2422 mark_vtable_entries (vars);
2423 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2424 store_init_value (vars, DECL_INITIAL (vars));
2426 #ifdef DWARF_DEBUGGING_INFO
2427 if (write_symbols == DWARF_DEBUG)
2429 /* Mark the VAR_DECL node representing the vtable itself as a
2430 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2431 It is rather important that such things be ignored because
2432 any effort to actually generate DWARF for them will run
2433 into trouble when/if we encounter code like:
2436 struct S { virtual void member (); };
2438 because the artificial declaration of the vtable itself (as
2439 manufactured by the g++ front end) will say that the vtable
2440 is a static member of `S' but only *after* the debug output
2441 for the definition of `S' has already been output. This causes
2442 grief because the DWARF entry for the definition of the vtable
2443 will try to refer back to an earlier *declaration* of the
2444 vtable as a static member of `S' and there won't be one.
2445 We might be able to arrange to have the "vtable static member"
2446 attached to the member list for `S' before the debug info for
2447 `S' get written (which would solve the problem) but that would
2448 require more intrusive changes to the g++ front end. */
2450 DECL_IGNORED_P (vars) = 1;
2452 #endif /* DWARF_DEBUGGING_INFO */
2454 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2457 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2458 /* We don't know what to do with this one yet. */
2461 /* We know that PREV must be non-zero here. */
2462 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2467 prune_vtable_vardecl (prev, vars)
2470 /* We know that PREV must be non-zero here. */
2471 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2476 walk_vtables (typedecl_fn, vardecl_fn)
2477 register void (*typedecl_fn)();
2478 register int (*vardecl_fn)();
2483 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2485 register tree type = TREE_TYPE (vars);
2487 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2490 flag |= (*vardecl_fn) (prev, vars);
2492 if (prev && TREE_CHAIN (prev) != vars)
2495 else if (TREE_CODE (vars) == TYPE_DECL
2496 && type != error_mark_node
2497 && TYPE_LANG_SPECIFIC (type)
2498 && CLASSTYPE_VSIZE (type))
2500 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2510 finish_sigtable_vardecl (prev, vars)
2513 /* We don't need to mark sigtable entries as addressable here as is done
2514 for vtables. Since sigtables, unlike vtables, are always written out,
2515 that was already done in build_signature_table_constructor. */
2517 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2519 /* We know that PREV must be non-zero here. */
2520 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2524 walk_sigtables (typedecl_fn, vardecl_fn)
2525 register void (*typedecl_fn)();
2526 register void (*vardecl_fn)();
2530 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2532 register tree type = TREE_TYPE (vars);
2534 if (TREE_CODE (vars) == TYPE_DECL
2535 && type != error_mark_node
2536 && IS_SIGNATURE (type))
2538 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2540 else if (TREE_CODE (vars) == VAR_DECL
2541 && TREE_TYPE (vars) != error_mark_node
2542 && IS_SIGNATURE (TREE_TYPE (vars)))
2544 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2551 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2552 inline function or template instantiation at end-of-file. */
2555 import_export_decl (decl)
2558 if (DECL_INTERFACE_KNOWN (decl))
2561 if (DECL_TEMPLATE_INSTANTIATION (decl))
2563 DECL_NOT_REALLY_EXTERN (decl) = 1;
2564 if (DECL_IMPLICIT_INSTANTIATION (decl)
2565 && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2567 if (TREE_CODE (decl) == FUNCTION_DECL)
2568 comdat_linkage (decl);
2569 /* Dynamically initialized vars go into common. */
2570 else if (DECL_INITIAL (decl) == NULL_TREE
2571 || DECL_INITIAL (decl) == error_mark_node)
2572 DECL_COMMON (decl) = 1;
2573 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
2575 DECL_COMMON (decl) = 1;
2576 DECL_INITIAL (decl) = error_mark_node;
2580 /* Statically initialized vars are weak or comdat, if
2583 make_decl_one_only (decl);
2584 /* else leave vars public so multiple defs will break. */
2588 DECL_NOT_REALLY_EXTERN (decl) = 0;
2590 else if (DECL_FUNCTION_MEMBER_P (decl))
2592 tree ctype = DECL_CLASS_CONTEXT (decl);
2593 if (CLASSTYPE_INTERFACE_KNOWN (ctype) && ! DECL_ARTIFICIAL (decl))
2595 DECL_NOT_REALLY_EXTERN (decl)
2596 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2597 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2600 comdat_linkage (decl);
2602 /* tinfo function */
2603 else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2605 tree ctype = TREE_TYPE (DECL_NAME (decl));
2606 if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2607 && TYPE_VIRTUAL_P (ctype))
2609 DECL_NOT_REALLY_EXTERN (decl)
2610 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2611 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2613 else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2614 DECL_NOT_REALLY_EXTERN (decl) = 0;
2616 comdat_linkage (decl);
2618 else if (DECL_C_STATIC (decl))
2619 TREE_PUBLIC (decl) = 0;
2621 comdat_linkage (decl);
2623 DECL_INTERFACE_KNOWN (decl) = 1;
2627 build_cleanup (decl)
2631 tree type = TREE_TYPE (decl);
2633 if (TREE_CODE (type) == ARRAY_TYPE)
2637 mark_addressable (decl);
2638 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2640 temp = build_delete (TREE_TYPE (temp), temp,
2642 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2646 extern int parse_time, varconst_time;
2647 extern tree pending_templates;
2648 extern tree maybe_templates;
2650 extern struct obstack permanent_obstack;
2651 extern tree get_id_2 ();
2657 tree sname = get_id_2 ("__sn", base);
2658 tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2661 push_obstacks (&permanent_obstack, &permanent_obstack);
2662 sentry = build_decl (VAR_DECL, sname, integer_type_node);
2663 TREE_PUBLIC (sentry) = 1;
2664 DECL_ARTIFICIAL (sentry) = 1;
2665 TREE_STATIC (sentry) = 1;
2666 TREE_USED (sentry) = 1;
2667 DECL_COMMON (sentry) = 1;
2668 pushdecl_top_level (sentry);
2669 cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2675 /* This routine is called from the last rule in yyparse ().
2676 Its job is to create all the code needed to initialize and
2677 destroy the global aggregates. We do the destruction
2678 first, since that way we only need to reverse the decls once. */
2684 int start_time, this_time;
2688 int needs_cleaning = 0, needs_messing_up = 0;
2692 if (flag_detailed_statistics)
2693 dump_tree_statistics ();
2695 /* Bad parse errors. Just forget about it. */
2696 if (! global_bindings_p () || current_class_type)
2699 start_time = get_run_time ();
2701 /* Otherwise, GDB can get confused, because in only knows
2702 about source for LINENO-1 lines. */
2705 interface_unknown = 1;
2708 for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
2710 tree decl = TREE_VALUE (fnname);
2711 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
2713 instantiate_class_template (decl);
2714 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
2715 for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
2716 if (! DECL_ARTIFICIAL (vars))
2717 instantiate_decl (vars);
2720 instantiate_decl (decl);
2723 for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
2725 tree *args, fn, decl = TREE_VALUE (fnname);
2727 if (DECL_INITIAL (decl))
2730 fn = TREE_PURPOSE (fnname);
2731 args = get_bindings (fn, decl);
2732 fn = instantiate_template (fn, args);
2734 instantiate_decl (fn);
2737 /* Push into C language context, because that's all
2739 push_lang_context (lang_name_c);
2742 /* The reason for pushing garbage onto the global_binding_level is to
2743 ensure that we can slice out _DECLs which pertain to virtual function
2744 tables. If the last thing pushed onto the global_binding_level was a
2745 virtual function table, then slicing it out would slice away all the
2746 decls (i.e., we lose the head of the chain).
2748 There are several ways of getting the same effect, from changing the
2749 way that iterators over the chain treat the elements that pertain to
2750 virtual function tables, moving the implementation of this code to
2751 decl.c (where we can manipulate global_binding_level directly),
2752 popping the garbage after pushing it and slicing away the vtable
2753 stuff, or just leaving it alone. */
2755 /* Make last thing in global scope not be a virtual function table. */
2756 #if 0 /* not yet, should get fixed properly later */
2757 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2759 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2761 DECL_IGNORED_P (vars) = 1;
2762 SET_DECL_ARTIFICIAL (vars);
2766 /* Walk to mark the inline functions we need, then output them so
2767 that we can pick up any other tdecls that those routines need. */
2768 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2770 for (vars = pending_statics; vars; vars = TREE_CHAIN (vars))
2772 tree decl = TREE_VALUE (vars);
2774 if (DECL_TEMPLATE_INSTANTIATION (decl)
2775 && ! DECL_IN_AGGR_P (decl))
2777 import_export_decl (decl);
2778 DECL_EXTERNAL (decl) = ! DECL_NOT_REALLY_EXTERN (decl);
2782 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2783 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
2784 rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
2785 vars = static_aggregates;
2787 if (static_ctors || vars || exception_table_p ())
2788 needs_messing_up = 1;
2792 /* See if we really need the hassle. */
2793 while (vars && needs_cleaning == 0)
2795 tree decl = TREE_VALUE (vars);
2796 tree type = TREE_TYPE (decl);
2797 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars))
2803 vars = TREE_CHAIN (vars);
2806 if (needs_cleaning == 0)
2809 fnname = get_file_function_name ('D');
2810 start_function (void_list_node,
2811 make_call_declarator (fnname, void_list_node, NULL_TREE,
2814 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2815 store_parm_decls ();
2820 expand_start_bindings (0);
2822 /* These must be done in backward order to destroy,
2823 in which they happen to be! */
2824 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2826 tree decl = TREE_VALUE (vars);
2827 tree type = TREE_TYPE (decl);
2828 tree temp = TREE_PURPOSE (vars);
2830 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
2831 && ! DECL_EXTERNAL (decl))
2833 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2834 || DECL_ONE_ONLY (decl)
2835 || DECL_WEAK (decl)));
2837 temp = build_cleanup (decl);
2841 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2842 sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
2843 sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
2844 expand_start_cond (sentry, 0);
2847 expand_expr_stmt (temp);
2854 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2855 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2858 expand_end_bindings (getdecls (), 1, 0);
2862 finish_function (lineno, 0, 0);
2864 assemble_destructor (IDENTIFIER_POINTER (fnname));
2866 /* if it needed cleaning, then it will need messing up: drop through */
2869 /* Must do this while we think we are at the top level. */
2870 vars = nreverse (static_aggregates);
2871 if (needs_messing_up)
2873 fnname = get_file_function_name ('I');
2874 start_function (void_list_node,
2875 make_call_declarator (fnname, void_list_node, NULL_TREE,
2878 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2879 store_parm_decls ();
2884 expand_start_bindings (0);
2886 if (exception_table_p ())
2887 register_exception_table ();
2891 extern int temp_slot_level;
2892 extern int target_temp_slot_level;
2893 tree decl = TREE_VALUE (vars);
2894 tree init = TREE_PURPOSE (vars);
2895 tree old_cleanups = cleanups_this_call;
2896 int old_temp_level = target_temp_slot_level;
2899 target_temp_slot_level = temp_slot_level;
2901 /* If this was a static attribute within some function's scope,
2902 then don't initialize it here. Also, don't bother
2903 with initializers that contain errors. */
2904 if (TREE_STATIC (vars)
2905 || DECL_EXTERNAL (decl)
2906 || (init && TREE_CODE (init) == TREE_LIST
2907 && value_member (error_mark_node, init)))
2910 if (TREE_CODE (decl) == VAR_DECL)
2912 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2913 || DECL_ONE_ONLY (decl)
2914 || DECL_WEAK (decl)));
2916 /* Set these global variables so that GDB at least puts
2917 us near the declaration which required the initialization. */
2918 input_filename = DECL_SOURCE_FILE (decl);
2919 lineno = DECL_SOURCE_LINE (decl);
2920 emit_note (input_filename, lineno);
2922 /* 9.5p5: The initializer of a static member of a class has
2923 the same access rights as a member function. */
2924 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2925 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
2929 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2930 sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
2931 sentry = build_binary_op
2932 (EQ_EXPR, sentry, integer_one_node, 1);
2933 expand_start_cond (sentry, 0);
2936 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2937 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2938 expand_aggr_init (decl, init, 0, 0);
2939 else if (TREE_CODE (init) == TREE_VEC)
2941 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2942 TREE_VEC_ELT (init, 1),
2943 TREE_VEC_ELT (init, 2), 0),
2944 const0_rtx, VOIDmode, 0);
2947 expand_assignment (decl, init, 0, 0);
2952 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2953 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
2955 else if (decl == error_mark_node)
2957 else my_friendly_abort (22);
2959 /* Cleanup any temporaries needed for the initial value. */
2960 expand_cleanups_to (old_cleanups);
2964 target_temp_slot_level = old_temp_level;
2966 vars = TREE_CHAIN (vars);
2969 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
2970 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
2973 expand_end_bindings (getdecls (), 1, 0);
2977 finish_function (lineno, 0, 0);
2978 assemble_constructor (IDENTIFIER_POINTER (fnname));
2981 expand_builtin_throw ();
2983 permanent_allocation (1);
2985 /* Done with C language context needs. */
2986 pop_lang_context ();
2988 /* Now write out any static class variables (which may have since
2989 learned how to be initialized). */
2990 while (pending_statics)
2992 tree decl = TREE_VALUE (pending_statics);
2994 if (TREE_USED (decl) == 1
2995 || TREE_READONLY (decl) == 0
2996 || DECL_INITIAL (decl) == 0)
2998 DECL_DEFER_OUTPUT (decl) = 0;
2999 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3001 pending_statics = TREE_CHAIN (pending_statics);
3004 this_time = get_run_time ();
3005 parse_time -= this_time - start_time;
3006 varconst_time += this_time - start_time;
3008 start_time = get_run_time ();
3010 if (flag_handle_signatures)
3011 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3013 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3015 tree decl = TREE_VALUE (fnname);
3016 import_export_decl (decl);
3019 /* Now write out inline functions which had their addresses taken and
3020 which were not declared virtual and which were not declared `extern
3023 int reconsider = 1; /* More may be referenced; check again */
3027 tree *p = &saved_inlines;
3030 /* We need to do this each time so that newly completed template
3031 types don't wind up at the front of the list. Sigh. */
3032 vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3033 DECL_IGNORED_P (vars) = 1;
3034 SET_DECL_ARTIFICIAL (vars);
3037 reconsider |= walk_vtables ((void (*)())0, finish_vtable_vardecl);
3041 tree decl = TREE_VALUE (*p);
3043 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3045 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3047 if (DECL_MUTABLE_P (decl))
3048 synthesize_tinfo_fn (decl);
3050 synthesize_method (decl);
3054 /* Catch new template instantiations. */
3055 if (decl != TREE_VALUE (*p))
3058 if (TREE_ASM_WRITTEN (decl)
3059 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3060 *p = TREE_CHAIN (*p);
3061 else if (DECL_INITIAL (decl) == 0)
3062 p = &TREE_CHAIN (*p);
3063 else if ((TREE_PUBLIC (decl) && ! DECL_WEAK (decl)
3064 && ! DECL_ONE_ONLY (decl))
3065 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3066 || flag_keep_inline_functions)
3068 if (DECL_NOT_REALLY_EXTERN (decl))
3070 DECL_EXTERNAL (decl) = 0;
3072 /* We can't inline this function after it's been
3073 emitted, so just disable inlining. We want a
3074 variant of output_inline_function that doesn't
3075 prevent subsequent integration... */
3077 temporary_allocation ();
3078 output_inline_function (decl);
3079 permanent_allocation (1);
3082 *p = TREE_CHAIN (*p);
3085 p = &TREE_CHAIN (*p);
3090 /* Now delete from the chain of variables all virtual function tables.
3091 We output them all ourselves, because each will be treated specially. */
3093 walk_vtables ((void (*)())0, prune_vtable_vardecl);
3095 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3097 if (TREE_CODE (vars) == FUNCTION_DECL
3098 && ! DECL_INTERFACE_KNOWN (vars)
3099 && DECL_C_STATIC (vars))
3100 TREE_PUBLIC (vars) = 0;
3103 if (write_virtuals == 2)
3105 /* Now complain about an virtual function tables promised
3106 but not delivered. */
3107 while (pending_vtables)
3109 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3110 error ("virtual function table for `%s' not defined",
3111 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3112 pending_vtables = TREE_CHAIN (pending_vtables);
3118 this_time = get_run_time ();
3119 parse_time -= this_time - start_time;
3120 varconst_time += this_time - start_time;
3122 if (flag_detailed_statistics)
3123 dump_time_statistics ();
3126 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3127 expr. Since it was parsed like a type, we need to wade through and fix
3128 that. Unfortunately, since operator() is left-associative, we can't use
3129 tail recursion. In the above example, TYPE is `A', and DECL is
3132 Maybe this shouldn't be recursive, but how often will it actually be
3136 reparse_absdcl_as_expr (type, decl)
3139 /* do build_functional_cast (type, NULL_TREE) at bottom */
3140 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3141 return build_functional_cast (type, NULL_TREE);
3144 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3146 decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3148 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3149 decl = require_complete_type (decl);
3154 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3155 out to be an expr. Since it was parsed like a type, we need to wade
3156 through and fix that. Since casts are right-associative, we are
3157 reversing the order, so we don't have to recurse.
3159 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3163 reparse_absdcl_as_casts (decl, expr)
3168 if (TREE_CODE (expr) == CONSTRUCTOR
3169 && TREE_TYPE (expr) == 0)
3171 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3172 decl = TREE_OPERAND (decl, 0);
3174 if (IS_SIGNATURE (type))
3176 error ("cast specifies signature type");
3177 return error_mark_node;
3180 expr = digest_init (type, expr, (tree *) 0);
3181 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3183 int failure = complete_array_type (type, expr, 1);
3185 my_friendly_abort (78);
3191 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3192 decl = TREE_OPERAND (decl, 0);
3193 expr = build_c_cast (type, expr, 0);
3199 /* Given plain tree nodes for an expression, build up the full semantics. */
3202 build_expr_from_tree (t)
3205 if (t == NULL_TREE || t == error_mark_node)
3208 switch (TREE_CODE (t))
3210 case IDENTIFIER_NODE:
3211 return do_identifier (t, 0);
3214 if (LOOKUP_EXPR_GLOBAL (t))
3215 return do_scoped_id (TREE_OPERAND (t, 0), 0);
3217 return do_identifier (TREE_OPERAND (t, 0), 0);
3220 return build_x_indirect_ref
3221 (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3224 return build_functional_cast
3225 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3227 case REINTERPRET_CAST_EXPR:
3228 return build_reinterpret_cast
3229 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3231 case CONST_CAST_EXPR:
3232 return build_const_cast
3233 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3235 case DYNAMIC_CAST_EXPR:
3236 return build_dynamic_cast
3237 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3239 case STATIC_CAST_EXPR:
3240 return build_static_cast
3241 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3243 case PREDECREMENT_EXPR:
3244 case PREINCREMENT_EXPR:
3245 case POSTDECREMENT_EXPR:
3246 case POSTINCREMENT_EXPR:
3250 case TRUTH_NOT_EXPR:
3252 case CONVERT_EXPR: /* Unary + */
3255 return build_x_unary_op (TREE_CODE (t),
3256 build_expr_from_tree (TREE_OPERAND (t, 0)));
3261 case TRUNC_DIV_EXPR:
3263 case FLOOR_DIV_EXPR:
3264 case ROUND_DIV_EXPR:
3265 case EXACT_DIV_EXPR:
3267 case BIT_ANDTC_EXPR:
3270 case TRUNC_MOD_EXPR:
3271 case FLOOR_MOD_EXPR:
3272 case TRUTH_ANDIF_EXPR:
3273 case TRUTH_ORIF_EXPR:
3274 case TRUTH_AND_EXPR:
3289 return build_x_binary_op
3291 build_expr_from_tree (TREE_OPERAND (t, 0)),
3292 build_expr_from_tree (TREE_OPERAND (t, 1)));
3295 return build_m_component_ref
3296 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3297 build_expr_from_tree (TREE_OPERAND (t, 1)));
3300 return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3303 if (TREE_OPERAND (t, 0) == NULL_TREE)
3305 return build_parse_node (ARRAY_REF, NULL_TREE,
3306 build_expr_from_tree (TREE_OPERAND (t, 1)));
3307 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3308 build_expr_from_tree (TREE_OPERAND (t, 1)));
3312 tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3313 if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3315 return c_sizeof (r);
3319 return build_x_modify_expr
3320 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3321 TREE_CODE (TREE_OPERAND (t, 1)),
3322 build_expr_from_tree (TREE_OPERAND (t, 2)));
3325 return build_x_arrow
3326 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3330 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3331 build_expr_from_tree (TREE_OPERAND (t, 1)),
3332 build_expr_from_tree (TREE_OPERAND (t, 2)),
3333 NEW_EXPR_USE_GLOBAL (t));
3336 return delete_sanity
3337 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3338 build_expr_from_tree (TREE_OPERAND (t, 1)),
3339 DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3342 if (TREE_OPERAND (t, 1) == NULL_TREE)
3343 return build_x_compound_expr
3344 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3346 my_friendly_abort (42);
3348 case METHOD_CALL_EXPR:
3349 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3351 tree ref = TREE_OPERAND (t, 0);
3352 return build_scoped_method_call
3353 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3354 build_expr_from_tree (TREE_OPERAND (ref, 0)),
3355 TREE_OPERAND (ref, 1),
3356 build_expr_from_tree (TREE_OPERAND (t, 2)));
3358 return build_method_call
3359 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3360 TREE_OPERAND (t, 0),
3361 build_expr_from_tree (TREE_OPERAND (t, 2)),
3362 NULL_TREE, LOOKUP_NORMAL);
3365 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3367 tree ref = TREE_OPERAND (t, 0);
3368 return build_member_call
3369 (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3370 TREE_OPERAND (ref, 1),
3371 build_expr_from_tree (TREE_OPERAND (t, 1)));
3375 tree name = TREE_OPERAND (t, 0);
3376 if (! really_overloaded_fn (name))
3377 name = build_expr_from_tree (name);
3378 return build_x_function_call
3379 (name, build_expr_from_tree (TREE_OPERAND (t, 1)),
3384 return build_x_conditional_expr
3385 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3386 build_expr_from_tree (TREE_OPERAND (t, 1)),
3387 build_expr_from_tree (TREE_OPERAND (t, 2)));
3391 tree purpose, value, chain;
3393 if (t == void_list_node)
3396 purpose = TREE_PURPOSE (t);
3398 purpose = build_expr_from_tree (purpose);
3399 value = TREE_VALUE (t);
3401 value = build_expr_from_tree (value);
3402 chain = TREE_CHAIN (t);
3403 if (chain && chain != void_type_node)
3404 chain = build_expr_from_tree (chain);
3405 return tree_cons (purpose, value, chain);
3409 return build_x_component_ref
3410 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3411 TREE_OPERAND (t, 1), NULL_TREE, 1);
3414 return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3418 tree r = build_nt (CONSTRUCTOR, NULL_TREE,
3419 build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3422 return digest_init (TREE_TYPE (t), r, 0);
3427 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3430 return convert_from_reference (t);
3437 /* This is something of the form `int (*a)++' that has turned out to be an
3438 expr. It was only converted into parse nodes, so we need to go through
3439 and build up the semantics. Most of the work is done by
3440 build_expr_from_tree, above.
3442 In the above example, TYPE is `int' and DECL is `*a'. */
3445 reparse_decl_as_expr (type, decl)
3448 decl = build_expr_from_tree (decl);
3450 return build_functional_cast (type, build_tree_list (NULL_TREE, decl));
3455 /* This is something of the form `int (*a)' that has turned out to be a
3456 decl. It was only converted into parse nodes, so we need to do the
3457 checking that make_{pointer,reference}_declarator do. */
3460 finish_decl_parsing (decl)
3463 extern int current_class_depth;
3465 switch (TREE_CODE (decl))
3467 case IDENTIFIER_NODE:
3470 return make_pointer_declarator
3471 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3473 return make_reference_declarator
3474 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3476 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3479 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3480 TREE_COMPLEXITY (decl) = current_class_depth;
3483 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3486 my_friendly_abort (5);
3492 check_cp_case_value (value)
3495 if (value == NULL_TREE)
3498 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3499 STRIP_TYPE_NOPS (value);
3501 if (TREE_READONLY_DECL_P (value))
3503 value = decl_constant_value (value);
3504 STRIP_TYPE_NOPS (value);
3506 value = fold (value);
3508 if (TREE_CODE (value) != INTEGER_CST
3509 && value != error_mark_node)
3511 cp_error ("case label `%E' does not reduce to an integer constant",
3513 value = error_mark_node;
3516 /* Promote char or short to int. */
3517 value = default_conversion (value);
3519 constant_expression_warning (value);
3524 tree current_namespace;
3526 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3527 postfix. Returns 0 if in global namespace. */
3532 tree x = current_namespace;
3534 x = TREE_PURPOSE (x);
3538 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3541 current_namespace_id (name)
3544 tree old_id = get_namespace_id ();
3547 /* Global names retain old encoding. */
3551 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3552 + IDENTIFIER_LENGTH (name));
3553 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3554 IDENTIFIER_POINTER (name));
3555 return get_identifier (buf);
3559 do_namespace_alias (alias, namespace)
3560 tree alias, namespace;
3562 sorry ("namespace alias");
3566 do_toplevel_using_decl (decl)
3569 if (decl == NULL_TREE || decl == error_mark_node)
3572 if (TREE_CODE (decl) == SCOPE_REF)
3573 decl = resolve_scope_to_name (NULL_TREE, decl);
3575 /* Is this the right way to do an id list? */
3576 if (TREE_CODE (decl) != TREE_LIST)
3583 pushdecl (TREE_VALUE (decl));
3584 decl = TREE_CHAIN (decl);
3589 do_class_using_decl (decl)
3594 if (TREE_CODE (decl) != SCOPE_REF)
3596 cp_error ("using-declaration for non-member at class scope");
3599 name = TREE_OPERAND (decl, 1);
3600 if (TREE_CODE (name) == BIT_NOT_EXPR)
3602 cp_error ("using-declaration for destructor");
3606 value = build_lang_field_decl (USING_DECL, name, void_type_node);
3607 DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
3612 do_using_directive (namespace)
3615 sorry ("using directive");
3619 check_default_args (x)
3622 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
3623 int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
3624 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
3626 if (TREE_PURPOSE (arg))
3630 cp_error ("default argument missing for parameter %P of `%#D'",
3641 TREE_USED (decl) = 1;
3642 if (processing_template_decl)
3644 assemble_external (decl);
3645 /* Is it a synthesized method that needs to be synthesized? */
3646 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
3647 && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3648 /* Kludge: don't synthesize for default args. */
3649 && current_function_decl)
3650 synthesize_method (decl);
3651 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
3652 instantiate_decl (decl);