]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/decl.c
class.c (grow_method): Remove check for redeclaration.
[gcc.git] / gcc / cp / decl.c
1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22
23 /* Process declarations and symbol lookup for C front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
26
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
29
30 #include "config.h"
31 #include <stdio.h>
32 #include "tree.h"
33 #include "rtl.h"
34 #include "flags.h"
35 #include "cp-tree.h"
36 #include "decl.h"
37 #include "lex.h"
38 #include <sys/types.h>
39 #include <signal.h>
40 #include "obstack.h"
41 #include "defaults.h"
42 #include "output.h"
43 #include "except.h"
44
45 #define obstack_chunk_alloc xmalloc
46 #define obstack_chunk_free free
47
48 extern tree builtin_return_address_fndecl;
49
50 extern struct obstack permanent_obstack;
51
52 extern int current_class_depth;
53
54 extern tree static_ctors, static_dtors;
55
56 extern int static_labelno;
57
58 /* Stack of places to restore the search obstack back to. */
59
60 /* Obstack used for remembering local class declarations (like
61 enums and static (const) members. */
62 #include "stack.h"
63 struct obstack decl_obstack;
64 static struct stack_level *decl_stack;
65
66 #ifndef CHAR_TYPE_SIZE
67 #define CHAR_TYPE_SIZE BITS_PER_UNIT
68 #endif
69
70 #ifndef SHORT_TYPE_SIZE
71 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
72 #endif
73
74 #ifndef INT_TYPE_SIZE
75 #define INT_TYPE_SIZE BITS_PER_WORD
76 #endif
77
78 #ifndef LONG_TYPE_SIZE
79 #define LONG_TYPE_SIZE BITS_PER_WORD
80 #endif
81
82 #ifndef LONG_LONG_TYPE_SIZE
83 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
84 #endif
85
86 #ifndef WCHAR_UNSIGNED
87 #define WCHAR_UNSIGNED 0
88 #endif
89
90 #ifndef FLOAT_TYPE_SIZE
91 #define FLOAT_TYPE_SIZE BITS_PER_WORD
92 #endif
93
94 #ifndef DOUBLE_TYPE_SIZE
95 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
96 #endif
97
98 #ifndef LONG_DOUBLE_TYPE_SIZE
99 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
100 #endif
101
102 #ifndef BOOL_TYPE_SIZE
103 #ifdef SLOW_BYTE_ACCESS
104 #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (POINTER_SIZE) : (CHAR_TYPE_SIZE))
105 #else
106 #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE
107 #endif
108 #endif
109
110 /* We let tm.h override the types used here, to handle trivial differences
111 such as the choice of unsigned int or long unsigned int for size_t.
112 When machines start needing nontrivial differences in the size type,
113 it would be best to do something here to figure out automatically
114 from other information what type to use. */
115
116 #ifndef SIZE_TYPE
117 #define SIZE_TYPE "long unsigned int"
118 #endif
119
120 #ifndef PTRDIFF_TYPE
121 #define PTRDIFF_TYPE "long int"
122 #endif
123
124 #ifndef WCHAR_TYPE
125 #define WCHAR_TYPE "int"
126 #endif
127
128 static tree grokparms PROTO((tree, int));
129 static tree lookup_nested_type PROTO((tree, tree));
130 static char *redeclaration_error_message PROTO((tree, tree));
131 static void revert_static_member_fn PROTO((tree *, tree *, tree *));
132 static tree push_overloaded_decl PROTO((tree, int));
133 static void push_overloaded_decl_top_level PROTO((tree, int));
134
135 static struct stack_level *push_decl_level PROTO((struct stack_level *,
136 struct obstack *));
137 static void push_binding_level PROTO((struct binding_level *, int,
138 int));
139 static void pop_binding_level PROTO((void));
140 static void suspend_binding_level PROTO((void));
141 static void resume_binding_level PROTO((struct binding_level *));
142 static struct binding_level *make_binding_level PROTO((void));
143 static int namespace_bindings_p PROTO((void));
144 static void declare_namespace_level PROTO((void));
145 static tree get_unique_name PROTO((void));
146 static void signal_catch PROTO((int));
147 static void storedecls PROTO((tree));
148 static void storetags PROTO((tree));
149 static void require_complete_types_for_parms PROTO((tree));
150 static void push_overloaded_decl_1 PROTO((tree));
151 static int ambi_op_p PROTO((tree));
152 static int unary_op_p PROTO((tree));
153 static tree store_bindings PROTO((tree, tree));
154 static tree lookup_tag_reverse PROTO((tree, tree));
155 static tree obscure_complex_init PROTO((tree, tree));
156 static tree maybe_build_cleanup_1 PROTO((tree, tree));
157 static tree lookup_name_real PROTO((tree, int, int));
158 static void warn_extern_redeclared_static PROTO((tree, tree));
159 static void grok_reference_init PROTO((tree, tree, tree, tree *));
160 static tree grokfndecl PROTO((tree, tree, tree, int,
161 enum overload_flags,
162 tree, tree, tree, int, int, int, int));
163 static tree grokvardecl PROTO((tree, tree, RID_BIT_TYPE *, int, int));
164 static tree lookup_tag PROTO((enum tree_code, tree,
165 struct binding_level *, int));
166 static void set_identifier_type_value_with_scope
167 PROTO((tree, tree, struct binding_level *));
168 static void record_builtin_type PROTO((enum rid, char *, tree));
169 static int member_function_or_else PROTO((tree, tree, char *));
170 static void bad_specifiers PROTO((tree, char *, int, int, int, int,
171 int));
172
173 /* a node which has tree code ERROR_MARK, and whose type is itself.
174 All erroneous expressions are replaced with this node. All functions
175 that accept nodes as arguments should avoid generating error messages
176 if this node is one of the arguments, since it is undesirable to get
177 multiple error messages from one error in the input. */
178
179 tree error_mark_node;
180
181 /* Erroneous argument lists can use this *IFF* they do not modify it. */
182 tree error_mark_list;
183
184 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
185
186 tree short_integer_type_node;
187 tree integer_type_node;
188 tree long_integer_type_node;
189 tree long_long_integer_type_node;
190
191 tree short_unsigned_type_node;
192 tree unsigned_type_node;
193 tree long_unsigned_type_node;
194 tree long_long_unsigned_type_node;
195
196 tree ptrdiff_type_node;
197
198 tree unsigned_char_type_node;
199 tree signed_char_type_node;
200 tree char_type_node;
201 tree wchar_type_node;
202 tree signed_wchar_type_node;
203 tree unsigned_wchar_type_node;
204
205 tree wchar_decl_node;
206
207 tree float_type_node;
208 tree double_type_node;
209 tree long_double_type_node;
210
211 tree complex_integer_type_node;
212 tree complex_float_type_node;
213 tree complex_double_type_node;
214 tree complex_long_double_type_node;
215
216 tree intQI_type_node;
217 tree intHI_type_node;
218 tree intSI_type_node;
219 tree intDI_type_node;
220
221 tree unsigned_intQI_type_node;
222 tree unsigned_intHI_type_node;
223 tree unsigned_intSI_type_node;
224 tree unsigned_intDI_type_node;
225
226 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
227
228 tree void_type_node, void_list_node;
229 tree void_zero_node;
230
231 /* Nodes for types `void *' and `const void *'. */
232
233 tree ptr_type_node;
234 static tree const_ptr_type_node;
235
236 /* Nodes for types `char *' and `const char *'. */
237
238 tree string_type_node, const_string_type_node;
239
240 /* Type `char[256]' or something like it.
241 Used when an array of char is needed and the size is irrelevant. */
242
243 tree char_array_type_node;
244
245 /* Type `int[256]' or something like it.
246 Used when an array of int needed and the size is irrelevant. */
247
248 tree int_array_type_node;
249
250 /* Type `wchar_t[256]' or something like it.
251 Used when a wide string literal is created. */
252
253 tree wchar_array_type_node;
254
255 /* The bool data type, and constants */
256 tree boolean_type_node, boolean_true_node, boolean_false_node;
257
258 /* type `int ()' -- used for implicit declaration of functions. */
259
260 tree default_function_type;
261
262 /* function types `double (double)' and `double (double, double)', etc. */
263
264 static tree double_ftype_double, double_ftype_double_double;
265 static tree int_ftype_int, long_ftype_long;
266 static tree float_ftype_float;
267 static tree ldouble_ftype_ldouble;
268
269 /* Function type `int (const void *, const void *, size_t)' */
270 static tree int_ftype_cptr_cptr_sizet;
271
272 /* C++ extensions */
273 tree vtable_entry_type;
274 tree delta_type_node;
275 #if 0
276 /* Old rtti stuff. */
277 tree __baselist_desc_type_node;
278 tree __i_desc_type_node, __m_desc_type_node;
279 tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
280 #endif
281 tree __t_desc_type_node;
282 #if 0
283 tree __tp_desc_type_node;
284 #endif
285 tree __access_mode_type_node;
286 tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node;
287 tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node;
288 tree __ptmf_desc_type_node, __ptmd_desc_type_node;
289 #if 0
290 /* Not needed yet? May be needed one day? */
291 tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type;
292 tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type;
293 tree __ptmf_desc_array_type, __ptmd_desc_array_type;
294 #endif
295
296 tree class_star_type_node;
297 tree class_type_node, record_type_node, union_type_node, enum_type_node;
298 tree unknown_type_node;
299 tree opaque_type_node, signature_type_node;
300 tree sigtable_entry_type;
301
302 /* Array type `vtable_entry_type[]' */
303 tree vtbl_type_node;
304
305 /* namespace std */
306 tree std_node;
307
308 /* In a destructor, the point at which all derived class destroying
309 has been done, just before any base class destroying will be done. */
310
311 tree dtor_label;
312
313 /* In a destructor, the last insn emitted after the start of the
314 function and the parms. */
315
316 static rtx last_dtor_insn;
317
318 /* In a constructor, the last insn emitted after the start of the
319 function and the parms, but before the start of the exception
320 specification. */
321
322 static rtx last_parm_cleanup_insn;
323
324 /* In a constructor, the point at which we are ready to return
325 the pointer to the initialized object. */
326
327 tree ctor_label;
328
329 /* A FUNCTION_DECL which can call `abort'. Not necessarily the
330 one that the user will declare, but sufficient to be called
331 by routines that want to abort the program. */
332
333 tree abort_fndecl;
334
335 extern rtx cleanup_label, return_label;
336
337 /* If original DECL_RESULT of current function was a register,
338 but due to being an addressable named return value, would up
339 on the stack, this variable holds the named return value's
340 original location. */
341 static rtx original_result_rtx;
342
343 /* Sequence of insns which represents base initialization. */
344 tree base_init_expr;
345
346 /* C++: Keep these around to reduce calls to `get_identifier'.
347 Identifiers for `this' in member functions and the auto-delete
348 parameter for destructors. */
349 tree this_identifier, in_charge_identifier;
350 tree ctor_identifier, dtor_identifier;
351 /* Used in pointer to member functions, in vtables, and in sigtables. */
352 tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
353 tree pfn_or_delta2_identifier, tag_identifier;
354 tree vt_off_identifier;
355
356 struct named_label_list
357 {
358 struct binding_level *binding_level;
359 tree names_in_scope;
360 tree label_decl;
361 char *filename_o_goto;
362 int lineno_o_goto;
363 struct named_label_list *next;
364 };
365
366 /* A list (chain of TREE_LIST nodes) of named label uses.
367 The TREE_PURPOSE field is the list of variables defined
368 the the label's scope defined at the point of use.
369 The TREE_VALUE field is the LABEL_DECL used.
370 The TREE_TYPE field holds `current_binding_level' at the
371 point of the label's use.
372
373 BWAHAHAAHAHahhahahahaah. No, no, no, said the little chicken.
374
375 Look at the pretty struct named_label_list. See the pretty struct
376 with the pretty named fields that describe what they do. See the
377 pretty lack of gratuitous casts. Notice the code got a lot cleaner.
378
379 Used only for jumps to as-yet undefined labels, since
380 jumps to defined labels can have their validity checked
381 by stmt.c. */
382
383 static struct named_label_list *named_label_uses = NULL;
384
385 /* A list of objects which have constructors or destructors
386 which reside in the global scope. The decl is stored in
387 the TREE_VALUE slot and the initializer is stored
388 in the TREE_PURPOSE slot. */
389 tree static_aggregates;
390
391 /* -- end of C++ */
392
393 /* Two expressions that are constants with value zero.
394 The first is of type `int', the second of type `void *'. */
395
396 tree integer_zero_node;
397 tree null_pointer_node;
398
399 /* The value for __null (NULL), either of type `void *' or, with -ansi,
400 an integer type of the same size. */
401
402 tree null_node;
403
404 /* A node for the integer constants 1, 2, and 3. */
405
406 tree integer_one_node, integer_two_node, integer_three_node;
407
408 /* While defining an enum type, this is 1 plus the last enumerator
409 constant value. */
410
411 static tree enum_next_value;
412
413 /* Nonzero means that there was overflow computing enum_next_value. */
414
415 static int enum_overflow;
416
417 /* Parsing a function declarator leaves a list of parameter names
418 or a chain or parameter decls here. */
419
420 tree last_function_parms;
421
422 /* Parsing a function declarator leaves here a chain of structure
423 and enum types declared in the parmlist. */
424
425 static tree last_function_parm_tags;
426
427 /* After parsing the declarator that starts a function definition,
428 `start_function' puts here the list of parameter names or chain of decls.
429 `store_parm_decls' finds it here. */
430
431 static tree current_function_parms;
432
433 /* Similar, for last_function_parm_tags. */
434 static tree current_function_parm_tags;
435
436 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
437 that have names. Here so we can clear out their names' definitions
438 at the end of the function. */
439
440 static tree named_labels;
441
442 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
443
444 static tree shadowed_labels;
445
446 /* The FUNCTION_DECL for the function currently being compiled,
447 or 0 if between functions. */
448 tree current_function_decl;
449
450 /* Set to 0 at beginning of a function definition, set to 1 if
451 a return statement that specifies a return value is seen. */
452
453 int current_function_returns_value;
454
455 /* Set to 0 at beginning of a function definition, set to 1 if
456 a return statement with no argument is seen. */
457
458 int current_function_returns_null;
459
460 /* Set to 0 at beginning of a function definition, and whenever
461 a label (case or named) is defined. Set to value of expression
462 returned from function when that value can be transformed into
463 a named return value. */
464
465 tree current_function_return_value;
466
467 /* Set to nonzero by `grokdeclarator' for a function
468 whose return type is defaulted, if warnings for this are desired. */
469
470 static int warn_about_return_type;
471
472 /* Nonzero means give `double' the same size as `float'. */
473
474 extern int flag_short_double;
475
476 /* Nonzero means don't recognize any builtin functions. */
477
478 extern int flag_no_builtin;
479
480 /* Nonzero means don't recognize the non-ANSI builtin functions.
481 -ansi sets this. */
482
483 extern int flag_no_nonansi_builtin;
484
485 /* Nonzero means enable obscure ANSI features and disable GNU extensions
486 that might cause ANSI-compliant code to be miscompiled. */
487
488 extern int flag_ansi;
489
490 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
491 objects. */
492 extern int flag_huge_objects;
493
494 /* Nonzero if we want to conserve space in the .o files. We do this
495 by putting uninitialized data and runtime initialized data into
496 .common instead of .data at the expense of not flagging multiple
497 definitions. */
498 extern int flag_conserve_space;
499
500 /* Pointers to the base and current top of the language name stack. */
501
502 extern tree *current_lang_base, *current_lang_stack;
503 \f
504 /* C and C++ flags are in decl2.c. */
505
506 /* Set to 0 at beginning of a constructor, set to 1
507 if that function does an allocation before referencing its
508 instance variable. */
509 static int current_function_assigns_this;
510 int current_function_just_assigned_this;
511
512 /* Set to 0 at beginning of a function. Set non-zero when
513 store_parm_decls is called. Don't call store_parm_decls
514 if this flag is non-zero! */
515 int current_function_parms_stored;
516
517 /* Flag used when debugging spew.c */
518
519 extern int spew_debug;
520
521 /* This is a copy of the class_shadowed list of the previous class binding
522 contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs
523 when entering another class scope (i.e. a cache miss). */
524 extern tree previous_class_values;
525
526 /* A expression of value 0 with the same precision as a sizetype
527 node, but signed. */
528 tree signed_size_zero_node;
529
530 \f
531 /* Allocate a level of searching. */
532
533 static
534 struct stack_level *
535 push_decl_level (stack, obstack)
536 struct stack_level *stack;
537 struct obstack *obstack;
538 {
539 struct stack_level tem;
540 tem.prev = stack;
541
542 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
543 }
544 \f
545 /* For each binding contour we allocate a binding_level structure
546 which records the names defined in that contour.
547 Contours include:
548 0) the global one
549 1) one for each function definition,
550 where internal declarations of the parameters appear.
551 2) one for each compound statement,
552 to record its declarations.
553
554 The current meaning of a name can be found by searching the levels
555 from the current one out to the global one.
556
557 Off to the side, may be the class_binding_level. This exists only
558 to catch class-local declarations. It is otherwise nonexistent.
559
560 Also there may be binding levels that catch cleanups that must be
561 run when exceptions occur. */
562
563 /* Note that the information in the `names' component of the global contour
564 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
565
566 struct binding_level
567 {
568 /* A chain of _DECL nodes for all variables, constants, functions,
569 and typedef types. These are in the reverse of the order
570 supplied. */
571 tree names;
572
573 /* A list of structure, union and enum definitions, for looking up
574 tag names.
575 It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
576 or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
577 or ENUMERAL_TYPE node.
578
579 C++: the TREE_VALUE nodes can be simple types for
580 component_bindings. */
581 tree tags;
582
583 /* For each level, a list of shadowed outer-level local definitions
584 to be restored when this level is popped.
585 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
586 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
587 tree shadowed;
588
589 /* Same, for IDENTIFIER_CLASS_VALUE. */
590 tree class_shadowed;
591
592 /* Same, for IDENTIFIER_TYPE_VALUE. */
593 tree type_shadowed;
594
595 /* For each level (except not the global one),
596 a chain of BLOCK nodes for all the levels
597 that were entered and exited one level down. */
598 tree blocks;
599
600 /* The BLOCK node for this level, if one has been preallocated.
601 If 0, the BLOCK is allocated (if needed) when the level is popped. */
602 tree this_block;
603
604 /* The binding level which this one is contained in (inherits from). */
605 struct binding_level *level_chain;
606
607 /* List of decls in `names' that have incomplete
608 structure or union types. */
609 tree incomplete;
610
611 /* List of VAR_DECLS saved from a previous for statement.
612 These would be dead in ANSI-conforming code, but might
613 be referenced in ARM-era code. */
614 tree dead_vars_from_for;
615
616 /* 1 for the level that holds the parameters of a function.
617 2 for the level that holds a class declaration.
618 3 for levels that hold parameter declarations. */
619 unsigned parm_flag : 4;
620
621 /* 1 means make a BLOCK for this level regardless of all else.
622 2 for temporary binding contours created by the compiler. */
623 unsigned keep : 3;
624
625 /* Nonzero if this level "doesn't exist" for tags. */
626 unsigned tag_transparent : 1;
627
628 /* Nonzero if this level can safely have additional
629 cleanup-needing variables added to it. */
630 unsigned more_cleanups_ok : 1;
631 unsigned have_cleanups : 1;
632
633 /* Nonzero if this level is for storing the decls for template
634 parameters and generic decls; these decls will be discarded and
635 replaced with a TEMPLATE_DECL. */
636 unsigned pseudo_global : 1;
637
638 /* This is set for a namespace binding level. */
639 unsigned namespace_p : 1;
640
641 /* True if this level is that of a for-statement where we need to
642 worry about ambiguous (ARM or ANSI) scope rules. */
643 unsigned is_for_scope : 1;
644
645 /* Two bits left for this word. */
646
647 #if defined(DEBUG_CP_BINDING_LEVELS)
648 /* Binding depth at which this level began. */
649 unsigned binding_depth;
650 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
651 };
652
653 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
654
655 /* The (non-class) binding level currently in effect. */
656
657 static struct binding_level *current_binding_level;
658
659 /* The binding level of the current class, if any. */
660
661 static struct binding_level *class_binding_level;
662
663 /* The current (class or non-class) binding level currently in effect. */
664
665 #define inner_binding_level \
666 (class_binding_level ? class_binding_level : current_binding_level)
667
668 /* A chain of binding_level structures awaiting reuse. */
669
670 static struct binding_level *free_binding_level;
671
672 /* The outermost binding level, for names of file scope.
673 This is created when the compiler is started and exists
674 through the entire run. */
675
676 static struct binding_level *global_binding_level;
677
678 /* Binding level structures are initialized by copying this one. */
679
680 static struct binding_level clear_binding_level;
681
682 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
683
684 static int keep_next_level_flag;
685
686 #if defined(DEBUG_CP_BINDING_LEVELS)
687 static int binding_depth = 0;
688 static int is_class_level = 0;
689
690 static void
691 indent ()
692 {
693 register unsigned i;
694
695 for (i = 0; i < binding_depth*2; i++)
696 putc (' ', stderr);
697 }
698 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
699
700 static tree pushdecl_with_scope PROTO((tree, struct binding_level *));
701
702 static void
703 push_binding_level (newlevel, tag_transparent, keep)
704 struct binding_level *newlevel;
705 int tag_transparent, keep;
706 {
707 /* Add this level to the front of the chain (stack) of levels that
708 are active. */
709 *newlevel = clear_binding_level;
710 if (class_binding_level)
711 {
712 newlevel->level_chain = class_binding_level;
713 class_binding_level = (struct binding_level *)0;
714 }
715 else
716 {
717 newlevel->level_chain = current_binding_level;
718 }
719 current_binding_level = newlevel;
720 newlevel->tag_transparent = tag_transparent;
721 newlevel->more_cleanups_ok = 1;
722 newlevel->keep = keep;
723 #if defined(DEBUG_CP_BINDING_LEVELS)
724 newlevel->binding_depth = binding_depth;
725 indent ();
726 fprintf (stderr, "push %s level 0x%08x line %d\n",
727 (is_class_level) ? "class" : "block", newlevel, lineno);
728 is_class_level = 0;
729 binding_depth++;
730 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
731 }
732
733 static void
734 pop_binding_level ()
735 {
736 if (class_binding_level)
737 current_binding_level = class_binding_level;
738
739 if (global_binding_level)
740 {
741 /* cannot pop a level, if there are none left to pop. */
742 if (current_binding_level == global_binding_level)
743 my_friendly_abort (123);
744 }
745 /* Pop the current level, and free the structure for reuse. */
746 #if defined(DEBUG_CP_BINDING_LEVELS)
747 binding_depth--;
748 indent ();
749 fprintf (stderr, "pop %s level 0x%08x line %d\n",
750 (is_class_level) ? "class" : "block",
751 current_binding_level, lineno);
752 if (is_class_level != (current_binding_level == class_binding_level))
753 {
754 indent ();
755 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
756 }
757 is_class_level = 0;
758 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
759 {
760 register struct binding_level *level = current_binding_level;
761 current_binding_level = current_binding_level->level_chain;
762 level->level_chain = free_binding_level;
763 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
764 if (level->binding_depth != binding_depth)
765 abort ();
766 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
767 free_binding_level = level;
768
769 class_binding_level = current_binding_level;
770 if (class_binding_level->parm_flag != 2)
771 class_binding_level = 0;
772 while (current_binding_level->parm_flag == 2)
773 current_binding_level = current_binding_level->level_chain;
774 }
775 }
776
777 static void
778 suspend_binding_level ()
779 {
780 if (class_binding_level)
781 current_binding_level = class_binding_level;
782
783 if (global_binding_level)
784 {
785 /* cannot suspend a level, if there are none left to suspend. */
786 if (current_binding_level == global_binding_level)
787 my_friendly_abort (123);
788 }
789 /* Suspend the current level. */
790 #if defined(DEBUG_CP_BINDING_LEVELS)
791 binding_depth--;
792 indent ();
793 fprintf (stderr, "suspend %s level 0x%08x line %d\n",
794 (is_class_level) ? "class" : "block",
795 current_binding_level, lineno);
796 if (is_class_level != (current_binding_level == class_binding_level))
797 {
798 indent ();
799 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
800 }
801 is_class_level = 0;
802 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
803 {
804 current_binding_level = current_binding_level->level_chain;
805 class_binding_level = current_binding_level;
806 if (class_binding_level->parm_flag != 2)
807 class_binding_level = 0;
808 while (current_binding_level->parm_flag == 2)
809 current_binding_level = current_binding_level->level_chain;
810 }
811 }
812
813 static void
814 resume_binding_level (b)
815 struct binding_level *b;
816 {
817 if (class_binding_level)
818 {
819 #if 1
820 /* These are here because we cannot deal with shadows yet. */
821 sorry ("cannot resume a namespace inside class");
822 return;
823 #else
824 b->level_chain = class_binding_level;
825 class_binding_level = (struct binding_level *)0;
826 #endif
827 }
828 else
829 {
830 #if 1
831 /* These are here because we cannot deal with shadows yet. */
832 if (b->level_chain != current_binding_level)
833 {
834 sorry ("cannot resume a namespace inside a different namespace");
835 return;
836 }
837 #endif
838 b->level_chain = current_binding_level;
839 }
840 current_binding_level = b;
841 #if defined(DEBUG_CP_BINDING_LEVELS)
842 b->binding_depth = binding_depth;
843 indent ();
844 fprintf (stderr, "resume %s level 0x%08x line %d\n",
845 (is_class_level) ? "class" : "block", b, lineno);
846 is_class_level = 0;
847 binding_depth++;
848 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
849 }
850 \f
851 /* Create a new `struct binding_level'. */
852
853 static
854 struct binding_level *
855 make_binding_level ()
856 {
857 /* NOSTRICT */
858 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
859 }
860
861 /* Nonzero if we are currently in the global binding level. */
862
863 int
864 global_bindings_p ()
865 {
866 return current_binding_level == global_binding_level;
867 }
868
869 /* Nonzero if we are currently in a toplevel binding level. This
870 means either the global binding level or a namespace in a toplevel
871 binding level. */
872
873 int
874 toplevel_bindings_p ()
875 {
876 struct binding_level *b = current_binding_level;
877
878 while (1)
879 {
880 if (b == global_binding_level)
881 return 1;
882 if (b->pseudo_global)
883 return 1;
884 if (! b->namespace_p)
885 return 0;
886 b=b->level_chain;
887 }
888 }
889
890 /* Nonzero if this is a namespace scope. */
891
892 static int
893 namespace_bindings_p ()
894 {
895 return current_binding_level->namespace_p;
896 }
897
898 void
899 keep_next_level ()
900 {
901 keep_next_level_flag = 1;
902 }
903
904 /* Nonzero if the current level needs to have a BLOCK made. */
905
906 int
907 kept_level_p ()
908 {
909 return (current_binding_level->blocks != NULL_TREE
910 || current_binding_level->keep
911 || current_binding_level->names != NULL_TREE
912 || (current_binding_level->tags != NULL_TREE
913 && !current_binding_level->tag_transparent));
914 }
915
916 /* Identify this binding level as a level of parameters. */
917
918 void
919 declare_parm_level ()
920 {
921 current_binding_level->parm_flag = 1;
922 }
923
924 void
925 declare_pseudo_global_level ()
926 {
927 current_binding_level->pseudo_global = 1;
928 }
929
930 static void
931 declare_namespace_level ()
932 {
933 current_binding_level->namespace_p = 1;
934 }
935
936 int
937 pseudo_global_level_p ()
938 {
939 return current_binding_level->pseudo_global;
940 }
941
942 void
943 set_class_shadows (shadows)
944 tree shadows;
945 {
946 class_binding_level->class_shadowed = shadows;
947 }
948
949 /* Enter a new binding level.
950 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
951 not for that of tags. */
952
953 void
954 pushlevel (tag_transparent)
955 int tag_transparent;
956 {
957 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
958
959 /* If this is the top level of a function,
960 just make sure that NAMED_LABELS is 0.
961 They should have been set to 0 at the end of the previous function. */
962
963 if (current_binding_level == global_binding_level)
964 my_friendly_assert (named_labels == NULL_TREE, 134);
965
966 /* Reuse or create a struct for this binding level. */
967
968 #if defined(DEBUG_CP_BINDING_LEVELS)
969 if (0)
970 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
971 if (free_binding_level)
972 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
973 {
974 newlevel = free_binding_level;
975 free_binding_level = free_binding_level->level_chain;
976 }
977 else
978 {
979 newlevel = make_binding_level ();
980 }
981
982 push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
983 GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
984 keep_next_level_flag = 0;
985 }
986
987 void
988 note_level_for_for ()
989 {
990 current_binding_level->is_for_scope = 1;
991 }
992
993 void
994 pushlevel_temporary (tag_transparent)
995 int tag_transparent;
996 {
997 pushlevel (tag_transparent);
998 current_binding_level->keep = 2;
999 clear_last_expr ();
1000
1001 /* Note we don't call push_momentary() here. Otherwise, it would cause
1002 cleanups to be allocated on the momentary obstack, and they will be
1003 overwritten by the next statement. */
1004
1005 expand_start_bindings (0);
1006 }
1007
1008 /* Exit a binding level.
1009 Pop the level off, and restore the state of the identifier-decl mappings
1010 that were in effect when this level was entered.
1011
1012 If KEEP == 1, this level had explicit declarations, so
1013 and create a "block" (a BLOCK node) for the level
1014 to record its declarations and subblocks for symbol table output.
1015
1016 If KEEP == 2, this level's subblocks go to the front,
1017 not the back of the current binding level. This happens,
1018 for instance, when code for constructors and destructors
1019 need to generate code at the end of a function which must
1020 be moved up to the front of the function.
1021
1022 If FUNCTIONBODY is nonzero, this level is the body of a function,
1023 so create a block as if KEEP were set and also clear out all
1024 label names.
1025
1026 If REVERSE is nonzero, reverse the order of decls before putting
1027 them into the BLOCK. */
1028
1029 tree
1030 poplevel (keep, reverse, functionbody)
1031 int keep;
1032 int reverse;
1033 int functionbody;
1034 {
1035 register tree link;
1036 /* The chain of decls was accumulated in reverse order.
1037 Put it into forward order, just for cleanliness. */
1038 tree decls;
1039 int tmp = functionbody;
1040 int real_functionbody = current_binding_level->keep == 2
1041 ? ((functionbody = 0), tmp) : functionbody;
1042 tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
1043 tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
1044 tree block = NULL_TREE;
1045 tree decl;
1046 int block_previously_created;
1047
1048 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
1049 (HOST_WIDE_INT) current_binding_level->level_chain,
1050 current_binding_level->parm_flag,
1051 current_binding_level->keep);
1052
1053 if (current_binding_level->keep == 1)
1054 keep = 1;
1055
1056 /* Get the decls in the order they were written.
1057 Usually current_binding_level->names is in reverse order.
1058 But parameter decls were previously put in forward order. */
1059
1060 if (reverse)
1061 current_binding_level->names
1062 = decls = nreverse (current_binding_level->names);
1063 else
1064 decls = current_binding_level->names;
1065
1066 /* Output any nested inline functions within this block
1067 if they weren't already output. */
1068
1069 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1070 if (TREE_CODE (decl) == FUNCTION_DECL
1071 && ! TREE_ASM_WRITTEN (decl)
1072 && DECL_INITIAL (decl) != NULL_TREE
1073 && TREE_ADDRESSABLE (decl)
1074 && decl_function_context (decl) == current_function_decl)
1075 {
1076 /* If this decl was copied from a file-scope decl
1077 on account of a block-scope extern decl,
1078 propagate TREE_ADDRESSABLE to the file-scope decl. */
1079 if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
1080 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1081 else
1082 {
1083 push_function_context ();
1084 output_inline_function (decl);
1085 pop_function_context ();
1086 }
1087 }
1088
1089 /* If there were any declarations or structure tags in that level,
1090 or if this level is a function body,
1091 create a BLOCK to record them for the life of this function. */
1092
1093 block = NULL_TREE;
1094 block_previously_created = (current_binding_level->this_block != NULL_TREE);
1095 if (block_previously_created)
1096 block = current_binding_level->this_block;
1097 else if (keep == 1 || functionbody)
1098 block = make_node (BLOCK);
1099 if (block != NULL_TREE)
1100 {
1101 if (block_previously_created)
1102 {
1103 if (decls || tags || subblocks)
1104 {
1105 if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block))
1106 {
1107 warning ("internal compiler error: debugging info corrupted");
1108 }
1109 BLOCK_VARS (block) = decls;
1110 BLOCK_TYPE_TAGS (block) = tags;
1111
1112 /* We can have previous subblocks and new subblocks when
1113 doing fixup_gotos with complex cleanups. We chain the new
1114 subblocks onto the end of any pre-existing subblocks. */
1115 BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block),
1116 subblocks);
1117 }
1118 /* If we created the block earlier on, and we are just
1119 diddling it now, then it already should have a proper
1120 BLOCK_END_NOTE value associated with it. */
1121 }
1122 else
1123 {
1124 BLOCK_VARS (block) = decls;
1125 BLOCK_TYPE_TAGS (block) = tags;
1126 BLOCK_SUBBLOCKS (block) = subblocks;
1127 /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */
1128 remember_end_note (block);
1129 }
1130 }
1131
1132 /* In each subblock, record that this is its superior. */
1133
1134 if (keep >= 0)
1135 for (link = subblocks; link; link = TREE_CHAIN (link))
1136 BLOCK_SUPERCONTEXT (link) = block;
1137
1138 /* Clear out the meanings of the local variables of this level. */
1139
1140 if (current_binding_level->is_for_scope && flag_new_for_scope == 1)
1141 {
1142 struct binding_level *outer = current_binding_level->level_chain;
1143 for (link = decls; link; link = TREE_CHAIN (link))
1144 {
1145 if (TREE_CODE (link) == VAR_DECL)
1146 DECL_DEAD_FOR_LOCAL (link) = 1;
1147 else
1148 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1149 }
1150
1151 /* Save declarations made in a 'for' statement so we can support pre-ANSI
1152 'for' scoping semantics. */
1153
1154 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1155 {
1156 tree id = TREE_PURPOSE (link);
1157 tree decl = IDENTIFIER_LOCAL_VALUE (id);
1158
1159 if (decl && DECL_DEAD_FOR_LOCAL (decl))
1160 {
1161 /* In this case keep the dead for-decl visible,
1162 but remember what (if anything) it shadowed. */
1163 DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link);
1164 TREE_CHAIN (decl) = outer->dead_vars_from_for;
1165 outer->dead_vars_from_for = decl;
1166 }
1167 else
1168 IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link);
1169 }
1170 }
1171 else /* Not special for scope. */
1172 {
1173 for (link = decls; link; link = TREE_CHAIN (link))
1174 {
1175 if (DECL_NAME (link) != NULL_TREE)
1176 {
1177 /* If the ident. was used or addressed via a local extern decl,
1178 don't forget that fact. */
1179 if (DECL_EXTERNAL (link))
1180 {
1181 if (TREE_USED (link))
1182 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1183 if (TREE_ADDRESSABLE (link))
1184 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1185 }
1186 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1187 }
1188 }
1189
1190 /* Restore all name-meanings of the outer levels
1191 that were shadowed by this level. */
1192
1193 for (link = current_binding_level->shadowed;
1194 link; link = TREE_CHAIN (link))
1195 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1196
1197 /* We first restore the regular decls and *then* the dead_vars_from_for
1198 to handle this case:
1199
1200 int i; // i#1
1201 {
1202 for (int i; ; ) { ...} // i#2
1203 int i; // i#3
1204 } // we are here
1205
1206 In this case, we want remove the binding for i#3, restoring
1207 that of i#2. Then we want to remove the binding for i#2,
1208 and restore that of i#1. */
1209
1210 link = current_binding_level->dead_vars_from_for;
1211 for (; link != NULL_TREE; link = TREE_CHAIN (link))
1212 {
1213 tree id = DECL_NAME (link);
1214 if (IDENTIFIER_LOCAL_VALUE (id) == link)
1215 IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link);
1216 }
1217
1218 for (link = current_binding_level->class_shadowed;
1219 link; link = TREE_CHAIN (link))
1220 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1221 for (link = current_binding_level->type_shadowed;
1222 link; link = TREE_CHAIN (link))
1223 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1224 }
1225
1226 /* If the level being exited is the top level of a function,
1227 check over all the labels. */
1228
1229 if (functionbody)
1230 {
1231 /* If this is the top level block of a function,
1232 the vars are the function's parameters.
1233 Don't leave them in the BLOCK because they are
1234 found in the FUNCTION_DECL instead. */
1235
1236 BLOCK_VARS (block) = 0;
1237
1238 /* Clear out the definitions of all label names,
1239 since their scopes end here. */
1240
1241 for (link = named_labels; link; link = TREE_CHAIN (link))
1242 {
1243 register tree label = TREE_VALUE (link);
1244
1245 if (DECL_INITIAL (label) == NULL_TREE)
1246 {
1247 cp_error_at ("label `%D' used but not defined", label);
1248 /* Avoid crashing later. */
1249 define_label (input_filename, 1, DECL_NAME (label));
1250 }
1251 else if (warn_unused && !TREE_USED (label))
1252 cp_warning_at ("label `%D' defined but not used", label);
1253 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
1254
1255 /* Put the labels into the "variables" of the
1256 top-level block, so debugger can see them. */
1257 TREE_CHAIN (label) = BLOCK_VARS (block);
1258 BLOCK_VARS (block) = label;
1259 }
1260
1261 named_labels = NULL_TREE;
1262 }
1263
1264 /* Any uses of undefined labels now operate under constraints
1265 of next binding contour. */
1266 {
1267 struct binding_level *level_chain;
1268 level_chain = current_binding_level->level_chain;
1269 if (level_chain)
1270 {
1271 struct named_label_list *labels;
1272 for (labels = named_label_uses; labels; labels = labels->next)
1273 if (labels->binding_level == current_binding_level)
1274 {
1275 labels->binding_level = level_chain;
1276 labels->names_in_scope = level_chain->names;
1277 }
1278 }
1279 }
1280
1281 tmp = current_binding_level->keep;
1282
1283 pop_binding_level ();
1284 if (functionbody)
1285 DECL_INITIAL (current_function_decl) = block;
1286 else if (block)
1287 {
1288 if (!block_previously_created)
1289 current_binding_level->blocks
1290 = chainon (current_binding_level->blocks, block);
1291 }
1292 /* If we did not make a block for the level just exited,
1293 any blocks made for inner levels
1294 (since they cannot be recorded as subblocks in that level)
1295 must be carried forward so they will later become subblocks
1296 of something else. */
1297 else if (subblocks)
1298 {
1299 if (keep == 2)
1300 current_binding_level->blocks
1301 = chainon (subblocks, current_binding_level->blocks);
1302 else
1303 current_binding_level->blocks
1304 = chainon (current_binding_level->blocks, subblocks);
1305 }
1306
1307 /* Take care of compiler's internal binding structures. */
1308 if (tmp == 2)
1309 {
1310 expand_end_bindings (getdecls (), keep, 1);
1311 /* Each and every BLOCK node created here in `poplevel' is important
1312 (e.g. for proper debugging information) so if we created one
1313 earlier, mark it as "used". */
1314 if (block)
1315 TREE_USED (block) = 1;
1316 block = poplevel (keep, reverse, real_functionbody);
1317 }
1318
1319 /* Each and every BLOCK node created here in `poplevel' is important
1320 (e.g. for proper debugging information) so if we created one
1321 earlier, mark it as "used". */
1322 if (block)
1323 TREE_USED (block) = 1;
1324 return block;
1325 }
1326
1327 /* Resume a binding level for a namespace. */
1328
1329 void
1330 resume_level (b)
1331 struct binding_level *b;
1332 {
1333 tree decls, link;
1334
1335 resume_binding_level (b);
1336
1337 /* Resume the variable caches. */
1338 decls = current_binding_level->names;
1339
1340 /* Restore the meanings of the local variables of this level. */
1341
1342 for (link = decls; link; link = TREE_CHAIN (link))
1343 {
1344 /* If it doesn't have a name, there is nothing left to do with it. */
1345 if (DECL_NAME (link) == NULL_TREE)
1346 continue;
1347
1348 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link;
1349
1350 /* If this is a TYPE_DECL, push it into the type value slot. */
1351 if (TREE_CODE (link) == TYPE_DECL)
1352 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link));
1353 }
1354 }
1355
1356 /* Delete the node BLOCK from the current binding level.
1357 This is used for the block inside a stmt expr ({...})
1358 so that the block can be reinserted where appropriate. */
1359
1360 void
1361 delete_block (block)
1362 tree block;
1363 {
1364 tree t;
1365 if (current_binding_level->blocks == block)
1366 current_binding_level->blocks = TREE_CHAIN (block);
1367 for (t = current_binding_level->blocks; t;)
1368 {
1369 if (TREE_CHAIN (t) == block)
1370 TREE_CHAIN (t) = TREE_CHAIN (block);
1371 else
1372 t = TREE_CHAIN (t);
1373 }
1374 TREE_CHAIN (block) = NULL_TREE;
1375 /* Clear TREE_USED which is always set by poplevel.
1376 The flag is set again if insert_block is called. */
1377 TREE_USED (block) = 0;
1378 }
1379
1380 /* Insert BLOCK at the end of the list of subblocks of the
1381 current binding level. This is used when a BIND_EXPR is expanded,
1382 to handle the BLOCK node inside the BIND_EXPR. */
1383
1384 void
1385 insert_block (block)
1386 tree block;
1387 {
1388 TREE_USED (block) = 1;
1389 current_binding_level->blocks
1390 = chainon (current_binding_level->blocks, block);
1391 }
1392
1393 /* Add BLOCK to the current list of blocks for this binding contour. */
1394
1395 void
1396 add_block_current_level (block)
1397 tree block;
1398 {
1399 current_binding_level->blocks
1400 = chainon (current_binding_level->blocks, block);
1401 }
1402
1403 /* Set the BLOCK node for the innermost scope
1404 (the one we are currently in). */
1405
1406 void
1407 set_block (block)
1408 register tree block;
1409 {
1410 current_binding_level->this_block = block;
1411 }
1412
1413 /* Do a pushlevel for class declarations. */
1414
1415 void
1416 pushlevel_class ()
1417 {
1418 register struct binding_level *newlevel;
1419
1420 /* Reuse or create a struct for this binding level. */
1421 #if defined(DEBUG_CP_BINDING_LEVELS)
1422 if (0)
1423 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1424 if (free_binding_level)
1425 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1426 {
1427 newlevel = free_binding_level;
1428 free_binding_level = free_binding_level->level_chain;
1429 }
1430 else
1431 {
1432 newlevel = make_binding_level ();
1433 }
1434
1435 #if defined(DEBUG_CP_BINDING_LEVELS)
1436 is_class_level = 1;
1437 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1438
1439 push_binding_level (newlevel, 0, 0);
1440
1441 decl_stack = push_decl_level (decl_stack, &decl_obstack);
1442 class_binding_level = current_binding_level;
1443 class_binding_level->parm_flag = 2;
1444 /* We have just pushed into a new binding level. Now, fake out the rest
1445 of the compiler. Set the `current_binding_level' back to point to
1446 the most closely containing non-class binding level. */
1447 do
1448 {
1449 current_binding_level = current_binding_level->level_chain;
1450 }
1451 while (current_binding_level->parm_flag == 2);
1452 }
1453
1454 /* ...and a poplevel for class declarations. FORCE is used to force
1455 clearing out of CLASS_VALUEs after a class definition. */
1456
1457 tree
1458 poplevel_class (force)
1459 int force;
1460 {
1461 register struct binding_level *level = class_binding_level;
1462 tree block = NULL_TREE;
1463 tree shadowed;
1464
1465 my_friendly_assert (level != 0, 354);
1466
1467 decl_stack = pop_stack_level (decl_stack);
1468 for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1469 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1470 /* If we're leaving a toplevel class, don't bother to do the setting
1471 of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot
1472 shouldn't even be used when current_class_type isn't set, and second,
1473 if we don't touch it here, we're able to use the cache effect if the
1474 next time we're entering a class scope, it is the same class. */
1475 if (current_class_depth != 1 || force)
1476 for (shadowed = level->class_shadowed;
1477 shadowed;
1478 shadowed = TREE_CHAIN (shadowed))
1479 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1480 else
1481 /* Remember to save what IDENTIFIER's were bound in this scope so we
1482 can recover from cache misses. */
1483 {
1484 previous_class_type = current_class_type;
1485 previous_class_values = class_binding_level->class_shadowed;
1486 }
1487 for (shadowed = level->type_shadowed;
1488 shadowed;
1489 shadowed = TREE_CHAIN (shadowed))
1490 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1491
1492 GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
1493 (HOST_WIDE_INT) class_binding_level->level_chain,
1494 class_binding_level->parm_flag,
1495 class_binding_level->keep);
1496
1497 if (class_binding_level->parm_flag != 2)
1498 class_binding_level = (struct binding_level *)0;
1499
1500 /* Now, pop out of the the binding level which we created up in the
1501 `pushlevel_class' routine. */
1502 #if defined(DEBUG_CP_BINDING_LEVELS)
1503 is_class_level = 1;
1504 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1505
1506 pop_binding_level ();
1507
1508 return block;
1509 }
1510 \f
1511 /* For debugging. */
1512 static int no_print_functions = 0;
1513 static int no_print_builtins = 0;
1514
1515 void
1516 print_binding_level (lvl)
1517 struct binding_level *lvl;
1518 {
1519 tree t;
1520 int i = 0, len;
1521 fprintf (stderr, " blocks=");
1522 fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
1523 fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
1524 list_length (lvl->incomplete), lvl->parm_flag, lvl->keep);
1525 if (lvl->tag_transparent)
1526 fprintf (stderr, " tag-transparent");
1527 if (lvl->more_cleanups_ok)
1528 fprintf (stderr, " more-cleanups-ok");
1529 if (lvl->have_cleanups)
1530 fprintf (stderr, " have-cleanups");
1531 fprintf (stderr, "\n");
1532 if (lvl->names)
1533 {
1534 fprintf (stderr, " names:\t");
1535 /* We can probably fit 3 names to a line? */
1536 for (t = lvl->names; t; t = TREE_CHAIN (t))
1537 {
1538 if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL))
1539 continue;
1540 if (no_print_builtins
1541 && (TREE_CODE (t) == TYPE_DECL)
1542 && (!strcmp (DECL_SOURCE_FILE (t),"<built-in>")))
1543 continue;
1544
1545 /* Function decls tend to have longer names. */
1546 if (TREE_CODE (t) == FUNCTION_DECL)
1547 len = 3;
1548 else
1549 len = 2;
1550 i += len;
1551 if (i > 6)
1552 {
1553 fprintf (stderr, "\n\t");
1554 i = len;
1555 }
1556 print_node_brief (stderr, "", t, 0);
1557 if (t == error_mark_node)
1558 break;
1559 }
1560 if (i)
1561 fprintf (stderr, "\n");
1562 }
1563 if (lvl->tags)
1564 {
1565 fprintf (stderr, " tags:\t");
1566 i = 0;
1567 for (t = lvl->tags; t; t = TREE_CHAIN (t))
1568 {
1569 if (TREE_PURPOSE (t) == NULL_TREE)
1570 len = 3;
1571 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1572 len = 2;
1573 else
1574 len = 4;
1575 i += len;
1576 if (i > 5)
1577 {
1578 fprintf (stderr, "\n\t");
1579 i = len;
1580 }
1581 if (TREE_PURPOSE (t) == NULL_TREE)
1582 {
1583 print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1584 fprintf (stderr, ">");
1585 }
1586 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1587 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1588 else
1589 {
1590 print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1591 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1592 fprintf (stderr, ">");
1593 }
1594 }
1595 if (i)
1596 fprintf (stderr, "\n");
1597 }
1598 if (lvl->shadowed)
1599 {
1600 fprintf (stderr, " shadowed:");
1601 for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1602 {
1603 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1604 }
1605 fprintf (stderr, "\n");
1606 }
1607 if (lvl->class_shadowed)
1608 {
1609 fprintf (stderr, " class-shadowed:");
1610 for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1611 {
1612 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1613 }
1614 fprintf (stderr, "\n");
1615 }
1616 if (lvl->type_shadowed)
1617 {
1618 fprintf (stderr, " type-shadowed:");
1619 for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1620 {
1621 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1622 }
1623 fprintf (stderr, "\n");
1624 }
1625 }
1626
1627 void
1628 print_other_binding_stack (stack)
1629 struct binding_level *stack;
1630 {
1631 struct binding_level *level;
1632 for (level = stack; level != global_binding_level; level = level->level_chain)
1633 {
1634 fprintf (stderr, "binding level ");
1635 fprintf (stderr, HOST_PTR_PRINTF, level);
1636 fprintf (stderr, "\n");
1637 print_binding_level (level);
1638 }
1639 }
1640
1641 void
1642 print_binding_stack ()
1643 {
1644 struct binding_level *b;
1645 fprintf (stderr, "current_binding_level=");
1646 fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
1647 fprintf (stderr, "\nclass_binding_level=");
1648 fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
1649 fprintf (stderr, "\nglobal_binding_level=");
1650 fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
1651 fprintf (stderr, "\n");
1652 if (class_binding_level)
1653 {
1654 for (b = class_binding_level; b; b = b->level_chain)
1655 if (b == current_binding_level)
1656 break;
1657 if (b)
1658 b = class_binding_level;
1659 else
1660 b = current_binding_level;
1661 }
1662 else
1663 b = current_binding_level;
1664 print_other_binding_stack (b);
1665 fprintf (stderr, "global:\n");
1666 print_binding_level (global_binding_level);
1667 }
1668
1669 extern char * first_global_object_name;
1670
1671 /* Get a unique name for each call to this routine for unnamed namespaces.
1672 Mostly copied from get_file_function_name. */
1673
1674 static tree
1675 get_unique_name ()
1676 {
1677 static int temp_name_counter = 0;
1678 char *buf;
1679 register char *p;
1680
1681 if (first_global_object_name)
1682 p = first_global_object_name;
1683 else if (main_input_filename)
1684 p = main_input_filename;
1685 else
1686 p = input_filename;
1687
1688 #define UNNAMED_NAMESPACE_FORMAT "__%s_%d"
1689
1690 buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p));
1691
1692 sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++);
1693
1694 /* Don't need to pull weird characters out of global names. */
1695 if (p != first_global_object_name)
1696 {
1697 for (p = buf+11; *p; p++)
1698 if (! ((*p >= '0' && *p <= '9')
1699 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
1700 || *p == '$'
1701 #endif
1702 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
1703 || *p == '.'
1704 #endif
1705 || (*p >= 'A' && *p <= 'Z')
1706 || (*p >= 'a' && *p <= 'z')))
1707 *p = '_';
1708 }
1709
1710 return get_identifier (buf);
1711 }
1712
1713 /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we
1714 select a name that is unique to this compilation unit. */
1715
1716 void
1717 push_namespace (name)
1718 tree name;
1719 {
1720 #if 1
1721 static int warned;
1722 if (! warned)
1723 sorry ("namespace");
1724
1725 warned = 1;
1726 #else
1727 extern tree current_namespace;
1728 tree old_id = get_namespace_id ();
1729 char *buf;
1730 tree d;
1731
1732 if (! name)
1733 {
1734 /* Create a truly ugly name! */
1735 name = get_unique_name ();
1736 }
1737
1738 d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
1739
1740 /* Mark them as external, so redeclaration_error_message doesn't think
1741 they are duplicates. */
1742
1743 DECL_EXTERNAL (d) = 1;
1744 d = pushdecl (d);
1745
1746 if (NAMESPACE_LEVEL (d) == 0)
1747 {
1748 /* This is new for this compilation unit. */
1749 pushlevel (0);
1750 declare_namespace_level ();
1751 NAMESPACE_LEVEL (d) = current_binding_level;
1752 }
1753 else
1754 resume_level (NAMESPACE_LEVEL (d));
1755
1756 /* This code is just is bit old now... */
1757 current_namespace = tree_cons (NULL_TREE, name, current_namespace);
1758 buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0)
1759 + IDENTIFIER_LENGTH (name));
1760 sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "",
1761 IDENTIFIER_POINTER (name));
1762 TREE_PURPOSE (current_namespace) = get_identifier (buf);
1763 #endif
1764 }
1765
1766 /* Pop from the scope of the current namespace. */
1767
1768 void
1769 pop_namespace ()
1770 {
1771 #if 0
1772 extern tree current_namespace;
1773 tree decls, link;
1774 current_namespace = TREE_CHAIN (current_namespace);
1775
1776 /* Just in case we get out of sync. */
1777 if (! namespace_bindings_p ())
1778 poplevel (0, 0, 0);
1779
1780 decls = current_binding_level->names;
1781
1782 /* Clear out the meanings of the local variables of this level. */
1783
1784 for (link = decls; link; link = TREE_CHAIN (link))
1785 {
1786 if (DECL_NAME (link) != NULL_TREE)
1787 {
1788 /* If the ident. was used or addressed via a local extern decl,
1789 don't forget that fact. */
1790 if (DECL_EXTERNAL (link))
1791 {
1792 if (TREE_USED (link))
1793 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1794 if (TREE_ADDRESSABLE (link))
1795 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1796 }
1797 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1798 }
1799 }
1800
1801 /* Restore all name-meanings of the outer levels
1802 that were shadowed by this level. */
1803
1804 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1805 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1806 for (link = current_binding_level->class_shadowed;
1807 link; link = TREE_CHAIN (link))
1808 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1809 for (link = current_binding_level->type_shadowed;
1810 link; link = TREE_CHAIN (link))
1811 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1812
1813 /* suspend a level. */
1814 suspend_binding_level ();
1815 #endif
1816 }
1817 \f
1818 /* Subroutines for reverting temporarily to top-level for instantiation
1819 of templates and such. We actually need to clear out the class- and
1820 local-value slots of all identifiers, so that only the global values
1821 are at all visible. Simply setting current_binding_level to the global
1822 scope isn't enough, because more binding levels may be pushed. */
1823 struct saved_scope {
1824 struct binding_level *old_binding_level;
1825 tree old_bindings;
1826 struct saved_scope *prev;
1827 tree class_name, class_type, function_decl;
1828 struct binding_level *class_bindings;
1829 tree *lang_base, *lang_stack, lang_name;
1830 int lang_stacksize;
1831 int minimal_parse_mode;
1832 tree last_function_parms;
1833 tree template_parms;
1834 HOST_WIDE_INT processing_template_decl;
1835 tree previous_class_type, previous_class_values;
1836 };
1837 static struct saved_scope *current_saved_scope;
1838
1839 static tree
1840 store_bindings (names, old_bindings)
1841 tree names, old_bindings;
1842 {
1843 tree t;
1844 for (t = names; t; t = TREE_CHAIN (t))
1845 {
1846 tree binding, t1, id;
1847
1848 if (TREE_CODE (t) == TREE_LIST)
1849 id = TREE_PURPOSE (t);
1850 else
1851 id = DECL_NAME (t);
1852
1853 if (!id
1854 || (!IDENTIFIER_LOCAL_VALUE (id)
1855 && !IDENTIFIER_CLASS_VALUE (id)))
1856 continue;
1857
1858 for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1859 if (TREE_VEC_ELT (t1, 0) == id)
1860 goto skip_it;
1861
1862 binding = make_tree_vec (4);
1863 if (id)
1864 {
1865 my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
1866 TREE_VEC_ELT (binding, 0) = id;
1867 TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1868 TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1869 TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1870 IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
1871 IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
1872 }
1873 TREE_CHAIN (binding) = old_bindings;
1874 old_bindings = binding;
1875 skip_it:
1876 ;
1877 }
1878 return old_bindings;
1879 }
1880
1881 void
1882 maybe_push_to_top_level (pseudo)
1883 int pseudo;
1884 {
1885 extern int current_lang_stacksize;
1886 struct saved_scope *s
1887 = (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1888 struct binding_level *b = inner_binding_level;
1889 tree old_bindings = NULL_TREE;
1890
1891 if (current_function_decl)
1892 push_cp_function_context (NULL_TREE);
1893
1894 if (previous_class_type)
1895 old_bindings = store_bindings (previous_class_values, old_bindings);
1896
1897 /* Have to include global_binding_level, because class-level decls
1898 aren't listed anywhere useful. */
1899 for (; b; b = b->level_chain)
1900 {
1901 tree t;
1902
1903 if (b == global_binding_level || (pseudo && b->pseudo_global))
1904 break;
1905
1906 old_bindings = store_bindings (b->names, old_bindings);
1907 /* We also need to check class_shadowed to save class-level type
1908 bindings, since pushclass doesn't fill in b->names. */
1909 if (b->parm_flag == 2)
1910 old_bindings = store_bindings (b->class_shadowed, old_bindings);
1911
1912 /* Unwind type-value slots back to top level. */
1913 for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1914 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1915 }
1916
1917 s->old_binding_level = current_binding_level;
1918 current_binding_level = b;
1919
1920 s->class_name = current_class_name;
1921 s->class_type = current_class_type;
1922 s->function_decl = current_function_decl;
1923 s->class_bindings = class_binding_level;
1924 s->lang_stack = current_lang_stack;
1925 s->lang_base = current_lang_base;
1926 s->lang_stacksize = current_lang_stacksize;
1927 s->lang_name = current_lang_name;
1928 s->minimal_parse_mode = minimal_parse_mode;
1929 s->last_function_parms = last_function_parms;
1930 s->template_parms = current_template_parms;
1931 s->processing_template_decl = processing_template_decl;
1932 s->previous_class_type = previous_class_type;
1933 s->previous_class_values = previous_class_values;
1934
1935 current_class_name = current_class_type = NULL_TREE;
1936 current_function_decl = NULL_TREE;
1937 class_binding_level = (struct binding_level *)0;
1938 current_lang_stacksize = 10;
1939 current_lang_stack = current_lang_base
1940 = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
1941 current_lang_name = lang_name_cplusplus;
1942 strict_prototype = strict_prototypes_lang_cplusplus;
1943 named_labels = NULL_TREE;
1944 minimal_parse_mode = 0;
1945 previous_class_type = previous_class_values = NULL_TREE;
1946 if (!pseudo)
1947 {
1948 current_template_parms = NULL_TREE;
1949 processing_template_decl = 0;
1950 }
1951
1952 s->prev = current_saved_scope;
1953 s->old_bindings = old_bindings;
1954 current_saved_scope = s;
1955
1956 push_obstacks (&permanent_obstack, &permanent_obstack);
1957 }
1958
1959 void
1960 push_to_top_level ()
1961 {
1962 maybe_push_to_top_level (0);
1963 }
1964
1965 void
1966 pop_from_top_level ()
1967 {
1968 extern int current_lang_stacksize;
1969 struct saved_scope *s = current_saved_scope;
1970 tree t;
1971
1972 /* Clear out class-level bindings cache. */
1973 if (previous_class_type)
1974 {
1975 popclass (-1);
1976 previous_class_type = NULL_TREE;
1977 }
1978
1979 pop_obstacks ();
1980
1981 current_binding_level = s->old_binding_level;
1982 current_saved_scope = s->prev;
1983 for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1984 {
1985 tree id = TREE_VEC_ELT (t, 0);
1986 if (id)
1987 {
1988 IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1989 IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1990 IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1991 }
1992 }
1993 current_class_name = s->class_name;
1994 current_class_type = s->class_type;
1995 current_function_decl = s->function_decl;
1996 class_binding_level = s->class_bindings;
1997 free (current_lang_base);
1998 current_lang_base = s->lang_base;
1999 current_lang_stack = s->lang_stack;
2000 current_lang_name = s->lang_name;
2001 current_lang_stacksize = s->lang_stacksize;
2002 if (current_lang_name == lang_name_cplusplus)
2003 strict_prototype = strict_prototypes_lang_cplusplus;
2004 else if (current_lang_name == lang_name_c)
2005 strict_prototype = strict_prototypes_lang_c;
2006 minimal_parse_mode = s->minimal_parse_mode;
2007 last_function_parms = s->last_function_parms;
2008 current_template_parms = s->template_parms;
2009 processing_template_decl = s->processing_template_decl;
2010 previous_class_type = s->previous_class_type;
2011 previous_class_values = s->previous_class_values;
2012
2013 free (s);
2014
2015 if (current_function_decl)
2016 pop_cp_function_context (NULL_TREE);
2017 }
2018 \f
2019 /* Push a definition of struct, union or enum tag "name".
2020 into binding_level "b". "type" should be the type node,
2021 We assume that the tag "name" is not already defined.
2022
2023 Note that the definition may really be just a forward reference.
2024 In that case, the TYPE_SIZE will be a NULL_TREE.
2025
2026 C++ gratuitously puts all these tags in the name space. */
2027
2028 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
2029 record the shadowed value for this binding contour. TYPE is
2030 the type that ID maps to. */
2031
2032 static void
2033 set_identifier_type_value_with_scope (id, type, b)
2034 tree id;
2035 tree type;
2036 struct binding_level *b;
2037 {
2038 if (b != global_binding_level)
2039 {
2040 tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
2041 b->type_shadowed
2042 = tree_cons (id, old_type_value, b->type_shadowed);
2043 }
2044 SET_IDENTIFIER_TYPE_VALUE (id, type);
2045 }
2046
2047 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
2048
2049 void
2050 set_identifier_type_value (id, type)
2051 tree id;
2052 tree type;
2053 {
2054 set_identifier_type_value_with_scope (id, type, inner_binding_level);
2055 }
2056
2057 /* Pop off extraneous binding levels left over due to syntax errors.
2058
2059 We don't pop past namespaces, as they might be valid. */
2060
2061 void
2062 pop_everything ()
2063 {
2064 #ifdef DEBUG_CP_BINDING_LEVELS
2065 fprintf (stderr, "XXX entering pop_everything ()\n");
2066 #endif
2067 while (! toplevel_bindings_p () && ! pseudo_global_level_p ())
2068 {
2069 if (class_binding_level)
2070 pop_nested_class (1);
2071 else
2072 poplevel (0, 0, 0);
2073 }
2074 #ifdef DEBUG_CP_BINDING_LEVELS
2075 fprintf (stderr, "XXX leaving pop_everything ()\n");
2076 #endif
2077 }
2078
2079 /* Push a tag name NAME for struct/class/union/enum type TYPE.
2080 Normally put into into the inner-most non-tag-transparent scope,
2081 but if GLOBALIZE is true, put it in the inner-most non-class scope.
2082 The latter is needed for implicit declarations. */
2083
2084 void
2085 pushtag (name, type, globalize)
2086 tree name, type;
2087 int globalize;
2088 {
2089 register struct binding_level *b;
2090 tree context = 0;
2091 tree c_decl = 0;
2092
2093 b = inner_binding_level;
2094 while (b->tag_transparent
2095 || (globalize && b->parm_flag == 2))
2096 b = b->level_chain;
2097
2098 if (toplevel_bindings_p ())
2099 b->tags = perm_tree_cons (name, type, b->tags);
2100 else
2101 b->tags = saveable_tree_cons (name, type, b->tags);
2102
2103 if (name)
2104 {
2105 context = type ? TYPE_CONTEXT (type) : NULL_TREE;
2106 if (! context && ! globalize)
2107 context = current_scope ();
2108 if (context)
2109 c_decl = TREE_CODE (context) == FUNCTION_DECL
2110 ? context : TYPE_MAIN_DECL (context);
2111
2112 /* Do C++ gratuitous typedefing. */
2113 if (IDENTIFIER_TYPE_VALUE (name) != type)
2114 {
2115 register tree d;
2116 int newdecl = 0;
2117
2118 if (b->parm_flag != 2
2119 || TYPE_SIZE (current_class_type) != NULL_TREE)
2120 {
2121 d = lookup_nested_type (type, c_decl);
2122
2123 if (d == NULL_TREE)
2124 {
2125 newdecl = 1;
2126 d = build_decl (TYPE_DECL, name, type);
2127 SET_DECL_ARTIFICIAL (d);
2128 set_identifier_type_value_with_scope (name, type, b);
2129 }
2130 else
2131 d = TYPE_MAIN_DECL (d);
2132
2133 TYPE_NAME (type) = d;
2134 DECL_CONTEXT (d) = context;
2135 if (! globalize && processing_template_decl && IS_AGGR_TYPE (type))
2136 push_template_decl (d);
2137
2138 if (b->parm_flag == 2)
2139 d = pushdecl_class_level (d);
2140 else
2141 d = pushdecl_with_scope (d, b);
2142 }
2143 else
2144 {
2145 /* Make nested declarations go into class-level scope. */
2146 newdecl = 1;
2147 d = build_decl (TYPE_DECL, name, type);
2148 SET_DECL_ARTIFICIAL (d);
2149 TYPE_NAME (type) = d;
2150 DECL_CONTEXT (d) = context;
2151 if (! globalize && processing_template_decl && IS_AGGR_TYPE (type))
2152 push_template_decl (d);
2153
2154 d = pushdecl_class_level (d);
2155 }
2156 if (newdecl)
2157 {
2158 if (ANON_AGGRNAME_P (name))
2159 DECL_IGNORED_P (d) = 1;
2160
2161 TYPE_CONTEXT (type) = DECL_CONTEXT (d);
2162 DECL_ASSEMBLER_NAME (d)
2163 = get_identifier (build_overload_name (type, 1, 1));
2164 }
2165 }
2166 if (b->parm_flag == 2)
2167 {
2168 TREE_NONLOCAL_FLAG (type) = 1;
2169 if (TYPE_SIZE (current_class_type) == NULL_TREE)
2170 CLASSTYPE_TAGS (current_class_type) = b->tags;
2171 }
2172 }
2173
2174 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2175 /* Use the canonical TYPE_DECL for this node. */
2176 TYPE_STUB_DECL (type) = TYPE_NAME (type);
2177 else
2178 {
2179 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
2180 will be the tagged type we just added to the current
2181 binding level. This fake NULL-named TYPE_DECL node helps
2182 dwarfout.c to know when it needs to output a
2183 representation of a tagged type, and it also gives us a
2184 convenient place to record the "scope start" address for
2185 the tagged type. */
2186
2187 tree d = build_decl (TYPE_DECL, NULL_TREE, type);
2188 TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
2189 }
2190 }
2191
2192 /* Counter used to create anonymous type names. */
2193
2194 static int anon_cnt = 0;
2195
2196 /* Return an IDENTIFIER which can be used as a name for
2197 anonymous structs and unions. */
2198
2199 tree
2200 make_anon_name ()
2201 {
2202 char buf[32];
2203
2204 sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
2205 return get_identifier (buf);
2206 }
2207
2208 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
2209 This keeps dbxout from getting confused. */
2210
2211 void
2212 clear_anon_tags ()
2213 {
2214 register struct binding_level *b;
2215 register tree tags;
2216 static int last_cnt = 0;
2217
2218 /* Fast out if no new anon names were declared. */
2219 if (last_cnt == anon_cnt)
2220 return;
2221
2222 b = current_binding_level;
2223 while (b->tag_transparent)
2224 b = b->level_chain;
2225 tags = b->tags;
2226 while (tags)
2227 {
2228 /* A NULL purpose means we have already processed all tags
2229 from here to the end of the list. */
2230 if (TREE_PURPOSE (tags) == NULL_TREE)
2231 break;
2232 if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
2233 TREE_PURPOSE (tags) = NULL_TREE;
2234 tags = TREE_CHAIN (tags);
2235 }
2236 last_cnt = anon_cnt;
2237 }
2238 \f
2239 /* Subroutine of duplicate_decls: return truthvalue of whether
2240 or not types of these decls match.
2241
2242 For C++, we must compare the parameter list so that `int' can match
2243 `int&' in a parameter position, but `int&' is not confused with
2244 `const int&'. */
2245
2246 int
2247 decls_match (newdecl, olddecl)
2248 tree newdecl, olddecl;
2249 {
2250 int types_match;
2251
2252 if (TREE_CODE (newdecl) == FUNCTION_DECL
2253 && TREE_CODE (olddecl) == FUNCTION_DECL)
2254 {
2255 tree f1 = TREE_TYPE (newdecl);
2256 tree f2 = TREE_TYPE (olddecl);
2257 tree p1 = TYPE_ARG_TYPES (f1);
2258 tree p2 = TYPE_ARG_TYPES (f2);
2259
2260 /* When we parse a static member function definition,
2261 we put together a FUNCTION_DECL which thinks its type
2262 is METHOD_TYPE. Change that to FUNCTION_TYPE, and
2263 proceed. */
2264 if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
2265 revert_static_member_fn (&newdecl, &f1, &p1);
2266 else if (TREE_CODE (f2) == METHOD_TYPE
2267 && DECL_STATIC_FUNCTION_P (newdecl))
2268 revert_static_member_fn (&olddecl, &f2, &p2);
2269
2270 /* Here we must take care of the case where new default
2271 parameters are specified. Also, warn if an old
2272 declaration becomes ambiguous because default
2273 parameters may cause the two to be ambiguous. */
2274 if (TREE_CODE (f1) != TREE_CODE (f2))
2275 {
2276 if (TREE_CODE (f1) == OFFSET_TYPE)
2277 cp_compiler_error ("`%D' redeclared as member function", newdecl);
2278 else
2279 cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
2280 return 0;
2281 }
2282
2283 if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1))
2284 {
2285 if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c
2286 && p2 == NULL_TREE)
2287 {
2288 types_match = self_promoting_args_p (p1);
2289 if (p1 == void_list_node)
2290 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
2291 }
2292 else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c
2293 && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE)
2294 {
2295 types_match = self_promoting_args_p (p2);
2296 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
2297 }
2298 else
2299 types_match = compparms (p1, p2, 3);
2300 }
2301 else
2302 types_match = 0;
2303 }
2304 else if (TREE_CODE (newdecl) == TEMPLATE_DECL
2305 && TREE_CODE (olddecl) == TEMPLATE_DECL)
2306 {
2307 tree newargs = DECL_TEMPLATE_PARMS (newdecl);
2308 tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
2309 int i;
2310
2311 /* Run through all the levels of template parmaters, checking
2312 that they match. */
2313 while (newargs && oldargs)
2314 {
2315 int len = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (newargs));
2316
2317 if (TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (oldargs)) != len)
2318 return 0;
2319
2320 for (i = 0; i < len; i++)
2321 {
2322 tree newarg =
2323 TREE_VALUE (TREE_VEC_ELT
2324 (INNERMOST_TEMPLATE_PARMS (newargs), i));
2325 tree oldarg =
2326 TREE_VALUE (TREE_VEC_ELT
2327 (INNERMOST_TEMPLATE_PARMS (oldargs), i));
2328 if (TREE_CODE (newarg) != TREE_CODE (oldarg))
2329 return 0;
2330 else if (TREE_CODE (newarg) == TYPE_DECL)
2331 /* continue */;
2332 else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
2333 return 0;
2334 }
2335 newargs = TREE_CHAIN (newargs);
2336 oldargs = TREE_CHAIN (oldargs);
2337 }
2338
2339 if ((newargs == NULL_TREE) != (oldargs == NULL_TREE))
2340 /* One declaration has more levels that the other. */
2341 return 0;
2342
2343 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
2344 types_match = 1;
2345 else
2346 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
2347 DECL_TEMPLATE_RESULT (newdecl));
2348 }
2349 else
2350 {
2351 if (TREE_TYPE (newdecl) == error_mark_node)
2352 types_match = TREE_TYPE (olddecl) == error_mark_node;
2353 else if (TREE_TYPE (olddecl) == NULL_TREE)
2354 types_match = TREE_TYPE (newdecl) == NULL_TREE;
2355 else if (TREE_TYPE (newdecl) == NULL_TREE)
2356 types_match = 0;
2357 /* Qualifiers must match, and they may be present on either, the type
2358 or the decl. */
2359 else if ((TREE_READONLY (newdecl)
2360 || TYPE_READONLY (TREE_TYPE (newdecl)))
2361 == (TREE_READONLY (olddecl)
2362 || TYPE_READONLY (TREE_TYPE (olddecl)))
2363 && (TREE_THIS_VOLATILE (newdecl)
2364 || TYPE_VOLATILE (TREE_TYPE (newdecl)))
2365 == (TREE_THIS_VOLATILE (olddecl)
2366 || TYPE_VOLATILE (TREE_TYPE (olddecl))))
2367 types_match = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (newdecl)),
2368 TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)), 1);
2369 else
2370 types_match = 0;
2371 }
2372
2373 return types_match;
2374 }
2375
2376 /* If NEWDECL is `static' and an `extern' was seen previously,
2377 warn about it. (OLDDECL may be NULL_TREE; NAME contains
2378 information about previous usage as an `extern'.)
2379
2380 Note that this does not apply to the C++ case of declaring
2381 a variable `extern const' and then later `const'.
2382
2383 Don't complain about built-in functions, since they are beyond
2384 the user's control. */
2385
2386 static void
2387 warn_extern_redeclared_static (newdecl, olddecl)
2388 tree newdecl, olddecl;
2389 {
2390 tree name;
2391
2392 static char *explicit_extern_static_warning
2393 = "`%D' was declared `extern' and later `static'";
2394 static char *implicit_extern_static_warning
2395 = "`%D' was declared implicitly `extern' and later `static'";
2396
2397 if (TREE_CODE (newdecl) == TYPE_DECL)
2398 return;
2399
2400 name = DECL_ASSEMBLER_NAME (newdecl);
2401 if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl))
2402 {
2403 /* It's okay to redeclare an ANSI built-in function as static,
2404 or to declare a non-ANSI built-in function as anything. */
2405 if (! (TREE_CODE (newdecl) == FUNCTION_DECL
2406 && olddecl != NULL_TREE
2407 && TREE_CODE (olddecl) == FUNCTION_DECL
2408 && (DECL_BUILT_IN (olddecl)
2409 || DECL_BUILT_IN_NONANSI (olddecl))))
2410 {
2411 cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
2412 ? implicit_extern_static_warning
2413 : explicit_extern_static_warning, newdecl);
2414 if (olddecl != NULL_TREE)
2415 cp_pedwarn_at ("previous declaration of `%D'", olddecl);
2416 }
2417 }
2418 }
2419
2420 /* Handle when a new declaration NEWDECL has the same name as an old
2421 one OLDDECL in the same binding contour. Prints an error message
2422 if appropriate.
2423
2424 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2425 Otherwise, return 0. */
2426
2427 int
2428 duplicate_decls (newdecl, olddecl)
2429 tree newdecl, olddecl;
2430 {
2431 extern struct obstack permanent_obstack;
2432 unsigned olddecl_uid = DECL_UID (olddecl);
2433 int olddecl_friend = 0, types_match = 0;
2434 int new_defines_function;
2435
2436 if (newdecl == olddecl)
2437 return 1;
2438
2439 if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd')
2440 DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl);
2441
2442 types_match = decls_match (newdecl, olddecl);
2443
2444 if (TREE_CODE (olddecl) != TREE_LIST)
2445 olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
2446
2447 /* If either the type of the new decl or the type of the old decl is an
2448 error_mark_node, then that implies that we have already issued an
2449 error (earlier) for some bogus type specification, and in that case,
2450 it is rather pointless to harass the user with yet more error message
2451 about the same declaration, so well just pretent the types match here. */
2452 if (TREE_TYPE (newdecl) == error_mark_node
2453 || TREE_TYPE (olddecl) == error_mark_node)
2454 types_match = 1;
2455
2456 if (TREE_CODE (olddecl) == FUNCTION_DECL
2457 && DECL_ARTIFICIAL (olddecl)
2458 && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
2459 {
2460 /* If you declare a built-in or predefined function name as static,
2461 the old definition is overridden, but optionally warn this was a
2462 bad choice of name. Ditto for overloads. */
2463 if (! DECL_PUBLIC (newdecl)
2464 || (TREE_CODE (newdecl) == FUNCTION_DECL
2465 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
2466 {
2467 if (warn_shadow)
2468 cp_warning ("shadowing %s function `%#D'",
2469 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
2470 olddecl);
2471 /* Discard the old built-in function. */
2472 return 0;
2473 }
2474 else if (! types_match)
2475 {
2476 if (TREE_CODE (newdecl) != FUNCTION_DECL)
2477 {
2478 /* If the built-in is not ansi, then programs can override
2479 it even globally without an error. */
2480 if (! DECL_BUILT_IN (olddecl))
2481 cp_warning ("library function `%#D' redeclared as non-function `%#D'",
2482 olddecl, newdecl);
2483 else
2484 {
2485 cp_error ("declaration of `%#D'", newdecl);
2486 cp_error ("conflicts with built-in declaration `%#D'",
2487 olddecl);
2488 }
2489 return 0;
2490 }
2491
2492 cp_warning ("declaration of `%#D'", newdecl);
2493 cp_warning ("conflicts with built-in declaration `%#D'",
2494 olddecl);
2495 }
2496 }
2497 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2498 {
2499 if ((TREE_CODE (newdecl) == FUNCTION_DECL
2500 && DECL_FUNCTION_TEMPLATE_P (olddecl))
2501 || (TREE_CODE (olddecl) == FUNCTION_DECL
2502 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
2503 return 0;
2504
2505 cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
2506 if (TREE_CODE (olddecl) == TREE_LIST)
2507 olddecl = TREE_VALUE (olddecl);
2508 cp_error_at ("previous declaration of `%#D'", olddecl);
2509
2510 /* New decl is completely inconsistent with the old one =>
2511 tell caller to replace the old one. */
2512
2513 return 0;
2514 }
2515 else if (!types_match)
2516 {
2517 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2518 {
2519 /* The name of a class template may not be declared to refer to
2520 any other template, class, function, object, namespace, value,
2521 or type in the same scope. */
2522 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
2523 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
2524 {
2525 cp_error ("declaration of template `%#D'", newdecl);
2526 cp_error_at ("conflicts with previous declaration `%#D'",
2527 olddecl);
2528 }
2529 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
2530 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
2531 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
2532 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))), 3))
2533 {
2534 cp_error ("new declaration `%#D'", newdecl);
2535 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
2536 }
2537 return 0;
2538 }
2539 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2540 {
2541 if (DECL_LANGUAGE (newdecl) == lang_c
2542 && DECL_LANGUAGE (olddecl) == lang_c)
2543 {
2544 cp_error ("declaration of C function `%#D' conflicts with",
2545 newdecl);
2546 cp_error_at ("previous declaration `%#D' here", olddecl);
2547 }
2548 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2549 TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3))
2550 {
2551 cp_error ("new declaration `%#D'", newdecl);
2552 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
2553 }
2554 else
2555 return 0;
2556 }
2557
2558 /* Already complained about this, so don't do so again. */
2559 else if (current_class_type == NULL_TREE
2560 || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
2561 {
2562 cp_error ("conflicting types for `%#D'", newdecl);
2563 cp_error_at ("previous declaration as `%#D'", olddecl);
2564 }
2565 }
2566 else
2567 {
2568 char *errmsg = redeclaration_error_message (newdecl, olddecl);
2569 if (errmsg)
2570 {
2571 cp_error (errmsg, newdecl);
2572 if (DECL_NAME (olddecl) != NULL_TREE)
2573 cp_error_at ((DECL_INITIAL (olddecl)
2574 && current_binding_level == global_binding_level)
2575 ? "`%#D' previously defined here"
2576 : "`%#D' previously declared here", olddecl);
2577 }
2578 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2579 && DECL_INITIAL (olddecl) != NULL_TREE
2580 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2581 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
2582 {
2583 /* Prototype decl follows defn w/o prototype. */
2584 cp_warning_at ("prototype for `%#D'", newdecl);
2585 cp_warning_at ("follows non-prototype definition here", olddecl);
2586 }
2587 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2588 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2589 {
2590 /* extern "C" int foo ();
2591 int foo () { bar (); }
2592 is OK. */
2593 if (current_lang_stack == current_lang_base)
2594 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2595 else
2596 {
2597 cp_error_at ("previous declaration of `%#D' with %L linkage",
2598 olddecl, DECL_LANGUAGE (olddecl));
2599 cp_error ("conflicts with new declaration with %L linkage",
2600 DECL_LANGUAGE (newdecl));
2601 }
2602 }
2603
2604 if (TREE_CODE (olddecl) == FUNCTION_DECL
2605 && ! DECL_USE_TEMPLATE (olddecl))
2606 {
2607 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2608 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
2609 int i = 1;
2610
2611 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
2612 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
2613
2614 for (; t1 && t1 != void_list_node;
2615 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
2616 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
2617 {
2618 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
2619 TREE_PURPOSE (t2)))
2620 {
2621 if (pedantic)
2622 {
2623 cp_pedwarn ("default argument given for parameter %d of `%#D'",
2624 i, newdecl);
2625 cp_pedwarn_at ("after previous specification in `%#D'",
2626 olddecl);
2627 }
2628 }
2629 else
2630 {
2631 cp_error ("default argument given for parameter %d of `%#D'",
2632 i, newdecl);
2633 cp_error_at ("after previous specification in `%#D'",
2634 olddecl);
2635 }
2636 }
2637
2638 if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl)
2639 && TREE_ADDRESSABLE (olddecl) && warn_inline)
2640 {
2641 cp_warning ("`%#D' was used before it was declared inline",
2642 newdecl);
2643 cp_warning_at ("previous non-inline declaration here",
2644 olddecl);
2645 }
2646 }
2647 /* These bits are logically part of the type for non-functions. */
2648 else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
2649 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))
2650 {
2651 cp_pedwarn ("type qualifiers for `%#D'", newdecl);
2652 cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl);
2653 }
2654 }
2655
2656 /* If new decl is `static' and an `extern' was seen previously,
2657 warn about it. */
2658 warn_extern_redeclared_static (newdecl, olddecl);
2659
2660 /* We have committed to returning 1 at this point. */
2661 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2662 {
2663 /* Now that functions must hold information normally held
2664 by field decls, there is extra work to do so that
2665 declaration information does not get destroyed during
2666 definition. */
2667 if (DECL_VINDEX (olddecl))
2668 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2669 if (DECL_CONTEXT (olddecl))
2670 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2671 if (DECL_CLASS_CONTEXT (olddecl))
2672 DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
2673 if (DECL_CHAIN (newdecl) == NULL_TREE)
2674 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2675 if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
2676 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2677 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
2678 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2679 DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl);
2680 }
2681
2682 /* Deal with C++: must preserve virtual function table size. */
2683 if (TREE_CODE (olddecl) == TYPE_DECL)
2684 {
2685 register tree newtype = TREE_TYPE (newdecl);
2686 register tree oldtype = TREE_TYPE (olddecl);
2687
2688 if (newtype != error_mark_node && oldtype != error_mark_node
2689 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2690 {
2691 CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
2692 CLASSTYPE_FRIEND_CLASSES (newtype)
2693 = CLASSTYPE_FRIEND_CLASSES (oldtype);
2694 }
2695 }
2696
2697 /* Special handling ensues if new decl is a function definition. */
2698 new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
2699 && DECL_INITIAL (newdecl) != NULL_TREE);
2700
2701 /* Optionally warn about more than one declaration for the same name,
2702 but don't warn about a function declaration followed by a definition. */
2703 if (warn_redundant_decls
2704 && ! DECL_ARTIFICIAL (olddecl)
2705 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2706 /* Don't warn about extern decl followed by (tentative) definition. */
2707 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
2708 {
2709 cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
2710 cp_warning_at ("previous declaration of `%D'", olddecl);
2711 }
2712
2713 /* Copy all the DECL_... slots specified in the new decl
2714 except for any that we copy here from the old type. */
2715
2716 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2717 {
2718 if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE)
2719 {
2720 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2721 DECL_TEMPLATE_RESULT (olddecl) = DECL_TEMPLATE_RESULT (newdecl);
2722 DECL_TEMPLATE_PARMS (olddecl) = DECL_TEMPLATE_PARMS (newdecl);
2723 }
2724 return 1;
2725 }
2726
2727 if (types_match)
2728 {
2729 /* Automatically handles default parameters. */
2730 tree oldtype = TREE_TYPE (olddecl);
2731 tree newtype;
2732
2733 /* Make sure we put the new type in the same obstack as the old one. */
2734 if (oldtype)
2735 push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
2736 else
2737 {
2738 push_obstacks_nochange ();
2739 end_temporary_allocation ();
2740 }
2741
2742 /* Merge the data types specified in the two decls. */
2743 newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2744
2745 if (TREE_CODE (newdecl) == VAR_DECL)
2746 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2747 /* Do this after calling `common_type' so that default
2748 parameters don't confuse us. */
2749 else if (TREE_CODE (newdecl) == FUNCTION_DECL
2750 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2751 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2752 {
2753 TREE_TYPE (newdecl) = build_exception_variant (newtype,
2754 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2755 TREE_TYPE (olddecl) = build_exception_variant (newtype,
2756 TYPE_RAISES_EXCEPTIONS (oldtype));
2757
2758 if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl))
2759 && flag_exceptions
2760 && ! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
2761 {
2762 cp_pedwarn ("declaration of `%D' throws different exceptions",
2763 newdecl);
2764 cp_pedwarn_at ("previous declaration here", olddecl);
2765 }
2766 }
2767 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2768
2769 /* Lay the type out, unless already done. */
2770 if (oldtype != TREE_TYPE (newdecl)
2771 && TREE_TYPE (newdecl) != error_mark_node
2772 && !(processing_template_decl && uses_template_parms (newdecl)))
2773 layout_type (TREE_TYPE (newdecl));
2774
2775 if ((TREE_CODE (newdecl) == VAR_DECL
2776 || TREE_CODE (newdecl) == PARM_DECL
2777 || TREE_CODE (newdecl) == RESULT_DECL
2778 || TREE_CODE (newdecl) == FIELD_DECL
2779 || TREE_CODE (newdecl) == TYPE_DECL)
2780 && !(processing_template_decl && uses_template_parms (newdecl)))
2781 layout_decl (newdecl, 0);
2782
2783 /* Merge the type qualifiers. */
2784 if (TREE_READONLY (newdecl))
2785 TREE_READONLY (olddecl) = 1;
2786 if (TREE_THIS_VOLATILE (newdecl))
2787 TREE_THIS_VOLATILE (olddecl) = 1;
2788
2789 /* Merge the initialization information. */
2790 if (DECL_INITIAL (newdecl) == NULL_TREE
2791 && DECL_INITIAL (olddecl) != NULL_TREE)
2792 {
2793 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2794 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
2795 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
2796 }
2797
2798 /* Merge the section attribute.
2799 We want to issue an error if the sections conflict but that must be
2800 done later in decl_attributes since we are called before attributes
2801 are assigned. */
2802 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
2803 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
2804
2805 /* Keep the old rtl since we can safely use it, unless it's the
2806 call to abort() used for abstract virtuals. */
2807 if ((DECL_LANG_SPECIFIC (olddecl)
2808 && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
2809 || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
2810 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2811
2812 pop_obstacks ();
2813 }
2814 /* If cannot merge, then use the new type and qualifiers,
2815 and don't preserve the old rtl. */
2816 else
2817 {
2818 /* Clean out any memory we had of the old declaration. */
2819 tree oldstatic = value_member (olddecl, static_aggregates);
2820 if (oldstatic)
2821 TREE_VALUE (oldstatic) = error_mark_node;
2822
2823 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2824 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2825 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2826 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2827 }
2828
2829 /* Merge the storage class information. */
2830 DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
2831 DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl);
2832 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2833 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
2834 if (! DECL_EXTERNAL (olddecl))
2835 DECL_EXTERNAL (newdecl) = 0;
2836
2837 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2838 DECL_C_STATIC (newdecl) |= DECL_C_STATIC (olddecl);
2839
2840 if (DECL_LANG_SPECIFIC (newdecl))
2841 {
2842 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
2843 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
2844 }
2845
2846 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2847 {
2848 DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl);
2849
2850 /* If either decl says `inline', this fn is inline, unless its
2851 definition was passed already. */
2852 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
2853 DECL_INLINE (olddecl) = 1;
2854 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2855
2856 if (! types_match)
2857 {
2858 DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl);
2859 DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl);
2860 DECL_RTL (olddecl) = DECL_RTL (newdecl);
2861 }
2862 if (! types_match || new_defines_function)
2863 {
2864 /* These need to be copied so that the names are available. */
2865 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2866 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2867 }
2868 if (new_defines_function)
2869 /* If defining a function declared with other language
2870 linkage, use the previously declared language linkage. */
2871 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2872 else
2873 {
2874 /* If redeclaring a builtin function, and not a definition,
2875 it stays built in. */
2876 if (DECL_BUILT_IN (olddecl))
2877 {
2878 DECL_BUILT_IN (newdecl) = 1;
2879 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2880 /* If we're keeping the built-in definition, keep the rtl,
2881 regardless of declaration matches. */
2882 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2883 }
2884 else
2885 DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2886
2887 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2888 if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
2889 /* Previously saved insns go together with
2890 the function's previous definition. */
2891 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2892 /* Don't clear out the arguments if we're redefining a function. */
2893 if (DECL_ARGUMENTS (olddecl))
2894 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2895 }
2896 if (DECL_LANG_SPECIFIC (olddecl))
2897 DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl);
2898 }
2899
2900 if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2901 {
2902 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
2903 }
2904
2905 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2906 {
2907 DECL_TEMPLATE_INSTANTIATIONS (newdecl)
2908 = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
2909 if (DECL_CHAIN (newdecl) == NULL_TREE)
2910 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2911 }
2912
2913 /* Now preserve various other info from the definition. */
2914 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2915 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2916 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2917 DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl);
2918
2919 /* Don't really know how much of the language-specific
2920 values we should copy from old to new. */
2921 if (DECL_LANG_SPECIFIC (olddecl))
2922 {
2923 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2924 DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
2925 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
2926 if (DECL_TEMPLATE_INFO (newdecl) == NULL_TREE)
2927 {
2928 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
2929 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
2930 }
2931 }
2932
2933 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2934 {
2935 int function_size;
2936 struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
2937 struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
2938
2939 function_size = sizeof (struct tree_decl);
2940
2941 bcopy ((char *) newdecl + sizeof (struct tree_common),
2942 (char *) olddecl + sizeof (struct tree_common),
2943 function_size - sizeof (struct tree_common));
2944
2945 /* Can we safely free the storage used by newdecl? */
2946
2947 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2948 & ~ obstack_alignment_mask (&permanent_obstack))
2949
2950 if ((char *)newdecl + ROUND (function_size)
2951 + ROUND (sizeof (struct lang_decl))
2952 == obstack_next_free (&permanent_obstack))
2953 {
2954 DECL_MAIN_VARIANT (newdecl) = olddecl;
2955 DECL_LANG_SPECIFIC (olddecl) = ol;
2956 bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
2957
2958 obstack_free (&permanent_obstack, newdecl);
2959 }
2960 else if (LANG_DECL_PERMANENT (ol) && ol != nl)
2961 {
2962 if (DECL_MAIN_VARIANT (olddecl) == olddecl)
2963 {
2964 /* Save these lang_decls that would otherwise be lost. */
2965 extern tree free_lang_decl_chain;
2966 tree free_lang_decl = (tree) ol;
2967
2968 if (DECL_LANG_SPECIFIC (olddecl) == ol)
2969 abort ();
2970
2971 TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
2972 free_lang_decl_chain = free_lang_decl;
2973 }
2974 else
2975 {
2976 /* Storage leak. */;
2977 }
2978 }
2979 }
2980 else
2981 {
2982 bcopy ((char *) newdecl + sizeof (struct tree_common),
2983 (char *) olddecl + sizeof (struct tree_common),
2984 sizeof (struct tree_decl) - sizeof (struct tree_common)
2985 + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
2986 }
2987
2988 DECL_UID (olddecl) = olddecl_uid;
2989 if (olddecl_friend)
2990 DECL_FRIEND_P (olddecl) = 1;
2991
2992 return 1;
2993 }
2994
2995 /* Record a decl-node X as belonging to the current lexical scope.
2996 Check for errors (such as an incompatible declaration for the same
2997 name already seen in the same scope).
2998
2999 Returns either X or an old decl for the same name.
3000 If an old decl is returned, it may have been smashed
3001 to agree with what X says. */
3002
3003 tree
3004 pushdecl (x)
3005 tree x;
3006 {
3007 register tree t;
3008 register tree name = DECL_ASSEMBLER_NAME (x);
3009 register struct binding_level *b = current_binding_level;
3010
3011 if (x != current_function_decl
3012 /* Don't change DECL_CONTEXT of virtual methods. */
3013 && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x))
3014 && ! DECL_CONTEXT (x))
3015 DECL_CONTEXT (x) = current_function_decl;
3016 /* A local declaration for a function doesn't constitute nesting. */
3017 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
3018 DECL_CONTEXT (x) = 0;
3019
3020 /* Type are looked up using the DECL_NAME, as that is what the rest of the
3021 compiler wants to use. */
3022 if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL
3023 || TREE_CODE (x) == NAMESPACE_DECL || TREE_CODE (x) == TEMPLATE_TYPE_PARM)
3024 name = DECL_NAME (x);
3025
3026 if (name)
3027 {
3028 #if 0
3029 /* Not needed...see below. */
3030 char *file;
3031 int line;
3032 #endif
3033
3034 t = lookup_name_current_level (name);
3035 if (t == error_mark_node)
3036 {
3037 /* error_mark_node is 0 for a while during initialization! */
3038 t = NULL_TREE;
3039 cp_error_at ("`%#D' used prior to declaration", x);
3040 }
3041
3042 else if (t != NULL_TREE)
3043 {
3044 #if 0
3045 /* This is turned off until I have time to do it right (bpk). */
3046 /* With the code below that uses it... */
3047 file = DECL_SOURCE_FILE (t);
3048 line = DECL_SOURCE_LINE (t);
3049 #endif
3050 if (TREE_CODE (t) == PARM_DECL)
3051 {
3052 if (DECL_CONTEXT (t) == NULL_TREE)
3053 fatal ("parse errors have confused me too much");
3054
3055 /* Check for duplicate params. */
3056 if (duplicate_decls (x, t))
3057 return t;
3058 }
3059 else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c)
3060 || DECL_FUNCTION_TEMPLATE_P (x))
3061 && is_overloaded_fn (t))
3062 /* don't do anything just yet */;
3063 else if (t == wchar_decl_node)
3064 {
3065 if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
3066 cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x));
3067
3068 /* Throw away the redeclaration. */
3069 return t;
3070 }
3071 else if (TREE_CODE (t) != TREE_CODE (x))
3072 {
3073 if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
3074 && TREE_CODE (x) != TYPE_DECL
3075 && ! (TREE_CODE (x) == TEMPLATE_DECL
3076 && TREE_CODE (DECL_TEMPLATE_RESULT (x)) == TYPE_DECL))
3077 || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
3078 && TREE_CODE (t) != TYPE_DECL
3079 && ! (TREE_CODE (t) == TEMPLATE_DECL
3080 && (TREE_CODE (DECL_TEMPLATE_RESULT (t))
3081 == TYPE_DECL))))
3082 {
3083 /* We do nothing special here, because C++ does such nasty
3084 things with TYPE_DECLs. Instead, just let the TYPE_DECL
3085 get shadowed, and know that if we need to find a TYPE_DECL
3086 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
3087 slot of the identifier. */
3088 ;
3089 }
3090 else if (duplicate_decls (x, t))
3091 return t;
3092 }
3093 else if (duplicate_decls (x, t))
3094 {
3095 #if 0
3096 /* This is turned off until I have time to do it right (bpk). */
3097
3098 /* Also warn if they did a prototype with `static' on it, but
3099 then later left the `static' off. */
3100 if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
3101 {
3102 if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
3103 return t;
3104
3105 if (extra_warnings)
3106 {
3107 cp_warning ("`static' missing from declaration of `%D'",
3108 t);
3109 warning_with_file_and_line (file, line,
3110 "previous declaration of `%s'",
3111 decl_as_string (t, 0));
3112 }
3113
3114 /* Now fix things so it'll do what they expect. */
3115 if (current_function_decl)
3116 TREE_PUBLIC (current_function_decl) = 0;
3117 }
3118 /* Due to interference in memory reclamation (X may be
3119 obstack-deallocated at this point), we must guard against
3120 one really special case. [jason: This should be handled
3121 by start_function] */
3122 if (current_function_decl == x)
3123 current_function_decl = t;
3124 #endif
3125 if (TREE_CODE (t) == TYPE_DECL)
3126 SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
3127 else if (TREE_CODE (t) == FUNCTION_DECL)
3128 check_default_args (t);
3129
3130 return t;
3131 }
3132 }
3133
3134 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
3135 {
3136 t = push_overloaded_decl (x, 1);
3137 if (t != x || DECL_LANGUAGE (x) == lang_c)
3138 return t;
3139 }
3140 else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_CONTEXT (x) == NULL_TREE)
3141 return push_overloaded_decl (x, 0);
3142
3143 /* If declaring a type as a typedef, and the type has no known
3144 typedef name, install this TYPE_DECL as its typedef name. */
3145 if (TREE_CODE (x) == TYPE_DECL)
3146 {
3147 tree type = TREE_TYPE (x);
3148 tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
3149
3150 if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
3151 {
3152 /* If these are different names, and we're at the global
3153 binding level, make two equivalent definitions. */
3154 name = x;
3155 if (global_bindings_p ())
3156 TYPE_NAME (type) = x;
3157 }
3158 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
3159
3160 if (type != error_mark_node
3161 && TYPE_NAME (type)
3162 && TYPE_IDENTIFIER (type))
3163 set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
3164 }
3165
3166 /* Multiple external decls of the same identifier ought to match.
3167
3168 We get warnings about inline functions where they are defined.
3169 We get warnings about other functions from push_overloaded_decl.
3170
3171 Avoid duplicate warnings where they are used. */
3172 if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
3173 {
3174 tree decl;
3175
3176 if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
3177 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
3178 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
3179 decl = IDENTIFIER_GLOBAL_VALUE (name);
3180 else
3181 decl = NULL_TREE;
3182
3183 if (decl
3184 /* If different sort of thing, we already gave an error. */
3185 && TREE_CODE (decl) == TREE_CODE (x)
3186 && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1))
3187 {
3188 cp_pedwarn ("type mismatch with previous external decl", x);
3189 cp_pedwarn_at ("previous external decl of `%#D'", decl);
3190 }
3191 }
3192
3193 /* This name is new in its binding level.
3194 Install the new declaration and return it. */
3195 if (b == global_binding_level)
3196 {
3197 /* Install a global value. */
3198
3199 /* If the first global decl has external linkage,
3200 warn if we later see static one. */
3201 if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x))
3202 TREE_PUBLIC (name) = 1;
3203
3204 /* Don't install an artificial TYPE_DECL if we already have
3205 another _DECL with that name. */
3206 if (TREE_CODE (x) != TYPE_DECL
3207 || t == NULL_TREE
3208 || ! DECL_ARTIFICIAL (x))
3209 IDENTIFIER_GLOBAL_VALUE (name) = x;
3210
3211 /* Don't forget if the function was used via an implicit decl. */
3212 if (IDENTIFIER_IMPLICIT_DECL (name)
3213 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
3214 TREE_USED (x) = 1;
3215
3216 /* Don't forget if its address was taken in that way. */
3217 if (IDENTIFIER_IMPLICIT_DECL (name)
3218 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
3219 TREE_ADDRESSABLE (x) = 1;
3220
3221 /* Warn about mismatches against previous implicit decl. */
3222 if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
3223 /* If this real decl matches the implicit, don't complain. */
3224 && ! (TREE_CODE (x) == FUNCTION_DECL
3225 && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
3226 cp_warning
3227 ("`%D' was previously implicitly declared to return `int'", x);
3228
3229 /* If new decl is `static' and an `extern' was seen previously,
3230 warn about it. */
3231 if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
3232 warn_extern_redeclared_static (x, t);
3233 }
3234 else
3235 {
3236 /* Here to install a non-global value. */
3237 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
3238 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
3239
3240 /* Don't install an artificial TYPE_DECL if we already have
3241 another _DECL with that name. */
3242 if (TREE_CODE (x) != TYPE_DECL
3243 || t == NULL_TREE
3244 || ! DECL_ARTIFICIAL (x))
3245 {
3246 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
3247 IDENTIFIER_LOCAL_VALUE (name) = x;
3248 }
3249
3250 /* If this is a TYPE_DECL, push it into the type value slot. */
3251 if (TREE_CODE (x) == TYPE_DECL)
3252 set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
3253
3254 /* Clear out any TYPE_DECL shadowed by a namespace so that
3255 we won't think this is a type. The C struct hack doesn't
3256 go through namespaces. */
3257 if (TREE_CODE (x) == NAMESPACE_DECL)
3258 set_identifier_type_value_with_scope (name, NULL_TREE, b);
3259
3260 /* If this is an extern function declaration, see if we
3261 have a global definition or declaration for the function. */
3262 if (oldlocal == NULL_TREE
3263 && DECL_EXTERNAL (x)
3264 && oldglobal != NULL_TREE
3265 && TREE_CODE (x) == FUNCTION_DECL
3266 && TREE_CODE (oldglobal) == FUNCTION_DECL)
3267 {
3268 /* We have one. Their types must agree. */
3269 if (decls_match (x, oldglobal))
3270 /* OK */;
3271 else
3272 {
3273 cp_warning ("extern declaration of `%#D' doesn't match", x);
3274 cp_warning_at ("global declaration `%#D'", oldglobal);
3275 }
3276 }
3277 /* If we have a local external declaration,
3278 and no file-scope declaration has yet been seen,
3279 then if we later have a file-scope decl it must not be static. */
3280 if (oldlocal == NULL_TREE
3281 && oldglobal == NULL_TREE
3282 && DECL_EXTERNAL (x)
3283 && TREE_PUBLIC (x))
3284 {
3285 TREE_PUBLIC (name) = 1;
3286 }
3287
3288 if (DECL_FROM_INLINE (x))
3289 /* Inline decls shadow nothing. */;
3290
3291 /* Warn if shadowing an argument at the top level of the body. */
3292 else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
3293 && TREE_CODE (oldlocal) == PARM_DECL
3294 && TREE_CODE (x) != PARM_DECL)
3295 {
3296 /* Go to where the parms should be and see if we
3297 find them there. */
3298 struct binding_level *b = current_binding_level->level_chain;
3299
3300 if (cleanup_label)
3301 b = b->level_chain;
3302
3303 /* ARM $8.3 */
3304 if (b->parm_flag == 1)
3305 cp_error ("declaration of `%#D' shadows a parameter", name);
3306 }
3307 else if (warn_shadow && oldlocal != NULL_TREE && b->is_for_scope
3308 && !DECL_DEAD_FOR_LOCAL (oldlocal))
3309 {
3310 warning ("variable `%s' shadows local",
3311 IDENTIFIER_POINTER (name));
3312 cp_warning_at (" this is the shadowed declaration", oldlocal);
3313 }
3314 /* Maybe warn if shadowing something else. */
3315 else if (warn_shadow && !DECL_EXTERNAL (x)
3316 /* No shadow warnings for internally generated vars. */
3317 && ! DECL_ARTIFICIAL (x)
3318 /* No shadow warnings for vars made for inlining. */
3319 && ! DECL_FROM_INLINE (x))
3320 {
3321 char *warnstring = NULL;
3322
3323 if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
3324 warnstring = "declaration of `%s' shadows a parameter";
3325 else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
3326 && current_class_ptr
3327 && !TREE_STATIC (name))
3328 warnstring = "declaration of `%s' shadows a member of `this'";
3329 else if (oldlocal != NULL_TREE)
3330 warnstring = "declaration of `%s' shadows previous local";
3331 else if (oldglobal != NULL_TREE)
3332 warnstring = "declaration of `%s' shadows global declaration";
3333
3334 if (warnstring)
3335 warning (warnstring, IDENTIFIER_POINTER (name));
3336 }
3337 }
3338
3339 if (TREE_CODE (x) == FUNCTION_DECL)
3340 check_default_args (x);
3341
3342 /* Keep count of variables in this level with incomplete type. */
3343 if (TREE_CODE (x) == VAR_DECL
3344 && TREE_TYPE (x) != error_mark_node
3345 && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
3346 && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
3347 /* RTTI TD entries are created while defining the type_info. */
3348 || (TYPE_LANG_SPECIFIC (TREE_TYPE (x))
3349 && TYPE_BEING_DEFINED (TREE_TYPE (x)))))
3350 b->incomplete = tree_cons (NULL_TREE, x, b->incomplete);
3351 }
3352
3353 /* Put decls on list in reverse order.
3354 We will reverse them later if necessary. */
3355 TREE_CHAIN (x) = b->names;
3356 b->names = x;
3357 if (! (b != global_binding_level || TREE_PERMANENT (x)))
3358 my_friendly_abort (124);
3359
3360 return x;
3361 }
3362
3363 /* Same as pushdecl, but define X in binding-level LEVEL. We rely on the
3364 caller to set DECL_CONTEXT properly. */
3365
3366 static tree
3367 pushdecl_with_scope (x, level)
3368 tree x;
3369 struct binding_level *level;
3370 {
3371 register struct binding_level *b = current_binding_level;
3372 tree function_decl = current_function_decl;
3373
3374 current_function_decl = NULL_TREE;
3375 current_binding_level = level;
3376 x = pushdecl (x);
3377 current_binding_level = b;
3378 current_function_decl = function_decl;
3379 return x;
3380 }
3381
3382 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
3383 if appropriate. */
3384
3385 tree
3386 pushdecl_top_level (x)
3387 tree x;
3388 {
3389 register struct binding_level *b = inner_binding_level;
3390 register tree t = pushdecl_with_scope (x, global_binding_level);
3391
3392 /* Now, the type_shadowed stack may screw us. Munge it so it does
3393 what we want. */
3394 if (TREE_CODE (x) == TYPE_DECL)
3395 {
3396 tree name = DECL_NAME (x);
3397 tree newval;
3398 tree *ptr = (tree *)0;
3399 for (; b != global_binding_level; b = b->level_chain)
3400 {
3401 tree shadowed = b->type_shadowed;
3402 for (; shadowed; shadowed = TREE_CHAIN (shadowed))
3403 if (TREE_PURPOSE (shadowed) == name)
3404 {
3405 ptr = &TREE_VALUE (shadowed);
3406 /* Can't break out of the loop here because sometimes
3407 a binding level will have duplicate bindings for
3408 PT names. It's gross, but I haven't time to fix it. */
3409 }
3410 }
3411 newval = TREE_TYPE (x);
3412 if (ptr == (tree *)0)
3413 {
3414 /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3415 up here if this is changed to an assertion. --KR */
3416 SET_IDENTIFIER_TYPE_VALUE (name, newval);
3417 }
3418 else
3419 {
3420 *ptr = newval;
3421 }
3422 }
3423 return t;
3424 }
3425
3426 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3427 if appropriate. */
3428
3429 static void
3430 push_overloaded_decl_top_level (x, forget)
3431 tree x;
3432 int forget;
3433 {
3434 struct binding_level *b = current_binding_level;
3435
3436 current_binding_level = global_binding_level;
3437 push_overloaded_decl (x, forget);
3438 current_binding_level = b;
3439 }
3440
3441 /* Make the declaration of X appear in CLASS scope. */
3442
3443 tree
3444 pushdecl_class_level (x)
3445 tree x;
3446 {
3447 /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3448 scope looks for the pre-mangled name. */
3449 register tree name = DECL_NAME (x);
3450
3451 if (name)
3452 {
3453 if (TYPE_BEING_DEFINED (current_class_type))
3454 {
3455 /* Check for inconsistent use of this name in the class body.
3456 Types, enums, and static vars are checked here; other
3457 members are checked in finish_struct. */
3458 tree icv = IDENTIFIER_CLASS_VALUE (name);
3459
3460 if (icv && icv != x
3461 /* Don't complain about inherited names. */
3462 && id_in_current_class (name)
3463 /* Or shadowed tags. */
3464 && !(TREE_CODE (icv) == TYPE_DECL
3465 && DECL_CONTEXT (icv) == current_class_type))
3466 {
3467 cp_error ("declaration of identifier `%D' as `%#D'", name, x);
3468 cp_error_at ("conflicts with previous use in class as `%#D'",
3469 icv);
3470 }
3471 }
3472
3473 push_class_level_binding (name, x);
3474 if (TREE_CODE (x) == TYPE_DECL)
3475 {
3476 set_identifier_type_value (name, TREE_TYPE (x));
3477 }
3478 }
3479 return x;
3480 }
3481
3482 #if 0
3483 /* This function is used to push the mangled decls for nested types into
3484 the appropriate scope. Previously pushdecl_top_level was used, but that
3485 is incorrect for members of local classes. */
3486
3487 void
3488 pushdecl_nonclass_level (x)
3489 tree x;
3490 {
3491 struct binding_level *b = current_binding_level;
3492
3493 my_friendly_assert (b->parm_flag != 2, 180);
3494
3495 #if 0
3496 /* Get out of template binding levels */
3497 while (b->pseudo_global)
3498 b = b->level_chain;
3499 #endif
3500
3501 pushdecl_with_scope (x, b);
3502 }
3503 #endif
3504
3505 /* Make the declaration(s) of X appear in CLASS scope
3506 under the name NAME. */
3507
3508 void
3509 push_class_level_binding (name, x)
3510 tree name;
3511 tree x;
3512 {
3513 /* The class_binding_level will be NULL if x is a template
3514 parameter name in a member template. */
3515 if (!class_binding_level)
3516 return;
3517
3518 if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
3519 && purpose_member (name, class_binding_level->class_shadowed))
3520 return;
3521
3522 maybe_push_cache_obstack ();
3523 class_binding_level->class_shadowed
3524 = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
3525 class_binding_level->class_shadowed);
3526 pop_obstacks ();
3527 IDENTIFIER_CLASS_VALUE (name) = x;
3528 obstack_ptr_grow (&decl_obstack, x);
3529 }
3530
3531 /* Tell caller how to interpret a TREE_LIST which contains
3532 chains of FUNCTION_DECLS. */
3533
3534 int
3535 overloaded_globals_p (list)
3536 tree list;
3537 {
3538 my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
3539
3540 /* Don't commit caller to seeing them as globals. */
3541 if (TREE_NONLOCAL_FLAG (list))
3542 return -1;
3543 /* Do commit caller to not seeing them as globals. */
3544 if (TREE_CODE (TREE_VALUE (list)) == TREE_LIST)
3545 return 0;
3546 /* Do commit caller to seeing them as globals. */
3547 return 1;
3548 }
3549
3550 /* DECL is a FUNCTION_DECL which may have other definitions already in
3551 place. We get around this by making the value of the identifier point
3552 to a list of all the things that want to be referenced by that name. It
3553 is then up to the users of that name to decide what to do with that
3554 list.
3555
3556 DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3557 slot. It is dealt with the same way.
3558
3559 The value returned may be a previous declaration if we guessed wrong
3560 about what language DECL should belong to (C or C++). Otherwise,
3561 it's always DECL (and never something that's not a _DECL). */
3562
3563 static tree
3564 push_overloaded_decl (decl, forgettable)
3565 tree decl;
3566 int forgettable;
3567 {
3568 tree orig_name = DECL_NAME (decl);
3569 tree old;
3570 int doing_global = (global_bindings_p () || ! forgettable);
3571
3572 if (doing_global)
3573 {
3574 old = IDENTIFIER_GLOBAL_VALUE (orig_name);
3575 if (old && TREE_CODE (old) == FUNCTION_DECL
3576 && DECL_ARTIFICIAL (old)
3577 && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
3578 {
3579 if (duplicate_decls (decl, old))
3580 return old;
3581 old = NULL_TREE;
3582 }
3583 }
3584 else
3585 {
3586 old = IDENTIFIER_LOCAL_VALUE (orig_name);
3587
3588 if (! purpose_member (orig_name, current_binding_level->shadowed))
3589 {
3590 current_binding_level->shadowed
3591 = tree_cons (orig_name, old, current_binding_level->shadowed);
3592 old = NULL_TREE;
3593 }
3594 }
3595
3596 if (old)
3597 {
3598 if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
3599 {
3600 tree t = TREE_TYPE (old);
3601 if (IS_AGGR_TYPE (t) && warn_shadow
3602 && (! DECL_IN_SYSTEM_HEADER (decl)
3603 || ! DECL_IN_SYSTEM_HEADER (old)))
3604 cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
3605 old = NULL_TREE;
3606 }
3607 else if (is_overloaded_fn (old))
3608 {
3609 tree tmp;
3610
3611 for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp))
3612 if (decl == tmp || duplicate_decls (decl, tmp))
3613 return tmp;
3614 }
3615 else
3616 {
3617 cp_error_at ("previous non-function declaration `%#D'", old);
3618 cp_error ("conflicts with function declaration `%#D'", decl);
3619 return decl;
3620 }
3621 }
3622
3623 if (old || TREE_CODE (decl) == TEMPLATE_DECL)
3624 {
3625 if (old && is_overloaded_fn (old))
3626 DECL_CHAIN (decl) = get_first_fn (old);
3627 else
3628 DECL_CHAIN (decl) = NULL_TREE;
3629 old = tree_cons (orig_name, decl, NULL_TREE);
3630 TREE_TYPE (old) = unknown_type_node;
3631 }
3632 else
3633 /* orig_name is not ambiguous. */
3634 old = decl;
3635
3636 if (doing_global)
3637 IDENTIFIER_GLOBAL_VALUE (orig_name) = old;
3638 else
3639 IDENTIFIER_LOCAL_VALUE (orig_name) = old;
3640
3641 return decl;
3642 }
3643 \f
3644 /* Generate an implicit declaration for identifier FUNCTIONID
3645 as a function of type int (). Print a warning if appropriate. */
3646
3647 tree
3648 implicitly_declare (functionid)
3649 tree functionid;
3650 {
3651 register tree decl;
3652 int temp = allocation_temporary_p ();
3653
3654 push_obstacks_nochange ();
3655
3656 /* Save the decl permanently so we can warn if definition follows.
3657 In ANSI C, warn_implicit is usually false, so the saves little space.
3658 But in C++, it's usually true, hence the extra code. */
3659 if (temp && (! warn_implicit || toplevel_bindings_p ()))
3660 end_temporary_allocation ();
3661
3662 /* We used to reuse an old implicit decl here,
3663 but this loses with inline functions because it can clobber
3664 the saved decl chains. */
3665 decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
3666
3667 DECL_EXTERNAL (decl) = 1;
3668 TREE_PUBLIC (decl) = 1;
3669
3670 /* ANSI standard says implicit declarations are in the innermost block.
3671 So we record the decl in the standard fashion. */
3672 pushdecl (decl);
3673 rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
3674
3675 if (warn_implicit
3676 /* Only one warning per identifier. */
3677 && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
3678 {
3679 cp_pedwarn ("implicit declaration of function `%#D'", decl);
3680 }
3681
3682 SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
3683
3684 pop_obstacks ();
3685
3686 return decl;
3687 }
3688
3689 /* Return zero if the declaration NEWDECL is valid
3690 when the declaration OLDDECL (assumed to be for the same name)
3691 has already been seen.
3692 Otherwise return an error message format string with a %s
3693 where the identifier should go. */
3694
3695 static char *
3696 redeclaration_error_message (newdecl, olddecl)
3697 tree newdecl, olddecl;
3698 {
3699 if (TREE_CODE (newdecl) == TYPE_DECL)
3700 {
3701 /* Because C++ can put things into name space for free,
3702 constructs like "typedef struct foo { ... } foo"
3703 would look like an erroneous redeclaration. */
3704 if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
3705 return 0;
3706 else
3707 return "redefinition of `%#D'";
3708 }
3709 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3710 {
3711 /* If this is a pure function, its olddecl will actually be
3712 the original initialization to `0' (which we force to call
3713 abort()). Don't complain about redefinition in this case. */
3714 if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
3715 return 0;
3716
3717 /* We'll complain about linkage mismatches in
3718 warn_extern_redeclared_static. */
3719
3720 /* defining the same name twice is no good. */
3721 if (DECL_INITIAL (olddecl) != NULL_TREE
3722 && DECL_INITIAL (newdecl) != NULL_TREE)
3723 {
3724 if (DECL_NAME (olddecl) == NULL_TREE)
3725 return "`%#D' not declared in class";
3726 else
3727 return "redefinition of `%#D'";
3728 }
3729 return 0;
3730 }
3731 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3732 {
3733 if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
3734 && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl))
3735 && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)))
3736 || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL
3737 && TYPE_SIZE (TREE_TYPE (newdecl))
3738 && TYPE_SIZE (TREE_TYPE (olddecl))))
3739 return "redefinition of `%#D'";
3740 return 0;
3741 }
3742 else if (toplevel_bindings_p ())
3743 {
3744 /* Objects declared at top level: */
3745 /* If at least one is a reference, it's ok. */
3746 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3747 return 0;
3748 /* Reject two definitions. */
3749 return "redefinition of `%#D'";
3750 }
3751 else
3752 {
3753 /* Objects declared with block scope: */
3754 /* Reject two definitions, and reject a definition
3755 together with an external reference. */
3756 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3757 return "redeclaration of `%#D'";
3758 return 0;
3759 }
3760 }
3761 \f
3762 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3763 Create one if none exists so far for the current function.
3764 This function is called for both label definitions and label references. */
3765
3766 tree
3767 lookup_label (id)
3768 tree id;
3769 {
3770 register tree decl = IDENTIFIER_LABEL_VALUE (id);
3771
3772 if (current_function_decl == NULL_TREE)
3773 {
3774 error ("label `%s' referenced outside of any function",
3775 IDENTIFIER_POINTER (id));
3776 return NULL_TREE;
3777 }
3778
3779 if ((decl == NULL_TREE
3780 || DECL_SOURCE_LINE (decl) == 0)
3781 && (named_label_uses == NULL
3782 || named_label_uses->names_in_scope != current_binding_level->names
3783 || named_label_uses->label_decl != decl))
3784 {
3785 struct named_label_list *new_ent;
3786 new_ent
3787 = (struct named_label_list*)oballoc (sizeof (struct named_label_list));
3788 new_ent->label_decl = decl;
3789 new_ent->names_in_scope = current_binding_level->names;
3790 new_ent->binding_level = current_binding_level;
3791 new_ent->lineno_o_goto = lineno;
3792 new_ent->filename_o_goto = input_filename;
3793 new_ent->next = named_label_uses;
3794 named_label_uses = new_ent;
3795 }
3796
3797 /* Use a label already defined or ref'd with this name. */
3798 if (decl != NULL_TREE)
3799 {
3800 /* But not if it is inherited and wasn't declared to be inheritable. */
3801 if (DECL_CONTEXT (decl) != current_function_decl
3802 && ! C_DECLARED_LABEL_FLAG (decl))
3803 return shadow_label (id);
3804 return decl;
3805 }
3806
3807 decl = build_decl (LABEL_DECL, id, void_type_node);
3808
3809 /* Make sure every label has an rtx. */
3810 label_rtx (decl);
3811
3812 /* A label not explicitly declared must be local to where it's ref'd. */
3813 DECL_CONTEXT (decl) = current_function_decl;
3814
3815 DECL_MODE (decl) = VOIDmode;
3816
3817 /* Say where one reference is to the label,
3818 for the sake of the error if it is not defined. */
3819 DECL_SOURCE_LINE (decl) = lineno;
3820 DECL_SOURCE_FILE (decl) = input_filename;
3821
3822 SET_IDENTIFIER_LABEL_VALUE (id, decl);
3823
3824 named_labels = tree_cons (NULL_TREE, decl, named_labels);
3825 named_label_uses->label_decl = decl;
3826
3827 return decl;
3828 }
3829
3830 /* Make a label named NAME in the current function,
3831 shadowing silently any that may be inherited from containing functions
3832 or containing scopes.
3833
3834 Note that valid use, if the label being shadowed
3835 comes from another scope in the same function,
3836 requires calling declare_nonlocal_label right away. */
3837
3838 tree
3839 shadow_label (name)
3840 tree name;
3841 {
3842 register tree decl = IDENTIFIER_LABEL_VALUE (name);
3843
3844 if (decl != NULL_TREE)
3845 {
3846 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3847 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3848 SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
3849 }
3850
3851 return lookup_label (name);
3852 }
3853
3854 /* Define a label, specifying the location in the source file.
3855 Return the LABEL_DECL node for the label, if the definition is valid.
3856 Otherwise return 0. */
3857
3858 tree
3859 define_label (filename, line, name)
3860 char *filename;
3861 int line;
3862 tree name;
3863 {
3864 tree decl;
3865
3866 if (minimal_parse_mode)
3867 {
3868 push_obstacks (&permanent_obstack, &permanent_obstack);
3869 decl = build_decl (LABEL_DECL, name, void_type_node);
3870 pop_obstacks ();
3871 DECL_SOURCE_LINE (decl) = line;
3872 DECL_SOURCE_FILE (decl) = filename;
3873 add_tree (decl);
3874 return decl;
3875 }
3876
3877 decl = lookup_label (name);
3878
3879 /* After labels, make any new cleanups go into their
3880 own new (temporary) binding contour. */
3881 current_binding_level->more_cleanups_ok = 0;
3882
3883 /* If label with this name is known from an outer context, shadow it. */
3884 if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
3885 {
3886 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3887 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3888 decl = lookup_label (name);
3889 }
3890
3891 if (name == get_identifier ("wchar_t"))
3892 cp_pedwarn ("label named wchar_t");
3893
3894 if (DECL_INITIAL (decl) != NULL_TREE)
3895 {
3896 cp_error ("duplicate label `%D'", decl);
3897 return 0;
3898 }
3899 else
3900 {
3901 struct named_label_list *uses, *prev;
3902 int identified = 0;
3903
3904 /* Mark label as having been defined. */
3905 DECL_INITIAL (decl) = error_mark_node;
3906 /* Say where in the source. */
3907 DECL_SOURCE_FILE (decl) = filename;
3908 DECL_SOURCE_LINE (decl) = line;
3909
3910 prev = NULL;
3911 uses = named_label_uses;
3912 while (uses != NULL)
3913 if (uses->label_decl == decl)
3914 {
3915 struct binding_level *b = current_binding_level;
3916 while (b)
3917 {
3918 tree new_decls = b->names;
3919 tree old_decls = (b == uses->binding_level)
3920 ? uses->names_in_scope : NULL_TREE;
3921 while (new_decls != old_decls)
3922 {
3923 if (TREE_CODE (new_decls) == VAR_DECL
3924 /* Don't complain about crossing initialization
3925 of internal entities. They can't be accessed,
3926 and they should be cleaned up
3927 by the time we get to the label. */
3928 && ! DECL_ARTIFICIAL (new_decls)
3929 && ((DECL_INITIAL (new_decls) != NULL_TREE
3930 && DECL_INITIAL (new_decls) != error_mark_node)
3931 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
3932 {
3933 if (! identified)
3934 {
3935 cp_error ("jump to label `%D'", decl);
3936 error_with_file_and_line (uses->filename_o_goto,
3937 uses->lineno_o_goto,
3938 " from here");
3939 identified = 1;
3940 }
3941 cp_error_at (" crosses initialization of `%#D'",
3942 new_decls);
3943 }
3944 new_decls = TREE_CHAIN (new_decls);
3945 }
3946 if (b == uses->binding_level)
3947 break;
3948 b = b->level_chain;
3949 }
3950
3951 if (prev != NULL)
3952 prev->next = uses->next;
3953 else
3954 named_label_uses = uses->next;
3955
3956 uses = uses->next;
3957 }
3958 else
3959 {
3960 prev = uses;
3961 uses = uses->next;
3962 }
3963 current_function_return_value = NULL_TREE;
3964 return decl;
3965 }
3966 }
3967
3968 struct cp_switch
3969 {
3970 struct binding_level *level;
3971 struct cp_switch *next;
3972 };
3973
3974 static struct cp_switch *switch_stack;
3975
3976 void
3977 push_switch ()
3978 {
3979 struct cp_switch *p
3980 = (struct cp_switch *) oballoc (sizeof (struct cp_switch));
3981 p->level = current_binding_level;
3982 p->next = switch_stack;
3983 switch_stack = p;
3984 }
3985
3986 void
3987 pop_switch ()
3988 {
3989 switch_stack = switch_stack->next;
3990 }
3991
3992 /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3993 /* XXX Note decl is never actually used. (bpk) */
3994
3995 void
3996 define_case_label (decl)
3997 tree decl;
3998 {
3999 tree cleanup = last_cleanup_this_contour ();
4000 struct binding_level *b = current_binding_level;
4001 int identified = 0;
4002
4003 if (cleanup)
4004 {
4005 static int explained = 0;
4006 cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
4007 warning ("where case label appears here");
4008 if (!explained)
4009 {
4010 warning ("(enclose actions of previous case statements requiring");
4011 warning ("destructors in their own binding contours.)");
4012 explained = 1;
4013 }
4014 }
4015
4016 for (; b && b != switch_stack->level; b = b->level_chain)
4017 {
4018 tree new_decls = b->names;
4019 for (; new_decls; new_decls = TREE_CHAIN (new_decls))
4020 {
4021 if (TREE_CODE (new_decls) == VAR_DECL
4022 /* Don't complain about crossing initialization
4023 of internal entities. They can't be accessed,
4024 and they should be cleaned up
4025 by the time we get to the label. */
4026 && ! DECL_ARTIFICIAL (new_decls)
4027 && ((DECL_INITIAL (new_decls) != NULL_TREE
4028 && DECL_INITIAL (new_decls) != error_mark_node)
4029 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
4030 {
4031 if (! identified)
4032 error ("jump to case label");
4033 identified = 1;
4034 cp_error_at (" crosses initialization of `%#D'",
4035 new_decls);
4036 }
4037 }
4038 }
4039
4040 /* After labels, make any new cleanups go into their
4041 own new (temporary) binding contour. */
4042
4043 current_binding_level->more_cleanups_ok = 0;
4044 current_function_return_value = NULL_TREE;
4045 }
4046 \f
4047 /* Return the list of declarations of the current level.
4048 Note that this list is in reverse order unless/until
4049 you nreverse it; and when you do nreverse it, you must
4050 store the result back using `storedecls' or you will lose. */
4051
4052 tree
4053 getdecls ()
4054 {
4055 return current_binding_level->names;
4056 }
4057
4058 /* Return the list of type-tags (for structs, etc) of the current level. */
4059
4060 tree
4061 gettags ()
4062 {
4063 return current_binding_level->tags;
4064 }
4065
4066 /* Store the list of declarations of the current level.
4067 This is done for the parameter declarations of a function being defined,
4068 after they are modified in the light of any missing parameters. */
4069
4070 static void
4071 storedecls (decls)
4072 tree decls;
4073 {
4074 current_binding_level->names = decls;
4075 }
4076
4077 /* Similarly, store the list of tags of the current level. */
4078
4079 static void
4080 storetags (tags)
4081 tree tags;
4082 {
4083 current_binding_level->tags = tags;
4084 }
4085 \f
4086 /* Given NAME, an IDENTIFIER_NODE,
4087 return the structure (or union or enum) definition for that name.
4088 Searches binding levels from BINDING_LEVEL up to the global level.
4089 If THISLEVEL_ONLY is nonzero, searches only the specified context
4090 (but skips any tag-transparent contexts to find one that is
4091 meaningful for tags).
4092 FORM says which kind of type the caller wants;
4093 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
4094 If the wrong kind of type is found, and it's not a template, an error is
4095 reported. */
4096
4097 static tree
4098 lookup_tag (form, name, binding_level, thislevel_only)
4099 enum tree_code form;
4100 tree name;
4101 struct binding_level *binding_level;
4102 int thislevel_only;
4103 {
4104 register struct binding_level *level;
4105
4106 for (level = binding_level; level; level = level->level_chain)
4107 {
4108 register tree tail;
4109 if (ANON_AGGRNAME_P (name))
4110 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4111 {
4112 /* There's no need for error checking here, because
4113 anon names are unique throughout the compilation. */
4114 if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
4115 return TREE_VALUE (tail);
4116 }
4117 else
4118 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4119 {
4120 if (TREE_PURPOSE (tail) == name)
4121 {
4122 enum tree_code code = TREE_CODE (TREE_VALUE (tail));
4123 /* Should tighten this up; it'll probably permit
4124 UNION_TYPE and a struct template, for example. */
4125 if (code != form
4126 && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL))
4127 {
4128 /* Definition isn't the kind we were looking for. */
4129 cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
4130 form);
4131 return NULL_TREE;
4132 }
4133 return TREE_VALUE (tail);
4134 }
4135 }
4136 if (thislevel_only && ! level->tag_transparent)
4137 {
4138 if (level->pseudo_global)
4139 {
4140 tree t = IDENTIFIER_GLOBAL_VALUE (name);
4141 if (t && TREE_CODE (t) == TEMPLATE_DECL
4142 && TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
4143 return TREE_TYPE (t);
4144 }
4145 return NULL_TREE;
4146 }
4147 if (current_class_type && level->level_chain == global_binding_level)
4148 {
4149 /* Try looking in this class's tags before heading into
4150 global binding level. */
4151 tree context = current_class_type;
4152 while (context)
4153 {
4154 switch (TREE_CODE_CLASS (TREE_CODE (context)))
4155 {
4156 tree these_tags;
4157 case 't':
4158 these_tags = CLASSTYPE_TAGS (context);
4159 if (ANON_AGGRNAME_P (name))
4160 while (these_tags)
4161 {
4162 if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
4163 == name)
4164 return TREE_VALUE (tail);
4165 these_tags = TREE_CHAIN (these_tags);
4166 }
4167 else
4168 while (these_tags)
4169 {
4170 if (TREE_PURPOSE (these_tags) == name)
4171 {
4172 if (TREE_CODE (TREE_VALUE (these_tags)) != form)
4173 {
4174 cp_error ("`%#D' redeclared as %C in class scope",
4175 TREE_VALUE (tail), form);
4176 return NULL_TREE;
4177 }
4178 return TREE_VALUE (tail);
4179 }
4180 these_tags = TREE_CHAIN (these_tags);
4181 }
4182 /* If this type is not yet complete, then don't
4183 look at its context. */
4184 if (TYPE_SIZE (context) == NULL_TREE)
4185 goto no_context;
4186 /* Go to next enclosing type, if any. */
4187 context = DECL_CONTEXT (TYPE_MAIN_DECL (context));
4188 break;
4189 case 'd':
4190 context = DECL_CONTEXT (context);
4191 break;
4192 default:
4193 my_friendly_abort (10);
4194 }
4195 continue;
4196 no_context:
4197 break;
4198 }
4199 }
4200 }
4201 return NULL_TREE;
4202 }
4203
4204 #if 0
4205 void
4206 set_current_level_tags_transparency (tags_transparent)
4207 int tags_transparent;
4208 {
4209 current_binding_level->tag_transparent = tags_transparent;
4210 }
4211 #endif
4212
4213 /* Given a type, find the tag that was defined for it and return the tag name.
4214 Otherwise return 0. However, the value can never be 0
4215 in the cases in which this is used.
4216
4217 C++: If NAME is non-zero, this is the new name to install. This is
4218 done when replacing anonymous tags with real tag names. */
4219
4220 static tree
4221 lookup_tag_reverse (type, name)
4222 tree type;
4223 tree name;
4224 {
4225 register struct binding_level *level;
4226
4227 for (level = current_binding_level; level; level = level->level_chain)
4228 {
4229 register tree tail;
4230 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4231 {
4232 if (TREE_VALUE (tail) == type)
4233 {
4234 if (name)
4235 TREE_PURPOSE (tail) = name;
4236 return TREE_PURPOSE (tail);
4237 }
4238 }
4239 }
4240 return NULL_TREE;
4241 }
4242 \f
4243 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
4244 Return the type value, or NULL_TREE if not found. */
4245
4246 static tree
4247 lookup_nested_type (type, context)
4248 tree type;
4249 tree context;
4250 {
4251 if (context == NULL_TREE)
4252 return NULL_TREE;
4253 while (context)
4254 {
4255 switch (TREE_CODE (context))
4256 {
4257 case TYPE_DECL:
4258 {
4259 tree ctype = TREE_TYPE (context);
4260 tree match = value_member (type, CLASSTYPE_TAGS (ctype));
4261 if (match)
4262 return TREE_VALUE (match);
4263 context = DECL_CONTEXT (context);
4264
4265 /* When we have a nested class whose member functions have
4266 local types (e.g., a set of enums), we'll arrive here
4267 with the DECL_CONTEXT as the actual RECORD_TYPE node for
4268 the enclosing class. Instead, we want to make sure we
4269 come back in here with the TYPE_DECL, not the RECORD_TYPE. */
4270 if (context && TREE_CODE (context) == RECORD_TYPE)
4271 context = TREE_CHAIN (context);
4272 }
4273 break;
4274 case FUNCTION_DECL:
4275 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
4276 return lookup_name (TYPE_IDENTIFIER (type), 1);
4277 return NULL_TREE;
4278 default:
4279 my_friendly_abort (12);
4280 }
4281 }
4282 return NULL_TREE;
4283 }
4284
4285 /* Look up NAME in the NAMESPACE. */
4286
4287 tree
4288 lookup_namespace_name (namespace, name)
4289 tree namespace, name;
4290 {
4291 struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace);
4292 tree x = NULL_TREE;
4293
4294 #if 1
4295 /* This searches just one level. */
4296 if (b)
4297 {
4298 for (x = b->names; x; x = TREE_CHAIN (x))
4299 if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name)
4300 break;
4301 }
4302 #else
4303 /* This searches all levels. */
4304 for (; b && !x; b = b->level_chain)
4305 {
4306 for (x = b->names; x; x = TREE_CHAIN (x))
4307 if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name)
4308 break;
4309 }
4310 #endif
4311 return x;
4312 }
4313
4314 tree
4315 make_typename_type (context, name)
4316 tree context, name;
4317 {
4318 tree t, d;
4319
4320 if (TREE_CODE (name) == TYPE_DECL)
4321 name = DECL_NAME (name);
4322 else if (TREE_CODE (name) != IDENTIFIER_NODE)
4323 my_friendly_abort (2000);
4324
4325 if (! processing_template_decl
4326 || ! uses_template_parms (context)
4327 || context == current_class_type)
4328 {
4329 t = lookup_field (context, name, 0, 1);
4330 if (t == NULL_TREE)
4331 {
4332 cp_error ("no type named `%#T' in `%#T'", name, context);
4333 return error_mark_node;
4334 }
4335 return TREE_TYPE (t);
4336 }
4337
4338 if (processing_template_decl)
4339 push_obstacks (&permanent_obstack, &permanent_obstack);
4340 t = make_lang_type (TYPENAME_TYPE);
4341 d = build_decl (TYPE_DECL, name, t);
4342 if (processing_template_decl)
4343 pop_obstacks ();
4344
4345 TYPE_CONTEXT (t) = context;
4346 TYPE_NAME (TREE_TYPE (d)) = d;
4347 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
4348 DECL_CONTEXT (d) = context;
4349 CLASSTYPE_GOT_SEMICOLON (t) = 1;
4350
4351 return t;
4352 }
4353
4354 /* Look up NAME in the current binding level and its superiors in the
4355 namespace of variables, functions and typedefs. Return a ..._DECL
4356 node of some kind representing its definition if there is only one
4357 such declaration, or return a TREE_LIST with all the overloaded
4358 definitions if there are many, or return 0 if it is undefined.
4359
4360 If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
4361 If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
4362 Otherwise we prefer non-TYPE_DECLs. */
4363
4364 static tree
4365 lookup_name_real (name, prefer_type, nonclass)
4366 tree name;
4367 int prefer_type, nonclass;
4368 {
4369 register tree val;
4370 int yylex = 0;
4371 tree from_obj = NULL_TREE;
4372 tree locval, classval;
4373
4374 if (prefer_type == -2)
4375 {
4376 extern int looking_for_typename;
4377 tree type = NULL_TREE;
4378
4379 yylex = 1;
4380 prefer_type = looking_for_typename;
4381
4382 if (got_scope)
4383 type = got_scope;
4384 else if (got_object != error_mark_node)
4385 type = got_object;
4386
4387 if (type)
4388 {
4389 if (type == error_mark_node)
4390 return error_mark_node;
4391 if (TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type))
4392 type = TREE_TYPE (type);
4393
4394 type = complete_type (type);
4395
4396 if (type == void_type_node)
4397 val = IDENTIFIER_GLOBAL_VALUE (name);
4398 else if (TREE_CODE (type) == NAMESPACE_DECL)
4399 {
4400 val = lookup_namespace_name (type, name);
4401 }
4402 else if (! IS_AGGR_TYPE (type)
4403 || TREE_CODE (type) == TEMPLATE_TYPE_PARM
4404 || TREE_CODE (type) == TYPENAME_TYPE)
4405 /* Someone else will give an error about this if needed. */
4406 val = NULL_TREE;
4407 else if (TYPE_BEING_DEFINED (type))
4408 {
4409 val = IDENTIFIER_CLASS_VALUE (name);
4410 if (val && DECL_CONTEXT (val) != type)
4411 {
4412 struct binding_level *b = class_binding_level;
4413 for (val = NULL_TREE; b; b = b->level_chain)
4414 {
4415 tree t = purpose_member (name, b->class_shadowed);
4416 if (t && TREE_VALUE (t)
4417 && DECL_CONTEXT (TREE_VALUE (t)) == type)
4418 {
4419 val = TREE_VALUE (t);
4420 break;
4421 }
4422 }
4423 }
4424 if (val == NULL_TREE)
4425 val = lookup_field (type, name, 0, 1);
4426 }
4427 else if (type == current_class_type)
4428 val = IDENTIFIER_CLASS_VALUE (name);
4429 else
4430 val = lookup_field (type, name, 0, prefer_type);
4431 }
4432 else
4433 val = NULL_TREE;
4434
4435 #if 1
4436 if (got_scope && processing_template_decl
4437 && got_scope != current_class_type
4438 && uses_template_parms (got_scope)
4439 && val && TREE_CODE (val) == TYPE_DECL
4440 && ! DECL_ARTIFICIAL (val))
4441 {
4442 tree t = make_typename_type (got_scope, DECL_NAME (val));
4443 TREE_TYPE (t) = TREE_TYPE (val);
4444 val = TYPE_MAIN_DECL (t);
4445 }
4446 #endif
4447
4448 if (got_scope)
4449 goto done;
4450 else if (got_object && val)
4451 from_obj = val;
4452 }
4453
4454 locval = classval = NULL_TREE;
4455
4456 if (current_binding_level != global_binding_level
4457 && IDENTIFIER_LOCAL_VALUE (name))
4458 locval = IDENTIFIER_LOCAL_VALUE (name);
4459
4460 /* In C++ class fields are between local and global scope,
4461 just before the global scope. */
4462 if (current_class_type && ! nonclass)
4463 {
4464 classval = IDENTIFIER_CLASS_VALUE (name);
4465 if (classval == NULL_TREE && TYPE_BEING_DEFINED (current_class_type))
4466 /* Try to find values from base classes if we are presently
4467 defining a type. We are presently only interested in
4468 TYPE_DECLs. */
4469 classval = lookup_field (current_class_type, name, 0, 1);
4470
4471 /* yylex() calls this with -2, since we should never start digging for
4472 the nested name at the point where we haven't even, for example,
4473 created the COMPONENT_REF or anything like that. */
4474 if (classval == NULL_TREE)
4475 classval = lookup_nested_field (name, ! yylex);
4476 }
4477
4478 if (locval && classval)
4479 {
4480 if (current_scope () == current_function_decl
4481 && ! hack_decl_function_context (current_function_decl))
4482 /* Not in a nested function. */
4483 val = locval;
4484 else
4485 {
4486 /* This is incredibly horrible. The whole concept of
4487 IDENTIFIER_LOCAL_VALUE / IDENTIFIER_CLASS_VALUE /
4488 IDENTIFIER_GLOBAL_VALUE needs to be scrapped for local
4489 classes. */
4490 tree lctx = hack_decl_function_context (locval);
4491 tree cctx = hack_decl_function_context (classval);
4492
4493 if (lctx == current_scope ())
4494 val = locval;
4495 else if (lctx == cctx)
4496 val = classval;
4497 else
4498 /* I don't know which is right; let's just guess for now. */
4499 val = locval;
4500 }
4501 }
4502 else if (locval)
4503 val = locval;
4504 else if (classval)
4505 val = classval;
4506 else
4507 val = IDENTIFIER_GLOBAL_VALUE (name);
4508
4509 done:
4510 if (val)
4511 {
4512 /* This should only warn about types used in qualified-ids. */
4513 if (from_obj && from_obj != val)
4514 {
4515 if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL
4516 && TREE_CODE (val) == TYPE_DECL
4517 && TREE_TYPE (from_obj) != TREE_TYPE (val))
4518 {
4519 cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%#T')",
4520 name, got_object, TREE_TYPE (from_obj));
4521 cp_pedwarn (" does not match lookup in the current scope (`%#T')",
4522 TREE_TYPE (val));
4523 }
4524
4525 val = from_obj;
4526 }
4527
4528 if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template)
4529 || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0)
4530 ;
4531 else if (IDENTIFIER_HAS_TYPE_VALUE (name))
4532 val = TYPE_MAIN_DECL (IDENTIFIER_TYPE_VALUE (name));
4533 else if (TREE_TYPE (val) == error_mark_node)
4534 val = error_mark_node;
4535 }
4536 else if (from_obj)
4537 val = from_obj;
4538
4539 return val;
4540 }
4541
4542 tree
4543 lookup_name_nonclass (name)
4544 tree name;
4545 {
4546 return lookup_name_real (name, 0, 1);
4547 }
4548
4549 tree
4550 lookup_name (name, prefer_type)
4551 tree name;
4552 int prefer_type;
4553 {
4554 return lookup_name_real (name, prefer_type, 0);
4555 }
4556
4557 /* Similar to `lookup_name' but look only at current binding level. */
4558
4559 tree
4560 lookup_name_current_level (name)
4561 tree name;
4562 {
4563 register tree t = NULL_TREE;
4564
4565 if (current_binding_level == global_binding_level)
4566 {
4567 t = IDENTIFIER_GLOBAL_VALUE (name);
4568
4569 /* extern "C" function() */
4570 if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
4571 t = TREE_VALUE (t);
4572 }
4573 else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
4574 {
4575 struct binding_level *b = current_binding_level;
4576 while (1)
4577 {
4578 for (t = b->names; t; t = TREE_CHAIN (t))
4579 if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name)
4580 goto out;
4581 if (b->keep == 2)
4582 b = b->level_chain;
4583 else
4584 break;
4585 }
4586 out:
4587 ;
4588 }
4589
4590 return t;
4591 }
4592 \f
4593 /* Arrange for the user to get a source line number, even when the
4594 compiler is going down in flames, so that she at least has a
4595 chance of working around problems in the compiler. We used to
4596 call error(), but that let the segmentation fault continue
4597 through; now, it's much more passive by asking them to send the
4598 maintainers mail about the problem. */
4599
4600 static void
4601 signal_catch (sig)
4602 int sig;
4603 {
4604 signal (SIGSEGV, SIG_DFL);
4605 #ifdef SIGIOT
4606 signal (SIGIOT, SIG_DFL);
4607 #endif
4608 #ifdef SIGILL
4609 signal (SIGILL, SIG_DFL);
4610 #endif
4611 #ifdef SIGABRT
4612 signal (SIGABRT, SIG_DFL);
4613 #endif
4614 #ifdef SIGBUS
4615 signal (SIGBUS, SIG_DFL);
4616 #endif
4617 my_friendly_abort (0);
4618 }
4619
4620 #if 0
4621 /* Unused -- brendan 970107 */
4622 /* Array for holding types considered "built-in". These types
4623 are output in the module in which `main' is defined. */
4624 static tree *builtin_type_tdescs_arr;
4625 static int builtin_type_tdescs_len, builtin_type_tdescs_max;
4626 #endif
4627
4628 /* Push the declarations of builtin types into the namespace.
4629 RID_INDEX, if < RID_MAX is the index of the builtin type
4630 in the array RID_POINTERS. NAME is the name used when looking
4631 up the builtin type. TYPE is the _TYPE node for the builtin type. */
4632
4633 static void
4634 record_builtin_type (rid_index, name, type)
4635 enum rid rid_index;
4636 char *name;
4637 tree type;
4638 {
4639 tree rname = NULL_TREE, tname = NULL_TREE;
4640 tree tdecl;
4641
4642 if ((int) rid_index < (int) RID_MAX)
4643 rname = ridpointers[(int) rid_index];
4644 if (name)
4645 tname = get_identifier (name);
4646
4647 TYPE_BUILT_IN (type) = 1;
4648
4649 if (tname)
4650 {
4651 tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
4652 set_identifier_type_value (tname, NULL_TREE);
4653 if ((int) rid_index < (int) RID_MAX)
4654 IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
4655 }
4656 if (rname != NULL_TREE)
4657 {
4658 if (tname != NULL_TREE)
4659 {
4660 set_identifier_type_value (rname, NULL_TREE);
4661 IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
4662 }
4663 else
4664 {
4665 tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
4666 set_identifier_type_value (rname, NULL_TREE);
4667 }
4668 }
4669 }
4670
4671 /* Push overloaded decl, in global scope, with one argument so it
4672 can be used as a callback from define_function. */
4673
4674 static void
4675 push_overloaded_decl_1 (x)
4676 tree x;
4677 {
4678 push_overloaded_decl (x, 0);
4679 }
4680
4681 #ifdef __GNUC__
4682 __inline
4683 #endif
4684 tree
4685 auto_function (name, type, code)
4686 tree name, type;
4687 enum built_in_function code;
4688 {
4689 return define_function
4690 (IDENTIFIER_POINTER (name), type, code, push_overloaded_decl_1,
4691 IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type),
4692 0)));
4693 }
4694
4695 /* Create the predefined scalar types of C,
4696 and some nodes representing standard constants (0, 1, (void *)0).
4697 Initialize the global binding level.
4698 Make definitions for built-in primitive functions. */
4699
4700 void
4701 init_decl_processing ()
4702 {
4703 tree decl;
4704 register tree endlink, int_endlink, double_endlink, unsigned_endlink;
4705 tree fields[20];
4706 /* Data type of memcpy. */
4707 tree memcpy_ftype, strlen_ftype;
4708 int wchar_type_size;
4709 tree temp;
4710 tree array_domain_type;
4711 extern int flag_strict_prototype;
4712 tree vb_off_identifier;
4713 /* Function type `char *(char *, char *)' and similar ones */
4714 tree string_ftype_ptr_ptr, int_ftype_string_string;
4715 tree sizetype_endlink;
4716 tree ptr_ftype, ptr_ftype_unsigned, ptr_ftype_sizetype;
4717 tree void_ftype, void_ftype_int, void_ftype_ptr;
4718
4719 /* Have to make these distinct before we try using them. */
4720 lang_name_cplusplus = get_identifier ("C++");
4721 lang_name_c = get_identifier ("C");
4722
4723 if (flag_strict_prototype == 2)
4724 {
4725 if (pedantic)
4726 strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
4727 }
4728 else
4729 strict_prototypes_lang_c = flag_strict_prototype;
4730
4731 /* Initially, C. */
4732 current_lang_name = lang_name_c;
4733
4734 current_function_decl = NULL_TREE;
4735 named_labels = NULL_TREE;
4736 named_label_uses = NULL;
4737 current_binding_level = NULL_BINDING_LEVEL;
4738 free_binding_level = NULL_BINDING_LEVEL;
4739
4740 #ifndef __CYGWIN32__
4741 /* Because most segmentation signals can be traced back into user
4742 code, catch them and at least give the user a chance of working
4743 around compiler bugs. */
4744 signal (SIGSEGV, signal_catch);
4745
4746 /* We will also catch aborts in the back-end through signal_catch and
4747 give the user a chance to see where the error might be, and to defeat
4748 aborts in the back-end when there have been errors previously in their
4749 code. */
4750 #ifdef SIGIOT
4751 signal (SIGIOT, signal_catch);
4752 #endif
4753 #ifdef SIGILL
4754 signal (SIGILL, signal_catch);
4755 #endif
4756 #ifdef SIGABRT
4757 signal (SIGABRT, signal_catch);
4758 #endif
4759 #ifdef SIGBUS
4760 signal (SIGBUS, signal_catch);
4761 #endif
4762 #else /* ndef __CYGWIN32__ */
4763 /* Cygwin32 cannot handle catching signals other than
4764 SIGABRT yet. We hope this will cease to be the case soon. */
4765 #ifdef SIGABRT
4766 signal (SIGABRT, signal_catch);
4767 #endif
4768 #endif /* ndef __CYGWIN32__ */
4769
4770 gcc_obstack_init (&decl_obstack);
4771
4772 /* Must lay these out before anything else gets laid out. */
4773 error_mark_node = make_node (ERROR_MARK);
4774 TREE_PERMANENT (error_mark_node) = 1;
4775 TREE_TYPE (error_mark_node) = error_mark_node;
4776 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
4777 TREE_TYPE (error_mark_list) = error_mark_node;
4778
4779 /* Make the binding_level structure for global names. */
4780 pushlevel (0);
4781 global_binding_level = current_binding_level;
4782
4783 this_identifier = get_identifier (THIS_NAME);
4784 in_charge_identifier = get_identifier (IN_CHARGE_NAME);
4785 ctor_identifier = get_identifier (CTOR_NAME);
4786 dtor_identifier = get_identifier (DTOR_NAME);
4787 pfn_identifier = get_identifier (VTABLE_PFN_NAME);
4788 index_identifier = get_identifier (VTABLE_INDEX_NAME);
4789 delta_identifier = get_identifier (VTABLE_DELTA_NAME);
4790 delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
4791 pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
4792 if (flag_handle_signatures)
4793 {
4794 tag_identifier = get_identifier (SIGTABLE_TAG_NAME);
4795 vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME);
4796 vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME);
4797 }
4798
4799 /* Define `int' and `char' first so that dbx will output them first. */
4800
4801 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4802 record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
4803
4804 /* Define `char', which is like either `signed char' or `unsigned char'
4805 but not the same as either. */
4806
4807 char_type_node
4808 = (flag_signed_char
4809 ? make_signed_type (CHAR_TYPE_SIZE)
4810 : make_unsigned_type (CHAR_TYPE_SIZE));
4811 record_builtin_type (RID_CHAR, "char", char_type_node);
4812
4813 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4814 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4815
4816 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4817 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4818
4819 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4820 record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
4821 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4822
4823 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4824 record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
4825
4826 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4827 record_builtin_type (RID_MAX, "long long unsigned int",
4828 long_long_unsigned_type_node);
4829 record_builtin_type (RID_MAX, "long long unsigned",
4830 long_long_unsigned_type_node);
4831
4832 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4833 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4834 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4835 record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
4836 record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
4837
4838 /* `unsigned long' is the standard type for sizeof.
4839 Note that stddef.h uses `unsigned long',
4840 and this must agree, even of long and int are the same size. */
4841 sizetype
4842 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
4843
4844 ptrdiff_type_node
4845 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
4846
4847 TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
4848 TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
4849 TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
4850 TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
4851 TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
4852 TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
4853 TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
4854 TREE_TYPE (TYPE_SIZE (short_integer_type_node)) = sizetype;
4855 TREE_TYPE (TYPE_SIZE (short_unsigned_type_node)) = sizetype;
4856
4857 /* Define both `signed char' and `unsigned char'. */
4858 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4859 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4860 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4861 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4862
4863 /* These are types that type_for_size and type_for_mode use. */
4864 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4865 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
4866 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4867 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
4868 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4869 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
4870 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4871 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
4872 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4873 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
4874 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4875 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
4876 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4877 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
4878 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4879 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
4880
4881 float_type_node = make_node (REAL_TYPE);
4882 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4883 record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
4884 layout_type (float_type_node);
4885
4886 double_type_node = make_node (REAL_TYPE);
4887 if (flag_short_double)
4888 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4889 else
4890 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4891 record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
4892 layout_type (double_type_node);
4893
4894 long_double_type_node = make_node (REAL_TYPE);
4895 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4896 record_builtin_type (RID_MAX, "long double", long_double_type_node);
4897 layout_type (long_double_type_node);
4898
4899 complex_integer_type_node = make_node (COMPLEX_TYPE);
4900 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"),
4901 complex_integer_type_node));
4902 TREE_TYPE (complex_integer_type_node) = integer_type_node;
4903 layout_type (complex_integer_type_node);
4904
4905 complex_float_type_node = make_node (COMPLEX_TYPE);
4906 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"),
4907 complex_float_type_node));
4908 TREE_TYPE (complex_float_type_node) = float_type_node;
4909 layout_type (complex_float_type_node);
4910
4911 complex_double_type_node = make_node (COMPLEX_TYPE);
4912 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"),
4913 complex_double_type_node));
4914 TREE_TYPE (complex_double_type_node) = double_type_node;
4915 layout_type (complex_double_type_node);
4916
4917 complex_long_double_type_node = make_node (COMPLEX_TYPE);
4918 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"),
4919 complex_long_double_type_node));
4920 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
4921 layout_type (complex_long_double_type_node);
4922
4923 integer_zero_node = build_int_2 (0, 0);
4924 TREE_TYPE (integer_zero_node) = integer_type_node;
4925 integer_one_node = build_int_2 (1, 0);
4926 TREE_TYPE (integer_one_node) = integer_type_node;
4927 integer_two_node = build_int_2 (2, 0);
4928 TREE_TYPE (integer_two_node) = integer_type_node;
4929 integer_three_node = build_int_2 (3, 0);
4930 TREE_TYPE (integer_three_node) = integer_type_node;
4931
4932 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
4933 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
4934 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
4935 boolean_false_node = build_int_2 (0, 0);
4936 TREE_TYPE (boolean_false_node) = boolean_type_node;
4937 boolean_true_node = build_int_2 (1, 0);
4938 TREE_TYPE (boolean_true_node) = boolean_type_node;
4939
4940 /* These are needed by stor-layout.c. */
4941 size_zero_node = size_int (0);
4942 size_one_node = size_int (1);
4943
4944 signed_size_zero_node = build_int_2 (0, 0);
4945 TREE_TYPE (signed_size_zero_node) = make_signed_type (TYPE_PRECISION (sizetype));
4946
4947 void_type_node = make_node (VOID_TYPE);
4948 record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
4949 layout_type (void_type_node); /* Uses integer_zero_node. */
4950 void_list_node = build_tree_list (NULL_TREE, void_type_node);
4951 TREE_PARMLIST (void_list_node) = 1;
4952
4953 null_pointer_node = build_int_2 (0, 0);
4954 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4955 layout_type (TREE_TYPE (null_pointer_node));
4956
4957 if (flag_ansi)
4958 TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0);
4959 else
4960 TREE_TYPE (null_node) = build_pointer_type (void_type_node);
4961
4962 /* Used for expressions that do nothing, but are not errors. */
4963 void_zero_node = build_int_2 (0, 0);
4964 TREE_TYPE (void_zero_node) = void_type_node;
4965
4966 string_type_node = build_pointer_type (char_type_node);
4967 const_string_type_node
4968 = build_pointer_type (build_type_variant (char_type_node, 1, 0));
4969 #if 0
4970 record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
4971 #endif
4972
4973 /* Make a type to be the domain of a few array types
4974 whose domains don't really matter.
4975 200 is small enough that it always fits in size_t
4976 and large enough that it can hold most function names for the
4977 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4978 array_domain_type = build_index_type (build_int_2 (200, 0));
4979
4980 /* make a type for arrays of characters.
4981 With luck nothing will ever really depend on the length of this
4982 array type. */
4983 char_array_type_node
4984 = build_array_type (char_type_node, array_domain_type);
4985 /* Likewise for arrays of ints. */
4986 int_array_type_node
4987 = build_array_type (integer_type_node, array_domain_type);
4988
4989 /* This is just some anonymous class type. Nobody should ever
4990 need to look inside this envelope. */
4991 class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
4992
4993 default_function_type
4994 = build_function_type (integer_type_node, NULL_TREE);
4995
4996 ptr_type_node = build_pointer_type (void_type_node);
4997 const_ptr_type_node
4998 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
4999 #if 0
5000 record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
5001 #endif
5002 endlink = void_list_node;
5003 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
5004 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
5005 unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink);
5006
5007 ptr_ftype = build_function_type (ptr_type_node, NULL_TREE);
5008 ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink);
5009 sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink);
5010 /* We realloc here because sizetype could be int or unsigned. S'ok. */
5011 ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink);
5012
5013 void_ftype = build_function_type (void_type_node, endlink);
5014 void_ftype_int = build_function_type (void_type_node, int_endlink);
5015 void_ftype_ptr
5016 = build_function_type (void_type_node,
5017 tree_cons (NULL_TREE, ptr_type_node, endlink));
5018 void_ftype_ptr
5019 = build_exception_variant (void_ftype_ptr,
5020 tree_cons (NULL_TREE, NULL_TREE, NULL_TREE));
5021
5022 float_ftype_float
5023 = build_function_type (float_type_node,
5024 tree_cons (NULL_TREE, float_type_node, endlink));
5025
5026 double_ftype_double
5027 = build_function_type (double_type_node, double_endlink);
5028
5029 ldouble_ftype_ldouble
5030 = build_function_type (long_double_type_node,
5031 tree_cons (NULL_TREE, long_double_type_node,
5032 endlink));
5033
5034 double_ftype_double_double
5035 = build_function_type (double_type_node,
5036 tree_cons (NULL_TREE, double_type_node,
5037 double_endlink));
5038
5039 int_ftype_int
5040 = build_function_type (integer_type_node, int_endlink);
5041
5042 long_ftype_long
5043 = build_function_type (long_integer_type_node,
5044 tree_cons (NULL_TREE, long_integer_type_node,
5045 endlink));
5046
5047 int_ftype_cptr_cptr_sizet
5048 = build_function_type (integer_type_node,
5049 tree_cons (NULL_TREE, const_ptr_type_node,
5050 tree_cons (NULL_TREE, const_ptr_type_node,
5051 tree_cons (NULL_TREE,
5052 sizetype,
5053 endlink))));
5054
5055 string_ftype_ptr_ptr /* strcpy prototype */
5056 = build_function_type (string_type_node,
5057 tree_cons (NULL_TREE, string_type_node,
5058 tree_cons (NULL_TREE,
5059 const_string_type_node,
5060 endlink)));
5061
5062 int_ftype_string_string /* strcmp prototype */
5063 = build_function_type (integer_type_node,
5064 tree_cons (NULL_TREE, const_string_type_node,
5065 tree_cons (NULL_TREE,
5066 const_string_type_node,
5067 endlink)));
5068
5069 strlen_ftype /* strlen prototype */
5070 = build_function_type (sizetype,
5071 tree_cons (NULL_TREE, const_string_type_node,
5072 endlink));
5073
5074 memcpy_ftype /* memcpy prototype */
5075 = build_function_type (ptr_type_node,
5076 tree_cons (NULL_TREE, ptr_type_node,
5077 tree_cons (NULL_TREE, const_ptr_type_node,
5078 sizetype_endlink)));
5079
5080 if (flag_huge_objects)
5081 delta_type_node = long_integer_type_node;
5082 else
5083 delta_type_node = short_integer_type_node;
5084
5085 builtin_function ("__builtin_constant_p", int_ftype_int,
5086 BUILT_IN_CONSTANT_P, NULL_PTR);
5087
5088 builtin_return_address_fndecl
5089 = builtin_function ("__builtin_return_address", ptr_ftype_unsigned,
5090 BUILT_IN_RETURN_ADDRESS, NULL_PTR);
5091
5092 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned,
5093 BUILT_IN_FRAME_ADDRESS, NULL_PTR);
5094
5095 builtin_function ("__builtin_alloca", ptr_ftype_sizetype,
5096 BUILT_IN_ALLOCA, "alloca");
5097 builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
5098 /* Define alloca, ffs as builtins.
5099 Declare _exit just to mark it as volatile. */
5100 if (! flag_no_builtin && !flag_no_nonansi_builtin)
5101 {
5102 temp = builtin_function ("alloca", ptr_ftype_sizetype,
5103 BUILT_IN_ALLOCA, NULL_PTR);
5104 /* Suppress error if redefined as a non-function. */
5105 DECL_BUILT_IN_NONANSI (temp) = 1;
5106 temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
5107 /* Suppress error if redefined as a non-function. */
5108 DECL_BUILT_IN_NONANSI (temp) = 1;
5109 temp = builtin_function ("_exit", void_ftype_int,
5110 NOT_BUILT_IN, NULL_PTR);
5111 TREE_THIS_VOLATILE (temp) = 1;
5112 TREE_SIDE_EFFECTS (temp) = 1;
5113 /* Suppress error if redefined as a non-function. */
5114 DECL_BUILT_IN_NONANSI (temp) = 1;
5115 }
5116
5117 builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
5118 builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS,
5119 NULL_PTR);
5120 builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS,
5121 NULL_PTR);
5122 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
5123 NULL_PTR);
5124 builtin_function ("__builtin_labs", long_ftype_long,
5125 BUILT_IN_LABS, NULL_PTR);
5126 builtin_function ("__builtin_saveregs", ptr_ftype,
5127 BUILT_IN_SAVEREGS, NULL_PTR);
5128 builtin_function ("__builtin_classify_type", default_function_type,
5129 BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
5130 builtin_function ("__builtin_next_arg", ptr_ftype,
5131 BUILT_IN_NEXT_ARG, NULL_PTR);
5132 builtin_function ("__builtin_args_info", int_ftype_int,
5133 BUILT_IN_ARGS_INFO, NULL_PTR);
5134 builtin_function ("__builtin_setjmp",
5135 build_function_type (integer_type_node,
5136 tree_cons (NULL_TREE, ptr_type_node,
5137 endlink)),
5138 BUILT_IN_SETJMP, NULL_PTR);
5139 builtin_function ("__builtin_longjmp",
5140 build_function_type (integer_type_node,
5141 tree_cons (NULL_TREE, ptr_type_node,
5142 tree_cons (NULL_TREE,
5143 integer_type_node,
5144 endlink))),
5145 BUILT_IN_LONGJMP, NULL_PTR);
5146
5147 /* Untyped call and return. */
5148 builtin_function ("__builtin_apply_args", ptr_ftype,
5149 BUILT_IN_APPLY_ARGS, NULL_PTR);
5150
5151 temp = tree_cons (NULL_TREE,
5152 build_pointer_type (build_function_type (void_type_node,
5153 NULL_TREE)),
5154 ptr_ftype_sizetype);
5155 builtin_function ("__builtin_apply",
5156 build_function_type (ptr_type_node, temp),
5157 BUILT_IN_APPLY, NULL_PTR);
5158 builtin_function ("__builtin_return", void_ftype_ptr,
5159 BUILT_IN_RETURN, NULL_PTR);
5160
5161 /* Currently under experimentation. */
5162 builtin_function ("__builtin_memcpy", memcpy_ftype,
5163 BUILT_IN_MEMCPY, "memcpy");
5164 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
5165 BUILT_IN_MEMCMP, "memcmp");
5166 builtin_function ("__builtin_strcmp", int_ftype_string_string,
5167 BUILT_IN_STRCMP, "strcmp");
5168 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
5169 BUILT_IN_STRCPY, "strcpy");
5170 builtin_function ("__builtin_strlen", strlen_ftype,
5171 BUILT_IN_STRLEN, "strlen");
5172 builtin_function ("__builtin_sqrtf", float_ftype_float,
5173 BUILT_IN_FSQRT, "sqrtf");
5174 builtin_function ("__builtin_fsqrt", double_ftype_double,
5175 BUILT_IN_FSQRT, NULL_PTR);
5176 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
5177 BUILT_IN_FSQRT, "sqrtl");
5178 builtin_function ("__builtin_sinf", float_ftype_float,
5179 BUILT_IN_SIN, "sinf");
5180 builtin_function ("__builtin_sin", double_ftype_double,
5181 BUILT_IN_SIN, "sin");
5182 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
5183 BUILT_IN_SIN, "sinl");
5184 builtin_function ("__builtin_cosf", float_ftype_float,
5185 BUILT_IN_COS, "cosf");
5186 builtin_function ("__builtin_cos", double_ftype_double,
5187 BUILT_IN_COS, "cos");
5188 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
5189 BUILT_IN_COS, "cosl");
5190
5191 if (!flag_no_builtin)
5192 {
5193 #if 0 /* These do not work well with libg++. */
5194 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
5195 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
5196 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
5197 #endif
5198 builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR);
5199 builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
5200 NULL_PTR);
5201 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
5202 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
5203 NULL_PTR);
5204 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP,
5205 NULL_PTR);
5206 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
5207 NULL_PTR);
5208 builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR);
5209 builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR);
5210 builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR);
5211 builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT,
5212 NULL_PTR);
5213 builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR);
5214 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
5215 builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR);
5216 builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR);
5217 builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
5218 builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR);
5219
5220 /* Declare these functions volatile
5221 to avoid spurious "control drops through" warnings. */
5222 temp = builtin_function ("abort", void_ftype,
5223 NOT_BUILT_IN, NULL_PTR);
5224 TREE_THIS_VOLATILE (temp) = 1;
5225 TREE_SIDE_EFFECTS (temp) = 1;
5226 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
5227 them... */
5228 DECL_BUILT_IN_NONANSI (temp) = 1;
5229 temp = builtin_function ("exit", void_ftype_int,
5230 NOT_BUILT_IN, NULL_PTR);
5231 TREE_THIS_VOLATILE (temp) = 1;
5232 TREE_SIDE_EFFECTS (temp) = 1;
5233 DECL_BUILT_IN_NONANSI (temp) = 1;
5234 }
5235
5236 #if 0
5237 /* Support for these has not been written in either expand_builtin
5238 or build_function_call. */
5239 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR);
5240 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR);
5241 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
5242 NULL_PTR);
5243 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
5244 NULL_PTR);
5245 builtin_function ("__builtin_fmod", double_ftype_double_double,
5246 BUILT_IN_FMOD, NULL_PTR);
5247 builtin_function ("__builtin_frem", double_ftype_double_double,
5248 BUILT_IN_FREM, NULL_PTR);
5249 builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int,
5250 BUILT_IN_MEMSET, NULL_PTR);
5251 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
5252 NULL_PTR);
5253 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
5254 NULL_PTR);
5255 #endif
5256
5257 /* C++ extensions */
5258
5259 unknown_type_node = make_node (UNKNOWN_TYPE);
5260 decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
5261 unknown_type_node));
5262 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
5263 DECL_IGNORED_P (decl) = 1;
5264 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
5265 TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
5266 TYPE_ALIGN (unknown_type_node) = 1;
5267 TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
5268 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
5269 TREE_TYPE (unknown_type_node) = unknown_type_node;
5270 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
5271 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
5272 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
5273
5274 /* This is for handling opaque types in signatures. */
5275 opaque_type_node = copy_node (ptr_type_node);
5276 TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
5277 record_builtin_type (RID_MAX, 0, opaque_type_node);
5278
5279 /* This is special for C++ so functions can be overloaded. */
5280 wchar_type_node
5281 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
5282 wchar_type_size = TYPE_PRECISION (wchar_type_node);
5283 signed_wchar_type_node = make_signed_type (wchar_type_size);
5284 unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
5285 wchar_type_node
5286 = TREE_UNSIGNED (wchar_type_node)
5287 ? unsigned_wchar_type_node
5288 : signed_wchar_type_node;
5289 record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
5290
5291 /* Artificial declaration of wchar_t -- can be bashed */
5292 wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"),
5293 wchar_type_node);
5294 pushdecl (wchar_decl_node);
5295
5296 /* This is for wide string constants. */
5297 wchar_array_type_node
5298 = build_array_type (wchar_type_node, array_domain_type);
5299
5300 if (flag_vtable_thunks)
5301 {
5302 /* Make sure we get a unique function type, so we can give
5303 its pointer type a name. (This wins for gdb.) */
5304 tree vfunc_type = make_node (FUNCTION_TYPE);
5305 TREE_TYPE (vfunc_type) = integer_type_node;
5306 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
5307 layout_type (vfunc_type);
5308
5309 vtable_entry_type = build_pointer_type (vfunc_type);
5310 }
5311 else
5312 {
5313 vtable_entry_type = make_lang_type (RECORD_TYPE);
5314 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
5315 delta_type_node);
5316 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
5317 delta_type_node);
5318 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
5319 ptr_type_node);
5320 finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
5321 double_type_node);
5322
5323 /* Make this part of an invisible union. */
5324 fields[3] = copy_node (fields[2]);
5325 TREE_TYPE (fields[3]) = delta_type_node;
5326 DECL_NAME (fields[3]) = delta2_identifier;
5327 DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
5328 DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
5329 TREE_UNSIGNED (fields[3]) = 0;
5330 TREE_CHAIN (fields[2]) = fields[3];
5331 vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
5332 }
5333 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
5334
5335 vtbl_type_node
5336 = build_array_type (vtable_entry_type, NULL_TREE);
5337 layout_type (vtbl_type_node);
5338 vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0);
5339 record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
5340
5341 /* Simplify life by making a "sigtable_entry_type". Give its
5342 fields names so that the debugger can use them. */
5343
5344 if (flag_handle_signatures)
5345 {
5346 sigtable_entry_type = make_lang_type (RECORD_TYPE);
5347 fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier,
5348 delta_type_node);
5349 fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier,
5350 delta_type_node);
5351 fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier,
5352 delta_type_node);
5353 fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier,
5354 delta_type_node);
5355 fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
5356 ptr_type_node);
5357
5358 /* Set the alignment to the max of the alignment of ptr_type_node and
5359 delta_type_node. Double alignment wastes a word on the Sparc. */
5360 finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4,
5361 (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node))
5362 ? ptr_type_node
5363 : delta_type_node);
5364
5365 /* Make this part of an invisible union. */
5366 fields[5] = copy_node (fields[4]);
5367 TREE_TYPE (fields[5]) = delta_type_node;
5368 DECL_NAME (fields[5]) = vt_off_identifier;
5369 DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node);
5370 DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node);
5371 TREE_UNSIGNED (fields[5]) = 0;
5372 TREE_CHAIN (fields[4]) = fields[5];
5373
5374 sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
5375 record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
5376 }
5377
5378 std_node = build_decl (NAMESPACE_DECL, get_identifier ("std"),
5379 void_type_node);
5380 pushdecl (std_node);
5381
5382 #if 0
5383 if (flag_rtti)
5384 {
5385 /* Must build __t_desc type. Currently, type descriptors look like this:
5386
5387 struct __t_desc
5388 {
5389 const char *name;
5390 int size;
5391 int bits;
5392 struct __t_desc *points_to;
5393 int ivars_count, meths_count;
5394 struct __i_desc *ivars[];
5395 struct __m_desc *meths[];
5396 struct __t_desc *parents[];
5397 struct __t_desc *vbases[];
5398 int offsets[];
5399 };
5400
5401 ...as per Linton's paper. */
5402
5403 __t_desc_type_node = make_lang_type (RECORD_TYPE);
5404 __i_desc_type_node = make_lang_type (RECORD_TYPE);
5405 __m_desc_type_node = make_lang_type (RECORD_TYPE);
5406 __t_desc_array_type
5407 = build_array_type (build_pointer_type (__t_desc_type_node),
5408 NULL_TREE);
5409 __i_desc_array_type
5410 = build_array_type (build_pointer_type (__i_desc_type_node),
5411 NULL_TREE);
5412 __m_desc_array_type
5413 = build_array_type (build_pointer_type (__m_desc_type_node),
5414 NULL_TREE);
5415
5416 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5417 string_type_node);
5418 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
5419 unsigned_type_node);
5420 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
5421 unsigned_type_node);
5422 fields[3] = build_lang_field_decl (FIELD_DECL,
5423 get_identifier ("points_to"),
5424 build_pointer_type (__t_desc_type_node));
5425 fields[4] = build_lang_field_decl (FIELD_DECL,
5426 get_identifier ("ivars_count"),
5427 integer_type_node);
5428 fields[5] = build_lang_field_decl (FIELD_DECL,
5429 get_identifier ("meths_count"),
5430 integer_type_node);
5431 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
5432 build_pointer_type (__i_desc_array_type));
5433 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
5434 build_pointer_type (__m_desc_array_type));
5435 fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
5436 build_pointer_type (__t_desc_array_type));
5437 fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
5438 build_pointer_type (__t_desc_array_type));
5439 fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
5440 build_pointer_type (integer_type_node));
5441 finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
5442
5443 /* ivar descriptors look like this:
5444
5445 struct __i_desc
5446 {
5447 const char *name;
5448 int offset;
5449 struct __t_desc *type;
5450 };
5451 */
5452
5453 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5454 string_type_node);
5455 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
5456 integer_type_node);
5457 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
5458 build_pointer_type (__t_desc_type_node));
5459 finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2,
5460 integer_type_node);
5461
5462 /* method descriptors look like this:
5463
5464 struct __m_desc
5465 {
5466 const char *name;
5467 int vindex;
5468 struct __t_desc *vcontext;
5469 struct __t_desc *return_type;
5470 void (*address)();
5471 short parm_count;
5472 short required_parms;
5473 struct __t_desc *parm_types[];
5474 };
5475 */
5476
5477 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5478 string_type_node);
5479 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
5480 integer_type_node);
5481 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
5482 build_pointer_type (__t_desc_type_node));
5483 fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
5484 build_pointer_type (__t_desc_type_node));
5485 fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
5486 build_pointer_type (default_function_type));
5487 fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
5488 short_integer_type_node);
5489 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
5490 short_integer_type_node);
5491 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
5492 build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE)));
5493 finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7,
5494 integer_type_node);
5495 }
5496 #endif /*flag_rtti*/
5497
5498 /* Now, C++. */
5499 current_lang_name = lang_name_cplusplus;
5500
5501 auto_function (ansi_opname[(int) NEW_EXPR], ptr_ftype_sizetype,
5502 NOT_BUILT_IN);
5503 auto_function (ansi_opname[(int) VEC_NEW_EXPR], ptr_ftype_sizetype,
5504 NOT_BUILT_IN);
5505 auto_function (ansi_opname[(int) DELETE_EXPR], void_ftype_ptr,
5506 NOT_BUILT_IN);
5507 auto_function (ansi_opname[(int) VEC_DELETE_EXPR], void_ftype_ptr,
5508 NOT_BUILT_IN);
5509
5510 abort_fndecl
5511 = define_function ("__pure_virtual", void_ftype,
5512 NOT_BUILT_IN, 0, 0);
5513
5514 /* Perform other language dependent initializations. */
5515 init_class_processing ();
5516 init_init_processing ();
5517 init_search_processing ();
5518 init_rtti_processing ();
5519
5520 if (flag_exceptions)
5521 init_exception_processing ();
5522 if (flag_no_inline)
5523 {
5524 flag_inline_functions = 0;
5525 }
5526
5527 if (! supports_one_only ())
5528 flag_weak = 0;
5529
5530 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
5531 declare_function_name ();
5532
5533 /* Prepare to check format strings against argument lists. */
5534 init_function_format_info ();
5535 }
5536
5537 /* initialize type descriptor type node of various rtti type. */
5538
5539 int
5540 init_type_desc()
5541 {
5542 tree tdecl;
5543
5544 tdecl = lookup_name (get_identifier ("type_info"), 0);
5545 if (tdecl == NULL_TREE)
5546 return 0;
5547 __t_desc_type_node = TREE_TYPE (tdecl);
5548 #if 0
5549 __tp_desc_type_node = build_pointer_type (__t_desc_type_node);
5550 #endif
5551
5552 #if 0
5553 tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0);
5554 if (tdecl == NULL_TREE)
5555 return 0;
5556 __baselist_desc_type_node = TREE_TYPE (tdecl);
5557 #endif
5558
5559 tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0);
5560 if (tdecl == NULL_TREE)
5561 return 0;
5562 __bltn_desc_type_node = TREE_TYPE (tdecl);
5563
5564 tdecl = lookup_name (get_identifier ("__user_type_info"), 0);
5565 if (tdecl == NULL_TREE)
5566 return 0;
5567 __user_desc_type_node = TREE_TYPE (tdecl);
5568
5569 tdecl = lookup_name (get_identifier ("__class_type_info"), 0);
5570 if (tdecl == NULL_TREE)
5571 return 0;
5572 __class_desc_type_node = TREE_TYPE (tdecl);
5573
5574 tdecl = lookup_field (__class_desc_type_node,
5575 get_identifier ("access_mode"), 0, 0);
5576 if (tdecl == NULL_TREE)
5577 return 0;
5578 __access_mode_type_node = TREE_TYPE (tdecl);
5579
5580 tdecl = lookup_name (get_identifier ("__attr_type_info"), 0);
5581 if (tdecl == NULL_TREE)
5582 return 0;
5583 __attr_desc_type_node = TREE_TYPE (tdecl);
5584
5585 tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0);
5586 if (tdecl == NULL_TREE)
5587 return 0;
5588 __ptr_desc_type_node = TREE_TYPE (tdecl);
5589
5590 tdecl = lookup_name (get_identifier ("__func_type_info"), 0);
5591 if (tdecl == NULL_TREE)
5592 return 0;
5593 __func_desc_type_node = TREE_TYPE (tdecl);
5594
5595 tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0);
5596 if (tdecl == NULL_TREE)
5597 return 0;
5598 __ptmf_desc_type_node = TREE_TYPE (tdecl);
5599
5600 tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0);
5601 if (tdecl == NULL_TREE)
5602 return 0;
5603 __ptmd_desc_type_node = TREE_TYPE (tdecl);
5604
5605 return 1;
5606 }
5607 /* Make a definition for a builtin function named NAME and whose data type
5608 is TYPE. TYPE should be a function type with argument types.
5609 FUNCTION_CODE tells later passes how to compile calls to this function.
5610 See tree.h for its possible values.
5611
5612 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
5613 the name to be called if we can't opencode the function. */
5614
5615 tree
5616 define_function (name, type, function_code, pfn, library_name)
5617 char *name;
5618 tree type;
5619 enum built_in_function function_code;
5620 void (*pfn) PROTO((tree));
5621 char *library_name;
5622 {
5623 tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
5624 DECL_EXTERNAL (decl) = 1;
5625 TREE_PUBLIC (decl) = 1;
5626 DECL_ARTIFICIAL (decl) = 1;
5627
5628 /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
5629 we cannot change DECL_ASSEMBLER_NAME until we have installed this
5630 function in the namespace. */
5631 if (pfn) (*pfn) (decl);
5632 if (library_name)
5633 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
5634 make_function_rtl (decl);
5635 if (function_code != NOT_BUILT_IN)
5636 {
5637 DECL_BUILT_IN (decl) = 1;
5638 DECL_FUNCTION_CODE (decl) = function_code;
5639 }
5640 return decl;
5641 }
5642 \f
5643 /* Called when a declaration is seen that contains no names to declare.
5644 If its type is a reference to a structure, union or enum inherited
5645 from a containing scope, shadow that tag name for the current scope
5646 with a forward reference.
5647 If its type defines a new named structure or union
5648 or defines an enum, it is valid but we need not do anything here.
5649 Otherwise, it is an error.
5650
5651 C++: may have to grok the declspecs to learn about static,
5652 complain for anonymous unions. */
5653
5654 void
5655 shadow_tag (declspecs)
5656 tree declspecs;
5657 {
5658 int found_tag = 0;
5659 tree ob_modifier = NULL_TREE;
5660 register tree link;
5661 register enum tree_code code, ok_code = ERROR_MARK;
5662 register tree t = NULL_TREE;
5663
5664 for (link = declspecs; link; link = TREE_CHAIN (link))
5665 {
5666 register tree value = TREE_VALUE (link);
5667
5668 code = TREE_CODE (value);
5669 if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
5670 {
5671 my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261);
5672
5673 if (IS_AGGR_TYPE (value) && CLASSTYPE_USE_TEMPLATE (value))
5674 {
5675 if (CLASSTYPE_IMPLICIT_INSTANTIATION (value)
5676 && TYPE_SIZE (value) == NULL_TREE)
5677 {
5678 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (value);
5679 if (processing_template_decl)
5680 push_template_decl (TYPE_MAIN_DECL (value));
5681 }
5682 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (value))
5683 cp_error ("specialization after instantiation of `%T'", value);
5684 }
5685
5686 t = value;
5687 ok_code = code;
5688 found_tag++;
5689 }
5690 else if (value == ridpointers[(int) RID_STATIC]
5691 || value == ridpointers[(int) RID_EXTERN]
5692 || value == ridpointers[(int) RID_AUTO]
5693 || value == ridpointers[(int) RID_REGISTER]
5694 || value == ridpointers[(int) RID_INLINE]
5695 || value == ridpointers[(int) RID_VIRTUAL]
5696 || value == ridpointers[(int) RID_EXPLICIT])
5697 ob_modifier = value;
5698 }
5699
5700 /* This is where the variables in an anonymous union are
5701 declared. An anonymous union declaration looks like:
5702 union { ... } ;
5703 because there is no declarator after the union, the parser
5704 sends that declaration here. */
5705 if (ok_code == UNION_TYPE
5706 && t != NULL_TREE
5707 && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
5708 && ANON_AGGRNAME_P (TYPE_NAME (t)))
5709 || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
5710 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
5711 {
5712 /* See also grok_x_components. */
5713 tree *q;
5714
5715 /* Wipe out memory of synthesized methods */
5716 TYPE_HAS_CONSTRUCTOR (t) = 0;
5717 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
5718 TYPE_HAS_INIT_REF (t) = 0;
5719 TYPE_HAS_CONST_INIT_REF (t) = 0;
5720 TYPE_HAS_ASSIGN_REF (t) = 0;
5721 TYPE_HAS_ASSIGNMENT (t) = 0;
5722 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
5723
5724 q = &TYPE_METHODS (t);
5725 while (*q)
5726 {
5727 if (DECL_ARTIFICIAL (*q))
5728 *q = TREE_CHAIN (*q);
5729 else
5730 q = &TREE_CHAIN (*q);
5731 }
5732
5733 /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
5734 function members. */
5735 if (TYPE_METHODS (t))
5736 error ("an anonymous union cannot have function members");
5737
5738 if (TYPE_FIELDS (t))
5739 {
5740 tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
5741 NULL_TREE);
5742 finish_anon_union (decl);
5743 }
5744 }
5745 else
5746 {
5747 /* Anonymous unions are objects, that's why we only check for
5748 inappropriate specifiers in this branch. */
5749
5750 if (ob_modifier)
5751 {
5752 if (ob_modifier == ridpointers[(int) RID_INLINE]
5753 || ob_modifier == ridpointers[(int) RID_VIRTUAL])
5754 cp_error ("`%D' can only be specified for functions", ob_modifier);
5755 else if (ob_modifier == ridpointers[(int) RID_EXPLICIT])
5756 cp_error ("`%D' can only be specified for constructors",
5757 ob_modifier);
5758 else
5759 cp_error ("`%D' can only be specified for objects and functions",
5760 ob_modifier);
5761 }
5762
5763 if (found_tag == 0)
5764 pedwarn ("abstract declarator used as declaration");
5765 else if (found_tag > 1)
5766 pedwarn ("multiple types in one declaration");
5767 }
5768 }
5769 \f
5770 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
5771
5772 tree
5773 groktypename (typename)
5774 tree typename;
5775 {
5776 if (TREE_CODE (typename) != TREE_LIST)
5777 return typename;
5778 return grokdeclarator (TREE_VALUE (typename),
5779 TREE_PURPOSE (typename),
5780 TYPENAME, 0, NULL_TREE);
5781 }
5782
5783 /* Decode a declarator in an ordinary declaration or data definition.
5784 This is called as soon as the type information and variable name
5785 have been parsed, before parsing the initializer if any.
5786 Here we create the ..._DECL node, fill in its type,
5787 and put it on the list of decls for the current context.
5788 The ..._DECL node is returned as the value.
5789
5790 Exception: for arrays where the length is not specified,
5791 the type is left null, to be filled in by `cp_finish_decl'.
5792
5793 Function definitions do not come here; they go to start_function
5794 instead. However, external and forward declarations of functions
5795 do go through here. Structure field declarations are done by
5796 grokfield and not through here. */
5797
5798 /* Set this to zero to debug not using the temporary obstack
5799 to parse initializers. */
5800 int debug_temp_inits = 1;
5801
5802 tree
5803 start_decl (declarator, declspecs, initialized)
5804 tree declarator, declspecs;
5805 int initialized;
5806 {
5807 register tree decl;
5808 register tree type, tem;
5809 tree context;
5810 extern int have_extern_spec;
5811 extern int used_extern_spec;
5812
5813 #if 0
5814 /* See code below that used this. */
5815 int init_written = initialized;
5816 #endif
5817
5818 /* This should only be done once on the top most decl. */
5819 if (have_extern_spec && !used_extern_spec)
5820 {
5821 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"),
5822 declspecs);
5823 used_extern_spec = 1;
5824 }
5825
5826 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
5827 NULL_TREE);
5828 if (decl == NULL_TREE || decl == void_type_node)
5829 return NULL_TREE;
5830
5831 type = TREE_TYPE (decl);
5832
5833 /* Don't lose if destructors must be executed at file-level. */
5834 if (! processing_template_decl && TREE_STATIC (decl)
5835 && TYPE_NEEDS_DESTRUCTOR (complete_type (type))
5836 && !TREE_PERMANENT (decl))
5837 {
5838 push_obstacks (&permanent_obstack, &permanent_obstack);
5839 decl = copy_node (decl);
5840 if (TREE_CODE (type) == ARRAY_TYPE)
5841 {
5842 tree itype = TYPE_DOMAIN (type);
5843 if (itype && ! TREE_PERMANENT (itype))
5844 {
5845 itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
5846 type = build_cplus_array_type (TREE_TYPE (type), itype);
5847 TREE_TYPE (decl) = type;
5848 }
5849 }
5850 pop_obstacks ();
5851 }
5852
5853 context
5854 = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
5855 ? DECL_CLASS_CONTEXT (decl)
5856 : DECL_CONTEXT (decl);
5857
5858 if (initialized)
5859 /* Is it valid for this decl to have an initializer at all?
5860 If not, set INITIALIZED to zero, which will indirectly
5861 tell `cp_finish_decl' to ignore the initializer once it is parsed. */
5862 switch (TREE_CODE (decl))
5863 {
5864 case TYPE_DECL:
5865 /* typedef foo = bar means give foo the same type as bar.
5866 We haven't parsed bar yet, so `cp_finish_decl' will fix that up.
5867 Any other case of an initialization in a TYPE_DECL is an error. */
5868 if (pedantic || list_length (declspecs) > 1)
5869 {
5870 cp_error ("typedef `%D' is initialized", decl);
5871 initialized = 0;
5872 }
5873 break;
5874
5875 case FUNCTION_DECL:
5876 cp_error ("function `%#D' is initialized like a variable", decl);
5877 initialized = 0;
5878 break;
5879
5880 default:
5881 if (! processing_template_decl)
5882 {
5883 if (type != error_mark_node)
5884 {
5885 if (TYPE_SIZE (type) != NULL_TREE
5886 && ! TREE_CONSTANT (TYPE_SIZE (type)))
5887 {
5888 cp_error
5889 ("variable-sized object `%D' may not be initialized",
5890 decl);
5891 initialized = 0;
5892 }
5893
5894 if (TREE_CODE (type) == ARRAY_TYPE
5895 && TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE)
5896 {
5897 cp_error
5898 ("elements of array `%#D' have incomplete type", decl);
5899 initialized = 0;
5900 }
5901 }
5902 }
5903 }
5904
5905 if (initialized)
5906 {
5907 if (! toplevel_bindings_p ()
5908 && DECL_EXTERNAL (decl))
5909 cp_warning ("declaration of `%#D' has `extern' and is initialized",
5910 decl);
5911 DECL_EXTERNAL (decl) = 0;
5912 if (toplevel_bindings_p ())
5913 TREE_STATIC (decl) = 1;
5914
5915 /* Tell `pushdecl' this is an initialized decl
5916 even though we don't yet have the initializer expression.
5917 Also tell `cp_finish_decl' it may store the real initializer. */
5918 DECL_INITIAL (decl) = error_mark_node;
5919 }
5920
5921 if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE)
5922 {
5923 if (TREE_CODE (decl) == VAR_DECL)
5924 {
5925 tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
5926 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
5927 cp_error ("`%#D' is not a static member of `%#T'", decl, context);
5928 else
5929 {
5930 if (DECL_CONTEXT (field) != context)
5931 cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'", DECL_CONTEXT (field), DECL_NAME (decl), context, DECL_NAME (decl));
5932 if (duplicate_decls (decl, field))
5933 decl = field;
5934 }
5935 }
5936 else
5937 {
5938 tree field = check_classfn (context, decl);
5939 if (field && duplicate_decls (decl, field))
5940 decl = field;
5941 }
5942
5943 /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
5944 if (DECL_LANG_SPECIFIC (decl))
5945 DECL_IN_AGGR_P (decl) = 0;
5946 if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context))
5947 SET_DECL_TEMPLATE_SPECIALIZATION (decl);
5948
5949 /* Stupid stupid stupid stupid (jason 7/21/95) */
5950 if (pedantic && DECL_EXTERNAL (decl)
5951 && ! DECL_TEMPLATE_SPECIALIZATION (decl))
5952 cp_pedwarn ("declaration of `%#D' outside of class is not definition",
5953 decl);
5954
5955 pushclass (context, 2);
5956 }
5957
5958 /* Add this decl to the current binding level, but not if it
5959 comes from another scope, e.g. a static member variable.
5960 TEM may equal DECL or it may be a previous decl of the same name. */
5961
5962 if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
5963 || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
5964 || TREE_CODE (type) == LANG_TYPE)
5965 tem = decl;
5966 else
5967 tem = pushdecl (decl);
5968
5969 if (processing_template_decl)
5970 {
5971 if (! current_function_decl)
5972 push_template_decl (tem);
5973 else if (minimal_parse_mode)
5974 DECL_VINDEX (decl)
5975 = build_min_nt (DECL_STMT, copy_to_permanent (declarator),
5976 copy_to_permanent (declspecs),
5977 NULL_TREE);
5978 }
5979
5980
5981 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
5982 /* Tell the back-end to use or not use .common as appropriate. If we say
5983 -fconserve-space, we want this to save .data space, at the expense of
5984 wrong semantics. If we say -fno-conserve-space, we want this to
5985 produce errors about redefs; to do this we force variables into the
5986 data segment. */
5987 DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem);
5988 #endif
5989
5990 if (! processing_template_decl)
5991 start_decl_1 (tem);
5992
5993 /* Corresponding pop_obstacks is done in `cp_finish_decl'. */
5994 push_obstacks_nochange ();
5995
5996 #if 0
5997 /* We have no way of knowing whether the initializer will need to be
5998 evaluated at run-time or not until we've parsed it, so let's just put
5999 it in the permanent obstack. (jason) */
6000 if (init_written
6001 && ! (TREE_CODE (tem) == PARM_DECL
6002 || (TREE_READONLY (tem)
6003 && (TREE_CODE (tem) == VAR_DECL
6004 || TREE_CODE (tem) == FIELD_DECL))))
6005 {
6006 /* When parsing and digesting the initializer,
6007 use temporary storage. Do this even if we will ignore the value. */
6008 if (toplevel_bindings_p () && debug_temp_inits)
6009 {
6010 if (processing_template_decl
6011 || TYPE_NEEDS_CONSTRUCTING (type)
6012 || TREE_CODE (type) == REFERENCE_TYPE)
6013 /* In this case, the initializer must lay down in permanent
6014 storage, since it will be saved until `finish_file' is run. */
6015 ;
6016 else
6017 temporary_allocation ();
6018 }
6019 }
6020 #endif
6021
6022 return tem;
6023 }
6024
6025 void
6026 start_decl_1 (decl)
6027 tree decl;
6028 {
6029 tree type = TREE_TYPE (decl);
6030 int initialized = (DECL_INITIAL (decl) != NULL_TREE);
6031
6032 /* If this type of object needs a cleanup, and control may
6033 jump past it, make a new binding level so that it is cleaned
6034 up only when it is initialized first. */
6035 if (TYPE_NEEDS_DESTRUCTOR (type)
6036 && current_binding_level->more_cleanups_ok == 0)
6037 pushlevel_temporary (1);
6038
6039 if (initialized)
6040 /* Is it valid for this decl to have an initializer at all?
6041 If not, set INITIALIZED to zero, which will indirectly
6042 tell `cp_finish_decl' to ignore the initializer once it is parsed. */
6043 {
6044 /* Don't allow initializations for incomplete types except for
6045 arrays which might be completed by the initialization. */
6046 if (type == error_mark_node)
6047 ; /* Don't complain again. */
6048 else if (TYPE_SIZE (complete_type (type)) != NULL_TREE)
6049 ; /* A complete type is ok. */
6050 else if (TREE_CODE (type) != ARRAY_TYPE)
6051 {
6052 cp_error ("variable `%#D' has initializer but incomplete type",
6053 decl);
6054 initialized = 0;
6055 }
6056 else if (TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE)
6057 {
6058 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
6059 cp_error ("elements of array `%#D' have incomplete type", decl);
6060 /* else we already gave an error in start_decl. */
6061 initialized = 0;
6062 }
6063 }
6064
6065 if (!initialized
6066 && TREE_CODE (decl) != TYPE_DECL
6067 && TREE_CODE (decl) != TEMPLATE_DECL
6068 && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
6069 {
6070 if ((! processing_template_decl || ! uses_template_parms (type))
6071 && TYPE_SIZE (complete_type (type)) == NULL_TREE)
6072 {
6073 cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
6074 decl);
6075 /* Change the type so that assemble_variable will give
6076 DECL an rtl we can live with: (mem (const_int 0)). */
6077 TREE_TYPE (decl) = error_mark_node;
6078 type = error_mark_node;
6079 }
6080 else
6081 {
6082 /* If any base type in the hierarchy of TYPE needs a constructor,
6083 then we set initialized to 1. This way any nodes which are
6084 created for the purposes of initializing this aggregate
6085 will live as long as it does. This is necessary for global
6086 aggregates which do not have their initializers processed until
6087 the end of the file. */
6088 initialized = TYPE_NEEDS_CONSTRUCTING (type);
6089 }
6090 }
6091
6092 #if 0
6093 /* We don't do this yet for GNU C++. */
6094 /* For a local variable, define the RTL now. */
6095 if (! toplevel_bindings_p ()
6096 /* But not if this is a duplicate decl
6097 and we preserved the rtl from the previous one
6098 (which may or may not happen). */
6099 && DECL_RTL (tem) == NULL_RTX)
6100 {
6101 if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
6102 expand_decl (tem);
6103 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
6104 && DECL_INITIAL (tem) != NULL_TREE)
6105 expand_decl (tem);
6106 }
6107 #endif
6108
6109 if (! initialized)
6110 DECL_INITIAL (decl) = NULL_TREE;
6111 }
6112
6113 /* Handle initialization of references.
6114 These three arguments from from `cp_finish_decl', and have the
6115 same meaning here that they do there.
6116
6117 Quotes on semantics can be found in ARM 8.4.3. */
6118
6119 static void
6120 grok_reference_init (decl, type, init, cleanupp)
6121 tree decl, type, init;
6122 tree *cleanupp;
6123 {
6124 tree tmp;
6125
6126 if (init == NULL_TREE)
6127 {
6128 if ((DECL_LANG_SPECIFIC (decl) == 0
6129 || DECL_IN_AGGR_P (decl) == 0)
6130 && ! DECL_THIS_EXTERN (decl))
6131 {
6132 cp_error ("`%D' declared as reference but not initialized", decl);
6133 if (TREE_CODE (decl) == VAR_DECL)
6134 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
6135 }
6136 return;
6137 }
6138
6139 if (init == error_mark_node)
6140 return;
6141
6142 if (TREE_CODE (type) == REFERENCE_TYPE
6143 && TREE_CODE (init) == CONSTRUCTOR)
6144 {
6145 cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
6146 return;
6147 }
6148
6149 if (TREE_TYPE (init) && TREE_CODE (TREE_TYPE (init)) == UNKNOWN_TYPE)
6150 /* decay_conversion is probably wrong for references to functions. */
6151 init = decay_conversion (instantiate_type (TREE_TYPE (type), init, 1));
6152
6153 if (TREE_CODE (init) == TREE_LIST)
6154 init = build_compound_expr (init);
6155
6156 if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
6157 init = convert_from_reference (init);
6158
6159 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
6160 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
6161 {
6162 /* Note: default conversion is only called in very special cases. */
6163 init = default_conversion (init);
6164 }
6165
6166 tmp = convert_to_reference
6167 (type, init, CONV_IMPLICIT,
6168 LOOKUP_SPECULATIVELY|LOOKUP_NORMAL|DIRECT_BIND, decl);
6169
6170 if (tmp == error_mark_node)
6171 goto fail;
6172 else if (tmp != NULL_TREE)
6173 {
6174 init = tmp;
6175 DECL_INITIAL (decl) = save_expr (init);
6176 }
6177 else
6178 {
6179 cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
6180 goto fail;
6181 }
6182
6183 /* ?? Can this be optimized in some cases to
6184 hand back the DECL_INITIAL slot?? */
6185 if (TYPE_SIZE (TREE_TYPE (type)))
6186 {
6187 init = convert_from_reference (decl);
6188 if (TREE_PERMANENT (decl))
6189 init = copy_to_permanent (init);
6190 SET_DECL_REFERENCE_SLOT (decl, init);
6191 }
6192
6193 if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
6194 {
6195 expand_static_init (decl, DECL_INITIAL (decl));
6196 DECL_INITIAL (decl) = NULL_TREE;
6197 }
6198 return;
6199
6200 fail:
6201 if (TREE_CODE (decl) == VAR_DECL)
6202 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
6203 return;
6204 }
6205
6206 /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from
6207 mucking with forces it does not comprehend (i.e. initialization with a
6208 constructor). If we are at global scope and won't go into COMMON, fill
6209 it in with a dummy CONSTRUCTOR to force the variable into .data;
6210 otherwise we can use error_mark_node. */
6211
6212 static tree
6213 obscure_complex_init (decl, init)
6214 tree decl, init;
6215 {
6216 if (! flag_no_inline && TREE_STATIC (decl))
6217 {
6218 if (extract_init (decl, init))
6219 return NULL_TREE;
6220 }
6221
6222 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
6223 if (toplevel_bindings_p () && ! DECL_COMMON (decl))
6224 DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE,
6225 NULL_TREE);
6226 else
6227 #endif
6228 DECL_INITIAL (decl) = error_mark_node;
6229
6230 return init;
6231 }
6232
6233 /* Finish processing of a declaration;
6234 install its line number and initial value.
6235 If the length of an array type is not known before,
6236 it must be determined now, from the initial value, or it is an error.
6237
6238 Call `pop_obstacks' iff NEED_POP is nonzero.
6239
6240 For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers
6241 for aggregates that have constructors alive on the permanent obstack,
6242 so that the global initializing functions can be written at the end.
6243
6244 INIT0 holds the value of an initializer that should be allowed to escape
6245 the normal rules.
6246
6247 FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0
6248 if the (init) syntax was used.
6249
6250 For functions that take default parameters, DECL points to its
6251 "maximal" instantiation. `cp_finish_decl' must then also declared its
6252 subsequently lower and lower forms of instantiation, checking for
6253 ambiguity as it goes. This can be sped up later. */
6254
6255 void
6256 cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
6257 tree decl, init;
6258 tree asmspec_tree;
6259 int need_pop;
6260 int flags;
6261 {
6262 register tree type;
6263 tree cleanup = NULL_TREE, ttype;
6264 int was_incomplete;
6265 int temporary = allocation_temporary_p ();
6266 char *asmspec = NULL;
6267 int was_readonly = 0;
6268
6269 /* If this is 0, then we did not change obstacks. */
6270 if (! decl)
6271 {
6272 if (init)
6273 error ("assignment (not initialization) in declaration");
6274 return;
6275 }
6276
6277 /* If a name was specified, get the string. */
6278 if (asmspec_tree)
6279 asmspec = TREE_STRING_POINTER (asmspec_tree);
6280
6281 /* If the type of the thing we are declaring either has
6282 a constructor, or has a virtual function table pointer,
6283 AND its initialization was accepted by `start_decl',
6284 then we stayed on the permanent obstack through the
6285 declaration, otherwise, changed obstacks as GCC would. */
6286
6287 type = TREE_TYPE (decl);
6288
6289 if (type == error_mark_node)
6290 {
6291 if (toplevel_bindings_p () && temporary)
6292 end_temporary_allocation ();
6293
6294 return;
6295 }
6296
6297 if (processing_template_decl)
6298 {
6299 if (init && DECL_INITIAL (decl))
6300 DECL_INITIAL (decl) = init;
6301 if (minimal_parse_mode && ! DECL_ARTIFICIAL (decl))
6302 {
6303 tree stmt = DECL_VINDEX (decl);
6304 DECL_VINDEX (decl) = NULL_TREE;
6305 TREE_OPERAND (stmt, 2) = copy_to_permanent (init);
6306 add_tree (stmt);
6307 }
6308
6309 goto finish_end0;
6310 }
6311 /* Take care of TYPE_DECLs up front. */
6312 if (TREE_CODE (decl) == TYPE_DECL)
6313 {
6314 if (init && DECL_INITIAL (decl))
6315 {
6316 /* typedef foo = bar; store the type of bar as the type of foo. */
6317 TREE_TYPE (decl) = type = TREE_TYPE (init);
6318 DECL_INITIAL (decl) = init = NULL_TREE;
6319 }
6320 if (type != error_mark_node
6321 && IS_AGGR_TYPE (type) && DECL_NAME (decl))
6322 {
6323 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
6324 cp_warning ("shadowing previous type declaration of `%#D'", decl);
6325 set_identifier_type_value (DECL_NAME (decl), type);
6326 CLASSTYPE_GOT_SEMICOLON (type) = 1;
6327 }
6328 GNU_xref_decl (current_function_decl, decl);
6329
6330 /* If we have installed this as the canonical typedef for this
6331 type, and that type has not been defined yet, delay emitting
6332 the debug informaion for it, as we will emit it later. */
6333 if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
6334 && TYPE_SIZE (TREE_TYPE (decl)) == NULL_TREE)
6335 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
6336
6337 rest_of_decl_compilation (decl, NULL_PTR,
6338 DECL_CONTEXT (decl) == NULL_TREE, at_eof);
6339 goto finish_end;
6340 }
6341 if (TREE_CODE (decl) != FUNCTION_DECL)
6342 {
6343 ttype = target_type (type);
6344 }
6345
6346 if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
6347 && TYPE_NEEDS_CONSTRUCTING (type))
6348 {
6349
6350 /* Currently, GNU C++ puts constants in text space, making them
6351 impossible to initialize. In the future, one would hope for
6352 an operating system which understood the difference between
6353 initialization and the running of a program. */
6354 was_readonly = 1;
6355 TREE_READONLY (decl) = 0;
6356 }
6357
6358 if (TREE_CODE (decl) == FIELD_DECL)
6359 {
6360 if (init && init != error_mark_node)
6361 my_friendly_assert (TREE_PERMANENT (init), 147);
6362
6363 if (asmspec)
6364 {
6365 /* This must override the asm specifier which was placed
6366 by grokclassfn. Lay this out fresh. */
6367 DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
6368 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
6369 make_decl_rtl (decl, asmspec, 0);
6370 }
6371 }
6372 /* If `start_decl' didn't like having an initialization, ignore it now. */
6373 else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
6374 init = NULL_TREE;
6375 else if (DECL_EXTERNAL (decl))
6376 ;
6377 else if (TREE_CODE (type) == REFERENCE_TYPE
6378 || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
6379 {
6380 if (TREE_STATIC (decl))
6381 make_decl_rtl (decl, NULL_PTR,
6382 toplevel_bindings_p ()
6383 || pseudo_global_level_p ());
6384 grok_reference_init (decl, type, init, &cleanup);
6385 init = NULL_TREE;
6386 }
6387
6388 GNU_xref_decl (current_function_decl, decl);
6389
6390 if (TREE_CODE (decl) == FIELD_DECL)
6391 ;
6392 else if (TREE_CODE (decl) == CONST_DECL)
6393 {
6394 my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
6395
6396 DECL_INITIAL (decl) = init;
6397
6398 /* This will keep us from needing to worry about our obstacks. */
6399 my_friendly_assert (init != NULL_TREE, 149);
6400 init = NULL_TREE;
6401 }
6402 else if (init)
6403 {
6404 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
6405 {
6406 if (TREE_CODE (type) == ARRAY_TYPE)
6407 init = digest_init (type, init, (tree *) 0);
6408 else if (TREE_CODE (init) == CONSTRUCTOR)
6409 {
6410 if (TYPE_NON_AGGREGATE_CLASS (type))
6411 {
6412 cp_error ("`%D' must be initialized by constructor, not by `{...}'",
6413 decl);
6414 init = error_mark_node;
6415 }
6416 else
6417 goto dont_use_constructor;
6418 }
6419 }
6420 else
6421 {
6422 dont_use_constructor:
6423 if (TREE_CODE (init) != TREE_VEC)
6424 init = store_init_value (decl, init);
6425 }
6426
6427 if (init)
6428 /* We must hide the initializer so that expand_decl
6429 won't try to do something it does not understand. */
6430 init = obscure_complex_init (decl, init);
6431 }
6432 else if (DECL_EXTERNAL (decl))
6433 ;
6434 else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
6435 && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
6436 {
6437 tree ctype = type;
6438 while (TREE_CODE (ctype) == ARRAY_TYPE)
6439 ctype = TREE_TYPE (ctype);
6440 if (! TYPE_NEEDS_CONSTRUCTING (ctype))
6441 {
6442 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
6443 cp_error ("structure `%D' with uninitialized const members", decl);
6444 if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
6445 cp_error ("structure `%D' with uninitialized reference members",
6446 decl);
6447 }
6448
6449 if (TREE_CODE (decl) == VAR_DECL
6450 && !DECL_INITIAL (decl)
6451 && !TYPE_NEEDS_CONSTRUCTING (type)
6452 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
6453 cp_error ("uninitialized const `%D'", decl);
6454
6455 if (TYPE_SIZE (type) != NULL_TREE
6456 && TYPE_NEEDS_CONSTRUCTING (type))
6457 init = obscure_complex_init (decl, NULL_TREE);
6458 }
6459 else if (TREE_CODE (decl) == VAR_DECL
6460 && TREE_CODE (type) != REFERENCE_TYPE
6461 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
6462 {
6463 /* ``Unless explicitly declared extern, a const object does not have
6464 external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
6465 However, if it's `const int foo = 1; const int foo;', don't complain
6466 about the second decl, since it does have an initializer before.
6467 We deliberately don't complain about arrays, because they're
6468 supposed to be initialized by a constructor. */
6469 if (! DECL_INITIAL (decl)
6470 && TREE_CODE (type) != ARRAY_TYPE
6471 && (!pedantic || !current_class_type))
6472 cp_error ("uninitialized const `%#D'", decl);
6473 }
6474
6475 /* For top-level declaration, the initial value was read in
6476 the temporary obstack. MAXINDEX, rtl, etc. to be made below
6477 must go in the permanent obstack; but don't discard the
6478 temporary data yet. */
6479
6480 if (toplevel_bindings_p () && temporary)
6481 end_temporary_allocation ();
6482
6483 /* Deduce size of array from initialization, if not already known. */
6484
6485 if (TREE_CODE (type) == ARRAY_TYPE
6486 && TYPE_DOMAIN (type) == NULL_TREE
6487 && TREE_CODE (decl) != TYPE_DECL)
6488 {
6489 int do_default
6490 = (TREE_STATIC (decl)
6491 /* Even if pedantic, an external linkage array
6492 may have incomplete type at first. */
6493 ? pedantic && ! DECL_EXTERNAL (decl)
6494 : !DECL_EXTERNAL (decl));
6495 tree initializer = init ? init : DECL_INITIAL (decl);
6496 int failure = complete_array_type (type, initializer, do_default);
6497
6498 if (failure == 1)
6499 cp_error ("initializer fails to determine size of `%D'", decl);
6500
6501 if (failure == 2)
6502 {
6503 if (do_default)
6504 cp_error ("array size missing in `%D'", decl);
6505 /* If a `static' var's size isn't known, make it extern as
6506 well as static, so it does not get allocated. If it's not
6507 `static', then don't mark it extern; finish_incomplete_decl
6508 will give it a default size and it will get allocated. */
6509 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
6510 DECL_EXTERNAL (decl) = 1;
6511 }
6512
6513 if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
6514 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6515 integer_zero_node))
6516 cp_error ("zero-size array `%D'", decl);
6517
6518 layout_decl (decl, 0);
6519 }
6520
6521 if (TREE_CODE (decl) == VAR_DECL)
6522 {
6523 if (DECL_SIZE (decl) == NULL_TREE
6524 && TYPE_SIZE (complete_type (TREE_TYPE (decl))) != NULL_TREE)
6525 layout_decl (decl, 0);
6526
6527 if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
6528 {
6529 /* A static variable with an incomplete type:
6530 that is an error if it is initialized.
6531 Otherwise, let it through, but if it is not `extern'
6532 then it may cause an error message later. */
6533 if (DECL_INITIAL (decl) != NULL_TREE)
6534 cp_error ("storage size of `%D' isn't known", decl);
6535 init = NULL_TREE;
6536 }
6537 else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
6538 {
6539 /* An automatic variable with an incomplete type: that is an error.
6540 Don't talk about array types here, since we took care of that
6541 message in grokdeclarator. */
6542 cp_error ("storage size of `%D' isn't known", decl);
6543 TREE_TYPE (decl) = error_mark_node;
6544 }
6545 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
6546 /* Let debugger know it should output info for this type. */
6547 note_debug_info_needed (ttype);
6548
6549 if (TREE_STATIC (decl) && DECL_CONTEXT (decl)
6550 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
6551 note_debug_info_needed (DECL_CONTEXT (decl));
6552
6553 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
6554 && DECL_SIZE (decl) != NULL_TREE
6555 && ! TREE_CONSTANT (DECL_SIZE (decl)))
6556 {
6557 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
6558 constant_expression_warning (DECL_SIZE (decl));
6559 else
6560 cp_error ("storage size of `%D' isn't constant", decl);
6561 }
6562
6563 if (! DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type)
6564 /* Cleanups for static variables are handled by `finish_file'. */
6565 && ! TREE_STATIC (decl))
6566 {
6567 int yes = suspend_momentary ();
6568 cleanup = maybe_build_cleanup (decl);
6569 resume_momentary (yes);
6570 }
6571 }
6572 /* PARM_DECLs get cleanups, too. */
6573 else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
6574 {
6575 if (temporary)
6576 end_temporary_allocation ();
6577 cleanup = maybe_build_cleanup (decl);
6578 if (temporary)
6579 resume_temporary_allocation ();
6580 }
6581
6582 /* Output the assembler code and/or RTL code for variables and functions,
6583 unless the type is an undefined structure or union.
6584 If not, it will get done when the type is completed. */
6585
6586 was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
6587
6588 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
6589 || TREE_CODE (decl) == RESULT_DECL)
6590 {
6591 /* ??? FIXME: What about nested classes? */
6592 int toplev = toplevel_bindings_p () || pseudo_global_level_p ();
6593 int was_temp
6594 = (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)
6595 && allocation_temporary_p ());
6596
6597 if (was_temp)
6598 end_temporary_allocation ();
6599
6600 /* Extern inline function static data has external linkage. */
6601 if (TREE_CODE (decl) == VAR_DECL
6602 && TREE_STATIC (decl)
6603 && current_function_decl
6604 && DECL_CONTEXT (decl) == current_function_decl
6605 && DECL_THIS_INLINE (current_function_decl)
6606 && DECL_PUBLIC (current_function_decl))
6607 {
6608 if (DECL_INTERFACE_KNOWN (current_function_decl))
6609 {
6610 TREE_PUBLIC (decl) = 1;
6611 DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl);
6612 }
6613 /* We can only do this if we can use common or weak, and we
6614 can't if it has been initialized and we don't support weak. */
6615 else if (DECL_INITIAL (decl) == NULL_TREE
6616 || DECL_INITIAL (decl) == error_mark_node)
6617 {
6618 TREE_PUBLIC (decl) = 1;
6619 DECL_COMMON (decl) = 1;
6620 }
6621 else if (flag_weak)
6622 make_decl_one_only (decl);
6623
6624 if (TREE_PUBLIC (decl))
6625 DECL_ASSEMBLER_NAME (decl)
6626 = build_static_name (current_function_decl, DECL_NAME (decl));
6627 else if (! DECL_ARTIFICIAL (decl))
6628 cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl);
6629 }
6630
6631 if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
6632 make_decl_rtl (decl, NULL_PTR, toplev);
6633 else if (TREE_CODE (decl) == VAR_DECL
6634 && TREE_READONLY (decl)
6635 && DECL_INITIAL (decl) != NULL_TREE
6636 && DECL_INITIAL (decl) != error_mark_node
6637 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
6638 {
6639 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
6640
6641 if (asmspec)
6642 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
6643
6644 if (! toplev
6645 && TREE_STATIC (decl)
6646 && ! TREE_SIDE_EFFECTS (decl)
6647 && ! TREE_PUBLIC (decl)
6648 && ! DECL_EXTERNAL (decl)
6649 && ! TYPE_NEEDS_DESTRUCTOR (type)
6650 && DECL_MODE (decl) != BLKmode)
6651 {
6652 /* If this variable is really a constant, then fill its DECL_RTL
6653 slot with something which won't take up storage.
6654 If something later should take its address, we can always give
6655 it legitimate RTL at that time. */
6656 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
6657 store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
6658 TREE_ASM_WRITTEN (decl) = 1;
6659 }
6660 else if (toplev && ! TREE_PUBLIC (decl))
6661 {
6662 /* If this is a static const, change its apparent linkage
6663 if it belongs to a #pragma interface. */
6664 if (!interface_unknown)
6665 {
6666 TREE_PUBLIC (decl) = 1;
6667 DECL_EXTERNAL (decl) = interface_only;
6668 }
6669 make_decl_rtl (decl, asmspec, toplev);
6670 }
6671 else
6672 rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
6673 }
6674 else if (TREE_CODE (decl) == VAR_DECL
6675 && DECL_LANG_SPECIFIC (decl)
6676 && DECL_IN_AGGR_P (decl))
6677 {
6678 if (TREE_STATIC (decl))
6679 {
6680 if (init == NULL_TREE
6681 #ifdef DEFAULT_STATIC_DEFS
6682 /* If this code is dead, then users must
6683 explicitly declare static member variables
6684 outside the class def'n as well. */
6685 && TYPE_NEEDS_CONSTRUCTING (type)
6686 #endif
6687 )
6688 {
6689 DECL_EXTERNAL (decl) = 1;
6690 make_decl_rtl (decl, asmspec, 1);
6691 }
6692 else
6693 rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
6694 }
6695 else
6696 /* Just a constant field. Should not need any rtl. */
6697 goto finish_end0;
6698 }
6699 else
6700 rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
6701
6702 if (was_temp)
6703 resume_temporary_allocation ();
6704
6705 if (type != error_mark_node
6706 && TYPE_LANG_SPECIFIC (type)
6707 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
6708 abstract_virtuals_error (decl, type);
6709 else if ((TREE_CODE (type) == FUNCTION_TYPE
6710 || TREE_CODE (type) == METHOD_TYPE)
6711 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6712 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
6713 abstract_virtuals_error (decl, TREE_TYPE (type));
6714
6715 if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
6716 signature_error (decl, type);
6717 else if ((TREE_CODE (type) == FUNCTION_TYPE
6718 || TREE_CODE (type) == METHOD_TYPE)
6719 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6720 && IS_SIGNATURE (TREE_TYPE (type)))
6721 signature_error (decl, TREE_TYPE (type));
6722
6723 if (TREE_CODE (decl) == FUNCTION_DECL)
6724 ;
6725 else if (DECL_EXTERNAL (decl)
6726 && ! (DECL_LANG_SPECIFIC (decl)
6727 && DECL_NOT_REALLY_EXTERN (decl)))
6728 {
6729 if (init)
6730 DECL_INITIAL (decl) = init;
6731 }
6732 else if (TREE_STATIC (decl) && type != error_mark_node)
6733 {
6734 /* Cleanups for static variables are handled by `finish_file'. */
6735 if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE
6736 || TYPE_NEEDS_DESTRUCTOR (type))
6737 expand_static_init (decl, init);
6738 }
6739 else if (! toplev)
6740 {
6741 /* This is a declared decl which must live until the
6742 end of the binding contour. It may need a cleanup. */
6743
6744 /* Recompute the RTL of a local array now
6745 if it used to be an incomplete type. */
6746 if (was_incomplete && ! TREE_STATIC (decl))
6747 {
6748 /* If we used it already as memory, it must stay in memory. */
6749 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
6750 /* If it's still incomplete now, no init will save it. */
6751 if (DECL_SIZE (decl) == NULL_TREE)
6752 DECL_INITIAL (decl) = NULL_TREE;
6753 expand_decl (decl);
6754 }
6755 else if (! TREE_ASM_WRITTEN (decl)
6756 && (TYPE_SIZE (type) != NULL_TREE
6757 || TREE_CODE (type) == ARRAY_TYPE))
6758 {
6759 /* Do this here, because we did not expand this decl's
6760 rtl in start_decl. */
6761 if (DECL_RTL (decl) == NULL_RTX)
6762 expand_decl (decl);
6763 else if (cleanup)
6764 {
6765 /* XXX: Why don't we use decl here? */
6766 /* Ans: Because it was already expanded? */
6767 if (! expand_decl_cleanup (NULL_TREE, cleanup))
6768 cp_error ("parser lost in parsing declaration of `%D'",
6769 decl);
6770 /* Cleanup used up here. */
6771 cleanup = NULL_TREE;
6772 }
6773 }
6774
6775 if (current_binding_level->is_for_scope)
6776 {
6777 struct binding_level *outer = current_binding_level->level_chain;
6778
6779 /* Check to see if the same name is already bound at
6780 the outer level, either because it was directly declared,
6781 or because a dead for-decl got preserved. In either case,
6782 the code would not have been valid under the ARM
6783 scope rules, so clear is_for_scope for the
6784 current_binding_level.
6785
6786 Otherwise, we need to preserve the temp slot for decl
6787 to last into the outer binding level. */
6788
6789 int handling_dead_for_vars = 0;
6790 tree link = outer->names;
6791 for (; ; link = TREE_CHAIN (link))
6792 {
6793 if (link == NULL && handling_dead_for_vars == 0)
6794 {
6795 link = outer->dead_vars_from_for;
6796 handling_dead_for_vars = 1;
6797 }
6798 if (link == NULL)
6799 {
6800 if (DECL_IN_MEMORY_P (decl))
6801 preserve_temp_slots (DECL_RTL (decl));
6802 break;
6803 }
6804 if (DECL_NAME (link) == DECL_NAME (decl))
6805 {
6806 if (handling_dead_for_vars)
6807 {
6808 tree shadowing
6809 = purpose_member (DECL_NAME (decl),
6810 current_binding_level->shadowed);
6811 if (shadowing && TREE_VALUE (shadowing) == link)
6812 TREE_VALUE (shadowing)
6813 = DECL_SHADOWED_FOR_VAR (link);
6814 }
6815 current_binding_level->is_for_scope = 0;
6816 break;
6817 }
6818 }
6819 }
6820
6821 expand_start_target_temps ();
6822
6823 if (DECL_SIZE (decl) && type != error_mark_node)
6824 {
6825 /* Compute and store the initial value. */
6826 expand_decl_init (decl);
6827
6828 if (init || TYPE_NEEDS_CONSTRUCTING (type))
6829 {
6830 emit_line_note (DECL_SOURCE_FILE (decl),
6831 DECL_SOURCE_LINE (decl));
6832 expand_aggr_init (decl, init, 0, flags);
6833 }
6834
6835 /* Set this to 0 so we can tell whether an aggregate which
6836 was initialized was ever used. Don't do this if it has a
6837 destructor, so we don't complain about the 'resource
6838 allocation is initialization' idiom. */
6839 if (TYPE_NEEDS_CONSTRUCTING (type)
6840 && cleanup == NULL_TREE
6841 && DECL_NAME (decl))
6842 TREE_USED (decl) = 0;
6843 }
6844
6845 /* Cleanup any temporaries needed for the initial value. */
6846 expand_end_target_temps ();
6847
6848 if (DECL_SIZE (decl) && type != error_mark_node)
6849 {
6850 /* Store the cleanup, if there was one. */
6851 if (cleanup)
6852 {
6853 if (! expand_decl_cleanup (decl, cleanup))
6854 cp_error ("parser lost in parsing declaration of `%D'",
6855 decl);
6856 }
6857 }
6858 }
6859 finish_end0:
6860
6861 /* Undo call to `pushclass' that was done in `start_decl'
6862 due to initialization of qualified member variable.
6863 I.e., Foo::x = 10; */
6864 {
6865 tree context = DECL_REAL_CONTEXT (decl);
6866 if (context
6867 && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
6868 && (TREE_CODE (decl) == VAR_DECL
6869 /* We also have a pushclass done that we need to undo here
6870 if we're at top level and declare a method. */
6871 || TREE_CODE (decl) == FUNCTION_DECL)
6872 /* If size hasn't been set, we're still defining it,
6873 and therefore inside the class body; don't pop
6874 the binding level.. */
6875 && TYPE_SIZE (context) != NULL_TREE
6876 && context == current_class_type)
6877 popclass (1);
6878 }
6879 }
6880
6881 finish_end:
6882
6883 /* If requested, warn about definitions of large data objects. */
6884
6885 if (warn_larger_than
6886 && ! processing_template_decl
6887 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
6888 && !DECL_EXTERNAL (decl))
6889 {
6890 register tree decl_size = DECL_SIZE (decl);
6891
6892 if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
6893 {
6894 unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT;
6895
6896 if (units > larger_than_size)
6897 warning_with_decl (decl, "size of `%s' is %u bytes", units);
6898 }
6899 }
6900
6901 if (need_pop)
6902 {
6903 /* Resume permanent allocation, if not within a function. */
6904 /* The corresponding push_obstacks_nochange is in start_decl,
6905 start_method, groktypename, and in grokfield. */
6906 pop_obstacks ();
6907 }
6908
6909 if (was_readonly)
6910 TREE_READONLY (decl) = 1;
6911 }
6912
6913 /* This is here for a midend callback from c-common.c */
6914
6915 void
6916 finish_decl (decl, init, asmspec_tree)
6917 tree decl, init;
6918 tree asmspec_tree;
6919 {
6920 cp_finish_decl (decl, init, asmspec_tree, 1, 0);
6921 }
6922
6923 void
6924 expand_static_init (decl, init)
6925 tree decl;
6926 tree init;
6927 {
6928 tree oldstatic = value_member (decl, static_aggregates);
6929
6930 if (oldstatic)
6931 {
6932 if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
6933 cp_error ("multiple initializations given for `%D'", decl);
6934 }
6935 else if (! toplevel_bindings_p () && ! pseudo_global_level_p ())
6936 {
6937 /* Emit code to perform this initialization but once. */
6938 tree temp;
6939
6940 /* Remember this information until end of file. */
6941 push_obstacks (&permanent_obstack, &permanent_obstack);
6942
6943 /* Emit code to perform this initialization but once. */
6944 temp = get_temp_name (integer_type_node, 1);
6945 rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
6946 expand_start_cond (build_binary_op (EQ_EXPR, temp,
6947 integer_zero_node, 1), 0);
6948 expand_start_target_temps ();
6949
6950 expand_assignment (temp, integer_one_node, 0, 0);
6951 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
6952 || (init && TREE_CODE (init) == TREE_LIST))
6953 {
6954 expand_aggr_init (decl, init, 0, 0);
6955 do_pending_stack_adjust ();
6956 }
6957 else if (init)
6958 expand_assignment (decl, init, 0, 0);
6959
6960 /* Cleanup any temporaries needed for the initial value. */
6961 expand_end_target_temps ();
6962
6963 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
6964 {
6965 tree cleanup, fcall;
6966 static tree Atexit = 0;
6967 if (Atexit == 0)
6968 {
6969 tree atexit_fndecl, PFV, pfvlist;
6970 /* Remember this information until end of file. */
6971 push_obstacks (&permanent_obstack, &permanent_obstack);
6972 PFV = build_pointer_type (build_function_type
6973 (void_type_node, void_list_node));
6974
6975 pfvlist = tree_cons (NULL_TREE, PFV, void_list_node);
6976
6977 push_lang_context (lang_name_c);
6978 atexit_fndecl
6979 = builtin_function ("atexit",
6980 build_function_type (void_type_node,
6981 pfvlist),
6982 NOT_BUILT_IN, NULL_PTR);
6983 assemble_external (atexit_fndecl);
6984 Atexit = default_conversion (atexit_fndecl);
6985 pop_lang_context ();
6986 pop_obstacks ();
6987 }
6988
6989 cleanup = start_anon_func ();
6990 expand_expr_stmt (build_cleanup (decl));
6991 end_anon_func ();
6992 mark_addressable (cleanup);
6993 cleanup = build_unary_op (ADDR_EXPR, cleanup, 0);
6994 fcall = build_function_call (Atexit, tree_cons (NULL_TREE, cleanup, NULL_TREE));
6995 expand_expr_stmt (fcall);
6996 }
6997
6998 expand_end_cond ();
6999 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
7000 {
7001 static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
7002 TREE_STATIC (static_aggregates) = 1;
7003 }
7004
7005 /* Resume old (possibly temporary) allocation. */
7006 pop_obstacks ();
7007 }
7008 else
7009 {
7010 /* This code takes into account memory allocation
7011 policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
7012 does not hold for this object, then we must make permanent
7013 the storage currently in the temporary obstack. */
7014 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
7015 preserve_initializer ();
7016 static_aggregates = perm_tree_cons (init, decl, static_aggregates);
7017 }
7018 }
7019 \f
7020 /* Make TYPE a complete type based on INITIAL_VALUE.
7021 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
7022 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
7023
7024 int
7025 complete_array_type (type, initial_value, do_default)
7026 tree type, initial_value;
7027 int do_default;
7028 {
7029 register tree maxindex = NULL_TREE;
7030 int value = 0;
7031
7032 if (initial_value)
7033 {
7034 /* Note MAXINDEX is really the maximum index,
7035 one less than the size. */
7036 if (TREE_CODE (initial_value) == STRING_CST)
7037 {
7038 int eltsize
7039 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
7040 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
7041 / eltsize) - 1, 0);
7042 }
7043 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
7044 {
7045 tree elts = CONSTRUCTOR_ELTS (initial_value);
7046 maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node);
7047 for (; elts; elts = TREE_CHAIN (elts))
7048 {
7049 if (TREE_PURPOSE (elts))
7050 maxindex = TREE_PURPOSE (elts);
7051 else
7052 maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node);
7053 }
7054 maxindex = copy_node (maxindex);
7055 }
7056 else
7057 {
7058 /* Make an error message unless that happened already. */
7059 if (initial_value != error_mark_node)
7060 value = 1;
7061
7062 /* Prevent further error messages. */
7063 maxindex = build_int_2 (0, 0);
7064 }
7065 }
7066
7067 if (!maxindex)
7068 {
7069 if (do_default)
7070 maxindex = build_int_2 (0, 0);
7071 value = 2;
7072 }
7073
7074 if (maxindex)
7075 {
7076 tree itype;
7077
7078 TYPE_DOMAIN (type) = build_index_type (maxindex);
7079 if (! TREE_TYPE (maxindex))
7080 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
7081 if (initial_value)
7082 itype = TREE_TYPE (initial_value);
7083 else
7084 itype = NULL;
7085 if (itype && !TYPE_DOMAIN (itype))
7086 TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
7087 /* The type of the main variant should never be used for arrays
7088 of different sizes. It should only ever be completed with the
7089 size of the array. */
7090 if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)))
7091 TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type);
7092 }
7093
7094 /* Lay out the type now that we can get the real answer. */
7095
7096 layout_type (type);
7097
7098 return value;
7099 }
7100 \f
7101 /* Return zero if something is declared to be a member of type
7102 CTYPE when in the context of CUR_TYPE. STRING is the error
7103 message to print in that case. Otherwise, quietly return 1. */
7104
7105 static int
7106 member_function_or_else (ctype, cur_type, string)
7107 tree ctype, cur_type;
7108 char *string;
7109 {
7110 if (ctype && ctype != cur_type)
7111 {
7112 error (string, TYPE_NAME_STRING (ctype));
7113 return 0;
7114 }
7115 return 1;
7116 }
7117 \f
7118 /* Subroutine of `grokdeclarator'. */
7119
7120 /* Generate errors possibly applicable for a given set of specifiers.
7121 This is for ARM $7.1.2. */
7122
7123 static void
7124 bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
7125 tree object;
7126 char *type;
7127 int virtualp, quals, friendp, raises, inlinep;
7128 {
7129 if (virtualp)
7130 cp_error ("`%D' declared as a `virtual' %s", object, type);
7131 if (inlinep)
7132 cp_error ("`%D' declared as an `inline' %s", object, type);
7133 if (quals)
7134 cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
7135 object, type);
7136 if (friendp)
7137 cp_error_at ("invalid friend declaration", object);
7138 if (raises)
7139 cp_error_at ("invalid exception specifications", object);
7140 }
7141
7142 /* CTYPE is class type, or null if non-class.
7143 TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
7144 or METHOD_TYPE.
7145 DECLARATOR is the function's name.
7146 VIRTUALP is truthvalue of whether the function is virtual or not.
7147 FLAGS are to be passed through to `grokclassfn'.
7148 QUALS are qualifiers indicating whether the function is `const'
7149 or `volatile'.
7150 RAISES is a list of exceptions that this function can raise.
7151 CHECK is 1 if we must find this method in CTYPE, 0 if we should
7152 not look, and -1 if we should not call `grokclassfn' at all. */
7153
7154 static tree
7155 grokfndecl (ctype, type, declarator, virtualp, flags, quals,
7156 raises, attrlist, check, publicp, inlinep, funcdef_flag)
7157 tree ctype, type;
7158 tree declarator;
7159 int virtualp;
7160 enum overload_flags flags;
7161 tree quals, raises, attrlist;
7162 int check, publicp, inlinep, funcdef_flag;
7163 {
7164 tree cname, decl;
7165 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
7166 tree t;
7167
7168 if (ctype)
7169 cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
7170 ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
7171 else
7172 cname = NULL_TREE;
7173
7174 if (raises)
7175 {
7176 type = build_exception_variant (type, raises);
7177 }
7178
7179 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
7180 /* propagate volatile out from type to decl */
7181 if (TYPE_VOLATILE (type))
7182 TREE_THIS_VOLATILE (decl) = 1;
7183
7184 /* Should probably propagate const out from type to decl I bet (mrs). */
7185 if (staticp)
7186 {
7187 DECL_STATIC_FUNCTION_P (decl) = 1;
7188 DECL_CONTEXT (decl) = ctype;
7189 }
7190
7191 if (ctype)
7192 DECL_CLASS_CONTEXT (decl) = ctype;
7193
7194 /* All function decls start out public; we'll fix their linkage later (at
7195 definition or EOF) if appropriate. */
7196 TREE_PUBLIC (decl) = 1;
7197
7198 if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main"))
7199 {
7200 if (inlinep)
7201 error ("cannot declare `main' to be inline");
7202 else if (! publicp)
7203 error ("cannot declare `main' to be static");
7204 inlinep = 0;
7205 publicp = 1;
7206 }
7207
7208 if (! publicp)
7209 DECL_C_STATIC (decl) = 1;
7210
7211 if (inlinep)
7212 DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1;
7213
7214 DECL_EXTERNAL (decl) = 1;
7215 if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
7216 {
7217 cp_error ("%smember function `%D' cannot have `%T' method qualifier",
7218 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
7219 quals = NULL_TREE;
7220 }
7221
7222 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
7223 grok_op_properties (decl, virtualp, check < 0);
7224
7225 if (ctype && hack_decl_function_context (decl))
7226 DECL_NO_STATIC_CHAIN (decl) = 1;
7227
7228 for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
7229 if (TREE_PURPOSE (t)
7230 && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG)
7231 {
7232 add_defarg_fn (decl);
7233 break;
7234 }
7235
7236 /* Caller will do the rest of this. */
7237 if (check < 0)
7238 return decl;
7239
7240 if (check && funcdef_flag)
7241 DECL_INITIAL (decl) = error_mark_node;
7242
7243 if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
7244 {
7245 tree tmp;
7246 /* Just handle constructors here. We could do this
7247 inside the following if stmt, but I think
7248 that the code is more legible by breaking this
7249 case out. See comments below for what each of
7250 the following calls is supposed to do. */
7251 DECL_CONSTRUCTOR_P (decl) = 1;
7252
7253 grokclassfn (ctype, declarator, decl, flags, quals);
7254 if (check)
7255 {
7256 tmp = check_classfn (ctype, decl);
7257
7258 if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL)
7259 tmp = DECL_TEMPLATE_RESULT(tmp);
7260
7261 if (tmp && DECL_ARTIFICIAL (tmp))
7262 cp_error ("definition of implicitly-declared `%D'", tmp);
7263 if (tmp && duplicate_decls (decl, tmp))
7264 return tmp;
7265 }
7266 if (! grok_ctor_properties (ctype, decl))
7267 return NULL_TREE;
7268
7269 if (check == 0 && ! current_function_decl)
7270 {
7271 tmp = IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl));
7272 if (tmp == NULL_TREE)
7273 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
7274 else if (TREE_CODE (tmp) != TREE_CODE (decl))
7275 cp_error ("inconsistent declarations for `%D'", decl);
7276 else
7277 {
7278 duplicate_decls (decl, tmp);
7279 decl = tmp;
7280 /* avoid creating circularities. */
7281 DECL_CHAIN (decl) = NULL_TREE;
7282 }
7283 make_decl_rtl (decl, NULL_PTR, 1);
7284 }
7285 }
7286 else
7287 {
7288 tree tmp;
7289
7290 /* Function gets the ugly name, field gets the nice one.
7291 This call may change the type of the function (because
7292 of default parameters)! */
7293 if (ctype != NULL_TREE)
7294 grokclassfn (ctype, cname, decl, flags, quals);
7295
7296 if (ctype != NULL_TREE && check)
7297 {
7298 tmp = check_classfn (ctype, decl);
7299
7300 if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL)
7301 tmp = DECL_TEMPLATE_RESULT(tmp);
7302
7303 if (tmp && DECL_STATIC_FUNCTION_P (tmp)
7304 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
7305 {
7306 /* Remove the `this' parm added by grokclassfn.
7307 XXX Isn't this done in start_function, too? */
7308 revert_static_member_fn (&decl, NULL, NULL);
7309 last_function_parms = TREE_CHAIN (last_function_parms);
7310 }
7311 if (tmp && DECL_ARTIFICIAL (tmp))
7312 cp_error ("definition of implicitly-declared `%D'", tmp);
7313 if (tmp)
7314 {
7315 if (!duplicate_decls (decl, tmp))
7316 my_friendly_abort (892);
7317 return tmp;
7318 }
7319 }
7320
7321 if (ctype == NULL_TREE || check)
7322 return decl;
7323
7324 /* Now install the declaration of this function so that others may
7325 find it (esp. its DECL_FRIENDLIST). Don't do this for local class
7326 methods, though. */
7327 if (! current_function_decl)
7328 {
7329 /* FIXME: this should only need to look at
7330 IDENTIFIER_GLOBAL_VALUE. */
7331 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
7332 if (tmp == NULL_TREE)
7333 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
7334 else if (TREE_CODE (tmp) != TREE_CODE (decl))
7335 cp_error ("inconsistent declarations for `%D'", decl);
7336 else
7337 {
7338 duplicate_decls (decl, tmp);
7339 decl = tmp;
7340 /* avoid creating circularities. */
7341 DECL_CHAIN (decl) = NULL_TREE;
7342 }
7343
7344 if (attrlist)
7345 cplus_decl_attributes (decl, TREE_PURPOSE (attrlist),
7346 TREE_VALUE (attrlist));
7347 make_decl_rtl (decl, NULL_PTR, 1);
7348 }
7349 if (virtualp)
7350 {
7351 DECL_VIRTUAL_P (decl) = 1;
7352 if (DECL_VINDEX (decl) == NULL_TREE)
7353 DECL_VINDEX (decl) = error_mark_node;
7354 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
7355 }
7356 }
7357 return decl;
7358 }
7359
7360 static tree
7361 grokvardecl (type, declarator, specbits_in, initialized, constp)
7362 tree type;
7363 tree declarator;
7364 RID_BIT_TYPE *specbits_in;
7365 int initialized;
7366 int constp;
7367 {
7368 tree decl;
7369 RID_BIT_TYPE specbits;
7370
7371 specbits = *specbits_in;
7372
7373 if (TREE_CODE (type) == OFFSET_TYPE)
7374 {
7375 /* If you declare a static member so that it
7376 can be initialized, the code will reach here. */
7377 tree basetype = TYPE_OFFSET_BASETYPE (type);
7378 type = TREE_TYPE (type);
7379 decl = build_lang_field_decl (VAR_DECL, declarator, type);
7380 DECL_CONTEXT (decl) = basetype;
7381 DECL_CLASS_CONTEXT (decl) = basetype;
7382 DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator);
7383 }
7384 else
7385 decl = build_decl (VAR_DECL, declarator, complete_type (type));
7386
7387 DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl));
7388
7389 if (RIDBIT_SETP (RID_EXTERN, specbits))
7390 {
7391 DECL_THIS_EXTERN (decl) = 1;
7392 DECL_EXTERNAL (decl) = !initialized;
7393 }
7394
7395 /* In class context, static means one per class,
7396 public access, and static storage. */
7397 if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
7398 && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
7399 {
7400 TREE_PUBLIC (decl) = 1;
7401 TREE_STATIC (decl) = 1;
7402 DECL_EXTERNAL (decl) = 0;
7403 }
7404 /* At top level, either `static' or no s.c. makes a definition
7405 (perhaps tentative), and absence of `static' makes it public. */
7406 else if (toplevel_bindings_p ())
7407 {
7408 TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits)
7409 && (DECL_THIS_EXTERN (decl) || ! constp));
7410 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
7411 }
7412 /* Not at top level, only `static' makes a static definition. */
7413 else
7414 {
7415 TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
7416 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
7417 }
7418 return decl;
7419 }
7420
7421 /* Create a canonical pointer to member function type. */
7422
7423 tree
7424 build_ptrmemfunc_type (type)
7425 tree type;
7426 {
7427 tree fields[4];
7428 tree t;
7429 tree u;
7430
7431 /* If a canonical type already exists for this type, use it. We use
7432 this method instead of type_hash_canon, because it only does a
7433 simple equality check on the list of field members. */
7434
7435 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
7436 return t;
7437
7438 push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
7439
7440 u = make_lang_type (UNION_TYPE);
7441 IS_AGGR_TYPE (u) = 0;
7442 fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
7443 fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier,
7444 delta_type_node);
7445 finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
7446 TYPE_NAME (u) = NULL_TREE;
7447
7448 t = make_lang_type (RECORD_TYPE);
7449
7450 /* Let the front-end know this is a pointer to member function. */
7451 TYPE_PTRMEMFUNC_FLAG (t) = 1;
7452 /* and not really an aggregate. */
7453 IS_AGGR_TYPE (t) = 0;
7454
7455 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
7456 delta_type_node);
7457 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
7458 delta_type_node);
7459 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
7460 finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
7461
7462 pop_obstacks ();
7463
7464 /* Zap out the name so that the back-end will give us the debugging
7465 information for this anonymous RECORD_TYPE. */
7466 TYPE_NAME (t) = NULL_TREE;
7467
7468 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
7469
7470 /* Seems to be wanted. */
7471 CLASSTYPE_GOT_SEMICOLON (t) = 1;
7472 return t;
7473 }
7474
7475 /* Given declspecs and a declarator,
7476 determine the name and type of the object declared
7477 and construct a ..._DECL node for it.
7478 (In one case we can return a ..._TYPE node instead.
7479 For invalid input we sometimes return 0.)
7480
7481 DECLSPECS is a chain of tree_list nodes whose value fields
7482 are the storage classes and type specifiers.
7483
7484 DECL_CONTEXT says which syntactic context this declaration is in:
7485 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
7486 FUNCDEF for a function definition. Like NORMAL but a few different
7487 error messages in each case. Return value may be zero meaning
7488 this definition is too screwy to try to parse.
7489 MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
7490 handle member functions (which have FIELD context).
7491 Return value may be zero meaning this definition is too screwy to
7492 try to parse.
7493 PARM for a parameter declaration (either within a function prototype
7494 or before a function body). Make a PARM_DECL, or return void_type_node.
7495 CATCHPARM for a parameter declaration before a catch clause.
7496 TYPENAME if for a typename (in a cast or sizeof).
7497 Don't make a DECL node; just return the ..._TYPE node.
7498 FIELD for a struct or union field; make a FIELD_DECL.
7499 BITFIELD for a field with specified width.
7500 INITIALIZED is 1 if the decl has an initializer.
7501
7502 In the TYPENAME case, DECLARATOR is really an absolute declarator.
7503 It may also be so in the PARM case, for a prototype where the
7504 argument type is specified but not the name.
7505
7506 This function is where the complicated C meanings of `static'
7507 and `extern' are interpreted.
7508
7509 For C++, if there is any monkey business to do, the function which
7510 calls this one must do it, i.e., prepending instance variables,
7511 renaming overloaded function names, etc.
7512
7513 Note that for this C++, it is an error to define a method within a class
7514 which does not belong to that class.
7515
7516 Except in the case where SCOPE_REFs are implicitly known (such as
7517 methods within a class being redundantly qualified),
7518 declarations which involve SCOPE_REFs are returned as SCOPE_REFs
7519 (class_name::decl_name). The caller must also deal with this.
7520
7521 If a constructor or destructor is seen, and the context is FIELD,
7522 then the type gains the attribute TREE_HAS_x. If such a declaration
7523 is erroneous, NULL_TREE is returned.
7524
7525 QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
7526 function, these are the qualifiers to give to the `this' pointer.
7527
7528 May return void_type_node if the declarator turned out to be a friend.
7529 See grokfield for details. */
7530
7531 enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
7532
7533 tree
7534 grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
7535 tree declspecs;
7536 tree declarator;
7537 enum decl_context decl_context;
7538 int initialized;
7539 tree attrlist;
7540 {
7541 RID_BIT_TYPE specbits;
7542 int nclasses = 0;
7543 tree spec;
7544 tree type = NULL_TREE;
7545 int longlong = 0;
7546 int constp;
7547 int volatilep;
7548 int virtualp, explicitp, friendp, inlinep, staticp;
7549 int explicit_int = 0;
7550 int explicit_char = 0;
7551 int defaulted_int = 0;
7552 int opaque_typedef = 0;
7553 tree typedef_decl = NULL_TREE;
7554 char *name;
7555 tree typedef_type = NULL_TREE;
7556 int funcdef_flag = 0;
7557 enum tree_code innermost_code = ERROR_MARK;
7558 int bitfield = 0;
7559 #if 0
7560 /* See the code below that used this. */
7561 tree decl_machine_attr = NULL_TREE;
7562 #endif
7563 /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
7564 All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
7565 tree init = NULL_TREE;
7566
7567 /* Keep track of what sort of function is being processed
7568 so that we can warn about default return values, or explicit
7569 return values which do not match prescribed defaults. */
7570 enum return_types return_type = return_normal;
7571
7572 tree dname = NULL_TREE;
7573 tree ctype = current_class_type;
7574 tree ctor_return_type = NULL_TREE;
7575 enum overload_flags flags = NO_SPECIAL;
7576 tree quals = NULL_TREE;
7577 tree raises = NULL_TREE;
7578
7579 RIDBIT_RESET_ALL (specbits);
7580 if (decl_context == FUNCDEF)
7581 funcdef_flag = 1, decl_context = NORMAL;
7582 else if (decl_context == MEMFUNCDEF)
7583 funcdef_flag = -1, decl_context = FIELD;
7584 else if (decl_context == BITFIELD)
7585 bitfield = 1, decl_context = FIELD;
7586
7587 /* Look inside a declarator for the name being declared
7588 and get it as a string, for an error message. */
7589 {
7590 tree *next = &declarator;
7591 register tree decl;
7592 name = NULL;
7593
7594 while (next && *next)
7595 {
7596 decl = *next;
7597 switch (TREE_CODE (decl))
7598 {
7599 case COND_EXPR:
7600 ctype = NULL_TREE;
7601 next = &TREE_OPERAND (decl, 0);
7602 break;
7603
7604 case BIT_NOT_EXPR: /* for C++ destructors! */
7605 {
7606 tree name = TREE_OPERAND (decl, 0);
7607 tree rename = NULL_TREE;
7608
7609 my_friendly_assert (flags == NO_SPECIAL, 152);
7610 flags = DTOR_FLAG;
7611 return_type = return_dtor;
7612 if (TREE_CODE (name) == TYPE_DECL)
7613 TREE_OPERAND (decl, 0) = name = constructor_name (name);
7614 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
7615 if (ctype == NULL_TREE)
7616 {
7617 if (current_class_type == NULL_TREE)
7618 {
7619 error ("destructors must be member functions");
7620 flags = NO_SPECIAL;
7621 }
7622 else
7623 {
7624 tree t = constructor_name (current_class_name);
7625 if (t != name)
7626 rename = t;
7627 }
7628 }
7629 else
7630 {
7631 tree t = constructor_name (ctype);
7632 if (t != name)
7633 rename = t;
7634 }
7635
7636 if (rename)
7637 {
7638 cp_error ("destructor `%T' must match class name `%T'",
7639 name, rename);
7640 TREE_OPERAND (decl, 0) = rename;
7641 }
7642 next = &name;
7643 }
7644 break;
7645
7646 case ADDR_EXPR: /* C++ reference declaration */
7647 /* fall through */
7648 case ARRAY_REF:
7649 case INDIRECT_REF:
7650 ctype = NULL_TREE;
7651 innermost_code = TREE_CODE (decl);
7652 next = &TREE_OPERAND (decl, 0);
7653 break;
7654
7655 case CALL_EXPR:
7656 if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
7657 {
7658 /* This is actually a variable declaration using constructor
7659 syntax. We need to call start_decl and cp_finish_decl so we
7660 can get the variable initialized... */
7661
7662 *next = TREE_OPERAND (decl, 0);
7663 init = TREE_OPERAND (decl, 1);
7664
7665 decl = start_decl (declarator, declspecs, 1);
7666 finish_decl (decl, init, NULL_TREE);
7667 return 0;
7668 }
7669 innermost_code = TREE_CODE (decl);
7670 if (decl_context == FIELD && ctype == NULL_TREE)
7671 ctype = current_class_type;
7672 if (ctype
7673 && TREE_OPERAND (decl, 0)
7674 && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL
7675 && ((DECL_NAME (TREE_OPERAND (decl, 0))
7676 == constructor_name_full (ctype))
7677 || (DECL_NAME (TREE_OPERAND (decl, 0))
7678 == constructor_name (ctype)))))
7679 TREE_OPERAND (decl, 0) = constructor_name (ctype);
7680 next = &TREE_OPERAND (decl, 0);
7681 decl = *next;
7682 if (ctype != NULL_TREE
7683 && decl != NULL_TREE && flags != DTOR_FLAG
7684 && decl == constructor_name (ctype))
7685 {
7686 return_type = return_ctor;
7687 ctor_return_type = ctype;
7688 }
7689 ctype = NULL_TREE;
7690 break;
7691
7692 case IDENTIFIER_NODE:
7693 dname = decl;
7694 next = 0;
7695
7696 if (is_rid (dname))
7697 {
7698 cp_error ("declarator-id missing; using reserved word `%D'",
7699 dname);
7700 name = IDENTIFIER_POINTER (dname);
7701 }
7702 if (! IDENTIFIER_OPNAME_P (dname)
7703 /* Linux headers use '__op'. Arrgh. */
7704 || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))
7705 name = IDENTIFIER_POINTER (dname);
7706 else
7707 {
7708 if (IDENTIFIER_TYPENAME_P (dname))
7709 {
7710 my_friendly_assert (flags == NO_SPECIAL, 154);
7711 flags = TYPENAME_FLAG;
7712 ctor_return_type = TREE_TYPE (dname);
7713 return_type = return_conversion;
7714 }
7715 name = operator_name_string (dname);
7716 }
7717 break;
7718
7719 /* C++ extension */
7720 case SCOPE_REF:
7721 {
7722 /* Perform error checking, and decide on a ctype. */
7723 tree cname = TREE_OPERAND (decl, 0);
7724 if (cname == NULL_TREE)
7725 ctype = NULL_TREE;
7726 else if (! is_aggr_type (cname, 1))
7727 TREE_OPERAND (decl, 0) = NULL_TREE;
7728 /* Must test TREE_OPERAND (decl, 1), in case user gives
7729 us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7730 else if (TREE_OPERAND (decl, 1)
7731 && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
7732 ctype = cname;
7733 else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM)
7734 {
7735 cp_error ("`%T::%D' is not a valid declarator", cname,
7736 TREE_OPERAND (decl, 1));
7737 cp_error (" perhaps you want `typename %T::%D' to make it a type",
7738 cname, TREE_OPERAND (decl, 1));
7739 return void_type_node;
7740 }
7741 else if (ctype == NULL_TREE)
7742 ctype = cname;
7743 else if (TREE_COMPLEXITY (decl) == current_class_depth)
7744 TREE_OPERAND (decl, 0) = ctype;
7745 else
7746 {
7747 if (! UNIQUELY_DERIVED_FROM_P (cname, ctype))
7748 {
7749 cp_error ("type `%T' is not derived from type `%T'",
7750 cname, ctype);
7751 TREE_OPERAND (decl, 0) = NULL_TREE;
7752 }
7753 else
7754 ctype = cname;
7755 }
7756
7757 if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL
7758 && ((DECL_NAME (TREE_OPERAND (decl, 1))
7759 == constructor_name_full (ctype))
7760 || (DECL_NAME (TREE_OPERAND (decl, 1))
7761 == constructor_name (ctype))))
7762 TREE_OPERAND (decl, 1) = constructor_name (ctype);
7763 next = &TREE_OPERAND (decl, 1);
7764 decl = *next;
7765 if (ctype)
7766 {
7767 if (TREE_CODE (decl) == IDENTIFIER_NODE
7768 && constructor_name (ctype) == decl)
7769 {
7770 return_type = return_ctor;
7771 ctor_return_type = ctype;
7772 }
7773 else if (TREE_CODE (decl) == BIT_NOT_EXPR
7774 && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
7775 && (constructor_name (ctype) == TREE_OPERAND (decl, 0)
7776 || constructor_name_full (ctype) == TREE_OPERAND (decl, 0)))
7777 {
7778 return_type = return_dtor;
7779 ctor_return_type = ctype;
7780 flags = DTOR_FLAG;
7781 TREE_OPERAND (decl, 0) = constructor_name (ctype);
7782 next = &TREE_OPERAND (decl, 0);
7783 }
7784 }
7785 }
7786 break;
7787
7788 case ERROR_MARK:
7789 next = 0;
7790 break;
7791
7792 case TYPE_DECL:
7793 /* Parse error puts this typespec where
7794 a declarator should go. */
7795 cp_error ("`%T' specified as declarator-id", DECL_NAME (decl));
7796 if (TREE_TYPE (decl) == current_class_type)
7797 cp_error (" perhaps you want `%T' for a constructor",
7798 current_class_name);
7799 dname = DECL_NAME (decl);
7800 name = IDENTIFIER_POINTER (dname);
7801
7802 /* Avoid giving two errors for this. */
7803 IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE;
7804
7805 declspecs = temp_tree_cons (NULL_TREE, integer_type_node,
7806 declspecs);
7807 *next = dname;
7808 next = 0;
7809 break;
7810
7811 default:
7812 cp_compiler_error ("`%D' as declarator", decl);
7813 return 0; /* We used to do a 155 abort here. */
7814 }
7815 }
7816 if (name == NULL)
7817 name = "type name";
7818 }
7819
7820 /* A function definition's declarator must have the form of
7821 a function declarator. */
7822
7823 if (funcdef_flag && innermost_code != CALL_EXPR)
7824 return 0;
7825
7826 if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
7827 && innermost_code != CALL_EXPR
7828 && ! (ctype && declspecs == NULL_TREE))
7829 {
7830 cp_error ("declaration of `%D' as non-function", dname);
7831 return void_type_node;
7832 }
7833
7834 /* Anything declared one level down from the top level
7835 must be one of the parameters of a function
7836 (because the body is at least two levels down). */
7837
7838 /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7839 by not allowing C++ class definitions to specify their parameters
7840 with xdecls (must be spec.d in the parmlist).
7841
7842 Since we now wait to push a class scope until we are sure that
7843 we are in a legitimate method context, we must set oldcname
7844 explicitly (since current_class_name is not yet alive).
7845
7846 We also want to avoid calling this a PARM if it is in a namespace. */
7847
7848 if (decl_context == NORMAL && ! namespace_bindings_p ()
7849 && ! pseudo_global_level_p ())
7850 {
7851 struct binding_level *b = current_binding_level;
7852 current_binding_level = b->level_chain;
7853 if (current_binding_level != 0 && toplevel_bindings_p ())
7854 decl_context = PARM;
7855 current_binding_level = b;
7856 }
7857
7858 /* Look through the decl specs and record which ones appear.
7859 Some typespecs are defined as built-in typenames.
7860 Others, the ones that are modifiers of other types,
7861 are represented by bits in SPECBITS: set the bits for
7862 the modifiers that appear. Storage class keywords are also in SPECBITS.
7863
7864 If there is a typedef name or a type, store the type in TYPE.
7865 This includes builtin typedefs such as `int'.
7866
7867 Set EXPLICIT_INT if the type is `int' or `char' and did not
7868 come from a user typedef.
7869
7870 Set LONGLONG if `long' is mentioned twice.
7871
7872 For C++, constructors and destructors have their own fast treatment. */
7873
7874 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
7875 {
7876 register int i;
7877 register tree id;
7878
7879 /* Certain parse errors slip through. For example,
7880 `int class;' is not caught by the parser. Try
7881 weakly to recover here. */
7882 if (TREE_CODE (spec) != TREE_LIST)
7883 return 0;
7884
7885 id = TREE_VALUE (spec);
7886
7887 if (TREE_CODE (id) == IDENTIFIER_NODE)
7888 {
7889 if (id == ridpointers[(int) RID_INT]
7890 || id == ridpointers[(int) RID_CHAR]
7891 || id == ridpointers[(int) RID_BOOL]
7892 || id == ridpointers[(int) RID_WCHAR])
7893 {
7894 if (type)
7895 {
7896 if (id == ridpointers[(int) RID_BOOL])
7897 error ("`bool' is now a keyword");
7898 else
7899 cp_error ("extraneous `%T' ignored", id);
7900 }
7901 else
7902 {
7903 if (id == ridpointers[(int) RID_INT])
7904 explicit_int = 1;
7905 else if (id == ridpointers[(int) RID_CHAR])
7906 explicit_char = 1;
7907 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7908 }
7909 goto found;
7910 }
7911 /* C++ aggregate types. */
7912 if (IDENTIFIER_HAS_TYPE_VALUE (id))
7913 {
7914 if (type)
7915 cp_error ("multiple declarations `%T' and `%T'", type, id);
7916 else
7917 type = IDENTIFIER_TYPE_VALUE (id);
7918 goto found;
7919 }
7920
7921 for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++)
7922 {
7923 if (ridpointers[i] == id)
7924 {
7925 if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
7926 {
7927 if (pedantic && ! in_system_header)
7928 pedwarn ("ANSI C++ does not support `long long'");
7929 if (longlong)
7930 error ("`long long long' is too long for GCC");
7931 else
7932 longlong = 1;
7933 }
7934 else if (RIDBIT_SETP (i, specbits))
7935 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
7936 RIDBIT_SET (i, specbits);
7937 goto found;
7938 }
7939 }
7940 }
7941 /* C++ aggregate types. */
7942 else if (TREE_CODE (id) == TYPE_DECL)
7943 {
7944 if (type)
7945 cp_error ("multiple declarations `%T' and `%T'", type,
7946 TREE_TYPE (id));
7947 else
7948 {
7949 type = TREE_TYPE (id);
7950 TREE_VALUE (spec) = type;
7951 }
7952 goto found;
7953 }
7954 if (type)
7955 error ("two or more data types in declaration of `%s'", name);
7956 else if (TREE_CODE (id) == IDENTIFIER_NODE)
7957 {
7958 register tree t = lookup_name (id, 1);
7959 if (!t || TREE_CODE (t) != TYPE_DECL)
7960 error ("`%s' fails to be a typedef or built in type",
7961 IDENTIFIER_POINTER (id));
7962 else
7963 {
7964 type = TREE_TYPE (t);
7965 #if 0
7966 /* See the code below that used this. */
7967 decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
7968 #endif
7969 typedef_decl = t;
7970 }
7971 }
7972 else if (id != error_mark_node)
7973 /* Can't change CLASS nodes into RECORD nodes here! */
7974 type = id;
7975
7976 found: ;
7977 }
7978
7979 typedef_type = type;
7980
7981 /* No type at all: default to `int', and set DEFAULTED_INT
7982 because it was not a user-defined typedef.
7983 Except when we have a `typedef' inside a signature, in
7984 which case the type defaults to `unknown type' and is
7985 instantiated when assigning to a signature pointer or ref. */
7986
7987 if (type == NULL_TREE
7988 && (RIDBIT_SETP (RID_SIGNED, specbits)
7989 || RIDBIT_SETP (RID_UNSIGNED, specbits)
7990 || RIDBIT_SETP (RID_LONG, specbits)
7991 || RIDBIT_SETP (RID_SHORT, specbits)))
7992 {
7993 /* These imply 'int'. */
7994 type = integer_type_node;
7995 defaulted_int = 1;
7996 }
7997
7998 if (type == NULL_TREE)
7999 {
8000 explicit_int = -1;
8001 if (return_type == return_dtor)
8002 type = void_type_node;
8003 else if (return_type == return_ctor)
8004 type = build_pointer_type (ctor_return_type);
8005 else if (return_type == return_conversion)
8006 type = ctor_return_type;
8007 else if (current_class_type
8008 && IS_SIGNATURE (current_class_type)
8009 && RIDBIT_SETP (RID_TYPEDEF, specbits)
8010 && (decl_context == FIELD || decl_context == NORMAL))
8011 {
8012 explicit_int = 0;
8013 opaque_typedef = 1;
8014 type = copy_node (opaque_type_node);
8015 }
8016 else
8017 {
8018 if (funcdef_flag)
8019 {
8020 if (warn_return_type
8021 && return_type == return_normal)
8022 /* Save warning until we know what is really going on. */
8023 warn_about_return_type = 1;
8024 }
8025 else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8026 pedwarn ("ANSI C++ forbids typedef which does not specify a type");
8027 else if (declspecs == NULL_TREE
8028 && (innermost_code != CALL_EXPR || pedantic))
8029 cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
8030 dname);
8031 type = integer_type_node;
8032 }
8033 }
8034 else if (return_type == return_dtor)
8035 {
8036 error ("return type specification for destructor invalid");
8037 type = void_type_node;
8038 }
8039 else if (return_type == return_ctor)
8040 {
8041 error ("return type specification for constructor invalid");
8042 type = build_pointer_type (ctor_return_type);
8043 }
8044 else if (return_type == return_conversion)
8045 {
8046 if (comptypes (type, ctor_return_type, 1) == 0)
8047 cp_error ("operator `%T' declared to return `%T'",
8048 ctor_return_type, type);
8049 else
8050 cp_pedwarn ("return type specified for `operator %T'",
8051 ctor_return_type);
8052
8053 type = ctor_return_type;
8054 }
8055
8056 ctype = NULL_TREE;
8057
8058 /* Now process the modifiers that were specified
8059 and check for invalid combinations. */
8060
8061 /* Long double is a special combination. */
8062
8063 if (RIDBIT_SETP (RID_LONG, specbits)
8064 && TYPE_MAIN_VARIANT (type) == double_type_node)
8065 {
8066 RIDBIT_RESET (RID_LONG, specbits);
8067 type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
8068 TYPE_VOLATILE (type));
8069 }
8070
8071 /* Check all other uses of type modifiers. */
8072
8073 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
8074 || RIDBIT_SETP (RID_SIGNED, specbits)
8075 || RIDBIT_SETP (RID_LONG, specbits)
8076 || RIDBIT_SETP (RID_SHORT, specbits))
8077 {
8078 int ok = 0;
8079
8080 if (TREE_CODE (type) == REAL_TYPE)
8081 error ("short, signed or unsigned invalid for `%s'", name);
8082 else if (TREE_CODE (type) != INTEGER_TYPE)
8083 error ("long, short, signed or unsigned invalid for `%s'", name);
8084 else if (RIDBIT_SETP (RID_LONG, specbits)
8085 && RIDBIT_SETP (RID_SHORT, specbits))
8086 error ("long and short specified together for `%s'", name);
8087 else if ((RIDBIT_SETP (RID_LONG, specbits)
8088 || RIDBIT_SETP (RID_SHORT, specbits))
8089 && explicit_char)
8090 error ("long or short specified with char for `%s'", name);
8091 else if ((RIDBIT_SETP (RID_LONG, specbits)
8092 || RIDBIT_SETP (RID_SHORT, specbits))
8093 && TREE_CODE (type) == REAL_TYPE)
8094 error ("long or short specified with floating type for `%s'", name);
8095 else if (RIDBIT_SETP (RID_SIGNED, specbits)
8096 && RIDBIT_SETP (RID_UNSIGNED, specbits))
8097 error ("signed and unsigned given together for `%s'", name);
8098 else
8099 {
8100 ok = 1;
8101 if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
8102 {
8103 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
8104 name);
8105 if (flag_pedantic_errors)
8106 ok = 0;
8107 }
8108 }
8109
8110 /* Discard the type modifiers if they are invalid. */
8111 if (! ok)
8112 {
8113 RIDBIT_RESET (RID_UNSIGNED, specbits);
8114 RIDBIT_RESET (RID_SIGNED, specbits);
8115 RIDBIT_RESET (RID_LONG, specbits);
8116 RIDBIT_RESET (RID_SHORT, specbits);
8117 longlong = 0;
8118 }
8119 }
8120
8121 if (RIDBIT_SETP (RID_COMPLEX, specbits)
8122 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
8123 {
8124 error ("complex invalid for `%s'", name);
8125 RIDBIT_RESET (RID_COMPLEX, specbits);
8126 }
8127
8128 /* Decide whether an integer type is signed or not.
8129 Optionally treat bitfields as signed by default. */
8130 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
8131 || (bitfield && ! flag_signed_bitfields
8132 && (explicit_int || defaulted_int || explicit_char
8133 /* A typedef for plain `int' without `signed'
8134 can be controlled just like plain `int'. */
8135 || ! (typedef_decl != NULL_TREE
8136 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
8137 && TREE_CODE (type) != ENUMERAL_TYPE
8138 && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
8139 {
8140 if (longlong)
8141 type = long_long_unsigned_type_node;
8142 else if (RIDBIT_SETP (RID_LONG, specbits))
8143 type = long_unsigned_type_node;
8144 else if (RIDBIT_SETP (RID_SHORT, specbits))
8145 type = short_unsigned_type_node;
8146 else if (type == char_type_node)
8147 type = unsigned_char_type_node;
8148 else if (typedef_decl)
8149 type = unsigned_type (type);
8150 else
8151 type = unsigned_type_node;
8152 }
8153 else if (RIDBIT_SETP (RID_SIGNED, specbits)
8154 && type == char_type_node)
8155 type = signed_char_type_node;
8156 else if (longlong)
8157 type = long_long_integer_type_node;
8158 else if (RIDBIT_SETP (RID_LONG, specbits))
8159 type = long_integer_type_node;
8160 else if (RIDBIT_SETP (RID_SHORT, specbits))
8161 type = short_integer_type_node;
8162
8163 if (RIDBIT_SETP (RID_COMPLEX, specbits))
8164 {
8165 /* If we just have "complex", it is equivalent to
8166 "complex double", but if any modifiers at all are specified it is
8167 the complex form of TYPE. E.g, "complex short" is
8168 "complex short int". */
8169
8170 if (defaulted_int && ! longlong
8171 && ! (RIDBIT_SETP (RID_LONG, specbits)
8172 || RIDBIT_SETP (RID_SHORT, specbits)
8173 || RIDBIT_SETP (RID_SIGNED, specbits)
8174 || RIDBIT_SETP (RID_UNSIGNED, specbits)))
8175 type = complex_double_type_node;
8176 else if (type == integer_type_node)
8177 type = complex_integer_type_node;
8178 else if (type == float_type_node)
8179 type = complex_float_type_node;
8180 else if (type == double_type_node)
8181 type = complex_double_type_node;
8182 else if (type == long_double_type_node)
8183 type = complex_long_double_type_node;
8184 else
8185 type = build_complex_type (type);
8186 }
8187
8188 /* Set CONSTP if this declaration is `const', whether by
8189 explicit specification or via a typedef.
8190 Likewise for VOLATILEP. */
8191
8192 constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
8193 volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
8194 staticp = 0;
8195 inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
8196 virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
8197 RIDBIT_RESET (RID_VIRTUAL, specbits);
8198 explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0;
8199 RIDBIT_RESET (RID_EXPLICIT, specbits);
8200
8201 if (RIDBIT_SETP (RID_STATIC, specbits))
8202 staticp = 1 + (decl_context == FIELD);
8203
8204 if (virtualp && staticp == 2)
8205 {
8206 cp_error ("member `%D' cannot be declared both virtual and static",
8207 dname);
8208 staticp = 0;
8209 }
8210 friendp = RIDBIT_SETP (RID_FRIEND, specbits);
8211 RIDBIT_RESET (RID_FRIEND, specbits);
8212
8213 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8214 {
8215 if (decl_context == PARM)
8216 {
8217 error ("non-member `%s' cannot be declared `mutable'", name);
8218 RIDBIT_RESET (RID_MUTABLE, specbits);
8219 }
8220 else if (friendp || decl_context == TYPENAME)
8221 {
8222 error ("non-object member `%s' cannot be declared `mutable'", name);
8223 RIDBIT_RESET (RID_MUTABLE, specbits);
8224 }
8225 }
8226
8227 /* Warn if two storage classes are given. Default to `auto'. */
8228
8229 if (RIDBIT_ANY_SET (specbits))
8230 {
8231 if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
8232 if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
8233 if (decl_context == PARM && nclasses > 0)
8234 error ("storage class specifiers invalid in parameter declarations");
8235 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8236 {
8237 if (decl_context == PARM)
8238 error ("typedef declaration invalid in parameter declaration");
8239 nclasses++;
8240 }
8241 if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
8242 if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
8243 }
8244
8245 /* Give error if `virtual' is used outside of class declaration. */
8246 if (virtualp
8247 && (current_class_name == NULL_TREE || decl_context != FIELD))
8248 {
8249 error ("virtual outside class declaration");
8250 virtualp = 0;
8251 }
8252 if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
8253 {
8254 error ("only members can be declared mutable");
8255 RIDBIT_RESET (RID_MUTABLE, specbits);
8256 }
8257
8258 /* Static anonymous unions are dealt with here. */
8259 if (staticp && decl_context == TYPENAME
8260 && TREE_CODE (declspecs) == TREE_LIST
8261 && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
8262 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
8263 decl_context = FIELD;
8264
8265 /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
8266 is used in a signature member function declaration. */
8267 if (decl_context == FIELD
8268 && IS_SIGNATURE (current_class_type)
8269 && RIDBIT_NOTSETP (RID_TYPEDEF, specbits))
8270 {
8271 if (constp)
8272 {
8273 error ("`const' specified for signature member function `%s'", name);
8274 constp = 0;
8275 }
8276 if (volatilep)
8277 {
8278 error ("`volatile' specified for signature member function `%s'",
8279 name);
8280 volatilep = 0;
8281 }
8282 if (inlinep)
8283 {
8284 error ("`inline' specified for signature member function `%s'", name);
8285 /* Later, we'll make signature member functions inline. */
8286 inlinep = 0;
8287 }
8288 if (friendp)
8289 {
8290 error ("`friend' declaration in signature definition");
8291 friendp = 0;
8292 }
8293 if (virtualp)
8294 {
8295 error ("`virtual' specified for signature member function `%s'",
8296 name);
8297 /* Later, we'll make signature member functions virtual. */
8298 virtualp = 0;
8299 }
8300 }
8301
8302 /* Warn about storage classes that are invalid for certain
8303 kinds of declarations (parameters, typenames, etc.). */
8304
8305 if (nclasses > 1)
8306 error ("multiple storage classes in declaration of `%s'", name);
8307 else if (decl_context != NORMAL && nclasses > 0)
8308 {
8309 if ((decl_context == PARM || decl_context == CATCHPARM)
8310 && (RIDBIT_SETP (RID_REGISTER, specbits)
8311 || RIDBIT_SETP (RID_AUTO, specbits)))
8312 ;
8313 else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8314 ;
8315 else if (decl_context == FIELD
8316 && ! IS_SIGNATURE (current_class_type)
8317 /* C++ allows static class elements */
8318 && RIDBIT_SETP (RID_STATIC, specbits))
8319 /* C++ also allows inlines and signed and unsigned elements,
8320 but in those cases we don't come in here. */
8321 ;
8322 else
8323 {
8324 if (decl_context == FIELD)
8325 {
8326 tree tmp = NULL_TREE;
8327 register int op = 0;
8328
8329 if (declarator)
8330 {
8331 /* Avoid trying to get an operand off an identifier node. */
8332 if (TREE_CODE (declarator) == IDENTIFIER_NODE)
8333 tmp = declarator;
8334 else
8335 tmp = TREE_OPERAND (declarator, 0);
8336 op = IDENTIFIER_OPNAME_P (tmp);
8337 }
8338 error ("storage class specified for %s `%s'",
8339 IS_SIGNATURE (current_class_type)
8340 ? (op
8341 ? "signature member operator"
8342 : "signature member function")
8343 : (op ? "member operator" : "field"),
8344 op ? operator_name_string (tmp) : name);
8345 }
8346 else
8347 error (((decl_context == PARM || decl_context == CATCHPARM)
8348 ? "storage class specified for parameter `%s'"
8349 : "storage class specified for typename"), name);
8350 RIDBIT_RESET (RID_REGISTER, specbits);
8351 RIDBIT_RESET (RID_AUTO, specbits);
8352 RIDBIT_RESET (RID_EXTERN, specbits);
8353
8354 if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
8355 {
8356 RIDBIT_RESET (RID_STATIC, specbits);
8357 staticp = 0;
8358 }
8359 }
8360 }
8361 else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
8362 {
8363 if (toplevel_bindings_p ())
8364 {
8365 /* It's common practice (and completely valid) to have a const
8366 be initialized and declared extern. */
8367 if (! constp)
8368 warning ("`%s' initialized and declared `extern'", name);
8369 }
8370 else
8371 error ("`%s' has both `extern' and initializer", name);
8372 }
8373 else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
8374 && ! toplevel_bindings_p ())
8375 error ("nested function `%s' declared `extern'", name);
8376 else if (toplevel_bindings_p ())
8377 {
8378 if (RIDBIT_SETP (RID_AUTO, specbits))
8379 error ("top-level declaration of `%s' specifies `auto'", name);
8380 }
8381
8382 if (nclasses > 0 && friendp)
8383 error ("storage class specifiers invalid in friend function declarations");
8384
8385 /* Now figure out the structure of the declarator proper.
8386 Descend through it, creating more complex types, until we reach
8387 the declared identifier (or NULL_TREE, in an absolute declarator). */
8388
8389 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
8390 {
8391 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
8392 an INDIRECT_REF (for *...),
8393 a CALL_EXPR (for ...(...)),
8394 an identifier (for the name being declared)
8395 or a null pointer (for the place in an absolute declarator
8396 where the name was omitted).
8397 For the last two cases, we have just exited the loop.
8398
8399 For C++ it could also be
8400 a SCOPE_REF (for class :: ...). In this case, we have converted
8401 sensible names to types, and those are the values we use to
8402 qualify the member name.
8403 an ADDR_EXPR (for &...),
8404 a BIT_NOT_EXPR (for destructors)
8405
8406 At this point, TYPE is the type of elements of an array,
8407 or for a function to return, or for a pointer to point to.
8408 After this sequence of ifs, TYPE is the type of the
8409 array or function or pointer, and DECLARATOR has had its
8410 outermost layer removed. */
8411
8412 if (type == error_mark_node)
8413 {
8414 if (TREE_CODE (declarator) == SCOPE_REF)
8415 declarator = TREE_OPERAND (declarator, 1);
8416 else
8417 declarator = TREE_OPERAND (declarator, 0);
8418 continue;
8419 }
8420 if (quals != NULL_TREE
8421 && (declarator == NULL_TREE
8422 || TREE_CODE (declarator) != SCOPE_REF))
8423 {
8424 if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
8425 ctype = TYPE_METHOD_BASETYPE (type);
8426 if (ctype != NULL_TREE)
8427 {
8428 tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
8429 ctype = grok_method_quals (ctype, dummy, quals);
8430 type = TREE_TYPE (dummy);
8431 quals = NULL_TREE;
8432 }
8433 }
8434 switch (TREE_CODE (declarator))
8435 {
8436 case ARRAY_REF:
8437 {
8438 register tree itype = NULL_TREE;
8439 register tree size = TREE_OPERAND (declarator, 1);
8440 /* The index is a signed object `sizetype' bits wide. */
8441 tree index_type = signed_type (sizetype);
8442
8443 declarator = TREE_OPERAND (declarator, 0);
8444
8445 /* Check for some types that there cannot be arrays of. */
8446
8447 if (TYPE_MAIN_VARIANT (type) == void_type_node)
8448 {
8449 cp_error ("declaration of `%D' as array of voids", dname);
8450 type = error_mark_node;
8451 }
8452
8453 if (TREE_CODE (type) == FUNCTION_TYPE)
8454 {
8455 cp_error ("declaration of `%D' as array of functions", dname);
8456 type = error_mark_node;
8457 }
8458
8459 /* ARM $8.4.3: Since you can't have a pointer to a reference,
8460 you can't have arrays of references. If we allowed them,
8461 then we'd be saying x[i] is valid for an array x, but
8462 then you'd have to ask: what does `*(x + i)' mean? */
8463 if (TREE_CODE (type) == REFERENCE_TYPE)
8464 {
8465 if (decl_context == TYPENAME)
8466 cp_error ("cannot make arrays of references");
8467 else
8468 cp_error ("declaration of `%D' as array of references",
8469 dname);
8470 type = error_mark_node;
8471 }
8472
8473 if (TREE_CODE (type) == OFFSET_TYPE)
8474 {
8475 cp_error ("declaration of `%D' as array of data members",
8476 dname);
8477 type = error_mark_node;
8478 }
8479
8480 if (TREE_CODE (type) == METHOD_TYPE)
8481 {
8482 cp_error ("declaration of `%D' as array of function members",
8483 dname);
8484 type = error_mark_node;
8485 }
8486
8487 if (size == error_mark_node)
8488 type = error_mark_node;
8489
8490 if (type == error_mark_node)
8491 continue;
8492
8493 if (size)
8494 {
8495 /* Must suspend_momentary here because the index
8496 type may need to live until the end of the function.
8497 For example, it is used in the declaration of a
8498 variable which requires destructing at the end of
8499 the function; then build_vec_delete will need this
8500 value. */
8501 int yes = suspend_momentary ();
8502 /* might be a cast */
8503 if (TREE_CODE (size) == NOP_EXPR
8504 && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
8505 size = TREE_OPERAND (size, 0);
8506
8507 /* If this involves a template parameter, it'll be
8508 constant, but we don't know what the value is yet. */
8509 if (processing_template_decl)
8510 {
8511 itype = make_node (INTEGER_TYPE);
8512 TYPE_MIN_VALUE (itype) = size_zero_node;
8513 TYPE_MAX_VALUE (itype) = build_min
8514 (MINUS_EXPR, sizetype, size, integer_one_node);
8515 goto dont_grok_size;
8516 }
8517
8518 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
8519 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
8520 {
8521 cp_error ("size of array `%D' has non-integer type",
8522 dname);
8523 size = integer_one_node;
8524 }
8525 if (TREE_READONLY_DECL_P (size))
8526 size = decl_constant_value (size);
8527 if (pedantic && integer_zerop (size))
8528 cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
8529 if (TREE_CONSTANT (size))
8530 {
8531 int old_flag_pedantic_errors = flag_pedantic_errors;
8532 int old_pedantic = pedantic;
8533 pedantic = flag_pedantic_errors = 1;
8534 /* Always give overflow errors on array subscripts. */
8535 constant_expression_warning (size);
8536 pedantic = old_pedantic;
8537 flag_pedantic_errors = old_flag_pedantic_errors;
8538 if (INT_CST_LT (size, integer_zero_node))
8539 {
8540 cp_error ("size of array `%D' is negative", dname);
8541 size = integer_one_node;
8542 }
8543 }
8544 else
8545 {
8546 if (pedantic)
8547 {
8548 if (dname)
8549 cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
8550 dname);
8551 else
8552 cp_pedwarn ("ANSI C++ forbids variable-size array");
8553 }
8554 }
8555
8556 itype
8557 = fold (build_binary_op (MINUS_EXPR,
8558 cp_convert (index_type, size),
8559 cp_convert (index_type,
8560 integer_one_node), 1));
8561 if (! TREE_CONSTANT (itype))
8562 itype = variable_size (itype);
8563 else if (TREE_OVERFLOW (itype))
8564 {
8565 error ("overflow in array dimension");
8566 TREE_OVERFLOW (itype) = 0;
8567 }
8568
8569 /* If we're a parm, we need to have a permanent type so
8570 mangling checks for re-use will work right. If both the
8571 element and index types are permanent, the array type
8572 will be, too. */
8573 if (decl_context == PARM
8574 && allocation_temporary_p () && TREE_PERMANENT (type))
8575 {
8576 push_obstacks (&permanent_obstack, &permanent_obstack);
8577 itype = build_index_type (itype);
8578 pop_obstacks ();
8579 }
8580 else
8581 itype = build_index_type (itype);
8582
8583 dont_grok_size:
8584 resume_momentary (yes);
8585 }
8586
8587 /* Build the array type itself, then merge any constancy or
8588 volatility into the target type. We must do it in this order
8589 to ensure that the TYPE_MAIN_VARIANT field of the array type
8590 is set correctly. */
8591
8592 type = build_cplus_array_type (type, itype);
8593 if (constp || volatilep)
8594 type = cp_build_type_variant (type, constp, volatilep);
8595
8596 ctype = NULL_TREE;
8597 }
8598 break;
8599
8600 case CALL_EXPR:
8601 {
8602 tree arg_types;
8603 int funcdecl_p;
8604 tree inner_parms = TREE_OPERAND (declarator, 1);
8605 tree inner_decl = TREE_OPERAND (declarator, 0);
8606
8607 /* Declaring a function type.
8608 Make sure we have a valid type for the function to return. */
8609 #if 0
8610 /* Is this an error? Should they be merged into TYPE here? */
8611 if (pedantic && (constp || volatilep))
8612 pedwarn ("function declared to return const or volatile result");
8613 #else
8614 /* Merge any constancy or volatility into the function return
8615 type. */
8616
8617 if (constp || volatilep)
8618 {
8619 type = cp_build_type_variant (type, constp, volatilep);
8620 if (IS_AGGR_TYPE (type))
8621 build_pointer_type (type);
8622 constp = 0;
8623 volatilep = 0;
8624 }
8625 #endif
8626
8627 /* Warn about some types functions can't return. */
8628
8629 if (TREE_CODE (type) == FUNCTION_TYPE)
8630 {
8631 error ("`%s' declared as function returning a function", name);
8632 type = integer_type_node;
8633 }
8634 if (TREE_CODE (type) == ARRAY_TYPE)
8635 {
8636 error ("`%s' declared as function returning an array", name);
8637 type = integer_type_node;
8638 }
8639
8640 if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
8641 inner_decl = TREE_OPERAND (inner_decl, 1);
8642
8643 /* Pick up type qualifiers which should be applied to `this'. */
8644 quals = TREE_OPERAND (declarator, 2);
8645
8646 /* Pick up the exception specifications. */
8647 raises = TREE_TYPE (declarator);
8648
8649 /* Say it's a definition only for the CALL_EXPR
8650 closest to the identifier. */
8651 funcdecl_p
8652 = inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE
8653 || TREE_CODE (inner_decl) == BIT_NOT_EXPR);
8654
8655 if (ctype == NULL_TREE
8656 && decl_context == FIELD
8657 && funcdecl_p
8658 && (friendp == 0 || dname == current_class_name))
8659 ctype = current_class_type;
8660
8661 if (ctype && return_type == return_conversion)
8662 TYPE_HAS_CONVERSION (ctype) = 1;
8663 if (ctype && constructor_name (ctype) == dname)
8664 {
8665 /* We are within a class's scope. If our declarator name
8666 is the same as the class name, and we are defining
8667 a function, then it is a constructor/destructor, and
8668 therefore returns a void type. */
8669
8670 if (flags == DTOR_FLAG)
8671 {
8672 /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
8673 not be declared const or volatile. A destructor
8674 may not be static. */
8675 if (staticp == 2)
8676 error ("destructor cannot be static member function");
8677 if (quals)
8678 {
8679 error ("destructors cannot be declared `const' or `volatile'");
8680 return void_type_node;
8681 }
8682 if (decl_context == FIELD)
8683 {
8684 if (! member_function_or_else (ctype, current_class_type,
8685 "destructor for alien class `%s' cannot be a member"))
8686 return void_type_node;
8687 }
8688 }
8689 else /* it's a constructor. */
8690 {
8691 if (explicitp == 1)
8692 explicitp = 2;
8693 /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
8694 not be declared const or volatile. A constructor may
8695 not be virtual. A constructor may not be static. */
8696 if (staticp == 2)
8697 error ("constructor cannot be static member function");
8698 if (virtualp)
8699 {
8700 pedwarn ("constructors cannot be declared virtual");
8701 virtualp = 0;
8702 }
8703 if (quals)
8704 {
8705 error ("constructors cannot be declared `const' or `volatile'");
8706 return void_type_node;
8707 }
8708 {
8709 RID_BIT_TYPE tmp_bits;
8710 bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof (RID_BIT_TYPE));
8711 RIDBIT_RESET (RID_INLINE, tmp_bits);
8712 RIDBIT_RESET (RID_STATIC, tmp_bits);
8713 if (RIDBIT_ANY_SET (tmp_bits))
8714 error ("return value type specifier for constructor ignored");
8715 }
8716 type = build_pointer_type (ctype);
8717 if (decl_context == FIELD
8718 && IS_SIGNATURE (current_class_type))
8719 {
8720 error ("constructor not allowed in signature");
8721 return void_type_node;
8722 }
8723 else if (decl_context == FIELD)
8724 {
8725 if (! member_function_or_else (ctype, current_class_type,
8726 "constructor for alien class `%s' cannot be member"))
8727 return void_type_node;
8728 TYPE_HAS_CONSTRUCTOR (ctype) = 1;
8729 if (return_type != return_ctor)
8730 return NULL_TREE;
8731 }
8732 }
8733 if (decl_context == FIELD)
8734 staticp = 0;
8735 }
8736 else if (friendp)
8737 {
8738 if (initialized)
8739 error ("can't initialize friend function `%s'", name);
8740 if (virtualp)
8741 {
8742 /* Cannot be both friend and virtual. */
8743 error ("virtual functions cannot be friends");
8744 RIDBIT_RESET (RID_FRIEND, specbits);
8745 friendp = 0;
8746 }
8747 if (decl_context == NORMAL)
8748 error ("friend declaration not in class definition");
8749 if (current_function_decl && funcdef_flag)
8750 cp_error ("can't define friend function `%s' in a local class definition",
8751 name);
8752 }
8753
8754 /* Construct the function type and go to the next
8755 inner layer of declarator. */
8756
8757 declarator = TREE_OPERAND (declarator, 0);
8758
8759 /* FIXME: This is where default args should be fully
8760 processed. */
8761
8762 arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0);
8763
8764 if (declarator)
8765 {
8766 /* Get past destructors, etc.
8767 We know we have one because FLAGS will be non-zero.
8768
8769 Complain about improper parameter lists here. */
8770 if (TREE_CODE (declarator) == BIT_NOT_EXPR)
8771 {
8772 declarator = TREE_OPERAND (declarator, 0);
8773
8774 if (strict_prototype == 0 && arg_types == NULL_TREE)
8775 arg_types = void_list_node;
8776 else if (arg_types == NULL_TREE
8777 || arg_types != void_list_node)
8778 {
8779 error ("destructors cannot be specified with parameters");
8780 arg_types = void_list_node;
8781 }
8782 }
8783 }
8784
8785 /* ANSI says that `const int foo ();'
8786 does not make the function foo const. */
8787 type = build_function_type (type, arg_types);
8788
8789 {
8790 tree t;
8791 for (t = arg_types; t; t = TREE_CHAIN (t))
8792 if (TREE_PURPOSE (t)
8793 && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG)
8794 {
8795 add_defarg_fn (type);
8796 break;
8797 }
8798 }
8799 }
8800 break;
8801
8802 case ADDR_EXPR:
8803 case INDIRECT_REF:
8804 /* Filter out pointers-to-references and references-to-references.
8805 We can get these if a TYPE_DECL is used. */
8806
8807 if (TREE_CODE (type) == REFERENCE_TYPE)
8808 {
8809 error ("cannot declare %s to references",
8810 TREE_CODE (declarator) == ADDR_EXPR
8811 ? "references" : "pointers");
8812 declarator = TREE_OPERAND (declarator, 0);
8813 continue;
8814 }
8815
8816 if (TREE_CODE (type) == OFFSET_TYPE
8817 && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE
8818 || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE))
8819 {
8820 cp_error ("cannot declare pointer to `%#T' member",
8821 TREE_TYPE (type));
8822 type = TREE_TYPE (type);
8823 }
8824
8825 /* Merge any constancy or volatility into the target type
8826 for the pointer. */
8827
8828 if (constp || volatilep)
8829 {
8830 /* A const or volatile signature pointer/reference is
8831 pointing to a const or volatile object, i.e., the
8832 `optr' is const or volatile, respectively, not the
8833 signature pointer/reference itself. */
8834 if (! IS_SIGNATURE (type))
8835 {
8836 type = cp_build_type_variant (type, constp, volatilep);
8837 if (IS_AGGR_TYPE (type))
8838 build_pointer_type (type);
8839 constp = 0;
8840 volatilep = 0;
8841 }
8842 }
8843
8844 if (IS_SIGNATURE (type))
8845 {
8846 if (TREE_CODE (declarator) == ADDR_EXPR)
8847 {
8848 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8849 && TYPE_SIZE (type))
8850 cp_warning ("empty signature `%T' used in signature reference declaration",
8851 type);
8852 #if 0
8853 type = build_signature_reference_type (type,
8854 constp, volatilep);
8855 #else
8856 sorry ("signature reference");
8857 return NULL_TREE;
8858 #endif
8859 }
8860 else
8861 {
8862 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8863 && TYPE_SIZE (type))
8864 cp_warning ("empty signature `%T' used in signature pointer declaration",
8865 type);
8866 type = build_signature_pointer_type (type,
8867 constp, volatilep);
8868 }
8869 constp = 0;
8870 volatilep = 0;
8871 }
8872 else if (TREE_CODE (declarator) == ADDR_EXPR)
8873 {
8874 if (TREE_CODE (type) == FUNCTION_TYPE)
8875 {
8876 error ("cannot declare references to functions; use pointer to function instead");
8877 type = build_pointer_type (type);
8878 }
8879 else
8880 {
8881 if (TYPE_MAIN_VARIANT (type) == void_type_node)
8882 error ("invalid type: `void &'");
8883 else
8884 type = build_reference_type (type);
8885 }
8886 }
8887 else if (TREE_CODE (type) == METHOD_TYPE)
8888 {
8889 type = build_ptrmemfunc_type (build_pointer_type (type));
8890 }
8891 else
8892 type = build_pointer_type (type);
8893
8894 /* Process a list of type modifier keywords (such as
8895 const or volatile) that were given inside the `*' or `&'. */
8896
8897 if (TREE_TYPE (declarator))
8898 {
8899 register tree typemodlist;
8900 int erred = 0;
8901 for (typemodlist = TREE_TYPE (declarator); typemodlist;
8902 typemodlist = TREE_CHAIN (typemodlist))
8903 {
8904 if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
8905 constp++;
8906 else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
8907 volatilep++;
8908 else if (!erred)
8909 {
8910 erred = 1;
8911 error ("invalid type modifier within %s declarator",
8912 TREE_CODE (declarator) == ADDR_EXPR
8913 ? "reference" : "pointer");
8914 }
8915 }
8916 if (constp > 1)
8917 pedwarn ("duplicate `const'");
8918 if (volatilep > 1)
8919 pedwarn ("duplicate `volatile'");
8920 if (TREE_CODE (declarator) == ADDR_EXPR
8921 && (constp || volatilep))
8922 {
8923 if (constp)
8924 pedwarn ("discarding `const' applied to a reference");
8925 if (volatilep)
8926 pedwarn ("discarding `volatile' applied to a reference");
8927 constp = volatilep = 0;
8928 }
8929 }
8930 declarator = TREE_OPERAND (declarator, 0);
8931 ctype = NULL_TREE;
8932 break;
8933
8934 case SCOPE_REF:
8935 {
8936 /* We have converted type names to NULL_TREE if the
8937 name was bogus, or to a _TYPE node, if not.
8938
8939 The variable CTYPE holds the type we will ultimately
8940 resolve to. The code here just needs to build
8941 up appropriate member types. */
8942 tree sname = TREE_OPERAND (declarator, 1);
8943 /* Destructors can have their visibilities changed as well. */
8944 if (TREE_CODE (sname) == BIT_NOT_EXPR)
8945 sname = TREE_OPERAND (sname, 0);
8946
8947 if (TREE_COMPLEXITY (declarator) == 0)
8948 /* This needs to be here, in case we are called
8949 multiple times. */ ;
8950 else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
8951 /* don't fall out into global scope. Hides real bug? --eichin */ ;
8952 else if (! IS_AGGR_TYPE_CODE
8953 (TREE_CODE (TREE_OPERAND (declarator, 0))))
8954 ;
8955 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
8956 {
8957 /* Resolve any TYPENAME_TYPEs from the decl-specifier-seq
8958 that refer to ctype. They couldn't be resolved earlier
8959 because we hadn't pushed into the class yet.
8960 Example: resolve 'B<T>::type' in
8961 'B<typename B<T>::type> B<T>::f () { }'. */
8962 if (current_template_parms
8963 && uses_template_parms (type)
8964 && uses_template_parms (current_class_type))
8965 {
8966 tree args = current_template_args ();
8967 type = tsubst (type, args,
8968 TREE_VEC_LENGTH (TREE_VEC_ELT
8969 (args, 0)),
8970 NULL_TREE);
8971 }
8972
8973 /* This pop_nested_class corresponds to the
8974 push_nested_class used to push into class scope for
8975 parsing the argument list of a function decl, in
8976 qualified_id. */
8977 pop_nested_class (1);
8978 TREE_COMPLEXITY (declarator) = current_class_depth;
8979 }
8980 else
8981 my_friendly_abort (16);
8982
8983 if (TREE_OPERAND (declarator, 0) == NULL_TREE)
8984 {
8985 /* We had a reference to a global decl, or
8986 perhaps we were given a non-aggregate typedef,
8987 in which case we cleared this out, and should just
8988 keep going as though it wasn't there. */
8989 declarator = sname;
8990 continue;
8991 }
8992 ctype = TREE_OPERAND (declarator, 0);
8993
8994 if (sname == NULL_TREE)
8995 goto done_scoping;
8996
8997 if (TREE_CODE (sname) == IDENTIFIER_NODE)
8998 {
8999 /* This is the `standard' use of the scoping operator:
9000 basetype :: member . */
9001
9002 if (ctype == current_class_type)
9003 {
9004 /* class A {
9005 void A::f ();
9006 };
9007
9008 Is this ill-formed? */
9009
9010 if (pedantic)
9011 cp_pedwarn ("extra qualification `%T::' on member `%s' ignored",
9012 ctype, name);
9013 }
9014 else if (TREE_CODE (type) == FUNCTION_TYPE)
9015 {
9016 if (current_class_type == NULL_TREE
9017 || friendp)
9018 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9019 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9020 else
9021 {
9022 cp_error ("cannot declare member function `%T::%s' within `%T'",
9023 ctype, name, current_class_type);
9024 return void_type_node;
9025 }
9026 }
9027 else if (RIDBIT_SETP (RID_TYPEDEF, specbits)
9028 || TYPE_SIZE (complete_type (ctype)) != NULL_TREE)
9029 {
9030 /* have to move this code elsewhere in this function.
9031 this code is used for i.e., typedef int A::M; M *pm;
9032
9033 It is? How? jason 10/2/94 */
9034
9035 if (current_class_type)
9036 {
9037 cp_error ("cannot declare member `%T::%s' within `%T'",
9038 ctype, name, current_class_type);
9039 return void_type_node;
9040 }
9041 type = build_offset_type (ctype, type);
9042 }
9043 else if (uses_template_parms (ctype))
9044 {
9045 if (TREE_CODE (type) == FUNCTION_TYPE)
9046 type
9047 = build_cplus_method_type (build_type_variant (ctype,
9048 constp,
9049 volatilep),
9050 TREE_TYPE (type),
9051 TYPE_ARG_TYPES (type));
9052 }
9053 else
9054 {
9055 cp_error ("structure `%T' not yet defined", ctype);
9056 return error_mark_node;
9057 }
9058
9059 declarator = sname;
9060 }
9061 else if (TREE_CODE (sname) == SCOPE_REF)
9062 my_friendly_abort (17);
9063 else
9064 {
9065 done_scoping:
9066 declarator = TREE_OPERAND (declarator, 1);
9067 if (declarator && TREE_CODE (declarator) == CALL_EXPR)
9068 /* In this case, we will deal with it later. */
9069 ;
9070 else
9071 {
9072 if (TREE_CODE (type) == FUNCTION_TYPE)
9073 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
9074 else
9075 type = build_offset_type (ctype, type);
9076 }
9077 }
9078 }
9079 break;
9080
9081 case BIT_NOT_EXPR:
9082 declarator = TREE_OPERAND (declarator, 0);
9083 break;
9084
9085 case RECORD_TYPE:
9086 case UNION_TYPE:
9087 case ENUMERAL_TYPE:
9088 declarator = NULL_TREE;
9089 break;
9090
9091 case ERROR_MARK:
9092 declarator = NULL_TREE;
9093 break;
9094
9095 default:
9096 my_friendly_abort (158);
9097 }
9098 }
9099
9100 if (explicitp == 1)
9101 {
9102 error ("only constructors can be declared `explicit'");
9103 explicitp = 0;
9104 }
9105
9106 /* Now TYPE has the actual type. */
9107
9108 /* If this is declaring a typedef name, return a TYPE_DECL. */
9109
9110 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9111 {
9112 if (constp)
9113 {
9114 error ("const `%s' cannot be declared `mutable'", name);
9115 RIDBIT_RESET (RID_MUTABLE, specbits);
9116 }
9117 else if (staticp)
9118 {
9119 error ("static `%s' cannot be declared `mutable'", name);
9120 RIDBIT_RESET (RID_MUTABLE, specbits);
9121 }
9122 }
9123
9124 if (RIDBIT_SETP (RID_TYPEDEF, specbits) && decl_context != TYPENAME)
9125 {
9126 tree decl;
9127
9128 /* Note that the grammar rejects storage classes
9129 in typenames, fields or parameters. */
9130 if (constp || volatilep)
9131 type = cp_build_type_variant (type, constp, volatilep);
9132
9133 if (decl_context == FIELD)
9134 {
9135 if (declarator == current_class_name)
9136 cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class",
9137 declarator);
9138 decl = build_lang_decl (TYPE_DECL, declarator, type);
9139 if (IS_SIGNATURE (current_class_type) && opaque_typedef)
9140 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
9141 }
9142 else
9143 decl = build_decl (TYPE_DECL, declarator, type);
9144
9145 /* If the user declares "struct {...} foo" then `foo' will have
9146 an anonymous name. Fill that name in now. Nothing can
9147 refer to it, so nothing needs know about the name change.
9148 The TYPE_NAME field was filled in by build_struct_xref. */
9149 if (type != error_mark_node
9150 && TYPE_NAME (type)
9151 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9152 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
9153 {
9154 /* replace the anonymous name with the real name everywhere. */
9155 lookup_tag_reverse (type, declarator);
9156 TYPE_NAME (type) = decl;
9157
9158 if (TYPE_LANG_SPECIFIC (type))
9159 TYPE_WAS_ANONYMOUS (type) = 1;
9160
9161 DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl);
9162 DECL_ASSEMBLER_NAME (decl)
9163 = get_identifier (build_overload_name (type, 1, 1));
9164 }
9165
9166 if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
9167 {
9168 cp_error_at ("typedef name may not be class-qualified", decl);
9169 return NULL_TREE;
9170 }
9171 else if (quals)
9172 {
9173 if (ctype == NULL_TREE)
9174 {
9175 if (TREE_CODE (type) != METHOD_TYPE)
9176 cp_error_at ("invalid type qualifier for non-method type", decl);
9177 else
9178 ctype = TYPE_METHOD_BASETYPE (type);
9179 }
9180 if (ctype != NULL_TREE)
9181 grok_method_quals (ctype, decl, quals);
9182 }
9183
9184 if (RIDBIT_SETP (RID_SIGNED, specbits)
9185 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
9186 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
9187
9188 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9189 {
9190 error ("non-object member `%s' cannot be declared mutable", name);
9191 }
9192
9193 bad_specifiers (decl, "type", virtualp, quals != NULL_TREE,
9194 inlinep, friendp, raises != NULL_TREE);
9195
9196 if (initialized)
9197 error ("typedef declaration includes an initializer");
9198
9199 return decl;
9200 }
9201
9202 /* Detect the case of an array type of unspecified size
9203 which came, as such, direct from a typedef name.
9204 We must copy the type, so that each identifier gets
9205 a distinct type, so that each identifier's size can be
9206 controlled separately by its own initializer. */
9207
9208 if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
9209 && TYPE_DOMAIN (type) == NULL_TREE)
9210 {
9211 type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
9212 }
9213
9214 /* If this is a type name (such as, in a cast or sizeof),
9215 compute the type and return it now. */
9216
9217 if (decl_context == TYPENAME)
9218 {
9219 /* Note that the grammar rejects storage classes
9220 in typenames, fields or parameters. */
9221 if (constp || volatilep)
9222 if (IS_SIGNATURE (type))
9223 error ("`const' or `volatile' specified with signature type");
9224 else
9225 type = cp_build_type_variant (type, constp, volatilep);
9226
9227 /* Special case: "friend class foo" looks like a TYPENAME context. */
9228 if (friendp)
9229 {
9230 if (volatilep)
9231 {
9232 cp_error ("`volatile' specified for friend class declaration");
9233 volatilep = 0;
9234 }
9235 if (inlinep)
9236 {
9237 cp_error ("`inline' specified for friend class declaration");
9238 inlinep = 0;
9239 }
9240
9241 /* Only try to do this stuff if we didn't already give up. */
9242 if (type != integer_type_node)
9243 {
9244 /* A friendly class? */
9245 if (current_class_type)
9246 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
9247 else
9248 error ("trying to make class `%s' a friend of global scope",
9249 TYPE_NAME_STRING (type));
9250 type = void_type_node;
9251 }
9252 }
9253 else if (quals)
9254 {
9255 tree dummy = build_decl (TYPE_DECL, declarator, type);
9256 if (ctype == NULL_TREE)
9257 {
9258 my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
9259 ctype = TYPE_METHOD_BASETYPE (type);
9260 }
9261 grok_method_quals (ctype, dummy, quals);
9262 type = TREE_TYPE (dummy);
9263 }
9264
9265 return type;
9266 }
9267 else if (declarator == NULL_TREE && decl_context != PARM
9268 && decl_context != CATCHPARM
9269 && TREE_CODE (type) != UNION_TYPE
9270 && ! bitfield)
9271 {
9272 cp_error ("abstract declarator `%T' used as declaration", type);
9273 declarator = make_anon_name ();
9274 }
9275
9276 /* `void' at top level (not within pointer)
9277 is allowed only in typedefs or type names.
9278 We don't complain about parms either, but that is because
9279 a better error message can be made later. */
9280
9281 if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
9282 {
9283 if (! declarator)
9284 error ("unnamed variable or field declared void");
9285 else if (TREE_CODE (declarator) == IDENTIFIER_NODE)
9286 {
9287 if (IDENTIFIER_OPNAME_P (declarator))
9288 my_friendly_abort (356);
9289 else
9290 error ("variable or field `%s' declared void", name);
9291 }
9292 else
9293 error ("variable or field declared void");
9294 type = integer_type_node;
9295 }
9296
9297 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
9298 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
9299
9300 {
9301 register tree decl;
9302
9303 if (decl_context == PARM)
9304 {
9305 if (ctype)
9306 error ("cannot use `::' in parameter declaration");
9307
9308 /* A parameter declared as an array of T is really a pointer to T.
9309 One declared as a function is really a pointer to a function.
9310 One declared as a member is really a pointer to member. */
9311
9312 if (TREE_CODE (type) == ARRAY_TYPE)
9313 {
9314 /* Transfer const-ness of array into that of type pointed to. */
9315 type = build_pointer_type
9316 (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
9317 volatilep = constp = 0;
9318 }
9319 else if (TREE_CODE (type) == FUNCTION_TYPE)
9320 type = build_pointer_type (type);
9321 else if (TREE_CODE (type) == OFFSET_TYPE)
9322 type = build_pointer_type (type);
9323 else if (type == void_type_node && declarator)
9324 {
9325 error ("declaration of `%s' as void", name);
9326 return NULL_TREE;
9327 }
9328
9329 decl = build_decl (PARM_DECL, declarator, complete_type (type));
9330
9331 bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
9332 inlinep, friendp, raises != NULL_TREE);
9333 if (current_class_type
9334 && IS_SIGNATURE (current_class_type))
9335 {
9336 if (inlinep)
9337 error ("parameter of signature member function declared `inline'");
9338 if (RIDBIT_SETP (RID_AUTO, specbits))
9339 error ("parameter of signature member function declared `auto'");
9340 if (RIDBIT_SETP (RID_REGISTER, specbits))
9341 error ("parameter of signature member function declared `register'");
9342 }
9343
9344 /* Compute the type actually passed in the parmlist,
9345 for the case where there is no prototype.
9346 (For example, shorts and chars are passed as ints.)
9347 When there is a prototype, this is overridden later. */
9348
9349 DECL_ARG_TYPE (decl) = type_promotes_to (type);
9350 }
9351 else if (decl_context == FIELD)
9352 {
9353 if (type == error_mark_node)
9354 {
9355 /* Happens when declaring arrays of sizes which
9356 are error_mark_node, for example. */
9357 decl = NULL_TREE;
9358 }
9359 else if (TREE_CODE (type) == FUNCTION_TYPE)
9360 {
9361 int publicp = 0;
9362
9363 /* We catch the others as conflicts with the builtin
9364 typedefs. */
9365 if (friendp && declarator == ridpointers[(int) RID_SIGNED])
9366 {
9367 cp_error ("function `%D' cannot be declared friend",
9368 declarator);
9369 friendp = 0;
9370 }
9371
9372 if (friendp == 0)
9373 {
9374 if (ctype == NULL_TREE)
9375 ctype = current_class_type;
9376
9377 if (ctype == NULL_TREE)
9378 {
9379 cp_error ("can't make `%D' into a method -- not in a class",
9380 declarator);
9381 return void_type_node;
9382 }
9383
9384 /* ``A union may [ ... ] not [ have ] virtual functions.''
9385 ARM 9.5 */
9386 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
9387 {
9388 cp_error ("function `%D' declared virtual inside a union",
9389 declarator);
9390 return void_type_node;
9391 }
9392
9393 if (declarator == ansi_opname[(int) NEW_EXPR]
9394 || declarator == ansi_opname[(int) VEC_NEW_EXPR]
9395 || declarator == ansi_opname[(int) DELETE_EXPR]
9396 || declarator == ansi_opname[(int) VEC_DELETE_EXPR])
9397 {
9398 if (virtualp)
9399 {
9400 cp_error ("`%D' cannot be declared virtual, since it is always static",
9401 declarator);
9402 virtualp = 0;
9403 }
9404 }
9405 else if (staticp < 2)
9406 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9407 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9408 }
9409
9410 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
9411 publicp = (! friendp || ! staticp);
9412 decl = grokfndecl (ctype, type, declarator,
9413 virtualp, flags, quals, raises, attrlist,
9414 friendp ? -1 : 0, publicp, inlinep,
9415 funcdef_flag);
9416 if (decl == NULL_TREE)
9417 return NULL_TREE;
9418 #if 0
9419 /* This clobbers the attrs stored in `decl' from `attrlist'. */
9420 /* The decl and setting of decl_machine_attr is also turned off. */
9421 decl = build_decl_attribute_variant (decl, decl_machine_attr);
9422 #endif
9423
9424 if (explicitp == 2)
9425 DECL_NONCONVERTING_P (decl) = 1;
9426 }
9427 else if (TREE_CODE (type) == METHOD_TYPE)
9428 {
9429 /* We only get here for friend declarations of
9430 members of other classes. */
9431 /* All method decls are public, so tell grokfndecl to set
9432 TREE_PUBLIC, also. */
9433 decl = grokfndecl (ctype, type, declarator,
9434 virtualp, flags, quals, raises, attrlist,
9435 friendp ? -1 : 0, 1, 0, funcdef_flag);
9436 if (decl == NULL_TREE)
9437 return NULL_TREE;
9438 }
9439 else if (!staticp && ! processing_template_decl
9440 && TYPE_SIZE (complete_type (type)) == NULL_TREE
9441 && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
9442 {
9443 if (declarator)
9444 cp_error ("field `%D' has incomplete type", declarator);
9445 else
9446 cp_error ("name `%T' has incomplete type", type);
9447
9448 /* If we're instantiating a template, tell them which
9449 instantiation made the field's type be incomplete. */
9450 if (current_class_type
9451 && TYPE_NAME (current_class_type)
9452 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type))
9453 && declspecs && TREE_VALUE (declspecs)
9454 && TREE_TYPE (TREE_VALUE (declspecs)) == type)
9455 cp_error (" in instantiation of template `%T'",
9456 current_class_type);
9457
9458 type = error_mark_node;
9459 decl = NULL_TREE;
9460 }
9461 else
9462 {
9463 if (friendp)
9464 {
9465 error ("`%s' is neither function nor method; cannot be declared friend",
9466 IDENTIFIER_POINTER (declarator));
9467 friendp = 0;
9468 }
9469 decl = NULL_TREE;
9470 }
9471
9472 if (friendp)
9473 {
9474 /* Friends are treated specially. */
9475 if (ctype == current_class_type)
9476 warning ("member functions are implicitly friends of their class");
9477 else
9478 {
9479 tree t = NULL_TREE;
9480 if (decl && DECL_NAME (decl))
9481 t = do_friend (ctype, declarator, decl,
9482 last_function_parms, flags, quals,
9483 funcdef_flag);
9484 if (t && funcdef_flag)
9485 return t;
9486
9487 return void_type_node;
9488 }
9489 }
9490
9491 /* Structure field. It may not be a function, except for C++ */
9492
9493 if (decl == NULL_TREE)
9494 {
9495 if (initialized)
9496 {
9497 /* Motion 10 at San Diego: If a static const integral data
9498 member is initialized with an integral constant
9499 expression, the initializer may appear either in the
9500 declaration (within the class), or in the definition,
9501 but not both. If it appears in the class, the member is
9502 a member constant. The file-scope definition is always
9503 required. */
9504 if (staticp)
9505 {
9506 if (pedantic)
9507 {
9508 if (! constp)
9509 cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
9510 declarator);
9511
9512 else if (! INTEGRAL_TYPE_P (type))
9513 cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type);
9514 }
9515 }
9516
9517 /* Note that initialization of const members is prohibited
9518 by the draft ANSI standard, though it appears to be in
9519 common practice. 12.6.2: The argument list is used to
9520 initialize the named nonstatic member.... This (or an
9521 initializer list) is the only way to initialize
9522 nonstatic const and reference members. */
9523 else if (pedantic || ! constp)
9524 cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
9525 constp ? "const member" : "member", declarator);
9526 }
9527
9528 if (staticp || (constp && initialized))
9529 {
9530 /* ANSI C++ Apr '95 wp 9.2 */
9531 if (staticp && declarator == current_class_name)
9532 cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class",
9533 declarator);
9534
9535 /* C++ allows static class members.
9536 All other work for this is done by grokfield.
9537 This VAR_DECL is built by build_lang_field_decl.
9538 All other VAR_DECLs are built by build_decl. */
9539 decl = build_lang_field_decl (VAR_DECL, declarator, type);
9540 TREE_STATIC (decl) = 1;
9541 /* In class context, 'static' means public access. */
9542 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp;
9543 }
9544 else
9545 {
9546 decl = build_lang_field_decl (FIELD_DECL, declarator, type);
9547 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9548 {
9549 DECL_MUTABLE_P (decl) = 1;
9550 RIDBIT_RESET (RID_MUTABLE, specbits);
9551 }
9552 }
9553
9554 bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
9555 inlinep, friendp, raises != NULL_TREE);
9556 }
9557 }
9558 else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
9559 {
9560 tree original_name = declarator;
9561 int publicp = 0;
9562
9563 if (! declarator)
9564 return NULL_TREE;
9565
9566 if (RIDBIT_SETP (RID_AUTO, specbits))
9567 error ("storage class `auto' invalid for function `%s'", name);
9568 else if (RIDBIT_SETP (RID_REGISTER, specbits))
9569 error ("storage class `register' invalid for function `%s'", name);
9570
9571 /* Function declaration not at top level.
9572 Storage classes other than `extern' are not allowed
9573 and `extern' makes no difference. */
9574 if (! toplevel_bindings_p ()
9575 && (RIDBIT_SETP (RID_STATIC, specbits)
9576 || RIDBIT_SETP (RID_INLINE, specbits))
9577 && pedantic)
9578 {
9579 if (RIDBIT_SETP (RID_STATIC, specbits))
9580 pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
9581 else
9582 pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
9583 }
9584
9585 if (ctype == NULL_TREE)
9586 {
9587 if (virtualp)
9588 {
9589 error ("virtual non-class function `%s'", name);
9590 virtualp = 0;
9591 }
9592
9593 if (current_lang_name == lang_name_cplusplus
9594 && ! processing_template_decl
9595 && ! (IDENTIFIER_LENGTH (original_name) == 4
9596 && IDENTIFIER_POINTER (original_name)[0] == 'm'
9597 && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
9598 && ! (IDENTIFIER_LENGTH (original_name) > 10
9599 && IDENTIFIER_POINTER (original_name)[0] == '_'
9600 && IDENTIFIER_POINTER (original_name)[1] == '_'
9601 && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
9602 /* Plain overloading: will not be grok'd by grokclassfn. */
9603 declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
9604 }
9605 else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
9606 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9607 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9608
9609 /* Record presence of `static'. */
9610 publicp = (ctype != NULL_TREE
9611 || RIDBIT_SETP (RID_EXTERN, specbits)
9612 || !RIDBIT_SETP (RID_STATIC, specbits));
9613
9614 decl = grokfndecl (ctype, type, original_name,
9615 virtualp, flags, quals, raises, attrlist,
9616 friendp ? 2 : 1,
9617 publicp, inlinep, funcdef_flag);
9618 if (decl == NULL_TREE)
9619 return NULL_TREE;
9620
9621 if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
9622 DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator);
9623
9624 if (staticp == 1)
9625 {
9626 int illegal_static = 0;
9627
9628 /* Don't allow a static member function in a class, and forbid
9629 declaring main to be static. */
9630 if (TREE_CODE (type) == METHOD_TYPE)
9631 {
9632 cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl);
9633 illegal_static = 1;
9634 }
9635 else if (current_function_decl)
9636 {
9637 /* FIXME need arm citation */
9638 error ("cannot declare static function inside another function");
9639 illegal_static = 1;
9640 }
9641
9642 if (illegal_static)
9643 {
9644 staticp = 0;
9645 RIDBIT_RESET (RID_STATIC, specbits);
9646 }
9647 }
9648 }
9649 else
9650 {
9651 /* It's a variable. */
9652
9653 if (decl_context == CATCHPARM)
9654 {
9655 if (ctype)
9656 {
9657 ctype = NULL_TREE;
9658 error ("cannot use `::' in parameter declaration");
9659 }
9660
9661 /* A parameter declared as an array of T is really a pointer to T.
9662 One declared as a function is really a pointer to a function.
9663 One declared as a member is really a pointer to member. */
9664
9665 if (TREE_CODE (type) == ARRAY_TYPE)
9666 {
9667 /* Transfer const-ness of array into that of type
9668 pointed to. */
9669 type = build_pointer_type
9670 (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
9671 volatilep = constp = 0;
9672 }
9673 else if (TREE_CODE (type) == FUNCTION_TYPE)
9674 type = build_pointer_type (type);
9675 else if (TREE_CODE (type) == OFFSET_TYPE)
9676 type = build_pointer_type (type);
9677 }
9678
9679 /* An uninitialized decl with `extern' is a reference. */
9680 decl = grokvardecl (type, declarator, &specbits, initialized, constp);
9681 bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
9682 inlinep, friendp, raises != NULL_TREE);
9683
9684 if (ctype)
9685 {
9686 DECL_CONTEXT (decl) = ctype;
9687 if (staticp == 1)
9688 {
9689 cp_pedwarn ("static member `%D' re-declared as static", decl);
9690 staticp = 0;
9691 RIDBIT_RESET (RID_STATIC, specbits);
9692 }
9693 if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl))
9694 {
9695 cp_error ("static member `%D' declared `register'", decl);
9696 RIDBIT_RESET (RID_REGISTER, specbits);
9697 }
9698 if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic)
9699 {
9700 cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage",
9701 decl);
9702 RIDBIT_RESET (RID_EXTERN, specbits);
9703 }
9704 }
9705 }
9706
9707 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9708 {
9709 error ("`%s' cannot be declared mutable", name);
9710 }
9711
9712 /* Record `register' declaration for warnings on &
9713 and in case doing stupid register allocation. */
9714
9715 if (RIDBIT_SETP (RID_REGISTER, specbits))
9716 DECL_REGISTER (decl) = 1;
9717
9718 if (RIDBIT_SETP (RID_EXTERN, specbits))
9719 DECL_THIS_EXTERN (decl) = 1;
9720
9721 if (RIDBIT_SETP (RID_STATIC, specbits))
9722 DECL_THIS_STATIC (decl) = 1;
9723
9724 /* Record constancy and volatility. */
9725
9726 if (constp)
9727 TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
9728 if (volatilep)
9729 {
9730 TREE_SIDE_EFFECTS (decl) = 1;
9731 TREE_THIS_VOLATILE (decl) = 1;
9732 }
9733
9734 return decl;
9735 }
9736 }
9737 \f
9738 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
9739 An empty exprlist is a parmlist. An exprlist which
9740 contains only identifiers at the global level
9741 is a parmlist. Otherwise, it is an exprlist. */
9742
9743 int
9744 parmlist_is_exprlist (exprs)
9745 tree exprs;
9746 {
9747 if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
9748 return 0;
9749
9750 if (toplevel_bindings_p ())
9751 {
9752 /* At the global level, if these are all identifiers,
9753 then it is a parmlist. */
9754 while (exprs)
9755 {
9756 if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
9757 return 1;
9758 exprs = TREE_CHAIN (exprs);
9759 }
9760 return 0;
9761 }
9762 return 1;
9763 }
9764
9765 /* Subroutine of `grokparms'. In a fcn definition, arg types must
9766 be complete.
9767
9768 C++: also subroutine of `start_function'. */
9769
9770 static void
9771 require_complete_types_for_parms (parms)
9772 tree parms;
9773 {
9774 if (processing_template_decl)
9775 return;
9776
9777 while (parms)
9778 {
9779 tree type = TREE_TYPE (parms);
9780 if (TYPE_SIZE (complete_type (type)) == NULL_TREE)
9781 {
9782 if (DECL_NAME (parms))
9783 error ("parameter `%s' has incomplete type",
9784 IDENTIFIER_POINTER (DECL_NAME (parms)));
9785 else
9786 error ("parameter has incomplete type");
9787 TREE_TYPE (parms) = error_mark_node;
9788 }
9789 #if 0
9790 /* If the arg types are incomplete in a declaration,
9791 they must include undefined tags.
9792 These tags can never be defined in the scope of the declaration,
9793 so the types can never be completed,
9794 and no call can be compiled successfully. */
9795 /* This is not the right behavior for C++, but not having
9796 it is also probably wrong. */
9797 else
9798 {
9799 /* Now warn if is a pointer to an incomplete type. */
9800 while (TREE_CODE (type) == POINTER_TYPE
9801 || TREE_CODE (type) == REFERENCE_TYPE)
9802 type = TREE_TYPE (type);
9803 type = TYPE_MAIN_VARIANT (type);
9804 if (TYPE_SIZE (type) == NULL_TREE)
9805 {
9806 if (DECL_NAME (parm) != NULL_TREE)
9807 warning ("parameter `%s' points to incomplete type",
9808 IDENTIFIER_POINTER (DECL_NAME (parm)));
9809 else
9810 warning ("parameter points to incomplete type");
9811 }
9812 }
9813 #endif
9814 parms = TREE_CHAIN (parms);
9815 }
9816 }
9817
9818 /* Decode the list of parameter types for a function type.
9819 Given the list of things declared inside the parens,
9820 return a list of types.
9821
9822 The list we receive can have three kinds of elements:
9823 an IDENTIFIER_NODE for names given without types,
9824 a TREE_LIST node for arguments given as typespecs or names with typespecs,
9825 or void_type_node, to mark the end of an argument list
9826 when additional arguments are not permitted (... was not used).
9827
9828 FUNCDEF_FLAG is nonzero for a function definition, 0 for
9829 a mere declaration. A nonempty identifier-list gets an error message
9830 when FUNCDEF_FLAG is zero.
9831 If FUNCDEF_FLAG is 1, then parameter types must be complete.
9832 If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9833
9834 If all elements of the input list contain types,
9835 we return a list of the types.
9836 If all elements contain no type (except perhaps a void_type_node
9837 at the end), we return a null list.
9838 If some have types and some do not, it is an error, and we
9839 return a null list.
9840
9841 Also set last_function_parms to either
9842 a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9843 A list of names is converted to a chain of PARM_DECLs
9844 by store_parm_decls so that ultimately it is always a chain of decls.
9845
9846 Note that in C++, parameters can take default values. These default
9847 values are in the TREE_PURPOSE field of the TREE_LIST. It is
9848 an error to specify default values which are followed by parameters
9849 that have no default values, or an ELLIPSES. For simplicities sake,
9850 only parameters which are specified with their types can take on
9851 default values. */
9852
9853 static tree
9854 grokparms (first_parm, funcdef_flag)
9855 tree first_parm;
9856 int funcdef_flag;
9857 {
9858 tree result = NULL_TREE;
9859 tree decls = NULL_TREE;
9860
9861 if (first_parm != NULL_TREE
9862 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
9863 {
9864 if (! funcdef_flag)
9865 pedwarn ("parameter names (without types) in function declaration");
9866 last_function_parms = first_parm;
9867 return NULL_TREE;
9868 }
9869 else if (first_parm != NULL_TREE
9870 && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
9871 && TREE_VALUE (first_parm) != void_type_node)
9872 my_friendly_abort (145);
9873 else
9874 {
9875 /* Types were specified. This is a list of declarators
9876 each represented as a TREE_LIST node. */
9877 register tree parm, chain;
9878 int any_init = 0, any_error = 0;
9879
9880 if (first_parm != NULL_TREE)
9881 {
9882 tree last_result = NULL_TREE;
9883 tree last_decl = NULL_TREE;
9884
9885 for (parm = first_parm; parm != NULL_TREE; parm = chain)
9886 {
9887 tree type, list_node = parm;
9888 register tree decl = TREE_VALUE (parm);
9889 tree init = TREE_PURPOSE (parm);
9890
9891 chain = TREE_CHAIN (parm);
9892 /* @@ weak defense against parse errors. */
9893 if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
9894 {
9895 /* Give various messages as the need arises. */
9896 if (TREE_CODE (decl) == STRING_CST)
9897 cp_error ("invalid string constant `%E'", decl);
9898 else if (TREE_CODE (decl) == INTEGER_CST)
9899 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9900 continue;
9901 }
9902
9903 if (decl != void_type_node)
9904 {
9905 decl = grokdeclarator (TREE_VALUE (decl),
9906 TREE_PURPOSE (decl),
9907 PARM, init != NULL_TREE,
9908 NULL_TREE);
9909 if (! decl)
9910 continue;
9911 type = TREE_TYPE (decl);
9912 if (TYPE_MAIN_VARIANT (type) == void_type_node)
9913 decl = void_type_node;
9914 else if (TREE_CODE (type) == METHOD_TYPE)
9915 {
9916 if (DECL_NAME (decl))
9917 /* Cannot use the decl here because
9918 we don't have DECL_CONTEXT set up yet. */
9919 cp_error ("parameter `%D' invalidly declared method type",
9920 DECL_NAME (decl));
9921 else
9922 error ("parameter invalidly declared method type");
9923 type = build_pointer_type (type);
9924 TREE_TYPE (decl) = type;
9925 }
9926 else if (TREE_CODE (type) == OFFSET_TYPE)
9927 {
9928 if (DECL_NAME (decl))
9929 cp_error ("parameter `%D' invalidly declared offset type",
9930 DECL_NAME (decl));
9931 else
9932 error ("parameter invalidly declared offset type");
9933 type = build_pointer_type (type);
9934 TREE_TYPE (decl) = type;
9935 }
9936 else if (TREE_CODE (type) == RECORD_TYPE
9937 && TYPE_LANG_SPECIFIC (type)
9938 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
9939 {
9940 abstract_virtuals_error (decl, type);
9941 any_error = 1; /* seems like a good idea */
9942 }
9943 else if (TREE_CODE (type) == RECORD_TYPE
9944 && TYPE_LANG_SPECIFIC (type)
9945 && IS_SIGNATURE (type))
9946 {
9947 signature_error (decl, type);
9948 any_error = 1; /* seems like a good idea */
9949 }
9950 }
9951
9952 if (decl == void_type_node)
9953 {
9954 if (result == NULL_TREE)
9955 {
9956 result = void_list_node;
9957 last_result = result;
9958 }
9959 else
9960 {
9961 TREE_CHAIN (last_result) = void_list_node;
9962 last_result = void_list_node;
9963 }
9964 if (chain
9965 && (chain != void_list_node || TREE_CHAIN (chain)))
9966 error ("`void' in parameter list must be entire list");
9967 break;
9968 }
9969
9970 /* Since there is a prototype, args are passed in their own types. */
9971 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
9972 #ifdef PROMOTE_PROTOTYPES
9973 if ((TREE_CODE (type) == INTEGER_TYPE
9974 || TREE_CODE (type) == ENUMERAL_TYPE)
9975 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
9976 DECL_ARG_TYPE (decl) = integer_type_node;
9977 #endif
9978 if (!any_error)
9979 {
9980 if (init)
9981 {
9982 any_init++;
9983 if (TREE_CODE (init) == SAVE_EXPR)
9984 PARM_DECL_EXPR (init) = 1;
9985 else if (processing_template_decl)
9986 ;
9987 /* Unparsed default arg from in-class decl. */
9988 else if (TREE_CODE (init) == DEFAULT_ARG)
9989 ;
9990 else if (TREE_CODE (init) == VAR_DECL
9991 || TREE_CODE (init) == PARM_DECL)
9992 {
9993 if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
9994 {
9995 /* ``Local variables may not be used in default
9996 argument expressions.'' dpANSI C++ 8.2.6 */
9997 /* If extern int i; within a function is not
9998 considered a local variable, then this code is
9999 wrong. */
10000 cp_error ("local variable `%D' may not be used as a default argument", init);
10001 any_error = 1;
10002 }
10003 else if (TREE_READONLY_DECL_P (init))
10004 init = decl_constant_value (init);
10005 }
10006 else
10007 init = require_instantiated_type (type, init, integer_zero_node);
10008 if (! processing_template_decl
10009 && TREE_CODE (init) != DEFAULT_ARG
10010 && ! can_convert_arg (type, TREE_TYPE (init), init))
10011 cp_pedwarn ("invalid type `%T' for default argument to `%#D'",
10012 TREE_TYPE (init), decl);
10013 }
10014 }
10015 else
10016 init = NULL_TREE;
10017
10018 if (decls == NULL_TREE)
10019 {
10020 decls = decl;
10021 last_decl = decls;
10022 }
10023 else
10024 {
10025 TREE_CHAIN (last_decl) = decl;
10026 last_decl = decl;
10027 }
10028 if (TREE_PERMANENT (list_node))
10029 {
10030 TREE_PURPOSE (list_node) = init;
10031 TREE_VALUE (list_node) = type;
10032 TREE_CHAIN (list_node) = NULL_TREE;
10033 }
10034 else
10035 list_node = saveable_tree_cons (init, type, NULL_TREE);
10036 if (result == NULL_TREE)
10037 {
10038 result = list_node;
10039 last_result = result;
10040 }
10041 else
10042 {
10043 TREE_CHAIN (last_result) = list_node;
10044 last_result = list_node;
10045 }
10046 }
10047 if (last_result)
10048 TREE_CHAIN (last_result) = NULL_TREE;
10049 /* If there are no parameters, and the function does not end
10050 with `...', then last_decl will be NULL_TREE. */
10051 if (last_decl != NULL_TREE)
10052 TREE_CHAIN (last_decl) = NULL_TREE;
10053 }
10054 }
10055
10056 last_function_parms = decls;
10057
10058 /* In a fcn definition, arg types must be complete. */
10059 if (funcdef_flag > 0)
10060 require_complete_types_for_parms (last_function_parms);
10061
10062 return result;
10063 }
10064
10065 /* Called from the parser to update an element of TYPE_ARG_TYPES for some
10066 FUNCTION_TYPE with the newly parsed version of its default argument, which
10067 was previously digested as text. See snarf_defarg et al in lex.c. */
10068
10069 void
10070 replace_defarg (arg, init)
10071 tree arg, init;
10072 {
10073 if (! processing_template_decl && ! uses_template_parms (TREE_VALUE (arg))
10074 && ! can_convert_arg (TREE_VALUE (arg), TREE_TYPE (init), init))
10075 cp_pedwarn ("invalid type `%T' for default argument to `%T'",
10076 TREE_TYPE (init), TREE_VALUE (arg));
10077 TREE_PURPOSE (arg) = init;
10078 }
10079 \f
10080 int
10081 copy_args_p (d)
10082 tree d;
10083 {
10084 tree t = FUNCTION_ARG_CHAIN (d);
10085 if (t && TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE
10086 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (t)))
10087 == DECL_CLASS_CONTEXT (d))
10088 && (TREE_CHAIN (t) == NULL_TREE
10089 || TREE_CHAIN (t) == void_list_node
10090 || TREE_PURPOSE (TREE_CHAIN (t))))
10091 return 1;
10092 return 0;
10093 }
10094
10095 /* These memoizing functions keep track of special properties which
10096 a class may have. `grok_ctor_properties' notices whether a class
10097 has a constructor of the form X(X&), and also complains
10098 if the class has a constructor of the form X(X).
10099 `grok_op_properties' takes notice of the various forms of
10100 operator= which are defined, as well as what sorts of type conversion
10101 may apply. Both functions take a FUNCTION_DECL as an argument. */
10102
10103 int
10104 grok_ctor_properties (ctype, decl)
10105 tree ctype, decl;
10106 {
10107 tree parmtypes = FUNCTION_ARG_CHAIN (decl);
10108 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
10109
10110 /* When a type has virtual baseclasses, a magical first int argument is
10111 added to any ctor so we can tell if the class has been initialized
10112 yet. This could screw things up in this function, so we deliberately
10113 ignore the leading int if we're in that situation. */
10114 if (parmtypes
10115 && TREE_VALUE (parmtypes) == integer_type_node
10116 && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
10117 {
10118 parmtypes = TREE_CHAIN (parmtypes);
10119 parmtype = TREE_VALUE (parmtypes);
10120 }
10121
10122 if (TREE_CODE (parmtype) == REFERENCE_TYPE
10123 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
10124 {
10125 if (TREE_CHAIN (parmtypes) == NULL_TREE
10126 || TREE_CHAIN (parmtypes) == void_list_node
10127 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
10128 {
10129 TYPE_HAS_INIT_REF (ctype) = 1;
10130 if (TYPE_READONLY (TREE_TYPE (parmtype)))
10131 TYPE_HAS_CONST_INIT_REF (ctype) = 1;
10132 }
10133 else
10134 TYPE_GETS_INIT_AGGR (ctype) = 1;
10135 }
10136 else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
10137 {
10138 if (TREE_CHAIN (parmtypes) != NULL_TREE
10139 && TREE_CHAIN (parmtypes) == void_list_node)
10140 {
10141 cp_error ("invalid constructor; you probably meant `%T (const %T&)'",
10142 ctype, ctype);
10143 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
10144
10145 return 0;
10146 }
10147 else
10148 TYPE_GETS_INIT_AGGR (ctype) = 1;
10149 }
10150 else if (TREE_CODE (parmtype) == VOID_TYPE
10151 || TREE_PURPOSE (parmtypes) != NULL_TREE)
10152 TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
10153
10154 return 1;
10155 }
10156
10157 /* An operator with this name can be either unary or binary. */
10158
10159 static int
10160 ambi_op_p (name)
10161 tree name;
10162 {
10163 return (name == ansi_opname [(int) INDIRECT_REF]
10164 || name == ansi_opname [(int) ADDR_EXPR]
10165 || name == ansi_opname [(int) NEGATE_EXPR]
10166 || name == ansi_opname[(int) POSTINCREMENT_EXPR]
10167 || name == ansi_opname[(int) POSTDECREMENT_EXPR]
10168 || name == ansi_opname [(int) CONVERT_EXPR]);
10169 }
10170
10171 /* An operator with this name can only be unary. */
10172
10173 static int
10174 unary_op_p (name)
10175 tree name;
10176 {
10177 return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
10178 || name == ansi_opname [(int) BIT_NOT_EXPR]
10179 || name == ansi_opname [(int) COMPONENT_REF]
10180 || OPERATOR_TYPENAME_P (name));
10181 }
10182
10183 /* Do a little sanity-checking on how they declared their operator. */
10184
10185 void
10186 grok_op_properties (decl, virtualp, friendp)
10187 tree decl;
10188 int virtualp, friendp;
10189 {
10190 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
10191 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
10192 tree name = DECL_NAME (decl);
10193
10194 if (current_class_type == NULL_TREE)
10195 friendp = 1;
10196
10197 if (! friendp)
10198 {
10199 if (name == ansi_opname[(int) MODIFY_EXPR])
10200 TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
10201 else if (name == ansi_opname[(int) CALL_EXPR])
10202 TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
10203 else if (name == ansi_opname[(int) ARRAY_REF])
10204 TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
10205 else if (name == ansi_opname[(int) COMPONENT_REF]
10206 || name == ansi_opname[(int) MEMBER_REF])
10207 TYPE_OVERLOADS_ARROW (current_class_type) = 1;
10208 else if (name == ansi_opname[(int) NEW_EXPR])
10209 TYPE_GETS_NEW (current_class_type) |= 1;
10210 else if (name == ansi_opname[(int) DELETE_EXPR])
10211 TYPE_GETS_DELETE (current_class_type) |= 1;
10212 else if (name == ansi_opname[(int) VEC_NEW_EXPR])
10213 TYPE_GETS_NEW (current_class_type) |= 2;
10214 else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
10215 TYPE_GETS_DELETE (current_class_type) |= 2;
10216 }
10217
10218 if (name == ansi_opname[(int) NEW_EXPR]
10219 || name == ansi_opname[(int) VEC_NEW_EXPR])
10220 {
10221 /* When the compiler encounters the definition of A::operator new, it
10222 doesn't look at the class declaration to find out if it's static. */
10223 if (methodp)
10224 revert_static_member_fn (&decl, NULL, NULL);
10225
10226 /* Take care of function decl if we had syntax errors. */
10227 if (argtypes == NULL_TREE)
10228 TREE_TYPE (decl)
10229 = build_function_type (ptr_type_node,
10230 hash_tree_chain (integer_type_node,
10231 void_list_node));
10232 else
10233 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
10234 }
10235 else if (name == ansi_opname[(int) DELETE_EXPR]
10236 || name == ansi_opname[(int) VEC_DELETE_EXPR])
10237 {
10238 if (methodp)
10239 revert_static_member_fn (&decl, NULL, NULL);
10240
10241 if (argtypes == NULL_TREE)
10242 TREE_TYPE (decl)
10243 = build_function_type (void_type_node,
10244 hash_tree_chain (ptr_type_node,
10245 void_list_node));
10246 else
10247 {
10248 TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
10249
10250 if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR]
10251 && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
10252 != void_list_node))
10253 TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1;
10254 }
10255 }
10256 else
10257 {
10258 /* An operator function must either be a non-static member function
10259 or have at least one parameter of a class, a reference to a class,
10260 an enumeration, or a reference to an enumeration. 13.4.0.6 */
10261 if (! methodp || DECL_STATIC_FUNCTION_P (decl))
10262 {
10263 if (OPERATOR_TYPENAME_P (name)
10264 || name == ansi_opname[(int) CALL_EXPR]
10265 || name == ansi_opname[(int) MODIFY_EXPR]
10266 || name == ansi_opname[(int) COMPONENT_REF]
10267 || name == ansi_opname[(int) ARRAY_REF])
10268 cp_error ("`%D' must be a nonstatic member function", decl);
10269 else
10270 {
10271 tree p = argtypes;
10272
10273 if (DECL_STATIC_FUNCTION_P (decl))
10274 cp_error ("`%D' must be either a non-static member function or a non-member function", decl);
10275
10276 if (p)
10277 for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
10278 {
10279 tree arg = TREE_VALUE (p);
10280 if (TREE_CODE (arg) == REFERENCE_TYPE)
10281 arg = TREE_TYPE (arg);
10282
10283 /* This lets bad template code slip through. */
10284 if (IS_AGGR_TYPE (arg)
10285 || TREE_CODE (arg) == ENUMERAL_TYPE
10286 || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
10287 goto foundaggr;
10288 }
10289 cp_error
10290 ("`%D' must have an argument of class or enumerated type",
10291 decl);
10292 foundaggr:
10293 ;
10294 }
10295 }
10296
10297 if (name == ansi_opname[(int) CALL_EXPR]
10298 || name == ansi_opname[(int) METHOD_CALL_EXPR])
10299 return; /* no restrictions on args */
10300
10301 if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl))
10302 {
10303 tree t = TREE_TYPE (name);
10304 if (TREE_CODE (t) == VOID_TYPE)
10305 pedwarn ("void is not a valid type conversion operator");
10306 else if (! friendp)
10307 {
10308 int ref = (TREE_CODE (t) == REFERENCE_TYPE);
10309 char *what = 0;
10310 if (ref)
10311 t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
10312
10313 if (t == current_class_type)
10314 what = "the same type";
10315 /* Don't force t to be complete here. */
10316 else if (IS_AGGR_TYPE (t)
10317 && TYPE_SIZE (t)
10318 && DERIVED_FROM_P (t, current_class_type))
10319 what = "a base class";
10320
10321 if (what)
10322 warning ("conversion to %s%s will never use a type conversion operator",
10323 ref ? "a reference to " : "", what);
10324 }
10325 }
10326
10327 if (name == ansi_opname[(int) MODIFY_EXPR])
10328 {
10329 tree parmtype;
10330
10331 if (list_length (argtypes) != 3 && methodp)
10332 {
10333 cp_error ("`%D' must take exactly one argument", decl);
10334 return;
10335 }
10336 parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
10337
10338 if (copy_assignment_arg_p (parmtype, virtualp)
10339 && ! friendp)
10340 {
10341 TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
10342 if (TREE_CODE (parmtype) != REFERENCE_TYPE
10343 || TYPE_READONLY (TREE_TYPE (parmtype)))
10344 TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
10345 }
10346 }
10347 else if (name == ansi_opname[(int) COND_EXPR])
10348 {
10349 /* 13.4.0.3 */
10350 pedwarn ("ANSI C++ prohibits overloading operator ?:");
10351 if (list_length (argtypes) != 4)
10352 cp_error ("`%D' must take exactly three arguments", decl);
10353 }
10354 else if (ambi_op_p (name))
10355 {
10356 if (list_length (argtypes) == 2)
10357 /* prefix */;
10358 else if (list_length (argtypes) == 3)
10359 {
10360 if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
10361 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
10362 && ! processing_template_decl
10363 && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
10364 {
10365 if (methodp)
10366 cp_error ("postfix `%D' must take `int' as its argument",
10367 decl);
10368 else
10369 cp_error
10370 ("postfix `%D' must take `int' as its second argument",
10371 decl);
10372 }
10373 }
10374 else
10375 {
10376 if (methodp)
10377 cp_error ("`%D' must take either zero or one argument", decl);
10378 else
10379 cp_error ("`%D' must take either one or two arguments", decl);
10380 }
10381
10382 /* More Effective C++ rule 6. */
10383 if (warn_ecpp
10384 && (name == ansi_opname[(int) POSTINCREMENT_EXPR]
10385 || name == ansi_opname[(int) POSTDECREMENT_EXPR]))
10386 {
10387 tree arg = TREE_VALUE (argtypes);
10388 tree ret = TREE_TYPE (TREE_TYPE (decl));
10389 if (methodp || TREE_CODE (arg) == REFERENCE_TYPE)
10390 arg = TREE_TYPE (arg);
10391 arg = TYPE_MAIN_VARIANT (arg);
10392 if (list_length (argtypes) == 2)
10393 {
10394 if (TREE_CODE (ret) != REFERENCE_TYPE
10395 || !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ret)),
10396 arg, 1))
10397 cp_warning ("prefix `%D' should return `%T'", decl,
10398 build_reference_type (arg));
10399 }
10400 else
10401 {
10402 if (!comptypes (TYPE_MAIN_VARIANT (ret), arg, 1))
10403 cp_warning ("postfix `%D' should return `%T'", decl, arg);
10404 }
10405 }
10406 }
10407 else if (unary_op_p (name))
10408 {
10409 if (list_length (argtypes) != 2)
10410 {
10411 if (methodp)
10412 cp_error ("`%D' must take `void'", decl);
10413 else
10414 cp_error ("`%D' must take exactly one argument", decl);
10415 }
10416 }
10417 else /* if (binary_op_p (name)) */
10418 {
10419 if (list_length (argtypes) != 3)
10420 {
10421 if (methodp)
10422 cp_error ("`%D' must take exactly one argument", decl);
10423 else
10424 cp_error ("`%D' must take exactly two arguments", decl);
10425 }
10426
10427 /* More Effective C++ rule 7. */
10428 if (warn_ecpp
10429 && (name == ansi_opname [TRUTH_ANDIF_EXPR]
10430 || name == ansi_opname [TRUTH_ORIF_EXPR]
10431 || name == ansi_opname [COMPOUND_EXPR]))
10432 cp_warning ("user-defined `%D' always evaluates both arguments",
10433 decl);
10434 }
10435
10436 /* Effective C++ rule 23. */
10437 if (warn_ecpp
10438 && list_length (argtypes) == 3
10439 && (name == ansi_opname [PLUS_EXPR]
10440 || name == ansi_opname [MINUS_EXPR]
10441 || name == ansi_opname [TRUNC_DIV_EXPR]
10442 || name == ansi_opname [MULT_EXPR])
10443 && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE)
10444 cp_warning ("`%D' should return by value", decl);
10445
10446 /* 13.4.0.8 */
10447 if (argtypes)
10448 for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
10449 if (TREE_PURPOSE (argtypes))
10450 {
10451 TREE_PURPOSE (argtypes) = NULL_TREE;
10452 if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
10453 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
10454 {
10455 if (pedantic)
10456 cp_pedwarn ("`%D' cannot have default arguments", decl);
10457 }
10458 else
10459 cp_error ("`%D' cannot have default arguments", decl);
10460 }
10461 }
10462 }
10463 \f
10464 /* Get the struct, enum or union (CODE says which) with tag NAME.
10465 Define the tag as a forward-reference if it is not defined.
10466
10467 C++: If a class derivation is given, process it here, and report
10468 an error if multiple derivation declarations are not identical.
10469
10470 If this is a definition, come in through xref_tag and only look in
10471 the current frame for the name (since C++ allows new names in any
10472 scope.) */
10473
10474 tree
10475 xref_tag (code_type_node, name, binfo, globalize)
10476 tree code_type_node;
10477 tree name, binfo;
10478 int globalize;
10479 {
10480 enum tag_types tag_code;
10481 enum tree_code code;
10482 int temp = 0;
10483 register tree ref, t;
10484 struct binding_level *b = inner_binding_level;
10485 int got_type = 0;
10486
10487 tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
10488 switch (tag_code)
10489 {
10490 case record_type:
10491 case class_type:
10492 case signature_type:
10493 code = RECORD_TYPE;
10494 break;
10495 case union_type:
10496 code = UNION_TYPE;
10497 break;
10498 case enum_type:
10499 code = ENUMERAL_TYPE;
10500 break;
10501 default:
10502 my_friendly_abort (18);
10503 }
10504
10505 /* If a cross reference is requested, look up the type
10506 already defined for this tag and return it. */
10507 if (TREE_CODE_CLASS (TREE_CODE (name)) == 't')
10508 {
10509 t = name;
10510 name = TYPE_IDENTIFIER (t);
10511 got_type = 1;
10512 }
10513 else
10514 t = IDENTIFIER_TYPE_VALUE (name);
10515 if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM)
10516 t = NULL_TREE;
10517
10518 if (! globalize)
10519 {
10520 if (pedantic && t && TREE_CODE (t) == TEMPLATE_TYPE_PARM)
10521 {
10522 cp_pedwarn ("redeclaration of template type-parameter `%T'", name);
10523 cp_pedwarn_at (" previously declared here", t);
10524 }
10525 if (t && TYPE_CONTEXT (t) && got_type)
10526 ref = t;
10527 else
10528 {
10529 /* If we know we are defining this tag, only look it up in
10530 this scope and don't try to find it as a type. */
10531 ref = lookup_tag (code, name, b, 1);
10532 }
10533 }
10534 else
10535 {
10536 if (t)
10537 ref = t;
10538 else
10539 ref = lookup_tag (code, name, b, 0);
10540
10541 if (! ref)
10542 {
10543 /* Try finding it as a type declaration. If that wins, use it. */
10544 ref = lookup_name (name, 1);
10545 if (ref && TREE_CODE (ref) == TYPE_DECL
10546 && TREE_CODE (TREE_TYPE (ref)) == code)
10547 ref = TREE_TYPE (ref);
10548 else
10549 ref = NULL_TREE;
10550 }
10551 }
10552
10553 push_obstacks_nochange ();
10554
10555 if (! ref)
10556 {
10557 /* If no such tag is yet defined, create a forward-reference node
10558 and record it as the "definition".
10559 When a real declaration of this type is found,
10560 the forward-reference will be altered into a real type. */
10561
10562 /* In C++, since these migrate into the global scope, we must
10563 build them on the permanent obstack. */
10564
10565 temp = allocation_temporary_p ();
10566 if (temp)
10567 end_temporary_allocation ();
10568
10569 if (code == ENUMERAL_TYPE)
10570 {
10571 cp_error ("use of enum `%#D' without previous declaration", name);
10572
10573 ref = make_node (ENUMERAL_TYPE);
10574
10575 /* Give the type a default layout like unsigned int
10576 to avoid crashing if it does not get defined. */
10577 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
10578 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
10579 TREE_UNSIGNED (ref) = 1;
10580 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
10581 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
10582 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
10583
10584 /* Enable us to recognize when a type is created in class context.
10585 To do nested classes correctly, this should probably be cleared
10586 out when we leave this classes scope. Currently this in only
10587 done in `start_enum'. */
10588
10589 pushtag (name, ref, globalize);
10590 }
10591 else
10592 {
10593 struct binding_level *old_b = class_binding_level;
10594
10595 ref = make_lang_type (code);
10596
10597 if (tag_code == signature_type)
10598 {
10599 SET_SIGNATURE (ref);
10600 /* Since a signature type will be turned into the type
10601 of signature tables, it's not only an interface. */
10602 CLASSTYPE_INTERFACE_ONLY (ref) = 0;
10603 SET_CLASSTYPE_INTERFACE_KNOWN (ref);
10604 /* A signature doesn't have a vtable. */
10605 CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
10606 }
10607
10608 #ifdef NONNESTED_CLASSES
10609 /* Class types don't nest the way enums do. */
10610 class_binding_level = (struct binding_level *)0;
10611 #endif
10612 pushtag (name, ref, globalize);
10613 class_binding_level = old_b;
10614 }
10615 }
10616 else
10617 {
10618 /* If it no longer looks like a nested type, make sure it's
10619 in global scope. */
10620 if (b == global_binding_level && !class_binding_level
10621 && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
10622 IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
10623 }
10624
10625 if (binfo)
10626 xref_basetypes (code_type_node, name, ref, binfo);
10627
10628 just_return:
10629
10630 /* Until the type is defined, tentatively accept whatever
10631 structure tag the user hands us. */
10632 if (TYPE_SIZE (ref) == NULL_TREE
10633 && ref != current_class_type
10634 /* Have to check this, in case we have contradictory tag info. */
10635 && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
10636 {
10637 if (tag_code == class_type)
10638 CLASSTYPE_DECLARED_CLASS (ref) = 1;
10639 else if (tag_code == record_type || tag_code == signature_type)
10640 CLASSTYPE_DECLARED_CLASS (ref) = 0;
10641 }
10642
10643 pop_obstacks ();
10644
10645 return ref;
10646 }
10647
10648 tree
10649 xref_tag_from_type (old, id, globalize)
10650 tree old, id;
10651 int globalize;
10652 {
10653 tree code_type_node;
10654
10655 if (TREE_CODE (old) == RECORD_TYPE)
10656 code_type_node = (CLASSTYPE_DECLARED_CLASS (old)
10657 ? class_type_node : record_type_node);
10658 else
10659 code_type_node = union_type_node;
10660
10661 if (id == NULL_TREE)
10662 id = TYPE_IDENTIFIER (old);
10663
10664 return xref_tag (code_type_node, id, NULL_TREE, globalize);
10665 }
10666
10667 void
10668 xref_basetypes (code_type_node, name, ref, binfo)
10669 tree code_type_node;
10670 tree name, ref;
10671 tree binfo;
10672 {
10673 /* In the declaration `A : X, Y, ... Z' we mark all the types
10674 (A, X, Y, ..., Z) so we can check for duplicates. */
10675 tree binfos;
10676 int i, len;
10677 enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
10678
10679 if (tag_code == union_type)
10680 {
10681 cp_error ("derived union `%T' invalid", ref);
10682 return;
10683 }
10684
10685 len = list_length (binfo);
10686 push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref));
10687
10688 SET_CLASSTYPE_MARKED (ref);
10689 BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
10690
10691 for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
10692 {
10693 /* The base of a derived struct is public by default. */
10694 int via_public
10695 = (TREE_PURPOSE (binfo) == access_public_node
10696 || TREE_PURPOSE (binfo) == access_public_virtual_node
10697 || (tag_code != class_type
10698 && (TREE_PURPOSE (binfo) == access_default_node
10699 || TREE_PURPOSE (binfo) == access_default_virtual_node)));
10700 int via_protected = TREE_PURPOSE (binfo) == access_protected_node;
10701 int via_virtual
10702 = (TREE_PURPOSE (binfo) == access_private_virtual_node
10703 || TREE_PURPOSE (binfo) == access_public_virtual_node
10704 || TREE_PURPOSE (binfo) == access_default_virtual_node);
10705 tree basetype = TREE_VALUE (binfo);
10706 tree base_binfo;
10707
10708 GNU_xref_hier (IDENTIFIER_POINTER (name),
10709 IDENTIFIER_POINTER (TREE_VALUE (binfo)),
10710 via_public, via_virtual, 0);
10711
10712 if (basetype && TREE_CODE (basetype) == TYPE_DECL)
10713 basetype = TREE_TYPE (basetype);
10714 if (!basetype
10715 || (TREE_CODE (basetype) != RECORD_TYPE
10716 && TREE_CODE (basetype) != TYPENAME_TYPE
10717 && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM))
10718 {
10719 cp_error ("base type `%T' fails to be a struct or class type",
10720 TREE_VALUE (binfo));
10721 continue;
10722 }
10723 #if 1
10724 /* This code replaces similar code in layout_basetypes. */
10725 else if (TYPE_SIZE (complete_type (basetype)) == NULL_TREE
10726 && ! (current_template_parms && uses_template_parms (basetype)))
10727 {
10728 cp_error ("base class `%T' has incomplete type", basetype);
10729 continue;
10730 }
10731 #endif
10732 else
10733 {
10734 if (CLASSTYPE_MARKED (basetype))
10735 {
10736 if (basetype == ref)
10737 cp_error ("recursive type `%T' undefined", basetype);
10738 else
10739 cp_error ("duplicate base type `%T' invalid", basetype);
10740 continue;
10741 }
10742
10743 /* Note that the BINFO records which describe individual
10744 inheritances are *not* shared in the lattice! They
10745 cannot be shared because a given baseclass may be
10746 inherited with different `accessibility' by different
10747 derived classes. (Each BINFO record describing an
10748 individual inheritance contains flags which say what
10749 the `accessibility' of that particular inheritance is.) */
10750
10751 base_binfo = make_binfo (integer_zero_node, basetype,
10752 TYPE_BINFO_VTABLE (basetype),
10753 TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
10754
10755 TREE_VEC_ELT (binfos, i) = base_binfo;
10756 TREE_VIA_PUBLIC (base_binfo) = via_public;
10757 TREE_VIA_PROTECTED (base_binfo) = via_protected;
10758 TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
10759 BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref);
10760
10761 SET_CLASSTYPE_MARKED (basetype);
10762
10763 /* We are free to modify these bits because they are meaningless
10764 at top level, and BASETYPE is a top-level type. */
10765 if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
10766 {
10767 TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
10768 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10769 }
10770
10771 TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
10772 TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype);
10773 TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
10774 CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
10775 i += 1;
10776 }
10777 }
10778 if (i)
10779 TREE_VEC_LENGTH (binfos) = i;
10780 else
10781 BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
10782
10783 if (i > 1)
10784 TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
10785 else if (i == 1)
10786 TYPE_USES_MULTIPLE_INHERITANCE (ref)
10787 = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
10788 if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
10789 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10790
10791 /* Unmark all the types. */
10792 while (--i >= 0)
10793 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
10794 CLEAR_CLASSTYPE_MARKED (ref);
10795
10796 pop_obstacks ();
10797 }
10798
10799 \f
10800 static tree current_local_enum = NULL_TREE;
10801
10802 /* Begin compiling the definition of an enumeration type.
10803 NAME is its name (or null if anonymous).
10804 Returns the type object, as yet incomplete.
10805 Also records info about it so that build_enumerator
10806 may be used to declare the individual values as they are read. */
10807
10808 tree
10809 start_enum (name)
10810 tree name;
10811 {
10812 register tree enumtype = NULL_TREE;
10813 struct binding_level *b = inner_binding_level;
10814
10815 if (processing_template_decl && current_function_decl)
10816 end_temporary_allocation ();
10817
10818 /* If this is the real definition for a previous forward reference,
10819 fill in the contents in the same object that used to be the
10820 forward reference. */
10821
10822 if (name != NULL_TREE)
10823 enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
10824
10825 if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10826 cp_error ("multiple definition of `%#T'", enumtype);
10827 else
10828 {
10829 enumtype = make_node (ENUMERAL_TYPE);
10830 pushtag (name, enumtype, 0);
10831 }
10832
10833 if (b->pseudo_global)
10834 cp_error ("template declaration of `%#T'", enumtype);
10835
10836 if (current_class_type)
10837 TREE_ADDRESSABLE (b->tags) = 1;
10838
10839 current_local_enum = NULL_TREE;
10840
10841 /* We don't copy this value because build_enumerator needs to do it. */
10842 enum_next_value = integer_zero_node;
10843 enum_overflow = 0;
10844
10845 GNU_xref_decl (current_function_decl, enumtype);
10846 return enumtype;
10847 }
10848
10849 /* After processing and defining all the values of an enumeration type,
10850 install their decls in the enumeration type and finish it off.
10851 ENUMTYPE is the type object and VALUES a list of name-value pairs.
10852 Returns ENUMTYPE. */
10853
10854 tree
10855 finish_enum (enumtype, values)
10856 register tree enumtype, values;
10857 {
10858 register tree minnode, maxnode;
10859 /* Calculate the maximum value of any enumerator in this type. */
10860
10861 if (values)
10862 {
10863 register tree pair;
10864 register tree value = DECL_INITIAL (TREE_VALUE (values));
10865
10866 if (! processing_template_decl)
10867 {
10868 /* Speed up the main loop by performing some precalculations */
10869 TREE_TYPE (TREE_VALUE (values)) = enumtype;
10870 TREE_TYPE (value) = enumtype;
10871 minnode = maxnode = value;
10872 }
10873 TREE_VALUE (values) = value;
10874
10875 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
10876 {
10877 value = DECL_INITIAL (TREE_VALUE (pair));
10878 if (! processing_template_decl)
10879 {
10880 TREE_TYPE (TREE_VALUE (pair)) = enumtype;
10881 TREE_TYPE (value) = enumtype;
10882 if (tree_int_cst_lt (maxnode, value))
10883 maxnode = value;
10884 else if (tree_int_cst_lt (value, minnode))
10885 minnode = value;
10886 }
10887 TREE_VALUE (pair) = value;
10888 }
10889 }
10890 else
10891 maxnode = minnode = integer_zero_node;
10892
10893 TYPE_VALUES (enumtype) = nreverse (values);
10894
10895 if (processing_template_decl)
10896 {
10897 if (current_function_decl)
10898 {
10899 add_tree (build_min (TAG_DEFN, enumtype));
10900 resume_temporary_allocation ();
10901 }
10902 return enumtype;
10903 }
10904
10905 {
10906 int unsignedp = tree_int_cst_sgn (minnode) >= 0;
10907 int lowprec = min_precision (minnode, unsignedp);
10908 int highprec = min_precision (maxnode, unsignedp);
10909 int precision = MAX (lowprec, highprec);
10910
10911 TYPE_SIZE (enumtype) = NULL_TREE;
10912
10913 /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */
10914
10915 TYPE_PRECISION (enumtype) = precision;
10916 if (unsignedp)
10917 fixup_unsigned_type (enumtype);
10918 else
10919 fixup_signed_type (enumtype);
10920
10921 if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node)))
10922 /* Use the width of the narrowest normal C type which is wide enough. */
10923 TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size
10924 (precision, 1));
10925 else
10926 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10927
10928 TYPE_SIZE (enumtype) = 0;
10929 layout_type (enumtype);
10930 }
10931
10932 {
10933 register tree tem;
10934
10935 /* Fix up all variant types of this enum type. */
10936 for (tem = TYPE_MAIN_VARIANT (enumtype); tem;
10937 tem = TYPE_NEXT_VARIANT (tem))
10938 {
10939 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
10940 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
10941 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
10942 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
10943 TYPE_MODE (tem) = TYPE_MODE (enumtype);
10944 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
10945 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
10946 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
10947 }
10948 }
10949
10950 /* Finish debugging output for this type. */
10951 rest_of_type_compilation (enumtype, global_bindings_p ());
10952
10953 return enumtype;
10954 }
10955
10956 /* Build and install a CONST_DECL for one value of the
10957 current enumeration type (one that was begun with start_enum).
10958 Return a tree-list containing the name and its value.
10959 Assignment of sequential values by default is handled here. */
10960
10961 tree
10962 build_enumerator (name, value)
10963 tree name, value;
10964 {
10965 tree decl, result;
10966
10967 /* Remove no-op casts from the value. */
10968 if (value)
10969 STRIP_TYPE_NOPS (value);
10970
10971 if (! processing_template_decl)
10972 {
10973 /* Validate and default VALUE. */
10974 if (value != NULL_TREE)
10975 {
10976 if (TREE_READONLY_DECL_P (value))
10977 value = decl_constant_value (value);
10978
10979 if (TREE_CODE (value) == INTEGER_CST)
10980 {
10981 value = default_conversion (value);
10982 constant_expression_warning (value);
10983 }
10984 else
10985 {
10986 cp_error ("enumerator value for `%D' not integer constant", name);
10987 value = NULL_TREE;
10988 }
10989 }
10990
10991 /* Default based on previous value. */
10992 if (value == NULL_TREE && ! processing_template_decl)
10993 {
10994 value = enum_next_value;
10995 if (enum_overflow)
10996 cp_error ("overflow in enumeration values at `%D'", name);
10997 }
10998
10999 /* Remove no-op casts from the value. */
11000 if (value)
11001 STRIP_TYPE_NOPS (value);
11002
11003 /* We have to always copy here; not all INTEGER_CSTs are unshared,
11004 and there's no wedding ring. Look at size_int()...*/
11005 value = copy_node (value);
11006 #if 0
11007 /* To fix MAX_VAL enum consts. (bkoz) */
11008 TREE_TYPE (value) = integer_type_node;
11009 #endif
11010 }
11011
11012 /* C++ associates enums with global, function, or class declarations. */
11013
11014 decl = current_scope ();
11015 if (decl && decl == current_class_type)
11016 {
11017 /* This enum declaration is local to the class, so we must put
11018 it in that class's list of decls. */
11019 decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
11020 DECL_INITIAL (decl) = value;
11021 TREE_READONLY (decl) = 1;
11022 pushdecl_class_level (decl);
11023 TREE_CHAIN (decl) = current_local_enum;
11024 current_local_enum = decl;
11025 }
11026 else
11027 {
11028 /* It's a global enum, or it's local to a function. (Note local to
11029 a function could mean local to a class method. */
11030 decl = build_decl (CONST_DECL, name, integer_type_node);
11031 DECL_INITIAL (decl) = value;
11032 TREE_READONLY (decl) = 1;
11033
11034 pushdecl (decl);
11035 GNU_xref_decl (current_function_decl, decl);
11036 }
11037
11038 if (! processing_template_decl)
11039 {
11040 /* Set basis for default for next value. */
11041 enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
11042 integer_one_node, PLUS_EXPR);
11043 enum_overflow = tree_int_cst_lt (enum_next_value, value);
11044 }
11045
11046 result = saveable_tree_cons (name, decl, NULL_TREE);
11047 return result;
11048 }
11049
11050 tree
11051 grok_enum_decls (type, decl)
11052 tree type, decl;
11053 {
11054 tree d = current_local_enum;
11055
11056 if (d == NULL_TREE)
11057 return decl;
11058
11059 while (1)
11060 {
11061 TREE_TYPE (d) = type;
11062 if (TREE_CHAIN (d) == NULL_TREE)
11063 {
11064 TREE_CHAIN (d) = decl;
11065 break;
11066 }
11067 d = TREE_CHAIN (d);
11068 }
11069
11070 decl = current_local_enum;
11071 current_local_enum = NULL_TREE;
11072
11073 return decl;
11074 }
11075 \f
11076 static int function_depth;
11077
11078 /* Create the FUNCTION_DECL for a function definition.
11079 DECLSPECS and DECLARATOR are the parts of the declaration;
11080 they describe the function's name and the type it returns,
11081 but twisted together in a fashion that parallels the syntax of C.
11082
11083 This function creates a binding context for the function body
11084 as well as setting up the FUNCTION_DECL in current_function_decl.
11085
11086 Returns 1 on success. If the DECLARATOR is not suitable for a function
11087 (it defines a datum instead), we return 0, which tells
11088 yyparse to report a parse error.
11089
11090 For C++, we must first check whether that datum makes any sense.
11091 For example, "class A local_a(1,2);" means that variable local_a
11092 is an aggregate of type A, which should have a constructor
11093 applied to it with the argument list [1, 2].
11094
11095 @@ There is currently no way to retrieve the storage
11096 @@ allocated to FUNCTION (or all of its parms) if we return
11097 @@ something we had previously. */
11098
11099 int
11100 start_function (declspecs, declarator, attrs, pre_parsed_p)
11101 tree declspecs, declarator, attrs;
11102 int pre_parsed_p;
11103 {
11104 tree decl1;
11105 tree ctype = NULL_TREE;
11106 tree fntype;
11107 tree restype;
11108 extern int have_extern_spec;
11109 extern int used_extern_spec;
11110 int doing_friend = 0;
11111
11112 /* Sanity check. */
11113 my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
11114 my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
11115
11116 /* Assume, until we see it does. */
11117 current_function_returns_value = 0;
11118 current_function_returns_null = 0;
11119 warn_about_return_type = 0;
11120 named_labels = 0;
11121 shadowed_labels = 0;
11122 current_function_assigns_this = 0;
11123 current_function_just_assigned_this = 0;
11124 current_function_parms_stored = 0;
11125 original_result_rtx = NULL_RTX;
11126 base_init_expr = NULL_TREE;
11127 current_base_init_list = NULL_TREE;
11128 current_member_init_list = NULL_TREE;
11129 ctor_label = dtor_label = NULL_TREE;
11130 static_labelno = 0;
11131
11132 clear_temp_name ();
11133
11134 /* This should only be done once on the top most decl. */
11135 if (have_extern_spec && !used_extern_spec)
11136 {
11137 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
11138 used_extern_spec = 1;
11139 }
11140
11141 if (pre_parsed_p)
11142 {
11143 decl1 = declarator;
11144
11145 if (! DECL_ARGUMENTS (decl1)
11146 && !DECL_STATIC_FUNCTION_P (decl1)
11147 && DECL_CONTEXT (decl1)
11148 && TYPE_IDENTIFIER (DECL_CONTEXT (decl1))
11149 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (DECL_CONTEXT (decl1))))
11150 {
11151 cp_error ("redeclaration of `%#D'", decl1);
11152 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
11153 cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
11154 else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
11155 cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
11156 }
11157
11158 fntype = TREE_TYPE (decl1);
11159 if (TREE_CODE (fntype) == METHOD_TYPE)
11160 ctype = TYPE_METHOD_BASETYPE (fntype);
11161
11162 /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
11163 class is in the (lexical) scope of the class in which it is
11164 defined. */
11165 if (!ctype && DECL_FRIEND_P (decl1))
11166 {
11167 ctype = DECL_CLASS_CONTEXT (decl1);
11168
11169 /* CTYPE could be null here if we're dealing with a template;
11170 for example, `inline friend float foo()' inside a template
11171 will have no CTYPE set. */
11172 if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
11173 ctype = NULL_TREE;
11174 else
11175 doing_friend = 1;
11176 }
11177
11178 /* In a fcn definition, arg types must be complete. */
11179 require_complete_types_for_parms (DECL_ARGUMENTS (decl1));
11180
11181 /* In case some arg types were completed since the declaration was
11182 parsed, fix up the decls. */
11183 {
11184 tree t = DECL_ARGUMENTS (decl1);
11185 for (; t; t = TREE_CHAIN (t))
11186 layout_decl (t, 0);
11187 }
11188
11189 last_function_parms = DECL_ARGUMENTS (decl1);
11190 last_function_parm_tags = NULL_TREE;
11191 }
11192 else
11193 {
11194 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL_TREE);
11195 /* If the declarator is not suitable for a function definition,
11196 cause a syntax error. */
11197 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
11198
11199 fntype = TREE_TYPE (decl1);
11200
11201 restype = TREE_TYPE (fntype);
11202 if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
11203 && ! CLASSTYPE_GOT_SEMICOLON (restype))
11204 {
11205 cp_error ("semicolon missing after declaration of `%#T'", restype);
11206 shadow_tag (build_tree_list (NULL_TREE, restype));
11207 CLASSTYPE_GOT_SEMICOLON (restype) = 1;
11208 if (TREE_CODE (fntype) == FUNCTION_TYPE)
11209 fntype = build_function_type (integer_type_node,
11210 TYPE_ARG_TYPES (fntype));
11211 else
11212 fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
11213 integer_type_node,
11214 TYPE_ARG_TYPES (fntype));
11215 TREE_TYPE (decl1) = fntype;
11216 }
11217
11218 if (TREE_CODE (fntype) == METHOD_TYPE)
11219 ctype = TYPE_METHOD_BASETYPE (fntype);
11220 else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
11221 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
11222 && DECL_CONTEXT (decl1) == NULL_TREE)
11223 {
11224 /* If this doesn't return integer_type, complain. */
11225 if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
11226 {
11227 if (pedantic || warn_return_type)
11228 pedwarn ("return type for `main' changed to `int'");
11229 TREE_TYPE (decl1) = fntype = default_function_type;
11230 }
11231 warn_about_return_type = 0;
11232 }
11233 }
11234
11235 /* Warn if function was previously implicitly declared
11236 (but not if we warned then). */
11237 if (! warn_implicit
11238 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
11239 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
11240
11241 current_function_decl = decl1;
11242 /* Save the parm names or decls from this function's declarator
11243 where store_parm_decls will find them. */
11244 current_function_parms = last_function_parms;
11245 current_function_parm_tags = last_function_parm_tags;
11246
11247 announce_function (decl1);
11248
11249 if (! processing_template_decl)
11250 {
11251 if (TYPE_SIZE (complete_type (TREE_TYPE (fntype))) == NULL_TREE)
11252 {
11253 cp_error ("return-type `%#T' is an incomplete type",
11254 TREE_TYPE (fntype));
11255
11256 /* Make it return void instead, but don't change the
11257 type of the DECL_RESULT, in case we have a named return value. */
11258 if (ctype)
11259 TREE_TYPE (decl1)
11260 = build_cplus_method_type (build_type_variant (ctype,
11261 TREE_READONLY (decl1),
11262 TREE_SIDE_EFFECTS (decl1)),
11263 void_type_node,
11264 FUNCTION_ARG_CHAIN (decl1));
11265 else
11266 TREE_TYPE (decl1)
11267 = build_function_type (void_type_node,
11268 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
11269 DECL_RESULT (decl1)
11270 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype)));
11271 TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype));
11272 TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype));
11273 }
11274
11275 if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype))
11276 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype)))
11277 abstract_virtuals_error (decl1, TREE_TYPE (fntype));
11278 }
11279
11280 if (warn_about_return_type)
11281 warning ("return-type defaults to `int'");
11282
11283 /* Effective C++ rule 15. See also c_expand_return. */
11284 if (warn_ecpp
11285 && DECL_NAME (decl1) == ansi_opname[(int) MODIFY_EXPR]
11286 && TREE_TYPE (fntype) == void_type_node)
11287 cp_warning ("`operator=' should return a reference to `*this'");
11288
11289 /* Make the init_value nonzero so pushdecl knows this is not tentative.
11290 error_mark_node is replaced below (in poplevel) with the BLOCK. */
11291 DECL_INITIAL (decl1) = error_mark_node;
11292
11293 /* This function exists in static storage.
11294 (This does not mean `static' in the C sense!) */
11295 TREE_STATIC (decl1) = 1;
11296
11297 /* Record the decl so that the function name is defined.
11298 If we already have a decl for this name, and it is a FUNCTION_DECL,
11299 use the old decl. */
11300
11301 if (processing_template_decl)
11302 push_template_decl (decl1);
11303 else if (pre_parsed_p == 0)
11304 {
11305 decl1 = pushdecl (decl1);
11306 DECL_MAIN_VARIANT (decl1) = decl1;
11307 fntype = TREE_TYPE (decl1);
11308 }
11309
11310 current_function_decl = decl1;
11311
11312 if (DECL_INTERFACE_KNOWN (decl1))
11313 {
11314 if (DECL_NOT_REALLY_EXTERN (decl1))
11315 DECL_EXTERNAL (decl1) = 0;
11316 }
11317 /* If this function belongs to an interface, it is public.
11318 If it belongs to someone else's interface, it is also external.
11319 It doesn't matter whether it's inline or not. */
11320 else if (interface_unknown == 0
11321 && (! DECL_TEMPLATE_INSTANTIATION (decl1)
11322 || flag_alt_external_templates))
11323 {
11324 if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)
11325 || processing_template_decl)
11326 DECL_EXTERNAL (decl1)
11327 = (interface_only
11328 || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines));
11329 else
11330 {
11331 DECL_EXTERNAL (decl1) = 0;
11332 if (DECL_C_STATIC (decl1))
11333 TREE_PUBLIC (decl1) = 0;
11334 }
11335 DECL_NOT_REALLY_EXTERN (decl1) = 0;
11336 DECL_INTERFACE_KNOWN (decl1) = 1;
11337 }
11338 else
11339 {
11340 /* This is a definition, not a reference.
11341 So clear DECL_EXTERNAL. */
11342 DECL_EXTERNAL (decl1) = 0;
11343
11344 if ((DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1))
11345 && ! DECL_INTERFACE_KNOWN (decl1)
11346 /* Don't try to defer nested functions for now. */
11347 && ! hack_decl_function_context (decl1))
11348 DECL_DEFER_OUTPUT (decl1) = 1;
11349 else
11350 {
11351 DECL_INTERFACE_KNOWN (decl1) = 1;
11352 if (DECL_C_STATIC (decl1))
11353 TREE_PUBLIC (decl1) = 0;
11354 }
11355 }
11356
11357 if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
11358 {
11359 if (TREE_CODE (fntype) == METHOD_TYPE)
11360 TREE_TYPE (decl1) = fntype
11361 = build_function_type (TREE_TYPE (fntype),
11362 TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
11363 current_function_parms = TREE_CHAIN (current_function_parms);
11364 DECL_ARGUMENTS (decl1) = current_function_parms;
11365 ctype = NULL_TREE;
11366 }
11367 restype = TREE_TYPE (fntype);
11368
11369 if (ctype)
11370 {
11371 push_nested_class (ctype, 1);
11372
11373 /* If we're compiling a friend function, neither of the variables
11374 current_class_ptr nor current_class_type will have values. */
11375 if (! doing_friend)
11376 {
11377 /* We know that this was set up by `grokclassfn'.
11378 We do not wait until `store_parm_decls', since evil
11379 parse errors may never get us to that point. Here
11380 we keep the consistency between `current_class_type'
11381 and `current_class_ptr'. */
11382 tree t = current_function_parms;
11383
11384 my_friendly_assert (t != NULL_TREE
11385 && TREE_CODE (t) == PARM_DECL, 162);
11386
11387 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
11388 {
11389 int i = suspend_momentary ();
11390
11391 /* Fool build_indirect_ref. */
11392 current_class_ptr = NULL_TREE;
11393 current_class_ref = build_indirect_ref (t, NULL_PTR);
11394 current_class_ptr = t;
11395 resume_momentary (i);
11396 }
11397 else
11398 /* We're having a signature pointer here. */
11399 current_class_ref = current_class_ptr = t;
11400
11401 }
11402 }
11403 else
11404 {
11405 if (DECL_STATIC_FUNCTION_P (decl1))
11406 push_nested_class (DECL_CONTEXT (decl1), 2);
11407 else
11408 push_memoized_context (0, 1);
11409 current_class_ptr = current_class_ref = NULL_TREE;
11410 }
11411
11412 pushlevel (0);
11413 current_binding_level->parm_flag = 1;
11414
11415 GNU_xref_function (decl1, current_function_parms);
11416
11417 if (attrs)
11418 cplus_decl_attributes (decl1, NULL_TREE, attrs);
11419 make_function_rtl (decl1);
11420
11421 /* Promote the value to int before returning it. */
11422 if (C_PROMOTING_INTEGER_TYPE_P (restype))
11423 restype = type_promotes_to (restype);
11424
11425 /* If this fcn was already referenced via a block-scope `extern' decl
11426 (or an implicit decl), propagate certain information about the usage. */
11427 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
11428 TREE_ADDRESSABLE (decl1) = 1;
11429
11430 if (DECL_RESULT (decl1) == NULL_TREE)
11431 {
11432 DECL_RESULT (decl1)
11433 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
11434 TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype);
11435 TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype);
11436 }
11437
11438 /* Allocate further tree nodes temporarily during compilation
11439 of this function only. Tiemann moved up here from bottom of fn. */
11440 temporary_allocation ();
11441
11442 if (processing_template_decl)
11443 {
11444 extern tree last_tree;
11445 ++minimal_parse_mode;
11446 last_tree = DECL_SAVED_TREE (decl1)
11447 = build_nt (EXPR_STMT, void_zero_node);
11448 }
11449
11450 ++function_depth;
11451
11452 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1))
11453 && DECL_LANGUAGE (decl1) == lang_cplusplus)
11454 {
11455 dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11456 ctor_label = NULL_TREE;
11457 }
11458 else
11459 {
11460 dtor_label = NULL_TREE;
11461 if (DECL_CONSTRUCTOR_P (decl1))
11462 ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11463 }
11464
11465 return 1;
11466 }
11467 \f
11468 void
11469 store_after_parms (insns)
11470 rtx insns;
11471 {
11472 rtx x;
11473
11474 for (x = get_insns (); x; x = next_insn (x))
11475 {
11476 if (GET_CODE (x) == NOTE && NOTE_LINE_NUMBER (x) == NOTE_INSN_FUNCTION_BEG)
11477 {
11478 emit_insns_after (insns, x);
11479 return;
11480 }
11481 }
11482 #if 0
11483 /* This doesn't work, because the inline output routine doesn't reset
11484 last_parm_insn correctly for get_first_nonparm_insn () to work. */
11485
11486 last_parm_insn = get_first_nonparm_insn ();
11487 if (last_parm_insn == NULL_RTX)
11488 emit_insns (insns);
11489 else
11490 emit_insns_before (insns, last_parm_insn);
11491 #endif
11492 }
11493
11494 void
11495 expand_start_early_try_stmts ()
11496 {
11497 rtx insns;
11498 start_sequence ();
11499 expand_start_try_stmts ();
11500 insns = get_insns ();
11501 end_sequence ();
11502 #if 1
11503 emit_insns_after (insns, get_insns ());
11504 #else
11505 store_after_parms (insns);
11506 #endif
11507 }
11508
11509 /* Store the parameter declarations into the current function declaration.
11510 This is called after parsing the parameter declarations, before
11511 digesting the body of the function.
11512
11513 Also install to binding contour return value identifier, if any. */
11514
11515 void
11516 store_parm_decls ()
11517 {
11518 register tree fndecl = current_function_decl;
11519 register tree parm;
11520 int parms_have_cleanups = 0;
11521 tree cleanups = NULL_TREE;
11522
11523 /* This is either a chain of PARM_DECLs (when a prototype is used). */
11524 tree specparms = current_function_parms;
11525
11526 /* This is a list of types declared among parms in a prototype. */
11527 tree parmtags = current_function_parm_tags;
11528
11529 /* This is a chain of any other decls that came in among the parm
11530 declarations. If a parm is declared with enum {foo, bar} x;
11531 then CONST_DECLs for foo and bar are put here. */
11532 tree nonparms = NULL_TREE;
11533
11534 if (toplevel_bindings_p ())
11535 fatal ("parse errors have confused me too much");
11536
11537 /* Initialize RTL machinery. */
11538 init_function_start (fndecl, input_filename, lineno);
11539
11540 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
11541 declare_function_name ();
11542
11543 /* Create a binding level for the parms. */
11544 expand_start_bindings (0);
11545
11546 if (specparms != NULL_TREE)
11547 {
11548 /* This case is when the function was defined with an ANSI prototype.
11549 The parms already have decls, so we need not do anything here
11550 except record them as in effect
11551 and complain if any redundant old-style parm decls were written. */
11552
11553 register tree next;
11554
11555 /* Must clear this because it might contain TYPE_DECLs declared
11556 at class level. */
11557 storedecls (NULL_TREE);
11558
11559 for (parm = nreverse (specparms); parm; parm = next)
11560 {
11561 next = TREE_CHAIN (parm);
11562 if (TREE_CODE (parm) == PARM_DECL)
11563 {
11564 tree cleanup;
11565 if (DECL_NAME (parm) == NULL_TREE)
11566 {
11567 pushdecl (parm);
11568 }
11569 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
11570 cp_error ("parameter `%D' declared void", parm);
11571 else
11572 {
11573 /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
11574 A parameter is assumed not to have any side effects.
11575 If this should change for any reason, then this
11576 will have to wrap the bashed reference type in a save_expr.
11577
11578 Also, if the parameter type is declared to be an X
11579 and there is an X(X&) constructor, we cannot lay it
11580 into the stack (any more), so we make this parameter
11581 look like it is really of reference type. Functions
11582 which pass parameters to this function will know to
11583 create a temporary in their frame, and pass a reference
11584 to that. */
11585
11586 if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
11587 && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
11588 SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
11589
11590 pushdecl (parm);
11591 }
11592 if (! processing_template_decl
11593 && (cleanup = maybe_build_cleanup (parm), cleanup))
11594 {
11595 expand_decl (parm);
11596 parms_have_cleanups = 1;
11597
11598 /* Keep track of the cleanups. */
11599 cleanups = tree_cons (parm, cleanup, cleanups);
11600 }
11601 }
11602 else
11603 {
11604 /* If we find an enum constant or a type tag,
11605 put it aside for the moment. */
11606 TREE_CHAIN (parm) = NULL_TREE;
11607 nonparms = chainon (nonparms, parm);
11608 }
11609 }
11610
11611 /* Get the decls in their original chain order
11612 and record in the function. This is all and only the
11613 PARM_DECLs that were pushed into scope by the loop above. */
11614 DECL_ARGUMENTS (fndecl) = getdecls ();
11615
11616 storetags (chainon (parmtags, gettags ()));
11617 }
11618 else
11619 DECL_ARGUMENTS (fndecl) = NULL_TREE;
11620
11621 /* Now store the final chain of decls for the arguments
11622 as the decl-chain of the current lexical scope.
11623 Put the enumerators in as well, at the front so that
11624 DECL_ARGUMENTS is not modified. */
11625
11626 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
11627
11628 /* Initialize the RTL code for the function. */
11629 DECL_SAVED_INSNS (fndecl) = NULL_RTX;
11630 if (! processing_template_decl)
11631 expand_function_start (fndecl, parms_have_cleanups);
11632
11633 current_function_parms_stored = 1;
11634
11635 /* If this function is `main', emit a call to `__main'
11636 to run global initializers, etc. */
11637 if (DECL_NAME (fndecl)
11638 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11639 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
11640 && DECL_CONTEXT (fndecl) == NULL_TREE)
11641 {
11642 expand_main_function ();
11643 }
11644
11645 /* Now that we have initialized the parms, we can start their
11646 cleanups. We cannot do this before, since expand_decl_cleanup
11647 should not be called before the parm can be used. */
11648 if (cleanups
11649 && ! processing_template_decl)
11650 {
11651 for (cleanups = nreverse (cleanups); cleanups; cleanups = TREE_CHAIN (cleanups))
11652 {
11653 if (! expand_decl_cleanup (TREE_PURPOSE (cleanups), TREE_VALUE (cleanups)))
11654 cp_error ("parser lost in parsing declaration of `%D'",
11655 TREE_PURPOSE (cleanups));
11656 }
11657 }
11658
11659 /* Create a binding contour which can be used to catch
11660 cleanup-generated temporaries. Also, if the return value needs or
11661 has initialization, deal with that now. */
11662 if (parms_have_cleanups)
11663 {
11664 pushlevel (0);
11665 expand_start_bindings (0);
11666 }
11667
11668 last_parm_cleanup_insn = get_last_insn ();
11669
11670 if (! processing_template_decl && flag_exceptions)
11671 {
11672 /* Do the starting of the exception specifications, if we have any. */
11673 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl)))
11674 expand_start_eh_spec ();
11675 }
11676
11677 last_dtor_insn = get_last_insn ();
11678 }
11679
11680 /* Bind a name and initialization to the return value of
11681 the current function. */
11682
11683 void
11684 store_return_init (return_id, init)
11685 tree return_id, init;
11686 {
11687 tree decl = DECL_RESULT (current_function_decl);
11688
11689 if (pedantic)
11690 /* Give this error as many times as there are occurrences,
11691 so that users can use Emacs compilation buffers to find
11692 and fix all such places. */
11693 pedwarn ("ANSI C++ does not permit named return values");
11694
11695 if (return_id != NULL_TREE)
11696 {
11697 if (DECL_NAME (decl) == NULL_TREE)
11698 {
11699 DECL_NAME (decl) = return_id;
11700 DECL_ASSEMBLER_NAME (decl) = return_id;
11701 }
11702 else
11703 cp_error ("return identifier `%D' already in place", decl);
11704 }
11705
11706 /* Can't let this happen for constructors. */
11707 if (DECL_CONSTRUCTOR_P (current_function_decl))
11708 {
11709 error ("can't redefine default return value for constructors");
11710 return;
11711 }
11712
11713 /* If we have a named return value, put that in our scope as well. */
11714 if (DECL_NAME (decl) != NULL_TREE)
11715 {
11716 /* If this named return value comes in a register,
11717 put it in a pseudo-register. */
11718 if (DECL_REGISTER (decl))
11719 {
11720 original_result_rtx = DECL_RTL (decl);
11721 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
11722 }
11723
11724 /* Let `cp_finish_decl' know that this initializer is ok. */
11725 DECL_INITIAL (decl) = init;
11726 pushdecl (decl);
11727
11728 if (minimal_parse_mode)
11729 add_tree (build_min_nt (RETURN_INIT, return_id,
11730 copy_to_permanent (init)));
11731 else
11732 cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
11733 }
11734 }
11735
11736 \f
11737 /* Finish up a function declaration and compile that function
11738 all the way to assembler language output. The free the storage
11739 for the function definition.
11740
11741 This is called after parsing the body of the function definition.
11742 LINENO is the current line number.
11743
11744 C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11745 (and expand_end_bindings) must be made to take care of the binding
11746 contour for the base initializers. This is only relevant for
11747 constructors.
11748
11749 NESTED is nonzero if we were in the middle of compiling another function
11750 when we started on this one. */
11751
11752 void
11753 finish_function (lineno, call_poplevel, nested)
11754 int lineno;
11755 int call_poplevel;
11756 int nested;
11757 {
11758 register tree fndecl = current_function_decl;
11759 tree fntype, ctype = NULL_TREE;
11760 rtx last_parm_insn, insns;
11761 /* Label to use if this function is supposed to return a value. */
11762 tree no_return_label = NULL_TREE;
11763 tree decls = NULL_TREE;
11764
11765 /* When we get some parse errors, we can end up without a
11766 current_function_decl, so cope. */
11767 if (fndecl == NULL_TREE)
11768 return;
11769
11770 if (! nested && function_depth > 1)
11771 nested = 1;
11772
11773 fntype = TREE_TYPE (fndecl);
11774
11775 /* TREE_READONLY (fndecl) = 1;
11776 This caused &foo to be of type ptr-to-const-function
11777 which then got a warning when stored in a ptr-to-function variable. */
11778
11779 /* This happens on strange parse errors. */
11780 if (! current_function_parms_stored)
11781 {
11782 call_poplevel = 0;
11783 store_parm_decls ();
11784 }
11785
11786 if (processing_template_decl)
11787 {
11788 if (DECL_CONSTRUCTOR_P (fndecl) && call_poplevel)
11789 {
11790 decls = getdecls ();
11791 expand_end_bindings (decls, decls != NULL_TREE, 0);
11792 poplevel (decls != NULL_TREE, 0, 0);
11793 }
11794 }
11795 else
11796 {
11797 if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/)
11798 {
11799 tree ttype = target_type (fntype);
11800 tree parmdecl;
11801
11802 if (IS_AGGR_TYPE (ttype))
11803 /* Let debugger know it should output info for this type. */
11804 note_debug_info_needed (ttype);
11805
11806 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
11807 {
11808 ttype = target_type (TREE_TYPE (parmdecl));
11809 if (IS_AGGR_TYPE (ttype))
11810 /* Let debugger know it should output info for this type. */
11811 note_debug_info_needed (ttype);
11812 }
11813 }
11814
11815 /* Clean house because we will need to reorder insns here. */
11816 do_pending_stack_adjust ();
11817
11818 if (dtor_label)
11819 {
11820 tree binfo = TYPE_BINFO (current_class_type);
11821 tree cond = integer_one_node;
11822 tree exprstmt;
11823 tree in_charge_node = lookup_name (in_charge_identifier, 0);
11824 tree virtual_size;
11825 int ok_to_optimize_dtor = 0;
11826 int empty_dtor = get_last_insn () == last_dtor_insn;
11827
11828 if (current_function_assigns_this)
11829 cond = build (NE_EXPR, boolean_type_node,
11830 current_class_ptr, integer_zero_node);
11831 else
11832 {
11833 int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
11834
11835 /* If this destructor is empty, then we don't need to check
11836 whether `this' is NULL in some cases. */
11837 if ((flag_this_is_variable & 1) == 0)
11838 ok_to_optimize_dtor = 1;
11839 else if (empty_dtor)
11840 ok_to_optimize_dtor
11841 = (n_baseclasses == 0
11842 || (n_baseclasses == 1
11843 && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
11844 }
11845
11846 /* These initializations might go inline. Protect
11847 the binding level of the parms. */
11848 pushlevel (0);
11849 expand_start_bindings (0);
11850
11851 if (current_function_assigns_this)
11852 {
11853 current_function_assigns_this = 0;
11854 current_function_just_assigned_this = 0;
11855 }
11856
11857 /* Generate the code to call destructor on base class.
11858 If this destructor belongs to a class with virtual
11859 functions, then set the virtual function table
11860 pointer to represent the type of our base class. */
11861
11862 /* This side-effect makes call to `build_delete' generate the
11863 code we have to have at the end of this destructor. */
11864 TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
11865
11866 /* These are two cases where we cannot delegate deletion. */
11867 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
11868 || TYPE_GETS_REG_DELETE (current_class_type))
11869 exprstmt = build_delete (current_class_type, current_class_ref, integer_zero_node,
11870 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0);
11871 else
11872 exprstmt = build_delete (current_class_type, current_class_ref, in_charge_node,
11873 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0);
11874
11875 /* If we did not assign to this, then `this' is non-zero at
11876 the end of a destructor. As a special optimization, don't
11877 emit test if this is an empty destructor. If it does nothing,
11878 it does nothing. If it calls a base destructor, the base
11879 destructor will perform the test. */
11880
11881 if (exprstmt != error_mark_node
11882 && (TREE_CODE (exprstmt) != NOP_EXPR
11883 || TREE_OPERAND (exprstmt, 0) != integer_zero_node
11884 || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
11885 {
11886 expand_label (dtor_label);
11887 if (cond != integer_one_node)
11888 expand_start_cond (cond, 0);
11889 if (exprstmt != void_zero_node)
11890 /* Don't call `expand_expr_stmt' if we're not going to do
11891 anything, since -Wall will give a diagnostic. */
11892 expand_expr_stmt (exprstmt);
11893
11894 /* Run destructor on all virtual baseclasses. */
11895 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11896 {
11897 tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
11898 expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
11899 in_charge_node, integer_two_node), 0);
11900 while (vbases)
11901 {
11902 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
11903 {
11904 tree vb = get_vbase
11905 (BINFO_TYPE (vbases),
11906 TYPE_BINFO (current_class_type));
11907 expand_expr_stmt
11908 (build_scoped_method_call
11909 (current_class_ref, vb, dtor_identifier,
11910 build_tree_list (NULL_TREE, integer_zero_node)));
11911 }
11912 vbases = TREE_CHAIN (vbases);
11913 }
11914 expand_end_cond ();
11915 }
11916
11917 do_pending_stack_adjust ();
11918 if (cond != integer_one_node)
11919 expand_end_cond ();
11920 }
11921
11922 TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
11923
11924 virtual_size = c_sizeof (current_class_type);
11925
11926 /* At the end, call delete if that's what's requested. */
11927 if (TYPE_GETS_REG_DELETE (current_class_type))
11928 /* This NOP_EXPR means we are in a static call context. */
11929 exprstmt
11930 = build_method_call (build_indirect_ref (build1 (NOP_EXPR,
11931 build_pointer_type (current_class_type),
11932 error_mark_node),
11933 NULL_PTR),
11934 ansi_opname[(int) DELETE_EXPR],
11935 tree_cons (NULL_TREE, current_class_ptr,
11936 build_tree_list (NULL_TREE, virtual_size)),
11937 NULL_TREE, LOOKUP_NORMAL);
11938 else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11939 exprstmt = build_x_delete (ptr_type_node, current_class_ptr, 0,
11940 virtual_size);
11941 else
11942 exprstmt = NULL_TREE;
11943
11944 if (exprstmt)
11945 {
11946 cond = build (BIT_AND_EXPR, integer_type_node,
11947 in_charge_node, integer_one_node);
11948 expand_start_cond (cond, 0);
11949 expand_expr_stmt (exprstmt);
11950 expand_end_cond ();
11951 }
11952
11953 /* End of destructor. */
11954 expand_end_bindings (NULL_TREE, getdecls () != NULL_TREE, 0);
11955 poplevel (2, 0, 0); /* XXX change to 1 */
11956
11957 /* Back to the top of destructor. */
11958 /* Dont execute destructor code if `this' is NULL. */
11959
11960 start_sequence ();
11961
11962 /* If the dtor is empty, and we know there is not possible way we
11963 could use any vtable entries, before they are possibly set by
11964 a base class dtor, we don't have to setup the vtables, as we
11965 know that any base class dtoring will set up any vtables it
11966 needs. We avoid MI, because one base class dtor can do a
11967 virtual dispatch to an overridden function that would need to
11968 have a non-related vtable set up, we cannot avoid setting up
11969 vtables in that case. We could change this to see if there is
11970 just one vtable. */
11971 if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type))
11972 {
11973 /* Make all virtual function table pointers in non-virtual base
11974 classes point to CURRENT_CLASS_TYPE's virtual function
11975 tables. */
11976 expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr);
11977
11978 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11979 expand_indirect_vtbls_init (binfo, current_class_ref, current_class_ptr);
11980 }
11981
11982 if (! ok_to_optimize_dtor)
11983 {
11984 cond = build_binary_op (NE_EXPR,
11985 current_class_ptr, integer_zero_node, 1);
11986 expand_start_cond (cond, 0);
11987 }
11988
11989 insns = get_insns ();
11990 end_sequence ();
11991
11992 last_parm_insn = get_first_nonparm_insn ();
11993 if (last_parm_insn == NULL_RTX)
11994 last_parm_insn = get_last_insn ();
11995 else
11996 last_parm_insn = previous_insn (last_parm_insn);
11997
11998 emit_insns_after (insns, last_parm_insn);
11999
12000 if (! ok_to_optimize_dtor)
12001 expand_end_cond ();
12002 }
12003 else if (current_function_assigns_this)
12004 {
12005 /* Does not need to call emit_base_init, because
12006 that is done (if needed) just after assignment to this
12007 is seen. */
12008
12009 if (DECL_CONSTRUCTOR_P (current_function_decl))
12010 {
12011 end_protect_partials ();
12012 expand_label (ctor_label);
12013 ctor_label = NULL_TREE;
12014
12015 if (call_poplevel)
12016 {
12017 decls = getdecls ();
12018 expand_end_bindings (decls, decls != NULL_TREE, 0);
12019 poplevel (decls != NULL_TREE, 0, 0);
12020 }
12021 c_expand_return (current_class_ptr);
12022 }
12023 else if (TYPE_MAIN_VARIANT (TREE_TYPE (
12024 DECL_RESULT (current_function_decl))) != void_type_node
12025 && return_label != NULL_RTX)
12026 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
12027
12028 current_function_assigns_this = 0;
12029 current_function_just_assigned_this = 0;
12030 base_init_expr = NULL_TREE;
12031 }
12032 else if (DECL_CONSTRUCTOR_P (fndecl))
12033 {
12034 tree cond, thenclause;
12035 /* Allow constructor for a type to get a new instance of the object
12036 using `build_new'. */
12037 tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
12038 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
12039
12040 DECL_RETURNS_FIRST_ARG (fndecl) = 1;
12041
12042 if (flag_this_is_variable > 0)
12043 {
12044 cond = build_binary_op (EQ_EXPR,
12045 current_class_ptr, integer_zero_node, 1);
12046 thenclause = build_modify_expr (current_class_ptr, NOP_EXPR,
12047 build_new (NULL_TREE, current_class_type, void_type_node, 0));
12048 }
12049
12050 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
12051
12052 start_sequence ();
12053
12054 if (flag_this_is_variable > 0)
12055 {
12056 expand_start_cond (cond, 0);
12057 expand_expr_stmt (thenclause);
12058 expand_end_cond ();
12059 }
12060
12061 /* Emit insns from `emit_base_init' which sets up virtual
12062 function table pointer(s). */
12063 if (base_init_expr)
12064 {
12065 expand_expr_stmt (base_init_expr);
12066 base_init_expr = NULL_TREE;
12067 }
12068
12069 insns = get_insns ();
12070 end_sequence ();
12071
12072 /* This is where the body of the constructor begins. */
12073
12074 emit_insns_after (insns, last_parm_cleanup_insn);
12075
12076 end_protect_partials ();
12077
12078 /* This is where the body of the constructor ends. */
12079 expand_label (ctor_label);
12080 ctor_label = NULL_TREE;
12081
12082 if (call_poplevel)
12083 {
12084 decls = getdecls ();
12085 expand_end_bindings (decls, decls != NULL_TREE, 0);
12086 poplevel (decls != NULL_TREE, 1, 0);
12087 }
12088
12089 c_expand_return (current_class_ptr);
12090
12091 current_function_assigns_this = 0;
12092 current_function_just_assigned_this = 0;
12093 }
12094 else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
12095 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
12096 && DECL_CONTEXT (fndecl) == NULL_TREE)
12097 {
12098 /* Make it so that `main' always returns 0 by default. */
12099 #ifdef VMS
12100 c_expand_return (integer_one_node);
12101 #else
12102 c_expand_return (integer_zero_node);
12103 #endif
12104 }
12105 else if (return_label != NULL_RTX
12106 && current_function_return_value == NULL_TREE
12107 && ! DECL_NAME (DECL_RESULT (current_function_decl)))
12108 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
12109
12110 if (flag_exceptions)
12111 expand_exception_blocks ();
12112
12113 /* If this function is supposed to return a value, ensure that
12114 we do not fall into the cleanups by mistake. The end of our
12115 function will look like this:
12116
12117 user code (may have return stmt somewhere)
12118 goto no_return_label
12119 cleanup_label:
12120 cleanups
12121 goto return_label
12122 no_return_label:
12123 NOTE_INSN_FUNCTION_END
12124 return_label:
12125 things for return
12126
12127 If the user omits a return stmt in the USER CODE section, we
12128 will have a control path which reaches NOTE_INSN_FUNCTION_END.
12129 Otherwise, we won't. */
12130 if (no_return_label)
12131 {
12132 DECL_CONTEXT (no_return_label) = fndecl;
12133 DECL_INITIAL (no_return_label) = error_mark_node;
12134 DECL_SOURCE_FILE (no_return_label) = input_filename;
12135 DECL_SOURCE_LINE (no_return_label) = lineno;
12136 expand_goto (no_return_label);
12137 }
12138
12139 if (cleanup_label)
12140 {
12141 /* remove the binding contour which is used
12142 to catch cleanup-generated temporaries. */
12143 expand_end_bindings (0, 0, 0);
12144 poplevel (0, 0, 0);
12145
12146 /* Emit label at beginning of cleanup code for parameters. */
12147 emit_label (cleanup_label);
12148 }
12149
12150 /* Get return value into register if that's where it's supposed to be. */
12151 if (original_result_rtx)
12152 fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
12153
12154 /* Finish building code that will trigger warnings if users forget
12155 to make their functions return values. */
12156 if (no_return_label || cleanup_label)
12157 emit_jump (return_label);
12158 if (no_return_label)
12159 {
12160 /* We don't need to call `expand_*_return' here because we
12161 don't need any cleanups here--this path of code is only
12162 for error checking purposes. */
12163 expand_label (no_return_label);
12164 }
12165
12166 /* Generate rtl for function exit. */
12167 expand_function_end (input_filename, lineno, 1);
12168 }
12169
12170 /* This must come after expand_function_end because cleanups might
12171 have declarations (from inline functions) that need to go into
12172 this function's blocks. */
12173 if (current_binding_level->parm_flag != 1)
12174 my_friendly_abort (122);
12175 poplevel (1, 0, 1);
12176
12177 /* reset scope for C++: if we were in the scope of a class,
12178 then when we finish this function, we are not longer so.
12179 This cannot be done until we know for sure that no more
12180 class members will ever be referenced in this function
12181 (i.e., calls to destructors). */
12182 if (current_class_name)
12183 {
12184 ctype = current_class_type;
12185 pop_nested_class (1);
12186 }
12187 else
12188 pop_memoized_context (1);
12189
12190 /* Must mark the RESULT_DECL as being in this function. */
12191 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
12192
12193 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
12194 to the FUNCTION_DECL node itself. */
12195 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
12196
12197 if (! processing_template_decl)
12198 {
12199 /* So we can tell if jump_optimize sets it to 1. */
12200 can_reach_end = 0;
12201
12202 /* Run the optimizers and output the assembler code for this
12203 function. */
12204
12205 if (DECL_ARTIFICIAL (fndecl))
12206 {
12207 /* Do we really *want* to inline this synthesized method? */
12208
12209 int save_fif = flag_inline_functions;
12210 flag_inline_functions = 1;
12211
12212 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
12213 will check our size. */
12214 DECL_INLINE (fndecl) = 0;
12215
12216 rest_of_compilation (fndecl);
12217 flag_inline_functions = save_fif;
12218 }
12219 else
12220 rest_of_compilation (fndecl);
12221
12222 if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl))
12223 {
12224 /* Set DECL_EXTERNAL so that assemble_external will be called as
12225 necessary. We'll clear it again in finish_file. */
12226 if (! DECL_EXTERNAL (fndecl))
12227 DECL_NOT_REALLY_EXTERN (fndecl) = 1;
12228 DECL_EXTERNAL (fndecl) = 1;
12229 mark_inline_for_output (fndecl);
12230 }
12231
12232 if (ctype && TREE_ASM_WRITTEN (fndecl))
12233 note_debug_info_needed (ctype);
12234
12235 current_function_returns_null |= can_reach_end;
12236
12237 /* Since we don't normally go through c_expand_return for constructors,
12238 this normally gets the wrong value.
12239 Also, named return values have their return codes emitted after
12240 NOTE_INSN_FUNCTION_END, confusing jump.c. */
12241 if (DECL_CONSTRUCTOR_P (fndecl)
12242 || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
12243 current_function_returns_null = 0;
12244
12245 if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
12246 cp_warning ("`noreturn' function `%D' does return", fndecl);
12247 else if ((warn_return_type || pedantic)
12248 && current_function_returns_null
12249 && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
12250 {
12251 /* If this function returns non-void and control can drop through,
12252 complain. */
12253 cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
12254 }
12255 /* With just -W, complain only if function returns both with
12256 and without a value. */
12257 else if (extra_warnings
12258 && current_function_returns_value && current_function_returns_null)
12259 warning ("this function may return with or without a value");
12260 }
12261
12262 --function_depth;
12263
12264 /* Free all the tree nodes making up this function. */
12265 /* Switch back to allocating nodes permanently
12266 until we start another function. */
12267 if (processing_template_decl)
12268 {
12269 --minimal_parse_mode;
12270 DECL_SAVED_TREE (fndecl) = TREE_CHAIN (DECL_SAVED_TREE (fndecl));
12271 }
12272
12273 if (! nested)
12274 permanent_allocation (1);
12275
12276 if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
12277 {
12278 tree t;
12279
12280 /* Stop pointing to the local nodes about to be freed. */
12281 /* But DECL_INITIAL must remain nonzero so we know this
12282 was an actual function definition. */
12283 DECL_INITIAL (fndecl) = error_mark_node;
12284 for (t = DECL_ARGUMENTS (fndecl); t; t = TREE_CHAIN (t))
12285 DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX;
12286 }
12287
12288 if (DECL_STATIC_CONSTRUCTOR (fndecl))
12289 static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors);
12290 if (DECL_STATIC_DESTRUCTOR (fndecl))
12291 static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors);
12292
12293 if (! nested)
12294 {
12295 /* Let the error reporting routines know that we're outside a
12296 function. For a nested function, this value is used in
12297 pop_cp_function_context and then reset via pop_function_context. */
12298 current_function_decl = NULL_TREE;
12299 }
12300
12301 named_label_uses = NULL;
12302 current_class_ptr = NULL_TREE;
12303 current_class_ref = NULL_TREE;
12304 }
12305 \f
12306 /* Create the FUNCTION_DECL for a function definition.
12307 LINE1 is the line number that the definition absolutely begins on.
12308 LINE2 is the line number that the name of the function appears on.
12309 DECLSPECS and DECLARATOR are the parts of the declaration;
12310 they describe the return type and the name of the function,
12311 but twisted together in a fashion that parallels the syntax of C.
12312
12313 This function creates a binding context for the function body
12314 as well as setting up the FUNCTION_DECL in current_function_decl.
12315
12316 Returns a FUNCTION_DECL on success.
12317
12318 If the DECLARATOR is not suitable for a function (it defines a datum
12319 instead), we return 0, which tells yyparse to report a parse error.
12320
12321 May return void_type_node indicating that this method is actually
12322 a friend. See grokfield for more details.
12323
12324 Came here with a `.pushlevel' .
12325
12326 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
12327 CHANGES TO CODE IN `grokfield'. */
12328
12329 tree
12330 start_method (declspecs, declarator)
12331 tree declarator, declspecs;
12332 {
12333 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
12334 NULL_TREE);
12335
12336 /* Something too ugly to handle. */
12337 if (fndecl == NULL_TREE)
12338 return NULL_TREE;
12339
12340 /* Pass friends other than inline friend functions back. */
12341 if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
12342 return fndecl;
12343
12344 if (TREE_CODE (fndecl) != FUNCTION_DECL)
12345 /* Not a function, tell parser to report parse error. */
12346 return NULL_TREE;
12347
12348 if (IS_SIGNATURE (current_class_type))
12349 IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
12350
12351 if (DECL_IN_AGGR_P (fndecl))
12352 {
12353 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
12354 {
12355 if (DECL_CONTEXT (fndecl))
12356 cp_error ("`%D' is already defined in class %s", fndecl,
12357 TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
12358 }
12359 return void_type_node;
12360 }
12361
12362 DECL_THIS_INLINE (fndecl) = 1;
12363
12364 if (flag_default_inline)
12365 DECL_INLINE (fndecl) = 1;
12366
12367 if (processing_template_decl && ! current_function_decl)
12368 push_template_decl (fndecl);
12369
12370 /* We read in the parameters on the maybepermanent_obstack,
12371 but we won't be getting back to them until after we
12372 may have clobbered them. So the call to preserve_data
12373 will keep them safe. */
12374 preserve_data ();
12375
12376 if (! DECL_FRIEND_P (fndecl))
12377 {
12378 if (DECL_CHAIN (fndecl) != NULL_TREE)
12379 {
12380 /* Need a fresh node here so that we don't get circularity
12381 when we link these together. If FNDECL was a friend, then
12382 `pushdecl' does the right thing, which is nothing wrt its
12383 current value of DECL_CHAIN. */
12384 fndecl = copy_node (fndecl);
12385 }
12386 if (TREE_CHAIN (fndecl))
12387 {
12388 fndecl = copy_node (fndecl);
12389 TREE_CHAIN (fndecl) = NULL_TREE;
12390 }
12391
12392 if (DECL_CONSTRUCTOR_P (fndecl))
12393 {
12394 if (! grok_ctor_properties (current_class_type, fndecl))
12395 return void_type_node;
12396 }
12397 else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
12398 grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
12399 }
12400
12401 cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0);
12402
12403 /* Make a place for the parms */
12404 pushlevel (0);
12405 current_binding_level->parm_flag = 1;
12406
12407 DECL_IN_AGGR_P (fndecl) = 1;
12408 return fndecl;
12409 }
12410
12411 /* Go through the motions of finishing a function definition.
12412 We don't compile this method until after the whole class has
12413 been processed.
12414
12415 FINISH_METHOD must return something that looks as though it
12416 came from GROKFIELD (since we are defining a method, after all).
12417
12418 This is called after parsing the body of the function definition.
12419 STMTS is the chain of statements that makes up the function body.
12420
12421 DECL is the ..._DECL that `start_method' provided. */
12422
12423 tree
12424 finish_method (decl)
12425 tree decl;
12426 {
12427 register tree fndecl = decl;
12428 tree old_initial;
12429
12430 register tree link;
12431
12432 if (TYPE_MAIN_VARIANT (decl) == void_type_node)
12433 return decl;
12434
12435 old_initial = DECL_INITIAL (fndecl);
12436
12437 /* Undo the level for the parms (from start_method).
12438 This is like poplevel, but it causes nothing to be
12439 saved. Saving information here confuses symbol-table
12440 output routines. Besides, this information will
12441 be correctly output when this method is actually
12442 compiled. */
12443
12444 /* Clear out the meanings of the local variables of this level;
12445 also record in each decl which block it belongs to. */
12446
12447 for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
12448 {
12449 if (DECL_NAME (link) != NULL_TREE)
12450 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
12451 my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
12452 DECL_CONTEXT (link) = NULL_TREE;
12453 }
12454
12455 /* Restore all name-meanings of the outer levels
12456 that were shadowed by this level. */
12457
12458 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
12459 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12460 for (link = current_binding_level->class_shadowed;
12461 link; link = TREE_CHAIN (link))
12462 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12463 for (link = current_binding_level->type_shadowed;
12464 link; link = TREE_CHAIN (link))
12465 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12466
12467 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
12468 (HOST_WIDE_INT) current_binding_level->level_chain,
12469 current_binding_level->parm_flag,
12470 current_binding_level->keep);
12471
12472 poplevel (0, 0, 0);
12473
12474 DECL_INITIAL (fndecl) = old_initial;
12475
12476 /* We used to check if the context of FNDECL was different from
12477 current_class_type as another way to get inside here. This didn't work
12478 for String.cc in libg++. */
12479 if (DECL_FRIEND_P (fndecl))
12480 {
12481 CLASSTYPE_INLINE_FRIENDS (current_class_type)
12482 = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
12483 decl = void_type_node;
12484 }
12485
12486 return decl;
12487 }
12488 \f
12489 /* Called when a new struct TYPE is defined.
12490 If this structure or union completes the type of any previous
12491 variable declaration, lay it out and output its rtl. */
12492
12493 void
12494 hack_incomplete_structures (type)
12495 tree type;
12496 {
12497 tree *list;
12498
12499 if (current_binding_level->incomplete == NULL_TREE)
12500 return;
12501
12502 if (!type) /* Don't do this for class templates. */
12503 return;
12504
12505 for (list = &current_binding_level->incomplete; *list; )
12506 {
12507 tree decl = TREE_VALUE (*list);
12508 if (decl && TREE_TYPE (decl) == type
12509 || (TREE_TYPE (decl)
12510 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
12511 && TREE_TYPE (TREE_TYPE (decl)) == type))
12512 {
12513 int toplevel = toplevel_bindings_p ();
12514 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
12515 && TREE_TYPE (TREE_TYPE (decl)) == type)
12516 layout_type (TREE_TYPE (decl));
12517 layout_decl (decl, 0);
12518 rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
12519 if (! toplevel)
12520 {
12521 tree cleanup;
12522 expand_decl (decl);
12523 cleanup = maybe_build_cleanup (decl);
12524 expand_decl_init (decl);
12525 if (! expand_decl_cleanup (decl, cleanup))
12526 cp_error ("parser lost in parsing declaration of `%D'",
12527 decl);
12528 }
12529 *list = TREE_CHAIN (*list);
12530 }
12531 else
12532 list = &TREE_CHAIN (*list);
12533 }
12534 }
12535
12536 /* If DECL is of a type which needs a cleanup, build that cleanup here.
12537 See build_delete for information about AUTO_DELETE.
12538
12539 Don't build these on the momentary obstack; they must live
12540 the life of the binding contour. */
12541
12542 static tree
12543 maybe_build_cleanup_1 (decl, auto_delete)
12544 tree decl, auto_delete;
12545 {
12546 tree type = TREE_TYPE (decl);
12547 if (TYPE_NEEDS_DESTRUCTOR (type))
12548 {
12549 int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
12550 tree rval;
12551
12552 if (TREE_CODE (decl) != PARM_DECL)
12553 temp = suspend_momentary ();
12554
12555 if (TREE_CODE (type) == ARRAY_TYPE)
12556 rval = decl;
12557 else
12558 {
12559 mark_addressable (decl);
12560 rval = build_unary_op (ADDR_EXPR, decl, 0);
12561 }
12562
12563 /* Optimize for space over speed here. */
12564 if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
12565 || flag_expensive_optimizations)
12566 flags |= LOOKUP_NONVIRTUAL;
12567
12568 rval = build_delete (TREE_TYPE (rval), rval, auto_delete, flags, 0);
12569
12570 if (TYPE_USES_VIRTUAL_BASECLASSES (type)
12571 && ! TYPE_HAS_DESTRUCTOR (type))
12572 rval = build_compound_expr (tree_cons (NULL_TREE, rval,
12573 build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
12574
12575 if (TREE_CODE (decl) != PARM_DECL)
12576 resume_momentary (temp);
12577
12578 return rval;
12579 }
12580 return 0;
12581 }
12582
12583 /* If DECL is of a type which needs a cleanup, build that cleanup
12584 here. The cleanup does free the storage with a call to delete. */
12585
12586 tree
12587 maybe_build_cleanup_and_delete (decl)
12588 tree decl;
12589 {
12590 return maybe_build_cleanup_1 (decl, integer_three_node);
12591 }
12592
12593 /* If DECL is of a type which needs a cleanup, build that cleanup
12594 here. The cleanup does not free the storage with a call a delete. */
12595
12596 tree
12597 maybe_build_cleanup (decl)
12598 tree decl;
12599 {
12600 return maybe_build_cleanup_1 (decl, integer_two_node);
12601 }
12602 \f
12603 /* Expand a C++ expression at the statement level.
12604 This is needed to ferret out nodes which have UNKNOWN_TYPE.
12605 The C++ type checker should get all of these out when
12606 expressions are combined with other, type-providing, expressions,
12607 leaving only orphan expressions, such as:
12608
12609 &class::bar; / / takes its address, but does nothing with it. */
12610
12611 void
12612 cplus_expand_expr_stmt (exp)
12613 tree exp;
12614 {
12615 if (processing_template_decl)
12616 {
12617 add_tree (build_min_nt (EXPR_STMT, exp));
12618 return;
12619 }
12620
12621 /* Arrange for all temps to disappear. */
12622 expand_start_target_temps ();
12623
12624 if (TREE_TYPE (exp) == unknown_type_node)
12625 {
12626 if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
12627 error ("address of overloaded function with no contextual type information");
12628 else if (TREE_CODE (exp) == COMPONENT_REF)
12629 warning ("useless reference to a member function name, did you forget the ()?");
12630 }
12631 else
12632 {
12633 if (TREE_CODE (exp) == FUNCTION_DECL)
12634 {
12635 cp_warning ("reference, not call, to function `%D'", exp);
12636 warning ("at this point in file");
12637 }
12638
12639 #if 0
12640 /* We should do this eventually, but right now this causes regex.o from
12641 libg++ to miscompile, and tString to core dump. */
12642 exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp);
12643 #endif
12644 /* If we don't do this, we end up down inside expand_expr
12645 trying to do TYPE_MODE on the ERROR_MARK, and really
12646 go outside the bounds of the type. */
12647 if (exp != error_mark_node)
12648 expand_expr_stmt (break_out_cleanups (exp));
12649 }
12650
12651 /* Clean up any pending cleanups. This happens when a function call
12652 returns a cleanup-needing value that nobody uses. */
12653 expand_end_target_temps ();
12654 }
12655
12656 /* When a stmt has been parsed, this function is called.
12657
12658 Currently, this function only does something within a
12659 constructor's scope: if a stmt has just assigned to this,
12660 and we are in a derived class, we call `emit_base_init'. */
12661
12662 void
12663 finish_stmt ()
12664 {
12665 extern struct nesting *cond_stack, *loop_stack, *case_stack;
12666
12667
12668 if (current_function_assigns_this
12669 || ! current_function_just_assigned_this)
12670 return;
12671 if (DECL_CONSTRUCTOR_P (current_function_decl))
12672 {
12673 /* Constructors must wait until we are out of control
12674 zones before calling base constructors. */
12675 if (cond_stack || loop_stack || case_stack)
12676 return;
12677 expand_expr_stmt (base_init_expr);
12678 check_base_init (current_class_type);
12679 }
12680 current_function_assigns_this = 1;
12681 }
12682
12683 /* Change a static member function definition into a FUNCTION_TYPE, instead
12684 of the METHOD_TYPE that we create when it's originally parsed.
12685
12686 WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
12687 (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
12688 other decls. Either pass the addresses of local variables or NULL. */
12689
12690 static void
12691 revert_static_member_fn (decl, fn, argtypes)
12692 tree *decl, *fn, *argtypes;
12693 {
12694 tree tmp;
12695 tree function = fn ? *fn : TREE_TYPE (*decl);
12696 tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function);
12697
12698 if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args))))
12699 cp_error ("static member function `%#D' declared const", *decl);
12700 if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args))))
12701 cp_error ("static member function `%#D' declared volatile", *decl);
12702
12703 args = TREE_CHAIN (args);
12704 tmp = build_function_type (TREE_TYPE (function), args);
12705 tmp = build_type_variant (tmp, TYPE_READONLY (function),
12706 TYPE_VOLATILE (function));
12707 tmp = build_exception_variant (tmp,
12708 TYPE_RAISES_EXCEPTIONS (function));
12709 TREE_TYPE (*decl) = tmp;
12710 if (DECL_ARGUMENTS (*decl))
12711 DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl));
12712 DECL_STATIC_FUNCTION_P (*decl) = 1;
12713 if (fn)
12714 *fn = tmp;
12715 if (argtypes)
12716 *argtypes = args;
12717 }
12718
12719 int
12720 id_in_current_class (id)
12721 tree id;
12722 {
12723 return !!purpose_member (id, class_binding_level->class_shadowed);
12724 }
12725
12726 struct cp_function
12727 {
12728 int returns_value;
12729 int returns_null;
12730 int warn_about_return_type;
12731 int assigns_this;
12732 int just_assigned_this;
12733 int parms_stored;
12734 int temp_name_counter;
12735 tree named_labels;
12736 tree shadowed_labels;
12737 tree ctor_label;
12738 tree dtor_label;
12739 rtx last_dtor_insn;
12740 rtx last_parm_cleanup_insn;
12741 tree base_init_list;
12742 tree member_init_list;
12743 tree base_init_expr;
12744 tree current_class_ptr;
12745 tree current_class_ref;
12746 rtx result_rtx;
12747 struct cp_function *next;
12748 struct binding_level *binding_level;
12749 int static_labelno;
12750 };
12751
12752 static struct cp_function *cp_function_chain;
12753
12754 extern int temp_name_counter;
12755
12756 /* Save and reinitialize the variables
12757 used during compilation of a C++ function. */
12758
12759 void
12760 push_cp_function_context (context)
12761 tree context;
12762 {
12763 struct cp_function *p
12764 = (struct cp_function *) xmalloc (sizeof (struct cp_function));
12765
12766 push_function_context_to (context);
12767
12768 p->next = cp_function_chain;
12769 cp_function_chain = p;
12770
12771 p->named_labels = named_labels;
12772 p->shadowed_labels = shadowed_labels;
12773 p->returns_value = current_function_returns_value;
12774 p->returns_null = current_function_returns_null;
12775 p->warn_about_return_type = warn_about_return_type;
12776 p->binding_level = current_binding_level;
12777 p->ctor_label = ctor_label;
12778 p->dtor_label = dtor_label;
12779 p->last_dtor_insn = last_dtor_insn;
12780 p->last_parm_cleanup_insn = last_parm_cleanup_insn;
12781 p->assigns_this = current_function_assigns_this;
12782 p->just_assigned_this = current_function_just_assigned_this;
12783 p->parms_stored = current_function_parms_stored;
12784 p->result_rtx = original_result_rtx;
12785 p->base_init_expr = base_init_expr;
12786 p->temp_name_counter = temp_name_counter;
12787 p->base_init_list = current_base_init_list;
12788 p->member_init_list = current_member_init_list;
12789 p->current_class_ptr = current_class_ptr;
12790 p->current_class_ref = current_class_ref;
12791 p->static_labelno = static_labelno;
12792 }
12793
12794 /* Restore the variables used during compilation of a C++ function. */
12795
12796 void
12797 pop_cp_function_context (context)
12798 tree context;
12799 {
12800 struct cp_function *p = cp_function_chain;
12801 tree link;
12802
12803 /* Bring back all the labels that were shadowed. */
12804 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
12805 if (DECL_NAME (TREE_VALUE (link)) != 0)
12806 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)),
12807 TREE_VALUE (link));
12808
12809 pop_function_context_from (context);
12810
12811 cp_function_chain = p->next;
12812
12813 named_labels = p->named_labels;
12814 shadowed_labels = p->shadowed_labels;
12815 current_function_returns_value = p->returns_value;
12816 current_function_returns_null = p->returns_null;
12817 warn_about_return_type = p->warn_about_return_type;
12818 current_binding_level = p->binding_level;
12819 ctor_label = p->ctor_label;
12820 dtor_label = p->dtor_label;
12821 last_dtor_insn = p->last_dtor_insn;
12822 last_parm_cleanup_insn = p->last_parm_cleanup_insn;
12823 current_function_assigns_this = p->assigns_this;
12824 current_function_just_assigned_this = p->just_assigned_this;
12825 current_function_parms_stored = p->parms_stored;
12826 original_result_rtx = p->result_rtx;
12827 base_init_expr = p->base_init_expr;
12828 temp_name_counter = p->temp_name_counter;
12829 current_base_init_list = p->base_init_list;
12830 current_member_init_list = p->member_init_list;
12831 current_class_ptr = p->current_class_ptr;
12832 current_class_ref = p->current_class_ref;
12833 static_labelno = p->static_labelno;
12834
12835 free (p);
12836 }
12837
12838 int
12839 in_function_p ()
12840 {
12841 return function_depth != 0;
12842 }
12843
12844 /* FSF LOCAL dje prefix attributes */
12845 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
12846 This function is used by the parser when a rule will accept attributes
12847 in a particular position, but we don't want to support that just yet.
12848
12849 A warning is issued for every ignored attribute. */
12850
12851 tree
12852 strip_attrs (specs_attrs)
12853 tree specs_attrs;
12854 {
12855 tree specs, attrs;
12856
12857 split_specs_attrs (specs_attrs, &specs, &attrs);
12858
12859 while (attrs)
12860 {
12861 warning ("`%s' attribute ignored",
12862 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
12863 attrs = TREE_CHAIN (attrs);
12864 }
12865
12866 return specs;
12867 }
12868 /* END FSF LOCAL */
12869
This page took 0.61324 seconds and 5 git commands to generate.