]>
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" | |
8d052bc7 | 31 | #include "system.h" |
8d08fdba MS |
32 | #include "tree.h" |
33 | #include "rtl.h" | |
34 | #include "flags.h" | |
35 | #include "cp-tree.h" | |
36 | #include "decl.h" | |
37 | #include "lex.h" | |
e8abc66f | 38 | #include "output.h" |
49c249e1 | 39 | #include "except.h" |
9f617717 | 40 | #include "expr.h" |
eb773359 | 41 | #include "defaults.h" |
54f92bfb | 42 | #include "toplev.h" |
bcb80729 KG |
43 | #include "dwarf2out.h" |
44 | #include "dwarfout.h" | |
49c249e1 | 45 | |
297441fd DB |
46 | #if USE_CPPLIB |
47 | #include "cpplib.h" | |
48 | extern cpp_reader parse_in; | |
49 | extern cpp_options parse_options; | |
50 | static int cpp_initialized; | |
51 | #endif | |
52 | ||
49c249e1 JM |
53 | static tree get_sentry PROTO((tree)); |
54 | static void mark_vtable_entries PROTO((tree)); | |
6b5fbb55 | 55 | static void grok_function_init PROTO((tree, tree)); |
49c249e1 JM |
56 | static int finish_vtable_vardecl PROTO((tree, tree)); |
57 | static int prune_vtable_vardecl PROTO((tree, tree)); | |
58 | static void finish_sigtable_vardecl PROTO((tree, tree)); | |
69ac77ce | 59 | static int is_namespace_ancestor PROTO((tree, tree)); |
69ac77ce | 60 | static void add_using_namespace PROTO((tree, tree, int)); |
52c11ef6 | 61 | static tree ambiguous_decl PROTO((tree, tree, tree,int)); |
cb96daa2 | 62 | static tree build_anon_union_vars PROTO((tree, tree*, int, int)); |
9a68c51f | 63 | static void check_decl_namespace PROTO((void)); |
49c249e1 | 64 | |
cffa8729 | 65 | extern int current_class_depth; |
8d08fdba MS |
66 | |
67 | /* A list of virtual function tables we must make sure to write out. */ | |
68 | tree pending_vtables; | |
69 | ||
70 | /* A list of static class variables. This is needed, because a | |
71 | static class variable can be declared inside the class without | |
72 | an initializer, and then initialized, staticly, outside the class. */ | |
73 | tree pending_statics; | |
74 | ||
8926095f | 75 | /* A list of functions which were declared inline, but which we |
e92cc029 | 76 | may need to emit outline anyway. */ |
8926095f | 77 | static tree saved_inlines; |
8d08fdba MS |
78 | |
79 | /* Used to help generate temporary names which are unique within | |
80 | a function. Reset to 0 by start_function. */ | |
81 | ||
7215f9a0 | 82 | int temp_name_counter; |
8d08fdba MS |
83 | |
84 | /* Same, but not reset. Local temp variables and global temp variables | |
85 | can have the same name. */ | |
86 | static int global_temp_name_counter; | |
87 | ||
51c184be | 88 | /* Flag used when debugging spew.c */ |
8d08fdba MS |
89 | |
90 | extern int spew_debug; | |
e1cd6e56 | 91 | |
5566b478 MS |
92 | /* Nonzero if we're done parsing and into end-of-file activities. */ |
93 | ||
94 | int at_eof; | |
95 | ||
e1cd6e56 MS |
96 | /* Functions called along with real static constructors and destructors. */ |
97 | ||
98 | tree static_ctors, static_dtors; | |
30394414 | 99 | |
2c73f9f5 | 100 | /* The current open namespace, and ::. */ |
30394414 JM |
101 | |
102 | tree current_namespace; | |
103 | tree global_namespace; | |
104 | ||
2c73f9f5 ML |
105 | /* The stack for namespaces of current declarations. */ |
106 | ||
107 | static tree decl_namespace_list; | |
108 | ||
8d08fdba MS |
109 | \f |
110 | /* C (and C++) language-specific option variables. */ | |
111 | ||
112 | /* Nonzero means allow type mismatches in conditional expressions; | |
113 | just make their values `void'. */ | |
114 | ||
115 | int flag_cond_mismatch; | |
116 | ||
117 | /* Nonzero means give `double' the same size as `float'. */ | |
118 | ||
119 | int flag_short_double; | |
120 | ||
121 | /* Nonzero means don't recognize the keyword `asm'. */ | |
122 | ||
123 | int flag_no_asm; | |
124 | ||
e1cd6e56 MS |
125 | /* Nonzero means don't recognize any extension keywords. */ |
126 | ||
127 | int flag_no_gnu_keywords; | |
128 | ||
8d08fdba MS |
129 | /* Nonzero means don't recognize the non-ANSI builtin functions. */ |
130 | ||
131 | int flag_no_builtin; | |
132 | ||
00595019 MS |
133 | /* Nonzero means don't recognize the non-ANSI builtin functions. |
134 | -ansi sets this. */ | |
135 | ||
136 | int flag_no_nonansi_builtin; | |
137 | ||
d22c8596 MS |
138 | /* Nonzero means do some things the same way PCC does. Only provided so |
139 | the compiler will link. */ | |
8d08fdba MS |
140 | |
141 | int flag_traditional; | |
142 | ||
143 | /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */ | |
144 | ||
145 | int flag_signed_bitfields = 1; | |
146 | ||
147 | /* Nonzero means handle `#ident' directives. 0 means ignore them. */ | |
148 | ||
e1cd6e56 | 149 | int flag_no_ident; |
8d08fdba | 150 | |
e1cd6e56 MS |
151 | /* Nonzero means enable obscure ANSI features and disable GNU extensions |
152 | that might cause ANSI-compliant code to be miscompiled. */ | |
8d08fdba | 153 | |
e1cd6e56 | 154 | int flag_ansi; |
8d08fdba | 155 | |
8d08fdba MS |
156 | /* Nonzero means do emit exported implementations of functions even if |
157 | they can be inlined. */ | |
158 | ||
159 | int flag_implement_inlines = 1; | |
160 | ||
161 | /* Nonzero means do emit exported implementations of templates, instead of | |
e92cc029 | 162 | multiple static copies in each file that needs a definition. */ |
8d08fdba | 163 | |
e1cd6e56 | 164 | int flag_external_templates; |
8d08fdba MS |
165 | |
166 | /* Nonzero means that the decision to emit or not emit the implementation of a | |
167 | template depends on where the template is instantiated, rather than where | |
168 | it is defined. */ | |
169 | ||
e1cd6e56 | 170 | int flag_alt_external_templates; |
8d08fdba | 171 | |
a0a33927 MS |
172 | /* Nonzero means that implicit instantiations will be emitted if needed. */ |
173 | ||
174 | int flag_implicit_templates = 1; | |
175 | ||
5eea678f JM |
176 | /* Nonzero means that implicit instantiations of inline templates will be |
177 | emitted if needed, even if instantiations of non-inline templates | |
178 | aren't. */ | |
179 | ||
180 | int flag_implicit_inline_templates = 1; | |
181 | ||
2ce3c6c6 JM |
182 | /* Nonzero means allow numerical priorities on constructors. */ |
183 | ||
184 | #ifdef USE_INIT_PRIORITY | |
185 | int flag_init_priority = 1; | |
186 | #else | |
187 | int flag_init_priority; | |
188 | #endif | |
189 | ||
8d08fdba MS |
190 | /* Nonzero means warn about implicit declarations. */ |
191 | ||
192 | int warn_implicit = 1; | |
193 | ||
795add94 VM |
194 | /* Nonzero means warn about usage of long long when `-pedantic'. */ |
195 | ||
196 | int warn_long_long = 1; | |
197 | ||
8d08fdba MS |
198 | /* Nonzero means warn when all ctors or dtors are private, and the class |
199 | has no friends. */ | |
200 | ||
201 | int warn_ctor_dtor_privacy = 1; | |
202 | ||
a80e4195 | 203 | /* True if we want to implement vtables using "thunks". |
6467930b | 204 | The default is off. */ |
8926095f | 205 | |
da20811c JM |
206 | #ifndef DEFAULT_VTABLE_THUNKS |
207 | #define DEFAULT_VTABLE_THUNKS 0 | |
c73964b2 | 208 | #endif |
da20811c | 209 | int flag_vtable_thunks = DEFAULT_VTABLE_THUNKS; |
51c184be | 210 | |
faae18ab MS |
211 | /* True if we want to deal with repository information. */ |
212 | ||
213 | int flag_use_repository; | |
214 | ||
dc8263bc JM |
215 | /* Nonzero if we want to issue diagnostics that the standard says are not |
216 | required. */ | |
217 | ||
218 | int flag_optional_diags = 1; | |
219 | ||
d9cf7c82 JM |
220 | /* Nonzero means give string constants the type `const char *', as mandated |
221 | by the standard. */ | |
222 | ||
223 | int flag_const_strings = 1; | |
224 | ||
225 | /* Nonzero means warn about deprecated conversion from string constant to | |
226 | `char *'. */ | |
8d08fdba MS |
227 | |
228 | int warn_write_strings; | |
229 | ||
230 | /* Nonzero means warn about pointer casts that can drop a type qualifier | |
231 | from the pointer target type. */ | |
232 | ||
233 | int warn_cast_qual; | |
234 | ||
8d08fdba MS |
235 | /* Nonzero means warn about sizeof(function) or addition/subtraction |
236 | of function pointers. */ | |
237 | ||
be99da77 | 238 | int warn_pointer_arith = 1; |
8d08fdba | 239 | |
8d08fdba MS |
240 | /* Nonzero means warn for any function def without prototype decl. */ |
241 | ||
242 | int warn_missing_prototypes; | |
243 | ||
244 | /* Nonzero means warn about multiple (redundant) decls for the same single | |
245 | variable or function. */ | |
246 | ||
247 | int warn_redundant_decls; | |
248 | ||
249 | /* Warn if initializer is not completely bracketed. */ | |
250 | ||
251 | int warn_missing_braces; | |
252 | ||
2ee887f2 MS |
253 | /* Warn about comparison of signed and unsigned values. */ |
254 | ||
255 | int warn_sign_compare; | |
256 | ||
e92cc029 | 257 | /* Warn about *printf or *scanf format/argument anomalies. */ |
8d08fdba MS |
258 | |
259 | int warn_format; | |
260 | ||
261 | /* Warn about a subscript that has type char. */ | |
262 | ||
263 | int warn_char_subscripts; | |
264 | ||
265 | /* Warn if a type conversion is done that might have confusing results. */ | |
266 | ||
267 | int warn_conversion; | |
268 | ||
269 | /* Warn if adding () is suggested. */ | |
270 | ||
e1cd6e56 | 271 | int warn_parentheses; |
8d08fdba MS |
272 | |
273 | /* Non-zero means warn in function declared in derived class has the | |
274 | same name as a virtual in the base class, but fails to match the | |
275 | type signature of any virtual function in the base class. */ | |
276 | int warn_overloaded_virtual; | |
277 | ||
278 | /* Non-zero means warn when declaring a class that has a non virtual | |
e92cc029 | 279 | destructor, when it really ought to have a virtual one. */ |
9a0e77ba | 280 | int warn_nonvdtor; |
8d08fdba MS |
281 | |
282 | /* Non-zero means warn when a function is declared extern and later inline. */ | |
283 | int warn_extern_inline; | |
284 | ||
f376e137 MS |
285 | /* Non-zero means warn when the compiler will reorder code. */ |
286 | int warn_reorder; | |
287 | ||
ddd5a7c1 | 288 | /* Non-zero means warn when synthesis behavior differs from Cfront's. */ |
f376e137 MS |
289 | int warn_synth; |
290 | ||
9a3b49ac MS |
291 | /* Non-zero means warn when we convert a pointer to member function |
292 | into a pointer to (void or function). */ | |
293 | int warn_pmf2ptr = 1; | |
294 | ||
eb448459 MS |
295 | /* Nonzero means warn about violation of some Effective C++ style rules. */ |
296 | ||
da20811c JM |
297 | int warn_ecpp; |
298 | ||
299 | /* Nonzero means warn where overload resolution chooses a promotion from | |
300 | unsigned to signed over a conversion to an unsigned of the same size. */ | |
301 | ||
302 | int warn_sign_promo; | |
eb448459 | 303 | |
0c4b14c4 JM |
304 | /* Nonzero means warn when an old-style cast is used. */ |
305 | ||
306 | int warn_old_style_cast; | |
307 | ||
f9fc59e8 NC |
308 | /* Warn about #pragma directives that are not recognised. */ |
309 | ||
dc8263bc JM |
310 | int warn_unknown_pragmas; /* Tri state variable. */ |
311 | ||
312 | /* Nonzero means warn about use of multicharacter literals. */ | |
313 | ||
314 | int warn_multichar = 1; | |
f9fc59e8 | 315 | |
7f84cec9 BK |
316 | /* Nonzero means warn when non-templatized friend functions are |
317 | declared within a template */ | |
318 | ||
319 | int warn_nontemplate_friend = 1; | |
320 | ||
4f6140be | 321 | /* Nonzero means `$' can be in an identifier. */ |
8d08fdba MS |
322 | |
323 | #ifndef DOLLARS_IN_IDENTIFIERS | |
324 | #define DOLLARS_IN_IDENTIFIERS 1 | |
325 | #endif | |
326 | int dollars_in_ident = DOLLARS_IN_IDENTIFIERS; | |
327 | ||
a3203465 | 328 | /* Nonzero for -fno-strict-prototype switch: do not consider empty |
8d08fdba MS |
329 | argument prototype to mean function takes no arguments. */ |
330 | ||
e1cd6e56 | 331 | int flag_strict_prototype = 2; |
8d08fdba MS |
332 | int strict_prototype = 1; |
333 | int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1; | |
334 | ||
335 | /* Nonzero means that labels can be used as first-class objects */ | |
336 | ||
337 | int flag_labels_ok; | |
338 | ||
339 | /* Non-zero means to collect statistics which might be expensive | |
340 | and to print them when we are done. */ | |
341 | int flag_detailed_statistics; | |
342 | ||
343 | /* C++ specific flags. */ | |
8d08fdba MS |
344 | /* Zero means that `this' is a *const. This gives nice behavior in the |
345 | 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior. | |
346 | -2 means we're constructing an object and it has fixed type. */ | |
347 | ||
348 | int flag_this_is_variable; | |
349 | ||
8d08fdba MS |
350 | /* 3 means write out only virtuals function tables `defined' |
351 | in this implementation file. | |
8d08fdba | 352 | 0 means write out virtual function tables and give them |
56ae6d77 | 353 | (C) static access (default). */ |
8d08fdba MS |
354 | |
355 | int write_virtuals; | |
356 | ||
56ae6d77 | 357 | /* Nonzero means we should attempt to elide constructors when possible. */ |
8d08fdba | 358 | |
56ae6d77 | 359 | int flag_elide_constructors = 1; |
8d08fdba | 360 | |
8d08fdba MS |
361 | /* Nonzero means recognize and handle signature language constructs. */ |
362 | ||
363 | int flag_handle_signatures; | |
364 | ||
365 | /* Nonzero means that member functions defined in class scope are | |
366 | inline by default. */ | |
367 | ||
368 | int flag_default_inline = 1; | |
369 | ||
db5ae43f | 370 | /* Controls whether compiler generates 'type descriptor' that give |
8d08fdba | 371 | run-time type information. */ |
6b5fbb55 | 372 | int flag_rtti = 1; |
8d08fdba MS |
373 | |
374 | /* Nonzero if we wish to output cross-referencing information | |
375 | for the GNU class browser. */ | |
376 | extern int flag_gnu_xref; | |
377 | ||
8d08fdba | 378 | /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) |
e92cc029 | 379 | objects. */ |
e1cd6e56 | 380 | |
8d08fdba MS |
381 | int flag_huge_objects; |
382 | ||
383 | /* Nonzero if we want to conserve space in the .o files. We do this | |
384 | by putting uninitialized data and runtime initialized data into | |
ddd5a7c1 | 385 | .common instead of .data at the expense of not flagging multiple |
8d08fdba | 386 | definitions. */ |
e1cd6e56 | 387 | |
8d08fdba MS |
388 | int flag_conserve_space; |
389 | ||
eae89e04 | 390 | /* Nonzero if we want to obey access control semantics. */ |
e1cd6e56 | 391 | |
eae89e04 JM |
392 | int flag_access_control = 1; |
393 | ||
e1cd6e56 MS |
394 | /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */ |
395 | ||
396 | int flag_operator_names; | |
397 | ||
d18c083e MS |
398 | /* Nonzero if we want to check the return value of new and avoid calling |
399 | constructors if it is a null pointer. */ | |
400 | ||
401 | int flag_check_new; | |
402 | ||
863adfc0 | 403 | /* Nonzero if we want the new ANSI rules for pushing a new scope for `for' |
57c0c9ca PB |
404 | initialization variables. |
405 | 0: Old rules, set by -fno-for-scope. | |
406 | 2: New ANSI rules, set by -ffor-scope. | |
abc95ed3 | 407 | 1: Try to implement new ANSI rules, but with backup compatibility |
57c0c9ca | 408 | (and warnings). This is the default, for now. */ |
863adfc0 MS |
409 | |
410 | int flag_new_for_scope = 1; | |
411 | ||
72b7eeff MS |
412 | /* Nonzero if we want to emit defined symbols with common-like linkage as |
413 | weak symbols where possible, in order to conform to C++ semantics. | |
414 | Otherwise, emit them as local symbols. */ | |
415 | ||
416 | int flag_weak = 1; | |
417 | ||
a59ca936 JM |
418 | /* Nonzero to enable experimental ABI changes. */ |
419 | ||
420 | int flag_new_abi; | |
732dcb6f | 421 | |
2c73f9f5 ML |
422 | /* Nonzero to not ignore namespace std. */ |
423 | ||
424 | int flag_honor_std; | |
425 | ||
e9f32eb5 MS |
426 | /* Maximum template instantiation depth. Must be at least 17 for ANSI |
427 | compliance. */ | |
428 | ||
429 | int max_tinst_depth = 17; | |
430 | ||
386b8a85 JM |
431 | /* The name-mangling scheme to use. Must be 1 or greater to support |
432 | template functions with identical types, but different template | |
433 | arguments. */ | |
1d9ffce9 | 434 | int name_mangling_version = 2; |
386b8a85 JM |
435 | |
436 | /* Nonzero means that guiding declarations are allowed. */ | |
437 | int flag_guiding_decls; | |
438 | ||
1d9ffce9 AM |
439 | /* Nonzero if squashed mangling is to be performed. |
440 | This uses the B and K codes to reference previously seen class types | |
441 | and class qualifiers. */ | |
442 | int flag_do_squangling; | |
443 | ||
a1dd0d36 JM |
444 | /* Nonzero means output .vtable_{entry,inherit} for use in doing vtable gc. */ |
445 | ||
446 | int flag_vtable_gc; | |
1d9ffce9 | 447 | |
8d08fdba MS |
448 | /* Table of language-dependent -f options. |
449 | STRING is the option name. VARIABLE is the address of the variable. | |
450 | ON_VALUE is the value to store in VARIABLE | |
451 | if `-fSTRING' is seen as an option. | |
452 | (If `-fno-STRING' is seen as an option, the opposite value is stored.) */ | |
453 | ||
454 | static struct { char *string; int *variable; int on_value;} lang_f_options[] = | |
455 | { | |
456 | {"signed-char", &flag_signed_char, 1}, | |
457 | {"unsigned-char", &flag_signed_char, 0}, | |
458 | {"signed-bitfields", &flag_signed_bitfields, 1}, | |
459 | {"unsigned-bitfields", &flag_signed_bitfields, 0}, | |
460 | {"short-enums", &flag_short_enums, 1}, | |
461 | {"short-double", &flag_short_double, 1}, | |
462 | {"cond-mismatch", &flag_cond_mismatch, 1}, | |
1d9ffce9 | 463 | {"squangle", &flag_do_squangling, 1}, |
8d08fdba MS |
464 | {"asm", &flag_no_asm, 0}, |
465 | {"builtin", &flag_no_builtin, 0}, | |
466 | {"ident", &flag_no_ident, 0}, | |
467 | {"labels-ok", &flag_labels_ok, 1}, | |
d9cf7c82 | 468 | {"const-strings", &flag_const_strings, 1}, |
8d08fdba MS |
469 | {"stats", &flag_detailed_statistics, 1}, |
470 | {"this-is-variable", &flag_this_is_variable, 1}, | |
e1cd6e56 | 471 | {"strict-prototype", &flag_strict_prototype, 1}, |
8d08fdba | 472 | {"elide-constructors", &flag_elide_constructors, 1}, |
da20811c | 473 | {"handle-exceptions", &flag_exceptions, 1}, |
8d08fdba | 474 | {"handle-signatures", &flag_handle_signatures, 1}, |
8d08fdba MS |
475 | {"default-inline", &flag_default_inline, 1}, |
476 | {"dollars-in-identifiers", &dollars_in_ident, 1}, | |
2c73f9f5 | 477 | {"honor-std", &flag_honor_std, 1}, |
db5ae43f | 478 | {"rtti", &flag_rtti, 1}, |
8d08fdba | 479 | {"xref", &flag_gnu_xref, 1}, |
8d08fdba MS |
480 | {"implement-inlines", &flag_implement_inlines, 1}, |
481 | {"external-templates", &flag_external_templates, 1}, | |
a0a33927 | 482 | {"implicit-templates", &flag_implicit_templates, 1}, |
5eea678f | 483 | {"implicit-inline-templates", &flag_implicit_inline_templates, 1}, |
2ce3c6c6 | 484 | {"init-priority", &flag_init_priority, 1}, |
8d08fdba MS |
485 | {"huge-objects", &flag_huge_objects, 1}, |
486 | {"conserve-space", &flag_conserve_space, 1}, | |
a1dd0d36 | 487 | {"vtable-gc", &flag_vtable_gc, 1}, |
8926095f | 488 | {"vtable-thunks", &flag_vtable_thunks, 1}, |
eae89e04 | 489 | {"access-control", &flag_access_control, 1}, |
e1cd6e56 MS |
490 | {"nonansi-builtins", &flag_no_nonansi_builtin, 0}, |
491 | {"gnu-keywords", &flag_no_gnu_keywords, 0}, | |
d18c083e | 492 | {"operator-names", &flag_operator_names, 1}, |
dc8263bc | 493 | {"optional-diags", &flag_optional_diags, 1}, |
faae18ab | 494 | {"check-new", &flag_check_new, 1}, |
863adfc0 | 495 | {"repo", &flag_use_repository, 1}, |
72b7eeff | 496 | {"for-scope", &flag_new_for_scope, 2}, |
8251199e | 497 | {"weak", &flag_weak, 1} |
8d08fdba MS |
498 | }; |
499 | ||
500 | /* Decode the string P as a language-specific option. | |
297441fd DB |
501 | Return the number of strings consumed for a valid option. |
502 | Otherwise return 0. */ | |
8d08fdba MS |
503 | |
504 | int | |
297441fd | 505 | lang_decode_option (argc, argv) |
b370501f KG |
506 | int argc |
507 | #if !USE_CPPLIB | |
508 | ATTRIBUTE_UNUSED | |
509 | #endif | |
510 | ; | |
297441fd DB |
511 | char **argv; |
512 | ||
8d08fdba | 513 | { |
297441fd DB |
514 | int strings_processed; |
515 | char *p = argv[0]; | |
516 | #if USE_CPPLIB | |
517 | if (! cpp_initialized) | |
518 | { | |
519 | cpp_reader_init (&parse_in); | |
520 | parse_in.data = &parse_options; | |
521 | cpp_options_init (&parse_options); | |
522 | cpp_initialized = 1; | |
523 | } | |
524 | strings_processed = cpp_handle_option (&parse_in, argc, argv); | |
525 | #else | |
526 | strings_processed = 0; | |
527 | #endif /* ! USE_CPPLIB */ | |
528 | ||
8d08fdba | 529 | if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) |
8cd4c175 | 530 | /* ignore */; |
8d08fdba MS |
531 | else if (p[0] == '-' && p[1] == 'f') |
532 | { | |
533 | /* Some kind of -f option. | |
534 | P's value is the option sans `-f'. | |
535 | Search for it in the table of options. */ | |
85066503 MH |
536 | int found = 0; |
537 | size_t j; | |
8d08fdba MS |
538 | |
539 | p += 2; | |
540 | /* Try special -f options. */ | |
541 | ||
da20811c JM |
542 | if (!strcmp (p, "handle-exceptions") |
543 | || !strcmp (p, "no-handle-exceptions")) | |
8251199e | 544 | warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)"); |
da20811c | 545 | |
e907984f JM |
546 | if (!strcmp (p, "memoize-lookups") |
547 | || !strcmp (p, "no-memoize-lookups") | |
548 | || !strcmp (p, "save-memoized") | |
84663f74 JM |
549 | || !strcmp (p, "no-save-memoized") |
550 | || !strcmp (p, "no-all-virtual") | |
551 | || !strcmp (p, "no-enum-int-equiv") | |
552 | || !strcmp (p, "nonnull-objects") | |
553 | || !strcmp (p, "ansi-overloading")) | |
8d08fdba | 554 | { |
e907984f | 555 | /* ignore */ |
8d08fdba MS |
556 | found = 1; |
557 | } | |
84663f74 JM |
558 | else if (!strcmp (p, "all-virtual") |
559 | || !strcmp (p, "enum-int-equiv") | |
560 | || !strcmp (p, "no-nonnull-objects") | |
561 | || !strcmp (p, "no-ansi-overloading")) | |
562 | { | |
8251199e | 563 | warning ("-f%s is no longer supported", p); |
84663f74 JM |
564 | found = 1; |
565 | } | |
8d08fdba MS |
566 | else if (! strcmp (p, "alt-external-templates")) |
567 | { | |
568 | flag_external_templates = 1; | |
569 | flag_alt_external_templates = 1; | |
570 | found = 1; | |
571 | } | |
572 | else if (! strcmp (p, "no-alt-external-templates")) | |
573 | { | |
574 | flag_alt_external_templates = 0; | |
575 | found = 1; | |
576 | } | |
79ff2c6c MS |
577 | else if (!strcmp (p, "repo")) |
578 | { | |
579 | flag_use_repository = 1; | |
580 | flag_implicit_templates = 0; | |
581 | found = 1; | |
00595019 | 582 | } |
386b8a85 JM |
583 | else if (!strcmp (p, "guiding-decls")) |
584 | { | |
585 | flag_guiding_decls = 1; | |
586 | name_mangling_version = 0; | |
587 | found = 1; | |
588 | } | |
589 | else if (!strcmp (p, "no-guiding-decls")) | |
590 | { | |
591 | flag_guiding_decls = 0; | |
592 | found = 1; | |
593 | } | |
a59ca936 JM |
594 | else if (!strcmp (p, "new-abi")) |
595 | { | |
596 | flag_new_abi = 1; | |
597 | flag_do_squangling = 1; | |
2c73f9f5 | 598 | flag_honor_std = 1; |
9577319f | 599 | flag_vtable_thunks = 1; |
a59ca936 JM |
600 | } |
601 | else if (!strcmp (p, "no-new-abi")) | |
602 | { | |
603 | flag_new_abi = 0; | |
604 | flag_do_squangling = 0; | |
2c73f9f5 | 605 | flag_honor_std = 0; |
a59ca936 | 606 | } |
e9f32eb5 MS |
607 | else if (!strncmp (p, "template-depth-", 15)) |
608 | { | |
609 | char *endp = p + 15; | |
610 | while (*endp) | |
611 | { | |
612 | if (*endp >= '0' && *endp <= '9') | |
613 | endp++; | |
614 | else | |
615 | { | |
8251199e | 616 | error ("Invalid option `%s'", p - 2); |
e9f32eb5 MS |
617 | goto template_depth_lose; |
618 | } | |
619 | } | |
620 | max_tinst_depth = atoi (p + 15); | |
621 | template_depth_lose: ; | |
622 | } | |
386b8a85 JM |
623 | else if (!strncmp (p, "name-mangling-version-", 22)) |
624 | { | |
625 | char *endp = p + 22; | |
626 | while (*endp) | |
627 | { | |
628 | if (*endp >= '0' && *endp <= '9') | |
629 | endp++; | |
630 | else | |
631 | { | |
8251199e | 632 | error ("Invalid option `%s'", p - 2); |
386b8a85 JM |
633 | goto mangling_version_lose; |
634 | } | |
635 | } | |
636 | name_mangling_version = atoi (p + 22); | |
893de33c | 637 | mangling_version_lose: ; |
386b8a85 | 638 | } |
8d08fdba MS |
639 | else for (j = 0; |
640 | !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]); | |
641 | j++) | |
642 | { | |
643 | if (!strcmp (p, lang_f_options[j].string)) | |
644 | { | |
645 | *lang_f_options[j].variable = lang_f_options[j].on_value; | |
646 | /* A goto here would be cleaner, | |
647 | but breaks the vax pcc. */ | |
648 | found = 1; | |
649 | } | |
650 | if (p[0] == 'n' && p[1] == 'o' && p[2] == '-' | |
651 | && ! strcmp (p+3, lang_f_options[j].string)) | |
652 | { | |
653 | *lang_f_options[j].variable = ! lang_f_options[j].on_value; | |
654 | found = 1; | |
655 | } | |
656 | } | |
657 | return found; | |
658 | } | |
659 | else if (p[0] == '-' && p[1] == 'W') | |
660 | { | |
661 | int setting = 1; | |
662 | ||
663 | /* The -W options control the warning behavior of the compiler. */ | |
664 | p += 2; | |
665 | ||
666 | if (p[0] == 'n' && p[1] == 'o' && p[2] == '-') | |
667 | setting = 0, p += 3; | |
668 | ||
669 | if (!strcmp (p, "implicit")) | |
670 | warn_implicit = setting; | |
795add94 VM |
671 | else if (!strcmp (p, "long-long")) |
672 | warn_long_long = setting; | |
8d08fdba MS |
673 | else if (!strcmp (p, "return-type")) |
674 | warn_return_type = setting; | |
675 | else if (!strcmp (p, "ctor-dtor-privacy")) | |
676 | warn_ctor_dtor_privacy = setting; | |
677 | else if (!strcmp (p, "write-strings")) | |
678 | warn_write_strings = setting; | |
679 | else if (!strcmp (p, "cast-qual")) | |
680 | warn_cast_qual = setting; | |
8d08fdba MS |
681 | else if (!strcmp (p, "char-subscripts")) |
682 | warn_char_subscripts = setting; | |
683 | else if (!strcmp (p, "pointer-arith")) | |
684 | warn_pointer_arith = setting; | |
8d08fdba MS |
685 | else if (!strcmp (p, "missing-prototypes")) |
686 | warn_missing_prototypes = setting; | |
687 | else if (!strcmp (p, "redundant-decls")) | |
688 | warn_redundant_decls = setting; | |
689 | else if (!strcmp (p, "missing-braces")) | |
690 | warn_missing_braces = setting; | |
2ee887f2 MS |
691 | else if (!strcmp (p, "sign-compare")) |
692 | warn_sign_compare = setting; | |
8d08fdba MS |
693 | else if (!strcmp (p, "format")) |
694 | warn_format = setting; | |
695 | else if (!strcmp (p, "conversion")) | |
696 | warn_conversion = setting; | |
697 | else if (!strcmp (p, "parentheses")) | |
698 | warn_parentheses = setting; | |
21474714 MS |
699 | else if (!strcmp (p, "non-virtual-dtor")) |
700 | warn_nonvdtor = setting; | |
8d08fdba MS |
701 | else if (!strcmp (p, "extern-inline")) |
702 | warn_extern_inline = setting; | |
f376e137 MS |
703 | else if (!strcmp (p, "reorder")) |
704 | warn_reorder = setting; | |
705 | else if (!strcmp (p, "synth")) | |
706 | warn_synth = setting; | |
9a3b49ac MS |
707 | else if (!strcmp (p, "pmf-conversions")) |
708 | warn_pmf2ptr = setting; | |
eb448459 MS |
709 | else if (!strcmp (p, "effc++")) |
710 | warn_ecpp = setting; | |
da20811c JM |
711 | else if (!strcmp (p, "sign-promo")) |
712 | warn_sign_promo = setting; | |
0c4b14c4 JM |
713 | else if (!strcmp (p, "old-style-cast")) |
714 | warn_old_style_cast = setting; | |
dc8263bc JM |
715 | else if (!strcmp (p, "overloaded-virtual")) |
716 | warn_overloaded_virtual = setting; | |
717 | else if (!strcmp (p, "multichar")) | |
718 | warn_multichar = setting; | |
f9fc59e8 NC |
719 | else if (!strcmp (p, "unknown-pragmas")) |
720 | /* Set to greater than 1, so that even unknown pragmas in | |
721 | system headers will be warned about. */ | |
722 | warn_unknown_pragmas = setting * 2; | |
7f84cec9 BK |
723 | else if (!strcmp (p, "non-template-friend")) |
724 | warn_nontemplate_friend = setting; | |
8d08fdba MS |
725 | else if (!strcmp (p, "comment")) |
726 | ; /* cpp handles this one. */ | |
727 | else if (!strcmp (p, "comments")) | |
728 | ; /* cpp handles this one. */ | |
729 | else if (!strcmp (p, "trigraphs")) | |
730 | ; /* cpp handles this one. */ | |
731 | else if (!strcmp (p, "import")) | |
732 | ; /* cpp handles this one. */ | |
733 | else if (!strcmp (p, "all")) | |
734 | { | |
8d08fdba MS |
735 | warn_return_type = setting; |
736 | warn_unused = setting; | |
737 | warn_implicit = setting; | |
738 | warn_ctor_dtor_privacy = setting; | |
739 | warn_switch = setting; | |
740 | warn_format = setting; | |
e1cd6e56 | 741 | warn_parentheses = setting; |
8d08fdba | 742 | warn_missing_braces = setting; |
2ee887f2 | 743 | warn_sign_compare = setting; |
8d08fdba | 744 | warn_extern_inline = setting; |
9a0e77ba | 745 | warn_nonvdtor = setting; |
dc8263bc | 746 | warn_multichar = setting; |
8d08fdba MS |
747 | /* We save the value of warn_uninitialized, since if they put |
748 | -Wuninitialized on the command line, we need to generate a | |
749 | warning about not using it without also specifying -O. */ | |
750 | if (warn_uninitialized != 1) | |
751 | warn_uninitialized = (setting ? 2 : 0); | |
f376e137 | 752 | warn_reorder = setting; |
da20811c | 753 | warn_sign_promo = setting; |
f9fc59e8 NC |
754 | /* Only warn about unknown pragmas that are not in system |
755 | headers. */ | |
7f84cec9 BK |
756 | warn_unknown_pragmas = 1; |
757 | warn_nontemplate_friend = setting; | |
8d08fdba | 758 | } |
297441fd | 759 | else return strings_processed; |
8d08fdba MS |
760 | } |
761 | else if (!strcmp (p, "-ansi")) | |
4f6140be | 762 | flag_no_nonansi_builtin = 1, flag_ansi = 1, |
e1cd6e56 | 763 | flag_no_gnu_keywords = 1, flag_operator_names = 1; |
8d08fdba MS |
764 | #ifdef SPEW_DEBUG |
765 | /* Undocumented, only ever used when you're invoking cc1plus by hand, since | |
766 | it's probably safe to assume no sane person would ever want to use this | |
767 | under normal circumstances. */ | |
768 | else if (!strcmp (p, "-spew-debug")) | |
769 | spew_debug = 1; | |
770 | #endif | |
771 | else | |
297441fd | 772 | return strings_processed; |
8d08fdba MS |
773 | |
774 | return 1; | |
775 | } | |
776 | \f | |
777 | /* Incorporate `const' and `volatile' qualifiers for member functions. | |
778 | FUNCTION is a TYPE_DECL or a FUNCTION_DECL. | |
779 | QUALS is a list of qualifiers. */ | |
e92cc029 | 780 | |
8d08fdba MS |
781 | tree |
782 | grok_method_quals (ctype, function, quals) | |
783 | tree ctype, function, quals; | |
784 | { | |
785 | tree fntype = TREE_TYPE (function); | |
786 | tree raises = TYPE_RAISES_EXCEPTIONS (fntype); | |
787 | ||
788 | do | |
789 | { | |
790 | extern tree ridpointers[]; | |
791 | ||
792 | if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST]) | |
793 | { | |
794 | if (TYPE_READONLY (ctype)) | |
8251199e | 795 | error ("duplicate `%s' %s", |
8d08fdba MS |
796 | IDENTIFIER_POINTER (TREE_VALUE (quals)), |
797 | (TREE_CODE (function) == FUNCTION_DECL | |
798 | ? "for member function" : "in type declaration")); | |
799 | ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype)); | |
800 | build_pointer_type (ctype); | |
801 | } | |
802 | else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE]) | |
803 | { | |
804 | if (TYPE_VOLATILE (ctype)) | |
8251199e | 805 | error ("duplicate `%s' %s", |
8d08fdba MS |
806 | IDENTIFIER_POINTER (TREE_VALUE (quals)), |
807 | (TREE_CODE (function) == FUNCTION_DECL | |
808 | ? "for member function" : "in type declaration")); | |
809 | ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1); | |
810 | build_pointer_type (ctype); | |
811 | } | |
812 | else | |
813 | my_friendly_abort (20); | |
814 | quals = TREE_CHAIN (quals); | |
815 | } | |
816 | while (quals); | |
817 | fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype), | |
818 | (TREE_CODE (fntype) == METHOD_TYPE | |
819 | ? TREE_CHAIN (TYPE_ARG_TYPES (fntype)) | |
820 | : TYPE_ARG_TYPES (fntype))); | |
821 | if (raises) | |
f30432d7 | 822 | fntype = build_exception_variant (fntype, raises); |
8d08fdba MS |
823 | |
824 | TREE_TYPE (function) = fntype; | |
825 | return ctype; | |
826 | } | |
827 | ||
8d08fdba MS |
828 | /* Warn when -fexternal-templates is used and #pragma |
829 | interface/implementation is not used all the times it should be, | |
830 | inform the user. */ | |
e92cc029 | 831 | |
8d08fdba | 832 | void |
8ccc31eb MS |
833 | warn_if_unknown_interface (decl) |
834 | tree decl; | |
8d08fdba MS |
835 | { |
836 | static int already_warned = 0; | |
8ccc31eb MS |
837 | if (already_warned++) |
838 | return; | |
839 | ||
840 | if (flag_alt_external_templates) | |
841 | { | |
842 | struct tinst_level *til = tinst_for_decl (); | |
843 | int sl = lineno; | |
844 | char *sf = input_filename; | |
845 | ||
f30432d7 MS |
846 | if (til) |
847 | { | |
848 | lineno = til->line; | |
849 | input_filename = til->file; | |
850 | } | |
8251199e | 851 | cp_warning ("template `%#D' instantiated in file without #pragma interface", |
8ccc31eb MS |
852 | decl); |
853 | lineno = sl; | |
854 | input_filename = sf; | |
855 | } | |
856 | else | |
8251199e | 857 | cp_warning_at ("template `%#D' defined in file without #pragma interface", |
8ccc31eb | 858 | decl); |
8d08fdba MS |
859 | } |
860 | ||
861 | /* A subroutine of the parser, to handle a component list. */ | |
e92cc029 | 862 | |
61a127b3 MM |
863 | void |
864 | grok_x_components (specs) | |
865 | tree specs; | |
8d08fdba | 866 | { |
61a127b3 MM |
867 | struct pending_inline **p; |
868 | tree t; | |
8d08fdba | 869 | |
61a127b3 MM |
870 | t = groktypename (build_decl_list (strip_attrs (specs), NULL_TREE)); |
871 | ||
872 | if (t == NULL_TREE) | |
8d08fdba | 873 | { |
61a127b3 MM |
874 | cp_error ("invalid member declaration"); |
875 | return; | |
876 | } | |
36a117a5 | 877 | |
61a127b3 MM |
878 | /* The only case where we need to do anything additional here is an |
879 | anonymous union field, e.g.: `struct S { union { int i; }; };'. */ | |
880 | if (!ANON_UNION_TYPE_P (t)) | |
881 | return; | |
8d08fdba | 882 | |
61a127b3 MM |
883 | fixup_anonymous_union (t); |
884 | finish_member_declaration (build_lang_field_decl (FIELD_DECL, | |
885 | NULL_TREE, | |
886 | t)); | |
887 | ||
888 | /* Ignore any inline function definitions in the anonymous union | |
889 | since an anonymous union may not have function members. */ | |
890 | p = &pending_inlines; | |
891 | for (; *p; *p = (*p)->next) | |
892 | if (DECL_CONTEXT ((*p)->fndecl) != t) | |
893 | break; | |
8d08fdba MS |
894 | } |
895 | ||
711734a9 JM |
896 | /* Constructors for types with virtual baseclasses need an "in-charge" flag |
897 | saying whether this constructor is responsible for initialization of | |
898 | virtual baseclasses or not. All destructors also need this "in-charge" | |
899 | flag, which additionally determines whether or not the destructor should | |
900 | free the memory for the object. | |
901 | ||
902 | This function adds the "in-charge" flag to member function FN if | |
903 | appropriate. It is called from grokclassfn and tsubst. | |
904 | FN must be either a constructor or destructor. */ | |
905 | ||
906 | void | |
907 | maybe_retrofit_in_chrg (fn) | |
908 | tree fn; | |
909 | { | |
910 | tree basetype, arg_types, parms, parm, fntype; | |
911 | ||
912 | if (DECL_CONSTRUCTOR_P (fn) | |
913 | && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CLASS_CONTEXT (fn)) | |
914 | && ! DECL_CONSTRUCTOR_FOR_VBASE_P (fn)) | |
915 | /* OK */; | |
916 | else if (! DECL_CONSTRUCTOR_P (fn) | |
917 | && TREE_CHAIN (DECL_ARGUMENTS (fn)) == NULL_TREE) | |
918 | /* OK */; | |
919 | else | |
920 | return; | |
921 | ||
922 | if (DECL_CONSTRUCTOR_P (fn)) | |
923 | DECL_CONSTRUCTOR_FOR_VBASE_P (fn) = 1; | |
924 | ||
925 | /* First add it to DECL_ARGUMENTS... */ | |
926 | parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node); | |
927 | /* Mark the artificial `__in_chrg' parameter as "artificial". */ | |
928 | SET_DECL_ARTIFICIAL (parm); | |
929 | DECL_ARG_TYPE (parm) = integer_type_node; | |
930 | TREE_READONLY (parm) = 1; | |
931 | parms = DECL_ARGUMENTS (fn); | |
932 | TREE_CHAIN (parm) = TREE_CHAIN (parms); | |
933 | TREE_CHAIN (parms) = parm; | |
934 | ||
935 | /* ...and then to TYPE_ARG_TYPES. */ | |
936 | arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn)); | |
937 | basetype = TREE_TYPE (TREE_VALUE (arg_types)); | |
938 | arg_types = hash_tree_chain (integer_type_node, TREE_CHAIN (arg_types)); | |
939 | fntype = build_cplus_method_type (basetype, TREE_TYPE (TREE_TYPE (fn)), | |
940 | arg_types); | |
941 | if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))) | |
942 | fntype = build_exception_variant (fntype, | |
943 | TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))); | |
944 | TREE_TYPE (fn) = fntype; | |
945 | } | |
946 | ||
8d08fdba MS |
947 | /* Classes overload their constituent function names automatically. |
948 | When a function name is declared in a record structure, | |
949 | its name is changed to it overloaded name. Since names for | |
950 | constructors and destructors can conflict, we place a leading | |
951 | '$' for destructors. | |
952 | ||
953 | CNAME is the name of the class we are grokking for. | |
954 | ||
955 | FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'. | |
956 | ||
957 | FLAGS contains bits saying what's special about today's | |
958 | arguments. 1 == DESTRUCTOR. 2 == OPERATOR. | |
959 | ||
960 | If FUNCTION is a destructor, then we must add the `auto-delete' field | |
961 | as a second parameter. There is some hair associated with the fact | |
962 | that we must "declare" this variable in the manner consistent with the | |
963 | way the rest of the arguments were declared. | |
964 | ||
965 | QUALS are the qualifiers for the this pointer. */ | |
966 | ||
967 | void | |
b370501f KG |
968 | grokclassfn (ctype, function, flags, quals) |
969 | tree ctype, function; | |
8d08fdba MS |
970 | enum overload_flags flags; |
971 | tree quals; | |
972 | { | |
973 | tree fn_name = DECL_NAME (function); | |
974 | tree arg_types; | |
975 | tree parm; | |
700f8a87 | 976 | tree qualtype; |
8d08fdba MS |
977 | |
978 | if (fn_name == NULL_TREE) | |
979 | { | |
8251199e | 980 | error ("name missing for member function"); |
8d08fdba MS |
981 | fn_name = get_identifier ("<anonymous>"); |
982 | DECL_NAME (function) = fn_name; | |
983 | } | |
984 | ||
985 | if (quals) | |
700f8a87 MS |
986 | qualtype = grok_method_quals (ctype, function, quals); |
987 | else | |
988 | qualtype = ctype; | |
8d08fdba MS |
989 | |
990 | arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); | |
991 | if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE) | |
992 | { | |
993 | /* Must add the class instance variable up front. */ | |
994 | /* Right now we just make this a pointer. But later | |
995 | we may wish to make it special. */ | |
996 | tree type = TREE_VALUE (arg_types); | |
863adfc0 | 997 | int constp = 1; |
8d08fdba | 998 | |
2986ae00 MS |
999 | if ((flag_this_is_variable > 0) |
1000 | && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))) | |
863adfc0 | 1001 | constp = 0; |
2986ae00 | 1002 | |
8d08fdba MS |
1003 | parm = build_decl (PARM_DECL, this_identifier, type); |
1004 | /* Mark the artificial `this' parameter as "artificial". */ | |
700f8a87 | 1005 | SET_DECL_ARTIFICIAL (parm); |
8d08fdba MS |
1006 | DECL_ARG_TYPE (parm) = type; |
1007 | /* We can make this a register, so long as we don't | |
1008 | accidentally complain if someone tries to take its address. */ | |
1009 | DECL_REGISTER (parm) = 1; | |
863adfc0 | 1010 | if (constp) |
8d08fdba MS |
1011 | TREE_READONLY (parm) = 1; |
1012 | TREE_CHAIN (parm) = last_function_parms; | |
1013 | last_function_parms = parm; | |
1014 | } | |
1015 | ||
711734a9 JM |
1016 | DECL_ARGUMENTS (function) = last_function_parms; |
1017 | /* First approximations. */ | |
1018 | DECL_CONTEXT (function) = ctype; | |
1019 | DECL_CLASS_CONTEXT (function) = ctype; | |
1020 | ||
1021 | if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)) | |
1022 | { | |
1023 | maybe_retrofit_in_chrg (function); | |
1024 | arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); | |
1025 | } | |
1026 | ||
8d08fdba MS |
1027 | if (flags == DTOR_FLAG) |
1028 | { | |
711734a9 | 1029 | DECL_ASSEMBLER_NAME (function) = build_destructor_name (ctype); |
8d08fdba MS |
1030 | TYPE_HAS_DESTRUCTOR (ctype) = 1; |
1031 | } | |
1032 | else | |
36a117a5 | 1033 | set_mangled_name_for_decl (function); |
8d08fdba MS |
1034 | } |
1035 | ||
1036 | /* Work on the expr used by alignof (this is only called by the parser). */ | |
e92cc029 | 1037 | |
8d08fdba MS |
1038 | tree |
1039 | grok_alignof (expr) | |
1040 | tree expr; | |
1041 | { | |
1042 | tree best, t; | |
1043 | int bestalign; | |
1044 | ||
abff8e06 JM |
1045 | if (processing_template_decl) |
1046 | return build_min (ALIGNOF_EXPR, sizetype, expr); | |
1047 | ||
8d08fdba | 1048 | if (TREE_CODE (expr) == COMPONENT_REF |
162bc98d | 1049 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1))) |
8251199e | 1050 | error ("`__alignof__' applied to a bit-field"); |
8d08fdba MS |
1051 | |
1052 | if (TREE_CODE (expr) == INDIRECT_REF) | |
1053 | { | |
1054 | best = t = TREE_OPERAND (expr, 0); | |
1055 | bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); | |
1056 | ||
1057 | while (TREE_CODE (t) == NOP_EXPR | |
1058 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE) | |
1059 | { | |
1060 | int thisalign; | |
1061 | t = TREE_OPERAND (t, 0); | |
1062 | thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); | |
1063 | if (thisalign > bestalign) | |
1064 | best = t, bestalign = thisalign; | |
1065 | } | |
1066 | return c_alignof (TREE_TYPE (TREE_TYPE (best))); | |
1067 | } | |
1068 | else | |
1069 | { | |
1070 | /* ANSI says arrays and fns are converted inside comma. | |
1071 | But we can't convert them in build_compound_expr | |
1072 | because that would break commas in lvalues. | |
1073 | So do the conversion here if operand was a comma. */ | |
1074 | if (TREE_CODE (expr) == COMPOUND_EXPR | |
1075 | && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE | |
1076 | || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)) | |
1077 | expr = default_conversion (expr); | |
1078 | return c_alignof (TREE_TYPE (expr)); | |
1079 | } | |
1080 | } | |
1081 | ||
1082 | /* Create an ARRAY_REF, checking for the user doing things backwards | |
1083 | along the way. */ | |
e92cc029 | 1084 | |
8d08fdba MS |
1085 | tree |
1086 | grok_array_decl (array_expr, index_exp) | |
1087 | tree array_expr, index_exp; | |
1088 | { | |
1089 | tree type = TREE_TYPE (array_expr); | |
b7484fbe | 1090 | tree p1, p2, i1, i2; |
8d08fdba MS |
1091 | |
1092 | if (type == error_mark_node || index_exp == error_mark_node) | |
1093 | return error_mark_node; | |
5156628f | 1094 | if (processing_template_decl) |
5566b478 MS |
1095 | return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE, |
1096 | array_expr, index_exp); | |
1097 | ||
8d08fdba MS |
1098 | if (type == NULL_TREE) |
1099 | { | |
1100 | /* Something has gone very wrong. Assume we are mistakenly reducing | |
1101 | an expression instead of a declaration. */ | |
8251199e | 1102 | error ("parser may be lost: is there a '{' missing somewhere?"); |
8d08fdba MS |
1103 | return NULL_TREE; |
1104 | } | |
1105 | ||
1106 | if (TREE_CODE (type) == OFFSET_TYPE | |
1107 | || TREE_CODE (type) == REFERENCE_TYPE) | |
1108 | type = TREE_TYPE (type); | |
1109 | ||
1110 | /* If they have an `operator[]', use that. */ | |
3c215895 | 1111 | if (IS_AGGR_TYPE (type) || IS_AGGR_TYPE (TREE_TYPE (index_exp))) |
8d08fdba | 1112 | return build_opfncall (ARRAY_REF, LOOKUP_NORMAL, |
00595019 | 1113 | array_expr, index_exp, NULL_TREE); |
8d08fdba | 1114 | |
03d0f4af MM |
1115 | /* Otherwise, create an ARRAY_REF for a pointer or array type. It |
1116 | is a little-known fact that, if `a' is an array and `i' is an | |
1117 | int, you can write `i[a]', which means the same thing as `a[i]'. */ | |
8d08fdba | 1118 | |
b7484fbe MS |
1119 | if (TREE_CODE (type) == ARRAY_TYPE) |
1120 | p1 = array_expr; | |
1121 | else | |
1122 | p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0); | |
8d08fdba | 1123 | |
b7484fbe MS |
1124 | if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE) |
1125 | p2 = index_exp; | |
1126 | else | |
1127 | p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0); | |
8d08fdba | 1128 | |
b7484fbe MS |
1129 | i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0); |
1130 | i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0); | |
8d08fdba | 1131 | |
b7484fbe | 1132 | if ((p1 && i2) && (i1 && p2)) |
8251199e | 1133 | error ("ambiguous conversion for array subscript"); |
8d08fdba | 1134 | |
b7484fbe MS |
1135 | if (p1 && i2) |
1136 | array_expr = p1, index_exp = i2; | |
1137 | else if (i1 && p2) | |
1138 | array_expr = p2, index_exp = i1; | |
1139 | else | |
1140 | { | |
8251199e | 1141 | cp_error ("invalid types `%T[%T]' for array subscript", |
b7484fbe MS |
1142 | type, TREE_TYPE (index_exp)); |
1143 | return error_mark_node; | |
1144 | } | |
1145 | ||
1146 | if (array_expr == error_mark_node || index_exp == error_mark_node) | |
8251199e | 1147 | error ("ambiguous conversion for array subscript"); |
b7484fbe MS |
1148 | |
1149 | return build_array_ref (array_expr, index_exp); | |
8d08fdba MS |
1150 | } |
1151 | ||
1152 | /* Given the cast expression EXP, checking out its validity. Either return | |
1153 | an error_mark_node if there was an unavoidable error, return a cast to | |
1154 | void for trying to delete a pointer w/ the value 0, or return the | |
1155 | call to delete. If DOING_VEC is 1, we handle things differently | |
1156 | for doing an array delete. If DOING_VEC is 2, they gave us the | |
1157 | array size as an argument to delete. | |
1158 | Implements ARM $5.3.4. This is called from the parser. */ | |
e92cc029 | 1159 | |
8d08fdba MS |
1160 | tree |
1161 | delete_sanity (exp, size, doing_vec, use_global_delete) | |
1162 | tree exp, size; | |
1163 | int doing_vec, use_global_delete; | |
1164 | { | |
02020185 | 1165 | tree t, type; |
8d08fdba MS |
1166 | /* For a regular vector delete (aka, no size argument) we will pass |
1167 | this down as a NULL_TREE into build_vec_delete. */ | |
1168 | tree maxindex = NULL_TREE; | |
5566b478 | 1169 | |
909e536a MS |
1170 | if (exp == error_mark_node) |
1171 | return exp; | |
1172 | ||
5156628f | 1173 | if (processing_template_decl) |
5566b478 MS |
1174 | { |
1175 | t = build_min (DELETE_EXPR, void_type_node, exp, size); | |
1176 | DELETE_EXPR_USE_GLOBAL (t) = use_global_delete; | |
1177 | DELETE_EXPR_USE_VEC (t) = doing_vec; | |
1178 | return t; | |
1179 | } | |
1180 | ||
02020185 JM |
1181 | if (TREE_CODE (exp) == OFFSET_REF) |
1182 | exp = resolve_offset_ref (exp); | |
1183 | exp = convert_from_reference (exp); | |
1184 | t = stabilize_reference (exp); | |
1185 | t = build_expr_type_conversion (WANT_POINTER, t, 1); | |
8d08fdba | 1186 | |
02020185 | 1187 | if (t == NULL_TREE || t == error_mark_node) |
8d08fdba | 1188 | { |
8251199e | 1189 | cp_error ("type `%#T' argument given to `delete', expected pointer", |
02020185 JM |
1190 | TREE_TYPE (exp)); |
1191 | return error_mark_node; | |
8d08fdba MS |
1192 | } |
1193 | ||
02020185 | 1194 | if (doing_vec == 2) |
8d08fdba | 1195 | { |
02020185 | 1196 | maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1); |
8251199e | 1197 | pedwarn ("anachronistic use of array size in vector delete"); |
8d08fdba MS |
1198 | } |
1199 | ||
02020185 JM |
1200 | type = TREE_TYPE (t); |
1201 | ||
1202 | /* As of Valley Forge, you can delete a pointer to const. */ | |
1203 | ||
1204 | /* You can't delete functions. */ | |
1205 | if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) | |
8926095f | 1206 | { |
8251199e | 1207 | error ("cannot delete a function"); |
02020185 | 1208 | return error_mark_node; |
8926095f | 1209 | } |
02020185 JM |
1210 | |
1211 | /* An array can't have been allocated by new, so complain. */ | |
1212 | if (TREE_CODE (t) == ADDR_EXPR | |
1213 | && TREE_CODE (TREE_OPERAND (t, 0)) == VAR_DECL | |
1214 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == ARRAY_TYPE) | |
8251199e | 1215 | cp_warning ("deleting array `%#D'", TREE_OPERAND (t, 0)); |
02020185 JM |
1216 | |
1217 | /* Deleting a pointer with the value zero is valid and has no effect. */ | |
1218 | if (integer_zerop (t)) | |
1219 | return build1 (NOP_EXPR, void_type_node, t); | |
8d08fdba MS |
1220 | |
1221 | if (doing_vec) | |
5566b478 | 1222 | return build_vec_delete (t, maxindex, integer_one_node, |
a28e3c7f | 1223 | integer_two_node, use_global_delete); |
8d08fdba | 1224 | else |
863adfc0 MS |
1225 | { |
1226 | if (IS_AGGR_TYPE (TREE_TYPE (type)) | |
1227 | && TYPE_GETS_REG_DELETE (TREE_TYPE (type))) | |
1228 | { | |
1229 | /* Only do access checking here; we'll be calling op delete | |
1230 | from the destructor. */ | |
519ebd1e JM |
1231 | tree tmp = build_op_delete_call (DELETE_EXPR, t, size_zero_node, |
1232 | LOOKUP_NORMAL, NULL_TREE); | |
863adfc0 MS |
1233 | if (tmp == error_mark_node) |
1234 | return error_mark_node; | |
1235 | } | |
1236 | ||
1237 | return build_delete (type, t, integer_three_node, | |
bd6dd845 | 1238 | LOOKUP_NORMAL, use_global_delete); |
863adfc0 | 1239 | } |
8d08fdba MS |
1240 | } |
1241 | ||
98c1c668 JM |
1242 | /* Report an error if the indicated template declaration is not the |
1243 | sort of thing that should be a member template. */ | |
1244 | ||
1245 | void | |
1246 | check_member_template (tmpl) | |
1247 | tree tmpl; | |
1248 | { | |
1249 | tree decl; | |
1250 | ||
1251 | my_friendly_assert (TREE_CODE (tmpl) == TEMPLATE_DECL, 0); | |
1252 | decl = DECL_TEMPLATE_RESULT (tmpl); | |
1253 | ||
1701f21e MM |
1254 | if (TREE_CODE (decl) == FUNCTION_DECL |
1255 | || (TREE_CODE (decl) == TYPE_DECL | |
1256 | && IS_AGGR_TYPE (TREE_TYPE (decl)))) | |
98c1c668 JM |
1257 | { |
1258 | if (current_function_decl) | |
1259 | /* 14.5.2.2 [temp.mem] | |
1260 | ||
1261 | A local class shall not have member templates. */ | |
8251199e | 1262 | cp_error ("declaration of member template `%#D' in local class", |
98c1c668 JM |
1263 | decl); |
1264 | ||
1701f21e | 1265 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) |
98c1c668 JM |
1266 | { |
1267 | /* 14.5.2.3 [temp.mem] | |
1268 | ||
1269 | A member function template shall not be virtual. */ | |
8251199e JM |
1270 | cp_error |
1271 | ("invalid use of `virtual' in template declaration of `%#D'", | |
98c1c668 JM |
1272 | decl); |
1273 | DECL_VIRTUAL_P (decl) = 0; | |
1274 | } | |
1275 | ||
1276 | /* The debug-information generating code doesn't know what to do | |
1277 | with member templates. */ | |
1278 | DECL_IGNORED_P (tmpl) = 1; | |
1279 | } | |
98c1c668 | 1280 | else |
8251199e | 1281 | cp_error ("template declaration of `%#D'", decl); |
98c1c668 JM |
1282 | } |
1283 | ||
eff71ab0 PB |
1284 | /* Return true iff TYPE is a valid Java parameter or return type. */ |
1285 | ||
1286 | int | |
1287 | acceptable_java_type (type) | |
1288 | tree type; | |
1289 | { | |
1290 | if (TREE_CODE (type) == VOID_TYPE || TYPE_FOR_JAVA (type)) | |
1291 | return 1; | |
1292 | if (TREE_CODE (type) == POINTER_TYPE) | |
1293 | { | |
1294 | type = TREE_TYPE (type); | |
1295 | if (TREE_CODE (type) == RECORD_TYPE) | |
1296 | { | |
824f42ab PB |
1297 | tree args; int i; |
1298 | if (! TYPE_FOR_JAVA (type)) | |
1299 | return 0; | |
1300 | if (! CLASSTYPE_TEMPLATE_INFO (type)) | |
1301 | return 1; | |
1302 | args = CLASSTYPE_TI_ARGS (type); | |
1303 | i = TREE_VEC_LENGTH (args); | |
1304 | while (--i >= 0) | |
1305 | { | |
1306 | type = TREE_VEC_ELT (args, i); | |
1307 | if (TREE_CODE (type) == POINTER_TYPE) | |
1308 | type = TREE_TYPE (type); | |
1309 | if (! TYPE_FOR_JAVA (type)) | |
1310 | return 0; | |
1311 | } | |
1312 | return 1; | |
eff71ab0 PB |
1313 | } |
1314 | } | |
1315 | return 0; | |
1316 | } | |
1317 | ||
1318 | /* For a METHOD in a Java class CTYPE, return 1 if | |
1319 | the parameter and return types are valid Java types. | |
1320 | Otherwise, print appropriate error messages, and return 0. */ | |
1321 | ||
1322 | int | |
b370501f KG |
1323 | check_java_method (method) |
1324 | tree method; | |
eff71ab0 PB |
1325 | { |
1326 | int jerr = 0; | |
1327 | tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (method)); | |
1328 | tree ret_type = TREE_TYPE (TREE_TYPE (method)); | |
1329 | if (! acceptable_java_type (ret_type)) | |
1330 | { | |
8251199e | 1331 | cp_error ("Java method '%D' has non-Java return type `%T'", |
eff71ab0 PB |
1332 | method, ret_type); |
1333 | jerr++; | |
1334 | } | |
1335 | for (; arg_types != NULL_TREE; arg_types = TREE_CHAIN (arg_types)) | |
1336 | { | |
1337 | tree type = TREE_VALUE (arg_types); | |
1338 | if (! acceptable_java_type (type)) | |
1339 | { | |
8251199e | 1340 | cp_error ("Java method '%D' has non-Java parameter type `%T'", |
eff71ab0 PB |
1341 | method, type); |
1342 | jerr++; | |
1343 | } | |
1344 | } | |
1345 | return jerr ? 0 : 1; | |
1346 | } | |
1347 | ||
8d08fdba MS |
1348 | /* Sanity check: report error if this function FUNCTION is not |
1349 | really a member of the class (CTYPE) it is supposed to belong to. | |
1350 | CNAME is the same here as it is for grokclassfn above. */ | |
1351 | ||
f30432d7 | 1352 | tree |
5566b478 MS |
1353 | check_classfn (ctype, function) |
1354 | tree ctype, function; | |
8d08fdba MS |
1355 | { |
1356 | tree fn_name = DECL_NAME (function); | |
2c73f9f5 | 1357 | tree fndecl, fndecls; |
5566b478 | 1358 | tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype)); |
8d08fdba MS |
1359 | tree *methods = 0; |
1360 | tree *end = 0; | |
98c1c668 | 1361 | tree templates = NULL_TREE; |
8d08fdba MS |
1362 | |
1363 | if (method_vec != 0) | |
1364 | { | |
1365 | methods = &TREE_VEC_ELT (method_vec, 0); | |
1366 | end = TREE_VEC_END (method_vec); | |
1367 | ||
1368 | /* First suss out ctors and dtors. */ | |
2c73f9f5 | 1369 | if (*methods && fn_name == DECL_NAME (OVL_CURRENT (*methods)) |
fc378698 MS |
1370 | && DECL_CONSTRUCTOR_P (function)) |
1371 | goto got_it; | |
2c73f9f5 | 1372 | if (*++methods && fn_name == DECL_NAME (OVL_CURRENT (*methods)) |
fc378698 | 1373 | && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function))) |
8d08fdba MS |
1374 | goto got_it; |
1375 | ||
61a127b3 | 1376 | while (++methods != end && *methods) |
8d08fdba | 1377 | { |
98c1c668 | 1378 | fndecl = *methods; |
2c73f9f5 | 1379 | if (fn_name == DECL_NAME (OVL_CURRENT (*methods))) |
8d08fdba MS |
1380 | { |
1381 | got_it: | |
2c73f9f5 ML |
1382 | for (fndecls = *methods; fndecls != NULL_TREE; |
1383 | fndecls = OVL_NEXT (fndecls)) | |
8d08fdba | 1384 | { |
2c73f9f5 | 1385 | fndecl = OVL_CURRENT (fndecls); |
6b4b3deb MM |
1386 | /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL, or |
1387 | for a for member function of a template class, is | |
f84b4be9 | 1388 | not mangled, so the check below does not work |
6b4b3deb MM |
1389 | correctly in that case. Since mangled destructor |
1390 | names do not include the type of the arguments, | |
1391 | we can't use this short-cut for them, either. | |
1392 | (It's not legal to declare arguments for a | |
1393 | destructor, but some people try.) */ | |
1394 | if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)) | |
1395 | && (DECL_ASSEMBLER_NAME (function) | |
1396 | != DECL_NAME (function)) | |
1397 | && (DECL_ASSEMBLER_NAME (fndecl) | |
1398 | != DECL_NAME (fndecl)) | |
f84b4be9 JM |
1399 | && (DECL_ASSEMBLER_NAME (function) |
1400 | == DECL_ASSEMBLER_NAME (fndecl))) | |
f30432d7 | 1401 | return fndecl; |
f84b4be9 JM |
1402 | |
1403 | /* We cannot simply call decls_match because this | |
1404 | doesn't work for static member functions that are | |
1405 | pretending to be methods, and because the name | |
1406 | may have been changed by asm("new_name"). */ | |
8145f082 MS |
1407 | if (DECL_NAME (function) == DECL_NAME (fndecl)) |
1408 | { | |
1409 | tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function)); | |
1410 | tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); | |
1411 | ||
1412 | /* Get rid of the this parameter on functions that become | |
e92cc029 | 1413 | static. */ |
8145f082 MS |
1414 | if (DECL_STATIC_FUNCTION_P (fndecl) |
1415 | && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE) | |
1416 | p1 = TREE_CHAIN (p1); | |
1417 | ||
1418 | if (comptypes (TREE_TYPE (TREE_TYPE (function)), | |
1419 | TREE_TYPE (TREE_TYPE (fndecl)), 1) | |
386b8a85 JM |
1420 | && compparms (p1, p2, 3) |
1421 | && (DECL_TEMPLATE_SPECIALIZATION (function) | |
1422 | == DECL_TEMPLATE_SPECIALIZATION (fndecl)) | |
1423 | && (!DECL_TEMPLATE_SPECIALIZATION (function) | |
1424 | || (DECL_TI_TEMPLATE (function) | |
1425 | == DECL_TI_TEMPLATE (fndecl)))) | |
5566b478 | 1426 | return fndecl; |
98c1c668 | 1427 | |
386b8a85 | 1428 | if (is_member_template (fndecl)) |
98c1c668 JM |
1429 | /* This function might be an instantiation |
1430 | or specialization of fndecl. */ | |
1431 | templates = | |
e66d884e | 1432 | scratch_tree_cons (NULL_TREE, fndecl, templates); |
8145f082 | 1433 | } |
8d08fdba MS |
1434 | } |
1435 | break; /* loser */ | |
1436 | } | |
98c1c668 JM |
1437 | else if (TREE_CODE (fndecl) == TEMPLATE_DECL |
1438 | && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl)) | |
1439 | && IDENTIFIER_TYPENAME_P (fn_name)) | |
1440 | /* The method in the class is a member template | |
1441 | conversion operator. We are declaring another | |
1442 | conversion operator. It is possible that even though | |
1443 | the names don't match, there is some specialization | |
1444 | occurring. */ | |
1445 | templates = | |
e66d884e | 1446 | scratch_tree_cons (NULL_TREE, fndecl, templates); |
8d08fdba MS |
1447 | } |
1448 | } | |
1449 | ||
98c1c668 JM |
1450 | if (templates) |
1451 | /* This function might be an instantiation or a specialization. | |
61a127b3 MM |
1452 | We should verify that this is possible. For now, we simply |
1453 | return NULL_TREE, which lets the caller know that this function | |
1454 | is new, but we don't print an error message. */ | |
98c1c668 JM |
1455 | return NULL_TREE; |
1456 | ||
61a127b3 | 1457 | if (methods != end && *methods) |
f30432d7 MS |
1458 | { |
1459 | tree fndecl = *methods; | |
8251199e | 1460 | cp_error ("prototype for `%#D' does not match any in class `%T'", |
f30432d7 | 1461 | function, ctype); |
8251199e | 1462 | cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl) ? "s are" : " is", |
2c73f9f5 ML |
1463 | OVL_CURRENT (fndecl)); |
1464 | while (fndecl = OVL_NEXT (fndecl), fndecl) | |
8251199e | 1465 | cp_error_at (" %#D", OVL_CURRENT(fndecl)); |
f30432d7 | 1466 | } |
8d08fdba MS |
1467 | else |
1468 | { | |
1469 | methods = 0; | |
8251199e | 1470 | cp_error ("no `%#D' member function declared in class `%T'", |
00595019 | 1471 | function, ctype); |
8d08fdba MS |
1472 | } |
1473 | ||
fc378698 | 1474 | /* If we did not find the method in the class, add it to avoid |
6b4b3deb MM |
1475 | spurious errors (unless the CTYPE is not yet defined, in which |
1476 | case we'll only confuse ourselves when the function is declared | |
1477 | properly within the class. */ | |
1478 | if (TYPE_SIZE (ctype)) | |
1479 | add_method (ctype, methods, function); | |
f30432d7 | 1480 | return NULL_TREE; |
8d08fdba MS |
1481 | } |
1482 | ||
1483 | /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted) | |
1484 | of a structure component, returning a FIELD_DECL node. | |
1485 | QUALS is a list of type qualifiers for this decl (such as for declaring | |
1486 | const member functions). | |
1487 | ||
1488 | This is done during the parsing of the struct declaration. | |
1489 | The FIELD_DECL nodes are chained together and the lot of them | |
1490 | are ultimately passed to `build_struct' to make the RECORD_TYPE node. | |
1491 | ||
1492 | C++: | |
1493 | ||
1494 | If class A defines that certain functions in class B are friends, then | |
1495 | the way I have set things up, it is B who is interested in permission | |
1496 | granted by A. However, it is in A's context that these declarations | |
1497 | are parsed. By returning a void_type_node, class A does not attempt | |
1498 | to incorporate the declarations of the friends within its structure. | |
1499 | ||
1500 | DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING | |
1501 | CHANGES TO CODE IN `start_method'. */ | |
1502 | ||
1503 | tree | |
c11b6f21 MS |
1504 | grokfield (declarator, declspecs, init, asmspec_tree, attrlist) |
1505 | tree declarator, declspecs, init, asmspec_tree, attrlist; | |
8d08fdba MS |
1506 | { |
1507 | register tree value; | |
1508 | char *asmspec = 0; | |
6060a796 | 1509 | int flags = LOOKUP_ONLYCONVERTING; |
8d08fdba MS |
1510 | |
1511 | /* Convert () initializers to = initializers. */ | |
1512 | if (init == NULL_TREE && declarator != NULL_TREE | |
1513 | && TREE_CODE (declarator) == CALL_EXPR | |
1514 | && TREE_OPERAND (declarator, 0) | |
1515 | && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE | |
1516 | || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF) | |
1517 | && parmlist_is_exprlist (TREE_OPERAND (declarator, 1))) | |
1518 | { | |
1519 | init = TREE_OPERAND (declarator, 1); | |
1520 | declarator = TREE_OPERAND (declarator, 0); | |
6060a796 | 1521 | flags = 0; |
8d08fdba MS |
1522 | } |
1523 | ||
cffa8729 | 1524 | if (declspecs == NULL_TREE |
7fcdf4c2 MS |
1525 | && TREE_CODE (declarator) == SCOPE_REF |
1526 | && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE) | |
cffa8729 MS |
1527 | { |
1528 | /* Access declaration */ | |
5566b478 MS |
1529 | if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0)))) |
1530 | ; | |
1531 | else if (TREE_COMPLEXITY (declarator) == current_class_depth) | |
cffa8729 MS |
1532 | pop_nested_class (1); |
1533 | return do_class_using_decl (declarator); | |
1534 | } | |
1535 | ||
8d08fdba MS |
1536 | if (init |
1537 | && TREE_CODE (init) == TREE_LIST | |
1538 | && TREE_VALUE (init) == error_mark_node | |
1539 | && TREE_CHAIN (init) == NULL_TREE) | |
cffa8729 | 1540 | init = NULL_TREE; |
8d08fdba | 1541 | |
c11b6f21 | 1542 | value = grokdeclarator (declarator, declspecs, FIELD, init != 0, NULL_TREE); |
6c30752f | 1543 | if (! value || value == error_mark_node) |
3ddfb0e6 MM |
1544 | /* friend or constructor went bad. */ |
1545 | return value; | |
8d08fdba MS |
1546 | |
1547 | /* Pass friendly classes back. */ | |
1548 | if (TREE_CODE (value) == VOID_TYPE) | |
1549 | return void_type_node; | |
1550 | ||
1551 | if (DECL_NAME (value) != NULL_TREE | |
1552 | && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_' | |
1553 | && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr")) | |
8251199e | 1554 | cp_error ("member `%D' conflicts with virtual function table field name", |
3c215895 | 1555 | value); |
8d08fdba MS |
1556 | |
1557 | /* Stash away type declarations. */ | |
1558 | if (TREE_CODE (value) == TYPE_DECL) | |
1559 | { | |
1560 | DECL_NONLOCAL (value) = 1; | |
700f8a87 MS |
1561 | DECL_CONTEXT (value) = current_class_type; |
1562 | DECL_CLASS_CONTEXT (value) = current_class_type; | |
8145f082 | 1563 | |
61cd1234 MM |
1564 | /* Now that we've updated the context, we need to remangle the |
1565 | name for this TYPE_DECL. */ | |
1566 | DECL_ASSEMBLER_NAME (value) = DECL_NAME (value); | |
35fce3ce MM |
1567 | if (!uses_template_parms (value)) |
1568 | DECL_ASSEMBLER_NAME (value) = | |
1569 | get_identifier (build_overload_name (TREE_TYPE (value), 1, 1)); | |
61cd1234 | 1570 | |
8ccc31eb | 1571 | pushdecl_class_level (value); |
8d08fdba MS |
1572 | return value; |
1573 | } | |
1574 | ||
1575 | if (IS_SIGNATURE (current_class_type) | |
1576 | && TREE_CODE (value) != FUNCTION_DECL) | |
1577 | { | |
8251199e | 1578 | error ("field declaration not allowed in signature"); |
8d08fdba MS |
1579 | return void_type_node; |
1580 | } | |
1581 | ||
1582 | if (DECL_IN_AGGR_P (value)) | |
1583 | { | |
6b4b3deb MM |
1584 | cp_error ("`%D' is already defined in `%T'", value, |
1585 | DECL_CONTEXT (value)); | |
8d08fdba MS |
1586 | return void_type_node; |
1587 | } | |
1588 | ||
8d08fdba MS |
1589 | if (asmspec_tree) |
1590 | asmspec = TREE_STRING_POINTER (asmspec_tree); | |
1591 | ||
1592 | if (init) | |
1593 | { | |
1594 | if (IS_SIGNATURE (current_class_type) | |
1595 | && TREE_CODE (value) == FUNCTION_DECL) | |
1596 | { | |
8251199e | 1597 | error ("function declarations cannot have initializers in signature"); |
8d08fdba MS |
1598 | init = NULL_TREE; |
1599 | } | |
1600 | else if (TREE_CODE (value) == FUNCTION_DECL) | |
1601 | { | |
1602 | grok_function_init (value, init); | |
1603 | init = NULL_TREE; | |
1604 | } | |
5b605f68 | 1605 | else if (pedantic && TREE_CODE (value) != VAR_DECL) |
a0a33927 MS |
1606 | /* Already complained in grokdeclarator. */ |
1607 | init = NULL_TREE; | |
8d08fdba MS |
1608 | else |
1609 | { | |
a0a33927 MS |
1610 | /* We allow initializers to become parameters to base |
1611 | initializers. */ | |
8d08fdba MS |
1612 | if (TREE_CODE (init) == TREE_LIST) |
1613 | { | |
1614 | if (TREE_CHAIN (init) == NULL_TREE) | |
1615 | init = TREE_VALUE (init); | |
1616 | else | |
1617 | init = digest_init (TREE_TYPE (value), init, (tree *)0); | |
1618 | } | |
1619 | ||
1620 | if (TREE_CODE (init) == CONST_DECL) | |
1621 | init = DECL_INITIAL (init); | |
1622 | else if (TREE_READONLY_DECL_P (init)) | |
1623 | init = decl_constant_value (init); | |
1624 | else if (TREE_CODE (init) == CONSTRUCTOR) | |
1625 | init = digest_init (TREE_TYPE (value), init, (tree *)0); | |
1626 | my_friendly_assert (TREE_PERMANENT (init), 192); | |
1627 | if (init == error_mark_node) | |
1628 | /* We must make this look different than `error_mark_node' | |
1629 | because `decl_const_value' would mis-interpret it | |
1630 | as only meaning that this VAR_DECL is defined. */ | |
1631 | init = build1 (NOP_EXPR, TREE_TYPE (value), init); | |
5156628f | 1632 | else if (processing_template_decl) |
5566b478 | 1633 | ; |
8d08fdba MS |
1634 | else if (! TREE_CONSTANT (init)) |
1635 | { | |
1636 | /* We can allow references to things that are effectively | |
1637 | static, since references are initialized with the address. */ | |
1638 | if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE | |
1639 | || (TREE_STATIC (init) == 0 | |
1640 | && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd' | |
1641 | || DECL_EXTERNAL (init) == 0))) | |
1642 | { | |
8251199e | 1643 | error ("field initializer is not constant"); |
8d08fdba MS |
1644 | init = error_mark_node; |
1645 | } | |
1646 | } | |
1647 | } | |
1648 | } | |
1649 | ||
b3417a04 | 1650 | /* The corresponding pop_obstacks is in cp_finish_decl. */ |
8d08fdba MS |
1651 | push_obstacks_nochange (); |
1652 | ||
5156628f | 1653 | if (processing_template_decl && ! current_function_decl |
5566b478 | 1654 | && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL)) |
3ac3d9ea | 1655 | value = push_template_decl (value); |
5566b478 | 1656 | |
2450bb7d BK |
1657 | /* Check to see if a field redeclares a template parameter. */ |
1658 | if (current_template_parms | |
1659 | && TREE_CODE (declarator) == IDENTIFIER_NODE | |
1660 | && IDENTIFIER_LOCAL_VALUE (declarator)) | |
1661 | { | |
1662 | tree olddecl = IDENTIFIER_LOCAL_VALUE (declarator); | |
1663 | if (decl_template_parm_p (olddecl)) | |
1664 | { | |
8251199e JM |
1665 | cp_error ("redeclaration of template parameter `%T'", declarator); |
1666 | cp_error_at (" previously declared here `%#D'", olddecl); | |
2450bb7d BK |
1667 | } |
1668 | } | |
1669 | ||
45537677 MS |
1670 | if (attrlist) |
1671 | cplus_decl_attributes (value, TREE_PURPOSE (attrlist), | |
1672 | TREE_VALUE (attrlist)); | |
1673 | ||
8d08fdba MS |
1674 | if (TREE_CODE (value) == VAR_DECL) |
1675 | { | |
3ac3d9ea MM |
1676 | my_friendly_assert (TREE_PUBLIC (value), 0); |
1677 | ||
8d08fdba MS |
1678 | /* We cannot call pushdecl here, because that would |
1679 | fill in the value of our TREE_CHAIN. Instead, we | |
b3417a04 | 1680 | modify cp_finish_decl to do the right thing, namely, to |
8d08fdba | 1681 | put this decl out straight away. */ |
3ac3d9ea MM |
1682 | /* current_class_type can be NULL_TREE in case of error. */ |
1683 | if (asmspec == 0 && current_class_type) | |
8d08fdba | 1684 | { |
3ac3d9ea MM |
1685 | TREE_PUBLIC (value) = 1; |
1686 | DECL_INITIAL (value) = error_mark_node; | |
1687 | DECL_ASSEMBLER_NAME (value) | |
1688 | = build_static_name (current_class_type, DECL_NAME (value)); | |
1689 | } | |
1690 | if (! processing_template_decl) | |
1691 | pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics); | |
1692 | ||
1693 | /* Static consts need not be initialized in the class definition. */ | |
1694 | if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value))) | |
1695 | { | |
1696 | static int explanation = 0; | |
1697 | ||
8251199e | 1698 | error ("initializer invalid for static member with constructor"); |
3ac3d9ea | 1699 | if (explanation++ == 0) |
8251199e | 1700 | error ("(you really want to initialize it separately)"); |
3ac3d9ea | 1701 | init = 0; |
8d08fdba | 1702 | } |
3ac3d9ea MM |
1703 | /* Force the compiler to know when an uninitialized static |
1704 | const member is being used. */ | |
1705 | if (TYPE_READONLY (value) && init == 0) | |
1706 | TREE_USED (value) = 1; | |
8d08fdba MS |
1707 | DECL_INITIAL (value) = init; |
1708 | DECL_IN_AGGR_P (value) = 1; | |
5566b478 MS |
1709 | DECL_CONTEXT (value) = current_class_type; |
1710 | DECL_CLASS_CONTEXT (value) = current_class_type; | |
8d08fdba | 1711 | |
b3417a04 | 1712 | cp_finish_decl (value, init, asmspec_tree, 1, flags); |
8d08fdba MS |
1713 | pushdecl_class_level (value); |
1714 | return value; | |
1715 | } | |
1716 | if (TREE_CODE (value) == FIELD_DECL) | |
1717 | { | |
1718 | if (asmspec) | |
6060a796 MS |
1719 | { |
1720 | /* This must override the asm specifier which was placed | |
1721 | by grokclassfn. Lay this out fresh. */ | |
1722 | DECL_RTL (value) = NULL_RTX; | |
1723 | DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec); | |
1724 | } | |
8d08fdba MS |
1725 | if (DECL_INITIAL (value) == error_mark_node) |
1726 | init = error_mark_node; | |
b3417a04 | 1727 | cp_finish_decl (value, init, asmspec_tree, 1, flags); |
8d08fdba MS |
1728 | DECL_INITIAL (value) = init; |
1729 | DECL_IN_AGGR_P (value) = 1; | |
1730 | return value; | |
1731 | } | |
1732 | if (TREE_CODE (value) == FUNCTION_DECL) | |
1733 | { | |
6060a796 MS |
1734 | if (asmspec) |
1735 | { | |
1736 | /* This must override the asm specifier which was placed | |
1737 | by grokclassfn. Lay this out fresh. */ | |
1738 | DECL_RTL (value) = NULL_RTX; | |
1739 | DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec); | |
1740 | } | |
b3417a04 | 1741 | cp_finish_decl (value, init, asmspec_tree, 1, flags); |
8d08fdba MS |
1742 | |
1743 | /* Pass friends back this way. */ | |
1744 | if (DECL_FRIEND_P (value)) | |
1745 | return void_type_node; | |
1746 | ||
f376e137 | 1747 | #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */ |
a0a33927 | 1748 | if (current_function_decl && ! IS_SIGNATURE (current_class_type)) |
8251199e | 1749 | cp_error ("method `%#D' of local class must be defined in class body", |
7177d104 | 1750 | value); |
f376e137 | 1751 | #endif |
7177d104 | 1752 | |
8d08fdba MS |
1753 | DECL_IN_AGGR_P (value) = 1; |
1754 | return value; | |
1755 | } | |
1756 | my_friendly_abort (21); | |
1757 | /* NOTREACHED */ | |
1758 | return NULL_TREE; | |
1759 | } | |
1760 | ||
1761 | /* Like `grokfield', but for bitfields. | |
1762 | WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */ | |
1763 | ||
1764 | tree | |
1765 | grokbitfield (declarator, declspecs, width) | |
1766 | tree declarator, declspecs, width; | |
1767 | { | |
f30432d7 | 1768 | register tree value = grokdeclarator (declarator, declspecs, BITFIELD, |
c11b6f21 | 1769 | 0, NULL_TREE); |
8d08fdba MS |
1770 | |
1771 | if (! value) return NULL_TREE; /* friends went bad. */ | |
1772 | ||
1773 | /* Pass friendly classes back. */ | |
1774 | if (TREE_CODE (value) == VOID_TYPE) | |
1775 | return void_type_node; | |
1776 | ||
1777 | if (TREE_CODE (value) == TYPE_DECL) | |
1778 | { | |
8251199e | 1779 | cp_error ("cannot declare `%D' to be a bitfield type", value); |
8d08fdba MS |
1780 | return NULL_TREE; |
1781 | } | |
1782 | ||
ae58fa02 MM |
1783 | /* Usually, finish_struct_1 catches bitifields with invalid types. |
1784 | But, in the case of bitfields with function type, we confuse | |
1785 | ourselves into thinking they are member functions, so we must | |
1786 | check here. */ | |
1787 | if (TREE_CODE (value) == FUNCTION_DECL) | |
1788 | { | |
8251199e | 1789 | cp_error ("cannot declare bitfield `%D' with funcion type", |
ae58fa02 MM |
1790 | DECL_NAME (value)); |
1791 | return NULL_TREE; | |
1792 | } | |
1793 | ||
8d08fdba MS |
1794 | if (IS_SIGNATURE (current_class_type)) |
1795 | { | |
8251199e | 1796 | error ("field declaration not allowed in signature"); |
8d08fdba MS |
1797 | return void_type_node; |
1798 | } | |
1799 | ||
1800 | if (DECL_IN_AGGR_P (value)) | |
1801 | { | |
8251199e | 1802 | cp_error ("`%D' is already defined in the class %T", value, |
8d08fdba MS |
1803 | DECL_CONTEXT (value)); |
1804 | return void_type_node; | |
1805 | } | |
1806 | ||
1807 | GNU_xref_member (current_class_name, value); | |
1808 | ||
1809 | if (TREE_STATIC (value)) | |
1810 | { | |
8251199e | 1811 | cp_error ("static member `%D' cannot be a bitfield", value); |
8d08fdba MS |
1812 | return NULL_TREE; |
1813 | } | |
b3417a04 | 1814 | cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0); |
8d08fdba MS |
1815 | |
1816 | if (width != error_mark_node) | |
1817 | { | |
5566b478 MS |
1818 | constant_expression_warning (width); |
1819 | DECL_INITIAL (value) = width; | |
162bc98d | 1820 | SET_DECL_C_BIT_FIELD (value); |
8d08fdba MS |
1821 | } |
1822 | ||
1823 | DECL_IN_AGGR_P (value) = 1; | |
1824 | return value; | |
1825 | } | |
1826 | ||
8d08fdba | 1827 | tree |
51c184be MS |
1828 | grokoptypename (declspecs, declarator) |
1829 | tree declspecs, declarator; | |
8d08fdba | 1830 | { |
c11b6f21 | 1831 | tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE); |
51c184be | 1832 | return build_typename_overload (t); |
8d08fdba MS |
1833 | } |
1834 | ||
1835 | /* When a function is declared with an initializer, | |
1836 | do the right thing. Currently, there are two possibilities: | |
1837 | ||
1838 | class B | |
1839 | { | |
1840 | public: | |
1841 | // initialization possibility #1. | |
1842 | virtual void f () = 0; | |
1843 | int g (); | |
1844 | }; | |
1845 | ||
1846 | class D1 : B | |
1847 | { | |
1848 | public: | |
1849 | int d1; | |
1850 | // error, no f (); | |
1851 | }; | |
1852 | ||
1853 | class D2 : B | |
1854 | { | |
1855 | public: | |
1856 | int d2; | |
1857 | void f (); | |
1858 | }; | |
1859 | ||
1860 | class D3 : B | |
1861 | { | |
1862 | public: | |
1863 | int d3; | |
1864 | // initialization possibility #2 | |
1865 | void f () = B::f; | |
1866 | }; | |
1867 | ||
1868 | */ | |
1869 | ||
f0e01782 MS |
1870 | int |
1871 | copy_assignment_arg_p (parmtype, virtualp) | |
1872 | tree parmtype; | |
b370501f | 1873 | int virtualp ATTRIBUTE_UNUSED; |
f0e01782 | 1874 | { |
691c003d MS |
1875 | if (current_class_type == NULL_TREE) |
1876 | return 0; | |
1877 | ||
f0e01782 MS |
1878 | if (TREE_CODE (parmtype) == REFERENCE_TYPE) |
1879 | parmtype = TREE_TYPE (parmtype); | |
1880 | ||
1881 | if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type) | |
824b9a4c MS |
1882 | #if 0 |
1883 | /* Non-standard hack to support old Booch components. */ | |
1884 | || (! virtualp && DERIVED_FROM_P (parmtype, current_class_type)) | |
1885 | #endif | |
1886 | ) | |
f0e01782 MS |
1887 | return 1; |
1888 | ||
1889 | return 0; | |
1890 | } | |
1891 | ||
8d08fdba MS |
1892 | static void |
1893 | grok_function_init (decl, init) | |
1894 | tree decl; | |
1895 | tree init; | |
1896 | { | |
1897 | /* An initializer for a function tells how this function should | |
1898 | be inherited. */ | |
1899 | tree type = TREE_TYPE (decl); | |
8d08fdba MS |
1900 | |
1901 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
8251199e | 1902 | cp_error ("initializer specified for non-member function `%D'", decl); |
cffa8729 MS |
1903 | #if 0 |
1904 | /* We'll check for this in finish_struct_1. */ | |
8d08fdba | 1905 | else if (DECL_VINDEX (decl) == NULL_TREE) |
8251199e | 1906 | cp_error ("initializer specified for non-virtual method `%D'", decl); |
cffa8729 | 1907 | #endif |
8d08fdba MS |
1908 | else if (integer_zerop (init)) |
1909 | { | |
8926095f | 1910 | #if 0 |
8d08fdba MS |
1911 | /* Mark this function as being "defined". */ |
1912 | DECL_INITIAL (decl) = error_mark_node; | |
e92cc029 | 1913 | /* pure virtual destructors must be defined. */ |
8926095f MS |
1914 | /* pure virtual needs to be defined (as abort) only when put in |
1915 | vtbl. For wellformed call, it should be itself. pr4737 */ | |
8d08fdba MS |
1916 | if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl))) |
1917 | { | |
8926095f | 1918 | extern tree abort_fndecl; |
8d08fdba MS |
1919 | /* Give this node rtl from `abort'. */ |
1920 | DECL_RTL (decl) = DECL_RTL (abort_fndecl); | |
1921 | } | |
8926095f | 1922 | #endif |
8d08fdba | 1923 | DECL_ABSTRACT_VIRTUAL_P (decl) = 1; |
f0e01782 MS |
1924 | if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR]) |
1925 | { | |
1926 | tree parmtype | |
1927 | = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))); | |
1928 | ||
1929 | if (copy_assignment_arg_p (parmtype, 1)) | |
1930 | TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1; | |
1931 | } | |
8d08fdba | 1932 | } |
8d08fdba | 1933 | else |
8251199e | 1934 | cp_error ("invalid initializer for virtual method `%D'", decl); |
8d08fdba MS |
1935 | } |
1936 | \f | |
28cbf42c MS |
1937 | void |
1938 | cplus_decl_attributes (decl, attributes, prefix_attributes) | |
f6abb50a | 1939 | tree decl, attributes, prefix_attributes; |
8d08fdba | 1940 | { |
e8abc66f MS |
1941 | if (decl == NULL_TREE || decl == void_type_node) |
1942 | return; | |
1943 | ||
1944 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
1945 | decl = DECL_TEMPLATE_RESULT (decl); | |
1946 | ||
1947 | decl_attributes (decl, attributes, prefix_attributes); | |
863adfc0 MS |
1948 | |
1949 | if (TREE_CODE (decl) == TYPE_DECL) | |
1950 | SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl)); | |
8d08fdba MS |
1951 | } |
1952 | \f | |
1953 | /* CONSTRUCTOR_NAME: | |
1954 | Return the name for the constructor (or destructor) for the | |
1955 | specified class. Argument can be RECORD_TYPE, TYPE_DECL, or | |
1956 | IDENTIFIER_NODE. When given a template, this routine doesn't | |
1957 | lose the specialization. */ | |
e92cc029 | 1958 | |
8d08fdba MS |
1959 | tree |
1960 | constructor_name_full (thing) | |
1961 | tree thing; | |
1962 | { | |
73b0fce8 | 1963 | if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM |
97e7cbe4 JM |
1964 | || TREE_CODE (thing) == TEMPLATE_TEMPLATE_PARM |
1965 | || TREE_CODE (thing) == TYPENAME_TYPE) | |
be99da77 MS |
1966 | thing = TYPE_NAME (thing); |
1967 | else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing))) | |
8d08fdba MS |
1968 | { |
1969 | if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing)) | |
42c7b807 | 1970 | thing = DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0))); |
8d08fdba MS |
1971 | else |
1972 | thing = TYPE_NAME (thing); | |
1973 | } | |
1974 | if (TREE_CODE (thing) == TYPE_DECL | |
1975 | || (TREE_CODE (thing) == TEMPLATE_DECL | |
5566b478 | 1976 | && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL)) |
8d08fdba MS |
1977 | thing = DECL_NAME (thing); |
1978 | my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197); | |
1979 | return thing; | |
1980 | } | |
1981 | ||
1982 | /* CONSTRUCTOR_NAME: | |
1983 | Return the name for the constructor (or destructor) for the | |
1984 | specified class. Argument can be RECORD_TYPE, TYPE_DECL, or | |
1985 | IDENTIFIER_NODE. When given a template, return the plain | |
1986 | unspecialized name. */ | |
e92cc029 | 1987 | |
8d08fdba MS |
1988 | tree |
1989 | constructor_name (thing) | |
1990 | tree thing; | |
1991 | { | |
1992 | tree t; | |
1993 | thing = constructor_name_full (thing); | |
1994 | t = IDENTIFIER_TEMPLATE (thing); | |
1995 | if (!t) | |
1996 | return thing; | |
5566b478 | 1997 | return t; |
8d08fdba MS |
1998 | } |
1999 | \f | |
2000 | /* Cache the value of this class's main virtual function table pointer | |
2001 | in a register variable. This will save one indirection if a | |
2002 | more than one virtual function call is made this function. */ | |
e92cc029 | 2003 | |
8d08fdba MS |
2004 | void |
2005 | setup_vtbl_ptr () | |
2006 | { | |
f30432d7 | 2007 | extern tree base_init_expr; |
8d08fdba | 2008 | |
a9aedbc2 | 2009 | if (base_init_expr == 0 |
8d08fdba | 2010 | && DECL_CONSTRUCTOR_P (current_function_decl)) |
5566b478 | 2011 | { |
5156628f | 2012 | if (processing_template_decl) |
5566b478 MS |
2013 | add_tree (build_min_nt |
2014 | (CTOR_INITIALIZER, | |
2015 | current_member_init_list, current_base_init_list)); | |
2016 | else | |
2017 | emit_base_init (current_class_type, 0); | |
2018 | } | |
8d08fdba MS |
2019 | } |
2020 | ||
2021 | /* Record the existence of an addressable inline function. */ | |
e92cc029 | 2022 | |
8d08fdba MS |
2023 | void |
2024 | mark_inline_for_output (decl) | |
2025 | tree decl; | |
2026 | { | |
6060a796 | 2027 | decl = DECL_MAIN_VARIANT (decl); |
8926095f MS |
2028 | if (DECL_SAVED_INLINE (decl)) |
2029 | return; | |
6060a796 | 2030 | my_friendly_assert (TREE_PERMANENT (decl), 363); |
8926095f | 2031 | DECL_SAVED_INLINE (decl) = 1; |
a5894242 | 2032 | #if 0 |
8d08fdba MS |
2033 | if (DECL_PENDING_INLINE_INFO (decl) != 0 |
2034 | && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu) | |
2035 | { | |
2036 | struct pending_inline *t = pending_inlines; | |
2037 | my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198); | |
2038 | while (t) | |
2039 | { | |
2040 | if (t == DECL_PENDING_INLINE_INFO (decl)) | |
2041 | break; | |
2042 | t = t->next; | |
2043 | } | |
2044 | if (t == 0) | |
2045 | { | |
2046 | t = DECL_PENDING_INLINE_INFO (decl); | |
2047 | t->next = pending_inlines; | |
2048 | pending_inlines = t; | |
2049 | } | |
2050 | DECL_PENDING_INLINE_INFO (decl) = 0; | |
2051 | } | |
a5894242 | 2052 | #endif |
8926095f | 2053 | saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines); |
8d08fdba MS |
2054 | } |
2055 | ||
2056 | void | |
2057 | clear_temp_name () | |
2058 | { | |
2059 | temp_name_counter = 0; | |
2060 | } | |
2061 | ||
2062 | /* Hand off a unique name which can be used for variable we don't really | |
2063 | want to know about anyway, for example, the anonymous variables which | |
2064 | are needed to make references work. Declare this thing so we can use it. | |
2065 | The variable created will be of type TYPE. | |
2066 | ||
2067 | STATICP is nonzero if this variable should be static. */ | |
2068 | ||
2069 | tree | |
2070 | get_temp_name (type, staticp) | |
2071 | tree type; | |
2072 | int staticp; | |
2073 | { | |
2074 | char buf[sizeof (AUTO_TEMP_FORMAT) + 20]; | |
2075 | tree decl; | |
a9aedbc2 | 2076 | int toplev = toplevel_bindings_p (); |
8d08fdba MS |
2077 | |
2078 | push_obstacks_nochange (); | |
2079 | if (toplev || staticp) | |
2080 | { | |
2081 | end_temporary_allocation (); | |
2082 | sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++); | |
2083 | decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type)); | |
2084 | } | |
2085 | else | |
2086 | { | |
2087 | sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++); | |
2088 | decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type)); | |
2089 | } | |
2090 | TREE_USED (decl) = 1; | |
2091 | TREE_STATIC (decl) = staticp; | |
fc378698 | 2092 | DECL_ARTIFICIAL (decl) = 1; |
8d08fdba MS |
2093 | |
2094 | /* If this is a local variable, then lay out its rtl now. | |
2095 | Otherwise, callers of this function are responsible for dealing | |
2096 | with this variable's rtl. */ | |
2097 | if (! toplev) | |
2098 | { | |
2099 | expand_decl (decl); | |
2100 | expand_decl_init (decl); | |
2101 | } | |
2102 | pop_obstacks (); | |
2103 | ||
2104 | return decl; | |
2105 | } | |
2106 | ||
2107 | /* Get a variable which we can use for multiple assignments. | |
2108 | It is not entered into current_binding_level, because | |
2109 | that breaks things when it comes time to do final cleanups | |
2110 | (which take place "outside" the binding contour of the function). */ | |
e92cc029 | 2111 | |
8d08fdba MS |
2112 | tree |
2113 | get_temp_regvar (type, init) | |
2114 | tree type, init; | |
2115 | { | |
8d08fdba MS |
2116 | tree decl; |
2117 | ||
a0d5fba7 | 2118 | decl = build_decl (VAR_DECL, NULL_TREE, type); |
8d08fdba MS |
2119 | TREE_USED (decl) = 1; |
2120 | DECL_REGISTER (decl) = 1; | |
a0d5fba7 | 2121 | DECL_ARTIFICIAL (decl) = 1; |
8d08fdba | 2122 | |
a0d5fba7 | 2123 | DECL_RTL (decl) = assign_temp (type, 2, 0, 1); |
8d08fdba MS |
2124 | /* We can expand these without fear, since they cannot need |
2125 | constructors or destructors. */ | |
a0d5fba7 JM |
2126 | expand_expr (build_modify_expr (decl, INIT_EXPR, init), |
2127 | NULL_RTX, VOIDmode, 0); | |
8d08fdba | 2128 | |
8d08fdba MS |
2129 | return decl; |
2130 | } | |
2131 | ||
cb96daa2 MM |
2132 | /* Hunts through the global anonymous union ANON_DECL, building |
2133 | appropriate VAR_DECLs. Stores cleanups on the list of ELEMS, and | |
2134 | returns a VAR_DECL whose size is the same as the size of the | |
2135 | ANON_DECL, if one is available. */ | |
ce1b9eb9 | 2136 | |
cb96daa2 MM |
2137 | tree |
2138 | build_anon_union_vars (anon_decl, elems, static_p, external_p) | |
ce1b9eb9 | 2139 | tree anon_decl; |
cb96daa2 MM |
2140 | tree* elems; |
2141 | int static_p; | |
2142 | int external_p; | |
ce1b9eb9 | 2143 | { |
cb96daa2 | 2144 | tree type = TREE_TYPE (anon_decl); |
ce1b9eb9 | 2145 | tree main_decl = NULL_TREE; |
cb96daa2 | 2146 | tree field; |
ce1b9eb9 | 2147 | |
cb96daa2 | 2148 | for (field = TYPE_FIELDS (type); |
ce1b9eb9 MM |
2149 | field != NULL_TREE; |
2150 | field = TREE_CHAIN (field)) | |
2151 | { | |
cb96daa2 | 2152 | tree decl; |
ce1b9eb9 MM |
2153 | if (TREE_CODE (field) != FIELD_DECL) |
2154 | continue; | |
2155 | ||
cb96daa2 | 2156 | if (TREE_PRIVATE (field)) |
8251199e | 2157 | cp_pedwarn_at ("private member `%#D' in anonymous union", field); |
cb96daa2 | 2158 | else if (TREE_PROTECTED (field)) |
8251199e | 2159 | cp_pedwarn_at ("protected member `%#D' in anonymous union", field); |
cb96daa2 MM |
2160 | |
2161 | if (DECL_NAME (field) == NULL_TREE | |
2162 | && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) | |
67ffc812 MM |
2163 | { |
2164 | decl = build_anon_union_vars (field, elems, static_p, external_p); | |
2165 | if (!decl) | |
2166 | continue; | |
2167 | } | |
18141e4c JM |
2168 | else if (DECL_NAME (field) == NULL_TREE) |
2169 | continue; | |
cb96daa2 MM |
2170 | else |
2171 | { | |
2172 | decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field)); | |
2173 | /* tell `pushdecl' that this is not tentative. */ | |
2174 | DECL_INITIAL (decl) = error_mark_node; | |
2175 | TREE_PUBLIC (decl) = 0; | |
2176 | TREE_STATIC (decl) = static_p; | |
2177 | DECL_EXTERNAL (decl) = external_p; | |
2178 | decl = pushdecl (decl); | |
2179 | DECL_INITIAL (decl) = NULL_TREE; | |
2180 | } | |
2181 | ||
ce1b9eb9 MM |
2182 | /* Only write out one anon union element--choose the one that |
2183 | can hold them all. */ | |
2184 | if (main_decl == NULL_TREE | |
cb96daa2 MM |
2185 | && simple_cst_equal (DECL_SIZE (decl), |
2186 | DECL_SIZE (anon_decl)) == 1) | |
2187 | main_decl = decl; | |
2188 | else | |
ce1b9eb9 MM |
2189 | /* ??? This causes there to be no debug info written out |
2190 | about this decl. */ | |
cb96daa2 MM |
2191 | TREE_ASM_WRITTEN (decl) = 1; |
2192 | ||
2193 | if (DECL_NAME (field) == NULL_TREE | |
2194 | && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) | |
2195 | /* The remainder of the processing was already done in the | |
2196 | recursive call. */ | |
2197 | continue; | |
ce1b9eb9 | 2198 | |
cb96daa2 MM |
2199 | /* If there's a cleanup to do, it belongs in the |
2200 | TREE_PURPOSE of the following TREE_LIST. */ | |
2201 | *elems = scratch_tree_cons (NULL_TREE, decl, *elems); | |
2202 | TREE_TYPE (*elems) = type; | |
2203 | } | |
2204 | ||
ce1b9eb9 MM |
2205 | return main_decl; |
2206 | } | |
2207 | ||
8d08fdba MS |
2208 | /* Finish off the processing of a UNION_TYPE structure. |
2209 | If there are static members, then all members are | |
2210 | static, and must be laid out together. If the | |
2211 | union is an anonymous union, we arrange for that | |
2212 | as well. PUBLIC_P is nonzero if this union is | |
2213 | not declared static. */ | |
e92cc029 | 2214 | |
8d08fdba MS |
2215 | void |
2216 | finish_anon_union (anon_union_decl) | |
2217 | tree anon_union_decl; | |
2218 | { | |
2219 | tree type = TREE_TYPE (anon_union_decl); | |
8d08fdba | 2220 | tree elems = NULL_TREE; |
cb96daa2 | 2221 | tree main_decl; |
8d08fdba MS |
2222 | int public_p = TREE_PUBLIC (anon_union_decl); |
2223 | int static_p = TREE_STATIC (anon_union_decl); | |
2224 | int external_p = DECL_EXTERNAL (anon_union_decl); | |
2225 | ||
cb96daa2 | 2226 | if (TYPE_FIELDS (type) == NULL_TREE) |
8d08fdba MS |
2227 | return; |
2228 | ||
2229 | if (public_p) | |
2230 | { | |
8251199e | 2231 | error ("global anonymous unions must be declared static"); |
8d08fdba MS |
2232 | return; |
2233 | } | |
2234 | ||
cb96daa2 MM |
2235 | main_decl = build_anon_union_vars (anon_union_decl, &elems, |
2236 | static_p, external_p); | |
ce1b9eb9 | 2237 | |
18141e4c JM |
2238 | if (main_decl == NULL_TREE) |
2239 | { | |
2240 | warning ("anonymous union with no members"); | |
2241 | return; | |
2242 | } | |
2243 | ||
8d08fdba MS |
2244 | if (static_p) |
2245 | { | |
18141e4c JM |
2246 | make_decl_rtl (main_decl, 0, toplevel_bindings_p ()); |
2247 | DECL_RTL (anon_union_decl) = DECL_RTL (main_decl); | |
8d08fdba MS |
2248 | } |
2249 | ||
2250 | /* The following call assumes that there are never any cleanups | |
2251 | for anonymous unions--a reasonable assumption. */ | |
2252 | expand_anon_union_decl (anon_union_decl, NULL_TREE, elems); | |
8d08fdba MS |
2253 | } |
2254 | ||
8d08fdba MS |
2255 | /* Finish processing a builtin type TYPE. It's name is NAME, |
2256 | its fields are in the array FIELDS. LEN is the number of elements | |
2257 | in FIELDS minus one, or put another way, it is the maximum subscript | |
2258 | used in FIELDS. | |
2259 | ||
2260 | It is given the same alignment as ALIGN_TYPE. */ | |
e92cc029 | 2261 | |
8d08fdba MS |
2262 | void |
2263 | finish_builtin_type (type, name, fields, len, align_type) | |
2264 | tree type; | |
2265 | char *name; | |
2266 | tree fields[]; | |
2267 | int len; | |
2268 | tree align_type; | |
2269 | { | |
2270 | register int i; | |
2271 | ||
2272 | TYPE_FIELDS (type) = fields[0]; | |
2273 | for (i = 0; i < len; i++) | |
2274 | { | |
2275 | layout_type (TREE_TYPE (fields[i])); | |
2276 | DECL_FIELD_CONTEXT (fields[i]) = type; | |
2277 | TREE_CHAIN (fields[i]) = fields[i+1]; | |
2278 | } | |
2279 | DECL_FIELD_CONTEXT (fields[i]) = type; | |
2280 | DECL_CLASS_CONTEXT (fields[i]) = type; | |
2281 | TYPE_ALIGN (type) = TYPE_ALIGN (align_type); | |
2282 | layout_type (type); | |
2283 | #if 0 /* not yet, should get fixed properly later */ | |
2284 | TYPE_NAME (type) = make_type_decl (get_identifier (name), type); | |
2285 | #else | |
2286 | TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type); | |
2287 | #endif | |
d2e5ee5c | 2288 | TYPE_STUB_DECL (type) = TYPE_NAME (type); |
8d08fdba MS |
2289 | layout_decl (TYPE_NAME (type), 0); |
2290 | } | |
2291 | \f | |
2292 | /* Auxiliary functions to make type signatures for | |
2293 | `operator new' and `operator delete' correspond to | |
2294 | what compiler will be expecting. */ | |
2295 | ||
8d08fdba MS |
2296 | tree |
2297 | coerce_new_type (type) | |
2298 | tree type; | |
2299 | { | |
2300 | int e1 = 0, e2 = 0; | |
2301 | ||
2302 | if (TREE_CODE (type) == METHOD_TYPE) | |
2303 | type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type))); | |
2304 | if (TREE_TYPE (type) != ptr_type_node) | |
8251199e | 2305 | e1 = 1, error ("`operator new' must return type `void *'"); |
8d08fdba MS |
2306 | |
2307 | /* Technically the type must be `size_t', but we may not know | |
2308 | what that is. */ | |
2309 | if (TYPE_ARG_TYPES (type) == NULL_TREE) | |
8251199e | 2310 | e1 = 1, error ("`operator new' takes type `size_t' parameter"); |
8d08fdba MS |
2311 | else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE |
2312 | || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype)) | |
8251199e | 2313 | e2 = 1, error ("`operator new' takes type `size_t' as first parameter"); |
8d08fdba MS |
2314 | if (e2) |
2315 | type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type)))); | |
2316 | else if (e1) | |
2317 | type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type)); | |
2318 | return type; | |
2319 | } | |
2320 | ||
2321 | tree | |
2322 | coerce_delete_type (type) | |
2323 | tree type; | |
2324 | { | |
a703fb38 KG |
2325 | int e1 = 0, e2 = 0; |
2326 | #if 0 | |
2327 | e3 = 0; | |
2328 | #endif | |
8d08fdba MS |
2329 | tree arg_types = TYPE_ARG_TYPES (type); |
2330 | ||
2331 | if (TREE_CODE (type) == METHOD_TYPE) | |
2332 | { | |
2333 | type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types)); | |
2334 | arg_types = TREE_CHAIN (arg_types); | |
2335 | } | |
824b9a4c | 2336 | |
8d08fdba | 2337 | if (TREE_TYPE (type) != void_type_node) |
8251199e | 2338 | e1 = 1, error ("`operator delete' must return type `void'"); |
824b9a4c | 2339 | |
8d08fdba MS |
2340 | if (arg_types == NULL_TREE |
2341 | || TREE_VALUE (arg_types) != ptr_type_node) | |
8251199e | 2342 | e2 = 1, error ("`operator delete' takes type `void *' as first parameter"); |
8d08fdba | 2343 | |
da4768fe | 2344 | #if 0 |
8d08fdba MS |
2345 | if (arg_types |
2346 | && TREE_CHAIN (arg_types) | |
2347 | && TREE_CHAIN (arg_types) != void_list_node) | |
2348 | { | |
2349 | /* Again, technically this argument must be `size_t', but again | |
2350 | we may not know what that is. */ | |
2351 | tree t2 = TREE_VALUE (TREE_CHAIN (arg_types)); | |
2352 | if (TREE_CODE (t2) != INTEGER_TYPE | |
2353 | || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype)) | |
8251199e | 2354 | e3 = 1, error ("second argument to `operator delete' must be of type `size_t'"); |
8d08fdba MS |
2355 | else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node) |
2356 | { | |
2357 | e3 = 1; | |
2358 | if (TREE_CHAIN (TREE_CHAIN (arg_types))) | |
8251199e | 2359 | error ("too many arguments in declaration of `operator delete'"); |
8d08fdba | 2360 | else |
8251199e | 2361 | error ("`...' invalid in specification of `operator delete'"); |
8d08fdba MS |
2362 | } |
2363 | } | |
824b9a4c | 2364 | |
8d08fdba | 2365 | if (e3) |
824b9a4c MS |
2366 | arg_types = tree_cons (NULL_TREE, ptr_type_node, |
2367 | build_tree_list (NULL_TREE, sizetype)); | |
8d08fdba MS |
2368 | else if (e3 |= e2) |
2369 | { | |
2370 | if (arg_types == NULL_TREE) | |
a28e3c7f | 2371 | arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node); |
8d08fdba MS |
2372 | else |
2373 | arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types)); | |
2374 | } | |
2375 | else e3 |= e1; | |
da4768fe | 2376 | #endif |
8d08fdba | 2377 | |
da4768fe JM |
2378 | if (e2) |
2379 | arg_types = tree_cons (NULL_TREE, ptr_type_node, | |
2380 | arg_types ? TREE_CHAIN (arg_types): NULL_TREE); | |
2381 | if (e2 || e1) | |
8d08fdba MS |
2382 | type = build_function_type (void_type_node, arg_types); |
2383 | ||
2384 | return type; | |
2385 | } | |
2386 | \f | |
72b7eeff MS |
2387 | extern tree abort_fndecl; |
2388 | ||
8d08fdba | 2389 | static void |
8926095f | 2390 | mark_vtable_entries (decl) |
8d08fdba MS |
2391 | tree decl; |
2392 | { | |
f30432d7 MS |
2393 | tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl)); |
2394 | ||
6b5fbb55 MS |
2395 | if (flag_rtti) |
2396 | { | |
2397 | tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries)) | |
2398 | : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries))); | |
2399 | tree fn = TREE_OPERAND (fnaddr, 0); | |
2400 | TREE_ADDRESSABLE (fn) = 1; | |
2401 | mark_used (fn); | |
2402 | } | |
f30432d7 | 2403 | skip_rtti_stuff (&entries); |
8d08fdba | 2404 | |
8d08fdba MS |
2405 | for (; entries; entries = TREE_CHAIN (entries)) |
2406 | { | |
72b7eeff MS |
2407 | tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries) |
2408 | : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries))); | |
8d08fdba | 2409 | tree fn = TREE_OPERAND (fnaddr, 0); |
8926095f | 2410 | TREE_ADDRESSABLE (fn) = 1; |
72b7eeff | 2411 | if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn)) |
49c249e1 JM |
2412 | { |
2413 | TREE_OPERAND (fnaddr, 0) = fn = copy_node (fn); | |
2414 | DECL_RTL (fn) = DECL_RTL (abort_fndecl); | |
7e3af374 | 2415 | mark_used (abort_fndecl); |
49c249e1 | 2416 | } |
a80e4195 MS |
2417 | if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn)) |
2418 | { | |
2419 | DECL_EXTERNAL (fn) = 0; | |
2420 | emit_thunk (fn); | |
2421 | } | |
5566b478 | 2422 | mark_used (fn); |
7177d104 MS |
2423 | } |
2424 | } | |
2425 | ||
d11ad92e MS |
2426 | /* Set DECL up to have the closest approximation of "initialized common" |
2427 | linkage available. */ | |
2428 | ||
2429 | void | |
2430 | comdat_linkage (decl) | |
2431 | tree decl; | |
2432 | { | |
d11ad92e | 2433 | if (flag_weak) |
7fcdf4c2 MS |
2434 | make_decl_one_only (decl); |
2435 | else | |
2436 | TREE_PUBLIC (decl) = 0; | |
ab23f787 JM |
2437 | |
2438 | if (DECL_LANG_SPECIFIC (decl)) | |
2439 | DECL_COMDAT (decl) = 1; | |
d11ad92e MS |
2440 | } |
2441 | ||
b385c841 JM |
2442 | /* For win32 we also want to put explicit instantiations in |
2443 | linkonce sections, so that they will be merged with implicit | |
2444 | instantiations; otherwise we get duplicate symbol errors. */ | |
2445 | ||
2446 | void | |
2447 | maybe_make_one_only (decl) | |
2448 | tree decl; | |
2449 | { | |
2450 | /* This is not necessary on targets that support weak symbols, because | |
2451 | the implicit instantiations will defer to the explicit one. */ | |
2452 | if (! supports_one_only () || SUPPORTS_WEAK) | |
2453 | return; | |
2454 | ||
2455 | /* We can't set DECL_COMDAT on functions, or finish_file will think | |
2456 | we can get away with not emitting them if they aren't used. | |
2457 | We can't use make_decl_one_only for variables, because their | |
2458 | DECL_INITIAL may not have been set properly yet. */ | |
2459 | ||
2460 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
2461 | make_decl_one_only (decl); | |
2462 | else | |
2463 | comdat_linkage (decl); | |
2464 | } | |
2465 | ||
d18c083e | 2466 | /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL, |
7177d104 MS |
2467 | based on TYPE and other static flags. |
2468 | ||
2469 | Note that anything public is tagged TREE_PUBLIC, whether | |
2470 | it's public in this file or in another one. */ | |
2471 | ||
5b605f68 | 2472 | void |
e3417fcd MS |
2473 | import_export_vtable (decl, type, final) |
2474 | tree decl, type; | |
2475 | int final; | |
7177d104 | 2476 | { |
e3417fcd MS |
2477 | if (DECL_INTERFACE_KNOWN (decl)) |
2478 | return; | |
2479 | ||
56ae6d77 | 2480 | if (TYPE_FOR_JAVA (type)) |
7177d104 MS |
2481 | { |
2482 | TREE_PUBLIC (decl) = 1; | |
56ae6d77 | 2483 | DECL_EXTERNAL (decl) = 1; |
e3417fcd MS |
2484 | DECL_INTERFACE_KNOWN (decl) = 1; |
2485 | } | |
2486 | else if (CLASSTYPE_INTERFACE_KNOWN (type)) | |
2487 | { | |
2488 | TREE_PUBLIC (decl) = 1; | |
2489 | DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type); | |
2490 | DECL_INTERFACE_KNOWN (decl) = 1; | |
eb773359 | 2491 | |
1a408d07 JM |
2492 | /* Always make vtables weak. */ |
2493 | if (flag_weak) | |
2494 | comdat_linkage (decl); | |
e3417fcd MS |
2495 | } |
2496 | else | |
2497 | { | |
b7484fbe MS |
2498 | /* We can only wait to decide if we have real non-inline virtual |
2499 | functions in our class, or if we come from a template. */ | |
e3417fcd MS |
2500 | |
2501 | int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type); | |
2502 | ||
1f109f0f | 2503 | #ifndef MULTIPLE_SYMBOL_SPACES |
e3417fcd MS |
2504 | if (! found && ! final) |
2505 | { | |
e3417fcd | 2506 | tree method; |
72b7eeff MS |
2507 | for (method = TYPE_METHODS (type); method != NULL_TREE; |
2508 | method = TREE_CHAIN (method)) | |
faae18ab MS |
2509 | if (DECL_VINDEX (method) != NULL_TREE |
2510 | && ! DECL_THIS_INLINE (method) | |
e3417fcd MS |
2511 | && ! DECL_ABSTRACT_VIRTUAL_P (method)) |
2512 | { | |
2513 | found = 1; | |
2514 | break; | |
2515 | } | |
2516 | } | |
1f109f0f | 2517 | #endif |
e3417fcd MS |
2518 | |
2519 | if (final || ! found) | |
2520 | { | |
d11ad92e | 2521 | comdat_linkage (decl); |
e3417fcd | 2522 | DECL_EXTERNAL (decl) = 0; |
e3417fcd MS |
2523 | } |
2524 | else | |
2525 | { | |
2526 | TREE_PUBLIC (decl) = 1; | |
2527 | DECL_EXTERNAL (decl) = 1; | |
e3417fcd | 2528 | } |
8d08fdba MS |
2529 | } |
2530 | } | |
2531 | ||
7e776093 JM |
2532 | /* Determine whether or not we want to specifically import or export CTYPE, |
2533 | using various heuristics. */ | |
67f7c391 JM |
2534 | |
2535 | void | |
2536 | import_export_class (ctype) | |
2537 | tree ctype; | |
8d08fdba | 2538 | { |
7e776093 JM |
2539 | /* -1 for imported, 1 for exported. */ |
2540 | int import_export = 0; | |
2541 | ||
2542 | if (CLASSTYPE_INTERFACE_KNOWN (ctype)) | |
2543 | return; | |
2544 | ||
2545 | #ifdef VALID_MACHINE_TYPE_ATTRIBUTE | |
2546 | /* FIXME this should really use some sort of target-independent macro. */ | |
2547 | if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype))) | |
2548 | import_export = -1; | |
2549 | else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype))) | |
2550 | import_export = 1; | |
2551 | #endif | |
2552 | ||
2553 | /* If we got -fno-implicit-templates, we import template classes that | |
2554 | weren't explicitly instantiated. */ | |
2555 | if (import_export == 0 | |
2556 | && CLASSTYPE_IMPLICIT_INSTANTIATION (ctype) | |
2557 | && ! flag_implicit_templates) | |
2558 | import_export = -1; | |
7177d104 | 2559 | |
eb448459 | 2560 | #ifndef MULTIPLE_SYMBOL_SPACES |
7e776093 JM |
2561 | /* Base our import/export status on that of the first non-inline, |
2562 | non-abstract virtual function, if any. */ | |
2563 | if (import_export == 0 | |
2564 | && TYPE_VIRTUAL_P (ctype) | |
b7484fbe | 2565 | && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype)) |
51c184be MS |
2566 | { |
2567 | tree method; | |
72b7eeff MS |
2568 | for (method = TYPE_METHODS (ctype); method != NULL_TREE; |
2569 | method = TREE_CHAIN (method)) | |
51c184be | 2570 | { |
28cbf42c | 2571 | if (DECL_VINDEX (method) != NULL_TREE |
faae18ab | 2572 | && !DECL_THIS_INLINE (method) |
a0a33927 | 2573 | && !DECL_ABSTRACT_VIRTUAL_P (method)) |
51c184be | 2574 | { |
7e776093 | 2575 | import_export = (DECL_REALLY_EXTERN (method) ? -1 : 1); |
51c184be MS |
2576 | break; |
2577 | } | |
2578 | } | |
2579 | } | |
c11b6f21 | 2580 | #endif |
7e776093 JM |
2581 | |
2582 | if (import_export) | |
2583 | { | |
2584 | SET_CLASSTYPE_INTERFACE_KNOWN (ctype); | |
2585 | CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = (import_export > 0); | |
2586 | CLASSTYPE_INTERFACE_ONLY (ctype) = (import_export < 0); | |
2587 | } | |
67f7c391 JM |
2588 | } |
2589 | ||
2590 | int | |
2591 | finish_prevtable_vardecl (prev, vars) | |
b370501f | 2592 | tree prev ATTRIBUTE_UNUSED, vars; |
67f7c391 JM |
2593 | { |
2594 | tree ctype = DECL_CONTEXT (vars); | |
2595 | import_export_class (ctype); | |
e3417fcd | 2596 | import_export_vtable (vars, ctype, 1); |
fc378698 | 2597 | return 1; |
d18c083e | 2598 | } |
a1dd0d36 JM |
2599 | |
2600 | /* We need to describe to the assembler the relationship between | |
59fa060f | 2601 | a vtable and the vtable of the parent class. */ |
a1dd0d36 JM |
2602 | |
2603 | static void | |
2604 | output_vtable_inherit (vars) | |
2605 | tree vars; | |
2606 | { | |
2607 | tree parent; | |
2608 | rtx op[2]; | |
2609 | ||
2610 | op[0] = XEXP (DECL_RTL (vars), 0); /* strip the mem ref */ | |
2611 | ||
2612 | parent = binfo_for_vtable (vars); | |
2613 | ||
2614 | if (parent == TYPE_BINFO (DECL_CONTEXT (vars))) | |
2615 | op[1] = const0_rtx; | |
2616 | else if (parent) | |
2617 | { | |
2618 | parent = TYPE_BINFO_VTABLE (BINFO_TYPE (parent)); | |
2619 | op[1] = XEXP (DECL_RTL (parent), 0); /* strip the mem ref */ | |
2620 | } | |
2621 | else | |
2622 | my_friendly_abort (980826); | |
2623 | ||
59fa060f | 2624 | output_asm_insn (".vtable_inherit %c0, %c1", op); |
a1dd0d36 JM |
2625 | } |
2626 | ||
fc378698 | 2627 | static int |
d18c083e MS |
2628 | finish_vtable_vardecl (prev, vars) |
2629 | tree prev, vars; | |
2630 | { | |
56ae6d77 | 2631 | if (! DECL_EXTERNAL (vars) |
c3437800 | 2632 | && (DECL_INTERFACE_KNOWN (vars) |
e92cc029 MS |
2633 | || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)) |
2634 | || (hack_decl_function_context (vars) && TREE_USED (vars))) | |
fc378698 | 2635 | && ! TREE_ASM_WRITTEN (vars)) |
d18c083e | 2636 | { |
8d08fdba | 2637 | /* Write it out. */ |
8926095f | 2638 | mark_vtable_entries (vars); |
8d08fdba | 2639 | if (TREE_TYPE (DECL_INITIAL (vars)) == 0) |
b7484fbe | 2640 | store_init_value (vars, DECL_INITIAL (vars)); |
8d08fdba | 2641 | |
faf5394a | 2642 | if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG) |
8d08fdba MS |
2643 | { |
2644 | /* Mark the VAR_DECL node representing the vtable itself as a | |
2645 | "gratuitous" one, thereby forcing dwarfout.c to ignore it. | |
2646 | It is rather important that such things be ignored because | |
2647 | any effort to actually generate DWARF for them will run | |
2648 | into trouble when/if we encounter code like: | |
2649 | ||
2650 | #pragma interface | |
2651 | struct S { virtual void member (); }; | |
2652 | ||
2653 | because the artificial declaration of the vtable itself (as | |
2654 | manufactured by the g++ front end) will say that the vtable | |
2655 | is a static member of `S' but only *after* the debug output | |
2656 | for the definition of `S' has already been output. This causes | |
2657 | grief because the DWARF entry for the definition of the vtable | |
2658 | will try to refer back to an earlier *declaration* of the | |
2659 | vtable as a static member of `S' and there won't be one. | |
2660 | We might be able to arrange to have the "vtable static member" | |
2661 | attached to the member list for `S' before the debug info for | |
2662 | `S' get written (which would solve the problem) but that would | |
2663 | require more intrusive changes to the g++ front end. */ | |
2664 | ||
2665 | DECL_IGNORED_P (vars) = 1; | |
2666 | } | |
8d08fdba | 2667 | |
311862c8 | 2668 | rest_of_decl_compilation (vars, NULL_PTR, 1, 1); |
a1dd0d36 JM |
2669 | |
2670 | if (flag_vtable_gc) | |
2671 | output_vtable_inherit (vars); | |
2672 | ||
fc378698 | 2673 | return 1; |
8d08fdba | 2674 | } |
a50f0918 | 2675 | else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))) |
b7484fbe | 2676 | /* We don't know what to do with this one yet. */ |
fc378698 | 2677 | return 0; |
b7484fbe MS |
2678 | |
2679 | /* We know that PREV must be non-zero here. */ | |
2680 | TREE_CHAIN (prev) = TREE_CHAIN (vars); | |
fc378698 | 2681 | return 0; |
b7484fbe MS |
2682 | } |
2683 | ||
fc378698 | 2684 | static int |
b7484fbe MS |
2685 | prune_vtable_vardecl (prev, vars) |
2686 | tree prev, vars; | |
2687 | { | |
8d08fdba MS |
2688 | /* We know that PREV must be non-zero here. */ |
2689 | TREE_CHAIN (prev) = TREE_CHAIN (vars); | |
fc378698 | 2690 | return 1; |
8d08fdba MS |
2691 | } |
2692 | ||
fc378698 | 2693 | int |
8d08fdba | 2694 | walk_vtables (typedecl_fn, vardecl_fn) |
49c249e1 JM |
2695 | register void (*typedecl_fn) PROTO ((tree, tree)); |
2696 | register int (*vardecl_fn) PROTO ((tree, tree)); | |
8d08fdba MS |
2697 | { |
2698 | tree prev, vars; | |
fc378698 | 2699 | int flag = 0; |
8d08fdba MS |
2700 | |
2701 | for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars)) | |
2702 | { | |
2703 | register tree type = TREE_TYPE (vars); | |
2704 | ||
28cbf42c | 2705 | if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars)) |
8d08fdba | 2706 | { |
fc378698 MS |
2707 | if (vardecl_fn) |
2708 | flag |= (*vardecl_fn) (prev, vars); | |
28cbf42c MS |
2709 | |
2710 | if (prev && TREE_CHAIN (prev) != vars) | |
2711 | continue; | |
8d08fdba | 2712 | } |
28cbf42c MS |
2713 | else if (TREE_CODE (vars) == TYPE_DECL |
2714 | && type != error_mark_node | |
2715 | && TYPE_LANG_SPECIFIC (type) | |
2716 | && CLASSTYPE_VSIZE (type)) | |
8d08fdba | 2717 | { |
28cbf42c | 2718 | if (typedecl_fn) (*typedecl_fn) (prev, vars); |
8d08fdba | 2719 | } |
28cbf42c MS |
2720 | |
2721 | prev = vars; | |
8d08fdba | 2722 | } |
fc378698 MS |
2723 | |
2724 | return flag; | |
8d08fdba MS |
2725 | } |
2726 | ||
311862c8 GB |
2727 | static void |
2728 | finish_sigtable_vardecl (prev, vars) | |
2729 | tree prev, vars; | |
2730 | { | |
2731 | /* We don't need to mark sigtable entries as addressable here as is done | |
2732 | for vtables. Since sigtables, unlike vtables, are always written out, | |
2733 | that was already done in build_signature_table_constructor. */ | |
2734 | ||
2735 | rest_of_decl_compilation (vars, NULL_PTR, 1, 1); | |
2736 | ||
2737 | /* We know that PREV must be non-zero here. */ | |
2738 | TREE_CHAIN (prev) = TREE_CHAIN (vars); | |
2739 | } | |
2740 | ||
2741 | void | |
2742 | walk_sigtables (typedecl_fn, vardecl_fn) | |
49c249e1 JM |
2743 | register void (*typedecl_fn) PROTO((tree, tree)); |
2744 | register void (*vardecl_fn) PROTO((tree, tree)); | |
311862c8 GB |
2745 | { |
2746 | tree prev, vars; | |
2747 | ||
2748 | for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars)) | |
2749 | { | |
2750 | register tree type = TREE_TYPE (vars); | |
2751 | ||
2752 | if (TREE_CODE (vars) == TYPE_DECL | |
2753 | && type != error_mark_node | |
2754 | && IS_SIGNATURE (type)) | |
2755 | { | |
2756 | if (typedecl_fn) (*typedecl_fn) (prev, vars); | |
2757 | } | |
2758 | else if (TREE_CODE (vars) == VAR_DECL | |
2759 | && TREE_TYPE (vars) != error_mark_node | |
2760 | && IS_SIGNATURE (TREE_TYPE (vars))) | |
2761 | { | |
2762 | if (vardecl_fn) (*vardecl_fn) (prev, vars); | |
2763 | } | |
2764 | else | |
2765 | prev = vars; | |
2766 | } | |
2767 | } | |
2768 | ||
00595019 | 2769 | /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an |
5566b478 | 2770 | inline function or template instantiation at end-of-file. */ |
00595019 MS |
2771 | |
2772 | void | |
5566b478 | 2773 | import_export_decl (decl) |
00595019 MS |
2774 | tree decl; |
2775 | { | |
db5ae43f | 2776 | if (DECL_INTERFACE_KNOWN (decl)) |
00595019 MS |
2777 | return; |
2778 | ||
61289ca3 MM |
2779 | if (DECL_TEMPLATE_INSTANTIATION (decl) |
2780 | || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)) | |
00595019 | 2781 | { |
5566b478 | 2782 | DECL_NOT_REALLY_EXTERN (decl) = 1; |
61289ca3 MM |
2783 | if ((DECL_IMPLICIT_INSTANTIATION (decl) |
2784 | || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)) | |
5eea678f JM |
2785 | && (flag_implicit_templates |
2786 | || (flag_implicit_inline_templates && DECL_THIS_INLINE (decl)))) | |
a9aedbc2 | 2787 | { |
75650646 MM |
2788 | if (!TREE_PUBLIC (decl)) |
2789 | /* Templates are allowed to have internal linkage. See | |
2790 | [basic.link]. */ | |
2791 | ; | |
2792 | else if (TREE_CODE (decl) == FUNCTION_DECL) | |
d11ad92e | 2793 | comdat_linkage (decl); |
d11ad92e | 2794 | else |
77be6f82 | 2795 | DECL_COMDAT (decl) = 1; |
a9aedbc2 | 2796 | } |
db5ae43f | 2797 | else |
faae18ab | 2798 | DECL_NOT_REALLY_EXTERN (decl) = 0; |
00595019 MS |
2799 | } |
2800 | else if (DECL_FUNCTION_MEMBER_P (decl)) | |
2801 | { | |
2802 | tree ctype = DECL_CLASS_CONTEXT (decl); | |
047f64a3 JM |
2803 | if (CLASSTYPE_INTERFACE_KNOWN (ctype) |
2804 | && (! DECL_ARTIFICIAL (decl) || DECL_VINDEX (decl))) | |
00595019 | 2805 | { |
faae18ab MS |
2806 | DECL_NOT_REALLY_EXTERN (decl) |
2807 | = ! (CLASSTYPE_INTERFACE_ONLY (ctype) | |
2808 | || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines)); | |
1a408d07 JM |
2809 | |
2810 | /* Always make artificials weak. */ | |
2811 | if (DECL_ARTIFICIAL (decl) && flag_weak) | |
2812 | comdat_linkage (decl); | |
00595019 | 2813 | } |
db5ae43f | 2814 | else |
d11ad92e | 2815 | comdat_linkage (decl); |
00595019 | 2816 | } |
6b5fbb55 MS |
2817 | /* tinfo function */ |
2818 | else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl)) | |
2819 | { | |
2820 | tree ctype = TREE_TYPE (DECL_NAME (decl)); | |
d11ad92e | 2821 | if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype) |
7e776093 | 2822 | && TYPE_VIRTUAL_P (ctype) |
af9c2d8a MM |
2823 | /* If the type is a cv-qualified variant of a type, then we |
2824 | must emit the tinfo function in this translation unit | |
2825 | since it will not be emitted when the vtable for the type | |
2826 | is output (which is when the unqualified version is | |
2827 | generated). */ | |
7e776093 JM |
2828 | && ctype == TYPE_MAIN_VARIANT (ctype)) |
2829 | { | |
6b5fbb55 | 2830 | DECL_NOT_REALLY_EXTERN (decl) |
7e776093 JM |
2831 | = ! (CLASSTYPE_INTERFACE_ONLY (ctype) |
2832 | || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines)); | |
eb773359 | 2833 | |
1a408d07 JM |
2834 | /* Always make artificials weak. */ |
2835 | if (flag_weak) | |
2836 | comdat_linkage (decl); | |
6b5fbb55 MS |
2837 | } |
2838 | else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype)) | |
2839 | DECL_NOT_REALLY_EXTERN (decl) = 0; | |
6b5fbb55 | 2840 | else |
d11ad92e | 2841 | comdat_linkage (decl); |
6b5fbb55 | 2842 | } |
db5ae43f | 2843 | else |
d11ad92e | 2844 | comdat_linkage (decl); |
e8abc66f MS |
2845 | |
2846 | DECL_INTERFACE_KNOWN (decl) = 1; | |
00595019 | 2847 | } |
db5ae43f | 2848 | |
72b7eeff MS |
2849 | tree |
2850 | build_cleanup (decl) | |
2851 | tree decl; | |
2852 | { | |
2853 | tree temp; | |
2854 | tree type = TREE_TYPE (decl); | |
2855 | ||
2856 | if (TREE_CODE (type) == ARRAY_TYPE) | |
2857 | temp = decl; | |
2858 | else | |
2859 | { | |
2860 | mark_addressable (decl); | |
2861 | temp = build1 (ADDR_EXPR, build_pointer_type (type), decl); | |
2862 | } | |
2863 | temp = build_delete (TREE_TYPE (temp), temp, | |
2864 | integer_two_node, | |
2865 | LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); | |
2866 | return temp; | |
2867 | } | |
2868 | ||
8d08fdba | 2869 | extern int parse_time, varconst_time; |
5566b478 | 2870 | extern tree pending_templates; |
73aad9b9 | 2871 | extern tree maybe_templates; |
8d08fdba | 2872 | |
824b9a4c | 2873 | static tree |
67d743fe MS |
2874 | get_sentry (base) |
2875 | tree base; | |
2876 | { | |
2877 | tree sname = get_id_2 ("__sn", base); | |
2c73f9f5 | 2878 | /* For struct X foo __attribute__((weak)), there is a counter |
30394414 JM |
2879 | __snfoo. Since base is already an assembler name, sname should |
2880 | be globally unique */ | |
67d743fe MS |
2881 | tree sentry = IDENTIFIER_GLOBAL_VALUE (sname); |
2882 | if (! sentry) | |
2883 | { | |
88537ff2 JM |
2884 | push_obstacks_nochange (); |
2885 | end_temporary_allocation (); | |
67d743fe MS |
2886 | sentry = build_decl (VAR_DECL, sname, integer_type_node); |
2887 | TREE_PUBLIC (sentry) = 1; | |
2888 | DECL_ARTIFICIAL (sentry) = 1; | |
2889 | TREE_STATIC (sentry) = 1; | |
2890 | TREE_USED (sentry) = 1; | |
2891 | DECL_COMMON (sentry) = 1; | |
2892 | pushdecl_top_level (sentry); | |
2893 | cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0); | |
2894 | pop_obstacks (); | |
2895 | } | |
2896 | return sentry; | |
2897 | } | |
2898 | ||
2ce3c6c6 JM |
2899 | /* A list of objects which have constructors or destructors |
2900 | which reside in the global scope. The decl is stored in | |
2901 | the TREE_VALUE slot and the initializer is stored | |
2902 | in the TREE_PURPOSE slot. */ | |
2903 | extern tree static_aggregates_initp; | |
2904 | ||
2905 | /* Set up the static_aggregates* lists for processing. Subroutine of | |
2906 | finish_file. Note that this function changes the format of | |
2907 | static_aggregates_initp, from (priority . decl) to | |
2908 | (priority . ((initializer . decl) ...)). */ | |
2909 | ||
2910 | static void | |
2911 | setup_initp () | |
2912 | { | |
2913 | tree t, *p, next_t; | |
2914 | ||
2915 | if (! flag_init_priority) | |
2916 | { | |
2917 | for (t = static_aggregates_initp; t; t = TREE_CHAIN (t)) | |
8251199e | 2918 | cp_warning ("init_priority for `%#D' ignored without -finit-priority", |
2ce3c6c6 JM |
2919 | TREE_VALUE (t)); |
2920 | return; | |
2921 | } | |
2922 | ||
2923 | /* First, remove any entries from static_aggregates that are also in | |
2924 | static_aggregates_initp, and update the entries in _initp to | |
2925 | include the initializer. */ | |
2926 | p = &static_aggregates; | |
2927 | for (; *p; ) | |
2928 | { | |
2929 | t = value_member (TREE_VALUE (*p), static_aggregates_initp); | |
2930 | ||
2931 | if (t) | |
2932 | { | |
2933 | TREE_VALUE (t) = *p; | |
2934 | *p = TREE_CHAIN (*p); | |
2935 | TREE_CHAIN (TREE_VALUE (t)) = NULL_TREE; | |
2936 | } | |
2937 | else | |
2938 | p = &TREE_CHAIN (*p); | |
2939 | } | |
2940 | ||
2941 | /* Then, group static_aggregates_initp. After this step, there will only | |
2942 | be one entry for each priority, with a chain coming off it. */ | |
2943 | t = static_aggregates_initp; | |
2944 | static_aggregates_initp = NULL_TREE; | |
2945 | ||
2946 | for (; t; t = next_t) | |
2947 | { | |
2948 | next_t = TREE_CHAIN (t); | |
2949 | ||
2950 | for (p = &static_aggregates_initp; ; p = &TREE_CHAIN (*p)) | |
2951 | { | |
2952 | if (*p == NULL_TREE | |
2953 | || tree_int_cst_lt (TREE_PURPOSE (*p), TREE_PURPOSE (t))) | |
2954 | { | |
2955 | TREE_CHAIN (t) = *p; | |
2956 | *p = t; | |
2957 | break; | |
2958 | } | |
2959 | else if (tree_int_cst_equal (TREE_PURPOSE (*p), TREE_PURPOSE (t))) | |
2960 | { | |
2961 | TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (*p); | |
2962 | TREE_VALUE (*p) = TREE_VALUE (t); | |
2963 | break; | |
2964 | } | |
2965 | } | |
2966 | } | |
2967 | ||
2968 | /* Reverse each list to preserve the order (currently reverse declaration | |
2969 | order, for destructors). */ | |
2970 | for (t = static_aggregates_initp; t; t = TREE_CHAIN (t)) | |
2971 | TREE_VALUE (t) = nreverse (TREE_VALUE (t)); | |
2972 | } | |
2973 | ||
961ec1a5 JM |
2974 | /* Start the process of running a particular set of global constructors |
2975 | or destructors. Subroutine of do_[cd]tors. */ | |
2976 | ||
2977 | static void | |
2ce3c6c6 JM |
2978 | start_objects (method_type, initp) |
2979 | int method_type, initp; | |
961ec1a5 JM |
2980 | { |
2981 | tree fnname; | |
2ce3c6c6 | 2982 | char type[10]; |
961ec1a5 JM |
2983 | |
2984 | /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */ | |
2985 | ||
2ce3c6c6 JM |
2986 | if (flag_init_priority) |
2987 | { | |
066d147c MH |
2988 | char joiner; |
2989 | ||
2990 | #ifdef JOINER | |
2991 | joiner = JOINER; | |
2992 | #else | |
2993 | joiner = '_'; | |
2994 | #endif | |
2ce3c6c6 JM |
2995 | if (initp == 0) |
2996 | initp = DEFAULT_INIT_PRIORITY; | |
2997 | ||
066d147c | 2998 | sprintf (type, "%c%c%.5u", method_type, joiner, initp); |
2ce3c6c6 JM |
2999 | } |
3000 | else | |
3001 | sprintf (type, "%c", method_type); | |
3002 | ||
3003 | fnname = get_file_function_name_long (type); | |
961ec1a5 JM |
3004 | |
3005 | start_function (void_list_node, | |
3006 | make_call_declarator (fnname, void_list_node, NULL_TREE, | |
3007 | NULL_TREE), | |
3008 | NULL_TREE, 0); | |
3009 | ||
3010 | store_parm_decls (); | |
3011 | pushlevel (0); | |
3012 | clear_last_expr (); | |
3013 | push_momentary (); | |
3014 | expand_start_bindings (0); | |
3015 | } | |
3016 | ||
3017 | /* Finish the process of running a particular set of global constructors | |
3018 | or destructors. Subroutine of do_[cd]tors. */ | |
3019 | ||
3020 | static void | |
2ce3c6c6 JM |
3021 | finish_objects (method_type, initp) |
3022 | int method_type, initp; | |
961ec1a5 JM |
3023 | { |
3024 | char *fnname; | |
3025 | ||
2ce3c6c6 JM |
3026 | if (! initp) |
3027 | { | |
3028 | tree list = (method_type == 'I' ? static_ctors : static_dtors); | |
961ec1a5 | 3029 | |
2ce3c6c6 JM |
3030 | if (! current_function_decl && list) |
3031 | start_objects (method_type, initp); | |
961ec1a5 | 3032 | |
2ce3c6c6 JM |
3033 | for (; list; list = TREE_CHAIN (list)) |
3034 | expand_expr_stmt (build_function_call (TREE_VALUE (list), NULL_TREE)); | |
3035 | } | |
961ec1a5 JM |
3036 | |
3037 | if (! current_function_decl) | |
3038 | return; | |
3039 | ||
3040 | fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); | |
3041 | ||
3042 | /* Finish up. */ | |
3043 | expand_end_bindings (getdecls (), 1, 0); | |
3044 | poplevel (1, 0, 0); | |
3045 | pop_momentary (); | |
3046 | finish_function (lineno, 0, 0); | |
3047 | ||
2ce3c6c6 JM |
3048 | if (! flag_init_priority) |
3049 | { | |
3050 | if (method_type == 'I') | |
3051 | assemble_constructor (fnname); | |
3052 | else | |
3053 | assemble_destructor (fnname); | |
3054 | } | |
3055 | ||
3056 | #ifdef ASM_OUTPUT_SECTION_NAME | |
3057 | /* If we're using init priority we can't use assemble_*tor, but on ELF | |
3058 | targets we can stick the references into named sections for GNU ld | |
3059 | to collect. */ | |
3060 | if (flag_init_priority) | |
3061 | { | |
3062 | char buf[15]; | |
3063 | if (initp == 0) | |
3064 | initp = DEFAULT_INIT_PRIORITY; | |
3065 | sprintf (buf, ".%ctors.%.5u", method_type == 'I' ? 'c' : 'd', | |
3066 | /* invert the numbering so the linker puts us in the proper | |
3067 | order; constructors are run from right to left, and the | |
3068 | linker sorts in increasing order. */ | |
3069 | MAX_INIT_PRIORITY - initp); | |
3070 | named_section (NULL_TREE, buf, 0); | |
3071 | assemble_integer (gen_rtx_SYMBOL_REF (Pmode, fnname), | |
3072 | POINTER_SIZE / BITS_PER_UNIT, 1); | |
3073 | } | |
3074 | #endif | |
961ec1a5 JM |
3075 | } |
3076 | ||
2ce3c6c6 JM |
3077 | /* Generate a function to run a set of global destructors. START is either |
3078 | NULL_TREE or a node indicating a set of destructors with the same | |
3079 | init priority. Subroutine of finish_file. */ | |
961ec1a5 JM |
3080 | |
3081 | static void | |
2ce3c6c6 JM |
3082 | do_dtors (start) |
3083 | tree start; | |
961ec1a5 | 3084 | { |
2ce3c6c6 JM |
3085 | tree vars; |
3086 | int initp; | |
3087 | ||
3088 | if (start) | |
3089 | { | |
3090 | initp = TREE_INT_CST_LOW (TREE_PURPOSE (start)); | |
3091 | vars = TREE_VALUE (start); | |
3092 | } | |
3093 | else | |
3094 | { | |
3095 | initp = 0; | |
3096 | vars = static_aggregates; | |
3097 | } | |
961ec1a5 JM |
3098 | |
3099 | for (; vars; vars = TREE_CHAIN (vars)) | |
3100 | { | |
3101 | tree decl = TREE_VALUE (vars); | |
3102 | tree type = TREE_TYPE (decl); | |
3103 | tree temp; | |
3104 | ||
3105 | if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars) | |
3106 | && ! DECL_EXTERNAL (decl)) | |
3107 | { | |
3108 | int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl) | |
3109 | || DECL_ONE_ONLY (decl) | |
3110 | || DECL_WEAK (decl))); | |
3111 | ||
3112 | if (! current_function_decl) | |
2ce3c6c6 | 3113 | start_objects ('D', initp); |
961ec1a5 | 3114 | |
ae58fa02 MM |
3115 | /* Because of: |
3116 | ||
3117 | [class.access.spec] | |
3118 | ||
3119 | Access control for implicit calls to the constructors, | |
3120 | the conversion functions, or the destructor called to | |
01240200 | 3121 | create and destroy a static data member is performed as |
ae58fa02 MM |
3122 | if these calls appeared in the scope of the member's |
3123 | class. | |
3124 | ||
3125 | we must convince enforce_access to let us access the | |
3126 | DECL. */ | |
3127 | if (member_p (decl)) | |
3128 | { | |
3129 | DECL_CLASS_CONTEXT (current_function_decl) | |
3130 | = DECL_CONTEXT (decl); | |
3131 | DECL_STATIC_FUNCTION_P (current_function_decl) = 1; | |
3132 | } | |
3133 | ||
961ec1a5 JM |
3134 | temp = build_cleanup (decl); |
3135 | ||
3136 | if (protect) | |
3137 | { | |
3138 | tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl)); | |
3139 | sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0); | |
3140 | sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1); | |
3141 | expand_start_cond (sentry, 0); | |
3142 | } | |
3143 | ||
3144 | expand_expr_stmt (temp); | |
3145 | ||
3146 | if (protect) | |
3147 | expand_end_cond (); | |
ae58fa02 MM |
3148 | |
3149 | /* Now that we're done with DECL we don't need to pretend to | |
3150 | be a member of its class any longer. */ | |
3151 | DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE; | |
3152 | DECL_STATIC_FUNCTION_P (current_function_decl) = 0; | |
961ec1a5 JM |
3153 | } |
3154 | } | |
3155 | ||
2ce3c6c6 | 3156 | finish_objects ('D', initp); |
961ec1a5 JM |
3157 | } |
3158 | ||
2ce3c6c6 JM |
3159 | /* Generate a function to run a set of global constructors. START is |
3160 | either NULL_TREE or a node indicating a set of constructors with the | |
3161 | same init priority. Subroutine of finish_file. */ | |
961ec1a5 JM |
3162 | |
3163 | static void | |
2ce3c6c6 JM |
3164 | do_ctors (start) |
3165 | tree start; | |
961ec1a5 | 3166 | { |
2ce3c6c6 JM |
3167 | tree vars; |
3168 | int initp; | |
3169 | ||
3170 | if (start) | |
3171 | { | |
3172 | initp = TREE_INT_CST_LOW (TREE_PURPOSE (start)); | |
3173 | vars = TREE_VALUE (start); | |
3174 | } | |
3175 | else | |
3176 | { | |
3177 | initp = 0; | |
3178 | vars = static_aggregates; | |
3179 | } | |
961ec1a5 JM |
3180 | |
3181 | /* Reverse the list so it's in the right order for ctors. */ | |
3182 | vars = nreverse (vars); | |
3183 | ||
3184 | for (; vars; vars = TREE_CHAIN (vars)) | |
3185 | { | |
3186 | tree decl = TREE_VALUE (vars); | |
3187 | tree init = TREE_PURPOSE (vars); | |
3188 | ||
3189 | /* If this was a static attribute within some function's scope, | |
3190 | then don't initialize it here. Also, don't bother | |
3191 | with initializers that contain errors. */ | |
3192 | if (TREE_STATIC (vars) | |
3193 | || DECL_EXTERNAL (decl) | |
3194 | || (init && TREE_CODE (init) == TREE_LIST | |
3195 | && value_member (error_mark_node, init))) | |
3196 | continue; | |
3197 | ||
3198 | if (TREE_CODE (decl) == VAR_DECL) | |
3199 | { | |
3200 | int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl) | |
3201 | || DECL_ONE_ONLY (decl) | |
3202 | || DECL_WEAK (decl))); | |
3203 | ||
3204 | if (! current_function_decl) | |
2ce3c6c6 | 3205 | start_objects ('I', initp); |
961ec1a5 JM |
3206 | |
3207 | /* Set these global variables so that GDB at least puts | |
3208 | us near the declaration which required the initialization. */ | |
3209 | input_filename = DECL_SOURCE_FILE (decl); | |
3210 | lineno = DECL_SOURCE_LINE (decl); | |
3211 | emit_note (input_filename, lineno); | |
3212 | ||
3213 | /* 9.5p5: The initializer of a static member of a class has | |
3214 | the same access rights as a member function. */ | |
3215 | if (member_p (decl)) | |
3216 | { | |
3217 | DECL_CLASS_CONTEXT (current_function_decl) | |
3218 | = DECL_CONTEXT (decl); | |
3219 | DECL_STATIC_FUNCTION_P (current_function_decl) = 1; | |
3220 | } | |
3221 | ||
3222 | if (protect) | |
3223 | { | |
3224 | tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl)); | |
3225 | sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0); | |
3226 | sentry = build_binary_op | |
3227 | (EQ_EXPR, sentry, integer_one_node, 1); | |
3228 | expand_start_cond (sentry, 0); | |
3229 | } | |
3230 | ||
3231 | expand_start_target_temps (); | |
3232 | ||
3233 | if (IS_AGGR_TYPE (TREE_TYPE (decl)) | |
3234 | || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
b370501f | 3235 | expand_aggr_init (decl, init, 0); |
961ec1a5 JM |
3236 | else if (TREE_CODE (init) == TREE_VEC) |
3237 | { | |
3238 | expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0), | |
3239 | TREE_VEC_ELT (init, 1), | |
3240 | TREE_VEC_ELT (init, 2), 0), | |
3241 | const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3242 | } | |
3243 | else | |
3244 | expand_assignment (decl, init, 0, 0); | |
3245 | ||
3246 | /* The expression might have involved increments and | |
3247 | decrements. */ | |
3248 | emit_queue (); | |
3249 | ||
3250 | /* Cleanup any temporaries needed for the initial value. */ | |
3251 | expand_end_target_temps (); | |
3252 | ||
3253 | if (protect) | |
3254 | expand_end_cond (); | |
3255 | ||
3256 | DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE; | |
3257 | DECL_STATIC_FUNCTION_P (current_function_decl) = 0; | |
3258 | } | |
3259 | else if (decl == error_mark_node) | |
3260 | /* OK */; | |
3261 | else | |
3262 | my_friendly_abort (22); | |
3263 | } | |
3264 | ||
2ce3c6c6 | 3265 | finish_objects ('I', initp); |
961ec1a5 JM |
3266 | } |
3267 | ||
8d08fdba MS |
3268 | /* This routine is called from the last rule in yyparse (). |
3269 | Its job is to create all the code needed to initialize and | |
3270 | destroy the global aggregates. We do the destruction | |
3271 | first, since that way we only need to reverse the decls once. */ | |
3272 | ||
3273 | void | |
3274 | finish_file () | |
3275 | { | |
3276 | extern int lineno; | |
3277 | int start_time, this_time; | |
3278 | ||
3279 | tree fnname; | |
44a8d0b3 | 3280 | tree vars; |
8d08fdba | 3281 | int needs_cleaning = 0, needs_messing_up = 0; |
8d2733ca | 3282 | |
5566b478 MS |
3283 | at_eof = 1; |
3284 | ||
8d08fdba MS |
3285 | /* Bad parse errors. Just forget about it. */ |
3286 | if (! global_bindings_p () || current_class_type) | |
3287 | return; | |
3288 | ||
9a68c51f JM |
3289 | check_decl_namespace (); |
3290 | ||
8d08fdba MS |
3291 | start_time = get_run_time (); |
3292 | ||
8d08fdba MS |
3293 | /* Otherwise, GDB can get confused, because in only knows |
3294 | about source for LINENO-1 lines. */ | |
3295 | lineno -= 1; | |
3296 | ||
d18c083e MS |
3297 | interface_unknown = 1; |
3298 | interface_only = 0; | |
3299 | ||
909e536a MS |
3300 | for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname)) |
3301 | { | |
1139b3d8 | 3302 | tree srcloc = TREE_PURPOSE (fnname); |
909e536a | 3303 | tree decl = TREE_VALUE (fnname); |
1139b3d8 JM |
3304 | |
3305 | input_filename = SRCLOC_FILE (srcloc); | |
3306 | lineno = SRCLOC_LINE (srcloc); | |
3307 | ||
e92cc029 MS |
3308 | if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't') |
3309 | { | |
3310 | instantiate_class_template (decl); | |
3311 | if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl)) | |
3312 | for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars)) | |
9a3b49ac MS |
3313 | if (! DECL_ARTIFICIAL (vars)) |
3314 | instantiate_decl (vars); | |
e92cc029 MS |
3315 | } |
3316 | else | |
3317 | instantiate_decl (decl); | |
909e536a MS |
3318 | } |
3319 | ||
73aad9b9 JM |
3320 | for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname)) |
3321 | { | |
98c1c668 | 3322 | tree args, fn, decl = TREE_VALUE (fnname); |
73aad9b9 JM |
3323 | |
3324 | if (DECL_INITIAL (decl)) | |
3325 | continue; | |
3326 | ||
3327 | fn = TREE_PURPOSE (fnname); | |
e1467ff2 | 3328 | args = get_bindings (fn, decl, NULL_TREE); |
73aad9b9 | 3329 | fn = instantiate_template (fn, args); |
73aad9b9 JM |
3330 | instantiate_decl (fn); |
3331 | } | |
3332 | ||
2c73f9f5 ML |
3333 | cat_namespace_levels(); |
3334 | ||
909e536a MS |
3335 | /* Push into C language context, because that's all |
3336 | we'll need here. */ | |
3337 | push_lang_context (lang_name_c); | |
3338 | ||
28cbf42c MS |
3339 | #if 1 |
3340 | /* The reason for pushing garbage onto the global_binding_level is to | |
3341 | ensure that we can slice out _DECLs which pertain to virtual function | |
3342 | tables. If the last thing pushed onto the global_binding_level was a | |
3343 | virtual function table, then slicing it out would slice away all the | |
3344 | decls (i.e., we lose the head of the chain). | |
3345 | ||
3346 | There are several ways of getting the same effect, from changing the | |
3347 | way that iterators over the chain treat the elements that pertain to | |
3348 | virtual function tables, moving the implementation of this code to | |
3349 | decl.c (where we can manipulate global_binding_level directly), | |
3350 | popping the garbage after pushing it and slicing away the vtable | |
e92cc029 | 3351 | stuff, or just leaving it alone. */ |
28cbf42c MS |
3352 | |
3353 | /* Make last thing in global scope not be a virtual function table. */ | |
3354 | #if 0 /* not yet, should get fixed properly later */ | |
3355 | vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node); | |
3356 | #else | |
3357 | vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node); | |
3358 | #endif | |
3359 | DECL_IGNORED_P (vars) = 1; | |
3360 | SET_DECL_ARTIFICIAL (vars); | |
3361 | pushdecl (vars); | |
3362 | #endif | |
3363 | ||
d18c083e | 3364 | /* Walk to mark the inline functions we need, then output them so |
e92cc029 | 3365 | that we can pick up any other tdecls that those routines need. */ |
49c249e1 JM |
3366 | walk_vtables ((void (*) PROTO ((tree, tree))) 0, |
3367 | finish_prevtable_vardecl); | |
d18c083e | 3368 | |
c11b6f21 MS |
3369 | for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars)) |
3370 | if (! TREE_ASM_WRITTEN (TREE_VALUE (vars))) | |
3371 | rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1); | |
44a8d0b3 MS |
3372 | vars = static_aggregates; |
3373 | ||
02531345 | 3374 | if (static_ctors || vars) |
44a8d0b3 | 3375 | needs_messing_up = 1; |
961ec1a5 | 3376 | if (static_dtors || vars) |
44a8d0b3 MS |
3377 | needs_cleaning = 1; |
3378 | ||
2ce3c6c6 JM |
3379 | setup_initp (); |
3380 | ||
3381 | /* After setup_initp, the aggregates are listed in reverse declaration | |
3382 | order, for cleaning. */ | |
961ec1a5 | 3383 | if (needs_cleaning) |
44a8d0b3 | 3384 | { |
2ce3c6c6 JM |
3385 | do_dtors (NULL_TREE); |
3386 | ||
3387 | if (flag_init_priority) | |
3388 | for (vars = static_aggregates_initp; vars; vars = TREE_CHAIN (vars)) | |
3389 | do_dtors (vars); | |
44a8d0b3 MS |
3390 | } |
3391 | ||
961ec1a5 | 3392 | /* do_ctors will reverse the lists for messing up. */ |
e1cd6e56 | 3393 | if (needs_messing_up) |
8d08fdba | 3394 | { |
2ce3c6c6 JM |
3395 | do_ctors (NULL_TREE); |
3396 | ||
3397 | if (flag_init_priority) | |
3398 | for (vars = static_aggregates_initp; vars; vars = TREE_CHAIN (vars)) | |
3399 | do_ctors (vars); | |
3400 | } | |
8d08fdba | 3401 | |
faae18ab MS |
3402 | permanent_allocation (1); |
3403 | ||
8d08fdba MS |
3404 | /* Done with C language context needs. */ |
3405 | pop_lang_context (); | |
3406 | ||
3407 | /* Now write out any static class variables (which may have since | |
3408 | learned how to be initialized). */ | |
3409 | while (pending_statics) | |
3410 | { | |
3411 | tree decl = TREE_VALUE (pending_statics); | |
5566b478 | 3412 | |
d2e5ee5c MS |
3413 | /* Output DWARF debug information. */ |
3414 | #ifdef DWARF_DEBUGGING_INFO | |
3415 | if (write_symbols == DWARF_DEBUG) | |
3416 | dwarfout_file_scope_decl (decl, 1); | |
3417 | #endif | |
3418 | #ifdef DWARF2_DEBUGGING_INFO | |
3419 | if (write_symbols == DWARF2_DEBUG) | |
3420 | dwarf2out_decl (decl); | |
3421 | #endif | |
3422 | ||
3423 | DECL_DEFER_OUTPUT (decl) = 0; | |
3424 | rest_of_decl_compilation | |
3425 | (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1); | |
3426 | ||
8d08fdba MS |
3427 | pending_statics = TREE_CHAIN (pending_statics); |
3428 | } | |
3429 | ||
3430 | this_time = get_run_time (); | |
3431 | parse_time -= this_time - start_time; | |
3432 | varconst_time += this_time - start_time; | |
3433 | ||
8d08fdba MS |
3434 | start_time = get_run_time (); |
3435 | ||
5b605f68 | 3436 | if (flag_handle_signatures) |
49c249e1 JM |
3437 | walk_sigtables ((void (*) PROTO ((tree, tree))) 0, |
3438 | finish_sigtable_vardecl); | |
8926095f | 3439 | |
28cbf42c | 3440 | for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname)) |
fd378c9d JM |
3441 | { |
3442 | tree decl = TREE_VALUE (fnname); | |
5566b478 | 3443 | import_export_decl (decl); |
fd378c9d | 3444 | } |
28cbf42c | 3445 | |
9c606f69 AM |
3446 | mark_all_runtime_matches (); |
3447 | ||
db5ae43f MS |
3448 | /* Now write out inline functions which had their addresses taken and |
3449 | which were not declared virtual and which were not declared `extern | |
3450 | inline'. */ | |
9a0e77ba | 3451 | { |
db5ae43f | 3452 | int reconsider = 1; /* More may be referenced; check again */ |
9a0e77ba | 3453 | |
db5ae43f | 3454 | while (reconsider) |
9a0e77ba | 3455 | { |
21451173 | 3456 | tree *p = &saved_inlines; |
db5ae43f MS |
3457 | reconsider = 0; |
3458 | ||
e76a2646 MS |
3459 | /* We need to do this each time so that newly completed template |
3460 | types don't wind up at the front of the list. Sigh. */ | |
3461 | vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node); | |
3462 | DECL_IGNORED_P (vars) = 1; | |
3463 | SET_DECL_ARTIFICIAL (vars); | |
3464 | pushdecl (vars); | |
3465 | ||
49c249e1 JM |
3466 | reconsider |= walk_vtables ((void (*) PROTO((tree, tree))) 0, |
3467 | finish_vtable_vardecl); | |
b7484fbe | 3468 | |
21451173 | 3469 | while (*p) |
9a0e77ba | 3470 | { |
21451173 | 3471 | tree decl = TREE_VALUE (*p); |
db5ae43f | 3472 | |
21451173 | 3473 | if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl) |
6b5fbb55 MS |
3474 | && TREE_USED (decl) |
3475 | && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl))) | |
e8abc66f | 3476 | { |
6b5fbb55 MS |
3477 | if (DECL_MUTABLE_P (decl)) |
3478 | synthesize_tinfo_fn (decl); | |
3479 | else | |
3480 | synthesize_method (decl); | |
21451173 | 3481 | reconsider = 1; |
e8abc66f MS |
3482 | } |
3483 | ||
a50f0918 | 3484 | /* Catch new template instantiations. */ |
6b5fbb55 | 3485 | if (decl != TREE_VALUE (*p)) |
a50f0918 | 3486 | continue; |
b7484fbe | 3487 | |
a50f0918 MS |
3488 | if (TREE_ASM_WRITTEN (decl) |
3489 | || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl))) | |
21451173 | 3490 | *p = TREE_CHAIN (*p); |
a50f0918 MS |
3491 | else if (DECL_INITIAL (decl) == 0) |
3492 | p = &TREE_CHAIN (*p); | |
ab23f787 | 3493 | else if ((TREE_PUBLIC (decl) && ! DECL_COMDAT (decl)) |
21451173 MS |
3494 | || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) |
3495 | || flag_keep_inline_functions) | |
3496 | { | |
faae18ab | 3497 | if (DECL_NOT_REALLY_EXTERN (decl)) |
9a0e77ba | 3498 | { |
faae18ab | 3499 | DECL_EXTERNAL (decl) = 0; |
db5ae43f | 3500 | reconsider = 1; |
bd871063 JM |
3501 | /* We can't inline this function after it's been |
3502 | emitted. We want a variant of | |
3503 | output_inline_function that doesn't prevent | |
3504 | subsequent integration... */ | |
3505 | DECL_INLINE (decl) = 0; | |
db5ae43f MS |
3506 | output_inline_function (decl); |
3507 | permanent_allocation (1); | |
9a0e77ba | 3508 | } |
db5ae43f | 3509 | |
21451173 | 3510 | *p = TREE_CHAIN (*p); |
9a0e77ba | 3511 | } |
21451173 MS |
3512 | else |
3513 | p = &TREE_CHAIN (*p); | |
9a0e77ba JM |
3514 | } |
3515 | } | |
9c0d0367 MM |
3516 | |
3517 | /* It's possible that some of the remaining inlines will still be | |
3518 | needed. For example, a static inline whose address is used in | |
3519 | the initializer for a file-scope static variable will be | |
3520 | needed. Code in compile_file will handle this, but we mustn't | |
3521 | pretend that there are no definitions for the inlines, or it | |
3522 | won't be able to. | |
3523 | ||
3524 | FIXME: This won't catch member functions. We should really | |
3525 | unify this stuff with the compile_file stuff. */ | |
3526 | for (vars = saved_inlines; vars != NULL_TREE; vars = TREE_CHAIN (vars)) | |
3527 | { | |
3528 | tree decl = TREE_VALUE (vars); | |
3529 | ||
3530 | if (DECL_NOT_REALLY_EXTERN (decl) | |
3531 | && !DECL_COMDAT (decl) | |
3532 | && DECL_INITIAL (decl) != NULL_TREE) | |
3533 | DECL_EXTERNAL (decl) = 0; | |
3534 | } | |
9a0e77ba | 3535 | } |
8d08fdba | 3536 | |
28cbf42c MS |
3537 | /* Now delete from the chain of variables all virtual function tables. |
3538 | We output them all ourselves, because each will be treated specially. */ | |
3539 | ||
49c249e1 JM |
3540 | walk_vtables ((void (*) PROTO((tree, tree))) 0, |
3541 | prune_vtable_vardecl); | |
b7484fbe | 3542 | |
faae18ab MS |
3543 | finish_repo (); |
3544 | ||
8d08fdba MS |
3545 | this_time = get_run_time (); |
3546 | parse_time -= this_time - start_time; | |
3547 | varconst_time += this_time - start_time; | |
3548 | ||
3549 | if (flag_detailed_statistics) | |
27bb8339 JM |
3550 | { |
3551 | dump_tree_statistics (); | |
3552 | dump_time_statistics (); | |
3553 | } | |
8d08fdba | 3554 | } |
51c184be MS |
3555 | |
3556 | /* This is something of the form 'A()()()()()+1' that has turned out to be an | |
3557 | expr. Since it was parsed like a type, we need to wade through and fix | |
3558 | that. Unfortunately, since operator() is left-associative, we can't use | |
3559 | tail recursion. In the above example, TYPE is `A', and DECL is | |
3560 | `()()()()()'. | |
3561 | ||
3562 | Maybe this shouldn't be recursive, but how often will it actually be | |
3563 | used? (jason) */ | |
e92cc029 | 3564 | |
51c184be MS |
3565 | tree |
3566 | reparse_absdcl_as_expr (type, decl) | |
3567 | tree type, decl; | |
3568 | { | |
3569 | /* do build_functional_cast (type, NULL_TREE) at bottom */ | |
3570 | if (TREE_OPERAND (decl, 0) == NULL_TREE) | |
3571 | return build_functional_cast (type, NULL_TREE); | |
3572 | ||
3573 | /* recurse */ | |
3574 | decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0)); | |
3575 | ||
4ac14744 | 3576 | decl = build_x_function_call (decl, NULL_TREE, current_class_ref); |
51c184be MS |
3577 | |
3578 | if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node) | |
3579 | decl = require_complete_type (decl); | |
3580 | ||
3581 | return decl; | |
3582 | } | |
3583 | ||
3584 | /* This is something of the form `int ((int)(int)(int)1)' that has turned | |
3585 | out to be an expr. Since it was parsed like a type, we need to wade | |
3586 | through and fix that. Since casts are right-associative, we are | |
3587 | reversing the order, so we don't have to recurse. | |
3588 | ||
3589 | In the above example, DECL is the `(int)(int)(int)', and EXPR is the | |
3590 | `1'. */ | |
e92cc029 | 3591 | |
51c184be MS |
3592 | tree |
3593 | reparse_absdcl_as_casts (decl, expr) | |
3594 | tree decl, expr; | |
3595 | { | |
3596 | tree type; | |
3597 | ||
4ac14744 MS |
3598 | if (TREE_CODE (expr) == CONSTRUCTOR |
3599 | && TREE_TYPE (expr) == 0) | |
51c184be MS |
3600 | { |
3601 | type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1))); | |
3602 | decl = TREE_OPERAND (decl, 0); | |
3603 | ||
3604 | if (IS_SIGNATURE (type)) | |
3605 | { | |
8251199e | 3606 | error ("cast specifies signature type"); |
51c184be MS |
3607 | return error_mark_node; |
3608 | } | |
3609 | ||
3610 | expr = digest_init (type, expr, (tree *) 0); | |
3611 | if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0) | |
3612 | { | |
3613 | int failure = complete_array_type (type, expr, 1); | |
3614 | if (failure) | |
3615 | my_friendly_abort (78); | |
3616 | } | |
3617 | } | |
3618 | ||
3619 | while (decl) | |
3620 | { | |
3621 | type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1))); | |
3622 | decl = TREE_OPERAND (decl, 0); | |
faf5394a | 3623 | expr = build_c_cast (type, expr); |
51c184be MS |
3624 | } |
3625 | ||
0c4b14c4 | 3626 | if (warn_old_style_cast) |
8251199e | 3627 | warning ("use of old-style cast"); |
0c4b14c4 | 3628 | |
51c184be MS |
3629 | return expr; |
3630 | } | |
3631 | ||
e92cc029 | 3632 | /* Given plain tree nodes for an expression, build up the full semantics. */ |
5566b478 MS |
3633 | |
3634 | tree | |
3635 | build_expr_from_tree (t) | |
3636 | tree t; | |
51c184be | 3637 | { |
5566b478 MS |
3638 | if (t == NULL_TREE || t == error_mark_node) |
3639 | return t; | |
3640 | ||
3641 | switch (TREE_CODE (t)) | |
51c184be MS |
3642 | { |
3643 | case IDENTIFIER_NODE: | |
a759e627 | 3644 | return do_identifier (t, 0, NULL_TREE); |
5566b478 MS |
3645 | |
3646 | case LOOKUP_EXPR: | |
3647 | if (LOOKUP_EXPR_GLOBAL (t)) | |
3648 | return do_scoped_id (TREE_OPERAND (t, 0), 0); | |
3649 | else | |
a759e627 | 3650 | return do_identifier (TREE_OPERAND (t, 0), 0, NULL_TREE); |
5566b478 | 3651 | |
386b8a85 | 3652 | case TEMPLATE_ID_EXPR: |
00d3396f JM |
3653 | return (lookup_template_function |
3654 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3655 | build_expr_from_tree (TREE_OPERAND (t, 1)))); | |
386b8a85 | 3656 | |
51c184be MS |
3657 | case INDIRECT_REF: |
3658 | return build_x_indirect_ref | |
5566b478 MS |
3659 | (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *"); |
3660 | ||
3661 | case CAST_EXPR: | |
3662 | return build_functional_cast | |
3663 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3664 | ||
3665 | case REINTERPRET_CAST_EXPR: | |
3666 | return build_reinterpret_cast | |
3667 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3668 | ||
e92cc029 MS |
3669 | case CONST_CAST_EXPR: |
3670 | return build_const_cast | |
3671 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3672 | ||
3673 | case DYNAMIC_CAST_EXPR: | |
3674 | return build_dynamic_cast | |
3675 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3676 | ||
3677 | case STATIC_CAST_EXPR: | |
3678 | return build_static_cast | |
3679 | (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3680 | ||
5566b478 MS |
3681 | case PREDECREMENT_EXPR: |
3682 | case PREINCREMENT_EXPR: | |
3683 | case POSTDECREMENT_EXPR: | |
3684 | case POSTINCREMENT_EXPR: | |
3685 | case NEGATE_EXPR: | |
51c184be | 3686 | case BIT_NOT_EXPR: |
5566b478 MS |
3687 | case ABS_EXPR: |
3688 | case TRUTH_NOT_EXPR: | |
3689 | case ADDR_EXPR: | |
3690 | case CONVERT_EXPR: /* Unary + */ | |
fc378698 MS |
3691 | if (TREE_TYPE (t)) |
3692 | return t; | |
5566b478 MS |
3693 | return build_x_unary_op (TREE_CODE (t), |
3694 | build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3695 | ||
3696 | case PLUS_EXPR: | |
3697 | case MINUS_EXPR: | |
3698 | case MULT_EXPR: | |
3699 | case TRUNC_DIV_EXPR: | |
3700 | case CEIL_DIV_EXPR: | |
3701 | case FLOOR_DIV_EXPR: | |
3702 | case ROUND_DIV_EXPR: | |
3703 | case EXACT_DIV_EXPR: | |
3704 | case BIT_AND_EXPR: | |
3705 | case BIT_ANDTC_EXPR: | |
3706 | case BIT_IOR_EXPR: | |
3707 | case BIT_XOR_EXPR: | |
3708 | case TRUNC_MOD_EXPR: | |
3709 | case FLOOR_MOD_EXPR: | |
3710 | case TRUTH_ANDIF_EXPR: | |
3711 | case TRUTH_ORIF_EXPR: | |
3712 | case TRUTH_AND_EXPR: | |
3713 | case TRUTH_OR_EXPR: | |
3714 | case RSHIFT_EXPR: | |
3715 | case LSHIFT_EXPR: | |
3716 | case RROTATE_EXPR: | |
3717 | case LROTATE_EXPR: | |
3718 | case EQ_EXPR: | |
3719 | case NE_EXPR: | |
3720 | case MAX_EXPR: | |
3721 | case MIN_EXPR: | |
3722 | case LE_EXPR: | |
3723 | case GE_EXPR: | |
3724 | case LT_EXPR: | |
3725 | case GT_EXPR: | |
3726 | case MEMBER_REF: | |
3727 | return build_x_binary_op | |
3728 | (TREE_CODE (t), | |
3729 | build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3730 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3731 | ||
3732 | case DOTSTAR_EXPR: | |
3733 | return build_m_component_ref | |
3734 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3735 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3736 | ||
a28e3c7f | 3737 | case SCOPE_REF: |
5566b478 MS |
3738 | return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1)); |
3739 | ||
a28e3c7f | 3740 | case ARRAY_REF: |
5566b478 MS |
3741 | if (TREE_OPERAND (t, 0) == NULL_TREE) |
3742 | /* new-type-id */ | |
3743 | return build_parse_node (ARRAY_REF, NULL_TREE, | |
3744 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3745 | return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3746 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3747 | ||
3748 | case SIZEOF_EXPR: | |
abff8e06 | 3749 | case ALIGNOF_EXPR: |
5566b478 MS |
3750 | { |
3751 | tree r = build_expr_from_tree (TREE_OPERAND (t, 0)); | |
3752 | if (TREE_CODE_CLASS (TREE_CODE (r)) != 't') | |
3753 | r = TREE_TYPE (r); | |
abff8e06 | 3754 | return TREE_CODE (t) == SIZEOF_EXPR ? c_sizeof (r) : c_alignof (r); |
5566b478 MS |
3755 | } |
3756 | ||
3757 | case MODOP_EXPR: | |
3758 | return build_x_modify_expr | |
3759 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3760 | TREE_CODE (TREE_OPERAND (t, 1)), | |
3761 | build_expr_from_tree (TREE_OPERAND (t, 2))); | |
3762 | ||
3763 | case ARROW_EXPR: | |
3764 | return build_x_arrow | |
3765 | (build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3766 | ||
3767 | case NEW_EXPR: | |
3768 | return build_new | |
3769 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3770 | build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3771 | build_expr_from_tree (TREE_OPERAND (t, 2)), | |
3772 | NEW_EXPR_USE_GLOBAL (t)); | |
3773 | ||
3774 | case DELETE_EXPR: | |
3775 | return delete_sanity | |
3776 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3777 | build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3778 | DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t)); | |
3779 | ||
3780 | case COMPOUND_EXPR: | |
3781 | if (TREE_OPERAND (t, 1) == NULL_TREE) | |
3782 | return build_x_compound_expr | |
3783 | (build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3784 | else | |
3785 | my_friendly_abort (42); | |
3786 | ||
3787 | case METHOD_CALL_EXPR: | |
3788 | if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF) | |
3789 | { | |
3790 | tree ref = TREE_OPERAND (t, 0); | |
3791 | return build_scoped_method_call | |
3792 | (build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3793 | build_expr_from_tree (TREE_OPERAND (ref, 0)), | |
3794 | TREE_OPERAND (ref, 1), | |
3795 | build_expr_from_tree (TREE_OPERAND (t, 2))); | |
3796 | } | |
3797 | return build_method_call | |
3798 | (build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3799 | TREE_OPERAND (t, 0), | |
3800 | build_expr_from_tree (TREE_OPERAND (t, 2)), | |
3801 | NULL_TREE, LOOKUP_NORMAL); | |
3802 | ||
3803 | case CALL_EXPR: | |
3804 | if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF) | |
3805 | { | |
3806 | tree ref = TREE_OPERAND (t, 0); | |
3807 | return build_member_call | |
3808 | (build_expr_from_tree (TREE_OPERAND (ref, 0)), | |
3809 | TREE_OPERAND (ref, 1), | |
3810 | build_expr_from_tree (TREE_OPERAND (t, 1))); | |
3811 | } | |
3812 | else | |
3813 | { | |
3814 | tree name = TREE_OPERAND (t, 0); | |
a759e627 ML |
3815 | tree id; |
3816 | tree args = build_expr_from_tree (TREE_OPERAND (t, 1)); | |
3817 | if (args != NULL_TREE && TREE_CODE (name) == LOOKUP_EXPR | |
3818 | && !LOOKUP_EXPR_GLOBAL (name) | |
3819 | && TREE_CODE ((id = TREE_OPERAND (name, 0))) == IDENTIFIER_NODE | |
3820 | && (!current_class_type | |
3821 | || !lookup_member (current_class_type, id, 0, 0))) | |
3822 | { | |
3823 | /* Do Koenig lookup if there are no class members. */ | |
3824 | name = do_identifier (id, 0, args); | |
3825 | } | |
3826 | else if (TREE_CODE (name) == TEMPLATE_ID_EXPR | |
00d3396f | 3827 | || ! really_overloaded_fn (name)) |
5566b478 | 3828 | name = build_expr_from_tree (name); |
a759e627 | 3829 | return build_x_function_call (name, args, current_class_ref); |
5566b478 MS |
3830 | } |
3831 | ||
3832 | case COND_EXPR: | |
3833 | return build_x_conditional_expr | |
3834 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3835 | build_expr_from_tree (TREE_OPERAND (t, 1)), | |
3836 | build_expr_from_tree (TREE_OPERAND (t, 2))); | |
3837 | ||
3838 | case TREE_LIST: | |
3839 | { | |
3840 | tree purpose, value, chain; | |
3841 | ||
3842 | if (t == void_list_node) | |
3843 | return t; | |
3844 | ||
3845 | purpose = TREE_PURPOSE (t); | |
3846 | if (purpose) | |
3847 | purpose = build_expr_from_tree (purpose); | |
3848 | value = TREE_VALUE (t); | |
3849 | if (value) | |
3850 | value = build_expr_from_tree (value); | |
3851 | chain = TREE_CHAIN (t); | |
3852 | if (chain && chain != void_type_node) | |
3853 | chain = build_expr_from_tree (chain); | |
e66d884e | 3854 | return expr_tree_cons (purpose, value, chain); |
5566b478 MS |
3855 | } |
3856 | ||
3857 | case COMPONENT_REF: | |
e1467ff2 MM |
3858 | return build_x_component_ref |
3859 | (build_expr_from_tree (TREE_OPERAND (t, 0)), | |
3860 | TREE_OPERAND (t, 1), NULL_TREE, 1); | |
3861 | ||
fc378698 MS |
3862 | case THROW_EXPR: |
3863 | return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0))); | |
3864 | ||
5156628f MS |
3865 | case CONSTRUCTOR: |
3866 | { | |
2fcdec57 JM |
3867 | tree r; |
3868 | ||
3869 | /* digest_init will do the wrong thing if we let it. */ | |
3870 | if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t))) | |
3871 | return t; | |
3872 | ||
3873 | r = build_nt (CONSTRUCTOR, NULL_TREE, | |
3874 | build_expr_from_tree (CONSTRUCTOR_ELTS (t))); | |
5156628f MS |
3875 | |
3876 | if (TREE_TYPE (t)) | |
3877 | return digest_init (TREE_TYPE (t), r, 0); | |
3878 | return r; | |
3879 | } | |
3880 | ||
3881 | case TYPEID_EXPR: | |
e9f32eb5 MS |
3882 | if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't') |
3883 | return get_typeid (TREE_OPERAND (t, 0)); | |
5156628f MS |
3884 | return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0))); |
3885 | ||
9a3b49ac MS |
3886 | case VAR_DECL: |
3887 | return convert_from_reference (t); | |
3888 | ||
8926095f | 3889 | default: |
5566b478 | 3890 | return t; |
51c184be | 3891 | } |
51c184be MS |
3892 | } |
3893 | ||
3894 | /* This is something of the form `int (*a)++' that has turned out to be an | |
3895 | expr. It was only converted into parse nodes, so we need to go through | |
3896 | and build up the semantics. Most of the work is done by | |
5566b478 | 3897 | build_expr_from_tree, above. |
51c184be MS |
3898 | |
3899 | In the above example, TYPE is `int' and DECL is `*a'. */ | |
e92cc029 | 3900 | |
51c184be MS |
3901 | tree |
3902 | reparse_decl_as_expr (type, decl) | |
3903 | tree type, decl; | |
3904 | { | |
5566b478 | 3905 | decl = build_expr_from_tree (decl); |
e3417fcd | 3906 | if (type) |
e66d884e | 3907 | return build_functional_cast (type, build_expr_list (NULL_TREE, decl)); |
e3417fcd MS |
3908 | else |
3909 | return decl; | |
51c184be MS |
3910 | } |
3911 | ||
3912 | /* This is something of the form `int (*a)' that has turned out to be a | |
3913 | decl. It was only converted into parse nodes, so we need to do the | |
e92cc029 | 3914 | checking that make_{pointer,reference}_declarator do. */ |
51c184be MS |
3915 | |
3916 | tree | |
3917 | finish_decl_parsing (decl) | |
3918 | tree decl; | |
3919 | { | |
8926095f MS |
3920 | extern int current_class_depth; |
3921 | ||
51c184be MS |
3922 | switch (TREE_CODE (decl)) |
3923 | { | |
3924 | case IDENTIFIER_NODE: | |
3925 | return decl; | |
3926 | case INDIRECT_REF: | |
3927 | return make_pointer_declarator | |
3928 | (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0))); | |
3929 | case ADDR_EXPR: | |
3930 | return make_reference_declarator | |
3931 | (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0))); | |
3932 | case BIT_NOT_EXPR: | |
3933 | TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0)); | |
3934 | return decl; | |
8926095f | 3935 | case SCOPE_REF: |
a4443a08 | 3936 | push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3); |
8926095f MS |
3937 | TREE_COMPLEXITY (decl) = current_class_depth; |
3938 | return decl; | |
a28e3c7f MS |
3939 | case ARRAY_REF: |
3940 | TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0)); | |
3941 | return decl; | |
8926095f MS |
3942 | default: |
3943 | my_friendly_abort (5); | |
3944 | return NULL_TREE; | |
51c184be MS |
3945 | } |
3946 | } | |
2986ae00 MS |
3947 | |
3948 | tree | |
3949 | check_cp_case_value (value) | |
3950 | tree value; | |
3951 | { | |
3952 | if (value == NULL_TREE) | |
3953 | return value; | |
3954 | ||
5566b478 MS |
3955 | /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ |
3956 | STRIP_TYPE_NOPS (value); | |
2986ae00 MS |
3957 | |
3958 | if (TREE_READONLY_DECL_P (value)) | |
3959 | { | |
3960 | value = decl_constant_value (value); | |
5566b478 | 3961 | STRIP_TYPE_NOPS (value); |
2986ae00 MS |
3962 | } |
3963 | value = fold (value); | |
3964 | ||
3965 | if (TREE_CODE (value) != INTEGER_CST | |
3966 | && value != error_mark_node) | |
3967 | { | |
8251199e | 3968 | cp_error ("case label `%E' does not reduce to an integer constant", |
2986ae00 MS |
3969 | value); |
3970 | value = error_mark_node; | |
3971 | } | |
3972 | else | |
3973 | /* Promote char or short to int. */ | |
3974 | value = default_conversion (value); | |
3975 | ||
3976 | constant_expression_warning (value); | |
3977 | ||
3978 | return value; | |
3979 | } | |
6060a796 | 3980 | |
2c73f9f5 ML |
3981 | /* Return 1 if root encloses child. */ |
3982 | ||
30394414 JM |
3983 | static int |
3984 | is_namespace_ancestor (root, child) | |
3985 | tree root, child; | |
3986 | { | |
3987 | if (root == child) | |
3988 | return 1; | |
3989 | if (root == global_namespace) | |
3990 | return 1; | |
3991 | if (child == global_namespace) | |
3992 | return 0; | |
cb0dbb9a | 3993 | return is_namespace_ancestor (root, CP_DECL_CONTEXT (child)); |
30394414 JM |
3994 | } |
3995 | ||
3996 | ||
2c73f9f5 ML |
3997 | /* Return the namespace that is the common ancestor |
3998 | of two given namespaces. */ | |
3999 | ||
9ed182dc | 4000 | tree |
30394414 JM |
4001 | namespace_ancestor (ns1, ns2) |
4002 | tree ns1, ns2; | |
4003 | { | |
4004 | if (is_namespace_ancestor (ns1, ns2)) | |
4005 | return ns1; | |
a41461c9 | 4006 | return namespace_ancestor (CP_DECL_CONTEXT (ns1), ns2); |
30394414 JM |
4007 | } |
4008 | ||
4009 | /* Insert used into the using list of user. Set indirect_flag if this | |
4010 | directive is not directly from the source. Also find the common | |
4011 | ancestor and let our users know about the new namespace */ | |
4012 | static void | |
4013 | add_using_namespace (user, used, indirect) | |
4014 | tree user; | |
4015 | tree used; | |
4016 | int indirect; | |
4017 | { | |
52c11ef6 | 4018 | tree t; |
2c73f9f5 | 4019 | /* Using oneself is a no-op. */ |
30394414 JM |
4020 | if (user == used) |
4021 | return; | |
4022 | my_friendly_assert (TREE_CODE (user) == NAMESPACE_DECL, 380); | |
4023 | my_friendly_assert (TREE_CODE (used) == NAMESPACE_DECL, 380); | |
2c73f9f5 | 4024 | /* Check if we already have this. */ |
52c11ef6 JM |
4025 | t = purpose_member (used, DECL_NAMESPACE_USING (user)); |
4026 | if (t != NULL_TREE) | |
4027 | { | |
4028 | if (!indirect) | |
4029 | /* Promote to direct usage. */ | |
4030 | TREE_INDIRECT_USING (t) = 0; | |
4031 | return; | |
4032 | } | |
30394414 | 4033 | |
2c73f9f5 | 4034 | /* Add used to the user's using list. */ |
30394414 JM |
4035 | DECL_NAMESPACE_USING (user) |
4036 | = perm_tree_cons (used, namespace_ancestor (user, used), | |
4037 | DECL_NAMESPACE_USING (user)); | |
4038 | ||
4039 | TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user)) = indirect; | |
4040 | ||
2c73f9f5 | 4041 | /* Add user to the used's users list. */ |
30394414 JM |
4042 | DECL_NAMESPACE_USERS (used) |
4043 | = perm_tree_cons (user, 0, DECL_NAMESPACE_USERS (used)); | |
85c6cbaf ML |
4044 | |
4045 | /* Recursively add all namespaces used. */ | |
52c11ef6 | 4046 | for (t = DECL_NAMESPACE_USING (used); t; t = TREE_CHAIN (t)) |
30394414 | 4047 | /* indirect usage */ |
52c11ef6 | 4048 | add_using_namespace (user, TREE_PURPOSE (t), 1); |
85c6cbaf ML |
4049 | |
4050 | /* Tell everyone using us about the new used namespaces. */ | |
52c11ef6 JM |
4051 | for (t = DECL_NAMESPACE_USERS (user); t; t = TREE_CHAIN (t)) |
4052 | add_using_namespace (TREE_PURPOSE (t), used, 1); | |
30394414 JM |
4053 | } |
4054 | ||
5eea678f JM |
4055 | /* Combines two sets of overloaded functions into an OVERLOAD chain, removing |
4056 | duplicates. The first list becomes the tail of the result. | |
4057 | ||
61a127b3 MM |
4058 | The algorithm is O(n^2). We could get this down to O(n log n) by |
4059 | doing a sort on the addresses of the functions, if that becomes | |
4060 | necessary. */ | |
2c73f9f5 ML |
4061 | |
4062 | static tree | |
4063 | merge_functions (s1, s2) | |
4064 | tree s1; | |
4065 | tree s2; | |
4066 | { | |
5eea678f JM |
4067 | for (; s2; s2 = OVL_NEXT (s2)) |
4068 | { | |
4069 | tree fn = OVL_CURRENT (s2); | |
4070 | if (! ovl_member (fn, s1)) | |
4071 | s1 = build_overload (fn, s1); | |
4072 | } | |
2c73f9f5 ML |
4073 | return s1; |
4074 | } | |
4075 | ||
30394414 JM |
4076 | /* This should return an error not all definitions define functions. |
4077 | It is not an error if we find two functions with exactly the | |
4078 | same signature, only if these are selected in overload resolution. | |
2c73f9f5 | 4079 | old is the current set of bindings, new the freshly-found binding. |
30394414 JM |
4080 | XXX Do we want to give *all* candidates in case of ambiguity? |
4081 | XXX In what way should I treat extern declarations? | |
4082 | XXX I don't want to repeat the entire duplicate_decls here */ | |
2c73f9f5 | 4083 | |
30394414 | 4084 | static tree |
52c11ef6 | 4085 | ambiguous_decl (name, old, new, flags) |
2c73f9f5 ML |
4086 | tree name; |
4087 | tree old; | |
4088 | tree new; | |
52c11ef6 | 4089 | int flags; |
30394414 | 4090 | { |
52c11ef6 | 4091 | tree val, type; |
2c73f9f5 ML |
4092 | my_friendly_assert (old != NULL_TREE, 393); |
4093 | /* Copy the value. */ | |
52c11ef6 JM |
4094 | val = BINDING_VALUE (new); |
4095 | if (val) | |
4096 | switch (TREE_CODE (val)) | |
4097 | { | |
4098 | case TEMPLATE_DECL: | |
4099 | /* If we expect types or namespaces, and not templates, | |
4100 | or this is not a template class. */ | |
4101 | if (LOOKUP_QUALIFIERS_ONLY (flags) | |
4102 | && (!(flags & LOOKUP_TEMPLATES_EXPECTED) | |
4103 | || !DECL_CLASS_TEMPLATE_P (val))) | |
4104 | val = NULL_TREE; | |
4105 | break; | |
4106 | case TYPE_DECL: | |
4107 | if (LOOKUP_NAMESPACES_ONLY (flags)) | |
4108 | val = NULL_TREE; | |
4109 | break; | |
4110 | case NAMESPACE_DECL: | |
4111 | if (LOOKUP_TYPES_ONLY (flags)) | |
4112 | val = NULL_TREE; | |
4113 | break; | |
4114 | default: | |
4115 | if (LOOKUP_QUALIFIERS_ONLY (flags)) | |
4116 | val = NULL_TREE; | |
4117 | } | |
4118 | ||
2c73f9f5 | 4119 | if (!BINDING_VALUE (old)) |
52c11ef6 JM |
4120 | BINDING_VALUE (old) = val; |
4121 | else if (val && val != BINDING_VALUE (old)) | |
2c73f9f5 ML |
4122 | { |
4123 | if (is_overloaded_fn (BINDING_VALUE (old)) | |
52c11ef6 | 4124 | && is_overloaded_fn (val)) |
2c73f9f5 ML |
4125 | { |
4126 | BINDING_VALUE (old) = merge_functions (BINDING_VALUE (old), | |
52c11ef6 | 4127 | val); |
2c73f9f5 ML |
4128 | } |
4129 | else | |
4130 | { | |
4131 | /* Some declarations are functions, some are not. */ | |
52c11ef6 JM |
4132 | if (flags & LOOKUP_COMPLAIN) |
4133 | { | |
8251199e JM |
4134 | cp_error ("use of `%D' is ambiguous", name); |
4135 | cp_error_at (" first declared as `%#D' here", | |
52c11ef6 | 4136 | BINDING_VALUE (old)); |
8251199e | 4137 | cp_error_at (" also declared as `%#D' here", val); |
52c11ef6 | 4138 | } |
2c73f9f5 ML |
4139 | return error_mark_node; |
4140 | } | |
4141 | } | |
4142 | /* ... and copy the type. */ | |
52c11ef6 JM |
4143 | type = BINDING_TYPE (new); |
4144 | if (LOOKUP_NAMESPACES_ONLY (flags)) | |
4145 | type = NULL_TREE; | |
2c73f9f5 | 4146 | if (!BINDING_TYPE (old)) |
52c11ef6 | 4147 | BINDING_TYPE (old) = type; |
1c35f5b6 | 4148 | else if (type && BINDING_TYPE (old) != type) |
30394414 | 4149 | { |
52c11ef6 JM |
4150 | if (flags & LOOKUP_COMPLAIN) |
4151 | { | |
8251199e JM |
4152 | cp_error ("`%D' denotes an ambiguous type",name); |
4153 | cp_error_at (" first type here", BINDING_TYPE (old)); | |
4154 | cp_error_at (" other type here", type); | |
52c11ef6 | 4155 | } |
30394414 | 4156 | } |
2c73f9f5 | 4157 | return old; |
30394414 JM |
4158 | } |
4159 | ||
2c73f9f5 | 4160 | /* Add the bindings of name in used namespaces to val. |
ea9635c7 | 4161 | The using list is defined by usings, and the lookup goes to scope. |
2c73f9f5 ML |
4162 | Returns zero on errors. */ |
4163 | ||
4164 | int | |
52c11ef6 | 4165 | lookup_using_namespace (name, val, usings, scope, flags) |
ea9635c7 | 4166 | tree name, val, usings, scope; |
52c11ef6 | 4167 | int flags; |
30394414 JM |
4168 | { |
4169 | tree iter; | |
4170 | tree val1; | |
ea9635c7 ML |
4171 | /* Iterate over all used namespaces in current, searching for using |
4172 | directives of scope. */ | |
4173 | for (iter = usings; iter; iter = TREE_CHAIN (iter)) | |
4174 | if (TREE_VALUE (iter) == scope) | |
4175 | { | |
4176 | val1 = binding_for_name (name, TREE_PURPOSE (iter)); | |
4177 | /* Resolve ambiguities. */ | |
52c11ef6 | 4178 | val = ambiguous_decl (name, val, val1, flags); |
ea9635c7 | 4179 | } |
2c73f9f5 | 4180 | return val != error_mark_node; |
30394414 JM |
4181 | } |
4182 | ||
2c73f9f5 ML |
4183 | /* [namespace.qual] |
4184 | Excepts the name to lookup and its qualifying scope. | |
4185 | Returns the name/type pair found into the CPLUS_BINDING result, | |
4186 | or 0 on error. */ | |
4187 | ||
4188 | int | |
52c11ef6 | 4189 | qualified_lookup_using_namespace (name, scope, result, flags) |
30394414 JM |
4190 | tree name; |
4191 | tree scope; | |
2c73f9f5 | 4192 | tree result; |
52c11ef6 | 4193 | int flags; |
30394414 | 4194 | { |
2c73f9f5 | 4195 | /* Maintain a list of namespaces visited... */ |
30394414 | 4196 | tree seen = NULL_TREE; |
2c73f9f5 | 4197 | /* ... and a list of namespace yet to see. */ |
30394414 JM |
4198 | tree todo = NULL_TREE; |
4199 | tree usings; | |
2c73f9f5 | 4200 | while (scope && (result != error_mark_node)) |
30394414 JM |
4201 | { |
4202 | seen = temp_tree_cons (scope, NULL_TREE, seen); | |
52c11ef6 JM |
4203 | result = ambiguous_decl (name, result, |
4204 | binding_for_name (name, scope), flags); | |
2c73f9f5 ML |
4205 | if (!BINDING_VALUE (result) && !BINDING_TYPE (result)) |
4206 | /* Consider using directives. */ | |
30394414 JM |
4207 | for (usings = DECL_NAMESPACE_USING (scope); usings; |
4208 | usings = TREE_CHAIN (usings)) | |
2c73f9f5 | 4209 | /* If this was a real directive, and we have not seen it. */ |
30394414 | 4210 | if (!TREE_INDIRECT_USING (usings) |
2b9dc906 | 4211 | && !purpose_member (TREE_PURPOSE (usings), seen)) |
30394414 JM |
4212 | todo = temp_tree_cons (TREE_PURPOSE (usings), NULL_TREE, todo); |
4213 | if (todo) | |
4214 | { | |
4215 | scope = TREE_PURPOSE (todo); | |
4216 | todo = TREE_CHAIN (todo); | |
4217 | } | |
4218 | else | |
2c73f9f5 | 4219 | scope = NULL_TREE; /* If there never was a todo list. */ |
30394414 | 4220 | } |
2c73f9f5 | 4221 | return result != error_mark_node; |
30394414 | 4222 | } |
6060a796 | 4223 | |
2c73f9f5 ML |
4224 | /* [namespace.memdef]/2 */ |
4225 | ||
4226 | /* Set the context of a declaration to scope. Complain if we are not | |
4227 | outside scope. */ | |
4228 | ||
4229 | void | |
4230 | set_decl_namespace (decl, scope) | |
4231 | tree decl; | |
4232 | tree scope; | |
4233 | { | |
4234 | tree old; | |
4235 | if (scope == std_node) | |
4236 | scope = global_namespace; | |
3e3f722c ML |
4237 | /* Get rid of namespace aliases. */ |
4238 | scope = ORIGINAL_NAMESPACE (scope); | |
4239 | ||
2c73f9f5 | 4240 | if (!is_namespace_ancestor (current_namespace, scope)) |
8251199e | 4241 | cp_error ("declaration of `%D' not in a namespace surrounding `%D'", |
2c73f9f5 | 4242 | decl, scope); |
cb0dbb9a | 4243 | DECL_CONTEXT (decl) = FROB_CONTEXT (scope); |
2c73f9f5 ML |
4244 | if (scope != current_namespace) |
4245 | { | |
4246 | /* See whether this has been declared in the namespace. */ | |
4247 | old = namespace_binding (DECL_NAME (decl), scope); | |
4248 | if (!old) | |
4249 | /* No old declaration at all. */ | |
4250 | goto complain; | |
4251 | if (!is_overloaded_fn (decl)) | |
4252 | /* Don't compare non-function decls with decls_match here, | |
4253 | since it can't check for the correct constness at this | |
4254 | point. pushdecl will find those errors later. */ | |
4255 | return; | |
4256 | /* Since decl is a function, old should contain a function decl. */ | |
4257 | if (!is_overloaded_fn (old)) | |
4258 | goto complain; | |
4259 | for (; old; old = OVL_NEXT (old)) | |
4260 | if (decls_match (decl, OVL_CURRENT (old))) | |
4261 | return; | |
4262 | } | |
4263 | else | |
4264 | return; | |
4265 | complain: | |
8251199e | 4266 | cp_error ("`%D' should have been declared inside `%D'", |
2c73f9f5 ML |
4267 | decl, scope); |
4268 | } | |
4269 | ||
4270 | /* Compute the namespace where a declaration is defined. */ | |
e92cc029 | 4271 | |
6060a796 | 4272 | tree |
2c73f9f5 ML |
4273 | decl_namespace (decl) |
4274 | tree decl; | |
6060a796 | 4275 | { |
2c73f9f5 ML |
4276 | while (DECL_CONTEXT (decl)) |
4277 | { | |
4278 | decl = DECL_CONTEXT (decl); | |
4279 | if (TREE_CODE (decl) == NAMESPACE_DECL) | |
4280 | return decl; | |
4281 | if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't') | |
4282 | decl = TYPE_STUB_DECL (decl); | |
4283 | my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', 390); | |
4284 | } | |
4285 | ||
cb0dbb9a | 4286 | return global_namespace; |
6060a796 MS |
4287 | } |
4288 | ||
2c73f9f5 | 4289 | /* Return the namespace where the current declaration is declared. */ |
e92cc029 | 4290 | |
6060a796 | 4291 | tree |
2c73f9f5 | 4292 | current_decl_namespace () |
6060a796 | 4293 | { |
2c73f9f5 ML |
4294 | tree result; |
4295 | /* If we have been pushed into a different namespace, use it. */ | |
4296 | if (decl_namespace_list) | |
4297 | return TREE_PURPOSE (decl_namespace_list); | |
4298 | ||
4299 | if (current_class_type) | |
c3baf4b5 | 4300 | result = decl_namespace (TYPE_STUB_DECL (current_class_type)); |
2c73f9f5 | 4301 | else if (current_function_decl) |
c3baf4b5 | 4302 | result = decl_namespace (current_function_decl); |
2c73f9f5 ML |
4303 | else |
4304 | result = current_namespace; | |
4305 | return result; | |
4306 | } | |
6060a796 | 4307 | |
2c73f9f5 | 4308 | /* Temporarily set the namespace for the current declaration. */ |
6060a796 | 4309 | |
2c73f9f5 ML |
4310 | void |
4311 | push_decl_namespace (decl) | |
4312 | tree decl; | |
4313 | { | |
4314 | if (TREE_CODE (decl) != NAMESPACE_DECL) | |
4315 | decl = decl_namespace (decl); | |
4316 | decl_namespace_list = tree_cons (decl, NULL_TREE, decl_namespace_list); | |
4317 | } | |
4318 | ||
4319 | void | |
4320 | pop_decl_namespace () | |
4321 | { | |
4322 | decl_namespace_list = TREE_CHAIN (decl_namespace_list); | |
4323 | } | |
4324 | ||
9a68c51f JM |
4325 | static void |
4326 | check_decl_namespace () | |
4327 | { | |
4328 | my_friendly_assert (decl_namespace_list == NULL_TREE, 980711); | |
4329 | } | |
4330 | ||
2c73f9f5 ML |
4331 | /* [basic.lookup.koenig] */ |
4332 | /* A non-zero return value in the functions below indicates an error. | |
4333 | All nodes allocated in the procedure are on the scratch obstack. */ | |
4334 | ||
4335 | struct arg_lookup | |
4336 | { | |
4337 | tree name; | |
4338 | tree namespaces; | |
4339 | tree classes; | |
4340 | tree functions; | |
4341 | }; | |
4342 | ||
4343 | static int arg_assoc PROTO((struct arg_lookup*, tree)); | |
4344 | static int arg_assoc_args PROTO((struct arg_lookup*, tree)); | |
61a127b3 | 4345 | static int arg_assoc_type PROTO((struct arg_lookup*, tree)); |
2c73f9f5 | 4346 | |
2d390867 JM |
4347 | /* Add a function to the lookup structure. |
4348 | Returns 1 on error. */ | |
2c73f9f5 ML |
4349 | |
4350 | static int | |
4351 | add_function (k, fn) | |
4352 | struct arg_lookup *k; | |
4353 | tree fn; | |
4354 | { | |
4355 | if (ovl_member (fn, k->functions)) | |
4356 | return 0; | |
5f8ac7d1 ML |
4357 | /* We must find only functions, or exactly one non-function. */ |
4358 | if (k->functions && is_overloaded_fn (k->functions) | |
4359 | && is_overloaded_fn (fn)) | |
4360 | k->functions = build_overload (fn, k->functions); | |
4361 | else | |
4362 | if(k->functions) | |
4363 | { | |
4364 | tree f1 = OVL_CURRENT (k->functions); | |
4365 | tree f2 = fn; | |
4366 | if (is_overloaded_fn (f1)) | |
4367 | { | |
4368 | fn = f1; f1 = f2; f2 = fn; | |
4369 | } | |
8251199e JM |
4370 | cp_error_at ("`%D' is not a function,", f1); |
4371 | cp_error_at (" conflict with `%D'", f2); | |
4372 | cp_error (" in call to `%D'", k->name); | |
5f8ac7d1 ML |
4373 | return 1; |
4374 | } | |
4375 | else | |
4376 | k->functions = fn; | |
2c73f9f5 ML |
4377 | return 0; |
4378 | } | |
4379 | ||
2d390867 JM |
4380 | /* Add functions of a namespace to the lookup structure. |
4381 | Returns 1 on error. */ | |
2c73f9f5 ML |
4382 | |
4383 | static int | |
4384 | arg_assoc_namespace (k, scope) | |
4385 | struct arg_lookup *k; | |
4386 | tree scope; | |
4387 | { | |
4388 | tree value; | |
4389 | ||
4390 | if (purpose_member (scope, k->namespaces)) | |
4391 | return 0; | |
4392 | k->namespaces = tree_cons (scope, NULL_TREE, k->namespaces); | |
4393 | ||
4394 | value = namespace_binding (k->name, scope); | |
4395 | if (!value) | |
4396 | return 0; | |
4397 | ||
2c73f9f5 ML |
4398 | for (; value; value = OVL_NEXT (value)) |
4399 | if (add_function (k, OVL_CURRENT (value))) | |
4400 | return 1; | |
4401 | ||
4402 | return 0; | |
6060a796 | 4403 | } |
2c73f9f5 | 4404 | |
2d390867 JM |
4405 | /* Adds everything associated with class to the lookup structure. |
4406 | Returns 1 on error. */ | |
2c73f9f5 ML |
4407 | |
4408 | static int | |
4409 | arg_assoc_class (k, type) | |
4410 | struct arg_lookup* k; | |
4411 | tree type; | |
4412 | { | |
4413 | tree list, friends, context; | |
4414 | int i; | |
4415 | ||
4416 | if (purpose_member (type, k->classes)) | |
4417 | return 0; | |
4418 | k->classes = tree_cons (type, NULL_TREE, k->classes); | |
4419 | ||
4420 | context = decl_namespace (TYPE_MAIN_DECL (type)); | |
4421 | if (arg_assoc_namespace (k, context)) | |
4422 | return 1; | |
4423 | ||
4424 | /* Process baseclasses. */ | |
4425 | for (i = 0; i < CLASSTYPE_N_BASECLASSES (type); i++) | |
4426 | if (arg_assoc_class (k, TYPE_BINFO_BASETYPE (type, i))) | |
4427 | return 1; | |
4428 | ||
4429 | /* Process friends. */ | |
4430 | for (list = DECL_FRIENDLIST (TYPE_MAIN_DECL (type)); list; | |
4431 | list = TREE_CHAIN (list)) | |
4432 | if (k->name == TREE_PURPOSE (list)) | |
4433 | for (friends = TREE_VALUE (list); friends; | |
4434 | friends = TREE_CHAIN (friends)) | |
4435 | /* Only interested in global functions with potentially hidden | |
4436 | (i.e. unqualified) declarations. */ | |
4437 | if (TREE_PURPOSE (list) == error_mark_node && TREE_VALUE (list) | |
4438 | && decl_namespace (TREE_VALUE (list)) == context) | |
4439 | if (add_function (k, TREE_VALUE (list))) | |
4440 | return 1; | |
00dc6358 JM |
4441 | |
4442 | /* Process template arguments. */ | |
4443 | if (CLASSTYPE_TEMPLATE_INFO (type)) | |
4444 | { | |
36a117a5 | 4445 | list = innermost_args (CLASSTYPE_TI_ARGS (type)); |
00dc6358 JM |
4446 | for (i = 0; i < TREE_VEC_LENGTH (list); ++i) |
4447 | arg_assoc (k, TREE_VEC_ELT (list, i)); | |
4448 | } | |
4449 | ||
2c73f9f5 ML |
4450 | return 0; |
4451 | } | |
4452 | ||
2d390867 JM |
4453 | /* Adds everything associated with a given type. |
4454 | Returns 1 on error. */ | |
2c73f9f5 ML |
4455 | |
4456 | static int | |
4457 | arg_assoc_type (k, type) | |
4458 | struct arg_lookup *k; | |
4459 | tree type; | |
4460 | { | |
4461 | switch (TREE_CODE (type)) | |
4462 | { | |
4463 | case VOID_TYPE: | |
4464 | case INTEGER_TYPE: | |
4465 | case REAL_TYPE: | |
4466 | case COMPLEX_TYPE: | |
4467 | case CHAR_TYPE: | |
4468 | case BOOLEAN_TYPE: | |
4469 | return 0; | |
4470 | case RECORD_TYPE: | |
4471 | if (TYPE_PTRMEMFUNC_P (type)) | |
4472 | return arg_assoc_type (k, TYPE_PTRMEMFUNC_FN_TYPE (type)); | |
4473 | return arg_assoc_class (k, type); | |
4474 | case POINTER_TYPE: | |
4475 | case REFERENCE_TYPE: | |
4476 | case ARRAY_TYPE: | |
4477 | return arg_assoc_type (k, TREE_TYPE (type)); | |
4478 | case UNION_TYPE: | |
4479 | case ENUMERAL_TYPE: | |
4480 | return arg_assoc_namespace (k, decl_namespace (TYPE_MAIN_DECL (type))); | |
1813dd7b ML |
4481 | case OFFSET_TYPE: |
4482 | /* Pointer to member: associate class type and value type. */ | |
4483 | if (arg_assoc_type (k, TYPE_OFFSET_BASETYPE (type))) | |
4484 | return 1; | |
4485 | return arg_assoc_type (k, TREE_TYPE (type)); | |
2c73f9f5 | 4486 | case METHOD_TYPE: |
2d390867 JM |
4487 | /* The basetype is referenced in the first arg type, so just |
4488 | fall through. */ | |
2c73f9f5 ML |
4489 | case FUNCTION_TYPE: |
4490 | /* Associate the parameter types. */ | |
4491 | if (arg_assoc_args (k, TYPE_ARG_TYPES (type))) | |
4492 | return 1; | |
4493 | /* Associate the return type. */ | |
4494 | return arg_assoc_type (k, TREE_TYPE (type)); | |
2d390867 JM |
4495 | case TEMPLATE_TYPE_PARM: |
4496 | return 0; | |
1813dd7b ML |
4497 | case LANG_TYPE: |
4498 | if (type == unknown_type_node) | |
4499 | return 0; | |
4500 | /* else fall through */ | |
2c73f9f5 ML |
4501 | default: |
4502 | my_friendly_abort (390); | |
4503 | } | |
4504 | return 0; | |
4505 | } | |
4506 | ||
2d390867 | 4507 | /* Adds everything associated with arguments. Returns 1 on error. */ |
2c73f9f5 ML |
4508 | |
4509 | static int | |
4510 | arg_assoc_args (k, args) | |
4511 | struct arg_lookup* k; | |
4512 | tree args; | |
4513 | { | |
4514 | for (; args; args = TREE_CHAIN (args)) | |
4515 | if (arg_assoc (k, TREE_VALUE (args))) | |
4516 | return 1; | |
4517 | return 0; | |
4518 | } | |
4519 | ||
2d390867 | 4520 | /* Adds everything associated with a given tree_node. Returns 1 on error. */ |
2c73f9f5 ML |
4521 | |
4522 | static int | |
4523 | arg_assoc (k, n) | |
4524 | struct arg_lookup* k; | |
4525 | tree n; | |
4526 | { | |
00dc6358 JM |
4527 | if (n == error_mark_node) |
4528 | return 0; | |
4529 | ||
2d390867 JM |
4530 | if (TREE_CODE_CLASS (TREE_CODE (n)) == 't') |
4531 | return arg_assoc_type (k, n); | |
4532 | ||
4533 | if (! type_unknown_p (n)) | |
4534 | return arg_assoc_type (k, TREE_TYPE (n)); | |
4535 | ||
4536 | if (TREE_CODE (n) == ADDR_EXPR) | |
4537 | n = TREE_OPERAND (n, 0); | |
00dc6358 | 4538 | while (TREE_CODE (n) == TREE_LIST) |
2d390867 JM |
4539 | n = TREE_VALUE (n); |
4540 | ||
0c8bfdbc MM |
4541 | if (TREE_CODE (n) == TEMPLATE_ID_EXPR) |
4542 | { | |
4543 | /* [basic.lookup.koenig] | |
4544 | ||
4545 | If T is a template-id, its associated namespaces and classes | |
4546 | are the namespace in which the template is defined; for | |
4547 | member templates, the member template's class; the namespaces | |
4548 | and classes associated with the types of the template | |
4549 | arguments provided for template type parameters (excluding | |
4550 | template template parameters); the namespaces in which any | |
4551 | template template arguments are defined; and the classes in | |
4552 | which any member templates used as template template | |
4553 | arguments are defined. [Note: non-type template arguments do | |
4554 | not contribute to the set of associated namespaces. ] */ | |
4555 | tree template = TREE_OPERAND (n, 0); | |
4556 | tree args = TREE_OPERAND (n, 1); | |
4557 | tree ctx; | |
4558 | tree arg; | |
4559 | ||
4560 | /* First, the template. There may actually be more than one if | |
4561 | this is an overloaded function template. But, in that case, | |
4562 | we only need the first; all the functions will be in the same | |
4563 | namespace. */ | |
4564 | template = OVL_CURRENT (template); | |
4565 | ||
4566 | ctx = CP_DECL_CONTEXT (template); | |
4567 | ||
4568 | if (TREE_CODE (ctx) == NAMESPACE_DECL) | |
4569 | { | |
4570 | if (arg_assoc_namespace (k, ctx) == 1) | |
4571 | return 1; | |
4572 | } | |
4573 | /* It must be a member template. */ | |
4574 | else if (arg_assoc_class (k, ctx) == 1) | |
4575 | return 1; | |
2d390867 | 4576 | |
0c8bfdbc MM |
4577 | /* Now the arguments. */ |
4578 | for (arg = args; arg != NULL_TREE; arg = TREE_CHAIN (arg)) | |
4579 | { | |
4580 | tree t = TREE_VALUE (arg); | |
4581 | ||
4582 | if (TREE_CODE (t) == TEMPLATE_DECL) | |
4583 | { | |
4584 | ctx = CP_DECL_CONTEXT (t); | |
4585 | if (TREE_CODE (ctx) == NAMESPACE_DECL) | |
4586 | { | |
4587 | if (arg_assoc_namespace (k, ctx) == 1) | |
4588 | return 1; | |
4589 | } | |
4590 | else if (arg_assoc_class (k, ctx) == 1) | |
4591 | return 1; | |
4592 | } | |
4593 | else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't' | |
61a127b3 | 4594 | && arg_assoc_type (k, t) == 1) |
0c8bfdbc MM |
4595 | return 1; |
4596 | } | |
4597 | } | |
4598 | else | |
4599 | { | |
4600 | my_friendly_assert (TREE_CODE (n) == OVERLOAD, 980715); | |
4601 | ||
4602 | for (; n; n = OVL_CHAIN (n)) | |
4603 | if (arg_assoc (k, OVL_FUNCTION (n))) | |
4604 | return 1; | |
4605 | } | |
2c73f9f5 | 4606 | |
2c73f9f5 ML |
4607 | return 0; |
4608 | } | |
4609 | ||
4610 | /* Performs Koenig lookup depending on arguments, where fns | |
4611 | are the functions found in normal lookup. */ | |
4612 | ||
4613 | tree | |
4614 | lookup_arg_dependent (name, fns, args) | |
4615 | tree name; | |
4616 | tree fns; | |
4617 | tree args; | |
4618 | { | |
4619 | struct arg_lookup k; | |
4620 | k.name = name; | |
4621 | k.functions = fns; | |
4622 | k.namespaces = NULL_TREE; | |
4623 | k.classes = NULL_TREE; | |
4624 | ||
4625 | push_scratch_obstack (); | |
4626 | arg_assoc_args (&k, args); | |
4627 | pop_obstacks (); | |
4628 | return k.functions; | |
4629 | } | |
4630 | ||
4631 | /* Process a namespace-alias declaration. */ | |
6060a796 | 4632 | |
6060a796 | 4633 | void |
a9aedbc2 MS |
4634 | do_namespace_alias (alias, namespace) |
4635 | tree alias, namespace; | |
6060a796 | 4636 | { |
3e3f722c | 4637 | if (TREE_CODE (namespace) != NAMESPACE_DECL) |
30394414 | 4638 | { |
3e3f722c | 4639 | /* The parser did not find it, so it's not there. */ |
8251199e | 4640 | cp_error ("unknown namespace `%D'", namespace); |
30394414 JM |
4641 | return; |
4642 | } | |
3e3f722c ML |
4643 | |
4644 | namespace = ORIGINAL_NAMESPACE (namespace); | |
4645 | ||
85c6cbaf ML |
4646 | /* Build the alias. */ |
4647 | alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node); | |
4648 | DECL_NAMESPACE_ALIAS (alias) = namespace; | |
4649 | pushdecl (alias); | |
6060a796 MS |
4650 | } |
4651 | ||
ea9635c7 ML |
4652 | /* Check a non-member using-declaration. Return the name and scope |
4653 | being used, and the USING_DECL, or NULL_TREE on failure. */ | |
2c73f9f5 | 4654 | |
ea9635c7 ML |
4655 | static tree |
4656 | validate_nonmember_using_decl (decl, scope, name) | |
a9aedbc2 | 4657 | tree decl; |
ea9635c7 ML |
4658 | tree *scope; |
4659 | tree *name; | |
6060a796 | 4660 | { |
6633d636 MS |
4661 | if (TREE_CODE (decl) == SCOPE_REF |
4662 | && TREE_OPERAND (decl, 0) == std_node) | |
ea9635c7 | 4663 | return NULL_TREE; |
2c73f9f5 ML |
4664 | if (TREE_CODE (decl) == SCOPE_REF) |
4665 | { | |
ea9635c7 ML |
4666 | *scope = TREE_OPERAND (decl, 0); |
4667 | *name = TREE_OPERAND (decl, 1); | |
2c73f9f5 | 4668 | } |
0228fa7e ML |
4669 | else if (TREE_CODE (decl) == IDENTIFIER_NODE |
4670 | || TREE_CODE (decl) == TYPE_DECL) | |
2c73f9f5 | 4671 | { |
ea9635c7 ML |
4672 | *scope = global_namespace; |
4673 | *name = decl; | |
2c73f9f5 ML |
4674 | } |
4675 | else | |
4676 | my_friendly_abort (382); | |
ea9635c7 ML |
4677 | if (TREE_CODE_CLASS (TREE_CODE (*name)) == 'd') |
4678 | *name = DECL_NAME (*name); | |
2c73f9f5 | 4679 | /* Make a USING_DECL. */ |
ea9635c7 ML |
4680 | return push_using_decl (*scope, *name); |
4681 | } | |
4682 | ||
4683 | /* Process local and global using-declarations. */ | |
4684 | ||
4685 | static void | |
4686 | do_nonmember_using_decl (scope, name, oldval, oldtype, newval, newtype) | |
4687 | tree scope, name; | |
4688 | tree oldval, oldtype; | |
4689 | tree *newval, *newtype; | |
4690 | { | |
4691 | tree decls; | |
4692 | struct tree_binding _decls; | |
4693 | ||
4694 | *newval = *newtype = NULL_TREE; | |
2c73f9f5 | 4695 | decls = binding_init (&_decls); |
52c11ef6 | 4696 | if (!qualified_lookup_using_namespace (name, scope, decls, 0)) |
2c73f9f5 | 4697 | /* Lookup error */ |
a9aedbc2 | 4698 | return; |
6060a796 | 4699 | |
2c73f9f5 ML |
4700 | if (!BINDING_VALUE (decls) && !BINDING_TYPE (decls)) |
4701 | { | |
8251199e | 4702 | cp_error ("`%D' not declared", name); |
2c73f9f5 ML |
4703 | return; |
4704 | } | |
2c73f9f5 ML |
4705 | |
4706 | /* Check for using functions. */ | |
4707 | if (BINDING_VALUE (decls) && is_overloaded_fn (BINDING_VALUE (decls))) | |
4708 | { | |
2c73f9f5 | 4709 | tree tmp, tmp1; |
9ed182dc JM |
4710 | |
4711 | if (oldval && !is_overloaded_fn (oldval)) | |
4712 | { | |
4713 | duplicate_decls (OVL_CURRENT (BINDING_VALUE (decls)), oldval); | |
4714 | oldval = NULL_TREE; | |
4715 | } | |
4716 | ||
ea9635c7 | 4717 | *newval = oldval; |
2c73f9f5 ML |
4718 | for (tmp = BINDING_VALUE (decls); tmp; tmp = OVL_NEXT (tmp)) |
4719 | { | |
2c73f9f5 ML |
4720 | /* Compare each new function with each old one. |
4721 | If the old function was also used, there is no conflict. */ | |
4722 | for (tmp1 = oldval; tmp1; tmp1 = OVL_NEXT (tmp1)) | |
4723 | if (OVL_CURRENT (tmp) == OVL_CURRENT (tmp1)) | |
4724 | break; | |
4725 | else if (OVL_USED (tmp1)) | |
4726 | continue; | |
4727 | else if (duplicate_decls (OVL_CURRENT (tmp), OVL_CURRENT (tmp1))) | |
4728 | return; | |
a9aedbc2 | 4729 | |
2c73f9f5 ML |
4730 | /* Duplicate use, ignore */ |
4731 | if (tmp1) | |
4732 | continue; | |
4733 | ||
ea9635c7 ML |
4734 | *newval = build_overload (OVL_CURRENT (tmp), *newval); |
4735 | if (TREE_CODE (*newval) != OVERLOAD) | |
4736 | *newval = ovl_cons (*newval, NULL_TREE); | |
4737 | OVL_USED (*newval) = 1; | |
2c73f9f5 ML |
4738 | } |
4739 | } | |
4740 | else | |
a9aedbc2 | 4741 | { |
ea9635c7 | 4742 | *newval = BINDING_VALUE (decls); |
9ed182dc JM |
4743 | if (oldval) |
4744 | duplicate_decls (*newval, oldval); | |
2c73f9f5 ML |
4745 | } |
4746 | ||
ea9635c7 ML |
4747 | *newtype = BINDING_TYPE (decls); |
4748 | if (oldtype && *newtype && oldtype != *newtype) | |
2c73f9f5 | 4749 | { |
8251199e | 4750 | cp_error ("using directive `%D' introduced ambiguous type `%T'", |
ea9635c7 | 4751 | name, oldtype); |
2c73f9f5 | 4752 | return; |
a9aedbc2 | 4753 | } |
ea9635c7 ML |
4754 | } |
4755 | ||
4756 | /* Process a using-declaration not appearing in class or local scope. */ | |
4757 | ||
4758 | void | |
4759 | do_toplevel_using_decl (decl) | |
4760 | tree decl; | |
4761 | { | |
4762 | tree scope, name, binding; | |
4763 | tree oldval, oldtype, newval, newtype; | |
4764 | ||
4765 | decl = validate_nonmember_using_decl (decl, &scope, &name); | |
4766 | if (decl == NULL_TREE) | |
4767 | return; | |
4768 | ||
4769 | binding = binding_for_name (name, current_namespace); | |
4770 | ||
4771 | oldval = BINDING_VALUE (binding); | |
4772 | oldtype = BINDING_TYPE (binding); | |
4773 | ||
4774 | do_nonmember_using_decl (scope, name, oldval, oldtype, &newval, &newtype); | |
4775 | ||
2c73f9f5 ML |
4776 | /* Copy declarations found. */ |
4777 | if (newval) | |
4778 | BINDING_VALUE (binding) = newval; | |
4779 | if (newtype) | |
4780 | BINDING_TYPE (binding) = newtype; | |
4781 | return; | |
6060a796 MS |
4782 | } |
4783 | ||
9ed182dc JM |
4784 | /* Process a using-declaration at function scope. */ |
4785 | ||
ea9635c7 ML |
4786 | void |
4787 | do_local_using_decl (decl) | |
4788 | tree decl; | |
4789 | { | |
4790 | tree scope, name; | |
4791 | tree oldval, oldtype, newval, newtype; | |
9ed182dc | 4792 | |
ea9635c7 ML |
4793 | decl = validate_nonmember_using_decl (decl, &scope, &name); |
4794 | if (decl == NULL_TREE) | |
4795 | return; | |
4796 | ||
9ed182dc JM |
4797 | oldval = lookup_name_current_level (name); |
4798 | oldtype = lookup_type_current_level (name); | |
ea9635c7 ML |
4799 | |
4800 | do_nonmember_using_decl (scope, name, oldval, oldtype, &newval, &newtype); | |
4801 | ||
4802 | if (newval) | |
9ed182dc JM |
4803 | set_identifier_local_value (name, newval); |
4804 | if (newtype) | |
4805 | set_identifier_type_value (name, newtype); | |
ea9635c7 ML |
4806 | } |
4807 | ||
6060a796 | 4808 | tree |
a9aedbc2 | 4809 | do_class_using_decl (decl) |
6060a796 MS |
4810 | tree decl; |
4811 | { | |
cffa8729 | 4812 | tree name, value; |
f30432d7 | 4813 | |
2c73f9f5 ML |
4814 | if (TREE_CODE (decl) != SCOPE_REF |
4815 | || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (decl, 0))) != 't') | |
cffa8729 | 4816 | { |
8251199e | 4817 | cp_error ("using-declaration for non-member at class scope"); |
cffa8729 MS |
4818 | return NULL_TREE; |
4819 | } | |
4820 | name = TREE_OPERAND (decl, 1); | |
4821 | if (TREE_CODE (name) == BIT_NOT_EXPR) | |
4822 | { | |
8251199e | 4823 | cp_error ("using-declaration for destructor"); |
cffa8729 MS |
4824 | return NULL_TREE; |
4825 | } | |
1c35f5b6 JM |
4826 | if (TREE_CODE (name) == TYPE_DECL) |
4827 | name = DECL_NAME (name); | |
4828 | ||
4829 | my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 980716); | |
cffa8729 | 4830 | |
5566b478 | 4831 | value = build_lang_field_decl (USING_DECL, name, void_type_node); |
cffa8729 MS |
4832 | DECL_INITIAL (value) = TREE_OPERAND (decl, 0); |
4833 | return value; | |
6060a796 MS |
4834 | } |
4835 | ||
2c73f9f5 ML |
4836 | /* Process a using-directive. */ |
4837 | ||
6060a796 MS |
4838 | void |
4839 | do_using_directive (namespace) | |
4840 | tree namespace; | |
4841 | { | |
6633d636 MS |
4842 | if (namespace == std_node) |
4843 | return; | |
3e3f722c | 4844 | /* using namespace A::B::C; */ |
30394414 JM |
4845 | if (TREE_CODE (namespace) == SCOPE_REF) |
4846 | namespace = TREE_OPERAND (namespace, 1); | |
2c73f9f5 ML |
4847 | if (TREE_CODE (namespace) == IDENTIFIER_NODE) |
4848 | { | |
4849 | /* Lookup in lexer did not find a namespace. */ | |
8251199e | 4850 | cp_error ("namespace `%T' undeclared", namespace); |
2c73f9f5 ML |
4851 | return; |
4852 | } | |
4853 | if (TREE_CODE (namespace) != NAMESPACE_DECL) | |
4854 | { | |
8251199e | 4855 | cp_error ("`%T' is not a namespace", namespace); |
2c73f9f5 ML |
4856 | return; |
4857 | } | |
3e3f722c | 4858 | namespace = ORIGINAL_NAMESPACE (namespace); |
ea9635c7 | 4859 | if (!toplevel_bindings_p ()) |
9ed182dc | 4860 | push_using_directive (namespace); |
ea9635c7 ML |
4861 | else |
4862 | /* direct usage */ | |
4863 | add_using_namespace (current_namespace, namespace, 0); | |
6060a796 | 4864 | } |
f30432d7 MS |
4865 | |
4866 | void | |
4867 | check_default_args (x) | |
4868 | tree x; | |
4869 | { | |
4870 | tree arg = TYPE_ARG_TYPES (TREE_TYPE (x)); | |
4871 | int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE); | |
4872 | for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i) | |
4873 | { | |
4874 | if (TREE_PURPOSE (arg)) | |
4875 | saw_def = 1; | |
4876 | else if (saw_def) | |
4877 | { | |
8251199e | 4878 | cp_error_at ("default argument missing for parameter %P of `%+#D'", |
b7698cf0 | 4879 | i, x); |
f30432d7 MS |
4880 | break; |
4881 | } | |
4882 | } | |
4883 | } | |
72b7eeff MS |
4884 | |
4885 | void | |
4886 | mark_used (decl) | |
4887 | tree decl; | |
4888 | { | |
4889 | TREE_USED (decl) = 1; | |
5156628f | 4890 | if (processing_template_decl) |
5566b478 | 4891 | return; |
72b7eeff | 4892 | assemble_external (decl); |
36a117a5 | 4893 | |
73aad9b9 JM |
4894 | /* Is it a synthesized method that needs to be synthesized? */ |
4895 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl) | |
4896 | && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl) | |
4897 | /* Kludge: don't synthesize for default args. */ | |
4898 | && current_function_decl) | |
4899 | synthesize_method (decl); | |
36a117a5 MM |
4900 | |
4901 | /* If this is a function or variable that is an instance of some | |
4902 | template, we now know that we will need to actually do the | |
4903 | instantiation. A TEMPLATE_DECL may also have DECL_TEMPLATE_INFO, | |
4904 | if it's a partial instantiation, but there's no need to | |
03d0f4af MM |
4905 | instantiate such a thing. We check that DECL is not an explicit |
4906 | instantiation because that is not checked in instantiate_decl. */ | |
36a117a5 | 4907 | if (TREE_CODE (decl) != TEMPLATE_DECL |
03d0f4af MM |
4908 | && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl) |
4909 | && !DECL_EXPLICIT_INSTANTIATION (decl)) | |
5566b478 | 4910 | instantiate_decl (decl); |
72b7eeff | 4911 | } |
f62dbf03 JM |
4912 | |
4913 | /* Helper function for named_class_head_sans_basetype nonterminal. */ | |
4914 | ||
4915 | tree | |
4916 | handle_class_head (aggr, scope, id) | |
4917 | tree aggr, scope, id; | |
4918 | { | |
4919 | if (TREE_CODE (id) == TYPE_DECL) | |
4920 | return id; | |
4921 | ||
4922 | if (scope) | |
8251199e | 4923 | cp_error ("`%T' does not have a nested type named `%D'", scope, id); |
f62dbf03 | 4924 | else |
8251199e | 4925 | cp_error ("no file-scope type named `%D'", id); |
f62dbf03 JM |
4926 | |
4927 | id = xref_tag | |
ca107ded | 4928 | (aggr, make_anon_name (), 1); |
f62dbf03 JM |
4929 | return TYPE_MAIN_DECL (id); |
4930 | } |