Initial revision
[official-gcc.git] / gcc / cp / decl2.c
blobb4fced4a1270f6e0a7095218c4f9f945eb772746
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)
10 any later version.
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. */
30 #include "config.h"
31 #include <stdio.h>
32 #include "tree.h"
33 #include "rtl.h"
34 #include "flags.h"
35 #include "cp-tree.h"
36 #include "decl.h"
37 #include "lex.h"
38 #include "output.h"
40 extern tree get_file_function_name ();
41 static void grok_function_init PROTO((tree, tree));
42 void import_export_decl ();
43 extern int current_class_depth;
45 /* A list of virtual function tables we must make sure to write out. */
46 tree pending_vtables;
48 /* A list of static class variables. This is needed, because a
49 static class variable can be declared inside the class without
50 an initializer, and then initialized, staticly, outside the class. */
51 tree pending_statics;
53 /* A list of functions which were declared inline, but which we
54 may need to emit outline anyway. */
55 static tree saved_inlines;
57 /* Used to help generate temporary names which are unique within
58 a function. Reset to 0 by start_function. */
60 int temp_name_counter;
62 /* Same, but not reset. Local temp variables and global temp variables
63 can have the same name. */
64 static int global_temp_name_counter;
66 /* Flag used when debugging spew.c */
68 extern int spew_debug;
70 /* Nonzero if we're done parsing and into end-of-file activities. */
72 int at_eof;
74 /* Functions called along with real static constructors and destructors. */
76 tree static_ctors, static_dtors;
78 /* C (and C++) language-specific option variables. */
80 /* Nonzero means allow type mismatches in conditional expressions;
81 just make their values `void'. */
83 int flag_cond_mismatch;
85 /* Nonzero means give `double' the same size as `float'. */
87 int flag_short_double;
89 /* Nonzero means don't recognize the keyword `asm'. */
91 int flag_no_asm;
93 /* Nonzero means don't recognize any extension keywords. */
95 int flag_no_gnu_keywords;
97 /* Nonzero means don't recognize the non-ANSI builtin functions. */
99 int flag_no_builtin;
101 /* Nonzero means don't recognize the non-ANSI builtin functions.
102 -ansi sets this. */
104 int flag_no_nonansi_builtin;
106 /* Nonzero means do some things the same way PCC does. Only provided so
107 the compiler will link. */
109 int flag_traditional;
111 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
113 int flag_signed_bitfields = 1;
115 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
117 int flag_no_ident;
119 /* Nonzero means enable obscure ANSI features and disable GNU extensions
120 that might cause ANSI-compliant code to be miscompiled. */
122 int flag_ansi;
124 /* Nonzero means do argument matching for overloading according to the
125 ANSI rules, rather than what g++ used to believe to be correct. */
127 int flag_ansi_overloading = 1;
129 /* Nonzero means do emit exported implementations of functions even if
130 they can be inlined. */
132 int flag_implement_inlines = 1;
134 /* Nonzero means do emit exported implementations of templates, instead of
135 multiple static copies in each file that needs a definition. */
137 int flag_external_templates;
139 /* Nonzero means that the decision to emit or not emit the implementation of a
140 template depends on where the template is instantiated, rather than where
141 it is defined. */
143 int flag_alt_external_templates;
145 /* Nonzero means that implicit instantiations will be emitted if needed. */
147 int flag_implicit_templates = 1;
149 /* Nonzero means warn about implicit declarations. */
151 int warn_implicit = 1;
153 /* Nonzero means warn when all ctors or dtors are private, and the class
154 has no friends. */
156 int warn_ctor_dtor_privacy = 1;
158 /* True if we want to implement vtables using "thunks".
159 The default is off. */
161 #if defined(NEW_OVER) && defined (__i386__)
162 int flag_vtable_thunks = 1;
163 #else
164 int flag_vtable_thunks;
165 #endif
167 /* True if we want to deal with repository information. */
169 int flag_use_repository;
171 /* Nonzero means give string constants the type `const char *'
172 to get extra warnings from them. These warnings will be too numerous
173 to be useful, except in thoroughly ANSIfied programs. */
175 int warn_write_strings;
177 /* Nonzero means warn about pointer casts that can drop a type qualifier
178 from the pointer target type. */
180 int warn_cast_qual;
182 /* Nonzero means warn that dbx info for template class methods isn't fully
183 supported yet. */
185 int warn_template_debugging;
187 /* Nonzero means warn about sizeof(function) or addition/subtraction
188 of function pointers. */
190 int warn_pointer_arith = 1;
192 /* Nonzero means warn for any function def without prototype decl. */
194 int warn_missing_prototypes;
196 /* Nonzero means warn about multiple (redundant) decls for the same single
197 variable or function. */
199 int warn_redundant_decls;
201 /* Warn if initializer is not completely bracketed. */
203 int warn_missing_braces;
205 /* Warn about comparison of signed and unsigned values. */
207 int warn_sign_compare;
209 /* Warn about *printf or *scanf format/argument anomalies. */
211 int warn_format;
213 /* Warn about a subscript that has type char. */
215 int warn_char_subscripts;
217 /* Warn if a type conversion is done that might have confusing results. */
219 int warn_conversion;
221 /* Warn if adding () is suggested. */
223 int warn_parentheses;
225 /* Non-zero means warn in function declared in derived class has the
226 same name as a virtual in the base class, but fails to match the
227 type signature of any virtual function in the base class. */
228 int warn_overloaded_virtual;
230 /* Non-zero means warn when declaring a class that has a non virtual
231 destructor, when it really ought to have a virtual one. */
232 int warn_nonvdtor;
234 /* Non-zero means warn when a function is declared extern and later inline. */
235 int warn_extern_inline;
237 /* Non-zero means warn when the compiler will reorder code. */
238 int warn_reorder;
240 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
241 int warn_synth;
243 /* Non-zero means warn when we convert a pointer to member function
244 into a pointer to (void or function). */
245 int warn_pmf2ptr = 1;
247 /* Nonzero means warn about violation of some Effective C++ style rules. */
249 int warn_ecpp = 0;
251 /* Nonzero means `$' can be in an identifier.
252 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
254 #ifndef DOLLARS_IN_IDENTIFIERS
255 #define DOLLARS_IN_IDENTIFIERS 1
256 #endif
257 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
259 /* Nonzero for -fno-strict-prototype switch: do not consider empty
260 argument prototype to mean function takes no arguments. */
262 int flag_strict_prototype = 2;
263 int strict_prototype = 1;
264 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
266 /* Nonzero means that labels can be used as first-class objects */
268 int flag_labels_ok;
270 /* Non-zero means to collect statistics which might be expensive
271 and to print them when we are done. */
272 int flag_detailed_statistics;
274 /* C++ specific flags. */
275 /* Nonzero for -fall-virtual: make every member function (except
276 constructors) lay down in the virtual function table. Calls
277 can then either go through the virtual function table or not,
278 depending. */
280 int flag_all_virtual;
282 /* Zero means that `this' is a *const. This gives nice behavior in the
283 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
284 -2 means we're constructing an object and it has fixed type. */
286 int flag_this_is_variable;
288 /* Nonzero means memoize our member lookups. */
290 int flag_memoize_lookups; int flag_save_memoized_contexts;
292 /* 3 means write out only virtuals function tables `defined'
293 in this implementation file.
294 2 means write out only specific virtual function tables
295 and give them (C) public access.
296 1 means write out virtual function tables and give them
297 (C) public access.
298 0 means write out virtual function tables and give them
299 (C) static access (default).
300 -1 means declare virtual function tables extern. */
302 int write_virtuals;
304 /* Nonzero means we should attempt to elide constructors when possible. */
306 int flag_elide_constructors;
308 /* Nonzero means recognize and handle signature language constructs. */
310 int flag_handle_signatures;
312 /* Nonzero means that member functions defined in class scope are
313 inline by default. */
315 int flag_default_inline = 1;
317 /* Controls whether enums and ints freely convert.
318 1 means with complete freedom.
319 0 means enums can convert to ints, but not vice-versa. */
320 int flag_int_enum_equivalence;
322 /* Controls whether compiler generates 'type descriptor' that give
323 run-time type information. */
324 int flag_rtti = 1;
326 /* Nonzero if we wish to output cross-referencing information
327 for the GNU class browser. */
328 extern int flag_gnu_xref;
330 /* Nonzero if compiler can make `reasonable' assumptions about
331 references and objects. For example, the compiler must be
332 conservative about the following and not assume that `a' is nonnull:
334 obj &a = g ();
335 a.f (2);
337 In general, it is `reasonable' to assume that for many programs,
338 and better code can be generated in that case. */
340 int flag_assume_nonnull_objects = 1;
342 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
343 objects. */
345 int flag_huge_objects;
347 /* Nonzero if we want to conserve space in the .o files. We do this
348 by putting uninitialized data and runtime initialized data into
349 .common instead of .data at the expense of not flagging multiple
350 definitions. */
352 int flag_conserve_space;
354 /* Nonzero if we want to obey access control semantics. */
356 int flag_access_control = 1;
358 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
360 int flag_operator_names;
362 /* Nonzero if we want to check the return value of new and avoid calling
363 constructors if it is a null pointer. */
365 int flag_check_new;
367 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
368 initialization variables.
369 0: Old rules, set by -fno-for-scope.
370 2: New ANSI rules, set by -ffor-scope.
371 1: Try to implement new ANSI rules, but with backup compatibility
372 (and warnings). This is the default, for now. */
374 int flag_new_for_scope = 1;
376 /* Nonzero if we want to emit defined symbols with common-like linkage as
377 weak symbols where possible, in order to conform to C++ semantics.
378 Otherwise, emit them as local symbols. */
380 int flag_weak = 1;
382 /* Maximum template instantiation depth. Must be at least 17 for ANSI
383 compliance. */
385 int max_tinst_depth = 17;
387 /* Table of language-dependent -f options.
388 STRING is the option name. VARIABLE is the address of the variable.
389 ON_VALUE is the value to store in VARIABLE
390 if `-fSTRING' is seen as an option.
391 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
393 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
395 {"signed-char", &flag_signed_char, 1},
396 {"unsigned-char", &flag_signed_char, 0},
397 {"signed-bitfields", &flag_signed_bitfields, 1},
398 {"unsigned-bitfields", &flag_signed_bitfields, 0},
399 {"short-enums", &flag_short_enums, 1},
400 {"short-double", &flag_short_double, 1},
401 {"cond-mismatch", &flag_cond_mismatch, 1},
402 {"asm", &flag_no_asm, 0},
403 {"builtin", &flag_no_builtin, 0},
404 {"ident", &flag_no_ident, 0},
405 {"labels-ok", &flag_labels_ok, 1},
406 {"stats", &flag_detailed_statistics, 1},
407 {"this-is-variable", &flag_this_is_variable, 1},
408 {"strict-prototype", &flag_strict_prototype, 1},
409 {"all-virtual", &flag_all_virtual, 1},
410 {"memoize-lookups", &flag_memoize_lookups, 1},
411 {"elide-constructors", &flag_elide_constructors, 1},
412 {"handle-signatures", &flag_handle_signatures, 1},
413 {"default-inline", &flag_default_inline, 1},
414 {"dollars-in-identifiers", &dollars_in_ident, 1},
415 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
416 {"rtti", &flag_rtti, 1},
417 {"xref", &flag_gnu_xref, 1},
418 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
419 {"implement-inlines", &flag_implement_inlines, 1},
420 {"external-templates", &flag_external_templates, 1},
421 {"implicit-templates", &flag_implicit_templates, 1},
422 {"ansi-overloading", &flag_ansi_overloading, 1},
423 {"huge-objects", &flag_huge_objects, 1},
424 {"conserve-space", &flag_conserve_space, 1},
425 {"vtable-thunks", &flag_vtable_thunks, 1},
426 {"access-control", &flag_access_control, 1},
427 {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
428 {"gnu-keywords", &flag_no_gnu_keywords, 0},
429 {"operator-names", &flag_operator_names, 1},
430 {"check-new", &flag_check_new, 1},
431 {"repo", &flag_use_repository, 1},
432 {"for-scope", &flag_new_for_scope, 2},
433 {"weak", &flag_weak, 1}
436 /* Decode the string P as a language-specific option.
437 Return 1 if it is recognized (and handle it);
438 return 0 if not recognized. */
440 int
441 lang_decode_option (p)
442 char *p;
444 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
445 dollars_in_ident = 1, flag_writable_strings = 1,
446 flag_this_is_variable = 1, flag_new_for_scope = 0;
447 /* The +e options are for cfront compatibility. They come in as
448 `-+eN', to kludge around gcc.c's argument handling. */
449 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
451 int old_write_virtuals = write_virtuals;
452 if (p[3] == '1')
453 write_virtuals = 1;
454 else if (p[3] == '0')
455 write_virtuals = -1;
456 else if (p[3] == '2')
457 write_virtuals = 2;
458 else error ("invalid +e option");
459 if (old_write_virtuals != 0
460 && write_virtuals != old_write_virtuals)
461 error ("conflicting +e options given");
463 else if (p[0] == '-' && p[1] == 'f')
465 /* Some kind of -f option.
466 P's value is the option sans `-f'.
467 Search for it in the table of options. */
468 int found = 0, j;
470 p += 2;
471 /* Try special -f options. */
473 if (!strcmp (p, "save-memoized"))
475 flag_memoize_lookups = 1;
476 flag_save_memoized_contexts = 1;
477 found = 1;
479 if (!strcmp (p, "no-save-memoized"))
481 flag_memoize_lookups = 0;
482 flag_save_memoized_contexts = 0;
483 found = 1;
485 else if (! strcmp (p, "alt-external-templates"))
487 flag_external_templates = 1;
488 flag_alt_external_templates = 1;
489 found = 1;
491 else if (! strcmp (p, "no-alt-external-templates"))
493 flag_alt_external_templates = 0;
494 found = 1;
496 else if (!strcmp (p, "repo"))
498 flag_use_repository = 1;
499 flag_implicit_templates = 0;
500 found = 1;
502 else if (!strncmp (p, "template-depth-", 15))
504 char *endp = p + 15;
505 while (*endp)
507 if (*endp >= '0' && *endp <= '9')
508 endp++;
509 else
511 error ("Invalid option `%s'", p - 2);
512 goto template_depth_lose;
515 max_tinst_depth = atoi (p + 15);
516 template_depth_lose: ;
518 else for (j = 0;
519 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
520 j++)
522 if (!strcmp (p, lang_f_options[j].string))
524 *lang_f_options[j].variable = lang_f_options[j].on_value;
525 /* A goto here would be cleaner,
526 but breaks the vax pcc. */
527 found = 1;
529 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
530 && ! strcmp (p+3, lang_f_options[j].string))
532 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
533 found = 1;
536 return found;
538 else if (p[0] == '-' && p[1] == 'W')
540 int setting = 1;
542 /* The -W options control the warning behavior of the compiler. */
543 p += 2;
545 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
546 setting = 0, p += 3;
548 if (!strcmp (p, "implicit"))
549 warn_implicit = setting;
550 else if (!strcmp (p, "return-type"))
551 warn_return_type = setting;
552 else if (!strcmp (p, "ctor-dtor-privacy"))
553 warn_ctor_dtor_privacy = setting;
554 else if (!strcmp (p, "write-strings"))
555 warn_write_strings = setting;
556 else if (!strcmp (p, "cast-qual"))
557 warn_cast_qual = setting;
558 else if (!strcmp (p, "char-subscripts"))
559 warn_char_subscripts = setting;
560 else if (!strcmp (p, "pointer-arith"))
561 warn_pointer_arith = setting;
562 else if (!strcmp (p, "missing-prototypes"))
563 warn_missing_prototypes = setting;
564 else if (!strcmp (p, "redundant-decls"))
565 warn_redundant_decls = setting;
566 else if (!strcmp (p, "missing-braces"))
567 warn_missing_braces = setting;
568 else if (!strcmp (p, "sign-compare"))
569 warn_sign_compare = setting;
570 else if (!strcmp (p, "format"))
571 warn_format = setting;
572 else if (!strcmp (p, "conversion"))
573 warn_conversion = setting;
574 else if (!strcmp (p, "parentheses"))
575 warn_parentheses = setting;
576 else if (!strcmp (p, "non-virtual-dtor"))
577 warn_nonvdtor = setting;
578 else if (!strcmp (p, "extern-inline"))
579 warn_extern_inline = setting;
580 else if (!strcmp (p, "reorder"))
581 warn_reorder = setting;
582 else if (!strcmp (p, "synth"))
583 warn_synth = setting;
584 else if (!strcmp (p, "pmf-conversions"))
585 warn_pmf2ptr = setting;
586 else if (!strcmp (p, "effc++"))
587 warn_ecpp = setting;
588 else if (!strcmp (p, "comment"))
589 ; /* cpp handles this one. */
590 else if (!strcmp (p, "comments"))
591 ; /* cpp handles this one. */
592 else if (!strcmp (p, "trigraphs"))
593 ; /* cpp handles this one. */
594 else if (!strcmp (p, "import"))
595 ; /* cpp handles this one. */
596 else if (!strcmp (p, "all"))
598 warn_return_type = setting;
599 warn_unused = setting;
600 warn_implicit = setting;
601 warn_ctor_dtor_privacy = setting;
602 warn_switch = setting;
603 warn_format = setting;
604 warn_parentheses = setting;
605 warn_missing_braces = setting;
606 warn_sign_compare = setting;
607 warn_extern_inline = setting;
608 warn_nonvdtor = setting;
609 /* We save the value of warn_uninitialized, since if they put
610 -Wuninitialized on the command line, we need to generate a
611 warning about not using it without also specifying -O. */
612 if (warn_uninitialized != 1)
613 warn_uninitialized = (setting ? 2 : 0);
614 warn_template_debugging = setting;
615 warn_reorder = setting;
618 else if (!strcmp (p, "overloaded-virtual"))
619 warn_overloaded_virtual = setting;
620 else return 0;
622 else if (!strcmp (p, "-ansi"))
623 dollars_in_ident = 0, flag_no_nonansi_builtin = 1, flag_ansi = 1,
624 flag_no_gnu_keywords = 1, flag_operator_names = 1;
625 #ifdef SPEW_DEBUG
626 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
627 it's probably safe to assume no sane person would ever want to use this
628 under normal circumstances. */
629 else if (!strcmp (p, "-spew-debug"))
630 spew_debug = 1;
631 #endif
632 else
633 return 0;
635 return 1;
638 /* Incorporate `const' and `volatile' qualifiers for member functions.
639 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
640 QUALS is a list of qualifiers. */
642 tree
643 grok_method_quals (ctype, function, quals)
644 tree ctype, function, quals;
646 tree fntype = TREE_TYPE (function);
647 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
651 extern tree ridpointers[];
653 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
655 if (TYPE_READONLY (ctype))
656 error ("duplicate `%s' %s",
657 IDENTIFIER_POINTER (TREE_VALUE (quals)),
658 (TREE_CODE (function) == FUNCTION_DECL
659 ? "for member function" : "in type declaration"));
660 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
661 build_pointer_type (ctype);
663 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
665 if (TYPE_VOLATILE (ctype))
666 error ("duplicate `%s' %s",
667 IDENTIFIER_POINTER (TREE_VALUE (quals)),
668 (TREE_CODE (function) == FUNCTION_DECL
669 ? "for member function" : "in type declaration"));
670 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
671 build_pointer_type (ctype);
673 else
674 my_friendly_abort (20);
675 quals = TREE_CHAIN (quals);
677 while (quals);
678 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
679 (TREE_CODE (fntype) == METHOD_TYPE
680 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
681 : TYPE_ARG_TYPES (fntype)));
682 if (raises)
683 fntype = build_exception_variant (fntype, raises);
685 TREE_TYPE (function) = fntype;
686 return ctype;
689 #if 0 /* Not used. */
690 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
691 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
692 /* This does not yet work with user defined conversion operators
693 It should. */
695 static void
696 substitute_nice_name (decl)
697 tree decl;
699 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
701 char *n = decl_as_string (DECL_NAME (decl), 1);
702 if (n[strlen (n) - 1] == ' ')
703 n[strlen (n) - 1] = 0;
704 DECL_NAME (decl) = get_identifier (n);
707 #endif
709 /* Warn when -fexternal-templates is used and #pragma
710 interface/implementation is not used all the times it should be,
711 inform the user. */
713 void
714 warn_if_unknown_interface (decl)
715 tree decl;
717 static int already_warned = 0;
718 if (already_warned++)
719 return;
721 if (flag_alt_external_templates)
723 struct tinst_level *til = tinst_for_decl ();
724 int sl = lineno;
725 char *sf = input_filename;
727 if (til)
729 lineno = til->line;
730 input_filename = til->file;
732 cp_warning ("template `%#D' instantiated in file without #pragma interface",
733 decl);
734 lineno = sl;
735 input_filename = sf;
737 else
738 cp_warning_at ("template `%#D' defined in file without #pragma interface",
739 decl);
742 /* A subroutine of the parser, to handle a component list. */
744 tree
745 grok_x_components (specs, components)
746 tree specs, components;
748 register tree t, x, tcode;
750 /* We just got some friends. They have been recorded elsewhere. */
751 if (components == void_type_node)
752 return NULL_TREE;
754 if (components == NULL_TREE)
756 t = groktypename (build_decl_list (specs, NULL_TREE));
758 if (t == NULL_TREE)
760 error ("error in component specification");
761 return NULL_TREE;
764 switch (TREE_CODE (t))
766 case VAR_DECL:
767 /* Static anonymous unions come out as VAR_DECLs. */
768 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
769 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
770 return t;
772 /* We return SPECS here, because in the parser it was ending
773 up with not doing anything to $$, which is what SPECS
774 represents. */
775 return specs;
776 break;
778 case RECORD_TYPE:
779 /* This code may be needed for UNION_TYPEs as
780 well. */
781 tcode = record_type_node;
782 if (CLASSTYPE_DECLARED_CLASS (t))
783 tcode = class_type_node;
784 else if (IS_SIGNATURE (t))
785 tcode = signature_type_node;
787 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
788 if (TYPE_CONTEXT (t))
789 CLASSTYPE_NO_GLOBALIZE (t) = 1;
790 return NULL_TREE;
791 break;
793 case UNION_TYPE:
794 case ENUMERAL_TYPE:
795 if (TREE_CODE (t) == UNION_TYPE)
796 tcode = union_type_node;
797 else
798 tcode = enum_type_node;
800 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
801 if (TREE_CODE (t) == UNION_TYPE && TYPE_CONTEXT (t))
802 CLASSTYPE_NO_GLOBALIZE (t) = 1;
803 if (TREE_CODE (t) == UNION_TYPE
804 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
806 /* See also shadow_tag. */
808 struct pending_inline **p;
809 tree *q;
810 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
812 /* Wipe out memory of synthesized methods */
813 TYPE_HAS_CONSTRUCTOR (t) = 0;
814 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
815 TYPE_HAS_INIT_REF (t) = 0;
816 TYPE_HAS_CONST_INIT_REF (t) = 0;
817 TYPE_HAS_ASSIGN_REF (t) = 0;
818 TYPE_HAS_ASSIGNMENT (t) = 0;
819 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
821 q = &TYPE_METHODS (t);
822 while (*q)
824 if (DECL_ARTIFICIAL (*q))
825 *q = TREE_CHAIN (*q);
826 else
827 q = &TREE_CHAIN (*q);
829 if (TYPE_METHODS (t))
830 error ("an anonymous union cannot have function members");
832 p = &pending_inlines;
833 for (; *p; *p = (*p)->next)
834 if (DECL_CONTEXT ((*p)->fndecl) != t)
835 break;
837 else if (TREE_CODE (t) == ENUMERAL_TYPE)
838 x = grok_enum_decls (t, NULL_TREE);
839 else
840 x = NULL_TREE;
841 return x;
842 break;
844 default:
845 if (t != void_type_node)
846 error ("empty component declaration");
847 return NULL_TREE;
850 else
852 t = TREE_TYPE (components);
853 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
854 return grok_enum_decls (t, components);
855 else
856 return components;
860 /* Classes overload their constituent function names automatically.
861 When a function name is declared in a record structure,
862 its name is changed to it overloaded name. Since names for
863 constructors and destructors can conflict, we place a leading
864 '$' for destructors.
866 CNAME is the name of the class we are grokking for.
868 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
870 FLAGS contains bits saying what's special about today's
871 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
873 If FUNCTION is a destructor, then we must add the `auto-delete' field
874 as a second parameter. There is some hair associated with the fact
875 that we must "declare" this variable in the manner consistent with the
876 way the rest of the arguments were declared.
878 QUALS are the qualifiers for the this pointer. */
880 void
881 grokclassfn (ctype, cname, function, flags, quals)
882 tree ctype, cname, function;
883 enum overload_flags flags;
884 tree quals;
886 tree fn_name = DECL_NAME (function);
887 tree arg_types;
888 tree parm;
889 tree qualtype;
890 tree fntype = TREE_TYPE (function);
891 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
893 if (fn_name == NULL_TREE)
895 error ("name missing for member function");
896 fn_name = get_identifier ("<anonymous>");
897 DECL_NAME (function) = fn_name;
900 if (quals)
901 qualtype = grok_method_quals (ctype, function, quals);
902 else
903 qualtype = ctype;
905 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
906 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
908 /* Must add the class instance variable up front. */
909 /* Right now we just make this a pointer. But later
910 we may wish to make it special. */
911 tree type = TREE_VALUE (arg_types);
912 int constp = 1;
914 if ((flag_this_is_variable > 0)
915 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
916 constp = 0;
918 if (DECL_CONSTRUCTOR_P (function))
920 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
922 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
923 /* In this case we need "in-charge" flag saying whether
924 this constructor is responsible for initialization
925 of virtual baseclasses or not. */
926 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
927 /* Mark the artificial `__in_chrg' parameter as "artificial". */
928 SET_DECL_ARTIFICIAL (parm);
929 DECL_ARG_TYPE (parm) = integer_type_node;
930 TREE_READONLY (parm) = 1;
931 TREE_CHAIN (parm) = last_function_parms;
932 last_function_parms = parm;
936 parm = build_decl (PARM_DECL, this_identifier, type);
937 /* Mark the artificial `this' parameter as "artificial". */
938 SET_DECL_ARTIFICIAL (parm);
939 DECL_ARG_TYPE (parm) = type;
940 /* We can make this a register, so long as we don't
941 accidentally complain if someone tries to take its address. */
942 DECL_REGISTER (parm) = 1;
943 if (constp)
944 TREE_READONLY (parm) = 1;
945 TREE_CHAIN (parm) = last_function_parms;
946 last_function_parms = parm;
949 if (flags == DTOR_FLAG)
951 char *buf, *dbuf;
952 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
954 arg_types = hash_tree_chain (integer_type_node, void_list_node);
955 TREE_SIDE_EFFECTS (arg_types) = 1;
956 /* Build the overload name. It will look like `7Example'. */
957 if (IDENTIFIER_TYPE_VALUE (cname))
958 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
959 else if (IDENTIFIER_LOCAL_VALUE (cname))
960 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
961 else
962 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
963 it's defined out of the class definition, since poplevel_class wipes
964 it out. This used to be internal error 346. */
965 dbuf = build_overload_name (ctype, 1, 1);
966 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
967 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
968 buf[len] = '\0';
969 strcat (buf, dbuf);
970 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
971 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
972 /* Mark the artificial `__in_chrg' parameter as "artificial". */
973 SET_DECL_ARTIFICIAL (parm);
974 TREE_READONLY (parm) = 1;
975 DECL_ARG_TYPE (parm) = integer_type_node;
976 /* This is the same chain as DECL_ARGUMENTS (...). */
977 TREE_CHAIN (last_function_parms) = parm;
979 fntype = build_cplus_method_type (qualtype, void_type_node,
980 arg_types);
981 if (raises)
983 fntype = build_exception_variant (fntype, raises);
985 TREE_TYPE (function) = fntype;
986 TYPE_HAS_DESTRUCTOR (ctype) = 1;
988 else
990 tree these_arg_types;
992 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
994 arg_types = hash_tree_chain (integer_type_node,
995 TREE_CHAIN (arg_types));
996 fntype = build_cplus_method_type (qualtype,
997 TREE_TYPE (TREE_TYPE (function)),
998 arg_types);
999 if (raises)
1001 fntype = build_exception_variant (fntype, raises);
1003 TREE_TYPE (function) = fntype;
1004 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
1007 these_arg_types = arg_types;
1009 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
1010 /* Only true for static member functions. */
1011 these_arg_types = hash_tree_chain (build_pointer_type (qualtype),
1012 arg_types);
1014 DECL_ASSEMBLER_NAME (function)
1015 = build_decl_overload (fn_name, these_arg_types,
1016 1 + DECL_CONSTRUCTOR_P (function));
1018 #if 0
1019 /* This code is going into the compiler, but currently, it makes
1020 libg++/src/Integer.cc not compile. The problem is that the nice name
1021 winds up going into the symbol table, and conversion operations look
1022 for the manged name. */
1023 substitute_nice_name (function);
1024 #endif
1027 DECL_ARGUMENTS (function) = last_function_parms;
1028 /* First approximations. */
1029 DECL_CONTEXT (function) = ctype;
1030 DECL_CLASS_CONTEXT (function) = ctype;
1033 /* Work on the expr used by alignof (this is only called by the parser). */
1035 tree
1036 grok_alignof (expr)
1037 tree expr;
1039 tree best, t;
1040 int bestalign;
1042 if (TREE_CODE (expr) == COMPONENT_REF
1043 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
1044 error ("`__alignof__' applied to a bit-field");
1046 if (TREE_CODE (expr) == INDIRECT_REF)
1048 best = t = TREE_OPERAND (expr, 0);
1049 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1051 while (TREE_CODE (t) == NOP_EXPR
1052 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1054 int thisalign;
1055 t = TREE_OPERAND (t, 0);
1056 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1057 if (thisalign > bestalign)
1058 best = t, bestalign = thisalign;
1060 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1062 else
1064 /* ANSI says arrays and fns are converted inside comma.
1065 But we can't convert them in build_compound_expr
1066 because that would break commas in lvalues.
1067 So do the conversion here if operand was a comma. */
1068 if (TREE_CODE (expr) == COMPOUND_EXPR
1069 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1070 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1071 expr = default_conversion (expr);
1072 return c_alignof (TREE_TYPE (expr));
1076 /* Create an ARRAY_REF, checking for the user doing things backwards
1077 along the way. */
1079 tree
1080 grok_array_decl (array_expr, index_exp)
1081 tree array_expr, index_exp;
1083 tree type = TREE_TYPE (array_expr);
1084 tree p1, p2, i1, i2;
1086 if (type == error_mark_node || index_exp == error_mark_node)
1087 return error_mark_node;
1088 if (processing_template_decl)
1089 return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE,
1090 array_expr, index_exp);
1092 if (type == NULL_TREE)
1094 /* Something has gone very wrong. Assume we are mistakenly reducing
1095 an expression instead of a declaration. */
1096 error ("parser may be lost: is there a '{' missing somewhere?");
1097 return NULL_TREE;
1100 if (TREE_CODE (type) == OFFSET_TYPE
1101 || TREE_CODE (type) == REFERENCE_TYPE)
1102 type = TREE_TYPE (type);
1104 /* If they have an `operator[]', use that. */
1105 if (TYPE_LANG_SPECIFIC (type)
1106 && TYPE_OVERLOADS_ARRAY_REF (complete_type (type)))
1107 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1108 array_expr, index_exp, NULL_TREE);
1110 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1112 if (TREE_CODE (type) == ARRAY_TYPE)
1113 p1 = array_expr;
1114 else
1115 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1117 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1118 p2 = index_exp;
1119 else
1120 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1122 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1123 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1125 if ((p1 && i2) && (i1 && p2))
1126 error ("ambiguous conversion for array subscript");
1128 if (p1 && i2)
1129 array_expr = p1, index_exp = i2;
1130 else if (i1 && p2)
1131 array_expr = p2, index_exp = i1;
1132 else
1134 cp_error ("invalid types `%T[%T]' for array subscript",
1135 type, TREE_TYPE (index_exp));
1136 return error_mark_node;
1139 if (array_expr == error_mark_node || index_exp == error_mark_node)
1140 error ("ambiguous conversion for array subscript");
1142 return build_array_ref (array_expr, index_exp);
1145 /* Given the cast expression EXP, checking out its validity. Either return
1146 an error_mark_node if there was an unavoidable error, return a cast to
1147 void for trying to delete a pointer w/ the value 0, or return the
1148 call to delete. If DOING_VEC is 1, we handle things differently
1149 for doing an array delete. If DOING_VEC is 2, they gave us the
1150 array size as an argument to delete.
1151 Implements ARM $5.3.4. This is called from the parser. */
1153 tree
1154 delete_sanity (exp, size, doing_vec, use_global_delete)
1155 tree exp, size;
1156 int doing_vec, use_global_delete;
1158 tree t;
1159 tree type;
1160 enum tree_code code;
1161 /* For a regular vector delete (aka, no size argument) we will pass
1162 this down as a NULL_TREE into build_vec_delete. */
1163 tree maxindex = NULL_TREE;
1165 if (exp == error_mark_node)
1166 return exp;
1168 if (processing_template_decl)
1170 t = build_min (DELETE_EXPR, void_type_node, exp, size);
1171 DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
1172 DELETE_EXPR_USE_VEC (t) = doing_vec;
1173 return t;
1176 t = stabilize_reference (convert_from_reference (exp));
1177 type = TREE_TYPE (t);
1178 code = TREE_CODE (type);
1180 switch (doing_vec)
1182 case 2:
1183 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1184 pedwarn ("anachronistic use of array size in vector delete");
1185 /* Fall through. */
1186 case 1:
1187 break;
1188 default:
1189 if (code != POINTER_TYPE)
1191 cp_error ("type `%#T' argument given to `delete', expected pointer",
1192 type);
1193 return error_mark_node;
1196 /* Deleting a pointer with the value zero is valid and has no effect. */
1197 if (integer_zerop (t))
1198 return build1 (NOP_EXPR, void_type_node, t);
1201 if (code == POINTER_TYPE)
1203 #if 0
1204 /* As of Valley Forge, you can delete a pointer to constant. */
1205 /* You can't delete a pointer to constant. */
1206 if (TREE_READONLY (TREE_TYPE (type)))
1208 error ("`const *' cannot be deleted");
1209 return error_mark_node;
1211 #endif
1212 /* You also can't delete functions. */
1213 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1215 error ("cannot delete a function");
1216 return error_mark_node;
1220 #if 0
1221 /* If the type has no destructor, then we should build a regular
1222 delete, instead of a vector delete. Otherwise, we would end
1223 up passing a bogus offset into __builtin_delete, which is
1224 not expecting it. */
1225 if (doing_vec
1226 && TREE_CODE (type) == POINTER_TYPE
1227 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1229 doing_vec = 0;
1230 use_global_delete = 1;
1232 #endif
1234 if (doing_vec)
1235 return build_vec_delete (t, maxindex, integer_one_node,
1236 integer_two_node, use_global_delete);
1237 else
1239 if (IS_AGGR_TYPE (TREE_TYPE (type))
1240 && TYPE_GETS_REG_DELETE (TREE_TYPE (type)))
1242 /* Only do access checking here; we'll be calling op delete
1243 from the destructor. */
1244 tree tmp = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, t,
1245 size_zero_node, NULL_TREE);
1246 if (tmp == error_mark_node)
1247 return error_mark_node;
1250 return build_delete (type, t, integer_three_node,
1251 LOOKUP_NORMAL, use_global_delete);
1255 /* Sanity check: report error if this function FUNCTION is not
1256 really a member of the class (CTYPE) it is supposed to belong to.
1257 CNAME is the same here as it is for grokclassfn above. */
1259 tree
1260 check_classfn (ctype, function)
1261 tree ctype, function;
1263 tree fn_name = DECL_NAME (function);
1264 tree fndecl;
1265 tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype));
1266 tree *methods = 0;
1267 tree *end = 0;
1269 if (method_vec != 0)
1271 methods = &TREE_VEC_ELT (method_vec, 0);
1272 end = TREE_VEC_END (method_vec);
1274 /* First suss out ctors and dtors. */
1275 if (*methods && fn_name == DECL_NAME (*methods)
1276 && DECL_CONSTRUCTOR_P (function))
1277 goto got_it;
1278 if (*++methods && fn_name == DECL_NAME (*methods)
1279 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)))
1280 goto got_it;
1282 while (++methods != end)
1284 if (fn_name == DECL_NAME (*methods))
1286 got_it:
1287 fndecl = *methods;
1288 while (fndecl)
1290 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1291 return fndecl;
1292 #if 0
1293 /* This doesn't work for static member functions that are
1294 pretending to be methods. */
1295 /* We have to do more extensive argument checking here, as
1296 the name may have been changed by asm("new_name"). */
1297 if (decls_match (function, fndecl))
1298 return fndecl;
1299 #else
1300 if (DECL_NAME (function) == DECL_NAME (fndecl))
1302 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1303 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1305 /* Get rid of the this parameter on functions that become
1306 static. */
1307 if (DECL_STATIC_FUNCTION_P (fndecl)
1308 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1309 p1 = TREE_CHAIN (p1);
1311 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1312 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1313 && compparms (p1, p2, 3))
1314 return fndecl;
1316 #endif
1317 fndecl = DECL_CHAIN (fndecl);
1319 break; /* loser */
1324 if (methods != end)
1326 tree fndecl = *methods;
1327 cp_error ("prototype for `%#D' does not match any in class `%T'",
1328 function, ctype);
1329 cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl) ? "s are" : " is",
1330 fndecl);
1331 while (fndecl = DECL_CHAIN (fndecl), fndecl)
1332 cp_error_at (" %#D", fndecl);
1334 else
1336 methods = 0;
1337 cp_error ("no `%#D' member function declared in class `%T'",
1338 function, ctype);
1341 /* If we did not find the method in the class, add it to avoid
1342 spurious errors. */
1343 add_method (ctype, methods, function);
1344 return NULL_TREE;
1347 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1348 of a structure component, returning a FIELD_DECL node.
1349 QUALS is a list of type qualifiers for this decl (such as for declaring
1350 const member functions).
1352 This is done during the parsing of the struct declaration.
1353 The FIELD_DECL nodes are chained together and the lot of them
1354 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1356 C++:
1358 If class A defines that certain functions in class B are friends, then
1359 the way I have set things up, it is B who is interested in permission
1360 granted by A. However, it is in A's context that these declarations
1361 are parsed. By returning a void_type_node, class A does not attempt
1362 to incorporate the declarations of the friends within its structure.
1364 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1365 CHANGES TO CODE IN `start_method'. */
1367 tree
1368 grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
1369 tree declarator, declspecs, init, asmspec_tree, attrlist;
1371 register tree value;
1372 char *asmspec = 0;
1373 int flags = LOOKUP_ONLYCONVERTING;
1375 /* Convert () initializers to = initializers. */
1376 if (init == NULL_TREE && declarator != NULL_TREE
1377 && TREE_CODE (declarator) == CALL_EXPR
1378 && TREE_OPERAND (declarator, 0)
1379 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1380 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1381 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1383 init = TREE_OPERAND (declarator, 1);
1384 declarator = TREE_OPERAND (declarator, 0);
1385 flags = 0;
1388 if (declspecs == NULL_TREE
1389 && TREE_CODE (declarator) == SCOPE_REF
1390 && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE)
1392 /* Access declaration */
1393 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0))))
1395 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
1396 pop_nested_class (1);
1397 return do_class_using_decl (declarator);
1400 if (init
1401 && TREE_CODE (init) == TREE_LIST
1402 && TREE_VALUE (init) == error_mark_node
1403 && TREE_CHAIN (init) == NULL_TREE)
1404 init = NULL_TREE;
1406 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, NULL_TREE);
1407 if (! value)
1408 return value; /* friend or constructor went bad. */
1410 /* Pass friendly classes back. */
1411 if (TREE_CODE (value) == VOID_TYPE)
1412 return void_type_node;
1414 if (DECL_NAME (value) != NULL_TREE
1415 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1416 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1417 cp_error ("member `%D' conflicts with virtual function table field name", value);
1419 /* Stash away type declarations. */
1420 if (TREE_CODE (value) == TYPE_DECL)
1422 DECL_NONLOCAL (value) = 1;
1423 DECL_CONTEXT (value) = current_class_type;
1424 DECL_CLASS_CONTEXT (value) = current_class_type;
1425 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1427 pushdecl_class_level (value);
1428 return value;
1431 if (IS_SIGNATURE (current_class_type)
1432 && TREE_CODE (value) != FUNCTION_DECL)
1434 error ("field declaration not allowed in signature");
1435 return void_type_node;
1438 if (DECL_IN_AGGR_P (value))
1440 cp_error ("`%D' is already defined in the class %T", value,
1441 DECL_CONTEXT (value));
1442 return void_type_node;
1445 if (asmspec_tree)
1446 asmspec = TREE_STRING_POINTER (asmspec_tree);
1448 if (init)
1450 if (IS_SIGNATURE (current_class_type)
1451 && TREE_CODE (value) == FUNCTION_DECL)
1453 error ("function declarations cannot have initializers in signature");
1454 init = NULL_TREE;
1456 else if (TREE_CODE (value) == FUNCTION_DECL)
1458 grok_function_init (value, init);
1459 init = NULL_TREE;
1461 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1462 /* Already complained in grokdeclarator. */
1463 init = NULL_TREE;
1464 else
1466 /* We allow initializers to become parameters to base
1467 initializers. */
1468 if (TREE_CODE (init) == TREE_LIST)
1470 if (TREE_CHAIN (init) == NULL_TREE)
1471 init = TREE_VALUE (init);
1472 else
1473 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1476 if (TREE_CODE (init) == CONST_DECL)
1477 init = DECL_INITIAL (init);
1478 else if (TREE_READONLY_DECL_P (init))
1479 init = decl_constant_value (init);
1480 else if (TREE_CODE (init) == CONSTRUCTOR)
1481 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1482 my_friendly_assert (TREE_PERMANENT (init), 192);
1483 if (init == error_mark_node)
1484 /* We must make this look different than `error_mark_node'
1485 because `decl_const_value' would mis-interpret it
1486 as only meaning that this VAR_DECL is defined. */
1487 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1488 else if (processing_template_decl)
1490 else if (! TREE_CONSTANT (init))
1492 /* We can allow references to things that are effectively
1493 static, since references are initialized with the address. */
1494 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1495 || (TREE_STATIC (init) == 0
1496 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1497 || DECL_EXTERNAL (init) == 0)))
1499 error ("field initializer is not constant");
1500 init = error_mark_node;
1506 /* The corresponding pop_obstacks is in cp_finish_decl. */
1507 push_obstacks_nochange ();
1509 if (processing_template_decl && ! current_function_decl
1510 && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
1511 push_template_decl (value);
1513 if (attrlist)
1514 cplus_decl_attributes (value, TREE_PURPOSE (attrlist),
1515 TREE_VALUE (attrlist));
1517 if (TREE_CODE (value) == VAR_DECL)
1519 /* We cannot call pushdecl here, because that would
1520 fill in the value of our TREE_CHAIN. Instead, we
1521 modify cp_finish_decl to do the right thing, namely, to
1522 put this decl out straight away. */
1523 if (TREE_PUBLIC (value))
1525 /* current_class_type can be NULL_TREE in case of error. */
1526 if (asmspec == 0 && current_class_type)
1528 TREE_PUBLIC (value) = 1;
1529 DECL_INITIAL (value) = error_mark_node;
1530 DECL_ASSEMBLER_NAME (value)
1531 = build_static_name (current_class_type, DECL_NAME (value));
1533 if (! processing_template_decl)
1534 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1536 /* Static consts need not be initialized in the class definition. */
1537 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1539 static int explanation = 0;
1541 error ("initializer invalid for static member with constructor");
1542 if (explanation++ == 0)
1543 error ("(you really want to initialize it separately)");
1544 init = 0;
1546 /* Force the compiler to know when an uninitialized static
1547 const member is being used. */
1548 if (TYPE_READONLY (value) && init == 0)
1549 TREE_USED (value) = 1;
1551 DECL_INITIAL (value) = init;
1552 DECL_IN_AGGR_P (value) = 1;
1553 DECL_CONTEXT (value) = current_class_type;
1554 DECL_CLASS_CONTEXT (value) = current_class_type;
1556 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1557 pushdecl_class_level (value);
1558 return value;
1560 if (TREE_CODE (value) == FIELD_DECL)
1562 if (asmspec)
1564 /* This must override the asm specifier which was placed
1565 by grokclassfn. Lay this out fresh. */
1566 DECL_RTL (value) = NULL_RTX;
1567 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1569 if (DECL_INITIAL (value) == error_mark_node)
1570 init = error_mark_node;
1571 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1572 DECL_INITIAL (value) = init;
1573 DECL_IN_AGGR_P (value) = 1;
1574 return value;
1576 if (TREE_CODE (value) == FUNCTION_DECL)
1578 check_default_args (value);
1579 if (DECL_CHAIN (value) != NULL_TREE)
1581 /* Need a fresh node here so that we don't get circularity
1582 when we link these together. */
1583 value = copy_node (value);
1584 /* When does this happen? */
1585 my_friendly_assert (init == NULL_TREE, 193);
1587 if (asmspec)
1589 /* This must override the asm specifier which was placed
1590 by grokclassfn. Lay this out fresh. */
1591 DECL_RTL (value) = NULL_RTX;
1592 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1594 cp_finish_decl (value, init, asmspec_tree, 1, flags);
1596 /* Pass friends back this way. */
1597 if (DECL_FRIEND_P (value))
1598 return void_type_node;
1600 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1601 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1602 cp_error ("method `%#D' of local class must be defined in class body",
1603 value);
1604 #endif
1606 DECL_IN_AGGR_P (value) = 1;
1607 return value;
1609 my_friendly_abort (21);
1610 /* NOTREACHED */
1611 return NULL_TREE;
1614 /* Like `grokfield', but for bitfields.
1615 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1617 tree
1618 grokbitfield (declarator, declspecs, width)
1619 tree declarator, declspecs, width;
1621 register tree value = grokdeclarator (declarator, declspecs, BITFIELD,
1622 0, NULL_TREE);
1624 if (! value) return NULL_TREE; /* friends went bad. */
1626 /* Pass friendly classes back. */
1627 if (TREE_CODE (value) == VOID_TYPE)
1628 return void_type_node;
1630 if (TREE_CODE (value) == TYPE_DECL)
1632 cp_error ("cannot declare `%D' to be a bitfield type", value);
1633 return NULL_TREE;
1636 if (IS_SIGNATURE (current_class_type))
1638 error ("field declaration not allowed in signature");
1639 return void_type_node;
1642 if (DECL_IN_AGGR_P (value))
1644 cp_error ("`%D' is already defined in the class %T", value,
1645 DECL_CONTEXT (value));
1646 return void_type_node;
1649 GNU_xref_member (current_class_name, value);
1651 if (TREE_STATIC (value))
1653 cp_error ("static member `%D' cannot be a bitfield", value);
1654 return NULL_TREE;
1656 cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1658 if (width != error_mark_node)
1660 constant_expression_warning (width);
1661 DECL_INITIAL (value) = width;
1662 DECL_BIT_FIELD (value) = 1;
1665 DECL_IN_AGGR_P (value) = 1;
1666 return value;
1669 tree
1670 grokoptypename (declspecs, declarator)
1671 tree declspecs, declarator;
1673 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1674 return build_typename_overload (t);
1677 /* When a function is declared with an initializer,
1678 do the right thing. Currently, there are two possibilities:
1680 class B
1682 public:
1683 // initialization possibility #1.
1684 virtual void f () = 0;
1685 int g ();
1688 class D1 : B
1690 public:
1691 int d1;
1692 // error, no f ();
1695 class D2 : B
1697 public:
1698 int d2;
1699 void f ();
1702 class D3 : B
1704 public:
1705 int d3;
1706 // initialization possibility #2
1707 void f () = B::f;
1713 copy_assignment_arg_p (parmtype, virtualp)
1714 tree parmtype;
1715 int virtualp;
1717 if (current_class_type == NULL_TREE)
1718 return 0;
1720 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1721 parmtype = TREE_TYPE (parmtype);
1723 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1724 #if 0
1725 /* Non-standard hack to support old Booch components. */
1726 || (! virtualp && DERIVED_FROM_P (parmtype, current_class_type))
1727 #endif
1729 return 1;
1731 return 0;
1734 static void
1735 grok_function_init (decl, init)
1736 tree decl;
1737 tree init;
1739 /* An initializer for a function tells how this function should
1740 be inherited. */
1741 tree type = TREE_TYPE (decl);
1743 if (TREE_CODE (type) == FUNCTION_TYPE)
1744 cp_error ("initializer specified for non-member function `%D'", decl);
1745 #if 0
1746 /* We'll check for this in finish_struct_1. */
1747 else if (DECL_VINDEX (decl) == NULL_TREE)
1748 cp_error ("initializer specified for non-virtual method `%D'", decl);
1749 #endif
1750 else if (integer_zerop (init))
1752 #if 0
1753 /* Mark this function as being "defined". */
1754 DECL_INITIAL (decl) = error_mark_node;
1755 /* pure virtual destructors must be defined. */
1756 /* pure virtual needs to be defined (as abort) only when put in
1757 vtbl. For wellformed call, it should be itself. pr4737 */
1758 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1760 extern tree abort_fndecl;
1761 /* Give this node rtl from `abort'. */
1762 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1764 #endif
1765 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1766 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1768 tree parmtype
1769 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1771 if (copy_assignment_arg_p (parmtype, 1))
1772 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1775 else if (TREE_CODE (init) == OFFSET_REF
1776 && TREE_OPERAND (init, 0) == NULL_TREE
1777 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1779 tree basetype = DECL_CLASS_CONTEXT (init);
1780 tree basefn = TREE_OPERAND (init, 1);
1781 if (TREE_CODE (basefn) != FUNCTION_DECL)
1782 cp_error ("non-method initializer invalid for method `%D'", decl);
1783 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1784 sorry ("base member function from other than first base class");
1785 else
1787 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1788 if (binfo == error_mark_node)
1790 else if (binfo == 0)
1791 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1792 TYPE_METHOD_BASETYPE (type));
1793 else
1795 /* Mark this function as being defined,
1796 and give it new rtl. */
1797 DECL_INITIAL (decl) = error_mark_node;
1798 DECL_RTL (decl) = DECL_RTL (basefn);
1802 else
1803 cp_error ("invalid initializer for virtual method `%D'", decl);
1806 void
1807 cplus_decl_attributes (decl, attributes, prefix_attributes)
1808 tree decl, attributes, prefix_attributes;
1810 if (decl == NULL_TREE || decl == void_type_node)
1811 return;
1813 if (TREE_CODE (decl) == TEMPLATE_DECL)
1814 decl = DECL_TEMPLATE_RESULT (decl);
1816 decl_attributes (decl, attributes, prefix_attributes);
1818 if (TREE_CODE (decl) == TYPE_DECL)
1819 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl));
1822 /* CONSTRUCTOR_NAME:
1823 Return the name for the constructor (or destructor) for the
1824 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1825 IDENTIFIER_NODE. When given a template, this routine doesn't
1826 lose the specialization. */
1828 tree
1829 constructor_name_full (thing)
1830 tree thing;
1832 if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM)
1833 thing = TYPE_NAME (thing);
1834 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1836 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1837 thing = DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0));
1838 else
1839 thing = TYPE_NAME (thing);
1841 if (TREE_CODE (thing) == TYPE_DECL
1842 || (TREE_CODE (thing) == TEMPLATE_DECL
1843 && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL))
1844 thing = DECL_NAME (thing);
1845 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1846 return thing;
1849 /* CONSTRUCTOR_NAME:
1850 Return the name for the constructor (or destructor) for the
1851 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1852 IDENTIFIER_NODE. When given a template, return the plain
1853 unspecialized name. */
1855 tree
1856 constructor_name (thing)
1857 tree thing;
1859 tree t;
1860 thing = constructor_name_full (thing);
1861 t = IDENTIFIER_TEMPLATE (thing);
1862 if (!t)
1863 return thing;
1864 return t;
1867 /* Cache the value of this class's main virtual function table pointer
1868 in a register variable. This will save one indirection if a
1869 more than one virtual function call is made this function. */
1871 void
1872 setup_vtbl_ptr ()
1874 extern tree base_init_expr;
1876 if (base_init_expr == 0
1877 && DECL_CONSTRUCTOR_P (current_function_decl))
1879 if (processing_template_decl)
1880 add_tree (build_min_nt
1881 (CTOR_INITIALIZER,
1882 current_member_init_list, current_base_init_list));
1883 else
1884 emit_base_init (current_class_type, 0);
1888 /* Record the existence of an addressable inline function. */
1890 void
1891 mark_inline_for_output (decl)
1892 tree decl;
1894 decl = DECL_MAIN_VARIANT (decl);
1895 if (DECL_SAVED_INLINE (decl))
1896 return;
1897 my_friendly_assert (TREE_PERMANENT (decl), 363);
1898 DECL_SAVED_INLINE (decl) = 1;
1899 #if 0
1900 if (DECL_PENDING_INLINE_INFO (decl) != 0
1901 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
1903 struct pending_inline *t = pending_inlines;
1904 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
1905 while (t)
1907 if (t == DECL_PENDING_INLINE_INFO (decl))
1908 break;
1909 t = t->next;
1911 if (t == 0)
1913 t = DECL_PENDING_INLINE_INFO (decl);
1914 t->next = pending_inlines;
1915 pending_inlines = t;
1917 DECL_PENDING_INLINE_INFO (decl) = 0;
1919 #endif
1920 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
1923 void
1924 clear_temp_name ()
1926 temp_name_counter = 0;
1929 /* Hand off a unique name which can be used for variable we don't really
1930 want to know about anyway, for example, the anonymous variables which
1931 are needed to make references work. Declare this thing so we can use it.
1932 The variable created will be of type TYPE.
1934 STATICP is nonzero if this variable should be static. */
1936 tree
1937 get_temp_name (type, staticp)
1938 tree type;
1939 int staticp;
1941 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
1942 tree decl;
1943 int toplev = toplevel_bindings_p ();
1945 push_obstacks_nochange ();
1946 if (toplev || staticp)
1948 end_temporary_allocation ();
1949 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
1950 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
1952 else
1954 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
1955 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1957 TREE_USED (decl) = 1;
1958 TREE_STATIC (decl) = staticp;
1959 DECL_ARTIFICIAL (decl) = 1;
1961 /* If this is a local variable, then lay out its rtl now.
1962 Otherwise, callers of this function are responsible for dealing
1963 with this variable's rtl. */
1964 if (! toplev)
1966 expand_decl (decl);
1967 expand_decl_init (decl);
1969 pop_obstacks ();
1971 return decl;
1974 /* Get a variable which we can use for multiple assignments.
1975 It is not entered into current_binding_level, because
1976 that breaks things when it comes time to do final cleanups
1977 (which take place "outside" the binding contour of the function). */
1979 tree
1980 get_temp_regvar (type, init)
1981 tree type, init;
1983 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
1984 tree decl;
1986 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
1987 decl = build_decl (VAR_DECL, get_identifier (buf), type);
1988 TREE_USED (decl) = 1;
1989 DECL_REGISTER (decl) = 1;
1991 if (init)
1992 store_init_value (decl, init);
1994 /* We can expand these without fear, since they cannot need
1995 constructors or destructors. */
1996 expand_decl (decl);
1997 expand_decl_init (decl);
1999 return decl;
2002 /* Finish off the processing of a UNION_TYPE structure.
2003 If there are static members, then all members are
2004 static, and must be laid out together. If the
2005 union is an anonymous union, we arrange for that
2006 as well. PUBLIC_P is nonzero if this union is
2007 not declared static. */
2009 void
2010 finish_anon_union (anon_union_decl)
2011 tree anon_union_decl;
2013 tree type = TREE_TYPE (anon_union_decl);
2014 tree field, main_decl = NULL_TREE;
2015 tree elems = NULL_TREE;
2016 int public_p = TREE_PUBLIC (anon_union_decl);
2017 int static_p = TREE_STATIC (anon_union_decl);
2018 int external_p = DECL_EXTERNAL (anon_union_decl);
2020 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
2021 return;
2023 if (public_p)
2025 error ("global anonymous unions must be declared static");
2026 return;
2029 for (; field; field = TREE_CHAIN (field))
2031 tree decl;
2032 if (TREE_CODE (field) != FIELD_DECL)
2033 continue;
2035 if (TREE_PRIVATE (field))
2036 cp_pedwarn_at ("private member `%#D' in anonymous union", field);
2037 else if (TREE_PROTECTED (field))
2038 cp_pedwarn_at ("protected member `%#D' in anonymous union", field);
2040 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2041 /* tell `pushdecl' that this is not tentative. */
2042 DECL_INITIAL (decl) = error_mark_node;
2043 TREE_PUBLIC (decl) = public_p;
2044 TREE_STATIC (decl) = static_p;
2045 DECL_EXTERNAL (decl) = external_p;
2046 decl = pushdecl (decl);
2048 /* Only write out one anon union element--choose the one that
2049 can hold them all. */
2050 if (main_decl == NULL_TREE
2051 && 1 == simple_cst_equal (DECL_SIZE (decl),
2052 DECL_SIZE (anon_union_decl)))
2054 main_decl = decl;
2056 else
2058 /* ??? This causes there to be no debug info written out
2059 about this decl. */
2060 TREE_ASM_WRITTEN (decl) = 1;
2063 DECL_INITIAL (decl) = NULL_TREE;
2064 /* If there's a cleanup to do, it belongs in the
2065 TREE_PURPOSE of the following TREE_LIST. */
2066 elems = tree_cons (NULL_TREE, decl, elems);
2067 TREE_TYPE (elems) = type;
2069 if (static_p)
2071 if (main_decl)
2073 make_decl_rtl (main_decl, 0, toplevel_bindings_p ());
2074 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2076 else
2078 warning ("anonymous union with no members");
2079 return;
2083 /* The following call assumes that there are never any cleanups
2084 for anonymous unions--a reasonable assumption. */
2085 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2088 /* Finish and output a table which is generated by the compiler.
2089 NAME is the name to give the table.
2090 TYPE is the type of the table entry.
2091 INIT is all the elements in the table.
2092 PUBLICP is non-zero if this table should be given external access. */
2094 tree
2095 finish_table (name, type, init, publicp)
2096 tree name, type, init;
2097 int publicp;
2099 tree itype, atype, decl;
2100 static tree empty_table;
2101 int is_empty = 0;
2102 tree asmspec;
2104 itype = build_index_type (size_int (list_length (init) - 1));
2105 atype = build_cplus_array_type (type, itype);
2106 layout_type (atype);
2108 if (TREE_VALUE (init) == integer_zero_node
2109 && TREE_CHAIN (init) == NULL_TREE)
2111 #if 0
2112 if (empty_table == NULL_TREE)
2113 #endif
2115 empty_table = get_temp_name (atype, 1);
2116 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2117 TREE_CONSTANT (init) = 1;
2118 TREE_STATIC (init) = 1;
2119 DECL_INITIAL (empty_table) = init;
2120 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2121 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2122 cp_finish_decl (empty_table, NULL_TREE, asmspec, 0, 0);
2124 is_empty = 1;
2127 if (name == NULL_TREE)
2129 if (is_empty)
2130 return empty_table;
2131 decl = get_temp_name (atype, 1);
2133 else
2135 decl = build_decl (VAR_DECL, name, atype);
2136 decl = pushdecl (decl);
2137 TREE_STATIC (decl) = 1;
2140 if (is_empty == 0)
2142 TREE_PUBLIC (decl) = publicp;
2143 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2144 TREE_CONSTANT (init) = 1;
2145 TREE_STATIC (init) = 1;
2146 DECL_INITIAL (decl) = init;
2147 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2148 IDENTIFIER_POINTER (DECL_NAME (decl)));
2150 else
2152 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2153 DECL_EXTERNAL (decl) = 1;
2154 TREE_STATIC (decl) = 0;
2155 init = 0;
2156 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2157 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2160 cp_finish_decl (decl, NULL_TREE, asmspec, 0, 0);
2161 return decl;
2164 /* Finish processing a builtin type TYPE. It's name is NAME,
2165 its fields are in the array FIELDS. LEN is the number of elements
2166 in FIELDS minus one, or put another way, it is the maximum subscript
2167 used in FIELDS.
2169 It is given the same alignment as ALIGN_TYPE. */
2171 void
2172 finish_builtin_type (type, name, fields, len, align_type)
2173 tree type;
2174 char *name;
2175 tree fields[];
2176 int len;
2177 tree align_type;
2179 register int i;
2181 TYPE_FIELDS (type) = fields[0];
2182 for (i = 0; i < len; i++)
2184 layout_type (TREE_TYPE (fields[i]));
2185 DECL_FIELD_CONTEXT (fields[i]) = type;
2186 TREE_CHAIN (fields[i]) = fields[i+1];
2188 DECL_FIELD_CONTEXT (fields[i]) = type;
2189 DECL_CLASS_CONTEXT (fields[i]) = type;
2190 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2191 layout_type (type);
2192 #if 0 /* not yet, should get fixed properly later */
2193 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2194 #else
2195 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2196 #endif
2197 TYPE_STUB_DECL (type) = TYPE_NAME (type);
2198 layout_decl (TYPE_NAME (type), 0);
2201 /* Auxiliary functions to make type signatures for
2202 `operator new' and `operator delete' correspond to
2203 what compiler will be expecting. */
2205 extern tree sizetype;
2207 tree
2208 coerce_new_type (type)
2209 tree type;
2211 int e1 = 0, e2 = 0;
2213 if (TREE_CODE (type) == METHOD_TYPE)
2214 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2215 if (TREE_TYPE (type) != ptr_type_node)
2216 e1 = 1, error ("`operator new' must return type `void *'");
2218 /* Technically the type must be `size_t', but we may not know
2219 what that is. */
2220 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2221 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2222 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2223 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2224 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2225 if (e2)
2226 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2227 else if (e1)
2228 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2229 return type;
2232 tree
2233 coerce_delete_type (type)
2234 tree type;
2236 int e1 = 0, e2 = 0, e3 = 0;
2237 tree arg_types = TYPE_ARG_TYPES (type);
2239 if (TREE_CODE (type) == METHOD_TYPE)
2241 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2242 arg_types = TREE_CHAIN (arg_types);
2245 if (TREE_TYPE (type) != void_type_node)
2246 e1 = 1, error ("`operator delete' must return type `void'");
2248 if (arg_types == NULL_TREE
2249 || TREE_VALUE (arg_types) != ptr_type_node)
2250 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2252 if (arg_types
2253 && TREE_CHAIN (arg_types)
2254 && TREE_CHAIN (arg_types) != void_list_node)
2256 /* Again, technically this argument must be `size_t', but again
2257 we may not know what that is. */
2258 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2259 if (TREE_CODE (t2) != INTEGER_TYPE
2260 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2261 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2262 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2264 e3 = 1;
2265 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2266 error ("too many arguments in declaration of `operator delete'");
2267 else
2268 error ("`...' invalid in specification of `operator delete'");
2272 if (e3)
2273 arg_types = tree_cons (NULL_TREE, ptr_type_node,
2274 build_tree_list (NULL_TREE, sizetype));
2275 else if (e3 |= e2)
2277 if (arg_types == NULL_TREE)
2278 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2279 else
2280 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2282 else e3 |= e1;
2284 if (e3)
2285 type = build_function_type (void_type_node, arg_types);
2287 return type;
2290 extern tree abort_fndecl;
2292 static void
2293 mark_vtable_entries (decl)
2294 tree decl;
2296 tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
2298 if (flag_rtti)
2300 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries))
2301 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2302 tree fn = TREE_OPERAND (fnaddr, 0);
2303 TREE_ADDRESSABLE (fn) = 1;
2304 mark_used (fn);
2306 skip_rtti_stuff (&entries);
2308 for (; entries; entries = TREE_CHAIN (entries))
2310 tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries)
2311 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2312 tree fn = TREE_OPERAND (fnaddr, 0);
2313 TREE_ADDRESSABLE (fn) = 1;
2314 if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn))
2315 TREE_OPERAND (fnaddr, 0) = fn = abort_fndecl;
2316 if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn))
2318 DECL_EXTERNAL (fn) = 0;
2319 emit_thunk (fn);
2321 mark_used (fn);
2325 /* Set DECL up to have the closest approximation of "initialized common"
2326 linkage available. */
2328 void
2329 comdat_linkage (decl)
2330 tree decl;
2332 if (flag_weak)
2333 make_decl_one_only (decl);
2334 else
2335 TREE_PUBLIC (decl) = 0;
2338 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2339 based on TYPE and other static flags.
2341 Note that anything public is tagged TREE_PUBLIC, whether
2342 it's public in this file or in another one. */
2344 void
2345 import_export_vtable (decl, type, final)
2346 tree decl, type;
2347 int final;
2349 if (DECL_INTERFACE_KNOWN (decl))
2350 return;
2352 /* +e0 or +e1 */
2353 if (write_virtuals < 2 && write_virtuals != 0)
2355 TREE_PUBLIC (decl) = 1;
2356 if (write_virtuals < 0)
2357 DECL_EXTERNAL (decl) = 1;
2358 DECL_INTERFACE_KNOWN (decl) = 1;
2360 else if (CLASSTYPE_INTERFACE_KNOWN (type))
2362 TREE_PUBLIC (decl) = 1;
2363 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2364 DECL_INTERFACE_KNOWN (decl) = 1;
2366 else
2368 /* We can only wait to decide if we have real non-inline virtual
2369 functions in our class, or if we come from a template. */
2371 int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2373 if (! found && ! final)
2375 tree method;
2376 for (method = TYPE_METHODS (type); method != NULL_TREE;
2377 method = TREE_CHAIN (method))
2378 if (DECL_VINDEX (method) != NULL_TREE
2379 && ! DECL_THIS_INLINE (method)
2380 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2382 found = 1;
2383 break;
2387 if (final || ! found)
2389 comdat_linkage (decl);
2390 DECL_EXTERNAL (decl) = 0;
2392 else
2394 TREE_PUBLIC (decl) = 1;
2395 DECL_EXTERNAL (decl) = 1;
2400 static void
2401 import_export_template (type)
2402 tree type;
2404 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2405 && ! flag_implicit_templates
2406 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2408 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2409 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2410 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2415 finish_prevtable_vardecl (prev, vars)
2416 tree prev, vars;
2418 tree ctype = DECL_CONTEXT (vars);
2419 import_export_template (ctype);
2421 #ifndef MULTIPLE_SYMBOL_SPACES
2422 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype)
2423 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2425 tree method;
2426 for (method = TYPE_METHODS (ctype); method != NULL_TREE;
2427 method = TREE_CHAIN (method))
2429 if (DECL_VINDEX (method) != NULL_TREE
2430 && !DECL_THIS_INLINE (method)
2431 && !DECL_ABSTRACT_VIRTUAL_P (method))
2433 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2434 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method);
2435 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2436 break;
2440 #endif
2442 import_export_vtable (vars, ctype, 1);
2443 return 1;
2446 static int
2447 finish_vtable_vardecl (prev, vars)
2448 tree prev, vars;
2450 if (write_virtuals >= 0
2451 && ! DECL_EXTERNAL (vars)
2452 && ((TREE_PUBLIC (vars) && ! DECL_WEAK (vars) && ! DECL_ONE_ONLY (vars))
2453 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))
2454 || (hack_decl_function_context (vars) && TREE_USED (vars)))
2455 && ! TREE_ASM_WRITTEN (vars))
2457 /* Write it out. */
2458 mark_vtable_entries (vars);
2459 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2460 store_init_value (vars, DECL_INITIAL (vars));
2462 if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG)
2464 /* Mark the VAR_DECL node representing the vtable itself as a
2465 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2466 It is rather important that such things be ignored because
2467 any effort to actually generate DWARF for them will run
2468 into trouble when/if we encounter code like:
2470 #pragma interface
2471 struct S { virtual void member (); };
2473 because the artificial declaration of the vtable itself (as
2474 manufactured by the g++ front end) will say that the vtable
2475 is a static member of `S' but only *after* the debug output
2476 for the definition of `S' has already been output. This causes
2477 grief because the DWARF entry for the definition of the vtable
2478 will try to refer back to an earlier *declaration* of the
2479 vtable as a static member of `S' and there won't be one.
2480 We might be able to arrange to have the "vtable static member"
2481 attached to the member list for `S' before the debug info for
2482 `S' get written (which would solve the problem) but that would
2483 require more intrusive changes to the g++ front end. */
2485 DECL_IGNORED_P (vars) = 1;
2488 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2489 return 1;
2491 else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2492 /* We don't know what to do with this one yet. */
2493 return 0;
2495 /* We know that PREV must be non-zero here. */
2496 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2497 return 0;
2500 static int
2501 prune_vtable_vardecl (prev, vars)
2502 tree prev, vars;
2504 /* We know that PREV must be non-zero here. */
2505 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2506 return 1;
2510 walk_vtables (typedecl_fn, vardecl_fn)
2511 register void (*typedecl_fn)();
2512 register int (*vardecl_fn)();
2514 tree prev, vars;
2515 int flag = 0;
2517 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2519 register tree type = TREE_TYPE (vars);
2521 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2523 if (vardecl_fn)
2524 flag |= (*vardecl_fn) (prev, vars);
2526 if (prev && TREE_CHAIN (prev) != vars)
2527 continue;
2529 else if (TREE_CODE (vars) == TYPE_DECL
2530 && type != error_mark_node
2531 && TYPE_LANG_SPECIFIC (type)
2532 && CLASSTYPE_VSIZE (type))
2534 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2537 prev = vars;
2540 return flag;
2543 static void
2544 finish_sigtable_vardecl (prev, vars)
2545 tree prev, vars;
2547 /* We don't need to mark sigtable entries as addressable here as is done
2548 for vtables. Since sigtables, unlike vtables, are always written out,
2549 that was already done in build_signature_table_constructor. */
2551 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2553 /* We know that PREV must be non-zero here. */
2554 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2557 void
2558 walk_sigtables (typedecl_fn, vardecl_fn)
2559 register void (*typedecl_fn)();
2560 register void (*vardecl_fn)();
2562 tree prev, vars;
2564 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2566 register tree type = TREE_TYPE (vars);
2568 if (TREE_CODE (vars) == TYPE_DECL
2569 && type != error_mark_node
2570 && IS_SIGNATURE (type))
2572 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2574 else if (TREE_CODE (vars) == VAR_DECL
2575 && TREE_TYPE (vars) != error_mark_node
2576 && IS_SIGNATURE (TREE_TYPE (vars)))
2578 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2580 else
2581 prev = vars;
2585 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2586 inline function or template instantiation at end-of-file. */
2588 void
2589 import_export_decl (decl)
2590 tree decl;
2592 if (DECL_INTERFACE_KNOWN (decl))
2593 return;
2595 if (DECL_TEMPLATE_INSTANTIATION (decl))
2597 DECL_NOT_REALLY_EXTERN (decl) = 1;
2598 if (DECL_IMPLICIT_INSTANTIATION (decl)
2599 && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2601 if (TREE_CODE (decl) == FUNCTION_DECL)
2602 comdat_linkage (decl);
2603 /* Dynamically initialized vars go into common. */
2604 else if (DECL_INITIAL (decl) == NULL_TREE
2605 || DECL_INITIAL (decl) == error_mark_node)
2606 DECL_COMMON (decl) = 1;
2607 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
2609 DECL_COMMON (decl) = 1;
2610 DECL_INITIAL (decl) = error_mark_node;
2612 else
2614 /* Statically initialized vars are weak or comdat, if
2615 supported. */
2616 if (flag_weak)
2617 make_decl_one_only (decl);
2618 else
2619 /* we can't do anything useful; leave vars for explicit
2620 instantiation. */
2621 DECL_NOT_REALLY_EXTERN (decl) = 0;
2624 else
2625 DECL_NOT_REALLY_EXTERN (decl) = 0;
2627 else if (DECL_FUNCTION_MEMBER_P (decl))
2629 tree ctype = DECL_CLASS_CONTEXT (decl);
2630 if (CLASSTYPE_INTERFACE_KNOWN (ctype) && ! DECL_ARTIFICIAL (decl))
2632 DECL_NOT_REALLY_EXTERN (decl)
2633 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2634 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2636 else
2637 comdat_linkage (decl);
2639 /* tinfo function */
2640 else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2642 tree ctype = TREE_TYPE (DECL_NAME (decl));
2643 if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2644 && TYPE_VIRTUAL_P (ctype))
2646 DECL_NOT_REALLY_EXTERN (decl)
2647 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2648 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2650 else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2651 DECL_NOT_REALLY_EXTERN (decl) = 0;
2652 else
2653 comdat_linkage (decl);
2655 else if (DECL_C_STATIC (decl))
2656 TREE_PUBLIC (decl) = 0;
2657 else
2658 comdat_linkage (decl);
2660 DECL_INTERFACE_KNOWN (decl) = 1;
2663 tree
2664 build_cleanup (decl)
2665 tree decl;
2667 tree temp;
2668 tree type = TREE_TYPE (decl);
2670 if (TREE_CODE (type) == ARRAY_TYPE)
2671 temp = decl;
2672 else
2674 mark_addressable (decl);
2675 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2677 temp = build_delete (TREE_TYPE (temp), temp,
2678 integer_two_node,
2679 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2680 return temp;
2683 extern int parse_time, varconst_time;
2684 extern tree pending_templates;
2685 extern tree maybe_templates;
2687 extern struct obstack permanent_obstack;
2688 extern tree get_id_2 ();
2690 static tree
2691 get_sentry (base)
2692 tree base;
2694 tree sname = get_id_2 ("__sn", base);
2695 tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2696 if (! sentry)
2698 push_obstacks (&permanent_obstack, &permanent_obstack);
2699 sentry = build_decl (VAR_DECL, sname, integer_type_node);
2700 TREE_PUBLIC (sentry) = 1;
2701 DECL_ARTIFICIAL (sentry) = 1;
2702 TREE_STATIC (sentry) = 1;
2703 TREE_USED (sentry) = 1;
2704 DECL_COMMON (sentry) = 1;
2705 pushdecl_top_level (sentry);
2706 cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2707 pop_obstacks ();
2709 return sentry;
2712 /* This routine is called from the last rule in yyparse ().
2713 Its job is to create all the code needed to initialize and
2714 destroy the global aggregates. We do the destruction
2715 first, since that way we only need to reverse the decls once. */
2717 void
2718 finish_file ()
2720 extern int lineno;
2721 int start_time, this_time;
2723 tree fnname;
2724 tree vars;
2725 int needs_cleaning = 0, needs_messing_up = 0;
2727 at_eof = 1;
2729 if (flag_detailed_statistics)
2730 dump_tree_statistics ();
2732 /* Bad parse errors. Just forget about it. */
2733 if (! global_bindings_p () || current_class_type)
2734 return;
2736 start_time = get_run_time ();
2738 /* Otherwise, GDB can get confused, because in only knows
2739 about source for LINENO-1 lines. */
2740 lineno -= 1;
2742 interface_unknown = 1;
2743 interface_only = 0;
2745 for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
2747 tree decl = TREE_VALUE (fnname);
2748 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
2750 instantiate_class_template (decl);
2751 if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
2752 for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
2753 if (! DECL_ARTIFICIAL (vars))
2754 instantiate_decl (vars);
2756 else
2757 instantiate_decl (decl);
2760 for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
2762 tree *args, fn, decl = TREE_VALUE (fnname);
2764 if (DECL_INITIAL (decl))
2765 continue;
2767 fn = TREE_PURPOSE (fnname);
2768 args = get_bindings (fn, decl);
2769 fn = instantiate_template (fn, args);
2770 free (args);
2771 instantiate_decl (fn);
2774 /* Push into C language context, because that's all
2775 we'll need here. */
2776 push_lang_context (lang_name_c);
2778 #if 1
2779 /* The reason for pushing garbage onto the global_binding_level is to
2780 ensure that we can slice out _DECLs which pertain to virtual function
2781 tables. If the last thing pushed onto the global_binding_level was a
2782 virtual function table, then slicing it out would slice away all the
2783 decls (i.e., we lose the head of the chain).
2785 There are several ways of getting the same effect, from changing the
2786 way that iterators over the chain treat the elements that pertain to
2787 virtual function tables, moving the implementation of this code to
2788 decl.c (where we can manipulate global_binding_level directly),
2789 popping the garbage after pushing it and slicing away the vtable
2790 stuff, or just leaving it alone. */
2792 /* Make last thing in global scope not be a virtual function table. */
2793 #if 0 /* not yet, should get fixed properly later */
2794 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2795 #else
2796 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2797 #endif
2798 DECL_IGNORED_P (vars) = 1;
2799 SET_DECL_ARTIFICIAL (vars);
2800 pushdecl (vars);
2801 #endif
2803 /* Walk to mark the inline functions we need, then output them so
2804 that we can pick up any other tdecls that those routines need. */
2805 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2807 for (vars = pending_statics; vars; vars = TREE_CHAIN (vars))
2809 tree decl = TREE_VALUE (vars);
2811 if (DECL_TEMPLATE_INSTANTIATION (decl)
2812 && ! DECL_IN_AGGR_P (decl))
2814 import_export_decl (decl);
2815 DECL_EXTERNAL (decl) = ! DECL_NOT_REALLY_EXTERN (decl);
2819 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2820 if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
2821 rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
2822 vars = static_aggregates;
2824 if (static_ctors || vars || exception_table_p ())
2825 needs_messing_up = 1;
2826 if (static_dtors)
2827 needs_cleaning = 1;
2829 /* See if we really need the hassle. */
2830 while (vars && needs_cleaning == 0)
2832 tree decl = TREE_VALUE (vars);
2833 tree type = TREE_TYPE (decl);
2834 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars))
2836 needs_cleaning = 1;
2837 break;
2840 vars = TREE_CHAIN (vars);
2843 if (needs_cleaning == 0)
2844 goto mess_up;
2846 fnname = get_file_function_name ('D');
2847 start_function (void_list_node,
2848 make_call_declarator (fnname, void_list_node, NULL_TREE,
2849 NULL_TREE),
2850 NULL_TREE, 0);
2851 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2852 store_parm_decls ();
2854 pushlevel (0);
2855 clear_last_expr ();
2856 push_momentary ();
2857 expand_start_bindings (0);
2859 /* These must be done in backward order to destroy,
2860 in which they happen to be! */
2861 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2863 tree decl = TREE_VALUE (vars);
2864 tree type = TREE_TYPE (decl);
2865 tree temp = TREE_PURPOSE (vars);
2867 if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
2868 && ! DECL_EXTERNAL (decl))
2870 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2871 || DECL_ONE_ONLY (decl)
2872 || DECL_WEAK (decl)));
2874 temp = build_cleanup (decl);
2876 if (protect)
2878 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2879 sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
2880 sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
2881 expand_start_cond (sentry, 0);
2884 expand_expr_stmt (temp);
2886 if (protect)
2887 expand_end_cond ();
2891 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2892 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2893 NULL_TREE));
2895 expand_end_bindings (getdecls (), 1, 0);
2896 poplevel (1, 0, 0);
2897 pop_momentary ();
2899 finish_function (lineno, 0, 0);
2901 assemble_destructor (IDENTIFIER_POINTER (fnname));
2903 /* if it needed cleaning, then it will need messing up: drop through */
2905 mess_up:
2906 /* Must do this while we think we are at the top level. */
2907 vars = nreverse (static_aggregates);
2908 if (needs_messing_up)
2910 fnname = get_file_function_name ('I');
2911 start_function (void_list_node,
2912 make_call_declarator (fnname, void_list_node, NULL_TREE,
2913 NULL_TREE),
2914 NULL_TREE, 0);
2915 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2916 store_parm_decls ();
2918 pushlevel (0);
2919 clear_last_expr ();
2920 push_momentary ();
2921 expand_start_bindings (0);
2923 if (exception_table_p ())
2924 register_exception_table ();
2926 while (vars)
2928 tree decl = TREE_VALUE (vars);
2929 tree init = TREE_PURPOSE (vars);
2931 /* If this was a static attribute within some function's scope,
2932 then don't initialize it here. Also, don't bother
2933 with initializers that contain errors. */
2934 if (TREE_STATIC (vars)
2935 || DECL_EXTERNAL (decl)
2936 || (init && TREE_CODE (init) == TREE_LIST
2937 && value_member (error_mark_node, init)))
2938 goto next_mess;
2940 if (TREE_CODE (decl) == VAR_DECL)
2942 int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2943 || DECL_ONE_ONLY (decl)
2944 || DECL_WEAK (decl)));
2946 /* Set these global variables so that GDB at least puts
2947 us near the declaration which required the initialization. */
2948 input_filename = DECL_SOURCE_FILE (decl);
2949 lineno = DECL_SOURCE_LINE (decl);
2950 emit_note (input_filename, lineno);
2952 /* 9.5p5: The initializer of a static member of a class has
2953 the same access rights as a member function. */
2954 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2955 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
2957 if (protect)
2959 tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2960 sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
2961 sentry = build_binary_op
2962 (EQ_EXPR, sentry, integer_one_node, 1);
2963 expand_start_cond (sentry, 0);
2966 expand_start_target_temps ();
2968 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2969 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2970 expand_aggr_init (decl, init, 0, 0);
2971 else if (TREE_CODE (init) == TREE_VEC)
2973 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2974 TREE_VEC_ELT (init, 1),
2975 TREE_VEC_ELT (init, 2), 0),
2976 const0_rtx, VOIDmode, 0);
2978 else
2979 expand_assignment (decl, init, 0, 0);
2981 /* Cleanup any temporaries needed for the initial value. */
2982 expand_end_target_temps ();
2984 if (protect)
2985 expand_end_cond ();
2987 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2988 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
2990 else if (decl == error_mark_node)
2992 else my_friendly_abort (22);
2994 next_mess:
2995 vars = TREE_CHAIN (vars);
2998 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
2999 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
3000 NULL_TREE));
3002 expand_end_bindings (getdecls (), 1, 0);
3003 poplevel (1, 0, 0);
3004 pop_momentary ();
3006 finish_function (lineno, 0, 0);
3007 assemble_constructor (IDENTIFIER_POINTER (fnname));
3010 expand_builtin_throw ();
3012 permanent_allocation (1);
3014 /* Done with C language context needs. */
3015 pop_lang_context ();
3017 /* Now write out any static class variables (which may have since
3018 learned how to be initialized). */
3019 while (pending_statics)
3021 tree decl = TREE_VALUE (pending_statics);
3023 /* Output DWARF debug information. */
3024 #ifdef DWARF_DEBUGGING_INFO
3025 if (write_symbols == DWARF_DEBUG)
3026 dwarfout_file_scope_decl (decl, 1);
3027 #endif
3028 #ifdef DWARF2_DEBUGGING_INFO
3029 if (write_symbols == DWARF2_DEBUG)
3030 dwarf2out_decl (decl);
3031 #endif
3033 DECL_DEFER_OUTPUT (decl) = 0;
3034 rest_of_decl_compilation
3035 (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3037 pending_statics = TREE_CHAIN (pending_statics);
3040 this_time = get_run_time ();
3041 parse_time -= this_time - start_time;
3042 varconst_time += this_time - start_time;
3044 start_time = get_run_time ();
3046 if (flag_handle_signatures)
3047 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3049 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3051 tree decl = TREE_VALUE (fnname);
3052 import_export_decl (decl);
3055 /* Now write out inline functions which had their addresses taken and
3056 which were not declared virtual and which were not declared `extern
3057 inline'. */
3059 int reconsider = 1; /* More may be referenced; check again */
3061 while (reconsider)
3063 tree *p = &saved_inlines;
3064 reconsider = 0;
3066 /* We need to do this each time so that newly completed template
3067 types don't wind up at the front of the list. Sigh. */
3068 vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3069 DECL_IGNORED_P (vars) = 1;
3070 SET_DECL_ARTIFICIAL (vars);
3071 pushdecl (vars);
3073 reconsider |= walk_vtables ((void (*)())0, finish_vtable_vardecl);
3075 while (*p)
3077 tree decl = TREE_VALUE (*p);
3079 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3080 && TREE_USED (decl)
3081 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3083 if (DECL_MUTABLE_P (decl))
3084 synthesize_tinfo_fn (decl);
3085 else
3086 synthesize_method (decl);
3087 reconsider = 1;
3090 /* Catch new template instantiations. */
3091 if (decl != TREE_VALUE (*p))
3092 continue;
3094 if (TREE_ASM_WRITTEN (decl)
3095 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3096 *p = TREE_CHAIN (*p);
3097 else if (DECL_INITIAL (decl) == 0)
3098 p = &TREE_CHAIN (*p);
3099 else if ((TREE_PUBLIC (decl) && ! DECL_WEAK (decl)
3100 && ! DECL_ONE_ONLY (decl))
3101 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3102 || flag_keep_inline_functions)
3104 if (DECL_NOT_REALLY_EXTERN (decl))
3106 DECL_EXTERNAL (decl) = 0;
3107 reconsider = 1;
3108 /* We can't inline this function after it's been
3109 emitted, so just disable inlining. We want a
3110 variant of output_inline_function that doesn't
3111 prevent subsequent integration... */
3112 flag_no_inline = 1;
3113 temporary_allocation ();
3114 output_inline_function (decl);
3115 permanent_allocation (1);
3118 *p = TREE_CHAIN (*p);
3120 else
3121 p = &TREE_CHAIN (*p);
3126 /* Now delete from the chain of variables all virtual function tables.
3127 We output them all ourselves, because each will be treated specially. */
3129 walk_vtables ((void (*)())0, prune_vtable_vardecl);
3131 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3133 if (TREE_CODE (vars) == FUNCTION_DECL
3134 && ! DECL_INTERFACE_KNOWN (vars)
3135 && DECL_C_STATIC (vars))
3136 TREE_PUBLIC (vars) = 0;
3139 if (write_virtuals == 2)
3141 /* Now complain about an virtual function tables promised
3142 but not delivered. */
3143 while (pending_vtables)
3145 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3146 error ("virtual function table for `%s' not defined",
3147 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3148 pending_vtables = TREE_CHAIN (pending_vtables);
3152 finish_repo ();
3154 this_time = get_run_time ();
3155 parse_time -= this_time - start_time;
3156 varconst_time += this_time - start_time;
3158 if (flag_detailed_statistics)
3159 dump_time_statistics ();
3162 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3163 expr. Since it was parsed like a type, we need to wade through and fix
3164 that. Unfortunately, since operator() is left-associative, we can't use
3165 tail recursion. In the above example, TYPE is `A', and DECL is
3166 `()()()()()'.
3168 Maybe this shouldn't be recursive, but how often will it actually be
3169 used? (jason) */
3171 tree
3172 reparse_absdcl_as_expr (type, decl)
3173 tree type, decl;
3175 /* do build_functional_cast (type, NULL_TREE) at bottom */
3176 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3177 return build_functional_cast (type, NULL_TREE);
3179 /* recurse */
3180 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3182 decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3184 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3185 decl = require_complete_type (decl);
3187 return decl;
3190 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3191 out to be an expr. Since it was parsed like a type, we need to wade
3192 through and fix that. Since casts are right-associative, we are
3193 reversing the order, so we don't have to recurse.
3195 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3196 `1'. */
3198 tree
3199 reparse_absdcl_as_casts (decl, expr)
3200 tree decl, expr;
3202 tree type;
3204 if (TREE_CODE (expr) == CONSTRUCTOR
3205 && TREE_TYPE (expr) == 0)
3207 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3208 decl = TREE_OPERAND (decl, 0);
3210 if (IS_SIGNATURE (type))
3212 error ("cast specifies signature type");
3213 return error_mark_node;
3216 expr = digest_init (type, expr, (tree *) 0);
3217 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3219 int failure = complete_array_type (type, expr, 1);
3220 if (failure)
3221 my_friendly_abort (78);
3225 while (decl)
3227 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3228 decl = TREE_OPERAND (decl, 0);
3229 expr = build_c_cast (type, expr);
3232 return expr;
3235 /* Given plain tree nodes for an expression, build up the full semantics. */
3237 tree
3238 build_expr_from_tree (t)
3239 tree t;
3241 if (t == NULL_TREE || t == error_mark_node)
3242 return t;
3244 switch (TREE_CODE (t))
3246 case IDENTIFIER_NODE:
3247 return do_identifier (t, 0);
3249 case LOOKUP_EXPR:
3250 if (LOOKUP_EXPR_GLOBAL (t))
3251 return do_scoped_id (TREE_OPERAND (t, 0), 0);
3252 else
3253 return do_identifier (TREE_OPERAND (t, 0), 0);
3255 case INDIRECT_REF:
3256 return build_x_indirect_ref
3257 (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3259 case CAST_EXPR:
3260 return build_functional_cast
3261 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3263 case REINTERPRET_CAST_EXPR:
3264 return build_reinterpret_cast
3265 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3267 case CONST_CAST_EXPR:
3268 return build_const_cast
3269 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3271 case DYNAMIC_CAST_EXPR:
3272 return build_dynamic_cast
3273 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3275 case STATIC_CAST_EXPR:
3276 return build_static_cast
3277 (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3279 case PREDECREMENT_EXPR:
3280 case PREINCREMENT_EXPR:
3281 case POSTDECREMENT_EXPR:
3282 case POSTINCREMENT_EXPR:
3283 case NEGATE_EXPR:
3284 case BIT_NOT_EXPR:
3285 case ABS_EXPR:
3286 case TRUTH_NOT_EXPR:
3287 case ADDR_EXPR:
3288 case CONVERT_EXPR: /* Unary + */
3289 if (TREE_TYPE (t))
3290 return t;
3291 return build_x_unary_op (TREE_CODE (t),
3292 build_expr_from_tree (TREE_OPERAND (t, 0)));
3294 case PLUS_EXPR:
3295 case MINUS_EXPR:
3296 case MULT_EXPR:
3297 case TRUNC_DIV_EXPR:
3298 case CEIL_DIV_EXPR:
3299 case FLOOR_DIV_EXPR:
3300 case ROUND_DIV_EXPR:
3301 case EXACT_DIV_EXPR:
3302 case BIT_AND_EXPR:
3303 case BIT_ANDTC_EXPR:
3304 case BIT_IOR_EXPR:
3305 case BIT_XOR_EXPR:
3306 case TRUNC_MOD_EXPR:
3307 case FLOOR_MOD_EXPR:
3308 case TRUTH_ANDIF_EXPR:
3309 case TRUTH_ORIF_EXPR:
3310 case TRUTH_AND_EXPR:
3311 case TRUTH_OR_EXPR:
3312 case RSHIFT_EXPR:
3313 case LSHIFT_EXPR:
3314 case RROTATE_EXPR:
3315 case LROTATE_EXPR:
3316 case EQ_EXPR:
3317 case NE_EXPR:
3318 case MAX_EXPR:
3319 case MIN_EXPR:
3320 case LE_EXPR:
3321 case GE_EXPR:
3322 case LT_EXPR:
3323 case GT_EXPR:
3324 case MEMBER_REF:
3325 return build_x_binary_op
3326 (TREE_CODE (t),
3327 build_expr_from_tree (TREE_OPERAND (t, 0)),
3328 build_expr_from_tree (TREE_OPERAND (t, 1)));
3330 case DOTSTAR_EXPR:
3331 return build_m_component_ref
3332 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3333 build_expr_from_tree (TREE_OPERAND (t, 1)));
3335 case SCOPE_REF:
3336 return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3338 case ARRAY_REF:
3339 if (TREE_OPERAND (t, 0) == NULL_TREE)
3340 /* new-type-id */
3341 return build_parse_node (ARRAY_REF, NULL_TREE,
3342 build_expr_from_tree (TREE_OPERAND (t, 1)));
3343 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3344 build_expr_from_tree (TREE_OPERAND (t, 1)));
3346 case SIZEOF_EXPR:
3348 tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3349 if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3350 r = TREE_TYPE (r);
3351 return c_sizeof (r);
3354 case MODOP_EXPR:
3355 return build_x_modify_expr
3356 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3357 TREE_CODE (TREE_OPERAND (t, 1)),
3358 build_expr_from_tree (TREE_OPERAND (t, 2)));
3360 case ARROW_EXPR:
3361 return build_x_arrow
3362 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3364 case NEW_EXPR:
3365 return build_new
3366 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3367 build_expr_from_tree (TREE_OPERAND (t, 1)),
3368 build_expr_from_tree (TREE_OPERAND (t, 2)),
3369 NEW_EXPR_USE_GLOBAL (t));
3371 case DELETE_EXPR:
3372 return delete_sanity
3373 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3374 build_expr_from_tree (TREE_OPERAND (t, 1)),
3375 DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3377 case COMPOUND_EXPR:
3378 if (TREE_OPERAND (t, 1) == NULL_TREE)
3379 return build_x_compound_expr
3380 (build_expr_from_tree (TREE_OPERAND (t, 0)));
3381 else
3382 my_friendly_abort (42);
3384 case METHOD_CALL_EXPR:
3385 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3387 tree ref = TREE_OPERAND (t, 0);
3388 return build_scoped_method_call
3389 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3390 build_expr_from_tree (TREE_OPERAND (ref, 0)),
3391 TREE_OPERAND (ref, 1),
3392 build_expr_from_tree (TREE_OPERAND (t, 2)));
3394 return build_method_call
3395 (build_expr_from_tree (TREE_OPERAND (t, 1)),
3396 TREE_OPERAND (t, 0),
3397 build_expr_from_tree (TREE_OPERAND (t, 2)),
3398 NULL_TREE, LOOKUP_NORMAL);
3400 case CALL_EXPR:
3401 if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3403 tree ref = TREE_OPERAND (t, 0);
3404 return build_member_call
3405 (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3406 TREE_OPERAND (ref, 1),
3407 build_expr_from_tree (TREE_OPERAND (t, 1)));
3409 else
3411 tree name = TREE_OPERAND (t, 0);
3412 if (! really_overloaded_fn (name))
3413 name = build_expr_from_tree (name);
3414 return build_x_function_call
3415 (name, build_expr_from_tree (TREE_OPERAND (t, 1)),
3416 current_class_ref);
3419 case COND_EXPR:
3420 return build_x_conditional_expr
3421 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3422 build_expr_from_tree (TREE_OPERAND (t, 1)),
3423 build_expr_from_tree (TREE_OPERAND (t, 2)));
3425 case TREE_LIST:
3427 tree purpose, value, chain;
3429 if (t == void_list_node)
3430 return t;
3432 purpose = TREE_PURPOSE (t);
3433 if (purpose)
3434 purpose = build_expr_from_tree (purpose);
3435 value = TREE_VALUE (t);
3436 if (value)
3437 value = build_expr_from_tree (value);
3438 chain = TREE_CHAIN (t);
3439 if (chain && chain != void_type_node)
3440 chain = build_expr_from_tree (chain);
3441 return tree_cons (purpose, value, chain);
3444 case COMPONENT_REF:
3445 return build_x_component_ref
3446 (build_expr_from_tree (TREE_OPERAND (t, 0)),
3447 TREE_OPERAND (t, 1), NULL_TREE, 1);
3449 case THROW_EXPR:
3450 return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3452 case CONSTRUCTOR:
3454 tree r = build_nt (CONSTRUCTOR, NULL_TREE,
3455 build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3457 if (TREE_TYPE (t))
3458 return digest_init (TREE_TYPE (t), r, 0);
3459 return r;
3462 case TYPEID_EXPR:
3463 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
3464 return get_typeid (TREE_OPERAND (t, 0));
3465 return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3467 case VAR_DECL:
3468 return convert_from_reference (t);
3470 default:
3471 return t;
3475 /* This is something of the form `int (*a)++' that has turned out to be an
3476 expr. It was only converted into parse nodes, so we need to go through
3477 and build up the semantics. Most of the work is done by
3478 build_expr_from_tree, above.
3480 In the above example, TYPE is `int' and DECL is `*a'. */
3482 tree
3483 reparse_decl_as_expr (type, decl)
3484 tree type, decl;
3486 decl = build_expr_from_tree (decl);
3487 if (type)
3488 return build_functional_cast (type, build_tree_list (NULL_TREE, decl));
3489 else
3490 return decl;
3493 /* This is something of the form `int (*a)' that has turned out to be a
3494 decl. It was only converted into parse nodes, so we need to do the
3495 checking that make_{pointer,reference}_declarator do. */
3497 tree
3498 finish_decl_parsing (decl)
3499 tree decl;
3501 extern int current_class_depth;
3503 switch (TREE_CODE (decl))
3505 case IDENTIFIER_NODE:
3506 return decl;
3507 case INDIRECT_REF:
3508 return make_pointer_declarator
3509 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3510 case ADDR_EXPR:
3511 return make_reference_declarator
3512 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3513 case BIT_NOT_EXPR:
3514 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3515 return decl;
3516 case SCOPE_REF:
3517 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3518 TREE_COMPLEXITY (decl) = current_class_depth;
3519 return decl;
3520 case ARRAY_REF:
3521 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3522 return decl;
3523 default:
3524 my_friendly_abort (5);
3525 return NULL_TREE;
3529 tree
3530 check_cp_case_value (value)
3531 tree value;
3533 if (value == NULL_TREE)
3534 return value;
3536 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3537 STRIP_TYPE_NOPS (value);
3539 if (TREE_READONLY_DECL_P (value))
3541 value = decl_constant_value (value);
3542 STRIP_TYPE_NOPS (value);
3544 value = fold (value);
3546 if (TREE_CODE (value) != INTEGER_CST
3547 && value != error_mark_node)
3549 cp_error ("case label `%E' does not reduce to an integer constant",
3550 value);
3551 value = error_mark_node;
3553 else
3554 /* Promote char or short to int. */
3555 value = default_conversion (value);
3557 constant_expression_warning (value);
3559 return value;
3562 tree current_namespace;
3564 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3565 postfix. Returns 0 if in global namespace. */
3567 tree
3568 get_namespace_id ()
3570 tree x = current_namespace;
3571 if (x)
3572 x = TREE_PURPOSE (x);
3573 return x;
3576 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3578 tree
3579 current_namespace_id (name)
3580 tree name;
3582 tree old_id = get_namespace_id ();
3583 char *buf;
3585 /* Global names retain old encoding. */
3586 if (! old_id)
3587 return name;
3589 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3590 + IDENTIFIER_LENGTH (name));
3591 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3592 IDENTIFIER_POINTER (name));
3593 return get_identifier (buf);
3596 void
3597 do_namespace_alias (alias, namespace)
3598 tree alias, namespace;
3600 sorry ("namespace alias");
3603 void
3604 do_toplevel_using_decl (decl)
3605 tree decl;
3607 #if 1
3608 if (TREE_CODE (decl) == SCOPE_REF
3609 && TREE_OPERAND (decl, 0) == std_node)
3610 return;
3611 sorry ("using-declaration");
3612 #else
3613 if (decl == NULL_TREE || decl == error_mark_node)
3614 return;
3616 if (TREE_CODE (decl) == SCOPE_REF)
3617 decl = resolve_scope_to_name (NULL_TREE, decl);
3619 /* Is this the right way to do an id list? */
3620 if (TREE_CODE (decl) != TREE_LIST)
3622 pushdecl (decl);
3624 else
3625 while (decl)
3627 pushdecl (TREE_VALUE (decl));
3628 decl = TREE_CHAIN (decl);
3630 #endif
3633 tree
3634 do_class_using_decl (decl)
3635 tree decl;
3637 tree name, value;
3639 if (TREE_CODE (decl) != SCOPE_REF)
3641 cp_error ("using-declaration for non-member at class scope");
3642 return NULL_TREE;
3644 name = TREE_OPERAND (decl, 1);
3645 if (TREE_CODE (name) == BIT_NOT_EXPR)
3647 cp_error ("using-declaration for destructor");
3648 return NULL_TREE;
3651 value = build_lang_field_decl (USING_DECL, name, void_type_node);
3652 DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
3653 return value;
3656 void
3657 do_using_directive (namespace)
3658 tree namespace;
3660 if (namespace == std_node)
3661 return;
3662 sorry ("using directive");
3665 void
3666 check_default_args (x)
3667 tree x;
3669 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
3670 int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
3671 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
3673 if (TREE_PURPOSE (arg))
3674 saw_def = 1;
3675 else if (saw_def)
3677 cp_error ("default argument missing for parameter %P of `%#D'",
3678 i, x);
3679 break;
3684 void
3685 mark_used (decl)
3686 tree decl;
3688 TREE_USED (decl) = 1;
3689 if (processing_template_decl)
3690 return;
3691 assemble_external (decl);
3692 /* Is it a synthesized method that needs to be synthesized? */
3693 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
3694 && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3695 /* Kludge: don't synthesize for default args. */
3696 && current_function_decl)
3697 synthesize_method (decl);
3698 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
3699 instantiate_decl (decl);