Sync usage with man page.
[netbsd-mini2440.git] / gnu / usr.bin / g++ / cc1plus / cplus-decl2.c
blobdcf0fc231ba9fadad5263303a1090bc8f0e5a200
1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@mcc.com)
5 This file is part of GNU CC.
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 1, or (at your option)
10 any later version.
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.
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. */
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. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
29 #include "config.h"
30 #include "tree.h"
31 #include "flags.h"
32 #include "cplus-tree.h"
33 #include "cplus-parse.h"
34 #include "cplus-decl.h"
35 #include "assert.h"
37 #define NULL 0
39 extern tree grokdeclarator ();
40 static void grok_function_init ();
42 /* A list of virtual function tables we must make sure to write out. */
43 tree pending_vtables;
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;
50 extern tree pending_addressable_inlines;
52 /* Used to help generate temporary names which are unique within
53 a function. Reset to 0 by start_function. */
55 static int temp_name_counter;
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;
61 /* The (assembler) name of the first globally-visible object output. */
62 extern char * first_global_object_name;
64 /* C (and C++) language-specific option variables. */
66 /* Nonzero means allow type mismatches in conditional expressions;
67 just make their values `void'. */
69 int flag_cond_mismatch;
71 /* Nonzero means don't recognize the keyword `asm'. */
73 int flag_no_asm;
75 /* Nonzero means do some things the same way PCC does. */
77 int flag_traditional;
79 /* Nonzero means warn about implicit declarations. */
81 int warn_implicit = 1;
83 /* Nonzero means warn about function definitions that default the return type
84 or that use a null return and have a return-type other than void. */
86 int warn_return_type;
88 /* Nonzero means give string constants the type `const char *'
89 to get extra warnings from them. These warnings will be too numerous
90 to be useful, except in thoroughly ANSIfied programs. */
92 int warn_write_strings;
94 /* Nonzero means warn about pointer casts that can drop a type qualifier
95 from the pointer target type. */
97 int warn_cast_qual;
99 /* Nonzero means warn about sizeof(function) or addition/subtraction
100 of function pointers. */
102 int warn_pointer_arith;
104 /* Nonzero means warn for all old-style non-prototype function decls. */
106 int warn_strict_prototypes;
108 /* Non-zero means warn in function declared in derived class has the
109 same name as a virtual in the base class, but fails to match the
110 type signature of any virtual function in the base class. */
111 int warn_overloaded_virtual;
113 /* Non-zero means warn when converting between different enumeral types. */
114 int warn_enum_clash;
116 /* Nonzero means `$' can be in an identifier.
117 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
119 #ifndef DOLLARS_IN_IDENTIFIERS
120 #define DOLLARS_IN_IDENTIFIERS 0
121 #endif
122 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
124 /* Nonzero for -no-strict-prototype switch: do not consider empty
125 argument prototype to mean function takes no arguments. */
127 int strict_prototype = 1;
128 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
130 /* Nonzero means that labels can be used as first-class objects */
132 int flag_labels_ok;
134 /* Non-zero means to collect statistics which might be expensive
135 and to print them when we are done. */
136 int flag_detailed_statistics;
138 /* C++ specific flags. */
139 /* Nonzero for -fall-virtual: make every member function (except
140 constructors) lay down in the virtual function table. Calls
141 can then either go through the virtual function table or not,
142 depending. */
144 int flag_all_virtual;
146 /* Zero means that `this' is a *const. This gives nice behavior in the
147 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior. */
149 int flag_this_is_variable;
151 /* Nonzero means memoize our member lookups. */
153 int flag_memoize_lookups; int flag_save_memoized_contexts;
155 /* Nonzero means to implement `dynamic' features a la SOS. */
157 int flag_dynamic;
159 /* 3 means write out only virtuals function tables `defined'
160 in this implementation file.
161 2 means write out only specific virtual function tables
162 and give them (C) public visibility.
163 1 means write out virtual function tables and give them
164 (C) public visibility.
165 0 means write out virtual function tables and give them
166 (C) static visibility (default).
167 -1 means declare virtual function tables extern. */
169 int write_virtuals;
171 /* Nonzero means we should attempt to elide constructors when possible. */
173 int flag_elide_constructors;
175 /* Nonzero means if the type has methods, only output debugging
176 information if methods are actually written to the asm file. */
178 int flag_minimal_debug = 1;
180 /* Same, but for inline functions: nonzero means write out debug info
181 for inlines. Zero means do not. */
183 int flag_inline_debug;
185 /* Nonzero means recognize and handle exception handling constructs.
186 2 means handle exceptions the way Spring wants them handled. */
188 int flag_handle_exceptions;
190 /* Nonzero means that member functions defined in class scope are
191 inline by default. */
193 int flag_default_inline = 1;
195 /* Nonzero means that functions declared `inline' will be treated
196 as `static'. Used in conjunction with -g. */
197 int flag_no_inline = 0;
199 /* Controls whether enums and ints freely convert.
200 1 means with complete freedom.
201 0 means enums can convert to ints, but not vice-versa. */
202 int flag_int_enum_equivalence;
204 /* Controls whether compiler is operating under LUCID's Cadillac
205 system. 1 means yes, 0 means no. */
206 int flag_cadillac;
208 /* Table of language-dependent -f options.
209 STRING is the option name. VARIABLE is the address of the variable.
210 ON_VALUE is the value to store in VARIABLE
211 if `-fSTRING' is seen as an option.
212 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
214 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
216 {"signed-char", &flag_signed_char, 1},
217 {"unsigned-char", &flag_signed_char, 0},
218 {"short-enums", &flag_short_enums, 1},
219 {"cond-mismatch", &flag_cond_mismatch, 1},
220 {"asm", &flag_no_asm, 0},
221 {"labels-ok", &flag_labels_ok, 1},
222 {"stats", &flag_detailed_statistics, 1},
223 {"this-is-variable", &flag_this_is_variable, 1},
224 {"strict-prototype", &strict_prototypes_lang_cplusplus, 1},
225 {"warn-implicit", &warn_implicit, 1},
226 {"all-virtual", &flag_all_virtual, 1},
227 {"memoize-lookups", &flag_memoize_lookups, 1},
228 {"elide-constructors", &flag_elide_constructors, 1},
229 {"minimal-debug", &flag_minimal_debug, 1},
230 {"inline-debug", &flag_inline_debug, 0},
231 {"handle-exceptions", &flag_handle_exceptions, 1},
232 {"spring-exceptions", &flag_handle_exceptions, 2},
233 {"default-inline", &flag_default_inline, 1},
234 {"inline", &flag_no_inline, 0},
235 {"dollars-in-identifiers", &dollars_in_ident, 1},
236 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
239 /* Decode the string P as a language-specific option.
240 Return 1 if it is recognized (and handle it);
241 return 0 if not recognized. */
243 int
244 lang_decode_option (p)
245 char *p;
247 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
248 flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
249 flag_this_is_variable = 1;
250 /* The +e options are for cfront compatability. */
251 else if (p[0] == '+' && p[1] == 'e')
253 int old_write_virtuals = write_virtuals;
254 if (p[2] == '1')
255 write_virtuals = 1;
256 else if (p[2] == '0')
257 write_virtuals = -1;
258 else if (p[2] == '2')
259 write_virtuals = 2;
260 else error ("invalid +e option");
261 if (old_write_virtuals != 0
262 && write_virtuals != old_write_virtuals)
263 error ("conflicting +e options given");
265 else if (p[0] == '-' && p[1] == 'f')
267 /* Some kind of -f option.
268 P's value is the option sans `-f'.
269 Search for it in the table of options. */
270 int found = 0, j;
272 p += 2;
273 /* Try special -f options. */
275 if (!strcmp (p, "save-memoized"))
277 flag_memoize_lookups = 1;
278 flag_save_memoized_contexts = 1;
279 found = 1;
281 else if (!strcmp (p, "SOS"))
283 flag_all_virtual = 2;
284 found = 1;
286 else if (! strncmp (p, "cadillac", 8))
288 flag_cadillac = atoi (p+9);
289 found = 1;
291 else if (! strncmp (p, "no-cadillac", 11))
293 flag_cadillac = 0;
294 found = 1;
296 else for (j = 0;
297 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
298 j++)
300 if (!strcmp (p, lang_f_options[j].string))
302 *lang_f_options[j].variable = lang_f_options[j].on_value;
303 /* A goto here would be cleaner,
304 but breaks the vax pcc. */
305 found = 1;
307 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
308 && ! strcmp (p+3, lang_f_options[j].string))
310 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
311 found = 1;
314 return found;
316 else if (p[0] == '-' && p[1] == 'W')
318 /* The -W options control the warning behavior of the compiler. */
319 p += 2;
321 if (!strcmp (p, "implicit"))
322 warn_implicit = 1;
323 else if (!strcmp (p, "return-type"))
324 warn_return_type = 1;
325 else if (!strcmp (p, "write-strings"))
326 warn_write_strings = 1;
327 else if (!strcmp (p, "cast-qual"))
328 warn_cast_qual = 1;
329 else if (!strcmp (p, "pointer-arith"))
330 warn_pointer_arith = 1;
331 else if (!strcmp (p, "strict-prototypes"))
332 warn_strict_prototypes = 1;
333 else if (!strcmp (p, "comment"))
334 ; /* cpp handles this one. */
335 else if (!strcmp (p, "comments"))
336 ; /* cpp handles this one. */
337 else if (!strcmp (p, "trigraphs"))
338 ; /* cpp handles this one. */
339 else if (!strcmp (p, "all"))
341 extra_warnings = 1;
342 warn_implicit = 1;
343 warn_return_type = 1;
344 warn_unused = 1;
345 warn_switch = 1;
346 #if 0
347 warn_enum_clash = 1;
348 #endif
349 warn_inline = 1;
352 else if (!strcmp (p, "overloaded-virtual"))
353 warn_overloaded_virtual = 1;
354 else if (!strcmp (p, "enum-clash"))
355 warn_enum_clash = 1;
356 else return 0;
358 else if (!strcmp (p, "-ansi"))
359 flag_no_asm = 1, dollars_in_ident = 0;
360 else
361 return 0;
363 return 1;
366 /* Incorporate `const' and `volatile' qualifiers for member functions.
367 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
368 QUALS is a list of qualifiers. */
369 tree
370 grok_method_quals (ctype, function, quals)
371 tree ctype, function, quals;
373 tree fntype = TREE_TYPE (function);
374 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
376 assert (quals != NULL_TREE);
379 extern tree ridpointers[];
381 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
383 if (TREE_READONLY (ctype))
384 error ("duplicate `%s' %s",
385 IDENTIFIER_POINTER (TREE_VALUE (quals)),
386 (TREE_CODE (function) == FUNCTION_DECL
387 ? "for member function" : "in type declaration"));
388 ctype = build_type_variant (ctype, 1, TREE_VOLATILE (ctype));
389 build_pointer_type (ctype);
391 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
393 if (TREE_VOLATILE (ctype))
394 error ("duplicate `%s' %s",
395 IDENTIFIER_POINTER (TREE_VALUE (quals)),
396 (TREE_CODE (function) == FUNCTION_DECL
397 ? "for member function" : "in type declaration"));
398 ctype = build_type_variant (ctype, TREE_READONLY (ctype), 1);
399 build_pointer_type (ctype);
401 else
402 abort ();
403 quals = TREE_CHAIN (quals);
405 while (quals);
406 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
407 (TREE_CODE (fntype) == METHOD_TYPE
408 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
409 : TYPE_ARG_TYPES (fntype)));
410 if (raises)
411 fntype = build_exception_variant (ctype, fntype, raises);
413 TREE_TYPE (function) = fntype;
414 return ctype;
418 /* Classes overload their constituent function names automatically.
419 When a function name is declared in a record structure,
420 its name is changed to it overloaded name. Since names for
421 constructors and destructors can conflict, we place a leading
422 '$' for destructors.
424 CNAME is the name of the class we are grokking for.
426 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
428 FLAGS contains bits saying what's special about today's
429 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
431 If FUNCTION is a destructor, then we must add the `auto-delete' field
432 as a second parameter. There is some hair associated with the fact
433 that we must "declare" this variable in the manner consistent with the
434 way the rest of the arguements were declared.
436 If FUNCTION is a constructor, and we are doing SOS hacks for dynamic
437 classes, then the second hidden argument is the virtual function table
438 pointer with which to initialize the object.
440 QUALS are the qualifiers for the this pointer. */
442 void
443 grokclassfn (ctype, cname, function, flags, complain, quals)
444 tree ctype, cname, function;
445 enum overload_flags flags;
446 tree quals;
448 tree fn_name = DECL_NAME (function);
449 tree arg_types;
450 tree parm;
451 char *name;
453 if (fn_name == NULL_TREE)
455 error ("name missing for member function");
456 fn_name = get_identifier ("<anonymous>");
457 DECL_NAME (function) = DECL_ORIGINAL_NAME (function) = fn_name;
460 if (quals)
461 ctype = grok_method_quals (ctype, function, quals);
463 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
464 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
466 /* Must add the class instance variable up front. */
467 /* Right now we just make this a pointer. But later
468 we may wish to make it special. */
469 tree type = TREE_VALUE (arg_types);
471 if (flags == DTOR_FLAG)
472 type = TYPE_MAIN_VARIANT (type);
473 else if (DECL_CONSTRUCTOR_P (function))
475 if (TYPE_DYNAMIC (ctype))
477 parm = build_decl (PARM_DECL, get_identifier (AUTO_VTABLE_NAME), TYPE_POINTER_TO (ptr_type_node));
478 TREE_USED (parm) = 1;
479 TREE_READONLY (parm) = 1;
480 DECL_ARG_TYPE (parm) = TYPE_POINTER_TO (ptr_type_node);
481 TREE_CHAIN (parm) = last_function_parms;
482 last_function_parms = parm;
485 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
487 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
488 /* In this case we need "in-charge" flag saying whether
489 this constructor is responsible for initialization
490 of virtual baseclasses or not. */
491 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
492 DECL_ARG_TYPE (parm) = integer_type_node;
493 TREE_REGDECL (parm) = 1;
494 TREE_CHAIN (parm) = last_function_parms;
495 last_function_parms = parm;
499 parm = build_decl (PARM_DECL, this_identifier, type);
500 DECL_ARG_TYPE (parm) = type;
501 /* We can make this a register, so long as we don't
502 accidently complain if someone tries to take its address. */
503 TREE_REGDECL (parm) = 1;
504 if (flags != DTOR_FLAG
505 && (!flag_this_is_variable || TREE_READONLY (type)))
506 TREE_READONLY (parm) = 1;
507 TREE_CHAIN (parm) = last_function_parms;
508 last_function_parms = parm;
511 if (flags == DTOR_FLAG)
513 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
514 arg_types = hash_tree_chain (const_integer_type, void_list_node);
515 name = (char *)alloca (sizeof (DESTRUCTOR_DECL_FORMAT)
516 + IDENTIFIER_LENGTH (cname) + 2);
517 sprintf (name, DESTRUCTOR_DECL_FORMAT, IDENTIFIER_POINTER (cname));
518 DECL_NAME (function) = get_identifier (name);
519 DECL_ASSEMBLER_NAME (function) = IDENTIFIER_POINTER (DECL_NAME (function));
520 parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
521 TREE_USED (parm) = 1;
522 TREE_READONLY (parm) = 1;
523 DECL_ARG_TYPE (parm) = const_integer_type;
524 /* This is the same chain as DECL_ARGUMENTS (fndecl). */
525 TREE_CHAIN (last_function_parms) = parm;
527 TREE_TYPE (function) = build_cplus_method_type (ctype, void_type_node, arg_types);
528 TYPE_HAS_DESTRUCTOR (ctype) = 1;
530 else if (flags == WRAPPER_FLAG || flags == ANTI_WRAPPER_FLAG)
532 name = (char *)alloca (sizeof (WRAPPER_DECL_FORMAT)
533 + sizeof (ANTI_WRAPPER_DECL_FORMAT)
534 + IDENTIFIER_LENGTH (cname) + 2);
535 sprintf (name,
536 flags == WRAPPER_FLAG ? WRAPPER_DECL_FORMAT : ANTI_WRAPPER_DECL_FORMAT,
537 IDENTIFIER_POINTER (cname));
538 DECL_NAME (function) = build_decl_overload (name, arg_types, 1);
539 DECL_ASSEMBLER_NAME (function) = IDENTIFIER_POINTER (DECL_NAME (function));
540 sprintf (name, flags == WRAPPER_FLAG ? WRAPPER_NAME_FORMAT : ANTI_WRAPPER_NAME_FORMAT,
541 IDENTIFIER_POINTER (cname));
542 DECL_ORIGINAL_NAME (function) = fn_name = get_identifier (name);
544 else if (flags == WRAPPER_PRED_FLAG)
546 name = (char *)alloca (sizeof (WRAPPER_PRED_DECL_FORMAT)
547 + sizeof (WRAPPER_PRED_NAME_FORMAT)
548 + IDENTIFIER_LENGTH (cname) + 2);
549 sprintf (name, WRAPPER_PRED_DECL_FORMAT, IDENTIFIER_POINTER (cname));
550 DECL_NAME (function) = build_decl_overload (name, arg_types, 1);
551 DECL_ASSEMBLER_NAME (function) = IDENTIFIER_POINTER (DECL_NAME (function));
552 sprintf (name, WRAPPER_PRED_NAME_FORMAT, IDENTIFIER_POINTER (cname));
553 DECL_ORIGINAL_NAME (function) = fn_name = get_identifier (name);
555 else
557 tree these_arg_types;
559 if (TYPE_DYNAMIC (ctype) && DECL_CONSTRUCTOR_P (function))
561 arg_types = hash_tree_chain (build_pointer_type (ptr_type_node),
562 TREE_CHAIN (arg_types));
563 TREE_TYPE (function)
564 = build_cplus_method_type (ctype, TREE_TYPE (TREE_TYPE (function)), arg_types);
565 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
568 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
570 arg_types = hash_tree_chain (integer_type_node, TREE_CHAIN (arg_types));
571 TREE_TYPE (function)
572 = build_cplus_method_type (ctype, TREE_TYPE (TREE_TYPE (function)), arg_types);
573 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
576 these_arg_types = arg_types;
578 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
579 /* Only true for static member functions. */
580 these_arg_types = hash_tree_chain (TYPE_POINTER_TO (ctype), arg_types);
582 DECL_NAME (function) = build_decl_overload (IDENTIFIER_POINTER (fn_name),
583 these_arg_types,
584 1 + DECL_CONSTRUCTOR_P (function));
585 DECL_ASSEMBLER_NAME (function) = IDENTIFIER_POINTER (DECL_NAME (function));
586 if (flags == TYPENAME_FLAG)
587 TREE_TYPE (DECL_NAME (function)) = TREE_TYPE (fn_name);
590 DECL_ARGUMENTS (function) = last_function_parms;
592 /* now, the sanity check: report error if this function is not
593 really a member of the class it is supposed to belong to. */
594 if (complain)
596 tree field;
597 int need_quotes = 0;
598 char *err_name;
599 tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
600 tree *methods = 0;
601 tree *end = 0;
603 if (method_vec != 0)
605 methods = &TREE_VEC_ELT (method_vec, 0);
606 end = TREE_VEC_END (method_vec);
608 if (*methods == 0)
609 methods++;
611 while (methods != end)
613 if (fn_name == DECL_ORIGINAL_NAME (*methods))
615 field = *methods;
616 while (field)
618 if (DECL_NAME (function) == DECL_NAME (field))
619 return;
620 field = TREE_CHAIN (field);
622 break; /* loser */
624 methods++;
628 if (OPERATOR_NAME_P (fn_name))
630 err_name = (char *)alloca (1024);
631 sprintf (err_name, "`operator %s'", operator_name_string (fn_name));
633 else if (OPERATOR_TYPENAME_P (fn_name))
634 if (complain && TYPE_HAS_CONVERSION (ctype))
635 err_name = "such type conversion operator";
636 else
637 err_name = "type conversion operator";
638 else if (flags == WRAPPER_FLAG)
639 err_name = "wrapper";
640 else if (flags == WRAPPER_PRED_FLAG)
641 err_name = "wrapper predicate";
642 else
644 err_name = IDENTIFIER_POINTER (fn_name);
645 need_quotes = 1;
648 if (methods != end)
649 if (need_quotes)
650 error ("argument list for `%s' does not match any in class", err_name);
651 else
652 error ("argument list for %s does not match any in class", err_name);
653 else
655 methods = 0;
656 if (need_quotes)
657 error ("no `%s' member function declared in class", err_name);
658 else
659 error ("no %s declared in class", err_name);
662 /* If we did not find the method in the class, add it to
663 avoid spurious errors. */
664 add_method (ctype, methods, function);
668 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
669 of a structure component, returning a FIELD_DECL node.
670 QUALS is a list of type qualifiers for this decl (such as for declaring
671 const member functions).
673 This is done during the parsing of the struct declaration.
674 The FIELD_DECL nodes are chained together and the lot of them
675 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
677 C++:
679 If class A defines that certain functions in class B are friends, then
680 the way I have set things up, it is B who is interested in permission
681 granted by A. However, it is in A's context that these declarations
682 are parsed. By returning a void_type_node, class A does not attempt
683 to incorporate the declarations of the friends within its structure.
685 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
686 CHANGES TO CODE IN `start_method'. */
688 tree
689 grokfield (declarator, declspecs, raises, init, asmspec_tree)
690 tree declarator, declspecs, raises, init;
691 tree asmspec_tree;
693 register tree value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
694 char *asmspec = 0;
696 if (! value) return NULL_TREE; /* friends went bad. */
698 /* Pass friendly classes back. */
699 if (TREE_CODE (value) == VOID_TYPE)
700 return void_type_node;
702 if (DECL_NAME (value) != NULL_TREE
703 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
704 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
705 error_with_decl (value, "member `%s' conflicts with virtual function table field name");
707 /* Stash away type declarations. */
708 if (TREE_CODE (value) == TYPE_DECL)
710 TREE_NONLOCAL (value) = 1;
711 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
712 pushdecl_class_level (value);
713 return value;
716 if (DECL_IN_AGGR_P (value))
718 error_with_decl (value, "`%s' is already defined in aggregate scope");
719 return void_type_node;
722 if (flag_cadillac)
723 cadillac_start_decl (value);
725 if (asmspec_tree)
726 asmspec = TREE_STRING_POINTER (asmspec_tree);
728 if (init != 0)
730 if (TREE_CODE (value) == FUNCTION_DECL)
732 grok_function_init (value, init);
733 init = NULL_TREE;
735 else if (pedantic
736 && ! TREE_STATIC (value)
737 && ! TREE_READONLY (value))
739 error ("fields cannot have initializers");
740 init = error_mark_node;
742 else
744 /* We allow initializers to become parameters to base initializers. */
745 if (TREE_CODE (init) == CONST_DECL)
746 init = DECL_INITIAL (init);
747 else if (TREE_READONLY_DECL_P (init))
748 init = decl_constant_value (init);
749 else if (TREE_CODE (init) == CONSTRUCTOR)
750 init = digest_init (TREE_TYPE (value), init, 0);
751 assert (TREE_PERMANENT (init));
752 if (init == error_mark_node)
753 /* We must make this look different than `error_mark_node'
754 because `decl_const_value' would mis-interpret it
755 as only meaning that this VAR_DECL is defined. */
756 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
757 else if (! TREE_LITERAL (init))
759 /* We can allow references to things that are effectively
760 static, since references are initialized with the address. */
761 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
762 || (TREE_EXTERNAL (init) == 0
763 && TREE_STATIC (init) == 0))
765 error ("field initializer is not constant");
766 init = error_mark_node;
772 if (TREE_CODE (value) == VAR_DECL)
774 /* We cannot call pushdecl here, because that would
775 fill in the value of our TREE_CHAIN. Instead, we
776 modify finish_decl to do the right thing, namely, to
777 put this decl out straight away. */
778 if (TREE_STATIC (value))
780 if (asmspec == 0)
782 char *buf
783 = (char *)alloca (IDENTIFIER_LENGTH (current_class_name)
784 + IDENTIFIER_LENGTH (DECL_NAME (value))
785 + sizeof (STATIC_NAME_FORMAT));
786 tree name;
788 sprintf (buf, STATIC_NAME_FORMAT,
789 IDENTIFIER_POINTER (current_class_name),
790 IDENTIFIER_POINTER (DECL_NAME (value)));
791 name = get_identifier (buf);
792 TREE_PUBLIC (value) = 1;
793 DECL_INITIAL (value) = error_mark_node;
794 asmspec = IDENTIFIER_POINTER (name);
795 DECL_ASSEMBLER_NAME (value) = asmspec;
796 asmspec_tree = build_string (IDENTIFIER_LENGTH (name), asmspec);
798 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
800 /* Static consts need not be initialized in the class definition. */
801 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
803 static int explanation = 0;
805 error ("initializer invalid for static member with constructor");
806 if (explanation++ == 0)
807 error ("(you really want to initialize it separately)");
808 init = 0;
810 /* Force the user to know when an uninitialized static
811 member is being used. */
812 if (TREE_READONLY (value)
813 && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
814 TREE_EXTERNAL (value) = 1;
816 DECL_INITIAL (value) = init;
817 DECL_IN_AGGR_P (value) = 1;
818 finish_decl (value, init, asmspec_tree);
819 pushdecl_class_level (value);
820 return value;
822 if (TREE_CODE (value) == FIELD_DECL)
824 DECL_ASSEMBLER_NAME (value) = asmspec;
825 if (DECL_INITIAL (value) == error_mark_node)
826 init = error_mark_node;
827 finish_decl (value, init, asmspec_tree);
828 DECL_INITIAL (value) = init;
829 DECL_IN_AGGR_P (value) = 1;
830 return value;
832 if (TREE_CODE (value) == FUNCTION_DECL)
834 /* grokdeclarator defers setting this. */
835 TREE_PUBLIC (value) = 1;
836 if (TREE_CHAIN (value) != NULL_TREE)
838 /* Need a fresh node here so that we don't get circularity
839 when we link these together. */
840 value = copy_node (value);
841 /* When does this happen? */
842 assert (init == NULL_TREE);
844 finish_decl (value, init, asmspec_tree);
846 /* Pass friends back this way. */
847 if (DECL_FRIEND_P (value))
848 return void_type_node;
850 DECL_IN_AGGR_P (value) = 1;
851 return value;
853 abort ();
856 /* Like `grokfield', but for bitfields.
857 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
859 tree
860 grokbitfield (declarator, declspecs, width)
861 tree declarator, declspecs, width;
863 register tree value = grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE);
865 if (! value) return NULL_TREE; /* friends went bad. */
867 /* Pass friendly classes back. */
868 if (TREE_CODE (value) == VOID_TYPE)
869 return void_type_node;
871 if (TREE_CODE (value) == TYPE_DECL)
873 error_with_decl (value, "cannot declare `%s' to be a bitfield type");
874 return NULL_TREE;
877 if (DECL_IN_AGGR_P (value))
879 error_with_decl (value, "`%s' is already defined in aggregate scope");
880 return void_type_node;
883 #ifdef FIELD_XREF
884 FIELD_xref_member(current_class_name,value);
885 #endif
887 if (TREE_STATIC (value))
889 error_with_decl (value, "static member `%s' cannot be a bitfield");
890 return NULL_TREE;
892 if (TREE_CODE (value) == FIELD_DECL)
894 finish_decl (value, NULL_TREE, NULL_TREE);
895 /* detect invalid field size. */
896 if (TREE_CODE (width) == CONST_DECL)
897 width = DECL_INITIAL (width);
898 else if (TREE_READONLY_DECL_P (width))
899 width = decl_constant_value (width);
901 if (TREE_CODE (width) != INTEGER_CST)
903 error_with_decl (value, "structure field `%s' width not an integer constant");
904 DECL_INITIAL (value) = NULL;
906 else
908 DECL_INITIAL (value) = width;
909 TREE_PACKED (value) = 1;
911 DECL_IN_AGGR_P (value) = 1;
912 return value;
914 abort ();
917 /* Like GROKFIELD, except that the declarator has been
918 buried in DECLSPECS. Find the declarator, and
919 return something that looks like it came from
920 GROKFIELD. */
921 tree
922 groktypefield (declspecs, parmlist)
923 tree declspecs;
924 tree parmlist;
926 tree spec = declspecs;
927 tree prev = NULL_TREE;
929 tree type_id = NULL_TREE;
930 tree quals = NULL_TREE;
931 tree lengths = NULL_TREE;
932 tree decl = NULL_TREE;
934 while (spec)
936 register tree id = TREE_VALUE (spec);
938 if (TREE_CODE (spec) != TREE_LIST)
939 /* Certain parse errors slip through. For example,
940 `int class ();' is not caught by the parser. Try
941 weakly to recover here. */
942 return NULL_TREE;
944 if (TREE_CODE (id) == TYPE_DECL
945 || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
947 /* We have a constructor/destructor or
948 conversion operator. Use it. */
949 if (prev)
950 TREE_CHAIN (prev) = TREE_CHAIN (spec);
951 else
953 declspecs = TREE_CHAIN (spec);
955 type_id = id;
956 goto found;
958 prev = spec;
959 spec = TREE_CHAIN (spec);
962 /* Nope, we have a conversion operator to a scalar type. */
963 spec = declspecs;
964 while (spec)
966 tree id = TREE_VALUE (spec);
968 if (TREE_CODE (id) == IDENTIFIER_NODE)
970 if (id == ridpointers[(int)RID_INT]
971 || id == ridpointers[(int)RID_DOUBLE]
972 || id == ridpointers[(int)RID_FLOAT])
974 if (type_id)
975 error ("extra `%s' ignored",
976 IDENTIFIER_POINTER (id));
977 else
978 type_id = id;
980 else if (id == ridpointers[(int)RID_LONG]
981 || id == ridpointers[(int)RID_SHORT]
982 || id == ridpointers[(int)RID_CHAR])
984 lengths = tree_cons (NULL_TREE, id, lengths);
986 else if (id == ridpointers[(int)RID_VOID])
988 if (type_id)
989 error ("spurious `void' type ignored");
990 else
991 error ("conversion to `void' type invalid");
993 else if (id == ridpointers[(int)RID_AUTO]
994 || id == ridpointers[(int)RID_REGISTER]
995 || id == ridpointers[(int)RID_TYPEDEF]
996 || id == ridpointers[(int)RID_CONST]
997 || id == ridpointers[(int)RID_VOLATILE])
999 error ("type specifier `%s' used invalidly",
1000 IDENTIFIER_POINTER (id));
1002 else if (id == ridpointers[(int)RID_FRIEND]
1003 || id == ridpointers[(int)RID_VIRTUAL]
1004 || id == ridpointers[(int)RID_INLINE]
1005 || id == ridpointers[(int)RID_UNSIGNED]
1006 || id == ridpointers[(int)RID_SIGNED]
1007 || id == ridpointers[(int)RID_STATIC]
1008 || id == ridpointers[(int)RID_EXTERN])
1010 quals = tree_cons (NULL_TREE, id, quals);
1012 else
1014 /* Happens when we have a global typedef
1015 and a class-local member function with
1016 the same name. */
1017 type_id = id;
1018 goto found;
1021 else if (TREE_CODE (id) == RECORD_TYPE)
1023 type_id = TYPE_NAME (id);
1024 if (TREE_CODE (type_id) == TYPE_DECL)
1025 type_id = DECL_NAME (type_id);
1026 if (type_id == NULL_TREE)
1027 error ("identifier for aggregate type conversion omitted");
1029 else
1030 assert (0);
1031 spec = TREE_CHAIN (spec);
1034 if (type_id)
1036 declspecs = chainon (lengths, quals);
1038 else if (lengths)
1040 if (TREE_CHAIN (lengths))
1041 error ("multiple length specifiers");
1042 type_id = ridpointers[(int)RID_INT];
1043 declspecs = chainon (lengths, quals);
1045 else if (quals)
1047 error ("no type given, defaulting to `operator int ...'");
1048 type_id = ridpointers[(int)RID_INT];
1049 declspecs = quals;
1051 else return NULL_TREE;
1052 found:
1053 decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
1054 declspecs, FIELD, 0, NULL_TREE);
1055 if (decl == NULL_TREE)
1056 return NULL_TREE;
1058 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_CHAIN (decl) != NULL_TREE)
1060 /* Need a fresh node here so that we don't get circularity
1061 when we link these together. */
1062 decl = copy_node (decl);
1065 if (decl == void_type_node
1066 || (TREE_CODE (decl) == FUNCTION_DECL
1067 && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
1068 /* bunch of friends. */
1069 return decl;
1071 if (DECL_IN_AGGR_P (decl))
1073 error_with_decl (decl, "`%s' already defined in aggregate scope");
1074 return void_type_node;
1077 finish_decl (decl, NULL_TREE, NULL_TREE);
1079 /* If this declaration is common to another declaration
1080 complain about such redundancy, and return NULL_TREE
1081 so that we don't build a circular list. */
1082 if (TREE_CHAIN (decl))
1084 error_with_decl (decl, "function `%s' declared twice in aggregate");
1085 return NULL_TREE;
1087 DECL_IN_AGGR_P (decl) = 1;
1088 return decl;
1091 /* The precedence rules of this grammar (or any other deterministic LALR
1092 grammar, for that matter), place the CALL_EXPR somewhere where we
1093 may not want it. The solution is to grab the first CALL_EXPR we see,
1094 pretend that that is the one that belongs to the parameter list of
1095 the type conversion function, and leave everything else alone.
1096 We pull it out in place.
1098 CALL_REQUIRED is non-zero if we should complain if a CALL_EXPR
1099 does not appear in DECL. */
1100 tree
1101 grokoptypename (decl, call_required)
1102 tree decl;
1103 int call_required;
1105 tree tmp, last;
1107 assert (TREE_CODE (decl) == TYPE_EXPR);
1109 tmp = TREE_OPERAND (decl, 0);
1110 last = NULL_TREE;
1112 while (tmp)
1114 switch (TREE_CODE (tmp))
1116 case CALL_EXPR:
1118 tree parms = TREE_OPERAND (tmp, 1);
1120 if (last)
1121 TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
1122 else
1123 TREE_OPERAND (decl, 0) = TREE_OPERAND (tmp, 0);
1124 if (parms
1125 && TREE_CODE (TREE_VALUE (parms)) == TREE_LIST)
1126 TREE_VALUE (parms)
1127 = grokdeclarator (TREE_VALUE (TREE_VALUE (parms)),
1128 TREE_PURPOSE (TREE_VALUE (parms)),
1129 TYPENAME, 0, NULL_TREE);
1130 if (parms)
1132 if (TREE_VALUE (parms) != void_type_node)
1133 error ("operator <typename> requires empty parameter list");
1134 else
1135 /* Canonicalize parameter lists. */
1136 TREE_OPERAND (tmp, 1) = void_list_node;
1139 last = grokdeclarator (TREE_OPERAND (decl, 0),
1140 TREE_TYPE (decl),
1141 TYPENAME, 0, NULL_TREE);
1142 TREE_OPERAND (tmp, 0) = build_typename_overload (last);
1143 TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
1144 return tmp;
1147 case INDIRECT_REF:
1148 case ADDR_EXPR:
1149 case ARRAY_REF:
1150 break;
1152 case SCOPE_REF:
1153 /* This is legal when declaring a conversion to
1154 something of type pointer-to-member. */
1155 if (TREE_CODE (TREE_OPERAND (tmp, 1)) == INDIRECT_REF)
1157 tmp = TREE_OPERAND (tmp, 1);
1159 else
1161 #if 0
1162 /* We may need to do this if grokdeclarator cannot handle this. */
1163 error ("type `member of class %s' invalid return type",
1164 TYPE_NAME_STRING (TREE_OPERAND (tmp, 0)));
1165 TREE_OPERAND (tmp, 1) = build_parse_node (INDIRECT_REF, TREE_OPERAND (tmp, 1));
1166 #endif
1167 tmp = TREE_OPERAND (tmp, 1);
1169 break;
1171 default:
1172 assert (0);
1174 last = tmp;
1175 tmp = TREE_OPERAND (tmp, 0);
1178 if (call_required)
1179 error ("operator <typename> construct requires parameter list");
1181 last = grokdeclarator (TREE_OPERAND (decl, 0),
1182 TREE_TYPE (decl),
1183 TYPENAME, 0, NULL_TREE);
1184 tmp = build_parse_node (CALL_EXPR, build_typename_overload (last),
1185 void_list_node, NULL_TREE);
1186 TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
1187 return tmp;
1190 /* Given an encoding for an operator name (see parse.y, the rules
1191 for making an `operator_name' in the variable DECLARATOR,
1192 return the name of the operator prefix as an IDENTIFIER_NODE.
1194 CTYPE is the class type to which this operator belongs.
1195 Needed in case it is a static member function.
1197 TYPE, if nonnull, is the function type for this declarator.
1198 This information helps to resolve potential ambiguities.
1200 If REPORT_AMBIGUOUS is non-zero, an error message
1201 is reported, and a default arity of the operator is
1202 returned. Otherwise, return the operator under an OP_EXPR,
1203 for later evaluation when type information will enable
1204 proper instantiation.
1206 IS_DECL is 1 if this is a decl (as opposed to an expression).
1207 IS_DECL is 2 if this is a static function decl.
1208 Otherwise IS_DECL is 0. */
1209 tree
1210 grokopexpr (declp, ctype, type, report_ambiguous, is_decl)
1211 tree *declp;
1212 tree ctype, type;
1213 int report_ambiguous;
1215 tree declarator = *declp;
1216 tree name, parmtypes;
1217 int seen_classtype_parm
1218 = (type != NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
1219 || is_decl == 2;
1221 if (type != NULL_TREE)
1223 if (ctype == 0 && TREE_CODE (TREE_OPERAND (declarator, 0)) == NEW_EXPR)
1225 if (TYPE_ARG_TYPES (type)
1226 && TREE_CHAIN (TYPE_ARG_TYPES (type))
1227 && TREE_CHAIN (TYPE_ARG_TYPES (type)) != void_list_node)
1228 return get_identifier (OPERATOR_NEW_FORMAT);
1229 return get_identifier ("__builtin_new");
1231 else if (ctype == 0 && TREE_CODE (TREE_OPERAND (declarator, 0)) == DELETE_EXPR)
1232 return get_identifier ("__builtin_delete");
1233 else
1235 /* Now we know the number of parameters,
1236 so build the real operator fnname. */
1237 parmtypes = TYPE_ARG_TYPES (type);
1238 if (is_decl > 1 && TREE_CODE (type) == METHOD_TYPE)
1239 parmtypes = TREE_CHAIN (parmtypes);
1240 name = build_operator_fnname (declp, parmtypes, is_decl > 1);
1241 declarator = *declp;
1244 else
1246 if (TREE_PURPOSE (declarator) == NULL_TREE)
1247 switch (TREE_CODE (TREE_VALUE (declarator)))
1249 case PLUS_EXPR:
1250 case CONVERT_EXPR:
1251 case ADDR_EXPR:
1252 case BIT_AND_EXPR:
1253 case INDIRECT_REF:
1254 case MULT_EXPR:
1255 case NEGATE_EXPR:
1256 case MINUS_EXPR:
1257 if (report_ambiguous)
1259 error ("operator '%s' ambiguous, (default binary)",
1260 opname_tab[(int)TREE_CODE (TREE_VALUE (declarator))]);
1261 name = build_operator_fnname (declp, NULL_TREE, 2);
1262 declarator = *declp;
1264 else
1266 /* do something intellegent. */
1267 TREE_TYPE (declarator) = unknown_type_node;
1268 return declarator;
1270 break;
1271 default:
1272 name = build_operator_fnname (declp, NULL_TREE, -1);
1273 declarator = *declp;
1274 break;
1276 else if (TREE_CODE (TREE_PURPOSE (declarator)) == MODIFY_EXPR)
1278 name = build_operator_fnname (declp, NULL_TREE, -1);
1279 declarator = *declp;
1281 else abort ();
1283 /* Now warn if the parameter list does not contain any args
1284 which are of aggregate type. */
1285 if (is_decl && type != NULL_TREE && ! seen_classtype_parm)
1286 for (parmtypes = TYPE_ARG_TYPES (type);
1287 parmtypes;
1288 parmtypes = TREE_CHAIN (parmtypes))
1289 if (IS_AGGR_TYPE (TREE_VALUE (parmtypes))
1290 || (TREE_CODE (TREE_VALUE (parmtypes)) == REFERENCE_TYPE
1291 && IS_AGGR_TYPE (TREE_TYPE (TREE_VALUE (parmtypes)))))
1293 seen_classtype_parm = 1;
1294 break;
1297 if (is_decl && seen_classtype_parm == 0)
1298 if (TREE_CODE (declarator) == OP_IDENTIFIER
1299 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == NEW_EXPR
1300 || TREE_CODE (TREE_OPERAND (declarator, 0)) == DELETE_EXPR))
1301 /* Global operators new and delete are not overloaded. */
1302 TREE_OVERLOADED (name) = 0;
1303 else
1304 error ("operator has no %suser-defined argument type",
1305 type == NULL_TREE ? "(default) " : "");
1307 return name;
1310 /* When a function is declared with an initialializer,
1311 do the right thing. Currently, there are two possibilities:
1313 class B
1315 public:
1316 // initialization possibility #1.
1317 virtual void f () = 0;
1318 int g ();
1321 class D1 : B
1323 public:
1324 int d1;
1325 // error, no f ();
1328 class D2 : B
1330 public:
1331 int d2;
1332 void f ();
1335 class D3 : B
1337 public:
1338 int d3;
1339 // initialization possibility #2
1340 void f () = B::f;
1345 static void
1346 grok_function_init (decl, init)
1347 tree decl;
1348 tree init;
1350 /* An initializer for a function tells how this function should
1351 be inherited. */
1352 tree type = TREE_TYPE (decl);
1353 extern tree abort_fndecl;
1355 if (TREE_CODE (type) == FUNCTION_TYPE)
1356 error_with_decl (decl, "initializer specified for non-member function `%s'");
1357 else if (! DECL_VIRTUAL_P (decl))
1358 error_with_decl (decl, "initializer specified for non-virtual method `%s'");
1359 else if (integer_zerop (init))
1361 /* Mark this function as being "defined". */
1362 DECL_INITIAL (decl) = error_mark_node;
1363 /* Give this node rtl from `abort'. */
1364 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1365 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1367 else if (TREE_CODE (init) == OFFSET_REF
1368 && TREE_OPERAND (init, 0) == NULL_TREE
1369 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1371 tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (init));
1372 tree basefn = TREE_OPERAND (init, 1);
1373 if (TREE_CODE (basefn) != FUNCTION_DECL)
1374 error_with_decl (decl, "non-method initializer invalid for method `%s'");
1375 else if (DECL_OFFSET (TYPE_NAME (basefn)) != 0)
1376 sorry ("base member function from other than first base class");
1377 else
1379 basetype = get_base_type (basetype, TYPE_METHOD_BASETYPE (type), 1);
1380 if (basetype == error_mark_node)
1382 else if (basetype == 0)
1383 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1384 TYPE_METHOD_BASETYPE (type));
1385 else
1387 /* Mark this function as being defined,
1388 and give it new rtl. */
1389 DECL_INITIAL (decl) = error_mark_node;
1390 DECL_RTL (decl) = DECL_RTL (basefn);
1394 else
1395 error_with_decl (decl, "invalid initializer for virtual method `%s'");
1398 /* Cache the value of this class's main virtual function table pointer
1399 in a register variable. This will save one indirection if a
1400 more than one virtual function call is made this function. */
1401 void
1402 setup_vtbl_ptr ()
1404 extern struct rtx_def *base_init_insns;
1406 if (base_init_insns == 0
1407 && DECL_CONSTRUCTOR_P (current_function_decl))
1408 emit_base_init (current_class_type, 0);
1410 if ((flag_this_is_variable & 1) == 0
1411 && optimize
1412 && current_class_type
1413 && CLASSTYPE_VSIZE (current_class_type)
1414 && ! DECL_STATIC_FUNCTION_P (current_function_decl))
1416 tree vfield = build_vfield_ref (C_C_D, current_class_type);
1417 current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
1418 DECL_RTL (current_vtable_decl) = 0;
1419 DECL_INITIAL (current_vtable_decl) = error_mark_node;
1420 /* Have to cast the initializer, since it may have come from a
1421 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
1422 finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield), 0);
1423 current_vtable_decl = build_indirect_ref (current_vtable_decl, 0);
1425 else
1426 current_vtable_decl = NULL_TREE;
1429 /* Record the existence of an addressable inline function. */
1430 void
1431 mark_inline_for_output (decl)
1432 tree decl;
1434 pending_addressable_inlines = perm_tree_cons (NULL_TREE, decl,
1435 pending_addressable_inlines);
1438 void
1439 clear_temp_name ()
1441 temp_name_counter = 0;
1444 /* Hand off a unique name which can be used for variable we don't really
1445 want to know about anyway, for example, the anonymous variables which
1446 are needed to make references work. Declare this thing so we can use it.
1447 The variable created will be of type TYPE.
1449 STATICP is nonzero if this variable should be static. */
1451 tree
1452 get_temp_name (type, staticp)
1453 tree type;
1454 int staticp;
1456 char buf[sizeof (AUTO_TEMP_FORMAT) + 12];
1457 tree decl;
1458 int temp = 0;
1459 int toplev = global_bindings_p ();
1460 if (toplev || staticp)
1462 temp = allocation_temporary_p ();
1463 if (temp)
1464 end_temporary_allocation ();
1465 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
1466 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
1468 else
1470 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
1471 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1473 TREE_USED (decl) = 1;
1474 TREE_STATIC (decl) = staticp;
1476 /* If this is a local variable, then lay out its rtl now.
1477 Otherwise, callers of this function are responsible for dealing
1478 with this variable's rtl. */
1479 if (! toplev)
1481 expand_decl (decl);
1482 expand_decl_init (decl);
1484 else if (temp)
1485 resume_temporary_allocation ();
1487 return decl;
1490 /* Get a variable which we can use for multiple assignments.
1491 It is not entered into current_binding_level, because
1492 that breaks things when it comes time to do final cleanups
1493 (which take place "outside" the binding contour of the function).
1495 Because it is not entered into the binding contour, `expand_end_bindings'
1496 does not see this variable automatically. Users of this function
1497 must either pass this variable to expand_end_bindings or do
1498 themselves what expand_end_bindings was meant to do (like keeping
1499 the variable live if -noreg was specified). */
1500 tree
1501 get_temp_regvar (type, init)
1502 tree type, init;
1504 static char buf[sizeof (AUTO_TEMP_FORMAT) + 8] = { '_' };
1505 tree decl;
1507 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
1508 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
1509 TREE_USED (decl) = 1;
1510 TREE_REGDECL (decl) = 1;
1512 if (init)
1513 store_init_value (decl, init);
1515 /* We can expand these without fear, since they cannot need
1516 constructors or destructors. */
1517 expand_decl (decl);
1518 expand_decl_init (decl);
1519 return decl;
1522 /* Make the macro TEMP_NAME_P available to units which do not
1523 include c-tree.h. */
1525 temp_name_p (decl)
1526 tree decl;
1528 return TEMP_NAME_P (decl);
1531 /* Finish off the processing of a UNION_TYPE structure.
1532 If there are static members, then all members are
1533 static, and must be laid out together. If the
1534 union is an anonymous union, we arrage for that
1535 as well. PUBLICP is nonzero if this union is
1536 not declared static. */
1537 void
1538 finish_anon_union (anon_union_decl)
1539 tree anon_union_decl;
1541 tree type = TREE_TYPE (anon_union_decl);
1542 tree field, decl;
1543 tree elems = NULL_TREE;
1544 int public_p = TREE_PUBLIC (anon_union_decl);
1545 int static_p = TREE_STATIC (anon_union_decl);
1546 int external_p = TREE_EXTERNAL (anon_union_decl);
1548 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
1549 return;
1551 if (public_p && (static_p || external_p))
1552 error ("optimizer cannot handle global anonymous unions");
1554 while (field)
1556 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
1557 /* tell `pushdecl' that this is not tentative. */
1558 DECL_INITIAL (decl) = error_mark_node;
1559 TREE_PUBLIC (decl) = public_p;
1560 TREE_STATIC (decl) = static_p;
1561 TREE_EXTERNAL (decl) = external_p;
1562 decl = pushdecl (decl);
1563 DECL_INITIAL (decl) = NULL_TREE;
1564 elems = tree_cons (DECL_ASSEMBLER_NAME (field), decl, elems);
1565 TREE_TYPE (elems) = type;
1566 field = TREE_CHAIN (field);
1568 if (static_p)
1569 make_decl_rtl (decl, 0, global_bindings_p ());
1570 expand_anon_union_decl (decl, NULL_TREE, elems);
1572 if (flag_cadillac)
1573 cadillac_finish_anon_union (decl);
1576 /* Finish and output a table which is generated by the compiler.
1577 NAME is the name to give the table.
1578 TYPE is the type of the table entry.
1579 INIT is all the elements in the table.
1580 PUBLICP is non-zero if this table should be given external visibility. */
1581 tree
1582 finish_table (name, type, init, publicp)
1583 tree name, type, init;
1585 tree itype, atype, decl;
1587 itype = build_index_type (build_int_2 (list_length (init), 0));
1588 atype = build_cplus_array_type (type, itype);
1589 layout_type (atype);
1590 decl = build_decl (VAR_DECL, name, atype);
1591 decl = pushdecl (decl);
1592 TREE_STATIC (decl) = 1;
1593 TREE_PUBLIC (decl) = publicp;
1594 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
1595 TREE_LITERAL (init) = 1;
1596 TREE_STATIC (init) = 1;
1597 DECL_INITIAL (decl) = init;
1598 finish_decl (decl, init,
1599 build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
1600 IDENTIFIER_POINTER (DECL_NAME (decl))));
1601 return decl;
1604 /* Auxilliary functions to make type signatures for
1605 `operator new' and `operator delete' correspond to
1606 what compiler will be expecting. */
1608 extern tree sizetype;
1610 tree
1611 coerce_new_type (ctype, type)
1612 tree ctype;
1613 tree type;
1615 int e1 = 0, e2 = 0;
1617 if (TREE_CODE (type) == METHOD_TYPE)
1618 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
1619 if (TREE_TYPE (type) != ptr_type_node)
1620 e1 = 1, error ("`operator new' must return type `void *'");
1622 /* Technically the type must be `size_t', but we may not know
1623 what that is. */
1624 if (TYPE_ARG_TYPES (type) == NULL_TREE)
1625 e1 = 1, error ("`operator new' takes type `size_t' parameter");
1626 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
1627 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
1628 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
1629 if (e2)
1630 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
1631 else if (e1)
1632 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
1633 return type;
1636 tree
1637 coerce_delete_type (ctype, type)
1638 tree ctype;
1639 tree type;
1641 int e1 = 0, e2 = 0, e3 = 0;
1642 tree arg_types = TYPE_ARG_TYPES (type);
1644 if (TREE_CODE (type) == METHOD_TYPE)
1646 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
1647 arg_types = TREE_CHAIN (arg_types);
1649 if (TREE_TYPE (type) != void_type_node)
1650 e1 = 1, error ("`operator delete' must return type `void'");
1651 if (arg_types == NULL_TREE
1652 || TREE_VALUE (arg_types) != ptr_type_node)
1653 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
1655 if (arg_types
1656 && TREE_CHAIN (arg_types)
1657 && TREE_CHAIN (arg_types) != void_list_node)
1659 /* Again, technically this argument must be `size_t', but again
1660 we may not know what that is. */
1661 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
1662 if (TREE_CODE (t2) != INTEGER_TYPE
1663 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
1664 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
1665 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
1667 e3 = 1;
1668 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
1669 error ("too many arguments in declaration of `operator delete'");
1670 else
1671 error ("`...' invalid in specification of `operator delete'");
1674 if (e3)
1675 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
1676 else if (e3 |= e2)
1678 if (arg_types == NULL_TREE)
1679 arg_types = void_list_node;
1680 else
1681 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
1683 else e3 |= e1;
1685 if (e3)
1686 type = build_function_type (void_type_node, arg_types);
1688 return type;
1691 static void
1692 write_vtable_entries (decl)
1693 tree decl;
1695 tree entries;
1697 for (entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
1698 entries; entries = TREE_CHAIN (entries))
1700 tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
1701 tree fn = TREE_OPERAND (fnaddr, 0);
1702 if (! TREE_ASM_WRITTEN (fn)
1703 && DECL_SAVED_INSNS (fn))
1705 if (TREE_PUBLIC (DECL_CONTEXT (fn)))
1706 TREE_PUBLIC (fn) = 1;
1707 TREE_ADDRESSABLE (fn) = 1;
1708 output_inline_function (fn);
1713 static void
1714 finish_vtable_typedecl (prev, vars)
1715 tree prev, vars;
1717 tree decl = CLASS_ASSOC_VTABLE (TREE_TYPE (vars));
1719 /* If we are controlled by `+e2', obey. */
1720 if (write_virtuals == 2)
1722 tree assoc = value_member (DECL_NAME (vars), pending_vtables);
1723 if (assoc)
1724 TREE_PURPOSE (assoc) = void_type_node;
1725 else
1726 decl = NULL_TREE;
1728 /* If this type has inline virtual functions, then
1729 write those functions out now. */
1730 if (decl && (TREE_PUBLIC (decl)
1731 || (! TREE_EXTERNAL (decl) && TREE_USED (decl))))
1732 write_vtable_entries (decl);
1735 static void
1736 finish_vtable_vardecl (prev, vars)
1737 tree prev, vars;
1739 if (write_virtuals < 0)
1741 else if (write_virtuals == 0
1742 ? TREE_USED (vars)
1743 : (TREE_PUBLIC (vars)
1744 || (! TREE_EXTERNAL (vars) && TREE_USED (vars))))
1746 extern tree the_null_vtable_entry;
1748 /* Stuff this virtual function table's size into
1749 `pfn' slot of `the_null_vtable_entry'. */
1750 tree nelts = array_type_nelts (TREE_TYPE (vars));
1751 tree *ppfn = &FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry);
1752 *ppfn = nelts;
1753 assert (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (TREE_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))))))) == nelts);
1754 /* Write it out. */
1755 write_vtable_entries (vars);
1756 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
1757 store_init_value (vars, DECL_INITIAL (vars));
1758 rest_of_decl_compilation (vars, 0, 1, 1);
1760 /* We know that PREV must be non-zero here. */
1761 TREE_CHAIN (prev) = TREE_CHAIN (vars);
1764 void
1765 walk_vtables (typedecl_fn, vardecl_fn)
1766 register void (*typedecl_fn)();
1767 register void (*vardecl_fn)();
1769 tree prev, vars;
1771 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
1773 if (TREE_CODE (vars) == TYPE_DECL
1774 && TYPE_LANG_SPECIFIC (TREE_TYPE (vars))
1775 && CLASSTYPE_VSIZE (TREE_TYPE (vars)))
1777 if (typedecl_fn) (*typedecl_fn) (prev, vars);
1779 else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
1781 if (vardecl_fn) (*vardecl_fn) (prev, vars);
1783 else
1784 prev = vars;
1788 extern int parse_time, varconst_time;
1790 #define TIMEVAR(VAR, BODY) \
1791 do { int otime = gettime (); BODY; VAR += gettime () - otime; } while (0)
1793 /* This routine is called from the last rule in yyparse ().
1794 Its job is to create all the code needed to initialize and
1795 destroy the global aggregates. We do the destruction
1796 first, since that way we only need to reverse the decls once. */
1798 void
1799 finish_file ()
1801 extern struct rtx_def *const0_rtx;
1802 extern int lineno;
1803 extern struct _iob *asm_out_file;
1804 int start_time, this_time;
1805 char *init_function_name;
1807 char *buf;
1808 char *p;
1809 tree fnname;
1810 tree vars = static_aggregates;
1811 int needs_cleaning = 0, needs_messing_up = 0;
1813 if (main_input_filename == 0)
1814 main_input_filename = input_filename;
1815 if (!first_global_object_name)
1816 first_global_object_name = main_input_filename;
1818 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT)
1819 + strlen (first_global_object_name));
1821 #ifndef MERGED
1822 if (flag_detailed_statistics)
1823 dump_tree_statistics ();
1824 #endif
1826 /* Bad parse errors. Just forget about it. */
1827 if (! global_bindings_p ())
1828 return;
1830 #ifndef MERGED
1831 /* This is the first run of an unexec'd program, so save this till
1832 we come back again. -- bryan@kewill.uucp */
1834 extern int just_done_unexec;
1835 if (just_done_unexec)
1836 return;
1838 #endif
1840 start_time = gettime ();
1842 /* Push into C language context, because that's all
1843 we'll need here. */
1844 push_lang_context (lang_name_c);
1846 /* Set up the name of the file-level functions we may need. */
1847 /* Use a global object (which is already required to be unique over
1848 the program) rather than the file name (which imposes extra
1849 constraints). -- Raeburn@MIT.EDU, 10 Jan 1990. */
1850 sprintf (buf, FILE_FUNCTION_FORMAT, first_global_object_name);
1852 /* Don't need to pull wierd characters out of global names. */
1853 if (first_global_object_name == main_input_filename)
1855 for (p = buf+11; *p; p++)
1856 if (! ((*p >= '0' && *p <= '9')
1857 #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */
1858 || *p == '.'
1859 #endif
1860 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
1861 || *p == '$'
1862 #endif
1863 || (*p >= 'A' && *p <= 'Z')
1864 || (*p >= 'a' && *p <= 'z')))
1865 *p = '_';
1868 /* See if we really need the hassle. */
1869 while (vars && needs_cleaning == 0)
1871 tree decl = TREE_VALUE (vars);
1872 tree type = TREE_TYPE (decl);
1873 if (TYPE_NEEDS_DESTRUCTOR (type))
1875 needs_cleaning = 1;
1876 needs_messing_up = 1;
1877 break;
1879 else
1880 needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
1881 vars = TREE_CHAIN (vars);
1883 if (needs_cleaning == 0)
1884 goto mess_up;
1886 /* Otherwise, GDB can get confused, because in only knows
1887 about source for LINENO-1 lines. */
1888 lineno -= 1;
1890 #if defined(sun)
1891 /* Point Sun linker at this function. */
1892 fprintf (asm_out_file, ".stabs \"_fini\",10,0,0,0\n.stabs \"");
1893 assemble_name (asm_out_file, buf);
1894 fprintf (asm_out_file, "\",4,0,0,0\n");
1895 #endif
1897 fnname = get_identifier (buf);
1898 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
1899 DECL_PRINT_NAME (current_function_decl) = "file cleanup";
1900 fnname = DECL_NAME (current_function_decl);
1901 store_parm_decls ();
1903 pushlevel (0);
1904 clear_last_expr ();
1905 push_momentary ();
1906 expand_start_bindings (0);
1908 /* These must be done in backward order to destroy,
1909 in which they happen to be! */
1910 while (vars)
1912 tree decl = TREE_VALUE (vars);
1913 tree type = TREE_TYPE (decl);
1914 tree temp = TREE_PURPOSE (vars);
1916 if (TYPE_NEEDS_DESTRUCTOR (type))
1918 if (TREE_STATIC (vars))
1919 expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node), 0);
1920 if (TREE_CODE (type) == ARRAY_TYPE)
1921 temp = decl;
1922 else
1924 mark_addressable (decl);
1925 temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
1927 temp = build_delete (TREE_TYPE (temp), temp, integer_two_node, LOOKUP_NORMAL, 0);
1928 expand_expr_stmt (temp);
1930 if (TREE_STATIC (vars))
1931 expand_end_cond ();
1933 vars = TREE_CHAIN (vars);
1936 expand_end_bindings (getdecls (), 1, 0);
1937 poplevel (1, 0, 1);
1938 pop_momentary ();
1940 finish_function (lineno, 0);
1942 #if defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER) && !defined(SDB_DEBUGGING_INFO)
1943 /* Now tell GNU LD that this is part of the static destructor set. */
1945 extern struct _iob *asm_out_file;
1946 fprintf (asm_out_file, ".stabs \"___DTOR_LIST__\",22,0,0,");
1947 assemble_name (asm_out_file, IDENTIFIER_POINTER (fnname));
1948 fputc ('\n', asm_out_file);
1950 #endif
1952 /* if it needed cleaning, then it will need messing up: drop through */
1954 mess_up:
1955 /* Must do this while we think we are at the top level. */
1956 vars = nreverse (static_aggregates);
1957 if (vars != NULL_TREE)
1959 buf[FILE_FUNCTION_PREFIX_LEN] = 'I';
1961 #if defined(sun)
1962 /* Point Sun linker at this function. */
1963 fprintf (asm_out_file, ".stabs \"_init\",10,0,0,0\n.stabs \"");
1964 assemble_name (asm_out_file, buf);
1965 fprintf (asm_out_file, "\",4,0,0,0\n");
1966 #endif
1968 fnname = get_identifier (buf);
1969 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
1970 DECL_PRINT_NAME (current_function_decl) = "file initialization";
1971 fnname = DECL_NAME (current_function_decl);
1972 store_parm_decls ();
1974 pushlevel (0);
1975 clear_last_expr ();
1976 push_momentary ();
1977 expand_start_bindings (0);
1979 #ifdef SOS
1980 if (flag_all_virtual == 2)
1982 tree decl;
1983 char c = buf[FILE_FUNCTION_PREFIX_LEN];
1984 buf[FILE_FUNCTION_PREFIX_LEN] = 'Z';
1986 decl = pushdecl (build_lang_decl (FUNCTION_DECL, get_identifier (buf), default_function_type));
1987 finish_decl (decl, NULL_TREE, NULL_TREE);
1988 expand_expr_stmt (build_function_call (decl, NULL_TREE));
1989 buf[FILE_FUNCTION_PREFIX_LEN] = c;
1991 #endif
1993 while (vars)
1995 tree decl = TREE_VALUE (vars);
1996 tree init = TREE_PURPOSE (vars);
1998 /* If this was a static attribute within some function's scope,
1999 then don't initialize it here. Also, don't bother
2000 with initializers that contain errors. */
2001 if (TREE_STATIC (vars)
2002 || (init && TREE_CODE (init) == TREE_LIST
2003 && value_member (error_mark_node, init)))
2005 vars = TREE_CHAIN (vars);
2006 continue;
2009 if (TREE_CODE (decl) == VAR_DECL)
2011 /* Set these global variables so that GDB at least puts
2012 us near the declaration which required the initialization. */
2013 input_filename = DECL_SOURCE_FILE (decl);
2014 lineno = DECL_SOURCE_LINE (decl);
2015 emit_note (input_filename, lineno);
2017 if (init)
2019 if (TREE_CODE (init) == VAR_DECL)
2021 /* This behavior results when there are
2022 multiple declarations of an aggregate,
2023 the last of which defines it. */
2024 if (DECL_RTL (init) == DECL_RTL (decl))
2026 assert (DECL_INITIAL (decl) == error_mark_node
2027 || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
2028 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE));
2029 init = DECL_INITIAL (init);
2030 if (TREE_CODE (init) == CONSTRUCTOR
2031 && CONSTRUCTOR_ELTS (init) == NULL_TREE)
2032 init = NULL_TREE;
2034 #if 0
2035 else if (TREE_TYPE (decl) == TREE_TYPE (init))
2037 #if 1
2038 assert (0);
2039 #else
2040 /* point to real decl's rtl anyway. */
2041 DECL_RTL (init) = DECL_RTL (decl);
2042 assert (DECL_INITIAL (decl) == error_mark_node);
2043 init = DECL_INITIAL (init);
2044 #endif /* 1 */
2046 #endif /* 0 */
2049 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2050 || init == 0
2051 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2052 expand_aggr_init (decl, init, 0);
2053 else if (TREE_CODE (init) == TREE_VEC)
2054 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2055 TREE_VEC_ELT (init, 1),
2056 TREE_VEC_ELT (init, 2), 0),
2057 const0_rtx, VOIDmode, 0);
2058 else
2059 expand_assignment (decl, init, 0, 0);
2061 else if (TREE_CODE (decl) == SAVE_EXPR)
2063 if (! PARM_DECL_EXPR (decl))
2065 /* a `new' expression at top level. */
2066 expand_expr (decl, const0_rtx, VOIDmode, 0);
2067 expand_aggr_init (build_indirect_ref (decl, 0), init, 0);
2070 else if (decl == error_mark_node)
2072 else abort ();
2073 vars = TREE_CHAIN (vars);
2076 expand_end_bindings (getdecls (), 1, 0);
2077 poplevel (1, 0, 1);
2078 pop_momentary ();
2080 finish_function (lineno, 0);
2081 #if defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER) && !defined(SDB_DEBUGGING_INFO)
2082 /* Now tell GNU LD that this is part of the static constructor set. */
2084 extern struct _iob *asm_out_file;
2085 fprintf (asm_out_file, ".stabs \"___CTOR_LIST__\",22,0,0,");
2086 assemble_name (asm_out_file, IDENTIFIER_POINTER (fnname));
2087 fputc ('\n', asm_out_file);
2089 #endif
2092 #ifdef SOS
2093 if (flag_all_virtual == 2)
2095 tree __sosDynError = default_conversion (lookup_name (get_identifier ("sosDynError")));
2097 tree null_string = build1 (ADDR_EXPR, string_type_node, combine_strings (build_string (0, "")));
2098 tree tags = gettags ();
2099 tree decls = getdecls ();
2100 tree entry;
2101 int i;
2103 entry = NULL_TREE;
2104 for (i = 0; i < 3; i++)
2105 entry = tree_cons (NULL_TREE, integer_zero_node, entry);
2106 zlink = build_tree_list (NULL_TREE, build (CONSTRUCTOR, zlink_type, NULL_TREE, entry));
2107 TREE_LITERAL (TREE_VALUE (zlink)) = 1;
2108 TREE_STATIC (TREE_VALUE (zlink)) = 1;
2110 entry = NULL_TREE;
2111 for (i = 0; i < 5; i++)
2112 entry = tree_cons (NULL_TREE, integer_zero_node, entry);
2113 zret = build_tree_list (NULL_TREE, build (CONSTRUCTOR, zret_type, NULL_TREE, entry));
2114 TREE_LITERAL (TREE_VALUE (zret)) = 1;
2115 TREE_STATIC (TREE_VALUE (zret)) = 1;
2117 /* Symbols with external visibility (except globally visible
2118 dynamic member functions) into the `zlink' table. */
2119 while (decls)
2121 if (TREE_PUBLIC (decls)
2122 && TREE_ASM_WRITTEN (decls)
2123 && (TREE_CODE (decls) != FUNCTION_DECL
2124 || TREE_CODE (TREE_TYPE (decls)) != METHOD_TYPE
2125 || TYPE_DYNAMIC (TYPE_METHOD_BASETYPE (TREE_TYPE (decls))) == 0))
2127 entry = build (CONSTRUCTOR, zlink_type, NULL_TREE,
2128 tree_cons (NULL_TREE,
2129 build1 (ADDR_EXPR, string_type_node,
2130 combine_strings (build_string (IDENTIFIER_LENGTH (DECL_NAME (decls)),
2131 IDENTIFIER_POINTER (DECL_NAME (decls))))),
2132 tree_cons (NULL_TREE, integer_one_node,
2133 build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, decls, 0)))));
2134 TREE_LITERAL (entry) = 1;
2135 TREE_STATIC (entry) = 1;
2136 zlink = tree_cons (NULL_TREE, entry, zlink);
2138 decls = TREE_CHAIN (decls);
2141 buf[FILE_FUNCTION_PREFIX_LEN] = 'Z';
2143 fnname = get_identifier (buf);
2144 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2145 fnname = DECL_NAME (current_function_decl);
2146 store_parm_decls ();
2148 pushlevel (0);
2149 clear_last_expr ();
2150 push_momentary ();
2151 expand_start_bindings (0);
2154 tree decl, type;
2155 /* Lay out a table static to this function
2156 with information about all text and data that
2157 this file provides. */
2158 tree zlink_table = finish_table (get_identifier ("__ZLINK_tbl"), zlink_type, zlink, 0);
2159 decl = pushdecl (build_decl (VAR_DECL, get_identifier ("_ZLINK_once"), integer_type_node));
2160 TREE_STATIC (decl) = 1;
2161 finish_decl (decl, NULL_TREE, NULL_TREE);
2162 expand_start_cond (truthvalue_conversion (decl), 0);
2163 expand_null_return ();
2164 expand_end_cond ();
2165 finish_stmt ();
2166 expand_expr_stmt (build_modify_expr (decl, NOP_EXPR, integer_one_node));
2167 type = build_function_type (void_type_node, NULL_TREE);
2168 decl = pushdecl (build_lang_decl (FUNCTION_DECL, get_identifier ("_Ztable_from_cfront"), type));
2169 TREE_EXTERNAL (decl) = 1;
2170 finish_decl (decl, NULL_TREE, NULL_TREE);
2171 expand_expr_stmt (build_function_call (decl, build_tree_list (NULL_TREE, zlink_table)));
2172 expand_null_return ();
2174 expand_end_bindings (0, 1, 0);
2175 poplevel (1, 0, 1);
2176 pop_momentary ();
2177 finish_function (lineno, 0);
2179 buf[FILE_FUNCTION_PREFIX_LEN] = 'Y';
2180 fnname = get_identifier (buf);
2181 start_function (build_tree_list (NULL_TREE, get_identifier ("int")),
2182 build_parse_node (INDIRECT_REF, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE)), 0, 0);
2183 fnname = DECL_NAME (current_function_decl);
2184 store_parm_decls ();
2186 pushlevel (0);
2187 clear_last_expr ();
2188 push_momentary ();
2189 expand_start_bindings (0);
2192 #define SOS_VERSION 2
2193 tree sosVersionNumber = build_int_2 (SOS_VERSION, 0);
2194 tree zret_table;
2196 /* For each type defined, if is a dynamic type, write out
2197 an entry linking its member functions with their names. */
2199 while (tags)
2201 tree type = TREE_VALUE (tags);
2202 if (TYPE_DYNAMIC (type))
2204 /* SOS currently only implements single inheritance,
2205 so we just pick up one string, if this class
2206 has a base class. */
2207 tree base_name = CLASSTYPE_N_BASECLASSES (type) > 0 && TYPE_DYNAMIC (CLASSTYPE_BASECLASS (type, 1))
2208 ? build1 (ADDR_EXPR, string_type_node, CLASSTYPE_TYPENAME_AS_STRING (CLASSTYPE_BASECLASS (type, 1)))
2209 : null_string;
2210 tree dyn_table, dyn_entry = NULL_TREE, fns = CLASS_ASSOC_VIRTUALS (type);
2211 while (fns)
2213 if (TREE_ASM_WRITTEN (TREE_OPERAND (TREE_VALUE (fns), 0)))
2214 dyn_entry = tree_cons (NULL_TREE, TREE_VALUE (fns), dyn_entry);
2215 else
2216 dyn_entry = tree_cons (NULL_TREE, __sosDynError, dyn_entry);
2217 fns = TREE_CHAIN (fns);
2219 dyn_entry = nreverse (dyn_entry);
2220 dyn_entry = tree_cons (NULL_TREE, build1 (NOP_EXPR, TYPE_POINTER_TO (default_function_type), sosVersionNumber),
2221 tree_cons (NULL_TREE, integer_zero_node,
2222 tree_cons (NULL_TREE, integer_zero_node,
2223 dyn_entry)));
2224 dyn_table = finish_table (DECL_NAME (TYPE_NAME (type)), TYPE_POINTER_TO (default_function_type), dyn_entry, 0);
2225 entry = build (CONSTRUCTOR, zret_type, NULL_TREE,
2226 tree_cons (NULL_TREE, build1 (ADDR_EXPR, string_type_node, CLASSTYPE_TYPENAME_AS_STRING (type)),
2227 tree_cons (NULL_TREE, default_conversion (dyn_table),
2228 tree_cons (NULL_TREE, build_int_2 (CLASSTYPE_VSIZE (type), 0),
2229 tree_cons (NULL_TREE, base_name,
2230 build_tree_list (NULL_TREE, integer_zero_node))))));
2231 TREE_LITERAL (entry) = 1;
2232 TREE_STATIC (entry) = 1;
2233 zret = tree_cons (NULL_TREE, entry, zret);
2235 tags = TREE_CHAIN (tags);
2237 zret_table = finish_table (get_identifier ("__Zret"), zret_type, zret, 0);
2238 c_expand_return (convert (build_pointer_type (integer_type_node), default_conversion (zret_table)));
2240 expand_end_bindings (0, 1, 0);
2241 poplevel (1, 0, 1);
2242 pop_momentary ();
2243 finish_function (lineno, 0);
2245 #if defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER)
2247 extern struct _iob *asm_out_file;
2248 fprintf (asm_out_file, ".stabs \"___ZTOR_LIST__\",22,0,0,");
2249 assemble_name (asm_out_file, IDENTIFIER_POINTER (fnname));
2250 fputc ('\n', asm_out_file);
2252 #endif
2254 #endif
2256 /* Done with C language context needs. */
2257 pop_lang_context ();
2259 /* Now write out any static class variables (which may have since
2260 learned how to be initialized). */
2261 while (pending_statics)
2263 tree decl = TREE_VALUE (pending_statics);
2264 if (TREE_USED (decl) == 1
2265 || TREE_READONLY (decl) == 0
2266 || DECL_INITIAL (decl) == 0)
2267 rest_of_decl_compilation (decl, DECL_ASSEMBLER_NAME (decl), 1, 1);
2268 pending_statics = TREE_CHAIN (pending_statics);
2271 this_time = gettime ();
2272 parse_time -= this_time - start_time;
2273 varconst_time += this_time - start_time;
2275 /* Now write out inline functions which had their addresses taken
2276 and which were not declared virtual and which were not declared
2277 `extern inline'. */
2278 while (pending_addressable_inlines)
2280 tree decl = TREE_VALUE (pending_addressable_inlines);
2281 if (! TREE_ASM_WRITTEN (decl)
2282 && ! TREE_EXTERNAL (decl)
2283 && DECL_SAVED_INSNS (decl))
2284 output_inline_function (decl);
2285 pending_addressable_inlines = TREE_CHAIN (pending_addressable_inlines);
2288 start_time = gettime ();
2290 /* Now delete from the chain of variables all virtual function tables.
2291 We output them all ourselves, because each will be treated specially. */
2293 /* Make last thing in global scope not be a virtual function table. */
2294 vars = build_decl (VAR_DECL, get_identifier (" @%$#@!"), integer_type_node);
2295 TREE_EXTERNAL (vars) = 1;
2296 pushdecl (vars);
2297 /* Make this dummy variable look used. */
2298 TREE_ASM_WRITTEN (vars) = 1;
2299 DECL_INITIAL (vars) = error_mark_node;
2301 walk_vtables (finish_vtable_typedecl, finish_vtable_vardecl);
2303 if (write_virtuals == 2)
2305 /* Now complain about an virtual function tables promised
2306 but not delivered. */
2307 while (pending_vtables)
2309 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
2310 error ("virtual function table for `%s' not defined",
2311 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
2312 pending_vtables = TREE_CHAIN (pending_vtables);
2316 permanent_allocation ();
2317 this_time = gettime ();
2318 parse_time -= this_time - start_time;
2319 varconst_time += this_time - start_time;
2321 if (flag_detailed_statistics)
2322 dump_time_statistics ();