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