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