]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/lex.c
mips-protos.h (enum mips_symbol_type): Move from mips.h.
[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,
a6dd4094 3 1999, 2000, 2001, 2002, 2003, 2004 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"
f09f1de5 34#include "lex.h"
8d08fdba 35#include "flags.h"
3d6f7931 36#include "c-pragma.h"
54f92bfb 37#include "toplev.h"
7dee3f36 38#include "output.h"
7bdb32b9 39#include "tm_p.h"
2a9a326b 40#include "timevar.h"
8d08fdba 41
9e7d1164
NN
42static int interface_strcmp (const char *);
43static void init_cp_pragma (void);
0e5921e8 44
9e7d1164
NN
45static tree parse_strconst_pragma (const char *, int);
46static void handle_pragma_vtable (cpp_reader *);
47static void handle_pragma_unit (cpp_reader *);
48static void handle_pragma_interface (cpp_reader *);
49static void handle_pragma_implementation (cpp_reader *);
50static void handle_pragma_java_exceptions (cpp_reader *);
0e5921e8 51
9e7d1164
NN
52static void init_operators (void);
53static void copy_lang_type (tree);
8d08fdba 54
0e5921e8 55/* A constraint that can be tested at compile time. */
0e5921e8 56#define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
66a6250f 57
87e3dbc9
MM
58/* Functions and data structures for #pragma interface.
59
60 `#pragma implementation' means that the main file being compiled
61 is considered to implement (provide) the classes that appear in
62 its main body. I.e., if this is file "foo.cc", and class `bar'
63 is defined in "foo.cc", then we say that "foo.cc implements bar".
64
65 All main input files "implement" themselves automagically.
66
67 `#pragma interface' means that unless this file (of the form "foo.h"
68 is not presently being included by file "foo.cc", the
69 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
70 of the vtables nor any of the inline functions defined in foo.h
71 will ever be output.
72
73 There are cases when we want to link files such as "defs.h" and
74 "main.cc". In this case, we give "defs.h" a `#pragma interface',
75 and "main.cc" has `#pragma implementation "defs.h"'. */
76
77struct impl_files
78{
520a57c8 79 const char *filename;
87e3dbc9
MM
80 struct impl_files *next;
81};
82
83static struct impl_files *impl_file_chain;
84
8d08fdba
MS
85\f
86/* Return something to represent absolute declarators containing a *.
87 TARGET is the absolute declarator that the * contains.
c11b6f21 88 CV_QUALIFIERS is a list of modifiers such as const or volatile
8d08fdba
MS
89 to apply to the pointer type, represented as identifiers.
90
91 We return an INDIRECT_REF whose "contents" are TARGET
92 and whose type is the modifier list. */
93
94tree
9e7d1164 95make_pointer_declarator (tree cv_qualifiers, tree target)
8d08fdba
MS
96{
97 if (target && TREE_CODE (target) == IDENTIFIER_NODE
98 && ANON_AGGRNAME_P (target))
8251199e 99 error ("type name expected before `*'");
718b8ea5 100 target = build_nt (INDIRECT_REF, target);
c11b6f21 101 TREE_TYPE (target) = cv_qualifiers;
8d08fdba
MS
102 return target;
103}
104
105/* Return something to represent absolute declarators containing a &.
106 TARGET is the absolute declarator that the & contains.
c11b6f21 107 CV_QUALIFIERS is a list of modifiers such as const or volatile
8d08fdba
MS
108 to apply to the reference type, represented as identifiers.
109
110 We return an ADDR_EXPR whose "contents" are TARGET
111 and whose type is the modifier list. */
5362b086 112
8d08fdba 113tree
9e7d1164 114make_reference_declarator (tree cv_qualifiers, tree target)
8d08fdba 115{
718b8ea5 116 target = build_nt (ADDR_EXPR, target);
c11b6f21 117 TREE_TYPE (target) = cv_qualifiers;
8d08fdba
MS
118 return target;
119}
c11b6f21
MS
120
121tree
9e7d1164
NN
122make_call_declarator (tree target, tree parms, tree cv_qualifiers,
123 tree exception_specification)
c11b6f21 124{
718b8ea5
JM
125 target = build_nt (CALL_EXPR, target,
126 tree_cons (parms, cv_qualifiers, NULL_TREE),
127 /* The third operand is really RTL. We
128 shouldn't put anything there. */
129 NULL_TREE);
43f887f9 130 CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
c11b6f21
MS
131 return target;
132}
133
134void
9e7d1164
NN
135set_quals_and_spec (tree call_declarator, tree cv_qualifiers,
136 tree exception_specification)
c11b6f21 137{
43f887f9
MM
138 CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
139 CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
c11b6f21 140}
8d08fdba 141\f
8d08fdba
MS
142int interface_only; /* whether or not current file is only for
143 interface definitions. */
144int interface_unknown; /* whether or not we know this class
145 to behave according to #pragma interface. */
146
8d08fdba 147\f
19551f29 148void
9e7d1164 149cxx_finish (void)
8d08fdba 150{
22703ccc 151 c_common_finish ();
8d08fdba
MS
152}
153
596ea4e5
AS
154/* A mapping from tree codes to operator name information. */
155operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
156/* Similar, but for assignment operators. */
157operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
5362b086 158
596ea4e5
AS
159/* Initialize data structures that keep track of operator names. */
160
0c918ce5 161#define DEF_OPERATOR(NAME, C, M, AR, AP) \
0e5921e8
ZW
162 CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256);
163#include "operators.def"
164#undef DEF_OPERATOR
165
596ea4e5 166static void
9e7d1164 167init_operators (void)
596ea4e5
AS
168{
169 tree identifier;
170 char buffer[256];
171 struct operator_name_info_t *oni;
5362b086 172
0c918ce5 173#define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \
dba1acea 174 sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \
596ea4e5
AS
175 identifier = get_identifier (buffer); \
176 IDENTIFIER_OPNAME_P (identifier) = 1; \
177 \
178 oni = (ASSN_P \
179 ? &assignment_operator_name_info[(int) CODE] \
180 : &operator_name_info[(int) CODE]); \
181 oni->identifier = identifier; \
182 oni->name = NAME; \
3fa3c4bd
MM
183 oni->mangled_name = MANGLING; \
184 oni->arity = ARITY;
596ea4e5
AS
185
186#include "operators.def"
187#undef DEF_OPERATOR
188
5362b086 189 operator_name_info[(int) ERROR_MARK].identifier
596ea4e5
AS
190 = get_identifier ("<invalid operator>");
191
192 /* Handle some special cases. These operators are not defined in
193 the language, but can be produced internally. We may need them
194 for error-reporting. (Eventually, we should ensure that this
195 does not happen. Error messages involving these operators will
196 be confusing to users.) */
5362b086
EC
197
198 operator_name_info [(int) INIT_EXPR].name
596ea4e5
AS
199 = operator_name_info [(int) MODIFY_EXPR].name;
200 operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)";
201 operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)";
202 operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)";
203 operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)";
204 operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)";
205 operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
206 operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
207 operator_name_info [(int) ABS_EXPR].name = "abs";
596ea4e5
AS
208 operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
209 operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
210 operator_name_info [(int) IN_EXPR].name = "in";
211 operator_name_info [(int) RANGE_EXPR].name = "...";
212 operator_name_info [(int) CONVERT_EXPR].name = "+";
213
5362b086 214 assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
596ea4e5 215 = "(exact /=)";
5362b086 216 assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
596ea4e5 217 = "(ceiling /=)";
5362b086 218 assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
596ea4e5 219 = "(floor /=)";
5362b086 220 assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
596ea4e5 221 = "(round /=)";
5362b086 222 assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
596ea4e5 223 = "(ceiling %=)";
5362b086 224 assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
596ea4e5 225 = "(floor %=)";
5362b086 226 assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
596ea4e5
AS
227 = "(round %=)";
228}
229
0e5921e8
ZW
230/* The reserved keyword table. */
231struct resword
8d08fdba 232{
8b60264b 233 const char *const word;
df2b750f 234 ENUM_BITFIELD(rid) const rid : 16;
8b60264b 235 const unsigned int disable : 16;
0e5921e8 236};
8d08fdba 237
0e5921e8
ZW
238/* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
239 _true_. */
240#define D_EXT 0x01 /* GCC extension */
241#define D_ASM 0x02 /* in C99, but has a switch to turn it off */
0e5921e8
ZW
242
243CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
244
245static const struct resword reswords[] =
246{
d9dbd9b1 247 { "_Complex", RID_COMPLEX, 0 },
0ba8a114
NS
248 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
249 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
0e5921e8
ZW
250 { "__alignof", RID_ALIGNOF, 0 },
251 { "__alignof__", RID_ALIGNOF, 0 },
252 { "__asm", RID_ASM, 0 },
253 { "__asm__", RID_ASM, 0 },
254 { "__attribute", RID_ATTRIBUTE, 0 },
255 { "__attribute__", RID_ATTRIBUTE, 0 },
256 { "__builtin_va_arg", RID_VA_ARG, 0 },
257 { "__complex", RID_COMPLEX, 0 },
258 { "__complex__", RID_COMPLEX, 0 },
259 { "__const", RID_CONST, 0 },
260 { "__const__", RID_CONST, 0 },
261 { "__extension__", RID_EXTENSION, 0 },
0ba8a114 262 { "__func__", RID_C99_FUNCTION_NAME, 0 },
0e5921e8
ZW
263 { "__imag", RID_IMAGPART, 0 },
264 { "__imag__", RID_IMAGPART, 0 },
265 { "__inline", RID_INLINE, 0 },
266 { "__inline__", RID_INLINE, 0 },
267 { "__label__", RID_LABEL, 0 },
268 { "__null", RID_NULL, 0 },
263ee052
MM
269 { "__offsetof", RID_OFFSETOF, 0 },
270 { "__offsetof__", RID_OFFSETOF, 0 },
0e5921e8
ZW
271 { "__real", RID_REALPART, 0 },
272 { "__real__", RID_REALPART, 0 },
273 { "__restrict", RID_RESTRICT, 0 },
274 { "__restrict__", RID_RESTRICT, 0 },
275 { "__signed", RID_SIGNED, 0 },
276 { "__signed__", RID_SIGNED, 0 },
7a1f3f5f 277 { "__thread", RID_THREAD, 0 },
0e5921e8
ZW
278 { "__typeof", RID_TYPEOF, 0 },
279 { "__typeof__", RID_TYPEOF, 0 },
280 { "__volatile", RID_VOLATILE, 0 },
281 { "__volatile__", RID_VOLATILE, 0 },
0e5921e8 282 { "asm", RID_ASM, D_ASM },
0e5921e8 283 { "auto", RID_AUTO, 0 },
0e5921e8
ZW
284 { "bool", RID_BOOL, 0 },
285 { "break", RID_BREAK, 0 },
286 { "case", RID_CASE, 0 },
287 { "catch", RID_CATCH, 0 },
288 { "char", RID_CHAR, 0 },
289 { "class", RID_CLASS, 0 },
0e5921e8
ZW
290 { "const", RID_CONST, 0 },
291 { "const_cast", RID_CONSTCAST, 0 },
292 { "continue", RID_CONTINUE, 0 },
293 { "default", RID_DEFAULT, 0 },
294 { "delete", RID_DELETE, 0 },
295 { "do", RID_DO, 0 },
296 { "double", RID_DOUBLE, 0 },
297 { "dynamic_cast", RID_DYNCAST, 0 },
298 { "else", RID_ELSE, 0 },
299 { "enum", RID_ENUM, 0 },
300 { "explicit", RID_EXPLICIT, 0 },
301 { "export", RID_EXPORT, 0 },
302 { "extern", RID_EXTERN, 0 },
303 { "false", RID_FALSE, 0 },
304 { "float", RID_FLOAT, 0 },
305 { "for", RID_FOR, 0 },
306 { "friend", RID_FRIEND, 0 },
307 { "goto", RID_GOTO, 0 },
308 { "if", RID_IF, 0 },
309 { "inline", RID_INLINE, 0 },
310 { "int", RID_INT, 0 },
311 { "long", RID_LONG, 0 },
312 { "mutable", RID_MUTABLE, 0 },
313 { "namespace", RID_NAMESPACE, 0 },
314 { "new", RID_NEW, 0 },
0e5921e8 315 { "operator", RID_OPERATOR, 0 },
0e5921e8
ZW
316 { "private", RID_PRIVATE, 0 },
317 { "protected", RID_PROTECTED, 0 },
318 { "public", RID_PUBLIC, 0 },
319 { "register", RID_REGISTER, 0 },
320 { "reinterpret_cast", RID_REINTCAST, 0 },
321 { "return", RID_RETURN, 0 },
322 { "short", RID_SHORT, 0 },
323 { "signed", RID_SIGNED, 0 },
324 { "sizeof", RID_SIZEOF, 0 },
325 { "static", RID_STATIC, 0 },
326 { "static_cast", RID_STATCAST, 0 },
327 { "struct", RID_STRUCT, 0 },
328 { "switch", RID_SWITCH, 0 },
329 { "template", RID_TEMPLATE, 0 },
330 { "this", RID_THIS, 0 },
331 { "throw", RID_THROW, 0 },
332 { "true", RID_TRUE, 0 },
333 { "try", RID_TRY, 0 },
334 { "typedef", RID_TYPEDEF, 0 },
335 { "typename", RID_TYPENAME, 0 },
336 { "typeid", RID_TYPEID, 0 },
337 { "typeof", RID_TYPEOF, D_ASM|D_EXT },
338 { "union", RID_UNION, 0 },
339 { "unsigned", RID_UNSIGNED, 0 },
340 { "using", RID_USING, 0 },
341 { "virtual", RID_VIRTUAL, 0 },
342 { "void", RID_VOID, 0 },
343 { "volatile", RID_VOLATILE, 0 },
5362b086 344 { "wchar_t", RID_WCHAR, 0 },
0e5921e8 345 { "while", RID_WHILE, 0 },
0d3ba739 346
0e5921e8 347};
0e5921e8 348
f5e99456 349void
9e7d1164 350init_reswords (void)
0e5921e8
ZW
351{
352 unsigned int i;
353 tree id;
c372b0fa 354 int mask = ((flag_no_asm ? D_ASM : 0)
0e5921e8
ZW
355 | (flag_no_gnu_keywords ? D_EXT : 0));
356
c68b0a84 357 ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree));
ca7558fc 358 for (i = 0; i < ARRAY_SIZE (reswords); i++)
2b2a3531 359 {
0e5921e8
ZW
360 id = get_identifier (reswords[i].word);
361 C_RID_CODE (id) = reswords[i].rid;
362 ridpointers [(int) reswords[i].rid] = id;
363 if (! (reswords[i].disable & mask))
364 C_IS_RESERVED_WORD (id) = 1;
2b2a3531 365 }
0e5921e8 366}
2b2a3531 367
0e5921e8 368static void
9e7d1164 369init_cp_pragma (void)
0e5921e8 370{
c58b209a
NB
371 c_register_pragma (0, "vtable", handle_pragma_vtable);
372 c_register_pragma (0, "unit", handle_pragma_unit);
373 c_register_pragma (0, "interface", handle_pragma_interface);
374 c_register_pragma (0, "implementation", handle_pragma_implementation);
375 c_register_pragma ("GCC", "interface", handle_pragma_interface);
376 c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
377 c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions);
0e5921e8 378}
009ed910 379\f
f5e99456
NB
380/* Initialize the C++ front end. This function is very sensitive to
381 the exact order that things are done here. It would be nice if the
382 initialization done by this routine were moved to its subroutines,
383 and the ordering dependencies clarified and reduced. */
4bfec483
NB
384bool
385cxx_init (void)
0e5921e8 386{
009ed910
SB
387 static const enum tree_code stmt_codes[] = {
388 c_common_stmt_codes,
389 cp_stmt_codes
390 };
391
392 INIT_STATEMENT_CODES (stmt_codes);
393
267a0752
MC
394 /* We cannot just assign to input_filename because it has already
395 been initialized and will be used later as an N_BINCL for stabs+
396 debugging. */
397 push_srcloc ("<internal>", 0);
0e5921e8
ZW
398
399 init_reswords ();
87e3dbc9 400 init_tree ();
54f7877c 401 init_cp_semantics ();
596ea4e5 402 init_operators ();
669ec2b4 403 init_method ();
8d08fdba 404 init_error ();
f3cdb9c6 405
8d08fdba
MS
406 current_function_decl = NULL;
407
9e62871e 408 class_type_node = ridpointers[(int) RID_CLASS];
8d08fdba 409
f5e99456
NB
410 cxx_init_decl_processing ();
411
4d6baafa 412 /* Create the built-in __null node. */
03d0f4af 413 null_node = build_int_2 (0, 0);
b0c48229 414 TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
d11ad92e 415 ridpointers[RID_NULL] = null_node;
c73964b2 416
8d08fdba 417 interface_unknown = 1;
a755ad1c 418
4bfec483 419 if (c_common_init () == false)
267a0752
MC
420 {
421 pop_srcloc();
422 return false;
423 }
f5e99456
NB
424
425 init_cp_pragma ();
426
4bfec483 427 init_repo (main_input_filename);
f5e99456 428
267a0752 429 pop_srcloc();
4bfec483 430 return true;
8d08fdba 431}
8d08fdba 432\f
8d08fdba
MS
433/* Helper function to load global variables with interface
434 information. */
e92cc029 435
8d08fdba 436void
9e7d1164 437extract_interface_info (void)
8d08fdba 438{
7813d14c 439 struct c_fileinfo *finfo;
0e5921e8 440
7813d14c 441 finfo = get_fileinfo (input_filename);
0e5921e8
ZW
442 interface_only = finfo->interface_only;
443 interface_unknown = finfo->interface_unknown;
8d08fdba
MS
444}
445
51c184be 446/* Return nonzero if S is not considered part of an
8d08fdba 447 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
e92cc029 448
8d08fdba 449static int
9e7d1164 450interface_strcmp (const char* s)
8d08fdba
MS
451{
452 /* Set the interface/implementation bits for this scope. */
453 struct impl_files *ifiles;
d8e178a0 454 const char *s1;
8d08fdba 455
8d08fdba
MS
456 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
457 {
d8e178a0 458 const char *t1 = ifiles->filename;
8d08fdba
MS
459 s1 = s;
460
461 if (*s1 != *t1 || *s1 == 0)
462 continue;
463
464 while (*s1 == *t1 && *s1 != 0)
465 s1++, t1++;
466
467 /* A match. */
468 if (*s1 == *t1)
469 return 0;
470
471 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
9473c522 472 if (strchr (s1, '.') || strchr (t1, '.'))
8d08fdba
MS
473 continue;
474
475 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
476 continue;
477
478 /* A match. */
479 return 0;
480 }
481
482 /* No matches. */
483 return 1;
484}
485
0e5921e8
ZW
486\f
487
488/* Parse a #pragma whose sole argument is a string constant.
489 If OPT is true, the argument is optional. */
490static tree
9e7d1164 491parse_strconst_pragma (const char* name, int opt)
0e5921e8
ZW
492{
493 tree result, x;
494 enum cpp_ttype t;
495
496 t = c_lex (&x);
497 if (t == CPP_STRING)
498 {
499 result = x;
500 if (c_lex (&x) != CPP_EOF)
501 warning ("junk at end of #pragma %s", name);
502 return result;
503 }
504
505 if (t == CPP_EOF && opt)
506 return 0;
507
508 error ("invalid #pragma %s", name);
509 return (tree)-1;
510}
5362b086 511
0e5921e8 512static void
9e7d1164 513handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED )
0e5921e8 514{
46ccf50a
JM
515 parse_strconst_pragma ("vtable", 0);
516 sorry ("#pragma vtable no longer supported");
0e5921e8
ZW
517}
518
1d02ac83 519static void
9e7d1164 520handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED )
1d02ac83 521{
0e5921e8
ZW
522 /* Validate syntax, but don't do anything. */
523 parse_strconst_pragma ("unit", 0);
524}
525
526static void
9e7d1164 527handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
0e5921e8
ZW
528{
529 tree fname = parse_strconst_pragma ("interface", 1);
530 struct c_fileinfo *finfo;
531 const char *main_filename;
532
533 if (fname == (tree)-1)
534 return;
535 else if (fname == 0)
b3e68a79 536 main_filename = lbasename (input_filename);
0e5921e8 537 else
839ee4bc 538 main_filename = TREE_STRING_POINTER (fname);
0e5921e8
ZW
539
540 finfo = get_fileinfo (input_filename);
1d02ac83
JM
541
542 if (impl_file_chain == 0)
543 {
544 /* If this is zero at this point, then we are
545 auto-implementing. */
546 if (main_input_filename == 0)
547 main_input_filename = input_filename;
1d02ac83
JM
548 }
549
550 interface_only = interface_strcmp (main_filename);
551#ifdef MULTIPLE_SYMBOL_SPACES
552 if (! interface_only)
0e5921e8 553#endif
1d02ac83 554 interface_unknown = 0;
0e5921e8
ZW
555
556 finfo->interface_only = interface_only;
557 finfo->interface_unknown = interface_unknown;
1d02ac83
JM
558}
559
777ffbda
JM
560/* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
561 We used to only allow this at toplevel, but that restriction was buggy
562 in older compilers and it seems reasonable to allow it in the headers
563 themselves, too. It only needs to precede the matching #p interface.
564
565 We don't touch interface_only or interface_unknown; the user must specify
566 a matching #p interface for this to have any effect. */
567
1d02ac83 568static void
9e7d1164 569handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
1d02ac83 570{
0e5921e8
ZW
571 tree fname = parse_strconst_pragma ("implementation", 1);
572 const char *main_filename;
777ffbda 573 struct impl_files *ifiles = impl_file_chain;
0e5921e8
ZW
574
575 if (fname == (tree)-1)
576 return;
577
578 if (fname == 0)
579 {
580 if (main_input_filename)
581 main_filename = main_input_filename;
582 else
583 main_filename = input_filename;
b3e68a79 584 main_filename = lbasename (main_filename);
0e5921e8
ZW
585 }
586 else
587 {
839ee4bc 588 main_filename = TREE_STRING_POINTER (fname);
cf44ea52 589 if (cpp_included (parse_in, main_filename))
0e5921e8
ZW
590 warning ("#pragma implementation for %s appears after file is included",
591 main_filename);
0e5921e8
ZW
592 }
593
777ffbda 594 for (; ifiles; ifiles = ifiles->next)
1d02ac83 595 {
777ffbda
JM
596 if (! strcmp (ifiles->filename, main_filename))
597 break;
1d02ac83 598 }
777ffbda 599 if (ifiles == 0)
1d02ac83 600 {
c68b0a84 601 ifiles = xmalloc (sizeof (struct impl_files));
a8a05998 602 ifiles->filename = main_filename;
777ffbda
JM
603 ifiles->next = impl_file_chain;
604 impl_file_chain = ifiles;
1d02ac83 605 }
1d02ac83 606}
f181d4ae 607
1f730ff7
ZW
608/* Indicate that this file uses Java-personality exception handling. */
609static void
9e7d1164 610handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED )
1f730ff7
ZW
611{
612 tree x;
613 if (c_lex (&x) != CPP_EOF)
614 warning ("junk at end of #pragma GCC java_exceptions");
615
616 choose_personality_routine (lang_java);
617}
618
15c7fb9c 619/* Issue an error message indicating that the lookup of NAME (an
b3445994 620 IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */
15c7fb9c 621
b3445994 622tree
15c7fb9c
MM
623unqualified_name_lookup_error (tree name)
624{
625 if (IDENTIFIER_OPNAME_P (name))
626 {
627 if (name != ansi_opname (ERROR_MARK))
628 error ("`%D' not defined", name);
629 }
630 else if (current_function_decl == 0)
631 error ("`%D' was not declared in this scope", name);
632 else
633 {
634 if (IDENTIFIER_NAMESPACE_VALUE (name) != error_mark_node
635 || IDENTIFIER_ERROR_LOCUS (name) != current_function_decl)
636 {
637 static int undeclared_variable_notice;
638
639 error ("`%D' undeclared (first use this function)", name);
640
641 if (! undeclared_variable_notice)
642 {
643 error ("(Each undeclared identifier is reported only once for each function it appears in.)");
644 undeclared_variable_notice = 1;
645 }
646 }
647 /* Prevent repeated error messages. */
648 SET_IDENTIFIER_NAMESPACE_VALUE (name, error_mark_node);
649 SET_IDENTIFIER_ERROR_LOCUS (name, current_function_decl);
650 }
935d1834 651
b3445994 652 return error_mark_node;
5566b478
MS
653}
654
b3445994
MM
655/* Like unqualified_name_lookup_error, but NAME is an unqualified-id
656 used as a function. Returns an appropriate expression for
657 NAME. */
658
5566b478 659tree
b3445994 660unqualified_fn_lookup_error (tree name)
5566b478 661{
5156628f 662 if (processing_template_decl)
5566b478 663 {
b3445994
MM
664 /* In a template, it is invalid to write "f()" or "f(3)" if no
665 declaration of "f" is available. Historically, G++ and most
c5785644
WB
666 other compilers accepted that usage since they deferred all name
667 lookup until instantiation time rather than doing unqualified
668 name lookup at template definition time; explain to the user what
669 is going wrong.
670
671 Note that we have the exact wording of the following message in
672 the manual (trouble.texi, node "Name lookup"), so they need to
673 be kept in synch. */
10b1d5e7
MM
674 pedwarn ("there are no arguments to `%D' that depend on a template "
675 "parameter, so a declaration of `%D' must be available",
676 name, name);
b3445994
MM
677
678 if (!flag_permissive)
5566b478 679 {
b3445994
MM
680 static bool hint;
681 if (!hint)
682 {
683 error ("(if you use `-fpermissive', G++ will accept your code, "
684 "but allowing the use of an undeclared name is "
685 "deprecated)");
686 hint = true;
687 }
5566b478 688 }
10b1d5e7 689 return name;
5566b478 690 }
8d08fdba 691
b3445994 692 return unqualified_name_lookup_error (name);
8d08fdba
MS
693}
694
8d08fdba 695tree
9e7d1164 696build_lang_decl (enum tree_code code, tree name, tree type)
8d08fdba 697{
4ce3d537
MM
698 tree t;
699
4ce3d537 700 t = build_decl (code, name, type);
fcfcdfc8 701 retrofit_lang_decl (t);
4ce3d537 702
fcfcdfc8
JM
703 return t;
704}
705
706/* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
707 and pushdecl (for functions generated by the backend). */
708
709void
9e7d1164 710retrofit_lang_decl (tree t)
fcfcdfc8 711{
9188c363 712 struct lang_decl *ld;
4ce3d537 713 size_t size;
8d08fdba 714
4ce3d537
MM
715 if (CAN_HAVE_FULL_LANG_DECL_P (t))
716 size = sizeof (struct lang_decl);
717 else
718 size = sizeof (struct lang_decl_flags);
b0d06515 719
c68b0a84 720 ld = ggc_alloc_cleared (size);
8d08fdba 721
e2500fed
GK
722 ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
723 ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
724 ld->decl_flags.u2sel = 0;
725 if (ld->decl_flags.can_be_full)
726 ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
727
9188c363 728 DECL_LANG_SPECIFIC (t) = ld;
8d08fdba 729 if (current_lang_name == lang_name_cplusplus)
5d2ed28c 730 SET_DECL_LANGUAGE (t, lang_cplusplus);
8d08fdba 731 else if (current_lang_name == lang_name_c)
5d2ed28c 732 SET_DECL_LANGUAGE (t, lang_c);
a1774733 733 else if (current_lang_name == lang_name_java)
5d2ed28c 734 SET_DECL_LANGUAGE (t, lang_java);
a98facb0 735 else abort ();
8d08fdba 736
8d08fdba
MS
737#ifdef GATHER_STATISTICS
738 tree_node_counts[(int)lang_decl] += 1;
4ce3d537 739 tree_node_sizes[(int)lang_decl] += size;
8d08fdba 740#endif
8d08fdba
MS
741}
742
8d08fdba 743void
9e7d1164 744cxx_dup_lang_specific_decl (tree node)
8d08fdba
MS
745{
746 int size;
d60f72ae 747 struct lang_decl *ld;
8d08fdba 748
5566b478
MS
749 if (! DECL_LANG_SPECIFIC (node))
750 return;
751
b0d06515 752 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
8d08fdba
MS
753 size = sizeof (struct lang_decl_flags);
754 else
755 size = sizeof (struct lang_decl);
c68b0a84 756 ld = ggc_alloc (size);
4e135bdd 757 memcpy (ld, DECL_LANG_SPECIFIC (node), size);
d60f72ae 758 DECL_LANG_SPECIFIC (node) = ld;
11e74ea6
KL
759
760#ifdef GATHER_STATISTICS
761 tree_node_counts[(int)lang_decl] += 1;
762 tree_node_sizes[(int)lang_decl] += size;
763#endif
8d08fdba
MS
764}
765
0acf7199
MM
766/* Copy DECL, including any language-specific parts. */
767
768tree
9e7d1164 769copy_decl (tree decl)
0acf7199
MM
770{
771 tree copy;
772
773 copy = copy_node (decl);
63e1b1c4 774 cxx_dup_lang_specific_decl (copy);
0acf7199
MM
775 return copy;
776}
777
11e74ea6
KL
778/* Replace the shared language-specific parts of NODE with a new copy. */
779
76648a8b 780static void
9e7d1164 781copy_lang_type (tree node)
11e74ea6
KL
782{
783 int size;
784 struct lang_type *lt;
785
786 if (! TYPE_LANG_SPECIFIC (node))
787 return;
788
e2500fed
GK
789 if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class)
790 size = sizeof (struct lang_type);
791 else
792 size = sizeof (struct lang_type_ptrmem);
c68b0a84 793 lt = ggc_alloc (size);
11e74ea6
KL
794 memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
795 TYPE_LANG_SPECIFIC (node) = lt;
796
797#ifdef GATHER_STATISTICS
798 tree_node_counts[(int)lang_type] += 1;
799 tree_node_sizes[(int)lang_type] += size;
800#endif
801}
802
803/* Copy TYPE, including any language-specific parts. */
804
805tree
9e7d1164 806copy_type (tree type)
11e74ea6
KL
807{
808 tree copy;
809
810 copy = copy_node (type);
811 copy_lang_type (copy);
812 return copy;
813}
814
8d08fdba 815tree
9e7d1164 816cxx_make_type (enum tree_code code)
8d08fdba 817{
926ce8bd 818 tree t = make_node (code);
8d08fdba 819
11e74ea6
KL
820 /* Create lang_type structure. */
821 if (IS_AGGR_TYPE_CODE (code)
822 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
7ddedda4 823 {
32201ce4
AS
824 struct lang_type *pi;
825
c68b0a84 826 pi = ggc_alloc_cleared (sizeof (struct lang_type));
8d08fdba 827
32201ce4 828 TYPE_LANG_SPECIFIC (t) = pi;
e2500fed 829 pi->u.c.h.is_lang_type_class = 1;
11e74ea6
KL
830
831#ifdef GATHER_STATISTICS
832 tree_node_counts[(int)lang_type] += 1;
833 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
834#endif
835 }
836
837 /* Set up some flags that give proper default behavior. */
838 if (IS_AGGR_TYPE_CODE (code))
839 {
7ddedda4
MM
840 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
841 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
8d08fdba 842
7ddedda4
MM
843 /* Make sure this is laid out, for ease of use later. In the
844 presence of parse errors, the normal was of assuring this
845 might not ever get executed, so we lay it out *immediately*. */
846 build_pointer_type (t);
7ddedda4
MM
847 }
848 else
849 /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
850 TYPE_ALIAS_SET is initialized to -1 by default, so we must
851 clear it here. */
852 TYPE_ALIAS_SET (t) = 0;
8d08fdba 853
807625cf 854 /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
f6a7cfd2
MM
855 since they can be virtual base types, and we then need a
856 canonical binfo for them. Ideally, this would be done lazily for
857 all types. */
11e74ea6
KL
858 if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM
859 || code == BOUND_TEMPLATE_TEMPLATE_PARM
860 || code == TYPENAME_TYPE)
fed3cef0 861 TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
f6a7cfd2 862
8d08fdba
MS
863 return t;
864}
865
33848bb0 866tree
9e7d1164 867make_aggr_type (enum tree_code code)
33848bb0 868{
f1e639b1 869 tree t = cxx_make_type (code);
33848bb0
RH
870
871 if (IS_AGGR_TYPE_CODE (code))
872 SET_IS_AGGR_TYPE (t, 1);
873
874 return t;
875}
876
91063b51
MM
877/* Return the type-qualifier corresponding to the identifier given by
878 RID. */
879
880int
9e7d1164 881cp_type_qual_from_rid (tree rid)
91063b51
MM
882{
883 if (rid == ridpointers[(int) RID_CONST])
884 return TYPE_QUAL_CONST;
885 else if (rid == ridpointers[(int) RID_VOLATILE])
886 return TYPE_QUAL_VOLATILE;
887 else if (rid == ridpointers[(int) RID_RESTRICT])
888 return TYPE_QUAL_RESTRICT;
889
a98facb0 890 abort ();
91063b51
MM
891 return TYPE_UNQUALIFIED;
892}
This page took 1.610895 seconds and 5 git commands to generate.