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