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