]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/lex.c
Fix rs6000 -maix64 -mstring
[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,
03dc0325 3 1999, 2000, 2001 Free Software Foundation, Inc.
8d08fdba
MS
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
5
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify
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
13GNU CC is distributed in the hope that it will be useful,
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
19along with GNU CC; 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
8926095f 26/* Cause the `yydebug' variable to be defined. */
8d08fdba 27#define YYDEBUG 1
8d08fdba 28
da20811c 29#include "config.h"
8d052bc7 30#include "system.h"
8d08fdba
MS
31#include "input.h"
32#include "tree.h"
8d08fdba 33#include "cp-tree.h"
0e5921e8
ZW
34#include "cpplib.h"
35#include "c-lex.h"
f09f1de5 36#include "lex.h"
46b02c6d 37#include "parse.h"
8d08fdba 38#include "flags.h"
3d6f7931 39#include "c-pragma.h"
54f92bfb 40#include "toplev.h"
7dee3f36 41#include "output.h"
9cd64686 42#include "ggc.h"
7bdb32b9 43#include "tm_p.h"
2a9a326b 44#include "timevar.h"
856b6244 45#include "diagnostic.h"
8d08fdba
MS
46
47#ifdef MULTIBYTE_CHARS
0d3ba739 48#include "mbchar.h"
8d08fdba
MS
49#include <locale.h>
50#endif
51
158991b7
KG
52extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
53
158991b7 54static int interface_strcmp PARAMS ((const char *));
158991b7 55static int *init_cpp_parse PARAMS ((void));
0e5921e8 56static void init_cp_pragma PARAMS ((void));
0e5921e8
ZW
57
58static tree parse_strconst_pragma PARAMS ((const char *, int));
59static void handle_pragma_vtable PARAMS ((cpp_reader *));
60static void handle_pragma_unit PARAMS ((cpp_reader *));
61static void handle_pragma_interface PARAMS ((cpp_reader *));
62static void handle_pragma_implementation PARAMS ((cpp_reader *));
1f730ff7 63static void handle_pragma_java_exceptions PARAMS ((cpp_reader *));
0e5921e8 64
69ac77ce
JL
65#ifdef GATHER_STATISTICS
66#ifdef REDUCE_LENGTH
158991b7
KG
67static int reduce_cmp PARAMS ((int *, int *));
68static int token_cmp PARAMS ((int *, int *));
69ac77ce
JL
69#endif
70#endif
158991b7 71static int is_global PARAMS ((tree));
596ea4e5 72static void init_operators PARAMS ((void));
76648a8b 73static void copy_lang_type PARAMS ((tree));
8d08fdba 74
0e5921e8
ZW
75/* A constraint that can be tested at compile time. */
76#ifdef __STDC__
77#define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
78#else
79#define CONSTRAINT(name, expr) extern int constraint_/**/name [(expr) ? 1 : -1]
80#endif
0b807ad8 81
d4dfe7d6 82#include "cpplib.h"
66a6250f 83
8d08fdba
MS
84extern int yychar; /* the lookahead symbol */
85extern YYSTYPE yylval; /* the semantic value of the */
86 /* lookahead symbol */
87
0e5921e8
ZW
88/* These flags are used by c-lex.c. In C++, they're always off and on,
89 respectively. */
90int warn_traditional = 0;
91int flag_digraphs = 1;
8d08fdba
MS
92
93/* the declaration found for the last IDENTIFIER token read in.
94 yylex must look this up to detect typedefs, which get token type TYPENAME,
95 so it is left around in case the identifier is not a typedef but is
96 used in a context which makes it a reference to a variable. */
97tree lastiddecl;
98
8d08fdba
MS
99/* Array for holding counts of the numbers of tokens seen. */
100extern int *token_count;
9cd64686 101
87e3dbc9
MM
102/* Functions and data structures for #pragma interface.
103
104 `#pragma implementation' means that the main file being compiled
105 is considered to implement (provide) the classes that appear in
106 its main body. I.e., if this is file "foo.cc", and class `bar'
107 is defined in "foo.cc", then we say that "foo.cc implements bar".
108
109 All main input files "implement" themselves automagically.
110
111 `#pragma interface' means that unless this file (of the form "foo.h"
112 is not presently being included by file "foo.cc", the
113 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
114 of the vtables nor any of the inline functions defined in foo.h
115 will ever be output.
116
117 There are cases when we want to link files such as "defs.h" and
118 "main.cc". In this case, we give "defs.h" a `#pragma interface',
119 and "main.cc" has `#pragma implementation "defs.h"'. */
120
121struct impl_files
122{
520a57c8 123 const char *filename;
87e3dbc9
MM
124 struct impl_files *next;
125};
126
127static struct impl_files *impl_file_chain;
128
8d08fdba
MS
129\f
130/* Return something to represent absolute declarators containing a *.
131 TARGET is the absolute declarator that the * contains.
c11b6f21 132 CV_QUALIFIERS is a list of modifiers such as const or volatile
8d08fdba
MS
133 to apply to the pointer type, represented as identifiers.
134
135 We return an INDIRECT_REF whose "contents" are TARGET
136 and whose type is the modifier list. */
137
138tree
c11b6f21
MS
139make_pointer_declarator (cv_qualifiers, target)
140 tree cv_qualifiers, target;
8d08fdba
MS
141{
142 if (target && TREE_CODE (target) == IDENTIFIER_NODE
143 && ANON_AGGRNAME_P (target))
8251199e 144 error ("type name expected before `*'");
718b8ea5 145 target = build_nt (INDIRECT_REF, target);
c11b6f21 146 TREE_TYPE (target) = cv_qualifiers;
8d08fdba
MS
147 return target;
148}
149
150/* Return something to represent absolute declarators containing a &.
151 TARGET is the absolute declarator that the & contains.
c11b6f21 152 CV_QUALIFIERS is a list of modifiers such as const or volatile
8d08fdba
MS
153 to apply to the reference type, represented as identifiers.
154
155 We return an ADDR_EXPR whose "contents" are TARGET
156 and whose type is the modifier list. */
5362b086 157
8d08fdba 158tree
c11b6f21
MS
159make_reference_declarator (cv_qualifiers, target)
160 tree cv_qualifiers, target;
8d08fdba
MS
161{
162 if (target)
163 {
164 if (TREE_CODE (target) == ADDR_EXPR)
165 {
8251199e 166 error ("cannot declare references to references");
8d08fdba
MS
167 return target;
168 }
169 if (TREE_CODE (target) == INDIRECT_REF)
170 {
8251199e 171 error ("cannot declare pointers to references");
8d08fdba
MS
172 return target;
173 }
174 if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
8251199e 175 error ("type name expected before `&'");
8d08fdba 176 }
718b8ea5 177 target = build_nt (ADDR_EXPR, target);
c11b6f21 178 TREE_TYPE (target) = cv_qualifiers;
8d08fdba
MS
179 return target;
180}
c11b6f21
MS
181
182tree
183make_call_declarator (target, parms, cv_qualifiers, exception_specification)
184 tree target, parms, cv_qualifiers, exception_specification;
185{
718b8ea5
JM
186 target = build_nt (CALL_EXPR, target,
187 tree_cons (parms, cv_qualifiers, NULL_TREE),
188 /* The third operand is really RTL. We
189 shouldn't put anything there. */
190 NULL_TREE);
43f887f9 191 CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
c11b6f21
MS
192 return target;
193}
194
195void
196set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
197 tree call_declarator, cv_qualifiers, exception_specification;
198{
43f887f9
MM
199 CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
200 CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
c11b6f21 201}
8d08fdba 202\f
8d08fdba
MS
203int interface_only; /* whether or not current file is only for
204 interface definitions. */
205int interface_unknown; /* whether or not we know this class
206 to behave according to #pragma interface. */
207
c7d87c0a 208/* Tree code classes. */
8d08fdba
MS
209
210#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
211
8b60264b 212static const char cplus_tree_code_type[] = {
0a6969ad 213 'x',
e92cc029 214#include "cp-tree.def"
8d08fdba
MS
215};
216#undef DEFTREECODE
217
218/* Table indexed by tree code giving number of expression
219 operands beyond the fixed part of the node structure.
220 Not used for types or decls. */
221
222#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
223
8b60264b 224static const int cplus_tree_code_length[] = {
8d08fdba 225 0,
e92cc029 226#include "cp-tree.def"
8d08fdba
MS
227};
228#undef DEFTREECODE
229
230/* Names of tree components.
231 Used for printing out the tree and error messages. */
232#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
233
40008eda 234static const char *const cplus_tree_code_name[] = {
8d08fdba 235 "@@dummy",
e92cc029 236#include "cp-tree.def"
8d08fdba
MS
237};
238#undef DEFTREECODE
239\f
13c61421 240/* Post-switch processing. */
19551f29 241void
13c61421
NB
242cxx_post_options ()
243{
4d6baafa 244 c_common_post_options ();
13c61421 245}
8d08fdba 246
4d6baafa 247/* Initialization before switch parsing. */
19551f29 248void
ee811cfd 249cxx_init_options ()
9116eca2 250{
4d6baafa 251 c_common_init_options (clk_cplusplus);
dfb0fb1d 252
9116eca2
RH
253 /* Default exceptions on. */
254 flag_exceptions = 1;
24805e80
GDR
255 /* By default wrap lines at 80 characters. Is getenv ("COLUMNS")
256 preferable? */
9596ddd6 257 diagnostic_line_cutoff (global_dc) = 80;
856b6244
GDR
258 /* By default, emit location information once for every
259 diagnostic message. */
9596ddd6 260 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
9116eca2
RH
261}
262
19551f29 263void
13c61421 264cxx_finish ()
8d08fdba 265{
19551f29 266 if (flag_gnu_xref)
22703ccc
NB
267 GNU_xref_end (errorcount + sorrycount);
268 c_common_finish ();
8d08fdba
MS
269}
270
2b2a3531
DB
271static int *
272init_cpp_parse ()
273{
274#ifdef GATHER_STATISTICS
275#ifdef REDUCE_LENGTH
fffeac96 276 reduce_count = (int *) xcalloc (sizeof (int), (REDUCE_LENGTH + 1));
2b2a3531 277 reduce_count += 1;
fffeac96 278 token_count = (int *) xcalloc (sizeof (int), (TOKEN_LENGTH + 1));
2b2a3531
DB
279 token_count += 1;
280#endif
281#endif
282 return token_count;
283}
284
596ea4e5
AS
285/* A mapping from tree codes to operator name information. */
286operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
287/* Similar, but for assignment operators. */
288operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
5362b086 289
596ea4e5
AS
290/* Initialize data structures that keep track of operator names. */
291
0c918ce5 292#define DEF_OPERATOR(NAME, C, M, AR, AP) \
0e5921e8
ZW
293 CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256);
294#include "operators.def"
295#undef DEF_OPERATOR
296
596ea4e5
AS
297static void
298init_operators ()
299{
300 tree identifier;
301 char buffer[256];
302 struct operator_name_info_t *oni;
5362b086 303
0c918ce5 304#define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \
dba1acea 305 sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \
596ea4e5
AS
306 identifier = get_identifier (buffer); \
307 IDENTIFIER_OPNAME_P (identifier) = 1; \
308 \
309 oni = (ASSN_P \
310 ? &assignment_operator_name_info[(int) CODE] \
311 : &operator_name_info[(int) CODE]); \
312 oni->identifier = identifier; \
313 oni->name = NAME; \
0c918ce5 314 oni->mangled_name = MANGLING;
596ea4e5
AS
315
316#include "operators.def"
317#undef DEF_OPERATOR
318
5362b086 319 operator_name_info[(int) ERROR_MARK].identifier
596ea4e5
AS
320 = get_identifier ("<invalid operator>");
321
322 /* Handle some special cases. These operators are not defined in
323 the language, but can be produced internally. We may need them
324 for error-reporting. (Eventually, we should ensure that this
325 does not happen. Error messages involving these operators will
326 be confusing to users.) */
5362b086
EC
327
328 operator_name_info [(int) INIT_EXPR].name
596ea4e5
AS
329 = operator_name_info [(int) MODIFY_EXPR].name;
330 operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)";
331 operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)";
332 operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)";
333 operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)";
334 operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)";
335 operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
336 operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
337 operator_name_info [(int) ABS_EXPR].name = "abs";
338 operator_name_info [(int) FFS_EXPR].name = "ffs";
339 operator_name_info [(int) BIT_ANDTC_EXPR].name = "&~";
340 operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
341 operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
342 operator_name_info [(int) IN_EXPR].name = "in";
343 operator_name_info [(int) RANGE_EXPR].name = "...";
344 operator_name_info [(int) CONVERT_EXPR].name = "+";
345
5362b086 346 assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
596ea4e5 347 = "(exact /=)";
5362b086 348 assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
596ea4e5 349 = "(ceiling /=)";
5362b086 350 assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
596ea4e5 351 = "(floor /=)";
5362b086 352 assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
596ea4e5 353 = "(round /=)";
5362b086 354 assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
596ea4e5 355 = "(ceiling %=)";
5362b086 356 assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
596ea4e5 357 = "(floor %=)";
5362b086 358 assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
596ea4e5
AS
359 = "(round %=)";
360}
361
0e5921e8
ZW
362/* The reserved keyword table. */
363struct resword
8d08fdba 364{
8b60264b
KG
365 const char *const word;
366 const ENUM_BITFIELD(rid) rid : 16;
367 const unsigned int disable : 16;
0e5921e8 368};
8d08fdba 369
0e5921e8
ZW
370/* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
371 _true_. */
372#define D_EXT 0x01 /* GCC extension */
373#define D_ASM 0x02 /* in C99, but has a switch to turn it off */
374#define D_OPNAME 0x04 /* operator names */
375
376CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
377
378static const struct resword reswords[] =
379{
d9dbd9b1 380 { "_Complex", RID_COMPLEX, 0 },
0ba8a114
NS
381 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
382 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
0e5921e8
ZW
383 { "__alignof", RID_ALIGNOF, 0 },
384 { "__alignof__", RID_ALIGNOF, 0 },
385 { "__asm", RID_ASM, 0 },
386 { "__asm__", RID_ASM, 0 },
387 { "__attribute", RID_ATTRIBUTE, 0 },
388 { "__attribute__", RID_ATTRIBUTE, 0 },
389 { "__builtin_va_arg", RID_VA_ARG, 0 },
390 { "__complex", RID_COMPLEX, 0 },
391 { "__complex__", RID_COMPLEX, 0 },
392 { "__const", RID_CONST, 0 },
393 { "__const__", RID_CONST, 0 },
394 { "__extension__", RID_EXTENSION, 0 },
0ba8a114 395 { "__func__", RID_C99_FUNCTION_NAME, 0 },
0e5921e8
ZW
396 { "__imag", RID_IMAGPART, 0 },
397 { "__imag__", RID_IMAGPART, 0 },
398 { "__inline", RID_INLINE, 0 },
399 { "__inline__", RID_INLINE, 0 },
400 { "__label__", RID_LABEL, 0 },
401 { "__null", RID_NULL, 0 },
402 { "__real", RID_REALPART, 0 },
403 { "__real__", RID_REALPART, 0 },
404 { "__restrict", RID_RESTRICT, 0 },
405 { "__restrict__", RID_RESTRICT, 0 },
406 { "__signed", RID_SIGNED, 0 },
407 { "__signed__", RID_SIGNED, 0 },
408 { "__typeof", RID_TYPEOF, 0 },
409 { "__typeof__", RID_TYPEOF, 0 },
410 { "__volatile", RID_VOLATILE, 0 },
411 { "__volatile__", RID_VOLATILE, 0 },
0e5921e8
ZW
412 { "asm", RID_ASM, D_ASM },
413 { "and", RID_AND, D_OPNAME },
414 { "and_eq", RID_AND_EQ, D_OPNAME },
415 { "auto", RID_AUTO, 0 },
416 { "bitand", RID_BITAND, D_OPNAME },
417 { "bitor", RID_BITOR, D_OPNAME },
418 { "bool", RID_BOOL, 0 },
419 { "break", RID_BREAK, 0 },
420 { "case", RID_CASE, 0 },
421 { "catch", RID_CATCH, 0 },
422 { "char", RID_CHAR, 0 },
423 { "class", RID_CLASS, 0 },
424 { "compl", RID_COMPL, D_OPNAME },
425 { "const", RID_CONST, 0 },
426 { "const_cast", RID_CONSTCAST, 0 },
427 { "continue", RID_CONTINUE, 0 },
428 { "default", RID_DEFAULT, 0 },
429 { "delete", RID_DELETE, 0 },
430 { "do", RID_DO, 0 },
431 { "double", RID_DOUBLE, 0 },
432 { "dynamic_cast", RID_DYNCAST, 0 },
433 { "else", RID_ELSE, 0 },
434 { "enum", RID_ENUM, 0 },
435 { "explicit", RID_EXPLICIT, 0 },
436 { "export", RID_EXPORT, 0 },
437 { "extern", RID_EXTERN, 0 },
438 { "false", RID_FALSE, 0 },
439 { "float", RID_FLOAT, 0 },
440 { "for", RID_FOR, 0 },
441 { "friend", RID_FRIEND, 0 },
442 { "goto", RID_GOTO, 0 },
443 { "if", RID_IF, 0 },
444 { "inline", RID_INLINE, 0 },
445 { "int", RID_INT, 0 },
446 { "long", RID_LONG, 0 },
447 { "mutable", RID_MUTABLE, 0 },
448 { "namespace", RID_NAMESPACE, 0 },
449 { "new", RID_NEW, 0 },
450 { "not", RID_NOT, D_OPNAME },
451 { "not_eq", RID_NOT_EQ, D_OPNAME },
452 { "operator", RID_OPERATOR, 0 },
453 { "or", RID_OR, D_OPNAME },
454 { "or_eq", RID_OR_EQ, D_OPNAME },
455 { "private", RID_PRIVATE, 0 },
456 { "protected", RID_PROTECTED, 0 },
457 { "public", RID_PUBLIC, 0 },
458 { "register", RID_REGISTER, 0 },
459 { "reinterpret_cast", RID_REINTCAST, 0 },
460 { "return", RID_RETURN, 0 },
461 { "short", RID_SHORT, 0 },
462 { "signed", RID_SIGNED, 0 },
463 { "sizeof", RID_SIZEOF, 0 },
464 { "static", RID_STATIC, 0 },
465 { "static_cast", RID_STATCAST, 0 },
466 { "struct", RID_STRUCT, 0 },
467 { "switch", RID_SWITCH, 0 },
468 { "template", RID_TEMPLATE, 0 },
469 { "this", RID_THIS, 0 },
470 { "throw", RID_THROW, 0 },
471 { "true", RID_TRUE, 0 },
472 { "try", RID_TRY, 0 },
473 { "typedef", RID_TYPEDEF, 0 },
474 { "typename", RID_TYPENAME, 0 },
475 { "typeid", RID_TYPEID, 0 },
476 { "typeof", RID_TYPEOF, D_ASM|D_EXT },
477 { "union", RID_UNION, 0 },
478 { "unsigned", RID_UNSIGNED, 0 },
479 { "using", RID_USING, 0 },
480 { "virtual", RID_VIRTUAL, 0 },
481 { "void", RID_VOID, 0 },
482 { "volatile", RID_VOLATILE, 0 },
5362b086 483 { "wchar_t", RID_WCHAR, 0 },
0e5921e8
ZW
484 { "while", RID_WHILE, 0 },
485 { "xor", RID_XOR, D_OPNAME },
486 { "xor_eq", RID_XOR_EQ, D_OPNAME },
0d3ba739 487
0e5921e8
ZW
488};
489#define N_reswords (sizeof reswords / sizeof (struct resword))
490
491/* Table mapping from RID_* constants to yacc token numbers.
492 Unfortunately we have to have entries for all the keywords in all
493 three languages. */
494const short rid_to_yy[RID_MAX] =
495{
496 /* RID_STATIC */ SCSPEC,
497 /* RID_UNSIGNED */ TYPESPEC,
498 /* RID_LONG */ TYPESPEC,
499 /* RID_CONST */ CV_QUALIFIER,
500 /* RID_EXTERN */ SCSPEC,
501 /* RID_REGISTER */ SCSPEC,
502 /* RID_TYPEDEF */ SCSPEC,
503 /* RID_SHORT */ TYPESPEC,
504 /* RID_INLINE */ SCSPEC,
505 /* RID_VOLATILE */ CV_QUALIFIER,
506 /* RID_SIGNED */ TYPESPEC,
507 /* RID_AUTO */ SCSPEC,
508 /* RID_RESTRICT */ CV_QUALIFIER,
509
510 /* C extensions. Bounded pointers are not yet in C++ */
511 /* RID_BOUNDED */ 0,
512 /* RID_UNBOUNDED */ 0,
513 /* RID_COMPLEX */ TYPESPEC,
514
515 /* C++ */
516 /* RID_FRIEND */ SCSPEC,
517 /* RID_VIRTUAL */ SCSPEC,
518 /* RID_EXPLICIT */ SCSPEC,
447306fa 519 /* RID_EXPORT */ EXPORT,
0e5921e8
ZW
520 /* RID_MUTABLE */ SCSPEC,
521
522 /* ObjC */
523 /* RID_IN */ 0,
524 /* RID_OUT */ 0,
525 /* RID_INOUT */ 0,
526 /* RID_BYCOPY */ 0,
527 /* RID_BYREF */ 0,
528 /* RID_ONEWAY */ 0,
5362b086 529
0e5921e8
ZW
530 /* C */
531 /* RID_INT */ TYPESPEC,
532 /* RID_CHAR */ TYPESPEC,
533 /* RID_FLOAT */ TYPESPEC,
534 /* RID_DOUBLE */ TYPESPEC,
535 /* RID_VOID */ TYPESPEC,
536 /* RID_ENUM */ ENUM,
537 /* RID_STRUCT */ AGGR,
538 /* RID_UNION */ AGGR,
539 /* RID_IF */ IF,
540 /* RID_ELSE */ ELSE,
541 /* RID_WHILE */ WHILE,
542 /* RID_DO */ DO,
543 /* RID_FOR */ FOR,
544 /* RID_SWITCH */ SWITCH,
545 /* RID_CASE */ CASE,
546 /* RID_DEFAULT */ DEFAULT,
547 /* RID_BREAK */ BREAK,
548 /* RID_CONTINUE */ CONTINUE,
549 /* RID_RETURN */ RETURN_KEYWORD,
550 /* RID_GOTO */ GOTO,
551 /* RID_SIZEOF */ SIZEOF,
552
553 /* C extensions */
554 /* RID_ASM */ ASM_KEYWORD,
555 /* RID_TYPEOF */ TYPEOF,
556 /* RID_ALIGNOF */ ALIGNOF,
557 /* RID_ATTRIBUTE */ ATTRIBUTE,
558 /* RID_VA_ARG */ VA_ARG,
559 /* RID_EXTENSION */ EXTENSION,
560 /* RID_IMAGPART */ IMAGPART,
561 /* RID_REALPART */ REALPART,
562 /* RID_LABEL */ LABEL,
563 /* RID_PTRBASE */ 0,
564 /* RID_PTREXTENT */ 0,
565 /* RID_PTRVALUE */ 0,
566
0ba8a114
NS
567 /* RID_FUNCTION_NAME */ VAR_FUNC_NAME,
568 /* RID_PRETTY_FUNCTION_NAME */ VAR_FUNC_NAME,
569 /* RID_c99_FUNCTION_NAME */ VAR_FUNC_NAME,
570
0e5921e8
ZW
571 /* C++ */
572 /* RID_BOOL */ TYPESPEC,
573 /* RID_WCHAR */ TYPESPEC,
574 /* RID_CLASS */ AGGR,
575 /* RID_PUBLIC */ VISSPEC,
576 /* RID_PRIVATE */ VISSPEC,
577 /* RID_PROTECTED */ VISSPEC,
578 /* RID_TEMPLATE */ TEMPLATE,
579 /* RID_NULL */ CONSTANT,
580 /* RID_CATCH */ CATCH,
581 /* RID_DELETE */ DELETE,
582 /* RID_FALSE */ CXX_FALSE,
583 /* RID_NAMESPACE */ NAMESPACE,
584 /* RID_NEW */ NEW,
585 /* RID_OPERATOR */ OPERATOR,
586 /* RID_THIS */ THIS,
587 /* RID_THROW */ THROW,
588 /* RID_TRUE */ CXX_TRUE,
589 /* RID_TRY */ TRY,
590 /* RID_TYPENAME */ TYPENAME_KEYWORD,
591 /* RID_TYPEID */ TYPEID,
592 /* RID_USING */ USING,
593
594 /* casts */
595 /* RID_CONSTCAST */ CONST_CAST,
596 /* RID_DYNCAST */ DYNAMIC_CAST,
597 /* RID_REINTCAST */ REINTERPRET_CAST,
598 /* RID_STATCAST */ STATIC_CAST,
599
600 /* alternate spellings */
601 /* RID_AND */ ANDAND,
602 /* RID_AND_EQ */ ASSIGN,
603 /* RID_NOT */ '!',
604 /* RID_NOT_EQ */ EQCOMPARE,
605 /* RID_OR */ OROR,
606 /* RID_OR_EQ */ ASSIGN,
607 /* RID_XOR */ '^',
608 /* RID_XOR_EQ */ ASSIGN,
609 /* RID_BITAND */ '&',
610 /* RID_BITOR */ '|',
611 /* RID_COMPL */ '~',
612
613 /* Objective C */
614 /* RID_ID */ 0,
615 /* RID_AT_ENCODE */ 0,
616 /* RID_AT_END */ 0,
617 /* RID_AT_CLASS */ 0,
618 /* RID_AT_ALIAS */ 0,
619 /* RID_AT_DEFS */ 0,
620 /* RID_AT_PRIVATE */ 0,
621 /* RID_AT_PROTECTED */ 0,
622 /* RID_AT_PUBLIC */ 0,
623 /* RID_AT_PROTOCOL */ 0,
624 /* RID_AT_SELECTOR */ 0,
625 /* RID_AT_INTERFACE */ 0,
626 /* RID_AT_IMPLEMENTATION */ 0
627};
628
f5e99456 629void
0e5921e8
ZW
630init_reswords ()
631{
632 unsigned int i;
633 tree id;
634 int mask = ((flag_operator_names ? 0 : D_OPNAME)
635 | (flag_no_asm ? D_ASM : 0)
636 | (flag_no_gnu_keywords ? D_EXT : 0));
637
638 /* It is not necessary to register ridpointers as a GC root, because
639 all the trees it points to are permanently interned in the
640 get_identifier hash anyway. */
641 ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
642 for (i = 0; i < N_reswords; i++)
2b2a3531 643 {
0e5921e8
ZW
644 id = get_identifier (reswords[i].word);
645 C_RID_CODE (id) = reswords[i].rid;
646 ridpointers [(int) reswords[i].rid] = id;
647 if (! (reswords[i].disable & mask))
648 C_IS_RESERVED_WORD (id) = 1;
2b2a3531 649 }
0e5921e8 650}
2b2a3531 651
0e5921e8
ZW
652static void
653init_cp_pragma ()
654{
cf44ea52
NB
655 cpp_register_pragma (parse_in, 0, "vtable", handle_pragma_vtable);
656 cpp_register_pragma (parse_in, 0, "unit", handle_pragma_unit);
1ceb5ff3 657
cf44ea52
NB
658 cpp_register_pragma (parse_in, 0, "interface", handle_pragma_interface);
659 cpp_register_pragma (parse_in, 0, "implementation",
0e5921e8 660 handle_pragma_implementation);
1ceb5ff3 661
cf44ea52
NB
662 cpp_register_pragma (parse_in, "GCC", "interface", handle_pragma_interface);
663 cpp_register_pragma (parse_in, "GCC", "implementation",
0e5921e8 664 handle_pragma_implementation);
1f730ff7
ZW
665 cpp_register_pragma (parse_in, "GCC", "java_exceptions",
666 handle_pragma_java_exceptions);
0e5921e8 667}
8d08fdba 668
f5e99456
NB
669/* Initialize the C++ front end. This function is very sensitive to
670 the exact order that things are done here. It would be nice if the
671 initialization done by this routine were moved to its subroutines,
672 and the ordering dependencies clarified and reduced. */
0e5921e8 673const char *
f5e99456 674cxx_init (filename)
0e5921e8
ZW
675 const char *filename;
676{
8d08fdba 677 decl_printable_name = lang_printable_name;
a8a05998 678 input_filename = "<internal>";
0e5921e8
ZW
679
680 init_reswords ();
0e5921e8 681 init_spew ();
87e3dbc9 682 init_tree ();
8d08fdba 683 init_cplus_expand ();
54f7877c 684 init_cp_semantics ();
8d08fdba 685
c7d87c0a
BC
686 add_c_tree_codes ();
687
688 memcpy (tree_code_type + (int) LAST_C_TREE_CODE,
f5984164 689 cplus_tree_code_type,
c7d87c0a
BC
690 (int)LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE);
691 memcpy (tree_code_length + (int) LAST_C_TREE_CODE,
f5984164 692 cplus_tree_code_length,
c7d87c0a
BC
693 (LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE) * sizeof (int));
694 memcpy (tree_code_name + (int) LAST_C_TREE_CODE,
f5984164 695 cplus_tree_code_name,
c7d87c0a 696 (LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE) * sizeof (char *));
8d08fdba 697
596ea4e5 698 init_operators ();
669ec2b4 699 init_method ();
8d08fdba 700 init_error ();
f3cdb9c6 701
8d08fdba
MS
702 current_function_decl = NULL;
703
8d08fdba
MS
704 class_type_node = build_int_2 (class_type, 0);
705 TREE_TYPE (class_type_node) = class_type_node;
706 ridpointers[(int) RID_CLASS] = class_type_node;
707
708 record_type_node = build_int_2 (record_type, 0);
709 TREE_TYPE (record_type_node) = record_type_node;
0e5921e8 710 ridpointers[(int) RID_STRUCT] = record_type_node;
8d08fdba
MS
711
712 union_type_node = build_int_2 (union_type, 0);
713 TREE_TYPE (union_type_node) = union_type_node;
714 ridpointers[(int) RID_UNION] = union_type_node;
715
716 enum_type_node = build_int_2 (enum_type, 0);
717 TREE_TYPE (enum_type_node) = enum_type_node;
718 ridpointers[(int) RID_ENUM] = enum_type_node;
719
f5e99456
NB
720 cxx_init_decl_processing ();
721
4d6baafa 722 /* Create the built-in __null node. */
03d0f4af 723 null_node = build_int_2 (0, 0);
f5e99456 724 TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0);
d11ad92e 725 ridpointers[RID_NULL] = null_node;
c73964b2 726
2b2a3531 727 token_count = init_cpp_parse ();
8d08fdba 728 interface_unknown = 1;
a755ad1c 729
4d6baafa 730 filename = c_common_init (filename);
f5e99456
NB
731
732 init_cp_pragma ();
733
734 if (flag_gnu_xref)
735 GNU_xref_begin (filename);
736 init_repo (filename);
737
738 return filename;
8d08fdba 739}
8d08fdba 740\f
f9c4f105 741inline void
8d08fdba
MS
742yyprint (file, yychar, yylval)
743 FILE *file;
744 int yychar;
745 YYSTYPE yylval;
746{
747 tree t;
748 switch (yychar)
749 {
750 case IDENTIFIER:
751 case TYPENAME:
752 case TYPESPEC:
753 case PTYPENAME:
074917ba 754 case PFUNCNAME:
8d08fdba
MS
755 case IDENTIFIER_DEFN:
756 case TYPENAME_DEFN:
757 case PTYPENAME_DEFN:
8d08fdba
MS
758 case SCSPEC:
759 case PRE_PARSED_CLASS_DECL:
760 t = yylval.ttype;
11686454 761 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL)
fc378698 762 {
430bb96b 763 fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t)));
fc378698
MS
764 break;
765 }
8d08fdba
MS
766 my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
767 if (IDENTIFIER_POINTER (t))
768 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
769 break;
1ceb5ff3 770
8d08fdba
MS
771 case AGGR:
772 if (yylval.ttype == class_type_node)
773 fprintf (file, " `class'");
774 else if (yylval.ttype == record_type_node)
775 fprintf (file, " `struct'");
776 else if (yylval.ttype == union_type_node)
777 fprintf (file, " `union'");
778 else if (yylval.ttype == enum_type_node)
779 fprintf (file, " `enum'");
8d08fdba
MS
780 else
781 my_friendly_abort (80);
782 break;
1ceb5ff3
JM
783
784 case CONSTANT:
785 t = yylval.ttype;
786 if (TREE_CODE (t) == INTEGER_CST)
787 fprintf (file,
788#if HOST_BITS_PER_WIDE_INT == 64
789#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
790 " 0x%x%016x",
791#else
792#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
793 " 0x%lx%016lx",
794#else
795 " 0x%llx%016llx",
796#endif
797#endif
798#else
799#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
800 " 0x%lx%08lx",
801#else
802 " 0x%x%08x",
803#endif
804#endif
805 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
806 break;
8d08fdba
MS
807 }
808}
809
5566b478 810#if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
8d08fdba 811static int *reduce_count;
5566b478
MS
812#endif
813
8d08fdba
MS
814int *token_count;
815
72b7eeff 816#if 0
8d08fdba
MS
817#define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
818#define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
72b7eeff 819#endif
8d08fdba 820
8d08fdba 821#ifdef GATHER_STATISTICS
72b7eeff 822#ifdef REDUCE_LENGTH
8d08fdba
MS
823void
824yyhook (yyn)
825 int yyn;
826{
827 reduce_count[yyn] += 1;
828}
8d08fdba
MS
829
830static int
831reduce_cmp (p, q)
832 int *p, *q;
833{
834 return reduce_count[*q] - reduce_count[*p];
835}
836
837static int
838token_cmp (p, q)
839 int *p, *q;
840{
841 return token_count[*q] - token_count[*p];
842}
8926095f 843#endif
72b7eeff 844#endif
8d08fdba
MS
845
846void
847print_parse_statistics ()
848{
849#ifdef GATHER_STATISTICS
72b7eeff 850#ifdef REDUCE_LENGTH
8d08fdba
MS
851#if YYDEBUG != 0
852 int i;
853 int maxlen = REDUCE_LENGTH;
854 unsigned *sorted;
5362b086 855
8d08fdba
MS
856 if (reduce_count[-1] == 0)
857 return;
858
859 if (TOKEN_LENGTH > REDUCE_LENGTH)
860 maxlen = TOKEN_LENGTH;
861 sorted = (unsigned *) alloca (sizeof (int) * maxlen);
862
863 for (i = 0; i < TOKEN_LENGTH; i++)
864 sorted[i] = i;
865 qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
866 for (i = 0; i < TOKEN_LENGTH; i++)
867 {
e92cc029
MS
868 int idx = sorted[i];
869 if (token_count[idx] == 0)
8d08fdba 870 break;
e92cc029 871 if (token_count[idx] < token_count[-1])
8d08fdba
MS
872 break;
873 fprintf (stderr, "token %d, `%s', count = %d\n",
e92cc029 874 idx, yytname[YYTRANSLATE (idx)], token_count[idx]);
8d08fdba
MS
875 }
876 fprintf (stderr, "\n");
877 for (i = 0; i < REDUCE_LENGTH; i++)
878 sorted[i] = i;
879 qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
880 for (i = 0; i < REDUCE_LENGTH; i++)
881 {
e92cc029
MS
882 int idx = sorted[i];
883 if (reduce_count[idx] == 0)
8d08fdba 884 break;
e92cc029 885 if (reduce_count[idx] < reduce_count[-1])
8d08fdba
MS
886 break;
887 fprintf (stderr, "rule %d, line %d, count = %d\n",
e92cc029 888 idx, yyrline[idx], reduce_count[idx]);
8d08fdba
MS
889 }
890 fprintf (stderr, "\n");
891#endif
892#endif
72b7eeff 893#endif
8d08fdba
MS
894}
895
896/* Sets the value of the 'yydebug' variable to VALUE.
897 This is a function so we don't have to have YYDEBUG defined
898 in order to build the compiler. */
e92cc029 899
8d08fdba 900void
5d69f816 901cxx_set_yydebug (value)
8d08fdba
MS
902 int value;
903{
904#if YYDEBUG != 0
905 extern int yydebug;
906 yydebug = value;
907#else
357351e5 908 warning ("YYDEBUG not defined");
8d08fdba
MS
909#endif
910}
911
8d08fdba
MS
912/* Helper function to load global variables with interface
913 information. */
e92cc029 914
8d08fdba
MS
915void
916extract_interface_info ()
917{
0e5921e8 918 struct c_fileinfo *finfo = 0;
8d08fdba
MS
919
920 if (flag_alt_external_templates)
921 {
3ae18eaf 922 tree til = tinst_for_decl ();
5362b086 923
8d08fdba 924 if (til)
0e5921e8 925 finfo = get_fileinfo (TINST_FILE (til));
8d08fdba 926 }
0e5921e8
ZW
927 if (!finfo)
928 finfo = get_fileinfo (input_filename);
929
930 interface_only = finfo->interface_only;
931 interface_unknown = finfo->interface_unknown;
932
933 /* This happens to be a convenient place to put this. */
934 if (flag_gnu_xref) GNU_xref_file (input_filename);
8d08fdba
MS
935}
936
51c184be 937/* Return nonzero if S is not considered part of an
8d08fdba 938 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
e92cc029 939
8d08fdba
MS
940static int
941interface_strcmp (s)
d8e178a0 942 const char *s;
8d08fdba
MS
943{
944 /* Set the interface/implementation bits for this scope. */
945 struct impl_files *ifiles;
d8e178a0 946 const char *s1;
8d08fdba 947
8d08fdba
MS
948 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
949 {
d8e178a0 950 const char *t1 = ifiles->filename;
8d08fdba
MS
951 s1 = s;
952
953 if (*s1 != *t1 || *s1 == 0)
954 continue;
955
956 while (*s1 == *t1 && *s1 != 0)
957 s1++, t1++;
958
959 /* A match. */
960 if (*s1 == *t1)
961 return 0;
962
963 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
9473c522 964 if (strchr (s1, '.') || strchr (t1, '.'))
8d08fdba
MS
965 continue;
966
967 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
968 continue;
969
970 /* A match. */
971 return 0;
972 }
973
974 /* No matches. */
975 return 1;
976}
977
0e5921e8
ZW
978/* Heuristic to tell whether the user is missing a semicolon
979 after a struct or enum declaration. Emit an error message
980 if we know the user has blown it. */
981
982void
983check_for_missing_semicolon (type)
984 tree type;
985{
986 if (yychar < 0)
987 yychar = yylex ();
988
989 if ((yychar > 255
990 && yychar != SCSPEC
991 && yychar != IDENTIFIER
992 && yychar != TYPENAME
993 && yychar != CV_QUALIFIER
994 && yychar != SELFNAME)
995 || yychar == 0 /* EOF */)
996 {
1951a1b6 997 if (TYPE_ANONYMOUS_P (type))
0e5921e8
ZW
998 error ("semicolon missing after %s declaration",
999 TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
1000 else
1001 cp_error ("semicolon missing after declaration of `%T'", type);
1002 shadow_tag (build_tree_list (0, type));
1003 }
1004 /* Could probably also hack cases where class { ... } f (); appears. */
1005 clear_anon_tags ();
1006}
1007
1008void
1009note_got_semicolon (type)
1010 tree type;
1011{
1012 if (!TYPE_P (type))
1013 my_friendly_abort (60);
1014 if (CLASS_TYPE_P (type))
1015 CLASSTYPE_GOT_SEMICOLON (type) = 1;
1016}
1017
1018void
1019note_list_got_semicolon (declspecs)
1020 tree declspecs;
1021{
1022 tree link;
1023
1024 for (link = declspecs; link; link = TREE_CHAIN (link))
1025 {
1026 tree type = TREE_VALUE (link);
1027 if (TYPE_P (type))
1028 note_got_semicolon (type);
1029 }
1030 clear_anon_tags ();
1031}
1032\f
1033
1034/* Parse a #pragma whose sole argument is a string constant.
1035 If OPT is true, the argument is optional. */
1036static tree
1037parse_strconst_pragma (name, opt)
1038 const char *name;
1039 int opt;
1040{
1041 tree result, x;
1042 enum cpp_ttype t;
1043
1044 t = c_lex (&x);
1045 if (t == CPP_STRING)
1046 {
1047 result = x;
1048 if (c_lex (&x) != CPP_EOF)
1049 warning ("junk at end of #pragma %s", name);
1050 return result;
1051 }
1052
1053 if (t == CPP_EOF && opt)
1054 return 0;
1055
1056 error ("invalid #pragma %s", name);
1057 return (tree)-1;
1058}
5362b086 1059
0e5921e8
ZW
1060static void
1061handle_pragma_vtable (dfile)
1062 cpp_reader *dfile ATTRIBUTE_UNUSED;
1063{
46ccf50a
JM
1064 parse_strconst_pragma ("vtable", 0);
1065 sorry ("#pragma vtable no longer supported");
0e5921e8
ZW
1066}
1067
1d02ac83 1068static void
0e5921e8
ZW
1069handle_pragma_unit (dfile)
1070 cpp_reader *dfile ATTRIBUTE_UNUSED;
1d02ac83 1071{
0e5921e8
ZW
1072 /* Validate syntax, but don't do anything. */
1073 parse_strconst_pragma ("unit", 0);
1074}
1075
1076static void
1077handle_pragma_interface (dfile)
1078 cpp_reader *dfile ATTRIBUTE_UNUSED;
1079{
1080 tree fname = parse_strconst_pragma ("interface", 1);
1081 struct c_fileinfo *finfo;
1082 const char *main_filename;
1083
1084 if (fname == (tree)-1)
1085 return;
1086 else if (fname == 0)
b3e68a79 1087 main_filename = lbasename (input_filename);
0e5921e8
ZW
1088 else
1089 main_filename = TREE_STRING_POINTER (fname);
1090
1091 finfo = get_fileinfo (input_filename);
1d02ac83
JM
1092
1093 if (impl_file_chain == 0)
1094 {
1095 /* If this is zero at this point, then we are
1096 auto-implementing. */
1097 if (main_input_filename == 0)
1098 main_input_filename = input_filename;
1d02ac83
JM
1099 }
1100
1101 interface_only = interface_strcmp (main_filename);
1102#ifdef MULTIPLE_SYMBOL_SPACES
1103 if (! interface_only)
0e5921e8 1104#endif
1d02ac83 1105 interface_unknown = 0;
0e5921e8
ZW
1106
1107 finfo->interface_only = interface_only;
1108 finfo->interface_unknown = interface_unknown;
1d02ac83
JM
1109}
1110
777ffbda
JM
1111/* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
1112 We used to only allow this at toplevel, but that restriction was buggy
1113 in older compilers and it seems reasonable to allow it in the headers
1114 themselves, too. It only needs to precede the matching #p interface.
1115
1116 We don't touch interface_only or interface_unknown; the user must specify
1117 a matching #p interface for this to have any effect. */
1118
1d02ac83 1119static void
0e5921e8
ZW
1120handle_pragma_implementation (dfile)
1121 cpp_reader *dfile ATTRIBUTE_UNUSED;
1d02ac83 1122{
0e5921e8
ZW
1123 tree fname = parse_strconst_pragma ("implementation", 1);
1124 const char *main_filename;
777ffbda 1125 struct impl_files *ifiles = impl_file_chain;
0e5921e8
ZW
1126
1127 if (fname == (tree)-1)
1128 return;
1129
1130 if (fname == 0)
1131 {
1132 if (main_input_filename)
1133 main_filename = main_input_filename;
1134 else
1135 main_filename = input_filename;
b3e68a79 1136 main_filename = lbasename (main_filename);
0e5921e8
ZW
1137 }
1138 else
1139 {
1140 main_filename = TREE_STRING_POINTER (fname);
cf44ea52 1141 if (cpp_included (parse_in, main_filename))
0e5921e8
ZW
1142 warning ("#pragma implementation for %s appears after file is included",
1143 main_filename);
0e5921e8
ZW
1144 }
1145
777ffbda 1146 for (; ifiles; ifiles = ifiles->next)
1d02ac83 1147 {
777ffbda
JM
1148 if (! strcmp (ifiles->filename, main_filename))
1149 break;
1d02ac83 1150 }
777ffbda 1151 if (ifiles == 0)
1d02ac83 1152 {
777ffbda 1153 ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files));
a8a05998 1154 ifiles->filename = main_filename;
777ffbda
JM
1155 ifiles->next = impl_file_chain;
1156 impl_file_chain = ifiles;
1d02ac83 1157 }
1d02ac83 1158}
f181d4ae 1159
1f730ff7
ZW
1160/* Indicate that this file uses Java-personality exception handling. */
1161static void
1162handle_pragma_java_exceptions (dfile)
1163 cpp_reader *dfile ATTRIBUTE_UNUSED;
1164{
1165 tree x;
1166 if (c_lex (&x) != CPP_EOF)
1167 warning ("junk at end of #pragma GCC java_exceptions");
1168
1169 choose_personality_routine (lang_java);
1170}
1171
0e5921e8
ZW
1172void
1173do_pending_lang_change ()
f181d4ae 1174{
0e5921e8
ZW
1175 for (; pending_lang_change > 0; --pending_lang_change)
1176 push_lang_context (lang_name_c);
1177 for (; pending_lang_change < 0; ++pending_lang_change)
1178 pop_lang_context ();
f181d4ae
MM
1179}
1180
0e5921e8 1181/* Return true if d is in a global scope. */
e92cc029 1182
0e5921e8
ZW
1183static int
1184is_global (d)
1185 tree d;
8d08fdba 1186{
0e5921e8
ZW
1187 while (1)
1188 switch (TREE_CODE (d))
1189 {
1190 case ERROR_MARK:
1191 return 1;
f376e137 1192
0e5921e8
ZW
1193 case OVERLOAD: d = OVL_FUNCTION (d); continue;
1194 case TREE_LIST: d = TREE_VALUE (d); continue;
1195 default:
1196 my_friendly_assert (DECL_P (d), 980629);
f376e137 1197
0e5921e8 1198 return DECL_NAMESPACE_SCOPE_P (d);
eac293a1 1199 }
8d08fdba
MS
1200}
1201
0e5921e8
ZW
1202tree
1203do_identifier (token, parsing, args)
1204 register tree token;
1205 int parsing;
1206 tree args;
8d08fdba 1207{
0e5921e8
ZW
1208 register tree id;
1209 int lexing = (parsing == 1);
e92cc029 1210
5361cbb7 1211 if (! lexing)
0e5921e8 1212 id = lookup_name (token, 0);
8d08fdba 1213 else
0e5921e8 1214 id = lastiddecl;
8d08fdba 1215
0e5921e8
ZW
1216 /* Do Koenig lookup if appropriate (inside templates we build lookup
1217 expressions instead).
8d08fdba 1218
0e5921e8
ZW
1219 [basic.lookup.koenig]: If the ordinary unqualified lookup of the name
1220 finds the declaration of a class member function, the associated
1221 namespaces and classes are not considered. */
2c169bab 1222
a759e627 1223 if (args && !current_template_parms && (!id || is_global (id)))
f181d4ae 1224 id = lookup_arg_dependent (token, id, args);
a759e627 1225
8d2733ca
MS
1226 /* Remember that this name has been used in the class definition, as per
1227 [class.scope0] */
70adf8a9 1228 if (id && parsing)
8f032717 1229 maybe_note_name_used_in_class (token, id);
72b7eeff 1230
5b163de4
JM
1231 if (id == error_mark_node)
1232 {
1233 /* lookup_name quietly returns error_mark_node if we're parsing,
1234 as we don't want to complain about an identifier that ends up
1235 being used as a declarator. So we call it again to get the error
1236 message. */
1237 id = lookup_name (token, 0);
1238 return error_mark_node;
1239 }
935d1834
ZW
1240
1241 if (!id || (TREE_CODE (id) == FUNCTION_DECL
1242 && DECL_ANTICIPATED (id)))
5b163de4 1243 {
5566b478 1244 if (current_template_parms)
672476cb 1245 return build_min_nt (LOOKUP_EXPR, token);
5566b478 1246 else if (IDENTIFIER_OPNAME_P (token))
72b7eeff 1247 {
596ea4e5 1248 if (token != ansi_opname (ERROR_MARK))
8251199e 1249 cp_error ("`%D' not defined", token);
72b7eeff
MS
1250 id = error_mark_node;
1251 }
8d08fdba
MS
1252 else if (current_function_decl == 0)
1253 {
8251199e 1254 cp_error ("`%D' was not declared in this scope", token);
8d08fdba
MS
1255 id = error_mark_node;
1256 }
1257 else
1258 {
30394414 1259 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node
8d08fdba
MS
1260 || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
1261 {
1262 static int undeclared_variable_notice;
1263
8251199e 1264 cp_error ("`%D' undeclared (first use this function)", token);
8d08fdba
MS
1265
1266 if (! undeclared_variable_notice)
1267 {
b4f4233d 1268 error ("(Each undeclared identifier is reported only once for each function it appears in.)");
8d08fdba
MS
1269 undeclared_variable_notice = 1;
1270 }
1271 }
1272 id = error_mark_node;
1273 /* Prevent repeated error messages. */
2c73f9f5 1274 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
8d08fdba
MS
1275 SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
1276 }
1277 }
f3be9e3c
PB
1278
1279 if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
1280 {
1281 tree shadowed = DECL_SHADOWED_FOR_VAR (id);
2ee887f2
MS
1282 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
1283 && DECL_DEAD_FOR_LOCAL (shadowed))
1284 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
1285 if (!shadowed)
30394414 1286 shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id));
f3be9e3c
PB
1287 if (shadowed)
1288 {
1289 if (!DECL_ERROR_REPORTED (id))
1290 {
8251199e 1291 warning ("name lookup of `%s' changed",
f3be9e3c 1292 IDENTIFIER_POINTER (token));
cab1f180 1293 cp_warning_at (" matches this `%D' under ISO standard rules",
f3be9e3c 1294 shadowed);
8251199e 1295 cp_warning_at (" matches this `%D' under old rules", id);
f3be9e3c
PB
1296 DECL_ERROR_REPORTED (id) = 1;
1297 }
1298 id = shadowed;
1299 }
1300 else if (!DECL_ERROR_REPORTED (id))
1301 {
f3be9e3c 1302 DECL_ERROR_REPORTED (id) = 1;
834c6dff 1303 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (id)))
f3be9e3c 1304 {
cab1f180 1305 error ("name lookup of `%s' changed for new ISO `for' scoping",
b9d12519 1306 IDENTIFIER_POINTER (token));
8251199e 1307 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id);
f3be9e3c
PB
1308 id = error_mark_node;
1309 }
1310 else
1311 {
cab1f180 1312 pedwarn ("name lookup of `%s' changed for new ISO `for' scoping",
b9d12519 1313 IDENTIFIER_POINTER (token));
8251199e 1314 cp_pedwarn_at (" using obsolete binding at `%D'", id);
f3be9e3c
PB
1315 }
1316 }
1317 }
8d08fdba
MS
1318 /* TREE_USED is set in `hack_identifier'. */
1319 if (TREE_CODE (id) == CONST_DECL)
1320 {
d6479fe7 1321 /* Check access. */
8d08fdba 1322 if (IDENTIFIER_CLASS_VALUE (token) == id)
4f1c5b7d 1323 enforce_access (CP_DECL_CONTEXT(id), id);
50714e79 1324 if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
5566b478 1325 id = DECL_INITIAL (id);
8d08fdba
MS
1326 }
1327 else
5566b478
MS
1328 id = hack_identifier (id, token);
1329
ed44da02
MM
1330 /* We must look up dependent names when the template is
1331 instantiated, not while parsing it. For now, we don't
1332 distinguish between dependent and independent names. So, for
1333 example, we look up all overloaded functions at
1334 instantiation-time, even though in some cases we should just use
1335 the DECL we have here. We also use LOOKUP_EXPRs to find things
c0a483c7 1336 like local variables, rather than creating TEMPLATE_DECLs for the
ed44da02 1337 local variables and then finding matching instantiations. */
672476cb 1338 if (current_template_parms
5362b086
EC
1339 && (is_overloaded_fn (id)
1340 || (TREE_CODE (id) == VAR_DECL
ed44da02
MM
1341 && CP_DECL_CONTEXT (id)
1342 && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL)
672476cb 1343 || TREE_CODE (id) == PARM_DECL
c6882a35 1344 || TREE_CODE (id) == RESULT_DECL
672476cb
MM
1345 || TREE_CODE (id) == USING_DECL))
1346 id = build_min_nt (LOOKUP_EXPR, token);
5362b086 1347
5566b478
MS
1348 return id;
1349}
1350
1351tree
1352do_scoped_id (token, parsing)
1353 tree token;
1354 int parsing;
1355{
30394414
JM
1356 tree id;
1357 /* during parsing, this is ::name. Otherwise, it is black magic. */
1358 if (parsing)
2c73f9f5 1359 {
87e3dbc9 1360 id = make_node (CPLUS_BINDING);
52c11ef6 1361 if (!qualified_lookup_using_namespace (token, global_namespace, id, 0))
2c73f9f5
ML
1362 id = NULL_TREE;
1363 else
1364 id = BINDING_VALUE (id);
5362b086 1365 }
30394414
JM
1366 else
1367 id = IDENTIFIER_GLOBAL_VALUE (token);
5566b478
MS
1368 if (parsing && yychar == YYEMPTY)
1369 yychar = yylex ();
1370 if (! id)
1371 {
5156628f 1372 if (processing_template_decl)
5566b478 1373 {
672476cb 1374 id = build_min_nt (LOOKUP_EXPR, token);
5566b478
MS
1375 LOOKUP_EXPR_GLOBAL (id) = 1;
1376 return id;
1377 }
8b27e9ef
NS
1378 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
1379 cp_error ("`::%D' undeclared (first use here)", token);
1380 id = error_mark_node;
1381 /* Prevent repeated error messages. */
1382 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
5566b478
MS
1383 }
1384 else
1385 {
1386 if (TREE_CODE (id) == ADDR_EXPR)
1387 mark_used (TREE_OPERAND (id, 0));
2c73f9f5 1388 else if (TREE_CODE (id) != OVERLOAD)
5566b478
MS
1389 mark_used (id);
1390 }
5156628f 1391 if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
5566b478
MS
1392 {
1393 /* XXX CHS - should we set TREE_USED of the constant? */
1394 id = DECL_INITIAL (id);
1395 /* This is to prevent an enum whose value is 0
1396 from being considered a null pointer constant. */
1397 id = build1 (NOP_EXPR, TREE_TYPE (id), id);
1398 TREE_CONSTANT (id) = 1;
1399 }
1400
5156628f 1401 if (processing_template_decl)
5566b478
MS
1402 {
1403 if (is_overloaded_fn (id))
1404 {
672476cb 1405 id = build_min_nt (LOOKUP_EXPR, token);
5566b478 1406 LOOKUP_EXPR_GLOBAL (id) = 1;
672476cb 1407 return id;
5566b478
MS
1408 }
1409 /* else just use the decl */
1410 }
42976354 1411 return convert_from_reference (id);
8d08fdba
MS
1412}
1413
1414tree
1415identifier_typedecl_value (node)
1416 tree node;
1417{
1418 tree t, type;
1419 type = IDENTIFIER_TYPE_VALUE (node);
1420 if (type == NULL_TREE)
1421 return NULL_TREE;
f181d4ae
MM
1422
1423 if (IDENTIFIER_BINDING (node))
1424 {
1425 t = IDENTIFIER_VALUE (node);
1426 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
1427 return t;
1428 }
1429 if (IDENTIFIER_NAMESPACE_VALUE (node))
1430 {
1431 t = IDENTIFIER_NAMESPACE_VALUE (node);
1432 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
1433 return t;
1434 }
1435
8d08fdba 1436 /* Will this one ever happen? */
d2e5ee5c
MS
1437 if (TYPE_MAIN_DECL (type))
1438 return TYPE_MAIN_DECL (type);
8d08fdba
MS
1439
1440 /* We used to do an internal error of 62 here, but instead we will
1441 handle the return of a null appropriately in the callers. */
1442 return NULL_TREE;
1443}
1444
5566b478 1445#ifdef GATHER_STATISTICS
5156628f
MS
1446/* The original for tree_node_kind is in the toplevel tree.c; changes there
1447 need to be brought into here, unless this were actually put into a header
1448 instead. */
1449/* Statistics-gathering stuff. */
1450typedef enum
1451{
1452 d_kind,
1453 t_kind,
1454 b_kind,
1455 s_kind,
1456 r_kind,
1457 e_kind,
1458 c_kind,
1459 id_kind,
1460 op_id_kind,
1461 perm_list_kind,
1462 temp_list_kind,
1463 vec_kind,
1464 x_kind,
1465 lang_decl,
1466 lang_type,
1467 all_kinds
1468} tree_node_kind;
1469
8d08fdba
MS
1470extern int tree_node_counts[];
1471extern int tree_node_sizes[];
5566b478 1472#endif
8d08fdba 1473
8d08fdba
MS
1474tree
1475build_lang_decl (code, name, type)
1476 enum tree_code code;
1477 tree name;
1478 tree type;
1479{
4ce3d537
MM
1480 tree t;
1481
4ce3d537 1482 t = build_decl (code, name, type);
fcfcdfc8 1483 retrofit_lang_decl (t);
4ce3d537 1484
fcfcdfc8
JM
1485 return t;
1486}
1487
1488/* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
1489 and pushdecl (for functions generated by the backend). */
1490
1491void
1492retrofit_lang_decl (t)
1493 tree t;
1494{
9188c363 1495 struct lang_decl *ld;
4ce3d537 1496 size_t size;
8d08fdba 1497
4ce3d537
MM
1498 if (CAN_HAVE_FULL_LANG_DECL_P (t))
1499 size = sizeof (struct lang_decl);
1500 else
1501 size = sizeof (struct lang_decl_flags);
b0d06515 1502
f8a83ee3 1503 ld = (struct lang_decl *) ggc_alloc_cleared (size);
8d08fdba 1504
9188c363 1505 DECL_LANG_SPECIFIC (t) = ld;
8d08fdba 1506 if (current_lang_name == lang_name_cplusplus)
5d2ed28c 1507 SET_DECL_LANGUAGE (t, lang_cplusplus);
8d08fdba 1508 else if (current_lang_name == lang_name_c)
5d2ed28c 1509 SET_DECL_LANGUAGE (t, lang_c);
a1774733 1510 else if (current_lang_name == lang_name_java)
5d2ed28c 1511 SET_DECL_LANGUAGE (t, lang_java);
8d08fdba
MS
1512 else my_friendly_abort (64);
1513
8d08fdba
MS
1514#ifdef GATHER_STATISTICS
1515 tree_node_counts[(int)lang_decl] += 1;
4ce3d537 1516 tree_node_sizes[(int)lang_decl] += size;
8d08fdba 1517#endif
8d08fdba
MS
1518}
1519
8d08fdba
MS
1520void
1521copy_lang_decl (node)
1522 tree node;
1523{
1524 int size;
d60f72ae 1525 struct lang_decl *ld;
8d08fdba 1526
5566b478
MS
1527 if (! DECL_LANG_SPECIFIC (node))
1528 return;
1529
b0d06515 1530 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
8d08fdba
MS
1531 size = sizeof (struct lang_decl_flags);
1532 else
1533 size = sizeof (struct lang_decl);
d60f72ae 1534 ld = (struct lang_decl *) ggc_alloc (size);
4e135bdd 1535 memcpy (ld, DECL_LANG_SPECIFIC (node), size);
d60f72ae 1536 DECL_LANG_SPECIFIC (node) = ld;
11e74ea6
KL
1537
1538#ifdef GATHER_STATISTICS
1539 tree_node_counts[(int)lang_decl] += 1;
1540 tree_node_sizes[(int)lang_decl] += size;
1541#endif
8d08fdba
MS
1542}
1543
0acf7199
MM
1544/* Copy DECL, including any language-specific parts. */
1545
1546tree
1547copy_decl (decl)
1548 tree decl;
1549{
1550 tree copy;
1551
1552 copy = copy_node (decl);
1553 copy_lang_decl (copy);
1554 return copy;
1555}
1556
11e74ea6
KL
1557/* Replace the shared language-specific parts of NODE with a new copy. */
1558
76648a8b 1559static void
11e74ea6
KL
1560copy_lang_type (node)
1561 tree node;
1562{
1563 int size;
1564 struct lang_type *lt;
1565
1566 if (! TYPE_LANG_SPECIFIC (node))
1567 return;
1568
1569 size = sizeof (struct lang_type);
1570 lt = (struct lang_type *) ggc_alloc (size);
1571 memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
1572 TYPE_LANG_SPECIFIC (node) = lt;
1573
1574#ifdef GATHER_STATISTICS
1575 tree_node_counts[(int)lang_type] += 1;
1576 tree_node_sizes[(int)lang_type] += size;
1577#endif
1578}
1579
1580/* Copy TYPE, including any language-specific parts. */
1581
1582tree
1583copy_type (type)
1584 tree type;
1585{
1586 tree copy;
1587
1588 copy = copy_node (type);
1589 copy_lang_type (copy);
1590 return copy;
1591}
1592
8d08fdba 1593tree
266f2faa 1594cp_make_lang_type (code)
8d08fdba
MS
1595 enum tree_code code;
1596{
8d08fdba 1597 register tree t = make_node (code);
8d08fdba 1598
11e74ea6
KL
1599 /* Create lang_type structure. */
1600 if (IS_AGGR_TYPE_CODE (code)
1601 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
7ddedda4 1602 {
32201ce4
AS
1603 struct lang_type *pi;
1604
5362b086 1605 pi = ((struct lang_type *)
f15b9af9 1606 ggc_alloc_cleared (sizeof (struct lang_type)));
8d08fdba 1607
32201ce4 1608 TYPE_LANG_SPECIFIC (t) = pi;
11e74ea6
KL
1609
1610#ifdef GATHER_STATISTICS
1611 tree_node_counts[(int)lang_type] += 1;
1612 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
1613#endif
1614 }
1615
1616 /* Set up some flags that give proper default behavior. */
1617 if (IS_AGGR_TYPE_CODE (code))
1618 {
7ddedda4
MM
1619 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
1620 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
8d08fdba 1621
7ddedda4
MM
1622 /* Make sure this is laid out, for ease of use later. In the
1623 presence of parse errors, the normal was of assuring this
1624 might not ever get executed, so we lay it out *immediately*. */
1625 build_pointer_type (t);
7ddedda4
MM
1626 }
1627 else
1628 /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
1629 TYPE_ALIAS_SET is initialized to -1 by default, so we must
1630 clear it here. */
1631 TYPE_ALIAS_SET (t) = 0;
8d08fdba 1632
807625cf 1633 /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
f6a7cfd2
MM
1634 since they can be virtual base types, and we then need a
1635 canonical binfo for them. Ideally, this would be done lazily for
1636 all types. */
11e74ea6
KL
1637 if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM
1638 || code == BOUND_TEMPLATE_TEMPLATE_PARM
1639 || code == TYPENAME_TYPE)
fed3cef0 1640 TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
f6a7cfd2 1641
8d08fdba
MS
1642 return t;
1643}
1644
33848bb0
RH
1645tree
1646make_aggr_type (code)
1647 enum tree_code code;
1648{
1649 tree t = cp_make_lang_type (code);
1650
1651 if (IS_AGGR_TYPE_CODE (code))
1652 SET_IS_AGGR_TYPE (t, 1);
1653
1654 return t;
1655}
1656
8d08fdba 1657void
158991b7 1658compiler_error VPARAMS ((const char *msg, ...))
8d08fdba
MS
1659{
1660 char buf[1024];
5362b086 1661
7a75edb7
AJ
1662 VA_OPEN (ap, msg);
1663 VA_FIXEDARG (ap, const char *, msg);
d8e178a0
KG
1664
1665 vsprintf (buf, msg, ap);
7a75edb7
AJ
1666 VA_CLOSE (ap);
1667
8d08fdba
MS
1668 error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
1669}
0e5921e8 1670
91063b51
MM
1671/* Return the type-qualifier corresponding to the identifier given by
1672 RID. */
1673
1674int
1675cp_type_qual_from_rid (rid)
1676 tree rid;
1677{
1678 if (rid == ridpointers[(int) RID_CONST])
1679 return TYPE_QUAL_CONST;
1680 else if (rid == ridpointers[(int) RID_VOLATILE])
1681 return TYPE_QUAL_VOLATILE;
1682 else if (rid == ridpointers[(int) RID_RESTRICT])
1683 return TYPE_QUAL_RESTRICT;
1684
1685 my_friendly_abort (0);
1686 return TYPE_UNQUALIFIED;
1687}
This page took 1.152355 seconds and 5 git commands to generate.