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