]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Separate lexical analyzer for GNU C++. |
d6a8bdff | 2 | Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
b39309c8 | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
8d08fdba MS |
4 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
5 | ||
f5adbb8d | 6 | This file is part of GCC. |
8d08fdba | 7 | |
f5adbb8d | 8 | GCC is free software; you can redistribute it and/or modify |
8d08fdba MS |
9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
f5adbb8d | 13 | GCC is distributed in the hope that it will be useful, |
8d08fdba MS |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
f5adbb8d | 19 | along with GCC; see the file COPYING. If not, write to |
e9fa0c7c RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
22 | |
23 | ||
24 | /* This file is the lexical analyzer for GNU C++. */ | |
25 | ||
da20811c | 26 | #include "config.h" |
8d052bc7 | 27 | #include "system.h" |
4977bab6 ZW |
28 | #include "coretypes.h" |
29 | #include "tm.h" | |
8d08fdba MS |
30 | #include "input.h" |
31 | #include "tree.h" | |
8d08fdba | 32 | #include "cp-tree.h" |
0e5921e8 | 33 | #include "cpplib.h" |
8d08fdba | 34 | #include "flags.h" |
3d6f7931 | 35 | #include "c-pragma.h" |
54f92bfb | 36 | #include "toplev.h" |
7dee3f36 | 37 | #include "output.h" |
7bdb32b9 | 38 | #include "tm_p.h" |
2a9a326b | 39 | #include "timevar.h" |
8d08fdba | 40 | |
9e7d1164 NN |
41 | static int interface_strcmp (const char *); |
42 | static void init_cp_pragma (void); | |
0e5921e8 | 43 | |
9e7d1164 NN |
44 | static tree parse_strconst_pragma (const char *, int); |
45 | static void handle_pragma_vtable (cpp_reader *); | |
46 | static void handle_pragma_unit (cpp_reader *); | |
47 | static void handle_pragma_interface (cpp_reader *); | |
48 | static void handle_pragma_implementation (cpp_reader *); | |
49 | static void handle_pragma_java_exceptions (cpp_reader *); | |
0e5921e8 | 50 | |
9e7d1164 NN |
51 | static void init_operators (void); |
52 | static void copy_lang_type (tree); | |
8d08fdba | 53 | |
0e5921e8 | 54 | /* A constraint that can be tested at compile time. */ |
0e5921e8 | 55 | #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1] |
66a6250f | 56 | |
87e3dbc9 MM |
57 | /* Functions and data structures for #pragma interface. |
58 | ||
59 | `#pragma implementation' means that the main file being compiled | |
60 | is considered to implement (provide) the classes that appear in | |
61 | its main body. I.e., if this is file "foo.cc", and class `bar' | |
62 | is defined in "foo.cc", then we say that "foo.cc implements bar". | |
63 | ||
64 | All main input files "implement" themselves automagically. | |
65 | ||
66 | `#pragma interface' means that unless this file (of the form "foo.h" | |
67 | is not presently being included by file "foo.cc", the | |
68 | CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none | |
69 | of the vtables nor any of the inline functions defined in foo.h | |
70 | will ever be output. | |
71 | ||
72 | There are cases when we want to link files such as "defs.h" and | |
73 | "main.cc". In this case, we give "defs.h" a `#pragma interface', | |
74 | and "main.cc" has `#pragma implementation "defs.h"'. */ | |
75 | ||
76 | struct impl_files | |
77 | { | |
520a57c8 | 78 | const char *filename; |
87e3dbc9 MM |
79 | struct impl_files *next; |
80 | }; | |
81 | ||
82 | static struct impl_files *impl_file_chain; | |
83 | ||
8d08fdba | 84 | \f |
19551f29 | 85 | void |
9e7d1164 | 86 | cxx_finish (void) |
8d08fdba | 87 | { |
22703ccc | 88 | c_common_finish (); |
8d08fdba MS |
89 | } |
90 | ||
596ea4e5 AS |
91 | /* A mapping from tree codes to operator name information. */ |
92 | operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE]; | |
93 | /* Similar, but for assignment operators. */ | |
94 | operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE]; | |
5362b086 | 95 | |
596ea4e5 AS |
96 | /* Initialize data structures that keep track of operator names. */ |
97 | ||
0c918ce5 | 98 | #define DEF_OPERATOR(NAME, C, M, AR, AP) \ |
0e5921e8 ZW |
99 | CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256); |
100 | #include "operators.def" | |
101 | #undef DEF_OPERATOR | |
102 | ||
596ea4e5 | 103 | static void |
9e7d1164 | 104 | init_operators (void) |
596ea4e5 AS |
105 | { |
106 | tree identifier; | |
107 | char buffer[256]; | |
108 | struct operator_name_info_t *oni; | |
5362b086 | 109 | |
0c918ce5 | 110 | #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \ |
dba1acea | 111 | sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \ |
596ea4e5 AS |
112 | identifier = get_identifier (buffer); \ |
113 | IDENTIFIER_OPNAME_P (identifier) = 1; \ | |
114 | \ | |
115 | oni = (ASSN_P \ | |
116 | ? &assignment_operator_name_info[(int) CODE] \ | |
117 | : &operator_name_info[(int) CODE]); \ | |
118 | oni->identifier = identifier; \ | |
119 | oni->name = NAME; \ | |
3fa3c4bd MM |
120 | oni->mangled_name = MANGLING; \ |
121 | oni->arity = ARITY; | |
596ea4e5 AS |
122 | |
123 | #include "operators.def" | |
124 | #undef DEF_OPERATOR | |
125 | ||
5362b086 | 126 | operator_name_info[(int) ERROR_MARK].identifier |
596ea4e5 AS |
127 | = get_identifier ("<invalid operator>"); |
128 | ||
129 | /* Handle some special cases. These operators are not defined in | |
130 | the language, but can be produced internally. We may need them | |
131 | for error-reporting. (Eventually, we should ensure that this | |
132 | does not happen. Error messages involving these operators will | |
133 | be confusing to users.) */ | |
5362b086 EC |
134 | |
135 | operator_name_info [(int) INIT_EXPR].name | |
596ea4e5 AS |
136 | = operator_name_info [(int) MODIFY_EXPR].name; |
137 | operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)"; | |
138 | operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)"; | |
139 | operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)"; | |
140 | operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)"; | |
141 | operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)"; | |
142 | operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)"; | |
143 | operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)"; | |
144 | operator_name_info [(int) ABS_EXPR].name = "abs"; | |
596ea4e5 AS |
145 | operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&"; |
146 | operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||"; | |
596ea4e5 | 147 | operator_name_info [(int) RANGE_EXPR].name = "..."; |
392e3d51 | 148 | operator_name_info [(int) UNARY_PLUS_EXPR].name = "+"; |
596ea4e5 | 149 | |
5362b086 | 150 | assignment_operator_name_info [(int) EXACT_DIV_EXPR].name |
596ea4e5 | 151 | = "(exact /=)"; |
5362b086 | 152 | assignment_operator_name_info [(int) CEIL_DIV_EXPR].name |
596ea4e5 | 153 | = "(ceiling /=)"; |
5362b086 | 154 | assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name |
596ea4e5 | 155 | = "(floor /=)"; |
5362b086 | 156 | assignment_operator_name_info [(int) ROUND_DIV_EXPR].name |
596ea4e5 | 157 | = "(round /=)"; |
5362b086 | 158 | assignment_operator_name_info [(int) CEIL_MOD_EXPR].name |
596ea4e5 | 159 | = "(ceiling %=)"; |
5362b086 | 160 | assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name |
596ea4e5 | 161 | = "(floor %=)"; |
5362b086 | 162 | assignment_operator_name_info [(int) ROUND_MOD_EXPR].name |
596ea4e5 AS |
163 | = "(round %=)"; |
164 | } | |
165 | ||
0e5921e8 ZW |
166 | /* The reserved keyword table. */ |
167 | struct resword | |
8d08fdba | 168 | { |
8b60264b | 169 | const char *const word; |
df2b750f | 170 | ENUM_BITFIELD(rid) const rid : 16; |
8b60264b | 171 | const unsigned int disable : 16; |
0e5921e8 | 172 | }; |
8d08fdba | 173 | |
0e5921e8 ZW |
174 | /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is |
175 | _true_. */ | |
176 | #define D_EXT 0x01 /* GCC extension */ | |
177 | #define D_ASM 0x02 /* in C99, but has a switch to turn it off */ | |
e58a9aa1 | 178 | #define D_OBJC 0x04 /* Objective C++ only */ |
0e5921e8 ZW |
179 | |
180 | CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT); | |
181 | ||
182 | static const struct resword reswords[] = | |
183 | { | |
d9dbd9b1 | 184 | { "_Complex", RID_COMPLEX, 0 }, |
0ba8a114 NS |
185 | { "__FUNCTION__", RID_FUNCTION_NAME, 0 }, |
186 | { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 }, | |
0e5921e8 ZW |
187 | { "__alignof", RID_ALIGNOF, 0 }, |
188 | { "__alignof__", RID_ALIGNOF, 0 }, | |
189 | { "__asm", RID_ASM, 0 }, | |
190 | { "__asm__", RID_ASM, 0 }, | |
191 | { "__attribute", RID_ATTRIBUTE, 0 }, | |
192 | { "__attribute__", RID_ATTRIBUTE, 0 }, | |
7a3ea201 | 193 | { "__builtin_offsetof", RID_OFFSETOF, 0 }, |
0e5921e8 ZW |
194 | { "__builtin_va_arg", RID_VA_ARG, 0 }, |
195 | { "__complex", RID_COMPLEX, 0 }, | |
196 | { "__complex__", RID_COMPLEX, 0 }, | |
197 | { "__const", RID_CONST, 0 }, | |
198 | { "__const__", RID_CONST, 0 }, | |
199 | { "__extension__", RID_EXTENSION, 0 }, | |
0ba8a114 | 200 | { "__func__", RID_C99_FUNCTION_NAME, 0 }, |
0e5921e8 ZW |
201 | { "__imag", RID_IMAGPART, 0 }, |
202 | { "__imag__", RID_IMAGPART, 0 }, | |
203 | { "__inline", RID_INLINE, 0 }, | |
204 | { "__inline__", RID_INLINE, 0 }, | |
205 | { "__label__", RID_LABEL, 0 }, | |
206 | { "__null", RID_NULL, 0 }, | |
207 | { "__real", RID_REALPART, 0 }, | |
208 | { "__real__", RID_REALPART, 0 }, | |
209 | { "__restrict", RID_RESTRICT, 0 }, | |
210 | { "__restrict__", RID_RESTRICT, 0 }, | |
211 | { "__signed", RID_SIGNED, 0 }, | |
212 | { "__signed__", RID_SIGNED, 0 }, | |
7a1f3f5f | 213 | { "__thread", RID_THREAD, 0 }, |
0e5921e8 ZW |
214 | { "__typeof", RID_TYPEOF, 0 }, |
215 | { "__typeof__", RID_TYPEOF, 0 }, | |
216 | { "__volatile", RID_VOLATILE, 0 }, | |
217 | { "__volatile__", RID_VOLATILE, 0 }, | |
0e5921e8 | 218 | { "asm", RID_ASM, D_ASM }, |
0e5921e8 | 219 | { "auto", RID_AUTO, 0 }, |
0e5921e8 ZW |
220 | { "bool", RID_BOOL, 0 }, |
221 | { "break", RID_BREAK, 0 }, | |
222 | { "case", RID_CASE, 0 }, | |
223 | { "catch", RID_CATCH, 0 }, | |
224 | { "char", RID_CHAR, 0 }, | |
225 | { "class", RID_CLASS, 0 }, | |
0e5921e8 ZW |
226 | { "const", RID_CONST, 0 }, |
227 | { "const_cast", RID_CONSTCAST, 0 }, | |
228 | { "continue", RID_CONTINUE, 0 }, | |
229 | { "default", RID_DEFAULT, 0 }, | |
230 | { "delete", RID_DELETE, 0 }, | |
231 | { "do", RID_DO, 0 }, | |
232 | { "double", RID_DOUBLE, 0 }, | |
233 | { "dynamic_cast", RID_DYNCAST, 0 }, | |
234 | { "else", RID_ELSE, 0 }, | |
235 | { "enum", RID_ENUM, 0 }, | |
236 | { "explicit", RID_EXPLICIT, 0 }, | |
237 | { "export", RID_EXPORT, 0 }, | |
238 | { "extern", RID_EXTERN, 0 }, | |
239 | { "false", RID_FALSE, 0 }, | |
240 | { "float", RID_FLOAT, 0 }, | |
241 | { "for", RID_FOR, 0 }, | |
242 | { "friend", RID_FRIEND, 0 }, | |
243 | { "goto", RID_GOTO, 0 }, | |
244 | { "if", RID_IF, 0 }, | |
245 | { "inline", RID_INLINE, 0 }, | |
246 | { "int", RID_INT, 0 }, | |
247 | { "long", RID_LONG, 0 }, | |
248 | { "mutable", RID_MUTABLE, 0 }, | |
249 | { "namespace", RID_NAMESPACE, 0 }, | |
250 | { "new", RID_NEW, 0 }, | |
0e5921e8 | 251 | { "operator", RID_OPERATOR, 0 }, |
0e5921e8 ZW |
252 | { "private", RID_PRIVATE, 0 }, |
253 | { "protected", RID_PROTECTED, 0 }, | |
254 | { "public", RID_PUBLIC, 0 }, | |
255 | { "register", RID_REGISTER, 0 }, | |
256 | { "reinterpret_cast", RID_REINTCAST, 0 }, | |
257 | { "return", RID_RETURN, 0 }, | |
258 | { "short", RID_SHORT, 0 }, | |
259 | { "signed", RID_SIGNED, 0 }, | |
260 | { "sizeof", RID_SIZEOF, 0 }, | |
261 | { "static", RID_STATIC, 0 }, | |
262 | { "static_cast", RID_STATCAST, 0 }, | |
263 | { "struct", RID_STRUCT, 0 }, | |
264 | { "switch", RID_SWITCH, 0 }, | |
265 | { "template", RID_TEMPLATE, 0 }, | |
266 | { "this", RID_THIS, 0 }, | |
267 | { "throw", RID_THROW, 0 }, | |
268 | { "true", RID_TRUE, 0 }, | |
269 | { "try", RID_TRY, 0 }, | |
270 | { "typedef", RID_TYPEDEF, 0 }, | |
271 | { "typename", RID_TYPENAME, 0 }, | |
272 | { "typeid", RID_TYPEID, 0 }, | |
273 | { "typeof", RID_TYPEOF, D_ASM|D_EXT }, | |
274 | { "union", RID_UNION, 0 }, | |
275 | { "unsigned", RID_UNSIGNED, 0 }, | |
276 | { "using", RID_USING, 0 }, | |
277 | { "virtual", RID_VIRTUAL, 0 }, | |
278 | { "void", RID_VOID, 0 }, | |
279 | { "volatile", RID_VOLATILE, 0 }, | |
5362b086 | 280 | { "wchar_t", RID_WCHAR, 0 }, |
0e5921e8 | 281 | { "while", RID_WHILE, 0 }, |
0d3ba739 | 282 | |
e58a9aa1 ZL |
283 | /* The remaining keywords are specific to Objective-C++. NB: |
284 | All of them will remain _disabled_, since they are context- | |
285 | sensitive. */ | |
286 | ||
287 | /* These ObjC keywords are recognized only immediately after | |
288 | an '@'. NB: The following C++ keywords double as | |
289 | ObjC keywords in this context: RID_CLASS, RID_PRIVATE, | |
290 | RID_PROTECTED, RID_PUBLIC, RID_THROW, RID_TRY and RID_CATCH. */ | |
291 | { "compatibility_alias", RID_AT_ALIAS, D_OBJC }, | |
292 | { "defs", RID_AT_DEFS, D_OBJC }, | |
293 | { "encode", RID_AT_ENCODE, D_OBJC }, | |
294 | { "end", RID_AT_END, D_OBJC }, | |
295 | { "implementation", RID_AT_IMPLEMENTATION, D_OBJC }, | |
296 | { "interface", RID_AT_INTERFACE, D_OBJC }, | |
297 | { "protocol", RID_AT_PROTOCOL, D_OBJC }, | |
298 | { "selector", RID_AT_SELECTOR, D_OBJC }, | |
299 | { "finally", RID_AT_FINALLY, D_OBJC }, | |
300 | { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC }, | |
301 | /* These are recognized only in protocol-qualifier context. */ | |
302 | { "bycopy", RID_BYCOPY, D_OBJC }, | |
303 | { "byref", RID_BYREF, D_OBJC }, | |
304 | { "in", RID_IN, D_OBJC }, | |
305 | { "inout", RID_INOUT, D_OBJC }, | |
306 | { "oneway", RID_ONEWAY, D_OBJC }, | |
307 | { "out", RID_OUT, D_OBJC }, | |
0e5921e8 | 308 | }; |
0e5921e8 | 309 | |
f5e99456 | 310 | void |
9e7d1164 | 311 | init_reswords (void) |
0e5921e8 ZW |
312 | { |
313 | unsigned int i; | |
314 | tree id; | |
c372b0fa | 315 | int mask = ((flag_no_asm ? D_ASM : 0) |
e58a9aa1 | 316 | | D_OBJC |
0e5921e8 ZW |
317 | | (flag_no_gnu_keywords ? D_EXT : 0)); |
318 | ||
c68b0a84 | 319 | ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree)); |
ca7558fc | 320 | for (i = 0; i < ARRAY_SIZE (reswords); i++) |
2b2a3531 | 321 | { |
0e5921e8 ZW |
322 | id = get_identifier (reswords[i].word); |
323 | C_RID_CODE (id) = reswords[i].rid; | |
324 | ridpointers [(int) reswords[i].rid] = id; | |
325 | if (! (reswords[i].disable & mask)) | |
326 | C_IS_RESERVED_WORD (id) = 1; | |
2b2a3531 | 327 | } |
0e5921e8 | 328 | } |
2b2a3531 | 329 | |
0e5921e8 | 330 | static void |
9e7d1164 | 331 | init_cp_pragma (void) |
0e5921e8 | 332 | { |
c58b209a NB |
333 | c_register_pragma (0, "vtable", handle_pragma_vtable); |
334 | c_register_pragma (0, "unit", handle_pragma_unit); | |
335 | c_register_pragma (0, "interface", handle_pragma_interface); | |
336 | c_register_pragma (0, "implementation", handle_pragma_implementation); | |
337 | c_register_pragma ("GCC", "interface", handle_pragma_interface); | |
338 | c_register_pragma ("GCC", "implementation", handle_pragma_implementation); | |
339 | c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions); | |
0e5921e8 | 340 | } |
009ed910 | 341 | \f |
feea5b18 ILT |
342 | /* TRUE if a code represents a statement. */ |
343 | ||
344 | bool statement_code_p[MAX_TREE_CODES]; | |
345 | ||
f5e99456 NB |
346 | /* Initialize the C++ front end. This function is very sensitive to |
347 | the exact order that things are done here. It would be nice if the | |
348 | initialization done by this routine were moved to its subroutines, | |
349 | and the ordering dependencies clarified and reduced. */ | |
4bfec483 NB |
350 | bool |
351 | cxx_init (void) | |
0e5921e8 | 352 | { |
feea5b18 | 353 | unsigned int i; |
009ed910 | 354 | static const enum tree_code stmt_codes[] = { |
feea5b18 ILT |
355 | CTOR_INITIALIZER, TRY_BLOCK, HANDLER, |
356 | EH_SPEC_BLOCK, USING_STMT, TAG_DEFN, | |
357 | IF_STMT, CLEANUP_STMT, FOR_STMT, | |
358 | WHILE_STMT, DO_STMT, BREAK_STMT, | |
359 | CONTINUE_STMT, SWITCH_STMT, EXPR_STMT | |
009ed910 SB |
360 | }; |
361 | ||
feea5b18 ILT |
362 | memset (&statement_code_p, 0, sizeof (statement_code_p)); |
363 | for (i = 0; i < ARRAY_SIZE (stmt_codes); i++) | |
364 | statement_code_p[stmt_codes[i]] = true; | |
009ed910 | 365 | |
267a0752 MC |
366 | /* We cannot just assign to input_filename because it has already |
367 | been initialized and will be used later as an N_BINCL for stabs+ | |
368 | debugging. */ | |
93409b8c PB |
369 | #ifdef USE_MAPPED_LOCATION |
370 | push_srcloc (BUILTINS_LOCATION); | |
371 | #else | |
372 | push_srcloc ("<built-in>", 0); | |
373 | #endif | |
0e5921e8 ZW |
374 | |
375 | init_reswords (); | |
87e3dbc9 | 376 | init_tree (); |
54f7877c | 377 | init_cp_semantics (); |
596ea4e5 | 378 | init_operators (); |
669ec2b4 | 379 | init_method (); |
8d08fdba | 380 | init_error (); |
f3cdb9c6 | 381 | |
8d08fdba MS |
382 | current_function_decl = NULL; |
383 | ||
9e62871e | 384 | class_type_node = ridpointers[(int) RID_CLASS]; |
8d08fdba | 385 | |
f5e99456 NB |
386 | cxx_init_decl_processing (); |
387 | ||
4684cd27 MM |
388 | /* The fact that G++ uses COMDAT for many entities (inline |
389 | functions, template instantiations, virtual tables, etc.) mean | |
390 | that it is fundamentally unreliable to try to make decisions | |
391 | about whether or not to output a particular entity until the end | |
392 | of the compilation. However, the inliner requires that functions | |
393 | be provided to the back end if they are to be inlined. | |
394 | Therefore, we always use unit-at-a-time mode; in that mode, we | |
395 | can provide entities to the back end and it will decide what to | |
396 | emit based on what is actually needed. */ | |
397 | flag_unit_at_a_time = 1; | |
398 | ||
4bfec483 | 399 | if (c_common_init () == false) |
267a0752 MC |
400 | { |
401 | pop_srcloc(); | |
402 | return false; | |
403 | } | |
f5e99456 NB |
404 | |
405 | init_cp_pragma (); | |
406 | ||
4684cd27 | 407 | init_repo (); |
f5e99456 | 408 | |
267a0752 | 409 | pop_srcloc(); |
4bfec483 | 410 | return true; |
8d08fdba | 411 | } |
8d08fdba | 412 | \f |
51c184be | 413 | /* Return nonzero if S is not considered part of an |
8d08fdba | 414 | INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */ |
e92cc029 | 415 | |
8d08fdba | 416 | static int |
9e7d1164 | 417 | interface_strcmp (const char* s) |
8d08fdba MS |
418 | { |
419 | /* Set the interface/implementation bits for this scope. */ | |
420 | struct impl_files *ifiles; | |
d8e178a0 | 421 | const char *s1; |
8d08fdba | 422 | |
8d08fdba MS |
423 | for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next) |
424 | { | |
d8e178a0 | 425 | const char *t1 = ifiles->filename; |
8d08fdba MS |
426 | s1 = s; |
427 | ||
428 | if (*s1 != *t1 || *s1 == 0) | |
429 | continue; | |
430 | ||
431 | while (*s1 == *t1 && *s1 != 0) | |
432 | s1++, t1++; | |
433 | ||
434 | /* A match. */ | |
435 | if (*s1 == *t1) | |
436 | return 0; | |
437 | ||
438 | /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */ | |
9473c522 | 439 | if (strchr (s1, '.') || strchr (t1, '.')) |
8d08fdba MS |
440 | continue; |
441 | ||
442 | if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.') | |
443 | continue; | |
444 | ||
445 | /* A match. */ | |
446 | return 0; | |
447 | } | |
448 | ||
449 | /* No matches. */ | |
450 | return 1; | |
451 | } | |
452 | ||
0e5921e8 ZW |
453 | \f |
454 | ||
455 | /* Parse a #pragma whose sole argument is a string constant. | |
456 | If OPT is true, the argument is optional. */ | |
457 | static tree | |
9e7d1164 | 458 | parse_strconst_pragma (const char* name, int opt) |
0e5921e8 ZW |
459 | { |
460 | tree result, x; | |
461 | enum cpp_ttype t; | |
462 | ||
463 | t = c_lex (&x); | |
464 | if (t == CPP_STRING) | |
465 | { | |
466 | result = x; | |
467 | if (c_lex (&x) != CPP_EOF) | |
d4ee4d25 | 468 | warning (0, "junk at end of #pragma %s", name); |
0e5921e8 ZW |
469 | return result; |
470 | } | |
471 | ||
472 | if (t == CPP_EOF && opt) | |
473 | return 0; | |
474 | ||
475 | error ("invalid #pragma %s", name); | |
476 | return (tree)-1; | |
477 | } | |
5362b086 | 478 | |
0e5921e8 | 479 | static void |
9e7d1164 | 480 | handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
0e5921e8 | 481 | { |
46ccf50a JM |
482 | parse_strconst_pragma ("vtable", 0); |
483 | sorry ("#pragma vtable no longer supported"); | |
0e5921e8 ZW |
484 | } |
485 | ||
1d02ac83 | 486 | static void |
9e7d1164 | 487 | handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
1d02ac83 | 488 | { |
0e5921e8 ZW |
489 | /* Validate syntax, but don't do anything. */ |
490 | parse_strconst_pragma ("unit", 0); | |
491 | } | |
492 | ||
493 | static void | |
9e7d1164 | 494 | handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
0e5921e8 ZW |
495 | { |
496 | tree fname = parse_strconst_pragma ("interface", 1); | |
497 | struct c_fileinfo *finfo; | |
c162c75e | 498 | const char *filename; |
0e5921e8 ZW |
499 | |
500 | if (fname == (tree)-1) | |
501 | return; | |
502 | else if (fname == 0) | |
c162c75e | 503 | filename = lbasename (input_filename); |
0e5921e8 | 504 | else |
c162c75e | 505 | filename = ggc_strdup (TREE_STRING_POINTER (fname)); |
0e5921e8 | 506 | |
c162c75e | 507 | finfo = get_fileinfo (filename); |
1d02ac83 JM |
508 | |
509 | if (impl_file_chain == 0) | |
510 | { | |
511 | /* If this is zero at this point, then we are | |
512 | auto-implementing. */ | |
513 | if (main_input_filename == 0) | |
514 | main_input_filename = input_filename; | |
1d02ac83 JM |
515 | } |
516 | ||
c162c75e | 517 | finfo->interface_only = interface_strcmp (filename); |
15072eb1 ZW |
518 | /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see |
519 | a definition in another file. */ | |
5d709b00 ZW |
520 | if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only) |
521 | finfo->interface_unknown = 0; | |
1d02ac83 JM |
522 | } |
523 | ||
777ffbda JM |
524 | /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME. |
525 | We used to only allow this at toplevel, but that restriction was buggy | |
526 | in older compilers and it seems reasonable to allow it in the headers | |
527 | themselves, too. It only needs to precede the matching #p interface. | |
528 | ||
5d709b00 ZW |
529 | We don't touch finfo->interface_only or finfo->interface_unknown; |
530 | the user must specify a matching #p interface for this to have | |
531 | any effect. */ | |
777ffbda | 532 | |
1d02ac83 | 533 | static void |
9e7d1164 | 534 | handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
1d02ac83 | 535 | { |
0e5921e8 | 536 | tree fname = parse_strconst_pragma ("implementation", 1); |
c162c75e | 537 | const char *filename; |
777ffbda | 538 | struct impl_files *ifiles = impl_file_chain; |
0e5921e8 ZW |
539 | |
540 | if (fname == (tree)-1) | |
541 | return; | |
542 | ||
543 | if (fname == 0) | |
544 | { | |
545 | if (main_input_filename) | |
c162c75e | 546 | filename = main_input_filename; |
0e5921e8 | 547 | else |
c162c75e MA |
548 | filename = input_filename; |
549 | filename = lbasename (filename); | |
0e5921e8 ZW |
550 | } |
551 | else | |
552 | { | |
c162c75e MA |
553 | filename = ggc_strdup (TREE_STRING_POINTER (fname)); |
554 | #if 0 | |
555 | /* We currently cannot give this diagnostic, as we reach this point | |
556 | only after cpplib has scanned the entire translation unit, so | |
557 | cpp_included always returns true. A plausible fix is to compare | |
558 | the current source-location cookie with the first source-location | |
559 | cookie (if any) of the filename, but this requires completing the | |
560 | --enable-mapped-location project first. See PR 17577. */ | |
561 | if (cpp_included (parse_in, filename)) | |
d4ee4d25 | 562 | warning (0, "#pragma implementation for %qs appears after " |
c162c75e MA |
563 | "file is included", filename); |
564 | #endif | |
0e5921e8 ZW |
565 | } |
566 | ||
777ffbda | 567 | for (; ifiles; ifiles = ifiles->next) |
1d02ac83 | 568 | { |
c162c75e | 569 | if (! strcmp (ifiles->filename, filename)) |
777ffbda | 570 | break; |
1d02ac83 | 571 | } |
777ffbda | 572 | if (ifiles == 0) |
1d02ac83 | 573 | { |
c68b0a84 | 574 | ifiles = xmalloc (sizeof (struct impl_files)); |
c162c75e | 575 | ifiles->filename = filename; |
777ffbda JM |
576 | ifiles->next = impl_file_chain; |
577 | impl_file_chain = ifiles; | |
1d02ac83 | 578 | } |
1d02ac83 | 579 | } |
f181d4ae | 580 | |
1f730ff7 ZW |
581 | /* Indicate that this file uses Java-personality exception handling. */ |
582 | static void | |
9e7d1164 | 583 | handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
1f730ff7 ZW |
584 | { |
585 | tree x; | |
586 | if (c_lex (&x) != CPP_EOF) | |
d4ee4d25 | 587 | warning (0, "junk at end of #pragma GCC java_exceptions"); |
1f730ff7 ZW |
588 | |
589 | choose_personality_routine (lang_java); | |
590 | } | |
591 | ||
15c7fb9c | 592 | /* Issue an error message indicating that the lookup of NAME (an |
b3445994 | 593 | IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */ |
15c7fb9c | 594 | |
b3445994 | 595 | tree |
15c7fb9c MM |
596 | unqualified_name_lookup_error (tree name) |
597 | { | |
598 | if (IDENTIFIER_OPNAME_P (name)) | |
599 | { | |
600 | if (name != ansi_opname (ERROR_MARK)) | |
2a13a625 | 601 | error ("%qD not defined", name); |
15c7fb9c | 602 | } |
15c7fb9c MM |
603 | else |
604 | { | |
2a13a625 | 605 | error ("%qD was not declared in this scope", name); |
58ec3cc5 MM |
606 | /* Prevent repeated error messages by creating a VAR_DECL with |
607 | this NAME in the innermost block scope. */ | |
608 | if (current_function_decl) | |
15c7fb9c | 609 | { |
58ec3cc5 MM |
610 | tree decl; |
611 | decl = build_decl (VAR_DECL, name, error_mark_node); | |
612 | DECL_CONTEXT (decl) = current_function_decl; | |
613 | push_local_binding (name, decl, 0); | |
996c2b52 MM |
614 | /* Mark the variable as used so that we do not get warnings |
615 | about it being unused later. */ | |
616 | TREE_USED (decl) = 1; | |
15c7fb9c | 617 | } |
15c7fb9c | 618 | } |
935d1834 | 619 | |
b3445994 | 620 | return error_mark_node; |
5566b478 MS |
621 | } |
622 | ||
b3445994 MM |
623 | /* Like unqualified_name_lookup_error, but NAME is an unqualified-id |
624 | used as a function. Returns an appropriate expression for | |
625 | NAME. */ | |
626 | ||
5566b478 | 627 | tree |
b3445994 | 628 | unqualified_fn_lookup_error (tree name) |
5566b478 | 629 | { |
5156628f | 630 | if (processing_template_decl) |
5566b478 | 631 | { |
b3445994 MM |
632 | /* In a template, it is invalid to write "f()" or "f(3)" if no |
633 | declaration of "f" is available. Historically, G++ and most | |
c5785644 WB |
634 | other compilers accepted that usage since they deferred all name |
635 | lookup until instantiation time rather than doing unqualified | |
636 | name lookup at template definition time; explain to the user what | |
637 | is going wrong. | |
638 | ||
639 | Note that we have the exact wording of the following message in | |
640 | the manual (trouble.texi, node "Name lookup"), so they need to | |
641 | be kept in synch. */ | |
2a13a625 GDR |
642 | pedwarn ("there are no arguments to %qD that depend on a template " |
643 | "parameter, so a declaration of %qD must be available", | |
10b1d5e7 | 644 | name, name); |
b3445994 MM |
645 | |
646 | if (!flag_permissive) | |
5566b478 | 647 | { |
b3445994 MM |
648 | static bool hint; |
649 | if (!hint) | |
650 | { | |
597cdf4f JM |
651 | error ("(if you use %<-fpermissive%>, G++ will accept your " |
652 | "code, but allowing the use of an undeclared name is " | |
b3445994 MM |
653 | "deprecated)"); |
654 | hint = true; | |
655 | } | |
5566b478 | 656 | } |
10b1d5e7 | 657 | return name; |
5566b478 | 658 | } |
8d08fdba | 659 | |
b3445994 | 660 | return unqualified_name_lookup_error (name); |
8d08fdba MS |
661 | } |
662 | ||
8d08fdba | 663 | tree |
9e7d1164 | 664 | build_lang_decl (enum tree_code code, tree name, tree type) |
8d08fdba | 665 | { |
4ce3d537 MM |
666 | tree t; |
667 | ||
4ce3d537 | 668 | t = build_decl (code, name, type); |
fcfcdfc8 | 669 | retrofit_lang_decl (t); |
4ce3d537 | 670 | |
6dc36fed MM |
671 | /* All nesting of C++ functions is lexical; there is never a "static |
672 | chain" in the sense of GNU C nested functions. */ | |
673 | if (code == FUNCTION_DECL) | |
674 | DECL_NO_STATIC_CHAIN (t) = 1; | |
675 | ||
fcfcdfc8 JM |
676 | return t; |
677 | } | |
678 | ||
679 | /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl | |
680 | and pushdecl (for functions generated by the backend). */ | |
681 | ||
682 | void | |
9e7d1164 | 683 | retrofit_lang_decl (tree t) |
fcfcdfc8 | 684 | { |
9188c363 | 685 | struct lang_decl *ld; |
4ce3d537 | 686 | size_t size; |
8d08fdba | 687 | |
4ce3d537 MM |
688 | if (CAN_HAVE_FULL_LANG_DECL_P (t)) |
689 | size = sizeof (struct lang_decl); | |
690 | else | |
691 | size = sizeof (struct lang_decl_flags); | |
b0d06515 | 692 | |
99dd239f | 693 | ld = GGC_CNEWVAR (struct lang_decl, size); |
8d08fdba | 694 | |
e2500fed GK |
695 | ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0; |
696 | ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0; | |
697 | ld->decl_flags.u2sel = 0; | |
698 | if (ld->decl_flags.can_be_full) | |
699 | ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0; | |
700 | ||
9188c363 | 701 | DECL_LANG_SPECIFIC (t) = ld; |
ab73670a MM |
702 | if (current_lang_name == lang_name_cplusplus |
703 | || decl_linkage (t) == lk_none) | |
5d2ed28c | 704 | SET_DECL_LANGUAGE (t, lang_cplusplus); |
8d08fdba | 705 | else if (current_lang_name == lang_name_c) |
5d2ed28c | 706 | SET_DECL_LANGUAGE (t, lang_c); |
a1774733 | 707 | else if (current_lang_name == lang_name_java) |
5d2ed28c | 708 | SET_DECL_LANGUAGE (t, lang_java); |
8dc2b103 NS |
709 | else |
710 | gcc_unreachable (); | |
8d08fdba | 711 | |
8d08fdba MS |
712 | #ifdef GATHER_STATISTICS |
713 | tree_node_counts[(int)lang_decl] += 1; | |
4ce3d537 | 714 | tree_node_sizes[(int)lang_decl] += size; |
8d08fdba | 715 | #endif |
8d08fdba MS |
716 | } |
717 | ||
8d08fdba | 718 | void |
9e7d1164 | 719 | cxx_dup_lang_specific_decl (tree node) |
8d08fdba MS |
720 | { |
721 | int size; | |
d60f72ae | 722 | struct lang_decl *ld; |
8d08fdba | 723 | |
5566b478 MS |
724 | if (! DECL_LANG_SPECIFIC (node)) |
725 | return; | |
726 | ||
b0d06515 | 727 | if (!CAN_HAVE_FULL_LANG_DECL_P (node)) |
8d08fdba MS |
728 | size = sizeof (struct lang_decl_flags); |
729 | else | |
730 | size = sizeof (struct lang_decl); | |
99dd239f | 731 | ld = GGC_NEWVAR (struct lang_decl, size); |
4e135bdd | 732 | memcpy (ld, DECL_LANG_SPECIFIC (node), size); |
d60f72ae | 733 | DECL_LANG_SPECIFIC (node) = ld; |
11e74ea6 KL |
734 | |
735 | #ifdef GATHER_STATISTICS | |
736 | tree_node_counts[(int)lang_decl] += 1; | |
737 | tree_node_sizes[(int)lang_decl] += size; | |
738 | #endif | |
8d08fdba MS |
739 | } |
740 | ||
0acf7199 MM |
741 | /* Copy DECL, including any language-specific parts. */ |
742 | ||
743 | tree | |
9e7d1164 | 744 | copy_decl (tree decl) |
0acf7199 MM |
745 | { |
746 | tree copy; | |
747 | ||
748 | copy = copy_node (decl); | |
63e1b1c4 | 749 | cxx_dup_lang_specific_decl (copy); |
0acf7199 MM |
750 | return copy; |
751 | } | |
752 | ||
11e74ea6 KL |
753 | /* Replace the shared language-specific parts of NODE with a new copy. */ |
754 | ||
76648a8b | 755 | static void |
9e7d1164 | 756 | copy_lang_type (tree node) |
11e74ea6 KL |
757 | { |
758 | int size; | |
759 | struct lang_type *lt; | |
760 | ||
761 | if (! TYPE_LANG_SPECIFIC (node)) | |
762 | return; | |
763 | ||
e2500fed GK |
764 | if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class) |
765 | size = sizeof (struct lang_type); | |
766 | else | |
767 | size = sizeof (struct lang_type_ptrmem); | |
99dd239f | 768 | lt = GGC_NEWVAR (struct lang_type, size); |
11e74ea6 KL |
769 | memcpy (lt, TYPE_LANG_SPECIFIC (node), size); |
770 | TYPE_LANG_SPECIFIC (node) = lt; | |
771 | ||
772 | #ifdef GATHER_STATISTICS | |
773 | tree_node_counts[(int)lang_type] += 1; | |
774 | tree_node_sizes[(int)lang_type] += size; | |
775 | #endif | |
776 | } | |
777 | ||
778 | /* Copy TYPE, including any language-specific parts. */ | |
779 | ||
780 | tree | |
9e7d1164 | 781 | copy_type (tree type) |
11e74ea6 KL |
782 | { |
783 | tree copy; | |
784 | ||
785 | copy = copy_node (type); | |
786 | copy_lang_type (copy); | |
787 | return copy; | |
788 | } | |
789 | ||
8d08fdba | 790 | tree |
9e7d1164 | 791 | cxx_make_type (enum tree_code code) |
8d08fdba | 792 | { |
926ce8bd | 793 | tree t = make_node (code); |
8d08fdba | 794 | |
11e74ea6 KL |
795 | /* Create lang_type structure. */ |
796 | if (IS_AGGR_TYPE_CODE (code) | |
797 | || code == BOUND_TEMPLATE_TEMPLATE_PARM) | |
7ddedda4 | 798 | { |
99dd239f | 799 | struct lang_type *pi = GGC_CNEW (struct lang_type); |
8d08fdba | 800 | |
32201ce4 | 801 | TYPE_LANG_SPECIFIC (t) = pi; |
e2500fed | 802 | pi->u.c.h.is_lang_type_class = 1; |
11e74ea6 KL |
803 | |
804 | #ifdef GATHER_STATISTICS | |
805 | tree_node_counts[(int)lang_type] += 1; | |
806 | tree_node_sizes[(int)lang_type] += sizeof (struct lang_type); | |
807 | #endif | |
808 | } | |
809 | ||
810 | /* Set up some flags that give proper default behavior. */ | |
811 | if (IS_AGGR_TYPE_CODE (code)) | |
812 | { | |
c162c75e | 813 | struct c_fileinfo *finfo = get_fileinfo (lbasename (input_filename)); |
5d709b00 ZW |
814 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown); |
815 | CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only; | |
7ddedda4 | 816 | } |
8d08fdba MS |
817 | |
818 | return t; | |
819 | } | |
820 | ||
33848bb0 | 821 | tree |
9e7d1164 | 822 | make_aggr_type (enum tree_code code) |
33848bb0 | 823 | { |
f1e639b1 | 824 | tree t = cxx_make_type (code); |
33848bb0 RH |
825 | |
826 | if (IS_AGGR_TYPE_CODE (code)) | |
827 | SET_IS_AGGR_TYPE (t, 1); | |
828 | ||
829 | return t; | |
830 | } |