|
|
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 "config.h"
30: #include "tree.h"
31: #include "flags.h"
32: #include "cp-tree.h"
33: #include "cp-lex.h"
34: #include "cp-decl.h"
35: #include "assert.h"
36:
37: #define NULL 0
38:
39: extern tree grokdeclarator ();
40: static void grok_function_init ();
41:
42: /* A list of virtual function tables we must make sure to write out. */
43: tree pending_vtables;
44:
45: /* A list of static class variables. This is needed, because a
46: static class variable can be declared inside the class without
47: an initializer, and then initialized, staticly, outside the class. */
48: tree pending_statics;
49:
50: extern tree pending_addressable_inlines;
51:
52: /* Used to help generate temporary names which are unique within
53: a function. Reset to 0 by start_function. */
54:
55: static int temp_name_counter;
56:
57: /* Same, but not reset. Local temp variables and global temp variables
58: can have the same name. */
59: static int global_temp_name_counter;
60:
61: /* The (assembler) name of the first globally-visible object output. */
62: extern char * first_global_object_name;
63:
64: /* C (and C++) language-specific option variables. */
65:
66: /* Nonzero means allow type mismatches in conditional expressions;
67: just make their values `void'. */
68:
69: int flag_cond_mismatch;
70:
71: /* Nonzero means give `double' the same size as `float'. */
72:
73: int flag_short_double;
74:
75: /* Nonzero means don't recognize the keyword `asm'. */
76:
77: int flag_no_asm;
78:
79: /* Nonzero means don't recognize the non-ANSI builtin functions. */
80:
81: int flag_no_builtin;
82:
83: /* Nonzero means do some things the same way PCC does. */
84:
85: int flag_traditional;
86:
87: /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
88:
89: int flag_signed_bitfields = 1;
90:
91: /* Nonzero means handle `#ident' directives. 0 means ignore them. */
92:
93: int flag_no_ident = 0;
94:
95: /* Nonzero means handle things in ANSI, instead of GNU fashion. This
96: flag should be tested for language behavior that's different between
97: ANSI and GNU, but not so horrible as to merit a PEDANTIC label. */
98:
99: int flag_ansi = 0;
100:
101: /* Nonzero means warn about implicit declarations. */
102:
103: int warn_implicit = 1;
104:
105: /* Like `warn_return_type', but this is set by users, whereas
106: `warn_return_type' is set by the compiler. */
107:
108: int explicit_warn_return_type;
109:
110: /* Nonzero means give string constants the type `const char *'
111: to get extra warnings from them. These warnings will be too numerous
112: to be useful, except in thoroughly ANSIfied programs. */
113:
114: int warn_write_strings;
115:
116: /* Nonzero means warn about pointer casts that can drop a type qualifier
117: from the pointer target type. */
118:
119: int warn_cast_qual;
120:
121: /* Nonzero means warn about sizeof(function) or addition/subtraction
122: of function pointers. */
123:
124: int warn_pointer_arith;
125:
126: /* Nonzero means warn for non-prototype function decls
127: or non-prototyped defs without previous prototype. */
128:
129: int warn_strict_prototypes;
130:
131: /* Nonzero means warn for any function def without prototype decl. */
132:
133: int warn_missing_prototypes;
134:
135: /* Warn about *printf or *scanf format/argument anomalies. */
136:
137: int warn_format;
138:
139: /* Warn if a type conversion is done that might have confusing results. */
140:
141: int warn_conversion;
142:
143: /* Warn if adding () is suggested. */
144:
145: int warn_parentheses = 1;
146:
147: /* Non-zero means warn in function declared in derived class has the
148: same name as a virtual in the base class, but fails to match the
149: type signature of any virtual function in the base class. */
150: int warn_overloaded_virtual;
151:
152: /* Non-zero means warn when converting between different enumeral types. */
153: int warn_enum_clash;
154:
155: /* Nonzero means `$' can be in an identifier.
156: See cccp.c for reasons why this breaks some obscure ANSI C programs. */
157:
158: #ifndef DOLLARS_IN_IDENTIFIERS
159: #define DOLLARS_IN_IDENTIFIERS 1
160: #endif
161: int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
162:
163: /* Nonzero for -no-strict-prototype switch: do not consider empty
164: argument prototype to mean function takes no arguments. */
165:
166: int strict_prototype = 1;
167: int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
168:
169: /* Nonzero means that labels can be used as first-class objects */
170:
171: int flag_labels_ok;
172:
173: /* Non-zero means to collect statistics which might be expensive
174: and to print them when we are done. */
175: int flag_detailed_statistics;
176:
177: /* C++ specific flags. */
178: /* Nonzero for -fall-virtual: make every member function (except
179: constructors) lay down in the virtual function table. Calls
180: can then either go through the virtual function table or not,
181: depending. */
182:
183: int flag_all_virtual;
184:
185: /* Zero means that `this' is a *const. This gives nice behavior in the
1.1.1.2 ! root 186: 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
! 187: -2 means we're constructing an object and it has fixed type. */
1.1 root 188:
189: int flag_this_is_variable;
190:
191: /* Nonzero means memoize our member lookups. */
192:
193: int flag_memoize_lookups; int flag_save_memoized_contexts;
194:
195: /* 3 means write out only virtuals function tables `defined'
196: in this implementation file.
197: 2 means write out only specific virtual function tables
198: and give them (C) public visibility.
199: 1 means write out virtual function tables and give them
200: (C) public visibility.
201: 0 means write out virtual function tables and give them
202: (C) static visibility (default).
203: -1 means declare virtual function tables extern. */
204:
205: int write_virtuals;
206:
207: /* Nonzero means we should attempt to elide constructors when possible. */
208:
209: int flag_elide_constructors;
210:
211: /* Same, but for inline functions: nonzero means write out debug info
212: for inlines. Zero means do not. */
213:
214: int flag_inline_debug;
215:
216: /* Nonzero means recognize and handle exception handling constructs.
217: 2 means handle exceptions the way Spring wants them handled. */
218:
219: int flag_handle_exceptions;
220:
221: /* Nonzero means recognize and handle exception handling constructs.
222: Use ansi syntax and semantics. WORK IN PROGRESS!
223: 2 means handle exceptions the way Spring wants them handled. */
224:
225: int flag_ansi_exceptions;
226:
227: /* Nonzero means that member functions defined in class scope are
228: inline by default. */
229:
230: int flag_default_inline = 1;
231:
232: /* Controls whether enums and ints freely convert.
233: 1 means with complete freedom.
234: 0 means enums can convert to ints, but not vice-versa. */
235: int flag_int_enum_equivalence;
236:
237: /* Controls whether compiler is operating under LUCID's Cadillac
238: system. 1 means yes, 0 means no. */
239: int flag_cadillac;
240:
241: /* Controls whether compiler generates code to build objects
242: that can be collected when they become garbage. */
243: int flag_gc;
244:
245: /* Controls whether compiler generates 'dossiers' that give
246: run-time type information. */
247: int flag_dossier;
248:
249: /* Nonzero if we wish to output cross-referencing information
250: for the GNU class browser. */
251: extern int flag_gnu_xref;
252:
253: /* Controls how compiler generates code in case there are
254: no GNU binutils. */
255:
256: #ifndef DBX_DEBUGGING_INFO
257: int flag_gnu_binutils = 0;
258: #else
259: int flag_gnu_binutils = 1;
260: #endif
261:
262: /* Nonzero if compiler can make `reasonable' assumptions about
263: references and objects. For example, the compiler must be
264: conservative about the following and not assume that `a' is nonnull:
265:
266: obj &a = g ();
267: a.f (2);
268:
269: In general, it is `reasonable' to assume that for many programs,
270: and better code can be generated in that case. */
271:
272: int flag_assume_nonnull_objects;
273:
274: /* Table of language-dependent -f options.
275: STRING is the option name. VARIABLE is the address of the variable.
276: ON_VALUE is the value to store in VARIABLE
277: if `-fSTRING' is seen as an option.
278: (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
279:
280: static struct { char *string; int *variable; int on_value;} lang_f_options[] =
281: {
282: {"signed-char", &flag_signed_char, 1},
283: {"unsigned-char", &flag_signed_char, 0},
284: {"signed-bitfields", &flag_signed_bitfields, 1},
285: {"unsigned-bitfields", &flag_signed_bitfields, 0},
286: {"short-enums", &flag_short_enums, 1},
287: {"short-double", &flag_short_double, 1},
288: {"cond-mismatch", &flag_cond_mismatch, 1},
289: {"asm", &flag_no_asm, 0},
290: {"builtin", &flag_no_builtin, 0},
291: {"ident", &flag_no_ident, 0},
292: {"labels-ok", &flag_labels_ok, 1},
293: {"stats", &flag_detailed_statistics, 1},
294: {"this-is-variable", &flag_this_is_variable, 1},
295: {"strict-prototype", &strict_prototypes_lang_cplusplus, 1},
296: {"all-virtual", &flag_all_virtual, 1},
297: {"memoize-lookups", &flag_memoize_lookups, 1},
298: {"elide-constructors", &flag_elide_constructors, 1},
299: {"inline-debug", &flag_inline_debug, 0},
300: {"handle-exceptions", &flag_handle_exceptions, 1},
301: {"ansi-exceptions", &flag_ansi_exceptions, 1},
302: {"spring-exceptions", &flag_handle_exceptions, 2},
303: {"default-inline", &flag_default_inline, 1},
304: {"dollars-in-identifiers", &dollars_in_ident, 1},
305: {"enum-int-equiv", &flag_int_enum_equivalence, 1},
306: {"gc", &flag_gc, 1},
307: {"dossier", &flag_dossier, 1},
308: {"gnu-binutils", &flag_gnu_binutils, 1},
309: {"xref", &flag_gnu_xref, 1},
310: {"nonnull-objects", &flag_assume_nonnull_objects, 1},
311: };
312:
313: /* Decode the string P as a language-specific option.
314: Return 1 if it is recognized (and handle it);
315: return 0 if not recognized. */
316:
317: int
318: lang_decode_option (p)
319: char *p;
320: {
321: if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
322: flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
323: flag_this_is_variable = 1;
1.1.1.2 ! root 324: /* The +e options are for cfront compatibility. */
1.1 root 325: else if (p[0] == '+' && p[1] == 'e')
326: {
327: int old_write_virtuals = write_virtuals;
328: if (p[2] == '1')
329: write_virtuals = 1;
330: else if (p[2] == '0')
331: write_virtuals = -1;
332: else if (p[2] == '2')
333: write_virtuals = 2;
334: else error ("invalid +e option");
335: if (old_write_virtuals != 0
336: && write_virtuals != old_write_virtuals)
337: error ("conflicting +e options given");
338: }
339: else if (p[0] == '-' && p[1] == 'f')
340: {
341: /* Some kind of -f option.
342: P's value is the option sans `-f'.
343: Search for it in the table of options. */
344: int found = 0, j;
345:
346: p += 2;
347: /* Try special -f options. */
348:
349: if (!strcmp (p, "save-memoized"))
350: {
351: flag_memoize_lookups = 1;
352: flag_save_memoized_contexts = 1;
353: found = 1;
354: }
355: if (!strcmp (p, "no-save-memoized"))
356: {
357: flag_memoize_lookups = 0;
358: flag_save_memoized_contexts = 0;
359: found = 1;
360: }
361: else if (!strcmp (p, "SOS"))
362: {
363: flag_all_virtual = 2;
364: found = 1;
365: }
366: else if (!strcmp (p, "no-SOS"))
367: {
368: flag_all_virtual = 0;
369: found = 1;
370: }
371: else if (! strncmp (p, "cadillac", 8))
372: {
373: flag_cadillac = atoi (p+9);
374: found = 1;
375: }
376: else if (! strncmp (p, "no-cadillac", 11))
377: {
378: flag_cadillac = 0;
379: found = 1;
380: }
381: else if (! strcmp (p, "gc"))
382: {
383: flag_gc = 1;
384: /* This must come along for the ride. */
385: flag_dossier = 1;
386: found = 1;
387: }
388: else if (! strcmp (p, "no-gc"))
389: {
390: flag_gc = 0;
391: /* This must come along for the ride. */
392: flag_dossier = 0;
393: found = 1;
394: }
395: else for (j = 0;
396: !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
397: j++)
398: {
399: if (!strcmp (p, lang_f_options[j].string))
400: {
401: *lang_f_options[j].variable = lang_f_options[j].on_value;
402: /* A goto here would be cleaner,
403: but breaks the vax pcc. */
404: found = 1;
405: }
406: if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
407: && ! strcmp (p+3, lang_f_options[j].string))
408: {
409: *lang_f_options[j].variable = ! lang_f_options[j].on_value;
410: found = 1;
411: }
412: }
413: return found;
414: }
415: else if (p[0] == '-' && p[1] == 'W')
416: {
417: int setting = 1;
418:
419: /* The -W options control the warning behavior of the compiler. */
420: p += 2;
421:
422: if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
423: setting = 0, p += 3;
424:
425: if (!strcmp (p, "implicit"))
426: warn_implicit = setting;
427: else if (!strcmp (p, "return-type"))
428: explicit_warn_return_type = setting;
429: else if (!strcmp (p, "write-strings"))
430: warn_write_strings = setting;
431: else if (!strcmp (p, "cast-qual"))
432: warn_cast_qual = setting;
433: else if (!strcmp (p, "pointer-arith"))
434: warn_pointer_arith = setting;
435: else if (!strcmp (p, "strict-prototypes"))
436: warn_strict_prototypes = setting;
437: else if (!strcmp (p, "missing-prototypes"))
438: warn_missing_prototypes = setting;
439: else if (!strcmp (p, "format"))
440: warn_format = setting;
441: else if (!strcmp (p, "conversion"))
442: warn_conversion = setting;
443: else if (!strcmp (p, "parentheses"))
444: warn_parentheses = setting;
445: else if (!strcmp (p, "comment"))
446: ; /* cpp handles this one. */
447: else if (!strcmp (p, "comments"))
448: ; /* cpp handles this one. */
449: else if (!strcmp (p, "trigraphs"))
450: ; /* cpp handles this one. */
451: else if (!strcmp (p, "all"))
452: {
453: extra_warnings = setting;
454: warn_implicit = setting;
455: explicit_warn_return_type = setting;
456: warn_unused = setting;
457: warn_switch = setting;
458: warn_uninitialized = setting;
459: #if 0
460: warn_enum_clash = setting;
461: #endif
462: }
463:
464: else if (!strcmp (p, "overloaded-virtual"))
465: warn_overloaded_virtual = setting;
466: else if (!strcmp (p, "enum-clash"))
467: warn_enum_clash = setting;
468: else return 0;
469: }
470: else if (!strcmp (p, "-ansi"))
471: flag_no_asm = 1, dollars_in_ident = 0, flag_ansi = 1;
472: else
473: return 0;
474:
475: return 1;
476: }
477:
478: /* Incorporate `const' and `volatile' qualifiers for member functions.
479: FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
480: QUALS is a list of qualifiers. */
481: tree
482: grok_method_quals (ctype, function, quals)
483: tree ctype, function, quals;
484: {
485: tree fntype = TREE_TYPE (function);
486: tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
487:
488: do
489: {
490: extern tree ridpointers[];
491:
492: if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
493: {
494: if (TYPE_READONLY (ctype))
495: error ("duplicate `%s' %s",
496: IDENTIFIER_POINTER (TREE_VALUE (quals)),
497: (TREE_CODE (function) == FUNCTION_DECL
498: ? "for member function" : "in type declaration"));
499: ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
500: build_pointer_type (ctype);
501: }
502: else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
503: {
504: if (TYPE_VOLATILE (ctype))
505: error ("duplicate `%s' %s",
506: IDENTIFIER_POINTER (TREE_VALUE (quals)),
507: (TREE_CODE (function) == FUNCTION_DECL
508: ? "for member function" : "in type declaration"));
509: ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
510: build_pointer_type (ctype);
511: }
512: else
513: abort ();
514: quals = TREE_CHAIN (quals);
515: }
516: while (quals);
517: fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
518: (TREE_CODE (fntype) == METHOD_TYPE
519: ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
520: : TYPE_ARG_TYPES (fntype)));
521: if (raises)
522: fntype = build_exception_variant (ctype, fntype, raises);
523:
524: TREE_TYPE (function) = fntype;
525: return ctype;
526: }
527:
528: /* Classes overload their constituent function names automatically.
529: When a function name is declared in a record structure,
530: its name is changed to it overloaded name. Since names for
531: constructors and destructors can conflict, we place a leading
532: '$' for destructors.
533:
534: CNAME is the name of the class we are grokking for.
535:
536: FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
537:
538: FLAGS contains bits saying what's special about today's
539: arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
540:
541: If FUNCTION is a destructor, then we must add the `auto-delete' field
542: as a second parameter. There is some hair associated with the fact
543: that we must "declare" this variable in the manner consistent with the
1.1.1.2 ! root 544: way the rest of the arguments were declared.
1.1 root 545:
546: If FUNCTION is a constructor, and we are doing SOS hacks for dynamic
547: classes, then the second hidden argument is the virtual function table
548: pointer with which to initialize the object.
549:
550: QUALS are the qualifiers for the this pointer. */
551:
552: void
553: grokclassfn (ctype, cname, function, flags, quals)
554: tree ctype, cname, function;
555: enum overload_flags flags;
556: tree quals;
557: {
558: tree fn_name = DECL_NAME (function);
559: tree arg_types;
560: tree parm;
561: char *name;
562:
563: if (fn_name == NULL_TREE)
564: {
565: error ("name missing for member function");
566: fn_name = get_identifier ("<anonymous>");
567: DECL_NAME (function) = fn_name;
568: }
569:
570: if (quals)
571: ctype = grok_method_quals (ctype, function, quals);
572:
573: arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
574: if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
575: {
576: /* Must add the class instance variable up front. */
577: /* Right now we just make this a pointer. But later
578: we may wish to make it special. */
579: tree type = TREE_VALUE (arg_types);
580:
581: if (flags == DTOR_FLAG)
582: type = TYPE_MAIN_VARIANT (type);
583: else if (DECL_CONSTRUCTOR_P (function))
584: {
585: if (TYPE_DYNAMIC (ctype))
586: {
587: parm = build_decl (PARM_DECL, get_identifier (AUTO_VTABLE_NAME), TYPE_POINTER_TO (ptr_type_node));
588: TREE_USED (parm) = 1;
589: TREE_READONLY (parm) = 1;
590: DECL_ARG_TYPE (parm) = TYPE_POINTER_TO (ptr_type_node);
591: TREE_CHAIN (parm) = last_function_parms;
592: last_function_parms = parm;
593: }
594:
595: if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
596: {
597: DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
598: /* In this case we need "in-charge" flag saying whether
599: this constructor is responsible for initialization
600: of virtual baseclasses or not. */
601: parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
602: DECL_ARG_TYPE (parm) = integer_type_node;
603: TREE_REGDECL (parm) = 1;
604: TREE_CHAIN (parm) = last_function_parms;
605: last_function_parms = parm;
606: }
607: }
608:
609: parm = build_decl (PARM_DECL, this_identifier, type);
610: DECL_ARG_TYPE (parm) = type;
611: /* We can make this a register, so long as we don't
1.1.1.2 ! root 612: accidentally complain if someone tries to take its address. */
1.1 root 613: TREE_REGDECL (parm) = 1;
614: if (flags != DTOR_FLAG
1.1.1.2 ! root 615: && (flag_this_is_variable <= 0 || TYPE_READONLY (type)))
1.1 root 616: TREE_READONLY (parm) = 1;
617: TREE_CHAIN (parm) = last_function_parms;
618: last_function_parms = parm;
619: }
620:
621: if (flags == DTOR_FLAG)
622: {
623: char *buf, *dbuf;
624: tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
625: int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
626:
627: arg_types = hash_tree_chain (const_integer_type, void_list_node);
628: /* Build the overload name. It will look like e.g. 7Example. */
629: dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
630: buf = (char *)alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
631: bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
632: buf[len] = '\0';
633: strcat (buf, dbuf);
634: DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
635: parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
636: TREE_USED (parm) = 1;
637: TREE_READONLY (parm) = 1;
638: DECL_ARG_TYPE (parm) = const_integer_type;
639: /* This is the same chain as DECL_ARGUMENTS (...). */
640: TREE_CHAIN (last_function_parms) = parm;
641:
642: TREE_TYPE (function) = build_cplus_method_type (ctype, void_type_node, arg_types);
643: TYPE_HAS_DESTRUCTOR (ctype) = 1;
644: }
645: else if (flags == WRAPPER_FLAG || flags == ANTI_WRAPPER_FLAG)
646: {
647: name = (char *)alloca (sizeof (WRAPPER_DECL_FORMAT)
648: + sizeof (ANTI_WRAPPER_DECL_FORMAT)
649: + IDENTIFIER_LENGTH (cname) + 2);
650: sprintf (name,
651: flags == WRAPPER_FLAG ? WRAPPER_DECL_FORMAT : ANTI_WRAPPER_DECL_FORMAT,
652: IDENTIFIER_POINTER (cname));
1.1.1.2 ! root 653: DECL_ASSEMBLER_NAME (function) = build_decl_overload (get_identifier (name), arg_types, 1);
1.1 root 654: sprintf (name, flags == WRAPPER_FLAG ? WRAPPER_NAME_FORMAT : ANTI_WRAPPER_NAME_FORMAT,
655: IDENTIFIER_POINTER (cname));
656: DECL_NAME (function) = fn_name = get_identifier (name);
657: }
658: else if (flags == WRAPPER_PRED_FLAG)
659: {
660: name = (char *)alloca (sizeof (WRAPPER_PRED_DECL_FORMAT)
661: + sizeof (WRAPPER_PRED_NAME_FORMAT)
662: + IDENTIFIER_LENGTH (cname) + 2);
663: sprintf (name, WRAPPER_PRED_DECL_FORMAT, IDENTIFIER_POINTER (cname));
1.1.1.2 ! root 664: DECL_ASSEMBLER_NAME (function) = build_decl_overload (get_identifier (name), arg_types, 1);
1.1 root 665: sprintf (name, WRAPPER_PRED_NAME_FORMAT, IDENTIFIER_POINTER (cname));
666: DECL_NAME (function) = fn_name = get_identifier (name);
667: }
668: else
669: {
670: tree these_arg_types;
671:
672: if (TYPE_DYNAMIC (ctype) && DECL_CONSTRUCTOR_P (function))
673: {
674: arg_types = hash_tree_chain (build_pointer_type (ptr_type_node),
675: TREE_CHAIN (arg_types));
676: TREE_TYPE (function)
677: = build_cplus_method_type (ctype, TREE_TYPE (TREE_TYPE (function)), arg_types);
678: arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
679: }
680:
681: if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
682: {
683: arg_types = hash_tree_chain (integer_type_node, TREE_CHAIN (arg_types));
684: TREE_TYPE (function)
685: = build_cplus_method_type (ctype, TREE_TYPE (TREE_TYPE (function)), arg_types);
686: arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
687: }
688:
689: these_arg_types = arg_types;
690:
691: if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
692: /* Only true for static member functions. */
693: these_arg_types = hash_tree_chain (TYPE_POINTER_TO (ctype), arg_types);
694:
695: DECL_ASSEMBLER_NAME (function)
1.1.1.2 ! root 696: = build_decl_overload (fn_name, these_arg_types,
1.1 root 697: 1 + DECL_CONSTRUCTOR_P (function));
698: #if 0
699: if (flags == TYPENAME_FLAG)
700: /* Not exactly an IDENTIFIER_TYPE_VALUE. */
701: TREE_TYPE (DECL_ASSEMBLER_NAME (function)) = TREE_TYPE (fn_name);
702: #endif
703: }
704:
705: DECL_ARGUMENTS (function) = last_function_parms;
706: /* First approximations. */
707: DECL_CONTEXT (function) = ctype;
708: DECL_CLASS_CONTEXT (function) = ctype;
709: }
710:
711: /* Sanity check: report error if this function FUNCTION is not
712: really a member of the class (CTYPE) it is supposed to belong to.
713: CNAME and FLAGS are the same here as they are for grokclassfn above. */
714:
715: void
716: check_classfn (ctype, cname, function, flags)
717: tree ctype, cname, function;
718: int flags;
719: {
720: tree fn_name = DECL_NAME (function);
721: tree fndecl;
722: int need_quotes = 0;
723: char *err_name;
724: tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
725: tree *methods = 0;
726: tree *end = 0;
727:
728: if (method_vec != 0)
729: {
730: methods = &TREE_VEC_ELT (method_vec, 0);
731: end = TREE_VEC_END (method_vec);
732:
733: /* First suss out ctors and dtors. */
734: if (*methods && fn_name == cname)
735: goto got_it;
736:
737: while (++methods != end)
738: {
739: if (fn_name == DECL_NAME (*methods))
740: {
741: got_it:
742: fndecl = *methods;
743: while (fndecl)
744: {
745: if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
746: return;
747: fndecl = DECL_CHAIN (fndecl);
748: }
749: break; /* loser */
750: }
751: }
752: }
753:
1.1.1.2 ! root 754: if (fn_name == ansi_opname[(int) TYPE_EXPR])
1.1 root 755: {
756: if (TYPE_HAS_CONVERSION (ctype))
757: err_name = "such type conversion operator";
758: }
759: else if (IDENTIFIER_OPNAME_P (fn_name))
760: {
761: err_name = (char *)alloca (1024);
762: sprintf (err_name, "`operator %s'", operator_name_string (fn_name));
763: }
764: else if (flags == WRAPPER_FLAG)
765: err_name = "wrapper";
766: else if (flags == WRAPPER_PRED_FLAG)
767: err_name = "wrapper predicate";
768: else
769: {
770: err_name = IDENTIFIER_POINTER (fn_name);
771: need_quotes = 1;
772: }
773:
774: if (methods != end)
775: if (need_quotes)
776: error ("argument list for `%s' does not match any in class", err_name);
777: else
778: error ("argument list for %s does not match any in class", err_name);
779: else
780: {
781: methods = 0;
782: if (need_quotes)
783: error ("no `%s' member function declared in class", err_name);
784: else
785: error ("no %s declared in class", err_name);
786: }
787:
788: /* If we did not find the method in the class, add it to
789: avoid spurious errors. */
790: add_method (ctype, methods, function);
791: }
792:
793: /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
794: of a structure component, returning a FIELD_DECL node.
795: QUALS is a list of type qualifiers for this decl (such as for declaring
796: const member functions).
797:
798: This is done during the parsing of the struct declaration.
799: The FIELD_DECL nodes are chained together and the lot of them
800: are ultimately passed to `build_struct' to make the RECORD_TYPE node.
801:
802: C++:
803:
804: If class A defines that certain functions in class B are friends, then
805: the way I have set things up, it is B who is interested in permission
806: granted by A. However, it is in A's context that these declarations
807: are parsed. By returning a void_type_node, class A does not attempt
808: to incorporate the declarations of the friends within its structure.
809:
810: DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
811: CHANGES TO CODE IN `start_method'. */
812:
813: tree
814: grokfield (declarator, declspecs, raises, init, asmspec_tree)
815: tree declarator, declspecs, raises, init;
816: tree asmspec_tree;
817: {
818: register tree value;
819: char *asmspec = 0;
820:
821: /* Convert () initializers to = initializers. */
822: if (init == NULL_TREE && declarator != NULL_TREE
823: && TREE_CODE (declarator) == CALL_EXPR
824: && TREE_OPERAND (declarator, 0)
825: && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
826: || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
827: && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
828: {
829: init = TREE_OPERAND (declarator, 1);
830: declarator = TREE_OPERAND (declarator, 0);
831: }
832:
833: value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
834: if (! value)
835: return NULL_TREE; /* friends went bad. */
836:
837: /* Pass friendly classes back. */
838: if (TREE_CODE (value) == VOID_TYPE)
839: return void_type_node;
840:
841: if (DECL_NAME (value) != NULL_TREE
842: && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
843: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
844: error_with_decl (value, "member `%s' conflicts with virtual function table field name");
845:
846: /* Stash away type declarations. */
847: if (TREE_CODE (value) == TYPE_DECL)
848: {
849: TREE_NONLOCAL (value) = 1;
850: CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
851: pushdecl_class_level (value);
852: return value;
853: }
854:
855: if (DECL_IN_AGGR_P (value))
856: {
857: error_with_decl (value, "`%s' is already defined in aggregate scope");
858: return void_type_node;
859: }
860:
861: if (flag_cadillac)
862: cadillac_start_decl (value);
863:
864: if (asmspec_tree)
865: asmspec = TREE_STRING_POINTER (asmspec_tree);
866:
867: if (init != 0)
868: {
869: if (TREE_CODE (value) == FUNCTION_DECL)
870: {
871: grok_function_init (value, init);
872: init = NULL_TREE;
873: }
874: else if (pedantic)
875: {
876: error ("fields cannot have initializers");
877: init = NULL_TREE;
878: }
879: else
880: {
881: /* We allow initializers to become parameters to base initializers. */
882: if (TREE_CODE (init) == TREE_LIST)
883: {
884: if (TREE_CHAIN (init) == NULL_TREE)
885: init = TREE_VALUE (init);
886: else
887: init = digest_init (TREE_TYPE (value), init, 0, 1, 0,
888: "field declaration");
889: }
890:
891: if (TREE_CODE (init) == CONST_DECL)
892: init = DECL_INITIAL (init);
893: else if (TREE_READONLY_DECL_P (init))
894: init = decl_constant_value (init);
895: else if (TREE_CODE (init) == CONSTRUCTOR)
896: init = digest_init (TREE_TYPE (value), init, 0);
897: assert (TREE_PERMANENT (init));
898: if (init == error_mark_node)
899: /* We must make this look different than `error_mark_node'
900: because `decl_const_value' would mis-interpret it
901: as only meaning that this VAR_DECL is defined. */
902: init = build1 (NOP_EXPR, TREE_TYPE (value), init);
903: else if (! TREE_CONSTANT (init))
904: {
905: /* We can allow references to things that are effectively
906: static, since references are initialized with the address. */
907: if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
908: || (TREE_STATIC (init) == 0
909: && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
910: || TREE_EXTERNAL (init) == 0)))
911: {
912: error ("field initializer is not constant");
913: init = error_mark_node;
914: }
915: }
916: }
917: }
918:
919: /* The corresponding pop_obstacks is in finish_decl. */
920: push_obstacks_nochange ();
921:
922: if (TREE_CODE (value) == VAR_DECL)
923: {
924: /* We cannot call pushdecl here, because that would
925: fill in the value of our TREE_CHAIN. Instead, we
926: modify finish_decl to do the right thing, namely, to
927: put this decl out straight away. */
928: if (TREE_STATIC (value))
929: {
930: if (asmspec == 0)
931: {
932: tree name;
933: char *buf, *buf2;
934:
935: buf2 = build_overload_name (current_class_type, 1, 1);
936: buf = (char *)alloca (IDENTIFIER_LENGTH (DECL_NAME (value))
937: + sizeof (STATIC_NAME_FORMAT)
938: + strlen (buf2));
939: sprintf (buf, STATIC_NAME_FORMAT, buf2,
940: IDENTIFIER_POINTER (DECL_NAME (value)));
941: name = get_identifier (buf);
942: TREE_PUBLIC (value) = 1;
943: DECL_INITIAL (value) = error_mark_node;
944: DECL_ASSEMBLER_NAME (value) = name;
945: }
946: pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
947:
948: /* Static consts need not be initialized in the class definition. */
949: if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
950: {
951: static int explanation = 0;
952:
953: error ("initializer invalid for static member with constructor");
954: if (explanation++ == 0)
955: error ("(you really want to initialize it separately)");
956: init = 0;
957: }
958: /* Force the compiler to know when an uninitialized static
959: const member is being used. */
960: if (TYPE_READONLY (value) && init == 0)
961: TREE_USED (value) = 1;
962: }
963: DECL_INITIAL (value) = init;
964: DECL_IN_AGGR_P (value) = 1;
965:
966: finish_decl (value, init, asmspec_tree, 1);
967: pushdecl_class_level (value);
968: return value;
969: }
970: if (TREE_CODE (value) == FIELD_DECL)
971: {
972: if (asmspec)
973: DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
974: if (DECL_INITIAL (value) == error_mark_node)
975: init = error_mark_node;
976: finish_decl (value, init, asmspec_tree, 1);
977: DECL_INITIAL (value) = init;
978: DECL_IN_AGGR_P (value) = 1;
979: return value;
980: }
981: if (TREE_CODE (value) == FUNCTION_DECL)
982: {
983: /* grokdeclarator defers setting this. */
984: TREE_PUBLIC (value) = 1;
985: if (DECL_CHAIN (value) != NULL_TREE)
986: {
987: /* Need a fresh node here so that we don't get circularity
988: when we link these together. */
989: value = copy_node (value);
990: /* When does this happen? */
991: assert (init == NULL_TREE);
992: }
993: finish_decl (value, init, asmspec_tree, 1);
994:
995: /* Pass friends back this way. */
996: if (DECL_FRIEND_P (value))
997: return void_type_node;
998:
999: DECL_IN_AGGR_P (value) = 1;
1000: return value;
1001: }
1002: abort ();
1003: /* NOTREACHED */
1004: return NULL_TREE;
1005: }
1006:
1007: /* Like `grokfield', but for bitfields.
1008: WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1009:
1010: tree
1011: grokbitfield (declarator, declspecs, width)
1012: tree declarator, declspecs, width;
1013: {
1014: register tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL_TREE);
1015:
1016: if (! value) return NULL_TREE; /* friends went bad. */
1017:
1018: /* Pass friendly classes back. */
1019: if (TREE_CODE (value) == VOID_TYPE)
1020: return void_type_node;
1021:
1022: if (TREE_CODE (value) == TYPE_DECL)
1023: {
1024: error_with_decl (value, "cannot declare `%s' to be a bitfield type");
1025: return NULL_TREE;
1026: }
1027:
1028: if (DECL_IN_AGGR_P (value))
1029: {
1030: error_with_decl (value, "`%s' is already defined in aggregate scope");
1031: return void_type_node;
1032: }
1033:
1034: GNU_xref_member (current_class_name, value);
1035:
1036: if (TREE_STATIC (value))
1037: {
1038: error_with_decl (value, "static member `%s' cannot be a bitfield");
1039: return NULL_TREE;
1040: }
1041: finish_decl (value, NULL_TREE, NULL_TREE, 0);
1042: /* detect invalid field size. */
1043: if (TREE_CODE (width) == CONST_DECL)
1044: width = DECL_INITIAL (width);
1045: else if (TREE_READONLY_DECL_P (width))
1046: width = decl_constant_value (width);
1047:
1048: if (TREE_CODE (width) != INTEGER_CST)
1049: {
1050: error_with_decl (value, "structure field `%s' width not an integer constant");
1051: DECL_INITIAL (value) = NULL;
1052: }
1053: else
1054: {
1055: DECL_INITIAL (value) = width;
1056: DECL_BIT_FIELD (value) = 1;
1057: }
1058: DECL_IN_AGGR_P (value) = 1;
1059: return value;
1060: }
1061:
1062: /* Like GROKFIELD, except that the declarator has been
1063: buried in DECLSPECS. Find the declarator, and
1064: return something that looks like it came from
1065: GROKFIELD. */
1066: tree
1067: groktypefield (declspecs, parmlist)
1068: tree declspecs;
1069: tree parmlist;
1070: {
1071: tree spec = declspecs;
1072: tree prev = NULL_TREE;
1073:
1074: tree type_id = NULL_TREE;
1075: tree quals = NULL_TREE;
1076: tree lengths = NULL_TREE;
1077: tree decl = NULL_TREE;
1078:
1079: while (spec)
1080: {
1081: register tree id = TREE_VALUE (spec);
1082:
1083: if (TREE_CODE (spec) != TREE_LIST)
1084: /* Certain parse errors slip through. For example,
1085: `int class ();' is not caught by the parser. Try
1086: weakly to recover here. */
1087: return NULL_TREE;
1088:
1089: if (TREE_CODE (id) == TYPE_DECL
1090: || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
1091: {
1092: /* We have a constructor/destructor or
1093: conversion operator. Use it. */
1094: if (prev)
1095: TREE_CHAIN (prev) = TREE_CHAIN (spec);
1096: else
1097: declspecs = TREE_CHAIN (spec);
1098:
1099: type_id = id;
1100: goto found;
1101: }
1102: prev = spec;
1103: spec = TREE_CHAIN (spec);
1104: }
1105:
1106: /* Nope, we have a conversion operator to a scalar type. */
1107: spec = declspecs;
1108: while (spec)
1109: {
1110: tree id = TREE_VALUE (spec);
1111:
1112: if (TREE_CODE (id) == IDENTIFIER_NODE)
1113: {
1114: if (id == ridpointers[(int)RID_INT]
1115: || id == ridpointers[(int)RID_DOUBLE]
1116: || id == ridpointers[(int)RID_FLOAT])
1117: {
1118: if (type_id)
1119: error ("extra `%s' ignored",
1120: IDENTIFIER_POINTER (id));
1121: else
1122: type_id = id;
1123: }
1124: else if (id == ridpointers[(int)RID_LONG]
1125: || id == ridpointers[(int)RID_SHORT]
1126: || id == ridpointers[(int)RID_CHAR])
1127: {
1128: lengths = tree_cons (NULL_TREE, id, lengths);
1129: }
1130: else if (id == ridpointers[(int)RID_VOID])
1131: {
1132: if (type_id)
1133: error ("spurious `void' type ignored");
1134: else
1135: error ("conversion to `void' type invalid");
1136: }
1137: else if (id == ridpointers[(int)RID_AUTO]
1138: || id == ridpointers[(int)RID_REGISTER]
1139: || id == ridpointers[(int)RID_TYPEDEF]
1140: || id == ridpointers[(int)RID_CONST]
1141: || id == ridpointers[(int)RID_VOLATILE])
1142: {
1143: error ("type specifier `%s' used invalidly",
1144: IDENTIFIER_POINTER (id));
1145: }
1146: else if (id == ridpointers[(int)RID_FRIEND]
1147: || id == ridpointers[(int)RID_VIRTUAL]
1148: || id == ridpointers[(int)RID_INLINE]
1149: || id == ridpointers[(int)RID_UNSIGNED]
1150: || id == ridpointers[(int)RID_SIGNED]
1151: || id == ridpointers[(int)RID_STATIC]
1152: || id == ridpointers[(int)RID_EXTERN])
1153: {
1154: quals = tree_cons (NULL_TREE, id, quals);
1155: }
1156: else
1157: {
1158: /* Happens when we have a global typedef
1159: and a class-local member function with
1160: the same name. */
1161: type_id = id;
1162: goto found;
1163: }
1164: }
1165: else if (TREE_CODE (id) == RECORD_TYPE)
1166: {
1167: type_id = TYPE_NAME (id);
1168: if (TREE_CODE (type_id) == TYPE_DECL)
1169: type_id = DECL_NAME (type_id);
1170: if (type_id == NULL_TREE)
1171: error ("identifier for aggregate type conversion omitted");
1172: }
1173: else
1174: assert (0);
1175: spec = TREE_CHAIN (spec);
1176: }
1177:
1178: if (type_id)
1179: {
1180: declspecs = chainon (lengths, quals);
1181: }
1182: else if (lengths)
1183: {
1184: if (TREE_CHAIN (lengths))
1185: error ("multiple length specifiers");
1186: type_id = ridpointers[(int)RID_INT];
1187: declspecs = chainon (lengths, quals);
1188: }
1189: else if (quals)
1190: {
1191: error ("no type given, defaulting to `operator int ...'");
1192: type_id = ridpointers[(int)RID_INT];
1193: declspecs = quals;
1194: }
1195: else return NULL_TREE;
1196: found:
1197: decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
1198: declspecs, FIELD, 0, NULL_TREE);
1199: if (decl == NULL_TREE)
1200: return NULL_TREE;
1201:
1202: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
1203: {
1204: /* Need a fresh node here so that we don't get circularity
1205: when we link these together. */
1206: decl = copy_node (decl);
1207: }
1208:
1209: if (decl == void_type_node
1210: || (TREE_CODE (decl) == FUNCTION_DECL
1211: && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
1212: /* bunch of friends. */
1213: return decl;
1214:
1215: if (DECL_IN_AGGR_P (decl))
1216: {
1217: error_with_decl (decl, "`%s' already defined in aggregate scope");
1218: return void_type_node;
1219: }
1220:
1221: finish_decl (decl, NULL_TREE, NULL_TREE, 0);
1222:
1223: /* If this declaration is common to another declaration
1224: complain about such redundancy, and return NULL_TREE
1225: so that we don't build a circular list. */
1226: if (DECL_CHAIN (decl))
1227: {
1228: error_with_decl (decl, "function `%s' declared twice in aggregate");
1229: return NULL_TREE;
1230: }
1231: DECL_IN_AGGR_P (decl) = 1;
1232: return decl;
1233: }
1234:
1235: /* The precedence rules of this grammar (or any other deterministic LALR
1236: grammar, for that matter), place the CALL_EXPR somewhere where we
1237: may not want it. The solution is to grab the first CALL_EXPR we see,
1238: pretend that that is the one that belongs to the parameter list of
1239: the type conversion function, and leave everything else alone.
1240: We pull it out in place.
1241:
1242: CALL_REQUIRED is non-zero if we should complain if a CALL_EXPR
1243: does not appear in DECL. */
1244: tree
1245: grokoptypename (decl, call_required)
1246: tree decl;
1247: int call_required;
1248: {
1249: tree tmp, last;
1250:
1251: assert (TREE_CODE (decl) == TYPE_EXPR);
1252:
1253: tmp = TREE_OPERAND (decl, 0);
1254: last = NULL_TREE;
1255:
1256: while (tmp)
1257: {
1258: switch (TREE_CODE (tmp))
1259: {
1260: case CALL_EXPR:
1261: {
1262: tree parms = TREE_OPERAND (tmp, 1);
1263:
1264: if (last)
1265: TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
1266: else
1267: TREE_OPERAND (decl, 0) = TREE_OPERAND (tmp, 0);
1268: if (parms
1269: && TREE_CODE (TREE_VALUE (parms)) == TREE_LIST)
1270: TREE_VALUE (parms)
1271: = grokdeclarator (TREE_VALUE (TREE_VALUE (parms)),
1272: TREE_PURPOSE (TREE_VALUE (parms)),
1273: TYPENAME, 0, NULL_TREE);
1274: if (parms)
1275: {
1276: if (TREE_VALUE (parms) != void_type_node)
1277: error ("operator <typename> requires empty parameter list");
1278: else
1279: /* Canonicalize parameter lists. */
1280: TREE_OPERAND (tmp, 1) = void_list_node;
1281: }
1282:
1283: last = grokdeclarator (TREE_OPERAND (decl, 0),
1284: TREE_TYPE (decl),
1285: TYPENAME, 0, NULL_TREE);
1286: TREE_OPERAND (tmp, 0) = build_typename_overload (last);
1287: TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
1288: return tmp;
1289: }
1290:
1291: case INDIRECT_REF:
1292: case ADDR_EXPR:
1293: case ARRAY_REF:
1294: break;
1295:
1296: case SCOPE_REF:
1297: /* This is legal when declaring a conversion to
1298: something of type pointer-to-member. */
1299: if (TREE_CODE (TREE_OPERAND (tmp, 1)) == INDIRECT_REF)
1300: {
1301: tmp = TREE_OPERAND (tmp, 1);
1302: }
1303: else
1304: {
1305: #if 0
1306: /* We may need to do this if grokdeclarator cannot handle this. */
1307: error ("type `member of class %s' invalid return type",
1308: TYPE_NAME_STRING (TREE_OPERAND (tmp, 0)));
1309: TREE_OPERAND (tmp, 1) = build_parse_node (INDIRECT_REF, TREE_OPERAND (tmp, 1));
1310: #endif
1311: tmp = TREE_OPERAND (tmp, 1);
1312: }
1313: break;
1314:
1315: default:
1316: assert (0);
1317: }
1318: last = tmp;
1319: tmp = TREE_OPERAND (tmp, 0);
1320: }
1321:
1322: if (call_required)
1323: error ("operator <typename> construct requires parameter list");
1324:
1325: last = grokdeclarator (TREE_OPERAND (decl, 0),
1326: TREE_TYPE (decl),
1327: TYPENAME, 0, NULL_TREE);
1328: tmp = build_parse_node (CALL_EXPR, build_typename_overload (last),
1329: void_list_node, NULL_TREE);
1330: TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
1331: return tmp;
1332: }
1333:
1.1.1.2 ! root 1334: /* When a function is declared with an initializer,
1.1 root 1335: do the right thing. Currently, there are two possibilities:
1336:
1337: class B
1338: {
1339: public:
1340: // initialization possibility #1.
1341: virtual void f () = 0;
1342: int g ();
1343: };
1344:
1345: class D1 : B
1346: {
1347: public:
1348: int d1;
1349: // error, no f ();
1350: };
1351:
1352: class D2 : B
1353: {
1354: public:
1355: int d2;
1356: void f ();
1357: };
1358:
1359: class D3 : B
1360: {
1361: public:
1362: int d3;
1363: // initialization possibility #2
1364: void f () = B::f;
1365: };
1366:
1367: */
1368:
1369: static void
1370: grok_function_init (decl, init)
1371: tree decl;
1372: tree init;
1373: {
1374: /* An initializer for a function tells how this function should
1375: be inherited. */
1376: tree type = TREE_TYPE (decl);
1377: extern tree abort_fndecl;
1378:
1379: if (TREE_CODE (type) == FUNCTION_TYPE)
1380: error_with_decl (decl, "initializer specified for non-member function `%s'");
1381: else if (DECL_VINDEX (decl) == NULL_TREE)
1382: error_with_decl (decl, "initializer specified for non-virtual method `%s'");
1383: else if (integer_zerop (init))
1384: {
1385: /* Mark this function as being "defined". */
1386: DECL_INITIAL (decl) = error_mark_node;
1387: /* Give this node rtl from `abort'. */
1388: DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1389: DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1390: }
1391: else if (TREE_CODE (init) == OFFSET_REF
1392: && TREE_OPERAND (init, 0) == NULL_TREE
1393: && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1394: {
1395: tree basetype = DECL_CLASS_CONTEXT (init);
1396: tree basefn = TREE_OPERAND (init, 1);
1397: if (TREE_CODE (basefn) != FUNCTION_DECL)
1398: error_with_decl (decl, "non-method initializer invalid for method `%s'");
1399: else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1400: sorry ("base member function from other than first base class");
1401: else
1402: {
1403: tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1404: if (binfo == error_mark_node)
1405: ;
1406: else if (binfo == 0)
1407: error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1408: TYPE_METHOD_BASETYPE (type));
1409: else
1410: {
1411: /* Mark this function as being defined,
1412: and give it new rtl. */
1413: DECL_INITIAL (decl) = error_mark_node;
1414: DECL_RTL (decl) = DECL_RTL (basefn);
1415: }
1416: }
1417: }
1418: else
1419: error_with_decl (decl, "invalid initializer for virtual method `%s'");
1420: }
1421:
1422: /* When we get a declaration of the form
1423:
1424: type cname::fname ...
1425:
1426: the node for `cname::fname' gets built here in a special way.
1427: Namely, we push into `cname's scope. When this declaration is
1428: processed, we pop back out. */
1429: tree
1430: build_push_scope (cname, name)
1431: tree cname;
1432: tree name;
1433: {
1434: extern int current_class_depth;
1435: tree ctype, rval;
1436:
1437: if (cname == error_mark_node)
1438: return error_mark_node;
1439:
1440: ctype = IDENTIFIER_TYPE_VALUE (cname);
1441:
1442: if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
1443: {
1444: error ("`%s' not defined as aggregate type", IDENTIFIER_POINTER (cname));
1445: return name;
1446: }
1447:
1448: rval = build_parse_node (SCOPE_REF, cname, name);
1449:
1450: /* Don't need to push the scope here, but we do need to return
1451: a SCOPE_REF for something like
1452:
1453: class foo { typedef int bar (foo::*foo_fn)(void); }; */
1454: if (ctype == current_class_type)
1455: return rval;
1456:
1457: pushclass (ctype, 3);
1458: TREE_COMPLEXITY (rval) = current_class_depth;
1459: return rval;
1460: }
1461:
1462: /* CONSTRUCTOR_NAME:
1463: Return the name for the constructor (or destructor) for the specified
1464: class. Argument can be RECORD_TYPE, TYPE_DECL, or IDENTIFIER_NODE. */
1465: tree
1466: constructor_name (thing)
1467: tree thing;
1468: {
1469: tree t;
1470: if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
1471: return DECL_NAME (UPT_TEMPLATE (thing));
1472: if (TREE_CODE (thing) == RECORD_TYPE || TREE_CODE (thing) == UNION_TYPE)
1473: thing = TYPE_NAME (thing);
1474: if (TREE_CODE (thing) == TYPE_DECL
1475: || (TREE_CODE (thing) == TEMPLATE_DECL
1476: && DECL_TEMPLATE_IS_CLASS (thing)))
1477: thing = DECL_NAME (thing);
1478: assert (TREE_CODE (thing) == IDENTIFIER_NODE);
1479: t = IDENTIFIER_TEMPLATE (thing);
1480: if (!t)
1481: return thing;
1482: t = TREE_PURPOSE (t);
1483: return DECL_NAME (t);
1484: }
1485:
1486: /* Cache the value of this class's main virtual function table pointer
1487: in a register variable. This will save one indirection if a
1488: more than one virtual function call is made this function. */
1489: void
1490: setup_vtbl_ptr ()
1491: {
1492: extern struct rtx_def *base_init_insns;
1493:
1494: if (base_init_insns == 0
1495: && DECL_CONSTRUCTOR_P (current_function_decl))
1496: emit_base_init (current_class_type, 0);
1497:
1498: if ((flag_this_is_variable & 1) == 0
1499: && optimize
1500: && current_class_type
1501: && CLASSTYPE_VSIZE (current_class_type)
1502: && ! DECL_STATIC_FUNCTION_P (current_function_decl))
1503: {
1504: tree vfield = build_vfield_ref (C_C_D, current_class_type);
1505: current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
1506: DECL_RTL (current_vtable_decl) = 0;
1507: DECL_INITIAL (current_vtable_decl) = error_mark_node;
1508: /* Have to cast the initializer, since it may have come from a
1509: more base class then we ascribe CURRENT_VTABLE_DECL to be. */
1510: finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield), 0, 0);
1511: current_vtable_decl = build_indirect_ref (current_vtable_decl, 0);
1512: }
1513: else
1514: current_vtable_decl = NULL_TREE;
1515: }
1516:
1517: /* Record the existence of an addressable inline function. */
1518: void
1519: mark_inline_for_output (decl)
1520: tree decl;
1521: {
1522: if (DECL_PENDING_INLINE_INFO (decl) != 0
1523: && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
1524: {
1525: struct pending_inline *t = pending_inlines;
1526: assert (DECL_SAVED_INSNS (decl) == 0);
1527: while (t)
1528: {
1529: if (t == DECL_PENDING_INLINE_INFO (decl))
1530: break;
1531: t = t->next;
1532: }
1533: if (t == 0)
1534: {
1535: t = DECL_PENDING_INLINE_INFO (decl);
1536: t->next = pending_inlines;
1537: pending_inlines = t;
1538: }
1539: DECL_PENDING_INLINE_INFO (decl) = 0;
1540: }
1541: pending_addressable_inlines = perm_tree_cons (NULL_TREE, decl,
1542: pending_addressable_inlines);
1543: }
1544:
1545: void
1546: clear_temp_name ()
1547: {
1548: temp_name_counter = 0;
1549: }
1550:
1551: /* Hand off a unique name which can be used for variable we don't really
1552: want to know about anyway, for example, the anonymous variables which
1553: are needed to make references work. Declare this thing so we can use it.
1554: The variable created will be of type TYPE.
1555:
1556: STATICP is nonzero if this variable should be static. */
1557:
1558: tree
1559: get_temp_name (type, staticp)
1560: tree type;
1561: int staticp;
1562: {
1563: char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
1564: tree decl;
1565: int temp = 0;
1566: int toplev = global_bindings_p ();
1567:
1568: push_obstacks_nochange ();
1569: if (toplev || staticp)
1570: {
1571: end_temporary_allocation ();
1572: sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
1573: decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
1574: }
1575: else
1576: {
1577: sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
1578: decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1579: }
1580: TREE_USED (decl) = 1;
1581: TREE_STATIC (decl) = staticp;
1582:
1583: /* If this is a local variable, then lay out its rtl now.
1584: Otherwise, callers of this function are responsible for dealing
1585: with this variable's rtl. */
1586: if (! toplev)
1587: {
1588: expand_decl (decl);
1589: expand_decl_init (decl);
1590: }
1591: pop_obstacks ();
1592:
1593: return decl;
1594: }
1595:
1596: /* Get a variable which we can use for multiple assignments.
1597: It is not entered into current_binding_level, because
1598: that breaks things when it comes time to do final cleanups
1599: (which take place "outside" the binding contour of the function). */
1600: tree
1601: get_temp_regvar (type, init)
1602: tree type, init;
1603: {
1604: static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
1605: tree decl;
1606:
1607: sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
1608: decl = build_decl (VAR_DECL, get_identifier (buf), type);
1609: TREE_USED (decl) = 1;
1610: TREE_REGDECL (decl) = 1;
1611:
1612: if (init)
1613: store_init_value (decl, init);
1614:
1615: /* We can expand these without fear, since they cannot need
1616: constructors or destructors. */
1617: expand_decl (decl);
1618: expand_decl_init (decl);
1619:
1620: if (type_needs_gc_entry (type))
1621: DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
1622:
1623: return decl;
1624: }
1625:
1626: /* Make the macro TEMP_NAME_P available to units which do not
1627: include c-tree.h. */
1628: int
1629: temp_name_p (decl)
1630: tree decl;
1631: {
1632: return TEMP_NAME_P (decl);
1633: }
1634:
1635: /* Finish off the processing of a UNION_TYPE structure.
1636: If there are static members, then all members are
1637: static, and must be laid out together. If the
1.1.1.2 ! root 1638: union is an anonymous union, we arrange for that
1.1 root 1639: as well. PUBLICP is nonzero if this union is
1640: not declared static. */
1641: void
1642: finish_anon_union (anon_union_decl)
1643: tree anon_union_decl;
1644: {
1645: tree type = TREE_TYPE (anon_union_decl);
1.1.1.2 ! root 1646: tree field, main_decl = NULL_TREE;
1.1 root 1647: tree elems = NULL_TREE;
1648: int public_p = TREE_PUBLIC (anon_union_decl);
1649: int static_p = TREE_STATIC (anon_union_decl);
1650: int external_p = TREE_EXTERNAL (anon_union_decl);
1651:
1652: if ((field = TYPE_FIELDS (type)) == NULL_TREE)
1653: return;
1654:
1655: if (public_p && (static_p || external_p))
1656: error ("optimizer cannot handle global anonymous unions");
1657:
1658: while (field)
1659: {
1.1.1.2 ! root 1660: tree decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
1.1 root 1661: /* tell `pushdecl' that this is not tentative. */
1662: DECL_INITIAL (decl) = error_mark_node;
1663: TREE_PUBLIC (decl) = public_p;
1664: TREE_STATIC (decl) = static_p;
1665: TREE_EXTERNAL (decl) = external_p;
1666: decl = pushdecl (decl);
1.1.1.2 ! root 1667:
! 1668: /* Only write out one anon union element--choose the one that
! 1669: can hold them all. */
! 1670: if (main_decl == NULL_TREE
! 1671: && DECL_SIZE (decl) == DECL_SIZE (anon_union_decl))
! 1672: {
! 1673: main_decl = decl;
! 1674: }
! 1675: else
! 1676: {
! 1677: /* ??? This causes there to be no debug info written out
! 1678: about this decl. */
! 1679: TREE_ASM_WRITTEN (decl) = 1;
! 1680: }
! 1681:
1.1 root 1682: DECL_INITIAL (decl) = NULL_TREE;
1683: /* If there's a cleanup to do, it belongs in the
1684: TREE_PURPOSE of the following TREE_LIST. */
1685: elems = tree_cons (NULL_TREE, decl, elems);
1686: TREE_TYPE (elems) = type;
1687: field = TREE_CHAIN (field);
1688: }
1689: if (static_p)
1.1.1.2 ! root 1690: {
! 1691: make_decl_rtl (main_decl, 0, global_bindings_p ());
! 1692: DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
! 1693: }
1.1 root 1694:
1695: /* The following call assumes that there are never any cleanups
1696: for anonymous unions--a reasonable assumption. */
1697: expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
1698:
1699: if (flag_cadillac)
1.1.1.2 ! root 1700: cadillac_finish_anon_union (anon_union_decl);
1.1 root 1701: }
1702:
1703: /* Finish and output a table which is generated by the compiler.
1704: NAME is the name to give the table.
1705: TYPE is the type of the table entry.
1706: INIT is all the elements in the table.
1707: PUBLICP is non-zero if this table should be given external visibility. */
1708: tree
1709: finish_table (name, type, init, publicp)
1710: tree name, type, init;
1711: {
1712: tree itype, atype, decl;
1713: static tree empty_table;
1714: int is_empty = 0;
1715: tree asmspec;
1716:
1717: itype = build_index_type (size_int (list_length (init) - 1));
1718: atype = build_cplus_array_type (type, itype);
1719: layout_type (atype);
1720:
1721: if (TREE_VALUE (init) == integer_zero_node
1722: && TREE_CHAIN (init) == NULL_TREE)
1723: {
1724: if (empty_table == NULL_TREE)
1725: {
1726: empty_table = get_temp_name (atype, 1);
1727: init = build (CONSTRUCTOR, atype, NULL_TREE, init);
1728: TREE_CONSTANT (init) = 1;
1729: TREE_STATIC (init) = 1;
1730: DECL_INITIAL (empty_table) = init;
1731: asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
1732: IDENTIFIER_POINTER (DECL_NAME (empty_table)));
1733: finish_decl (empty_table, init, asmspec, 0);
1734: }
1735: is_empty = 1;
1736: }
1737:
1738: if (name == NULL_TREE)
1739: {
1740: if (is_empty)
1741: return empty_table;
1742: decl = get_temp_name (atype, 1);
1743: }
1744: else
1745: {
1746: decl = build_decl (VAR_DECL, name, atype);
1747: decl = pushdecl (decl);
1748: TREE_STATIC (decl) = 1;
1749: }
1750:
1751: if (is_empty == 0)
1752: {
1753: TREE_PUBLIC (decl) = publicp;
1754: init = build (CONSTRUCTOR, atype, NULL_TREE, init);
1755: TREE_CONSTANT (init) = 1;
1756: TREE_STATIC (init) = 1;
1757: DECL_INITIAL (decl) = init;
1758: asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
1759: IDENTIFIER_POINTER (DECL_NAME (decl)));
1760: }
1761: else
1762: {
1763: /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
1764: TREE_EXTERNAL (decl) = 1;
1765: TREE_STATIC (decl) = 0;
1766: init = 0;
1767: asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
1768: IDENTIFIER_POINTER (DECL_NAME (empty_table)));
1769: }
1770:
1771: finish_decl (decl, init, asmspec, 0);
1772: return decl;
1773: }
1774:
1775: /* Finish processing a builtin type TYPE. It's name is NAME,
1776: its fields are in the array FIELDS. LEN is the number of elements
1777: in FIELDS.
1778:
1779: It is given the same alignment as ALIGN_TYPE. */
1780: void
1781: finish_builtin_type (type, name, fields, len, align_type)
1782: tree type;
1783: char *name;
1784: tree fields[];
1785: tree align_type;
1786: {
1787: register int i;
1788:
1789: TYPE_FIELDS (type) = fields[0];
1790: for (i = 0; i < len; i++)
1791: {
1792: layout_type (TREE_TYPE (fields[i]));
1793: DECL_FIELD_CONTEXT (fields[i]) = type;
1794: TREE_CHAIN (fields[i]) = fields[i+1];
1795: }
1796: DECL_FIELD_CONTEXT (fields[i]) = type;
1797: DECL_CLASS_CONTEXT (fields[i]) = type;
1798: TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
1799: layout_type (type);
1.1.1.2 ! root 1800: #if 0 /* not yet, should get fixed properly later */
! 1801: TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
! 1802: #else
1.1 root 1803: TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
1.1.1.2 ! root 1804: #endif
1.1 root 1805: layout_decl (TYPE_NAME (type), 0);
1806: }
1807:
1.1.1.2 ! root 1808: /* Auxiliary functions to make type signatures for
1.1 root 1809: `operator new' and `operator delete' correspond to
1810: what compiler will be expecting. */
1811:
1812: extern tree sizetype;
1813:
1814: tree
1815: coerce_new_type (ctype, type)
1816: tree ctype;
1817: tree type;
1818: {
1819: int e1 = 0, e2 = 0;
1820:
1821: if (TREE_CODE (type) == METHOD_TYPE)
1822: type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
1823: if (TREE_TYPE (type) != ptr_type_node)
1824: e1 = 1, error ("`operator new' must return type `void *'");
1825:
1826: /* Technically the type must be `size_t', but we may not know
1827: what that is. */
1828: if (TYPE_ARG_TYPES (type) == NULL_TREE)
1829: e1 = 1, error ("`operator new' takes type `size_t' parameter");
1830: else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
1831: || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
1832: e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
1833: if (e2)
1834: type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
1835: else if (e1)
1836: type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
1837: return type;
1838: }
1839:
1840: tree
1841: coerce_delete_type (ctype, type)
1842: tree ctype;
1843: tree type;
1844: {
1845: int e1 = 0, e2 = 0, e3 = 0;
1846: tree arg_types = TYPE_ARG_TYPES (type);
1847:
1848: if (TREE_CODE (type) == METHOD_TYPE)
1849: {
1850: type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
1851: arg_types = TREE_CHAIN (arg_types);
1852: }
1853: if (TREE_TYPE (type) != void_type_node)
1854: e1 = 1, error ("`operator delete' must return type `void'");
1855: if (arg_types == NULL_TREE
1856: || TREE_VALUE (arg_types) != ptr_type_node)
1857: e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
1858:
1859: if (arg_types
1860: && TREE_CHAIN (arg_types)
1861: && TREE_CHAIN (arg_types) != void_list_node)
1862: {
1863: /* Again, technically this argument must be `size_t', but again
1864: we may not know what that is. */
1865: tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
1866: if (TREE_CODE (t2) != INTEGER_TYPE
1867: || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
1868: e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
1869: else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
1870: {
1871: e3 = 1;
1872: if (TREE_CHAIN (TREE_CHAIN (arg_types)))
1873: error ("too many arguments in declaration of `operator delete'");
1874: else
1875: error ("`...' invalid in specification of `operator delete'");
1876: }
1877: }
1878: if (e3)
1879: arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
1880: else if (e3 |= e2)
1881: {
1882: if (arg_types == NULL_TREE)
1883: arg_types = void_list_node;
1884: else
1885: arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
1886: }
1887: else e3 |= e1;
1888:
1889: if (e3)
1890: type = build_function_type (void_type_node, arg_types);
1891:
1892: return type;
1893: }
1894:
1895: static void
1896: write_vtable_entries (decl)
1897: tree decl;
1898: {
1899: tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
1900:
1901: if (flag_dossier)
1902: entries = TREE_CHAIN (entries);
1903:
1904: for (; entries; entries = TREE_CHAIN (entries))
1905: {
1906: tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
1907: tree fn = TREE_OPERAND (fnaddr, 0);
1908: if (! TREE_ASM_WRITTEN (fn) && DECL_SAVED_INSNS (fn))
1909: {
1910: if (TREE_PUBLIC (DECL_CLASS_CONTEXT (fn)))
1911: TREE_PUBLIC (fn) = 1;
1912: TREE_ADDRESSABLE (fn) = 1;
1913: output_inline_function (fn);
1914: }
1915: else
1916: assemble_external (fn);
1917: }
1918: }
1919:
1920: static void
1921: finish_vtable_typedecl (prev, vars)
1922: tree prev, vars;
1923: {
1924: tree decl = TYPE_BINFO_VTABLE (TREE_TYPE (vars));
1925:
1926: /* If we are controlled by `+e2', obey. */
1927: if (write_virtuals == 2)
1928: {
1929: tree binfo = value_member (DECL_NAME (vars), pending_vtables);
1930: if (binfo)
1931: TREE_PURPOSE (binfo) = void_type_node;
1932: else
1933: decl = NULL_TREE;
1934: }
1935: /* If this type has inline virtual functions, then
1936: write those functions out now. */
1937: if (decl && write_virtuals >= 0
1938: && (TREE_PUBLIC (decl) || (! TREE_EXTERNAL (decl) && TREE_USED (decl))))
1939: write_vtable_entries (decl);
1940: }
1941:
1942: static void
1943: finish_vtable_vardecl (prev, vars)
1944: tree prev, vars;
1945: {
1946: if (write_virtuals < 0)
1947: ;
1948: else if (write_virtuals == 0
1949: ? TREE_USED (vars)
1950: : (TREE_PUBLIC (vars)
1951: || (! TREE_EXTERNAL (vars) && TREE_USED (vars))))
1952: {
1953: extern tree the_null_vtable_entry;
1954:
1955: /* Stuff this virtual function table's size into
1956: `pfn' slot of `the_null_vtable_entry'. */
1957: tree nelts = array_type_nelts (TREE_TYPE (vars));
1958: SET_FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry, nelts);
1959: /* Kick out the dossier before writing out the vtable. */
1960: if (flag_dossier)
1961: rest_of_decl_compilation (TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))))), 0), 0, 1, 1);
1962:
1963: /* Write it out. */
1964: write_vtable_entries (vars);
1965: if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
1966: store_init_value (vars, DECL_INITIAL (vars));
1967: rest_of_decl_compilation (vars, 0, 1, 1);
1968: }
1969: /* We know that PREV must be non-zero here. */
1970: TREE_CHAIN (prev) = TREE_CHAIN (vars);
1971: }
1972:
1973: void
1974: walk_vtables (typedecl_fn, vardecl_fn)
1975: register void (*typedecl_fn)();
1976: register void (*vardecl_fn)();
1977: {
1978: tree prev, vars;
1979:
1980: for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
1981: {
1982: if (TREE_CODE (vars) == TYPE_DECL
1983: && TYPE_LANG_SPECIFIC (TREE_TYPE (vars))
1984: && CLASSTYPE_VSIZE (TREE_TYPE (vars)))
1985: {
1986: if (typedecl_fn) (*typedecl_fn) (prev, vars);
1987: }
1988: else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
1989: {
1990: if (vardecl_fn) (*vardecl_fn) (prev, vars);
1991: }
1992: else
1993: prev = vars;
1994: }
1995: }
1996:
1997: extern int parse_time, varconst_time;
1998:
1999: #define TIMEVAR(VAR, BODY) \
2000: do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2001:
2002: /* This routine is called from the last rule in yyparse ().
2003: Its job is to create all the code needed to initialize and
2004: destroy the global aggregates. We do the destruction
2005: first, since that way we only need to reverse the decls once. */
2006:
2007: void
2008: finish_file ()
2009: {
2010: extern struct rtx_def *const0_rtx;
2011: extern int lineno;
2012: extern struct _iob *asm_out_file;
2013: int start_time, this_time;
2014: char *init_function_name;
2015:
2016: char *buf;
2017: char *p;
2018: tree fnname;
2019: tree vars = static_aggregates;
2020: int needs_cleaning = 0, needs_messing_up = 0;
2021:
2022: if (main_input_filename == 0)
2023: main_input_filename = input_filename;
2024: if (!first_global_object_name)
2025: first_global_object_name = main_input_filename;
2026:
2027: buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT)
2028: + strlen (first_global_object_name));
2029:
2030: if (flag_detailed_statistics)
2031: dump_tree_statistics ();
2032:
2033: /* Bad parse errors. Just forget about it. */
1.1.1.2 ! root 2034: if (! global_bindings_p () || current_class_type)
1.1 root 2035: return;
2036:
2037: start_time = get_run_time ();
2038:
2039: /* Push into C language context, because that's all
2040: we'll need here. */
2041: push_lang_context (lang_name_c);
2042:
2043: /* Set up the name of the file-level functions we may need. */
2044: /* Use a global object (which is already required to be unique over
2045: the program) rather than the file name (which imposes extra
2046: constraints). -- [email protected], 10 Jan 1990. */
2047: sprintf (buf, FILE_FUNCTION_FORMAT, first_global_object_name);
2048:
2049: /* Don't need to pull wierd characters out of global names. */
2050: if (first_global_object_name == main_input_filename)
2051: {
2052: for (p = buf+11; *p; p++)
2053: if (! ((*p >= '0' && *p <= '9')
2054: #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
2055: #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */
2056: || *p == '.'
2057: #endif
2058: #endif
2059: #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
2060: || *p == '$'
2061: #endif
2062: || (*p >= 'A' && *p <= 'Z')
2063: || (*p >= 'a' && *p <= 'z')))
2064: *p = '_';
2065: }
2066:
2067: /* See if we really need the hassle. */
2068: while (vars && needs_cleaning == 0)
2069: {
2070: tree decl = TREE_VALUE (vars);
2071: tree type = TREE_TYPE (decl);
2072: if (TYPE_NEEDS_DESTRUCTOR (type))
2073: {
2074: needs_cleaning = 1;
2075: needs_messing_up = 1;
2076: break;
2077: }
2078: else
2079: needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
2080: vars = TREE_CHAIN (vars);
2081: }
2082: if (needs_cleaning == 0)
2083: goto mess_up;
2084:
2085: /* Otherwise, GDB can get confused, because in only knows
2086: about source for LINENO-1 lines. */
2087: lineno -= 1;
2088:
2089: fnname = get_identifier (buf);
2090: start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2091: fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2092: store_parm_decls ();
2093:
2094: pushlevel (0);
2095: clear_last_expr ();
2096: push_momentary ();
2097: expand_start_bindings (0);
2098:
2099: /* These must be done in backward order to destroy,
2100: in which they happen to be! */
2101: while (vars)
2102: {
2103: tree decl = TREE_VALUE (vars);
2104: tree type = TREE_TYPE (decl);
2105: tree temp = TREE_PURPOSE (vars);
2106:
2107: if (TYPE_NEEDS_DESTRUCTOR (type))
2108: {
2109: if (TREE_STATIC (vars))
2110: expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node), 0);
2111: if (TREE_CODE (type) == ARRAY_TYPE)
2112: temp = decl;
2113: else
2114: {
2115: mark_addressable (decl);
2116: temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
2117: }
2118: temp = build_delete (TREE_TYPE (temp), temp,
2119: integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0, 0);
2120: expand_expr_stmt (temp);
2121:
2122: if (TREE_STATIC (vars))
2123: expand_end_cond ();
2124: }
2125: vars = TREE_CHAIN (vars);
2126: }
2127:
2128: expand_end_bindings (getdecls (), 1, 0);
2129: poplevel (1, 0, 1);
2130: pop_momentary ();
2131:
2132: finish_function (lineno, 0);
2133:
2134: assemble_destructor (IDENTIFIER_POINTER (fnname));
2135:
2136: /* if it needed cleaning, then it will need messing up: drop through */
2137:
2138: mess_up:
2139: /* Must do this while we think we are at the top level. */
2140: vars = nreverse (static_aggregates);
2141: if (vars != NULL_TREE)
2142: {
2143: buf[FILE_FUNCTION_PREFIX_LEN] = 'I';
2144:
2145: fnname = get_identifier (buf);
2146: start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2147: fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2148: store_parm_decls ();
2149:
2150: pushlevel (0);
2151: clear_last_expr ();
2152: push_momentary ();
2153: expand_start_bindings (0);
2154:
2155: #ifdef SOS
2156: if (flag_all_virtual == 2)
2157: {
2158: tree decl;
2159: char c = buf[FILE_FUNCTION_PREFIX_LEN];
2160: buf[FILE_FUNCTION_PREFIX_LEN] = 'Z';
2161:
2162: decl = pushdecl (build_lang_decl (FUNCTION_DECL, get_identifier (buf), default_function_type));
2163: finish_decl (decl, NULL_TREE, NULL_TREE, 0);
2164: expand_expr_stmt (build_function_call (decl, NULL_TREE));
2165: buf[FILE_FUNCTION_PREFIX_LEN] = c;
2166: }
2167: #endif
2168:
2169: while (vars)
2170: {
2171: tree decl = TREE_VALUE (vars);
2172: tree init = TREE_PURPOSE (vars);
2173:
2174: /* If this was a static attribute within some function's scope,
2175: then don't initialize it here. Also, don't bother
2176: with initializers that contain errors. */
2177: if (TREE_STATIC (vars)
2178: || (init && TREE_CODE (init) == TREE_LIST
2179: && value_member (error_mark_node, init)))
2180: {
2181: vars = TREE_CHAIN (vars);
2182: continue;
2183: }
2184:
2185: if (TREE_CODE (decl) == VAR_DECL)
2186: {
2187: /* Set these global variables so that GDB at least puts
2188: us near the declaration which required the initialization. */
2189: input_filename = DECL_SOURCE_FILE (decl);
2190: lineno = DECL_SOURCE_LINE (decl);
2191: emit_note (input_filename, lineno);
2192:
2193: if (init)
2194: {
2195: if (TREE_CODE (init) == VAR_DECL)
2196: {
2197: /* This behavior results when there are
2198: multiple declarations of an aggregate,
2199: the last of which defines it. */
2200: if (DECL_RTL (init) == DECL_RTL (decl))
2201: {
2202: assert (DECL_INITIAL (decl) == error_mark_node
2203: || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
2204: && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE));
2205: init = DECL_INITIAL (init);
2206: if (TREE_CODE (init) == CONSTRUCTOR
2207: && CONSTRUCTOR_ELTS (init) == NULL_TREE)
2208: init = NULL_TREE;
2209: }
2210: #if 0
2211: else if (TREE_TYPE (decl) == TREE_TYPE (init))
2212: {
2213: #if 1
2214: assert (0);
2215: #else
2216: /* point to real decl's rtl anyway. */
2217: DECL_RTL (init) = DECL_RTL (decl);
2218: assert (DECL_INITIAL (decl) == error_mark_node);
2219: init = DECL_INITIAL (init);
2220: #endif /* 1 */
2221: }
2222: #endif /* 0 */
2223: }
2224: }
2225: if (IS_AGGR_TYPE (TREE_TYPE (decl))
2226: || init == 0
2227: || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2228: expand_aggr_init (decl, init, 0);
2229: else if (TREE_CODE (init) == TREE_VEC)
2230: {
2231: expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2232: TREE_VEC_ELT (init, 1),
2233: TREE_VEC_ELT (init, 2), 0),
2234: const0_rtx, VOIDmode, 0);
2235: free_temp_slots ();
2236: }
2237: else
2238: expand_assignment (decl, init, 0, 0);
2239: }
2240: else if (TREE_CODE (decl) == SAVE_EXPR)
2241: {
2242: if (! PARM_DECL_EXPR (decl))
2243: {
2244: /* a `new' expression at top level. */
2245: expand_expr (decl, const0_rtx, VOIDmode, 0);
2246: free_temp_slots ();
2247: expand_aggr_init (build_indirect_ref (decl, 0), init, 0);
2248: }
2249: }
2250: else if (decl == error_mark_node)
2251: ;
2252: else abort ();
2253: vars = TREE_CHAIN (vars);
2254: }
2255:
2256: expand_end_bindings (getdecls (), 1, 0);
2257: poplevel (1, 0, 1);
2258: pop_momentary ();
2259:
2260: finish_function (lineno, 0);
2261: assemble_constructor (IDENTIFIER_POINTER (fnname));
2262: }
2263:
2264: #ifdef SOS
2265: if (flag_all_virtual == 2)
2266: {
2267: tree __sosDynError = default_conversion (lookup_name (get_identifier ("sosDynError"), 0));
2268:
2269: tree null_string = build1 (ADDR_EXPR, string_type_node, combine_strings (build_string (0, "")));
2270: tree tags = gettags ();
2271: tree decls = getdecls ();
2272: tree entry;
2273: int i;
2274:
2275: entry = NULL_TREE;
2276: for (i = 0; i < 3; i++)
2277: entry = tree_cons (NULL_TREE, integer_zero_node, entry);
2278: zlink = build_tree_list (NULL_TREE, build (CONSTRUCTOR, zlink_type, NULL_TREE, entry));
2279: TREE_CONSTANT (TREE_VALUE (zlink)) = 1;
2280: TREE_STATIC (TREE_VALUE (zlink)) = 1;
2281:
2282: entry = NULL_TREE;
2283: for (i = 0; i < 5; i++)
2284: entry = tree_cons (NULL_TREE, integer_zero_node, entry);
2285: zret = build_tree_list (NULL_TREE, build (CONSTRUCTOR, zret_type, NULL_TREE, entry));
2286: TREE_CONSTANT (TREE_VALUE (zret)) = 1;
2287: TREE_STATIC (TREE_VALUE (zret)) = 1;
2288:
2289: /* Symbols with external visibility (except globally visible
2290: dynamic member functions) into the `zlink' table. */
2291: while (decls)
2292: {
2293: if (TREE_PUBLIC (decls)
2294: && TREE_ASM_WRITTEN (decls)
2295: && (TREE_CODE (decls) != FUNCTION_DECL
2296: || TREE_CODE (TREE_TYPE (decls)) != METHOD_TYPE
2297: || TYPE_DYNAMIC (DECL_CLASS_CONTEXT (decls)) == 0))
2298: {
2299: entry = build (CONSTRUCTOR, zlink_type, NULL_TREE,
2300: tree_cons (NULL_TREE,
2301: build1 (ADDR_EXPR, string_type_node,
2302: combine_strings (build_string (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decls)),
2303: IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decls))))),
2304: tree_cons (NULL_TREE, integer_one_node,
2305: build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, decls, 0)))));
2306: TREE_CONSTANT (entry) = 1;
2307: TREE_STATIC (entry) = 1;
2308: zlink = tree_cons (NULL_TREE, entry, zlink);
2309: }
2310: decls = TREE_CHAIN (decls);
2311: }
2312:
2313: buf[FILE_FUNCTION_PREFIX_LEN] = 'Z';
2314:
2315: fnname = get_identifier (buf);
2316: start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2317: fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2318: store_parm_decls ();
2319:
2320: pushlevel (0);
2321: clear_last_expr ();
2322: push_momentary ();
2323: expand_start_bindings (0);
2324:
2325: {
2326: tree decl, type;
2327: /* Lay out a table static to this function
2328: with information about all text and data that
2329: this file provides. */
2330: tree zlink_table = finish_table (get_identifier ("__ZLINK_tbl"), zlink_type, zlink, 0);
2331: decl = pushdecl (build_decl (VAR_DECL, get_identifier ("_ZLINK_once"), integer_type_node));
2332: TREE_STATIC (decl) = 1;
2333: finish_decl (decl, NULL_TREE, NULL_TREE, 0);
2334: expand_start_cond (truthvalue_conversion (decl), 0);
2335: expand_null_return ();
2336: expand_end_cond ();
2337: finish_stmt ();
2338: expand_expr_stmt (build_modify_expr (decl, NOP_EXPR, integer_one_node));
2339: type = build_function_type (void_type_node, NULL_TREE);
2340: decl = pushdecl (build_lang_decl (FUNCTION_DECL, get_identifier ("_Ztable_from_cfront"), type));
2341: TREE_EXTERNAL (decl) = 1;
2342: finish_decl (decl, NULL_TREE, NULL_TREE, 0);
2343: expand_expr_stmt (build_function_call (decl, build_tree_list (NULL_TREE, zlink_table)));
2344: expand_null_return ();
2345: }
2346: expand_end_bindings (0, 1, 0);
2347: poplevel (1, 0, 1);
2348: pop_momentary ();
2349: finish_function (lineno, 0);
2350:
2351: buf[FILE_FUNCTION_PREFIX_LEN] = 'Y';
2352: fnname = get_identifier (buf);
2353: start_function (build_tree_list (NULL_TREE, get_identifier ("int")),
2354: build_parse_node (INDIRECT_REF, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE)), 0, 0);
2355: fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2356: store_parm_decls ();
2357:
2358: pushlevel (0);
2359: clear_last_expr ();
2360: push_momentary ();
2361: expand_start_bindings (0);
2362:
2363: {
2364: #define SOS_VERSION 2
2365: tree sosVersionNumber = build_int_2 (SOS_VERSION, 0);
2366: tree zret_table;
2367:
2368: /* For each type defined, if is a dynamic type, write out
2369: an entry linking its member functions with their names. */
2370:
2371: while (tags)
2372: {
2373: tree type = TREE_VALUE (tags);
2374: if (TYPE_DYNAMIC (type))
2375: {
2376: /* SOS currently only implements single inheritance,
2377: so we just pick up one string, if this class
2378: has a base class. */
2379: tree base_name = TYPE_BINFO_BASETYPES (type) && TYPE_DYNAMIC (TYPE_BINFO_BASECLASS (type, 0))
2380: ? build1 (ADDR_EXPR, string_type_node, CLASSTYPE_TYPENAME_AS_STRING (TYPE_BINFO_BASETYPE (type, 0)))
2381: : null_string;
2382: tree dyn_table, dyn_entry = NULL_TREE, fns = TYPE_BINFO_VIRTUALS (type);
2383: while (fns)
2384: {
2385: if (TREE_ASM_WRITTEN (TREE_OPERAND (TREE_VALUE (fns), 0)))
2386: dyn_entry = tree_cons (NULL_TREE, TREE_VALUE (fns), dyn_entry);
2387: else
2388: dyn_entry = tree_cons (NULL_TREE, __sosDynError, dyn_entry);
2389: fns = TREE_CHAIN (fns);
2390: }
2391: dyn_entry = nreverse (dyn_entry);
2392: dyn_entry = tree_cons (NULL_TREE, build1 (NOP_EXPR, TYPE_POINTER_TO (default_function_type), sosVersionNumber),
2393: tree_cons (NULL_TREE, integer_zero_node,
2394: tree_cons (NULL_TREE, integer_zero_node,
2395: dyn_entry)));
2396: dyn_table = finish_table (TYPE_IDENTIFIER (type), TYPE_POINTER_TO (default_function_type), dyn_entry, 0);
2397: entry = build (CONSTRUCTOR, zret_type, NULL_TREE,
2398: tree_cons (NULL_TREE, build1 (ADDR_EXPR, string_type_node, CLASSTYPE_TYPENAME_AS_STRING (type)),
2399: tree_cons (NULL_TREE, default_conversion (dyn_table),
2400: tree_cons (NULL_TREE, build_int_2 (CLASSTYPE_VSIZE (type), 0),
2401: tree_cons (NULL_TREE, base_name,
2402: build_tree_list (NULL_TREE, integer_zero_node))))));
2403: TREE_CONSTANT (entry) = 1;
2404: TREE_STATIC (entry) = 1;
2405: zret = tree_cons (NULL_TREE, entry, zret);
2406: }
2407: tags = TREE_CHAIN (tags);
2408: }
2409: zret_table = finish_table (get_identifier ("__Zret"), zret_type, zret, 0);
2410: c_expand_return (convert (build_pointer_type (integer_type_node), default_conversion (zret_table)));
2411: }
2412: expand_end_bindings (0, 1, 0);
2413: poplevel (1, 0, 1);
2414: pop_momentary ();
2415: finish_function (lineno, 0);
2416:
2417: assemble_constructor (fnname);
2418: }
2419: #endif
2420:
2421: /* Done with C language context needs. */
2422: pop_lang_context ();
2423:
2424: /* Now write out any static class variables (which may have since
2425: learned how to be initialized). */
2426: while (pending_statics)
2427: {
2428: tree decl = TREE_VALUE (pending_statics);
2429: if (TREE_USED (decl) == 1
2430: || TREE_READONLY (decl) == 0
2431: || DECL_INITIAL (decl) == 0)
2432: rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
2433: pending_statics = TREE_CHAIN (pending_statics);
2434: }
2435:
2436: this_time = get_run_time ();
2437: parse_time -= this_time - start_time;
2438: varconst_time += this_time - start_time;
2439:
2440: /* Now write out inline functions which had their addresses taken
2441: and which were not declared virtual and which were not declared
2442: `extern inline'. */
2443: while (pending_addressable_inlines)
2444: {
2445: tree decl = TREE_VALUE (pending_addressable_inlines);
2446: if (! TREE_ASM_WRITTEN (decl)
2447: && ! TREE_EXTERNAL (decl)
2448: && DECL_SAVED_INSNS (decl))
2449: output_inline_function (decl);
2450: pending_addressable_inlines = TREE_CHAIN (pending_addressable_inlines);
2451: }
2452:
2453: start_time = get_run_time ();
2454:
2455: /* Now delete from the chain of variables all virtual function tables.
2456: We output them all ourselves, because each will be treated specially. */
2457:
2458: /* Make last thing in global scope not be a virtual function table. */
1.1.1.2 ! root 2459: #if 0 /* not yet, should get fixed properly later */
! 2460: vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
! 2461: #else
1.1 root 2462: vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
1.1.1.2 ! root 2463: #endif
1.1 root 2464: pushdecl (vars);
2465:
2466: walk_vtables (finish_vtable_typedecl, finish_vtable_vardecl);
2467:
2468: if (write_virtuals == 2)
2469: {
2470: /* Now complain about an virtual function tables promised
2471: but not delivered. */
2472: while (pending_vtables)
2473: {
2474: if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
2475: error ("virtual function table for `%s' not defined",
2476: IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
2477: pending_vtables = TREE_CHAIN (pending_vtables);
2478: }
2479: }
2480:
2481: permanent_allocation ();
2482: this_time = get_run_time ();
2483: parse_time -= this_time - start_time;
2484: varconst_time += this_time - start_time;
2485:
2486: if (flag_detailed_statistics)
2487: dump_time_statistics ();
2488: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.