]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/decl2.c
(distribute_notes...
[gcc.git] / gcc / cp / decl2.c
CommitLineData
8d08fdba
MS
1/* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21
22/* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
25
26/* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
28
29#include "config.h"
30#include <stdio.h>
31#include "tree.h"
32#include "rtl.h"
33#include "flags.h"
34#include "cp-tree.h"
35#include "decl.h"
36#include "lex.h"
37
38extern tree grokdeclarator ();
39extern tree get_file_function_name ();
a4443a08 40extern tree cleanups_this_call;
8d08fdba
MS
41static void grok_function_init ();
42
43/* A list of virtual function tables we must make sure to write out. */
44tree pending_vtables;
45
46/* A list of static class variables. This is needed, because a
47 static class variable can be declared inside the class without
48 an initializer, and then initialized, staticly, outside the class. */
49tree pending_statics;
50
8926095f
MS
51/* A list of functions which were declared inline, but which we
52 may need to emit outline anyway. */
53static tree saved_inlines;
8d08fdba
MS
54
55/* Used to help generate temporary names which are unique within
56 a function. Reset to 0 by start_function. */
57
58static int temp_name_counter;
59
60/* Same, but not reset. Local temp variables and global temp variables
61 can have the same name. */
62static int global_temp_name_counter;
63
51c184be 64/* Flag used when debugging spew.c */
8d08fdba
MS
65
66extern int spew_debug;
67\f
68/* C (and C++) language-specific option variables. */
69
70/* Nonzero means allow type mismatches in conditional expressions;
71 just make their values `void'. */
72
73int flag_cond_mismatch;
74
75/* Nonzero means give `double' the same size as `float'. */
76
77int flag_short_double;
78
79/* Nonzero means don't recognize the keyword `asm'. */
80
81int flag_no_asm;
82
83/* Nonzero means don't recognize the non-ANSI builtin functions. */
84
85int flag_no_builtin;
86
87/* Nonzero means do some things the same way PCC does. */
88
89int flag_traditional;
90
91/* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
92
93int flag_signed_bitfields = 1;
94
95/* Nonzero means handle `#ident' directives. 0 means ignore them. */
96
97int flag_no_ident = 0;
98
2986ae00 99/* Nonzero means disable GNU extensions. */
8d08fdba
MS
100
101int flag_ansi = 0;
102
8d08fdba
MS
103/* Nonzero means do emit exported implementations of functions even if
104 they can be inlined. */
105
106int flag_implement_inlines = 1;
107
108/* Nonzero means do emit exported implementations of templates, instead of
109 multiple static copies in each file that needs a definition. */
110
111int flag_external_templates = 0;
112
113/* Nonzero means that the decision to emit or not emit the implementation of a
114 template depends on where the template is instantiated, rather than where
115 it is defined. */
116
117int flag_alt_external_templates = 0;
118
a0a33927
MS
119/* Nonzero means that implicit instantiations will be emitted if needed. */
120
121int flag_implicit_templates = 1;
122
8d08fdba
MS
123/* Nonzero means warn about implicit declarations. */
124
125int warn_implicit = 1;
126
127/* Nonzero means warn when all ctors or dtors are private, and the class
128 has no friends. */
129
130int warn_ctor_dtor_privacy = 1;
131
8926095f
MS
132/* True if we want to implement vtbvales using "thunks".
133 The default is off now, but will be on later.
134
135 Also causes output of vtables to be controlled by whether
51c184be 136 we seen the class's first non-inline virtual function. */
8926095f 137int flag_vtable_thunks = 0;
51c184be 138
8d08fdba
MS
139/* Nonzero means give string constants the type `const char *'
140 to get extra warnings from them. These warnings will be too numerous
141 to be useful, except in thoroughly ANSIfied programs. */
142
143int warn_write_strings;
144
145/* Nonzero means warn about pointer casts that can drop a type qualifier
146 from the pointer target type. */
147
148int warn_cast_qual;
149
150/* Nonzero means warn that dbx info for template class methods isn't fully
151 supported yet. */
152
153int warn_template_debugging;
154
155/* Warn about traditional constructs whose meanings changed in ANSI C. */
156
157int warn_traditional;
158
159/* Nonzero means warn about sizeof(function) or addition/subtraction
160 of function pointers. */
161
162int warn_pointer_arith;
163
164/* Nonzero means warn for non-prototype function decls
165 or non-prototyped defs without previous prototype. */
166
167int warn_strict_prototypes;
168
169/* Nonzero means warn for any function def without prototype decl. */
170
171int warn_missing_prototypes;
172
173/* Nonzero means warn about multiple (redundant) decls for the same single
174 variable or function. */
175
176int warn_redundant_decls;
177
178/* Warn if initializer is not completely bracketed. */
179
180int warn_missing_braces;
181
182/* Warn about *printf or *scanf format/argument anomalies. */
183
184int warn_format;
185
186/* Warn about a subscript that has type char. */
187
188int warn_char_subscripts;
189
190/* Warn if a type conversion is done that might have confusing results. */
191
192int warn_conversion;
193
194/* Warn if adding () is suggested. */
195
196int warn_parentheses = 1;
197
198/* Non-zero means warn in function declared in derived class has the
199 same name as a virtual in the base class, but fails to match the
200 type signature of any virtual function in the base class. */
201int warn_overloaded_virtual;
202
203/* Non-zero means warn when declaring a class that has a non virtual
204 destructor, when it really ought to have a virtual one. */
9a0e77ba 205int warn_nonvdtor;
8d08fdba
MS
206
207/* Non-zero means warn when a function is declared extern and later inline. */
208int warn_extern_inline;
209
210/* Nonzero means `$' can be in an identifier.
211 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
212
213#ifndef DOLLARS_IN_IDENTIFIERS
214#define DOLLARS_IN_IDENTIFIERS 1
215#endif
216int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
217
a3203465 218/* Nonzero for -fno-strict-prototype switch: do not consider empty
8d08fdba
MS
219 argument prototype to mean function takes no arguments. */
220
221int strict_prototype = 1;
222int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
223
224/* Nonzero means that labels can be used as first-class objects */
225
226int flag_labels_ok;
227
228/* Non-zero means to collect statistics which might be expensive
229 and to print them when we are done. */
230int flag_detailed_statistics;
231
232/* C++ specific flags. */
233/* Nonzero for -fall-virtual: make every member function (except
234 constructors) lay down in the virtual function table. Calls
235 can then either go through the virtual function table or not,
236 depending. */
237
238int flag_all_virtual;
239
240/* Zero means that `this' is a *const. This gives nice behavior in the
241 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
242 -2 means we're constructing an object and it has fixed type. */
243
244int flag_this_is_variable;
245
246/* Nonzero means memoize our member lookups. */
247
248int flag_memoize_lookups; int flag_save_memoized_contexts;
249
250/* 3 means write out only virtuals function tables `defined'
251 in this implementation file.
252 2 means write out only specific virtual function tables
253 and give them (C) public access.
254 1 means write out virtual function tables and give them
255 (C) public access.
256 0 means write out virtual function tables and give them
257 (C) static access (default).
258 -1 means declare virtual function tables extern. */
259
260int write_virtuals;
261
262/* Nonzero means we should attempt to elide constructors when possible. */
263
264int flag_elide_constructors;
265
266/* Nonzero means recognize and handle exception handling constructs.
8d2733ca 267 Use ansi syntax and semantics. WORK IN PROGRESS! */
8d08fdba
MS
268
269int flag_handle_exceptions;
270
8d08fdba
MS
271/* Nonzero means recognize and handle signature language constructs. */
272
273int flag_handle_signatures;
274
275/* Nonzero means that member functions defined in class scope are
276 inline by default. */
277
278int flag_default_inline = 1;
279
280/* Controls whether enums and ints freely convert.
281 1 means with complete freedom.
282 0 means enums can convert to ints, but not vice-versa. */
283int flag_int_enum_equivalence;
284
285/* Controls whether compiler is operating under LUCID's Cadillac
286 system. 1 means yes, 0 means no. */
287int flag_cadillac;
288
289/* Controls whether compiler generates code to build objects
290 that can be collected when they become garbage. */
291int flag_gc;
292
293/* Controls whether compiler generates 'dossiers' that give
294 run-time type information. */
295int flag_dossier;
296
297/* Nonzero if we wish to output cross-referencing information
298 for the GNU class browser. */
299extern int flag_gnu_xref;
300
301/* Nonzero if compiler can make `reasonable' assumptions about
302 references and objects. For example, the compiler must be
303 conservative about the following and not assume that `a' is nonnull:
304
305 obj &a = g ();
306 a.f (2);
307
308 In general, it is `reasonable' to assume that for many programs,
309 and better code can be generated in that case. */
310
311int flag_assume_nonnull_objects;
312
313/* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
314 objects. */
315int flag_huge_objects;
316
317/* Nonzero if we want to conserve space in the .o files. We do this
318 by putting uninitialized data and runtime initialized data into
319 .common instead of .data at the expense of not flaging multiple
320 definitions. */
321int flag_conserve_space;
322
323/* Table of language-dependent -f options.
324 STRING is the option name. VARIABLE is the address of the variable.
325 ON_VALUE is the value to store in VARIABLE
326 if `-fSTRING' is seen as an option.
327 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
328
329static struct { char *string; int *variable; int on_value;} lang_f_options[] =
330{
331 {"signed-char", &flag_signed_char, 1},
332 {"unsigned-char", &flag_signed_char, 0},
333 {"signed-bitfields", &flag_signed_bitfields, 1},
334 {"unsigned-bitfields", &flag_signed_bitfields, 0},
335 {"short-enums", &flag_short_enums, 1},
336 {"short-double", &flag_short_double, 1},
337 {"cond-mismatch", &flag_cond_mismatch, 1},
338 {"asm", &flag_no_asm, 0},
339 {"builtin", &flag_no_builtin, 0},
340 {"ident", &flag_no_ident, 0},
341 {"labels-ok", &flag_labels_ok, 1},
342 {"stats", &flag_detailed_statistics, 1},
343 {"this-is-variable", &flag_this_is_variable, 1},
344 {"strict-prototype", &strict_prototypes_lang_cplusplus, 1},
345 {"all-virtual", &flag_all_virtual, 1},
346 {"memoize-lookups", &flag_memoize_lookups, 1},
347 {"elide-constructors", &flag_elide_constructors, 1},
348 {"handle-exceptions", &flag_handle_exceptions, 1},
8d08fdba 349 {"handle-signatures", &flag_handle_signatures, 1},
8d08fdba
MS
350 {"default-inline", &flag_default_inline, 1},
351 {"dollars-in-identifiers", &dollars_in_ident, 1},
352 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
353 {"gc", &flag_gc, 1},
354 {"dossier", &flag_dossier, 1},
355 {"xref", &flag_gnu_xref, 1},
356 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
357 {"implement-inlines", &flag_implement_inlines, 1},
358 {"external-templates", &flag_external_templates, 1},
a0a33927 359 {"implicit-templates", &flag_implicit_templates, 1},
8d08fdba
MS
360 {"huge-objects", &flag_huge_objects, 1},
361 {"conserve-space", &flag_conserve_space, 1},
8926095f 362 {"vtable-thunks", &flag_vtable_thunks, 1},
a4443a08 363 {"short-temps", &flag_short_temps, 1},
8d08fdba
MS
364};
365
366/* Decode the string P as a language-specific option.
367 Return 1 if it is recognized (and handle it);
368 return 0 if not recognized. */
369
370int
371lang_decode_option (p)
372 char *p;
373{
374 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
375 flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
376 flag_this_is_variable = 1;
377 /* The +e options are for cfront compatibility. They come in as
378 `-+eN', to kludge around gcc.c's argument handling. */
379 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
380 {
381 int old_write_virtuals = write_virtuals;
382 if (p[3] == '1')
383 write_virtuals = 1;
384 else if (p[3] == '0')
385 write_virtuals = -1;
386 else if (p[3] == '2')
387 write_virtuals = 2;
388 else error ("invalid +e option");
389 if (old_write_virtuals != 0
390 && write_virtuals != old_write_virtuals)
391 error ("conflicting +e options given");
392 }
393 else if (p[0] == '-' && p[1] == 'f')
394 {
395 /* Some kind of -f option.
396 P's value is the option sans `-f'.
397 Search for it in the table of options. */
398 int found = 0, j;
399
400 p += 2;
401 /* Try special -f options. */
402
403 if (!strcmp (p, "save-memoized"))
404 {
405 flag_memoize_lookups = 1;
406 flag_save_memoized_contexts = 1;
407 found = 1;
408 }
409 if (!strcmp (p, "no-save-memoized"))
410 {
411 flag_memoize_lookups = 0;
412 flag_save_memoized_contexts = 0;
413 found = 1;
414 }
415 else if (! strncmp (p, "cadillac", 8))
416 {
417 flag_cadillac = atoi (p+9);
418 found = 1;
419 }
420 else if (! strncmp (p, "no-cadillac", 11))
421 {
422 flag_cadillac = 0;
423 found = 1;
424 }
425 else if (! strcmp (p, "gc"))
426 {
427 flag_gc = 1;
428 /* This must come along for the ride. */
429 flag_dossier = 1;
430 found = 1;
431 }
432 else if (! strcmp (p, "no-gc"))
433 {
434 flag_gc = 0;
435 /* This must come along for the ride. */
436 flag_dossier = 0;
437 found = 1;
438 }
439 else if (! strcmp (p, "alt-external-templates"))
440 {
441 flag_external_templates = 1;
442 flag_alt_external_templates = 1;
443 found = 1;
444 }
445 else if (! strcmp (p, "no-alt-external-templates"))
446 {
447 flag_alt_external_templates = 0;
448 found = 1;
449 }
450 else for (j = 0;
451 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
452 j++)
453 {
454 if (!strcmp (p, lang_f_options[j].string))
455 {
456 *lang_f_options[j].variable = lang_f_options[j].on_value;
457 /* A goto here would be cleaner,
458 but breaks the vax pcc. */
459 found = 1;
460 }
461 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
462 && ! strcmp (p+3, lang_f_options[j].string))
463 {
464 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
465 found = 1;
466 }
467 }
468 return found;
469 }
470 else if (p[0] == '-' && p[1] == 'W')
471 {
472 int setting = 1;
473
474 /* The -W options control the warning behavior of the compiler. */
475 p += 2;
476
477 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
478 setting = 0, p += 3;
479
480 if (!strcmp (p, "implicit"))
481 warn_implicit = setting;
482 else if (!strcmp (p, "return-type"))
483 warn_return_type = setting;
484 else if (!strcmp (p, "ctor-dtor-privacy"))
485 warn_ctor_dtor_privacy = setting;
486 else if (!strcmp (p, "write-strings"))
487 warn_write_strings = setting;
488 else if (!strcmp (p, "cast-qual"))
489 warn_cast_qual = setting;
490 else if (!strcmp (p, "traditional"))
491 warn_traditional = setting;
492 else if (!strcmp (p, "char-subscripts"))
493 warn_char_subscripts = setting;
494 else if (!strcmp (p, "pointer-arith"))
495 warn_pointer_arith = setting;
496 else if (!strcmp (p, "strict-prototypes"))
497 warn_strict_prototypes = setting;
498 else if (!strcmp (p, "missing-prototypes"))
499 warn_missing_prototypes = setting;
500 else if (!strcmp (p, "redundant-decls"))
501 warn_redundant_decls = setting;
502 else if (!strcmp (p, "missing-braces"))
503 warn_missing_braces = setting;
504 else if (!strcmp (p, "format"))
505 warn_format = setting;
506 else if (!strcmp (p, "conversion"))
507 warn_conversion = setting;
508 else if (!strcmp (p, "parentheses"))
509 warn_parentheses = setting;
21474714
MS
510 else if (!strcmp (p, "non-virtual-dtor"))
511 warn_nonvdtor = setting;
8d08fdba
MS
512 else if (!strcmp (p, "extern-inline"))
513 warn_extern_inline = setting;
514 else if (!strcmp (p, "comment"))
515 ; /* cpp handles this one. */
516 else if (!strcmp (p, "comments"))
517 ; /* cpp handles this one. */
518 else if (!strcmp (p, "trigraphs"))
519 ; /* cpp handles this one. */
520 else if (!strcmp (p, "import"))
521 ; /* cpp handles this one. */
522 else if (!strcmp (p, "all"))
523 {
524 extra_warnings = setting;
525 warn_return_type = setting;
526 warn_unused = setting;
527 warn_implicit = setting;
528 warn_ctor_dtor_privacy = setting;
529 warn_switch = setting;
530 warn_format = setting;
531 warn_missing_braces = setting;
532 warn_extern_inline = setting;
9a0e77ba 533 warn_nonvdtor = setting;
8d08fdba
MS
534 /* We save the value of warn_uninitialized, since if they put
535 -Wuninitialized on the command line, we need to generate a
536 warning about not using it without also specifying -O. */
537 if (warn_uninitialized != 1)
538 warn_uninitialized = (setting ? 2 : 0);
539 warn_template_debugging = setting;
540 }
541
542 else if (!strcmp (p, "overloaded-virtual"))
543 warn_overloaded_virtual = setting;
544 else return 0;
545 }
546 else if (!strcmp (p, "-ansi"))
547 flag_no_asm = 1, dollars_in_ident = 0, flag_ansi = 1;
548#ifdef SPEW_DEBUG
549 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
550 it's probably safe to assume no sane person would ever want to use this
551 under normal circumstances. */
552 else if (!strcmp (p, "-spew-debug"))
553 spew_debug = 1;
554#endif
555 else
556 return 0;
557
558 return 1;
559}
560\f
561/* Incorporate `const' and `volatile' qualifiers for member functions.
562 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
563 QUALS is a list of qualifiers. */
564tree
565grok_method_quals (ctype, function, quals)
566 tree ctype, function, quals;
567{
568 tree fntype = TREE_TYPE (function);
569 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
570
571 do
572 {
573 extern tree ridpointers[];
574
575 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
576 {
577 if (TYPE_READONLY (ctype))
578 error ("duplicate `%s' %s",
579 IDENTIFIER_POINTER (TREE_VALUE (quals)),
580 (TREE_CODE (function) == FUNCTION_DECL
581 ? "for member function" : "in type declaration"));
582 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
583 build_pointer_type (ctype);
584 }
585 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
586 {
587 if (TYPE_VOLATILE (ctype))
588 error ("duplicate `%s' %s",
589 IDENTIFIER_POINTER (TREE_VALUE (quals)),
590 (TREE_CODE (function) == FUNCTION_DECL
591 ? "for member function" : "in type declaration"));
592 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
593 build_pointer_type (ctype);
594 }
595 else
596 my_friendly_abort (20);
597 quals = TREE_CHAIN (quals);
598 }
599 while (quals);
600 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
601 (TREE_CODE (fntype) == METHOD_TYPE
602 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
603 : TYPE_ARG_TYPES (fntype)));
604 if (raises)
605 fntype = build_exception_variant (ctype, fntype, raises);
606
607 TREE_TYPE (function) = fntype;
608 return ctype;
609}
610
8926095f 611#if 0 /* Not used. */
8d08fdba
MS
612/* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
613 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
614/* This does not yet work with user defined conversion operators
615 It should. */
616static void
617substitute_nice_name (decl)
618 tree decl;
619{
620 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
621 {
622 char *n = decl_as_string (DECL_NAME (decl), 1);
623 if (n[strlen (n) - 1] == ' ')
624 n[strlen (n) - 1] = 0;
625 DECL_NAME (decl) = get_identifier (n);
626 }
627}
8926095f 628#endif
8d08fdba
MS
629
630/* Warn when -fexternal-templates is used and #pragma
631 interface/implementation is not used all the times it should be,
632 inform the user. */
633void
634warn_if_unknown_interface ()
635{
636 static int already_warned = 0;
637 if (++already_warned == 1)
638 warning ("templates that are built with -fexternal-templates should be in files that have #pragma interface/implementation");
639}
640
641/* A subroutine of the parser, to handle a component list. */
642tree
643grok_x_components (specs, components)
644 tree specs, components;
645{
646 register tree t, x, tcode;
647
648 /* We just got some friends. They have been recorded elsewhere. */
649 if (components == void_type_node)
650 return NULL_TREE;
651
652 if (components == NULL_TREE)
653 {
654 t = groktypename (build_decl_list (specs, NULL_TREE));
655
656 if (t == NULL_TREE)
657 {
658 error ("error in component specification");
659 return NULL_TREE;
660 }
661
662 switch (TREE_CODE (t))
663 {
664 case VAR_DECL:
665 /* Static anonymous unions come out as VAR_DECLs. */
666 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
667 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
668 return t;
669
670 /* We return SPECS here, because in the parser it was ending
671 up with not doing anything to $$, which is what SPECS
672 represents. */
673 return specs;
674 break;
675
676 case RECORD_TYPE:
677 /* This code may be needed for UNION_TYPEs as
678 well. */
679 tcode = record_type_node;
680 if (CLASSTYPE_DECLARED_CLASS(t))
681 tcode = class_type_node;
682 else if (IS_SIGNATURE(t))
683 tcode = signature_type_node;
684 else if (CLASSTYPE_DECLARED_EXCEPTION(t))
685 tcode = exception_type_node;
686
687 t = xref_defn_tag(tcode, TYPE_IDENTIFIER(t), NULL_TREE);
688 if (TYPE_CONTEXT(t))
689 CLASSTYPE_NO_GLOBALIZE(t) = 1;
690 if (TYPE_LANG_SPECIFIC (t)
691 && CLASSTYPE_DECLARED_EXCEPTION (t))
692 shadow_tag (specs);
693 return NULL_TREE;
694 break;
695
696 case UNION_TYPE:
697 case ENUMERAL_TYPE:
698 if (TREE_CODE(t) == UNION_TYPE)
699 tcode = union_type_node;
700 else
701 tcode = enum_type_node;
702
703 t = xref_defn_tag(tcode, TYPE_IDENTIFIER(t), NULL_TREE);
704 if (TREE_CODE(t) == UNION_TYPE && TYPE_CONTEXT(t))
705 CLASSTYPE_NO_GLOBALIZE(t) = 1;
706 if (TREE_CODE (t) == UNION_TYPE
707 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
708 {
709 struct pending_inline **p;
710 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
711
712 /* Wipe out memory of synthesized methods */
713 TYPE_HAS_CONSTRUCTOR (t) = 0;
714 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
715 TYPE_HAS_INIT_REF (t) = 0;
716 TYPE_HAS_CONST_INIT_REF (t) = 0;
717 TYPE_HAS_ASSIGN_REF (t) = 0;
718 TYPE_HAS_ASSIGNMENT (t) = 0;
719 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
720
721 p = &pending_inlines;
722 for (; *p; *p = (*p)->next)
723 if (DECL_CONTEXT ((*p)->fndecl) != t)
724 break;
725 }
726 else if (TREE_CODE (t) == ENUMERAL_TYPE)
727 x = grok_enum_decls (t, NULL_TREE);
728 else
729 x = NULL_TREE;
730 return x;
731 break;
732
733 default:
734 if (t != void_type_node)
735 error ("empty component declaration");
736 return NULL_TREE;
737 }
738 }
739 else
740 {
741 t = TREE_TYPE (components);
742 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
743 return grok_enum_decls (t, components);
744 else
745 return components;
746 }
747}
748
749/* Classes overload their constituent function names automatically.
750 When a function name is declared in a record structure,
751 its name is changed to it overloaded name. Since names for
752 constructors and destructors can conflict, we place a leading
753 '$' for destructors.
754
755 CNAME is the name of the class we are grokking for.
756
757 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
758
759 FLAGS contains bits saying what's special about today's
760 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
761
762 If FUNCTION is a destructor, then we must add the `auto-delete' field
763 as a second parameter. There is some hair associated with the fact
764 that we must "declare" this variable in the manner consistent with the
765 way the rest of the arguments were declared.
766
767 QUALS are the qualifiers for the this pointer. */
768
769void
770grokclassfn (ctype, cname, function, flags, quals)
771 tree ctype, cname, function;
772 enum overload_flags flags;
773 tree quals;
774{
775 tree fn_name = DECL_NAME (function);
776 tree arg_types;
777 tree parm;
700f8a87 778 tree qualtype;
8d08fdba
MS
779
780 if (fn_name == NULL_TREE)
781 {
782 error ("name missing for member function");
783 fn_name = get_identifier ("<anonymous>");
784 DECL_NAME (function) = fn_name;
785 }
786
787 if (quals)
700f8a87
MS
788 qualtype = grok_method_quals (ctype, function, quals);
789 else
790 qualtype = ctype;
8d08fdba
MS
791
792 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
793 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
794 {
795 /* Must add the class instance variable up front. */
796 /* Right now we just make this a pointer. But later
797 we may wish to make it special. */
798 tree type = TREE_VALUE (arg_types);
799
2986ae00
MS
800 if ((flag_this_is_variable > 0)
801 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
8d08fdba 802 type = TYPE_MAIN_VARIANT (type);
2986ae00
MS
803
804 if (DECL_CONSTRUCTOR_P (function))
8d08fdba
MS
805 {
806 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
807 {
808 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
809 /* In this case we need "in-charge" flag saying whether
810 this constructor is responsible for initialization
811 of virtual baseclasses or not. */
812 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
813 /* Mark the artificial `__in_chrg' parameter as "artificial". */
700f8a87 814 SET_DECL_ARTIFICIAL (parm);
8d08fdba
MS
815 DECL_ARG_TYPE (parm) = integer_type_node;
816 DECL_REGISTER (parm) = 1;
817 TREE_CHAIN (parm) = last_function_parms;
818 last_function_parms = parm;
819 }
820 }
821
822 parm = build_decl (PARM_DECL, this_identifier, type);
823 /* Mark the artificial `this' parameter as "artificial". */
700f8a87 824 SET_DECL_ARTIFICIAL (parm);
8d08fdba
MS
825 DECL_ARG_TYPE (parm) = type;
826 /* We can make this a register, so long as we don't
827 accidentally complain if someone tries to take its address. */
828 DECL_REGISTER (parm) = 1;
2986ae00 829 if (TYPE_READONLY (type))
8d08fdba
MS
830 TREE_READONLY (parm) = 1;
831 TREE_CHAIN (parm) = last_function_parms;
832 last_function_parms = parm;
833 }
834
835 if (flags == DTOR_FLAG)
836 {
837 char *buf, *dbuf;
838 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
839 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
840
841 arg_types = hash_tree_chain (const_integer_type, void_list_node);
842 TREE_SIDE_EFFECTS (arg_types) = 1;
843 /* Build the overload name. It will look like `7Example'. */
844 if (IDENTIFIER_TYPE_VALUE (cname))
845 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
846 else if (IDENTIFIER_LOCAL_VALUE (cname))
847 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
848 else
849 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
850 it's defined out of the class definition, since poplevel_class wipes
851 it out. This used to be internal error 346. */
852 dbuf = build_overload_name (ctype, 1, 1);
853 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
854 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
855 buf[len] = '\0';
856 strcat (buf, dbuf);
857 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
858 parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
859 /* Mark the artificial `__in_chrg' parameter as "artificial". */
700f8a87 860 SET_DECL_ARTIFICIAL (parm);
8d08fdba
MS
861 TREE_USED (parm) = 1;
862#if 0
863 /* We don't need to mark the __in_chrg parameter itself as `const'
864 since its type is already `const int'. In fact we MUST NOT mark
865 it as `const' cuz that will screw up the debug info (causing it
866 to say that the type of __in_chrg is `const const int'). */
867 TREE_READONLY (parm) = 1;
868#endif
869 DECL_ARG_TYPE (parm) = const_integer_type;
870 /* This is the same chain as DECL_ARGUMENTS (...). */
871 TREE_CHAIN (last_function_parms) = parm;
872
700f8a87 873 TREE_TYPE (function) = build_cplus_method_type (qualtype, void_type_node,
8d08fdba
MS
874 arg_types);
875 TYPE_HAS_DESTRUCTOR (ctype) = 1;
876 }
877 else
878 {
879 tree these_arg_types;
880
881 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
882 {
883 arg_types = hash_tree_chain (integer_type_node,
884 TREE_CHAIN (arg_types));
885 TREE_TYPE (function)
700f8a87 886 = build_cplus_method_type (qualtype,
8d08fdba
MS
887 TREE_TYPE (TREE_TYPE (function)),
888 arg_types);
889 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
890 }
891
892 these_arg_types = arg_types;
893
894 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
895 /* Only true for static member functions. */
700f8a87
MS
896 these_arg_types = hash_tree_chain (TYPE_POINTER_TO (qualtype),
897 arg_types);
8d08fdba
MS
898
899 DECL_ASSEMBLER_NAME (function)
900 = build_decl_overload (fn_name, these_arg_types,
901 1 + DECL_CONSTRUCTOR_P (function));
902
903#if 0
904 /* This code is going into the compiler, but currently, it makes
905 libg++/src/Interger.cc not compile. The problem is that the nice name
906 winds up going into the symbol table, and conversion operations look
907 for the manged name. */
908 substitute_nice_name (function);
909#endif
910 }
911
912 DECL_ARGUMENTS (function) = last_function_parms;
913 /* First approximations. */
914 DECL_CONTEXT (function) = ctype;
915 DECL_CLASS_CONTEXT (function) = ctype;
916}
917
918/* Work on the expr used by alignof (this is only called by the parser). */
919tree
920grok_alignof (expr)
921 tree expr;
922{
923 tree best, t;
924 int bestalign;
925
926 if (TREE_CODE (expr) == COMPONENT_REF
927 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
928 error ("`__alignof__' applied to a bit-field");
929
930 if (TREE_CODE (expr) == INDIRECT_REF)
931 {
932 best = t = TREE_OPERAND (expr, 0);
933 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
934
935 while (TREE_CODE (t) == NOP_EXPR
936 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
937 {
938 int thisalign;
939 t = TREE_OPERAND (t, 0);
940 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
941 if (thisalign > bestalign)
942 best = t, bestalign = thisalign;
943 }
944 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
945 }
946 else
947 {
948 /* ANSI says arrays and fns are converted inside comma.
949 But we can't convert them in build_compound_expr
950 because that would break commas in lvalues.
951 So do the conversion here if operand was a comma. */
952 if (TREE_CODE (expr) == COMPOUND_EXPR
953 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
954 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
955 expr = default_conversion (expr);
956 return c_alignof (TREE_TYPE (expr));
957 }
958}
959
960/* Create an ARRAY_REF, checking for the user doing things backwards
961 along the way. */
962tree
963grok_array_decl (array_expr, index_exp)
964 tree array_expr, index_exp;
965{
966 tree type = TREE_TYPE (array_expr);
967
968 if (type == error_mark_node || index_exp == error_mark_node)
969 return error_mark_node;
970 if (type == NULL_TREE)
971 {
972 /* Something has gone very wrong. Assume we are mistakenly reducing
973 an expression instead of a declaration. */
974 error ("parser may be lost: is there a '{' missing somewhere?");
975 return NULL_TREE;
976 }
977
978 if (TREE_CODE (type) == OFFSET_TYPE
979 || TREE_CODE (type) == REFERENCE_TYPE)
980 type = TREE_TYPE (type);
981
982 /* If they have an `operator[]', use that. */
983 if (TYPE_LANG_SPECIFIC (type)
984 && TYPE_OVERLOADS_ARRAY_REF (type))
985 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
986 array_expr, index_exp, NULL_TREE);
987
988 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
989 if (TREE_CODE (type) == POINTER_TYPE
990 || TREE_CODE (type) == ARRAY_TYPE)
991 return build_array_ref (array_expr, index_exp);
992
993 /* Woops, looks like they did something like `5[a]' instead of `a[5]'.
994 We don't emit a warning or error for this, since it's allowed
995 by ARM $8.2.4. */
996
997 type = TREE_TYPE (index_exp);
998
999 if (TREE_CODE (type) == OFFSET_TYPE
1000 || TREE_CODE (type) == REFERENCE_TYPE)
1001 type = TREE_TYPE (type);
1002
1003 if (TYPE_LANG_SPECIFIC (type)
1004 && TYPE_OVERLOADS_ARRAY_REF (type))
1005 error ("array expression backwards");
1006 else if (TREE_CODE (type) == POINTER_TYPE
1007 || TREE_CODE (type) == ARRAY_TYPE)
1008 return build_array_ref (index_exp, array_expr);
1009 else
1010 error("`[]' applied to non-pointer type");
1011
1012 /* We gave an error, so give an error. Huh? */
1013 return error_mark_node;
1014}
1015
1016/* Given the cast expression EXP, checking out its validity. Either return
1017 an error_mark_node if there was an unavoidable error, return a cast to
1018 void for trying to delete a pointer w/ the value 0, or return the
1019 call to delete. If DOING_VEC is 1, we handle things differently
1020 for doing an array delete. If DOING_VEC is 2, they gave us the
1021 array size as an argument to delete.
1022 Implements ARM $5.3.4. This is called from the parser. */
1023tree
1024delete_sanity (exp, size, doing_vec, use_global_delete)
1025 tree exp, size;
1026 int doing_vec, use_global_delete;
1027{
1028 tree t = stabilize_reference (convert_from_reference (exp));
1029 tree type = TREE_TYPE (t);
1030 enum tree_code code = TREE_CODE (type);
1031 /* For a regular vector delete (aka, no size argument) we will pass
1032 this down as a NULL_TREE into build_vec_delete. */
1033 tree maxindex = NULL_TREE;
1034 /* This is used for deleting arrays. */
1035 tree elt_size;
1036
1037 switch (doing_vec)
1038 {
1039 case 2:
1040 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1041 if (! flag_traditional)
2986ae00 1042 pedwarn ("anachronistic use of array size in vector delete");
8d08fdba
MS
1043 /* Fall through. */
1044 case 1:
1045 elt_size = c_sizeof (type);
1046 break;
1047 default:
1048 if (code != POINTER_TYPE)
1049 {
1050 cp_error ("type `%#T' argument given to `delete', expected pointer",
1051 type);
1052 return error_mark_node;
1053 }
1054
1055 /* Deleting a pointer with the value zero is legal and has no effect. */
1056 if (integer_zerop (t))
1057 return build1 (NOP_EXPR, void_type_node, t);
1058 }
1059
1060 /* You can't delete a pointer to constant. */
1061 if (code == POINTER_TYPE && TREE_READONLY (TREE_TYPE (type)))
1062 {
1063 error ("`const *' cannot be deleted");
1064 return error_mark_node;
1065 }
1066
a28e3c7f 1067#if 0
8d08fdba
MS
1068 /* If the type has no destructor, then we should build a regular
1069 delete, instead of a vector delete. Otherwise, we would end
1070 up passing a bogus offset into __builtin_delete, which is
1071 not expecting it. */
1072 if (doing_vec
1073 && TREE_CODE (type) == POINTER_TYPE
1074 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
8926095f
MS
1075 {
1076 doing_vec = 0;
1077 use_global_delete = 1;
1078 }
a28e3c7f 1079#endif
8d08fdba
MS
1080
1081 if (doing_vec)
a28e3c7f
MS
1082 return build_vec_delete (t, maxindex, elt_size, integer_one_node,
1083 integer_two_node, use_global_delete);
8d08fdba
MS
1084 else
1085 return build_delete (type, t, integer_three_node,
1086 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
a28e3c7f 1087 use_global_delete);
8d08fdba
MS
1088}
1089
1090/* Sanity check: report error if this function FUNCTION is not
1091 really a member of the class (CTYPE) it is supposed to belong to.
1092 CNAME is the same here as it is for grokclassfn above. */
1093
1094void
1095check_classfn (ctype, cname, function)
1096 tree ctype, cname, function;
1097{
1098 tree fn_name = DECL_NAME (function);
1099 tree fndecl;
8d08fdba
MS
1100 tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
1101 tree *methods = 0;
1102 tree *end = 0;
1103
1104 if (method_vec != 0)
1105 {
1106 methods = &TREE_VEC_ELT (method_vec, 0);
1107 end = TREE_VEC_END (method_vec);
1108
1109 /* First suss out ctors and dtors. */
1110 if (*methods && fn_name == cname)
1111 goto got_it;
1112
1113 while (++methods != end)
1114 {
1115 if (fn_name == DECL_NAME (*methods))
1116 {
1117 got_it:
1118 fndecl = *methods;
1119 while (fndecl)
1120 {
1121 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1122 return;
1123 fndecl = DECL_CHAIN (fndecl);
1124 }
1125 break; /* loser */
1126 }
1127 }
1128 }
1129
1130 if (methods != end)
1131 cp_error ("argument list for `%D' does not match any in class `%T'",
1132 fn_name, ctype);
1133 else
1134 {
1135 methods = 0;
1136 cp_error ("no `%D' member function declared in class `%T'",
1137 fn_name, ctype);
1138 }
1139
1140 /* If we did not find the method in the class, add it to
1141 avoid spurious errors. */
1142 add_method (ctype, methods, function);
1143}
1144
1145/* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1146 of a structure component, returning a FIELD_DECL node.
1147 QUALS is a list of type qualifiers for this decl (such as for declaring
1148 const member functions).
1149
1150 This is done during the parsing of the struct declaration.
1151 The FIELD_DECL nodes are chained together and the lot of them
1152 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1153
1154 C++:
1155
1156 If class A defines that certain functions in class B are friends, then
1157 the way I have set things up, it is B who is interested in permission
1158 granted by A. However, it is in A's context that these declarations
1159 are parsed. By returning a void_type_node, class A does not attempt
1160 to incorporate the declarations of the friends within its structure.
1161
1162 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1163 CHANGES TO CODE IN `start_method'. */
1164
1165tree
1166grokfield (declarator, declspecs, raises, init, asmspec_tree)
1167 tree declarator, declspecs, raises, init, asmspec_tree;
1168{
1169 register tree value;
1170 char *asmspec = 0;
1171
1172 /* Convert () initializers to = initializers. */
1173 if (init == NULL_TREE && declarator != NULL_TREE
1174 && TREE_CODE (declarator) == CALL_EXPR
1175 && TREE_OPERAND (declarator, 0)
1176 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1177 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1178 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1179 {
1180 init = TREE_OPERAND (declarator, 1);
1181 declarator = TREE_OPERAND (declarator, 0);
1182 }
1183
1184 if (init
1185 && TREE_CODE (init) == TREE_LIST
1186 && TREE_VALUE (init) == error_mark_node
1187 && TREE_CHAIN (init) == NULL_TREE)
1188 init = NULL_TREE;
1189
1190 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
1191 if (! value)
a0a33927 1192 return value; /* friend or constructor went bad. */
8d08fdba
MS
1193
1194 /* Pass friendly classes back. */
1195 if (TREE_CODE (value) == VOID_TYPE)
1196 return void_type_node;
1197
1198 if (DECL_NAME (value) != NULL_TREE
1199 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1200 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1201 cp_error ("member `%D' conflicts with virtual function table field name", value);
1202
1203 /* Stash away type declarations. */
1204 if (TREE_CODE (value) == TYPE_DECL)
1205 {
1206 DECL_NONLOCAL (value) = 1;
700f8a87
MS
1207 DECL_CONTEXT (value) = current_class_type;
1208 DECL_CLASS_CONTEXT (value) = current_class_type;
8d08fdba
MS
1209 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1210 pushdecl_class_level (value);
1211 return value;
1212 }
1213
1214 if (IS_SIGNATURE (current_class_type)
1215 && TREE_CODE (value) != FUNCTION_DECL)
1216 {
1217 error ("field declaration not allowed in signature");
1218 return void_type_node;
1219 }
1220
1221 if (DECL_IN_AGGR_P (value))
1222 {
1223 cp_error ("`%D' is already defined in the class %T", value,
1224 DECL_CONTEXT (value));
1225 return void_type_node;
1226 }
1227
1228 if (flag_cadillac)
1229 cadillac_start_decl (value);
1230
1231 if (asmspec_tree)
1232 asmspec = TREE_STRING_POINTER (asmspec_tree);
1233
1234 if (init)
1235 {
1236 if (IS_SIGNATURE (current_class_type)
1237 && TREE_CODE (value) == FUNCTION_DECL)
1238 {
1239 error ("function declarations cannot have initializers in signature");
1240 init = NULL_TREE;
1241 }
1242 else if (TREE_CODE (value) == FUNCTION_DECL)
1243 {
1244 grok_function_init (value, init);
1245 init = NULL_TREE;
1246 }
5b605f68 1247 else if (pedantic && TREE_CODE (value) != VAR_DECL)
a0a33927
MS
1248 /* Already complained in grokdeclarator. */
1249 init = NULL_TREE;
8d08fdba
MS
1250 else
1251 {
a0a33927
MS
1252 /* We allow initializers to become parameters to base
1253 initializers. */
8d08fdba
MS
1254 if (TREE_CODE (init) == TREE_LIST)
1255 {
1256 if (TREE_CHAIN (init) == NULL_TREE)
1257 init = TREE_VALUE (init);
1258 else
1259 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1260 }
1261
1262 if (TREE_CODE (init) == CONST_DECL)
1263 init = DECL_INITIAL (init);
1264 else if (TREE_READONLY_DECL_P (init))
1265 init = decl_constant_value (init);
1266 else if (TREE_CODE (init) == CONSTRUCTOR)
1267 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1268 my_friendly_assert (TREE_PERMANENT (init), 192);
1269 if (init == error_mark_node)
1270 /* We must make this look different than `error_mark_node'
1271 because `decl_const_value' would mis-interpret it
1272 as only meaning that this VAR_DECL is defined. */
1273 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1274 else if (! TREE_CONSTANT (init))
1275 {
1276 /* We can allow references to things that are effectively
1277 static, since references are initialized with the address. */
1278 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1279 || (TREE_STATIC (init) == 0
1280 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1281 || DECL_EXTERNAL (init) == 0)))
1282 {
1283 error ("field initializer is not constant");
1284 init = error_mark_node;
1285 }
1286 }
1287 }
1288 }
1289
1290 /* The corresponding pop_obstacks is in finish_decl. */
1291 push_obstacks_nochange ();
1292
1293 if (TREE_CODE (value) == VAR_DECL)
1294 {
1295 /* We cannot call pushdecl here, because that would
1296 fill in the value of our TREE_CHAIN. Instead, we
1297 modify finish_decl to do the right thing, namely, to
1298 put this decl out straight away. */
5b605f68 1299 if (TREE_PUBLIC (value))
8d08fdba
MS
1300 {
1301 /* current_class_type can be NULL_TREE in case of error. */
1302 if (asmspec == 0 && current_class_type)
1303 {
1304 tree name;
1305 char *buf, *buf2;
1306
1307 buf2 = build_overload_name (current_class_type, 1, 1);
1308 buf = (char *)alloca (IDENTIFIER_LENGTH (DECL_NAME (value))
1309 + sizeof (STATIC_NAME_FORMAT)
1310 + strlen (buf2));
1311 sprintf (buf, STATIC_NAME_FORMAT, buf2,
1312 IDENTIFIER_POINTER (DECL_NAME (value)));
1313 name = get_identifier (buf);
1314 TREE_PUBLIC (value) = 1;
1315 DECL_INITIAL (value) = error_mark_node;
1316 DECL_ASSEMBLER_NAME (value) = name;
1317 }
1318 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1319
1320 /* Static consts need not be initialized in the class definition. */
1321 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1322 {
1323 static int explanation = 0;
1324
1325 error ("initializer invalid for static member with constructor");
1326 if (explanation++ == 0)
1327 error ("(you really want to initialize it separately)");
1328 init = 0;
1329 }
1330 /* Force the compiler to know when an uninitialized static
1331 const member is being used. */
1332 if (TYPE_READONLY (value) && init == 0)
1333 TREE_USED (value) = 1;
1334 }
1335 DECL_INITIAL (value) = init;
1336 DECL_IN_AGGR_P (value) = 1;
1337
1338 finish_decl (value, init, asmspec_tree, 1);
1339 pushdecl_class_level (value);
1340 return value;
1341 }
1342 if (TREE_CODE (value) == FIELD_DECL)
1343 {
1344 if (asmspec)
1345 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1346 if (DECL_INITIAL (value) == error_mark_node)
1347 init = error_mark_node;
1348 finish_decl (value, init, asmspec_tree, 1);
1349 DECL_INITIAL (value) = init;
1350 DECL_IN_AGGR_P (value) = 1;
1351 return value;
1352 }
1353 if (TREE_CODE (value) == FUNCTION_DECL)
1354 {
8d08fdba
MS
1355 if (DECL_CHAIN (value) != NULL_TREE)
1356 {
1357 /* Need a fresh node here so that we don't get circularity
1358 when we link these together. */
1359 value = copy_node (value);
1360 /* When does this happen? */
1361 my_friendly_assert (init == NULL_TREE, 193);
1362 }
1363 finish_decl (value, init, asmspec_tree, 1);
1364
1365 /* Pass friends back this way. */
1366 if (DECL_FRIEND_P (value))
1367 return void_type_node;
1368
a0a33927 1369 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
7177d104
MS
1370 cp_error ("method `%#D' of local class must be defined in class body",
1371 value);
1372
8d08fdba
MS
1373 DECL_IN_AGGR_P (value) = 1;
1374 return value;
1375 }
1376 my_friendly_abort (21);
1377 /* NOTREACHED */
1378 return NULL_TREE;
1379}
1380
1381/* Like `grokfield', but for bitfields.
1382 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1383
1384tree
1385grokbitfield (declarator, declspecs, width)
1386 tree declarator, declspecs, width;
1387{
1388 register tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL_TREE);
1389
1390 if (! value) return NULL_TREE; /* friends went bad. */
1391
1392 /* Pass friendly classes back. */
1393 if (TREE_CODE (value) == VOID_TYPE)
1394 return void_type_node;
1395
1396 if (TREE_CODE (value) == TYPE_DECL)
1397 {
1398 cp_error ("cannot declare `%D' to be a bitfield type", value);
1399 return NULL_TREE;
1400 }
1401
1402 if (IS_SIGNATURE (current_class_type))
1403 {
1404 error ("field declaration not allowed in signature");
1405 return void_type_node;
1406 }
1407
1408 if (DECL_IN_AGGR_P (value))
1409 {
1410 cp_error ("`%D' is already defined in the class %T", value,
1411 DECL_CONTEXT (value));
1412 return void_type_node;
1413 }
1414
1415 GNU_xref_member (current_class_name, value);
1416
1417 if (TREE_STATIC (value))
1418 {
1419 cp_error ("static member `%D' cannot be a bitfield", value);
1420 return NULL_TREE;
1421 }
1422 finish_decl (value, NULL_TREE, NULL_TREE, 0);
1423
1424 if (width != error_mark_node)
1425 {
1426 /* detect invalid field size. */
1427 if (TREE_CODE (width) == CONST_DECL)
1428 width = DECL_INITIAL (width);
1429 else if (TREE_READONLY_DECL_P (width))
1430 width = decl_constant_value (width);
1431 if (TREE_CODE (width) != INTEGER_CST)
1432 {
1433 cp_error ("structure field `%D' width not an integer constant",
1434 value);
1435 DECL_INITIAL (value) = NULL_TREE;
1436 }
1437 else
1438 {
1439 constant_expression_warning (width);
1440 DECL_INITIAL (value) = width;
1441 DECL_BIT_FIELD (value) = 1;
1442 }
1443 }
1444
1445 DECL_IN_AGGR_P (value) = 1;
1446 return value;
1447}
1448
a28e3c7f 1449#if 0
8d08fdba
MS
1450/* Like GROKFIELD, except that the declarator has been
1451 buried in DECLSPECS. Find the declarator, and
1452 return something that looks like it came from
1453 GROKFIELD. */
1454tree
1455groktypefield (declspecs, parmlist)
1456 tree declspecs;
1457 tree parmlist;
1458{
1459 tree spec = declspecs;
1460 tree prev = NULL_TREE;
1461
1462 tree type_id = NULL_TREE;
1463 tree quals = NULL_TREE;
1464 tree lengths = NULL_TREE;
1465 tree decl = NULL_TREE;
1466
1467 while (spec)
1468 {
1469 register tree id = TREE_VALUE (spec);
1470
1471 if (TREE_CODE (spec) != TREE_LIST)
1472 /* Certain parse errors slip through. For example,
1473 `int class ();' is not caught by the parser. Try
1474 weakly to recover here. */
1475 return NULL_TREE;
1476
1477 if (TREE_CODE (id) == TYPE_DECL
1478 || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
1479 {
1480 /* We have a constructor/destructor or
1481 conversion operator. Use it. */
1482 if (prev)
1483 TREE_CHAIN (prev) = TREE_CHAIN (spec);
1484 else
1485 declspecs = TREE_CHAIN (spec);
1486
1487 type_id = id;
1488 goto found;
1489 }
1490 prev = spec;
1491 spec = TREE_CHAIN (spec);
1492 }
1493
1494 /* Nope, we have a conversion operator to a scalar type or something
1495 else, that includes things like constructor declarations for
1496 templates. */
1497 spec = declspecs;
1498 while (spec)
1499 {
1500 tree id = TREE_VALUE (spec);
1501
1502 if (TREE_CODE (id) == IDENTIFIER_NODE)
1503 {
1504 if (id == ridpointers[(int)RID_INT]
1505 || id == ridpointers[(int)RID_DOUBLE]
1506 || id == ridpointers[(int)RID_FLOAT]
1507 || id == ridpointers[(int)RID_WCHAR])
1508 {
1509 if (type_id)
1510 error ("extra `%s' ignored",
1511 IDENTIFIER_POINTER (id));
1512 else
1513 type_id = id;
1514 }
1515 else if (id == ridpointers[(int)RID_LONG]
1516 || id == ridpointers[(int)RID_SHORT]
1517 || id == ridpointers[(int)RID_CHAR])
1518 {
1519 lengths = tree_cons (NULL_TREE, id, lengths);
1520 }
1521 else if (id == ridpointers[(int)RID_VOID])
1522 {
1523 if (type_id)
1524 error ("spurious `void' type ignored");
1525 else
1526 error ("conversion to `void' type invalid");
1527 }
1528 else if (id == ridpointers[(int)RID_AUTO]
1529 || id == ridpointers[(int)RID_REGISTER]
1530 || id == ridpointers[(int)RID_TYPEDEF]
1531 || id == ridpointers[(int)RID_CONST]
1532 || id == ridpointers[(int)RID_VOLATILE])
1533 {
1534 error ("type specifier `%s' used invalidly",
1535 IDENTIFIER_POINTER (id));
1536 }
1537 else if (id == ridpointers[(int)RID_FRIEND]
1538 || id == ridpointers[(int)RID_VIRTUAL]
1539 || id == ridpointers[(int)RID_INLINE]
1540 || id == ridpointers[(int)RID_UNSIGNED]
1541 || id == ridpointers[(int)RID_SIGNED]
1542 || id == ridpointers[(int)RID_STATIC]
1543 || id == ridpointers[(int)RID_EXTERN])
1544 {
1545 quals = tree_cons (NULL_TREE, id, quals);
1546 }
1547 else
1548 {
1549 /* Happens when we have a global typedef
1550 and a class-local member function with
1551 the same name. */
1552 type_id = id;
1553 goto found;
1554 }
1555 }
1556 else if (TREE_CODE (id) == RECORD_TYPE)
1557 {
1558 type_id = TYPE_NAME (id);
1559 if (TREE_CODE (type_id) == TYPE_DECL)
1560 type_id = DECL_NAME (type_id);
1561 if (type_id == NULL_TREE)
1562 error ("identifier for aggregate type conversion omitted");
1563 }
1564 else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't')
1565 error ("`operator' missing on conversion operator or tag missing from type");
1566 else
1567 my_friendly_abort (194);
1568 spec = TREE_CHAIN (spec);
1569 }
1570
1571 if (type_id)
1572 declspecs = chainon (lengths, quals);
1573 else if (lengths)
1574 {
1575 if (TREE_CHAIN (lengths))
1576 error ("multiple length specifiers");
1577 type_id = ridpointers[(int)RID_INT];
1578 declspecs = chainon (lengths, quals);
1579 }
1580 else if (quals)
1581 {
1582 error ("no type given, defaulting to `operator int ...'");
1583 type_id = ridpointers[(int)RID_INT];
1584 declspecs = quals;
1585 }
1586 else
1587 return NULL_TREE;
1588
1589 found:
1590 decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
1591 declspecs, FIELD, 0, NULL_TREE);
1592 if (decl == NULL_TREE)
1593 return NULL_TREE;
1594
1595 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
1596 {
1597 /* Need a fresh node here so that we don't get circularity
1598 when we link these together. */
1599 decl = copy_node (decl);
1600 }
1601
1602 if (decl == void_type_node
1603 || (TREE_CODE (decl) == FUNCTION_DECL
1604 && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
1605 /* bunch of friends. */
1606 return decl;
1607
1608 if (DECL_IN_AGGR_P (decl))
1609 {
1610 cp_error ("`%D' already defined in the class ", decl);
1611 return void_type_node;
1612 }
1613
1614 finish_decl (decl, NULL_TREE, NULL_TREE, 0);
1615
1616 /* If this declaration is common to another declaration
1617 complain about such redundancy, and return NULL_TREE
1618 so that we don't build a circular list. */
1619 if (DECL_CHAIN (decl))
1620 {
1621 cp_error ("function `%D' declared twice in class %T", decl,
1622 DECL_CONTEXT (decl));
1623 return NULL_TREE;
1624 }
1625 DECL_IN_AGGR_P (decl) = 1;
1626 return decl;
1627}
a28e3c7f 1628#endif
8d08fdba 1629
8d08fdba 1630tree
51c184be
MS
1631grokoptypename (declspecs, declarator)
1632 tree declspecs, declarator;
8d08fdba 1633{
51c184be
MS
1634 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1635 return build_typename_overload (t);
8d08fdba
MS
1636}
1637
1638/* When a function is declared with an initializer,
1639 do the right thing. Currently, there are two possibilities:
1640
1641 class B
1642 {
1643 public:
1644 // initialization possibility #1.
1645 virtual void f () = 0;
1646 int g ();
1647 };
1648
1649 class D1 : B
1650 {
1651 public:
1652 int d1;
1653 // error, no f ();
1654 };
1655
1656 class D2 : B
1657 {
1658 public:
1659 int d2;
1660 void f ();
1661 };
1662
1663 class D3 : B
1664 {
1665 public:
1666 int d3;
1667 // initialization possibility #2
1668 void f () = B::f;
1669 };
1670
1671*/
1672
f0e01782
MS
1673int
1674copy_assignment_arg_p (parmtype, virtualp)
1675 tree parmtype;
1676 int virtualp;
1677{
1678 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1679 parmtype = TREE_TYPE (parmtype);
1680
1681 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1682 || (virtualp && DERIVED_FROM_P (parmtype, current_class_type)))
1683 return 1;
1684
1685 return 0;
1686}
1687
8d08fdba
MS
1688static void
1689grok_function_init (decl, init)
1690 tree decl;
1691 tree init;
1692{
1693 /* An initializer for a function tells how this function should
1694 be inherited. */
1695 tree type = TREE_TYPE (decl);
8d08fdba
MS
1696
1697 if (TREE_CODE (type) == FUNCTION_TYPE)
1698 cp_error ("initializer specified for non-member function `%D'", decl);
1699 else if (DECL_VINDEX (decl) == NULL_TREE)
1700 cp_error ("initializer specified for non-virtual method `%D'", decl);
1701 else if (integer_zerop (init))
1702 {
8926095f 1703#if 0
8d08fdba
MS
1704 /* Mark this function as being "defined". */
1705 DECL_INITIAL (decl) = error_mark_node;
1706 /* pure virtual destructors must be defined. */
8926095f
MS
1707 /* pure virtual needs to be defined (as abort) only when put in
1708 vtbl. For wellformed call, it should be itself. pr4737 */
8d08fdba
MS
1709 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1710 {
8926095f 1711 extern tree abort_fndecl;
8d08fdba
MS
1712 /* Give this node rtl from `abort'. */
1713 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1714 }
8926095f 1715#endif
8d08fdba 1716 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
f0e01782
MS
1717 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1718 {
1719 tree parmtype
1720 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1721
1722 if (copy_assignment_arg_p (parmtype, 1))
1723 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1724 }
8d08fdba
MS
1725 }
1726 else if (TREE_CODE (init) == OFFSET_REF
1727 && TREE_OPERAND (init, 0) == NULL_TREE
1728 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1729 {
1730 tree basetype = DECL_CLASS_CONTEXT (init);
1731 tree basefn = TREE_OPERAND (init, 1);
1732 if (TREE_CODE (basefn) != FUNCTION_DECL)
1733 cp_error ("non-method initializer invalid for method `%D'", decl);
1734 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1735 sorry ("base member function from other than first base class");
1736 else
1737 {
1738 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1739 if (binfo == error_mark_node)
1740 ;
1741 else if (binfo == 0)
1742 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1743 TYPE_METHOD_BASETYPE (type));
1744 else
1745 {
1746 /* Mark this function as being defined,
1747 and give it new rtl. */
1748 DECL_INITIAL (decl) = error_mark_node;
1749 DECL_RTL (decl) = DECL_RTL (basefn);
1750 }
1751 }
1752 }
1753 else
1754 cp_error ("invalid initializer for virtual method `%D'", decl);
1755}
1756\f
1757/* When we get a declaration of the form
1758
1759 type cname::fname ...
1760
1761 the node for `cname::fname' gets built here in a special way.
1762 Namely, we push into `cname's scope. When this declaration is
1763 processed, we pop back out. */
1764tree
1765build_push_scope (cname, name)
1766 tree cname;
1767 tree name;
1768{
1769 extern int current_class_depth;
1770 tree ctype, rval;
1771 int is_ttp = 0;
1772
1773 if (cname == error_mark_node)
1774 return error_mark_node;
1775
1776 ctype = IDENTIFIER_TYPE_VALUE (cname);
1777
1778 if (TREE_CODE (ctype) == TEMPLATE_TYPE_PARM)
1779 is_ttp = 1;
1780 else if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
1781 {
1782 cp_error ("`%T' not defined as aggregate type", cname);
1783 return name;
1784 }
1785 else if (IS_SIGNATURE (ctype))
1786 {
1787 error ("cannot push into signature scope, scope resolution operator ignored");
1788 return name;
1789 }
1790
1791 rval = build_parse_node (SCOPE_REF, cname, name);
1792
1793 /* Don't need to push the scope if we're already in it.
1794 We also don't need to push the scope for a ptr-to-member/method. */
1795
1796 if (ctype == current_class_type || TREE_CODE (name) != IDENTIFIER_NODE
1797 || is_ttp)
1798 return rval;
1799
1800 /* We do need to push the scope in this case, since CTYPE helps
1801 determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;). */
1802
1803 push_nested_class (ctype, 3);
1804 TREE_COMPLEXITY (rval) = current_class_depth;
1805 return rval;
1806}
1807
1808void cplus_decl_attributes (decl, attributes)
1809 tree decl, attributes;
1810{
2986ae00 1811 if (decl && decl != void_type_node)
8d08fdba
MS
1812 decl_attributes (decl, attributes);
1813}
1814\f
1815/* CONSTRUCTOR_NAME:
1816 Return the name for the constructor (or destructor) for the
1817 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1818 IDENTIFIER_NODE. When given a template, this routine doesn't
1819 lose the specialization. */
1820tree
1821constructor_name_full (thing)
1822 tree thing;
1823{
8d08fdba
MS
1824 if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
1825 return DECL_NAME (UPT_TEMPLATE (thing));
1826 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1827 {
1828 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1829 thing = DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing), 0));
1830 else
1831 thing = TYPE_NAME (thing);
1832 }
1833 if (TREE_CODE (thing) == TYPE_DECL
1834 || (TREE_CODE (thing) == TEMPLATE_DECL
1835 && DECL_TEMPLATE_IS_CLASS (thing)))
1836 thing = DECL_NAME (thing);
1837 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1838 return thing;
1839}
1840
1841/* CONSTRUCTOR_NAME:
1842 Return the name for the constructor (or destructor) for the
1843 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1844 IDENTIFIER_NODE. When given a template, return the plain
1845 unspecialized name. */
1846tree
1847constructor_name (thing)
1848 tree thing;
1849{
1850 tree t;
1851 thing = constructor_name_full (thing);
1852 t = IDENTIFIER_TEMPLATE (thing);
1853 if (!t)
1854 return thing;
1855 t = TREE_PURPOSE (t);
1856 return DECL_NAME (t);
1857}
1858\f
1859/* Cache the value of this class's main virtual function table pointer
1860 in a register variable. This will save one indirection if a
1861 more than one virtual function call is made this function. */
1862void
1863setup_vtbl_ptr ()
1864{
1865 extern rtx base_init_insns;
1866
1867 if (base_init_insns == 0
1868 && DECL_CONSTRUCTOR_P (current_function_decl))
1869 emit_base_init (current_class_type, 0);
1870
1871#if 0
1872 /* This has something a little wrong with it.
1873
1874 On a sun4, code like:
1875
1876 be L6
1877 ld [%i0],%o1
1878
1879 is generated, when the below is used when -O4 is given. The delay
1880 slot it filled with an instruction that is safe, when this isn't
1881 used, like in:
1882
1883 be L6
1884 sethi %hi(LC1),%o0
1885 ld [%i0],%o1
1886
1887 on code like:
1888
1889 struct A {
1890 virtual void print() { printf("xxx"); }
1891 void f();
1892 };
1893
1894 void A::f() {
1895 if (this) {
1896 print();
1897 } else {
1898 printf("0");
1899 }
1900 }
1901
1902 And that is why this is disabled for now. (mrs)
1903 */
1904
1905 if ((flag_this_is_variable & 1) == 0
1906 && optimize
1907 && current_class_type
1908 && CLASSTYPE_VSIZE (current_class_type)
1909 && ! DECL_STATIC_FUNCTION_P (current_function_decl))
1910 {
1911 tree vfield = build_vfield_ref (C_C_D, current_class_type);
1912 current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
1913 DECL_RTL (current_vtable_decl) = 0;
1914 DECL_INITIAL (current_vtable_decl) = error_mark_node;
1915 /* Have to cast the initializer, since it may have come from a
1916 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
1917 finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield), 0, 0);
1918 current_vtable_decl = build_indirect_ref (current_vtable_decl, NULL_PTR);
1919 }
1920 else
1921#endif
1922 current_vtable_decl = NULL_TREE;
1923}
1924
1925/* Record the existence of an addressable inline function. */
1926void
1927mark_inline_for_output (decl)
1928 tree decl;
1929{
8926095f
MS
1930 if (DECL_SAVED_INLINE (decl))
1931 return;
1932 DECL_SAVED_INLINE (decl) = 1;
8d08fdba
MS
1933 if (DECL_PENDING_INLINE_INFO (decl) != 0
1934 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
1935 {
1936 struct pending_inline *t = pending_inlines;
1937 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
1938 while (t)
1939 {
1940 if (t == DECL_PENDING_INLINE_INFO (decl))
1941 break;
1942 t = t->next;
1943 }
1944 if (t == 0)
1945 {
1946 t = DECL_PENDING_INLINE_INFO (decl);
1947 t->next = pending_inlines;
1948 pending_inlines = t;
1949 }
1950 DECL_PENDING_INLINE_INFO (decl) = 0;
1951 }
8926095f 1952 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
8d08fdba
MS
1953}
1954
1955void
1956clear_temp_name ()
1957{
1958 temp_name_counter = 0;
1959}
1960
1961/* Hand off a unique name which can be used for variable we don't really
1962 want to know about anyway, for example, the anonymous variables which
1963 are needed to make references work. Declare this thing so we can use it.
1964 The variable created will be of type TYPE.
1965
1966 STATICP is nonzero if this variable should be static. */
1967
1968tree
1969get_temp_name (type, staticp)
1970 tree type;
1971 int staticp;
1972{
1973 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
1974 tree decl;
1975 int toplev = global_bindings_p ();
1976
1977 push_obstacks_nochange ();
1978 if (toplev || staticp)
1979 {
1980 end_temporary_allocation ();
1981 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
1982 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
1983 }
1984 else
1985 {
1986 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
1987 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1988 }
1989 TREE_USED (decl) = 1;
1990 TREE_STATIC (decl) = staticp;
1991
1992 /* If this is a local variable, then lay out its rtl now.
1993 Otherwise, callers of this function are responsible for dealing
1994 with this variable's rtl. */
1995 if (! toplev)
1996 {
1997 expand_decl (decl);
1998 expand_decl_init (decl);
1999 }
2000 pop_obstacks ();
2001
2002 return decl;
2003}
2004
2005/* Get a variable which we can use for multiple assignments.
2006 It is not entered into current_binding_level, because
2007 that breaks things when it comes time to do final cleanups
2008 (which take place "outside" the binding contour of the function). */
2009tree
2010get_temp_regvar (type, init)
2011 tree type, init;
2012{
2013 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
2014 tree decl;
2015
2016 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
2017 decl = build_decl (VAR_DECL, get_identifier (buf), type);
2018 TREE_USED (decl) = 1;
2019 DECL_REGISTER (decl) = 1;
2020
2021 if (init)
2022 store_init_value (decl, init);
2023
2024 /* We can expand these without fear, since they cannot need
2025 constructors or destructors. */
2026 expand_decl (decl);
2027 expand_decl_init (decl);
2028
2029 if (type_needs_gc_entry (type))
2030 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
2031
2032 return decl;
2033}
2034
2035/* Make the macro TEMP_NAME_P available to units which do not
2036 include c-tree.h. */
2037int
2038temp_name_p (decl)
2039 tree decl;
2040{
2041 return TEMP_NAME_P (decl);
2042}
2043
2044/* Finish off the processing of a UNION_TYPE structure.
2045 If there are static members, then all members are
2046 static, and must be laid out together. If the
2047 union is an anonymous union, we arrange for that
2048 as well. PUBLIC_P is nonzero if this union is
2049 not declared static. */
2050void
2051finish_anon_union (anon_union_decl)
2052 tree anon_union_decl;
2053{
2054 tree type = TREE_TYPE (anon_union_decl);
2055 tree field, main_decl = NULL_TREE;
2056 tree elems = NULL_TREE;
2057 int public_p = TREE_PUBLIC (anon_union_decl);
2058 int static_p = TREE_STATIC (anon_union_decl);
2059 int external_p = DECL_EXTERNAL (anon_union_decl);
2060
2061 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
2062 return;
2063
2064 if (public_p)
2065 {
2066 error ("global anonymous unions must be declared static");
2067 return;
2068 }
2069
2070 while (field)
2071 {
2072 tree decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2073 /* tell `pushdecl' that this is not tentative. */
2074 DECL_INITIAL (decl) = error_mark_node;
2075 TREE_PUBLIC (decl) = public_p;
2076 TREE_STATIC (decl) = static_p;
2077 DECL_EXTERNAL (decl) = external_p;
2078 decl = pushdecl (decl);
2079
2080 /* Only write out one anon union element--choose the one that
2081 can hold them all. */
2082 if (main_decl == NULL_TREE
2083 && simple_cst_equal (DECL_SIZE (decl), DECL_SIZE (anon_union_decl)))
2084 {
2085 main_decl = decl;
2086 }
2087 else
2088 {
2089 /* ??? This causes there to be no debug info written out
2090 about this decl. */
2091 TREE_ASM_WRITTEN (decl) = 1;
2092 }
2093
2094 DECL_INITIAL (decl) = NULL_TREE;
2095 /* If there's a cleanup to do, it belongs in the
2096 TREE_PURPOSE of the following TREE_LIST. */
2097 elems = tree_cons (NULL_TREE, decl, elems);
2098 TREE_TYPE (elems) = type;
2099 field = TREE_CHAIN (field);
2100 }
2101 if (static_p)
2102 {
a292b002
MS
2103 if (main_decl)
2104 {
2105 make_decl_rtl (main_decl, 0, global_bindings_p ());
2106 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2107 }
2108 else
2109 {
2110 warning ("anonymous union with no members");
2111 return;
2112 }
8d08fdba
MS
2113 }
2114
2115 /* The following call assumes that there are never any cleanups
2116 for anonymous unions--a reasonable assumption. */
2117 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2118
2119 if (flag_cadillac)
2120 cadillac_finish_anon_union (anon_union_decl);
2121}
2122
2123/* Finish and output a table which is generated by the compiler.
2124 NAME is the name to give the table.
2125 TYPE is the type of the table entry.
2126 INIT is all the elements in the table.
2127 PUBLICP is non-zero if this table should be given external access. */
2128tree
2129finish_table (name, type, init, publicp)
2130 tree name, type, init;
2131 int publicp;
2132{
2133 tree itype, atype, decl;
2134 static tree empty_table;
2135 int is_empty = 0;
2136 tree asmspec;
2137
2138 itype = build_index_type (size_int (list_length (init) - 1));
2139 atype = build_cplus_array_type (type, itype);
2140 layout_type (atype);
2141
2142 if (TREE_VALUE (init) == integer_zero_node
2143 && TREE_CHAIN (init) == NULL_TREE)
2144 {
2145 if (empty_table == NULL_TREE)
2146 {
2147 empty_table = get_temp_name (atype, 1);
2148 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2149 TREE_CONSTANT (init) = 1;
2150 TREE_STATIC (init) = 1;
2151 DECL_INITIAL (empty_table) = init;
2152 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2153 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2154 finish_decl (empty_table, init, asmspec, 0);
2155 }
2156 is_empty = 1;
2157 }
2158
2159 if (name == NULL_TREE)
2160 {
2161 if (is_empty)
2162 return empty_table;
2163 decl = get_temp_name (atype, 1);
2164 }
2165 else
2166 {
2167 decl = build_decl (VAR_DECL, name, atype);
2168 decl = pushdecl (decl);
2169 TREE_STATIC (decl) = 1;
2170 }
2171
2172 if (is_empty == 0)
2173 {
2174 TREE_PUBLIC (decl) = publicp;
2175 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2176 TREE_CONSTANT (init) = 1;
2177 TREE_STATIC (init) = 1;
2178 DECL_INITIAL (decl) = init;
2179 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2180 IDENTIFIER_POINTER (DECL_NAME (decl)));
2181 }
2182 else
2183 {
2184 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2185 DECL_EXTERNAL (decl) = 1;
2186 TREE_STATIC (decl) = 0;
2187 init = 0;
2188 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2189 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2190 }
2191
2192 finish_decl (decl, init, asmspec, 0);
2193 return decl;
2194}
2195
2196/* Finish processing a builtin type TYPE. It's name is NAME,
2197 its fields are in the array FIELDS. LEN is the number of elements
2198 in FIELDS minus one, or put another way, it is the maximum subscript
2199 used in FIELDS.
2200
2201 It is given the same alignment as ALIGN_TYPE. */
2202void
2203finish_builtin_type (type, name, fields, len, align_type)
2204 tree type;
2205 char *name;
2206 tree fields[];
2207 int len;
2208 tree align_type;
2209{
2210 register int i;
2211
2212 TYPE_FIELDS (type) = fields[0];
2213 for (i = 0; i < len; i++)
2214 {
2215 layout_type (TREE_TYPE (fields[i]));
2216 DECL_FIELD_CONTEXT (fields[i]) = type;
2217 TREE_CHAIN (fields[i]) = fields[i+1];
2218 }
2219 DECL_FIELD_CONTEXT (fields[i]) = type;
2220 DECL_CLASS_CONTEXT (fields[i]) = type;
2221 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2222 layout_type (type);
2223#if 0 /* not yet, should get fixed properly later */
2224 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2225#else
2226 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2227#endif
2228 layout_decl (TYPE_NAME (type), 0);
2229}
2230\f
2231/* Auxiliary functions to make type signatures for
2232 `operator new' and `operator delete' correspond to
2233 what compiler will be expecting. */
2234
2235extern tree sizetype;
2236
2237tree
2238coerce_new_type (type)
2239 tree type;
2240{
2241 int e1 = 0, e2 = 0;
2242
2243 if (TREE_CODE (type) == METHOD_TYPE)
2244 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2245 if (TREE_TYPE (type) != ptr_type_node)
2246 e1 = 1, error ("`operator new' must return type `void *'");
2247
2248 /* Technically the type must be `size_t', but we may not know
2249 what that is. */
2250 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2251 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2252 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2253 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2254 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2255 if (e2)
2256 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2257 else if (e1)
2258 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2259 return type;
2260}
2261
2262tree
2263coerce_delete_type (type)
2264 tree type;
2265{
2266 int e1 = 0, e2 = 0, e3 = 0;
2267 tree arg_types = TYPE_ARG_TYPES (type);
2268
2269 if (TREE_CODE (type) == METHOD_TYPE)
2270 {
2271 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2272 arg_types = TREE_CHAIN (arg_types);
2273 }
2274 if (TREE_TYPE (type) != void_type_node)
2275 e1 = 1, error ("`operator delete' must return type `void'");
2276 if (arg_types == NULL_TREE
2277 || TREE_VALUE (arg_types) != ptr_type_node)
2278 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2279
2280 if (arg_types
2281 && TREE_CHAIN (arg_types)
2282 && TREE_CHAIN (arg_types) != void_list_node)
2283 {
2284 /* Again, technically this argument must be `size_t', but again
2285 we may not know what that is. */
2286 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2287 if (TREE_CODE (t2) != INTEGER_TYPE
2288 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2289 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2290 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2291 {
2292 e3 = 1;
2293 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2294 error ("too many arguments in declaration of `operator delete'");
2295 else
2296 error ("`...' invalid in specification of `operator delete'");
2297 }
2298 }
2299 if (e3)
2300 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
2301 else if (e3 |= e2)
2302 {
2303 if (arg_types == NULL_TREE)
a28e3c7f 2304 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
8d08fdba
MS
2305 else
2306 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2307 }
2308 else e3 |= e1;
2309
2310 if (e3)
2311 type = build_function_type (void_type_node, arg_types);
2312
2313 return type;
2314}
2315\f
2316static void
8926095f 2317mark_vtable_entries (decl)
8d08fdba
MS
2318 tree decl;
2319{
2320 tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
2321
2322 if (flag_dossier)
2323 entries = TREE_CHAIN (entries);
2324
2325 for (; entries; entries = TREE_CHAIN (entries))
2326 {
2327 tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
2328 tree fn = TREE_OPERAND (fnaddr, 0);
8926095f 2329 TREE_ADDRESSABLE (fn) = 1;
7177d104
MS
2330 if (DECL_ABSTRACT_VIRTUAL_P (fn))
2331 {
2332 extern tree abort_fndecl;
a3b49ccd
MS
2333 if (flag_vtable_thunks)
2334 fnaddr = TREE_VALUE (entries);
7177d104
MS
2335 TREE_OPERAND (fnaddr, 0) = abort_fndecl;
2336 }
2337 }
2338}
2339
2340/* Set TREE_PUBLIC and/or TREE_EXTERN on the vtable DECL,
2341 based on TYPE and other static flags.
2342
2343 Note that anything public is tagged TREE_PUBLIC, whether
2344 it's public in this file or in another one. */
2345
5b605f68 2346void
7177d104
MS
2347import_export_vtable (decl, type)
2348 tree decl, type;
2349{
f0e01782
MS
2350 if (write_virtuals >= 2
2351 || CLASSTYPE_TEMPLATE_INSTANTIATION (type))
7177d104
MS
2352 {
2353 if (CLASSTYPE_INTERFACE_KNOWN (type))
2354 {
2355 TREE_PUBLIC (decl) = 1;
2356 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2357 }
2358 }
2359 else if (write_virtuals != 0)
2360 {
2361 TREE_PUBLIC (decl) = 1;
2362 if (write_virtuals < 0)
2363 DECL_EXTERNAL (decl) = 1;
8d08fdba
MS
2364 }
2365}
2366
5b605f68
MS
2367static void
2368import_export_template (type)
2369 tree type;
2370{
2371 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2372 && ! flag_implicit_templates
2373 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2374 {
2375 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2376 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2377 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2378 }
2379}
2380
8d08fdba
MS
2381static void
2382finish_vtable_vardecl (prev, vars)
2383 tree prev, vars;
2384{
51c184be 2385 tree ctype = DECL_CONTEXT (vars);
5b605f68 2386 import_export_template (ctype);
7177d104
MS
2387 import_export_vtable (vars, ctype);
2388
8926095f 2389 if (flag_vtable_thunks && !CLASSTYPE_INTERFACE_KNOWN (ctype))
51c184be
MS
2390 {
2391 tree method;
2392 for (method = CLASSTYPE_METHODS (ctype); method != NULL_TREE;
2393 method = DECL_NEXT_METHOD (method))
2394 {
a0a33927
MS
2395 if (DECL_VINDEX (method) != NULL_TREE && !DECL_SAVED_INSNS (method)
2396 && !DECL_ABSTRACT_VIRTUAL_P (method))
51c184be 2397 {
8926095f
MS
2398 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2399 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
51c184be
MS
2400 TREE_PUBLIC (vars) = 1;
2401 DECL_EXTERNAL (vars) = DECL_EXTERNAL (method);
2402 break;
2403 }
2404 }
2405 }
2406
8d08fdba
MS
2407 if (write_virtuals >= 0
2408 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
2409 {
2410 extern tree the_null_vtable_entry;
2411
2412 /* Stuff this virtual function table's size into
2413 `pfn' slot of `the_null_vtable_entry'. */
2414 tree nelts = array_type_nelts (TREE_TYPE (vars));
8926095f
MS
2415 if (flag_vtable_thunks)
2416 TREE_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))) = nelts;
2417 else
2418 SET_FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry, nelts);
8d08fdba
MS
2419 /* Kick out the dossier before writing out the vtable. */
2420 if (flag_dossier)
2421 rest_of_decl_compilation (TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))))), 0), 0, 1, 1);
2422
2423 /* Write it out. */
8926095f 2424 mark_vtable_entries (vars);
8d08fdba 2425 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
8926095f 2426 store_init_value (vars, DECL_INITIAL (vars));
8d08fdba
MS
2427
2428#ifdef DWARF_DEBUGGING_INFO
2429 if (write_symbols == DWARF_DEBUG)
2430 {
2431 /* Mark the VAR_DECL node representing the vtable itself as a
2432 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2433 It is rather important that such things be ignored because
2434 any effort to actually generate DWARF for them will run
2435 into trouble when/if we encounter code like:
2436
2437 #pragma interface
2438 struct S { virtual void member (); };
2439
2440 because the artificial declaration of the vtable itself (as
2441 manufactured by the g++ front end) will say that the vtable
2442 is a static member of `S' but only *after* the debug output
2443 for the definition of `S' has already been output. This causes
2444 grief because the DWARF entry for the definition of the vtable
2445 will try to refer back to an earlier *declaration* of the
2446 vtable as a static member of `S' and there won't be one.
2447 We might be able to arrange to have the "vtable static member"
2448 attached to the member list for `S' before the debug info for
2449 `S' get written (which would solve the problem) but that would
2450 require more intrusive changes to the g++ front end. */
2451
2452 DECL_IGNORED_P (vars) = 1;
2453 }
2454#endif /* DWARF_DEBUGGING_INFO */
2455
311862c8 2456 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
8d08fdba 2457 }
8926095f 2458 else if (TREE_USED (vars) && flag_vtable_thunks)
51c184be 2459 assemble_external (vars);
8d08fdba
MS
2460 /* We know that PREV must be non-zero here. */
2461 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2462}
2463
2464void
2465walk_vtables (typedecl_fn, vardecl_fn)
2466 register void (*typedecl_fn)();
2467 register void (*vardecl_fn)();
2468{
2469 tree prev, vars;
2470
2471 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2472 {
2473 register tree type = TREE_TYPE (vars);
2474
2475 if (TREE_CODE (vars) == TYPE_DECL
2476 && type != error_mark_node
2477 && TYPE_LANG_SPECIFIC (type)
2478 && CLASSTYPE_VSIZE (type))
2479 {
2480 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2481 }
2482 else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2483 {
2484 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2485 }
2486 else
2487 prev = vars;
2488 }
2489}
2490
311862c8
GB
2491static void
2492finish_sigtable_vardecl (prev, vars)
2493 tree prev, vars;
2494{
2495 /* We don't need to mark sigtable entries as addressable here as is done
2496 for vtables. Since sigtables, unlike vtables, are always written out,
2497 that was already done in build_signature_table_constructor. */
2498
2499 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2500
2501 /* We know that PREV must be non-zero here. */
2502 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2503}
2504
2505void
2506walk_sigtables (typedecl_fn, vardecl_fn)
2507 register void (*typedecl_fn)();
2508 register void (*vardecl_fn)();
2509{
2510 tree prev, vars;
2511
2512 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2513 {
2514 register tree type = TREE_TYPE (vars);
2515
2516 if (TREE_CODE (vars) == TYPE_DECL
2517 && type != error_mark_node
2518 && IS_SIGNATURE (type))
2519 {
2520 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2521 }
2522 else if (TREE_CODE (vars) == VAR_DECL
2523 && TREE_TYPE (vars) != error_mark_node
2524 && IS_SIGNATURE (TREE_TYPE (vars)))
2525 {
2526 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2527 }
2528 else
2529 prev = vars;
2530 }
2531}
2532
8d08fdba
MS
2533extern int parse_time, varconst_time;
2534
2535#define TIMEVAR(VAR, BODY) \
2536do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2537
2538/* This routine is called from the last rule in yyparse ().
2539 Its job is to create all the code needed to initialize and
2540 destroy the global aggregates. We do the destruction
2541 first, since that way we only need to reverse the decls once. */
2542
2543void
2544finish_file ()
2545{
2546 extern int lineno;
2547 int start_time, this_time;
2548
2549 tree fnname;
2550 tree vars = static_aggregates;
2551 int needs_cleaning = 0, needs_messing_up = 0;
2552
8d2733ca
MS
2553 build_exception_table ();
2554
8d08fdba
MS
2555 if (flag_detailed_statistics)
2556 dump_tree_statistics ();
2557
2558 /* Bad parse errors. Just forget about it. */
2559 if (! global_bindings_p () || current_class_type)
2560 return;
2561
2562 start_time = get_run_time ();
2563
2564 /* Push into C language context, because that's all
2565 we'll need here. */
2566 push_lang_context (lang_name_c);
2567
2568 /* Set up the name of the file-level functions we may need. */
2569 /* Use a global object (which is already required to be unique over
2570 the program) rather than the file name (which imposes extra
2571 constraints). -- Raeburn@MIT.EDU, 10 Jan 1990. */
2572
2573 /* See if we really need the hassle. */
2574 while (vars && needs_cleaning == 0)
2575 {
2576 tree decl = TREE_VALUE (vars);
2577 tree type = TREE_TYPE (decl);
2578 if (TYPE_NEEDS_DESTRUCTOR (type))
2579 {
2580 needs_cleaning = 1;
2581 needs_messing_up = 1;
2582 break;
2583 }
2584 else
2585 needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
2586 vars = TREE_CHAIN (vars);
2587 }
2588 if (needs_cleaning == 0)
2589 goto mess_up;
2590
2591 /* Otherwise, GDB can get confused, because in only knows
2592 about source for LINENO-1 lines. */
2593 lineno -= 1;
2594
2595 fnname = get_file_function_name ('D');
2596 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2597 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2598 store_parm_decls ();
2599
2600 pushlevel (0);
2601 clear_last_expr ();
2602 push_momentary ();
2603 expand_start_bindings (0);
2604
2605 /* These must be done in backward order to destroy,
2606 in which they happen to be! */
2607 while (vars)
2608 {
2609 tree decl = TREE_VALUE (vars);
2610 tree type = TREE_TYPE (decl);
2611 tree temp = TREE_PURPOSE (vars);
2612
2613 if (TYPE_NEEDS_DESTRUCTOR (type))
2614 {
2615 if (TREE_STATIC (vars))
2616 expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node, 1), 0);
2617 if (TREE_CODE (type) == ARRAY_TYPE)
2618 temp = decl;
2619 else
2620 {
2621 mark_addressable (decl);
2622 temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
2623 }
2624 temp = build_delete (TREE_TYPE (temp), temp,
2625 integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2626 expand_expr_stmt (temp);
2627
2628 if (TREE_STATIC (vars))
2629 expand_end_cond ();
2630 }
2631 vars = TREE_CHAIN (vars);
2632 }
2633
2634 expand_end_bindings (getdecls(), 1, 0);
2635 poplevel (1, 0, 0);
2636 pop_momentary ();
2637
2638 finish_function (lineno, 0);
2639
2640 assemble_destructor (IDENTIFIER_POINTER (fnname));
2641
2642 /* if it needed cleaning, then it will need messing up: drop through */
2643
2644 mess_up:
2645 /* Must do this while we think we are at the top level. */
2646 vars = nreverse (static_aggregates);
2647 if (vars != NULL_TREE)
2648 {
2649 fnname = get_file_function_name ('I');
2650 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2651 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2652 store_parm_decls ();
2653
2654 pushlevel (0);
2655 clear_last_expr ();
2656 push_momentary ();
2657 expand_start_bindings (0);
2658
2659 while (vars)
2660 {
2661 tree decl = TREE_VALUE (vars);
2662 tree init = TREE_PURPOSE (vars);
a4443a08 2663 tree old_cleanups = cleanups_this_call;
8d08fdba
MS
2664
2665 /* If this was a static attribute within some function's scope,
2666 then don't initialize it here. Also, don't bother
2667 with initializers that contain errors. */
2668 if (TREE_STATIC (vars)
2669 || (init && TREE_CODE (init) == TREE_LIST
2670 && value_member (error_mark_node, init)))
2671 {
2672 vars = TREE_CHAIN (vars);
2673 continue;
2674 }
2675
2676 if (TREE_CODE (decl) == VAR_DECL)
2677 {
2678 /* Set these global variables so that GDB at least puts
2679 us near the declaration which required the initialization. */
2680 input_filename = DECL_SOURCE_FILE (decl);
2681 lineno = DECL_SOURCE_LINE (decl);
2682 emit_note (input_filename, lineno);
2683
7177d104
MS
2684 /* 9.5p5: The initializer of a static member of a class has
2685 the same acess rights as a member function. */
2686 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2687
8d08fdba
MS
2688 if (init)
2689 {
2690 if (TREE_CODE (init) == VAR_DECL)
2691 {
2692 /* This behavior results when there are
2693 multiple declarations of an aggregate,
2694 the last of which defines it. */
2695 if (DECL_RTL (init) == DECL_RTL (decl))
2696 {
2697 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node
2698 || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
2699 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE),
2700 199);
2701 init = DECL_INITIAL (init);
2702 if (TREE_CODE (init) == CONSTRUCTOR
2703 && CONSTRUCTOR_ELTS (init) == NULL_TREE)
2704 init = NULL_TREE;
2705 }
2706#if 0
2707 else if (TREE_TYPE (decl) == TREE_TYPE (init))
2708 {
2709#if 1
2710 my_friendly_abort (200);
2711#else
2712 /* point to real decl's rtl anyway. */
2713 DECL_RTL (init) = DECL_RTL (decl);
2714 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node,
2715 201);
2716 init = DECL_INITIAL (init);
2717#endif /* 1 */
2718 }
2719#endif /* 0 */
2720 }
2721 }
2722 if (IS_AGGR_TYPE (TREE_TYPE (decl))
8d08fdba 2723 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
7177d104 2724 expand_aggr_init (decl, init, 0);
8d08fdba
MS
2725 else if (TREE_CODE (init) == TREE_VEC)
2726 {
2727 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2728 TREE_VEC_ELT (init, 1),
2729 TREE_VEC_ELT (init, 2), 0),
2730 const0_rtx, VOIDmode, 0);
2731 free_temp_slots ();
2732 }
2733 else
2734 expand_assignment (decl, init, 0, 0);
7177d104
MS
2735
2736 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
8d08fdba
MS
2737 }
2738 else if (TREE_CODE (decl) == SAVE_EXPR)
2739 {
2740 if (! PARM_DECL_EXPR (decl))
2741 {
2742 /* a `new' expression at top level. */
2743 expand_expr (decl, const0_rtx, VOIDmode, 0);
2744 free_temp_slots ();
2745 expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0);
2746 }
2747 }
2748 else if (decl == error_mark_node)
2749 ;
2750 else my_friendly_abort (22);
2751 vars = TREE_CHAIN (vars);
a4443a08
MS
2752 /* Cleanup any temporaries needed for the initial value. */
2753 expand_cleanups_to (old_cleanups);
8d08fdba
MS
2754 }
2755
2756 expand_end_bindings (getdecls(), 1, 0);
2757 poplevel (1, 0, 0);
2758 pop_momentary ();
2759
2760 finish_function (lineno, 0);
2761 assemble_constructor (IDENTIFIER_POINTER (fnname));
2762 }
2763
2764 /* Done with C language context needs. */
2765 pop_lang_context ();
2766
2767 /* Now write out any static class variables (which may have since
2768 learned how to be initialized). */
2769 while (pending_statics)
2770 {
2771 tree decl = TREE_VALUE (pending_statics);
2772 if (TREE_USED (decl) == 1
2773 || TREE_READONLY (decl) == 0
2774 || DECL_INITIAL (decl) == 0)
2775 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
2776 pending_statics = TREE_CHAIN (pending_statics);
2777 }
2778
2779 this_time = get_run_time ();
2780 parse_time -= this_time - start_time;
2781 varconst_time += this_time - start_time;
2782
8d08fdba
MS
2783 start_time = get_run_time ();
2784
2785 /* Now delete from the chain of variables all virtual function tables.
2786 We output them all ourselves, because each will be treated specially. */
2787
2788#if 1
2789 /* The reason for pushing garbage onto the global_binding_level is to
2790 ensure that we can slice out _DECLs which pertain to virtual function
2791 tables. If the last thing pushed onto the global_binding_level was a
2792 virtual function table, then slicing it out would slice away all the
2793 decls (i.e., we lose the head of the chain).
2794
2795 There are several ways of getting the same effect, from changing the
2796 way that iterators over the chain treat the elements that pertain to
2797 virtual function tables, moving the implementation of this code to
51c184be 2798 decl.c (where we can manipulate global_binding_level directly),
8d08fdba
MS
2799 popping the garbage after pushing it and slicing away the vtable
2800 stuff, or just leaving it alone. */
2801
2802 /* Make last thing in global scope not be a virtual function table. */
2803#if 0 /* not yet, should get fixed properly later */
2804 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2805#else
2806 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2807#endif
2808 DECL_IGNORED_P (vars) = 1;
700f8a87 2809 SET_DECL_ARTIFICIAL (vars);
8d08fdba
MS
2810 pushdecl (vars);
2811#endif
2812
8926095f 2813 walk_vtables ((void (*)())0, finish_vtable_vardecl);
5b605f68
MS
2814 if (flag_handle_signatures)
2815 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
8926095f 2816
a0a33927
MS
2817 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2818 {
2819 if (TREE_CODE (vars) == THUNK_DECL)
2820 emit_thunk (vars);
2821 }
2822
9a0e77ba
JM
2823 {
2824 int reconsider = 0; /* More may be referenced; check again */
2825 tree delayed = NULL_TREE; /* These might be referenced later */
2826
2827 /* Now write out inline functions which had their addresses taken and
2828 which were not declared virtual and which were not declared `extern
2829 inline'. */
2830 while (saved_inlines)
2831 {
2832 tree decl = TREE_VALUE (saved_inlines);
2833 saved_inlines = TREE_CHAIN (saved_inlines);
2834 /* Redefinition of a member function can cause DECL_SAVED_INSNS to be
2835 0; don't crash. */
2836 if (TREE_ASM_WRITTEN (decl) || DECL_SAVED_INSNS (decl) == 0)
2837 continue;
2838 if (DECL_FUNCTION_MEMBER_P (decl) && !TREE_PUBLIC (decl))
2839 {
2840 tree ctype = DECL_CLASS_CONTEXT (decl);
2841 if (CLASSTYPE_INTERFACE_KNOWN (ctype))
2842 {
2843 TREE_PUBLIC (decl) = 1;
2844 DECL_EXTERNAL (decl)
2845 = (CLASSTYPE_INTERFACE_ONLY (ctype)
2846 || (DECL_INLINE (decl) && ! flag_implement_inlines));
2847 }
2848 }
2849 if (TREE_PUBLIC (decl)
2850 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2851 || flag_keep_inline_functions)
2852 {
2853 if (DECL_EXTERNAL (decl)
2854 || (DECL_IMPLICIT_INSTANTIATION (decl)
2855 && ! flag_implicit_templates))
2856 assemble_external (decl);
2857 else
2858 {
2859 reconsider = 1;
2860 temporary_allocation ();
2861 output_inline_function (decl);
2862 permanent_allocation (1);
2863 }
2864 }
2865 else if (TREE_USED (decl)
2866 || TREE_USED (DECL_ASSEMBLER_NAME (decl)))
2867 delayed = tree_cons (NULL_TREE, decl, delayed);
2868 }
2869
2870 if (reconsider && delayed)
2871 {
2872 while (reconsider)
2873 {
2874 tree place;
2875 reconsider = 0;
2876 for (place = delayed; place; place = TREE_CHAIN (place))
2877 {
2878 tree decl = TREE_VALUE (place);
2879 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2880 && ! TREE_ASM_WRITTEN (decl))
2881 {
2882 if (DECL_EXTERNAL (decl)
2883 || (DECL_IMPLICIT_INSTANTIATION (decl)
2884 && ! flag_implicit_templates))
2885 assemble_external (decl);
2886 else
2887 {
2888 reconsider = 1;
2889 temporary_allocation ();
2890 output_inline_function (decl);
2891 permanent_allocation (1);
2892 }
2893 }
2894 }
2895 }
2896 }
2897 }
8d08fdba
MS
2898
2899 if (write_virtuals == 2)
2900 {
2901 /* Now complain about an virtual function tables promised
2902 but not delivered. */
2903 while (pending_vtables)
2904 {
2905 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
2906 error ("virtual function table for `%s' not defined",
2907 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
2908 pending_vtables = TREE_CHAIN (pending_vtables);
2909 }
2910 }
2911
2fe204da 2912 permanent_allocation (1);
8d08fdba
MS
2913 this_time = get_run_time ();
2914 parse_time -= this_time - start_time;
2915 varconst_time += this_time - start_time;
2916
2917 if (flag_detailed_statistics)
2918 dump_time_statistics ();
2919}
51c184be
MS
2920
2921/* This is something of the form 'A()()()()()+1' that has turned out to be an
2922 expr. Since it was parsed like a type, we need to wade through and fix
2923 that. Unfortunately, since operator() is left-associative, we can't use
2924 tail recursion. In the above example, TYPE is `A', and DECL is
2925 `()()()()()'.
2926
2927 Maybe this shouldn't be recursive, but how often will it actually be
2928 used? (jason) */
2929tree
2930reparse_absdcl_as_expr (type, decl)
2931 tree type, decl;
2932{
2933 /* do build_functional_cast (type, NULL_TREE) at bottom */
2934 if (TREE_OPERAND (decl, 0) == NULL_TREE)
2935 return build_functional_cast (type, NULL_TREE);
2936
2937 /* recurse */
2938 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
2939
2940 decl = build_x_function_call (decl, NULL_TREE, current_class_decl);
2941
2942 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
2943 decl = require_complete_type (decl);
2944
2945 return decl;
2946}
2947
2948/* This is something of the form `int ((int)(int)(int)1)' that has turned
2949 out to be an expr. Since it was parsed like a type, we need to wade
2950 through and fix that. Since casts are right-associative, we are
2951 reversing the order, so we don't have to recurse.
2952
2953 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
2954 `1'. */
2955tree
2956reparse_absdcl_as_casts (decl, expr)
2957 tree decl, expr;
2958{
2959 tree type;
2960
2961 if (TREE_CODE (expr) == CONSTRUCTOR)
2962 {
2963 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
2964 decl = TREE_OPERAND (decl, 0);
2965
2966 if (IS_SIGNATURE (type))
2967 {
2968 error ("cast specifies signature type");
2969 return error_mark_node;
2970 }
2971
2972 expr = digest_init (type, expr, (tree *) 0);
2973 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
2974 {
2975 int failure = complete_array_type (type, expr, 1);
2976 if (failure)
2977 my_friendly_abort (78);
2978 }
2979 }
2980
2981 while (decl)
2982 {
2983 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
2984 decl = TREE_OPERAND (decl, 0);
2985 expr = build_c_cast (type, expr);
2986 }
2987
2988 return expr;
2989}
2990
2991/* Recursive helper function for reparse_decl_as_expr. It may be a good
2992 idea to reimplement this using an explicit stack, rather than recursion. */
2993static tree
2994reparse_decl_as_expr1 (decl)
2995 tree decl;
2996{
2997 switch (TREE_CODE (decl))
2998 {
2999 case IDENTIFIER_NODE:
3000 return do_identifier (decl);
3001 case INDIRECT_REF:
3002 return build_x_indirect_ref
3003 (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)), "unary *");
3004 case ADDR_EXPR:
3005 return build_x_unary_op (ADDR_EXPR,
3006 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3007 case BIT_NOT_EXPR:
3008 return build_x_unary_op (BIT_NOT_EXPR,
3009 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
a28e3c7f
MS
3010 case SCOPE_REF:
3011 return build_offset_ref (TREE_OPERAND (decl, 0), TREE_OPERAND (decl, 1));
3012 case ARRAY_REF:
3013 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)),
3014 TREE_OPERAND (decl, 1));
8926095f
MS
3015 default:
3016 my_friendly_abort (5);
3017 return NULL_TREE;
51c184be 3018 }
51c184be
MS
3019}
3020
3021/* This is something of the form `int (*a)++' that has turned out to be an
3022 expr. It was only converted into parse nodes, so we need to go through
3023 and build up the semantics. Most of the work is done by
3024 reparse_decl_as_expr1, above.
3025
3026 In the above example, TYPE is `int' and DECL is `*a'. */
3027tree
3028reparse_decl_as_expr (type, decl)
3029 tree type, decl;
3030{
3031 decl = build_tree_list (NULL_TREE, reparse_decl_as_expr1 (decl));
3032 return build_functional_cast (type, decl);
3033}
3034
3035/* This is something of the form `int (*a)' that has turned out to be a
3036 decl. It was only converted into parse nodes, so we need to do the
3037 checking that make_{pointer,reference}_declarator do. */
3038
3039tree
3040finish_decl_parsing (decl)
3041 tree decl;
3042{
8926095f
MS
3043 extern int current_class_depth;
3044
51c184be
MS
3045 switch (TREE_CODE (decl))
3046 {
3047 case IDENTIFIER_NODE:
3048 return decl;
3049 case INDIRECT_REF:
3050 return make_pointer_declarator
3051 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3052 case ADDR_EXPR:
3053 return make_reference_declarator
3054 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3055 case BIT_NOT_EXPR:
3056 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3057 return decl;
8926095f 3058 case SCOPE_REF:
a4443a08 3059 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
8926095f
MS
3060 TREE_COMPLEXITY (decl) = current_class_depth;
3061 return decl;
a28e3c7f
MS
3062 case ARRAY_REF:
3063 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3064 return decl;
8926095f
MS
3065 default:
3066 my_friendly_abort (5);
3067 return NULL_TREE;
51c184be
MS
3068 }
3069}
2986ae00
MS
3070
3071tree
3072check_cp_case_value (value)
3073 tree value;
3074{
3075 if (value == NULL_TREE)
3076 return value;
3077
3078 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3079 Strip such NOP_EXPRs. */
3080 if (TREE_CODE (value) == NOP_EXPR
3081 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3082 value = TREE_OPERAND (value, 0);
3083
3084 if (TREE_READONLY_DECL_P (value))
3085 {
3086 value = decl_constant_value (value);
3087 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3088 Strip such NOP_EXPRs. */
3089 if (TREE_CODE (value) == NOP_EXPR
3090 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3091 value = TREE_OPERAND (value, 0);
3092 }
3093 value = fold (value);
3094
3095 if (TREE_CODE (value) != INTEGER_CST
3096 && value != error_mark_node)
3097 {
3098 cp_error ("case label `%E' does not reduce to an integer constant",
3099 value);
3100 value = error_mark_node;
3101 }
3102 else
3103 /* Promote char or short to int. */
3104 value = default_conversion (value);
3105
3106 constant_expression_warning (value);
3107
3108 return value;
3109}
This page took 0.361053 seconds and 5 git commands to generate.