]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/lex.c
invoke.texi: Remove documentation for -fsquangle and -fname-mangling-version.
[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 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 "lex.h"
34 #include "cp-tree.h"
35 #include "parse.h"
36 #include "flags.h"
37 #include "obstack.h"
38 #include "c-pragma.h"
39 #include "toplev.h"
40 #include "output.h"
41 #include "ggc.h"
42 #include "tm_p.h"
43 #include "timevar.h"
44 #include "diagnostic.h"
45
46 #ifdef MULTIBYTE_CHARS
47 #include "mbchar.h"
48 #include <locale.h>
49 #endif
50
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
53
54 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
55
56 static tree get_time_identifier PARAMS ((const char *));
57 static int check_newline PARAMS ((void));
58 static int whitespace_cr PARAMS ((int));
59 static int skip_white_space PARAMS ((int));
60 static void finish_defarg PARAMS ((void));
61 static int interface_strcmp PARAMS ((const char *));
62 static int readescape PARAMS ((int *));
63 static char *extend_token_buffer PARAMS ((const char *));
64 static void consume_string PARAMS ((struct obstack *, int));
65 static void feed_defarg PARAMS ((tree, tree));
66 static void store_pending_inline PARAMS ((tree, struct pending_inline *));
67 static void reinit_parse_for_expr PARAMS ((struct obstack *));
68 static int *init_cpp_parse PARAMS ((void));
69 static void cp_pragma_interface PARAMS ((const char *));
70 static void cp_pragma_implementation PARAMS ((const char *));
71 static int handle_cp_pragma PARAMS ((const char *));
72 #ifdef HANDLE_GENERIC_PRAGMAS
73 static int handle_generic_pragma PARAMS ((int));
74 #endif
75 #ifdef GATHER_STATISTICS
76 #ifdef REDUCE_LENGTH
77 static int reduce_cmp PARAMS ((int *, int *));
78 static int token_cmp PARAMS ((int *, int *));
79 #endif
80 #endif
81 static void begin_definition_of_inclass_inline PARAMS ((struct pending_inline*));
82 static void parse_float PARAMS ((PTR));
83 static int is_global PARAMS ((tree));
84 static void init_filename_times PARAMS ((void));
85 static void extend_token_buffer_to PARAMS ((int));
86 #ifdef HANDLE_PRAGMA
87 static int pragma_getc PARAMS ((void));
88 static void pragma_ungetc PARAMS ((int));
89 #endif
90 static int read_line_number PARAMS ((int *));
91 static int token_getch PARAMS ((void));
92 static void token_put_back PARAMS ((int));
93 static void mark_impl_file_chain PARAMS ((void *));
94 static int read_ucs PARAMS ((int));
95 static int is_extended_char PARAMS ((int));
96 static int is_extended_char_1 PARAMS ((int));
97 static void init_operators PARAMS ((void));
98
99 /* Given a file name X, return the nondirectory portion.
100 Keep in mind that X can be computed more than once. */
101 char *
102 file_name_nondirectory (x)
103 const char *x;
104 {
105 char *tmp = (char *) rindex (x, '/');
106 if (DIR_SEPARATOR != '/' && ! tmp)
107 tmp = (char *) rindex (x, DIR_SEPARATOR);
108 if (tmp)
109 return (char *) (tmp + 1);
110 else
111 return (char *) x;
112 }
113
114 /* This obstack is needed to hold text. It is not safe to use
115 TOKEN_BUFFER because `check_newline' calls `yylex'. */
116 struct obstack inline_text_obstack;
117 char *inline_text_firstobj;
118
119 /* Nonzero if parse output is being saved to an obstack for later parsing. */
120 static int saving_parse_to_obstack = 0;
121
122 #if USE_CPPLIB
123 #include "cpplib.h"
124 extern cpp_reader parse_in;
125 extern cpp_options parse_options;
126 extern unsigned char *yy_cur, *yy_lim;
127 extern enum cpp_token cpp_token;
128 #else
129 FILE *finput;
130 #endif
131 int end_of_file;
132
133 int linemode;
134
135 /* Pending language change.
136 Positive is push count, negative is pop count. */
137 int pending_lang_change = 0;
138
139 /* Wrap the current header file in extern "C". */
140 static int c_header_level = 0;
141
142 extern int first_token;
143 extern struct obstack token_obstack;
144
145 /* ??? Don't really know where this goes yet. */
146 #include "input.c"
147
148 \f
149 extern int yychar; /* the lookahead symbol */
150 extern YYSTYPE yylval; /* the semantic value of the */
151 /* lookahead symbol */
152
153 #if 0
154 YYLTYPE yylloc; /* location data for the lookahead */
155 /* symbol */
156 #endif
157
158
159 /* the declaration found for the last IDENTIFIER token read in.
160 yylex must look this up to detect typedefs, which get token type TYPENAME,
161 so it is left around in case the identifier is not a typedef but is
162 used in a context which makes it a reference to a variable. */
163 tree lastiddecl;
164
165 /* The elements of `ridpointers' are identifier nodes
166 for the reserved type names and storage classes.
167 It is indexed by a RID_... value. */
168 tree ridpointers[(int) RID_MAX];
169
170 /* We may keep statistics about how long which files took to compile. */
171 static int header_time, body_time;
172 static tree filename_times;
173 static tree this_filename_time;
174
175 /* Array for holding counts of the numbers of tokens seen. */
176 extern int *token_count;
177
178 /* When we see a default argument in a method declaration, we snarf it as
179 text using snarf_defarg. When we get up to namespace scope, we then go
180 through and parse all of them using do_pending_defargs. Since yacc
181 parsers are not reentrant, we retain defargs state in these two
182 variables so that subsequent calls to do_pending_defargs can resume
183 where the previous call left off. */
184
185 static tree defarg_fns;
186 static tree defarg_parm;
187
188 /* Functions and data structures for #pragma interface.
189
190 `#pragma implementation' means that the main file being compiled
191 is considered to implement (provide) the classes that appear in
192 its main body. I.e., if this is file "foo.cc", and class `bar'
193 is defined in "foo.cc", then we say that "foo.cc implements bar".
194
195 All main input files "implement" themselves automagically.
196
197 `#pragma interface' means that unless this file (of the form "foo.h"
198 is not presently being included by file "foo.cc", the
199 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
200 of the vtables nor any of the inline functions defined in foo.h
201 will ever be output.
202
203 There are cases when we want to link files such as "defs.h" and
204 "main.cc". In this case, we give "defs.h" a `#pragma interface',
205 and "main.cc" has `#pragma implementation "defs.h"'. */
206
207 struct impl_files
208 {
209 char *filename;
210 struct impl_files *next;
211 };
212
213 static struct impl_files *impl_file_chain;
214
215 /* The string used to represent the filename of internally generated
216 tree nodes. The variable, which is dynamically allocated, should
217 be used; the macro is only used to initialize it. */
218 static char *internal_filename;
219 #define INTERNAL_FILENAME ("<internal>")
220 \f
221 /* Return something to represent absolute declarators containing a *.
222 TARGET is the absolute declarator that the * contains.
223 CV_QUALIFIERS is a list of modifiers such as const or volatile
224 to apply to the pointer type, represented as identifiers.
225
226 We return an INDIRECT_REF whose "contents" are TARGET
227 and whose type is the modifier list. */
228
229 tree
230 make_pointer_declarator (cv_qualifiers, target)
231 tree cv_qualifiers, target;
232 {
233 if (target && TREE_CODE (target) == IDENTIFIER_NODE
234 && ANON_AGGRNAME_P (target))
235 error ("type name expected before `*'");
236 target = build_parse_node (INDIRECT_REF, target);
237 TREE_TYPE (target) = cv_qualifiers;
238 return target;
239 }
240
241 /* Return something to represent absolute declarators containing a &.
242 TARGET is the absolute declarator that the & contains.
243 CV_QUALIFIERS is a list of modifiers such as const or volatile
244 to apply to the reference type, represented as identifiers.
245
246 We return an ADDR_EXPR whose "contents" are TARGET
247 and whose type is the modifier list. */
248
249 tree
250 make_reference_declarator (cv_qualifiers, target)
251 tree cv_qualifiers, target;
252 {
253 if (target)
254 {
255 if (TREE_CODE (target) == ADDR_EXPR)
256 {
257 error ("cannot declare references to references");
258 return target;
259 }
260 if (TREE_CODE (target) == INDIRECT_REF)
261 {
262 error ("cannot declare pointers to references");
263 return target;
264 }
265 if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
266 error ("type name expected before `&'");
267 }
268 target = build_parse_node (ADDR_EXPR, target);
269 TREE_TYPE (target) = cv_qualifiers;
270 return target;
271 }
272
273 tree
274 make_call_declarator (target, parms, cv_qualifiers, exception_specification)
275 tree target, parms, cv_qualifiers, exception_specification;
276 {
277 target = build_parse_node (CALL_EXPR, target,
278 /* Both build_parse_node and
279 decl_tree_cons build on the
280 temp_decl_obstack. */
281 decl_tree_cons (parms, cv_qualifiers, NULL_TREE),
282 /* The third operand is really RTL. We
283 shouldn't put anything there. */
284 NULL_TREE);
285 CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
286 return target;
287 }
288
289 void
290 set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
291 tree call_declarator, cv_qualifiers, exception_specification;
292 {
293 CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
294 CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
295 }
296 \f
297 int interface_only; /* whether or not current file is only for
298 interface definitions. */
299 int interface_unknown; /* whether or not we know this class
300 to behave according to #pragma interface. */
301
302 /* lexical analyzer */
303
304 #undef WCHAR_TYPE_SIZE
305 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
306
307 /* Number of bytes in a wide character. */
308 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
309
310 static int maxtoken; /* Current nominal length of token buffer. */
311 char *token_buffer; /* Pointer to token buffer.
312 Actual allocated length is maxtoken + 2. */
313
314 static int indent_level; /* Number of { minus number of }. */
315
316 #include "hash.h"
317 \f
318
319 /* Nonzero tells yylex to ignore \ in string constants. */
320 static int ignore_escape_flag;
321
322 static tree
323 get_time_identifier (name)
324 const char *name;
325 {
326 tree time_identifier;
327 int len = strlen (name);
328 char *buf = (char *) alloca (len + 6);
329 strcpy (buf, "file ");
330 bcopy (name, buf+5, len);
331 buf[len+5] = '\0';
332 time_identifier = get_identifier (buf);
333 if (TIME_IDENTIFIER_TIME (time_identifier) == NULL_TREE)
334 {
335 TIME_IDENTIFIER_TIME (time_identifier) = build_int_2 (0, 0);
336 TIME_IDENTIFIER_FILEINFO (time_identifier)
337 = build_int_2 (0, 1);
338 SET_IDENTIFIER_GLOBAL_VALUE (time_identifier, filename_times);
339 filename_times = time_identifier;
340 }
341 return time_identifier;
342 }
343 \f
344 /* Table indexed by tree code giving a string containing a character
345 classifying the tree code. Possibilities are
346 t, d, s, c, r, <, 1 and 2. See cp/cp-tree.def for details. */
347
348 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
349
350 static char cplus_tree_code_type[] = {
351 'x',
352 #include "cp-tree.def"
353 };
354 #undef DEFTREECODE
355
356 /* Table indexed by tree code giving number of expression
357 operands beyond the fixed part of the node structure.
358 Not used for types or decls. */
359
360 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
361
362 static int cplus_tree_code_length[] = {
363 0,
364 #include "cp-tree.def"
365 };
366 #undef DEFTREECODE
367
368 /* Names of tree components.
369 Used for printing out the tree and error messages. */
370 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
371
372 static const char *cplus_tree_code_name[] = {
373 "@@dummy",
374 #include "cp-tree.def"
375 };
376 #undef DEFTREECODE
377 \f
378 /* toplev.c needs to call these. */
379
380 void
381 lang_init_options ()
382 {
383 #if USE_CPPLIB
384 cpp_reader_init (&parse_in);
385 parse_in.opts = &parse_options;
386 cpp_options_init (&parse_options);
387 parse_options.cplusplus = 1;
388 #endif
389
390 /* Default exceptions on. */
391 flag_exceptions = 1;
392 /* Mark as "unspecified". */
393 flag_bounds_check = -1;
394 /* By default wrap lines at 72 characters. */
395 diagnostic_message_length_per_line = 72;
396 /* By default, emit location information once for every
397 diagnostic message. */
398 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
399 }
400
401 void
402 lang_init ()
403 {
404 /* If still "unspecified", make it match -fbounded-pointers. */
405 if (flag_bounds_check < 0)
406 flag_bounds_check = flag_bounded_pointers;
407
408 /* the beginning of the file is a new line; check for # */
409 /* With luck, we discover the real source file's name from that
410 and put it in input_filename. */
411 put_back (check_newline ());
412 if (flag_gnu_xref) GNU_xref_begin (input_filename);
413 init_repo (input_filename);
414 }
415
416 void
417 lang_finish ()
418 {
419 if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount);
420 }
421
422 const char *
423 lang_identify ()
424 {
425 return "cplusplus";
426 }
427
428 static void
429 init_filename_times ()
430 {
431 this_filename_time = get_time_identifier ("<top level>");
432 if (flag_detailed_statistics)
433 {
434 header_time = 0;
435 body_time = get_run_time ();
436 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
437 = body_time;
438 }
439 }
440
441 static int *
442 init_cpp_parse ()
443 {
444 #ifdef GATHER_STATISTICS
445 #ifdef REDUCE_LENGTH
446 reduce_count = (int *) xcalloc (sizeof (int), (REDUCE_LENGTH + 1));
447 reduce_count += 1;
448 token_count = (int *) xcalloc (sizeof (int), (TOKEN_LENGTH + 1));
449 token_count += 1;
450 #endif
451 #endif
452 return token_count;
453 }
454
455 /* A mapping from tree codes to operator name information. */
456 operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
457 /* Similar, but for assignment operators. */
458 operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
459
460 /* Initialize data structures that keep track of operator names. */
461
462 static void
463 init_operators ()
464 {
465 tree identifier;
466 char buffer[256];
467 struct operator_name_info_t *oni;
468
469 #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \
470 my_friendly_assert ((strlen ("operator ") + strlen (NAME) + 1 \
471 <= 256), \
472 20000526); \
473 sprintf (buffer, "operator %s", NAME); \
474 identifier = get_identifier (buffer); \
475 IDENTIFIER_OPNAME_P (identifier) = 1; \
476 \
477 oni = (ASSN_P \
478 ? &assignment_operator_name_info[(int) CODE] \
479 : &operator_name_info[(int) CODE]); \
480 oni->identifier = identifier; \
481 oni->name = NAME; \
482 oni->mangled_name = MANGLING;
483
484 #include "operators.def"
485 #undef DEF_OPERATOR
486
487 operator_name_info[(int) ERROR_MARK].identifier
488 = get_identifier ("<invalid operator>");
489
490 /* Handle some special cases. These operators are not defined in
491 the language, but can be produced internally. We may need them
492 for error-reporting. (Eventually, we should ensure that this
493 does not happen. Error messages involving these operators will
494 be confusing to users.) */
495
496 operator_name_info [(int) INIT_EXPR].name
497 = operator_name_info [(int) MODIFY_EXPR].name;
498 operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)";
499 operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)";
500 operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)";
501 operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)";
502 operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)";
503 operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
504 operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
505 operator_name_info [(int) ABS_EXPR].name = "abs";
506 operator_name_info [(int) FFS_EXPR].name = "ffs";
507 operator_name_info [(int) BIT_ANDTC_EXPR].name = "&~";
508 operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
509 operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
510 operator_name_info [(int) IN_EXPR].name = "in";
511 operator_name_info [(int) RANGE_EXPR].name = "...";
512 operator_name_info [(int) CONVERT_EXPR].name = "+";
513
514 assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
515 = "(exact /=)";
516 assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
517 = "(ceiling /=)";
518 assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
519 = "(floor /=)";
520 assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
521 = "(round /=)";
522 assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
523 = "(ceiling %=)";
524 assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
525 = "(floor %=)";
526 assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
527 = "(round %=)";
528 }
529
530 const char *
531 init_parse (filename)
532 const char *filename;
533 {
534 extern int flag_no_gnu_keywords;
535 extern int flag_operator_names;
536
537 #ifdef MULTIBYTE_CHARS
538 /* Change to the native locale for multibyte conversions. */
539 setlocale (LC_CTYPE, "");
540 literal_codeset = getenv ("LANG");
541 #endif
542
543 #if !USE_CPPLIB
544 /* Open input file. */
545 if (filename == 0 || !strcmp (filename, "-"))
546 {
547 finput = stdin;
548 filename = "stdin";
549 }
550 else
551 finput = fopen (filename, "r");
552 if (finput == 0)
553 pfatal_with_name (filename);
554
555 #ifdef IO_BUFFER_SIZE
556 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
557 #endif
558 #else /* !USE_CPPLIB */
559 parse_in.show_column = 1;
560 if (! cpp_start_read (&parse_in, filename))
561 abort ();
562
563 if (filename == 0 || !strcmp (filename, "-"))
564 filename = "stdin";
565
566 /* cpp_start_read always puts at least one line directive into the
567 token buffer. We must arrange to read it out here. */
568 yy_cur = parse_in.token_buffer;
569 yy_lim = CPP_PWRITTEN (&parse_in);
570 cpp_token = CPP_DIRECTIVE;
571
572 #endif /* !USE_CPPLIB */
573
574 /* Initialize the lookahead machinery. */
575 init_spew ();
576
577 /* Make identifier nodes long enough for the language-specific slots. */
578 set_identifier_size (sizeof (struct lang_identifier));
579 decl_printable_name = lang_printable_name;
580
581 init_tree ();
582 init_cplus_expand ();
583
584 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
585 cplus_tree_code_type,
586 (int)LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
587 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
588 cplus_tree_code_length,
589 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
590 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
591 cplus_tree_code_name,
592 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
593
594 init_operators ();
595 init_mangle ();
596 init_error ();
597 gcc_obstack_init (&inline_text_obstack);
598 inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
599
600 internal_filename = ggc_alloc_string (INTERNAL_FILENAME,
601 sizeof (INTERNAL_FILENAME));
602
603 /* Start it at 0, because check_newline is called at the very beginning
604 and will increment it to 1. */
605 lineno = 0;
606 input_filename = internal_filename;
607 current_function_decl = NULL;
608
609 maxtoken = 40;
610 token_buffer = (char *) xmalloc (maxtoken + 2);
611
612 ridpointers[(int) RID_INT] = get_identifier ("int");
613 ridpointers[(int) RID_BOOL] = get_identifier ("bool");
614 ridpointers[(int) RID_CHAR] = get_identifier ("char");
615 ridpointers[(int) RID_VOID] = get_identifier ("void");
616 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
617 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
618 ridpointers[(int) RID_SHORT] = get_identifier ("short");
619 ridpointers[(int) RID_LONG] = get_identifier ("long");
620 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
621 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
622 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
623 ridpointers[(int) RID_CONST] = get_identifier ("const");
624 ridpointers[(int) RID_RESTRICT] = get_identifier ("__restrict");
625 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
626 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
627 ridpointers[(int) RID_STATIC] = get_identifier ("static");
628 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
629 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
630 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
631 ridpointers[(int) RID_COMPLEX] = get_identifier ("__complex");
632
633 /* C++ extensions. These are probably not correctly named. */
634 ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t");
635 class_type_node = build_int_2 (class_type, 0);
636 TREE_TYPE (class_type_node) = class_type_node;
637 ridpointers[(int) RID_CLASS] = class_type_node;
638
639 record_type_node = build_int_2 (record_type, 0);
640 TREE_TYPE (record_type_node) = record_type_node;
641 ridpointers[(int) RID_RECORD] = record_type_node;
642
643 union_type_node = build_int_2 (union_type, 0);
644 TREE_TYPE (union_type_node) = union_type_node;
645 ridpointers[(int) RID_UNION] = union_type_node;
646
647 enum_type_node = build_int_2 (enum_type, 0);
648 TREE_TYPE (enum_type_node) = enum_type_node;
649 ridpointers[(int) RID_ENUM] = enum_type_node;
650
651 ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual");
652 ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit");
653 ridpointers[(int) RID_EXPORT] = get_identifier ("export");
654 ridpointers[(int) RID_FRIEND] = get_identifier ("friend");
655
656 ridpointers[(int) RID_PUBLIC] = get_identifier ("public");
657 ridpointers[(int) RID_PRIVATE] = get_identifier ("private");
658 ridpointers[(int) RID_PROTECTED] = get_identifier ("protected");
659 ridpointers[(int) RID_TEMPLATE] = get_identifier ("template");
660 /* This is for ANSI C++. */
661 ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable");
662
663 /* Create the built-in __null node. Note that we can't yet call for
664 type_for_size here because integer_type_node and so forth are not
665 set up. Therefore, we don't set the type of these nodes until
666 init_decl_processing. */
667 null_node = build_int_2 (0, 0);
668 ridpointers[RID_NULL] = null_node;
669
670 init_filename_times ();
671
672 /* Some options inhibit certain reserved words.
673 Clear those words out of the hash table so they won't be recognized. */
674 #define UNSET_RESERVED_WORD(STRING) \
675 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
676 if (s) s->name = ""; } while (0)
677
678 #if 0
679 /* let's parse things, and if they use it, then give them an error. */
680 if (!flag_exceptions)
681 {
682 UNSET_RESERVED_WORD ("throw");
683 UNSET_RESERVED_WORD ("try");
684 UNSET_RESERVED_WORD ("catch");
685 }
686 #endif
687
688 if (flag_no_asm || flag_no_gnu_keywords)
689 UNSET_RESERVED_WORD ("typeof");
690 if (! flag_operator_names)
691 {
692 /* These are new ANSI keywords that may break code. */
693 UNSET_RESERVED_WORD ("and");
694 UNSET_RESERVED_WORD ("and_eq");
695 UNSET_RESERVED_WORD ("bitand");
696 UNSET_RESERVED_WORD ("bitor");
697 UNSET_RESERVED_WORD ("compl");
698 UNSET_RESERVED_WORD ("not");
699 UNSET_RESERVED_WORD ("not_eq");
700 UNSET_RESERVED_WORD ("or");
701 UNSET_RESERVED_WORD ("or_eq");
702 UNSET_RESERVED_WORD ("xor");
703 UNSET_RESERVED_WORD ("xor_eq");
704 }
705
706 token_count = init_cpp_parse ();
707 interface_unknown = 1;
708
709 ggc_add_string_root (&internal_filename, 1);
710 ggc_add_tree_root (ridpointers, RID_MAX);
711 ggc_add_tree_root (&defarg_fns, 1);
712 ggc_add_tree_root (&defarg_parm, 1);
713 ggc_add_tree_root (&this_filename_time, 1);
714 ggc_add_tree_root (&filename_times, 1);
715 ggc_add_root (&impl_file_chain, 1, sizeof (impl_file_chain),
716 mark_impl_file_chain);
717 return filename;
718 }
719
720 void
721 finish_parse ()
722 {
723 #if USE_CPPLIB
724 cpp_finish (&parse_in);
725 errorcount += parse_in.errors;
726 #else
727 fclose (finput);
728 #endif
729 }
730
731 void
732 reinit_parse_for_function ()
733 {
734 current_base_init_list = NULL_TREE;
735 current_member_init_list = NULL_TREE;
736 }
737 \f
738 inline void
739 yyprint (file, yychar, yylval)
740 FILE *file;
741 int yychar;
742 YYSTYPE yylval;
743 {
744 tree t;
745 switch (yychar)
746 {
747 case IDENTIFIER:
748 case TYPENAME:
749 case TYPESPEC:
750 case PTYPENAME:
751 case PFUNCNAME:
752 case IDENTIFIER_DEFN:
753 case TYPENAME_DEFN:
754 case PTYPENAME_DEFN:
755 case SCSPEC:
756 case PRE_PARSED_CLASS_DECL:
757 t = yylval.ttype;
758 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL)
759 {
760 fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t)));
761 break;
762 }
763 my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
764 if (IDENTIFIER_POINTER (t))
765 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
766 break;
767
768 case AGGR:
769 if (yylval.ttype == class_type_node)
770 fprintf (file, " `class'");
771 else if (yylval.ttype == record_type_node)
772 fprintf (file, " `struct'");
773 else if (yylval.ttype == union_type_node)
774 fprintf (file, " `union'");
775 else if (yylval.ttype == enum_type_node)
776 fprintf (file, " `enum'");
777 else
778 my_friendly_abort (80);
779 break;
780
781 case CONSTANT:
782 t = yylval.ttype;
783 if (TREE_CODE (t) == INTEGER_CST)
784 fprintf (file,
785 #if HOST_BITS_PER_WIDE_INT == 64
786 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
787 " 0x%x%016x",
788 #else
789 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
790 " 0x%lx%016lx",
791 #else
792 " 0x%llx%016llx",
793 #endif
794 #endif
795 #else
796 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
797 " 0x%lx%08lx",
798 #else
799 " 0x%x%08x",
800 #endif
801 #endif
802 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
803 break;
804 }
805 }
806
807 #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
808 static int *reduce_count;
809 #endif
810
811 int *token_count;
812
813 #if 0
814 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
815 #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
816 #endif
817
818 #ifdef GATHER_STATISTICS
819 #ifdef REDUCE_LENGTH
820 void
821 yyhook (yyn)
822 int yyn;
823 {
824 reduce_count[yyn] += 1;
825 }
826
827 static int
828 reduce_cmp (p, q)
829 int *p, *q;
830 {
831 return reduce_count[*q] - reduce_count[*p];
832 }
833
834 static int
835 token_cmp (p, q)
836 int *p, *q;
837 {
838 return token_count[*q] - token_count[*p];
839 }
840 #endif
841 #endif
842
843 void
844 print_parse_statistics ()
845 {
846 #ifdef GATHER_STATISTICS
847 #ifdef REDUCE_LENGTH
848 #if YYDEBUG != 0
849 int i;
850 int maxlen = REDUCE_LENGTH;
851 unsigned *sorted;
852
853 if (reduce_count[-1] == 0)
854 return;
855
856 if (TOKEN_LENGTH > REDUCE_LENGTH)
857 maxlen = TOKEN_LENGTH;
858 sorted = (unsigned *) alloca (sizeof (int) * maxlen);
859
860 for (i = 0; i < TOKEN_LENGTH; i++)
861 sorted[i] = i;
862 qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
863 for (i = 0; i < TOKEN_LENGTH; i++)
864 {
865 int idx = sorted[i];
866 if (token_count[idx] == 0)
867 break;
868 if (token_count[idx] < token_count[-1])
869 break;
870 fprintf (stderr, "token %d, `%s', count = %d\n",
871 idx, yytname[YYTRANSLATE (idx)], token_count[idx]);
872 }
873 fprintf (stderr, "\n");
874 for (i = 0; i < REDUCE_LENGTH; i++)
875 sorted[i] = i;
876 qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
877 for (i = 0; i < REDUCE_LENGTH; i++)
878 {
879 int idx = sorted[i];
880 if (reduce_count[idx] == 0)
881 break;
882 if (reduce_count[idx] < reduce_count[-1])
883 break;
884 fprintf (stderr, "rule %d, line %d, count = %d\n",
885 idx, yyrline[idx], reduce_count[idx]);
886 }
887 fprintf (stderr, "\n");
888 #endif
889 #endif
890 #endif
891 }
892
893 /* Sets the value of the 'yydebug' variable to VALUE.
894 This is a function so we don't have to have YYDEBUG defined
895 in order to build the compiler. */
896
897 void
898 set_yydebug (value)
899 int value;
900 {
901 #if YYDEBUG != 0
902 extern int yydebug;
903 yydebug = value;
904 #else
905 warning ("YYDEBUG not defined.");
906 #endif
907 }
908
909 \f
910 /* Mark ARG (which is really a struct impl_files **) for GC. */
911
912 static void
913 mark_impl_file_chain (arg)
914 void *arg;
915 {
916 struct impl_files *ifs;
917
918 ifs = *(struct impl_files **) arg;
919 while (ifs)
920 {
921 ggc_mark_string (ifs->filename);
922 ifs = ifs->next;
923 }
924 }
925
926 /* Helper function to load global variables with interface
927 information. */
928
929 void
930 extract_interface_info ()
931 {
932 tree fileinfo = 0;
933
934 if (flag_alt_external_templates)
935 {
936 tree til = tinst_for_decl ();
937
938 if (til)
939 fileinfo = get_time_identifier (TINST_FILE (til));
940 }
941 if (!fileinfo)
942 fileinfo = get_time_identifier (input_filename);
943 fileinfo = TIME_IDENTIFIER_FILEINFO (fileinfo);
944 interface_only = TREE_INT_CST_LOW (fileinfo);
945 interface_unknown = TREE_INT_CST_HIGH (fileinfo);
946 }
947
948 /* Return nonzero if S is not considered part of an
949 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
950
951 static int
952 interface_strcmp (s)
953 const char *s;
954 {
955 /* Set the interface/implementation bits for this scope. */
956 struct impl_files *ifiles;
957 const char *s1;
958
959 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
960 {
961 const char *t1 = ifiles->filename;
962 s1 = s;
963
964 if (*s1 != *t1 || *s1 == 0)
965 continue;
966
967 while (*s1 == *t1 && *s1 != 0)
968 s1++, t1++;
969
970 /* A match. */
971 if (*s1 == *t1)
972 return 0;
973
974 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
975 if (index (s1, '.') || index (t1, '.'))
976 continue;
977
978 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
979 continue;
980
981 /* A match. */
982 return 0;
983 }
984
985 /* No matches. */
986 return 1;
987 }
988
989 static void
990 cp_pragma_interface (main_filename)
991 const char *main_filename;
992 {
993 tree fileinfo
994 = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename));
995
996 if (impl_file_chain == 0)
997 {
998 /* If this is zero at this point, then we are
999 auto-implementing. */
1000 if (main_input_filename == 0)
1001 main_input_filename = input_filename;
1002
1003 #ifdef AUTO_IMPLEMENT
1004 filename = file_name_nondirectory (main_input_filename);
1005 fi = get_time_identifier (filename);
1006 fi = TIME_IDENTIFIER_FILEINFO (fi);
1007 TREE_INT_CST_LOW (fi) = 0;
1008 TREE_INT_CST_HIGH (fi) = 1;
1009 /* Get default. */
1010 impl_file_chain
1011 = (struct impl_files *) xmalloc (sizeof (struct impl_files));
1012 impl_file_chain->filename = ggc_alloc_string (filename, -1);
1013 impl_file_chain->next = 0;
1014 #endif
1015 }
1016
1017 interface_only = interface_strcmp (main_filename);
1018 #ifdef MULTIPLE_SYMBOL_SPACES
1019 if (! interface_only)
1020 interface_unknown = 0;
1021 #else /* MULTIPLE_SYMBOL_SPACES */
1022 interface_unknown = 0;
1023 #endif /* MULTIPLE_SYMBOL_SPACES */
1024 TREE_INT_CST_LOW (fileinfo) = interface_only;
1025 TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
1026 }
1027
1028 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
1029 We used to only allow this at toplevel, but that restriction was buggy
1030 in older compilers and it seems reasonable to allow it in the headers
1031 themselves, too. It only needs to precede the matching #p interface.
1032
1033 We don't touch interface_only or interface_unknown; the user must specify
1034 a matching #p interface for this to have any effect. */
1035
1036 static void
1037 cp_pragma_implementation (main_filename)
1038 const char *main_filename;
1039 {
1040 struct impl_files *ifiles = impl_file_chain;
1041 for (; ifiles; ifiles = ifiles->next)
1042 {
1043 if (! strcmp (ifiles->filename, main_filename))
1044 break;
1045 }
1046 if (ifiles == 0)
1047 {
1048 ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files));
1049 ifiles->filename = ggc_alloc_string (main_filename, -1);
1050 ifiles->next = impl_file_chain;
1051 impl_file_chain = ifiles;
1052 }
1053 }
1054 \f
1055 /* Set up the state required to correctly handle the definition of the
1056 inline function whose preparsed state has been saved in PI. */
1057
1058 static void
1059 begin_definition_of_inclass_inline (pi)
1060 struct pending_inline* pi;
1061 {
1062 tree context;
1063
1064 if (!pi->fndecl)
1065 return;
1066
1067 /* If this is an inline function in a local class, we must make sure
1068 that we save all pertinent information about the function
1069 surrounding the local class. */
1070 context = decl_function_context (pi->fndecl);
1071 if (context)
1072 push_function_context_to (context);
1073
1074 feed_input (pi->buf, pi->len, pi->filename, pi->lineno);
1075 yychar = PRE_PARSED_FUNCTION_DECL;
1076 yylval.pi = pi;
1077 /* Pass back a handle to the rest of the inline functions, so that they
1078 can be processed later. */
1079 DECL_PENDING_INLINE_INFO (pi->fndecl) = 0;
1080 DECL_PENDING_INLINE_P (pi->fndecl) = 0;
1081 interface_unknown = pi->interface == 1;
1082 interface_only = pi->interface == 0;
1083 }
1084
1085 /* Called from the top level: if there are any pending inlines to
1086 do, set up to process them now. This function sets up the first function
1087 to be parsed; after it has been, the rule for fndef in parse.y will
1088 call process_next_inline to start working on the next one. */
1089
1090 void
1091 do_pending_inlines ()
1092 {
1093 struct pending_inline *t;
1094
1095 /* Oops, we're still dealing with the last batch. */
1096 if (yychar == PRE_PARSED_FUNCTION_DECL)
1097 return;
1098
1099 /* Reverse the pending inline functions, since
1100 they were cons'd instead of appended. */
1101 {
1102 struct pending_inline *prev = 0, *tail;
1103 t = pending_inlines;
1104 pending_inlines = 0;
1105
1106 for (; t; t = tail)
1107 {
1108 tail = t->next;
1109 t->next = prev;
1110 t->deja_vu = 1;
1111 prev = t;
1112 }
1113 t = prev;
1114 }
1115
1116 if (t == 0)
1117 return;
1118
1119 /* Now start processing the first inline function. */
1120 begin_definition_of_inclass_inline (t);
1121 }
1122
1123 /* Called from the fndecl rule in the parser when the function just parsed
1124 was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1125 do_pending_inlines). */
1126
1127 void
1128 process_next_inline (i)
1129 struct pending_inline *i;
1130 {
1131 tree context;
1132 context = decl_function_context (i->fndecl);
1133 if (context)
1134 pop_function_context_from (context);
1135 i = i->next;
1136 if (yychar == YYEMPTY)
1137 yychar = yylex ();
1138 if (yychar != END_OF_SAVED_INPUT)
1139 {
1140 error ("parse error at end of saved function text");
1141
1142 /* restore_pending_input will abort unless yychar is either
1143 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1144 hosed, feed back YYEMPTY. */
1145 }
1146 yychar = YYEMPTY;
1147 end_input ();
1148 if (i)
1149 begin_definition_of_inclass_inline (i);
1150 else
1151 extract_interface_info ();
1152 }
1153
1154 /* Since inline methods can refer to text which has not yet been seen,
1155 we store the text of the method in a structure which is placed in the
1156 DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1157 After parsing the body of the class definition, the FUNCTION_DECL's are
1158 scanned to see which ones have this field set. Those are then digested
1159 one at a time.
1160
1161 This function's FUNCTION_DECL will have a bit set in its common so
1162 that we know to watch out for it. */
1163
1164 static void
1165 consume_string (this_obstack, matching_char)
1166 register struct obstack *this_obstack;
1167 int matching_char;
1168 {
1169 register int c;
1170 int starting_lineno;
1171
1172 #if USE_CPPLIB
1173 if (cpp_token == CPP_STRING)
1174 {
1175 /* The C preprocessor will warn about newlines in strings. */
1176 obstack_grow (this_obstack, yy_cur, (yy_lim - yy_cur));
1177 yy_cur = yy_lim;
1178 lineno = parse_in.lineno;
1179 return;
1180 }
1181 #endif
1182
1183 starting_lineno = lineno;
1184 do
1185 {
1186 c = getch ();
1187 if (c == EOF)
1188 {
1189 int save_lineno = lineno;
1190 lineno = starting_lineno;
1191 if (matching_char == '"')
1192 error ("end of file encountered inside string constant");
1193 else
1194 error ("end of file encountered inside character constant");
1195 lineno = save_lineno;
1196 return;
1197 }
1198 if (c == '\\')
1199 {
1200 obstack_1grow (this_obstack, c);
1201 c = getch ();
1202 obstack_1grow (this_obstack, c);
1203
1204 /* Make sure we continue the loop */
1205 c = 0;
1206 continue;
1207 }
1208 if (c == '\n')
1209 {
1210 if (pedantic)
1211 pedwarn ("ISO C++ forbids newline in string constant");
1212 lineno++;
1213 }
1214 obstack_1grow (this_obstack, c);
1215 }
1216 while (c != matching_char);
1217 }
1218
1219 struct pending_input {
1220 int yychar, eof;
1221 YYSTYPE yylval;
1222 struct obstack token_obstack;
1223 int first_token;
1224 };
1225
1226 struct pending_input *
1227 save_pending_input ()
1228 {
1229 struct pending_input *p;
1230 p = (struct pending_input *) xmalloc (sizeof (struct pending_input));
1231 p->yychar = yychar;
1232 p->yylval = yylval;
1233 p->eof = end_of_file;
1234 yychar = YYEMPTY;
1235 p->first_token = first_token;
1236 p->token_obstack = token_obstack;
1237
1238 first_token = 0;
1239 gcc_obstack_init (&token_obstack);
1240 end_of_file = 0;
1241 return p;
1242 }
1243
1244 void
1245 restore_pending_input (p)
1246 struct pending_input *p;
1247 {
1248 my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230);
1249 yychar = p->yychar;
1250 yylval = p->yylval;
1251 first_token = p->first_token;
1252 obstack_free (&token_obstack, (char *) 0);
1253 token_obstack = p->token_obstack;
1254 end_of_file = p->eof;
1255 free (p);
1256 }
1257
1258 /* Unget character CH from the input stream.
1259 If RESCAN is non-zero, then we want to `see' this
1260 character as the next input token. */
1261
1262 void
1263 yyungetc (ch, rescan)
1264 int ch;
1265 int rescan;
1266 {
1267 /* Unget a character from the input stream. */
1268 if (yychar == YYEMPTY || rescan == 0)
1269 {
1270 /* If we're putting back a brace, undo the change in indent_level
1271 from the first time we saw it. */
1272 if (ch == '{')
1273 indent_level--;
1274 else if (ch == '}')
1275 indent_level++;
1276
1277 put_back (ch);
1278 }
1279 else
1280 {
1281 yychar = ch;
1282 }
1283 }
1284
1285 void
1286 clear_inline_text_obstack ()
1287 {
1288 obstack_free (&inline_text_obstack, inline_text_firstobj);
1289 }
1290
1291 /* This function stores away the text for an inline function that should
1292 be processed later. It decides how much later, and may need to move
1293 the info between obstacks; therefore, the caller should not refer to
1294 the T parameter after calling this function. */
1295
1296 static void
1297 store_pending_inline (decl, t)
1298 tree decl;
1299 struct pending_inline *t;
1300 {
1301 t->fndecl = decl;
1302 DECL_PENDING_INLINE_INFO (decl) = t;
1303 DECL_PENDING_INLINE_P (decl) = 1;
1304
1305 /* Because we use obstacks, we must process these in precise order. */
1306 t->next = pending_inlines;
1307 pending_inlines = t;
1308 }
1309
1310 void
1311 reinit_parse_for_method (yychar, decl)
1312 int yychar;
1313 tree decl;
1314 {
1315 int len;
1316 int starting_lineno = lineno;
1317 const char *starting_filename = input_filename;
1318
1319 reinit_parse_for_block (yychar, &inline_text_obstack);
1320
1321 len = obstack_object_size (&inline_text_obstack);
1322 if (decl == void_type_node
1323 || (current_class_type && TYPE_REDEFINED (current_class_type)))
1324 {
1325 /* Happens when we get two declarations of the same
1326 function in the same scope. */
1327 char *buf = obstack_finish (&inline_text_obstack);
1328 obstack_free (&inline_text_obstack, buf);
1329 return;
1330 }
1331 else
1332 {
1333 struct pending_inline *t;
1334 char *buf = obstack_finish (&inline_text_obstack);
1335
1336 t = (struct pending_inline *) obstack_alloc (&inline_text_obstack,
1337 sizeof (struct pending_inline));
1338 t->lineno = starting_lineno;
1339 t->filename = starting_filename;
1340 t->token = YYEMPTY;
1341 t->token_value = 0;
1342 t->buf = buf;
1343 t->len = len;
1344 t->deja_vu = 0;
1345 #if 0
1346 if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
1347 warn_if_unknown_interface (decl);
1348 #endif
1349 t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2));
1350 store_pending_inline (decl, t);
1351 }
1352 }
1353
1354 /* Consume a block -- actually, a method beginning
1355 with `:' or `{' -- and save it away on the specified obstack. */
1356
1357 void
1358 reinit_parse_for_block (pyychar, obstackp)
1359 int pyychar;
1360 struct obstack *obstackp;
1361 {
1362 register int c;
1363 int blev = 1;
1364 int starting_lineno = lineno;
1365 const char *starting_filename = input_filename;
1366 int len;
1367 int look_for_semicolon = 0;
1368 int look_for_lbrac = 0;
1369
1370 if (pyychar == '{')
1371 {
1372 obstack_1grow (obstackp, '{');
1373 /* We incremented indent_level in yylex; undo that. */
1374 indent_level--;
1375 }
1376 else if (pyychar == '=')
1377 look_for_semicolon = 1;
1378 else if (pyychar == ':')
1379 {
1380 obstack_1grow (obstackp, pyychar);
1381 /* Add a space so we don't get confused by ': ::A(20)'. */
1382 obstack_1grow (obstackp, ' ');
1383 look_for_lbrac = 1;
1384 blev = 0;
1385 }
1386 else if (pyychar == RETURN_KEYWORD)
1387 {
1388 obstack_grow (obstackp, "return", 6);
1389 look_for_lbrac = 1;
1390 blev = 0;
1391 }
1392 else if (pyychar == TRY)
1393 {
1394 obstack_grow (obstackp, "try", 3);
1395 look_for_lbrac = 1;
1396 blev = 0;
1397 }
1398 else
1399 {
1400 yyerror ("parse error in method specification");
1401 obstack_1grow (obstackp, '{');
1402 }
1403
1404 c = getch ();
1405
1406 while (c != EOF)
1407 {
1408 int this_lineno = lineno;
1409
1410 saving_parse_to_obstack = 1;
1411 c = skip_white_space (c);
1412 saving_parse_to_obstack = 0;
1413
1414 /* Don't lose our cool if there are lots of comments. */
1415 if (lineno == this_lineno + 1)
1416 obstack_1grow (obstackp, '\n');
1417 else if (lineno == this_lineno)
1418 ;
1419 else if (lineno - this_lineno < 10)
1420 {
1421 int i;
1422 for (i = lineno - this_lineno; i > 0; i--)
1423 obstack_1grow (obstackp, '\n');
1424 }
1425 else
1426 {
1427 char buf[16];
1428 sprintf (buf, "\n# %d \"", lineno);
1429 len = strlen (buf);
1430 obstack_grow (obstackp, buf, len);
1431
1432 len = strlen (input_filename);
1433 obstack_grow (obstackp, input_filename, len);
1434 obstack_1grow (obstackp, '\"');
1435 obstack_1grow (obstackp, '\n');
1436 }
1437
1438 while (c > ' ') /* ASCII dependent... */
1439 {
1440 obstack_1grow (obstackp, c);
1441 if (c == '{')
1442 {
1443 look_for_lbrac = 0;
1444 blev++;
1445 }
1446 else if (c == '}')
1447 {
1448 blev--;
1449 if (blev == 0 && !look_for_semicolon)
1450 {
1451 if (pyychar == TRY)
1452 {
1453 if (peekyylex () == CATCH)
1454 {
1455 yylex ();
1456 obstack_grow (obstackp, " catch ", 7);
1457 look_for_lbrac = 1;
1458 }
1459 else
1460 {
1461 yychar = '{';
1462 goto done;
1463 }
1464 }
1465 else
1466 {
1467 goto done;
1468 }
1469 }
1470 }
1471 else if (c == '\\')
1472 {
1473 /* Don't act on the next character...e.g, doing an escaped
1474 double-quote. */
1475 c = getch ();
1476 if (c == EOF)
1477 {
1478 error_with_file_and_line (starting_filename,
1479 starting_lineno,
1480 "end of file read inside definition");
1481 goto done;
1482 }
1483 obstack_1grow (obstackp, c);
1484 }
1485 else if (c == '\"')
1486 consume_string (obstackp, c);
1487 else if (c == '\'')
1488 consume_string (obstackp, c);
1489 else if (c == ';')
1490 {
1491 if (look_for_lbrac)
1492 {
1493 error ("function body for constructor missing");
1494 obstack_1grow (obstackp, '{');
1495 obstack_1grow (obstackp, '}');
1496 len += 2;
1497 goto done;
1498 }
1499 else if (look_for_semicolon && blev == 0)
1500 goto done;
1501 }
1502 c = getch ();
1503 }
1504
1505 if (c == EOF)
1506 {
1507 error_with_file_and_line (starting_filename,
1508 starting_lineno,
1509 "end of file read inside definition");
1510 goto done;
1511 }
1512 else if (c != '\n')
1513 {
1514 obstack_1grow (obstackp, c);
1515 c = getch ();
1516 }
1517 }
1518 done:
1519 obstack_1grow (obstackp, '\0');
1520 }
1521
1522 /* Consume a no-commas expression -- actually, a default argument -- and
1523 save it away on the specified obstack. */
1524
1525 static void
1526 reinit_parse_for_expr (obstackp)
1527 struct obstack *obstackp;
1528 {
1529 register int c;
1530 int starting_lineno = lineno;
1531 const char *starting_filename = input_filename;
1532 int len;
1533 int plev = 0;
1534
1535 c = getch ();
1536
1537 while (c != EOF)
1538 {
1539 int this_lineno = lineno;
1540
1541 saving_parse_to_obstack = 1;
1542 c = skip_white_space (c);
1543 saving_parse_to_obstack = 0;
1544
1545 /* Don't lose our cool if there are lots of comments. */
1546 if (lineno == this_lineno + 1)
1547 obstack_1grow (obstackp, '\n');
1548 else if (lineno == this_lineno)
1549 ;
1550 else if (lineno - this_lineno < 10)
1551 {
1552 int i;
1553 for (i = lineno - this_lineno; i > 0; --i)
1554 obstack_1grow (obstackp, '\n');
1555 }
1556 else
1557 {
1558 char buf[16];
1559 sprintf (buf, "\n# %d \"", lineno);
1560 len = strlen (buf);
1561 obstack_grow (obstackp, buf, len);
1562
1563 len = strlen (input_filename);
1564 obstack_grow (obstackp, input_filename, len);
1565 obstack_1grow (obstackp, '\"');
1566 obstack_1grow (obstackp, '\n');
1567 }
1568
1569 while (c > ' ') /* ASCII dependent... */
1570 {
1571 if (plev <= 0 && (c == ')' || c == ','))
1572 {
1573 put_back (c);
1574 goto done;
1575 }
1576 obstack_1grow (obstackp, c);
1577 if (c == '(' || c == '[')
1578 ++plev;
1579 else if (c == ']' || c == ')')
1580 --plev;
1581 else if (c == '\\')
1582 {
1583 /* Don't act on the next character...e.g, doing an escaped
1584 double-quote. */
1585 c = getch ();
1586 if (c == EOF)
1587 {
1588 error_with_file_and_line (starting_filename,
1589 starting_lineno,
1590 "end of file read inside definition");
1591 goto done;
1592 }
1593 obstack_1grow (obstackp, c);
1594 }
1595 else if (c == '\"')
1596 consume_string (obstackp, c);
1597 else if (c == '\'')
1598 consume_string (obstackp, c);
1599 c = getch ();
1600 }
1601
1602 if (c == EOF)
1603 {
1604 error_with_file_and_line (starting_filename,
1605 starting_lineno,
1606 "end of file read inside definition");
1607 goto done;
1608 }
1609 else if (c != '\n')
1610 {
1611 obstack_1grow (obstackp, c);
1612 c = getch ();
1613 }
1614 }
1615 done:
1616 obstack_1grow (obstackp, '\0');
1617 }
1618
1619 int do_snarf_defarg;
1620
1621 /* Decide whether the default argument we are about to see should be
1622 gobbled up as text for later parsing. */
1623
1624 void
1625 maybe_snarf_defarg ()
1626 {
1627 if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
1628 do_snarf_defarg = 1;
1629 }
1630
1631 tree
1632 snarf_defarg ()
1633 {
1634 int len;
1635 char *buf;
1636 tree arg;
1637
1638 reinit_parse_for_expr (&inline_text_obstack);
1639 len = obstack_object_size (&inline_text_obstack);
1640 buf = obstack_finish (&inline_text_obstack);
1641
1642 arg = make_node (DEFAULT_ARG);
1643 DEFARG_LENGTH (arg) = len - 1;
1644 DEFARG_POINTER (arg) = buf;
1645
1646 return arg;
1647 }
1648
1649 /* Called from grokfndecl to note a function decl with unparsed default
1650 arguments for later processing. Also called from grokdeclarator
1651 for function types with unparsed defargs; the call from grokfndecl
1652 will always come second, so we can overwrite the entry from the type. */
1653
1654 void
1655 add_defarg_fn (decl)
1656 tree decl;
1657 {
1658 if (TREE_CODE (decl) == FUNCTION_DECL)
1659 TREE_VALUE (defarg_fns) = decl;
1660 else
1661 defarg_fns = tree_cons (current_class_type, decl, defarg_fns);
1662 }
1663
1664 /* Helper for do_pending_defargs. Starts the parsing of a default arg. */
1665
1666 static void
1667 feed_defarg (f, p)
1668 tree f, p;
1669 {
1670 tree d = TREE_PURPOSE (p);
1671 const char *file;
1672 int line;
1673 if (TREE_CODE (f) == FUNCTION_DECL)
1674 {
1675 line = DECL_SOURCE_LINE (f);
1676 file = DECL_SOURCE_FILE (f);
1677 }
1678 else
1679 {
1680 line = lineno;
1681 file = input_filename;
1682 }
1683
1684 feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d), file, line);
1685 yychar = DEFARG_MARKER;
1686 yylval.ttype = p;
1687 }
1688
1689 /* Helper for do_pending_defargs. Ends the parsing of a default arg. */
1690
1691 static void
1692 finish_defarg ()
1693 {
1694 if (yychar == YYEMPTY)
1695 yychar = yylex ();
1696 if (yychar != END_OF_SAVED_INPUT)
1697 {
1698 error ("parse error at end of saved function text");
1699
1700 /* restore_pending_input will abort unless yychar is either
1701 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1702 hosed, feed back YYEMPTY. */
1703 }
1704 yychar = YYEMPTY;
1705 end_input ();
1706 }
1707
1708 /* Main function for deferred parsing of default arguments. Called from
1709 the parser. */
1710
1711 void
1712 do_pending_defargs ()
1713 {
1714 if (defarg_parm)
1715 finish_defarg ();
1716
1717 for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns))
1718 {
1719 tree defarg_fn = TREE_VALUE (defarg_fns);
1720 if (defarg_parm == NULL_TREE)
1721 {
1722 push_nested_class (TREE_PURPOSE (defarg_fns), 1);
1723 pushlevel (0);
1724 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1725 maybe_begin_member_template_processing (defarg_fn);
1726
1727 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1728 {
1729 #if 0
1730 tree p;
1731 for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p))
1732 pushdecl (copy_node (p));
1733 #endif
1734 defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn));
1735 }
1736 else
1737 defarg_parm = TYPE_ARG_TYPES (defarg_fn);
1738 }
1739 else
1740 defarg_parm = TREE_CHAIN (defarg_parm);
1741
1742 for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm))
1743 if (TREE_PURPOSE (defarg_parm)
1744 && TREE_CODE (TREE_PURPOSE (defarg_parm)) == DEFAULT_ARG)
1745 {
1746 feed_defarg (defarg_fn, defarg_parm);
1747
1748 /* Return to the parser, which will process this defarg
1749 and call us again. */
1750 return;
1751 }
1752
1753 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1754 {
1755 maybe_end_member_template_processing ();
1756 check_default_args (defarg_fn);
1757 }
1758
1759 poplevel (0, 0, 0);
1760 pop_nested_class ();
1761 }
1762 }
1763
1764 /* Heuristic to tell whether the user is missing a semicolon
1765 after a struct or enum declaration. Emit an error message
1766 if we know the user has blown it. */
1767
1768 void
1769 check_for_missing_semicolon (type)
1770 tree type;
1771 {
1772 if (yychar < 0)
1773 yychar = yylex ();
1774
1775 if ((yychar > 255
1776 && yychar != SCSPEC
1777 && yychar != IDENTIFIER
1778 && yychar != TYPENAME
1779 && yychar != CV_QUALIFIER
1780 && yychar != SELFNAME)
1781 || end_of_file)
1782 {
1783 if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
1784 error ("semicolon missing after %s declaration",
1785 TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
1786 else
1787 cp_error ("semicolon missing after declaration of `%T'", type);
1788 shadow_tag (build_tree_list (0, type));
1789 }
1790 /* Could probably also hack cases where class { ... } f (); appears. */
1791 clear_anon_tags ();
1792 }
1793
1794 void
1795 note_got_semicolon (type)
1796 tree type;
1797 {
1798 if (!TYPE_P (type))
1799 my_friendly_abort (60);
1800 if (CLASS_TYPE_P (type))
1801 CLASSTYPE_GOT_SEMICOLON (type) = 1;
1802 }
1803
1804 void
1805 note_list_got_semicolon (declspecs)
1806 tree declspecs;
1807 {
1808 tree link;
1809
1810 for (link = declspecs; link; link = TREE_CHAIN (link))
1811 {
1812 tree type = TREE_VALUE (link);
1813 if (TYPE_P (type))
1814 note_got_semicolon (type);
1815 }
1816 clear_anon_tags ();
1817 }
1818 \f
1819 /* Iff C is a carriage return, warn about it - if appropriate -
1820 and return nonzero. */
1821 static int
1822 whitespace_cr (c)
1823 int c;
1824 {
1825 static int newline_warning = 0;
1826
1827 if (c == '\r')
1828 {
1829 /* ANSI C says the effects of a carriage return in a source file
1830 are undefined. */
1831 if (pedantic && !newline_warning)
1832 {
1833 warning ("carriage return in source file (we only warn about the first carriage return)");
1834 newline_warning = 1;
1835 }
1836 return 1;
1837 }
1838 return 0;
1839 }
1840
1841 /* If C is not whitespace, return C.
1842 Otherwise skip whitespace and return first nonwhite char read. */
1843
1844 static int
1845 skip_white_space (c)
1846 register int c;
1847 {
1848 for (;;)
1849 {
1850 switch (c)
1851 {
1852 /* We don't recognize comments here, because
1853 cpp output can include / and * consecutively as operators.
1854 Also, there's no need, since cpp removes all comments. */
1855
1856 case '\n':
1857 if (linemode)
1858 {
1859 put_back (c);
1860 return EOF;
1861 }
1862 c = check_newline ();
1863 break;
1864
1865 case ' ':
1866 case '\t':
1867 case '\f':
1868 case '\v':
1869 case '\b':
1870 #if USE_CPPLIB
1871 /* While processing a # directive we don't get CPP_HSPACE
1872 tokens, so we also need to handle whitespace the normal way. */
1873 if (cpp_token == CPP_HSPACE)
1874 c = yy_get_token ();
1875 else
1876 #endif
1877 c = getch ();
1878 break;
1879
1880 case '\r':
1881 whitespace_cr (c);
1882 c = getch ();
1883 break;
1884
1885 case '\\':
1886 c = getch ();
1887 if (c == '\n')
1888 {
1889 lineno++;
1890 c = getch ();
1891 }
1892 else if (c == 'u')
1893 c = read_ucs (4);
1894 else if (c == 'U')
1895 c = read_ucs (8);
1896 else
1897 error ("stray '\\' in program");
1898 break;
1899
1900 default:
1901 return (c);
1902 }
1903 }
1904 }
1905
1906 /* Make the token buffer longer, preserving the data in it.
1907 P should point to just beyond the last valid character in the old buffer.
1908 The value we return is a pointer to the new buffer
1909 at a place corresponding to P. */
1910
1911 static void
1912 extend_token_buffer_to (size)
1913 int size;
1914 {
1915 do
1916 maxtoken = maxtoken * 2 + 10;
1917 while (maxtoken < size);
1918 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
1919 }
1920
1921 static char *
1922 extend_token_buffer (p)
1923 const char *p;
1924 {
1925 int offset = p - token_buffer;
1926 extend_token_buffer_to (offset);
1927 return token_buffer + offset;
1928 }
1929 \f
1930 #if defined HANDLE_PRAGMA
1931 /* Local versions of these macros, that can be passed as function pointers. */
1932 static int
1933 pragma_getc ()
1934 {
1935 return getch ();
1936 }
1937
1938 static void
1939 pragma_ungetc (arg)
1940 int arg;
1941 {
1942 put_back (arg);
1943 }
1944 #endif
1945
1946 static int
1947 read_line_number (num)
1948 int *num;
1949 {
1950 register int token = real_yylex ();
1951
1952 if (token == CONSTANT
1953 && TREE_CODE (yylval.ttype) == INTEGER_CST)
1954 {
1955 *num = TREE_INT_CST_LOW (yylval.ttype);
1956 return 1;
1957 }
1958 else
1959 {
1960 if (token != END_OF_LINE)
1961 error ("invalid #-line");
1962 return 0;
1963 }
1964 }
1965
1966 /* At the beginning of a line, increment the line number
1967 and process any #-directive on this line.
1968 If the line is a #-directive, read the entire line and return a newline.
1969 Otherwise, return the line's first non-whitespace character.
1970
1971 Note that in the case of USE_CPPLIB, we get the whole line as one
1972 CPP_DIRECTIVE token. */
1973
1974 static int
1975 check_newline ()
1976 {
1977 register int c;
1978 register int token;
1979 int saw_line;
1980 enum { act_none, act_push, act_pop } action;
1981 int action_number, l;
1982 int entering_c_header;
1983 char *new_file;
1984
1985 restart:
1986 /* Read first nonwhite char on the line. Do this before incrementing the
1987 line number, in case we're at the end of saved text. */
1988
1989 #ifdef USE_CPPLIB
1990 c = getch ();
1991 /* In some cases where we're leaving an include file, we can get multiple
1992 CPP_HSPACE tokens in a row, so we need to loop. */
1993 while (cpp_token == CPP_HSPACE)
1994 c = yy_get_token ();
1995 #else
1996 do
1997 c = getch ();
1998 while (c == ' ' || c == '\t');
1999 #endif
2000
2001 lineno++;
2002
2003 if (c != '#')
2004 {
2005 /* Sequences of multiple newlines are very common; optimize them. */
2006 if (c == '\n')
2007 goto restart;
2008
2009 /* If not #, return it so caller will use it. */
2010 return c;
2011 }
2012
2013 /* Don't read beyond this line. */
2014 saw_line = 0;
2015 linemode = 1;
2016
2017 #if USE_CPPLIB
2018 if (cpp_token == CPP_VSPACE)
2019 {
2020 /* Format is "<space> <line number> <filename> <newline>".
2021 Only the line number is interesting, and even that
2022 we can get more efficiently than scanning the line. */
2023 yy_cur = yy_lim - 1;
2024 lineno = parse_in.lineno - 1;
2025 goto skipline;
2026 }
2027 #endif
2028
2029 token = real_yylex ();
2030
2031 if (token == IDENTIFIER)
2032 {
2033 /* If a letter follows, then if the word here is `line', skip
2034 it and ignore it; otherwise, ignore the line, with an error
2035 if the word isn't `pragma'. */
2036
2037 const char *name = IDENTIFIER_POINTER (yylval.ttype);
2038
2039 if (!strcmp (name, "pragma"))
2040 {
2041 token = real_yylex ();
2042 if (token != IDENTIFIER
2043 || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
2044 goto skipline;
2045
2046 /* If this is 1, we handled it; if it's -1, it was one we
2047 wanted but had something wrong with it. Only if it's
2048 0 was it not handled. */
2049 if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype)))
2050 goto skipline;
2051
2052 #ifdef HANDLE_PRAGMA
2053 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
2054 (if both are defined), in order to give the back
2055 end a chance to override the interpretation of
2056 SYSV style pragmas. */
2057 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
2058 IDENTIFIER_POINTER (yylval.ttype)))
2059 goto skipline;
2060 #endif /* HANDLE_PRAGMA */
2061
2062 #ifdef HANDLE_GENERIC_PRAGMAS
2063 if (handle_generic_pragma (token))
2064 goto skipline;
2065 #endif /* HANDLE_GENERIC_PRAGMAS */
2066
2067 /* Issue a warning message if we have been asked to do so.
2068 Ignoring unknown pragmas in system header file unless
2069 an explcit -Wunknown-pragmas has been given. */
2070 if (warn_unknown_pragmas > 1
2071 || (warn_unknown_pragmas && ! in_system_header))
2072 warning ("ignoring pragma: %s", token_buffer);
2073
2074 goto skipline;
2075 }
2076 else if (!strcmp (name, "define"))
2077 {
2078 debug_define (lineno, GET_DIRECTIVE_LINE ());
2079 goto skipline;
2080 }
2081 else if (!strcmp (name, "undef"))
2082 {
2083 debug_undef (lineno, GET_DIRECTIVE_LINE ());
2084 goto skipline;
2085 }
2086 else if (!strcmp (name, "line"))
2087 {
2088 saw_line = 1;
2089 token = real_yylex ();
2090 goto linenum;
2091 }
2092 else if (!strcmp (name, "ident"))
2093 {
2094 /* #ident. The pedantic warning is now in cpp. */
2095
2096 /* Here we have just seen `#ident '.
2097 A string constant should follow. */
2098
2099 token = real_yylex ();
2100 if (token == END_OF_LINE)
2101 goto skipline;
2102 if (token != STRING
2103 || TREE_CODE (yylval.ttype) != STRING_CST)
2104 {
2105 error ("invalid #ident");
2106 goto skipline;
2107 }
2108
2109 if (! flag_no_ident)
2110 {
2111 #ifdef ASM_OUTPUT_IDENT
2112 ASM_OUTPUT_IDENT (asm_out_file,
2113 TREE_STRING_POINTER (yylval.ttype));
2114 #endif
2115 }
2116
2117 /* Skip the rest of this line. */
2118 goto skipline;
2119 }
2120
2121 error ("undefined or invalid # directive `%s'", name);
2122 goto skipline;
2123 }
2124
2125 /* If the # is the only nonwhite char on the line,
2126 just ignore it. Check the new newline. */
2127 if (token == END_OF_LINE)
2128 goto skipline;
2129
2130 linenum:
2131 /* Here we have either `#line' or `# <nonletter>'.
2132 In either case, it should be a line number; a digit should follow. */
2133
2134 if (token != CONSTANT
2135 || TREE_CODE (yylval.ttype) != INTEGER_CST)
2136 {
2137 error ("invalid #-line");
2138 goto skipline;
2139 }
2140
2141 /* subtract one, because it is the following line that
2142 gets the specified number */
2143
2144 l = TREE_INT_CST_LOW (yylval.ttype) - 1;
2145
2146 /* More follows: it must be a string constant (filename).
2147 It would be neat to use cpplib to quickly process the string, but
2148 (1) we don't have a handy tokenization of the string, and
2149 (2) I don't know how well that would work in the presense
2150 of filenames that contain wide characters. */
2151
2152 if (saw_line || saving_parse_to_obstack)
2153 {
2154 /* Don't treat \ as special if we are processing #line 1 "...".
2155 If you want it to be treated specially, use # 1 "...". Also
2156 ignore these if saving to an obstack for later parsing. */
2157 ignore_escape_flag = 1;
2158 }
2159
2160 /* Read the string constant. */
2161 token = real_yylex ();
2162
2163 ignore_escape_flag = 0;
2164
2165 if (token == END_OF_LINE)
2166 {
2167 /* No more: store the line number and check following line. */
2168 lineno = l;
2169 goto skipline;
2170 }
2171
2172 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2173 {
2174 error ("invalid #line");
2175 goto skipline;
2176 }
2177
2178 /* Changing files again. This means currently collected time
2179 is charged against header time, and body time starts back at 0. */
2180 if (flag_detailed_statistics)
2181 {
2182 int this_time = get_run_time ();
2183 tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype));
2184 header_time += this_time - body_time;
2185 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
2186 += this_time - body_time;
2187 this_filename_time = time_identifier;
2188 body_time = this_time;
2189 }
2190
2191 new_file = TREE_STRING_POINTER (yylval.ttype);
2192
2193 GNU_xref_file (new_file);
2194
2195 if (main_input_filename == 0)
2196 {
2197 struct impl_files *ifiles = impl_file_chain;
2198
2199 if (ifiles)
2200 {
2201 while (ifiles->next)
2202 ifiles = ifiles->next;
2203 ifiles->filename = file_name_nondirectory (new_file);
2204 }
2205
2206 main_input_filename = new_file;
2207 }
2208
2209 action = act_none;
2210 action_number = 0;
2211
2212 /* Each change of file name
2213 reinitializes whether we are now in a system header. */
2214 in_system_header = 0;
2215 entering_c_header = 0;
2216
2217 if (!read_line_number (&action_number) && input_file_stack)
2218 {
2219 input_file_stack->name = input_filename = new_file;
2220 input_file_stack->line = lineno = l;
2221 }
2222
2223 /* `1' after file name means entering new file.
2224 `2' after file name means just left a file. */
2225
2226 if (action_number == 1)
2227 {
2228 action = act_push;
2229 read_line_number (&action_number);
2230 }
2231 else if (action_number == 2)
2232 {
2233 action = act_pop;
2234 read_line_number (&action_number);
2235 }
2236 if (action_number == 3)
2237 {
2238 /* `3' after file name means this is a system header file. */
2239 in_system_header = 1;
2240 read_line_number (&action_number);
2241 }
2242 if (action_number == 4)
2243 {
2244 /* `4' after file name means this is a C header file. */
2245 entering_c_header = 1;
2246 read_line_number (&action_number);
2247 }
2248
2249 /* Do the actions implied by the preceding numbers. */
2250
2251 if (action == act_push)
2252 {
2253 /* Pushing to a new file. */
2254 push_srcloc (new_file, l);
2255 input_file_stack->indent_level = indent_level;
2256 debug_start_source_file (input_filename);
2257 if (c_header_level)
2258 ++c_header_level;
2259 else if (entering_c_header)
2260 {
2261 c_header_level = 1;
2262 ++pending_lang_change;
2263 }
2264 }
2265 else if (action == act_pop)
2266 {
2267 /* Popping out of a file. */
2268 if (input_file_stack->next)
2269 {
2270 if (c_header_level && --c_header_level == 0)
2271 {
2272 if (entering_c_header)
2273 warning ("badly nested C headers from preprocessor");
2274 --pending_lang_change;
2275 }
2276
2277 if (indent_level != input_file_stack->indent_level)
2278 {
2279 warning_with_file_and_line
2280 (input_filename, lineno,
2281 "This file contains more `%c's than `%c's.",
2282 indent_level > input_file_stack->indent_level ? '{' : '}',
2283 indent_level > input_file_stack->indent_level ? '}' : '{');
2284 }
2285
2286 pop_srcloc ();
2287 input_file_stack->name = new_file;
2288 debug_end_source_file (input_file_stack->line);
2289 }
2290 else
2291 error ("#-lines for entering and leaving files don't match");
2292 }
2293
2294 input_filename = new_file;
2295 lineno = l;
2296
2297 extract_interface_info ();
2298
2299 /* skip the rest of this line. */
2300 skipline:
2301 linemode = 0;
2302 end_of_file = 0;
2303
2304 do
2305 c = getch ();
2306 while (c != '\n' && c != EOF);
2307 return c;
2308 }
2309 \f
2310 #ifdef HANDLE_GENERIC_PRAGMAS
2311
2312 /* Handle a #pragma directive.
2313 TOKEN is the token we read after `#pragma'. Processes the entire input
2314 line and return non-zero iff the pragma has been successfully parsed. */
2315
2316 /* This function has to be in this file, in order to get at
2317 the token types. */
2318
2319 static int
2320 handle_generic_pragma (token)
2321 register int token;
2322 {
2323 for (;;)
2324 {
2325 switch (token)
2326 {
2327 case IDENTIFIER:
2328 case TYPENAME:
2329 case STRING:
2330 case CONSTANT:
2331 handle_pragma_token (token_buffer, yylval.ttype);
2332 break;
2333
2334 case LEFT_RIGHT:
2335 handle_pragma_token ("(", NULL_TREE);
2336 handle_pragma_token (")", NULL_TREE);
2337 break;
2338
2339 case END_OF_LINE:
2340 return handle_pragma_token (NULL_PTR, NULL_TREE);
2341
2342 default:
2343 handle_pragma_token (token_buffer, NULL_TREE);
2344 }
2345
2346 token = real_yylex ();
2347 }
2348 }
2349 #endif /* HANDLE_GENERIC_PRAGMAS */
2350
2351 static int
2352 handle_cp_pragma (pname)
2353 const char *pname;
2354 {
2355 register int token;
2356
2357 if (! strcmp (pname, "vtable"))
2358 {
2359 /* More follows: it must be a string constant (class name). */
2360 token = real_yylex ();
2361 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2362 {
2363 error ("invalid #pragma vtable");
2364 return -1;
2365 }
2366
2367 pending_vtables
2368 = tree_cons (NULL_TREE,
2369 get_identifier (TREE_STRING_POINTER (yylval.ttype)),
2370 pending_vtables);
2371 token = real_yylex ();
2372 if (token != END_OF_LINE)
2373 warning ("trailing characters ignored");
2374 return 1;
2375 }
2376 else if (! strcmp (pname, "unit"))
2377 {
2378 /* More follows: it must be a string constant (unit name). */
2379 token = real_yylex ();
2380 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2381 {
2382 error ("invalid #pragma unit");
2383 return -1;
2384 }
2385 token = real_yylex ();
2386 if (token != END_OF_LINE)
2387 warning ("trailing characters ignored");
2388 return 1;
2389 }
2390 else if (! strcmp (pname, "interface"))
2391 {
2392 const char *main_filename = input_filename;
2393
2394 main_filename = file_name_nondirectory (main_filename);
2395
2396 token = real_yylex ();
2397
2398 if (token != END_OF_LINE)
2399 {
2400 if (token != STRING
2401 || TREE_CODE (yylval.ttype) != STRING_CST)
2402 {
2403 error ("invalid `#pragma interface'");
2404 return -1;
2405 }
2406 main_filename = TREE_STRING_POINTER (yylval.ttype);
2407 token = real_yylex ();
2408 }
2409
2410 if (token != END_OF_LINE)
2411 warning ("garbage after `#pragma interface' ignored");
2412
2413 cp_pragma_interface (main_filename);
2414
2415 return 1;
2416 }
2417 else if (! strcmp (pname, "implementation"))
2418 {
2419 const char *main_filename = main_input_filename ? main_input_filename : input_filename;
2420
2421 main_filename = file_name_nondirectory (main_filename);
2422
2423 token = real_yylex ();
2424
2425 if (token != END_OF_LINE)
2426 {
2427 if (token != STRING
2428 || TREE_CODE (yylval.ttype) != STRING_CST)
2429 {
2430 error ("invalid `#pragma implementation'");
2431 return -1;
2432 }
2433 main_filename = TREE_STRING_POINTER (yylval.ttype);
2434 token = real_yylex ();
2435 }
2436
2437 if (token != END_OF_LINE)
2438 warning ("garbage after `#pragma implementation' ignored");
2439
2440 cp_pragma_implementation (main_filename);
2441
2442 return 1;
2443 }
2444
2445 return 0;
2446 }
2447 \f
2448 void
2449 do_pending_lang_change ()
2450 {
2451 for (; pending_lang_change > 0; --pending_lang_change)
2452 push_lang_context (lang_name_c);
2453 for (; pending_lang_change < 0; ++pending_lang_change)
2454 pop_lang_context ();
2455 }
2456 \f
2457 /* Parse a '\uNNNN' or '\UNNNNNNNN' sequence.
2458
2459 [lex.charset]: The character designated by the universal-character-name
2460 \UNNNNNNNN is that character whose character short name in ISO/IEC 10646
2461 is NNNNNNNN; the character designated by the universal-character-name
2462 \uNNNN is that character whose character short name in ISO/IEC 10646 is
2463 0000NNNN. If the hexadecimal value for a universal character name is
2464 less than 0x20 or in the range 0x7F-0x9F (inclusive), or if the
2465 universal character name designates a character in the basic source
2466 character set, then the program is ill-formed.
2467
2468 We assume that wchar_t is Unicode, so we don't need to do any
2469 mapping. Is this ever wrong? */
2470
2471 static int
2472 read_ucs (length)
2473 int length;
2474 {
2475 unsigned int code = 0;
2476 int c;
2477
2478 for (; length; --length)
2479 {
2480 c = getch ();
2481 if (! ISXDIGIT (c))
2482 {
2483 error ("non hex digit '%c' in universal-character-name", c);
2484 put_back (c);
2485 break;
2486 }
2487 code <<= 4;
2488 if (c >= 'a' && c <= 'f')
2489 code += c - 'a' + 10;
2490 if (c >= 'A' && c <= 'F')
2491 code += c - 'A' + 10;
2492 if (c >= '0' && c <= '9')
2493 code += c - '0';
2494 }
2495
2496 #ifdef TARGET_EBCDIC
2497 sorry ("universal-character-name on EBCDIC target");
2498 return 0x3F;
2499 #endif
2500
2501 if (code > 0x9f && !(code & 0x80000000))
2502 /* True extended character, OK. */;
2503 else if (code >= 0x20 && code < 0x7f)
2504 {
2505 /* ASCII printable character. The C character set consists of all of
2506 these except $, @ and `. We use hex escapes so that this also
2507 works with EBCDIC hosts. */
2508 if (code != 0x24 && code != 0x40 && code != 0x60)
2509 error ("universal-character-name designates `%c', part of the basic source character set", code);
2510 }
2511 else
2512 error ("invalid universal-character-name");
2513 return code;
2514 }
2515
2516 /* Returns nonzero if C is a universal-character-name. Give an error if it
2517 is not one which may appear in an identifier, as per [extendid]. */
2518
2519 static inline int
2520 is_extended_char (c)
2521 int c;
2522 {
2523 #ifdef TARGET_EBCDIC
2524 return 0;
2525 #else
2526 /* ASCII. */
2527 if (c < 0x7f)
2528 return 0;
2529
2530 return is_extended_char_1 (c);
2531 #endif
2532 }
2533
2534 static int
2535 is_extended_char_1 (c)
2536 int c;
2537 {
2538 /* None of the valid chars are outside the Basic Multilingual Plane (the
2539 low 16 bits). */
2540 if (c > 0xffff)
2541 {
2542 error ("universal-character-name `\\U%08x' not valid in identifier", c);
2543 return 1;
2544 }
2545
2546 /* Latin */
2547 if ((c >= 0x00c0 && c <= 0x00d6)
2548 || (c >= 0x00d8 && c <= 0x00f6)
2549 || (c >= 0x00f8 && c <= 0x01f5)
2550 || (c >= 0x01fa && c <= 0x0217)
2551 || (c >= 0x0250 && c <= 0x02a8)
2552 || (c >= 0x1e00 && c <= 0x1e9a)
2553 || (c >= 0x1ea0 && c <= 0x1ef9))
2554 return 1;
2555
2556 /* Greek */
2557 if ((c == 0x0384)
2558 || (c >= 0x0388 && c <= 0x038a)
2559 || (c == 0x038c)
2560 || (c >= 0x038e && c <= 0x03a1)
2561 || (c >= 0x03a3 && c <= 0x03ce)
2562 || (c >= 0x03d0 && c <= 0x03d6)
2563 || (c == 0x03da)
2564 || (c == 0x03dc)
2565 || (c == 0x03de)
2566 || (c == 0x03e0)
2567 || (c >= 0x03e2 && c <= 0x03f3)
2568 || (c >= 0x1f00 && c <= 0x1f15)
2569 || (c >= 0x1f18 && c <= 0x1f1d)
2570 || (c >= 0x1f20 && c <= 0x1f45)
2571 || (c >= 0x1f48 && c <= 0x1f4d)
2572 || (c >= 0x1f50 && c <= 0x1f57)
2573 || (c == 0x1f59)
2574 || (c == 0x1f5b)
2575 || (c == 0x1f5d)
2576 || (c >= 0x1f5f && c <= 0x1f7d)
2577 || (c >= 0x1f80 && c <= 0x1fb4)
2578 || (c >= 0x1fb6 && c <= 0x1fbc)
2579 || (c >= 0x1fc2 && c <= 0x1fc4)
2580 || (c >= 0x1fc6 && c <= 0x1fcc)
2581 || (c >= 0x1fd0 && c <= 0x1fd3)
2582 || (c >= 0x1fd6 && c <= 0x1fdb)
2583 || (c >= 0x1fe0 && c <= 0x1fec)
2584 || (c >= 0x1ff2 && c <= 0x1ff4)
2585 || (c >= 0x1ff6 && c <= 0x1ffc))
2586 return 1;
2587
2588 /* Cyrillic */
2589 if ((c >= 0x0401 && c <= 0x040d)
2590 || (c >= 0x040f && c <= 0x044f)
2591 || (c >= 0x0451 && c <= 0x045c)
2592 || (c >= 0x045e && c <= 0x0481)
2593 || (c >= 0x0490 && c <= 0x04c4)
2594 || (c >= 0x04c7 && c <= 0x04c8)
2595 || (c >= 0x04cb && c <= 0x04cc)
2596 || (c >= 0x04d0 && c <= 0x04eb)
2597 || (c >= 0x04ee && c <= 0x04f5)
2598 || (c >= 0x04f8 && c <= 0x04f9))
2599 return 1;
2600
2601 /* Armenian */
2602 if ((c >= 0x0531 && c <= 0x0556)
2603 || (c >= 0x0561 && c <= 0x0587))
2604 return 1;
2605
2606 /* Hebrew */
2607 if ((c >= 0x05d0 && c <= 0x05ea)
2608 || (c >= 0x05f0 && c <= 0x05f4))
2609 return 1;
2610
2611 /* Arabic */
2612 if ((c >= 0x0621 && c <= 0x063a)
2613 || (c >= 0x0640 && c <= 0x0652)
2614 || (c >= 0x0670 && c <= 0x06b7)
2615 || (c >= 0x06ba && c <= 0x06be)
2616 || (c >= 0x06c0 && c <= 0x06ce)
2617 || (c >= 0x06e5 && c <= 0x06e7))
2618 return 1;
2619
2620 /* Devanagari */
2621 if ((c >= 0x0905 && c <= 0x0939)
2622 || (c >= 0x0958 && c <= 0x0962))
2623 return 1;
2624
2625 /* Bengali */
2626 if ((c >= 0x0985 && c <= 0x098c)
2627 || (c >= 0x098f && c <= 0x0990)
2628 || (c >= 0x0993 && c <= 0x09a8)
2629 || (c >= 0x09aa && c <= 0x09b0)
2630 || (c == 0x09b2)
2631 || (c >= 0x09b6 && c <= 0x09b9)
2632 || (c >= 0x09dc && c <= 0x09dd)
2633 || (c >= 0x09df && c <= 0x09e1)
2634 || (c >= 0x09f0 && c <= 0x09f1))
2635 return 1;
2636
2637 /* Gurmukhi */
2638 if ((c >= 0x0a05 && c <= 0x0a0a)
2639 || (c >= 0x0a0f && c <= 0x0a10)
2640 || (c >= 0x0a13 && c <= 0x0a28)
2641 || (c >= 0x0a2a && c <= 0x0a30)
2642 || (c >= 0x0a32 && c <= 0x0a33)
2643 || (c >= 0x0a35 && c <= 0x0a36)
2644 || (c >= 0x0a38 && c <= 0x0a39)
2645 || (c >= 0x0a59 && c <= 0x0a5c)
2646 || (c == 0x0a5e))
2647 return 1;
2648
2649 /* Gujarati */
2650 if ((c >= 0x0a85 && c <= 0x0a8b)
2651 || (c == 0x0a8d)
2652 || (c >= 0x0a8f && c <= 0x0a91)
2653 || (c >= 0x0a93 && c <= 0x0aa8)
2654 || (c >= 0x0aaa && c <= 0x0ab0)
2655 || (c >= 0x0ab2 && c <= 0x0ab3)
2656 || (c >= 0x0ab5 && c <= 0x0ab9)
2657 || (c == 0x0ae0))
2658 return 1;
2659
2660 /* Oriya */
2661 if ((c >= 0x0b05 && c <= 0x0b0c)
2662 || (c >= 0x0b0f && c <= 0x0b10)
2663 || (c >= 0x0b13 && c <= 0x0b28)
2664 || (c >= 0x0b2a && c <= 0x0b30)
2665 || (c >= 0x0b32 && c <= 0x0b33)
2666 || (c >= 0x0b36 && c <= 0x0b39)
2667 || (c >= 0x0b5c && c <= 0x0b5d)
2668 || (c >= 0x0b5f && c <= 0x0b61))
2669 return 1;
2670
2671 /* Tamil */
2672 if ((c >= 0x0b85 && c <= 0x0b8a)
2673 || (c >= 0x0b8e && c <= 0x0b90)
2674 || (c >= 0x0b92 && c <= 0x0b95)
2675 || (c >= 0x0b99 && c <= 0x0b9a)
2676 || (c == 0x0b9c)
2677 || (c >= 0x0b9e && c <= 0x0b9f)
2678 || (c >= 0x0ba3 && c <= 0x0ba4)
2679 || (c >= 0x0ba8 && c <= 0x0baa)
2680 || (c >= 0x0bae && c <= 0x0bb5)
2681 || (c >= 0x0bb7 && c <= 0x0bb9))
2682 return 1;
2683
2684 /* Telugu */
2685 if ((c >= 0x0c05 && c <= 0x0c0c)
2686 || (c >= 0x0c0e && c <= 0x0c10)
2687 || (c >= 0x0c12 && c <= 0x0c28)
2688 || (c >= 0x0c2a && c <= 0x0c33)
2689 || (c >= 0x0c35 && c <= 0x0c39)
2690 || (c >= 0x0c60 && c <= 0x0c61))
2691 return 1;
2692
2693 /* Kannada */
2694 if ((c >= 0x0c85 && c <= 0x0c8c)
2695 || (c >= 0x0c8e && c <= 0x0c90)
2696 || (c >= 0x0c92 && c <= 0x0ca8)
2697 || (c >= 0x0caa && c <= 0x0cb3)
2698 || (c >= 0x0cb5 && c <= 0x0cb9)
2699 || (c >= 0x0ce0 && c <= 0x0ce1))
2700 return 1;
2701
2702 /* Malayalam */
2703 if ((c >= 0x0d05 && c <= 0x0d0c)
2704 || (c >= 0x0d0e && c <= 0x0d10)
2705 || (c >= 0x0d12 && c <= 0x0d28)
2706 || (c >= 0x0d2a && c <= 0x0d39)
2707 || (c >= 0x0d60 && c <= 0x0d61))
2708 return 1;
2709
2710 /* Thai */
2711 if ((c >= 0x0e01 && c <= 0x0e30)
2712 || (c >= 0x0e32 && c <= 0x0e33)
2713 || (c >= 0x0e40 && c <= 0x0e46)
2714 || (c >= 0x0e4f && c <= 0x0e5b))
2715 return 1;
2716
2717 /* Lao */
2718 if ((c >= 0x0e81 && c <= 0x0e82)
2719 || (c == 0x0e84)
2720 || (c == 0x0e87)
2721 || (c == 0x0e88)
2722 || (c == 0x0e8a)
2723 || (c == 0x0e0d)
2724 || (c >= 0x0e94 && c <= 0x0e97)
2725 || (c >= 0x0e99 && c <= 0x0e9f)
2726 || (c >= 0x0ea1 && c <= 0x0ea3)
2727 || (c == 0x0ea5)
2728 || (c == 0x0ea7)
2729 || (c == 0x0eaa)
2730 || (c == 0x0eab)
2731 || (c >= 0x0ead && c <= 0x0eb0)
2732 || (c == 0x0eb2)
2733 || (c == 0x0eb3)
2734 || (c == 0x0ebd)
2735 || (c >= 0x0ec0 && c <= 0x0ec4)
2736 || (c == 0x0ec6))
2737 return 1;
2738
2739 /* Georgian */
2740 if ((c >= 0x10a0 && c <= 0x10c5)
2741 || (c >= 0x10d0 && c <= 0x10f6))
2742 return 1;
2743
2744 /* Hiragana */
2745 if ((c >= 0x3041 && c <= 0x3094)
2746 || (c >= 0x309b && c <= 0x309e))
2747 return 1;
2748
2749 /* Katakana */
2750 if ((c >= 0x30a1 && c <= 0x30fe))
2751 return 1;
2752
2753 /* Bopmofo */
2754 if ((c >= 0x3105 && c <= 0x312c))
2755 return 1;
2756
2757 /* Hangul */
2758 if ((c >= 0x1100 && c <= 0x1159)
2759 || (c >= 0x1161 && c <= 0x11a2)
2760 || (c >= 0x11a8 && c <= 0x11f9))
2761 return 1;
2762
2763 /* CJK Unified Ideographs */
2764 if ((c >= 0xf900 && c <= 0xfa2d)
2765 || (c >= 0xfb1f && c <= 0xfb36)
2766 || (c >= 0xfb38 && c <= 0xfb3c)
2767 || (c == 0xfb3e)
2768 || (c >= 0xfb40 && c <= 0xfb41)
2769 || (c >= 0xfb42 && c <= 0xfb44)
2770 || (c >= 0xfb46 && c <= 0xfbb1)
2771 || (c >= 0xfbd3 && c <= 0xfd3f)
2772 || (c >= 0xfd50 && c <= 0xfd8f)
2773 || (c >= 0xfd92 && c <= 0xfdc7)
2774 || (c >= 0xfdf0 && c <= 0xfdfb)
2775 || (c >= 0xfe70 && c <= 0xfe72)
2776 || (c == 0xfe74)
2777 || (c >= 0xfe76 && c <= 0xfefc)
2778 || (c >= 0xff21 && c <= 0xff3a)
2779 || (c >= 0xff41 && c <= 0xff5a)
2780 || (c >= 0xff66 && c <= 0xffbe)
2781 || (c >= 0xffc2 && c <= 0xffc7)
2782 || (c >= 0xffca && c <= 0xffcf)
2783 || (c >= 0xffd2 && c <= 0xffd7)
2784 || (c >= 0xffda && c <= 0xffdc)
2785 || (c >= 0x4e00 && c <= 0x9fa5))
2786 return 1;
2787
2788 error ("universal-character-name `\\u%04x' not valid in identifier", c);
2789 return 1;
2790 }
2791
2792 #if 0
2793 /* Add the UTF-8 representation of C to the token_buffer. */
2794
2795 static void
2796 utf8_extend_token (c)
2797 int c;
2798 {
2799 int shift, mask;
2800
2801 if (c <= 0x0000007f)
2802 {
2803 extend_token (c);
2804 return;
2805 }
2806 else if (c <= 0x000007ff)
2807 shift = 6, mask = 0xc0;
2808 else if (c <= 0x0000ffff)
2809 shift = 12, mask = 0xe0;
2810 else if (c <= 0x001fffff)
2811 shift = 18, mask = 0xf0;
2812 else if (c <= 0x03ffffff)
2813 shift = 24, mask = 0xf8;
2814 else
2815 shift = 30, mask = 0xfc;
2816
2817 extend_token (mask | (c >> shift));
2818 do
2819 {
2820 shift -= 6;
2821 extend_token ((unsigned char) (0x80 | (c >> shift)));
2822 }
2823 while (shift);
2824 }
2825 #endif
2826 \f
2827 #define ENDFILE -1 /* token that represents end-of-file */
2828
2829 /* Read an escape sequence, returning its equivalent as a character,
2830 or store 1 in *ignore_ptr if it is backslash-newline. */
2831
2832 static int
2833 readescape (ignore_ptr)
2834 int *ignore_ptr;
2835 {
2836 register int c = getch ();
2837 register int code;
2838 register unsigned count;
2839 unsigned firstdig = 0;
2840 int nonnull;
2841
2842 switch (c)
2843 {
2844 case 'x':
2845 code = 0;
2846 count = 0;
2847 nonnull = 0;
2848 while (1)
2849 {
2850 c = getch ();
2851 if (! ISXDIGIT (c))
2852 {
2853 put_back (c);
2854 break;
2855 }
2856 code *= 16;
2857 if (c >= 'a' && c <= 'f')
2858 code += c - 'a' + 10;
2859 if (c >= 'A' && c <= 'F')
2860 code += c - 'A' + 10;
2861 if (c >= '0' && c <= '9')
2862 code += c - '0';
2863 if (code != 0 || count != 0)
2864 {
2865 if (count == 0)
2866 firstdig = code;
2867 count++;
2868 }
2869 nonnull = 1;
2870 }
2871 if (! nonnull)
2872 error ("\\x used with no following hex digits");
2873 else if (count == 0)
2874 /* Digits are all 0's. Ok. */
2875 ;
2876 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
2877 || (count > 1
2878 && (((unsigned)1
2879 << (TYPE_PRECISION (integer_type_node)
2880 - (count - 1) * 4))
2881 <= firstdig)))
2882 pedwarn ("hex escape out of range");
2883 return code;
2884
2885 case '0': case '1': case '2': case '3': case '4':
2886 case '5': case '6': case '7':
2887 code = 0;
2888 count = 0;
2889 while ((c <= '7') && (c >= '0') && (count++ < 3))
2890 {
2891 code = (code * 8) + (c - '0');
2892 c = getch ();
2893 }
2894 put_back (c);
2895 return code;
2896
2897 case 'U':
2898 return read_ucs (8);
2899 case 'u':
2900 return read_ucs (4);
2901
2902 case '\\': case '\'': case '"':
2903 return c;
2904
2905 case '\n':
2906 lineno++;
2907 *ignore_ptr = 1;
2908 return 0;
2909
2910 case 'n':
2911 return TARGET_NEWLINE;
2912
2913 case 't':
2914 return TARGET_TAB;
2915
2916 case 'r':
2917 return TARGET_CR;
2918
2919 case 'f':
2920 return TARGET_FF;
2921
2922 case 'b':
2923 return TARGET_BS;
2924
2925 case 'a':
2926 return TARGET_BELL;
2927
2928 case 'v':
2929 return TARGET_VT;
2930
2931 case 'e':
2932 case 'E':
2933 if (pedantic)
2934 pedwarn ("non-ISO-standard escape sequence, `\\%c'", c);
2935 return 033;
2936
2937 case '?':
2938 return c;
2939
2940 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
2941 case '(':
2942 case '{':
2943 case '[':
2944 /* `\%' is used to prevent SCCS from getting confused. */
2945 case '%':
2946 if (pedantic)
2947 pedwarn ("unknown escape sequence `\\%c'", c);
2948 return c;
2949 }
2950 if (ISGRAPH (c))
2951 pedwarn ("unknown escape sequence `\\%c'", c);
2952 else
2953 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
2954 return c;
2955 }
2956 \f
2957 void
2958 yyerror (string)
2959 const char *string;
2960 {
2961 extern int end_of_file;
2962
2963 /* We can't print string and character constants well
2964 because the token_buffer contains the result of processing escapes. */
2965 if (end_of_file)
2966 {
2967 if (input_redirected ())
2968 error ("%s at end of saved text", string);
2969 else
2970 error ("%s at end of input", string);
2971 }
2972 else if (token_buffer[0] == 0)
2973 error ("%s at null character", string);
2974 else if (token_buffer[0] == '"')
2975 error ("%s before string constant", string);
2976 else if (token_buffer[0] == '\'')
2977 error ("%s before character constant", string);
2978 else if (!ISGRAPH ((unsigned char)token_buffer[0]))
2979 error ("%s before character 0%o", string, (unsigned char) token_buffer[0]);
2980 else
2981 error ("%s before `%s'", string, token_buffer);
2982 }
2983 \f
2984 /* Value is 1 (or 2) if we should try to make the next identifier look like
2985 a typename (when it may be a local variable or a class variable).
2986 Value is 0 if we treat this name in a default fashion. */
2987 int looking_for_typename;
2988
2989 inline int
2990 identifier_type (decl)
2991 tree decl;
2992 {
2993 tree t;
2994
2995 if (TREE_CODE (decl) == TEMPLATE_DECL)
2996 {
2997 if (TREE_CODE (DECL_TEMPLATE_RESULT (decl)) == TYPE_DECL)
2998 return PTYPENAME;
2999 else if (looking_for_template)
3000 return PFUNCNAME;
3001 }
3002 if (looking_for_template && really_overloaded_fn (decl))
3003 {
3004 /* See through a baselink. */
3005 if (TREE_CODE (decl) == TREE_LIST)
3006 decl = TREE_VALUE (decl);
3007
3008 for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t))
3009 if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t)))
3010 return PFUNCNAME;
3011 }
3012 if (TREE_CODE (decl) == NAMESPACE_DECL)
3013 return NSNAME;
3014 if (TREE_CODE (decl) != TYPE_DECL)
3015 return IDENTIFIER;
3016 if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type)
3017 return SELFNAME;
3018
3019 /* A constructor declarator for a template type will get here as an
3020 implicit typename, a TYPENAME_TYPE with a type. */
3021 t = got_scope;
3022 if (t && TREE_CODE (t) == TYPENAME_TYPE)
3023 t = TREE_TYPE (t);
3024 decl = TREE_TYPE (decl);
3025 if (TREE_CODE (decl) == TYPENAME_TYPE)
3026 decl = TREE_TYPE (decl);
3027 if (t && t == decl)
3028 return SELFNAME;
3029
3030 return TYPENAME;
3031 }
3032
3033 void
3034 see_typename ()
3035 {
3036 /* Only types expected, not even namespaces. */
3037 looking_for_typename = 2;
3038 if (yychar < 0)
3039 if ((yychar = yylex ()) < 0) yychar = 0;
3040 looking_for_typename = 0;
3041 if (yychar == IDENTIFIER)
3042 {
3043 lastiddecl = lookup_name (yylval.ttype, -2);
3044 if (lastiddecl == 0)
3045 {
3046 if (flag_labels_ok)
3047 lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype);
3048 }
3049 else
3050 yychar = identifier_type (lastiddecl);
3051 }
3052 }
3053
3054 /* Return true if d is in a global scope. */
3055
3056 static int
3057 is_global (d)
3058 tree d;
3059 {
3060 while (1)
3061 switch (TREE_CODE (d))
3062 {
3063 case ERROR_MARK:
3064 return 1;
3065
3066 case OVERLOAD: d = OVL_FUNCTION (d); continue;
3067 case TREE_LIST: d = TREE_VALUE (d); continue;
3068 default:
3069 my_friendly_assert (DECL_P (d), 980629);
3070
3071 return DECL_NAMESPACE_SCOPE_P (d);
3072 }
3073 }
3074
3075 tree
3076 do_identifier (token, parsing, args)
3077 register tree token;
3078 int parsing;
3079 tree args;
3080 {
3081 register tree id;
3082 int lexing = (parsing == 1);
3083 int in_call = (parsing == 2);
3084
3085 if (! lexing || IDENTIFIER_OPNAME_P (token))
3086 id = lookup_name (token, 0);
3087 else
3088 id = lastiddecl;
3089
3090 /* Do Koenig lookup if appropriate (inside templates we build lookup
3091 expressions instead).
3092
3093 [basic.lookup.koenig]: If the ordinary unqualified lookup of the name
3094 finds the declaration of a class member function, the associated
3095 namespaces and classes are not considered. */
3096
3097 if (args && !current_template_parms && (!id || is_global (id)))
3098 id = lookup_arg_dependent (token, id, args);
3099
3100 /* Remember that this name has been used in the class definition, as per
3101 [class.scope0] */
3102 if (id && parsing)
3103 maybe_note_name_used_in_class (token, id);
3104
3105 if (id == error_mark_node)
3106 {
3107 /* lookup_name quietly returns error_mark_node if we're parsing,
3108 as we don't want to complain about an identifier that ends up
3109 being used as a declarator. So we call it again to get the error
3110 message. */
3111 id = lookup_name (token, 0);
3112 return error_mark_node;
3113 }
3114
3115 if (!id || (TREE_CODE (id) == FUNCTION_DECL
3116 && DECL_ANTICIPATED (id)))
3117 {
3118 if (current_template_parms)
3119 return build_min_nt (LOOKUP_EXPR, token);
3120 else if (IDENTIFIER_OPNAME_P (token))
3121 {
3122 if (token != ansi_opname (ERROR_MARK))
3123 cp_error ("`%D' not defined", token);
3124 id = error_mark_node;
3125 }
3126 else if (in_call && ! flag_strict_prototype)
3127 {
3128 if (!id)
3129 id = implicitly_declare (token);
3130 else
3131 {
3132 /* Implicit declaration of built-in function. Don't
3133 change the built-in declaration, but don't let this
3134 go by silently, either. */
3135 cp_pedwarn ("implicit declaration of function `%D'", token);
3136 DECL_ANTICIPATED (id) = 0; /* only issue this warning once */
3137 }
3138 }
3139 else if (current_function_decl == 0)
3140 {
3141 cp_error ("`%D' was not declared in this scope", token);
3142 id = error_mark_node;
3143 }
3144 else
3145 {
3146 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node
3147 || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
3148 {
3149 static int undeclared_variable_notice;
3150
3151 cp_error ("`%D' undeclared (first use this function)", token);
3152
3153 if (! undeclared_variable_notice)
3154 {
3155 error ("(Each undeclared identifier is reported only once for each function it appears in.)");
3156 undeclared_variable_notice = 1;
3157 }
3158 }
3159 id = error_mark_node;
3160 /* Prevent repeated error messages. */
3161 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3162 SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
3163 }
3164 }
3165
3166 if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
3167 {
3168 tree shadowed = DECL_SHADOWED_FOR_VAR (id);
3169 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
3170 && DECL_DEAD_FOR_LOCAL (shadowed))
3171 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
3172 if (!shadowed)
3173 shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id));
3174 if (shadowed)
3175 {
3176 if (!DECL_ERROR_REPORTED (id))
3177 {
3178 warning ("name lookup of `%s' changed",
3179 IDENTIFIER_POINTER (token));
3180 cp_warning_at (" matches this `%D' under ISO standard rules",
3181 shadowed);
3182 cp_warning_at (" matches this `%D' under old rules", id);
3183 DECL_ERROR_REPORTED (id) = 1;
3184 }
3185 id = shadowed;
3186 }
3187 else if (!DECL_ERROR_REPORTED (id))
3188 {
3189 DECL_ERROR_REPORTED (id) = 1;
3190 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (id)))
3191 {
3192 error ("name lookup of `%s' changed for new ISO `for' scoping",
3193 IDENTIFIER_POINTER (token));
3194 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id);
3195 id = error_mark_node;
3196 }
3197 else
3198 {
3199 pedwarn ("name lookup of `%s' changed for new ISO `for' scoping",
3200 IDENTIFIER_POINTER (token));
3201 cp_pedwarn_at (" using obsolete binding at `%D'", id);
3202 }
3203 }
3204 }
3205 /* TREE_USED is set in `hack_identifier'. */
3206 if (TREE_CODE (id) == CONST_DECL)
3207 {
3208 /* Check access. */
3209 if (IDENTIFIER_CLASS_VALUE (token) == id)
3210 enforce_access (CP_DECL_CONTEXT(id), id);
3211 if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
3212 id = DECL_INITIAL (id);
3213 }
3214 else
3215 id = hack_identifier (id, token);
3216
3217 /* We must look up dependent names when the template is
3218 instantiated, not while parsing it. For now, we don't
3219 distinguish between dependent and independent names. So, for
3220 example, we look up all overloaded functions at
3221 instantiation-time, even though in some cases we should just use
3222 the DECL we have here. We also use LOOKUP_EXPRs to find things
3223 like local variables, rather than creating TEMPLATE_DECLs for the
3224 local variables and then finding matching instantiations. */
3225 if (current_template_parms
3226 && (is_overloaded_fn (id)
3227 /* Some local VAR_DECLs (such as those for local variables
3228 in member functions of local classes) are built on the
3229 permanent obstack. */
3230 || (TREE_CODE (id) == VAR_DECL
3231 && CP_DECL_CONTEXT (id)
3232 && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL)
3233 || TREE_CODE (id) == PARM_DECL
3234 || TREE_CODE (id) == RESULT_DECL
3235 || TREE_CODE (id) == USING_DECL))
3236 id = build_min_nt (LOOKUP_EXPR, token);
3237
3238 return id;
3239 }
3240
3241 tree
3242 do_scoped_id (token, parsing)
3243 tree token;
3244 int parsing;
3245 {
3246 tree id;
3247 /* during parsing, this is ::name. Otherwise, it is black magic. */
3248 if (parsing)
3249 {
3250 id = make_node (CPLUS_BINDING);
3251 if (!qualified_lookup_using_namespace (token, global_namespace, id, 0))
3252 id = NULL_TREE;
3253 else
3254 id = BINDING_VALUE (id);
3255 }
3256 else
3257 id = IDENTIFIER_GLOBAL_VALUE (token);
3258 if (parsing && yychar == YYEMPTY)
3259 yychar = yylex ();
3260 if (! id)
3261 {
3262 if (processing_template_decl)
3263 {
3264 id = build_min_nt (LOOKUP_EXPR, token);
3265 LOOKUP_EXPR_GLOBAL (id) = 1;
3266 return id;
3267 }
3268 if (parsing && (yychar == '(' || yychar == LEFT_RIGHT)
3269 && ! flag_strict_prototype)
3270 id = implicitly_declare (token);
3271 else
3272 {
3273 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
3274 cp_error ("`::%D' undeclared (first use here)", token);
3275 id = error_mark_node;
3276 /* Prevent repeated error messages. */
3277 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3278 }
3279 }
3280 else
3281 {
3282 if (TREE_CODE (id) == ADDR_EXPR)
3283 mark_used (TREE_OPERAND (id, 0));
3284 else if (TREE_CODE (id) != OVERLOAD)
3285 mark_used (id);
3286 }
3287 if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
3288 {
3289 /* XXX CHS - should we set TREE_USED of the constant? */
3290 id = DECL_INITIAL (id);
3291 /* This is to prevent an enum whose value is 0
3292 from being considered a null pointer constant. */
3293 id = build1 (NOP_EXPR, TREE_TYPE (id), id);
3294 TREE_CONSTANT (id) = 1;
3295 }
3296
3297 if (processing_template_decl)
3298 {
3299 if (is_overloaded_fn (id))
3300 {
3301 id = build_min_nt (LOOKUP_EXPR, token);
3302 LOOKUP_EXPR_GLOBAL (id) = 1;
3303 return id;
3304 }
3305 /* else just use the decl */
3306 }
3307 return convert_from_reference (id);
3308 }
3309
3310 tree
3311 identifier_typedecl_value (node)
3312 tree node;
3313 {
3314 tree t, type;
3315 type = IDENTIFIER_TYPE_VALUE (node);
3316 if (type == NULL_TREE)
3317 return NULL_TREE;
3318
3319 if (IDENTIFIER_BINDING (node))
3320 {
3321 t = IDENTIFIER_VALUE (node);
3322 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3323 return t;
3324 }
3325 if (IDENTIFIER_NAMESPACE_VALUE (node))
3326 {
3327 t = IDENTIFIER_NAMESPACE_VALUE (node);
3328 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3329 return t;
3330 }
3331
3332 /* Will this one ever happen? */
3333 if (TYPE_MAIN_DECL (type))
3334 return TYPE_MAIN_DECL (type);
3335
3336 /* We used to do an internal error of 62 here, but instead we will
3337 handle the return of a null appropriately in the callers. */
3338 return NULL_TREE;
3339 }
3340
3341 struct pf_args
3342 {
3343 /* Input */
3344 int base;
3345 char * p;
3346 /* I/O */
3347 int c;
3348 /* Output */
3349 int imag;
3350 tree type;
3351 int conversion_errno;
3352 REAL_VALUE_TYPE value;
3353 };
3354
3355 static void
3356 parse_float (data)
3357 PTR data;
3358 {
3359 struct pf_args * args = (struct pf_args *) data;
3360 int fflag = 0, lflag = 0;
3361 /* Copy token_buffer now, while it has just the number
3362 and not the suffixes; once we add `f' or `i',
3363 REAL_VALUE_ATOF may not work any more. */
3364 char *copy = (char *) alloca (args->p - token_buffer + 1);
3365 bcopy (token_buffer, copy, args->p - token_buffer + 1);
3366 args->imag = 0;
3367 args->conversion_errno = 0;
3368 args->type = double_type_node;
3369
3370 while (1)
3371 {
3372 int lose = 0;
3373
3374 /* Read the suffixes to choose a data type. */
3375 switch (args->c)
3376 {
3377 case 'f': case 'F':
3378 if (fflag)
3379 error ("more than one `f' in numeric constant");
3380 fflag = 1;
3381 break;
3382
3383 case 'l': case 'L':
3384 if (lflag)
3385 error ("more than one `l' in numeric constant");
3386 lflag = 1;
3387 break;
3388
3389 case 'i': case 'I':
3390 if (args->imag)
3391 error ("more than one `i' or `j' in numeric constant");
3392 else if (pedantic)
3393 pedwarn ("ISO C++ forbids imaginary numeric constants");
3394 args->imag = 1;
3395 break;
3396
3397 default:
3398 lose = 1;
3399 }
3400
3401 if (lose)
3402 break;
3403
3404 if (args->p >= token_buffer + maxtoken - 3)
3405 args->p = extend_token_buffer (args->p);
3406 *(args->p++) = args->c;
3407 *(args->p) = 0;
3408 args->c = getch ();
3409 }
3410
3411 /* The second argument, machine_mode, of REAL_VALUE_ATOF
3412 tells the desired precision of the binary result
3413 of decimal-to-binary conversion. */
3414
3415 if (fflag)
3416 {
3417 if (lflag)
3418 error ("both `f' and `l' in floating constant");
3419
3420 args->type = float_type_node;
3421 errno = 0;
3422 if (args->base == 16)
3423 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3424 else
3425 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3426 args->conversion_errno = errno;
3427 /* A diagnostic is required here by some ANSI C testsuites.
3428 This is not pedwarn, because some people don't want
3429 an error for this. */
3430 if (REAL_VALUE_ISINF (args->value) && pedantic)
3431 warning ("floating point number exceeds range of `float'");
3432 }
3433 else if (lflag)
3434 {
3435 args->type = long_double_type_node;
3436 errno = 0;
3437 if (args->base == 16)
3438 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3439 else
3440 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3441 args->conversion_errno = errno;
3442 if (REAL_VALUE_ISINF (args->value) && pedantic)
3443 warning ("floating point number exceeds range of `long double'");
3444 }
3445 else
3446 {
3447 errno = 0;
3448 if (args->base == 16)
3449 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3450 else
3451 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3452 args->conversion_errno = errno;
3453 if (REAL_VALUE_ISINF (args->value) && pedantic)
3454 warning ("floating point number exceeds range of `double'");
3455 }
3456 }
3457
3458 /* Get the next character, staying within the current token if possible.
3459 If we're lexing a token, we don't want to look beyond the end of the
3460 token cpplib has prepared for us; otherwise, we end up reading in the
3461 next token, which screws up feed_input. So just return a null
3462 character. */
3463
3464 static int
3465 token_getch ()
3466 {
3467 #if USE_CPPLIB
3468 if (yy_cur == yy_lim)
3469 return '\0';
3470 #endif
3471 return getch ();
3472 }
3473
3474 static void
3475 token_put_back (ch)
3476 int ch;
3477 {
3478 #if USE_CPPLIB
3479 if (ch == '\0')
3480 return;
3481 #endif
3482 put_back (ch);
3483 }
3484
3485 /* Read a single token from the input stream, and assign it lexical
3486 semantics.
3487
3488 Note: We used to do token pasting here, to produce compound tokens like
3489 LEFT_RIGHT and EXTERN_LANG_STRING. That's now handled in spew.c, along
3490 with symbol table interaction and other context-sensitivity. */
3491
3492 int
3493 real_yylex ()
3494 {
3495 register int c;
3496 register char *p;
3497 register int value;
3498 int wide_flag = 0;
3499
3500 c = getch ();
3501
3502 /* Effectively do c = skip_white_space (c)
3503 but do it faster in the usual cases. */
3504 while (1)
3505 switch (c)
3506 {
3507 case ' ':
3508 case '\t':
3509 case '\f':
3510 case '\v':
3511 case '\b':
3512 #if USE_CPPLIB
3513 if (cpp_token == CPP_HSPACE)
3514 c = yy_get_token ();
3515 else
3516 #endif
3517 c = getch ();
3518 break;
3519
3520 case '\r':
3521 /* Call skip_white_space so we can warn if appropriate. */
3522
3523 case '\n':
3524 case '/':
3525 case '\\':
3526 c = skip_white_space (c);
3527 default:
3528 goto found_nonwhite;
3529 }
3530 found_nonwhite:
3531
3532 token_buffer[0] = c;
3533 token_buffer[1] = 0;
3534
3535 /* yylloc.first_line = lineno; */
3536
3537 switch (c)
3538 {
3539 case EOF:
3540 end_of_file = 1;
3541 token_buffer[0] = 0;
3542 if (linemode)
3543 value = END_OF_LINE;
3544 else if (input_redirected ())
3545 value = END_OF_SAVED_INPUT;
3546 else
3547 value = ENDFILE;
3548 break;
3549
3550 case 'L':
3551 #if USE_CPPLIB
3552 if (cpp_token == CPP_NAME)
3553 goto letter;
3554 #endif
3555 /* Capital L may start a wide-string or wide-character constant. */
3556 {
3557 register int c = token_getch ();
3558 if (c == '\'')
3559 {
3560 wide_flag = 1;
3561 goto char_constant;
3562 }
3563 if (c == '"')
3564 {
3565 wide_flag = 1;
3566 goto string_constant;
3567 }
3568 token_put_back (c);
3569 }
3570
3571 case 'A': case 'B': case 'C': case 'D': case 'E':
3572 case 'F': case 'G': case 'H': case 'I': case 'J':
3573 case 'K': case 'M': case 'N': case 'O':
3574 case 'P': case 'Q': case 'R': case 'S': case 'T':
3575 case 'U': case 'V': case 'W': case 'X': case 'Y':
3576 case 'Z':
3577 case 'a': case 'b': case 'c': case 'd': case 'e':
3578 case 'f': case 'g': case 'h': case 'i': case 'j':
3579 case 'k': case 'l': case 'm': case 'n': case 'o':
3580 case 'p': case 'q': case 'r': case 's': case 't':
3581 case 'u': case 'v': case 'w': case 'x': case 'y':
3582 case 'z':
3583 case '_':
3584 case '$':
3585 letter:
3586 #if USE_CPPLIB
3587 if (cpp_token == CPP_NAME)
3588 {
3589 /* Note that one character has already been read from
3590 yy_cur into token_buffer. Also, cpplib complains about
3591 $ in identifiers, so we don't have to. */
3592
3593 int len = yy_lim - yy_cur + 1;
3594 if (len >= maxtoken)
3595 extend_token_buffer_to (len + 1);
3596 memcpy (token_buffer + 1, yy_cur, len);
3597 p = token_buffer + len;
3598 yy_cur = yy_lim;
3599 }
3600 else
3601 #endif
3602 {
3603 p = token_buffer;
3604 while (1)
3605 {
3606 /* Make sure this char really belongs in an identifier. */
3607 if (ISALNUM (c) || c == '_')
3608 /* OK */;
3609 else if (c == '$')
3610 {
3611 if (! dollars_in_ident)
3612 error ("`$' in identifier");
3613 else if (pedantic)
3614 pedwarn ("`$' in identifier");
3615 }
3616 /* FIXME we should use some sort of multibyte character
3617 encoding. Locale-dependent? Always UTF-8? */
3618 else if (is_extended_char (c))
3619 {
3620 sorry ("universal characters in identifiers");
3621 c = '_';
3622 }
3623 else
3624 break;
3625
3626 if (p >= token_buffer + maxtoken)
3627 p = extend_token_buffer (p);
3628
3629 *p++ = c;
3630
3631 idtryagain:
3632 c = token_getch ();
3633
3634 if (c == '\\')
3635 {
3636 int ignore = 0;
3637 c = readescape (&ignore);
3638 if (ignore)
3639 goto idtryagain;
3640 }
3641 }
3642
3643 *p = 0;
3644 token_put_back (c);
3645 }
3646
3647 value = IDENTIFIER;
3648 yylval.itype = 0;
3649
3650 /* Try to recognize a keyword. Uses minimum-perfect hash function */
3651
3652 {
3653 register struct resword *ptr;
3654
3655 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
3656 {
3657 if (ptr->rid)
3658 {
3659 if (ptr->token == VISSPEC)
3660 {
3661 switch (ptr->rid)
3662 {
3663 case RID_PUBLIC:
3664 yylval.ttype = access_public_node;
3665 break;
3666 case RID_PRIVATE:
3667 yylval.ttype = access_private_node;
3668 break;
3669 case RID_PROTECTED:
3670 yylval.ttype = access_protected_node;
3671 break;
3672 default:
3673 my_friendly_abort (63);
3674 }
3675 }
3676 else
3677 yylval.ttype = ridpointers[(int) ptr->rid];
3678 }
3679 else switch (ptr->token)
3680 {
3681 case EQCOMPARE:
3682 yylval.code = NE_EXPR;
3683 token_buffer[0] = '!';
3684 token_buffer[1] = '=';
3685 token_buffer[2] = 0;
3686 break;
3687
3688 case ASSIGN:
3689 if (strcmp ("and_eq", token_buffer) == 0)
3690 {
3691 yylval.code = BIT_AND_EXPR;
3692 token_buffer[0] = '&';
3693 }
3694 else if (strcmp ("or_eq", token_buffer) == 0)
3695 {
3696 yylval.code = BIT_IOR_EXPR;
3697 token_buffer[0] = '|';
3698 }
3699 else if (strcmp ("xor_eq", token_buffer) == 0)
3700 {
3701 yylval.code = BIT_XOR_EXPR;
3702 token_buffer[0] = '^';
3703 }
3704 token_buffer[1] = '=';
3705 token_buffer[2] = 0;
3706 break;
3707
3708 case '&':
3709 yylval.code = BIT_AND_EXPR;
3710 token_buffer[0] = '&';
3711 token_buffer[1] = 0;
3712 break;
3713
3714 case '|':
3715 yylval.code = BIT_IOR_EXPR;
3716 token_buffer[0] = '|';
3717 token_buffer[1] = 0;
3718 break;
3719
3720 case '^':
3721 yylval.code = BIT_XOR_EXPR;
3722 token_buffer[0] = '^';
3723 token_buffer[1] = 0;
3724 break;
3725 }
3726
3727 value = (int) ptr->token;
3728 }
3729 }
3730
3731 /* If we did not find a keyword, look for an identifier
3732 (or a typename). */
3733
3734 if (value == IDENTIFIER || value == TYPESPEC)
3735 GNU_xref_ref (current_function_decl, token_buffer);
3736
3737 if (value == IDENTIFIER)
3738 {
3739 register tree tmp = get_identifier (token_buffer);
3740
3741 #if !defined(VMS) && defined(JOINER)
3742 /* Make sure that user does not collide with our internal
3743 naming scheme. */
3744 if (JOINER == '$'
3745 && (THIS_NAME_P (tmp)
3746 || VPTR_NAME_P (tmp)
3747 || DESTRUCTOR_NAME_P (tmp)
3748 || VTABLE_NAME_P (tmp)
3749 || TEMP_NAME_P (tmp)
3750 || ANON_AGGRNAME_P (tmp)
3751 || ANON_PARMNAME_P (tmp)))
3752 warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3753 token_buffer);
3754 #endif
3755
3756 yylval.ttype = tmp;
3757 }
3758 if (value == NEW && ! global_bindings_p ())
3759 {
3760 value = NEW;
3761 goto done;
3762 }
3763 break;
3764
3765 case '.':
3766 #if USE_CPPLIB
3767 if (yy_cur < yy_lim)
3768 #endif
3769 {
3770 /* It's hard to preserve tokenization on '.' because
3771 it could be a symbol by itself, or it could be the
3772 start of a floating point number and cpp won't tell us. */
3773 register int c1 = token_getch ();
3774 token_buffer[1] = c1;
3775 if (c1 == '*')
3776 {
3777 value = DOT_STAR;
3778 token_buffer[2] = 0;
3779 goto done;
3780 }
3781 if (c1 == '.')
3782 {
3783 c1 = token_getch ();
3784 if (c1 == '.')
3785 {
3786 token_buffer[2] = c1;
3787 token_buffer[3] = 0;
3788 value = ELLIPSIS;
3789 goto done;
3790 }
3791 error ("parse error at `..'");
3792 }
3793 if (ISDIGIT (c1))
3794 {
3795 token_put_back (c1);
3796 goto number;
3797 }
3798 token_put_back (c1);
3799 }
3800 value = '.';
3801 token_buffer[1] = 0;
3802 break;
3803
3804 case '0': case '1':
3805 /* Optimize for most frequent case. */
3806 {
3807 register int cond;
3808
3809 #if USE_CPPLIB
3810 cond = (yy_cur == yy_lim);
3811 #else
3812 register int c1 = token_getch ();
3813 token_put_back (c1);
3814 cond = (! ISALNUM (c1) && c1 != '.');
3815 #endif
3816 if (cond)
3817 {
3818 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
3819 value = CONSTANT;
3820 break;
3821 }
3822 /*FALLTHRU*/
3823 }
3824 case '2': case '3': case '4':
3825 case '5': case '6': case '7': case '8': case '9':
3826 number:
3827 {
3828 int base = 10;
3829 int count = 0;
3830 int largest_digit = 0;
3831 int numdigits = 0;
3832 int overflow = 0;
3833
3834 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
3835 The code below which fills the parts array assumes that a host
3836 int is at least twice as wide as a host char, and that
3837 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
3838 Two HOST_WIDE_INTs is the largest int literal we can store.
3839 In order to detect overflow below, the number of parts (TOTAL_PARTS)
3840 must be exactly the number of parts needed to hold the bits
3841 of two HOST_WIDE_INTs. */
3842 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
3843 unsigned int parts[TOTAL_PARTS];
3844
3845 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON }
3846 floatflag = NOT_FLOAT;
3847
3848 for (count = 0; count < TOTAL_PARTS; count++)
3849 parts[count] = 0;
3850
3851 p = token_buffer;
3852 *p++ = c;
3853
3854 if (c == '0')
3855 {
3856 *p++ = (c = token_getch ());
3857 if ((c == 'x') || (c == 'X'))
3858 {
3859 base = 16;
3860 *p++ = (c = token_getch ());
3861 }
3862 /* Leading 0 forces octal unless the 0 is the only digit. */
3863 else if (c >= '0' && c <= '9')
3864 {
3865 base = 8;
3866 numdigits++;
3867 }
3868 else
3869 numdigits++;
3870 }
3871
3872 /* Read all the digits-and-decimal-points. */
3873
3874 while (c == '.'
3875 || (ISALNUM (c) && c != 'l' && c != 'L'
3876 && c != 'u' && c != 'U'
3877 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
3878 && (floatflag == NOT_FLOAT
3879 || ((base != 16) && (c != 'f') && (c != 'F'))
3880 || base == 16)))
3881 {
3882 if (c == '.')
3883 {
3884 if (base == 16 && pedantic)
3885 pedwarn ("floating constant may not be in radix 16");
3886 if (floatflag == TOO_MANY_POINTS)
3887 /* We have already emitted an error. Don't need another. */
3888 ;
3889 else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON)
3890 {
3891 error ("malformed floating constant");
3892 floatflag = TOO_MANY_POINTS;
3893 /* Avoid another error from atof by forcing all characters
3894 from here on to be ignored. */
3895 p[-1] = '\0';
3896 }
3897 else
3898 floatflag = AFTER_POINT;
3899
3900 if (base == 8)
3901 base = 10;
3902 *p++ = c = token_getch ();
3903 /* Accept '.' as the start of a floating-point number
3904 only when it is followed by a digit. */
3905 if (p == token_buffer + 2 && !ISDIGIT (c))
3906 my_friendly_abort (990710);
3907 }
3908 else
3909 {
3910 /* It is not a decimal point.
3911 It should be a digit (perhaps a hex digit). */
3912
3913 if (ISDIGIT (c))
3914 {
3915 c = c - '0';
3916 }
3917 else if (base <= 10)
3918 {
3919 if (c == 'e' || c == 'E')
3920 {
3921 base = 10;
3922 floatflag = AFTER_EXPON;
3923 break; /* start of exponent */
3924 }
3925 error ("nondigits in number and not hexadecimal");
3926 c = 0;
3927 }
3928 else if (base == 16 && (c == 'p' || c == 'P'))
3929 {
3930 floatflag = AFTER_EXPON;
3931 break; /* start of exponent */
3932 }
3933 else if (c >= 'a')
3934 {
3935 c = c - 'a' + 10;
3936 }
3937 else
3938 {
3939 c = c - 'A' + 10;
3940 }
3941 if (c >= largest_digit)
3942 largest_digit = c;
3943 numdigits++;
3944
3945 for (count = 0; count < TOTAL_PARTS; count++)
3946 {
3947 parts[count] *= base;
3948 if (count)
3949 {
3950 parts[count]
3951 += (parts[count-1] >> HOST_BITS_PER_CHAR);
3952 parts[count-1]
3953 &= (1 << HOST_BITS_PER_CHAR) - 1;
3954 }
3955 else
3956 parts[0] += c;
3957 }
3958
3959 /* If the highest-order part overflows (gets larger than
3960 a host char will hold) then the whole number has
3961 overflowed. Record this and truncate the highest-order
3962 part. */
3963 if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
3964 {
3965 overflow = 1;
3966 parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
3967 }
3968
3969 if (p >= token_buffer + maxtoken - 3)
3970 p = extend_token_buffer (p);
3971 *p++ = (c = token_getch ());
3972 }
3973 }
3974
3975 /* This can happen on input like `int i = 0x;' */
3976 if (numdigits == 0)
3977 error ("numeric constant with no digits");
3978
3979 if (largest_digit >= base)
3980 error ("numeric constant contains digits beyond the radix");
3981
3982 /* Remove terminating char from the token buffer and delimit the
3983 string. */
3984 *--p = 0;
3985
3986 if (floatflag != NOT_FLOAT)
3987 {
3988 tree type;
3989 int imag, conversion_errno;
3990 REAL_VALUE_TYPE value;
3991 struct pf_args args;
3992
3993 /* Read explicit exponent if any, and put it in tokenbuf. */
3994
3995 if ((base == 10 && ((c == 'e') || (c == 'E')))
3996 || (base == 16 && (c == 'p' || c == 'P')))
3997 {
3998 if (p >= token_buffer + maxtoken - 3)
3999 p = extend_token_buffer (p);
4000 *p++ = c;
4001 c = token_getch ();
4002 if ((c == '+') || (c == '-'))
4003 {
4004 *p++ = c;
4005 c = token_getch ();
4006 }
4007 /* Exponent is decimal, even if string is a hex float. */
4008 if (! ISDIGIT (c))
4009 error ("floating constant exponent has no digits");
4010 while (ISDIGIT (c))
4011 {
4012 if (p >= token_buffer + maxtoken - 3)
4013 p = extend_token_buffer (p);
4014 *p++ = c;
4015 c = token_getch ();
4016 }
4017 }
4018 if (base == 16 && floatflag != AFTER_EXPON)
4019 error ("hexadecimal floating constant has no exponent");
4020
4021 *p = 0;
4022
4023 /* Setup input for parse_float() */
4024 args.base = base;
4025 args.p = p;
4026 args.c = c;
4027
4028 /* Convert string to a double, checking for overflow. */
4029 if (do_float_handler (parse_float, (PTR) &args))
4030 {
4031 /* Receive output from parse_float() */
4032 value = args.value;
4033 }
4034 else
4035 {
4036 /* We got an exception from parse_float() */
4037 error ("floating constant out of range");
4038 value = dconst0;
4039 }
4040
4041 /* Receive output from parse_float() */
4042 c = args.c;
4043 imag = args.imag;
4044 type = args.type;
4045 conversion_errno = args.conversion_errno;
4046
4047 #ifdef ERANGE
4048 /* ERANGE is also reported for underflow,
4049 so test the value to distinguish overflow from that. */
4050 if (conversion_errno == ERANGE && pedantic
4051 && (REAL_VALUES_LESS (dconst1, value)
4052 || REAL_VALUES_LESS (value, dconstm1)))
4053 warning ("floating point number exceeds range of `double'");
4054 #endif
4055
4056 /* If the result is not a number, assume it must have been
4057 due to some error message above, so silently convert
4058 it to a zero. */
4059 if (REAL_VALUE_ISNAN (value))
4060 value = dconst0;
4061
4062 /* Create a node with determined type and value. */
4063 if (imag)
4064 yylval.ttype = build_complex (NULL_TREE,
4065 convert (type, integer_zero_node),
4066 build_real (type, value));
4067 else
4068 yylval.ttype = build_real (type, value);
4069 }
4070 else
4071 {
4072 tree type;
4073 HOST_WIDE_INT high, low;
4074 int spec_unsigned = 0;
4075 int spec_long = 0;
4076 int spec_long_long = 0;
4077 int spec_imag = 0;
4078 int warn = 0;
4079 int i;
4080
4081 while (1)
4082 {
4083 if (c == 'u' || c == 'U')
4084 {
4085 if (spec_unsigned)
4086 error ("two `u's in integer constant");
4087 spec_unsigned = 1;
4088 }
4089 else if (c == 'l' || c == 'L')
4090 {
4091 if (spec_long)
4092 {
4093 if (spec_long_long)
4094 error ("three `l's in integer constant");
4095 else if (pedantic && ! in_system_header && warn_long_long)
4096 pedwarn ("ISO C++ forbids long long integer constants");
4097 spec_long_long = 1;
4098 }
4099 spec_long = 1;
4100 }
4101 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
4102 {
4103 if (spec_imag)
4104 error ("more than one `i' or `j' in numeric constant");
4105 else if (pedantic)
4106 pedwarn ("ISO C++ forbids imaginary numeric constants");
4107 spec_imag = 1;
4108 }
4109 else
4110 break;
4111 if (p >= token_buffer + maxtoken - 3)
4112 p = extend_token_buffer (p);
4113 *p++ = c;
4114 c = token_getch ();
4115 }
4116
4117 /* If the literal overflowed, pedwarn about it now. */
4118 if (overflow)
4119 {
4120 warn = 1;
4121 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
4122 }
4123
4124 /* This is simplified by the fact that our constant
4125 is always positive. */
4126
4127 high = low = 0;
4128
4129 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
4130 {
4131 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
4132 / HOST_BITS_PER_CHAR)]
4133 << (i * HOST_BITS_PER_CHAR));
4134 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
4135 }
4136
4137 yylval.ttype = build_int_2 (low, high);
4138 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
4139
4140 /* Calculate the ANSI type. */
4141 if (! spec_long && ! spec_unsigned
4142 && int_fits_type_p (yylval.ttype, integer_type_node))
4143 type = integer_type_node;
4144 else if (! spec_long && (base != 10 || spec_unsigned)
4145 && int_fits_type_p (yylval.ttype, unsigned_type_node))
4146 type = unsigned_type_node;
4147 else if (! spec_unsigned && !spec_long_long
4148 && int_fits_type_p (yylval.ttype, long_integer_type_node))
4149 type = long_integer_type_node;
4150 else if (! spec_long_long
4151 && int_fits_type_p (yylval.ttype,
4152 long_unsigned_type_node))
4153 type = long_unsigned_type_node;
4154 else if (! spec_unsigned
4155 && int_fits_type_p (yylval.ttype,
4156 long_long_integer_type_node))
4157 type = long_long_integer_type_node;
4158 else if (int_fits_type_p (yylval.ttype,
4159 long_long_unsigned_type_node))
4160 type = long_long_unsigned_type_node;
4161 else if (! spec_unsigned
4162 && int_fits_type_p (yylval.ttype,
4163 widest_integer_literal_type_node))
4164 type = widest_integer_literal_type_node;
4165 else
4166 type = widest_unsigned_literal_type_node;
4167
4168 if (pedantic && !spec_long_long && !warn
4169 && (TYPE_PRECISION (long_integer_type_node)
4170 < TYPE_PRECISION (type)))
4171 {
4172 warn = 1;
4173 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
4174 }
4175
4176 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
4177 warning ("decimal constant is so large that it is unsigned");
4178
4179 if (spec_imag)
4180 {
4181 if (TYPE_PRECISION (type)
4182 <= TYPE_PRECISION (integer_type_node))
4183 yylval.ttype
4184 = build_complex (NULL_TREE, integer_zero_node,
4185 convert (integer_type_node,
4186 yylval.ttype));
4187 else
4188 error ("complex integer constant is too wide for `__complex int'");
4189 }
4190 else
4191 TREE_TYPE (yylval.ttype) = type;
4192
4193
4194 /* If it's still an integer (not a complex), and it doesn't
4195 fit in the type we choose for it, then pedwarn. */
4196
4197 if (! warn
4198 && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
4199 && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
4200 pedwarn ("integer constant is larger than the maximum value for its type");
4201 }
4202
4203 token_put_back (c);
4204 *p = 0;
4205
4206 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
4207 || ((c == '-' || c == '+')
4208 && (p[-1] == 'e' || p[-1] == 'E')))
4209 error ("missing white space after number `%s'", token_buffer);
4210
4211 value = CONSTANT; break;
4212 }
4213
4214 case '\'':
4215 char_constant:
4216 {
4217 register int result = 0;
4218 register int num_chars = 0;
4219 int chars_seen = 0;
4220 unsigned width = TYPE_PRECISION (char_type_node);
4221 int max_chars;
4222 #ifdef MULTIBYTE_CHARS
4223 int longest_char = local_mb_cur_max ();
4224 local_mbtowc (NULL_PTR, NULL_PTR, 0);
4225 #endif
4226
4227 max_chars = TYPE_PRECISION (integer_type_node) / width;
4228 if (wide_flag)
4229 width = WCHAR_TYPE_SIZE;
4230
4231 while (1)
4232 {
4233 tryagain:
4234 c = token_getch ();
4235
4236 if (c == '\'' || c == EOF)
4237 break;
4238
4239 ++chars_seen;
4240 if (c == '\\')
4241 {
4242 int ignore = 0;
4243 c = readescape (&ignore);
4244 if (ignore)
4245 goto tryagain;
4246 if (width < HOST_BITS_PER_INT
4247 && (unsigned) c >= ((unsigned)1 << width))
4248 pedwarn ("escape sequence out of range for character");
4249 #ifdef MAP_CHARACTER
4250 if (ISPRINT (c))
4251 c = MAP_CHARACTER (c);
4252 #endif
4253 }
4254 else if (c == '\n')
4255 {
4256 if (pedantic)
4257 pedwarn ("ISO C++ forbids newline in character constant");
4258 lineno++;
4259 }
4260 else
4261 {
4262 #ifdef MULTIBYTE_CHARS
4263 wchar_t wc;
4264 int i;
4265 int char_len = -1;
4266 for (i = 1; i <= longest_char; ++i)
4267 {
4268 if (i > maxtoken - 4)
4269 extend_token_buffer (token_buffer);
4270
4271 token_buffer[i] = c;
4272 char_len = local_mbtowc (& wc,
4273 token_buffer + 1,
4274 i);
4275 if (char_len != -1)
4276 break;
4277 c = token_getch ();
4278 }
4279 if (char_len > 1)
4280 {
4281 /* mbtowc sometimes needs an extra char before accepting */
4282 if (char_len < i)
4283 token_put_back (c);
4284 if (! wide_flag)
4285 {
4286 /* Merge character into result; ignore excess chars. */
4287 for (i = 1; i <= char_len; ++i)
4288 {
4289 if (i > max_chars)
4290 break;
4291 if (width < HOST_BITS_PER_INT)
4292 result = (result << width)
4293 | (token_buffer[i]
4294 & ((1 << width) - 1));
4295 else
4296 result = token_buffer[i];
4297 }
4298 num_chars += char_len;
4299 goto tryagain;
4300 }
4301 c = wc;
4302 }
4303 else
4304 {
4305 if (char_len == -1)
4306 {
4307 warning ("Ignoring invalid multibyte character");
4308 /* Replace all but the first byte. */
4309 for (--i; i > 1; --i)
4310 token_put_back (token_buffer[i]);
4311 wc = token_buffer[1];
4312 }
4313 #ifdef MAP_CHARACTER
4314 c = MAP_CHARACTER (wc);
4315 #else
4316 c = wc;
4317 #endif
4318 }
4319 #else /* ! MULTIBYTE_CHARS */
4320 #ifdef MAP_CHARACTER
4321 c = MAP_CHARACTER (c);
4322 #endif
4323 #endif /* ! MULTIBYTE_CHARS */
4324 }
4325
4326 if (wide_flag)
4327 {
4328 if (chars_seen == 1) /* only keep the first one */
4329 result = c;
4330 goto tryagain;
4331 }
4332
4333 /* Merge character into result; ignore excess chars. */
4334 num_chars += (width / TYPE_PRECISION (char_type_node));
4335 if (num_chars < max_chars + 1)
4336 {
4337 if (width < HOST_BITS_PER_INT)
4338 result = (result << width) | (c & ((1 << width) - 1));
4339 else
4340 result = c;
4341 }
4342 }
4343
4344 if (c != '\'')
4345 error ("malformatted character constant");
4346 else if (chars_seen == 0)
4347 error ("empty character constant");
4348 else if (num_chars > max_chars)
4349 {
4350 num_chars = max_chars;
4351 error ("character constant too long");
4352 }
4353 else if (chars_seen != 1 && warn_multichar)
4354 warning ("multi-character character constant");
4355
4356 /* If char type is signed, sign-extend the constant. */
4357 if (! wide_flag)
4358 {
4359 int num_bits = num_chars * width;
4360 if (num_bits == 0)
4361 /* We already got an error; avoid invalid shift. */
4362 yylval.ttype = build_int_2 (0, 0);
4363 else if (TREE_UNSIGNED (char_type_node)
4364 || ((result >> (num_bits - 1)) & 1) == 0)
4365 yylval.ttype
4366 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
4367 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4368 0);
4369 else
4370 yylval.ttype
4371 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
4372 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4373 -1);
4374 /* In C, a character constant has type 'int'; in C++, 'char'. */
4375 if (chars_seen <= 1)
4376 TREE_TYPE (yylval.ttype) = char_type_node;
4377 else
4378 TREE_TYPE (yylval.ttype) = integer_type_node;
4379 }
4380 else
4381 {
4382 yylval.ttype = build_int_2 (result, 0);
4383 TREE_TYPE (yylval.ttype) = wchar_type_node;
4384 }
4385
4386 value = CONSTANT;
4387 break;
4388 }
4389
4390 case '"':
4391 string_constant:
4392 {
4393 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
4394 : TYPE_PRECISION (char_type_node);
4395 #ifdef MULTIBYTE_CHARS
4396 int longest_char = local_mb_cur_max ();
4397 local_mbtowc (NULL_PTR, NULL_PTR, 0);
4398 #endif
4399
4400 c = token_getch ();
4401 p = token_buffer + 1;
4402
4403 while (c != '"' && c != EOF)
4404 {
4405 /* ignore_escape_flag is set for reading the filename in #line. */
4406 if (!ignore_escape_flag && c == '\\')
4407 {
4408 int ignore = 0;
4409 c = readescape (&ignore);
4410 if (ignore)
4411 goto skipnewline;
4412 if (width < HOST_BITS_PER_INT
4413 && (unsigned) c >= ((unsigned)1 << width))
4414 pedwarn ("escape sequence out of range for character");
4415 }
4416 else if (c == '\n')
4417 {
4418 if (pedantic)
4419 pedwarn ("ISO C++ forbids newline in string constant");
4420 lineno++;
4421 }
4422 else
4423 {
4424 #ifdef MULTIBYTE_CHARS
4425 wchar_t wc;
4426 int i;
4427 int char_len = -1;
4428 for (i = 0; i < longest_char; ++i)
4429 {
4430 if (p + i >= token_buffer + maxtoken)
4431 p = extend_token_buffer (p);
4432 p[i] = c;
4433
4434 char_len = local_mbtowc (& wc, p, i + 1);
4435 if (char_len != -1)
4436 break;
4437 c = token_getch ();
4438 }
4439 if (char_len == -1)
4440 {
4441 warning ("Ignoring invalid multibyte character");
4442 /* Replace all except the first byte. */
4443 token_put_back (c);
4444 for (--i; i > 0; --i)
4445 token_put_back (p[i]);
4446 char_len = 1;
4447 }
4448 /* mbtowc sometimes needs an extra char before accepting */
4449 if (char_len <= i)
4450 token_put_back (c);
4451 if (! wide_flag)
4452 {
4453 p += (i + 1);
4454 c = token_getch ();
4455 continue;
4456 }
4457 c = wc;
4458 #endif /* MULTIBYTE_CHARS */
4459 }
4460
4461 /* Add this single character into the buffer either as a wchar_t
4462 or as a single byte. */
4463 if (wide_flag)
4464 {
4465 unsigned width = TYPE_PRECISION (char_type_node);
4466 unsigned bytemask = (1 << width) - 1;
4467 int byte;
4468
4469 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4470 p = extend_token_buffer (p);
4471
4472 for (byte = 0; byte < WCHAR_BYTES; ++byte)
4473 {
4474 int value;
4475 if (byte >= (int) sizeof (c))
4476 value = 0;
4477 else
4478 value = (c >> (byte * width)) & bytemask;
4479 if (BYTES_BIG_ENDIAN)
4480 p[WCHAR_BYTES - byte - 1] = value;
4481 else
4482 p[byte] = value;
4483 }
4484 p += WCHAR_BYTES;
4485 }
4486 else
4487 {
4488 if (p >= token_buffer + maxtoken)
4489 p = extend_token_buffer (p);
4490 *p++ = c;
4491 }
4492
4493 skipnewline:
4494 c = token_getch ();
4495 }
4496
4497 /* Terminate the string value, either with a single byte zero
4498 or with a wide zero. */
4499 if (wide_flag)
4500 {
4501 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4502 p = extend_token_buffer (p);
4503 bzero (p, WCHAR_BYTES);
4504 p += WCHAR_BYTES;
4505 }
4506 else
4507 {
4508 if (p >= token_buffer + maxtoken)
4509 p = extend_token_buffer (p);
4510 *p++ = 0;
4511 }
4512
4513 if (c == EOF)
4514 error ("Unterminated string constant");
4515
4516 /* We have read the entire constant.
4517 Construct a STRING_CST for the result. */
4518
4519 yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1);
4520
4521 if (wide_flag)
4522 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
4523 else
4524 TREE_TYPE (yylval.ttype) = char_array_type_node;
4525
4526 value = STRING; break;
4527 }
4528
4529 case '+':
4530 case '-':
4531 case '&':
4532 case '|':
4533 case ':':
4534 case '<':
4535 case '>':
4536 case '*':
4537 case '/':
4538 case '%':
4539 case '^':
4540 case '!':
4541 case '=':
4542 {
4543 register int c1;
4544
4545 combine:
4546
4547 switch (c)
4548 {
4549 case '+':
4550 yylval.code = PLUS_EXPR; break;
4551 case '-':
4552 yylval.code = MINUS_EXPR; break;
4553 case '&':
4554 yylval.code = BIT_AND_EXPR; break;
4555 case '|':
4556 yylval.code = BIT_IOR_EXPR; break;
4557 case '*':
4558 yylval.code = MULT_EXPR; break;
4559 case '/':
4560 yylval.code = TRUNC_DIV_EXPR; break;
4561 case '%':
4562 yylval.code = TRUNC_MOD_EXPR; break;
4563 case '^':
4564 yylval.code = BIT_XOR_EXPR; break;
4565 case LSHIFT:
4566 yylval.code = LSHIFT_EXPR; break;
4567 case RSHIFT:
4568 yylval.code = RSHIFT_EXPR; break;
4569 case '<':
4570 yylval.code = LT_EXPR; break;
4571 case '>':
4572 yylval.code = GT_EXPR; break;
4573 }
4574
4575 token_buffer[1] = c1 = token_getch ();
4576 token_buffer[2] = 0;
4577
4578 if (c1 == '=')
4579 {
4580 switch (c)
4581 {
4582 case '<':
4583 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
4584 case '>':
4585 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
4586 case '!':
4587 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
4588 case '=':
4589 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
4590 }
4591 value = ASSIGN; goto done;
4592 }
4593 else if (c == c1)
4594 switch (c)
4595 {
4596 case '+':
4597 value = PLUSPLUS; goto done;
4598 case '-':
4599 value = MINUSMINUS; goto done;
4600 case '&':
4601 value = ANDAND; goto done;
4602 case '|':
4603 value = OROR; goto done;
4604 case '<':
4605 c = LSHIFT;
4606 goto combine;
4607 case '>':
4608 c = RSHIFT;
4609 goto combine;
4610 case ':':
4611 value = SCOPE;
4612 yylval.itype = 1;
4613 goto done;
4614 }
4615 else if (c1 == '?' && (c == '<' || c == '>'))
4616 {
4617 token_buffer[3] = 0;
4618
4619 c1 = token_getch ();
4620 yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR);
4621 if (c1 == '=')
4622 {
4623 /* <?= or >?= expression. */
4624 token_buffer[2] = c1;
4625 value = ASSIGN;
4626 }
4627 else
4628 {
4629 value = MIN_MAX;
4630 token_put_back (c1);
4631 }
4632 if (pedantic)
4633 pedwarn ("use of `operator %s' is not standard C++",
4634 token_buffer);
4635 goto done;
4636 }
4637 else
4638 switch (c)
4639 {
4640 case '-':
4641 if (c1 == '>')
4642 {
4643 c1 = token_getch ();
4644 if (c1 == '*')
4645 value = POINTSAT_STAR;
4646 else
4647 {
4648 token_put_back (c1);
4649 value = POINTSAT;
4650 }
4651 goto done;
4652 }
4653 break;
4654
4655 /* digraphs */
4656 case ':':
4657 if (c1 == '>')
4658 { value = ']'; goto done; }
4659 break;
4660 case '<':
4661 if (c1 == '%')
4662 { value = '{'; indent_level++; goto done; }
4663 if (c1 == ':')
4664 { value = '['; goto done; }
4665 break;
4666 case '%':
4667 if (c1 == '>')
4668 { value = '}'; indent_level--; goto done; }
4669 break;
4670 }
4671
4672 token_put_back (c1);
4673 token_buffer[1] = 0;
4674
4675 /* Here the C frontend changes < and > to ARITHCOMPARE. We don't
4676 do that because of templates. */
4677
4678 value = c;
4679 break;
4680 }
4681
4682 case 0:
4683 /* Don't make yyparse think this is eof. */
4684 value = 1;
4685 break;
4686
4687 case '{':
4688 indent_level++;
4689 value = c;
4690 break;
4691
4692 case '}':
4693 indent_level--;
4694 value = c;
4695 break;
4696
4697 default:
4698 if (is_extended_char (c))
4699 goto letter;
4700 value = c;
4701 }
4702
4703 done:
4704 /* yylloc.last_line = lineno; */
4705 #ifdef GATHER_STATISTICS
4706 #ifdef REDUCE_LENGTH
4707 token_count[value] += 1;
4708 #endif
4709 #endif
4710
4711 return value;
4712 }
4713
4714 int
4715 is_rid (t)
4716 tree t;
4717 {
4718 return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
4719 }
4720
4721 #ifdef GATHER_STATISTICS
4722 /* The original for tree_node_kind is in the toplevel tree.c; changes there
4723 need to be brought into here, unless this were actually put into a header
4724 instead. */
4725 /* Statistics-gathering stuff. */
4726 typedef enum
4727 {
4728 d_kind,
4729 t_kind,
4730 b_kind,
4731 s_kind,
4732 r_kind,
4733 e_kind,
4734 c_kind,
4735 id_kind,
4736 op_id_kind,
4737 perm_list_kind,
4738 temp_list_kind,
4739 vec_kind,
4740 x_kind,
4741 lang_decl,
4742 lang_type,
4743 all_kinds
4744 } tree_node_kind;
4745
4746 extern int tree_node_counts[];
4747 extern int tree_node_sizes[];
4748 #endif
4749
4750 tree
4751 build_lang_decl (code, name, type)
4752 enum tree_code code;
4753 tree name;
4754 tree type;
4755 {
4756 tree t;
4757
4758 t = build_decl (code, name, type);
4759 retrofit_lang_decl (t);
4760
4761 return t;
4762 }
4763
4764 /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
4765 and pushdecl (for functions generated by the backend). */
4766
4767 void
4768 retrofit_lang_decl (t)
4769 tree t;
4770 {
4771 struct lang_decl *ld;
4772 size_t size;
4773
4774 if (CAN_HAVE_FULL_LANG_DECL_P (t))
4775 size = sizeof (struct lang_decl);
4776 else
4777 size = sizeof (struct lang_decl_flags);
4778
4779 ld = (struct lang_decl *) ggc_alloc_obj (size, 1);
4780
4781 DECL_LANG_SPECIFIC (t) = ld;
4782 if (current_lang_name == lang_name_cplusplus)
4783 DECL_LANGUAGE (t) = lang_cplusplus;
4784 else if (current_lang_name == lang_name_c)
4785 DECL_LANGUAGE (t) = lang_c;
4786 else if (current_lang_name == lang_name_java)
4787 DECL_LANGUAGE (t) = lang_java;
4788 else my_friendly_abort (64);
4789
4790 #ifdef GATHER_STATISTICS
4791 tree_node_counts[(int)lang_decl] += 1;
4792 tree_node_sizes[(int)lang_decl] += size;
4793 #endif
4794 }
4795
4796 void
4797 copy_lang_decl (node)
4798 tree node;
4799 {
4800 int size;
4801 struct lang_decl *ld;
4802
4803 if (! DECL_LANG_SPECIFIC (node))
4804 return;
4805
4806 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
4807 size = sizeof (struct lang_decl_flags);
4808 else
4809 size = sizeof (struct lang_decl);
4810 ld = (struct lang_decl *) ggc_alloc (size);
4811 bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)ld, size);
4812 DECL_LANG_SPECIFIC (node) = ld;
4813 }
4814
4815 /* Copy DECL, including any language-specific parts. */
4816
4817 tree
4818 copy_decl (decl)
4819 tree decl;
4820 {
4821 tree copy;
4822
4823 copy = copy_node (decl);
4824 copy_lang_decl (copy);
4825 return copy;
4826 }
4827
4828 tree
4829 cp_make_lang_type (code)
4830 enum tree_code code;
4831 {
4832 register tree t = make_node (code);
4833
4834 /* Set up some flags that give proper default behavior. */
4835 if (IS_AGGR_TYPE_CODE (code))
4836 {
4837 struct lang_type *pi;
4838
4839 pi = (struct lang_type *) ggc_alloc (sizeof (struct lang_type));
4840 bzero ((char *) pi, (int) sizeof (struct lang_type));
4841
4842 TYPE_LANG_SPECIFIC (t) = pi;
4843 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
4844 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
4845
4846 /* Make sure this is laid out, for ease of use later. In the
4847 presence of parse errors, the normal was of assuring this
4848 might not ever get executed, so we lay it out *immediately*. */
4849 build_pointer_type (t);
4850
4851 #ifdef GATHER_STATISTICS
4852 tree_node_counts[(int)lang_type] += 1;
4853 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
4854 #endif
4855 }
4856 else
4857 /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
4858 TYPE_ALIAS_SET is initialized to -1 by default, so we must
4859 clear it here. */
4860 TYPE_ALIAS_SET (t) = 0;
4861
4862 /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
4863 since they can be virtual base types, and we then need a
4864 canonical binfo for them. Ideally, this would be done lazily for
4865 all types. */
4866 if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM)
4867 TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
4868
4869 return t;
4870 }
4871
4872 tree
4873 make_aggr_type (code)
4874 enum tree_code code;
4875 {
4876 tree t = cp_make_lang_type (code);
4877
4878 if (IS_AGGR_TYPE_CODE (code))
4879 SET_IS_AGGR_TYPE (t, 1);
4880
4881 return t;
4882 }
4883
4884 void
4885 dump_time_statistics ()
4886 {
4887 register tree prev = 0, decl, next;
4888 int this_time = get_run_time ();
4889 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
4890 += this_time - body_time;
4891
4892 fprintf (stderr, "\n******\n");
4893 print_time ("header files (total)", header_time);
4894 print_time ("main file (total)", this_time - body_time);
4895 fprintf (stderr, "ratio = %g : 1\n",
4896 (double)header_time / (double)(this_time - body_time));
4897 fprintf (stderr, "\n******\n");
4898
4899 for (decl = filename_times; decl; decl = next)
4900 {
4901 next = IDENTIFIER_GLOBAL_VALUE (decl);
4902 SET_IDENTIFIER_GLOBAL_VALUE (decl, prev);
4903 prev = decl;
4904 }
4905
4906 for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl))
4907 print_time (IDENTIFIER_POINTER (decl),
4908 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (decl)));
4909 }
4910
4911 void
4912 compiler_error VPARAMS ((const char *msg, ...))
4913 {
4914 #ifndef ANSI_PROTOTYPES
4915 const char *msg;
4916 #endif
4917 char buf[1024];
4918 va_list ap;
4919
4920 VA_START (ap, msg);
4921
4922 #ifndef ANSI_PROTOTYPES
4923 msg = va_arg (ap, const char *);
4924 #endif
4925
4926 vsprintf (buf, msg, ap);
4927 va_end (ap);
4928 error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
4929 }
4930 \f
4931 /* Return the type-qualifier corresponding to the identifier given by
4932 RID. */
4933
4934 int
4935 cp_type_qual_from_rid (rid)
4936 tree rid;
4937 {
4938 if (rid == ridpointers[(int) RID_CONST])
4939 return TYPE_QUAL_CONST;
4940 else if (rid == ridpointers[(int) RID_VOLATILE])
4941 return TYPE_QUAL_VOLATILE;
4942 else if (rid == ridpointers[(int) RID_RESTRICT])
4943 return TYPE_QUAL_RESTRICT;
4944
4945 my_friendly_abort (0);
4946 return TYPE_UNQUALIFIED;
4947 }
This page took 0.24871 seconds and 6 git commands to generate.