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