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