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