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