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)
6 This file is part of GNU CC.
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)
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.
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. */
24 /* This file is the lexical analyzer for GNU C++. */
26 /* Cause the `yydebug' variable to be defined. */
44 #include "diagnostic.h"
46 #ifdef MULTIBYTE_CHARS
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
54 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
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));
75 #ifdef GATHER_STATISTICS
77 static int reduce_cmp PARAMS ((int *, int *));
78 static int token_cmp PARAMS ((int *, int *));
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));
87 static int pragma_getc PARAMS ((void));
88 static void pragma_ungetc PARAMS ((int));
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));
99 /* Given a file name X, return the nondirectory portion.
100 Keep in mind that X can be computed more than once. */
102 file_name_nondirectory (x)
105 char *tmp = (char *) rindex (x, '/');
106 if (DIR_SEPARATOR != '/' && ! tmp)
107 tmp = (char *) rindex (x, DIR_SEPARATOR);
109 return (char *) (tmp + 1);
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;
119 /* Nonzero if parse output is being saved to an obstack for later parsing. */
120 static int saving_parse_to_obstack = 0;
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;
135 /* Pending language change.
136 Positive is push count, negative is pop count. */
137 int pending_lang_change = 0;
139 /* Wrap the current header file in extern "C". */
140 static int c_header_level = 0;
142 extern int first_token;
143 extern struct obstack token_obstack;
145 /* ??? Don't really know where this goes yet. */
149 extern int yychar; /* the lookahead symbol */
150 extern YYSTYPE yylval; /* the semantic value of the */
151 /* lookahead symbol */
154 YYLTYPE yylloc; /* location data for the lookahead */
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. */
165 /* We may keep statistics about how long which files took to compile. */
166 static int header_time, body_time;
167 static tree filename_times;
168 static tree this_filename_time;
170 /* Array for holding counts of the numbers of tokens seen. */
171 extern int *token_count;
173 /* When we see a default argument in a method declaration, we snarf it as
174 text using snarf_defarg. When we get up to namespace scope, we then go
175 through and parse all of them using do_pending_defargs. Since yacc
176 parsers are not reentrant, we retain defargs state in these two
177 variables so that subsequent calls to do_pending_defargs can resume
178 where the previous call left off. */
180 static tree defarg_fns;
181 static tree defarg_parm;
183 /* Functions and data structures for #pragma interface.
185 `#pragma implementation' means that the main file being compiled
186 is considered to implement (provide) the classes that appear in
187 its main body. I.e., if this is file "foo.cc", and class `bar'
188 is defined in "foo.cc", then we say that "foo.cc implements bar".
190 All main input files "implement" themselves automagically.
192 `#pragma interface' means that unless this file (of the form "foo.h"
193 is not presently being included by file "foo.cc", the
194 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
195 of the vtables nor any of the inline functions defined in foo.h
198 There are cases when we want to link files such as "defs.h" and
199 "main.cc". In this case, we give "defs.h" a `#pragma interface',
200 and "main.cc" has `#pragma implementation "defs.h"'. */
205 struct impl_files *next;
208 static struct impl_files *impl_file_chain;
210 /* The string used to represent the filename of internally generated
211 tree nodes. The variable, which is dynamically allocated, should
212 be used; the macro is only used to initialize it. */
213 static char *internal_filename;
214 #define INTERNAL_FILENAME ("<internal>")
216 /* Return something to represent absolute declarators containing a *.
217 TARGET is the absolute declarator that the * contains.
218 CV_QUALIFIERS is a list of modifiers such as const or volatile
219 to apply to the pointer type, represented as identifiers.
221 We return an INDIRECT_REF whose "contents" are TARGET
222 and whose type is the modifier list. */
225 make_pointer_declarator (cv_qualifiers, target)
226 tree cv_qualifiers, target;
228 if (target && TREE_CODE (target) == IDENTIFIER_NODE
229 && ANON_AGGRNAME_P (target))
230 error ("type name expected before `*'");
231 target = build_parse_node (INDIRECT_REF, target);
232 TREE_TYPE (target) = cv_qualifiers;
236 /* Return something to represent absolute declarators containing a &.
237 TARGET is the absolute declarator that the & contains.
238 CV_QUALIFIERS is a list of modifiers such as const or volatile
239 to apply to the reference type, represented as identifiers.
241 We return an ADDR_EXPR whose "contents" are TARGET
242 and whose type is the modifier list. */
245 make_reference_declarator (cv_qualifiers, target)
246 tree cv_qualifiers, target;
250 if (TREE_CODE (target) == ADDR_EXPR)
252 error ("cannot declare references to references");
255 if (TREE_CODE (target) == INDIRECT_REF)
257 error ("cannot declare pointers to references");
260 if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
261 error ("type name expected before `&'");
263 target = build_parse_node (ADDR_EXPR, target);
264 TREE_TYPE (target) = cv_qualifiers;
269 make_call_declarator (target, parms, cv_qualifiers, exception_specification)
270 tree target, parms, cv_qualifiers, exception_specification;
272 target = build_parse_node (CALL_EXPR, target,
273 /* Both build_parse_node and
274 decl_tree_cons build on the
275 temp_decl_obstack. */
276 decl_tree_cons (parms, cv_qualifiers, NULL_TREE),
277 /* The third operand is really RTL. We
278 shouldn't put anything there. */
280 CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
285 set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
286 tree call_declarator, cv_qualifiers, exception_specification;
288 CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
289 CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
292 int interface_only; /* whether or not current file is only for
293 interface definitions. */
294 int interface_unknown; /* whether or not we know this class
295 to behave according to #pragma interface. */
297 /* lexical analyzer */
299 #undef WCHAR_TYPE_SIZE
300 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
302 /* Number of bytes in a wide character. */
303 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
305 static int maxtoken; /* Current nominal length of token buffer. */
306 char *token_buffer; /* Pointer to token buffer.
307 Actual allocated length is maxtoken + 2. */
309 static int indent_level; /* Number of { minus number of }. */
314 /* Nonzero tells yylex to ignore \ in string constants. */
315 static int ignore_escape_flag;
318 get_time_identifier (name)
321 tree time_identifier;
322 int len = strlen (name);
323 char *buf = (char *) alloca (len + 6);
324 strcpy (buf, "file ");
325 bcopy (name, buf+5, len);
327 time_identifier = get_identifier (buf);
328 if (TIME_IDENTIFIER_TIME (time_identifier) == NULL_TREE)
330 TIME_IDENTIFIER_TIME (time_identifier) = build_int_2 (0, 0);
331 TIME_IDENTIFIER_FILEINFO (time_identifier)
332 = build_int_2 (0, 1);
333 SET_IDENTIFIER_GLOBAL_VALUE (time_identifier, filename_times);
334 filename_times = time_identifier;
336 return time_identifier;
340 /* Tree code classes. */
342 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
344 static char cplus_tree_code_type[] = {
346 #include "cp-tree.def"
350 /* Table indexed by tree code giving number of expression
351 operands beyond the fixed part of the node structure.
352 Not used for types or decls. */
354 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
356 static int cplus_tree_code_length[] = {
358 #include "cp-tree.def"
362 /* Names of tree components.
363 Used for printing out the tree and error messages. */
364 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
366 static const char *cplus_tree_code_name[] = {
368 #include "cp-tree.def"
372 /* toplev.c needs to call these. */
378 cpp_reader_init (&parse_in);
379 parse_in.opts = &parse_options;
380 cpp_options_init (&parse_options);
381 parse_options.cplusplus = 1;
384 /* Default exceptions on. */
386 /* Mark as "unspecified". */
387 flag_bounds_check = -1;
388 /* By default wrap lines at 80 characters. Is getenv ("COLUMNS")
390 diagnostic_message_length_per_line = 80;
391 /* By default, emit location information once for every
392 diagnostic message. */
393 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
399 /* If still "unspecified", make it match -fbounded-pointers. */
400 if (flag_bounds_check < 0)
401 flag_bounds_check = flag_bounded_pointers;
403 /* the beginning of the file is a new line; check for # */
404 /* With luck, we discover the real source file's name from that
405 and put it in input_filename. */
406 put_back (check_newline ());
407 if (flag_gnu_xref) GNU_xref_begin (input_filename);
408 init_repo (input_filename);
414 if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount);
424 init_filename_times ()
426 this_filename_time = get_time_identifier ("<top level>");
427 if (flag_detailed_statistics)
430 body_time = get_run_time ();
431 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
439 #ifdef GATHER_STATISTICS
441 reduce_count = (int *) xcalloc (sizeof (int), (REDUCE_LENGTH + 1));
443 token_count = (int *) xcalloc (sizeof (int), (TOKEN_LENGTH + 1));
450 /* A mapping from tree codes to operator name information. */
451 operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
452 /* Similar, but for assignment operators. */
453 operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
455 /* Initialize data structures that keep track of operator names. */
462 struct operator_name_info_t *oni;
464 #define DEF_OPERATOR(NAME, CODE, NEW_MANGLING, OLD_MANGLING, ARITY, ASSN_P) \
465 my_friendly_assert ((strlen ("operator ") + strlen (NAME) + 1 \
466 + ISALPHA (NAME[0]) <= 256), \
468 sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \
469 identifier = get_identifier (buffer); \
470 IDENTIFIER_OPNAME_P (identifier) = 1; \
473 ? &assignment_operator_name_info[(int) CODE] \
474 : &operator_name_info[(int) CODE]); \
475 oni->identifier = identifier; \
477 oni->mangled_name = flag_new_abi ? NEW_MANGLING : OLD_MANGLING;
479 #include "operators.def"
482 operator_name_info[(int) ERROR_MARK].identifier
483 = get_identifier ("<invalid operator>");
485 /* Handle some special cases. These operators are not defined in
486 the language, but can be produced internally. We may need them
487 for error-reporting. (Eventually, we should ensure that this
488 does not happen. Error messages involving these operators will
489 be confusing to users.) */
491 operator_name_info [(int) INIT_EXPR].name
492 = operator_name_info [(int) MODIFY_EXPR].name;
493 operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)";
494 operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)";
495 operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)";
496 operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)";
497 operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)";
498 operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
499 operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
500 operator_name_info [(int) ABS_EXPR].name = "abs";
501 operator_name_info [(int) FFS_EXPR].name = "ffs";
502 operator_name_info [(int) BIT_ANDTC_EXPR].name = "&~";
503 operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
504 operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
505 operator_name_info [(int) IN_EXPR].name = "in";
506 operator_name_info [(int) RANGE_EXPR].name = "...";
507 operator_name_info [(int) CONVERT_EXPR].name = "+";
509 assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
511 assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
513 assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
515 assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
517 assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
519 assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
521 assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
526 init_parse (filename)
527 const char *filename;
529 extern int flag_no_gnu_keywords;
530 extern int flag_operator_names;
532 #ifdef MULTIBYTE_CHARS
533 /* Change to the native locale for multibyte conversions. */
534 setlocale (LC_CTYPE, "");
535 literal_codeset = getenv ("LANG");
539 /* Open input file. */
540 if (filename == 0 || !strcmp (filename, "-"))
546 finput = fopen (filename, "r");
548 pfatal_with_name (filename);
550 #ifdef IO_BUFFER_SIZE
551 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
553 #else /* !USE_CPPLIB */
554 parse_in.show_column = 1;
555 if (! cpp_start_read (&parse_in, filename))
558 if (filename == 0 || !strcmp (filename, "-"))
561 /* cpp_start_read always puts at least one line directive into the
562 token buffer. We must arrange to read it out here. */
563 yy_cur = parse_in.token_buffer;
564 yy_lim = CPP_PWRITTEN (&parse_in);
565 cpp_token = CPP_DIRECTIVE;
567 #endif /* !USE_CPPLIB */
569 /* Initialize the lookahead machinery. */
572 /* Make identifier nodes long enough for the language-specific slots. */
573 set_identifier_size (sizeof (struct lang_identifier));
574 decl_printable_name = lang_printable_name;
577 init_cplus_expand ();
581 memcpy (tree_code_type + (int) LAST_C_TREE_CODE,
582 cplus_tree_code_type,
583 (int)LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE);
584 memcpy (tree_code_length + (int) LAST_C_TREE_CODE,
585 cplus_tree_code_length,
586 (LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE) * sizeof (int));
587 memcpy (tree_code_name + (int) LAST_C_TREE_CODE,
588 cplus_tree_code_name,
589 (LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE) * sizeof (char *));
594 gcc_obstack_init (&inline_text_obstack);
595 inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
597 internal_filename = ggc_alloc_string (INTERNAL_FILENAME,
598 sizeof (INTERNAL_FILENAME));
600 /* Start it at 0, because check_newline is called at the very beginning
601 and will increment it to 1. */
603 input_filename = internal_filename;
604 current_function_decl = NULL;
607 token_buffer = (char *) xmalloc (maxtoken + 2);
609 my_friendly_assert ((int) CP_RID_MAX < 64, 20000630);
610 ridpointers = (tree *) xcalloc ((int) CP_RID_MAX, sizeof (tree));
611 ridpointers[(int) RID_INT] = get_identifier ("int");
612 ridpointers[(int) RID_BOOL] = get_identifier ("bool");
613 ridpointers[(int) RID_CHAR] = get_identifier ("char");
614 ridpointers[(int) RID_VOID] = get_identifier ("void");
615 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
616 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
617 ridpointers[(int) RID_SHORT] = get_identifier ("short");
618 ridpointers[(int) RID_LONG] = get_identifier ("long");
619 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
620 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
621 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
622 ridpointers[(int) RID_CONST] = get_identifier ("const");
623 ridpointers[(int) RID_RESTRICT] = get_identifier ("__restrict");
624 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
625 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
626 ridpointers[(int) RID_STATIC] = get_identifier ("static");
627 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
628 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
629 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
630 ridpointers[(int) RID_COMPLEX] = get_identifier ("__complex");
632 /* C++ extensions. These are probably not correctly named. */
633 ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t");
634 class_type_node = build_int_2 (class_type, 0);
635 TREE_TYPE (class_type_node) = class_type_node;
636 ridpointers[(int) RID_CLASS] = class_type_node;
638 record_type_node = build_int_2 (record_type, 0);
639 TREE_TYPE (record_type_node) = record_type_node;
640 ridpointers[(int) RID_RECORD] = record_type_node;
642 union_type_node = build_int_2 (union_type, 0);
643 TREE_TYPE (union_type_node) = union_type_node;
644 ridpointers[(int) RID_UNION] = union_type_node;
646 enum_type_node = build_int_2 (enum_type, 0);
647 TREE_TYPE (enum_type_node) = enum_type_node;
648 ridpointers[(int) RID_ENUM] = enum_type_node;
650 ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual");
651 ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit");
652 ridpointers[(int) RID_EXPORT] = get_identifier ("export");
653 ridpointers[(int) RID_FRIEND] = get_identifier ("friend");
655 ridpointers[(int) RID_PUBLIC] = get_identifier ("public");
656 ridpointers[(int) RID_PRIVATE] = get_identifier ("private");
657 ridpointers[(int) RID_PROTECTED] = get_identifier ("protected");
658 ridpointers[(int) RID_TEMPLATE] = get_identifier ("template");
659 /* This is for ANSI C++. */
660 ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable");
662 /* Create the built-in __null node. Note that we can't yet call for
663 type_for_size here because integer_type_node and so forth are not
664 set up. Therefore, we don't set the type of these nodes until
665 init_decl_processing. */
666 null_node = build_int_2 (0, 0);
667 ridpointers[RID_NULL] = null_node;
669 init_filename_times ();
671 /* Some options inhibit certain reserved words.
672 Clear those words out of the hash table so they won't be recognized. */
673 #define UNSET_RESERVED_WORD(STRING) \
674 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
675 if (s) s->name = ""; } while (0)
678 /* let's parse things, and if they use it, then give them an error. */
679 if (!flag_exceptions)
681 UNSET_RESERVED_WORD ("throw");
682 UNSET_RESERVED_WORD ("try");
683 UNSET_RESERVED_WORD ("catch");
687 if (flag_no_asm || flag_no_gnu_keywords)
688 UNSET_RESERVED_WORD ("typeof");
689 if (! flag_operator_names)
691 /* These are new ANSI keywords that may break code. */
692 UNSET_RESERVED_WORD ("and");
693 UNSET_RESERVED_WORD ("and_eq");
694 UNSET_RESERVED_WORD ("bitand");
695 UNSET_RESERVED_WORD ("bitor");
696 UNSET_RESERVED_WORD ("compl");
697 UNSET_RESERVED_WORD ("not");
698 UNSET_RESERVED_WORD ("not_eq");
699 UNSET_RESERVED_WORD ("or");
700 UNSET_RESERVED_WORD ("or_eq");
701 UNSET_RESERVED_WORD ("xor");
702 UNSET_RESERVED_WORD ("xor_eq");
705 token_count = init_cpp_parse ();
706 interface_unknown = 1;
708 ggc_add_string_root (&internal_filename, 1);
709 ggc_add_tree_root (ridpointers, CP_RID_MAX);
710 ggc_add_tree_root (&defarg_fns, 1);
711 ggc_add_tree_root (&defarg_parm, 1);
712 ggc_add_tree_root (&this_filename_time, 1);
713 ggc_add_tree_root (&filename_times, 1);
714 ggc_add_root (&impl_file_chain, 1, sizeof (impl_file_chain),
715 mark_impl_file_chain);
723 cpp_finish (&parse_in);
724 errorcount += parse_in.errors;
731 yyprint (file, yychar, yylval)
744 case IDENTIFIER_DEFN:
748 case PRE_PARSED_CLASS_DECL:
750 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL)
752 fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t)));
755 my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
756 if (IDENTIFIER_POINTER (t))
757 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
761 if (yylval.ttype == class_type_node)
762 fprintf (file, " `class'");
763 else if (yylval.ttype == record_type_node)
764 fprintf (file, " `struct'");
765 else if (yylval.ttype == union_type_node)
766 fprintf (file, " `union'");
767 else if (yylval.ttype == enum_type_node)
768 fprintf (file, " `enum'");
770 my_friendly_abort (80);
775 if (TREE_CODE (t) == INTEGER_CST)
777 #if HOST_BITS_PER_WIDE_INT == 64
778 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
781 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
788 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
794 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
799 #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
800 static int *reduce_count;
806 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
807 #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
810 #ifdef GATHER_STATISTICS
816 reduce_count[yyn] += 1;
823 return reduce_count[*q] - reduce_count[*p];
830 return token_count[*q] - token_count[*p];
836 print_parse_statistics ()
838 #ifdef GATHER_STATISTICS
842 int maxlen = REDUCE_LENGTH;
845 if (reduce_count[-1] == 0)
848 if (TOKEN_LENGTH > REDUCE_LENGTH)
849 maxlen = TOKEN_LENGTH;
850 sorted = (unsigned *) alloca (sizeof (int) * maxlen);
852 for (i = 0; i < TOKEN_LENGTH; i++)
854 qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
855 for (i = 0; i < TOKEN_LENGTH; i++)
858 if (token_count[idx] == 0)
860 if (token_count[idx] < token_count[-1])
862 fprintf (stderr, "token %d, `%s', count = %d\n",
863 idx, yytname[YYTRANSLATE (idx)], token_count[idx]);
865 fprintf (stderr, "\n");
866 for (i = 0; i < REDUCE_LENGTH; i++)
868 qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
869 for (i = 0; i < REDUCE_LENGTH; i++)
872 if (reduce_count[idx] == 0)
874 if (reduce_count[idx] < reduce_count[-1])
876 fprintf (stderr, "rule %d, line %d, count = %d\n",
877 idx, yyrline[idx], reduce_count[idx]);
879 fprintf (stderr, "\n");
885 /* Sets the value of the 'yydebug' variable to VALUE.
886 This is a function so we don't have to have YYDEBUG defined
887 in order to build the compiler. */
897 warning ("YYDEBUG not defined.");
902 /* Mark ARG (which is really a struct impl_files **) for GC. */
905 mark_impl_file_chain (arg)
908 struct impl_files *ifs;
910 ifs = *(struct impl_files **) arg;
913 ggc_mark_string (ifs->filename);
918 /* Helper function to load global variables with interface
922 extract_interface_info ()
926 if (flag_alt_external_templates)
928 tree til = tinst_for_decl ();
931 fileinfo = get_time_identifier (TINST_FILE (til));
934 fileinfo = get_time_identifier (input_filename);
935 fileinfo = TIME_IDENTIFIER_FILEINFO (fileinfo);
936 interface_only = TREE_INT_CST_LOW (fileinfo);
937 interface_unknown = TREE_INT_CST_HIGH (fileinfo);
940 /* Return nonzero if S is not considered part of an
941 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
947 /* Set the interface/implementation bits for this scope. */
948 struct impl_files *ifiles;
951 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
953 const char *t1 = ifiles->filename;
956 if (*s1 != *t1 || *s1 == 0)
959 while (*s1 == *t1 && *s1 != 0)
966 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
967 if (index (s1, '.') || index (t1, '.'))
970 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
982 cp_pragma_interface (main_filename)
983 const char *main_filename;
986 = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename));
988 if (impl_file_chain == 0)
990 /* If this is zero at this point, then we are
991 auto-implementing. */
992 if (main_input_filename == 0)
993 main_input_filename = input_filename;
995 #ifdef AUTO_IMPLEMENT
996 filename = file_name_nondirectory (main_input_filename);
997 fi = get_time_identifier (filename);
998 fi = TIME_IDENTIFIER_FILEINFO (fi);
999 TREE_INT_CST_LOW (fi) = 0;
1000 TREE_INT_CST_HIGH (fi) = 1;
1003 = (struct impl_files *) xmalloc (sizeof (struct impl_files));
1004 impl_file_chain->filename = ggc_alloc_string (filename, -1);
1005 impl_file_chain->next = 0;
1009 interface_only = interface_strcmp (main_filename);
1010 #ifdef MULTIPLE_SYMBOL_SPACES
1011 if (! interface_only)
1012 interface_unknown = 0;
1013 #else /* MULTIPLE_SYMBOL_SPACES */
1014 interface_unknown = 0;
1015 #endif /* MULTIPLE_SYMBOL_SPACES */
1016 TREE_INT_CST_LOW (fileinfo) = interface_only;
1017 TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
1020 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
1021 We used to only allow this at toplevel, but that restriction was buggy
1022 in older compilers and it seems reasonable to allow it in the headers
1023 themselves, too. It only needs to precede the matching #p interface.
1025 We don't touch interface_only or interface_unknown; the user must specify
1026 a matching #p interface for this to have any effect. */
1029 cp_pragma_implementation (main_filename)
1030 const char *main_filename;
1032 struct impl_files *ifiles = impl_file_chain;
1033 for (; ifiles; ifiles = ifiles->next)
1035 if (! strcmp (ifiles->filename, main_filename))
1040 ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files));
1041 ifiles->filename = ggc_alloc_string (main_filename, -1);
1042 ifiles->next = impl_file_chain;
1043 impl_file_chain = ifiles;
1047 /* Set up the state required to correctly handle the definition of the
1048 inline function whose preparsed state has been saved in PI. */
1051 begin_definition_of_inclass_inline (pi)
1052 struct pending_inline* pi;
1059 /* If this is an inline function in a local class, we must make sure
1060 that we save all pertinent information about the function
1061 surrounding the local class. */
1062 context = decl_function_context (pi->fndecl);
1064 push_function_context_to (context);
1066 feed_input (pi->buf, pi->len, pi->filename, pi->lineno);
1067 yychar = PRE_PARSED_FUNCTION_DECL;
1069 /* Pass back a handle to the rest of the inline functions, so that they
1070 can be processed later. */
1071 DECL_PENDING_INLINE_INFO (pi->fndecl) = 0;
1072 DECL_PENDING_INLINE_P (pi->fndecl) = 0;
1073 interface_unknown = pi->interface == 1;
1074 interface_only = pi->interface == 0;
1077 /* Called from the top level: if there are any pending inlines to
1078 do, set up to process them now. This function sets up the first function
1079 to be parsed; after it has been, the rule for fndef in parse.y will
1080 call process_next_inline to start working on the next one. */
1083 do_pending_inlines ()
1085 struct pending_inline *t;
1087 /* Oops, we're still dealing with the last batch. */
1088 if (yychar == PRE_PARSED_FUNCTION_DECL)
1091 /* Reverse the pending inline functions, since
1092 they were cons'd instead of appended. */
1094 struct pending_inline *prev = 0, *tail;
1095 t = pending_inlines;
1096 pending_inlines = 0;
1111 /* Now start processing the first inline function. */
1112 begin_definition_of_inclass_inline (t);
1115 /* Called from the fndecl rule in the parser when the function just parsed
1116 was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1117 do_pending_inlines). */
1120 process_next_inline (i)
1121 struct pending_inline *i;
1124 context = decl_function_context (i->fndecl);
1126 pop_function_context_from (context);
1128 if (yychar == YYEMPTY)
1130 if (yychar != END_OF_SAVED_INPUT)
1132 error ("parse error at end of saved function text");
1134 /* restore_pending_input will abort unless yychar is either
1135 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1136 hosed, feed back YYEMPTY. */
1141 begin_definition_of_inclass_inline (i);
1143 extract_interface_info ();
1146 /* Since inline methods can refer to text which has not yet been seen,
1147 we store the text of the method in a structure which is placed in the
1148 DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1149 After parsing the body of the class definition, the FUNCTION_DECL's are
1150 scanned to see which ones have this field set. Those are then digested
1153 This function's FUNCTION_DECL will have a bit set in its common so
1154 that we know to watch out for it. */
1157 consume_string (this_obstack, matching_char)
1158 register struct obstack *this_obstack;
1162 int starting_lineno;
1165 if (cpp_token == CPP_STRING)
1167 /* The C preprocessor will warn about newlines in strings. */
1168 obstack_grow (this_obstack, yy_cur, (yy_lim - yy_cur));
1170 lineno = parse_in.lineno;
1175 starting_lineno = lineno;
1181 int save_lineno = lineno;
1182 lineno = starting_lineno;
1183 if (matching_char == '"')
1184 error ("end of file encountered inside string constant");
1186 error ("end of file encountered inside character constant");
1187 lineno = save_lineno;
1192 obstack_1grow (this_obstack, c);
1194 obstack_1grow (this_obstack, c);
1196 /* Make sure we continue the loop */
1203 pedwarn ("ISO C++ forbids newline in string constant");
1206 obstack_1grow (this_obstack, c);
1208 while (c != matching_char);
1211 struct pending_input {
1214 struct obstack token_obstack;
1218 struct pending_input *
1219 save_pending_input ()
1221 struct pending_input *p;
1222 p = (struct pending_input *) xmalloc (sizeof (struct pending_input));
1225 p->eof = end_of_file;
1227 p->first_token = first_token;
1228 p->token_obstack = token_obstack;
1231 gcc_obstack_init (&token_obstack);
1237 restore_pending_input (p)
1238 struct pending_input *p;
1240 my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230);
1243 first_token = p->first_token;
1244 obstack_free (&token_obstack, (char *) 0);
1245 token_obstack = p->token_obstack;
1246 end_of_file = p->eof;
1250 /* Unget character CH from the input stream.
1251 If RESCAN is non-zero, then we want to `see' this
1252 character as the next input token. */
1255 yyungetc (ch, rescan)
1259 /* Unget a character from the input stream. */
1260 if (yychar == YYEMPTY || rescan == 0)
1262 /* If we're putting back a brace, undo the change in indent_level
1263 from the first time we saw it. */
1278 clear_inline_text_obstack ()
1280 obstack_free (&inline_text_obstack, inline_text_firstobj);
1283 /* This function stores away the text for an inline function that should
1284 be processed later. It decides how much later, and may need to move
1285 the info between obstacks; therefore, the caller should not refer to
1286 the T parameter after calling this function. */
1289 store_pending_inline (decl, t)
1291 struct pending_inline *t;
1294 DECL_PENDING_INLINE_INFO (decl) = t;
1295 DECL_PENDING_INLINE_P (decl) = 1;
1297 /* Because we use obstacks, we must process these in precise order. */
1298 t->next = pending_inlines;
1299 pending_inlines = t;
1303 reinit_parse_for_method (yychar, decl)
1308 int starting_lineno = lineno;
1309 const char *starting_filename = input_filename;
1311 reinit_parse_for_block (yychar, &inline_text_obstack);
1313 len = obstack_object_size (&inline_text_obstack);
1314 if (decl == void_type_node
1315 || (current_class_type && TYPE_REDEFINED (current_class_type)))
1317 /* Happens when we get two declarations of the same
1318 function in the same scope. */
1319 char *buf = obstack_finish (&inline_text_obstack);
1320 obstack_free (&inline_text_obstack, buf);
1325 struct pending_inline *t;
1326 char *buf = obstack_finish (&inline_text_obstack);
1328 t = (struct pending_inline *) obstack_alloc (&inline_text_obstack,
1329 sizeof (struct pending_inline));
1330 t->lineno = starting_lineno;
1331 t->filename = starting_filename;
1338 if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
1339 warn_if_unknown_interface (decl);
1341 t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2));
1342 store_pending_inline (decl, t);
1346 /* Consume a block -- actually, a method beginning
1347 with `:' or `{' -- and save it away on the specified obstack. */
1350 reinit_parse_for_block (pyychar, obstackp)
1352 struct obstack *obstackp;
1356 int starting_lineno = lineno;
1357 const char *starting_filename = input_filename;
1359 int look_for_semicolon = 0;
1360 int look_for_lbrac = 0;
1364 obstack_1grow (obstackp, '{');
1365 /* We incremented indent_level in yylex; undo that. */
1368 else if (pyychar == '=')
1369 look_for_semicolon = 1;
1370 else if (pyychar == ':')
1372 obstack_1grow (obstackp, pyychar);
1373 /* Add a space so we don't get confused by ': ::A(20)'. */
1374 obstack_1grow (obstackp, ' ');
1378 else if (pyychar == RETURN_KEYWORD)
1380 obstack_grow (obstackp, "return", 6);
1384 else if (pyychar == TRY)
1386 obstack_grow (obstackp, "try", 3);
1392 yyerror ("parse error in method specification");
1393 obstack_1grow (obstackp, '{');
1400 int this_lineno = lineno;
1402 saving_parse_to_obstack = 1;
1403 c = skip_white_space (c);
1404 saving_parse_to_obstack = 0;
1406 /* Don't lose our cool if there are lots of comments. */
1407 if (lineno == this_lineno + 1)
1408 obstack_1grow (obstackp, '\n');
1409 else if (lineno == this_lineno)
1411 else if (lineno - this_lineno < 10)
1414 for (i = lineno - this_lineno; i > 0; i--)
1415 obstack_1grow (obstackp, '\n');
1420 sprintf (buf, "\n# %d \"", lineno);
1422 obstack_grow (obstackp, buf, len);
1424 len = strlen (input_filename);
1425 obstack_grow (obstackp, input_filename, len);
1426 obstack_1grow (obstackp, '\"');
1427 obstack_1grow (obstackp, '\n');
1430 while (c > ' ') /* ASCII dependent... */
1432 obstack_1grow (obstackp, c);
1441 if (blev == 0 && !look_for_semicolon)
1445 if (peekyylex () == CATCH)
1448 obstack_grow (obstackp, " catch ", 7);
1465 /* Don't act on the next character...e.g, doing an escaped
1470 error_with_file_and_line (starting_filename,
1472 "end of file read inside definition");
1475 obstack_1grow (obstackp, c);
1478 consume_string (obstackp, c);
1480 consume_string (obstackp, c);
1485 error ("function body for constructor missing");
1486 obstack_1grow (obstackp, '{');
1487 obstack_1grow (obstackp, '}');
1491 else if (look_for_semicolon && blev == 0)
1499 error_with_file_and_line (starting_filename,
1501 "end of file read inside definition");
1506 obstack_1grow (obstackp, c);
1511 obstack_1grow (obstackp, '\0');
1514 /* Consume a no-commas expression -- actually, a default argument -- and
1515 save it away on the specified obstack. */
1518 reinit_parse_for_expr (obstackp)
1519 struct obstack *obstackp;
1522 int starting_lineno = lineno;
1523 const char *starting_filename = input_filename;
1531 int this_lineno = lineno;
1533 saving_parse_to_obstack = 1;
1534 c = skip_white_space (c);
1535 saving_parse_to_obstack = 0;
1537 /* Don't lose our cool if there are lots of comments. */
1538 if (lineno == this_lineno + 1)
1539 obstack_1grow (obstackp, '\n');
1540 else if (lineno == this_lineno)
1542 else if (lineno - this_lineno < 10)
1545 for (i = lineno - this_lineno; i > 0; --i)
1546 obstack_1grow (obstackp, '\n');
1551 sprintf (buf, "\n# %d \"", lineno);
1553 obstack_grow (obstackp, buf, len);
1555 len = strlen (input_filename);
1556 obstack_grow (obstackp, input_filename, len);
1557 obstack_1grow (obstackp, '\"');
1558 obstack_1grow (obstackp, '\n');
1561 while (c > ' ') /* ASCII dependent... */
1563 if (plev <= 0 && (c == ')' || c == ','))
1568 obstack_1grow (obstackp, c);
1569 if (c == '(' || c == '[')
1571 else if (c == ']' || c == ')')
1575 /* Don't act on the next character...e.g, doing an escaped
1580 error_with_file_and_line (starting_filename,
1582 "end of file read inside definition");
1585 obstack_1grow (obstackp, c);
1588 consume_string (obstackp, c);
1590 consume_string (obstackp, c);
1596 error_with_file_and_line (starting_filename,
1598 "end of file read inside definition");
1603 obstack_1grow (obstackp, c);
1608 obstack_1grow (obstackp, '\0');
1611 int do_snarf_defarg;
1613 /* Decide whether the default argument we are about to see should be
1614 gobbled up as text for later parsing. */
1617 maybe_snarf_defarg ()
1619 if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
1620 do_snarf_defarg = 1;
1630 reinit_parse_for_expr (&inline_text_obstack);
1631 len = obstack_object_size (&inline_text_obstack);
1632 buf = obstack_finish (&inline_text_obstack);
1634 arg = make_node (DEFAULT_ARG);
1635 DEFARG_LENGTH (arg) = len - 1;
1636 DEFARG_POINTER (arg) = buf;
1641 /* Called from grokfndecl to note a function decl with unparsed default
1642 arguments for later processing. Also called from grokdeclarator
1643 for function types with unparsed defargs; the call from grokfndecl
1644 will always come second, so we can overwrite the entry from the type. */
1647 add_defarg_fn (decl)
1650 if (TREE_CODE (decl) == FUNCTION_DECL)
1651 TREE_VALUE (defarg_fns) = decl;
1653 defarg_fns = tree_cons (current_class_type, decl, defarg_fns);
1656 /* Helper for do_pending_defargs. Starts the parsing of a default arg. */
1662 tree d = TREE_PURPOSE (p);
1665 if (TREE_CODE (f) == FUNCTION_DECL)
1667 line = DECL_SOURCE_LINE (f);
1668 file = DECL_SOURCE_FILE (f);
1673 file = input_filename;
1676 feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d), file, line);
1677 yychar = DEFARG_MARKER;
1681 /* Helper for do_pending_defargs. Ends the parsing of a default arg. */
1686 if (yychar == YYEMPTY)
1688 if (yychar != END_OF_SAVED_INPUT)
1690 error ("parse error at end of saved function text");
1692 /* restore_pending_input will abort unless yychar is either
1693 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1694 hosed, feed back YYEMPTY. */
1700 /* Main function for deferred parsing of default arguments. Called from
1704 do_pending_defargs ()
1709 for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns))
1711 tree defarg_fn = TREE_VALUE (defarg_fns);
1712 if (defarg_parm == NULL_TREE)
1714 push_nested_class (TREE_PURPOSE (defarg_fns), 1);
1716 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1717 maybe_begin_member_template_processing (defarg_fn);
1719 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1723 for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p))
1724 pushdecl (copy_node (p));
1726 defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn));
1729 defarg_parm = TYPE_ARG_TYPES (defarg_fn);
1732 defarg_parm = TREE_CHAIN (defarg_parm);
1734 for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm))
1735 if (TREE_PURPOSE (defarg_parm)
1736 && TREE_CODE (TREE_PURPOSE (defarg_parm)) == DEFAULT_ARG)
1738 feed_defarg (defarg_fn, defarg_parm);
1740 /* Return to the parser, which will process this defarg
1741 and call us again. */
1745 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1747 maybe_end_member_template_processing ();
1748 check_default_args (defarg_fn);
1752 pop_nested_class ();
1756 /* Heuristic to tell whether the user is missing a semicolon
1757 after a struct or enum declaration. Emit an error message
1758 if we know the user has blown it. */
1761 check_for_missing_semicolon (type)
1769 && yychar != IDENTIFIER
1770 && yychar != TYPENAME
1771 && yychar != CV_QUALIFIER
1772 && yychar != SELFNAME)
1775 if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
1776 error ("semicolon missing after %s declaration",
1777 TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
1779 cp_error ("semicolon missing after declaration of `%T'", type);
1780 shadow_tag (build_tree_list (0, type));
1782 /* Could probably also hack cases where class { ... } f (); appears. */
1787 note_got_semicolon (type)
1791 my_friendly_abort (60);
1792 if (CLASS_TYPE_P (type))
1793 CLASSTYPE_GOT_SEMICOLON (type) = 1;
1797 note_list_got_semicolon (declspecs)
1802 for (link = declspecs; link; link = TREE_CHAIN (link))
1804 tree type = TREE_VALUE (link);
1806 note_got_semicolon (type);
1811 /* Iff C is a carriage return, warn about it - if appropriate -
1812 and return nonzero. */
1817 static int newline_warning = 0;
1821 /* ANSI C says the effects of a carriage return in a source file
1823 if (pedantic && !newline_warning)
1825 warning ("carriage return in source file (we only warn about the first carriage return)");
1826 newline_warning = 1;
1833 /* If C is not whitespace, return C.
1834 Otherwise skip whitespace and return first nonwhite char read. */
1837 skip_white_space (c)
1844 /* We don't recognize comments here, because
1845 cpp output can include / and * consecutively as operators.
1846 Also, there's no need, since cpp removes all comments. */
1854 c = check_newline ();
1863 /* While processing a # directive we don't get CPP_HSPACE
1864 tokens, so we also need to handle whitespace the normal way. */
1865 if (cpp_token == CPP_HSPACE)
1866 c = yy_get_token ();
1889 error ("stray '\\' in program");
1898 /* Make the token buffer longer, preserving the data in it.
1899 P should point to just beyond the last valid character in the old buffer.
1900 The value we return is a pointer to the new buffer
1901 at a place corresponding to P. */
1904 extend_token_buffer_to (size)
1908 maxtoken = maxtoken * 2 + 10;
1909 while (maxtoken < size);
1910 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
1914 extend_token_buffer (p)
1917 int offset = p - token_buffer;
1918 extend_token_buffer_to (offset);
1919 return token_buffer + offset;
1922 #if defined HANDLE_PRAGMA
1923 /* Local versions of these macros, that can be passed as function pointers. */
1939 read_line_number (num)
1942 register int token = real_yylex ();
1944 if (token == CONSTANT
1945 && TREE_CODE (yylval.ttype) == INTEGER_CST)
1947 *num = TREE_INT_CST_LOW (yylval.ttype);
1952 if (token != END_OF_LINE)
1953 error ("invalid #-line");
1958 /* At the beginning of a line, increment the line number
1959 and process any #-directive on this line.
1960 If the line is a #-directive, read the entire line and return a newline.
1961 Otherwise, return the line's first non-whitespace character.
1963 Note that in the case of USE_CPPLIB, we get the whole line as one
1964 CPP_DIRECTIVE token. */
1972 enum { act_none, act_push, act_pop } action;
1973 int action_number, l;
1974 int entering_c_header;
1978 /* Read first nonwhite char on the line. Do this before incrementing the
1979 line number, in case we're at the end of saved text. */
1983 /* In some cases where we're leaving an include file, we can get multiple
1984 CPP_HSPACE tokens in a row, so we need to loop. */
1985 while (cpp_token == CPP_HSPACE)
1986 c = yy_get_token ();
1990 while (c == ' ' || c == '\t');
1997 /* Sequences of multiple newlines are very common; optimize them. */
2001 /* If not #, return it so caller will use it. */
2005 /* Don't read beyond this line. */
2010 if (cpp_token == CPP_VSPACE)
2012 /* Format is "<space> <line number> <filename> <newline>".
2013 Only the line number is interesting, and even that
2014 we can get more efficiently than scanning the line. */
2015 yy_cur = yy_lim - 1;
2016 lineno = parse_in.lineno - 1;
2021 token = real_yylex ();
2023 if (token == IDENTIFIER)
2025 /* If a letter follows, then if the word here is `line', skip
2026 it and ignore it; otherwise, ignore the line, with an error
2027 if the word isn't `pragma'. */
2029 const char *name = IDENTIFIER_POINTER (yylval.ttype);
2031 if (!strcmp (name, "pragma"))
2033 token = real_yylex ();
2034 if (token != IDENTIFIER
2035 || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
2038 /* If this is 1, we handled it; if it's -1, it was one we
2039 wanted but had something wrong with it. Only if it's
2040 0 was it not handled. */
2041 if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype)))
2044 #ifdef HANDLE_PRAGMA
2045 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
2046 (if both are defined), in order to give the back
2047 end a chance to override the interpretation of
2048 SYSV style pragmas. */
2049 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
2050 IDENTIFIER_POINTER (yylval.ttype)))
2052 #endif /* HANDLE_PRAGMA */
2054 #ifdef HANDLE_GENERIC_PRAGMAS
2055 if (handle_generic_pragma (token))
2057 #endif /* HANDLE_GENERIC_PRAGMAS */
2059 /* Issue a warning message if we have been asked to do so.
2060 Ignoring unknown pragmas in system header file unless
2061 an explcit -Wunknown-pragmas has been given. */
2062 if (warn_unknown_pragmas > 1
2063 || (warn_unknown_pragmas && ! in_system_header))
2064 warning ("ignoring pragma: %s", token_buffer);
2068 else if (!strcmp (name, "define"))
2070 debug_define (lineno, GET_DIRECTIVE_LINE ());
2073 else if (!strcmp (name, "undef"))
2075 debug_undef (lineno, GET_DIRECTIVE_LINE ());
2078 else if (!strcmp (name, "line"))
2081 token = real_yylex ();
2084 else if (!strcmp (name, "ident"))
2086 /* #ident. The pedantic warning is now in cpp. */
2088 /* Here we have just seen `#ident '.
2089 A string constant should follow. */
2091 token = real_yylex ();
2092 if (token == END_OF_LINE)
2095 || TREE_CODE (yylval.ttype) != STRING_CST)
2097 error ("invalid #ident");
2101 if (! flag_no_ident)
2103 #ifdef ASM_OUTPUT_IDENT
2104 ASM_OUTPUT_IDENT (asm_out_file,
2105 TREE_STRING_POINTER (yylval.ttype));
2109 /* Skip the rest of this line. */
2113 error ("undefined or invalid # directive `%s'", name);
2117 /* If the # is the only nonwhite char on the line,
2118 just ignore it. Check the new newline. */
2119 if (token == END_OF_LINE)
2123 /* Here we have either `#line' or `# <nonletter>'.
2124 In either case, it should be a line number; a digit should follow. */
2126 if (token != CONSTANT
2127 || TREE_CODE (yylval.ttype) != INTEGER_CST)
2129 error ("invalid #-line");
2133 /* subtract one, because it is the following line that
2134 gets the specified number */
2136 l = TREE_INT_CST_LOW (yylval.ttype) - 1;
2138 /* More follows: it must be a string constant (filename).
2139 It would be neat to use cpplib to quickly process the string, but
2140 (1) we don't have a handy tokenization of the string, and
2141 (2) I don't know how well that would work in the presense
2142 of filenames that contain wide characters. */
2144 if (saw_line || saving_parse_to_obstack)
2146 /* Don't treat \ as special if we are processing #line 1 "...".
2147 If you want it to be treated specially, use # 1 "...". Also
2148 ignore these if saving to an obstack for later parsing. */
2149 ignore_escape_flag = 1;
2152 /* Read the string constant. */
2153 token = real_yylex ();
2155 ignore_escape_flag = 0;
2157 if (token == END_OF_LINE)
2159 /* No more: store the line number and check following line. */
2164 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2166 error ("invalid #line");
2170 /* Changing files again. This means currently collected time
2171 is charged against header time, and body time starts back at 0. */
2172 if (flag_detailed_statistics)
2174 int this_time = get_run_time ();
2175 tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype));
2176 header_time += this_time - body_time;
2177 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
2178 += this_time - body_time;
2179 this_filename_time = time_identifier;
2180 body_time = this_time;
2183 new_file = TREE_STRING_POINTER (yylval.ttype);
2185 GNU_xref_file (new_file);
2187 if (main_input_filename == 0)
2189 struct impl_files *ifiles = impl_file_chain;
2193 while (ifiles->next)
2194 ifiles = ifiles->next;
2195 ifiles->filename = file_name_nondirectory (new_file);
2198 main_input_filename = new_file;
2204 /* Each change of file name
2205 reinitializes whether we are now in a system header. */
2206 in_system_header = 0;
2207 entering_c_header = 0;
2209 if (!read_line_number (&action_number) && input_file_stack)
2211 input_file_stack->name = input_filename = new_file;
2212 input_file_stack->line = lineno = l;
2215 /* `1' after file name means entering new file.
2216 `2' after file name means just left a file. */
2218 if (action_number == 1)
2221 read_line_number (&action_number);
2223 else if (action_number == 2)
2226 read_line_number (&action_number);
2228 if (action_number == 3)
2230 /* `3' after file name means this is a system header file. */
2231 in_system_header = 1;
2232 read_line_number (&action_number);
2234 if (action_number == 4)
2236 /* `4' after file name means this is a C header file. */
2237 entering_c_header = 1;
2238 read_line_number (&action_number);
2241 /* Do the actions implied by the preceding numbers. */
2243 if (action == act_push)
2245 /* Pushing to a new file. */
2246 push_srcloc (new_file, l);
2247 input_file_stack->indent_level = indent_level;
2248 debug_start_source_file (input_filename);
2251 else if (entering_c_header)
2254 ++pending_lang_change;
2257 else if (action == act_pop)
2259 /* Popping out of a file. */
2260 if (input_file_stack->next)
2262 if (c_header_level && --c_header_level == 0)
2264 if (entering_c_header)
2265 warning ("badly nested C headers from preprocessor");
2266 --pending_lang_change;
2269 if (indent_level != input_file_stack->indent_level)
2271 warning_with_file_and_line
2272 (input_filename, lineno,
2273 "This file contains more `%c's than `%c's.",
2274 indent_level > input_file_stack->indent_level ? '{' : '}',
2275 indent_level > input_file_stack->indent_level ? '}' : '{');
2279 input_file_stack->name = new_file;
2280 debug_end_source_file (input_file_stack->line);
2283 error ("#-lines for entering and leaving files don't match");
2286 input_filename = new_file;
2289 extract_interface_info ();
2291 /* skip the rest of this line. */
2298 while (c != '\n' && c != EOF);
2302 #ifdef HANDLE_GENERIC_PRAGMAS
2304 /* Handle a #pragma directive.
2305 TOKEN is the token we read after `#pragma'. Processes the entire input
2306 line and return non-zero iff the pragma has been successfully parsed. */
2308 /* This function has to be in this file, in order to get at
2312 handle_generic_pragma (token)
2323 handle_pragma_token (token_buffer, yylval.ttype);
2327 handle_pragma_token ("(", NULL_TREE);
2328 handle_pragma_token (")", NULL_TREE);
2332 return handle_pragma_token (NULL_PTR, NULL_TREE);
2335 handle_pragma_token (token_buffer, NULL_TREE);
2338 token = real_yylex ();
2341 #endif /* HANDLE_GENERIC_PRAGMAS */
2344 handle_cp_pragma (pname)
2349 if (! strcmp (pname, "vtable"))
2351 /* More follows: it must be a string constant (class name). */
2352 token = real_yylex ();
2353 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2355 error ("invalid #pragma vtable");
2360 = tree_cons (NULL_TREE,
2361 get_identifier (TREE_STRING_POINTER (yylval.ttype)),
2363 token = real_yylex ();
2364 if (token != END_OF_LINE)
2365 warning ("trailing characters ignored");
2368 else if (! strcmp (pname, "unit"))
2370 /* More follows: it must be a string constant (unit name). */
2371 token = real_yylex ();
2372 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2374 error ("invalid #pragma unit");
2377 token = real_yylex ();
2378 if (token != END_OF_LINE)
2379 warning ("trailing characters ignored");
2382 else if (! strcmp (pname, "interface"))
2384 const char *main_filename = input_filename;
2386 main_filename = file_name_nondirectory (main_filename);
2388 token = real_yylex ();
2390 if (token != END_OF_LINE)
2393 || TREE_CODE (yylval.ttype) != STRING_CST)
2395 error ("invalid `#pragma interface'");
2398 main_filename = TREE_STRING_POINTER (yylval.ttype);
2399 token = real_yylex ();
2402 if (token != END_OF_LINE)
2403 warning ("garbage after `#pragma interface' ignored");
2405 cp_pragma_interface (main_filename);
2409 else if (! strcmp (pname, "implementation"))
2411 const char *main_filename = main_input_filename ? main_input_filename : input_filename;
2413 main_filename = file_name_nondirectory (main_filename);
2415 token = real_yylex ();
2417 if (token != END_OF_LINE)
2420 || TREE_CODE (yylval.ttype) != STRING_CST)
2422 error ("invalid `#pragma implementation'");
2425 main_filename = TREE_STRING_POINTER (yylval.ttype);
2426 token = real_yylex ();
2429 if (token != END_OF_LINE)
2430 warning ("garbage after `#pragma implementation' ignored");
2432 cp_pragma_implementation (main_filename);
2441 do_pending_lang_change ()
2443 for (; pending_lang_change > 0; --pending_lang_change)
2444 push_lang_context (lang_name_c);
2445 for (; pending_lang_change < 0; ++pending_lang_change)
2446 pop_lang_context ();
2449 /* Parse a '\uNNNN' or '\UNNNNNNNN' sequence.
2451 [lex.charset]: The character designated by the universal-character-name
2452 \UNNNNNNNN is that character whose character short name in ISO/IEC 10646
2453 is NNNNNNNN; the character designated by the universal-character-name
2454 \uNNNN is that character whose character short name in ISO/IEC 10646 is
2455 0000NNNN. If the hexadecimal value for a universal character name is
2456 less than 0x20 or in the range 0x7F-0x9F (inclusive), or if the
2457 universal character name designates a character in the basic source
2458 character set, then the program is ill-formed.
2460 We assume that wchar_t is Unicode, so we don't need to do any
2461 mapping. Is this ever wrong? */
2467 unsigned int code = 0;
2470 for (; length; --length)
2475 error ("non hex digit '%c' in universal-character-name", c);
2480 if (c >= 'a' && c <= 'f')
2481 code += c - 'a' + 10;
2482 if (c >= 'A' && c <= 'F')
2483 code += c - 'A' + 10;
2484 if (c >= '0' && c <= '9')
2488 #ifdef TARGET_EBCDIC
2489 sorry ("universal-character-name on EBCDIC target");
2493 if (code > 0x9f && !(code & 0x80000000))
2494 /* True extended character, OK. */;
2495 else if (code >= 0x20 && code < 0x7f)
2497 /* ASCII printable character. The C character set consists of all of
2498 these except $, @ and `. We use hex escapes so that this also
2499 works with EBCDIC hosts. */
2500 if (code != 0x24 && code != 0x40 && code != 0x60)
2501 error ("universal-character-name designates `%c', part of the basic source character set", code);
2504 error ("invalid universal-character-name");
2508 /* Returns nonzero if C is a universal-character-name. Give an error if it
2509 is not one which may appear in an identifier, as per [extendid]. */
2512 is_extended_char (c)
2515 #ifdef TARGET_EBCDIC
2522 return is_extended_char_1 (c);
2527 is_extended_char_1 (c)
2530 /* None of the valid chars are outside the Basic Multilingual Plane (the
2534 error ("universal-character-name `\\U%08x' not valid in identifier", c);
2539 if ((c >= 0x00c0 && c <= 0x00d6)
2540 || (c >= 0x00d8 && c <= 0x00f6)
2541 || (c >= 0x00f8 && c <= 0x01f5)
2542 || (c >= 0x01fa && c <= 0x0217)
2543 || (c >= 0x0250 && c <= 0x02a8)
2544 || (c >= 0x1e00 && c <= 0x1e9a)
2545 || (c >= 0x1ea0 && c <= 0x1ef9))
2550 || (c >= 0x0388 && c <= 0x038a)
2552 || (c >= 0x038e && c <= 0x03a1)
2553 || (c >= 0x03a3 && c <= 0x03ce)
2554 || (c >= 0x03d0 && c <= 0x03d6)
2559 || (c >= 0x03e2 && c <= 0x03f3)
2560 || (c >= 0x1f00 && c <= 0x1f15)
2561 || (c >= 0x1f18 && c <= 0x1f1d)
2562 || (c >= 0x1f20 && c <= 0x1f45)
2563 || (c >= 0x1f48 && c <= 0x1f4d)
2564 || (c >= 0x1f50 && c <= 0x1f57)
2568 || (c >= 0x1f5f && c <= 0x1f7d)
2569 || (c >= 0x1f80 && c <= 0x1fb4)
2570 || (c >= 0x1fb6 && c <= 0x1fbc)
2571 || (c >= 0x1fc2 && c <= 0x1fc4)
2572 || (c >= 0x1fc6 && c <= 0x1fcc)
2573 || (c >= 0x1fd0 && c <= 0x1fd3)
2574 || (c >= 0x1fd6 && c <= 0x1fdb)
2575 || (c >= 0x1fe0 && c <= 0x1fec)
2576 || (c >= 0x1ff2 && c <= 0x1ff4)
2577 || (c >= 0x1ff6 && c <= 0x1ffc))
2581 if ((c >= 0x0401 && c <= 0x040d)
2582 || (c >= 0x040f && c <= 0x044f)
2583 || (c >= 0x0451 && c <= 0x045c)
2584 || (c >= 0x045e && c <= 0x0481)
2585 || (c >= 0x0490 && c <= 0x04c4)
2586 || (c >= 0x04c7 && c <= 0x04c8)
2587 || (c >= 0x04cb && c <= 0x04cc)
2588 || (c >= 0x04d0 && c <= 0x04eb)
2589 || (c >= 0x04ee && c <= 0x04f5)
2590 || (c >= 0x04f8 && c <= 0x04f9))
2594 if ((c >= 0x0531 && c <= 0x0556)
2595 || (c >= 0x0561 && c <= 0x0587))
2599 if ((c >= 0x05d0 && c <= 0x05ea)
2600 || (c >= 0x05f0 && c <= 0x05f4))
2604 if ((c >= 0x0621 && c <= 0x063a)
2605 || (c >= 0x0640 && c <= 0x0652)
2606 || (c >= 0x0670 && c <= 0x06b7)
2607 || (c >= 0x06ba && c <= 0x06be)
2608 || (c >= 0x06c0 && c <= 0x06ce)
2609 || (c >= 0x06e5 && c <= 0x06e7))
2613 if ((c >= 0x0905 && c <= 0x0939)
2614 || (c >= 0x0958 && c <= 0x0962))
2618 if ((c >= 0x0985 && c <= 0x098c)
2619 || (c >= 0x098f && c <= 0x0990)
2620 || (c >= 0x0993 && c <= 0x09a8)
2621 || (c >= 0x09aa && c <= 0x09b0)
2623 || (c >= 0x09b6 && c <= 0x09b9)
2624 || (c >= 0x09dc && c <= 0x09dd)
2625 || (c >= 0x09df && c <= 0x09e1)
2626 || (c >= 0x09f0 && c <= 0x09f1))
2630 if ((c >= 0x0a05 && c <= 0x0a0a)
2631 || (c >= 0x0a0f && c <= 0x0a10)
2632 || (c >= 0x0a13 && c <= 0x0a28)
2633 || (c >= 0x0a2a && c <= 0x0a30)
2634 || (c >= 0x0a32 && c <= 0x0a33)
2635 || (c >= 0x0a35 && c <= 0x0a36)
2636 || (c >= 0x0a38 && c <= 0x0a39)
2637 || (c >= 0x0a59 && c <= 0x0a5c)
2642 if ((c >= 0x0a85 && c <= 0x0a8b)
2644 || (c >= 0x0a8f && c <= 0x0a91)
2645 || (c >= 0x0a93 && c <= 0x0aa8)
2646 || (c >= 0x0aaa && c <= 0x0ab0)
2647 || (c >= 0x0ab2 && c <= 0x0ab3)
2648 || (c >= 0x0ab5 && c <= 0x0ab9)
2653 if ((c >= 0x0b05 && c <= 0x0b0c)
2654 || (c >= 0x0b0f && c <= 0x0b10)
2655 || (c >= 0x0b13 && c <= 0x0b28)
2656 || (c >= 0x0b2a && c <= 0x0b30)
2657 || (c >= 0x0b32 && c <= 0x0b33)
2658 || (c >= 0x0b36 && c <= 0x0b39)
2659 || (c >= 0x0b5c && c <= 0x0b5d)
2660 || (c >= 0x0b5f && c <= 0x0b61))
2664 if ((c >= 0x0b85 && c <= 0x0b8a)
2665 || (c >= 0x0b8e && c <= 0x0b90)
2666 || (c >= 0x0b92 && c <= 0x0b95)
2667 || (c >= 0x0b99 && c <= 0x0b9a)
2669 || (c >= 0x0b9e && c <= 0x0b9f)
2670 || (c >= 0x0ba3 && c <= 0x0ba4)
2671 || (c >= 0x0ba8 && c <= 0x0baa)
2672 || (c >= 0x0bae && c <= 0x0bb5)
2673 || (c >= 0x0bb7 && c <= 0x0bb9))
2677 if ((c >= 0x0c05 && c <= 0x0c0c)
2678 || (c >= 0x0c0e && c <= 0x0c10)
2679 || (c >= 0x0c12 && c <= 0x0c28)
2680 || (c >= 0x0c2a && c <= 0x0c33)
2681 || (c >= 0x0c35 && c <= 0x0c39)
2682 || (c >= 0x0c60 && c <= 0x0c61))
2686 if ((c >= 0x0c85 && c <= 0x0c8c)
2687 || (c >= 0x0c8e && c <= 0x0c90)
2688 || (c >= 0x0c92 && c <= 0x0ca8)
2689 || (c >= 0x0caa && c <= 0x0cb3)
2690 || (c >= 0x0cb5 && c <= 0x0cb9)
2691 || (c >= 0x0ce0 && c <= 0x0ce1))
2695 if ((c >= 0x0d05 && c <= 0x0d0c)
2696 || (c >= 0x0d0e && c <= 0x0d10)
2697 || (c >= 0x0d12 && c <= 0x0d28)
2698 || (c >= 0x0d2a && c <= 0x0d39)
2699 || (c >= 0x0d60 && c <= 0x0d61))
2703 if ((c >= 0x0e01 && c <= 0x0e30)
2704 || (c >= 0x0e32 && c <= 0x0e33)
2705 || (c >= 0x0e40 && c <= 0x0e46)
2706 || (c >= 0x0e4f && c <= 0x0e5b))
2710 if ((c >= 0x0e81 && c <= 0x0e82)
2716 || (c >= 0x0e94 && c <= 0x0e97)
2717 || (c >= 0x0e99 && c <= 0x0e9f)
2718 || (c >= 0x0ea1 && c <= 0x0ea3)
2723 || (c >= 0x0ead && c <= 0x0eb0)
2727 || (c >= 0x0ec0 && c <= 0x0ec4)
2732 if ((c >= 0x10a0 && c <= 0x10c5)
2733 || (c >= 0x10d0 && c <= 0x10f6))
2737 if ((c >= 0x3041 && c <= 0x3094)
2738 || (c >= 0x309b && c <= 0x309e))
2742 if ((c >= 0x30a1 && c <= 0x30fe))
2746 if ((c >= 0x3105 && c <= 0x312c))
2750 if ((c >= 0x1100 && c <= 0x1159)
2751 || (c >= 0x1161 && c <= 0x11a2)
2752 || (c >= 0x11a8 && c <= 0x11f9))
2755 /* CJK Unified Ideographs */
2756 if ((c >= 0xf900 && c <= 0xfa2d)
2757 || (c >= 0xfb1f && c <= 0xfb36)
2758 || (c >= 0xfb38 && c <= 0xfb3c)
2760 || (c >= 0xfb40 && c <= 0xfb41)
2761 || (c >= 0xfb42 && c <= 0xfb44)
2762 || (c >= 0xfb46 && c <= 0xfbb1)
2763 || (c >= 0xfbd3 && c <= 0xfd3f)
2764 || (c >= 0xfd50 && c <= 0xfd8f)
2765 || (c >= 0xfd92 && c <= 0xfdc7)
2766 || (c >= 0xfdf0 && c <= 0xfdfb)
2767 || (c >= 0xfe70 && c <= 0xfe72)
2769 || (c >= 0xfe76 && c <= 0xfefc)
2770 || (c >= 0xff21 && c <= 0xff3a)
2771 || (c >= 0xff41 && c <= 0xff5a)
2772 || (c >= 0xff66 && c <= 0xffbe)
2773 || (c >= 0xffc2 && c <= 0xffc7)
2774 || (c >= 0xffca && c <= 0xffcf)
2775 || (c >= 0xffd2 && c <= 0xffd7)
2776 || (c >= 0xffda && c <= 0xffdc)
2777 || (c >= 0x4e00 && c <= 0x9fa5))
2780 error ("universal-character-name `\\u%04x' not valid in identifier", c);
2785 /* Add the UTF-8 representation of C to the token_buffer. */
2788 utf8_extend_token (c)
2793 if (c <= 0x0000007f)
2798 else if (c <= 0x000007ff)
2799 shift = 6, mask = 0xc0;
2800 else if (c <= 0x0000ffff)
2801 shift = 12, mask = 0xe0;
2802 else if (c <= 0x001fffff)
2803 shift = 18, mask = 0xf0;
2804 else if (c <= 0x03ffffff)
2805 shift = 24, mask = 0xf8;
2807 shift = 30, mask = 0xfc;
2809 extend_token (mask | (c >> shift));
2813 extend_token ((unsigned char) (0x80 | (c >> shift)));
2819 #define ENDFILE -1 /* token that represents end-of-file */
2821 /* Read an escape sequence, returning its equivalent as a character,
2822 or store 1 in *ignore_ptr if it is backslash-newline. */
2825 readescape (ignore_ptr)
2828 register int c = getch ();
2830 register unsigned count;
2831 unsigned firstdig = 0;
2849 if (c >= 'a' && c <= 'f')
2850 code += c - 'a' + 10;
2851 if (c >= 'A' && c <= 'F')
2852 code += c - 'A' + 10;
2853 if (c >= '0' && c <= '9')
2855 if (code != 0 || count != 0)
2864 error ("\\x used with no following hex digits");
2865 else if (count == 0)
2866 /* Digits are all 0's. Ok. */
2868 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
2871 << (TYPE_PRECISION (integer_type_node)
2874 pedwarn ("hex escape out of range");
2877 case '0': case '1': case '2': case '3': case '4':
2878 case '5': case '6': case '7':
2881 while ((c <= '7') && (c >= '0') && (count++ < 3))
2883 code = (code * 8) + (c - '0');
2890 return read_ucs (8);
2892 return read_ucs (4);
2894 case '\\': case '\'': case '"':
2903 return TARGET_NEWLINE;
2926 pedwarn ("non-ISO-standard escape sequence, `\\%c'", c);
2932 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
2936 /* `\%' is used to prevent SCCS from getting confused. */
2939 pedwarn ("unknown escape sequence `\\%c'", c);
2943 pedwarn ("unknown escape sequence `\\%c'", c);
2945 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
2953 extern int end_of_file;
2955 /* We can't print string and character constants well
2956 because the token_buffer contains the result of processing escapes. */
2959 if (input_redirected ())
2960 error ("%s at end of saved text", string);
2962 error ("%s at end of input", string);
2964 else if (token_buffer[0] == 0)
2965 error ("%s at null character", string);
2966 else if (token_buffer[0] == '"')
2967 error ("%s before string constant", string);
2968 else if (token_buffer[0] == '\'')
2969 error ("%s before character constant", string);
2970 else if (!ISGRAPH ((unsigned char)token_buffer[0]))
2971 error ("%s before character 0%o", string, (unsigned char) token_buffer[0]);
2973 error ("%s before `%s'", string, token_buffer);
2976 /* Value is 1 (or 2) if we should try to make the next identifier look like
2977 a typename (when it may be a local variable or a class variable).
2978 Value is 0 if we treat this name in a default fashion. */
2979 int looking_for_typename;
2982 identifier_type (decl)
2987 if (TREE_CODE (decl) == TEMPLATE_DECL)
2989 if (TREE_CODE (DECL_TEMPLATE_RESULT (decl)) == TYPE_DECL)
2991 else if (looking_for_template)
2994 if (looking_for_template && really_overloaded_fn (decl))
2996 /* See through a baselink. */
2997 if (TREE_CODE (decl) == TREE_LIST)
2998 decl = TREE_VALUE (decl);
3000 for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t))
3001 if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t)))
3004 if (TREE_CODE (decl) == NAMESPACE_DECL)
3006 if (TREE_CODE (decl) != TYPE_DECL)
3008 if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type)
3011 /* A constructor declarator for a template type will get here as an
3012 implicit typename, a TYPENAME_TYPE with a type. */
3014 if (t && TREE_CODE (t) == TYPENAME_TYPE)
3016 decl = TREE_TYPE (decl);
3017 if (TREE_CODE (decl) == TYPENAME_TYPE)
3018 decl = TREE_TYPE (decl);
3028 /* Only types expected, not even namespaces. */
3029 looking_for_typename = 2;
3031 if ((yychar = yylex ()) < 0) yychar = 0;
3032 looking_for_typename = 0;
3033 if (yychar == IDENTIFIER)
3035 lastiddecl = lookup_name (yylval.ttype, -2);
3036 if (lastiddecl == 0)
3039 lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype);
3042 yychar = identifier_type (lastiddecl);
3046 /* Return true if d is in a global scope. */
3053 switch (TREE_CODE (d))
3058 case OVERLOAD: d = OVL_FUNCTION (d); continue;
3059 case TREE_LIST: d = TREE_VALUE (d); continue;
3061 my_friendly_assert (DECL_P (d), 980629);
3063 return DECL_NAMESPACE_SCOPE_P (d);
3068 do_identifier (token, parsing, args)
3069 register tree token;
3074 int lexing = (parsing == 1);
3076 if (! lexing || IDENTIFIER_OPNAME_P (token))
3077 id = lookup_name (token, 0);
3081 /* Do Koenig lookup if appropriate (inside templates we build lookup
3082 expressions instead).
3084 [basic.lookup.koenig]: If the ordinary unqualified lookup of the name
3085 finds the declaration of a class member function, the associated
3086 namespaces and classes are not considered. */
3088 if (args && !current_template_parms && (!id || is_global (id)))
3089 id = lookup_arg_dependent (token, id, args);
3091 /* Remember that this name has been used in the class definition, as per
3094 maybe_note_name_used_in_class (token, id);
3096 if (id == error_mark_node)
3098 /* lookup_name quietly returns error_mark_node if we're parsing,
3099 as we don't want to complain about an identifier that ends up
3100 being used as a declarator. So we call it again to get the error
3102 id = lookup_name (token, 0);
3103 return error_mark_node;
3106 if (!id || (TREE_CODE (id) == FUNCTION_DECL
3107 && DECL_ANTICIPATED (id)))
3109 if (current_template_parms)
3110 return build_min_nt (LOOKUP_EXPR, token);
3111 else if (IDENTIFIER_OPNAME_P (token))
3113 if (token != ansi_opname (ERROR_MARK))
3114 cp_error ("`%D' not defined", token);
3115 id = error_mark_node;
3117 else if (current_function_decl == 0)
3119 cp_error ("`%D' was not declared in this scope", token);
3120 id = error_mark_node;
3124 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node
3125 || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
3127 static int undeclared_variable_notice;
3129 cp_error ("`%D' undeclared (first use this function)", token);
3131 if (! undeclared_variable_notice)
3133 error ("(Each undeclared identifier is reported only once for each function it appears in.)");
3134 undeclared_variable_notice = 1;
3137 id = error_mark_node;
3138 /* Prevent repeated error messages. */
3139 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3140 SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
3144 if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
3146 tree shadowed = DECL_SHADOWED_FOR_VAR (id);
3147 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
3148 && DECL_DEAD_FOR_LOCAL (shadowed))
3149 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
3151 shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id));
3154 if (!DECL_ERROR_REPORTED (id))
3156 warning ("name lookup of `%s' changed",
3157 IDENTIFIER_POINTER (token));
3158 cp_warning_at (" matches this `%D' under ISO standard rules",
3160 cp_warning_at (" matches this `%D' under old rules", id);
3161 DECL_ERROR_REPORTED (id) = 1;
3165 else if (!DECL_ERROR_REPORTED (id))
3167 DECL_ERROR_REPORTED (id) = 1;
3168 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (id)))
3170 error ("name lookup of `%s' changed for new ISO `for' scoping",
3171 IDENTIFIER_POINTER (token));
3172 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id);
3173 id = error_mark_node;
3177 pedwarn ("name lookup of `%s' changed for new ISO `for' scoping",
3178 IDENTIFIER_POINTER (token));
3179 cp_pedwarn_at (" using obsolete binding at `%D'", id);
3183 /* TREE_USED is set in `hack_identifier'. */
3184 if (TREE_CODE (id) == CONST_DECL)
3187 if (IDENTIFIER_CLASS_VALUE (token) == id)
3188 enforce_access (CP_DECL_CONTEXT(id), id);
3189 if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
3190 id = DECL_INITIAL (id);
3193 id = hack_identifier (id, token);
3195 /* We must look up dependent names when the template is
3196 instantiated, not while parsing it. For now, we don't
3197 distinguish between dependent and independent names. So, for
3198 example, we look up all overloaded functions at
3199 instantiation-time, even though in some cases we should just use
3200 the DECL we have here. We also use LOOKUP_EXPRs to find things
3201 like local variables, rather than creating TEMPLATE_DECLs for the
3202 local variables and then finding matching instantiations. */
3203 if (current_template_parms
3204 && (is_overloaded_fn (id)
3205 /* Some local VAR_DECLs (such as those for local variables
3206 in member functions of local classes) are built on the
3207 permanent obstack. */
3208 || (TREE_CODE (id) == VAR_DECL
3209 && CP_DECL_CONTEXT (id)
3210 && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL)
3211 || TREE_CODE (id) == PARM_DECL
3212 || TREE_CODE (id) == RESULT_DECL
3213 || TREE_CODE (id) == USING_DECL))
3214 id = build_min_nt (LOOKUP_EXPR, token);
3220 do_scoped_id (token, parsing)
3225 /* during parsing, this is ::name. Otherwise, it is black magic. */
3228 id = make_node (CPLUS_BINDING);
3229 if (!qualified_lookup_using_namespace (token, global_namespace, id, 0))
3232 id = BINDING_VALUE (id);
3235 id = IDENTIFIER_GLOBAL_VALUE (token);
3236 if (parsing && yychar == YYEMPTY)
3240 if (processing_template_decl)
3242 id = build_min_nt (LOOKUP_EXPR, token);
3243 LOOKUP_EXPR_GLOBAL (id) = 1;
3246 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
3247 cp_error ("`::%D' undeclared (first use here)", token);
3248 id = error_mark_node;
3249 /* Prevent repeated error messages. */
3250 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3254 if (TREE_CODE (id) == ADDR_EXPR)
3255 mark_used (TREE_OPERAND (id, 0));
3256 else if (TREE_CODE (id) != OVERLOAD)
3259 if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
3261 /* XXX CHS - should we set TREE_USED of the constant? */
3262 id = DECL_INITIAL (id);
3263 /* This is to prevent an enum whose value is 0
3264 from being considered a null pointer constant. */
3265 id = build1 (NOP_EXPR, TREE_TYPE (id), id);
3266 TREE_CONSTANT (id) = 1;
3269 if (processing_template_decl)
3271 if (is_overloaded_fn (id))
3273 id = build_min_nt (LOOKUP_EXPR, token);
3274 LOOKUP_EXPR_GLOBAL (id) = 1;
3277 /* else just use the decl */
3279 return convert_from_reference (id);
3283 identifier_typedecl_value (node)
3287 type = IDENTIFIER_TYPE_VALUE (node);
3288 if (type == NULL_TREE)
3291 if (IDENTIFIER_BINDING (node))
3293 t = IDENTIFIER_VALUE (node);
3294 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3297 if (IDENTIFIER_NAMESPACE_VALUE (node))
3299 t = IDENTIFIER_NAMESPACE_VALUE (node);
3300 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3304 /* Will this one ever happen? */
3305 if (TYPE_MAIN_DECL (type))
3306 return TYPE_MAIN_DECL (type);
3308 /* We used to do an internal error of 62 here, but instead we will
3309 handle the return of a null appropriately in the callers. */
3323 int conversion_errno;
3324 REAL_VALUE_TYPE value;
3331 struct pf_args * args = (struct pf_args *) data;
3332 int fflag = 0, lflag = 0;
3333 /* Copy token_buffer now, while it has just the number
3334 and not the suffixes; once we add `f' or `i',
3335 REAL_VALUE_ATOF may not work any more. */
3336 char *copy = (char *) alloca (args->p - token_buffer + 1);
3337 bcopy (token_buffer, copy, args->p - token_buffer + 1);
3339 args->conversion_errno = 0;
3340 args->type = double_type_node;
3346 /* Read the suffixes to choose a data type. */
3351 error ("more than one `f' in numeric constant");
3357 error ("more than one `l' in numeric constant");
3363 error ("more than one `i' or `j' in numeric constant");
3365 pedwarn ("ISO C++ forbids imaginary numeric constants");
3376 if (args->p >= token_buffer + maxtoken - 3)
3377 args->p = extend_token_buffer (args->p);
3378 *(args->p++) = args->c;
3383 /* The second argument, machine_mode, of REAL_VALUE_ATOF
3384 tells the desired precision of the binary result
3385 of decimal-to-binary conversion. */
3390 error ("both `f' and `l' in floating constant");
3392 args->type = float_type_node;
3394 if (args->base == 16)
3395 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3397 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3398 args->conversion_errno = errno;
3399 /* A diagnostic is required here by some ANSI C testsuites.
3400 This is not pedwarn, because some people don't want
3401 an error for this. */
3402 if (REAL_VALUE_ISINF (args->value) && pedantic)
3403 warning ("floating point number exceeds range of `float'");
3407 args->type = long_double_type_node;
3409 if (args->base == 16)
3410 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3412 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3413 args->conversion_errno = errno;
3414 if (REAL_VALUE_ISINF (args->value) && pedantic)
3415 warning ("floating point number exceeds range of `long double'");
3420 if (args->base == 16)
3421 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3423 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3424 args->conversion_errno = errno;
3425 if (REAL_VALUE_ISINF (args->value) && pedantic)
3426 warning ("floating point number exceeds range of `double'");
3430 /* Get the next character, staying within the current token if possible.
3431 If we're lexing a token, we don't want to look beyond the end of the
3432 token cpplib has prepared for us; otherwise, we end up reading in the
3433 next token, which screws up feed_input. So just return a null
3440 if (yy_cur == yy_lim)
3457 /* Read a single token from the input stream, and assign it lexical
3460 Note: We used to do token pasting here, to produce compound tokens like
3461 LEFT_RIGHT and EXTERN_LANG_STRING. That's now handled in spew.c, along
3462 with symbol table interaction and other context-sensitivity. */
3474 /* Effectively do c = skip_white_space (c)
3475 but do it faster in the usual cases. */
3485 if (cpp_token == CPP_HSPACE)
3486 c = yy_get_token ();
3493 /* Call skip_white_space so we can warn if appropriate. */
3498 c = skip_white_space (c);
3500 goto found_nonwhite;
3504 token_buffer[0] = c;
3505 token_buffer[1] = 0;
3507 /* yylloc.first_line = lineno; */
3513 token_buffer[0] = 0;
3515 value = END_OF_LINE;
3516 else if (input_redirected ())
3517 value = END_OF_SAVED_INPUT;
3524 if (cpp_token == CPP_NAME)
3527 /* Capital L may start a wide-string or wide-character constant. */
3529 register int c = token_getch ();
3538 goto string_constant;
3543 case 'A': case 'B': case 'C': case 'D': case 'E':
3544 case 'F': case 'G': case 'H': case 'I': case 'J':
3545 case 'K': case 'M': case 'N': case 'O':
3546 case 'P': case 'Q': case 'R': case 'S': case 'T':
3547 case 'U': case 'V': case 'W': case 'X': case 'Y':
3549 case 'a': case 'b': case 'c': case 'd': case 'e':
3550 case 'f': case 'g': case 'h': case 'i': case 'j':
3551 case 'k': case 'l': case 'm': case 'n': case 'o':
3552 case 'p': case 'q': case 'r': case 's': case 't':
3553 case 'u': case 'v': case 'w': case 'x': case 'y':
3559 if (cpp_token == CPP_NAME)
3561 /* Note that one character has already been read from
3562 yy_cur into token_buffer. Also, cpplib complains about
3563 $ in identifiers, so we don't have to. */
3565 int len = yy_lim - yy_cur + 1;
3566 if (len >= maxtoken)
3567 extend_token_buffer_to (len + 1);
3568 memcpy (token_buffer + 1, yy_cur, len);
3569 p = token_buffer + len;
3578 /* Make sure this char really belongs in an identifier. */
3579 if (ISALNUM (c) || c == '_')
3583 if (! dollars_in_ident)
3584 error ("`$' in identifier");
3586 pedwarn ("`$' in identifier");
3588 /* FIXME we should use some sort of multibyte character
3589 encoding. Locale-dependent? Always UTF-8? */
3590 else if (is_extended_char (c))
3592 sorry ("universal characters in identifiers");
3598 if (p >= token_buffer + maxtoken)
3599 p = extend_token_buffer (p);
3609 c = readescape (&ignore);
3622 /* Try to recognize a keyword. Uses minimum-perfect hash function */
3625 register struct resword *ptr;
3627 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
3631 if (ptr->token == VISSPEC)
3636 yylval.ttype = access_public_node;
3639 yylval.ttype = access_private_node;
3642 yylval.ttype = access_protected_node;
3645 my_friendly_abort (63);
3649 yylval.ttype = ridpointers[(int) ptr->rid];
3651 else switch (ptr->token)
3654 yylval.code = NE_EXPR;
3655 token_buffer[0] = '!';
3656 token_buffer[1] = '=';
3657 token_buffer[2] = 0;
3661 if (strcmp ("and_eq", token_buffer) == 0)
3663 yylval.code = BIT_AND_EXPR;
3664 token_buffer[0] = '&';
3666 else if (strcmp ("or_eq", token_buffer) == 0)
3668 yylval.code = BIT_IOR_EXPR;
3669 token_buffer[0] = '|';
3671 else if (strcmp ("xor_eq", token_buffer) == 0)
3673 yylval.code = BIT_XOR_EXPR;
3674 token_buffer[0] = '^';
3676 token_buffer[1] = '=';
3677 token_buffer[2] = 0;
3681 yylval.code = BIT_AND_EXPR;
3682 token_buffer[0] = '&';
3683 token_buffer[1] = 0;
3687 yylval.code = BIT_IOR_EXPR;
3688 token_buffer[0] = '|';
3689 token_buffer[1] = 0;
3693 yylval.code = BIT_XOR_EXPR;
3694 token_buffer[0] = '^';
3695 token_buffer[1] = 0;
3699 value = (int) ptr->token;
3703 /* If we did not find a keyword, look for an identifier
3706 if (value == IDENTIFIER || value == TYPESPEC)
3707 GNU_xref_ref (current_function_decl, token_buffer);
3709 if (value == IDENTIFIER)
3711 register tree tmp = get_identifier (token_buffer);
3713 #if !defined(VMS) && defined(JOINER)
3714 /* Make sure that user does not collide with our internal
3717 && (THIS_NAME_P (tmp)
3718 || VPTR_NAME_P (tmp)
3719 || DESTRUCTOR_NAME_P (tmp)
3720 || VTABLE_NAME_P (tmp)
3721 || TEMP_NAME_P (tmp)
3722 || ANON_AGGRNAME_P (tmp)
3723 || ANON_PARMNAME_P (tmp)))
3724 warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3730 if (value == NEW && ! global_bindings_p ())
3739 if (yy_cur < yy_lim)
3742 /* It's hard to preserve tokenization on '.' because
3743 it could be a symbol by itself, or it could be the
3744 start of a floating point number and cpp won't tell us. */
3745 register int c1 = token_getch ();
3746 token_buffer[1] = c1;
3750 token_buffer[2] = 0;
3755 c1 = token_getch ();
3758 token_buffer[2] = c1;
3759 token_buffer[3] = 0;
3763 error ("parse error at `..'");
3767 token_put_back (c1);
3770 token_put_back (c1);
3773 token_buffer[1] = 0;
3777 /* Optimize for most frequent case. */
3782 cond = (yy_cur == yy_lim);
3784 register int c1 = token_getch ();
3785 token_put_back (c1);
3786 cond = (! ISALNUM (c1) && c1 != '.');
3790 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
3796 case '2': case '3': case '4':
3797 case '5': case '6': case '7': case '8': case '9':
3802 int largest_digit = 0;
3806 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
3807 The code below which fills the parts array assumes that a host
3808 int is at least twice as wide as a host char, and that
3809 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
3810 Two HOST_WIDE_INTs is the largest int literal we can store.
3811 In order to detect overflow below, the number of parts (TOTAL_PARTS)
3812 must be exactly the number of parts needed to hold the bits
3813 of two HOST_WIDE_INTs. */
3814 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
3815 unsigned int parts[TOTAL_PARTS];
3817 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON }
3818 floatflag = NOT_FLOAT;
3820 for (count = 0; count < TOTAL_PARTS; count++)
3828 *p++ = (c = token_getch ());
3829 if ((c == 'x') || (c == 'X'))
3832 *p++ = (c = token_getch ());
3834 /* Leading 0 forces octal unless the 0 is the only digit. */
3835 else if (c >= '0' && c <= '9')
3844 /* Read all the digits-and-decimal-points. */
3847 || (ISALNUM (c) && c != 'l' && c != 'L'
3848 && c != 'u' && c != 'U'
3849 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
3850 && (floatflag == NOT_FLOAT
3851 || ((base != 16) && (c != 'f') && (c != 'F'))
3856 if (base == 16 && pedantic)
3857 pedwarn ("floating constant may not be in radix 16");
3858 if (floatflag == TOO_MANY_POINTS)
3859 /* We have already emitted an error. Don't need another. */
3861 else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON)
3863 error ("malformed floating constant");
3864 floatflag = TOO_MANY_POINTS;
3865 /* Avoid another error from atof by forcing all characters
3866 from here on to be ignored. */
3870 floatflag = AFTER_POINT;
3874 *p++ = c = token_getch ();
3875 /* Accept '.' as the start of a floating-point number
3876 only when it is followed by a digit. */
3877 if (p == token_buffer + 2 && !ISDIGIT (c))
3878 my_friendly_abort (990710);
3882 /* It is not a decimal point.
3883 It should be a digit (perhaps a hex digit). */
3889 else if (base <= 10)
3891 if (c == 'e' || c == 'E')
3894 floatflag = AFTER_EXPON;
3895 break; /* start of exponent */
3897 error ("nondigits in number and not hexadecimal");
3900 else if (base == 16 && (c == 'p' || c == 'P'))
3902 floatflag = AFTER_EXPON;
3903 break; /* start of exponent */
3913 if (c >= largest_digit)
3917 for (count = 0; count < TOTAL_PARTS; count++)
3919 parts[count] *= base;
3923 += (parts[count-1] >> HOST_BITS_PER_CHAR);
3925 &= (1 << HOST_BITS_PER_CHAR) - 1;
3931 /* If the highest-order part overflows (gets larger than
3932 a host char will hold) then the whole number has
3933 overflowed. Record this and truncate the highest-order
3935 if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
3938 parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
3941 if (p >= token_buffer + maxtoken - 3)
3942 p = extend_token_buffer (p);
3943 *p++ = (c = token_getch ());
3947 /* This can happen on input like `int i = 0x;' */
3949 error ("numeric constant with no digits");
3951 if (largest_digit >= base)
3952 error ("numeric constant contains digits beyond the radix");
3954 /* Remove terminating char from the token buffer and delimit the
3958 if (floatflag != NOT_FLOAT)
3961 int imag, conversion_errno;
3962 REAL_VALUE_TYPE value;
3963 struct pf_args args;
3965 /* Read explicit exponent if any, and put it in tokenbuf. */
3967 if ((base == 10 && ((c == 'e') || (c == 'E')))
3968 || (base == 16 && (c == 'p' || c == 'P')))
3970 if (p >= token_buffer + maxtoken - 3)
3971 p = extend_token_buffer (p);
3974 if ((c == '+') || (c == '-'))
3979 /* Exponent is decimal, even if string is a hex float. */
3981 error ("floating constant exponent has no digits");
3984 if (p >= token_buffer + maxtoken - 3)
3985 p = extend_token_buffer (p);
3990 if (base == 16 && floatflag != AFTER_EXPON)
3991 error ("hexadecimal floating constant has no exponent");
3995 /* Setup input for parse_float() */
4000 /* Convert string to a double, checking for overflow. */
4001 if (do_float_handler (parse_float, (PTR) &args))
4003 /* Receive output from parse_float() */
4008 /* We got an exception from parse_float() */
4009 error ("floating constant out of range");
4013 /* Receive output from parse_float() */
4017 conversion_errno = args.conversion_errno;
4020 /* ERANGE is also reported for underflow,
4021 so test the value to distinguish overflow from that. */
4022 if (conversion_errno == ERANGE && pedantic
4023 && (REAL_VALUES_LESS (dconst1, value)
4024 || REAL_VALUES_LESS (value, dconstm1)))
4025 warning ("floating point number exceeds range of `double'");
4028 /* If the result is not a number, assume it must have been
4029 due to some error message above, so silently convert
4031 if (REAL_VALUE_ISNAN (value))
4034 /* Create a node with determined type and value. */
4036 yylval.ttype = build_complex (NULL_TREE,
4037 convert (type, integer_zero_node),
4038 build_real (type, value));
4040 yylval.ttype = build_real (type, value);
4045 HOST_WIDE_INT high, low;
4046 int spec_unsigned = 0;
4048 int spec_long_long = 0;
4055 if (c == 'u' || c == 'U')
4058 error ("two `u's in integer constant");
4061 else if (c == 'l' || c == 'L')
4066 error ("three `l's in integer constant");
4067 else if (pedantic && ! in_system_header && warn_long_long)
4068 pedwarn ("ISO C++ forbids long long integer constants");
4073 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
4076 error ("more than one `i' or `j' in numeric constant");
4078 pedwarn ("ISO C++ forbids imaginary numeric constants");
4083 if (p >= token_buffer + maxtoken - 3)
4084 p = extend_token_buffer (p);
4089 /* If the literal overflowed, pedwarn about it now. */
4093 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
4096 /* This is simplified by the fact that our constant
4097 is always positive. */
4101 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
4103 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
4104 / HOST_BITS_PER_CHAR)]
4105 << (i * HOST_BITS_PER_CHAR));
4106 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
4109 yylval.ttype = build_int_2 (low, high);
4110 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
4112 /* Calculate the ANSI type. */
4113 if (! spec_long && ! spec_unsigned
4114 && int_fits_type_p (yylval.ttype, integer_type_node))
4115 type = integer_type_node;
4116 else if (! spec_long && (base != 10 || spec_unsigned)
4117 && int_fits_type_p (yylval.ttype, unsigned_type_node))
4118 type = unsigned_type_node;
4119 else if (! spec_unsigned && !spec_long_long
4120 && int_fits_type_p (yylval.ttype, long_integer_type_node))
4121 type = long_integer_type_node;
4122 else if (! spec_long_long
4123 && int_fits_type_p (yylval.ttype,
4124 long_unsigned_type_node))
4125 type = long_unsigned_type_node;
4126 else if (! spec_unsigned
4127 && int_fits_type_p (yylval.ttype,
4128 long_long_integer_type_node))
4129 type = long_long_integer_type_node;
4130 else if (int_fits_type_p (yylval.ttype,
4131 long_long_unsigned_type_node))
4132 type = long_long_unsigned_type_node;
4133 else if (! spec_unsigned
4134 && int_fits_type_p (yylval.ttype,
4135 widest_integer_literal_type_node))
4136 type = widest_integer_literal_type_node;
4138 type = widest_unsigned_literal_type_node;
4140 if (pedantic && !spec_long_long && !warn
4141 && (TYPE_PRECISION (long_integer_type_node)
4142 < TYPE_PRECISION (type)))
4145 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
4148 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
4149 warning ("decimal constant is so large that it is unsigned");
4153 if (TYPE_PRECISION (type)
4154 <= TYPE_PRECISION (integer_type_node))
4156 = build_complex (NULL_TREE, integer_zero_node,
4157 convert (integer_type_node,
4160 error ("complex integer constant is too wide for `__complex int'");
4163 TREE_TYPE (yylval.ttype) = type;
4166 /* If it's still an integer (not a complex), and it doesn't
4167 fit in the type we choose for it, then pedwarn. */
4170 && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
4171 && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
4172 pedwarn ("integer constant is larger than the maximum value for its type");
4178 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
4179 || ((c == '-' || c == '+')
4180 && (p[-1] == 'e' || p[-1] == 'E')))
4181 error ("missing white space after number `%s'", token_buffer);
4183 value = CONSTANT; break;
4189 register int result = 0;
4190 register int num_chars = 0;
4192 unsigned width = TYPE_PRECISION (char_type_node);
4194 #ifdef MULTIBYTE_CHARS
4195 int longest_char = local_mb_cur_max ();
4196 local_mbtowc (NULL_PTR, NULL_PTR, 0);
4199 max_chars = TYPE_PRECISION (integer_type_node) / width;
4201 width = WCHAR_TYPE_SIZE;
4208 if (c == '\'' || c == EOF)
4215 c = readescape (&ignore);
4218 if (width < HOST_BITS_PER_INT
4219 && (unsigned) c >= ((unsigned)1 << width))
4220 pedwarn ("escape sequence out of range for character");
4221 #ifdef MAP_CHARACTER
4223 c = MAP_CHARACTER (c);
4229 pedwarn ("ISO C++ forbids newline in character constant");
4234 #ifdef MULTIBYTE_CHARS
4238 for (i = 1; i <= longest_char; ++i)
4240 if (i > maxtoken - 4)
4241 extend_token_buffer (token_buffer);
4243 token_buffer[i] = c;
4244 char_len = local_mbtowc (& wc,
4253 /* mbtowc sometimes needs an extra char before accepting */
4258 /* Merge character into result; ignore excess chars. */
4259 for (i = 1; i <= char_len; ++i)
4263 if (width < HOST_BITS_PER_INT)
4264 result = (result << width)
4266 & ((1 << width) - 1));
4268 result = token_buffer[i];
4270 num_chars += char_len;
4279 warning ("Ignoring invalid multibyte character");
4280 /* Replace all but the first byte. */
4281 for (--i; i > 1; --i)
4282 token_put_back (token_buffer[i]);
4283 wc = token_buffer[1];
4285 #ifdef MAP_CHARACTER
4286 c = MAP_CHARACTER (wc);
4291 #else /* ! MULTIBYTE_CHARS */
4292 #ifdef MAP_CHARACTER
4293 c = MAP_CHARACTER (c);
4295 #endif /* ! MULTIBYTE_CHARS */
4300 if (chars_seen == 1) /* only keep the first one */
4305 /* Merge character into result; ignore excess chars. */
4306 num_chars += (width / TYPE_PRECISION (char_type_node));
4307 if (num_chars < max_chars + 1)
4309 if (width < HOST_BITS_PER_INT)
4310 result = (result << width) | (c & ((1 << width) - 1));
4317 error ("malformatted character constant");
4318 else if (chars_seen == 0)
4319 error ("empty character constant");
4320 else if (num_chars > max_chars)
4322 num_chars = max_chars;
4323 error ("character constant too long");
4325 else if (chars_seen != 1 && warn_multichar)
4326 warning ("multi-character character constant");
4328 /* If char type is signed, sign-extend the constant. */
4331 int num_bits = num_chars * width;
4333 /* We already got an error; avoid invalid shift. */
4334 yylval.ttype = build_int_2 (0, 0);
4335 else if (TREE_UNSIGNED (char_type_node)
4336 || ((result >> (num_bits - 1)) & 1) == 0)
4338 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
4339 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4343 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
4344 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4346 /* In C, a character constant has type 'int'; in C++, 'char'. */
4347 if (chars_seen <= 1)
4348 TREE_TYPE (yylval.ttype) = char_type_node;
4350 TREE_TYPE (yylval.ttype) = integer_type_node;
4354 yylval.ttype = build_int_2 (result, 0);
4355 TREE_TYPE (yylval.ttype) = wchar_type_node;
4365 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
4366 : TYPE_PRECISION (char_type_node);
4367 #ifdef MULTIBYTE_CHARS
4368 int longest_char = local_mb_cur_max ();
4369 local_mbtowc (NULL_PTR, NULL_PTR, 0);
4373 p = token_buffer + 1;
4375 while (c != '"' && c != EOF)
4377 /* ignore_escape_flag is set for reading the filename in #line. */
4378 if (!ignore_escape_flag && c == '\\')
4381 c = readescape (&ignore);
4384 if (width < HOST_BITS_PER_INT
4385 && (unsigned) c >= ((unsigned)1 << width))
4386 pedwarn ("escape sequence out of range for character");
4391 pedwarn ("ISO C++ forbids newline in string constant");
4396 #ifdef MULTIBYTE_CHARS
4400 for (i = 0; i < longest_char; ++i)
4402 if (p + i >= token_buffer + maxtoken)
4403 p = extend_token_buffer (p);
4406 char_len = local_mbtowc (& wc, p, i + 1);
4413 warning ("Ignoring invalid multibyte character");
4414 /* Replace all except the first byte. */
4416 for (--i; i > 0; --i)
4417 token_put_back (p[i]);
4420 /* mbtowc sometimes needs an extra char before accepting */
4430 #endif /* MULTIBYTE_CHARS */
4433 /* Add this single character into the buffer either as a wchar_t
4434 or as a single byte. */
4437 unsigned width = TYPE_PRECISION (char_type_node);
4438 unsigned bytemask = (1 << width) - 1;
4441 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4442 p = extend_token_buffer (p);
4444 for (byte = 0; byte < WCHAR_BYTES; ++byte)
4447 if (byte >= (int) sizeof (c))
4450 value = (c >> (byte * width)) & bytemask;
4451 if (BYTES_BIG_ENDIAN)
4452 p[WCHAR_BYTES - byte - 1] = value;
4460 if (p >= token_buffer + maxtoken)
4461 p = extend_token_buffer (p);
4469 /* Terminate the string value, either with a single byte zero
4470 or with a wide zero. */
4473 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4474 p = extend_token_buffer (p);
4475 bzero (p, WCHAR_BYTES);
4480 if (p >= token_buffer + maxtoken)
4481 p = extend_token_buffer (p);
4486 error ("Unterminated string constant");
4488 /* We have read the entire constant.
4489 Construct a STRING_CST for the result. */
4491 yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1);
4494 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
4496 TREE_TYPE (yylval.ttype) = char_array_type_node;
4498 value = STRING; break;
4522 yylval.code = PLUS_EXPR; break;
4524 yylval.code = MINUS_EXPR; break;
4526 yylval.code = BIT_AND_EXPR; break;
4528 yylval.code = BIT_IOR_EXPR; break;
4530 yylval.code = MULT_EXPR; break;
4532 yylval.code = TRUNC_DIV_EXPR; break;
4534 yylval.code = TRUNC_MOD_EXPR; break;
4536 yylval.code = BIT_XOR_EXPR; break;
4538 yylval.code = LSHIFT_EXPR; break;
4540 yylval.code = RSHIFT_EXPR; break;
4542 yylval.code = LT_EXPR; break;
4544 yylval.code = GT_EXPR; break;
4547 token_buffer[1] = c1 = token_getch ();
4548 token_buffer[2] = 0;
4555 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
4557 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
4559 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
4561 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
4563 value = ASSIGN; goto done;
4569 value = PLUSPLUS; goto done;
4571 value = MINUSMINUS; goto done;
4573 value = ANDAND; goto done;
4575 value = OROR; goto done;
4587 else if (c1 == '?' && (c == '<' || c == '>'))
4589 token_buffer[3] = 0;
4591 c1 = token_getch ();
4592 yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR);
4595 /* <?= or >?= expression. */
4596 token_buffer[2] = c1;
4602 token_put_back (c1);
4605 pedwarn ("use of `operator %s' is not standard C++",
4615 c1 = token_getch ();
4617 value = POINTSAT_STAR;
4620 token_put_back (c1);
4630 { value = ']'; goto done; }
4634 { value = '{'; indent_level++; goto done; }
4636 { value = '['; goto done; }
4640 { value = '}'; indent_level--; goto done; }
4644 token_put_back (c1);
4645 token_buffer[1] = 0;
4647 /* Here the C frontend changes < and > to ARITHCOMPARE. We don't
4648 do that because of templates. */
4655 /* Don't make yyparse think this is eof. */
4670 if (is_extended_char (c))
4676 /* yylloc.last_line = lineno; */
4677 #ifdef GATHER_STATISTICS
4678 #ifdef REDUCE_LENGTH
4679 token_count[value] += 1;
4690 return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
4693 #ifdef GATHER_STATISTICS
4694 /* The original for tree_node_kind is in the toplevel tree.c; changes there
4695 need to be brought into here, unless this were actually put into a header
4697 /* Statistics-gathering stuff. */
4718 extern int tree_node_counts[];
4719 extern int tree_node_sizes[];
4723 build_lang_decl (code, name, type)
4724 enum tree_code code;
4730 t = build_decl (code, name, type);
4731 retrofit_lang_decl (t);
4736 /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
4737 and pushdecl (for functions generated by the backend). */
4740 retrofit_lang_decl (t)
4743 struct lang_decl *ld;
4746 if (CAN_HAVE_FULL_LANG_DECL_P (t))
4747 size = sizeof (struct lang_decl);
4749 size = sizeof (struct lang_decl_flags);
4751 ld = (struct lang_decl *) ggc_alloc_cleared (size);
4753 DECL_LANG_SPECIFIC (t) = ld;
4754 if (current_lang_name == lang_name_cplusplus)
4755 DECL_LANGUAGE (t) = lang_cplusplus;
4756 else if (current_lang_name == lang_name_c)
4757 DECL_LANGUAGE (t) = lang_c;
4758 else if (current_lang_name == lang_name_java)
4759 DECL_LANGUAGE (t) = lang_java;
4760 else my_friendly_abort (64);
4762 #ifdef GATHER_STATISTICS
4763 tree_node_counts[(int)lang_decl] += 1;
4764 tree_node_sizes[(int)lang_decl] += size;
4769 copy_lang_decl (node)
4773 struct lang_decl *ld;
4775 if (! DECL_LANG_SPECIFIC (node))
4778 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
4779 size = sizeof (struct lang_decl_flags);
4781 size = sizeof (struct lang_decl);
4782 ld = (struct lang_decl *) ggc_alloc (size);
4783 bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)ld, size);
4784 DECL_LANG_SPECIFIC (node) = ld;
4787 /* Copy DECL, including any language-specific parts. */
4795 copy = copy_node (decl);
4796 copy_lang_decl (copy);
4801 cp_make_lang_type (code)
4802 enum tree_code code;
4804 register tree t = make_node (code);
4806 /* Set up some flags that give proper default behavior. */
4807 if (IS_AGGR_TYPE_CODE (code))
4809 struct lang_type *pi;
4811 pi = (struct lang_type *) ggc_alloc (sizeof (struct lang_type));
4812 bzero ((char *) pi, (int) sizeof (struct lang_type));
4814 TYPE_LANG_SPECIFIC (t) = pi;
4815 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
4816 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
4818 /* Make sure this is laid out, for ease of use later. In the
4819 presence of parse errors, the normal was of assuring this
4820 might not ever get executed, so we lay it out *immediately*. */
4821 build_pointer_type (t);
4823 #ifdef GATHER_STATISTICS
4824 tree_node_counts[(int)lang_type] += 1;
4825 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
4829 /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
4830 TYPE_ALIAS_SET is initialized to -1 by default, so we must
4832 TYPE_ALIAS_SET (t) = 0;
4834 /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
4835 since they can be virtual base types, and we then need a
4836 canonical binfo for them. Ideally, this would be done lazily for
4838 if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM)
4839 TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
4845 make_aggr_type (code)
4846 enum tree_code code;
4848 tree t = cp_make_lang_type (code);
4850 if (IS_AGGR_TYPE_CODE (code))
4851 SET_IS_AGGR_TYPE (t, 1);
4857 dump_time_statistics ()
4859 register tree prev = 0, decl, next;
4860 int this_time = get_run_time ();
4861 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
4862 += this_time - body_time;
4864 fprintf (stderr, "\n******\n");
4865 print_time ("header files (total)", header_time);
4866 print_time ("main file (total)", this_time - body_time);
4867 fprintf (stderr, "ratio = %g : 1\n",
4868 (double)header_time / (double)(this_time - body_time));
4869 fprintf (stderr, "\n******\n");
4871 for (decl = filename_times; decl; decl = next)
4873 next = IDENTIFIER_GLOBAL_VALUE (decl);
4874 SET_IDENTIFIER_GLOBAL_VALUE (decl, prev);
4878 for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl))
4879 print_time (IDENTIFIER_POINTER (decl),
4880 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (decl)));
4884 compiler_error VPARAMS ((const char *msg, ...))
4886 #ifndef ANSI_PROTOTYPES
4894 #ifndef ANSI_PROTOTYPES
4895 msg = va_arg (ap, const char *);
4898 vsprintf (buf, msg, ap);
4900 error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
4903 /* Return the type-qualifier corresponding to the identifier given by
4907 cp_type_qual_from_rid (rid)
4910 if (rid == ridpointers[(int) RID_CONST])
4911 return TYPE_QUAL_CONST;
4912 else if (rid == ridpointers[(int) RID_VOLATILE])
4913 return TYPE_QUAL_VOLATILE;
4914 else if (rid == ridpointers[(int) RID_RESTRICT])
4915 return TYPE_QUAL_RESTRICT;
4917 my_friendly_abort (0);
4918 return TYPE_UNQUALIFIED;