]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Process declarations and variables for C compiler. |
357a4089 | 2 | Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc. |
8d08fdba MS |
3 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
21 | |
22 | ||
23 | /* Process declarations and symbol lookup for C front end. | |
24 | Also constructs types; the standard scalar types at initialization, | |
25 | and structure, union, array and enum types when they are declared. */ | |
26 | ||
27 | /* ??? not all decl nodes are given the most useful possible | |
28 | line numbers. For example, the CONST_DECLs for enum values. */ | |
29 | ||
30 | #include "config.h" | |
31 | #include <stdio.h> | |
32 | #include "tree.h" | |
33 | #include "rtl.h" | |
34 | #include "flags.h" | |
35 | #include "cp-tree.h" | |
36 | #include "decl.h" | |
37 | #include "lex.h" | |
e8abc66f | 38 | #include "output.h" |
49c249e1 | 39 | #include "except.h" |
9f617717 | 40 | #include "expr.h" |
eb773359 | 41 | #include "defaults.h" |
49c249e1 JM |
42 | |
43 | #ifdef HAVE_STDLIB_H | |
44 | #include <stdlib.h> | |
45 | #endif | |
46 | ||
47 | #ifdef HAVE_STRING_H | |
48 | #include <string.h> | |
49 | #endif | |
50 | ||
51 | static tree get_sentry PROTO((tree)); | |
52 | static void mark_vtable_entries PROTO((tree)); | |
53 | static void import_export_template PROTO((tree)); | |
6b5fbb55 | 54 | static void grok_function_init PROTO((tree, tree)); |
49c249e1 JM |
55 | static int finish_vtable_vardecl PROTO((tree, tree)); |
56 | static int prune_vtable_vardecl PROTO((tree, tree)); | |
57 | static void finish_sigtable_vardecl PROTO((tree, tree)); | |
58 | ||
cffa8729 | 59 | extern int current_class_depth; |
8d08fdba MS |
60 | |
61 | /* A list of virtual function tables we must make sure to write out. */ | |
62 | tree pending_vtables; | |
63 | ||
64 | /* A list of static class variables. This is needed, because a | |
65 | static class variable can be declared inside the class without | |
66 | an initializer, and then initialized, staticly, outside the class. */ | |
67 | tree pending_statics; | |
68 | ||
8926095f | 69 | /* A list of functions which were declared inline, but which we |
e92cc029 | 70 | may need to emit outline anyway. */ |
8926095f | 71 | static tree saved_inlines; |
8d08fdba MS |
72 | |
73 | /* Used to help generate temporary names which are unique within | |
74 | a function. Reset to 0 by start_function. */ | |
75 | ||
7215f9a0 | 76 | int temp_name_counter; |
8d08fdba MS |
77 | |
78 | /* Same, but not reset. Local temp variables and global temp variables | |
79 | can have the same name. */ | |
80 | static int global_temp_name_counter; | |
81 | ||
51c184be | 82 | /* Flag used when debugging spew.c */ |
8d08fdba MS |
83 | |
84 | extern int spew_debug; | |
e1cd6e56 | 85 | |
5566b478 MS |
86 | /* Nonzero if we're done parsing and into end-of-file activities. */ |
87 | ||
88 | int at_eof; | |
89 | ||
e1cd6e56 MS |
90 | /* Functions called along with real static constructors and destructors. */ |
91 | ||
92 | tree static_ctors, static_dtors; | |
8d08fdba MS |
93 | \f |
94 | /* C (and C++) language-specific option variables. */ | |
95 | ||
96 | /* Nonzero means allow type mismatches in conditional expressions; | |
97 | just make their values `void'. */ | |
98 | ||
99 | int flag_cond_mismatch; | |
100 | ||
101 | /* Nonzero means give `double' the same size as `float'. */ | |
102 | ||
103 | int flag_short_double; | |
104 | ||
105 | /* Nonzero means don't recognize the keyword `asm'. */ | |
106 | ||
107 | int flag_no_asm; | |
108 | ||
e1cd6e56 MS |
109 | /* Nonzero means don't recognize any extension keywords. */ |
110 | ||
111 | int flag_no_gnu_keywords; | |
112 | ||
8d08fdba MS |
113 | /* Nonzero means don't recognize the non-ANSI builtin functions. */ |
114 | ||
115 | int flag_no_builtin; | |
116 | ||
00595019 MS |
117 | /* Nonzero means don't recognize the non-ANSI builtin functions. |
118 | -ansi sets this. */ | |
119 | ||
120 | int flag_no_nonansi_builtin; | |
121 | ||
d22c8596 MS |
122 | /* Nonzero means do some things the same way PCC does. Only provided so |
123 | the compiler will link. */ | |
8d08fdba MS |
124 | |
125 | int flag_traditional; | |
126 | ||
127 | /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */ | |
128 | ||
129 | int flag_signed_bitfields = 1; | |
130 | ||
131 | /* Nonzero means handle `#ident' directives. 0 means ignore them. */ | |
132 | ||
e1cd6e56 | 133 | int flag_no_ident; |
8d08fdba | 134 | |
e1cd6e56 MS |
135 | /* Nonzero means enable obscure ANSI features and disable GNU extensions |
136 | that might cause ANSI-compliant code to be miscompiled. */ | |
8d08fdba | 137 | |
e1cd6e56 | 138 | int flag_ansi; |
8d08fdba | 139 | |
c73964b2 MS |
140 | /* Nonzero means do argument matching for overloading according to the |
141 | ANSI rules, rather than what g++ used to believe to be correct. */ | |
142 | ||
c73964b2 | 143 | int flag_ansi_overloading = 1; |
c73964b2 | 144 | |
8d08fdba MS |
145 | /* Nonzero means do emit exported implementations of functions even if |
146 | they can be inlined. */ | |
147 | ||
148 | int flag_implement_inlines = 1; | |
149 | ||
150 | /* Nonzero means do emit exported implementations of templates, instead of | |
e92cc029 | 151 | multiple static copies in each file that needs a definition. */ |
8d08fdba | 152 | |
e1cd6e56 | 153 | int flag_external_templates; |
8d08fdba MS |
154 | |
155 | /* Nonzero means that the decision to emit or not emit the implementation of a | |
156 | template depends on where the template is instantiated, rather than where | |
157 | it is defined. */ | |
158 | ||
e1cd6e56 | 159 | int flag_alt_external_templates; |
8d08fdba | 160 | |
a0a33927 MS |
161 | /* Nonzero means that implicit instantiations will be emitted if needed. */ |
162 | ||
163 | int flag_implicit_templates = 1; | |
164 | ||
8d08fdba MS |
165 | /* Nonzero means warn about implicit declarations. */ |
166 | ||
167 | int warn_implicit = 1; | |
168 | ||
169 | /* Nonzero means warn when all ctors or dtors are private, and the class | |
170 | has no friends. */ | |
171 | ||
172 | int warn_ctor_dtor_privacy = 1; | |
173 | ||
a80e4195 | 174 | /* True if we want to implement vtables using "thunks". |
6467930b | 175 | The default is off. */ |
8926095f | 176 | |
da20811c JM |
177 | #ifndef DEFAULT_VTABLE_THUNKS |
178 | #define DEFAULT_VTABLE_THUNKS 0 | |
c73964b2 | 179 | #endif |
da20811c | 180 | int flag_vtable_thunks = DEFAULT_VTABLE_THUNKS; |
51c184be | 181 | |
faae18ab MS |
182 | /* True if we want to deal with repository information. */ |
183 | ||
184 | int flag_use_repository; | |
185 | ||
8d08fdba MS |
186 | /* Nonzero means give string constants the type `const char *' |
187 | to get extra warnings from them. These warnings will be too numerous | |
188 | to be useful, except in thoroughly ANSIfied programs. */ | |
189 | ||
190 | int warn_write_strings; | |
191 | ||
192 | /* Nonzero means warn about pointer casts that can drop a type qualifier | |
193 | from the pointer target type. */ | |
194 | ||
195 | int warn_cast_qual; | |
196 | ||
197 | /* Nonzero means warn that dbx info for template class methods isn't fully | |
198 | supported yet. */ | |
199 | ||
200 | int warn_template_debugging; | |
201 | ||
8d08fdba MS |
202 | /* Nonzero means warn about sizeof(function) or addition/subtraction |
203 | of function pointers. */ | |
204 | ||
be99da77 | 205 | int warn_pointer_arith = 1; |
8d08fdba | 206 | |
8d08fdba MS |
207 | /* Nonzero means warn for any function def without prototype decl. */ |
208 | ||
209 | int warn_missing_prototypes; | |
210 | ||
211 | /* Nonzero means warn about multiple (redundant) decls for the same single | |
212 | variable or function. */ | |
213 | ||
214 | int warn_redundant_decls; | |
215 | ||
216 | /* Warn if initializer is not completely bracketed. */ | |
217 | ||
218 | int warn_missing_braces; | |
219 | ||
2ee887f2 MS |
220 | /* Warn about comparison of signed and unsigned values. */ |
221 | ||
222 | int warn_sign_compare; | |
223 | ||
e92cc029 | 224 | /* Warn about *printf or *scanf format/argument anomalies. */ |
8d08fdba MS |
225 | |
226 | int warn_format; | |
227 | ||
228 | /* Warn about a subscript that has type char. */ | |
229 | ||
230 | int warn_char_subscripts; | |
231 | ||
232 | /* Warn if a type conversion is done that might have confusing results. */ | |
233 | ||
234 | int warn_conversion; | |
235 | ||
236 | /* Warn if adding () is suggested. */ | |
237 | ||
e1cd6e56 | 238 | int warn_parentheses; |
8d08fdba MS |
239 | |
240 | /* Non-zero means warn in function declared in derived class has the | |
241 | same name as a virtual in the base class, but fails to match the | |
242 | type signature of any virtual function in the base class. */ | |
243 | int warn_overloaded_virtual; | |
244 | ||
245 | /* Non-zero means warn when declaring a class that has a non virtual | |
e92cc029 | 246 | destructor, when it really ought to have a virtual one. */ |
9a0e77ba | 247 | int warn_nonvdtor; |
8d08fdba MS |
248 | |
249 | /* Non-zero means warn when a function is declared extern and later inline. */ | |
250 | int warn_extern_inline; | |
251 | ||
f376e137 MS |
252 | /* Non-zero means warn when the compiler will reorder code. */ |
253 | int warn_reorder; | |
254 | ||
ddd5a7c1 | 255 | /* Non-zero means warn when synthesis behavior differs from Cfront's. */ |
f376e137 MS |
256 | int warn_synth; |
257 | ||
9a3b49ac MS |
258 | /* Non-zero means warn when we convert a pointer to member function |
259 | into a pointer to (void or function). */ | |
260 | int warn_pmf2ptr = 1; | |
261 | ||
eb448459 MS |
262 | /* Nonzero means warn about violation of some Effective C++ style rules. */ |
263 | ||
da20811c JM |
264 | int warn_ecpp; |
265 | ||
266 | /* Nonzero means warn where overload resolution chooses a promotion from | |
267 | unsigned to signed over a conversion to an unsigned of the same size. */ | |
268 | ||
269 | int warn_sign_promo; | |
eb448459 | 270 | |
0c4b14c4 JM |
271 | /* Nonzero means warn when an old-style cast is used. */ |
272 | ||
273 | int warn_old_style_cast; | |
274 | ||
f9fc59e8 NC |
275 | /* Warn about #pragma directives that are not recognised. */ |
276 | ||
277 | int warn_unknown_pragmas = 0; /* Tri state variable. */ | |
278 | ||
4f6140be | 279 | /* Nonzero means `$' can be in an identifier. */ |
8d08fdba MS |
280 | |
281 | #ifndef DOLLARS_IN_IDENTIFIERS | |
282 | #define DOLLARS_IN_IDENTIFIERS 1 | |
283 | #endif | |
284 | int dollars_in_ident = DOLLARS_IN_IDENTIFIERS; | |
285 | ||
a3203465 | 286 | /* Nonzero for -fno-strict-prototype switch: do not consider empty |
8d08fdba MS |
287 | argument prototype to mean function takes no arguments. */ |
288 | ||
e1cd6e56 | 289 | int flag_strict_prototype = 2; |
8d08fdba MS |
290 | int strict_prototype = 1; |
291 | int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1; | |
292 | ||
293 | /* Nonzero means that labels can be used as first-class objects */ | |
294 | ||
295 | int flag_labels_ok; | |
296 | ||
297 | /* Non-zero means to collect statistics which might be expensive | |
298 | and to print them when we are done. */ | |
299 | int flag_detailed_statistics; | |
300 | ||
301 | /* C++ specific flags. */ | |
302 | /* Nonzero for -fall-virtual: make every member function (except | |
303 | constructors) lay down in the virtual function table. Calls | |
304 | can then either go through the virtual function table or not, | |
305 | depending. */ | |
306 | ||
307 | int flag_all_virtual; | |
308 | ||
309 | /* Zero means that `this' is a *const. This gives nice behavior in the | |
310 | 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior. | |
311 | -2 means we're constructing an object and it has fixed type. */ | |
312 | ||
313 | int flag_this_is_variable; | |
314 | ||
315 | /* Nonzero means memoize our member lookups. */ | |
316 | ||
317 | int flag_memoize_lookups; int flag_save_memoized_contexts; | |
318 | ||
319 | /* 3 means write out only virtuals function tables `defined' | |
320 | in this implementation file. | |
321 | 2 means write out only specific virtual function tables | |
322 | and give them (C) public access. | |
323 | 1 means write out virtual function tables and give them | |
324 | (C) public access. | |
325 | 0 means write out virtual function tables and give them | |
326 | (C) static access (default). | |
327 | -1 means declare virtual function tables extern. */ | |
328 | ||
329 | int write_virtuals; | |
330 | ||
c1bc6829 JM |
331 | /* Nonzero means we should attempt to elide constructors when possible. |
332 | FIXME: This flag is obsolete, and should be torn out along with the | |
333 | old overloading code. */ | |
8d08fdba MS |
334 | |
335 | int flag_elide_constructors; | |
336 | ||
8d08fdba MS |
337 | /* Nonzero means recognize and handle signature language constructs. */ |
338 | ||
339 | int flag_handle_signatures; | |
340 | ||
341 | /* Nonzero means that member functions defined in class scope are | |
342 | inline by default. */ | |
343 | ||
344 | int flag_default_inline = 1; | |
345 | ||
346 | /* Controls whether enums and ints freely convert. | |
347 | 1 means with complete freedom. | |
348 | 0 means enums can convert to ints, but not vice-versa. */ | |
349 | int flag_int_enum_equivalence; | |
350 | ||
db5ae43f | 351 | /* Controls whether compiler generates 'type descriptor' that give |
8d08fdba | 352 | run-time type information. */ |
6b5fbb55 | 353 | int flag_rtti = 1; |
8d08fdba MS |
354 | |
355 | /* Nonzero if we wish to output cross-referencing information | |
356 | for the GNU class browser. */ | |
357 | extern int flag_gnu_xref; | |
358 | ||
359 | /* Nonzero if compiler can make `reasonable' assumptions about | |
360 | references and objects. For example, the compiler must be | |
361 | conservative about the following and not assume that `a' is nonnull: | |
362 | ||
363 | obj &a = g (); | |
364 | a.f (2); | |
365 | ||
366 | In general, it is `reasonable' to assume that for many programs, | |
367 | and better code can be generated in that case. */ | |
368 | ||
e1cd6e56 | 369 | int flag_assume_nonnull_objects = 1; |
8d08fdba MS |
370 | |
371 | /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) | |
e92cc029 | 372 | objects. */ |
e1cd6e56 | 373 | |
8d08fdba MS |
374 | int flag_huge_objects; |
375 | ||
376 | /* Nonzero if we want to conserve space in the .o files. We do this | |
377 | by putting uninitialized data and runtime initialized data into | |
ddd5a7c1 | 378 | .common instead of .data at the expense of not flagging multiple |
8d08fdba | 379 | definitions. */ |
e1cd6e56 | 380 | |
8d08fdba MS |
381 | int flag_conserve_space; |
382 | ||
eae89e04 | 383 | /* Nonzero if we want to obey access control semantics. */ |
e1cd6e56 | 384 | |
eae89e04 JM |
385 | int flag_access_control = 1; |
386 | ||
e1cd6e56 MS |
387 | /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */ |
388 | ||
389 | int flag_operator_names; | |
390 | ||
d18c083e MS |
391 | /* Nonzero if we want to check the return value of new and avoid calling |
392 | constructors if it is a null pointer. */ | |
393 | ||
394 | int flag_check_new; | |
395 | ||
863adfc0 | 396 | /* Nonzero if we want the new ANSI rules for pushing a new scope for `for' |
57c0c9ca PB |
397 | initialization variables. |
398 | 0: Old rules, set by -fno-for-scope. | |
399 | 2: New ANSI rules, set by -ffor-scope. | |
abc95ed3 | 400 | 1: Try to implement new ANSI rules, but with backup compatibility |
57c0c9ca | 401 | (and warnings). This is the default, for now. */ |
863adfc0 MS |
402 | |
403 | int flag_new_for_scope = 1; | |
404 | ||
72b7eeff MS |
405 | /* Nonzero if we want to emit defined symbols with common-like linkage as |
406 | weak symbols where possible, in order to conform to C++ semantics. | |
407 | Otherwise, emit them as local symbols. */ | |
408 | ||
409 | int flag_weak = 1; | |
410 | ||
e9f32eb5 MS |
411 | /* Maximum template instantiation depth. Must be at least 17 for ANSI |
412 | compliance. */ | |
413 | ||
414 | int max_tinst_depth = 17; | |
415 | ||
386b8a85 JM |
416 | /* The name-mangling scheme to use. Must be 1 or greater to support |
417 | template functions with identical types, but different template | |
418 | arguments. */ | |
419 | int name_mangling_version = 1; | |
420 | ||
421 | /* Nonzero means that guiding declarations are allowed. */ | |
422 | int flag_guiding_decls; | |
423 | ||
8d08fdba MS |
424 | /* Table of language-dependent -f options. |
425 | STRING is the option name. VARIABLE is the address of the variable. | |
426 | ON_VALUE is the value to store in VARIABLE | |
427 | if `-fSTRING' is seen as an option. | |
428 | (If `-fno-STRING' is seen as an option, the opposite value is stored.) */ | |
429 | ||
430 | static struct { char *string; int *variable; int on_value;} lang_f_options[] = | |
431 | { | |
432 | {"signed-char", &flag_signed_char, 1}, | |
433 | {"unsigned-char", &flag_signed_char, 0}, | |
434 | {"signed-bitfields", &flag_signed_bitfields, 1}, | |
435 | {"unsigned-bitfields", &flag_signed_bitfields, 0}, | |
436 | {"short-enums", &flag_short_enums, 1}, | |
437 | {"short-double", &flag_short_double, 1}, | |
438 | {"cond-mismatch", &flag_cond_mismatch, 1}, | |
439 | {"asm", &flag_no_asm, 0}, | |
440 | {"builtin", &flag_no_builtin, 0}, | |
441 | {"ident", &flag_no_ident, 0}, | |
442 | {"labels-ok", &flag_labels_ok, 1}, | |
443 | {"stats", &flag_detailed_statistics, 1}, | |
444 | {"this-is-variable", &flag_this_is_variable, 1}, | |
e1cd6e56 | 445 | {"strict-prototype", &flag_strict_prototype, 1}, |
8d08fdba MS |
446 | {"all-virtual", &flag_all_virtual, 1}, |
447 | {"memoize-lookups", &flag_memoize_lookups, 1}, | |
448 | {"elide-constructors", &flag_elide_constructors, 1}, | |
da20811c | 449 | {"handle-exceptions", &flag_exceptions, 1}, |
8d08fdba | 450 | {"handle-signatures", &flag_handle_signatures, 1}, |
8d08fdba MS |
451 | {"default-inline", &flag_default_inline, 1}, |
452 | {"dollars-in-identifiers", &dollars_in_ident, 1}, | |
453 | {"enum-int-equiv", &flag_int_enum_equivalence, 1}, | |
db5ae43f | 454 | {"rtti", &flag_rtti, 1}, |
8d08fdba MS |
455 | {"xref", &flag_gnu_xref, 1}, |
456 | {"nonnull-objects", &flag_assume_nonnull_objects, 1}, | |
457 | {"implement-inlines", &flag_implement_inlines, 1}, | |
458 | {"external-templates", &flag_external_templates, 1}, | |
a0a33927 | 459 | {"implicit-templates", &flag_implicit_templates, 1}, |
c73964b2 | 460 | {"ansi-overloading", &flag_ansi_overloading, 1}, |
8d08fdba MS |
461 | {"huge-objects", &flag_huge_objects, 1}, |
462 | {"conserve-space", &flag_conserve_space, 1}, | |
8926095f | 463 | {"vtable-thunks", &flag_vtable_thunks, 1}, |
eae89e04 | 464 | {"access-control", &flag_access_control, 1}, |
e1cd6e56 MS |
465 | {"nonansi-builtins", &flag_no_nonansi_builtin, 0}, |
466 | {"gnu-keywords", &flag_no_gnu_keywords, 0}, | |
d18c083e | 467 | {"operator-names", &flag_operator_names, 1}, |
faae18ab | 468 | {"check-new", &flag_check_new, 1}, |
863adfc0 | 469 | {"repo", &flag_use_repository, 1}, |
72b7eeff MS |
470 | {"for-scope", &flag_new_for_scope, 2}, |
471 | {"weak", &flag_weak, 1} | |
8d08fdba MS |
472 | }; |
473 | ||
474 | /* Decode the string P as a language-specific option. | |
475 | Return 1 if it is recognized (and handle it); | |
476 | return 0 if not recognized. */ | |
477 | ||
478 | int | |
479 | lang_decode_option (p) | |
480 | char *p; | |
481 | { | |
482 | if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) | |
4f6140be | 483 | flag_writable_strings = 1, |
863adfc0 | 484 | flag_this_is_variable = 1, flag_new_for_scope = 0; |
8d08fdba MS |
485 | /* The +e options are for cfront compatibility. They come in as |
486 | `-+eN', to kludge around gcc.c's argument handling. */ | |
487 | else if (p[0] == '-' && p[1] == '+' && p[2] == 'e') | |
488 | { | |
489 | int old_write_virtuals = write_virtuals; | |
490 | if (p[3] == '1') | |
491 | write_virtuals = 1; | |
492 | else if (p[3] == '0') | |
493 | write_virtuals = -1; | |
494 | else if (p[3] == '2') | |
495 | write_virtuals = 2; | |
496 | else error ("invalid +e option"); | |
497 | if (old_write_virtuals != 0 | |
498 | && write_virtuals != old_write_virtuals) | |
499 | error ("conflicting +e options given"); | |
500 | } | |
501 | else if (p[0] == '-' && p[1] == 'f') | |
502 | { | |
503 | /* Some kind of -f option. | |
504 | P's value is the option sans `-f'. | |
505 | Search for it in the table of options. */ | |
506 | int found = 0, j; | |
507 | ||
508 | p += 2; | |
509 | /* Try special -f options. */ | |
510 | ||
da20811c JM |
511 | if (!strcmp (p, "handle-exceptions") |
512 | || !strcmp (p, "no-handle-exceptions")) | |
513 | warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)"); | |
514 | ||
8d08fdba MS |
515 | if (!strcmp (p, "save-memoized")) |
516 | { | |
517 | flag_memoize_lookups = 1; | |
518 | flag_save_memoized_contexts = 1; | |
519 | found = 1; | |
520 | } | |
da20811c | 521 | else if (!strcmp (p, "no-save-memoized")) |
8d08fdba MS |
522 | { |
523 | flag_memoize_lookups = 0; | |
524 | flag_save_memoized_contexts = 0; | |
525 | found = 1; | |
526 | } | |
8d08fdba MS |
527 | else if (! strcmp (p, "alt-external-templates")) |
528 | { | |
529 | flag_external_templates = 1; | |
530 | flag_alt_external_templates = 1; | |
531 | found = 1; | |
532 | } | |
533 | else if (! strcmp (p, "no-alt-external-templates")) | |
534 | { | |
535 | flag_alt_external_templates = 0; | |
536 | found = 1; | |
537 | } | |
79ff2c6c MS |
538 | else if (!strcmp (p, "repo")) |
539 | { | |
540 | flag_use_repository = 1; | |
541 | flag_implicit_templates = 0; | |
542 | found = 1; | |
00595019 | 543 | } |
386b8a85 JM |
544 | else if (!strcmp (p, "guiding-decls")) |
545 | { | |
546 | flag_guiding_decls = 1; | |
547 | name_mangling_version = 0; | |
548 | found = 1; | |
549 | } | |
550 | else if (!strcmp (p, "no-guiding-decls")) | |
551 | { | |
552 | flag_guiding_decls = 0; | |
553 | found = 1; | |
554 | } | |
e9f32eb5 MS |
555 | else if (!strncmp (p, "template-depth-", 15)) |
556 | { | |
557 | char *endp = p + 15; | |
558 | while (*endp) | |
559 | { | |
560 | if (*endp >= '0' && *endp <= '9') | |
561 | endp++; | |
562 | else | |
563 | { | |
564 | error ("Invalid option `%s'", p - 2); | |
565 | goto template_depth_lose; | |
566 | } | |
567 | } | |
568 | max_tinst_depth = atoi (p + 15); | |
569 | template_depth_lose: ; | |
570 | } | |
386b8a85 JM |
571 | else if (!strncmp (p, "name-mangling-version-", 22)) |
572 | { | |
573 | char *endp = p + 22; | |
574 | while (*endp) | |
575 | { | |
576 | if (*endp >= '0' && *endp <= '9') | |
577 | endp++; | |
578 | else | |
579 | { | |
580 | error ("Invalid option `%s'", p - 2); | |
581 | goto mangling_version_lose; | |
582 | } | |
583 | } | |
584 | name_mangling_version = atoi (p + 22); | |
893de33c | 585 | mangling_version_lose: ; |
386b8a85 | 586 | } |
8d08fdba MS |
587 | else for (j = 0; |
588 | !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]); | |
589 | j++) | |
590 | { | |
591 | if (!strcmp (p, lang_f_options[j].string)) | |
592 | { | |
593 | *lang_f_options[j].variable = lang_f_options[j].on_value; | |
594 | /* A goto here would be cleaner, | |
595 | but breaks the vax pcc. */ | |
596 | found = 1; | |
597 | } | |
598 | if (p[0] == 'n' && p[1] == 'o' && p[2] == '-' | |
599 | && ! strcmp (p+3, lang_f_options[j].string)) | |
600 | { | |
601 | *lang_f_options[j].variable = ! lang_f_options[j].on_value; | |
602 | found = 1; | |
603 | } | |
604 | } | |
605 | return found; | |
606 | } | |
607 | else if (p[0] == '-' && p[1] == 'W') | |
608 | { | |
609 | int setting = 1; | |
610 | ||
611 | /* The -W options control the warning behavior of the compiler. */ | |
612 | p += 2; | |
613 | ||
614 | if (p[0] == 'n' && p[1] == 'o' && p[2] == '-') | |
615 | setting = 0, p += 3; | |
616 | ||
617 | if (!strcmp (p, "implicit")) | |
618 | warn_implicit = setting; | |
619 | else if (!strcmp (p, "return-type")) | |
620 | warn_return_type = setting; | |
621 | else if (!strcmp (p, "ctor-dtor-privacy")) | |
622 | warn_ctor_dtor_privacy = setting; | |
623 | else if (!strcmp (p, "write-strings")) | |
624 | warn_write_strings = setting; | |
625 | else if (!strcmp (p, "cast-qual")) | |
626 | warn_cast_qual = setting; | |
8d08fdba MS |
627 | else if (!strcmp (p, "char-subscripts")) |
628 | warn_char_subscripts = setting; | |
629 | else if (!strcmp (p, "pointer-arith")) | |
630 | warn_pointer_arith = setting; | |
8d08fdba MS |
631 | else if (!strcmp (p, "missing-prototypes")) |
632 | warn_missing_prototypes = setting; | |
633 | else if (!strcmp (p, "redundant-decls")) | |
634 | warn_redundant_decls = setting; | |
635 | else if (!strcmp (p, "missing-braces")) | |
636 | warn_missing_braces = setting; | |
2ee887f2 MS |
637 | else if (!strcmp (p, "sign-compare")) |
638 | warn_sign_compare = setting; | |
8d08fdba MS |
639 | else if (!strcmp (p, "format")) |
640 | warn_format = setting; | |
641 | else if (!strcmp (p, "conversion")) | |
642 | warn_conversion = setting; | |
643 | else if (!strcmp (p, "parentheses")) | |
644 | warn_parentheses = setting; | |
21474714 MS |
645 | else if (!strcmp (p, "non-virtual-dtor")) |
646 | warn_nonvdtor = setting; | |
8d08fdba MS |
647 | else if (!strcmp (p, "extern-inline")) |
648 | warn_extern_inline = setting; | |
f376e137 MS |
649 | else if (!strcmp (p, "reorder")) |
650 | warn_reorder = setting; | |
651 | else if (!strcmp (p, "synth")) | |
652 | warn_synth = setting; | |
9a3b49ac MS |
653 | else if (!strcmp (p, "pmf-conversions")) |
654 | warn_pmf2ptr = setting; | |
eb448459 MS |
655 | else if (!strcmp (p, "effc++")) |
656 | warn_ecpp = setting; | |
da20811c JM |
657 | else if (!strcmp (p, "sign-promo")) |
658 | warn_sign_promo = setting; | |
0c4b14c4 JM |
659 | else if (!strcmp (p, "old-style-cast")) |
660 | warn_old_style_cast = setting; | |
f9fc59e8 NC |
661 | else if (!strcmp (p, "unknown-pragmas")) |
662 | /* Set to greater than 1, so that even unknown pragmas in | |
663 | system headers will be warned about. */ | |
664 | warn_unknown_pragmas = setting * 2; | |
8d08fdba MS |
665 | else if (!strcmp (p, "comment")) |
666 | ; /* cpp handles this one. */ | |
667 | else if (!strcmp (p, "comments")) | |
668 | ; /* cpp handles this one. */ | |
669 | else if (!strcmp (p, "trigraphs")) | |
670 | ; /* cpp handles this one. */ | |
671 | else if (!strcmp (p, "import")) | |
672 | ; /* cpp handles this one. */ | |
673 | else if (!strcmp (p, "all")) | |
674 | { | |
8d08fdba MS |
675 | warn_return_type = setting; |
676 | warn_unused = setting; | |
677 | warn_implicit = setting; | |
678 | warn_ctor_dtor_privacy = setting; | |
679 | warn_switch = setting; | |
680 | warn_format = setting; | |
e1cd6e56 | 681 | warn_parentheses = setting; |
8d08fdba | 682 | warn_missing_braces = setting; |
2ee887f2 | 683 | warn_sign_compare = setting; |
8d08fdba | 684 | warn_extern_inline = setting; |
9a0e77ba | 685 | warn_nonvdtor = setting; |
8d08fdba MS |
686 | /* We save the value of warn_uninitialized, since if they put |
687 | -Wuninitialized on the command line, we need to generate a | |
688 | warning about not using it without also specifying -O. */ | |
689 | if (warn_uninitialized != 1) | |
690 | warn_uninitialized = (setting ? 2 : 0); | |
691 | warn_template_debugging = setting; | |
f376e137 | 692 | warn_reorder = setting; |
da20811c | 693 | warn_sign_promo = setting; |
f9fc59e8 NC |
694 | /* Only warn about unknown pragmas that are not in system |
695 | headers. */ | |
696 | warn_unknown_pragmas = 1; | |
8d08fdba MS |
697 | } |
698 | ||
699 | else if (!strcmp (p, "overloaded-virtual")) | |
700 | warn_overloaded_virtual = setting; | |
701 | else return 0; | |
702 | } | |
703 | else if (!strcmp (p, "-ansi")) | |
4f6140be | 704 | flag_no_nonansi_builtin = 1, flag_ansi = 1, |
e1cd6e56 | 705 | flag_no_gnu_keywords = 1, flag_operator_names = 1; |
8d08fdba MS |
706 | #ifdef SPEW_DEBUG |
707 | /* Undocumented, only ever used when you're invoking cc1plus by hand, since | |
708 | it's probably safe to assume no sane person would ever want to use this | |
709 | under normal circumstances. */ | |
710 | else if (!strcmp (p, "-spew-debug")) | |
711 | spew_debug = 1; | |
712 | #endif | |
713 | else | |
714 | return 0; | |
715 | ||
716 | return 1; | |
717 | } | |
718 | \f | |
719 | /* Incorporate `const' and `volatile' qualifiers for member functions. | |
720 | FUNCTION is a TYPE_DECL or a FUNCTION_DECL. | |
721 | QUALS is a list of qualifiers. */ | |
e92cc029 | 722 | |
8d08fdba MS |
723 | tree |
724 | grok_method_quals (ctype, function, quals) | |
725 | tree ctype, function, quals; | |
726 | { | |
727 | tree fntype = TREE_TYPE (function); | |
728 | tree raises = TYPE_RAISES_EXCEPTIONS (fntype); | |
729 | ||
730 | do | |
731 | { | |
732 | extern tree ridpointers[]; | |
733 | ||
734 | if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST]) | |
735 | { | |
736 | if (TYPE_READONLY (ctype)) | |
737 | error ("duplicate `%s' %s", | |
738 | IDENTIFIER_POINTER (TREE_VALUE (quals)), | |
739 | (TREE_CODE (function) == FUNCTION_DECL | |
740 | ? "for member function" : "in type declaration")); | |
741 | ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype)); | |
742 | build_pointer_type (ctype); | |
743 | } | |
744 | else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE]) | |
745 | { | |
746 | if (TYPE_VOLATILE (ctype)) | |
747 | error ("duplicate `%s' %s", | |
748 | IDENTIFIER_POINTER (TREE_VALUE (quals)), | |
749 | (TREE_CODE (function) == FUNCTION_DECL | |
750 | ? "for member function" : "in type declaration")); | |
751 | ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1); | |
752 | build_pointer_type (ctype); | |
753 | } | |
754 | else | |
755 | my_friendly_abort (20); | |
756 | quals = TREE_CHAIN (quals); | |
757 | } | |
758 | while (quals); | |
759 | fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype), | |
760 | (TREE_CODE (fntype) == METHOD_TYPE | |
761 | ? TREE_CHAIN (TYPE_ARG_TYPES (fntype)) | |
762 | : TYPE_ARG_TYPES (fntype))); | |
763 | if (raises) | |
f30432d7 | 764 | fntype = build_exception_variant (fntype, raises); |
8d08fdba MS |
765 | |
766 | TREE_TYPE (function) = fntype; | |
767 | return ctype; | |
768 | } | |
769 | ||
e92cc029 | 770 | #if 0 /* Not used. */ |
8d08fdba MS |
771 | /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs. |
772 | It leaves DECL_ASSEMBLER_NAMEs with the correct value. */ | |
773 | /* This does not yet work with user defined conversion operators | |
774 | It should. */ | |
e92cc029 | 775 | |
8d08fdba MS |
776 | static void |
777 | substitute_nice_name (decl) | |
778 | tree decl; | |
779 | { | |
780 | if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) | |
781 | { | |
782 | char *n = decl_as_string (DECL_NAME (decl), 1); | |
783 | if (n[strlen (n) - 1] == ' ') | |
784 | n[strlen (n) - 1] = 0; | |
785 | DECL_NAME (decl) = get_identifier (n); | |
786 | } | |
787 | } | |
8926095f | 788 | #endif |
8d08fdba MS |
789 | |
790 | /* Warn when -fexternal-templates is used and #pragma | |
791 | interface/implementation is not used all the times it should be, | |
792 | inform the user. */ | |
e92cc029 | 793 | |
8d08fdba | 794 | void |
8ccc31eb MS |
795 | warn_if_unknown_interface (decl) |
796 | tree decl; | |
8d08fdba MS |
797 | { |
798 | static int already_warned = 0; | |
8ccc31eb MS |
799 | if (already_warned++) |
800 | return; | |
801 | ||
802 | if (flag_alt_external_templates) | |
803 | { | |
804 | struct tinst_level *til = tinst_for_decl (); | |
805 | int sl = lineno; | |
806 | char *sf = input_filename; | |
807 | ||
f30432d7 MS |
808 | if (til) |
809 | { | |
810 | lineno = til->line; | |
811 | input_filename = til->file; | |
812 | } | |
8ccc31eb MS |
813 | cp_warning ("template `%#D' instantiated in file without #pragma interface", |
814 | decl); | |
815 | lineno = sl; | |
816 | input_filename = sf; | |
817 | } | |
818 | else | |
819 | cp_warning_at ("template `%#D' defined in file without #pragma interface", | |
820 | decl); | |
8d08fdba MS |
821 | } |
822 | ||
823 | /* A subroutine of the parser, to handle a component list. */ | |
e92cc029 | 824 | |
8d08fdba MS |
825 | tree |
826 | grok_x_components (specs, components) | |
827 | tree specs, components; | |
828 | { | |
829 | register tree t, x, tcode; | |
830 | ||
831 | /* We just got some friends. They have been recorded elsewhere. */ | |
832 | if (components == void_type_node) | |
833 | return NULL_TREE; | |
834 | ||
835 | if (components == NULL_TREE) | |
836 | { | |
837 | t = groktypename (build_decl_list (specs, NULL_TREE)); | |
838 | ||
839 | if (t == NULL_TREE) | |
840 | { | |
841 | error ("error in component specification"); | |
842 | return NULL_TREE; | |
843 | } | |
844 | ||
845 | switch (TREE_CODE (t)) | |
846 | { | |
847 | case VAR_DECL: | |
848 | /* Static anonymous unions come out as VAR_DECLs. */ | |
849 | if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE | |
850 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t)))) | |
851 | return t; | |
852 | ||
853 | /* We return SPECS here, because in the parser it was ending | |
854 | up with not doing anything to $$, which is what SPECS | |
855 | represents. */ | |
856 | return specs; | |
857 | break; | |
858 | ||
859 | case RECORD_TYPE: | |
860 | /* This code may be needed for UNION_TYPEs as | |
861 | well. */ | |
862 | tcode = record_type_node; | |
fc378698 | 863 | if (CLASSTYPE_DECLARED_CLASS (t)) |
8d08fdba | 864 | tcode = class_type_node; |
fc378698 | 865 | else if (IS_SIGNATURE (t)) |
8d08fdba | 866 | tcode = signature_type_node; |
8d08fdba | 867 | |
8ccc31eb | 868 | t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0); |
fc378698 MS |
869 | if (TYPE_CONTEXT (t)) |
870 | CLASSTYPE_NO_GLOBALIZE (t) = 1; | |
8d08fdba MS |
871 | return NULL_TREE; |
872 | break; | |
873 | ||
874 | case UNION_TYPE: | |
875 | case ENUMERAL_TYPE: | |
fc378698 | 876 | if (TREE_CODE (t) == UNION_TYPE) |
8d08fdba MS |
877 | tcode = union_type_node; |
878 | else | |
879 | tcode = enum_type_node; | |
880 | ||
8ccc31eb | 881 | t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0); |
fc378698 MS |
882 | if (TREE_CODE (t) == UNION_TYPE && TYPE_CONTEXT (t)) |
883 | CLASSTYPE_NO_GLOBALIZE (t) = 1; | |
8d08fdba MS |
884 | if (TREE_CODE (t) == UNION_TYPE |
885 | && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) | |
886 | { | |
d2e5ee5c MS |
887 | /* See also shadow_tag. */ |
888 | ||
8d08fdba | 889 | struct pending_inline **p; |
d2e5ee5c | 890 | tree *q; |
8d08fdba MS |
891 | x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t); |
892 | ||
893 | /* Wipe out memory of synthesized methods */ | |
894 | TYPE_HAS_CONSTRUCTOR (t) = 0; | |
895 | TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0; | |
896 | TYPE_HAS_INIT_REF (t) = 0; | |
897 | TYPE_HAS_CONST_INIT_REF (t) = 0; | |
898 | TYPE_HAS_ASSIGN_REF (t) = 0; | |
899 | TYPE_HAS_ASSIGNMENT (t) = 0; | |
900 | TYPE_HAS_CONST_ASSIGN_REF (t) = 0; | |
901 | ||
d2e5ee5c MS |
902 | q = &TYPE_METHODS (t); |
903 | while (*q) | |
904 | { | |
905 | if (DECL_ARTIFICIAL (*q)) | |
906 | *q = TREE_CHAIN (*q); | |
907 | else | |
908 | q = &TREE_CHAIN (*q); | |
909 | } | |
910 | if (TYPE_METHODS (t)) | |
911 | error ("an anonymous union cannot have function members"); | |
912 | ||
8d08fdba MS |
913 | p = &pending_inlines; |
914 | for (; *p; *p = (*p)->next) | |
915 | if (DECL_CONTEXT ((*p)->fndecl) != t) | |
916 | break; | |
917 | } | |
918 | else if (TREE_CODE (t) == ENUMERAL_TYPE) | |
86052cc3 | 919 | x = grok_enum_decls (NULL_TREE); |
8d08fdba MS |
920 | else |
921 | x = NULL_TREE; | |
922 | return x; | |
923 | break; | |
924 | ||
925 | default: | |
926 | if (t != void_type_node) | |
927 | error ("empty component declaration"); | |
928 | return NULL_TREE; | |
929 | } | |
930 | } | |
931 | else | |
86052cc3 JM |
932 | /* There may or may not be any enum decls to grok, but |
933 | grok_enum_decls will just return components, if there aren't | |
934 | any. We used to try to figure out whether or not there were | |
935 | any enum decls based on the type of components, but that's too | |
936 | hard; it might be something like `enum { a } *p;'. */ | |
937 | return grok_enum_decls (components); | |
8d08fdba MS |
938 | } |
939 | ||
940 | /* Classes overload their constituent function names automatically. | |
941 | When a function name is declared in a record structure, | |
942 | its name is changed to it overloaded name. Since names for | |
943 | constructors and destructors can conflict, we place a leading | |
944 | '$' for destructors. | |
945 | ||
946 | CNAME is the name of the class we are grokking for. | |
947 | ||
948 | FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'. | |
949 | ||
950 | FLAGS contains bits saying what's special about today's | |
951 | arguments. 1 == DESTRUCTOR. 2 == OPERATOR. | |
952 | ||
953 | If FUNCTION is a destructor, then we must add the `auto-delete' field | |
954 | as a second parameter. There is some hair associated with the fact | |
955 | that we must "declare" this variable in the manner consistent with the | |
956 | way the rest of the arguments were declared. | |
957 | ||
958 | QUALS are the qualifiers for the this pointer. */ | |
959 | ||
960 | void | |
961 | grokclassfn (ctype, cname, function, flags, quals) | |
962 | tree ctype, cname, function; | |
963 | enum overload_flags flags; | |
964 | tree quals; | |
965 | { | |
966 | tree fn_name = DECL_NAME (function); | |
967 | tree arg_types; | |
968 | tree parm; | |
700f8a87 | 969 | tree qualtype; |
f30432d7 MS |
970 | tree fntype = TREE_TYPE (function); |
971 | tree raises = TYPE_RAISES_EXCEPTIONS (fntype); | |
8d08fdba MS |
972 | |
973 | if (fn_name == NULL_TREE) | |
974 | { | |
975 | error ("name missing for member function"); | |
976 | fn_name = get_identifier ("<anonymous>"); | |
977 | DECL_NAME (function) = fn_name; | |
978 | } | |
979 | ||
980 | if (quals) | |
700f8a87 MS |
981 | qualtype = grok_method_quals (ctype, function, quals); |
982 | else | |
983 | qualtype = ctype; | |
8d08fdba MS |
984 | |
985 | arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); | |
986 | if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE) | |
987 | { | |
988 | /* Must add the class instance variable up front. */ | |
989 | /* Right now we just make this a pointer. But later | |
990 | we may wish to make it special. */ | |
991 | tree type = TREE_VALUE (arg_types); | |
863adfc0 | 992 | int constp = 1; |
8d08fdba | 993 | |
2986ae00 MS |
994 | if ((flag_this_is_variable > 0) |
995 | && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))) | |
863adfc0 | 996 | constp = 0; |
2986ae00 MS |
997 | |
998 | if (DECL_CONSTRUCTOR_P (function)) | |
8d08fdba MS |
999 | { |
1000 | if (TYPE_USES_VIRTUAL_BASECLASSES (ctype)) | |
1001 | { | |
1002 | DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1; | |
1003 | /* In this case we need "in-charge" flag saying whether | |
1004 | this constructor is responsible for initialization | |
1005 | of virtual baseclasses or not. */ | |
1006 | parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node); | |
1007 | /* Mark the artificial `__in_chrg' parameter as "artificial". */ | |
700f8a87 | 1008 | SET_DECL_ARTIFICIAL (parm); |
8d08fdba | 1009 | DECL_ARG_TYPE (parm) = integer_type_node; |
72b7eeff | 1010 | TREE_READONLY (parm) = 1; |
8d08fdba MS |
1011 | TREE_CHAIN (parm) = last_function_parms; |
1012 | last_function_parms = parm; | |
1013 | } | |
1014 | } | |
1015 | ||
1016 | parm = build_decl (PARM_DECL, this_identifier, type); | |
1017 | /* Mark the artificial `this' parameter as "artificial". */ | |
700f8a87 | 1018 | SET_DECL_ARTIFICIAL (parm); |
8d08fdba MS |
1019 | DECL_ARG_TYPE (parm) = type; |
1020 | /* We can make this a register, so long as we don't | |
1021 | accidentally complain if someone tries to take its address. */ | |
1022 | DECL_REGISTER (parm) = 1; | |
863adfc0 | 1023 | if (constp) |
8d08fdba MS |
1024 | TREE_READONLY (parm) = 1; |
1025 | TREE_CHAIN (parm) = last_function_parms; | |
1026 | last_function_parms = parm; | |
1027 | } | |
1028 | ||
1029 | if (flags == DTOR_FLAG) | |
1030 | { | |
1031 | char *buf, *dbuf; | |
8d08fdba MS |
1032 | int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1; |
1033 | ||
7834ab39 | 1034 | arg_types = hash_tree_chain (integer_type_node, void_list_node); |
8d08fdba MS |
1035 | TREE_SIDE_EFFECTS (arg_types) = 1; |
1036 | /* Build the overload name. It will look like `7Example'. */ | |
1037 | if (IDENTIFIER_TYPE_VALUE (cname)) | |
1038 | dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1); | |
1039 | else if (IDENTIFIER_LOCAL_VALUE (cname)) | |
1040 | dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1); | |
1041 | else | |
1042 | /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when | |
1043 | it's defined out of the class definition, since poplevel_class wipes | |
1044 | it out. This used to be internal error 346. */ | |
1045 | dbuf = build_overload_name (ctype, 1, 1); | |
1046 | buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX)); | |
1047 | bcopy (DESTRUCTOR_DECL_PREFIX, buf, len); | |
1048 | buf[len] = '\0'; | |
1049 | strcat (buf, dbuf); | |
1050 | DECL_ASSEMBLER_NAME (function) = get_identifier (buf); | |
72b7eeff | 1051 | parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node); |
8d08fdba | 1052 | /* Mark the artificial `__in_chrg' parameter as "artificial". */ |
700f8a87 | 1053 | SET_DECL_ARTIFICIAL (parm); |
8d08fdba | 1054 | TREE_READONLY (parm) = 1; |
72b7eeff | 1055 | DECL_ARG_TYPE (parm) = integer_type_node; |
8d08fdba MS |
1056 | /* This is the same chain as DECL_ARGUMENTS (...). */ |
1057 | TREE_CHAIN (last_function_parms) = parm; | |
1058 | ||
f30432d7 MS |
1059 | fntype = build_cplus_method_type (qualtype, void_type_node, |
1060 | arg_types); | |
1061 | if (raises) | |
1062 | { | |
1063 | fntype = build_exception_variant (fntype, raises); | |
1064 | } | |
1065 | TREE_TYPE (function) = fntype; | |
8d08fdba MS |
1066 | TYPE_HAS_DESTRUCTOR (ctype) = 1; |
1067 | } | |
1068 | else | |
1069 | { | |
1070 | tree these_arg_types; | |
1071 | ||
1072 | if (DECL_CONSTRUCTOR_FOR_VBASE_P (function)) | |
1073 | { | |
1074 | arg_types = hash_tree_chain (integer_type_node, | |
1075 | TREE_CHAIN (arg_types)); | |
f30432d7 MS |
1076 | fntype = build_cplus_method_type (qualtype, |
1077 | TREE_TYPE (TREE_TYPE (function)), | |
1078 | arg_types); | |
1079 | if (raises) | |
1080 | { | |
1081 | fntype = build_exception_variant (fntype, raises); | |
1082 | } | |
1083 | TREE_TYPE (function) = fntype; | |
8d08fdba MS |
1084 | arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); |
1085 | } | |
1086 | ||
1087 | these_arg_types = arg_types; | |
1088 | ||
1089 | if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE) | |
1090 | /* Only true for static member functions. */ | |
f30432d7 | 1091 | these_arg_types = hash_tree_chain (build_pointer_type (qualtype), |
700f8a87 | 1092 | arg_types); |
8d08fdba MS |
1093 | |
1094 | DECL_ASSEMBLER_NAME (function) | |
1095 | = build_decl_overload (fn_name, these_arg_types, | |
1096 | 1 + DECL_CONSTRUCTOR_P (function)); | |
1097 | ||
1098 | #if 0 | |
1099 | /* This code is going into the compiler, but currently, it makes | |
ddd5a7c1 | 1100 | libg++/src/Integer.cc not compile. The problem is that the nice name |
8d08fdba MS |
1101 | winds up going into the symbol table, and conversion operations look |
1102 | for the manged name. */ | |
1103 | substitute_nice_name (function); | |
1104 | #endif | |
1105 | } | |
1106 | ||
1107 | DECL_ARGUMENTS (function) = last_function_parms; | |
1108 | /* First approximations. */ | |
1109 | DECL_CONTEXT (function) = ctype; | |
1110 | DECL_CLASS_CONTEXT (function) = ctype; | |
1111 | } | |
1112 | ||
1113 | /* Work on the expr used by alignof (this is only called by the parser). */ | |
e92cc029 | 1114 | |
8d08fdba MS |
1115 | tree |
1116 | grok_alignof (expr) | |
1117 | tree expr; | |
1118 | { | |
1119 | tree best, t; | |
1120 | int bestalign; | |
1121 | ||
abff8e06 JM |
1122 | if (processing_template_decl) |
1123 | return build_min (ALIGNOF_EXPR, sizetype, expr); | |
1124 | ||
8d08fdba MS |
1125 | if (TREE_CODE (expr) == COMPONENT_REF |
1126 | && DECL_BIT_FIELD (TREE_OPERAND (expr, 1))) | |
1127 | error ("`__alignof__' applied to a bit-field"); | |
1128 | ||
1129 | if (TREE_CODE (expr) == INDIRECT_REF) | |
1130 | { | |
1131 | best = t = TREE_OPERAND (expr, 0); | |
1132 | bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); | |
1133 | ||
1134 | while (TREE_CODE (t) == NOP_EXPR | |
1135 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE) | |
1136 | { | |
1137 | int thisalign; | |
1138 | t = TREE_OPERAND (t, 0); | |
1139 | thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); | |
1140 | if (thisalign > bestalign) | |
1141 | best = t, bestalign = thisalign; | |
1142 | } | |
1143 | return c_alignof (TREE_TYPE (TREE_TYPE (best))); | |
1144 | } | |
1145 | else | |
1146 | { | |
1147 | /* ANSI says arrays and fns are converted inside comma. | |
1148 | But we can't convert them in build_compound_expr | |
1149 | because that would break commas in lvalues. | |
1150 | So do the conversion here if operand was a comma. */ | |
1151 | if (TREE_CODE (expr) == COMPOUND_EXPR | |
1152 | && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE | |
1153 | || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)) | |
1154 | expr = default_conversion (expr); | |
1155 | return c_alignof (TREE_TYPE (expr)); | |
1156 | } | |
1157 | } | |
1158 | ||
1159 | /* Create an ARRAY_REF, checking for the user doing things backwards | |
1160 | along the way. */ | |
e92cc029 | 1161 | |
8d08fdba MS |
1162 | tree |
1163 | grok_array_decl (array_expr, index_exp) | |
1164 | tree array_expr, index_exp; | |
1165 | { | |
1166 | tree type = TREE_TYPE (array_expr); | |
b7484fbe | 1167 | tree p1, p2, i1, i2; |
8d08fdba MS |
1168 | |
1169 | if (type == error_mark_node || index_exp == error_mark_node) | |
1170 | return error_mark_node; | |
5156628f | 1171 | if (processing_template_decl) |
5566b478 MS |
1172 | return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE, |
1173 | array_expr, index_exp); | |
1174 | ||
8d08fdba MS |
1175 | if (type == NULL_TREE) |
1176 | { | |
1177 | /* Something has gone very wrong. Assume we are mistakenly reducing | |
1178 | an expression instead of a declaration. */ | |
1179 | error ("parser may be lost: is there a '{' missing somewhere?"); | |
1180 | return NULL_TREE; | |
1181 | } | |
1182 | ||
1183 | if (TREE_CODE (type) == OFFSET_TYPE | |
1184 | || TREE_CODE (type) == REFERENCE_TYPE) | |
1185 | type = TREE_TYPE (type); | |
1186 | ||
1187 | /* If they have an `operator[]', use that. */ | |
1188 | if (TYPE_LANG_SPECIFIC (type) | |
5566b478 | 1189 | && TYPE_OVERLOADS_ARRAY_REF (complete_type (type))) |
8d08fdba | 1190 | return build_opfncall (ARRAY_REF, LOOKUP_NORMAL, |
00595019 | 1191 | array_expr, index_exp, NULL_TREE); |
8d08fdba MS |
1192 | |
1193 | /* Otherwise, create an ARRAY_REF for a pointer or array type. */ | |
8d08fdba | 1194 | |
b7484fbe MS |
1195 | if (TREE_CODE (type) == ARRAY_TYPE) |
1196 | p1 = array_expr; | |
1197 | else | |
1198 | p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0); | |
8d08fdba | 1199 | |
b7484fbe MS |
1200 | if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE) |
1201 | p2 = index_exp; | |
1202 | else | |
1203 | p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0); | |
8d08fdba | 1204 | |
b7484fbe MS |
1205 | i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0); |
1206 | i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0); | |
8d08fdba | 1207 | |
b7484fbe MS |
1208 | if ((p1 && i2) && (i1 && p2)) |
1209 | error ("ambiguous conversion for array subscript"); | |
8d08fdba | 1210 | |
b7484fbe MS |
1211 | if (p1 && i2) |
1212 | array_expr = p1, index_exp = i2; | |
1213 | else if (i1 && p2) | |
1214 | array_expr = p2, index_exp = i1; | |
1215 | else | |
1216 | { | |
1217 | cp_error ("invalid types `%T[%T]' for array subscript", | |
1218 | type, TREE_TYPE (index_exp)); | |
1219 | return error_mark_node; | |
1220 | } | |
1221 | ||
1222 | if (array_expr == error_mark_node || index_exp == error_mark_node) | |
1223 | error ("ambiguous conversion for array subscript"); | |
1224 | ||
1225 | return build_array_ref (array_expr, index_exp); | |
8d08fdba MS |
1226 | } |
1227 | ||
1228 | /* Given the cast expression EXP, checking out its validity. Either return | |
1229 | an error_mark_node if there was an unavoidable error, return a cast to | |
1230 | void for trying to delete a pointer w/ the value 0, or return the | |
1231 | call to delete. If DOING_VEC is 1, we handle things differently | |
1232 | for doing an array delete. If DOING_VEC is 2, they gave us the | |
1233 | array size as an argument to delete. | |
1234 | Implements ARM $5.3.4. This is called from the parser. */ | |
e92cc029 | 1235 | |
8d08fdba MS |
1236 | tree |
1237 | delete_sanity (exp, size, doing_vec, use_global_delete) | |
1238 | tree exp, size; | |
1239 | int doing_vec, use_global_delete; | |
1240 | { | |
5566b478 MS |
1241 | tree t; |
1242 | tree type; | |
1243 | enum tree_code code; | |
8d08fdba MS |
1244 | /* For a regular vector delete (aka, no size argument) we will pass |
1245 | this down as a NULL_TREE into build_vec_delete. */ | |
1246 | tree maxindex = NULL_TREE; | |
5566b478 | 1247 | |
909e536a MS |
1248 | if (exp == error_mark_node) |
1249 | return exp; | |
1250 | ||
5156628f | 1251 | if (processing_template_decl) |
5566b478 MS |
1252 | { |
1253 | t = build_min (DELETE_EXPR, void_type_node, exp, size); | |
1254 | DELETE_EXPR_USE_GLOBAL (t) = use_global_delete; | |
1255 | DELETE_EXPR_USE_VEC (t) = doing_vec; | |
1256 | return t; | |
1257 | } | |
1258 | ||
19754d4c JM |
1259 | t = exp; |
1260 | if (TREE_CODE (t) == OFFSET_REF) | |
1261 | t = resolve_offset_ref (t); | |
1262 | t = stabilize_reference (convert_from_reference (t)); | |
5566b478 MS |
1263 | type = TREE_TYPE (t); |
1264 | code = TREE_CODE (type); | |
8d08fdba MS |
1265 | |
1266 | switch (doing_vec) | |
1267 | { | |
1268 | case 2: | |
1269 | maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1); | |
d22c8596 | 1270 | pedwarn ("anachronistic use of array size in vector delete"); |
8d08fdba MS |
1271 | /* Fall through. */ |
1272 | case 1: | |
8d08fdba MS |
1273 | break; |
1274 | default: | |
1275 | if (code != POINTER_TYPE) | |
1276 | { | |
1277 | cp_error ("type `%#T' argument given to `delete', expected pointer", | |
1278 | type); | |
1279 | return error_mark_node; | |
1280 | } | |
1281 | ||
59be0cdd | 1282 | /* Deleting a pointer with the value zero is valid and has no effect. */ |
8d08fdba MS |
1283 | if (integer_zerop (t)) |
1284 | return build1 (NOP_EXPR, void_type_node, t); | |
1285 | } | |
1286 | ||
f376e137 | 1287 | if (code == POINTER_TYPE) |
8d08fdba | 1288 | { |
8ccc31eb | 1289 | #if 0 |
19754d4c | 1290 | /* As of Valley Forge, you can delete a pointer to const. */ |
f376e137 MS |
1291 | if (TREE_READONLY (TREE_TYPE (type))) |
1292 | { | |
1293 | error ("`const *' cannot be deleted"); | |
1294 | return error_mark_node; | |
1295 | } | |
8ccc31eb | 1296 | #endif |
19754d4c | 1297 | /* You can't delete functions. */ |
f376e137 MS |
1298 | if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) |
1299 | { | |
1300 | error ("cannot delete a function"); | |
1301 | return error_mark_node; | |
1302 | } | |
8d08fdba MS |
1303 | } |
1304 | ||
a28e3c7f | 1305 | #if 0 |
8d08fdba MS |
1306 | /* If the type has no destructor, then we should build a regular |
1307 | delete, instead of a vector delete. Otherwise, we would end | |
1308 | up passing a bogus offset into __builtin_delete, which is | |
1309 | not expecting it. */ | |
1310 | if (doing_vec | |
1311 | && TREE_CODE (type) == POINTER_TYPE | |
1312 | && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type))) | |
8926095f MS |
1313 | { |
1314 | doing_vec = 0; | |
1315 | use_global_delete = 1; | |
1316 | } | |
a28e3c7f | 1317 | #endif |
8d08fdba MS |
1318 | |
1319 | if (doing_vec) | |
5566b478 | 1320 | return build_vec_delete (t, maxindex, integer_one_node, |
a28e3c7f | 1321 | integer_two_node, use_global_delete); |
8d08fdba | 1322 | else |
863adfc0 MS |
1323 | { |
1324 | if (IS_AGGR_TYPE (TREE_TYPE (type)) | |
1325 | && TYPE_GETS_REG_DELETE (TREE_TYPE (type))) | |
1326 | { | |
1327 | /* Only do access checking here; we'll be calling op delete | |
1328 | from the destructor. */ | |
da4768fe JM |
1329 | tree tmp = build_op_delete_call (DELETE_EXPR, t, |
1330 | size_zero_node, LOOKUP_NORMAL); | |
863adfc0 MS |
1331 | if (tmp == error_mark_node) |
1332 | return error_mark_node; | |
1333 | } | |
1334 | ||
1335 | return build_delete (type, t, integer_three_node, | |
bd6dd845 | 1336 | LOOKUP_NORMAL, use_global_delete); |
863adfc0 | 1337 | } |
8d08fdba MS |
1338 | } |
1339 | ||
98c1c668 JM |
1340 | /* Report an error if the indicated template declaration is not the |
1341 | sort of thing that should be a member template. */ | |
1342 | ||
1343 | void | |
1344 | check_member_template (tmpl) | |
1345 | tree tmpl; | |
1346 | { | |
1347 | tree decl; | |
1348 | ||
1349 | my_friendly_assert (TREE_CODE (tmpl) == TEMPLATE_DECL, 0); | |
1350 | decl = DECL_TEMPLATE_RESULT (tmpl); | |
1351 | ||
1352 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1353 | { | |
1354 | if (current_function_decl) | |
1355 | /* 14.5.2.2 [temp.mem] | |
1356 | ||
1357 | A local class shall not have member templates. */ | |
1358 | cp_error ("declaration of of member template `%#D' in local class", | |
1359 | decl); | |
1360 | ||
1361 | if (DECL_VIRTUAL_P (decl)) | |
1362 | { | |
1363 | /* 14.5.2.3 [temp.mem] | |
1364 | ||
1365 | A member function template shall not be virtual. */ | |
1366 | cp_error | |
1367 | ("invalid use of `virtual' in template declaration of `%#D'", | |
1368 | decl); | |
1369 | DECL_VIRTUAL_P (decl) = 0; | |
1370 | } | |
1371 | ||
1372 | /* The debug-information generating code doesn't know what to do | |
1373 | with member templates. */ | |
1374 | DECL_IGNORED_P (tmpl) = 1; | |
1375 | } | |
1376 | else if (TREE_CODE (decl) == TYPE_DECL && | |
1377 | AGGREGATE_TYPE_P (TREE_TYPE (decl))) | |
1378 | { | |
1379 | if (current_function_decl) | |
1380 | /* 14.5.2.2 [temp.mem] | |
1381 | ||
1382 | A local class shall not have member templates. */ | |
1383 | cp_error ("declaration of of member template `%#D' in local class", | |
1384 | decl); | |
1385 | ||
1386 | /* We don't handle member template classes yet. */ | |
1387 | sorry ("member templates classes"); | |
1388 | } | |
1389 | else | |
1390 | cp_error ("template declaration of `%#D'", decl); | |
1391 | } | |
1392 | ||
8d08fdba MS |
1393 | /* Sanity check: report error if this function FUNCTION is not |
1394 | really a member of the class (CTYPE) it is supposed to belong to. | |
1395 | CNAME is the same here as it is for grokclassfn above. */ | |
1396 | ||
f30432d7 | 1397 | tree |
5566b478 MS |
1398 | check_classfn (ctype, function) |
1399 | tree ctype, function; | |
8d08fdba MS |
1400 | { |
1401 | tree fn_name = DECL_NAME (function); | |
1402 | tree fndecl; | |
5566b478 | 1403 | tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype)); |
8d08fdba MS |
1404 | tree *methods = 0; |
1405 | tree *end = 0; | |
98c1c668 | 1406 | tree templates = NULL_TREE; |
8d08fdba MS |
1407 | |
1408 | if (method_vec != 0) | |
1409 | { | |
1410 | methods = &TREE_VEC_ELT (method_vec, 0); | |
1411 | end = TREE_VEC_END (method_vec); | |
1412 | ||
1413 | /* First suss out ctors and dtors. */ | |
fc378698 MS |
1414 | if (*methods && fn_name == DECL_NAME (*methods) |
1415 | && DECL_CONSTRUCTOR_P (function)) | |
1416 | goto got_it; | |
1417 | if (*++methods && fn_name == DECL_NAME (*methods) | |
1418 | && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function))) | |
8d08fdba MS |
1419 | goto got_it; |
1420 | ||
1421 | while (++methods != end) | |
1422 | { | |
98c1c668 | 1423 | fndecl = *methods; |
8d08fdba MS |
1424 | if (fn_name == DECL_NAME (*methods)) |
1425 | { | |
1426 | got_it: | |
1427 | fndecl = *methods; | |
1428 | while (fndecl) | |
1429 | { | |
1430 | if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl)) | |
f30432d7 | 1431 | return fndecl; |
5edb8b93 | 1432 | #if 0 |
5566b478 | 1433 | /* This doesn't work for static member functions that are |
e92cc029 | 1434 | pretending to be methods. */ |
6060a796 | 1435 | /* We have to do more extensive argument checking here, as |
e92cc029 | 1436 | the name may have been changed by asm("new_name"). */ |
6060a796 | 1437 | if (decls_match (function, fndecl)) |
f30432d7 | 1438 | return fndecl; |
5edb8b93 | 1439 | #else |
8145f082 MS |
1440 | if (DECL_NAME (function) == DECL_NAME (fndecl)) |
1441 | { | |
1442 | tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function)); | |
1443 | tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); | |
1444 | ||
1445 | /* Get rid of the this parameter on functions that become | |
e92cc029 | 1446 | static. */ |
8145f082 MS |
1447 | if (DECL_STATIC_FUNCTION_P (fndecl) |
1448 | && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE) | |
1449 | p1 = TREE_CHAIN (p1); | |
1450 | ||
1451 | if (comptypes (TREE_TYPE (TREE_TYPE (function)), | |
1452 | TREE_TYPE (TREE_TYPE (fndecl)), 1) | |
386b8a85 JM |
1453 | && compparms (p1, p2, 3) |
1454 | && (DECL_TEMPLATE_SPECIALIZATION (function) | |
1455 | == DECL_TEMPLATE_SPECIALIZATION (fndecl)) | |
1456 | && (!DECL_TEMPLATE_SPECIALIZATION (function) | |
1457 | || (DECL_TI_TEMPLATE (function) | |
1458 | == DECL_TI_TEMPLATE (fndecl)))) | |
5566b478 | 1459 | return fndecl; |
98c1c668 | 1460 | |
386b8a85 | 1461 | if (is_member_template (fndecl)) |
98c1c668 JM |
1462 | /* This function might be an instantiation |
1463 | or specialization of fndecl. */ | |
1464 | templates = | |
e66d884e | 1465 | scratch_tree_cons (NULL_TREE, fndecl, templates); |
8145f082 | 1466 | } |
5edb8b93 | 1467 | #endif |
8d08fdba MS |
1468 | fndecl = DECL_CHAIN (fndecl); |
1469 | } | |
1470 | break; /* loser */ | |
1471 | } | |
98c1c668 JM |
1472 | else if (TREE_CODE (fndecl) == TEMPLATE_DECL |
1473 | && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl)) | |
1474 | && IDENTIFIER_TYPENAME_P (fn_name)) | |
1475 | /* The method in the class is a member template | |
1476 | conversion operator. We are declaring another | |
1477 | conversion operator. It is possible that even though | |
1478 | the names don't match, there is some specialization | |
1479 | occurring. */ | |
1480 | templates = | |
e66d884e | 1481 | scratch_tree_cons (NULL_TREE, fndecl, templates); |
8d08fdba MS |
1482 | } |
1483 | } | |
1484 | ||
98c1c668 JM |
1485 | if (templates) |
1486 | /* This function might be an instantiation or a specialization. | |
1487 | We should verify that this is possible. If it is, we must | |
1488 | somehow add the new declaration to the method vector for the | |
1489 | class. Perhaps we should use add_method? For now, we simply | |
1490 | return NULL_TREE, which lets the caller know that this | |
1491 | function is new, but we don't print an error message. */ | |
1492 | return NULL_TREE; | |
1493 | ||
8d08fdba | 1494 | if (methods != end) |
f30432d7 MS |
1495 | { |
1496 | tree fndecl = *methods; | |
1497 | cp_error ("prototype for `%#D' does not match any in class `%T'", | |
1498 | function, ctype); | |
1499 | cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl) ? "s are" : " is", | |
1500 | fndecl); | |
1501 | while (fndecl = DECL_CHAIN (fndecl), fndecl) | |
1502 | cp_error_at (" %#D", fndecl); | |
1503 | } | |
8d08fdba MS |
1504 | else |
1505 | { | |
1506 | methods = 0; | |
00595019 MS |
1507 | cp_error ("no `%#D' member function declared in class `%T'", |
1508 | function, ctype); | |
8d08fdba MS |
1509 | } |
1510 | ||
fc378698 MS |
1511 | /* If we did not find the method in the class, add it to avoid |
1512 | spurious errors. */ | |
8d08fdba | 1513 | add_method (ctype, methods, function); |
f30432d7 | 1514 | return NULL_TREE; |
8d08fdba MS |
1515 | } |
1516 | ||
1517 | /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted) | |
1518 | of a structure component, returning a FIELD_DECL node. | |
1519 | QUALS is a list of type qualifiers for this decl (such as for declaring | |
1520 | const member functions). | |
1521 | ||
1522 | This is done during the parsing of the struct declaration. | |
1523 | The FIELD_DECL nodes are chained together and the lot of them | |
1524 | are ultimately passed to `build_struct' to make the RECORD_TYPE node. | |
1525 | ||
1526 | C++: | |
1527 | ||
1528 | If class A defines that certain functions in class B are friends, then | |
1529 | the way I have set things up, it is B who is interested in permission | |
1530 | granted by A. However, it is in A's context that these declarations | |
1531 | are parsed. By returning a void_type_node, class A does not attempt | |
1532 | to incorporate the declarations of the friends within its structure. | |
1533 | ||
1534 | DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING | |
1535 | CHANGES TO CODE IN `start_method'. */ | |
1536 | ||
1537 | tree | |
c11b6f21 MS |
1538 | grokfield (declarator, declspecs, init, asmspec_tree, attrlist) |
1539 | tree declarator, declspecs, init, asmspec_tree, attrlist; | |
8d08fdba MS |
1540 | { |
1541 | register tree value; | |
1542 | char *asmspec = 0; | |
6060a796 | 1543 | int flags = LOOKUP_ONLYCONVERTING; |
8d08fdba MS |
1544 | |
1545 | /* Convert () initializers to = initializers. */ | |
1546 | if (init == NULL_TREE && declarator != NULL_TREE | |
1547 | && TREE_CODE (declarator) == CALL_EXPR | |
1548 | && TREE_OPERAND (declarator, 0) | |
1549 | && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE | |
1550 | || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF) | |
1551 | && parmlist_is_exprlist (TREE_OPERAND (declarator, 1))) | |
1552 | { | |
1553 | init = TREE_OPERAND (declarator, 1); | |
1554 | declarator = TREE_OPERAND (declarator, 0); | |
6060a796 | 1555 | flags = 0; |
8d08fdba MS |
1556 | } |
1557 | ||
cffa8729 | 1558 | if (declspecs == NULL_TREE |
7fcdf4c2 MS |
1559 | && TREE_CODE (declarator) == SCOPE_REF |
1560 | && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE) | |
cffa8729 MS |
1561 | { |
1562 | /* Access declaration */ | |
5566b478 MS |
1563 | if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0)))) |
1564 | ; | |
1565 | else if (TREE_COMPLEXITY (declarator) == current_class_depth) | |
cffa8729 MS |
1566 | pop_nested_class (1); |
1567 | return do_class_using_decl (declarator); | |
1568 | } | |
1569 | ||
8d08fdba MS |
1570 | if (init |
1571 | && TREE_CODE (init) == TREE_LIST | |
1572 | && TREE_VALUE (init) == error_mark_node | |
1573 | && TREE_CHAIN (init) == NULL_TREE) | |
cffa8729 | 1574 | init = NULL_TREE; |
8d08fdba | 1575 | |
c11b6f21 | 1576 | value = grokdeclarator (declarator, declspecs, FIELD, init != 0, NULL_TREE); |
8d08fdba | 1577 | if (! value) |
a0a33927 | 1578 | return value; /* friend or constructor went bad. */ |
8d08fdba MS |
1579 | |
1580 | /* Pass friendly classes back. */ | |
1581 | if (TREE_CODE (value) == VOID_TYPE) | |
1582 | return void_type_node; | |
1583 | ||
1584 | if (DECL_NAME (value) != NULL_TREE | |
1585 | && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_' | |
1586 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr")) | |
1587 | cp_error ("member `%D' conflicts with virtual function table field name", value); | |
1588 | ||
1589 | /* Stash away type declarations. */ | |
1590 | if (TREE_CODE (value) == TYPE_DECL) | |
1591 | { | |
1592 | DECL_NONLOCAL (value) = 1; | |
700f8a87 MS |
1593 | DECL_CONTEXT (value) = current_class_type; |
1594 | DECL_CLASS_CONTEXT (value) = current_class_type; | |
8d08fdba | 1595 | CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1; |
8145f082 | 1596 | |
8ccc31eb | 1597 | pushdecl_class_level (value); |
8d08fdba MS |
1598 | return value; |
1599 | } | |
1600 | ||
1601 | if (IS_SIGNATURE (current_class_type) | |
1602 | && TREE_CODE (value) != FUNCTION_DECL) | |
1603 | { | |
1604 | error ("field declaration not allowed in signature"); | |
1605 | return void_type_node; | |
1606 | } | |
1607 | ||
1608 | if (DECL_IN_AGGR_P (value)) | |
1609 | { | |
1610 | cp_error ("`%D' is already defined in the class %T", value, | |
1611 | DECL_CONTEXT (value)); | |
1612 | return void_type_node; | |
1613 | } | |
1614 | ||
8d08fdba MS |
1615 | if (asmspec_tree) |
1616 | asmspec = TREE_STRING_POINTER (asmspec_tree); | |
1617 | ||
1618 | if (init) | |
1619 | { | |
1620 | if (IS_SIGNATURE (current_class_type) | |
1621 | && TREE_CODE (value) == FUNCTION_DECL) | |
1622 | { | |
1623 | error ("function declarations cannot have initializers in signature"); | |
1624 | init = NULL_TREE; | |
1625 | } | |
1626 | else if (TREE_CODE (value) == FUNCTION_DECL) | |
1627 | { | |
1628 | grok_function_init (value, init); | |
1629 | init = NULL_TREE; | |
1630 | } | |
5b605f68 | 1631 | else if (pedantic && TREE_CODE (value) != VAR_DECL) |
a0a33927 MS |
1632 | /* Already complained in grokdeclarator. */ |
1633 | init = NULL_TREE; | |
8d08fdba MS |
1634 | else |
1635 | { | |
a0a33927 MS |
1636 | /* We allow initializers to become parameters to base |
1637 | initializers. */ | |
8d08fdba MS |
1638 | if (TREE_CODE (init) == TREE_LIST) |
1639 | { | |
1640 | if (TREE_CHAIN (init) == NULL_TREE) | |
1641 | init = TREE_VALUE (init); | |
1642 | else | |
1643 | init = digest_init (TREE_TYPE (value), init, (tree *)0); | |
1644 | } | |
1645 | ||
1646 | if (TREE_CODE (init) == CONST_DECL) | |
1647 | init = DECL_INITIAL (init); | |
1648 | else if (TREE_READONLY_DECL_P (init)) | |
1649 | init = decl_constant_value (init); | |
1650 | else if (TREE_CODE (init) == CONSTRUCTOR) | |
1651 | init = digest_init (TREE_TYPE (value), init, (tree *)0); | |
1652 | my_friendly_assert (TREE_PERMANENT (init), 192); | |
1653 | if (init == error_mark_node) | |
1654 | /* We must make this look different than `error_mark_node' | |
1655 | because `decl_const_value' would mis-interpret it | |
1656 | as only meaning that this VAR_DECL is defined. */ | |
1657 | init = build1 (NOP_EXPR, TREE_TYPE (value), init); | |
5156628f | 1658 | else if (processing_template_decl) |
5566b478 | 1659 | ; |
8d08fdba MS |
1660 | else if (! TREE_CONSTANT (init)) |
1661 | { | |
1662 | /* We can allow references to things that are effectively | |
1663 | static, since references are initialized with the address. */ | |
1664 | if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE | |
1665 | || (TREE_STATIC (init) == 0 | |
1666 | && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd' | |
1667 | || DECL_EXTERNAL (init) == 0))) | |
1668 | { | |
1669 | error ("field initializer is not constant"); | |
1670 | init = error_mark_node; | |
1671 | } | |
1672 | } | |
1673 | } | |
1674 | } | |
1675 | ||
b3417a04 | 1676 | /* The corresponding pop_obstacks is in cp_finish_decl. */ |
8d08fdba MS |
1677 | push_obstacks_nochange (); |
1678 | ||
5156628f | 1679 | if (processing_template_decl && ! current_function_decl |
5566b478 MS |
1680 | && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL)) |
1681 | push_template_decl (value); | |
1682 | ||
45537677 MS |
1683 | if (attrlist) |
1684 | cplus_decl_attributes (value, TREE_PURPOSE (attrlist), | |
1685 | TREE_VALUE (attrlist)); | |
1686 | ||
8d08fdba MS |
1687 | if (TREE_CODE (value) == VAR_DECL) |
1688 | { | |
1689 | /* We cannot call pushdecl here, because that would | |
1690 | fill in the value of our TREE_CHAIN. Instead, we | |
b3417a04 | 1691 | modify cp_finish_decl to do the right thing, namely, to |
8d08fdba | 1692 | put this decl out straight away. */ |
5b605f68 | 1693 | if (TREE_PUBLIC (value)) |
8d08fdba MS |
1694 | { |
1695 | /* current_class_type can be NULL_TREE in case of error. */ | |
1696 | if (asmspec == 0 && current_class_type) | |
1697 | { | |
8d08fdba MS |
1698 | TREE_PUBLIC (value) = 1; |
1699 | DECL_INITIAL (value) = error_mark_node; | |
f376e137 MS |
1700 | DECL_ASSEMBLER_NAME (value) |
1701 | = build_static_name (current_class_type, DECL_NAME (value)); | |
8d08fdba | 1702 | } |
5156628f | 1703 | if (! processing_template_decl) |
5566b478 | 1704 | pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics); |
8d08fdba MS |
1705 | |
1706 | /* Static consts need not be initialized in the class definition. */ | |
1707 | if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value))) | |
1708 | { | |
1709 | static int explanation = 0; | |
1710 | ||
1711 | error ("initializer invalid for static member with constructor"); | |
1712 | if (explanation++ == 0) | |
1713 | error ("(you really want to initialize it separately)"); | |
1714 | init = 0; | |
1715 | } | |
1716 | /* Force the compiler to know when an uninitialized static | |
1717 | const member is being used. */ | |
1718 | if (TYPE_READONLY (value) && init == 0) | |
1719 | TREE_USED (value) = 1; | |
1720 | } | |
1721 | DECL_INITIAL (value) = init; | |
1722 | DECL_IN_AGGR_P (value) = 1; | |
5566b478 MS |
1723 | DECL_CONTEXT (value) = current_class_type; |
1724 | DECL_CLASS_CONTEXT (value) = current_class_type; | |
8d08fdba | 1725 | |
b3417a04 | 1726 | cp_finish_decl (value, init, asmspec_tree, 1, flags); |
8d08fdba MS |
1727 | pushdecl_class_level (value); |
1728 | return value; | |
1729 | } | |
1730 | if (TREE_CODE (value) == FIELD_DECL) | |
1731 | { | |
1732 | if (asmspec) | |
6060a796 MS |
1733 | { |
1734 | /* This must override the asm specifier which was placed | |
1735 | by grokclassfn. Lay this out fresh. */ | |
1736 | DECL_RTL (value) = NULL_RTX; | |
1737 | DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec); | |
1738 | } | |
8d08fdba MS |
1739 | if (DECL_INITIAL (value) == error_mark_node) |
1740 | init = error_mark_node; | |
b3417a04 | 1741 | cp_finish_decl (value, init, asmspec_tree, 1, flags); |
8d08fdba MS |
1742 | DECL_INITIAL (value) = init; |
1743 | DECL_IN_AGGR_P (value) = 1; | |
1744 | return value; | |
1745 | } | |
1746 | if (TREE_CODE (value) == FUNCTION_DECL) | |
1747 | { | |
f30432d7 | 1748 | check_default_args (value); |
8d08fdba MS |
1749 | if (DECL_CHAIN (value) != NULL_TREE) |
1750 | { | |
1751 | /* Need a fresh node here so that we don't get circularity | |
1752 | when we link these together. */ | |
1753 | value = copy_node (value); | |
1754 | /* When does this happen? */ | |
1755 | my_friendly_assert (init == NULL_TREE, 193); | |
1756 | } | |
6060a796 MS |
1757 | if (asmspec) |
1758 | { | |
1759 | /* This must override the asm specifier which was placed | |
1760 | by grokclassfn. Lay this out fresh. */ | |
1761 | DECL_RTL (value) = NULL_RTX; | |
1762 | DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec); | |
1763 | } | |
b3417a04 | 1764 | cp_finish_decl (value, init, asmspec_tree, 1, flags); |
8d08fdba MS |
1765 | |
1766 | /* Pass friends back this way. */ | |
1767 | if (DECL_FRIEND_P (value)) | |
1768 | return void_type_node; | |
1769 | ||
f376e137 | 1770 | #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */ |
a0a33927 | 1771 | if (current_function_decl && ! IS_SIGNATURE (current_class_type)) |
7177d104 MS |
1772 | cp_error ("method `%#D' of local class must be defined in class body", |
1773 | value); | |
f376e137 | 1774 | #endif |
7177d104 | 1775 | |
8d08fdba MS |
1776 | DECL_IN_AGGR_P (value) = 1; |
1777 | return value; | |
1778 | } | |
1779 | my_friendly_abort (21); | |
1780 | /* NOTREACHED */ | |
1781 | return NULL_TREE; | |
1782 | } | |
1783 | ||
1784 | /* Like `grokfield', but for bitfields. | |
1785 | WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */ | |
1786 | ||
1787 | tree | |
1788 | grokbitfield (declarator, declspecs, width) | |
1789 | tree declarator, declspecs, width; | |
1790 | { | |
f30432d7 | 1791 | register tree value = grokdeclarator (declarator, declspecs, BITFIELD, |
c11b6f21 | 1792 | 0, NULL_TREE); |
8d08fdba MS |
1793 | |
1794 | if (! value) return NULL_TREE; /* friends went bad. */ | |
1795 | ||
1796 | /* Pass friendly classes back. */ | |
1797 | if (TREE_CODE (value) == VOID_TYPE) | |
1798 | return void_type_node; | |
1799 | ||
1800 | if (TREE_CODE (value) == TYPE_DECL) | |
1801 | { | |
1802 | cp_error ("cannot declare `%D' to be a bitfield type", value); | |
1803 | return NULL_TREE; | |
1804 | } | |
1805 | ||
1806 | if (IS_SIGNATURE (current_class_type)) | |
1807 | { | |
1808 | error ("field declaration not allowed in signature"); | |
1809 | return void_type_node; | |
1810 | } | |
1811 | ||
1812 | if (DECL_IN_AGGR_P (value)) | |
1813 | { | |
1814 | cp_error ("`%D' is already defined in the class %T", value, | |
1815 | DECL_CONTEXT (value)); | |
1816 | return void_type_node; | |
1817 | } | |
1818 | ||
1819 | GNU_xref_member (current_class_name, value); | |
1820 | ||
1821 | if (TREE_STATIC (value)) | |
1822 | { | |
1823 | cp_error ("static member `%D' cannot be a bitfield", value); | |
1824 | return NULL_TREE; | |
1825 | } | |
b3417a04 | 1826 | cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0); |
8d08fdba MS |
1827 | |
1828 | if (width != error_mark_node) | |
1829 | { | |
5566b478 MS |
1830 | constant_expression_warning (width); |
1831 | DECL_INITIAL (value) = width; | |
1832 | DECL_BIT_FIELD (value) = 1; | |
8d08fdba MS |
1833 | } |
1834 | ||
1835 | DECL_IN_AGGR_P (value) = 1; | |
1836 | return value; | |
1837 | } | |
1838 | ||
8d08fdba | 1839 | tree |
51c184be MS |
1840 | grokoptypename (declspecs, declarator) |
1841 | tree declspecs, declarator; | |
8d08fdba | 1842 | { |
c11b6f21 | 1843 | tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE); |
51c184be | 1844 | return build_typename_overload (t); |
8d08fdba MS |
1845 | } |
1846 | ||
1847 | /* When a function is declared with an initializer, | |
1848 | do the right thing. Currently, there are two possibilities: | |
1849 | ||
1850 | class B | |
1851 | { | |
1852 | public: | |
1853 | // initialization possibility #1. | |
1854 | virtual void f () = 0; | |
1855 | int g (); | |
1856 | }; | |
1857 | ||
1858 | class D1 : B | |
1859 | { | |
1860 | public: | |
1861 | int d1; | |
1862 | // error, no f (); | |
1863 | }; | |
1864 | ||
1865 | class D2 : B | |
1866 | { | |
1867 | public: | |
1868 | int d2; | |
1869 | void f (); | |
1870 | }; | |
1871 | ||
1872 | class D3 : B | |
1873 | { | |
1874 | public: | |
1875 | int d3; | |
1876 | // initialization possibility #2 | |
1877 | void f () = B::f; | |
1878 | }; | |
1879 | ||
1880 | */ | |
1881 | ||
f0e01782 MS |
1882 | int |
1883 | copy_assignment_arg_p (parmtype, virtualp) | |
1884 | tree parmtype; | |
1885 | int virtualp; | |
1886 | { | |
691c003d MS |
1887 | if (current_class_type == NULL_TREE) |
1888 | return 0; | |
1889 | ||
f0e01782 MS |
1890 | if (TREE_CODE (parmtype) == REFERENCE_TYPE) |
1891 | parmtype = TREE_TYPE (parmtype); | |
1892 | ||
1893 | if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type) | |
824b9a4c MS |
1894 | #if 0 |
1895 | /* Non-standard hack to support old Booch components. */ | |
1896 | || (! virtualp && DERIVED_FROM_P (parmtype, current_class_type)) | |
1897 | #endif | |
1898 | ) | |
f0e01782 MS |
1899 | return 1; |
1900 | ||
1901 | return 0; | |
1902 | } | |
1903 | ||
8d08fdba MS |
1904 | static void |
1905 | grok_function_init (decl, init) | |
1906 | tree decl; | |
1907 | tree init; | |
1908 | { | |
1909 | /* An initializer for a function tells how this function should | |
1910 | be inherited. */ | |
1911 | tree type = TREE_TYPE (decl); | |
8d08fdba MS |
1912 | |
1913 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
1914 | cp_error ("initializer specified for non-member function `%D'", decl); | |
cffa8729 MS |
1915 | #if 0 |
1916 | /* We'll check for this in finish_struct_1. */ | |
8d08fdba MS |
1917 | else if (DECL_VINDEX (decl) == NULL_TREE) |
1918 | cp_error ("initializer specified for non-virtual method `%D'", decl); | |
cffa8729 | 1919 | #endif |
8d08fdba MS |
1920 | else if (integer_zerop (init)) |
1921 | { | |
8926095f | 1922 | #if 0 |
8d08fdba MS |
1923 | /* Mark this function as being "defined". */ |
1924 | DECL_INITIAL (decl) = error_mark_node; | |
e92cc029 | 1925 | /* pure virtual destructors must be defined. */ |
8926095f MS |
1926 | /* pure virtual needs to be defined (as abort) only when put in |
1927 | vtbl. For wellformed call, it should be itself. pr4737 */ | |
8d08fdba MS |
1928 | if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl))) |
1929 | { | |
8926095f | 1930 | extern tree abort_fndecl; |
8d08fdba MS |
1931 | /* Give this node rtl from `abort'. */ |
1932 | DECL_RTL (decl) = DECL_RTL (abort_fndecl); | |
1933 | } | |
8926095f | 1934 | #endif |
8d08fdba | 1935 | DECL_ABSTRACT_VIRTUAL_P (decl) = 1; |
f0e01782 MS |
1936 | if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR]) |
1937 | { | |
1938 | tree parmtype | |
1939 | = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))); | |
1940 | ||
1941 | if (copy_assignment_arg_p (parmtype, 1)) | |
1942 | TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1; | |
1943 | } | |
8d08fdba MS |
1944 | } |
1945 | else if (TREE_CODE (init) == OFFSET_REF | |
1946 | && TREE_OPERAND (init, 0) == NULL_TREE | |
1947 | && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE) | |
1948 | { | |
1949 | tree basetype = DECL_CLASS_CONTEXT (init); | |
1950 | tree basefn = TREE_OPERAND (init, 1); | |
1951 | if (TREE_CODE (basefn) != FUNCTION_DECL) | |
1952 | cp_error ("non-method initializer invalid for method `%D'", decl); | |
1953 | else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn)))) | |
1954 | sorry ("base member function from other than first base class"); | |
1955 | else | |
1956 | { | |
1957 | tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1); | |
1958 | if (binfo == error_mark_node) | |
1959 | ; | |
1960 | else if (binfo == 0) | |
1961 | error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)), | |
1962 | TYPE_METHOD_BASETYPE (type)); | |
1963 | else | |
1964 | { | |
1965 | /* Mark this function as being defined, | |
1966 | and give it new rtl. */ | |
1967 | DECL_INITIAL (decl) = error_mark_node; | |
1968 | DECL_RTL (decl) = DECL_RTL (basefn); | |
1969 | } | |
1970 | } | |
1971 | } | |
1972 | else | |
1973 | cp_error ("invalid initializer for virtual method `%D'", decl); | |
1974 | } | |
1975 | \f | |
28cbf42c MS |
1976 | void |
1977 | cplus_decl_attributes (decl, attributes, prefix_attributes) | |
f6abb50a | 1978 | tree decl, attributes, prefix_attributes; |
8d08fdba | 1979 | { |
e8abc66f MS |
1980 | if (decl == NULL_TREE || decl == void_type_node) |
1981 | return; | |
1982 | ||
1983 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
1984 | decl = DECL_TEMPLATE_RESULT (decl); | |
1985 | ||
1986 | decl_attributes (decl, attributes, prefix_attributes); | |
863adfc0 MS |
1987 | |
1988 | if (TREE_CODE (decl) == TYPE_DECL) | |
1989 | SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl)); | |
8d08fdba MS |
1990 | } |
1991 | \f | |
1992 | /* CONSTRUCTOR_NAME: | |
1993 | Return the name for the constructor (or destructor) for the | |
1994 | specified class. Argument can be RECORD_TYPE, TYPE_DECL, or | |
1995 | IDENTIFIER_NODE. When given a template, this routine doesn't | |
1996 | lose the specialization. */ | |
e92cc029 | 1997 | |
8d08fdba MS |
1998 | tree |
1999 | constructor_name_full (thing) | |
2000 | tree thing; | |
2001 | { | |
73b0fce8 KL |
2002 | if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM |
2003 | || TREE_CODE (thing) == TEMPLATE_TEMPLATE_PARM) | |
be99da77 MS |
2004 | thing = TYPE_NAME (thing); |
2005 | else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing))) | |
8d08fdba MS |
2006 | { |
2007 | if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing)) | |
72b7eeff | 2008 | thing = DECL_NAME (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0)); |
8d08fdba MS |
2009 | else |
2010 | thing = TYPE_NAME (thing); | |
2011 | } | |
2012 | if (TREE_CODE (thing) == TYPE_DECL | |
2013 | || (TREE_CODE (thing) == TEMPLATE_DECL | |
5566b478 | 2014 | && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL)) |
8d08fdba MS |
2015 | thing = DECL_NAME (thing); |
2016 | my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197); | |
2017 | return thing; | |
2018 | } | |
2019 | ||
2020 | /* CONSTRUCTOR_NAME: | |
2021 | Return the name for the constructor (or destructor) for the | |
2022 | specified class. Argument can be RECORD_TYPE, TYPE_DECL, or | |
2023 | IDENTIFIER_NODE. When given a template, return the plain | |
2024 | unspecialized name. */ | |
e92cc029 | 2025 | |
8d08fdba MS |
2026 | tree |
2027 | constructor_name (thing) | |
2028 | tree thing; | |
2029 | { | |
2030 | tree t; | |
2031 | thing = constructor_name_full (thing); | |
2032 | t = IDENTIFIER_TEMPLATE (thing); | |
2033 | if (!t) | |
2034 | return thing; | |
5566b478 | 2035 | return t; |
8d08fdba MS |
2036 | } |
2037 | \f | |
2038 | /* Cache the value of this class's main virtual function table pointer | |
2039 | in a register variable. This will save one indirection if a | |
2040 | more than one virtual function call is made this function. */ | |
e92cc029 | 2041 | |
8d08fdba MS |
2042 | void |
2043 | setup_vtbl_ptr () | |
2044 | { | |
f30432d7 | 2045 | extern tree base_init_expr; |
8d08fdba | 2046 | |
a9aedbc2 | 2047 | if (base_init_expr == 0 |
8d08fdba | 2048 | && DECL_CONSTRUCTOR_P (current_function_decl)) |
5566b478 | 2049 | { |
5156628f | 2050 | if (processing_template_decl) |
5566b478 MS |
2051 | add_tree (build_min_nt |
2052 | (CTOR_INITIALIZER, | |
2053 | current_member_init_list, current_base_init_list)); | |
2054 | else | |
2055 | emit_base_init (current_class_type, 0); | |
2056 | } | |
8d08fdba MS |
2057 | } |
2058 | ||
2059 | /* Record the existence of an addressable inline function. */ | |
e92cc029 | 2060 | |
8d08fdba MS |
2061 | void |
2062 | mark_inline_for_output (decl) | |
2063 | tree decl; | |
2064 | { | |
6060a796 | 2065 | decl = DECL_MAIN_VARIANT (decl); |
8926095f MS |
2066 | if (DECL_SAVED_INLINE (decl)) |
2067 | return; | |
6060a796 | 2068 | my_friendly_assert (TREE_PERMANENT (decl), 363); |
8926095f | 2069 | DECL_SAVED_INLINE (decl) = 1; |
a5894242 | 2070 | #if 0 |
8d08fdba MS |
2071 | if (DECL_PENDING_INLINE_INFO (decl) != 0 |
2072 | && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu) | |
2073 | { | |
2074 | struct pending_inline *t = pending_inlines; | |
2075 | my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198); | |
2076 | while (t) | |
2077 | { | |
2078 | if (t == DECL_PENDING_INLINE_INFO (decl)) | |
2079 | break; | |
2080 | t = t->next; | |
2081 | } | |
2082 | if (t == 0) | |
2083 | { | |
2084 | t = DECL_PENDING_INLINE_INFO (decl); | |
2085 | t->next = pending_inlines; | |
2086 | pending_inlines = t; | |
2087 | } | |
2088 | DECL_PENDING_INLINE_INFO (decl) = 0; | |
2089 | } | |
a5894242 | 2090 | #endif |
8926095f | 2091 | saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines); |
8d08fdba MS |
2092 | } |
2093 | ||
2094 | void | |
2095 | clear_temp_name () | |
2096 | { | |
2097 | temp_name_counter = 0; | |
2098 | } | |
2099 | ||
2100 | /* Hand off a unique name which can be used for variable we don't really | |
2101 | want to know about anyway, for example, the anonymous variables which | |
2102 | are needed to make references work. Declare this thing so we can use it. | |
2103 | The variable created will be of type TYPE. | |
2104 | ||
2105 | STATICP is nonzero if this variable should be static. */ | |
2106 | ||
2107 | tree | |
2108 | get_temp_name (type, staticp) | |
2109 | tree type; | |
2110 | int staticp; | |
2111 | { | |
2112 | char buf[sizeof (AUTO_TEMP_FORMAT) + 20]; | |
2113 | tree decl; | |
a9aedbc2 | 2114 | int toplev = toplevel_bindings_p (); |
8d08fdba MS |
2115 | |
2116 | push_obstacks_nochange (); | |
2117 | if (toplev || staticp) | |
2118 | { | |
2119 | end_temporary_allocation (); | |
2120 | sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++); | |
2121 | decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type)); | |
2122 | } | |
2123 | else | |
2124 | { | |
2125 | sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++); | |
2126 | decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type)); | |
2127 | } | |
2128 | TREE_USED (decl) = 1; | |
2129 | TREE_STATIC (decl) = staticp; | |
fc378698 | 2130 | DECL_ARTIFICIAL (decl) = 1; |
8d08fdba MS |
2131 | |
2132 | /* If this is a local variable, then lay out its rtl now. | |
2133 | Otherwise, callers of this function are responsible for dealing | |
2134 | with this variable's rtl. */ | |
2135 | if (! toplev) | |
2136 | { | |
2137 | expand_decl (decl); | |
2138 | expand_decl_init (decl); | |
2139 | } | |
2140 | pop_obstacks (); | |
2141 | ||
2142 | return decl; | |
2143 | } | |
2144 | ||
2145 | /* Get a variable which we can use for multiple assignments. | |
2146 | It is not entered into current_binding_level, because | |
2147 | that breaks things when it comes time to do final cleanups | |
2148 | (which take place "outside" the binding contour of the function). */ | |
e92cc029 | 2149 | |
8d08fdba MS |
2150 | tree |
2151 | get_temp_regvar (type, init) | |
2152 | tree type, init; | |
2153 | { | |
8d08fdba MS |
2154 | tree decl; |
2155 | ||
a0d5fba7 | 2156 | decl = build_decl (VAR_DECL, NULL_TREE, type); |
8d08fdba MS |
2157 | TREE_USED (decl) = 1; |
2158 | DECL_REGISTER (decl) = 1; | |
a0d5fba7 | 2159 | DECL_ARTIFICIAL (decl) = 1; |
8d08fdba | 2160 | |
a0d5fba7 | 2161 | DECL_RTL (decl) = assign_temp (type, 2, 0, 1); |
8d08fdba MS |
2162 | /* We can expand these without fear, since they cannot need |
2163 | constructors or destructors. */ | |
a0d5fba7 JM |
2164 | expand_expr (build_modify_expr (decl, INIT_EXPR, init), |
2165 | NULL_RTX, VOIDmode, 0); | |
8d08fdba | 2166 | |
8d08fdba MS |
2167 | return decl; |
2168 | } | |
2169 | ||
8d08fdba MS |
2170 | /* Finish off the processing of a UNION_TYPE structure. |
2171 | If there are static members, then all members are | |
2172 | static, and must be laid out together. If the | |
2173 | union is an anonymous union, we arrange for that | |
2174 | as well. PUBLIC_P is nonzero if this union is | |
2175 | not declared static. */ | |
e92cc029 | 2176 | |
8d08fdba MS |
2177 | void |
2178 | finish_anon_union (anon_union_decl) | |
2179 | tree anon_union_decl; | |
2180 | { | |
2181 | tree type = TREE_TYPE (anon_union_decl); | |
2182 | tree field, main_decl = NULL_TREE; | |
2183 | tree elems = NULL_TREE; | |
2184 | int public_p = TREE_PUBLIC (anon_union_decl); | |
2185 | int static_p = TREE_STATIC (anon_union_decl); | |
2186 | int external_p = DECL_EXTERNAL (anon_union_decl); | |
2187 | ||
2188 | if ((field = TYPE_FIELDS (type)) == NULL_TREE) | |
2189 | return; | |
2190 | ||
2191 | if (public_p) | |
2192 | { | |
2193 | error ("global anonymous unions must be declared static"); | |
2194 | return; | |
2195 | } | |
2196 | ||
00595019 | 2197 | for (; field; field = TREE_CHAIN (field)) |
8d08fdba | 2198 | { |
00595019 MS |
2199 | tree decl; |
2200 | if (TREE_CODE (field) != FIELD_DECL) | |
2201 | continue; | |
2202 | ||
f30432d7 MS |
2203 | if (TREE_PRIVATE (field)) |
2204 | cp_pedwarn_at ("private member `%#D' in anonymous union", field); | |
2205 | else if (TREE_PROTECTED (field)) | |
2206 | cp_pedwarn_at ("protected member `%#D' in anonymous union", field); | |
2207 | ||
00595019 | 2208 | decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field)); |
8d08fdba MS |
2209 | /* tell `pushdecl' that this is not tentative. */ |
2210 | DECL_INITIAL (decl) = error_mark_node; | |
2211 | TREE_PUBLIC (decl) = public_p; | |
2212 | TREE_STATIC (decl) = static_p; | |
2213 | DECL_EXTERNAL (decl) = external_p; | |
2214 | decl = pushdecl (decl); | |
2215 | ||
2216 | /* Only write out one anon union element--choose the one that | |
2217 | can hold them all. */ | |
2218 | if (main_decl == NULL_TREE | |
f7cb6357 RK |
2219 | && 1 == simple_cst_equal (DECL_SIZE (decl), |
2220 | DECL_SIZE (anon_union_decl))) | |
8d08fdba MS |
2221 | { |
2222 | main_decl = decl; | |
2223 | } | |
2224 | else | |
2225 | { | |
2226 | /* ??? This causes there to be no debug info written out | |
2227 | about this decl. */ | |
2228 | TREE_ASM_WRITTEN (decl) = 1; | |
2229 | } | |
2230 | ||
2231 | DECL_INITIAL (decl) = NULL_TREE; | |
2232 | /* If there's a cleanup to do, it belongs in the | |
2233 | TREE_PURPOSE of the following TREE_LIST. */ | |
e66d884e | 2234 | elems = scratch_tree_cons (NULL_TREE, decl, elems); |
8d08fdba | 2235 | TREE_TYPE (elems) = type; |
8d08fdba MS |
2236 | } |
2237 | if (static_p) | |
2238 | { | |
a292b002 MS |
2239 | if (main_decl) |
2240 | { | |
a9aedbc2 | 2241 | make_decl_rtl (main_decl, 0, toplevel_bindings_p ()); |
a292b002 MS |
2242 | DECL_RTL (anon_union_decl) = DECL_RTL (main_decl); |
2243 | } | |
2244 | else | |
2245 | { | |
2246 | warning ("anonymous union with no members"); | |
2247 | return; | |
2248 | } | |
8d08fdba MS |
2249 | } |
2250 | ||
2251 | /* The following call assumes that there are never any cleanups | |
2252 | for anonymous unions--a reasonable assumption. */ | |
2253 | expand_anon_union_decl (anon_union_decl, NULL_TREE, elems); | |
8d08fdba MS |
2254 | } |
2255 | ||
2256 | /* Finish and output a table which is generated by the compiler. | |
2257 | NAME is the name to give the table. | |
2258 | TYPE is the type of the table entry. | |
2259 | INIT is all the elements in the table. | |
2260 | PUBLICP is non-zero if this table should be given external access. */ | |
e92cc029 | 2261 | |
8d08fdba MS |
2262 | tree |
2263 | finish_table (name, type, init, publicp) | |
2264 | tree name, type, init; | |
2265 | int publicp; | |
2266 | { | |
2267 | tree itype, atype, decl; | |
2268 | static tree empty_table; | |
2269 | int is_empty = 0; | |
2270 | tree asmspec; | |
2271 | ||
2272 | itype = build_index_type (size_int (list_length (init) - 1)); | |
2273 | atype = build_cplus_array_type (type, itype); | |
2274 | layout_type (atype); | |
2275 | ||
2276 | if (TREE_VALUE (init) == integer_zero_node | |
2277 | && TREE_CHAIN (init) == NULL_TREE) | |
2278 | { | |
db5ae43f | 2279 | #if 0 |
8d08fdba | 2280 | if (empty_table == NULL_TREE) |
db5ae43f | 2281 | #endif |
8d08fdba MS |
2282 | { |
2283 | empty_table = get_temp_name (atype, 1); | |
2284 | init = build (CONSTRUCTOR, atype, NULL_TREE, init); | |
2285 | TREE_CONSTANT (init) = 1; | |
2286 | TREE_STATIC (init) = 1; | |
2287 | DECL_INITIAL (empty_table) = init; | |
2288 | asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)), | |
2289 | IDENTIFIER_POINTER (DECL_NAME (empty_table))); | |
b3417a04 | 2290 | cp_finish_decl (empty_table, NULL_TREE, asmspec, 0, 0); |
8d08fdba MS |
2291 | } |
2292 | is_empty = 1; | |
2293 | } | |
2294 | ||
2295 | if (name == NULL_TREE) | |
2296 | { | |
2297 | if (is_empty) | |
2298 | return empty_table; | |
2299 | decl = get_temp_name (atype, 1); | |
2300 | } | |
2301 | else | |
2302 | { | |
2303 | decl = build_decl (VAR_DECL, name, atype); | |
2304 | decl = pushdecl (decl); | |
2305 | TREE_STATIC (decl) = 1; | |
2306 | } | |
2307 | ||
2308 | if (is_empty == 0) | |
2309 | { | |
2310 | TREE_PUBLIC (decl) = publicp; | |
2311 | init = build (CONSTRUCTOR, atype, NULL_TREE, init); | |
2312 | TREE_CONSTANT (init) = 1; | |
2313 | TREE_STATIC (init) = 1; | |
2314 | DECL_INITIAL (decl) = init; | |
2315 | asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)), | |
2316 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
2317 | } | |
2318 | else | |
2319 | { | |
2320 | /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */ | |
2321 | DECL_EXTERNAL (decl) = 1; | |
2322 | TREE_STATIC (decl) = 0; | |
2323 | init = 0; | |
2324 | asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)), | |
2325 | IDENTIFIER_POINTER (DECL_NAME (empty_table))); | |
2326 | } | |
2327 | ||
b3417a04 | 2328 | cp_finish_decl (decl, NULL_TREE, asmspec, 0, 0); |
8d08fdba MS |
2329 | return decl; |
2330 | } | |
2331 | ||
2332 | /* Finish processing a builtin type TYPE. It's name is NAME, | |
2333 | its fields are in the array FIELDS. LEN is the number of elements | |
2334 | in FIELDS minus one, or put another way, it is the maximum subscript | |
2335 | used in FIELDS. | |
2336 | ||
2337 | It is given the same alignment as ALIGN_TYPE. */ | |
e92cc029 | 2338 | |
8d08fdba MS |
2339 | void |
2340 | finish_builtin_type (type, name, fields, len, align_type) | |
2341 | tree type; | |
2342 | char *name; | |
2343 | tree fields[]; | |
2344 | int len; | |
2345 | tree align_type; | |
2346 | { | |
2347 | register int i; | |
2348 | ||
2349 | TYPE_FIELDS (type) = fields[0]; | |
2350 | for (i = 0; i < len; i++) | |
2351 | { | |
2352 | layout_type (TREE_TYPE (fields[i])); | |
2353 | DECL_FIELD_CONTEXT (fields[i]) = type; | |
2354 | TREE_CHAIN (fields[i]) = fields[i+1]; | |
2355 | } | |
2356 | DECL_FIELD_CONTEXT (fields[i]) = type; | |
2357 | DECL_CLASS_CONTEXT (fields[i]) = type; | |
2358 | TYPE_ALIGN (type) = TYPE_ALIGN (align_type); | |
2359 | layout_type (type); | |
2360 | #if 0 /* not yet, should get fixed properly later */ | |
2361 | TYPE_NAME (type) = make_type_decl (get_identifier (name), type); | |
2362 | #else | |
2363 | TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type); | |
2364 | #endif | |
d2e5ee5c | 2365 | TYPE_STUB_DECL (type) = TYPE_NAME (type); |
8d08fdba MS |
2366 | layout_decl (TYPE_NAME (type), 0); |
2367 | } | |
2368 | \f | |
2369 | /* Auxiliary functions to make type signatures for | |
2370 | `operator new' and `operator delete' correspond to | |
2371 | what compiler will be expecting. */ | |
2372 | ||
8d08fdba MS |
2373 | tree |
2374 | coerce_new_type (type) | |
2375 | tree type; | |
2376 | { | |
2377 | int e1 = 0, e2 = 0; | |
2378 | ||
2379 | if (TREE_CODE (type) == METHOD_TYPE) | |
2380 | type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type))); | |
2381 | if (TREE_TYPE (type) != ptr_type_node) | |
2382 | e1 = 1, error ("`operator new' must return type `void *'"); | |
2383 | ||
2384 | /* Technically the type must be `size_t', but we may not know | |
2385 | what that is. */ | |
2386 | if (TYPE_ARG_TYPES (type) == NULL_TREE) | |
2387 | e1 = 1, error ("`operator new' takes type `size_t' parameter"); | |
2388 | else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE | |
2389 | || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype)) | |
2390 | e2 = 1, error ("`operator new' takes type `size_t' as first parameter"); | |
2391 | if (e2) | |
2392 | type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type)))); | |
2393 | else if (e1) | |
2394 | type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type)); | |
2395 | return type; | |
2396 | } | |
2397 | ||
2398 | tree | |
2399 | coerce_delete_type (type) | |
2400 | tree type; | |
2401 | { | |
a703fb38 KG |
2402 | int e1 = 0, e2 = 0; |
2403 | #if 0 | |
2404 | e3 = 0; | |
2405 | #endif | |
8d08fdba MS |
2406 | tree arg_types = TYPE_ARG_TYPES (type); |
2407 | ||
2408 | if (TREE_CODE (type) == METHOD_TYPE) | |
2409 | { | |
2410 | type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types)); | |
2411 | arg_types = TREE_CHAIN (arg_types); | |
2412 | } | |
824b9a4c | 2413 | |
8d08fdba MS |
2414 | if (TREE_TYPE (type) != void_type_node) |
2415 | e1 = 1, error ("`operator delete' must return type `void'"); | |
824b9a4c | 2416 | |
8d08fdba MS |
2417 | if (arg_types == NULL_TREE |
2418 | || TREE_VALUE (arg_types) != ptr_type_node) | |
2419 | e2 = 1, error ("`operator delete' takes type `void *' as first parameter"); | |
2420 | ||
da4768fe | 2421 | #if 0 |
8d08fdba MS |
2422 | if (arg_types |
2423 | && TREE_CHAIN (arg_types) | |
2424 | && TREE_CHAIN (arg_types) != void_list_node) | |
2425 | { | |
2426 | /* Again, technically this argument must be `size_t', but again | |
2427 | we may not know what that is. */ | |
2428 | tree t2 = TREE_VALUE (TREE_CHAIN (arg_types)); | |
2429 | if (TREE_CODE (t2) != INTEGER_TYPE | |
2430 | || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype)) | |
2431 | e3 = 1, error ("second argument to `operator delete' must be of type `size_t'"); | |
2432 | else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node) | |
2433 | { | |
2434 | e3 = 1; | |
2435 | if (TREE_CHAIN (TREE_CHAIN (arg_types))) | |
2436 | error ("too many arguments in declaration of `operator delete'"); | |
2437 | else | |
2438 | error ("`...' invalid in specification of `operator delete'"); | |
2439 | } | |
2440 | } | |
824b9a4c | 2441 | |
8d08fdba | 2442 | if (e3) |
824b9a4c MS |
2443 | arg_types = tree_cons (NULL_TREE, ptr_type_node, |
2444 | build_tree_list (NULL_TREE, sizetype)); | |
8d08fdba MS |
2445 | else if (e3 |= e2) |
2446 | { | |
2447 | if (arg_types == NULL_TREE) | |
a28e3c7f | 2448 | arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node); |
8d08fdba MS |
2449 | else |
2450 | arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types)); | |
2451 | } | |
2452 | else e3 |= e1; | |
da4768fe | 2453 | #endif |
8d08fdba | 2454 | |
da4768fe JM |
2455 | if (e2) |
2456 | arg_types = tree_cons (NULL_TREE, ptr_type_node, | |
2457 | arg_types ? TREE_CHAIN (arg_types): NULL_TREE); | |
2458 | if (e2 || e1) | |
8d08fdba MS |
2459 | type = build_function_type (void_type_node, arg_types); |
2460 | ||
2461 | return type; | |
2462 | } | |
2463 | \f | |
72b7eeff MS |
2464 | extern tree abort_fndecl; |
2465 | ||
8d08fdba | 2466 | static void |
8926095f | 2467 | mark_vtable_entries (decl) |
8d08fdba MS |
2468 | tree decl; |
2469 | { | |
f30432d7 MS |
2470 | tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl)); |
2471 | ||
6b5fbb55 MS |
2472 | if (flag_rtti) |
2473 | { | |
2474 | tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries)) | |
2475 | : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries))); | |
2476 | tree fn = TREE_OPERAND (fnaddr, 0); | |
2477 | TREE_ADDRESSABLE (fn) = 1; | |
2478 | mark_used (fn); | |
2479 | } | |
f30432d7 | 2480 | skip_rtti_stuff (&entries); |
8d08fdba | 2481 | |
8d08fdba MS |
2482 | for (; entries; entries = TREE_CHAIN (entries)) |
2483 | { | |
72b7eeff MS |
2484 | tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries) |
2485 | : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries))); | |
8d08fdba | 2486 | tree fn = TREE_OPERAND (fnaddr, 0); |
8926095f | 2487 | TREE_ADDRESSABLE (fn) = 1; |
72b7eeff | 2488 | if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn)) |
49c249e1 JM |
2489 | { |
2490 | TREE_OPERAND (fnaddr, 0) = fn = copy_node (fn); | |
2491 | DECL_RTL (fn) = DECL_RTL (abort_fndecl); | |
7e3af374 | 2492 | mark_used (abort_fndecl); |
49c249e1 | 2493 | } |
a80e4195 MS |
2494 | if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn)) |
2495 | { | |
2496 | DECL_EXTERNAL (fn) = 0; | |
2497 | emit_thunk (fn); | |
2498 | } | |
5566b478 | 2499 | mark_used (fn); |
7177d104 MS |
2500 | } |
2501 | } | |
2502 | ||
d11ad92e MS |
2503 | /* Set DECL up to have the closest approximation of "initialized common" |
2504 | linkage available. */ | |
2505 | ||
2506 | void | |
2507 | comdat_linkage (decl) | |
2508 | tree decl; | |
2509 | { | |
d11ad92e | 2510 | if (flag_weak) |
7fcdf4c2 MS |
2511 | make_decl_one_only (decl); |
2512 | else | |
2513 | TREE_PUBLIC (decl) = 0; | |
ab23f787 JM |
2514 | |
2515 | if (DECL_LANG_SPECIFIC (decl)) | |
2516 | DECL_COMDAT (decl) = 1; | |
d11ad92e MS |
2517 | } |
2518 | ||
d18c083e | 2519 | /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL, |
7177d104 MS |
2520 | based on TYPE and other static flags. |
2521 | ||
2522 | Note that anything public is tagged TREE_PUBLIC, whether | |
2523 | it's public in this file or in another one. */ | |
2524 | ||
5b605f68 | 2525 | void |
e3417fcd MS |
2526 | import_export_vtable (decl, type, final) |
2527 | tree decl, type; | |
2528 | int final; | |
7177d104 | 2529 | { |
e3417fcd MS |
2530 | if (DECL_INTERFACE_KNOWN (decl)) |
2531 | return; | |
2532 | ||
2533 | /* +e0 or +e1 */ | |
2534 | if (write_virtuals < 2 && write_virtuals != 0) | |
7177d104 MS |
2535 | { |
2536 | TREE_PUBLIC (decl) = 1; | |
2537 | if (write_virtuals < 0) | |
2538 | DECL_EXTERNAL (decl) = 1; | |
e3417fcd MS |
2539 | DECL_INTERFACE_KNOWN (decl) = 1; |
2540 | } | |
2541 | else if (CLASSTYPE_INTERFACE_KNOWN (type)) | |
2542 | { | |
2543 | TREE_PUBLIC (decl) = 1; | |
2544 | DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type); | |
2545 | DECL_INTERFACE_KNOWN (decl) = 1; | |
eb773359 JM |
2546 | |
2547 | /* For WIN32 we also want to put explicit instantiations in | |
2548 | linkonce sections. */ | |
2549 | if (CLASSTYPE_EXPLICIT_INSTANTIATION (type) | |
2550 | && supports_one_only () && ! SUPPORTS_WEAK) | |
ab23f787 | 2551 | make_decl_one_only (decl); |
e3417fcd MS |
2552 | } |
2553 | else | |
2554 | { | |
b7484fbe MS |
2555 | /* We can only wait to decide if we have real non-inline virtual |
2556 | functions in our class, or if we come from a template. */ | |
e3417fcd MS |
2557 | |
2558 | int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type); | |
2559 | ||
1f109f0f | 2560 | #ifndef MULTIPLE_SYMBOL_SPACES |
e3417fcd MS |
2561 | if (! found && ! final) |
2562 | { | |
e3417fcd | 2563 | tree method; |
72b7eeff MS |
2564 | for (method = TYPE_METHODS (type); method != NULL_TREE; |
2565 | method = TREE_CHAIN (method)) | |
faae18ab MS |
2566 | if (DECL_VINDEX (method) != NULL_TREE |
2567 | && ! DECL_THIS_INLINE (method) | |
e3417fcd MS |
2568 | && ! DECL_ABSTRACT_VIRTUAL_P (method)) |
2569 | { | |
2570 | found = 1; | |
2571 | break; | |
2572 | } | |
2573 | } | |
1f109f0f | 2574 | #endif |
e3417fcd MS |
2575 | |
2576 | if (final || ! found) | |
2577 | { | |
d11ad92e | 2578 | comdat_linkage (decl); |
e3417fcd | 2579 | DECL_EXTERNAL (decl) = 0; |
e3417fcd MS |
2580 | } |
2581 | else | |
2582 | { | |
2583 | TREE_PUBLIC (decl) = 1; | |
2584 | DECL_EXTERNAL (decl) = 1; | |
e3417fcd | 2585 | } |
8d08fdba MS |
2586 | } |
2587 | } | |
2588 | ||
5b605f68 MS |
2589 | static void |
2590 | import_export_template (type) | |
2591 | tree type; | |
2592 | { | |
2593 | if (CLASSTYPE_IMPLICIT_INSTANTIATION (type) | |
2594 | && ! flag_implicit_templates | |
2595 | && CLASSTYPE_INTERFACE_UNKNOWN (type)) | |
2596 | { | |
2597 | SET_CLASSTYPE_INTERFACE_KNOWN (type); | |
2598 | CLASSTYPE_INTERFACE_ONLY (type) = 1; | |
2599 | CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0; | |
2600 | } | |
2601 | } | |
2602 | ||
c73964b2 | 2603 | int |
d18c083e | 2604 | finish_prevtable_vardecl (prev, vars) |
8d08fdba MS |
2605 | tree prev, vars; |
2606 | { | |
51c184be | 2607 | tree ctype = DECL_CONTEXT (vars); |
5b605f68 | 2608 | import_export_template (ctype); |
7177d104 | 2609 | |
eb448459 | 2610 | #ifndef MULTIPLE_SYMBOL_SPACES |
b7484fbe MS |
2611 | if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype) |
2612 | && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype)) | |
51c184be MS |
2613 | { |
2614 | tree method; | |
72b7eeff MS |
2615 | for (method = TYPE_METHODS (ctype); method != NULL_TREE; |
2616 | method = TREE_CHAIN (method)) | |
51c184be | 2617 | { |
28cbf42c | 2618 | if (DECL_VINDEX (method) != NULL_TREE |
faae18ab | 2619 | && !DECL_THIS_INLINE (method) |
a0a33927 | 2620 | && !DECL_ABSTRACT_VIRTUAL_P (method)) |
51c184be | 2621 | { |
8926095f | 2622 | SET_CLASSTYPE_INTERFACE_KNOWN (ctype); |
3bd1e206 JM |
2623 | CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) |
2624 | = ! DECL_REALLY_EXTERN (method); | |
2625 | CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_REALLY_EXTERN (method); | |
51c184be MS |
2626 | break; |
2627 | } | |
2628 | } | |
2629 | } | |
c11b6f21 | 2630 | #endif |
51c184be | 2631 | |
e3417fcd | 2632 | import_export_vtable (vars, ctype, 1); |
fc378698 | 2633 | return 1; |
d18c083e MS |
2634 | } |
2635 | ||
fc378698 | 2636 | static int |
d18c083e MS |
2637 | finish_vtable_vardecl (prev, vars) |
2638 | tree prev, vars; | |
2639 | { | |
d18c083e | 2640 | if (write_virtuals >= 0 |
a50f0918 | 2641 | && ! DECL_EXTERNAL (vars) |
7fcdf4c2 | 2642 | && ((TREE_PUBLIC (vars) && ! DECL_WEAK (vars) && ! DECL_ONE_ONLY (vars)) |
eb773359 | 2643 | || CLASSTYPE_EXPLICIT_INSTANTIATION (DECL_CONTEXT (vars)) |
e92cc029 MS |
2644 | || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)) |
2645 | || (hack_decl_function_context (vars) && TREE_USED (vars))) | |
fc378698 | 2646 | && ! TREE_ASM_WRITTEN (vars)) |
d18c083e | 2647 | { |
8d08fdba | 2648 | /* Write it out. */ |
8926095f | 2649 | mark_vtable_entries (vars); |
8d08fdba | 2650 | if (TREE_TYPE (DECL_INITIAL (vars)) == 0) |
b7484fbe | 2651 | store_init_value (vars, DECL_INITIAL (vars)); |
8d08fdba | 2652 | |
faf5394a | 2653 | if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG) |
8d08fdba MS |
2654 | { |
2655 | /* Mark the VAR_DECL node representing the vtable itself as a | |
2656 | "gratuitous" one, thereby forcing dwarfout.c to ignore it. | |
2657 | It is rather important that such things be ignored because | |
2658 | any effort to actually generate DWARF for them will run | |
2659 | into trouble when/if we encounter code like: | |
2660 | ||
2661 | #pragma interface | |
2662 | struct S { virtual void member (); }; | |
2663 | ||
2664 | because the artificial declaration of the vtable itself (as | |
2665 | manufactured by the g++ front end) will say that the vtable | |
2666 | is a static member of `S' but only *after* the debug output | |
2667 | for the definition of `S' has already been output. This causes | |
2668 | grief because the DWARF entry for the definition of the vtable | |
2669 | will try to refer back to an earlier *declaration* of the | |
2670 | vtable as a static member of `S' and there won't be one. | |
2671 | We might be able to arrange to have the "vtable static member" | |
2672 | attached to the member list for `S' before the debug info for | |
2673 | `S' get written (which would solve the problem) but that would | |
2674 | require more intrusive changes to the g++ front end. */ | |
2675 | ||
2676 | DECL_IGNORED_P (vars) = 1; | |
2677 | } | |
8d08fdba | 2678 | |
311862c8 | 2679 | rest_of_decl_compilation (vars, NULL_PTR, 1, 1); |
fc378698 | 2680 | return 1; |
8d08fdba | 2681 | } |
a50f0918 | 2682 | else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))) |
b7484fbe | 2683 | /* We don't know what to do with this one yet. */ |
fc378698 | 2684 | return 0; |
b7484fbe MS |
2685 | |
2686 | /* We know that PREV must be non-zero here. */ | |
2687 | TREE_CHAIN (prev) = TREE_CHAIN (vars); | |
fc378698 | 2688 | return 0; |
b7484fbe MS |
2689 | } |
2690 | ||
fc378698 | 2691 | static int |
b7484fbe MS |
2692 | prune_vtable_vardecl (prev, vars) |
2693 | tree prev, vars; | |
2694 | { | |
8d08fdba MS |
2695 | /* We know that PREV must be non-zero here. */ |
2696 | TREE_CHAIN (prev) = TREE_CHAIN (vars); | |
fc378698 | 2697 | return 1; |
8d08fdba MS |
2698 | } |
2699 | ||
fc378698 | 2700 | int |
8d08fdba | 2701 | walk_vtables (typedecl_fn, vardecl_fn) |
49c249e1 JM |
2702 | register void (*typedecl_fn) PROTO ((tree, tree)); |
2703 | register int (*vardecl_fn) PROTO ((tree, tree)); | |
8d08fdba MS |
2704 | { |
2705 | tree prev, vars; | |
fc378698 | 2706 | int flag = 0; |
8d08fdba MS |
2707 | |
2708 | for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars)) | |
2709 | { | |
2710 | register tree type = TREE_TYPE (vars); | |
2711 | ||
28cbf42c | 2712 | if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars)) |
8d08fdba | 2713 | { |
fc378698 MS |
2714 | if (vardecl_fn) |
2715 | flag |= (*vardecl_fn) (prev, vars); | |
28cbf42c MS |
2716 | |
2717 | if (prev && TREE_CHAIN (prev) != vars) | |
2718 | continue; | |
8d08fdba | 2719 | } |
28cbf42c MS |
2720 | else if (TREE_CODE (vars) == TYPE_DECL |
2721 | && type != error_mark_node | |
2722 | && TYPE_LANG_SPECIFIC (type) | |
2723 | && CLASSTYPE_VSIZE (type)) | |
8d08fdba | 2724 | { |
28cbf42c | 2725 | if (typedecl_fn) (*typedecl_fn) (prev, vars); |
8d08fdba | 2726 | } |
28cbf42c MS |
2727 | |
2728 | prev = vars; | |
8d08fdba | 2729 | } |
fc378698 MS |
2730 | |
2731 | return flag; | |
8d08fdba MS |
2732 | } |
2733 | ||
311862c8 GB |
2734 | static void |
2735 | finish_sigtable_vardecl (prev, vars) | |
2736 | tree prev, vars; | |
2737 | { | |
2738 | /* We don't need to mark sigtable entries as addressable here as is done | |
2739 | for vtables. Since sigtables, unlike vtables, are always written out, | |
2740 | that was already done in build_signature_table_constructor. */ | |
2741 | ||
2742 | rest_of_decl_compilation (vars, NULL_PTR, 1, 1); | |
2743 | ||
2744 | /* We know that PREV must be non-zero here. */ | |
2745 | TREE_CHAIN (prev) = TREE_CHAIN (vars); | |
2746 | } | |
2747 | ||
2748 | void | |
2749 | walk_sigtables (typedecl_fn, vardecl_fn) | |
49c249e1 JM |
2750 | register void (*typedecl_fn) PROTO((tree, tree)); |
2751 | register void (*vardecl_fn) PROTO((tree, tree)); | |
311862c8 GB |
2752 | { |
2753 | tree prev, vars; | |
2754 | ||
2755 | for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars)) | |
2756 | { | |
2757 | register tree type = TREE_TYPE (vars); | |
2758 | ||
2759 | if (TREE_CODE (vars) == TYPE_DECL | |
2760 | && type != error_mark_node | |
2761 | && IS_SIGNATURE (type)) | |
2762 | { | |
2763 | if (typedecl_fn) (*typedecl_fn) (prev, vars); | |
2764 | } | |
2765 | else if (TREE_CODE (vars) == VAR_DECL | |
2766 | && TREE_TYPE (vars) != error_mark_node | |
2767 | && IS_SIGNATURE (TREE_TYPE (vars))) | |
2768 | { | |
2769 | if (vardecl_fn) (*vardecl_fn) (prev, vars); | |
2770 | } | |
2771 | else | |
2772 | prev = vars; | |
2773 | } | |
2774 | } | |
2775 | ||
00595019 | 2776 | /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an |
5566b478 | 2777 | inline function or template instantiation at end-of-file. */ |
00595019 MS |
2778 | |
2779 | void | |
5566b478 | 2780 | import_export_decl (decl) |
00595019 MS |
2781 | tree decl; |
2782 | { | |
db5ae43f | 2783 | if (DECL_INTERFACE_KNOWN (decl)) |
00595019 MS |
2784 | return; |
2785 | ||
db5ae43f | 2786 | if (DECL_TEMPLATE_INSTANTIATION (decl)) |
00595019 | 2787 | { |
5566b478 | 2788 | DECL_NOT_REALLY_EXTERN (decl) = 1; |
e92cc029 MS |
2789 | if (DECL_IMPLICIT_INSTANTIATION (decl) |
2790 | && (flag_implicit_templates || DECL_THIS_INLINE (decl))) | |
a9aedbc2 | 2791 | { |
75650646 MM |
2792 | if (!TREE_PUBLIC (decl)) |
2793 | /* Templates are allowed to have internal linkage. See | |
2794 | [basic.link]. */ | |
2795 | ; | |
2796 | else if (TREE_CODE (decl) == FUNCTION_DECL) | |
d11ad92e | 2797 | comdat_linkage (decl); |
d11ad92e | 2798 | else |
77be6f82 | 2799 | DECL_COMDAT (decl) = 1; |
a9aedbc2 | 2800 | } |
db5ae43f | 2801 | else |
faae18ab | 2802 | DECL_NOT_REALLY_EXTERN (decl) = 0; |
00595019 MS |
2803 | } |
2804 | else if (DECL_FUNCTION_MEMBER_P (decl)) | |
2805 | { | |
2806 | tree ctype = DECL_CLASS_CONTEXT (decl); | |
047f64a3 JM |
2807 | if (CLASSTYPE_INTERFACE_KNOWN (ctype) |
2808 | && (! DECL_ARTIFICIAL (decl) || DECL_VINDEX (decl))) | |
00595019 | 2809 | { |
faae18ab MS |
2810 | DECL_NOT_REALLY_EXTERN (decl) |
2811 | = ! (CLASSTYPE_INTERFACE_ONLY (ctype) | |
2812 | || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines)); | |
00595019 | 2813 | } |
db5ae43f | 2814 | else |
d11ad92e | 2815 | comdat_linkage (decl); |
00595019 | 2816 | } |
6b5fbb55 MS |
2817 | /* tinfo function */ |
2818 | else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl)) | |
2819 | { | |
2820 | tree ctype = TREE_TYPE (DECL_NAME (decl)); | |
d11ad92e MS |
2821 | if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype) |
2822 | && TYPE_VIRTUAL_P (ctype)) | |
6b5fbb55 MS |
2823 | { |
2824 | DECL_NOT_REALLY_EXTERN (decl) | |
2825 | = ! (CLASSTYPE_INTERFACE_ONLY (ctype) | |
2826 | || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines)); | |
eb773359 JM |
2827 | |
2828 | /* For WIN32 we also want to put explicit instantiations in | |
2829 | linkonce sections. */ | |
2830 | if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype) | |
2831 | && supports_one_only () && ! SUPPORTS_WEAK) | |
ab23f787 | 2832 | make_decl_one_only (decl); |
6b5fbb55 MS |
2833 | } |
2834 | else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype)) | |
2835 | DECL_NOT_REALLY_EXTERN (decl) = 0; | |
6b5fbb55 | 2836 | else |
d11ad92e | 2837 | comdat_linkage (decl); |
6b5fbb55 | 2838 | } |
db5ae43f | 2839 | else |
d11ad92e | 2840 | comdat_linkage (decl); |
e8abc66f MS |
2841 | |
2842 | DECL_INTERFACE_KNOWN (decl) = 1; | |
00595019 | 2843 | } |
db5ae43f | 2844 | |
72b7eeff MS |
2845 | tree |
2846 | build_cleanup (decl) | |
2847 | tree decl; | |
2848 | { | |
2849 | tree temp; | |
2850 | tree type = TREE_TYPE (decl); | |
2851 | ||
2852 | if (TREE_CODE (type) == ARRAY_TYPE) | |
2853 | temp = decl; | |
2854 | else | |
2855 | { | |
2856 | mark_addressable (decl); | |
2857 | temp = build1 (ADDR_EXPR, build_pointer_type (type), decl); | |
2858 | } | |
2859 | temp = build_delete (TREE_TYPE (temp), temp, | |
2860 | integer_two_node, | |
2861 | LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); | |
2862 | return temp; | |
2863 | } | |
2864 | ||
8d08fdba | 2865 | extern int parse_time, varconst_time; |
5566b478 | 2866 | extern tree pending_templates; |
73aad9b9 | 2867 | extern tree maybe_templates; |
8d08fdba | 2868 | |
67d743fe | 2869 | extern struct obstack permanent_obstack; |
67d743fe | 2870 | |
824b9a4c | 2871 | static tree |
67d743fe MS |
2872 | get_sentry (base) |
2873 | tree base; | |
2874 | { | |
2875 | tree sname = get_id_2 ("__sn", base); | |
2876 | tree sentry = IDENTIFIER_GLOBAL_VALUE (sname); | |
2877 | if (! sentry) | |
2878 | { | |
2879 | push_obstacks (&permanent_obstack, &permanent_obstack); | |
2880 | sentry = build_decl (VAR_DECL, sname, integer_type_node); | |
2881 | TREE_PUBLIC (sentry) = 1; | |
2882 | DECL_ARTIFICIAL (sentry) = 1; | |
2883 | TREE_STATIC (sentry) = 1; | |
2884 | TREE_USED (sentry) = 1; | |
2885 | DECL_COMMON (sentry) = 1; | |
2886 | pushdecl_top_level (sentry); | |
2887 | cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0); | |
2888 | pop_obstacks (); | |
2889 | } | |
2890 | return sentry; | |
2891 | } | |
2892 | ||
8d08fdba MS |
2893 | /* This routine is called from the last rule in yyparse (). |
2894 | Its job is to create all the code needed to initialize and | |
2895 | destroy the global aggregates. We do the destruction | |
2896 | first, since that way we only need to reverse the decls once. */ | |
2897 | ||
2898 | void | |
2899 | finish_file () | |
2900 | { | |
2901 | extern int lineno; | |
2902 | int start_time, this_time; | |
2903 | ||
2904 | tree fnname; | |
44a8d0b3 | 2905 | tree vars; |
8d08fdba | 2906 | int needs_cleaning = 0, needs_messing_up = 0; |
8d2733ca | 2907 | |
5566b478 MS |
2908 | at_eof = 1; |
2909 | ||
8d08fdba MS |
2910 | /* Bad parse errors. Just forget about it. */ |
2911 | if (! global_bindings_p () || current_class_type) | |
2912 | return; | |
2913 | ||
2914 | start_time = get_run_time (); | |
2915 | ||
8d08fdba MS |
2916 | /* Otherwise, GDB can get confused, because in only knows |
2917 | about source for LINENO-1 lines. */ | |
2918 | lineno -= 1; | |
2919 | ||
d18c083e MS |
2920 | interface_unknown = 1; |
2921 | interface_only = 0; | |
2922 | ||
909e536a MS |
2923 | for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname)) |
2924 | { | |
2925 | tree decl = TREE_VALUE (fnname); | |
e92cc029 MS |
2926 | if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't') |
2927 | { | |
2928 | instantiate_class_template (decl); | |
2929 | if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl)) | |
2930 | for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars)) | |
9a3b49ac MS |
2931 | if (! DECL_ARTIFICIAL (vars)) |
2932 | instantiate_decl (vars); | |
e92cc029 MS |
2933 | } |
2934 | else | |
2935 | instantiate_decl (decl); | |
909e536a MS |
2936 | } |
2937 | ||
73aad9b9 JM |
2938 | for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname)) |
2939 | { | |
98c1c668 | 2940 | tree args, fn, decl = TREE_VALUE (fnname); |
73aad9b9 JM |
2941 | |
2942 | if (DECL_INITIAL (decl)) | |
2943 | continue; | |
2944 | ||
2945 | fn = TREE_PURPOSE (fnname); | |
e1467ff2 | 2946 | args = get_bindings (fn, decl, NULL_TREE); |
73aad9b9 | 2947 | fn = instantiate_template (fn, args); |
73aad9b9 JM |
2948 | instantiate_decl (fn); |
2949 | } | |
2950 | ||
909e536a MS |
2951 | /* Push into C language context, because that's all |
2952 | we'll need here. */ | |
2953 | push_lang_context (lang_name_c); | |
2954 | ||
28cbf42c MS |
2955 | #if 1 |
2956 | /* The reason for pushing garbage onto the global_binding_level is to | |
2957 | ensure that we can slice out _DECLs which pertain to virtual function | |
2958 | tables. If the last thing pushed onto the global_binding_level was a | |
2959 | virtual function table, then slicing it out would slice away all the | |
2960 | decls (i.e., we lose the head of the chain). | |
2961 | ||
2962 | There are several ways of getting the same effect, from changing the | |
2963 | way that iterators over the chain treat the elements that pertain to | |
2964 | virtual function tables, moving the implementation of this code to | |
2965 | decl.c (where we can manipulate global_binding_level directly), | |
2966 | popping the garbage after pushing it and slicing away the vtable | |
e92cc029 | 2967 | stuff, or just leaving it alone. */ |
28cbf42c MS |
2968 | |
2969 | /* Make last thing in global scope not be a virtual function table. */ | |
2970 | #if 0 /* not yet, should get fixed properly later */ | |
2971 | vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node); | |
2972 | #else | |
2973 | vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node); | |
2974 | #endif | |
2975 | DECL_IGNORED_P (vars) = 1; | |
2976 | SET_DECL_ARTIFICIAL (vars); | |
2977 | pushdecl (vars); | |
2978 | #endif | |
2979 | ||
d18c083e | 2980 | /* Walk to mark the inline functions we need, then output them so |
e92cc029 | 2981 | that we can pick up any other tdecls that those routines need. */ |
49c249e1 JM |
2982 | walk_vtables ((void (*) PROTO ((tree, tree))) 0, |
2983 | finish_prevtable_vardecl); | |
d18c083e | 2984 | |
c11b6f21 MS |
2985 | for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars)) |
2986 | if (! TREE_ASM_WRITTEN (TREE_VALUE (vars))) | |
2987 | rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1); | |
44a8d0b3 MS |
2988 | vars = static_aggregates; |
2989 | ||
02531345 | 2990 | if (static_ctors || vars) |
44a8d0b3 MS |
2991 | needs_messing_up = 1; |
2992 | if (static_dtors) | |
2993 | needs_cleaning = 1; | |
2994 | ||
2995 | /* See if we really need the hassle. */ | |
2996 | while (vars && needs_cleaning == 0) | |
2997 | { | |
2998 | tree decl = TREE_VALUE (vars); | |
2999 | tree type = TREE_TYPE (decl); | |
72b7eeff | 3000 | if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)) |
44a8d0b3 MS |
3001 | { |
3002 | needs_cleaning = 1; | |
44a8d0b3 MS |
3003 | break; |
3004 | } | |
72b7eeff | 3005 | |
44a8d0b3 MS |
3006 | vars = TREE_CHAIN (vars); |
3007 | } | |
3008 | ||
d18c083e MS |
3009 | if (needs_cleaning == 0) |
3010 | goto mess_up; | |
3011 | ||
8d08fdba | 3012 | fnname = get_file_function_name ('D'); |
f30432d7 | 3013 | start_function (void_list_node, |
c11b6f21 MS |
3014 | make_call_declarator (fnname, void_list_node, NULL_TREE, |
3015 | NULL_TREE), | |
3016 | NULL_TREE, 0); | |
8d08fdba MS |
3017 | fnname = DECL_ASSEMBLER_NAME (current_function_decl); |
3018 | store_parm_decls (); | |
3019 | ||
3020 | pushlevel (0); | |
3021 | clear_last_expr (); | |
3022 | push_momentary (); | |
3023 | expand_start_bindings (0); | |
3024 | ||
3025 | /* These must be done in backward order to destroy, | |
3026 | in which they happen to be! */ | |
1038f4f9 | 3027 | for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars)) |
8d08fdba MS |
3028 | { |
3029 | tree decl = TREE_VALUE (vars); | |
3030 | tree type = TREE_TYPE (decl); | |
3031 | tree temp = TREE_PURPOSE (vars); | |
3032 | ||
67d743fe MS |
3033 | if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars) |
3034 | && ! DECL_EXTERNAL (decl)) | |
8d08fdba | 3035 | { |
809c8c30 | 3036 | int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl) |
809c8c30 | 3037 | || DECL_ONE_ONLY (decl) |
809c8c30 JM |
3038 | || DECL_WEAK (decl))); |
3039 | ||
72b7eeff | 3040 | temp = build_cleanup (decl); |
67d743fe | 3041 | |
809c8c30 | 3042 | if (protect) |
67d743fe MS |
3043 | { |
3044 | tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl)); | |
3045 | sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0); | |
3046 | sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1); | |
3047 | expand_start_cond (sentry, 0); | |
3048 | } | |
3049 | ||
8d08fdba | 3050 | expand_expr_stmt (temp); |
67d743fe | 3051 | |
809c8c30 | 3052 | if (protect) |
67d743fe | 3053 | expand_end_cond (); |
8d08fdba | 3054 | } |
8d08fdba MS |
3055 | } |
3056 | ||
e1cd6e56 MS |
3057 | for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors)) |
3058 | expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors), | |
3059 | NULL_TREE)); | |
3060 | ||
fc378698 | 3061 | expand_end_bindings (getdecls (), 1, 0); |
8d08fdba MS |
3062 | poplevel (1, 0, 0); |
3063 | pop_momentary (); | |
3064 | ||
db5ae43f | 3065 | finish_function (lineno, 0, 0); |
8d08fdba MS |
3066 | |
3067 | assemble_destructor (IDENTIFIER_POINTER (fnname)); | |
3068 | ||
3069 | /* if it needed cleaning, then it will need messing up: drop through */ | |
3070 | ||
3071 | mess_up: | |
3072 | /* Must do this while we think we are at the top level. */ | |
3073 | vars = nreverse (static_aggregates); | |
e1cd6e56 | 3074 | if (needs_messing_up) |
8d08fdba MS |
3075 | { |
3076 | fnname = get_file_function_name ('I'); | |
f30432d7 | 3077 | start_function (void_list_node, |
c11b6f21 MS |
3078 | make_call_declarator (fnname, void_list_node, NULL_TREE, |
3079 | NULL_TREE), | |
3080 | NULL_TREE, 0); | |
8d08fdba MS |
3081 | fnname = DECL_ASSEMBLER_NAME (current_function_decl); |
3082 | store_parm_decls (); | |
3083 | ||
3084 | pushlevel (0); | |
3085 | clear_last_expr (); | |
3086 | push_momentary (); | |
3087 | expand_start_bindings (0); | |
3088 | ||
3089 | while (vars) | |
3090 | { | |
3091 | tree decl = TREE_VALUE (vars); | |
3092 | tree init = TREE_PURPOSE (vars); | |
3093 | ||
3094 | /* If this was a static attribute within some function's scope, | |
3095 | then don't initialize it here. Also, don't bother | |
3096 | with initializers that contain errors. */ | |
3097 | if (TREE_STATIC (vars) | |
67d743fe | 3098 | || DECL_EXTERNAL (decl) |
8d08fdba MS |
3099 | || (init && TREE_CODE (init) == TREE_LIST |
3100 | && value_member (error_mark_node, init))) | |
7303f45c | 3101 | goto next_mess; |
8d08fdba MS |
3102 | |
3103 | if (TREE_CODE (decl) == VAR_DECL) | |
3104 | { | |
eb66be0e MS |
3105 | int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl) |
3106 | || DECL_ONE_ONLY (decl) | |
3107 | || DECL_WEAK (decl))); | |
809c8c30 | 3108 | |
8d08fdba MS |
3109 | /* Set these global variables so that GDB at least puts |
3110 | us near the declaration which required the initialization. */ | |
3111 | input_filename = DECL_SOURCE_FILE (decl); | |
3112 | lineno = DECL_SOURCE_LINE (decl); | |
3113 | emit_note (input_filename, lineno); | |
3114 | ||
7177d104 | 3115 | /* 9.5p5: The initializer of a static member of a class has |
ddd5a7c1 | 3116 | the same access rights as a member function. */ |
7177d104 | 3117 | DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl); |
b7484fbe | 3118 | DECL_STATIC_FUNCTION_P (current_function_decl) = 1; |
7177d104 | 3119 | |
809c8c30 | 3120 | if (protect) |
67d743fe MS |
3121 | { |
3122 | tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl)); | |
3123 | sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0); | |
3124 | sentry = build_binary_op | |
3125 | (EQ_EXPR, sentry, integer_one_node, 1); | |
3126 | expand_start_cond (sentry, 0); | |
3127 | } | |
3128 | ||
eb66be0e MS |
3129 | expand_start_target_temps (); |
3130 | ||
8d08fdba | 3131 | if (IS_AGGR_TYPE (TREE_TYPE (decl)) |
8d08fdba | 3132 | || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) |
6060a796 | 3133 | expand_aggr_init (decl, init, 0, 0); |
8d08fdba MS |
3134 | else if (TREE_CODE (init) == TREE_VEC) |
3135 | { | |
3136 | expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0), | |
3137 | TREE_VEC_ELT (init, 1), | |
3138 | TREE_VEC_ELT (init, 2), 0), | |
9f617717 | 3139 | const0_rtx, VOIDmode, EXPAND_NORMAL); |
8d08fdba MS |
3140 | } |
3141 | else | |
3142 | expand_assignment (decl, init, 0, 0); | |
7177d104 | 3143 | |
eb66be0e MS |
3144 | /* Cleanup any temporaries needed for the initial value. */ |
3145 | expand_end_target_temps (); | |
3146 | ||
809c8c30 | 3147 | if (protect) |
67d743fe MS |
3148 | expand_end_cond (); |
3149 | ||
7177d104 | 3150 | DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE; |
e76a2646 | 3151 | DECL_STATIC_FUNCTION_P (current_function_decl) = 0; |
8d08fdba | 3152 | } |
8d08fdba MS |
3153 | else if (decl == error_mark_node) |
3154 | ; | |
3155 | else my_friendly_abort (22); | |
72b7eeff | 3156 | |
67d743fe | 3157 | next_mess: |
72b7eeff | 3158 | vars = TREE_CHAIN (vars); |
8d08fdba MS |
3159 | } |
3160 | ||
e1cd6e56 MS |
3161 | for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors)) |
3162 | expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors), | |
3163 | NULL_TREE)); | |
3164 | ||
fc378698 | 3165 | expand_end_bindings (getdecls (), 1, 0); |
8d08fdba MS |
3166 | poplevel (1, 0, 0); |
3167 | pop_momentary (); | |
3168 | ||
db5ae43f | 3169 | finish_function (lineno, 0, 0); |
8d08fdba MS |
3170 | assemble_constructor (IDENTIFIER_POINTER (fnname)); |
3171 | } | |
3172 | ||
faae18ab MS |
3173 | permanent_allocation (1); |
3174 | ||
8d08fdba MS |
3175 | /* Done with C language context needs. */ |
3176 | pop_lang_context (); | |
3177 | ||
3178 | /* Now write out any static class variables (which may have since | |
3179 | learned how to be initialized). */ | |
3180 | while (pending_statics) | |
3181 | { | |
3182 | tree decl = TREE_VALUE (pending_statics); | |
5566b478 | 3183 | |
d2e5ee5c MS |
3184 | /* Output DWARF debug information. */ |
3185 | #ifdef DWARF_DEBUGGING_INFO | |
3186 | if (write_symbols == DWARF_DEBUG) | |
3187 | dwarfout_file_scope_decl (decl, 1); | |
3188 | #endif | |
3189 | #ifdef DWARF2_DEBUGGING_INFO | |
3190 | if (write_symbols == DWARF2_DEBUG) | |
3191 | dwarf2out_decl (decl); | |
3192 | #endif | |
3193 | ||
3194 | DECL_DEFER_OUTPUT (decl) = 0; | |
3195 | rest_of_decl_compilation | |
3196 | (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1); | |
3197 | ||
8d08fdba MS |
3198 | pending_statics = TREE_CHAIN (pending_statics); |
3199 | } | |
3200 | ||
3201 | this_time = get_run_time (); | |
3202 | parse_time -= this_time - start_time; | |
3203 | varconst_time += this_time - start_time; | |
3204 | ||
8d08fdba MS |
3205 | start_time = get_run_time (); |
3206 | ||
5b605f68 | 3207 | if (flag_handle_signatures) |
49c249e1 JM |
3208 | walk_sigtables ((void (*) PROTO ((tree, tree))) 0, |
3209 | finish_sigtable_vardecl); | |
8926095f | 3210 | |
28cbf42c | 3211 | for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname)) |
fd378c9d JM |
3212 | { |
3213 | tree decl = TREE_VALUE (fnname); | |
5566b478 | 3214 | import_export_decl (decl); |
fd378c9d | 3215 | } |
28cbf42c | 3216 | |
db5ae43f MS |
3217 | /* Now write out inline functions which had their addresses taken and |
3218 | which were not declared virtual and which were not declared `extern | |
3219 | inline'. */ | |
9a0e77ba | 3220 | { |
db5ae43f | 3221 | int reconsider = 1; /* More may be referenced; check again */ |
9a0e77ba | 3222 | |
db5ae43f | 3223 | while (reconsider) |
9a0e77ba | 3224 | { |
21451173 | 3225 | tree *p = &saved_inlines; |
db5ae43f MS |
3226 | reconsider = 0; |
3227 | ||
e76a2646 MS |
3228 | /* We need to do this each time so that newly completed template |
3229 | types don't wind up at the front of the list. Sigh. */ | |
3230 | vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node); | |
3231 | DECL_IGNORED_P (vars) = 1; | |
3232 | SET_DECL_ARTIFICIAL (vars); | |
3233 | pushdecl (vars); | |
3234 | ||
49c249e1 JM |
3235 | reconsider |= walk_vtables ((void (*) PROTO((tree, tree))) 0, |
3236 | finish_vtable_vardecl); | |
b7484fbe | 3237 | |
21451173 | 3238 | while (*p) |
9a0e77ba | 3239 | { |
21451173 | 3240 | tree decl = TREE_VALUE (*p); |
db5ae43f | 3241 | |
21451173 | 3242 | if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl) |
6b5fbb55 MS |
3243 | && TREE_USED (decl) |
3244 | && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl))) | |
e8abc66f | 3245 | { |
6b5fbb55 MS |
3246 | if (DECL_MUTABLE_P (decl)) |
3247 | synthesize_tinfo_fn (decl); | |
3248 | else | |
3249 | synthesize_method (decl); | |
21451173 | 3250 | reconsider = 1; |
e8abc66f MS |
3251 | } |
3252 | ||
a50f0918 | 3253 | /* Catch new template instantiations. */ |
6b5fbb55 | 3254 | if (decl != TREE_VALUE (*p)) |
a50f0918 | 3255 | continue; |
b7484fbe | 3256 | |
a50f0918 MS |
3257 | if (TREE_ASM_WRITTEN (decl) |
3258 | || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl))) | |
21451173 | 3259 | *p = TREE_CHAIN (*p); |
a50f0918 MS |
3260 | else if (DECL_INITIAL (decl) == 0) |
3261 | p = &TREE_CHAIN (*p); | |
ab23f787 | 3262 | else if ((TREE_PUBLIC (decl) && ! DECL_COMDAT (decl)) |
21451173 MS |
3263 | || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) |
3264 | || flag_keep_inline_functions) | |
3265 | { | |
faae18ab | 3266 | if (DECL_NOT_REALLY_EXTERN (decl)) |
9a0e77ba | 3267 | { |
faae18ab | 3268 | DECL_EXTERNAL (decl) = 0; |
db5ae43f | 3269 | reconsider = 1; |
bd871063 JM |
3270 | /* We can't inline this function after it's been |
3271 | emitted. We want a variant of | |
3272 | output_inline_function that doesn't prevent | |
3273 | subsequent integration... */ | |
3274 | DECL_INLINE (decl) = 0; | |
db5ae43f MS |
3275 | output_inline_function (decl); |
3276 | permanent_allocation (1); | |
9a0e77ba | 3277 | } |
db5ae43f | 3278 | |
21451173 | 3279 | *p = TREE_CHAIN (*p); |
9a0e77ba | 3280 | } |
21451173 MS |
3281 | else |
3282 | p = &TREE_CHAIN (*p); | |
9a0e77ba JM |
3283 | } |
3284 | } | |
3285 | } | |
8d08fdba | 3286 | |
28cbf42c MS |
3287 | /* Now delete from the chain of variables all virtual function tables. |
3288 | We output them all ourselves, because each will be treated specially. */ | |
3289 | ||
49c249e1 JM |
3290 | walk_vtables ((void (*) PROTO((tree, tree))) 0, |
3291 | prune_vtable_vardecl); | |
b7484fbe | 3292 | |
8d08fdba MS |
3293 | if (write_virtuals == 2) |
3294 | { | |
3295 | /* Now complain about an virtual function tables promised | |
3296 | but not delivered. */ | |
3297 | while (pending_vtables) | |
3298 | { | |
3299 | if (TREE_PURPOSE (pending_vtables) == NULL_TREE) | |
3300 | error ("virtual function table for `%s' not defined", | |
3301 | IDENTIFIER_POINTER (TREE_VALUE (pending_vtables))); | |
3302 | pending_vtables = TREE_CHAIN (pending_vtables); | |
3303 | } | |
3304 | } | |
3305 | ||
faae18ab MS |
3306 | finish_repo (); |
3307 | ||
8d08fdba MS |
3308 | this_time = get_run_time (); |
3309 | parse_time -= this_time - start_time; | |
3310 | varconst_time += this_time - start_time; | |
3311 | ||
3312 | if (flag_detailed_statistics) | |
27bb8339 JM |
3313 | { |
3314 | dump_tree_statistics (); | |
3315 | dump_time_statistics (); | |
3316 | } | |
8d08fdba | 3317 | } |
51c184be MS |
3318 | |
3319 | /* This is something of the form 'A()()()()()+1' that has turned out to be an | |
3320 | expr. Since it was parsed like a type, we need to wade through and fix | |
3321 | that. Unfortunately, since operator() is left-associative, we can't use | |
3322 | tail recursion. In the above example, TYPE is `A', and DECL is | |
3323 | `()()()()()'. | |
3324 | ||
3325 | Maybe this shouldn't be recursive, but how often will it actually be | |
3326 | used? (jason) */ | |
e92cc029 | 3327 | |
51c184be MS |
3328 | tree |
3329 | reparse_absdcl_as_expr (type, decl) | |
3330 | tree type, decl; | |
3331 | { | |
3332 | /* do build_functional_cast (type, NULL_TREE) at bottom */ | |
3333 | if (TREE_OPERAND (decl, 0) == NULL_TREE) | |
3334 | return build_functional_cast (type, NULL_TREE); | |
3335 | ||
3336 | /* recurse */ | |
3337 | decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0)); | |
3338 | ||
4ac14744 | 3339 | decl = build_x_function_call (decl, NULL_TREE, current_class_ref); |
51c184be MS |
3340 | |
3341 | if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node) | |
3342 | decl = require_complete_type (decl); | |
3343 | ||
3344 | return decl; | |
3345 | } | |
3346 | ||
3347 | /* This is something of the form `int ((int)(int)(int)1)' that has turned | |
3348 | out to be an expr. Since it was parsed like a type, we need to wade | |
3349 | through and fix that. Since casts are right-associative, we are | |
3350 | reversing the order, so we don't have to recurse. | |
3351 | ||
3352 | In the above example, DECL is the `(int)(int)(int)', and EXPR is the | |
3353 | `1'. */ | |
e92cc029 | 3354 | |
51c184be MS |
3355 | tree |
3356 | reparse_absdcl_as_casts (decl, expr) | |
3357 | tree decl, expr; | |
3358 | { | |
3359 | tree type; | |
3360 | ||
4ac14744 MS |
3361 | if (TREE_CODE (expr) == CONSTRUCTOR |
3362 | && TREE_TYPE (expr) == 0) | |
51c184be MS |
3363 | { |
3364 | type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1))); | |
3365 | decl = TREE_OPERAND (decl, 0); | |
3366 | ||
3367 | if (IS_SIGNATURE (type)) | |
3368 | { | |
3369 | error ("cast specifies signature type"); | |
3370 | return error_mark_node; | |
3371 | } | |
3372 | ||
3373 | expr = digest_init (type, expr, (tree *) 0); | |
3374 | if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0) | |
3375 | { | |
3376 | int failure = complete_array_type (type, expr, 1); | |
3377 | if (failure) | |
3378 | my_friendly_abort (78); | |
3379 | } | |
3380 | } | |
3381 | ||
3382 | while (decl) | |
3383 | { | |
3384 | type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1))); | |
3385 | decl = TREE_OPERAND (decl, 0); | |
faf5394a | 3386 | expr = build_c_cast (type, expr); |
51c184be MS |
3387 | } |
3388 | ||
0c4b14c4 JM |
3389 | if (warn_old_style_cast) |
3390 | warning ("use of old-style cast"); | |
3391 | ||
51c184be MS |
3392 | return expr; |
3393 | } | |
3394 | ||
e92cc029 | 3395 | /* Given plain tree nodes for an expression, build up the full semantics. */ |
5566b478 MS |
3396 | |
3397 | tree | |
3398 | build_expr_from_tree (t) | |
3399 | tree t; | |
51c184be | 3400 | { |
5566b478 MS |
3401 | if (t == NULL_TREE || t == error_mark_node) |
3402 | return t; | |
3403 | ||
3404 | switch (TREE_CODE (t)) | |
51c184be MS |
3405 | { |
3406 | case IDENTIFIER_NODE: | |
5566b478 MS |
3407 | return do_identifier (t, 0); |
3408 | ||
3409 | case LOOKUP_EXPR: | |
3410 | if (LOOKUP_EXPR_GLOBAL (t)) | |
3411 | return do_scoped_id (TREE_OPERAND (t, 0), 0); | |
3412 | else | |
3413 | return do_identifier (TREE_OPERAND (t, 0), 0); | |
3414 | ||
386b8a85 | 3415 | case TEMPLATE_ID_EXPR: |
00d3396f JM |
3416 | return (lookup_template_function |
3417 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3418 | build_expr_from_tree (TREE_OPERAND (t, 1)))); | |
386b8a85 | 3419 | |
51c184be MS |
3420 | case INDIRECT_REF: |
3421 | return build_x_indirect_ref | |
5566b478 MS |
3422 | (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *"); |
3423 | ||
3424 | case CAST_EXPR: | |
3425 | return build_functional_cast | |
3426 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3427 | ||
3428 | case REINTERPRET_CAST_EXPR: | |
3429 | return build_reinterpret_cast | |
3430 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3431 | ||
e92cc029 MS |
3432 | case CONST_CAST_EXPR: |
3433 | return build_const_cast | |
3434 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3435 | ||
3436 | case DYNAMIC_CAST_EXPR: | |
3437 | return build_dynamic_cast | |
3438 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3439 | ||
3440 | case STATIC_CAST_EXPR: | |
3441 | return build_static_cast | |
3442 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3443 | ||
5566b478 MS |
3444 | case PREDECREMENT_EXPR: |
3445 | case PREINCREMENT_EXPR: | |
3446 | case POSTDECREMENT_EXPR: | |
3447 | case POSTINCREMENT_EXPR: | |
3448 | case NEGATE_EXPR: | |
51c184be | 3449 | case BIT_NOT_EXPR: |
5566b478 MS |
3450 | case ABS_EXPR: |
3451 | case TRUTH_NOT_EXPR: | |
3452 | case ADDR_EXPR: | |
3453 | case CONVERT_EXPR: /* Unary + */ | |
fc378698 MS |
3454 | if (TREE_TYPE (t)) |
3455 | return t; | |
5566b478 MS |
3456 | return build_x_unary_op (TREE_CODE (t), |
3457 | build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3458 | ||
3459 | case PLUS_EXPR: | |
3460 | case MINUS_EXPR: | |
3461 | case MULT_EXPR: | |
3462 | case TRUNC_DIV_EXPR: | |
3463 | case CEIL_DIV_EXPR: | |
3464 | case FLOOR_DIV_EXPR: | |
3465 | case ROUND_DIV_EXPR: | |
3466 | case EXACT_DIV_EXPR: | |
3467 | case BIT_AND_EXPR: | |
3468 | case BIT_ANDTC_EXPR: | |
3469 | case BIT_IOR_EXPR: | |
3470 | case BIT_XOR_EXPR: | |
3471 | case TRUNC_MOD_EXPR: | |
3472 | case FLOOR_MOD_EXPR: | |
3473 | case TRUTH_ANDIF_EXPR: | |
3474 | case TRUTH_ORIF_EXPR: | |
3475 | case TRUTH_AND_EXPR: | |
3476 | case TRUTH_OR_EXPR: | |
3477 | case RSHIFT_EXPR: | |
3478 | case LSHIFT_EXPR: | |
3479 | case RROTATE_EXPR: | |
3480 | case LROTATE_EXPR: | |
3481 | case EQ_EXPR: | |
3482 | case NE_EXPR: | |
3483 | case MAX_EXPR: | |
3484 | case MIN_EXPR: | |
3485 | case LE_EXPR: | |
3486 | case GE_EXPR: | |
3487 | case LT_EXPR: | |
3488 | case GT_EXPR: | |
3489 | case MEMBER_REF: | |
3490 | return build_x_binary_op | |
3491 | (TREE_CODE (t), | |
3492 | build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3493 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3494 | ||
3495 | case DOTSTAR_EXPR: | |
3496 | return build_m_component_ref | |
3497 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3498 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3499 | ||
a28e3c7f | 3500 | case SCOPE_REF: |
5566b478 MS |
3501 | return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1)); |
3502 | ||
a28e3c7f | 3503 | case ARRAY_REF: |
5566b478 MS |
3504 | if (TREE_OPERAND (t, 0) == NULL_TREE) |
3505 | /* new-type-id */ | |
3506 | return build_parse_node (ARRAY_REF, NULL_TREE, | |
3507 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3508 | return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3509 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3510 | ||
3511 | case SIZEOF_EXPR: | |
abff8e06 | 3512 | case ALIGNOF_EXPR: |
5566b478 MS |
3513 | { |
3514 | tree r = build_expr_from_tree (TREE_OPERAND (t, 0)); | |
3515 | if (TREE_CODE_CLASS (TREE_CODE (r)) != 't') | |
3516 | r = TREE_TYPE (r); | |
abff8e06 | 3517 | return TREE_CODE (t) == SIZEOF_EXPR ? c_sizeof (r) : c_alignof (r); |
5566b478 MS |
3518 | } |
3519 | ||
3520 | case MODOP_EXPR: | |
3521 | return build_x_modify_expr | |
3522 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3523 | TREE_CODE (TREE_OPERAND (t, 1)), | |
3524 | build_expr_from_tree (TREE_OPERAND (t, 2))); | |
3525 | ||
3526 | case ARROW_EXPR: | |
3527 | return build_x_arrow | |
3528 | (build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3529 | ||
3530 | case NEW_EXPR: | |
3531 | return build_new | |
3532 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3533 | build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3534 | build_expr_from_tree (TREE_OPERAND (t, 2)), | |
3535 | NEW_EXPR_USE_GLOBAL (t)); | |
3536 | ||
3537 | case DELETE_EXPR: | |
3538 | return delete_sanity | |
3539 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3540 | build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3541 | DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t)); | |
3542 | ||
3543 | case COMPOUND_EXPR: | |
3544 | if (TREE_OPERAND (t, 1) == NULL_TREE) | |
3545 | return build_x_compound_expr | |
3546 | (build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3547 | else | |
3548 | my_friendly_abort (42); | |
3549 | ||
3550 | case METHOD_CALL_EXPR: | |
3551 | if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF) | |
3552 | { | |
3553 | tree ref = TREE_OPERAND (t, 0); | |
3554 | return build_scoped_method_call | |
3555 | (build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3556 | build_expr_from_tree (TREE_OPERAND (ref, 0)), | |
3557 | TREE_OPERAND (ref, 1), | |
3558 | build_expr_from_tree (TREE_OPERAND (t, 2))); | |
3559 | } | |
3560 | return build_method_call | |
3561 | (build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3562 | TREE_OPERAND (t, 0), | |
3563 | build_expr_from_tree (TREE_OPERAND (t, 2)), | |
3564 | NULL_TREE, LOOKUP_NORMAL); | |
3565 | ||
3566 | case CALL_EXPR: | |
3567 | if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF) | |
3568 | { | |
3569 | tree ref = TREE_OPERAND (t, 0); | |
3570 | return build_member_call | |
3571 | (build_expr_from_tree (TREE_OPERAND (ref, 0)), | |
3572 | TREE_OPERAND (ref, 1), | |
3573 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3574 | } | |
3575 | else | |
3576 | { | |
3577 | tree name = TREE_OPERAND (t, 0); | |
00d3396f JM |
3578 | if (TREE_CODE (name) == TEMPLATE_ID_EXPR |
3579 | || ! really_overloaded_fn (name)) | |
5566b478 MS |
3580 | name = build_expr_from_tree (name); |
3581 | return build_x_function_call | |
3582 | (name, build_expr_from_tree (TREE_OPERAND (t, 1)), | |
4ac14744 | 3583 | current_class_ref); |
5566b478 MS |
3584 | } |
3585 | ||
3586 | case COND_EXPR: | |
3587 | return build_x_conditional_expr | |
3588 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3589 | build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3590 | build_expr_from_tree (TREE_OPERAND (t, 2))); | |
3591 | ||
3592 | case TREE_LIST: | |
3593 | { | |
3594 | tree purpose, value, chain; | |
3595 | ||
3596 | if (t == void_list_node) | |
3597 | return t; | |
3598 | ||
3599 | purpose = TREE_PURPOSE (t); | |
3600 | if (purpose) | |
3601 | purpose = build_expr_from_tree (purpose); | |
3602 | value = TREE_VALUE (t); | |
3603 | if (value) | |
3604 | value = build_expr_from_tree (value); | |
3605 | chain = TREE_CHAIN (t); | |
3606 | if (chain && chain != void_type_node) | |
3607 | chain = build_expr_from_tree (chain); | |
e66d884e | 3608 | return expr_tree_cons (purpose, value, chain); |
5566b478 MS |
3609 | } |
3610 | ||
3611 | case COMPONENT_REF: | |
e1467ff2 MM |
3612 | return build_x_component_ref |
3613 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3614 | TREE_OPERAND (t, 1), NULL_TREE, 1); | |
3615 | ||
fc378698 MS |
3616 | case THROW_EXPR: |
3617 | return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3618 | ||
5156628f MS |
3619 | case CONSTRUCTOR: |
3620 | { | |
3621 | tree r = build_nt (CONSTRUCTOR, NULL_TREE, | |
3622 | build_expr_from_tree (CONSTRUCTOR_ELTS (t))); | |
3623 | ||
3624 | if (TREE_TYPE (t)) | |
3625 | return digest_init (TREE_TYPE (t), r, 0); | |
3626 | return r; | |
3627 | } | |
3628 | ||
3629 | case TYPEID_EXPR: | |
e9f32eb5 MS |
3630 | if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't') |
3631 | return get_typeid (TREE_OPERAND (t, 0)); | |
5156628f MS |
3632 | return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0))); |
3633 | ||
9a3b49ac MS |
3634 | case VAR_DECL: |
3635 | return convert_from_reference (t); | |
3636 | ||
8926095f | 3637 | default: |
5566b478 | 3638 | return t; |
51c184be | 3639 | } |
51c184be MS |
3640 | } |
3641 | ||
3642 | /* This is something of the form `int (*a)++' that has turned out to be an | |
3643 | expr. It was only converted into parse nodes, so we need to go through | |
3644 | and build up the semantics. Most of the work is done by | |
5566b478 | 3645 | build_expr_from_tree, above. |
51c184be MS |
3646 | |
3647 | In the above example, TYPE is `int' and DECL is `*a'. */ | |
e92cc029 | 3648 | |
51c184be MS |
3649 | tree |
3650 | reparse_decl_as_expr (type, decl) | |
3651 | tree type, decl; | |
3652 | { | |
5566b478 | 3653 | decl = build_expr_from_tree (decl); |
e3417fcd | 3654 | if (type) |
e66d884e | 3655 | return build_functional_cast (type, build_expr_list (NULL_TREE, decl)); |
e3417fcd MS |
3656 | else |
3657 | return decl; | |
51c184be MS |
3658 | } |
3659 | ||
3660 | /* This is something of the form `int (*a)' that has turned out to be a | |
3661 | decl. It was only converted into parse nodes, so we need to do the | |
e92cc029 | 3662 | checking that make_{pointer,reference}_declarator do. */ |
51c184be MS |
3663 | |
3664 | tree | |
3665 | finish_decl_parsing (decl) | |
3666 | tree decl; | |
3667 | { | |
8926095f MS |
3668 | extern int current_class_depth; |
3669 | ||
51c184be MS |
3670 | switch (TREE_CODE (decl)) |
3671 | { | |
3672 | case IDENTIFIER_NODE: | |
3673 | return decl; | |
3674 | case INDIRECT_REF: | |
3675 | return make_pointer_declarator | |
3676 | (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0))); | |
3677 | case ADDR_EXPR: | |
3678 | return make_reference_declarator | |
3679 | (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0))); | |
3680 | case BIT_NOT_EXPR: | |
3681 | TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0)); | |
3682 | return decl; | |
8926095f | 3683 | case SCOPE_REF: |
a4443a08 | 3684 | push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3); |
8926095f MS |
3685 | TREE_COMPLEXITY (decl) = current_class_depth; |
3686 | return decl; | |
a28e3c7f MS |
3687 | case ARRAY_REF: |
3688 | TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0)); | |
3689 | return decl; | |
8926095f MS |
3690 | default: |
3691 | my_friendly_abort (5); | |
3692 | return NULL_TREE; | |
51c184be MS |
3693 | } |
3694 | } | |
2986ae00 MS |
3695 | |
3696 | tree | |
3697 | check_cp_case_value (value) | |
3698 | tree value; | |
3699 | { | |
3700 | if (value == NULL_TREE) | |
3701 | return value; | |
3702 | ||
5566b478 MS |
3703 | /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ |
3704 | STRIP_TYPE_NOPS (value); | |
2986ae00 MS |
3705 | |
3706 | if (TREE_READONLY_DECL_P (value)) | |
3707 | { | |
3708 | value = decl_constant_value (value); | |
5566b478 | 3709 | STRIP_TYPE_NOPS (value); |
2986ae00 MS |
3710 | } |
3711 | value = fold (value); | |
3712 | ||
3713 | if (TREE_CODE (value) != INTEGER_CST | |
3714 | && value != error_mark_node) | |
3715 | { | |
3716 | cp_error ("case label `%E' does not reduce to an integer constant", | |
3717 | value); | |
3718 | value = error_mark_node; | |
3719 | } | |
3720 | else | |
3721 | /* Promote char or short to int. */ | |
3722 | value = default_conversion (value); | |
3723 | ||
3724 | constant_expression_warning (value); | |
3725 | ||
3726 | return value; | |
3727 | } | |
6060a796 | 3728 | |
a9aedbc2 | 3729 | tree current_namespace; |
6060a796 MS |
3730 | |
3731 | /* Get the inner part of a namespace id. It doesn't have any prefix, nor | |
3732 | postfix. Returns 0 if in global namespace. */ | |
e92cc029 | 3733 | |
6060a796 MS |
3734 | tree |
3735 | get_namespace_id () | |
3736 | { | |
3737 | tree x = current_namespace; | |
3738 | if (x) | |
3739 | x = TREE_PURPOSE (x); | |
3740 | return x; | |
3741 | } | |
3742 | ||
e92cc029 MS |
3743 | /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */ |
3744 | ||
6060a796 MS |
3745 | tree |
3746 | current_namespace_id (name) | |
3747 | tree name; | |
3748 | { | |
3749 | tree old_id = get_namespace_id (); | |
3750 | char *buf; | |
3751 | ||
e92cc029 | 3752 | /* Global names retain old encoding. */ |
6060a796 MS |
3753 | if (! old_id) |
3754 | return name; | |
3755 | ||
3756 | buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id) | |
3757 | + IDENTIFIER_LENGTH (name)); | |
3758 | sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id), | |
3759 | IDENTIFIER_POINTER (name)); | |
3760 | return get_identifier (buf); | |
3761 | } | |
3762 | ||
6060a796 | 3763 | void |
a9aedbc2 MS |
3764 | do_namespace_alias (alias, namespace) |
3765 | tree alias, namespace; | |
6060a796 | 3766 | { |
fc378698 | 3767 | sorry ("namespace alias"); |
6060a796 MS |
3768 | } |
3769 | ||
6b5fbb55 | 3770 | void |
a9aedbc2 MS |
3771 | do_toplevel_using_decl (decl) |
3772 | tree decl; | |
6060a796 | 3773 | { |
6633d636 MS |
3774 | #if 1 |
3775 | if (TREE_CODE (decl) == SCOPE_REF | |
3776 | && TREE_OPERAND (decl, 0) == std_node) | |
3777 | return; | |
3778 | sorry ("using-declaration"); | |
3779 | #else | |
a9aedbc2 MS |
3780 | if (decl == NULL_TREE || decl == error_mark_node) |
3781 | return; | |
6060a796 | 3782 | |
a9aedbc2 MS |
3783 | if (TREE_CODE (decl) == SCOPE_REF) |
3784 | decl = resolve_scope_to_name (NULL_TREE, decl); | |
3785 | ||
3786 | /* Is this the right way to do an id list? */ | |
3787 | if (TREE_CODE (decl) != TREE_LIST) | |
3788 | { | |
3789 | pushdecl (decl); | |
3790 | } | |
3791 | else | |
3792 | while (decl) | |
3793 | { | |
3794 | pushdecl (TREE_VALUE (decl)); | |
3795 | decl = TREE_CHAIN (decl); | |
3796 | } | |
6633d636 | 3797 | #endif |
6060a796 MS |
3798 | } |
3799 | ||
3800 | tree | |
a9aedbc2 | 3801 | do_class_using_decl (decl) |
6060a796 MS |
3802 | tree decl; |
3803 | { | |
cffa8729 | 3804 | tree name, value; |
f30432d7 | 3805 | |
cffa8729 MS |
3806 | if (TREE_CODE (decl) != SCOPE_REF) |
3807 | { | |
3808 | cp_error ("using-declaration for non-member at class scope"); | |
3809 | return NULL_TREE; | |
3810 | } | |
3811 | name = TREE_OPERAND (decl, 1); | |
3812 | if (TREE_CODE (name) == BIT_NOT_EXPR) | |
3813 | { | |
3814 | cp_error ("using-declaration for destructor"); | |
3815 | return NULL_TREE; | |
3816 | } | |
3817 | ||
5566b478 | 3818 | value = build_lang_field_decl (USING_DECL, name, void_type_node); |
cffa8729 MS |
3819 | DECL_INITIAL (value) = TREE_OPERAND (decl, 0); |
3820 | return value; | |
6060a796 MS |
3821 | } |
3822 | ||
3823 | void | |
3824 | do_using_directive (namespace) | |
3825 | tree namespace; | |
3826 | { | |
6633d636 MS |
3827 | if (namespace == std_node) |
3828 | return; | |
fc378698 | 3829 | sorry ("using directive"); |
6060a796 | 3830 | } |
f30432d7 MS |
3831 | |
3832 | void | |
3833 | check_default_args (x) | |
3834 | tree x; | |
3835 | { | |
3836 | tree arg = TYPE_ARG_TYPES (TREE_TYPE (x)); | |
3837 | int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE); | |
3838 | for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i) | |
3839 | { | |
3840 | if (TREE_PURPOSE (arg)) | |
3841 | saw_def = 1; | |
3842 | else if (saw_def) | |
3843 | { | |
3844 | cp_error ("default argument missing for parameter %P of `%#D'", | |
3845 | i, x); | |
3846 | break; | |
3847 | } | |
3848 | } | |
3849 | } | |
72b7eeff MS |
3850 | |
3851 | void | |
3852 | mark_used (decl) | |
3853 | tree decl; | |
3854 | { | |
3855 | TREE_USED (decl) = 1; | |
5156628f | 3856 | if (processing_template_decl) |
5566b478 | 3857 | return; |
72b7eeff | 3858 | assemble_external (decl); |
73aad9b9 JM |
3859 | /* Is it a synthesized method that needs to be synthesized? */ |
3860 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl) | |
3861 | && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl) | |
3862 | /* Kludge: don't synthesize for default args. */ | |
3863 | && current_function_decl) | |
3864 | synthesize_method (decl); | |
5566b478 MS |
3865 | if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)) |
3866 | instantiate_decl (decl); | |
72b7eeff | 3867 | } |
f62dbf03 JM |
3868 | |
3869 | /* Helper function for named_class_head_sans_basetype nonterminal. */ | |
3870 | ||
3871 | tree | |
3872 | handle_class_head (aggr, scope, id) | |
3873 | tree aggr, scope, id; | |
3874 | { | |
3875 | if (TREE_CODE (id) == TYPE_DECL) | |
3876 | return id; | |
3877 | ||
3878 | if (scope) | |
3879 | cp_error ("`%T' does not have a nested type named `%D'", scope, id); | |
3880 | else | |
3881 | cp_error ("no file-scope type named `%D'", id); | |
3882 | ||
3883 | id = xref_tag | |
3884 | (aggr, make_anon_name (), NULL_TREE, 1); | |
3885 | return TYPE_MAIN_DECL (id); | |
3886 | } |