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