]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/lex.c
re PR bootstrap/21230 (bootstrap failed unless bootstrap compiler is gcc.)
[gcc.git] / gcc / cp / lex.c
CommitLineData
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 6This file is part of GCC.
8d08fdba 7
f5adbb8d 8GCC is free software; you can redistribute it and/or modify
8d08fdba
MS
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
f5adbb8d 13GCC is distributed in the hope that it will be useful,
8d08fdba
MS
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
f5adbb8d 19along with GCC; see the file COPYING. If not, write to
e9fa0c7c
RK
20the Free Software Foundation, 59 Temple Place - Suite 330,
21Boston, 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
41static int interface_strcmp (const char *);
42static void init_cp_pragma (void);
0e5921e8 43
9e7d1164
NN
44static tree parse_strconst_pragma (const char *, int);
45static void handle_pragma_vtable (cpp_reader *);
46static void handle_pragma_unit (cpp_reader *);
47static void handle_pragma_interface (cpp_reader *);
48static void handle_pragma_implementation (cpp_reader *);
49static void handle_pragma_java_exceptions (cpp_reader *);
0e5921e8 50
9e7d1164
NN
51static void init_operators (void);
52static 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
76struct impl_files
77{
520a57c8 78 const char *filename;
87e3dbc9
MM
79 struct impl_files *next;
80};
81
82static struct impl_files *impl_file_chain;
83
8d08fdba 84\f
19551f29 85void
9e7d1164 86cxx_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. */
92operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
93/* Similar, but for assignment operators. */
94operator_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 103static void
9e7d1164 104init_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
AS
147 operator_name_info [(int) RANGE_EXPR].name = "...";
148 operator_name_info [(int) CONVERT_EXPR].name = "+";
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. */
167struct 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 */
0e5921e8
ZW
178
179CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
180
181static const struct resword reswords[] =
182{
d9dbd9b1 183 { "_Complex", RID_COMPLEX, 0 },
0ba8a114
NS
184 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
185 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
0e5921e8
ZW
186 { "__alignof", RID_ALIGNOF, 0 },
187 { "__alignof__", RID_ALIGNOF, 0 },
188 { "__asm", RID_ASM, 0 },
189 { "__asm__", RID_ASM, 0 },
190 { "__attribute", RID_ATTRIBUTE, 0 },
191 { "__attribute__", RID_ATTRIBUTE, 0 },
7a3ea201 192 { "__builtin_offsetof", RID_OFFSETOF, 0 },
0e5921e8
ZW
193 { "__builtin_va_arg", RID_VA_ARG, 0 },
194 { "__complex", RID_COMPLEX, 0 },
195 { "__complex__", RID_COMPLEX, 0 },
196 { "__const", RID_CONST, 0 },
197 { "__const__", RID_CONST, 0 },
198 { "__extension__", RID_EXTENSION, 0 },
0ba8a114 199 { "__func__", RID_C99_FUNCTION_NAME, 0 },
0e5921e8
ZW
200 { "__imag", RID_IMAGPART, 0 },
201 { "__imag__", RID_IMAGPART, 0 },
202 { "__inline", RID_INLINE, 0 },
203 { "__inline__", RID_INLINE, 0 },
204 { "__label__", RID_LABEL, 0 },
205 { "__null", RID_NULL, 0 },
206 { "__real", RID_REALPART, 0 },
207 { "__real__", RID_REALPART, 0 },
208 { "__restrict", RID_RESTRICT, 0 },
209 { "__restrict__", RID_RESTRICT, 0 },
210 { "__signed", RID_SIGNED, 0 },
211 { "__signed__", RID_SIGNED, 0 },
7a1f3f5f 212 { "__thread", RID_THREAD, 0 },
0e5921e8
ZW
213 { "__typeof", RID_TYPEOF, 0 },
214 { "__typeof__", RID_TYPEOF, 0 },
215 { "__volatile", RID_VOLATILE, 0 },
216 { "__volatile__", RID_VOLATILE, 0 },
0e5921e8 217 { "asm", RID_ASM, D_ASM },
0e5921e8 218 { "auto", RID_AUTO, 0 },
0e5921e8
ZW
219 { "bool", RID_BOOL, 0 },
220 { "break", RID_BREAK, 0 },
221 { "case", RID_CASE, 0 },
222 { "catch", RID_CATCH, 0 },
223 { "char", RID_CHAR, 0 },
224 { "class", RID_CLASS, 0 },
0e5921e8
ZW
225 { "const", RID_CONST, 0 },
226 { "const_cast", RID_CONSTCAST, 0 },
227 { "continue", RID_CONTINUE, 0 },
228 { "default", RID_DEFAULT, 0 },
229 { "delete", RID_DELETE, 0 },
230 { "do", RID_DO, 0 },
231 { "double", RID_DOUBLE, 0 },
232 { "dynamic_cast", RID_DYNCAST, 0 },
233 { "else", RID_ELSE, 0 },
234 { "enum", RID_ENUM, 0 },
235 { "explicit", RID_EXPLICIT, 0 },
236 { "export", RID_EXPORT, 0 },
237 { "extern", RID_EXTERN, 0 },
238 { "false", RID_FALSE, 0 },
239 { "float", RID_FLOAT, 0 },
240 { "for", RID_FOR, 0 },
241 { "friend", RID_FRIEND, 0 },
242 { "goto", RID_GOTO, 0 },
243 { "if", RID_IF, 0 },
244 { "inline", RID_INLINE, 0 },
245 { "int", RID_INT, 0 },
246 { "long", RID_LONG, 0 },
247 { "mutable", RID_MUTABLE, 0 },
248 { "namespace", RID_NAMESPACE, 0 },
249 { "new", RID_NEW, 0 },
0e5921e8 250 { "operator", RID_OPERATOR, 0 },
0e5921e8
ZW
251 { "private", RID_PRIVATE, 0 },
252 { "protected", RID_PROTECTED, 0 },
253 { "public", RID_PUBLIC, 0 },
254 { "register", RID_REGISTER, 0 },
255 { "reinterpret_cast", RID_REINTCAST, 0 },
256 { "return", RID_RETURN, 0 },
257 { "short", RID_SHORT, 0 },
258 { "signed", RID_SIGNED, 0 },
259 { "sizeof", RID_SIZEOF, 0 },
260 { "static", RID_STATIC, 0 },
261 { "static_cast", RID_STATCAST, 0 },
262 { "struct", RID_STRUCT, 0 },
263 { "switch", RID_SWITCH, 0 },
264 { "template", RID_TEMPLATE, 0 },
265 { "this", RID_THIS, 0 },
266 { "throw", RID_THROW, 0 },
267 { "true", RID_TRUE, 0 },
268 { "try", RID_TRY, 0 },
269 { "typedef", RID_TYPEDEF, 0 },
270 { "typename", RID_TYPENAME, 0 },
271 { "typeid", RID_TYPEID, 0 },
272 { "typeof", RID_TYPEOF, D_ASM|D_EXT },
273 { "union", RID_UNION, 0 },
274 { "unsigned", RID_UNSIGNED, 0 },
275 { "using", RID_USING, 0 },
276 { "virtual", RID_VIRTUAL, 0 },
277 { "void", RID_VOID, 0 },
278 { "volatile", RID_VOLATILE, 0 },
5362b086 279 { "wchar_t", RID_WCHAR, 0 },
0e5921e8 280 { "while", RID_WHILE, 0 },
0d3ba739 281
0e5921e8 282};
0e5921e8 283
f5e99456 284void
9e7d1164 285init_reswords (void)
0e5921e8
ZW
286{
287 unsigned int i;
288 tree id;
c372b0fa 289 int mask = ((flag_no_asm ? D_ASM : 0)
0e5921e8
ZW
290 | (flag_no_gnu_keywords ? D_EXT : 0));
291
c68b0a84 292 ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree));
ca7558fc 293 for (i = 0; i < ARRAY_SIZE (reswords); i++)
2b2a3531 294 {
0e5921e8
ZW
295 id = get_identifier (reswords[i].word);
296 C_RID_CODE (id) = reswords[i].rid;
297 ridpointers [(int) reswords[i].rid] = id;
298 if (! (reswords[i].disable & mask))
299 C_IS_RESERVED_WORD (id) = 1;
2b2a3531 300 }
0e5921e8 301}
2b2a3531 302
0e5921e8 303static void
9e7d1164 304init_cp_pragma (void)
0e5921e8 305{
c58b209a
NB
306 c_register_pragma (0, "vtable", handle_pragma_vtable);
307 c_register_pragma (0, "unit", handle_pragma_unit);
308 c_register_pragma (0, "interface", handle_pragma_interface);
309 c_register_pragma (0, "implementation", handle_pragma_implementation);
310 c_register_pragma ("GCC", "interface", handle_pragma_interface);
311 c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
312 c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions);
0e5921e8 313}
009ed910 314\f
f5e99456
NB
315/* Initialize the C++ front end. This function is very sensitive to
316 the exact order that things are done here. It would be nice if the
317 initialization done by this routine were moved to its subroutines,
318 and the ordering dependencies clarified and reduced. */
4bfec483
NB
319bool
320cxx_init (void)
0e5921e8 321{
009ed910 322 static const enum tree_code stmt_codes[] = {
009ed910
SB
323 cp_stmt_codes
324 };
325
326 INIT_STATEMENT_CODES (stmt_codes);
327
267a0752
MC
328 /* We cannot just assign to input_filename because it has already
329 been initialized and will be used later as an N_BINCL for stabs+
330 debugging. */
93409b8c
PB
331#ifdef USE_MAPPED_LOCATION
332 push_srcloc (BUILTINS_LOCATION);
333#else
334 push_srcloc ("<built-in>", 0);
335#endif
0e5921e8
ZW
336
337 init_reswords ();
87e3dbc9 338 init_tree ();
54f7877c 339 init_cp_semantics ();
596ea4e5 340 init_operators ();
669ec2b4 341 init_method ();
8d08fdba 342 init_error ();
f3cdb9c6 343
8d08fdba
MS
344 current_function_decl = NULL;
345
9e62871e 346 class_type_node = ridpointers[(int) RID_CLASS];
8d08fdba 347
f5e99456
NB
348 cxx_init_decl_processing ();
349
4684cd27
MM
350 /* The fact that G++ uses COMDAT for many entities (inline
351 functions, template instantiations, virtual tables, etc.) mean
352 that it is fundamentally unreliable to try to make decisions
353 about whether or not to output a particular entity until the end
354 of the compilation. However, the inliner requires that functions
355 be provided to the back end if they are to be inlined.
356 Therefore, we always use unit-at-a-time mode; in that mode, we
357 can provide entities to the back end and it will decide what to
358 emit based on what is actually needed. */
359 flag_unit_at_a_time = 1;
360
4bfec483 361 if (c_common_init () == false)
267a0752
MC
362 {
363 pop_srcloc();
364 return false;
365 }
f5e99456
NB
366
367 init_cp_pragma ();
368
4684cd27 369 init_repo ();
f5e99456 370
267a0752 371 pop_srcloc();
4bfec483 372 return true;
8d08fdba 373}
8d08fdba 374\f
51c184be 375/* Return nonzero if S is not considered part of an
8d08fdba 376 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
e92cc029 377
8d08fdba 378static int
9e7d1164 379interface_strcmp (const char* s)
8d08fdba
MS
380{
381 /* Set the interface/implementation bits for this scope. */
382 struct impl_files *ifiles;
d8e178a0 383 const char *s1;
8d08fdba 384
8d08fdba
MS
385 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
386 {
d8e178a0 387 const char *t1 = ifiles->filename;
8d08fdba
MS
388 s1 = s;
389
390 if (*s1 != *t1 || *s1 == 0)
391 continue;
392
393 while (*s1 == *t1 && *s1 != 0)
394 s1++, t1++;
395
396 /* A match. */
397 if (*s1 == *t1)
398 return 0;
399
400 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
9473c522 401 if (strchr (s1, '.') || strchr (t1, '.'))
8d08fdba
MS
402 continue;
403
404 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
405 continue;
406
407 /* A match. */
408 return 0;
409 }
410
411 /* No matches. */
412 return 1;
413}
414
0e5921e8
ZW
415\f
416
417/* Parse a #pragma whose sole argument is a string constant.
418 If OPT is true, the argument is optional. */
419static tree
9e7d1164 420parse_strconst_pragma (const char* name, int opt)
0e5921e8
ZW
421{
422 tree result, x;
423 enum cpp_ttype t;
424
425 t = c_lex (&x);
426 if (t == CPP_STRING)
427 {
428 result = x;
429 if (c_lex (&x) != CPP_EOF)
d4ee4d25 430 warning (0, "junk at end of #pragma %s", name);
0e5921e8
ZW
431 return result;
432 }
433
434 if (t == CPP_EOF && opt)
435 return 0;
436
437 error ("invalid #pragma %s", name);
438 return (tree)-1;
439}
5362b086 440
0e5921e8 441static void
9e7d1164 442handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED )
0e5921e8 443{
46ccf50a
JM
444 parse_strconst_pragma ("vtable", 0);
445 sorry ("#pragma vtable no longer supported");
0e5921e8
ZW
446}
447
1d02ac83 448static void
9e7d1164 449handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED )
1d02ac83 450{
0e5921e8
ZW
451 /* Validate syntax, but don't do anything. */
452 parse_strconst_pragma ("unit", 0);
453}
454
455static void
9e7d1164 456handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
0e5921e8
ZW
457{
458 tree fname = parse_strconst_pragma ("interface", 1);
459 struct c_fileinfo *finfo;
c162c75e 460 const char *filename;
0e5921e8
ZW
461
462 if (fname == (tree)-1)
463 return;
464 else if (fname == 0)
c162c75e 465 filename = lbasename (input_filename);
0e5921e8 466 else
c162c75e 467 filename = ggc_strdup (TREE_STRING_POINTER (fname));
0e5921e8 468
c162c75e 469 finfo = get_fileinfo (filename);
1d02ac83
JM
470
471 if (impl_file_chain == 0)
472 {
473 /* If this is zero at this point, then we are
474 auto-implementing. */
475 if (main_input_filename == 0)
476 main_input_filename = input_filename;
1d02ac83
JM
477 }
478
c162c75e 479 finfo->interface_only = interface_strcmp (filename);
15072eb1
ZW
480 /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see
481 a definition in another file. */
5d709b00
ZW
482 if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only)
483 finfo->interface_unknown = 0;
1d02ac83
JM
484}
485
777ffbda
JM
486/* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
487 We used to only allow this at toplevel, but that restriction was buggy
488 in older compilers and it seems reasonable to allow it in the headers
489 themselves, too. It only needs to precede the matching #p interface.
490
5d709b00
ZW
491 We don't touch finfo->interface_only or finfo->interface_unknown;
492 the user must specify a matching #p interface for this to have
493 any effect. */
777ffbda 494
1d02ac83 495static void
9e7d1164 496handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
1d02ac83 497{
0e5921e8 498 tree fname = parse_strconst_pragma ("implementation", 1);
c162c75e 499 const char *filename;
777ffbda 500 struct impl_files *ifiles = impl_file_chain;
0e5921e8
ZW
501
502 if (fname == (tree)-1)
503 return;
504
505 if (fname == 0)
506 {
507 if (main_input_filename)
c162c75e 508 filename = main_input_filename;
0e5921e8 509 else
c162c75e
MA
510 filename = input_filename;
511 filename = lbasename (filename);
0e5921e8
ZW
512 }
513 else
514 {
c162c75e
MA
515 filename = ggc_strdup (TREE_STRING_POINTER (fname));
516#if 0
517 /* We currently cannot give this diagnostic, as we reach this point
518 only after cpplib has scanned the entire translation unit, so
519 cpp_included always returns true. A plausible fix is to compare
520 the current source-location cookie with the first source-location
521 cookie (if any) of the filename, but this requires completing the
522 --enable-mapped-location project first. See PR 17577. */
523 if (cpp_included (parse_in, filename))
d4ee4d25 524 warning (0, "#pragma implementation for %qs appears after "
c162c75e
MA
525 "file is included", filename);
526#endif
0e5921e8
ZW
527 }
528
777ffbda 529 for (; ifiles; ifiles = ifiles->next)
1d02ac83 530 {
c162c75e 531 if (! strcmp (ifiles->filename, filename))
777ffbda 532 break;
1d02ac83 533 }
777ffbda 534 if (ifiles == 0)
1d02ac83 535 {
c68b0a84 536 ifiles = xmalloc (sizeof (struct impl_files));
c162c75e 537 ifiles->filename = filename;
777ffbda
JM
538 ifiles->next = impl_file_chain;
539 impl_file_chain = ifiles;
1d02ac83 540 }
1d02ac83 541}
f181d4ae 542
1f730ff7
ZW
543/* Indicate that this file uses Java-personality exception handling. */
544static void
9e7d1164 545handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED )
1f730ff7
ZW
546{
547 tree x;
548 if (c_lex (&x) != CPP_EOF)
d4ee4d25 549 warning (0, "junk at end of #pragma GCC java_exceptions");
1f730ff7
ZW
550
551 choose_personality_routine (lang_java);
552}
553
15c7fb9c 554/* Issue an error message indicating that the lookup of NAME (an
b3445994 555 IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */
15c7fb9c 556
b3445994 557tree
15c7fb9c
MM
558unqualified_name_lookup_error (tree name)
559{
560 if (IDENTIFIER_OPNAME_P (name))
561 {
562 if (name != ansi_opname (ERROR_MARK))
2a13a625 563 error ("%qD not defined", name);
15c7fb9c 564 }
15c7fb9c
MM
565 else
566 {
2a13a625 567 error ("%qD was not declared in this scope", name);
58ec3cc5
MM
568 /* Prevent repeated error messages by creating a VAR_DECL with
569 this NAME in the innermost block scope. */
570 if (current_function_decl)
15c7fb9c 571 {
58ec3cc5
MM
572 tree decl;
573 decl = build_decl (VAR_DECL, name, error_mark_node);
574 DECL_CONTEXT (decl) = current_function_decl;
575 push_local_binding (name, decl, 0);
996c2b52
MM
576 /* Mark the variable as used so that we do not get warnings
577 about it being unused later. */
578 TREE_USED (decl) = 1;
15c7fb9c 579 }
15c7fb9c 580 }
935d1834 581
b3445994 582 return error_mark_node;
5566b478
MS
583}
584
b3445994
MM
585/* Like unqualified_name_lookup_error, but NAME is an unqualified-id
586 used as a function. Returns an appropriate expression for
587 NAME. */
588
5566b478 589tree
b3445994 590unqualified_fn_lookup_error (tree name)
5566b478 591{
5156628f 592 if (processing_template_decl)
5566b478 593 {
b3445994
MM
594 /* In a template, it is invalid to write "f()" or "f(3)" if no
595 declaration of "f" is available. Historically, G++ and most
c5785644
WB
596 other compilers accepted that usage since they deferred all name
597 lookup until instantiation time rather than doing unqualified
598 name lookup at template definition time; explain to the user what
599 is going wrong.
600
601 Note that we have the exact wording of the following message in
602 the manual (trouble.texi, node "Name lookup"), so they need to
603 be kept in synch. */
2a13a625
GDR
604 pedwarn ("there are no arguments to %qD that depend on a template "
605 "parameter, so a declaration of %qD must be available",
10b1d5e7 606 name, name);
b3445994
MM
607
608 if (!flag_permissive)
5566b478 609 {
b3445994
MM
610 static bool hint;
611 if (!hint)
612 {
597cdf4f
JM
613 error ("(if you use %<-fpermissive%>, G++ will accept your "
614 "code, but allowing the use of an undeclared name is "
b3445994
MM
615 "deprecated)");
616 hint = true;
617 }
5566b478 618 }
10b1d5e7 619 return name;
5566b478 620 }
8d08fdba 621
b3445994 622 return unqualified_name_lookup_error (name);
8d08fdba
MS
623}
624
8d08fdba 625tree
9e7d1164 626build_lang_decl (enum tree_code code, tree name, tree type)
8d08fdba 627{
4ce3d537
MM
628 tree t;
629
4ce3d537 630 t = build_decl (code, name, type);
fcfcdfc8 631 retrofit_lang_decl (t);
4ce3d537 632
6dc36fed
MM
633 /* All nesting of C++ functions is lexical; there is never a "static
634 chain" in the sense of GNU C nested functions. */
635 if (code == FUNCTION_DECL)
636 DECL_NO_STATIC_CHAIN (t) = 1;
637
fcfcdfc8
JM
638 return t;
639}
640
641/* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
642 and pushdecl (for functions generated by the backend). */
643
644void
9e7d1164 645retrofit_lang_decl (tree t)
fcfcdfc8 646{
9188c363 647 struct lang_decl *ld;
4ce3d537 648 size_t size;
8d08fdba 649
4ce3d537
MM
650 if (CAN_HAVE_FULL_LANG_DECL_P (t))
651 size = sizeof (struct lang_decl);
652 else
653 size = sizeof (struct lang_decl_flags);
b0d06515 654
99dd239f 655 ld = GGC_CNEWVAR (struct lang_decl, size);
8d08fdba 656
e2500fed
GK
657 ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
658 ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
659 ld->decl_flags.u2sel = 0;
660 if (ld->decl_flags.can_be_full)
661 ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
662
9188c363 663 DECL_LANG_SPECIFIC (t) = ld;
ab73670a
MM
664 if (current_lang_name == lang_name_cplusplus
665 || decl_linkage (t) == lk_none)
5d2ed28c 666 SET_DECL_LANGUAGE (t, lang_cplusplus);
8d08fdba 667 else if (current_lang_name == lang_name_c)
5d2ed28c 668 SET_DECL_LANGUAGE (t, lang_c);
a1774733 669 else if (current_lang_name == lang_name_java)
5d2ed28c 670 SET_DECL_LANGUAGE (t, lang_java);
8dc2b103
NS
671 else
672 gcc_unreachable ();
8d08fdba 673
8d08fdba
MS
674#ifdef GATHER_STATISTICS
675 tree_node_counts[(int)lang_decl] += 1;
4ce3d537 676 tree_node_sizes[(int)lang_decl] += size;
8d08fdba 677#endif
8d08fdba
MS
678}
679
8d08fdba 680void
9e7d1164 681cxx_dup_lang_specific_decl (tree node)
8d08fdba
MS
682{
683 int size;
d60f72ae 684 struct lang_decl *ld;
8d08fdba 685
5566b478
MS
686 if (! DECL_LANG_SPECIFIC (node))
687 return;
688
b0d06515 689 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
8d08fdba
MS
690 size = sizeof (struct lang_decl_flags);
691 else
692 size = sizeof (struct lang_decl);
99dd239f 693 ld = GGC_NEWVAR (struct lang_decl, size);
4e135bdd 694 memcpy (ld, DECL_LANG_SPECIFIC (node), size);
d60f72ae 695 DECL_LANG_SPECIFIC (node) = ld;
11e74ea6
KL
696
697#ifdef GATHER_STATISTICS
698 tree_node_counts[(int)lang_decl] += 1;
699 tree_node_sizes[(int)lang_decl] += size;
700#endif
8d08fdba
MS
701}
702
0acf7199
MM
703/* Copy DECL, including any language-specific parts. */
704
705tree
9e7d1164 706copy_decl (tree decl)
0acf7199
MM
707{
708 tree copy;
709
710 copy = copy_node (decl);
63e1b1c4 711 cxx_dup_lang_specific_decl (copy);
0acf7199
MM
712 return copy;
713}
714
11e74ea6
KL
715/* Replace the shared language-specific parts of NODE with a new copy. */
716
76648a8b 717static void
9e7d1164 718copy_lang_type (tree node)
11e74ea6
KL
719{
720 int size;
721 struct lang_type *lt;
722
723 if (! TYPE_LANG_SPECIFIC (node))
724 return;
725
e2500fed
GK
726 if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class)
727 size = sizeof (struct lang_type);
728 else
729 size = sizeof (struct lang_type_ptrmem);
99dd239f 730 lt = GGC_NEWVAR (struct lang_type, size);
11e74ea6
KL
731 memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
732 TYPE_LANG_SPECIFIC (node) = lt;
733
734#ifdef GATHER_STATISTICS
735 tree_node_counts[(int)lang_type] += 1;
736 tree_node_sizes[(int)lang_type] += size;
737#endif
738}
739
740/* Copy TYPE, including any language-specific parts. */
741
742tree
9e7d1164 743copy_type (tree type)
11e74ea6
KL
744{
745 tree copy;
746
747 copy = copy_node (type);
748 copy_lang_type (copy);
749 return copy;
750}
751
8d08fdba 752tree
9e7d1164 753cxx_make_type (enum tree_code code)
8d08fdba 754{
926ce8bd 755 tree t = make_node (code);
8d08fdba 756
11e74ea6
KL
757 /* Create lang_type structure. */
758 if (IS_AGGR_TYPE_CODE (code)
759 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
7ddedda4 760 {
99dd239f 761 struct lang_type *pi = GGC_CNEW (struct lang_type);
8d08fdba 762
32201ce4 763 TYPE_LANG_SPECIFIC (t) = pi;
e2500fed 764 pi->u.c.h.is_lang_type_class = 1;
11e74ea6
KL
765
766#ifdef GATHER_STATISTICS
767 tree_node_counts[(int)lang_type] += 1;
768 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
769#endif
770 }
771
772 /* Set up some flags that give proper default behavior. */
773 if (IS_AGGR_TYPE_CODE (code))
774 {
c162c75e 775 struct c_fileinfo *finfo = get_fileinfo (lbasename (input_filename));
5d709b00
ZW
776 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
777 CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
7ddedda4 778 }
8d08fdba
MS
779
780 return t;
781}
782
33848bb0 783tree
9e7d1164 784make_aggr_type (enum tree_code code)
33848bb0 785{
f1e639b1 786 tree t = cxx_make_type (code);
33848bb0
RH
787
788 if (IS_AGGR_TYPE_CODE (code))
789 SET_IS_AGGR_TYPE (t, 1);
790
791 return t;
792}
This page took 1.969097 seconds and 5 git commands to generate.