]>
Commit | Line | Data |
---|---|---|
471086d6 | 1 | /* Separate lexical analyzer for GNU C++. |
107c7f39 | 2 | Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
d91f7526 | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2010 |
aa139c3f | 4 | Free Software Foundation, Inc. |
471086d6 | 5 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
6 | ||
6f0d25a6 | 7 | This file is part of GCC. |
471086d6 | 8 | |
6f0d25a6 | 9 | GCC is free software; you can redistribute it and/or modify |
471086d6 | 10 | it under the terms of the GNU General Public License as published by |
aa139c3f | 11 | the Free Software Foundation; either version 3, or (at your option) |
471086d6 | 12 | any later version. |
13 | ||
6f0d25a6 | 14 | GCC is distributed in the hope that it will be useful, |
471086d6 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
aa139c3f | 20 | along with GCC; see the file COPYING3. If not see |
21 | <http://www.gnu.org/licenses/>. */ | |
471086d6 | 22 | |
23 | ||
24 | /* This file is the lexical analyzer for GNU C++. */ | |
25 | ||
39c8ac16 | 26 | #include "config.h" |
b3ef7553 | 27 | #include "system.h" |
805e22b2 | 28 | #include "coretypes.h" |
29 | #include "tm.h" | |
471086d6 | 30 | #include "input.h" |
31 | #include "tree.h" | |
471086d6 | 32 | #include "cp-tree.h" |
518796ad | 33 | #include "cpplib.h" |
471086d6 | 34 | #include "flags.h" |
7bedc3a0 | 35 | #include "c-family/c-pragma.h" |
79408174 | 36 | #include "c-family/c-objc.h" |
0ba25c9a | 37 | #include "output.h" |
d8c9779c | 38 | #include "tm_p.h" |
74d2af64 | 39 | #include "timevar.h" |
471086d6 | 40 | |
42c35e28 | 41 | static int interface_strcmp (const char *); |
42 | static void init_cp_pragma (void); | |
518796ad | 43 | |
42c35e28 | 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 *); | |
518796ad | 50 | |
42c35e28 | 51 | static void init_operators (void); |
52 | static void copy_lang_type (tree); | |
471086d6 | 53 | |
518796ad | 54 | /* A constraint that can be tested at compile time. */ |
518796ad | 55 | #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1] |
46e5e818 | 56 | |
23f83a9a | 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 | { | |
44acf429 | 78 | const char *filename; |
23f83a9a | 79 | struct impl_files *next; |
80 | }; | |
81 | ||
82 | static struct impl_files *impl_file_chain; | |
83 | ||
bde8fea7 | 84 | /* True if we saw "#pragma GCC java_exceptions". */ |
85 | bool pragma_java_exceptions; | |
471086d6 | 86 | \f |
ca58dfe1 | 87 | void |
42c35e28 | 88 | cxx_finish (void) |
471086d6 | 89 | { |
cdc9fa3e | 90 | c_common_finish (); |
471086d6 | 91 | } |
92 | ||
97cc4539 | 93 | /* A mapping from tree codes to operator name information. */ |
e014fc6a | 94 | operator_name_info_t operator_name_info[(int) MAX_TREE_CODES]; |
97cc4539 | 95 | /* Similar, but for assignment operators. */ |
e014fc6a | 96 | operator_name_info_t assignment_operator_name_info[(int) MAX_TREE_CODES]; |
3c3beda6 | 97 | |
97cc4539 | 98 | /* Initialize data structures that keep track of operator names. */ |
99 | ||
c5144efa | 100 | #define DEF_OPERATOR(NAME, C, M, AR, AP) \ |
518796ad | 101 | CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256); |
102 | #include "operators.def" | |
103 | #undef DEF_OPERATOR | |
104 | ||
97cc4539 | 105 | static void |
42c35e28 | 106 | init_operators (void) |
97cc4539 | 107 | { |
108 | tree identifier; | |
109 | char buffer[256]; | |
110 | struct operator_name_info_t *oni; | |
3c3beda6 | 111 | |
c5144efa | 112 | #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \ |
0169d787 | 113 | sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \ |
97cc4539 | 114 | identifier = get_identifier (buffer); \ |
115 | IDENTIFIER_OPNAME_P (identifier) = 1; \ | |
116 | \ | |
117 | oni = (ASSN_P \ | |
118 | ? &assignment_operator_name_info[(int) CODE] \ | |
119 | : &operator_name_info[(int) CODE]); \ | |
120 | oni->identifier = identifier; \ | |
121 | oni->name = NAME; \ | |
653e5405 | 122 | oni->mangled_name = MANGLING; \ |
94302392 | 123 | oni->arity = ARITY; |
97cc4539 | 124 | |
125 | #include "operators.def" | |
126 | #undef DEF_OPERATOR | |
127 | ||
3c3beda6 | 128 | operator_name_info[(int) ERROR_MARK].identifier |
97cc4539 | 129 | = get_identifier ("<invalid operator>"); |
130 | ||
131 | /* Handle some special cases. These operators are not defined in | |
132 | the language, but can be produced internally. We may need them | |
133 | for error-reporting. (Eventually, we should ensure that this | |
134 | does not happen. Error messages involving these operators will | |
135 | be confusing to users.) */ | |
3c3beda6 | 136 | |
137 | operator_name_info [(int) INIT_EXPR].name | |
97cc4539 | 138 | = operator_name_info [(int) MODIFY_EXPR].name; |
139 | operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)"; | |
140 | operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)"; | |
141 | operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)"; | |
142 | operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)"; | |
143 | operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)"; | |
144 | operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)"; | |
145 | operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)"; | |
146 | operator_name_info [(int) ABS_EXPR].name = "abs"; | |
97cc4539 | 147 | operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&"; |
148 | operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||"; | |
97cc4539 | 149 | operator_name_info [(int) RANGE_EXPR].name = "..."; |
97d541d5 | 150 | operator_name_info [(int) UNARY_PLUS_EXPR].name = "+"; |
97cc4539 | 151 | |
3c3beda6 | 152 | assignment_operator_name_info [(int) EXACT_DIV_EXPR].name |
97cc4539 | 153 | = "(exact /=)"; |
3c3beda6 | 154 | assignment_operator_name_info [(int) CEIL_DIV_EXPR].name |
97cc4539 | 155 | = "(ceiling /=)"; |
3c3beda6 | 156 | assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name |
97cc4539 | 157 | = "(floor /=)"; |
3c3beda6 | 158 | assignment_operator_name_info [(int) ROUND_DIV_EXPR].name |
97cc4539 | 159 | = "(round /=)"; |
3c3beda6 | 160 | assignment_operator_name_info [(int) CEIL_MOD_EXPR].name |
97cc4539 | 161 | = "(ceiling %=)"; |
3c3beda6 | 162 | assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name |
97cc4539 | 163 | = "(floor %=)"; |
3c3beda6 | 164 | assignment_operator_name_info [(int) ROUND_MOD_EXPR].name |
97cc4539 | 165 | = "(round %=)"; |
166 | } | |
167 | ||
5c6e5756 | 168 | /* Initialize the reserved words. */ |
518796ad | 169 | |
9ceb1c29 | 170 | void |
42c35e28 | 171 | init_reswords (void) |
518796ad | 172 | { |
173 | unsigned int i; | |
174 | tree id; | |
5c6e5756 | 175 | int mask = 0; |
176 | ||
5c6e5756 | 177 | if (cxx_dialect != cxx0x) |
178 | mask |= D_CXX0X; | |
179 | if (flag_no_asm) | |
180 | mask |= D_ASM | D_EXT; | |
181 | if (flag_no_gnu_keywords) | |
182 | mask |= D_EXT; | |
b4d6f57b | 183 | |
184 | /* The Objective-C keywords are all context-dependent. */ | |
185 | mask |= D_OBJC; | |
518796ad | 186 | |
ba72912a | 187 | ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX); |
5c6e5756 | 188 | for (i = 0; i < num_c_common_reswords; i++) |
17fd67d5 | 189 | { |
69201cc5 | 190 | if (c_common_reswords[i].disable & D_CONLY) |
191 | continue; | |
5c6e5756 | 192 | id = get_identifier (c_common_reswords[i].word); |
193 | C_SET_RID_CODE (id, c_common_reswords[i].rid); | |
194 | ridpointers [(int) c_common_reswords[i].rid] = id; | |
195 | if (! (c_common_reswords[i].disable & mask)) | |
518796ad | 196 | C_IS_RESERVED_WORD (id) = 1; |
17fd67d5 | 197 | } |
518796ad | 198 | } |
17fd67d5 | 199 | |
518796ad | 200 | static void |
42c35e28 | 201 | init_cp_pragma (void) |
518796ad | 202 | { |
eb180587 | 203 | c_register_pragma (0, "vtable", handle_pragma_vtable); |
204 | c_register_pragma (0, "unit", handle_pragma_unit); | |
205 | c_register_pragma (0, "interface", handle_pragma_interface); | |
206 | c_register_pragma (0, "implementation", handle_pragma_implementation); | |
207 | c_register_pragma ("GCC", "interface", handle_pragma_interface); | |
208 | c_register_pragma ("GCC", "implementation", handle_pragma_implementation); | |
209 | c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions); | |
518796ad | 210 | } |
bac62436 | 211 | \f |
820440d6 | 212 | /* TRUE if a code represents a statement. */ |
213 | ||
214 | bool statement_code_p[MAX_TREE_CODES]; | |
215 | ||
9ceb1c29 | 216 | /* Initialize the C++ front end. This function is very sensitive to |
217 | the exact order that things are done here. It would be nice if the | |
218 | initialization done by this routine were moved to its subroutines, | |
219 | and the ordering dependencies clarified and reduced. */ | |
03bde601 | 220 | bool |
221 | cxx_init (void) | |
518796ad | 222 | { |
26cb3d1c | 223 | location_t saved_loc; |
820440d6 | 224 | unsigned int i; |
bac62436 | 225 | static const enum tree_code stmt_codes[] = { |
820440d6 | 226 | CTOR_INITIALIZER, TRY_BLOCK, HANDLER, |
227 | EH_SPEC_BLOCK, USING_STMT, TAG_DEFN, | |
228 | IF_STMT, CLEANUP_STMT, FOR_STMT, | |
9dd72ec4 | 229 | RANGE_FOR_STMT, WHILE_STMT, DO_STMT, |
230 | BREAK_STMT, CONTINUE_STMT, SWITCH_STMT, | |
231 | EXPR_STMT | |
bac62436 | 232 | }; |
233 | ||
820440d6 | 234 | memset (&statement_code_p, 0, sizeof (statement_code_p)); |
235 | for (i = 0; i < ARRAY_SIZE (stmt_codes); i++) | |
236 | statement_code_p[stmt_codes[i]] = true; | |
bac62436 | 237 | |
26cb3d1c | 238 | saved_loc = input_location; |
239 | input_location = BUILTINS_LOCATION; | |
518796ad | 240 | |
241 | init_reswords (); | |
23f83a9a | 242 | init_tree (); |
41fb2c18 | 243 | init_cp_semantics (); |
97cc4539 | 244 | init_operators (); |
442fd60a | 245 | init_method (); |
471086d6 | 246 | init_error (); |
cfa70726 | 247 | |
471086d6 | 248 | current_function_decl = NULL; |
249 | ||
38253b86 | 250 | class_type_node = ridpointers[(int) RID_CLASS]; |
471086d6 | 251 | |
9ceb1c29 | 252 | cxx_init_decl_processing (); |
253 | ||
03bde601 | 254 | if (c_common_init () == false) |
0c6109e0 | 255 | { |
26cb3d1c | 256 | input_location = saved_loc; |
0c6109e0 | 257 | return false; |
258 | } | |
9ceb1c29 | 259 | |
260 | init_cp_pragma (); | |
261 | ||
caa6fdce | 262 | init_repo (); |
9ceb1c29 | 263 | |
26cb3d1c | 264 | input_location = saved_loc; |
03bde601 | 265 | return true; |
471086d6 | 266 | } |
471086d6 | 267 | \f |
ac9386a0 | 268 | /* Return nonzero if S is not considered part of an |
471086d6 | 269 | INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */ |
96624a9e | 270 | |
471086d6 | 271 | static int |
42c35e28 | 272 | interface_strcmp (const char* s) |
471086d6 | 273 | { |
274 | /* Set the interface/implementation bits for this scope. */ | |
275 | struct impl_files *ifiles; | |
e1721763 | 276 | const char *s1; |
471086d6 | 277 | |
471086d6 | 278 | for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next) |
279 | { | |
e1721763 | 280 | const char *t1 = ifiles->filename; |
471086d6 | 281 | s1 = s; |
282 | ||
82715bcd | 283 | if (*s1 == 0 || filename_ncmp (s1, t1, 1) != 0) |
471086d6 | 284 | continue; |
285 | ||
82715bcd | 286 | while (*s1 != 0 && filename_ncmp (s1, t1, 1) == 0) |
471086d6 | 287 | s1++, t1++; |
288 | ||
289 | /* A match. */ | |
290 | if (*s1 == *t1) | |
291 | return 0; | |
292 | ||
293 | /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */ | |
78dbff7c | 294 | if (strchr (s1, '.') || strchr (t1, '.')) |
471086d6 | 295 | continue; |
296 | ||
297 | if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.') | |
298 | continue; | |
299 | ||
300 | /* A match. */ | |
301 | return 0; | |
302 | } | |
303 | ||
304 | /* No matches. */ | |
305 | return 1; | |
306 | } | |
307 | ||
518796ad | 308 | \f |
309 | ||
310 | /* Parse a #pragma whose sole argument is a string constant. | |
311 | If OPT is true, the argument is optional. */ | |
312 | static tree | |
42c35e28 | 313 | parse_strconst_pragma (const char* name, int opt) |
518796ad | 314 | { |
315 | tree result, x; | |
316 | enum cpp_ttype t; | |
317 | ||
b0b1c358 | 318 | t = pragma_lex (&result); |
518796ad | 319 | if (t == CPP_STRING) |
320 | { | |
b5d533bb | 321 | if (pragma_lex (&x) != CPP_EOF) |
c3ceba8e | 322 | warning (0, "junk at end of #pragma %s", name); |
518796ad | 323 | return result; |
324 | } | |
325 | ||
326 | if (t == CPP_EOF && opt) | |
b0b1c358 | 327 | return NULL_TREE; |
518796ad | 328 | |
329 | error ("invalid #pragma %s", name); | |
b0b1c358 | 330 | return error_mark_node; |
518796ad | 331 | } |
3c3beda6 | 332 | |
518796ad | 333 | static void |
42c35e28 | 334 | handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
518796ad | 335 | { |
b53db2b0 | 336 | parse_strconst_pragma ("vtable", 0); |
337 | sorry ("#pragma vtable no longer supported"); | |
518796ad | 338 | } |
339 | ||
495d2af2 | 340 | static void |
42c35e28 | 341 | handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
495d2af2 | 342 | { |
518796ad | 343 | /* Validate syntax, but don't do anything. */ |
344 | parse_strconst_pragma ("unit", 0); | |
345 | } | |
346 | ||
347 | static void | |
42c35e28 | 348 | handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
518796ad | 349 | { |
350 | tree fname = parse_strconst_pragma ("interface", 1); | |
351 | struct c_fileinfo *finfo; | |
00d26680 | 352 | const char *filename; |
518796ad | 353 | |
b0b1c358 | 354 | if (fname == error_mark_node) |
518796ad | 355 | return; |
356 | else if (fname == 0) | |
00d26680 | 357 | filename = lbasename (input_filename); |
518796ad | 358 | else |
b25f004c | 359 | filename = TREE_STRING_POINTER (fname); |
518796ad | 360 | |
4507a637 | 361 | finfo = get_fileinfo (input_filename); |
495d2af2 | 362 | |
363 | if (impl_file_chain == 0) | |
364 | { | |
365 | /* If this is zero at this point, then we are | |
366 | auto-implementing. */ | |
367 | if (main_input_filename == 0) | |
368 | main_input_filename = input_filename; | |
495d2af2 | 369 | } |
370 | ||
00d26680 | 371 | finfo->interface_only = interface_strcmp (filename); |
197e583a | 372 | /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see |
373 | a definition in another file. */ | |
62bf98ad | 374 | if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only) |
375 | finfo->interface_unknown = 0; | |
495d2af2 | 376 | } |
377 | ||
e060fd61 | 378 | /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME. |
379 | We used to only allow this at toplevel, but that restriction was buggy | |
380 | in older compilers and it seems reasonable to allow it in the headers | |
381 | themselves, too. It only needs to precede the matching #p interface. | |
382 | ||
62bf98ad | 383 | We don't touch finfo->interface_only or finfo->interface_unknown; |
384 | the user must specify a matching #p interface for this to have | |
385 | any effect. */ | |
e060fd61 | 386 | |
495d2af2 | 387 | static void |
42c35e28 | 388 | handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED ) |
495d2af2 | 389 | { |
518796ad | 390 | tree fname = parse_strconst_pragma ("implementation", 1); |
00d26680 | 391 | const char *filename; |
e060fd61 | 392 | struct impl_files *ifiles = impl_file_chain; |
518796ad | 393 | |
b0b1c358 | 394 | if (fname == error_mark_node) |
518796ad | 395 | return; |
396 | ||
397 | if (fname == 0) | |
398 | { | |
399 | if (main_input_filename) | |
00d26680 | 400 | filename = main_input_filename; |
518796ad | 401 | else |
00d26680 | 402 | filename = input_filename; |
403 | filename = lbasename (filename); | |
518796ad | 404 | } |
405 | else | |
406 | { | |
b25f004c | 407 | filename = TREE_STRING_POINTER (fname); |
67015c73 | 408 | if (cpp_included_before (parse_in, filename, input_location)) |
c3ceba8e | 409 | warning (0, "#pragma implementation for %qs appears after " |
00d26680 | 410 | "file is included", filename); |
518796ad | 411 | } |
412 | ||
e060fd61 | 413 | for (; ifiles; ifiles = ifiles->next) |
495d2af2 | 414 | { |
82715bcd | 415 | if (! filename_cmp (ifiles->filename, filename)) |
e060fd61 | 416 | break; |
495d2af2 | 417 | } |
e060fd61 | 418 | if (ifiles == 0) |
495d2af2 | 419 | { |
56e60747 | 420 | ifiles = XNEW (struct impl_files); |
b25f004c | 421 | ifiles->filename = xstrdup (filename); |
e060fd61 | 422 | ifiles->next = impl_file_chain; |
423 | impl_file_chain = ifiles; | |
495d2af2 | 424 | } |
495d2af2 | 425 | } |
53137e6a | 426 | |
6df8a9dd | 427 | /* Indicate that this file uses Java-personality exception handling. */ |
428 | static void | |
b75b98aa | 429 | handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED) |
6df8a9dd | 430 | { |
431 | tree x; | |
b5d533bb | 432 | if (pragma_lex (&x) != CPP_EOF) |
c3ceba8e | 433 | warning (0, "junk at end of #pragma GCC java_exceptions"); |
6df8a9dd | 434 | |
435 | choose_personality_routine (lang_java); | |
bde8fea7 | 436 | pragma_java_exceptions = true; |
6df8a9dd | 437 | } |
438 | ||
7d172fa8 | 439 | /* Issue an error message indicating that the lookup of NAME (an |
0886adbc | 440 | IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */ |
7d172fa8 | 441 | |
0886adbc | 442 | tree |
7d172fa8 | 443 | unqualified_name_lookup_error (tree name) |
444 | { | |
445 | if (IDENTIFIER_OPNAME_P (name)) | |
446 | { | |
447 | if (name != ansi_opname (ERROR_MARK)) | |
a2c5b975 | 448 | error ("%qD not defined", name); |
7d172fa8 | 449 | } |
7d172fa8 | 450 | else |
451 | { | |
79408174 | 452 | if (!objc_diagnose_private_ivar (name)) |
f91726b4 | 453 | { |
454 | error ("%qD was not declared in this scope", name); | |
d3c44c27 | 455 | suggest_alternatives_for (location_of (name), name); |
f91726b4 | 456 | } |
28bbd27a | 457 | /* Prevent repeated error messages by creating a VAR_DECL with |
458 | this NAME in the innermost block scope. */ | |
459 | if (current_function_decl) | |
7d172fa8 | 460 | { |
28bbd27a | 461 | tree decl; |
e60a6f7b | 462 | decl = build_decl (input_location, |
463 | VAR_DECL, name, error_mark_node); | |
28bbd27a | 464 | DECL_CONTEXT (decl) = current_function_decl; |
465 | push_local_binding (name, decl, 0); | |
d1a64350 | 466 | /* Mark the variable as used so that we do not get warnings |
467 | about it being unused later. */ | |
468 | TREE_USED (decl) = 1; | |
7d172fa8 | 469 | } |
7d172fa8 | 470 | } |
c324ed63 | 471 | |
0886adbc | 472 | return error_mark_node; |
e857e9c7 | 473 | } |
474 | ||
0886adbc | 475 | /* Like unqualified_name_lookup_error, but NAME is an unqualified-id |
476 | used as a function. Returns an appropriate expression for | |
477 | NAME. */ | |
478 | ||
e857e9c7 | 479 | tree |
0886adbc | 480 | unqualified_fn_lookup_error (tree name) |
e857e9c7 | 481 | { |
3cc0b4b9 | 482 | if (processing_template_decl) |
e857e9c7 | 483 | { |
0886adbc | 484 | /* In a template, it is invalid to write "f()" or "f(3)" if no |
485 | declaration of "f" is available. Historically, G++ and most | |
8ddbdfab | 486 | other compilers accepted that usage since they deferred all name |
487 | lookup until instantiation time rather than doing unqualified | |
9031d10b | 488 | name lookup at template definition time; explain to the user what |
8ddbdfab | 489 | is going wrong. |
490 | ||
491 | Note that we have the exact wording of the following message in | |
492 | the manual (trouble.texi, node "Name lookup"), so they need to | |
493 | be kept in synch. */ | |
2b9e3597 | 494 | permerror (input_location, "there are no arguments to %qD that depend on a template " |
07317e69 | 495 | "parameter, so a declaration of %qD must be available", |
496 | name, name); | |
9031d10b | 497 | |
0886adbc | 498 | if (!flag_permissive) |
e857e9c7 | 499 | { |
0886adbc | 500 | static bool hint; |
501 | if (!hint) | |
502 | { | |
5bcc316e | 503 | inform (input_location, "(if you use %<-fpermissive%>, G++ will accept your " |
7668b48e | 504 | "code, but allowing the use of an undeclared name is " |
0886adbc | 505 | "deprecated)"); |
506 | hint = true; | |
507 | } | |
e857e9c7 | 508 | } |
c08d51be | 509 | return name; |
e857e9c7 | 510 | } |
471086d6 | 511 | |
0886adbc | 512 | return unqualified_name_lookup_error (name); |
471086d6 | 513 | } |
514 | ||
cbdababb | 515 | /* Wrapper around build_lang_decl_loc(). Should gradually move to |
516 | build_lang_decl_loc() and then rename build_lang_decl_loc() back to | |
517 | build_lang_decl(). */ | |
518 | ||
471086d6 | 519 | tree |
42c35e28 | 520 | build_lang_decl (enum tree_code code, tree name, tree type) |
cbdababb | 521 | { |
522 | return build_lang_decl_loc (input_location, code, name, type); | |
523 | } | |
524 | ||
525 | /* Build a decl from CODE, NAME, TYPE declared at LOC, and then add | |
526 | DECL_LANG_SPECIFIC info to the result. */ | |
527 | ||
528 | tree | |
529 | build_lang_decl_loc (location_t loc, enum tree_code code, tree name, tree type) | |
471086d6 | 530 | { |
c4802aa6 | 531 | tree t; |
532 | ||
cbdababb | 533 | t = build_decl (loc, code, name, type); |
4ba5f733 | 534 | retrofit_lang_decl (t); |
c4802aa6 | 535 | |
4ba5f733 | 536 | return t; |
537 | } | |
538 | ||
539 | /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl | |
a17c2a3a | 540 | and pushdecl (for functions generated by the back end). */ |
4ba5f733 | 541 | |
542 | void | |
42c35e28 | 543 | retrofit_lang_decl (tree t) |
4ba5f733 | 544 | { |
70a658bd | 545 | struct lang_decl *ld; |
c4802aa6 | 546 | size_t size; |
39e70cbf | 547 | int sel; |
548 | ||
549 | if (TREE_CODE (t) == FUNCTION_DECL) | |
550 | sel = 1, size = sizeof (struct lang_decl_fn); | |
551 | else if (TREE_CODE (t) == NAMESPACE_DECL) | |
552 | sel = 2, size = sizeof (struct lang_decl_ns); | |
32d008d9 | 553 | else if (TREE_CODE (t) == PARM_DECL) |
554 | sel = 3, size = sizeof (struct lang_decl_parm); | |
39e70cbf | 555 | else if (LANG_DECL_HAS_MIN (t)) |
556 | sel = 0, size = sizeof (struct lang_decl_min); | |
c4802aa6 | 557 | else |
39e70cbf | 558 | gcc_unreachable (); |
c6138f2d | 559 | |
ba72912a | 560 | ld = ggc_alloc_cleared_lang_decl (size); |
471086d6 | 561 | |
39e70cbf | 562 | ld->u.base.selector = sel; |
1f3233d1 | 563 | |
70a658bd | 564 | DECL_LANG_SPECIFIC (t) = ld; |
a8f49272 | 565 | if (current_lang_name == lang_name_cplusplus |
566 | || decl_linkage (t) == lk_none) | |
4b1984f5 | 567 | SET_DECL_LANGUAGE (t, lang_cplusplus); |
471086d6 | 568 | else if (current_lang_name == lang_name_c) |
4b1984f5 | 569 | SET_DECL_LANGUAGE (t, lang_c); |
f468434d | 570 | else if (current_lang_name == lang_name_java) |
4b1984f5 | 571 | SET_DECL_LANGUAGE (t, lang_java); |
092b1d6f | 572 | else |
573 | gcc_unreachable (); | |
471086d6 | 574 | |
471086d6 | 575 | #ifdef GATHER_STATISTICS |
576 | tree_node_counts[(int)lang_decl] += 1; | |
c4802aa6 | 577 | tree_node_sizes[(int)lang_decl] += size; |
471086d6 | 578 | #endif |
471086d6 | 579 | } |
580 | ||
471086d6 | 581 | void |
42c35e28 | 582 | cxx_dup_lang_specific_decl (tree node) |
471086d6 | 583 | { |
584 | int size; | |
a1b0969c | 585 | struct lang_decl *ld; |
471086d6 | 586 | |
e857e9c7 | 587 | if (! DECL_LANG_SPECIFIC (node)) |
588 | return; | |
589 | ||
39e70cbf | 590 | if (TREE_CODE (node) == FUNCTION_DECL) |
591 | size = sizeof (struct lang_decl_fn); | |
592 | else if (TREE_CODE (node) == NAMESPACE_DECL) | |
593 | size = sizeof (struct lang_decl_ns); | |
32d008d9 | 594 | else if (TREE_CODE (node) == PARM_DECL) |
595 | size = sizeof (struct lang_decl_parm); | |
39e70cbf | 596 | else if (LANG_DECL_HAS_MIN (node)) |
597 | size = sizeof (struct lang_decl_min); | |
471086d6 | 598 | else |
39e70cbf | 599 | gcc_unreachable (); |
600 | ||
ba72912a | 601 | ld = ggc_alloc_lang_decl (size); |
b1b63592 | 602 | memcpy (ld, DECL_LANG_SPECIFIC (node), size); |
a1b0969c | 603 | DECL_LANG_SPECIFIC (node) = ld; |
1d36b416 | 604 | |
605 | #ifdef GATHER_STATISTICS | |
606 | tree_node_counts[(int)lang_decl] += 1; | |
607 | tree_node_sizes[(int)lang_decl] += size; | |
608 | #endif | |
471086d6 | 609 | } |
610 | ||
c771ec7a | 611 | /* Copy DECL, including any language-specific parts. */ |
612 | ||
613 | tree | |
42c35e28 | 614 | copy_decl (tree decl) |
c771ec7a | 615 | { |
616 | tree copy; | |
617 | ||
618 | copy = copy_node (decl); | |
dbc42b78 | 619 | cxx_dup_lang_specific_decl (copy); |
c771ec7a | 620 | return copy; |
621 | } | |
622 | ||
1d36b416 | 623 | /* Replace the shared language-specific parts of NODE with a new copy. */ |
624 | ||
f6020ad0 | 625 | static void |
42c35e28 | 626 | copy_lang_type (tree node) |
1d36b416 | 627 | { |
628 | int size; | |
629 | struct lang_type *lt; | |
630 | ||
631 | if (! TYPE_LANG_SPECIFIC (node)) | |
632 | return; | |
633 | ||
1f3233d1 | 634 | if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class) |
635 | size = sizeof (struct lang_type); | |
636 | else | |
637 | size = sizeof (struct lang_type_ptrmem); | |
ba72912a | 638 | lt = ggc_alloc_lang_type (size); |
1d36b416 | 639 | memcpy (lt, TYPE_LANG_SPECIFIC (node), size); |
640 | TYPE_LANG_SPECIFIC (node) = lt; | |
641 | ||
642 | #ifdef GATHER_STATISTICS | |
643 | tree_node_counts[(int)lang_type] += 1; | |
644 | tree_node_sizes[(int)lang_type] += size; | |
645 | #endif | |
646 | } | |
647 | ||
648 | /* Copy TYPE, including any language-specific parts. */ | |
649 | ||
650 | tree | |
42c35e28 | 651 | copy_type (tree type) |
1d36b416 | 652 | { |
653 | tree copy; | |
654 | ||
655 | copy = copy_node (type); | |
656 | copy_lang_type (copy); | |
657 | return copy; | |
658 | } | |
659 | ||
471086d6 | 660 | tree |
42c35e28 | 661 | cxx_make_type (enum tree_code code) |
471086d6 | 662 | { |
cd16867a | 663 | tree t = make_node (code); |
471086d6 | 664 | |
1d36b416 | 665 | /* Create lang_type structure. */ |
95397ff9 | 666 | if (RECORD_OR_UNION_CODE_P (code) |
1d36b416 | 667 | || code == BOUND_TEMPLATE_TEMPLATE_PARM) |
e4e283ec | 668 | { |
ba72912a | 669 | struct lang_type *pi |
670 | = ggc_alloc_cleared_lang_type (sizeof (struct lang_type)); | |
471086d6 | 671 | |
dc125c61 | 672 | TYPE_LANG_SPECIFIC (t) = pi; |
1f3233d1 | 673 | pi->u.c.h.is_lang_type_class = 1; |
1d36b416 | 674 | |
675 | #ifdef GATHER_STATISTICS | |
676 | tree_node_counts[(int)lang_type] += 1; | |
677 | tree_node_sizes[(int)lang_type] += sizeof (struct lang_type); | |
678 | #endif | |
679 | } | |
680 | ||
681 | /* Set up some flags that give proper default behavior. */ | |
95397ff9 | 682 | if (RECORD_OR_UNION_CODE_P (code)) |
1d36b416 | 683 | { |
4507a637 | 684 | struct c_fileinfo *finfo = get_fileinfo (input_filename); |
62bf98ad | 685 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown); |
686 | CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only; | |
e4e283ec | 687 | } |
471086d6 | 688 | |
689 | return t; | |
690 | } | |
691 | ||
9972f65e | 692 | tree |
95397ff9 | 693 | make_class_type (enum tree_code code) |
9972f65e | 694 | { |
a1f71e15 | 695 | tree t = cxx_make_type (code); |
95397ff9 | 696 | SET_CLASS_TYPE_P (t, 1); |
9972f65e | 697 | return t; |
698 | } | |
96cc8e6a | 699 | |
700 | /* Returns true if we are currently in the main source file, or in a | |
701 | template instantiation started from the main source file. */ | |
702 | ||
703 | bool | |
704 | in_main_input_context (void) | |
705 | { | |
c5dd8e06 | 706 | struct tinst_level *tl = outermost_tinst_level(); |
96cc8e6a | 707 | |
708 | if (tl) | |
82715bcd | 709 | return filename_cmp (main_input_filename, |
710 | LOCATION_FILE (tl->locus)) == 0; | |
96cc8e6a | 711 | else |
82715bcd | 712 | return filename_cmp (main_input_filename, input_filename) == 0; |
96cc8e6a | 713 | } |