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