1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
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)
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.
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. */
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. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
38 #include <sys/types.h>
43 #define obstack_chunk_alloc xmalloc
44 #define obstack_chunk_free free
46 extern tree builtin_return_address_fndecl;
48 extern struct obstack permanent_obstack;
50 extern int current_class_depth;
52 extern tree cleanups_this_call;
54 extern tree static_ctors, static_dtors;
56 /* Stack of places to restore the search obstack back to. */
58 /* Obstack used for remembering local class declarations (like
59 enums and static (const) members. */
61 struct obstack decl_obstack;
62 static struct stack_level *decl_stack;
64 #ifndef CHAR_TYPE_SIZE
65 #define CHAR_TYPE_SIZE BITS_PER_UNIT
68 #ifndef SHORT_TYPE_SIZE
69 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
73 #define INT_TYPE_SIZE BITS_PER_WORD
76 #ifndef LONG_TYPE_SIZE
77 #define LONG_TYPE_SIZE BITS_PER_WORD
80 #ifndef LONG_LONG_TYPE_SIZE
81 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
84 #ifndef WCHAR_UNSIGNED
85 #define WCHAR_UNSIGNED 0
88 #ifndef FLOAT_TYPE_SIZE
89 #define FLOAT_TYPE_SIZE BITS_PER_WORD
92 #ifndef DOUBLE_TYPE_SIZE
93 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
96 #ifndef LONG_DOUBLE_TYPE_SIZE
97 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
100 #ifndef BOOL_TYPE_SIZE
101 #ifdef SLOW_BYTE_ACCESS
102 #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (BITS_PER_WORD) : (BITS_PER_UNIT))
104 #define BOOL_TYPE_SIZE BITS_PER_UNIT
108 /* We let tm.h override the types used here, to handle trivial differences
109 such as the choice of unsigned int or long unsigned int for size_t.
110 When machines start needing nontrivial differences in the size type,
111 it would be best to do something here to figure out automatically
112 from other information what type to use. */
115 #define SIZE_TYPE "long unsigned int"
119 #define PTRDIFF_TYPE "long int"
123 #define WCHAR_TYPE "int"
126 static tree grokparms PROTO((tree, int));
127 static tree lookup_nested_type PROTO((tree, tree));
128 static char *redeclaration_error_message PROTO((tree, tree));
129 extern void* push_eh_context PROTO(());
130 extern void pop_eh_context PROTO((void *));
133 PROTO((char *, tree, enum built_in_function, void (*)(), char *));
135 /* a node which has tree code ERROR_MARK, and whose type is itself.
136 All erroneous expressions are replaced with this node. All functions
137 that accept nodes as arguments should avoid generating error messages
138 if this node is one of the arguments, since it is undesirable to get
139 multiple error messages from one error in the input. */
141 tree error_mark_node;
143 /* Erroneous argument lists can use this *IFF* they do not modify it. */
144 tree error_mark_list;
146 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
148 tree short_integer_type_node;
149 tree integer_type_node;
150 tree long_integer_type_node;
151 tree long_long_integer_type_node;
153 tree short_unsigned_type_node;
154 tree unsigned_type_node;
155 tree long_unsigned_type_node;
156 tree long_long_unsigned_type_node;
158 tree ptrdiff_type_node;
160 tree unsigned_char_type_node;
161 tree signed_char_type_node;
163 tree wchar_type_node;
164 tree signed_wchar_type_node;
165 tree unsigned_wchar_type_node;
167 tree wchar_decl_node;
169 tree float_type_node;
170 tree double_type_node;
171 tree long_double_type_node;
173 tree intQI_type_node;
174 tree intHI_type_node;
175 tree intSI_type_node;
176 tree intDI_type_node;
178 tree unsigned_intQI_type_node;
179 tree unsigned_intHI_type_node;
180 tree unsigned_intSI_type_node;
181 tree unsigned_intDI_type_node;
183 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
185 tree void_type_node, void_list_node;
188 /* Nodes for types `void *' and `const void *'. */
190 tree ptr_type_node, const_ptr_type_node;
192 /* Nodes for types `char *' and `const char *'. */
194 tree string_type_node, const_string_type_node;
196 /* Type `char[256]' or something like it.
197 Used when an array of char is needed and the size is irrelevant. */
199 tree char_array_type_node;
201 /* Type `int[256]' or something like it.
202 Used when an array of int needed and the size is irrelevant. */
204 tree int_array_type_node;
206 /* Type `wchar_t[256]' or something like it.
207 Used when a wide string literal is created. */
209 tree wchar_array_type_node;
211 /* The bool data type, and constants */
212 tree boolean_type_node, boolean_true_node, boolean_false_node;
214 /* type `int ()' -- used for implicit declaration of functions. */
216 tree default_function_type;
218 /* function types `double (double)' and `double (double, double)', etc. */
220 tree double_ftype_double, double_ftype_double_double;
221 tree int_ftype_int, long_ftype_long;
222 tree float_ftype_float;
223 tree ldouble_ftype_ldouble;
225 /* Function type `int (const void *, const void *, size_t)' */
226 static tree int_ftype_cptr_cptr_sizet;
229 tree vtable_entry_type;
230 tree delta_type_node;
232 /* Old rtti stuff. */
233 tree __baselist_desc_type_node;
234 tree __i_desc_type_node, __m_desc_type_node;
235 tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
237 tree __t_desc_type_node;
239 tree __tp_desc_type_node;
241 tree __access_mode_type_node;
242 tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node;
243 tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node;
244 tree __ptmf_desc_type_node, __ptmd_desc_type_node;
246 /* Not needed yet? May be needed one day? */
247 tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type;
248 tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type;
249 tree __ptmf_desc_array_type, __ptmd_desc_array_type;
252 tree class_star_type_node;
253 tree class_type_node, record_type_node, union_type_node, enum_type_node;
254 tree unknown_type_node;
255 tree opaque_type_node, signature_type_node;
256 tree sigtable_entry_type;
258 /* Array type `vtable_entry_type[]' */
261 /* In a destructor, the point at which all derived class destroying
262 has been done, just before any base class destroying will be done. */
266 /* In a destructor, the last insn emitted after the start of the
267 function and the parms. */
271 /* In a constructor, the point at which we are ready to return
272 the pointer to the initialized object. */
276 /* A FUNCTION_DECL which can call `abort'. Not necessarily the
277 one that the user will declare, but sufficient to be called
278 by routines that want to abort the program. */
282 extern rtx cleanup_label, return_label;
284 /* If original DECL_RESULT of current function was a register,
285 but due to being an addressable named return value, would up
286 on the stack, this variable holds the named return value's
287 original location. */
288 rtx original_result_rtx;
290 /* Sequence of insns which represents base initialization. */
293 /* C++: Keep these around to reduce calls to `get_identifier'.
294 Identifiers for `this' in member functions and the auto-delete
295 parameter for destructors. */
296 tree this_identifier, in_charge_identifier;
297 /* Used in pointer to member functions, in vtables, and in sigtables. */
298 tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
299 tree pfn_or_delta2_identifier, tag_identifier;
300 tree vt_off_identifier;
302 /* A list (chain of TREE_LIST nodes) of named label uses.
303 The TREE_PURPOSE field is the list of variables defined
304 the the label's scope defined at the point of use.
305 The TREE_VALUE field is the LABEL_DECL used.
306 The TREE_TYPE field holds `current_binding_level' at the
307 point of the label's use.
309 Used only for jumps to as-yet undefined labels, since
310 jumps to defined labels can have their validity checked
313 static tree named_label_uses;
315 /* A list of objects which have constructors or destructors
316 which reside in the global scope. The decl is stored in
317 the TREE_VALUE slot and the initializer is stored
318 in the TREE_PURPOSE slot. */
319 tree static_aggregates;
323 /* Two expressions that are constants with value zero.
324 The first is of type `int', the second of type `void *'. */
326 tree integer_zero_node;
327 tree null_pointer_node;
329 /* A node for the integer constants 1, 2, and 3. */
331 tree integer_one_node, integer_two_node, integer_three_node;
333 /* Nonzero if we have seen an invalid cross reference
334 to a struct, union, or enum, but not yet printed the message. */
336 tree pending_invalid_xref;
337 /* File and line to appear in the eventual error message. */
338 char *pending_invalid_xref_file;
339 int pending_invalid_xref_line;
341 /* While defining an enum type, this is 1 plus the last enumerator
344 static tree enum_next_value;
346 /* Nonzero means that there was overflow computing enum_next_value. */
348 static int enum_overflow;
350 /* Parsing a function declarator leaves a list of parameter names
351 or a chain or parameter decls here. */
353 tree last_function_parms;
355 /* Parsing a function declarator leaves here a chain of structure
356 and enum types declared in the parmlist. */
358 static tree last_function_parm_tags;
360 /* After parsing the declarator that starts a function definition,
361 `start_function' puts here the list of parameter names or chain of decls.
362 `store_parm_decls' finds it here. */
364 static tree current_function_parms;
366 /* Similar, for last_function_parm_tags. */
367 static tree current_function_parm_tags;
369 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
370 that have names. Here so we can clear out their names' definitions
371 at the end of the function. */
373 static tree named_labels;
375 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
377 static tree shadowed_labels;
379 /* The FUNCTION_DECL for the function currently being compiled,
380 or 0 if between functions. */
381 tree current_function_decl;
383 /* Set to 0 at beginning of a function definition, set to 1 if
384 a return statement that specifies a return value is seen. */
386 int current_function_returns_value;
388 /* Set to 0 at beginning of a function definition, set to 1 if
389 a return statement with no argument is seen. */
391 int current_function_returns_null;
393 /* Set to 0 at beginning of a function definition, and whenever
394 a label (case or named) is defined. Set to value of expression
395 returned from function when that value can be transformed into
396 a named return value. */
398 tree current_function_return_value;
400 /* Set to nonzero by `grokdeclarator' for a function
401 whose return type is defaulted, if warnings for this are desired. */
403 static int warn_about_return_type;
405 /* Nonzero means give `double' the same size as `float'. */
407 extern int flag_short_double;
409 /* Nonzero means don't recognize any builtin functions. */
411 extern int flag_no_builtin;
413 /* Nonzero means don't recognize the non-ANSI builtin functions.
416 extern int flag_no_nonansi_builtin;
418 /* Nonzero means enable obscure ANSI features and disable GNU extensions
419 that might cause ANSI-compliant code to be miscompiled. */
421 extern int flag_ansi;
423 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
425 extern int flag_huge_objects;
427 /* Nonzero if we want to conserve space in the .o files. We do this
428 by putting uninitialized data and runtime initialized data into
429 .common instead of .data at the expense of not flagging multiple
431 extern int flag_conserve_space;
433 /* Pointers to the base and current top of the language name stack. */
435 extern tree *current_lang_base, *current_lang_stack;
437 /* C and C++ flags are in decl2.c. */
439 /* Set to 0 at beginning of a constructor, set to 1
440 if that function does an allocation before referencing its
441 instance variable. */
442 static int current_function_assigns_this;
443 int current_function_just_assigned_this;
445 /* Set to 0 at beginning of a function. Set non-zero when
446 store_parm_decls is called. Don't call store_parm_decls
447 if this flag is non-zero! */
448 int current_function_parms_stored;
450 /* Flag used when debugging spew.c */
452 extern int spew_debug;
454 /* This is a copy of the class_shadowed list of the previous class binding
455 contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs
456 when entering another class scope (i.e. a cache miss). */
457 extern tree previous_class_values;
460 /* Allocate a level of searching. */
462 push_decl_level (stack, obstack)
463 struct stack_level *stack;
464 struct obstack *obstack;
466 struct stack_level tem;
469 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
472 /* For each binding contour we allocate a binding_level structure
473 * which records the names defined in that contour.
476 * 1) one for each function definition,
477 * where internal declarations of the parameters appear.
478 * 2) one for each compound statement,
479 * to record its declarations.
481 * The current meaning of a name can be found by searching the levels from
482 * the current one out to the global one.
484 * Off to the side, may be the class_binding_level. This exists
485 * only to catch class-local declarations. It is otherwise
488 * Also there may be binding levels that catch cleanups that
489 * must be run when exceptions occur.
492 /* Note that the information in the `names' component of the global contour
493 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
497 /* A chain of _DECL nodes for all variables, constants, functions,
498 * and typedef types. These are in the reverse of the order supplied.
502 /* A list of structure, union and enum definitions,
503 * for looking up tag names.
504 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
505 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
506 * or ENUMERAL_TYPE node.
508 * C++: the TREE_VALUE nodes can be simple types for component_bindings.
513 /* For each level, a list of shadowed outer-level local definitions
514 to be restored when this level is popped.
515 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
516 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
519 /* Same, for IDENTIFIER_CLASS_VALUE. */
522 /* Same, for IDENTIFIER_TYPE_VALUE. */
525 /* For each level (except not the global one),
526 a chain of BLOCK nodes for all the levels
527 that were entered and exited one level down. */
530 /* The BLOCK node for this level, if one has been preallocated.
531 If 0, the BLOCK is allocated (if needed) when the level is popped. */
534 /* The binding level which this one is contained in (inherits from). */
535 struct binding_level *level_chain;
537 /* List of decls in `names' that have incomplete
538 structure or union types. */
541 /* List of VAR_DECLS saved from a previous for statement.
542 These would be dead in ANSI-conforming code, but might
543 be referenced in traditional code. */
544 tree dead_vars_from_for;
546 /* 1 for the level that holds the parameters of a function.
547 2 for the level that holds a class declaration.
548 3 for levels that hold parameter declarations. */
549 unsigned parm_flag : 4;
551 /* 1 means make a BLOCK for this level regardless of all else.
552 2 for temporary binding contours created by the compiler. */
555 /* Nonzero if this level "doesn't exist" for tags. */
556 unsigned tag_transparent : 1;
558 /* Nonzero if this level can safely have additional
559 cleanup-needing variables added to it. */
560 unsigned more_cleanups_ok : 1;
561 unsigned have_cleanups : 1;
563 /* Nonzero if this level is for storing the decls for template
564 parameters and generic decls; these decls will be discarded and
565 replaced with a TEMPLATE_DECL. */
566 unsigned pseudo_global : 1;
568 /* This is set for a namespace binding level. */
569 unsigned namespace_p : 1;
571 /* True if this level is that of a for-statement where we need to
572 worry about ambiguous (traditional or ANSI) scope rules. */
573 unsigned is_for_scope : 1;
575 /* Two bits left for this word. */
577 #if defined(DEBUG_CP_BINDING_LEVELS)
578 /* Binding depth at which this level began. */
579 unsigned binding_depth;
580 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
583 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
585 /* The (non-class) binding level currently in effect. */
587 static struct binding_level *current_binding_level;
589 /* The binding level of the current class, if any. */
591 static struct binding_level *class_binding_level;
593 /* The current (class or non-class) binding level currently in effect. */
595 #define inner_binding_level \
596 (class_binding_level ? class_binding_level : current_binding_level)
598 /* A chain of binding_level structures awaiting reuse. */
600 static struct binding_level *free_binding_level;
602 /* The outermost binding level, for names of file scope.
603 This is created when the compiler is started and exists
604 through the entire run. */
606 static struct binding_level *global_binding_level;
608 /* Binding level structures are initialized by copying this one. */
610 static struct binding_level clear_binding_level;
612 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
614 static int keep_next_level_flag;
616 #if defined(DEBUG_CP_BINDING_LEVELS)
617 static int binding_depth = 0;
618 static int is_class_level = 0;
625 for (i = 0; i < binding_depth*2; i++)
628 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
630 static tree pushdecl_with_scope PROTO((tree, struct binding_level *));
633 push_binding_level (newlevel, tag_transparent, keep)
634 struct binding_level *newlevel;
635 int tag_transparent, keep;
637 /* Add this level to the front of the chain (stack) of levels that
639 *newlevel = clear_binding_level;
640 if (class_binding_level)
642 newlevel->level_chain = class_binding_level;
643 class_binding_level = (struct binding_level *)0;
647 newlevel->level_chain = current_binding_level;
649 current_binding_level = newlevel;
650 newlevel->tag_transparent = tag_transparent;
651 newlevel->more_cleanups_ok = 1;
652 newlevel->keep = keep;
653 #if defined(DEBUG_CP_BINDING_LEVELS)
654 newlevel->binding_depth = binding_depth;
656 fprintf (stderr, "push %s level 0x%08x line %d\n",
657 (is_class_level) ? "class" : "block", newlevel, lineno);
660 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
666 if (class_binding_level)
667 current_binding_level = class_binding_level;
669 if (global_binding_level)
671 /* cannot pop a level, if there are none left to pop. */
672 if (current_binding_level == global_binding_level)
673 my_friendly_abort (123);
675 /* Pop the current level, and free the structure for reuse. */
676 #if defined(DEBUG_CP_BINDING_LEVELS)
679 fprintf (stderr, "pop %s level 0x%08x line %d\n",
680 (is_class_level) ? "class" : "block",
681 current_binding_level, lineno);
682 if (is_class_level != (current_binding_level == class_binding_level))
685 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
688 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
690 register struct binding_level *level = current_binding_level;
691 current_binding_level = current_binding_level->level_chain;
692 level->level_chain = free_binding_level;
693 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
694 if (level->binding_depth != binding_depth)
696 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
697 free_binding_level = level;
699 class_binding_level = current_binding_level;
700 if (class_binding_level->parm_flag != 2)
701 class_binding_level = 0;
702 while (current_binding_level->parm_flag == 2)
703 current_binding_level = current_binding_level->level_chain;
708 suspend_binding_level ()
710 if (class_binding_level)
711 current_binding_level = class_binding_level;
713 if (global_binding_level)
715 /* cannot suspend a level, if there are none left to suspend. */
716 if (current_binding_level == global_binding_level)
717 my_friendly_abort (123);
719 /* Suspend the current level. */
720 #if defined(DEBUG_CP_BINDING_LEVELS)
723 fprintf (stderr, "suspend %s level 0x%08x line %d\n",
724 (is_class_level) ? "class" : "block",
725 current_binding_level, lineno);
726 if (is_class_level != (current_binding_level == class_binding_level))
729 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
732 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
734 current_binding_level = current_binding_level->level_chain;
735 class_binding_level = current_binding_level;
736 if (class_binding_level->parm_flag != 2)
737 class_binding_level = 0;
738 while (current_binding_level->parm_flag == 2)
739 current_binding_level = current_binding_level->level_chain;
744 resume_binding_level (b)
745 struct binding_level *b;
747 if (class_binding_level)
750 /* These are here because we cannot deal with shadows yet. */
751 sorry ("cannot resume a namespace inside class");
754 b->level_chain = class_binding_level;
755 class_binding_level = (struct binding_level *)0;
761 /* These are here because we cannot deal with shadows yet. */
762 if (b->level_chain != current_binding_level)
764 sorry ("cannot resume a namespace inside a different namespace");
768 b->level_chain = current_binding_level;
770 current_binding_level = b;
771 #if defined(DEBUG_CP_BINDING_LEVELS)
772 b->binding_depth = binding_depth;
774 fprintf (stderr, "resume %s level 0x%08x line %d\n",
775 (is_class_level) ? "class" : "block", b, lineno);
778 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
781 /* Create a new `struct binding_level'. */
784 struct binding_level *
785 make_binding_level ()
788 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
791 /* Nonzero if we are currently in the global binding level. */
796 return current_binding_level == global_binding_level;
799 /* Nonzero if we are currently in a toplevel binding level. This
800 means either the global binding level or a namespace in a toplevel
804 toplevel_bindings_p ()
806 struct binding_level *b = current_binding_level;
810 if (b == global_binding_level)
812 if (b->pseudo_global)
814 if (! b->namespace_p)
820 /* Nonzero if this is a namespace scope. */
823 namespace_bindings_p ()
825 return current_binding_level->namespace_p;
831 keep_next_level_flag = 1;
834 /* Nonzero if the current level needs to have a BLOCK made. */
839 return (current_binding_level->blocks != NULL_TREE
840 || current_binding_level->keep
841 || current_binding_level->names != NULL_TREE
842 || (current_binding_level->tags != NULL_TREE
843 && !current_binding_level->tag_transparent));
846 /* Identify this binding level as a level of parameters. */
849 declare_parm_level ()
851 current_binding_level->parm_flag = 1;
855 declare_pseudo_global_level ()
857 current_binding_level->pseudo_global = 1;
861 declare_namespace_level ()
863 current_binding_level->namespace_p = 1;
867 pseudo_global_level_p ()
869 return current_binding_level->pseudo_global;
873 set_class_shadows (shadows)
876 class_binding_level->class_shadowed = shadows;
879 /* Enter a new binding level.
880 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
881 not for that of tags. */
884 pushlevel (tag_transparent)
887 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
889 /* If this is the top level of a function,
890 just make sure that NAMED_LABELS is 0.
891 They should have been set to 0 at the end of the previous function. */
893 if (current_binding_level == global_binding_level)
894 my_friendly_assert (named_labels == NULL_TREE, 134);
896 /* Reuse or create a struct for this binding level. */
898 #if defined(DEBUG_CP_BINDING_LEVELS)
900 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
901 if (free_binding_level)
902 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
904 newlevel = free_binding_level;
905 free_binding_level = free_binding_level->level_chain;
909 newlevel = make_binding_level ();
912 push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
913 GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
914 keep_next_level_flag = 0;
918 note_level_for_for ()
920 current_binding_level->is_for_scope = 1;
924 pushlevel_temporary (tag_transparent)
927 pushlevel (tag_transparent);
928 current_binding_level->keep = 2;
931 /* Note we don't call push_momentary() here. Otherwise, it would cause
932 cleanups to be allocated on the momentary obstack, and they will be
933 overwritten by the next statement. */
935 expand_start_bindings (0);
938 /* Exit a binding level.
939 Pop the level off, and restore the state of the identifier-decl mappings
940 that were in effect when this level was entered.
942 If KEEP == 1, this level had explicit declarations, so
943 and create a "block" (a BLOCK node) for the level
944 to record its declarations and subblocks for symbol table output.
946 If KEEP == 2, this level's subblocks go to the front,
947 not the back of the current binding level. This happens,
948 for instance, when code for constructors and destructors
949 need to generate code at the end of a function which must
950 be moved up to the front of the function.
952 If FUNCTIONBODY is nonzero, this level is the body of a function,
953 so create a block as if KEEP were set and also clear out all
956 If REVERSE is nonzero, reverse the order of decls before putting
957 them into the BLOCK. */
960 poplevel (keep, reverse, functionbody)
966 /* The chain of decls was accumulated in reverse order.
967 Put it into forward order, just for cleanliness. */
969 int tmp = functionbody;
970 int real_functionbody = current_binding_level->keep == 2
971 ? ((functionbody = 0), tmp) : functionbody;
972 tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
973 tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
974 tree block = NULL_TREE;
976 int block_previously_created;
978 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
979 (HOST_WIDE_INT) current_binding_level->level_chain,
980 current_binding_level->parm_flag,
981 current_binding_level->keep);
983 if (current_binding_level->keep == 1)
986 /* Get the decls in the order they were written.
987 Usually current_binding_level->names is in reverse order.
988 But parameter decls were previously put in forward order. */
991 current_binding_level->names
992 = decls = nreverse (current_binding_level->names);
994 decls = current_binding_level->names;
996 /* Output any nested inline functions within this block
997 if they weren't already output. */
999 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1000 if (TREE_CODE (decl) == FUNCTION_DECL
1001 && ! TREE_ASM_WRITTEN (decl)
1002 && DECL_INITIAL (decl) != NULL_TREE
1003 && TREE_ADDRESSABLE (decl)
1004 && decl_function_context (decl) == current_function_decl)
1006 /* If this decl was copied from a file-scope decl
1007 on account of a block-scope extern decl,
1008 propagate TREE_ADDRESSABLE to the file-scope decl. */
1009 if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
1010 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1013 push_function_context ();
1014 output_inline_function (decl);
1015 pop_function_context ();
1019 /* If there were any declarations or structure tags in that level,
1020 or if this level is a function body,
1021 create a BLOCK to record them for the life of this function. */
1024 block_previously_created = (current_binding_level->this_block != NULL_TREE);
1025 if (block_previously_created)
1026 block = current_binding_level->this_block;
1027 else if (keep == 1 || functionbody)
1028 block = make_node (BLOCK);
1029 if (block != NULL_TREE)
1031 if (block_previously_created)
1033 if (decls || tags || subblocks)
1035 if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block))
1037 warning ("internal compiler error: debugging info corrupted");
1039 BLOCK_VARS (block) = decls;
1040 BLOCK_TYPE_TAGS (block) = tags;
1042 /* We can have previous subblocks and new subblocks when
1043 doing fixup_gotos with complex cleanups. We chain the new
1044 subblocks onto the end of any pre-existing subblocks. */
1045 BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block),
1048 /* If we created the block earlier on, and we are just
1049 diddling it now, then it already should have a proper
1050 BLOCK_END_NOTE value associated with it. */
1054 BLOCK_VARS (block) = decls;
1055 BLOCK_TYPE_TAGS (block) = tags;
1056 BLOCK_SUBBLOCKS (block) = subblocks;
1057 /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */
1058 remember_end_note (block);
1062 /* In each subblock, record that this is its superior. */
1065 for (link = subblocks; link; link = TREE_CHAIN (link))
1066 BLOCK_SUPERCONTEXT (link) = block;
1068 /* Clear out the meanings of the local variables of this level. */
1070 if (current_binding_level->is_for_scope && flag_new_for_scope == 1)
1072 struct binding_level *outer = current_binding_level->level_chain;
1073 for (link = decls; link; link = TREE_CHAIN (link))
1075 if (TREE_CODE (link) == VAR_DECL)
1076 DECL_DEAD_FOR_LOCAL (link) = 1;
1079 /* Save declarations made in a 'for' statement so we can support pre-ANSI
1080 'for' scoping semantics. */
1082 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1084 tree id = TREE_PURPOSE (link);
1085 tree decl = IDENTIFIER_LOCAL_VALUE (id);
1087 /* In this case keep the dead for-decl visible,
1088 but remember what (if anything) it shadowed. */
1089 DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link);
1090 TREE_CHAIN (decl) = outer->dead_vars_from_for;
1091 outer->dead_vars_from_for = decl;
1094 else /* Not special for scope. */
1096 for (link = decls; link; link = TREE_CHAIN (link))
1098 if (DECL_NAME (link) != NULL_TREE)
1100 /* If the ident. was used or addressed via a local extern decl,
1101 don't forget that fact. */
1102 if (DECL_EXTERNAL (link))
1104 if (TREE_USED (link))
1105 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1106 if (TREE_ADDRESSABLE (link))
1107 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1109 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1113 /* Restore all name-meanings of the outer levels
1114 that were shadowed by this level. */
1116 for (link = current_binding_level->shadowed;
1117 link; link = TREE_CHAIN (link))
1118 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1120 /* We first restore the regular decls and *then* the dead_vars_from_for
1121 to handle this case:
1125 for (int i; ; ) { ...} // i#2
1129 In this case, we want remove the binding for i#3, restoring
1130 that of i#2. Then we want to remove the binding for i#2,
1131 and restore that of i#1. */
1133 link = current_binding_level->dead_vars_from_for;
1134 for (; link != NULL_TREE; link = TREE_CHAIN (link))
1136 tree id = DECL_NAME (link);
1137 if (IDENTIFIER_LOCAL_VALUE (id) == link)
1138 IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link);
1141 for (link = current_binding_level->class_shadowed;
1142 link; link = TREE_CHAIN (link))
1143 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1144 for (link = current_binding_level->type_shadowed;
1145 link; link = TREE_CHAIN (link))
1146 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1149 /* If the level being exited is the top level of a function,
1150 check over all the labels. */
1154 /* If this is the top level block of a function,
1155 the vars are the function's parameters.
1156 Don't leave them in the BLOCK because they are
1157 found in the FUNCTION_DECL instead. */
1159 BLOCK_VARS (block) = 0;
1161 /* Clear out the definitions of all label names,
1162 since their scopes end here. */
1164 for (link = named_labels; link; link = TREE_CHAIN (link))
1166 register tree label = TREE_VALUE (link);
1168 if (DECL_INITIAL (label) == NULL_TREE)
1170 cp_error_at ("label `%D' used but not defined", label);
1171 /* Avoid crashing later. */
1172 define_label (input_filename, 1, DECL_NAME (label));
1174 else if (warn_unused && !TREE_USED (label))
1175 cp_warning_at ("label `%D' defined but not used", label);
1176 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
1178 /* Put the labels into the "variables" of the
1179 top-level block, so debugger can see them. */
1180 TREE_CHAIN (label) = BLOCK_VARS (block);
1181 BLOCK_VARS (block) = label;
1184 named_labels = NULL_TREE;
1187 /* Any uses of undefined labels now operate under constraints
1188 of next binding contour. */
1190 struct binding_level *level_chain;
1191 level_chain = current_binding_level->level_chain;
1195 for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
1196 if (TREE_TYPE (labels) == (tree)current_binding_level)
1198 TREE_TYPE (labels) = (tree)level_chain;
1199 TREE_PURPOSE (labels) = level_chain->names;
1204 tmp = current_binding_level->keep;
1206 pop_binding_level ();
1208 DECL_INITIAL (current_function_decl) = block;
1211 if (!block_previously_created)
1212 current_binding_level->blocks
1213 = chainon (current_binding_level->blocks, block);
1215 /* If we did not make a block for the level just exited,
1216 any blocks made for inner levels
1217 (since they cannot be recorded as subblocks in that level)
1218 must be carried forward so they will later become subblocks
1219 of something else. */
1223 current_binding_level->blocks
1224 = chainon (subblocks, current_binding_level->blocks);
1226 current_binding_level->blocks
1227 = chainon (current_binding_level->blocks, subblocks);
1230 /* Take care of compiler's internal binding structures. */
1233 expand_end_bindings (getdecls (), keep, 1);
1234 /* Each and every BLOCK node created here in `poplevel' is important
1235 (e.g. for proper debugging information) so if we created one
1236 earlier, mark it as "used". */
1238 TREE_USED (block) = 1;
1239 block = poplevel (keep, reverse, real_functionbody);
1242 /* Each and every BLOCK node created here in `poplevel' is important
1243 (e.g. for proper debugging information) so if we created one
1244 earlier, mark it as "used". */
1246 TREE_USED (block) = 1;
1250 /* Resume a binding level for a namespace. */
1253 struct binding_level *b;
1257 resume_binding_level (b);
1259 /* Resume the variable caches. */
1260 decls = current_binding_level->names;
1262 /* Restore the meanings of the local variables of this level. */
1264 for (link = decls; link; link = TREE_CHAIN (link))
1266 /* If it doesn't have a name, there is nothing left to do with it. */
1267 if (DECL_NAME (link) == NULL_TREE)
1270 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link;
1272 /* If this is a TYPE_DECL, push it into the type value slot. */
1273 if (TREE_CODE (link) == TYPE_DECL)
1274 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link));
1278 /* Delete the node BLOCK from the current binding level.
1279 This is used for the block inside a stmt expr ({...})
1280 so that the block can be reinserted where appropriate. */
1283 delete_block (block)
1287 if (current_binding_level->blocks == block)
1288 current_binding_level->blocks = TREE_CHAIN (block);
1289 for (t = current_binding_level->blocks; t;)
1291 if (TREE_CHAIN (t) == block)
1292 TREE_CHAIN (t) = TREE_CHAIN (block);
1296 TREE_CHAIN (block) = NULL_TREE;
1297 /* Clear TREE_USED which is always set by poplevel.
1298 The flag is set again if insert_block is called. */
1299 TREE_USED (block) = 0;
1302 /* Insert BLOCK at the end of the list of subblocks of the
1303 current binding level. This is used when a BIND_EXPR is expanded,
1304 to handle the BLOCK node inside the BIND_EXPR. */
1307 insert_block (block)
1310 TREE_USED (block) = 1;
1311 current_binding_level->blocks
1312 = chainon (current_binding_level->blocks, block);
1315 /* Add BLOCK to the current list of blocks for this binding contour. */
1317 add_block_current_level (block)
1320 current_binding_level->blocks
1321 = chainon (current_binding_level->blocks, block);
1324 /* Set the BLOCK node for the innermost scope
1325 (the one we are currently in). */
1329 register tree block;
1331 current_binding_level->this_block = block;
1334 /* Do a pushlevel for class declarations. */
1338 register struct binding_level *newlevel;
1340 /* Reuse or create a struct for this binding level. */
1341 #if defined(DEBUG_CP_BINDING_LEVELS)
1343 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1344 if (free_binding_level)
1345 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1347 newlevel = free_binding_level;
1348 free_binding_level = free_binding_level->level_chain;
1352 newlevel = make_binding_level ();
1355 #if defined(DEBUG_CP_BINDING_LEVELS)
1357 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1359 push_binding_level (newlevel, 0, 0);
1361 decl_stack = push_decl_level (decl_stack, &decl_obstack);
1362 class_binding_level = current_binding_level;
1363 class_binding_level->parm_flag = 2;
1364 /* We have just pushed into a new binding level. Now, fake out the rest
1365 of the compiler. Set the `current_binding_level' back to point to
1366 the most closely containing non-class binding level. */
1369 current_binding_level = current_binding_level->level_chain;
1371 while (current_binding_level->parm_flag == 2);
1374 /* ...and a poplevel for class declarations. FORCE is used to force
1375 clearing out of CLASS_VALUEs after a class definition. */
1377 poplevel_class (force)
1380 register struct binding_level *level = class_binding_level;
1381 tree block = NULL_TREE;
1384 my_friendly_assert (level != 0, 354);
1386 decl_stack = pop_stack_level (decl_stack);
1387 for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1388 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1389 /* If we're leaving a toplevel class, don't bother to do the setting
1390 of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot
1391 shouldn't even be used when current_class_type isn't set, and second,
1392 if we don't touch it here, we're able to use the cache effect if the
1393 next time we're entering a class scope, it is the same class. */
1394 if (current_class_depth != 1 || force)
1395 for (shadowed = level->class_shadowed;
1397 shadowed = TREE_CHAIN (shadowed))
1398 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1400 /* Remember to save what IDENTIFIER's were bound in this scope so we
1401 can recover from cache misses. */
1402 previous_class_values = class_binding_level->class_shadowed;
1403 for (shadowed = level->type_shadowed;
1405 shadowed = TREE_CHAIN (shadowed))
1406 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1408 GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
1409 (HOST_WIDE_INT) class_binding_level->level_chain,
1410 class_binding_level->parm_flag,
1411 class_binding_level->keep);
1413 if (class_binding_level->parm_flag != 2)
1414 class_binding_level = (struct binding_level *)0;
1416 /* Now, pop out of the the binding level which we created up in the
1417 `pushlevel_class' routine. */
1418 #if defined(DEBUG_CP_BINDING_LEVELS)
1420 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1422 pop_binding_level ();
1427 /* For debugging. */
1428 static int no_print_functions = 0;
1429 static int no_print_builtins = 0;
1432 print_binding_level (lvl)
1433 struct binding_level *lvl;
1437 fprintf (stderr, " blocks=");
1438 fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
1439 fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
1440 list_length (lvl->incomplete), lvl->parm_flag, lvl->keep);
1441 if (lvl->tag_transparent)
1442 fprintf (stderr, " tag-transparent");
1443 if (lvl->more_cleanups_ok)
1444 fprintf (stderr, " more-cleanups-ok");
1445 if (lvl->have_cleanups)
1446 fprintf (stderr, " have-cleanups");
1447 fprintf (stderr, "\n");
1450 fprintf (stderr, " names:\t");
1451 /* We can probably fit 3 names to a line? */
1452 for (t = lvl->names; t; t = TREE_CHAIN (t))
1454 if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL))
1456 if (no_print_builtins
1457 && (TREE_CODE(t) == TYPE_DECL)
1458 && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
1461 /* Function decls tend to have longer names. */
1462 if (TREE_CODE (t) == FUNCTION_DECL)
1469 fprintf (stderr, "\n\t");
1472 print_node_brief (stderr, "", t, 0);
1473 if (TREE_CODE (t) == ERROR_MARK)
1477 fprintf (stderr, "\n");
1481 fprintf (stderr, " tags:\t");
1483 for (t = lvl->tags; t; t = TREE_CHAIN (t))
1485 if (TREE_PURPOSE (t) == NULL_TREE)
1487 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1494 fprintf (stderr, "\n\t");
1497 if (TREE_PURPOSE (t) == NULL_TREE)
1499 print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1500 fprintf (stderr, ">");
1502 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1503 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1506 print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1507 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1508 fprintf (stderr, ">");
1512 fprintf (stderr, "\n");
1516 fprintf (stderr, " shadowed:");
1517 for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1519 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1521 fprintf (stderr, "\n");
1523 if (lvl->class_shadowed)
1525 fprintf (stderr, " class-shadowed:");
1526 for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1528 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1530 fprintf (stderr, "\n");
1532 if (lvl->type_shadowed)
1534 fprintf (stderr, " type-shadowed:");
1535 for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1537 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1539 fprintf (stderr, "\n");
1544 print_other_binding_stack (stack)
1545 struct binding_level *stack;
1547 struct binding_level *level;
1548 for (level = stack; level != global_binding_level; level = level->level_chain)
1550 fprintf (stderr, "binding level ");
1551 fprintf (stderr, HOST_PTR_PRINTF, level);
1552 fprintf (stderr, "\n");
1553 print_binding_level (level);
1558 print_binding_stack ()
1560 struct binding_level *b;
1561 fprintf (stderr, "current_binding_level=");
1562 fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
1563 fprintf (stderr, "\nclass_binding_level=");
1564 fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
1565 fprintf (stderr, "\nglobal_binding_level=");
1566 fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
1567 fprintf (stderr, "\n");
1568 if (class_binding_level)
1570 for (b = class_binding_level; b; b = b->level_chain)
1571 if (b == current_binding_level)
1574 b = class_binding_level;
1576 b = current_binding_level;
1579 b = current_binding_level;
1580 print_other_binding_stack (b);
1581 fprintf (stderr, "global:\n");
1582 print_binding_level (global_binding_level);
1585 extern char * first_global_object_name;
1587 /* Get a unique name for each call to this routine for unnamed namespaces.
1588 Mostly copied from get_file_function_name. */
1592 static int temp_name_counter = 0;
1596 if (first_global_object_name)
1597 p = first_global_object_name;
1598 else if (main_input_filename)
1599 p = main_input_filename;
1603 #define UNNAMED_NAMESPACE_FORMAT "__%s_%d"
1605 buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p));
1607 sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++);
1609 /* Don't need to pull weird characters out of global names. */
1610 if (p != first_global_object_name)
1612 for (p = buf+11; *p; p++)
1613 if (! ((*p >= '0' && *p <= '9')
1614 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
1617 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
1620 || (*p >= 'A' && *p <= 'Z')
1621 || (*p >= 'a' && *p <= 'z')))
1625 return get_identifier (buf);
1628 /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we
1629 select a name that is unique to this compilation unit. */
1631 push_namespace (name)
1634 extern tree current_namespace;
1635 tree old_id = get_namespace_id ();
1641 /* Create a truly ugly name! */
1642 name = get_unique_name ();
1645 d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
1647 /* Mark them as external, so redeclaration_error_message doesn't think
1648 they are duplicates. */
1650 DECL_EXTERNAL (d) = 1;
1653 if (NAMESPACE_LEVEL (d) == 0)
1655 /* This is new for this compilation unit. */
1657 declare_namespace_level ();
1658 NAMESPACE_LEVEL (d) = current_binding_level;
1661 resume_level (NAMESPACE_LEVEL (d));
1663 /* This code is just is bit old now... */
1664 current_namespace = tree_cons (NULL_TREE, name, current_namespace);
1665 buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0)
1666 + IDENTIFIER_LENGTH (name));
1667 sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "",
1668 IDENTIFIER_POINTER (name));
1669 TREE_PURPOSE (current_namespace) = get_identifier (buf);
1672 /* Pop from the scope of the current namespace. */
1676 extern tree current_namespace;
1678 current_namespace = TREE_CHAIN (current_namespace);
1680 /* Just in case we get out of sync. */
1681 if (! namespace_bindings_p ())
1684 decls = current_binding_level->names;
1686 /* Clear out the meanings of the local variables of this level. */
1688 for (link = decls; link; link = TREE_CHAIN (link))
1690 if (DECL_NAME (link) != NULL_TREE)
1692 /* If the ident. was used or addressed via a local extern decl,
1693 don't forget that fact. */
1694 if (DECL_EXTERNAL (link))
1696 if (TREE_USED (link))
1697 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1698 if (TREE_ADDRESSABLE (link))
1699 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1701 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1705 /* Restore all name-meanings of the outer levels
1706 that were shadowed by this level. */
1708 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1709 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1710 for (link = current_binding_level->class_shadowed;
1711 link; link = TREE_CHAIN (link))
1712 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1713 for (link = current_binding_level->type_shadowed;
1714 link; link = TREE_CHAIN (link))
1715 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1717 /* suspend a level. */
1718 suspend_binding_level ();
1721 /* Subroutines for reverting temporarily to top-level for instantiation
1722 of templates and such. We actually need to clear out the class- and
1723 local-value slots of all identifiers, so that only the global values
1724 are at all visible. Simply setting current_binding_level to the global
1725 scope isn't enough, because more binding levels may be pushed. */
1726 struct saved_scope {
1727 struct binding_level *old_binding_level;
1729 struct saved_scope *prev;
1730 tree class_name, class_type, function_decl;
1731 tree base_init_list, member_init_list;
1732 struct binding_level *class_bindings;
1733 tree previous_class_type, previous_class_values;
1734 tree *lang_base, *lang_stack, lang_name;
1737 int minimal_parse_mode;
1738 tree last_function_parms;
1740 static struct saved_scope *current_saved_scope;
1741 extern tree prev_class_type;
1744 store_bindings (names, old_bindings)
1745 tree names, old_bindings;
1748 for (t = names; t; t = TREE_CHAIN (t))
1750 tree binding, t1, id;
1752 if (TREE_CODE (t) == TREE_LIST)
1753 id = TREE_PURPOSE (t);
1758 || (!IDENTIFIER_LOCAL_VALUE (id)
1759 && !IDENTIFIER_CLASS_VALUE (id)))
1762 for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1763 if (TREE_VEC_ELT (t1, 0) == id)
1766 binding = make_tree_vec (4);
1769 my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
1770 TREE_VEC_ELT (binding, 0) = id;
1771 TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1772 TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1773 TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1774 IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
1775 IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
1777 TREE_CHAIN (binding) = old_bindings;
1778 old_bindings = binding;
1782 return old_bindings;
1786 maybe_push_to_top_level (pseudo)
1789 extern int current_lang_stacksize;
1790 struct saved_scope *s =
1791 (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1792 struct binding_level *b = inner_binding_level;
1793 tree old_bindings = NULL_TREE;
1795 /* Have to include global_binding_level, because class-level decls
1796 aren't listed anywhere useful. */
1797 for (; b; b = b->level_chain)
1801 if (b == global_binding_level || (pseudo && b->pseudo_global))
1804 old_bindings = store_bindings (b->names, old_bindings);
1805 /* We also need to check class_shadowed to save class-level type
1806 bindings, since pushclass doesn't fill in b->names. */
1807 if (b->parm_flag == 2)
1808 old_bindings = store_bindings (b->class_shadowed, old_bindings);
1810 /* Unwind type-value slots back to top level. */
1811 for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1812 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1814 /* Clear out class-level bindings cache. */
1815 if (current_binding_level == global_binding_level
1816 && previous_class_type != NULL_TREE)
1819 previous_class_type = NULL_TREE;
1822 s->old_binding_level = current_binding_level;
1823 current_binding_level = b;
1825 s->class_name = current_class_name;
1826 s->class_type = current_class_type;
1827 s->function_decl = current_function_decl;
1828 s->base_init_list = current_base_init_list;
1829 s->member_init_list = current_member_init_list;
1830 s->class_bindings = class_binding_level;
1831 s->previous_class_type = previous_class_type;
1832 s->previous_class_values = previous_class_values;
1833 s->lang_stack = current_lang_stack;
1834 s->lang_base = current_lang_base;
1835 s->lang_stacksize = current_lang_stacksize;
1836 s->lang_name = current_lang_name;
1837 s->named_labels = named_labels;
1838 s->minimal_parse_mode = minimal_parse_mode;
1839 s->last_function_parms = last_function_parms;
1840 current_class_name = current_class_type = NULL_TREE;
1841 current_function_decl = NULL_TREE;
1842 class_binding_level = (struct binding_level *)0;
1843 previous_class_type = NULL_TREE;
1844 current_lang_stacksize = 10;
1845 current_lang_stack = current_lang_base
1846 = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
1847 current_lang_name = lang_name_cplusplus;
1848 strict_prototype = strict_prototypes_lang_cplusplus;
1849 named_labels = NULL_TREE;
1850 minimal_parse_mode = 0;
1852 s->prev = current_saved_scope;
1853 s->old_bindings = old_bindings;
1854 current_saved_scope = s;
1856 push_obstacks (&permanent_obstack, &permanent_obstack);
1860 push_to_top_level ()
1862 maybe_push_to_top_level (0);
1866 pop_from_top_level ()
1868 extern int current_lang_stacksize;
1869 struct saved_scope *s = current_saved_scope;
1872 if (previous_class_type)
1873 previous_class_type = NULL_TREE;
1877 current_binding_level = s->old_binding_level;
1878 current_saved_scope = s->prev;
1879 for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1881 tree id = TREE_VEC_ELT (t, 0);
1884 IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1885 IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1886 IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1889 current_class_name = s->class_name;
1890 current_class_type = s->class_type;
1891 current_base_init_list = s->base_init_list;
1892 current_member_init_list = s->member_init_list;
1893 current_function_decl = s->function_decl;
1894 class_binding_level = s->class_bindings;
1895 previous_class_type = s->previous_class_type;
1896 previous_class_values = s->previous_class_values;
1897 free (current_lang_base);
1898 current_lang_base = s->lang_base;
1899 current_lang_stack = s->lang_stack;
1900 current_lang_name = s->lang_name;
1901 current_lang_stacksize = s->lang_stacksize;
1902 if (current_lang_name == lang_name_cplusplus)
1903 strict_prototype = strict_prototypes_lang_cplusplus;
1904 else if (current_lang_name == lang_name_c)
1905 strict_prototype = strict_prototypes_lang_c;
1906 named_labels = s->named_labels;
1907 minimal_parse_mode = s->minimal_parse_mode;
1908 last_function_parms = s->last_function_parms;
1913 /* Push a definition of struct, union or enum tag "name".
1914 into binding_level "b". "type" should be the type node,
1915 We assume that the tag "name" is not already defined.
1917 Note that the definition may really be just a forward reference.
1918 In that case, the TYPE_SIZE will be a NULL_TREE.
1920 C++ gratuitously puts all these tags in the name space. */
1922 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
1923 record the shadowed value for this binding contour. TYPE is
1924 the type that ID maps to. */
1927 set_identifier_type_value_with_scope (id, type, b)
1930 struct binding_level *b;
1932 if (b != global_binding_level)
1934 tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1936 = tree_cons (id, old_type_value, b->type_shadowed);
1938 SET_IDENTIFIER_TYPE_VALUE (id, type);
1941 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
1944 set_identifier_type_value (id, type)
1948 set_identifier_type_value_with_scope (id, type, inner_binding_level);
1951 /* Subroutine "set_nested_typename" builds the nested-typename of
1952 the type decl in question. (Argument CLASSNAME can actually be
1953 a function as well, if that's the smallest containing scope.) */
1956 set_nested_typename (decl, classname, name, type)
1957 tree decl, classname, name, type;
1960 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
1962 /* No need to do this for anonymous names, since they're unique. */
1963 if (ANON_AGGRNAME_P (name))
1965 DECL_NESTED_TYPENAME (decl) = name;
1969 if (classname == NULL_TREE)
1970 classname = get_identifier ("");
1972 my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
1973 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
1974 buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
1975 + IDENTIFIER_LENGTH (name));
1976 sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
1977 IDENTIFIER_POINTER (name));
1978 DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
1979 TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1;
1981 /* Create an extra decl so that the nested name will have a type value
1982 where appropriate. */
1984 tree nested, type_decl;
1985 nested = DECL_NESTED_TYPENAME (decl);
1986 type_decl = build_decl (TYPE_DECL, nested, type);
1987 DECL_NESTED_TYPENAME (type_decl) = nested;
1988 SET_DECL_ARTIFICIAL (type_decl);
1989 /* Mark the TYPE_DECL node created just above as a gratuitous one so that
1990 dwarfout.c will know not to generate a TAG_typedef DIE for it, and
1991 sdbout.c won't try to output a .def for "::foo". */
1992 DECL_IGNORED_P (type_decl) = 1;
1994 /* Remove this when local classes are fixed. */
1995 SET_IDENTIFIER_TYPE_VALUE (nested, type);
1997 pushdecl_nonclass_level (type_decl);
2001 /* Pop off extraneous binding levels left over due to syntax errors.
2003 We don't pop past namespaces, as they might be valid. */
2007 #ifdef DEBUG_CP_BINDING_LEVELS
2008 fprintf (stderr, "XXX entering pop_everything ()\n");
2010 while (! toplevel_bindings_p () && ! pseudo_global_level_p ())
2012 if (class_binding_level)
2013 pop_nested_class (1);
2017 #ifdef DEBUG_CP_BINDING_LEVELS
2018 fprintf (stderr, "XXX leaving pop_everything ()\n");
2022 /* Push a tag name NAME for struct/class/union/enum type TYPE.
2023 Normally put into into the inner-most non-tag-transparent scope,
2024 but if GLOBALIZE is true, put it in the inner-most non-class scope.
2025 The latter is needed for implicit declarations. */
2028 pushtag (name, type, globalize)
2032 register struct binding_level *b;
2036 b = inner_binding_level;
2037 while (b->tag_transparent
2038 || (globalize && b->parm_flag == 2))
2041 if (toplevel_bindings_p ())
2042 b->tags = perm_tree_cons (name, type, b->tags);
2044 b->tags = saveable_tree_cons (name, type, b->tags);
2048 context = type ? TYPE_CONTEXT (type) : NULL_TREE;
2049 if (! context && ! globalize)
2050 context = current_scope ();
2052 c_decl = TREE_CODE (context) == FUNCTION_DECL
2053 ? context : TYPE_MAIN_DECL (context);
2055 /* Do C++ gratuitous typedefing. */
2056 if (IDENTIFIER_TYPE_VALUE (name) != type)
2061 if (b->parm_flag != 2
2062 || TYPE_SIZE (current_class_type) != NULL_TREE)
2064 d = lookup_nested_type (type, c_decl);
2069 d = build_decl (TYPE_DECL, name, type);
2070 SET_DECL_ARTIFICIAL (d);
2071 #ifdef DWARF_DEBUGGING_INFO
2072 if (write_symbols == DWARF_DEBUG)
2074 /* Mark the TYPE_DECL node we created just above as an
2075 gratuitous one. We need to do this so that dwarfout.c
2076 will understand that it is not supposed to output a
2077 TAG_typedef DIE for it. */
2078 DECL_IGNORED_P (d) = 1;
2080 #endif /* DWARF_DEBUGGING_INFO */
2081 set_identifier_type_value_with_scope (name, type, b);
2086 TYPE_NAME (type) = d;
2087 DECL_CONTEXT (d) = context;
2088 if (! globalize && current_template_parms && IS_AGGR_TYPE (type))
2089 push_template_decl (d);
2091 /* If it is anonymous, then we are called from pushdecl,
2092 and we don't want to infinitely recurse. */
2093 if (! ANON_AGGRNAME_P (name))
2095 if (b->parm_flag == 2)
2096 d = pushdecl_class_level (d);
2098 d = pushdecl_with_scope (d, b);
2103 /* Make nested declarations go into class-level scope. */
2105 d = build_decl (TYPE_DECL, name, type);
2106 SET_DECL_ARTIFICIAL (d);
2107 #ifdef DWARF_DEBUGGING_INFO
2108 if (write_symbols == DWARF_DEBUG)
2110 /* Mark the TYPE_DECL node we created just above as an
2111 gratuitous one. We need to do this so that dwarfout.c
2112 will understand that it is not supposed to output a
2113 TAG_typedef DIE for it. */
2114 DECL_IGNORED_P (d) = 1;
2116 #endif /* DWARF_DEBUGGING_INFO */
2118 TYPE_MAIN_DECL (type) = d;
2119 DECL_CONTEXT (d) = context;
2120 if (! globalize && current_template_parms && IS_AGGR_TYPE (type))
2121 push_template_decl (d);
2123 d = pushdecl_class_level (d);
2127 if (write_symbols != DWARF_DEBUG)
2129 if (ANON_AGGRNAME_P (name))
2130 DECL_IGNORED_P (d) = 1;
2133 TYPE_CONTEXT (type) = DECL_CONTEXT (d);
2135 if (context == NULL_TREE)
2136 /* Non-nested class. */
2137 set_nested_typename (d, NULL_TREE, name, type);
2138 else if (context && TREE_CODE (context) == FUNCTION_DECL)
2139 /* Function-nested class. */
2140 set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl),
2142 else /* if (context && IS_AGGR_TYPE (context)) */
2143 /* Class-nested class. */
2144 set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl),
2147 DECL_ASSEMBLER_NAME (d)
2148 = get_identifier (build_overload_name (type, 1, 1));
2151 if (b->parm_flag == 2)
2153 TREE_NONLOCAL_FLAG (type) = 1;
2154 if (TYPE_SIZE (current_class_type) == NULL_TREE)
2155 CLASSTYPE_TAGS (current_class_type) = b->tags;
2159 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2160 /* Use the canonical TYPE_DECL for this node. */
2161 TYPE_STUB_DECL (type) = TYPE_NAME (type);
2164 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
2165 will be the tagged type we just added to the current
2166 binding level. This fake NULL-named TYPE_DECL node helps
2167 dwarfout.c to know when it needs to output a
2168 representation of a tagged type, and it also gives us a
2169 convenient place to record the "scope start" address for
2172 tree d = build_decl (TYPE_DECL, NULL_TREE, type);
2173 TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
2177 /* Counter used to create anonymous type names. */
2178 static int anon_cnt = 0;
2180 /* Return an IDENTIFIER which can be used as a name for
2181 anonymous structs and unions. */
2187 sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
2188 return get_identifier (buf);
2191 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
2192 This keeps dbxout from getting confused. */
2196 register struct binding_level *b;
2198 static int last_cnt = 0;
2200 /* Fast out if no new anon names were declared. */
2201 if (last_cnt == anon_cnt)
2204 b = current_binding_level;
2205 while (b->tag_transparent)
2210 /* A NULL purpose means we have already processed all tags
2211 from here to the end of the list. */
2212 if (TREE_PURPOSE (tags) == NULL_TREE)
2214 if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
2215 TREE_PURPOSE (tags) = NULL_TREE;
2216 tags = TREE_CHAIN (tags);
2218 last_cnt = anon_cnt;
2221 /* Subroutine of duplicate_decls: return truthvalue of whether
2222 or not types of these decls match.
2224 For C++, we must compare the parameter list so that `int' can match
2225 `int&' in a parameter position, but `int&' is not confused with
2228 decls_match (newdecl, olddecl)
2229 tree newdecl, olddecl;
2233 if (TREE_CODE (newdecl) == FUNCTION_DECL
2234 && TREE_CODE (olddecl) == FUNCTION_DECL)
2236 tree f1 = TREE_TYPE (newdecl);
2237 tree f2 = TREE_TYPE (olddecl);
2238 tree p1 = TYPE_ARG_TYPES (f1);
2239 tree p2 = TYPE_ARG_TYPES (f2);
2241 /* When we parse a static member function definition,
2242 we put together a FUNCTION_DECL which thinks its type
2243 is METHOD_TYPE. Change that to FUNCTION_TYPE, and
2245 if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
2246 revert_static_member_fn (&newdecl, &f1, &p1);
2247 else if (TREE_CODE (f2) == METHOD_TYPE
2248 && DECL_STATIC_FUNCTION_P (newdecl))
2249 revert_static_member_fn (&olddecl, &f2, &p2);
2251 /* Here we must take care of the case where new default
2252 parameters are specified. Also, warn if an old
2253 declaration becomes ambiguous because default
2254 parameters may cause the two to be ambiguous. */
2255 if (TREE_CODE (f1) != TREE_CODE (f2))
2257 if (TREE_CODE (f1) == OFFSET_TYPE)
2258 cp_compiler_error ("`%D' redeclared as member function", newdecl);
2260 cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
2264 if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1))
2266 if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c
2269 types_match = self_promoting_args_p (p1);
2270 if (p1 == void_list_node)
2271 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
2273 else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c
2274 && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE)
2276 types_match = self_promoting_args_p (p2);
2277 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
2280 types_match = compparms (p1, p2, 3);
2285 else if (TREE_CODE (newdecl) == TEMPLATE_DECL
2286 && TREE_CODE (olddecl) == TEMPLATE_DECL)
2288 tree newargs = DECL_TEMPLATE_PARMS (newdecl);
2289 tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
2290 int i, len = TREE_VEC_LENGTH (newargs);
2292 if (TREE_VEC_LENGTH (oldargs) != len)
2295 for (i = 0; i < len; i++)
2297 tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i));
2298 tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i));
2299 if (TREE_CODE (newarg) != TREE_CODE (oldarg))
2301 else if (TREE_CODE (newarg) == TYPE_DECL)
2303 else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
2307 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
2310 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
2311 DECL_TEMPLATE_RESULT (newdecl));
2315 if (TREE_TYPE (newdecl) == error_mark_node)
2316 types_match = TREE_TYPE (olddecl) == error_mark_node;
2317 else if (TREE_TYPE (olddecl) == NULL_TREE)
2318 types_match = TREE_TYPE (newdecl) == NULL_TREE;
2319 else if (TREE_TYPE (newdecl) == NULL_TREE)
2321 /* Qualifiers must match, and they may be present on either, the type
2323 else if ((TREE_READONLY (newdecl)
2324 || TYPE_READONLY (TREE_TYPE (newdecl)))
2325 == (TREE_READONLY (olddecl)
2326 || TYPE_READONLY (TREE_TYPE (olddecl)))
2327 && (TREE_THIS_VOLATILE (newdecl)
2328 || TYPE_VOLATILE (TREE_TYPE (newdecl)))
2329 == (TREE_THIS_VOLATILE (olddecl)
2330 || TYPE_VOLATILE (TREE_TYPE (olddecl))))
2331 types_match = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (newdecl)),
2332 TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)), 1);
2340 /* If NEWDECL is `static' and an `extern' was seen previously,
2341 warn about it. (OLDDECL may be NULL_TREE; NAME contains
2342 information about previous usage as an `extern'.)
2344 Note that this does not apply to the C++ case of declaring
2345 a variable `extern const' and then later `const'.
2347 Don't complain if -traditional, since traditional compilers
2350 Don't complain about built-in functions, since they are beyond
2351 the user's control. */
2354 warn_extern_redeclared_static (newdecl, olddecl)
2355 tree newdecl, olddecl;
2359 static char *explicit_extern_static_warning
2360 = "`%D' was declared `extern' and later `static'";
2361 static char *implicit_extern_static_warning
2362 = "`%D' was declared implicitly `extern' and later `static'";
2364 if (flag_traditional
2365 || TREE_CODE (newdecl) == TYPE_DECL)
2368 name = DECL_ASSEMBLER_NAME (newdecl);
2369 if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl))
2371 /* It's okay to redeclare an ANSI built-in function as static,
2372 or to declare a non-ANSI built-in function as anything. */
2373 if (! (TREE_CODE (newdecl) == FUNCTION_DECL
2374 && olddecl != NULL_TREE
2375 && TREE_CODE (olddecl) == FUNCTION_DECL
2376 && (DECL_BUILT_IN (olddecl)
2377 || DECL_BUILT_IN_NONANSI (olddecl))))
2379 cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
2380 ? implicit_extern_static_warning
2381 : explicit_extern_static_warning, newdecl);
2382 if (olddecl != NULL_TREE)
2383 cp_pedwarn_at ("previous declaration of `%D'", olddecl);
2388 /* Handle when a new declaration NEWDECL has the same name as an old
2389 one OLDDECL in the same binding contour. Prints an error message
2392 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2393 Otherwise, return 0. */
2396 duplicate_decls (newdecl, olddecl)
2397 register tree newdecl, olddecl;
2399 extern struct obstack permanent_obstack;
2400 unsigned olddecl_uid = DECL_UID (olddecl);
2401 int olddecl_friend = 0, types_match = 0;
2402 int new_defines_function;
2404 if (newdecl == olddecl)
2407 if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd')
2408 DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl);
2410 types_match = decls_match (newdecl, olddecl);
2412 if (TREE_CODE (olddecl) != TREE_LIST)
2413 olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
2415 /* If either the type of the new decl or the type of the old decl is an
2416 error_mark_node, then that implies that we have already issued an
2417 error (earlier) for some bogus type specification, and in that case,
2418 it is rather pointless to harass the user with yet more error message
2419 about the same declaration, so well just pretent the types match here. */
2420 if ((TREE_TYPE (newdecl)
2421 && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
2422 || (TREE_TYPE (olddecl)
2423 && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
2426 if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
2427 && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
2428 /* If -traditional, avoid error for redeclaring fcn
2429 after implicit decl. */
2431 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2432 && DECL_ARTIFICIAL (olddecl)
2433 && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
2435 /* If you declare a built-in or predefined function name as static,
2436 the old definition is overridden, but optionally warn this was a
2437 bad choice of name. Ditto for overloads. */
2438 if (! DECL_PUBLIC (newdecl)
2439 || (TREE_CODE (newdecl) == FUNCTION_DECL
2440 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
2443 cp_warning ("shadowing %s function `%#D'",
2444 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
2446 /* Discard the old built-in function. */
2449 else if (! types_match)
2451 if (TREE_CODE (newdecl) != FUNCTION_DECL)
2453 /* If the built-in is not ansi, then programs can override
2454 it even globally without an error. */
2455 if (! DECL_BUILT_IN (olddecl))
2456 cp_warning ("library function `%#D' redeclared as non-function `%#D'",
2460 cp_error ("declaration of `%#D'", newdecl);
2461 cp_error ("conflicts with built-in declaration `%#D'",
2467 cp_warning ("declaration of `%#D'", newdecl);
2468 cp_warning ("conflicts with built-in declaration `%#D'",
2472 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2474 if ((TREE_CODE (newdecl) == FUNCTION_DECL
2475 && DECL_FUNCTION_TEMPLATE_P (olddecl))
2476 || (TREE_CODE (olddecl) == FUNCTION_DECL
2477 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
2480 cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
2481 if (TREE_CODE (olddecl) == TREE_LIST)
2482 olddecl = TREE_VALUE (olddecl);
2483 cp_error_at ("previous declaration of `%#D'", olddecl);
2485 /* New decl is completely inconsistent with the old one =>
2486 tell caller to replace the old one. */
2490 else if (!types_match)
2492 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2494 /* The name of a class template may not be declared to refer to
2495 any other template, class, function, object, namespace, value,
2496 or type in the same scope. */
2497 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
2498 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
2500 cp_error ("declaration of template `%#D'", newdecl);
2501 cp_error_at ("conflicts with previous declaration `%#D'",
2504 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
2505 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
2506 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
2507 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))), 3))
2509 cp_error ("new declaration `%#D'", newdecl);
2510 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
2514 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2516 if (DECL_LANGUAGE (newdecl) == lang_c
2517 && DECL_LANGUAGE (olddecl) == lang_c)
2519 cp_error ("declaration of C function `%#D' conflicts with",
2521 cp_error_at ("previous declaration `%#D' here", olddecl);
2523 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2524 TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3))
2526 cp_error ("new declaration `%#D'", newdecl);
2527 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
2533 /* Already complained about this, so don't do so again. */
2534 else if (current_class_type == NULL_TREE
2535 || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
2537 cp_error ("conflicting types for `%#D'", newdecl);
2538 cp_error_at ("previous declaration as `%#D'", olddecl);
2543 char *errmsg = redeclaration_error_message (newdecl, olddecl);
2546 cp_error (errmsg, newdecl);
2547 if (DECL_NAME (olddecl) != NULL_TREE)
2548 cp_error_at ((DECL_INITIAL (olddecl)
2549 && current_binding_level == global_binding_level)
2550 ? "`%#D' previously defined here"
2551 : "`%#D' previously declared here", olddecl);
2553 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2554 && DECL_INITIAL (olddecl) != NULL_TREE
2555 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2556 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
2558 /* Prototype decl follows defn w/o prototype. */
2559 cp_warning_at ("prototype for `%#D'", newdecl);
2560 cp_warning_at ("follows non-prototype definition here", olddecl);
2562 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2563 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2565 /* extern "C" int foo ();
2566 int foo () { bar (); }
2568 if (current_lang_stack == current_lang_base)
2569 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2572 cp_error_at ("previous declaration of `%#D' with %L linkage",
2573 olddecl, DECL_LANGUAGE (olddecl));
2574 cp_error ("conflicts with new declaration with %L linkage",
2575 DECL_LANGUAGE (newdecl));
2579 if (TREE_CODE (olddecl) == FUNCTION_DECL
2580 && ! DECL_USE_TEMPLATE (olddecl))
2582 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2583 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
2586 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
2587 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
2589 for (; t1 && t1 != void_list_node;
2590 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
2591 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
2593 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
2598 cp_pedwarn ("default argument given for parameter %d of `%#D'",
2600 cp_pedwarn_at ("after previous specification in `%#D'",
2606 cp_error ("default argument given for parameter %d of `%#D'",
2608 cp_error_at ("conflicts with previous specification in `%#D'",
2613 if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl))
2615 #if 0 /* I think this will be correct, but it's really annoying. We should
2616 fix the compiler to find vtables by indirection so it isn't
2617 necessary. (jason 8/25/95) */
2618 if (DECL_VINDEX (olddecl) && ! DECL_ABSTRACT_VIRTUAL_P (olddecl))
2620 cp_pedwarn ("virtual function `%#D' redeclared inline",
2622 cp_pedwarn_at ("previous non-inline declaration here",
2627 if (TREE_ADDRESSABLE (olddecl))
2629 cp_pedwarn ("`%#D' was used before it was declared inline",
2631 cp_pedwarn_at ("previous non-inline declaration here",
2636 /* These bits are logically part of the type for non-functions. */
2637 else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
2638 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))
2640 cp_pedwarn ("type qualifiers for `%#D'", newdecl);
2641 cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl);
2645 /* If new decl is `static' and an `extern' was seen previously,
2647 warn_extern_redeclared_static (newdecl, olddecl);
2649 /* We have committed to returning 1 at this point. */
2650 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2652 /* Now that functions must hold information normally held
2653 by field decls, there is extra work to do so that
2654 declaration information does not get destroyed during
2656 if (DECL_VINDEX (olddecl))
2657 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2658 if (DECL_CONTEXT (olddecl))
2659 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2660 if (DECL_CLASS_CONTEXT (olddecl))
2661 DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
2662 if (DECL_CHAIN (newdecl) == NULL_TREE)
2663 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2664 if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
2665 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2666 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
2667 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2668 DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl);
2671 /* Deal with C++: must preserve virtual function table size. */
2672 if (TREE_CODE (olddecl) == TYPE_DECL)
2674 register tree newtype = TREE_TYPE (newdecl);
2675 register tree oldtype = TREE_TYPE (olddecl);
2677 DECL_NESTED_TYPENAME (newdecl) = DECL_NESTED_TYPENAME (olddecl);
2679 if (newtype != error_mark_node && oldtype != error_mark_node
2680 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2682 CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
2683 CLASSTYPE_FRIEND_CLASSES (newtype)
2684 = CLASSTYPE_FRIEND_CLASSES (oldtype);
2688 /* Special handling ensues if new decl is a function definition. */
2689 new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
2690 && DECL_INITIAL (newdecl) != NULL_TREE);
2692 /* Optionally warn about more than one declaration for the same name,
2693 but don't warn about a function declaration followed by a definition. */
2694 if (warn_redundant_decls
2695 && ! DECL_ARTIFICIAL (olddecl)
2696 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2697 /* Don't warn about extern decl followed by (tentative) definition. */
2698 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
2700 cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
2701 cp_warning_at ("previous declaration of `%D'", olddecl);
2704 /* Copy all the DECL_... slots specified in the new decl
2705 except for any that we copy here from the old type. */
2707 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2709 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2710 DECL_TEMPLATE_RESULT (olddecl) = DECL_TEMPLATE_RESULT (newdecl);
2711 DECL_TEMPLATE_PARMS (olddecl) = DECL_TEMPLATE_PARMS (newdecl);
2717 /* Automatically handles default parameters. */
2718 tree oldtype = TREE_TYPE (olddecl);
2721 /* Make sure we put the new type in the same obstack as the old one. */
2723 push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
2726 push_obstacks_nochange ();
2727 end_temporary_allocation ();
2730 /* Merge the data types specified in the two decls. */
2731 newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2733 if (TREE_CODE (newdecl) == VAR_DECL)
2734 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2735 /* Do this after calling `common_type' so that default
2736 parameters don't confuse us. */
2737 else if (TREE_CODE (newdecl) == FUNCTION_DECL
2738 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2739 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2741 TREE_TYPE (newdecl) = build_exception_variant (newtype,
2742 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2743 TREE_TYPE (olddecl) = build_exception_variant (newtype,
2744 TYPE_RAISES_EXCEPTIONS (oldtype));
2746 if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
2748 cp_error ("declaration of `%D' throws different exceptions...",
2750 cp_error_at ("...from previous declaration here", olddecl);
2753 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2755 /* Lay the type out, unless already done. */
2756 if (oldtype != TREE_TYPE (newdecl)
2757 && TREE_TYPE (newdecl) != error_mark_node
2758 && !(current_template_parms && uses_template_parms (newdecl)))
2759 layout_type (TREE_TYPE (newdecl));
2761 if ((TREE_CODE (newdecl) == VAR_DECL
2762 || TREE_CODE (newdecl) == PARM_DECL
2763 || TREE_CODE (newdecl) == RESULT_DECL
2764 || TREE_CODE (newdecl) == FIELD_DECL
2765 || TREE_CODE (newdecl) == TYPE_DECL)
2766 && !(current_template_parms && uses_template_parms (newdecl)))
2767 layout_decl (newdecl, 0);
2769 /* Merge the type qualifiers. */
2770 if (TREE_READONLY (newdecl))
2771 TREE_READONLY (olddecl) = 1;
2772 if (TREE_THIS_VOLATILE (newdecl))
2773 TREE_THIS_VOLATILE (olddecl) = 1;
2775 /* Merge the initialization information. */
2776 if (DECL_INITIAL (newdecl) == NULL_TREE
2777 && DECL_INITIAL (olddecl) != NULL_TREE)
2779 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2780 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
2781 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
2784 /* Merge the section attribute.
2785 We want to issue an error if the sections conflict but that must be
2786 done later in decl_attributes since we are called before attributes
2788 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
2789 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
2791 /* Keep the old rtl since we can safely use it, unless it's the
2792 call to abort() used for abstract virtuals. */
2793 if ((DECL_LANG_SPECIFIC (olddecl)
2794 && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
2795 || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
2796 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2800 /* If cannot merge, then use the new type and qualifiers,
2801 and don't preserve the old rtl. */
2804 /* Clean out any memory we had of the old declaration. */
2805 tree oldstatic = value_member (olddecl, static_aggregates);
2807 TREE_VALUE (oldstatic) = error_mark_node;
2809 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2810 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2811 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2812 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2815 /* Merge the storage class information. */
2816 DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
2817 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2818 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
2819 if (! DECL_EXTERNAL (olddecl))
2820 DECL_EXTERNAL (newdecl) = 0;
2822 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2823 DECL_C_STATIC (newdecl) |= DECL_C_STATIC (olddecl);
2825 if (DECL_LANG_SPECIFIC (newdecl))
2827 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
2828 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
2831 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2833 DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl);
2835 /* If either decl says `inline', this fn is inline, unless its
2836 definition was passed already. */
2837 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
2838 DECL_INLINE (olddecl) = 1;
2839 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2843 DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl);
2844 DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl);
2845 DECL_RTL (olddecl) = DECL_RTL (newdecl);
2847 if (! types_match || new_defines_function)
2849 /* These need to be copied so that the names are available. */
2850 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2851 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2853 if (new_defines_function)
2854 /* If defining a function declared with other language
2855 linkage, use the previously declared language linkage. */
2856 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2859 /* If redeclaring a builtin function, and not a definition,
2860 it stays built in. */
2861 if (DECL_BUILT_IN (olddecl))
2863 DECL_BUILT_IN (newdecl) = 1;
2864 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2865 /* If we're keeping the built-in definition, keep the rtl,
2866 regardless of declaration matches. */
2867 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2870 DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2872 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2873 if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
2874 /* Previously saved insns go together with
2875 the function's previous definition. */
2876 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2877 /* Don't clear out the arguments if we're redefining a function. */
2878 if (DECL_ARGUMENTS (olddecl))
2879 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2881 if (DECL_LANG_SPECIFIC (olddecl))
2882 DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl);
2885 if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2887 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
2890 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2892 DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl);
2893 DECL_TEMPLATE_INSTANTIATIONS (newdecl)
2894 = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
2895 if (DECL_CHAIN (newdecl) == NULL_TREE)
2896 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2899 /* Now preserve various other info from the definition. */
2900 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2901 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2902 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2903 DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl);
2905 /* Don't really know how much of the language-specific
2906 values we should copy from old to new. */
2907 if (DECL_LANG_SPECIFIC (olddecl))
2909 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2910 DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
2911 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
2912 if (DECL_TEMPLATE_INFO (newdecl) == NULL_TREE)
2914 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
2915 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
2919 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2922 struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
2923 struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
2925 function_size = sizeof (struct tree_decl);
2927 bcopy ((char *) newdecl + sizeof (struct tree_common),
2928 (char *) olddecl + sizeof (struct tree_common),
2929 function_size - sizeof (struct tree_common));
2931 /* Can we safely free the storage used by newdecl? */
2933 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2934 & ~ obstack_alignment_mask (&permanent_obstack))
2936 if ((char *)newdecl + ROUND (function_size)
2937 + ROUND (sizeof (struct lang_decl))
2938 == obstack_next_free (&permanent_obstack))
2940 DECL_MAIN_VARIANT (newdecl) = olddecl;
2941 DECL_LANG_SPECIFIC (olddecl) = ol;
2942 bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
2944 obstack_free (&permanent_obstack, newdecl);
2946 else if (LANG_DECL_PERMANENT (ol))
2948 if (DECL_MAIN_VARIANT (olddecl) == olddecl)
2950 /* Save these lang_decls that would otherwise be lost. */
2951 extern tree free_lang_decl_chain;
2952 tree free_lang_decl = (tree) ol;
2953 TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
2954 free_lang_decl_chain = free_lang_decl;
2964 bcopy ((char *) newdecl + sizeof (struct tree_common),
2965 (char *) olddecl + sizeof (struct tree_common),
2966 sizeof (struct tree_decl) - sizeof (struct tree_common)
2967 + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
2970 DECL_UID (olddecl) = olddecl_uid;
2972 DECL_FRIEND_P (olddecl) = 1;
2977 /* Record a decl-node X as belonging to the current lexical scope.
2978 Check for errors (such as an incompatible declaration for the same
2979 name already seen in the same scope).
2981 Returns either X or an old decl for the same name.
2982 If an old decl is returned, it may have been smashed
2983 to agree with what X says. */
2990 register tree name = DECL_ASSEMBLER_NAME (x);
2991 register struct binding_level *b = current_binding_level;
2993 if (x != current_function_decl
2994 /* Don't change DECL_CONTEXT of virtual methods. */
2995 && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x))
2996 && ! DECL_CONTEXT (x))
2997 DECL_CONTEXT (x) = current_function_decl;
2998 /* A local declaration for a function doesn't constitute nesting. */
2999 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
3000 DECL_CONTEXT (x) = 0;
3002 /* Type are looked up using the DECL_NAME, as that is what the rest of the
3003 compiler wants to use. */
3004 if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL
3005 || TREE_CODE (x) == NAMESPACE_DECL)
3006 name = DECL_NAME (x);
3011 /* Not needed...see below. */
3016 t = lookup_name_current_level (name);
3017 if (t == error_mark_node)
3019 /* error_mark_node is 0 for a while during initialization! */
3021 cp_error_at ("`%#D' used prior to declaration", x);
3024 else if (t != NULL_TREE)
3027 /* This is turned off until I have time to do it right (bpk). */
3028 /* With the code below that uses it... */
3029 file = DECL_SOURCE_FILE (t);
3030 line = DECL_SOURCE_LINE (t);
3032 if (TREE_CODE (t) == PARM_DECL)
3034 if (DECL_CONTEXT (t) == NULL_TREE)
3035 fatal ("parse errors have confused me too much");
3037 /* Check for duplicate params. */
3038 if (duplicate_decls (x, t))
3041 else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c)
3042 || DECL_FUNCTION_TEMPLATE_P (x))
3043 && is_overloaded_fn (t))
3044 /* don't do anything just yet */;
3045 else if (t == wchar_decl_node)
3047 if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
3048 cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x));
3050 /* Throw away the redeclaration. */
3053 else if (TREE_CODE (t) != TREE_CODE (x))
3055 if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
3056 && TREE_CODE (x) != TYPE_DECL
3057 && ! (TREE_CODE (x) == TEMPLATE_DECL
3058 && TREE_CODE (DECL_TEMPLATE_RESULT (x)) == TYPE_DECL))
3059 || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
3060 && TREE_CODE (t) != TYPE_DECL
3061 && ! (TREE_CODE (t) == TEMPLATE_DECL
3062 && (TREE_CODE (DECL_TEMPLATE_RESULT (t))
3065 /* We do nothing special here, because C++ does such nasty
3066 things with TYPE_DECLs. Instead, just let the TYPE_DECL
3067 get shadowed, and know that if we need to find a TYPE_DECL
3068 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
3069 slot of the identifier. */
3072 else if (duplicate_decls (x, t))
3075 else if (duplicate_decls (x, t))
3078 /* This is turned off until I have time to do it right (bpk). */
3080 /* Also warn if they did a prototype with `static' on it, but
3081 then later left the `static' off. */
3082 if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
3084 if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
3089 cp_warning ("`static' missing from declaration of `%D'",
3091 warning_with_file_and_line (file, line,
3092 "previous declaration of `%s'",
3093 decl_as_string (t, 0));
3096 /* Now fix things so it'll do what they expect. */
3097 if (current_function_decl)
3098 TREE_PUBLIC (current_function_decl) = 0;
3100 /* Due to interference in memory reclamation (X may be
3101 obstack-deallocated at this point), we must guard against
3102 one really special case. [jason: This should be handled
3103 by start_function] */
3104 if (current_function_decl == x)
3105 current_function_decl = t;
3107 if (TREE_CODE (t) == TYPE_DECL)
3108 SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
3109 else if (TREE_CODE (t) == FUNCTION_DECL)
3110 check_default_args (t);
3116 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
3118 t = push_overloaded_decl (x, 1);
3119 if (t != x || DECL_LANGUAGE (x) == lang_c)
3122 else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_CONTEXT (x) == NULL_TREE)
3123 return push_overloaded_decl (x, 0);
3125 /* If declaring a type as a typedef, and the type has no known
3126 typedef name, install this TYPE_DECL as its typedef name. */
3127 if (TREE_CODE (x) == TYPE_DECL)
3129 tree type = TREE_TYPE (x);
3130 tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
3132 if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
3134 /* If these are different names, and we're at the global
3135 binding level, make two equivalent definitions. */
3137 if (global_bindings_p ())
3138 TYPE_NAME (type) = x;
3142 tree tname = DECL_NAME (name);
3144 /* This is a disgusting kludge for dealing with UPTs. */
3145 if (global_bindings_p () && ANON_AGGRNAME_P (tname))
3147 /* do gratuitous C++ typedefing, and make sure that
3148 we access this type either through TREE_TYPE field
3149 or via the tags list. */
3150 TYPE_NAME (TREE_TYPE (x)) = x;
3151 pushtag (tname, TREE_TYPE (x), 0);
3154 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
3156 /* Don't set nested_typename on template type parms, for instance.
3157 Any artificial decls that need DECL_NESTED_TYPENAME will have it
3159 if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x))
3160 set_nested_typename (x, current_class_name, DECL_NAME (x), type);
3162 if (type != error_mark_node
3164 && TYPE_IDENTIFIER (type))
3165 set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
3168 /* Multiple external decls of the same identifier ought to match.
3170 We get warnings about inline functions where they are defined.
3171 We get warnings about other functions from push_overloaded_decl.
3173 Avoid duplicate warnings where they are used. */
3174 if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
3178 if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
3179 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
3180 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
3181 decl = IDENTIFIER_GLOBAL_VALUE (name);
3186 /* If different sort of thing, we already gave an error. */
3187 && TREE_CODE (decl) == TREE_CODE (x)
3188 && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1))
3190 cp_pedwarn ("type mismatch with previous external decl", x);
3191 cp_pedwarn_at ("previous external decl of `%#D'", decl);
3195 /* In PCC-compatibility mode, extern decls of vars with no current decl
3196 take effect at top level no matter where they are. */
3197 if (flag_traditional && DECL_EXTERNAL (x)
3198 && lookup_name (name, 0) == NULL_TREE)
3199 b = global_binding_level;
3201 /* This name is new in its binding level.
3202 Install the new declaration and return it. */
3203 if (b == global_binding_level)
3205 /* Install a global value. */
3207 /* If the first global decl has external linkage,
3208 warn if we later see static one. */
3209 if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x))
3210 TREE_PUBLIC (name) = 1;
3212 /* Don't install an artificial TYPE_DECL if we already have
3213 another _DECL with that name. */
3214 if (TREE_CODE (x) != TYPE_DECL
3216 || ! DECL_ARTIFICIAL (x))
3217 IDENTIFIER_GLOBAL_VALUE (name) = x;
3219 /* Don't forget if the function was used via an implicit decl. */
3220 if (IDENTIFIER_IMPLICIT_DECL (name)
3221 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
3224 /* Don't forget if its address was taken in that way. */
3225 if (IDENTIFIER_IMPLICIT_DECL (name)
3226 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
3227 TREE_ADDRESSABLE (x) = 1;
3229 /* Warn about mismatches against previous implicit decl. */
3230 if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
3231 /* If this real decl matches the implicit, don't complain. */
3232 && ! (TREE_CODE (x) == FUNCTION_DECL
3233 && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
3235 ("`%D' was previously implicitly declared to return `int'", x);
3237 /* If new decl is `static' and an `extern' was seen previously,
3239 if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
3240 warn_extern_redeclared_static (x, t);
3244 /* Here to install a non-global value. */
3245 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
3246 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
3248 /* Don't install an artificial TYPE_DECL if we already have
3249 another _DECL with that name. */
3250 if (TREE_CODE (x) != TYPE_DECL
3252 || ! DECL_ARTIFICIAL (x))
3254 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
3255 IDENTIFIER_LOCAL_VALUE (name) = x;
3258 /* If this is a TYPE_DECL, push it into the type value slot. */
3259 if (TREE_CODE (x) == TYPE_DECL)
3260 set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
3262 /* Clear out any TYPE_DECL shadowed by a namespace so that
3263 we won't think this is a type. The C struct hack doesn't
3264 go through namespaces. */
3265 if (TREE_CODE (x) == NAMESPACE_DECL)
3266 set_identifier_type_value_with_scope (name, NULL_TREE, b);
3268 /* If this is an extern function declaration, see if we
3269 have a global definition or declaration for the function. */
3270 if (oldlocal == NULL_TREE
3271 && DECL_EXTERNAL (x)
3272 && oldglobal != NULL_TREE
3273 && TREE_CODE (x) == FUNCTION_DECL
3274 && TREE_CODE (oldglobal) == FUNCTION_DECL)
3276 /* We have one. Their types must agree. */
3277 if (decls_match (x, oldglobal))
3281 cp_warning ("extern declaration of `%#D' doesn't match", x);
3282 cp_warning_at ("global declaration `%#D'", oldglobal);
3285 /* If we have a local external declaration,
3286 and no file-scope declaration has yet been seen,
3287 then if we later have a file-scope decl it must not be static. */
3288 if (oldlocal == NULL_TREE
3289 && oldglobal == NULL_TREE
3290 && DECL_EXTERNAL (x)
3293 TREE_PUBLIC (name) = 1;
3296 if (DECL_FROM_INLINE (x))
3297 /* Inline decls shadow nothing. */;
3299 /* Warn if shadowing an argument at the top level of the body. */
3300 else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
3301 && TREE_CODE (oldlocal) == PARM_DECL
3302 && TREE_CODE (x) != PARM_DECL)
3304 /* Go to where the parms should be and see if we
3306 struct binding_level *b = current_binding_level->level_chain;
3312 if (b->parm_flag == 1)
3313 cp_error ("declaration of `%#D' shadows a parameter", name);
3315 else if (warn_shadow && oldlocal != NULL_TREE && b->is_for_scope
3316 && !DECL_DEAD_FOR_LOCAL (oldlocal))
3318 warning ("variable `%s' shadows local",
3319 IDENTIFIER_POINTER (name));
3320 cp_warning_at (" this is the shadowed declaration", oldlocal);
3322 /* Maybe warn if shadowing something else. */
3323 else if (warn_shadow && !DECL_EXTERNAL (x)
3324 /* No shadow warnings for internally generated vars. */
3325 && ! DECL_ARTIFICIAL (x)
3326 /* No shadow warnings for vars made for inlining. */
3327 && ! DECL_FROM_INLINE (x))
3329 char *warnstring = NULL;
3331 if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
3332 warnstring = "declaration of `%s' shadows a parameter";
3333 else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
3334 && current_class_decl
3335 && !TREE_STATIC (name))
3336 warnstring = "declaration of `%s' shadows a member of `this'";
3337 else if (oldlocal != NULL_TREE)
3338 warnstring = "declaration of `%s' shadows previous local";
3339 else if (oldglobal != NULL_TREE)
3340 warnstring = "declaration of `%s' shadows global declaration";
3343 warning (warnstring, IDENTIFIER_POINTER (name));
3347 if (TREE_CODE (x) == FUNCTION_DECL)
3348 check_default_args (x);
3350 /* Keep count of variables in this level with incomplete type. */
3351 if (TREE_CODE (x) == VAR_DECL
3352 && TREE_TYPE (x) != error_mark_node
3353 && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
3354 && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
3355 /* RTTI TD entries are created while defining the type_info. */
3356 || (TYPE_LANG_SPECIFIC (TREE_TYPE (x))
3357 && TYPE_BEING_DEFINED (TREE_TYPE (x)))))
3358 b->incomplete = tree_cons (NULL_TREE, x, b->incomplete);
3361 /* Put decls on list in reverse order.
3362 We will reverse them later if necessary. */
3363 TREE_CHAIN (x) = b->names;
3365 if (! (b != global_binding_level || TREE_PERMANENT (x)))
3366 my_friendly_abort (124);
3371 /* Same as pushdecl, but define X in binding-level LEVEL. We rely on the
3372 caller to set DECL_CONTEXT properly. */
3375 pushdecl_with_scope (x, level)
3377 struct binding_level *level;
3379 register struct binding_level *b = current_binding_level;
3380 tree function_decl = current_function_decl;
3382 current_function_decl = NULL_TREE;
3383 current_binding_level = level;
3385 current_binding_level = b;
3386 current_function_decl = function_decl;
3390 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
3393 pushdecl_top_level (x)
3396 register struct binding_level *b = inner_binding_level;
3397 register tree t = pushdecl_with_scope (x, global_binding_level);
3399 /* Now, the type_shadowed stack may screw us. Munge it so it does
3401 if (TREE_CODE (x) == TYPE_DECL)
3403 tree name = DECL_NAME (x);
3405 tree *ptr = (tree *)0;
3406 for (; b != global_binding_level; b = b->level_chain)
3408 tree shadowed = b->type_shadowed;
3409 for (; shadowed; shadowed = TREE_CHAIN (shadowed))
3410 if (TREE_PURPOSE (shadowed) == name)
3412 ptr = &TREE_VALUE (shadowed);
3413 /* Can't break out of the loop here because sometimes
3414 a binding level will have duplicate bindings for
3415 PT names. It's gross, but I haven't time to fix it. */
3418 newval = TREE_TYPE (x);
3419 if (ptr == (tree *)0)
3421 /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3422 up here if this is changed to an assertion. --KR */
3423 SET_IDENTIFIER_TYPE_VALUE (name, newval);
3433 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3436 push_overloaded_decl_top_level (x, forget)
3440 struct binding_level *b = current_binding_level;
3442 current_binding_level = global_binding_level;
3443 push_overloaded_decl (x, forget);
3444 current_binding_level = b;
3447 /* Make the declaration of X appear in CLASS scope. */
3449 pushdecl_class_level (x)
3452 /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3453 scope looks for the pre-mangled name. */
3454 register tree name = DECL_NAME (x);
3458 if (TYPE_BEING_DEFINED (current_class_type))
3460 /* Check for inconsistent use of this name in the class body.
3461 Types, enums, and static vars are checked here; other
3462 members are checked in finish_struct. */
3463 tree icv = IDENTIFIER_CLASS_VALUE (name);
3466 /* Don't complain about inherited names. */
3467 && id_in_current_class (name)
3468 /* Or shadowed tags. */
3469 && !(TREE_CODE (icv) == TYPE_DECL
3470 && DECL_CONTEXT (icv) == current_class_type))
3472 cp_error ("declaration of identifier `%D' as `%#D'", name, x);
3473 cp_error_at ("conflicts with previous use in class as `%#D'",
3478 push_class_level_binding (name, x);
3479 if (TREE_CODE (x) == TYPE_DECL)
3481 set_identifier_type_value (name, TREE_TYPE (x));
3483 /* Don't set nested_typename on template type parms, for instance.
3484 Any artificial decls that need DECL_NESTED_TYPENAME will have it
3486 if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x))
3487 set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
3493 /* This function is used to push the mangled decls for nested types into
3494 the appropriate scope. Previously pushdecl_top_level was used, but that
3495 is incorrect for members of local classes. */
3497 pushdecl_nonclass_level (x)
3500 struct binding_level *b = current_binding_level;
3502 my_friendly_assert (b->parm_flag != 2, 180);
3505 /* Get out of template binding levels */
3506 while (b->pseudo_global)
3510 pushdecl_with_scope (x, b);
3513 /* Make the declaration(s) of X appear in CLASS scope
3514 under the name NAME. */
3516 push_class_level_binding (name, x)
3520 if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
3521 && purpose_member (name, class_binding_level->class_shadowed))
3524 maybe_push_cache_obstack ();
3525 class_binding_level->class_shadowed
3526 = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
3527 class_binding_level->class_shadowed);
3529 IDENTIFIER_CLASS_VALUE (name) = x;
3530 obstack_ptr_grow (&decl_obstack, x);
3533 /* Tell caller how to interpret a TREE_LIST which contains
3534 chains of FUNCTION_DECLS. */
3536 overloaded_globals_p (list)
3539 my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
3541 /* Don't commit caller to seeing them as globals. */
3542 if (TREE_NONLOCAL_FLAG (list))
3544 /* Do commit caller to not seeing them as globals. */
3545 if (TREE_CODE (TREE_VALUE (list)) == TREE_LIST)
3547 /* Do commit caller to seeing them as globals. */
3551 /* DECL is a FUNCTION_DECL which may have other definitions already in
3552 place. We get around this by making the value of the identifier point
3553 to a list of all the things that want to be referenced by that name. It
3554 is then up to the users of that name to decide what to do with that
3557 DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3558 slot. It is dealt with the same way.
3560 The value returned may be a previous declaration if we guessed wrong
3561 about what language DECL should belong to (C or C++). Otherwise,
3562 it's always DECL (and never something that's not a _DECL). */
3564 push_overloaded_decl (decl, forgettable)
3568 tree orig_name = DECL_NAME (decl);
3570 int doing_global = (global_bindings_p () || ! forgettable);
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)))
3579 if (duplicate_decls (decl, old))
3586 old = IDENTIFIER_LOCAL_VALUE (orig_name);
3588 if (! purpose_member (orig_name, current_binding_level->shadowed))
3590 current_binding_level->shadowed
3591 = tree_cons (orig_name, old, current_binding_level->shadowed);
3598 if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
3600 tree t = TREE_TYPE (old);
3601 if (IS_AGGR_TYPE (t) && warn_shadow)
3602 cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
3605 else if (is_overloaded_fn (old))
3609 for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp))
3610 if (decl == tmp || duplicate_decls (decl, tmp))
3615 cp_error_at ("previous non-function declaration `%#D'", old);
3616 cp_error ("conflicts with function declaration `%#D'", decl);
3621 if (old || TREE_CODE (decl) == TEMPLATE_DECL)
3623 if (old && is_overloaded_fn (old))
3624 DECL_CHAIN (decl) = get_first_fn (old);
3626 DECL_CHAIN (decl) = NULL_TREE;
3627 old = tree_cons (orig_name, decl, NULL_TREE);
3628 TREE_TYPE (old) = unknown_type_node;
3631 /* orig_name is not ambiguous. */
3635 IDENTIFIER_GLOBAL_VALUE (orig_name) = old;
3637 IDENTIFIER_LOCAL_VALUE (orig_name) = old;
3642 /* Generate an implicit declaration for identifier FUNCTIONID
3643 as a function of type int (). Print a warning if appropriate. */
3646 implicitly_declare (functionid)
3650 int temp = allocation_temporary_p ();
3652 push_obstacks_nochange ();
3654 /* Save the decl permanently so we can warn if definition follows.
3655 In ANSI C, warn_implicit is usually false, so the saves little space.
3656 But in C++, it's usually true, hence the extra code. */
3657 if (temp && (flag_traditional || !warn_implicit || toplevel_bindings_p ()))
3658 end_temporary_allocation ();
3660 /* We used to reuse an old implicit decl here,
3661 but this loses with inline functions because it can clobber
3662 the saved decl chains. */
3663 decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
3665 DECL_EXTERNAL (decl) = 1;
3666 TREE_PUBLIC (decl) = 1;
3668 /* ANSI standard says implicit declarations are in the innermost block.
3669 So we record the decl in the standard fashion.
3670 If flag_traditional is set, pushdecl does it top-level. */
3672 rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
3675 /* Only one warning per identifier. */
3676 && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
3678 cp_pedwarn ("implicit declaration of function `%#D'", decl);
3681 SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
3688 /* Return zero if the declaration NEWDECL is valid
3689 when the declaration OLDDECL (assumed to be for the same name)
3690 has already been seen.
3691 Otherwise return an error message format string with a %s
3692 where the identifier should go. */
3695 redeclaration_error_message (newdecl, olddecl)
3696 tree newdecl, olddecl;
3698 if (TREE_CODE (newdecl) == TYPE_DECL)
3700 /* Because C++ can put things into name space for free,
3701 constructs like "typedef struct foo { ... } foo"
3702 would look like an erroneous redeclaration. */
3703 if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
3706 return "redefinition of `%#D'";
3708 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3710 /* If this is a pure function, its olddecl will actually be
3711 the original initialization to `0' (which we force to call
3712 abort()). Don't complain about redefinition in this case. */
3713 if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
3716 /* We'll complain about linkage mismatches in
3717 warn_extern_redeclared_static. */
3719 /* defining the same name twice is no good. */
3720 if (DECL_INITIAL (olddecl) != NULL_TREE
3721 && DECL_INITIAL (newdecl) != NULL_TREE)
3723 if (DECL_NAME (olddecl) == NULL_TREE)
3724 return "`%#D' not declared in class";
3726 return "redefinition of `%#D'";
3730 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3732 if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
3733 && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl))
3734 && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)))
3735 || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL
3736 && TYPE_SIZE (TREE_TYPE (newdecl))
3737 && TYPE_SIZE (TREE_TYPE (olddecl))))
3738 return "redefinition of `%#D'";
3741 else if (toplevel_bindings_p ())
3743 /* Objects declared at top level: */
3744 /* If at least one is a reference, it's ok. */
3745 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3747 /* Reject two definitions. */
3748 return "redefinition of `%#D'";
3752 /* Objects declared with block scope: */
3753 /* Reject two definitions, and reject a definition
3754 together with an external reference. */
3755 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3756 return "redeclaration of `%#D'";
3761 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3762 Create one if none exists so far for the current function.
3763 This function is called for both label definitions and label references. */
3769 register tree decl = IDENTIFIER_LABEL_VALUE (id);
3771 if (current_function_decl == NULL_TREE)
3773 error ("label `%s' referenced outside of any function",
3774 IDENTIFIER_POINTER (id));
3778 if ((decl == NULL_TREE
3779 || DECL_SOURCE_LINE (decl) == 0)
3780 && (named_label_uses == NULL_TREE
3781 || TREE_PURPOSE (named_label_uses) != current_binding_level->names
3782 || TREE_VALUE (named_label_uses) != decl))
3785 = tree_cons (current_binding_level->names, decl, named_label_uses);
3786 TREE_TYPE (named_label_uses) = (tree)current_binding_level;
3789 /* Use a label already defined or ref'd with this name. */
3790 if (decl != NULL_TREE)
3792 /* But not if it is inherited and wasn't declared to be inheritable. */
3793 if (DECL_CONTEXT (decl) != current_function_decl
3794 && ! C_DECLARED_LABEL_FLAG (decl))
3795 return shadow_label (id);
3799 decl = build_decl (LABEL_DECL, id, void_type_node);
3801 /* Make sure every label has an rtx. */
3804 /* A label not explicitly declared must be local to where it's ref'd. */
3805 DECL_CONTEXT (decl) = current_function_decl;
3807 DECL_MODE (decl) = VOIDmode;
3809 /* Say where one reference is to the label,
3810 for the sake of the error if it is not defined. */
3811 DECL_SOURCE_LINE (decl) = lineno;
3812 DECL_SOURCE_FILE (decl) = input_filename;
3814 SET_IDENTIFIER_LABEL_VALUE (id, decl);
3816 named_labels = tree_cons (NULL_TREE, decl, named_labels);
3817 TREE_VALUE (named_label_uses) = decl;
3822 /* Make a label named NAME in the current function,
3823 shadowing silently any that may be inherited from containing functions
3824 or containing scopes.
3826 Note that valid use, if the label being shadowed
3827 comes from another scope in the same function,
3828 requires calling declare_nonlocal_label right away. */
3834 register tree decl = IDENTIFIER_LABEL_VALUE (name);
3836 if (decl != NULL_TREE)
3838 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3839 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3840 SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
3843 return lookup_label (name);
3846 /* Define a label, specifying the location in the source file.
3847 Return the LABEL_DECL node for the label, if the definition is valid.
3848 Otherwise return 0. */
3851 define_label (filename, line, name)
3858 if (minimal_parse_mode)
3860 push_obstacks (&permanent_obstack, &permanent_obstack);
3861 decl = build_decl (LABEL_DECL, name, void_type_node);
3863 DECL_SOURCE_LINE (decl) = line;
3864 DECL_SOURCE_FILE (decl) = filename;
3869 decl = lookup_label (name);
3871 /* After labels, make any new cleanups go into their
3872 own new (temporary) binding contour. */
3873 current_binding_level->more_cleanups_ok = 0;
3875 /* If label with this name is known from an outer context, shadow it. */
3876 if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
3878 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3879 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3880 decl = lookup_label (name);
3883 if (name == get_identifier ("wchar_t"))
3884 cp_pedwarn ("label named wchar_t");
3886 if (DECL_INITIAL (decl) != NULL_TREE)
3888 cp_error ("duplicate label `%D'", decl);
3896 /* Mark label as having been defined. */
3897 DECL_INITIAL (decl) = error_mark_node;
3898 /* Say where in the source. */
3899 DECL_SOURCE_FILE (decl) = filename;
3900 DECL_SOURCE_LINE (decl) = line;
3902 for (prev = NULL_TREE, uses = named_label_uses;
3904 prev = uses, uses = TREE_CHAIN (uses))
3905 if (TREE_VALUE (uses) == decl)
3907 struct binding_level *b = current_binding_level;
3910 tree new_decls = b->names;
3911 tree old_decls = ((tree)b == TREE_TYPE (uses)
3912 ? TREE_PURPOSE (uses) : NULL_TREE);
3913 while (new_decls != old_decls)
3915 if (TREE_CODE (new_decls) == VAR_DECL
3916 /* Don't complain about crossing initialization
3917 of internal entities. They can't be accessed,
3918 and they should be cleaned up
3919 by the time we get to the label. */
3920 && ! DECL_ARTIFICIAL (new_decls)
3921 && ((DECL_INITIAL (new_decls) != NULL_TREE
3922 && DECL_INITIAL (new_decls) != error_mark_node)
3923 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
3926 cp_error ("jump to label `%D'", decl);
3928 cp_error_at (" crosses initialization of `%#D'",
3931 new_decls = TREE_CHAIN (new_decls);
3933 if ((tree)b == TREE_TYPE (uses))
3939 TREE_CHAIN (prev) = TREE_CHAIN (uses);
3941 named_label_uses = TREE_CHAIN (uses);
3943 current_function_return_value = NULL_TREE;
3950 struct binding_level *level;
3951 struct cp_switch *next;
3954 static struct cp_switch *switch_stack;
3960 = (struct cp_switch *) oballoc (sizeof (struct cp_switch));
3961 p->level = current_binding_level;
3962 p->next = switch_stack;
3969 switch_stack = switch_stack->next;
3972 /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3973 /* XXX Note decl is never actually used. (bpk) */
3975 define_case_label (decl)
3978 tree cleanup = last_cleanup_this_contour ();
3979 struct binding_level *b = current_binding_level;
3984 static int explained = 0;
3985 cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
3986 warning ("where case label appears here");
3989 warning ("(enclose actions of previous case statements requiring");
3990 warning ("destructors in their own binding contours.)");
3995 for (; b && b != switch_stack->level; b = b->level_chain)
3997 tree new_decls = b->names;
3998 for (; new_decls; new_decls = TREE_CHAIN (new_decls))
4000 if (TREE_CODE (new_decls) == VAR_DECL
4001 /* Don't complain about crossing initialization
4002 of internal entities. They can't be accessed,
4003 and they should be cleaned up
4004 by the time we get to the label. */
4005 && ! DECL_ARTIFICIAL (new_decls)
4006 && ((DECL_INITIAL (new_decls) != NULL_TREE
4007 && DECL_INITIAL (new_decls) != error_mark_node)
4008 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
4011 error ("jump to case label");
4013 cp_error_at (" crosses initialization of `%#D'",
4019 /* After labels, make any new cleanups go into their
4020 own new (temporary) binding contour. */
4022 current_binding_level->more_cleanups_ok = 0;
4023 current_function_return_value = NULL_TREE;
4026 /* Return the list of declarations of the current level.
4027 Note that this list is in reverse order unless/until
4028 you nreverse it; and when you do nreverse it, you must
4029 store the result back using `storedecls' or you will lose. */
4034 return current_binding_level->names;
4037 /* Return the list of type-tags (for structs, etc) of the current level. */
4042 return current_binding_level->tags;
4045 /* Store the list of declarations of the current level.
4046 This is done for the parameter declarations of a function being defined,
4047 after they are modified in the light of any missing parameters. */
4053 current_binding_level->names = decls;
4056 /* Similarly, store the list of tags of the current level. */
4062 current_binding_level->tags = tags;
4065 /* Given NAME, an IDENTIFIER_NODE,
4066 return the structure (or union or enum) definition for that name.
4067 Searches binding levels from BINDING_LEVEL up to the global level.
4068 If THISLEVEL_ONLY is nonzero, searches only the specified context
4069 (but skips any tag-transparent contexts to find one that is
4070 meaningful for tags).
4071 FORM says which kind of type the caller wants;
4072 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
4073 If the wrong kind of type is found, and it's not a template, an error is
4077 lookup_tag (form, name, binding_level, thislevel_only)
4078 enum tree_code form;
4080 struct binding_level *binding_level;
4083 register struct binding_level *level;
4085 for (level = binding_level; level; level = level->level_chain)
4088 if (ANON_AGGRNAME_P (name))
4089 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4091 /* There's no need for error checking here, because
4092 anon names are unique throughout the compilation. */
4093 if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
4094 return TREE_VALUE (tail);
4097 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4099 if (TREE_PURPOSE (tail) == name
4100 || TYPE_NESTED_NAME (TREE_VALUE (tail)) == name)
4102 enum tree_code code = TREE_CODE (TREE_VALUE (tail));
4103 /* Should tighten this up; it'll probably permit
4104 UNION_TYPE and a struct template, for example. */
4106 && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL))
4108 /* Definition isn't the kind we were looking for. */
4109 cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
4113 return TREE_VALUE (tail);
4116 if (thislevel_only && ! level->tag_transparent)
4118 if (level->pseudo_global)
4120 tree t = IDENTIFIER_GLOBAL_VALUE (name);
4121 if (t && TREE_CODE (t) == TEMPLATE_DECL
4122 && TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
4123 return TREE_TYPE (t);
4127 if (current_class_type && level->level_chain == global_binding_level)
4129 /* Try looking in this class's tags before heading into
4130 global binding level. */
4131 tree context = current_class_type;
4134 switch (TREE_CODE_CLASS (TREE_CODE (context)))
4138 these_tags = CLASSTYPE_TAGS (context);
4139 if (ANON_AGGRNAME_P (name))
4142 if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
4144 return TREE_VALUE (tail);
4145 these_tags = TREE_CHAIN (these_tags);
4150 if (TREE_PURPOSE (these_tags) == name)
4152 if (TREE_CODE (TREE_VALUE (these_tags)) != form)
4154 cp_error ("`%#D' redeclared as %C in class scope",
4155 TREE_VALUE (tail), form);
4158 return TREE_VALUE (tail);
4160 these_tags = TREE_CHAIN (these_tags);
4162 /* If this type is not yet complete, then don't
4163 look at its context. */
4164 if (TYPE_SIZE (context) == NULL_TREE)
4166 /* Go to next enclosing type, if any. */
4167 context = DECL_CONTEXT (TYPE_NAME (context));
4170 context = DECL_CONTEXT (context);
4173 my_friendly_abort (10);
4185 set_current_level_tags_transparency (tags_transparent)
4186 int tags_transparent;
4188 current_binding_level->tag_transparent = tags_transparent;
4191 /* Given a type, find the tag that was defined for it and return the tag name.
4192 Otherwise return 0. However, the value can never be 0
4193 in the cases in which this is used.
4195 C++: If NAME is non-zero, this is the new name to install. This is
4196 done when replacing anonymous tags with real tag names. */
4199 lookup_tag_reverse (type, name)
4203 register struct binding_level *level;
4205 for (level = current_binding_level; level; level = level->level_chain)
4208 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4210 if (TREE_VALUE (tail) == type)
4213 TREE_PURPOSE (tail) = name;
4214 return TREE_PURPOSE (tail);
4221 /* Given type TYPE which was not declared in C++ language context,
4222 attempt to find a name by which it is referred. */
4224 typedecl_for_tag (tag)
4227 struct binding_level *b = current_binding_level;
4229 if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
4230 return TYPE_NAME (tag);
4234 tree decls = b->names;
4237 if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
4239 decls = TREE_CHAIN (decls);
4248 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
4249 Return the type value, or NULL_TREE if not found. */
4251 lookup_nested_type (type, context)
4255 if (context == NULL_TREE)
4259 switch (TREE_CODE (context))
4263 tree ctype = TREE_TYPE (context);
4264 tree match = value_member (type, CLASSTYPE_TAGS (ctype));
4266 return TREE_VALUE (match);
4267 context = DECL_CONTEXT (context);
4269 /* When we have a nested class whose member functions have
4270 local types (e.g., a set of enums), we'll arrive here
4271 with the DECL_CONTEXT as the actual RECORD_TYPE node for
4272 the enclosing class. Instead, we want to make sure we
4273 come back in here with the TYPE_DECL, not the RECORD_TYPE. */
4274 if (context && TREE_CODE (context) == RECORD_TYPE)
4275 context = TREE_CHAIN (context);
4279 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
4280 return lookup_name (TYPE_IDENTIFIER (type), 1);
4283 my_friendly_abort (12);
4289 /* Look up NAME in the NAMESPACE. */
4291 lookup_namespace_name (namespace, name)
4292 tree namespace, name;
4294 struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace);
4297 for (x = NULL_TREE; b && !x; b = b->level_chain)
4299 for (x = b->names; x; x = TREE_CHAIN (x))
4300 if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name)
4302 /* Must find directly in the namespace. */
4309 make_typename_type (context, name)
4314 if (! current_template_parms
4315 || ! uses_template_parms (context))
4317 t = lookup_field (context, name, 0, 1);
4320 cp_error_at ("no type matching `%#T' in `%#T'", name, context);
4321 return error_mark_node;
4323 return TREE_TYPE (t);
4326 if (current_template_parms)
4327 push_obstacks (&permanent_obstack, &permanent_obstack);
4328 t = make_lang_type (TYPENAME_TYPE);
4329 d = build_decl (TYPE_DECL, name, t);
4330 i = make_anon_name ();
4331 if (current_template_parms)
4334 TYPE_CONTEXT (t) = context;
4335 TYPE_MAIN_DECL (TREE_TYPE (d)) = d;
4336 DECL_CONTEXT (d) = context;
4337 DECL_NESTED_TYPENAME (d) = i;
4338 IDENTIFIER_LOCAL_VALUE (i) = d;
4344 /* Look up NAME in the current binding level and its superiors in the
4345 namespace of variables, functions and typedefs. Return a ..._DECL
4346 node of some kind representing its definition if there is only one
4347 such declaration, or return a TREE_LIST with all the overloaded
4348 definitions if there are many, or return 0 if it is undefined.
4350 If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
4351 If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
4352 Otherwise we prefer non-TYPE_DECLs. */
4355 lookup_name_real (name, prefer_type, nonclass)
4357 int prefer_type, nonclass;
4361 tree from_obj = NULL_TREE;
4363 if (prefer_type == -2)
4365 extern int looking_for_typename;
4369 prefer_type = looking_for_typename;
4373 else if (got_object != error_mark_node)
4378 if (type == error_mark_node)
4379 return error_mark_node;
4381 type = complete_type (type);
4383 if (type == void_type_node)
4384 val = IDENTIFIER_GLOBAL_VALUE (name);
4385 else if (TREE_CODE (type) == NAMESPACE_DECL)
4387 val = lookup_namespace_name (type, name);
4389 else if (! IS_AGGR_TYPE (type)
4390 || TREE_CODE (type) == TEMPLATE_TYPE_PARM)
4391 /* Someone else will give an error about this if needed. */
4393 else if (TYPE_BEING_DEFINED (type))
4395 val = IDENTIFIER_CLASS_VALUE (name);
4396 if (val && DECL_CONTEXT (val) != type)
4398 struct binding_level *b = class_binding_level;
4399 for (val = NULL_TREE; b; b = b->level_chain)
4401 tree t = purpose_member (name, b->class_shadowed);
4402 if (t && TREE_VALUE (t)
4403 && DECL_CONTEXT (TREE_VALUE (t)) == type)
4405 val = TREE_VALUE (t);
4410 if (val == NULL_TREE)
4411 val = lookup_field (type, name, 0, 1);
4413 else if (type == current_class_type)
4414 val = IDENTIFIER_CLASS_VALUE (name);
4416 val = lookup_field (type, name, 0, prefer_type);
4424 /* This special lookup only applies to types. */
4425 else if (got_object && val && TREE_CODE (val) == TYPE_DECL)
4429 if (current_binding_level != global_binding_level
4430 && IDENTIFIER_LOCAL_VALUE (name))
4431 val = IDENTIFIER_LOCAL_VALUE (name);
4432 /* In C++ class fields are between local and global scope,
4433 just before the global scope. */
4434 else if (current_class_type && ! nonclass)
4436 val = IDENTIFIER_CLASS_VALUE (name);
4437 if (val == NULL_TREE && TYPE_BEING_DEFINED (current_class_type))
4438 /* Try to find values from base classes if we are presently
4439 defining a type. We are presently only interested in
4441 val = lookup_field (current_class_type, name, 0, 1);
4443 /* yylex() calls this with -2, since we should never start digging for
4444 the nested name at the point where we haven't even, for example,
4445 created the COMPONENT_REF or anything like that. */
4446 if (val == NULL_TREE)
4447 val = lookup_nested_field (name, ! yylex);
4449 if (val == NULL_TREE)
4450 val = IDENTIFIER_GLOBAL_VALUE (name);
4453 val = IDENTIFIER_GLOBAL_VALUE (name);
4458 if (from_obj && from_obj != val)
4460 cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%D')",
4461 name, got_object, from_obj);
4462 cp_pedwarn (" does not match lookup in the current scope (`%D')",
4466 if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template)
4467 || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0)
4469 else if (IDENTIFIER_HAS_TYPE_VALUE (name))
4470 val = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
4471 else if (TREE_TYPE (val) == error_mark_node)
4472 val = error_mark_node;
4481 lookup_name_nonclass (name)
4484 return lookup_name_real (name, 0, 1);
4488 lookup_name (name, prefer_type)
4492 return lookup_name_real (name, prefer_type, 0);
4495 /* Similar to `lookup_name' but look only at current binding level. */
4498 lookup_name_current_level (name)
4501 register tree t = NULL_TREE;
4503 if (current_binding_level == global_binding_level)
4505 t = IDENTIFIER_GLOBAL_VALUE (name);
4507 /* extern "C" function() */
4508 if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
4511 else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
4513 struct binding_level *b = current_binding_level;
4516 for (t = b->names; t; t = TREE_CHAIN (t))
4517 if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name)
4531 /* Arrange for the user to get a source line number, even when the
4532 compiler is going down in flames, so that she at least has a
4533 chance of working around problems in the compiler. We used to
4534 call error(), but that let the segmentation fault continue
4535 through; now, it's much more passive by asking them to send the
4536 maintainers mail about the problem. */
4542 signal (SIGSEGV, SIG_DFL);
4544 signal (SIGIOT, SIG_DFL);
4547 signal (SIGILL, SIG_DFL);
4550 signal (SIGABRT, SIG_DFL);
4553 signal (SIGBUS, SIG_DFL);
4555 my_friendly_abort (0);
4558 /* Array for holding types considered "built-in". These types
4559 are output in the module in which `main' is defined. */
4560 static tree *builtin_type_tdescs_arr;
4561 static int builtin_type_tdescs_len, builtin_type_tdescs_max;
4563 /* Push the declarations of builtin types into the namespace.
4564 RID_INDEX, if < RID_MAX is the index of the builtin type
4565 in the array RID_POINTERS. NAME is the name used when looking
4566 up the builtin type. TYPE is the _TYPE node for the builtin type. */
4569 record_builtin_type (rid_index, name, type)
4574 tree rname = NULL_TREE, tname = NULL_TREE;
4577 if ((int) rid_index < (int) RID_MAX)
4578 rname = ridpointers[(int) rid_index];
4580 tname = get_identifier (name);
4582 TYPE_BUILT_IN (type) = 1;
4586 tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
4587 set_identifier_type_value (tname, NULL_TREE);
4588 if ((int) rid_index < (int) RID_MAX)
4589 IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
4591 if (rname != NULL_TREE)
4593 if (tname != NULL_TREE)
4595 set_identifier_type_value (rname, NULL_TREE);
4596 IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
4600 tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
4601 set_identifier_type_value (rname, NULL_TREE);
4607 if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
4609 builtin_type_tdescs_max *= 2;
4610 builtin_type_tdescs_arr
4611 = (tree *)xrealloc (builtin_type_tdescs_arr,
4612 builtin_type_tdescs_max * sizeof (tree));
4614 builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
4615 if (TREE_CODE (type) != POINTER_TYPE)
4617 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4618 = build_pointer_type (type);
4619 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4620 = build_pointer_type (build_type_variant (type, 1, 0));
4622 if (TREE_CODE (type) != VOID_TYPE)
4624 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4625 = build_reference_type (type);
4626 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4627 = build_reference_type (build_type_variant (type, 1, 0));
4632 /* Push overloaded decl, in global scope, with one argument so it
4633 can be used as a callback from define_function. */
4635 push_overloaded_decl_1 (x)
4638 push_overloaded_decl (x, 0);
4644 tree auto_function (name, type, code)
4646 enum built_in_function code;
4648 return define_function
4649 (IDENTIFIER_POINTER (name), type, code, (void (*)())push_overloaded_decl_1,
4650 IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type),
4654 /* Create the predefined scalar types of C,
4655 and some nodes representing standard constants (0, 1, (void *)0).
4656 Initialize the global binding level.
4657 Make definitions for built-in primitive functions. */
4660 init_decl_processing ()
4663 register tree endlink, int_endlink, double_endlink;
4665 /* Either char* or void*. */
4666 tree traditional_ptr_type_node;
4667 /* Data type of memcpy. */
4668 tree memcpy_ftype, strlen_ftype;
4669 int wchar_type_size;
4671 tree array_domain_type;
4672 extern int flag_strict_prototype;
4673 tree vb_off_identifier;
4674 /* Function type `char *(char *, char *)' and similar ones */
4675 tree string_ftype_ptr_ptr, int_ftype_string_string;
4677 /* Have to make these distinct before we try using them. */
4678 lang_name_cplusplus = get_identifier ("C++");
4679 lang_name_c = get_identifier ("C");
4681 if (flag_strict_prototype == 2)
4684 strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
4687 strict_prototypes_lang_c = flag_strict_prototype;
4690 current_lang_name = lang_name_c;
4692 current_function_decl = NULL_TREE;
4693 named_labels = NULL_TREE;
4694 named_label_uses = NULL_TREE;
4695 current_binding_level = NULL_BINDING_LEVEL;
4696 free_binding_level = NULL_BINDING_LEVEL;
4698 /* Because most segmentation signals can be traced back into user
4699 code, catch them and at least give the user a chance of working
4700 around compiler bugs. */
4701 signal (SIGSEGV, signal_catch);
4703 /* We will also catch aborts in the back-end through signal_catch and
4704 give the user a chance to see where the error might be, and to defeat
4705 aborts in the back-end when there have been errors previously in their
4708 signal (SIGIOT, signal_catch);
4711 signal (SIGILL, signal_catch);
4714 signal (SIGABRT, signal_catch);
4717 signal (SIGBUS, signal_catch);
4720 gcc_obstack_init (&decl_obstack);
4723 builtin_type_tdescs_max = 100;
4724 builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
4727 /* Must lay these out before anything else gets laid out. */
4728 error_mark_node = make_node (ERROR_MARK);
4729 TREE_PERMANENT (error_mark_node) = 1;
4730 TREE_TYPE (error_mark_node) = error_mark_node;
4731 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
4732 TREE_TYPE (error_mark_list) = error_mark_node;
4734 /* Make the binding_level structure for global names. */
4736 global_binding_level = current_binding_level;
4738 this_identifier = get_identifier (THIS_NAME);
4739 in_charge_identifier = get_identifier (IN_CHARGE_NAME);
4740 pfn_identifier = get_identifier (VTABLE_PFN_NAME);
4741 index_identifier = get_identifier (VTABLE_INDEX_NAME);
4742 delta_identifier = get_identifier (VTABLE_DELTA_NAME);
4743 delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
4744 pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
4745 if (flag_handle_signatures)
4747 tag_identifier = get_identifier (SIGTABLE_TAG_NAME);
4748 vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME);
4749 vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME);
4752 /* Define `int' and `char' first so that dbx will output them first. */
4754 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4755 record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
4757 /* Define `char', which is like either `signed char' or `unsigned char'
4758 but not the same as either. */
4762 ? make_signed_type (CHAR_TYPE_SIZE)
4763 : make_unsigned_type (CHAR_TYPE_SIZE));
4764 record_builtin_type (RID_CHAR, "char", char_type_node);
4766 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4767 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4769 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4770 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4772 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4773 record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
4774 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4776 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4777 record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
4779 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4780 record_builtin_type (RID_MAX, "long long unsigned int",
4781 long_long_unsigned_type_node);
4782 record_builtin_type (RID_MAX, "long long unsigned",
4783 long_long_unsigned_type_node);
4785 /* `unsigned long' is the standard type for sizeof.
4786 Traditionally, use a signed type.
4787 Note that stddef.h uses `unsigned long',
4788 and this must agree, even of long and int are the same size. */
4790 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
4791 if (flag_traditional && TREE_UNSIGNED (sizetype))
4792 sizetype = signed_type (sizetype);
4795 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
4797 TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
4798 TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
4799 TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
4800 TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
4801 TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
4802 TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
4803 TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
4805 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4806 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4807 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4808 record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
4809 record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
4811 /* Define both `signed char' and `unsigned char'. */
4812 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4813 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4814 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4815 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4817 /* These are types that type_for_size and type_for_mode use. */
4818 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4819 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
4820 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4821 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
4822 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4823 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
4824 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4825 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
4826 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4827 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
4828 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4829 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
4830 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4831 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
4832 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4833 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
4835 float_type_node = make_node (REAL_TYPE);
4836 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4837 record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
4838 layout_type (float_type_node);
4840 double_type_node = make_node (REAL_TYPE);
4841 if (flag_short_double)
4842 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4844 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4845 record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
4846 layout_type (double_type_node);
4848 long_double_type_node = make_node (REAL_TYPE);
4849 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4850 record_builtin_type (RID_MAX, "long double", long_double_type_node);
4851 layout_type (long_double_type_node);
4853 integer_zero_node = build_int_2 (0, 0);
4854 TREE_TYPE (integer_zero_node) = integer_type_node;
4855 integer_one_node = build_int_2 (1, 0);
4856 TREE_TYPE (integer_one_node) = integer_type_node;
4857 integer_two_node = build_int_2 (2, 0);
4858 TREE_TYPE (integer_two_node) = integer_type_node;
4859 integer_three_node = build_int_2 (3, 0);
4860 TREE_TYPE (integer_three_node) = integer_type_node;
4862 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
4863 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
4864 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
4865 boolean_false_node = build_int_2 (0, 0);
4866 TREE_TYPE (boolean_false_node) = boolean_type_node;
4867 boolean_true_node = build_int_2 (1, 0);
4868 TREE_TYPE (boolean_true_node) = boolean_type_node;
4870 /* These are needed by stor-layout.c. */
4871 size_zero_node = size_int (0);
4872 size_one_node = size_int (1);
4874 void_type_node = make_node (VOID_TYPE);
4875 record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
4876 layout_type (void_type_node); /* Uses integer_zero_node. */
4877 void_list_node = build_tree_list (NULL_TREE, void_type_node);
4878 TREE_PARMLIST (void_list_node) = 1;
4880 null_pointer_node = build_int_2 (0, 0);
4881 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4882 layout_type (TREE_TYPE (null_pointer_node));
4884 /* Used for expressions that do nothing, but are not errors. */
4885 void_zero_node = build_int_2 (0, 0);
4886 TREE_TYPE (void_zero_node) = void_type_node;
4888 string_type_node = build_pointer_type (char_type_node);
4889 const_string_type_node =
4890 build_pointer_type (build_type_variant (char_type_node, 1, 0));
4891 record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
4893 /* Make a type to be the domain of a few array types
4894 whose domains don't really matter.
4895 200 is small enough that it always fits in size_t
4896 and large enough that it can hold most function names for the
4897 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4898 array_domain_type = build_index_type (build_int_2 (200, 0));
4900 /* make a type for arrays of characters.
4901 With luck nothing will ever really depend on the length of this
4903 char_array_type_node
4904 = build_array_type (char_type_node, array_domain_type);
4905 /* Likewise for arrays of ints. */
4907 = build_array_type (integer_type_node, array_domain_type);
4909 /* This is just some anonymous class type. Nobody should ever
4910 need to look inside this envelope. */
4911 class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
4913 default_function_type
4914 = build_function_type (integer_type_node, NULL_TREE);
4916 ptr_type_node = build_pointer_type (void_type_node);
4917 const_ptr_type_node =
4918 build_pointer_type (build_type_variant (void_type_node, 1, 0));
4919 record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
4920 endlink = void_list_node;
4921 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
4922 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
4925 = build_function_type (float_type_node,
4926 tree_cons (NULL_TREE, float_type_node, endlink));
4929 = build_function_type (double_type_node, double_endlink);
4931 ldouble_ftype_ldouble
4932 = build_function_type (long_double_type_node,
4933 tree_cons (NULL_TREE, long_double_type_node,
4936 double_ftype_double_double
4937 = build_function_type (double_type_node,
4938 tree_cons (NULL_TREE, double_type_node,
4942 = build_function_type (integer_type_node, int_endlink);
4945 = build_function_type (long_integer_type_node,
4946 tree_cons (NULL_TREE, long_integer_type_node,
4949 int_ftype_cptr_cptr_sizet
4950 = build_function_type (integer_type_node,
4951 tree_cons (NULL_TREE, const_ptr_type_node,
4952 tree_cons (NULL_TREE, const_ptr_type_node,
4953 tree_cons (NULL_TREE,
4957 string_ftype_ptr_ptr /* strcpy prototype */
4958 = build_function_type (string_type_node,
4959 tree_cons (NULL_TREE, string_type_node,
4960 tree_cons (NULL_TREE,
4961 const_string_type_node,
4964 int_ftype_string_string /* strcmp prototype */
4965 = build_function_type (integer_type_node,
4966 tree_cons (NULL_TREE, const_string_type_node,
4967 tree_cons (NULL_TREE,
4968 const_string_type_node,
4971 strlen_ftype /* strlen prototype */
4972 = build_function_type (sizetype,
4973 tree_cons (NULL_TREE, const_string_type_node,
4976 traditional_ptr_type_node
4977 = (flag_traditional ? string_type_node : ptr_type_node);
4979 memcpy_ftype /* memcpy prototype */
4980 = build_function_type (traditional_ptr_type_node,
4981 tree_cons (NULL_TREE, ptr_type_node,
4982 tree_cons (NULL_TREE, const_ptr_type_node,
4983 tree_cons (NULL_TREE,
4987 if (flag_huge_objects)
4988 delta_type_node = long_integer_type_node;
4990 delta_type_node = short_integer_type_node;
4992 builtin_function ("__builtin_constant_p", int_ftype_int,
4993 BUILT_IN_CONSTANT_P, NULL_PTR);
4995 builtin_return_address_fndecl =
4996 builtin_function ("__builtin_return_address",
4997 build_function_type (ptr_type_node,
4998 tree_cons (NULL_TREE,
5001 BUILT_IN_RETURN_ADDRESS, NULL_PTR);
5003 builtin_function ("__builtin_frame_address",
5004 build_function_type (ptr_type_node,
5005 tree_cons (NULL_TREE,
5008 BUILT_IN_FRAME_ADDRESS, NULL_PTR);
5010 builtin_function ("__builtin_alloca",
5011 build_function_type (ptr_type_node,
5012 tree_cons (NULL_TREE,
5015 BUILT_IN_ALLOCA, "alloca");
5016 builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
5017 /* Define alloca, ffs as builtins.
5018 Declare _exit just to mark it as volatile. */
5019 if (! flag_no_builtin && !flag_no_nonansi_builtin)
5021 temp = builtin_function ("alloca",
5022 build_function_type (ptr_type_node,
5023 tree_cons (NULL_TREE,
5026 BUILT_IN_ALLOCA, NULL_PTR);
5027 /* Suppress error if redefined as a non-function. */
5028 DECL_BUILT_IN_NONANSI (temp) = 1;
5029 temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
5030 /* Suppress error if redefined as a non-function. */
5031 DECL_BUILT_IN_NONANSI (temp) = 1;
5032 temp = builtin_function ("_exit", build_function_type (void_type_node,
5034 NOT_BUILT_IN, NULL_PTR);
5035 TREE_THIS_VOLATILE (temp) = 1;
5036 TREE_SIDE_EFFECTS (temp) = 1;
5037 /* Suppress error if redefined as a non-function. */
5038 DECL_BUILT_IN_NONANSI (temp) = 1;
5041 builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
5042 builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS,
5044 builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS,
5046 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
5048 builtin_function ("__builtin_labs", long_ftype_long,
5049 BUILT_IN_LABS, NULL_PTR);
5050 builtin_function ("__builtin_saveregs",
5051 build_function_type (ptr_type_node, NULL_TREE),
5052 BUILT_IN_SAVEREGS, NULL_PTR);
5053 builtin_function ("__builtin_classify_type", default_function_type,
5054 BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
5055 builtin_function ("__builtin_next_arg",
5056 build_function_type (ptr_type_node, NULL_TREE),
5057 BUILT_IN_NEXT_ARG, NULL_PTR);
5058 builtin_function ("__builtin_args_info",
5059 build_function_type (integer_type_node,
5060 tree_cons (NULL_TREE,
5063 BUILT_IN_ARGS_INFO, NULL_PTR);
5065 /* Untyped call and return. */
5066 builtin_function ("__builtin_apply_args",
5067 build_function_type (ptr_type_node, NULL_TREE),
5068 BUILT_IN_APPLY_ARGS, NULL_PTR);
5070 temp = tree_cons (NULL_TREE,
5071 build_pointer_type (build_function_type (void_type_node,
5073 tree_cons (NULL_TREE,
5075 tree_cons (NULL_TREE,
5078 builtin_function ("__builtin_apply",
5079 build_function_type (ptr_type_node, temp),
5080 BUILT_IN_APPLY, NULL_PTR);
5081 builtin_function ("__builtin_return",
5082 build_function_type (void_type_node,
5083 tree_cons (NULL_TREE,
5086 BUILT_IN_RETURN, NULL_PTR);
5088 /* Currently under experimentation. */
5089 builtin_function ("__builtin_memcpy", memcpy_ftype,
5090 BUILT_IN_MEMCPY, "memcpy");
5091 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
5092 BUILT_IN_MEMCMP, "memcmp");
5093 builtin_function ("__builtin_strcmp", int_ftype_string_string,
5094 BUILT_IN_STRCMP, "strcmp");
5095 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
5096 BUILT_IN_STRCPY, "strcpy");
5097 builtin_function ("__builtin_strlen", strlen_ftype,
5098 BUILT_IN_STRLEN, "strlen");
5099 builtin_function ("__builtin_sqrtf", float_ftype_float,
5100 BUILT_IN_FSQRT, "sqrtf");
5101 builtin_function ("__builtin_fsqrt", double_ftype_double,
5102 BUILT_IN_FSQRT, NULL_PTR);
5103 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
5104 BUILT_IN_FSQRT, "sqrtl");
5105 builtin_function ("__builtin_sinf", float_ftype_float,
5106 BUILT_IN_SIN, "sinf");
5107 builtin_function ("__builtin_sin", double_ftype_double,
5108 BUILT_IN_SIN, "sin");
5109 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
5110 BUILT_IN_SIN, "sinl");
5111 builtin_function ("__builtin_cosf", float_ftype_float,
5112 BUILT_IN_COS, "cosf");
5113 builtin_function ("__builtin_cos", double_ftype_double,
5114 BUILT_IN_COS, "cos");
5115 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
5116 BUILT_IN_COS, "cosl");
5118 if (!flag_no_builtin)
5120 #if 0 /* These do not work well with libg++. */
5121 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
5122 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
5123 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
5125 builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR);
5126 builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
5128 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
5129 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
5131 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP,
5133 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
5135 builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR);
5136 builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR);
5137 builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR);
5138 builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT,
5140 builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR);
5141 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
5142 builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR);
5143 builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR);
5144 builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
5145 builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR);
5147 /* Declare these functions volatile
5148 to avoid spurious "control drops through" warnings. */
5149 temp = builtin_function ("abort",
5150 build_function_type (void_type_node, endlink),
5151 NOT_BUILT_IN, NULL_PTR);
5152 TREE_THIS_VOLATILE (temp) = 1;
5153 TREE_SIDE_EFFECTS (temp) = 1;
5154 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
5156 DECL_BUILT_IN_NONANSI (temp) = 1;
5157 temp = builtin_function ("exit", build_function_type (void_type_node,
5159 NOT_BUILT_IN, NULL_PTR);
5160 TREE_THIS_VOLATILE (temp) = 1;
5161 TREE_SIDE_EFFECTS (temp) = 1;
5162 DECL_BUILT_IN_NONANSI (temp) = 1;
5166 /* Support for these has not been written in either expand_builtin
5167 or build_function_call. */
5168 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR);
5169 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR);
5170 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
5172 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
5174 builtin_function ("__builtin_fmod", double_ftype_double_double,
5175 BUILT_IN_FMOD, NULL_PTR);
5176 builtin_function ("__builtin_frem", double_ftype_double_double,
5177 BUILT_IN_FREM, NULL_PTR);
5178 builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int,
5179 BUILT_IN_MEMSET, NULL_PTR);
5180 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
5182 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
5186 /* C++ extensions */
5188 unknown_type_node = make_node (UNKNOWN_TYPE);
5189 decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
5190 unknown_type_node));
5191 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
5192 DECL_IGNORED_P (decl) = 1;
5193 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
5194 TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
5195 TYPE_ALIGN (unknown_type_node) = 1;
5196 TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
5197 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
5198 TREE_TYPE (unknown_type_node) = unknown_type_node;
5199 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
5200 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
5201 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
5203 /* This is for handling opaque types in signatures. */
5204 opaque_type_node = copy_node (ptr_type_node);
5205 TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
5206 record_builtin_type (RID_MAX, 0, opaque_type_node);
5208 /* This is special for C++ so functions can be overloaded. */
5210 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
5211 wchar_type_size = TYPE_PRECISION (wchar_type_node);
5212 signed_wchar_type_node = make_signed_type (wchar_type_size);
5213 unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
5215 = TREE_UNSIGNED (wchar_type_node)
5216 ? unsigned_wchar_type_node
5217 : signed_wchar_type_node;
5218 record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
5220 /* Artificial declaration of wchar_t -- can be bashed */
5221 wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"),
5223 pushdecl (wchar_decl_node);
5225 /* This is for wide string constants. */
5226 wchar_array_type_node
5227 = build_array_type (wchar_type_node, array_domain_type);
5229 if (flag_vtable_thunks)
5231 /* Make sure we get a unique function type, so we can give
5232 its pointer type a name. (This wins for gdb.) */
5233 tree vfunc_type = make_node (FUNCTION_TYPE);
5234 TREE_TYPE (vfunc_type) = integer_type_node;
5235 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
5236 layout_type (vfunc_type);
5238 vtable_entry_type = build_pointer_type (vfunc_type);
5242 vtable_entry_type = make_lang_type (RECORD_TYPE);
5243 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
5245 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
5247 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
5249 finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
5252 /* Make this part of an invisible union. */
5253 fields[3] = copy_node (fields[2]);
5254 TREE_TYPE (fields[3]) = delta_type_node;
5255 DECL_NAME (fields[3]) = delta2_identifier;
5256 DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
5257 DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
5258 TREE_UNSIGNED (fields[3]) = 0;
5259 TREE_CHAIN (fields[2]) = fields[3];
5260 vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
5262 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
5265 = build_array_type (vtable_entry_type, NULL_TREE);
5266 layout_type (vtbl_type_node);
5267 vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0);
5268 record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
5270 /* Simplify life by making a "sigtable_entry_type". Give its
5271 fields names so that the debugger can use them. */
5273 if (flag_handle_signatures)
5275 sigtable_entry_type = make_lang_type (RECORD_TYPE);
5276 fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier,
5278 fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier,
5280 fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier,
5282 fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier,
5284 fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
5287 /* Set the alignment to the max of the alignment of ptr_type_node and
5288 delta_type_node. Double alignment wastes a word on the Sparc. */
5289 finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4,
5290 (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node))
5294 /* Make this part of an invisible union. */
5295 fields[5] = copy_node (fields[4]);
5296 TREE_TYPE (fields[5]) = delta_type_node;
5297 DECL_NAME (fields[5]) = vt_off_identifier;
5298 DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node);
5299 DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node);
5300 TREE_UNSIGNED (fields[5]) = 0;
5301 TREE_CHAIN (fields[4]) = fields[5];
5303 sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
5304 record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
5310 /* Must build __t_desc type. Currently, type descriptors look like this:
5317 struct __t_desc *points_to;
5318 int ivars_count, meths_count;
5319 struct __i_desc *ivars[];
5320 struct __m_desc *meths[];
5321 struct __t_desc *parents[];
5322 struct __t_desc *vbases[];
5326 ...as per Linton's paper. */
5328 __t_desc_type_node = make_lang_type (RECORD_TYPE);
5329 __i_desc_type_node = make_lang_type (RECORD_TYPE);
5330 __m_desc_type_node = make_lang_type (RECORD_TYPE);
5331 __t_desc_array_type =
5332 build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE);
5333 __i_desc_array_type =
5334 build_array_type (build_pointer_type (__i_desc_type_node), NULL_TREE);
5335 __m_desc_array_type =
5336 build_array_type (build_pointer_type (__m_desc_type_node), NULL_TREE);
5338 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5340 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
5341 unsigned_type_node);
5342 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
5343 unsigned_type_node);
5344 fields[3] = build_lang_field_decl (FIELD_DECL,
5345 get_identifier ("points_to"),
5346 build_pointer_type (__t_desc_type_node));
5347 fields[4] = build_lang_field_decl (FIELD_DECL,
5348 get_identifier ("ivars_count"),
5350 fields[5] = build_lang_field_decl (FIELD_DECL,
5351 get_identifier ("meths_count"),
5353 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
5354 build_pointer_type (__i_desc_array_type));
5355 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
5356 build_pointer_type (__m_desc_array_type));
5357 fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
5358 build_pointer_type (__t_desc_array_type));
5359 fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
5360 build_pointer_type (__t_desc_array_type));
5361 fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
5362 build_pointer_type (integer_type_node));
5363 finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
5365 /* ivar descriptors look like this:
5371 struct __t_desc *type;
5375 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5377 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
5379 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
5380 build_pointer_type (__t_desc_type_node));
5381 finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2,
5384 /* method descriptors look like this:
5390 struct __t_desc *vcontext;
5391 struct __t_desc *return_type;
5394 short required_parms;
5395 struct __t_desc *parm_types[];
5399 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5401 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
5403 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
5404 build_pointer_type (__t_desc_type_node));
5405 fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
5406 build_pointer_type (__t_desc_type_node));
5407 fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
5408 build_pointer_type (default_function_type));
5409 fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
5410 short_integer_type_node);
5411 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
5412 short_integer_type_node);
5413 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
5414 build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE)));
5415 finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7,
5421 int i = builtin_type_tdescs_len;
5424 tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
5425 TREE_ASM_WRITTEN (tdesc) = 1;
5426 TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
5429 #endif /*flag_rtti*/
5432 current_lang_name = lang_name_cplusplus;
5434 auto_function (ansi_opname[(int) NEW_EXPR],
5435 build_function_type (ptr_type_node,
5436 tree_cons (NULL_TREE, sizetype,
5439 auto_function (ansi_opname[(int) VEC_NEW_EXPR],
5440 build_function_type (ptr_type_node,
5441 tree_cons (NULL_TREE, sizetype,
5444 auto_function (ansi_opname[(int) DELETE_EXPR],
5445 build_function_type (void_type_node,
5446 tree_cons (NULL_TREE, ptr_type_node,
5449 auto_function (ansi_opname[(int) VEC_DELETE_EXPR],
5450 build_function_type (void_type_node,
5451 tree_cons (NULL_TREE, ptr_type_node,
5456 = define_function ("__pure_virtual",
5457 build_function_type (void_type_node, void_list_node),
5458 NOT_BUILT_IN, 0, 0);
5460 /* Perform other language dependent initializations. */
5461 init_class_processing ();
5462 init_init_processing ();
5463 init_search_processing ();
5465 if (flag_handle_exceptions)
5466 init_exception_processing ();
5469 flag_inline_functions = 0;
5472 if (! SUPPORTS_WEAK)
5475 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
5476 declare_function_name ();
5478 /* Prepare to check format strings against argument lists. */
5479 init_function_format_info ();
5482 /* initialize type descriptor type node of various rtti type. */
5489 tdecl = lookup_name (get_identifier ("type_info"), 0);
5490 if (tdecl == NULL_TREE)
5492 __t_desc_type_node = TREE_TYPE(tdecl);
5494 __tp_desc_type_node = build_pointer_type (__t_desc_type_node);
5498 tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0);
5499 if (tdecl == NULL_TREE)
5501 __baselist_desc_type_node = TREE_TYPE (tdecl);
5504 tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0);
5505 if (tdecl == NULL_TREE)
5507 __bltn_desc_type_node = TREE_TYPE (tdecl);
5509 tdecl = lookup_name (get_identifier ("__user_type_info"), 0);
5510 if (tdecl == NULL_TREE)
5512 __user_desc_type_node = TREE_TYPE (tdecl);
5514 tdecl = lookup_name (get_identifier ("__class_type_info"), 0);
5515 if (tdecl == NULL_TREE)
5517 __class_desc_type_node = TREE_TYPE (tdecl);
5519 tdecl = lookup_field (__class_desc_type_node,
5520 get_identifier ("access_mode"), 0, 0);
5521 if (tdecl == NULL_TREE)
5523 __access_mode_type_node = TREE_TYPE (tdecl);
5525 tdecl = lookup_name (get_identifier ("__attr_type_info"), 0);
5526 if (tdecl == NULL_TREE)
5528 __attr_desc_type_node = TREE_TYPE (tdecl);
5530 tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0);
5531 if (tdecl == NULL_TREE)
5533 __ptr_desc_type_node = TREE_TYPE (tdecl);
5535 tdecl = lookup_name (get_identifier ("__func_type_info"), 0);
5536 if (tdecl == NULL_TREE)
5538 __func_desc_type_node = TREE_TYPE (tdecl);
5540 tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0);
5541 if (tdecl == NULL_TREE)
5543 __ptmf_desc_type_node = TREE_TYPE (tdecl);
5545 tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0);
5546 if (tdecl == NULL_TREE)
5548 __ptmd_desc_type_node = TREE_TYPE (tdecl);
5552 /* Make a definition for a builtin function named NAME and whose data type
5553 is TYPE. TYPE should be a function type with argument types.
5554 FUNCTION_CODE tells later passes how to compile calls to this function.
5555 See tree.h for its possible values.
5557 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
5558 the name to be called if we can't opencode the function. */
5561 define_function (name, type, function_code, pfn, library_name)
5564 enum built_in_function function_code;
5568 tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
5569 DECL_EXTERNAL (decl) = 1;
5570 TREE_PUBLIC (decl) = 1;
5571 DECL_ARTIFICIAL (decl) = 1;
5573 /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
5574 we cannot change DECL_ASSEMBLER_NAME until we have installed this
5575 function in the namespace. */
5576 if (pfn) (*pfn) (decl);
5578 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
5579 make_function_rtl (decl);
5580 if (function_code != NOT_BUILT_IN)
5582 DECL_BUILT_IN (decl) = 1;
5583 DECL_FUNCTION_CODE (decl) = function_code;
5588 /* Called when a declaration is seen that contains no names to declare.
5589 If its type is a reference to a structure, union or enum inherited
5590 from a containing scope, shadow that tag name for the current scope
5591 with a forward reference.
5592 If its type defines a new named structure or union
5593 or defines an enum, it is valid but we need not do anything here.
5594 Otherwise, it is an error.
5596 C++: may have to grok the declspecs to learn about static,
5597 complain for anonymous unions. */
5600 shadow_tag (declspecs)
5604 tree ob_modifier = NULL_TREE;
5606 register enum tree_code code, ok_code = ERROR_MARK;
5607 register tree t = NULL_TREE;
5609 for (link = declspecs; link; link = TREE_CHAIN (link))
5611 register tree value = TREE_VALUE (link);
5613 code = TREE_CODE (value);
5614 if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
5616 my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261);
5618 if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0)
5619 cp_error ("forward declaration of `%#T'", value);
5621 else if (IS_AGGR_TYPE (value) && CLASSTYPE_USE_TEMPLATE (value))
5623 if (CLASSTYPE_IMPLICIT_INSTANTIATION (value)
5624 && TYPE_SIZE (value) == NULL_TREE)
5625 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (value);
5626 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (value))
5627 cp_error ("specialization after instantiation of `%T'", value);
5634 else if (value == ridpointers[(int) RID_STATIC]
5635 || value == ridpointers[(int) RID_EXTERN]
5636 || value == ridpointers[(int) RID_AUTO]
5637 || value == ridpointers[(int) RID_REGISTER]
5638 || value == ridpointers[(int) RID_INLINE]
5639 || value == ridpointers[(int) RID_VIRTUAL]
5640 || value == ridpointers[(int) RID_EXPLICIT])
5641 ob_modifier = value;
5644 /* This is where the variables in an anonymous union are
5645 declared. An anonymous union declaration looks like:
5647 because there is no declarator after the union, the parser
5648 sends that declaration here. */
5649 if (ok_code == UNION_TYPE
5651 && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
5652 && ANON_AGGRNAME_P (TYPE_NAME (t)))
5653 || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
5654 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
5656 /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
5657 function members. */
5658 if (TYPE_FIELDS (t))
5660 tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
5661 NULL_TREE, NULL_TREE);
5662 finish_anon_union (decl);
5665 error ("anonymous union cannot have a function member");
5669 /* Anonymous unions are objects, that's why we only check for
5670 inappropriate specifiers in this branch. */
5674 if (ob_modifier == ridpointers[(int) RID_INLINE]
5675 || ob_modifier == ridpointers[(int) RID_VIRTUAL])
5676 cp_error ("`%D' can only be specified for functions", ob_modifier);
5677 else if (ob_modifier == ridpointers[(int) RID_EXPLICIT])
5678 cp_error ("`%D' can only be specified for constructors",
5681 cp_error ("`%D' can only be specified for objects and functions",
5686 pedwarn ("abstract declarator used as declaration");
5687 else if (found_tag > 1)
5688 pedwarn ("multiple types in one declaration");
5692 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
5695 groktypename (typename)
5698 if (TREE_CODE (typename) != TREE_LIST)
5700 return grokdeclarator (TREE_VALUE (typename),
5701 TREE_PURPOSE (typename),
5702 TYPENAME, 0, NULL_TREE, NULL_TREE);
5705 /* Decode a declarator in an ordinary declaration or data definition.
5706 This is called as soon as the type information and variable name
5707 have been parsed, before parsing the initializer if any.
5708 Here we create the ..._DECL node, fill in its type,
5709 and put it on the list of decls for the current context.
5710 The ..._DECL node is returned as the value.
5712 Exception: for arrays where the length is not specified,
5713 the type is left null, to be filled in by `cp_finish_decl'.
5715 Function definitions do not come here; they go to start_function
5716 instead. However, external and forward declarations of functions
5717 do go through here. Structure field declarations are done by
5718 grokfield and not through here. */
5720 /* Set this to zero to debug not using the temporary obstack
5721 to parse initializers. */
5722 int debug_temp_inits = 1;
5724 void start_decl_1 ();
5727 start_decl (declarator, declspecs, initialized, raises)
5728 tree declarator, declspecs;
5733 register tree type, tem;
5735 extern int have_extern_spec;
5736 extern int used_extern_spec;
5739 /* See code below that used this. */
5740 int init_written = initialized;
5743 /* This should only be done once on the top most decl. */
5744 if (have_extern_spec && !used_extern_spec)
5746 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"),
5748 used_extern_spec = 1;
5751 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises,
5753 if (decl == NULL_TREE || decl == void_type_node)
5756 type = TREE_TYPE (decl);
5758 /* Don't lose if destructors must be executed at file-level. */
5759 if (! current_template_parms && TREE_STATIC (decl)
5760 && TYPE_NEEDS_DESTRUCTOR (complete_type (type))
5761 && !TREE_PERMANENT (decl))
5763 push_obstacks (&permanent_obstack, &permanent_obstack);
5764 decl = copy_node (decl);
5765 if (TREE_CODE (type) == ARRAY_TYPE)
5767 tree itype = TYPE_DOMAIN (type);
5768 if (itype && ! TREE_PERMANENT (itype))
5770 itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
5771 type = build_cplus_array_type (TREE_TYPE (type), itype);
5772 TREE_TYPE (decl) = type;
5779 = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
5780 ? DECL_CLASS_CONTEXT (decl)
5781 : DECL_CONTEXT (decl);
5784 /* Is it valid for this decl to have an initializer at all?
5785 If not, set INITIALIZED to zero, which will indirectly
5786 tell `cp_finish_decl' to ignore the initializer once it is parsed. */
5787 switch (TREE_CODE (decl))
5790 /* typedef foo = bar means give foo the same type as bar.
5791 We haven't parsed bar yet, so `cp_finish_decl' will fix that up.
5792 Any other case of an initialization in a TYPE_DECL is an error. */
5793 if (pedantic || list_length (declspecs) > 1)
5795 cp_error ("typedef `%D' is initialized", decl);
5801 cp_error ("function `%#D' is initialized like a variable", decl);
5806 if (TREE_CODE (type) == ARRAY_TYPE && ! current_template_parms
5807 && TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE)
5809 cp_error ("elements of array `%#D' have incomplete type", decl);
5816 if (! toplevel_bindings_p ()
5817 && DECL_EXTERNAL (decl))
5818 cp_warning ("declaration of `%#D' has `extern' and is initialized",
5820 DECL_EXTERNAL (decl) = 0;
5821 if (toplevel_bindings_p ())
5822 TREE_STATIC (decl) = 1;
5824 /* Tell `pushdecl' this is an initialized decl
5825 even though we don't yet have the initializer expression.
5826 Also tell `cp_finish_decl' it may store the real initializer. */
5827 DECL_INITIAL (decl) = error_mark_node;
5830 if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE)
5832 if (TREE_CODE (decl) == VAR_DECL)
5834 tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
5835 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
5836 cp_error ("`%#D' is not a static member of `%#T'", decl, context);
5837 else if (duplicate_decls (decl, field))
5842 tree field = check_classfn (context, decl);
5843 if (field && duplicate_decls (decl, field))
5847 /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
5848 if (DECL_LANG_SPECIFIC (decl))
5849 DECL_IN_AGGR_P (decl) = 0;
5850 if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context))
5851 SET_DECL_TEMPLATE_SPECIALIZATION (decl);
5853 /* Stupid stupid stupid stupid (jason 7/21/95) */
5854 if (pedantic && DECL_EXTERNAL (decl)
5855 && ! DECL_TEMPLATE_SPECIALIZATION (decl))
5856 cp_pedwarn ("declaration of `%#D' outside of class is not definition",
5859 pushclass (context, 2);
5862 /* Add this decl to the current binding level, but not if it
5863 comes from another scope, e.g. a static member variable.
5864 TEM may equal DECL or it may be a previous decl of the same name. */
5866 if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
5867 || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
5868 || TREE_CODE (type) == LANG_TYPE)
5871 tem = pushdecl (decl);
5873 if (current_template_parms)
5875 if (! current_function_decl)
5876 push_template_decl (tem);
5877 else if (minimal_parse_mode)
5879 = build_min_nt (DECL_STMT, copy_to_permanent (declarator),
5880 copy_to_permanent (declspecs),
5881 copy_to_permanent (raises), NULL_TREE);
5885 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
5886 /* Tell the back-end to use or not use .common as appropriate. If we say
5887 -fconserve-space, we want this to save space, at the expense of wrong
5888 semantics. If we say -fno-conserve-space, we want this to produce
5889 errors about redefs; to do this we force variables into the data
5890 segment. Common storage is okay for non-public uninitialized data;
5891 the linker can't match it with storage from other files, and we may
5892 save some disk space. */
5893 DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem);
5896 if (! current_template_parms)
5899 /* Corresponding pop_obstacks is done in `cp_finish_decl'. */
5900 push_obstacks_nochange ();
5903 /* We have no way of knowing whether the initializer will need to be
5904 evaluated at run-time or not until we've parsed it, so let's just put
5905 it in the permanent obstack. (jason) */
5907 && ! (TREE_CODE (tem) == PARM_DECL
5908 || (TREE_READONLY (tem)
5909 && (TREE_CODE (tem) == VAR_DECL
5910 || TREE_CODE (tem) == FIELD_DECL))))
5912 /* When parsing and digesting the initializer,
5913 use temporary storage. Do this even if we will ignore the value. */
5914 if (toplevel_bindings_p () && debug_temp_inits)
5916 if (current_template_parms
5917 || TYPE_NEEDS_CONSTRUCTING (type)
5918 || TREE_CODE (type) == REFERENCE_TYPE)
5919 /* In this case, the initializer must lay down in permanent
5920 storage, since it will be saved until `finish_file' is run. */
5923 temporary_allocation ();
5935 tree type = TREE_TYPE (decl);
5936 int initialized = (DECL_INITIAL (decl) != NULL_TREE);
5938 /* If this type of object needs a cleanup, and control may
5939 jump past it, make a new binding level so that it is cleaned
5940 up only when it is initialized first. */
5941 if (TYPE_NEEDS_DESTRUCTOR (type)
5942 && current_binding_level->more_cleanups_ok == 0)
5943 pushlevel_temporary (1);
5946 /* Is it valid for this decl to have an initializer at all?
5947 If not, set INITIALIZED to zero, which will indirectly
5948 tell `cp_finish_decl' to ignore the initializer once it is parsed. */
5950 /* Don't allow initializations for incomplete types except for
5951 arrays which might be completed by the initialization. */
5952 if (type == error_mark_node)
5953 ; /* Don't complain again. */
5954 else if (TYPE_SIZE (complete_type (type)) != NULL_TREE)
5955 ; /* A complete type is ok. */
5956 else if (TREE_CODE (type) != ARRAY_TYPE)
5958 cp_error ("variable `%#D' has initializer but incomplete type",
5962 else if (TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE)
5964 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
5965 cp_error ("elements of array `%#D' have incomplete type", decl);
5966 /* else we already gave an error in start_decl. */
5972 && TREE_CODE (decl) != TYPE_DECL
5973 && TREE_CODE (decl) != TEMPLATE_DECL
5974 && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
5976 if (TYPE_SIZE (complete_type (type)) == NULL_TREE)
5978 cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
5980 /* Change the type so that assemble_variable will give
5981 DECL an rtl we can live with: (mem (const_int 0)). */
5982 TREE_TYPE (decl) = error_mark_node;
5983 type = error_mark_node;
5987 /* If any base type in the hierarchy of TYPE needs a constructor,
5988 then we set initialized to 1. This way any nodes which are
5989 created for the purposes of initializing this aggregate
5990 will live as long as it does. This is necessary for global
5991 aggregates which do not have their initializers processed until
5992 the end of the file. */
5993 initialized = TYPE_NEEDS_CONSTRUCTING (type);
5998 /* We don't do this yet for GNU C++. */
5999 /* For a local variable, define the RTL now. */
6000 if (! toplevel_bindings_p ()
6001 /* But not if this is a duplicate decl
6002 and we preserved the rtl from the previous one
6003 (which may or may not happen). */
6004 && DECL_RTL (tem) == NULL_RTX)
6006 if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
6008 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
6009 && DECL_INITIAL (tem) != NULL_TREE)
6015 DECL_INITIAL (decl) = NULL_TREE;
6018 /* Handle initialization of references.
6019 These three arguments from from `cp_finish_decl', and have the
6020 same meaning here that they do there. */
6021 /* quotes on semantics can be found in ARM 8.4.3. */
6023 grok_reference_init (decl, type, init, cleanupp)
6024 tree decl, type, init;
6029 if (init == NULL_TREE)
6031 if ((DECL_LANG_SPECIFIC (decl) == 0
6032 || DECL_IN_AGGR_P (decl) == 0)
6033 && ! DECL_THIS_EXTERN (decl))
6035 cp_error ("`%D' declared as reference but not initialized", decl);
6036 if (TREE_CODE (decl) == VAR_DECL)
6037 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
6042 if (init == error_mark_node)
6045 if (TREE_CODE (type) == REFERENCE_TYPE
6046 && TREE_CODE (init) == CONSTRUCTOR)
6048 cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
6052 if (TREE_TYPE (init) && TREE_CODE (TREE_TYPE (init)) == UNKNOWN_TYPE)
6053 /* decay_conversion is probably wrong for references to functions. */
6054 init = decay_conversion (instantiate_type (TREE_TYPE (type), init, 1));
6056 if (TREE_CODE (init) == TREE_LIST)
6057 init = build_compound_expr (init);
6059 if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
6060 init = convert_from_reference (init);
6062 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
6063 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
6065 /* Note: default conversion is only called in very special cases. */
6066 init = default_conversion (init);
6069 tmp = convert_to_reference
6070 (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl);
6072 if (tmp == error_mark_node)
6074 else if (tmp != NULL_TREE)
6076 tree subtype = TREE_TYPE (type);
6079 /* Associate the cleanup with the reference so that we
6080 don't get burned by "aggressive" cleanup policy. */
6081 if (TYPE_NEEDS_DESTRUCTOR (subtype))
6083 if (TREE_CODE (tmp) == ADDR_EXPR)
6084 tmp = TREE_OPERAND (tmp, 0);
6085 if (TREE_CODE (tmp) == TARGET_EXPR)
6087 *cleanupp = build_delete
6088 (build_pointer_type (subtype),
6089 build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0),
6090 integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
6091 TREE_OPERAND (tmp, 2) = error_mark_node;
6095 DECL_INITIAL (decl) = save_expr (init);
6099 cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
6103 /* ?? Can this be optimized in some cases to
6104 hand back the DECL_INITIAL slot?? */
6105 if (TYPE_SIZE (TREE_TYPE (type)))
6107 init = convert_from_reference (decl);
6108 if (TREE_PERMANENT (decl))
6109 init = copy_to_permanent (init);
6110 SET_DECL_REFERENCE_SLOT (decl, init);
6113 if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
6115 expand_static_init (decl, DECL_INITIAL (decl));
6116 DECL_INITIAL (decl) = NULL_TREE;
6121 if (TREE_CODE (decl) == VAR_DECL)
6122 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
6126 /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from
6127 mucking with forces it does not comprehend (i.e. initialization with a
6128 constructor). If we are at global scope and won't go into COMMON, fill
6129 it in with a dummy CONSTRUCTOR to force the variable into .data;
6130 otherwise we can use error_mark_node. */
6133 obscure_complex_init (decl, init)
6136 if (! flag_no_inline && TREE_STATIC (decl))
6138 if (extract_init (decl, init))
6142 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
6143 if (toplevel_bindings_p () && ! DECL_COMMON (decl))
6144 DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE,
6148 DECL_INITIAL (decl) = error_mark_node;
6153 /* Finish processing of a declaration;
6154 install its line number and initial value.
6155 If the length of an array type is not known before,
6156 it must be determined now, from the initial value, or it is an error.
6158 Call `pop_obstacks' iff NEED_POP is nonzero.
6160 For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers
6161 for aggregates that have constructors alive on the permanent obstack,
6162 so that the global initializing functions can be written at the end.
6164 INIT0 holds the value of an initializer that should be allowed to escape
6167 FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0
6168 if the (init) syntax was used.
6170 For functions that take default parameters, DECL points to its
6171 "maximal" instantiation. `cp_finish_decl' must then also declared its
6172 subsequently lower and lower forms of instantiation, checking for
6173 ambiguity as it goes. This can be sped up later. */
6176 cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
6183 tree cleanup = NULL_TREE, ttype;
6185 int temporary = allocation_temporary_p ();
6186 char *asmspec = NULL;
6187 int was_readonly = 0;
6189 /* If this is 0, then we did not change obstacks. */
6193 error ("assignment (not initialization) in declaration");
6197 /* If a name was specified, get the string. */
6199 asmspec = TREE_STRING_POINTER (asmspec_tree);
6201 /* If the type of the thing we are declaring either has
6202 a constructor, or has a virtual function table pointer,
6203 AND its initialization was accepted by `start_decl',
6204 then we stayed on the permanent obstack through the
6205 declaration, otherwise, changed obstacks as GCC would. */
6207 type = TREE_TYPE (decl);
6209 if (type == error_mark_node)
6211 if (toplevel_bindings_p () && temporary)
6212 end_temporary_allocation ();
6217 if (current_template_parms)
6219 if (init && DECL_INITIAL (decl))
6220 DECL_INITIAL (decl) = init;
6221 if (minimal_parse_mode && ! DECL_ARTIFICIAL (decl))
6223 tree stmt = DECL_VINDEX (decl);
6224 DECL_VINDEX (decl) = NULL_TREE;
6225 TREE_OPERAND (stmt, 3) = copy_to_permanent (init);
6231 /* Take care of TYPE_DECLs up front. */
6232 if (TREE_CODE (decl) == TYPE_DECL)
6234 if (init && DECL_INITIAL (decl))
6236 /* typedef foo = bar; store the type of bar as the type of foo. */
6237 TREE_TYPE (decl) = type = TREE_TYPE (init);
6238 DECL_INITIAL (decl) = init = NULL_TREE;
6240 if (type != error_mark_node
6241 && IS_AGGR_TYPE (type) && DECL_NAME (decl))
6243 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
6244 cp_warning ("shadowing previous type declaration of `%#D'", decl);
6245 set_identifier_type_value (DECL_NAME (decl), type);
6246 CLASSTYPE_GOT_SEMICOLON (type) = 1;
6248 GNU_xref_decl (current_function_decl, decl);
6250 /* If we have installed this as the canonical typedef for this
6251 type, and that type has not been defined yet, delay emitting
6252 the debug informaion for it, as we will emit it later. */
6253 if (TYPE_NAME (TREE_TYPE (decl)) == decl
6254 && TYPE_SIZE (TREE_TYPE (decl)) == NULL_TREE)
6255 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
6257 rest_of_decl_compilation (decl, NULL_PTR,
6258 DECL_CONTEXT (decl) == NULL_TREE, at_eof);
6261 if (TREE_CODE (decl) != FUNCTION_DECL)
6263 ttype = target_type (type);
6266 if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
6267 && TYPE_NEEDS_CONSTRUCTING (type))
6270 /* Currently, GNU C++ puts constants in text space, making them
6271 impossible to initialize. In the future, one would hope for
6272 an operating system which understood the difference between
6273 initialization and the running of a program. */
6275 TREE_READONLY (decl) = 0;
6278 if (TREE_CODE (decl) == FIELD_DECL)
6280 if (init && init != error_mark_node)
6281 my_friendly_assert (TREE_PERMANENT (init), 147);
6285 /* This must override the asm specifier which was placed
6286 by grokclassfn. Lay this out fresh. */
6287 DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
6288 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
6289 make_decl_rtl (decl, asmspec, 0);
6292 /* If `start_decl' didn't like having an initialization, ignore it now. */
6293 else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
6295 else if (DECL_EXTERNAL (decl))
6297 else if (TREE_CODE (type) == REFERENCE_TYPE
6298 || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
6300 if (TREE_STATIC (decl))
6301 make_decl_rtl (decl, NULL_PTR,
6302 toplevel_bindings_p ()
6303 || pseudo_global_level_p ());
6304 grok_reference_init (decl, type, init, &cleanup);
6308 GNU_xref_decl (current_function_decl, decl);
6310 if (TREE_CODE (decl) == FIELD_DECL)
6312 else if (TREE_CODE (decl) == CONST_DECL)
6314 my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
6316 DECL_INITIAL (decl) = init;
6318 /* This will keep us from needing to worry about our obstacks. */
6319 my_friendly_assert (init != NULL_TREE, 149);
6324 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
6326 if (TREE_CODE (type) == ARRAY_TYPE)
6327 init = digest_init (type, init, (tree *) 0);
6328 else if (TREE_CODE (init) == CONSTRUCTOR)
6330 if (TYPE_NON_AGGREGATE_CLASS (type))
6332 cp_error ("`%D' must be initialized by constructor, not by `{...}'",
6334 init = error_mark_node;
6337 goto dont_use_constructor;
6342 dont_use_constructor:
6343 if (TREE_CODE (init) != TREE_VEC)
6344 init = store_init_value (decl, init);
6348 /* We must hide the initializer so that expand_decl
6349 won't try to do something it does not understand. */
6350 init = obscure_complex_init (decl, init);
6352 else if (DECL_EXTERNAL (decl))
6354 else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
6355 && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
6358 while (TREE_CODE (ctype) == ARRAY_TYPE)
6359 ctype = TREE_TYPE (ctype);
6360 if (! TYPE_NEEDS_CONSTRUCTING (ctype))
6362 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
6363 cp_error ("structure `%D' with uninitialized const members", decl);
6364 if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
6365 cp_error ("structure `%D' with uninitialized reference members",
6369 if (TREE_CODE (decl) == VAR_DECL
6370 && !DECL_INITIAL (decl)
6371 && !TYPE_NEEDS_CONSTRUCTING (type)
6372 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
6373 cp_error ("uninitialized const `%D'", decl);
6375 if (TYPE_SIZE (type) != NULL_TREE
6376 && TYPE_NEEDS_CONSTRUCTING (type))
6377 init = obscure_complex_init (decl, NULL_TREE);
6379 else if (TREE_CODE (decl) == VAR_DECL
6380 && TREE_CODE (type) != REFERENCE_TYPE
6381 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
6383 /* ``Unless explicitly declared extern, a const object does not have
6384 external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
6385 However, if it's `const int foo = 1; const int foo;', don't complain
6386 about the second decl, since it does have an initializer before.
6387 We deliberately don't complain about arrays, because they're
6388 supposed to be initialized by a constructor. */
6389 if (! DECL_INITIAL (decl)
6390 && TREE_CODE (type) != ARRAY_TYPE
6391 && (!pedantic || !current_class_type))
6392 cp_error ("uninitialized const `%#D'", decl);
6395 /* For top-level declaration, the initial value was read in
6396 the temporary obstack. MAXINDEX, rtl, etc. to be made below
6397 must go in the permanent obstack; but don't discard the
6398 temporary data yet. */
6400 if (toplevel_bindings_p () && temporary)
6401 end_temporary_allocation ();
6403 /* Deduce size of array from initialization, if not already known. */
6405 if (TREE_CODE (type) == ARRAY_TYPE
6406 && TYPE_DOMAIN (type) == NULL_TREE
6407 && TREE_CODE (decl) != TYPE_DECL)
6410 = (TREE_STATIC (decl)
6411 /* Even if pedantic, an external linkage array
6412 may have incomplete type at first. */
6413 ? pedantic && ! DECL_EXTERNAL (decl)
6414 : !DECL_EXTERNAL (decl));
6415 tree initializer = init ? init : DECL_INITIAL (decl);
6416 int failure = complete_array_type (type, initializer, do_default);
6419 cp_error ("initializer fails to determine size of `%D'", decl);
6424 cp_error ("array size missing in `%D'", decl);
6425 /* If a `static' var's size isn't known, make it extern as
6426 well as static, so it does not get allocated. If it's not
6427 `static', then don't mark it extern; finish_incomplete_decl
6428 will give it a default size and it will get allocated. */
6429 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
6430 DECL_EXTERNAL (decl) = 1;
6433 if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
6434 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6436 cp_error ("zero-size array `%D'", decl);
6438 layout_decl (decl, 0);
6441 if (TREE_CODE (decl) == VAR_DECL)
6443 if (DECL_SIZE (decl) == NULL_TREE
6444 && TYPE_SIZE (complete_type (TREE_TYPE (decl))) != NULL_TREE)
6445 layout_decl (decl, 0);
6447 if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
6449 /* A static variable with an incomplete type:
6450 that is an error if it is initialized.
6451 Otherwise, let it through, but if it is not `extern'
6452 then it may cause an error message later. */
6453 if (DECL_INITIAL (decl) != NULL_TREE)
6454 cp_error ("storage size of `%D' isn't known", decl);
6457 else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
6459 /* An automatic variable with an incomplete type: that is an error.
6460 Don't talk about array types here, since we took care of that
6461 message in grokdeclarator. */
6462 cp_error ("storage size of `%D' isn't known", decl);
6463 TREE_TYPE (decl) = error_mark_node;
6465 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
6466 /* Let debugger know it should output info for this type. */
6467 note_debug_info_needed (ttype);
6469 if (TREE_STATIC (decl) && DECL_CONTEXT (decl)
6470 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
6471 note_debug_info_needed (DECL_CONTEXT (decl));
6473 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
6474 && DECL_SIZE (decl) != NULL_TREE
6475 && ! TREE_CONSTANT (DECL_SIZE (decl)))
6477 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
6478 constant_expression_warning (DECL_SIZE (decl));
6480 cp_error ("storage size of `%D' isn't constant", decl);
6483 if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
6485 int yes = suspend_momentary ();
6486 cleanup = maybe_build_cleanup (decl);
6487 resume_momentary (yes);
6490 /* PARM_DECLs get cleanups, too. */
6491 else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
6494 end_temporary_allocation ();
6495 cleanup = maybe_build_cleanup (decl);
6497 resume_temporary_allocation ();
6500 /* Output the assembler code and/or RTL code for variables and functions,
6501 unless the type is an undefined structure or union.
6502 If not, it will get done when the type is completed. */
6504 was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
6506 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
6507 || TREE_CODE (decl) == RESULT_DECL)
6509 /* ??? FIXME: What about nested classes? */
6510 int toplev = toplevel_bindings_p () || pseudo_global_level_p ();
6512 = ((flag_traditional
6513 || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
6514 && allocation_temporary_p ());
6517 end_temporary_allocation ();
6519 if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
6520 make_decl_rtl (decl, NULL_PTR, toplev);
6521 else if (TREE_CODE (decl) == VAR_DECL
6522 && TREE_READONLY (decl)
6523 && DECL_INITIAL (decl) != NULL_TREE
6524 && DECL_INITIAL (decl) != error_mark_node
6525 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
6527 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
6530 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
6533 && TREE_STATIC (decl)
6534 && ! TREE_SIDE_EFFECTS (decl)
6535 && ! TREE_PUBLIC (decl)
6536 && ! DECL_EXTERNAL (decl)
6537 && ! TYPE_NEEDS_DESTRUCTOR (type)
6538 && DECL_MODE (decl) != BLKmode)
6540 /* If this variable is really a constant, then fill its DECL_RTL
6541 slot with something which won't take up storage.
6542 If something later should take its address, we can always give
6543 it legitimate RTL at that time. */
6544 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
6545 store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
6546 TREE_ASM_WRITTEN (decl) = 1;
6548 else if (toplev && ! TREE_PUBLIC (decl))
6550 /* If this is a static const, change its apparent linkage
6551 if it belongs to a #pragma interface. */
6552 if (!interface_unknown)
6554 TREE_PUBLIC (decl) = 1;
6555 DECL_EXTERNAL (decl) = interface_only;
6557 make_decl_rtl (decl, asmspec, toplev);
6560 rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
6562 else if (TREE_CODE (decl) == VAR_DECL
6563 && DECL_LANG_SPECIFIC (decl)
6564 && DECL_IN_AGGR_P (decl))
6566 if (TREE_STATIC (decl))
6568 if (init == NULL_TREE
6569 #ifdef DEFAULT_STATIC_DEFS
6570 /* If this code is dead, then users must
6571 explicitly declare static member variables
6572 outside the class def'n as well. */
6573 && TYPE_NEEDS_CONSTRUCTING (type)
6577 DECL_EXTERNAL (decl) = 1;
6578 make_decl_rtl (decl, asmspec, 1);
6581 rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
6584 /* Just a constant field. Should not need any rtl. */
6588 rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
6591 resume_temporary_allocation ();
6593 if (type != error_mark_node
6594 && TYPE_LANG_SPECIFIC (type)
6595 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
6596 abstract_virtuals_error (decl, type);
6597 else if ((TREE_CODE (type) == FUNCTION_TYPE
6598 || TREE_CODE (type) == METHOD_TYPE)
6599 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6600 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
6601 abstract_virtuals_error (decl, TREE_TYPE (type));
6603 if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
6604 signature_error (decl, type);
6605 else if ((TREE_CODE (type) == FUNCTION_TYPE
6606 || TREE_CODE (type) == METHOD_TYPE)
6607 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6608 && IS_SIGNATURE (TREE_TYPE (type)))
6609 signature_error (decl, TREE_TYPE (type));
6611 if (TREE_CODE (decl) == FUNCTION_DECL)
6613 else if (DECL_EXTERNAL (decl))
6616 DECL_INITIAL (decl) = init;
6618 else if (TREE_STATIC (decl) && type != error_mark_node)
6620 /* Cleanups for static variables are handled by `finish_file'. */
6621 if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE
6622 || TYPE_NEEDS_DESTRUCTOR (type))
6623 expand_static_init (decl, init);
6627 extern int temp_slot_level;
6628 extern int target_temp_slot_level;
6629 tree old_cleanups = cleanups_this_call;
6630 int old_temp_level = target_temp_slot_level;
6632 /* This is a declared decl which must live until the
6633 end of the binding contour. It may need a cleanup. */
6635 /* Recompute the RTL of a local array now
6636 if it used to be an incomplete type. */
6637 if (was_incomplete && ! TREE_STATIC (decl))
6639 /* If we used it already as memory, it must stay in memory. */
6640 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
6641 /* If it's still incomplete now, no init will save it. */
6642 if (DECL_SIZE (decl) == NULL_TREE)
6643 DECL_INITIAL (decl) = NULL_TREE;
6646 else if (! TREE_ASM_WRITTEN (decl)
6647 && (TYPE_SIZE (type) != NULL_TREE
6648 || TREE_CODE (type) == ARRAY_TYPE))
6650 /* Do this here, because we did not expand this decl's
6651 rtl in start_decl. */
6652 if (DECL_RTL (decl) == NULL_RTX)
6656 /* XXX: Why don't we use decl here? */
6657 /* Ans: Because it was already expanded? */
6658 if (! cp_expand_decl_cleanup (NULL_TREE, cleanup))
6659 cp_error ("parser lost in parsing declaration of `%D'",
6661 /* Cleanup used up here. */
6662 cleanup = NULL_TREE;
6666 if (current_binding_level->is_for_scope)
6668 struct binding_level *outer = current_binding_level->level_chain;
6670 /* Check to see if the same name is already bound at
6671 the outer level, either because it was directly declared,
6672 or because a dead for-decl got preserved. In either case,
6673 the code would not have been valid under the traditional
6674 scope rules, so clear is_for_scope for the
6675 current_binding_level.
6677 Otherwise, we need to preserve the temp slot for decl
6678 to last into the outer binding level. */
6680 int handling_dead_for_vars = 0;
6681 tree link = outer->names;
6682 for (; ; link = TREE_CHAIN (link))
6684 if (link == NULL && handling_dead_for_vars == 0)
6686 link = outer->dead_vars_from_for;
6687 handling_dead_for_vars = 1;
6691 if (DECL_IN_MEMORY_P (decl))
6692 preserve_temp_slots (DECL_RTL (decl));
6695 if (DECL_NAME (link) == DECL_NAME (decl))
6697 if (handling_dead_for_vars)
6700 = purpose_member (DECL_NAME (decl),
6701 current_binding_level->shadowed);
6702 if (shadowing && TREE_VALUE (shadowing) == link)
6703 TREE_VALUE (shadowing)
6704 = DECL_SHADOWED_FOR_VAR (link);
6706 current_binding_level->is_for_scope = 0;
6714 target_temp_slot_level = temp_slot_level;
6716 if (DECL_SIZE (decl) && type != error_mark_node)
6718 /* Compute and store the initial value. */
6719 expand_decl_init (decl);
6721 if (init || TYPE_NEEDS_CONSTRUCTING (type))
6723 emit_line_note (DECL_SOURCE_FILE (decl),
6724 DECL_SOURCE_LINE (decl));
6725 expand_aggr_init (decl, init, 0, flags);
6728 /* Set this to 0 so we can tell whether an aggregate which
6729 was initialized was ever used. Don't do this if it has a
6730 destructor, so we don't complain about the 'resource
6731 allocation is initialization' idiom. */
6732 if (TYPE_NEEDS_CONSTRUCTING (type)
6733 && cleanup == NULL_TREE
6734 && DECL_NAME (decl))
6735 TREE_USED (decl) = 0;
6737 /* Store the cleanup, if there was one. */
6740 if (! cp_expand_decl_cleanup (decl, cleanup))
6741 cp_error ("parser lost in parsing declaration of `%D'",
6745 /* Cleanup any temporaries needed for the initial value. */
6746 expand_cleanups_to (old_cleanups);
6749 target_temp_slot_level = old_temp_level;
6753 /* Undo call to `pushclass' that was done in `start_decl'
6754 due to initialization of qualified member variable.
6755 I.e., Foo::x = 10; */
6757 tree context = DECL_REAL_CONTEXT (decl);
6759 && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
6760 && (TREE_CODE (decl) == VAR_DECL
6761 /* We also have a pushclass done that we need to undo here
6762 if we're at top level and declare a method. */
6763 || TREE_CODE (decl) == FUNCTION_DECL)
6764 /* If size hasn't been set, we're still defining it,
6765 and therefore inside the class body; don't pop
6766 the binding level.. */
6767 && TYPE_SIZE (context) != NULL_TREE
6768 && context == current_class_type)
6775 /* If requested, warn about definitions of large data objects. */
6777 if (warn_larger_than
6778 && ! current_template_parms
6779 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
6780 && !DECL_EXTERNAL (decl))
6782 register tree decl_size = DECL_SIZE (decl);
6784 if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
6786 unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT;
6788 if (units > larger_than_size)
6789 warning_with_decl (decl, "size of `%s' is %u bytes", units);
6795 /* Resume permanent allocation, if not within a function. */
6796 /* The corresponding push_obstacks_nochange is in start_decl,
6797 start_method, groktypename, and in grokfield. */
6802 TREE_READONLY (decl) = 1;
6805 /* This is here for a midend callback from c-common.c */
6807 finish_decl (decl, init, asmspec_tree)
6811 cp_finish_decl (decl, init, asmspec_tree, 1, 0);
6815 expand_static_init (decl, init)
6819 tree oldstatic = value_member (decl, static_aggregates);
6823 if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
6824 cp_error ("multiple initializations given for `%D'", decl);
6826 else if (! toplevel_bindings_p () && ! pseudo_global_level_p ())
6828 /* Emit code to perform this initialization but once. */
6831 extern int temp_slot_level;
6832 extern int target_temp_slot_level;
6836 /* Remember this information until end of file. */
6837 push_obstacks (&permanent_obstack, &permanent_obstack);
6839 /* Emit code to perform this initialization but once. */
6840 temp = get_temp_name (integer_type_node, 1);
6841 rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
6842 expand_start_cond (build_binary_op (EQ_EXPR, temp,
6843 integer_zero_node, 1), 0);
6844 old_cleanups = cleanups_this_call;
6845 old_temp_level = target_temp_slot_level;
6848 target_temp_slot_level = temp_slot_level;
6850 expand_assignment (temp, integer_one_node, 0, 0);
6851 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
6852 || (init && TREE_CODE (init) == TREE_LIST))
6854 expand_aggr_init (decl, init, 0, 0);
6855 do_pending_stack_adjust ();
6858 expand_assignment (decl, init, 0, 0);
6860 /* Cleanup any temporaries needed for the initial value. */
6861 expand_cleanups_to (old_cleanups);
6864 target_temp_slot_level = old_temp_level;
6866 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
6868 tree cleanup, fcall;
6869 static tree Atexit = 0;
6872 tree atexit_fndecl, PFV, pfvlist;
6873 /* Remember this information until end of file. */
6874 push_obstacks (&permanent_obstack, &permanent_obstack);
6875 PFV = build_pointer_type (build_function_type
6876 (void_type_node, void_list_node));
6878 pfvlist = tree_cons (NULL_TREE, PFV, void_list_node);
6880 push_lang_context (lang_name_c);
6882 builtin_function ("atexit",
6883 build_function_type (void_type_node,
6885 NOT_BUILT_IN, NULL_PTR);
6886 assemble_external (atexit_fndecl);
6887 Atexit = default_conversion (atexit_fndecl);
6888 pop_lang_context ();
6892 cleanup = start_anon_func ();
6893 expand_expr_stmt (build_cleanup (decl));
6895 mark_addressable (cleanup);
6896 cleanup = build_unary_op (ADDR_EXPR, cleanup, 0);
6897 fcall = build_function_call (Atexit, tree_cons (NULL_TREE, cleanup, NULL_TREE));
6898 expand_expr_stmt (fcall);
6902 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
6904 static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
6905 TREE_STATIC (static_aggregates) = 1;
6908 /* Resume old (possibly temporary) allocation. */
6913 /* This code takes into account memory allocation
6914 policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
6915 does not hold for this object, then we must make permanent
6916 the storage currently in the temporary obstack. */
6917 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6918 preserve_initializer ();
6919 static_aggregates = perm_tree_cons (init, decl, static_aggregates);
6923 /* Make TYPE a complete type based on INITIAL_VALUE.
6924 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
6925 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
6928 complete_array_type (type, initial_value, do_default)
6929 tree type, initial_value;
6932 register tree maxindex = NULL_TREE;
6937 /* Note MAXINDEX is really the maximum index,
6938 one less than the size. */
6939 if (TREE_CODE (initial_value) == STRING_CST)
6942 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
6943 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
6946 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
6948 tree elts = CONSTRUCTOR_ELTS (initial_value);
6949 maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node);
6950 for (; elts; elts = TREE_CHAIN (elts))
6952 if (TREE_PURPOSE (elts))
6953 maxindex = TREE_PURPOSE (elts);
6955 maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node);
6957 maxindex = copy_node (maxindex);
6961 /* Make an error message unless that happened already. */
6962 if (initial_value != error_mark_node)
6965 /* Prevent further error messages. */
6966 maxindex = build_int_2 (0, 0);
6973 maxindex = build_int_2 (0, 0);
6981 TYPE_DOMAIN (type) = build_index_type (maxindex);
6982 if (! TREE_TYPE (maxindex))
6983 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
6985 itype = TREE_TYPE (initial_value);
6988 if (itype && !TYPE_DOMAIN (itype))
6989 TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
6990 /* The type of the main variant should never be used for arrays
6991 of different sizes. It should only ever be completed with the
6992 size of the array. */
6993 if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)))
6994 TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type);
6997 /* Lay out the type now that we can get the real answer. */
7004 /* Return zero if something is declared to be a member of type
7005 CTYPE when in the context of CUR_TYPE. STRING is the error
7006 message to print in that case. Otherwise, quietly return 1. */
7008 member_function_or_else (ctype, cur_type, string)
7009 tree ctype, cur_type;
7012 if (ctype && ctype != cur_type)
7014 error (string, TYPE_NAME_STRING (ctype));
7020 /* Subroutine of `grokdeclarator'. */
7022 /* Generate errors possibly applicable for a given set of specifiers.
7023 This is for ARM $7.1.2. */
7025 bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
7028 int virtualp, quals, friendp, raises, inlinep;
7031 cp_error ("`%D' declared as a `virtual' %s", object, type);
7033 cp_error ("`%D' declared as an `inline' %s", object, type);
7035 cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
7038 cp_error_at ("invalid friend declaration", object);
7040 cp_error_at ("invalid exception specifications", object);
7043 /* CTYPE is class type, or null if non-class.
7044 TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
7046 DECLARATOR is the function's name.
7047 VIRTUALP is truthvalue of whether the function is virtual or not.
7048 FLAGS are to be passed through to `grokclassfn'.
7049 QUALS are qualifiers indicating whether the function is `const'
7051 RAISES is a list of exceptions that this function can raise.
7052 CHECK is 1 if we must find this method in CTYPE, 0 if we should
7053 not look, and -1 if we should not call `grokclassfn' at all. */
7055 grokfndecl (ctype, type, declarator, virtualp, flags, quals,
7056 raises, attrlist, check, publicp, inlinep, funcdef_flag)
7060 enum overload_flags flags;
7061 tree quals, raises, attrlist;
7062 int check, publicp, inlinep, funcdef_flag;
7065 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
7068 cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
7069 ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
7075 type = build_exception_variant (type, raises);
7076 raises = TYPE_RAISES_EXCEPTIONS (type);
7078 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
7079 /* propagate volatile out from type to decl */
7080 if (TYPE_VOLATILE (type))
7081 TREE_THIS_VOLATILE (decl) = 1;
7083 /* Should probably propagate const out from type to decl I bet (mrs). */
7086 DECL_STATIC_FUNCTION_P (decl) = 1;
7087 DECL_CONTEXT (decl) = ctype;
7088 DECL_CLASS_CONTEXT (decl) = ctype;
7091 /* All function decls start out public; we'll fix their linkage later (at
7092 definition or EOF) if appropriate. */
7093 TREE_PUBLIC (decl) = 1;
7095 if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main"))
7098 error ("cannot declare `main' to be inline");
7100 error ("cannot declare `main' to be static");
7106 DECL_C_STATIC (decl) = 1;
7109 DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1;
7111 DECL_EXTERNAL (decl) = 1;
7112 if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
7114 cp_error ("%smember function `%D' cannot have `%T' method qualifier",
7115 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
7119 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
7120 grok_op_properties (decl, virtualp, check < 0);
7122 /* Caller will do the rest of this. */
7126 if (check && funcdef_flag)
7127 DECL_INITIAL (decl) = error_mark_node;
7129 if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
7132 /* Just handle constructors here. We could do this
7133 inside the following if stmt, but I think
7134 that the code is more legible by breaking this
7135 case out. See comments below for what each of
7136 the following calls is supposed to do. */
7137 DECL_CONSTRUCTOR_P (decl) = 1;
7139 grokclassfn (ctype, declarator, decl, flags, quals);
7142 tmp = check_classfn (ctype, decl);
7143 if (tmp && duplicate_decls (decl, tmp))
7146 if (! grok_ctor_properties (ctype, decl))
7149 if (check == 0 && ! current_function_decl)
7151 /* FIXME: this should only need to look at
7152 IDENTIFIER_GLOBAL_VALUE. */
7153 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
7154 if (tmp == NULL_TREE)
7155 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
7156 else if (TREE_CODE (tmp) != TREE_CODE (decl))
7157 cp_error ("inconsistent declarations for `%D'", decl);
7160 duplicate_decls (decl, tmp);
7162 /* avoid creating circularities. */
7163 DECL_CHAIN (decl) = NULL_TREE;
7165 make_decl_rtl (decl, NULL_PTR, 1);
7172 /* Function gets the ugly name, field gets the nice one.
7173 This call may change the type of the function (because
7174 of default parameters)! */
7175 if (ctype != NULL_TREE)
7176 grokclassfn (ctype, cname, decl, flags, quals);
7178 if (ctype != NULL_TREE && check)
7180 tmp = check_classfn (ctype, decl);
7181 if (tmp && DECL_STATIC_FUNCTION_P (tmp)
7182 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
7184 /* Remove the `this' parm added by grokclassfn.
7185 XXX Isn't this done in start_function, too? */
7186 revert_static_member_fn (&decl, NULL, NULL);
7187 last_function_parms = TREE_CHAIN (last_function_parms);
7189 if (tmp && duplicate_decls (decl, tmp))
7193 if (ctype == NULL_TREE || check)
7196 /* Now install the declaration of this function so that others may
7197 find it (esp. its DECL_FRIENDLIST). Don't do this for local class
7199 if (! current_function_decl)
7201 /* FIXME: this should only need to look at
7202 IDENTIFIER_GLOBAL_VALUE. */
7203 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
7204 if (tmp == NULL_TREE)
7205 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
7206 else if (TREE_CODE (tmp) != TREE_CODE (decl))
7207 cp_error ("inconsistent declarations for `%D'", decl);
7210 duplicate_decls (decl, tmp);
7212 /* avoid creating circularities. */
7213 DECL_CHAIN (decl) = NULL_TREE;
7217 cplus_decl_attributes (decl, TREE_PURPOSE (attrlist),
7218 TREE_VALUE (attrlist));
7219 make_decl_rtl (decl, NULL_PTR, 1);
7223 DECL_VIRTUAL_P (decl) = 1;
7224 if (DECL_VINDEX (decl) == NULL_TREE)
7225 DECL_VINDEX (decl) = error_mark_node;
7226 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
7233 grokvardecl (type, declarator, specbits, initialized, constp)
7236 RID_BIT_TYPE specbits;
7242 if (TREE_CODE (type) == OFFSET_TYPE)
7244 /* If you declare a static member so that it
7245 can be initialized, the code will reach here. */
7246 tree basetype = TYPE_OFFSET_BASETYPE (type);
7247 type = TREE_TYPE (type);
7248 decl = build_lang_field_decl (VAR_DECL, declarator, type);
7249 DECL_CONTEXT (decl) = basetype;
7250 DECL_CLASS_CONTEXT (decl) = basetype;
7251 DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator);
7254 decl = build_decl (VAR_DECL, declarator, type);
7256 DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl));
7258 if (RIDBIT_SETP (RID_EXTERN, specbits))
7260 DECL_THIS_EXTERN (decl) = 1;
7261 DECL_EXTERNAL (decl) = !initialized;
7264 /* In class context, static means one per class,
7265 public access, and static storage. */
7266 if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
7267 && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
7269 TREE_PUBLIC (decl) = 1;
7270 TREE_STATIC (decl) = 1;
7271 DECL_EXTERNAL (decl) = 0;
7273 /* At top level, either `static' or no s.c. makes a definition
7274 (perhaps tentative), and absence of `static' makes it public. */
7275 else if (toplevel_bindings_p ())
7277 TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits)
7278 && (DECL_THIS_EXTERN (decl) || ! constp));
7279 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
7281 /* Not at top level, only `static' makes a static definition. */
7284 TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
7285 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
7290 /* Create a canonical pointer to member function type. */
7293 build_ptrmemfunc_type (type)
7300 /* If a canonical type already exists for this type, use it. We use
7301 this method instead of type_hash_canon, because it only does a
7302 simple equality check on the list of field members. */
7304 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
7307 push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
7309 u = make_lang_type (UNION_TYPE);
7310 IS_AGGR_TYPE (u) = 0;
7311 fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
7312 fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier,
7314 finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
7315 TYPE_NAME (u) = NULL_TREE;
7317 t = make_lang_type (RECORD_TYPE);
7319 /* Let the front-end know this is a pointer to member function. */
7320 TYPE_PTRMEMFUNC_FLAG (t) = 1;
7321 /* and not really an aggregate. */
7322 IS_AGGR_TYPE (t) = 0;
7324 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
7326 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
7328 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
7329 finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
7333 /* Zap out the name so that the back-end will give us the debugging
7334 information for this anonymous RECORD_TYPE. */
7335 TYPE_NAME (t) = NULL_TREE;
7337 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
7339 /* Seems to be wanted. */
7340 CLASSTYPE_GOT_SEMICOLON (t) = 1;
7344 /* Given declspecs and a declarator,
7345 determine the name and type of the object declared
7346 and construct a ..._DECL node for it.
7347 (In one case we can return a ..._TYPE node instead.
7348 For invalid input we sometimes return 0.)
7350 DECLSPECS is a chain of tree_list nodes whose value fields
7351 are the storage classes and type specifiers.
7353 DECL_CONTEXT says which syntactic context this declaration is in:
7354 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
7355 FUNCDEF for a function definition. Like NORMAL but a few different
7356 error messages in each case. Return value may be zero meaning
7357 this definition is too screwy to try to parse.
7358 MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
7359 handle member functions (which have FIELD context).
7360 Return value may be zero meaning this definition is too screwy to
7362 PARM for a parameter declaration (either within a function prototype
7363 or before a function body). Make a PARM_DECL, or return void_type_node.
7364 CATCHPARM for a parameter declaration before a catch clause.
7365 TYPENAME if for a typename (in a cast or sizeof).
7366 Don't make a DECL node; just return the ..._TYPE node.
7367 FIELD for a struct or union field; make a FIELD_DECL.
7368 BITFIELD for a field with specified width.
7369 INITIALIZED is 1 if the decl has an initializer.
7371 In the TYPENAME case, DECLARATOR is really an absolute declarator.
7372 It may also be so in the PARM case, for a prototype where the
7373 argument type is specified but not the name.
7375 This function is where the complicated C meanings of `static'
7376 and `extern' are interpreted.
7378 For C++, if there is any monkey business to do, the function which
7379 calls this one must do it, i.e., prepending instance variables,
7380 renaming overloaded function names, etc.
7382 Note that for this C++, it is an error to define a method within a class
7383 which does not belong to that class.
7385 Except in the case where SCOPE_REFs are implicitly known (such as
7386 methods within a class being redundantly qualified),
7387 declarations which involve SCOPE_REFs are returned as SCOPE_REFs
7388 (class_name::decl_name). The caller must also deal with this.
7390 If a constructor or destructor is seen, and the context is FIELD,
7391 then the type gains the attribute TREE_HAS_x. If such a declaration
7392 is erroneous, NULL_TREE is returned.
7394 QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
7395 function, these are the qualifiers to give to the `this' pointer.
7397 May return void_type_node if the declarator turned out to be a friend.
7398 See grokfield for details. */
7400 enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
7403 grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrlist)
7406 enum decl_context decl_context;
7408 tree raises, attrlist;
7410 RID_BIT_TYPE specbits;
7413 tree type = NULL_TREE;
7417 int virtualp, explicitp, friendp, inlinep, staticp;
7418 int explicit_int = 0;
7419 int explicit_char = 0;
7420 int opaque_typedef = 0;
7421 tree typedef_decl = NULL_TREE;
7423 tree typedef_type = NULL_TREE;
7424 int funcdef_flag = 0;
7425 enum tree_code innermost_code = ERROR_MARK;
7428 /* See the code below that used this. */
7429 tree decl_machine_attr = NULL_TREE;
7431 /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
7432 All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
7433 tree init = NULL_TREE;
7435 /* Keep track of what sort of function is being processed
7436 so that we can warn about default return values, or explicit
7437 return values which do not match prescribed defaults. */
7438 enum return_types return_type = return_normal;
7440 tree dname = NULL_TREE;
7441 tree ctype = current_class_type;
7442 tree ctor_return_type = NULL_TREE;
7443 enum overload_flags flags = NO_SPECIAL;
7444 tree quals = NULL_TREE;
7446 RIDBIT_RESET_ALL (specbits);
7447 if (decl_context == FUNCDEF)
7448 funcdef_flag = 1, decl_context = NORMAL;
7449 else if (decl_context == MEMFUNCDEF)
7450 funcdef_flag = -1, decl_context = FIELD;
7451 else if (decl_context == BITFIELD)
7452 bitfield = 1, decl_context = FIELD;
7454 if (flag_traditional && allocation_temporary_p ())
7455 end_temporary_allocation ();
7457 /* Look inside a declarator for the name being declared
7458 and get it as a string, for an error message. */
7460 tree *next = &declarator;
7464 while (next && *next)
7467 switch (TREE_CODE (decl))
7471 next = &TREE_OPERAND (decl, 0);
7474 case BIT_NOT_EXPR: /* for C++ destructors! */
7476 tree name = TREE_OPERAND (decl, 0);
7477 tree rename = NULL_TREE;
7479 my_friendly_assert (flags == NO_SPECIAL, 152);
7481 return_type = return_dtor;
7482 if (TREE_CODE (name) == TYPE_DECL)
7483 TREE_OPERAND (decl, 0) = name = constructor_name (name);
7484 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
7485 if (ctype == NULL_TREE)
7487 if (current_class_type == NULL_TREE)
7489 error ("destructors must be member functions");
7494 tree t = constructor_name (current_class_name);
7501 tree t = constructor_name (ctype);
7508 cp_error ("destructor `%T' must match class name `%T'",
7510 TREE_OPERAND (decl, 0) = rename;
7516 case ADDR_EXPR: /* C++ reference declaration */
7521 innermost_code = TREE_CODE (decl);
7522 next = &TREE_OPERAND (decl, 0);
7526 if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
7528 /* This is actually a variable declaration using constructor
7529 syntax. We need to call start_decl and cp_finish_decl so we
7530 can get the variable initialized... */
7532 *next = TREE_OPERAND (decl, 0);
7533 init = TREE_OPERAND (decl, 1);
7535 decl = start_decl (declarator, declspecs, 1, NULL_TREE);
7536 finish_decl (decl, init, NULL_TREE);
7539 innermost_code = TREE_CODE (decl);
7540 if (decl_context == FIELD && ctype == NULL_TREE)
7541 ctype = current_class_type;
7543 && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL
7544 && ((DECL_NAME (TREE_OPERAND (decl, 0))
7545 == constructor_name_full (ctype))
7546 || (DECL_NAME (TREE_OPERAND (decl, 0))
7547 == constructor_name (ctype)))))
7548 TREE_OPERAND (decl, 0) = constructor_name (ctype);
7549 next = &TREE_OPERAND (decl, 0);
7551 if (ctype != NULL_TREE
7552 && decl != NULL_TREE && flags != DTOR_FLAG
7553 && decl == constructor_name (ctype))
7555 return_type = return_ctor;
7556 ctor_return_type = ctype;
7561 case IDENTIFIER_NODE:
7567 cp_error ("declarator-id missing; using reserved word `%D'",
7569 name = IDENTIFIER_POINTER (dname);
7571 if (! IDENTIFIER_OPNAME_P (dname)
7572 /* Linux headers use '__op'. Arrgh. */
7573 || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))
7574 name = IDENTIFIER_POINTER (dname);
7577 if (IDENTIFIER_TYPENAME_P (dname))
7579 my_friendly_assert (flags == NO_SPECIAL, 154);
7580 flags = TYPENAME_FLAG;
7581 ctor_return_type = TREE_TYPE (dname);
7582 return_type = return_conversion;
7584 name = operator_name_string (dname);
7591 /* Perform error checking, and decide on a ctype. */
7592 tree cname = TREE_OPERAND (decl, 0);
7593 if (cname == NULL_TREE)
7595 else if (! is_aggr_type (cname, 1))
7596 TREE_OPERAND (decl, 0) = NULL_TREE;
7597 /* Must test TREE_OPERAND (decl, 1), in case user gives
7598 us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7599 else if (TREE_OPERAND (decl, 1)
7600 && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
7602 else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM)
7604 cp_error ("`%T::%D' is not a valid declarator", cname,
7605 TREE_OPERAND (decl, 1));
7606 cp_error (" perhaps you want `typename %T::%D' to make it a type",
7607 cname, TREE_OPERAND (decl, 1));
7608 return void_type_node;
7610 else if (ctype == NULL_TREE)
7612 else if (TREE_COMPLEXITY (decl) == current_class_depth)
7613 TREE_OPERAND (decl, 0) = ctype;
7616 if (! UNIQUELY_DERIVED_FROM_P (cname, ctype))
7618 cp_error ("type `%T' is not derived from type `%T'",
7620 TREE_OPERAND (decl, 0) = NULL_TREE;
7627 && TREE_OPERAND (decl, 1) == constructor_name_full (ctype))
7628 TREE_OPERAND (decl, 1) = constructor_name (ctype);
7629 next = &TREE_OPERAND (decl, 1);
7633 if (TREE_CODE (decl) == IDENTIFIER_NODE
7634 && constructor_name (ctype) == decl)
7636 return_type = return_ctor;
7637 ctor_return_type = ctype;
7639 else if (TREE_CODE (decl) == BIT_NOT_EXPR
7640 && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
7641 && (constructor_name (ctype) == TREE_OPERAND (decl, 0)
7642 || constructor_name_full (ctype) == TREE_OPERAND (decl, 0)))
7644 return_type = return_dtor;
7645 ctor_return_type = ctype;
7647 TREE_OPERAND (decl, 0) = constructor_name (ctype);
7648 next = &TREE_OPERAND (decl, 0);
7659 /* Parse error puts this typespec where
7660 a declarator should go. */
7661 cp_error ("`%T' specified as declarator-id", DECL_NAME (decl));
7662 if (TREE_TYPE (decl) == current_class_type)
7663 cp_error (" perhaps you want `%T' for a constructor",
7664 current_class_name);
7665 dname = DECL_NAME (decl);
7666 name = IDENTIFIER_POINTER (dname);
7668 /* Avoid giving two errors for this. */
7669 IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE;
7671 declspecs = temp_tree_cons (NULL_TREE, integer_type_node,
7678 cp_compiler_error ("`%D' as declarator", decl);
7679 return 0; /* We used to do a 155 abort here. */
7686 /* A function definition's declarator must have the form of
7687 a function declarator. */
7689 if (funcdef_flag && innermost_code != CALL_EXPR)
7692 if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
7693 && innermost_code != CALL_EXPR
7694 && ! (ctype && declspecs == NULL_TREE))
7696 cp_error ("declaration of `%D' as non-function", dname);
7697 return void_type_node;
7700 /* Anything declared one level down from the top level
7701 must be one of the parameters of a function
7702 (because the body is at least two levels down). */
7704 /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7705 by not allowing C++ class definitions to specify their parameters
7706 with xdecls (must be spec.d in the parmlist).
7708 Since we now wait to push a class scope until we are sure that
7709 we are in a legitimate method context, we must set oldcname
7710 explicitly (since current_class_name is not yet alive).
7712 We also want to avoid calling this a PARM if it is in a namespace. */
7714 if (decl_context == NORMAL && ! namespace_bindings_p ()
7715 && ! pseudo_global_level_p ())
7717 struct binding_level *b = current_binding_level;
7718 current_binding_level = b->level_chain;
7719 if (current_binding_level != 0 && toplevel_bindings_p ())
7720 decl_context = PARM;
7721 current_binding_level = b;
7724 /* Look through the decl specs and record which ones appear.
7725 Some typespecs are defined as built-in typenames.
7726 Others, the ones that are modifiers of other types,
7727 are represented by bits in SPECBITS: set the bits for
7728 the modifiers that appear. Storage class keywords are also in SPECBITS.
7730 If there is a typedef name or a type, store the type in TYPE.
7731 This includes builtin typedefs such as `int'.
7733 Set EXPLICIT_INT if the type is `int' or `char' and did not
7734 come from a user typedef.
7736 Set LONGLONG if `long' is mentioned twice.
7738 For C++, constructors and destructors have their own fast treatment. */
7740 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
7745 /* Certain parse errors slip through. For example,
7746 `int class;' is not caught by the parser. Try
7747 weakly to recover here. */
7748 if (TREE_CODE (spec) != TREE_LIST)
7751 id = TREE_VALUE (spec);
7753 if (TREE_CODE (id) == IDENTIFIER_NODE)
7755 if (id == ridpointers[(int) RID_INT]
7756 || id == ridpointers[(int) RID_CHAR]
7757 || id == ridpointers[(int) RID_BOOL]
7758 || id == ridpointers[(int) RID_WCHAR])
7762 if (id == ridpointers[(int) RID_BOOL])
7763 error ("`bool' is now a keyword");
7765 cp_error ("extraneous `%T' ignored", id);
7769 if (id == ridpointers[(int) RID_INT])
7771 else if (id == ridpointers[(int) RID_CHAR])
7773 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7777 /* C++ aggregate types. */
7778 if (IDENTIFIER_HAS_TYPE_VALUE (id))
7781 cp_error ("multiple declarations `%T' and `%T'", type, id);
7783 type = IDENTIFIER_TYPE_VALUE (id);
7787 for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++)
7789 if (ridpointers[i] == id)
7791 if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
7793 if (pedantic && ! in_system_header)
7794 pedwarn ("ANSI C++ does not support `long long'");
7796 error ("`long long long' is too long for GCC");
7800 else if (RIDBIT_SETP (i, specbits))
7801 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
7802 RIDBIT_SET (i, specbits);
7807 /* C++ aggregate types. */
7808 else if (TREE_CODE (id) == TYPE_DECL)
7811 cp_error ("multiple declarations `%T' and `%T'", type,
7815 type = TREE_TYPE (id);
7816 TREE_VALUE (spec) = type;
7821 error ("two or more data types in declaration of `%s'", name);
7822 else if (TREE_CODE (id) == IDENTIFIER_NODE)
7824 register tree t = lookup_name (id, 1);
7825 if (!t || TREE_CODE (t) != TYPE_DECL)
7826 error ("`%s' fails to be a typedef or built in type",
7827 IDENTIFIER_POINTER (id));
7830 type = TREE_TYPE (t);
7832 /* See the code below that used this. */
7833 decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
7838 else if (TREE_CODE (id) != ERROR_MARK)
7839 /* Can't change CLASS nodes into RECORD nodes here! */
7845 typedef_type = type;
7847 /* No type at all: default to `int', and set EXPLICIT_INT
7848 because it was not a user-defined typedef.
7849 Except when we have a `typedef' inside a signature, in
7850 which case the type defaults to `unknown type' and is
7851 instantiated when assigning to a signature pointer or ref. */
7853 if (type == NULL_TREE
7854 && (RIDBIT_SETP (RID_SIGNED, specbits)
7855 || RIDBIT_SETP (RID_UNSIGNED, specbits)
7856 || RIDBIT_SETP (RID_LONG, specbits)
7857 || RIDBIT_SETP (RID_SHORT, specbits)))
7859 /* These imply 'int'. */
7860 type = integer_type_node;
7864 if (type == NULL_TREE)
7867 if (return_type == return_dtor)
7868 type = void_type_node;
7869 else if (return_type == return_ctor)
7870 type = build_pointer_type (ctor_return_type);
7871 else if (return_type == return_conversion)
7872 type = ctor_return_type;
7873 else if (current_class_type
7874 && IS_SIGNATURE (current_class_type)
7875 && (RIDBIT_SETP (RID_TYPEDEF, specbits)
7876 || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7877 && (decl_context == FIELD || decl_context == NORMAL))
7881 type = copy_node (opaque_type_node);
7887 if (warn_return_type
7888 && return_type == return_normal)
7889 /* Save warning until we know what is really going on. */
7890 warn_about_return_type = 1;
7892 else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7893 pedwarn ("ANSI C++ forbids typedef which does not specify a type");
7894 else if (declspecs == NULL_TREE &&
7895 (innermost_code != CALL_EXPR || pedantic))
7896 cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
7898 type = integer_type_node;
7901 else if (return_type == return_dtor)
7903 error ("return type specification for destructor invalid");
7904 type = void_type_node;
7906 else if (return_type == return_ctor)
7908 error ("return type specification for constructor invalid");
7909 type = build_pointer_type (ctor_return_type);
7911 else if (return_type == return_conversion)
7913 if (comptypes (type, ctor_return_type, 1) == 0)
7914 cp_error ("operator `%T' declared to return `%T'",
7915 ctor_return_type, type);
7917 cp_pedwarn ("return type specified for `operator %T'",
7920 type = ctor_return_type;
7925 /* Now process the modifiers that were specified
7926 and check for invalid combinations. */
7928 /* Long double is a special combination. */
7930 if (RIDBIT_SETP (RID_LONG, specbits)
7931 && TYPE_MAIN_VARIANT (type) == double_type_node)
7933 RIDBIT_RESET (RID_LONG, specbits);
7934 type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
7935 TYPE_VOLATILE (type));
7938 /* Check all other uses of type modifiers. */
7940 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7941 || RIDBIT_SETP (RID_SIGNED, specbits)
7942 || RIDBIT_SETP (RID_LONG, specbits)
7943 || RIDBIT_SETP (RID_SHORT, specbits))
7947 if (TREE_CODE (type) == REAL_TYPE)
7948 error ("short, signed or unsigned invalid for `%s'", name);
7949 else if (TREE_CODE (type) != INTEGER_TYPE)
7950 error ("long, short, signed or unsigned invalid for `%s'", name);
7951 else if (RIDBIT_SETP (RID_LONG, specbits)
7952 && RIDBIT_SETP (RID_SHORT, specbits))
7953 error ("long and short specified together for `%s'", name);
7954 else if ((RIDBIT_SETP (RID_LONG, specbits)
7955 || RIDBIT_SETP (RID_SHORT, specbits))
7957 error ("long or short specified with char for `%s'", name);
7958 else if ((RIDBIT_SETP (RID_LONG, specbits)
7959 || RIDBIT_SETP (RID_SHORT, specbits))
7960 && TREE_CODE (type) == REAL_TYPE)
7961 error ("long or short specified with floating type for `%s'", name);
7962 else if (RIDBIT_SETP (RID_SIGNED, specbits)
7963 && RIDBIT_SETP (RID_UNSIGNED, specbits))
7964 error ("signed and unsigned given together for `%s'", name);
7968 if (!explicit_int && !explicit_char && pedantic)
7970 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
7972 if (flag_pedantic_errors)
7977 /* Discard the type modifiers if they are invalid. */
7980 RIDBIT_RESET (RID_UNSIGNED, specbits);
7981 RIDBIT_RESET (RID_SIGNED, specbits);
7982 RIDBIT_RESET (RID_LONG, specbits);
7983 RIDBIT_RESET (RID_SHORT, specbits);
7988 /* Decide whether an integer type is signed or not.
7989 Optionally treat bitfields as signed by default. */
7990 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7991 /* Traditionally, all bitfields are unsigned. */
7992 || (bitfield && flag_traditional)
7993 || (bitfield && ! flag_signed_bitfields
7994 && (explicit_int || explicit_char
7995 /* A typedef for plain `int' without `signed'
7996 can be controlled just like plain `int'. */
7997 || ! (typedef_decl != NULL_TREE
7998 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
7999 && TREE_CODE (type) != ENUMERAL_TYPE
8000 && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
8003 type = long_long_unsigned_type_node;
8004 else if (RIDBIT_SETP (RID_LONG, specbits))
8005 type = long_unsigned_type_node;
8006 else if (RIDBIT_SETP (RID_SHORT, specbits))
8007 type = short_unsigned_type_node;
8008 else if (type == char_type_node)
8009 type = unsigned_char_type_node;
8010 else if (typedef_decl)
8011 type = unsigned_type (type);
8013 type = unsigned_type_node;
8015 else if (RIDBIT_SETP (RID_SIGNED, specbits)
8016 && type == char_type_node)
8017 type = signed_char_type_node;
8019 type = long_long_integer_type_node;
8020 else if (RIDBIT_SETP (RID_LONG, specbits))
8021 type = long_integer_type_node;
8022 else if (RIDBIT_SETP (RID_SHORT, specbits))
8023 type = short_integer_type_node;
8025 /* Set CONSTP if this declaration is `const', whether by
8026 explicit specification or via a typedef.
8027 Likewise for VOLATILEP. */
8029 constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
8030 volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
8032 inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
8033 virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
8034 RIDBIT_RESET (RID_VIRTUAL, specbits);
8035 explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0;
8036 RIDBIT_RESET (RID_EXPLICIT, specbits);
8038 if (RIDBIT_SETP (RID_STATIC, specbits))
8039 staticp = 1 + (decl_context == FIELD);
8041 if (virtualp && staticp == 2)
8043 cp_error ("member `%D' cannot be declared both virtual and static",
8047 friendp = RIDBIT_SETP (RID_FRIEND, specbits);
8048 RIDBIT_RESET (RID_FRIEND, specbits);
8050 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8052 if (decl_context == PARM)
8054 error ("non-member `%s' cannot be declared `mutable'", name);
8055 RIDBIT_RESET (RID_MUTABLE, specbits);
8057 else if (friendp || decl_context == TYPENAME)
8059 error ("non-object member `%s' cannot be declared `mutable'", name);
8060 RIDBIT_RESET (RID_MUTABLE, specbits);
8064 /* Warn if two storage classes are given. Default to `auto'. */
8066 if (RIDBIT_ANY_SET (specbits))
8068 if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
8069 if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
8070 if (decl_context == PARM && nclasses > 0)
8071 error ("storage class specifiers invalid in parameter declarations");
8072 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8074 if (decl_context == PARM)
8075 error ("typedef declaration invalid in parameter declaration");
8078 if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
8079 if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
8082 /* Give error if `virtual' is used outside of class declaration. */
8084 && (current_class_name == NULL_TREE || decl_context != FIELD))
8086 error ("virtual outside class declaration");
8089 if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
8091 error ("only members can be declared mutable");
8092 RIDBIT_RESET (RID_MUTABLE, specbits);
8095 /* Static anonymous unions are dealt with here. */
8096 if (staticp && decl_context == TYPENAME
8097 && TREE_CODE (declspecs) == TREE_LIST
8098 && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
8099 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
8100 decl_context = FIELD;
8102 /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
8103 is used in a signature member function declaration. */
8104 if (decl_context == FIELD
8105 && IS_SIGNATURE (current_class_type)
8106 && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
8107 && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
8111 error ("`const' specified for signature member function `%s'", name);
8116 error ("`volatile' specified for signature member function `%s'",
8122 error ("`inline' specified for signature member function `%s'", name);
8123 /* Later, we'll make signature member functions inline. */
8128 error ("`friend' declaration in signature definition");
8133 error ("`virtual' specified for signature member function `%s'",
8135 /* Later, we'll make signature member functions virtual. */
8140 /* Warn about storage classes that are invalid for certain
8141 kinds of declarations (parameters, typenames, etc.). */
8144 error ("multiple storage classes in declaration of `%s'", name);
8145 else if (decl_context != NORMAL && nclasses > 0)
8147 if ((decl_context == PARM || decl_context == CATCHPARM)
8148 && (RIDBIT_SETP (RID_REGISTER, specbits)
8149 || RIDBIT_SETP (RID_AUTO, specbits)))
8151 else if (decl_context == FIELD
8152 && RIDBIT_SETP (RID_TYPEDEF, specbits))
8154 /* Processing a typedef declaration nested within a class type
8156 register tree scanner;
8157 register tree previous_declspec;
8161 error ("typedef declaration includes an initializer");
8163 /* To process a class-local typedef declaration, we descend down
8164 the chain of declspecs looking for the `typedef' spec. When
8165 we find it, we replace it with `static', and then recursively
8166 call `grokdeclarator' with the original declarator and with
8167 the newly adjusted declspecs. This call should return a
8168 FIELD_DECL node with the TREE_TYPE (and other parts) set
8169 appropriately. We can then just change the TREE_CODE on that
8170 from FIELD_DECL to TYPE_DECL and we're done. */
8172 for (previous_declspec = NULL_TREE, scanner = declspecs;
8174 previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
8176 if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
8180 if (previous_declspec)
8181 TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner);
8183 declspecs = TREE_CHAIN (scanner);
8185 declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC],
8188 /* In the recursive call to grokdeclarator we need to know
8189 whether we are working on a signature-local typedef. */
8190 if (IS_SIGNATURE (current_class_type))
8191 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
8194 grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE);
8196 if (previous_declspec)
8197 TREE_CHAIN (previous_declspec) = scanner;
8199 if (loc_typedecl != error_mark_node)
8201 register int i = sizeof (struct lang_decl_flags) / sizeof (int);
8204 TREE_SET_CODE (loc_typedecl, TYPE_DECL);
8205 /* This is the same field as DECL_ARGUMENTS, which is set for
8206 function typedefs by the above grokdeclarator. */
8207 DECL_NESTED_TYPENAME (loc_typedecl) = 0;
8209 pi = (int *) permalloc (sizeof (struct lang_decl_flags));
8212 DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
8215 if (IS_SIGNATURE (current_class_type))
8217 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
8218 if (loc_typedecl != error_mark_node && opaque_typedef)
8219 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
8222 return loc_typedecl;
8224 else if (decl_context == FIELD
8225 && (! IS_SIGNATURE (current_class_type)
8226 || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
8227 /* C++ allows static class elements */
8228 && RIDBIT_SETP (RID_STATIC, specbits))
8229 /* C++ also allows inlines and signed and unsigned elements,
8230 but in those cases we don't come in here. */
8234 if (decl_context == FIELD)
8236 tree tmp = NULL_TREE;
8237 register int op = 0;
8241 /* Avoid trying to get an operand off an identifier node. */
8242 if (TREE_CODE (declarator) == IDENTIFIER_NODE)
8245 tmp = TREE_OPERAND (declarator, 0);
8246 op = IDENTIFIER_OPNAME_P (tmp);
8248 error ("storage class specified for %s `%s'",
8249 IS_SIGNATURE (current_class_type)
8251 ? "signature member operator"
8252 : "signature member function")
8253 : (op ? "member operator" : "field"),
8254 op ? operator_name_string (tmp) : name);
8257 error (((decl_context == PARM || decl_context == CATCHPARM)
8258 ? "storage class specified for parameter `%s'"
8259 : "storage class specified for typename"), name);
8260 RIDBIT_RESET (RID_REGISTER, specbits);
8261 RIDBIT_RESET (RID_AUTO, specbits);
8262 RIDBIT_RESET (RID_EXTERN, specbits);
8264 if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
8266 RIDBIT_RESET (RID_STATIC, specbits);
8271 else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
8273 if (toplevel_bindings_p ())
8275 /* It's common practice (and completely valid) to have a const
8276 be initialized and declared extern. */
8278 warning ("`%s' initialized and declared `extern'", name);
8281 error ("`%s' has both `extern' and initializer", name);
8283 else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
8284 && ! toplevel_bindings_p ())
8285 error ("nested function `%s' declared `extern'", name);
8286 else if (toplevel_bindings_p ())
8288 if (RIDBIT_SETP (RID_AUTO, specbits))
8289 error ("top-level declaration of `%s' specifies `auto'", name);
8292 /* Now figure out the structure of the declarator proper.
8293 Descend through it, creating more complex types, until we reach
8294 the declared identifier (or NULL_TREE, in an absolute declarator). */
8296 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
8298 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
8299 an INDIRECT_REF (for *...),
8300 a CALL_EXPR (for ...(...)),
8301 an identifier (for the name being declared)
8302 or a null pointer (for the place in an absolute declarator
8303 where the name was omitted).
8304 For the last two cases, we have just exited the loop.
8306 For C++ it could also be
8307 a SCOPE_REF (for class :: ...). In this case, we have converted
8308 sensible names to types, and those are the values we use to
8309 qualify the member name.
8310 an ADDR_EXPR (for &...),
8311 a BIT_NOT_EXPR (for destructors)
8313 At this point, TYPE is the type of elements of an array,
8314 or for a function to return, or for a pointer to point to.
8315 After this sequence of ifs, TYPE is the type of the
8316 array or function or pointer, and DECLARATOR has had its
8317 outermost layer removed. */
8319 if (TREE_CODE (type) == ERROR_MARK)
8321 if (TREE_CODE (declarator) == SCOPE_REF)
8322 declarator = TREE_OPERAND (declarator, 1);
8324 declarator = TREE_OPERAND (declarator, 0);
8327 if (quals != NULL_TREE
8328 && (declarator == NULL_TREE
8329 || TREE_CODE (declarator) != SCOPE_REF))
8331 if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
8332 ctype = TYPE_METHOD_BASETYPE (type);
8333 if (ctype != NULL_TREE)
8335 tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
8336 ctype = grok_method_quals (ctype, dummy, quals);
8337 type = TREE_TYPE (dummy);
8341 switch (TREE_CODE (declarator))
8345 register tree itype = NULL_TREE;
8346 register tree size = TREE_OPERAND (declarator, 1);
8347 /* The index is a signed object `sizetype' bits wide. */
8348 tree index_type = signed_type (sizetype);
8350 declarator = TREE_OPERAND (declarator, 0);
8352 /* Check for some types that there cannot be arrays of. */
8354 if (TYPE_MAIN_VARIANT (type) == void_type_node)
8356 cp_error ("declaration of `%D' as array of voids", dname);
8357 type = error_mark_node;
8360 if (TREE_CODE (type) == FUNCTION_TYPE)
8362 cp_error ("declaration of `%D' as array of functions", dname);
8363 type = error_mark_node;
8366 /* ARM $8.4.3: Since you can't have a pointer to a reference,
8367 you can't have arrays of references. If we allowed them,
8368 then we'd be saying x[i] is valid for an array x, but
8369 then you'd have to ask: what does `*(x + i)' mean? */
8370 if (TREE_CODE (type) == REFERENCE_TYPE)
8372 if (decl_context == TYPENAME)
8373 cp_error ("cannot make arrays of references");
8375 cp_error ("declaration of `%D' as array of references",
8377 type = error_mark_node;
8380 if (TREE_CODE (type) == OFFSET_TYPE)
8382 cp_error ("declaration of `%D' as array of data members",
8384 type = error_mark_node;
8387 if (TREE_CODE (type) == METHOD_TYPE)
8389 cp_error ("declaration of `%D' as array of function members",
8391 type = error_mark_node;
8394 if (size == error_mark_node)
8395 type = error_mark_node;
8397 if (type == error_mark_node)
8402 /* Must suspend_momentary here because the index
8403 type may need to live until the end of the function.
8404 For example, it is used in the declaration of a
8405 variable which requires destructing at the end of
8406 the function; then build_vec_delete will need this
8408 int yes = suspend_momentary ();
8409 /* might be a cast */
8410 if (TREE_CODE (size) == NOP_EXPR
8411 && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
8412 size = TREE_OPERAND (size, 0);
8414 /* If this involves a template parameter, it'll be
8415 constant, but we don't know what the value is yet. */
8416 if (current_template_parms)
8418 itype = make_node (INTEGER_TYPE);
8419 TYPE_MIN_VALUE (itype) = size_zero_node;
8420 TYPE_MAX_VALUE (itype) = build_min
8421 (MINUS_EXPR, sizetype, size, integer_one_node);
8422 goto dont_grok_size;
8425 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
8426 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
8428 cp_error ("size of array `%D' has non-integer type",
8430 size = integer_one_node;
8432 if (TREE_READONLY_DECL_P (size))
8433 size = decl_constant_value (size);
8434 if (pedantic && integer_zerop (size))
8435 cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
8436 if (TREE_CONSTANT (size))
8438 int old_flag_pedantic_errors = flag_pedantic_errors;
8439 int old_pedantic = pedantic;
8440 pedantic = flag_pedantic_errors = 1;
8441 /* Always give overflow errors on array subscripts. */
8442 constant_expression_warning (size);
8443 pedantic = old_pedantic;
8444 flag_pedantic_errors = old_flag_pedantic_errors;
8445 if (INT_CST_LT (size, integer_zero_node))
8447 cp_error ("size of array `%D' is negative", dname);
8448 size = integer_one_node;
8456 cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
8459 cp_pedwarn ("ANSI C++ forbids variable-size array");
8464 fold (build_binary_op (MINUS_EXPR,
8465 convert (index_type, size),
8466 convert (index_type,
8467 integer_one_node), 1));
8468 if (! TREE_CONSTANT (itype))
8469 itype = variable_size (itype);
8470 itype = build_index_type (itype);
8472 resume_momentary (yes);
8475 /* Build the array type itself, then merge any constancy or
8476 volatility into the target type. We must do it in this order
8477 to ensure that the TYPE_MAIN_VARIANT field of the array type
8478 is set correctly. */
8480 type = build_cplus_array_type (type, itype);
8481 if (constp || volatilep)
8482 type = cp_build_type_variant (type, constp, volatilep);
8492 tree inner_parms = TREE_OPERAND (declarator, 1);
8493 tree inner_decl = TREE_OPERAND (declarator, 0);
8495 /* Declaring a function type.
8496 Make sure we have a valid type for the function to return. */
8498 /* Is this an error? Should they be merged into TYPE here? */
8499 if (pedantic && (constp || volatilep))
8500 pedwarn ("function declared to return const or volatile result");
8502 /* Merge any constancy or volatility into the function return
8505 if (constp || volatilep)
8507 type = cp_build_type_variant (type, constp, volatilep);
8508 if (IS_AGGR_TYPE (type))
8509 build_pointer_type (type);
8515 /* Warn about some types functions can't return. */
8517 if (TREE_CODE (type) == FUNCTION_TYPE)
8519 error ("`%s' declared as function returning a function", name);
8520 type = integer_type_node;
8522 if (TREE_CODE (type) == ARRAY_TYPE)
8524 error ("`%s' declared as function returning an array", name);
8525 type = integer_type_node;
8528 if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
8529 inner_decl = TREE_OPERAND (inner_decl, 1);
8531 /* Pick up type qualifiers which should be applied to `this'. */
8532 quals = TREE_OPERAND (declarator, 2);
8534 /* Say it's a definition only for the CALL_EXPR
8535 closest to the identifier. */
8537 inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE
8538 || TREE_CODE (inner_decl) == BIT_NOT_EXPR);
8540 if (ctype == NULL_TREE
8541 && decl_context == FIELD
8543 && (friendp == 0 || dname == current_class_name))
8544 ctype = current_class_type;
8546 if (ctype && return_type == return_conversion)
8547 TYPE_HAS_CONVERSION (ctype) = 1;
8548 if (ctype && constructor_name (ctype) == dname)
8550 /* We are within a class's scope. If our declarator name
8551 is the same as the class name, and we are defining
8552 a function, then it is a constructor/destructor, and
8553 therefore returns a void type. */
8555 if (flags == DTOR_FLAG)
8557 /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
8558 not be declared const or volatile. A destructor
8559 may not be static. */
8561 error ("destructor cannot be static member function");
8564 error ("destructors cannot be declared `const' or `volatile'");
8565 return void_type_node;
8567 if (decl_context == FIELD)
8569 if (! member_function_or_else (ctype, current_class_type,
8570 "destructor for alien class `%s' cannot be a member"))
8571 return void_type_node;
8574 else /* it's a constructor. */
8578 /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
8579 not be declared const or volatile. A constructor may
8580 not be virtual. A constructor may not be static. */
8582 error ("constructor cannot be static member function");
8585 pedwarn ("constructors cannot be declared virtual");
8590 error ("constructors cannot be declared `const' or `volatile'");
8591 return void_type_node;
8594 RID_BIT_TYPE tmp_bits;
8595 bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE));
8596 RIDBIT_RESET (RID_INLINE, tmp_bits);
8597 RIDBIT_RESET (RID_STATIC, tmp_bits);
8598 if (RIDBIT_ANY_SET (tmp_bits))
8599 error ("return value type specifier for constructor ignored");
8601 type = build_pointer_type (ctype);
8602 if (decl_context == FIELD &&
8603 IS_SIGNATURE (current_class_type))
8605 error ("constructor not allowed in signature");
8606 return void_type_node;
8608 else if (decl_context == FIELD)
8610 if (! member_function_or_else (ctype, current_class_type,
8611 "constructor for alien class `%s' cannot be member"))
8612 return void_type_node;
8613 TYPE_HAS_CONSTRUCTOR (ctype) = 1;
8614 if (return_type != return_ctor)
8618 if (decl_context == FIELD)
8624 error ("can't initialize friend function `%s'", name);
8627 /* Cannot be both friend and virtual. */
8628 error ("virtual functions cannot be friends");
8629 RIDBIT_RESET (RID_FRIEND, specbits);
8632 if (decl_context == NORMAL)
8633 error ("friend declaration not in class definition");
8634 if (current_function_decl && funcdef_flag)
8635 cp_error ("can't define friend function `%s' in a local class definition",
8639 /* Traditionally, declaring return type float means double. */
8641 if (flag_traditional
8642 && TYPE_MAIN_VARIANT (type) == float_type_node)
8644 type = build_type_variant (double_type_node,
8645 TYPE_READONLY (type),
8646 TYPE_VOLATILE (type));
8649 /* Construct the function type and go to the next
8650 inner layer of declarator. */
8652 declarator = TREE_OPERAND (declarator, 0);
8654 /* FIXME: This is where default args should be fully
8657 arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0);
8661 /* Get past destructors, etc.
8662 We know we have one because FLAGS will be non-zero.
8664 Complain about improper parameter lists here. */
8665 if (TREE_CODE (declarator) == BIT_NOT_EXPR)
8667 declarator = TREE_OPERAND (declarator, 0);
8669 if (strict_prototype == 0 && arg_types == NULL_TREE)
8670 arg_types = void_list_node;
8671 else if (arg_types == NULL_TREE
8672 || arg_types != void_list_node)
8674 error ("destructors cannot be specified with parameters");
8675 arg_types = void_list_node;
8680 /* ANSI seems to say that `const int foo ();'
8681 does not make the function foo const. */
8682 type = build_function_type (type,
8683 flag_traditional ? 0 : arg_types);
8689 /* Filter out pointers-to-references and references-to-references.
8690 We can get these if a TYPE_DECL is used. */
8692 if (TREE_CODE (type) == REFERENCE_TYPE)
8694 error ("cannot declare %s to references",
8695 TREE_CODE (declarator) == ADDR_EXPR
8696 ? "references" : "pointers");
8697 declarator = TREE_OPERAND (declarator, 0);
8701 if (TREE_CODE (type) == OFFSET_TYPE
8702 && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE
8703 || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE))
8705 cp_error ("cannot declare pointer to `%#T' member",
8707 type = TREE_TYPE (type);
8710 /* Merge any constancy or volatility into the target type
8713 if (constp || volatilep)
8715 /* A const or volatile signature pointer/reference is
8716 pointing to a const or volatile object, i.e., the
8717 `optr' is const or volatile, respectively, not the
8718 signature pointer/reference itself. */
8719 if (! IS_SIGNATURE (type))
8721 type = cp_build_type_variant (type, constp, volatilep);
8722 if (IS_AGGR_TYPE (type))
8723 build_pointer_type (type);
8729 if (IS_SIGNATURE (type))
8731 if (TREE_CODE (declarator) == ADDR_EXPR)
8733 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8734 && TYPE_SIZE (type))
8735 cp_warning ("empty signature `%T' used in signature reference declaration",
8738 type = build_signature_reference_type (type,
8741 sorry ("signature reference");
8747 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8748 && TYPE_SIZE (type))
8749 cp_warning ("empty signature `%T' used in signature pointer declaration",
8751 type = build_signature_pointer_type (type,
8757 else if (TREE_CODE (declarator) == ADDR_EXPR)
8759 if (TREE_CODE (type) == FUNCTION_TYPE)
8761 error ("cannot declare references to functions; use pointer to function instead");
8762 type = build_pointer_type (type);
8766 if (TYPE_MAIN_VARIANT (type) == void_type_node)
8767 error ("invalid type: `void &'");
8769 type = build_reference_type (type);
8772 else if (TREE_CODE (type) == METHOD_TYPE)
8774 type = build_ptrmemfunc_type (build_pointer_type (type));
8777 type = build_pointer_type (type);
8779 /* Process a list of type modifier keywords (such as
8780 const or volatile) that were given inside the `*' or `&'. */
8782 if (TREE_TYPE (declarator))
8784 register tree typemodlist;
8786 for (typemodlist = TREE_TYPE (declarator); typemodlist;
8787 typemodlist = TREE_CHAIN (typemodlist))
8789 if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
8791 else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
8796 error ("invalid type modifier within %s declarator",
8797 TREE_CODE (declarator) == ADDR_EXPR
8798 ? "reference" : "pointer");
8802 pedwarn ("duplicate `const'");
8804 pedwarn ("duplicate `volatile'");
8805 if (TREE_CODE (declarator) == ADDR_EXPR
8806 && (constp || volatilep))
8809 pedwarn ("discarding `const' applied to a reference");
8811 pedwarn ("discarding `volatile' applied to a reference");
8812 constp = volatilep = 0;
8815 declarator = TREE_OPERAND (declarator, 0);
8821 /* We have converted type names to NULL_TREE if the
8822 name was bogus, or to a _TYPE node, if not.
8824 The variable CTYPE holds the type we will ultimately
8825 resolve to. The code here just needs to build
8826 up appropriate member types. */
8827 tree sname = TREE_OPERAND (declarator, 1);
8828 /* Destructors can have their visibilities changed as well. */
8829 if (TREE_CODE (sname) == BIT_NOT_EXPR)
8830 sname = TREE_OPERAND (sname, 0);
8832 if (TREE_COMPLEXITY (declarator) == 0)
8833 /* This needs to be here, in case we are called
8834 multiple times. */ ;
8835 else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
8836 /* don't fall out into global scope. Hides real bug? --eichin */ ;
8837 else if (! IS_AGGR_TYPE_CODE
8838 (TREE_CODE (TREE_OPERAND (declarator, 0))))
8840 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
8842 /* This pop_nested_class corresponds to the
8843 push_nested_class used to push into class scope for
8844 parsing the argument list of a function decl, in
8846 pop_nested_class (1);
8847 TREE_COMPLEXITY (declarator) = current_class_depth;
8850 my_friendly_abort (16);
8852 if (TREE_OPERAND (declarator, 0) == NULL_TREE)
8854 /* We had a reference to a global decl, or
8855 perhaps we were given a non-aggregate typedef,
8856 in which case we cleared this out, and should just
8857 keep going as though it wasn't there. */
8861 ctype = TREE_OPERAND (declarator, 0);
8863 if (sname == NULL_TREE)
8866 if (TREE_CODE (sname) == IDENTIFIER_NODE)
8868 /* This is the `standard' use of the scoping operator:
8869 basetype :: member . */
8871 if (ctype == current_class_type)
8877 Is this ill-formed? */
8880 cp_pedwarn ("extra qualification `%T::' on member `%s' ignored",
8883 else if (TREE_CODE (type) == FUNCTION_TYPE)
8885 if (current_class_type == NULL_TREE
8887 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8888 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8891 cp_error ("cannot declare member function `%T::%s' within `%T'",
8892 ctype, name, current_class_type);
8893 return void_type_node;
8896 else if (RIDBIT_SETP (RID_TYPEDEF, specbits)
8897 || TYPE_SIZE (complete_type (ctype)) != NULL_TREE)
8899 /* have to move this code elsewhere in this function.
8900 this code is used for i.e., typedef int A::M; M *pm;
8902 It is? How? jason 10/2/94 */
8904 if (current_class_type)
8906 cp_error ("cannot declare member `%T::%s' within `%T'",
8907 ctype, name, current_class_type);
8908 return void_type_node;
8910 type = build_offset_type (ctype, type);
8912 else if (uses_template_parms (ctype))
8914 if (TREE_CODE (type) == FUNCTION_TYPE)
8916 build_cplus_method_type (build_type_variant (ctype,
8920 TYPE_ARG_TYPES (type));
8924 cp_error ("structure `%T' not yet defined", ctype);
8925 return error_mark_node;
8930 else if (TREE_CODE (sname) == SCOPE_REF)
8931 my_friendly_abort (17);
8935 declarator = TREE_OPERAND (declarator, 1);
8936 if (declarator && TREE_CODE (declarator) == CALL_EXPR)
8937 /* In this case, we will deal with it later. */
8941 if (TREE_CODE (type) == FUNCTION_TYPE)
8942 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
8944 type = build_offset_type (ctype, type);
8951 declarator = TREE_OPERAND (declarator, 0);
8957 declarator = NULL_TREE;
8961 declarator = NULL_TREE;
8965 my_friendly_abort (158);
8971 error ("only constructors can be declared `explicit'");
8975 /* Now TYPE has the actual type. */
8977 /* If this is declaring a typedef name, return a TYPE_DECL. */
8979 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8983 error ("const `%s' cannot be declared `mutable'", name);
8984 RIDBIT_RESET (RID_MUTABLE, specbits);
8988 error ("static `%s' cannot be declared `mutable'", name);
8989 RIDBIT_RESET (RID_MUTABLE, specbits);
8993 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8997 /* Note that the grammar rejects storage classes
8998 in typenames, fields or parameters. */
8999 if (constp || volatilep)
9000 type = cp_build_type_variant (type, constp, volatilep);
9002 /* If the user declares "struct {...} foo" then `foo' will have
9003 an anonymous name. Fill that name in now. Nothing can
9004 refer to it, so nothing needs know about the name change.
9005 The TYPE_NAME field was filled in by build_struct_xref. */
9006 if (type != error_mark_node
9008 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9009 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
9011 /* replace the anonymous name with the real name everywhere. */
9012 lookup_tag_reverse (type, declarator);
9013 TYPE_IDENTIFIER (type) = declarator;
9015 if (TYPE_LANG_SPECIFIC (type))
9016 TYPE_WAS_ANONYMOUS (type) = 1;
9019 tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
9022 set_nested_typename (d, 0, declarator, type);
9023 else if (TREE_CODE (c) == FUNCTION_DECL)
9024 set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
9027 set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
9029 DECL_ASSEMBLER_NAME (d) = DECL_NAME (d);
9030 DECL_ASSEMBLER_NAME (d)
9031 = get_identifier (build_overload_name (type, 1, 1));
9035 decl = build_decl (TYPE_DECL, declarator, type);
9036 if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
9038 cp_error_at ("typedef name may not be class-qualified", decl);
9043 if (ctype == NULL_TREE)
9045 if (TREE_CODE (type) != METHOD_TYPE)
9046 cp_error_at ("invalid type qualifier for non-method type", decl);
9048 ctype = TYPE_METHOD_BASETYPE (type);
9050 if (ctype != NULL_TREE)
9051 grok_method_quals (ctype, decl, quals);
9054 if (RIDBIT_SETP (RID_SIGNED, specbits)
9055 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
9056 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
9058 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9060 error ("non-object member `%s' cannot be declared mutable", name);
9066 /* Detect the case of an array type of unspecified size
9067 which came, as such, direct from a typedef name.
9068 We must copy the type, so that each identifier gets
9069 a distinct type, so that each identifier's size can be
9070 controlled separately by its own initializer. */
9072 if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
9073 && TYPE_DOMAIN (type) == NULL_TREE)
9075 type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
9078 /* If this is a type name (such as, in a cast or sizeof),
9079 compute the type and return it now. */
9081 if (decl_context == TYPENAME)
9083 /* Note that the grammar rejects storage classes
9084 in typenames, fields or parameters. */
9085 if (constp || volatilep)
9086 if (IS_SIGNATURE (type))
9087 error ("`const' or `volatile' specified with signature type");
9089 type = cp_build_type_variant (type, constp, volatilep);
9091 /* Special case: "friend class foo" looks like a TYPENAME context. */
9096 cp_error ("`volatile' specified for friend class declaration");
9101 cp_error ("`inline' specified for friend class declaration");
9105 /* Only try to do this stuff if we didn't already give up. */
9106 if (type != integer_type_node)
9108 /* A friendly class? */
9109 if (current_class_type)
9110 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
9112 error ("trying to make class `%s' a friend of global scope",
9113 TYPE_NAME_STRING (type));
9114 type = void_type_node;
9119 tree dummy = build_decl (TYPE_DECL, declarator, type);
9120 if (ctype == NULL_TREE)
9122 my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
9123 ctype = TYPE_METHOD_BASETYPE (type);
9125 grok_method_quals (ctype, dummy, quals);
9126 type = TREE_TYPE (dummy);
9131 else if (declarator == NULL_TREE && decl_context != PARM
9132 && decl_context != CATCHPARM
9133 && TREE_CODE (type) != UNION_TYPE
9136 cp_error ("abstract declarator `%T' used as declaration", type);
9137 declarator = make_anon_name ();
9140 /* `void' at top level (not within pointer)
9141 is allowed only in typedefs or type names.
9142 We don't complain about parms either, but that is because
9143 a better error message can be made later. */
9145 if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
9148 error ("unnamed variable or field declared void");
9149 else if (TREE_CODE (declarator) == IDENTIFIER_NODE)
9151 if (IDENTIFIER_OPNAME_P (declarator))
9152 my_friendly_abort (356);
9154 error ("variable or field `%s' declared void", name);
9157 error ("variable or field declared void");
9158 type = integer_type_node;
9161 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
9162 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
9167 if (decl_context == PARM)
9170 error ("cannot use `::' in parameter declaration");
9172 /* A parameter declared as an array of T is really a pointer to T.
9173 One declared as a function is really a pointer to a function.
9174 One declared as a member is really a pointer to member. */
9176 if (TREE_CODE (type) == ARRAY_TYPE)
9178 /* Transfer const-ness of array into that of type pointed to. */
9179 type = build_pointer_type
9180 (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
9181 volatilep = constp = 0;
9183 else if (TREE_CODE (type) == FUNCTION_TYPE)
9184 type = build_pointer_type (type);
9185 else if (TREE_CODE (type) == OFFSET_TYPE)
9186 type = build_pointer_type (type);
9187 else if (type == void_type_node && declarator)
9189 error ("declaration of `%s' as void", name);
9193 decl = build_decl (PARM_DECL, declarator, type);
9195 bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
9196 inlinep, friendp, raises != NULL_TREE);
9197 if (current_class_type
9198 && IS_SIGNATURE (current_class_type))
9201 error ("parameter of signature member function declared `inline'");
9202 if (RIDBIT_SETP (RID_AUTO, specbits))
9203 error ("parameter of signature member function declared `auto'");
9204 if (RIDBIT_SETP (RID_REGISTER, specbits))
9205 error ("parameter of signature member function declared `register'");
9208 /* Compute the type actually passed in the parmlist,
9209 for the case where there is no prototype.
9210 (For example, shorts and chars are passed as ints.)
9211 When there is a prototype, this is overridden later. */
9213 DECL_ARG_TYPE (decl) = type_promotes_to (type);
9215 else if (decl_context == FIELD)
9217 if (type == error_mark_node)
9219 /* Happens when declaring arrays of sizes which
9220 are error_mark_node, for example. */
9223 else if (TREE_CODE (type) == FUNCTION_TYPE)
9227 /* We catch the others as conflicts with the builtin
9229 if (friendp && declarator == ridpointers[(int) RID_SIGNED])
9231 cp_error ("function `%D' cannot be declared friend",
9238 if (ctype == NULL_TREE)
9239 ctype = current_class_type;
9241 if (ctype == NULL_TREE)
9243 cp_error ("can't make `%D' into a method -- not in a class",
9245 return void_type_node;
9248 /* ``A union may [ ... ] not [ have ] virtual functions.''
9250 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
9252 cp_error ("function `%D' declared virtual inside a union",
9254 return void_type_node;
9257 if (declarator == ansi_opname[(int) NEW_EXPR]
9258 || declarator == ansi_opname[(int) VEC_NEW_EXPR]
9259 || declarator == ansi_opname[(int) DELETE_EXPR]
9260 || declarator == ansi_opname[(int) VEC_DELETE_EXPR])
9264 cp_error ("`%D' cannot be declared virtual, since it is always static",
9269 else if (staticp < 2)
9270 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9271 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9274 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
9275 publicp = (! friendp
9276 || RIDBIT_SETP (RID_EXTERN, specbits)
9277 || ! (funcdef_flag < 0 || inlinep));
9278 decl = grokfndecl (ctype, type, declarator,
9279 virtualp, flags, quals, raises, attrlist,
9280 friendp ? -1 : 0, publicp, inlinep);
9281 if (decl == NULL_TREE)
9283 decl = build_decl_attribute_variant (decl, decl_machine_attr);
9286 DECL_NONCONVERTING_P (decl) = 1;
9288 else if (TREE_CODE (type) == METHOD_TYPE)
9290 /* We only get here for friend declarations of
9291 members of other classes. */
9292 /* All method decls are public, so tell grokfndecl to set
9293 TREE_PUBLIC, also. */
9294 decl = grokfndecl (ctype, type, declarator,
9295 virtualp, flags, quals, raises, attrlist,
9296 friendp ? -1 : 0, 1, 0, funcdef_flag);
9297 if (decl == NULL_TREE)
9300 else if (!staticp && ! processing_template_decl
9301 && TYPE_SIZE (complete_type (type)) == NULL_TREE
9302 && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
9305 cp_error ("field `%D' has incomplete type", declarator);
9307 cp_error ("name `%T' has incomplete type", type);
9309 /* If we're instantiating a template, tell them which
9310 instantiation made the field's type be incomplete. */
9311 if (current_class_type
9312 && TYPE_NAME (current_class_type)
9313 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
9314 && declspecs && TREE_VALUE (declspecs)
9315 && TREE_TYPE (TREE_VALUE (declspecs)) == type)
9316 cp_error (" in instantiation of template `%T'",
9317 current_class_type);
9319 type = error_mark_node;
9326 error ("`%s' is neither function nor method; cannot be declared friend",
9327 IDENTIFIER_POINTER (declarator));
9335 /* Friends are treated specially. */
9336 if (ctype == current_class_type)
9337 warning ("member functions are implicitly friends of their class");
9341 if (decl && DECL_NAME (decl))
9342 t = do_friend (ctype, declarator, decl,
9343 last_function_parms, flags, quals,
9345 if (t && funcdef_flag)
9348 return void_type_node;
9352 /* Structure field. It may not be a function, except for C++ */
9354 if (decl == NULL_TREE)
9358 /* Motion 10 at San Diego: If a static const integral data
9359 member is initialized with an integral constant
9360 expression, the initializer may appear either in the
9361 declaration (within the class), or in the definition,
9362 but not both. If it appears in the class, the member is
9363 a member constant. The file-scope definition is always
9370 cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
9373 else if (! INTEGRAL_TYPE_P (type))
9374 cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type);
9378 /* Note that initialization of const members is prohibited
9379 by the draft ANSI standard, though it appears to be in
9380 common practice. 12.6.2: The argument list is used to
9381 initialize the named nonstatic member.... This (or an
9382 initializer list) is the only way to initialize
9383 nonstatic const and reference members. */
9384 else if (pedantic || ! constp)
9385 cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
9386 constp ? "const member" : "member", declarator);
9389 if (staticp || (constp && initialized))
9391 /* ANSI C++ Apr '95 wp 9.2 */
9392 if (staticp && declarator == current_class_name)
9393 cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class",
9396 /* C++ allows static class members.
9397 All other work for this is done by grokfield.
9398 This VAR_DECL is built by build_lang_field_decl.
9399 All other VAR_DECLs are built by build_decl. */
9400 decl = build_lang_field_decl (VAR_DECL, declarator, type);
9401 TREE_STATIC (decl) = 1;
9402 /* In class context, 'static' means public access. */
9403 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp;
9407 decl = build_lang_field_decl (FIELD_DECL, declarator, type);
9408 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9410 DECL_MUTABLE_P (decl) = 1;
9411 RIDBIT_RESET (RID_MUTABLE, specbits);
9415 bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
9416 inlinep, friendp, raises != NULL_TREE);
9419 else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
9421 tree original_name = declarator;
9427 if (RIDBIT_SETP (RID_AUTO, specbits))
9428 error ("storage class `auto' invalid for function `%s'", name);
9429 else if (RIDBIT_SETP (RID_REGISTER, specbits))
9430 error ("storage class `register' invalid for function `%s'", name);
9432 /* Function declaration not at top level.
9433 Storage classes other than `extern' are not allowed
9434 and `extern' makes no difference. */
9435 if (! toplevel_bindings_p ()
9436 && (RIDBIT_SETP (RID_STATIC, specbits)
9437 || RIDBIT_SETP (RID_INLINE, specbits))
9440 if (RIDBIT_SETP (RID_STATIC, specbits))
9441 pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
9443 pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
9446 if (ctype == NULL_TREE)
9450 error ("virtual non-class function `%s'", name);
9454 if (current_lang_name == lang_name_cplusplus
9455 && ! current_template_parms
9456 && ! (IDENTIFIER_LENGTH (original_name) == 4
9457 && IDENTIFIER_POINTER (original_name)[0] == 'm'
9458 && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
9459 && ! (IDENTIFIER_LENGTH (original_name) > 10
9460 && IDENTIFIER_POINTER (original_name)[0] == '_'
9461 && IDENTIFIER_POINTER (original_name)[1] == '_'
9462 && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
9463 /* Plain overloading: will not be grok'd by grokclassfn. */
9464 declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
9466 else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
9467 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9468 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9470 /* Record presence of `static'. In C++, `inline' implies `static'. */
9471 publicp = (ctype != NULL_TREE
9472 || RIDBIT_SETP (RID_EXTERN, specbits)
9473 || (!RIDBIT_SETP (RID_STATIC, specbits)
9474 && !RIDBIT_SETP (RID_INLINE, specbits)));
9476 decl = grokfndecl (ctype, type, original_name,
9477 virtualp, flags, quals, raises, attrlist,
9479 publicp, inlinep, funcdef_flag);
9480 if (decl == NULL_TREE)
9483 if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
9484 DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator);
9488 int illegal_static = 0;
9490 /* Don't allow a static member function in a class, and forbid
9491 declaring main to be static. */
9492 if (TREE_CODE (type) == METHOD_TYPE)
9494 cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl);
9497 else if (current_function_decl)
9499 /* FIXME need arm citation */
9500 error ("cannot declare static function inside another function");
9507 RIDBIT_RESET (RID_STATIC, specbits);
9513 /* It's a variable. */
9515 if (decl_context == CATCHPARM)
9520 error ("cannot use `::' in parameter declaration");
9523 /* A parameter declared as an array of T is really a pointer to T.
9524 One declared as a function is really a pointer to a function.
9525 One declared as a member is really a pointer to member. */
9527 if (TREE_CODE (type) == ARRAY_TYPE)
9529 /* Transfer const-ness of array into that of type pointed to. */
9530 type = build_pointer_type
9531 (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
9532 volatilep = constp = 0;
9534 else if (TREE_CODE (type) == FUNCTION_TYPE)
9535 type = build_pointer_type (type);
9536 else if (TREE_CODE (type) == OFFSET_TYPE)
9537 type = build_pointer_type (type);
9540 /* An uninitialized decl with `extern' is a reference. */
9541 decl = grokvardecl (type, declarator, specbits, initialized, constp);
9542 bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
9543 inlinep, friendp, raises != NULL_TREE);
9547 DECL_CONTEXT (decl) = ctype;
9550 cp_pedwarn ("static member `%D' re-declared as static", decl);
9552 RIDBIT_RESET (RID_STATIC, specbits);
9554 if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl))
9556 cp_error ("static member `%D' declared `register'", decl);
9557 RIDBIT_RESET (RID_REGISTER, specbits);
9559 if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic)
9561 cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage",
9563 RIDBIT_RESET (RID_EXTERN, specbits);
9568 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9570 error ("`%s' cannot be declared mutable", name);
9573 /* Record `register' declaration for warnings on &
9574 and in case doing stupid register allocation. */
9576 if (RIDBIT_SETP (RID_REGISTER, specbits))
9577 DECL_REGISTER (decl) = 1;
9579 if (RIDBIT_SETP (RID_EXTERN, specbits))
9580 DECL_THIS_EXTERN (decl) = 1;
9582 if (RIDBIT_SETP (RID_STATIC, specbits))
9583 DECL_THIS_STATIC (decl) = 1;
9585 /* Record constancy and volatility. */
9588 TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
9591 TREE_SIDE_EFFECTS (decl) = 1;
9592 TREE_THIS_VOLATILE (decl) = 1;
9599 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
9600 An empty exprlist is a parmlist. An exprlist which
9601 contains only identifiers at the global level
9602 is a parmlist. Otherwise, it is an exprlist. */
9604 parmlist_is_exprlist (exprs)
9607 if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
9610 if (toplevel_bindings_p ())
9612 /* At the global level, if these are all identifiers,
9613 then it is a parmlist. */
9616 if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
9618 exprs = TREE_CHAIN (exprs);
9625 /* Subroutine of `grokparms'. In a fcn definition, arg types must
9628 C++: also subroutine of `start_function'. */
9630 require_complete_types_for_parms (parms)
9633 if (processing_template_decl)
9638 tree type = TREE_TYPE (parms);
9639 if (TYPE_SIZE (complete_type (type)) == NULL_TREE)
9641 if (DECL_NAME (parms))
9642 error ("parameter `%s' has incomplete type",
9643 IDENTIFIER_POINTER (DECL_NAME (parms)));
9645 error ("parameter has incomplete type");
9646 TREE_TYPE (parms) = error_mark_node;
9649 /* If the arg types are incomplete in a declaration,
9650 they must include undefined tags.
9651 These tags can never be defined in the scope of the declaration,
9652 so the types can never be completed,
9653 and no call can be compiled successfully. */
9654 /* This is not the right behavior for C++, but not having
9655 it is also probably wrong. */
9658 /* Now warn if is a pointer to an incomplete type. */
9659 while (TREE_CODE (type) == POINTER_TYPE
9660 || TREE_CODE (type) == REFERENCE_TYPE)
9661 type = TREE_TYPE (type);
9662 type = TYPE_MAIN_VARIANT (type);
9663 if (TYPE_SIZE (type) == NULL_TREE)
9665 if (DECL_NAME (parm) != NULL_TREE)
9666 warning ("parameter `%s' points to incomplete type",
9667 IDENTIFIER_POINTER (DECL_NAME (parm)));
9669 warning ("parameter points to incomplete type");
9673 parms = TREE_CHAIN (parms);
9677 /* Decode the list of parameter types for a function type.
9678 Given the list of things declared inside the parens,
9679 return a list of types.
9681 The list we receive can have three kinds of elements:
9682 an IDENTIFIER_NODE for names given without types,
9683 a TREE_LIST node for arguments given as typespecs or names with typespecs,
9684 or void_type_node, to mark the end of an argument list
9685 when additional arguments are not permitted (... was not used).
9687 FUNCDEF_FLAG is nonzero for a function definition, 0 for
9688 a mere declaration. A nonempty identifier-list gets an error message
9689 when FUNCDEF_FLAG is zero.
9690 If FUNCDEF_FLAG is 1, then parameter types must be complete.
9691 If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9693 If all elements of the input list contain types,
9694 we return a list of the types.
9695 If all elements contain no type (except perhaps a void_type_node
9696 at the end), we return a null list.
9697 If some have types and some do not, it is an error, and we
9700 Also set last_function_parms to either
9701 a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9702 A list of names is converted to a chain of PARM_DECLs
9703 by store_parm_decls so that ultimately it is always a chain of decls.
9705 Note that in C++, parameters can take default values. These default
9706 values are in the TREE_PURPOSE field of the TREE_LIST. It is
9707 an error to specify default values which are followed by parameters
9708 that have no default values, or an ELLIPSES. For simplicities sake,
9709 only parameters which are specified with their types can take on
9713 grokparms (first_parm, funcdef_flag)
9717 tree result = NULL_TREE;
9718 tree decls = NULL_TREE;
9720 if (first_parm != NULL_TREE
9721 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
9724 pedwarn ("parameter names (without types) in function declaration");
9725 last_function_parms = first_parm;
9728 else if (first_parm != NULL_TREE
9729 && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
9730 && TREE_VALUE (first_parm) != void_type_node)
9731 my_friendly_abort (145);
9734 /* Types were specified. This is a list of declarators
9735 each represented as a TREE_LIST node. */
9736 register tree parm, chain;
9737 int any_init = 0, any_error = 0;
9739 if (first_parm != NULL_TREE)
9741 tree last_result = NULL_TREE;
9742 tree last_decl = NULL_TREE;
9744 for (parm = first_parm; parm != NULL_TREE; parm = chain)
9746 tree type, list_node = parm;
9747 register tree decl = TREE_VALUE (parm);
9748 tree init = TREE_PURPOSE (parm);
9750 chain = TREE_CHAIN (parm);
9751 /* @@ weak defense against parse errors. */
9752 if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
9754 /* Give various messages as the need arises. */
9755 if (TREE_CODE (decl) == STRING_CST)
9756 error ("invalid string constant `%s'",
9757 TREE_STRING_POINTER (decl));
9758 else if (TREE_CODE (decl) == INTEGER_CST)
9759 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9763 if (decl != void_type_node)
9765 /* @@ May need to fetch out a `raises' here. */
9766 decl = grokdeclarator (TREE_VALUE (decl),
9767 TREE_PURPOSE (decl),
9768 PARM, init != NULL_TREE,
9769 NULL_TREE, NULL_TREE);
9772 type = TREE_TYPE (decl);
9773 if (TYPE_MAIN_VARIANT (type) == void_type_node)
9774 decl = void_type_node;
9775 else if (TREE_CODE (type) == METHOD_TYPE)
9777 if (DECL_NAME (decl))
9778 /* Cannot use `error_with_decl' here because
9779 we don't have DECL_CONTEXT set up yet. */
9780 error ("parameter `%s' invalidly declared method type",
9781 IDENTIFIER_POINTER (DECL_NAME (decl)));
9783 error ("parameter invalidly declared method type");
9784 type = build_pointer_type (type);
9785 TREE_TYPE (decl) = type;
9787 else if (TREE_CODE (type) == OFFSET_TYPE)
9789 if (DECL_NAME (decl))
9790 error ("parameter `%s' invalidly declared offset type",
9791 IDENTIFIER_POINTER (DECL_NAME (decl)));
9793 error ("parameter invalidly declared offset type");
9794 type = build_pointer_type (type);
9795 TREE_TYPE (decl) = type;
9797 else if (TREE_CODE (type) == RECORD_TYPE
9798 && TYPE_LANG_SPECIFIC (type)
9799 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
9801 abstract_virtuals_error (decl, type);
9802 any_error = 1; /* seems like a good idea */
9804 else if (TREE_CODE (type) == RECORD_TYPE
9805 && TYPE_LANG_SPECIFIC (type)
9806 && IS_SIGNATURE (type))
9808 signature_error (decl, type);
9809 any_error = 1; /* seems like a good idea */
9813 if (decl == void_type_node)
9815 if (result == NULL_TREE)
9817 result = void_list_node;
9818 last_result = result;
9822 TREE_CHAIN (last_result) = void_list_node;
9823 last_result = void_list_node;
9826 && (chain != void_list_node || TREE_CHAIN (chain)))
9827 error ("`void' in parameter list must be entire list");
9831 /* Since there is a prototype, args are passed in their own types. */
9832 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
9833 #ifdef PROMOTE_PROTOTYPES
9834 if ((TREE_CODE (type) == INTEGER_TYPE
9835 || TREE_CODE (type) == ENUMERAL_TYPE)
9836 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
9837 DECL_ARG_TYPE (decl) = integer_type_node;
9844 if (TREE_CODE (init) == SAVE_EXPR)
9845 PARM_DECL_EXPR (init) = 1;
9846 else if (current_template_parms)
9848 else if (TREE_CODE (init) == VAR_DECL
9849 || TREE_CODE (init) == PARM_DECL)
9851 if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
9853 /* ``Local variables may not be used in default
9854 argument expressions.'' dpANSI C++ 8.2.6 */
9855 /* If extern int i; within a function is not
9856 considered a local variable, then this code is
9858 cp_error ("local variable `%D' may not be used as a default argument", init);
9861 else if (TREE_READONLY_DECL_P (init))
9862 init = decl_constant_value (init);
9865 init = require_instantiated_type (type, init, integer_zero_node);
9871 if (decls == NULL_TREE)
9878 TREE_CHAIN (last_decl) = decl;
9881 if (TREE_PERMANENT (list_node))
9883 TREE_PURPOSE (list_node) = init;
9884 TREE_VALUE (list_node) = type;
9885 TREE_CHAIN (list_node) = NULL_TREE;
9888 list_node = saveable_tree_cons (init, type, NULL_TREE);
9889 if (result == NULL_TREE)
9892 last_result = result;
9896 TREE_CHAIN (last_result) = list_node;
9897 last_result = list_node;
9901 TREE_CHAIN (last_result) = NULL_TREE;
9902 /* If there are no parameters, and the function does not end
9903 with `...', then last_decl will be NULL_TREE. */
9904 if (last_decl != NULL_TREE)
9905 TREE_CHAIN (last_decl) = NULL_TREE;
9909 last_function_parms = decls;
9911 /* In a fcn definition, arg types must be complete. */
9912 if (funcdef_flag > 0)
9913 require_complete_types_for_parms (last_function_parms);
9918 /* These memoizing functions keep track of special properties which
9919 a class may have. `grok_ctor_properties' notices whether a class
9920 has a constructor of the form X(X&), and also complains
9921 if the class has a constructor of the form X(X).
9922 `grok_op_properties' takes notice of the various forms of
9923 operator= which are defined, as well as what sorts of type conversion
9924 may apply. Both functions take a FUNCTION_DECL as an argument. */
9926 grok_ctor_properties (ctype, decl)
9929 tree parmtypes = FUNCTION_ARG_CHAIN (decl);
9930 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
9932 /* When a type has virtual baseclasses, a magical first int argument is
9933 added to any ctor so we can tell if the class has been initialized
9934 yet. This could screw things up in this function, so we deliberately
9935 ignore the leading int if we're in that situation. */
9937 && TREE_VALUE (parmtypes) == integer_type_node
9938 && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
9940 parmtypes = TREE_CHAIN (parmtypes);
9941 parmtype = TREE_VALUE (parmtypes);
9944 if (TREE_CODE (parmtype) == REFERENCE_TYPE
9945 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
9947 if (TREE_CHAIN (parmtypes) == NULL_TREE
9948 || TREE_CHAIN (parmtypes) == void_list_node
9949 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
9951 TYPE_HAS_INIT_REF (ctype) = 1;
9952 if (TYPE_READONLY (TREE_TYPE (parmtype)))
9953 TYPE_HAS_CONST_INIT_REF (ctype) = 1;
9956 TYPE_GETS_INIT_AGGR (ctype) = 1;
9958 else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
9960 if (TREE_CHAIN (parmtypes) != NULL_TREE
9961 && TREE_CHAIN (parmtypes) == void_list_node)
9963 cp_error ("invalid constructor; you probably meant `%T (%T&)'",
9965 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
9970 TYPE_GETS_INIT_AGGR (ctype) = 1;
9972 else if (TREE_CODE (parmtype) == VOID_TYPE
9973 || TREE_PURPOSE (parmtypes) != NULL_TREE)
9974 TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
9979 /* An operator with this name can be either unary or binary. */
9984 return (name == ansi_opname [(int) INDIRECT_REF]
9985 || name == ansi_opname [(int) ADDR_EXPR]
9986 || name == ansi_opname [(int) NEGATE_EXPR]
9987 || name == ansi_opname[(int) POSTINCREMENT_EXPR]
9988 || name == ansi_opname[(int) POSTDECREMENT_EXPR]
9989 || name == ansi_opname [(int) CONVERT_EXPR]);
9992 /* An operator with this name can only be unary. */
9997 return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
9998 || name == ansi_opname [(int) BIT_NOT_EXPR]
9999 || name == ansi_opname [(int) COMPONENT_REF]
10000 || OPERATOR_TYPENAME_P (name));
10003 /* Do a little sanity-checking on how they declared their operator. */
10005 grok_op_properties (decl, virtualp, friendp)
10007 int virtualp, friendp;
10009 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
10010 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
10011 tree name = DECL_NAME (decl);
10013 if (current_class_type == NULL_TREE)
10018 if (name == ansi_opname[(int) MODIFY_EXPR])
10019 TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
10020 else if (name == ansi_opname[(int) CALL_EXPR])
10021 TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
10022 else if (name == ansi_opname[(int) ARRAY_REF])
10023 TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
10024 else if (name == ansi_opname[(int) COMPONENT_REF]
10025 || name == ansi_opname[(int) MEMBER_REF])
10026 TYPE_OVERLOADS_ARROW (current_class_type) = 1;
10027 else if (name == ansi_opname[(int) NEW_EXPR])
10028 TYPE_GETS_NEW (current_class_type) |= 1;
10029 else if (name == ansi_opname[(int) DELETE_EXPR])
10030 TYPE_GETS_DELETE (current_class_type) |= 1;
10031 else if (name == ansi_opname[(int) VEC_NEW_EXPR])
10032 TYPE_GETS_NEW (current_class_type) |= 2;
10033 else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
10034 TYPE_GETS_DELETE (current_class_type) |= 2;
10037 if (name == ansi_opname[(int) NEW_EXPR]
10038 || name == ansi_opname[(int) VEC_NEW_EXPR])
10040 /* When the compiler encounters the definition of A::operator new, it
10041 doesn't look at the class declaration to find out if it's static. */
10043 revert_static_member_fn (&decl, NULL, NULL);
10045 /* Take care of function decl if we had syntax errors. */
10046 if (argtypes == NULL_TREE)
10048 build_function_type (ptr_type_node,
10049 hash_tree_chain (integer_type_node,
10052 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
10054 else if (name == ansi_opname[(int) DELETE_EXPR]
10055 || name == ansi_opname[(int) VEC_DELETE_EXPR])
10058 revert_static_member_fn (&decl, NULL, NULL);
10060 if (argtypes == NULL_TREE)
10062 build_function_type (void_type_node,
10063 hash_tree_chain (ptr_type_node,
10067 TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
10069 if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR]
10070 && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
10071 != void_list_node))
10072 TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1;
10077 /* An operator function must either be a non-static member function
10078 or have at least one parameter of a class, a reference to a class,
10079 an enumeration, or a reference to an enumeration. 13.4.0.6 */
10080 if (! methodp || DECL_STATIC_FUNCTION_P (decl))
10082 if (OPERATOR_TYPENAME_P (name)
10083 || name == ansi_opname[(int) CALL_EXPR]
10084 || name == ansi_opname[(int) MODIFY_EXPR]
10085 || name == ansi_opname[(int) COMPONENT_REF]
10086 || name == ansi_opname[(int) ARRAY_REF])
10087 cp_error ("`%D' must be a nonstatic member function", decl);
10092 if (DECL_STATIC_FUNCTION_P (decl))
10093 cp_error ("`%D' must be either a non-static member function or a non-member function", decl);
10096 for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
10098 tree arg = TREE_VALUE (p);
10099 if (TREE_CODE (arg) == REFERENCE_TYPE)
10100 arg = TREE_TYPE (arg);
10102 /* This lets bad template code slip through. */
10103 if (IS_AGGR_TYPE (arg)
10104 || TREE_CODE (arg) == ENUMERAL_TYPE
10105 || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
10109 ("`%D' must have an argument of class or enumerated type",
10116 if (name == ansi_opname[(int) CALL_EXPR]
10117 || name == ansi_opname[(int) METHOD_CALL_EXPR])
10118 return; /* no restrictions on args */
10120 if (IDENTIFIER_TYPENAME_P (name))
10122 tree t = TREE_TYPE (name);
10123 if (TREE_CODE (t) == VOID_TYPE)
10124 pedwarn ("void is not a valid type conversion operator");
10125 else if (! friendp)
10127 int ref = (TREE_CODE (t) == REFERENCE_TYPE);
10130 t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
10132 if (t == current_class_type)
10133 what = "the same type";
10134 else if (IS_AGGR_TYPE (t)
10135 && DERIVED_FROM_P (t, current_class_type))
10136 what = "a base class";
10139 warning ("conversion to %s%s will never use a type conversion operator",
10140 ref ? "a reference to " : "", what);
10144 if (name == ansi_opname[(int) MODIFY_EXPR])
10148 if (list_length (argtypes) != 3 && methodp)
10150 cp_error ("`%D' must take exactly one argument", decl);
10153 parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
10155 if (copy_assignment_arg_p (parmtype, virtualp)
10158 TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
10159 if (TREE_CODE (parmtype) != REFERENCE_TYPE
10160 || TYPE_READONLY (TREE_TYPE (parmtype)))
10161 TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
10164 else if (name == ansi_opname[(int) COND_EXPR])
10167 pedwarn ("ANSI C++ prohibits overloading operator ?:");
10168 if (list_length (argtypes) != 4)
10169 cp_error ("`%D' must take exactly three arguments", decl);
10171 else if (ambi_op_p (name))
10173 if (list_length (argtypes) == 2)
10175 else if (list_length (argtypes) == 3)
10177 if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
10178 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
10179 && ! current_template_parms
10180 && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
10183 cp_error ("postfix `%D' must take `int' as its argument",
10187 ("postfix `%D' must take `int' as its second argument",
10194 cp_error ("`%D' must take either zero or one argument", decl);
10196 cp_error ("`%D' must take either one or two arguments", decl);
10199 else if (unary_op_p (name))
10201 if (list_length (argtypes) != 2)
10204 cp_error ("`%D' must take `void'", decl);
10206 cp_error ("`%D' must take exactly one argument", decl);
10209 else /* if (binary_op_p (name)) */
10211 if (list_length (argtypes) != 3)
10214 cp_error ("`%D' must take exactly one argument", decl);
10216 cp_error ("`%D' must take exactly two arguments", decl);
10222 for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
10223 if (TREE_PURPOSE (argtypes))
10225 TREE_PURPOSE (argtypes) = NULL_TREE;
10226 if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
10227 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
10230 cp_pedwarn ("`%D' cannot have default arguments", decl);
10233 cp_error ("`%D' cannot have default arguments", decl);
10238 /* Get the struct, enum or union (CODE says which) with tag NAME.
10239 Define the tag as a forward-reference if it is not defined.
10241 C++: If a class derivation is given, process it here, and report
10242 an error if multiple derivation declarations are not identical.
10244 If this is a definition, come in through xref_tag and only look in
10245 the current frame for the name (since C++ allows new names in any
10249 xref_tag (code_type_node, name, binfo, globalize)
10250 tree code_type_node;
10254 enum tag_types tag_code;
10255 enum tree_code code;
10257 register tree ref, t;
10258 struct binding_level *b = inner_binding_level;
10260 tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
10265 case signature_type:
10266 code = RECORD_TYPE;
10272 code = ENUMERAL_TYPE;
10275 my_friendly_abort (18);
10278 /* If a cross reference is requested, look up the type
10279 already defined for this tag and return it. */
10280 if (TREE_CODE_CLASS (TREE_CODE (name)) == 't')
10283 name = TYPE_NESTED_NAME (t);
10286 t = IDENTIFIER_TYPE_VALUE (name);
10287 if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM)
10292 if (pedantic && t && TREE_CODE (t) == TEMPLATE_TYPE_PARM)
10294 cp_pedwarn ("redeclaration of template type-parameter `%T'", name);
10295 cp_pedwarn_at (" previously declared here", t);
10297 /* If we know we are defining this tag, only look it up in this scope
10298 * and don't try to find it as a type. */
10299 if (t && TYPE_CONTEXT(t) && TREE_MANGLED (name))
10302 ref = lookup_tag (code, name, b, 1);
10309 ref = lookup_tag (code, name, b, 0);
10313 /* Try finding it as a type declaration. If that wins, use it. */
10314 ref = lookup_name (name, 1);
10315 if (ref && TREE_CODE (ref) == TYPE_DECL
10316 && TREE_CODE (TREE_TYPE (ref)) == code)
10317 ref = TREE_TYPE (ref);
10323 push_obstacks_nochange ();
10327 /* If no such tag is yet defined, create a forward-reference node
10328 and record it as the "definition".
10329 When a real declaration of this type is found,
10330 the forward-reference will be altered into a real type. */
10332 /* In C++, since these migrate into the global scope, we must
10333 build them on the permanent obstack. */
10335 temp = allocation_temporary_p ();
10337 end_temporary_allocation ();
10339 if (code == ENUMERAL_TYPE)
10341 ref = make_node (ENUMERAL_TYPE);
10343 /* Give the type a default layout like unsigned int
10344 to avoid crashing if it does not get defined. */
10345 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
10346 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
10347 TREE_UNSIGNED (ref) = 1;
10348 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
10349 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
10350 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
10352 /* Enable us to recognize when a type is created in class context.
10353 To do nested classes correctly, this should probably be cleared
10354 out when we leave this classes scope. Currently this in only
10355 done in `start_enum'. */
10357 pushtag (name, ref, globalize);
10361 struct binding_level *old_b = class_binding_level;
10363 ref = make_lang_type (code);
10365 if (tag_code == signature_type)
10367 SET_SIGNATURE (ref);
10368 /* Since a signature type will be turned into the type
10369 of signature tables, it's not only an interface. */
10370 CLASSTYPE_INTERFACE_ONLY (ref) = 0;
10371 SET_CLASSTYPE_INTERFACE_KNOWN (ref);
10372 /* A signature doesn't have a vtable. */
10373 CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
10376 #ifdef NONNESTED_CLASSES
10377 /* Class types don't nest the way enums do. */
10378 class_binding_level = (struct binding_level *)0;
10380 pushtag (name, ref, globalize);
10381 class_binding_level = old_b;
10386 /* If it no longer looks like a nested type, make sure it's
10387 in global scope. */
10388 if (b == global_binding_level && !class_binding_level
10389 && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
10390 IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
10394 xref_basetypes (code_type_node, name, ref, binfo);
10398 /* Until the type is defined, tentatively accept whatever
10399 structure tag the user hands us. */
10400 if (TYPE_SIZE (ref) == NULL_TREE
10401 && ref != current_class_type
10402 /* Have to check this, in case we have contradictory tag info. */
10403 && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
10405 if (tag_code == class_type)
10406 CLASSTYPE_DECLARED_CLASS (ref) = 1;
10407 else if (tag_code == record_type || tag_code == signature_type)
10408 CLASSTYPE_DECLARED_CLASS (ref) = 0;
10417 xref_basetypes (code_type_node, name, ref, binfo)
10418 tree code_type_node;
10422 /* In the declaration `A : X, Y, ... Z' we mark all the types
10423 (A, X, Y, ..., Z) so we can check for duplicates. */
10426 enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
10428 if (tag_code == union_type)
10430 cp_error ("derived union `%T' invalid", ref);
10434 len = list_length (binfo);
10435 push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref));
10437 SET_CLASSTYPE_MARKED (ref);
10438 BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
10440 for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
10442 /* The base of a derived struct is public by default. */
10444 = (TREE_PURPOSE (binfo) == access_public_node
10445 || TREE_PURPOSE (binfo) == access_public_virtual_node
10446 || (tag_code != class_type
10447 && (TREE_PURPOSE (binfo) == access_default_node
10448 || TREE_PURPOSE (binfo) == access_default_virtual_node)));
10449 int via_protected = TREE_PURPOSE (binfo) == access_protected_node;
10451 = (TREE_PURPOSE (binfo) == access_private_virtual_node
10452 || TREE_PURPOSE (binfo) == access_public_virtual_node
10453 || TREE_PURPOSE (binfo) == access_default_virtual_node);
10454 tree basetype = TREE_VALUE (binfo);
10457 GNU_xref_hier (IDENTIFIER_POINTER (name),
10458 IDENTIFIER_POINTER (TREE_VALUE (binfo)),
10459 via_public, via_virtual, 0);
10461 if (basetype && TREE_CODE (basetype) == TYPE_DECL)
10462 basetype = TREE_TYPE (basetype);
10464 || (TREE_CODE (basetype) != RECORD_TYPE
10465 && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM))
10467 cp_error ("base type `%T' fails to be a struct or class type",
10468 TREE_VALUE (binfo));
10472 /* This code replaces similar code in layout_basetypes. */
10473 else if (TREE_CODE (basetype) != TEMPLATE_TYPE_PARM
10474 && TYPE_SIZE (complete_type (basetype)) == NULL_TREE)
10476 cp_error ("base class `%T' has incomplete type", basetype);
10482 if (CLASSTYPE_MARKED (basetype))
10484 if (basetype == ref)
10485 cp_error ("recursive type `%T' undefined", basetype);
10487 cp_error ("duplicate base type `%T' invalid", basetype);
10491 /* Note that the BINFO records which describe individual
10492 inheritances are *not* shared in the lattice! They
10493 cannot be shared because a given baseclass may be
10494 inherited with different `accessibility' by different
10495 derived classes. (Each BINFO record describing an
10496 individual inheritance contains flags which say what
10497 the `accessibility' of that particular inheritance is.) */
10499 base_binfo = make_binfo (integer_zero_node, basetype,
10500 TYPE_BINFO_VTABLE (basetype),
10501 TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
10503 TREE_VEC_ELT (binfos, i) = base_binfo;
10504 TREE_VIA_PUBLIC (base_binfo) = via_public;
10505 TREE_VIA_PROTECTED (base_binfo) = via_protected;
10506 TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
10507 BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref);
10509 SET_CLASSTYPE_MARKED (basetype);
10511 /* We are free to modify these bits because they are meaningless
10512 at top level, and BASETYPE is a top-level type. */
10513 if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
10515 TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
10516 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10519 TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
10520 TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype);
10521 TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
10522 CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
10527 TREE_VEC_LENGTH (binfos) = i;
10529 BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
10532 TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
10534 TYPE_USES_MULTIPLE_INHERITANCE (ref)
10535 = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
10536 if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
10537 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10539 /* Unmark all the types. */
10541 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
10542 CLEAR_CLASSTYPE_MARKED (ref);
10548 static tree current_local_enum = NULL_TREE;
10550 /* Begin compiling the definition of an enumeration type.
10551 NAME is its name (or null if anonymous).
10552 Returns the type object, as yet incomplete.
10553 Also records info about it so that build_enumerator
10554 may be used to declare the individual values as they are read. */
10560 register tree enumtype = NULL_TREE;
10561 struct binding_level *b = inner_binding_level;
10563 /* If this is the real definition for a previous forward reference,
10564 fill in the contents in the same object that used to be the
10565 forward reference. */
10567 if (name != NULL_TREE)
10568 enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
10570 if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10571 cp_error ("multiple definition of enum `%T'", enumtype);
10574 enumtype = make_node (ENUMERAL_TYPE);
10575 pushtag (name, enumtype, 0);
10578 if (current_class_type)
10579 TREE_ADDRESSABLE (b->tags) = 1;
10580 current_local_enum = NULL_TREE;
10582 /* We copy this value because enumerated type constants
10583 are really of the type of the enumerator, not integer_type_node. */
10584 enum_next_value = copy_node (integer_zero_node);
10587 GNU_xref_decl (current_function_decl, enumtype);
10591 /* After processing and defining all the values of an enumeration type,
10592 install their decls in the enumeration type and finish it off.
10593 ENUMTYPE is the type object and VALUES a list of name-value pairs.
10594 Returns ENUMTYPE. */
10597 finish_enum (enumtype, values)
10598 register tree enumtype, values;
10600 register tree minnode, maxnode;
10601 /* Calculate the maximum value of any enumerator in this type. */
10605 register tree pair;
10606 register tree value = DECL_INITIAL (TREE_VALUE (values));
10608 if (! current_template_parms)
10610 /* Speed up the main loop by performing some precalculations */
10611 TREE_TYPE (TREE_VALUE (values)) = enumtype;
10612 TREE_TYPE (value) = enumtype;
10613 minnode = maxnode = value;
10615 TREE_VALUE (values) = value;
10617 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
10619 value = DECL_INITIAL (TREE_VALUE (pair));
10620 if (! current_template_parms)
10622 TREE_TYPE (TREE_VALUE (pair)) = enumtype;
10623 TREE_TYPE (value) = enumtype;
10624 if (tree_int_cst_lt (maxnode, value))
10626 else if (tree_int_cst_lt (value, minnode))
10629 TREE_VALUE (pair) = value;
10633 maxnode = minnode = integer_zero_node;
10635 TYPE_VALUES (enumtype) = values;
10637 if (current_template_parms)
10641 int unsignedp = tree_int_cst_sgn (minnode) >= 0;
10642 int lowprec = min_precision (minnode, unsignedp);
10643 int highprec = min_precision (maxnode, unsignedp);
10644 int precision = MAX (lowprec, highprec);
10646 TYPE_SIZE (enumtype) = NULL_TREE;
10648 /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */
10650 TYPE_PRECISION (enumtype) = precision;
10652 fixup_unsigned_type (enumtype);
10654 fixup_signed_type (enumtype);
10656 if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node)))
10657 /* Use the width of the narrowest normal C type which is wide enough. */
10658 TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size
10661 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10663 TYPE_SIZE (enumtype) = 0;
10664 layout_type (enumtype);
10670 /* Fix up all variant types of this enum type. */
10671 for (tem = TYPE_MAIN_VARIANT (enumtype); tem;
10672 tem = TYPE_NEXT_VARIANT (tem))
10674 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
10675 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
10676 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
10677 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
10678 TYPE_MODE (tem) = TYPE_MODE (enumtype);
10679 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
10680 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
10681 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
10685 /* Finish debugging output for this type. */
10686 rest_of_type_compilation (enumtype, global_bindings_p ());
10691 /* Build and install a CONST_DECL for one value of the
10692 current enumeration type (one that was begun with start_enum).
10693 Return a tree-list containing the name and its value.
10694 Assignment of sequential values by default is handled here. */
10697 build_enumerator (name, value)
10701 /* Change this to zero if we find VALUE is not shareable. */
10704 /* Remove no-op casts from the value. */
10706 STRIP_TYPE_NOPS (value);
10708 if (! current_template_parms)
10710 /* Validate and default VALUE. */
10711 if (value != NULL_TREE)
10713 if (TREE_READONLY_DECL_P (value))
10715 value = decl_constant_value (value);
10719 if (TREE_CODE (value) == INTEGER_CST)
10721 value = default_conversion (value);
10722 constant_expression_warning (value);
10726 cp_error ("enumerator value for `%D' not integer constant", name);
10731 /* The order of things is reversed here so that we
10732 can check for possible sharing of enum values,
10733 to keep that from happening. */
10734 /* Default based on previous value. */
10735 if (value == NULL_TREE && ! current_template_parms)
10737 value = enum_next_value;
10739 cp_error ("overflow in enumeration values at `%D'", name);
10742 /* Remove no-op casts from the value. */
10744 STRIP_TYPE_NOPS (value);
10746 /* Make up for hacks in lex.c. */
10747 if (value == integer_zero_node)
10748 value = build_int_2 (0, 0);
10749 else if (value == integer_one_node)
10750 value = build_int_2 (1, 0);
10751 else if (TREE_CODE (value) == INTEGER_CST
10753 || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
10755 value = copy_node (value);
10756 TREE_TYPE (value) = integer_type_node;
10760 /* C++ associates enums with global, function, or class declarations. */
10762 decl = current_scope ();
10763 if (decl && decl == current_class_type)
10765 /* This enum declaration is local to the class, so we must put
10766 it in that class's list of decls. */
10767 decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
10768 DECL_INITIAL (decl) = value;
10769 TREE_READONLY (decl) = 1;
10770 pushdecl_class_level (decl);
10771 TREE_CHAIN (decl) = current_local_enum;
10772 current_local_enum = decl;
10776 /* It's a global enum, or it's local to a function. (Note local to
10777 a function could mean local to a class method. */
10778 decl = build_decl (CONST_DECL, name, integer_type_node);
10779 DECL_INITIAL (decl) = value;
10782 GNU_xref_decl (current_function_decl, decl);
10785 if (! current_template_parms)
10787 /* Set basis for default for next value. */
10788 enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
10789 integer_one_node, PLUS_EXPR);
10790 enum_overflow = tree_int_cst_lt (enum_next_value, value);
10792 if (enum_next_value == integer_one_node)
10793 enum_next_value = copy_node (enum_next_value);
10796 result = saveable_tree_cons (name, decl, NULL_TREE);
10801 grok_enum_decls (type, decl)
10804 tree d = current_local_enum;
10806 if (d == NULL_TREE)
10811 TREE_TYPE (d) = type;
10812 if (TREE_CHAIN (d) == NULL_TREE)
10814 TREE_CHAIN (d) = decl;
10817 d = TREE_CHAIN (d);
10820 decl = current_local_enum;
10821 current_local_enum = NULL_TREE;
10826 static int function_depth;
10828 /* Create the FUNCTION_DECL for a function definition.
10829 DECLSPECS and DECLARATOR are the parts of the declaration;
10830 they describe the function's name and the type it returns,
10831 but twisted together in a fashion that parallels the syntax of C.
10833 This function creates a binding context for the function body
10834 as well as setting up the FUNCTION_DECL in current_function_decl.
10836 Returns 1 on success. If the DECLARATOR is not suitable for a function
10837 (it defines a datum instead), we return 0, which tells
10838 yyparse to report a parse error.
10840 For C++, we must first check whether that datum makes any sense.
10841 For example, "class A local_a(1,2);" means that variable local_a
10842 is an aggregate of type A, which should have a constructor
10843 applied to it with the argument list [1, 2].
10845 @@ There is currently no way to retrieve the storage
10846 @@ allocated to FUNCTION (or all of its parms) if we return
10847 @@ something we had previously. */
10850 start_function (declspecs, declarator, raises, attrs, pre_parsed_p)
10851 tree declspecs, declarator, raises, attrs;
10855 tree ctype = NULL_TREE;
10858 extern int have_extern_spec;
10859 extern int used_extern_spec;
10860 int doing_friend = 0;
10862 /* Sanity check. */
10863 my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
10864 my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
10866 /* Assume, until we see it does. */
10867 current_function_returns_value = 0;
10868 current_function_returns_null = 0;
10869 warn_about_return_type = 0;
10871 shadowed_labels = 0;
10872 current_function_assigns_this = 0;
10873 current_function_just_assigned_this = 0;
10874 current_function_parms_stored = 0;
10875 original_result_rtx = NULL_RTX;
10876 base_init_expr = NULL_TREE;
10877 protect_list = NULL_TREE;
10878 current_base_init_list = NULL_TREE;
10879 current_member_init_list = NULL_TREE;
10880 ctor_label = dtor_label = NULL_TREE;
10882 clear_temp_name ();
10884 /* This should only be done once on the top most decl. */
10885 if (have_extern_spec && !used_extern_spec)
10887 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
10888 used_extern_spec = 1;
10893 decl1 = declarator;
10895 if (! DECL_ARGUMENTS (decl1)
10896 && !DECL_STATIC_FUNCTION_P (decl1)
10897 && DECL_CONTEXT (decl1)
10898 && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
10899 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
10901 cp_error ("redeclaration of `%#D'", decl1);
10902 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
10903 cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
10904 else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
10905 cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
10908 fntype = TREE_TYPE (decl1);
10909 if (TREE_CODE (fntype) == METHOD_TYPE)
10910 ctype = TYPE_METHOD_BASETYPE (fntype);
10912 /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
10913 class is in the (lexical) scope of the class in which it is
10915 if (!ctype && DECL_FRIEND_P (decl1))
10917 ctype = DECL_CLASS_CONTEXT (decl1);
10919 /* CTYPE could be null here if we're dealing with a template;
10920 for example, `inline friend float foo()' inside a template
10921 will have no CTYPE set. */
10922 if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
10928 raises = TYPE_RAISES_EXCEPTIONS (fntype);
10930 /* In a fcn definition, arg types must be complete. */
10931 require_complete_types_for_parms (DECL_ARGUMENTS (decl1));
10933 /* In case some arg types were completed since the declaration was
10934 parsed, fix up the decls. */
10936 tree t = DECL_ARGUMENTS (decl1);
10937 for (; t; t = TREE_CHAIN (t))
10938 layout_decl (t, 0);
10941 last_function_parms = DECL_ARGUMENTS (decl1);
10942 last_function_parm_tags = NULL_TREE;
10946 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises,
10948 /* If the declarator is not suitable for a function definition,
10949 cause a syntax error. */
10950 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
10952 fntype = TREE_TYPE (decl1);
10954 restype = TREE_TYPE (fntype);
10955 if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
10956 && ! CLASSTYPE_GOT_SEMICOLON (restype))
10958 cp_error ("semicolon missing after declaration of `%#T'", restype);
10959 shadow_tag (build_tree_list (NULL_TREE, restype));
10960 CLASSTYPE_GOT_SEMICOLON (restype) = 1;
10961 if (TREE_CODE (fntype) == FUNCTION_TYPE)
10962 fntype = build_function_type (integer_type_node,
10963 TYPE_ARG_TYPES (fntype));
10965 fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
10967 TYPE_ARG_TYPES (fntype));
10968 TREE_TYPE (decl1) = fntype;
10971 if (TREE_CODE (fntype) == METHOD_TYPE)
10972 ctype = TYPE_METHOD_BASETYPE (fntype);
10973 else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
10974 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
10975 && DECL_CONTEXT (decl1) == NULL_TREE)
10977 /* If this doesn't return integer_type, complain. */
10978 if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
10980 if (pedantic || warn_return_type)
10981 pedwarn ("return type for `main' changed to `int'");
10982 TREE_TYPE (decl1) = fntype = default_function_type;
10984 warn_about_return_type = 0;
10988 /* Warn if function was previously implicitly declared
10989 (but not if we warned then). */
10990 if (! warn_implicit
10991 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
10992 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
10994 current_function_decl = decl1;
10995 /* Save the parm names or decls from this function's declarator
10996 where store_parm_decls will find them. */
10997 current_function_parms = last_function_parms;
10998 current_function_parm_tags = last_function_parm_tags;
11000 announce_function (decl1);
11002 if (! current_template_parms || ! uses_template_parms (TREE_TYPE (fntype)))
11004 if (TYPE_SIZE (complete_type (TREE_TYPE (fntype))) == NULL_TREE)
11006 cp_error ("return-type `%#T' is an incomplete type",
11007 TREE_TYPE (fntype));
11009 /* Make it return void instead, but don't change the
11010 type of the DECL_RESULT, in case we have a named return value. */
11013 = build_cplus_method_type (build_type_variant (ctype,
11014 TREE_READONLY (decl1),
11015 TREE_SIDE_EFFECTS (decl1)),
11017 FUNCTION_ARG_CHAIN (decl1));
11020 = build_function_type (void_type_node,
11021 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
11022 DECL_RESULT (decl1)
11023 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype)));
11024 TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype));
11025 TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype));
11028 if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype))
11029 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype)))
11030 abstract_virtuals_error (decl1, TREE_TYPE (fntype));
11033 if (warn_about_return_type)
11034 warning ("return-type defaults to `int'");
11036 /* Make the init_value nonzero so pushdecl knows this is not tentative.
11037 error_mark_node is replaced below (in poplevel) with the BLOCK. */
11038 DECL_INITIAL (decl1) = error_mark_node;
11040 /* This function exists in static storage.
11041 (This does not mean `static' in the C sense!) */
11042 TREE_STATIC (decl1) = 1;
11044 /* Record the decl so that the function name is defined.
11045 If we already have a decl for this name, and it is a FUNCTION_DECL,
11046 use the old decl. */
11048 if (current_template_parms)
11049 push_template_decl (decl1);
11050 else if (pre_parsed_p == 0)
11052 decl1 = pushdecl (decl1);
11053 DECL_MAIN_VARIANT (decl1) = decl1;
11054 fntype = TREE_TYPE (decl1);
11057 current_function_decl = decl1;
11059 if (DECL_INTERFACE_KNOWN (decl1))
11061 if (DECL_NOT_REALLY_EXTERN (decl1))
11062 DECL_EXTERNAL (decl1) = 0;
11064 /* If this function belongs to an interface, it is public.
11065 If it belongs to someone else's interface, it is also external.
11066 It doesn't matter whether it's inline or not. */
11067 else if (interface_unknown == 0
11068 && (! DECL_TEMPLATE_INSTANTIATION (decl1)
11069 || flag_external_templates))
11071 if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)
11072 || current_template_parms)
11073 DECL_EXTERNAL (decl1)
11075 || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines));
11077 DECL_EXTERNAL (decl1) = 0;
11078 DECL_NOT_REALLY_EXTERN (decl1) = 0;
11079 DECL_INTERFACE_KNOWN (decl1) = 1;
11083 /* This is a definition, not a reference.
11084 So clear DECL_EXTERNAL. */
11085 DECL_EXTERNAL (decl1) = 0;
11087 if ((DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1))
11088 && ! DECL_INTERFACE_KNOWN (decl1)
11089 /* Don't try to defer nested functions for now. */
11090 && ! decl_function_context (decl1))
11091 DECL_DEFER_OUTPUT (decl1) = 1;
11094 DECL_INTERFACE_KNOWN (decl1) = 1;
11095 if (DECL_C_STATIC (decl1))
11096 TREE_PUBLIC (decl1) = 0;
11100 if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
11102 if (TREE_CODE (fntype) == METHOD_TYPE)
11103 TREE_TYPE (decl1) = fntype
11104 = build_function_type (TREE_TYPE (fntype),
11105 TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
11106 current_function_parms = TREE_CHAIN (current_function_parms);
11107 DECL_ARGUMENTS (decl1) = current_function_parms;
11110 restype = TREE_TYPE (fntype);
11114 push_nested_class (ctype, 1);
11116 /* If we're compiling a friend function, neither of the variables
11117 current_class_decl nor current_class_type will have values. */
11118 if (! doing_friend)
11120 /* We know that this was set up by `grokclassfn'.
11121 We do not wait until `store_parm_decls', since evil
11122 parse errors may never get us to that point. Here
11123 we keep the consistency between `current_class_type'
11124 and `current_class_decl'. */
11125 tree t = current_function_parms;
11127 my_friendly_assert (t != NULL_TREE
11128 && TREE_CODE (t) == PARM_DECL, 162);
11130 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
11132 int i = suspend_momentary ();
11134 /* Fool build_indirect_ref. */
11135 current_class_decl = NULL_TREE;
11136 C_C_D = build_indirect_ref (t, NULL_PTR);
11137 current_class_decl = t;
11138 resume_momentary (i);
11141 /* We're having a signature pointer here. */
11142 C_C_D = current_class_decl = t;
11148 if (DECL_STATIC_FUNCTION_P (decl1))
11149 push_nested_class (DECL_CONTEXT (decl1), 2);
11151 push_memoized_context (0, 1);
11152 current_class_decl = C_C_D = NULL_TREE;
11156 current_binding_level->parm_flag = 1;
11158 GNU_xref_function (decl1, current_function_parms);
11161 cplus_decl_attributes (decl1, NULL_TREE, attrs);
11162 make_function_rtl (decl1);
11164 /* Promote the value to int before returning it. */
11165 if (C_PROMOTING_INTEGER_TYPE_P (restype))
11166 restype = type_promotes_to (restype);
11168 /* If this fcn was already referenced via a block-scope `extern' decl
11169 (or an implicit decl), propagate certain information about the usage. */
11170 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
11171 TREE_ADDRESSABLE (decl1) = 1;
11173 if (DECL_RESULT (decl1) == NULL_TREE)
11175 DECL_RESULT (decl1)
11176 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
11177 TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype);
11178 TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype);
11181 /* Allocate further tree nodes temporarily during compilation
11182 of this function only. Tiemann moved up here from bottom of fn. */
11183 temporary_allocation ();
11185 if (current_template_parms)
11187 extern tree last_tree;
11188 ++minimal_parse_mode;
11189 last_tree = DECL_SAVED_TREE (decl1)
11190 = build_nt (EXPR_STMT, void_zero_node);
11195 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1))
11196 && DECL_LANGUAGE (decl1) == lang_cplusplus)
11198 dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11199 ctor_label = NULL_TREE;
11203 dtor_label = NULL_TREE;
11204 if (DECL_CONSTRUCTOR_P (decl1))
11205 ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11212 expand_start_early_try_stmts ()
11216 expand_start_try_stmts ();
11217 insns = get_insns ();
11219 store_in_parms (insns);
11223 store_in_parms (insns)
11226 rtx last_parm_insn;
11228 last_parm_insn = get_first_nonparm_insn ();
11229 if (last_parm_insn == NULL_RTX)
11230 emit_insns (insns);
11232 emit_insns_before (insns, previous_insn (last_parm_insn));
11235 /* Store the parameter declarations into the current function declaration.
11236 This is called after parsing the parameter declarations, before
11237 digesting the body of the function.
11239 Also install to binding contour return value identifier, if any. */
11242 store_parm_decls ()
11244 register tree fndecl = current_function_decl;
11245 register tree parm;
11246 int parms_have_cleanups = 0;
11248 /* This is either a chain of PARM_DECLs (when a prototype is used). */
11249 tree specparms = current_function_parms;
11251 /* This is a list of types declared among parms in a prototype. */
11252 tree parmtags = current_function_parm_tags;
11254 /* This is a chain of any other decls that came in among the parm
11255 declarations. If a parm is declared with enum {foo, bar} x;
11256 then CONST_DECLs for foo and bar are put here. */
11257 tree nonparms = NULL_TREE;
11259 if (toplevel_bindings_p ())
11260 fatal ("parse errors have confused me too much");
11262 /* Initialize RTL machinery. */
11263 init_function_start (fndecl, input_filename, lineno);
11265 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
11266 declare_function_name ();
11268 /* Create a binding level for the parms. */
11269 expand_start_bindings (0);
11271 if (specparms != NULL_TREE)
11273 /* This case is when the function was defined with an ANSI prototype.
11274 The parms already have decls, so we need not do anything here
11275 except record them as in effect
11276 and complain if any redundant old-style parm decls were written. */
11278 register tree next;
11280 /* Must clear this because it might contain TYPE_DECLs declared
11282 storedecls (NULL_TREE);
11284 for (parm = nreverse (specparms); parm; parm = next)
11286 next = TREE_CHAIN (parm);
11287 if (TREE_CODE (parm) == PARM_DECL)
11290 if (DECL_NAME (parm) == NULL_TREE)
11294 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
11295 cp_error ("parameter `%D' declared void", parm);
11298 /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
11299 A parameter is assumed not to have any side effects.
11300 If this should change for any reason, then this
11301 will have to wrap the bashed reference type in a save_expr.
11303 Also, if the parameter type is declared to be an X
11304 and there is an X(X&) constructor, we cannot lay it
11305 into the stack (any more), so we make this parameter
11306 look like it is really of reference type. Functions
11307 which pass parameters to this function will know to
11308 create a temporary in their frame, and pass a reference
11311 if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
11312 && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
11313 SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
11317 if (! current_template_parms
11318 && (cleanup = maybe_build_cleanup (parm), cleanup))
11320 expand_decl (parm);
11321 if (! cp_expand_decl_cleanup (parm, cleanup))
11322 cp_error ("parser lost in parsing declaration of `%D'",
11324 parms_have_cleanups = 1;
11329 /* If we find an enum constant or a type tag,
11330 put it aside for the moment. */
11331 TREE_CHAIN (parm) = NULL_TREE;
11332 nonparms = chainon (nonparms, parm);
11336 /* Get the decls in their original chain order
11337 and record in the function. This is all and only the
11338 PARM_DECLs that were pushed into scope by the loop above. */
11339 DECL_ARGUMENTS (fndecl) = getdecls ();
11341 storetags (chainon (parmtags, gettags ()));
11344 DECL_ARGUMENTS (fndecl) = NULL_TREE;
11346 /* Now store the final chain of decls for the arguments
11347 as the decl-chain of the current lexical scope.
11348 Put the enumerators in as well, at the front so that
11349 DECL_ARGUMENTS is not modified. */
11351 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
11353 /* Initialize the RTL code for the function. */
11354 DECL_SAVED_INSNS (fndecl) = NULL_RTX;
11355 if (! current_template_parms)
11356 expand_function_start (fndecl, parms_have_cleanups);
11358 /* Create a binding contour which can be used to catch
11359 cleanup-generated temporaries. Also, if the return value needs or
11360 has initialization, deal with that now. */
11361 if (parms_have_cleanups)
11364 expand_start_bindings (0);
11367 current_function_parms_stored = 1;
11369 /* If this function is `main', emit a call to `__main'
11370 to run global initializers, etc. */
11371 if (DECL_NAME (fndecl)
11372 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11373 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
11374 && DECL_CONTEXT (fndecl) == NULL_TREE)
11376 expand_main_function ();
11379 /* Take care of exception handling things. */
11380 if (! current_template_parms && flag_handle_exceptions)
11385 /* Mark the start of a stack unwinder if we need one. */
11386 start_eh_unwinder ();
11388 /* Do the starting of the exception specifications, if we have any. */
11389 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl)))
11390 expand_start_eh_spec ();
11392 insns = get_insns ();
11396 store_in_parms (insns);
11398 last_dtor_insn = get_last_insn ();
11401 /* Bind a name and initialization to the return value of
11402 the current function. */
11404 store_return_init (return_id, init)
11405 tree return_id, init;
11407 tree decl = DECL_RESULT (current_function_decl);
11410 /* Give this error as many times as there are occurrences,
11411 so that users can use Emacs compilation buffers to find
11412 and fix all such places. */
11413 pedwarn ("ANSI C++ does not permit named return values");
11415 if (return_id != NULL_TREE)
11417 if (DECL_NAME (decl) == NULL_TREE)
11419 DECL_NAME (decl) = return_id;
11420 DECL_ASSEMBLER_NAME (decl) = return_id;
11423 error ("return identifier `%s' already in place",
11424 IDENTIFIER_POINTER (DECL_NAME (decl)));
11427 /* Can't let this happen for constructors. */
11428 if (DECL_CONSTRUCTOR_P (current_function_decl))
11430 error ("can't redefine default return value for constructors");
11434 /* If we have a named return value, put that in our scope as well. */
11435 if (DECL_NAME (decl) != NULL_TREE)
11437 /* If this named return value comes in a register,
11438 put it in a pseudo-register. */
11439 if (DECL_REGISTER (decl))
11441 original_result_rtx = DECL_RTL (decl);
11442 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
11445 /* Let `cp_finish_decl' know that this initializer is ok. */
11446 DECL_INITIAL (decl) = init;
11448 cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
11453 /* Finish up a function declaration and compile that function
11454 all the way to assembler language output. The free the storage
11455 for the function definition.
11457 This is called after parsing the body of the function definition.
11458 LINENO is the current line number.
11460 C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11461 (and expand_end_bindings) must be made to take care of the binding
11462 contour for the base initializers. This is only relevant for
11466 finish_function (lineno, call_poplevel, nested)
11471 register tree fndecl = current_function_decl;
11472 tree fntype, ctype = NULL_TREE;
11473 rtx last_parm_insn, insns;
11474 /* Label to use if this function is supposed to return a value. */
11475 tree no_return_label = NULL_TREE;
11476 tree decls = NULL_TREE;
11478 /* When we get some parse errors, we can end up without a
11479 current_function_decl, so cope. */
11480 if (fndecl == NULL_TREE)
11483 if (! nested && decl_function_context (fndecl) != NULL_TREE)
11486 fntype = TREE_TYPE (fndecl);
11488 /* TREE_READONLY (fndecl) = 1;
11489 This caused &foo to be of type ptr-to-const-function
11490 which then got a warning when stored in a ptr-to-function variable. */
11492 /* This happens on strange parse errors. */
11493 if (! current_function_parms_stored)
11496 store_parm_decls ();
11499 if (current_template_parms)
11501 if (DECL_CONSTRUCTOR_P (fndecl) && call_poplevel)
11503 decls = getdecls ();
11504 expand_end_bindings (decls, decls != NULL_TREE, 0);
11505 poplevel (decls != NULL_TREE, 0, 0);
11510 if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/)
11512 tree ttype = target_type (fntype);
11515 if (IS_AGGR_TYPE (ttype))
11516 /* Let debugger know it should output info for this type. */
11517 note_debug_info_needed (ttype);
11519 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
11521 ttype = target_type (TREE_TYPE (parmdecl));
11522 if (IS_AGGR_TYPE (ttype))
11523 /* Let debugger know it should output info for this type. */
11524 note_debug_info_needed (ttype);
11528 /* Clean house because we will need to reorder insns here. */
11529 do_pending_stack_adjust ();
11533 tree binfo = TYPE_BINFO (current_class_type);
11534 tree cond = integer_one_node;
11536 tree in_charge_node = lookup_name (in_charge_identifier, 0);
11538 int ok_to_optimize_dtor = 0;
11539 int empty_dtor = get_last_insn () == last_dtor_insn;
11541 if (current_function_assigns_this)
11542 cond = build (NE_EXPR, boolean_type_node,
11543 current_class_decl, integer_zero_node);
11546 int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
11548 /* If this destructor is empty, then we don't need to check
11549 whether `this' is NULL in some cases. */
11550 if ((flag_this_is_variable & 1) == 0)
11551 ok_to_optimize_dtor = 1;
11552 else if (empty_dtor)
11553 ok_to_optimize_dtor
11554 = (n_baseclasses == 0
11555 || (n_baseclasses == 1
11556 && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
11559 /* These initializations might go inline. Protect
11560 the binding level of the parms. */
11562 expand_start_bindings (0);
11564 if (current_function_assigns_this)
11566 current_function_assigns_this = 0;
11567 current_function_just_assigned_this = 0;
11570 /* Generate the code to call destructor on base class.
11571 If this destructor belongs to a class with virtual
11572 functions, then set the virtual function table
11573 pointer to represent the type of our base class. */
11575 /* This side-effect makes call to `build_delete' generate the
11576 code we have to have at the end of this destructor. */
11577 TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
11579 /* These are two cases where we cannot delegate deletion. */
11580 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
11581 || TYPE_GETS_REG_DELETE (current_class_type))
11582 exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
11583 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11585 exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
11586 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11588 /* If we did not assign to this, then `this' is non-zero at
11589 the end of a destructor. As a special optimization, don't
11590 emit test if this is an empty destructor. If it does nothing,
11591 it does nothing. If it calls a base destructor, the base
11592 destructor will perform the test. */
11594 if (exprstmt != error_mark_node
11595 && (TREE_CODE (exprstmt) != NOP_EXPR
11596 || TREE_OPERAND (exprstmt, 0) != integer_zero_node
11597 || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
11599 expand_label (dtor_label);
11600 if (cond != integer_one_node)
11601 expand_start_cond (cond, 0);
11602 if (exprstmt != void_zero_node)
11603 /* Don't call `expand_expr_stmt' if we're not going to do
11604 anything, since -Wall will give a diagnostic. */
11605 expand_expr_stmt (exprstmt);
11607 /* Run destructor on all virtual baseclasses. */
11608 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11610 tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
11611 expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
11612 in_charge_node, integer_two_node), 0);
11615 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
11617 tree ptr = convert_pointer_to_vbase (BINFO_TYPE (vbases), current_class_decl);
11618 expand_expr_stmt (build_delete (build_pointer_type (BINFO_TYPE (vbases)),
11619 ptr, integer_zero_node,
11620 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
11622 vbases = TREE_CHAIN (vbases);
11624 expand_end_cond ();
11627 do_pending_stack_adjust ();
11628 if (cond != integer_one_node)
11629 expand_end_cond ();
11632 TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
11634 virtual_size = c_sizeof (current_class_type);
11636 /* At the end, call delete if that's what's requested. */
11637 if (TYPE_GETS_REG_DELETE (current_class_type))
11638 /* This NOP_EXPR means we are in a static call context. */
11641 (build_indirect_ref
11642 (build1 (NOP_EXPR, build_pointer_type (current_class_type),
11645 ansi_opname[(int) DELETE_EXPR],
11646 tree_cons (NULL_TREE, current_class_decl,
11647 build_tree_list (NULL_TREE, virtual_size)),
11648 NULL_TREE, LOOKUP_NORMAL);
11649 else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11650 exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
11653 exprstmt = NULL_TREE;
11657 cond = build (BIT_AND_EXPR, integer_type_node,
11658 in_charge_node, integer_one_node);
11659 expand_start_cond (cond, 0);
11660 expand_expr_stmt (exprstmt);
11661 expand_end_cond ();
11664 /* End of destructor. */
11665 expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
11666 poplevel (2, 0, 0); /* XXX change to 1 */
11668 /* Back to the top of destructor. */
11669 /* Dont execute destructor code if `this' is NULL. */
11673 /* If the dtor is empty, and we know there is not possible way we
11674 could use any vtable entries, before they are possibly set by
11675 a base class dtor, we don't have to setup the vtables, as we
11676 know that any base class dtoring will set up any vtables it
11677 needs. We avoid MI, because one base class dtor can do a
11678 virtual dispatch to an overridden function that would need to
11679 have a non-related vtable set up, we cannot avoid setting up
11680 vtables in that case. We could change this to see if there is
11681 just one vtable. */
11682 if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type))
11684 /* Make all virtual function table pointers in non-virtual base
11685 classes point to CURRENT_CLASS_TYPE's virtual function
11687 expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl);
11689 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11690 expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl);
11693 if (! ok_to_optimize_dtor)
11695 cond = build_binary_op (NE_EXPR,
11696 current_class_decl, integer_zero_node, 1);
11697 expand_start_cond (cond, 0);
11700 insns = get_insns ();
11703 last_parm_insn = get_first_nonparm_insn ();
11704 if (last_parm_insn == NULL_RTX)
11705 last_parm_insn = get_last_insn ();
11707 last_parm_insn = previous_insn (last_parm_insn);
11709 emit_insns_after (insns, last_parm_insn);
11711 if (! ok_to_optimize_dtor)
11712 expand_end_cond ();
11714 else if (current_function_assigns_this)
11716 /* Does not need to call emit_base_init, because
11717 that is done (if needed) just after assignment to this
11720 if (DECL_CONSTRUCTOR_P (current_function_decl))
11722 end_protect_partials ();
11723 expand_label (ctor_label);
11724 ctor_label = NULL_TREE;
11728 decls = getdecls ();
11729 expand_end_bindings (decls, decls != NULL_TREE, 0);
11730 poplevel (decls != NULL_TREE, 0, 0);
11732 c_expand_return (current_class_decl);
11734 else if (TYPE_MAIN_VARIANT (TREE_TYPE (
11735 DECL_RESULT (current_function_decl))) != void_type_node
11736 && return_label != NULL_RTX)
11737 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11739 current_function_assigns_this = 0;
11740 current_function_just_assigned_this = 0;
11741 base_init_expr = NULL_TREE;
11743 else if (DECL_CONSTRUCTOR_P (fndecl))
11745 tree cond, thenclause;
11746 /* Allow constructor for a type to get a new instance of the object
11747 using `build_new'. */
11748 tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
11749 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
11751 DECL_RETURNS_FIRST_ARG (fndecl) = 1;
11753 if (flag_this_is_variable > 0)
11755 cond = build_binary_op (EQ_EXPR,
11756 current_class_decl, integer_zero_node, 1);
11757 thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
11758 build_new (NULL_TREE, current_class_type, void_type_node, 0));
11761 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
11765 if (flag_this_is_variable > 0)
11767 expand_start_cond (cond, 0);
11768 expand_expr_stmt (thenclause);
11769 expand_end_cond ();
11772 /* Emit insns from `emit_base_init' which sets up virtual
11773 function table pointer(s). */
11774 if (base_init_expr)
11776 expand_expr_stmt (base_init_expr);
11777 base_init_expr = NULL_TREE;
11780 insns = get_insns ();
11783 /* This is where the body of the constructor begins.
11784 If there were no insns in this function body, then the
11785 last_parm_insn is also the last insn.
11787 If optimization is enabled, last_parm_insn may move, so
11788 we don't hold on to it (across emit_base_init). */
11789 last_parm_insn = get_first_nonparm_insn ();
11790 if (last_parm_insn == NULL_RTX)
11791 last_parm_insn = get_last_insn ();
11793 last_parm_insn = previous_insn (last_parm_insn);
11795 emit_insns_after (insns, last_parm_insn);
11797 end_protect_partials ();
11799 /* This is where the body of the constructor ends. */
11800 expand_label (ctor_label);
11801 ctor_label = NULL_TREE;
11805 decls = getdecls ();
11806 expand_end_bindings (decls, decls != NULL_TREE, 0);
11807 poplevel (decls != NULL_TREE, 1, 0);
11810 c_expand_return (current_class_decl);
11812 current_function_assigns_this = 0;
11813 current_function_just_assigned_this = 0;
11815 else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11816 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
11817 && DECL_CONTEXT (fndecl) == NULL_TREE)
11819 /* Make it so that `main' always returns 0 by default. */
11821 c_expand_return (integer_one_node);
11823 c_expand_return (integer_zero_node);
11826 else if (return_label != NULL_RTX
11827 && current_function_return_value == NULL_TREE
11828 && ! DECL_NAME (DECL_RESULT (current_function_decl)))
11829 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11831 /* If this function is supposed to return a value, ensure that
11832 we do not fall into the cleanups by mistake. The end of our
11833 function will look like this:
11835 user code (may have return stmt somewhere)
11836 goto no_return_label
11841 NOTE_INSN_FUNCTION_END
11845 If the user omits a return stmt in the USER CODE section, we
11846 will have a control path which reaches NOTE_INSN_FUNCTION_END.
11847 Otherwise, we won't. */
11848 if (no_return_label)
11850 DECL_CONTEXT (no_return_label) = fndecl;
11851 DECL_INITIAL (no_return_label) = error_mark_node;
11852 DECL_SOURCE_FILE (no_return_label) = input_filename;
11853 DECL_SOURCE_LINE (no_return_label) = lineno;
11854 expand_goto (no_return_label);
11859 /* remove the binding contour which is used
11860 to catch cleanup-generated temporaries. */
11861 expand_end_bindings (0, 0, 0);
11862 poplevel (0, 0, 0);
11866 /* Emit label at beginning of cleanup code for parameters. */
11867 emit_label (cleanup_label);
11869 /* Get return value into register if that's where it's supposed to be. */
11870 if (original_result_rtx)
11871 fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
11873 /* Finish building code that will trigger warnings if users forget
11874 to make their functions return values. */
11875 if (no_return_label || cleanup_label)
11876 emit_jump (return_label);
11877 if (no_return_label)
11879 /* We don't need to call `expand_*_return' here because we
11880 don't need any cleanups here--this path of code is only
11881 for error checking purposes. */
11882 expand_label (no_return_label);
11885 /* Generate rtl for function exit. */
11886 expand_function_end (input_filename, lineno, 1);
11888 if (flag_handle_exceptions)
11889 expand_exception_blocks ();
11892 /* This must come after expand_function_end because cleanups might
11893 have declarations (from inline functions) that need to go into
11894 this function's blocks. */
11895 if (current_binding_level->parm_flag != 1)
11896 my_friendly_abort (122);
11897 poplevel (1, 0, 1);
11899 /* reset scope for C++: if we were in the scope of a class,
11900 then when we finish this function, we are not longer so.
11901 This cannot be done until we know for sure that no more
11902 class members will ever be referenced in this function
11903 (i.e., calls to destructors). */
11904 if (current_class_name)
11906 ctype = current_class_type;
11907 pop_nested_class (1);
11910 pop_memoized_context (1);
11912 /* Must mark the RESULT_DECL as being in this function. */
11913 DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
11915 /* Obey `register' declarations if `setjmp' is called in this fn. */
11916 if (flag_traditional && current_function_calls_setjmp)
11917 setjmp_protect (DECL_INITIAL (fndecl));
11919 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
11920 to the FUNCTION_DECL node itself. */
11921 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
11923 if (! current_template_parms)
11925 /* So we can tell if jump_optimize sets it to 1. */
11928 /* Run the optimizers and output the assembler code for this function. */
11929 rest_of_compilation (fndecl);
11931 if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl))
11933 /* Set DECL_EXTERNAL so that assemble_external will be called as
11934 necessary. We'll clear it again in finish_file. */
11935 if (! DECL_EXTERNAL (fndecl))
11936 DECL_NOT_REALLY_EXTERN (fndecl) = 1;
11937 DECL_EXTERNAL (fndecl) = 1;
11938 mark_inline_for_output (fndecl);
11941 if (ctype && TREE_ASM_WRITTEN (fndecl))
11942 note_debug_info_needed (ctype);
11944 current_function_returns_null |= can_reach_end;
11946 /* Since we don't normally go through c_expand_return for constructors,
11947 this normally gets the wrong value.
11948 Also, named return values have their return codes emitted after
11949 NOTE_INSN_FUNCTION_END, confusing jump.c. */
11950 if (DECL_CONSTRUCTOR_P (fndecl)
11951 || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
11952 current_function_returns_null = 0;
11954 if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
11955 cp_warning ("`noreturn' function `%D' does return", fndecl);
11956 else if ((warn_return_type || pedantic)
11957 && current_function_returns_null
11958 && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
11960 /* If this function returns non-void and control can drop through,
11962 cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
11964 /* With just -W, complain only if function returns both with
11965 and without a value. */
11966 else if (extra_warnings
11967 && current_function_returns_value && current_function_returns_null)
11968 warning ("this function may return with or without a value");
11973 /* Free all the tree nodes making up this function. */
11974 /* Switch back to allocating nodes permanently
11975 until we start another function. */
11976 if (current_template_parms)
11978 --minimal_parse_mode;
11979 DECL_SAVED_TREE (fndecl) = TREE_CHAIN (DECL_SAVED_TREE (fndecl));
11983 permanent_allocation (1);
11985 if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
11987 /* Stop pointing to the local nodes about to be freed. */
11988 /* But DECL_INITIAL must remain nonzero so we know this
11989 was an actual function definition. */
11990 DECL_INITIAL (fndecl) = error_mark_node;
11991 /* And we need the arguments for template instantiation. */
11992 if (! current_template_parms)
11994 if (! DECL_CONSTRUCTOR_P (fndecl)
11995 || !(TYPE_USES_VIRTUAL_BASECLASSES
11996 (TYPE_METHOD_BASETYPE (fntype))))
11997 DECL_ARGUMENTS (fndecl) = NULL_TREE;
12001 if (DECL_STATIC_CONSTRUCTOR (fndecl))
12002 static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors);
12003 if (DECL_STATIC_DESTRUCTOR (fndecl))
12004 static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors);
12008 /* Let the error reporting routines know that we're outside a
12009 function. For a nested function, this value is used in
12010 pop_cp_function_context and then reset via pop_function_context. */
12011 current_function_decl = NULL_TREE;
12014 named_label_uses = NULL_TREE;
12015 current_class_decl = NULL_TREE;
12018 /* Create the FUNCTION_DECL for a function definition.
12019 LINE1 is the line number that the definition absolutely begins on.
12020 LINE2 is the line number that the name of the function appears on.
12021 DECLSPECS and DECLARATOR are the parts of the declaration;
12022 they describe the return type and the name of the function,
12023 but twisted together in a fashion that parallels the syntax of C.
12025 This function creates a binding context for the function body
12026 as well as setting up the FUNCTION_DECL in current_function_decl.
12028 Returns a FUNCTION_DECL on success.
12030 If the DECLARATOR is not suitable for a function (it defines a datum
12031 instead), we return 0, which tells yyparse to report a parse error.
12033 May return void_type_node indicating that this method is actually
12034 a friend. See grokfield for more details.
12036 Came here with a `.pushlevel' .
12038 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
12039 CHANGES TO CODE IN `grokfield'. */
12041 start_method (declspecs, declarator, raises)
12042 tree declarator, declspecs, raises;
12044 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises,
12047 /* Something too ugly to handle. */
12048 if (fndecl == NULL_TREE)
12051 /* Pass friends other than inline friend functions back. */
12052 if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
12055 if (TREE_CODE (fndecl) != FUNCTION_DECL)
12056 /* Not a function, tell parser to report parse error. */
12059 if (IS_SIGNATURE (current_class_type))
12061 IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
12062 /* In case we need this info later. */
12063 HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
12066 if (DECL_IN_AGGR_P (fndecl))
12068 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
12070 if (DECL_CONTEXT (fndecl))
12071 cp_error ("`%D' is already defined in class %s", fndecl,
12072 TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
12074 return void_type_node;
12077 DECL_THIS_INLINE (fndecl) = 1;
12079 if (flag_default_inline)
12080 DECL_INLINE (fndecl) = 1;
12082 if (current_template_parms && ! current_function_decl)
12083 push_template_decl (fndecl);
12085 /* We read in the parameters on the maybepermanent_obstack,
12086 but we won't be getting back to them until after we
12087 may have clobbered them. So the call to preserve_data
12088 will keep them safe. */
12091 if (! DECL_FRIEND_P (fndecl))
12093 if (DECL_CHAIN (fndecl) != NULL_TREE)
12095 /* Need a fresh node here so that we don't get circularity
12096 when we link these together. If FNDECL was a friend, then
12097 `pushdecl' does the right thing, which is nothing wrt its
12098 current value of DECL_CHAIN. */
12099 fndecl = copy_node (fndecl);
12101 if (TREE_CHAIN (fndecl))
12103 fndecl = copy_node (fndecl);
12104 TREE_CHAIN (fndecl) = NULL_TREE;
12107 if (DECL_CONSTRUCTOR_P (fndecl))
12109 if (! grok_ctor_properties (current_class_type, fndecl))
12110 return void_type_node;
12112 else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
12113 grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
12116 cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0);
12118 /* Make a place for the parms */
12120 current_binding_level->parm_flag = 1;
12122 DECL_IN_AGGR_P (fndecl) = 1;
12126 /* Go through the motions of finishing a function definition.
12127 We don't compile this method until after the whole class has
12130 FINISH_METHOD must return something that looks as though it
12131 came from GROKFIELD (since we are defining a method, after all).
12133 This is called after parsing the body of the function definition.
12134 STMTS is the chain of statements that makes up the function body.
12136 DECL is the ..._DECL that `start_method' provided. */
12139 finish_method (decl)
12142 register tree fndecl = decl;
12145 register tree link;
12147 if (TYPE_MAIN_VARIANT (decl) == void_type_node)
12150 old_initial = DECL_INITIAL (fndecl);
12152 /* Undo the level for the parms (from start_method).
12153 This is like poplevel, but it causes nothing to be
12154 saved. Saving information here confuses symbol-table
12155 output routines. Besides, this information will
12156 be correctly output when this method is actually
12159 /* Clear out the meanings of the local variables of this level;
12160 also record in each decl which block it belongs to. */
12162 for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
12164 if (DECL_NAME (link) != NULL_TREE)
12165 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
12166 my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
12167 DECL_CONTEXT (link) = NULL_TREE;
12170 /* Restore all name-meanings of the outer levels
12171 that were shadowed by this level. */
12173 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
12174 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12175 for (link = current_binding_level->class_shadowed;
12176 link; link = TREE_CHAIN (link))
12177 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12178 for (link = current_binding_level->type_shadowed;
12179 link; link = TREE_CHAIN (link))
12180 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12182 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
12183 (HOST_WIDE_INT) current_binding_level->level_chain,
12184 current_binding_level->parm_flag,
12185 current_binding_level->keep);
12187 poplevel (0, 0, 0);
12189 DECL_INITIAL (fndecl) = old_initial;
12191 /* We used to check if the context of FNDECL was different from
12192 current_class_type as another way to get inside here. This didn't work
12193 for String.cc in libg++. */
12194 if (DECL_FRIEND_P (fndecl))
12196 CLASSTYPE_INLINE_FRIENDS (current_class_type)
12197 = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
12198 decl = void_type_node;
12204 /* Called when a new struct TYPE is defined.
12205 If this structure or union completes the type of any previous
12206 variable declaration, lay it out and output its rtl. */
12209 hack_incomplete_structures (type)
12214 if (current_binding_level->incomplete == NULL_TREE)
12217 if (!type) /* Don't do this for class templates. */
12220 for (list = ¤t_binding_level->incomplete; *list; )
12222 tree decl = TREE_VALUE (*list);
12223 if (decl && TREE_TYPE (decl) == type
12224 || (TREE_TYPE (decl)
12225 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
12226 && TREE_TYPE (TREE_TYPE (decl)) == type))
12228 int toplevel = toplevel_bindings_p ();
12229 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
12230 && TREE_TYPE (TREE_TYPE (decl)) == type)
12231 layout_type (TREE_TYPE (decl));
12232 layout_decl (decl, 0);
12233 rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
12237 expand_decl (decl);
12238 cleanup = maybe_build_cleanup (decl);
12239 expand_decl_init (decl);
12240 if (! cp_expand_decl_cleanup (decl, cleanup))
12241 cp_error ("parser lost in parsing declaration of `%D'",
12244 *list = TREE_CHAIN (*list);
12247 list = &TREE_CHAIN (*list);
12251 /* If DECL is of a type which needs a cleanup, build that cleanup here.
12252 We don't build cleanups if just going for syntax checking, since
12253 fixup_cleanups does not know how to not handle them.
12255 Don't build these on the momentary obstack; they must live
12256 the life of the binding contour. */
12258 maybe_build_cleanup (decl)
12261 tree type = TREE_TYPE (decl);
12262 if (TYPE_NEEDS_DESTRUCTOR (type))
12264 int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
12267 if (TREE_CODE (decl) != PARM_DECL)
12268 temp = suspend_momentary ();
12270 if (TREE_CODE (type) == ARRAY_TYPE)
12274 mark_addressable (decl);
12275 rval = build_unary_op (ADDR_EXPR, decl, 0);
12278 /* Optimize for space over speed here. */
12279 if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
12280 || flag_expensive_optimizations)
12281 flags |= LOOKUP_NONVIRTUAL;
12283 rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
12285 if (TYPE_USES_VIRTUAL_BASECLASSES (type)
12286 && ! TYPE_HAS_DESTRUCTOR (type))
12287 rval = build_compound_expr (tree_cons (NULL_TREE, rval,
12288 build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
12290 /* Since this is a cleanup, UNSAVE it now. */
12291 rval = unsave_expr (rval);
12293 if (TREE_CODE (decl) != PARM_DECL)
12294 resume_momentary (temp);
12301 /* Expand a C++ expression at the statement level.
12302 This is needed to ferret out nodes which have UNKNOWN_TYPE.
12303 The C++ type checker should get all of these out when
12304 expressions are combined with other, type-providing, expressions,
12305 leaving only orphan expressions, such as:
12307 &class::bar; / / takes its address, but does nothing with it.
12311 cplus_expand_expr_stmt (exp)
12314 extern int temp_slot_level;
12315 extern int target_temp_slot_level;
12316 tree old_cleanups = cleanups_this_call;
12317 int old_temp_level = target_temp_slot_level;
12318 push_temp_slots ();
12319 push_temp_slots ();
12320 target_temp_slot_level = temp_slot_level;
12322 if (current_template_parms)
12324 add_tree (build_min_nt (EXPR_STMT, exp));
12328 if (TREE_TYPE (exp) == unknown_type_node)
12330 if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
12331 error ("address of overloaded function with no contextual type information");
12332 else if (TREE_CODE (exp) == COMPONENT_REF)
12333 warning ("useless reference to a member function name, did you forget the ()?");
12337 if (TREE_CODE (exp) == FUNCTION_DECL)
12339 cp_warning ("reference, not call, to function `%D'", exp);
12340 warning ("at this point in file");
12344 /* We should do this eventually, but right now this causes regex.o from
12345 libg++ to miscompile, and tString to core dump. */
12346 exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp);
12348 expand_expr_stmt (break_out_cleanups (exp));
12351 /* Clean up any pending cleanups. This happens when a function call
12352 returns a cleanup-needing value that nobody uses. */
12353 expand_cleanups_to (old_cleanups);
12356 target_temp_slot_level = old_temp_level;
12357 /* There might something left from building the trees. */
12358 if (cleanups_this_call)
12360 expand_cleanups_to (NULL_TREE);
12362 free_temp_slots ();
12365 /* When a stmt has been parsed, this function is called.
12367 Currently, this function only does something within a
12368 constructor's scope: if a stmt has just assigned to this,
12369 and we are in a derived class, we call `emit_base_init'. */
12374 extern struct nesting *cond_stack, *loop_stack, *case_stack;
12377 if (current_function_assigns_this
12378 || ! current_function_just_assigned_this)
12380 if (DECL_CONSTRUCTOR_P (current_function_decl))
12382 /* Constructors must wait until we are out of control
12383 zones before calling base constructors. */
12384 if (cond_stack || loop_stack || case_stack)
12386 expand_expr_stmt (base_init_expr);
12387 check_base_init (current_class_type);
12389 current_function_assigns_this = 1;
12392 /* Change a static member function definition into a FUNCTION_TYPE, instead
12393 of the METHOD_TYPE that we create when it's originally parsed.
12395 WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
12396 (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
12397 other decls. Either pass the addresses of local variables or NULL. */
12400 revert_static_member_fn (decl, fn, argtypes)
12401 tree *decl, *fn, *argtypes;
12404 tree function = fn ? *fn : TREE_TYPE (*decl);
12405 tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function);
12407 if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args))))
12408 cp_error ("static member function `%#D' declared const", *decl);
12409 if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args))))
12410 cp_error ("static member function `%#D' declared volatile", *decl);
12412 args = TREE_CHAIN (args);
12413 tmp = build_function_type (TREE_TYPE (function), args);
12414 tmp = build_type_variant (tmp, TYPE_READONLY (function),
12415 TYPE_VOLATILE (function));
12416 tmp = build_exception_variant (tmp,
12417 TYPE_RAISES_EXCEPTIONS (function));
12418 TREE_TYPE (*decl) = tmp;
12419 if (DECL_ARGUMENTS (*decl))
12420 DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl));
12421 DECL_STATIC_FUNCTION_P (*decl) = 1;
12429 id_in_current_class (id)
12432 return !!purpose_member (id, class_binding_level->class_shadowed);
12439 int warn_about_return_type;
12441 int just_assigned_this;
12443 int temp_name_counter;
12445 tree shadowed_labels;
12448 rtx last_dtor_insn;
12450 tree base_init_list;
12451 tree member_init_list;
12452 tree base_init_expr;
12456 struct cp_function *next;
12457 struct binding_level *binding_level;
12463 struct cp_function *cp_function_chain;
12465 extern int temp_name_counter;
12467 /* Save and reinitialize the variables
12468 used during compilation of a C++ function. */
12471 push_cp_function_context (context)
12474 struct cp_function *p
12475 = (struct cp_function *) xmalloc (sizeof (struct cp_function));
12477 push_function_context_to (context);
12479 p->next = cp_function_chain;
12480 cp_function_chain = p;
12482 p->named_labels = named_labels;
12483 p->shadowed_labels = shadowed_labels;
12484 p->returns_value = current_function_returns_value;
12485 p->returns_null = current_function_returns_null;
12486 p->warn_about_return_type = warn_about_return_type;
12487 p->binding_level = current_binding_level;
12488 p->ctor_label = ctor_label;
12489 p->dtor_label = dtor_label;
12490 p->last_dtor_insn = last_dtor_insn;
12491 p->assigns_this = current_function_assigns_this;
12492 p->just_assigned_this = current_function_just_assigned_this;
12493 p->parms_stored = current_function_parms_stored;
12494 p->result_rtx = original_result_rtx;
12495 p->base_init_expr = base_init_expr;
12496 p->protect_list = protect_list;
12497 p->temp_name_counter = temp_name_counter;
12498 p->base_init_list = current_base_init_list;
12499 p->member_init_list = current_member_init_list;
12500 p->class_decl = current_class_decl;
12503 p->eh_context = push_eh_context ();
12506 /* Restore the variables used during compilation of a C++ function. */
12509 pop_cp_function_context (context)
12512 struct cp_function *p = cp_function_chain;
12515 /* Bring back all the labels that were shadowed. */
12516 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
12517 if (DECL_NAME (TREE_VALUE (link)) != 0)
12518 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)),
12519 TREE_VALUE (link));
12521 pop_function_context_from (context);
12523 cp_function_chain = p->next;
12525 named_labels = p->named_labels;
12526 shadowed_labels = p->shadowed_labels;
12527 current_function_returns_value = p->returns_value;
12528 current_function_returns_null = p->returns_null;
12529 warn_about_return_type = p->warn_about_return_type;
12530 current_binding_level = p->binding_level;
12531 ctor_label = p->ctor_label;
12532 dtor_label = p->dtor_label;
12533 last_dtor_insn = p->last_dtor_insn;
12534 protect_list = p->protect_list;
12535 current_function_assigns_this = p->assigns_this;
12536 current_function_just_assigned_this = p->just_assigned_this;
12537 current_function_parms_stored = p->parms_stored;
12538 original_result_rtx = p->result_rtx;
12539 base_init_expr = p->base_init_expr;
12540 temp_name_counter = p->temp_name_counter;
12541 current_base_init_list = p->base_init_list;
12542 current_member_init_list = p->member_init_list;
12543 current_class_decl = p->class_decl;
12546 pop_eh_context (p->eh_context);
12554 return function_depth != 0;
12557 /* FSF LOCAL dje prefix attributes */
12558 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
12559 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
12561 The head of the declspec list is stored in DECLSPECS.
12562 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
12564 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
12565 the list elements. We drop the containing TREE_LIST nodes and link the
12566 resulting attributes together the way decl_attributes expects them. */
12569 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
12571 tree *declspecs, *prefix_attributes;
12573 tree t, s, a, next, specs, attrs;
12575 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
12576 if (specs_attrs != NULL_TREE
12577 && TREE_CODE (specs_attrs) != TREE_LIST)
12579 *declspecs = specs_attrs;
12580 *prefix_attributes = NULL_TREE;
12584 /* Remember to keep the lists in the same order, element-wise. */
12586 specs = s = NULL_TREE;
12587 attrs = a = NULL_TREE;
12588 for (t = specs_attrs; t; t = next)
12590 next = TREE_CHAIN (t);
12591 /* Declspecs have a non-NULL TREE_VALUE. */
12592 if (TREE_VALUE (t) != NULL_TREE)
12594 if (specs == NULL_TREE)
12598 TREE_CHAIN (s) = t;
12604 if (attrs == NULL_TREE)
12605 attrs = a = TREE_PURPOSE (t);
12608 TREE_CHAIN (a) = TREE_PURPOSE (t);
12609 a = TREE_PURPOSE (t);
12614 /* Terminate the lists. */
12615 if (s != NULL_TREE)
12616 TREE_CHAIN (s) = NULL_TREE;
12617 if (a != NULL_TREE)
12618 TREE_CHAIN (a) = NULL_TREE;
12621 *declspecs = specs;
12622 *prefix_attributes = attrs;
12625 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
12626 This function is used by the parser when a rule will accept attributes
12627 in a particular position, but we don't want to support that just yet.
12629 A warning is issued for every ignored attribute. */
12632 strip_attrs (specs_attrs)
12637 split_specs_attrs (specs_attrs, &specs, &attrs);
12641 warning ("`%s' attribute ignored",
12642 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
12643 attrs = TREE_CHAIN (attrs);
12648 /* END FSF LOCAL */