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 if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG)
2428 /* Mark the VAR_DECL node representing the vtable itself as a
2429 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2430 It is rather important that such things be ignored because
2431 any effort to actually generate DWARF for them will run
2432 into trouble when/if we encounter code like:
2435 struct S { virtual void member (); };
2437 because the artificial declaration of the vtable itself (as
2438 manufactured by the g++ front end) will say that the vtable
2439 is a static member of `S' but only *after* the debug output
2440 for the definition of `S' has already been output. This causes
2441 grief because the DWARF entry for the definition of the vtable
2442 will try to refer back to an earlier *declaration* of the
2443 vtable as a static member of `S' and there won't be one.
2444 We might be able to arrange to have the "vtable static member"
2445 attached to the member list for `S' before the debug info for
2446 `S' get written (which would solve the problem) but that would
2447 require more intrusive changes to the g++ front end. */
2449 DECL_IGNORED_P (vars) = 1;
2452 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2455 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2456 /* We don't know what to do with this one yet. */
2459 /* We know that PREV must be non-zero here. */
2460 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2465 prune_vtable_vardecl (prev, vars)
2468 /* We know that PREV must be non-zero here. */
2469 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2474 walk_vtables (typedecl_fn, vardecl_fn)
2475 register void (*typedecl_fn)();
2476 register int (*vardecl_fn)();
2481 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2483 register tree type = TREE_TYPE (vars);
2485 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2488 flag |= (*vardecl_fn) (prev, vars);
2490 if (prev && TREE_CHAIN (prev) != vars)
2493 else if (TREE_CODE (vars) == TYPE_DECL
2494 && type != error_mark_node
2495 && TYPE_LANG_SPECIFIC (type)
2496 && CLASSTYPE_VSIZE (type))
2498 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2508 finish_sigtable_vardecl (prev, vars)
2511 /* We don't need to mark sigtable entries as addressable here as is done
2512 for vtables. Since sigtables, unlike vtables, are always written out,
2513 that was already done in build_signature_table_constructor. */
2515 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2517 /* We know that PREV must be non-zero here. */
2518 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2522 walk_sigtables (typedecl_fn, vardecl_fn)
2523 register void (*typedecl_fn)();
2524 register void (*vardecl_fn)();
2528 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2530 register tree type = TREE_TYPE (vars);
2532 if (TREE_CODE (vars) == TYPE_DECL
2533 && type != error_mark_node
2534 && IS_SIGNATURE (type))
2536 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2538 else if (TREE_CODE (vars) == VAR_DECL
2539 && TREE_TYPE (vars) != error_mark_node
2540 && IS_SIGNATURE (TREE_TYPE (vars)))
2542 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2549 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2550 inline function or template instantiation at end-of-file. */
2553 import_export_decl (decl)
2556 if (DECL_INTERFACE_KNOWN (decl))
2559 if (DECL_TEMPLATE_INSTANTIATION (decl))
2561 DECL_NOT_REALLY_EXTERN (decl) = 1;
2562 if (DECL_IMPLICIT_INSTANTIATION (decl)
2563 && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2565 if (TREE_CODE (decl) == FUNCTION_DECL)
2566 comdat_linkage (decl);
2567 /* Dynamically initialized vars go into common. */
2568 else if (DECL_INITIAL (decl) == NULL_TREE
2569 || DECL_INITIAL (decl) == error_mark_node)
2570 DECL_COMMON (decl) = 1;
2571 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
2573 DECL_COMMON (decl) = 1;
2574 DECL_INITIAL (decl) = error_mark_node;
2578 /* Statically initialized vars are weak or comdat, if
2581 make_decl_one_only (decl);
2582 /* else leave vars public so multiple defs will break. */
2586 DECL_NOT_REALLY_EXTERN (decl) = 0;
2588 else if (DECL_FUNCTION_MEMBER_P (decl))
2590 tree ctype = DECL_CLASS_CONTEXT (decl);
2591 if (CLASSTYPE_INTERFACE_KNOWN (ctype) && ! DECL_ARTIFICIAL (decl))
2593 DECL_NOT_REALLY_EXTERN (decl)
2594 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2595 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2598 comdat_linkage (decl);
2600 /* tinfo function */
2601 else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2603 tree ctype = TREE_TYPE (DECL_NAME (decl));
2604 if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2605 && TYPE_VIRTUAL_P (ctype))
2607 DECL_NOT_REALLY_EXTERN (decl)
2608 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2609 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2611 else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2612 DECL_NOT_REALLY_EXTERN (decl) = 0;
2614 comdat_linkage (decl);
2616 else if (DECL_C_STATIC (decl))
2617 TREE_PUBLIC (decl) = 0;
2619 comdat_linkage (decl);
2621 DECL_INTERFACE_KNOWN (decl) = 1;
2625 build_cleanup (decl)
2629 tree type = TREE_TYPE (decl);
2631 if (TREE_CODE (type) == ARRAY_TYPE)
2635 mark_addressable (decl);
2636 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2638 temp = build_delete (TREE_TYPE (temp), temp,
2640 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2644 extern int parse_time, varconst_time;
2645 extern tree pending_templates;
2646 extern tree maybe_templates;
2648 extern struct obstack permanent_obstack;
2649 extern tree get_id_2 ();
2655 tree sname = get_id_2 ("__sn", base);
2656 tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2659 push_obstacks (&permanent_obstack, &permanent_obstack);
2660 sentry = build_decl (VAR_DECL, sname, integer_type_node);
2661 TREE_PUBLIC (sentry) = 1;
2662 DECL_ARTIFICIAL (sentry) = 1;
2663 TREE_STATIC (sentry) = 1;
2664 TREE_USED (sentry) = 1;
2665 DECL_COMMON (sentry) = 1;
2666 pushdecl_top_level (sentry);
2667 cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2673 /* This routine is called from the last rule in yyparse ().
2674 Its job is to create all the code needed to initialize and
2675 destroy the global aggregates. We do the destruction
2676 first, since that way we only need to reverse the decls once. */
2682 int start_time, this_time;
2686 int needs_cleaning = 0, needs_messing_up = 0;
2690 if (flag_detailed_statistics)
2691 dump_tree_statistics ();
2693 /* Bad parse errors. Just forget about it. */
2694 if (! global_bindings_p () || current_class_type)
2697 start_time = get_run_time ();
2699 /* Otherwise, GDB can get confused, because in only knows
2700 about source for LINENO-1 lines. */
2703 interface_unknown = 1;
2706 for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
2708 tree decl = TREE_VALUE (fnname);
2709 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
2711 instantiate_class_template (decl);
2712 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
2713 for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
2714 if (! DECL_ARTIFICIAL (vars))
2715 instantiate_decl (vars);
2718 instantiate_decl (decl);
2721 for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
2723 tree *args, fn, decl = TREE_VALUE (fnname);
2725 if (DECL_INITIAL (decl))
2728 fn = TREE_PURPOSE (fnname);
2729 args = get_bindings (fn, decl);
2730 fn = instantiate_template (fn, args);
2732 instantiate_decl (fn);
2735 /* Push into C language context, because that's all
2737 push_lang_context (lang_name_c);
2740 /* The reason for pushing garbage onto the global_binding_level is to
2741 ensure that we can slice out _DECLs which pertain to virtual function
2742 tables. If the last thing pushed onto the global_binding_level was a
2743 virtual function table, then slicing it out would slice away all the
2744 decls (i.e., we lose the head of the chain).
2746 There are several ways of getting the same effect, from changing the
2747 way that iterators over the chain treat the elements that pertain to
2748 virtual function tables, moving the implementation of this code to
2749 decl.c (where we can manipulate global_binding_level directly),
2750 popping the garbage after pushing it and slicing away the vtable
2751 stuff, or just leaving it alone. */
2753 /* Make last thing in global scope not be a virtual function table. */
2754 #if 0 /* not yet, should get fixed properly later */
2755 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2757 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2759 DECL_IGNORED_P (vars) = 1;
2760 SET_DECL_ARTIFICIAL (vars);
2764 /* Walk to mark the inline functions we need, then output them so
2765 that we can pick up any other tdecls that those routines need. */
2766 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2768 for (vars = pending_statics; vars; vars = TREE_CHAIN (vars))
2770 tree decl = TREE_VALUE (vars);
2772 if (DECL_TEMPLATE_INSTANTIATION (decl)
2773 && ! DECL_IN_AGGR_P (decl))
2775 import_export_decl (decl);
2776 DECL_EXTERNAL (decl) = ! DECL_NOT_REALLY_EXTERN (decl);
2780 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2781 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
2782 rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
2783 vars = static_aggregates;
2785 if (static_ctors || vars || exception_table_p ())
2786 needs_messing_up = 1;
2790 /* See if we really need the hassle. */
2791 while (vars && needs_cleaning == 0)
2793 tree decl = TREE_VALUE (vars);
2794 tree type = TREE_TYPE (decl);
2795 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars))
2801 vars = TREE_CHAIN (vars);
2804 if (needs_cleaning == 0)
2807 fnname = get_file_function_name ('D');
2808 start_function (void_list_node,
2809 make_call_declarator (fnname, void_list_node, NULL_TREE,
2812 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2813 store_parm_decls ();
2818 expand_start_bindings (0);
2820 /* These must be done in backward order to destroy,
2821 in which they happen to be! */
2822 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2824 tree decl = TREE_VALUE (vars);
2825 tree type = TREE_TYPE (decl);
2826 tree temp = TREE_PURPOSE (vars);
2828 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
2829 && ! DECL_EXTERNAL (decl))
2831 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2832 || DECL_ONE_ONLY (decl)
2833 || DECL_WEAK (decl)));
2835 temp = build_cleanup (decl);
2839 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2840 sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
2841 sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
2842 expand_start_cond (sentry, 0);
2845 expand_expr_stmt (temp);
2852 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2853 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2856 expand_end_bindings (getdecls (), 1, 0);
2860 finish_function (lineno, 0, 0);
2862 assemble_destructor (IDENTIFIER_POINTER (fnname));
2864 /* if it needed cleaning, then it will need messing up: drop through */
2867 /* Must do this while we think we are at the top level. */
2868 vars = nreverse (static_aggregates);
2869 if (needs_messing_up)
2871 fnname = get_file_function_name ('I');
2872 start_function (void_list_node,
2873 make_call_declarator (fnname, void_list_node, NULL_TREE,
2876 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2877 store_parm_decls ();
2882 expand_start_bindings (0);
2884 if (exception_table_p ())
2885 register_exception_table ();
2889 extern int temp_slot_level;
2890 extern int target_temp_slot_level;
2891 tree decl = TREE_VALUE (vars);
2892 tree init = TREE_PURPOSE (vars);
2893 tree old_cleanups = cleanups_this_call;
2894 int old_temp_level = target_temp_slot_level;
2897 target_temp_slot_level = temp_slot_level;
2899 /* If this was a static attribute within some function's scope,
2900 then don't initialize it here. Also, don't bother
2901 with initializers that contain errors. */
2902 if (TREE_STATIC (vars)
2903 || DECL_EXTERNAL (decl)
2904 || (init && TREE_CODE (init) == TREE_LIST
2905 && value_member (error_mark_node, init)))
2908 if (TREE_CODE (decl) == VAR_DECL)
2910 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2911 || DECL_ONE_ONLY (decl)
2912 || DECL_WEAK (decl)));
2914 /* Set these global variables so that GDB at least puts
2915 us near the declaration which required the initialization. */
2916 input_filename = DECL_SOURCE_FILE (decl);
2917 lineno = DECL_SOURCE_LINE (decl);
2918 emit_note (input_filename, lineno);
2920 /* 9.5p5: The initializer of a static member of a class has
2921 the same access rights as a member function. */
2922 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2923 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
2927 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2928 sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
2929 sentry = build_binary_op
2930 (EQ_EXPR, sentry, integer_one_node, 1);
2931 expand_start_cond (sentry, 0);
2934 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2935 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2936 expand_aggr_init (decl, init, 0, 0);
2937 else if (TREE_CODE (init) == TREE_VEC)
2939 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2940 TREE_VEC_ELT (init, 1),
2941 TREE_VEC_ELT (init, 2), 0),
2942 const0_rtx, VOIDmode, 0);
2945 expand_assignment (decl, init, 0, 0);
2950 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2951 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
2953 else if (decl == error_mark_node)
2955 else my_friendly_abort (22);
2957 /* Cleanup any temporaries needed for the initial value. */
2958 expand_cleanups_to (old_cleanups);
2962 target_temp_slot_level = old_temp_level;
2964 vars = TREE_CHAIN (vars);
2967 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
2968 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
2971 expand_end_bindings (getdecls (), 1, 0);
2975 finish_function (lineno, 0, 0);
2976 assemble_constructor (IDENTIFIER_POINTER (fnname));
2979 expand_builtin_throw ();
2981 permanent_allocation (1);
2983 /* Done with C language context needs. */
2984 pop_lang_context ();
2986 /* Now write out any static class variables (which may have since
2987 learned how to be initialized). */
2988 while (pending_statics)
2990 tree decl = TREE_VALUE (pending_statics);
2992 if (TREE_USED (decl) == 1
2993 || TREE_READONLY (decl) == 0
2994 || DECL_INITIAL (decl) == 0)
2996 DECL_DEFER_OUTPUT (decl) = 0;
2997 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
2999 pending_statics = TREE_CHAIN (pending_statics);
3002 this_time = get_run_time ();
3003 parse_time -= this_time - start_time;
3004 varconst_time += this_time - start_time;
3006 start_time = get_run_time ();
3008 if (flag_handle_signatures)
3009 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3011 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3013 tree decl = TREE_VALUE (fnname);
3014 import_export_decl (decl);
3017 /* Now write out inline functions which had their addresses taken and
3018 which were not declared virtual and which were not declared `extern
3021 int reconsider = 1; /* More may be referenced; check again */
3025 tree *p = &saved_inlines;
3028 /* We need to do this each time so that newly completed template
3029 types don't wind up at the front of the list. Sigh. */
3030 vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3031 DECL_IGNORED_P (vars) = 1;
3032 SET_DECL_ARTIFICIAL (vars);
3035 reconsider |= walk_vtables ((void (*)())0, finish_vtable_vardecl);
3039 tree decl = TREE_VALUE (*p);
3041 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3043 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3045 if (DECL_MUTABLE_P (decl))
3046 synthesize_tinfo_fn (decl);
3048 synthesize_method (decl);
3052 /* Catch new template instantiations. */
3053 if (decl != TREE_VALUE (*p))
3056 if (TREE_ASM_WRITTEN (decl)
3057 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3058 *p = TREE_CHAIN (*p);
3059 else if (DECL_INITIAL (decl) == 0)
3060 p = &TREE_CHAIN (*p);
3061 else if ((TREE_PUBLIC (decl) && ! DECL_WEAK (decl)
3062 && ! DECL_ONE_ONLY (decl))
3063 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3064 || flag_keep_inline_functions)
3066 if (DECL_NOT_REALLY_EXTERN (decl))
3068 DECL_EXTERNAL (decl) = 0;
3070 /* We can't inline this function after it's been
3071 emitted, so just disable inlining. We want a
3072 variant of output_inline_function that doesn't
3073 prevent subsequent integration... */
3075 temporary_allocation ();
3076 output_inline_function (decl);
3077 permanent_allocation (1);
3080 *p = TREE_CHAIN (*p);
3083 p = &TREE_CHAIN (*p);
3088 /* Now delete from the chain of variables all virtual function tables.
3089 We output them all ourselves, because each will be treated specially. */
3091 walk_vtables ((void (*)())0, prune_vtable_vardecl);
3093 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3095 if (TREE_CODE (vars) == FUNCTION_DECL
3096 && ! DECL_INTERFACE_KNOWN (vars)
3097 && DECL_C_STATIC (vars))
3098 TREE_PUBLIC (vars) = 0;
3101 if (write_virtuals == 2)
3103 /* Now complain about an virtual function tables promised
3104 but not delivered. */
3105 while (pending_vtables)
3107 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3108 error ("virtual function table for `%s' not defined",
3109 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3110 pending_vtables = TREE_CHAIN (pending_vtables);
3116 this_time = get_run_time ();
3117 parse_time -= this_time - start_time;
3118 varconst_time += this_time - start_time;
3120 if (flag_detailed_statistics)
3121 dump_time_statistics ();
3124 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3125 expr. Since it was parsed like a type, we need to wade through and fix
3126 that. Unfortunately, since operator() is left-associative, we can't use
3127 tail recursion. In the above example, TYPE is `A', and DECL is
3130 Maybe this shouldn't be recursive, but how often will it actually be
3134 reparse_absdcl_as_expr (type, decl)
3137 /* do build_functional_cast (type, NULL_TREE) at bottom */
3138 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3139 return build_functional_cast (type, NULL_TREE);
3142 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3144 decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3146 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3147 decl = require_complete_type (decl);
3152 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3153 out to be an expr. Since it was parsed like a type, we need to wade
3154 through and fix that. Since casts are right-associative, we are
3155 reversing the order, so we don't have to recurse.
3157 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3161 reparse_absdcl_as_casts (decl, expr)
3166 if (TREE_CODE (expr) == CONSTRUCTOR
3167 && TREE_TYPE (expr) == 0)
3169 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3170 decl = TREE_OPERAND (decl, 0);
3172 if (IS_SIGNATURE (type))
3174 error ("cast specifies signature type");
3175 return error_mark_node;
3178 expr = digest_init (type, expr, (tree *) 0);
3179 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3181 int failure = complete_array_type (type, expr, 1);
3183 my_friendly_abort (78);
3189 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3190 decl = TREE_OPERAND (decl, 0);
3191 expr = build_c_cast (type, expr);
3197 /* Given plain tree nodes for an expression, build up the full semantics. */
3200 build_expr_from_tree (t)
3203 if (t == NULL_TREE || t == error_mark_node)
3206 switch (TREE_CODE (t))
3208 case IDENTIFIER_NODE:
3209 return do_identifier (t, 0);
3212 if (LOOKUP_EXPR_GLOBAL (t))
3213 return do_scoped_id (TREE_OPERAND (t, 0), 0);
3215 return do_identifier (TREE_OPERAND (t, 0), 0);
3218 return build_x_indirect_ref
3219 (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3222 return build_functional_cast
3223 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3225 case REINTERPRET_CAST_EXPR:
3226 return build_reinterpret_cast
3227 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3229 case CONST_CAST_EXPR:
3230 return build_const_cast
3231 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3233 case DYNAMIC_CAST_EXPR:
3234 return build_dynamic_cast
3235 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3237 case STATIC_CAST_EXPR:
3238 return build_static_cast
3239 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3241 case PREDECREMENT_EXPR:
3242 case PREINCREMENT_EXPR:
3243 case POSTDECREMENT_EXPR:
3244 case POSTINCREMENT_EXPR:
3248 case TRUTH_NOT_EXPR:
3250 case CONVERT_EXPR: /* Unary + */
3253 return build_x_unary_op (TREE_CODE (t),
3254 build_expr_from_tree (TREE_OPERAND (t, 0)));
3259 case TRUNC_DIV_EXPR:
3261 case FLOOR_DIV_EXPR:
3262 case ROUND_DIV_EXPR:
3263 case EXACT_DIV_EXPR:
3265 case BIT_ANDTC_EXPR:
3268 case TRUNC_MOD_EXPR:
3269 case FLOOR_MOD_EXPR:
3270 case TRUTH_ANDIF_EXPR:
3271 case TRUTH_ORIF_EXPR:
3272 case TRUTH_AND_EXPR:
3287 return build_x_binary_op
3289 build_expr_from_tree (TREE_OPERAND (t, 0)),
3290 build_expr_from_tree (TREE_OPERAND (t, 1)));
3293 return build_m_component_ref
3294 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3295 build_expr_from_tree (TREE_OPERAND (t, 1)));
3298 return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3301 if (TREE_OPERAND (t, 0) == NULL_TREE)
3303 return build_parse_node (ARRAY_REF, NULL_TREE,
3304 build_expr_from_tree (TREE_OPERAND (t, 1)));
3305 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3306 build_expr_from_tree (TREE_OPERAND (t, 1)));
3310 tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3311 if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3313 return c_sizeof (r);
3317 return build_x_modify_expr
3318 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3319 TREE_CODE (TREE_OPERAND (t, 1)),
3320 build_expr_from_tree (TREE_OPERAND (t, 2)));
3323 return build_x_arrow
3324 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3328 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3329 build_expr_from_tree (TREE_OPERAND (t, 1)),
3330 build_expr_from_tree (TREE_OPERAND (t, 2)),
3331 NEW_EXPR_USE_GLOBAL (t));
3334 return delete_sanity
3335 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3336 build_expr_from_tree (TREE_OPERAND (t, 1)),
3337 DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3340 if (TREE_OPERAND (t, 1) == NULL_TREE)
3341 return build_x_compound_expr
3342 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3344 my_friendly_abort (42);
3346 case METHOD_CALL_EXPR:
3347 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3349 tree ref = TREE_OPERAND (t, 0);
3350 return build_scoped_method_call
3351 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3352 build_expr_from_tree (TREE_OPERAND (ref, 0)),
3353 TREE_OPERAND (ref, 1),
3354 build_expr_from_tree (TREE_OPERAND (t, 2)));
3356 return build_method_call
3357 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3358 TREE_OPERAND (t, 0),
3359 build_expr_from_tree (TREE_OPERAND (t, 2)),
3360 NULL_TREE, LOOKUP_NORMAL);
3363 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3365 tree ref = TREE_OPERAND (t, 0);
3366 return build_member_call
3367 (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3368 TREE_OPERAND (ref, 1),
3369 build_expr_from_tree (TREE_OPERAND (t, 1)));
3373 tree name = TREE_OPERAND (t, 0);
3374 if (! really_overloaded_fn (name))
3375 name = build_expr_from_tree (name);
3376 return build_x_function_call
3377 (name, build_expr_from_tree (TREE_OPERAND (t, 1)),
3382 return build_x_conditional_expr
3383 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3384 build_expr_from_tree (TREE_OPERAND (t, 1)),
3385 build_expr_from_tree (TREE_OPERAND (t, 2)));
3389 tree purpose, value, chain;
3391 if (t == void_list_node)
3394 purpose = TREE_PURPOSE (t);
3396 purpose = build_expr_from_tree (purpose);
3397 value = TREE_VALUE (t);
3399 value = build_expr_from_tree (value);
3400 chain = TREE_CHAIN (t);
3401 if (chain && chain != void_type_node)
3402 chain = build_expr_from_tree (chain);
3403 return tree_cons (purpose, value, chain);
3407 return build_x_component_ref
3408 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3409 TREE_OPERAND (t, 1), NULL_TREE, 1);
3412 return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3416 tree r = build_nt (CONSTRUCTOR, NULL_TREE,
3417 build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3420 return digest_init (TREE_TYPE (t), r, 0);
3425 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3428 return convert_from_reference (t);
3435 /* This is something of the form `int (*a)++' that has turned out to be an
3436 expr. It was only converted into parse nodes, so we need to go through
3437 and build up the semantics. Most of the work is done by
3438 build_expr_from_tree, above.
3440 In the above example, TYPE is `int' and DECL is `*a'. */
3443 reparse_decl_as_expr (type, decl)
3446 decl = build_expr_from_tree (decl);
3448 return build_functional_cast (type, build_tree_list (NULL_TREE, decl));
3453 /* This is something of the form `int (*a)' that has turned out to be a
3454 decl. It was only converted into parse nodes, so we need to do the
3455 checking that make_{pointer,reference}_declarator do. */
3458 finish_decl_parsing (decl)
3461 extern int current_class_depth;
3463 switch (TREE_CODE (decl))
3465 case IDENTIFIER_NODE:
3468 return make_pointer_declarator
3469 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3471 return make_reference_declarator
3472 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3474 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3477 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3478 TREE_COMPLEXITY (decl) = current_class_depth;
3481 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3484 my_friendly_abort (5);
3490 check_cp_case_value (value)
3493 if (value == NULL_TREE)
3496 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3497 STRIP_TYPE_NOPS (value);
3499 if (TREE_READONLY_DECL_P (value))
3501 value = decl_constant_value (value);
3502 STRIP_TYPE_NOPS (value);
3504 value = fold (value);
3506 if (TREE_CODE (value) != INTEGER_CST
3507 && value != error_mark_node)
3509 cp_error ("case label `%E' does not reduce to an integer constant",
3511 value = error_mark_node;
3514 /* Promote char or short to int. */
3515 value = default_conversion (value);
3517 constant_expression_warning (value);
3522 tree current_namespace;
3524 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3525 postfix. Returns 0 if in global namespace. */
3530 tree x = current_namespace;
3532 x = TREE_PURPOSE (x);
3536 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3539 current_namespace_id (name)
3542 tree old_id = get_namespace_id ();
3545 /* Global names retain old encoding. */
3549 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3550 + IDENTIFIER_LENGTH (name));
3551 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3552 IDENTIFIER_POINTER (name));
3553 return get_identifier (buf);
3557 do_namespace_alias (alias, namespace)
3558 tree alias, namespace;
3560 sorry ("namespace alias");
3564 do_toplevel_using_decl (decl)
3567 if (decl == NULL_TREE || decl == error_mark_node)
3570 if (TREE_CODE (decl) == SCOPE_REF)
3571 decl = resolve_scope_to_name (NULL_TREE, decl);
3573 /* Is this the right way to do an id list? */
3574 if (TREE_CODE (decl) != TREE_LIST)
3581 pushdecl (TREE_VALUE (decl));
3582 decl = TREE_CHAIN (decl);
3587 do_class_using_decl (decl)
3592 if (TREE_CODE (decl) != SCOPE_REF)
3594 cp_error ("using-declaration for non-member at class scope");
3597 name = TREE_OPERAND (decl, 1);
3598 if (TREE_CODE (name) == BIT_NOT_EXPR)
3600 cp_error ("using-declaration for destructor");
3604 value = build_lang_field_decl (USING_DECL, name, void_type_node);
3605 DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
3610 do_using_directive (namespace)
3613 sorry ("using directive");
3617 check_default_args (x)
3620 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
3621 int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
3622 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
3624 if (TREE_PURPOSE (arg))
3628 cp_error ("default argument missing for parameter %P of `%#D'",
3639 TREE_USED (decl) = 1;
3640 if (processing_template_decl)
3642 assemble_external (decl);
3643 /* Is it a synthesized method that needs to be synthesized? */
3644 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
3645 && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3646 /* Kludge: don't synthesize for default args. */
3647 && current_function_decl)
3648 synthesize_method (decl);
3649 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
3650 instantiate_decl (decl);