* decl.c (grokfndecl): Remove dead code.
[official-gcc.git] / gcc / cp / lex.c
bloba672bd0b249f43d616478d29373cf9021a2895f8
1 /* Separate lexical analyzer for GNU C++.
2 Copyright (C) 1987, 89, 92-98, 1999 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file is the lexical analyzer for GNU C++. */
25 /* Cause the `yydebug' variable to be defined. */
26 #define YYDEBUG 1
28 #include "config.h"
29 #include "system.h"
30 #include "input.h"
31 #include "tree.h"
32 #include "lex.h"
33 #include "cp-tree.h"
34 #include "parse.h"
35 #include "flags.h"
36 #include "obstack.h"
37 #include "c-pragma.h"
38 #include "toplev.h"
39 #include "output.h"
40 #include "ggc.h"
42 #ifdef MULTIBYTE_CHARS
43 #include "mbchar.h"
44 #include <locale.h>
45 #endif
47 #define obstack_chunk_alloc xmalloc
48 #define obstack_chunk_free free
50 #ifndef DIR_SEPARATOR
51 #define DIR_SEPARATOR '/'
52 #endif
54 extern struct obstack permanent_obstack;
55 extern struct obstack *current_obstack, *saveable_obstack;
57 extern void yyprint PROTO((FILE *, int, YYSTYPE));
59 static tree get_time_identifier PROTO((const char *));
60 static int check_newline PROTO((void));
61 static int whitespace_cr PROTO((int));
62 static int skip_white_space PROTO((int));
63 static void finish_defarg PROTO((void));
64 static int my_get_run_time PROTO((void));
65 static int interface_strcmp PROTO((const char *));
66 static int readescape PROTO((int *));
67 static char *extend_token_buffer PROTO((const char *));
68 static void consume_string PROTO((struct obstack *, int));
69 static void feed_defarg PROTO((tree, tree));
70 static void store_pending_inline PROTO((tree, struct pending_inline *));
71 static void reinit_parse_for_expr PROTO((struct obstack *));
72 static int *init_cpp_parse PROTO((void));
73 static void cp_pragma_interface PROTO((char *));
74 static void cp_pragma_implementation PROTO ((char *));
75 static int handle_cp_pragma PROTO((const char *));
76 #ifdef HANDLE_GENERIC_PRAGMAS
77 static int handle_generic_pragma PROTO((int));
78 #endif
79 #ifdef GATHER_STATISTICS
80 #ifdef REDUCE_LENGTH
81 static int reduce_cmp PROTO((int *, int *));
82 static int token_cmp PROTO((int *, int *));
83 #endif
84 #endif
85 static void begin_definition_of_inclass_inline PROTO((struct pending_inline*));
86 static void parse_float PROTO((PTR));
87 static int is_global PROTO((tree));
88 static void init_filename_times PROTO((void));
89 static void extend_token_buffer_to PROTO((int));
90 #ifdef HANDLE_PRAGMA
91 static int pragma_getc PROTO((void));
92 static void pragma_ungetc PROTO((int));
93 #endif
94 static int read_line_number PROTO((int *));
95 static int token_getch PROTO ((void));
96 static void token_put_back PROTO ((int));
97 static void mark_impl_file_chain PROTO ((void *));
99 /* Given a file name X, return the nondirectory portion.
100 Keep in mind that X can be computed more than once. */
101 char *
102 file_name_nondirectory (x)
103 const char *x;
105 char *tmp = (char *) rindex (x, '/');
106 if (DIR_SEPARATOR != '/' && ! tmp)
107 tmp = (char *) rindex (x, DIR_SEPARATOR);
108 if (tmp)
109 return (char *) (tmp + 1);
110 else
111 return (char *) x;
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 #if USE_CPPLIB
120 #include "cpplib.h"
121 extern cpp_reader parse_in;
122 extern cpp_options parse_options;
123 extern unsigned char *yy_cur, *yy_lim;
124 extern enum cpp_token cpp_token;
125 #else
126 FILE *finput;
127 #endif
128 int end_of_file;
130 int linemode;
132 /* Pending language change.
133 Positive is push count, negative is pop count. */
134 int pending_lang_change = 0;
136 /* Wrap the current header file in extern "C". */
137 static int c_header_level = 0;
139 extern int first_token;
140 extern struct obstack token_obstack;
142 /* ??? Don't really know where this goes yet. */
143 #include "input.c"
145 /* Holds translations from TREE_CODEs to operator name strings,
146 i.e., opname_tab[PLUS_EXPR] == "+". */
147 const char **opname_tab;
148 const char **assignop_tab;
150 extern int yychar; /* the lookahead symbol */
151 extern YYSTYPE yylval; /* the semantic value of the */
152 /* lookahead symbol */
154 #if 0
155 YYLTYPE yylloc; /* location data for the lookahead */
156 /* symbol */
157 #endif
160 /* the declaration found for the last IDENTIFIER token read in.
161 yylex must look this up to detect typedefs, which get token type TYPENAME,
162 so it is left around in case the identifier is not a typedef but is
163 used in a context which makes it a reference to a variable. */
164 tree lastiddecl;
166 /* The elements of `ridpointers' are identifier nodes
167 for the reserved type names and storage classes.
168 It is indexed by a RID_... value. */
169 tree ridpointers[(int) RID_MAX];
171 /* We may keep statistics about how long which files took to compile. */
172 static int header_time, body_time;
173 static tree filename_times;
174 static tree this_filename_time;
176 /* Array for holding counts of the numbers of tokens seen. */
177 extern int *token_count;
179 /* When we see a default argument in a method declaration, we snarf it as
180 text using snarf_defarg. When we get up to namespace scope, we then go
181 through and parse all of them using do_pending_defargs. Since yacc
182 parsers are not reentrant, we retain defargs state in these two
183 variables so that subsequent calls to do_pending_defargs can resume
184 where the previous call left off. */
186 static tree defarg_fns;
187 static tree defarg_parm;
189 /* Functions and data structures for #pragma interface.
191 `#pragma implementation' means that the main file being compiled
192 is considered to implement (provide) the classes that appear in
193 its main body. I.e., if this is file "foo.cc", and class `bar'
194 is defined in "foo.cc", then we say that "foo.cc implements bar".
196 All main input files "implement" themselves automagically.
198 `#pragma interface' means that unless this file (of the form "foo.h"
199 is not presently being included by file "foo.cc", the
200 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
201 of the vtables nor any of the inline functions defined in foo.h
202 will ever be output.
204 There are cases when we want to link files such as "defs.h" and
205 "main.cc". In this case, we give "defs.h" a `#pragma interface',
206 and "main.cc" has `#pragma implementation "defs.h"'. */
208 struct impl_files
210 char *filename;
211 struct impl_files *next;
214 static struct impl_files *impl_file_chain;
216 /* The string used to represent the filename of internally generated
217 tree nodes. The variable, which is dynamically allocated, should
218 be used; the macro is only used to initialize it. */
219 static char *internal_filename;
220 #define INTERNAL_FILENAME ("<internal>")
222 /* Return something to represent absolute declarators containing a *.
223 TARGET is the absolute declarator that the * contains.
224 CV_QUALIFIERS is a list of modifiers such as const or volatile
225 to apply to the pointer type, represented as identifiers.
227 We return an INDIRECT_REF whose "contents" are TARGET
228 and whose type is the modifier list. */
230 tree
231 make_pointer_declarator (cv_qualifiers, target)
232 tree cv_qualifiers, target;
234 if (target && TREE_CODE (target) == IDENTIFIER_NODE
235 && ANON_AGGRNAME_P (target))
236 error ("type name expected before `*'");
237 target = build_parse_node (INDIRECT_REF, target);
238 TREE_TYPE (target) = cv_qualifiers;
239 return target;
242 /* Return something to represent absolute declarators containing a &.
243 TARGET is the absolute declarator that the & contains.
244 CV_QUALIFIERS is a list of modifiers such as const or volatile
245 to apply to the reference type, represented as identifiers.
247 We return an ADDR_EXPR whose "contents" are TARGET
248 and whose type is the modifier list. */
250 tree
251 make_reference_declarator (cv_qualifiers, target)
252 tree cv_qualifiers, target;
254 if (target)
256 if (TREE_CODE (target) == ADDR_EXPR)
258 error ("cannot declare references to references");
259 return target;
261 if (TREE_CODE (target) == INDIRECT_REF)
263 error ("cannot declare pointers to references");
264 return target;
266 if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
267 error ("type name expected before `&'");
269 target = build_parse_node (ADDR_EXPR, target);
270 TREE_TYPE (target) = cv_qualifiers;
271 return target;
274 tree
275 make_call_declarator (target, parms, cv_qualifiers, exception_specification)
276 tree target, parms, cv_qualifiers, exception_specification;
278 target = build_parse_node (CALL_EXPR, target,
279 /* Both build_parse_node and
280 decl_tree_cons build on the
281 temp_decl_obstack. */
282 decl_tree_cons (parms, cv_qualifiers, NULL_TREE),
283 /* The third operand is really RTL. We
284 shouldn't put anything there. */
285 NULL_TREE);
286 CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
287 return target;
290 void
291 set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
292 tree call_declarator, cv_qualifiers, exception_specification;
294 CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
295 CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
298 /* Build names and nodes for overloaded operators. */
300 tree ansi_opname[LAST_CPLUS_TREE_CODE];
301 tree ansi_assopname[LAST_CPLUS_TREE_CODE];
303 const char *
304 operator_name_string (name)
305 tree name;
307 char *opname = IDENTIFIER_POINTER (name) + 2;
308 tree *opname_table;
309 int i, assign;
311 /* Works for builtin and user defined types. */
312 if (IDENTIFIER_GLOBAL_VALUE (name)
313 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL)
314 return IDENTIFIER_POINTER (name);
316 if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_')
318 opname += 1;
319 assign = 1;
320 opname_table = ansi_assopname;
322 else
324 assign = 0;
325 opname_table = ansi_opname;
328 for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
330 if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign]
331 && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign])
332 break;
335 if (i == LAST_CPLUS_TREE_CODE)
336 return "<invalid operator>";
338 if (assign)
339 return assignop_tab[i];
340 else
341 return opname_tab[i];
344 int interface_only; /* whether or not current file is only for
345 interface definitions. */
346 int interface_unknown; /* whether or not we know this class
347 to behave according to #pragma interface. */
349 /* lexical analyzer */
351 #undef WCHAR_TYPE_SIZE
352 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
354 /* Number of bytes in a wide character. */
355 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
357 static int maxtoken; /* Current nominal length of token buffer. */
358 char *token_buffer; /* Pointer to token buffer.
359 Actual allocated length is maxtoken + 2. */
361 static int indent_level; /* Number of { minus number of }. */
363 #include "hash.h"
366 /* Nonzero tells yylex to ignore \ in string constants. */
367 static int ignore_escape_flag;
369 static tree
370 get_time_identifier (name)
371 const char *name;
373 tree time_identifier;
374 int len = strlen (name);
375 char *buf = (char *) alloca (len + 6);
376 strcpy (buf, "file ");
377 bcopy (name, buf+5, len);
378 buf[len+5] = '\0';
379 time_identifier = get_identifier (buf);
380 if (TIME_IDENTIFIER_TIME (time_identifier) == NULL_TREE)
382 push_permanent_obstack ();
383 TIME_IDENTIFIER_TIME (time_identifier) = build_int_2 (0, 0);
384 TIME_IDENTIFIER_FILEINFO (time_identifier)
385 = build_int_2 (0, 1);
386 SET_IDENTIFIER_GLOBAL_VALUE (time_identifier, filename_times);
387 filename_times = time_identifier;
388 pop_obstacks ();
390 return time_identifier;
393 static inline int
394 my_get_run_time ()
396 int old_quiet_flag = quiet_flag;
397 int this_time;
398 quiet_flag = 0;
399 this_time = get_run_time ();
400 quiet_flag = old_quiet_flag;
401 return this_time;
404 /* Table indexed by tree code giving a string containing a character
405 classifying the tree code. Possibilities are
406 t, d, s, c, r, <, 1 and 2. See cp/cp-tree.def for details. */
408 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
410 char cplus_tree_code_type[] = {
411 'x',
412 #include "cp-tree.def"
414 #undef DEFTREECODE
416 /* Table indexed by tree code giving number of expression
417 operands beyond the fixed part of the node structure.
418 Not used for types or decls. */
420 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
422 int cplus_tree_code_length[] = {
424 #include "cp-tree.def"
426 #undef DEFTREECODE
428 /* Names of tree components.
429 Used for printing out the tree and error messages. */
430 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
432 const char *cplus_tree_code_name[] = {
433 "@@dummy",
434 #include "cp-tree.def"
436 #undef DEFTREECODE
438 /* toplev.c needs to call these. */
440 void
441 lang_init_options ()
443 #if USE_CPPLIB
444 cpp_reader_init (&parse_in);
445 parse_in.opts = &parse_options;
446 cpp_options_init (&parse_options);
447 parse_options.cplusplus = 1;
448 #endif
450 /* Default exceptions on. */
451 flag_exceptions = 1;
452 /* Mark as "unspecified". */
453 flag_bounds_check = -1;
456 void
457 lang_init ()
459 /* If still "unspecified", make it match -fbounded-pointers. */
460 if (flag_bounds_check < 0)
461 flag_bounds_check = flag_bounded_pointers;
463 /* the beginning of the file is a new line; check for # */
464 /* With luck, we discover the real source file's name from that
465 and put it in input_filename. */
466 put_back (check_newline ());
467 if (flag_gnu_xref) GNU_xref_begin (input_filename);
468 init_repo (input_filename);
471 void
472 lang_finish ()
474 if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount);
477 const char *
478 lang_identify ()
480 return "cplusplus";
483 static void
484 init_filename_times ()
486 this_filename_time = get_time_identifier ("<top level>");
487 if (flag_detailed_statistics)
489 header_time = 0;
490 body_time = my_get_run_time ();
491 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
492 = body_time;
496 /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
497 Stuck this hack in to get the files open correctly; this is called
498 in place of init_parse if we are an unexec'd binary. */
500 #if 0
501 void
502 reinit_lang_specific ()
504 init_filename_times ();
505 reinit_search_statistics ();
507 #endif
509 static int *
510 init_cpp_parse ()
512 #ifdef GATHER_STATISTICS
513 #ifdef REDUCE_LENGTH
514 reduce_count = (int *) xcalloc (sizeof (int), (REDUCE_LENGTH + 1));
515 reduce_count += 1;
516 token_count = (int *) xcalloc (sizeof (int), (TOKEN_LENGTH + 1));
517 token_count += 1;
518 #endif
519 #endif
520 return token_count;
523 char *
524 init_parse (filename)
525 char *filename;
527 extern int flag_no_gnu_keywords;
528 extern int flag_operator_names;
530 int i;
532 #ifdef MULTIBYTE_CHARS
533 /* Change to the native locale for multibyte conversions. */
534 setlocale (LC_CTYPE, "");
535 literal_codeset = getenv ("LANG");
536 #endif
538 #if !USE_CPPLIB
539 /* Open input file. */
540 if (filename == 0 || !strcmp (filename, "-"))
542 finput = stdin;
543 filename = "stdin";
545 else
546 finput = fopen (filename, "r");
547 if (finput == 0)
548 pfatal_with_name (filename);
550 #ifdef IO_BUFFER_SIZE
551 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
552 #endif
553 #else /* !USE_CPPLIB */
554 parse_in.show_column = 1;
555 if (! cpp_start_read (&parse_in, filename))
556 abort ();
558 if (filename == 0 || !strcmp (filename, "-"))
559 filename = "stdin";
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. */
570 init_spew ();
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;
576 init_tree ();
577 init_cplus_expand ();
579 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
580 cplus_tree_code_type,
581 (int)LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
582 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
583 cplus_tree_code_length,
584 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
585 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
586 cplus_tree_code_name,
587 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
589 opname_tab = (const char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
590 memset (opname_tab, 0, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
591 assignop_tab = (const char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
592 memset (assignop_tab, 0, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
594 ansi_opname[0] = get_identifier ("<invalid operator>");
595 for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
597 ansi_opname[i] = ansi_opname[0];
598 ansi_assopname[i] = ansi_opname[0];
601 ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml");
602 IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1;
603 ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR];
604 ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml");
605 IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1;
606 ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR];
607 ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md");
608 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1;
609 ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd");
610 IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1;
611 ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
612 ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
613 ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
614 ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi");
615 IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1;
616 ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR];
617 ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami");
618 IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1;
619 ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR];
620 ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs");
621 IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1;
622 ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars");
623 IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1;
624 ansi_opname[(int) NE_EXPR] = get_identifier ("__ne");
625 IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1;
626 ansi_opname[(int) GT_EXPR] = get_identifier ("__gt");
627 IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1;
628 ansi_opname[(int) GE_EXPR] = get_identifier ("__ge");
629 IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1;
630 ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or");
631 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1;
632 ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor");
633 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1;
634 ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa");
635 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1;
636 ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt");
637 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1;
638 ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp");
639 IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1;
640 ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR];
641 ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as");
642 IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1;
643 ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR];
644 ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm");
645 IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1;
646 ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv");
647 IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1;
648 ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv");
649 IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1;
650 ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
651 ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
652 ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
653 ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
654 ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl");
655 ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
656 ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
657 ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
658 ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
659 IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1;
660 ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl");
661 IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1;
662 ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR];
663 ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR];
664 ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls");
665 IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1;
666 ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als");
667 IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1;
668 ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq");
669 IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1;
670 ansi_opname[(int) LT_EXPR] = get_identifier ("__lt");
671 IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1;
672 ansi_opname[(int) LE_EXPR] = get_identifier ("__le");
673 IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1;
674 ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad");
675 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1;
676 ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad");
677 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1;
678 ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR];
679 ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR];
680 ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er");
681 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1;
682 ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer");
683 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1;
684 ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo");
685 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1;
686 ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co");
687 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1;
688 ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm");
689 IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1;
690 ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR];
691 ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf");
692 IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1;
693 ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm");
694 IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1;
695 ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl");
696 IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1;
697 ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc");
698 IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1;
699 ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw");
700 IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1;
701 ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl");
702 IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1;
703 ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn");
704 IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1;
705 ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd");
706 IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1;
707 ansi_opname[(int) TYPE_EXPR] = get_identifier (OPERATOR_TYPENAME_FORMAT);
708 IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1;
710 /* This is not true: these operators are not defined in ANSI,
711 but we need them anyway. */
712 ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn");
713 IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1;
714 ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx");
715 IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1;
716 ansi_opname[(int) COND_EXPR] = get_identifier ("__cn");
717 IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1;
718 ansi_opname[(int) SIZEOF_EXPR] = get_identifier ("__sz");
719 IDENTIFIER_OPNAME_P (ansi_opname[(int) SIZEOF_EXPR]) = 1;
721 init_method ();
722 init_error ();
723 gcc_obstack_init (&inline_text_obstack);
724 inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
726 internal_filename = ggc_alloc_string (INTERNAL_FILENAME,
727 sizeof (INTERNAL_FILENAME));
729 /* Start it at 0, because check_newline is called at the very beginning
730 and will increment it to 1. */
731 lineno = 0;
732 input_filename = internal_filename;
733 current_function_decl = NULL;
735 maxtoken = 40;
736 token_buffer = (char *) xmalloc (maxtoken + 2);
738 ridpointers[(int) RID_INT] = get_identifier ("int");
739 ridpointers[(int) RID_BOOL] = get_identifier ("bool");
740 ridpointers[(int) RID_CHAR] = get_identifier ("char");
741 ridpointers[(int) RID_VOID] = get_identifier ("void");
742 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
743 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
744 ridpointers[(int) RID_SHORT] = get_identifier ("short");
745 ridpointers[(int) RID_LONG] = get_identifier ("long");
746 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
747 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
748 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
749 ridpointers[(int) RID_CONST] = get_identifier ("const");
750 ridpointers[(int) RID_RESTRICT] = get_identifier ("__restrict");
751 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
752 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
753 ridpointers[(int) RID_STATIC] = get_identifier ("static");
754 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
755 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
756 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
757 ridpointers[(int) RID_COMPLEX] = get_identifier ("__complex");
759 /* C++ extensions. These are probably not correctly named. */
760 ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t");
761 class_type_node = build_int_2 (class_type, 0);
762 TREE_TYPE (class_type_node) = class_type_node;
763 ridpointers[(int) RID_CLASS] = class_type_node;
765 record_type_node = build_int_2 (record_type, 0);
766 TREE_TYPE (record_type_node) = record_type_node;
767 ridpointers[(int) RID_RECORD] = record_type_node;
769 union_type_node = build_int_2 (union_type, 0);
770 TREE_TYPE (union_type_node) = union_type_node;
771 ridpointers[(int) RID_UNION] = union_type_node;
773 enum_type_node = build_int_2 (enum_type, 0);
774 TREE_TYPE (enum_type_node) = enum_type_node;
775 ridpointers[(int) RID_ENUM] = enum_type_node;
777 ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual");
778 ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit");
779 ridpointers[(int) RID_EXPORT] = get_identifier ("export");
780 ridpointers[(int) RID_FRIEND] = get_identifier ("friend");
782 ridpointers[(int) RID_PUBLIC] = get_identifier ("public");
783 ridpointers[(int) RID_PRIVATE] = get_identifier ("private");
784 ridpointers[(int) RID_PROTECTED] = get_identifier ("protected");
785 ridpointers[(int) RID_TEMPLATE] = get_identifier ("template");
786 /* This is for ANSI C++. */
787 ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable");
789 /* Create the built-in __null node. Note that we can't yet call for
790 type_for_size here because integer_type_node and so forth are not
791 set up. Therefore, we don't set the type of these nodes until
792 init_decl_processing. */
793 null_node = build_int_2 (0, 0);
794 ridpointers[RID_NULL] = null_node;
796 opname_tab[(int) COMPONENT_REF] = "->";
797 opname_tab[(int) MEMBER_REF] = "->*";
798 opname_tab[(int) INDIRECT_REF] = "*";
799 opname_tab[(int) ARRAY_REF] = "[]";
800 opname_tab[(int) MODIFY_EXPR] = "=";
801 opname_tab[(int) INIT_EXPR] = "=";
802 opname_tab[(int) NEW_EXPR] = "new";
803 opname_tab[(int) DELETE_EXPR] = "delete";
804 opname_tab[(int) VEC_NEW_EXPR] = "new []";
805 opname_tab[(int) VEC_DELETE_EXPR] = "delete []";
806 opname_tab[(int) COND_EXPR] = "?:";
807 opname_tab[(int) CALL_EXPR] = "()";
808 opname_tab[(int) PLUS_EXPR] = "+";
809 opname_tab[(int) MINUS_EXPR] = "-";
810 opname_tab[(int) MULT_EXPR] = "*";
811 opname_tab[(int) TRUNC_DIV_EXPR] = "/";
812 opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)";
813 opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)";
814 opname_tab[(int) ROUND_DIV_EXPR] = "(round /)";
815 opname_tab[(int) TRUNC_MOD_EXPR] = "%";
816 opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)";
817 opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)";
818 opname_tab[(int) ROUND_MOD_EXPR] = "(round %)";
819 opname_tab[(int) EXACT_DIV_EXPR] = "/";
820 opname_tab[(int) NEGATE_EXPR] = "-";
821 opname_tab[(int) MIN_EXPR] = "<?";
822 opname_tab[(int) MAX_EXPR] = ">?";
823 opname_tab[(int) ABS_EXPR] = "abs";
824 opname_tab[(int) FFS_EXPR] = "ffs";
825 opname_tab[(int) LSHIFT_EXPR] = "<<";
826 opname_tab[(int) RSHIFT_EXPR] = ">>";
827 opname_tab[(int) BIT_IOR_EXPR] = "|";
828 opname_tab[(int) BIT_XOR_EXPR] = "^";
829 opname_tab[(int) BIT_AND_EXPR] = "&";
830 opname_tab[(int) BIT_ANDTC_EXPR] = "&~";
831 opname_tab[(int) BIT_NOT_EXPR] = "~";
832 opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&";
833 opname_tab[(int) TRUTH_ORIF_EXPR] = "||";
834 opname_tab[(int) TRUTH_AND_EXPR] = "strict &&";
835 opname_tab[(int) TRUTH_OR_EXPR] = "strict ||";
836 opname_tab[(int) TRUTH_NOT_EXPR] = "!";
837 opname_tab[(int) LT_EXPR] = "<";
838 opname_tab[(int) LE_EXPR] = "<=";
839 opname_tab[(int) GT_EXPR] = ">";
840 opname_tab[(int) GE_EXPR] = ">=";
841 opname_tab[(int) EQ_EXPR] = "==";
842 opname_tab[(int) NE_EXPR] = "!=";
843 opname_tab[(int) IN_EXPR] = "in";
844 opname_tab[(int) RANGE_EXPR] = "...";
845 opname_tab[(int) CONVERT_EXPR] = "+";
846 opname_tab[(int) ADDR_EXPR] = "&";
847 opname_tab[(int) PREDECREMENT_EXPR] = "--";
848 opname_tab[(int) PREINCREMENT_EXPR] = "++";
849 opname_tab[(int) POSTDECREMENT_EXPR] = "--";
850 opname_tab[(int) POSTINCREMENT_EXPR] = "++";
851 opname_tab[(int) COMPOUND_EXPR] = ",";
853 assignop_tab[(int) NOP_EXPR] = "=";
854 assignop_tab[(int) PLUS_EXPR] = "+=";
855 assignop_tab[(int) CONVERT_EXPR] = "+=";
856 assignop_tab[(int) MINUS_EXPR] = "-=";
857 assignop_tab[(int) NEGATE_EXPR] = "-=";
858 assignop_tab[(int) MULT_EXPR] = "*=";
859 assignop_tab[(int) INDIRECT_REF] = "*=";
860 assignop_tab[(int) TRUNC_DIV_EXPR] = "/=";
861 assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)";
862 assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)";
863 assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)";
864 assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)";
865 assignop_tab[(int) TRUNC_MOD_EXPR] = "%=";
866 assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)";
867 assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)";
868 assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)";
869 assignop_tab[(int) MIN_EXPR] = "<?=";
870 assignop_tab[(int) MAX_EXPR] = ">?=";
871 assignop_tab[(int) LSHIFT_EXPR] = "<<=";
872 assignop_tab[(int) RSHIFT_EXPR] = ">>=";
873 assignop_tab[(int) BIT_IOR_EXPR] = "|=";
874 assignop_tab[(int) BIT_XOR_EXPR] = "^=";
875 assignop_tab[(int) BIT_AND_EXPR] = "&=";
876 assignop_tab[(int) ADDR_EXPR] = "&=";
878 init_filename_times ();
880 /* Some options inhibit certain reserved words.
881 Clear those words out of the hash table so they won't be recognized. */
882 #define UNSET_RESERVED_WORD(STRING) \
883 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
884 if (s) s->name = ""; } while (0)
886 #if 0
887 /* let's parse things, and if they use it, then give them an error. */
888 if (!flag_exceptions)
890 UNSET_RESERVED_WORD ("throw");
891 UNSET_RESERVED_WORD ("try");
892 UNSET_RESERVED_WORD ("catch");
894 #endif
896 if (!flag_rtti || flag_no_gnu_keywords)
898 UNSET_RESERVED_WORD ("classof");
899 UNSET_RESERVED_WORD ("headof");
902 if (flag_no_asm || flag_no_gnu_keywords)
903 UNSET_RESERVED_WORD ("typeof");
904 if (! flag_operator_names)
906 /* These are new ANSI keywords that may break code. */
907 UNSET_RESERVED_WORD ("and");
908 UNSET_RESERVED_WORD ("and_eq");
909 UNSET_RESERVED_WORD ("bitand");
910 UNSET_RESERVED_WORD ("bitor");
911 UNSET_RESERVED_WORD ("compl");
912 UNSET_RESERVED_WORD ("not");
913 UNSET_RESERVED_WORD ("not_eq");
914 UNSET_RESERVED_WORD ("or");
915 UNSET_RESERVED_WORD ("or_eq");
916 UNSET_RESERVED_WORD ("xor");
917 UNSET_RESERVED_WORD ("xor_eq");
920 token_count = init_cpp_parse ();
921 interface_unknown = 1;
923 ggc_add_tree_root (ansi_opname, LAST_CPLUS_TREE_CODE);
924 ggc_add_tree_root (ansi_assopname, LAST_CPLUS_TREE_CODE);
925 ggc_add_string_root (&internal_filename, 1);
926 ggc_add_tree_root (ridpointers, RID_MAX);
927 ggc_add_tree_root (&defarg_fns, 1);
928 ggc_add_tree_root (&defarg_parm, 1);
929 ggc_add_tree_root (&this_filename_time, 1);
930 ggc_add_tree_root (&filename_times, 1);
931 ggc_add_root (&impl_file_chain, 1, sizeof (impl_file_chain),
932 mark_impl_file_chain);
933 return filename;
936 void
937 finish_parse ()
939 #if USE_CPPLIB
940 cpp_finish (&parse_in);
941 errorcount += parse_in.errors;
942 #else
943 fclose (finput);
944 #endif
947 void
948 reinit_parse_for_function ()
950 current_base_init_list = NULL_TREE;
951 current_member_init_list = NULL_TREE;
954 inline void
955 yyprint (file, yychar, yylval)
956 FILE *file;
957 int yychar;
958 YYSTYPE yylval;
960 tree t;
961 switch (yychar)
963 case IDENTIFIER:
964 case TYPENAME:
965 case TYPESPEC:
966 case PTYPENAME:
967 case PFUNCNAME:
968 case IDENTIFIER_DEFN:
969 case TYPENAME_DEFN:
970 case PTYPENAME_DEFN:
971 case SCSPEC:
972 case PRE_PARSED_CLASS_DECL:
973 t = yylval.ttype;
974 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL)
976 fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t)));
977 break;
979 my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
980 if (IDENTIFIER_POINTER (t))
981 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
982 break;
984 case AGGR:
985 if (yylval.ttype == class_type_node)
986 fprintf (file, " `class'");
987 else if (yylval.ttype == record_type_node)
988 fprintf (file, " `struct'");
989 else if (yylval.ttype == union_type_node)
990 fprintf (file, " `union'");
991 else if (yylval.ttype == enum_type_node)
992 fprintf (file, " `enum'");
993 else
994 my_friendly_abort (80);
995 break;
997 case CONSTANT:
998 t = yylval.ttype;
999 if (TREE_CODE (t) == INTEGER_CST)
1000 fprintf (file,
1001 #if HOST_BITS_PER_WIDE_INT == 64
1002 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1003 " 0x%x%016x",
1004 #else
1005 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1006 " 0x%lx%016lx",
1007 #else
1008 " 0x%llx%016llx",
1009 #endif
1010 #endif
1011 #else
1012 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
1013 " 0x%lx%08lx",
1014 #else
1015 " 0x%x%08x",
1016 #endif
1017 #endif
1018 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
1019 break;
1023 #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
1024 static int *reduce_count;
1025 #endif
1027 int *token_count;
1029 #if 0
1030 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
1031 #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
1032 #endif
1034 #ifdef GATHER_STATISTICS
1035 #ifdef REDUCE_LENGTH
1036 void
1037 yyhook (yyn)
1038 int yyn;
1040 reduce_count[yyn] += 1;
1043 static int
1044 reduce_cmp (p, q)
1045 int *p, *q;
1047 return reduce_count[*q] - reduce_count[*p];
1050 static int
1051 token_cmp (p, q)
1052 int *p, *q;
1054 return token_count[*q] - token_count[*p];
1056 #endif
1057 #endif
1059 void
1060 print_parse_statistics ()
1062 #ifdef GATHER_STATISTICS
1063 #ifdef REDUCE_LENGTH
1064 #if YYDEBUG != 0
1065 int i;
1066 int maxlen = REDUCE_LENGTH;
1067 unsigned *sorted;
1069 if (reduce_count[-1] == 0)
1070 return;
1072 if (TOKEN_LENGTH > REDUCE_LENGTH)
1073 maxlen = TOKEN_LENGTH;
1074 sorted = (unsigned *) alloca (sizeof (int) * maxlen);
1076 for (i = 0; i < TOKEN_LENGTH; i++)
1077 sorted[i] = i;
1078 qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
1079 for (i = 0; i < TOKEN_LENGTH; i++)
1081 int idx = sorted[i];
1082 if (token_count[idx] == 0)
1083 break;
1084 if (token_count[idx] < token_count[-1])
1085 break;
1086 fprintf (stderr, "token %d, `%s', count = %d\n",
1087 idx, yytname[YYTRANSLATE (idx)], token_count[idx]);
1089 fprintf (stderr, "\n");
1090 for (i = 0; i < REDUCE_LENGTH; i++)
1091 sorted[i] = i;
1092 qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
1093 for (i = 0; i < REDUCE_LENGTH; i++)
1095 int idx = sorted[i];
1096 if (reduce_count[idx] == 0)
1097 break;
1098 if (reduce_count[idx] < reduce_count[-1])
1099 break;
1100 fprintf (stderr, "rule %d, line %d, count = %d\n",
1101 idx, yyrline[idx], reduce_count[idx]);
1103 fprintf (stderr, "\n");
1104 #endif
1105 #endif
1106 #endif
1109 /* Sets the value of the 'yydebug' variable to VALUE.
1110 This is a function so we don't have to have YYDEBUG defined
1111 in order to build the compiler. */
1113 void
1114 set_yydebug (value)
1115 int value;
1117 #if YYDEBUG != 0
1118 extern int yydebug;
1119 yydebug = value;
1120 #else
1121 warning ("YYDEBUG not defined.");
1122 #endif
1126 /* Mark ARG (which is really a struct impl_files **) for GC. */
1128 static void
1129 mark_impl_file_chain (arg)
1130 void *arg;
1132 struct impl_files *ifs;
1134 ifs = *(struct impl_files **) arg;
1135 while (ifs)
1137 ggc_mark_string (ifs->filename);
1138 ifs = ifs->next;
1142 /* Helper function to load global variables with interface
1143 information. */
1145 void
1146 extract_interface_info ()
1148 tree fileinfo = 0;
1150 if (flag_alt_external_templates)
1152 struct tinst_level *til = tinst_for_decl ();
1154 if (til)
1155 fileinfo = get_time_identifier (til->file);
1157 if (!fileinfo)
1158 fileinfo = get_time_identifier (input_filename);
1159 fileinfo = TIME_IDENTIFIER_FILEINFO (fileinfo);
1160 interface_only = TREE_INT_CST_LOW (fileinfo);
1161 interface_unknown = TREE_INT_CST_HIGH (fileinfo);
1164 /* Return nonzero if S is not considered part of an
1165 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
1167 static int
1168 interface_strcmp (s)
1169 const char *s;
1171 /* Set the interface/implementation bits for this scope. */
1172 struct impl_files *ifiles;
1173 const char *s1;
1175 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
1177 const char *t1 = ifiles->filename;
1178 s1 = s;
1180 if (*s1 != *t1 || *s1 == 0)
1181 continue;
1183 while (*s1 == *t1 && *s1 != 0)
1184 s1++, t1++;
1186 /* A match. */
1187 if (*s1 == *t1)
1188 return 0;
1190 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
1191 if (index (s1, '.') || index (t1, '.'))
1192 continue;
1194 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
1195 continue;
1197 /* A match. */
1198 return 0;
1201 /* No matches. */
1202 return 1;
1205 static void
1206 cp_pragma_interface (main_filename)
1207 char *main_filename;
1209 tree fileinfo
1210 = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename));
1212 if (impl_file_chain == 0)
1214 /* If this is zero at this point, then we are
1215 auto-implementing. */
1216 if (main_input_filename == 0)
1217 main_input_filename = input_filename;
1219 #ifdef AUTO_IMPLEMENT
1220 filename = file_name_nondirectory (main_input_filename);
1221 fi = get_time_identifier (filename);
1222 fi = TIME_IDENTIFIER_FILEINFO (fi);
1223 TREE_INT_CST_LOW (fi) = 0;
1224 TREE_INT_CST_HIGH (fi) = 1;
1225 /* Get default. */
1226 impl_file_chain
1227 = (struct impl_files *) xmalloc (sizeof (struct impl_files));
1228 impl_file_chain->filename = ggc_alloc_string (filename, -1);
1229 impl_file_chain->next = 0;
1230 #endif
1233 interface_only = interface_strcmp (main_filename);
1234 #ifdef MULTIPLE_SYMBOL_SPACES
1235 if (! interface_only)
1236 interface_unknown = 0;
1237 #else /* MULTIPLE_SYMBOL_SPACES */
1238 interface_unknown = 0;
1239 #endif /* MULTIPLE_SYMBOL_SPACES */
1240 TREE_INT_CST_LOW (fileinfo) = interface_only;
1241 TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
1244 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
1245 We used to only allow this at toplevel, but that restriction was buggy
1246 in older compilers and it seems reasonable to allow it in the headers
1247 themselves, too. It only needs to precede the matching #p interface.
1249 We don't touch interface_only or interface_unknown; the user must specify
1250 a matching #p interface for this to have any effect. */
1252 static void
1253 cp_pragma_implementation (main_filename)
1254 char *main_filename;
1256 struct impl_files *ifiles = impl_file_chain;
1257 for (; ifiles; ifiles = ifiles->next)
1259 if (! strcmp (ifiles->filename, main_filename))
1260 break;
1262 if (ifiles == 0)
1264 ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files));
1265 ifiles->filename = ggc_alloc_string (main_filename, -1);
1266 ifiles->next = impl_file_chain;
1267 impl_file_chain = ifiles;
1271 /* Set up the state required to correctly handle the definition of the
1272 inline function whose preparsed state has been saved in PI. */
1274 static void
1275 begin_definition_of_inclass_inline (pi)
1276 struct pending_inline* pi;
1278 tree context;
1280 if (!pi->fndecl)
1281 return;
1283 /* If this is an inline function in a local class, we must make sure
1284 that we save all pertinent information about the function
1285 surrounding the local class. */
1286 context = hack_decl_function_context (pi->fndecl);
1287 if (context)
1288 push_function_context_to (context);
1290 feed_input (pi->buf, pi->len, pi->filename, pi->lineno);
1291 yychar = PRE_PARSED_FUNCTION_DECL;
1292 yylval.pi = pi;
1293 /* Pass back a handle to the rest of the inline functions, so that they
1294 can be processed later. */
1295 DECL_PENDING_INLINE_INFO (pi->fndecl) = 0;
1296 DECL_PENDING_INLINE_P (pi->fndecl) = 0;
1297 interface_unknown = pi->interface == 1;
1298 interface_only = pi->interface == 0;
1301 /* Called from the top level: if there are any pending inlines to
1302 do, set up to process them now. This function sets up the first function
1303 to be parsed; after it has been, the rule for fndef in parse.y will
1304 call process_next_inline to start working on the next one. */
1306 void
1307 do_pending_inlines ()
1309 struct pending_inline *t;
1311 /* Oops, we're still dealing with the last batch. */
1312 if (yychar == PRE_PARSED_FUNCTION_DECL)
1313 return;
1315 /* Reverse the pending inline functions, since
1316 they were cons'd instead of appended. */
1318 struct pending_inline *prev = 0, *tail;
1319 t = pending_inlines;
1320 pending_inlines = 0;
1322 for (; t; t = tail)
1324 tail = t->next;
1325 t->next = prev;
1326 t->deja_vu = 1;
1327 prev = t;
1329 t = prev;
1332 if (t == 0)
1333 return;
1335 /* Now start processing the first inline function. */
1336 begin_definition_of_inclass_inline (t);
1339 /* Called from the fndecl rule in the parser when the function just parsed
1340 was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1341 do_pending_inlines). */
1343 void
1344 process_next_inline (i)
1345 struct pending_inline *i;
1347 tree context;
1348 context = hack_decl_function_context (i->fndecl);
1349 if (context)
1350 pop_function_context_from (context);
1351 i = i->next;
1352 if (yychar == YYEMPTY)
1353 yychar = yylex ();
1354 if (yychar != END_OF_SAVED_INPUT)
1356 error ("parse error at end of saved function text");
1358 /* restore_pending_input will abort unless yychar is either
1359 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1360 hosed, feed back YYEMPTY. */
1362 yychar = YYEMPTY;
1363 end_input ();
1364 if (i)
1365 begin_definition_of_inclass_inline (i);
1366 else
1367 extract_interface_info ();
1370 /* Since inline methods can refer to text which has not yet been seen,
1371 we store the text of the method in a structure which is placed in the
1372 DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1373 After parsing the body of the class definition, the FUNCTION_DECL's are
1374 scanned to see which ones have this field set. Those are then digested
1375 one at a time.
1377 This function's FUNCTION_DECL will have a bit set in its common so
1378 that we know to watch out for it. */
1380 static void
1381 consume_string (this_obstack, matching_char)
1382 register struct obstack *this_obstack;
1383 int matching_char;
1385 register int c;
1386 int starting_lineno;
1388 #if USE_CPPLIB
1389 if (cpp_token == CPP_STRING)
1391 /* The C preprocessor will warn about newlines in strings. */
1392 obstack_grow (this_obstack, yy_cur, (yy_lim - yy_cur));
1393 yy_cur = yy_lim;
1394 lineno = parse_in.lineno;
1395 return;
1397 #endif
1399 starting_lineno = lineno;
1402 c = getch ();
1403 if (c == EOF)
1405 int save_lineno = lineno;
1406 lineno = starting_lineno;
1407 if (matching_char == '"')
1408 error ("end of file encountered inside string constant");
1409 else
1410 error ("end of file encountered inside character constant");
1411 lineno = save_lineno;
1412 return;
1414 if (c == '\\')
1416 obstack_1grow (this_obstack, c);
1417 c = getch ();
1418 obstack_1grow (this_obstack, c);
1420 /* Make sure we continue the loop */
1421 c = 0;
1422 continue;
1424 if (c == '\n')
1426 if (pedantic)
1427 pedwarn ("ANSI C++ forbids newline in string constant");
1428 lineno++;
1430 obstack_1grow (this_obstack, c);
1432 while (c != matching_char);
1435 struct pending_input {
1436 int yychar, eof;
1437 YYSTYPE yylval;
1438 struct obstack token_obstack;
1439 int first_token;
1442 struct pending_input *
1443 save_pending_input ()
1445 struct pending_input *p;
1446 p = (struct pending_input *) xmalloc (sizeof (struct pending_input));
1447 p->yychar = yychar;
1448 p->yylval = yylval;
1449 p->eof = end_of_file;
1450 yychar = YYEMPTY;
1451 p->first_token = first_token;
1452 p->token_obstack = token_obstack;
1454 first_token = 0;
1455 gcc_obstack_init (&token_obstack);
1456 end_of_file = 0;
1457 return p;
1460 void
1461 restore_pending_input (p)
1462 struct pending_input *p;
1464 my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230);
1465 yychar = p->yychar;
1466 yylval = p->yylval;
1467 first_token = p->first_token;
1468 obstack_free (&token_obstack, (char *) 0);
1469 token_obstack = p->token_obstack;
1470 end_of_file = p->eof;
1471 free (p);
1474 /* Unget character CH from the input stream.
1475 If RESCAN is non-zero, then we want to `see' this
1476 character as the next input token. */
1478 void
1479 yyungetc (ch, rescan)
1480 int ch;
1481 int rescan;
1483 /* Unget a character from the input stream. */
1484 if (yychar == YYEMPTY || rescan == 0)
1486 /* If we're putting back a brace, undo the change in indent_level
1487 from the first time we saw it. */
1488 if (ch == '{')
1489 indent_level--;
1490 else if (ch == '}')
1491 indent_level++;
1493 put_back (ch);
1495 else
1497 yychar = ch;
1501 void
1502 clear_inline_text_obstack ()
1504 obstack_free (&inline_text_obstack, inline_text_firstobj);
1507 /* This function stores away the text for an inline function that should
1508 be processed later. It decides how much later, and may need to move
1509 the info between obstacks; therefore, the caller should not refer to
1510 the T parameter after calling this function. */
1512 static void
1513 store_pending_inline (decl, t)
1514 tree decl;
1515 struct pending_inline *t;
1517 t->fndecl = decl;
1518 DECL_PENDING_INLINE_INFO (decl) = t;
1519 DECL_PENDING_INLINE_P (decl) = 1;
1521 /* Because we use obstacks, we must process these in precise order. */
1522 t->next = pending_inlines;
1523 pending_inlines = t;
1526 void
1527 reinit_parse_for_method (yychar, decl)
1528 int yychar;
1529 tree decl;
1531 int len;
1532 int starting_lineno = lineno;
1533 char *starting_filename = input_filename;
1535 reinit_parse_for_block (yychar, &inline_text_obstack);
1537 len = obstack_object_size (&inline_text_obstack);
1538 if (decl == void_type_node
1539 || (current_class_type && TYPE_REDEFINED (current_class_type)))
1541 /* Happens when we get two declarations of the same
1542 function in the same scope. */
1543 char *buf = obstack_finish (&inline_text_obstack);
1544 obstack_free (&inline_text_obstack, buf);
1545 return;
1547 else
1549 struct pending_inline *t;
1550 char *buf = obstack_finish (&inline_text_obstack);
1552 t = (struct pending_inline *) obstack_alloc (&inline_text_obstack,
1553 sizeof (struct pending_inline));
1554 t->lineno = starting_lineno;
1555 t->filename = starting_filename;
1556 t->token = YYEMPTY;
1557 t->token_value = 0;
1558 t->buf = buf;
1559 t->len = len;
1560 t->deja_vu = 0;
1561 #if 0
1562 if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
1563 warn_if_unknown_interface (decl);
1564 #endif
1565 t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2));
1566 store_pending_inline (decl, t);
1570 /* Consume a block -- actually, a method beginning
1571 with `:' or `{' -- and save it away on the specified obstack. */
1573 void
1574 reinit_parse_for_block (pyychar, obstackp)
1575 int pyychar;
1576 struct obstack *obstackp;
1578 register int c;
1579 int blev = 1;
1580 int starting_lineno = lineno;
1581 char *starting_filename = input_filename;
1582 int len;
1583 int look_for_semicolon = 0;
1584 int look_for_lbrac = 0;
1586 if (pyychar == '{')
1588 obstack_1grow (obstackp, '{');
1589 /* We incremented indent_level in yylex; undo that. */
1590 indent_level--;
1592 else if (pyychar == '=')
1593 look_for_semicolon = 1;
1594 else if (pyychar == ':')
1596 obstack_1grow (obstackp, pyychar);
1597 /* Add a space so we don't get confused by ': ::A(20)'. */
1598 obstack_1grow (obstackp, ' ');
1599 look_for_lbrac = 1;
1600 blev = 0;
1602 else if (pyychar == RETURN_KEYWORD)
1604 obstack_grow (obstackp, "return", 6);
1605 look_for_lbrac = 1;
1606 blev = 0;
1608 else if (pyychar == TRY)
1610 obstack_grow (obstackp, "try", 3);
1611 look_for_lbrac = 1;
1612 blev = 0;
1614 else
1616 yyerror ("parse error in method specification");
1617 obstack_1grow (obstackp, '{');
1620 c = getch ();
1622 while (c != EOF)
1624 int this_lineno = lineno;
1626 c = skip_white_space (c);
1628 /* Don't lose our cool if there are lots of comments. */
1629 if (lineno == this_lineno + 1)
1630 obstack_1grow (obstackp, '\n');
1631 else if (lineno == this_lineno)
1633 else if (lineno - this_lineno < 10)
1635 int i;
1636 for (i = lineno - this_lineno; i > 0; i--)
1637 obstack_1grow (obstackp, '\n');
1639 else
1641 char buf[16];
1642 sprintf (buf, "\n# %d \"", lineno);
1643 len = strlen (buf);
1644 obstack_grow (obstackp, buf, len);
1646 len = strlen (input_filename);
1647 obstack_grow (obstackp, input_filename, len);
1648 obstack_1grow (obstackp, '\"');
1649 obstack_1grow (obstackp, '\n');
1652 while (c > ' ') /* ASCII dependent... */
1654 obstack_1grow (obstackp, c);
1655 if (c == '{')
1657 look_for_lbrac = 0;
1658 blev++;
1660 else if (c == '}')
1662 blev--;
1663 if (blev == 0 && !look_for_semicolon)
1665 if (pyychar == TRY)
1667 if (peekyylex () == CATCH)
1669 yylex ();
1670 obstack_grow (obstackp, " catch ", 7);
1671 look_for_lbrac = 1;
1673 else
1675 yychar = '{';
1676 goto done;
1679 else
1681 goto done;
1685 else if (c == '\\')
1687 /* Don't act on the next character...e.g, doing an escaped
1688 double-quote. */
1689 c = getch ();
1690 if (c == EOF)
1692 error_with_file_and_line (starting_filename,
1693 starting_lineno,
1694 "end of file read inside definition");
1695 goto done;
1697 obstack_1grow (obstackp, c);
1699 else if (c == '\"')
1700 consume_string (obstackp, c);
1701 else if (c == '\'')
1702 consume_string (obstackp, c);
1703 else if (c == ';')
1705 if (look_for_lbrac)
1707 error ("function body for constructor missing");
1708 obstack_1grow (obstackp, '{');
1709 obstack_1grow (obstackp, '}');
1710 len += 2;
1711 goto done;
1713 else if (look_for_semicolon && blev == 0)
1714 goto done;
1716 c = getch ();
1719 if (c == EOF)
1721 error_with_file_and_line (starting_filename,
1722 starting_lineno,
1723 "end of file read inside definition");
1724 goto done;
1726 else if (c != '\n')
1728 obstack_1grow (obstackp, c);
1729 c = getch ();
1732 done:
1733 obstack_1grow (obstackp, '\0');
1736 /* Consume a no-commas expression -- actually, a default argument -- and
1737 save it away on the specified obstack. */
1739 static void
1740 reinit_parse_for_expr (obstackp)
1741 struct obstack *obstackp;
1743 register int c;
1744 int starting_lineno = lineno;
1745 char *starting_filename = input_filename;
1746 int len;
1747 int plev = 0;
1749 c = getch ();
1751 while (c != EOF)
1753 int this_lineno = lineno;
1755 c = skip_white_space (c);
1757 /* Don't lose our cool if there are lots of comments. */
1758 if (lineno == this_lineno + 1)
1759 obstack_1grow (obstackp, '\n');
1760 else if (lineno == this_lineno)
1762 else if (lineno - this_lineno < 10)
1764 int i;
1765 for (i = lineno - this_lineno; i > 0; --i)
1766 obstack_1grow (obstackp, '\n');
1768 else
1770 char buf[16];
1771 sprintf (buf, "\n# %d \"", lineno);
1772 len = strlen (buf);
1773 obstack_grow (obstackp, buf, len);
1775 len = strlen (input_filename);
1776 obstack_grow (obstackp, input_filename, len);
1777 obstack_1grow (obstackp, '\"');
1778 obstack_1grow (obstackp, '\n');
1781 while (c > ' ') /* ASCII dependent... */
1783 if (plev <= 0 && (c == ')' || c == ','))
1785 put_back (c);
1786 goto done;
1788 obstack_1grow (obstackp, c);
1789 if (c == '(' || c == '[')
1790 ++plev;
1791 else if (c == ']' || c == ')')
1792 --plev;
1793 else if (c == '\\')
1795 /* Don't act on the next character...e.g, doing an escaped
1796 double-quote. */
1797 c = getch ();
1798 if (c == EOF)
1800 error_with_file_and_line (starting_filename,
1801 starting_lineno,
1802 "end of file read inside definition");
1803 goto done;
1805 obstack_1grow (obstackp, c);
1807 else if (c == '\"')
1808 consume_string (obstackp, c);
1809 else if (c == '\'')
1810 consume_string (obstackp, c);
1811 c = getch ();
1814 if (c == EOF)
1816 error_with_file_and_line (starting_filename,
1817 starting_lineno,
1818 "end of file read inside definition");
1819 goto done;
1821 else if (c != '\n')
1823 obstack_1grow (obstackp, c);
1824 c = getch ();
1827 done:
1828 obstack_1grow (obstackp, '\0');
1831 int do_snarf_defarg;
1833 /* Decide whether the default argument we are about to see should be
1834 gobbled up as text for later parsing. */
1836 void
1837 maybe_snarf_defarg ()
1839 if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
1840 do_snarf_defarg = 1;
1843 tree
1844 snarf_defarg ()
1846 int len;
1847 char *buf;
1848 tree arg;
1850 reinit_parse_for_expr (&inline_text_obstack);
1851 len = obstack_object_size (&inline_text_obstack);
1852 buf = obstack_finish (&inline_text_obstack);
1854 push_obstacks (&inline_text_obstack, &inline_text_obstack);
1855 arg = make_node (DEFAULT_ARG);
1856 DEFARG_LENGTH (arg) = len - 1;
1857 DEFARG_POINTER (arg) = buf;
1858 pop_obstacks ();
1860 return arg;
1863 /* Called from grokfndecl to note a function decl with unparsed default
1864 arguments for later processing. Also called from grokdeclarator
1865 for function types with unparsed defargs; the call from grokfndecl
1866 will always come second, so we can overwrite the entry from the type. */
1868 void
1869 add_defarg_fn (decl)
1870 tree decl;
1872 if (TREE_CODE (decl) == FUNCTION_DECL)
1873 TREE_VALUE (defarg_fns) = decl;
1874 else
1876 push_obstacks (&inline_text_obstack, &inline_text_obstack);
1877 defarg_fns = tree_cons (current_class_type, decl, defarg_fns);
1878 pop_obstacks ();
1882 /* Helper for do_pending_defargs. Starts the parsing of a default arg. */
1884 static void
1885 feed_defarg (f, p)
1886 tree f, p;
1888 tree d = TREE_PURPOSE (p);
1889 char *file;
1890 int line;
1891 if (TREE_CODE (f) == FUNCTION_DECL)
1893 line = DECL_SOURCE_LINE (f);
1894 file = DECL_SOURCE_FILE (f);
1896 else
1898 line = lineno;
1899 file = input_filename;
1902 feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d), file, line);
1903 yychar = DEFARG_MARKER;
1904 yylval.ttype = p;
1907 /* Helper for do_pending_defargs. Ends the parsing of a default arg. */
1909 static void
1910 finish_defarg ()
1912 if (yychar == YYEMPTY)
1913 yychar = yylex ();
1914 if (yychar != END_OF_SAVED_INPUT)
1916 error ("parse error at end of saved function text");
1918 /* restore_pending_input will abort unless yychar is either
1919 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1920 hosed, feed back YYEMPTY. */
1922 yychar = YYEMPTY;
1923 end_input ();
1926 /* Main function for deferred parsing of default arguments. Called from
1927 the parser. */
1929 void
1930 do_pending_defargs ()
1932 if (defarg_parm)
1933 finish_defarg ();
1935 for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns))
1937 tree defarg_fn = TREE_VALUE (defarg_fns);
1938 if (defarg_parm == NULL_TREE)
1940 push_nested_class (TREE_PURPOSE (defarg_fns), 1);
1941 pushlevel (0);
1942 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1943 maybe_begin_member_template_processing (defarg_fn);
1945 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1947 #if 0
1948 tree p;
1949 for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p))
1950 pushdecl (copy_node (p));
1951 #endif
1952 defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn));
1954 else
1955 defarg_parm = TYPE_ARG_TYPES (defarg_fn);
1957 else
1958 defarg_parm = TREE_CHAIN (defarg_parm);
1960 for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm))
1961 if (TREE_PURPOSE (defarg_parm)
1962 && TREE_CODE (TREE_PURPOSE (defarg_parm)) == DEFAULT_ARG)
1964 feed_defarg (defarg_fn, defarg_parm);
1966 /* Return to the parser, which will process this defarg
1967 and call us again. */
1968 return;
1971 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1973 maybe_end_member_template_processing ();
1974 check_default_args (defarg_fn);
1977 poplevel (0, 0, 0);
1978 pop_nested_class ();
1982 /* Build a default function named NAME for type TYPE.
1983 KIND says what to build.
1985 When KIND == 0, build default destructor.
1986 When KIND == 1, build virtual destructor.
1987 When KIND == 2, build default constructor.
1988 When KIND == 3, build default X(const X&) constructor.
1989 When KIND == 4, build default X(X&) constructor.
1990 When KIND == 5, build default operator = (const X&).
1991 When KIND == 6, build default operator = (X&). */
1993 tree
1994 cons_up_default_function (type, full_name, kind)
1995 tree type, full_name;
1996 int kind;
1998 tree declspecs = NULL_TREE;
1999 tree fn, args = NULL_TREE;
2000 tree argtype;
2001 int retref = 0;
2002 tree name = constructor_name (full_name);
2004 switch (kind)
2006 /* Destructors. */
2007 case 1:
2008 declspecs = build_decl_list (NULL_TREE, ridpointers [(int) RID_VIRTUAL]);
2009 /* Fall through... */
2010 case 0:
2011 name = build_parse_node (BIT_NOT_EXPR, name);
2012 args = void_list_node;
2013 break;
2015 case 2:
2016 /* Default constructor. */
2017 args = void_list_node;
2018 break;
2020 case 3:
2021 type = build_qualified_type (type, TYPE_QUAL_CONST);
2022 /* Fall through... */
2023 case 4:
2024 /* According to ARM $12.8, the default copy ctor will be declared, but
2025 not defined, unless it's needed. */
2026 argtype = build_reference_type (type);
2027 args = tree_cons (NULL_TREE,
2028 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
2029 get_identifier ("_ctor_arg")),
2030 void_list_node);
2031 break;
2033 case 5:
2034 case 6:
2035 retref = 1;
2036 declspecs = build_decl_list (NULL_TREE, type);
2038 if (kind == 5)
2039 type = build_qualified_type (type, TYPE_QUAL_CONST);
2041 name = ansi_opname [(int) MODIFY_EXPR];
2043 argtype = build_reference_type (type);
2044 args = tree_cons (NULL_TREE,
2045 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
2046 get_identifier ("_ctor_arg")),
2047 void_list_node);
2048 break;
2050 default:
2051 my_friendly_abort (59);
2054 declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE],
2055 declspecs);
2057 TREE_PARMLIST (args) = 1;
2060 tree declarator = make_call_declarator (name, args, NULL_TREE, NULL_TREE);
2061 if (retref)
2062 declarator = build_parse_node (ADDR_EXPR, declarator);
2064 fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
2067 if (fn == void_type_node)
2068 return fn;
2070 if (kind > 2)
2071 SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn)));
2073 #if 0
2074 if (processing_template_defn)
2076 SET_DECL_IMPLICIT_INSTANTIATION (fn);
2077 repo_template_used (fn);
2079 #endif
2081 #if 0
2082 if (CLASSTYPE_INTERFACE_KNOWN (type))
2084 DECL_INTERFACE_KNOWN (fn) = 1;
2085 DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type)
2086 && flag_implement_inlines);
2088 else
2089 #endif
2090 DECL_NOT_REALLY_EXTERN (fn) = 1;
2092 mark_inline_for_output (fn);
2094 #ifdef DEBUG_DEFAULT_FUNCTIONS
2095 { char *fn_type = NULL;
2096 tree t = name;
2097 switch (kind)
2099 case 0: fn_type = "default destructor"; break;
2100 case 1: fn_type = "virtual destructor"; break;
2101 case 2: fn_type = "default constructor"; break;
2102 case 3: fn_type = "default X(const X&)"; break;
2103 case 4: fn_type = "default X(X&)"; break;
2105 if (fn_type)
2107 if (TREE_CODE (name) == BIT_NOT_EXPR)
2108 t = TREE_OPERAND (name, 0);
2109 fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type,
2110 IDENTIFIER_POINTER (t), func_buf);
2113 #endif /* DEBUG_DEFAULT_FUNCTIONS */
2115 /* Show that this function was generated by the compiler. */
2116 SET_DECL_ARTIFICIAL (fn);
2118 return fn;
2121 /* Heuristic to tell whether the user is missing a semicolon
2122 after a struct or enum declaration. Emit an error message
2123 if we know the user has blown it. */
2125 void
2126 check_for_missing_semicolon (type)
2127 tree type;
2129 if (yychar < 0)
2130 yychar = yylex ();
2132 if ((yychar > 255
2133 && yychar != SCSPEC
2134 && yychar != IDENTIFIER
2135 && yychar != TYPENAME
2136 && yychar != CV_QUALIFIER
2137 && yychar != SELFNAME)
2138 || end_of_file)
2140 if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
2141 error ("semicolon missing after %s declaration",
2142 TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
2143 else
2144 cp_error ("semicolon missing after declaration of `%T'", type);
2145 shadow_tag (build_tree_list (0, type));
2147 /* Could probably also hack cases where class { ... } f (); appears. */
2148 clear_anon_tags ();
2151 void
2152 note_got_semicolon (type)
2153 tree type;
2155 if (TREE_CODE_CLASS (TREE_CODE (type)) != 't')
2156 my_friendly_abort (60);
2157 if (CLASS_TYPE_P (type))
2158 CLASSTYPE_GOT_SEMICOLON (type) = 1;
2161 void
2162 note_list_got_semicolon (declspecs)
2163 tree declspecs;
2165 tree link;
2167 for (link = declspecs; link; link = TREE_CHAIN (link))
2169 tree type = TREE_VALUE (link);
2170 if (TREE_CODE_CLASS (TREE_CODE (type)) == 't')
2171 note_got_semicolon (type);
2173 clear_anon_tags ();
2176 /* Iff C is a carriage return, warn about it - if appropriate -
2177 and return nonzero. */
2178 static int
2179 whitespace_cr (c)
2180 int c;
2182 static int newline_warning = 0;
2184 if (c == '\r')
2186 /* ANSI C says the effects of a carriage return in a source file
2187 are undefined. */
2188 if (pedantic && !newline_warning)
2190 warning ("carriage return in source file");
2191 warning ("(we only warn about the first carriage return)");
2192 newline_warning = 1;
2194 return 1;
2196 return 0;
2199 /* If C is not whitespace, return C.
2200 Otherwise skip whitespace and return first nonwhite char read. */
2202 static int
2203 skip_white_space (c)
2204 register int c;
2206 for (;;)
2208 switch (c)
2210 /* We don't recognize comments here, because
2211 cpp output can include / and * consecutively as operators.
2212 Also, there's no need, since cpp removes all comments. */
2214 case '\n':
2215 if (linemode)
2217 put_back (c);
2218 return EOF;
2220 c = check_newline ();
2221 break;
2223 case ' ':
2224 case '\t':
2225 case '\f':
2226 case '\v':
2227 case '\b':
2228 #if USE_CPPLIB
2229 /* While processing a # directive we don't get CPP_HSPACE
2230 tokens, so we also need to handle whitespace the normal way. */
2231 if (cpp_token == CPP_HSPACE)
2232 c = yy_get_token ();
2233 else
2234 #endif
2235 c = getch ();
2236 break;
2238 case '\r':
2239 whitespace_cr (c);
2240 c = getch ();
2241 break;
2243 case '\\':
2244 c = getch ();
2245 if (c == '\n')
2246 lineno++;
2247 else
2248 error ("stray '\\' in program");
2249 c = getch ();
2250 break;
2252 default:
2253 return (c);
2258 /* Make the token buffer longer, preserving the data in it.
2259 P should point to just beyond the last valid character in the old buffer.
2260 The value we return is a pointer to the new buffer
2261 at a place corresponding to P. */
2263 static void
2264 extend_token_buffer_to (size)
2265 int size;
2268 maxtoken = maxtoken * 2 + 10;
2269 while (maxtoken < size);
2270 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
2273 static char *
2274 extend_token_buffer (p)
2275 const char *p;
2277 int offset = p - token_buffer;
2278 extend_token_buffer_to (offset);
2279 return token_buffer + offset;
2282 #if defined HANDLE_PRAGMA
2283 /* Local versions of these macros, that can be passed as function pointers. */
2284 static int
2285 pragma_getc ()
2287 return getch ();
2290 static void
2291 pragma_ungetc (arg)
2292 int arg;
2294 put_back (arg);
2296 #endif
2298 static int
2299 read_line_number (num)
2300 int *num;
2302 register int token = real_yylex ();
2304 if (token == CONSTANT
2305 && TREE_CODE (yylval.ttype) == INTEGER_CST)
2307 *num = TREE_INT_CST_LOW (yylval.ttype);
2308 return 1;
2310 else
2312 if (token != END_OF_LINE)
2313 error ("invalid #-line");
2314 return 0;
2318 /* At the beginning of a line, increment the line number
2319 and process any #-directive on this line.
2320 If the line is a #-directive, read the entire line and return a newline.
2321 Otherwise, return the line's first non-whitespace character.
2323 Note that in the case of USE_CPPLIB, we get the whole line as one
2324 CPP_DIRECTIVE token. */
2326 static int
2327 check_newline ()
2329 register int c;
2330 register int token;
2331 int saw_line;
2332 enum { act_none, act_push, act_pop } action;
2333 int old_lineno, action_number, l;
2334 int entering_c_header;
2336 restart:
2337 /* Read first nonwhite char on the line. Do this before incrementing the
2338 line number, in case we're at the end of saved text. */
2340 #ifdef USE_CPPLIB
2341 c = getch ();
2342 /* In some cases where we're leaving an include file, we can get multiple
2343 CPP_HSPACE tokens in a row, so we need to loop. */
2344 while (cpp_token == CPP_HSPACE)
2345 c = yy_get_token ();
2346 #else
2348 c = getch ();
2349 while (c == ' ' || c == '\t');
2350 #endif
2352 lineno++;
2354 if (c != '#')
2356 /* Sequences of multiple newlines are very common; optimize them. */
2357 if (c == '\n')
2358 goto restart;
2360 /* If not #, return it so caller will use it. */
2361 return c;
2364 /* Don't read beyond this line. */
2365 saw_line = 0;
2366 linemode = 1;
2368 #if USE_CPPLIB
2369 if (cpp_token == CPP_VSPACE)
2371 /* Format is "<space> <line number> <filename> <newline>".
2372 Only the line number is interesting, and even that
2373 we can get more efficiently than scanning the line. */
2374 yy_cur = yy_lim - 1;
2375 lineno = parse_in.lineno - 1;
2376 goto skipline;
2378 #endif
2380 token = real_yylex ();
2382 if (token == IDENTIFIER)
2384 /* If a letter follows, then if the word here is `line', skip
2385 it and ignore it; otherwise, ignore the line, with an error
2386 if the word isn't `pragma'. */
2388 const char *name = IDENTIFIER_POINTER (yylval.ttype);
2390 if (!strcmp (name, "pragma"))
2392 token = real_yylex ();
2393 if (token != IDENTIFIER
2394 || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
2395 goto skipline;
2397 /* If this is 1, we handled it; if it's -1, it was one we
2398 wanted but had something wrong with it. Only if it's
2399 0 was it not handled. */
2400 if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype)))
2401 goto skipline;
2403 #ifdef HANDLE_PRAGMA
2404 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
2405 (if both are defined), in order to give the back
2406 end a chance to override the interpretation of
2407 SYSV style pragmas. */
2408 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
2409 IDENTIFIER_POINTER (yylval.ttype)))
2410 goto skipline;
2411 #endif /* HANDLE_PRAGMA */
2413 #ifdef HANDLE_GENERIC_PRAGMAS
2414 if (handle_generic_pragma (token))
2415 goto skipline;
2416 #endif /* HANDLE_GENERIC_PRAGMAS */
2418 /* Issue a warning message if we have been asked to do so.
2419 Ignoring unknown pragmas in system header file unless
2420 an explcit -Wunknown-pragmas has been given. */
2421 if (warn_unknown_pragmas > 1
2422 || (warn_unknown_pragmas && ! in_system_header))
2423 warning ("ignoring pragma: %s", token_buffer);
2425 goto skipline;
2427 else if (!strcmp (name, "define"))
2429 debug_define (lineno, GET_DIRECTIVE_LINE ());
2430 goto skipline;
2432 else if (!strcmp (name, "undef"))
2434 debug_undef (lineno, GET_DIRECTIVE_LINE ());
2435 goto skipline;
2437 else if (!strcmp (name, "line"))
2439 saw_line = 1;
2440 token = real_yylex ();
2441 goto linenum;
2443 else if (!strcmp (name, "ident"))
2445 /* #ident. The pedantic warning is now in cccp.c. */
2447 /* Here we have just seen `#ident '.
2448 A string constant should follow. */
2450 token = real_yylex ();
2451 if (token == END_OF_LINE)
2452 goto skipline;
2453 if (token != STRING
2454 || TREE_CODE (yylval.ttype) != STRING_CST)
2456 error ("invalid #ident");
2457 goto skipline;
2460 if (! flag_no_ident)
2462 #ifdef ASM_OUTPUT_IDENT
2463 ASM_OUTPUT_IDENT (asm_out_file,
2464 TREE_STRING_POINTER (yylval.ttype));
2465 #endif
2468 /* Skip the rest of this line. */
2469 goto skipline;
2472 error ("undefined or invalid # directive `%s'", name);
2473 goto skipline;
2476 /* If the # is the only nonwhite char on the line,
2477 just ignore it. Check the new newline. */
2478 if (token == END_OF_LINE)
2479 goto skipline;
2481 linenum:
2482 /* Here we have either `#line' or `# <nonletter>'.
2483 In either case, it should be a line number; a digit should follow. */
2485 if (token != CONSTANT
2486 || TREE_CODE (yylval.ttype) != INTEGER_CST)
2488 error ("invalid #-line");
2489 goto skipline;
2492 /* subtract one, because it is the following line that
2493 gets the specified number */
2495 l = TREE_INT_CST_LOW (yylval.ttype) - 1;
2497 /* More follows: it must be a string constant (filename).
2498 It would be neat to use cpplib to quickly process the string, but
2499 (1) we don't have a handy tokenization of the string, and
2500 (2) I don't know how well that would work in the presense
2501 of filenames that contain wide characters. */
2503 if (saw_line)
2505 /* Don't treat \ as special if we are processing #line 1 "...".
2506 If you want it to be treated specially, use # 1 "...". */
2507 ignore_escape_flag = 1;
2510 /* Read the string constant. */
2511 token = real_yylex ();
2513 ignore_escape_flag = 0;
2515 if (token == END_OF_LINE)
2517 /* No more: store the line number and check following line. */
2518 lineno = l;
2519 goto skipline;
2522 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2524 error ("invalid #line");
2525 goto skipline;
2528 /* Changing files again. This means currently collected time
2529 is charged against header time, and body time starts back at 0. */
2530 if (flag_detailed_statistics)
2532 int this_time = my_get_run_time ();
2533 tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype));
2534 header_time += this_time - body_time;
2535 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
2536 += this_time - body_time;
2537 this_filename_time = time_identifier;
2538 body_time = this_time;
2541 input_filename = TREE_STRING_POINTER (yylval.ttype);
2543 GNU_xref_file (input_filename);
2545 if (main_input_filename == 0)
2547 struct impl_files *ifiles = impl_file_chain;
2549 if (ifiles)
2551 while (ifiles->next)
2552 ifiles = ifiles->next;
2553 ifiles->filename = file_name_nondirectory (input_filename);
2556 main_input_filename = input_filename;
2559 extract_interface_info ();
2561 old_lineno = lineno;
2562 action = act_none;
2563 action_number = 0;
2564 lineno = l;
2566 /* Each change of file name
2567 reinitializes whether we are now in a system header. */
2568 in_system_header = 0;
2569 entering_c_header = 0;
2571 if (!read_line_number (&action_number))
2573 /* Update the name in the top element of input_file_stack. */
2574 if (input_file_stack)
2575 input_file_stack->name = input_filename;
2578 /* `1' after file name means entering new file.
2579 `2' after file name means just left a file. */
2581 if (action_number == 1)
2583 action = act_push;
2584 read_line_number (&action_number);
2586 else if (action_number == 2)
2588 action = act_pop;
2589 read_line_number (&action_number);
2591 if (action_number == 3)
2593 /* `3' after file name means this is a system header file. */
2594 in_system_header = 1;
2595 read_line_number (&action_number);
2597 if (action_number == 4)
2599 /* `4' after file name means this is a C header file. */
2600 entering_c_header = 1;
2601 read_line_number (&action_number);
2604 /* Do the actions implied by the preceding numbers. */
2606 if (action == act_push)
2608 /* Pushing to a new file. */
2609 struct file_stack *p
2610 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2611 input_file_stack->line = old_lineno;
2612 p->next = input_file_stack;
2613 p->name = input_filename;
2614 p->indent_level = indent_level;
2615 input_file_stack = p;
2616 input_file_stack_tick++;
2617 debug_start_source_file (input_filename);
2618 if (c_header_level)
2619 ++c_header_level;
2620 else if (entering_c_header)
2622 c_header_level = 1;
2623 ++pending_lang_change;
2626 else if (action == act_pop)
2628 /* Popping out of a file. */
2629 if (input_file_stack->next)
2631 struct file_stack *p = input_file_stack;
2633 if (c_header_level && --c_header_level == 0)
2635 if (entering_c_header)
2636 warning ("badly nested C headers from preprocessor");
2637 --pending_lang_change;
2640 if (indent_level != p->indent_level)
2642 warning_with_file_and_line
2643 (p->name, old_lineno,
2644 "This file contains more `%c's than `%c's.",
2645 indent_level > p->indent_level ? '{' : '}',
2646 indent_level > p->indent_level ? '}' : '{');
2648 input_file_stack = p->next;
2649 free (p);
2650 input_file_stack_tick++;
2651 debug_end_source_file (input_file_stack->line);
2653 else
2654 error ("#-lines for entering and leaving files don't match");
2657 /* Now that we've pushed or popped the input stack,
2658 update the name in the top element. */
2659 if (input_file_stack)
2660 input_file_stack->name = input_filename;
2662 /* skip the rest of this line. */
2663 skipline:
2664 linemode = 0;
2665 end_of_file = 0;
2668 c = getch ();
2669 while (c != '\n' && c != EOF);
2670 return c;
2673 #ifdef HANDLE_GENERIC_PRAGMAS
2675 /* Handle a #pragma directive.
2676 TOKEN is the token we read after `#pragma'. Processes the entire input
2677 line and return non-zero iff the pragma has been successfully parsed. */
2679 /* This function has to be in this file, in order to get at
2680 the token types. */
2682 static int
2683 handle_generic_pragma (token)
2684 register int token;
2686 for (;;)
2688 switch (token)
2690 case IDENTIFIER:
2691 case TYPENAME:
2692 case STRING:
2693 case CONSTANT:
2694 handle_pragma_token (token_buffer, yylval.ttype);
2695 break;
2697 case LEFT_RIGHT:
2698 handle_pragma_token ("(", NULL_TREE);
2699 handle_pragma_token (")", NULL_TREE);
2700 break;
2702 case END_OF_LINE:
2703 return handle_pragma_token (NULL_PTR, NULL_TREE);
2705 default:
2706 handle_pragma_token (token_buffer, NULL_TREE);
2709 token = real_yylex ();
2712 #endif /* HANDLE_GENERIC_PRAGMAS */
2714 static int
2715 handle_cp_pragma (pname)
2716 const char *pname;
2718 register int token;
2720 if (! strcmp (pname, "vtable"))
2722 /* More follows: it must be a string constant (class name). */
2723 token = real_yylex ();
2724 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2726 error ("invalid #pragma vtable");
2727 return -1;
2730 pending_vtables
2731 = tree_cons (NULL_TREE,
2732 get_identifier (TREE_STRING_POINTER (yylval.ttype)),
2733 pending_vtables);
2734 token = real_yylex ();
2735 if (token != END_OF_LINE)
2736 warning ("trailing characters ignored");
2737 return 1;
2739 else if (! strcmp (pname, "unit"))
2741 /* More follows: it must be a string constant (unit name). */
2742 token = real_yylex ();
2743 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2745 error ("invalid #pragma unit");
2746 return -1;
2748 token = real_yylex ();
2749 if (token != END_OF_LINE)
2750 warning ("trailing characters ignored");
2751 return 1;
2753 else if (! strcmp (pname, "interface"))
2755 char *main_filename = input_filename;
2757 main_filename = file_name_nondirectory (main_filename);
2759 token = real_yylex ();
2761 if (token != END_OF_LINE)
2763 if (token != STRING
2764 || TREE_CODE (yylval.ttype) != STRING_CST)
2766 error ("invalid `#pragma interface'");
2767 return -1;
2769 main_filename = TREE_STRING_POINTER (yylval.ttype);
2770 token = real_yylex ();
2773 if (token != END_OF_LINE)
2774 warning ("garbage after `#pragma interface' ignored");
2776 cp_pragma_interface (main_filename);
2778 return 1;
2780 else if (! strcmp (pname, "implementation"))
2782 char *main_filename = main_input_filename ? main_input_filename : input_filename;
2784 main_filename = file_name_nondirectory (main_filename);
2786 token = real_yylex ();
2788 if (token != END_OF_LINE)
2790 if (token != STRING
2791 || TREE_CODE (yylval.ttype) != STRING_CST)
2793 error ("invalid `#pragma implementation'");
2794 return -1;
2796 main_filename = TREE_STRING_POINTER (yylval.ttype);
2797 token = real_yylex ();
2800 if (token != END_OF_LINE)
2801 warning ("garbage after `#pragma implementation' ignored");
2803 cp_pragma_implementation (main_filename);
2805 return 1;
2808 return 0;
2811 void
2812 do_pending_lang_change ()
2814 for (; pending_lang_change > 0; --pending_lang_change)
2815 push_lang_context (lang_name_c);
2816 for (; pending_lang_change < 0; ++pending_lang_change)
2817 pop_lang_context ();
2820 #define ENDFILE -1 /* token that represents end-of-file */
2822 /* Read an escape sequence, returning its equivalent as a character,
2823 or store 1 in *ignore_ptr if it is backslash-newline. */
2825 static int
2826 readescape (ignore_ptr)
2827 int *ignore_ptr;
2829 register int c = getch ();
2830 register int code;
2831 register unsigned count;
2832 unsigned firstdig = 0;
2833 int nonnull;
2835 switch (c)
2837 case 'x':
2838 code = 0;
2839 count = 0;
2840 nonnull = 0;
2841 while (1)
2843 c = getch ();
2844 if (! ISXDIGIT (c))
2846 put_back (c);
2847 break;
2849 code *= 16;
2850 if (c >= 'a' && c <= 'f')
2851 code += c - 'a' + 10;
2852 if (c >= 'A' && c <= 'F')
2853 code += c - 'A' + 10;
2854 if (c >= '0' && c <= '9')
2855 code += c - '0';
2856 if (code != 0 || count != 0)
2858 if (count == 0)
2859 firstdig = code;
2860 count++;
2862 nonnull = 1;
2864 if (! nonnull)
2865 error ("\\x used with no following hex digits");
2866 else if (count == 0)
2867 /* Digits are all 0's. Ok. */
2869 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
2870 || (count > 1
2871 && (((unsigned)1
2872 << (TYPE_PRECISION (integer_type_node)
2873 - (count - 1) * 4))
2874 <= firstdig)))
2875 pedwarn ("hex escape out of range");
2876 return code;
2878 case '0': case '1': case '2': case '3': case '4':
2879 case '5': case '6': case '7':
2880 code = 0;
2881 count = 0;
2882 while ((c <= '7') && (c >= '0') && (count++ < 3))
2884 code = (code * 8) + (c - '0');
2885 c = getch ();
2887 put_back (c);
2888 return code;
2890 case '\\': case '\'': case '"':
2891 return c;
2893 case '\n':
2894 lineno++;
2895 *ignore_ptr = 1;
2896 return 0;
2898 case 'n':
2899 return TARGET_NEWLINE;
2901 case 't':
2902 return TARGET_TAB;
2904 case 'r':
2905 return TARGET_CR;
2907 case 'f':
2908 return TARGET_FF;
2910 case 'b':
2911 return TARGET_BS;
2913 case 'a':
2914 return TARGET_BELL;
2916 case 'v':
2917 return TARGET_VT;
2919 case 'e':
2920 case 'E':
2921 if (pedantic)
2922 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
2923 return 033;
2925 case '?':
2926 return c;
2928 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
2929 case '(':
2930 case '{':
2931 case '[':
2932 /* `\%' is used to prevent SCCS from getting confused. */
2933 case '%':
2934 if (pedantic)
2935 pedwarn ("unknown escape sequence `\\%c'", c);
2936 return c;
2938 if (ISGRAPH (c))
2939 pedwarn ("unknown escape sequence `\\%c'", c);
2940 else
2941 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
2942 return c;
2945 void
2946 yyerror (string)
2947 const char *string;
2949 extern int end_of_file;
2950 char buf[200];
2952 strcpy (buf, string);
2954 /* We can't print string and character constants well
2955 because the token_buffer contains the result of processing escapes. */
2956 if (end_of_file)
2957 strcat (buf, input_redirected ()
2958 ? " at end of saved text"
2959 : " at end of input");
2960 else if (token_buffer[0] == 0)
2961 strcat (buf, " at null character");
2962 else if (token_buffer[0] == '"')
2963 strcat (buf, " before string constant");
2964 else if (token_buffer[0] == '\'')
2965 strcat (buf, " before character constant");
2966 else if (!ISGRAPH ((unsigned char)token_buffer[0]))
2967 sprintf (buf + strlen (buf), " before character 0%o",
2968 (unsigned char) token_buffer[0]);
2969 else
2970 strcat (buf, " before `%s'");
2972 error (buf, token_buffer);
2975 /* Value is 1 (or 2) if we should try to make the next identifier look like
2976 a typename (when it may be a local variable or a class variable).
2977 Value is 0 if we treat this name in a default fashion. */
2978 int looking_for_typename;
2980 inline int
2981 identifier_type (decl)
2982 tree decl;
2984 tree t;
2985 if (TREE_CODE (decl) == TEMPLATE_DECL)
2987 if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL)
2988 return PTYPENAME;
2989 else if (looking_for_template)
2990 return PFUNCNAME;
2992 if (looking_for_template && really_overloaded_fn (decl))
2994 /* See through a baselink. */
2995 if (TREE_CODE (decl) == TREE_LIST)
2996 decl = TREE_VALUE (decl);
2998 for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t))
2999 if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t)))
3000 return PFUNCNAME;
3002 if (TREE_CODE (decl) == NAMESPACE_DECL)
3003 return NSNAME;
3004 if (TREE_CODE (decl) != TYPE_DECL)
3005 return IDENTIFIER;
3006 if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type)
3007 return SELFNAME;
3009 /* A constructor declarator for a template type will get here as an
3010 implicit typename, a TYPENAME_TYPE with a type. */
3011 t = got_scope;
3012 if (t && TREE_CODE (t) == TYPENAME_TYPE)
3013 t = TREE_TYPE (t);
3014 decl = TREE_TYPE (decl);
3015 if (TREE_CODE (decl) == TYPENAME_TYPE)
3016 decl = TREE_TYPE (decl);
3017 if (t && t == decl)
3018 return SELFNAME;
3020 return TYPENAME;
3023 void
3024 see_typename ()
3026 /* Only types expected, not even namespaces. */
3027 looking_for_typename = 2;
3028 if (yychar < 0)
3029 if ((yychar = yylex ()) < 0) yychar = 0;
3030 looking_for_typename = 0;
3031 if (yychar == IDENTIFIER)
3033 lastiddecl = lookup_name (yylval.ttype, -2);
3034 if (lastiddecl == 0)
3036 if (flag_labels_ok)
3037 lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype);
3039 else
3040 yychar = identifier_type (lastiddecl);
3044 /* Return true if d is in a global scope. */
3046 static int
3047 is_global (d)
3048 tree d;
3050 while (1)
3051 switch (TREE_CODE (d))
3053 case ERROR_MARK:
3054 return 1;
3056 case OVERLOAD: d = OVL_FUNCTION (d); continue;
3057 case TREE_LIST: d = TREE_VALUE (d); continue;
3058 default:
3059 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (d)) == 'd', 980629);
3061 /* A template parameter is not really global, even though it
3062 has no enclosing scope. */
3063 if (DECL_TEMPLATE_PARM_P (d))
3064 return 0;
3066 d = CP_DECL_CONTEXT (d);
3067 return TREE_CODE (d) == NAMESPACE_DECL;
3071 tree
3072 do_identifier (token, parsing, args)
3073 register tree token;
3074 int parsing;
3075 tree args;
3077 register tree id;
3078 int lexing = (parsing == 1);
3079 int in_call = (parsing == 2);
3081 if (! lexing || IDENTIFIER_OPNAME_P (token))
3082 id = lookup_name (token, 0);
3083 else
3084 id = lastiddecl;
3086 /* Do Koenig lookup if appropriate (inside templates we build lookup
3087 expressions instead).
3089 [basic.lookup.koenig]: If the ordinary unqualified lookup of the name
3090 finds the declaration of a class member function, the associated
3091 namespaces and classes are not considered. */
3093 if (args && !current_template_parms && (!id || is_global (id)))
3094 id = lookup_arg_dependent (token, id, args);
3096 /* Remember that this name has been used in the class definition, as per
3097 [class.scope0] */
3098 if (id && parsing
3099 /* Avoid breaking if we get called for a default argument that
3100 refers to an overloaded method. Eventually this will not be
3101 necessary, since default arguments shouldn't be parsed until
3102 after the class is complete. (jason 3/12/97) */
3103 && TREE_CODE (id) != OVERLOAD)
3104 maybe_note_name_used_in_class (token, id);
3106 if (id == error_mark_node)
3108 /* lookup_name quietly returns error_mark_node if we're parsing,
3109 as we don't want to complain about an identifier that ends up
3110 being used as a declarator. So we call it again to get the error
3111 message. */
3112 id = lookup_name (token, 0);
3113 return error_mark_node;
3116 if (!id)
3118 if (current_template_parms)
3119 return build_min_nt (LOOKUP_EXPR, token);
3120 else if (IDENTIFIER_OPNAME_P (token))
3122 if (token != ansi_opname[ERROR_MARK])
3123 cp_error ("`%D' not defined", token);
3124 id = error_mark_node;
3126 else if (in_call && ! flag_strict_prototype)
3128 id = implicitly_declare (token);
3130 else if (current_function_decl == 0)
3132 cp_error ("`%D' was not declared in this scope", token);
3133 id = error_mark_node;
3135 else
3137 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node
3138 || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
3140 static int undeclared_variable_notice;
3142 cp_error ("`%D' undeclared (first use this function)", token);
3144 if (! undeclared_variable_notice)
3146 error ("(Each undeclared identifier is reported only once");
3147 error ("for each function it appears in.)");
3148 undeclared_variable_notice = 1;
3151 id = error_mark_node;
3152 /* Prevent repeated error messages. */
3153 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3154 SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
3158 if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
3160 tree shadowed = DECL_SHADOWED_FOR_VAR (id);
3161 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
3162 && DECL_DEAD_FOR_LOCAL (shadowed))
3163 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
3164 if (!shadowed)
3165 shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id));
3166 if (shadowed)
3168 if (!DECL_ERROR_REPORTED (id))
3170 warning ("name lookup of `%s' changed",
3171 IDENTIFIER_POINTER (token));
3172 cp_warning_at (" matches this `%D' under current ANSI rules",
3173 shadowed);
3174 cp_warning_at (" matches this `%D' under old rules", id);
3175 DECL_ERROR_REPORTED (id) = 1;
3177 id = shadowed;
3179 else if (!DECL_ERROR_REPORTED (id))
3181 static char msg[]
3182 = "name lookup of `%s' changed for new ANSI `for' scoping";
3183 DECL_ERROR_REPORTED (id) = 1;
3184 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id)))
3186 error (msg, IDENTIFIER_POINTER (token));
3187 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id);
3188 id = error_mark_node;
3190 else
3192 pedwarn (msg, IDENTIFIER_POINTER (token));
3193 cp_pedwarn_at (" using obsolete binding at `%D'", id);
3197 /* TREE_USED is set in `hack_identifier'. */
3198 if (TREE_CODE (id) == CONST_DECL)
3200 /* Check access. */
3201 if (IDENTIFIER_CLASS_VALUE (token) == id)
3202 enforce_access (DECL_REAL_CONTEXT(id), id);
3203 if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
3204 id = DECL_INITIAL (id);
3206 else
3207 id = hack_identifier (id, token);
3209 /* We must look up dependent names when the template is
3210 instantiated, not while parsing it. For now, we don't
3211 distinguish between dependent and independent names. So, for
3212 example, we look up all overloaded functions at
3213 instantiation-time, even though in some cases we should just use
3214 the DECL we have here. We also use LOOKUP_EXPRs to find things
3215 like local variables, rather than creating TEMPLATE_DECLs for the
3216 local variables and then finding matching instantiations. */
3217 if (current_template_parms
3218 && (is_overloaded_fn (id)
3219 /* If it's not going to be around at instantiation time, we
3220 look it up then. This is a hack, and should go when we
3221 really get dependent/independent name lookup right. */
3222 || !TREE_PERMANENT (id)
3223 /* Some local VAR_DECLs (such as those for local variables
3224 in member functions of local classes) are built on the
3225 permanent obstack. */
3226 || (TREE_CODE (id) == VAR_DECL
3227 && CP_DECL_CONTEXT (id)
3228 && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL)
3229 || TREE_CODE (id) == PARM_DECL
3230 || TREE_CODE (id) == RESULT_DECL
3231 || TREE_CODE (id) == USING_DECL))
3232 id = build_min_nt (LOOKUP_EXPR, token);
3234 return id;
3237 tree
3238 do_scoped_id (token, parsing)
3239 tree token;
3240 int parsing;
3242 tree id;
3243 /* during parsing, this is ::name. Otherwise, it is black magic. */
3244 if (parsing)
3246 id = make_node (CPLUS_BINDING);
3247 if (!qualified_lookup_using_namespace (token, global_namespace, id, 0))
3248 id = NULL_TREE;
3249 else
3250 id = BINDING_VALUE (id);
3252 else
3253 id = IDENTIFIER_GLOBAL_VALUE (token);
3254 if (parsing && yychar == YYEMPTY)
3255 yychar = yylex ();
3256 if (! id)
3258 if (processing_template_decl)
3260 id = build_min_nt (LOOKUP_EXPR, token);
3261 LOOKUP_EXPR_GLOBAL (id) = 1;
3262 return id;
3264 if (parsing && (yychar == '(' || yychar == LEFT_RIGHT)
3265 && ! flag_strict_prototype)
3266 id = implicitly_declare (token);
3267 else
3269 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
3270 cp_error ("`::%D' undeclared (first use here)", token);
3271 id = error_mark_node;
3272 /* Prevent repeated error messages. */
3273 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3276 else
3278 if (TREE_CODE (id) == ADDR_EXPR)
3279 mark_used (TREE_OPERAND (id, 0));
3280 else if (TREE_CODE (id) != OVERLOAD)
3281 mark_used (id);
3283 if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
3285 /* XXX CHS - should we set TREE_USED of the constant? */
3286 id = DECL_INITIAL (id);
3287 /* This is to prevent an enum whose value is 0
3288 from being considered a null pointer constant. */
3289 id = build1 (NOP_EXPR, TREE_TYPE (id), id);
3290 TREE_CONSTANT (id) = 1;
3293 if (processing_template_decl)
3295 if (is_overloaded_fn (id))
3297 id = build_min_nt (LOOKUP_EXPR, token);
3298 LOOKUP_EXPR_GLOBAL (id) = 1;
3299 return id;
3301 /* else just use the decl */
3303 return convert_from_reference (id);
3306 tree
3307 identifier_typedecl_value (node)
3308 tree node;
3310 tree t, type;
3311 type = IDENTIFIER_TYPE_VALUE (node);
3312 if (type == NULL_TREE)
3313 return NULL_TREE;
3315 if (IDENTIFIER_BINDING (node))
3317 t = IDENTIFIER_VALUE (node);
3318 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3319 return t;
3321 if (IDENTIFIER_NAMESPACE_VALUE (node))
3323 t = IDENTIFIER_NAMESPACE_VALUE (node);
3324 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3325 return t;
3328 /* Will this one ever happen? */
3329 if (TYPE_MAIN_DECL (type))
3330 return TYPE_MAIN_DECL (type);
3332 /* We used to do an internal error of 62 here, but instead we will
3333 handle the return of a null appropriately in the callers. */
3334 return NULL_TREE;
3337 struct pf_args
3339 /* Input */
3340 int base;
3341 char * p;
3342 /* I/O */
3343 int c;
3344 /* Output */
3345 int imag;
3346 tree type;
3347 int conversion_errno;
3348 REAL_VALUE_TYPE value;
3351 static void
3352 parse_float (data)
3353 PTR data;
3355 struct pf_args * args = (struct pf_args *) data;
3356 int fflag = 0, lflag = 0;
3357 /* Copy token_buffer now, while it has just the number
3358 and not the suffixes; once we add `f' or `i',
3359 REAL_VALUE_ATOF may not work any more. */
3360 char *copy = (char *) alloca (args->p - token_buffer + 1);
3361 bcopy (token_buffer, copy, args->p - token_buffer + 1);
3362 args->imag = 0;
3363 args->conversion_errno = 0;
3364 args->type = double_type_node;
3366 while (1)
3368 int lose = 0;
3370 /* Read the suffixes to choose a data type. */
3371 switch (args->c)
3373 case 'f': case 'F':
3374 if (fflag)
3375 error ("more than one `f' in numeric constant");
3376 fflag = 1;
3377 break;
3379 case 'l': case 'L':
3380 if (lflag)
3381 error ("more than one `l' in numeric constant");
3382 lflag = 1;
3383 break;
3385 case 'i': case 'I':
3386 if (args->imag)
3387 error ("more than one `i' or `j' in numeric constant");
3388 else if (pedantic)
3389 pedwarn ("ANSI C++ forbids imaginary numeric constants");
3390 args->imag = 1;
3391 break;
3393 default:
3394 lose = 1;
3397 if (lose)
3398 break;
3400 if (args->p >= token_buffer + maxtoken - 3)
3401 args->p = extend_token_buffer (args->p);
3402 *(args->p++) = args->c;
3403 *(args->p) = 0;
3404 args->c = getch ();
3407 /* The second argument, machine_mode, of REAL_VALUE_ATOF
3408 tells the desired precision of the binary result
3409 of decimal-to-binary conversion. */
3411 if (fflag)
3413 if (lflag)
3414 error ("both `f' and `l' in floating constant");
3416 args->type = float_type_node;
3417 errno = 0;
3418 if (args->base == 16)
3419 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3420 else
3421 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3422 args->conversion_errno = errno;
3423 /* A diagnostic is required here by some ANSI C testsuites.
3424 This is not pedwarn, because some people don't want
3425 an error for this. */
3426 if (REAL_VALUE_ISINF (args->value) && pedantic)
3427 warning ("floating point number exceeds range of `float'");
3429 else if (lflag)
3431 args->type = long_double_type_node;
3432 errno = 0;
3433 if (args->base == 16)
3434 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3435 else
3436 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3437 args->conversion_errno = errno;
3438 if (REAL_VALUE_ISINF (args->value) && pedantic)
3439 warning ("floating point number exceeds range of `long double'");
3441 else
3443 errno = 0;
3444 if (args->base == 16)
3445 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3446 else
3447 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3448 args->conversion_errno = errno;
3449 if (REAL_VALUE_ISINF (args->value) && pedantic)
3450 warning ("floating point number exceeds range of `double'");
3454 /* Get the next character, staying within the current token if possible.
3455 If we're lexing a token, we don't want to look beyond the end of the
3456 token cpplib has prepared for us; otherwise, we end up reading in the
3457 next token, which screws up feed_input. So just return a null
3458 character. */
3460 static int
3461 token_getch ()
3463 #if USE_CPPLIB
3464 if (yy_cur == yy_lim)
3465 return '\0';
3466 #endif
3467 return getch ();
3470 static void
3471 token_put_back (ch)
3472 int ch;
3474 #if USE_CPPLIB
3475 if (ch == '\0')
3476 return;
3477 #endif
3478 put_back (ch);
3481 /* Read a single token from the input stream, and assign it lexical
3482 semantics.
3484 Note: We used to do token pasting here, to produce compound tokens like
3485 LEFT_RIGHT and EXTERN_LANG_STRING. That's now handled in spew.c, along
3486 with symbol table interaction and other context-sensitivity. */
3489 real_yylex ()
3491 register int c;
3492 register char *p;
3493 register int value;
3494 int wide_flag = 0;
3496 c = getch ();
3498 /* Effectively do c = skip_white_space (c)
3499 but do it faster in the usual cases. */
3500 while (1)
3501 switch (c)
3503 case ' ':
3504 case '\t':
3505 case '\f':
3506 case '\v':
3507 case '\b':
3508 #if USE_CPPLIB
3509 if (cpp_token == CPP_HSPACE)
3510 c = yy_get_token ();
3511 else
3512 #endif
3513 c = getch ();
3514 break;
3516 case '\r':
3517 /* Call skip_white_space so we can warn if appropriate. */
3519 case '\n':
3520 case '/':
3521 case '\\':
3522 c = skip_white_space (c);
3523 default:
3524 goto found_nonwhite;
3526 found_nonwhite:
3528 token_buffer[0] = c;
3529 token_buffer[1] = 0;
3531 /* yylloc.first_line = lineno; */
3533 switch (c)
3535 case EOF:
3536 end_of_file = 1;
3537 token_buffer[0] = 0;
3538 if (linemode)
3539 value = END_OF_LINE;
3540 else if (input_redirected ())
3541 value = END_OF_SAVED_INPUT;
3542 else
3543 value = ENDFILE;
3544 break;
3546 case 'L':
3547 #if USE_CPPLIB
3548 if (cpp_token == CPP_NAME)
3549 goto letter;
3550 #endif
3551 /* Capital L may start a wide-string or wide-character constant. */
3553 register int c = token_getch ();
3554 if (c == '\'')
3556 wide_flag = 1;
3557 goto char_constant;
3559 if (c == '"')
3561 wide_flag = 1;
3562 goto string_constant;
3564 token_put_back (c);
3567 case 'A': case 'B': case 'C': case 'D': case 'E':
3568 case 'F': case 'G': case 'H': case 'I': case 'J':
3569 case 'K': case 'M': case 'N': case 'O':
3570 case 'P': case 'Q': case 'R': case 'S': case 'T':
3571 case 'U': case 'V': case 'W': case 'X': case 'Y':
3572 case 'Z':
3573 case 'a': case 'b': case 'c': case 'd': case 'e':
3574 case 'f': case 'g': case 'h': case 'i': case 'j':
3575 case 'k': case 'l': case 'm': case 'n': case 'o':
3576 case 'p': case 'q': case 'r': case 's': case 't':
3577 case 'u': case 'v': case 'w': case 'x': case 'y':
3578 case 'z':
3579 case '_':
3580 case '$':
3581 #if USE_CPPLIB
3582 letter:
3583 if (cpp_token == CPP_NAME)
3585 /* Note that one character has already been read from
3586 yy_cur into token_buffer. Also, cpplib complains about
3587 $ in identifiers, so we don't have to. */
3589 int len = yy_lim - yy_cur + 1;
3590 if (len >= maxtoken)
3591 extend_token_buffer_to (len + 1);
3592 memcpy (token_buffer + 1, yy_cur, len);
3593 p = token_buffer + len;
3594 yy_cur = yy_lim;
3596 else
3597 #endif
3599 p = token_buffer;
3600 while (ISALNUM (c) || (c == '_') || c == '$')
3602 /* Make sure this char really belongs in an identifier. */
3603 if (c == '$')
3605 if (! dollars_in_ident)
3606 error ("`$' in identifier");
3607 else if (pedantic)
3608 pedwarn ("`$' in identifier");
3611 if (p >= token_buffer + maxtoken)
3612 p = extend_token_buffer (p);
3614 *p++ = c;
3615 c = token_getch ();
3618 *p = 0;
3619 token_put_back (c);
3622 value = IDENTIFIER;
3623 yylval.itype = 0;
3625 /* Try to recognize a keyword. Uses minimum-perfect hash function */
3628 register struct resword *ptr;
3630 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
3632 if (ptr->rid)
3634 if (ptr->token == VISSPEC)
3636 switch (ptr->rid)
3638 case RID_PUBLIC:
3639 yylval.ttype = access_public_node;
3640 break;
3641 case RID_PRIVATE:
3642 yylval.ttype = access_private_node;
3643 break;
3644 case RID_PROTECTED:
3645 yylval.ttype = access_protected_node;
3646 break;
3647 default:
3648 my_friendly_abort (63);
3651 else
3652 yylval.ttype = ridpointers[(int) ptr->rid];
3654 else switch (ptr->token)
3656 case EQCOMPARE:
3657 yylval.code = NE_EXPR;
3658 token_buffer[0] = '!';
3659 token_buffer[1] = '=';
3660 token_buffer[2] = 0;
3661 break;
3663 case ASSIGN:
3664 if (strcmp ("and_eq", token_buffer) == 0)
3666 yylval.code = BIT_AND_EXPR;
3667 token_buffer[0] = '&';
3669 else if (strcmp ("or_eq", token_buffer) == 0)
3671 yylval.code = BIT_IOR_EXPR;
3672 token_buffer[0] = '|';
3674 else if (strcmp ("xor_eq", token_buffer) == 0)
3676 yylval.code = BIT_XOR_EXPR;
3677 token_buffer[0] = '^';
3679 token_buffer[1] = '=';
3680 token_buffer[2] = 0;
3681 break;
3683 case '&':
3684 yylval.code = BIT_AND_EXPR;
3685 token_buffer[0] = '&';
3686 token_buffer[1] = 0;
3687 break;
3689 case '|':
3690 yylval.code = BIT_IOR_EXPR;
3691 token_buffer[0] = '|';
3692 token_buffer[1] = 0;
3693 break;
3695 case '^':
3696 yylval.code = BIT_XOR_EXPR;
3697 token_buffer[0] = '^';
3698 token_buffer[1] = 0;
3699 break;
3702 value = (int) ptr->token;
3706 /* If we did not find a keyword, look for an identifier
3707 (or a typename). */
3709 if (value == IDENTIFIER || value == TYPESPEC)
3710 GNU_xref_ref (current_function_decl, token_buffer);
3712 if (value == IDENTIFIER)
3714 register tree tmp = get_identifier (token_buffer);
3716 #if !defined(VMS) && defined(JOINER)
3717 /* Make sure that user does not collide with our internal
3718 naming scheme. */
3719 if (JOINER == '$'
3720 && (THIS_NAME_P (tmp)
3721 || VPTR_NAME_P (tmp)
3722 || DESTRUCTOR_NAME_P (tmp)
3723 || VTABLE_NAME_P (tmp)
3724 || TEMP_NAME_P (tmp)
3725 || ANON_AGGRNAME_P (tmp)
3726 || ANON_PARMNAME_P (tmp)))
3727 warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3728 token_buffer);
3729 #endif
3731 yylval.ttype = tmp;
3733 if (value == NEW && ! global_bindings_p ())
3735 value = NEW;
3736 goto done;
3738 break;
3740 case '.':
3741 #if USE_CPPLIB
3742 if (yy_cur < yy_lim)
3743 #endif
3745 /* It's hard to preserve tokenization on '.' because
3746 it could be a symbol by itself, or it could be the
3747 start of a floating point number and cpp won't tell us. */
3748 register int c1 = token_getch ();
3749 token_buffer[1] = c1;
3750 if (c1 == '*')
3752 value = DOT_STAR;
3753 token_buffer[2] = 0;
3754 goto done;
3756 if (c1 == '.')
3758 c1 = token_getch ();
3759 if (c1 == '.')
3761 token_buffer[2] = c1;
3762 token_buffer[3] = 0;
3763 value = ELLIPSIS;
3764 goto done;
3766 error ("parse error at `..'");
3768 if (ISDIGIT (c1))
3770 token_put_back (c1);
3771 goto number;
3773 token_put_back (c1);
3775 value = '.';
3776 token_buffer[1] = 0;
3777 break;
3779 case '0': case '1':
3780 /* Optimize for most frequent case. */
3782 register int cond;
3784 #if USE_CPPLIB
3785 cond = (yy_cur == yy_lim);
3786 #else
3787 register int c1 = token_getch ();
3788 token_put_back (c1);
3789 cond = (! ISALNUM (c1) && c1 != '.');
3790 #endif
3791 if (cond)
3793 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
3794 value = CONSTANT;
3795 break;
3797 /*FALLTHRU*/
3799 case '2': case '3': case '4':
3800 case '5': case '6': case '7': case '8': case '9':
3801 number:
3803 int base = 10;
3804 int count = 0;
3805 int largest_digit = 0;
3806 int numdigits = 0;
3807 int overflow = 0;
3809 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
3810 The code below which fills the parts array assumes that a host
3811 int is at least twice as wide as a host char, and that
3812 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
3813 Two HOST_WIDE_INTs is the largest int literal we can store.
3814 In order to detect overflow below, the number of parts (TOTAL_PARTS)
3815 must be exactly the number of parts needed to hold the bits
3816 of two HOST_WIDE_INTs. */
3817 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
3818 unsigned int parts[TOTAL_PARTS];
3820 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON }
3821 floatflag = NOT_FLOAT;
3823 for (count = 0; count < TOTAL_PARTS; count++)
3824 parts[count] = 0;
3826 p = token_buffer;
3827 *p++ = c;
3829 if (c == '0')
3831 *p++ = (c = token_getch ());
3832 if ((c == 'x') || (c == 'X'))
3834 base = 16;
3835 *p++ = (c = token_getch ());
3837 /* Leading 0 forces octal unless the 0 is the only digit. */
3838 else if (c >= '0' && c <= '9')
3840 base = 8;
3841 numdigits++;
3843 else
3844 numdigits++;
3847 /* Read all the digits-and-decimal-points. */
3849 while (c == '.'
3850 || (ISALNUM (c) && c != 'l' && c != 'L'
3851 && c != 'u' && c != 'U'
3852 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
3853 && (floatflag == NOT_FLOAT
3854 || ((base != 16) && (c != 'f') && (c != 'F'))
3855 || base == 16)))
3857 if (c == '.')
3859 if (base == 16 && pedantic)
3860 pedwarn ("floating constant may not be in radix 16");
3861 if (floatflag == TOO_MANY_POINTS)
3862 /* We have already emitted an error. Don't need another. */
3864 else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON)
3866 error ("malformed floating constant");
3867 floatflag = TOO_MANY_POINTS;
3868 /* Avoid another error from atof by forcing all characters
3869 from here on to be ignored. */
3870 p[-1] = '\0';
3872 else
3873 floatflag = AFTER_POINT;
3875 if (base == 8)
3876 base = 10;
3877 *p++ = c = token_getch ();
3878 /* Accept '.' as the start of a floating-point number
3879 only when it is followed by a digit. */
3880 if (p == token_buffer + 2 && !ISDIGIT (c))
3881 my_friendly_abort (990710);
3883 else
3885 /* It is not a decimal point.
3886 It should be a digit (perhaps a hex digit). */
3888 if (ISDIGIT (c))
3890 c = c - '0';
3892 else if (base <= 10)
3894 if (c == 'e' || c == 'E')
3896 base = 10;
3897 floatflag = AFTER_EXPON;
3898 break; /* start of exponent */
3900 error ("nondigits in number and not hexadecimal");
3901 c = 0;
3903 else if (base == 16 && (c == 'p' || c == 'P'))
3905 floatflag = AFTER_EXPON;
3906 break; /* start of exponent */
3908 else if (c >= 'a')
3910 c = c - 'a' + 10;
3912 else
3914 c = c - 'A' + 10;
3916 if (c >= largest_digit)
3917 largest_digit = c;
3918 numdigits++;
3920 for (count = 0; count < TOTAL_PARTS; count++)
3922 parts[count] *= base;
3923 if (count)
3925 parts[count]
3926 += (parts[count-1] >> HOST_BITS_PER_CHAR);
3927 parts[count-1]
3928 &= (1 << HOST_BITS_PER_CHAR) - 1;
3930 else
3931 parts[0] += c;
3934 /* If the highest-order part overflows (gets larger than
3935 a host char will hold) then the whole number has
3936 overflowed. Record this and truncate the highest-order
3937 part. */
3938 if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
3940 overflow = 1;
3941 parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
3944 if (p >= token_buffer + maxtoken - 3)
3945 p = extend_token_buffer (p);
3946 *p++ = (c = token_getch ());
3950 /* This can happen on input like `int i = 0x;' */
3951 if (numdigits == 0)
3952 error ("numeric constant with no digits");
3954 if (largest_digit >= base)
3955 error ("numeric constant contains digits beyond the radix");
3957 /* Remove terminating char from the token buffer and delimit the
3958 string. */
3959 *--p = 0;
3961 if (floatflag != NOT_FLOAT)
3963 tree type;
3964 int imag, conversion_errno;
3965 REAL_VALUE_TYPE value;
3966 struct pf_args args;
3968 /* Read explicit exponent if any, and put it in tokenbuf. */
3970 if ((base == 10 && ((c == 'e') || (c == 'E')))
3971 || (base == 16 && (c == 'p' || c == 'P')))
3973 if (p >= token_buffer + maxtoken - 3)
3974 p = extend_token_buffer (p);
3975 *p++ = c;
3976 c = token_getch ();
3977 if ((c == '+') || (c == '-'))
3979 *p++ = c;
3980 c = token_getch ();
3982 /* Exponent is decimal, even if string is a hex float. */
3983 if (! ISDIGIT (c))
3984 error ("floating constant exponent has no digits");
3985 while (ISDIGIT (c))
3987 if (p >= token_buffer + maxtoken - 3)
3988 p = extend_token_buffer (p);
3989 *p++ = c;
3990 c = token_getch ();
3993 if (base == 16 && floatflag != AFTER_EXPON)
3994 error ("hexadecimal floating constant has no exponent");
3996 *p = 0;
3998 /* Setup input for parse_float() */
3999 args.base = base;
4000 args.p = p;
4001 args.c = c;
4003 /* Convert string to a double, checking for overflow. */
4004 if (do_float_handler (parse_float, (PTR) &args))
4006 /* Receive output from parse_float() */
4007 value = args.value;
4009 else
4011 /* We got an exception from parse_float() */
4012 error ("floating constant out of range");
4013 value = dconst0;
4016 /* Receive output from parse_float() */
4017 c = args.c;
4018 imag = args.imag;
4019 type = args.type;
4020 conversion_errno = args.conversion_errno;
4022 #ifdef ERANGE
4023 /* ERANGE is also reported for underflow,
4024 so test the value to distinguish overflow from that. */
4025 if (conversion_errno == ERANGE && pedantic
4026 && (REAL_VALUES_LESS (dconst1, value)
4027 || REAL_VALUES_LESS (value, dconstm1)))
4028 warning ("floating point number exceeds range of `double'");
4029 #endif
4031 /* If the result is not a number, assume it must have been
4032 due to some error message above, so silently convert
4033 it to a zero. */
4034 if (REAL_VALUE_ISNAN (value))
4035 value = dconst0;
4037 /* Create a node with determined type and value. */
4038 if (imag)
4039 yylval.ttype = build_complex (NULL_TREE,
4040 convert (type, integer_zero_node),
4041 build_real (type, value));
4042 else
4043 yylval.ttype = build_real (type, value);
4045 else
4047 tree type;
4048 HOST_WIDE_INT high, low;
4049 int spec_unsigned = 0;
4050 int spec_long = 0;
4051 int spec_long_long = 0;
4052 int spec_imag = 0;
4053 int warn = 0;
4054 int i;
4056 while (1)
4058 if (c == 'u' || c == 'U')
4060 if (spec_unsigned)
4061 error ("two `u's in integer constant");
4062 spec_unsigned = 1;
4064 else if (c == 'l' || c == 'L')
4066 if (spec_long)
4068 if (spec_long_long)
4069 error ("three `l's in integer constant");
4070 else if (pedantic && ! in_system_header && warn_long_long)
4071 pedwarn ("ANSI C++ forbids long long integer constants");
4072 spec_long_long = 1;
4074 spec_long = 1;
4076 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
4078 if (spec_imag)
4079 error ("more than one `i' or `j' in numeric constant");
4080 else if (pedantic)
4081 pedwarn ("ANSI C++ forbids imaginary numeric constants");
4082 spec_imag = 1;
4084 else
4085 break;
4086 if (p >= token_buffer + maxtoken - 3)
4087 p = extend_token_buffer (p);
4088 *p++ = c;
4089 c = token_getch ();
4092 /* If the literal overflowed, pedwarn about it now. */
4093 if (overflow)
4095 warn = 1;
4096 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
4099 /* This is simplified by the fact that our constant
4100 is always positive. */
4102 high = low = 0;
4104 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
4106 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
4107 / HOST_BITS_PER_CHAR)]
4108 << (i * HOST_BITS_PER_CHAR));
4109 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
4112 yylval.ttype = build_int_2 (low, high);
4113 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
4115 /* Calculate the ANSI type. */
4116 if (! spec_long && ! spec_unsigned
4117 && int_fits_type_p (yylval.ttype, integer_type_node))
4118 type = integer_type_node;
4119 else if (! spec_long && (base != 10 || spec_unsigned)
4120 && int_fits_type_p (yylval.ttype, unsigned_type_node))
4121 type = unsigned_type_node;
4122 else if (! spec_unsigned && !spec_long_long
4123 && int_fits_type_p (yylval.ttype, long_integer_type_node))
4124 type = long_integer_type_node;
4125 else if (! spec_long_long
4126 && int_fits_type_p (yylval.ttype,
4127 long_unsigned_type_node))
4128 type = long_unsigned_type_node;
4129 else if (! spec_unsigned
4130 && int_fits_type_p (yylval.ttype,
4131 long_long_integer_type_node))
4132 type = long_long_integer_type_node;
4133 else if (int_fits_type_p (yylval.ttype,
4134 long_long_unsigned_type_node))
4135 type = long_long_unsigned_type_node;
4136 else if (! spec_unsigned
4137 && int_fits_type_p (yylval.ttype,
4138 widest_integer_literal_type_node))
4139 type = widest_integer_literal_type_node;
4140 else
4141 type = widest_unsigned_literal_type_node;
4143 if (pedantic && !spec_long_long && !warn
4144 && (TYPE_PRECISION (long_integer_type_node)
4145 < TYPE_PRECISION (type)))
4147 warn = 1;
4148 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
4151 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
4152 warning ("decimal constant is so large that it is unsigned");
4154 if (spec_imag)
4156 if (TYPE_PRECISION (type)
4157 <= TYPE_PRECISION (integer_type_node))
4158 yylval.ttype
4159 = build_complex (NULL_TREE, integer_zero_node,
4160 convert (integer_type_node,
4161 yylval.ttype));
4162 else
4163 error ("complex integer constant is too wide for `__complex int'");
4165 else
4166 TREE_TYPE (yylval.ttype) = type;
4169 /* If it's still an integer (not a complex), and it doesn't
4170 fit in the type we choose for it, then pedwarn. */
4172 if (! warn
4173 && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
4174 && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
4175 pedwarn ("integer constant is larger than the maximum value for its type");
4178 token_put_back (c);
4179 *p = 0;
4181 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
4182 || ((c == '-' || c == '+')
4183 && (p[-1] == 'e' || p[-1] == 'E')))
4184 error ("missing white space after number `%s'", token_buffer);
4186 value = CONSTANT; break;
4189 case '\'':
4190 char_constant:
4192 register int result = 0;
4193 register int num_chars = 0;
4194 int chars_seen = 0;
4195 unsigned width = TYPE_PRECISION (char_type_node);
4196 int max_chars;
4197 #ifdef MULTIBYTE_CHARS
4198 int longest_char = local_mb_cur_max ();
4199 local_mbtowc (NULL_PTR, NULL_PTR, 0);
4200 #endif
4202 max_chars = TYPE_PRECISION (integer_type_node) / width;
4203 if (wide_flag)
4204 width = WCHAR_TYPE_SIZE;
4206 while (1)
4208 tryagain:
4209 c = token_getch ();
4211 if (c == '\'' || c == EOF)
4212 break;
4214 ++chars_seen;
4215 if (c == '\\')
4217 int ignore = 0;
4218 c = readescape (&ignore);
4219 if (ignore)
4220 goto tryagain;
4221 if (width < HOST_BITS_PER_INT
4222 && (unsigned) c >= ((unsigned)1 << width))
4223 pedwarn ("escape sequence out of range for character");
4224 #ifdef MAP_CHARACTER
4225 if (ISPRINT (c))
4226 c = MAP_CHARACTER (c);
4227 #endif
4229 else if (c == '\n')
4231 if (pedantic)
4232 pedwarn ("ANSI C forbids newline in character constant");
4233 lineno++;
4235 else
4237 #ifdef MULTIBYTE_CHARS
4238 wchar_t wc;
4239 int i;
4240 int char_len = -1;
4241 for (i = 1; i <= longest_char; ++i)
4243 if (i > maxtoken - 4)
4244 extend_token_buffer (token_buffer);
4246 token_buffer[i] = c;
4247 char_len = local_mbtowc (& wc,
4248 token_buffer + 1,
4250 if (char_len != -1)
4251 break;
4252 c = token_getch ();
4254 if (char_len > 1)
4256 /* mbtowc sometimes needs an extra char before accepting */
4257 if (char_len < i)
4258 token_put_back (c);
4259 if (! wide_flag)
4261 /* Merge character into result; ignore excess chars. */
4262 for (i = 1; i <= char_len; ++i)
4264 if (i > max_chars)
4265 break;
4266 if (width < HOST_BITS_PER_INT)
4267 result = (result << width)
4268 | (token_buffer[i]
4269 & ((1 << width) - 1));
4270 else
4271 result = token_buffer[i];
4273 num_chars += char_len;
4274 goto tryagain;
4276 c = wc;
4278 else
4280 if (char_len == -1)
4282 warning ("Ignoring invalid multibyte character");
4283 /* Replace all but the first byte. */
4284 for (--i; i > 1; --i)
4285 token_put_back (token_buffer[i]);
4286 wc = token_buffer[1];
4288 #ifdef MAP_CHARACTER
4289 c = MAP_CHARACTER (wc);
4290 #else
4291 c = wc;
4292 #endif
4294 #else /* ! MULTIBYTE_CHARS */
4295 #ifdef MAP_CHARACTER
4296 c = MAP_CHARACTER (c);
4297 #endif
4298 #endif /* ! MULTIBYTE_CHARS */
4301 if (wide_flag)
4303 if (chars_seen == 1) /* only keep the first one */
4304 result = c;
4305 goto tryagain;
4308 /* Merge character into result; ignore excess chars. */
4309 num_chars += (width / TYPE_PRECISION (char_type_node));
4310 if (num_chars < max_chars + 1)
4312 if (width < HOST_BITS_PER_INT)
4313 result = (result << width) | (c & ((1 << width) - 1));
4314 else
4315 result = c;
4319 if (c != '\'')
4320 error ("malformatted character constant");
4321 else if (chars_seen == 0)
4322 error ("empty character constant");
4323 else if (num_chars > max_chars)
4325 num_chars = max_chars;
4326 error ("character constant too long");
4328 else if (chars_seen != 1 && warn_multichar)
4329 warning ("multi-character character constant");
4331 /* If char type is signed, sign-extend the constant. */
4332 if (! wide_flag)
4334 int num_bits = num_chars * width;
4335 if (num_bits == 0)
4336 /* We already got an error; avoid invalid shift. */
4337 yylval.ttype = build_int_2 (0, 0);
4338 else if (TREE_UNSIGNED (char_type_node)
4339 || ((result >> (num_bits - 1)) & 1) == 0)
4340 yylval.ttype
4341 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
4342 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4344 else
4345 yylval.ttype
4346 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
4347 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4348 -1);
4349 /* In C, a character constant has type 'int'; in C++, 'char'. */
4350 if (chars_seen <= 1)
4351 TREE_TYPE (yylval.ttype) = char_type_node;
4352 else
4353 TREE_TYPE (yylval.ttype) = integer_type_node;
4355 else
4357 yylval.ttype = build_int_2 (result, 0);
4358 TREE_TYPE (yylval.ttype) = wchar_type_node;
4361 value = CONSTANT;
4362 break;
4365 case '"':
4366 string_constant:
4368 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
4369 : TYPE_PRECISION (char_type_node);
4370 #ifdef MULTIBYTE_CHARS
4371 int longest_char = local_mb_cur_max ();
4372 local_mbtowc (NULL_PTR, NULL_PTR, 0);
4373 #endif
4375 c = token_getch ();
4376 p = token_buffer + 1;
4378 while (c != '"' && c != EOF)
4380 /* ignore_escape_flag is set for reading the filename in #line. */
4381 if (!ignore_escape_flag && c == '\\')
4383 int ignore = 0;
4384 c = readescape (&ignore);
4385 if (ignore)
4386 goto skipnewline;
4387 if (width < HOST_BITS_PER_INT
4388 && (unsigned) c >= ((unsigned)1 << width))
4389 pedwarn ("escape sequence out of range for character");
4391 else if (c == '\n')
4393 if (pedantic)
4394 pedwarn ("ANSI C++ forbids newline in string constant");
4395 lineno++;
4397 else
4399 #ifdef MULTIBYTE_CHARS
4400 wchar_t wc;
4401 int i;
4402 int char_len = -1;
4403 for (i = 0; i < longest_char; ++i)
4405 if (p + i >= token_buffer + maxtoken)
4406 p = extend_token_buffer (p);
4407 p[i] = c;
4409 char_len = local_mbtowc (& wc, p, i + 1);
4410 if (char_len != -1)
4411 break;
4412 c = token_getch ();
4414 if (char_len == -1)
4416 warning ("Ignoring invalid multibyte character");
4417 /* Replace all except the first byte. */
4418 token_put_back (c);
4419 for (--i; i > 0; --i)
4420 token_put_back (p[i]);
4421 char_len = 1;
4423 /* mbtowc sometimes needs an extra char before accepting */
4424 if (char_len <= i)
4425 token_put_back (c);
4426 if (! wide_flag)
4428 p += (i + 1);
4429 c = token_getch ();
4430 continue;
4432 c = wc;
4433 #endif /* MULTIBYTE_CHARS */
4436 /* Add this single character into the buffer either as a wchar_t
4437 or as a single byte. */
4438 if (wide_flag)
4440 unsigned width = TYPE_PRECISION (char_type_node);
4441 unsigned bytemask = (1 << width) - 1;
4442 int byte;
4444 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4445 p = extend_token_buffer (p);
4447 for (byte = 0; byte < WCHAR_BYTES; ++byte)
4449 int value;
4450 if (byte >= (int) sizeof (c))
4451 value = 0;
4452 else
4453 value = (c >> (byte * width)) & bytemask;
4454 if (BYTES_BIG_ENDIAN)
4455 p[WCHAR_BYTES - byte - 1] = value;
4456 else
4457 p[byte] = value;
4459 p += WCHAR_BYTES;
4461 else
4463 if (p >= token_buffer + maxtoken)
4464 p = extend_token_buffer (p);
4465 *p++ = c;
4468 skipnewline:
4469 c = token_getch ();
4472 /* Terminate the string value, either with a single byte zero
4473 or with a wide zero. */
4474 if (wide_flag)
4476 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4477 p = extend_token_buffer (p);
4478 bzero (p, WCHAR_BYTES);
4479 p += WCHAR_BYTES;
4481 else
4483 if (p >= token_buffer + maxtoken)
4484 p = extend_token_buffer (p);
4485 *p++ = 0;
4488 if (c == EOF)
4489 error ("Unterminated string constant");
4491 /* We have read the entire constant.
4492 Construct a STRING_CST for the result. */
4494 if (processing_template_decl)
4495 push_obstacks (&permanent_obstack, &permanent_obstack);
4496 yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1);
4497 if (processing_template_decl)
4498 pop_obstacks ();
4500 if (wide_flag)
4501 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
4502 else
4503 TREE_TYPE (yylval.ttype) = char_array_type_node;
4505 value = STRING; break;
4508 case '+':
4509 case '-':
4510 case '&':
4511 case '|':
4512 case ':':
4513 case '<':
4514 case '>':
4515 case '*':
4516 case '/':
4517 case '%':
4518 case '^':
4519 case '!':
4520 case '=':
4522 register int c1;
4524 combine:
4526 switch (c)
4528 case '+':
4529 yylval.code = PLUS_EXPR; break;
4530 case '-':
4531 yylval.code = MINUS_EXPR; break;
4532 case '&':
4533 yylval.code = BIT_AND_EXPR; break;
4534 case '|':
4535 yylval.code = BIT_IOR_EXPR; break;
4536 case '*':
4537 yylval.code = MULT_EXPR; break;
4538 case '/':
4539 yylval.code = TRUNC_DIV_EXPR; break;
4540 case '%':
4541 yylval.code = TRUNC_MOD_EXPR; break;
4542 case '^':
4543 yylval.code = BIT_XOR_EXPR; break;
4544 case LSHIFT:
4545 yylval.code = LSHIFT_EXPR; break;
4546 case RSHIFT:
4547 yylval.code = RSHIFT_EXPR; break;
4548 case '<':
4549 yylval.code = LT_EXPR; break;
4550 case '>':
4551 yylval.code = GT_EXPR; break;
4554 token_buffer[1] = c1 = token_getch ();
4555 token_buffer[2] = 0;
4557 if (c1 == '=')
4559 switch (c)
4561 case '<':
4562 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
4563 case '>':
4564 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
4565 case '!':
4566 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
4567 case '=':
4568 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
4570 value = ASSIGN; goto done;
4572 else if (c == c1)
4573 switch (c)
4575 case '+':
4576 value = PLUSPLUS; goto done;
4577 case '-':
4578 value = MINUSMINUS; goto done;
4579 case '&':
4580 value = ANDAND; goto done;
4581 case '|':
4582 value = OROR; goto done;
4583 case '<':
4584 c = LSHIFT;
4585 goto combine;
4586 case '>':
4587 c = RSHIFT;
4588 goto combine;
4589 case ':':
4590 value = SCOPE;
4591 yylval.itype = 1;
4592 goto done;
4594 else if (c1 == '?' && (c == '<' || c == '>'))
4596 token_buffer[3] = 0;
4598 c1 = token_getch ();
4599 yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR);
4600 if (c1 == '=')
4602 /* <?= or >?= expression. */
4603 token_buffer[2] = c1;
4604 value = ASSIGN;
4606 else
4608 value = MIN_MAX;
4609 token_put_back (c1);
4611 if (pedantic)
4612 pedwarn ("use of `operator %s' is not standard C++",
4613 token_buffer);
4614 goto done;
4616 else
4617 switch (c)
4619 case '-':
4620 if (c1 == '>')
4622 c1 = token_getch ();
4623 if (c1 == '*')
4624 value = POINTSAT_STAR;
4625 else
4627 token_put_back (c1);
4628 value = POINTSAT;
4630 goto done;
4632 break;
4634 /* digraphs */
4635 case ':':
4636 if (c1 == '>')
4637 { value = ']'; goto done; }
4638 break;
4639 case '<':
4640 if (c1 == '%')
4641 { value = '{'; indent_level++; goto done; }
4642 if (c1 == ':')
4643 { value = '['; goto done; }
4644 break;
4645 case '%':
4646 if (c1 == '>')
4647 { value = '}'; indent_level--; goto done; }
4648 break;
4651 token_put_back (c1);
4652 token_buffer[1] = 0;
4654 /* Here the C frontend changes < and > to ARITHCOMPARE. We don't
4655 do that because of templates. */
4657 value = c;
4658 break;
4661 case 0:
4662 /* Don't make yyparse think this is eof. */
4663 value = 1;
4664 break;
4666 case '{':
4667 indent_level++;
4668 value = c;
4669 break;
4671 case '}':
4672 indent_level--;
4673 value = c;
4674 break;
4676 default:
4677 value = c;
4680 done:
4681 /* yylloc.last_line = lineno; */
4682 #ifdef GATHER_STATISTICS
4683 #ifdef REDUCE_LENGTH
4684 token_count[value] += 1;
4685 #endif
4686 #endif
4688 return value;
4692 is_rid (t)
4693 tree t;
4695 return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
4698 #ifdef GATHER_STATISTICS
4699 /* The original for tree_node_kind is in the toplevel tree.c; changes there
4700 need to be brought into here, unless this were actually put into a header
4701 instead. */
4702 /* Statistics-gathering stuff. */
4703 typedef enum
4705 d_kind,
4706 t_kind,
4707 b_kind,
4708 s_kind,
4709 r_kind,
4710 e_kind,
4711 c_kind,
4712 id_kind,
4713 op_id_kind,
4714 perm_list_kind,
4715 temp_list_kind,
4716 vec_kind,
4717 x_kind,
4718 lang_decl,
4719 lang_type,
4720 all_kinds
4721 } tree_node_kind;
4723 extern int tree_node_counts[];
4724 extern int tree_node_sizes[];
4725 #endif
4727 tree
4728 build_lang_decl (code, name, type)
4729 enum tree_code code;
4730 tree name;
4731 tree type;
4733 tree t;
4735 t = build_decl (code, name, type);
4736 retrofit_lang_decl (t);
4738 return t;
4741 /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
4742 and pushdecl (for functions generated by the backend). */
4744 void
4745 retrofit_lang_decl (t)
4746 tree t;
4748 struct lang_decl *ld;
4749 size_t size;
4751 if (CAN_HAVE_FULL_LANG_DECL_P (t))
4752 size = sizeof (struct lang_decl);
4753 else
4754 size = sizeof (struct lang_decl_flags);
4756 ld = (struct lang_decl *) ggc_alloc (size);
4757 memset (ld, 0, size);
4759 DECL_LANG_SPECIFIC (t) = ld;
4760 if (current_lang_name == lang_name_cplusplus)
4761 DECL_LANGUAGE (t) = lang_cplusplus;
4762 else if (current_lang_name == lang_name_c)
4763 DECL_LANGUAGE (t) = lang_c;
4764 else if (current_lang_name == lang_name_java)
4765 DECL_LANGUAGE (t) = lang_java;
4766 else my_friendly_abort (64);
4768 if (CAN_HAVE_FULL_LANG_DECL_P (t))
4769 DECL_MAIN_VARIANT (t) = t;
4771 #ifdef GATHER_STATISTICS
4772 tree_node_counts[(int)lang_decl] += 1;
4773 tree_node_sizes[(int)lang_decl] += size;
4774 #endif
4777 void
4778 copy_lang_decl (node)
4779 tree node;
4781 int size;
4782 struct lang_decl *ld;
4784 if (! DECL_LANG_SPECIFIC (node))
4785 return;
4787 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
4788 size = sizeof (struct lang_decl_flags);
4789 else
4790 size = sizeof (struct lang_decl);
4791 ld = (struct lang_decl *) ggc_alloc (size);
4792 bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)ld, size);
4793 DECL_LANG_SPECIFIC (node) = ld;
4796 tree
4797 cp_make_lang_type (code)
4798 enum tree_code code;
4800 register tree t = make_node (code);
4802 /* Set up some flags that give proper default behavior. */
4803 if (IS_AGGR_TYPE_CODE (code))
4805 struct lang_type *pi;
4807 SET_IS_AGGR_TYPE (t, 1);
4809 pi = (struct lang_type *) ggc_alloc (sizeof (struct lang_type));
4810 bzero ((char *) pi, (int) sizeof (struct lang_type));
4812 TYPE_LANG_SPECIFIC (t) = pi;
4813 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
4814 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
4816 /* Make sure this is laid out, for ease of use later. In the
4817 presence of parse errors, the normal was of assuring this
4818 might not ever get executed, so we lay it out *immediately*. */
4819 build_pointer_type (t);
4821 #ifdef GATHER_STATISTICS
4822 tree_node_counts[(int)lang_type] += 1;
4823 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
4824 #endif
4826 else
4827 /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
4828 TYPE_ALIAS_SET is initialized to -1 by default, so we must
4829 clear it here. */
4830 TYPE_ALIAS_SET (t) = 0;
4832 /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
4833 since they can be virtual base types, and we then need a
4834 canonical binfo for them. Ideally, this would be done lazily for
4835 all types. */
4836 if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM)
4837 TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE);
4839 return t;
4842 void
4843 dump_time_statistics ()
4845 register tree prev = 0, decl, next;
4846 int this_time = my_get_run_time ();
4847 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
4848 += this_time - body_time;
4850 fprintf (stderr, "\n******\n");
4851 print_time ("header files (total)", header_time);
4852 print_time ("main file (total)", this_time - body_time);
4853 fprintf (stderr, "ratio = %g : 1\n",
4854 (double)header_time / (double)(this_time - body_time));
4855 fprintf (stderr, "\n******\n");
4857 for (decl = filename_times; decl; decl = next)
4859 next = IDENTIFIER_GLOBAL_VALUE (decl);
4860 SET_IDENTIFIER_GLOBAL_VALUE (decl, prev);
4861 prev = decl;
4864 for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl))
4865 print_time (IDENTIFIER_POINTER (decl),
4866 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (decl)));
4869 void
4870 compiler_error VPROTO ((const char *msg, ...))
4872 #ifndef ANSI_PROTOTYPES
4873 const char *msg;
4874 #endif
4875 char buf[1024];
4876 va_list ap;
4878 VA_START (ap, msg);
4880 #ifndef ANSI_PROTOTYPES
4881 msg = va_arg (ap, const char *);
4882 #endif
4884 vsprintf (buf, msg, ap);
4885 va_end (ap);
4886 error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
4889 /* Return the type-qualifier corresponding to the identifier given by
4890 RID. */
4893 cp_type_qual_from_rid (rid)
4894 tree rid;
4896 if (rid == ridpointers[(int) RID_CONST])
4897 return TYPE_QUAL_CONST;
4898 else if (rid == ridpointers[(int) RID_VOLATILE])
4899 return TYPE_QUAL_VOLATILE;
4900 else if (rid == ridpointers[(int) RID_RESTRICT])
4901 return TYPE_QUAL_RESTRICT;
4903 my_friendly_abort (0);
4904 return TYPE_UNQUALIFIED;