]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Separate lexical analyzer for GNU C++. |
5624e564 | 2 | Copyright (C) 1987-2015 Free Software Foundation, Inc. |
8d08fdba MS |
3 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
4 | ||
f5adbb8d | 5 | This file is part of GCC. |
8d08fdba | 6 | |
f5adbb8d | 7 | GCC is free software; you can redistribute it and/or modify |
8d08fdba | 8 | it under the terms of the GNU General Public License as published by |
e77f031d | 9 | the Free Software Foundation; either version 3, or (at your option) |
8d08fdba MS |
10 | any later version. |
11 | ||
f5adbb8d | 12 | GCC is distributed in the hope that it will be useful, |
8d08fdba MS |
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 | |
e77f031d NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
8d08fdba MS |
20 | |
21 | ||
22 | /* This file is the lexical analyzer for GNU C++. */ | |
23 | ||
da20811c | 24 | #include "config.h" |
8d052bc7 | 25 | #include "system.h" |
4977bab6 ZW |
26 | #include "coretypes.h" |
27 | #include "tm.h" | |
40e23961 | 28 | #include "alias.h" |
8d08fdba | 29 | #include "tree.h" |
d8a2d370 | 30 | #include "stringpool.h" |
8d08fdba | 31 | #include "cp-tree.h" |
0e5921e8 | 32 | #include "cpplib.h" |
8d08fdba | 33 | #include "flags.h" |
39dabefd | 34 | #include "c-family/c-pragma.h" |
dd2e44f0 | 35 | #include "c-family/c-objc.h" |
7bdb32b9 | 36 | #include "tm_p.h" |
2a9a326b | 37 | #include "timevar.h" |
8d08fdba | 38 | |
9e7d1164 NN |
39 | static int interface_strcmp (const char *); |
40 | static void init_cp_pragma (void); | |
0e5921e8 | 41 | |
9e7d1164 NN |
42 | static tree parse_strconst_pragma (const char *, int); |
43 | static void handle_pragma_vtable (cpp_reader *); | |
44 | static void handle_pragma_unit (cpp_reader *); | |
45 | static void handle_pragma_interface (cpp_reader *); | |
46 | static void handle_pragma_implementation (cpp_reader *); | |
47 | static void handle_pragma_java_exceptions (cpp_reader *); | |
0e5921e8 | 48 | |
9e7d1164 NN |
49 | static void init_operators (void); |
50 | static void copy_lang_type (tree); | |
8d08fdba | 51 | |
0e5921e8 | 52 | /* A constraint that can be tested at compile time. */ |
0e5921e8 | 53 | #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1] |
66a6250f | 54 | |
87e3dbc9 MM |
55 | /* Functions and data structures for #pragma interface. |
56 | ||
57 | `#pragma implementation' means that the main file being compiled | |
58 | is considered to implement (provide) the classes that appear in | |
59 | its main body. I.e., if this is file "foo.cc", and class `bar' | |
60 | is defined in "foo.cc", then we say that "foo.cc implements bar". | |
61 | ||
62 | All main input files "implement" themselves automagically. | |
63 | ||
64 | `#pragma interface' means that unless this file (of the form "foo.h" | |
65 | is not presently being included by file "foo.cc", the | |
66 | CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none | |
67 | of the vtables nor any of the inline functions defined in foo.h | |
68 | will ever be output. | |
69 | ||
70 | There are cases when we want to link files such as "defs.h" and | |
71 | "main.cc". In this case, we give "defs.h" a `#pragma interface', | |
72 | and "main.cc" has `#pragma implementation "defs.h"'. */ | |
73 | ||
74 | struct impl_files | |
75 | { | |
520a57c8 | 76 | const char *filename; |
87e3dbc9 MM |
77 | struct impl_files *next; |
78 | }; | |
79 | ||
80 | static struct impl_files *impl_file_chain; | |
81 | ||
359b8672 AH |
82 | /* True if we saw "#pragma GCC java_exceptions". */ |
83 | bool pragma_java_exceptions; | |
8d08fdba | 84 | \f |
19551f29 | 85 | void |
9e7d1164 | 86 | cxx_finish (void) |
8d08fdba | 87 | { |
22703ccc | 88 | c_common_finish (); |
8d08fdba MS |
89 | } |
90 | ||
596ea4e5 | 91 | /* A mapping from tree codes to operator name information. */ |
c0ed0531 | 92 | operator_name_info_t operator_name_info[(int) MAX_TREE_CODES]; |
596ea4e5 | 93 | /* Similar, but for assignment operators. */ |
c0ed0531 | 94 | operator_name_info_t assignment_operator_name_info[(int) MAX_TREE_CODES]; |
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; \ | |
0cbd7506 | 120 | oni->mangled_name = MANGLING; \ |
3fa3c4bd | 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 | ||
eea1139b | 166 | /* Initialize the reserved words. */ |
0e5921e8 | 167 | |
f5e99456 | 168 | void |
9e7d1164 | 169 | init_reswords (void) |
0e5921e8 ZW |
170 | { |
171 | unsigned int i; | |
172 | tree id; | |
eea1139b ILT |
173 | int mask = 0; |
174 | ||
604b2bfc | 175 | if (cxx_dialect < cxx11) |
36a85135 | 176 | mask |= D_CXX11; |
971e17ff AS |
177 | if (!flag_concepts) |
178 | mask |= D_CXX_CONCEPTS; | |
b8fd7909 JM |
179 | if (!flag_tm) |
180 | mask |= D_TRANSMEM; | |
eea1139b ILT |
181 | if (flag_no_asm) |
182 | mask |= D_ASM | D_EXT; | |
183 | if (flag_no_gnu_keywords) | |
184 | mask |= D_EXT; | |
7ce841d2 JM |
185 | |
186 | /* The Objective-C keywords are all context-dependent. */ | |
187 | mask |= D_OBJC; | |
0e5921e8 | 188 | |
766090c2 | 189 | ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX); |
eea1139b | 190 | for (i = 0; i < num_c_common_reswords; i++) |
2b2a3531 | 191 | { |
08222495 JJ |
192 | if (c_common_reswords[i].disable & D_CONLY) |
193 | continue; | |
eea1139b ILT |
194 | id = get_identifier (c_common_reswords[i].word); |
195 | C_SET_RID_CODE (id, c_common_reswords[i].rid); | |
196 | ridpointers [(int) c_common_reswords[i].rid] = id; | |
197 | if (! (c_common_reswords[i].disable & mask)) | |
0e5921e8 | 198 | C_IS_RESERVED_WORD (id) = 1; |
78a7c317 DD |
199 | } |
200 | ||
201 | for (i = 0; i < NUM_INT_N_ENTS; i++) | |
202 | { | |
203 | char name[50]; | |
204 | sprintf (name, "__int%d", int_n_data[i].bitsize); | |
205 | id = get_identifier (name); | |
206 | C_SET_RID_CODE (id, RID_FIRST_INT_N + i); | |
207 | C_IS_RESERVED_WORD (id) = 1; | |
2b2a3531 | 208 | } |
0e5921e8 | 209 | } |
2b2a3531 | 210 | |
0e5921e8 | 211 | static void |
9e7d1164 | 212 | init_cp_pragma (void) |
0e5921e8 | 213 | { |
c58b209a NB |
214 | c_register_pragma (0, "vtable", handle_pragma_vtable); |
215 | c_register_pragma (0, "unit", handle_pragma_unit); | |
216 | c_register_pragma (0, "interface", handle_pragma_interface); | |
217 | c_register_pragma (0, "implementation", handle_pragma_implementation); | |
218 | c_register_pragma ("GCC", "interface", handle_pragma_interface); | |
219 | c_register_pragma ("GCC", "implementation", handle_pragma_implementation); | |
220 | c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions); | |
0e5921e8 | 221 | } |
009ed910 | 222 | \f |
feea5b18 ILT |
223 | /* TRUE if a code represents a statement. */ |
224 | ||
225 | bool statement_code_p[MAX_TREE_CODES]; | |
226 | ||
f5e99456 NB |
227 | /* Initialize the C++ front end. This function is very sensitive to |
228 | the exact order that things are done here. It would be nice if the | |
229 | initialization done by this routine were moved to its subroutines, | |
230 | and the ordering dependencies clarified and reduced. */ | |
4bfec483 NB |
231 | bool |
232 | cxx_init (void) | |
0e5921e8 | 233 | { |
966e8f4d | 234 | location_t saved_loc; |
feea5b18 | 235 | unsigned int i; |
009ed910 | 236 | static const enum tree_code stmt_codes[] = { |
feea5b18 ILT |
237 | CTOR_INITIALIZER, TRY_BLOCK, HANDLER, |
238 | EH_SPEC_BLOCK, USING_STMT, TAG_DEFN, | |
239 | IF_STMT, CLEANUP_STMT, FOR_STMT, | |
f9132eb7 RRC |
240 | RANGE_FOR_STMT, WHILE_STMT, DO_STMT, |
241 | BREAK_STMT, CONTINUE_STMT, SWITCH_STMT, | |
242 | EXPR_STMT | |
009ed910 SB |
243 | }; |
244 | ||
feea5b18 ILT |
245 | memset (&statement_code_p, 0, sizeof (statement_code_p)); |
246 | for (i = 0; i < ARRAY_SIZE (stmt_codes); i++) | |
247 | statement_code_p[stmt_codes[i]] = true; | |
009ed910 | 248 | |
966e8f4d TT |
249 | saved_loc = input_location; |
250 | input_location = BUILTINS_LOCATION; | |
0e5921e8 ZW |
251 | |
252 | init_reswords (); | |
87e3dbc9 | 253 | init_tree (); |
54f7877c | 254 | init_cp_semantics (); |
596ea4e5 | 255 | init_operators (); |
669ec2b4 | 256 | init_method (); |
f3cdb9c6 | 257 | |
8d08fdba MS |
258 | current_function_decl = NULL; |
259 | ||
9e62871e | 260 | class_type_node = ridpointers[(int) RID_CLASS]; |
8d08fdba | 261 | |
f5e99456 NB |
262 | cxx_init_decl_processing (); |
263 | ||
4bfec483 | 264 | if (c_common_init () == false) |
267a0752 | 265 | { |
966e8f4d | 266 | input_location = saved_loc; |
267a0752 MC |
267 | return false; |
268 | } | |
f5e99456 NB |
269 | |
270 | init_cp_pragma (); | |
271 | ||
4684cd27 | 272 | init_repo (); |
f5e99456 | 273 | |
966e8f4d | 274 | input_location = saved_loc; |
4bfec483 | 275 | return true; |
8d08fdba | 276 | } |
8d08fdba | 277 | \f |
51c184be | 278 | /* Return nonzero if S is not considered part of an |
8d08fdba | 279 | INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */ |
e92cc029 | 280 | |
8d08fdba | 281 | static int |
9e7d1164 | 282 | interface_strcmp (const char* s) |
8d08fdba MS |
283 | { |
284 | /* Set the interface/implementation bits for this scope. */ | |
285 | struct impl_files *ifiles; | |
d8e178a0 | 286 | const char *s1; |
8d08fdba | 287 | |
8d08fdba MS |
288 | for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next) |
289 | { | |
d8e178a0 | 290 | const char *t1 = ifiles->filename; |
8d08fdba MS |
291 | s1 = s; |
292 | ||
ba78087b | 293 | if (*s1 == 0 || filename_ncmp (s1, t1, 1) != 0) |
8d08fdba MS |
294 | continue; |
295 | ||
ba78087b | 296 | while (*s1 != 0 && filename_ncmp (s1, t1, 1) == 0) |
8d08fdba MS |
297 | s1++, t1++; |
298 | ||
299 | /* A match. */ | |
300 | if (*s1 == *t1) | |
301 | return 0; | |
302 | ||
303 | /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */ | |
9473c522 | 304 | if (strchr (s1, '.') || strchr (t1, '.')) |
8d08fdba MS |
305 | continue; |
306 | ||
307 | if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.') | |
308 | continue; | |
309 | ||
310 | /* A match. */ | |
311 | return 0; | |
312 | } | |
313 | ||
314 | /* No matches. */ | |
315 | return 1; | |
316 | } | |
317 | ||
0e5921e8 ZW |
318 | \f |
319 | ||
320 | /* Parse a #pragma whose sole argument is a string constant. | |
321 | If OPT is true, the argument is optional. */ | |
322 | static tree | |
9e7d1164 | 323 | parse_strconst_pragma (const char* name, int opt) |
0e5921e8 ZW |
324 | { |
325 | tree result, x; | |
326 | enum cpp_ttype t; | |
327 | ||
ebf0088a | 328 | t = pragma_lex (&result); |
0e5921e8 ZW |
329 | if (t == CPP_STRING) |
330 | { | |
75ce3d48 | 331 | if (pragma_lex (&x) != CPP_EOF) |
d4ee4d25 | 332 | warning (0, "junk at end of #pragma %s", name); |
0e5921e8 ZW |
333 | return result; |
334 | } | |
335 | ||
336 | if (t == CPP_EOF && opt) | |
ebf0088a | 337 | return NULL_TREE; |
0e5921e8 ZW |
338 | |
339 | error ("invalid #pragma %s", name); | |
ebf0088a | 340 | return error_mark_node; |
0e5921e8 | 341 | } |
5362b086 | 342 | |
0e5921e8 | 343 | static void |
12308bc6 | 344 | handle_pragma_vtable (cpp_reader* /*dfile*/) |
0e5921e8 | 345 | { |
46ccf50a JM |
346 | parse_strconst_pragma ("vtable", 0); |
347 | sorry ("#pragma vtable no longer supported"); | |
0e5921e8 ZW |
348 | } |
349 | ||
1d02ac83 | 350 | static void |
12308bc6 | 351 | handle_pragma_unit (cpp_reader* /*dfile*/) |
1d02ac83 | 352 | { |
0e5921e8 ZW |
353 | /* Validate syntax, but don't do anything. */ |
354 | parse_strconst_pragma ("unit", 0); | |
355 | } | |
356 | ||
357 | static void | |
12308bc6 | 358 | handle_pragma_interface (cpp_reader* /*dfile*/) |
0e5921e8 ZW |
359 | { |
360 | tree fname = parse_strconst_pragma ("interface", 1); | |
361 | struct c_fileinfo *finfo; | |
c162c75e | 362 | const char *filename; |
0e5921e8 | 363 | |
ebf0088a | 364 | if (fname == error_mark_node) |
0e5921e8 ZW |
365 | return; |
366 | else if (fname == 0) | |
8400e75e | 367 | filename = lbasename (LOCATION_FILE (input_location)); |
0e5921e8 | 368 | else |
50c91950 | 369 | filename = TREE_STRING_POINTER (fname); |
0e5921e8 | 370 | |
8400e75e | 371 | finfo = get_fileinfo (LOCATION_FILE (input_location)); |
1d02ac83 JM |
372 | |
373 | if (impl_file_chain == 0) | |
374 | { | |
375 | /* If this is zero at this point, then we are | |
376 | auto-implementing. */ | |
377 | if (main_input_filename == 0) | |
8400e75e | 378 | main_input_filename = LOCATION_FILE (input_location); |
1d02ac83 JM |
379 | } |
380 | ||
c162c75e | 381 | finfo->interface_only = interface_strcmp (filename); |
15072eb1 ZW |
382 | /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see |
383 | a definition in another file. */ | |
5d709b00 ZW |
384 | if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only) |
385 | finfo->interface_unknown = 0; | |
1d02ac83 JM |
386 | } |
387 | ||
777ffbda JM |
388 | /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME. |
389 | We used to only allow this at toplevel, but that restriction was buggy | |
390 | in older compilers and it seems reasonable to allow it in the headers | |
391 | themselves, too. It only needs to precede the matching #p interface. | |
392 | ||
5d709b00 ZW |
393 | We don't touch finfo->interface_only or finfo->interface_unknown; |
394 | the user must specify a matching #p interface for this to have | |
395 | any effect. */ | |
777ffbda | 396 | |
1d02ac83 | 397 | static void |
12308bc6 | 398 | handle_pragma_implementation (cpp_reader* /*dfile*/) |
1d02ac83 | 399 | { |
0e5921e8 | 400 | tree fname = parse_strconst_pragma ("implementation", 1); |
c162c75e | 401 | const char *filename; |
777ffbda | 402 | struct impl_files *ifiles = impl_file_chain; |
0e5921e8 | 403 | |
ebf0088a | 404 | if (fname == error_mark_node) |
0e5921e8 ZW |
405 | return; |
406 | ||
407 | if (fname == 0) | |
408 | { | |
409 | if (main_input_filename) | |
c162c75e | 410 | filename = main_input_filename; |
0e5921e8 | 411 | else |
8400e75e | 412 | filename = LOCATION_FILE (input_location); |
c162c75e | 413 | filename = lbasename (filename); |
0e5921e8 ZW |
414 | } |
415 | else | |
416 | { | |
50c91950 | 417 | filename = TREE_STRING_POINTER (fname); |
f1e20710 | 418 | if (cpp_included_before (parse_in, filename, input_location)) |
d4ee4d25 | 419 | warning (0, "#pragma implementation for %qs appears after " |
c162c75e | 420 | "file is included", filename); |
0e5921e8 ZW |
421 | } |
422 | ||
777ffbda | 423 | for (; ifiles; ifiles = ifiles->next) |
1d02ac83 | 424 | { |
ba78087b | 425 | if (! filename_cmp (ifiles->filename, filename)) |
777ffbda | 426 | break; |
1d02ac83 | 427 | } |
777ffbda | 428 | if (ifiles == 0) |
1d02ac83 | 429 | { |
0ac1b889 | 430 | ifiles = XNEW (struct impl_files); |
50c91950 | 431 | ifiles->filename = xstrdup (filename); |
777ffbda JM |
432 | ifiles->next = impl_file_chain; |
433 | impl_file_chain = ifiles; | |
1d02ac83 | 434 | } |
1d02ac83 | 435 | } |
f181d4ae | 436 | |
1f730ff7 ZW |
437 | /* Indicate that this file uses Java-personality exception handling. */ |
438 | static void | |
12308bc6 | 439 | handle_pragma_java_exceptions (cpp_reader* /*dfile*/) |
1f730ff7 ZW |
440 | { |
441 | tree x; | |
75ce3d48 | 442 | if (pragma_lex (&x) != CPP_EOF) |
d4ee4d25 | 443 | warning (0, "junk at end of #pragma GCC java_exceptions"); |
1f730ff7 ZW |
444 | |
445 | choose_personality_routine (lang_java); | |
359b8672 | 446 | pragma_java_exceptions = true; |
1f730ff7 ZW |
447 | } |
448 | ||
15c7fb9c | 449 | /* Issue an error message indicating that the lookup of NAME (an |
b3445994 | 450 | IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */ |
15c7fb9c | 451 | |
b3445994 | 452 | tree |
15c7fb9c MM |
453 | unqualified_name_lookup_error (tree name) |
454 | { | |
455 | if (IDENTIFIER_OPNAME_P (name)) | |
456 | { | |
457 | if (name != ansi_opname (ERROR_MARK)) | |
2a13a625 | 458 | error ("%qD not defined", name); |
15c7fb9c | 459 | } |
15c7fb9c MM |
460 | else |
461 | { | |
dd2e44f0 | 462 | if (!objc_diagnose_private_ivar (name)) |
501c95ff NF |
463 | { |
464 | error ("%qD was not declared in this scope", name); | |
993acb36 | 465 | suggest_alternatives_for (location_of (name), name); |
501c95ff | 466 | } |
58ec3cc5 MM |
467 | /* Prevent repeated error messages by creating a VAR_DECL with |
468 | this NAME in the innermost block scope. */ | |
fdf03377 | 469 | if (local_bindings_p ()) |
15c7fb9c | 470 | { |
58ec3cc5 | 471 | tree decl; |
c2255bc4 AH |
472 | decl = build_decl (input_location, |
473 | VAR_DECL, name, error_mark_node); | |
58ec3cc5 MM |
474 | DECL_CONTEXT (decl) = current_function_decl; |
475 | push_local_binding (name, decl, 0); | |
996c2b52 MM |
476 | /* Mark the variable as used so that we do not get warnings |
477 | about it being unused later. */ | |
478 | TREE_USED (decl) = 1; | |
15c7fb9c | 479 | } |
15c7fb9c | 480 | } |
935d1834 | 481 | |
b3445994 | 482 | return error_mark_node; |
5566b478 MS |
483 | } |
484 | ||
b3445994 MM |
485 | /* Like unqualified_name_lookup_error, but NAME is an unqualified-id |
486 | used as a function. Returns an appropriate expression for | |
487 | NAME. */ | |
488 | ||
5566b478 | 489 | tree |
b3445994 | 490 | unqualified_fn_lookup_error (tree name) |
5566b478 | 491 | { |
5156628f | 492 | if (processing_template_decl) |
5566b478 | 493 | { |
b3445994 MM |
494 | /* In a template, it is invalid to write "f()" or "f(3)" if no |
495 | declaration of "f" is available. Historically, G++ and most | |
c5785644 WB |
496 | other compilers accepted that usage since they deferred all name |
497 | lookup until instantiation time rather than doing unqualified | |
c8094d83 | 498 | name lookup at template definition time; explain to the user what |
c5785644 WB |
499 | is going wrong. |
500 | ||
501 | Note that we have the exact wording of the following message in | |
502 | the manual (trouble.texi, node "Name lookup"), so they need to | |
503 | be kept in synch. */ | |
cbe5f3b3 | 504 | permerror (input_location, "there are no arguments to %qD that depend on a template " |
393eda6a MLI |
505 | "parameter, so a declaration of %qD must be available", |
506 | name, name); | |
c8094d83 | 507 | |
b3445994 | 508 | if (!flag_permissive) |
5566b478 | 509 | { |
b3445994 MM |
510 | static bool hint; |
511 | if (!hint) | |
512 | { | |
1f5b3869 | 513 | inform (input_location, "(if you use %<-fpermissive%>, G++ will accept your " |
597cdf4f | 514 | "code, but allowing the use of an undeclared name is " |
b3445994 MM |
515 | "deprecated)"); |
516 | hint = true; | |
517 | } | |
5566b478 | 518 | } |
10b1d5e7 | 519 | return name; |
5566b478 | 520 | } |
8d08fdba | 521 | |
b3445994 | 522 | return unqualified_name_lookup_error (name); |
8d08fdba MS |
523 | } |
524 | ||
4cc2a722 AC |
525 | /* Wrapper around build_lang_decl_loc(). Should gradually move to |
526 | build_lang_decl_loc() and then rename build_lang_decl_loc() back to | |
527 | build_lang_decl(). */ | |
528 | ||
8d08fdba | 529 | tree |
9e7d1164 | 530 | build_lang_decl (enum tree_code code, tree name, tree type) |
4cc2a722 AC |
531 | { |
532 | return build_lang_decl_loc (input_location, code, name, type); | |
533 | } | |
534 | ||
535 | /* Build a decl from CODE, NAME, TYPE declared at LOC, and then add | |
536 | DECL_LANG_SPECIFIC info to the result. */ | |
537 | ||
538 | tree | |
539 | build_lang_decl_loc (location_t loc, enum tree_code code, tree name, tree type) | |
8d08fdba | 540 | { |
4ce3d537 MM |
541 | tree t; |
542 | ||
4cc2a722 | 543 | t = build_decl (loc, code, name, type); |
fcfcdfc8 | 544 | retrofit_lang_decl (t); |
4ce3d537 | 545 | |
fcfcdfc8 JM |
546 | return t; |
547 | } | |
548 | ||
549 | /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl | |
3b426391 | 550 | and pushdecl (for functions generated by the back end). */ |
fcfcdfc8 JM |
551 | |
552 | void | |
9e7d1164 | 553 | retrofit_lang_decl (tree t) |
fcfcdfc8 | 554 | { |
9188c363 | 555 | struct lang_decl *ld; |
4ce3d537 | 556 | size_t size; |
b97e8a14 JM |
557 | int sel; |
558 | ||
3048c0c7 JM |
559 | if (DECL_LANG_SPECIFIC (t)) |
560 | return; | |
561 | ||
b97e8a14 JM |
562 | if (TREE_CODE (t) == FUNCTION_DECL) |
563 | sel = 1, size = sizeof (struct lang_decl_fn); | |
564 | else if (TREE_CODE (t) == NAMESPACE_DECL) | |
565 | sel = 2, size = sizeof (struct lang_decl_ns); | |
ad909c97 JM |
566 | else if (TREE_CODE (t) == PARM_DECL) |
567 | sel = 3, size = sizeof (struct lang_decl_parm); | |
b97e8a14 JM |
568 | else if (LANG_DECL_HAS_MIN (t)) |
569 | sel = 0, size = sizeof (struct lang_decl_min); | |
4ce3d537 | 570 | else |
b97e8a14 | 571 | gcc_unreachable (); |
b0d06515 | 572 | |
766090c2 | 573 | ld = (struct lang_decl *) ggc_internal_cleared_alloc (size); |
8d08fdba | 574 | |
b97e8a14 | 575 | ld->u.base.selector = sel; |
e2500fed | 576 | |
9188c363 | 577 | DECL_LANG_SPECIFIC (t) = ld; |
ab73670a MM |
578 | if (current_lang_name == lang_name_cplusplus |
579 | || decl_linkage (t) == lk_none) | |
5d2ed28c | 580 | SET_DECL_LANGUAGE (t, lang_cplusplus); |
8d08fdba | 581 | else if (current_lang_name == lang_name_c) |
5d2ed28c | 582 | SET_DECL_LANGUAGE (t, lang_c); |
a1774733 | 583 | else if (current_lang_name == lang_name_java) |
5d2ed28c | 584 | SET_DECL_LANGUAGE (t, lang_java); |
8dc2b103 NS |
585 | else |
586 | gcc_unreachable (); | |
8d08fdba | 587 | |
7aa6d18a SB |
588 | if (GATHER_STATISTICS) |
589 | { | |
590 | tree_node_counts[(int)lang_decl] += 1; | |
591 | tree_node_sizes[(int)lang_decl] += size; | |
592 | } | |
8d08fdba MS |
593 | } |
594 | ||
8d08fdba | 595 | void |
9e7d1164 | 596 | cxx_dup_lang_specific_decl (tree node) |
8d08fdba MS |
597 | { |
598 | int size; | |
d60f72ae | 599 | struct lang_decl *ld; |
8d08fdba | 600 | |
5566b478 MS |
601 | if (! DECL_LANG_SPECIFIC (node)) |
602 | return; | |
603 | ||
b97e8a14 JM |
604 | if (TREE_CODE (node) == FUNCTION_DECL) |
605 | size = sizeof (struct lang_decl_fn); | |
606 | else if (TREE_CODE (node) == NAMESPACE_DECL) | |
607 | size = sizeof (struct lang_decl_ns); | |
ad909c97 JM |
608 | else if (TREE_CODE (node) == PARM_DECL) |
609 | size = sizeof (struct lang_decl_parm); | |
b97e8a14 JM |
610 | else if (LANG_DECL_HAS_MIN (node)) |
611 | size = sizeof (struct lang_decl_min); | |
8d08fdba | 612 | else |
b97e8a14 JM |
613 | gcc_unreachable (); |
614 | ||
766090c2 | 615 | ld = (struct lang_decl *) ggc_internal_alloc (size); |
4e135bdd | 616 | memcpy (ld, DECL_LANG_SPECIFIC (node), size); |
d60f72ae | 617 | DECL_LANG_SPECIFIC (node) = ld; |
11e74ea6 | 618 | |
7aa6d18a SB |
619 | if (GATHER_STATISTICS) |
620 | { | |
621 | tree_node_counts[(int)lang_decl] += 1; | |
622 | tree_node_sizes[(int)lang_decl] += size; | |
623 | } | |
8d08fdba MS |
624 | } |
625 | ||
0acf7199 MM |
626 | /* Copy DECL, including any language-specific parts. */ |
627 | ||
628 | tree | |
9e7d1164 | 629 | copy_decl (tree decl) |
0acf7199 MM |
630 | { |
631 | tree copy; | |
632 | ||
633 | copy = copy_node (decl); | |
63e1b1c4 | 634 | cxx_dup_lang_specific_decl (copy); |
0acf7199 MM |
635 | return copy; |
636 | } | |
637 | ||
11e74ea6 KL |
638 | /* Replace the shared language-specific parts of NODE with a new copy. */ |
639 | ||
76648a8b | 640 | static void |
9e7d1164 | 641 | copy_lang_type (tree node) |
11e74ea6 KL |
642 | { |
643 | int size; | |
644 | struct lang_type *lt; | |
645 | ||
646 | if (! TYPE_LANG_SPECIFIC (node)) | |
647 | return; | |
648 | ||
e2500fed GK |
649 | if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class) |
650 | size = sizeof (struct lang_type); | |
651 | else | |
652 | size = sizeof (struct lang_type_ptrmem); | |
766090c2 | 653 | lt = (struct lang_type *) ggc_internal_alloc (size); |
11e74ea6 KL |
654 | memcpy (lt, TYPE_LANG_SPECIFIC (node), size); |
655 | TYPE_LANG_SPECIFIC (node) = lt; | |
656 | ||
7aa6d18a SB |
657 | if (GATHER_STATISTICS) |
658 | { | |
659 | tree_node_counts[(int)lang_type] += 1; | |
660 | tree_node_sizes[(int)lang_type] += size; | |
661 | } | |
11e74ea6 KL |
662 | } |
663 | ||
664 | /* Copy TYPE, including any language-specific parts. */ | |
665 | ||
666 | tree | |
9e7d1164 | 667 | copy_type (tree type) |
11e74ea6 KL |
668 | { |
669 | tree copy; | |
670 | ||
671 | copy = copy_node (type); | |
672 | copy_lang_type (copy); | |
673 | return copy; | |
674 | } | |
675 | ||
8d08fdba | 676 | tree |
9e7d1164 | 677 | cxx_make_type (enum tree_code code) |
8d08fdba | 678 | { |
926ce8bd | 679 | tree t = make_node (code); |
8d08fdba | 680 | |
11e74ea6 | 681 | /* Create lang_type structure. */ |
9e1e64ec | 682 | if (RECORD_OR_UNION_CODE_P (code) |
11e74ea6 | 683 | || code == BOUND_TEMPLATE_TEMPLATE_PARM) |
7ddedda4 | 684 | { |
a9429e29 | 685 | struct lang_type *pi |
766090c2 TS |
686 | = (struct lang_type *) ggc_internal_cleared_alloc |
687 | (sizeof (struct lang_type)); | |
8d08fdba | 688 | |
32201ce4 | 689 | TYPE_LANG_SPECIFIC (t) = pi; |
e2500fed | 690 | pi->u.c.h.is_lang_type_class = 1; |
11e74ea6 | 691 | |
7aa6d18a SB |
692 | if (GATHER_STATISTICS) |
693 | { | |
694 | tree_node_counts[(int)lang_type] += 1; | |
695 | tree_node_sizes[(int)lang_type] += sizeof (struct lang_type); | |
696 | } | |
11e74ea6 KL |
697 | } |
698 | ||
699 | /* Set up some flags that give proper default behavior. */ | |
9e1e64ec | 700 | if (RECORD_OR_UNION_CODE_P (code)) |
11e74ea6 | 701 | { |
8400e75e DM |
702 | struct c_fileinfo *finfo = \ |
703 | get_fileinfo (LOCATION_FILE (input_location)); | |
5d709b00 ZW |
704 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown); |
705 | CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only; | |
7ddedda4 | 706 | } |
8d08fdba MS |
707 | |
708 | return t; | |
709 | } | |
710 | ||
33848bb0 | 711 | tree |
9e1e64ec | 712 | make_class_type (enum tree_code code) |
33848bb0 | 713 | { |
f1e639b1 | 714 | tree t = cxx_make_type (code); |
9e1e64ec | 715 | SET_CLASS_TYPE_P (t, 1); |
33848bb0 RH |
716 | return t; |
717 | } | |
61172206 JM |
718 | |
719 | /* Returns true if we are currently in the main source file, or in a | |
720 | template instantiation started from the main source file. */ | |
721 | ||
722 | bool | |
723 | in_main_input_context (void) | |
724 | { | |
e2c3721c | 725 | struct tinst_level *tl = outermost_tinst_level(); |
61172206 JM |
726 | |
727 | if (tl) | |
ba78087b KT |
728 | return filename_cmp (main_input_filename, |
729 | LOCATION_FILE (tl->locus)) == 0; | |
61172206 | 730 | else |
8400e75e | 731 | return filename_cmp (main_input_filename, LOCATION_FILE (input_location)) == 0; |
61172206 | 732 | } |