1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.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 2, or (at your option)
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. */
38 extern tree grokdeclarator ();
39 extern tree get_file_function_name ();
40 extern tree cleanups_this_call;
41 static void grok_function_init ();
43 /* A list of virtual function tables we must make sure to write out. */
46 /* A list of static class variables. This is needed, because a
47 static class variable can be declared inside the class without
48 an initializer, and then initialized, staticly, outside the class. */
51 /* A list of functions which were declared inline, but which we
52 may need to emit outline anyway. */
53 static tree saved_inlines;
55 /* Used to help generate temporary names which are unique within
56 a function. Reset to 0 by start_function. */
58 static int temp_name_counter;
60 /* Same, but not reset. Local temp variables and global temp variables
61 can have the same name. */
62 static int global_temp_name_counter;
64 /* Flag used when debugging spew.c */
66 extern int spew_debug;
68 /* C (and C++) language-specific option variables. */
70 /* Nonzero means allow type mismatches in conditional expressions;
71 just make their values `void'. */
73 int flag_cond_mismatch;
75 /* Nonzero means give `double' the same size as `float'. */
77 int flag_short_double;
79 /* Nonzero means don't recognize the keyword `asm'. */
83 /* Nonzero means don't recognize the non-ANSI builtin functions. */
87 /* Nonzero means don't recognize the non-ANSI builtin functions.
90 int flag_no_nonansi_builtin;
92 /* Nonzero means do some things the same way PCC does. */
96 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
98 int flag_signed_bitfields = 1;
100 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
102 int flag_no_ident = 0;
104 /* Nonzero means disable GNU extensions. */
108 /* Nonzero means do emit exported implementations of functions even if
109 they can be inlined. */
111 int flag_implement_inlines = 1;
113 /* Nonzero means do emit exported implementations of templates, instead of
114 multiple static copies in each file that needs a definition. */
116 int flag_external_templates = 0;
118 /* Nonzero means that the decision to emit or not emit the implementation of a
119 template depends on where the template is instantiated, rather than where
122 int flag_alt_external_templates = 0;
124 /* Nonzero means that implicit instantiations will be emitted if needed. */
126 int flag_implicit_templates = 1;
128 /* Nonzero means warn about implicit declarations. */
130 int warn_implicit = 1;
132 /* Nonzero means warn when all ctors or dtors are private, and the class
135 int warn_ctor_dtor_privacy = 1;
137 /* True if we want to implement vtbvales using "thunks".
138 The default is off now, but will be on later.
140 Also causes output of vtables to be controlled by whether
141 we seen the class's first non-inline virtual function. */
142 int flag_vtable_thunks = 0;
144 /* Nonzero means give string constants the type `const char *'
145 to get extra warnings from them. These warnings will be too numerous
146 to be useful, except in thoroughly ANSIfied programs. */
148 int warn_write_strings;
150 /* Nonzero means warn about pointer casts that can drop a type qualifier
151 from the pointer target type. */
155 /* Nonzero means warn that dbx info for template class methods isn't fully
158 int warn_template_debugging;
160 /* Warn about traditional constructs whose meanings changed in ANSI C. */
162 int warn_traditional;
164 /* Nonzero means warn about sizeof(function) or addition/subtraction
165 of function pointers. */
167 int warn_pointer_arith;
169 /* Nonzero means warn for non-prototype function decls
170 or non-prototyped defs without previous prototype. */
172 int warn_strict_prototypes;
174 /* Nonzero means warn for any function def without prototype decl. */
176 int warn_missing_prototypes;
178 /* Nonzero means warn about multiple (redundant) decls for the same single
179 variable or function. */
181 int warn_redundant_decls;
183 /* Warn if initializer is not completely bracketed. */
185 int warn_missing_braces;
187 /* Warn about *printf or *scanf format/argument anomalies. */
191 /* Warn about a subscript that has type char. */
193 int warn_char_subscripts;
195 /* Warn if a type conversion is done that might have confusing results. */
199 /* Warn if adding () is suggested. */
201 int warn_parentheses = 1;
203 /* Non-zero means warn in function declared in derived class has the
204 same name as a virtual in the base class, but fails to match the
205 type signature of any virtual function in the base class. */
206 int warn_overloaded_virtual;
208 /* Non-zero means warn when declaring a class that has a non virtual
209 destructor, when it really ought to have a virtual one. */
212 /* Non-zero means warn when a function is declared extern and later inline. */
213 int warn_extern_inline;
215 /* Non-zero means warn when the compiler will reorder code. */
218 /* Non-zero means warn when sysnthesis behavior differs from Cfront's. */
221 /* Nonzero means `$' can be in an identifier.
222 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
224 #ifndef DOLLARS_IN_IDENTIFIERS
225 #define DOLLARS_IN_IDENTIFIERS 1
227 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
229 /* Nonzero for -fno-strict-prototype switch: do not consider empty
230 argument prototype to mean function takes no arguments. */
232 int strict_prototype = 1;
233 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
235 /* Nonzero means that labels can be used as first-class objects */
239 /* Non-zero means to collect statistics which might be expensive
240 and to print them when we are done. */
241 int flag_detailed_statistics;
243 /* C++ specific flags. */
244 /* Nonzero for -fall-virtual: make every member function (except
245 constructors) lay down in the virtual function table. Calls
246 can then either go through the virtual function table or not,
249 int flag_all_virtual;
251 /* Zero means that `this' is a *const. This gives nice behavior in the
252 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
253 -2 means we're constructing an object and it has fixed type. */
255 int flag_this_is_variable;
257 /* Nonzero means memoize our member lookups. */
259 int flag_memoize_lookups; int flag_save_memoized_contexts;
261 /* 3 means write out only virtuals function tables `defined'
262 in this implementation file.
263 2 means write out only specific virtual function tables
264 and give them (C) public access.
265 1 means write out virtual function tables and give them
267 0 means write out virtual function tables and give them
268 (C) static access (default).
269 -1 means declare virtual function tables extern. */
273 /* Nonzero means we should attempt to elide constructors when possible. */
275 int flag_elide_constructors;
277 /* Nonzero means recognize and handle exception handling constructs.
278 Use ansi syntax and semantics. WORK IN PROGRESS! */
280 int flag_handle_exceptions;
282 /* Nonzero means recognize and handle signature language constructs. */
284 int flag_handle_signatures;
286 /* Nonzero means that member functions defined in class scope are
287 inline by default. */
289 int flag_default_inline = 1;
291 /* Controls whether enums and ints freely convert.
292 1 means with complete freedom.
293 0 means enums can convert to ints, but not vice-versa. */
294 int flag_int_enum_equivalence;
296 /* Controls whether compiler is operating under LUCID's Cadillac
297 system. 1 means yes, 0 means no. */
300 /* Controls whether compiler generates code to build objects
301 that can be collected when they become garbage. */
304 /* Controls whether compiler generates 'type descriptor' that give
305 run-time type information. */
308 /* Nonzero if we wish to output cross-referencing information
309 for the GNU class browser. */
310 extern int flag_gnu_xref;
312 /* Nonzero if compiler can make `reasonable' assumptions about
313 references and objects. For example, the compiler must be
314 conservative about the following and not assume that `a' is nonnull:
319 In general, it is `reasonable' to assume that for many programs,
320 and better code can be generated in that case. */
322 int flag_assume_nonnull_objects;
324 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
326 int flag_huge_objects;
328 /* Nonzero if we want to conserve space in the .o files. We do this
329 by putting uninitialized data and runtime initialized data into
330 .common instead of .data at the expense of not flaging multiple
332 int flag_conserve_space;
334 /* Nonzero if we want to obey access control semantics. */
335 int flag_access_control = 1;
337 /* Table of language-dependent -f options.
338 STRING is the option name. VARIABLE is the address of the variable.
339 ON_VALUE is the value to store in VARIABLE
340 if `-fSTRING' is seen as an option.
341 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
343 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
345 {"signed-char", &flag_signed_char, 1},
346 {"unsigned-char", &flag_signed_char, 0},
347 {"signed-bitfields", &flag_signed_bitfields, 1},
348 {"unsigned-bitfields", &flag_signed_bitfields, 0},
349 {"short-enums", &flag_short_enums, 1},
350 {"short-double", &flag_short_double, 1},
351 {"cond-mismatch", &flag_cond_mismatch, 1},
352 {"asm", &flag_no_asm, 0},
353 {"builtin", &flag_no_builtin, 0},
354 {"ident", &flag_no_ident, 0},
355 {"labels-ok", &flag_labels_ok, 1},
356 {"stats", &flag_detailed_statistics, 1},
357 {"this-is-variable", &flag_this_is_variable, 1},
358 {"strict-prototype", &strict_prototypes_lang_cplusplus, 1},
359 {"all-virtual", &flag_all_virtual, 1},
360 {"memoize-lookups", &flag_memoize_lookups, 1},
361 {"elide-constructors", &flag_elide_constructors, 1},
362 {"handle-exceptions", &flag_handle_exceptions, 1},
363 {"handle-signatures", &flag_handle_signatures, 1},
364 {"default-inline", &flag_default_inline, 1},
365 {"dollars-in-identifiers", &dollars_in_ident, 1},
366 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
368 {"rtti", &flag_rtti, 1},
369 {"xref", &flag_gnu_xref, 1},
370 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
371 {"implement-inlines", &flag_implement_inlines, 1},
372 {"external-templates", &flag_external_templates, 1},
373 {"implicit-templates", &flag_implicit_templates, 1},
374 {"huge-objects", &flag_huge_objects, 1},
375 {"conserve-space", &flag_conserve_space, 1},
376 {"vtable-thunks", &flag_vtable_thunks, 1},
377 {"short-temps", &flag_short_temps, 1},
378 {"access-control", &flag_access_control, 1},
379 {"nonansi-builtins", &flag_no_nonansi_builtin, 0}
382 /* Decode the string P as a language-specific option.
383 Return 1 if it is recognized (and handle it);
384 return 0 if not recognized. */
387 lang_decode_option (p)
390 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
391 flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
392 flag_this_is_variable = 1;
393 /* The +e options are for cfront compatibility. They come in as
394 `-+eN', to kludge around gcc.c's argument handling. */
395 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
397 int old_write_virtuals = write_virtuals;
400 else if (p[3] == '0')
402 else if (p[3] == '2')
404 else error ("invalid +e option");
405 if (old_write_virtuals != 0
406 && write_virtuals != old_write_virtuals)
407 error ("conflicting +e options given");
409 else if (p[0] == '-' && p[1] == 'f')
411 /* Some kind of -f option.
412 P's value is the option sans `-f'.
413 Search for it in the table of options. */
417 /* Try special -f options. */
419 if (!strcmp (p, "save-memoized"))
421 flag_memoize_lookups = 1;
422 flag_save_memoized_contexts = 1;
425 if (!strcmp (p, "no-save-memoized"))
427 flag_memoize_lookups = 0;
428 flag_save_memoized_contexts = 0;
431 else if (! strncmp (p, "cadillac", 8))
433 flag_cadillac = atoi (p+9);
436 else if (! strncmp (p, "no-cadillac", 11))
441 else if (! strcmp (p, "gc"))
444 /* This must come along for the ride. */
448 else if (! strcmp (p, "no-gc"))
451 /* This must come along for the ride. */
455 else if (! strcmp (p, "alt-external-templates"))
457 flag_external_templates = 1;
458 flag_alt_external_templates = 1;
461 else if (! strcmp (p, "no-alt-external-templates"))
463 flag_alt_external_templates = 0;
466 else if (!strcmp (p, "ansi-overloading"))
468 warning ("-fansi-overloading is no longer meaningful");
471 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
474 if (!strcmp (p, lang_f_options[j].string))
476 *lang_f_options[j].variable = lang_f_options[j].on_value;
477 /* A goto here would be cleaner,
478 but breaks the vax pcc. */
481 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
482 && ! strcmp (p+3, lang_f_options[j].string))
484 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
490 else if (p[0] == '-' && p[1] == 'W')
494 /* The -W options control the warning behavior of the compiler. */
497 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
500 if (!strcmp (p, "implicit"))
501 warn_implicit = setting;
502 else if (!strcmp (p, "return-type"))
503 warn_return_type = setting;
504 else if (!strcmp (p, "ctor-dtor-privacy"))
505 warn_ctor_dtor_privacy = setting;
506 else if (!strcmp (p, "write-strings"))
507 warn_write_strings = setting;
508 else if (!strcmp (p, "cast-qual"))
509 warn_cast_qual = setting;
510 else if (!strcmp (p, "traditional"))
511 warn_traditional = setting;
512 else if (!strcmp (p, "char-subscripts"))
513 warn_char_subscripts = setting;
514 else if (!strcmp (p, "pointer-arith"))
515 warn_pointer_arith = setting;
516 else if (!strcmp (p, "strict-prototypes"))
517 warn_strict_prototypes = setting;
518 else if (!strcmp (p, "missing-prototypes"))
519 warn_missing_prototypes = setting;
520 else if (!strcmp (p, "redundant-decls"))
521 warn_redundant_decls = setting;
522 else if (!strcmp (p, "missing-braces"))
523 warn_missing_braces = setting;
524 else if (!strcmp (p, "format"))
525 warn_format = setting;
526 else if (!strcmp (p, "conversion"))
527 warn_conversion = setting;
528 else if (!strcmp (p, "parentheses"))
529 warn_parentheses = setting;
530 else if (!strcmp (p, "non-virtual-dtor"))
531 warn_nonvdtor = setting;
532 else if (!strcmp (p, "extern-inline"))
533 warn_extern_inline = setting;
534 else if (!strcmp (p, "reorder"))
535 warn_reorder = setting;
536 else if (!strcmp (p, "synth"))
537 warn_synth = setting;
538 else if (!strcmp (p, "comment"))
539 ; /* cpp handles this one. */
540 else if (!strcmp (p, "comments"))
541 ; /* cpp handles this one. */
542 else if (!strcmp (p, "trigraphs"))
543 ; /* cpp handles this one. */
544 else if (!strcmp (p, "import"))
545 ; /* cpp handles this one. */
546 else if (!strcmp (p, "all"))
548 extra_warnings = setting;
549 warn_return_type = setting;
550 warn_unused = setting;
551 warn_implicit = setting;
552 warn_ctor_dtor_privacy = setting;
553 warn_switch = setting;
554 warn_format = setting;
555 warn_missing_braces = setting;
556 warn_extern_inline = setting;
557 warn_nonvdtor = setting;
558 /* We save the value of warn_uninitialized, since if they put
559 -Wuninitialized on the command line, we need to generate a
560 warning about not using it without also specifying -O. */
561 if (warn_uninitialized != 1)
562 warn_uninitialized = (setting ? 2 : 0);
563 warn_template_debugging = setting;
564 warn_reorder = setting;
567 else if (!strcmp (p, "overloaded-virtual"))
568 warn_overloaded_virtual = setting;
571 else if (!strcmp (p, "-ansi"))
572 flag_no_asm = 1, dollars_in_ident = 0, flag_no_nonansi_builtin = 1,
575 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
576 it's probably safe to assume no sane person would ever want to use this
577 under normal circumstances. */
578 else if (!strcmp (p, "-spew-debug"))
587 /* Incorporate `const' and `volatile' qualifiers for member functions.
588 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
589 QUALS is a list of qualifiers. */
591 grok_method_quals (ctype, function, quals)
592 tree ctype, function, quals;
594 tree fntype = TREE_TYPE (function);
595 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
599 extern tree ridpointers[];
601 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
603 if (TYPE_READONLY (ctype))
604 error ("duplicate `%s' %s",
605 IDENTIFIER_POINTER (TREE_VALUE (quals)),
606 (TREE_CODE (function) == FUNCTION_DECL
607 ? "for member function" : "in type declaration"));
608 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
609 build_pointer_type (ctype);
611 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
613 if (TYPE_VOLATILE (ctype))
614 error ("duplicate `%s' %s",
615 IDENTIFIER_POINTER (TREE_VALUE (quals)),
616 (TREE_CODE (function) == FUNCTION_DECL
617 ? "for member function" : "in type declaration"));
618 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
619 build_pointer_type (ctype);
622 my_friendly_abort (20);
623 quals = TREE_CHAIN (quals);
626 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
627 (TREE_CODE (fntype) == METHOD_TYPE
628 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
629 : TYPE_ARG_TYPES (fntype)));
631 fntype = build_exception_variant (ctype, fntype, raises);
633 TREE_TYPE (function) = fntype;
637 #if 0 /* Not used. */
638 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
639 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
640 /* This does not yet work with user defined conversion operators
643 substitute_nice_name (decl)
646 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
648 char *n = decl_as_string (DECL_NAME (decl), 1);
649 if (n[strlen (n) - 1] == ' ')
650 n[strlen (n) - 1] = 0;
651 DECL_NAME (decl) = get_identifier (n);
656 /* Warn when -fexternal-templates is used and #pragma
657 interface/implementation is not used all the times it should be,
660 warn_if_unknown_interface ()
662 static int already_warned = 0;
663 if (++already_warned == 1)
664 warning ("templates that are built with -fexternal-templates should be in files that have #pragma interface/implementation");
667 /* A subroutine of the parser, to handle a component list. */
669 grok_x_components (specs, components)
670 tree specs, components;
672 register tree t, x, tcode;
674 /* We just got some friends. They have been recorded elsewhere. */
675 if (components == void_type_node)
678 if (components == NULL_TREE)
680 t = groktypename (build_decl_list (specs, NULL_TREE));
684 error ("error in component specification");
688 switch (TREE_CODE (t))
691 /* Static anonymous unions come out as VAR_DECLs. */
692 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
693 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
696 /* We return SPECS here, because in the parser it was ending
697 up with not doing anything to $$, which is what SPECS
703 /* This code may be needed for UNION_TYPEs as
705 tcode = record_type_node;
706 if (CLASSTYPE_DECLARED_CLASS(t))
707 tcode = class_type_node;
708 else if (IS_SIGNATURE(t))
709 tcode = signature_type_node;
711 t = xref_defn_tag(tcode, TYPE_IDENTIFIER(t), NULL_TREE);
713 CLASSTYPE_NO_GLOBALIZE(t) = 1;
719 if (TREE_CODE(t) == UNION_TYPE)
720 tcode = union_type_node;
722 tcode = enum_type_node;
724 t = xref_defn_tag(tcode, TYPE_IDENTIFIER(t), NULL_TREE);
725 if (TREE_CODE(t) == UNION_TYPE && TYPE_CONTEXT(t))
726 CLASSTYPE_NO_GLOBALIZE(t) = 1;
727 if (TREE_CODE (t) == UNION_TYPE
728 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
730 struct pending_inline **p;
731 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
733 /* Wipe out memory of synthesized methods */
734 TYPE_HAS_CONSTRUCTOR (t) = 0;
735 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
736 TYPE_HAS_INIT_REF (t) = 0;
737 TYPE_HAS_CONST_INIT_REF (t) = 0;
738 TYPE_HAS_ASSIGN_REF (t) = 0;
739 TYPE_HAS_ASSIGNMENT (t) = 0;
740 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
742 p = &pending_inlines;
743 for (; *p; *p = (*p)->next)
744 if (DECL_CONTEXT ((*p)->fndecl) != t)
747 else if (TREE_CODE (t) == ENUMERAL_TYPE)
748 x = grok_enum_decls (t, NULL_TREE);
755 if (t != void_type_node)
756 error ("empty component declaration");
762 t = TREE_TYPE (components);
763 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
764 return grok_enum_decls (t, components);
770 /* Classes overload their constituent function names automatically.
771 When a function name is declared in a record structure,
772 its name is changed to it overloaded name. Since names for
773 constructors and destructors can conflict, we place a leading
776 CNAME is the name of the class we are grokking for.
778 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
780 FLAGS contains bits saying what's special about today's
781 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
783 If FUNCTION is a destructor, then we must add the `auto-delete' field
784 as a second parameter. There is some hair associated with the fact
785 that we must "declare" this variable in the manner consistent with the
786 way the rest of the arguments were declared.
788 QUALS are the qualifiers for the this pointer. */
791 grokclassfn (ctype, cname, function, flags, quals)
792 tree ctype, cname, function;
793 enum overload_flags flags;
796 tree fn_name = DECL_NAME (function);
801 if (fn_name == NULL_TREE)
803 error ("name missing for member function");
804 fn_name = get_identifier ("<anonymous>");
805 DECL_NAME (function) = fn_name;
809 qualtype = grok_method_quals (ctype, function, quals);
813 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
814 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
816 /* Must add the class instance variable up front. */
817 /* Right now we just make this a pointer. But later
818 we may wish to make it special. */
819 tree type = TREE_VALUE (arg_types);
821 if ((flag_this_is_variable > 0)
822 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
823 type = TYPE_MAIN_VARIANT (type);
825 if (DECL_CONSTRUCTOR_P (function))
827 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
829 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
830 /* In this case we need "in-charge" flag saying whether
831 this constructor is responsible for initialization
832 of virtual baseclasses or not. */
833 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
834 /* Mark the artificial `__in_chrg' parameter as "artificial". */
835 SET_DECL_ARTIFICIAL (parm);
836 DECL_ARG_TYPE (parm) = integer_type_node;
837 DECL_REGISTER (parm) = 1;
838 TREE_CHAIN (parm) = last_function_parms;
839 last_function_parms = parm;
843 parm = build_decl (PARM_DECL, this_identifier, type);
844 /* Mark the artificial `this' parameter as "artificial". */
845 SET_DECL_ARTIFICIAL (parm);
846 DECL_ARG_TYPE (parm) = type;
847 /* We can make this a register, so long as we don't
848 accidentally complain if someone tries to take its address. */
849 DECL_REGISTER (parm) = 1;
850 if (TYPE_READONLY (type))
851 TREE_READONLY (parm) = 1;
852 TREE_CHAIN (parm) = last_function_parms;
853 last_function_parms = parm;
856 if (flags == DTOR_FLAG)
859 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
860 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
862 arg_types = hash_tree_chain (const_integer_type, void_list_node);
863 TREE_SIDE_EFFECTS (arg_types) = 1;
864 /* Build the overload name. It will look like `7Example'. */
865 if (IDENTIFIER_TYPE_VALUE (cname))
866 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
867 else if (IDENTIFIER_LOCAL_VALUE (cname))
868 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
870 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
871 it's defined out of the class definition, since poplevel_class wipes
872 it out. This used to be internal error 346. */
873 dbuf = build_overload_name (ctype, 1, 1);
874 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
875 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
878 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
879 parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
880 /* Mark the artificial `__in_chrg' parameter as "artificial". */
881 SET_DECL_ARTIFICIAL (parm);
882 TREE_USED (parm) = 1;
884 /* We don't need to mark the __in_chrg parameter itself as `const'
885 since its type is already `const int'. In fact we MUST NOT mark
886 it as `const' cuz that will screw up the debug info (causing it
887 to say that the type of __in_chrg is `const const int'). */
888 TREE_READONLY (parm) = 1;
890 DECL_ARG_TYPE (parm) = const_integer_type;
891 /* This is the same chain as DECL_ARGUMENTS (...). */
892 TREE_CHAIN (last_function_parms) = parm;
894 TREE_TYPE (function) = build_cplus_method_type (qualtype, void_type_node,
896 TYPE_HAS_DESTRUCTOR (ctype) = 1;
900 tree these_arg_types;
902 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
904 arg_types = hash_tree_chain (integer_type_node,
905 TREE_CHAIN (arg_types));
907 = build_cplus_method_type (qualtype,
908 TREE_TYPE (TREE_TYPE (function)),
910 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
913 these_arg_types = arg_types;
915 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
916 /* Only true for static member functions. */
917 these_arg_types = hash_tree_chain (TYPE_POINTER_TO (qualtype),
920 DECL_ASSEMBLER_NAME (function)
921 = build_decl_overload (fn_name, these_arg_types,
922 1 + DECL_CONSTRUCTOR_P (function));
925 /* This code is going into the compiler, but currently, it makes
926 libg++/src/Interger.cc not compile. The problem is that the nice name
927 winds up going into the symbol table, and conversion operations look
928 for the manged name. */
929 substitute_nice_name (function);
933 DECL_ARGUMENTS (function) = last_function_parms;
934 /* First approximations. */
935 DECL_CONTEXT (function) = ctype;
936 DECL_CLASS_CONTEXT (function) = ctype;
939 /* Work on the expr used by alignof (this is only called by the parser). */
947 if (TREE_CODE (expr) == COMPONENT_REF
948 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
949 error ("`__alignof__' applied to a bit-field");
951 if (TREE_CODE (expr) == INDIRECT_REF)
953 best = t = TREE_OPERAND (expr, 0);
954 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
956 while (TREE_CODE (t) == NOP_EXPR
957 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
960 t = TREE_OPERAND (t, 0);
961 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
962 if (thisalign > bestalign)
963 best = t, bestalign = thisalign;
965 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
969 /* ANSI says arrays and fns are converted inside comma.
970 But we can't convert them in build_compound_expr
971 because that would break commas in lvalues.
972 So do the conversion here if operand was a comma. */
973 if (TREE_CODE (expr) == COMPOUND_EXPR
974 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
975 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
976 expr = default_conversion (expr);
977 return c_alignof (TREE_TYPE (expr));
981 /* Create an ARRAY_REF, checking for the user doing things backwards
984 grok_array_decl (array_expr, index_exp)
985 tree array_expr, index_exp;
987 tree type = TREE_TYPE (array_expr);
989 if (type == error_mark_node || index_exp == error_mark_node)
990 return error_mark_node;
991 if (type == NULL_TREE)
993 /* Something has gone very wrong. Assume we are mistakenly reducing
994 an expression instead of a declaration. */
995 error ("parser may be lost: is there a '{' missing somewhere?");
999 if (TREE_CODE (type) == OFFSET_TYPE
1000 || TREE_CODE (type) == REFERENCE_TYPE)
1001 type = TREE_TYPE (type);
1003 /* If they have an `operator[]', use that. */
1004 if (TYPE_LANG_SPECIFIC (type)
1005 && TYPE_OVERLOADS_ARRAY_REF (type))
1006 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1007 array_expr, index_exp, NULL_TREE);
1009 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1010 if (TREE_CODE (type) == POINTER_TYPE
1011 || TREE_CODE (type) == ARRAY_TYPE)
1012 return build_array_ref (array_expr, index_exp);
1014 /* Woops, looks like they did something like `5[a]' instead of `a[5]'.
1015 We don't emit a warning or error for this, since it's allowed
1018 type = TREE_TYPE (index_exp);
1020 if (TREE_CODE (type) == OFFSET_TYPE
1021 || TREE_CODE (type) == REFERENCE_TYPE)
1022 type = TREE_TYPE (type);
1024 if (TREE_CODE (type) == POINTER_TYPE
1025 || TREE_CODE (type) == ARRAY_TYPE)
1026 return build_array_ref (index_exp, array_expr);
1028 /* The expression E1[E2] is identical (by definition) to *((E1)+(E2)). */
1029 return build_indirect_ref (build_binary_op (PLUS_EXPR, array_expr,
1034 /* Given the cast expression EXP, checking out its validity. Either return
1035 an error_mark_node if there was an unavoidable error, return a cast to
1036 void for trying to delete a pointer w/ the value 0, or return the
1037 call to delete. If DOING_VEC is 1, we handle things differently
1038 for doing an array delete. If DOING_VEC is 2, they gave us the
1039 array size as an argument to delete.
1040 Implements ARM $5.3.4. This is called from the parser. */
1042 delete_sanity (exp, size, doing_vec, use_global_delete)
1044 int doing_vec, use_global_delete;
1046 tree t = stabilize_reference (convert_from_reference (exp));
1047 tree type = TREE_TYPE (t);
1048 enum tree_code code = TREE_CODE (type);
1049 /* For a regular vector delete (aka, no size argument) we will pass
1050 this down as a NULL_TREE into build_vec_delete. */
1051 tree maxindex = NULL_TREE;
1052 /* This is used for deleting arrays. */
1058 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1059 if (! flag_traditional)
1060 pedwarn ("anachronistic use of array size in vector delete");
1063 elt_size = c_sizeof (type);
1066 if (code != POINTER_TYPE)
1068 cp_error ("type `%#T' argument given to `delete', expected pointer",
1070 return error_mark_node;
1073 /* Deleting a pointer with the value zero is legal and has no effect. */
1074 if (integer_zerop (t))
1075 return build1 (NOP_EXPR, void_type_node, t);
1078 if (code == POINTER_TYPE)
1080 /* You can't delete a pointer to constant. */
1081 if (TREE_READONLY (TREE_TYPE (type)))
1083 error ("`const *' cannot be deleted");
1084 return error_mark_node;
1086 /* You also can't delete functions. */
1087 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1089 error ("cannot delete a function");
1090 return error_mark_node;
1095 /* If the type has no destructor, then we should build a regular
1096 delete, instead of a vector delete. Otherwise, we would end
1097 up passing a bogus offset into __builtin_delete, which is
1098 not expecting it. */
1100 && TREE_CODE (type) == POINTER_TYPE
1101 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1104 use_global_delete = 1;
1109 return build_vec_delete (t, maxindex, elt_size, integer_one_node,
1110 integer_two_node, use_global_delete);
1112 return build_delete (type, t, integer_three_node,
1113 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
1117 /* Sanity check: report error if this function FUNCTION is not
1118 really a member of the class (CTYPE) it is supposed to belong to.
1119 CNAME is the same here as it is for grokclassfn above. */
1122 check_classfn (ctype, cname, function)
1123 tree ctype, cname, function;
1125 tree fn_name = DECL_NAME (function);
1127 tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
1131 if (method_vec != 0)
1133 methods = &TREE_VEC_ELT (method_vec, 0);
1134 end = TREE_VEC_END (method_vec);
1136 /* First suss out ctors and dtors. */
1137 if (*methods && fn_name == cname)
1140 while (++methods != end)
1142 if (fn_name == DECL_NAME (*methods))
1148 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1151 /* This should work, but causes libg++ to fail
1153 /* We have to do more extensive argument checking here, as
1154 the name may have been changed by asm("new_name"). */
1155 if (decls_match (function, fndecl))
1158 if (DECL_NAME (function) == DECL_NAME (fndecl))
1160 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1161 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1163 /* Get rid of the this parameter on functions that become
1165 if (DECL_STATIC_FUNCTION_P (fndecl)
1166 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1167 p1 = TREE_CHAIN (p1);
1169 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1170 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1171 && compparms (p1, p2, 3))
1175 fndecl = DECL_CHAIN (fndecl);
1183 cp_error ("argument list for `%#D' does not match any in class `%T'",
1188 cp_error ("no `%#D' member function declared in class `%T'",
1192 /* If we did not find the method in the class, add it to
1193 avoid spurious errors. */
1194 add_method (ctype, methods, function);
1197 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1198 of a structure component, returning a FIELD_DECL node.
1199 QUALS is a list of type qualifiers for this decl (such as for declaring
1200 const member functions).
1202 This is done during the parsing of the struct declaration.
1203 The FIELD_DECL nodes are chained together and the lot of them
1204 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1208 If class A defines that certain functions in class B are friends, then
1209 the way I have set things up, it is B who is interested in permission
1210 granted by A. However, it is in A's context that these declarations
1211 are parsed. By returning a void_type_node, class A does not attempt
1212 to incorporate the declarations of the friends within its structure.
1214 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1215 CHANGES TO CODE IN `start_method'. */
1218 grokfield (declarator, declspecs, raises, init, asmspec_tree)
1219 tree declarator, declspecs, raises, init, asmspec_tree;
1221 register tree value;
1223 int flags = LOOKUP_ONLYCONVERTING;
1225 /* Convert () initializers to = initializers. */
1226 if (init == NULL_TREE && declarator != NULL_TREE
1227 && TREE_CODE (declarator) == CALL_EXPR
1228 && TREE_OPERAND (declarator, 0)
1229 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1230 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1231 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1233 init = TREE_OPERAND (declarator, 1);
1234 declarator = TREE_OPERAND (declarator, 0);
1239 && TREE_CODE (init) == TREE_LIST
1240 && TREE_VALUE (init) == error_mark_node
1241 && TREE_CHAIN (init) == NULL_TREE)
1244 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
1246 return value; /* friend or constructor went bad. */
1248 /* Pass friendly classes back. */
1249 if (TREE_CODE (value) == VOID_TYPE)
1250 return void_type_node;
1252 if (DECL_NAME (value) != NULL_TREE
1253 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1254 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1255 cp_error ("member `%D' conflicts with virtual function table field name", value);
1257 /* Stash away type declarations. */
1258 if (TREE_CODE (value) == TYPE_DECL)
1260 DECL_NONLOCAL (value) = 1;
1261 DECL_CONTEXT (value) = current_class_type;
1262 DECL_CLASS_CONTEXT (value) = current_class_type;
1263 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1264 pushdecl_class_level (value);
1266 /* If we declare a typedef name for something that has no name,
1267 the typedef name is used for linkage. See 7.1.3 p4 94/0158. */
1268 if (TYPE_NAME (TREE_TYPE (value))
1269 && TREE_CODE (TYPE_NAME (TREE_TYPE (value))) == TYPE_DECL
1270 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (value))))
1272 TYPE_NAME (TREE_TYPE (value)) = value;
1273 TYPE_STUB_DECL (TREE_TYPE (value)) = value;
1278 if (IS_SIGNATURE (current_class_type)
1279 && TREE_CODE (value) != FUNCTION_DECL)
1281 error ("field declaration not allowed in signature");
1282 return void_type_node;
1285 if (DECL_IN_AGGR_P (value))
1287 cp_error ("`%D' is already defined in the class %T", value,
1288 DECL_CONTEXT (value));
1289 return void_type_node;
1293 cadillac_start_decl (value);
1296 asmspec = TREE_STRING_POINTER (asmspec_tree);
1300 if (IS_SIGNATURE (current_class_type)
1301 && TREE_CODE (value) == FUNCTION_DECL)
1303 error ("function declarations cannot have initializers in signature");
1306 else if (TREE_CODE (value) == FUNCTION_DECL)
1308 grok_function_init (value, init);
1311 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1312 /* Already complained in grokdeclarator. */
1316 /* We allow initializers to become parameters to base
1318 if (TREE_CODE (init) == TREE_LIST)
1320 if (TREE_CHAIN (init) == NULL_TREE)
1321 init = TREE_VALUE (init);
1323 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1326 if (TREE_CODE (init) == CONST_DECL)
1327 init = DECL_INITIAL (init);
1328 else if (TREE_READONLY_DECL_P (init))
1329 init = decl_constant_value (init);
1330 else if (TREE_CODE (init) == CONSTRUCTOR)
1331 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1332 my_friendly_assert (TREE_PERMANENT (init), 192);
1333 if (init == error_mark_node)
1334 /* We must make this look different than `error_mark_node'
1335 because `decl_const_value' would mis-interpret it
1336 as only meaning that this VAR_DECL is defined. */
1337 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1338 else if (! TREE_CONSTANT (init))
1340 /* We can allow references to things that are effectively
1341 static, since references are initialized with the address. */
1342 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1343 || (TREE_STATIC (init) == 0
1344 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1345 || DECL_EXTERNAL (init) == 0)))
1347 error ("field initializer is not constant");
1348 init = error_mark_node;
1354 /* The corresponding pop_obstacks is in finish_decl. */
1355 push_obstacks_nochange ();
1357 if (TREE_CODE (value) == VAR_DECL)
1359 /* We cannot call pushdecl here, because that would
1360 fill in the value of our TREE_CHAIN. Instead, we
1361 modify finish_decl to do the right thing, namely, to
1362 put this decl out straight away. */
1363 if (TREE_PUBLIC (value))
1365 /* current_class_type can be NULL_TREE in case of error. */
1366 if (asmspec == 0 && current_class_type)
1368 TREE_PUBLIC (value) = 1;
1369 DECL_INITIAL (value) = error_mark_node;
1370 DECL_ASSEMBLER_NAME (value)
1371 = build_static_name (current_class_type, DECL_NAME (value));
1373 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1375 /* Static consts need not be initialized in the class definition. */
1376 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1378 static int explanation = 0;
1380 error ("initializer invalid for static member with constructor");
1381 if (explanation++ == 0)
1382 error ("(you really want to initialize it separately)");
1385 /* Force the compiler to know when an uninitialized static
1386 const member is being used. */
1387 if (TYPE_READONLY (value) && init == 0)
1388 TREE_USED (value) = 1;
1390 DECL_INITIAL (value) = init;
1391 DECL_IN_AGGR_P (value) = 1;
1393 finish_decl (value, init, asmspec_tree, 1, flags);
1394 pushdecl_class_level (value);
1397 if (TREE_CODE (value) == FIELD_DECL)
1401 /* This must override the asm specifier which was placed
1402 by grokclassfn. Lay this out fresh. */
1403 DECL_RTL (value) = NULL_RTX;
1404 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1406 if (DECL_INITIAL (value) == error_mark_node)
1407 init = error_mark_node;
1408 finish_decl (value, init, asmspec_tree, 1, flags);
1409 DECL_INITIAL (value) = init;
1410 DECL_IN_AGGR_P (value) = 1;
1413 if (TREE_CODE (value) == FUNCTION_DECL)
1415 if (DECL_CHAIN (value) != NULL_TREE)
1417 /* Need a fresh node here so that we don't get circularity
1418 when we link these together. */
1419 value = copy_node (value);
1420 /* When does this happen? */
1421 my_friendly_assert (init == NULL_TREE, 193);
1425 /* This must override the asm specifier which was placed
1426 by grokclassfn. Lay this out fresh. */
1427 DECL_RTL (value) = NULL_RTX;
1428 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1430 finish_decl (value, init, asmspec_tree, 1, flags);
1432 /* Pass friends back this way. */
1433 if (DECL_FRIEND_P (value))
1434 return void_type_node;
1436 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1437 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1438 cp_error ("method `%#D' of local class must be defined in class body",
1442 DECL_IN_AGGR_P (value) = 1;
1445 my_friendly_abort (21);
1450 /* Like `grokfield', but for bitfields.
1451 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1454 grokbitfield (declarator, declspecs, width)
1455 tree declarator, declspecs, width;
1457 register tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL_TREE);
1459 if (! value) return NULL_TREE; /* friends went bad. */
1461 /* Pass friendly classes back. */
1462 if (TREE_CODE (value) == VOID_TYPE)
1463 return void_type_node;
1465 if (TREE_CODE (value) == TYPE_DECL)
1467 cp_error ("cannot declare `%D' to be a bitfield type", value);
1471 if (IS_SIGNATURE (current_class_type))
1473 error ("field declaration not allowed in signature");
1474 return void_type_node;
1477 if (DECL_IN_AGGR_P (value))
1479 cp_error ("`%D' is already defined in the class %T", value,
1480 DECL_CONTEXT (value));
1481 return void_type_node;
1484 GNU_xref_member (current_class_name, value);
1486 if (TREE_STATIC (value))
1488 cp_error ("static member `%D' cannot be a bitfield", value);
1491 finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1493 if (width != error_mark_node)
1495 /* detect invalid field size. */
1496 if (TREE_CODE (width) == CONST_DECL)
1497 width = DECL_INITIAL (width);
1498 else if (TREE_READONLY_DECL_P (width))
1499 width = decl_constant_value (width);
1500 if (TREE_CODE (width) != INTEGER_CST)
1502 cp_error ("structure field `%D' width not an integer constant",
1504 DECL_INITIAL (value) = NULL_TREE;
1508 constant_expression_warning (width);
1509 DECL_INITIAL (value) = width;
1510 DECL_BIT_FIELD (value) = 1;
1514 DECL_IN_AGGR_P (value) = 1;
1519 /* Like GROKFIELD, except that the declarator has been
1520 buried in DECLSPECS. Find the declarator, and
1521 return something that looks like it came from
1524 groktypefield (declspecs, parmlist)
1528 tree spec = declspecs;
1529 tree prev = NULL_TREE;
1531 tree type_id = NULL_TREE;
1532 tree quals = NULL_TREE;
1533 tree lengths = NULL_TREE;
1534 tree decl = NULL_TREE;
1538 register tree id = TREE_VALUE (spec);
1540 if (TREE_CODE (spec) != TREE_LIST)
1541 /* Certain parse errors slip through. For example,
1542 `int class ();' is not caught by the parser. Try
1543 weakly to recover here. */
1546 if (TREE_CODE (id) == TYPE_DECL
1547 || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
1549 /* We have a constructor/destructor or
1550 conversion operator. Use it. */
1552 TREE_CHAIN (prev) = TREE_CHAIN (spec);
1554 declspecs = TREE_CHAIN (spec);
1560 spec = TREE_CHAIN (spec);
1563 /* Nope, we have a conversion operator to a scalar type or something
1564 else, that includes things like constructor declarations for
1569 tree id = TREE_VALUE (spec);
1571 if (TREE_CODE (id) == IDENTIFIER_NODE)
1573 if (id == ridpointers[(int)RID_INT]
1574 || id == ridpointers[(int)RID_DOUBLE]
1575 || id == ridpointers[(int)RID_FLOAT]
1576 || id == ridpointers[(int)RID_WCHAR])
1579 error ("extra `%s' ignored",
1580 IDENTIFIER_POINTER (id));
1584 else if (id == ridpointers[(int)RID_LONG]
1585 || id == ridpointers[(int)RID_SHORT]
1586 || id == ridpointers[(int)RID_CHAR])
1588 lengths = tree_cons (NULL_TREE, id, lengths);
1590 else if (id == ridpointers[(int)RID_VOID])
1593 error ("spurious `void' type ignored");
1595 error ("conversion to `void' type invalid");
1597 else if (id == ridpointers[(int)RID_AUTO]
1598 || id == ridpointers[(int)RID_REGISTER]
1599 || id == ridpointers[(int)RID_TYPEDEF]
1600 || id == ridpointers[(int)RID_CONST]
1601 || id == ridpointers[(int)RID_VOLATILE])
1603 error ("type specifier `%s' used invalidly",
1604 IDENTIFIER_POINTER (id));
1606 else if (id == ridpointers[(int)RID_FRIEND]
1607 || id == ridpointers[(int)RID_VIRTUAL]
1608 || id == ridpointers[(int)RID_INLINE]
1609 || id == ridpointers[(int)RID_UNSIGNED]
1610 || id == ridpointers[(int)RID_SIGNED]
1611 || id == ridpointers[(int)RID_STATIC]
1612 || id == ridpointers[(int)RID_EXTERN])
1614 quals = tree_cons (NULL_TREE, id, quals);
1618 /* Happens when we have a global typedef
1619 and a class-local member function with
1625 else if (TREE_CODE (id) == RECORD_TYPE)
1627 type_id = TYPE_NAME (id);
1628 if (TREE_CODE (type_id) == TYPE_DECL)
1629 type_id = DECL_NAME (type_id);
1630 if (type_id == NULL_TREE)
1631 error ("identifier for aggregate type conversion omitted");
1633 else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't')
1634 error ("`operator' missing on conversion operator or tag missing from type");
1636 my_friendly_abort (194);
1637 spec = TREE_CHAIN (spec);
1641 declspecs = chainon (lengths, quals);
1644 if (TREE_CHAIN (lengths))
1645 error ("multiple length specifiers");
1646 type_id = ridpointers[(int)RID_INT];
1647 declspecs = chainon (lengths, quals);
1651 error ("no type given, defaulting to `operator int ...'");
1652 type_id = ridpointers[(int)RID_INT];
1659 decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
1660 declspecs, FIELD, 0, NULL_TREE);
1661 if (decl == NULL_TREE)
1664 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
1666 /* Need a fresh node here so that we don't get circularity
1667 when we link these together. */
1668 decl = copy_node (decl);
1671 if (decl == void_type_node
1672 || (TREE_CODE (decl) == FUNCTION_DECL
1673 && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
1674 /* bunch of friends. */
1677 if (DECL_IN_AGGR_P (decl))
1679 cp_error ("`%D' already defined in the class ", decl);
1680 return void_type_node;
1683 finish_decl (decl, NULL_TREE, NULL_TREE, 0, 0);
1685 /* If this declaration is common to another declaration
1686 complain about such redundancy, and return NULL_TREE
1687 so that we don't build a circular list. */
1688 if (DECL_CHAIN (decl))
1690 cp_error ("function `%D' declared twice in class %T", decl,
1691 DECL_CONTEXT (decl));
1694 DECL_IN_AGGR_P (decl) = 1;
1700 grokoptypename (declspecs, declarator)
1701 tree declspecs, declarator;
1703 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1704 return build_typename_overload (t);
1707 /* When a function is declared with an initializer,
1708 do the right thing. Currently, there are two possibilities:
1713 // initialization possibility #1.
1714 virtual void f () = 0;
1736 // initialization possibility #2
1743 copy_assignment_arg_p (parmtype, virtualp)
1747 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1748 parmtype = TREE_TYPE (parmtype);
1750 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1751 || (virtualp && DERIVED_FROM_P (parmtype, current_class_type)))
1758 grok_function_init (decl, init)
1762 /* An initializer for a function tells how this function should
1764 tree type = TREE_TYPE (decl);
1766 if (TREE_CODE (type) == FUNCTION_TYPE)
1767 cp_error ("initializer specified for non-member function `%D'", decl);
1768 else if (DECL_VINDEX (decl) == NULL_TREE)
1769 cp_error ("initializer specified for non-virtual method `%D'", decl);
1770 else if (integer_zerop (init))
1773 /* Mark this function as being "defined". */
1774 DECL_INITIAL (decl) = error_mark_node;
1775 /* pure virtual destructors must be defined. */
1776 /* pure virtual needs to be defined (as abort) only when put in
1777 vtbl. For wellformed call, it should be itself. pr4737 */
1778 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1780 extern tree abort_fndecl;
1781 /* Give this node rtl from `abort'. */
1782 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1785 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1786 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1789 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1791 if (copy_assignment_arg_p (parmtype, 1))
1792 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1795 else if (TREE_CODE (init) == OFFSET_REF
1796 && TREE_OPERAND (init, 0) == NULL_TREE
1797 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1799 tree basetype = DECL_CLASS_CONTEXT (init);
1800 tree basefn = TREE_OPERAND (init, 1);
1801 if (TREE_CODE (basefn) != FUNCTION_DECL)
1802 cp_error ("non-method initializer invalid for method `%D'", decl);
1803 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1804 sorry ("base member function from other than first base class");
1807 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1808 if (binfo == error_mark_node)
1810 else if (binfo == 0)
1811 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1812 TYPE_METHOD_BASETYPE (type));
1815 /* Mark this function as being defined,
1816 and give it new rtl. */
1817 DECL_INITIAL (decl) = error_mark_node;
1818 DECL_RTL (decl) = DECL_RTL (basefn);
1823 cp_error ("invalid initializer for virtual method `%D'", decl);
1826 /* When we get a declaration of the form
1828 type cname::fname ...
1830 the node for `cname::fname' gets built here in a special way.
1831 Namely, we push into `cname's scope. When this declaration is
1832 processed, we pop back out. */
1834 build_push_scope (cname, name)
1838 extern int current_class_depth;
1842 if (cname == error_mark_node)
1843 return error_mark_node;
1845 ctype = IDENTIFIER_TYPE_VALUE (cname);
1847 if (TREE_CODE (ctype) == TEMPLATE_TYPE_PARM)
1849 else if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
1851 cp_error ("`%T' not defined as aggregate type", cname);
1854 else if (IS_SIGNATURE (ctype))
1856 error ("cannot push into signature scope, scope resolution operator ignored");
1860 rval = build_parse_node (SCOPE_REF, cname, name);
1862 /* Don't need to push the scope if we're already in it.
1863 We also don't need to push the scope for a ptr-to-member/method. */
1865 if (ctype == current_class_type || TREE_CODE (name) != IDENTIFIER_NODE
1869 /* We do need to push the scope in this case, since CTYPE helps
1870 determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;). */
1872 push_nested_class (ctype, 3);
1873 TREE_COMPLEXITY (rval) = current_class_depth;
1877 void cplus_decl_attributes (decl, attributes)
1878 tree decl, attributes;
1880 if (decl && decl != void_type_node)
1881 decl_attributes (decl, attributes);
1884 /* CONSTRUCTOR_NAME:
1885 Return the name for the constructor (or destructor) for the
1886 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1887 IDENTIFIER_NODE. When given a template, this routine doesn't
1888 lose the specialization. */
1890 constructor_name_full (thing)
1893 if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
1894 return DECL_NAME (UPT_TEMPLATE (thing));
1895 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1897 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1898 thing = DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing), 0));
1900 thing = TYPE_NAME (thing);
1902 if (TREE_CODE (thing) == TYPE_DECL
1903 || (TREE_CODE (thing) == TEMPLATE_DECL
1904 && DECL_TEMPLATE_IS_CLASS (thing)))
1905 thing = DECL_NAME (thing);
1906 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1910 /* CONSTRUCTOR_NAME:
1911 Return the name for the constructor (or destructor) for the
1912 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1913 IDENTIFIER_NODE. When given a template, return the plain
1914 unspecialized name. */
1916 constructor_name (thing)
1920 thing = constructor_name_full (thing);
1921 t = IDENTIFIER_TEMPLATE (thing);
1924 t = TREE_PURPOSE (t);
1925 return DECL_NAME (t);
1928 /* Cache the value of this class's main virtual function table pointer
1929 in a register variable. This will save one indirection if a
1930 more than one virtual function call is made this function. */
1934 extern rtx base_init_insns;
1936 if (base_init_insns == 0
1937 && DECL_CONSTRUCTOR_P (current_function_decl))
1938 emit_base_init (current_class_type, 0);
1941 /* This has something a little wrong with it.
1943 On a sun4, code like:
1948 is generated, when the below is used when -O4 is given. The delay
1949 slot it filled with an instruction that is safe, when this isn't
1959 virtual void print() { printf("xxx"); }
1971 And that is why this is disabled for now. (mrs)
1974 if ((flag_this_is_variable & 1) == 0
1976 && current_class_type
1977 && CLASSTYPE_VSIZE (current_class_type)
1978 && ! DECL_STATIC_FUNCTION_P (current_function_decl))
1980 tree vfield = build_vfield_ref (C_C_D, current_class_type);
1981 current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
1982 DECL_RTL (current_vtable_decl) = 0;
1983 DECL_INITIAL (current_vtable_decl) = error_mark_node;
1984 /* Have to cast the initializer, since it may have come from a
1985 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
1986 finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield, 0), NULL_TREE, 0, 0);
1987 current_vtable_decl = build_indirect_ref (current_vtable_decl, NULL_PTR);
1991 current_vtable_decl = NULL_TREE;
1994 /* Record the existence of an addressable inline function. */
1996 mark_inline_for_output (decl)
1999 decl = DECL_MAIN_VARIANT (decl);
2000 if (DECL_SAVED_INLINE (decl))
2002 my_friendly_assert (TREE_PERMANENT (decl), 363);
2003 DECL_SAVED_INLINE (decl) = 1;
2004 if (DECL_PENDING_INLINE_INFO (decl) != 0
2005 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
2007 struct pending_inline *t = pending_inlines;
2008 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
2011 if (t == DECL_PENDING_INLINE_INFO (decl))
2017 t = DECL_PENDING_INLINE_INFO (decl);
2018 t->next = pending_inlines;
2019 pending_inlines = t;
2021 DECL_PENDING_INLINE_INFO (decl) = 0;
2023 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
2029 temp_name_counter = 0;
2032 /* Hand off a unique name which can be used for variable we don't really
2033 want to know about anyway, for example, the anonymous variables which
2034 are needed to make references work. Declare this thing so we can use it.
2035 The variable created will be of type TYPE.
2037 STATICP is nonzero if this variable should be static. */
2040 get_temp_name (type, staticp)
2044 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
2046 int toplev = global_bindings_p ();
2048 push_obstacks_nochange ();
2049 if (toplev || staticp)
2051 end_temporary_allocation ();
2052 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
2053 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
2057 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
2058 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
2060 TREE_USED (decl) = 1;
2061 TREE_STATIC (decl) = staticp;
2063 /* If this is a local variable, then lay out its rtl now.
2064 Otherwise, callers of this function are responsible for dealing
2065 with this variable's rtl. */
2069 expand_decl_init (decl);
2076 /* Get a variable which we can use for multiple assignments.
2077 It is not entered into current_binding_level, because
2078 that breaks things when it comes time to do final cleanups
2079 (which take place "outside" the binding contour of the function). */
2081 get_temp_regvar (type, init)
2084 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
2087 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
2088 decl = build_decl (VAR_DECL, get_identifier (buf), type);
2089 TREE_USED (decl) = 1;
2090 DECL_REGISTER (decl) = 1;
2093 store_init_value (decl, init);
2095 /* We can expand these without fear, since they cannot need
2096 constructors or destructors. */
2098 expand_decl_init (decl);
2100 if (type_needs_gc_entry (type))
2101 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
2106 /* Make the macro TEMP_NAME_P available to units which do not
2107 include c-tree.h. */
2112 return TEMP_NAME_P (decl);
2115 /* Finish off the processing of a UNION_TYPE structure.
2116 If there are static members, then all members are
2117 static, and must be laid out together. If the
2118 union is an anonymous union, we arrange for that
2119 as well. PUBLIC_P is nonzero if this union is
2120 not declared static. */
2122 finish_anon_union (anon_union_decl)
2123 tree anon_union_decl;
2125 tree type = TREE_TYPE (anon_union_decl);
2126 tree field, main_decl = NULL_TREE;
2127 tree elems = NULL_TREE;
2128 int public_p = TREE_PUBLIC (anon_union_decl);
2129 int static_p = TREE_STATIC (anon_union_decl);
2130 int external_p = DECL_EXTERNAL (anon_union_decl);
2132 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
2137 error ("global anonymous unions must be declared static");
2141 for (; field; field = TREE_CHAIN (field))
2144 if (TREE_CODE (field) != FIELD_DECL)
2147 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2148 /* tell `pushdecl' that this is not tentative. */
2149 DECL_INITIAL (decl) = error_mark_node;
2150 TREE_PUBLIC (decl) = public_p;
2151 TREE_STATIC (decl) = static_p;
2152 DECL_EXTERNAL (decl) = external_p;
2153 decl = pushdecl (decl);
2155 /* Only write out one anon union element--choose the one that
2156 can hold them all. */
2157 if (main_decl == NULL_TREE
2158 && simple_cst_equal (DECL_SIZE (decl), DECL_SIZE (anon_union_decl)))
2164 /* ??? This causes there to be no debug info written out
2166 TREE_ASM_WRITTEN (decl) = 1;
2169 DECL_INITIAL (decl) = NULL_TREE;
2170 /* If there's a cleanup to do, it belongs in the
2171 TREE_PURPOSE of the following TREE_LIST. */
2172 elems = tree_cons (NULL_TREE, decl, elems);
2173 TREE_TYPE (elems) = type;
2179 make_decl_rtl (main_decl, 0, global_bindings_p ());
2180 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2184 warning ("anonymous union with no members");
2189 /* The following call assumes that there are never any cleanups
2190 for anonymous unions--a reasonable assumption. */
2191 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2194 cadillac_finish_anon_union (anon_union_decl);
2197 /* Finish and output a table which is generated by the compiler.
2198 NAME is the name to give the table.
2199 TYPE is the type of the table entry.
2200 INIT is all the elements in the table.
2201 PUBLICP is non-zero if this table should be given external access. */
2203 finish_table (name, type, init, publicp)
2204 tree name, type, init;
2207 tree itype, atype, decl;
2208 static tree empty_table;
2212 itype = build_index_type (size_int (list_length (init) - 1));
2213 atype = build_cplus_array_type (type, itype);
2214 layout_type (atype);
2216 if (TREE_VALUE (init) == integer_zero_node
2217 && TREE_CHAIN (init) == NULL_TREE)
2220 if (empty_table == NULL_TREE)
2223 empty_table = get_temp_name (atype, 1);
2224 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2225 TREE_CONSTANT (init) = 1;
2226 TREE_STATIC (init) = 1;
2227 DECL_INITIAL (empty_table) = init;
2228 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2229 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2230 finish_decl (empty_table, init, asmspec, 0, 0);
2235 if (name == NULL_TREE)
2239 decl = get_temp_name (atype, 1);
2243 decl = build_decl (VAR_DECL, name, atype);
2244 decl = pushdecl (decl);
2245 TREE_STATIC (decl) = 1;
2250 TREE_PUBLIC (decl) = publicp;
2251 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2252 TREE_CONSTANT (init) = 1;
2253 TREE_STATIC (init) = 1;
2254 DECL_INITIAL (decl) = init;
2255 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2256 IDENTIFIER_POINTER (DECL_NAME (decl)));
2260 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2261 DECL_EXTERNAL (decl) = 1;
2262 TREE_STATIC (decl) = 0;
2264 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2265 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2268 finish_decl (decl, init, asmspec, 0, 0);
2272 /* Finish processing a builtin type TYPE. It's name is NAME,
2273 its fields are in the array FIELDS. LEN is the number of elements
2274 in FIELDS minus one, or put another way, it is the maximum subscript
2277 It is given the same alignment as ALIGN_TYPE. */
2279 finish_builtin_type (type, name, fields, len, align_type)
2288 TYPE_FIELDS (type) = fields[0];
2289 for (i = 0; i < len; i++)
2291 layout_type (TREE_TYPE (fields[i]));
2292 DECL_FIELD_CONTEXT (fields[i]) = type;
2293 TREE_CHAIN (fields[i]) = fields[i+1];
2295 DECL_FIELD_CONTEXT (fields[i]) = type;
2296 DECL_CLASS_CONTEXT (fields[i]) = type;
2297 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2299 #if 0 /* not yet, should get fixed properly later */
2300 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2302 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2304 layout_decl (TYPE_NAME (type), 0);
2307 /* Auxiliary functions to make type signatures for
2308 `operator new' and `operator delete' correspond to
2309 what compiler will be expecting. */
2311 extern tree sizetype;
2314 coerce_new_type (type)
2319 if (TREE_CODE (type) == METHOD_TYPE)
2320 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2321 if (TREE_TYPE (type) != ptr_type_node)
2322 e1 = 1, error ("`operator new' must return type `void *'");
2324 /* Technically the type must be `size_t', but we may not know
2326 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2327 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2328 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2329 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2330 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2332 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2334 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2339 coerce_delete_type (type)
2342 int e1 = 0, e2 = 0, e3 = 0;
2343 tree arg_types = TYPE_ARG_TYPES (type);
2345 if (TREE_CODE (type) == METHOD_TYPE)
2347 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2348 arg_types = TREE_CHAIN (arg_types);
2350 if (TREE_TYPE (type) != void_type_node)
2351 e1 = 1, error ("`operator delete' must return type `void'");
2352 if (arg_types == NULL_TREE
2353 || TREE_VALUE (arg_types) != ptr_type_node)
2354 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2357 && TREE_CHAIN (arg_types)
2358 && TREE_CHAIN (arg_types) != void_list_node)
2360 /* Again, technically this argument must be `size_t', but again
2361 we may not know what that is. */
2362 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2363 if (TREE_CODE (t2) != INTEGER_TYPE
2364 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2365 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2366 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2369 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2370 error ("too many arguments in declaration of `operator delete'");
2372 error ("`...' invalid in specification of `operator delete'");
2376 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
2379 if (arg_types == NULL_TREE)
2380 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2382 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2387 type = build_function_type (void_type_node, arg_types);
2393 mark_vtable_entries (decl)
2396 tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
2398 for (; entries; entries = TREE_CHAIN (entries))
2400 tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
2401 tree fn = TREE_OPERAND (fnaddr, 0);
2402 TREE_ADDRESSABLE (fn) = 1;
2403 if (DECL_ABSTRACT_VIRTUAL_P (fn))
2405 extern tree abort_fndecl;
2406 if (flag_vtable_thunks)
2407 fnaddr = TREE_VALUE (entries);
2408 TREE_OPERAND (fnaddr, 0) = abort_fndecl;
2413 /* Set TREE_PUBLIC and/or TREE_EXTERN on the vtable DECL,
2414 based on TYPE and other static flags.
2416 Note that anything public is tagged TREE_PUBLIC, whether
2417 it's public in this file or in another one. */
2420 import_export_vtable (decl, type)
2423 if (write_virtuals >= 2
2424 || CLASSTYPE_TEMPLATE_INSTANTIATION (type))
2426 if (CLASSTYPE_INTERFACE_KNOWN (type))
2428 TREE_PUBLIC (decl) = 1;
2429 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2432 else if (write_virtuals != 0)
2434 TREE_PUBLIC (decl) = 1;
2435 if (write_virtuals < 0)
2436 DECL_EXTERNAL (decl) = 1;
2441 import_export_template (type)
2444 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2445 && ! flag_implicit_templates
2446 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2448 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2449 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2450 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2455 finish_vtable_vardecl (prev, vars)
2458 tree ctype = DECL_CONTEXT (vars);
2459 import_export_template (ctype);
2460 import_export_vtable (vars, ctype);
2462 if (flag_vtable_thunks && !CLASSTYPE_INTERFACE_KNOWN (ctype))
2465 for (method = CLASSTYPE_METHODS (ctype); method != NULL_TREE;
2466 method = DECL_NEXT_METHOD (method))
2468 if (DECL_VINDEX (method) != NULL_TREE && !DECL_SAVED_INSNS (method)
2469 && !DECL_ABSTRACT_VIRTUAL_P (method))
2471 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2472 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2473 TREE_PUBLIC (vars) = 1;
2474 DECL_EXTERNAL (vars) = DECL_EXTERNAL (method);
2480 if (write_virtuals >= 0
2481 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
2483 extern tree the_null_vtable_entry;
2485 /* Stuff this virtual function table's size into
2486 `pfn' slot of `the_null_vtable_entry'. */
2488 /* we do not put size as first entry any more */
2489 tree nelts = array_type_nelts (TREE_TYPE (vars));
2490 if (flag_vtable_thunks)
2491 TREE_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))) = nelts;
2493 SET_FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry, nelts);
2496 /* Kick out the type descriptor before writing out the vtable. */
2498 rest_of_decl_compilation (TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (vars)))), 0), 0, 1, 1);
2501 mark_vtable_entries (vars);
2502 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2503 store_init_value (vars, DECL_INITIAL (vars));
2505 #ifdef DWARF_DEBUGGING_INFO
2506 if (write_symbols == DWARF_DEBUG)
2508 /* Mark the VAR_DECL node representing the vtable itself as a
2509 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2510 It is rather important that such things be ignored because
2511 any effort to actually generate DWARF for them will run
2512 into trouble when/if we encounter code like:
2515 struct S { virtual void member (); };
2517 because the artificial declaration of the vtable itself (as
2518 manufactured by the g++ front end) will say that the vtable
2519 is a static member of `S' but only *after* the debug output
2520 for the definition of `S' has already been output. This causes
2521 grief because the DWARF entry for the definition of the vtable
2522 will try to refer back to an earlier *declaration* of the
2523 vtable as a static member of `S' and there won't be one.
2524 We might be able to arrange to have the "vtable static member"
2525 attached to the member list for `S' before the debug info for
2526 `S' get written (which would solve the problem) but that would
2527 require more intrusive changes to the g++ front end. */
2529 DECL_IGNORED_P (vars) = 1;
2531 #endif /* DWARF_DEBUGGING_INFO */
2533 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2535 else if (TREE_USED (vars) && flag_vtable_thunks)
2536 assemble_external (vars);
2537 /* We know that PREV must be non-zero here. */
2538 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2542 walk_vtables (typedecl_fn, vardecl_fn)
2543 register void (*typedecl_fn)();
2544 register void (*vardecl_fn)();
2548 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2550 register tree type = TREE_TYPE (vars);
2552 if (TREE_CODE (vars) == TYPE_DECL
2553 && type != error_mark_node
2554 && TYPE_LANG_SPECIFIC (type)
2555 && CLASSTYPE_VSIZE (type))
2557 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2559 else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2561 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2569 finish_sigtable_vardecl (prev, vars)
2572 /* We don't need to mark sigtable entries as addressable here as is done
2573 for vtables. Since sigtables, unlike vtables, are always written out,
2574 that was already done in build_signature_table_constructor. */
2576 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2578 /* We know that PREV must be non-zero here. */
2579 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2583 walk_sigtables (typedecl_fn, vardecl_fn)
2584 register void (*typedecl_fn)();
2585 register void (*vardecl_fn)();
2589 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2591 register tree type = TREE_TYPE (vars);
2593 if (TREE_CODE (vars) == TYPE_DECL
2594 && type != error_mark_node
2595 && IS_SIGNATURE (type))
2597 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2599 else if (TREE_CODE (vars) == VAR_DECL
2600 && TREE_TYPE (vars) != error_mark_node
2601 && IS_SIGNATURE (TREE_TYPE (vars)))
2603 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2610 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2611 inline function at end-of-file. */
2614 import_export_inline (decl)
2617 if (DECL_INTERFACE_KNOWN (decl))
2620 if (DECL_TEMPLATE_INSTANTIATION (decl))
2622 if (DECL_IMPLICIT_INSTANTIATION (decl) && flag_implicit_templates)
2623 TREE_PUBLIC (decl) = 0;
2625 DECL_EXTERNAL (decl) = 1;
2627 else if (DECL_FUNCTION_MEMBER_P (decl))
2629 tree ctype = DECL_CLASS_CONTEXT (decl);
2630 if (CLASSTYPE_INTERFACE_KNOWN (ctype))
2632 DECL_EXTERNAL (decl)
2633 = (CLASSTYPE_INTERFACE_ONLY (ctype)
2634 || (DECL_INLINE (decl) && ! flag_implement_inlines));
2637 TREE_PUBLIC (decl) = 0;
2640 TREE_PUBLIC (decl) = 0;
2643 extern int parse_time, varconst_time;
2645 #define TIMEVAR(VAR, BODY) \
2646 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2648 /* This routine is called from the last rule in yyparse ().
2649 Its job is to create all the code needed to initialize and
2650 destroy the global aggregates. We do the destruction
2651 first, since that way we only need to reverse the decls once. */
2657 int start_time, this_time;
2660 tree vars = static_aggregates;
2661 int needs_cleaning = 0, needs_messing_up = 0;
2662 int have_exception_handlers = build_exception_table ();
2664 if (flag_detailed_statistics)
2665 dump_tree_statistics ();
2667 /* Bad parse errors. Just forget about it. */
2668 if (! global_bindings_p () || current_class_type)
2671 start_time = get_run_time ();
2673 /* Push into C language context, because that's all
2675 push_lang_context (lang_name_c);
2677 /* Set up the name of the file-level functions we may need. */
2678 /* Use a global object (which is already required to be unique over
2679 the program) rather than the file name (which imposes extra
2680 constraints). -- Raeburn@MIT.EDU, 10 Jan 1990. */
2682 /* See if we really need the hassle. */
2683 while (vars && needs_cleaning == 0)
2685 tree decl = TREE_VALUE (vars);
2686 tree type = TREE_TYPE (decl);
2687 if (TYPE_NEEDS_DESTRUCTOR (type))
2690 needs_messing_up = 1;
2694 needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
2695 vars = TREE_CHAIN (vars);
2697 if (needs_cleaning == 0)
2700 /* Otherwise, GDB can get confused, because in only knows
2701 about source for LINENO-1 lines. */
2704 fnname = get_file_function_name ('D');
2705 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2706 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2707 store_parm_decls ();
2712 expand_start_bindings (0);
2714 /* These must be done in backward order to destroy,
2715 in which they happen to be! */
2718 tree decl = TREE_VALUE (vars);
2719 tree type = TREE_TYPE (decl);
2720 tree temp = TREE_PURPOSE (vars);
2722 if (TYPE_NEEDS_DESTRUCTOR (type))
2724 if (TREE_STATIC (vars))
2725 expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node, 1), 0);
2726 if (TREE_CODE (type) == ARRAY_TYPE)
2730 mark_addressable (decl);
2731 temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
2733 temp = build_delete (TREE_TYPE (temp), temp,
2734 integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2735 expand_expr_stmt (temp);
2737 if (TREE_STATIC (vars))
2740 vars = TREE_CHAIN (vars);
2743 expand_end_bindings (getdecls(), 1, 0);
2747 finish_function (lineno, 0, 0);
2749 assemble_destructor (IDENTIFIER_POINTER (fnname));
2751 /* if it needed cleaning, then it will need messing up: drop through */
2754 /* Must do this while we think we are at the top level. */
2755 vars = nreverse (static_aggregates);
2756 if (vars != NULL_TREE || have_exception_handlers)
2758 fnname = get_file_function_name ('I');
2759 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2760 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2761 store_parm_decls ();
2766 expand_start_bindings (0);
2768 if (have_exception_handlers)
2769 register_exception_table ();
2773 tree decl = TREE_VALUE (vars);
2774 tree init = TREE_PURPOSE (vars);
2775 tree old_cleanups = cleanups_this_call;
2777 /* If this was a static attribute within some function's scope,
2778 then don't initialize it here. Also, don't bother
2779 with initializers that contain errors. */
2780 if (TREE_STATIC (vars)
2781 || (init && TREE_CODE (init) == TREE_LIST
2782 && value_member (error_mark_node, init)))
2784 vars = TREE_CHAIN (vars);
2788 if (TREE_CODE (decl) == VAR_DECL)
2790 /* Set these global variables so that GDB at least puts
2791 us near the declaration which required the initialization. */
2792 input_filename = DECL_SOURCE_FILE (decl);
2793 lineno = DECL_SOURCE_LINE (decl);
2794 emit_note (input_filename, lineno);
2796 /* 9.5p5: The initializer of a static member of a class has
2797 the same acess rights as a member function. */
2798 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2802 if (TREE_CODE (init) == VAR_DECL)
2804 /* This behavior results when there are
2805 multiple declarations of an aggregate,
2806 the last of which defines it. */
2807 if (DECL_RTL (init) == DECL_RTL (decl))
2809 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node
2810 || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
2811 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE),
2813 init = DECL_INITIAL (init);
2814 if (TREE_CODE (init) == CONSTRUCTOR
2815 && CONSTRUCTOR_ELTS (init) == NULL_TREE)
2819 else if (TREE_TYPE (decl) == TREE_TYPE (init))
2822 my_friendly_abort (200);
2824 /* point to real decl's rtl anyway. */
2825 DECL_RTL (init) = DECL_RTL (decl);
2826 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node,
2828 init = DECL_INITIAL (init);
2834 if (IS_AGGR_TYPE (TREE_TYPE (decl))
2835 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2836 expand_aggr_init (decl, init, 0, 0);
2837 else if (TREE_CODE (init) == TREE_VEC)
2839 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2840 TREE_VEC_ELT (init, 1),
2841 TREE_VEC_ELT (init, 2), 0),
2842 const0_rtx, VOIDmode, 0);
2846 expand_assignment (decl, init, 0, 0);
2848 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2850 else if (TREE_CODE (decl) == SAVE_EXPR)
2852 if (! PARM_DECL_EXPR (decl))
2854 /* a `new' expression at top level. */
2855 expand_expr (decl, const0_rtx, VOIDmode, 0);
2857 expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0, 0);
2860 else if (decl == error_mark_node)
2862 else my_friendly_abort (22);
2863 vars = TREE_CHAIN (vars);
2864 /* Cleanup any temporaries needed for the initial value. */
2865 expand_cleanups_to (old_cleanups);
2868 expand_end_bindings (getdecls(), 1, 0);
2872 finish_function (lineno, 0, 0);
2873 assemble_constructor (IDENTIFIER_POINTER (fnname));
2876 /* Done with C language context needs. */
2877 pop_lang_context ();
2879 /* Now write out any static class variables (which may have since
2880 learned how to be initialized). */
2881 while (pending_statics)
2883 tree decl = TREE_VALUE (pending_statics);
2884 if (TREE_USED (decl) == 1
2885 || TREE_READONLY (decl) == 0
2886 || DECL_INITIAL (decl) == 0)
2887 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
2888 pending_statics = TREE_CHAIN (pending_statics);
2891 this_time = get_run_time ();
2892 parse_time -= this_time - start_time;
2893 varconst_time += this_time - start_time;
2895 start_time = get_run_time ();
2897 /* Now delete from the chain of variables all virtual function tables.
2898 We output them all ourselves, because each will be treated specially. */
2901 /* The reason for pushing garbage onto the global_binding_level is to
2902 ensure that we can slice out _DECLs which pertain to virtual function
2903 tables. If the last thing pushed onto the global_binding_level was a
2904 virtual function table, then slicing it out would slice away all the
2905 decls (i.e., we lose the head of the chain).
2907 There are several ways of getting the same effect, from changing the
2908 way that iterators over the chain treat the elements that pertain to
2909 virtual function tables, moving the implementation of this code to
2910 decl.c (where we can manipulate global_binding_level directly),
2911 popping the garbage after pushing it and slicing away the vtable
2912 stuff, or just leaving it alone. */
2914 /* Make last thing in global scope not be a virtual function table. */
2915 #if 0 /* not yet, should get fixed properly later */
2916 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2918 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2920 DECL_IGNORED_P (vars) = 1;
2921 SET_DECL_ARTIFICIAL (vars);
2925 interface_unknown = 1;
2928 for (vars = saved_inlines; vars; vars = TREE_CHAIN (vars))
2930 tree decl = TREE_VALUE (vars);
2932 if (DECL_ARTIFICIAL (decl)
2933 && ! DECL_INITIAL (decl)
2934 && (TREE_USED (decl) || ! DECL_EXTERNAL (decl)))
2935 synthesize_method (decl);
2938 walk_vtables ((void (*)())0, finish_vtable_vardecl);
2939 if (flag_handle_signatures)
2940 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
2942 for (vars = saved_inlines; vars; vars = TREE_CHAIN (vars))
2944 tree decl = TREE_VALUE (vars);
2946 if (DECL_ARTIFICIAL (decl)
2947 && ! DECL_INITIAL (decl)
2948 && TREE_USED (decl))
2949 synthesize_method (decl);
2952 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2954 if (TREE_CODE (vars) == THUNK_DECL)
2956 else if (TREE_CODE (vars) == FUNCTION_DECL
2957 && ! DECL_INTERFACE_KNOWN (vars)
2958 && DECL_DECLARED_STATIC (vars))
2959 TREE_PUBLIC (vars) = 0;
2962 /* Now write out inline functions which had their addresses taken and
2963 which were not declared virtual and which were not declared `extern
2966 int reconsider = 1; /* More may be referenced; check again */
2967 saved_inlines = tree_cons (NULL_TREE, NULL_TREE, saved_inlines);
2971 tree last = saved_inlines;
2972 tree place = TREE_CHAIN (saved_inlines);
2975 for (; place; place = TREE_CHAIN (place))
2977 tree decl = TREE_VALUE (place);
2979 if (TREE_ASM_WRITTEN (decl) || DECL_SAVED_INSNS (decl) == 0)
2981 TREE_CHAIN (last) = TREE_CHAIN (place);
2984 import_export_inline (decl);
2985 if (TREE_PUBLIC (decl)
2986 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2987 || flag_keep_inline_functions)
2989 TREE_CHAIN (last) = TREE_CHAIN (place);
2991 if (DECL_EXTERNAL (decl))
2992 assemble_external (decl);
2996 temporary_allocation ();
2997 output_inline_function (decl);
2998 permanent_allocation (1);
3009 if (write_virtuals == 2)
3011 /* Now complain about an virtual function tables promised
3012 but not delivered. */
3013 while (pending_vtables)
3015 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3016 error ("virtual function table for `%s' not defined",
3017 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3018 pending_vtables = TREE_CHAIN (pending_vtables);
3022 permanent_allocation (1);
3023 this_time = get_run_time ();
3024 parse_time -= this_time - start_time;
3025 varconst_time += this_time - start_time;
3027 if (flag_detailed_statistics)
3028 dump_time_statistics ();
3031 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3032 expr. Since it was parsed like a type, we need to wade through and fix
3033 that. Unfortunately, since operator() is left-associative, we can't use
3034 tail recursion. In the above example, TYPE is `A', and DECL is
3037 Maybe this shouldn't be recursive, but how often will it actually be
3040 reparse_absdcl_as_expr (type, decl)
3043 /* do build_functional_cast (type, NULL_TREE) at bottom */
3044 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3045 return build_functional_cast (type, NULL_TREE);
3048 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3050 decl = build_x_function_call (decl, NULL_TREE, current_class_decl);
3052 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3053 decl = require_complete_type (decl);
3058 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3059 out to be an expr. Since it was parsed like a type, we need to wade
3060 through and fix that. Since casts are right-associative, we are
3061 reversing the order, so we don't have to recurse.
3063 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3066 reparse_absdcl_as_casts (decl, expr)
3071 if (TREE_CODE (expr) == CONSTRUCTOR)
3073 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3074 decl = TREE_OPERAND (decl, 0);
3076 if (IS_SIGNATURE (type))
3078 error ("cast specifies signature type");
3079 return error_mark_node;
3082 expr = digest_init (type, expr, (tree *) 0);
3083 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3085 int failure = complete_array_type (type, expr, 1);
3087 my_friendly_abort (78);
3093 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3094 decl = TREE_OPERAND (decl, 0);
3095 expr = build_c_cast (type, expr, 0);
3101 /* Recursive helper function for reparse_decl_as_expr. It may be a good
3102 idea to reimplement this using an explicit stack, rather than recursion. */
3104 reparse_decl_as_expr1 (decl)
3107 switch (TREE_CODE (decl))
3109 case IDENTIFIER_NODE:
3110 return do_identifier (decl);
3112 return build_x_indirect_ref
3113 (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)), "unary *");
3115 return build_x_unary_op (ADDR_EXPR,
3116 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3118 return build_x_unary_op (BIT_NOT_EXPR,
3119 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3121 return build_offset_ref (TREE_OPERAND (decl, 0), TREE_OPERAND (decl, 1));
3123 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)),
3124 TREE_OPERAND (decl, 1));
3126 my_friendly_abort (5);
3131 /* This is something of the form `int (*a)++' that has turned out to be an
3132 expr. It was only converted into parse nodes, so we need to go through
3133 and build up the semantics. Most of the work is done by
3134 reparse_decl_as_expr1, above.
3136 In the above example, TYPE is `int' and DECL is `*a'. */
3138 reparse_decl_as_expr (type, decl)
3141 decl = build_tree_list (NULL_TREE, reparse_decl_as_expr1 (decl));
3142 return build_functional_cast (type, decl);
3145 /* This is something of the form `int (*a)' that has turned out to be a
3146 decl. It was only converted into parse nodes, so we need to do the
3147 checking that make_{pointer,reference}_declarator do. */
3150 finish_decl_parsing (decl)
3153 extern int current_class_depth;
3155 switch (TREE_CODE (decl))
3157 case IDENTIFIER_NODE:
3160 return make_pointer_declarator
3161 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3163 return make_reference_declarator
3164 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3166 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3169 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3170 TREE_COMPLEXITY (decl) = current_class_depth;
3173 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3176 my_friendly_abort (5);
3182 check_cp_case_value (value)
3185 if (value == NULL_TREE)
3188 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3189 Strip such NOP_EXPRs. */
3190 if (TREE_CODE (value) == NOP_EXPR
3191 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3192 value = TREE_OPERAND (value, 0);
3194 if (TREE_READONLY_DECL_P (value))
3196 value = decl_constant_value (value);
3197 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3198 Strip such NOP_EXPRs. */
3199 if (TREE_CODE (value) == NOP_EXPR
3200 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3201 value = TREE_OPERAND (value, 0);
3203 value = fold (value);
3205 if (TREE_CODE (value) != INTEGER_CST
3206 && value != error_mark_node)
3208 cp_error ("case label `%E' does not reduce to an integer constant",
3210 value = error_mark_node;
3213 /* Promote char or short to int. */
3214 value = default_conversion (value);
3216 constant_expression_warning (value);
3221 static tree current_namespace;
3223 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3224 postfix. Returns 0 if in global namespace. */
3228 tree x = current_namespace;
3230 x = TREE_PURPOSE (x);
3234 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3236 current_namespace_id (name)
3239 tree old_id = get_namespace_id ();
3242 /* Global names retain old encoding. */
3246 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3247 + IDENTIFIER_LENGTH (name));
3248 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3249 IDENTIFIER_POINTER (name));
3250 return get_identifier (buf);
3253 /* Push into the scopre of the NAME namespace. */
3255 push_namespace (name)
3258 tree old_id = get_namespace_id ();
3261 current_namespace = tree_cons (NULL_TREE, name, current_namespace);
3262 buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0)
3263 + IDENTIFIER_LENGTH (name));
3264 sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "",
3265 IDENTIFIER_POINTER (name));
3266 TREE_PURPOSE (current_namespace) = get_identifier (buf);
3269 /* Pop from the scope of the current namespace. */
3273 current_namespace = TREE_CHAIN (current_namespace);
3277 do_namespace_alias (alias, namespace)
3278 tree alias, namespace;
3283 do_using_decl (decl)
3286 return error_mark_node;
3290 do_using_directive (namespace)