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