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