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