|
|
1.1 root 1: /* Process declarations and variables for C compiler.
2: Copyright (C) 1988, 1992 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 "flags.h"
33: #include "cp-tree.h"
34: #include "cp-lex.h"
35: #include <signal.h>
36: #include "assert.h"
37: #include "obstack.h"
38:
39: #define obstack_chunk_alloc xmalloc
40: #define obstack_chunk_free free
41:
42: extern int xmalloc ();
43: extern void free ();
44:
45: extern struct obstack permanent_obstack;
46:
47: /* Stack of places to restore the search obstack back to. */
48:
49: /* Obstack used for remembering local class declarations (like
50: enums and static (const) members. */
51: #include "stack.h"
52: static struct obstack decl_obstack;
53: static struct stack_level *decl_stack;
54:
55: #include "cp-decl.h"
56:
57: #undef NULL
58: #define NULL 0
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_TYPE_SIZE
81: #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
82: #endif
83:
84: #ifndef WCHAR_UNSIGNED
85: #define WCHAR_UNSIGNED 0
86: #endif
87:
88: #ifndef FLOAT_TYPE_SIZE
89: #define FLOAT_TYPE_SIZE BITS_PER_WORD
90: #endif
91:
92: #ifndef DOUBLE_TYPE_SIZE
93: #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
94: #endif
95:
96: #ifndef LONG_DOUBLE_TYPE_SIZE
97: #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
98: #endif
99:
100: /* We let tm.h override the types used here, to handle trivial differences
101: such as the choice of unsigned int or long unsigned int for size_t.
102: When machines start needing nontrivial differences in the size type,
103: it would be best to do something here to figure out automatically
104: from other information what type to use. */
105:
106: #ifndef SIZE_TYPE
107: #define SIZE_TYPE "long unsigned int"
108: #endif
109:
110: #ifndef PTRDIFF_TYPE
111: #define PTRDIFF_TYPE "long int"
112: #endif
113:
114: #ifndef WCHAR_TYPE
115: #define WCHAR_TYPE "int"
116: #endif
117:
118: static tree grokparms ();
119: tree grokdeclarator ();
120: tree pushdecl (), pushdecl_class_level ();
121: void pop_implicit_try_blocks ();
122:
123: #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
124: define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
125: #define auto_function(NAME, TYPE, CODE) \
126: define_function (NAME, TYPE, CODE, (void (*)())push_overloaded_decl_1, 0)
127:
128: /* static */ void grokclassfn ();
129: /* static */ tree grokoptypename ();
130:
131: static tree lookup_tag ();
132: static tree lookup_tag_reverse ();
133: static tree lookup_name_current_level ();
134: static void maybe_globalize_type (), globalize_nested_type ();
135: static tree lookup_nested_type ();
136: static char *redeclaration_error_message ();
137: int parmlist_is_exprlist ();
138: static int parmlist_is_random ();
139: void grok_ctor_properties ();
140: static void grok_op_properties ();
141: static void expand_static_init ();
142: static void deactivate_exception_cleanups ();
143: void adjust_type_value ();
144: static void push_overload_decl_1 ();
145:
146: tree finish_table ();
147:
148: /* a node which has tree code ERROR_MARK, and whose type is itself.
149: All erroneous expressions are replaced with this node. All functions
150: that accept nodes as arguments should avoid generating error messages
151: if this node is one of the arguments, since it is undesirable to get
152: multiple error messages from one error in the input. */
153:
154: tree error_mark_node;
155:
156: /* Erroneous argument lists can use this *IFF* they do not modify it. */
157: tree error_mark_list;
158:
159: /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
160:
161: tree short_integer_type_node;
162: tree integer_type_node;
163: tree long_integer_type_node;
164: tree long_long_integer_type_node;
165:
166: tree short_unsigned_type_node;
167: tree unsigned_type_node;
168: tree long_unsigned_type_node;
169: tree long_long_unsigned_type_node;
170:
171: tree ptrdiff_type_node;
172:
173: tree unsigned_char_type_node;
174: tree signed_char_type_node;
175: tree char_type_node;
176: tree wchar_type_node;
177: tree signed_wchar_type_node;
178: tree unsigned_wchar_type_node;
179:
180: tree float_type_node;
181: tree double_type_node;
182: tree long_double_type_node;
183:
184: /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
185:
186: tree void_type_node, void_list_node;
187: tree void_zero_node;
188:
189: /* Nodes for types `void *' and `const void *'. */
190:
191: tree ptr_type_node, const_ptr_type_node;
192:
193: /* Nodes for types `char *' and `const char *'. */
194:
195: tree string_type_node, const_string_type_node;
196:
197: /* Type `char[256]' or something like it.
198: Used when an array of char is needed and the size is irrelevant. */
199:
200: tree char_array_type_node;
201:
202: /* Type `int[256]' or something like it.
203: Used when an array of int needed and the size is irrelevant. */
204:
205: tree int_array_type_node;
206:
207: /* Type `wchar_t[256]' or something like it.
208: Used when a wide string literal is created. */
209:
210: tree wchar_array_type_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 __t_desc_type_node, __i_desc_type_node, __m_desc_type_node;
237: tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
238: tree class_star_type_node;
239: tree class_type_node, record_type_node, union_type_node, enum_type_node;
240: tree exception_type_node, unknown_type_node;
241: tree maybe_gc_cleanup;
242:
243: /* Function type `void * (long)', 'void (void *)' */
244: tree ptr_ftype_long, void_ftype_ptr;
245: tree ptr_ftype_ptr_int_int_ptr, void_ftype_ptr_int_int_ptr_int_int;
246:
247: /* Used for virtual function tables. */
248: tree vtbl_mask;
249:
250: /* Array type `(void *)[]' */
251: tree vtbl_type_node;
252:
253: #ifdef SOS
254: /* SOS extensions. */
255: tree zlink_type, zret_type;
256: tree zlink, zret;
257: #endif
258:
259: /* Static decls which do not have static initializers have no
260: initializers as far as GNU C is concerned. EMPTY_INIT_NODE
261: is a static initializer which makes varasm code place the decl
262: in data rather than in bss space. Such gymnastics are necessary
263: to avoid the problem that the linker will not include a library
264: file if all the library appears to contribute are bss variables. */
265:
266: tree empty_init_node;
267:
268: /* In a destructor, the point at which all derived class destroying
269: has been done, just before any base class destroying will be done. */
270:
271: tree dtor_label;
272:
273: /* In a constructor, the point at which we are ready to return
274: the pointer to the initialized object. */
275:
276: tree ctor_label;
277:
278: /* A FUNCTION_DECL which can call `unhandled_exception'.
279: Not neccessarily the one that the user will declare,
280: but sufficient to be called by routines that want to abort the program. */
281:
282: tree unhandled_exception_fndecl;
283:
284: /* A FUNCTION_DECL which can call `abort'. Not neccessarily the
285: one that the user will declare, but sufficient to be called
286: by routines that want to abort the program. */
287:
288: tree abort_fndecl;
289:
290: /* If original DECL_RESULT of current function was a register,
291: but due to being an addressable named return value, would up
292: on the stack, this variable holds the named return value's
293: original location. */
294: struct rtx_def *original_result_rtx;
295:
296: /* Sequence of insns which represents base initialization. */
297: struct rtx_def *base_init_insns;
298:
299: /* C++: Keep these around to reduce calls to `get_identifier'.
300: Identifiers for `this' in member functions and the auto-delete
301: parameter for destructors. */
302: tree this_identifier, in_charge_identifier;
303:
304: /* A list (chain of TREE_LIST nodes) of named label uses.
305: The TREE_PURPOSE field is the list of variables defined
306: the the label's scope defined at the point of use.
307: The TREE_VALUE field is the LABEL_DECL used.
308: The TREE_TYPE field holds `current_binding_level' at the
309: point of the label's use.
310:
311: Used only for jumps to as-yet undefined labels, since
312: jumps to defined labels can have their validity checked
313: by stmt.c. */
314:
315: static tree named_label_uses;
316:
317: /* A list of objects which have constructors or destructors
318: which reside in the global scope. The decl is stored in
319: the TREE_VALUE slot and the initializer is stored
320: in the TREE_PURPOSE slot. */
321: tree static_aggregates;
322:
323: /* A list of functions which were declared inline, but later had their
324: address taken. Used only for non-virtual member functions, since we can
325: find other functions easily enough. */
326: tree pending_addressable_inlines;
327:
328: /* A list of overloaded functions which we should forget ever
329: existed, such as functions declared in a function's scope,
330: once we leave that function's scope. */
331: static tree overloads_to_forget;
332:
333: /* -- end of C++ */
334:
335: /* Two expressions that are constants with value zero.
336: The first is of type `int', the second of type `void *'. */
337:
338: tree integer_zero_node;
339: tree null_pointer_node;
340:
341: /* A node for the integer constants 1, 2, and 3. */
342:
343: tree integer_one_node, integer_two_node, integer_three_node;
344:
345: /* Nonzero if we have seen an invalid cross reference
346: to a struct, union, or enum, but not yet printed the message. */
347:
348: tree pending_invalid_xref;
349: /* File and line to appear in the eventual error message. */
350: char *pending_invalid_xref_file;
351: int pending_invalid_xref_line;
352:
353: /* While defining an enum type, this is 1 plus the last enumerator
354: constant value. */
355:
356: static tree enum_next_value;
357:
358: /* Parsing a function declarator leaves a list of parameter names
359: or a chain or parameter decls here. */
360:
361: tree last_function_parms;
362:
363: /* Parsing a function declarator leaves here a chain of structure
364: and enum types declared in the parmlist. */
365:
366: static tree last_function_parm_tags;
367:
368: /* After parsing the declarator that starts a function definition,
369: `start_function' puts here the list of parameter names or chain of decls.
370: `store_parm_decls' finds it here. */
371:
372: static tree current_function_parms;
373:
374: /* Similar, for last_function_parm_tags. */
375: static tree current_function_parm_tags;
376:
377: /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
378: that have names. Here so we can clear out their names' definitions
379: at the end of the function. */
380:
381: static tree named_labels;
382:
383: /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
384:
385: static tree shadowed_labels;
386:
387: /* Nonzero when store_parm_decls is called indicates a varargs function.
388: Value not meaningful after store_parm_decls. */
389:
390: static int c_function_varargs;
391:
392: /* The FUNCTION_DECL for the function currently being compiled,
393: or 0 if between functions. */
394: tree current_function_decl;
395:
396: /* Set to 0 at beginning of a function definition, set to 1 if
397: a return statement that specifies a return value is seen. */
398:
399: int current_function_returns_value;
400:
401: /* Set to 0 at beginning of a function definition, set to 1 if
402: a return statement with no argument is seen. */
403:
404: int current_function_returns_null;
405:
406: /* Set to 0 at beginning of a function definition, and whenever
407: a label (case or named) is defined. Set to value of expression
408: returned from function when that value can be transformed into
409: a named return value. */
410:
411: tree current_function_return_value;
412:
413: /* Set to nonzero by `grokdeclarator' for a function
414: whose return type is defaulted, if warnings for this are desired. */
415:
416: static int warn_about_return_type;
417:
418: /* Nonzero when starting a function delcared `extern inline'. */
419:
420: static int current_extern_inline;
421:
422: /* Nonzero means give `double' the same size as `float'. */
423:
424: extern int flag_short_double;
425:
426: /* Pointers to the base and current top of the language name stack. */
427:
428: extern tree *current_lang_base, *current_lang_stack;
429:
430: /* C and C++ flags are in cp-decl2.c. */
431: char *language_string = "GNU C++";
432:
433: /* Set to 0 at beginning of a constructor, set to 1
434: if that function does an allocation before referencing its
435: instance variable. */
436: int current_function_assigns_this;
437: int current_function_just_assigned_this;
438:
439: /* Set to 0 at beginning of a function. Set non-zero when
440: store_parm_decls is called. Don't call store_parm_decls
441: if this flag is non-zero! */
442: int current_function_parms_stored;
443:
444: /* Current end of entries in the gc obstack for stack pointer variables. */
445:
446: int current_function_obstack_index;
447:
448: /* Flag saying whether we have used the obstack in this function or not. */
449:
450: int current_function_obstack_usage;
451:
452: /* Allocate a level of searching. */
453: struct stack_level *
454: push_decl_level (stack, obstack)
455: struct stack_level *stack;
456: struct obstack *obstack;
457: {
458: struct stack_level tem;
459: tem.prev = stack;
460:
461: return push_stack_level (obstack, &tem, sizeof (tem));
462: }
463:
464: /* Discard a level of decl allocation. */
465:
466: static struct stack_level *
467: pop_decl_level (stack)
468: struct stack_level *stack;
469: {
470: tree *bp, *tp;
471: struct obstack *obstack = stack->obstack;
472: bp = stack->first;
473: tp = (tree *)obstack_next_free (obstack);
474: while (tp != bp)
475: {
476: --tp;
477: if (*tp != NULL_TREE)
478: IDENTIFIER_CLASS_VALUE (DECL_NAME (*tp)) = NULL_TREE;
479: }
480: return pop_stack_level (stack);
481: }
482:
483: /* For each binding contour we allocate a binding_level structure
484: * which records the names defined in that contour.
485: * Contours include:
486: * 0) the global one
487: * 1) one for each function definition,
488: * where internal declarations of the parameters appear.
489: * 2) one for each compound statement,
490: * to record its declarations.
491: *
492: * The current meaning of a name can be found by searching the levels from
493: * the current one out to the global one.
494: *
495: * Off to the side, may be the class_binding_level. This exists
496: * only to catch class-local declarations. It is otherwise
497: * nonexistent.
498: *
499: * Also there may be binding levels that catch cleanups that
500: * must be run when exceptions occur.
501: */
502:
503: /* Note that the information in the `names' component of the global contour
504: is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
505:
506: struct binding_level
507: {
508: /* A chain of _DECL nodes for all variables, constants, functions,
509: * and typedef types. These are in the reverse of the order supplied.
510: */
511: tree names;
512:
513: /* A list of structure, union and enum definitions,
514: * for looking up tag names.
515: * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
516: * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
517: * or ENUMERAL_TYPE node.
518: *
519: * C++: the TREE_VALUE nodes can be simple types for component_bindings.
520: *
521: */
522: tree tags;
523:
524: /* For each level, a list of shadowed outer-level local definitions
525: to be restored when this level is popped.
526: Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
527: whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
528: tree shadowed;
529:
530: /* Same, for IDENTIFIER_CLASS_VALUE. */
531: tree class_shadowed;
532:
533: /* Same, for IDENTIFIER_TYPE_VALUE. */
534: tree type_shadowed;
535:
536: /* For each level (except not the global one),
537: a chain of BLOCK nodes for all the levels
538: that were entered and exited one level down. */
539: tree blocks;
540:
541: /* The binding level which this one is contained in (inherits from). */
542: struct binding_level *level_chain;
543:
544: /* Number of decls in `names' that have incomplete
545: structure or union types. */
546: unsigned short n_incomplete;
547:
548: /* 1 for the level that holds the parameters of a function.
549: 2 for the level that holds a class declaration.
550: 3 for levels that hold parameter declarations. */
551: unsigned parm_flag : 4;
552:
553: /* 1 means make a BLOCK for this level regardless of all else.
554: 2 for temporary binding contours created by the compiler. */
555: unsigned keep : 3;
556:
557: /* Nonzero if this level "doesn't exist" for tags. */
558: unsigned tag_transparent : 1;
559:
560: /* Nonzero if this level can safely have additional
561: cleanup-needing variables added to it. */
562: unsigned more_cleanups_ok : 1;
563: unsigned have_cleanups : 1;
564:
565: /* Nonzero if this level can safely have additional
566: exception-raising statements added to it. */
567: unsigned more_exceptions_ok : 1;
568: unsigned have_exceptions : 1;
569:
570: /* Nonzero if we should accept any name as an identifier in
571: this scope. This happens in some template definitions. */
572: unsigned accept_any : 1;
573:
574: /* Three bits left for this word. */
575:
576: #ifdef PARANOID
577: unsigned char depth;
578: #endif
579: };
580:
581: #define NULL_BINDING_LEVEL (struct binding_level *) NULL
582:
583: /* The binding level currently in effect. */
584:
585: static struct binding_level *current_binding_level;
586:
587: /* The binding level of the current class, if any. */
588:
589: static struct binding_level *class_binding_level;
590:
591: /* A chain of binding_level structures awaiting reuse. */
592:
593: static struct binding_level *free_binding_level;
594:
595: /* The outermost binding level, for names of file scope.
596: This is created when the compiler is started and exists
597: through the entire run. */
598:
599: static struct binding_level *global_binding_level;
600:
601: /* Binding level structures are initialized by copying this one. */
602:
603: static struct binding_level clear_binding_level;
604:
605: /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
606:
607: static int keep_next_level_flag;
608:
609: #if PARANOID
610: /* The argument here used to be to distinguish between the different
611: invocations of the function from the {PUSH,POP}_BINDING_LEVEL macros.
612: Since they are functions now, it could probably go away.
613: Also, this function could return void, and have its callers not use
614: assert(), since this will never return if the assertions fail. */
615: static int
616: binding_levels_sane (j)
617: {
618: struct binding_level *b = current_binding_level;
619: static int n;
620: if (++n < 3)
621: return 1;
622: assert (global_binding_level != 0);
623: assert (current_binding_level != 0);
624: for (b = current_binding_level; b != global_binding_level; b = b->level_chain)
625: {
626: assert (b->level_chain != 0);
627: assert (b->depth == 1 + b->level_chain->depth);
628: }
629: if (class_binding_level)
630: for (b = class_binding_level;
631: b != global_binding_level && b != current_binding_level;
632: b = b->level_chain)
633: {
634: assert (b->level_chain != 0);
635: assert (b->depth == 1 + b->level_chain->depth);
636: }
637: assert (global_binding_level->depth == 0);
638: assert (global_binding_level->level_chain == 0);
639: return 1;
640: }
641:
642: #else
643: #define binding_levels_sane(X) (1)
644: #endif
645:
646: #ifdef DEBUG_CP_BINDING_LEVELS
647: int debug_bindings_indentation;
648: #endif
649:
650: static void
651: #if !PARANOID && defined (__GNUC__)
652: __inline
653: #endif
654: push_binding_level (newlevel, tag_transparent, keep)
655: struct binding_level *newlevel;
656: {
657: assert(binding_levels_sane(1));
658: /* Add this level to the front of the chain (stack) of levels that
659: are active. */
660: #ifdef DEBUG_CP_BINDING_LEVELS
661: indent_to (stderr, debug_bindings_indentation);
662: fprintf (stderr, "pushing binding level %x\n", newlevel);
663: #endif
664: *newlevel = clear_binding_level;
665: if (class_binding_level)
666: {
667: newlevel->level_chain = class_binding_level;
668: class_binding_level = 0;
669: }
670: else
671: {
672: newlevel->level_chain = current_binding_level;
673: }
674: current_binding_level = newlevel;
675: newlevel->tag_transparent = tag_transparent;
676: newlevel->more_cleanups_ok = 1;
677: newlevel->more_exceptions_ok = 1;
678: newlevel->keep = keep;
679: #ifdef PARANOID
680: newlevel->depth = (newlevel->level_chain
681: ? newlevel->level_chain->depth + 1
682: : 0);
683: #endif
684: assert(binding_levels_sane(2));
685: }
686:
687: static void
688: #if !PARANOID && defined (__GNUC__)
689: __inline
690: #endif
691: pop_binding_level ()
692: {
693: assert(binding_levels_sane(3));
694: #ifdef DEBUG_CP_BINDING_LEVELS
695: indent_to (stderr, debug_bindings_indentation);
696: fprintf (stderr, "popping binding level %x\n", current_binding_level);
697: #endif
698: if (global_binding_level)
699: assert (current_binding_level != global_binding_level);
700: /* Pop the current level, and free the structure for reuse. */
701: {
702: register struct binding_level *level = current_binding_level;
703: current_binding_level = current_binding_level->level_chain;
704: level->level_chain = free_binding_level;
705: #ifdef DEBUG_CP_BINDING_LEVELS
706: memset (level, 0x69, sizeof (*level));
707: #else
708: free_binding_level = level;
709: #ifdef PARANOID
710: level->depth *= -1;
711: #endif
712: #endif
713: if (current_binding_level->parm_flag == 2)
714: {
715: class_binding_level = current_binding_level;
716: do
717: {
718: current_binding_level = current_binding_level->level_chain;
719: }
720: while (current_binding_level->parm_flag == 2);
721: }
722: }
723: assert(binding_levels_sane(4));
724: }
725:
726: /* Nonzero if we are currently in the global binding level. */
727:
728: int
729: global_bindings_p ()
730: {
731: return current_binding_level == global_binding_level;
732: }
733:
734: void
735: keep_next_level ()
736: {
737: keep_next_level_flag = 1;
738: }
739:
740: /* Nonzero if the current level needs to have a BLOCK made. */
741:
742: int
743: kept_level_p ()
744: {
745: return (current_binding_level->keep
746: || current_binding_level->names != 0);
747: }
748:
749: /* Identify this binding level as a level of parameters. */
750:
751: void
752: declare_parm_level ()
753: {
754: current_binding_level->parm_flag = 1;
755: }
756:
757: /* Identify this binding level as a level of a default exception handler. */
758:
759: void
760: declare_implicit_exception ()
761: {
762: current_binding_level->parm_flag = 3;
763: }
764:
765: /* Nonzero if current binding contour contains expressions
766: that might raise exceptions. */
767:
768: int
769: have_exceptions_p ()
770: {
771: return current_binding_level->have_exceptions;
772: }
773:
774: void
775: declare_uninstantiated_type_level ()
776: {
777: current_binding_level->accept_any = 1;
778: }
779:
780: int
781: uninstantiated_type_level_p ()
782: {
783: return current_binding_level->accept_any;
784: }
785:
786: /* Enter a new binding level.
787: If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
788: not for that of tags. */
789:
790: void
791: pushlevel (tag_transparent)
792: int tag_transparent;
793: {
794: register struct binding_level *newlevel = NULL_BINDING_LEVEL;
795:
796: #ifdef DEBUG_CP_BINDING_LEVELS
797: indent_to (stderr, debug_bindings_indentation);
798: fprintf (stderr, "pushlevel");
799: debug_bindings_indentation += 4;
800: #endif
801:
802: /* If this is the top level of a function,
803: just make sure that NAMED_LABELS is 0.
804: They should have been set to 0 at the end of the previous function. */
805:
806: if (current_binding_level == global_binding_level)
807: assert (named_labels == NULL_TREE);
808:
809: /* Reuse or create a struct for this binding level. */
810:
811: if (free_binding_level)
812: {
813: newlevel = free_binding_level;
814: free_binding_level = free_binding_level->level_chain;
815: }
816: else
817: {
818: /* Create a new `struct binding_level'. */
819: newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
820: }
821: push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
822: GNU_xref_start_scope (newlevel);
823: keep_next_level_flag = 0;
824:
825: #ifdef DEBUG_CP_BINDING_LEVELS
826: debug_bindings_indentation -= 4;
827: #endif
828: }
829:
830: void
831: pushlevel_temporary (tag_transparent)
832: int tag_transparent;
833: {
834: pushlevel (tag_transparent);
835: current_binding_level->keep = 2;
836: clear_last_expr ();
837: #if 0
838: /* Don't call push_momentary here! It will cause cleanups
839: to be allocated on the momentary obstack, and they
840: will be overwritten by the next statement. */
841: push_momentary ();
842: #endif
843: expand_start_bindings (0);
844: }
845:
846: /* Exit a binding level.
847: Pop the level off, and restore the state of the identifier-decl mappings
848: that were in effect when this level was entered.
849:
850: If KEEP == 1, this level had explicit declarations, so
851: and create a "block" (a BLOCK node) for the level
852: to record its declarations and subblocks for symbol table output.
853:
854: If KEEP == 2, this level's subblocks go to the front,
855: not the back of the current binding level. This happens,
856: for instance, when code for constructors and destructors
857: need to generate code at the end of a function which must
858: be moved up to the front of the function.
859:
860: If FUNCTIONBODY is nonzero, this level is the body of a function,
861: so create a block as if KEEP were set and also clear out all
862: label names.
863:
864: If REVERSE is nonzero, reverse the order of decls before putting
865: them into the BLOCK. */
866:
867: tree
868: poplevel (keep, reverse, functionbody)
869: int keep;
870: int reverse;
871: int functionbody;
872: {
873: register tree link;
874: /* The chain of decls was accumulated in reverse order.
875: Put it into forward order, just for cleanliness. */
876: tree decls;
877: int tmp = functionbody;
878: int implicit_try_block = current_binding_level->parm_flag == 3;
879: int real_functionbody = current_binding_level->keep == 2
880: ? ((functionbody = 0), tmp) : functionbody;
881: tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
882: tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
883: tree block = 0;
884: tree decl;
885:
886: #ifdef DEBUG_CP_BINDING_LEVELS
887: indent_to (stderr, debug_bindings_indentation);
888: fprintf (stderr, "poplevel");
889: debug_bindings_indentation += 4;
890: #endif
891:
892: assert (binding_levels_sane (12));
893: GNU_xref_end_scope (current_binding_level,
894: current_binding_level->level_chain,
895: current_binding_level->parm_flag,
896: current_binding_level->keep,
897: current_binding_level->tag_transparent);
898:
899: if (current_binding_level->keep == 1)
900: keep = 1;
901:
902: /* This warning is turned off because it causes warnings for
903: declarations like `extern struct foo *x'. */
904: #if 0
905: /* Warn about incomplete structure types in this level. */
906: for (link = tags; link; link = TREE_CHAIN (link))
907: if (TYPE_SIZE (TREE_VALUE (link)) == 0)
908: {
909: tree type = TREE_VALUE (link);
910: char *errmsg;
911: switch (TREE_CODE (type))
912: {
913: case RECORD_TYPE:
914: errmsg = "`struct %s' incomplete in scope ending here";
915: break;
916: case UNION_TYPE:
917: errmsg = "`union %s' incomplete in scope ending here";
918: break;
919: case ENUMERAL_TYPE:
920: errmsg = "`enum %s' incomplete in scope ending here";
921: break;
922: }
923: if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
924: error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
925: else
926: /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
927: error (errmsg, TYPE_NAME_STRING (type));
928: }
929: #endif /* 0 */
930:
931: /* Get the decls in the order they were written.
932: Usually current_binding_level->names is in reverse order.
933: But parameter decls were previously put in forward order. */
934:
935: if (reverse)
936: current_binding_level->names
937: = decls = nreverse (current_binding_level->names);
938: else
939: decls = current_binding_level->names;
940:
941: /* Output any nested inline functions within this block
942: if they weren't already output. */
943:
944: for (decl = decls; decl; decl = TREE_CHAIN (decl))
945: if (TREE_CODE (decl) == FUNCTION_DECL
946: && ! TREE_ASM_WRITTEN (decl)
947: && DECL_INITIAL (decl) != 0
948: && TREE_ADDRESSABLE (decl))
949: output_inline_function (decl);
950:
951: /* If there were any declarations or structure tags in that level,
952: or if this level is a function body,
953: create a BLOCK to record them for the life of this function. */
954:
955: if (keep == 1 || functionbody > 0)
956: block = build_block (keep ? decls : 0, keep ? tags : 0,
957: subblocks, 0, 0);
958:
959: /* In each subblock, record that this is its superior. */
960:
961: if (keep >= 0)
962: for (link = subblocks; link; link = TREE_CHAIN (link))
963: BLOCK_SUPERCONTEXT (link) = block;
964:
965: /* Clear out the meanings of the local variables of this level. */
966:
967: for (link = decls; link; link = TREE_CHAIN (link))
968: {
969: if (DECL_NAME (link) != 0)
970: {
971: /* If the ident. was used or addressed via a local extern decl,
972: don't forget that fact. */
973: if (TREE_EXTERNAL (link))
974: {
975: if (TREE_USED (link))
976: TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
977: if (TREE_ADDRESSABLE (link))
978: TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
979: }
980: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
981: }
982: }
983:
984: /* Restore all name-meanings of the outer levels
985: that were shadowed by this level. */
986:
987: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
988: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
989: for (link = current_binding_level->class_shadowed;
990: link; link = TREE_CHAIN (link))
991: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
992: for (link = current_binding_level->type_shadowed;
993: link; link = TREE_CHAIN (link))
994: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
995:
996: /* If the level being exited is the top level of a function,
997: check over all the labels. */
998:
999: if (functionbody)
1000: {
1001: /* Clear out the definitions of all label names,
1002: since their scopes end here. */
1003:
1004: for (link = named_labels; link; link = TREE_CHAIN (link))
1005: {
1006: if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
1007: {
1008: error ("label `%s' used somewhere above but not defined",
1009: IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (link))));
1010: /* Avoid crashing later. */
1011: define_label (input_filename, 1, DECL_NAME (TREE_VALUE (link)));
1012: }
1013: else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
1014: warning_with_decl (TREE_VALUE (link),
1015: "label `%s' defined but not used");
1016: SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), 0);
1017: }
1018:
1019: named_labels = 0;
1020: }
1021:
1022: /* Any uses of undefined labels now operate under constraints
1023: of next binding contour. */
1024: {
1025: struct binding_level *level_chain;
1026: level_chain = current_binding_level->level_chain;
1027: if (level_chain)
1028: {
1029: tree labels;
1030: for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
1031: if (TREE_TYPE (labels) == (tree)current_binding_level)
1032: {
1033: TREE_TYPE (labels) = (tree)level_chain;
1034: TREE_PURPOSE (labels) = level_chain->names;
1035: }
1036: }
1037: }
1038:
1039: tmp = current_binding_level->keep;
1040:
1041: pop_binding_level ();
1042: if (functionbody > 0)
1043: {
1044: DECL_INITIAL (current_function_decl) = block;
1045: /* If this is the top level block of a function,
1046: the vars are the function's parameters.
1047: Don't leave them in the BLOCK because they are
1048: found in the FUNCTION_DECL instead. */
1049: BLOCK_VARS (block) = 0;
1050: }
1051: else if (block)
1052: current_binding_level->blocks
1053: = chainon (current_binding_level->blocks, block);
1054: /* If we did not make a block for the level just exited,
1055: any blocks made for inner levels
1056: (since they cannot be recorded as subblocks in that level)
1057: must be carried forward so they will later become subblocks
1058: of something else. */
1059: else if (subblocks)
1060: if (keep == 2)
1061: current_binding_level->blocks = chainon (subblocks, current_binding_level->blocks);
1062: else
1063: current_binding_level->blocks
1064: = chainon (current_binding_level->blocks, subblocks);
1065:
1066: /* Take care of compiler's internal binding structures. */
1067: if (tmp == 2 && !implicit_try_block)
1068: {
1069: #if 0
1070: /* We did not call push_momentary for this
1071: binding contour, so there is nothing to pop. */
1072: pop_momentary ();
1073: #endif
1074: expand_end_bindings (getdecls (), keep, 1);
1075: block = poplevel (keep, reverse, real_functionbody);
1076: }
1077: if (block)
1078: TREE_USED (block) = 1;
1079: assert (binding_levels_sane (13));
1080: #ifdef DEBUG_CP_BINDING_LEVELS
1081: debug_bindings_indentation -= 4;
1082: #endif
1083: return block;
1084: }
1085:
1086: /* Add BLOCK to the current list of blocks for this binding contour. */
1087: void
1088: add_block_current_level (block)
1089: tree block;
1090: {
1091: current_binding_level->blocks
1092: = chainon (current_binding_level->blocks, block);
1093: }
1094:
1095: /* Do a pushlevel for class declarations. */
1096: void
1097: pushlevel_class ()
1098: {
1099: assert (binding_levels_sane (5));
1100: #ifdef DEBUG_CP_BINDING_LEVELS
1101: indent_to (stderr, debug_bindings_indentation);
1102: fprintf (stderr, "pushlevel_class");
1103: debug_bindings_indentation += 4;
1104: #endif
1105: pushlevel (0);
1106: decl_stack = push_decl_level (decl_stack, &decl_obstack);
1107: class_binding_level = current_binding_level;
1108: class_binding_level->parm_flag = 2;
1109: do
1110: {
1111: current_binding_level = current_binding_level->level_chain;
1112: }
1113: while (current_binding_level->parm_flag == 2);
1114: assert (binding_levels_sane (6));
1115: #ifdef DEBUG_CP_BINDING_LEVELS
1116: debug_bindings_indentation -= 4;
1117: #endif
1118: }
1119:
1120: /* ...and a poplevel for class declarations. */
1121: tree
1122: poplevel_class ()
1123: {
1124: register struct binding_level *level = class_binding_level;
1125: tree block = 0;
1126: tree shadowed;
1127:
1128: #ifdef DEBUG_CP_BINDING_LEVELS
1129: indent_to (stderr, debug_bindings_indentation);
1130: fprintf (stderr, "poplevel_class");
1131: debug_bindings_indentation += 4;
1132: #endif
1133: assert (binding_levels_sane (7));
1134: if (level == 0)
1135: {
1136: while (current_binding_level && class_binding_level == 0)
1137: block = poplevel (0, 0, 0);
1138: if (current_binding_level == 0)
1139: fatal ("syntax error too serious");
1140: level = class_binding_level;
1141: }
1142: decl_stack = pop_decl_level (decl_stack);
1143: for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1144: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1145: for (shadowed = level->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1146: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1147: for (shadowed = level->type_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1148: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1149:
1150: GNU_xref_end_scope (class_binding_level,
1151: class_binding_level->level_chain,
1152: class_binding_level->parm_flag,
1153: class_binding_level->keep,
1154: class_binding_level->tag_transparent);
1155:
1156: class_binding_level = level->level_chain;
1157: if (class_binding_level->parm_flag != 2)
1158: class_binding_level = 0;
1159:
1160: #ifdef DEBUG_CP_BINDING_LEVELS
1161: indent_to (stderr, debug_bindings_indentation);
1162: fprintf (stderr, "popping class binding level %x\n", level);
1163: memset (level, 0x69, sizeof (*level));
1164: debug_bindings_indentation -= 4;
1165: #else
1166: level->level_chain = free_binding_level;
1167: free_binding_level = level;
1168: #endif
1169: assert (binding_levels_sane (8));
1170:
1171: return block;
1172: }
1173:
1174: /* For debugging. */
1175: int no_print_functions = 0;
1176: int no_print_builtins = 0;
1177:
1178: void
1179: print_binding_level (lvl)
1180: struct binding_level *lvl;
1181: {
1182: tree t;
1183: int i = 0, len;
1184: fprintf (stderr, " blocks=%x n_incomplete=%d parm_flag=%d keep=%d",
1185: lvl->blocks, lvl->n_incomplete, lvl->parm_flag, lvl->keep);
1186: if (lvl->tag_transparent)
1187: fprintf (stderr, " tag-transparent");
1188: if (lvl->more_cleanups_ok)
1189: fprintf (stderr, " more-cleanups-ok");
1190: if (lvl->have_cleanups)
1191: fprintf (stderr, " have-cleanups");
1192: if (lvl->more_exceptions_ok)
1193: fprintf (stderr, " more-exceptions-ok");
1194: if (lvl->have_exceptions)
1195: fprintf (stderr, " have-exceptions");
1196: fprintf (stderr, "\n");
1197: if (lvl->names)
1198: {
1199: fprintf (stderr, " names:\t");
1200: /* We can probably fit 3 names to a line? */
1201: for (t = lvl->names; t; t = TREE_CHAIN (t))
1202: {
1203: if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL))
1204: continue;
1205: if (no_print_builtins
1206: && (TREE_CODE(t) == TYPE_DECL)
1207: && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
1208: continue;
1209:
1210: /* Function decls tend to have longer names. */
1211: if (TREE_CODE (t) == FUNCTION_DECL)
1212: len = 3;
1213: else
1214: len = 2;
1215: i += len;
1216: if (i > 6)
1217: {
1218: fprintf (stderr, "\n\t");
1219: i = len;
1220: }
1221: print_node_brief (stderr, "", t, 0);
1222: if (TREE_CODE (t) == ERROR_MARK)
1223: break;
1224: }
1225: if (i)
1226: fprintf (stderr, "\n");
1227: }
1228: if (lvl->tags)
1229: {
1230: fprintf (stderr, " tags:\t");
1231: i = 0;
1232: for (t = lvl->tags; t; t = TREE_CHAIN (t))
1233: {
1234: if (TREE_PURPOSE (t) == NULL_TREE)
1235: len = 3;
1236: else if (TREE_PURPOSE (t) == DECL_NAME (TYPE_NAME (TREE_VALUE (t))))
1237: len = 2;
1238: else
1239: len = 4;
1240: i += len;
1241: if (i > 5)
1242: {
1243: fprintf (stderr, "\n\t");
1244: i = len;
1245: }
1246: if (TREE_PURPOSE (t) == NULL_TREE)
1247: {
1248: print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1249: fprintf (stderr, ">");
1250: }
1251: else if (TREE_PURPOSE (t) == DECL_NAME (TYPE_NAME (TREE_VALUE (t))))
1252: print_node_brief (stderr, "", TREE_VALUE (t), 0);
1253: else
1254: {
1255: print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1256: print_node_brief (stderr, "", TREE_VALUE (t), 0);
1257: fprintf (stderr, ">");
1258: }
1259: }
1260: if (i)
1261: fprintf (stderr, "\n");
1262: }
1263: if (lvl->shadowed)
1264: {
1265: fprintf (stderr, " shadowed:");
1266: for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1267: {
1268: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1269: }
1270: fprintf (stderr, "\n");
1271: }
1272: if (lvl->class_shadowed)
1273: {
1274: fprintf (stderr, " class-shadowed:");
1275: for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1276: {
1277: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1278: }
1279: fprintf (stderr, "\n");
1280: }
1281: if (lvl->type_shadowed)
1282: {
1283: fprintf (stderr, " type-shadowed:");
1284: for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1285: {
1286: #if 0
1287: fprintf (stderr, "\n\t");
1288: print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
1289: if (TREE_VALUE (t))
1290: print_node_brief (stderr, " ", TREE_VALUE (t), 0);
1291: else
1292: fprintf (stderr, " (none)");
1293: fprintf (stderr, ">");
1294: #else
1295: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1296: #endif
1297: }
1298: fprintf (stderr, "\n");
1299: }
1300: }
1301:
1302: void
1303: print_other_binding_stack (stack)
1304: struct binding_level *stack;
1305: {
1306: struct binding_level *level;
1307: for (level = stack; level != global_binding_level; level = level->level_chain)
1308: {
1309: fprintf (stderr, "binding level %x\n", level);
1310: print_binding_level (level);
1311: }
1312: }
1313:
1314: void
1315: print_binding_stack ()
1316: {
1317: struct binding_level *b;
1318: fprintf (stderr, "current_binding_level=%8x\n", current_binding_level);
1319: fprintf (stderr, "class_binding_level= %8x\n", class_binding_level);
1320: fprintf (stderr, "global_binding_level= %8x\n", global_binding_level);
1321: if (class_binding_level)
1322: {
1323: for (b = class_binding_level; b; b = b->level_chain)
1324: if (b == current_binding_level)
1325: break;
1326: if (b)
1327: b = class_binding_level;
1328: else
1329: b = current_binding_level;
1330: }
1331: else
1332: b = current_binding_level;
1333: print_other_binding_stack (b);
1334: fprintf (stderr, "global:\n");
1335: print_binding_level (global_binding_level);
1336: }
1337:
1338: /* Subroutines for reverting temporarily to top-level for instantiation
1339: of templates and such. We actually need to clear out the class- and
1340: local-value slots of all identifiers, so that only the global values
1341: are at all visible. Simply setting current_binding_level to the global
1342: scope isn't enough, because more binding levels may be pushed. */
1343: struct saved_scope {
1344: struct binding_level *old_binding_level;
1345: tree old_bindings;
1346: struct saved_scope *prev;
1347: tree class_name, class_type, class_decl, function_decl;
1348: struct binding_level *class_bindings;
1349: };
1350: static struct saved_scope *current_saved_scope;
1351: extern tree prev_class_type;
1352:
1353: void
1354: push_to_top_level ()
1355: {
1356: struct saved_scope *s =
1357: (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1358: struct binding_level *b = current_binding_level;
1359: tree old_bindings = NULL_TREE;
1360:
1361: #ifdef DEBUG_CP_BINDING_LEVELS
1362: fprintf (stderr, "PUSH_TO_TOP_LEVEL\n");
1363: #endif
1364:
1365: /* Have to include global_binding_level, because class-level decls
1366: aren't listed anywhere useful. */
1367: for (; b; b = b->level_chain)
1368: {
1369: tree t;
1370: for (t = b->names; t; t = TREE_CHAIN (t))
1371: if (b != global_binding_level)
1372: {
1373: tree binding, t1, t2 = t;
1374: tree id = DECL_ASSEMBLER_NAME (t2);
1375:
1376: if (!id
1377: || (!IDENTIFIER_LOCAL_VALUE (id)
1378: && !IDENTIFIER_CLASS_VALUE (id)))
1379: continue;
1380:
1381: for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1382: if (TREE_VEC_ELT (t1, 0) == id)
1383: goto skip_it;
1384:
1385: binding = make_tree_vec (4);
1386: if (id)
1387: {
1388: assert (TREE_CODE (id) == IDENTIFIER_NODE);
1389: TREE_VEC_ELT (binding, 0) = id;
1390: TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1391: TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1392: TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1393: IDENTIFIER_LOCAL_VALUE (id) = 0;
1394: IDENTIFIER_CLASS_VALUE (id) = 0;
1395: adjust_type_value (id);
1396: }
1397: TREE_CHAIN (binding) = old_bindings;
1398: old_bindings = binding;
1399: skip_it:
1400: ;
1401: }
1402: /* Unwind type-value slots back to top level. */
1403: if (b != global_binding_level)
1404: for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1405: SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1406: }
1407:
1408: s->old_binding_level = current_binding_level;
1409: current_binding_level = global_binding_level;
1410:
1411: s->class_name = current_class_name;
1412: s->class_type = current_class_type;
1413: s->class_decl = current_class_decl;
1414: s->function_decl = current_function_decl;
1415: s->class_bindings = class_binding_level;
1416: current_class_name = current_class_type = current_class_decl = 0;
1417: current_function_decl = 0;
1418: class_binding_level = 0;
1419:
1420: s->prev = current_saved_scope;
1421: s->old_bindings = old_bindings;
1422: current_saved_scope = s;
1423: assert (binding_levels_sane (10));
1424: }
1425:
1426: void
1427: pop_from_top_level ()
1428: {
1429: struct saved_scope *s = current_saved_scope;
1430: tree t;
1431:
1432: #ifdef DEBUG_CP_BINDING_LEVELS
1433: fprintf (stderr, "POP_FROM_TOP_LEVEL\n");
1434: #endif
1435:
1436: assert (binding_levels_sane (11));
1437: current_binding_level = s->old_binding_level;
1438: current_saved_scope = s->prev;
1439: for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1440: {
1441: tree id = TREE_VEC_ELT (t, 0);
1442: if (id)
1443: {
1444: IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1445: IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1446: IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1447: }
1448: }
1449: current_class_name = s->class_name;
1450: current_class_type = s->class_type;
1451: current_class_decl = s->class_decl;
1452: current_function_decl = s->function_decl;
1453: class_binding_level = s->class_bindings;
1454: free (s);
1455: assert (binding_levels_sane (9));
1456: }
1457:
1458: /* Push a definition of struct, union or enum tag "name".
1459: "type" should be the type node.
1460: We assume that the tag "name" is not already defined.
1461:
1462: Note that the definition may really be just a forward reference.
1463: In that case, the TYPE_SIZE will be zero.
1464:
1465: C++ gratuitously puts all these tags in the name space. */
1466:
1467: /* When setting the IDENTIFER_TYPE_VALUE field of an identifier ID,
1468: record the shadowed value for this binding contour. TYPE is
1469: the type that ID maps to. */
1470: void
1471: set_identifier_type_value (id, type)
1472: tree id;
1473: tree type;
1474: {
1475: if (current_binding_level != global_binding_level)
1476: {
1477: tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1478: current_binding_level->type_shadowed
1479: = tree_cons (id, old_type_value, current_binding_level->type_shadowed);
1480: }
1481: else if (class_binding_level)
1482: {
1483: tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1484: class_binding_level->type_shadowed
1485: = tree_cons (id, old_type_value, class_binding_level->type_shadowed);
1486: }
1487: SET_IDENTIFIER_TYPE_VALUE (id, type);
1488: }
1489:
1490: /*
1491: * local values can need to be shadowed too, but it only happens
1492: * explicitly from pushdecl, in support of nested enums.
1493: */
1494: void
1495: set_identifier_local_value (id, type)
1496: tree id;
1497: tree type;
1498: {
1499: if (current_binding_level != global_binding_level)
1500: {
1501: tree old_local_value = IDENTIFIER_LOCAL_VALUE (id);
1502: current_binding_level->shadowed
1503: = tree_cons (id, old_local_value, current_binding_level->shadowed);
1504: }
1505: else if (class_binding_level)
1506: {
1507: tree old_local_value = IDENTIFIER_LOCAL_VALUE (id);
1508: class_binding_level->shadowed
1509: = tree_cons (id, old_local_value, class_binding_level->shadowed);
1510: }
1511: IDENTIFIER_LOCAL_VALUE (id) = type;
1512: }
1513:
1514: /* Subroutine "set_nested_typename" builds the nested-typename of
1515: the type decl in question. (Argument CLASSNAME can actually be
1516: a function as well, if that's the smallest containing scope.) */
1517:
1518: static void
1519: set_nested_typename (decl, classname, name, type)
1520: tree decl, classname, name, type;
1521: {
1522: assert (TREE_CODE (decl) == TYPE_DECL);
1523: if (classname != 0)
1524: {
1525: char *buf;
1526: assert (TREE_CODE (classname) == IDENTIFIER_NODE);
1527: assert (TREE_CODE (name) == IDENTIFIER_NODE);
1528: buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
1529: + IDENTIFIER_LENGTH (name));
1530: sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
1531: IDENTIFIER_POINTER (name));
1532: DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
1533: SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
1534: }
1535: else
1536: DECL_NESTED_TYPENAME (decl) = name;
1537: }
1538:
1539: void
1540: pushtag (name, type)
1541: tree name, type;
1542: {
1543: register struct binding_level *b;
1544:
1545: if (class_binding_level)
1546: b = class_binding_level;
1547: else
1548: {
1549: b = current_binding_level;
1550: while (b->tag_transparent) b = b->level_chain;
1551: }
1552:
1553: if (name)
1554: {
1555: /* Record the identifier as the type's name if it has none. */
1556:
1557: if (TYPE_NAME (type) == 0)
1558: TYPE_NAME (type) = name;
1559:
1560: if (b == global_binding_level)
1561: b->tags = perm_tree_cons (name, type, b->tags);
1562: else
1563: b->tags = saveable_tree_cons (name, type, b->tags);
1564:
1565: /* Do C++ gratuitous typedefing. */
1566: if (IDENTIFIER_TYPE_VALUE (name) != type
1567: && (TREE_CODE (type) != RECORD_TYPE
1568: || class_binding_level == 0
1569: || !CLASSTYPE_DECLARED_EXCEPTION (type)))
1570: {
1571: register tree d;
1572: if (current_class_type == 0
1573: || TYPE_SIZE (current_class_type) != NULL_TREE)
1574: {
1575: if (current_lang_name == lang_name_cplusplus)
1576: d = lookup_nested_type (type, current_class_type ? TYPE_NAME (current_class_type) : NULL_TREE);
1577: else
1578: d = NULL_TREE;
1579:
1580: if (d == NULL_TREE)
1581: {
1582: d = build_decl (TYPE_DECL, name, type);
1583: set_identifier_type_value (name, type);
1584: }
1585: else
1586: d = TYPE_NAME (d);
1587:
1588: /* If it is anonymous, then we are called from pushdecl,
1589: and we don't want to infinitely recurse. Also, if the
1590: name is already in scope, we don't want to push it
1591: again--pushdecl is only for pushing new decls. */
1592: if (! ANON_AGGRNAME_P (name)
1593: && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
1594: || lookup_name (name, 1) != TYPE_NAME (type)))
1595: {
1596: if (class_binding_level)
1597: d = pushdecl_class_level (d);
1598: else
1599: d = pushdecl (d);
1600: }
1601: }
1602: else
1603: {
1604: /* Make nested declarations go into class-level scope. */
1605: d = build_lang_field_decl (TYPE_DECL, name, type);
1606: set_identifier_type_value (name, type);
1607: d = pushdecl_class_level (d);
1608: }
1609: if (ANON_AGGRNAME_P (name))
1610: DECL_IGNORED_P (d) = 1;
1611: TYPE_NAME (type) = d;
1612:
1613: if ((current_class_type == NULL_TREE
1614: && current_function_decl == NULL_TREE)
1615: || current_lang_name != lang_name_cplusplus)
1616: /* Non-nested class. */
1617: DECL_NESTED_TYPENAME (d) = name;
1618: else if (current_function_decl != NULL_TREE)
1619: {
1620: /* Function-nested class. */
1621: set_nested_typename (d, DECL_ASSEMBLER_NAME (current_function_decl),
1622: name, type);
1623: /* This builds the links for classes nested in fn scope. */
1624: DECL_CONTEXT (d) = current_function_decl;
1625: }
1626: else if (TYPE_SIZE (current_class_type) == NULL_TREE)
1627: {
1628: /* Class-nested class. */
1629: set_nested_typename (d, DECL_NESTED_TYPENAME (TYPE_NAME (current_class_type)),
1630: name, type);
1631: /* This builds the links for classes nested in type scope. */
1632: DECL_CONTEXT (d) = current_class_type;
1633: DECL_CLASS_CONTEXT (d) = current_class_type;
1634: }
1635: }
1636: if (b->parm_flag == 2)
1637: {
1638: TREE_NONLOCAL_FLAG (type) = 1;
1639: IDENTIFIER_CLASS_VALUE (name) = TYPE_NAME (type);
1640: if (TYPE_SIZE (current_class_type) == NULL_TREE)
1641: CLASSTYPE_TAGS (current_class_type) = b->tags;
1642: }
1643:
1644: if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1645: /* Use the canonical TYPE_DECL for this node. */
1646: TYPE_STUB_DECL (type) = TYPE_NAME (type);
1647: else
1648: {
1649: /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
1650: will be the tagged type we just added to the current
1651: binding level. This fake NULL-named TYPE_DECL node helps
1652: dwarfout.c to know when it needs to output a a
1653: representation of a tagged type, and it also gives us a
1654: convenient place to record the "scope start" address for
1655: the tagged type. */
1656:
1657: TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL, type));
1658: }
1659: }
1660: }
1661:
1662: /* Counter used to create anonymous type names. */
1663: static int anon_cnt = 0;
1664:
1665: /* Return an IDENTIFIER which can be used as a name for
1666: anonymous structs and unions. */
1667: tree
1668: make_anon_name ()
1669: {
1670: char buf[32];
1671:
1672: sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
1673: return get_identifier (buf);
1674: }
1675:
1676: /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
1677: This keeps dbxout from getting confused. */
1678: void
1679: clear_anon_tags ()
1680: {
1681: register struct binding_level *b = current_binding_level;
1682: register tree tags;
1683: static int last_cnt = 0;
1684:
1685: /* Fast out if no new anon names were declared. */
1686: if (last_cnt == anon_cnt)
1687: return;
1688:
1689: while (b->tag_transparent) b = b->level_chain;
1690: tags = b->tags;
1691: while (tags)
1692: {
1693: /* A NULL purpose means we have already processed all tags
1694: from here to the end of the list. */
1695: if (TREE_PURPOSE (tags) == NULL_TREE)
1696: break;
1697: if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
1698: TREE_PURPOSE (tags) = NULL_TREE;
1699: tags = TREE_CHAIN (tags);
1700: }
1701: last_cnt = anon_cnt;
1702: }
1703:
1704: /* Subroutine of duplicate_decls: return truthvalue of whether
1705: or not types of these decls match. */
1706: static int
1707: decls_match (newdecl, olddecl)
1708: tree newdecl, olddecl;
1709: {
1710: int types_match;
1711:
1712: if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL)
1713: {
1714: tree f1 = TREE_TYPE (newdecl);
1715: tree f2 = TREE_TYPE (olddecl);
1716: tree p1 = TYPE_ARG_TYPES (f1);
1717: tree p2 = TYPE_ARG_TYPES (f2);
1718:
1719: /* When we parse a static member function definition,
1720: we put together a FUNCTION_DECL which thinks its type
1721: is METHOD_TYPE. Change that to FUNCTION_TYPE, and
1722: proceed. */
1723: if (TREE_CODE (f1) == METHOD_TYPE
1724: && DECL_STATIC_FUNCTION_P (olddecl))
1725: {
1726: tree n1;
1727: p1 = TREE_CHAIN (p1);
1728: n1 = build_function_type (TREE_TYPE (f1), p1);
1729: n1 = build_type_variant (n1, TYPE_READONLY (f1), TYPE_VOLATILE (f1));
1730: n1 = build_exception_variant (TYPE_METHOD_BASETYPE (f1), n1, TYPE_RAISES_EXCEPTIONS (f1));
1731: TREE_TYPE (newdecl) = n1;
1732: f1 = n1;
1733: DECL_STATIC_FUNCTION_P (newdecl) = 1;
1734: }
1735: /* Here we must take care of the case where new default
1736: parameters are specified. Also, warn if an old
1737: declaration becomes ambiguous because default
1738: parameters may cause the two to be ambiguous. */
1739: if (TREE_CODE (f1) != TREE_CODE (f2))
1740: {
1741: if (TREE_CODE (f1) == OFFSET_TYPE)
1742: compiler_error_with_decl (newdecl, "`%s' redeclared as member function");
1743: else
1744: compiler_error_with_decl (newdecl, "`%s' redeclared as non-member function");
1745: return 0;
1746: }
1747:
1748: if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)),
1749: TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 1))
1750: types_match = compparms (p1, p2, 1);
1751: else types_match = 0;
1752: }
1753: else
1754: {
1755: if (TREE_TYPE (newdecl) == error_mark_node)
1756: types_match = TREE_TYPE (olddecl) == error_mark_node;
1757: else
1758: types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
1759: }
1760:
1761: return types_match;
1762: }
1763:
1764: /* Handle when a new declaration NEWDECL has the same name as an old
1765: one OLDDECL in the same binding contour. Prints an error message
1766: if appropriate.
1767:
1768: If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
1769: Otherwise, return 0. */
1770:
1771: static int
1772: duplicate_decls (newdecl, olddecl)
1773: register tree newdecl, olddecl;
1774: {
1775: extern struct obstack permanent_obstack;
1776: int types_match;
1777: int new_is_definition;
1778:
1779: if (TREE_CODE (olddecl) == TREE_LIST
1780: && TREE_CODE (newdecl) == FUNCTION_DECL)
1781: {
1782: /* If a new decl finds a list of old decls, then
1783: we assume that the new decl has C linkage, and
1784: that the old decls have C++ linkage. In this case,
1785: we must look through the list to see whether
1786: there is an ambiguity or not. */
1787: tree olddecls = olddecl;
1788:
1789: /* If the overload list is empty, just install the decl. */
1790: if (TREE_VALUE (olddecls) == NULL_TREE)
1791: {
1792: TREE_VALUE (olddecls) = newdecl;
1793: return 1;
1794: }
1795:
1796: while (olddecls)
1797: {
1798: if (decls_match (newdecl, TREE_VALUE (olddecls)))
1799: {
1800: if (TREE_CODE (newdecl) == VAR_DECL)
1801: ;
1802: else if (DECL_LANGUAGE (newdecl)
1803: != DECL_LANGUAGE (TREE_VALUE (olddecls)))
1804: {
1805: error_with_decl (newdecl, "declaration of `%s' with different language linkage");
1806: error_with_decl (TREE_VALUE (olddecls), "previous declaration here");
1807: }
1808: types_match = 1;
1809: break;
1810: }
1811: olddecls = TREE_CHAIN (olddecls);
1812: }
1813: if (olddecls)
1814: olddecl = TREE_VALUE (olddecl);
1815: else
1816: return 1;
1817: }
1818: else
1819: types_match = decls_match (newdecl, olddecl);
1820:
1821: if ((TREE_TYPE (newdecl) && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
1822: || (TREE_TYPE (olddecl) && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
1823: types_match = 0;
1824:
1825: /* If this decl has linkage, and the old one does too, maybe no error. */
1826: if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1827: {
1828: error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
1829: if (TREE_CODE (olddecl) == TREE_LIST)
1830: olddecl = TREE_VALUE (olddecl);
1831: error_with_decl (olddecl, "previous declaration of `%s'");
1832:
1833: /* New decl is completely inconsistent with the old one =>
1834: tell caller to replace the old one. */
1835:
1836: return 0;
1837: }
1838:
1839: if (TREE_CODE (newdecl) == FUNCTION_DECL)
1840: {
1841: /* Now that functions must hold information normally held
1842: by field decls, there is extra work to do so that
1843: declaration information does not get destroyed during
1844: definition. */
1845: if (DECL_VINDEX (olddecl))
1846: DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
1847: if (DECL_CONTEXT (olddecl))
1848: DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1849: if (DECL_CLASS_CONTEXT (olddecl))
1850: DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
1851: #ifdef SOS
1852: if (DECL_DINDEX (olddecl))
1853: DECL_DINDEX (newdecl) = DECL_DINDEX (newdecl);
1854: #endif
1855: if (DECL_CHAIN (newdecl) == 0)
1856: DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
1857: if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
1858: DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
1859: }
1860:
1861: if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
1862: && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
1863: /* If -traditional, avoid error for redeclaring fcn
1864: after implicit decl. */
1865: ;
1866: else if (TREE_CODE (olddecl) == FUNCTION_DECL
1867: && DECL_BUILT_IN (olddecl))
1868: {
1869: if (!types_match)
1870: {
1871: error_with_decl (newdecl, "declaration of `%s'");
1872: error_with_decl (olddecl, "conflicts with built-in declaration `%s'");
1873: }
1874: }
1875: else if (!types_match)
1876: {
1877: tree oldtype = TREE_TYPE (olddecl);
1878: tree newtype = TREE_TYPE (newdecl);
1879: int give_error = 0;
1880:
1881: /* Already complained about this, so don't do so again. */
1882: if (current_class_type == NULL_TREE
1883: || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
1884: {
1885: give_error = 1;
1886: error_with_decl (newdecl, "conflicting types for `%s'");
1887: }
1888:
1889: /* Check for function type mismatch
1890: involving an empty arglist vs a nonempty one. */
1891: if (TREE_CODE (olddecl) == FUNCTION_DECL
1892: && comptypes (TREE_TYPE (oldtype),
1893: TREE_TYPE (newtype), 1)
1894: && ((TYPE_ARG_TYPES (oldtype) == 0
1895: && DECL_INITIAL (olddecl) == 0)
1896: || (TYPE_ARG_TYPES (newtype) == 0
1897: && DECL_INITIAL (newdecl) == 0)))
1898: {
1899: /* Classify the problem further. */
1900: register tree t = TYPE_ARG_TYPES (oldtype);
1901: if (t == 0)
1902: t = TYPE_ARG_TYPES (newtype);
1903: for (; t; t = TREE_CHAIN (t))
1904: {
1905: register tree type = TREE_VALUE (t);
1906:
1907: if (TREE_CHAIN (t) == 0 && type != void_type_node)
1908: {
1909: error ("A parameter list with an ellipsis can't match");
1910: error ("an empty parameter name list declaration.");
1911: break;
1912: }
1913:
1914: if (type == float_type_node
1915: || (TREE_CODE (type) == INTEGER_TYPE
1916: && (TYPE_PRECISION (type)
1917: < TYPE_PRECISION (integer_type_node))))
1918: {
1919: error ("An argument type that has a default promotion");
1920: error ("can't match an empty parameter name list declaration.");
1921: break;
1922: }
1923: }
1924: }
1925: if (give_error)
1926: error_with_decl (olddecl, "previous declaration of `%s'");
1927:
1928: /* There is one thing GNU C++ cannot tolerate: a constructor
1929: which takes the type of object being constructed.
1930: Farm that case out here. */
1931: if (TREE_CODE (newdecl) == FUNCTION_DECL
1932: && DECL_CONSTRUCTOR_P (newdecl))
1933: {
1934: tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype));
1935:
1936: if (tmp != NULL_TREE
1937: && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp))
1938: == TYPE_METHOD_BASETYPE (newtype)))
1939: {
1940: tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl));
1941: tree argtypes
1942: = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)),
1943: TREE_CHAIN (tmp));
1944:
1945: DECL_ARG_TYPE (parm)
1946: = TREE_TYPE (parm)
1947: = TYPE_REFERENCE_TO (TREE_VALUE (tmp));
1948:
1949: TREE_TYPE (newdecl) = newtype
1950: = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype),
1951: TREE_TYPE (newtype), argtypes);
1952: error ("constructor cannot take as argument the type being constructed");
1953: SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl), current_class_type);
1954: }
1955: }
1956: }
1957: else
1958: {
1959: char *errmsg = redeclaration_error_message (newdecl, olddecl);
1960: if (errmsg)
1961: {
1962: error_with_decl (newdecl, errmsg);
1963: if (DECL_NAME (olddecl) != NULL_TREE)
1964: error_with_decl (olddecl,
1965: "here is the previous declaration of `%s'");
1966: }
1967: else if (TREE_CODE (olddecl) == FUNCTION_DECL
1968: && DECL_INITIAL (olddecl) != 0
1969: && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == 0
1970: && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0)
1971: {
1972: /* Prototype decl follows defn w/o prototype. */
1973: warning_with_decl (newdecl, "prototype for `%s'");
1974: warning_with_decl (olddecl,
1975: "follows non-prototype definition here");
1976: }
1977:
1978: /* These bits are logically part of the type. */
1979: if (pedantic
1980: && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
1981: || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
1982: error_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
1983: }
1984:
1985: /* Deal with C++: must preserve virtual function table size. */
1986: if (TREE_CODE (olddecl) == TYPE_DECL)
1987: {
1988: if (TYPE_LANG_SPECIFIC (TREE_TYPE (newdecl))
1989: && TYPE_LANG_SPECIFIC (TREE_TYPE (olddecl)))
1990: {
1991: CLASSTYPE_VSIZE (TREE_TYPE (newdecl))
1992: = CLASSTYPE_VSIZE (TREE_TYPE (olddecl));
1993: CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (newdecl))
1994: = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (olddecl));
1995: }
1996: assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl));
1997: }
1998:
1999: new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
2000: && DECL_INITIAL (newdecl) != 0);
2001:
2002: /* Copy all the DECL_... slots specified in the new decl
2003: except for any that we copy here from the old type. */
2004:
2005: if (types_match)
2006: {
2007: /* Automatically handles default parameters. */
2008: tree oldtype = TREE_TYPE (olddecl);
2009: /* Merge the data types specified in the two decls. */
2010: tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2011:
2012: if (TREE_CODE (newdecl) == VAR_DECL)
2013: DECL_EXTERNAL (newdecl) |= DECL_EXTERNAL (olddecl);
2014: /* Do this after calling `common_type' so that default
2015: parameters don't confuse us. */
2016: else if (TREE_CODE (newdecl) == FUNCTION_DECL
2017: && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2018: != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2019: {
2020: tree ctype = NULL_TREE;
2021: ctype = DECL_CLASS_CONTEXT (newdecl);
2022: TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
2023: TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2024: TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
2025: TYPE_RAISES_EXCEPTIONS (oldtype));
2026:
2027: if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
2028: {
2029: error_with_decl (newdecl, "declaration of `%s' raises different exceptions...");
2030: error_with_decl (olddecl, "...from previous declaration here");
2031: }
2032: }
2033: TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2034:
2035: /* Lay the type out, unless already done. */
2036: if (oldtype != TREE_TYPE (newdecl))
2037: {
2038: if (TREE_TYPE (newdecl) != error_mark_node)
2039: layout_type (TREE_TYPE (newdecl));
2040: if (TREE_CODE (newdecl) != FUNCTION_DECL
2041: && TREE_CODE (newdecl) != TYPE_DECL
2042: && TREE_CODE (newdecl) != CONST_DECL)
2043: layout_decl (newdecl, 0);
2044: }
2045: else
2046: {
2047: /* Since the type is OLDDECL's, make OLDDECL's size go with. */
2048: DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
2049: }
2050:
2051: /* Merge the type qualifiers. */
2052: if (TREE_READONLY (newdecl))
2053: TREE_READONLY (olddecl) = 1;
2054: if (TREE_THIS_VOLATILE (newdecl))
2055: TREE_THIS_VOLATILE (olddecl) = 1;
2056:
2057: /* Merge the initialization information. */
2058: if (DECL_INITIAL (newdecl) == 0)
2059: DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2060: /* Keep the old rtl since we can safely use it. */
2061: DECL_RTL (newdecl) = DECL_RTL (olddecl);
2062: }
2063: /* If cannot merge, then use the new type and qualifiers,
2064: and don't preserve the old rtl. */
2065: else
2066: {
2067: /* Clean out any memory we had of the old declaration. */
2068: tree oldstatic = value_member (olddecl, static_aggregates);
2069: if (oldstatic)
2070: TREE_VALUE (oldstatic) = error_mark_node;
2071:
2072: TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2073: TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2074: TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2075: TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2076: }
2077:
2078: /* Merge the storage class information. */
2079: if (TREE_EXTERNAL (newdecl))
2080: {
2081: TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2082: TREE_EXTERNAL (newdecl) = TREE_EXTERNAL (olddecl);
2083:
2084: /* For functions, static overrides non-static. */
2085: if (TREE_CODE (newdecl) == FUNCTION_DECL)
2086: {
2087: TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
2088: /* This is since we don't automatically
2089: copy the attributes of NEWDECL into OLDDECL. */
2090: TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2091: /* If this clears `static', clear it in the identifier too. */
2092: if (! TREE_PUBLIC (olddecl))
2093: TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0;
2094: }
2095: else
2096: TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2097: }
2098: else
2099: {
2100: TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2101: TREE_EXTERNAL (olddecl) = 0;
2102: /* A `const' which was not declared `extern' and is
2103: in static storage is invisible. */
2104: if (TREE_CODE (newdecl) == VAR_DECL
2105: && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
2106: && ! DECL_EXTERNAL (newdecl))
2107: TREE_PUBLIC (newdecl) = 0;
2108: TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2109: }
2110: /* If either decl says `inline', this fn is inline,
2111: unless its definition was passed already. */
2112: TREE_INLINE (olddecl) |= TREE_INLINE (newdecl);
2113:
2114: if (TREE_CODE (newdecl) == FUNCTION_DECL)
2115: {
2116: if (new_is_definition)
2117: /* If defining a function declared with other language
2118: linkage, use the previously declared language linkage. */
2119: DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2120: else
2121: {
2122: /* If redeclaring a builtin function, and not a definition,
2123: it stays built in. */
2124: if (DECL_BUILT_IN (olddecl))
2125: {
2126: DECL_BUILT_IN (newdecl) = 1;
2127: DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl));
2128: /* If we're keeping the built-in definition, keep the rtl,
2129: regardless of declaration matches. */
2130: DECL_RTL (newdecl) = DECL_RTL (olddecl);
2131: }
2132: else
2133: DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2134:
2135: DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2136: if (DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))
2137: /* Previously saved insns go together with
2138: the function's previous definition. */
2139: DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2140: /* Don't clear out the arguments if we're redefining a function. */
2141: if (DECL_ARGUMENTS (olddecl))
2142: DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2143: }
2144: }
2145:
2146: /* Now preserve various other info from the definition. */
2147: TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2148: TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2149:
2150: /* Don't really know how much of the language-specific
2151: values we should copy from old to new. */
2152: #if 1
2153: if (DECL_LANG_SPECIFIC (olddecl))
2154: DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2155: #endif
2156:
2157: if (TREE_CODE (newdecl) == FUNCTION_DECL)
2158: {
2159: int function_size;
2160: struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
2161: struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
2162:
2163: function_size = sizeof (struct tree_decl);
2164:
2165: bcopy ((char *) newdecl + sizeof (struct tree_common),
2166: (char *) olddecl + sizeof (struct tree_common),
2167: function_size - sizeof (struct tree_common));
2168:
2169: if ((char *)newdecl == obstack_next_free (&permanent_obstack)
2170: - (function_size + sizeof (struct lang_decl)))
2171: {
2172: DECL_MAIN_VARIANT (newdecl) = olddecl;
2173: DECL_LANG_SPECIFIC (olddecl) = ol;
2174: bcopy (nl, ol, sizeof (struct lang_decl));
2175:
2176: obstack_free (&permanent_obstack, newdecl);
2177: }
2178: else if (LANG_DECL_PERMANENT (ol))
2179: {
2180: if (DECL_MAIN_VARIANT (olddecl) == olddecl)
2181: {
2182: /* Save these lang_decls that would otherwise be lost. */
2183: extern tree free_lang_decl_chain;
2184: tree free_lang_decl = (tree) ol;
2185: TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
2186: free_lang_decl_chain = free_lang_decl;
2187: }
2188: else
2189: {
2190: /* Storage leak. */
2191: }
2192: }
2193: }
2194: else
2195: {
2196: bcopy ((char *) newdecl + sizeof (struct tree_common),
2197: (char *) olddecl + sizeof (struct tree_common),
2198: sizeof (struct tree_decl) - sizeof (struct tree_common)
2199: + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
2200: }
2201:
2202: return 1;
2203: }
2204:
2205: void
2206: adjust_type_value (id)
2207: tree id;
2208: {
2209: tree t;
2210:
2211: if (current_binding_level != global_binding_level)
2212: {
2213: if (current_binding_level != class_binding_level)
2214: {
2215: t = IDENTIFIER_LOCAL_VALUE (id);
2216: if (t && TREE_CODE (t) == TYPE_DECL)
2217: {
2218: set_it:
2219: SET_IDENTIFIER_TYPE_VALUE (id, TREE_TYPE (t));
2220: return;
2221: }
2222: }
2223: else
2224: abort ();
2225:
2226: if (current_class_type)
2227: {
2228: t = IDENTIFIER_CLASS_VALUE (id);
2229: if (t && TREE_CODE (t) == TYPE_DECL)
2230: goto set_it;
2231: }
2232: }
2233:
2234: t = IDENTIFIER_GLOBAL_VALUE (id);
2235: if (t && TREE_CODE (t) == TYPE_DECL)
2236: goto set_it;
2237: if (t && TREE_CODE (t) == TEMPLATE_DECL)
2238: SET_IDENTIFIER_TYPE_VALUE (id, NULL_TREE);
2239: }
2240:
2241: /* Record a decl-node X as belonging to the current lexical scope.
2242: Check for errors (such as an incompatible declaration for the same
2243: name already seen in the same scope).
2244:
2245: Returns either X or an old decl for the same name.
2246: If an old decl is returned, it may have been smashed
2247: to agree with what X says. */
2248:
2249: tree
2250: pushdecl (x)
2251: tree x;
2252: {
2253: register tree t;
2254: register tree name = DECL_ASSEMBLER_NAME (x);
2255: register struct binding_level *b = current_binding_level;
2256:
2257: #if 0
2258: static int nglobals; int len;
2259:
2260: len = list_length (global_binding_level->names);
2261: if (len < nglobals)
2262: abort ();
2263: else if (len > nglobals)
2264: nglobals = len;
2265: #endif
2266:
2267: if (name)
2268: {
2269: char *file;
2270: int line;
2271:
2272: t = lookup_name_current_level (name);
2273: if (t != 0 && t == error_mark_node)
2274: /* error_mark_node is 0 for a while during initialization! */
2275: {
2276: t = 0;
2277: error_with_decl (x, "`%s' used prior to declaration");
2278: }
2279:
2280: if (t != 0)
2281: {
2282: tree cntxt = t;
2283: if (TREE_CODE (t) == PARM_DECL)
2284: {
2285: if (DECL_CONTEXT (t) == NULL_TREE)
2286: fatal ("parse errors have confused me too much");
2287: cntxt = DECL_CONTEXT (t);
2288: }
2289: file = DECL_SOURCE_FILE (t);
2290: line = DECL_SOURCE_LINE (t);
2291: }
2292:
2293: if (t != 0 && TREE_CODE (t) != TREE_CODE (x))
2294: {
2295: if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL)
2296: {
2297: /* We do nothing special here, because C++ does such nasty
2298: things with TYPE_DECLs. Instead, just let the TYPE_DECL
2299: get shadowed, and know that if we need to find a TYPE_DECL
2300: for a given name, we can look in the IDENTIFIER_TYPE_VALUE
2301: slot of the identifier. */
2302: ;
2303: }
2304: else if (duplicate_decls (x, t))
2305: return t;
2306: }
2307: else if (t != 0 && duplicate_decls (x, t))
2308: {
2309: /* If this decl is `static' and an `extern' was seen previously,
2310: that is erroneous. But don't complain if -traditional,
2311: since traditional compilers don't complain.
2312:
2313: Note that this does not apply to the C++ case of declaring
2314: a variable `extern const' and then later `const'. */
2315: if (!flag_traditional && TREE_PUBLIC (name)
2316: && ! TREE_PUBLIC (x) && ! TREE_EXTERNAL (x) && ! TREE_INLINE (x))
2317: {
2318: /* Due to interference in memory reclamation (X may be
2319: obstack-deallocated at this point), we must guard against
2320: one really special case. */
2321: if (current_function_decl == x)
2322: current_function_decl = t;
2323: if (IDENTIFIER_IMPLICIT_DECL (name))
2324: warning ("`%s' was declared implicitly `extern' and later `static'",
2325: lang_printable_name (t));
2326: else
2327: warning ("`%s' was declared `extern' and later `static'",
2328: lang_printable_name (t));
2329: warning_with_file_and_line (file, line,
2330: "previous declaration of `%s'",
2331: lang_printable_name (t));
2332: }
2333: return t;
2334: }
2335:
2336: /* If declaring a type as a typedef, and the type has no known
2337: typedef name, install this TYPE_DECL as its typedef name.
2338:
2339: C++: If it had an anonymous aggregate or enum name,
2340: give it a `better' one. */
2341: if (TREE_CODE (x) == TYPE_DECL)
2342: {
2343: tree name = TYPE_NAME (TREE_TYPE (x));
2344:
2345: if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
2346: {
2347: /* If these are different names, and we're at the global
2348: binding level, make two equivalent definitions. */
2349: name = x;
2350: if (global_bindings_p ())
2351: TYPE_NAME (TREE_TYPE (x)) = x;
2352: }
2353: else
2354: {
2355: tree tname = DECL_NAME (name);
2356: if (global_bindings_p () && ANON_AGGRNAME_P (tname))
2357: {
2358: /* do gratuitous C++ typedefing, and make sure that
2359: we access this type either through TREE_TYPE field
2360: or via the tags list. */
2361: TYPE_NAME (TREE_TYPE (x)) = x;
2362: pushtag (tname, TREE_TYPE (x));
2363: }
2364: }
2365: assert (TREE_CODE (name) == TYPE_DECL);
2366: if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
2367: set_nested_typename (x, current_class_name, DECL_NAME (name),
2368: TREE_TYPE (x));
2369: if (TYPE_NAME (TREE_TYPE (x)) && TYPE_IDENTIFIER (TREE_TYPE (x)))
2370: set_identifier_type_value (DECL_NAME (x), TREE_TYPE (x));
2371: /* was using TYPE_IDENTIFIER (TREE_TYPE (x)) */
2372: }
2373:
2374: /* Multiple external decls of the same identifier ought to match. */
2375:
2376: if (TREE_EXTERNAL (x) && IDENTIFIER_GLOBAL_VALUE (name) != 0
2377: && (TREE_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2378: || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))
2379: /* We get warnings about inline functions where they are defined.
2380: Avoid duplicate warnings where they are used. */
2381: && !TREE_INLINE (x))
2382: {
2383: if (! comptypes (TREE_TYPE (x),
2384: TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)), 1))
2385: {
2386: warning_with_decl (x,
2387: "type mismatch with previous external decl");
2388: warning_with_decl (IDENTIFIER_GLOBAL_VALUE (name),
2389: "previous external decl of `%s'");
2390: }
2391: }
2392:
2393: /* In PCC-compatibility mode, extern decls of vars with no current decl
2394: take effect at top level no matter where they are. */
2395: if (flag_traditional && TREE_EXTERNAL (x)
2396: && lookup_name (name, 0) == 0)
2397: b = global_binding_level;
2398:
2399: /* This name is new in its binding level.
2400: Install the new declaration and return it. */
2401: if (b == global_binding_level)
2402: {
2403: /* Install a global value. */
2404:
2405: /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
2406: A `const' which was not declared `extern' is invisible. */
2407: if (TREE_CODE (x) == VAR_DECL
2408: && TREE_READONLY (x) && ! DECL_EXTERNAL (x))
2409: TREE_PUBLIC (x) = 0;
2410:
2411: /* If the first global decl has external linkage,
2412: warn if we later see static one. */
2413: if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
2414: TREE_PUBLIC (name) = 1;
2415:
2416: /* Don't install a TYPE_DECL if we already have another
2417: sort of _DECL with that name. */
2418: if (TREE_CODE (x) != TYPE_DECL
2419: || t == NULL_TREE
2420: || TREE_CODE (t) == TYPE_DECL)
2421: IDENTIFIER_GLOBAL_VALUE (name) = x;
2422:
2423: /* Don't forget if the function was used via an implicit decl. */
2424: if (IDENTIFIER_IMPLICIT_DECL (name)
2425: && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2426: TREE_USED (x) = 1;
2427:
2428: /* Don't forget if its address was taken in that way. */
2429: if (IDENTIFIER_IMPLICIT_DECL (name)
2430: && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2431: TREE_ADDRESSABLE (x) = 1;
2432:
2433: /* Warn about mismatches against previous implicit decl. */
2434: if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2435: /* If this real decl matches the implicit, don't complain. */
2436: && ! (TREE_CODE (x) == FUNCTION_DECL
2437: && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
2438: warning ("`%s' was previously implicitly declared to return `int'",
2439: lang_printable_name (x));
2440:
2441: /* If this decl is `static' and an `extern' was seen previously,
2442: that is erroneous. Don't do this for TYPE_DECLs. */
2443: if (TREE_PUBLIC (name)
2444: && TREE_CODE (x) != TYPE_DECL
2445: && ! TREE_PUBLIC (x) && ! TREE_EXTERNAL (x))
2446: {
2447: if (IDENTIFIER_IMPLICIT_DECL (name))
2448: warning ("`%s' was declared implicitly `extern' and later `static'",
2449: lang_printable_name (x));
2450: else
2451: warning ("`%s' was declared `extern' and later `static'",
2452: lang_printable_name (x));
2453: }
2454: }
2455: else
2456: {
2457: /* Here to install a non-global value. */
2458: tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2459: tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2460: set_identifier_local_value (name, x);
2461:
2462: /* If this is an extern function declaration, see if we
2463: have a global definition for the function. */
2464: if (oldlocal == 0
2465: && TREE_EXTERNAL (x) && !TREE_INLINE (x)
2466: && oldglobal != 0
2467: && TREE_CODE (x) == FUNCTION_DECL
2468: && TREE_CODE (oldglobal) == FUNCTION_DECL)
2469: {
2470: /* We have one. Their types must agree. */
2471: if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
2472: warning_with_decl (x, "local declaration of `%s' doesn't match global one");
2473: /* If the global one is inline, make the local one inline. */
2474: else if (TREE_INLINE (oldglobal)
2475: || DECL_BUILT_IN (oldglobal)
2476: || (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
2477: && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0))
2478: IDENTIFIER_LOCAL_VALUE (name) = oldglobal;
2479: }
2480: /* If we have a local external declaration,
2481: and no file-scope declaration has yet been seen,
2482: then if we later have a file-scope decl it must not be static. */
2483: if (oldlocal == 0
2484: && oldglobal == 0
2485: && TREE_EXTERNAL (x)
2486: && TREE_PUBLIC (x))
2487: {
2488: TREE_PUBLIC (name) = 1;
2489: }
2490:
2491: if (DECL_FROM_INLINE (x))
2492: /* Inline decls shadow nothing. */;
2493:
2494: /* Warn if shadowing an argument at the top level of the body. */
2495: else if (oldlocal != 0 && !TREE_EXTERNAL (x)
2496: && TREE_CODE (oldlocal) == PARM_DECL
2497: && TREE_CODE (x) != PARM_DECL)
2498: {
2499: extern struct rtx_def *cleanup_label;
2500:
2501: /* Go to where the parms should be and see if we
2502: find them there. */
2503: struct binding_level *b = current_binding_level->level_chain;
2504:
2505: if (cleanup_label)
2506: b = b->level_chain;
2507:
2508: if (b->parm_flag == 1)
2509: warning ("declaration of `%s' shadows a parameter",
2510: IDENTIFIER_POINTER (name));
2511: }
2512: /* Maybe warn if shadowing something else. */
2513: else if (warn_shadow && !TREE_EXTERNAL (x)
2514: /* No shadow warnings for vars made for inlining. */
2515: && ! DECL_FROM_INLINE (x))
2516: {
2517: char *warnstring = 0;
2518:
2519: if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
2520: warnstring = "declaration of `%s' shadows a parameter";
2521: else if (IDENTIFIER_CLASS_VALUE (name) != 0)
2522: warnstring = "declaration of `%s' shadows a member of `this'";
2523: else if (oldlocal != 0)
2524: warnstring = "declaration of `%s' shadows previous local";
2525: else if (oldglobal != 0)
2526: warnstring = "declaration of `%s' shadows global declaration";
2527:
2528: if (warnstring)
2529: warning (warnstring, IDENTIFIER_POINTER (name));
2530: }
2531:
2532: /* If storing a local value, there may already be one (inherited).
2533: If so, record it for restoration when this binding level ends. */
2534: if (oldlocal != 0)
2535: b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2536: }
2537:
2538: /* Keep count of variables in this level with incomplete type. */
2539: if (TREE_CODE (x) != TEMPLATE_DECL
2540: && TREE_CODE (x) != CPLUS_CATCH_DECL
2541: && TYPE_SIZE (TREE_TYPE (x)) == 0
2542: && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
2543: {
2544: if (++b->n_incomplete == 0)
2545: error ("too many incomplete variables at this point");
2546: }
2547: }
2548:
2549: if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE)
2550: {
2551: adjust_type_value (name);
2552: if (current_class_name)
2553: {
2554: if (!DECL_NESTED_TYPENAME (x))
2555: set_nested_typename (x, current_class_name, DECL_NAME (x),
2556: TREE_TYPE (x));
2557: adjust_type_value (DECL_NESTED_TYPENAME (x));
2558: }
2559: }
2560:
2561: /* Put decls on list in reverse order.
2562: We will reverse them later if necessary. */
2563: TREE_CHAIN (x) = b->names;
2564: b->names = x;
2565: assert (b != global_binding_level || TREE_PERMANENT (x));
2566:
2567: return x;
2568: }
2569:
2570: /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
2571: if appropriate. */
2572: tree
2573: pushdecl_top_level (x)
2574: tree x;
2575: {
2576: register tree t;
2577: register struct binding_level *b = current_binding_level;
2578:
2579: current_binding_level = global_binding_level;
2580: t = pushdecl (x);
2581: current_binding_level = b;
2582: if (class_binding_level)
2583: b = class_binding_level;
2584: /* Now, the type_shadowed stack may screw us. Munge it so it does
2585: what we want. */
2586: if (TREE_CODE (x) == TYPE_DECL)
2587: {
2588: tree name = DECL_NAME (x);
2589: tree newval;
2590: tree *ptr = 0;
2591: for (; b != global_binding_level; b = b->level_chain)
2592: {
2593: tree shadowed = b->type_shadowed;
2594: for (; shadowed; shadowed = TREE_CHAIN (shadowed))
2595: if (TREE_PURPOSE (shadowed) == name)
2596: {
2597: ptr = &TREE_VALUE (shadowed);
2598: /* Can't break out of the loop here because sometimes
2599: a binding level will have duplicate bindings for
2600: PT names. It's gross, but I haven't time to fix it. */
2601: }
2602: }
2603: newval = TREE_TYPE (x);
2604: if (ptr == 0)
2605: {
2606: /* @@ This shouldn't be needed. My test case "zstring.cc" trips
2607: up here if this is changed to an assertion. --KR */
2608: SET_IDENTIFIER_TYPE_VALUE (name, newval);
2609: }
2610: else
2611: {
2612: assert (*ptr == NULL_TREE || *ptr == newval);
2613: *ptr = newval;
2614: }
2615: }
2616: return t;
2617: }
2618:
2619: /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
2620: if appropriate. */
2621: void
2622: push_overloaded_decl_top_level (x, forget)
2623: tree x;
2624: int forget;
2625: {
2626: struct binding_level *b = current_binding_level;
2627:
2628: current_binding_level = global_binding_level;
2629: push_overloaded_decl (x, forget);
2630: current_binding_level = b;
2631: }
2632:
2633: /* Make the declaration of X appear in CLASS scope. */
2634: tree
2635: pushdecl_class_level (x)
2636: tree x;
2637: {
2638: /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
2639: scope looks for the pre-mangled name. */
2640: register tree name = DECL_NAME (x);
2641:
2642: if (name)
2643: {
2644: tree oldclass = IDENTIFIER_CLASS_VALUE (name);
2645: if (oldclass)
2646: class_binding_level->class_shadowed
2647: = tree_cons (name, oldclass, class_binding_level->class_shadowed);
2648: IDENTIFIER_CLASS_VALUE (name) = x;
2649: obstack_ptr_grow (&decl_obstack, x);
2650: if (TREE_CODE (x) == TYPE_DECL && !DECL_NESTED_TYPENAME (x))
2651: set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
2652: }
2653: return x;
2654: }
2655:
2656: /* Tell caller how to interpret a TREE_LIST which contains
2657: chains of FUNCTION_DECLS. */
2658: int
2659: overloaded_globals_p (list)
2660: tree list;
2661: {
2662: assert (TREE_CODE (list) == TREE_LIST);
2663:
2664: /* Don't commit caller to seeing them as globals. */
2665: if (TREE_NONLOCAL_FLAG (list))
2666: return -1;
2667: /* Do commit caller to seeing them as globals. */
2668: if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
2669: return 1;
2670: /* Do commit caller to not seeing them as globals. */
2671: return 0;
2672: }
2673:
2674: /* DECL is a FUNCTION_DECL which may have other definitions already in place.
2675: We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_NAME (DECL))
2676: point to a list of all the things that want to be referenced by that name.
2677: It is then up to the users of that name to decide what to do with that
2678: list.
2679:
2680: DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
2681: slot. It is dealt with the same way.
2682:
2683: The value returned may be a previous declaration if we guessed wrong
2684: about what language DECL should belong to (C or C++). Otherwise,
2685: it's always DECL (and never something that's not a _DECL). */
2686: tree
2687: push_overloaded_decl (decl, forgettable)
2688: tree decl;
2689: int forgettable;
2690: {
2691: tree orig_name = DECL_NAME (decl);
2692: tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name);
2693:
2694: DECL_OVERLOADED (decl) = 1;
2695: if (glob)
2696: {
2697: if (TREE_CODE (glob) != TREE_LIST)
2698: {
2699: if (DECL_LANGUAGE (decl) == lang_c)
2700: {
2701: if (TREE_CODE (glob) == FUNCTION_DECL)
2702: {
2703: if (DECL_LANGUAGE (glob) == lang_c)
2704: {
2705: error_with_decl (decl, "C-language function `%s' overloaded here");
2706: error_with_decl (glob, "Previous C-language version of this function was `%s'");
2707: }
2708: }
2709: else
2710: abort ();
2711: }
2712: if (forgettable
2713: && ! flag_traditional
2714: && TREE_PERMANENT (glob) == 1
2715: && !global_bindings_p ())
2716: overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
2717: /* We cache the value of builtin functions as ADDR_EXPRs
2718: in the name space. Convert it to some kind of _DECL after
2719: remembering what to forget. */
2720: if (TREE_CODE (glob) == ADDR_EXPR)
2721: glob = TREE_OPERAND (glob, 0);
2722:
2723: if (TREE_CODE (glob) == FUNCTION_DECL
2724: && DECL_LANGUAGE (glob) != DECL_LANGUAGE (decl)
2725: && comptypes (TREE_TYPE (glob), TREE_TYPE (decl), 1))
2726: {
2727: if (current_lang_stack == current_lang_base)
2728: {
2729: DECL_LANGUAGE (decl) = DECL_LANGUAGE (glob);
2730: return glob;
2731: }
2732: else
2733: {
2734: error_with_decl (decl, "conflicting language contexts for declaration of `%s';");
2735: error_with_decl (glob, "conflicts with previous declaration here");
2736: }
2737: }
2738: if (pedantic && TREE_CODE (glob) == VAR_DECL)
2739: {
2740: assert (TREE_CODE_CLASS (TREE_CODE (glob)) == 'd');
2741: error_with_decl (glob, "non-function declaration `%s'");
2742: error_with_decl (decl, "conflicts with function declaration `%s'");
2743: }
2744: glob = tree_cons (DECL_ASSEMBLER_NAME (glob), glob, NULL_TREE);
2745: glob = tree_cons (TREE_PURPOSE (glob), decl, glob);
2746: IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
2747: TREE_TYPE (glob) = unknown_type_node;
2748: return decl;
2749: }
2750:
2751: if (TREE_VALUE (glob) == NULL_TREE)
2752: {
2753: TREE_VALUE (glob) = decl;
2754: return decl;
2755: }
2756: if (TREE_CODE (decl) != TEMPLATE_DECL)
2757: {
2758: tree name = DECL_ASSEMBLER_NAME (decl);
2759: tree tmp;
2760:
2761: for (tmp = glob; tmp; tmp = TREE_CHAIN (tmp))
2762: {
2763: if (TREE_CODE (TREE_VALUE (tmp)) == FUNCTION_DECL
2764: && DECL_LANGUAGE (TREE_VALUE (tmp)) != DECL_LANGUAGE (decl)
2765: && comptypes (TREE_TYPE (TREE_VALUE (tmp)), TREE_TYPE (decl),
2766: 1))
2767: {
2768: error_with_decl (decl,
2769: "conflicting language contexts for declaration of `%s';");
2770: error_with_decl (TREE_VALUE (tmp),
2771: "conflicts with previous declaration here");
2772: }
2773: if (TREE_CODE (TREE_VALUE (tmp)) != TEMPLATE_DECL
2774: && DECL_ASSEMBLER_NAME (TREE_VALUE (tmp)) == name)
2775: return decl;
2776: }
2777: }
2778: }
2779: if (DECL_LANGUAGE (decl) == lang_c)
2780: {
2781: tree decls = glob;
2782: while (decls && DECL_LANGUAGE (TREE_VALUE (decls)) == lang_cplusplus)
2783: decls = TREE_CHAIN (decls);
2784: if (decls)
2785: {
2786: error_with_decl (decl, "C-language function `%s' overloaded here");
2787: error_with_decl (TREE_VALUE (decls), "Previous C-language version of this function was `%s'");
2788: }
2789: }
2790:
2791: if (forgettable
2792: && ! flag_traditional
2793: && (glob == 0 || TREE_PERMANENT (glob) == 1)
2794: && !global_bindings_p ())
2795: overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
2796: glob = tree_cons (orig_name, decl, glob);
2797: IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
2798: TREE_TYPE (glob) = unknown_type_node;
2799: return decl;
2800: }
2801:
2802: /* Generate an implicit declaration for identifier FUNCTIONID
2803: as a function of type int (). Print a warning if appropriate. */
2804:
2805: tree
2806: implicitly_declare (functionid)
2807: tree functionid;
2808: {
2809: register tree decl;
2810: int temp = allocation_temporary_p ();
2811:
2812: push_obstacks_nochange ();
2813:
2814: /* Save the decl permanently so we can warn if definition follows.
2815: In ANSI C, warn_implicit is usually false, so the saves little space.
2816: But in C++, it's usually true, hence the extra code. */
2817: if (temp && (flag_traditional || !warn_implicit
2818: || current_binding_level == global_binding_level))
2819: end_temporary_allocation ();
2820:
2821: /* We used to reuse an old implicit decl here,
2822: but this loses with inline functions because it can clobber
2823: the saved decl chains. */
2824: /* if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
2825: decl = IDENTIFIER_IMPLICIT_DECL (functionid);
2826: else */
2827: decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
2828:
2829: TREE_EXTERNAL (decl) = 1;
2830: TREE_PUBLIC (decl) = 1;
2831:
2832: /* ANSI standard says implicit declarations are in the innermost block.
2833: So we record the decl in the standard fashion.
2834: If flag_traditional is set, pushdecl does it top-level. */
2835: pushdecl (decl);
2836: rest_of_decl_compilation (decl, 0, 0, 0);
2837:
2838: if (warn_implicit
2839: /* Only one warning per identifier. */
2840: && IDENTIFIER_IMPLICIT_DECL (functionid) == 0)
2841: {
2842: if (pedantic)
2843: error ("implicit declaration of function `%s'",
2844: IDENTIFIER_POINTER (functionid));
2845: else
2846: warning ("implicit declaration of function `%s'",
2847: IDENTIFIER_POINTER (functionid));
2848: }
2849:
2850: SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
2851:
2852: pop_obstacks ();
2853:
2854: return decl;
2855: }
2856:
2857: /* Return zero if the declaration NEWDECL is valid
2858: when the declaration OLDDECL (assumed to be for the same name)
2859: has already been seen.
2860: Otherwise return an error message format string with a %s
2861: where the identifier should go. */
2862:
2863: static char *
2864: redeclaration_error_message (newdecl, olddecl)
2865: tree newdecl, olddecl;
2866: {
2867: if (TREE_CODE (newdecl) == TYPE_DECL)
2868: {
2869: /* Because C++ can put things into name space for free,
2870: constructs like "typedef struct foo { ... } foo"
2871: would look like an erroneous redeclaration. */
2872: if (TREE_TYPE (olddecl) == TREE_TYPE (newdecl))
2873: return 0;
2874: else
2875: return "redefinition of `%s'";
2876: }
2877: else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2878: {
2879: /* Declarations of functions can insist on internal linkage
2880: but they can't be inconsistent with internal linkage,
2881: so there can be no error on that account.
2882: However defining the same name twice is no good. */
2883: if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
2884: /* However, defining once as extern inline and a second
2885: time in another way is ok. */
2886: && !(TREE_INLINE (olddecl) && TREE_EXTERNAL (olddecl)
2887: && !(TREE_INLINE (newdecl) && TREE_EXTERNAL (newdecl))))
2888: {
2889: if (DECL_NAME (olddecl) == NULL_TREE)
2890: return "`%s' not declared in class";
2891: else
2892: return "redefinition of `%s'";
2893: }
2894: return 0;
2895: }
2896: else if (current_binding_level == global_binding_level)
2897: {
2898: /* Objects declared at top level: */
2899: /* If at least one is a reference, it's ok. */
2900: if (TREE_EXTERNAL (newdecl) || TREE_EXTERNAL (olddecl))
2901: return 0;
2902: /* Reject two definitions. */
2903: if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
2904: return "redefinition of `%s'";
2905: /* Now we have two tentative defs, or one tentative and one real def. */
2906: /* Insist that the linkage match. */
2907: if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
2908: return "conflicting declarations of `%s'";
2909: return 0;
2910: }
2911: else
2912: {
2913: /* Objects declared with block scope: */
2914: /* Reject two definitions, and reject a definition
2915: together with an external reference. */
2916: if (!(TREE_EXTERNAL (newdecl) && TREE_EXTERNAL (olddecl)))
2917: return "redeclaration of `%s'";
2918: return 0;
2919: }
2920: }
2921:
2922: /* Get the LABEL_DECL corresponding to identifier ID as a label.
2923: Create one if none exists so far for the current function.
2924: This function is called for both label definitions and label references. */
2925:
2926: tree
2927: lookup_label (id)
2928: tree id;
2929: {
2930: register tree decl = IDENTIFIER_LABEL_VALUE (id);
2931:
2932: if ((decl == 0
2933: || DECL_SOURCE_LINE (decl) == 0)
2934: && (named_label_uses == 0
2935: || TREE_PURPOSE (named_label_uses) != current_binding_level->names
2936: || TREE_VALUE (named_label_uses) != decl))
2937: {
2938: named_label_uses
2939: = tree_cons (current_binding_level->names, decl, named_label_uses);
2940: TREE_TYPE (named_label_uses) = (tree)current_binding_level;
2941: }
2942:
2943: if (decl != 0)
2944: return decl;
2945:
2946: decl = build_decl (LABEL_DECL, id, void_type_node);
2947:
2948: /* A label not explicitly declared must be local to where it's ref'd. */
2949: DECL_CONTEXT (decl) = current_function_decl;
2950:
2951: DECL_MODE (decl) = VOIDmode;
2952:
2953: /* Say where one reference is to the label,
2954: for the sake of the error if it is not defined. */
2955: DECL_SOURCE_LINE (decl) = lineno;
2956: DECL_SOURCE_FILE (decl) = input_filename;
2957:
2958: SET_IDENTIFIER_LABEL_VALUE (id, decl);
2959:
2960: named_labels = tree_cons (NULL_TREE, decl, named_labels);
2961: TREE_VALUE (named_label_uses) = decl;
2962:
2963: return decl;
2964: }
2965:
2966: /* Define a label, specifying the location in the source file.
2967: Return the LABEL_DECL node for the label, if the definition is valid.
2968: Otherwise return 0. */
2969:
2970: tree
2971: define_label (filename, line, name)
2972: char *filename;
2973: int line;
2974: tree name;
2975: {
2976: tree decl = lookup_label (name);
2977:
2978: /* After labels, make any new cleanups go into their
2979: own new (temporary) binding contour. */
2980: current_binding_level->more_cleanups_ok = 0;
2981:
2982: if (DECL_INITIAL (decl) != 0)
2983: {
2984: error_with_decl (decl, "duplicate label `%s'");
2985: return 0;
2986: }
2987: else
2988: {
2989: tree uses, prev;
2990:
2991: /* Mark label as having been defined. */
2992: DECL_INITIAL (decl) = error_mark_node;
2993: /* Say where in the source. */
2994: DECL_SOURCE_FILE (decl) = filename;
2995: DECL_SOURCE_LINE (decl) = line;
2996:
2997: for (prev = 0, uses = named_label_uses;
2998: uses;
2999: prev = uses, uses = TREE_CHAIN (uses))
3000: if (TREE_VALUE (uses) == decl)
3001: {
3002: struct binding_level *b = current_binding_level;
3003: while (1)
3004: {
3005: tree new_decls = b->names;
3006: tree old_decls = ((tree)b == TREE_TYPE (uses)
3007: ? TREE_PURPOSE (uses) : NULL_TREE);
3008: while (new_decls != old_decls)
3009: {
3010: if (TREE_CODE (new_decls) == VAR_DECL
3011: /* Don't complain about crossing initialization
3012: of temporaries. They can't be accessed,
3013: and they should be cleaned up
3014: by the time we get to the label. */
3015: && ! TEMP_NAME_P (DECL_NAME (new_decls))
3016: && ((DECL_INITIAL (new_decls) != NULL_TREE
3017: && DECL_INITIAL (new_decls) != error_mark_node)
3018: || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
3019: {
3020: if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
3021: error_with_decl (decl, "invalid jump to label `%s'");
3022: SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
3023: error_with_decl (new_decls, "crosses initialization of `%s'");
3024: }
3025: new_decls = TREE_CHAIN (new_decls);
3026: }
3027: if ((tree)b == TREE_TYPE (uses))
3028: break;
3029: b = b->level_chain;
3030: }
3031:
3032: if (prev)
3033: TREE_CHAIN (prev) = TREE_CHAIN (uses);
3034: else
3035: named_label_uses = TREE_CHAIN (uses);
3036: }
3037: current_function_return_value = NULL_TREE;
3038: return decl;
3039: }
3040: }
3041:
3042: /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3043: void
3044: define_case_label (decl)
3045: tree decl;
3046: {
3047: tree cleanup = last_cleanup_this_contour ();
3048: if (cleanup)
3049: {
3050: static int explained = 0;
3051: error_with_decl (TREE_PURPOSE (cleanup), "destructor needed for `%s'");
3052: error ("where case label appears here");
3053: if (!explained)
3054: {
3055: error ("(enclose actions of previous case statements requiring");
3056: error ("destructors in their own binding contours.)");
3057: explained = 1;
3058: }
3059: }
3060:
3061: /* After labels, make any new cleanups go into their
3062: own new (temporary) binding contour. */
3063:
3064: current_binding_level->more_cleanups_ok = 0;
3065: current_function_return_value = NULL_TREE;
3066: }
3067:
3068: /* Return the list of declarations of the current level.
3069: Note that this list is in reverse order unless/until
3070: you nreverse it; and when you do nreverse it, you must
3071: store the result back using `storedecls' or you will lose. */
3072:
3073: tree
3074: getdecls ()
3075: {
3076: return current_binding_level->names;
3077: }
3078:
3079: /* Return the list of type-tags (for structs, etc) of the current level. */
3080:
3081: tree
3082: gettags ()
3083: {
3084: return current_binding_level->tags;
3085: }
3086:
3087: /* Store the list of declarations of the current level.
3088: This is done for the parameter declarations of a function being defined,
3089: after they are modified in the light of any missing parameters. */
3090:
3091: static void
3092: storedecls (decls)
3093: tree decls;
3094: {
3095: current_binding_level->names = decls;
3096: }
3097:
3098: /* Similarly, store the list of tags of the current level. */
3099:
3100: static void
3101: storetags (tags)
3102: tree tags;
3103: {
3104: current_binding_level->tags = tags;
3105: }
3106:
3107: /* Given NAME, an IDENTIFIER_NODE,
3108: return the structure (or union or enum) definition for that name.
3109: Searches binding levels from BINDING_LEVEL up to the global level.
3110: If THISLEVEL_ONLY is nonzero, searches only the specified context
3111: (but skips any tag-transparent contexts to find one that is
3112: meaningful for tags).
3113: FORM says which kind of type the caller wants;
3114: it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3115: If the wrong kind of type is found, and it's not a template, an error is
3116: reported. */
3117:
3118: static tree
3119: lookup_tag (form, name, binding_level, thislevel_only)
3120: enum tree_code form;
3121: struct binding_level *binding_level;
3122: tree name;
3123: int thislevel_only;
3124: {
3125: register struct binding_level *level;
3126:
3127: for (level = binding_level; level; level = level->level_chain)
3128: {
3129: register tree tail;
3130: for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3131: {
3132: if (TREE_PURPOSE (tail) == name)
3133: {
3134: enum tree_code code = TREE_CODE (TREE_VALUE (tail));
3135: /* Should tighten this up; it'll probably permit
3136: UNION_TYPE and a struct template, for example. */
3137: if (code != form
3138: && !(form != ENUMERAL_TYPE
3139: && (code == TEMPLATE_DECL
3140: || code == UNINSTANTIATED_P_TYPE)))
3141:
3142: {
3143: /* Definition isn't the kind we were looking for. */
3144: error ("`%s' defined as wrong kind of tag",
3145: IDENTIFIER_POINTER (name));
3146: }
3147: return TREE_VALUE (tail);
3148: }
3149: }
3150: if (thislevel_only && ! level->tag_transparent)
3151: return NULL_TREE;
3152: if (current_class_type && level->level_chain == global_binding_level)
3153: {
3154: /* Try looking in this class's tags before heading into
3155: global binding level. */
3156: tree context = current_class_type;
3157: while (context)
3158: {
3159: switch (TREE_CODE_CLASS (TREE_CODE (context)))
3160: {
3161: case 't':
3162: {
3163: tree these_tags = CLASSTYPE_TAGS (context);
3164: while (these_tags)
3165: {
3166: if (TREE_PURPOSE (these_tags) == name)
3167: {
3168: if (TREE_CODE (TREE_VALUE (these_tags)) != form)
3169: {
3170: error ("`%s' defined as wrong kind of tag in class scope",
3171: IDENTIFIER_POINTER (name));
3172: }
3173: return TREE_VALUE (tail);
3174: }
3175: these_tags = TREE_CHAIN (these_tags);
3176: }
3177: /* If this type is not yet complete, then don't
3178: look at its context. */
3179: if (TYPE_SIZE (context) == NULL_TREE)
3180: goto no_context;
3181: /* Go to next enclosing type, if any. */
3182: context = DECL_CONTEXT (TYPE_NAME (context));
3183: break;
3184: case 'd':
3185: context = DECL_CONTEXT (context);
3186: break;
3187: default:
3188: abort();
3189: }
3190: continue;
3191: }
3192: no_context:
3193: break;
3194: }
3195: }
3196: }
3197: return NULL_TREE;
3198: }
3199:
3200: void
3201: set_current_level_tags_transparency (tags_transparent)
3202: {
3203: current_binding_level->tag_transparent = tags_transparent;
3204: }
3205:
3206: /* Given a type, find the tag that was defined for it and return the tag name.
3207: Otherwise return 0. However, the value can never be 0
3208: in the cases in which this is used.
3209:
3210: C++: If NAME is non-zero, this is the new name to install. This is
3211: done when replacing anonymous tags with real tag names. */
3212:
3213: static tree
3214: lookup_tag_reverse (type, name)
3215: tree type;
3216: tree name;
3217: {
3218: register struct binding_level *level;
3219:
3220: for (level = current_binding_level; level; level = level->level_chain)
3221: {
3222: register tree tail;
3223: for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3224: {
3225: if (TREE_VALUE (tail) == type)
3226: {
3227: if (name)
3228: TREE_PURPOSE (tail) = name;
3229: return TREE_PURPOSE (tail);
3230: }
3231: }
3232: }
3233: return NULL_TREE;
3234: }
3235:
3236: /* Given type TYPE which was not declared in C++ language context,
3237: attempt to find a name by which it is refered. */
3238: tree
3239: typedecl_for_tag (tag)
3240: tree tag;
3241: {
3242: struct binding_level *b = current_binding_level;
3243:
3244: if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
3245: return TYPE_NAME (tag);
3246:
3247: while (b)
3248: {
3249: tree decls = b->names;
3250: while (decls)
3251: {
3252: if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
3253: break;
3254: decls = TREE_CHAIN (decls);
3255: }
3256: if (decls)
3257: return decls;
3258: b = b->level_chain;
3259: }
3260: return NULL_TREE;
3261: }
3262:
3263: /* Called when we must retroactively globalize a type we previously
3264: thought needed to be nested. This happenes, for example, when
3265: a `friend class' declaration is seen for an undefined type. */
3266:
3267: static void
3268: globalize_nested_type (type)
3269: tree type;
3270: {
3271: tree t, prev = NULL_TREE, d = TYPE_NAME (type);
3272: struct binding_level *b;
3273:
3274: assert (TREE_CODE (d) == TYPE_DECL);
3275: /* If the type value has already been globalized, then we're set. */
3276: if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (d)) == d)
3277: return;
3278: if (IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (d)))
3279: {
3280: /* If this type already made it into the global tags,
3281: silently return. */
3282: if (value_member (type, global_binding_level->tags))
3283: return;
3284: }
3285:
3286: set_identifier_type_value (DECL_NESTED_TYPENAME (d), NULL_TREE);
3287: DECL_NESTED_TYPENAME (d) = DECL_NAME (d);
3288: DECL_CONTEXT (d) = NULL_TREE;
3289: if (class_binding_level)
3290: b = class_binding_level;
3291: else
3292: b = current_binding_level;
3293: while (b != global_binding_level)
3294: {
3295: prev = NULL_TREE;
3296: if (b->parm_flag == 2)
3297: for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t))
3298: if (TREE_VALUE (t) == type)
3299: goto found;
3300: b = b->level_chain;
3301: }
3302: /* We failed to find this tag anywhere up the binding chains.
3303: B is now the global binding level... check there. */
3304: prev = NULL_TREE;
3305: if (b->parm_flag == 2)
3306: for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t))
3307: if (TREE_VALUE (t) == type)
3308: goto foundglobal;
3309: /* It wasn't in global scope either, so this is an anonymous forward ref
3310: of some kind; let it happen. */
3311: return;
3312:
3313: foundglobal:
3314: print_node_brief (stderr, "Tried to globalize already-global type ",
3315: type, 0);
3316: abort ();
3317:
3318: found:
3319: /* Pull the tag out of the nested binding contour. */
3320: if (prev)
3321: TREE_CHAIN (prev) = TREE_CHAIN (t);
3322: else
3323: b->tags = TREE_CHAIN (t);
3324:
3325: set_identifier_type_value (TREE_PURPOSE (t), TREE_VALUE (t));
3326: global_binding_level->tags
3327: = perm_tree_cons (TREE_PURPOSE (t), TREE_VALUE (t),
3328: global_binding_level->tags);
3329:
3330: /* Pull the tag out of the class's tags (if there).
3331: It won't show up if it appears e.g. in a parameter declaration
3332: or definition of a member function of this type. */
3333: if (current_class_type != NULL_TREE)
3334: {
3335: for (t = CLASSTYPE_TAGS (current_class_type), prev = NULL_TREE;
3336: t != NULL_TREE;
3337: prev = t, t = TREE_CHAIN (t))
3338: if (TREE_VALUE (t) == type)
3339: break;
3340:
3341: if (t != NULL_TREE)
3342: {
3343: if (prev)
3344: TREE_CHAIN (prev) = TREE_CHAIN (t);
3345: else
3346: CLASSTYPE_TAGS (current_class_type) = TREE_CHAIN (t);
3347: }
3348: }
3349:
3350: pushdecl_top_level (d);
3351: }
3352:
3353: static void
3354: maybe_globalize_type (type)
3355: tree type;
3356: {
3357: if ((((TREE_CODE (type) == RECORD_TYPE
3358: || TREE_CODE (type) == UNION_TYPE)
3359: && ! TYPE_BEING_DEFINED (type))
3360: || TREE_CODE (type) == ENUMERAL_TYPE)
3361: && TYPE_SIZE (type) == NULL_TREE
3362: /* This part is gross. We keep calling here with types that
3363: are instantiations of templates, when that type should is
3364: global, or doesn't have the type decl established yet,
3365: so globalizing will fail (because it won't find the type in any
3366: non-global scope). So we short-circuit that path. */
3367: && !(TYPE_NAME (type) != NULL_TREE
3368: && DECL_NAME (TYPE_NAME (type)) != NULL_TREE
3369: && ! IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (TYPE_NAME (type))))
3370: )
3371: globalize_nested_type (type);
3372: }
3373:
3374: /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
3375: Return the type value, or NULL_TREE if not found. */
3376: static tree
3377: lookup_nested_type (type, context)
3378: tree type;
3379: tree context;
3380: {
3381: if (context == NULL_TREE)
3382: return NULL_TREE;
3383: while (context)
3384: {
3385: switch (TREE_CODE (context))
3386: {
3387: case TYPE_DECL:
3388: {
3389: tree ctype = TREE_TYPE (context);
3390: tree match = value_member (type, CLASSTYPE_TAGS (ctype));
3391: if (match)
3392: return TREE_VALUE (match);
3393: context = DECL_CONTEXT (context);
3394: }
3395: break;
3396: case FUNCTION_DECL:
3397: return TYPE_IDENTIFIER (type) ? lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE;
3398: break;
3399: default:
3400: abort();
3401: }
3402: }
3403: return NULL_TREE;
3404: }
3405:
3406: /* Look up NAME in the current binding level and its superiors
3407: in the namespace of variables, functions and typedefs.
3408: Return a ..._DECL node of some kind representing its definition,
3409: or return 0 if it is undefined.
3410:
3411: If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
3412: If PREFER_TYPE is = 0, we prefer non-TYPE_DECLs.
3413: If PREFER_TYPE is < 0, we arbitrate according to lexical context. */
3414:
3415: tree
3416: lookup_name (name, prefer_type)
3417: tree name;
3418: {
3419: register tree val;
3420:
3421: if (current_binding_level != global_binding_level
3422: && IDENTIFIER_LOCAL_VALUE (name))
3423: val = IDENTIFIER_LOCAL_VALUE (name);
3424: /* In C++ class fields are between local and global scope,
3425: just before the global scope. */
3426: else if (current_class_type)
3427: {
3428: val = IDENTIFIER_CLASS_VALUE (name);
3429: if (val == NULL_TREE
3430: && TYPE_SIZE (current_class_type) == 0
3431: && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
3432: {
3433: /* Try to find values from base classes
3434: if we are presently defining a type.
3435: We are presently only interested in TYPE_DECLs. */
3436: val = lookup_field (current_class_type, name, 0);
3437: if (val == error_mark_node)
3438: return val;
3439: if (val && TREE_CODE (val) != TYPE_DECL)
3440: val = NULL_TREE;
3441: }
3442: if (val == NULL_TREE)
3443: val = IDENTIFIER_GLOBAL_VALUE (name);
3444: }
3445: else
3446: val = IDENTIFIER_GLOBAL_VALUE (name);
3447:
3448: if (val)
3449: {
3450: extern int looking_for_typename;
3451:
3452: /* Arbitrate between finding a TYPE_DECL and finding
3453: other kinds of _DECLs. */
3454: if (TREE_CODE (val) == TYPE_DECL || looking_for_typename < 0)
3455: return val;
3456:
3457: if (IDENTIFIER_HAS_TYPE_VALUE (name))
3458: {
3459: register tree val_as_type = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
3460:
3461: if (val == val_as_type || prefer_type > 0
3462: || looking_for_typename > 0)
3463: return val_as_type;
3464: if (prefer_type == 0)
3465: return val;
3466: return arbitrate_lookup (name, val, val_as_type);
3467: }
3468: if (TREE_TYPE (val) == error_mark_node)
3469: return error_mark_node;
3470: }
3471:
3472: return val;
3473: }
3474:
3475: /* Similar to `lookup_name' but look only at current binding level. */
3476:
3477: static tree
3478: lookup_name_current_level (name)
3479: tree name;
3480: {
3481: register tree t;
3482:
3483: if (current_binding_level == global_binding_level)
3484: return IDENTIFIER_GLOBAL_VALUE (name);
3485:
3486: if (IDENTIFIER_LOCAL_VALUE (name) == 0)
3487: return 0;
3488:
3489: for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
3490: if (DECL_NAME (t) == name)
3491: break;
3492:
3493: return t;
3494: }
3495:
3496: /* Array for holding types considered "built-in". These types
3497: are output in the module in which `main' is defined. */
3498: static tree *builtin_type_tdescs_arr;
3499: static int builtin_type_tdescs_len, builtin_type_tdescs_max;
3500:
3501: /* Push the declarations of builtin types into the namespace.
3502: RID_INDEX, if < RID_MAX is the index of the builtin type
3503: in the array RID_POINTERS. NAME is the name used when looking
3504: up the builtin type. TYPE is the _TYPE node for the builtin type. */
3505:
3506: static void
3507: record_builtin_type (rid_index, name, type)
3508: enum rid rid_index;
3509: char *name;
3510: tree type;
3511: {
3512: tree rname = NULL_TREE, tname = NULL_TREE;
3513: tree tdecl;
3514:
3515: if (rid_index < RID_MAX)
3516: rname = ridpointers[(int) rid_index];
3517: if (name)
3518: tname = get_identifier (name);
3519:
3520: if (tname)
3521: {
3522: tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
3523: DECL_IGNORED_P (TYPE_NAME (type)) = 0;
3524: set_identifier_type_value (tname, NULL_TREE);
3525: if (rid_index < RID_MAX)
3526: IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
3527: }
3528: if (rname != NULL_TREE)
3529: {
3530: if (tname != NULL_TREE)
3531: {
3532: set_identifier_type_value (rname, NULL_TREE);
3533: IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
3534: }
3535: else
3536: {
3537: tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
3538: set_identifier_type_value (rname, NULL_TREE);
3539: }
3540: }
3541:
3542: if (flag_dossier)
3543: {
3544: if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
3545: {
3546: builtin_type_tdescs_max *= 2;
3547: builtin_type_tdescs_arr
3548: = (tree *)xrealloc (builtin_type_tdescs_arr,
3549: builtin_type_tdescs_max * sizeof (tree));
3550: }
3551: builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
3552: if (TREE_CODE (type) != POINTER_TYPE)
3553: {
3554: builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3555: = build_pointer_type (type);
3556: builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3557: = build_type_variant (TYPE_POINTER_TO (type), 1, 0);
3558: }
3559: if (TREE_CODE (type) != VOID_TYPE)
3560: {
3561: builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3562: = build_reference_type (type);
3563: builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3564: = build_type_variant (TYPE_REFERENCE_TO (type), 1, 0);
3565: }
3566: }
3567: }
3568:
3569: static void
3570: output_builtin_tdesc_entries ()
3571: {
3572: extern struct obstack permanent_obstack;
3573:
3574: /* If there's more than one main in this file, don't crash. */
3575: if (builtin_type_tdescs_arr == 0)
3576: return;
3577:
3578: push_obstacks (&permanent_obstack, &permanent_obstack);
3579: while (builtin_type_tdescs_len > 0)
3580: {
3581: tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
3582: tree tdesc = build_t_desc (type, 0);
3583: TREE_ASM_WRITTEN (tdesc) = 0;
3584: build_t_desc (type, 2);
3585: }
3586: free (builtin_type_tdescs_arr);
3587: builtin_type_tdescs_arr = 0;
3588: pop_obstacks ();
3589: }
3590:
3591: /* Push overloaded decl, in global scope, with one argument so it
3592: can be used as a callback from define_function. */
3593: static void
3594: push_overloaded_decl_1 (x)
3595: tree x;
3596: {
3597: push_overloaded_decl (x, 0);
3598: }
3599:
3600: /* Create the predefined scalar types of C,
3601: and some nodes representing standard constants (0, 1, (void *)0).
3602: Initialize the global binding level.
3603: Make definitions for built-in primitive functions. */
3604:
3605: void
3606: init_decl_processing ()
3607: {
3608: register tree endlink, int_endlink, double_endlink, ptr_endlink;
3609: tree fields[20];
3610: /* Either char* or void*. */
3611: tree traditional_ptr_type_node;
3612: /* Data type of memcpy. */
3613: tree memcpy_ftype;
3614: int wchar_type_size;
3615:
3616: /* Have to make these distinct before we try using them. */
3617: lang_name_cplusplus = get_identifier ("C++");
3618: lang_name_c = get_identifier ("C");
3619:
3620: /* Initially, C. */
3621: current_lang_name = lang_name_c;
3622:
3623: current_function_decl = NULL_TREE;
3624: named_labels = NULL_TREE;
3625: named_label_uses = NULL_TREE;
3626: current_binding_level = NULL_BINDING_LEVEL;
3627: free_binding_level = NULL_BINDING_LEVEL;
3628:
3629: gcc_obstack_init (&decl_obstack);
3630: if (flag_dossier)
3631: {
3632: builtin_type_tdescs_max = 100;
3633: builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
3634: }
3635:
3636: /* Must lay these out before anything else gets laid out. */
3637: error_mark_node = make_node (ERROR_MARK);
3638: TREE_PERMANENT (error_mark_node) = 1;
3639: TREE_TYPE (error_mark_node) = error_mark_node;
3640: error_mark_list = build_tree_list (error_mark_node, error_mark_node);
3641: TREE_TYPE (error_mark_list) = error_mark_node;
3642:
3643: pushlevel (0); /* make the binding_level structure for global names. */
3644: global_binding_level = current_binding_level;
3645:
3646: this_identifier = get_identifier (THIS_NAME);
3647: in_charge_identifier = get_identifier (IN_CHARGE_NAME);
3648:
3649: /* Define `int' and `char' first so that dbx will output them first. */
3650:
3651: integer_type_node = make_signed_type (INT_TYPE_SIZE);
3652: record_builtin_type (RID_INT, 0, integer_type_node);
3653:
3654: /* Define `char', which is like either `signed char' or `unsigned char'
3655: but not the same as either. */
3656:
3657: char_type_node =
3658: (flag_signed_char
3659: ? make_signed_type (CHAR_TYPE_SIZE)
3660: : make_unsigned_type (CHAR_TYPE_SIZE));
3661: record_builtin_type (RID_CHAR, "char", char_type_node);
3662:
3663: long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
3664: record_builtin_type (RID_LONG, "long int", long_integer_type_node);
3665:
3666: unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
3667: record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
3668:
3669: long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
3670: record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
3671: record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
3672:
3673: /* `unsigned long' is the standard type for sizeof.
3674: Traditionally, use a signed type.
3675: Note that stddef.h uses `unsigned long',
3676: and this must agree, even of long and int are the same size. */
3677: if (flag_traditional)
3678: sizetype = long_integer_type_node;
3679: else
3680: sizetype
3681: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
3682:
3683: ptrdiff_type_node
3684: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
3685:
3686: TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
3687: TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
3688: TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
3689: TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
3690: TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
3691:
3692: short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
3693: record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
3694:
3695: long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
3696: record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
3697: short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
3698: record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
3699: record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
3700: long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
3701: record_builtin_type (RID_MAX, "long long unsigned int", long_long_unsigned_type_node);
3702: record_builtin_type (RID_MAX, "long long unsigned", long_long_unsigned_type_node);
3703:
3704: /* Define both `signed char' and `unsigned char'. */
3705: signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
3706: record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
3707: unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
3708: record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
3709:
3710: float_type_node = make_node (REAL_TYPE);
3711: TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
3712: record_builtin_type (RID_FLOAT, 0, float_type_node);
3713: layout_type (float_type_node);
3714:
3715: double_type_node = make_node (REAL_TYPE);
3716: if (flag_short_double)
3717: TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
3718: else
3719: TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
3720: record_builtin_type (RID_DOUBLE, 0, double_type_node);
3721: layout_type (double_type_node);
3722:
3723: long_double_type_node = make_node (REAL_TYPE);
3724: TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
3725: record_builtin_type (RID_MAX, "long double", long_double_type_node);
3726: layout_type (long_double_type_node);
3727:
3728: wchar_type_node
3729: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
3730: wchar_type_size = TYPE_PRECISION (wchar_type_node);
3731: signed_wchar_type_node = type_for_size (wchar_type_size, 0);
3732: unsigned_wchar_type_node = type_for_size (wchar_type_size, 1);
3733:
3734: integer_zero_node = build_int_2 (0, 0);
3735: TREE_TYPE (integer_zero_node) = integer_type_node;
3736: integer_one_node = build_int_2 (1, 0);
3737: TREE_TYPE (integer_one_node) = integer_type_node;
3738: integer_two_node = build_int_2 (2, 0);
3739: TREE_TYPE (integer_two_node) = integer_type_node;
3740: integer_three_node = build_int_2 (3, 0);
3741: TREE_TYPE (integer_three_node) = integer_type_node;
3742: empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
3743:
3744: /* These are needed by stor-layout.c. */
3745: size_zero_node = size_int (0);
3746: size_one_node = size_int (1);
3747:
3748: void_type_node = make_node (VOID_TYPE);
3749: record_builtin_type (RID_VOID, 0, void_type_node);
3750: layout_type (void_type_node); /* Uses integer_zero_node. */
3751: void_list_node = build_tree_list (NULL_TREE, void_type_node);
3752: TREE_PARMLIST (void_list_node) = 1;
3753:
3754: null_pointer_node = build_int_2 (0, 0);
3755: TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
3756: layout_type (TREE_TYPE (null_pointer_node));
3757:
3758: /* Used for expressions that do nothing, but are not errors. */
3759: void_zero_node = build_int_2 (0, 0);
3760: TREE_TYPE (void_zero_node) = void_type_node;
3761:
3762: string_type_node = build_pointer_type (char_type_node);
3763: const_string_type_node = build_pointer_type (build_type_variant (char_type_node, 1, 0));
3764: record_builtin_type (RID_MAX, 0, string_type_node);
3765:
3766: /* make a type for arrays of 256 characters.
3767: 256 is picked randomly because we have a type for integers from 0 to 255.
3768: With luck nothing will ever really depend on the length of this
3769: array type. */
3770: char_array_type_node
3771: = build_array_type (char_type_node, unsigned_char_type_node);
3772: /* Likewise for arrays of ints. */
3773: int_array_type_node
3774: = build_array_type (integer_type_node, unsigned_char_type_node);
3775: /* This is for wide string constants. */
3776: wchar_array_type_node
3777: = build_array_type (wchar_type_node, unsigned_char_type_node);
3778:
3779: /* This is just some anonymous class type. Nobody should ever
3780: need to look inside this envelope. */
3781: class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
3782:
3783: default_function_type
3784: = build_function_type (integer_type_node, NULL_TREE);
3785: build_pointer_type (default_function_type);
3786:
3787: ptr_type_node = build_pointer_type (void_type_node);
3788: const_ptr_type_node = build_pointer_type (build_type_variant (void_type_node, 1, 0));
3789: record_builtin_type (RID_MAX, 0, ptr_type_node);
3790: endlink = void_list_node;
3791: int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
3792: double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
3793: ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
3794:
3795: double_ftype_double
3796: = build_function_type (double_type_node, double_endlink);
3797:
3798: double_ftype_double_double
3799: = build_function_type (double_type_node,
3800: tree_cons (NULL_TREE, double_type_node, double_endlink));
3801:
3802: int_ftype_int
3803: = build_function_type (integer_type_node, int_endlink);
3804:
3805: long_ftype_long
3806: = build_function_type (long_integer_type_node,
3807: tree_cons (NULL_TREE, long_integer_type_node, endlink));
3808:
3809: void_ftype_ptr_ptr_int
3810: = build_function_type (void_type_node,
3811: tree_cons (NULL_TREE, ptr_type_node,
3812: tree_cons (NULL_TREE, ptr_type_node,
3813: int_endlink)));
3814:
3815: int_ftype_cptr_cptr_sizet
3816: = build_function_type (integer_type_node,
3817: tree_cons (NULL_TREE, const_ptr_type_node,
3818: tree_cons (NULL_TREE, const_ptr_type_node,
3819: tree_cons (NULL_TREE,
3820: sizetype,
3821: endlink))));
3822:
3823: void_ftype_ptr_int_int
3824: = build_function_type (void_type_node,
3825: tree_cons (NULL_TREE, ptr_type_node,
3826: tree_cons (NULL_TREE, integer_type_node,
3827: int_endlink)));
3828:
3829: string_ftype_ptr_ptr /* strcpy prototype */
3830: = build_function_type (string_type_node,
3831: tree_cons (NULL_TREE, string_type_node,
3832: tree_cons (NULL_TREE,
3833: const_string_type_node,
3834: endlink)));
3835:
3836: int_ftype_string_string /* strcmp prototype */
3837: = build_function_type (integer_type_node,
3838: tree_cons (NULL_TREE, const_string_type_node,
3839: tree_cons (NULL_TREE,
3840: const_string_type_node,
3841: endlink)));
3842:
3843: sizet_ftype_string /* strlen prototype */
3844: = build_function_type (sizetype,
3845: tree_cons (NULL_TREE, const_string_type_node,
3846: endlink));
3847:
3848: traditional_ptr_type_node
3849: = (flag_traditional ? string_type_node : ptr_type_node);
3850:
3851: memcpy_ftype /* memcpy prototype */
3852: = build_function_type (traditional_ptr_type_node,
3853: tree_cons (NULL_TREE, ptr_type_node,
3854: tree_cons (NULL_TREE, const_ptr_type_node,
3855: tree_cons (NULL_TREE,
3856: sizetype,
3857: endlink))));
3858:
3859: ptr_ftype_long /* builtin new prototype */
3860: = build_function_type (ptr_type_node, TYPE_ARG_TYPES (long_ftype_long));
3861:
3862: ptr_ftype_ptr_int_int_ptr /* builtin vec new prototype */
3863: = build_function_type (ptr_type_node,
3864: tree_cons (NULL_TREE, ptr_type_node,
3865: tree_cons (NULL_TREE, integer_type_node,
3866: tree_cons (NULL_TREE, integer_type_node,
3867: ptr_endlink))));
3868:
3869: void_ftype_ptr /* builtin deleted prototype */
3870: = build_function_type (void_type_node, ptr_endlink);
3871:
3872: void_ftype_ptr_int_int_ptr_int_int /* builtin vec delete prototype */
3873: = build_function_type (void_type_node,
3874: tree_cons (NULL_TREE, ptr_type_node,
3875: tree_cons (NULL_TREE, integer_type_node,
3876: tree_cons (NULL_TREE, integer_type_node,
3877: TYPE_ARG_TYPES (void_ftype_ptr_int_int)))));
3878:
3879: #ifdef VTABLE_USES_MASK
3880: /* This is primarily for virtual function definition. We
3881: declare an array of `void *', which can later be
3882: converted to the appropriate function pointer type.
3883: To do pointers to members, we need a mask which can
3884: distinguish an index value into a virtual function table
3885: from an address. */
3886: vtbl_mask = build_int_2 (~(VINDEX_MAX - 1), -1);
3887: #endif
3888:
3889: vtbl_type_node
3890: = build_array_type (ptr_type_node, NULL_TREE);
3891: layout_type (vtbl_type_node);
3892: vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0);
3893: record_builtin_type (RID_MAX, 0, vtbl_type_node);
3894:
3895: builtin_function ("__builtin_constant_p",
3896: build_function_type (integer_type_node, endlink),
3897: BUILT_IN_CONSTANT_P, 0);
3898:
3899: builtin_function ("__builtin_alloca",
3900: build_function_type (ptr_type_node,
3901: tree_cons (NULL_TREE,
3902: sizetype,
3903: endlink)),
3904: BUILT_IN_ALLOCA, "alloca");
3905: #if 0
3906: builtin_function ("alloca",
3907: build_function_type (ptr_type_node,
3908: tree_cons (NULL_TREE,
3909: sizetype,
3910: endlink)),
3911: BUILT_IN_ALLOCA, 0);
3912: #endif
3913:
3914: builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, 0);
3915: builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, 0);
3916: builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS, 0);
3917: builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, 0);
3918: #if 0
3919: /* This does not work well with libg++. */
3920: builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, 0);
3921: builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, 0);
3922: builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, 0);
3923: #endif
3924: builtin_function ("__builtin_saveregs", default_function_type,
3925: BUILT_IN_SAVEREGS, 0);
3926: #ifdef EXPAND_BUILTIN_VARARGS
3927: builtin_function ("__builtin_varargs",
3928: build_function_type (ptr_type_node,
3929: tree_cons (NULL_TREE,
3930: integer_type_node,
3931: endlink)),
3932: BUILT_IN_VARARGS, 0);
3933: #endif
3934: builtin_function ("__builtin_classify_type", default_function_type,
3935: BUILT_IN_CLASSIFY_TYPE, 0);
3936: builtin_function ("__builtin_next_arg",
3937: build_function_type (ptr_type_node, endlink),
3938: BUILT_IN_NEXT_ARG, 0);
3939:
3940: /* Currently under experimentation. */
3941: builtin_function ("__builtin_memcpy", memcpy_ftype,
3942: BUILT_IN_MEMCPY, "memcpy");
3943: builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
3944: BUILT_IN_MEMCMP, "memcmp");
3945: builtin_function ("__builtin_strcmp", int_ftype_string_string,
3946: BUILT_IN_STRCMP, "strcmp");
3947: builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
3948: BUILT_IN_STRCPY, "strcpy");
3949: builtin_function ("__builtin_strlen", sizet_ftype_string,
3950: BUILT_IN_STRLEN, "strlen");
3951: builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, 0);
3952: builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, 0);
3953: builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, 0);
3954: builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, 0);
3955: builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, 0);
3956:
3957: #if 0
3958: /* Support for these has not been written in either expand_builtin
3959: or build_function_call. */
3960: builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
3961: builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
3962: builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 0);
3963: builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
3964: builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, 0);
3965: builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, 0);
3966: builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 0);
3967: builtin_function ("__builtin_fsqrt", double_ftype_double, BUILT_IN_FSQRT, 0);
3968: builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 0);
3969: builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 0);
3970: #endif
3971:
3972: /* C++ extensions */
3973:
3974: unknown_type_node = make_node (UNKNOWN_TYPE);
3975: pushdecl (build_decl (TYPE_DECL,
3976: get_identifier ("unknown type"),
3977: unknown_type_node));
3978: TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
3979: TYPE_ALIGN (unknown_type_node) = 1;
3980: TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
3981: /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
3982: TREE_TYPE (unknown_type_node) = unknown_type_node;
3983: /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
3984: TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
3985: TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
3986:
3987: /* This is a hack that should go away when we deliver the
3988: real gc code. */
3989: if (flag_gc)
3990: {
3991: builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
3992: pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
3993: }
3994:
3995: /* Simplify life by making a "vtable_entry_type". Give its
3996: fields names so that the debugger can use them. */
3997:
3998: vtable_entry_type = make_lang_type (RECORD_TYPE);
3999: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_DELTA_NAME), short_integer_type_node);
4000: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_INDEX_NAME), short_integer_type_node);
4001: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_PFN_NAME), ptr_type_node);
4002: finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
4003: double_type_node);
4004:
4005: /* Make this part of an invisible union. */
4006: fields[3] = copy_node (fields[2]);
4007: TREE_TYPE (fields[3]) = short_integer_type_node;
4008: DECL_NAME (fields[3]) = get_identifier (VTABLE_DELTA2_NAME);
4009: DECL_MODE (fields[3]) = TYPE_MODE (short_integer_type_node);
4010: DECL_SIZE (fields[3]) = TYPE_SIZE (short_integer_type_node);
4011: TREE_UNSIGNED (fields[3]) = 0;
4012: TREE_CHAIN (fields[2]) = fields[3];
4013: vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
4014: record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
4015:
4016: if (flag_dossier)
4017: {
4018: /* Must build __t_desc type. Currently, type descriptors look like this:
4019:
4020: struct __t_desc
4021: {
4022: const char *name;
4023: int size;
4024: int bits;
4025: struct __t_desc *points_to;
4026: int ivars_count, meths_count;
4027: struct __i_desc *ivars[];
4028: struct __m_desc *meths[];
4029: struct __t_desc *parents[];
4030: struct __t_desc *vbases[];
4031: int offsets[];
4032: };
4033:
4034: ...as per Linton's paper. */
4035:
4036: __t_desc_type_node = make_lang_type (RECORD_TYPE);
4037: __i_desc_type_node = make_lang_type (RECORD_TYPE);
4038: __m_desc_type_node = make_lang_type (RECORD_TYPE);
4039: __t_desc_array_type = build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
4040: __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
4041: __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
4042:
4043: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4044: string_type_node);
4045: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
4046: unsigned_type_node);
4047: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
4048: unsigned_type_node);
4049: fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("points_to"),
4050: TYPE_POINTER_TO (__t_desc_type_node));
4051: fields[4] = build_lang_field_decl (FIELD_DECL,
4052: get_identifier ("ivars_count"),
4053: integer_type_node);
4054: fields[5] = build_lang_field_decl (FIELD_DECL,
4055: get_identifier ("meths_count"),
4056: integer_type_node);
4057: fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
4058: build_pointer_type (__i_desc_array_type));
4059: fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
4060: build_pointer_type (__m_desc_array_type));
4061: fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
4062: build_pointer_type (__t_desc_array_type));
4063: fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
4064: build_pointer_type (__t_desc_array_type));
4065: fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
4066: build_pointer_type (integer_type_node));
4067: finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
4068:
4069: /* ivar descriptors look like this:
4070:
4071: struct __i_desc
4072: {
4073: const char *name;
4074: int offset;
4075: struct __t_desc *type;
4076: };
4077: */
4078:
4079: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4080: string_type_node);
4081: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
4082: integer_type_node);
4083: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
4084: TYPE_POINTER_TO (__t_desc_type_node));
4085: finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, integer_type_node);
4086:
4087: /* method descriptors look like this:
4088:
4089: struct __m_desc
4090: {
4091: const char *name;
4092: int vindex;
4093: struct __t_desc *vcontext;
4094: struct __t_desc *return_type;
4095: void (*address)();
4096: short parm_count;
4097: short required_parms;
4098: struct __t_desc *parm_types[];
4099: };
4100: */
4101:
4102: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4103: string_type_node);
4104: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
4105: integer_type_node);
4106: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
4107: TYPE_POINTER_TO (__t_desc_type_node));
4108: fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
4109: TYPE_POINTER_TO (__t_desc_type_node));
4110: fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
4111: build_pointer_type (default_function_type));
4112: fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
4113: short_integer_type_node);
4114: fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
4115: short_integer_type_node);
4116: fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
4117: build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
4118: finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node);
4119: }
4120:
4121: #ifdef SOS
4122: if (flag_all_virtual == 2)
4123: {
4124: tree ptr_ftype_default
4125: = build_function_type (ptr_type_node, NULL_TREE);
4126:
4127: builtin_function ("sosFindCode", ptr_ftype_default, NOT_BUILT_IN, 0);
4128: builtin_function ("sosLookup", ptr_ftype_default, NOT_BUILT_IN, 0);
4129: builtin_function ("sosImport", ptr_ftype_default, NOT_BUILT_IN, 0);
4130: builtin_function ("sosDynError", ptr_ftype_default, NOT_BUILT_IN, 0);
4131:
4132: zlink_type = make_lang_type (RECORD_TYPE);
4133: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("n"), string_type_node);
4134: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("t"), char_type_node);
4135: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr"), TYPE_POINTER_TO (default_function_type));
4136: finish_builtin_type (zlink_type, "__zlink", fields, 2, integer_type_node);
4137:
4138: zret_type = make_lang_type (RECORD_TYPE);
4139: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("cn"), string_type_node);
4140: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr"), build_pointer_type (TYPE_POINTER_TO (default_function_type)));
4141: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("n"), integer_type_node);
4142: fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("bcl"), string_type_node);
4143: fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("f"), char_type_node);
4144: finish_builtin_type (zret_type, "__zret", fields, 4, integer_type_node);
4145: }
4146: #endif
4147:
4148: /* Now, C++. */
4149: current_lang_name = lang_name_cplusplus;
4150: if (flag_dossier)
4151: {
4152: int i = builtin_type_tdescs_len;
4153: while (i > 0)
4154: {
4155: tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
4156: TREE_ASM_WRITTEN (tdesc) = 1;
4157: TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
4158: }
4159: }
4160:
4161: auto_function ("__builtin_new", ptr_ftype_long, NOT_BUILT_IN);
4162: auto_function ("__builtin_delete", void_ftype_ptr, NOT_BUILT_IN);
4163:
4164: abort_fndecl
4165: = define_function ("abort",
4166: build_function_type (void_type_node, void_list_node),
4167: NOT_BUILT_IN, 0, 0);
4168:
4169: unhandled_exception_fndecl
4170: = define_function ("__unhandled_exception",
4171: build_function_type (void_type_node, NULL_TREE),
4172: NOT_BUILT_IN, 0, 0);
4173:
4174: /* Perform other language dependent initializations. */
4175: init_class_processing ();
4176: init_init_processing ();
4177: init_search_processing ();
4178:
4179: if (flag_handle_exceptions)
4180: {
4181: if (flag_handle_exceptions == 2)
4182: /* Too much trouble to inline all the trys needed for this. */
4183: flag_this_is_variable = 2;
4184: init_exception_processing ();
4185: }
4186: if (flag_gc)
4187: init_gc_processing ();
4188: if (flag_no_inline)
4189: flag_inline_functions = 0, flag_default_inline = 0;
4190: if (flag_cadillac)
4191: init_cadillac ();
4192:
4193: /* Warnings about failure to return values are too valuable to forego. */
4194: warn_return_type = 1;
4195: }
4196:
4197: /* Make a definition for a builtin function named NAME and whose data type
4198: is TYPE. TYPE should be a function type with argument types.
4199: FUNCTION_CODE tells later passes how to compile calls to this function.
4200: See tree.h for its possible values.
4201:
4202: If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
4203: the name to be called if we can't opencode the function. */
4204:
4205: tree
4206: define_function (name, type, function_code, pfn, library_name)
4207: char *name;
4208: tree type;
4209: enum built_in_function function_code;
4210: void (*pfn)();
4211: char *library_name;
4212: {
4213: tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
4214: TREE_EXTERNAL (decl) = 1;
4215: TREE_PUBLIC (decl) = 1;
4216:
4217: /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
4218: we cannot change DECL_ASSEMBLER_NAME until we have installed this
4219: function in the namespace. */
4220: if (pfn) (*pfn) (decl);
4221: if (library_name)
4222: DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
4223: make_function_rtl (decl);
4224: if (function_code != NOT_BUILT_IN)
4225: {
4226: DECL_BUILT_IN (decl) = 1;
4227: DECL_SET_FUNCTION_CODE (decl, function_code);
4228: }
4229: return decl;
4230: }
4231:
4232: /* Called when a declaration is seen that contains no names to declare.
4233: If its type is a reference to a structure, union or enum inherited
4234: from a containing scope, shadow that tag name for the current scope
4235: with a forward reference.
4236: If its type defines a new named structure or union
4237: or defines an enum, it is valid but we need not do anything here.
4238: Otherwise, it is an error.
4239:
4240: C++: may have to grok the declspecs to learn about static,
4241: complain for anonymous unions. */
4242:
4243: void
4244: shadow_tag (declspecs)
4245: tree declspecs;
4246: {
4247: int found_tag = 0;
4248: int warned = 0;
4249: register tree link;
4250: register enum tree_code code, ok_code = ERROR_MARK;
4251: register tree t = NULL_TREE;
4252:
4253: for (link = declspecs; link; link = TREE_CHAIN (link))
4254: {
4255: register tree value = TREE_VALUE (link);
4256:
4257: code = TREE_CODE (value);
4258: if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
4259: /* Used to test also that TYPE_SIZE (value) != 0.
4260: That caused warning for `struct foo;' at top level in the file. */
4261: {
4262: register tree name = TYPE_NAME (value);
4263:
4264: if (name == NULL_TREE)
4265: name = lookup_tag_reverse (value, NULL_TREE);
4266:
4267: if (name && TREE_CODE (name) == TYPE_DECL)
4268: name = DECL_NAME (name);
4269:
4270: if (class_binding_level)
4271: t = lookup_tag (code, name, class_binding_level, 1);
4272: else
4273: t = lookup_tag (code, name, current_binding_level, 1);
4274:
4275: if (t == 0)
4276: {
4277: push_obstacks (&permanent_obstack, &permanent_obstack);
4278: if (IS_AGGR_TYPE_CODE (code))
4279: t = make_lang_type (code);
4280: else
4281: t = make_node (code);
4282: pushtag (name, t);
4283: pop_obstacks ();
4284: ok_code = code;
4285: break;
4286: }
4287: else if (name != 0 || code == ENUMERAL_TYPE)
4288: ok_code = code;
4289:
4290: if (ok_code != ERROR_MARK)
4291: found_tag++;
4292: else
4293: {
4294: if (!warned)
4295: warning ("useless keyword or type name in declaration");
4296: warned = 1;
4297: }
4298: }
4299: }
4300:
4301: /* This is where the variables in an anonymous union are
4302: declared. An anonymous union declaration looks like:
4303: union { ... } ;
4304: because there is no declarator after the union, the parser
4305: sends that declaration here. */
4306: if (ok_code == UNION_TYPE
4307: && t != NULL_TREE
4308: && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
4309: && ANON_AGGRNAME_P (TYPE_NAME (t)))
4310: || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
4311: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))
4312: && TYPE_FIELDS (t))
4313: {
4314: tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE);
4315: finish_anon_union (decl);
4316: }
4317: else if (ok_code == RECORD_TYPE
4318: && found_tag == 1
4319: && TYPE_LANG_SPECIFIC (t)
4320: && CLASSTYPE_DECLARED_EXCEPTION (t))
4321: {
4322: if (TYPE_SIZE (t))
4323: error_with_aggr_type (t, "redeclaration of exception `%s'");
4324: else
4325: {
4326: tree ename, decl;
4327:
4328: push_obstacks (&permanent_obstack, &permanent_obstack);
4329:
4330: pushclass (t, 0);
4331: finish_exception (t, NULL_TREE);
4332:
4333: ename = TYPE_NAME (t);
4334: if (TREE_CODE (ename) == TYPE_DECL)
4335: ename = DECL_NAME (ename);
4336: decl = build_lang_field_decl (VAR_DECL, ename, t);
4337: finish_exception_decl (current_class_name, decl);
4338: end_exception_decls ();
4339:
4340: pop_obstacks ();
4341: }
4342: }
4343: else if (!warned && found_tag > 1)
4344: warning ("multiple types in one declaration");
4345: }
4346:
4347: /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
4348:
4349: tree
4350: groktypename (typename)
4351: tree typename;
4352: {
4353: if (TREE_CODE (typename) != TREE_LIST)
4354: return typename;
4355: return grokdeclarator (TREE_VALUE (typename),
4356: TREE_PURPOSE (typename),
4357: TYPENAME, 0, NULL_TREE);
4358: }
4359:
4360: /* Decode a declarator in an ordinary declaration or data definition.
4361: This is called as soon as the type information and variable name
4362: have been parsed, before parsing the initializer if any.
4363: Here we create the ..._DECL node, fill in its type,
4364: and put it on the list of decls for the current context.
4365: The ..._DECL node is returned as the value.
4366:
4367: Exception: for arrays where the length is not specified,
4368: the type is left null, to be filled in by `finish_decl'.
4369:
4370: Function definitions do not come here; they go to start_function
4371: instead. However, external and forward declarations of functions
4372: do go through here. Structure field declarations are done by
4373: grokfield and not through here. */
4374:
4375: /* Set this to zero to debug not using the temporary obstack
4376: to parse initializers. */
4377: int debug_temp_inits = 1;
4378:
4379: tree
4380: start_decl (declarator, declspecs, initialized, raises)
4381: tree declspecs, declarator;
4382: int initialized;
4383: tree raises;
4384: {
4385: register tree decl = grokdeclarator (declarator, declspecs,
4386: NORMAL, initialized, raises);
4387: register tree type, tem;
4388: tree context;
4389:
4390: int init_written = initialized;
4391:
4392: if (decl == NULL_TREE) return decl;
4393:
4394: type = TREE_TYPE (decl);
4395:
4396: /* Don't lose if destructors must be executed at file-level. */
4397: if (TREE_STATIC (decl)
4398: && TYPE_NEEDS_DESTRUCTOR (type)
4399: && TREE_PERMANENT (decl) == 0)
4400: {
4401: push_obstacks (&permanent_obstack, &permanent_obstack);
4402: decl = copy_node (decl);
4403: if (TREE_CODE (type) == ARRAY_TYPE)
4404: {
4405: tree itype = TYPE_DOMAIN (type);
4406: if (itype && ! TREE_PERMANENT (itype))
4407: {
4408: itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
4409: type = build_cplus_array_type (TREE_TYPE (type), itype);
4410: TREE_TYPE (decl) = type;
4411: }
4412: }
4413: pop_obstacks ();
4414: }
4415:
4416: /* Interesting work for this is done in `finish_exception_decl'. */
4417: if (TREE_CODE (type) == RECORD_TYPE
4418: && CLASSTYPE_DECLARED_EXCEPTION (type))
4419: return decl;
4420:
4421: /* Corresponding pop_obstacks is done in `finish_decl'. */
4422: push_obstacks_nochange ();
4423:
4424: context = DECL_LANG_SPECIFIC (decl) ? DECL_CLASS_CONTEXT (decl) : NULL_TREE;
4425:
4426: if (processing_template_decl)
4427: {
4428: tree d;
4429: if (TREE_CODE (decl) == FUNCTION_DECL)
4430: {
4431: /* Declarator is a call_expr; extract arguments from it, since
4432: grokdeclarator didn't do it. */
4433: tree args;
4434: args = copy_to_permanent (last_function_parms);
4435: if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
4436: {
4437: tree t = TREE_TYPE (decl); /* method type */
4438: tree decl;
4439:
4440: t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
4441: t = build_pointer_type (t); /* base type of `this' */
4442: t = build_type_variant (t, !flag_this_is_variable,
4443: 0); /* type of `this' */
4444: t = build (PARM_DECL, t, this_identifier);
4445: TREE_CHAIN (t) = args;
4446: args = t;
4447: }
4448: DECL_ARGUMENTS (decl) = args;
4449: }
4450: d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
4451: TREE_PUBLIC (d) = TREE_PUBLIC (decl) = 0;
4452: TREE_STATIC (d) = TREE_STATIC (decl);
4453: TREE_EXTERNAL (d) = (TREE_EXTERNAL (decl)
4454: && !(context && !DECL_EXTERNAL (decl)));
4455: DECL_TEMPLATE_RESULT (d) = decl;
4456: DECL_OVERLOADED (d) = 1;
4457: decl = d;
4458: }
4459:
4460: if (context && TYPE_SIZE (context) != NULL_TREE)
4461: {
4462: /* If it was not explicitly declared `extern',
4463: revoke any previous claims of TREE_EXTERNAL. */
4464: if (DECL_EXTERNAL (decl) == 0)
4465: TREE_EXTERNAL (decl) = 0;
4466: if (DECL_LANG_SPECIFIC (decl))
4467: DECL_IN_AGGR_P (decl) = 0;
4468: pushclass (context, 2);
4469: }
4470:
4471: /* If this type of object needs a cleanup, and control may
4472: jump past it, make a new binding level so that it is cleaned
4473: up only when it is initialized first. */
4474: if (TYPE_NEEDS_DESTRUCTOR (type)
4475: && current_binding_level->more_cleanups_ok == 0)
4476: pushlevel_temporary (1);
4477:
4478: if (initialized)
4479: /* Is it valid for this decl to have an initializer at all?
4480: If not, set INITIALIZED to zero, which will indirectly
4481: tell `finish_decl' to ignore the initializer once it is parsed. */
4482: switch (TREE_CODE (decl))
4483: {
4484: case TYPE_DECL:
4485: /* typedef foo = bar means give foo the same type as bar.
4486: We haven't parsed bar yet, so `finish_decl' will fix that up.
4487: Any other case of an initialization in a TYPE_DECL is an error. */
4488: if (pedantic || list_length (declspecs) > 1)
4489: {
4490: error ("typedef `%s' is initialized",
4491: IDENTIFIER_POINTER (DECL_NAME (decl)));
4492: initialized = 0;
4493: }
4494: break;
4495:
4496: case FUNCTION_DECL:
4497: error ("function `%s' is initialized like a variable",
4498: IDENTIFIER_POINTER (DECL_NAME (decl)));
4499: initialized = 0;
4500: break;
4501:
4502: default:
4503: /* Don't allow initializations for incomplete types
4504: except for arrays which might be completed by the initialization. */
4505: if (TYPE_SIZE (type) != 0)
4506: ; /* A complete type is ok. */
4507: else if (TREE_CODE (type) != ARRAY_TYPE)
4508: {
4509: error ("variable `%s' has initializer but incomplete type",
4510: IDENTIFIER_POINTER (DECL_NAME (decl)));
4511: initialized = 0;
4512: }
4513: else if (TYPE_SIZE (TREE_TYPE (type)) == 0)
4514: {
4515: error ("elements of array `%s' have incomplete type",
4516: IDENTIFIER_POINTER (DECL_NAME (decl)));
4517: initialized = 0;
4518: }
4519: }
4520:
4521: if (!initialized
4522: && TREE_CODE (decl) != TYPE_DECL
4523: && TREE_CODE (decl) != TEMPLATE_DECL
4524: && IS_AGGR_TYPE (type) && ! TREE_EXTERNAL (decl))
4525: {
4526: if (TYPE_SIZE (type) == 0)
4527: {
4528: error ("aggregate `%s' has incomplete type and cannot be initialized",
4529: IDENTIFIER_POINTER (DECL_NAME (decl)));
4530: /* Change the type so that assemble_variable will give
4531: DECL an rtl we can live with: (mem (const_int 0)). */
4532: TREE_TYPE (decl) = error_mark_node;
4533: type = error_mark_node;
4534: }
4535: else
4536: {
4537: /* If any base type in the hierarchy of TYPE needs a constructor,
4538: then we set initialized to 1. This way any nodes which are
4539: created for the purposes of initializing this aggregate
4540: will live as long as it does. This is necessary for global
4541: aggregates which do not have their initializers processed until
4542: the end of the file. */
4543: initialized = TYPE_NEEDS_CONSTRUCTING (type);
4544: }
4545: }
4546:
4547: if (initialized)
4548: {
4549: if (current_binding_level != global_binding_level
4550: && TREE_EXTERNAL (decl))
4551: warning ("declaration of `%s' has `extern' and is initialized",
4552: IDENTIFIER_POINTER (DECL_NAME (decl)));
4553: TREE_EXTERNAL (decl) = 0;
4554: if (current_binding_level == global_binding_level)
4555: TREE_STATIC (decl) = 1;
4556:
4557: /* Tell `pushdecl' this is an initialized decl
4558: even though we don't yet have the initializer expression.
4559: Also tell `finish_decl' it may store the real initializer. */
4560: DECL_INITIAL (decl) = error_mark_node;
4561: }
4562:
4563: /* Add this decl to the current binding level, but not if it
4564: comes from another scope, e.g. a static member variable.
4565: TEM may equal DECL or it may be a previous decl of the same name. */
4566: if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
4567: || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
4568: || TREE_CODE (type) == LANG_TYPE)
4569: tem = decl;
4570: else
4571: {
4572: tem = pushdecl (decl);
4573: if (TREE_CODE (tem) == TREE_LIST)
4574: {
4575: tree tem2 = value_member (decl, tem);
4576: if (tem2 != NULL_TREE)
4577: tem = TREE_VALUE (tem2);
4578: else
4579: {
4580: while (tem && ! decls_match (decl, TREE_VALUE (tem)))
4581: tem = TREE_CHAIN (tem);
4582: if (tem == NULL_TREE)
4583: tem = decl;
4584: else
4585: tem = TREE_VALUE (tem);
4586: }
4587: }
4588: }
4589:
4590: #if 0
4591: /* We don't do this yet for GNU C++. */
4592: /* For a local variable, define the RTL now. */
4593: if (current_binding_level != global_binding_level
4594: /* But not if this is a duplicate decl
4595: and we preserved the rtl from the previous one
4596: (which may or may not happen). */
4597: && DECL_RTL (tem) == 0)
4598: {
4599: if (TYPE_SIZE (TREE_TYPE (tem)) != 0)
4600: expand_decl (tem);
4601: else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
4602: && DECL_INITIAL (tem) != 0)
4603: expand_decl (tem);
4604: }
4605: #endif
4606:
4607: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_OVERLOADED (decl))
4608: /* @@ Also done in start_function. */
4609: tem = push_overloaded_decl (tem, 1);
4610: else if (TREE_CODE (decl) == TEMPLATE_DECL)
4611: {
4612: tree result = DECL_TEMPLATE_RESULT (decl);
4613: if (DECL_CONTEXT (result) != NULL_TREE)
4614: {
4615: tree type, classname, tmpl;
4616: type = DECL_CONTEXT (result);
4617: assert (TREE_CODE (type) == UNINSTANTIATED_P_TYPE);
4618: if (/* TREE_CODE (result) == VAR_DECL */ 1)
4619: {
4620: #if 0
4621: tree tmpl = UPT_TEMPLATE (type);
4622:
4623: fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
4624: print_node_brief (stderr, "", DECL_NAME (tem), 0);
4625: fprintf (stderr, " to class %s\n",
4626: IDENTIFIER_POINTER (DECL_NAME (tmpl)));
4627: DECL_TEMPLATE_MEMBERS (tmpl)
4628: = perm_tree_cons (DECL_NAME (tem), tem,
4629: DECL_TEMPLATE_MEMBERS (tmpl));
4630: #endif
4631: return tem;
4632: }
4633: abort ();
4634: }
4635: else if (TREE_CODE (result) == FUNCTION_DECL)
4636: tem = push_overloaded_decl (tem, 0);
4637: else if (TREE_CODE (result) == VAR_DECL)
4638: {
4639: sorry ("non-function templates not yet supported");
4640: return error_mark_node;
4641: }
4642: else
4643: abort ();
4644: }
4645:
4646: if (init_written
4647: && ! (TREE_CODE (tem) == PARM_DECL
4648: || (TREE_READONLY (tem)
4649: && (TREE_CODE (tem) == VAR_DECL
4650: || TREE_CODE (tem) == FIELD_DECL))))
4651: {
4652: /* When parsing and digesting the initializer,
4653: use temporary storage. Do this even if we will ignore the value. */
4654: if (current_binding_level == global_binding_level && debug_temp_inits)
4655: {
4656: if (TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE)
4657: /* In this case, the initializer must lay down in permanent
4658: storage, since it will be saved until `finish_file' is run. */
4659: ;
4660: else
4661: temporary_allocation ();
4662: }
4663: }
4664:
4665: if (flag_cadillac)
4666: cadillac_start_decl (tem);
4667:
4668: return tem;
4669: }
4670:
4671: static void
4672: make_temporary_for_reference (decl, ctor_call, init, cleanupp)
4673: tree decl, ctor_call, init;
4674: tree *cleanupp;
4675: {
4676: tree type = TREE_TYPE (decl);
4677: tree target_type = TREE_TYPE (type);
4678: tree tmp, tmp_addr;
4679:
4680: if (ctor_call)
4681: {
4682: tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
4683: if (TREE_CODE (tmp_addr) == NOP_EXPR)
4684: tmp_addr = TREE_OPERAND (tmp_addr, 0);
4685: assert (TREE_CODE (tmp_addr) == ADDR_EXPR);
4686: tmp = TREE_OPERAND (tmp_addr, 0);
4687: }
4688: else
4689: {
4690: tmp = get_temp_name (target_type,
4691: current_binding_level == global_binding_level);
4692: tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
4693: }
4694:
4695: TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
4696: DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr);
4697: TREE_TYPE (DECL_INITIAL (decl)) = type;
4698: if (TYPE_NEEDS_CONSTRUCTING (target_type))
4699: {
4700: if (current_binding_level == global_binding_level)
4701: {
4702: /* lay this variable out now. Otherwise `output_addressed_constants'
4703: gets confused by its initializer. */
4704: make_decl_rtl (tmp, 0, 1);
4705: static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
4706: }
4707: else
4708: {
4709: if (ctor_call != NULL_TREE)
4710: init = ctor_call;
4711: else
4712: init = build_method_call (tmp, constructor_name (target_type),
4713: build_tree_list (NULL_TREE, init),
4714: NULL_TREE, LOOKUP_NORMAL);
4715: DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
4716: DECL_INITIAL (decl));
4717: *cleanupp = maybe_build_cleanup (tmp);
4718: }
4719: }
4720: else
4721: {
4722: DECL_INITIAL (tmp) = init;
4723: TREE_STATIC (tmp) = current_binding_level == global_binding_level;
4724: finish_decl (tmp, init, 0, 0);
4725: }
4726: if (TREE_STATIC (tmp))
4727: preserve_initializer ();
4728: }
4729:
4730: /* Handle initialization of references.
4731: These three arguments from from `finish_decl', and have the
4732: same meaning here that they do there. */
4733: static void
4734: grok_reference_init (decl, type, init, cleanupp)
4735: tree decl, type, init;
4736: tree *cleanupp;
4737: {
4738: char *errstr = 0;
4739: int is_reference;
4740: tree tmp;
4741: tree this_ptr_type, actual_init;
4742:
4743: if (init == NULL_TREE)
4744: {
4745: if (DECL_LANG_SPECIFIC (decl) == 0 || DECL_IN_AGGR_P (decl) == 0)
4746: {
4747: error ("variable declared as reference not initialized");
4748: if (TREE_CODE (decl) == VAR_DECL)
4749: SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
4750: }
4751: return;
4752: }
4753:
4754: if (TREE_CODE (init) == TREE_LIST)
4755: init = build_compound_expr (init);
4756: is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE;
4757: tmp = is_reference ? convert_from_reference (init) : init;
4758:
4759: if (is_reference)
4760: {
4761: if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
4762: TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0))
4763: errstr = "initialization of `%s' from dissimilar reference type";
4764: else if (TYPE_READONLY (TREE_TYPE (type))
4765: >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (init))))
4766: {
4767: is_reference = 0;
4768: init = tmp;
4769: }
4770: }
4771: else
4772: {
4773: if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
4774: && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
4775: {
4776: /* Note: default conversion is only called in very
4777: special cases. */
4778: init = default_conversion (init);
4779: }
4780: if (IS_AGGR_TYPE_2 (TREE_TYPE (type), TREE_TYPE (init))
4781: && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
4782: TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0))
4783: {
4784: /* Nothing happens. */
4785: }
4786: else if (TREE_CODE (TREE_TYPE (type)) == TREE_CODE (TREE_TYPE (init)))
4787: {
4788: init = convert (TREE_TYPE (type), init);
4789: }
4790: else if (init != error_mark_node
4791: && ! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
4792: TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0))
4793: errstr = "invalid type conversion for reference";
4794: }
4795:
4796: if (errstr)
4797: {
4798: /* Things did not go smoothly; look for operator& type conversion. */
4799: if (IS_AGGR_TYPE (TREE_TYPE (tmp)))
4800: {
4801: tmp = build_type_conversion (CONVERT_EXPR, type, init, 0);
4802: if (tmp != NULL_TREE)
4803: {
4804: init = tmp;
4805: if (tmp == error_mark_node)
4806: errstr = "ambiguous pointer conversion";
4807: else
4808: errstr = 0;
4809: is_reference = 1;
4810: }
4811: else
4812: {
4813: tmp = build_type_conversion (CONVERT_EXPR, TREE_TYPE (type), init, 0);
4814: if (tmp != NULL_TREE)
4815: {
4816: init = tmp;
4817: if (tmp == error_mark_node)
4818: errstr = "ambiguous pointer conversion";
4819: else
4820: errstr = 0;
4821: is_reference = 0;
4822: }
4823: }
4824: }
4825: /* Look for constructor. */
4826: else if (IS_AGGR_TYPE (TREE_TYPE (type))
4827: && TYPE_HAS_CONSTRUCTOR (TREE_TYPE (type)))
4828: {
4829: tmp = get_temp_name (TREE_TYPE (type),
4830: current_binding_level == global_binding_level);
4831: tmp = build_method_call (tmp, constructor_name (TREE_TYPE (type)),
4832: build_tree_list (NULL_TREE, init),
4833: NULL_TREE, LOOKUP_NORMAL);
4834: if (tmp == NULL_TREE || tmp == error_mark_node)
4835: {
4836: if (TREE_CODE (decl) == VAR_DECL)
4837: SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
4838: error_with_decl (decl, "constructor failed to build reference initializer");
4839: return;
4840: }
4841: make_temporary_for_reference (decl, tmp, init, cleanupp);
4842: goto done;
4843: }
4844: }
4845:
4846: if (errstr)
4847: {
4848: error_with_decl (decl, errstr);
4849: if (TREE_CODE (decl) == VAR_DECL)
4850: SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
4851: return;
4852: }
4853:
4854: /* In the case of initialization, it is permissable
4855: to assign one reference to another. */
4856: this_ptr_type = build_pointer_type (TREE_TYPE (type));
4857:
4858: if (is_reference)
4859: {
4860: if (TREE_SIDE_EFFECTS (init))
4861: DECL_INITIAL (decl) = save_expr (init);
4862: else
4863: DECL_INITIAL (decl) = init;
4864: }
4865: else if (lvalue_p (init))
4866: {
4867: tmp = build_unary_op (ADDR_EXPR, init, 0);
4868: if (TREE_CODE (tmp) == ADDR_EXPR
4869: && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR)
4870: {
4871: /* Associate the cleanup with the reference so that we
4872: don't get burned by "aggressive" cleanup policy. */
4873: *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2);
4874: TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node;
4875: }
4876: if (IS_AGGR_TYPE (TREE_TYPE (this_ptr_type)))
4877: DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp);
4878: else
4879: DECL_INITIAL (decl) = convert (this_ptr_type, tmp);
4880:
4881: DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
4882: if (DECL_INITIAL (decl) == current_class_decl)
4883: DECL_INITIAL (decl) = copy_node (current_class_decl);
4884: TREE_TYPE (DECL_INITIAL (decl)) = type;
4885: }
4886: else if ((actual_init = unary_complex_lvalue (ADDR_EXPR, init)))
4887: {
4888: /* The initializer for this decl goes into its
4889: DECL_REFERENCE_SLOT. Make sure that we can handle
4890: multiple evaluations without ill effect. */
4891: if (TREE_CODE (actual_init) == ADDR_EXPR
4892: && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR)
4893: actual_init = save_expr (actual_init);
4894: DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init);
4895: DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
4896: TREE_TYPE (DECL_INITIAL (decl)) = type;
4897: }
4898: else if (TYPE_READONLY (TREE_TYPE (type)))
4899: /* Section 8.4.3 allows us to make a temporary for
4900: the initialization of const&. */
4901: make_temporary_for_reference (decl, NULL_TREE, init, cleanupp);
4902: else
4903: {
4904: error_with_decl (decl, "type mismatch in initialization of `%s' (use `const')");
4905: DECL_INITIAL (decl) = error_mark_node;
4906: }
4907:
4908: done:
4909: /* ?? Can this be optimized in some cases to
4910: hand back the DECL_INITIAL slot?? */
4911: if (TYPE_SIZE (TREE_TYPE (type)))
4912: {
4913: init = convert_from_reference (decl);
4914: if (TREE_PERMANENT (decl))
4915: init = copy_to_permanent (init);
4916: SET_DECL_REFERENCE_SLOT (decl, init);
4917: }
4918:
4919: if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
4920: {
4921: expand_static_init (decl, DECL_INITIAL (decl));
4922: DECL_INITIAL (decl) = 0;
4923: }
4924: }
4925:
4926: /* Finish processing of a declaration;
4927: install its line number and initial value.
4928: If the length of an array type is not known before,
4929: it must be determined now, from the initial value, or it is an error.
4930:
4931: Call `pop_obstacks' iff NEED_POP is nonzero.
4932:
4933: For C++, `finish_decl' must be fairly evasive: it must keep initializers
4934: for aggregates that have constructors alive on the permanent obstack,
4935: so that the global initializing functions can be written at the end.
4936:
4937: INIT0 holds the value of an initializer that should be allowed to escape
4938: the normal rules.
4939:
4940: For functions that take defualt parameters, DECL points to its
4941: "maximal" instantiation. finish_decl must then also declared its
4942: subsequently lower and lower forms of instantiation, checking for
4943: ambiguity as it goes. This can be sped up later. */
4944:
4945: void
4946: finish_decl (decl, init, asmspec_tree, need_pop)
4947: tree decl, init;
4948: tree asmspec_tree;
4949: int need_pop;
4950: {
4951: register tree type;
4952: tree cleanup = NULL_TREE, ttype;
4953: int was_incomplete;
4954: int temporary = allocation_temporary_p ();
4955: char *asmspec = 0;
4956: int was_readonly = 0;
4957:
4958: /* If this is 0, then we did not change obstacks. */
4959: if (! decl)
4960: {
4961: if (init)
4962: error ("assignment (not initialization) in declaration");
4963: return;
4964: }
4965:
4966: if (asmspec_tree)
4967: {
4968: asmspec = TREE_STRING_POINTER (asmspec_tree);
4969: /* Zero out old RTL, since we will rewrite it. */
4970: DECL_RTL (decl) = 0;
4971: }
4972:
4973: /* If the type of the thing we are declaring either has
4974: a constructor, or has a virtual function table pointer,
4975: AND its initialization was accepted by `start_decl',
4976: then we stayed on the permanent obstack through the
4977: declaration, otherwise, changed obstacks as GCC would. */
4978:
4979: type = TREE_TYPE (decl);
4980:
4981: was_incomplete = (DECL_SIZE (decl) == 0);
4982:
4983: /* Take care of TYPE_DECLs up front. */
4984: if (TREE_CODE (decl) == TYPE_DECL)
4985: {
4986: if (init && DECL_INITIAL (decl))
4987: {
4988: /* typedef foo = bar; store the type of bar as the type of foo. */
4989: TREE_TYPE (decl) = type = TREE_TYPE (init);
4990: DECL_INITIAL (decl) = init = 0;
4991: }
4992: if (IS_AGGR_TYPE (type))
4993: {
4994: if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
4995: warning ("shadowing previous type declaration of `%s'",
4996: IDENTIFIER_POINTER (DECL_NAME (decl)));
4997: set_identifier_type_value (DECL_NAME (decl), type);
4998: CLASSTYPE_GOT_SEMICOLON (type) = 1;
4999: }
5000: GNU_xref_decl (current_function_decl, decl);
5001: rest_of_decl_compilation (decl, 0,
5002: current_binding_level == global_binding_level, 0);
5003: goto finish_end;
5004: }
5005: if (IS_AGGR_TYPE (type) && CLASSTYPE_DECLARED_EXCEPTION (type))
5006: {
5007: finish_exception_decl (NULL_TREE, decl);
5008: CLASSTYPE_GOT_SEMICOLON (type) = 1;
5009: goto finish_end;
5010: }
5011: if (TREE_CODE (decl) != FUNCTION_DECL)
5012: {
5013: ttype = target_type (type);
5014: #if 0 /* WTF? -KR
5015: Leave this out until we can figure out why it was
5016: needed/desirable in the first place. Then put a comment
5017: here explaining why. Or just delete the code if no ill
5018: effects arise. */
5019: if (TYPE_NAME (ttype)
5020: && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
5021: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
5022: {
5023: tree old_id = TYPE_IDENTIFIER (ttype);
5024: char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
5025: /* Need to preserve template data for UPT nodes. */
5026: tree old_template = IDENTIFIER_TEMPLATE (old_id);
5027: newname[0] = '_';
5028: bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
5029: IDENTIFIER_LENGTH (old_id) + 1);
5030: old_id = get_identifier (newname);
5031: lookup_tag_reverse (ttype, old_id);
5032: TYPE_IDENTIFIER (ttype) = old_id;
5033: IDENTIFIER_TEMPLATE (old_id) = old_template;
5034: }
5035: #endif
5036: }
5037:
5038: if (! TREE_EXTERNAL (decl) && TREE_READONLY (decl)
5039: && TYPE_NEEDS_CONSTRUCTING (type))
5040: {
5041:
5042: /* Currently, GNU C++ puts constants in text space, making them
5043: impossible to initialize. In the future, one would hope for
5044: an operating system which understood the difference between
5045: initialization and the running of a program. */
5046: was_readonly = 1;
5047: TREE_READONLY (decl) = 0;
5048: }
5049:
5050: if (TREE_CODE (decl) == FIELD_DECL)
5051: {
5052: if (init && init != error_mark_node)
5053: assert (TREE_PERMANENT (init));
5054:
5055: if (asmspec)
5056: {
5057: /* This must override the asm specifier which was placed
5058: by grokclassfn. Lay this out fresh.
5059:
5060: @@ Should emit an error if this redefines an asm-specified
5061: @@ name, or if we have already used the function's name. */
5062: DECL_RTL (TREE_TYPE (decl)) = 0;
5063: DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5064: make_decl_rtl (decl, asmspec, 0);
5065: }
5066: }
5067: /* If `start_decl' didn't like having an initialization, ignore it now. */
5068: else if (init != 0 && DECL_INITIAL (decl) == 0)
5069: init = 0;
5070: else if (TREE_EXTERNAL (decl))
5071: ;
5072: else if (TREE_CODE (type) == REFERENCE_TYPE)
5073: {
5074: grok_reference_init (decl, type, init, &cleanup);
5075: init = 0;
5076: }
5077:
5078: GNU_xref_decl (current_function_decl, decl);
5079:
5080: if (TREE_CODE (decl) == FIELD_DECL || TREE_EXTERNAL (decl))
5081: ;
5082: else if (TREE_CODE (decl) == CONST_DECL)
5083: {
5084: assert (TREE_CODE (decl) != REFERENCE_TYPE);
5085:
5086: DECL_INITIAL (decl) = init;
5087:
5088: /* This will keep us from needing to worry about our obstacks. */
5089: assert (init != 0);
5090: init = 0;
5091: }
5092: else if (init)
5093: {
5094: if (TYPE_NEEDS_CONSTRUCTING (type))
5095: {
5096: if (TREE_CODE (type) == ARRAY_TYPE)
5097: init = digest_init (type, init, 0);
5098: else if (TREE_CODE (init) == CONSTRUCTOR
5099: && CONSTRUCTOR_ELTS (init) != NULL_TREE)
5100: {
5101: error_with_decl (decl, "`%s' must be initialized by constructor, not by `{...}'");
5102: init = error_mark_node;
5103: }
5104: #if 0
5105: /* fix this in `build_functional_cast' instead.
5106: Here's the trigger code:
5107:
5108: struct ostream
5109: {
5110: ostream ();
5111: ostream (int, char *);
5112: ostream (char *);
5113: operator char *();
5114: ostream (void *);
5115: operator void *();
5116: operator << (int);
5117: };
5118: int buf_size = 1024;
5119: static char buf[buf_size];
5120: const char *debug(int i) {
5121: char *b = &buf[0];
5122: ostream o = ostream(buf_size, b);
5123: o << i;
5124: return buf;
5125: }
5126: */
5127:
5128: else if (TREE_CODE (init) == TARGET_EXPR
5129: && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
5130: {
5131: /* User wrote something like `foo x = foo (args)' */
5132: assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL);
5133: assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE);
5134:
5135: /* User wrote exactly `foo x = foo (args)' */
5136: if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
5137: {
5138: init = build (CALL_EXPR, TREE_TYPE (init),
5139: TREE_OPERAND (TREE_OPERAND (init, 1), 0),
5140: TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
5141: TREE_SIDE_EFFECTS (init) = 1;
5142: }
5143: }
5144: #endif
5145:
5146: /* We must hide the initializer so that expand_decl
5147: won't try to do something it does not understand. */
5148: if (current_binding_level == global_binding_level)
5149: {
5150: tree value = digest_init (type, empty_init_node, 0);
5151: DECL_INITIAL (decl) = value;
5152: }
5153: else
5154: DECL_INITIAL (decl) = error_mark_node;
5155: }
5156: else
5157: {
5158: if (TREE_CODE (init) != TREE_VEC)
5159: init = store_init_value (decl, init);
5160:
5161: if (init)
5162: /* Don't let anyone try to initialize this variable
5163: until we are ready to do so. */
5164: DECL_INITIAL (decl) = error_mark_node;
5165: }
5166: }
5167: else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
5168: && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
5169: {
5170: tree ctype = type;
5171: while (TREE_CODE (ctype) == ARRAY_TYPE)
5172: ctype = TREE_TYPE (ctype);
5173: if (! TYPE_NEEDS_CONSTRUCTOR (ctype))
5174: {
5175: if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
5176: error_with_decl (decl, "structure `%s' with uninitialized const members");
5177: if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
5178: error_with_decl (decl, "structure `%s' with uninitialized reference members");
5179: }
5180:
5181: if (TREE_CODE (decl) == VAR_DECL
5182: && !TYPE_NEEDS_CONSTRUCTING (type)
5183: && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5184: error_with_decl (decl, "uninitialized const `%s'");
5185:
5186: /* Initialize variables in need of static initialization
5187: with `empty_init_node' to keep assemble_variable from putting them
5188: in the wrong program space. (Common storage is okay for non-public
5189: uninitialized data; the linker can't match it with storage from other
5190: files, and we may save some disk space.) */
5191: if (flag_pic == 0
5192: && TREE_STATIC (decl)
5193: && TREE_PUBLIC (decl)
5194: && TREE_CODE (decl) == VAR_DECL
5195: && TYPE_NEEDS_CONSTRUCTING (type)
5196: && (DECL_INITIAL (decl) == 0
5197: || DECL_INITIAL (decl) == error_mark_node))
5198: {
5199: tree value = digest_init (type, empty_init_node, 0);
5200: DECL_INITIAL (decl) = value;
5201: }
5202: }
5203: else if (TREE_CODE (decl) == VAR_DECL
5204: && TREE_CODE (type) != REFERENCE_TYPE
5205: && TREE_CODE_CLASS (TREE_CODE (type)) == 't'
5206: && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5207: {
5208: if (! TREE_STATIC (decl))
5209: error_with_decl (decl, "uninitialized const `%s'");
5210: }
5211:
5212: /* For top-level declaration, the initial value was read in
5213: the temporary obstack. MAXINDEX, rtl, etc. to be made below
5214: must go in the permanent obstack; but don't discard the
5215: temporary data yet. */
5216:
5217: if (current_binding_level == global_binding_level && temporary)
5218: end_temporary_allocation ();
5219:
5220: /* Deduce size of array from initialization, if not already known. */
5221:
5222: if (TREE_CODE (type) == ARRAY_TYPE
5223: && TYPE_DOMAIN (type) == 0
5224: && TREE_CODE (decl) != TYPE_DECL)
5225: {
5226: int do_default
5227: = (TREE_STATIC (decl)
5228: /* Even if pedantic, an external linkage array
5229: may have incomplete type at first. */
5230: ? pedantic && !TREE_PUBLIC (decl)
5231: : !TREE_EXTERNAL (decl));
5232: tree initializer = init ? init : DECL_INITIAL (decl);
5233: int failure = complete_array_type (type, initializer, do_default);
5234:
5235: if (failure == 1)
5236: error_with_decl (decl, "initializer fails to determine size of `%s'");
5237:
5238: if (failure == 2)
5239: {
5240: if (do_default)
5241: error_with_decl (decl, "array size missing in `%s'");
5242: else if (!pedantic && TREE_STATIC (decl))
5243: TREE_EXTERNAL (decl) = 1;
5244: }
5245:
5246: if (pedantic && TYPE_DOMAIN (type) != 0
5247: && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
5248: integer_zero_node))
5249: error_with_decl (decl, "zero-size array `%s'");
5250:
5251: layout_decl (decl, 0);
5252: }
5253:
5254: if (TREE_CODE (decl) == VAR_DECL)
5255: {
5256: if (TREE_STATIC (decl) && DECL_SIZE (decl) == 0)
5257: {
5258: /* A static variable with an incomplete type:
5259: that is an error if it is initialized or `static'.
5260: Otherwise, let it through, but if it is not `extern'
5261: then it may cause an error message later. */
5262: if (! (TREE_PUBLIC (decl) && DECL_INITIAL (decl) == 0))
5263: error_with_decl (decl, "storage size of `%s' isn't known");
5264: init = 0;
5265: }
5266: else if (!TREE_EXTERNAL (decl) && DECL_SIZE (decl) == 0)
5267: {
5268: /* An automatic variable with an incomplete type:
5269: that is an error. */
5270: error_with_decl (decl, "storage size of `%s' isn't known");
5271: TREE_TYPE (decl) = error_mark_node;
5272: }
5273: else if (!TREE_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
5274: /* Let debugger know it should output info for this type. */
5275: note_debug_info_needed (ttype);
5276:
5277: if ((TREE_EXTERNAL (decl) || TREE_STATIC (decl))
5278: && DECL_SIZE (decl) != 0 && ! TREE_CONSTANT (DECL_SIZE (decl)))
5279: error_with_decl (decl, "storage size of `%s' isn't constant");
5280:
5281: if (!TREE_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
5282: {
5283: int yes = suspend_momentary ();
5284:
5285: /* If INIT comes from a functional cast, use the cleanup
5286: we built for that. Otherwise, make our own cleanup. */
5287: if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
5288: && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
5289: {
5290: cleanup = TREE_OPERAND (init, 2);
5291: init = TREE_OPERAND (init, 0);
5292: current_binding_level->have_cleanups = 1;
5293: current_binding_level->more_exceptions_ok = 0;
5294: }
5295: else
5296: cleanup = maybe_build_cleanup (decl);
5297: resume_momentary (yes);
5298: }
5299: }
5300: /* PARM_DECLs get cleanups, too. */
5301: else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
5302: {
5303: if (temporary)
5304: end_temporary_allocation ();
5305: cleanup = maybe_build_cleanup (decl);
5306: if (temporary)
5307: resume_temporary_allocation ();
5308: }
5309:
5310: /* Output the assembler code and/or RTL code for variables and functions,
5311: unless the type is an undefined structure or union.
5312: If not, it will get done when the type is completed. */
5313:
5314: if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
5315: || TREE_CODE (decl) == RESULT_DECL)
5316: {
5317: int toplev = current_binding_level == global_binding_level;
5318: int was_temp
5319: = ((flag_traditional
5320: || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
5321: && allocation_temporary_p ());
5322:
5323: if (was_temp)
5324: end_temporary_allocation ();
5325:
5326: /* If we are in need of a cleanup, get out of any implicit
5327: handlers that have been established so far. */
5328: if (cleanup && current_binding_level->parm_flag == 3)
5329: {
5330: pop_implicit_try_blocks (decl);
5331: current_binding_level->more_exceptions_ok = 0;
5332: }
5333:
5334: if (TREE_CODE (decl) == VAR_DECL
5335: && current_binding_level != global_binding_level
5336: && ! TREE_STATIC (decl)
5337: && type_needs_gc_entry (type))
5338: DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
5339:
5340: if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
5341: make_decl_rtl (decl, 0, toplev);
5342: else if (TREE_CODE (decl) == VAR_DECL
5343: && TREE_READONLY (decl)
5344: && DECL_INITIAL (decl) != 0
5345: && DECL_INITIAL (decl) != error_mark_node
5346: && DECL_INITIAL (decl) != empty_init_node)
5347: {
5348: DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5349:
5350: if (asmspec)
5351: DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5352:
5353: if (! toplev
5354: && TREE_STATIC (decl)
5355: && ! TREE_SIDE_EFFECTS (decl)
5356: && ! TREE_PUBLIC (decl)
5357: && ! TREE_EXTERNAL (decl)
5358: && ! TYPE_NEEDS_DESTRUCTOR (type)
5359: && DECL_MODE (decl) != BLKmode)
5360: {
5361: /* If this variable is really a constant, then fill its DECL_RTL
5362: slot with something which won't take up storage.
5363: If something later should take its address, we can always give
5364: it legitimate RTL at that time. */
5365: DECL_RTL (decl) = (struct rtx_def *)gen_reg_rtx (DECL_MODE (decl));
5366: store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
5367: TREE_ASM_WRITTEN (decl) = 1;
5368: }
5369: else if (toplev)
5370: {
5371: /* Keep GCC from complaining that this variable
5372: is defined but never used. */
5373: DECL_FROM_INLINE (decl) = 1;
5374: /* If this is a static const, change its apparent linkage
5375: if it belongs to a #pragma interface. */
5376: if (TREE_STATIC (decl) && interface_unknown == 0)
5377: {
5378: if (interface_only)
5379: {
5380: TREE_STATIC (decl) = 0;
5381: TREE_EXTERNAL (decl) = 1;
5382: }
5383: else
5384: {
5385: TREE_PUBLIC (decl) = 1;
5386: /* Marking it used will cause it to be written. */
5387: TREE_USED (decl) = 1;
5388: }
5389: }
5390: make_decl_rtl (decl, asmspec, toplev);
5391: }
5392: else
5393: rest_of_decl_compilation (decl, asmspec, toplev, 0);
5394: }
5395: else if (TREE_CODE (decl) == VAR_DECL
5396: && DECL_LANG_SPECIFIC (decl)
5397: && DECL_IN_AGGR_P (decl))
5398: {
5399: if (TREE_STATIC (decl))
5400: if (init == 0
5401: #ifdef DEFAULT_STATIC_DEFS
5402: /* If this code is dead, then users must
5403: explicitly declare static member variables
5404: outside the class def'n as well. */
5405: && TYPE_NEEDS_CONSTRUCTING (type)
5406: #endif
5407: )
5408: {
5409: TREE_EXTERNAL (decl) = 1;
5410: make_decl_rtl (decl, asmspec, 1);
5411: }
5412: else
5413: rest_of_decl_compilation (decl, asmspec, toplev, 0);
5414: else
5415: /* Just a constant field. Should not need any rtl. */
5416: goto finish_end0;
5417: }
5418: else
5419: rest_of_decl_compilation (decl, asmspec, toplev, 0);
5420:
5421: if (was_temp)
5422: resume_temporary_allocation ();
5423:
5424: if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_ABSTRACT_VIRTUALS (type))
5425: abstract_virtuals_error (decl, type);
5426: else if (TREE_CODE (type) == FUNCTION_TYPE
5427: && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
5428: && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
5429: abstract_virtuals_error (decl, TREE_TYPE (type));
5430:
5431: if (TREE_CODE (decl) == FUNCTION_DECL)
5432: {
5433: /* C++: Handle overloaded functions with default parameters. */
5434: if (DECL_OVERLOADED (decl))
5435: {
5436: tree parmtypes = TYPE_ARG_TYPES (type);
5437: tree prev = NULL_TREE;
5438: char *original_name = IDENTIFIER_POINTER (DECL_NAME (decl));
5439: struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
5440: /* All variants will share an uncollectable lang_decl. */
5441: copy_decl_lang_specific (decl);
5442:
5443: while (parmtypes && parmtypes != void_list_node)
5444: {
5445: if (TREE_PURPOSE (parmtypes))
5446: {
5447: tree fnname, fndecl;
5448: tree *argp = prev
5449: ? & TREE_CHAIN (prev)
5450: : & TYPE_ARG_TYPES (type);
5451:
5452: *argp = NULL_TREE;
5453: fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0);
5454: *argp = parmtypes;
5455: fndecl = build_decl (FUNCTION_DECL, fnname, type);
5456: TREE_EXTERNAL (fndecl) = TREE_EXTERNAL (decl);
5457: TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
5458: TREE_INLINE (fndecl) = TREE_INLINE (decl);
5459: /* Keep G++ from thinking this function is unused.
5460: It is only used to speed up search in name space. */
5461: TREE_USED (fndecl) = 1;
5462: TREE_ASM_WRITTEN (fndecl) = 1;
5463: DECL_INITIAL (fndecl) = NULL_TREE;
5464: DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
5465: fndecl = pushdecl (fndecl);
5466: DECL_INITIAL (fndecl) = error_mark_node;
5467: DECL_RTL (fndecl) = DECL_RTL (decl);
5468: }
5469: prev = parmtypes;
5470: parmtypes = TREE_CHAIN (parmtypes);
5471: }
5472: DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
5473: }
5474: }
5475: else if (TREE_EXTERNAL (decl))
5476: ;
5477: else if (TREE_STATIC (decl) && type != error_mark_node)
5478: {
5479: /* Cleanups for static variables are handled by `finish_file'. */
5480: if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
5481: expand_static_init (decl, init);
5482:
5483: /* Make entry in appropriate vector. */
5484: if (flag_gc && type_needs_gc_entry (type))
5485: build_static_gc_entry (decl, type);
5486: }
5487: else if (current_binding_level != global_binding_level)
5488: {
5489: /* This is a declared decl which must live until the
5490: end of the binding contour. It may need a cleanup. */
5491:
5492: /* Recompute the RTL of a local array now
5493: if it used to be an incomplete type. */
5494: if (was_incomplete && ! TREE_STATIC (decl))
5495: {
5496: /* If we used it already as memory, it must stay in memory. */
5497: TREE_ADDRESSABLE (decl) = TREE_USED (decl);
5498: /* If it's still incomplete now, no init will save it. */
5499: if (DECL_SIZE (decl) == 0)
5500: DECL_INITIAL (decl) = 0;
5501: expand_decl (decl);
5502: }
5503: else if (! TREE_ASM_WRITTEN (decl)
5504: && (TYPE_SIZE (type) != 0 || TREE_CODE (type) == ARRAY_TYPE))
5505: {
5506: /* Do this here, because we did not expand this decl's
5507: rtl in start_decl. */
5508: if (DECL_RTL (decl) == 0)
5509: expand_decl (decl);
5510: else if (cleanup)
5511: {
5512: expand_decl_cleanup (NULL_TREE, cleanup);
5513: /* Cleanup used up here. */
5514: cleanup = 0;
5515: }
5516: }
5517:
5518: if (DECL_SIZE (decl) && type != error_mark_node)
5519: {
5520: /* Compute and store the initial value. */
5521: expand_decl_init (decl);
5522:
5523: if (init || TYPE_NEEDS_CONSTRUCTING (type))
5524: {
5525: emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
5526: expand_aggr_init (decl, init, 0);
5527: }
5528:
5529: /* Set this to 0 so we can tell whether an aggregate
5530: which was initialized was ever used. */
5531: if (TYPE_NEEDS_CONSTRUCTING (type))
5532: TREE_USED (decl) = 0;
5533:
5534: /* Store the cleanup, if there was one. */
5535: if (cleanup)
5536: {
5537: if (! expand_decl_cleanup (decl, cleanup))
5538: error_with_decl (decl, "parser lost in parsing declaration of `%s'");
5539: }
5540: }
5541: }
5542: finish_end0:
5543:
5544: /* Undo call to `pushclass' that was done in `start_decl'
5545: due to initialization of qualified member variable.
5546: I.e., Foo::x = 10; */
5547: {
5548: tree context = DECL_CONTEXT (decl);
5549: if (context
5550: && (TREE_CODE (decl) == VAR_DECL
5551: /* We also have a pushclass done that we need to undo here
5552: if we're at top level and declare a method. */
5553: || (TREE_CODE (decl) == FUNCTION_DECL
5554: /* If size hasn't been set, we're still defining it,
5555: and therefore inside the class body; don't pop
5556: the binding level.. */
5557: && TYPE_SIZE (context) != 0
5558: /* The binding level gets popped elsewhere for a
5559: friend declaration inside another class. */
5560: && DECL_NAME (TYPE_NAME (context)) == current_class_name
5561: )))
5562: popclass (1);
5563: }
5564: }
5565:
5566: finish_end:
5567:
5568: if (need_pop)
5569: {
5570: /* Resume permanent allocation, if not within a function. */
5571: /* The corresponding push_obstacks_nochange is in start_decl,
5572: start_method, groktypename, and in grokfield. */
5573: pop_obstacks ();
5574: }
5575:
5576: if (was_readonly)
5577: TREE_READONLY (decl) = 1;
5578:
5579: if (flag_cadillac)
5580: cadillac_finish_decl (decl);
5581: }
5582:
5583: static void
5584: expand_static_init (decl, init)
5585: tree decl;
5586: tree init;
5587: {
5588: tree oldstatic = value_member (decl, static_aggregates);
5589: if (oldstatic)
5590: {
5591: if (TREE_PURPOSE (oldstatic))
5592: error_with_decl (decl, "multiple initializations given for `%s'");
5593: }
5594: else if (current_binding_level != global_binding_level)
5595: {
5596: /* Emit code to perform this initialization but once. */
5597: tree temp;
5598:
5599: /* Remember this information until end of file. */
5600: push_obstacks (&permanent_obstack, &permanent_obstack);
5601:
5602: /* Emit code to perform this initialization but once. */
5603: temp = get_temp_name (integer_type_node, 1);
5604: rest_of_decl_compilation (temp, NULL_TREE, 0, 0);
5605: expand_start_cond (build_binary_op (EQ_EXPR, temp,
5606: integer_zero_node), 0);
5607: expand_assignment (temp, integer_one_node, 0, 0);
5608: if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
5609: {
5610: expand_aggr_init (decl, init, 0);
5611: do_pending_stack_adjust ();
5612: }
5613: else
5614: expand_assignment (decl, init, 0, 0);
5615: expand_end_cond ();
5616: if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
5617: {
5618: static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
5619: TREE_STATIC (static_aggregates) = 1;
5620: }
5621:
5622: /* Resume old (possibly temporary) allocation. */
5623: pop_obstacks ();
5624: }
5625: else
5626: {
5627: /* This code takes into account memory allocation
5628: policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
5629: does not hold for this object, then we must make permanent
5630: the storage currently in the temporary obstack. */
5631: if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
5632: preserve_initializer ();
5633: static_aggregates = perm_tree_cons (init, decl, static_aggregates);
5634: }
5635: }
5636:
5637: /* Make TYPE a complete type based on INITIAL_VALUE.
5638: Return 0 if successful, 1 if INITIAL_VALUE can't be decyphered,
5639: 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
5640:
5641: int
5642: complete_array_type (type, initial_value, do_default)
5643: tree type;
5644: tree initial_value;
5645: int do_default;
5646: {
5647: register tree maxindex = NULL_TREE;
5648: int value = 0;
5649:
5650: if (initial_value)
5651: {
5652: /* Note MAXINDEX is really the maximum index,
5653: one less than the size. */
5654: if (TREE_CODE (initial_value) == STRING_CST)
5655: maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
5656: else if (TREE_CODE (initial_value) == CONSTRUCTOR)
5657: {
5658: register int nelts
5659: = list_length (CONSTRUCTOR_ELTS (initial_value));
5660: maxindex = build_int_2 (nelts - 1, 0);
5661: }
5662: else
5663: {
5664: /* Make an error message unless that happened already. */
5665: if (initial_value != error_mark_node)
5666: value = 1;
5667:
5668: /* Prevent further error messages. */
5669: maxindex = build_int_2 (1, 0);
5670: }
5671: }
5672:
5673: if (!maxindex)
5674: {
5675: if (do_default)
5676: maxindex = build_int_2 (1, 0);
5677: value = 2;
5678: }
5679:
5680: if (maxindex)
5681: {
5682: TYPE_DOMAIN (type) = build_index_type (maxindex);
5683: if (!TREE_TYPE (maxindex))
5684: TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
5685: }
5686:
5687: /* Lay out the type now that we can get the real answer. */
5688:
5689: layout_type (type);
5690:
5691: return value;
5692: }
5693:
5694: /* Return zero if something is declared to be a member of type
5695: CTYPE when in the context of CUR_TYPE. STRING is the error
5696: message to print in that case. Otherwise, quietly return 1. */
5697: static int
5698: member_function_or_else (ctype, cur_type, string)
5699: tree ctype, cur_type;
5700: char *string;
5701: {
5702: if (ctype && ctype != cur_type)
5703: {
5704: error (string, TYPE_NAME_STRING (ctype));
5705: return 0;
5706: }
5707: return 1;
5708: }
5709:
5710: /* Subroutine of `grokdeclarator'. */
5711:
5712: /* CTYPE is class type, or null if non-class.
5713: TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
5714: or METHOD_TYPE.
5715: DECLARATOR is the function's name.
5716: VIRTUALP is truthvalue of whether the function is virtual or not.
5717: FLAGS are to be passed through to `grokclassfn'.
5718: QUALS are qualifiers indicating whether the function is `const'
5719: or `volatile'.
5720: RAISES is a list of exceptions that this function can raise.
5721: CHECK is 1 if we must find this method in CTYPE, 0 if we should
5722: not look, and -1 if we should not call `grokclassfn' at all. */
5723: static tree
5724: grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check)
5725: tree ctype, type;
5726: tree declarator;
5727: int virtualp;
5728: enum overload_flags flags;
5729: tree quals, raises;
5730: int check;
5731: {
5732: tree cname, decl;
5733: int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
5734:
5735: if (ctype)
5736: cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
5737: ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
5738: else
5739: cname = NULL_TREE;
5740:
5741: if (raises)
5742: {
5743: type = build_exception_variant (ctype, type, raises);
5744: raises = TYPE_RAISES_EXCEPTIONS (type);
5745: }
5746: decl = build_lang_decl (FUNCTION_DECL, declarator, type);
5747: if (staticp)
5748: {
5749: DECL_STATIC_FUNCTION_P (decl) = 1;
5750: DECL_CONTEXT (decl) = ctype;
5751: DECL_CLASS_CONTEXT (decl) = ctype;
5752: }
5753: TREE_EXTERNAL (decl) = 1;
5754: if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
5755: {
5756: error ("functions cannot have method qualifiers");
5757: quals = NULL_TREE;
5758: }
5759:
5760: /* Caller will do the rest of this. */
5761: if (check < 0)
5762: return decl;
5763:
5764: if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
5765: {
5766: tree tmp;
5767: /* Just handle constructors here. We could do this
5768: inside the following if stmt, but I think
5769: that the code is more legible by breaking this
5770: case out. See comments below for what each of
5771: the following calls is supposed to do. */
5772: DECL_CONSTRUCTOR_P (decl) = 1;
5773:
5774: grokclassfn (ctype, declarator, decl, flags, quals);
5775: if (check)
5776: check_classfn (ctype, declarator, decl, flags);
5777: grok_ctor_properties (ctype, decl);
5778: if (check == 0)
5779: {
5780: /* FIXME: this should only need to look at IDENTIFIER_GLOBAL_VALUE. */
5781: tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
5782: if (tmp == 0)
5783: IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
5784: else if (TREE_CODE (tmp) != TREE_CODE (decl))
5785: error_with_decl (decl, "inconsistant declarations for `%s'");
5786: else
5787: {
5788: duplicate_decls (decl, tmp);
5789: decl = tmp;
5790: }
5791: make_decl_rtl (decl, NULL_TREE, 1);
5792: }
5793: }
5794: else
5795: {
5796: tree tmp;
5797:
5798: /* Function gets the ugly name, field gets the nice one.
5799: This call may change the type of the function (because
5800: of default parameters)!
5801:
5802: Wrappers get field names which will not conflict
5803: with constructors and destructors. */
5804: if (ctype != NULL_TREE)
5805: grokclassfn (ctype, cname, decl, flags, quals);
5806:
5807: if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
5808: grok_op_properties (decl);
5809:
5810: if (ctype != NULL_TREE && check)
5811: check_classfn (ctype, cname, decl, flags);
5812:
5813: if (ctype == NULL_TREE || check)
5814: return decl;
5815:
5816: /* Now install the declaration of this function so that
5817: others may find it (esp. its DECL_FRIENDLIST).
5818: Pretend we are at top level, we will get true
5819: reference later, perhaps.
5820:
5821: FIXME: This should only need to look at IDENTIFIER_GLOBAL_VALUE. */
5822: tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
5823: if (tmp == 0)
5824: IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
5825: else if (TREE_CODE (tmp) != TREE_CODE (decl))
5826: error_with_decl (decl, "inconsistant declarations for `%s'");
5827: else
5828: {
5829: duplicate_decls (decl, tmp);
5830: decl = tmp;
5831: }
5832: make_decl_rtl (decl, NULL_TREE, 1);
5833:
5834: /* If this declaration supersedes the declaration of
5835: a method declared virtual in the base class, then
5836: mark this field as being virtual as well. */
5837: {
5838: tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
5839: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
5840:
5841: for (i = 0; i < n_baselinks; i++)
5842: {
5843: tree child = TREE_VEC_ELT (binfos, i);
5844: if (TYPE_VIRTUAL_P (BINFO_TYPE (child)) || flag_all_virtual == 1)
5845: {
5846: tmp = get_first_matching_virtual (child, decl,
5847: flags == DTOR_FLAG);
5848: if (tmp)
5849: {
5850: /* The TMP we really want is the one from the deepest
5851: baseclass on this path, taking care not to
5852: duplicate if we have already found it (via another
5853: path to its virtual baseclass. */
5854: if (staticp)
5855: {
5856: error_with_decl (decl, "method `%s' may not be declared static");
5857: error_with_decl (tmp, "(since `%s' declared virtual in base class.)");
5858: break;
5859: }
5860: virtualp = 1;
5861:
5862: if ((TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (child))
5863: || TYPE_USES_MULTIPLE_INHERITANCE (ctype))
5864: && BINFO_TYPE (child) != DECL_CONTEXT (tmp))
5865: tmp = get_first_matching_virtual (TYPE_BINFO (DECL_CONTEXT (tmp)),
5866: decl, flags == DTOR_FLAG);
5867: if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE)
5868: {
5869: /* The argument types may have changed... */
5870: tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
5871: tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
5872:
5873: argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
5874: TREE_CHAIN (argtypes));
5875: /* But the return type has not. */
5876: type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
5877: if (raises)
5878: {
5879: type = build_exception_variant (ctype, type, raises);
5880: raises = TYPE_RAISES_EXCEPTIONS (type);
5881: }
5882: TREE_TYPE (decl) = type;
5883: DECL_VINDEX (decl)
5884: = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
5885: }
5886: }
5887: }
5888: }
5889: }
5890: if (virtualp)
5891: {
5892: if (DECL_VINDEX (decl) == NULL_TREE)
5893: DECL_VINDEX (decl) = error_mark_node;
5894: IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
5895: if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
5896: && (write_virtuals == 2
5897: || (write_virtuals == 3
5898: && ! CLASSTYPE_INTERFACE_UNKNOWN (ctype))))
5899: TREE_PUBLIC (decl) = 1;
5900: }
5901: }
5902: return decl;
5903: }
5904:
5905: static tree
5906: grokvardecl (ctype, type, declarator, specbits, initialized)
5907: tree ctype, type;
5908: tree declarator;
5909: int specbits;
5910: {
5911: tree decl;
5912:
5913: if (TREE_CODE (type) == OFFSET_TYPE)
5914: {
5915: /* If you declare a static member so that it
5916: can be initialized, the code will reach here. */
5917: tree field = lookup_field (TYPE_OFFSET_BASETYPE (type),
5918: declarator, 0);
5919: if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
5920: {
5921: tree basetype = TYPE_OFFSET_BASETYPE (type);
5922: error ("`%s' is not a static member of class `%s'",
5923: IDENTIFIER_POINTER (declarator),
5924: TYPE_NAME_STRING (basetype));
5925: type = TREE_TYPE (type);
5926: decl = build_lang_field_decl (VAR_DECL, declarator, type);
5927: DECL_CONTEXT (decl) = basetype;
5928: DECL_CLASS_CONTEXT (decl) = basetype;
5929: }
5930: else
5931: {
5932: tree f_type = TREE_TYPE (field);
5933: tree o_type = TREE_TYPE (type);
5934:
5935: if (TYPE_SIZE (f_type) == NULL_TREE)
5936: {
5937: if (TREE_CODE (f_type) != TREE_CODE (o_type)
5938: || (TREE_CODE (f_type) == ARRAY_TYPE
5939: && TREE_TYPE (f_type) != TREE_TYPE (o_type)))
5940: error ("redeclaration of type for `%s'",
5941: IDENTIFIER_POINTER (declarator));
5942: }
5943: else if (f_type != o_type)
5944: error ("redeclaration of type for `%s'",
5945: IDENTIFIER_POINTER (declarator));
5946: decl = field;
5947: if (initialized && DECL_INITIAL (decl)
5948: /* Complain about multiply-initialized
5949: member variables, but don't be faked
5950: out if initializer is faked up from `empty_init_node'. */
5951: && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
5952: || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE))
5953: error_with_aggr_type (DECL_CONTEXT (decl),
5954: "multiple initializations of static member `%s::%s'",
5955: IDENTIFIER_POINTER (DECL_NAME (decl)));
5956: }
5957: }
5958: else decl = build_decl (VAR_DECL, declarator, type);
5959:
5960: if (specbits & (1 << (int) RID_EXTERN))
5961: {
5962: DECL_EXTERNAL (decl) = 1;
5963: TREE_EXTERNAL (decl) = !initialized;
5964: }
5965:
5966: /* In class context, static means one per class,
5967: public visibility, and static storage. */
5968: if (DECL_FIELD_CONTEXT (decl) != 0
5969: && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
5970: {
5971: TREE_PUBLIC (decl) = 1;
5972: TREE_STATIC (decl) = 1;
5973: TREE_EXTERNAL (decl) = !initialized;
5974: }
5975: /* At top level, either `static' or no s.c. makes a definition
5976: (perhaps tentative), and absence of `static' makes it public. */
5977: else if (current_binding_level == global_binding_level)
5978: {
5979: TREE_PUBLIC (decl) = !(specbits & (1 << (int) RID_STATIC));
5980: TREE_STATIC (decl) = ! TREE_EXTERNAL (decl);
5981: }
5982: /* Not at top level, only `static' makes a static definition. */
5983: else
5984: {
5985: TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
5986: TREE_PUBLIC (decl) = TREE_EXTERNAL (decl);
5987: }
5988: return decl;
5989: }
5990:
5991: /* Given declspecs and a declarator,
5992: determine the name and type of the object declared
5993: and construct a ..._DECL node for it.
5994: (In one case we can return a ..._TYPE node instead.
5995: For invalid input we sometimes return 0.)
5996:
5997: DECLSPECS is a chain of tree_list nodes whose value fields
5998: are the storage classes and type specifiers.
5999:
6000: DECL_CONTEXT says which syntactic context this declaration is in:
6001: NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
6002: FUNCDEF for a function definition. Like NORMAL but a few different
6003: error messages in each case. Return value may be zero meaning
6004: this definition is too screwy to try to parse.
6005: MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
6006: handle member functions (which have FIELD context).
6007: Return value may be zero meaning this definition is too screwy to
6008: try to parse.
6009: PARM for a parameter declaration (either within a function prototype
6010: or before a function body). Make a PARM_DECL, or return void_type_node.
6011: TYPENAME if for a typename (in a cast or sizeof).
6012: Don't make a DECL node; just return the ..._TYPE node.
6013: FIELD for a struct or union field; make a FIELD_DECL.
6014: BITFIELD for a field with specified width.
6015: INITIALIZED is 1 if the decl has an initializer.
6016:
6017: In the TYPENAME case, DECLARATOR is really an absolute declarator.
6018: It may also be so in the PARM case, for a prototype where the
6019: argument type is specified but not the name.
6020:
6021: This function is where the complicated C meanings of `static'
6022: and `extern' are intrepreted.
6023:
6024: For C++, if there is any monkey business to do, the function which
6025: calls this one must do it, i.e., prepending instance variables,
6026: renaming overloaded function names, etc.
6027:
6028: Note that for this C++, it is an error to define a method within a class
6029: which does not belong to that class.
6030:
6031: Execpt in the case where SCOPE_REFs are implicitly known (such as
6032: methods within a class being redundantly qualified),
6033: declarations which involve SCOPE_REFs are returned as SCOPE_REFs
6034: (class_name::decl_name). The caller must also deal with this.
6035:
6036: If a constructor or destructor is seen, and the context is FIELD,
6037: then the type gains the attribtue TREE_HAS_x. If such a declaration
6038: is erroneous, NULL_TREE is returned.
6039:
6040: QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
6041: function, these are the qualifiers to give to the `this' pointer.
6042:
6043: May return void_type_node if the declarator turned out to be a friend.
6044: See grokfield for details. */
6045:
6046: enum return_types { return_normal, return_ctor, return_dtor, return_conversion, };
6047:
6048: tree
6049: grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
6050: tree declspecs;
6051: tree declarator;
6052: enum decl_context decl_context;
6053: int initialized;
6054: tree raises;
6055: {
6056: extern int current_class_depth;
6057:
6058: int specbits = 0;
6059: int nclasses = 0;
6060: tree spec;
6061: tree type = NULL_TREE;
6062: int longlong = 0;
6063: int constp;
6064: int volatilep;
6065: int virtualp, friendp, inlinep, staticp;
6066: int explicit_int = 0;
6067: int explicit_char = 0;
6068: tree typedef_decl = 0;
6069: char *name;
6070: tree typedef_type = 0;
6071: int funcdef_flag = 0;
6072: enum tree_code innermost_code = ERROR_MARK;
6073: int bitfield = 0;
6074: int variable_size = 0;
6075: /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
6076: All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
6077: tree init = 0;
6078:
6079: /* Keep track of what sort of function is being processed
6080: so that we can warn about default return values, or explicit
6081: return values which do not match prescribed defaults. */
6082: enum return_types return_type = return_normal;
6083:
6084: tree dname = NULL_TREE;
6085: tree ctype = current_class_type;
6086: tree ctor_return_type = NULL_TREE;
6087: enum overload_flags flags = NO_SPECIAL;
6088: int seen_scope_ref = 0;
6089: tree quals = 0;
6090:
6091: if (decl_context == FUNCDEF)
6092: funcdef_flag = 1, decl_context = NORMAL;
6093: else if (decl_context == MEMFUNCDEF)
6094: funcdef_flag = -1, decl_context = FIELD;
6095: else if (decl_context == BITFIELD)
6096: bitfield = 1, decl_context = FIELD;
6097:
6098: if (flag_traditional && allocation_temporary_p ())
6099: end_temporary_allocation ();
6100:
6101: /* Look inside a declarator for the name being declared
6102: and get it as a string, for an error message. */
6103: {
6104: tree type, last = 0;
6105: register tree decl = declarator;
6106: name = 0;
6107:
6108: /* If we see something of the form `aggr_type xyzzy (a, b, c)'
6109: it is either an old-style function declaration or a call to
6110: a constructor. The following conditional makes recognizes this
6111: case as being a call to a constructor. Too bad if it is not. */
6112:
6113: /* For Doug Lea, also grok `aggr_type xyzzy (a, b, c)[10][10][10]'. */
6114: while (decl && TREE_CODE (decl) == ARRAY_REF)
6115: {
6116: last = decl;
6117: decl = TREE_OPERAND (decl, 0);
6118: }
6119:
6120: if (decl && declspecs
6121: && TREE_CODE (decl) == CALL_EXPR
6122: && TREE_OPERAND (decl, 0)
6123: && (TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
6124: || TREE_CODE (TREE_OPERAND (decl, 0)) == SCOPE_REF))
6125: {
6126: type = TREE_CODE (TREE_VALUE (declspecs)) == IDENTIFIER_NODE
6127: ? lookup_name (TREE_VALUE (declspecs), 1) :
6128: (IS_AGGR_TYPE (TREE_VALUE (declspecs))
6129: ? TYPE_NAME (TREE_VALUE (declspecs)) : NULL_TREE);
6130:
6131: if (type && TREE_CODE (type) == TYPE_DECL
6132: && IS_AGGR_TYPE (TREE_TYPE (type))
6133: && parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
6134: {
6135: if (decl_context == FIELD
6136: && TREE_CHAIN (TREE_OPERAND (decl, 1)))
6137: {
6138: /* That was an initializer list. */
6139: sorry ("initializer lists for field declarations");
6140: decl = TREE_OPERAND (decl, 0);
6141: if (last)
6142: {
6143: TREE_OPERAND (last, 0) = decl;
6144: decl = declarator;
6145: }
6146: declarator = decl;
6147: init = error_mark_node;
6148: goto bot;
6149: }
6150: else
6151: {
6152: init = TREE_OPERAND (decl, 1);
6153: if (last)
6154: {
6155: TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
6156: if (pedantic && init)
6157: error ("arrays cannot take initializers");
6158: }
6159: else
6160: declarator = TREE_OPERAND (declarator, 0);
6161: decl = start_decl (declarator, declspecs, 1, NULL_TREE);
6162: finish_decl (decl, init, NULL_TREE, 1);
6163: return 0;
6164: }
6165: }
6166:
6167: if (parmlist_is_random (TREE_OPERAND (decl, 1)))
6168: {
6169: decl = TREE_OPERAND (decl, 0);
6170: if (TREE_CODE (decl) == SCOPE_REF)
6171: {
6172: if (TREE_COMPLEXITY (decl))
6173: abort ();
6174: decl = TREE_OPERAND (decl, 1);
6175: }
6176: if (TREE_CODE (decl) == IDENTIFIER_NODE)
6177: name = IDENTIFIER_POINTER (decl);
6178: if (name)
6179: error ("bad parameter list specification for function `%s'",
6180: name);
6181: else
6182: error ("bad parameter list specification for function");
6183: return 0;
6184: }
6185: bot:
6186: ;
6187: }
6188: else
6189: /* It didn't look like we thought it would, leave the ARRAY_REFs on. */
6190: decl = declarator;
6191:
6192: while (decl)
6193: switch (TREE_CODE (decl))
6194: {
6195: case WRAPPER_EXPR: /* for C++ wrappers. */
6196: ctype = NULL_TREE;
6197: assert (flags == NO_SPECIAL);
6198: flags = WRAPPER_FLAG;
6199: decl = TREE_OPERAND (decl, 0);
6200: break;
6201:
6202: case ANTI_WRAPPER_EXPR: /* for C++ wrappers. */
6203: ctype = NULL_TREE;
6204: assert (flags == NO_SPECIAL);
6205: flags = ANTI_WRAPPER_FLAG;
6206: decl = TREE_OPERAND (decl, 0);
6207: break;
6208:
6209: case COND_EXPR:
6210: ctype = NULL_TREE;
6211: assert (flags == WRAPPER_FLAG);
6212: flags = WRAPPER_PRED_FLAG;
6213: decl = TREE_OPERAND (decl, 0);
6214: break;
6215:
6216: case BIT_NOT_EXPR: /* for C++ destructors! */
6217: {
6218: tree name = TREE_OPERAND (decl, 0);
6219: tree rename = NULL_TREE;
6220:
6221: assert (flags == NO_SPECIAL);
6222: flags = DTOR_FLAG;
6223: return_type = return_dtor;
6224: assert (TREE_CODE (name) == IDENTIFIER_NODE);
6225: if (ctype == NULL_TREE)
6226: {
6227: if (current_class_type == NULL_TREE)
6228: {
6229: error ("destructors must be member functions");
6230: flags = NO_SPECIAL;
6231: }
6232: else
6233: {
6234: tree t = constructor_name (current_class_name);
6235: if (t != name)
6236: rename = t;
6237: }
6238: }
6239: else
6240: {
6241: tree t = constructor_name (ctype);
6242: if (t != name)
6243: rename = t;
6244: }
6245:
6246: if (rename)
6247: {
6248: error ("destructor `%s' must match class name `%s'",
6249: IDENTIFIER_POINTER (name),
6250: IDENTIFIER_POINTER (rename));
6251: TREE_OPERAND (decl, 0) = rename;
6252: }
6253: decl = name;
6254: }
6255: break;
6256:
6257: case ADDR_EXPR: /* C++ reference declaration */
6258: /* fall through */
6259: case ARRAY_REF:
6260: case INDIRECT_REF:
6261: ctype = NULL_TREE;
6262: innermost_code = TREE_CODE (decl);
6263: decl = TREE_OPERAND (decl, 0);
6264: break;
6265:
6266: case CALL_EXPR:
6267: innermost_code = TREE_CODE (decl);
6268: decl = TREE_OPERAND (decl, 0);
6269: if (decl_context == FIELD && ctype == NULL_TREE)
6270: ctype = current_class_type;
6271: if (ctype != NULL_TREE
6272: && decl != NULL_TREE && flags != DTOR_FLAG
6273: && decl == constructor_name (ctype))
6274: {
6275: return_type = return_ctor;
6276: ctor_return_type = ctype;
6277: }
6278: ctype = NULL_TREE;
6279: break;
6280:
6281: case IDENTIFIER_NODE:
6282: dname = decl;
6283: name = IDENTIFIER_POINTER (decl);
6284: decl = 0;
6285: break;
6286:
6287: case RECORD_TYPE:
6288: case UNION_TYPE:
6289: case ENUMERAL_TYPE:
6290: /* Parse error puts this typespec where
6291: a declarator should go. */
6292: error ("declarator name missing");
6293: dname = TYPE_NAME (decl);
6294: if (dname && TREE_CODE (dname) == TYPE_DECL)
6295: dname = DECL_NAME (dname);
6296: name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
6297: declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
6298: decl = 0;
6299: break;
6300:
6301: case TYPE_EXPR:
6302: ctype = NULL_TREE;
6303: assert (flags == NO_SPECIAL);
6304: flags = TYPENAME_FLAG;
6305: name = "operator <typename>";
6306: /* Go to the absdcl. */
6307: decl = TREE_OPERAND (decl, 0);
6308: return_type = return_conversion;
6309: break;
6310:
6311: /* C++ extension */
6312: case SCOPE_REF:
6313: if (seen_scope_ref == 1)
6314: error ("multiple `::' terms in declarator invalid");
6315: seen_scope_ref += 1;
6316: {
6317: /* Perform error checking, and convert class names to types.
6318: We may call grokdeclarator multiple times for the same
6319: tree structure, so only do the conversion once. In this
6320: case, we have exactly what we want for `ctype'. */
6321: tree cname = TREE_OPERAND (decl, 0);
6322: if (cname == NULL_TREE)
6323: ctype = NULL_TREE;
6324: /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */
6325: else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
6326: || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
6327: ctype = cname;
6328: else if (! is_aggr_typedef (cname, 1))
6329: {
6330: TREE_OPERAND (decl, 0) = 0;
6331: }
6332: /* Must test TREE_OPERAND (decl, 1), in case user gives
6333: us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
6334: else if (TREE_OPERAND (decl, 1)
6335: && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
6336: {
6337: TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
6338: }
6339: else if (ctype == NULL_TREE)
6340: {
6341: ctype = IDENTIFIER_TYPE_VALUE (cname);
6342: TREE_OPERAND (decl, 0) = ctype;
6343: }
6344: else if (TREE_COMPLEXITY (decl) == current_class_depth)
6345: TREE_OPERAND (decl, 0) = ctype;
6346: else
6347: {
6348: if (! DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname), ctype))
6349: {
6350: error ("type `%s' is not derived from type `%s'",
6351: IDENTIFIER_POINTER (cname),
6352: TYPE_NAME_STRING (ctype));
6353: TREE_OPERAND (decl, 0) = 0;
6354: }
6355: else
6356: {
6357: ctype = IDENTIFIER_TYPE_VALUE (cname);
6358: TREE_OPERAND (decl, 0) = ctype;
6359: }
6360: }
6361:
6362: decl = TREE_OPERAND (decl, 1);
6363: if (ctype)
6364: {
6365: if (TREE_CODE (decl) == IDENTIFIER_NODE
6366: && constructor_name (ctype) == decl)
6367: {
6368: return_type = return_ctor;
6369: ctor_return_type = ctype;
6370: }
6371: else if (TREE_CODE (decl) == BIT_NOT_EXPR
6372: && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
6373: && constructor_name (ctype) == TREE_OPERAND (decl, 0))
6374: {
6375: return_type = return_dtor;
6376: ctor_return_type = ctype;
6377: flags = DTOR_FLAG;
6378: decl = TREE_OPERAND (decl, 0);
6379: }
6380: }
6381: }
6382: break;
6383:
6384: case ERROR_MARK:
6385: decl = NULL_TREE;
6386: break;
6387:
6388: default:
6389: assert (0);
6390: }
6391: if (name == 0)
6392: name = "type name";
6393: }
6394:
6395: /* A function definition's declarator must have the form of
6396: a function declarator. */
6397:
6398: if (funcdef_flag && innermost_code != CALL_EXPR)
6399: return 0;
6400:
6401: /* Anything declared one level down from the top level
6402: must be one of the parameters of a function
6403: (because the body is at least two levels down). */
6404:
6405: /* This heuristic cannot be applied to C++ nodes! Fixed, however,
6406: by not allowing C++ class definitions to specify their parameters
6407: with xdecls (must be spec.d in the parmlist).
6408:
6409: Since we now wait to push a class scope until we are sure that
6410: we are in a legitimate method context, we must set oldcname
6411: explicitly (since current_class_name is not yet alive). */
6412:
6413: if (decl_context == NORMAL
6414: && current_binding_level->level_chain == global_binding_level)
6415: decl_context = PARM;
6416:
6417: /* Look through the decl specs and record which ones appear.
6418: Some typespecs are defined as built-in typenames.
6419: Others, the ones that are modifiers of other types,
6420: are represented by bits in SPECBITS: set the bits for
6421: the modifiers that appear. Storage class keywords are also in SPECBITS.
6422:
6423: If there is a typedef name or a type, store the type in TYPE.
6424: This includes builtin typedefs such as `int'.
6425:
6426: Set EXPLICIT_INT if the type is `int' or `char' and did not
6427: come from a user typedef.
6428:
6429: Set LONGLONG if `long' is mentioned twice.
6430:
6431: For C++, constructors and destructors have their own fast treatment. */
6432:
6433: for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
6434: {
6435: register int i;
6436: register tree id = TREE_VALUE (spec);
6437:
6438: /* Certain parse errors slip through. For example,
6439: `int class;' is not caught by the parser. Try
6440: weakly to recover here. */
6441: if (TREE_CODE (spec) != TREE_LIST)
6442: return 0;
6443:
6444: if (TREE_CODE (id) == IDENTIFIER_NODE)
6445: {
6446: if (id == ridpointers[(int) RID_INT])
6447: {
6448: if (type)
6449: error ("extraneous `int' ignored");
6450: else
6451: {
6452: explicit_int = 1;
6453: type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
6454: }
6455: goto found;
6456: }
6457: if (id == ridpointers[(int) RID_CHAR])
6458: {
6459: if (type)
6460: error ("extraneous `char' ignored");
6461: else
6462: {
6463: explicit_char = 1;
6464: type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
6465: }
6466: goto found;
6467: }
6468: /* C++ aggregate types. */
6469: if (IDENTIFIER_HAS_TYPE_VALUE (id))
6470: {
6471: if (type)
6472: error ("multiple declarations `%s' and `%s'",
6473: IDENTIFIER_POINTER (type),
6474: IDENTIFIER_POINTER (id));
6475: else
6476: type = IDENTIFIER_TYPE_VALUE (id);
6477: goto found;
6478: }
6479:
6480: for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
6481: {
6482: if (ridpointers[i] == id)
6483: {
6484: if (i == (int) RID_LONG && specbits & (1<<i))
6485: {
6486: if (pedantic)
6487: warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
6488: else if (longlong)
6489: warning ("`long long long' is too long for GCC");
6490: else
6491: longlong = 1;
6492: }
6493: else if (specbits & (1 << i))
6494: warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
6495: specbits |= 1 << i;
6496: goto found;
6497: }
6498: }
6499: }
6500: if (type)
6501: error ("two or more data types in declaration of `%s'", name);
6502: else if (TREE_CODE (id) == IDENTIFIER_NODE)
6503: {
6504: register tree t = lookup_name (id, 1);
6505: if (!t || TREE_CODE (t) != TYPE_DECL)
6506: error ("`%s' fails to be a typedef or built in type",
6507: IDENTIFIER_POINTER (id));
6508: else
6509: {
6510: type = TREE_TYPE (t);
6511: typedef_decl = t;
6512: }
6513: }
6514: else if (TREE_CODE (id) != ERROR_MARK)
6515: /* Can't change CLASS nodes into RECORD nodes here! */
6516: type = id;
6517:
6518: found: {}
6519: }
6520:
6521: typedef_type = type;
6522:
6523: /* No type at all: default to `int', and set EXPLICIT_INT
6524: because it was not a user-defined typedef. */
6525:
6526: if (type == 0)
6527: {
6528: explicit_int = -1;
6529: if (return_type == return_dtor)
6530: type = void_type_node;
6531: else if (return_type == return_ctor)
6532: type = TYPE_POINTER_TO (ctor_return_type);
6533: else
6534: {
6535: if (funcdef_flag && explicit_warn_return_type
6536: && return_type == return_normal
6537: && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
6538: | (1 << (int) RID_SIGNED) | (1 << (int) RID_UNSIGNED))))
6539: warn_about_return_type = 1;
6540: /* Save warning until we know what is really going on. */
6541: type = integer_type_node;
6542: }
6543: }
6544: else if (return_type == return_dtor)
6545: {
6546: error ("return type specification for destructor invalid");
6547: type = void_type_node;
6548: }
6549: else if (return_type == return_ctor)
6550: {
6551: error ("return type specification for constructor invalid");
6552: type = TYPE_POINTER_TO (ctor_return_type);
6553: }
6554: else if ((specbits & (1 << (int) RID_FRIEND))
6555: && IS_AGGR_TYPE (type)
6556: && ! TYPE_BEING_DEFINED (type)
6557: && TYPE_SIZE (type) == NULL_TREE
6558: && ! ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))
6559: && current_function_decl == NULL_TREE)
6560: {
6561: /* xref_tag will make friend class declarations look like
6562: nested class declarations. Retroactively change that
6563: if the type has not yet been defined.
6564:
6565: ??? ANSI C++ doesn't say what to do in this case yet. */
6566: globalize_nested_type (type);
6567: }
6568:
6569: ctype = NULL_TREE;
6570:
6571: /* Now process the modifiers that were specified
6572: and check for invalid combinations. */
6573:
6574: /* Long double is a special combination. */
6575:
6576: if ((specbits & 1 << (int) RID_LONG) && type == double_type_node)
6577: {
6578: specbits &= ~ (1 << (int) RID_LONG);
6579: type = long_double_type_node;
6580: }
6581:
6582: /* Check all other uses of type modifiers. */
6583:
6584: if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
6585: | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
6586: {
6587: int ok = 0;
6588:
6589: if (TREE_CODE (type) == REAL_TYPE)
6590: error ("short, signed or unsigned invalid for `%s'", name);
6591: else if (TREE_CODE (type) != INTEGER_TYPE)
6592: error ("long, short, signed or unsigned invalid for `%s'", name);
6593: else if ((specbits & 1 << (int) RID_LONG)
6594: && (specbits & 1 << (int) RID_SHORT))
6595: error ("long and short specified together for `%s'", name);
6596: else if (((specbits & 1 << (int) RID_LONG)
6597: || (specbits & 1 << (int) RID_SHORT))
6598: && explicit_char)
6599: error ("long or short specified with char for `%s'", name);
6600: else if (((specbits & 1 << (int) RID_LONG)
6601: || (specbits & 1 << (int) RID_SHORT))
6602: && TREE_CODE (type) == REAL_TYPE)
6603: error ("long or short specified with floating type for `%s'", name);
6604: else if ((specbits & 1 << (int) RID_SIGNED)
6605: && (specbits & 1 << (int) RID_UNSIGNED))
6606: error ("signed and unsigned given together for `%s'", name);
6607: else
6608: {
6609: ok = 1;
6610: if (!explicit_int && !explicit_char && pedantic)
6611: {
6612: pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
6613: name);
6614: if (flag_pedantic_errors)
6615: ok = 0;
6616: }
6617: }
6618:
6619: /* Discard the type modifiers if they are invalid. */
6620: if (! ok)
6621: {
6622: specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
6623: | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
6624: longlong = 0;
6625: }
6626: }
6627:
6628: /* Decide whether an integer type is signed or not.
6629: Optionally treat bitfields as signed by default. */
6630: if (specbits & 1 << (int) RID_UNSIGNED
6631: /* Traditionally, all bitfields are unsigned. */
6632: || (bitfield && flag_traditional)
6633: || (bitfield && ! flag_signed_bitfields
6634: && (explicit_int || explicit_char
6635: /* A typedef for plain `int' without `signed'
6636: can be controlled just like plain `int'. */
6637: || ! (typedef_decl != 0
6638: && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
6639: && TREE_CODE (type) != ENUMERAL_TYPE
6640: && !(specbits & 1 << (int) RID_SIGNED)))
6641: {
6642: if (longlong)
6643: type = long_long_unsigned_type_node;
6644: else if (specbits & 1 << (int) RID_LONG)
6645: type = long_unsigned_type_node;
6646: else if (specbits & 1 << (int) RID_SHORT)
6647: type = short_unsigned_type_node;
6648: else if (type == char_type_node)
6649: type = unsigned_char_type_node;
6650: else if (typedef_decl)
6651: type = unsigned_type (type);
6652: else
6653: type = unsigned_type_node;
6654: }
6655: else if ((specbits & 1 << (int) RID_SIGNED)
6656: && type == char_type_node)
6657: type = signed_char_type_node;
6658: else if (longlong)
6659: type = long_long_integer_type_node;
6660: else if (specbits & 1 << (int) RID_LONG)
6661: type = long_integer_type_node;
6662: else if (specbits & 1 << (int) RID_SHORT)
6663: type = short_integer_type_node;
6664:
6665: /* Set CONSTP if this declaration is `const', whether by
6666: explicit specification or via a typedef.
6667: Likewise for VOLATILEP. */
6668:
6669: constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
6670: volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
6671: staticp = 0;
6672: inlinep = !! (specbits & (1 << (int) RID_INLINE));
6673: if (constp > 1)
6674: warning ("duplicate `const'");
6675: if (volatilep > 1)
6676: warning ("duplicate `volatile'");
6677: virtualp = specbits & (1 << (int) RID_VIRTUAL);
6678: if (specbits & (1 << (int) RID_STATIC))
6679: staticp = 1 + (decl_context == FIELD);
6680:
6681: if (virtualp && staticp == 2)
6682: {
6683: error ("member `%s' cannot be declared both virtual and static", name);
6684: staticp = 0;
6685: }
6686: friendp = specbits & (1 << (int) RID_FRIEND);
6687: specbits &= ~ ((1 << (int) RID_VIRTUAL) | (1 << (int) RID_FRIEND));
6688:
6689: /* Warn if two storage classes are given. Default to `auto'. */
6690:
6691: if (specbits)
6692: {
6693: if (specbits & 1 << (int) RID_STATIC) nclasses++;
6694: if (specbits & 1 << (int) RID_EXTERN) nclasses++;
6695: if (decl_context == PARM && nclasses > 0)
6696: error ("storage class specifiers invalid in parameter declarations");
6697: if (specbits & 1 << (int) RID_TYPEDEF)
6698: {
6699: if (decl_context == PARM)
6700: error ("typedef declaration invalid in parameter declaration");
6701: nclasses++;
6702: }
6703: if (specbits & 1 << (int) RID_AUTO) nclasses++;
6704: if (specbits & 1 << (int) RID_REGISTER) nclasses++;
6705: }
6706:
6707: /* Give error if `virtual' is used outside of class declaration. */
6708: if (virtualp && current_class_name == NULL_TREE)
6709: {
6710: error ("virtual outside class declaration");
6711: virtualp = 0;
6712: }
6713:
6714: /* Warn about storage classes that are invalid for certain
6715: kinds of declarations (parameters, typenames, etc.). */
6716:
6717: if (nclasses > 1)
6718: error ("multiple storage classes in declaration of `%s'", name);
6719: else if (decl_context != NORMAL && nclasses > 0)
6720: {
6721: if (decl_context == PARM
6722: && ((specbits & (1 << (int) RID_REGISTER)) | (1 << (int) RID_AUTO)))
6723: ;
6724: else if (decl_context == FIELD
6725: && (specbits
6726: & (/* C++ allows static class elements */
6727: (1 << (int) RID_STATIC)
6728: /* ...and inlines */
6729: | (1 << (int) RID_INLINE)
6730: /* ...and signed and unsigned elements. */
6731: | (1 << (int) RID_SIGNED)
6732: | (1 << (int) RID_UNSIGNED))))
6733: ;
6734: else if (decl_context == FIELD && (specbits & (1 << (int) RID_TYPEDEF)))
6735: {
6736: /* A typedef which was made in a class's scope. */
6737: tree loc_typedecl;
6738: register int i = sizeof (struct lang_decl_flags) / sizeof (int);
6739: register int *pi;
6740:
6741: /* keep `grokdeclarator' from thinking we are in PARM context. */
6742: pushlevel (0);
6743: loc_typedecl = start_decl (declarator, declspecs, initialized, NULL_TREE);
6744:
6745: pi = (int *) permalloc (sizeof (struct lang_decl_flags));
6746: while (i > 0)
6747: pi[--i] = 0;
6748: DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
6749: poplevel (0, 0, 0);
6750:
6751: #if 0
6752: if (TREE_CODE (TREE_TYPE (loc_typedecl)) == ENUMERAL_TYPE)
6753: {
6754: tree ref = lookup_tag (ENUMERAL_TYPE, DECL_NAME (loc_typedecl), current_binding_level, 0);
6755: if (! ref)
6756: pushtag (DECL_NAME (loc_typedecl), TREE_TYPE (loc_typedecl));
6757: }
6758: #endif
6759: if (IDENTIFIER_CLASS_VALUE (DECL_NAME (loc_typedecl)))
6760: error_with_decl (loc_typedecl,
6761: "typedef of `%s' in class scope hides previous declaration");
6762: #if 0
6763: /* Must push this into scope via `pushdecl_class_level'. */
6764: IDENTIFIER_CLASS_VALUE (DECL_NAME (loc_typedecl)) = loc_typedecl;
6765: #endif
6766: return loc_typedecl;
6767: }
6768: else
6769: {
6770: error ((decl_context == FIELD
6771: ? "storage class specified for structure field `%s'"
6772: : (decl_context == PARM
6773: ? "storage class specified for parameter `%s'"
6774: : "storage class specified for typename")),
6775: name);
6776: specbits &= ~ ((1 << (int) RID_REGISTER) | (1 << (int) RID_AUTO)
6777: | (1 << (int) RID_EXTERN));
6778: }
6779: }
6780: else if (specbits & 1 << (int) RID_EXTERN && initialized)
6781: {
6782: /* `extern' with initialization is invalid if not at top level. */
6783: if (current_binding_level != global_binding_level)
6784: warning ("non-global `%s' initialized and declared `extern'", name);
6785: }
6786: else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag
6787: && current_binding_level != global_binding_level)
6788: error ("nested function `%s' declared `extern'", name);
6789: else if (current_binding_level == global_binding_level)
6790: {
6791: if (specbits & (1 << (int) RID_AUTO))
6792: error ("top-level declaration of `%s' specifies `auto'", name);
6793: #if 0
6794: if (specbits & (1 << (int) RID_REGISTER))
6795: error ("top-level declaration of `%s' specifies `register'", name);
6796: #endif
6797: #if 0
6798: /* I'm not sure under what circumstances we should turn
6799: on the extern bit, and under what circumstances we should
6800: warn if other bits are turned on. */
6801: if (decl_context == NORMAL
6802: && (specbits & (1 << (int) RID_EXTERN)) == 0
6803: && ! root_lang_context_p ())
6804: {
6805: specbits |= (1 << (int) RID_EXTERN);
6806: }
6807: #endif
6808: }
6809:
6810: /* Now figure out the structure of the declarator proper.
6811: Descend through it, creating more complex types, until we reach
6812: the declared identifier (or NULL_TREE, in an absolute declarator). */
6813:
6814: while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
6815: {
6816: /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
6817: an INDIRECT_REF (for *...),
6818: a CALL_EXPR (for ...(...)),
6819: an identifier (for the name being declared)
6820: or a null pointer (for the place in an absolute declarator
6821: where the name was omitted).
6822: For the last two cases, we have just exited the loop.
6823:
6824: For C++ it could also be
6825: a SCOPE_REF (for class :: ...). In this case, we have converted
6826: sensible names to types, and those are the values we use to
6827: qualify the member name.
6828: an ADDR_EXPR (for &...),
6829: a BIT_NOT_EXPR (for destructors)
6830: a TYPE_EXPR (for operator typenames)
6831: a WRAPPER_EXPR (for wrappers)
6832: an ANTI_WRAPPER_EXPR (for averting wrappers)
6833:
6834: At this point, TYPE is the type of elements of an array,
6835: or for a function to return, or for a pointer to point to.
6836: After this sequence of ifs, TYPE is the type of the
6837: array or function or pointer, and DECLARATOR has had its
6838: outermost layer removed. */
6839:
6840: if (TREE_CODE (type) == ERROR_MARK)
6841: {
6842: if (TREE_CODE (declarator) == SCOPE_REF)
6843: declarator = TREE_OPERAND (declarator, 1);
6844: else
6845: declarator = TREE_OPERAND (declarator, 0);
6846: continue;
6847: }
6848: if (quals != NULL_TREE
6849: && (declarator == NULL_TREE
6850: || TREE_CODE (declarator) != SCOPE_REF))
6851: {
6852: if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
6853: ctype = TYPE_METHOD_BASETYPE (type);
6854: if (ctype != NULL_TREE)
6855: {
6856: tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
6857: ctype = grok_method_quals (ctype, dummy, quals);
6858: type = TREE_TYPE (dummy);
6859: quals = NULL_TREE;
6860: }
6861: }
6862: switch (TREE_CODE (declarator))
6863: {
6864: case ARRAY_REF:
6865: maybe_globalize_type (type);
6866: {
6867: register tree itype = NULL_TREE;
6868: register tree size = TREE_OPERAND (declarator, 1);
6869:
6870: declarator = TREE_OPERAND (declarator, 0);
6871:
6872: /* Check for some types that there cannot be arrays of. */
6873:
6874: if (type == void_type_node)
6875: {
6876: error ("declaration of `%s' as array of voids", name);
6877: type = error_mark_node;
6878: }
6879:
6880: if (TREE_CODE (type) == FUNCTION_TYPE)
6881: {
6882: error ("declaration of `%s' as array of functions", name);
6883: type = error_mark_node;
6884: }
6885:
6886: if (size == error_mark_node)
6887: type = error_mark_node;
6888:
6889: if (type == error_mark_node)
6890: continue;
6891:
6892: if (size)
6893: {
6894: /* Must suspend_momentary here because the index
6895: type may need to live until the end of the function.
6896: For example, it is used in the declaration of a
6897: variable which requires destructing at the end of
6898: the function; then build_vec_delete will need this
6899: value. */
6900: int yes = suspend_momentary ();
6901: /* might be a cast */
6902: if (TREE_CODE (size) == NOP_EXPR
6903: && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
6904: size = TREE_OPERAND (size, 0);
6905:
6906: /* If this is a template parameter, it'll be constant, but
6907: we don't know what the value is yet. */
6908: if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
6909: goto dont_grok_size;
6910:
6911: if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
6912: && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
6913: {
6914: error ("size of array `%s' has non-integer type", name);
6915: size = integer_one_node;
6916: }
6917: if (TREE_READONLY_DECL_P (size))
6918: size = decl_constant_value (size);
6919: if (pedantic && integer_zerop (size))
6920: warning ("ANSI C forbids zero-size array `%s'", name);
6921: if (TREE_CONSTANT (size))
6922: {
6923: if (INT_CST_LT (size, integer_zero_node))
6924: {
6925: error ("size of array `%s' is negative", name);
6926: size = integer_one_node;
6927: }
6928: itype = build_index_type (size_binop (MINUS_EXPR, size,
6929: integer_one_node));
6930: }
6931: else
6932: {
6933: if (pedantic)
6934: warning ("ANSI C forbids variable-size array `%s'", name);
6935: dont_grok_size:
6936: itype = build_binary_op (MINUS_EXPR, size, integer_one_node);
6937: itype = build_index_type (itype);
6938: }
6939: resume_momentary (yes);
6940: }
6941:
6942: /* Build the array type itself.
6943: Merge any constancy or volatility into the target type. */
6944:
6945: if (constp || volatilep)
6946: type = build_type_variant (type, constp, volatilep);
6947:
6948: #if 0 /* don't clear these; leave them set so that the array type
6949: or the variable is itself const or volatile. */
6950: constp = 0;
6951: volatilep = 0;
6952: #endif
6953: type = build_cplus_array_type (type, itype);
6954: ctype = NULL_TREE;
6955: }
6956: break;
6957:
6958: case CALL_EXPR:
6959: maybe_globalize_type (type);
6960: {
6961: tree arg_types;
6962:
6963: /* Declaring a function type.
6964: Make sure we have a valid type for the function to return. */
6965: /* Is this an error? Should they be merged into TYPE here? */
6966: if (pedantic && (constp || volatilep))
6967: warning ("function declared to return const or volatile result");
6968:
6969: /* Warn about some types functions can't return. */
6970:
6971: if (TREE_CODE (type) == FUNCTION_TYPE)
6972: {
6973: error ("`%s' declared as function returning a function", name);
6974: type = integer_type_node;
6975: }
6976: if (TREE_CODE (type) == ARRAY_TYPE)
6977: {
6978: error ("`%s' declared as function returning an array", name);
6979: type = integer_type_node;
6980: }
6981:
6982: if (ctype == NULL_TREE
6983: && decl_context == FIELD
6984: && (friendp == 0 || dname == current_class_name))
6985: ctype = current_class_type;
6986:
6987: if (ctype && flags == TYPENAME_FLAG)
6988: TYPE_HAS_CONVERSION (ctype) = 1;
6989: if (ctype && constructor_name (ctype) == dname)
6990: {
6991: /* We are within a class's scope. If our declarator name
6992: is the same as the class name, and we are defining
6993: a function, then it is a constructor/destructor, and
6994: therefore returns a void type. */
6995:
6996: if (flags == DTOR_FLAG)
6997: {
6998: if (staticp == 2)
6999: error ("destructor cannot be static member function");
7000: if (decl_context == FIELD)
7001: {
7002: if (! member_function_or_else (ctype, current_class_type,
7003: "destructor for alien class `%s' cannot be a member"))
7004: return NULL_TREE;
7005: if (TYPE_HAS_DESTRUCTOR (ctype))
7006: error_with_aggr_type (ctype, "class `%s' already has destructor defined");
7007: }
7008: }
7009: else if (flags == WRAPPER_FLAG || flags == ANTI_WRAPPER_FLAG)
7010: {
7011: if (staticp == 2)
7012: error ("wrapper cannot be static member function");
7013: if (decl_context == FIELD)
7014: {
7015: if (! member_function_or_else (ctype, current_class_type,
7016: "wrapper for alien class `%s' cannot be member"))
7017: return NULL_TREE;
7018: TYPE_WRAP_TYPE (ctype) = TYPE_MAIN_VARIANT (ctype);
7019: }
7020: }
7021: else if (flags == WRAPPER_PRED_FLAG)
7022: {
7023: if (staticp == 2)
7024: error ("wrapper predicate cannot be static member function");
7025: if (TREE_CODE (type) != INTEGER_TYPE)
7026: {
7027: error ("wrapper predicated must return an integer type");
7028: type = integer_type_node;
7029: }
7030: if (decl_context == FIELD)
7031: {
7032: if (! member_function_or_else (ctype, current_class_type,
7033: "wrapper predicate for alien class `%s' cannot be member"))
7034: return NULL_TREE;
7035: TYPE_HAS_WRAPPER_PRED (ctype) = 1;
7036: }
7037: }
7038: else /* its a constructor. */
7039: {
7040: if (staticp == 2)
7041: error ("constructor cannot be static member function");
7042: if (virtualp || friendp)
7043: {
7044: pedwarn ("constructors cannot be declared virtual or friend");
7045: virtualp = 0;
7046: friendp = 0;
7047: }
7048: if (specbits & ~((1 << (int) RID_INLINE)|(1 << (int) RID_STATIC)))
7049: error ("return value type specifier for %s ignored",
7050: flags == DTOR_FLAG ? "destructor" : "constructor");
7051: type = TYPE_POINTER_TO (ctype);
7052: if (decl_context == FIELD)
7053: {
7054: if (! member_function_or_else (ctype, current_class_type,
7055: "constructor for alien class `%s' cannot be member"))
7056: return NULL_TREE;
7057: TYPE_HAS_CONSTRUCTOR (ctype) = 1;
7058: assert (return_type == return_ctor);
7059: }
7060: }
7061: if (decl_context == FIELD)
7062: staticp = 0;
7063: }
7064: else if (friendp && virtualp)
7065: {
7066: /* Cannot be both friend and virtual. */
7067: error ("virtual functions cannot be friends");
7068: specbits ^= (1 << (int) RID_FRIEND);
7069: }
7070:
7071: if (decl_context == NORMAL && friendp)
7072: error ("friend declaration not in class definition");
7073:
7074: /* Pick up type qualifiers which should be applied to `this'. */
7075: quals = TREE_OPERAND (declarator, 2);
7076:
7077: /* Traditionally, declaring return type float means double. */
7078:
7079: if (flag_traditional && type == float_type_node)
7080: type = double_type_node;
7081:
7082: /* Construct the function type and go to the next
7083: inner layer of declarator. */
7084:
7085: {
7086: int funcdef_p;
7087: tree inner_parms = TREE_OPERAND (declarator, 1);
7088: tree inner_decl = TREE_OPERAND (declarator, 0);
7089:
7090: declarator = TREE_OPERAND (declarator, 0);
7091:
7092: if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
7093: inner_decl = TREE_OPERAND (inner_decl, 1);
7094:
7095: /* Say it's a definition only for the CALL_EXPR
7096: closest to the identifier. */
7097: funcdef_p =
7098: (inner_decl &&
7099: (TREE_CODE (inner_decl) == IDENTIFIER_NODE
7100: || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0;
7101:
7102: arg_types = grokparms (inner_parms, funcdef_p);
7103: }
7104:
7105: if (declarator)
7106: {
7107: /* Get past destructors, wrappers, etc.
7108: We know we have one because FLAGS will be non-zero.
7109:
7110: Complain about improper parameter lists here. */
7111: if (TREE_CODE (declarator) == BIT_NOT_EXPR)
7112: {
7113: declarator = TREE_OPERAND (declarator, 0);
7114:
7115: if (strict_prototype == 0 && arg_types == NULL_TREE)
7116: arg_types = void_list_node;
7117: else if (arg_types == NULL_TREE
7118: || arg_types != void_list_node)
7119: {
7120: error ("destructors cannot be specified with parameters");
7121: arg_types = void_list_node;
7122: }
7123: }
7124: else if (TREE_CODE (declarator) == WRAPPER_EXPR)
7125: {
7126: /* Report misuse of wrappers and their associates.
7127: Note that because wrappers may be invoked
7128: quite a bit implicitly, if we give an error
7129: message, we make an effort to fix that error
7130: so that spurious errors do not show up. */
7131: if (TREE_CODE (TREE_OPERAND (declarator, 0)) == COND_EXPR)
7132: {
7133: /* First parameter must be a pointer to a member function.
7134: Rest of parameters must all be default parameters. */
7135: if (arg_types == NULL_TREE
7136: || arg_types == void_list_node
7137: || TREE_CODE (TREE_VALUE (arg_types)) != POINTER_TYPE
7138: || TREE_CODE (TREE_TYPE (TREE_VALUE (arg_types))) != METHOD_TYPE)
7139: {
7140: error ("wrapper predicate takes a pointer-to-member-function as first argument");
7141: arg_types = NULL_TREE;
7142: }
7143: else if (TREE_CHAIN (arg_types)
7144: && TREE_CHAIN (arg_types) != void_list_node
7145: && TREE_PURPOSE (TREE_CHAIN (arg_types)) == NULL_TREE)
7146: {
7147: error ("all arguments past first must be default for wrapper predicate");
7148: TREE_CHAIN (arg_types) = NULL_TREE;
7149: }
7150: declarator = wrapper_pred_name;
7151: }
7152: else
7153: {
7154: /* First parameter must be an int.
7155: Second parameter must be a pointer to a member function. */
7156: if (arg_types == NULL_TREE || TREE_CHAIN (arg_types) == NULL_TREE)
7157: {
7158: error ("wrappers must have at least two arguments (int, pointer-to-member-function)");
7159: arg_types = NULL_TREE;
7160: }
7161: else
7162: {
7163: if (TREE_CODE (TREE_VALUE (arg_types)) != INTEGER_TYPE)
7164: {
7165: error ("first argument to wrapper must be an integer");
7166: TREE_VALUE (arg_types) = integer_type_node;
7167: }
7168: if (TREE_CODE (TREE_VALUE (TREE_CHAIN (arg_types))) != POINTER_TYPE
7169: || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arg_types)))) != METHOD_TYPE)
7170: {
7171: error ("second argument to wrapper must be a pointer-to-member-function type");
7172: TREE_CHAIN (arg_types) = NULL_TREE;
7173: }
7174: }
7175: declarator = wrapper_name;
7176: }
7177: }
7178: else if (TREE_CODE (declarator) == ANTI_WRAPPER_EXPR)
7179: declarator = anti_wrapper_name;
7180: }
7181: type = build_function_type (type, flag_traditional ? 0 : arg_types);
7182: }
7183: break;
7184:
7185: case ADDR_EXPR:
7186: case INDIRECT_REF:
7187: maybe_globalize_type (type);
7188:
7189: /* Filter out pointers-to-references and references-to-references.
7190: We can get these if a TYPE_DECL is used. */
7191:
7192: if (TREE_CODE (type) == REFERENCE_TYPE)
7193: {
7194: error ("cannot declare %s to references",
7195: TREE_CODE (declarator) == ADDR_EXPR
7196: ? "references" : "pointers");
7197: declarator = TREE_OPERAND (declarator, 0);
7198: continue;
7199: }
7200:
7201: /* Merge any constancy or volatility into the target type
7202: for the pointer. */
7203:
7204: if (constp || volatilep)
7205: {
7206: type = build_type_variant (type, constp, volatilep);
7207: if (IS_AGGR_TYPE (type))
7208: build_pointer_type (type);
7209: }
7210: constp = 0;
7211: volatilep = 0;
7212:
7213: if (TREE_CODE (declarator) == ADDR_EXPR)
7214: {
7215: if (TREE_CODE (type) == FUNCTION_TYPE)
7216: {
7217: error ("cannot declare references to functions; use pointer to function instead");
7218: type = build_pointer_type (type);
7219: }
7220: else
7221: {
7222: if (TYPE_MAIN_VARIANT (type) == void_type_node)
7223: error ("invalid type: `void &'");
7224: else
7225: type = build_reference_type (type);
7226: }
7227: }
7228: else
7229: type = build_pointer_type (type);
7230:
7231: /* Process a list of type modifier keywords (such as
7232: const or volatile) that were given inside the `*' or `&'. */
7233:
7234: if (TREE_TYPE (declarator))
7235: {
7236: register tree typemodlist;
7237: int erred = 0;
7238: for (typemodlist = TREE_TYPE (declarator); typemodlist;
7239: typemodlist = TREE_CHAIN (typemodlist))
7240: {
7241: if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
7242: constp++;
7243: else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
7244: volatilep++;
7245: else if (!erred)
7246: {
7247: erred = 1;
7248: error ("invalid type modifier within %s declarator",
7249: TREE_CODE (declarator) == ADDR_EXPR
7250: ? "reference" : "pointer");
7251: }
7252: }
7253: if (constp > 1)
7254: warning ("duplicate `const'");
7255: if (volatilep > 1)
7256: warning ("duplicate `volatile'");
7257: }
7258: declarator = TREE_OPERAND (declarator, 0);
7259: ctype = NULL_TREE;
7260: break;
7261:
7262: case SCOPE_REF:
7263: {
7264: /* We have converted type names to NULL_TREE if the
7265: name was bogus, or to a _TYPE node, if not.
7266:
7267: The variable CTYPE holds the type we will ultimately
7268: resolve to. The code here just needs to build
7269: up appropriate member types. */
7270: tree sname = TREE_OPERAND (declarator, 1);
7271:
7272: if (TREE_COMPLEXITY (declarator) == 0)
7273: /* This needs to be here, in case we are called
7274: multiple times. */ ;
7275: else if (TREE_COMPLEXITY (declarator) == current_class_depth)
7276: {
7277: TREE_COMPLEXITY (declarator) -= 1;
7278: popclass (1);
7279: }
7280: else
7281: abort ();
7282:
7283: if (TREE_OPERAND (declarator, 0) == NULL_TREE)
7284: {
7285: /* We had a reference to a global decl, or
7286: perhaps we were given a non-aggregate typedef,
7287: in which case we cleared this out, and should just
7288: keep going as though it wasn't there. */
7289: declarator = sname;
7290: continue;
7291: }
7292: ctype = TREE_OPERAND (declarator, 0);
7293:
7294: if (sname == NULL_TREE)
7295: goto done_scoping;
7296:
7297: /* Destructors can have their visibilities changed as well. */
7298: if (TREE_CODE (sname) == BIT_NOT_EXPR)
7299: sname = TREE_OPERAND (sname, 0);
7300:
7301: if (TREE_CODE (sname) == IDENTIFIER_NODE)
7302: {
7303: /* This is the `standard' use of the scoping operator:
7304: basetype :: member . */
7305:
7306: if (ctype == current_class_type || friendp)
7307: if (TREE_CODE (type) == FUNCTION_TYPE)
7308: type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
7309: else
7310: type = build_member_type (ctype, type);
7311: else if (TYPE_SIZE (ctype) != 0
7312: || (specbits & (1<<(int)RID_TYPEDEF)))
7313: {
7314: tree t;
7315: /* have to move this code elsewhere in this function.
7316: this code is used for i.e., typedef int A::M; M *pm; */
7317:
7318: if (decl_context == FIELD)
7319: {
7320: t = lookup_field (ctype, sname, 0);
7321: if (t)
7322: {
7323: t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
7324: DECL_INITIAL (t) = init;
7325: return t;
7326: }
7327: /* No such field, try member functions. */
7328: t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
7329: if (t)
7330: {
7331: if (flags == DTOR_FLAG)
7332: t = TREE_VALUE (t);
7333: else if (CLASSTYPE_METHOD_VEC (ctype)
7334: && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
7335: {
7336: /* Don't include destructor with constructors. */
7337: t = DECL_CHAIN (TREE_VALUE (t));
7338: if (t == NULL_TREE)
7339: error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
7340: t = build_tree_list (NULL_TREE, t);
7341: }
7342: t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
7343: DECL_INITIAL (t) = init;
7344: return t;
7345: }
7346:
7347: if (flags == TYPENAME_FLAG)
7348: error_with_aggr_type (ctype, "type conversion is not a member of structure `%s'");
7349: else
7350: error ("field `%s' is not a member of structure `%s'",
7351: IDENTIFIER_POINTER (sname),
7352: TYPE_NAME_STRING (ctype));
7353: }
7354: if (TREE_CODE (type) == FUNCTION_TYPE)
7355: type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
7356: else
7357: type = build_member_type (ctype, type);
7358: }
7359: else if (uses_template_parms (ctype))
7360: {
7361: enum tree_code c;
7362: tree t;
7363: if (TREE_CODE (type) == FUNCTION_TYPE)
7364: {
7365: type = build_cplus_method_type (ctype,
7366: TREE_TYPE (type),
7367: TYPE_ARG_TYPES (type));
7368: c = FUNCTION_DECL;
7369: }
7370: }
7371: else
7372: sorry ("structure `%s' not yet defined",
7373: TYPE_NAME_STRING (ctype));
7374: declarator = sname;
7375: }
7376: else if (TREE_CODE (sname) == TYPE_EXPR)
7377: {
7378: /* A TYPE_EXPR will change types out from under us.
7379: So do the TYPE_EXPR now, and make this SCOPE_REF
7380: inner to the TYPE_EXPR's CALL_EXPR.
7381:
7382: This does not work if we don't get a CALL_EXPR back.
7383: I did not think about error recovery, hence the
7384: assert (0). */
7385:
7386: /* Get the CALL_EXPR. */
7387: sname = grokoptypename (sname, 0);
7388: assert (TREE_CODE (sname) == CALL_EXPR);
7389: type = TREE_TYPE (TREE_OPERAND (sname, 0));
7390: /* Scope the CALL_EXPR's name. */
7391: TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0);
7392: /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position. */
7393: TREE_OPERAND (sname, 0) = declarator;
7394: /* Now work from the CALL_EXPR. */
7395: declarator = sname;
7396: continue;
7397: }
7398: else if (TREE_CODE (sname) == SCOPE_REF)
7399: abort ();
7400: else
7401: {
7402: done_scoping:
7403: declarator = TREE_OPERAND (declarator, 1);
7404: if (declarator && TREE_CODE (declarator) == CALL_EXPR)
7405: /* In this case, we will deal with it later. */
7406: ;
7407: else
7408: {
7409: if (TREE_CODE (type) == FUNCTION_TYPE)
7410: type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
7411: else
7412: type = build_member_type (ctype, type);
7413: }
7414: }
7415: }
7416: break;
7417:
7418: case BIT_NOT_EXPR:
7419: declarator = TREE_OPERAND (declarator, 0);
7420: break;
7421:
7422: case TYPE_EXPR:
7423: declarator = grokoptypename (declarator, 0);
7424: if (explicit_int != -1)
7425: if (comp_target_types (type, TREE_TYPE (TREE_OPERAND (declarator, 0)), 1) == 0)
7426: error ("type conversion function declared to return incongruent type");
7427: else if (pedantic)
7428: error ("return type specified for type conversion function");
7429: else
7430: warning ("return type specified for type conversion function");
7431: type = TREE_TYPE (TREE_OPERAND (declarator, 0));
7432: maybe_globalize_type (type);
7433: break;
7434:
7435: case WRAPPER_EXPR:
7436: if (TREE_CODE (TREE_OPERAND (declarator, 0)) == COND_EXPR)
7437: declarator = wrapper_pred_name;
7438: else
7439: declarator = wrapper_name;
7440: break;
7441:
7442: case ANTI_WRAPPER_EXPR:
7443: declarator = anti_wrapper_name;
7444: break;
7445:
7446: case RECORD_TYPE:
7447: case UNION_TYPE:
7448: case ENUMERAL_TYPE:
7449: declarator = 0;
7450: break;
7451:
7452: case ERROR_MARK:
7453: declarator = 0;
7454: break;
7455:
7456: default:
7457: assert (0);
7458: }
7459: }
7460:
7461: /* Now TYPE has the actual type. */
7462:
7463: /* If this is declaring a typedef name, return a TYPE_DECL. */
7464:
7465: if (specbits & (1 << (int) RID_TYPEDEF))
7466: {
7467: tree decl;
7468:
7469: /* Note that the grammar rejects storage classes
7470: in typenames, fields or parameters. */
7471: if (constp || volatilep)
7472: type = build_type_variant (type, constp, volatilep);
7473:
7474: /* If the user declares "struct {...} foo" then `foo' will have
7475: an anonymous name. Fill that name in now. Nothing can
7476: refer to it, so nothing needs know about the name change.
7477: The TYPE_NAME field was filled in by build_struct_xref. */
7478: if (TYPE_NAME (type)
7479: && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7480: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
7481: {
7482: /* replace the anonymous name with the real name everywhere. */
7483: lookup_tag_reverse (type, declarator);
7484: TYPE_IDENTIFIER (type) = declarator;
7485: }
7486:
7487: decl = build_decl (TYPE_DECL, declarator, type);
7488: if (quals)
7489: {
7490: if (ctype == NULL_TREE)
7491: {
7492: if (TREE_CODE (type) != METHOD_TYPE)
7493: error_with_decl (decl, "invalid type qualifier for non-method type");
7494: else
7495: ctype = TYPE_METHOD_BASETYPE (type);
7496: }
7497: if (ctype != NULL_TREE)
7498: grok_method_quals (ctype, decl, quals);
7499: }
7500:
7501: if ((specbits & (1 << (int) RID_SIGNED))
7502: || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
7503: C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
7504:
7505: return decl;
7506: }
7507:
7508: /* Detect the case of an array type of unspecified size
7509: which came, as such, direct from a typedef name.
7510: We must copy the type, so that each identifier gets
7511: a distinct type, so that each identifier's size can be
7512: controlled separately by its own initializer. */
7513:
7514: if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
7515: && TYPE_DOMAIN (type) == 0)
7516: {
7517: type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
7518: }
7519:
7520: /* If this is a type name (such as, in a cast or sizeof),
7521: compute the type and return it now. */
7522:
7523: if (decl_context == TYPENAME)
7524: {
7525: /* Note that the grammar rejects storage classes
7526: in typenames, fields or parameters. */
7527: if (constp || volatilep)
7528: type = build_type_variant (type, constp, volatilep);
7529:
7530: /* Special case: "friend class foo" looks like a TYPENAME context. */
7531: if (friendp)
7532: {
7533: /* A friendly class? */
7534: make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
7535: type = void_type_node;
7536: }
7537: else if (quals)
7538: {
7539: tree dummy = build_decl (TYPE_DECL, declarator, type);
7540: if (ctype == NULL_TREE)
7541: {
7542: assert (TREE_CODE (type) == METHOD_TYPE);
7543: ctype = TYPE_METHOD_BASETYPE (type);
7544: }
7545: grok_method_quals (ctype, dummy, quals);
7546: type = TREE_TYPE (dummy);
7547: }
7548:
7549: return type;
7550: }
7551:
7552: /* `void' at top level (not within pointer)
7553: is allowed only in typedefs or type names.
7554: We don't complain about parms either, but that is because
7555: a better error message can be made later. */
7556:
7557: if (type == void_type_node && decl_context != PARM)
7558: {
7559: if (declarator != NULL_TREE
7560: && TREE_CODE (declarator) == IDENTIFIER_NODE)
7561: error ("variable or field `%s' declared void", name);
7562: else
7563: error ("variable or field declared void");
7564: type = integer_type_node;
7565: }
7566:
7567: /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
7568: or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
7569:
7570: {
7571: register tree decl;
7572:
7573: if (decl_context == PARM)
7574: {
7575: tree parmtype = type;
7576:
7577: if (ctype)
7578: error ("cannot use `::' in parameter declaration");
7579: if (virtualp)
7580: error ("parameter declared `virtual'");
7581: if (quals)
7582: error ("`const' and `volatile' function specifiers invalid in parameter declaration");
7583: if (friendp)
7584: error ("invalid friend declaration");
7585: if (raises)
7586: error ("invalid raises declaration");
7587:
7588: /* A parameter declared as an array of T is really a pointer to T.
7589: One declared as a function is really a pointer to a function.
7590: One declared as a member is really a pointer to member.
7591:
7592: Don't be misled by references. */
7593:
7594: if (TREE_CODE (type) == REFERENCE_TYPE)
7595: type = TREE_TYPE (type);
7596:
7597: if (TREE_CODE (type) == ARRAY_TYPE)
7598: {
7599: if (parmtype == type)
7600: {
7601: /* Transfer const-ness of array into that of type
7602: pointed to. */
7603: type = build_pointer_type
7604: (build_type_variant (TREE_TYPE (type), constp, volatilep));
7605: volatilep = constp = 0;
7606: }
7607: else
7608: type = build_pointer_type (TREE_TYPE (type));
7609: }
7610: else if (TREE_CODE (type) == FUNCTION_TYPE)
7611: type = build_pointer_type (type);
7612: else if (TREE_CODE (type) == OFFSET_TYPE)
7613: type = build_pointer_type (type);
7614:
7615: if (TREE_CODE (parmtype) == REFERENCE_TYPE)
7616: {
7617: /* Transfer const-ness of reference into that of type pointed to. */
7618: type = build_reference_type (type, constp, volatilep);
7619: constp = volatilep = 0;
7620: }
7621:
7622: decl = build_decl (PARM_DECL, declarator, type);
7623:
7624: /* Compute the type actually passed in the parmlist,
7625: for the case where there is no prototype.
7626: (For example, shorts and chars are passed as ints.)
7627: When there is a prototype, this is overridden later. */
7628:
7629: DECL_ARG_TYPE (decl) = type;
7630: if (type == float_type_node)
7631: DECL_ARG_TYPE (decl) = double_type_node;
7632: else if (TREE_CODE (type) == INTEGER_TYPE
7633: && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
7634: DECL_ARG_TYPE (decl) = integer_type_node;
7635: }
7636: else if (decl_context == FIELD)
7637: {
7638: if (type == error_mark_node)
7639: {
7640: /* Happens when declaring arrays of sizes which
7641: are error_mark_node, for example. */
7642: decl = NULL_TREE;
7643: }
7644: else if (TREE_CODE (type) == FUNCTION_TYPE)
7645: {
7646: if (friendp == 0)
7647: {
7648: if (ctype == NULL_TREE)
7649: ctype = current_class_type;
7650: /* Don't convert type of operators new and delete to
7651: METHOD_TYPE; they remain FUNCTION_TYPEs. */
7652: if (staticp < 2
7653: && declarator != ansi_opname[NEW_EXPR]
7654: && declarator != ansi_opname[DELETE_EXPR])
7655: type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
7656: }
7657: decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0);
7658: TREE_INLINE (decl) = inlinep;
7659: if ((specbits & (1 << (int) RID_EXTERN))
7660: || (ctype != NULL_TREE && funcdef_flag >= 0))
7661: TREE_PUBLIC (decl) = 1;
7662: }
7663: else if (TREE_CODE (type) == METHOD_TYPE)
7664: {
7665: decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0);
7666: TREE_INLINE (decl) = inlinep;
7667: /* All method decls are public. */
7668: TREE_PUBLIC (decl) = 1;
7669: }
7670: else if (TREE_CODE (type) == RECORD_TYPE
7671: && CLASSTYPE_DECLARED_EXCEPTION (type))
7672: {
7673: /* Handle a class-local exception declaration. */
7674: decl = build_lang_field_decl (VAR_DECL, declarator, type);
7675: if (ctype == NULL_TREE)
7676: ctype = current_class_type;
7677: finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
7678: ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl);
7679: return void_type_node;
7680: }
7681: else if (TYPE_SIZE (type) == 0 && !staticp
7682: && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
7683: {
7684: if (declarator)
7685: error ("field `%s' has incomplete type",
7686: IDENTIFIER_POINTER (declarator));
7687: else
7688: error ("field has incomplete type");
7689: type = error_mark_node;
7690: decl = NULL_TREE;
7691: }
7692: else
7693: {
7694: if (friendp)
7695: {
7696: if (declarator)
7697: error ("`%s' is neither function nor method; cannot be declared friend",
7698: IDENTIFIER_POINTER (declarator));
7699: else
7700: {
7701: error ("invalid friend declaration");
7702: return void_type_node;
7703: }
7704: friendp = 0;
7705: }
7706: decl = NULL_TREE;
7707: }
7708:
7709: if (friendp)
7710: {
7711: /* Friends are treated specially. */
7712: if (ctype == current_class_type)
7713: warning ("member functions are implicitly friends of their class");
7714: else if (DECL_NAME (decl))
7715: return do_friend (ctype, declarator, decl, last_function_parms, flags, quals);
7716: else return void_type_node;
7717: }
7718:
7719: /* Structure field. It may not be a function, except for C++ */
7720:
7721: if (decl == 0)
7722: {
7723: if (virtualp)
7724: error ("field declared `virtual'");
7725: if (quals)
7726: error ("`const' and `volatile' function specifiers invalid in field declaration");
7727: if (friendp)
7728: error ("invalid friend declaration");
7729: if (raises)
7730: error ("invalid raises declaration");
7731:
7732: if (staticp || (constp && initialized))
7733: {
7734: /* C++ allows static class members.
7735: All other work for this is done by grokfield.
7736: This VAR_DECL is built by build_lang_field_decl.
7737: All other VAR_DECLs are built by build_decl. */
7738: decl = build_lang_field_decl (VAR_DECL, declarator, type);
7739: if (staticp || TREE_CODE (type) == ARRAY_TYPE)
7740: TREE_STATIC (decl) = 1;
7741: /* In class context, static means public visibility. */
7742: TREE_PUBLIC (decl) = 1;
7743: TREE_EXTERNAL (decl) = !initialized;
7744: }
7745: else
7746: decl = build_lang_field_decl (FIELD_DECL, declarator, type);
7747: }
7748: }
7749: else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
7750: {
7751: int was_overloaded = 0;
7752: tree original_name = declarator;
7753:
7754: if (! declarator) return NULL_TREE;
7755:
7756: if (specbits & ((1 << (int) RID_AUTO) | (1 << (int) RID_REGISTER)))
7757: error ("invalid storage class for function `%s'", name);
7758: /* Function declaration not at top level.
7759: Storage classes other than `extern' are not allowed
7760: and `extern' makes no difference. */
7761: if (current_binding_level != global_binding_level
7762: && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
7763: && pedantic)
7764: warning ("invalid storage class for function `%s'", name);
7765:
7766: if (ctype == NULL_TREE)
7767: {
7768: if (virtualp)
7769: {
7770: error ("virtual non-class function `%s'", name);
7771: virtualp = 0;
7772: }
7773: if (current_lang_name == lang_name_cplusplus
7774: && ! (IDENTIFIER_LENGTH (original_name) == 4
7775: && IDENTIFIER_POINTER (original_name)[0] == 'm'
7776: && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
7777: && ! (IDENTIFIER_LENGTH (original_name) > 10
7778: && IDENTIFIER_POINTER (original_name)[0] == '_'
7779: && IDENTIFIER_POINTER (original_name)[1] == '_'
7780: && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
7781: {
7782: /* Plain overloading: will not be grok'd by grokclassfn. */
7783: declarator = build_decl_overload (name, TYPE_ARG_TYPES (type), 0);
7784: was_overloaded = 1;
7785: }
7786: }
7787: else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
7788: type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
7789: decl = grokfndecl (ctype, type, original_name, virtualp, flags, quals,
7790: raises,
7791: processing_template_decl ? 0 : friendp ? 2 : 1);
7792: if (ctype == NULL_TREE)
7793: DECL_ASSEMBLER_NAME (decl) = declarator;
7794: if (staticp == 1 && TREE_CODE (type) == METHOD_TYPE)
7795: {
7796: error_with_decl (decl, "cannot declare member function `%s' to have static linkage");
7797: staticp = 0;
7798: specbits &= ~(1 << (int)RID_STATIC);
7799: }
7800:
7801: /* Record presence of `static'. In C++, `inline' is like `static'. */
7802: TREE_PUBLIC (decl) = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)));
7803: /* Record presence of `inline', if it is reasonable. */
7804: if (inlinep)
7805: {
7806: tree last = tree_last (TYPE_ARG_TYPES (type));
7807:
7808: if (! was_overloaded
7809: && ! ctype
7810: && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
7811: warning ("cannot inline function `main'");
7812: else if (last && last != void_list_node)
7813: warning ("inline declaration ignored for function with `...'");
7814: else
7815: /* Assume that otherwise the function can be inlined. */
7816: TREE_INLINE (decl) = 1;
7817:
7818: if (specbits & (1 << (int) RID_EXTERN))
7819: current_extern_inline = 1;
7820: }
7821: if (was_overloaded)
7822: DECL_OVERLOADED (decl) = 1;
7823: }
7824: else
7825: {
7826: /* It's a variable. */
7827:
7828: if (virtualp)
7829: error ("variable declared `virtual'");
7830: if (inlinep)
7831: warning ("variable declared `inline'");
7832: if (quals)
7833: error ("`const' and `volatile' function specifiers invalid in field declaration");
7834: if (friendp)
7835: error ("invalid friend declaration");
7836: if (raises)
7837: error ("invalid raises declaration");
7838:
7839: /* An uninitialized decl with `extern' is a reference. */
7840: decl = grokvardecl (ctype, type, declarator, specbits, initialized);
7841: if (ctype && staticp == 1)
7842: {
7843: error ("cannot declare member `%s' to have static linkage",
7844: lang_printable_name (decl));
7845: staticp = 0;
7846: specbits &= ~(1 << (int)RID_STATIC);
7847: }
7848: }
7849:
7850: /* Record `register' declaration for warnings on &
7851: and in case doing stupid register allocation. */
7852:
7853: if (specbits & (1 << (int) RID_REGISTER))
7854: TREE_REGDECL (decl) = 1;
7855:
7856: /* Record constancy and volatility. */
7857:
7858: if (constp)
7859: TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
7860: if (volatilep)
7861: {
7862: TREE_SIDE_EFFECTS (decl) = 1;
7863: TREE_THIS_VOLATILE (decl) = 1;
7864: }
7865:
7866: return decl;
7867: }
7868: }
7869:
7870: /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
7871: An empty exprlist is a parmlist. An exprlist which
7872: contains only identifiers at the global level
7873: is a parmlist. Otherwise, it is an exprlist. */
7874: int
7875: parmlist_is_exprlist (exprs)
7876: tree exprs;
7877: {
7878: if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
7879: return 0;
7880:
7881: if (current_binding_level == global_binding_level)
7882: {
7883: /* At the global level, if these are all identifiers,
7884: then it is a parmlist. */
7885: while (exprs)
7886: {
7887: if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
7888: return 1;
7889: exprs = TREE_CHAIN (exprs);
7890: }
7891: return 0;
7892: }
7893: return 1;
7894: }
7895:
7896: /* Make sure that the this list of PARMS has a chance of being
7897: grokked by `grokparms'.
7898:
7899: @@ This is really weak, but the grammar does not allow us
7900: @@ to easily reject things that this has to catch as syntax errors. */
7901: static int
7902: parmlist_is_random (parms)
7903: tree parms;
7904: {
7905: if (parms == NULL_TREE)
7906: return 0;
7907:
7908: if (TREE_CODE (parms) != TREE_LIST)
7909: return 1;
7910:
7911: while (parms)
7912: {
7913: if (parms == void_list_node)
7914: return 0;
7915:
7916: if (TREE_CODE (TREE_VALUE (parms)) != TREE_LIST)
7917: return 1;
7918: /* Don't get faked out by overloaded functions, which
7919: masquerade as TREE_LISTs! */
7920: if (TREE_TYPE (TREE_VALUE (parms)) == unknown_type_node)
7921: return 1;
7922: parms = TREE_CHAIN (parms);
7923: }
7924: return 0;
7925: }
7926:
7927: /* Subroutine of `grokparms'. In a fcn definition, arg types must
7928: be complete.
7929:
7930: C++: also subroutine of `start_function'. */
7931: static void
7932: require_complete_types_for_parms (parms)
7933: tree parms;
7934: {
7935: while (parms)
7936: {
7937: tree type = TREE_TYPE (parms);
7938: if (TYPE_SIZE (type) == 0)
7939: {
7940: if (DECL_NAME (parms))
7941: error ("parameter `%s' has incomplete type",
7942: IDENTIFIER_POINTER (DECL_NAME (parms)));
7943: else
7944: error ("parameter has incomplete type");
7945: TREE_TYPE (parms) = error_mark_node;
7946: }
7947: #if 0
7948: /* If the arg types are incomplete in a declaration,
7949: they must include undefined tags.
7950: These tags can never be defined in the scope of the declaration,
7951: so the types can never be completed,
7952: and no call can be compiled successfully. */
7953: /* This is not the right behavior for C++, but not having
7954: it is also probably wrong. */
7955: else
7956: {
7957: /* Now warn if is a pointer to an incomplete type. */
7958: while (TREE_CODE (type) == POINTER_TYPE
7959: || TREE_CODE (type) == REFERENCE_TYPE)
7960: type = TREE_TYPE (type);
7961: type = TYPE_MAIN_VARIANT (type);
7962: if (TYPE_SIZE (type) == 0)
7963: {
7964: if (DECL_NAME (parm) != 0)
7965: warning ("parameter `%s' points to incomplete type",
7966: IDENTIFIER_POINTER (DECL_NAME (parm)));
7967: else
7968: warning ("parameter points to incomplete type");
7969: }
7970: }
7971: #endif
7972: parms = TREE_CHAIN (parms);
7973: }
7974: }
7975:
7976: /* Decode the list of parameter types for a function type.
7977: Given the list of things declared inside the parens,
7978: return a list of types.
7979:
7980: The list we receive can have three kinds of elements:
7981: an IDENTIFIER_NODE for names given without types,
7982: a TREE_LIST node for arguments given as typespecs or names with typespecs,
7983: or void_type_node, to mark the end of an argument list
7984: when additional arguments are not permitted (... was not used).
7985:
7986: FUNCDEF_FLAG is nonzero for a function definition, 0 for
7987: a mere declaration. A nonempty identifier-list gets an error message
7988: when FUNCDEF_FLAG is zero.
7989: If FUNCDEF_FLAG is 1, then parameter types must be complete.
7990: If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
7991:
7992: If all elements of the input list contain types,
7993: we return a list of the types.
7994: If all elements contain no type (except perhaps a void_type_node
7995: at the end), we return a null list.
7996: If some have types and some do not, it is an error, and we
7997: return a null list.
7998:
7999: Also set last_function_parms to either
8000: a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
8001: A list of names is converted to a chain of PARM_DECLs
8002: by store_parm_decls so that ultimately it is always a chain of decls.
8003:
8004: Note that in C++, paramters can take default values. These default
8005: values are in the TREE_PURPOSE field of the TREE_LIST. It is
8006: an error to specify default values which are followed by parameters
8007: that have no default values, or an ELLIPSES. For simplicities sake,
8008: only parameters which are specified with their types can take on
8009: default values. */
8010:
8011: static tree
8012: grokparms (first_parm, funcdef_flag)
8013: tree first_parm;
8014: int funcdef_flag;
8015: {
8016: tree result = NULL_TREE;
8017: tree decls = NULL_TREE;
8018:
8019: if (first_parm != 0
8020: && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
8021: {
8022: if (! funcdef_flag)
8023: warning ("parameter names (without types) in function declaration");
8024: last_function_parms = first_parm;
8025: return 0;
8026: }
8027: else
8028: {
8029: /* Types were specified. This is a list of declarators
8030: each represented as a TREE_LIST node. */
8031: register tree parm, chain;
8032: int any_init = 0, any_error = 0, saw_void = 0;
8033:
8034: if (first_parm != NULL_TREE)
8035: {
8036: tree last_result = NULL_TREE;
8037: tree last_decl = NULL_TREE;
8038:
8039: for (parm = first_parm; parm != NULL_TREE; parm = chain)
8040: {
8041: tree type, list_node = parm;
8042: register tree decl = TREE_VALUE (parm);
8043: tree init = TREE_PURPOSE (parm);
8044:
8045: chain = TREE_CHAIN (parm);
8046: /* @@ weak defense against parse errors. */
8047: if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
8048: {
8049: /* Give various messages as the need arises. */
8050: if (TREE_CODE (decl) == STRING_CST)
8051: error ("invalid string constant `%s'",
8052: TREE_STRING_POINTER (decl));
8053: else if (TREE_CODE (decl) == INTEGER_CST)
8054: error ("invalid integer constant in parameter list, did you forget to give parameter name?");
8055: continue;
8056: }
8057:
8058: if (decl != void_type_node)
8059: {
8060: /* @@ May need to fetch out a `raises' here. */
8061: decl = grokdeclarator (TREE_VALUE (decl),
8062: TREE_PURPOSE (decl),
8063: PARM, 0, NULL_TREE);
8064: if (! decl) continue;
8065: type = TREE_TYPE (decl);
8066: if (type == void_type_node)
8067: decl = void_type_node;
8068: else if (TREE_CODE (type) == METHOD_TYPE)
8069: {
8070: if (DECL_NAME (decl))
8071: /* Cannot use `error_with_decl' here because
8072: we don't have DECL_CONTEXT set up yet. */
8073: error ("parameter `%s' invalidly declared method type",
8074: IDENTIFIER_POINTER (DECL_NAME (decl)));
8075: else
8076: error ("parameter invalidly declared method type");
8077: type = build_pointer_type (type);
8078: TREE_TYPE (decl) = type;
8079: }
8080: else if (TREE_CODE (type) == OFFSET_TYPE)
8081: {
8082: if (DECL_NAME (decl))
8083: error ("parameter `%s' invalidly declared offset type",
8084: IDENTIFIER_POINTER (DECL_NAME (decl)));
8085: else
8086: error ("parameter invalidly declared offset type");
8087: type = build_pointer_type (type);
8088: TREE_TYPE (decl) = type;
8089: }
8090: else if (TREE_CODE (type) == RECORD_TYPE
8091: && TYPE_LANG_SPECIFIC (type)
8092: && CLASSTYPE_ABSTRACT_VIRTUALS (type))
8093: {
8094: abstract_virtuals_error (decl, type);
8095: any_error = 1; /* seems like a good idea */
8096: }
8097: }
8098:
8099: if (decl == void_type_node)
8100: {
8101: if (result == NULL_TREE)
8102: {
8103: result = void_list_node;
8104: last_result = result;
8105: }
8106: else
8107: {
8108: TREE_CHAIN (last_result) = void_list_node;
8109: last_result = void_list_node;
8110: }
8111: saw_void = 1;
8112: if (chain
8113: && (chain != void_list_node || TREE_CHAIN (chain)))
8114: error ("`void' in parameter list must be entire list");
8115: break;
8116: }
8117:
8118: /* Since there is a prototype, args are passed in their own types. */
8119: DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
8120: #ifdef PROMOTE_PROTOTYPES
8121: if (TREE_CODE (type) == INTEGER_TYPE
8122: && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
8123: DECL_ARG_TYPE (decl) = integer_type_node;
8124: #endif
8125: if (!any_error)
8126: {
8127: if (init)
8128: {
8129: any_init++;
8130: if (TREE_CODE (init) == SAVE_EXPR)
8131: PARM_DECL_EXPR (init) = 1;
8132: else
8133: init = require_instantiated_type (type, init, integer_zero_node);
8134: }
8135: else if (any_init)
8136: {
8137: error ("all trailing parameters must have default arguments");
8138: any_error = 1;
8139: }
8140: }
8141: else
8142: init = NULL_TREE;
8143:
8144: if (decls == NULL_TREE)
8145: {
8146: decls = decl;
8147: last_decl = decls;
8148: }
8149: else
8150: {
8151: TREE_CHAIN (last_decl) = decl;
8152: last_decl = decl;
8153: }
8154: if (TREE_PERMANENT (list_node))
8155: {
8156: TREE_PURPOSE (list_node) = init;
8157: TREE_VALUE (list_node) = type;
8158: TREE_CHAIN (list_node) = 0;
8159: }
8160: else
8161: list_node = saveable_tree_cons (init, type, NULL_TREE);
8162: if (result == NULL_TREE)
8163: {
8164: result = list_node;
8165: last_result = result;
8166: }
8167: else
8168: {
8169: TREE_CHAIN (last_result) = list_node;
8170: last_result = list_node;
8171: }
8172: }
8173: if (last_result)
8174: TREE_CHAIN (last_result) = NULL_TREE;
8175: /* If there are no parameters, and the function does not end
8176: with `...', then last_decl will be NULL_TREE. */
8177: if (last_decl != NULL_TREE)
8178: TREE_CHAIN (last_decl) = NULL_TREE;
8179: }
8180: }
8181:
8182: last_function_parms = decls;
8183:
8184: /* In a fcn definition, arg types must be complete. */
8185: if (funcdef_flag > 0)
8186: require_complete_types_for_parms (last_function_parms);
8187:
8188: return result;
8189: }
8190:
8191: /* These memoizing functions keep track of special properties which
8192: a class may have. `grok_ctor_properties' notices whether a class
8193: has a constructor of the for X(X&), and also complains
8194: if the class has a constructor of the form X(X).
8195: `grok_op_properties' takes notice of the various forms of
8196: operator= which are defined, as well as what sorts of type conversion
8197: may apply. Both functions take a FUNCTION_DECL as an argument. */
8198: void
8199: grok_ctor_properties (ctype, decl)
8200: tree ctype, decl;
8201: {
8202: tree parmtypes = FUNCTION_ARG_CHAIN (decl);
8203: tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
8204:
8205: if (TREE_CODE (parmtype) == REFERENCE_TYPE
8206: && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
8207: {
8208: if (TREE_CHAIN (parmtypes) == NULL_TREE
8209: || TREE_CHAIN (parmtypes) == void_list_node
8210: || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
8211: {
8212: TYPE_HAS_INIT_REF (ctype) = 1;
8213: TYPE_GETS_INIT_REF (ctype) = 1;
8214: if (TYPE_READONLY (TREE_TYPE (parmtype)))
8215: TYPE_GETS_CONST_INIT_REF (ctype) = 1;
8216: }
8217: else
8218: TYPE_GETS_INIT_AGGR (ctype) = 1;
8219: }
8220: else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
8221: {
8222: if (TREE_CHAIN (parmtypes) != NULL_TREE
8223: && TREE_CHAIN (parmtypes) == void_list_node)
8224: error ("invalid constructor; you probably meant `%s (%s&)'",
8225: TYPE_NAME_STRING (ctype),
8226: TYPE_NAME_STRING (ctype));
8227: SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
8228: TYPE_GETS_INIT_AGGR (ctype) = 1;
8229: }
8230: else if (TREE_CODE (parmtype) == VOID_TYPE
8231: || TREE_PURPOSE (parmtypes) != NULL_TREE)
8232: TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
8233: }
8234:
8235: static void
8236: grok_op_properties (decl)
8237: tree decl;
8238: {
8239: tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
8240:
8241: if (DECL_STATIC_FUNCTION_P (decl))
8242: {
8243: if (DECL_NAME (decl) == ansi_opname[NEW_EXPR])
8244: {
8245: /* Take care of function decl if we had syntax errors. */
8246: if (argtypes == NULL_TREE)
8247: TREE_TYPE (decl) = build_function_type (ptr_type_node,
8248: hash_tree_chain (integer_type_node, void_list_node));
8249: }
8250: else if (DECL_NAME (decl) == ansi_opname[DELETE_EXPR])
8251: {
8252: if (argtypes == NULL_TREE)
8253: TREE_TYPE (decl) = build_function_type (void_type_node,
8254: hash_tree_chain (ptr_type_node, void_list_node));
8255: }
8256: else
8257: error_with_decl (decl, "`%s' cannot be a static member function");
8258: }
8259: else if (DECL_NAME (decl) == ansi_opname[MODIFY_EXPR])
8260: {
8261: tree parmtypes = TREE_CHAIN (argtypes);
8262: tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
8263:
8264: if (TREE_CODE (parmtype) == REFERENCE_TYPE
8265: && TREE_TYPE (parmtype) == current_class_type)
8266: {
8267: TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
8268: TYPE_GETS_ASSIGN_REF (current_class_type) = 1;
8269: if (TYPE_READONLY (TREE_TYPE (parmtype)))
8270: TYPE_GETS_CONST_INIT_REF (current_class_type) = 1;
8271: }
8272: }
8273: }
8274:
8275: /* Get the struct, enum or union (CODE says which) with tag NAME.
8276: Define the tag as a forward-reference if it is not defined.
8277:
8278: C++: If a class derivation is given, process it here, and report
8279: an error if multiple derivation declarations are not identical.
8280:
8281: If this is a definition, come in through xref_tag and only look in
8282: the current frame for the name (since C++ allows new names in any
8283: scope.)
8284:
8285: If we are compiling for SOS, then
8286: if CODE_TYPE_NODE is a TREE_LIST, then we have a dynamic class
8287: declaration. The name associated with the class is the tree
8288: purpose, and the real CODE is in the tree value slot. */
8289: /* avoid rewriting all callers of xref_tag */
8290: static int xref_next_defn = 0;
8291:
8292: tree
8293: xref_defn_tag (code_type_node, name, binfo)
8294: tree code_type_node;
8295: tree name, binfo;
8296: {
8297: tree rv, ncp;
8298: xref_next_defn = 1;
8299:
8300: if (class_binding_level)
8301: {
8302: tree n1;
8303: char *buf;
8304: /* we need to build a new IDENTIFIER_NODE for name which nukes
8305: * the pieces... */
8306: n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
8307: if (n1)
8308: n1 = DECL_NAME (n1);
8309: else
8310: n1 = current_class_name;
8311:
8312: buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1)
8313: + IDENTIFIER_LENGTH (name));
8314:
8315: sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1),
8316: IDENTIFIER_POINTER (name));
8317: ncp = get_identifier (buf);
8318: #ifdef SPEW_DEBUG
8319: printf("*** %s ***\n", IDENTIFIER_POINTER (ncp));
8320: #endif
8321: #if 0
8322: IDENTIFIER_LOCAL_VALUE (name) =
8323: build_lang_decl (TYPE_DECL, ncp, NULL_TREE);
8324: #endif
8325: rv = xref_tag (code_type_node, name, binfo);
8326: pushdecl_top_level (build_lang_decl (TYPE_DECL, ncp, rv));
8327: }
8328: else
8329: {
8330: rv = xref_tag (code_type_node, name, binfo);
8331: }
8332: xref_next_defn = 0;
8333: return rv;
8334: }
8335:
8336: tree
8337: xref_tag (code_type_node, name, binfo)
8338: tree code_type_node;
8339: tree name, binfo;
8340: {
8341: enum tag_types tag_code;
8342: enum tree_code code;
8343: int temp = 0;
8344: int i, len;
8345: register tree ref;
8346: struct binding_level *b
8347: = (class_binding_level ? class_binding_level : current_binding_level);
8348: #ifdef SOS
8349: tree dynamic_name = error_mark_node;
8350: if (TREE_CODE (code_type_node) == TREE_LIST)
8351: {
8352: dynamic_name = TREE_PURPOSE (code_type_node);
8353: code_type_node = TREE_VALUE (code_type_node);
8354: }
8355: #endif
8356:
8357: tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
8358: switch (tag_code)
8359: {
8360: case record_type:
8361: case class_type:
8362: case exception_type:
8363: code = RECORD_TYPE;
8364: len = list_length (binfo);
8365: break;
8366: case union_type:
8367: code = UNION_TYPE;
8368: if (binfo)
8369: {
8370: error ("derived union `%s' invalid", IDENTIFIER_POINTER (name));
8371: binfo = NULL_TREE;
8372: }
8373: len = 0;
8374: break;
8375: case enum_type:
8376: code = ENUMERAL_TYPE;
8377: break;
8378: default:
8379: abort ();
8380: }
8381:
8382: /* If a cross reference is requested, look up the type
8383: already defined for this tag and return it. */
8384: if (xref_next_defn)
8385: {
8386: /* If we know we are defining this tag, only look it up in this scope
8387: * and don't try to find it as a type. */
8388: xref_next_defn = 0;
8389: ref = lookup_tag (code, name, b, 1);
8390: }
8391: else
8392: {
8393: ref = lookup_tag (code, name, b, 0);
8394:
8395: if (! ref)
8396: {
8397: /* Try finding it as a type declaration. If that wins, use it. */
8398: ref = lookup_name (name, 1);
8399: if (ref && TREE_CODE (ref) == TYPE_DECL
8400: && TREE_CODE (TREE_TYPE (ref)) == code)
8401: ref = TREE_TYPE (ref);
8402: else
8403: ref = NULL_TREE;
8404: }
8405: }
8406:
8407: push_obstacks_nochange ();
8408:
8409: if (! ref)
8410: {
8411: /* If no such tag is yet defined, create a forward-reference node
8412: and record it as the "definition".
8413: When a real declaration of this type is found,
8414: the forward-reference will be altered into a real type. */
8415:
8416: /* In C++, since these migrate into the global scope, we must
8417: build them on the permanent obstack. */
8418:
8419: temp = allocation_temporary_p ();
8420: if (temp)
8421: end_temporary_allocation ();
8422:
8423: if (code == ENUMERAL_TYPE)
8424: {
8425: ref = make_node (ENUMERAL_TYPE);
8426:
8427: /* Give the type a default layout like unsigned int
8428: to avoid crashing if it does not get defined. */
8429: TYPE_MODE (ref) = SImode;
8430: TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
8431: TREE_UNSIGNED (ref) = 1;
8432: TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
8433: TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
8434: TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
8435:
8436: /* Enable us to recognize when a type is created in class context.
8437: To do nested classes correctly, this should probably be cleared
8438: out when we leave this classes scope. Currently this in only
8439: done in `start_enum'. */
8440:
8441: pushtag (name, ref);
8442: if (flag_cadillac)
8443: cadillac_start_enum (ref);
8444: }
8445: else if (tag_code == exception_type)
8446: {
8447: ref = make_lang_type (code);
8448: /* Enable us to recognize when an exception type is created in
8449: class context. To do nested classes correctly, this should
8450: probably be cleared out when we leave this class's scope. */
8451: CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
8452: pushtag (name, ref);
8453: if (flag_cadillac)
8454: cadillac_start_struct (ref);
8455: }
8456: else
8457: {
8458: extern tree pending_vtables;
8459: struct binding_level *old_b = class_binding_level;
8460: int needs_writing;
8461:
8462: ref = make_lang_type (code);
8463:
8464: /* Record how to set the visibility of this class's
8465: virtual functions. If write_virtuals == 2 or 3, then
8466: inline virtuals are ``extern inline''. */
8467: switch (write_virtuals)
8468: {
8469: case 0:
8470: case 1:
8471: needs_writing = 1;
8472: break;
8473: case 2:
8474: needs_writing = !! value_member (name, pending_vtables);
8475: break;
8476: case 3:
8477: needs_writing
8478: = ! (CLASSTYPE_INTERFACE_ONLY (ref) || CLASSTYPE_INTERFACE_UNKNOWN (ref));
8479: break;
8480: default:
8481: needs_writing = 0;
8482: }
8483:
8484: CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing;
8485:
8486: #ifdef NONNESTED_CLASSES
8487: /* Class types don't nest the way enums do. */
8488: class_binding_level = 0;
8489: #endif
8490: pushtag (name, ref);
8491: class_binding_level = old_b;
8492:
8493: if (flag_cadillac)
8494: cadillac_start_struct (ref);
8495: }
8496: }
8497: else
8498: {
8499: if (IS_AGGR_TYPE_CODE (code))
8500: {
8501: if (IS_AGGR_TYPE (ref)
8502: && ((tag_code == exception_type)
8503: != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
8504: {
8505: error ("type `%s' is both exception and aggregate type",
8506: IDENTIFIER_POINTER (name));
8507: CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
8508: }
8509: }
8510:
8511: /* If it no longer looks like a nested type, make sure it's
8512: in global scope. */
8513: if (b == global_binding_level && !class_binding_level
8514: && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
8515: IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
8516:
8517: if (binfo)
8518: {
8519: tree tt1 = binfo;
8520: tree tt2 = TYPE_BINFO_BASETYPES (ref);
8521:
8522: if (TYPE_BINFO_BASETYPES (ref))
8523: for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
8524: if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
8525: {
8526: error ("redeclaration of derivation chain of type `%s'",
8527: IDENTIFIER_POINTER (name));
8528: break;
8529: }
8530:
8531: if (tt1 == NULL_TREE)
8532: /* The user told us something we already knew. */
8533: goto just_return;
8534:
8535: /* In C++, since these migrate into the global scope, we must
8536: build them on the permanent obstack. */
8537: end_temporary_allocation ();
8538: }
8539: #ifdef SOS
8540: else if (TREE_CODE (ref) != ENUMERAL_TYPE
8541: && (dynamic_name != error_mark_node) != TYPE_DYNAMIC (ref))
8542: error ("type `%s' declared both dynamic and non-dynamic",
8543: IDENTIFIER_POINTER (name));
8544: #endif
8545: }
8546:
8547: if (binfo)
8548: {
8549: /* In the declaration `A : X, Y, ... Z' we mark all the types
8550: (A, X, Y, ..., Z) so we can check for duplicates. */
8551: tree binfos;
8552:
8553: SET_CLASSTYPE_MARKED (ref);
8554: BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
8555:
8556: for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
8557: {
8558: /* The base of a derived struct is public. */
8559: int via_public = (tag_code != class_type
8560: || TREE_PURPOSE (binfo) == (tree)visibility_public
8561: || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual);
8562: int via_virtual = (TREE_PURPOSE (binfo) == (tree)visibility_private_virtual
8563: || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual
8564: || TREE_PURPOSE (binfo) == (tree)visibility_default_virtual);
8565: tree basetype = TREE_TYPE (TREE_VALUE (binfo));
8566: tree child;
8567:
8568: GNU_xref_hier (IDENTIFIER_POINTER (name),
8569: IDENTIFIER_POINTER (TREE_VALUE (binfo)),
8570: via_public, via_virtual, 0);
8571:
8572: if (basetype && TREE_CODE (basetype) == TYPE_DECL)
8573: basetype = TREE_TYPE (basetype);
8574: if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
8575: {
8576: error ("base type `%s' fails to be a struct or class type",
8577: IDENTIFIER_POINTER (TREE_VALUE (binfo)));
8578: continue;
8579: }
8580: #if 0
8581: else if (TYPE_SIZE (basetype) == 0)
8582: {
8583: error_with_aggr_type (basetype, "base class `%s' has incomplete type");
8584: continue;
8585: }
8586: #endif
8587: else
8588: {
8589: #ifdef SOS
8590: if (dynamic_name == error_mark_node && TYPE_DYNAMIC (basetype))
8591: error_with_aggr_type (ref, "non-dynamic type `%s' cannot derive from dynamic type `%s'", TYPE_NAME_STRING (basetype));
8592: #endif
8593: if (CLASSTYPE_MARKED (basetype))
8594: {
8595: if (basetype == ref)
8596: error_with_aggr_type (basetype, "recursive type `%s' undefined");
8597: else
8598: error_with_aggr_type (basetype, "duplicate base type `%s' invalid");
8599: continue;
8600: }
8601:
8602: /* Note that virtual baseclasses are shared in the lattice! */
8603: if (via_virtual)
8604: {
8605: child = CLASSTYPE_VBINFO (basetype, via_public);
8606: if (child == NULL_TREE)
8607: {
8608: CLASSTYPE_VBINFO (basetype, via_public) = child
8609: = make_binfo (integer_zero_node, basetype,
8610: TYPE_BINFO_VTABLE (basetype),
8611: TYPE_BINFO_VIRTUALS (basetype), 0);
8612: }
8613: }
8614: else
8615: child = make_binfo (integer_zero_node, basetype,
8616: TYPE_BINFO_VTABLE (basetype),
8617: TYPE_BINFO_VIRTUALS (basetype), 0);
8618:
8619: TREE_VEC_ELT (binfos, i) = child;
8620: TREE_VIA_PUBLIC (child) = via_public;
8621: TREE_VIA_VIRTUAL (child) = via_virtual;
8622:
8623: SET_CLASSTYPE_MARKED (basetype);
8624: #if 0
8625: /* XYZZY TEST VIRTUAL BASECLASSES */
8626: if (CLASSTYPE_N_BASECLASSES (basetype) == 0
8627: && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
8628: && via_virtual == 0)
8629: {
8630: warning ("making type `%s' a virtual baseclass",
8631: TYPE_NAME_STRING (basetype));
8632: via_virtual = 1;
8633: }
8634: #endif
8635: /* We are free to modify these bits because they are meaningless
8636: at top level, and BASETYPE is a top-level type. */
8637: if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
8638: {
8639: TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
8640: TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
8641: }
8642:
8643: TYPE_GETS_ASSIGNMENT (ref) |= TYPE_GETS_ASSIGNMENT (basetype);
8644: TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
8645: TYPE_HAS_WRAPPER_PRED (ref) |= TYPE_HAS_WRAPPER_PRED (basetype);
8646: TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype);
8647: TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype);
8648: CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
8649: i += 1;
8650: }
8651: }
8652: if (i)
8653: TREE_VEC_LENGTH (binfos) = i;
8654: else
8655: BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
8656:
8657: if (i > 1)
8658: TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
8659: else if (i == 1)
8660: TYPE_USES_MULTIPLE_INHERITANCE (ref)
8661: = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
8662: if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
8663: TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
8664:
8665: /* Unmark all the types. */
8666: while (--i >= 0)
8667: CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
8668: CLEAR_CLASSTYPE_MARKED (ref);
8669: }
8670:
8671: just_return:
8672:
8673: #ifdef SOS
8674: if (dynamic_name != error_mark_node)
8675: {
8676: if (temp == 0)
8677: temp = allocation_temporary_p ();
8678: if (temp)
8679: end_temporary_allocation ();
8680:
8681: if (dynamic_name)
8682: CLASSTYPE_DYNAMIC_FILENAME (ref) = combine_strings (dynamic_name);
8683: else
8684: CLASSTYPE_DYNAMIC_FILENAME (ref) = NULL_TREE;
8685: TYPE_DYNAMIC (ref) = 1;
8686: CLASSTYPE_TYPENAME_AS_STRING (ref) = combine_strings (build_string (IDENTIFIER_LENGTH (name), IDENTIFIER_POINTER (name)));
8687:
8688: }
8689: #endif
8690:
8691: /* Until the type is defined, tentatively accept whatever
8692: structure tag the user hands us. */
8693: if (TYPE_SIZE (ref) == NULL_TREE
8694: && ref != current_class_type
8695: /* Have to check this, in case we have contradictory tag info. */
8696: && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
8697: {
8698: if (tag_code == class_type)
8699: CLASSTYPE_DECLARED_CLASS (ref) = 1;
8700: else if (tag_code == record_type)
8701: CLASSTYPE_DECLARED_CLASS (ref) = 0;
8702: }
8703:
8704: pop_obstacks ();
8705:
8706: return ref;
8707: }
8708:
8709: /* Begin compiling the definition of an enumeration type.
8710: NAME is its name (or null if anonymous).
8711: Returns the type object, as yet incomplete.
8712: Also records info about it so that build_enumerator
8713: may be used to declare the individual values as they are read. */
8714:
8715: tree
8716: start_enum (name)
8717: tree name;
8718: {
8719: register tree enumtype = 0;
8720: struct binding_level *b
8721: = (class_binding_level ? class_binding_level : current_binding_level);
8722:
8723: /* If this is the real definition for a previous forward reference,
8724: fill in the contents in the same object that used to be the
8725: forward reference. */
8726:
8727: if (name != 0)
8728: enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
8729:
8730: if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
8731: {
8732: enumtype = make_node (ENUMERAL_TYPE);
8733: pushtag (name, enumtype);
8734: }
8735:
8736: if (TYPE_VALUES (enumtype) != 0)
8737: {
8738: /* This enum is a named one that has been declared already. */
8739: error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
8740:
8741: /* Completely replace its old definition.
8742: The old enumerators remain defined, however. */
8743: TYPE_VALUES (enumtype) = 0;
8744: }
8745:
8746: /* Initially, set up this enum as like `int'
8747: so that we can create the enumerators' declarations and values.
8748: Later on, the precision of the type may be changed and
8749: it may be laid out again. */
8750:
8751: TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
8752: TYPE_SIZE (enumtype) = 0;
8753: fixup_unsigned_type (enumtype);
8754:
8755: /* We copy this value because enumerated type constants
8756: are really of the type of the enumerator, not integer_type_node. */
8757: enum_next_value = copy_node (integer_zero_node);
8758:
8759: GNU_xref_decl (current_function_decl, enumtype);
8760: return enumtype;
8761: }
8762:
8763: /* After processing and defining all the values of an enumeration type,
8764: install their decls in the enumeration type and finish it off.
8765: ENUMTYPE is the type object and VALUES a list of name-value pairs.
8766: Returns ENUMTYPE. */
8767:
8768: tree
8769: finish_enum (enumtype, values)
8770: register tree enumtype, values;
8771: {
8772: register tree pair;
8773: register long maxvalue = 0;
8774: register long minvalue = 0;
8775: register int i;
8776:
8777: TYPE_VALUES (enumtype) = values;
8778:
8779: /* Calculate the maximum value of any enumerator in this type. */
8780:
8781: if (values)
8782: {
8783: /* Speed up the main loop by performing some precalculations */
8784:
8785: int value = TREE_INT_CST_LOW (TREE_VALUE (values));
8786: TREE_TYPE (TREE_VALUE (values)) = enumtype;
8787: minvalue = maxvalue = value;
8788:
8789: for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
8790: {
8791: value = TREE_INT_CST_LOW (TREE_VALUE (pair));
8792: if (value > maxvalue)
8793: maxvalue = value;
8794: else if (value < minvalue)
8795: minvalue = value;
8796: TREE_TYPE (TREE_VALUE (pair)) = enumtype;
8797: }
8798: }
8799:
8800: if (flag_short_enums)
8801: {
8802: /* Determine the precision this type needs, lay it out, and define it. */
8803:
8804: for (i = maxvalue; i; i >>= 1)
8805: TYPE_PRECISION (enumtype)++;
8806:
8807: if (!TYPE_PRECISION (enumtype))
8808: TYPE_PRECISION (enumtype) = 1;
8809:
8810: /* Cancel the laying out previously done for the enum type,
8811: so that fixup_unsigned_type will do it over. */
8812: TYPE_SIZE (enumtype) = 0;
8813:
8814: fixup_unsigned_type (enumtype);
8815: }
8816:
8817: TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
8818:
8819: /* An enum can have some negative values; then it is signed. */
8820: if (minvalue < 0)
8821: {
8822: TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
8823: TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
8824: TREE_UNSIGNED (enumtype) = 0;
8825: }
8826: if (flag_cadillac)
8827: cadillac_finish_enum (enumtype);
8828:
8829: /* Finish debugging output for this type. */
8830: if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
8831: rest_of_type_compilation (enumtype, global_bindings_p ());
8832:
8833: return enumtype;
8834: }
8835:
8836: /* Build and install a CONST_DECL for one value of the
8837: current enumeration type (one that was begun with start_enum).
8838: Return a tree-list containing the name and its value.
8839: Assignment of sequential values by default is handled here. */
8840:
8841: tree
8842: build_enumerator (name, value)
8843: tree name, value;
8844: {
8845: tree decl, result;
8846: /* Change this to zero if we find VALUE is not shareable. */
8847: int shareable = 1;
8848:
8849: /* Validate and default VALUE. */
8850: if (value != 0)
8851: {
8852: if (TREE_READONLY_DECL_P (value))
8853: {
8854: value = decl_constant_value (value);
8855: shareable = 0;
8856: }
8857:
8858: if (TREE_CODE (value) != INTEGER_CST)
8859: {
8860: error ("enumerator value for `%s' not integer constant",
8861: IDENTIFIER_POINTER (name));
8862: value = 0;
8863: }
8864: }
8865: /* The order of things is reversed here so that we
8866: can check for possible sharing of enum values,
8867: to keep that from happening. */
8868: /* Default based on previous value. */
8869: if (value == 0)
8870: value = enum_next_value;
8871:
8872: /* Remove no-op casts from the value. */
8873: while (value != 0 && TREE_CODE (value) == NOP_EXPR)
8874: {
8875: value = TREE_OPERAND (value, 0);
8876: shareable = 0;
8877: }
8878:
8879: /* Make up for hacks in cp-lex.c. */
8880: if (value == integer_zero_node)
8881: value = build_int_2 (0, 0);
8882: else if (value == integer_one_node)
8883: value = build_int_2 (1, 0);
8884: else if (TREE_CODE (value) == INTEGER_CST
8885: && (shareable == 0
8886: || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
8887: {
8888: value = copy_node (value);
8889: TREE_TYPE (value) = integer_type_node;
8890: }
8891:
8892: result = saveable_tree_cons (name, value, NULL_TREE);
8893:
8894: /* C++ associates enums with global, function, or class declarations. */
8895: if (current_class_type == NULL_TREE || current_function_decl != NULL_TREE)
8896: {
8897: /* Create a declaration for the enum value name. */
8898:
8899: decl = build_decl (CONST_DECL, name, integer_type_node);
8900: DECL_INITIAL (decl) = value;
8901:
8902: pushdecl (decl);
8903: GNU_xref_decl (current_function_decl, decl);
8904: }
8905:
8906: /* Set basis for default for next value. */
8907: enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
8908: integer_one_node, PLUS_EXPR);
8909: if (enum_next_value == integer_one_node)
8910: enum_next_value = copy_node (enum_next_value);
8911:
8912: return result;
8913: }
8914:
8915: tree
8916: grok_enum_decls (type, decl)
8917: tree type, decl;
8918: {
8919: struct binding_level *b = class_binding_level;
8920: tree tag = NULL_TREE;
8921: tree values;
8922:
8923: while (b)
8924: {
8925: tag = value_member (type, b->tags);
8926: if (tag)
8927: break;
8928: b = b->level_chain;
8929: }
8930:
8931: if (b == 0)
8932: {
8933: tree name = TYPE_NAME (type);
8934: if (TREE_CODE (name) == TYPE_DECL)
8935: name = DECL_NAME (name);
8936: error ("class-local enum declaration `%s' is not in scope here",
8937: IDENTIFIER_POINTER (name));
8938: }
8939: else if (b != class_binding_level)
8940: {
8941: #if 0 /* This is nothing we should warn about. */
8942: warning ("class-local declaration for enumeral type `%s' found",
8943: IDENTIFIER_POINTER (TREE_PURPOSE (tag)));
8944: warning ("(probably missing '}' before that enum declaration)");
8945: #endif
8946: return decl;
8947: }
8948: else if (TREE_ADDRESSABLE (tag))
8949: return decl;
8950: else
8951: TREE_ADDRESSABLE (tag) = 1;
8952:
8953: values = TYPE_VALUES (type);
8954: while (values)
8955: {
8956: /* Create a declaration for the enum value name. */
8957: tree next = build_lang_field_decl (CONST_DECL, TREE_PURPOSE (values), type);
8958: DECL_INITIAL (next) = TREE_VALUE (values);
8959: TREE_CHAIN (next) = decl;
8960: decl = next;
8961: pushdecl_class_level (decl);
8962: values = TREE_CHAIN (values);
8963: }
8964: return decl;
8965: }
8966:
8967: /* Create the FUNCTION_DECL for a function definition.
8968: DECLSPECS and DECLARATOR are the parts of the declaration;
8969: they describe the function's name and the type it returns,
8970: but twisted together in a fashion that parallels the syntax of C.
8971:
8972: This function creates a binding context for the function body
8973: as well as setting up the FUNCTION_DECL in current_function_decl.
8974:
8975: Returns 1 on success. If the DECLARATOR is not suitable for a function
8976: (it defines a datum instead), we return 0, which tells
8977: yyparse to report a parse error.
8978:
8979: For C++, we must first check whether that datum makes any sense.
8980: For example, "class A local_a(1,2);" means that variable local
8981: a is an aggregate of type A, which should have a constructor
8982: applied to it with the argument list [1, 2].
8983:
8984: @@ There is currently no way to retrieve the storage
8985: @@ allocated to FUNCTION (or all of its parms) if we return
8986: @@ something we had previously. */
8987:
8988: int
8989: start_function (declspecs, declarator, raises, pre_parsed_p)
8990: tree declarator, declspecs, raises;
8991: int pre_parsed_p;
8992: {
8993: extern tree EHS_decl;
8994: tree decl1, olddecl;
8995: tree ctype = NULL_TREE;
8996: tree fntype;
8997: tree restype;
8998:
8999: if (flag_handle_exceptions && EHS_decl == NULL_TREE)
9000: init_exception_processing_1 ();
9001:
9002: /* Sanity check. */
9003: assert (TREE_VALUE (void_list_node) == void_type_node);
9004: assert (TREE_CHAIN (void_list_node) == NULL_TREE);
9005:
9006: /* Assume, until we see it does. */
9007: current_function_returns_value = 0;
9008: current_function_returns_null = 0;
9009: warn_about_return_type = 0;
9010: current_extern_inline = 0;
9011: current_function_assigns_this = 0;
9012: current_function_just_assigned_this = 0;
9013: current_function_parms_stored = 0;
9014: original_result_rtx = 0;
9015: current_function_obstack_index = 0;
9016: current_function_obstack_usage = 0;
9017:
9018: clear_temp_name ();
9019:
9020: if (pre_parsed_p)
9021: {
9022: decl1 = declarator;
9023: last_function_parms = DECL_ARGUMENTS (decl1);
9024: last_function_parm_tags = 0;
9025: fntype = TREE_TYPE (decl1);
9026: if (TREE_CODE (fntype) == METHOD_TYPE)
9027: ctype = TYPE_METHOD_BASETYPE (fntype);
9028:
9029: if ( !(DECL_VINDEX (decl1)
9030: && write_virtuals >= 2
9031: && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
9032: current_extern_inline = TREE_PUBLIC (decl1) && TREE_INLINE (decl1);
9033:
9034: raises = TYPE_RAISES_EXCEPTIONS (fntype);
9035:
9036: /* In a fcn definition, arg types must be complete. */
9037: require_complete_types_for_parms (last_function_parms);
9038: }
9039: else
9040: {
9041: decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
9042: /* If the declarator is not suitable for a function definition,
9043: cause a syntax error. */
9044: if (decl1 == 0 || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
9045:
9046: fntype = TREE_TYPE (decl1);
9047:
9048: restype = TREE_TYPE (fntype);
9049: if (IS_AGGR_TYPE (restype)
9050: && ! CLASSTYPE_GOT_SEMICOLON (restype))
9051: {
9052: error_with_aggr_type (restype, "semicolon missing after declaration of `%s'");
9053: shadow_tag (build_tree_list (NULL_TREE, restype));
9054: CLASSTYPE_GOT_SEMICOLON (restype) = 1;
9055: if (TREE_CODE (fntype) == FUNCTION_TYPE)
9056: fntype = build_function_type (integer_type_node,
9057: TYPE_ARG_TYPES (fntype));
9058: else
9059: fntype = build_cplus_method_type (TYPE_METHOD_BASETYPE (fntype),
9060: integer_type_node,
9061: TYPE_ARG_TYPES (fntype));
9062: TREE_TYPE (decl1) = fntype;
9063: }
9064:
9065: if (TREE_CODE (fntype) == METHOD_TYPE)
9066: ctype = TYPE_METHOD_BASETYPE (fntype);
9067: else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
9068: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
9069: && DECL_CONTEXT (decl1) == NULL_TREE)
9070: {
9071: /* If this doesn't return an integer type, complain. */
9072: if (TREE_CODE (TREE_TYPE (fntype)) != INTEGER_TYPE)
9073: {
9074: #if 0
9075: error ("return type for `main' must be integer type");
9076: #else
9077: warning ("return type for `main' changed to integer type");
9078: #endif
9079: TREE_TYPE (decl1) = fntype = default_function_type;
9080: }
9081: warn_about_return_type = 0;
9082: }
9083: }
9084:
9085: /* Warn if function was previously implicitly declared
9086: (but not if we warned then). */
9087: if (! warn_implicit && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != 0)
9088: warning_with_decl (IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)),
9089: "`%s' implicitly declared before its definition");
9090:
9091: current_function_decl = decl1;
9092:
9093: if (flag_cadillac)
9094: cadillac_start_function (decl1);
9095: else
9096: announce_function (decl1);
9097:
9098: if (TYPE_SIZE (TREE_TYPE (fntype)) == 0)
9099: {
9100: if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
9101: error_with_aggr_type (TREE_TYPE (fntype),
9102: "return-type `%s' is an incomplete type");
9103: else
9104: error ("return-type is an incomplete type");
9105:
9106: /* Make it return void instead, but don't change the
9107: type of the DECL_RESULT, in case we have a named return value. */
9108: if (ctype)
9109: TREE_TYPE (decl1)
9110: = build_cplus_method_type (ctype,
9111: void_type_node,
9112: FUNCTION_ARG_CHAIN (decl1));
9113: else
9114: TREE_TYPE (decl1)
9115: = build_function_type (void_type_node,
9116: TYPE_ARG_TYPES (TREE_TYPE (decl1)));
9117: DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype));
9118: }
9119:
9120: if (warn_about_return_type)
9121: warning ("return-type defaults to `int'");
9122:
9123: /* Make the init_value nonzero so pushdecl knows this is not tentative.
9124: error_mark_node is replaced below (in poplevel) with the BLOCK. */
9125: DECL_INITIAL (decl1) = error_mark_node;
9126:
9127: /* Didn't get anything from C. */
9128: olddecl = 0;
9129:
9130: /* This function exists in static storage.
9131: (This does not mean `static' in the C sense!) */
9132: TREE_STATIC (decl1) = 1;
9133:
9134: /* If this function belongs to the implementation, make it public.
9135: If it belongs to somebody else's interface, make it non-public.
9136: It doesn't matter whether it's inline or not. */
9137: if (interface_unknown == 0)
9138: {
9139: TREE_PUBLIC (decl1) = ! interface_only;
9140: TREE_EXTERNAL (decl1) = interface_only;
9141: }
9142: else
9143: /* This is a definition, not a reference.
9144: So normally clear TREE_EXTERNAL.
9145: However, `extern inline' acts like a declaration except for
9146: defining how to inline. So set TREE_EXTERNAL in that case. */
9147: TREE_EXTERNAL (decl1) = current_extern_inline;
9148:
9149: /* Now see if this is the implementation of a function
9150: declared with "C" linkage. */
9151: if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus)
9152: {
9153: olddecl = lookup_name_current_level (DECL_NAME (decl1));
9154: if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL)
9155: olddecl = NULL_TREE;
9156: if (olddecl && DECL_NAME (decl1) != DECL_NAME (olddecl))
9157: {
9158: /* Collision between user and internal naming scheme. */
9159: olddecl = lookup_name_current_level (DECL_ASSEMBLER_NAME (decl1));
9160: if (olddecl == NULL_TREE)
9161: olddecl = decl1;
9162: }
9163: if (olddecl && olddecl != decl1
9164: && DECL_NAME (decl1) == DECL_NAME (olddecl))
9165: {
9166: if (TREE_CODE (olddecl) == FUNCTION_DECL
9167: && (decls_match (decl1, olddecl)
9168: || comp_target_parms (TYPE_ARG_TYPES (TREE_TYPE (decl1)),
9169: TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 1)))
9170: {
9171: olddecl = DECL_MAIN_VARIANT (olddecl);
9172: /* The following copy is needed to handle forcing a function's
9173: linkage to obey the linkage of the original decl. */
9174: DECL_ASSEMBLER_NAME (decl1) = DECL_ASSEMBLER_NAME (olddecl);
9175: DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl);
9176: if (DECL_INITIAL (olddecl))
9177: redeclaration_error_message (decl1, olddecl);
9178: if (! duplicate_decls (decl1, olddecl))
9179: abort ();
9180: decl1 = olddecl;
9181: }
9182: else
9183: olddecl = NULL_TREE;
9184: }
9185: }
9186:
9187: /* Record the decl so that the function name is defined.
9188: If we already have a decl for this name, and it is a FUNCTION_DECL,
9189: use the old decl. */
9190:
9191: if (olddecl)
9192: current_function_decl = olddecl;
9193: else if (pre_parsed_p == 0)
9194: {
9195: current_function_decl = pushdecl (decl1);
9196: if (TREE_CODE (current_function_decl) == TREE_LIST)
9197: {
9198: /* @@ revert to modified original declaration. */
9199: decl1 = DECL_MAIN_VARIANT (decl1);
9200: current_function_decl = decl1;
9201: }
9202: else
9203: {
9204: decl1 = current_function_decl;
9205: DECL_MAIN_VARIANT (decl1) = decl1;
9206: }
9207: fntype = TREE_TYPE (decl1);
9208: }
9209: else
9210: current_function_decl = decl1;
9211:
9212: if (DECL_OVERLOADED (decl1))
9213: decl1 = push_overloaded_decl (decl1, 1);
9214:
9215: if (ctype != 0 && DECL_STATIC_FUNCTION_P (decl1))
9216: {
9217: if (TREE_CODE (fntype) == METHOD_TYPE)
9218: TREE_TYPE (decl1) = fntype
9219: = build_function_type (TREE_TYPE (fntype),
9220: TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
9221: last_function_parms = TREE_CHAIN (last_function_parms);
9222: DECL_ARGUMENTS (decl1) = last_function_parms;
9223: ctype = 0;
9224: }
9225: restype = TREE_TYPE (fntype);
9226:
9227: pushlevel (0);
9228: current_binding_level->parm_flag = 1;
9229:
9230: /* Save the parm names or decls from this function's declarator
9231: where store_parm_decls will find them. */
9232: current_function_parms = last_function_parms;
9233: current_function_parm_tags = last_function_parm_tags;
9234:
9235: GNU_xref_function (decl1, current_function_parms);
9236:
9237: make_function_rtl (decl1);
9238:
9239: if (ctype)
9240: {
9241: pushclass (ctype, 1);
9242: /* We know that this was set up by `grokclassfn'.
9243: We do not wait until `store_parm_decls', since evil
9244: parse errors may never get us to that point. Here
9245: we keep the consistency between `current_class_type'
9246: and `current_class_decl'. */
9247: current_class_decl = last_function_parms;
9248: assert (TREE_CODE (current_class_decl) == PARM_DECL);
9249: if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
9250: {
9251: tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
9252: if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
9253: {
9254: /* Can't call build_indirect_ref here, because it has special
9255: logic to return C_C_D given this argument. */
9256: C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
9257: CLASSTYPE_INST_VAR (ctype) = C_C_D;
9258: }
9259: else
9260: {
9261: C_C_D = CLASSTYPE_INST_VAR (ctype);
9262: /* `current_class_decl' is different for every
9263: function we compile. */
9264: TREE_OPERAND (C_C_D, 0) = current_class_decl;
9265: }
9266: TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
9267: TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
9268: TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
9269: }
9270: else
9271: C_C_D = current_class_decl;
9272: }
9273: else
9274: {
9275: if (DECL_STATIC_FUNCTION_P (decl1))
9276: pushclass (DECL_CONTEXT (decl1), 2);
9277: else
9278: push_memoized_context (0, 1);
9279: }
9280:
9281: /* Allocate further tree nodes temporarily during compilation
9282: of this function only. Tiemann moved up here from bottom of fn. */
9283: temporary_allocation ();
9284:
9285: /* Promote the value to int before returning it. */
9286: if (TREE_CODE (restype) == INTEGER_TYPE
9287: && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
9288: restype = integer_type_node;
9289: if (DECL_RESULT (decl1) == NULL_TREE)
9290: DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype);
9291:
9292: if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)))
9293: {
9294: dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
9295: ctor_label = NULL_TREE;
9296: }
9297: else
9298: {
9299: dtor_label = NULL_TREE;
9300: if (DECL_CONSTRUCTOR_P (decl1))
9301: ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
9302: }
9303:
9304: /* If this fcn was already referenced via a block-scope `extern' decl
9305: (or an implicit decl), propagate certain information about the usage. */
9306: if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
9307: TREE_ADDRESSABLE (decl1) = 1;
9308:
9309: return 1;
9310: }
9311:
9312: /* Store the parameter declarations into the current function declaration.
9313: This is called after parsing the parameter declarations, before
9314: digesting the body of the function.
9315:
9316: Also install to binding contour return value identifier, if any. */
9317:
9318: void
9319: store_parm_decls ()
9320: {
9321: register tree fndecl = current_function_decl;
9322: register tree parm;
9323: int parms_have_cleanups = 0;
9324: tree eh_decl;
9325:
9326: /* This is either a chain of PARM_DECLs (when a prototype is used). */
9327: tree specparms = current_function_parms;
9328:
9329: /* This is a list of types declared among parms in a prototype. */
9330: tree parmtags = current_function_parm_tags;
9331:
9332: /* This is a chain of any other decls that came in among the parm
9333: declarations. If a parm is declared with enum {foo, bar} x;
9334: then CONST_DECLs for foo and bar are put here. */
9335: tree nonparms = 0;
9336:
9337: if (current_binding_level == global_binding_level)
9338: fatal ("parse errors have confused me too much");
9339:
9340: /* Initialize RTL machinery. */
9341: init_function_start (fndecl, input_filename, lineno);
9342:
9343: /* Create a binding level for the parms. */
9344: expand_start_bindings (0);
9345:
9346: /* Prepare to catch raises, if appropriate. */
9347: if (flag_handle_exceptions)
9348: {
9349: /* Get this cleanup to be run last, since it
9350: is a call to `longjmp'. */
9351: setup_exception_throw_decl ();
9352: eh_decl = current_binding_level->names;
9353: current_binding_level->names = TREE_CHAIN (current_binding_level->names);
9354: }
9355: if (flag_handle_exceptions)
9356: expand_start_try (integer_one_node, 0, 1);
9357:
9358: if (specparms != 0)
9359: {
9360: /* This case is when the function was defined with an ANSI prototype.
9361: The parms already have decls, so we need not do anything here
9362: except record them as in effect
9363: and complain if any redundant old-style parm decls were written. */
9364:
9365: register tree next;
9366:
9367: /* Must clear this because it might contain TYPE_DECLs declared
9368: at class level. */
9369: storedecls (NULL_TREE);
9370: for (parm = nreverse (specparms); parm; parm = next)
9371: {
9372: next = TREE_CHAIN (parm);
9373: if (TREE_CODE (parm) == PARM_DECL)
9374: {
9375: tree cleanup = maybe_build_cleanup (parm);
9376: if (DECL_NAME (parm) == 0)
9377: {
9378: #if 0
9379: error_with_decl (parm, "parameter name omitted");
9380: #else
9381: /* for C++, this is not an error. */
9382: pushdecl (parm);
9383: #endif
9384: }
9385: else if (TREE_TYPE (parm) == void_type_node)
9386: error_with_decl (parm, "parameter `%s' declared void");
9387: else
9388: {
9389: /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
9390: A parameter is assumed not to have any side effects.
9391: If this should change for any reason, then this
9392: will have to wrap the bashed reference type in a save_expr.
9393:
9394: Also, if the parameter type is declared to be an X
9395: and there is an X(X&) constructor, we cannot lay it
9396: into the stack (any more), so we make this parameter
9397: look like it is really of reference type. Functions
9398: which pass parameters to this function will know to
9399: create a temporary in their frame, and pass a reference
9400: to that. */
9401:
9402: if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
9403: && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
9404: SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
9405:
9406: pushdecl (parm);
9407: }
9408: if (cleanup)
9409: {
9410: expand_decl (parm);
9411: expand_decl_cleanup (parm, cleanup);
9412: parms_have_cleanups = 1;
9413: }
9414: }
9415: else
9416: {
9417: /* If we find an enum constant or a type tag,
9418: put it aside for the moment. */
9419: TREE_CHAIN (parm) = 0;
9420: nonparms = chainon (nonparms, parm);
9421: }
9422: }
9423:
9424: /* Get the decls in their original chain order
9425: and record in the function. This is all and only the
9426: PARM_DECLs that were pushed into scope by the loop above. */
9427: DECL_ARGUMENTS (fndecl) = getdecls ();
9428:
9429: storetags (chainon (parmtags, gettags ()));
9430: }
9431: else
9432: DECL_ARGUMENTS (fndecl) = 0;
9433:
9434: /* Now store the final chain of decls for the arguments
9435: as the decl-chain of the current lexical scope.
9436: Put the enumerators in as well, at the front so that
9437: DECL_ARGUMENTS is not modified. */
9438:
9439: storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
9440:
9441: /* Initialize the RTL code for the function. */
9442: DECL_SAVED_INSNS (fndecl) = 0;
9443: expand_function_start (fndecl, parms_have_cleanups);
9444:
9445: if (flag_handle_exceptions)
9446: {
9447: /* Make the throw decl visibile at this level, just
9448: not in the way of the parameters. */
9449: pushdecl (eh_decl);
9450: expand_decl_init (eh_decl);
9451: }
9452:
9453: /* Create a binding contour which can be used to catch
9454: cleanup-generated temporaries. Also, if the return value needs or
9455: has initialization, deal with that now. */
9456: if (parms_have_cleanups)
9457: {
9458: pushlevel (0);
9459: expand_start_bindings (0);
9460: }
9461:
9462: current_function_parms_stored = 1;
9463:
9464: if (flag_gc)
9465: {
9466: maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
9467: expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup);
9468: }
9469:
9470: /* If this function is `main', emit a call to `__main'
9471: to run global initializers, etc. */
9472: if (DECL_NAME (fndecl)
9473: && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
9474: && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
9475: && DECL_CONTEXT (fndecl) == NULL_TREE)
9476: {
9477: expand_main_function ();
9478:
9479: if (flag_gc)
9480: expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
9481: 0, VOIDmode, 0);
9482:
9483: if (flag_dossier)
9484: output_builtin_tdesc_entries ();
9485: }
9486: }
9487:
9488: /* Bind a name and initialization to the return value of
9489: the current function. */
9490: void
9491: store_return_init (return_id, init)
9492: tree return_id, init;
9493: {
9494: tree decl = DECL_RESULT (current_function_decl);
9495:
9496: if (pedantic)
9497: /* Give this error as many times as there are occurences,
9498: so that users can use Emacs compilation buffers to find
9499: and fix all such places. */
9500: error ("ANSI C++ does not permit named return values");
9501:
9502: if (return_id != NULL_TREE)
9503: {
9504: if (DECL_NAME (decl) == 0)
9505: {
9506: DECL_NAME (decl) = return_id;
9507: DECL_ASSEMBLER_NAME (decl) = return_id;
9508: }
9509: else
9510: error ("return identifier `%s' already in place",
9511: IDENTIFIER_POINTER (DECL_NAME (decl)));
9512: }
9513:
9514: /* Can't let this happen for constructors. */
9515: if (DECL_CONSTRUCTOR_P (current_function_decl))
9516: {
9517: error ("can't redefine default return value for constructors");
9518: return;
9519: }
9520:
9521: /* If we have a named return value, put that in our scope as well. */
9522: if (DECL_NAME (decl) != 0)
9523: {
9524: /* If this named return value comes in a register,
9525: put it in a pseudo-register. */
9526: if (TREE_REGDECL (decl))
9527: {
9528: original_result_rtx = DECL_RTL (decl);
9529: DECL_RTL (decl) = (struct rtx_def *)gen_reg_rtx (DECL_MODE (decl));
9530: }
9531:
9532: /* Let `finish_decl' know that this initializer is ok. */
9533: DECL_INITIAL (decl) = init;
9534: pushdecl (decl);
9535: finish_decl (decl, init, 0, 0);
9536: }
9537: }
9538:
9539: /* Generate code for default X(X&) constructor. */
9540: static void
9541: build_default_constructor (fndecl)
9542: tree fndecl;
9543: {
9544: int i = CLASSTYPE_N_BASECLASSES (current_class_type);
9545: tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
9546: tree fields = TYPE_FIELDS (current_class_type);
9547: tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
9548:
9549: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
9550: parm = TREE_CHAIN (parm);
9551: parm = DECL_REFERENCE_SLOT (parm);
9552:
9553: while (--i >= 0)
9554: {
9555: tree basetype = TREE_VEC_ELT (binfos, i);
9556: if (TYPE_GETS_INIT_REF (basetype))
9557: {
9558: tree name = TYPE_NAME (basetype);
9559: if (TREE_CODE (name) == TYPE_DECL)
9560: name = DECL_NAME (name);
9561: current_base_init_list = tree_cons (name, parm, current_base_init_list);
9562: }
9563: }
9564: for (; fields; fields = TREE_CHAIN (fields))
9565: {
9566: tree name, init;
9567: if (TREE_STATIC (fields))
9568: continue;
9569: if (TREE_CODE (fields) != FIELD_DECL)
9570: continue;
9571: if (DECL_NAME (fields))
9572: {
9573: if (VFIELD_NAME_P (DECL_NAME (fields)))
9574: continue;
9575: if (VBASE_NAME_P (DECL_NAME (fields)))
9576: continue;
9577:
9578: /* True for duplicate members. */
9579: if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields)
9580: continue;
9581: }
9582:
9583: init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields);
9584:
9585: if (TREE_ANON_UNION_ELEM (fields))
9586: name = build (COMPONENT_REF, TREE_TYPE (fields), C_C_D, fields);
9587: else
9588: {
9589: name = DECL_NAME (fields);
9590: init = build_tree_list (NULL_TREE, init);
9591: }
9592:
9593: current_member_init_list
9594: = tree_cons (name, init, current_member_init_list);
9595: }
9596: }
9597:
9598:
9599: /* Finish up a function declaration and compile that function
9600: all the way to assembler language output. The free the storage
9601: for the function definition.
9602:
9603: This is called after parsing the body of the function definition.
9604: LINENO is the current line number.
9605:
9606: C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
9607: (and expand_end_bindings) must be made to take care of the binding
9608: contour for the base initializers. This is only relevant for
9609: constructors. */
9610:
9611: void
9612: finish_function (lineno, call_poplevel)
9613: int lineno;
9614: int call_poplevel;
9615: {
9616: register tree fndecl = current_function_decl;
9617: tree fntype = TREE_TYPE (fndecl), ctype = NULL_TREE;
9618: struct rtx_def *head, *last_parm_insn, *mark;
9619: extern struct rtx_def *get_last_insn ();
9620: extern struct rtx_def *cleanup_label, *return_label;
9621: extern int sets_exception_throw_decl;
9622: /* Label to use if this function is supposed to return a value. */
9623: tree no_return_label = 0;
9624:
9625: /* TREE_READONLY (fndecl) = 1;
9626: This caused &foo to be of type ptr-to-const-function
9627: which then got a warning when stored in a ptr-to-function variable. */
9628:
9629: /* This happens on strange parse errors. */
9630: if (! current_function_parms_stored)
9631: {
9632: call_poplevel = 0;
9633: store_parm_decls ();
9634: }
9635:
9636: if (write_symbols == DBX_DEBUG
9637: && (TREE_CODE (fntype) != METHOD_TYPE
9638: || ! DECL_IGNORED_P (TYPE_NAME (TYPE_METHOD_BASETYPE (fntype)))))
9639: {
9640: tree ttype = target_type (fntype);
9641: tree parmdecl;
9642:
9643: if (IS_AGGR_TYPE (ttype))
9644: /* Let debugger know it should output info for this type. */
9645: note_debug_info_needed (ttype);
9646:
9647: for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
9648: {
9649: ttype = target_type (TREE_TYPE (parmdecl));
9650: if (IS_AGGR_TYPE (ttype))
9651: /* Let debugger know it should output info for this type. */
9652: note_debug_info_needed (ttype);
9653: }
9654: }
9655:
9656: /* Clean house because we will need to reorder insns here. */
9657: do_pending_stack_adjust ();
9658:
9659: if (dtor_label)
9660: {
9661: tree binfo = TYPE_BINFO (current_class_type);
9662: tree cond = integer_one_node;
9663: tree exprstmt, vfields;
9664: tree in_charge_node = lookup_name (in_charge_identifier, 0);
9665: int ok_to_optimize_dtor = 0;
9666:
9667: if (current_function_assigns_this)
9668: cond = build (NE_EXPR, integer_type_node,
9669: current_class_decl, integer_zero_node);
9670: else
9671: {
9672: int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
9673:
9674: /* If this destructor is empty, then we don't need to check
9675: whether `this' is NULL in some cases. */
9676: mark = get_last_insn ();
9677: last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
9678:
9679: if ((flag_this_is_variable & 1) == 0)
9680: ok_to_optimize_dtor = 1;
9681: else if (mark == last_parm_insn)
9682: ok_to_optimize_dtor
9683: = (n_baseclasses == 0
9684: || (n_baseclasses == 1
9685: && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
9686: }
9687:
9688: /* These initializations might go inline. Protect
9689: the binding level of the parms. */
9690: pushlevel (0);
9691:
9692: if (current_function_assigns_this)
9693: {
9694: current_function_assigns_this = 0;
9695: current_function_just_assigned_this = 0;
9696: }
9697:
9698: /* Generate the code to call destructor on base class.
9699: If this destructor belongs to a class with virtual
9700: functions, then set the virtual function table
9701: pointer to represent the type of our base class. */
9702:
9703: /* This side-effect makes call to `build_delete' generate the
9704: code we have to have at the end of this destructor. */
9705: TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
9706:
9707: /* These are two cases where we cannot delegate deletion. */
9708: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
9709: || TREE_GETS_DELETE (current_class_type))
9710: exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
9711: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0, 0);
9712: else
9713: exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
9714: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0, 0);
9715:
9716: /* If we did not assign to this, then `this' is non-zero at
9717: the end of a destructor. As a special optimization, don't
9718: emit test if this is an empty destructor. If it does nothing,
9719: it does nothing. If it calls a base destructor, the base
9720: destructor will perform the test. */
9721:
9722: if (exprstmt != error_mark_node
9723: && (TREE_CODE (exprstmt) != NOP_EXPR
9724: || TREE_OPERAND (exprstmt, 0) != integer_zero_node
9725: || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
9726: {
9727: expand_label (dtor_label);
9728: if (cond != integer_one_node)
9729: expand_start_cond (cond, 0);
9730: if (exprstmt != void_zero_node)
9731: /* Don't call `expand_expr_stmt' if we're not going to do
9732: anything, since -Wall will give a diagnostic. */
9733: expand_expr_stmt (exprstmt);
9734:
9735: /* Run destructor on all virtual baseclasses. */
9736: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
9737: {
9738: tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
9739: expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
9740: in_charge_node, integer_two_node), 0);
9741: while (vbases)
9742: {
9743: if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
9744: {
9745: tree ptr = convert_pointer_to_vbase (vbases, current_class_decl);
9746: expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)),
9747: ptr, integer_zero_node,
9748: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0, 0));
9749: }
9750: vbases = TREE_CHAIN (vbases);
9751: }
9752: expand_end_cond ();
9753: }
9754:
9755: do_pending_stack_adjust ();
9756: if (cond != integer_one_node)
9757: expand_end_cond ();
9758: }
9759:
9760: TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
9761:
9762: /* At the end, call delete if that's what's requested. */
9763: if (TREE_GETS_DELETE (current_class_type))
9764: /* This NOP_EXPR means we are in a static call context. */
9765: exprstmt = build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node),
9766: ansi_opname[DELETE_EXPR],
9767: build_tree_list (NULL_TREE, current_class_decl),
9768: NULL_TREE, LOOKUP_NORMAL);
9769: else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
9770: exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0);
9771: else
9772: exprstmt = 0;
9773:
9774: if (exprstmt)
9775: {
9776: cond = build (BIT_AND_EXPR, integer_type_node,
9777: in_charge_node, integer_one_node);
9778: expand_start_cond (cond, 0);
9779: expand_expr_stmt (exprstmt);
9780: expand_end_cond ();
9781: }
9782:
9783: /* End of destructor. */
9784: poplevel (2, 0, 0);
9785:
9786: /* Back to the top of destructor. */
9787: /* Dont execute destructor code if `this' is NULL. */
9788: mark = get_last_insn ();
9789: last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
9790: if (last_parm_insn == 0) last_parm_insn = mark;
9791: else last_parm_insn = (struct rtx_def *) previous_insn (last_parm_insn);
9792:
9793: /* Make all virtual function table pointers point to CURRENT_CLASS_TYPE's
9794: virtual function tables. */
9795: if (CLASSTYPE_VFIELDS (current_class_type))
9796: {
9797: for (vfields = CLASSTYPE_VFIELDS (current_class_type);
9798: TREE_CHAIN (vfields);
9799: vfields = TREE_CHAIN (vfields))
9800: expand_expr_stmt (build_virtual_init (binfo,
9801: VF_BASETYPE_VALUE (vfields),
9802: current_class_decl));
9803: expand_expr_stmt (build_virtual_init (binfo, binfo,
9804: current_class_decl));
9805: }
9806: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
9807: expand_expr_stmt (build_vbase_vtables_init (binfo, binfo,
9808: C_C_D, current_class_decl, 0));
9809: if (! ok_to_optimize_dtor)
9810: {
9811: cond = build_binary_op (NE_EXPR, current_class_decl, integer_zero_node);
9812: expand_start_cond (cond, 0);
9813: }
9814: if (mark != get_last_insn ())
9815: reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
9816: if (! ok_to_optimize_dtor)
9817: expand_end_cond ();
9818: }
9819: else if (current_function_assigns_this)
9820: {
9821: /* Does not need to call emit_base_init, because
9822: that is done (if needed) just after assignment to this
9823: is seen. */
9824:
9825: if (DECL_CONSTRUCTOR_P (current_function_decl))
9826: {
9827: expand_label (ctor_label);
9828: ctor_label = NULL_TREE;
9829:
9830: if (call_poplevel)
9831: {
9832: tree decls = getdecls ();
9833: if (flag_handle_exceptions == 2)
9834: deactivate_exception_cleanups ();
9835: expand_end_bindings (decls, decls != 0, 0);
9836: poplevel (decls != 0, 0, 0);
9837: }
9838: c_expand_return (current_class_decl);
9839: }
9840: else if (TREE_TYPE (DECL_RESULT (current_function_decl)) != void_type_node
9841: && return_label != NULL)
9842: no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
9843:
9844: current_function_assigns_this = 0;
9845: current_function_just_assigned_this = 0;
9846: base_init_insns = 0;
9847: }
9848: else if (DECL_CONSTRUCTOR_P (fndecl))
9849: {
9850: tree allocated_this;
9851: tree cond, thenclause;
9852: /* Allow constructor for a type to get a new instance of the object
9853: using `build_new'. */
9854: tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
9855: CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
9856:
9857: DECL_RETURNS_FIRST_ARG (fndecl) = 1;
9858:
9859: if (flag_this_is_variable)
9860: {
9861: cond = build_binary_op (EQ_EXPR, current_class_decl, integer_zero_node);
9862: thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
9863: build_new (NULL_TREE, current_class_type, void_type_node, 0));
9864: if (flag_handle_exceptions == 2)
9865: {
9866: tree cleanup, cleanup_deallocate;
9867:
9868: allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node);
9869: TREE_REGDECL (allocated_this) = 1;
9870: DECL_INITIAL (allocated_this) = error_mark_node;
9871: expand_decl (allocated_this);
9872: expand_decl_init (allocated_this);
9873: /* How we cleanup `this' if an exception was raised before
9874: we are ready to bail out. */
9875: cleanup = TREE_GETS_DELETE (current_class_type)
9876: ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this)
9877: : build_delete (TREE_TYPE (allocated_this), allocated_this, integer_three_node, LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1, 0);
9878: cleanup_deallocate
9879: = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node);
9880: cleanup = tree_cons (NULL_TREE, cleanup,
9881: build_tree_list (NULL_TREE, cleanup_deallocate));
9882:
9883: expand_decl_cleanup (allocated_this,
9884: build (COND_EXPR, integer_type_node,
9885: build (NE_EXPR, integer_type_node,
9886: allocated_this, integer_zero_node),
9887: build_compound_expr (cleanup),
9888: integer_zero_node));
9889: }
9890: }
9891: else if (TREE_GETS_NEW (current_class_type))
9892: /* Just check visibility here. */
9893: build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node),
9894: ansi_opname[NEW_EXPR],
9895: build_tree_list (NULL_TREE, integer_zero_node),
9896: NULL_TREE, LOOKUP_NORMAL);
9897:
9898: CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
9899:
9900: /* must keep the first insn safe. */
9901: head = (struct rtx_def *)get_insns ();
9902:
9903: /* this note will come up to the top with us. */
9904: mark = get_last_insn ();
9905:
9906: if (flag_this_is_variable)
9907: {
9908: expand_start_cond (cond, 0);
9909: expand_expr_stmt (thenclause);
9910: if (flag_handle_exceptions == 2)
9911: expand_assignment (allocated_this, current_class_decl, 0, 0);
9912: expand_end_cond ();
9913: }
9914:
9915: if (DECL_NAME (fndecl) == NULL_TREE
9916: && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
9917: build_default_constructor (fndecl);
9918:
9919: /* Emit insns from `emit_base_init' which sets up virtual
9920: function table pointer(s). */
9921: emit_insns (base_init_insns);
9922: base_init_insns = 0;
9923:
9924: /* This is where the body of the constructor begins.
9925: If there were no insns in this function body, then the
9926: last_parm_insn is also the last insn.
9927:
9928: If optimization is enabled, last_parm_insn may move, so
9929: we don't hold on to it (across emit_base_init). */
9930: last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
9931: if (last_parm_insn == 0) last_parm_insn = mark;
9932: else last_parm_insn = (struct rtx_def *) previous_insn (last_parm_insn);
9933:
9934: if (mark != get_last_insn ())
9935: reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
9936:
9937: /* This is where the body of the constructor ends. */
9938: expand_label (ctor_label);
9939: ctor_label = NULL_TREE;
9940: if (flag_handle_exceptions == 2)
9941: {
9942: expand_assignment (allocated_this, integer_zero_node, 0, 0);
9943: if (call_poplevel)
9944: deactivate_exception_cleanups ();
9945: }
9946:
9947: pop_implicit_try_blocks (NULL_TREE);
9948:
9949: if (call_poplevel)
9950: {
9951: expand_end_bindings (getdecls (), 1, 0);
9952: poplevel (1, 1, 0);
9953: }
9954:
9955: c_expand_return (current_class_decl);
9956:
9957: current_function_assigns_this = 0;
9958: current_function_just_assigned_this = 0;
9959: }
9960: else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
9961: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
9962: && DECL_CONTEXT (fndecl) == NULL_TREE)
9963: {
9964: /* Make it so that `main' always returns 0 by default. */
9965: #ifdef VMS
9966: c_expand_return (integer_one_node);
9967: #else
9968: c_expand_return (integer_zero_node);
9969: #endif
9970: }
9971: else if (return_label != NULL
9972: && current_function_return_value == 0
9973: && ! DECL_NAME (DECL_RESULT (current_function_decl)))
9974: no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
9975:
9976: if (flag_gc)
9977: expand_gc_prologue_and_epilogue ();
9978:
9979: /* That's the end of the vtable decl's life. Need to mark it such
9980: if doing stupid register allocation.
9981:
9982: Note that current_vtable_decl is really an INDIRECT_REF
9983: on top of a VAR_DECL here. */
9984: if (obey_regdecls && current_vtable_decl)
9985: use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
9986:
9987: /* If this function is supposed to return a value, ensure that
9988: we do not fall into the cleanups by mistake. The end of our
9989: function will look like this:
9990:
9991: user code (may have return stmt somewhere)
9992: goto no_return_label
9993: cleanup_label:
9994: cleanups
9995: goto return_label
9996: no_return_label:
9997: NOTE_INSN_FUNCTION_END
9998: return_label:
9999: things for return
10000:
10001: If the user omits a return stmt in the USER CODE section, we
10002: will have a control path which reaches NOTE_INSN_FUNCTION_END.
10003: Otherwise, we won't. */
10004: if (no_return_label)
10005: {
10006: DECL_CONTEXT (no_return_label) = fndecl;
10007: DECL_INITIAL (no_return_label) = error_mark_node;
10008: DECL_SOURCE_FILE (no_return_label) = input_filename;
10009: DECL_SOURCE_LINE (no_return_label) = lineno;
10010: expand_goto (no_return_label);
10011: }
10012:
10013: if (cleanup_label)
10014: {
10015: /* remove the binding contour which is used
10016: to catch cleanup-generated temporaries. */
10017: expand_end_bindings (0, 0, 0);
10018: poplevel (0, 0, 0);
10019: }
10020:
10021: /* Must mark the RESULT_DECL as being in this function. */
10022: DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
10023:
10024: /* Obey `register' declarations if `setjmp' is called in this fn. */
10025: if (flag_traditional && current_function_calls_setjmp)
10026: setjmp_protect (DECL_INITIAL (fndecl));
10027:
10028: if (cleanup_label)
10029: /* Emit label at beginning of cleanup code for parmeters. */
10030: emit_label (cleanup_label);
10031:
10032: #if 1
10033: /* Cheap hack to get better code from GNU C++. Remove when cse is fixed. */
10034: if (exception_throw_decl && sets_exception_throw_decl == 0)
10035: expand_assignment (exception_throw_decl, integer_zero_node, 0, 0);
10036: #endif
10037:
10038: if (flag_handle_exceptions)
10039: {
10040: expand_end_try ();
10041: expand_start_except (0, 0);
10042: expand_end_except ();
10043: }
10044: expand_end_bindings (0, 0, 0);
10045:
10046: /* Get return value into reigster if that's where it's supposed to be. */
10047: if (original_result_rtx)
10048: fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
10049:
10050: /* Finish building code that will trigger warnings if users forget
10051: to make their functions return values. */
10052: if (no_return_label)
10053: {
10054: /* We don't need to call `expand_*_return' here because we
10055: don't need any cleanups here--this path of code is only
10056: for error checking purposes. */
10057: emit_jump (return_label);
10058: expand_label (no_return_label);
10059: }
10060:
10061: /* reset scope for C++: if we were in the scope of a class,
10062: then when we finish this function, we are not longer so.
10063: This cannot be done until we know for sure that no more
10064: class members will ever be referenced in this function
10065: (i.e., calls to destructors). */
10066: if (current_class_name)
10067: {
10068: ctype = current_class_type;
10069: popclass (1);
10070: }
10071: else
10072: pop_memoized_context (1);
10073:
10074: /* Forget about all overloaded functions defined in
10075: this scope which go away. */
10076: while (overloads_to_forget)
10077: {
10078: IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget))
10079: = TREE_VALUE (overloads_to_forget);
10080: overloads_to_forget = TREE_CHAIN (overloads_to_forget);
10081: }
10082:
10083: /* Generate rtl for function exit. */
10084: expand_function_end (input_filename, lineno);
10085:
10086: /* This must come after expand_function_end because cleanups might
10087: have declarations (from inline functions) that need to go into
10088: this function's blocks. */
10089: assert (current_binding_level->parm_flag == 1);
10090: poplevel (1, 0, 1);
10091:
10092: /* So we can tell if jump_optimize sets it to 1. */
10093: can_reach_end = 0;
10094:
10095: /* ??? Compensate for Sun brain damage in dealing with data segments
10096: of PIC code. */
10097: if (flag_pic
10098: && (DECL_CONSTRUCTOR_P (fndecl)
10099: || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
10100: && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))
10101: TREE_INLINE (fndecl) = 0;
10102:
10103: if (TREE_EXTERNAL (fndecl) && ! TREE_PUBLIC (fndecl)
10104: /* This function is just along for the ride. If we can make
10105: it inline, that's great. Otherwise, just punt it. */
10106: && (TREE_INLINE (fndecl) == 0
10107: || flag_no_inline
10108: || function_cannot_inline_p (fndecl)))
10109: {
10110: extern int rtl_dump_and_exit;
10111: int old_rtl_dump_and_exit = rtl_dump_and_exit;
10112: int inline_spec = TREE_INLINE (fndecl);
10113:
10114: /* This throws away the code for FNDECL. */
10115: rtl_dump_and_exit = 1;
10116: /* This throws away the memory of the code for FNDECL. */
10117: if (flag_no_inline)
10118: TREE_INLINE (fndecl) = 0;
10119: rest_of_compilation (fndecl);
10120: rtl_dump_and_exit = old_rtl_dump_and_exit;
10121: TREE_INLINE (fndecl) = inline_spec;
10122: }
10123: else
10124: {
10125: /* Run the optimizers and output the assembler code for this function. */
10126: rest_of_compilation (fndecl);
10127: }
10128:
10129: if (ctype && TREE_ASM_WRITTEN (fndecl))
10130: note_debug_info_needed (ctype);
10131:
10132: current_function_returns_null |= can_reach_end;
10133:
10134: /* Since we don't normally go through c_expand_return for constructors,
10135: this normally gets the wrong value.
10136: Also, named return values have their return codes emitted after
10137: NOTE_INSN_FUNCTION_END, confusing jump.c. */
10138: if (DECL_CONSTRUCTOR_P (fndecl) || DECL_NAME (DECL_RESULT (fndecl)) != 0)
10139: current_function_returns_null = 0;
10140:
10141: if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
10142: warning ("`volatile' function does return");
10143: else if (warn_return_type && current_function_returns_null
10144: && TREE_TYPE (fntype) != void_type_node)
10145: {
10146: /* If this function returns non-void and control can drop through,
10147: complain. */
10148: if (pedantic)
10149: error ("control reaches end of non-void function");
10150: else
10151: warning ("control reaches end of non-void function");
10152: }
10153: /* With just -W, complain only if function returns both with
10154: and without a value. */
10155: else if (extra_warnings
10156: && current_function_returns_value && current_function_returns_null)
10157: warning ("this function may return with or without a value");
10158:
10159: /* Free all the tree nodes making up this function. */
10160: /* Switch back to allocating nodes permanently
10161: until we start another function. */
10162: permanent_allocation ();
10163:
10164: if (flag_cadillac)
10165: cadillac_finish_function (fndecl);
10166:
10167: if (DECL_SAVED_INSNS (fndecl) == 0)
10168: {
10169: /* Stop pointing to the local nodes about to be freed. */
10170: /* But DECL_INITIAL must remain nonzero so we know this
10171: was an actual function definition. */
10172: DECL_INITIAL (fndecl) = error_mark_node;
10173: if (! DECL_CONSTRUCTOR_P (fndecl)
10174: || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
10175: DECL_ARGUMENTS (fndecl) = 0;
10176: }
10177:
10178: /* Let the error reporting routines know that we're outside a function. */
10179: current_function_decl = NULL_TREE;
10180: named_label_uses = NULL_TREE;
10181: clear_anon_parm_name ();
10182: }
10183:
10184: /* Create the FUNCTION_DECL for a function definition.
10185: LINE1 is the line number that the definition absolutely begins on.
10186: LINE2 is the line number that the name of the function appears on.
10187: DECLSPECS and DECLARATOR are the parts of the declaration;
10188: they describe the function's name and the type it returns,
10189: but twisted together in a fashion that parallels the syntax of C.
10190:
10191: This function creates a binding context for the function body
10192: as well as setting up the FUNCTION_DECL in current_function_decl.
10193:
10194: Returns a FUNCTION_DECL on success.
10195:
10196: If the DECLARATOR is not suitable for a function (it defines a datum
10197: instead), we return 0, which tells yyparse to report a parse error.
10198:
10199: May return void_type_node indicating that this method is actually
10200: a friend. See grokfield for more details.
10201:
10202: Came here with a `.pushlevel' .
10203:
10204: DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
10205: CHANGES TO CODE IN `grokfield'. */
10206: tree
10207: start_method (declspecs, declarator, raises)
10208: tree declarator, declspecs, raises;
10209: {
10210: tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
10211:
10212: /* Something too ugly to handle. */
10213: if (fndecl == 0)
10214: return 0;
10215:
10216: /* Pass friends other than inline friend functions back. */
10217: if (fndecl == void_type_node)
10218: return void_type_node;
10219:
10220: if (TREE_CODE (fndecl) != FUNCTION_DECL)
10221: /* Not a function, tell parser to report parse error. */
10222: return 0;
10223:
10224: if (DECL_IN_AGGR_P (fndecl))
10225: {
10226: if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
10227: error_with_decl (fndecl, "`%s' is already defined in aggregate scope");
10228: return void_type_node;
10229: }
10230:
10231: /* If we're expanding a template, a function must be explicitly declared
10232: inline if we're to compile it now. If it isn't, we have to wait to see
10233: whether it's needed, and whether an override exists. */
10234: if (flag_default_inline && !processing_template_defn)
10235: TREE_INLINE (fndecl) = 1;
10236:
10237: /* We read in the parameters on the maybepermanent_obstack,
10238: but we won't be getting back to them until after we
10239: may have clobbered them. So the call to preserve_data
10240: will keep them safe. */
10241: preserve_data ();
10242:
10243: if (! DECL_FRIEND_P (fndecl))
10244: {
10245: if (DECL_CHAIN (fndecl) != NULL_TREE)
10246: {
10247: /* Need a fresh node here so that we don't get circularity
10248: when we link these together. If FNDECL was a friend, then
10249: `pushdecl' does the right thing, which is nothing wrt its
10250: current value of DECL_CHAIN. */
10251: fndecl = copy_node (fndecl);
10252: }
10253:
10254: if (DECL_CONSTRUCTOR_P (fndecl))
10255: grok_ctor_properties (current_class_type, fndecl);
10256: else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
10257: grok_op_properties (fndecl);
10258: }
10259:
10260: finish_decl (fndecl, NULL, NULL, 0);
10261:
10262: /* Make a place for the parms */
10263: pushlevel (0);
10264: current_binding_level->parm_flag = 1;
10265:
10266: DECL_IN_AGGR_P (fndecl) = 1;
10267: return fndecl;
10268: }
10269:
10270: /* Go through the motions of finishing a function definition.
10271: We don't compile this method until after the whole class has
10272: been processed.
10273:
10274: FINISH_METHOD must return something that looks as though it
10275: came from GROKFIELD (since we are defining a method, after all).
10276:
10277: This is called after parsing the body of the function definition.
10278: STMTS is the chain of statements that makes up the function body.
10279:
10280: DECL is the ..._DECL that `start_method' provided. */
10281:
10282: tree
10283: finish_method (decl)
10284: tree decl;
10285: {
10286: register tree fndecl = decl;
10287: tree old_initial;
10288:
10289: register tree link;
10290:
10291: if (decl == void_type_node)
10292: return decl;
10293:
10294: #ifdef DEBUG_CP_BINDING_LEVELS
10295: indent_to (stderr, debug_bindings_indentation);
10296: fprintf (stderr, "finish_method");
10297: debug_bindings_indentation += 4;
10298: #endif
10299:
10300: old_initial = DECL_INITIAL (fndecl);
10301:
10302: /* Undo the level for the parms (from start_method).
10303: This is like poplevel, but it causes nothing to be
10304: saved. Saving information here confuses symbol-table
10305: output routines. Besides, this information will
10306: be correctly output when this method is actually
10307: compiled. */
10308:
10309: /* Clear out the meanings of the local variables of this level;
10310: also record in each decl which block it belongs to. */
10311:
10312: for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
10313: {
10314: if (DECL_NAME (link) != 0)
10315: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
10316: assert (TREE_CODE (link) != FUNCTION_DECL);
10317: DECL_CONTEXT (link) = 0;
10318: }
10319:
10320: /* Restore all name-meanings of the outer levels
10321: that were shadowed by this level. */
10322:
10323: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
10324: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
10325: for (link = current_binding_level->class_shadowed;
10326: link; link = TREE_CHAIN (link))
10327: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
10328: for (link = current_binding_level->type_shadowed;
10329: link; link = TREE_CHAIN (link))
10330: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
10331:
10332: GNU_xref_end_scope (current_binding_level,
10333: current_binding_level->level_chain,
10334: current_binding_level->parm_flag,
10335: current_binding_level->keep,
10336: current_binding_level->tag_transparent);
10337:
10338: pop_binding_level ();
10339:
10340: DECL_INITIAL (fndecl) = old_initial;
10341: if (DECL_FRIEND_P (fndecl))
10342: {
10343: CLASSTYPE_INLINE_FRIENDS (current_class_type)
10344: = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
10345: decl = void_type_node;
10346: }
10347:
10348: #ifdef DEBUG_CP_BINDING_LEVELS
10349: debug_bindings_indentation -= 4;
10350: #endif
10351:
10352: return decl;
10353: }
10354:
10355: /* Called when a new struct TYPE is defined.
10356: If this structure or union completes the type of any previous
10357: variable declaration, lay it out and output its rtl. */
10358:
10359: void
10360: hack_incomplete_structures (type)
10361: tree type;
10362: {
10363: tree decl;
10364:
10365: if (current_binding_level->n_incomplete == 0)
10366: return;
10367:
10368: if (!type) /* Don't do this for class templates. */
10369: return;
10370:
10371: for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
10372: if (TREE_TYPE (decl) == type
10373: || (TREE_TYPE (decl)
10374: && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
10375: && TREE_TYPE (TREE_TYPE (decl)) == type))
10376: {
10377: if (TREE_CODE (decl) == TYPE_DECL)
10378: layout_type (TREE_TYPE (decl));
10379: else
10380: {
10381: int toplevel = global_binding_level == current_binding_level;
10382: layout_decl (decl, 0);
10383: rest_of_decl_compilation (decl, 0, toplevel, 0);
10384: if (! toplevel)
10385: {
10386: expand_decl (decl);
10387: expand_decl_cleanup (decl, maybe_build_cleanup (decl));
10388: expand_decl_init (decl);
10389: }
10390: }
10391: --current_binding_level->n_incomplete;
10392: assert (current_binding_level->n_incomplete >= 0);
10393: }
10394: }
10395:
10396: /* Nonzero if presently building a cleanup. Needed because
10397: SAVE_EXPRs are not the right things to use inside of cleanups.
10398: They are only ever evaluated once, where the cleanup
10399: might be evaluated several times. In this case, a later evaluation
10400: of the cleanup might fill in the SAVE_EXPR_RTL, and it will
10401: not be valid for an earlier cleanup. */
10402:
10403: int building_cleanup;
10404:
10405: /* If DECL is of a type which needs a cleanup, build that cleanup here.
10406: We don't build cleanups if just going for syntax checking, since
10407: fixup_cleanups does not know how to not handle them.
10408:
10409: Don't build these on the momentary obstack; they must live
10410: the life of the binding contour. */
10411: tree
10412: maybe_build_cleanup (decl)
10413: tree decl;
10414: {
10415: tree type = TREE_TYPE (decl);
10416: if (TYPE_NEEDS_DESTRUCTOR (type))
10417: {
10418: int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
10419: tree rval;
10420: int old_building_cleanup = building_cleanup;
10421: building_cleanup = 1;
10422:
10423: if (TREE_CODE (decl) != PARM_DECL)
10424: temp = suspend_momentary ();
10425:
10426: if (TREE_CODE (type) == ARRAY_TYPE)
10427: rval = decl;
10428: else
10429: {
10430: mark_addressable (decl);
10431: rval = build_unary_op (ADDR_EXPR, decl, 0);
10432: }
10433:
10434: /* Optimize for space over speed here. */
10435: if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
10436: || flag_expensive_optimizations)
10437: flags |= LOOKUP_NONVIRTUAL;
10438:
10439: /* Use TYPE_MAIN_VARIANT so we don't get a warning about
10440: calling delete on a `const' variable. */
10441: if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval))))
10442: rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval);
10443:
10444: rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0, 0);
10445:
10446: if (TYPE_USES_VIRTUAL_BASECLASSES (type)
10447: && ! TYPE_HAS_DESTRUCTOR (type))
10448: rval = build_compound_expr (tree_cons (NULL_TREE, rval,
10449: build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
10450:
10451: current_binding_level->have_cleanups = 1;
10452: current_binding_level->more_exceptions_ok = 0;
10453:
10454: if (TREE_CODE (decl) != PARM_DECL)
10455: resume_momentary (temp);
10456:
10457: building_cleanup = old_building_cleanup;
10458:
10459: return rval;
10460: }
10461: return 0;
10462: }
10463:
10464: /* Expand a C++ expression at the statement level.
10465: This is needed to ferret out nodes which have UNKNOWN_TYPE.
10466: The C++ type checker should get all of these out when
10467: expressions are combined with other, type-providing, expressions,
10468: leaving only orphan expressions, such as:
10469:
10470: &class::bar; / / takes its address, but does nothing with it.
10471:
10472: */
10473: void
10474: cplus_expand_expr_stmt (exp)
10475: tree exp;
10476: {
10477: if (TREE_TYPE (exp) == unknown_type_node)
10478: {
10479: if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
10480: error ("address of overloaded function with no contextual type information");
10481: else if (TREE_CODE (exp) == COMPONENT_REF)
10482: warning ("useless reference to a member function name, did you forget the ()?");
10483: }
10484: else
10485: {
10486: int remove_implicit_immediately = 0;
10487:
10488: if (TREE_CODE (exp) == FUNCTION_DECL)
10489: warning_with_decl (exp, "reference, not call, to function `%s'");
10490: if (TREE_RAISES (exp))
10491: {
10492: assert (flag_handle_exceptions);
10493: if (flag_handle_exceptions == 2)
10494: {
10495: if (! current_binding_level->more_exceptions_ok)
10496: {
10497: extern struct nesting *nesting_stack, *block_stack;
10498:
10499: remove_implicit_immediately
10500: = (nesting_stack != block_stack);
10501: cplus_expand_start_try (1);
10502: }
10503: current_binding_level->have_exceptions = 1;
10504: }
10505: }
10506:
10507: expand_expr_stmt (break_out_cleanups (exp));
10508:
10509: if (remove_implicit_immediately)
10510: pop_implicit_try_blocks (NULL_TREE);
10511: }
10512:
10513: /* Clean up any pending cleanups. This happens when a function call
10514: returns a cleanup-needing value that nobody uses. */
10515: expand_cleanups_to (NULL_TREE);
10516: }
10517:
10518: /* When a stmt has been parsed, this function is called.
10519:
10520: Currently, this function only does something within a
10521: constructor's scope: if a stmt has just assigned to this,
10522: and we are in a derived class, we call `emit_base_init'. */
10523:
10524: void
10525: finish_stmt ()
10526: {
10527: extern struct nesting *cond_stack, *loop_stack, *case_stack;
10528:
10529:
10530: if (current_function_assigns_this
10531: || ! current_function_just_assigned_this)
10532: return;
10533: if (DECL_CONSTRUCTOR_P (current_function_decl))
10534: {
10535: /* Constructors must wait until we are out of control
10536: zones before calling base constructors. */
10537: if (cond_stack || loop_stack || case_stack)
10538: return;
10539: emit_insns (base_init_insns);
10540: check_base_init (current_class_type);
10541: }
10542: current_function_assigns_this = 1;
10543:
10544: if (flag_cadillac)
10545: cadillac_finish_stmt ();
10546: }
10547:
10548: void
10549: pop_implicit_try_blocks (decl)
10550: tree decl;
10551: {
10552: if (decl)
10553: {
10554: assert (current_binding_level->parm_flag == 3);
10555: current_binding_level->names = TREE_CHAIN (decl);
10556: }
10557:
10558: while (current_binding_level->parm_flag == 3)
10559: {
10560: tree name = get_identifier ("(compiler error)");
10561: tree orig_ex_type = current_exception_type;
10562: tree orig_ex_decl = current_exception_decl;
10563: tree orig_ex_obj = current_exception_object;
10564: tree decl = cplus_expand_end_try (2);
10565:
10566: /* @@ It would be nice to make all these point
10567: to exactly the same handler. */
10568: /* Start hidden EXCEPT. */
10569: cplus_expand_start_except (name, decl);
10570: /* reraise ALL. */
10571: cplus_expand_reraise (NULL_TREE);
10572: current_exception_type = orig_ex_type;
10573: current_exception_decl = orig_ex_decl;
10574: current_exception_object = orig_ex_obj;
10575: /* This will reraise for us. */
10576: cplus_expand_end_except (error_mark_node);
10577: }
10578:
10579: if (decl)
10580: {
10581: TREE_CHAIN (decl) = current_binding_level->names;
10582: current_binding_level->names = decl;
10583: }
10584: }
10585:
10586: /* Push a cleanup onto the current binding contour that will cause
10587: ADDR to be cleaned up, in the case that an exception propagates
10588: through its binding contour. */
10589:
10590: void
10591: push_exception_cleanup (addr)
10592: tree addr;
10593: {
10594: tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node);
10595: tree cleanup;
10596:
10597: decl = pushdecl (decl);
10598: TREE_REGDECL (decl) = 1;
10599: store_init_value (decl, addr);
10600: expand_decl (decl);
10601: expand_decl_init (decl);
10602:
10603: cleanup = build (COND_EXPR, integer_type_node,
10604: build (NE_EXPR, integer_type_node,
10605: decl, integer_zero_node),
10606: build_delete (TREE_TYPE (addr), decl,
10607: lookup_name (in_charge_identifier, 0),
10608: LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0, 0),
10609: integer_zero_node);
10610: expand_decl_cleanup (decl, cleanup);
10611: }
10612:
10613: /* For each binding contour, emit code that deactivates the
10614: exception cleanups. All other cleanups are left as they were. */
10615:
10616: static void
10617: deactivate_exception_cleanups ()
10618: {
10619: struct binding_level *b = current_binding_level;
10620: tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME);
10621: while (b != class_binding_level)
10622: {
10623: if (b->parm_flag == 3)
10624: {
10625: tree decls = b->names;
10626: while (decls)
10627: {
10628: if (DECL_NAME (decls) == xyzzy)
10629: expand_assignment (decls, integer_zero_node, 0, 0);
10630: decls = TREE_CHAIN (decls);
10631: }
10632: }
10633: b = b->level_chain;
10634: }
10635: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.