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