|
|
1.1 root 1: /* Process declarations and variables for C compiler.
2: Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
3: Hacked by Michael Tiemann ([email protected])
4:
5: This file is part of GNU CC.
6:
7: GNU CC is free software; you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation; either version 2, or (at your option)
10: any later version.
11:
12: GNU CC is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with GNU CC; see the file COPYING. If not, write to
19: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20:
21:
22: /* Process declarations and symbol lookup for C front end.
23: Also constructs types; the standard scalar types at initialization,
24: and structure, union, array and enum types when they are declared. */
25:
26: /* ??? not all decl nodes are given the most useful possible
27: line numbers. For example, the CONST_DECLs for enum values. */
28:
29: #include <stdio.h>
30: #include "config.h"
31: #include "tree.h"
32: #include "rtl.h"
33: #include "flags.h"
34: #include "cp-tree.h"
35: #include "decl.h"
36: #include "lex.h"
37: #include <sys/types.h>
38: #include <signal.h>
39: #include "obstack.h"
40:
41: #define obstack_chunk_alloc xmalloc
42: #define obstack_chunk_free free
43:
44: extern tree builtin_return_address_fndecl;
45:
46: extern struct obstack permanent_obstack;
47:
48: extern int current_class_depth;
49:
50: extern tree cleanups_this_call;
51:
52: /* Stack of places to restore the search obstack back to. */
53:
54: /* Obstack used for remembering local class declarations (like
55: enums and static (const) members. */
56: #include "stack.h"
57: static struct obstack decl_obstack;
58: static struct stack_level *decl_stack;
59:
60: #ifndef CHAR_TYPE_SIZE
61: #define CHAR_TYPE_SIZE BITS_PER_UNIT
62: #endif
63:
64: #ifndef SHORT_TYPE_SIZE
65: #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
66: #endif
67:
68: #ifndef INT_TYPE_SIZE
69: #define INT_TYPE_SIZE BITS_PER_WORD
70: #endif
71:
72: #ifndef LONG_TYPE_SIZE
73: #define LONG_TYPE_SIZE BITS_PER_WORD
74: #endif
75:
76: #ifndef LONG_LONG_TYPE_SIZE
77: #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
78: #endif
79:
80: #ifndef WCHAR_UNSIGNED
81: #define WCHAR_UNSIGNED 0
82: #endif
83:
84: #ifndef FLOAT_TYPE_SIZE
85: #define FLOAT_TYPE_SIZE BITS_PER_WORD
86: #endif
87:
88: #ifndef DOUBLE_TYPE_SIZE
89: #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
90: #endif
91:
92: #ifndef LONG_DOUBLE_TYPE_SIZE
93: #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
94: #endif
95:
96: /* We let tm.h override the types used here, to handle trivial differences
97: such as the choice of unsigned int or long unsigned int for size_t.
98: When machines start needing nontrivial differences in the size type,
99: it would be best to do something here to figure out automatically
100: from other information what type to use. */
101:
102: #ifndef SIZE_TYPE
103: #define SIZE_TYPE "long unsigned int"
104: #endif
105:
106: #ifndef PTRDIFF_TYPE
107: #define PTRDIFF_TYPE "long int"
108: #endif
109:
110: #ifndef WCHAR_TYPE
111: #define WCHAR_TYPE "int"
112: #endif
113:
114: #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
115: define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
116: #define auto_function(NAME, TYPE, CODE) \
117: do { \
118: tree __name = NAME; \
119: tree __type = TYPE; \
120: define_function (IDENTIFIER_POINTER (__name), __type, CODE, \
121: (void (*)())push_overloaded_decl_1, \
122: IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\
123: } while (0)
124:
125: static tree grokparms PROTO((tree, int));
126: static tree lookup_nested_type PROTO((tree, tree));
127: static char *redeclaration_error_message PROTO((tree, tree));
128: static void grok_op_properties PROTO((tree, int, int));
129:
130: tree define_function
131: PROTO((char *, tree, enum built_in_function, void (*)(), char *));
132:
133: /* a node which has tree code ERROR_MARK, and whose type is itself.
134: All erroneous expressions are replaced with this node. All functions
135: that accept nodes as arguments should avoid generating error messages
136: if this node is one of the arguments, since it is undesirable to get
137: multiple error messages from one error in the input. */
138:
139: tree error_mark_node;
140:
141: /* Erroneous argument lists can use this *IFF* they do not modify it. */
142: tree error_mark_list;
143:
144: /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
145:
146: tree short_integer_type_node;
147: tree integer_type_node;
148: tree long_integer_type_node;
149: tree long_long_integer_type_node;
150:
151: tree short_unsigned_type_node;
152: tree unsigned_type_node;
153: tree long_unsigned_type_node;
154: tree long_long_unsigned_type_node;
155:
156: tree ptrdiff_type_node;
157:
158: tree unsigned_char_type_node;
159: tree signed_char_type_node;
160: tree char_type_node;
161: tree wchar_type_node;
162: tree signed_wchar_type_node;
163: tree unsigned_wchar_type_node;
164:
165: tree wchar_decl_node;
166:
167: tree float_type_node;
168: tree double_type_node;
169: tree long_double_type_node;
170:
171: tree intQI_type_node;
172: tree intHI_type_node;
173: tree intSI_type_node;
174: tree intDI_type_node;
175:
176: tree unsigned_intQI_type_node;
177: tree unsigned_intHI_type_node;
178: tree unsigned_intSI_type_node;
179: tree unsigned_intDI_type_node;
180:
181: /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
182:
183: tree void_type_node, void_list_node;
184: tree void_zero_node;
185:
186: /* Nodes for types `void *' and `const void *'. */
187:
188: tree ptr_type_node, const_ptr_type_node;
189:
190: /* Nodes for types `char *' and `const char *'. */
191:
192: tree string_type_node, const_string_type_node;
193:
194: /* Type `char[256]' or something like it.
195: Used when an array of char is needed and the size is irrelevant. */
196:
197: tree char_array_type_node;
198:
199: /* Type `int[256]' or something like it.
200: Used when an array of int needed and the size is irrelevant. */
201:
202: tree int_array_type_node;
203:
204: /* Type `wchar_t[256]' or something like it.
205: Used when a wide string literal is created. */
206:
207: tree wchar_array_type_node;
208:
209: /* The bool data type, and constants */
210: tree bool_type_node, true_node, false_node;
211:
212: /* type `int ()' -- used for implicit declaration of functions. */
213:
214: tree default_function_type;
215:
216: /* function types `double (double)' and `double (double, double)', etc. */
217:
218: tree double_ftype_double, double_ftype_double_double;
219: tree int_ftype_int, long_ftype_long;
220:
221: /* Function type `void (void *, void *, int)' and similar ones. */
222:
223: tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
224:
225: /* Function type `char *(char *, char *)' and similar ones */
226: tree string_ftype_ptr_ptr, int_ftype_string_string;
227:
228: /* Function type `size_t (const char *)' */
229: tree sizet_ftype_string;
230:
231: /* Function type `int (const void *, const void *, size_t)' */
232: tree int_ftype_cptr_cptr_sizet;
233:
234: /* C++ extensions */
235: tree vtable_entry_type;
236: tree delta_type_node;
237: tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node;
238: tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
239: tree class_star_type_node;
240: tree class_type_node, record_type_node, union_type_node, enum_type_node;
241: tree exception_type_node, unknown_type_node;
242: tree opaque_type_node, signature_type_node;
243: tree sigtable_entry_type;
244: tree maybe_gc_cleanup;
245:
246: /* Array type `vtable_entry_type[]' */
247: tree vtbl_type_node;
248:
249: /* In a destructor, the point at which all derived class destroying
250: has been done, just before any base class destroying will be done. */
251:
252: tree dtor_label;
253:
254: /* In a constructor, the point at which we are ready to return
255: the pointer to the initialized object. */
256:
257: tree ctor_label;
258:
259: /* A FUNCTION_DECL which can call `abort'. Not necessarily the
260: one that the user will declare, but sufficient to be called
261: by routines that want to abort the program. */
262:
263: tree abort_fndecl;
264:
265: extern rtx cleanup_label, return_label;
266:
267: /* If original DECL_RESULT of current function was a register,
268: but due to being an addressable named return value, would up
269: on the stack, this variable holds the named return value's
270: original location. */
271: rtx original_result_rtx;
272:
273: /* Sequence of insns which represents base initialization. */
274: rtx base_init_insns;
275:
276: /* C++: Keep these around to reduce calls to `get_identifier'.
277: Identifiers for `this' in member functions and the auto-delete
278: parameter for destructors. */
279: tree this_identifier, in_charge_identifier;
280: /* Used in pointer to member functions, and in vtables. */
281: tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
282: tree pfn_or_delta2_identifier;
283:
284: /* A list (chain of TREE_LIST nodes) of named label uses.
285: The TREE_PURPOSE field is the list of variables defined
286: the the label's scope defined at the point of use.
287: The TREE_VALUE field is the LABEL_DECL used.
288: The TREE_TYPE field holds `current_binding_level' at the
289: point of the label's use.
290:
291: Used only for jumps to as-yet undefined labels, since
292: jumps to defined labels can have their validity checked
293: by stmt.c. */
294:
295: static tree named_label_uses;
296:
297: /* A list of objects which have constructors or destructors
298: which reside in the global scope. The decl is stored in
299: the TREE_VALUE slot and the initializer is stored
300: in the TREE_PURPOSE slot. */
301: tree static_aggregates;
302:
303: /* -- end of C++ */
304:
305: /* Two expressions that are constants with value zero.
306: The first is of type `int', the second of type `void *'. */
307:
308: tree integer_zero_node;
309: tree null_pointer_node;
310:
311: /* A node for the integer constants 1, 2, and 3. */
312:
313: tree integer_one_node, integer_two_node, integer_three_node;
314:
315: /* Nonzero if we have seen an invalid cross reference
316: to a struct, union, or enum, but not yet printed the message. */
317:
318: tree pending_invalid_xref;
319: /* File and line to appear in the eventual error message. */
320: char *pending_invalid_xref_file;
321: int pending_invalid_xref_line;
322:
323: /* While defining an enum type, this is 1 plus the last enumerator
324: constant value. */
325:
326: static tree enum_next_value;
327:
328: /* Nonzero means that there was overflow computing enum_next_value. */
329:
330: static int enum_overflow;
331:
332: /* Parsing a function declarator leaves a list of parameter names
333: or a chain or parameter decls here. */
334:
335: tree last_function_parms;
336:
337: /* Parsing a function declarator leaves here a chain of structure
338: and enum types declared in the parmlist. */
339:
340: static tree last_function_parm_tags;
341:
342: /* After parsing the declarator that starts a function definition,
343: `start_function' puts here the list of parameter names or chain of decls.
344: `store_parm_decls' finds it here. */
345:
346: static tree current_function_parms;
347:
348: /* Similar, for last_function_parm_tags. */
349: static tree current_function_parm_tags;
350:
351: /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
352: that have names. Here so we can clear out their names' definitions
353: at the end of the function. */
354:
355: static tree named_labels;
356:
357: /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
358:
359: static tree shadowed_labels;
360:
361: #if 0 /* Not needed by C++ */
362: /* Nonzero when store_parm_decls is called indicates a varargs function.
363: Value not meaningful after store_parm_decls. */
364:
365: static int c_function_varargs;
366: #endif
367:
368: /* The FUNCTION_DECL for the function currently being compiled,
369: or 0 if between functions. */
370: tree current_function_decl;
371:
372: /* Set to 0 at beginning of a function definition, set to 1 if
373: a return statement that specifies a return value is seen. */
374:
375: int current_function_returns_value;
376:
377: /* Set to 0 at beginning of a function definition, set to 1 if
378: a return statement with no argument is seen. */
379:
380: int current_function_returns_null;
381:
382: /* Set to 0 at beginning of a function definition, and whenever
383: a label (case or named) is defined. Set to value of expression
384: returned from function when that value can be transformed into
385: a named return value. */
386:
387: tree current_function_return_value;
388:
389: /* Set to nonzero by `grokdeclarator' for a function
390: whose return type is defaulted, if warnings for this are desired. */
391:
392: static int warn_about_return_type;
393:
394: /* Nonzero when starting a function declared `extern inline'. */
395:
396: static int current_extern_inline;
397:
398: /* Nonzero means give `double' the same size as `float'. */
399:
400: extern int flag_short_double;
401:
402: /* Nonzero means don't recognize any builtin functions. */
403:
404: extern int flag_no_builtin;
405:
406: /* Nonzero means don't recognize the non-ANSI builtin functions.
407: -ansi sets this. */
408:
409: extern int flag_no_nonansi_builtin;
410:
411: /* Nonzero means disable GNU extensions. */
412:
413: extern int flag_ansi;
414:
415: /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
416: objects. */
417: extern int flag_huge_objects;
418:
419: /* Nonzero if we want to conserve space in the .o files. We do this
420: by putting uninitialized data and runtime initialized data into
421: .common instead of .data at the expense of not flaging multiple
422: definitions. */
423: extern int flag_conserve_space;
424:
425: /* Pointers to the base and current top of the language name stack. */
426:
427: extern tree *current_lang_base, *current_lang_stack;
428:
429: /* C and C++ flags are in decl2.c. */
430:
431: /* Set to 0 at beginning of a constructor, set to 1
432: if that function does an allocation before referencing its
433: instance variable. */
434: int current_function_assigns_this;
435: int current_function_just_assigned_this;
436:
437: /* Set to 0 at beginning of a function. Set non-zero when
438: store_parm_decls is called. Don't call store_parm_decls
439: if this flag is non-zero! */
440: int current_function_parms_stored;
441:
442: /* Current end of entries in the gc obstack for stack pointer variables. */
443:
444: int current_function_obstack_index;
445:
446: /* Flag saying whether we have used the obstack in this function or not. */
447:
448: int current_function_obstack_usage;
449:
450: /* Flag used when debugging spew.c */
451:
452: extern int spew_debug;
453:
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;
458:
459:
460: /* Allocate a level of searching. */
461: struct stack_level *
462: push_decl_level (stack, obstack)
463: struct stack_level *stack;
464: struct obstack *obstack;
465: {
466: struct stack_level tem;
467: tem.prev = stack;
468:
469: return push_stack_level (obstack, (char *)&tem, sizeof (tem));
470: }
471:
472: /* For each binding contour we allocate a binding_level structure
473: * which records the names defined in that contour.
474: * Contours include:
475: * 0) the global one
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.
480: *
481: * The current meaning of a name can be found by searching the levels from
482: * the current one out to the global one.
483: *
484: * Off to the side, may be the class_binding_level. This exists
485: * only to catch class-local declarations. It is otherwise
486: * nonexistent.
487: *
488: * Also there may be binding levels that catch cleanups that
489: * must be run when exceptions occur.
490: */
491:
492: /* Note that the information in the `names' component of the global contour
493: is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
494:
495: struct binding_level
496: {
497: /* A chain of _DECL nodes for all variables, constants, functions,
498: * and typedef types. These are in the reverse of the order supplied.
499: */
500: tree names;
501:
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.
507: *
508: * C++: the TREE_VALUE nodes can be simple types for component_bindings.
509: *
510: */
511: tree tags;
512:
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). */
517: tree shadowed;
518:
519: /* Same, for IDENTIFIER_CLASS_VALUE. */
520: tree class_shadowed;
521:
522: /* Same, for IDENTIFIER_TYPE_VALUE. */
523: tree type_shadowed;
524:
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. */
528: tree blocks;
529:
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. */
532: tree this_block;
533:
534: /* The binding level which this one is contained in (inherits from). */
535: struct binding_level *level_chain;
536:
537: /* Number of decls in `names' that have incomplete
538: structure or union types. */
539: unsigned short n_incomplete;
540:
541: /* 1 for the level that holds the parameters of a function.
542: 2 for the level that holds a class declaration.
543: 3 for levels that hold parameter declarations. */
544: unsigned parm_flag : 4;
545:
546: /* 1 means make a BLOCK for this level regardless of all else.
547: 2 for temporary binding contours created by the compiler. */
548: unsigned keep : 3;
549:
550: /* Nonzero if this level "doesn't exist" for tags. */
551: unsigned tag_transparent : 1;
552:
553: /* Nonzero if this level can safely have additional
554: cleanup-needing variables added to it. */
555: unsigned more_cleanups_ok : 1;
556: unsigned have_cleanups : 1;
557:
558: /* Nonzero if we should accept any name as an identifier in
559: this scope. This happens in some template definitions. */
560: unsigned accept_any : 1;
561:
562: /* Nonzero if this level is for completing a template class definition
563: inside a binding level that temporarily binds the parameters. This
564: means that definitions here should not be popped off when unwinding
565: this binding level. (Not actually implemented this way,
566: unfortunately.) */
567: unsigned pseudo_global : 1;
568:
569: /* Two bits left for this word. */
570:
571: #if defined(DEBUG_CP_BINDING_LEVELS)
572: /* Binding depth at which this level began. */
573: unsigned binding_depth;
574: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
575: };
576:
577: #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
578:
579: /* The (non-class) binding level currently in effect. */
580:
581: static struct binding_level *current_binding_level;
582:
583: /* The binding level of the current class, if any. */
584:
585: static struct binding_level *class_binding_level;
586:
587: /* The current (class or non-class) binding level currently in effect. */
588:
589: #define inner_binding_level \
590: (class_binding_level ? class_binding_level : current_binding_level)
591:
592: /* A chain of binding_level structures awaiting reuse. */
593:
594: static struct binding_level *free_binding_level;
595:
596: /* The outermost binding level, for names of file scope.
597: This is created when the compiler is started and exists
598: through the entire run. */
599:
600: static struct binding_level *global_binding_level;
601:
602: /* Binding level structures are initialized by copying this one. */
603:
604: static struct binding_level clear_binding_level;
605:
606: /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
607:
608: static int keep_next_level_flag;
609:
610: #if defined(DEBUG_CP_BINDING_LEVELS)
611: static int binding_depth = 0;
612: static int is_class_level = 0;
613:
614: static void
615: indent ()
616: {
617: register unsigned i;
618:
619: for (i = 0; i < binding_depth*2; i++)
620: putc (' ', stderr);
621: }
622: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
623:
624: static tree pushdecl_with_scope PROTO((tree, struct binding_level *));
625:
626: static void
627: push_binding_level (newlevel, tag_transparent, keep)
628: struct binding_level *newlevel;
629: int tag_transparent, keep;
630: {
631: /* Add this level to the front of the chain (stack) of levels that
632: are active. */
633: *newlevel = clear_binding_level;
634: if (class_binding_level)
635: {
636: newlevel->level_chain = class_binding_level;
637: class_binding_level = (struct binding_level *)0;
638: }
639: else
640: {
641: newlevel->level_chain = current_binding_level;
642: }
643: current_binding_level = newlevel;
644: newlevel->tag_transparent = tag_transparent;
645: newlevel->more_cleanups_ok = 1;
646: newlevel->keep = keep;
647: #if defined(DEBUG_CP_BINDING_LEVELS)
648: newlevel->binding_depth = binding_depth;
649: indent ();
650: fprintf (stderr, "push %s level 0x%08x line %d\n",
651: (is_class_level) ? "class" : "block", newlevel, lineno);
652: is_class_level = 0;
653: binding_depth++;
654: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
655: }
656:
657: static void
658: pop_binding_level ()
659: {
660: if (class_binding_level)
661: current_binding_level = class_binding_level;
662:
663: if (global_binding_level)
664: {
665: /* cannot pop a level, if there are none left to pop. */
666: if (current_binding_level == global_binding_level)
667: my_friendly_abort (123);
668: }
669: /* Pop the current level, and free the structure for reuse. */
670: #if defined(DEBUG_CP_BINDING_LEVELS)
671: binding_depth--;
672: indent ();
673: fprintf (stderr, "pop %s level 0x%08x line %d\n",
674: (is_class_level) ? "class" : "block",
675: current_binding_level, lineno);
676: if (is_class_level != (current_binding_level == class_binding_level))
677: #if 0 /* XXX Don't abort when we're watching how things are being managed. */
678: abort ();
679: #else
680: {
681: indent ();
682: fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
683: }
684: #endif
685: is_class_level = 0;
686: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
687: {
688: register struct binding_level *level = current_binding_level;
689: current_binding_level = current_binding_level->level_chain;
690: level->level_chain = free_binding_level;
691: #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
692: if (level->binding_depth != binding_depth)
693: abort ();
694: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
695: free_binding_level = level;
696:
697: class_binding_level = current_binding_level;
698: if (class_binding_level->parm_flag != 2)
699: class_binding_level = 0;
700: while (current_binding_level->parm_flag == 2)
701: current_binding_level = current_binding_level->level_chain;
702: }
703: }
704:
705: /* Nonzero if we are currently in the global binding level. */
706:
707: int
708: global_bindings_p ()
709: {
710: return current_binding_level == global_binding_level;
711: }
712:
713: void
714: keep_next_level ()
715: {
716: keep_next_level_flag = 1;
717: }
718:
719: /* Nonzero if the current level needs to have a BLOCK made. */
720:
721: int
722: kept_level_p ()
723: {
724: return (current_binding_level->blocks != NULL_TREE
725: || current_binding_level->keep
726: || current_binding_level->names != NULL_TREE
727: || (current_binding_level->tags != NULL_TREE
728: && !current_binding_level->tag_transparent));
729: }
730:
731: /* Identify this binding level as a level of parameters. */
732:
733: void
734: declare_parm_level ()
735: {
736: current_binding_level->parm_flag = 1;
737: }
738:
739: void
740: declare_uninstantiated_type_level ()
741: {
742: current_binding_level->accept_any = 1;
743: }
744:
745: int
746: uninstantiated_type_level_p ()
747: {
748: return current_binding_level->accept_any;
749: }
750:
751: void
752: declare_pseudo_global_level ()
753: {
754: current_binding_level->pseudo_global = 1;
755: }
756:
757: int
758: pseudo_global_level_p ()
759: {
760: return current_binding_level->pseudo_global;
761: }
762:
763: void
764: set_class_shadows (shadows)
765: tree shadows;
766: {
767: class_binding_level->class_shadowed = shadows;
768: }
769:
770: /* Enter a new binding level.
771: If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
772: not for that of tags. */
773:
774: void
775: pushlevel (tag_transparent)
776: int tag_transparent;
777: {
778: register struct binding_level *newlevel = NULL_BINDING_LEVEL;
779:
780: /* If this is the top level of a function,
781: just make sure that NAMED_LABELS is 0.
782: They should have been set to 0 at the end of the previous function. */
783:
784: if (current_binding_level == global_binding_level)
785: my_friendly_assert (named_labels == NULL_TREE, 134);
786:
787: /* Reuse or create a struct for this binding level. */
788:
789: #if defined(DEBUG_CP_BINDING_LEVELS)
790: if (0)
791: #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
792: if (free_binding_level)
793: #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
794: {
795: newlevel = free_binding_level;
796: free_binding_level = free_binding_level->level_chain;
797: }
798: else
799: {
800: /* Create a new `struct binding_level'. */
801: newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
802: }
803: push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
804: GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
805: keep_next_level_flag = 0;
806: }
807:
808: void
809: pushlevel_temporary (tag_transparent)
810: int tag_transparent;
811: {
812: pushlevel (tag_transparent);
813: current_binding_level->keep = 2;
814: clear_last_expr ();
815:
816: /* Note we don't call push_momentary() here. Otherwise, it would cause
817: cleanups to be allocated on the momentary obstack, and they will be
818: overwritten by the next statement. */
819:
820: expand_start_bindings (0);
821: }
822:
823: /* Exit a binding level.
824: Pop the level off, and restore the state of the identifier-decl mappings
825: that were in effect when this level was entered.
826:
827: If KEEP == 1, this level had explicit declarations, so
828: and create a "block" (a BLOCK node) for the level
829: to record its declarations and subblocks for symbol table output.
830:
831: If KEEP == 2, this level's subblocks go to the front,
832: not the back of the current binding level. This happens,
833: for instance, when code for constructors and destructors
834: need to generate code at the end of a function which must
835: be moved up to the front of the function.
836:
837: If FUNCTIONBODY is nonzero, this level is the body of a function,
838: so create a block as if KEEP were set and also clear out all
839: label names.
840:
841: If REVERSE is nonzero, reverse the order of decls before putting
842: them into the BLOCK. */
843:
844: tree
845: poplevel (keep, reverse, functionbody)
846: int keep;
847: int reverse;
848: int functionbody;
849: {
850: register tree link;
851: /* The chain of decls was accumulated in reverse order.
852: Put it into forward order, just for cleanliness. */
853: tree decls;
854: int tmp = functionbody;
855: int implicit_try_block = current_binding_level->parm_flag == 3;
856: int real_functionbody = current_binding_level->keep == 2
857: ? ((functionbody = 0), tmp) : functionbody;
858: tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
859: tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
860: tree block = NULL_TREE;
861: tree decl;
862: int block_previously_created;
863:
864: GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
865: (HOST_WIDE_INT) current_binding_level->level_chain,
866: current_binding_level->parm_flag,
867: current_binding_level->keep,
868: current_binding_level->tag_transparent);
869:
870: if (current_binding_level->keep == 1)
871: keep = 1;
872:
873: /* This warning is turned off because it causes warnings for
874: declarations like `extern struct foo *x'. */
875: #if 0
876: /* Warn about incomplete structure types in this level. */
877: for (link = tags; link; link = TREE_CHAIN (link))
878: if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
879: {
880: tree type = TREE_VALUE (link);
881: char *errmsg;
882: switch (TREE_CODE (type))
883: {
884: case RECORD_TYPE:
885: errmsg = "`struct %s' incomplete in scope ending here";
886: break;
887: case UNION_TYPE:
888: errmsg = "`union %s' incomplete in scope ending here";
889: break;
890: case ENUMERAL_TYPE:
891: errmsg = "`enum %s' incomplete in scope ending here";
892: break;
893: }
894: if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
895: error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
896: else
897: /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
898: error (errmsg, TYPE_NAME_STRING (type));
899: }
900: #endif /* 0 */
901:
902: /* Get the decls in the order they were written.
903: Usually current_binding_level->names is in reverse order.
904: But parameter decls were previously put in forward order. */
905:
906: if (reverse)
907: current_binding_level->names
908: = decls = nreverse (current_binding_level->names);
909: else
910: decls = current_binding_level->names;
911:
912: /* Output any nested inline functions within this block
913: if they weren't already output. */
914:
915: for (decl = decls; decl; decl = TREE_CHAIN (decl))
916: if (TREE_CODE (decl) == FUNCTION_DECL
917: && ! TREE_ASM_WRITTEN (decl)
918: && DECL_INITIAL (decl) != NULL_TREE
919: && TREE_ADDRESSABLE (decl))
920: {
921: /* If this decl was copied from a file-scope decl
922: on account of a block-scope extern decl,
923: propagate TREE_ADDRESSABLE to the file-scope decl. */
924: if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
925: TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
926: else
927: {
928: push_function_context ();
929: output_inline_function (decl);
930: pop_function_context ();
931: }
932: }
933:
934: /* If there were any declarations or structure tags in that level,
935: or if this level is a function body,
936: create a BLOCK to record them for the life of this function. */
937:
938: block = NULL_TREE;
939: block_previously_created = (current_binding_level->this_block != NULL_TREE);
940: if (block_previously_created)
941: block = current_binding_level->this_block;
942: else if (keep == 1 || functionbody)
943: block = make_node (BLOCK);
944: if (block != NULL_TREE)
945: {
946: BLOCK_VARS (block) = decls;
947: BLOCK_TYPE_TAGS (block) = tags;
948: BLOCK_SUBBLOCKS (block) = subblocks;
949: /* If we created the block earlier on, and we are just diddling it now,
950: then it already should have a proper BLOCK_END_NOTE value associated
951: with it, so avoid trashing that. Otherwise, for a new block, install
952: a new BLOCK_END_NOTE value. */
953: if (! block_previously_created)
954: remember_end_note (block);
955: }
956:
957: /* In each subblock, record that this is its superior. */
958:
959: if (keep >= 0)
960: for (link = subblocks; link; link = TREE_CHAIN (link))
961: BLOCK_SUPERCONTEXT (link) = block;
962:
963: /* Clear out the meanings of the local variables of this level. */
964:
965: for (link = decls; link; link = TREE_CHAIN (link))
966: {
967: if (DECL_NAME (link) != NULL_TREE)
968: {
969: /* If the ident. was used or addressed via a local extern decl,
970: don't forget that fact. */
971: if (DECL_EXTERNAL (link))
972: {
973: if (TREE_USED (link))
974: TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
975: if (TREE_ADDRESSABLE (link))
976: TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
977: }
978: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
979: }
980: }
981:
982: /* Restore all name-meanings of the outer levels
983: that were shadowed by this level. */
984:
985: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
986: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
987: for (link = current_binding_level->class_shadowed;
988: link; link = TREE_CHAIN (link))
989: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
990: for (link = current_binding_level->type_shadowed;
991: link; link = TREE_CHAIN (link))
992: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
993:
994: /* If the level being exited is the top level of a function,
995: check over all the labels. */
996:
997: if (functionbody)
998: {
999: /* If this is the top level block of a function,
1000: the vars are the function's parameters.
1001: Don't leave them in the BLOCK because they are
1002: found in the FUNCTION_DECL instead. */
1003:
1004: BLOCK_VARS (block) = 0;
1005:
1006: /* Clear out the definitions of all label names,
1007: since their scopes end here. */
1008:
1009: for (link = named_labels; link; link = TREE_CHAIN (link))
1010: {
1011: register tree label = TREE_VALUE (link);
1012:
1013: if (DECL_INITIAL (label) == NULL_TREE)
1014: {
1015: cp_error_at ("label `%D' used but not defined", label);
1016: /* Avoid crashing later. */
1017: define_label (input_filename, 1, DECL_NAME (label));
1018: }
1019: else if (warn_unused && !TREE_USED (label))
1020: cp_warning_at ("label `%D' defined but not used", label);
1021: SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
1022:
1023: /* Put the labels into the "variables" of the
1024: top-level block, so debugger can see them. */
1025: TREE_CHAIN (label) = BLOCK_VARS (block);
1026: BLOCK_VARS (block) = label;
1027: }
1028:
1029: named_labels = NULL_TREE;
1030: }
1031:
1032: /* Any uses of undefined labels now operate under constraints
1033: of next binding contour. */
1034: {
1035: struct binding_level *level_chain;
1036: level_chain = current_binding_level->level_chain;
1037: if (level_chain)
1038: {
1039: tree labels;
1040: for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
1041: if (TREE_TYPE (labels) == (tree)current_binding_level)
1042: {
1043: TREE_TYPE (labels) = (tree)level_chain;
1044: TREE_PURPOSE (labels) = level_chain->names;
1045: }
1046: }
1047: }
1048:
1049: tmp = current_binding_level->keep;
1050:
1051: pop_binding_level ();
1052: if (functionbody)
1053: DECL_INITIAL (current_function_decl) = block;
1054: else if (block)
1055: {
1056: if (!block_previously_created)
1057: current_binding_level->blocks
1058: = chainon (current_binding_level->blocks, block);
1059: }
1060: /* If we did not make a block for the level just exited,
1061: any blocks made for inner levels
1062: (since they cannot be recorded as subblocks in that level)
1063: must be carried forward so they will later become subblocks
1064: of something else. */
1065: else if (subblocks)
1066: {
1067: if (keep == 2)
1068: current_binding_level->blocks
1069: = chainon (subblocks, current_binding_level->blocks);
1070: else
1071: current_binding_level->blocks
1072: = chainon (current_binding_level->blocks, subblocks);
1073: }
1074:
1075: /* Take care of compiler's internal binding structures. */
1076: if (tmp == 2)
1077: {
1078: #if 0
1079: /* We did not call push_momentary for this
1080: binding contour, so there is nothing to pop. */
1081: pop_momentary ();
1082: #endif
1083: expand_end_bindings (getdecls (), keep, 1);
1084: /* Each and every BLOCK node created here in `poplevel' is important
1085: (e.g. for proper debugging information) so if we created one
1086: earlier, mark it as "used". */
1087: if (block)
1088: TREE_USED (block) = 1;
1089: block = poplevel (keep, reverse, real_functionbody);
1090: }
1091:
1092: /* Each and every BLOCK node created here in `poplevel' is important
1093: (e.g. for proper debugging information) so if we created one
1094: earlier, mark it as "used". */
1095: if (block)
1096: TREE_USED (block) = 1;
1097: return block;
1098: }
1099:
1100: /* Delete the node BLOCK from the current binding level.
1101: This is used for the block inside a stmt expr ({...})
1102: so that the block can be reinserted where appropriate. */
1103:
1104: void
1105: delete_block (block)
1106: tree block;
1107: {
1108: tree t;
1109: if (current_binding_level->blocks == block)
1110: current_binding_level->blocks = TREE_CHAIN (block);
1111: for (t = current_binding_level->blocks; t;)
1112: {
1113: if (TREE_CHAIN (t) == block)
1114: TREE_CHAIN (t) = TREE_CHAIN (block);
1115: else
1116: t = TREE_CHAIN (t);
1117: }
1118: TREE_CHAIN (block) = NULL_TREE;
1119: /* Clear TREE_USED which is always set by poplevel.
1120: The flag is set again if insert_block is called. */
1121: TREE_USED (block) = 0;
1122: }
1123:
1124: /* Insert BLOCK at the end of the list of subblocks of the
1125: current binding level. This is used when a BIND_EXPR is expanded,
1126: to handle the BLOCK node inside the BIND_EXPR. */
1127:
1128: void
1129: insert_block (block)
1130: tree block;
1131: {
1132: TREE_USED (block) = 1;
1133: current_binding_level->blocks
1134: = chainon (current_binding_level->blocks, block);
1135: }
1136:
1137: /* Add BLOCK to the current list of blocks for this binding contour. */
1138: void
1139: add_block_current_level (block)
1140: tree block;
1141: {
1142: current_binding_level->blocks
1143: = chainon (current_binding_level->blocks, block);
1144: }
1145:
1146: /* Set the BLOCK node for the innermost scope
1147: (the one we are currently in). */
1148:
1149: void
1150: set_block (block)
1151: register tree block;
1152: {
1153: current_binding_level->this_block = block;
1154: }
1155:
1156: /* Do a pushlevel for class declarations. */
1157: void
1158: pushlevel_class ()
1159: {
1160: register struct binding_level *newlevel;
1161:
1162: /* Reuse or create a struct for this binding level. */
1163: #if defined(DEBUG_CP_BINDING_LEVELS)
1164: if (0)
1165: #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1166: if (free_binding_level)
1167: #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1168: {
1169: newlevel = free_binding_level;
1170: free_binding_level = free_binding_level->level_chain;
1171: }
1172: else
1173: {
1174: /* Create a new `struct binding_level'. */
1175: newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
1176: }
1177:
1178: #if defined(DEBUG_CP_BINDING_LEVELS)
1179: is_class_level = 1;
1180: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1181:
1182: push_binding_level (newlevel, 0, 0);
1183:
1184: decl_stack = push_decl_level (decl_stack, &decl_obstack);
1185: class_binding_level = current_binding_level;
1186: class_binding_level->parm_flag = 2;
1187: /* We have just pushed into a new binding level. Now, fake out the rest
1188: of the compiler. Set the `current_binding_level' back to point to
1189: the most closely containing non-class binding level. */
1190: do
1191: {
1192: current_binding_level = current_binding_level->level_chain;
1193: }
1194: while (current_binding_level->parm_flag == 2);
1195: }
1196:
1197: /* ...and a poplevel for class declarations. FORCE is used to force
1198: clearing out of CLASS_VALUEs after a class definition. */
1199: tree
1200: poplevel_class (force)
1201: int force;
1202: {
1203: register struct binding_level *level = class_binding_level;
1204: tree block = NULL_TREE;
1205: tree shadowed;
1206:
1207: my_friendly_assert (level != 0, 354);
1208:
1209: decl_stack = pop_stack_level (decl_stack);
1210: for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1211: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1212: /* If we're leaving a toplevel class, don't bother to do the setting
1213: of IDENTIFER_CLASS_VALUE to NULL_TREE, since first of all this slot
1214: shouldn't even be used when current_class_type isn't set, and second,
1215: if we don't touch it here, we're able to use the caching effect if the
1216: next time we're entering a class scope, it is the same class. */
1217: if (current_class_depth != 1 || force)
1218: for (shadowed = level->class_shadowed;
1219: shadowed;
1220: shadowed = TREE_CHAIN (shadowed))
1221: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1222: else
1223: /* Remember to save what IDENTIFIER's were bound in this scope so we
1224: can recover from cache misses. */
1225: previous_class_values = class_binding_level->class_shadowed;
1226: for (shadowed = level->type_shadowed;
1227: shadowed;
1228: shadowed = TREE_CHAIN (shadowed))
1229: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1230:
1231: GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
1232: (HOST_WIDE_INT) class_binding_level->level_chain,
1233: class_binding_level->parm_flag,
1234: class_binding_level->keep,
1235: class_binding_level->tag_transparent);
1236:
1237: if (class_binding_level->parm_flag != 2)
1238: class_binding_level = (struct binding_level *)0;
1239:
1240: /* Now, pop out of the the binding level which we created up in the
1241: `pushlevel_class' routine. */
1242: #if defined(DEBUG_CP_BINDING_LEVELS)
1243: is_class_level = 1;
1244: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1245:
1246: pop_binding_level ();
1247:
1248: return block;
1249: }
1250:
1251: /* For debugging. */
1252: int no_print_functions = 0;
1253: int no_print_builtins = 0;
1254:
1255: void
1256: print_binding_level (lvl)
1257: struct binding_level *lvl;
1258: {
1259: tree t;
1260: int i = 0, len;
1261: fprintf (stderr, " blocks=");
1262: fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
1263: fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
1264: lvl->n_incomplete, lvl->parm_flag, lvl->keep);
1265: if (lvl->tag_transparent)
1266: fprintf (stderr, " tag-transparent");
1267: if (lvl->more_cleanups_ok)
1268: fprintf (stderr, " more-cleanups-ok");
1269: if (lvl->have_cleanups)
1270: fprintf (stderr, " have-cleanups");
1271: fprintf (stderr, "\n");
1272: if (lvl->names)
1273: {
1274: fprintf (stderr, " names:\t");
1275: /* We can probably fit 3 names to a line? */
1276: for (t = lvl->names; t; t = TREE_CHAIN (t))
1277: {
1278: if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL))
1279: continue;
1280: if (no_print_builtins
1281: && (TREE_CODE(t) == TYPE_DECL)
1282: && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
1283: continue;
1284:
1285: /* Function decls tend to have longer names. */
1286: if (TREE_CODE (t) == FUNCTION_DECL)
1287: len = 3;
1288: else
1289: len = 2;
1290: i += len;
1291: if (i > 6)
1292: {
1293: fprintf (stderr, "\n\t");
1294: i = len;
1295: }
1296: print_node_brief (stderr, "", t, 0);
1297: if (TREE_CODE (t) == ERROR_MARK)
1298: break;
1299: }
1300: if (i)
1301: fprintf (stderr, "\n");
1302: }
1303: if (lvl->tags)
1304: {
1305: fprintf (stderr, " tags:\t");
1306: i = 0;
1307: for (t = lvl->tags; t; t = TREE_CHAIN (t))
1308: {
1309: if (TREE_PURPOSE (t) == NULL_TREE)
1310: len = 3;
1311: else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1312: len = 2;
1313: else
1314: len = 4;
1315: i += len;
1316: if (i > 5)
1317: {
1318: fprintf (stderr, "\n\t");
1319: i = len;
1320: }
1321: if (TREE_PURPOSE (t) == NULL_TREE)
1322: {
1323: print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1324: fprintf (stderr, ">");
1325: }
1326: else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1327: print_node_brief (stderr, "", TREE_VALUE (t), 0);
1328: else
1329: {
1330: print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1331: print_node_brief (stderr, "", TREE_VALUE (t), 0);
1332: fprintf (stderr, ">");
1333: }
1334: }
1335: if (i)
1336: fprintf (stderr, "\n");
1337: }
1338: if (lvl->shadowed)
1339: {
1340: fprintf (stderr, " shadowed:");
1341: for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1342: {
1343: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1344: }
1345: fprintf (stderr, "\n");
1346: }
1347: if (lvl->class_shadowed)
1348: {
1349: fprintf (stderr, " class-shadowed:");
1350: for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1351: {
1352: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1353: }
1354: fprintf (stderr, "\n");
1355: }
1356: if (lvl->type_shadowed)
1357: {
1358: fprintf (stderr, " type-shadowed:");
1359: for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1360: {
1361: #if 0
1362: fprintf (stderr, "\n\t");
1363: print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
1364: if (TREE_VALUE (t))
1365: print_node_brief (stderr, " ", TREE_VALUE (t), 0);
1366: else
1367: fprintf (stderr, " (none)");
1368: fprintf (stderr, ">");
1369: #else
1370: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1371: #endif
1372: }
1373: fprintf (stderr, "\n");
1374: }
1375: }
1376:
1377: void
1378: print_other_binding_stack (stack)
1379: struct binding_level *stack;
1380: {
1381: struct binding_level *level;
1382: for (level = stack; level != global_binding_level; level = level->level_chain)
1383: {
1384: fprintf (stderr, "binding level ");
1385: fprintf (stderr, HOST_PTR_PRINTF, level);
1386: fprintf (stderr, "\n");
1387: print_binding_level (level);
1388: }
1389: }
1390:
1391: void
1392: print_binding_stack ()
1393: {
1394: struct binding_level *b;
1395: fprintf (stderr, "current_binding_level=");
1396: fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
1397: fprintf (stderr, "\nclass_binding_level=");
1398: fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
1399: fprintf (stderr, "\nglobal_binding_level=");
1400: fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
1401: fprintf (stderr, "\n");
1402: if (class_binding_level)
1403: {
1404: for (b = class_binding_level; b; b = b->level_chain)
1405: if (b == current_binding_level)
1406: break;
1407: if (b)
1408: b = class_binding_level;
1409: else
1410: b = current_binding_level;
1411: }
1412: else
1413: b = current_binding_level;
1414: print_other_binding_stack (b);
1415: fprintf (stderr, "global:\n");
1416: print_binding_level (global_binding_level);
1417: }
1418:
1419: /* Subroutines for reverting temporarily to top-level for instantiation
1420: of templates and such. We actually need to clear out the class- and
1421: local-value slots of all identifiers, so that only the global values
1422: are at all visible. Simply setting current_binding_level to the global
1423: scope isn't enough, because more binding levels may be pushed. */
1424: struct saved_scope {
1425: struct binding_level *old_binding_level;
1426: tree old_bindings;
1427: struct saved_scope *prev;
1428: tree class_name, class_type, class_decl, function_decl;
1429: struct binding_level *class_bindings;
1430: tree previous_class_type;
1431: tree *lang_base, *lang_stack, lang_name;
1432: int lang_stacksize;
1433: tree named_labels;
1434: };
1435: static struct saved_scope *current_saved_scope;
1436: extern tree prev_class_type;
1437:
1438: void
1439: push_to_top_level ()
1440: {
1441: extern int current_lang_stacksize;
1442: struct saved_scope *s =
1443: (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1444: struct binding_level *b = current_binding_level;
1445: tree old_bindings = NULL_TREE;
1446:
1447: /* Have to include global_binding_level, because class-level decls
1448: aren't listed anywhere useful. */
1449: for (; b; b = b->level_chain)
1450: {
1451: tree t;
1452:
1453: if (b == global_binding_level)
1454: continue;
1455:
1456: for (t = b->names; t; t = TREE_CHAIN (t))
1457: {
1458: tree binding, t1, t2 = t;
1459: tree id = DECL_ASSEMBLER_NAME (t2);
1460:
1461: if (!id
1462: || (!IDENTIFIER_LOCAL_VALUE (id)
1463: && !IDENTIFIER_CLASS_VALUE (id)))
1464: continue;
1465:
1466: for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1467: if (TREE_VEC_ELT (t1, 0) == id)
1468: goto skip_it;
1469:
1470: binding = make_tree_vec (4);
1471: if (id)
1472: {
1473: my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
1474: TREE_VEC_ELT (binding, 0) = id;
1475: TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1476: TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1477: TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1478: IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
1479: IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
1480: }
1481: TREE_CHAIN (binding) = old_bindings;
1482: old_bindings = binding;
1483: skip_it:
1484: ;
1485: }
1486: /* Unwind type-value slots back to top level. */
1487: for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1488: SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1489: }
1490: /* Clear out class-level bindings cache. */
1491: if (current_binding_level == global_binding_level
1492: && previous_class_type != NULL_TREE)
1493: {
1494: popclass (-1);
1495: previous_class_type = NULL_TREE;
1496: }
1497:
1498: s->old_binding_level = current_binding_level;
1499: current_binding_level = global_binding_level;
1500:
1501: s->class_name = current_class_name;
1502: s->class_type = current_class_type;
1503: s->class_decl = current_class_decl;
1504: s->function_decl = current_function_decl;
1505: s->class_bindings = class_binding_level;
1506: s->previous_class_type = previous_class_type;
1507: s->lang_stack = current_lang_stack;
1508: s->lang_base = current_lang_base;
1509: s->lang_stacksize = current_lang_stacksize;
1510: s->lang_name = current_lang_name;
1511: s->named_labels = named_labels;
1512: current_class_name = current_class_type = current_class_decl = NULL_TREE;
1513: current_function_decl = NULL_TREE;
1514: class_binding_level = (struct binding_level *)0;
1515: previous_class_type = NULL_TREE;
1516: current_lang_stacksize = 10;
1517: current_lang_stack = current_lang_base
1518: = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
1519: current_lang_name = lang_name_cplusplus;
1520: strict_prototype = strict_prototypes_lang_cplusplus;
1521: named_labels = NULL_TREE;
1522:
1523: s->prev = current_saved_scope;
1524: s->old_bindings = old_bindings;
1525: current_saved_scope = s;
1526: }
1527:
1528: void
1529: pop_from_top_level ()
1530: {
1531: extern int current_lang_stacksize;
1532: struct saved_scope *s = current_saved_scope;
1533: tree t;
1534:
1535: if (previous_class_type)
1536: previous_class_type = NULL_TREE;
1537:
1538: current_binding_level = s->old_binding_level;
1539: current_saved_scope = s->prev;
1540: for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1541: {
1542: tree id = TREE_VEC_ELT (t, 0);
1543: if (id)
1544: {
1545: IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1546: IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1547: IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1548: }
1549: }
1550: current_class_name = s->class_name;
1551: current_class_type = s->class_type;
1552: current_class_decl = s->class_decl;
1553: if (current_class_type)
1554: C_C_D = CLASSTYPE_INST_VAR (current_class_type);
1555: else
1556: C_C_D = NULL_TREE;
1557: current_function_decl = s->function_decl;
1558: class_binding_level = s->class_bindings;
1559: previous_class_type = s->previous_class_type;
1560: free (current_lang_base);
1561: current_lang_base = s->lang_base;
1562: current_lang_stack = s->lang_stack;
1563: current_lang_name = s->lang_name;
1564: current_lang_stacksize = s->lang_stacksize;
1565: if (current_lang_name == lang_name_cplusplus)
1566: strict_prototype = strict_prototypes_lang_cplusplus;
1567: else if (current_lang_name == lang_name_c)
1568: strict_prototype = strict_prototypes_lang_c;
1569: named_labels = s->named_labels;
1570:
1571: free (s);
1572: }
1573:
1574: /* Push a definition of struct, union or enum tag "name".
1575: into binding_level "b". "type" should be the type node,
1576: We assume that the tag "name" is not already defined.
1577:
1578: Note that the definition may really be just a forward reference.
1579: In that case, the TYPE_SIZE will be a NULL_TREE.
1580:
1581: C++ gratuitously puts all these tags in the name space. */
1582:
1583: /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
1584: record the shadowed value for this binding contour. TYPE is
1585: the type that ID maps to. */
1586:
1587: static void
1588: set_identifier_type_value_with_scope (id, type, b)
1589: tree id;
1590: tree type;
1591: struct binding_level *b;
1592: {
1593: if (b != global_binding_level)
1594: {
1595: tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1596: b->type_shadowed
1597: = tree_cons (id, old_type_value, b->type_shadowed);
1598: }
1599: SET_IDENTIFIER_TYPE_VALUE (id, type);
1600: }
1601:
1602: /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
1603:
1604: void
1605: set_identifier_type_value (id, type)
1606: tree id;
1607: tree type;
1608: {
1609: set_identifier_type_value_with_scope (id, type, inner_binding_level);
1610: }
1611:
1612: /* Subroutine "set_nested_typename" builds the nested-typename of
1613: the type decl in question. (Argument CLASSNAME can actually be
1614: a function as well, if that's the smallest containing scope.) */
1615:
1616: static void
1617: set_nested_typename (decl, classname, name, type)
1618: tree decl, classname, name, type;
1619: {
1620: my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
1621: if (classname != NULL_TREE)
1622: {
1623: char *buf;
1624: my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
1625: my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
1626: buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
1627: + IDENTIFIER_LENGTH (name));
1628: sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
1629: IDENTIFIER_POINTER (name));
1630: DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
1631: TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1;
1632:
1633: /* This is a special usage of IDENTIFIER_TYPE_VALUE which have no
1634: correspondence in any binding_level. This is ok since the
1635: DECL_NESTED_TYPENAME is just a convenience identifier whose
1636: IDENTIFIER_TYPE_VALUE will remain constant from now on. */
1637: SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
1638: }
1639: else
1640: DECL_NESTED_TYPENAME (decl) = name;
1641: }
1642:
1643: /* Pop off extraneous binding levels left over due to syntax errors. */
1644: void
1645: pop_everything ()
1646: {
1647: #ifdef DEBUG_CP_BINDING_LEVELS
1648: fprintf (stderr, "XXX entering pop_everything ()\n");
1649: #endif
1650: while (current_binding_level != global_binding_level
1651: && ! current_binding_level->pseudo_global)
1652: {
1653: if (class_binding_level)
1654: pop_nested_class (1);
1655: else
1656: poplevel (0, 0, 0);
1657: }
1658: #ifdef DEBUG_CP_BINDING_LEVELS
1659: fprintf (stderr, "XXX leaving pop_everything ()\n");
1660: #endif
1661: }
1662:
1663: #if 0 /* not yet, should get fixed properly later */
1664: /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
1665: Other routines shouldn't use build_decl directly; they'll produce
1666: incorrect results with `-g' unless they duplicate this code.
1667:
1668: This is currently needed mainly for dbxout.c, but we can make
1669: use of it in method.c later as well. */
1670: tree
1671: make_type_decl (name, type)
1672: tree name, type;
1673: {
1674: tree decl, id;
1675: decl = build_decl (TYPE_DECL, name, type);
1676: if (TYPE_NAME (type) == name)
1677: /* Class/union/enum definition, or a redundant typedef for same. */
1678: {
1679: id = get_identifier (build_overload_name (type, 1, 1));
1680: DECL_ASSEMBLER_NAME (decl) = id;
1681: }
1682: else if (TYPE_NAME (type) != NULL_TREE)
1683: /* Explicit typedef, or implicit typedef for template expansion. */
1684: DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
1685: else
1686: {
1687: /* XXX: Typedef for unnamed struct; some other situations.
1688: TYPE_NAME is null; what's right here? */
1689: }
1690: return decl;
1691: }
1692: #endif
1693:
1694: /* Push a tag name NAME for struct/class/union/enum type TYPE.
1695: Normally put into into the inner-most non-tag-tranparent scope,
1696: but if GLOBALIZE is true, put it in the inner-most non-class scope.
1697: The latter is needed for implicit declarations. */
1698:
1699: void
1700: pushtag (name, type, globalize)
1701: tree name, type;
1702: int globalize;
1703: {
1704: register struct binding_level *b;
1705: tree context = 0;
1706: tree c_decl = 0;
1707:
1708: b = inner_binding_level;
1709: while (b->tag_transparent
1710: || (globalize && b->parm_flag == 2))
1711: b = b->level_chain;
1712:
1713: if (b == global_binding_level)
1714: b->tags = perm_tree_cons (name, type, b->tags);
1715: else
1716: b->tags = saveable_tree_cons (name, type, b->tags);
1717:
1718: if (name)
1719: {
1720: context = type ? TYPE_CONTEXT (type) : NULL_TREE;
1721: if (! context && ! globalize)
1722: context = current_scope ();
1723: if (context)
1724: c_decl = TREE_CODE (context) == FUNCTION_DECL
1725: ? context : TYPE_NAME (context);
1726:
1727: /* Record the identifier as the type's name if it has none. */
1728: if (TYPE_NAME (type) == NULL_TREE)
1729: TYPE_NAME (type) = name;
1730:
1731: /* Do C++ gratuitous typedefing. */
1732: if (IDENTIFIER_TYPE_VALUE (name) != type
1733: && (TREE_CODE (type) != RECORD_TYPE
1734: || b->parm_flag != 2
1735: || !CLASSTYPE_DECLARED_EXCEPTION (type)))
1736: {
1737: register tree d;
1738: int newdecl = 0;
1739:
1740: if (b->parm_flag != 2
1741: || TYPE_SIZE (current_class_type) != NULL_TREE)
1742: {
1743: d = lookup_nested_type (type, c_decl);
1744:
1745: if (d == NULL_TREE)
1746: {
1747: newdecl = 1;
1748: #if 0 /* not yet, should get fixed properly later */
1749: d = make_type_decl (name, type);
1750: #else
1751: d = build_decl (TYPE_DECL, name, type);
1752: #endif
1753: SET_DECL_ARTIFICIAL (d);
1754: #ifdef DWARF_DEBUGGING_INFO
1755: if (write_symbols == DWARF_DEBUG)
1756: {
1757: /* Mark the TYPE_DECL node we created just above as an
1758: gratuitous one. We need to do this so that dwarfout.c
1759: will understand that it is not supposed to output a
1760: TAG_typedef DIE for it. */
1761: DECL_IGNORED_P (d) = 1;
1762: }
1763: #endif /* DWARF_DEBUGGING_INFO */
1764: set_identifier_type_value_with_scope (name, type, b);
1765: }
1766: else
1767: d = TYPE_NAME (d);
1768:
1769: /* If it is anonymous, then we are called from pushdecl,
1770: and we don't want to infinitely recurse. Also, if the
1771: name is already in scope, we don't want to push it
1772: again--pushdecl is only for pushing new decls. */
1773: if (! ANON_AGGRNAME_P (name)
1774: && TYPE_NAME (type)
1775: && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
1776: || lookup_name (name, 1) != TYPE_NAME (type)))
1777: {
1778: if (b->parm_flag == 2)
1779: d = pushdecl_class_level (d);
1780: else
1781: d = pushdecl_with_scope (d, b);
1782: }
1783: }
1784: else
1785: {
1786: /* Make nested declarations go into class-level scope. */
1787: newdecl = 1;
1788: d = build_decl (TYPE_DECL, name, type);
1789: SET_DECL_ARTIFICIAL (d);
1790: #ifdef DWARF_DEBUGGING_INFO
1791: if (write_symbols == DWARF_DEBUG)
1792: {
1793: /* Mark the TYPE_DECL node we created just above as an
1794: gratuitous one. We need to do this so that dwarfout.c
1795: will understand that it is not supposed to output a
1796: TAG_typedef DIE for it. */
1797: DECL_IGNORED_P (d) = 1;
1798: }
1799: #endif /* DWARF_DEBUGGING_INFO */
1800: /* Make sure we're in this type's scope when we push the
1801: decl for a template, otherwise class_binding_level will
1802: be NULL and we'll end up dying inside of
1803: push_class_level_binding. */
1804: if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1805: pushclass (type, 0);
1806: d = pushdecl_class_level (d);
1807: if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1808: popclass (0);
1809: }
1810: if (write_symbols != DWARF_DEBUG)
1811: {
1812: if (ANON_AGGRNAME_P (name))
1813: DECL_IGNORED_P (d) = 1;
1814: }
1815: TYPE_NAME (type) = d;
1816:
1817: if (context == NULL_TREE)
1818: /* Non-nested class. */
1819: DECL_NESTED_TYPENAME (d) = name;
1820: else if (context && TREE_CODE (context) == FUNCTION_DECL)
1821: {
1822: /* Function-nested class. */
1823: set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl),
1824: name, type);
1825: /* This builds the links for classes nested in fn scope. */
1826: DECL_CONTEXT (d) = context;
1827: }
1828: /* else if (TYPE_SIZE (current_class_type) == NULL_TREE)
1829: */
1830: else if (context && IS_AGGR_TYPE (context))
1831: {
1832: /* Class-nested class. */
1833: set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl),
1834: name, type);
1835: /* This builds the links for classes nested in type scope. */
1836: DECL_CONTEXT (d) = context;
1837: }
1838: TYPE_CONTEXT (type) = DECL_CONTEXT (d);
1839: if (newdecl)
1840: DECL_ASSEMBLER_NAME (d)
1841: = get_identifier (build_overload_name (type, 1, 1));
1842: }
1843: if (b->parm_flag == 2)
1844: {
1845: TREE_NONLOCAL_FLAG (type) = 1;
1846: if (TYPE_SIZE (current_class_type) == NULL_TREE)
1847: CLASSTYPE_TAGS (current_class_type) = b->tags;
1848: }
1849: }
1850:
1851: if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1852: /* Use the canonical TYPE_DECL for this node. */
1853: TYPE_STUB_DECL (type) = TYPE_NAME (type);
1854: else
1855: {
1856: /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
1857: will be the tagged type we just added to the current
1858: binding level. This fake NULL-named TYPE_DECL node helps
1859: dwarfout.c to know when it needs to output a
1860: representation of a tagged type, and it also gives us a
1861: convenient place to record the "scope start" address for
1862: the tagged type. */
1863:
1864: #if 0 /* not yet, should get fixed properly later */
1865: tree d = make_type_decl (NULL_TREE, type);
1866: #else
1867: tree d = build_decl (TYPE_DECL, NULL_TREE, type);
1868: #endif
1869: TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
1870: }
1871: }
1872:
1873: /* Counter used to create anonymous type names. */
1874: static int anon_cnt = 0;
1875:
1876: /* Return an IDENTIFIER which can be used as a name for
1877: anonymous structs and unions. */
1878: tree
1879: make_anon_name ()
1880: {
1881: char buf[32];
1882:
1883: sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
1884: return get_identifier (buf);
1885: }
1886:
1887: /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
1888: This keeps dbxout from getting confused. */
1889: void
1890: clear_anon_tags ()
1891: {
1892: register struct binding_level *b;
1893: register tree tags;
1894: static int last_cnt = 0;
1895:
1896: /* Fast out if no new anon names were declared. */
1897: if (last_cnt == anon_cnt)
1898: return;
1899:
1900: b = current_binding_level;
1901: while (b->tag_transparent)
1902: b = b->level_chain;
1903: tags = b->tags;
1904: while (tags)
1905: {
1906: /* A NULL purpose means we have already processed all tags
1907: from here to the end of the list. */
1908: if (TREE_PURPOSE (tags) == NULL_TREE)
1909: break;
1910: if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
1911: TREE_PURPOSE (tags) = NULL_TREE;
1912: tags = TREE_CHAIN (tags);
1913: }
1914: last_cnt = anon_cnt;
1915: }
1916:
1917: /* Subroutine of duplicate_decls: return truthvalue of whether
1918: or not types of these decls match.
1919:
1920: For C++, we must compare the parameter list so that `int' can match
1921: `int&' in a parameter position, but `int&' is not confused with
1922: `const int&'. */
1923: static int
1924: decls_match (newdecl, olddecl)
1925: tree newdecl, olddecl;
1926: {
1927: int types_match;
1928:
1929: if (TREE_CODE (newdecl) == FUNCTION_DECL
1930: && TREE_CODE (olddecl) == FUNCTION_DECL)
1931: {
1932: tree f1 = TREE_TYPE (newdecl);
1933: tree f2 = TREE_TYPE (olddecl);
1934: tree p1 = TYPE_ARG_TYPES (f1);
1935: tree p2 = TYPE_ARG_TYPES (f2);
1936:
1937: /* When we parse a static member function definition,
1938: we put together a FUNCTION_DECL which thinks its type
1939: is METHOD_TYPE. Change that to FUNCTION_TYPE, and
1940: proceed. */
1941: if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
1942: revert_static_member_fn (&newdecl, &f1, &p1);
1943: else if (TREE_CODE (f2) == METHOD_TYPE
1944: && DECL_STATIC_FUNCTION_P (newdecl))
1945: revert_static_member_fn (&olddecl, &f2, &p2);
1946:
1947: /* Here we must take care of the case where new default
1948: parameters are specified. Also, warn if an old
1949: declaration becomes ambiguous because default
1950: parameters may cause the two to be ambiguous. */
1951: if (TREE_CODE (f1) != TREE_CODE (f2))
1952: {
1953: if (TREE_CODE (f1) == OFFSET_TYPE)
1954: cp_compiler_error ("`%D' redeclared as member function", newdecl);
1955: else
1956: cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
1957: return 0;
1958: }
1959:
1960: if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1))
1961: {
1962: if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c
1963: && p2 == NULL_TREE)
1964: {
1965: types_match = self_promoting_args_p (p1);
1966: if (p1 == void_list_node)
1967: TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
1968: }
1969: else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c
1970: && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE)
1971: {
1972: types_match = self_promoting_args_p (p2);
1973: TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
1974: }
1975: else
1976: types_match = compparms (p1, p2, 3);
1977: }
1978: else
1979: types_match = 0;
1980: }
1981: else if (TREE_CODE (newdecl) == TEMPLATE_DECL
1982: && TREE_CODE (olddecl) == TEMPLATE_DECL)
1983: {
1984: tree newargs = DECL_TEMPLATE_PARMS (newdecl);
1985: tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
1986: int i, len = TREE_VEC_LENGTH (newargs);
1987:
1988: if (TREE_VEC_LENGTH (oldargs) != len)
1989: return 0;
1990:
1991: for (i = 0; i < len; i++)
1992: {
1993: tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i));
1994: tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i));
1995: if (TREE_CODE (newarg) != TREE_CODE (oldarg))
1996: return 0;
1997: else if (TREE_CODE (newarg) == TYPE_DECL)
1998: /* continue */;
1999: else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
2000: return 0;
2001: }
2002:
2003: if (DECL_TEMPLATE_IS_CLASS (newdecl)
2004: != DECL_TEMPLATE_IS_CLASS (olddecl))
2005: types_match = 0;
2006: else if (DECL_TEMPLATE_IS_CLASS (newdecl))
2007: types_match = 1;
2008: else
2009: types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
2010: DECL_TEMPLATE_RESULT (newdecl));
2011: }
2012: else
2013: {
2014: if (TREE_TYPE (newdecl) == error_mark_node)
2015: types_match = TREE_TYPE (olddecl) == error_mark_node;
2016: else if (TREE_TYPE (olddecl) == NULL_TREE)
2017: types_match = TREE_TYPE (newdecl) == NULL_TREE;
2018: else if (TREE_TYPE (newdecl) == NULL_TREE)
2019: types_match = 0;
2020: else
2021: types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
2022: }
2023:
2024: return types_match;
2025: }
2026:
2027: /* If NEWDECL is `static' and an `extern' was seen previously,
2028: warn about it. (OLDDECL may be NULL_TREE; NAME contains
2029: information about previous usage as an `extern'.)
2030:
2031: Note that this does not apply to the C++ case of declaring
2032: a variable `extern const' and then later `const'.
2033:
2034: Don't complain if -traditional, since traditional compilers
2035: don't complain.
2036:
2037: Don't complain about built-in functions, since they are beyond
2038: the user's control. */
2039:
2040: static void
2041: warn_extern_redeclared_static (newdecl, olddecl)
2042: tree newdecl, olddecl;
2043: {
2044: tree name;
2045:
2046: static char *explicit_extern_static_warning
2047: = "`%D' was declared `extern' and later `static'";
2048: static char *implicit_extern_static_warning
2049: = "`%D' was declared implicitly `extern' and later `static'";
2050:
2051: if (flag_traditional
2052: || TREE_CODE (newdecl) == TYPE_DECL
2053: || (! warn_extern_inline
2054: && DECL_INLINE (newdecl)))
2055: return;
2056:
2057: name = DECL_ASSEMBLER_NAME (newdecl);
2058: if (TREE_PUBLIC (name) && ! TREE_PUBLIC (newdecl))
2059: {
2060: /* It's okay to redeclare an ANSI built-in function as static,
2061: or to declare a non-ANSI built-in function as anything. */
2062: if (! (TREE_CODE (newdecl) == FUNCTION_DECL
2063: && olddecl != NULL_TREE
2064: && TREE_CODE (olddecl) == FUNCTION_DECL
2065: && (DECL_BUILT_IN (olddecl)
2066: || DECL_BUILT_IN_NONANSI (olddecl))))
2067: {
2068: cp_warning (IDENTIFIER_IMPLICIT_DECL (name)
2069: ? implicit_extern_static_warning
2070: : explicit_extern_static_warning, newdecl);
2071: if (olddecl != NULL_TREE)
2072: cp_warning_at ("previous declaration of `%D'", olddecl);
2073: }
2074: }
2075: }
2076:
2077: /* Handle when a new declaration NEWDECL has the same name as an old
2078: one OLDDECL in the same binding contour. Prints an error message
2079: if appropriate.
2080:
2081: If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2082: Otherwise, return 0. */
2083:
2084: int
2085: duplicate_decls (newdecl, olddecl)
2086: register tree newdecl, olddecl;
2087: {
2088: extern struct obstack permanent_obstack;
2089: unsigned olddecl_uid = DECL_UID (olddecl);
2090: int olddecl_friend = 0, types_match = 0;
2091: int new_defines_function;
2092: tree previous_c_decl = NULL_TREE;
2093:
2094: types_match = decls_match (newdecl, olddecl);
2095:
2096: if (TREE_CODE (olddecl) != TREE_LIST)
2097: olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
2098:
2099: /* If either the type of the new decl or the type of the old decl is an
2100: error_mark_node, then that implies that we have already issued an
2101: error (earlier) for some bogus type specification, and in that case,
2102: it is rather pointless to harass the user with yet more error message
2103: about the same declaration, so well just pretent the types match here. */
2104: if ((TREE_TYPE (newdecl)
2105: && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
2106: || (TREE_TYPE (olddecl)
2107: && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
2108: types_match = 1;
2109:
2110: if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
2111: && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
2112: /* If -traditional, avoid error for redeclaring fcn
2113: after implicit decl. */
2114: ;
2115: else if (TREE_CODE (olddecl) == FUNCTION_DECL
2116: && DECL_ARTIFICIAL (olddecl)
2117: && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
2118: {
2119: /* If you declare a built-in or predefined function name as static,
2120: the old definition is overridden, but optionally warn this was a
2121: bad choice of name. Ditto for overloads. */
2122: if (! TREE_PUBLIC (newdecl)
2123: || (TREE_CODE (newdecl) == FUNCTION_DECL
2124: && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
2125: {
2126: if (warn_shadow)
2127: cp_warning ("shadowing %s function `%#D'",
2128: DECL_BUILT_IN (olddecl) ? "built-in" : "library",
2129: olddecl);
2130: /* Discard the old built-in function. */
2131: return 0;
2132: }
2133: else if (! types_match)
2134: {
2135: if (TREE_CODE (newdecl) != FUNCTION_DECL)
2136: {
2137: /* If the built-in is not ansi, then programs can override
2138: it even globally without an error. */
2139: if (! DECL_BUILT_IN (olddecl))
2140: cp_warning ("library function `%#D' redeclared as non-function `%#D'",
2141: olddecl, newdecl);
2142: else
2143: {
2144: cp_error ("declaration of `%#D'", newdecl);
2145: cp_error ("conflicts with built-in declaration `%#D'",
2146: olddecl);
2147: }
2148: return 0;
2149: }
2150:
2151: cp_warning ("declaration of `%#D'", newdecl);
2152: cp_warning ("conflicts with built-in declaration `%#D'",
2153: olddecl);
2154: }
2155: }
2156: else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2157: {
2158: if ((TREE_CODE (newdecl) == FUNCTION_DECL
2159: && TREE_CODE (olddecl) == TEMPLATE_DECL
2160: && ! DECL_TEMPLATE_IS_CLASS (olddecl))
2161: || (TREE_CODE (olddecl) == FUNCTION_DECL
2162: && TREE_CODE (newdecl) == TEMPLATE_DECL
2163: && ! DECL_TEMPLATE_IS_CLASS (newdecl)))
2164: return 0;
2165:
2166: cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
2167: if (TREE_CODE (olddecl) == TREE_LIST)
2168: olddecl = TREE_VALUE (olddecl);
2169: cp_error_at ("previous declaration of `%#D'", olddecl);
2170:
2171: /* New decl is completely inconsistent with the old one =>
2172: tell caller to replace the old one. */
2173:
2174: return 0;
2175: }
2176: else if (!types_match)
2177: {
2178: if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2179: {
2180: /* The name of a class template may not be declared to refer to
2181: any other template, class, function, object, namespace, value,
2182: or type in the same scope. */
2183: if (DECL_TEMPLATE_IS_CLASS (olddecl)
2184: || DECL_TEMPLATE_IS_CLASS (newdecl))
2185: {
2186: cp_error ("declaration of template `%#D'", newdecl);
2187: cp_error_at ("conflicts with previous declaration `%#D'",
2188: olddecl);
2189: }
2190: return 0;
2191: }
2192: if (TREE_CODE (newdecl) == FUNCTION_DECL)
2193: {
2194: if (DECL_LANGUAGE (newdecl) == lang_c
2195: && DECL_LANGUAGE (olddecl) == lang_c)
2196: {
2197: cp_error ("declaration of C function `%#D' conflicts with",
2198: newdecl);
2199: cp_error_at ("previous declaration `%#D' here", olddecl);
2200: }
2201: else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2202: TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 2))
2203: {
2204: cp_error ("new declaration `%#D'", newdecl);
2205: cp_error_at ("ambiguates old declaration `%#D'", olddecl);
2206: }
2207: else
2208: return 0;
2209: }
2210:
2211: if (olddecl == wchar_decl_node)
2212: {
2213: if (pedantic && ! DECL_IN_SYSTEM_HEADER (newdecl))
2214: cp_pedwarn ("redeclaration of wchar_t as `%T'",
2215: TREE_TYPE (newdecl));
2216:
2217: /* Throw away the redeclaration. */
2218: return 1;
2219: }
2220:
2221: /* Already complained about this, so don't do so again. */
2222: else if (current_class_type == NULL_TREE
2223: || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
2224: {
2225: cp_error ("conflicting types for `%#D'", newdecl);
2226: cp_error_at ("previous declaration as `%#D'", olddecl);
2227: }
2228: }
2229: else
2230: {
2231: char *errmsg = redeclaration_error_message (newdecl, olddecl);
2232: if (errmsg)
2233: {
2234: cp_error (errmsg, newdecl);
2235: if (DECL_NAME (olddecl) != NULL_TREE)
2236: cp_error_at ((DECL_INITIAL (olddecl)
2237: && current_binding_level == global_binding_level)
2238: ? "`%#D' previously defined here"
2239: : "`%#D' previously declared here", olddecl);
2240: }
2241: else if (TREE_CODE (olddecl) == FUNCTION_DECL
2242: && DECL_INITIAL (olddecl) != NULL_TREE
2243: && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2244: && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
2245: {
2246: /* Prototype decl follows defn w/o prototype. */
2247: cp_warning_at ("prototype for `%#D'", newdecl);
2248: cp_warning_at ("follows non-prototype definition here", olddecl);
2249: }
2250: else if (TREE_CODE (olddecl) == FUNCTION_DECL
2251: && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2252: {
2253: /* extern "C" int foo ();
2254: int foo () { bar (); }
2255: is OK. */
2256: if (current_lang_stack == current_lang_base)
2257: DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2258: else
2259: {
2260: cp_error_at ("previous declaration of `%#D' with %L linkage",
2261: olddecl, DECL_LANGUAGE (olddecl));
2262: cp_error ("conflicts with new declaration with %L linkage",
2263: DECL_LANGUAGE (newdecl));
2264: }
2265: }
2266:
2267: /* These bits are logically part of the type. */
2268: if (pedantic
2269: && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
2270: || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
2271: cp_error_at ("type qualifiers for `%D' conflict with previous decl",
2272: newdecl);
2273: }
2274:
2275: /* If new decl is `static' and an `extern' was seen previously,
2276: warn about it. */
2277: warn_extern_redeclared_static (newdecl, olddecl);
2278:
2279: /* We have committed to returning 1 at this point. */
2280: if (TREE_CODE (newdecl) == FUNCTION_DECL)
2281: {
2282: /* Now that functions must hold information normally held
2283: by field decls, there is extra work to do so that
2284: declaration information does not get destroyed during
2285: definition. */
2286: if (DECL_VINDEX (olddecl))
2287: DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2288: if (DECL_CONTEXT (olddecl))
2289: DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2290: if (DECL_CLASS_CONTEXT (olddecl))
2291: DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
2292: if (DECL_CHAIN (newdecl) == NULL_TREE)
2293: DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2294: if (DECL_NEXT_METHOD (newdecl) == NULL_TREE)
2295: DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl);
2296: if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
2297: DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2298: }
2299:
2300: /* Deal with C++: must preserve virtual function table size. */
2301: if (TREE_CODE (olddecl) == TYPE_DECL)
2302: {
2303: register tree newtype = TREE_TYPE (newdecl);
2304: register tree oldtype = TREE_TYPE (olddecl);
2305:
2306: if (newtype != error_mark_node && oldtype != error_mark_node
2307: && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2308: {
2309: CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
2310: CLASSTYPE_FRIEND_CLASSES (newtype)
2311: = CLASSTYPE_FRIEND_CLASSES (oldtype);
2312: }
2313: #if 0
2314: /* why assert here? Just because debugging information is
2315: messed up? (mrs) */
2316: /* it happens on something like:
2317: typedef struct Thing {
2318: Thing();
2319: int x;
2320: } Thing;
2321: */
2322: my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl),
2323: 139);
2324: #endif
2325: }
2326:
2327: /* Special handling ensues if new decl is a function definition. */
2328: new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
2329: && DECL_INITIAL (newdecl) != NULL_TREE);
2330:
2331: /* Optionally warn about more than one declaration for the same name,
2332: but don't warn about a function declaration followed by a definition. */
2333: if (warn_redundant_decls
2334: && ! DECL_ARTIFICIAL (olddecl)
2335: && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2336: /* Don't warn about extern decl followed by (tentative) definition. */
2337: && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
2338: {
2339: cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
2340: cp_warning ("previous declaration of `%D'", olddecl);
2341: }
2342:
2343: /* Copy all the DECL_... slots specified in the new decl
2344: except for any that we copy here from the old type. */
2345:
2346: if (types_match)
2347: {
2348: /* Automatically handles default parameters. */
2349: tree oldtype = TREE_TYPE (olddecl);
2350: /* Merge the data types specified in the two decls. */
2351: tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2352:
2353: /* Make sure we put the new type in the same obstack as the old ones.
2354: If the old types are not both in the same obstack, use the permanent
2355: one. */
2356: if (oldtype && TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype))
2357: push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
2358: else
2359: {
2360: push_obstacks_nochange ();
2361: end_temporary_allocation ();
2362: }
2363:
2364: if (TREE_CODE (newdecl) == VAR_DECL)
2365: DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2366: /* Do this after calling `common_type' so that default
2367: parameters don't confuse us. */
2368: else if (TREE_CODE (newdecl) == FUNCTION_DECL
2369: && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2370: != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2371: {
2372: tree ctype = NULL_TREE;
2373: ctype = DECL_CLASS_CONTEXT (newdecl);
2374: TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
2375: TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2376: TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
2377: TYPE_RAISES_EXCEPTIONS (oldtype));
2378:
2379: if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
2380: {
2381: cp_error ("declaration of `%D' raises different exceptions...",
2382: newdecl);
2383: cp_error_at ("...from previous declaration here", olddecl);
2384: }
2385: }
2386: TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2387:
2388: /* Lay the type out, unless already done. */
2389: if (oldtype != TREE_TYPE (newdecl))
2390: {
2391: if (TREE_TYPE (newdecl) != error_mark_node)
2392: layout_type (TREE_TYPE (newdecl));
2393: if (TREE_CODE (newdecl) != FUNCTION_DECL
2394: && TREE_CODE (newdecl) != TYPE_DECL
2395: && TREE_CODE (newdecl) != CONST_DECL
2396: && TREE_CODE (newdecl) != TEMPLATE_DECL)
2397: layout_decl (newdecl, 0);
2398: }
2399: else
2400: {
2401: /* Since the type is OLDDECL's, make OLDDECL's size go with. */
2402: DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
2403: }
2404:
2405: /* Merge the type qualifiers. */
2406: if (TREE_READONLY (newdecl))
2407: TREE_READONLY (olddecl) = 1;
2408: if (TREE_THIS_VOLATILE (newdecl))
2409: TREE_THIS_VOLATILE (olddecl) = 1;
2410:
2411: /* Merge the initialization information. */
2412: if (DECL_INITIAL (newdecl) == NULL_TREE
2413: && DECL_INITIAL (olddecl) != NULL_TREE)
2414: {
2415: DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2416: DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
2417: DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
2418: }
2419:
2420: /* Merge the section attribute.
2421: We want to issue an error if the sections conflict but that must be
2422: done later in decl_attributes since we are called before attributes
2423: are assigned. */
2424: if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
2425: DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
2426:
2427: /* Keep the old rtl since we can safely use it, unless it's the
2428: call to abort() used for abstract virtuals. */
2429: if ((DECL_LANG_SPECIFIC (olddecl)
2430: && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
2431: || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
2432: DECL_RTL (newdecl) = DECL_RTL (olddecl);
2433:
2434: pop_obstacks ();
2435: }
2436: /* If cannot merge, then use the new type and qualifiers,
2437: and don't preserve the old rtl. */
2438: else
2439: {
2440: /* Clean out any memory we had of the old declaration. */
2441: tree oldstatic = value_member (olddecl, static_aggregates);
2442: if (oldstatic)
2443: TREE_VALUE (oldstatic) = error_mark_node;
2444:
2445: TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2446: TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2447: TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2448: TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2449: }
2450:
2451: /* Merge the storage class information. */
2452: if (DECL_EXTERNAL (newdecl))
2453: {
2454: TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2455: DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
2456:
2457: if (TREE_CODE (newdecl) != FUNCTION_DECL)
2458: TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2459: }
2460: else
2461: {
2462: TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2463: /* A `const' which was not declared `extern' and is
2464: in static storage is invisible. */
2465: if (TREE_CODE (newdecl) == VAR_DECL
2466: && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
2467: && ! DECL_THIS_EXTERN (newdecl))
2468: TREE_PUBLIC (newdecl) = 0;
2469: else if (TREE_CODE (newdecl) != FUNCTION_DECL)
2470: TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2471: }
2472:
2473: /* For functions, static overrides non-static. */
2474: if (TREE_CODE (newdecl) == FUNCTION_DECL)
2475: {
2476: TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
2477: /* This is since we don't automatically
2478: copy the attributes of NEWDECL into OLDDECL. */
2479: TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2480: /* If this clears `static', clear it in the identifier too. */
2481: if (! TREE_PUBLIC (olddecl))
2482: TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0;
2483: }
2484:
2485: /* If either decl says `inline', this fn is inline,
2486: unless its definition was passed already. */
2487: if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
2488: DECL_INLINE (olddecl) = 1;
2489: DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2490:
2491: if (TREE_CODE (newdecl) == FUNCTION_DECL)
2492: {
2493: if (! types_match)
2494: {
2495: DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl);
2496: DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl);
2497: DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2498: DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2499: DECL_RTL (olddecl) = DECL_RTL (newdecl);
2500: }
2501: if (new_defines_function)
2502: /* If defining a function declared with other language
2503: linkage, use the previously declared language linkage. */
2504: DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2505: else
2506: {
2507: /* If redeclaring a builtin function, and not a definition,
2508: it stays built in. */
2509: if (DECL_BUILT_IN (olddecl))
2510: {
2511: DECL_BUILT_IN (newdecl) = 1;
2512: DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2513: /* If we're keeping the built-in definition, keep the rtl,
2514: regardless of declaration matches. */
2515: DECL_RTL (newdecl) = DECL_RTL (olddecl);
2516: }
2517: else
2518: DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2519:
2520: DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2521: if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
2522: /* Previously saved insns go together with
2523: the function's previous definition. */
2524: DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2525: /* Don't clear out the arguments if we're redefining a function. */
2526: if (DECL_ARGUMENTS (olddecl))
2527: DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2528: }
2529: }
2530:
2531: if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2532: {
2533: if (DECL_TEMPLATE_INFO (olddecl)->length)
2534: DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
2535: DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl);
2536: DECL_TEMPLATE_INSTANTIATIONS (newdecl)
2537: = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
2538: if (DECL_CHAIN (newdecl) == NULL_TREE)
2539: DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2540: }
2541:
2542: /* Now preserve various other info from the definition. */
2543: TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2544: TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2545: DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2546: DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl);
2547:
2548: /* Don't really know how much of the language-specific
2549: values we should copy from old to new. */
2550: if (DECL_LANG_SPECIFIC (olddecl))
2551: {
2552: DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2553: DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
2554: }
2555:
2556: if (TREE_CODE (newdecl) == FUNCTION_DECL)
2557: {
2558: int function_size;
2559: struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
2560: struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
2561:
2562: function_size = sizeof (struct tree_decl);
2563:
2564: bcopy ((char *) newdecl + sizeof (struct tree_common),
2565: (char *) olddecl + sizeof (struct tree_common),
2566: function_size - sizeof (struct tree_common));
2567:
2568: /* Can we safely free the storage used by newdecl? */
2569:
2570: #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2571: & ~ obstack_alignment_mask (&permanent_obstack))
2572:
2573: if ((char *)newdecl + ROUND (function_size)
2574: + ROUND (sizeof (struct lang_decl))
2575: == obstack_next_free (&permanent_obstack))
2576: {
2577: DECL_MAIN_VARIANT (newdecl) = olddecl;
2578: DECL_LANG_SPECIFIC (olddecl) = ol;
2579: bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
2580:
2581: obstack_free (&permanent_obstack, newdecl);
2582: }
2583: else if (LANG_DECL_PERMANENT (ol))
2584: {
2585: if (DECL_MAIN_VARIANT (olddecl) == olddecl)
2586: {
2587: /* Save these lang_decls that would otherwise be lost. */
2588: extern tree free_lang_decl_chain;
2589: tree free_lang_decl = (tree) ol;
2590: TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
2591: free_lang_decl_chain = free_lang_decl;
2592: }
2593: else
2594: {
2595: /* Storage leak. */
2596: }
2597: }
2598: }
2599: else
2600: {
2601: bcopy ((char *) newdecl + sizeof (struct tree_common),
2602: (char *) olddecl + sizeof (struct tree_common),
2603: sizeof (struct tree_decl) - sizeof (struct tree_common)
2604: + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
2605: }
2606:
2607: DECL_UID (olddecl) = olddecl_uid;
2608: if (olddecl_friend)
2609: DECL_FRIEND_P (olddecl) = 1;
2610:
2611: return 1;
2612: }
2613:
2614: /* Record a decl-node X as belonging to the current lexical scope.
2615: Check for errors (such as an incompatible declaration for the same
2616: name already seen in the same scope).
2617:
2618: Returns either X or an old decl for the same name.
2619: If an old decl is returned, it may have been smashed
2620: to agree with what X says. */
2621:
2622: tree
2623: pushdecl (x)
2624: tree x;
2625: {
2626: register tree t;
2627: #if 0 /* not yet, should get fixed properly later */
2628: register tree name;
2629: #else
2630: register tree name = DECL_ASSEMBLER_NAME (x);
2631: #endif
2632: register struct binding_level *b = current_binding_level;
2633:
2634: #if 0
2635: static int nglobals; int len;
2636:
2637: len = list_length (global_binding_level->names);
2638: if (len < nglobals)
2639: my_friendly_abort (8);
2640: else if (len > nglobals)
2641: nglobals = len;
2642: #endif
2643:
2644: if (x != current_function_decl
2645: /* Don't change DECL_CONTEXT of virtual methods. */
2646: && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x))
2647: && ! DECL_CONTEXT (x))
2648: DECL_CONTEXT (x) = current_function_decl;
2649: /* A local declaration for a function doesn't constitute nesting. */
2650: if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
2651: DECL_CONTEXT (x) = 0;
2652:
2653: #if 0 /* not yet, should get fixed properly later */
2654: /* For functions and class static data, we currently look up the encoded
2655: form of the name. For types, we want the real name. The former will
2656: probably be changed soon, according to MDT. */
2657: if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
2658: name = DECL_ASSEMBLER_NAME (x);
2659: else
2660: name = DECL_NAME (x);
2661: #else
2662: /* Type are looked up using the DECL_NAME, as that is what the rest of the
2663: compiler wants to use. */
2664: if (TREE_CODE (x) == TYPE_DECL)
2665: name = DECL_NAME (x);
2666: #endif
2667:
2668: if (name)
2669: {
2670: char *file;
2671: int line;
2672:
2673: t = lookup_name_current_level (name);
2674: if (t == error_mark_node)
2675: {
2676: /* error_mark_node is 0 for a while during initialization! */
2677: t = NULL_TREE;
2678: cp_error_at ("`%#D' used prior to declaration", x);
2679: }
2680:
2681: else if (t != NULL_TREE)
2682: {
2683: if (TREE_CODE (t) == PARM_DECL)
2684: {
2685: if (DECL_CONTEXT (t) == NULL_TREE)
2686: fatal ("parse errors have confused me too much");
2687: }
2688: file = DECL_SOURCE_FILE (t);
2689: line = DECL_SOURCE_LINE (t);
2690:
2691: if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c)
2692: || (TREE_CODE (x) == TEMPLATE_DECL
2693: && ! DECL_TEMPLATE_IS_CLASS (x)))
2694: && is_overloaded_fn (t))
2695: /* don't do anything just yet */;
2696: else if (TREE_CODE (t) != TREE_CODE (x))
2697: {
2698: if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
2699: || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)))
2700: {
2701: /* We do nothing special here, because C++ does such nasty
2702: things with TYPE_DECLs. Instead, just let the TYPE_DECL
2703: get shadowed, and know that if we need to find a TYPE_DECL
2704: for a given name, we can look in the IDENTIFIER_TYPE_VALUE
2705: slot of the identifier. */
2706: ;
2707: }
2708: else if (duplicate_decls (x, t))
2709: return t;
2710: }
2711: else if (duplicate_decls (x, t))
2712: {
2713: #if 0
2714: /* This is turned off until I have time to do it right (bpk). */
2715:
2716: /* Also warn if they did a prototype with `static' on it, but
2717: then later left the `static' off. */
2718: if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
2719: {
2720: if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
2721: return t;
2722:
2723: if (extra_warnings)
2724: {
2725: cp_warning ("`static' missing from declaration of `%D'",
2726: t);
2727: warning_with_file_and_line (file, line,
2728: "previous declaration of `%s'",
2729: decl_as_string (t, 0));
2730: }
2731:
2732: /* Now fix things so it'll do what they expect. */
2733: if (current_function_decl)
2734: TREE_PUBLIC (current_function_decl) = 0;
2735: }
2736: /* Due to interference in memory reclamation (X may be
2737: obstack-deallocated at this point), we must guard against
2738: one really special case. [jason: This should be handled
2739: by start_function] */
2740: if (current_function_decl == x)
2741: current_function_decl = t;
2742: #endif
2743: if (TREE_CODE (t) == TYPE_DECL)
2744: SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
2745:
2746: return t;
2747: }
2748: }
2749:
2750: if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
2751: {
2752: t = push_overloaded_decl (x, 1);
2753: if (t != x || DECL_LANGUAGE (x) == lang_c)
2754: return t;
2755: }
2756: else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x))
2757: return push_overloaded_decl (x, 0);
2758:
2759: /* If declaring a type as a typedef, and the type has no known
2760: typedef name, install this TYPE_DECL as its typedef name. */
2761: if (TREE_CODE (x) == TYPE_DECL)
2762: {
2763: tree type = TREE_TYPE (x);
2764: tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
2765:
2766: if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
2767: {
2768: /* If these are different names, and we're at the global
2769: binding level, make two equivalent definitions. */
2770: name = x;
2771: if (global_bindings_p ())
2772: TYPE_NAME (type) = x;
2773: }
2774: else
2775: {
2776: tree tname = DECL_NAME (name);
2777:
2778: if (global_bindings_p () && ANON_AGGRNAME_P (tname))
2779: {
2780: /* do gratuitous C++ typedefing, and make sure that
2781: we access this type either through TREE_TYPE field
2782: or via the tags list. */
2783: TYPE_NAME (TREE_TYPE (x)) = x;
2784: pushtag (tname, TREE_TYPE (x), 0);
2785: }
2786: }
2787: my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
2788:
2789: if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
2790: set_nested_typename (x, current_class_name,
2791: DECL_NAME (name), type);
2792:
2793: if (type != error_mark_node
2794: && TYPE_NAME (type)
2795: && TYPE_IDENTIFIER (type))
2796: set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
2797: }
2798:
2799: /* Multiple external decls of the same identifier ought to match.
2800:
2801: We get warnings about inline functions where they are defined.
2802: We get warnings about other functions from push_overloaded_decl.
2803:
2804: Avoid duplicate warnings where they are used. */
2805: if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
2806: {
2807: tree decl;
2808:
2809: if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
2810: && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2811: || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
2812: decl = IDENTIFIER_GLOBAL_VALUE (name);
2813: else
2814: decl = NULL_TREE;
2815:
2816: if (decl
2817: /* If different sort of thing, we already gave an error. */
2818: && TREE_CODE (decl) == TREE_CODE (x)
2819: && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1))
2820: {
2821: cp_pedwarn ("type mismatch with previous external decl", x);
2822: cp_pedwarn_at ("previous external decl of `%#D'", decl);
2823: }
2824: }
2825:
2826: /* In PCC-compatibility mode, extern decls of vars with no current decl
2827: take effect at top level no matter where they are. */
2828: if (flag_traditional && DECL_EXTERNAL (x)
2829: && lookup_name (name, 0) == NULL_TREE)
2830: b = global_binding_level;
2831:
2832: /* This name is new in its binding level.
2833: Install the new declaration and return it. */
2834: if (b == global_binding_level)
2835: {
2836: /* Install a global value. */
2837:
2838: /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
2839: A `const' which was not declared `extern' is invisible. */
2840: if (TREE_CODE (x) == VAR_DECL
2841: && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x))
2842: TREE_PUBLIC (x) = 0;
2843:
2844: /* If the first global decl has external linkage,
2845: warn if we later see static one. */
2846: if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
2847: TREE_PUBLIC (name) = 1;
2848:
2849: /* Don't install a TYPE_DECL if we already have another
2850: sort of _DECL with that name. */
2851: if (TREE_CODE (x) != TYPE_DECL
2852: || t == NULL_TREE
2853: || TREE_CODE (t) == TYPE_DECL)
2854: IDENTIFIER_GLOBAL_VALUE (name) = x;
2855:
2856: /* Don't forget if the function was used via an implicit decl. */
2857: if (IDENTIFIER_IMPLICIT_DECL (name)
2858: && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2859: TREE_USED (x) = 1;
2860:
2861: /* Don't forget if its address was taken in that way. */
2862: if (IDENTIFIER_IMPLICIT_DECL (name)
2863: && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2864: TREE_ADDRESSABLE (x) = 1;
2865:
2866: /* Warn about mismatches against previous implicit decl. */
2867: if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
2868: /* If this real decl matches the implicit, don't complain. */
2869: && ! (TREE_CODE (x) == FUNCTION_DECL
2870: && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
2871: cp_warning
2872: ("`%D' was previously implicitly declared to return `int'", x);
2873:
2874: /* If new decl is `static' and an `extern' was seen previously,
2875: warn about it. */
2876: if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
2877: warn_extern_redeclared_static (x, t);
2878: }
2879: else
2880: {
2881: /* Here to install a non-global value. */
2882: tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2883: tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2884:
2885: b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2886: IDENTIFIER_LOCAL_VALUE (name) = x;
2887:
2888: /* If this is a TYPE_DECL, push it into the type value slot. */
2889: if (TREE_CODE (x) == TYPE_DECL)
2890: set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
2891:
2892: /* If this is an extern function declaration, see if we
2893: have a global definition or declaration for the function. */
2894: if (oldlocal == NULL_TREE
2895: && DECL_EXTERNAL (x) && !DECL_INLINE (x)
2896: && oldglobal != NULL_TREE
2897: && TREE_CODE (x) == FUNCTION_DECL
2898: && TREE_CODE (oldglobal) == FUNCTION_DECL)
2899: {
2900: /* We have one. Their types must agree. */
2901: if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
2902: {
2903: cp_warning ("extern declaration of `%#D' doesn't match", x);
2904: cp_warning_at ("global declaration `%#D'", oldglobal);
2905: }
2906: else
2907: {
2908: /* Inner extern decl is inline if global one is.
2909: Copy enough to really inline it. */
2910: if (DECL_INLINE (oldglobal))
2911: {
2912: DECL_INLINE (x) = DECL_INLINE (oldglobal);
2913: DECL_INITIAL (x) = (current_function_decl == oldglobal
2914: ? NULL_TREE : DECL_INITIAL (oldglobal));
2915: DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
2916: DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal);
2917: DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
2918: DECL_RESULT (x) = DECL_RESULT (oldglobal);
2919: TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
2920: DECL_ABSTRACT_ORIGIN (x) = oldglobal;
2921: }
2922: /* Inner extern decl is built-in if global one is. */
2923: if (DECL_BUILT_IN (oldglobal))
2924: {
2925: DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
2926: DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal);
2927: }
2928: /* Keep the arg types from a file-scope fcn defn. */
2929: if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != NULL_TREE
2930: && DECL_INITIAL (oldglobal)
2931: && TYPE_ARG_TYPES (TREE_TYPE (x)) == NULL_TREE)
2932: TREE_TYPE (x) = TREE_TYPE (oldglobal);
2933: }
2934: }
2935: /* If we have a local external declaration,
2936: and no file-scope declaration has yet been seen,
2937: then if we later have a file-scope decl it must not be static. */
2938: if (oldlocal == NULL_TREE
2939: && oldglobal == NULL_TREE
2940: && DECL_EXTERNAL (x)
2941: && TREE_PUBLIC (x))
2942: {
2943: TREE_PUBLIC (name) = 1;
2944: }
2945:
2946: if (DECL_FROM_INLINE (x))
2947: /* Inline decls shadow nothing. */;
2948:
2949: /* Warn if shadowing an argument at the top level of the body. */
2950: else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
2951: && TREE_CODE (oldlocal) == PARM_DECL
2952: && TREE_CODE (x) != PARM_DECL)
2953: {
2954: /* Go to where the parms should be and see if we
2955: find them there. */
2956: struct binding_level *b = current_binding_level->level_chain;
2957:
2958: if (cleanup_label)
2959: b = b->level_chain;
2960:
2961: /* ARM $8.3 */
2962: if (b->parm_flag == 1)
2963: cp_error ("declaration of `%#D' shadows a parameter", name);
2964: }
2965: /* Maybe warn if shadowing something else. */
2966: else if (warn_shadow && !DECL_EXTERNAL (x)
2967: /* No shadow warnings for internally generated vars. */
2968: && ! DECL_ARTIFICIAL (x)
2969: /* No shadow warnings for vars made for inlining. */
2970: && ! DECL_FROM_INLINE (x))
2971: {
2972: char *warnstring = NULL;
2973:
2974: if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
2975: warnstring = "declaration of `%s' shadows a parameter";
2976: else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
2977: && !TREE_STATIC (name))
2978: warnstring = "declaration of `%s' shadows a member of `this'";
2979: else if (oldlocal != NULL_TREE)
2980: warnstring = "declaration of `%s' shadows previous local";
2981: else if (oldglobal != NULL_TREE)
2982: warnstring = "declaration of `%s' shadows global declaration";
2983:
2984: if (warnstring)
2985: warning (warnstring, IDENTIFIER_POINTER (name));
2986: }
2987:
2988: /* If storing a local value, there may already be one (inherited).
2989: If so, record it for restoration when this binding level ends. */
2990: if (oldlocal != NULL_TREE)
2991: b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2992: }
2993:
2994: /* Keep count of variables in this level with incomplete type. */
2995: if (TREE_CODE (x) != TEMPLATE_DECL
2996: && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
2997: && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
2998: {
2999: if (++b->n_incomplete == 0)
3000: error ("too many incomplete variables at this point");
3001: }
3002: }
3003:
3004: if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE)
3005: {
3006: if (current_class_name)
3007: {
3008: if (! TREE_MANGLED (name))
3009: set_nested_typename (x, current_class_name, DECL_NAME (x),
3010: TREE_TYPE (x));
3011: }
3012: }
3013:
3014: /* Put decls on list in reverse order.
3015: We will reverse them later if necessary. */
3016: TREE_CHAIN (x) = b->names;
3017: b->names = x;
3018: if (! (b != global_binding_level || TREE_PERMANENT (x)))
3019: my_friendly_abort (124);
3020:
3021: return x;
3022: }
3023:
3024: /* Same as pushdecl, but define X in binding-level LEVEL. */
3025:
3026: static tree
3027: pushdecl_with_scope (x, level)
3028: tree x;
3029: struct binding_level *level;
3030: {
3031: register struct binding_level *b = current_binding_level;
3032:
3033: current_binding_level = level;
3034: x = pushdecl (x);
3035: current_binding_level = b;
3036: return x;
3037: }
3038:
3039: /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
3040: if appropriate. */
3041: tree
3042: pushdecl_top_level (x)
3043: tree x;
3044: {
3045: register struct binding_level *b = inner_binding_level;
3046: register tree t = pushdecl_with_scope (x, global_binding_level);
3047:
3048: /* Now, the type_shadowed stack may screw us. Munge it so it does
3049: what we want. */
3050: if (TREE_CODE (x) == TYPE_DECL)
3051: {
3052: tree name = DECL_NAME (x);
3053: tree newval;
3054: tree *ptr = (tree *)0;
3055: for (; b != global_binding_level; b = b->level_chain)
3056: {
3057: tree shadowed = b->type_shadowed;
3058: for (; shadowed; shadowed = TREE_CHAIN (shadowed))
3059: if (TREE_PURPOSE (shadowed) == name)
3060: {
3061: ptr = &TREE_VALUE (shadowed);
3062: /* Can't break out of the loop here because sometimes
3063: a binding level will have duplicate bindings for
3064: PT names. It's gross, but I haven't time to fix it. */
3065: }
3066: }
3067: newval = TREE_TYPE (x);
3068: if (ptr == (tree *)0)
3069: {
3070: /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3071: up here if this is changed to an assertion. --KR */
3072: SET_IDENTIFIER_TYPE_VALUE (name, newval);
3073: }
3074: else
3075: {
3076: #if 0
3077: /* Disabled this 11/10/92, since there are many cases which
3078: behave just fine when *ptr doesn't satisfy either of these.
3079: For example, nested classes declared as friends of their enclosing
3080: class will not meet this criteria. (bpk) */
3081: my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
3082: #endif
3083: *ptr = newval;
3084: }
3085: }
3086: return t;
3087: }
3088:
3089: /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3090: if appropriate. */
3091: void
3092: push_overloaded_decl_top_level (x, forget)
3093: tree x;
3094: int forget;
3095: {
3096: struct binding_level *b = current_binding_level;
3097:
3098: current_binding_level = global_binding_level;
3099: push_overloaded_decl (x, forget);
3100: current_binding_level = b;
3101: }
3102:
3103: /* Make the declaration of X appear in CLASS scope. */
3104: tree
3105: pushdecl_class_level (x)
3106: tree x;
3107: {
3108: /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3109: scope looks for the pre-mangled name. */
3110: register tree name = DECL_NAME (x);
3111:
3112: if (name)
3113: {
3114: if (TYPE_BEING_DEFINED (current_class_type))
3115: {
3116: /* Check for inconsistent use of this name in the class body.
3117: Types, enums, and static vars are checked here; other
3118: members are checked in finish_struct. */
3119: tree icv = IDENTIFIER_CLASS_VALUE (name);
3120:
3121: if (icv
3122: /* Don't complain about inherited names. */
3123: && id_in_current_class (name)
3124: /* Or shadowed tags. */
3125: && !(TREE_CODE (icv) == TYPE_DECL
3126: && DECL_CONTEXT (icv) == current_class_type))
3127: {
3128: cp_error ("declaration of identifier `%D' as `%#D'", name, x);
3129: cp_error_at ("conflicts with previous use in class as `%#D'",
3130: icv);
3131: }
3132: }
3133:
3134: push_class_level_binding (name, x);
3135: if (TREE_CODE (x) == TYPE_DECL)
3136: {
3137: set_identifier_type_value (name, TREE_TYPE (x));
3138: if (!DECL_NESTED_TYPENAME (x))
3139: set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
3140: }
3141: }
3142: return x;
3143: }
3144:
3145: /* This function is used to push the mangled decls for nested types into
3146: the appropriate scope. Previously pushdecl_top_level was used, but that
3147: is incorrect for members of local classes. */
3148: tree
3149: pushdecl_nonclass_level (x)
3150: tree x;
3151: {
3152: struct binding_level *b = current_binding_level;
3153:
3154: #if 0
3155: /* Get out of class scope -- this isn't necessary, because class scope
3156: doesn't make it into current_binding_level. */
3157: while (b->parm_flag == 2)
3158: b = b->level_chain;
3159: #else
3160: my_friendly_assert (b->parm_flag != 2, 180);
3161: #endif
3162:
3163: /* Get out of template binding levels */
3164: while (b->pseudo_global)
3165: b = b->level_chain;
3166:
3167: pushdecl_with_scope (x, b);
3168: }
3169:
3170: /* Make the declaration(s) of X appear in CLASS scope
3171: under the name NAME. */
3172: void
3173: push_class_level_binding (name, x)
3174: tree name;
3175: tree x;
3176: {
3177: maybe_push_cache_obstack ();
3178: class_binding_level->class_shadowed
3179: = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
3180: class_binding_level->class_shadowed);
3181: pop_obstacks ();
3182: IDENTIFIER_CLASS_VALUE (name) = x;
3183: obstack_ptr_grow (&decl_obstack, x);
3184: }
3185:
3186: /* Tell caller how to interpret a TREE_LIST which contains
3187: chains of FUNCTION_DECLS. */
3188: int
3189: overloaded_globals_p (list)
3190: tree list;
3191: {
3192: my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
3193:
3194: /* Don't commit caller to seeing them as globals. */
3195: if (TREE_NONLOCAL_FLAG (list))
3196: return -1;
3197: /* Do commit caller to seeing them as globals. */
3198: if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
3199: return 1;
3200: /* Do commit caller to not seeing them as globals. */
3201: return 0;
3202: }
3203:
3204: /* DECL is a FUNCTION_DECL which may have other definitions already in
3205: place. We get around this by making the value of the identifier point
3206: to a list of all the things that want to be referenced by that name. It
3207: is then up to the users of that name to decide what to do with that
3208: list.
3209:
3210: DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3211: slot. It is dealt with the same way.
3212:
3213: The value returned may be a previous declaration if we guessed wrong
3214: about what language DECL should belong to (C or C++). Otherwise,
3215: it's always DECL (and never something that's not a _DECL). */
3216: tree
3217: push_overloaded_decl (decl, forgettable)
3218: tree decl;
3219: int forgettable;
3220: {
3221: tree orig_name = DECL_NAME (decl);
3222: tree old;
3223: int doing_global = (global_bindings_p () || ! forgettable
3224: || flag_traditional || pseudo_global_level_p ());
3225:
3226: if (doing_global)
3227: {
3228: old = IDENTIFIER_GLOBAL_VALUE (orig_name);
3229: if (old && TREE_CODE (old) == FUNCTION_DECL
3230: && DECL_ARTIFICIAL (old)
3231: && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
3232: {
3233: if (duplicate_decls (decl, old))
3234: return old;
3235: old = NULL_TREE;
3236: }
3237: }
3238: else
3239: {
3240: old = IDENTIFIER_LOCAL_VALUE (orig_name);
3241:
3242: if (! purpose_member (orig_name, current_binding_level->shadowed))
3243: {
3244: current_binding_level->shadowed
3245: = tree_cons (orig_name, old, current_binding_level->shadowed);
3246: old = NULL_TREE;
3247: }
3248: }
3249:
3250: if (old)
3251: {
3252: #if 0
3253: /* We cache the value of builtin functions as ADDR_EXPRs
3254: in the name space. Convert it to some kind of _DECL after
3255: remembering what to forget. */
3256: if (TREE_CODE (old) == ADDR_EXPR)
3257: old = TREE_OPERAND (old, 0);
3258: else
3259: #endif
3260: if (TREE_CODE (old) == VAR_DECL)
3261: {
3262: cp_error_at ("previous non-function declaration `%#D'", old);
3263: cp_error ("conflicts with function declaration `%#D'", decl);
3264: return error_mark_node;
3265: }
3266: else if (TREE_CODE (old) == TYPE_DECL)
3267: {
3268: tree t = TREE_TYPE (old);
3269: if (IS_AGGR_TYPE (t) && warn_shadow)
3270: cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
3271: old = NULL_TREE;
3272: }
3273: else if (is_overloaded_fn (old))
3274: {
3275: tree tmp;
3276:
3277: for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp))
3278: if (decl == tmp || duplicate_decls (decl, tmp))
3279: return tmp;
3280: }
3281: }
3282:
3283: if (old || TREE_CODE (decl) == TEMPLATE_DECL)
3284: {
3285: if (old && is_overloaded_fn (old))
3286: DECL_CHAIN (decl) = get_first_fn (old);
3287: else
3288: DECL_CHAIN (decl) = NULL_TREE;
3289: old = tree_cons (orig_name, decl, NULL_TREE);
3290: TREE_TYPE (old) = unknown_type_node;
3291: }
3292: else
3293: /* orig_name is not ambiguous. */
3294: old = decl;
3295:
3296: if (doing_global)
3297: IDENTIFIER_GLOBAL_VALUE (orig_name) = old;
3298: else
3299: IDENTIFIER_LOCAL_VALUE (orig_name) = old;
3300:
3301: return decl;
3302: }
3303:
3304: /* Generate an implicit declaration for identifier FUNCTIONID
3305: as a function of type int (). Print a warning if appropriate. */
3306:
3307: tree
3308: implicitly_declare (functionid)
3309: tree functionid;
3310: {
3311: register tree decl;
3312: int temp = allocation_temporary_p ();
3313:
3314: push_obstacks_nochange ();
3315:
3316: /* Save the decl permanently so we can warn if definition follows.
3317: In ANSI C, warn_implicit is usually false, so the saves little space.
3318: But in C++, it's usually true, hence the extra code. */
3319: if (temp && (flag_traditional || !warn_implicit
3320: || current_binding_level == global_binding_level))
3321: end_temporary_allocation ();
3322:
3323: /* We used to reuse an old implicit decl here,
3324: but this loses with inline functions because it can clobber
3325: the saved decl chains. */
3326: decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
3327:
3328: DECL_EXTERNAL (decl) = 1;
3329: TREE_PUBLIC (decl) = 1;
3330:
3331: /* ANSI standard says implicit declarations are in the innermost block.
3332: So we record the decl in the standard fashion.
3333: If flag_traditional is set, pushdecl does it top-level. */
3334: pushdecl (decl);
3335: rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
3336:
3337: if (warn_implicit
3338: /* Only one warning per identifier. */
3339: && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
3340: {
3341: cp_pedwarn ("implicit declaration of function `%#D'", decl);
3342: }
3343:
3344: SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
3345:
3346: pop_obstacks ();
3347:
3348: return decl;
3349: }
3350:
3351: /* Return zero if the declaration NEWDECL is valid
3352: when the declaration OLDDECL (assumed to be for the same name)
3353: has already been seen.
3354: Otherwise return an error message format string with a %s
3355: where the identifier should go. */
3356:
3357: static char *
3358: redeclaration_error_message (newdecl, olddecl)
3359: tree newdecl, olddecl;
3360: {
3361: if (TREE_CODE (newdecl) == TYPE_DECL)
3362: {
3363: /* Because C++ can put things into name space for free,
3364: constructs like "typedef struct foo { ... } foo"
3365: would look like an erroneous redeclaration. */
3366: if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
3367: return 0;
3368: else
3369: return "redefinition of `%#D'";
3370: }
3371: else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3372: {
3373: /* If this is a pure function, its olddecl will actually be
3374: the original initialization to `0' (which we force to call
3375: abort()). Don't complain about redefinition in this case. */
3376: if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
3377: return 0;
3378:
3379: /* Declarations of functions can insist on internal linkage
3380: but they can't be inconsistent with internal linkage,
3381: so there can be no error on that account.
3382: However defining the same name twice is no good. */
3383: if (DECL_INITIAL (olddecl) != NULL_TREE
3384: && DECL_INITIAL (newdecl) != NULL_TREE
3385: /* However, defining once as extern inline and a second
3386: time in another way is ok. */
3387: && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
3388: && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
3389: {
3390: if (DECL_NAME (olddecl) == NULL_TREE)
3391: return "`%#D' not declared in class";
3392: else
3393: return "redefinition of `%#D'";
3394: }
3395:
3396: {
3397: tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
3398: tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
3399:
3400: if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
3401: t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
3402:
3403: for (; t1; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3404: if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
3405: return "duplicate default arguments given for `%#D'";
3406: }
3407: return 0;
3408: }
3409: else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3410: {
3411: if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl))
3412: return "redefinition of `%#D'";
3413: return 0;
3414: }
3415: else if (current_binding_level == global_binding_level)
3416: {
3417: /* Objects declared at top level: */
3418: /* If at least one is a reference, it's ok. */
3419: if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3420: return 0;
3421: /* Now we have two tentative defs, or one tentative and one real def. */
3422: /* Insist that the linkage match. */
3423: if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
3424: return "conflicting declarations of `%#D'";
3425: /* Reject two definitions. */
3426: return "redefinition of `%#D'";
3427: }
3428: else
3429: {
3430: /* Objects declared with block scope: */
3431: /* Reject two definitions, and reject a definition
3432: together with an external reference. */
3433: if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3434: return "redeclaration of `%#D'";
3435: return 0;
3436: }
3437: }
3438:
3439: /* Get the LABEL_DECL corresponding to identifier ID as a label.
3440: Create one if none exists so far for the current function.
3441: This function is called for both label definitions and label references. */
3442:
3443: tree
3444: lookup_label (id)
3445: tree id;
3446: {
3447: register tree decl = IDENTIFIER_LABEL_VALUE (id);
3448:
3449: if (current_function_decl == NULL_TREE)
3450: {
3451: error ("label `%s' referenced outside of any function",
3452: IDENTIFIER_POINTER (id));
3453: return NULL_TREE;
3454: }
3455:
3456: if ((decl == NULL_TREE
3457: || DECL_SOURCE_LINE (decl) == 0)
3458: && (named_label_uses == NULL_TREE
3459: || TREE_PURPOSE (named_label_uses) != current_binding_level->names
3460: || TREE_VALUE (named_label_uses) != decl))
3461: {
3462: named_label_uses
3463: = tree_cons (current_binding_level->names, decl, named_label_uses);
3464: TREE_TYPE (named_label_uses) = (tree)current_binding_level;
3465: }
3466:
3467: /* Use a label already defined or ref'd with this name. */
3468: if (decl != NULL_TREE)
3469: {
3470: /* But not if it is inherited and wasn't declared to be inheritable. */
3471: if (DECL_CONTEXT (decl) != current_function_decl
3472: && ! C_DECLARED_LABEL_FLAG (decl))
3473: return shadow_label (id);
3474: return decl;
3475: }
3476:
3477: decl = build_decl (LABEL_DECL, id, void_type_node);
3478:
3479: /* A label not explicitly declared must be local to where it's ref'd. */
3480: DECL_CONTEXT (decl) = current_function_decl;
3481:
3482: DECL_MODE (decl) = VOIDmode;
3483:
3484: /* Say where one reference is to the label,
3485: for the sake of the error if it is not defined. */
3486: DECL_SOURCE_LINE (decl) = lineno;
3487: DECL_SOURCE_FILE (decl) = input_filename;
3488:
3489: SET_IDENTIFIER_LABEL_VALUE (id, decl);
3490:
3491: named_labels = tree_cons (NULL_TREE, decl, named_labels);
3492: TREE_VALUE (named_label_uses) = decl;
3493:
3494: return decl;
3495: }
3496:
3497: /* Make a label named NAME in the current function,
3498: shadowing silently any that may be inherited from containing functions
3499: or containing scopes.
3500:
3501: Note that valid use, if the label being shadowed
3502: comes from another scope in the same function,
3503: requires calling declare_nonlocal_label right away. */
3504:
3505: tree
3506: shadow_label (name)
3507: tree name;
3508: {
3509: register tree decl = IDENTIFIER_LABEL_VALUE (name);
3510:
3511: if (decl != NULL_TREE)
3512: {
3513: shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3514: SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3515: SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
3516: }
3517:
3518: return lookup_label (name);
3519: }
3520:
3521: /* Define a label, specifying the location in the source file.
3522: Return the LABEL_DECL node for the label, if the definition is valid.
3523: Otherwise return 0. */
3524:
3525: tree
3526: define_label (filename, line, name)
3527: char *filename;
3528: int line;
3529: tree name;
3530: {
3531: tree decl = lookup_label (name);
3532:
3533: /* After labels, make any new cleanups go into their
3534: own new (temporary) binding contour. */
3535: current_binding_level->more_cleanups_ok = 0;
3536:
3537: /* If label with this name is known from an outer context, shadow it. */
3538: if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
3539: {
3540: shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3541: SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3542: decl = lookup_label (name);
3543: }
3544:
3545: if (DECL_INITIAL (decl) != NULL_TREE)
3546: {
3547: cp_error ("duplicate label `%D'", decl);
3548: return 0;
3549: }
3550: else
3551: {
3552: tree uses, prev;
3553:
3554: /* Mark label as having been defined. */
3555: DECL_INITIAL (decl) = error_mark_node;
3556: /* Say where in the source. */
3557: DECL_SOURCE_FILE (decl) = filename;
3558: DECL_SOURCE_LINE (decl) = line;
3559:
3560: for (prev = NULL_TREE, uses = named_label_uses;
3561: uses;
3562: prev = uses, uses = TREE_CHAIN (uses))
3563: if (TREE_VALUE (uses) == decl)
3564: {
3565: struct binding_level *b = current_binding_level;
3566: while (b)
3567: {
3568: tree new_decls = b->names;
3569: tree old_decls = ((tree)b == TREE_TYPE (uses)
3570: ? TREE_PURPOSE (uses) : NULL_TREE);
3571: while (new_decls != old_decls)
3572: {
3573: if (TREE_CODE (new_decls) == VAR_DECL
3574: /* Don't complain about crossing initialization
3575: of internal entities. They can't be accessed,
3576: and they should be cleaned up
3577: by the time we get to the label. */
3578: && ! DECL_ARTIFICIAL (new_decls)
3579: && ((DECL_INITIAL (new_decls) != NULL_TREE
3580: && DECL_INITIAL (new_decls) != error_mark_node)
3581: || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
3582: {
3583: if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
3584: cp_error ("invalid jump to label `%D'", decl);
3585: SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
3586: cp_error ("crosses initialization of `%D'", new_decls);
3587: }
3588: new_decls = TREE_CHAIN (new_decls);
3589: }
3590: if ((tree)b == TREE_TYPE (uses))
3591: break;
3592: b = b->level_chain;
3593: }
3594:
3595: if (prev)
3596: TREE_CHAIN (prev) = TREE_CHAIN (uses);
3597: else
3598: named_label_uses = TREE_CHAIN (uses);
3599: }
3600: current_function_return_value = NULL_TREE;
3601: return decl;
3602: }
3603: }
3604:
3605: /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3606: /* XXX Note decl is never actually used. (bpk) */
3607: void
3608: define_case_label (decl)
3609: tree decl;
3610: {
3611: tree cleanup = last_cleanup_this_contour ();
3612: if (cleanup)
3613: {
3614: static int explained = 0;
3615: cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
3616: error ("where case label appears here");
3617: if (!explained)
3618: {
3619: error ("(enclose actions of previous case statements requiring");
3620: error ("destructors in their own binding contours.)");
3621: explained = 1;
3622: }
3623: }
3624:
3625: /* After labels, make any new cleanups go into their
3626: own new (temporary) binding contour. */
3627:
3628: current_binding_level->more_cleanups_ok = 0;
3629: current_function_return_value = NULL_TREE;
3630: }
3631:
3632: /* Return the list of declarations of the current level.
3633: Note that this list is in reverse order unless/until
3634: you nreverse it; and when you do nreverse it, you must
3635: store the result back using `storedecls' or you will lose. */
3636:
3637: tree
3638: getdecls ()
3639: {
3640: return current_binding_level->names;
3641: }
3642:
3643: /* Return the list of type-tags (for structs, etc) of the current level. */
3644:
3645: tree
3646: gettags ()
3647: {
3648: return current_binding_level->tags;
3649: }
3650:
3651: /* Store the list of declarations of the current level.
3652: This is done for the parameter declarations of a function being defined,
3653: after they are modified in the light of any missing parameters. */
3654:
3655: static void
3656: storedecls (decls)
3657: tree decls;
3658: {
3659: current_binding_level->names = decls;
3660: }
3661:
3662: /* Similarly, store the list of tags of the current level. */
3663:
3664: static void
3665: storetags (tags)
3666: tree tags;
3667: {
3668: current_binding_level->tags = tags;
3669: }
3670:
3671: /* Given NAME, an IDENTIFIER_NODE,
3672: return the structure (or union or enum) definition for that name.
3673: Searches binding levels from BINDING_LEVEL up to the global level.
3674: If THISLEVEL_ONLY is nonzero, searches only the specified context
3675: (but skips any tag-transparent contexts to find one that is
3676: meaningful for tags).
3677: FORM says which kind of type the caller wants;
3678: it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3679: If the wrong kind of type is found, and it's not a template, an error is
3680: reported. */
3681:
3682: static tree
3683: lookup_tag (form, name, binding_level, thislevel_only)
3684: enum tree_code form;
3685: struct binding_level *binding_level;
3686: tree name;
3687: int thislevel_only;
3688: {
3689: register struct binding_level *level;
3690:
3691: for (level = binding_level; level; level = level->level_chain)
3692: {
3693: register tree tail;
3694: if (ANON_AGGRNAME_P (name))
3695: for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3696: {
3697: /* There's no need for error checking here, because
3698: anon names are unique throughout the compilation. */
3699: if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
3700: return TREE_VALUE (tail);
3701: }
3702: else
3703: for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3704: {
3705: if (TREE_PURPOSE (tail) == name)
3706: {
3707: enum tree_code code = TREE_CODE (TREE_VALUE (tail));
3708: /* Should tighten this up; it'll probably permit
3709: UNION_TYPE and a struct template, for example. */
3710: if (code != form
3711: && !(form != ENUMERAL_TYPE
3712: && (code == TEMPLATE_DECL
3713: || code == UNINSTANTIATED_P_TYPE)))
3714:
3715: {
3716: /* Definition isn't the kind we were looking for. */
3717: cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
3718: form);
3719: }
3720: return TREE_VALUE (tail);
3721: }
3722: }
3723: if (thislevel_only && ! level->tag_transparent)
3724: return NULL_TREE;
3725: if (current_class_type && level->level_chain == global_binding_level)
3726: {
3727: /* Try looking in this class's tags before heading into
3728: global binding level. */
3729: tree context = current_class_type;
3730: while (context)
3731: {
3732: switch (TREE_CODE_CLASS (TREE_CODE (context)))
3733: {
3734: tree these_tags;
3735: case 't':
3736: these_tags = CLASSTYPE_TAGS (context);
3737: if (ANON_AGGRNAME_P (name))
3738: while (these_tags)
3739: {
3740: if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
3741: == name)
3742: return TREE_VALUE (tail);
3743: these_tags = TREE_CHAIN (these_tags);
3744: }
3745: else
3746: while (these_tags)
3747: {
3748: if (TREE_PURPOSE (these_tags) == name)
3749: {
3750: if (TREE_CODE (TREE_VALUE (these_tags)) != form)
3751: {
3752: cp_error ("`%#D' redeclared as %C in class scope",
3753: TREE_VALUE (tail), form);
3754: }
3755: return TREE_VALUE (tail);
3756: }
3757: these_tags = TREE_CHAIN (these_tags);
3758: }
3759: /* If this type is not yet complete, then don't
3760: look at its context. */
3761: if (TYPE_SIZE (context) == NULL_TREE)
3762: goto no_context;
3763: /* Go to next enclosing type, if any. */
3764: context = DECL_CONTEXT (TYPE_NAME (context));
3765: break;
3766: case 'd':
3767: context = DECL_CONTEXT (context);
3768: break;
3769: default:
3770: my_friendly_abort (10);
3771: }
3772: continue;
3773: no_context:
3774: break;
3775: }
3776: }
3777: }
3778: return NULL_TREE;
3779: }
3780:
3781: void
3782: set_current_level_tags_transparency (tags_transparent)
3783: int tags_transparent;
3784: {
3785: current_binding_level->tag_transparent = tags_transparent;
3786: }
3787:
3788: /* Given a type, find the tag that was defined for it and return the tag name.
3789: Otherwise return 0. However, the value can never be 0
3790: in the cases in which this is used.
3791:
3792: C++: If NAME is non-zero, this is the new name to install. This is
3793: done when replacing anonymous tags with real tag names. */
3794:
3795: static tree
3796: lookup_tag_reverse (type, name)
3797: tree type;
3798: tree name;
3799: {
3800: register struct binding_level *level;
3801:
3802: for (level = current_binding_level; level; level = level->level_chain)
3803: {
3804: register tree tail;
3805: for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3806: {
3807: if (TREE_VALUE (tail) == type)
3808: {
3809: if (name)
3810: TREE_PURPOSE (tail) = name;
3811: return TREE_PURPOSE (tail);
3812: }
3813: }
3814: }
3815: return NULL_TREE;
3816: }
3817:
3818: /* Given type TYPE which was not declared in C++ language context,
3819: attempt to find a name by which it is referred. */
3820: tree
3821: typedecl_for_tag (tag)
3822: tree tag;
3823: {
3824: struct binding_level *b = current_binding_level;
3825:
3826: if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
3827: return TYPE_NAME (tag);
3828:
3829: while (b)
3830: {
3831: tree decls = b->names;
3832: while (decls)
3833: {
3834: if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
3835: break;
3836: decls = TREE_CHAIN (decls);
3837: }
3838: if (decls)
3839: return decls;
3840: b = b->level_chain;
3841: }
3842: return NULL_TREE;
3843: }
3844:
3845: /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
3846: Return the type value, or NULL_TREE if not found. */
3847: static tree
3848: lookup_nested_type (type, context)
3849: tree type;
3850: tree context;
3851: {
3852: if (context == NULL_TREE)
3853: return NULL_TREE;
3854: while (context)
3855: {
3856: switch (TREE_CODE (context))
3857: {
3858: case TYPE_DECL:
3859: {
3860: tree ctype = TREE_TYPE (context);
3861: tree match = value_member (type, CLASSTYPE_TAGS (ctype));
3862: if (match)
3863: return TREE_VALUE (match);
3864: context = DECL_CONTEXT (context);
3865:
3866: /* When we have a nested class whose member functions have
3867: local types (e.g., a set of enums), we'll arrive here
3868: with the DECL_CONTEXT as the actual RECORD_TYPE node for
3869: the enclosing class. Instead, we want to make sure we
3870: come back in here with the TYPE_DECL, not the RECORD_TYPE. */
3871: if (context && TREE_CODE (context) == RECORD_TYPE)
3872: context = TREE_CHAIN (context);
3873: }
3874: break;
3875: case FUNCTION_DECL:
3876: return TYPE_IDENTIFIER (type) ?
3877: lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE;
3878: break;
3879: default:
3880: my_friendly_abort (12);
3881: }
3882: }
3883: return NULL_TREE;
3884: }
3885:
3886: /* Look up NAME in the current binding level and its superiors in the
3887: namespace of variables, functions and typedefs. Return a ..._DECL
3888: node of some kind representing its definition if there is only one
3889: such declaration, or return a TREE_LIST with all the overloaded
3890: definitions if there are many, or return 0 if it is undefined.
3891:
3892: If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
3893: If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
3894: Otherwise we prefer non-TYPE_DECLs. */
3895:
3896: tree
3897: lookup_name_real (name, prefer_type, nonclass)
3898: tree name;
3899: int prefer_type, nonclass;
3900: {
3901: register tree val;
3902: int yylex = 0;
3903:
3904: if (prefer_type == -2)
3905: {
3906: extern int looking_for_typename;
3907:
3908: yylex = 1;
3909: prefer_type = looking_for_typename;
3910:
3911: if (got_scope != NULL_TREE)
3912: {
3913: if (got_scope == error_mark_node)
3914: return error_mark_node;
3915: else if (got_scope == void_type_node)
3916: val = IDENTIFIER_GLOBAL_VALUE (name);
3917: else if (TREE_CODE (got_scope) == TEMPLATE_TYPE_PARM
3918: /* TFIXME -- don't do this for UPTs in new model. */
3919: || TREE_CODE (got_scope) == UNINSTANTIATED_P_TYPE)
3920: {
3921: if (prefer_type > 0)
3922: val = create_nested_upt (got_scope, name);
3923: else
3924: val = NULL_TREE;
3925: }
3926: else if (! IS_AGGR_TYPE (got_scope))
3927: /* Someone else will give an error about this if needed. */
3928: val = NULL_TREE;
3929: else if (TYPE_BEING_DEFINED (got_scope))
3930: {
3931: val = IDENTIFIER_CLASS_VALUE (name);
3932: if (val && DECL_CONTEXT (val) != got_scope)
3933: {
3934: struct binding_level *b = class_binding_level;
3935: for (val = NULL_TREE; b; b = b->level_chain)
3936: {
3937: tree t = purpose_member (name, b->class_shadowed);
3938: if (t && TREE_VALUE (t)
3939: && DECL_CONTEXT (TREE_VALUE (t)) == got_scope)
3940: {
3941: val = TREE_VALUE (t);
3942: break;
3943: }
3944: }
3945: }
3946: if (val == NULL_TREE
3947: && CLASSTYPE_LOCAL_TYPEDECLS (got_scope))
3948: val = lookup_field (got_scope, name, 0, 1);
3949: }
3950: else if (got_scope == current_class_type)
3951: val = IDENTIFIER_CLASS_VALUE (name);
3952: else
3953: val = lookup_field (got_scope, name, 0, 0);
3954:
3955: goto done;
3956: }
3957: }
3958:
3959: if (current_binding_level != global_binding_level
3960: && IDENTIFIER_LOCAL_VALUE (name))
3961: val = IDENTIFIER_LOCAL_VALUE (name);
3962: /* In C++ class fields are between local and global scope,
3963: just before the global scope. */
3964: else if (current_class_type && ! nonclass)
3965: {
3966: val = IDENTIFIER_CLASS_VALUE (name);
3967: if (val == NULL_TREE
3968: && TYPE_BEING_DEFINED (current_class_type)
3969: && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
3970: /* Try to find values from base classes if we are presently
3971: defining a type. We are presently only interested in
3972: TYPE_DECLs. */
3973: val = lookup_field (current_class_type, name, 0, 1);
3974:
3975: /* yylex() calls this with -2, since we should never start digging for
3976: the nested name at the point where we haven't even, for example,
3977: created the COMPONENT_REF or anything like that. */
3978: if (val == NULL_TREE)
3979: val = lookup_nested_field (name, ! yylex);
3980:
3981: if (val == NULL_TREE)
3982: val = IDENTIFIER_GLOBAL_VALUE (name);
3983: }
3984: else
3985: val = IDENTIFIER_GLOBAL_VALUE (name);
3986:
3987: done:
3988: if (val)
3989: {
3990: if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template)
3991: || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0)
3992: return val;
3993:
3994: if (IDENTIFIER_HAS_TYPE_VALUE (name))
3995: return TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
3996:
3997: if (TREE_TYPE (val) == error_mark_node)
3998: return error_mark_node;
3999: }
4000:
4001: return val;
4002: }
4003:
4004: tree
4005: lookup_name_nonclass (name)
4006: tree name;
4007: {
4008: return lookup_name_real (name, 0, 1);
4009: }
4010:
4011: tree
4012: lookup_name (name, prefer_type)
4013: tree name;
4014: int prefer_type;
4015: {
4016: return lookup_name_real (name, prefer_type, 0);
4017: }
4018:
4019: /* Similar to `lookup_name' but look only at current binding level. */
4020:
4021: tree
4022: lookup_name_current_level (name)
4023: tree name;
4024: {
4025: register tree t = NULL_TREE;
4026:
4027: if (current_binding_level == global_binding_level)
4028: {
4029: t = IDENTIFIER_GLOBAL_VALUE (name);
4030:
4031: /* extern "C" function() */
4032: if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
4033: t = TREE_VALUE (t);
4034: }
4035: else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
4036: {
4037: struct binding_level *b = current_binding_level;
4038: while (1)
4039: {
4040: for (t = b->names; t; t = TREE_CHAIN (t))
4041: if (DECL_NAME (t) == name)
4042: goto out;
4043: if (b->keep == 2)
4044: b = b->level_chain;
4045: else
4046: break;
4047: }
4048: out:
4049: ;
4050: }
4051:
4052: return t;
4053: }
4054:
4055: /* Arrange for the user to get a source line number, even when the
4056: compiler is going down in flames, so that she at least has a
4057: chance of working around problems in the compiler. We used to
4058: call error(), but that let the segmentation fault continue
4059: through; now, it's much more passive by asking them to send the
4060: maintainers mail about the problem. */
4061:
4062: static void
4063: signal_catch (sig)
4064: int sig;
4065: {
4066: signal (SIGSEGV, SIG_DFL);
4067: #ifdef SIGIOT
4068: signal (SIGIOT, SIG_DFL);
4069: #endif
4070: #ifdef SIGILL
4071: signal (SIGILL, SIG_DFL);
4072: #endif
4073: #ifdef SIGABRT
4074: signal (SIGABRT, SIG_DFL);
4075: #endif
4076: #ifdef SIGBUS
4077: signal (SIGBUS, SIG_DFL);
4078: #endif
4079: my_friendly_abort (0);
4080: }
4081:
4082: /* Array for holding types considered "built-in". These types
4083: are output in the module in which `main' is defined. */
4084: static tree *builtin_type_tdescs_arr;
4085: static int builtin_type_tdescs_len, builtin_type_tdescs_max;
4086:
4087: /* Push the declarations of builtin types into the namespace.
4088: RID_INDEX, if < RID_MAX is the index of the builtin type
4089: in the array RID_POINTERS. NAME is the name used when looking
4090: up the builtin type. TYPE is the _TYPE node for the builtin type. */
4091:
4092: static void
4093: record_builtin_type (rid_index, name, type)
4094: enum rid rid_index;
4095: char *name;
4096: tree type;
4097: {
4098: tree rname = NULL_TREE, tname = NULL_TREE;
4099: tree tdecl;
4100:
4101: if ((int) rid_index < (int) RID_MAX)
4102: rname = ridpointers[(int) rid_index];
4103: if (name)
4104: tname = get_identifier (name);
4105:
4106: TYPE_BUILT_IN (type) = 1;
4107:
4108: if (tname)
4109: {
4110: #if 0 /* not yet, should get fixed properly later */
4111: tdecl = pushdecl (make_type_decl (tname, type));
4112: #else
4113: tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
4114: #endif
4115: set_identifier_type_value (tname, NULL_TREE);
4116: if ((int) rid_index < (int) RID_MAX)
4117: IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
4118: }
4119: if (rname != NULL_TREE)
4120: {
4121: if (tname != NULL_TREE)
4122: {
4123: set_identifier_type_value (rname, NULL_TREE);
4124: IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
4125: }
4126: else
4127: {
4128: #if 0 /* not yet, should get fixed properly later */
4129: tdecl = pushdecl (make_type_decl (rname, type));
4130: #else
4131: tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
4132: #endif
4133: set_identifier_type_value (rname, NULL_TREE);
4134: }
4135: }
4136:
4137: if (flag_dossier)
4138: {
4139: if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
4140: {
4141: builtin_type_tdescs_max *= 2;
4142: builtin_type_tdescs_arr
4143: = (tree *)xrealloc (builtin_type_tdescs_arr,
4144: builtin_type_tdescs_max * sizeof (tree));
4145: }
4146: builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
4147: if (TREE_CODE (type) != POINTER_TYPE)
4148: {
4149: builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4150: = build_pointer_type (type);
4151: builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4152: = build_pointer_type (build_type_variant (type, 1, 0));
4153: }
4154: if (TREE_CODE (type) != VOID_TYPE)
4155: {
4156: builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4157: = build_reference_type (type);
4158: builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4159: = build_reference_type (build_type_variant (type, 1, 0));
4160: }
4161: }
4162: }
4163:
4164: static void
4165: output_builtin_tdesc_entries ()
4166: {
4167: extern struct obstack permanent_obstack;
4168:
4169: /* If there's more than one main in this file, don't crash. */
4170: if (builtin_type_tdescs_arr == 0)
4171: return;
4172:
4173: push_obstacks (&permanent_obstack, &permanent_obstack);
4174: while (builtin_type_tdescs_len > 0)
4175: {
4176: tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
4177: tree tdesc = build_t_desc (type, 0);
4178: TREE_ASM_WRITTEN (tdesc) = 0;
4179: build_t_desc (type, 2);
4180: }
4181: free (builtin_type_tdescs_arr);
4182: builtin_type_tdescs_arr = 0;
4183: pop_obstacks ();
4184: }
4185:
4186: /* Push overloaded decl, in global scope, with one argument so it
4187: can be used as a callback from define_function. */
4188: static void
4189: push_overloaded_decl_1 (x)
4190: tree x;
4191: {
4192: push_overloaded_decl (x, 0);
4193: }
4194:
4195: /* Create the predefined scalar types of C,
4196: and some nodes representing standard constants (0, 1, (void *)0).
4197: Initialize the global binding level.
4198: Make definitions for built-in primitive functions. */
4199:
4200: void
4201: init_decl_processing ()
4202: {
4203: tree decl;
4204: register tree endlink, int_endlink, double_endlink, ptr_endlink;
4205: tree fields[20];
4206: /* Either char* or void*. */
4207: tree traditional_ptr_type_node;
4208: /* Data type of memcpy. */
4209: tree memcpy_ftype;
4210: #if 0 /* Not yet. */
4211: /* Data type of strncpy. */
4212: tree strncpy_ftype;
4213: #endif
4214: int wchar_type_size;
4215: tree temp;
4216: tree array_domain_type;
4217:
4218: /* Have to make these distinct before we try using them. */
4219: lang_name_cplusplus = get_identifier ("C++");
4220: lang_name_c = get_identifier ("C");
4221:
4222: if (flag_ansi || pedantic)
4223: strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
4224:
4225: /* Initially, C. */
4226: current_lang_name = lang_name_c;
4227:
4228: current_function_decl = NULL_TREE;
4229: named_labels = NULL_TREE;
4230: named_label_uses = NULL_TREE;
4231: current_binding_level = NULL_BINDING_LEVEL;
4232: free_binding_level = NULL_BINDING_LEVEL;
4233:
4234: /* Because most segmentation signals can be traced back into user
4235: code, catch them and at least give the user a chance of working
4236: around compiler bugs. */
4237: signal (SIGSEGV, signal_catch);
4238:
4239: /* We will also catch aborts in the back-end through signal_catch and
4240: give the user a chance to see where the error might be, and to defeat
4241: aborts in the back-end when there have been errors previously in their
4242: code. */
4243: #ifdef SIGIOT
4244: signal (SIGIOT, signal_catch);
4245: #endif
4246: #ifdef SIGILL
4247: signal (SIGILL, signal_catch);
4248: #endif
4249: #ifdef SIGABRT
4250: signal (SIGABRT, signal_catch);
4251: #endif
4252: #ifdef SIGBUS
4253: signal (SIGBUS, signal_catch);
4254: #endif
4255:
4256: gcc_obstack_init (&decl_obstack);
4257: if (flag_dossier)
4258: {
4259: builtin_type_tdescs_max = 100;
4260: builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
4261: }
4262:
4263: /* Must lay these out before anything else gets laid out. */
4264: error_mark_node = make_node (ERROR_MARK);
4265: TREE_PERMANENT (error_mark_node) = 1;
4266: TREE_TYPE (error_mark_node) = error_mark_node;
4267: error_mark_list = build_tree_list (error_mark_node, error_mark_node);
4268: TREE_TYPE (error_mark_list) = error_mark_node;
4269:
4270: /* Make the binding_level structure for global names. */
4271: pushlevel (0);
4272: global_binding_level = current_binding_level;
4273:
4274: this_identifier = get_identifier (THIS_NAME);
4275: in_charge_identifier = get_identifier (IN_CHARGE_NAME);
4276: pfn_identifier = get_identifier (VTABLE_PFN_NAME);
4277: index_identifier = get_identifier (VTABLE_INDEX_NAME);
4278: delta_identifier = get_identifier (VTABLE_DELTA_NAME);
4279: delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
4280: pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
4281:
4282: /* Define `int' and `char' first so that dbx will output them first. */
4283:
4284: integer_type_node = make_signed_type (INT_TYPE_SIZE);
4285: record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
4286:
4287: /* Define `char', which is like either `signed char' or `unsigned char'
4288: but not the same as either. */
4289:
4290: char_type_node =
4291: (flag_signed_char
4292: ? make_signed_type (CHAR_TYPE_SIZE)
4293: : make_unsigned_type (CHAR_TYPE_SIZE));
4294: record_builtin_type (RID_CHAR, "char", char_type_node);
4295:
4296: long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4297: record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4298:
4299: unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4300: record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4301:
4302: long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4303: record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
4304: record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4305:
4306: long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4307: record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
4308:
4309: long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4310: record_builtin_type (RID_MAX, "long long unsigned int",
4311: long_long_unsigned_type_node);
4312: record_builtin_type (RID_MAX, "long long unsigned",
4313: long_long_unsigned_type_node);
4314:
4315: /* `unsigned long' is the standard type for sizeof.
4316: Traditionally, use a signed type.
4317: Note that stddef.h uses `unsigned long',
4318: and this must agree, even of long and int are the same size. */
4319: sizetype
4320: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
4321: if (flag_traditional && TREE_UNSIGNED (sizetype))
4322: sizetype = signed_type (sizetype);
4323:
4324: ptrdiff_type_node
4325: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
4326:
4327: TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
4328: TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
4329: TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
4330: TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
4331: TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
4332: TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
4333: TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
4334:
4335: short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4336: record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4337: short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4338: record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
4339: record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
4340:
4341: /* Define both `signed char' and `unsigned char'. */
4342: signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4343: record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4344: unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4345: record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4346:
4347: /* These are types that type_for_size and type_for_mode use. */
4348: intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4349: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
4350: intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4351: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
4352: intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4353: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
4354: intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4355: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
4356: unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4357: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
4358: unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4359: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
4360: unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4361: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
4362: unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4363: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
4364:
4365: float_type_node = make_node (REAL_TYPE);
4366: TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4367: record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
4368: layout_type (float_type_node);
4369:
4370: double_type_node = make_node (REAL_TYPE);
4371: if (flag_short_double)
4372: TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4373: else
4374: TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4375: record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
4376: layout_type (double_type_node);
4377:
4378: long_double_type_node = make_node (REAL_TYPE);
4379: TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4380: record_builtin_type (RID_MAX, "long double", long_double_type_node);
4381: layout_type (long_double_type_node);
4382:
4383: integer_zero_node = build_int_2 (0, 0);
4384: TREE_TYPE (integer_zero_node) = integer_type_node;
4385: integer_one_node = build_int_2 (1, 0);
4386: TREE_TYPE (integer_one_node) = integer_type_node;
4387: integer_two_node = build_int_2 (2, 0);
4388: TREE_TYPE (integer_two_node) = integer_type_node;
4389: integer_three_node = build_int_2 (3, 0);
4390: TREE_TYPE (integer_three_node) = integer_type_node;
4391:
4392: bool_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4393: TREE_SET_CODE (bool_type_node, BOOLEAN_TYPE);
4394: record_builtin_type (RID_BOOL, "bool", bool_type_node);
4395: false_node = build_int_2 (0, 0);
4396: TREE_TYPE (false_node) = bool_type_node;
4397: true_node = build_int_2 (1, 0);
4398: TREE_TYPE (true_node) = bool_type_node;
4399:
4400: /* These are needed by stor-layout.c. */
4401: size_zero_node = size_int (0);
4402: size_one_node = size_int (1);
4403:
4404: void_type_node = make_node (VOID_TYPE);
4405: record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
4406: layout_type (void_type_node); /* Uses integer_zero_node. */
4407: void_list_node = build_tree_list (NULL_TREE, void_type_node);
4408: TREE_PARMLIST (void_list_node) = 1;
4409:
4410: null_pointer_node = build_int_2 (0, 0);
4411: TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4412: layout_type (TREE_TYPE (null_pointer_node));
4413:
4414: /* Used for expressions that do nothing, but are not errors. */
4415: void_zero_node = build_int_2 (0, 0);
4416: TREE_TYPE (void_zero_node) = void_type_node;
4417:
4418: string_type_node = build_pointer_type (char_type_node);
4419: const_string_type_node =
4420: build_pointer_type (build_type_variant (char_type_node, 1, 0));
4421: record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
4422:
4423: /* Make a type to be the domain of a few array types
4424: whose domains don't really matter.
4425: 200 is small enough that it always fits in size_t
4426: and large enough that it can hold most function names for the
4427: initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4428: array_domain_type = build_index_type (build_int_2 (200, 0));
4429:
4430: /* make a type for arrays of characters.
4431: With luck nothing will ever really depend on the length of this
4432: array type. */
4433: char_array_type_node
4434: = build_array_type (char_type_node, array_domain_type);
4435: /* Likewise for arrays of ints. */
4436: int_array_type_node
4437: = build_array_type (integer_type_node, array_domain_type);
4438:
4439: /* This is just some anonymous class type. Nobody should ever
4440: need to look inside this envelope. */
4441: class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
4442:
4443: default_function_type
4444: = build_function_type (integer_type_node, NULL_TREE);
4445: build_pointer_type (default_function_type);
4446:
4447: ptr_type_node = build_pointer_type (void_type_node);
4448: const_ptr_type_node =
4449: build_pointer_type (build_type_variant (void_type_node, 1, 0));
4450: record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
4451: endlink = void_list_node;
4452: int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
4453: double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
4454: ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
4455:
4456: double_ftype_double
4457: = build_function_type (double_type_node, double_endlink);
4458:
4459: double_ftype_double_double
4460: = build_function_type (double_type_node,
4461: tree_cons (NULL_TREE, double_type_node,
4462: double_endlink));
4463:
4464: int_ftype_int
4465: = build_function_type (integer_type_node, int_endlink);
4466:
4467: long_ftype_long
4468: = build_function_type (long_integer_type_node,
4469: tree_cons (NULL_TREE, long_integer_type_node,
4470: endlink));
4471:
4472: void_ftype_ptr_ptr_int
4473: = build_function_type (void_type_node,
4474: tree_cons (NULL_TREE, ptr_type_node,
4475: tree_cons (NULL_TREE, ptr_type_node,
4476: int_endlink)));
4477:
4478: int_ftype_cptr_cptr_sizet
4479: = build_function_type (integer_type_node,
4480: tree_cons (NULL_TREE, const_ptr_type_node,
4481: tree_cons (NULL_TREE, const_ptr_type_node,
4482: tree_cons (NULL_TREE,
4483: sizetype,
4484: endlink))));
4485:
4486: void_ftype_ptr_int_int
4487: = build_function_type (void_type_node,
4488: tree_cons (NULL_TREE, ptr_type_node,
4489: tree_cons (NULL_TREE, integer_type_node,
4490: int_endlink)));
4491:
4492: string_ftype_ptr_ptr /* strcpy prototype */
4493: = build_function_type (string_type_node,
4494: tree_cons (NULL_TREE, string_type_node,
4495: tree_cons (NULL_TREE,
4496: const_string_type_node,
4497: endlink)));
4498:
4499: #if 0
4500: /* Not yet. */
4501: strncpy_ftype /* strncpy prototype */
4502: = build_function_type (string_type_node,
4503: tree_cons (NULL_TREE, string_type_node,
4504: tree_cons (NULL_TREE, const_string_type_node,
4505: tree_cons (NULL_TREE,
4506: sizetype,
4507: endlink))));
4508: #endif
4509:
4510: int_ftype_string_string /* strcmp prototype */
4511: = build_function_type (integer_type_node,
4512: tree_cons (NULL_TREE, const_string_type_node,
4513: tree_cons (NULL_TREE,
4514: const_string_type_node,
4515: endlink)));
4516:
4517: sizet_ftype_string /* strlen prototype */
4518: = build_function_type (sizetype,
4519: tree_cons (NULL_TREE, const_string_type_node,
4520: endlink));
4521:
4522: traditional_ptr_type_node
4523: = (flag_traditional ? string_type_node : ptr_type_node);
4524:
4525: memcpy_ftype /* memcpy prototype */
4526: = build_function_type (traditional_ptr_type_node,
4527: tree_cons (NULL_TREE, ptr_type_node,
4528: tree_cons (NULL_TREE, const_ptr_type_node,
4529: tree_cons (NULL_TREE,
4530: sizetype,
4531: endlink))));
4532:
4533: if (flag_huge_objects)
4534: delta_type_node = long_integer_type_node;
4535: else
4536: delta_type_node = short_integer_type_node;
4537:
4538: builtin_function ("__builtin_constant_p", int_ftype_int,
4539: BUILT_IN_CONSTANT_P, NULL_PTR);
4540:
4541: builtin_return_address_fndecl =
4542: builtin_function ("__builtin_return_address",
4543: build_function_type (ptr_type_node,
4544: tree_cons (NULL_TREE,
4545: unsigned_type_node,
4546: endlink)),
4547: BUILT_IN_RETURN_ADDRESS, NULL_PTR);
4548:
4549: builtin_function ("__builtin_frame_address",
4550: build_function_type (ptr_type_node,
4551: tree_cons (NULL_TREE,
4552: unsigned_type_node,
4553: endlink)),
4554: BUILT_IN_FRAME_ADDRESS, NULL_PTR);
4555:
4556:
4557: builtin_function ("__builtin_alloca",
4558: build_function_type (ptr_type_node,
4559: tree_cons (NULL_TREE,
4560: sizetype,
4561: endlink)),
4562: BUILT_IN_ALLOCA, "alloca");
4563: /* Define alloca, ffs as builtins.
4564: Declare _exit just to mark it as volatile. */
4565: if (! flag_no_builtin && !flag_no_nonansi_builtin)
4566: {
4567: temp = builtin_function ("alloca",
4568: build_function_type (ptr_type_node,
4569: tree_cons (NULL_TREE,
4570: sizetype,
4571: endlink)),
4572: BUILT_IN_ALLOCA, NULL_PTR);
4573: /* Suppress error if redefined as a non-function. */
4574: DECL_BUILT_IN_NONANSI (temp) = 1;
4575: temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
4576: /* Suppress error if redefined as a non-function. */
4577: DECL_BUILT_IN_NONANSI (temp) = 1;
4578: temp = builtin_function ("_exit", build_function_type (void_type_node,
4579: int_endlink),
4580: NOT_BUILT_IN, NULL_PTR);
4581: TREE_THIS_VOLATILE (temp) = 1;
4582: TREE_SIDE_EFFECTS (temp) = 1;
4583: /* Suppress error if redefined as a non-function. */
4584: DECL_BUILT_IN_NONANSI (temp) = 1;
4585: }
4586:
4587: builtin_function ("__builtin_abs", int_ftype_int,
4588: BUILT_IN_ABS, NULL_PTR);
4589: builtin_function ("__builtin_fabs", double_ftype_double,
4590: BUILT_IN_FABS, NULL_PTR);
4591: builtin_function ("__builtin_labs", long_ftype_long,
4592: BUILT_IN_LABS, NULL_PTR);
4593: builtin_function ("__builtin_ffs", int_ftype_int,
4594: BUILT_IN_FFS, NULL_PTR);
4595: builtin_function ("__builtin_fsqrt", double_ftype_double,
4596: BUILT_IN_FSQRT, NULL_PTR);
4597: builtin_function ("__builtin_sin", double_ftype_double,
4598: BUILT_IN_SIN, "sin");
4599: builtin_function ("__builtin_cos", double_ftype_double,
4600: BUILT_IN_COS, "cos");
4601: builtin_function ("__builtin_saveregs",
4602: build_function_type (ptr_type_node, NULL_TREE),
4603: BUILT_IN_SAVEREGS, NULL_PTR);
4604: /* EXPAND_BUILTIN_VARARGS is obsolete. */
4605: #if 0
4606: builtin_function ("__builtin_varargs",
4607: build_function_type (ptr_type_node,
4608: tree_cons (NULL_TREE,
4609: integer_type_node,
4610: endlink)),
4611: BUILT_IN_VARARGS, NULL_PTR);
4612: #endif
4613: builtin_function ("__builtin_classify_type", default_function_type,
4614: BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
4615: builtin_function ("__builtin_next_arg",
4616: build_function_type (ptr_type_node, NULL_TREE),
4617: BUILT_IN_NEXT_ARG, NULL_PTR);
4618: builtin_function ("__builtin_args_info",
4619: build_function_type (integer_type_node,
4620: tree_cons (NULL_TREE,
4621: integer_type_node,
4622: endlink)),
4623: BUILT_IN_ARGS_INFO, NULL_PTR);
4624:
4625: /* Untyped call and return. */
4626: builtin_function ("__builtin_apply_args",
4627: build_function_type (ptr_type_node, NULL_TREE),
4628: BUILT_IN_APPLY_ARGS, NULL_PTR);
4629:
4630: temp = tree_cons (NULL_TREE,
4631: build_pointer_type (build_function_type (void_type_node,
4632: NULL_TREE)),
4633: tree_cons (NULL_TREE,
4634: ptr_type_node,
4635: tree_cons (NULL_TREE,
4636: sizetype,
4637: endlink)));
4638: builtin_function ("__builtin_apply",
4639: build_function_type (ptr_type_node, temp),
4640: BUILT_IN_APPLY, NULL_PTR);
4641: builtin_function ("__builtin_return",
4642: build_function_type (void_type_node,
4643: tree_cons (NULL_TREE,
4644: ptr_type_node,
4645: endlink)),
4646: BUILT_IN_RETURN, NULL_PTR);
4647:
4648: /* Currently under experimentation. */
4649: builtin_function ("__builtin_memcpy", memcpy_ftype,
4650: BUILT_IN_MEMCPY, "memcpy");
4651: builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
4652: BUILT_IN_MEMCMP, "memcmp");
4653: builtin_function ("__builtin_strcmp", int_ftype_string_string,
4654: BUILT_IN_STRCMP, "strcmp");
4655: builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
4656: BUILT_IN_STRCPY, "strcpy");
4657: #if 0
4658: /* Not yet. */
4659: builtin_function ("__builtin_strncpy", strncpy_ftype,
4660: BUILT_IN_STRNCPY, "strncpy");
4661: #endif
4662: builtin_function ("__builtin_strlen", sizet_ftype_string,
4663: BUILT_IN_STRLEN, "strlen");
4664:
4665: if (!flag_no_builtin)
4666: {
4667: #if 0 /* These do not work well with libg++. */
4668: builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
4669: builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
4670: builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
4671: #endif
4672: builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
4673: builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
4674: NULL_PTR);
4675: builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
4676: builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
4677: NULL_PTR);
4678: #if 0
4679: /* Not yet. */
4680: builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
4681: #endif
4682: builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
4683: builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
4684: builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
4685:
4686: /* Declare these functions volatile
4687: to avoid spurious "control drops through" warnings. */
4688: temp = builtin_function ("abort",
4689: build_function_type (void_type_node, endlink),
4690: NOT_BUILT_IN, NULL_PTR);
4691: TREE_THIS_VOLATILE (temp) = 1;
4692: TREE_SIDE_EFFECTS (temp) = 1;
4693: /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
4694: them... */
4695: DECL_BUILT_IN_NONANSI (temp) = 1;
4696: temp = builtin_function ("exit", build_function_type (void_type_node,
4697: int_endlink),
4698: NOT_BUILT_IN, NULL_PTR);
4699: TREE_THIS_VOLATILE (temp) = 1;
4700: TREE_SIDE_EFFECTS (temp) = 1;
4701: DECL_BUILT_IN_NONANSI (temp) = 1;
4702: }
4703:
4704: #if 0
4705: /* Support for these has not been written in either expand_builtin
4706: or build_function_call. */
4707: builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
4708: builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
4709: builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
4710: 0);
4711: builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
4712: builtin_function ("__builtin_fmod", double_ftype_double_double,
4713: BUILT_IN_FMOD, 0);
4714: builtin_function ("__builtin_frem", double_ftype_double_double,
4715: BUILT_IN_FREM, 0);
4716: builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET,
4717: 0);
4718: builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
4719: 0);
4720: builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
4721: 0);
4722: #endif
4723:
4724: /* C++ extensions */
4725:
4726: unknown_type_node = make_node (UNKNOWN_TYPE);
4727: #if 0 /* not yet, should get fixed properly later */
4728: pushdecl (make_type_decl (get_identifier ("unknown type"),
4729: unknown_type_node));
4730: #else
4731: decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
4732: unknown_type_node));
4733: /* Make sure the "unknown type" typedecl gets ignored for debug info. */
4734: DECL_IGNORED_P (decl) = 1;
4735: TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
4736: #endif
4737: TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
4738: TYPE_ALIGN (unknown_type_node) = 1;
4739: TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
4740: /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
4741: TREE_TYPE (unknown_type_node) = unknown_type_node;
4742: /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
4743: TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
4744: TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
4745:
4746: /* This is for handling opaque types in signatures. */
4747: opaque_type_node = copy_node (ptr_type_node);
4748: TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
4749: record_builtin_type (RID_MAX, 0, opaque_type_node);
4750:
4751: /* This is special for C++ so functions can be overloaded. */
4752: wchar_type_node
4753: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
4754: wchar_type_size = TYPE_PRECISION (wchar_type_node);
4755: signed_wchar_type_node = make_signed_type (wchar_type_size);
4756: unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
4757: wchar_type_node
4758: = TREE_UNSIGNED (wchar_type_node)
4759: ? unsigned_wchar_type_node
4760: : signed_wchar_type_node;
4761: record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
4762:
4763: /* Artificial declaration of wchar_t -- can be bashed */
4764: wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"),
4765: wchar_type_node);
4766: pushdecl (wchar_decl_node);
4767:
4768: /* This is for wide string constants. */
4769: wchar_array_type_node
4770: = build_array_type (wchar_type_node, array_domain_type);
4771:
4772: /* This is a hack that should go away when we deliver the
4773: real gc code. */
4774: if (flag_gc)
4775: {
4776: builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
4777: pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
4778: }
4779:
4780: if (flag_vtable_thunks)
4781: {
4782: /* Make sure we get a unique function type, so we can give
4783: its pointer type a name. (This wins for gdb.) */
4784: tree vfunc_type = make_node (FUNCTION_TYPE);
4785: TREE_TYPE (vfunc_type) = integer_type_node;
4786: TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
4787: layout_type (vfunc_type);
4788:
4789: vtable_entry_type = build_pointer_type (vfunc_type);
4790: }
4791: else
4792: {
4793: vtable_entry_type = make_lang_type (RECORD_TYPE);
4794: fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
4795: delta_type_node);
4796: fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
4797: delta_type_node);
4798: fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
4799: ptr_type_node);
4800: finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
4801: double_type_node);
4802:
4803: /* Make this part of an invisible union. */
4804: fields[3] = copy_node (fields[2]);
4805: TREE_TYPE (fields[3]) = delta_type_node;
4806: DECL_NAME (fields[3]) = delta2_identifier;
4807: DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
4808: DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
4809: TREE_UNSIGNED (fields[3]) = 0;
4810: TREE_CHAIN (fields[2]) = fields[3];
4811: vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
4812: }
4813: record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
4814:
4815: vtbl_type_node
4816: = build_array_type (vtable_entry_type, NULL_TREE);
4817: layout_type (vtbl_type_node);
4818: vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0);
4819: record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
4820:
4821: /* Simplify life by making a "sigtable_entry_type". Give its
4822: fields names so that the debugger can use them. */
4823:
4824: if (flag_handle_signatures)
4825: {
4826: sigtable_entry_type = make_lang_type (RECORD_TYPE);
4827: fields[0] = build_lang_field_decl (FIELD_DECL,
4828: get_identifier (SIGTABLE_CODE_NAME),
4829: short_integer_type_node);
4830: fields[1] = build_lang_field_decl (FIELD_DECL,
4831: get_identifier (SIGTABLE_OFFSET_NAME),
4832: short_integer_type_node);
4833: fields[2] = build_lang_field_decl (FIELD_DECL,
4834: get_identifier (SIGTABLE_PFN_NAME),
4835: ptr_type_node);
4836: finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 2,
4837: double_type_node);
4838: sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
4839: record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
4840: }
4841:
4842: if (flag_dossier)
4843: {
4844: /* Must build __t_desc type. Currently, type descriptors look like this:
4845:
4846: struct __t_desc
4847: {
4848: const char *name;
4849: int size;
4850: int bits;
4851: struct __t_desc *points_to;
4852: int ivars_count, meths_count;
4853: struct __i_desc *ivars[];
4854: struct __m_desc *meths[];
4855: struct __t_desc *parents[];
4856: struct __t_desc *vbases[];
4857: int offsets[];
4858: };
4859:
4860: ...as per Linton's paper. */
4861:
4862: __t_desc_type_node = make_lang_type (RECORD_TYPE);
4863: __i_desc_type_node = make_lang_type (RECORD_TYPE);
4864: __m_desc_type_node = make_lang_type (RECORD_TYPE);
4865: __t_desc_array_type =
4866: build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
4867: __i_desc_array_type =
4868: build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
4869: __m_desc_array_type =
4870: build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
4871:
4872: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4873: string_type_node);
4874: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
4875: unsigned_type_node);
4876: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
4877: unsigned_type_node);
4878: fields[3] = build_lang_field_decl (FIELD_DECL,
4879: get_identifier ("points_to"),
4880: TYPE_POINTER_TO (__t_desc_type_node));
4881: fields[4] = build_lang_field_decl (FIELD_DECL,
4882: get_identifier ("ivars_count"),
4883: integer_type_node);
4884: fields[5] = build_lang_field_decl (FIELD_DECL,
4885: get_identifier ("meths_count"),
4886: integer_type_node);
4887: fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
4888: build_pointer_type (__i_desc_array_type));
4889: fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
4890: build_pointer_type (__m_desc_array_type));
4891: fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
4892: build_pointer_type (__t_desc_array_type));
4893: fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
4894: build_pointer_type (__t_desc_array_type));
4895: fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
4896: build_pointer_type (integer_type_node));
4897: finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
4898:
4899: /* ivar descriptors look like this:
4900:
4901: struct __i_desc
4902: {
4903: const char *name;
4904: int offset;
4905: struct __t_desc *type;
4906: };
4907: */
4908:
4909: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4910: string_type_node);
4911: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
4912: integer_type_node);
4913: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
4914: TYPE_POINTER_TO (__t_desc_type_node));
4915: finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2,
4916: integer_type_node);
4917:
4918: /* method descriptors look like this:
4919:
4920: struct __m_desc
4921: {
4922: const char *name;
4923: int vindex;
4924: struct __t_desc *vcontext;
4925: struct __t_desc *return_type;
4926: void (*address)();
4927: short parm_count;
4928: short required_parms;
4929: struct __t_desc *parm_types[];
4930: };
4931: */
4932:
4933: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4934: string_type_node);
4935: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
4936: integer_type_node);
4937: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
4938: TYPE_POINTER_TO (__t_desc_type_node));
4939: fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
4940: TYPE_POINTER_TO (__t_desc_type_node));
4941: fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
4942: build_pointer_type (default_function_type));
4943: fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
4944: short_integer_type_node);
4945: fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
4946: short_integer_type_node);
4947: fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
4948: build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
4949: finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7,
4950: integer_type_node);
4951: }
4952:
4953: /* Now, C++. */
4954: current_lang_name = lang_name_cplusplus;
4955: if (flag_dossier)
4956: {
4957: int i = builtin_type_tdescs_len;
4958: while (i > 0)
4959: {
4960: tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
4961: TREE_ASM_WRITTEN (tdesc) = 1;
4962: TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
4963: }
4964: }
4965:
4966: auto_function (ansi_opname[(int) NEW_EXPR],
4967: build_function_type (ptr_type_node,
4968: tree_cons (NULL_TREE, sizetype,
4969: void_list_node)),
4970: NOT_BUILT_IN);
4971: auto_function (ansi_opname[(int) VEC_NEW_EXPR],
4972: build_function_type (ptr_type_node,
4973: tree_cons (NULL_TREE, sizetype,
4974: void_list_node)),
4975: NOT_BUILT_IN);
4976: auto_function (ansi_opname[(int) DELETE_EXPR],
4977: build_function_type (void_type_node,
4978: tree_cons (NULL_TREE, ptr_type_node,
4979: void_list_node)),
4980: NOT_BUILT_IN);
4981: auto_function (ansi_opname[(int) VEC_DELETE_EXPR],
4982: build_function_type (void_type_node,
4983: tree_cons (NULL_TREE, ptr_type_node,
4984: void_list_node)),
4985: NOT_BUILT_IN);
4986:
4987: abort_fndecl
4988: = define_function ("__pure_virtual",
4989: build_function_type (void_type_node, void_list_node),
4990: NOT_BUILT_IN, 0, 0);
4991:
4992: /* Perform other language dependent initializations. */
4993: init_class_processing ();
4994: init_init_processing ();
4995: init_search_processing ();
4996:
4997: if (flag_handle_exceptions)
4998: init_exception_processing ();
4999: if (flag_gc)
5000: init_gc_processing ();
5001: if (flag_no_inline)
5002: {
5003: flag_inline_functions = 0;
5004: #if 0
5005: /* This causes uneccessary emission of inline functions. */
5006: flag_default_inline = 0;
5007: #endif
5008: }
5009: if (flag_cadillac)
5010: init_cadillac ();
5011:
5012: /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
5013: declare_function_name ();
5014:
5015: /* Prepare to check format strings against argument lists. */
5016: init_function_format_info ();
5017: }
5018:
5019: /* Make a definition for a builtin function named NAME and whose data type
5020: is TYPE. TYPE should be a function type with argument types.
5021: FUNCTION_CODE tells later passes how to compile calls to this function.
5022: See tree.h for its possible values.
5023:
5024: If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
5025: the name to be called if we can't opencode the function. */
5026:
5027: tree
5028: define_function (name, type, function_code, pfn, library_name)
5029: char *name;
5030: tree type;
5031: enum built_in_function function_code;
5032: void (*pfn)();
5033: char *library_name;
5034: {
5035: tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
5036: DECL_EXTERNAL (decl) = 1;
5037: TREE_PUBLIC (decl) = 1;
5038:
5039: /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
5040: we cannot change DECL_ASSEMBLER_NAME until we have installed this
5041: function in the namespace. */
5042: if (pfn) (*pfn) (decl);
5043: if (library_name)
5044: DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
5045: make_function_rtl (decl);
5046: if (function_code != NOT_BUILT_IN)
5047: {
5048: DECL_BUILT_IN (decl) = 1;
5049: DECL_FUNCTION_CODE (decl) = function_code;
5050: }
5051: return decl;
5052: }
5053:
5054: /* Called when a declaration is seen that contains no names to declare.
5055: If its type is a reference to a structure, union or enum inherited
5056: from a containing scope, shadow that tag name for the current scope
5057: with a forward reference.
5058: If its type defines a new named structure or union
5059: or defines an enum, it is valid but we need not do anything here.
5060: Otherwise, it is an error.
5061:
5062: C++: may have to grok the declspecs to learn about static,
5063: complain for anonymous unions. */
5064:
5065: void
5066: shadow_tag (declspecs)
5067: tree declspecs;
5068: {
5069: int found_tag = 0;
5070: tree ob_modifier = NULL_TREE;
5071: register tree link;
5072: register enum tree_code code, ok_code = ERROR_MARK;
5073: register tree t = NULL_TREE;
5074:
5075: for (link = declspecs; link; link = TREE_CHAIN (link))
5076: {
5077: register tree value = TREE_VALUE (link);
5078:
5079: code = TREE_CODE (value);
5080: if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
5081: {
5082: my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261);
5083:
5084: if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0)
5085: cp_error ("forward declaration of `%#T'", value);
5086:
5087: t = value;
5088: ok_code = code;
5089: found_tag++;
5090: }
5091: else if (value == ridpointers[(int) RID_STATIC]
5092: || value == ridpointers[(int) RID_EXTERN]
5093: || value == ridpointers[(int) RID_AUTO]
5094: || value == ridpointers[(int) RID_REGISTER])
5095: ob_modifier = value;
5096: }
5097:
5098: /* This is where the variables in an anonymous union are
5099: declared. An anonymous union declaration looks like:
5100: union { ... } ;
5101: because there is no declarator after the union, the parser
5102: sends that declaration here. */
5103: if (ok_code == UNION_TYPE
5104: && t != NULL_TREE
5105: && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
5106: && ANON_AGGRNAME_P (TYPE_NAME (t)))
5107: || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
5108: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
5109: {
5110: /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
5111: function members. */
5112: if (TYPE_FIELDS (t))
5113: {
5114: tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
5115: NULL_TREE);
5116: finish_anon_union (decl);
5117: }
5118: else
5119: error ("anonymous union cannot have a function member");
5120: }
5121: else
5122: {
5123: /* Anonymous unions are objects, that's why we only check for
5124: inappropriate specifiers in this branch. */
5125: if (ob_modifier)
5126: cp_error ("`%D' can only be specified for objects and functions",
5127: ob_modifier);
5128:
5129: if (found_tag == 0)
5130: pedwarn ("abstract declarator used as declaration");
5131: else if (found_tag > 1)
5132: pedwarn ("multiple types in one declaration");
5133: }
5134: }
5135:
5136: /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
5137:
5138: tree
5139: groktypename (typename)
5140: tree typename;
5141: {
5142: if (TREE_CODE (typename) != TREE_LIST)
5143: return typename;
5144: return grokdeclarator (TREE_VALUE (typename),
5145: TREE_PURPOSE (typename),
5146: TYPENAME, 0, NULL_TREE);
5147: }
5148:
5149: /* Decode a declarator in an ordinary declaration or data definition.
5150: This is called as soon as the type information and variable name
5151: have been parsed, before parsing the initializer if any.
5152: Here we create the ..._DECL node, fill in its type,
5153: and put it on the list of decls for the current context.
5154: The ..._DECL node is returned as the value.
5155:
5156: Exception: for arrays where the length is not specified,
5157: the type is left null, to be filled in by `finish_decl'.
5158:
5159: Function definitions do not come here; they go to start_function
5160: instead. However, external and forward declarations of functions
5161: do go through here. Structure field declarations are done by
5162: grokfield and not through here. */
5163:
5164: /* Set this to zero to debug not using the temporary obstack
5165: to parse initializers. */
5166: int debug_temp_inits = 1;
5167:
5168: tree
5169: start_decl (declarator, declspecs, initialized, raises)
5170: tree declarator, declspecs;
5171: int initialized;
5172: tree raises;
5173: {
5174: register tree decl;
5175: register tree type, tem;
5176: tree context;
5177: extern int have_extern_spec;
5178: extern int used_extern_spec;
5179:
5180: int init_written = initialized;
5181:
5182: /* This should only be done once on the top most decl. */
5183: if (have_extern_spec && !used_extern_spec)
5184: {
5185: declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"),
5186: declspecs);
5187: used_extern_spec = 1;
5188: }
5189:
5190: decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises);
5191: if (decl == NULL_TREE || decl == void_type_node)
5192: return NULL_TREE;
5193:
5194: type = TREE_TYPE (decl);
5195:
5196: /* Don't lose if destructors must be executed at file-level. */
5197: if (TREE_STATIC (decl)
5198: && TYPE_NEEDS_DESTRUCTOR (type)
5199: && !TREE_PERMANENT (decl))
5200: {
5201: push_obstacks (&permanent_obstack, &permanent_obstack);
5202: decl = copy_node (decl);
5203: if (TREE_CODE (type) == ARRAY_TYPE)
5204: {
5205: tree itype = TYPE_DOMAIN (type);
5206: if (itype && ! TREE_PERMANENT (itype))
5207: {
5208: itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
5209: type = build_cplus_array_type (TREE_TYPE (type), itype);
5210: TREE_TYPE (decl) = type;
5211: }
5212: }
5213: pop_obstacks ();
5214: }
5215:
5216: /* Interesting work for this is done in `finish_exception_decl'. */
5217: if (TREE_CODE (type) == RECORD_TYPE
5218: && CLASSTYPE_DECLARED_EXCEPTION (type))
5219: return decl;
5220:
5221: /* Corresponding pop_obstacks is done in `finish_decl'. */
5222: push_obstacks_nochange ();
5223:
5224: context
5225: = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
5226: ? DECL_CLASS_CONTEXT (decl)
5227: : DECL_CONTEXT (decl);
5228:
5229: if (processing_template_decl)
5230: {
5231: tree d;
5232: if (TREE_CODE (decl) == FUNCTION_DECL)
5233: {
5234: /* Declarator is a call_expr; extract arguments from it, since
5235: grokdeclarator didn't do it. */
5236: tree args;
5237: args = copy_to_permanent (last_function_parms);
5238: if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
5239: {
5240: tree t = TREE_TYPE (decl);
5241:
5242: t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
5243: if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
5244: {
5245: t = build_pointer_type (t); /* base type of `this' */
5246: #if 1
5247: /* I suspect this is wrong. */
5248: t = build_type_variant (t, flag_this_is_variable <= 0,
5249: 0); /* type of `this' */
5250: #else
5251: t = build_type_variant (t, 0, 0); /* type of `this' */
5252: #endif
5253: t = build (PARM_DECL, t, this_identifier);
5254: TREE_CHAIN (t) = args;
5255: args = t;
5256: }
5257: }
5258: DECL_ARGUMENTS (decl) = args;
5259: }
5260: d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
5261: if (interface_unknown && flag_external_templates
5262: && ! DECL_IN_SYSTEM_HEADER (decl))
5263: warn_if_unknown_interface ();
5264: TREE_PUBLIC (d) = TREE_PUBLIC (decl);
5265: TREE_STATIC (d) = TREE_STATIC (decl);
5266: DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
5267: && !(context && !DECL_THIS_EXTERN (decl)));
5268: DECL_TEMPLATE_RESULT (d) = decl;
5269: decl = d;
5270: }
5271:
5272: /* If this type of object needs a cleanup, and control may
5273: jump past it, make a new binding level so that it is cleaned
5274: up only when it is initialized first. */
5275: if (TYPE_NEEDS_DESTRUCTOR (type)
5276: && current_binding_level->more_cleanups_ok == 0)
5277: pushlevel_temporary (1);
5278:
5279: if (initialized)
5280: /* Is it valid for this decl to have an initializer at all?
5281: If not, set INITIALIZED to zero, which will indirectly
5282: tell `finish_decl' to ignore the initializer once it is parsed. */
5283: switch (TREE_CODE (decl))
5284: {
5285: case TYPE_DECL:
5286: /* typedef foo = bar means give foo the same type as bar.
5287: We haven't parsed bar yet, so `finish_decl' will fix that up.
5288: Any other case of an initialization in a TYPE_DECL is an error. */
5289: if (pedantic || list_length (declspecs) > 1)
5290: {
5291: cp_error ("typedef `%D' is initialized", decl);
5292: initialized = 0;
5293: }
5294: break;
5295:
5296: case FUNCTION_DECL:
5297: cp_error ("function `%#D' is initialized like a variable", decl);
5298: initialized = 0;
5299: break;
5300:
5301: default:
5302: /* Don't allow initializations for incomplete types except for
5303: arrays which might be completed by the initialization. */
5304: if (type == error_mark_node)
5305: ; /* Don't complain again. */
5306: else if (TYPE_SIZE (type) != NULL_TREE)
5307: ; /* A complete type is ok. */
5308: else if (TREE_CODE (type) != ARRAY_TYPE)
5309: {
5310: cp_error ("variable `%#D' has initializer but incomplete type",
5311: decl);
5312: initialized = 0;
5313: }
5314: else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
5315: {
5316: cp_error ("elements of array `%#D' have incomplete type", decl);
5317: initialized = 0;
5318: }
5319: }
5320:
5321: if (!initialized
5322: && TREE_CODE (decl) != TYPE_DECL
5323: && TREE_CODE (decl) != TEMPLATE_DECL
5324: && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
5325: {
5326: if (TYPE_SIZE (type) == NULL_TREE)
5327: {
5328: cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
5329: decl);
5330: /* Change the type so that assemble_variable will give
5331: DECL an rtl we can live with: (mem (const_int 0)). */
5332: TREE_TYPE (decl) = error_mark_node;
5333: type = error_mark_node;
5334: }
5335: else
5336: {
5337: /* If any base type in the hierarchy of TYPE needs a constructor,
5338: then we set initialized to 1. This way any nodes which are
5339: created for the purposes of initializing this aggregate
5340: will live as long as it does. This is necessary for global
5341: aggregates which do not have their initializers processed until
5342: the end of the file. */
5343: initialized = TYPE_NEEDS_CONSTRUCTING (type);
5344: }
5345: }
5346:
5347: if (initialized)
5348: {
5349: if (current_binding_level != global_binding_level
5350: && DECL_EXTERNAL (decl))
5351: cp_warning ("declaration of `%#D' has `extern' and is initialized",
5352: decl);
5353: DECL_EXTERNAL (decl) = 0;
5354: if (current_binding_level == global_binding_level)
5355: TREE_STATIC (decl) = 1;
5356:
5357: /* Tell `pushdecl' this is an initialized decl
5358: even though we don't yet have the initializer expression.
5359: Also tell `finish_decl' it may store the real initializer. */
5360: DECL_INITIAL (decl) = error_mark_node;
5361: }
5362:
5363: if (context && TYPE_SIZE (context) != NULL_TREE)
5364: {
5365: if (TREE_CODE (decl) == VAR_DECL)
5366: {
5367: tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
5368: if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
5369: cp_error ("`%#D' is not a static member of `%#T'", decl, context);
5370: else if (duplicate_decls (decl, field))
5371: decl = field;
5372: }
5373:
5374: /* If it was not explicitly declared `extern',
5375: revoke any previous claims of DECL_EXTERNAL. */
5376: if (DECL_THIS_EXTERN (decl) == 0)
5377: DECL_EXTERNAL (decl) = 0;
5378: if (DECL_LANG_SPECIFIC (decl))
5379: DECL_IN_AGGR_P (decl) = 0;
5380: pushclass (context, 2);
5381: }
5382:
5383: /* Add this decl to the current binding level, but not if it
5384: comes from another scope, e.g. a static member variable.
5385: TEM may equal DECL or it may be a previous decl of the same name. */
5386:
5387: if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
5388: || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
5389: || TREE_CODE (type) == LANG_TYPE)
5390: tem = decl;
5391: else
5392: tem = pushdecl (decl);
5393:
5394: /* Tell the back-end to use or not use .common as appropriate. If we say
5395: -fconserve-space, we want this to save space, at the expense of wrong
5396: semantics. If we say -fno-conserve-space, we want this to produce
5397: errors about redefs; to do this we force variables into the data
5398: segment. Common storage is okay for non-public uninitialized data;
5399: the linker can't match it with storage from other files, and we may
5400: save some disk space. */
5401: DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem);
5402:
5403: #if 0
5404: /* We don't do this yet for GNU C++. */
5405: /* For a local variable, define the RTL now. */
5406: if (current_binding_level != global_binding_level
5407: /* But not if this is a duplicate decl
5408: and we preserved the rtl from the previous one
5409: (which may or may not happen). */
5410: && DECL_RTL (tem) == NULL_RTX)
5411: {
5412: if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
5413: expand_decl (tem);
5414: else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
5415: && DECL_INITIAL (tem) != NULL_TREE)
5416: expand_decl (tem);
5417: }
5418: #endif
5419:
5420: if (TREE_CODE (decl) == TEMPLATE_DECL)
5421: {
5422: tree result = DECL_TEMPLATE_RESULT (decl);
5423: if (DECL_CONTEXT (result) != NULL_TREE)
5424: {
5425: tree type;
5426: type = DECL_CONTEXT (result);
5427:
5428: if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
5429: {
5430: cp_error ("declaration of `%D' in non-template type `%T'",
5431: decl, type);
5432: return NULL_TREE;
5433: }
5434:
5435: if (TREE_CODE (result) == FUNCTION_DECL)
5436: return tem;
5437: else if (TREE_CODE (result) == VAR_DECL)
5438: {
5439: #if 0
5440: tree tmpl = UPT_TEMPLATE (type);
5441:
5442: fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
5443: print_node_brief (stderr, "", DECL_NAME (tem), 0);
5444: fprintf (stderr, " to class %s\n",
5445: IDENTIFIER_POINTER (DECL_NAME (tmpl)));
5446: DECL_TEMPLATE_MEMBERS (tmpl)
5447: = perm_tree_cons (DECL_NAME (tem), tem,
5448: DECL_TEMPLATE_MEMBERS (tmpl));
5449: return tem;
5450: #else
5451: sorry ("static data member templates");
5452: return NULL_TREE;
5453: #endif
5454: }
5455: else
5456: my_friendly_abort (13);
5457: }
5458: else if (TREE_CODE (result) == FUNCTION_DECL)
5459: /*tem = push_overloaded_decl (tem, 0)*/;
5460: else if (TREE_CODE (result) == VAR_DECL)
5461: {
5462: cp_error ("data template `%#D' must be member of a class template",
5463: result);
5464: return NULL_TREE;
5465: }
5466: else if (TREE_CODE (result) == TYPE_DECL)
5467: {
5468: cp_error ("invalid template `%#D'", result);
5469: return NULL_TREE;
5470: }
5471: else
5472: my_friendly_abort (14);
5473: }
5474:
5475: if (init_written
5476: && ! (TREE_CODE (tem) == PARM_DECL
5477: || (TREE_READONLY (tem)
5478: && (TREE_CODE (tem) == VAR_DECL
5479: || TREE_CODE (tem) == FIELD_DECL))))
5480: {
5481: /* When parsing and digesting the initializer,
5482: use temporary storage. Do this even if we will ignore the value. */
5483: if (current_binding_level == global_binding_level && debug_temp_inits)
5484: {
5485: if (TYPE_NEEDS_CONSTRUCTING (type)
5486: || TREE_CODE (type) == REFERENCE_TYPE)
5487: /* In this case, the initializer must lay down in permanent
5488: storage, since it will be saved until `finish_file' is run. */
5489: ;
5490: else
5491: temporary_allocation ();
5492: }
5493: }
5494:
5495: if (flag_cadillac)
5496: cadillac_start_decl (tem);
5497:
5498: return tem;
5499: }
5500:
5501: #if 0 /* unused */
5502: static void
5503: make_temporary_for_reference (decl, ctor_call, init, cleanupp)
5504: tree decl, ctor_call, init;
5505: tree *cleanupp;
5506: {
5507: tree type = TREE_TYPE (decl);
5508: tree target_type = TREE_TYPE (type);
5509: tree tmp, tmp_addr;
5510:
5511: if (ctor_call)
5512: {
5513: tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
5514: if (TREE_CODE (tmp_addr) == NOP_EXPR)
5515: tmp_addr = TREE_OPERAND (tmp_addr, 0);
5516: my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
5517: tmp = TREE_OPERAND (tmp_addr, 0);
5518: }
5519: else
5520: {
5521: tmp = get_temp_name (target_type,
5522: current_binding_level == global_binding_level);
5523: tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
5524: }
5525:
5526: TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
5527: DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr);
5528: TREE_TYPE (DECL_INITIAL (decl)) = type;
5529: if (TYPE_NEEDS_CONSTRUCTING (target_type))
5530: {
5531: if (current_binding_level == global_binding_level)
5532: {
5533: /* lay this variable out now. Otherwise `output_addressed_constants'
5534: gets confused by its initializer. */
5535: make_decl_rtl (tmp, NULL_PTR, 1);
5536: static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
5537: }
5538: else
5539: {
5540: if (ctor_call != NULL_TREE)
5541: init = ctor_call;
5542: else
5543: init = build_method_call (tmp, constructor_name_full (target_type),
5544: build_tree_list (NULL_TREE, init),
5545: NULL_TREE, LOOKUP_NORMAL);
5546: DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
5547: DECL_INITIAL (decl));
5548: *cleanupp = maybe_build_cleanup (tmp);
5549: }
5550: }
5551: else
5552: {
5553: DECL_INITIAL (tmp) = init;
5554: TREE_STATIC (tmp) = current_binding_level == global_binding_level;
5555: finish_decl (tmp, init, 0, 0);
5556: }
5557: if (TREE_STATIC (tmp))
5558: preserve_initializer ();
5559: }
5560: #endif
5561:
5562: /* Handle initialization of references.
5563: These three arguments from from `finish_decl', and have the
5564: same meaning here that they do there. */
5565: /* quotes on semantics can be found in ARM 8.4.3. */
5566: static void
5567: grok_reference_init (decl, type, init, cleanupp)
5568: tree decl, type, init;
5569: tree *cleanupp;
5570: {
5571: tree tmp;
5572:
5573: if (init == NULL_TREE)
5574: {
5575: if (DECL_LANG_SPECIFIC (decl) == 0
5576: || DECL_IN_AGGR_P (decl) == 0)
5577: {
5578: cp_error ("`%D' declared as reference but not initialized", decl);
5579: if (TREE_CODE (decl) == VAR_DECL)
5580: SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5581: }
5582: return;
5583: }
5584:
5585: if (init == error_mark_node)
5586: return;
5587:
5588: if (TREE_CODE (type) == REFERENCE_TYPE
5589: && TREE_CODE (init) == CONSTRUCTOR)
5590: {
5591: cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
5592: return;
5593: }
5594:
5595: if (TREE_CODE (init) == TREE_LIST)
5596: init = build_compound_expr (init);
5597:
5598: if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
5599: && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
5600: {
5601: /* Note: default conversion is only called in very special cases. */
5602: init = default_conversion (init);
5603: }
5604:
5605: tmp = convert_to_reference
5606: (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl);
5607:
5608: if (tmp == error_mark_node)
5609: goto fail;
5610: else if (tmp != NULL_TREE)
5611: {
5612: tree subtype = TREE_TYPE (type);
5613: init = tmp;
5614:
5615: /* Associate the cleanup with the reference so that we
5616: don't get burned by "aggressive" cleanup policy. */
5617: if (TYPE_NEEDS_DESTRUCTOR (subtype))
5618: {
5619: if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
5620: {
5621: *cleanupp = TREE_OPERAND (init, 2);
5622: TREE_OPERAND (init, 2) = error_mark_node;
5623: }
5624: else
5625: {
5626: if (TREE_CODE (tmp) == ADDR_EXPR)
5627: tmp = TREE_OPERAND (tmp, 0);
5628: if (TREE_CODE (tmp) == TARGET_EXPR)
5629: {
5630: *cleanupp = build_delete
5631: (TYPE_POINTER_TO (subtype),
5632: build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0),
5633: integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
5634: TREE_OPERAND (tmp, 2) = error_mark_node;
5635: }
5636: }
5637: }
5638:
5639: DECL_INITIAL (decl) = save_expr (init);
5640: }
5641: else
5642: {
5643: cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
5644: goto fail;
5645: }
5646:
5647: /* ?? Can this be optimized in some cases to
5648: hand back the DECL_INITIAL slot?? */
5649: if (TYPE_SIZE (TREE_TYPE (type)))
5650: {
5651: init = convert_from_reference (decl);
5652: if (TREE_PERMANENT (decl))
5653: init = copy_to_permanent (init);
5654: SET_DECL_REFERENCE_SLOT (decl, init);
5655: }
5656:
5657: if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
5658: {
5659: expand_static_init (decl, DECL_INITIAL (decl));
5660: DECL_INITIAL (decl) = NULL_TREE;
5661: }
5662: return;
5663:
5664: fail:
5665: if (TREE_CODE (decl) == VAR_DECL)
5666: SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5667: return;
5668: }
5669:
5670: /* Finish processing of a declaration;
5671: install its line number and initial value.
5672: If the length of an array type is not known before,
5673: it must be determined now, from the initial value, or it is an error.
5674:
5675: Call `pop_obstacks' iff NEED_POP is nonzero.
5676:
5677: For C++, `finish_decl' must be fairly evasive: it must keep initializers
5678: for aggregates that have constructors alive on the permanent obstack,
5679: so that the global initializing functions can be written at the end.
5680:
5681: INIT0 holds the value of an initializer that should be allowed to escape
5682: the normal rules.
5683:
5684: For functions that take default parameters, DECL points to its
5685: "maximal" instantiation. `finish_decl' must then also declared its
5686: subsequently lower and lower forms of instantiation, checking for
5687: ambiguity as it goes. This can be sped up later. */
5688:
5689: void
5690: finish_decl (decl, init, asmspec_tree, need_pop)
5691: tree decl, init;
5692: tree asmspec_tree;
5693: int need_pop;
5694: {
5695: register tree type;
5696: tree cleanup = NULL_TREE, ttype;
5697: int was_incomplete;
5698: int temporary = allocation_temporary_p ();
5699: char *asmspec = NULL;
5700: int was_readonly = 0;
5701:
5702: /* If this is 0, then we did not change obstacks. */
5703: if (! decl)
5704: {
5705: if (init)
5706: error ("assignment (not initialization) in declaration");
5707: return;
5708: }
5709:
5710: /* If a name was specified, get the string. */
5711: if (asmspec_tree)
5712: asmspec = TREE_STRING_POINTER (asmspec_tree);
5713:
5714: /* If the type of the thing we are declaring either has
5715: a constructor, or has a virtual function table pointer,
5716: AND its initialization was accepted by `start_decl',
5717: then we stayed on the permanent obstack through the
5718: declaration, otherwise, changed obstacks as GCC would. */
5719:
5720: type = TREE_TYPE (decl);
5721:
5722: if (type == error_mark_node)
5723: {
5724: if (current_binding_level == global_binding_level && temporary)
5725: end_temporary_allocation ();
5726:
5727: return;
5728: }
5729:
5730: was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
5731:
5732: /* Take care of TYPE_DECLs up front. */
5733: if (TREE_CODE (decl) == TYPE_DECL)
5734: {
5735: if (init && DECL_INITIAL (decl))
5736: {
5737: /* typedef foo = bar; store the type of bar as the type of foo. */
5738: TREE_TYPE (decl) = type = TREE_TYPE (init);
5739: DECL_INITIAL (decl) = init = NULL_TREE;
5740: }
5741: if (type != error_mark_node
5742: && IS_AGGR_TYPE (type) && DECL_NAME (decl))
5743: {
5744: if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
5745: cp_warning ("shadowing previous type declaration of `%#D'", decl);
5746: set_identifier_type_value (DECL_NAME (decl), type);
5747: CLASSTYPE_GOT_SEMICOLON (type) = 1;
5748: }
5749: GNU_xref_decl (current_function_decl, decl);
5750: rest_of_decl_compilation (decl, NULL_PTR,
5751: DECL_CONTEXT (decl) == NULL_TREE, 0);
5752: goto finish_end;
5753: }
5754: if (type != error_mark_node && IS_AGGR_TYPE (type)
5755: && CLASSTYPE_DECLARED_EXCEPTION (type))
5756: {
5757: CLASSTYPE_GOT_SEMICOLON (type) = 1;
5758: goto finish_end;
5759: }
5760: if (TREE_CODE (decl) != FUNCTION_DECL)
5761: {
5762: ttype = target_type (type);
5763: #if 0 /* WTF? -KR
5764: Leave this out until we can figure out why it was
5765: needed/desirable in the first place. Then put a comment
5766: here explaining why. Or just delete the code if no ill
5767: effects arise. */
5768: if (TYPE_NAME (ttype)
5769: && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
5770: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
5771: {
5772: tree old_id = TYPE_IDENTIFIER (ttype);
5773: char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
5774: /* Need to preserve template data for UPT nodes. */
5775: tree old_template = IDENTIFIER_TEMPLATE (old_id);
5776: newname[0] = '_';
5777: bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
5778: IDENTIFIER_LENGTH (old_id) + 1);
5779: old_id = get_identifier (newname);
5780: lookup_tag_reverse (ttype, old_id);
5781: TYPE_IDENTIFIER (ttype) = old_id;
5782: IDENTIFIER_TEMPLATE (old_id) = old_template;
5783: }
5784: #endif
5785: }
5786:
5787: if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
5788: && TYPE_NEEDS_CONSTRUCTING (type))
5789: {
5790:
5791: /* Currently, GNU C++ puts constants in text space, making them
5792: impossible to initialize. In the future, one would hope for
5793: an operating system which understood the difference between
5794: initialization and the running of a program. */
5795: was_readonly = 1;
5796: TREE_READONLY (decl) = 0;
5797: }
5798:
5799: if (TREE_CODE (decl) == FIELD_DECL)
5800: {
5801: if (init && init != error_mark_node)
5802: my_friendly_assert (TREE_PERMANENT (init), 147);
5803:
5804: if (asmspec)
5805: {
5806: /* This must override the asm specifier which was placed
5807: by grokclassfn. Lay this out fresh.
5808:
5809: @@ Should emit an error if this redefines an asm-specified
5810: @@ name, or if we have already used the function's name. */
5811: DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
5812: DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5813: make_decl_rtl (decl, asmspec, 0);
5814: }
5815: }
5816: /* If `start_decl' didn't like having an initialization, ignore it now. */
5817: else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
5818: init = NULL_TREE;
5819: else if (DECL_EXTERNAL (decl))
5820: ;
5821: else if (TREE_CODE (type) == REFERENCE_TYPE
5822: || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
5823: {
5824: if (TREE_STATIC (decl))
5825: make_decl_rtl (decl, NULL_PTR,
5826: current_binding_level == global_binding_level
5827: || pseudo_global_level_p ());
5828: grok_reference_init (decl, type, init, &cleanup);
5829: init = NULL_TREE;
5830: }
5831:
5832: GNU_xref_decl (current_function_decl, decl);
5833:
5834: if (TREE_CODE (decl) == FIELD_DECL)
5835: ;
5836: else if (TREE_CODE (decl) == CONST_DECL)
5837: {
5838: my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
5839:
5840: DECL_INITIAL (decl) = init;
5841:
5842: /* This will keep us from needing to worry about our obstacks. */
5843: my_friendly_assert (init != NULL_TREE, 149);
5844: init = NULL_TREE;
5845: }
5846: else if (init)
5847: {
5848: if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
5849: {
5850: if (TREE_CODE (type) == ARRAY_TYPE)
5851: init = digest_init (type, init, (tree *) 0);
5852: else if (TREE_CODE (init) == CONSTRUCTOR)
5853: {
5854: if (TYPE_NEEDS_CONSTRUCTING (type))
5855: {
5856: cp_error ("`%D' must be initialized by constructor, not by `{...}'",
5857: decl);
5858: init = error_mark_node;
5859: }
5860: else
5861: goto dont_use_constructor;
5862: }
5863: #if 0
5864: /* fix this in `build_functional_cast' instead.
5865: Here's the trigger code:
5866:
5867: struct ostream
5868: {
5869: ostream ();
5870: ostream (int, char *);
5871: ostream (char *);
5872: operator char *();
5873: ostream (void *);
5874: operator void *();
5875: operator << (int);
5876: };
5877: int buf_size = 1024;
5878: static char buf[buf_size];
5879: const char *debug(int i) {
5880: char *b = &buf[0];
5881: ostream o = ostream(buf_size, b);
5882: o << i;
5883: return buf;
5884: }
5885: */
5886:
5887: else if (TREE_CODE (init) == TARGET_EXPR
5888: && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
5889: {
5890: /* User wrote something like `foo x = foo (args)' */
5891: my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150);
5892: my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151);
5893:
5894: /* User wrote exactly `foo x = foo (args)' */
5895: if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
5896: {
5897: init = build (CALL_EXPR, TREE_TYPE (init),
5898: TREE_OPERAND (TREE_OPERAND (init, 1), 0),
5899: TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
5900: TREE_SIDE_EFFECTS (init) = 1;
5901: }
5902: }
5903: #endif
5904:
5905: /* We must hide the initializer so that expand_decl
5906: won't try to do something it does not understand. */
5907: if (current_binding_level == global_binding_level)
5908: {
5909: tree value;
5910: if (DECL_COMMON (decl))
5911: /* Should this be a NULL_TREE? */
5912: value = error_mark_node;
5913: else
5914: value = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
5915: DECL_INITIAL (decl) = value;
5916: }
5917: else
5918: DECL_INITIAL (decl) = error_mark_node;
5919: }
5920: else
5921: {
5922: dont_use_constructor:
5923: if (TREE_CODE (init) != TREE_VEC)
5924: init = store_init_value (decl, init);
5925:
5926: /* Don't let anyone try to initialize this variable
5927: until we are ready to do so. */
5928: if (init)
5929: {
5930: tree value;
5931: if (DECL_COMMON (decl))
5932: value = error_mark_node;
5933: else
5934: value = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
5935: DECL_INITIAL (decl) = value;
5936: }
5937: }
5938: }
5939: else if (DECL_EXTERNAL (decl))
5940: ;
5941: else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
5942: && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
5943: {
5944: tree ctype = type;
5945: while (TREE_CODE (ctype) == ARRAY_TYPE)
5946: ctype = TREE_TYPE (ctype);
5947: if (! TYPE_NEEDS_CONSTRUCTING (ctype))
5948: {
5949: if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
5950: cp_error ("structure `%D' with uninitialized const members", decl);
5951: if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
5952: cp_error ("structure `%D' with uninitialized reference members",
5953: decl);
5954: }
5955:
5956: if (TREE_CODE (decl) == VAR_DECL
5957: && !DECL_INITIAL (decl)
5958: && !TYPE_NEEDS_CONSTRUCTING (type)
5959: && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5960: cp_error ("uninitialized const `%D'", decl);
5961:
5962: /* Initialize variables in need of static initialization with
5963: an empty CONSTRUCTOR to keep assemble_variable from putting them in
5964: the wrong program space. */
5965: if (flag_pic == 0
5966: && TREE_STATIC (decl)
5967: && TREE_PUBLIC (decl)
5968: && ! DECL_EXTERNAL (decl)
5969: && TREE_CODE (decl) == VAR_DECL
5970: && TYPE_NEEDS_CONSTRUCTING (type)
5971: && (DECL_INITIAL (decl) == NULL_TREE
5972: || DECL_INITIAL (decl) == error_mark_node)
5973: && ! DECL_COMMON (decl))
5974: DECL_INITIAL (decl) = build (CONSTRUCTOR, type, NULL_TREE,
5975: NULL_TREE);
5976: }
5977: else if (TREE_CODE (decl) == VAR_DECL
5978: && TREE_CODE (type) != REFERENCE_TYPE
5979: && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5980: {
5981: /* ``Unless explicitly declared extern, a const object does not have
5982: external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
5983: However, if it's `const int foo = 1; const int foo;', don't complain
5984: about the second decl, since it does have an initializer before.
5985: We deliberately don't complain about arrays, because they're
5986: supposed to be initialized by a constructor. */
5987: if (! DECL_INITIAL (decl)
5988: && TREE_CODE (type) != ARRAY_TYPE
5989: && (!pedantic || !current_class_type))
5990: cp_error ("uninitialized const `%#D'", decl);
5991: }
5992:
5993: /* For top-level declaration, the initial value was read in
5994: the temporary obstack. MAXINDEX, rtl, etc. to be made below
5995: must go in the permanent obstack; but don't discard the
5996: temporary data yet. */
5997:
5998: if (current_binding_level == global_binding_level && temporary)
5999: end_temporary_allocation ();
6000:
6001: /* Deduce size of array from initialization, if not already known. */
6002:
6003: if (TREE_CODE (type) == ARRAY_TYPE
6004: && TYPE_DOMAIN (type) == NULL_TREE
6005: && TREE_CODE (decl) != TYPE_DECL)
6006: {
6007: int do_default
6008: = (TREE_STATIC (decl)
6009: /* Even if pedantic, an external linkage array
6010: may have incomplete type at first. */
6011: ? pedantic && ! DECL_EXTERNAL (decl)
6012: : !DECL_EXTERNAL (decl));
6013: tree initializer = init ? init : DECL_INITIAL (decl);
6014: int failure = complete_array_type (type, initializer, do_default);
6015:
6016: if (failure == 1)
6017: cp_error ("initializer fails to determine size of `%D'", decl);
6018:
6019: if (failure == 2)
6020: {
6021: if (do_default)
6022: cp_error ("array size missing in `%D'", decl);
6023: /* If a `static' var's size isn't known, make it extern as
6024: well as static, so it does not get allocated. If it's not
6025: `static', then don't mark it extern; finish_incomplete_decl
6026: will give it a default size and it will get allocated. */
6027: else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
6028: DECL_EXTERNAL (decl) = 1;
6029: }
6030:
6031: if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
6032: && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6033: integer_zero_node))
6034: cp_error ("zero-size array `%D'", decl);
6035:
6036: layout_decl (decl, 0);
6037: }
6038:
6039: if (TREE_CODE (decl) == VAR_DECL)
6040: {
6041: if (DECL_SIZE (decl) == NULL_TREE
6042: && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
6043: layout_decl (decl, 0);
6044:
6045: if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
6046: {
6047: /* A static variable with an incomplete type:
6048: that is an error if it is initialized.
6049: Otherwise, let it through, but if it is not `extern'
6050: then it may cause an error message later. */
6051: if (DECL_INITIAL (decl) != NULL_TREE)
6052: cp_error ("storage size of `%D' isn't known", decl);
6053: init = NULL_TREE;
6054: }
6055: else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
6056: {
6057: /* An automatic variable with an incomplete type: that is an error.
6058: Don't talk about array types here, since we took care of that
6059: message in grokdeclarator. */
6060: cp_error ("storage size of `%D' isn't known", decl);
6061: TREE_TYPE (decl) = error_mark_node;
6062: }
6063: else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
6064: /* Let debugger know it should output info for this type. */
6065: note_debug_info_needed (ttype);
6066:
6067: if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
6068: && DECL_SIZE (decl) != NULL_TREE
6069: && ! TREE_CONSTANT (DECL_SIZE (decl)))
6070: {
6071: if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
6072: constant_expression_warning (DECL_SIZE (decl));
6073: else
6074: cp_error ("storage size of `%D' isn't constant", decl);
6075: }
6076:
6077: if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
6078: {
6079: int yes = suspend_momentary ();
6080:
6081: /* If INIT comes from a functional cast, use the cleanup
6082: we built for that. Otherwise, make our own cleanup. */
6083: if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
6084: && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
6085: {
6086: cleanup = TREE_OPERAND (init, 2);
6087: init = TREE_OPERAND (init, 0);
6088: current_binding_level->have_cleanups = 1;
6089: }
6090: else
6091: cleanup = maybe_build_cleanup (decl);
6092: resume_momentary (yes);
6093: }
6094: }
6095: /* PARM_DECLs get cleanups, too. */
6096: else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
6097: {
6098: if (temporary)
6099: end_temporary_allocation ();
6100: cleanup = maybe_build_cleanup (decl);
6101: if (temporary)
6102: resume_temporary_allocation ();
6103: }
6104:
6105: /* Output the assembler code and/or RTL code for variables and functions,
6106: unless the type is an undefined structure or union.
6107: If not, it will get done when the type is completed. */
6108:
6109: if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
6110: || TREE_CODE (decl) == RESULT_DECL)
6111: {
6112: /* ??? FIXME: What about nested classes? */
6113: int toplev = (current_binding_level == global_binding_level
6114: || pseudo_global_level_p ());
6115: int was_temp
6116: = ((flag_traditional
6117: || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
6118: && allocation_temporary_p ());
6119:
6120: if (was_temp)
6121: end_temporary_allocation ();
6122:
6123: if (TREE_CODE (decl) == VAR_DECL
6124: && current_binding_level != global_binding_level
6125: && ! TREE_STATIC (decl)
6126: && type_needs_gc_entry (type))
6127: DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
6128:
6129: if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
6130: make_decl_rtl (decl, NULL_PTR, toplev);
6131: else if (TREE_CODE (decl) == VAR_DECL
6132: && TREE_READONLY (decl)
6133: && DECL_INITIAL (decl) != NULL_TREE
6134: && DECL_INITIAL (decl) != error_mark_node
6135: && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
6136: {
6137: DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
6138:
6139: if (asmspec)
6140: DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
6141:
6142: if (! toplev
6143: && TREE_STATIC (decl)
6144: && ! TREE_SIDE_EFFECTS (decl)
6145: && ! TREE_PUBLIC (decl)
6146: && ! DECL_EXTERNAL (decl)
6147: && ! TYPE_NEEDS_DESTRUCTOR (type)
6148: && DECL_MODE (decl) != BLKmode)
6149: {
6150: /* If this variable is really a constant, then fill its DECL_RTL
6151: slot with something which won't take up storage.
6152: If something later should take its address, we can always give
6153: it legitimate RTL at that time. */
6154: DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
6155: store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
6156: TREE_ASM_WRITTEN (decl) = 1;
6157: }
6158: else if (toplev && ! TREE_PUBLIC (decl))
6159: {
6160: /* If this is a static const, change its apparent linkage
6161: if it belongs to a #pragma interface. */
6162: if (!interface_unknown)
6163: {
6164: TREE_PUBLIC (decl) = 1;
6165: DECL_EXTERNAL (decl) = interface_only;
6166: }
6167: make_decl_rtl (decl, asmspec, toplev);
6168: }
6169: else
6170: rest_of_decl_compilation (decl, asmspec, toplev, 0);
6171: }
6172: else if (TREE_CODE (decl) == VAR_DECL
6173: && DECL_LANG_SPECIFIC (decl)
6174: && DECL_IN_AGGR_P (decl))
6175: {
6176: if (TREE_STATIC (decl))
6177: {
6178: if (init == NULL_TREE
6179: #ifdef DEFAULT_STATIC_DEFS
6180: /* If this code is dead, then users must
6181: explicitly declare static member variables
6182: outside the class def'n as well. */
6183: && TYPE_NEEDS_CONSTRUCTING (type)
6184: #endif
6185: )
6186: {
6187: DECL_EXTERNAL (decl) = 1;
6188: make_decl_rtl (decl, asmspec, 1);
6189: }
6190: else
6191: rest_of_decl_compilation (decl, asmspec, toplev, 0);
6192: }
6193: else
6194: /* Just a constant field. Should not need any rtl. */
6195: goto finish_end0;
6196: }
6197: else
6198: rest_of_decl_compilation (decl, asmspec, toplev, 0);
6199:
6200: if (was_temp)
6201: resume_temporary_allocation ();
6202:
6203: if (type != error_mark_node
6204: && TYPE_LANG_SPECIFIC (type)
6205: && CLASSTYPE_ABSTRACT_VIRTUALS (type))
6206: abstract_virtuals_error (decl, type);
6207: else if ((TREE_CODE (type) == FUNCTION_TYPE
6208: || TREE_CODE (type) == METHOD_TYPE)
6209: && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6210: && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
6211: abstract_virtuals_error (decl, TREE_TYPE (type));
6212:
6213: if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
6214: signature_error (decl, type);
6215: else if ((TREE_CODE (type) == FUNCTION_TYPE
6216: || TREE_CODE (type) == METHOD_TYPE)
6217: && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6218: && IS_SIGNATURE (TREE_TYPE (type)))
6219: signature_error (decl, TREE_TYPE (type));
6220:
6221: if (TREE_CODE (decl) == FUNCTION_DECL)
6222: {
6223: #if 0
6224: /* C++: Handle overloaded functions with default parameters. */
6225: if (DECL_OVERLOADED (decl))
6226: {
6227: tree parmtypes = TYPE_ARG_TYPES (type);
6228: tree prev = NULL_TREE;
6229: tree original_name = DECL_NAME (decl);
6230: struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
6231: /* All variants will share an uncollectible lang_decl. */
6232: copy_decl_lang_specific (decl);
6233:
6234: while (parmtypes && parmtypes != void_list_node)
6235: {
6236: /* The default value for the parameter in parmtypes is
6237: stored in the TREE_PURPOSE of the TREE_LIST. */
6238: if (TREE_PURPOSE (parmtypes))
6239: {
6240: tree fnname, fndecl;
6241: tree *argp;
6242:
6243: argp = prev ? & TREE_CHAIN (prev)
6244: : & TYPE_ARG_TYPES (type);
6245:
6246: *argp = NULL_TREE;
6247: fnname = build_decl_overload (original_name,
6248: TYPE_ARG_TYPES (type), 0);
6249: *argp = parmtypes;
6250: fndecl = build_decl (FUNCTION_DECL, fnname, type);
6251: DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl);
6252: TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
6253: DECL_INLINE (fndecl) = DECL_INLINE (decl);
6254: /* Keep G++ from thinking this function is unused.
6255: It is only used to speed up search in name space. */
6256: TREE_USED (fndecl) = 1;
6257: TREE_ASM_WRITTEN (fndecl) = 1;
6258: DECL_INITIAL (fndecl) = NULL_TREE;
6259: DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
6260: fndecl = pushdecl (fndecl);
6261: DECL_INITIAL (fndecl) = error_mark_node;
6262: DECL_RTL (fndecl) = DECL_RTL (decl);
6263: }
6264: prev = parmtypes;
6265: parmtypes = TREE_CHAIN (parmtypes);
6266: }
6267: DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
6268: }
6269: #endif
6270: }
6271: else if (DECL_EXTERNAL (decl))
6272: ;
6273: else if (TREE_STATIC (decl) && type != error_mark_node)
6274: {
6275: /* Cleanups for static variables are handled by `finish_file'. */
6276: if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
6277: expand_static_init (decl, init);
6278: else if (TYPE_NEEDS_DESTRUCTOR (type))
6279: static_aggregates = perm_tree_cons (NULL_TREE, decl,
6280: static_aggregates);
6281:
6282: /* Make entry in appropriate vector. */
6283: if (flag_gc && type_needs_gc_entry (type))
6284: build_static_gc_entry (decl, type);
6285: }
6286: else if (! toplev)
6287: {
6288: tree old_cleanups = cleanups_this_call;
6289: /* This is a declared decl which must live until the
6290: end of the binding contour. It may need a cleanup. */
6291:
6292: /* Recompute the RTL of a local array now
6293: if it used to be an incomplete type. */
6294: if (was_incomplete && ! TREE_STATIC (decl))
6295: {
6296: /* If we used it already as memory, it must stay in memory. */
6297: TREE_ADDRESSABLE (decl) = TREE_USED (decl);
6298: /* If it's still incomplete now, no init will save it. */
6299: if (DECL_SIZE (decl) == NULL_TREE)
6300: DECL_INITIAL (decl) = NULL_TREE;
6301: expand_decl (decl);
6302: }
6303: else if (! TREE_ASM_WRITTEN (decl)
6304: && (TYPE_SIZE (type) != NULL_TREE
6305: || TREE_CODE (type) == ARRAY_TYPE))
6306: {
6307: /* Do this here, because we did not expand this decl's
6308: rtl in start_decl. */
6309: if (DECL_RTL (decl) == NULL_RTX)
6310: expand_decl (decl);
6311: else if (cleanup)
6312: {
6313: /* XXX: Why don't we use decl here? */
6314: /* Ans: Because it was already expanded? */
6315: if (! expand_decl_cleanup (NULL_TREE, cleanup))
6316: cp_error ("parser lost in parsing declaration of `%D'",
6317: decl);
6318: /* Cleanup used up here. */
6319: cleanup = NULL_TREE;
6320: }
6321: }
6322:
6323: if (DECL_SIZE (decl) && type != error_mark_node)
6324: {
6325: /* Compute and store the initial value. */
6326: expand_decl_init (decl);
6327:
6328: if (init || TYPE_NEEDS_CONSTRUCTING (type))
6329: {
6330: emit_line_note (DECL_SOURCE_FILE (decl),
6331: DECL_SOURCE_LINE (decl));
6332: expand_aggr_init (decl, init, 0);
6333: }
6334:
6335: /* Set this to 0 so we can tell whether an aggregate which
6336: was initialized was ever used. Don't do this if it has a
6337: destructor, so we don't complain about the 'resource
6338: allocation is initialization' idiom. */
6339: if (TYPE_NEEDS_CONSTRUCTING (type) && cleanup == NULL_TREE)
6340: TREE_USED (decl) = 0;
6341:
6342: /* Store the cleanup, if there was one. */
6343: if (cleanup)
6344: {
6345: if (! expand_decl_cleanup (decl, cleanup))
6346: cp_error ("parser lost in parsing declaration of `%D'",
6347: decl);
6348: }
6349: }
6350: /* Cleanup any temporaries needed for the initial value. */
6351: expand_cleanups_to (old_cleanups);
6352: }
6353: finish_end0:
6354:
6355: /* Undo call to `pushclass' that was done in `start_decl'
6356: due to initialization of qualified member variable.
6357: I.e., Foo::x = 10; */
6358: {
6359: tree context = DECL_CONTEXT (decl);
6360: if (context
6361: && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
6362: && (TREE_CODE (decl) == VAR_DECL
6363: /* We also have a pushclass done that we need to undo here
6364: if we're at top level and declare a method. */
6365: || (TREE_CODE (decl) == FUNCTION_DECL
6366: /* If size hasn't been set, we're still defining it,
6367: and therefore inside the class body; don't pop
6368: the binding level.. */
6369: && TYPE_SIZE (context) != NULL_TREE
6370: /* The binding level gets popped elsewhere for a
6371: friend declaration inside another class. */
6372: /*
6373: && TYPE_IDENTIFIER (context) == current_class_name
6374: */
6375: && context == current_class_type
6376: )))
6377: popclass (1);
6378: }
6379: }
6380:
6381: finish_end:
6382:
6383: /* If requested, warn about definitions of large data objects. */
6384:
6385: if (warn_larger_than
6386: && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
6387: && !DECL_EXTERNAL (decl))
6388: {
6389: register tree decl_size = DECL_SIZE (decl);
6390:
6391: if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
6392: {
6393: unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT;
6394:
6395: if (units > larger_than_size)
6396: warning_with_decl (decl, "size of `%s' is %u bytes", units);
6397: }
6398: }
6399:
6400: if (need_pop)
6401: {
6402: /* Resume permanent allocation, if not within a function. */
6403: /* The corresponding push_obstacks_nochange is in start_decl,
6404: start_method, groktypename, and in grokfield. */
6405: pop_obstacks ();
6406: }
6407:
6408: if (was_readonly)
6409: TREE_READONLY (decl) = 1;
6410:
6411: if (flag_cadillac)
6412: cadillac_finish_decl (decl);
6413: }
6414:
6415: void
6416: expand_static_init (decl, init)
6417: tree decl;
6418: tree init;
6419: {
6420: tree oldstatic = value_member (decl, static_aggregates);
6421: tree old_cleanups;
6422:
6423: if (oldstatic)
6424: {
6425: if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
6426: cp_error ("multiple initializations given for `%D'", decl);
6427: }
6428: else if (current_binding_level != global_binding_level
6429: && current_binding_level->pseudo_global == 0)
6430: {
6431: /* Emit code to perform this initialization but once. */
6432: tree temp;
6433:
6434: /* Remember this information until end of file. */
6435: push_obstacks (&permanent_obstack, &permanent_obstack);
6436:
6437: /* Emit code to perform this initialization but once. */
6438: temp = get_temp_name (integer_type_node, 1);
6439: rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
6440: expand_start_cond (build_binary_op (EQ_EXPR, temp,
6441: integer_zero_node, 1), 0);
6442: old_cleanups = cleanups_this_call;
6443: expand_assignment (temp, integer_one_node, 0, 0);
6444: if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6445: {
6446: expand_aggr_init (decl, init, 0);
6447: do_pending_stack_adjust ();
6448: }
6449: else
6450: expand_assignment (decl, init, 0, 0);
6451: /* Cleanup any temporaries needed for the initial value. */
6452: expand_cleanups_to (old_cleanups);
6453: expand_end_cond ();
6454: if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
6455: {
6456: static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
6457: TREE_STATIC (static_aggregates) = 1;
6458: }
6459:
6460: /* Resume old (possibly temporary) allocation. */
6461: pop_obstacks ();
6462: }
6463: else
6464: {
6465: /* This code takes into account memory allocation
6466: policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
6467: does not hold for this object, then we must make permanent
6468: the storage currently in the temporary obstack. */
6469: if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6470: preserve_initializer ();
6471: static_aggregates = perm_tree_cons (init, decl, static_aggregates);
6472: }
6473: }
6474:
6475: /* Make TYPE a complete type based on INITIAL_VALUE.
6476: Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
6477: 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
6478:
6479: int
6480: complete_array_type (type, initial_value, do_default)
6481: tree type, initial_value;
6482: int do_default;
6483: {
6484: register tree maxindex = NULL_TREE;
6485: int value = 0;
6486:
6487: if (initial_value)
6488: {
6489: /* Note MAXINDEX is really the maximum index,
6490: one less than the size. */
6491: if (TREE_CODE (initial_value) == STRING_CST)
6492: maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
6493: else if (TREE_CODE (initial_value) == CONSTRUCTOR)
6494: {
6495: register int nelts
6496: = list_length (CONSTRUCTOR_ELTS (initial_value));
6497: maxindex = build_int_2 (nelts - 1, - (nelts == 0));
6498: }
6499: else
6500: {
6501: /* Make an error message unless that happened already. */
6502: if (initial_value != error_mark_node)
6503: value = 1;
6504:
6505: /* Prevent further error messages. */
6506: maxindex = build_int_2 (0, 0);
6507: }
6508: }
6509:
6510: if (!maxindex)
6511: {
6512: if (do_default)
6513: maxindex = build_int_2 (0, 0);
6514: value = 2;
6515: }
6516:
6517: if (maxindex)
6518: {
6519: tree itype;
6520:
6521: TYPE_DOMAIN (type) = build_index_type (maxindex);
6522: if (!TREE_TYPE (maxindex))
6523: TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
6524: if (initial_value)
6525: itype = TREE_TYPE (initial_value);
6526: else
6527: itype = NULL;
6528: if (itype && !TYPE_DOMAIN (itype))
6529: TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
6530: }
6531:
6532: /* Lay out the type now that we can get the real answer. */
6533:
6534: layout_type (type);
6535:
6536: return value;
6537: }
6538:
6539: /* Return zero if something is declared to be a member of type
6540: CTYPE when in the context of CUR_TYPE. STRING is the error
6541: message to print in that case. Otherwise, quietly return 1. */
6542: static int
6543: member_function_or_else (ctype, cur_type, string)
6544: tree ctype, cur_type;
6545: char *string;
6546: {
6547: if (ctype && ctype != cur_type)
6548: {
6549: error (string, TYPE_NAME_STRING (ctype));
6550: return 0;
6551: }
6552: return 1;
6553: }
6554:
6555: /* Subroutine of `grokdeclarator'. */
6556:
6557: /* Generate errors possibly applicable for a given set of specifiers.
6558: This is for ARM $7.1.2. */
6559: static void
6560: bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
6561: tree object;
6562: char *type;
6563: int virtualp, quals, friendp, raises, inlinep;
6564: {
6565: if (virtualp)
6566: cp_error ("`%D' declared as a `virtual' %s", object, type);
6567: if (inlinep)
6568: cp_error ("`%D' declared as an `inline' %s", object, type);
6569: if (quals)
6570: cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
6571: object, type);
6572: if (friendp)
6573: cp_error_at ("invalid friend declaration", object);
6574: if (raises)
6575: cp_error_at ("invalid raises declaration", object);
6576: }
6577:
6578: /* CTYPE is class type, or null if non-class.
6579: TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
6580: or METHOD_TYPE.
6581: DECLARATOR is the function's name.
6582: VIRTUALP is truthvalue of whether the function is virtual or not.
6583: FLAGS are to be passed through to `grokclassfn'.
6584: QUALS are qualifiers indicating whether the function is `const'
6585: or `volatile'.
6586: RAISES is a list of exceptions that this function can raise.
6587: CHECK is 1 if we must find this method in CTYPE, 0 if we should
6588: not look, and -1 if we should not call `grokclassfn' at all. */
6589: static tree
6590: grokfndecl (ctype, type, declarator, virtualp, flags, quals,
6591: raises, check, publicp)
6592: tree ctype, type;
6593: tree declarator;
6594: int virtualp;
6595: enum overload_flags flags;
6596: tree quals, raises;
6597: int check, publicp;
6598: {
6599: tree cname, decl;
6600: int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
6601:
6602: if (ctype)
6603: cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
6604: ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
6605: else
6606: cname = NULL_TREE;
6607:
6608: if (raises)
6609: {
6610: type = build_exception_variant (ctype, type, raises);
6611: raises = TYPE_RAISES_EXCEPTIONS (type);
6612: }
6613: decl = build_lang_decl (FUNCTION_DECL, declarator, type);
6614: /* propagate volatile out from type to decl */
6615: if (TYPE_VOLATILE (type))
6616: TREE_THIS_VOLATILE (decl) = 1;
6617:
6618: /* Should probably propagate const out from type to decl I bet (mrs). */
6619: if (staticp)
6620: {
6621: DECL_STATIC_FUNCTION_P (decl) = 1;
6622: DECL_CONTEXT (decl) = ctype;
6623: DECL_CLASS_CONTEXT (decl) = ctype;
6624: }
6625:
6626: if (publicp)
6627: TREE_PUBLIC (decl) = 1;
6628:
6629: DECL_EXTERNAL (decl) = 1;
6630: if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
6631: {
6632: cp_error ("%smember function `%D' cannot have `%T' method qualifier",
6633: (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
6634: quals = NULL_TREE;
6635: }
6636:
6637: if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
6638: grok_op_properties (decl, virtualp, check < 0);
6639:
6640: /* Caller will do the rest of this. */
6641: if (check < 0)
6642: return decl;
6643:
6644: if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
6645: {
6646: tree tmp;
6647: /* Just handle constructors here. We could do this
6648: inside the following if stmt, but I think
6649: that the code is more legible by breaking this
6650: case out. See comments below for what each of
6651: the following calls is supposed to do. */
6652: DECL_CONSTRUCTOR_P (decl) = 1;
6653:
6654: grokclassfn (ctype, declarator, decl, flags, quals);
6655: if (check)
6656: check_classfn (ctype, declarator, decl);
6657: if (! grok_ctor_properties (ctype, decl))
6658: return NULL_TREE;
6659:
6660: if (check == 0 && ! current_function_decl)
6661: {
6662: /* FIXME: this should only need to look at
6663: IDENTIFIER_GLOBAL_VALUE. */
6664: tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6665: if (tmp == NULL_TREE)
6666: IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6667: else if (TREE_CODE (tmp) != TREE_CODE (decl))
6668: cp_error ("inconsistent declarations for `%D'", decl);
6669: else
6670: {
6671: duplicate_decls (decl, tmp);
6672: decl = tmp;
6673: /* avoid creating circularities. */
6674: DECL_CHAIN (decl) = NULL_TREE;
6675: }
6676: make_decl_rtl (decl, NULL_PTR, 1);
6677: }
6678: }
6679: else
6680: {
6681: tree tmp;
6682:
6683: /* Function gets the ugly name, field gets the nice one.
6684: This call may change the type of the function (because
6685: of default parameters)! */
6686: if (ctype != NULL_TREE)
6687: grokclassfn (ctype, cname, decl, flags, quals);
6688:
6689: if (ctype != NULL_TREE && check)
6690: check_classfn (ctype, cname, decl);
6691:
6692: if (ctype == NULL_TREE || check)
6693: return decl;
6694:
6695: /* Now install the declaration of this function so that others may
6696: find it (esp. its DECL_FRIENDLIST). Don't do this for local class
6697: methods, though. */
6698: if (! current_function_decl)
6699: {
6700: /* FIXME: this should only need to look at
6701: IDENTIFIER_GLOBAL_VALUE. */
6702: tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6703: if (tmp == NULL_TREE)
6704: IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6705: else if (TREE_CODE (tmp) != TREE_CODE (decl))
6706: cp_error ("inconsistent declarations for `%D'", decl);
6707: else
6708: {
6709: duplicate_decls (decl, tmp);
6710: decl = tmp;
6711: /* avoid creating circularities. */
6712: DECL_CHAIN (decl) = NULL_TREE;
6713: }
6714: make_decl_rtl (decl, NULL_PTR, 1);
6715: }
6716:
6717: /* If this declaration supersedes the declaration of
6718: a method declared virtual in the base class, then
6719: mark this field as being virtual as well. */
6720: {
6721: tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
6722: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
6723:
6724: for (i = 0; i < n_baselinks; i++)
6725: {
6726: tree base_binfo = TREE_VEC_ELT (binfos, i);
6727: if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo))
6728: || flag_all_virtual == 1)
6729: {
6730: tmp = get_matching_virtual (base_binfo, decl,
6731: flags == DTOR_FLAG);
6732: if (tmp)
6733: {
6734: /* If this function overrides some virtual in some base
6735: class, then the function itself is also necessarily
6736: virtual, even if the user didn't explicitly say so. */
6737: DECL_VIRTUAL_P (decl) = 1;
6738:
6739: /* The TMP we really want is the one from the deepest
6740: baseclass on this path, taking care not to
6741: duplicate if we have already found it (via another
6742: path to its virtual baseclass. */
6743: if (staticp)
6744: {
6745: cp_error ("method `%D' may not be declared static",
6746: decl);
6747: cp_error_at ("(since `%D' declared virtual in base class.)",
6748: tmp);
6749: break;
6750: }
6751: virtualp = 1;
6752:
6753: {
6754: /* The argument types may have changed... */
6755: tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
6756: tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
6757:
6758: argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
6759: TREE_CHAIN (argtypes));
6760: /* But the return type has not. */
6761: type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
6762: if (raises)
6763: {
6764: type = build_exception_variant (ctype, type, raises);
6765: raises = TYPE_RAISES_EXCEPTIONS (type);
6766: }
6767: TREE_TYPE (decl) = type;
6768: DECL_VINDEX (decl)
6769: = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
6770: }
6771: break;
6772: }
6773: }
6774: }
6775: }
6776: if (virtualp)
6777: {
6778: if (DECL_VINDEX (decl) == NULL_TREE)
6779: DECL_VINDEX (decl) = error_mark_node;
6780: IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
6781: if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
6782: /* If this function is derived from a template, don't
6783: make it public. This shouldn't be here, but there's
6784: no good way to override the interface pragmas for one
6785: function or class only. Bletch. */
6786: && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
6787: && (write_virtuals == 2
6788: || (write_virtuals == 3
6789: && CLASSTYPE_INTERFACE_KNOWN (ctype))))
6790: TREE_PUBLIC (decl) = 1;
6791: }
6792: }
6793: return decl;
6794: }
6795:
6796: static tree
6797: grokvardecl (type, declarator, specbits, initialized)
6798: tree type;
6799: tree declarator;
6800: RID_BIT_TYPE specbits;
6801: int initialized;
6802: {
6803: tree decl;
6804:
6805: if (TREE_CODE (type) == OFFSET_TYPE)
6806: {
6807: /* If you declare a static member so that it
6808: can be initialized, the code will reach here. */
6809: tree basetype = TYPE_OFFSET_BASETYPE (type);
6810: type = TREE_TYPE (type);
6811: decl = build_lang_field_decl (VAR_DECL, declarator, type);
6812: DECL_CONTEXT (decl) = basetype;
6813: DECL_CLASS_CONTEXT (decl) = basetype;
6814: DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator);
6815: }
6816: else
6817: decl = build_decl (VAR_DECL, declarator, type);
6818:
6819: if (RIDBIT_SETP (RID_EXTERN, specbits))
6820: {
6821: DECL_THIS_EXTERN (decl) = 1;
6822: DECL_EXTERNAL (decl) = !initialized;
6823: }
6824:
6825: /* In class context, static means one per class,
6826: public access, and static storage. */
6827: if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
6828: && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
6829: {
6830: TREE_PUBLIC (decl) = 1;
6831: TREE_STATIC (decl) = 1;
6832: DECL_EXTERNAL (decl) = 0;
6833: }
6834: /* At top level, either `static' or no s.c. makes a definition
6835: (perhaps tentative), and absence of `static' makes it public. */
6836: else if (current_binding_level == global_binding_level)
6837: {
6838: TREE_PUBLIC (decl) = RIDBIT_NOTSETP (RID_STATIC, specbits);
6839: TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
6840: }
6841: /* Not at top level, only `static' makes a static definition. */
6842: else
6843: {
6844: TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
6845: TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
6846: }
6847: return decl;
6848: }
6849:
6850: /* Create a canonical pointer to member function type. */
6851:
6852: tree
6853: build_ptrmemfunc_type (type)
6854: tree type;
6855: {
6856: tree fields[4];
6857: tree t;
6858: tree u;
6859:
6860: /* If a canonical type already exists for this type, use it. We use
6861: this method instead of type_hash_canon, because it only does a
6862: simple equality check on the list of field members. */
6863:
6864: if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
6865: return t;
6866:
6867: push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
6868:
6869: u = make_lang_type (UNION_TYPE);
6870: fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
6871: fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier,
6872: delta_type_node);
6873: finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
6874: TYPE_NAME (u) = NULL_TREE;
6875:
6876: t = make_lang_type (RECORD_TYPE);
6877:
6878: /* Let the front-end know this is a pointer to member function. */
6879: TYPE_PTRMEMFUNC_FLAG(t) = 1;
6880: /* and not really an aggregate. */
6881: IS_AGGR_TYPE (t) = 0;
6882:
6883: fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
6884: delta_type_node);
6885: fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
6886: delta_type_node);
6887: fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
6888: finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
6889:
6890: pop_obstacks ();
6891:
6892: /* Zap out the name so that the back-end will give us the debugging
6893: information for this anonymous RECORD_TYPE. */
6894: TYPE_NAME (t) = NULL_TREE;
6895:
6896: TYPE_SET_PTRMEMFUNC_TYPE (type, t);
6897:
6898: /* Seems to be wanted. */
6899: CLASSTYPE_GOT_SEMICOLON (t) = 1;
6900: return t;
6901: }
6902:
6903: /* Given declspecs and a declarator,
6904: determine the name and type of the object declared
6905: and construct a ..._DECL node for it.
6906: (In one case we can return a ..._TYPE node instead.
6907: For invalid input we sometimes return 0.)
6908:
6909: DECLSPECS is a chain of tree_list nodes whose value fields
6910: are the storage classes and type specifiers.
6911:
6912: DECL_CONTEXT says which syntactic context this declaration is in:
6913: NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
6914: FUNCDEF for a function definition. Like NORMAL but a few different
6915: error messages in each case. Return value may be zero meaning
6916: this definition is too screwy to try to parse.
6917: MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
6918: handle member functions (which have FIELD context).
6919: Return value may be zero meaning this definition is too screwy to
6920: try to parse.
6921: PARM for a parameter declaration (either within a function prototype
6922: or before a function body). Make a PARM_DECL, or return void_type_node.
6923: TYPENAME if for a typename (in a cast or sizeof).
6924: Don't make a DECL node; just return the ..._TYPE node.
6925: FIELD for a struct or union field; make a FIELD_DECL.
6926: BITFIELD for a field with specified width.
6927: INITIALIZED is 1 if the decl has an initializer.
6928:
6929: In the TYPENAME case, DECLARATOR is really an absolute declarator.
6930: It may also be so in the PARM case, for a prototype where the
6931: argument type is specified but not the name.
6932:
6933: This function is where the complicated C meanings of `static'
6934: and `extern' are interpreted.
6935:
6936: For C++, if there is any monkey business to do, the function which
6937: calls this one must do it, i.e., prepending instance variables,
6938: renaming overloaded function names, etc.
6939:
6940: Note that for this C++, it is an error to define a method within a class
6941: which does not belong to that class.
6942:
6943: Except in the case where SCOPE_REFs are implicitly known (such as
6944: methods within a class being redundantly qualified),
6945: declarations which involve SCOPE_REFs are returned as SCOPE_REFs
6946: (class_name::decl_name). The caller must also deal with this.
6947:
6948: If a constructor or destructor is seen, and the context is FIELD,
6949: then the type gains the attribute TREE_HAS_x. If such a declaration
6950: is erroneous, NULL_TREE is returned.
6951:
6952: QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
6953: function, these are the qualifiers to give to the `this' pointer.
6954:
6955: May return void_type_node if the declarator turned out to be a friend.
6956: See grokfield for details. */
6957:
6958: enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
6959:
6960: tree
6961: grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
6962: tree declspecs;
6963: tree declarator;
6964: enum decl_context decl_context;
6965: int initialized;
6966: tree raises;
6967: {
6968: RID_BIT_TYPE specbits;
6969: int nclasses = 0;
6970: tree spec;
6971: tree type = NULL_TREE;
6972: int longlong = 0;
6973: int constp;
6974: int volatilep;
6975: int virtualp, friendp, inlinep, staticp;
6976: int explicit_int = 0;
6977: int explicit_char = 0;
6978: int opaque_typedef = 0;
6979: tree typedef_decl = NULL_TREE;
6980: char *name;
6981: tree typedef_type = NULL_TREE;
6982: int funcdef_flag = 0;
6983: enum tree_code innermost_code = ERROR_MARK;
6984: int bitfield = 0;
6985: int size_varies = 0;
6986: /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
6987: All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
6988: tree init = NULL_TREE;
6989:
6990: /* Keep track of what sort of function is being processed
6991: so that we can warn about default return values, or explicit
6992: return values which do not match prescribed defaults. */
6993: enum return_types return_type = return_normal;
6994:
6995: tree dname = NULL_TREE;
6996: tree ctype = current_class_type;
6997: tree ctor_return_type = NULL_TREE;
6998: enum overload_flags flags = NO_SPECIAL;
6999: tree quals = NULL_TREE;
7000:
7001: RIDBIT_RESET_ALL (specbits);
7002: if (decl_context == FUNCDEF)
7003: funcdef_flag = 1, decl_context = NORMAL;
7004: else if (decl_context == MEMFUNCDEF)
7005: funcdef_flag = -1, decl_context = FIELD;
7006: else if (decl_context == BITFIELD)
7007: bitfield = 1, decl_context = FIELD;
7008:
7009: if (flag_traditional && allocation_temporary_p ())
7010: end_temporary_allocation ();
7011:
7012: /* Look inside a declarator for the name being declared
7013: and get it as a string, for an error message. */
7014: {
7015: tree last = NULL_TREE;
7016: register tree decl = declarator;
7017: name = NULL;
7018:
7019: while (decl)
7020: switch (TREE_CODE (decl))
7021: {
7022: case COND_EXPR:
7023: ctype = NULL_TREE;
7024: decl = TREE_OPERAND (decl, 0);
7025: break;
7026:
7027: case BIT_NOT_EXPR: /* for C++ destructors! */
7028: {
7029: tree name = TREE_OPERAND (decl, 0);
7030: tree rename = NULL_TREE;
7031:
7032: my_friendly_assert (flags == NO_SPECIAL, 152);
7033: flags = DTOR_FLAG;
7034: return_type = return_dtor;
7035: my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
7036: if (ctype == NULL_TREE)
7037: {
7038: if (current_class_type == NULL_TREE)
7039: {
7040: error ("destructors must be member functions");
7041: flags = NO_SPECIAL;
7042: }
7043: else
7044: {
7045: tree t = constructor_name (current_class_name);
7046: if (t != name)
7047: rename = t;
7048: }
7049: }
7050: else
7051: {
7052: tree t = constructor_name (ctype);
7053: if (t != name)
7054: rename = t;
7055: }
7056:
7057: if (rename)
7058: {
7059: error ("destructor `%s' must match class name `%s'",
7060: IDENTIFIER_POINTER (name),
7061: IDENTIFIER_POINTER (rename));
7062: TREE_OPERAND (decl, 0) = rename;
7063: }
7064: decl = name;
7065: }
7066: break;
7067:
7068: case ADDR_EXPR: /* C++ reference declaration */
7069: /* fall through */
7070: case ARRAY_REF:
7071: case INDIRECT_REF:
7072: ctype = NULL_TREE;
7073: innermost_code = TREE_CODE (decl);
7074: last = decl;
7075: decl = TREE_OPERAND (decl, 0);
7076: break;
7077:
7078: case CALL_EXPR:
7079: if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
7080: {
7081: /* This is actually a variable declaration using constructor
7082: syntax. We need to call start_decl and finish_decl so we
7083: can get the variable initialized... */
7084:
7085: if (last)
7086: /* We need to insinuate ourselves into the declarator in place
7087: of the CALL_EXPR. */
7088: TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
7089: else
7090: declarator = TREE_OPERAND (decl, 0);
7091:
7092: init = TREE_OPERAND (decl, 1);
7093:
7094: decl = start_decl (declarator, declspecs, 1, NULL_TREE);
7095: finish_decl (decl, init, NULL_TREE, 1);
7096: return 0;
7097: }
7098: innermost_code = TREE_CODE (decl);
7099: decl = TREE_OPERAND (decl, 0);
7100: if (decl_context == FIELD && ctype == NULL_TREE)
7101: ctype = current_class_type;
7102: if (ctype != NULL_TREE
7103: && decl != NULL_TREE && flags != DTOR_FLAG
7104: && decl == constructor_name (ctype))
7105: {
7106: return_type = return_ctor;
7107: ctor_return_type = ctype;
7108: }
7109: ctype = NULL_TREE;
7110: break;
7111:
7112: case IDENTIFIER_NODE:
7113: dname = decl;
7114: decl = NULL_TREE;
7115:
7116: if (! IDENTIFIER_OPNAME_P (dname)
7117: /* Linux headers use '__op'. Arrgh. */
7118: || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))
7119: name = IDENTIFIER_POINTER (dname);
7120: else
7121: {
7122: if (IDENTIFIER_TYPENAME_P (dname))
7123: {
7124: my_friendly_assert (flags == NO_SPECIAL, 154);
7125: flags = TYPENAME_FLAG;
7126: ctor_return_type = TREE_TYPE (dname);
7127: return_type = return_conversion;
7128: }
7129: name = operator_name_string (dname);
7130: }
7131: break;
7132:
7133: case RECORD_TYPE:
7134: case UNION_TYPE:
7135: case ENUMERAL_TYPE:
7136: /* Parse error puts this typespec where
7137: a declarator should go. */
7138: error ("declarator name missing");
7139: dname = TYPE_NAME (decl);
7140: if (dname && TREE_CODE (dname) == TYPE_DECL)
7141: dname = DECL_NAME (dname);
7142: name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
7143: declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
7144: decl = NULL_TREE;
7145: break;
7146:
7147: /* C++ extension */
7148: case SCOPE_REF:
7149: {
7150: /* Perform error checking, and convert class names to types.
7151: We may call grokdeclarator multiple times for the same
7152: tree structure, so only do the conversion once. In this
7153: case, we have exactly what we want for `ctype'. */
7154: tree cname = TREE_OPERAND (decl, 0);
7155: if (cname == NULL_TREE)
7156: ctype = NULL_TREE;
7157: /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */
7158: else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
7159: || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
7160: ctype = cname;
7161: else if (! is_aggr_typedef (cname, 1))
7162: {
7163: TREE_OPERAND (decl, 0) = NULL_TREE;
7164: }
7165: /* Must test TREE_OPERAND (decl, 1), in case user gives
7166: us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7167: else if (TREE_OPERAND (decl, 1)
7168: && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
7169: {
7170: TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
7171: }
7172: else if (ctype == NULL_TREE)
7173: {
7174: ctype = IDENTIFIER_TYPE_VALUE (cname);
7175: TREE_OPERAND (decl, 0) = ctype;
7176: }
7177: else if (TREE_COMPLEXITY (decl) == current_class_depth)
7178: TREE_OPERAND (decl, 0) = ctype;
7179: else
7180: {
7181: if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname),
7182: ctype))
7183: {
7184: cp_error ("type `%T' is not derived from type `%T'",
7185: IDENTIFIER_TYPE_VALUE (cname), ctype);
7186: TREE_OPERAND (decl, 0) = NULL_TREE;
7187: }
7188: else
7189: {
7190: ctype = IDENTIFIER_TYPE_VALUE (cname);
7191: TREE_OPERAND (decl, 0) = ctype;
7192: }
7193: }
7194:
7195: decl = TREE_OPERAND (decl, 1);
7196: if (ctype)
7197: {
7198: if (TREE_CODE (decl) == IDENTIFIER_NODE
7199: && constructor_name (ctype) == decl)
7200: {
7201: return_type = return_ctor;
7202: ctor_return_type = ctype;
7203: }
7204: else if (TREE_CODE (decl) == BIT_NOT_EXPR
7205: && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
7206: && constructor_name (ctype) == TREE_OPERAND (decl, 0))
7207: {
7208: return_type = return_dtor;
7209: ctor_return_type = ctype;
7210: flags = DTOR_FLAG;
7211: decl = TREE_OPERAND (decl, 0);
7212: }
7213: }
7214: }
7215: break;
7216:
7217: case ERROR_MARK:
7218: decl = NULL_TREE;
7219: break;
7220:
7221: default:
7222: return 0; /* We used to do a 155 abort here. */
7223: }
7224: if (name == NULL)
7225: name = "type name";
7226: }
7227:
7228: /* A function definition's declarator must have the form of
7229: a function declarator. */
7230:
7231: if (funcdef_flag && innermost_code != CALL_EXPR)
7232: return 0;
7233:
7234: /* Anything declared one level down from the top level
7235: must be one of the parameters of a function
7236: (because the body is at least two levels down). */
7237:
7238: /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7239: by not allowing C++ class definitions to specify their parameters
7240: with xdecls (must be spec.d in the parmlist).
7241:
7242: Since we now wait to push a class scope until we are sure that
7243: we are in a legitimate method context, we must set oldcname
7244: explicitly (since current_class_name is not yet alive). */
7245:
7246: if (decl_context == NORMAL
7247: && current_binding_level->level_chain == global_binding_level)
7248: decl_context = PARM;
7249:
7250: /* Look through the decl specs and record which ones appear.
7251: Some typespecs are defined as built-in typenames.
7252: Others, the ones that are modifiers of other types,
7253: are represented by bits in SPECBITS: set the bits for
7254: the modifiers that appear. Storage class keywords are also in SPECBITS.
7255:
7256: If there is a typedef name or a type, store the type in TYPE.
7257: This includes builtin typedefs such as `int'.
7258:
7259: Set EXPLICIT_INT if the type is `int' or `char' and did not
7260: come from a user typedef.
7261:
7262: Set LONGLONG if `long' is mentioned twice.
7263:
7264: For C++, constructors and destructors have their own fast treatment. */
7265:
7266: for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
7267: {
7268: register int i;
7269: register tree id;
7270:
7271: /* Certain parse errors slip through. For example,
7272: `int class;' is not caught by the parser. Try
7273: weakly to recover here. */
7274: if (TREE_CODE (spec) != TREE_LIST)
7275: return 0;
7276:
7277: id = TREE_VALUE (spec);
7278:
7279: if (TREE_CODE (id) == IDENTIFIER_NODE)
7280: {
7281: if (id == ridpointers[(int) RID_INT]
7282: || id == ridpointers[(int) RID_CHAR]
7283: || id == ridpointers[(int) RID_BOOL]
7284: || id == ridpointers[(int) RID_WCHAR])
7285: {
7286: if (type)
7287: error ("extraneous `%T' ignored", id);
7288: else
7289: {
7290: if (id == ridpointers[(int) RID_INT])
7291: explicit_int = 1;
7292: else if (id == ridpointers[(int) RID_CHAR])
7293: explicit_char = 1;
7294: type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7295: }
7296: goto found;
7297: }
7298: /* C++ aggregate types. */
7299: if (IDENTIFIER_HAS_TYPE_VALUE (id))
7300: {
7301: if (type)
7302: cp_error ("multiple declarations `%T' and `%T'", type, id);
7303: else
7304: type = IDENTIFIER_TYPE_VALUE (id);
7305: goto found;
7306: }
7307:
7308: for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++)
7309: {
7310: if (ridpointers[i] == id)
7311: {
7312: if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
7313: {
7314: if (pedantic && flag_ansi)
7315: pedwarn ("duplicate `long'");
7316: else if (longlong)
7317: error ("`long long long' is too long for GCC");
7318: else
7319: longlong = 1;
7320: }
7321: else if (RIDBIT_SETP (i, specbits))
7322: pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
7323: RIDBIT_SET (i, specbits);
7324: goto found;
7325: }
7326: }
7327: }
7328: if (type)
7329: error ("two or more data types in declaration of `%s'", name);
7330: else if (TREE_CODE (id) == IDENTIFIER_NODE)
7331: {
7332: register tree t = lookup_name (id, 1);
7333: if (!t || TREE_CODE (t) != TYPE_DECL)
7334: error ("`%s' fails to be a typedef or built in type",
7335: IDENTIFIER_POINTER (id));
7336: else
7337: {
7338: type = TREE_TYPE (t);
7339: typedef_decl = t;
7340: }
7341: }
7342: else if (TREE_CODE (id) != ERROR_MARK)
7343: /* Can't change CLASS nodes into RECORD nodes here! */
7344: type = id;
7345:
7346: found: ;
7347: }
7348:
7349: typedef_type = type;
7350:
7351: /* No type at all: default to `int', and set EXPLICIT_INT
7352: because it was not a user-defined typedef.
7353: Except when we have a `typedef' inside a signature, in
7354: which case the type defaults to `unknown type' and is
7355: instantiated when assigning to a signature pointer or ref. */
7356:
7357: if (type == NULL_TREE
7358: && (RIDBIT_SETP (RID_SIGNED, specbits)
7359: || RIDBIT_SETP (RID_UNSIGNED, specbits)
7360: || RIDBIT_SETP (RID_LONG, specbits)
7361: || RIDBIT_SETP (RID_SHORT, specbits)))
7362: {
7363: /* These imply 'int'. */
7364: type = integer_type_node;
7365: explicit_int = 1;
7366: }
7367:
7368: if (type == NULL_TREE)
7369: {
7370: explicit_int = -1;
7371: if (return_type == return_dtor)
7372: type = void_type_node;
7373: else if (return_type == return_ctor)
7374: type = TYPE_POINTER_TO (ctor_return_type);
7375: else if (return_type == return_conversion)
7376: type = ctor_return_type;
7377: else if (current_class_type
7378: && IS_SIGNATURE (current_class_type)
7379: && (RIDBIT_SETP (RID_TYPEDEF, specbits)
7380: || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7381: && (decl_context == FIELD || decl_context == NORMAL))
7382: {
7383: explicit_int = 0;
7384: opaque_typedef = 1;
7385: type = copy_node (opaque_type_node);
7386: }
7387: /* access declaration */
7388: else if (decl_context == FIELD && declarator
7389: && TREE_CODE (declarator) == SCOPE_REF)
7390: type = void_type_node;
7391: else
7392: {
7393: if (funcdef_flag)
7394: {
7395: if (warn_return_type
7396: && return_type == return_normal)
7397: /* Save warning until we know what is really going on. */
7398: warn_about_return_type = 1;
7399: }
7400: else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7401: pedwarn ("ANSI C++ forbids typedef which does not specify a type");
7402: else if (declspecs == NULL_TREE &&
7403: (innermost_code != CALL_EXPR || pedantic))
7404: cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
7405: dname);
7406: type = integer_type_node;
7407: }
7408: }
7409: else if (return_type == return_dtor)
7410: {
7411: error ("return type specification for destructor invalid");
7412: type = void_type_node;
7413: }
7414: else if (return_type == return_ctor)
7415: {
7416: error ("return type specification for constructor invalid");
7417: type = TYPE_POINTER_TO (ctor_return_type);
7418: }
7419: else if (return_type == return_conversion)
7420: {
7421: if (comp_target_types (type, ctor_return_type, 1) == 0)
7422: cp_error ("operator `%T' declared to return `%T'",
7423: ctor_return_type, type);
7424: else
7425: cp_pedwarn ("return type specified for `operator %T'",
7426: ctor_return_type);
7427:
7428: type = ctor_return_type;
7429: }
7430: /* Catch typedefs that only specify a type, like 'typedef int;'. */
7431: else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE)
7432: {
7433: /* Template "this is a type" syntax; just ignore for now. */
7434: if (processing_template_defn)
7435: return void_type_node;
7436: }
7437:
7438: ctype = NULL_TREE;
7439:
7440: /* Now process the modifiers that were specified
7441: and check for invalid combinations. */
7442:
7443: /* Long double is a special combination. */
7444:
7445: if (RIDBIT_SETP (RID_LONG, specbits)
7446: && TYPE_MAIN_VARIANT (type) == double_type_node)
7447: {
7448: RIDBIT_RESET (RID_LONG, specbits);
7449: type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
7450: TYPE_VOLATILE (type));
7451: }
7452:
7453: /* Check all other uses of type modifiers. */
7454:
7455: if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7456: || RIDBIT_SETP (RID_SIGNED, specbits)
7457: || RIDBIT_SETP (RID_LONG, specbits)
7458: || RIDBIT_SETP (RID_SHORT, specbits))
7459: {
7460: int ok = 0;
7461:
7462: if (TREE_CODE (type) == REAL_TYPE)
7463: error ("short, signed or unsigned invalid for `%s'", name);
7464: else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node)
7465: error ("long, short, signed or unsigned invalid for `%s'", name);
7466: else if (RIDBIT_SETP (RID_LONG, specbits)
7467: && RIDBIT_SETP (RID_SHORT, specbits))
7468: error ("long and short specified together for `%s'", name);
7469: else if ((RIDBIT_SETP (RID_LONG, specbits)
7470: || RIDBIT_SETP (RID_SHORT, specbits))
7471: && explicit_char)
7472: error ("long or short specified with char for `%s'", name);
7473: else if ((RIDBIT_SETP (RID_LONG, specbits)
7474: || RIDBIT_SETP (RID_SHORT, specbits))
7475: && TREE_CODE (type) == REAL_TYPE)
7476: error ("long or short specified with floating type for `%s'", name);
7477: else if (RIDBIT_SETP (RID_SIGNED, specbits)
7478: && RIDBIT_SETP (RID_UNSIGNED, specbits))
7479: error ("signed and unsigned given together for `%s'", name);
7480: else
7481: {
7482: ok = 1;
7483: if (!explicit_int && !explicit_char && pedantic)
7484: {
7485: pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
7486: name);
7487: if (flag_pedantic_errors)
7488: ok = 0;
7489: }
7490: }
7491:
7492: /* Discard the type modifiers if they are invalid. */
7493: if (! ok)
7494: {
7495: RIDBIT_RESET (RID_UNSIGNED, specbits);
7496: RIDBIT_RESET (RID_SIGNED, specbits);
7497: RIDBIT_RESET (RID_LONG, specbits);
7498: RIDBIT_RESET (RID_SHORT, specbits);
7499: longlong = 0;
7500: }
7501: }
7502:
7503: /* Decide whether an integer type is signed or not.
7504: Optionally treat bitfields as signed by default. */
7505: if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7506: /* Traditionally, all bitfields are unsigned. */
7507: || (bitfield && flag_traditional)
7508: || (bitfield && ! flag_signed_bitfields
7509: && (explicit_int || explicit_char
7510: /* A typedef for plain `int' without `signed'
7511: can be controlled just like plain `int'. */
7512: || ! (typedef_decl != NULL_TREE
7513: && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
7514: && TREE_CODE (type) != ENUMERAL_TYPE
7515: && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
7516: {
7517: if (longlong)
7518: type = long_long_unsigned_type_node;
7519: else if (RIDBIT_SETP (RID_LONG, specbits))
7520: type = long_unsigned_type_node;
7521: else if (RIDBIT_SETP (RID_SHORT, specbits))
7522: type = short_unsigned_type_node;
7523: else if (type == char_type_node)
7524: type = unsigned_char_type_node;
7525: else if (typedef_decl)
7526: type = unsigned_type (type);
7527: else
7528: type = unsigned_type_node;
7529: }
7530: else if (RIDBIT_SETP (RID_SIGNED, specbits)
7531: && type == char_type_node)
7532: type = signed_char_type_node;
7533: else if (longlong)
7534: type = long_long_integer_type_node;
7535: else if (RIDBIT_SETP (RID_LONG, specbits))
7536: type = long_integer_type_node;
7537: else if (RIDBIT_SETP (RID_SHORT, specbits))
7538: type = short_integer_type_node;
7539:
7540: /* Set CONSTP if this declaration is `const', whether by
7541: explicit specification or via a typedef.
7542: Likewise for VOLATILEP. */
7543:
7544: constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
7545: volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
7546: staticp = 0;
7547: inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
7548: #if 0
7549: /* This sort of redundancy is blessed in a footnote to the Sep 94 WP. */
7550: if (constp > 1)
7551: warning ("duplicate `const'");
7552: if (volatilep > 1)
7553: warning ("duplicate `volatile'");
7554: #endif
7555: virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
7556:
7557: if (RIDBIT_SETP (RID_STATIC, specbits))
7558: staticp = 1 + (decl_context == FIELD);
7559:
7560: if (virtualp && staticp == 2)
7561: {
7562: cp_error ("member `%D' cannot be declared both virtual and static",
7563: dname);
7564: staticp = 0;
7565: }
7566: friendp = RIDBIT_SETP (RID_FRIEND, specbits);
7567: RIDBIT_RESET (RID_VIRTUAL, specbits);
7568: RIDBIT_RESET (RID_FRIEND, specbits);
7569:
7570: if (RIDBIT_SETP (RID_MUTABLE, specbits))
7571: {
7572: if (decl_context == PARM)
7573: {
7574: error ("non-member `%s' cannot be declared mutable", name);
7575: RIDBIT_RESET (RID_MUTABLE, specbits);
7576: }
7577: else if (friendp || decl_context == TYPENAME)
7578: {
7579: error ("non-object member `%s' cannot be declared mutable", name);
7580: RIDBIT_RESET (RID_MUTABLE, specbits);
7581: }
7582: else if (staticp)
7583: {
7584: error ("static `%s' cannot be declared mutable", name);
7585: RIDBIT_RESET (RID_MUTABLE, specbits);
7586: }
7587: #if 0
7588: if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7589: {
7590: error ("non-object member `%s' cannot be declared mutable", name);
7591: RIDBIT_RESET (RID_MUTABLE, specbits);
7592: }
7593: /* Because local typedefs are parsed twice, we don't want this
7594: message here. */
7595: else if (decl_context != FIELD)
7596: {
7597: error ("non-member `%s' cannot be declared mutable", name);
7598: RIDBIT_RESET (RID_MUTABLE, specbits);
7599: }
7600: #endif
7601: }
7602:
7603: /* Warn if two storage classes are given. Default to `auto'. */
7604:
7605: if (RIDBIT_ANY_SET (specbits))
7606: {
7607: if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
7608: if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
7609: if (decl_context == PARM && nclasses > 0)
7610: error ("storage class specifiers invalid in parameter declarations");
7611: if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7612: {
7613: if (decl_context == PARM)
7614: error ("typedef declaration invalid in parameter declaration");
7615: nclasses++;
7616: }
7617: if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
7618: if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
7619: }
7620:
7621: /* Give error if `virtual' is used outside of class declaration. */
7622: if (virtualp && current_class_name == NULL_TREE)
7623: {
7624: error ("virtual outside class declaration");
7625: virtualp = 0;
7626: }
7627: if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
7628: {
7629: error ("only members can be declared mutable");
7630: RIDBIT_RESET (RID_MUTABLE, specbits);
7631: }
7632:
7633: /* Static anonymous unions are dealt with here. */
7634: if (staticp && decl_context == TYPENAME
7635: && TREE_CODE (declspecs) == TREE_LIST
7636: && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
7637: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
7638: decl_context = FIELD;
7639:
7640: /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
7641: is used in a signature member function declaration. */
7642: if (decl_context == FIELD
7643: && IS_SIGNATURE (current_class_type)
7644: && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
7645: && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7646: {
7647: if (constp)
7648: {
7649: error ("`const' specified for signature member function `%s'", name);
7650: constp = 0;
7651: }
7652: if (volatilep)
7653: {
7654: error ("`volatile' specified for signature member function `%s'",
7655: name);
7656: volatilep = 0;
7657: }
7658: if (inlinep)
7659: {
7660: error ("`inline' specified for signature member function `%s'", name);
7661: /* Later, we'll make signature member functions inline. */
7662: inlinep = 0;
7663: }
7664: if (friendp)
7665: {
7666: error ("`friend' declaration in signature definition");
7667: friendp = 0;
7668: }
7669: if (virtualp)
7670: {
7671: error ("`virtual' specified for signature member function `%s'",
7672: name);
7673: /* Later, we'll make signature member functions virtual. */
7674: virtualp = 0;
7675: }
7676: }
7677:
7678: /* Warn about storage classes that are invalid for certain
7679: kinds of declarations (parameters, typenames, etc.). */
7680:
7681: if (nclasses > 1)
7682: error ("multiple storage classes in declaration of `%s'", name);
7683: else if (decl_context != NORMAL && nclasses > 0)
7684: {
7685: if (decl_context == PARM
7686: && (RIDBIT_SETP (RID_REGISTER, specbits)
7687: || RIDBIT_SETP (RID_AUTO, specbits)))
7688: ;
7689: else if (decl_context == FIELD
7690: && RIDBIT_SETP (RID_TYPEDEF, specbits))
7691: {
7692: /* Processing a typedef declaration nested within a class type
7693: definition. */
7694: register tree scanner;
7695: register tree previous_declspec;
7696: tree loc_typedecl;
7697:
7698: if (initialized)
7699: error ("typedef declaration includes an initializer");
7700:
7701: /* To process a class-local typedef declaration, we descend down
7702: the chain of declspecs looking for the `typedef' spec. When
7703: we find it, we replace it with `static', and then recursively
7704: call `grokdeclarator' with the original declarator and with
7705: the newly adjusted declspecs. This call should return a
7706: FIELD_DECL node with the TREE_TYPE (and other parts) set
7707: appropriately. We can then just change the TREE_CODE on that
7708: from FIELD_DECL to TYPE_DECL and we're done. */
7709:
7710: for (previous_declspec = NULL_TREE, scanner = declspecs;
7711: scanner;
7712: previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
7713: {
7714: if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
7715: break;
7716: }
7717:
7718: if (previous_declspec)
7719: TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner);
7720: else
7721: declspecs = TREE_CHAIN (scanner);
7722:
7723: declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC],
7724: declspecs);
7725:
7726: /* In the recursive call to grokdeclarator we need to know
7727: whether we are working on a signature-local typedef. */
7728: if (IS_SIGNATURE (current_class_type))
7729: SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
7730:
7731: loc_typedecl =
7732: grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE);
7733:
7734: if (previous_declspec)
7735: TREE_CHAIN (previous_declspec) = scanner;
7736:
7737: if (loc_typedecl != error_mark_node)
7738: {
7739: register int i = sizeof (struct lang_decl_flags) / sizeof (int);
7740: register int *pi;
7741:
7742: TREE_SET_CODE (loc_typedecl, TYPE_DECL);
7743: /* This is the same field as DECL_ARGUMENTS, which is set for
7744: function typedefs by the above grokdeclarator. */
7745: DECL_NESTED_TYPENAME (loc_typedecl) = 0;
7746:
7747: pi = (int *) permalloc (sizeof (struct lang_decl_flags));
7748: while (i > 0)
7749: pi[--i] = 0;
7750: DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
7751: }
7752:
7753: if (IS_SIGNATURE (current_class_type))
7754: {
7755: SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
7756: if (loc_typedecl != error_mark_node && opaque_typedef)
7757: SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
7758: }
7759:
7760: return loc_typedecl;
7761: }
7762: else if (decl_context == FIELD
7763: && (! IS_SIGNATURE (current_class_type)
7764: || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7765: /* C++ allows static class elements */
7766: && RIDBIT_SETP (RID_STATIC, specbits))
7767: /* C++ also allows inlines and signed and unsigned elements,
7768: but in those cases we don't come in here. */
7769: ;
7770: else
7771: {
7772: if (decl_context == FIELD)
7773: {
7774: tree tmp = TREE_OPERAND (declarator, 0);
7775: register int op = IDENTIFIER_OPNAME_P (tmp);
7776: error ("storage class specified for %s `%s'",
7777: IS_SIGNATURE (current_class_type)
7778: ? (op
7779: ? "signature member operator"
7780: : "signature member function")
7781: : (op ? "member operator" : "structure field"),
7782: op ? operator_name_string (tmp) : name);
7783: }
7784: else
7785: error ((decl_context == PARM
7786: ? "storage class specified for parameter `%s'"
7787: : "storage class specified for typename"), name);
7788: RIDBIT_RESET (RID_REGISTER, specbits);
7789: RIDBIT_RESET (RID_AUTO, specbits);
7790: RIDBIT_RESET (RID_EXTERN, specbits);
7791:
7792: if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
7793: {
7794: RIDBIT_RESET (RID_STATIC, specbits);
7795: staticp = 0;
7796: }
7797: }
7798: }
7799: else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
7800: {
7801: if (current_binding_level == global_binding_level)
7802: {
7803: /* It's common practice (and completely legal) to have a const
7804: be initialized and declared extern. */
7805: if (! constp)
7806: warning ("`%s' initialized and declared `extern'", name);
7807: }
7808: else
7809: error ("`%s' has both `extern' and initializer", name);
7810: }
7811: else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
7812: && current_binding_level != global_binding_level)
7813: error ("nested function `%s' declared `extern'", name);
7814: else if (current_binding_level == global_binding_level)
7815: {
7816: if (RIDBIT_SETP (RID_AUTO, specbits))
7817: error ("top-level declaration of `%s' specifies `auto'", name);
7818: #if 0
7819: if (RIDBIT_SETP (RID_REGISTER, specbits))
7820: error ("top-level declaration of `%s' specifies `register'", name);
7821: #endif
7822: #if 0
7823: /* I'm not sure under what circumstances we should turn
7824: on the extern bit, and under what circumstances we should
7825: warn if other bits are turned on. */
7826: if (decl_context == NORMAL
7827: && RIDBIT_NOSETP (RID_EXTERN, specbits)
7828: && ! root_lang_context_p ())
7829: {
7830: RIDBIT_SET (RID_EXTERN, specbits);
7831: }
7832: #endif
7833: }
7834:
7835: /* Now figure out the structure of the declarator proper.
7836: Descend through it, creating more complex types, until we reach
7837: the declared identifier (or NULL_TREE, in an absolute declarator). */
7838:
7839: while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
7840: {
7841: /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
7842: an INDIRECT_REF (for *...),
7843: a CALL_EXPR (for ...(...)),
7844: an identifier (for the name being declared)
7845: or a null pointer (for the place in an absolute declarator
7846: where the name was omitted).
7847: For the last two cases, we have just exited the loop.
7848:
7849: For C++ it could also be
7850: a SCOPE_REF (for class :: ...). In this case, we have converted
7851: sensible names to types, and those are the values we use to
7852: qualify the member name.
7853: an ADDR_EXPR (for &...),
7854: a BIT_NOT_EXPR (for destructors)
7855:
7856: At this point, TYPE is the type of elements of an array,
7857: or for a function to return, or for a pointer to point to.
7858: After this sequence of ifs, TYPE is the type of the
7859: array or function or pointer, and DECLARATOR has had its
7860: outermost layer removed. */
7861:
7862: if (TREE_CODE (type) == ERROR_MARK)
7863: {
7864: if (TREE_CODE (declarator) == SCOPE_REF)
7865: declarator = TREE_OPERAND (declarator, 1);
7866: else
7867: declarator = TREE_OPERAND (declarator, 0);
7868: continue;
7869: }
7870: if (quals != NULL_TREE
7871: && (declarator == NULL_TREE
7872: || TREE_CODE (declarator) != SCOPE_REF))
7873: {
7874: if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
7875: ctype = TYPE_METHOD_BASETYPE (type);
7876: if (ctype != NULL_TREE)
7877: {
7878: #if 0 /* not yet, should get fixed properly later */
7879: tree dummy = make_type_decl (NULL_TREE, type);
7880: #else
7881: tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
7882: #endif
7883: ctype = grok_method_quals (ctype, dummy, quals);
7884: type = TREE_TYPE (dummy);
7885: quals = NULL_TREE;
7886: }
7887: }
7888: switch (TREE_CODE (declarator))
7889: {
7890: case ARRAY_REF:
7891: {
7892: register tree itype = NULL_TREE;
7893: register tree size = TREE_OPERAND (declarator, 1);
7894:
7895: declarator = TREE_OPERAND (declarator, 0);
7896:
7897: /* Check for some types that there cannot be arrays of. */
7898:
7899: if (TYPE_MAIN_VARIANT (type) == void_type_node)
7900: {
7901: cp_error ("declaration of `%D' as array of voids", dname);
7902: type = error_mark_node;
7903: }
7904:
7905: if (TREE_CODE (type) == FUNCTION_TYPE)
7906: {
7907: cp_error ("declaration of `%D' as array of functions", dname);
7908: type = error_mark_node;
7909: }
7910:
7911: /* ARM $8.4.3: Since you can't have a pointer to a reference,
7912: you can't have arrays of references. If we allowed them,
7913: then we'd be saying x[i] is legal for an array x, but
7914: then you'd have to ask: what does `*(x + i)' mean? */
7915: if (TREE_CODE (type) == REFERENCE_TYPE)
7916: {
7917: if (decl_context == TYPENAME)
7918: cp_error ("cannot make arrays of references");
7919: else
7920: cp_error ("declaration of `%D' as array of references",
7921: dname);
7922: type = error_mark_node;
7923: }
7924:
7925: if (TREE_CODE (type) == OFFSET_TYPE)
7926: {
7927: cp_error ("declaration of `%D' as array of data members",
7928: dname);
7929: type = error_mark_node;
7930: }
7931:
7932: if (TREE_CODE (type) == METHOD_TYPE)
7933: {
7934: cp_error ("declaration of `%D' as array of function members",
7935: dname);
7936: type = error_mark_node;
7937: }
7938:
7939: if (size == error_mark_node)
7940: type = error_mark_node;
7941:
7942: if (type == error_mark_node)
7943: continue;
7944:
7945: if (size)
7946: {
7947: /* Must suspend_momentary here because the index
7948: type may need to live until the end of the function.
7949: For example, it is used in the declaration of a
7950: variable which requires destructing at the end of
7951: the function; then build_vec_delete will need this
7952: value. */
7953: int yes = suspend_momentary ();
7954: /* might be a cast */
7955: if (TREE_CODE (size) == NOP_EXPR
7956: && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
7957: size = TREE_OPERAND (size, 0);
7958:
7959: /* If this is a template parameter, it'll be constant, but
7960: we don't know what the value is yet. */
7961: if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
7962: goto dont_grok_size;
7963:
7964: if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
7965: && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
7966: {
7967: cp_error ("size of array `%D' has non-integer type",
7968: dname);
7969: size = integer_one_node;
7970: }
7971: if (TREE_READONLY_DECL_P (size))
7972: size = decl_constant_value (size);
7973: if (flag_ansi && integer_zerop (size))
7974: cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
7975: if (TREE_CONSTANT (size))
7976: {
7977: constant_expression_warning (size);
7978: if (INT_CST_LT (size, integer_zero_node))
7979: {
7980: cp_error ("size of array `%D' is negative", dname);
7981: size = integer_one_node;
7982: }
7983: itype = build_index_type (size_binop (MINUS_EXPR, size,
7984: integer_one_node));
7985: }
7986: else
7987: {
7988: if (flag_ansi)
7989: {
7990: if (dname)
7991: cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
7992: dname);
7993: else
7994: cp_pedwarn ("ANSI C++ forbids variable-size array");
7995: }
7996: dont_grok_size:
7997: itype =
7998: build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
7999: /* Make sure the array size remains visibly nonconstant
8000: even if it is (eg) a const variable with known value. */
8001: size_varies = 1;
8002: itype = variable_size (itype);
8003: itype = build_index_type (itype);
8004: }
8005: resume_momentary (yes);
8006: }
8007:
8008: /* Build the array type itself, then merge any constancy or
8009: volatility into the target type. We must do it in this order
8010: to ensure that the TYPE_MAIN_VARIANT field of the array type
8011: is set correctly. */
8012:
8013: type = build_cplus_array_type (type, itype);
8014: if (constp || volatilep)
8015: type = cp_build_type_variant (type, constp, volatilep);
8016:
8017: ctype = NULL_TREE;
8018: }
8019: break;
8020:
8021: case CALL_EXPR:
8022: {
8023: tree arg_types;
8024: int funcdecl_p;
8025: tree inner_parms = TREE_OPERAND (declarator, 1);
8026: tree inner_decl = TREE_OPERAND (declarator, 0);
8027:
8028: /* Declaring a function type.
8029: Make sure we have a valid type for the function to return. */
8030: #if 0
8031: /* Is this an error? Should they be merged into TYPE here? */
8032: if (pedantic && (constp || volatilep))
8033: pedwarn ("function declared to return const or volatile result");
8034: #else
8035: /* Merge any constancy or volatility into the function return
8036: type. */
8037:
8038: if (constp || volatilep)
8039: {
8040: type = cp_build_type_variant (type, constp, volatilep);
8041: if (IS_AGGR_TYPE (type))
8042: build_pointer_type (type);
8043: constp = 0;
8044: volatilep = 0;
8045: }
8046: #endif
8047:
8048: /* Warn about some types functions can't return. */
8049:
8050: if (TREE_CODE (type) == FUNCTION_TYPE)
8051: {
8052: error ("`%s' declared as function returning a function", name);
8053: type = integer_type_node;
8054: }
8055: if (TREE_CODE (type) == ARRAY_TYPE)
8056: {
8057: error ("`%s' declared as function returning an array", name);
8058: type = integer_type_node;
8059: }
8060:
8061: if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
8062: inner_decl = TREE_OPERAND (inner_decl, 1);
8063:
8064: /* Say it's a definition only for the CALL_EXPR
8065: closest to the identifier. */
8066: funcdecl_p =
8067: inner_decl && TREE_CODE (inner_decl) == IDENTIFIER_NODE;
8068:
8069: if (ctype == NULL_TREE
8070: && decl_context == FIELD
8071: && funcdecl_p
8072: && (friendp == 0 || dname == current_class_name))
8073: ctype = current_class_type;
8074:
8075: if (ctype && return_type == return_conversion)
8076: TYPE_HAS_CONVERSION (ctype) = 1;
8077: if (ctype && constructor_name (ctype) == dname)
8078: {
8079: /* We are within a class's scope. If our declarator name
8080: is the same as the class name, and we are defining
8081: a function, then it is a constructor/destructor, and
8082: therefore returns a void type. */
8083:
8084: if (flags == DTOR_FLAG)
8085: {
8086: /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
8087: not be declared const or volatile. A destructor
8088: may not be static. */
8089: if (staticp == 2)
8090: error ("destructor cannot be static member function");
8091: if (TYPE_READONLY (type))
8092: {
8093: error ("destructors cannot be declared `const'");
8094: return void_type_node;
8095: }
8096: if (TYPE_VOLATILE (type))
8097: {
8098: error ("destructors cannot be declared `volatile'");
8099: return void_type_node;
8100: }
8101: if (decl_context == FIELD)
8102: {
8103: if (! member_function_or_else (ctype, current_class_type,
8104: "destructor for alien class `%s' cannot be a member"))
8105: return void_type_node;
8106: }
8107: }
8108: else /* it's a constructor. */
8109: {
8110: /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
8111: not be declared const or volatile. A constructor may
8112: not be virtual. A constructor may not be static. */
8113: if (staticp == 2)
8114: error ("constructor cannot be static member function");
8115: if (virtualp)
8116: {
8117: pedwarn ("constructors cannot be declared virtual");
8118: virtualp = 0;
8119: }
8120: if (TYPE_READONLY (type))
8121: {
8122: error ("constructors cannot be declared `const'");
8123: return void_type_node;
8124: }
8125: if (TYPE_VOLATILE (type))
8126: {
8127: error ("constructors cannot be declared `volatile'");
8128: return void_type_node;
8129: }
8130: {
8131: RID_BIT_TYPE tmp_bits;
8132: bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE));
8133: RIDBIT_RESET (RID_INLINE, tmp_bits);
8134: RIDBIT_RESET (RID_STATIC, tmp_bits);
8135: if (RIDBIT_ANY_SET (tmp_bits))
8136: error ("return value type specifier for constructor ignored");
8137: }
8138: type = TYPE_POINTER_TO (ctype);
8139: if (decl_context == FIELD &&
8140: IS_SIGNATURE (current_class_type))
8141: {
8142: error ("constructor not allowed in signature");
8143: return void_type_node;
8144: }
8145: else if (decl_context == FIELD)
8146: {
8147: if (! member_function_or_else (ctype, current_class_type,
8148: "constructor for alien class `%s' cannot be member"))
8149: return void_type_node;
8150: TYPE_HAS_CONSTRUCTOR (ctype) = 1;
8151: if (return_type != return_ctor)
8152: return NULL_TREE;
8153: }
8154: }
8155: if (decl_context == FIELD)
8156: staticp = 0;
8157: }
8158: else if (friendp && virtualp)
8159: {
8160: /* Cannot be both friend and virtual. */
8161: error ("virtual functions cannot be friends");
8162: RIDBIT_RESET (RID_FRIEND, specbits);
8163: friendp = 0;
8164: }
8165:
8166: if (decl_context == NORMAL && friendp)
8167: error ("friend declaration not in class definition");
8168:
8169: /* Pick up type qualifiers which should be applied to `this'. */
8170: quals = TREE_OPERAND (declarator, 2);
8171:
8172: /* Traditionally, declaring return type float means double. */
8173:
8174: if (flag_traditional
8175: && TYPE_MAIN_VARIANT (type) == float_type_node)
8176: {
8177: type = build_type_variant (double_type_node,
8178: TYPE_READONLY (type),
8179: TYPE_VOLATILE (type));
8180: }
8181:
8182: /* Construct the function type and go to the next
8183: inner layer of declarator. */
8184:
8185: declarator = TREE_OPERAND (declarator, 0);
8186:
8187: /* FIXME: This is where default args should be fully
8188: processed. */
8189:
8190: arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0);
8191:
8192: if (declarator)
8193: {
8194: /* Get past destructors, etc.
8195: We know we have one because FLAGS will be non-zero.
8196:
8197: Complain about improper parameter lists here. */
8198: if (TREE_CODE (declarator) == BIT_NOT_EXPR)
8199: {
8200: declarator = TREE_OPERAND (declarator, 0);
8201:
8202: if (strict_prototype == 0 && arg_types == NULL_TREE)
8203: arg_types = void_list_node;
8204: else if (arg_types == NULL_TREE
8205: || arg_types != void_list_node)
8206: {
8207: error ("destructors cannot be specified with parameters");
8208: arg_types = void_list_node;
8209: }
8210: }
8211: }
8212:
8213: /* ANSI seems to say that `const int foo ();'
8214: does not make the function foo const. */
8215: type = build_function_type (type,
8216: flag_traditional ? 0 : arg_types);
8217: }
8218: break;
8219:
8220: case ADDR_EXPR:
8221: case INDIRECT_REF:
8222: /* Filter out pointers-to-references and references-to-references.
8223: We can get these if a TYPE_DECL is used. */
8224:
8225: if (TREE_CODE (type) == REFERENCE_TYPE)
8226: {
8227: error ("cannot declare %s to references",
8228: TREE_CODE (declarator) == ADDR_EXPR
8229: ? "references" : "pointers");
8230: declarator = TREE_OPERAND (declarator, 0);
8231: continue;
8232: }
8233:
8234: /* Merge any constancy or volatility into the target type
8235: for the pointer. */
8236:
8237: if (constp || volatilep)
8238: {
8239: /* A const or volatile signature pointer/reference is
8240: pointing to a const or volatile object, i.e., the
8241: `optr' is const or volatile, respectively, not the
8242: signature pointer/reference itself. */
8243: if (! IS_SIGNATURE (type))
8244: {
8245: type = cp_build_type_variant (type, constp, volatilep);
8246: if (IS_AGGR_TYPE (type))
8247: build_pointer_type (type);
8248: constp = 0;
8249: volatilep = 0;
8250: }
8251: }
8252:
8253: if (IS_SIGNATURE (type))
8254: {
8255: if (TREE_CODE (declarator) == ADDR_EXPR)
8256: {
8257: if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8258: && TYPE_SIZE (type))
8259: cp_warning ("empty signature `%T' used in signature reference declaration",
8260: type);
8261: #if 0
8262: type = build_signature_reference_type (type,
8263: constp, volatilep);
8264: #else
8265: sorry ("signature reference");
8266: return NULL_TREE;
8267: #endif
8268: }
8269: else
8270: {
8271: if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8272: && TYPE_SIZE (type))
8273: cp_warning ("empty signature `%T' used in signature pointer declaration",
8274: type);
8275: type = build_signature_pointer_type (type,
8276: constp, volatilep);
8277: }
8278: constp = 0;
8279: volatilep = 0;
8280: }
8281: else if (TREE_CODE (declarator) == ADDR_EXPR)
8282: {
8283: if (TREE_CODE (type) == FUNCTION_TYPE)
8284: {
8285: error ("cannot declare references to functions; use pointer to function instead");
8286: type = build_pointer_type (type);
8287: }
8288: else
8289: {
8290: if (TYPE_MAIN_VARIANT (type) == void_type_node)
8291: error ("invalid type: `void &'");
8292: else
8293: type = build_reference_type (type);
8294: }
8295: }
8296: else if (TREE_CODE (type) == METHOD_TYPE)
8297: {
8298: type = build_ptrmemfunc_type (build_pointer_type (type));
8299: }
8300: else
8301: type = build_pointer_type (type);
8302:
8303: /* Process a list of type modifier keywords (such as
8304: const or volatile) that were given inside the `*' or `&'. */
8305:
8306: if (TREE_TYPE (declarator))
8307: {
8308: register tree typemodlist;
8309: int erred = 0;
8310: for (typemodlist = TREE_TYPE (declarator); typemodlist;
8311: typemodlist = TREE_CHAIN (typemodlist))
8312: {
8313: if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
8314: constp++;
8315: else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
8316: volatilep++;
8317: else if (!erred)
8318: {
8319: erred = 1;
8320: error ("invalid type modifier within %s declarator",
8321: TREE_CODE (declarator) == ADDR_EXPR
8322: ? "reference" : "pointer");
8323: }
8324: }
8325: if (constp > 1)
8326: pedwarn ("duplicate `const'");
8327: if (volatilep > 1)
8328: pedwarn ("duplicate `volatile'");
8329: if (TREE_CODE (declarator) == ADDR_EXPR
8330: && (constp || volatilep))
8331: {
8332: if (constp)
8333: warning ("discarding `const' applied to a reference");
8334: if (volatilep)
8335: warning ("discarding `volatile' applied to a reference");
8336: constp = volatilep = 0;
8337: }
8338: }
8339: declarator = TREE_OPERAND (declarator, 0);
8340: ctype = NULL_TREE;
8341: break;
8342:
8343: case SCOPE_REF:
8344: {
8345: /* We have converted type names to NULL_TREE if the
8346: name was bogus, or to a _TYPE node, if not.
8347:
8348: The variable CTYPE holds the type we will ultimately
8349: resolve to. The code here just needs to build
8350: up appropriate member types. */
8351: tree sname = TREE_OPERAND (declarator, 1);
8352: /* Destructors can have their visibilities changed as well. */
8353: if (TREE_CODE (sname) == BIT_NOT_EXPR)
8354: sname = TREE_OPERAND (sname, 0);
8355:
8356: if (TREE_COMPLEXITY (declarator) == 0)
8357: /* This needs to be here, in case we are called
8358: multiple times. */ ;
8359: else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
8360: /* don't fall out into global scope. Hides real bug? --eichin */ ;
8361: else if (TREE_COMPLEXITY (declarator) == current_class_depth)
8362: {
8363: /* This pop_nested_class corresponds to the
8364: push_nested_class used to push into class scope for
8365: parsing the argument list of a function decl, in
8366: qualified_id. */
8367: pop_nested_class (1);
8368: TREE_COMPLEXITY (declarator) = current_class_depth;
8369: }
8370: else
8371: my_friendly_abort (16);
8372:
8373: if (TREE_OPERAND (declarator, 0) == NULL_TREE)
8374: {
8375: /* We had a reference to a global decl, or
8376: perhaps we were given a non-aggregate typedef,
8377: in which case we cleared this out, and should just
8378: keep going as though it wasn't there. */
8379: declarator = sname;
8380: continue;
8381: }
8382: ctype = TREE_OPERAND (declarator, 0);
8383:
8384: if (sname == NULL_TREE)
8385: goto done_scoping;
8386:
8387: if (TREE_CODE (sname) == IDENTIFIER_NODE)
8388: {
8389: /* This is the `standard' use of the scoping operator:
8390: basetype :: member . */
8391:
8392: if (TREE_CODE (type) == FUNCTION_TYPE)
8393: {
8394: if (current_class_type == NULL_TREE
8395: || TYPE_MAIN_VARIANT (ctype) == current_class_type
8396: || friendp)
8397: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8398: TREE_TYPE (type), TYPE_ARG_TYPES (type));
8399: else
8400: {
8401: cp_error ("cannot declare member function `%T::%s' within `%T'",
8402: ctype, name, current_class_type);
8403: return void_type_node;
8404: }
8405: }
8406: else if (TYPE_MAIN_VARIANT (ctype) == current_class_type)
8407: {
8408: if (extra_warnings)
8409: cp_warning ("redundant qualification `%T' on member `%s' ignored",
8410: ctype, name);
8411: type = build_offset_type (ctype, type);
8412: }
8413: else if (TYPE_SIZE (ctype) != NULL_TREE
8414: || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
8415: {
8416: tree t;
8417: /* have to move this code elsewhere in this function.
8418: this code is used for i.e., typedef int A::M; M *pm; */
8419:
8420: if (explicit_int == -1 && decl_context == FIELD
8421: && funcdef_flag == 0)
8422: {
8423: /* The code in here should only be used to build
8424: stuff that will be grokked as access decls. */
8425: t = lookup_field (ctype, sname, 0, 0);
8426: if (t)
8427: {
8428: t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8429: DECL_INITIAL (t) = init;
8430: return t;
8431: }
8432: /* No such field, try member functions. */
8433: t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
8434: if (t)
8435: {
8436: if (flags == DTOR_FLAG)
8437: t = TREE_VALUE (t);
8438: else if (CLASSTYPE_METHOD_VEC (ctype)
8439: && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
8440: {
8441: /* Don't include destructor with constructors. */
8442: t = DECL_CHAIN (TREE_VALUE (t));
8443: if (t == NULL_TREE)
8444: error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
8445: t = build_tree_list (NULL_TREE, t);
8446: }
8447: t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8448: DECL_INITIAL (t) = init;
8449: return t;
8450: }
8451:
8452: cp_error
8453: ("field `%D' is not a member of structure `%T'",
8454: sname, ctype);
8455: }
8456:
8457: if (current_class_type)
8458: {
8459: if (TYPE_MAIN_VARIANT (ctype) != current_class_type)
8460: {
8461: cp_error ("cannot declare member `%T::%s' within `%T'",
8462: ctype, name, current_class_type);
8463: return void_type_node;
8464: }
8465: else if (extra_warnings)
8466: cp_warning ("extra qualification `%T' on member `%s' ignored",
8467: ctype, name);
8468: }
8469: type = build_offset_type (ctype, type);
8470: }
8471: else if (uses_template_parms (ctype))
8472: {
8473: enum tree_code c;
8474: if (TREE_CODE (type) == FUNCTION_TYPE)
8475: {
8476: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8477: TREE_TYPE (type),
8478: TYPE_ARG_TYPES (type));
8479: c = FUNCTION_DECL;
8480: }
8481: }
8482: else
8483: {
8484: cp_error ("structure `%T' not yet defined", ctype);
8485: return error_mark_node;
8486: }
8487:
8488: declarator = sname;
8489: }
8490: else if (TREE_CODE (sname) == SCOPE_REF)
8491: my_friendly_abort (17);
8492: else
8493: {
8494: done_scoping:
8495: declarator = TREE_OPERAND (declarator, 1);
8496: if (declarator && TREE_CODE (declarator) == CALL_EXPR)
8497: /* In this case, we will deal with it later. */
8498: ;
8499: else
8500: {
8501: if (TREE_CODE (type) == FUNCTION_TYPE)
8502: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
8503: else
8504: type = build_offset_type (ctype, type);
8505: }
8506: }
8507: }
8508: break;
8509:
8510: case BIT_NOT_EXPR:
8511: declarator = TREE_OPERAND (declarator, 0);
8512: break;
8513:
8514: case RECORD_TYPE:
8515: case UNION_TYPE:
8516: case ENUMERAL_TYPE:
8517: declarator = NULL_TREE;
8518: break;
8519:
8520: case ERROR_MARK:
8521: declarator = NULL_TREE;
8522: break;
8523:
8524: default:
8525: my_friendly_abort (158);
8526: }
8527: }
8528:
8529: /* Now TYPE has the actual type. */
8530:
8531: /* If this is declaring a typedef name, return a TYPE_DECL. */
8532:
8533: if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8534: {
8535: tree decl;
8536:
8537: /* Note that the grammar rejects storage classes
8538: in typenames, fields or parameters. */
8539: if (constp || volatilep)
8540: type = cp_build_type_variant (type, constp, volatilep);
8541:
8542: /* If the user declares "struct {...} foo" then `foo' will have
8543: an anonymous name. Fill that name in now. Nothing can
8544: refer to it, so nothing needs know about the name change.
8545: The TYPE_NAME field was filled in by build_struct_xref. */
8546: if (type != error_mark_node
8547: && TYPE_NAME (type)
8548: && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8549: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
8550: {
8551: /* replace the anonymous name with the real name everywhere. */
8552: lookup_tag_reverse (type, declarator);
8553: TYPE_IDENTIFIER (type) = declarator;
8554:
8555: if (TYPE_LANG_SPECIFIC (type))
8556: TYPE_WAS_ANONYMOUS (type) = 1;
8557:
8558: {
8559: tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
8560:
8561: if (!c)
8562: set_nested_typename (d, 0, declarator, type);
8563: else if (TREE_CODE (c) == FUNCTION_DECL)
8564: set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
8565: declarator, type);
8566: else
8567: set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
8568: }
8569: }
8570:
8571: #if 0 /* not yet, should get fixed properly later */
8572: decl = make_type_decl (declarator, type);
8573: #else
8574: decl = build_decl (TYPE_DECL, declarator, type);
8575: #endif
8576: if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
8577: {
8578: cp_error_at ("typedef name may not be class-qualified", decl);
8579: return NULL_TREE;
8580: }
8581: else if (quals)
8582: {
8583: if (ctype == NULL_TREE)
8584: {
8585: if (TREE_CODE (type) != METHOD_TYPE)
8586: cp_error_at ("invalid type qualifier for non-method type", decl);
8587: else
8588: ctype = TYPE_METHOD_BASETYPE (type);
8589: }
8590: if (ctype != NULL_TREE)
8591: grok_method_quals (ctype, decl, quals);
8592: }
8593:
8594: if (RIDBIT_SETP (RID_SIGNED, specbits)
8595: || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
8596: C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
8597:
8598: if (RIDBIT_SETP (RID_MUTABLE, specbits))
8599: {
8600: error ("non-object member `%s' cannot be declared mutable", name);
8601: }
8602:
8603: return decl;
8604: }
8605:
8606: /* Detect the case of an array type of unspecified size
8607: which came, as such, direct from a typedef name.
8608: We must copy the type, so that each identifier gets
8609: a distinct type, so that each identifier's size can be
8610: controlled separately by its own initializer. */
8611:
8612: if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
8613: && TYPE_DOMAIN (type) == NULL_TREE)
8614: {
8615: type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
8616: }
8617:
8618: /* If this is a type name (such as, in a cast or sizeof),
8619: compute the type and return it now. */
8620:
8621: if (decl_context == TYPENAME)
8622: {
8623: /* Note that the grammar rejects storage classes
8624: in typenames, fields or parameters. */
8625: if (constp || volatilep)
8626: if (IS_SIGNATURE (type))
8627: error ("`const' or `volatile' specified with signature type");
8628: else
8629: type = cp_build_type_variant (type, constp, volatilep);
8630:
8631: /* Special case: "friend class foo" looks like a TYPENAME context. */
8632: if (friendp)
8633: {
8634: /* A friendly class? */
8635: if (current_class_type)
8636: make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
8637: else
8638: error("trying to make class `%s' a friend of global scope",
8639: TYPE_NAME_STRING (type));
8640: type = void_type_node;
8641: }
8642: else if (quals)
8643: {
8644: #if 0 /* not yet, should get fixed properly later */
8645: tree dummy = make_type_decl (declarator, type);
8646: #else
8647: tree dummy = build_decl (TYPE_DECL, declarator, type);
8648: #endif
8649: if (ctype == NULL_TREE)
8650: {
8651: my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
8652: ctype = TYPE_METHOD_BASETYPE (type);
8653: }
8654: grok_method_quals (ctype, dummy, quals);
8655: type = TREE_TYPE (dummy);
8656: }
8657:
8658: return type;
8659: }
8660: else if (declarator == NULL_TREE && decl_context != PARM
8661: && TREE_CODE (type) != UNION_TYPE
8662: && ! bitfield)
8663: {
8664: cp_error ("abstract declarator `%T' used as declaration", type);
8665: declarator = make_anon_name ();
8666: }
8667:
8668: /* `void' at top level (not within pointer)
8669: is allowed only in typedefs or type names.
8670: We don't complain about parms either, but that is because
8671: a better error message can be made later. */
8672:
8673: if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
8674: {
8675: if (TREE_CODE (declarator) == IDENTIFIER_NODE)
8676: {
8677: if (IDENTIFIER_OPNAME_P (declarator))
8678: #if 0 /* How could this happen? */
8679: error ("operator `%s' declared void",
8680: operator_name_string (declarator));
8681: #else
8682: my_friendly_abort (356);
8683: #endif
8684: else
8685: error ("variable or field `%s' declared void", name);
8686: }
8687: else
8688: error ("variable or field declared void");
8689: type = integer_type_node;
8690: }
8691:
8692: /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
8693: or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
8694:
8695: {
8696: register tree decl;
8697:
8698: if (decl_context == PARM)
8699: {
8700: if (ctype)
8701: error ("cannot use `::' in parameter declaration");
8702:
8703: /* A parameter declared as an array of T is really a pointer to T.
8704: One declared as a function is really a pointer to a function.
8705: One declared as a member is really a pointer to member. */
8706:
8707: if (TREE_CODE (type) == ARRAY_TYPE)
8708: {
8709: /* Transfer const-ness of array into that of type pointed to. */
8710: type = build_pointer_type
8711: (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
8712: volatilep = constp = 0;
8713: }
8714: else if (TREE_CODE (type) == FUNCTION_TYPE)
8715: type = build_pointer_type (type);
8716: else if (TREE_CODE (type) == OFFSET_TYPE)
8717: type = build_pointer_type (type);
8718:
8719: decl = build_decl (PARM_DECL, declarator, type);
8720:
8721: bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
8722: inlinep, friendp, raises != NULL_TREE);
8723: if (current_class_type
8724: && IS_SIGNATURE (current_class_type))
8725: {
8726: if (inlinep)
8727: error ("parameter of signature member function declared `inline'");
8728: if (RIDBIT_SETP (RID_AUTO, specbits))
8729: error ("parameter of signature member function declared `auto'");
8730: if (RIDBIT_SETP (RID_REGISTER, specbits))
8731: error ("parameter of signature member function declared `register'");
8732: }
8733:
8734: /* Compute the type actually passed in the parmlist,
8735: for the case where there is no prototype.
8736: (For example, shorts and chars are passed as ints.)
8737: When there is a prototype, this is overridden later. */
8738:
8739: DECL_ARG_TYPE (decl) = type_promotes_to (type);
8740: }
8741: else if (decl_context == FIELD)
8742: {
8743: if (type == error_mark_node)
8744: {
8745: /* Happens when declaring arrays of sizes which
8746: are error_mark_node, for example. */
8747: decl = NULL_TREE;
8748: }
8749: else if (TREE_CODE (type) == FUNCTION_TYPE)
8750: {
8751: int publicp = 0;
8752:
8753: if (friendp == 0)
8754: {
8755: if (ctype == NULL_TREE)
8756: ctype = current_class_type;
8757:
8758: if (ctype == NULL_TREE)
8759: {
8760: cp_error ("can't make `%D' into a method -- not in a class",
8761: declarator);
8762: return void_type_node;
8763: }
8764:
8765: /* ``A union may [ ... ] not [ have ] virtual functions.''
8766: ARM 9.5 */
8767: if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
8768: {
8769: cp_error ("function `%D' declared virtual inside a union",
8770: declarator);
8771: return void_type_node;
8772: }
8773:
8774: if (declarator == ansi_opname[(int) NEW_EXPR]
8775: || declarator == ansi_opname[(int) VEC_NEW_EXPR]
8776: || declarator == ansi_opname[(int) DELETE_EXPR]
8777: || declarator == ansi_opname[(int) VEC_DELETE_EXPR])
8778: {
8779: if (virtualp)
8780: {
8781: cp_error ("`%D' cannot be declared virtual, since it is always static",
8782: declarator);
8783: virtualp = 0;
8784: }
8785: }
8786: else if (staticp < 2)
8787: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8788: TREE_TYPE (type), TYPE_ARG_TYPES (type));
8789: }
8790:
8791: /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
8792: publicp = (RIDBIT_SETP (RID_EXTERN, specbits)
8793: || (ctype != NULL_TREE
8794: && funcdef_flag >= 0
8795: && RIDBIT_NOTSETP (RID_INLINE, specbits))
8796: || (friendp
8797: && ! funcdef_flag
8798: && RIDBIT_NOTSETP (RID_STATIC, specbits)
8799: && RIDBIT_NOTSETP (RID_INLINE, specbits)));
8800: decl = grokfndecl (ctype, type, declarator,
8801: virtualp, flags, quals,
8802: raises, friendp ? -1 : 0, publicp);
8803: if (decl == NULL_TREE)
8804: return NULL_TREE;
8805:
8806: DECL_INLINE (decl) = inlinep;
8807: }
8808: else if (TREE_CODE (type) == METHOD_TYPE)
8809: {
8810: /* All method decls are public, so tell grokfndecl to set
8811: TREE_PUBLIC, also. */
8812: decl = grokfndecl (ctype, type, declarator,
8813: virtualp, flags, quals,
8814: raises, friendp ? -1 : 0, 1);
8815: if (decl == NULL_TREE)
8816: return NULL_TREE;
8817:
8818: DECL_INLINE (decl) = inlinep;
8819: }
8820: else if (TREE_CODE (type) == RECORD_TYPE
8821: && CLASSTYPE_DECLARED_EXCEPTION (type))
8822: {
8823: /* Handle a class-local exception declaration. */
8824: decl = build_lang_field_decl (VAR_DECL, declarator, type);
8825: if (ctype == NULL_TREE)
8826: ctype = current_class_type;
8827: return void_type_node;
8828: }
8829: else if (TYPE_SIZE (type) == NULL_TREE && !staticp
8830: && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
8831: {
8832: error ("field `%s' has incomplete type",
8833: IDENTIFIER_POINTER (declarator));
8834:
8835: /* If we're instantiating a template, tell them which
8836: instantiation made the field's type be incomplete. */
8837: if (current_class_type
8838: && TYPE_NAME (current_class_type)
8839: && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
8840: && declspecs && TREE_VALUE (declspecs)
8841: && TREE_TYPE (TREE_VALUE (declspecs)) == type)
8842: error (" in instantiation of template `%s'",
8843: TYPE_NAME_STRING (current_class_type));
8844:
8845: type = error_mark_node;
8846: decl = NULL_TREE;
8847: }
8848: else
8849: {
8850: if (friendp)
8851: {
8852: error ("`%s' is neither function nor method; cannot be declared friend",
8853: IDENTIFIER_POINTER (declarator));
8854: friendp = 0;
8855: }
8856: decl = NULL_TREE;
8857: }
8858:
8859: if (friendp)
8860: {
8861: /* Friends are treated specially. */
8862: if (ctype == current_class_type)
8863: warning ("member functions are implicitly friends of their class");
8864: else
8865: {
8866: tree t = NULL_TREE;
8867: if (decl && DECL_NAME (decl))
8868: t = do_friend (ctype, declarator, decl,
8869: last_function_parms, flags, quals);
8870: if (t && funcdef_flag)
8871: return t;
8872:
8873: return void_type_node;
8874: }
8875: }
8876:
8877: /* Structure field. It may not be a function, except for C++ */
8878:
8879: if (decl == NULL_TREE)
8880: {
8881: if (initialized)
8882: {
8883: /* Motion 10 at San Diego: If a static const integral data
8884: member is initialized with an integral constant
8885: expression, the initializer may appear either in the
8886: declaration (within the class), or in the definition,
8887: but not both. If it appears in the class, the member is
8888: a member constant. The file-scope definition is always
8889: required. */
8890: if (staticp)
8891: {
8892: if (pedantic)
8893: {
8894: if (! constp)
8895: cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
8896: declarator);
8897:
8898: else if (! INTEGRAL_TYPE_P (type))
8899: cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type);
8900: }
8901: }
8902:
8903: /* Note that initialization of const members is prohibited
8904: by the draft ANSI standard, though it appears to be in
8905: common practice. 12.6.2: The argument list is used to
8906: initialize the named nonstatic member.... This (or an
8907: initializer list) is the only way to initialize
8908: nonstatic const and reference members. */
8909: else if (flag_ansi || ! constp)
8910: cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
8911: constp ? "const member" : "member", declarator);
8912: }
8913:
8914: if (staticp || (constp && initialized))
8915: {
8916: /* C++ allows static class members.
8917: All other work for this is done by grokfield.
8918: This VAR_DECL is built by build_lang_field_decl.
8919: All other VAR_DECLs are built by build_decl. */
8920: decl = build_lang_field_decl (VAR_DECL, declarator, type);
8921: TREE_STATIC (decl) = 1;
8922: /* In class context, 'static' means public access. */
8923: TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp;
8924: }
8925: else
8926: {
8927: decl = build_lang_field_decl (FIELD_DECL, declarator, type);
8928: if (RIDBIT_SETP (RID_MUTABLE, specbits))
8929: {
8930: DECL_MUTABLE_P (decl) = 1;
8931: RIDBIT_RESET (RID_MUTABLE, specbits);
8932: }
8933: }
8934:
8935: bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
8936: inlinep, friendp, raises != NULL_TREE);
8937: }
8938: }
8939: else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
8940: {
8941: tree original_name = declarator;
8942: int publicp = 0;
8943:
8944: if (! declarator)
8945: return NULL_TREE;
8946:
8947: if (RIDBIT_SETP (RID_AUTO, specbits))
8948: error ("storage class `auto' invalid for function `%s'", name);
8949: else if (RIDBIT_SETP (RID_REGISTER, specbits))
8950: error ("storage class `register' invalid for function `%s'", name);
8951:
8952: /* Function declaration not at top level.
8953: Storage classes other than `extern' are not allowed
8954: and `extern' makes no difference. */
8955: if (current_binding_level != global_binding_level
8956: && ! processing_template_decl
8957: && (RIDBIT_SETP (RID_STATIC, specbits)
8958: || RIDBIT_SETP (RID_INLINE, specbits))
8959: && pedantic)
8960: {
8961: if (RIDBIT_SETP (RID_STATIC, specbits))
8962: pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
8963: else
8964: pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
8965: }
8966:
8967: if (ctype == NULL_TREE)
8968: {
8969: if (virtualp)
8970: {
8971: error ("virtual non-class function `%s'", name);
8972: virtualp = 0;
8973: }
8974:
8975: if (current_lang_name == lang_name_cplusplus
8976: && ! (IDENTIFIER_LENGTH (original_name) == 4
8977: && IDENTIFIER_POINTER (original_name)[0] == 'm'
8978: && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
8979: && ! (IDENTIFIER_LENGTH (original_name) > 10
8980: && IDENTIFIER_POINTER (original_name)[0] == '_'
8981: && IDENTIFIER_POINTER (original_name)[1] == '_'
8982: && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
8983: /* Plain overloading: will not be grok'd by grokclassfn. */
8984: declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
8985: }
8986: else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
8987: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8988: TREE_TYPE (type), TYPE_ARG_TYPES (type));
8989:
8990: /* Record presence of `static'. In C++, `inline' is like `static'. */
8991: publicp
8992: = !(RIDBIT_SETP (RID_STATIC, specbits)
8993: || RIDBIT_SETP (RID_INLINE, specbits));
8994:
8995: decl = grokfndecl (ctype, type, original_name,
8996: virtualp, flags, quals,
8997: raises,
8998: processing_template_decl ? 0 : friendp ? 2 : 1,
8999: publicp);
9000: if (decl == NULL_TREE)
9001: return NULL_TREE;
9002:
9003: if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
9004: DECL_ASSEMBLER_NAME (decl) = declarator;
9005:
9006: if (staticp == 1)
9007: {
9008: int illegal_static = 0;
9009:
9010: /* Don't allow a static member function in a class, and forbid
9011: declaring main to be static. */
9012: if (TREE_CODE (type) == METHOD_TYPE)
9013: {
9014: cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl);
9015: illegal_static = 1;
9016: }
9017: else if (! ctype
9018: && IDENTIFIER_LENGTH (original_name) == 4
9019: && IDENTIFIER_POINTER (original_name)[0] == 'm'
9020: && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
9021: {
9022: error ("cannot declare function `main' to have static linkage");
9023: illegal_static = 1;
9024: }
9025: else if (current_function_decl)
9026: {
9027: /* FIXME need arm citation */
9028: error ("cannot declare static function inside another function");
9029: illegal_static = 1;
9030: }
9031:
9032: if (illegal_static)
9033: {
9034: staticp = 0;
9035: RIDBIT_RESET (RID_STATIC, specbits);
9036: }
9037: }
9038:
9039: /* Record presence of `inline', if it is reasonable. */
9040: if (inlinep)
9041: {
9042: tree last = tree_last (TYPE_ARG_TYPES (type));
9043:
9044: if (! ctype
9045: && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
9046: error ("cannot inline function `main'");
9047: else if (last && last != void_list_node)
9048: cp_warning ("cannot inline function `%D' which takes `...'", original_name);
9049: else
9050: /* Assume that otherwise the function can be inlined. */
9051: DECL_INLINE (decl) = 1;
9052:
9053: if (RIDBIT_SETP (RID_EXTERN, specbits))
9054: {
9055: current_extern_inline = 1;
9056: if (flag_ansi)
9057: pedwarn ("ANSI C++ does not permit `extern inline'");
9058: }
9059: }
9060: }
9061: else
9062: {
9063: /* It's a variable. */
9064:
9065: /* An uninitialized decl with `extern' is a reference. */
9066: decl = grokvardecl (type, declarator, specbits, initialized);
9067: bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
9068: inlinep, friendp, raises != NULL_TREE);
9069:
9070: if (ctype)
9071: {
9072: DECL_CONTEXT (decl) = ctype;
9073: if (staticp == 1)
9074: {
9075: cp_error ("static member `%D' re-declared as static",
9076: decl);
9077: staticp = 0;
9078: RIDBIT_RESET (RID_STATIC, specbits);
9079: }
9080: if (RIDBIT_SETP (RID_EXTERN, specbits))
9081: {
9082: cp_error ("cannot explicitly declare member `%#D' to have extern linkage",
9083: decl);
9084: RIDBIT_RESET (RID_EXTERN, specbits);
9085: }
9086: }
9087: }
9088:
9089: if (RIDBIT_SETP (RID_MUTABLE, specbits))
9090: {
9091: error ("`%s' cannot be declared mutable", name);
9092: }
9093:
9094: /* Record `register' declaration for warnings on &
9095: and in case doing stupid register allocation. */
9096:
9097: if (RIDBIT_SETP (RID_REGISTER, specbits))
9098: DECL_REGISTER (decl) = 1;
9099:
9100: if (RIDBIT_SETP (RID_EXTERN, specbits))
9101: DECL_THIS_EXTERN (decl) = 1;
9102:
9103: /* Record constancy and volatility. */
9104:
9105: if (constp)
9106: TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
9107: if (volatilep)
9108: {
9109: TREE_SIDE_EFFECTS (decl) = 1;
9110: TREE_THIS_VOLATILE (decl) = 1;
9111: }
9112:
9113: return decl;
9114: }
9115: }
9116:
9117: /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
9118: An empty exprlist is a parmlist. An exprlist which
9119: contains only identifiers at the global level
9120: is a parmlist. Otherwise, it is an exprlist. */
9121: int
9122: parmlist_is_exprlist (exprs)
9123: tree exprs;
9124: {
9125: if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
9126: return 0;
9127:
9128: if (current_binding_level == global_binding_level)
9129: {
9130: /* At the global level, if these are all identifiers,
9131: then it is a parmlist. */
9132: while (exprs)
9133: {
9134: if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
9135: return 1;
9136: exprs = TREE_CHAIN (exprs);
9137: }
9138: return 0;
9139: }
9140: return 1;
9141: }
9142:
9143: /* Subroutine of `grokparms'. In a fcn definition, arg types must
9144: be complete.
9145:
9146: C++: also subroutine of `start_function'. */
9147: static void
9148: require_complete_types_for_parms (parms)
9149: tree parms;
9150: {
9151: while (parms)
9152: {
9153: tree type = TREE_TYPE (parms);
9154: if (TYPE_SIZE (type) == NULL_TREE)
9155: {
9156: if (DECL_NAME (parms))
9157: error ("parameter `%s' has incomplete type",
9158: IDENTIFIER_POINTER (DECL_NAME (parms)));
9159: else
9160: error ("parameter has incomplete type");
9161: TREE_TYPE (parms) = error_mark_node;
9162: }
9163: #if 0
9164: /* If the arg types are incomplete in a declaration,
9165: they must include undefined tags.
9166: These tags can never be defined in the scope of the declaration,
9167: so the types can never be completed,
9168: and no call can be compiled successfully. */
9169: /* This is not the right behavior for C++, but not having
9170: it is also probably wrong. */
9171: else
9172: {
9173: /* Now warn if is a pointer to an incomplete type. */
9174: while (TREE_CODE (type) == POINTER_TYPE
9175: || TREE_CODE (type) == REFERENCE_TYPE)
9176: type = TREE_TYPE (type);
9177: type = TYPE_MAIN_VARIANT (type);
9178: if (TYPE_SIZE (type) == NULL_TREE)
9179: {
9180: if (DECL_NAME (parm) != NULL_TREE)
9181: warning ("parameter `%s' points to incomplete type",
9182: IDENTIFIER_POINTER (DECL_NAME (parm)));
9183: else
9184: warning ("parameter points to incomplete type");
9185: }
9186: }
9187: #endif
9188: parms = TREE_CHAIN (parms);
9189: }
9190: }
9191:
9192: /* Decode the list of parameter types for a function type.
9193: Given the list of things declared inside the parens,
9194: return a list of types.
9195:
9196: The list we receive can have three kinds of elements:
9197: an IDENTIFIER_NODE for names given without types,
9198: a TREE_LIST node for arguments given as typespecs or names with typespecs,
9199: or void_type_node, to mark the end of an argument list
9200: when additional arguments are not permitted (... was not used).
9201:
9202: FUNCDEF_FLAG is nonzero for a function definition, 0 for
9203: a mere declaration. A nonempty identifier-list gets an error message
9204: when FUNCDEF_FLAG is zero.
9205: If FUNCDEF_FLAG is 1, then parameter types must be complete.
9206: If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9207:
9208: If all elements of the input list contain types,
9209: we return a list of the types.
9210: If all elements contain no type (except perhaps a void_type_node
9211: at the end), we return a null list.
9212: If some have types and some do not, it is an error, and we
9213: return a null list.
9214:
9215: Also set last_function_parms to either
9216: a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9217: A list of names is converted to a chain of PARM_DECLs
9218: by store_parm_decls so that ultimately it is always a chain of decls.
9219:
9220: Note that in C++, parameters can take default values. These default
9221: values are in the TREE_PURPOSE field of the TREE_LIST. It is
9222: an error to specify default values which are followed by parameters
9223: that have no default values, or an ELLIPSES. For simplicities sake,
9224: only parameters which are specified with their types can take on
9225: default values. */
9226:
9227: static tree
9228: grokparms (first_parm, funcdef_flag)
9229: tree first_parm;
9230: int funcdef_flag;
9231: {
9232: tree result = NULL_TREE;
9233: tree decls = NULL_TREE;
9234:
9235: if (first_parm != NULL_TREE
9236: && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
9237: {
9238: if (! funcdef_flag)
9239: pedwarn ("parameter names (without types) in function declaration");
9240: last_function_parms = first_parm;
9241: return NULL_TREE;
9242: }
9243: else if (first_parm != NULL_TREE
9244: && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
9245: && TREE_VALUE (first_parm) != void_type_node)
9246: my_friendly_abort (145);
9247: else
9248: {
9249: /* Types were specified. This is a list of declarators
9250: each represented as a TREE_LIST node. */
9251: register tree parm, chain;
9252: int any_init = 0, any_error = 0, saw_void = 0;
9253:
9254: if (first_parm != NULL_TREE)
9255: {
9256: tree last_result = NULL_TREE;
9257: tree last_decl = NULL_TREE;
9258:
9259: for (parm = first_parm; parm != NULL_TREE; parm = chain)
9260: {
9261: tree type, list_node = parm;
9262: register tree decl = TREE_VALUE (parm);
9263: tree init = TREE_PURPOSE (parm);
9264:
9265: chain = TREE_CHAIN (parm);
9266: /* @@ weak defense against parse errors. */
9267: if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
9268: {
9269: /* Give various messages as the need arises. */
9270: if (TREE_CODE (decl) == STRING_CST)
9271: error ("invalid string constant `%s'",
9272: TREE_STRING_POINTER (decl));
9273: else if (TREE_CODE (decl) == INTEGER_CST)
9274: error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9275: continue;
9276: }
9277:
9278: if (decl != void_type_node)
9279: {
9280: /* @@ May need to fetch out a `raises' here. */
9281: decl = grokdeclarator (TREE_VALUE (decl),
9282: TREE_PURPOSE (decl),
9283: PARM, init != NULL_TREE, NULL_TREE);
9284: if (! decl)
9285: continue;
9286: type = TREE_TYPE (decl);
9287: if (TYPE_MAIN_VARIANT (type) == void_type_node)
9288: decl = void_type_node;
9289: else if (TREE_CODE (type) == METHOD_TYPE)
9290: {
9291: if (DECL_NAME (decl))
9292: /* Cannot use `error_with_decl' here because
9293: we don't have DECL_CONTEXT set up yet. */
9294: error ("parameter `%s' invalidly declared method type",
9295: IDENTIFIER_POINTER (DECL_NAME (decl)));
9296: else
9297: error ("parameter invalidly declared method type");
9298: type = build_pointer_type (type);
9299: TREE_TYPE (decl) = type;
9300: }
9301: else if (TREE_CODE (type) == OFFSET_TYPE)
9302: {
9303: if (DECL_NAME (decl))
9304: error ("parameter `%s' invalidly declared offset type",
9305: IDENTIFIER_POINTER (DECL_NAME (decl)));
9306: else
9307: error ("parameter invalidly declared offset type");
9308: type = build_pointer_type (type);
9309: TREE_TYPE (decl) = type;
9310: }
9311: else if (TREE_CODE (type) == RECORD_TYPE
9312: && TYPE_LANG_SPECIFIC (type)
9313: && CLASSTYPE_ABSTRACT_VIRTUALS (type))
9314: {
9315: abstract_virtuals_error (decl, type);
9316: any_error = 1; /* seems like a good idea */
9317: }
9318: else if (TREE_CODE (type) == RECORD_TYPE
9319: && TYPE_LANG_SPECIFIC (type)
9320: && IS_SIGNATURE (type))
9321: {
9322: signature_error (decl, type);
9323: any_error = 1; /* seems like a good idea */
9324: }
9325: }
9326:
9327: if (decl == void_type_node)
9328: {
9329: if (result == NULL_TREE)
9330: {
9331: result = void_list_node;
9332: last_result = result;
9333: }
9334: else
9335: {
9336: TREE_CHAIN (last_result) = void_list_node;
9337: last_result = void_list_node;
9338: }
9339: saw_void = 1;
9340: if (chain
9341: && (chain != void_list_node || TREE_CHAIN (chain)))
9342: error ("`void' in parameter list must be entire list");
9343: break;
9344: }
9345:
9346: /* Since there is a prototype, args are passed in their own types. */
9347: DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
9348: #ifdef PROMOTE_PROTOTYPES
9349: if ((TREE_CODE (type) == INTEGER_TYPE
9350: || TREE_CODE (type) == ENUMERAL_TYPE)
9351: && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
9352: DECL_ARG_TYPE (decl) = integer_type_node;
9353: #endif
9354: if (!any_error)
9355: {
9356: if (init)
9357: {
9358: any_init++;
9359: if (TREE_CODE (init) == SAVE_EXPR)
9360: PARM_DECL_EXPR (init) = 1;
9361: else if (TREE_CODE (init) == VAR_DECL)
9362: {
9363: if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
9364: {
9365: /* ``Local variables may not be used in default
9366: argument expressions.'' dpANSI C++ 8.2.6 */
9367: /* If extern int i; within a function is not
9368: considered a local variable, then this code is
9369: wrong. */
9370: cp_error ("local variable `%D' may not be used as a default argument", init);
9371: any_error = 1;
9372: }
9373: else if (TREE_READONLY_DECL_P (init))
9374: init = decl_constant_value (init);
9375: }
9376: else
9377: init = require_instantiated_type (type, init, integer_zero_node);
9378: }
9379: else if (any_init)
9380: {
9381: error ("all trailing parameters must have default arguments");
9382: any_error = 1;
9383: }
9384: }
9385: else
9386: init = NULL_TREE;
9387:
9388: if (decls == NULL_TREE)
9389: {
9390: decls = decl;
9391: last_decl = decls;
9392: }
9393: else
9394: {
9395: TREE_CHAIN (last_decl) = decl;
9396: last_decl = decl;
9397: }
9398: if (TREE_PERMANENT (list_node))
9399: {
9400: TREE_PURPOSE (list_node) = init;
9401: TREE_VALUE (list_node) = type;
9402: TREE_CHAIN (list_node) = NULL_TREE;
9403: }
9404: else
9405: list_node = saveable_tree_cons (init, type, NULL_TREE);
9406: if (result == NULL_TREE)
9407: {
9408: result = list_node;
9409: last_result = result;
9410: }
9411: else
9412: {
9413: TREE_CHAIN (last_result) = list_node;
9414: last_result = list_node;
9415: }
9416: }
9417: if (last_result)
9418: TREE_CHAIN (last_result) = NULL_TREE;
9419: /* If there are no parameters, and the function does not end
9420: with `...', then last_decl will be NULL_TREE. */
9421: if (last_decl != NULL_TREE)
9422: TREE_CHAIN (last_decl) = NULL_TREE;
9423: }
9424: }
9425:
9426: last_function_parms = decls;
9427:
9428: /* In a fcn definition, arg types must be complete. */
9429: if (funcdef_flag > 0)
9430: require_complete_types_for_parms (last_function_parms);
9431:
9432: return result;
9433: }
9434:
9435: /* These memoizing functions keep track of special properties which
9436: a class may have. `grok_ctor_properties' notices whether a class
9437: has a constructor of the form X(X&), and also complains
9438: if the class has a constructor of the form X(X).
9439: `grok_op_properties' takes notice of the various forms of
9440: operator= which are defined, as well as what sorts of type conversion
9441: may apply. Both functions take a FUNCTION_DECL as an argument. */
9442: int
9443: grok_ctor_properties (ctype, decl)
9444: tree ctype, decl;
9445: {
9446: tree parmtypes = FUNCTION_ARG_CHAIN (decl);
9447: tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
9448:
9449: /* When a type has virtual baseclasses, a magical first int argument is
9450: added to any ctor so we can tell if the class has been initialized
9451: yet. This could screw things up in this function, so we deliberately
9452: ignore the leading int if we're in that situation. */
9453: if (parmtypes
9454: && TREE_VALUE (parmtypes) == integer_type_node
9455: && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
9456: {
9457: parmtypes = TREE_CHAIN (parmtypes);
9458: parmtype = TREE_VALUE (parmtypes);
9459: }
9460:
9461: if (TREE_CODE (parmtype) == REFERENCE_TYPE
9462: && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
9463: {
9464: if (TREE_CHAIN (parmtypes) == NULL_TREE
9465: || TREE_CHAIN (parmtypes) == void_list_node
9466: || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
9467: {
9468: TYPE_HAS_INIT_REF (ctype) = 1;
9469: if (TYPE_READONLY (TREE_TYPE (parmtype)))
9470: TYPE_HAS_CONST_INIT_REF (ctype) = 1;
9471: }
9472: else
9473: TYPE_GETS_INIT_AGGR (ctype) = 1;
9474: }
9475: else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
9476: {
9477: if (TREE_CHAIN (parmtypes) != NULL_TREE
9478: && TREE_CHAIN (parmtypes) == void_list_node)
9479: {
9480: cp_error ("invalid constructor; you probably meant `%T (%T&)'",
9481: ctype, ctype);
9482: SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
9483:
9484: return 0;
9485: }
9486: else
9487: TYPE_GETS_INIT_AGGR (ctype) = 1;
9488: }
9489: else if (TREE_CODE (parmtype) == VOID_TYPE
9490: || TREE_PURPOSE (parmtypes) != NULL_TREE)
9491: TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
9492:
9493: return 1;
9494: }
9495:
9496: /* An operator with this name can be either unary or binary. */
9497: static int
9498: ambi_op_p (name)
9499: tree name;
9500: {
9501: return (name == ansi_opname [(int) INDIRECT_REF]
9502: || name == ansi_opname [(int) ADDR_EXPR]
9503: || name == ansi_opname [(int) NEGATE_EXPR]
9504: || name == ansi_opname[(int) POSTINCREMENT_EXPR]
9505: || name == ansi_opname[(int) POSTDECREMENT_EXPR]
9506: || name == ansi_opname [(int) CONVERT_EXPR]);
9507: }
9508:
9509: /* An operator with this name can only be unary. */
9510: static int
9511: unary_op_p (name)
9512: tree name;
9513: {
9514: return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
9515: || name == ansi_opname [(int) BIT_NOT_EXPR]
9516: || name == ansi_opname [(int) COMPONENT_REF]
9517: || OPERATOR_TYPENAME_P (name));
9518: }
9519:
9520: /* Do a little sanity-checking on how they declared their operator. */
9521: static void
9522: grok_op_properties (decl, virtualp, friendp)
9523: tree decl;
9524: int virtualp, friendp;
9525: {
9526: tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
9527: int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
9528: tree name = DECL_NAME (decl);
9529:
9530: if (current_class_type == NULL_TREE)
9531: friendp = 1;
9532:
9533: if (! friendp)
9534: {
9535: if (name == ansi_opname[(int) MODIFY_EXPR])
9536: TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
9537: else if (name == ansi_opname[(int) CALL_EXPR])
9538: TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
9539: else if (name == ansi_opname[(int) ARRAY_REF])
9540: TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
9541: else if (name == ansi_opname[(int) COMPONENT_REF]
9542: || name == ansi_opname[(int) MEMBER_REF])
9543: TYPE_OVERLOADS_ARROW (current_class_type) = 1;
9544: else if (name == ansi_opname[(int) NEW_EXPR])
9545: TYPE_GETS_NEW (current_class_type) |= 1;
9546: else if (name == ansi_opname[(int) DELETE_EXPR])
9547: TYPE_GETS_DELETE (current_class_type) |= 1;
9548: else if (name == ansi_opname[(int) VEC_NEW_EXPR])
9549: TYPE_GETS_NEW (current_class_type) |= 2;
9550: else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
9551: TYPE_GETS_DELETE (current_class_type) |= 2;
9552: }
9553:
9554: if (name == ansi_opname[(int) NEW_EXPR]
9555: || name == ansi_opname[(int) VEC_NEW_EXPR])
9556: {
9557: /* When the compiler encounters the definition of A::operator new, it
9558: doesn't look at the class declaration to find out if it's static. */
9559: if (methodp)
9560: revert_static_member_fn (&decl, NULL, NULL);
9561:
9562: /* Take care of function decl if we had syntax errors. */
9563: if (argtypes == NULL_TREE)
9564: TREE_TYPE (decl) =
9565: build_function_type (ptr_type_node,
9566: hash_tree_chain (integer_type_node,
9567: void_list_node));
9568: else
9569: TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
9570: }
9571: else if (name == ansi_opname[(int) DELETE_EXPR]
9572: || name == ansi_opname[(int) VEC_DELETE_EXPR])
9573: {
9574: if (methodp)
9575: revert_static_member_fn (&decl, NULL, NULL);
9576:
9577: if (argtypes == NULL_TREE)
9578: TREE_TYPE (decl) =
9579: build_function_type (void_type_node,
9580: hash_tree_chain (ptr_type_node,
9581: void_list_node));
9582: else
9583: {
9584: TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
9585:
9586: if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR]
9587: && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
9588: != void_list_node))
9589: TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1;
9590: }
9591: }
9592: else
9593: {
9594: /* An operator function must either be a non-static member function
9595: or have at least one parameter of a class, a reference to a class,
9596: an enumeration, or a reference to an enumeration. 13.4.0.6 */
9597: if (! methodp || DECL_STATIC_FUNCTION_P (decl))
9598: {
9599: if (OPERATOR_TYPENAME_P (name)
9600: || name == ansi_opname[(int) CALL_EXPR]
9601: || name == ansi_opname[(int) MODIFY_EXPR]
9602: || name == ansi_opname[(int) COMPONENT_REF]
9603: || name == ansi_opname[(int) ARRAY_REF])
9604: cp_error ("`%D' must be a nonstatic member function", decl);
9605: else
9606: {
9607: tree p = argtypes;
9608:
9609: if (DECL_STATIC_FUNCTION_P (decl))
9610: cp_error ("`%D' must be either a non-static member function or a non-member function", decl);
9611:
9612: if (p)
9613: for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
9614: {
9615: tree arg = TREE_VALUE (p);
9616: if (TREE_CODE (arg) == REFERENCE_TYPE)
9617: arg = TREE_TYPE (arg);
9618:
9619: /* This lets bad template code slip through. */
9620: if (IS_AGGR_TYPE (arg)
9621: || TREE_CODE (arg) == ENUMERAL_TYPE
9622: || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
9623: goto foundaggr;
9624: }
9625: cp_error
9626: ("`%D' must have an argument of class or enumerated type",
9627: decl);
9628: foundaggr:
9629: ;
9630: }
9631: }
9632:
9633: if (name == ansi_opname[(int) CALL_EXPR]
9634: || name == ansi_opname[(int) METHOD_CALL_EXPR])
9635: return; /* no restrictions on args */
9636:
9637: if (IDENTIFIER_TYPENAME_P (name))
9638: {
9639: tree t = TREE_TYPE (name);
9640: if (TREE_CODE (t) == VOID_TYPE)
9641: pedwarn ("void is not a valid type conversion operator");
9642: else if (! friendp)
9643: {
9644: int ref = (TREE_CODE (t) == REFERENCE_TYPE);
9645: char *what = 0;
9646: if (ref)
9647: t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9648:
9649: if (t == current_class_type)
9650: what = "the same type";
9651: else if (IS_AGGR_TYPE (t)
9652: && DERIVED_FROM_P (t, current_class_type))
9653: what = "a base class";
9654:
9655: if (what)
9656: warning ("conversion to %s%s will never use a type conversion operator",
9657: ref ? "a reference to " : "", what);
9658: }
9659: }
9660:
9661: if (name == ansi_opname[(int) MODIFY_EXPR])
9662: {
9663: tree parmtype;
9664:
9665: if (list_length (argtypes) != 3 && methodp)
9666: {
9667: cp_error ("`%D' must take exactly one argument", decl);
9668: return;
9669: }
9670: parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
9671:
9672: if (copy_assignment_arg_p (parmtype, virtualp)
9673: && ! friendp)
9674: {
9675: TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
9676: if (TREE_CODE (parmtype) != REFERENCE_TYPE
9677: || TYPE_READONLY (TREE_TYPE (parmtype)))
9678: TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
9679: #if 0 /* Too soon; done in grok_function_init */
9680: if (DECL_ABSTRACT_VIRTUAL_P (decl))
9681: TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
9682: #endif
9683: }
9684: }
9685: else if (name == ansi_opname[(int) COND_EXPR])
9686: {
9687: /* 13.4.0.3 */
9688: pedwarn ("ANSI C++ prohibits overloading operator ?:");
9689: if (list_length (argtypes) != 4)
9690: cp_error ("`%D' must take exactly three arguments", decl);
9691: }
9692: else if (ambi_op_p (name))
9693: {
9694: if (list_length (argtypes) == 2)
9695: /* prefix */;
9696: else if (list_length (argtypes) == 3)
9697: {
9698: if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
9699: || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9700: && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
9701: {
9702: if (methodp)
9703: cp_error ("postfix `%D' must take `int' as its argument",
9704: decl);
9705: else
9706: cp_error
9707: ("postfix `%D' must take `int' as its second argument",
9708: decl);
9709: }
9710: }
9711: else
9712: {
9713: if (methodp)
9714: cp_error ("`%D' must take either zero or one argument", decl);
9715: else
9716: cp_error ("`%D' must take either one or two arguments", decl);
9717: }
9718: }
9719: else if (unary_op_p (name))
9720: {
9721: if (list_length (argtypes) != 2)
9722: {
9723: if (methodp)
9724: cp_error ("`%D' must take `void'", decl);
9725: else
9726: cp_error ("`%D' must take exactly one argument", decl);
9727: }
9728: }
9729: else /* if (binary_op_p (name)) */
9730: {
9731: if (list_length (argtypes) != 3)
9732: {
9733: if (methodp)
9734: cp_error ("`%D' must take exactly one argument", decl);
9735: else
9736: cp_error ("`%D' must take exactly two arguments", decl);
9737: }
9738: }
9739:
9740: /* 13.4.0.8 */
9741: if (argtypes)
9742: for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
9743: if (TREE_PURPOSE (argtypes))
9744: {
9745: TREE_PURPOSE (argtypes) = NULL_TREE;
9746: if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
9747: || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9748: {
9749: if (pedantic)
9750: cp_pedwarn ("`%D' cannot have default arguments", decl);
9751: }
9752: else
9753: cp_error ("`%D' cannot have default arguments", decl);
9754: }
9755: }
9756: }
9757:
9758: /* Get the struct, enum or union (CODE says which) with tag NAME.
9759: Define the tag as a forward-reference if it is not defined.
9760:
9761: C++: If a class derivation is given, process it here, and report
9762: an error if multiple derivation declarations are not identical.
9763:
9764: If this is a definition, come in through xref_tag and only look in
9765: the current frame for the name (since C++ allows new names in any
9766: scope.) */
9767:
9768: /* avoid rewriting all callers of xref_tag */
9769: static int xref_next_defn = 0;
9770:
9771: tree
9772: xref_defn_tag (code_type_node, name, binfo)
9773: tree code_type_node;
9774: tree name, binfo;
9775: {
9776: tree rv, ncp;
9777: xref_next_defn = 1;
9778:
9779: if (class_binding_level)
9780: {
9781: tree n1;
9782: char *buf;
9783: /* we need to build a new IDENTIFIER_NODE for name which nukes
9784: * the pieces... */
9785: /*
9786: n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
9787: if (n1)
9788: n1 = DECL_NAME (n1);
9789: else
9790: n1 = current_class_name;
9791: */
9792: n1 = TYPE_NAME (current_class_type);
9793: if (n1)
9794: n1 = DECL_NESTED_TYPENAME(n1);
9795: else
9796: n1 = current_class_name;
9797:
9798: buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1)
9799: + IDENTIFIER_LENGTH (name));
9800:
9801: sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1),
9802: IDENTIFIER_POINTER (name));
9803: ncp = get_identifier (buf);
9804: #ifdef SPEW_DEBUG
9805: if (spew_debug)
9806: printf("*** %s ***\n", IDENTIFIER_POINTER (ncp));
9807: #endif
9808: #if 0
9809: IDENTIFIER_LOCAL_VALUE (name) =
9810: build_decl (TYPE_DECL, ncp, NULL_TREE);
9811: #endif
9812: rv = xref_tag (code_type_node, name, binfo, 0);
9813: if (! ANON_AGGRNAME_P (name))
9814: {
9815: register tree type_decl = build_decl (TYPE_DECL, ncp, rv);
9816: SET_DECL_ARTIFICIAL (type_decl);
9817: #ifdef DWARF_DEBUGGING_INFO
9818: /* Mark the TYPE_DECL node created just above as a gratuitous one
9819: so that dwarfout.c will know not to generate a TAG_typedef DIE
9820: for it. */
9821: if (write_symbols == DWARF_DEBUG)
9822: DECL_IGNORED_P (type_decl) = 1;
9823: #endif /* DWARF_DEBUGGING_INFO */
9824: pushdecl_nonclass_level (type_decl);
9825: }
9826: }
9827: else
9828: {
9829: rv = xref_tag (code_type_node, name, binfo, 0);
9830: }
9831: xref_next_defn = 0;
9832: return rv;
9833: }
9834:
9835: tree
9836: xref_tag (code_type_node, name, binfo, globalize)
9837: tree code_type_node;
9838: tree name, binfo;
9839: int globalize;
9840: {
9841: enum tag_types tag_code;
9842: enum tree_code code;
9843: int temp = 0;
9844: int i, len;
9845: register tree ref, t;
9846: struct binding_level *b = inner_binding_level;
9847:
9848: tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
9849: switch (tag_code)
9850: {
9851: case record_type:
9852: case class_type:
9853: case exception_type:
9854: case signature_type:
9855: code = RECORD_TYPE;
9856: len = list_length (binfo);
9857: break;
9858: case union_type:
9859: code = UNION_TYPE;
9860: if (binfo)
9861: {
9862: cp_error ("derived union `%T' invalid", name);
9863: binfo = NULL_TREE;
9864: }
9865: len = 0;
9866: break;
9867: case enum_type:
9868: code = ENUMERAL_TYPE;
9869: break;
9870: default:
9871: my_friendly_abort (18);
9872: }
9873:
9874: /* If a cross reference is requested, look up the type
9875: already defined for this tag and return it. */
9876: t = IDENTIFIER_TYPE_VALUE (name);
9877: if (t && TREE_CODE (t) != code)
9878: t = NULL_TREE;
9879:
9880: if (xref_next_defn)
9881: {
9882: /* If we know we are defining this tag, only look it up in this scope
9883: * and don't try to find it as a type. */
9884: xref_next_defn = 0;
9885: if (t && TYPE_CONTEXT(t))
9886: {
9887: if (TREE_MANGLED (name))
9888: ref = t;
9889: else
9890: ref = lookup_tag (code, name, b, 1);
9891: }
9892: else
9893: ref = lookup_tag (code, name, b, 1);
9894: }
9895: else
9896: {
9897: if (t)
9898: ref = t;
9899: else
9900: ref = lookup_tag (code, name, b, 0);
9901:
9902: if (! ref)
9903: {
9904: /* Try finding it as a type declaration. If that wins, use it. */
9905: ref = lookup_name (name, 1);
9906: if (ref && TREE_CODE (ref) == TYPE_DECL
9907: && TREE_CODE (TREE_TYPE (ref)) == code)
9908: ref = TREE_TYPE (ref);
9909: else
9910: ref = NULL_TREE;
9911: }
9912: }
9913:
9914: push_obstacks_nochange ();
9915:
9916: if (! ref)
9917: {
9918: /* If no such tag is yet defined, create a forward-reference node
9919: and record it as the "definition".
9920: When a real declaration of this type is found,
9921: the forward-reference will be altered into a real type. */
9922:
9923: /* In C++, since these migrate into the global scope, we must
9924: build them on the permanent obstack. */
9925:
9926: temp = allocation_temporary_p ();
9927: if (temp)
9928: end_temporary_allocation ();
9929:
9930: if (code == ENUMERAL_TYPE)
9931: {
9932: ref = make_node (ENUMERAL_TYPE);
9933:
9934: /* Give the type a default layout like unsigned int
9935: to avoid crashing if it does not get defined. */
9936: TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
9937: TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
9938: TREE_UNSIGNED (ref) = 1;
9939: TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
9940: TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
9941: TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
9942:
9943: /* Enable us to recognize when a type is created in class context.
9944: To do nested classes correctly, this should probably be cleared
9945: out when we leave this classes scope. Currently this in only
9946: done in `start_enum'. */
9947:
9948: pushtag (name, ref, globalize);
9949: if (flag_cadillac)
9950: cadillac_start_enum (ref);
9951: }
9952: else if (tag_code == exception_type)
9953: {
9954: ref = make_lang_type (code);
9955: /* Enable us to recognize when an exception type is created in
9956: class context. To do nested classes correctly, this should
9957: probably be cleared out when we leave this class's scope. */
9958: CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
9959: pushtag (name, ref, globalize);
9960: if (flag_cadillac)
9961: cadillac_start_struct (ref);
9962: }
9963: else
9964: {
9965: struct binding_level *old_b = class_binding_level;
9966:
9967: ref = make_lang_type (code);
9968:
9969: if (tag_code == signature_type)
9970: {
9971: SET_SIGNATURE (ref);
9972: /* Since a signature type will be turned into the type
9973: of signature tables, it's not only an interface. */
9974: CLASSTYPE_INTERFACE_ONLY (ref) = 0;
9975: SET_CLASSTYPE_INTERFACE_KNOWN (ref);
9976: /* A signature doesn't have a vtable. */
9977: CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
9978: }
9979:
9980: #ifdef NONNESTED_CLASSES
9981: /* Class types don't nest the way enums do. */
9982: class_binding_level = (struct binding_level *)0;
9983: #endif
9984: pushtag (name, ref, globalize);
9985: class_binding_level = old_b;
9986:
9987: if (flag_cadillac)
9988: cadillac_start_struct (ref);
9989: }
9990: }
9991: else
9992: {
9993: if (IS_AGGR_TYPE_CODE (code))
9994: {
9995: if (IS_AGGR_TYPE (ref)
9996: && ((tag_code == exception_type)
9997: != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
9998: {
9999: cp_error ("type `%T' is both exception and aggregate type", ref);
10000: CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
10001: }
10002: }
10003:
10004: /* If it no longer looks like a nested type, make sure it's
10005: in global scope. */
10006: if (b == global_binding_level && !class_binding_level
10007: && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
10008: IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
10009:
10010: if (binfo)
10011: {
10012: tree tt1 = binfo;
10013: tree tt2 = TYPE_BINFO_BASETYPES (ref);
10014:
10015: if (TYPE_BINFO_BASETYPES (ref))
10016: for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
10017: if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
10018: {
10019: cp_error ("redeclaration of derivation chain of type `%#T'",
10020: ref);
10021: break;
10022: }
10023:
10024: if (tt1 == NULL_TREE)
10025: /* The user told us something we already knew. */
10026: goto just_return;
10027:
10028: /* In C++, since these migrate into the global scope, we must
10029: build them on the permanent obstack. */
10030: end_temporary_allocation ();
10031: }
10032: }
10033:
10034: if (binfo)
10035: {
10036: /* In the declaration `A : X, Y, ... Z' we mark all the types
10037: (A, X, Y, ..., Z) so we can check for duplicates. */
10038: tree binfos;
10039:
10040: SET_CLASSTYPE_MARKED (ref);
10041: BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
10042:
10043: for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
10044: {
10045: /* The base of a derived struct is public by default. */
10046: int via_public
10047: = (TREE_PURPOSE (binfo) == (tree)access_public
10048: || TREE_PURPOSE (binfo) == (tree)access_public_virtual
10049: || (tag_code != class_type
10050: && (TREE_PURPOSE (binfo) == (tree)access_default
10051: || TREE_PURPOSE (binfo) == (tree)access_default_virtual)));
10052: int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected;
10053: int via_virtual
10054: = (TREE_PURPOSE (binfo) == (tree)access_private_virtual
10055: || TREE_PURPOSE (binfo) == (tree)access_public_virtual
10056: || TREE_PURPOSE (binfo) == (tree)access_default_virtual);
10057: tree basetype = TREE_TYPE (TREE_VALUE (binfo));
10058: tree base_binfo;
10059:
10060: GNU_xref_hier (IDENTIFIER_POINTER (name),
10061: IDENTIFIER_POINTER (TREE_VALUE (binfo)),
10062: via_public, via_virtual, 0);
10063:
10064: if (basetype && TREE_CODE (basetype) == TYPE_DECL)
10065: basetype = TREE_TYPE (basetype);
10066: if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
10067: {
10068: error ("base type `%s' fails to be a struct or class type",
10069: IDENTIFIER_POINTER (TREE_VALUE (binfo)));
10070: continue;
10071: }
10072: #if 1
10073: /* This code replaces similar code in layout_basetypes. */
10074: else if (TYPE_SIZE (basetype) == NULL_TREE)
10075: {
10076: cp_error ("base class `%T' has incomplete type", basetype);
10077: continue;
10078: }
10079: #endif
10080: else
10081: {
10082: if (CLASSTYPE_MARKED (basetype))
10083: {
10084: if (basetype == ref)
10085: cp_error ("recursive type `%T' undefined", basetype);
10086: else
10087: cp_error ("duplicate base type `%T' invalid", basetype);
10088: continue;
10089: }
10090:
10091: /* Note that the BINFO records which describe individual
10092: inheritances are *not* shared in the lattice! They
10093: cannot be shared because a given baseclass may be
10094: inherited with different `accessibility' by different
10095: derived classes. (Each BINFO record describing an
10096: individual inheritance contains flags which say what
10097: the `accessibility' of that particular inheritance is.) */
10098:
10099: base_binfo = make_binfo (integer_zero_node, basetype,
10100: TYPE_BINFO_VTABLE (basetype),
10101: TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
10102:
10103: TREE_VEC_ELT (binfos, i) = base_binfo;
10104: TREE_VIA_PUBLIC (base_binfo) = via_public;
10105: TREE_VIA_PROTECTED (base_binfo) = via_protected;
10106: TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
10107: BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref);
10108:
10109: SET_CLASSTYPE_MARKED (basetype);
10110: #if 0
10111: /* XYZZY TEST VIRTUAL BASECLASSES */
10112: if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
10113: && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
10114: && via_virtual == 0)
10115: {
10116: warning ("making type `%s' a virtual baseclass",
10117: TYPE_NAME_STRING (basetype));
10118: via_virtual = 1;
10119: }
10120: #endif
10121: /* We are free to modify these bits because they are meaningless
10122: at top level, and BASETYPE is a top-level type. */
10123: if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
10124: {
10125: TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
10126: TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10127: }
10128:
10129: TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
10130: TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype);
10131: TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
10132: CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
10133: i += 1;
10134: }
10135: }
10136: if (i)
10137: TREE_VEC_LENGTH (binfos) = i;
10138: else
10139: BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
10140:
10141: if (i > 1)
10142: TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
10143: else if (i == 1)
10144: TYPE_USES_MULTIPLE_INHERITANCE (ref)
10145: = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
10146: if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
10147: TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10148:
10149: /* Unmark all the types. */
10150: while (--i >= 0)
10151: CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
10152: CLEAR_CLASSTYPE_MARKED (ref);
10153: }
10154:
10155: just_return:
10156:
10157: /* Until the type is defined, tentatively accept whatever
10158: structure tag the user hands us. */
10159: if (TYPE_SIZE (ref) == NULL_TREE
10160: && ref != current_class_type
10161: /* Have to check this, in case we have contradictory tag info. */
10162: && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
10163: {
10164: if (tag_code == class_type)
10165: CLASSTYPE_DECLARED_CLASS (ref) = 1;
10166: else if (tag_code == record_type || tag_code == signature_type)
10167: CLASSTYPE_DECLARED_CLASS (ref) = 0;
10168: }
10169:
10170: pop_obstacks ();
10171:
10172: return ref;
10173: }
10174:
10175: static tree current_local_enum = NULL_TREE;
10176:
10177: /* Begin compiling the definition of an enumeration type.
10178: NAME is its name (or null if anonymous).
10179: Returns the type object, as yet incomplete.
10180: Also records info about it so that build_enumerator
10181: may be used to declare the individual values as they are read. */
10182:
10183: tree
10184: start_enum (name)
10185: tree name;
10186: {
10187: register tree enumtype = NULL_TREE;
10188: struct binding_level *b = inner_binding_level;
10189:
10190: /* If this is the real definition for a previous forward reference,
10191: fill in the contents in the same object that used to be the
10192: forward reference. */
10193:
10194: if (name != NULL_TREE)
10195: enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
10196:
10197: if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10198: cp_error ("multiple definition of enum `%T'", enumtype);
10199: else
10200: {
10201: enumtype = make_node (ENUMERAL_TYPE);
10202: pushtag (name, enumtype, 0);
10203: }
10204:
10205: if (current_class_type)
10206: TREE_ADDRESSABLE (b->tags) = 1;
10207: current_local_enum = NULL_TREE;
10208:
10209: #if 0 /* This stuff gets cleared in finish_enum anyway. */
10210: if (TYPE_VALUES (enumtype) != NULL_TREE)
10211: /* Completely replace its old definition.
10212: The old enumerators remain defined, however. */
10213: TYPE_VALUES (enumtype) = NULL_TREE;
10214:
10215: /* Initially, set up this enum as like `int'
10216: so that we can create the enumerators' declarations and values.
10217: Later on, the precision of the type may be changed and
10218: it may be laid out again. */
10219:
10220: TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10221: TYPE_SIZE (enumtype) = NULL_TREE;
10222: fixup_signed_type (enumtype);
10223: #endif
10224:
10225: /* We copy this value because enumerated type constants
10226: are really of the type of the enumerator, not integer_type_node. */
10227: enum_next_value = copy_node (integer_zero_node);
10228: enum_overflow = 0;
10229:
10230: GNU_xref_decl (current_function_decl, enumtype);
10231: return enumtype;
10232: }
10233:
10234: /* After processing and defining all the values of an enumeration type,
10235: install their decls in the enumeration type and finish it off.
10236: ENUMTYPE is the type object and VALUES a list of name-value pairs.
10237: Returns ENUMTYPE. */
10238:
10239: tree
10240: finish_enum (enumtype, values)
10241: register tree enumtype, values;
10242: {
10243: register tree minnode, maxnode;
10244: /* Calculate the maximum value of any enumerator in this type. */
10245:
10246: if (values)
10247: {
10248: register tree pair;
10249: register tree value = DECL_INITIAL (TREE_VALUE (values));
10250:
10251: /* Speed up the main loop by performing some precalculations */
10252: TREE_TYPE (TREE_VALUE (values)) = enumtype;
10253: TREE_TYPE (value) = enumtype;
10254: TREE_VALUE (values) = value;
10255: minnode = maxnode = value;
10256:
10257: for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
10258: {
10259: value = DECL_INITIAL (TREE_VALUE (pair));
10260: TREE_TYPE (TREE_VALUE (pair)) = enumtype;
10261: TREE_TYPE (value) = enumtype;
10262: TREE_VALUE (pair) = value;
10263: if (tree_int_cst_lt (maxnode, value))
10264: maxnode = value;
10265: else if (tree_int_cst_lt (value, minnode))
10266: minnode = value;
10267: }
10268: }
10269: else
10270: maxnode = minnode = integer_zero_node;
10271:
10272: TYPE_VALUES (enumtype) = values;
10273:
10274: {
10275: int unsignedp = tree_int_cst_sgn (minnode) >= 0;
10276: int lowprec = min_precision (minnode, unsignedp);
10277: int highprec = min_precision (maxnode, unsignedp);
10278: int precision = MAX (lowprec, highprec);
10279:
10280: if (! flag_short_enums && precision < TYPE_PRECISION (integer_type_node))
10281: precision = TYPE_PRECISION (integer_type_node);
10282:
10283:
10284: /*
10285: * The following code is unnecessary since the function
10286: * type_promotes_to deals correctly with promotion of enums of
10287: * underlying unsigned types to signed integer types.
10288: * Moreover, it causes an enum bitfield to require one more bit of
10289: * storage than defined by the ANSI/ISO C++ resolution section r.7.2
10290: * which defines the range of an enum.
10291: */
10292: #if 0
10293: /* Unlike the C frontend, we prefer signed types. */
10294: if (unsignedp && int_fits_type_p (maxnode, type_for_size (precision, 0)))
10295: unsignedp = 0;
10296: #endif
10297:
10298: TYPE_PRECISION (enumtype) = precision;
10299: TYPE_SIZE (enumtype) = NULL_TREE;
10300: if (unsignedp)
10301: fixup_unsigned_type (enumtype);
10302: else
10303: fixup_signed_type (enumtype);
10304: }
10305:
10306: if (flag_cadillac)
10307: cadillac_finish_enum (enumtype);
10308:
10309: {
10310: register tree tem;
10311:
10312: /* Fix up all variant types of this enum type. */
10313: for (tem = TYPE_MAIN_VARIANT (enumtype); tem;
10314: tem = TYPE_NEXT_VARIANT (tem))
10315: {
10316: TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
10317: TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
10318: TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
10319: TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
10320: TYPE_MODE (tem) = TYPE_MODE (enumtype);
10321: TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
10322: TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
10323: TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
10324: }
10325: }
10326:
10327: /* Finish debugging output for this type. */
10328: #if 0
10329: /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
10330: information should *not* be generated? I think not. */
10331: if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
10332: #endif
10333: rest_of_type_compilation (enumtype, global_bindings_p ());
10334:
10335: return enumtype;
10336: }
10337:
10338: /* Build and install a CONST_DECL for one value of the
10339: current enumeration type (one that was begun with start_enum).
10340: Return a tree-list containing the name and its value.
10341: Assignment of sequential values by default is handled here. */
10342:
10343: tree
10344: build_enumerator (name, value)
10345: tree name, value;
10346: {
10347: tree decl, result;
10348: /* Change this to zero if we find VALUE is not shareable. */
10349: int shareable = 1;
10350:
10351: /* Remove no-op casts from the value. */
10352: if (value)
10353: STRIP_TYPE_NOPS (value);
10354:
10355: /* Validate and default VALUE. */
10356: if (value != NULL_TREE)
10357: {
10358: if (TREE_READONLY_DECL_P (value))
10359: {
10360: value = decl_constant_value (value);
10361: shareable = 0;
10362: }
10363:
10364: if (TREE_CODE (value) == INTEGER_CST)
10365: {
10366: value = default_conversion (value);
10367: constant_expression_warning (value);
10368: }
10369: else
10370: {
10371: cp_error ("enumerator value for `%D' not integer constant", name);
10372: value = NULL_TREE;
10373: }
10374: }
10375:
10376: /* The order of things is reversed here so that we
10377: can check for possible sharing of enum values,
10378: to keep that from happening. */
10379: /* Default based on previous value. */
10380: if (value == NULL_TREE)
10381: {
10382: value = enum_next_value;
10383: if (enum_overflow)
10384: cp_error ("overflow in enumeration values at `%D'", name);
10385: }
10386:
10387: /* Remove no-op casts from the value. */
10388: if (value)
10389: STRIP_TYPE_NOPS (value);
10390:
10391: /* Make up for hacks in lex.c. */
10392: if (value == integer_zero_node)
10393: value = build_int_2 (0, 0);
10394: else if (value == integer_one_node)
10395: value = build_int_2 (1, 0);
10396: else if (TREE_CODE (value) == INTEGER_CST
10397: && (shareable == 0
10398: || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
10399: {
10400: value = copy_node (value);
10401: TREE_TYPE (value) = integer_type_node;
10402: }
10403:
10404: /* C++ associates enums with global, function, or class declarations. */
10405:
10406: decl = current_scope ();
10407: if (decl && decl == current_class_type)
10408: {
10409: /* This enum declaration is local to the class, so we must put
10410: it in that class's list of decls. */
10411: decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
10412: DECL_INITIAL (decl) = value;
10413: TREE_READONLY (decl) = 1;
10414: pushdecl_class_level (decl);
10415: TREE_CHAIN (decl) = current_local_enum;
10416: current_local_enum = decl;
10417: }
10418: else
10419: {
10420: /* It's a global enum, or it's local to a function. (Note local to
10421: a function could mean local to a class method. */
10422: decl = build_decl (CONST_DECL, name, integer_type_node);
10423: DECL_INITIAL (decl) = value;
10424:
10425: pushdecl (decl);
10426: GNU_xref_decl (current_function_decl, decl);
10427: }
10428:
10429: /* Set basis for default for next value. */
10430: enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
10431: integer_one_node, PLUS_EXPR);
10432: enum_overflow = tree_int_cst_lt (enum_next_value, value);
10433:
10434: if (enum_next_value == integer_one_node)
10435: enum_next_value = copy_node (enum_next_value);
10436:
10437: result = saveable_tree_cons (name, decl, NULL_TREE);
10438: return result;
10439: }
10440:
10441: tree
10442: grok_enum_decls (type, decl)
10443: tree type, decl;
10444: {
10445: tree d = current_local_enum;
10446:
10447: if (d == NULL_TREE)
10448: return decl;
10449:
10450: while (1)
10451: {
10452: TREE_TYPE (d) = type;
10453: if (TREE_CHAIN (d) == NULL_TREE)
10454: {
10455: TREE_CHAIN (d) = decl;
10456: break;
10457: }
10458: d = TREE_CHAIN (d);
10459: }
10460:
10461: decl = current_local_enum;
10462: current_local_enum = NULL_TREE;
10463:
10464: return decl;
10465: }
10466:
10467: /* Create the FUNCTION_DECL for a function definition.
10468: DECLSPECS and DECLARATOR are the parts of the declaration;
10469: they describe the function's name and the type it returns,
10470: but twisted together in a fashion that parallels the syntax of C.
10471:
10472: This function creates a binding context for the function body
10473: as well as setting up the FUNCTION_DECL in current_function_decl.
10474:
10475: Returns 1 on success. If the DECLARATOR is not suitable for a function
10476: (it defines a datum instead), we return 0, which tells
10477: yyparse to report a parse error.
10478:
10479: For C++, we must first check whether that datum makes any sense.
10480: For example, "class A local_a(1,2);" means that variable local_a
10481: is an aggregate of type A, which should have a constructor
10482: applied to it with the argument list [1, 2].
10483:
10484: @@ There is currently no way to retrieve the storage
10485: @@ allocated to FUNCTION (or all of its parms) if we return
10486: @@ something we had previously. */
10487:
10488: int
10489: start_function (declspecs, declarator, raises, pre_parsed_p)
10490: tree declarator, declspecs, raises;
10491: int pre_parsed_p;
10492: {
10493: tree decl1, olddecl;
10494: tree ctype = NULL_TREE;
10495: tree fntype;
10496: tree restype;
10497: extern int have_extern_spec;
10498: extern int used_extern_spec;
10499: int doing_friend = 0;
10500:
10501: /* Sanity check. */
10502: my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
10503: my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
10504:
10505: /* Assume, until we see it does. */
10506: current_function_returns_value = 0;
10507: current_function_returns_null = 0;
10508: warn_about_return_type = 0;
10509: current_extern_inline = 0;
10510: current_function_assigns_this = 0;
10511: current_function_just_assigned_this = 0;
10512: current_function_parms_stored = 0;
10513: original_result_rtx = NULL_RTX;
10514: current_function_obstack_index = 0;
10515: current_function_obstack_usage = 0;
10516:
10517: clear_temp_name ();
10518:
10519: /* This should only be done once on the top most decl. */
10520: if (have_extern_spec && !used_extern_spec)
10521: {
10522: declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
10523: used_extern_spec = 1;
10524: }
10525:
10526: if (pre_parsed_p)
10527: {
10528: decl1 = declarator;
10529:
10530: if (! DECL_ARGUMENTS (decl1)
10531: && !DECL_STATIC_FUNCTION_P (decl1)
10532: && DECL_CONTEXT (decl1)
10533: && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
10534: && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
10535: {
10536: cp_error ("redeclaration of `%#D'", decl1);
10537: if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
10538: cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
10539: else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
10540: cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
10541: }
10542:
10543: last_function_parms = DECL_ARGUMENTS (decl1);
10544: last_function_parm_tags = NULL_TREE;
10545: fntype = TREE_TYPE (decl1);
10546: if (TREE_CODE (fntype) == METHOD_TYPE)
10547: ctype = TYPE_METHOD_BASETYPE (fntype);
10548:
10549: /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
10550: class is in the (lexical) scope of the class in which it is
10551: defined. */
10552: if (!ctype && DECL_FRIEND_P (decl1))
10553: {
10554: ctype = DECL_CLASS_CONTEXT (decl1);
10555:
10556: /* CTYPE could be null here if we're dealing with a template;
10557: for example, `inline friend float foo()' inside a template
10558: will have no CTYPE set. */
10559: if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
10560: ctype = NULL_TREE;
10561: else
10562: doing_friend = 1;
10563: }
10564:
10565: if ( !(DECL_VINDEX (decl1)
10566: && write_virtuals >= 2
10567: && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
10568: current_extern_inline = DECL_THIS_EXTERN (decl1) && DECL_INLINE (decl1);
10569:
10570: raises = TYPE_RAISES_EXCEPTIONS (fntype);
10571:
10572: /* In a fcn definition, arg types must be complete. */
10573: require_complete_types_for_parms (last_function_parms);
10574: }
10575: else
10576: {
10577: decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
10578: /* If the declarator is not suitable for a function definition,
10579: cause a syntax error. */
10580: if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
10581:
10582: fntype = TREE_TYPE (decl1);
10583:
10584: restype = TREE_TYPE (fntype);
10585: if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
10586: && ! CLASSTYPE_GOT_SEMICOLON (restype))
10587: {
10588: cp_error ("semicolon missing after declaration of `%#T'", restype);
10589: shadow_tag (build_tree_list (NULL_TREE, restype));
10590: CLASSTYPE_GOT_SEMICOLON (restype) = 1;
10591: if (TREE_CODE (fntype) == FUNCTION_TYPE)
10592: fntype = build_function_type (integer_type_node,
10593: TYPE_ARG_TYPES (fntype));
10594: else
10595: fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
10596: integer_type_node,
10597: TYPE_ARG_TYPES (fntype));
10598: TREE_TYPE (decl1) = fntype;
10599: }
10600:
10601: if (TREE_CODE (fntype) == METHOD_TYPE)
10602: ctype = TYPE_METHOD_BASETYPE (fntype);
10603: else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
10604: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
10605: && DECL_CONTEXT (decl1) == NULL_TREE)
10606: {
10607: /* If this doesn't return integer_type, complain. */
10608: if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
10609: {
10610: if (pedantic || warn_return_type)
10611: warning ("return type for `main' changed to integer type");
10612: TREE_TYPE (decl1) = fntype = default_function_type;
10613: }
10614: warn_about_return_type = 0;
10615: }
10616: }
10617:
10618: /* Warn if function was previously implicitly declared
10619: (but not if we warned then). */
10620: if (! warn_implicit
10621: && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
10622: cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
10623:
10624: current_function_decl = decl1;
10625:
10626: if (flag_cadillac)
10627: cadillac_start_function (decl1);
10628: else
10629: announce_function (decl1);
10630:
10631: if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
10632: {
10633: if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
10634: error_with_aggr_type (TREE_TYPE (fntype),
10635: "return-type `%s' is an incomplete type");
10636: else
10637: error ("return-type is an incomplete type");
10638:
10639: /* Make it return void instead, but don't change the
10640: type of the DECL_RESULT, in case we have a named return value. */
10641: if (ctype)
10642: TREE_TYPE (decl1)
10643: = build_cplus_method_type (build_type_variant (ctype,
10644: TREE_READONLY (decl1),
10645: TREE_SIDE_EFFECTS (decl1)),
10646: void_type_node,
10647: FUNCTION_ARG_CHAIN (decl1));
10648: else
10649: TREE_TYPE (decl1)
10650: = build_function_type (void_type_node,
10651: TYPE_ARG_TYPES (TREE_TYPE (decl1)));
10652: DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype));
10653: }
10654:
10655: if (warn_about_return_type)
10656: warning ("return-type defaults to `int'");
10657:
10658: /* Make the init_value nonzero so pushdecl knows this is not tentative.
10659: error_mark_node is replaced below (in poplevel) with the BLOCK. */
10660: DECL_INITIAL (decl1) = error_mark_node;
10661:
10662: /* Didn't get anything from C. */
10663: olddecl = NULL_TREE;
10664:
10665: /* This function exists in static storage.
10666: (This does not mean `static' in the C sense!) */
10667: TREE_STATIC (decl1) = 1;
10668:
10669: /* Record the decl so that the function name is defined.
10670: If we already have a decl for this name, and it is a FUNCTION_DECL,
10671: use the old decl. */
10672:
10673: if (pre_parsed_p == 0)
10674: {
10675: current_function_decl = decl1 = pushdecl (decl1);
10676: DECL_MAIN_VARIANT (decl1) = decl1;
10677: fntype = TREE_TYPE (decl1);
10678: }
10679: else
10680: current_function_decl = decl1;
10681:
10682: /* If this function belongs to an interface, it is public.
10683: If it belongs to someone else's interface, it is also external.
10684: It doesn't matter whether it's inline or not. */
10685: if (interface_unknown == 0
10686: && ! TREE_PUBLIC (decl1))
10687: {
10688: TREE_PUBLIC (decl1) = 1;
10689: DECL_EXTERNAL (decl1)
10690: = (interface_only
10691: || (DECL_INLINE (decl1) && ! flag_implement_inlines));
10692: }
10693: else
10694: {
10695: /* This is a definition, not a reference.
10696: So normally clear DECL_EXTERNAL.
10697: However, `extern inline' acts like a declaration except for
10698: defining how to inline. So set DECL_EXTERNAL in that case. */
10699: DECL_EXTERNAL (decl1) = current_extern_inline;
10700:
10701: DECL_DEFER_OUTPUT (decl1)
10702: = DECL_INLINE (decl1) && ! TREE_PUBLIC (decl1)
10703: && (DECL_FUNCTION_MEMBER_P (decl1)
10704: || DECL_TEMPLATE_INSTANTIATION (decl1));
10705: }
10706:
10707: if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
10708: {
10709: if (TREE_CODE (fntype) == METHOD_TYPE)
10710: TREE_TYPE (decl1) = fntype
10711: = build_function_type (TREE_TYPE (fntype),
10712: TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
10713: last_function_parms = TREE_CHAIN (last_function_parms);
10714: DECL_ARGUMENTS (decl1) = last_function_parms;
10715: ctype = NULL_TREE;
10716: }
10717: restype = TREE_TYPE (fntype);
10718:
10719: pushlevel (0);
10720: current_binding_level->parm_flag = 1;
10721:
10722: /* Save the parm names or decls from this function's declarator
10723: where store_parm_decls will find them. */
10724: current_function_parms = last_function_parms;
10725: current_function_parm_tags = last_function_parm_tags;
10726:
10727: GNU_xref_function (decl1, current_function_parms);
10728:
10729: make_function_rtl (decl1);
10730:
10731: if (ctype)
10732: {
10733: push_nested_class (ctype, 1);
10734:
10735: /* If we're compiling a friend function, neither of the variables
10736: current_class_decl nor current_class_type will have values. */
10737: if (! doing_friend)
10738: {
10739: /* We know that this was set up by `grokclassfn'.
10740: We do not wait until `store_parm_decls', since evil
10741: parse errors may never get us to that point. Here
10742: we keep the consistency between `current_class_type'
10743: and `current_class_decl'. */
10744: current_class_decl = last_function_parms;
10745: my_friendly_assert (current_class_decl != NULL_TREE
10746: && TREE_CODE (current_class_decl) == PARM_DECL, 162);
10747: if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
10748: {
10749: tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
10750: if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
10751: {
10752: /* Can't call build_indirect_ref here, because it has special
10753: logic to return C_C_D given this argument. */
10754: C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
10755: CLASSTYPE_INST_VAR (ctype) = C_C_D;
10756: }
10757: else
10758: {
10759: C_C_D = CLASSTYPE_INST_VAR (ctype);
10760: /* `current_class_decl' is different for every
10761: function we compile. */
10762: TREE_OPERAND (C_C_D, 0) = current_class_decl;
10763: }
10764: TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
10765: TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
10766: TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
10767: }
10768: else
10769: C_C_D = current_class_decl;
10770: }
10771: }
10772: else
10773: {
10774: if (DECL_STATIC_FUNCTION_P (decl1))
10775: push_nested_class (DECL_CONTEXT (decl1), 2);
10776: else
10777: push_memoized_context (0, 1);
10778: }
10779:
10780: /* Allocate further tree nodes temporarily during compilation
10781: of this function only. Tiemann moved up here from bottom of fn. */
10782: temporary_allocation ();
10783:
10784: /* Promote the value to int before returning it. */
10785: if (C_PROMOTING_INTEGER_TYPE_P (restype))
10786: {
10787: /* It retains unsignedness if traditional or if it isn't
10788: really getting wider. */
10789: if (TREE_UNSIGNED (restype)
10790: && (flag_traditional
10791: || TYPE_PRECISION (restype)
10792: == TYPE_PRECISION (integer_type_node)))
10793: restype = unsigned_type_node;
10794: else
10795: restype = integer_type_node;
10796: }
10797: if (DECL_RESULT (decl1) == NULL_TREE)
10798: DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype);
10799:
10800: if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)))
10801: {
10802: dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10803: ctor_label = NULL_TREE;
10804: }
10805: else
10806: {
10807: dtor_label = NULL_TREE;
10808: if (DECL_CONSTRUCTOR_P (decl1))
10809: ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10810: }
10811:
10812: /* If this fcn was already referenced via a block-scope `extern' decl
10813: (or an implicit decl), propagate certain information about the usage. */
10814: if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
10815: TREE_ADDRESSABLE (decl1) = 1;
10816:
10817: return 1;
10818: }
10819:
10820: /* Store the parameter declarations into the current function declaration.
10821: This is called after parsing the parameter declarations, before
10822: digesting the body of the function.
10823:
10824: Also install to binding contour return value identifier, if any. */
10825:
10826: void
10827: store_parm_decls ()
10828: {
10829: register tree fndecl = current_function_decl;
10830: register tree parm;
10831: int parms_have_cleanups = 0;
10832:
10833: /* This is either a chain of PARM_DECLs (when a prototype is used). */
10834: tree specparms = current_function_parms;
10835:
10836: /* This is a list of types declared among parms in a prototype. */
10837: tree parmtags = current_function_parm_tags;
10838:
10839: /* This is a chain of any other decls that came in among the parm
10840: declarations. If a parm is declared with enum {foo, bar} x;
10841: then CONST_DECLs for foo and bar are put here. */
10842: tree nonparms = NULL_TREE;
10843:
10844: if (current_binding_level == global_binding_level)
10845: fatal ("parse errors have confused me too much");
10846:
10847: /* Initialize RTL machinery. */
10848: init_function_start (fndecl, input_filename, lineno);
10849:
10850: /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
10851: declare_function_name ();
10852:
10853: /* Create a binding level for the parms. */
10854: expand_start_bindings (0);
10855:
10856: if (specparms != NULL_TREE)
10857: {
10858: /* This case is when the function was defined with an ANSI prototype.
10859: The parms already have decls, so we need not do anything here
10860: except record them as in effect
10861: and complain if any redundant old-style parm decls were written. */
10862:
10863: register tree next;
10864:
10865: /* Must clear this because it might contain TYPE_DECLs declared
10866: at class level. */
10867: storedecls (NULL_TREE);
10868: for (parm = nreverse (specparms); parm; parm = next)
10869: {
10870: next = TREE_CHAIN (parm);
10871: if (TREE_CODE (parm) == PARM_DECL)
10872: {
10873: tree cleanup = maybe_build_cleanup (parm);
10874: if (DECL_NAME (parm) == NULL_TREE)
10875: {
10876: #if 0
10877: cp_error_at ("parameter name omitted", parm);
10878: #else
10879: /* for C++, this is not an error. */
10880: pushdecl (parm);
10881: #endif
10882: }
10883: else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
10884: cp_error ("parameter `%D' declared void", parm);
10885: else
10886: {
10887: /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
10888: A parameter is assumed not to have any side effects.
10889: If this should change for any reason, then this
10890: will have to wrap the bashed reference type in a save_expr.
10891:
10892: Also, if the parameter type is declared to be an X
10893: and there is an X(X&) constructor, we cannot lay it
10894: into the stack (any more), so we make this parameter
10895: look like it is really of reference type. Functions
10896: which pass parameters to this function will know to
10897: create a temporary in their frame, and pass a reference
10898: to that. */
10899:
10900: if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
10901: && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
10902: SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
10903:
10904: pushdecl (parm);
10905: }
10906: if (cleanup)
10907: {
10908: expand_decl (parm);
10909: if (! expand_decl_cleanup (parm, cleanup))
10910: cp_error ("parser lost in parsing declaration of `%D'",
10911: parm);
10912: parms_have_cleanups = 1;
10913: }
10914: }
10915: else
10916: {
10917: /* If we find an enum constant or a type tag,
10918: put it aside for the moment. */
10919: TREE_CHAIN (parm) = NULL_TREE;
10920: nonparms = chainon (nonparms, parm);
10921: }
10922: }
10923:
10924: /* Get the decls in their original chain order
10925: and record in the function. This is all and only the
10926: PARM_DECLs that were pushed into scope by the loop above. */
10927: DECL_ARGUMENTS (fndecl) = getdecls ();
10928:
10929: storetags (chainon (parmtags, gettags ()));
10930: }
10931: else
10932: DECL_ARGUMENTS (fndecl) = NULL_TREE;
10933:
10934: /* Now store the final chain of decls for the arguments
10935: as the decl-chain of the current lexical scope.
10936: Put the enumerators in as well, at the front so that
10937: DECL_ARGUMENTS is not modified. */
10938:
10939: storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
10940:
10941: /* Initialize the RTL code for the function. */
10942: DECL_SAVED_INSNS (fndecl) = NULL_RTX;
10943: expand_function_start (fndecl, parms_have_cleanups);
10944:
10945: /* Create a binding contour which can be used to catch
10946: cleanup-generated temporaries. Also, if the return value needs or
10947: has initialization, deal with that now. */
10948: if (parms_have_cleanups)
10949: {
10950: pushlevel (0);
10951: expand_start_bindings (0);
10952: }
10953:
10954: current_function_parms_stored = 1;
10955:
10956: if (flag_gc)
10957: {
10958: maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
10959: if (! expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup))
10960: cp_error ("parser lost in parsing declaration of `%D'", fndecl);
10961: }
10962:
10963: /* If this function is `main', emit a call to `__main'
10964: to run global initializers, etc. */
10965: if (DECL_NAME (fndecl)
10966: && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
10967: && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
10968: && DECL_CONTEXT (fndecl) == NULL_TREE)
10969: {
10970: expand_main_function ();
10971:
10972: if (flag_gc)
10973: expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
10974: 0, VOIDmode, 0);
10975:
10976: if (flag_dossier)
10977: output_builtin_tdesc_entries ();
10978: }
10979: }
10980:
10981: /* Bind a name and initialization to the return value of
10982: the current function. */
10983: void
10984: store_return_init (return_id, init)
10985: tree return_id, init;
10986: {
10987: tree decl = DECL_RESULT (current_function_decl);
10988:
10989: if (flag_ansi)
10990: /* Give this error as many times as there are occurrences,
10991: so that users can use Emacs compilation buffers to find
10992: and fix all such places. */
10993: pedwarn ("ANSI C++ does not permit named return values");
10994:
10995: if (return_id != NULL_TREE)
10996: {
10997: if (DECL_NAME (decl) == NULL_TREE)
10998: {
10999: DECL_NAME (decl) = return_id;
11000: DECL_ASSEMBLER_NAME (decl) = return_id;
11001: }
11002: else
11003: error ("return identifier `%s' already in place",
11004: IDENTIFIER_POINTER (DECL_NAME (decl)));
11005: }
11006:
11007: /* Can't let this happen for constructors. */
11008: if (DECL_CONSTRUCTOR_P (current_function_decl))
11009: {
11010: error ("can't redefine default return value for constructors");
11011: return;
11012: }
11013:
11014: /* If we have a named return value, put that in our scope as well. */
11015: if (DECL_NAME (decl) != NULL_TREE)
11016: {
11017: /* If this named return value comes in a register,
11018: put it in a pseudo-register. */
11019: if (DECL_REGISTER (decl))
11020: {
11021: original_result_rtx = DECL_RTL (decl);
11022: DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
11023: }
11024:
11025: /* Let `finish_decl' know that this initializer is ok. */
11026: DECL_INITIAL (decl) = init;
11027: pushdecl (decl);
11028: finish_decl (decl, init, 0, 0);
11029: }
11030: }
11031:
11032:
11033: /* Finish up a function declaration and compile that function
11034: all the way to assembler language output. The free the storage
11035: for the function definition.
11036:
11037: This is called after parsing the body of the function definition.
11038: LINENO is the current line number.
11039:
11040: C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11041: (and expand_end_bindings) must be made to take care of the binding
11042: contour for the base initializers. This is only relevant for
11043: constructors. */
11044:
11045: void
11046: finish_function (lineno, call_poplevel)
11047: int lineno;
11048: int call_poplevel;
11049: {
11050: register tree fndecl = current_function_decl;
11051: tree fntype, ctype = NULL_TREE;
11052: rtx head, last_parm_insn, mark;
11053: /* Label to use if this function is supposed to return a value. */
11054: tree no_return_label = NULL_TREE;
11055: tree decls = NULL_TREE;
11056:
11057: /* When we get some parse errors, we can end up without a
11058: current_function_decl, so cope. */
11059: if (fndecl == NULL_TREE)
11060: return;
11061:
11062: fntype = TREE_TYPE (fndecl);
11063:
11064: /* TREE_READONLY (fndecl) = 1;
11065: This caused &foo to be of type ptr-to-const-function
11066: which then got a warning when stored in a ptr-to-function variable. */
11067:
11068: /* This happens on strange parse errors. */
11069: if (! current_function_parms_stored)
11070: {
11071: call_poplevel = 0;
11072: store_parm_decls ();
11073: }
11074:
11075: if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/)
11076: {
11077: tree ttype = target_type (fntype);
11078: tree parmdecl;
11079:
11080: if (IS_AGGR_TYPE (ttype))
11081: /* Let debugger know it should output info for this type. */
11082: note_debug_info_needed (ttype);
11083:
11084: for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
11085: {
11086: ttype = target_type (TREE_TYPE (parmdecl));
11087: if (IS_AGGR_TYPE (ttype))
11088: /* Let debugger know it should output info for this type. */
11089: note_debug_info_needed (ttype);
11090: }
11091: }
11092:
11093: /* Clean house because we will need to reorder insns here. */
11094: do_pending_stack_adjust ();
11095:
11096: if (dtor_label)
11097: {
11098: tree binfo = TYPE_BINFO (current_class_type);
11099: tree cond = integer_one_node;
11100: tree exprstmt, vfields;
11101: tree in_charge_node = lookup_name (in_charge_identifier, 0);
11102: tree virtual_size;
11103: int ok_to_optimize_dtor = 0;
11104:
11105: if (current_function_assigns_this)
11106: cond = build (NE_EXPR, integer_type_node,
11107: current_class_decl, integer_zero_node);
11108: else
11109: {
11110: int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
11111:
11112: /* If this destructor is empty, then we don't need to check
11113: whether `this' is NULL in some cases. */
11114: mark = get_last_insn ();
11115: last_parm_insn = get_first_nonparm_insn ();
11116:
11117: if ((flag_this_is_variable & 1) == 0)
11118: ok_to_optimize_dtor = 1;
11119: else if (mark == last_parm_insn)
11120: ok_to_optimize_dtor
11121: = (n_baseclasses == 0
11122: || (n_baseclasses == 1
11123: && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
11124: }
11125:
11126: /* These initializations might go inline. Protect
11127: the binding level of the parms. */
11128: pushlevel (0);
11129: expand_start_bindings (0);
11130:
11131: if (current_function_assigns_this)
11132: {
11133: current_function_assigns_this = 0;
11134: current_function_just_assigned_this = 0;
11135: }
11136:
11137: /* Generate the code to call destructor on base class.
11138: If this destructor belongs to a class with virtual
11139: functions, then set the virtual function table
11140: pointer to represent the type of our base class. */
11141:
11142: /* This side-effect makes call to `build_delete' generate the
11143: code we have to have at the end of this destructor. */
11144: TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
11145:
11146: /* These are two cases where we cannot delegate deletion. */
11147: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
11148: || TYPE_GETS_REG_DELETE (current_class_type))
11149: exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
11150: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11151: else
11152: exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
11153: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11154:
11155: /* If we did not assign to this, then `this' is non-zero at
11156: the end of a destructor. As a special optimization, don't
11157: emit test if this is an empty destructor. If it does nothing,
11158: it does nothing. If it calls a base destructor, the base
11159: destructor will perform the test. */
11160:
11161: if (exprstmt != error_mark_node
11162: && (TREE_CODE (exprstmt) != NOP_EXPR
11163: || TREE_OPERAND (exprstmt, 0) != integer_zero_node
11164: || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
11165: {
11166: expand_label (dtor_label);
11167: if (cond != integer_one_node)
11168: expand_start_cond (cond, 0);
11169: if (exprstmt != void_zero_node)
11170: /* Don't call `expand_expr_stmt' if we're not going to do
11171: anything, since -Wall will give a diagnostic. */
11172: expand_expr_stmt (exprstmt);
11173:
11174: /* Run destructor on all virtual baseclasses. */
11175: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11176: {
11177: tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
11178: expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
11179: in_charge_node, integer_two_node), 0);
11180: while (vbases)
11181: {
11182: if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
11183: {
11184: tree ptr = convert_pointer_to_vbase (vbases, current_class_decl);
11185: expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)),
11186: ptr, integer_zero_node,
11187: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
11188: }
11189: vbases = TREE_CHAIN (vbases);
11190: }
11191: expand_end_cond ();
11192: }
11193:
11194: do_pending_stack_adjust ();
11195: if (cond != integer_one_node)
11196: expand_end_cond ();
11197: }
11198:
11199: TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
11200:
11201: virtual_size = c_sizeof (current_class_type);
11202:
11203: /* At the end, call delete if that's what's requested. */
11204: if (TYPE_GETS_REG_DELETE (current_class_type))
11205: /* This NOP_EXPR means we are in a static call context. */
11206: exprstmt =
11207: build_method_call
11208: (build_indirect_ref
11209: (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type),
11210: error_mark_node),
11211: NULL_PTR),
11212: ansi_opname[(int) DELETE_EXPR],
11213: tree_cons (NULL_TREE, current_class_decl,
11214: build_tree_list (NULL_TREE, virtual_size)),
11215: NULL_TREE, LOOKUP_NORMAL);
11216: else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11217: exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
11218: virtual_size);
11219: else
11220: exprstmt = NULL_TREE;
11221:
11222: if (exprstmt)
11223: {
11224: cond = build (BIT_AND_EXPR, integer_type_node,
11225: in_charge_node, integer_one_node);
11226: expand_start_cond (cond, 0);
11227: expand_expr_stmt (exprstmt);
11228: expand_end_cond ();
11229: }
11230:
11231: /* End of destructor. */
11232: expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
11233: poplevel (2, 0, 0); /* XXX change to 1 */
11234:
11235: /* Back to the top of destructor. */
11236: /* Dont execute destructor code if `this' is NULL. */
11237: mark = get_last_insn ();
11238: last_parm_insn = get_first_nonparm_insn ();
11239: if (last_parm_insn == NULL_RTX)
11240: last_parm_insn = mark;
11241: else
11242: last_parm_insn = previous_insn (last_parm_insn);
11243:
11244: /* Make all virtual function table pointers in non-virtual base
11245: classes point to CURRENT_CLASS_TYPE's virtual function
11246: tables. */
11247: expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl);
11248: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11249: expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0);
11250: if (! ok_to_optimize_dtor)
11251: {
11252: cond = build_binary_op (NE_EXPR,
11253: current_class_decl, integer_zero_node, 1);
11254: expand_start_cond (cond, 0);
11255: }
11256: if (mark != get_last_insn ())
11257: reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11258: if (! ok_to_optimize_dtor)
11259: expand_end_cond ();
11260: }
11261: else if (current_function_assigns_this)
11262: {
11263: /* Does not need to call emit_base_init, because
11264: that is done (if needed) just after assignment to this
11265: is seen. */
11266:
11267: if (DECL_CONSTRUCTOR_P (current_function_decl))
11268: {
11269: expand_label (ctor_label);
11270: ctor_label = NULL_TREE;
11271:
11272: if (call_poplevel)
11273: {
11274: decls = getdecls ();
11275: expand_end_bindings (decls, decls != NULL_TREE, 0);
11276: poplevel (decls != NULL_TREE, 0, 0);
11277: }
11278: c_expand_return (current_class_decl);
11279: }
11280: else if (TYPE_MAIN_VARIANT (TREE_TYPE (
11281: DECL_RESULT (current_function_decl))) != void_type_node
11282: && return_label != NULL_RTX)
11283: no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11284:
11285: current_function_assigns_this = 0;
11286: current_function_just_assigned_this = 0;
11287: base_init_insns = NULL_RTX;
11288: }
11289: else if (DECL_CONSTRUCTOR_P (fndecl))
11290: {
11291: tree allocated_this;
11292: tree cond, thenclause;
11293: /* Allow constructor for a type to get a new instance of the object
11294: using `build_new'. */
11295: tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
11296: CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
11297:
11298: DECL_RETURNS_FIRST_ARG (fndecl) = 1;
11299:
11300: if (flag_this_is_variable > 0)
11301: {
11302: cond = build_binary_op (EQ_EXPR,
11303: current_class_decl, integer_zero_node, 1);
11304: thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
11305: build_new (NULL_TREE, current_class_type, void_type_node, 0));
11306: }
11307:
11308: CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
11309:
11310: /* must keep the first insn safe. */
11311: head = get_insns ();
11312:
11313: /* this note will come up to the top with us. */
11314: mark = get_last_insn ();
11315:
11316: if (flag_this_is_variable > 0)
11317: {
11318: expand_start_cond (cond, 0);
11319: expand_expr_stmt (thenclause);
11320: expand_end_cond ();
11321: }
11322:
11323: #if 0
11324: if (DECL_NAME (fndecl) == NULL_TREE
11325: && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
11326: build_default_constructor (fndecl);
11327: #endif
11328:
11329: /* Emit insns from `emit_base_init' which sets up virtual
11330: function table pointer(s). */
11331: emit_insns (base_init_insns);
11332: base_init_insns = NULL_RTX;
11333:
11334: /* This is where the body of the constructor begins.
11335: If there were no insns in this function body, then the
11336: last_parm_insn is also the last insn.
11337:
11338: If optimization is enabled, last_parm_insn may move, so
11339: we don't hold on to it (across emit_base_init). */
11340: last_parm_insn = get_first_nonparm_insn ();
11341: if (last_parm_insn == NULL_RTX)
11342: last_parm_insn = mark;
11343: else
11344: last_parm_insn = previous_insn (last_parm_insn);
11345:
11346: if (mark != get_last_insn ())
11347: reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11348:
11349: /* This is where the body of the constructor ends. */
11350: expand_label (ctor_label);
11351: ctor_label = NULL_TREE;
11352:
11353: if (call_poplevel)
11354: {
11355: expand_end_bindings (decls = getdecls (), decls != NULL_TREE, 0);
11356: poplevel (decls != NULL_TREE, 1, 0);
11357: }
11358:
11359: c_expand_return (current_class_decl);
11360:
11361: current_function_assigns_this = 0;
11362: current_function_just_assigned_this = 0;
11363: }
11364: else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11365: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
11366: && DECL_CONTEXT (fndecl) == NULL_TREE)
11367: {
11368: /* Make it so that `main' always returns 0 by default. */
11369: #ifdef VMS
11370: c_expand_return (integer_one_node);
11371: #else
11372: c_expand_return (integer_zero_node);
11373: #endif
11374: }
11375: else if (return_label != NULL_RTX
11376: && current_function_return_value == NULL_TREE
11377: && ! DECL_NAME (DECL_RESULT (current_function_decl)))
11378: no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11379:
11380: if (flag_gc)
11381: expand_gc_prologue_and_epilogue ();
11382:
11383: /* That's the end of the vtable decl's life. Need to mark it such
11384: if doing stupid register allocation.
11385:
11386: Note that current_vtable_decl is really an INDIRECT_REF
11387: on top of a VAR_DECL here. */
11388: if (obey_regdecls && current_vtable_decl)
11389: use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
11390:
11391: /* If this function is supposed to return a value, ensure that
11392: we do not fall into the cleanups by mistake. The end of our
11393: function will look like this:
11394:
11395: user code (may have return stmt somewhere)
11396: goto no_return_label
11397: cleanup_label:
11398: cleanups
11399: goto return_label
11400: no_return_label:
11401: NOTE_INSN_FUNCTION_END
11402: return_label:
11403: things for return
11404:
11405: If the user omits a return stmt in the USER CODE section, we
11406: will have a control path which reaches NOTE_INSN_FUNCTION_END.
11407: Otherwise, we won't. */
11408: if (no_return_label)
11409: {
11410: DECL_CONTEXT (no_return_label) = fndecl;
11411: DECL_INITIAL (no_return_label) = error_mark_node;
11412: DECL_SOURCE_FILE (no_return_label) = input_filename;
11413: DECL_SOURCE_LINE (no_return_label) = lineno;
11414: expand_goto (no_return_label);
11415: }
11416:
11417: if (cleanup_label)
11418: {
11419: /* remove the binding contour which is used
11420: to catch cleanup-generated temporaries. */
11421: expand_end_bindings (0, 0, 0);
11422: poplevel (0, 0, 0);
11423: }
11424:
11425: if (cleanup_label)
11426: /* Emit label at beginning of cleanup code for parameters. */
11427: emit_label (cleanup_label);
11428:
11429: /* Get return value into register if that's where it's supposed to be. */
11430: if (original_result_rtx)
11431: fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
11432:
11433: /* Finish building code that will trigger warnings if users forget
11434: to make their functions return values. */
11435: if (no_return_label || cleanup_label)
11436: emit_jump (return_label);
11437: if (no_return_label)
11438: {
11439: /* We don't need to call `expand_*_return' here because we
11440: don't need any cleanups here--this path of code is only
11441: for error checking purposes. */
11442: expand_label (no_return_label);
11443: }
11444:
11445: /* reset scope for C++: if we were in the scope of a class,
11446: then when we finish this function, we are not longer so.
11447: This cannot be done until we know for sure that no more
11448: class members will ever be referenced in this function
11449: (i.e., calls to destructors). */
11450: if (current_class_name)
11451: {
11452: ctype = current_class_type;
11453: pop_nested_class (1);
11454: }
11455: else
11456: pop_memoized_context (1);
11457:
11458: /* Generate rtl for function exit. */
11459: expand_function_end (input_filename, lineno, 1);
11460:
11461: if (flag_handle_exceptions)
11462: expand_exception_blocks();
11463:
11464: /* This must come after expand_function_end because cleanups might
11465: have declarations (from inline functions) that need to go into
11466: this function's blocks. */
11467: if (current_binding_level->parm_flag != 1)
11468: my_friendly_abort (122);
11469: poplevel (1, 0, 1);
11470:
11471: /* Must mark the RESULT_DECL as being in this function. */
11472: DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
11473:
11474: /* Obey `register' declarations if `setjmp' is called in this fn. */
11475: if (flag_traditional && current_function_calls_setjmp)
11476: setjmp_protect (DECL_INITIAL (fndecl));
11477:
11478: /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
11479: to the FUNCTION_DECL node itself. */
11480: BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
11481:
11482: /* So we can tell if jump_optimize sets it to 1. */
11483: can_reach_end = 0;
11484:
11485: if (DECL_EXTERNAL (fndecl)
11486: /* This function is just along for the ride. If we can make
11487: it inline, that's great. Otherwise, just punt it. */
11488: && (DECL_INLINE (fndecl) == 0
11489: || flag_no_inline
11490: || function_cannot_inline_p (fndecl)
11491: /* ??? Compensate for Sun brain damage in dealing with
11492: data segments of PIC code. */
11493: || (flag_pic
11494: && (DECL_CONSTRUCTOR_P (fndecl)
11495: || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
11496: && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))))
11497:
11498: {
11499: extern int rtl_dump_and_exit;
11500: int old_rtl_dump_and_exit = rtl_dump_and_exit;
11501: int inline_spec = DECL_INLINE (fndecl);
11502:
11503: /* This throws away the code for FNDECL. */
11504: rtl_dump_and_exit = 1;
11505: /* This throws away the memory of the code for FNDECL. */
11506: if (flag_no_inline)
11507: DECL_INLINE (fndecl) = 0;
11508: rest_of_compilation (fndecl);
11509: rtl_dump_and_exit = old_rtl_dump_and_exit;
11510: DECL_INLINE (fndecl) = inline_spec;
11511: }
11512: else
11513: {
11514: /* Run the optimizers and output the assembler code for this
11515: function. */
11516: rest_of_compilation (fndecl);
11517: }
11518:
11519: if (DECL_INLINE (fndecl) && !TREE_ASM_WRITTEN (fndecl)
11520: && DECL_DEFER_OUTPUT (fndecl))
11521: {
11522: mark_inline_for_output (fndecl);
11523: }
11524:
11525: if (ctype && TREE_ASM_WRITTEN (fndecl))
11526: note_debug_info_needed (ctype);
11527:
11528: current_function_returns_null |= can_reach_end;
11529:
11530: /* Since we don't normally go through c_expand_return for constructors,
11531: this normally gets the wrong value.
11532: Also, named return values have their return codes emitted after
11533: NOTE_INSN_FUNCTION_END, confusing jump.c. */
11534: if (DECL_CONSTRUCTOR_P (fndecl)
11535: || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
11536: current_function_returns_null = 0;
11537:
11538: if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
11539: cp_warning ("`noreturn' function `%D' does return", fndecl);
11540: else if ((warn_return_type || pedantic)
11541: && current_function_returns_null
11542: && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
11543: {
11544: /* If this function returns non-void and control can drop through,
11545: complain. */
11546: cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
11547: }
11548: /* With just -W, complain only if function returns both with
11549: and without a value. */
11550: else if (extra_warnings
11551: && current_function_returns_value && current_function_returns_null)
11552: warning ("this function may return with or without a value");
11553:
11554: /* Free all the tree nodes making up this function. */
11555: /* Switch back to allocating nodes permanently
11556: until we start another function. */
11557: permanent_allocation (1);
11558:
11559: if (flag_cadillac)
11560: cadillac_finish_function (fndecl);
11561:
11562: if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
11563: {
11564: /* Stop pointing to the local nodes about to be freed. */
11565: /* But DECL_INITIAL must remain nonzero so we know this
11566: was an actual function definition. */
11567: DECL_INITIAL (fndecl) = error_mark_node;
11568: if (! DECL_CONSTRUCTOR_P (fndecl)
11569: || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
11570: DECL_ARGUMENTS (fndecl) = NULL_TREE;
11571: }
11572:
11573: /* Let the error reporting routines know that we're outside a function. */
11574: current_function_decl = NULL_TREE;
11575: named_label_uses = NULL_TREE;
11576: }
11577:
11578: /* Create the FUNCTION_DECL for a function definition.
11579: LINE1 is the line number that the definition absolutely begins on.
11580: LINE2 is the line number that the name of the function appears on.
11581: DECLSPECS and DECLARATOR are the parts of the declaration;
11582: they describe the return type and the name of the function,
11583: but twisted together in a fashion that parallels the syntax of C.
11584:
11585: This function creates a binding context for the function body
11586: as well as setting up the FUNCTION_DECL in current_function_decl.
11587:
11588: Returns a FUNCTION_DECL on success.
11589:
11590: If the DECLARATOR is not suitable for a function (it defines a datum
11591: instead), we return 0, which tells yyparse to report a parse error.
11592:
11593: May return void_type_node indicating that this method is actually
11594: a friend. See grokfield for more details.
11595:
11596: Came here with a `.pushlevel' .
11597:
11598: DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
11599: CHANGES TO CODE IN `grokfield'. */
11600: tree
11601: start_method (declspecs, declarator, raises)
11602: tree declarator, declspecs, raises;
11603: {
11604: tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
11605:
11606: /* Something too ugly to handle. */
11607: if (fndecl == NULL_TREE)
11608: return NULL_TREE;
11609:
11610: /* Pass friends other than inline friend functions back. */
11611: if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
11612: return fndecl;
11613:
11614: if (TREE_CODE (fndecl) != FUNCTION_DECL)
11615: /* Not a function, tell parser to report parse error. */
11616: return NULL_TREE;
11617:
11618: if (IS_SIGNATURE (current_class_type))
11619: {
11620: IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
11621: /* In case we need this info later. */
11622: HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
11623: }
11624:
11625: if (DECL_IN_AGGR_P (fndecl))
11626: {
11627: if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
11628: {
11629: if (DECL_CONTEXT (fndecl))
11630: cp_error ("`%D' is already defined in class %s", fndecl,
11631: TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
11632: }
11633: return void_type_node;
11634: }
11635:
11636: if (flag_default_inline)
11637: DECL_INLINE (fndecl) = 1;
11638:
11639: if (processing_template_defn)
11640: SET_DECL_IMPLICIT_INSTANTIATION (fndecl);
11641:
11642: /* We read in the parameters on the maybepermanent_obstack,
11643: but we won't be getting back to them until after we
11644: may have clobbered them. So the call to preserve_data
11645: will keep them safe. */
11646: preserve_data ();
11647:
11648: if (! DECL_FRIEND_P (fndecl))
11649: {
11650: if (DECL_CHAIN (fndecl) != NULL_TREE)
11651: {
11652: /* Need a fresh node here so that we don't get circularity
11653: when we link these together. If FNDECL was a friend, then
11654: `pushdecl' does the right thing, which is nothing wrt its
11655: current value of DECL_CHAIN. */
11656: fndecl = copy_node (fndecl);
11657: }
11658: if (TREE_CHAIN (fndecl))
11659: {
11660: fndecl = copy_node (fndecl);
11661: TREE_CHAIN (fndecl) = NULL_TREE;
11662: }
11663:
11664: if (DECL_CONSTRUCTOR_P (fndecl))
11665: {
11666: if (! grok_ctor_properties (current_class_type, fndecl))
11667: return void_type_node;
11668: }
11669: else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
11670: grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
11671: }
11672:
11673: finish_decl (fndecl, NULL_TREE, NULL_TREE, 0);
11674:
11675: /* Make a place for the parms */
11676: pushlevel (0);
11677: current_binding_level->parm_flag = 1;
11678:
11679: DECL_IN_AGGR_P (fndecl) = 1;
11680: return fndecl;
11681: }
11682:
11683: /* Go through the motions of finishing a function definition.
11684: We don't compile this method until after the whole class has
11685: been processed.
11686:
11687: FINISH_METHOD must return something that looks as though it
11688: came from GROKFIELD (since we are defining a method, after all).
11689:
11690: This is called after parsing the body of the function definition.
11691: STMTS is the chain of statements that makes up the function body.
11692:
11693: DECL is the ..._DECL that `start_method' provided. */
11694:
11695: tree
11696: finish_method (decl)
11697: tree decl;
11698: {
11699: register tree fndecl = decl;
11700: tree old_initial;
11701:
11702: register tree link;
11703:
11704: if (TYPE_MAIN_VARIANT (decl) == void_type_node)
11705: return decl;
11706:
11707: old_initial = DECL_INITIAL (fndecl);
11708:
11709: /* Undo the level for the parms (from start_method).
11710: This is like poplevel, but it causes nothing to be
11711: saved. Saving information here confuses symbol-table
11712: output routines. Besides, this information will
11713: be correctly output when this method is actually
11714: compiled. */
11715:
11716: /* Clear out the meanings of the local variables of this level;
11717: also record in each decl which block it belongs to. */
11718:
11719: for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
11720: {
11721: if (DECL_NAME (link) != NULL_TREE)
11722: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
11723: my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
11724: DECL_CONTEXT (link) = NULL_TREE;
11725: }
11726:
11727: /* Restore all name-meanings of the outer levels
11728: that were shadowed by this level. */
11729:
11730: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
11731: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11732: for (link = current_binding_level->class_shadowed;
11733: link; link = TREE_CHAIN (link))
11734: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11735: for (link = current_binding_level->type_shadowed;
11736: link; link = TREE_CHAIN (link))
11737: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11738:
11739: GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
11740: (HOST_WIDE_INT) current_binding_level->level_chain,
11741: current_binding_level->parm_flag,
11742: current_binding_level->keep,
11743: current_binding_level->tag_transparent);
11744:
11745: poplevel (0, 0, 0);
11746:
11747: DECL_INITIAL (fndecl) = old_initial;
11748:
11749: /* We used to check if the context of FNDECL was different from
11750: current_class_type as another way to get inside here. This didn't work
11751: for String.cc in libg++. */
11752: if (DECL_FRIEND_P (fndecl))
11753: {
11754: CLASSTYPE_INLINE_FRIENDS (current_class_type)
11755: = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
11756: decl = void_type_node;
11757: }
11758:
11759: return decl;
11760: }
11761:
11762: /* Called when a new struct TYPE is defined.
11763: If this structure or union completes the type of any previous
11764: variable declaration, lay it out and output its rtl. */
11765:
11766: void
11767: hack_incomplete_structures (type)
11768: tree type;
11769: {
11770: tree decl;
11771:
11772: if (current_binding_level->n_incomplete == 0)
11773: return;
11774:
11775: if (!type) /* Don't do this for class templates. */
11776: return;
11777:
11778: for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
11779: if (TREE_TYPE (decl) == type
11780: || (TREE_TYPE (decl)
11781: && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11782: && TREE_TYPE (TREE_TYPE (decl)) == type))
11783: {
11784: if (TREE_CODE (decl) == TYPE_DECL)
11785: layout_type (TREE_TYPE (decl));
11786: else
11787: {
11788: int toplevel = global_binding_level == current_binding_level;
11789: if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11790: && TREE_TYPE (TREE_TYPE (decl)) == type)
11791: layout_type (TREE_TYPE (decl));
11792: layout_decl (decl, 0);
11793: rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
11794: if (! toplevel)
11795: {
11796: tree cleanup;
11797: expand_decl (decl);
11798: cleanup = maybe_build_cleanup (decl);
11799: expand_decl_init (decl);
11800: if (! expand_decl_cleanup (decl, cleanup))
11801: cp_error ("parser lost in parsing declaration of `%D'",
11802: decl);
11803: }
11804: }
11805: my_friendly_assert (current_binding_level->n_incomplete > 0, 164);
11806: --current_binding_level->n_incomplete;
11807: }
11808: }
11809:
11810: /* Nonzero if presently building a cleanup. Needed because
11811: SAVE_EXPRs are not the right things to use inside of cleanups.
11812: They are only ever evaluated once, where the cleanup
11813: might be evaluated several times. In this case, a later evaluation
11814: of the cleanup might fill in the SAVE_EXPR_RTL, and it will
11815: not be valid for an earlier cleanup. */
11816:
11817: int building_cleanup;
11818:
11819: /* If DECL is of a type which needs a cleanup, build that cleanup here.
11820: We don't build cleanups if just going for syntax checking, since
11821: fixup_cleanups does not know how to not handle them.
11822:
11823: Don't build these on the momentary obstack; they must live
11824: the life of the binding contour. */
11825: tree
11826: maybe_build_cleanup (decl)
11827: tree decl;
11828: {
11829: tree type = TREE_TYPE (decl);
11830: if (TYPE_NEEDS_DESTRUCTOR (type))
11831: {
11832: int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
11833: tree rval;
11834: int old_building_cleanup = building_cleanup;
11835: building_cleanup = 1;
11836:
11837: if (TREE_CODE (decl) != PARM_DECL)
11838: temp = suspend_momentary ();
11839:
11840: if (TREE_CODE (type) == ARRAY_TYPE)
11841: rval = decl;
11842: else
11843: {
11844: mark_addressable (decl);
11845: rval = build_unary_op (ADDR_EXPR, decl, 0);
11846: }
11847:
11848: /* Optimize for space over speed here. */
11849: if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
11850: || flag_expensive_optimizations)
11851: flags |= LOOKUP_NONVIRTUAL;
11852:
11853: /* Use TYPE_MAIN_VARIANT so we don't get a warning about
11854: calling delete on a `const' variable. */
11855: if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval))))
11856: rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval);
11857:
11858: rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
11859:
11860: if (TYPE_USES_VIRTUAL_BASECLASSES (type)
11861: && ! TYPE_HAS_DESTRUCTOR (type))
11862: rval = build_compound_expr (tree_cons (NULL_TREE, rval,
11863: build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
11864:
11865: if (TREE_CODE (decl) != PARM_DECL)
11866: resume_momentary (temp);
11867:
11868: building_cleanup = old_building_cleanup;
11869:
11870: return rval;
11871: }
11872: return 0;
11873: }
11874:
11875: /* Expand a C++ expression at the statement level.
11876: This is needed to ferret out nodes which have UNKNOWN_TYPE.
11877: The C++ type checker should get all of these out when
11878: expressions are combined with other, type-providing, expressions,
11879: leaving only orphan expressions, such as:
11880:
11881: &class::bar; / / takes its address, but does nothing with it.
11882:
11883: */
11884: void
11885: cplus_expand_expr_stmt (exp)
11886: tree exp;
11887: {
11888: if (TREE_TYPE (exp) == unknown_type_node)
11889: {
11890: if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
11891: error ("address of overloaded function with no contextual type information");
11892: else if (TREE_CODE (exp) == COMPONENT_REF)
11893: warning ("useless reference to a member function name, did you forget the ()?");
11894: }
11895: else
11896: {
11897: int remove_implicit_immediately = 0;
11898:
11899: if (TREE_CODE (exp) == FUNCTION_DECL)
11900: {
11901: cp_warning ("reference, not call, to function `%D'", exp);
11902: warning ("at this point in file");
11903: }
11904:
11905: #if 0
11906: /* We should do this eventually, but right now this causes regex.o from
11907: libg++ to miscompile, and tString to core dump. */
11908: exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp);
11909: #endif
11910: expand_expr_stmt (break_out_cleanups (exp));
11911: }
11912:
11913: /* Clean up any pending cleanups. This happens when a function call
11914: returns a cleanup-needing value that nobody uses. */
11915: expand_cleanups_to (NULL_TREE);
11916: }
11917:
11918: /* When a stmt has been parsed, this function is called.
11919:
11920: Currently, this function only does something within a
11921: constructor's scope: if a stmt has just assigned to this,
11922: and we are in a derived class, we call `emit_base_init'. */
11923:
11924: void
11925: finish_stmt ()
11926: {
11927: extern struct nesting *cond_stack, *loop_stack, *case_stack;
11928:
11929:
11930: if (current_function_assigns_this
11931: || ! current_function_just_assigned_this)
11932: return;
11933: if (DECL_CONSTRUCTOR_P (current_function_decl))
11934: {
11935: /* Constructors must wait until we are out of control
11936: zones before calling base constructors. */
11937: if (cond_stack || loop_stack || case_stack)
11938: return;
11939: emit_insns (base_init_insns);
11940: check_base_init (current_class_type);
11941: }
11942: current_function_assigns_this = 1;
11943:
11944: if (flag_cadillac)
11945: cadillac_finish_stmt ();
11946: }
11947:
11948: /* Change a static member function definition into a FUNCTION_TYPE, instead
11949: of the METHOD_TYPE that we create when it's originally parsed.
11950:
11951: WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
11952: (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
11953: other decls. Either pass the addresses of local variables or NULL. */
11954:
11955: void
11956: revert_static_member_fn (decl, fn, argtypes)
11957: tree *decl, *fn, *argtypes;
11958: {
11959: tree tmp;
11960: tree function = fn ? *fn : TREE_TYPE (*decl);
11961: tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function);
11962:
11963: args = TREE_CHAIN (args);
11964: tmp = build_function_type (TREE_TYPE (function), args);
11965: tmp = build_type_variant (tmp, TYPE_READONLY (function),
11966: TYPE_VOLATILE (function));
11967: tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp,
11968: TYPE_RAISES_EXCEPTIONS (function));
11969: TREE_TYPE (*decl) = tmp;
11970: DECL_STATIC_FUNCTION_P (*decl) = 1;
11971: if (fn)
11972: *fn = tmp;
11973: if (argtypes)
11974: *argtypes = args;
11975: }
11976:
11977: int
11978: id_in_current_class (id)
11979: tree id;
11980: {
11981: return !!purpose_member (id, class_binding_level->class_shadowed);
11982: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.