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