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