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