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