Use -static when testing --gc-sections on native targets
[official-gcc.git] / gcc / cp / lex.c
blobcedb837df7d4631fd192b0a8c06d9ecbe42784d6
1 /* Separate lexical analyzer for GNU C++.
2 Copyright (C) 1987, 89, 92-99, 2000 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"
41 #include "tm_p.h"
43 #ifdef MULTIBYTE_CHARS
44 #include "mbchar.h"
45 #include <locale.h>
46 #endif
48 #define obstack_chunk_alloc xmalloc
49 #define obstack_chunk_free free
51 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
53 static tree get_time_identifier PARAMS ((const char *));
54 static int check_newline PARAMS ((void));
55 static int whitespace_cr PARAMS ((int));
56 static int skip_white_space PARAMS ((int));
57 static void finish_defarg PARAMS ((void));
58 static int my_get_run_time PARAMS ((void));
59 static int interface_strcmp PARAMS ((const char *));
60 static int readescape PARAMS ((int *));
61 static char *extend_token_buffer PARAMS ((const char *));
62 static void consume_string PARAMS ((struct obstack *, int));
63 static void feed_defarg PARAMS ((tree, tree));
64 static void store_pending_inline PARAMS ((tree, struct pending_inline *));
65 static void reinit_parse_for_expr PARAMS ((struct obstack *));
66 static int *init_cpp_parse PARAMS ((void));
67 static void cp_pragma_interface PARAMS ((char *));
68 static void cp_pragma_implementation PARAMS ((char *));
69 static int handle_cp_pragma PARAMS ((const char *));
70 #ifdef HANDLE_GENERIC_PRAGMAS
71 static int handle_generic_pragma PARAMS ((int));
72 #endif
73 #ifdef GATHER_STATISTICS
74 #ifdef REDUCE_LENGTH
75 static int reduce_cmp PARAMS ((int *, int *));
76 static int token_cmp PARAMS ((int *, int *));
77 #endif
78 #endif
79 static void begin_definition_of_inclass_inline PARAMS ((struct pending_inline*));
80 static void parse_float PARAMS ((PTR));
81 static int is_global PARAMS ((tree));
82 static void init_filename_times PARAMS ((void));
83 static void extend_token_buffer_to PARAMS ((int));
84 #ifdef HANDLE_PRAGMA
85 static int pragma_getc PARAMS ((void));
86 static void pragma_ungetc PARAMS ((int));
87 #endif
88 static int read_line_number PARAMS ((int *));
89 static int token_getch PARAMS ((void));
90 static void token_put_back PARAMS ((int));
91 static void mark_impl_file_chain PARAMS ((void *));
93 /* Given a file name X, return the nondirectory portion.
94 Keep in mind that X can be computed more than once. */
95 char *
96 file_name_nondirectory (x)
97 const char *x;
99 char *tmp = (char *) rindex (x, '/');
100 if (DIR_SEPARATOR != '/' && ! tmp)
101 tmp = (char *) rindex (x, DIR_SEPARATOR);
102 if (tmp)
103 return (char *) (tmp + 1);
104 else
105 return (char *) x;
108 /* This obstack is needed to hold text. It is not safe to use
109 TOKEN_BUFFER because `check_newline' calls `yylex'. */
110 struct obstack inline_text_obstack;
111 char *inline_text_firstobj;
113 /* Nonzero if parse output is being saved to an obstack for later parsing. */
114 static int saving_parse_to_obstack = 0;
116 #if USE_CPPLIB
117 #include "cpplib.h"
118 extern cpp_reader parse_in;
119 extern cpp_options parse_options;
120 extern unsigned char *yy_cur, *yy_lim;
121 extern enum cpp_token cpp_token;
122 #else
123 FILE *finput;
124 #endif
125 int end_of_file;
127 int linemode;
129 /* Pending language change.
130 Positive is push count, negative is pop count. */
131 int pending_lang_change = 0;
133 /* Wrap the current header file in extern "C". */
134 static int c_header_level = 0;
136 extern int first_token;
137 extern struct obstack token_obstack;
139 /* ??? Don't really know where this goes yet. */
140 #include "input.c"
142 /* Holds translations from TREE_CODEs to operator name strings,
143 i.e., opname_tab[PLUS_EXPR] == "+". */
144 const char **opname_tab;
145 const char **assignop_tab;
147 extern int yychar; /* the lookahead symbol */
148 extern YYSTYPE yylval; /* the semantic value of the */
149 /* lookahead symbol */
151 #if 0
152 YYLTYPE yylloc; /* location data for the lookahead */
153 /* symbol */
154 #endif
157 /* the declaration found for the last IDENTIFIER token read in.
158 yylex must look this up to detect typedefs, which get token type TYPENAME,
159 so it is left around in case the identifier is not a typedef but is
160 used in a context which makes it a reference to a variable. */
161 tree lastiddecl;
163 /* The elements of `ridpointers' are identifier nodes
164 for the reserved type names and storage classes.
165 It is indexed by a RID_... value. */
166 tree ridpointers[(int) RID_MAX];
168 /* We may keep statistics about how long which files took to compile. */
169 static int header_time, body_time;
170 static tree filename_times;
171 static tree this_filename_time;
173 /* Array for holding counts of the numbers of tokens seen. */
174 extern int *token_count;
176 /* When we see a default argument in a method declaration, we snarf it as
177 text using snarf_defarg. When we get up to namespace scope, we then go
178 through and parse all of them using do_pending_defargs. Since yacc
179 parsers are not reentrant, we retain defargs state in these two
180 variables so that subsequent calls to do_pending_defargs can resume
181 where the previous call left off. */
183 static tree defarg_fns;
184 static tree defarg_parm;
186 /* Functions and data structures for #pragma interface.
188 `#pragma implementation' means that the main file being compiled
189 is considered to implement (provide) the classes that appear in
190 its main body. I.e., if this is file "foo.cc", and class `bar'
191 is defined in "foo.cc", then we say that "foo.cc implements bar".
193 All main input files "implement" themselves automagically.
195 `#pragma interface' means that unless this file (of the form "foo.h"
196 is not presently being included by file "foo.cc", the
197 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
198 of the vtables nor any of the inline functions defined in foo.h
199 will ever be output.
201 There are cases when we want to link files such as "defs.h" and
202 "main.cc". In this case, we give "defs.h" a `#pragma interface',
203 and "main.cc" has `#pragma implementation "defs.h"'. */
205 struct impl_files
207 char *filename;
208 struct impl_files *next;
211 static struct impl_files *impl_file_chain;
213 /* The string used to represent the filename of internally generated
214 tree nodes. The variable, which is dynamically allocated, should
215 be used; the macro is only used to initialize it. */
216 static char *internal_filename;
217 #define INTERNAL_FILENAME ("<internal>")
219 /* Return something to represent absolute declarators containing a *.
220 TARGET is the absolute declarator that the * contains.
221 CV_QUALIFIERS is a list of modifiers such as const or volatile
222 to apply to the pointer type, represented as identifiers.
224 We return an INDIRECT_REF whose "contents" are TARGET
225 and whose type is the modifier list. */
227 tree
228 make_pointer_declarator (cv_qualifiers, target)
229 tree cv_qualifiers, target;
231 if (target && TREE_CODE (target) == IDENTIFIER_NODE
232 && ANON_AGGRNAME_P (target))
233 error ("type name expected before `*'");
234 target = build_parse_node (INDIRECT_REF, target);
235 TREE_TYPE (target) = cv_qualifiers;
236 return target;
239 /* Return something to represent absolute declarators containing a &.
240 TARGET is the absolute declarator that the & contains.
241 CV_QUALIFIERS is a list of modifiers such as const or volatile
242 to apply to the reference type, represented as identifiers.
244 We return an ADDR_EXPR whose "contents" are TARGET
245 and whose type is the modifier list. */
247 tree
248 make_reference_declarator (cv_qualifiers, target)
249 tree cv_qualifiers, target;
251 if (target)
253 if (TREE_CODE (target) == ADDR_EXPR)
255 error ("cannot declare references to references");
256 return target;
258 if (TREE_CODE (target) == INDIRECT_REF)
260 error ("cannot declare pointers to references");
261 return target;
263 if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
264 error ("type name expected before `&'");
266 target = build_parse_node (ADDR_EXPR, target);
267 TREE_TYPE (target) = cv_qualifiers;
268 return target;
271 tree
272 make_call_declarator (target, parms, cv_qualifiers, exception_specification)
273 tree target, parms, cv_qualifiers, exception_specification;
275 target = build_parse_node (CALL_EXPR, target,
276 /* Both build_parse_node and
277 decl_tree_cons build on the
278 temp_decl_obstack. */
279 decl_tree_cons (parms, cv_qualifiers, NULL_TREE),
280 /* The third operand is really RTL. We
281 shouldn't put anything there. */
282 NULL_TREE);
283 CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification;
284 return target;
287 void
288 set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
289 tree call_declarator, cv_qualifiers, exception_specification;
291 CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers;
292 CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification;
295 /* Build names and nodes for overloaded operators. */
297 tree ansi_opname[LAST_CPLUS_TREE_CODE];
298 tree ansi_assopname[LAST_CPLUS_TREE_CODE];
300 const char *
301 operator_name_string (name)
302 tree name;
304 char *opname = IDENTIFIER_POINTER (name) + 2;
305 tree *opname_table;
306 int i, assign;
308 /* Works for builtin and user defined types. */
309 if (IDENTIFIER_GLOBAL_VALUE (name)
310 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL)
311 return IDENTIFIER_POINTER (name);
313 if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_')
315 opname += 1;
316 assign = 1;
317 opname_table = ansi_assopname;
319 else
321 assign = 0;
322 opname_table = ansi_opname;
325 for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
327 if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign]
328 && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign])
329 break;
332 if (i == LAST_CPLUS_TREE_CODE)
333 return "<invalid operator>";
335 if (assign)
336 return assignop_tab[i];
337 else
338 return opname_tab[i];
341 int interface_only; /* whether or not current file is only for
342 interface definitions. */
343 int interface_unknown; /* whether or not we know this class
344 to behave according to #pragma interface. */
346 /* lexical analyzer */
348 #undef WCHAR_TYPE_SIZE
349 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
351 /* Number of bytes in a wide character. */
352 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
354 static int maxtoken; /* Current nominal length of token buffer. */
355 char *token_buffer; /* Pointer to token buffer.
356 Actual allocated length is maxtoken + 2. */
358 static int indent_level; /* Number of { minus number of }. */
360 #include "hash.h"
363 /* Nonzero tells yylex to ignore \ in string constants. */
364 static int ignore_escape_flag;
366 static tree
367 get_time_identifier (name)
368 const char *name;
370 tree time_identifier;
371 int len = strlen (name);
372 char *buf = (char *) alloca (len + 6);
373 strcpy (buf, "file ");
374 bcopy (name, buf+5, len);
375 buf[len+5] = '\0';
376 time_identifier = get_identifier (buf);
377 if (TIME_IDENTIFIER_TIME (time_identifier) == NULL_TREE)
379 TIME_IDENTIFIER_TIME (time_identifier) = build_int_2 (0, 0);
380 TIME_IDENTIFIER_FILEINFO (time_identifier)
381 = build_int_2 (0, 1);
382 SET_IDENTIFIER_GLOBAL_VALUE (time_identifier, filename_times);
383 filename_times = time_identifier;
385 return time_identifier;
388 static inline int
389 my_get_run_time ()
391 int old_quiet_flag = quiet_flag;
392 int this_time;
393 quiet_flag = 0;
394 this_time = get_run_time ();
395 quiet_flag = old_quiet_flag;
396 return this_time;
399 /* Table indexed by tree code giving a string containing a character
400 classifying the tree code. Possibilities are
401 t, d, s, c, r, <, 1 and 2. See cp/cp-tree.def for details. */
403 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
405 static char cplus_tree_code_type[] = {
406 'x',
407 #include "cp-tree.def"
409 #undef DEFTREECODE
411 /* Table indexed by tree code giving number of expression
412 operands beyond the fixed part of the node structure.
413 Not used for types or decls. */
415 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
417 static int cplus_tree_code_length[] = {
419 #include "cp-tree.def"
421 #undef DEFTREECODE
423 /* Names of tree components.
424 Used for printing out the tree and error messages. */
425 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
427 static const char *cplus_tree_code_name[] = {
428 "@@dummy",
429 #include "cp-tree.def"
431 #undef DEFTREECODE
433 /* toplev.c needs to call these. */
435 void
436 lang_init_options ()
438 #if USE_CPPLIB
439 cpp_reader_init (&parse_in);
440 parse_in.opts = &parse_options;
441 cpp_options_init (&parse_options);
442 parse_options.cplusplus = 1;
443 #endif
445 /* Default exceptions on. */
446 flag_exceptions = 1;
447 /* Mark as "unspecified". */
448 flag_bounds_check = -1;
451 void
452 lang_init ()
454 /* If still "unspecified", make it match -fbounded-pointers. */
455 if (flag_bounds_check < 0)
456 flag_bounds_check = flag_bounded_pointers;
458 /* the beginning of the file is a new line; check for # */
459 /* With luck, we discover the real source file's name from that
460 and put it in input_filename. */
461 put_back (check_newline ());
462 if (flag_gnu_xref) GNU_xref_begin (input_filename);
463 init_repo (input_filename);
466 void
467 lang_finish ()
469 if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount);
472 const char *
473 lang_identify ()
475 return "cplusplus";
478 static void
479 init_filename_times ()
481 this_filename_time = get_time_identifier ("<top level>");
482 if (flag_detailed_statistics)
484 header_time = 0;
485 body_time = my_get_run_time ();
486 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
487 = body_time;
491 /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
492 Stuck this hack in to get the files open correctly; this is called
493 in place of init_parse if we are an unexec'd binary. */
495 #if 0
496 void
497 reinit_lang_specific ()
499 init_filename_times ();
500 reinit_search_statistics ();
502 #endif
504 static int *
505 init_cpp_parse ()
507 #ifdef GATHER_STATISTICS
508 #ifdef REDUCE_LENGTH
509 reduce_count = (int *) xcalloc (sizeof (int), (REDUCE_LENGTH + 1));
510 reduce_count += 1;
511 token_count = (int *) xcalloc (sizeof (int), (TOKEN_LENGTH + 1));
512 token_count += 1;
513 #endif
514 #endif
515 return token_count;
518 char *
519 init_parse (filename)
520 char *filename;
522 extern int flag_no_gnu_keywords;
523 extern int flag_operator_names;
525 int i;
527 #ifdef MULTIBYTE_CHARS
528 /* Change to the native locale for multibyte conversions. */
529 setlocale (LC_CTYPE, "");
530 literal_codeset = getenv ("LANG");
531 #endif
533 #if !USE_CPPLIB
534 /* Open input file. */
535 if (filename == 0 || !strcmp (filename, "-"))
537 finput = stdin;
538 filename = "stdin";
540 else
541 finput = fopen (filename, "r");
542 if (finput == 0)
543 pfatal_with_name (filename);
545 #ifdef IO_BUFFER_SIZE
546 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
547 #endif
548 #else /* !USE_CPPLIB */
549 parse_in.show_column = 1;
550 if (! cpp_start_read (&parse_in, filename))
551 abort ();
553 if (filename == 0 || !strcmp (filename, "-"))
554 filename = "stdin";
556 /* cpp_start_read always puts at least one line directive into the
557 token buffer. We must arrange to read it out here. */
558 yy_cur = parse_in.token_buffer;
559 yy_lim = CPP_PWRITTEN (&parse_in);
560 cpp_token = CPP_DIRECTIVE;
562 #endif /* !USE_CPPLIB */
564 /* Initialize the lookahead machinery. */
565 init_spew ();
567 /* Make identifier nodes long enough for the language-specific slots. */
568 set_identifier_size (sizeof (struct lang_identifier));
569 decl_printable_name = lang_printable_name;
571 init_tree ();
572 init_cplus_expand ();
574 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
575 cplus_tree_code_type,
576 (int)LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
577 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
578 cplus_tree_code_length,
579 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
580 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
581 cplus_tree_code_name,
582 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
584 opname_tab = (const char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
585 memset (opname_tab, 0, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
586 assignop_tab = (const char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
587 memset (assignop_tab, 0, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
589 ansi_opname[0] = get_identifier ("<invalid operator>");
590 for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
592 ansi_opname[i] = ansi_opname[0];
593 ansi_assopname[i] = ansi_opname[0];
596 ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml");
597 IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1;
598 ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR];
599 ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml");
600 IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1;
601 ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR];
602 ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md");
603 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1;
604 ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd");
605 IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1;
606 ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
607 ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
608 ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
609 ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi");
610 IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1;
611 ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR];
612 ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami");
613 IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1;
614 ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR];
615 ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs");
616 IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1;
617 ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars");
618 IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1;
619 ansi_opname[(int) NE_EXPR] = get_identifier ("__ne");
620 IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1;
621 ansi_opname[(int) GT_EXPR] = get_identifier ("__gt");
622 IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1;
623 ansi_opname[(int) GE_EXPR] = get_identifier ("__ge");
624 IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1;
625 ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or");
626 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1;
627 ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor");
628 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1;
629 ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa");
630 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1;
631 ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt");
632 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1;
633 ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp");
634 IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1;
635 ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR];
636 ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as");
637 IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1;
638 ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR];
639 ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm");
640 IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1;
641 ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv");
642 IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1;
643 ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv");
644 IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1;
645 ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
646 ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
647 ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
648 ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
649 ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl");
650 ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
651 ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
652 ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
653 ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
654 IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1;
655 ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl");
656 IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1;
657 ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR];
658 ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR];
659 ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls");
660 IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1;
661 ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als");
662 IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1;
663 ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq");
664 IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1;
665 ansi_opname[(int) LT_EXPR] = get_identifier ("__lt");
666 IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1;
667 ansi_opname[(int) LE_EXPR] = get_identifier ("__le");
668 IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1;
669 ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad");
670 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1;
671 ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad");
672 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1;
673 ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR];
674 ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR];
675 ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er");
676 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1;
677 ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer");
678 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1;
679 ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo");
680 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1;
681 ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co");
682 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1;
683 ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm");
684 IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1;
685 ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR];
686 ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf");
687 IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1;
688 ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm");
689 IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1;
690 ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl");
691 IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1;
692 ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc");
693 IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1;
694 ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw");
695 IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1;
696 ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl");
697 IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1;
698 ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn");
699 IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1;
700 ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd");
701 IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1;
702 ansi_opname[(int) TYPE_EXPR] = get_identifier (OPERATOR_TYPENAME_FORMAT);
703 IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1;
705 /* This is not true: these operators are not defined in ANSI,
706 but we need them anyway. */
707 ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn");
708 IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1;
709 ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx");
710 IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1;
711 ansi_opname[(int) COND_EXPR] = get_identifier ("__cn");
712 IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1;
713 ansi_opname[(int) SIZEOF_EXPR] = get_identifier ("__sz");
714 IDENTIFIER_OPNAME_P (ansi_opname[(int) SIZEOF_EXPR]) = 1;
716 init_method ();
717 init_error ();
718 gcc_obstack_init (&inline_text_obstack);
719 inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
721 internal_filename = ggc_alloc_string (INTERNAL_FILENAME,
722 sizeof (INTERNAL_FILENAME));
724 /* Start it at 0, because check_newline is called at the very beginning
725 and will increment it to 1. */
726 lineno = 0;
727 input_filename = internal_filename;
728 current_function_decl = NULL;
730 maxtoken = 40;
731 token_buffer = (char *) xmalloc (maxtoken + 2);
733 ridpointers[(int) RID_INT] = get_identifier ("int");
734 ridpointers[(int) RID_BOOL] = get_identifier ("bool");
735 ridpointers[(int) RID_CHAR] = get_identifier ("char");
736 ridpointers[(int) RID_VOID] = get_identifier ("void");
737 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
738 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
739 ridpointers[(int) RID_SHORT] = get_identifier ("short");
740 ridpointers[(int) RID_LONG] = get_identifier ("long");
741 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
742 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
743 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
744 ridpointers[(int) RID_CONST] = get_identifier ("const");
745 ridpointers[(int) RID_RESTRICT] = get_identifier ("__restrict");
746 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
747 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
748 ridpointers[(int) RID_STATIC] = get_identifier ("static");
749 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
750 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
751 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
752 ridpointers[(int) RID_COMPLEX] = get_identifier ("__complex");
754 /* C++ extensions. These are probably not correctly named. */
755 ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t");
756 class_type_node = build_int_2 (class_type, 0);
757 TREE_TYPE (class_type_node) = class_type_node;
758 ridpointers[(int) RID_CLASS] = class_type_node;
760 record_type_node = build_int_2 (record_type, 0);
761 TREE_TYPE (record_type_node) = record_type_node;
762 ridpointers[(int) RID_RECORD] = record_type_node;
764 union_type_node = build_int_2 (union_type, 0);
765 TREE_TYPE (union_type_node) = union_type_node;
766 ridpointers[(int) RID_UNION] = union_type_node;
768 enum_type_node = build_int_2 (enum_type, 0);
769 TREE_TYPE (enum_type_node) = enum_type_node;
770 ridpointers[(int) RID_ENUM] = enum_type_node;
772 ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual");
773 ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit");
774 ridpointers[(int) RID_EXPORT] = get_identifier ("export");
775 ridpointers[(int) RID_FRIEND] = get_identifier ("friend");
777 ridpointers[(int) RID_PUBLIC] = get_identifier ("public");
778 ridpointers[(int) RID_PRIVATE] = get_identifier ("private");
779 ridpointers[(int) RID_PROTECTED] = get_identifier ("protected");
780 ridpointers[(int) RID_TEMPLATE] = get_identifier ("template");
781 /* This is for ANSI C++. */
782 ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable");
784 /* Create the built-in __null node. Note that we can't yet call for
785 type_for_size here because integer_type_node and so forth are not
786 set up. Therefore, we don't set the type of these nodes until
787 init_decl_processing. */
788 null_node = build_int_2 (0, 0);
789 ridpointers[RID_NULL] = null_node;
791 opname_tab[(int) COMPONENT_REF] = "->";
792 opname_tab[(int) MEMBER_REF] = "->*";
793 opname_tab[(int) INDIRECT_REF] = "*";
794 opname_tab[(int) ARRAY_REF] = "[]";
795 opname_tab[(int) MODIFY_EXPR] = "=";
796 opname_tab[(int) INIT_EXPR] = "=";
797 opname_tab[(int) NEW_EXPR] = "new";
798 opname_tab[(int) DELETE_EXPR] = "delete";
799 opname_tab[(int) VEC_NEW_EXPR] = "new []";
800 opname_tab[(int) VEC_DELETE_EXPR] = "delete []";
801 opname_tab[(int) COND_EXPR] = "?:";
802 opname_tab[(int) CALL_EXPR] = "()";
803 opname_tab[(int) PLUS_EXPR] = "+";
804 opname_tab[(int) MINUS_EXPR] = "-";
805 opname_tab[(int) MULT_EXPR] = "*";
806 opname_tab[(int) TRUNC_DIV_EXPR] = "/";
807 opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)";
808 opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)";
809 opname_tab[(int) ROUND_DIV_EXPR] = "(round /)";
810 opname_tab[(int) TRUNC_MOD_EXPR] = "%";
811 opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)";
812 opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)";
813 opname_tab[(int) ROUND_MOD_EXPR] = "(round %)";
814 opname_tab[(int) EXACT_DIV_EXPR] = "/";
815 opname_tab[(int) NEGATE_EXPR] = "-";
816 opname_tab[(int) MIN_EXPR] = "<?";
817 opname_tab[(int) MAX_EXPR] = ">?";
818 opname_tab[(int) ABS_EXPR] = "abs";
819 opname_tab[(int) FFS_EXPR] = "ffs";
820 opname_tab[(int) LSHIFT_EXPR] = "<<";
821 opname_tab[(int) RSHIFT_EXPR] = ">>";
822 opname_tab[(int) BIT_IOR_EXPR] = "|";
823 opname_tab[(int) BIT_XOR_EXPR] = "^";
824 opname_tab[(int) BIT_AND_EXPR] = "&";
825 opname_tab[(int) BIT_ANDTC_EXPR] = "&~";
826 opname_tab[(int) BIT_NOT_EXPR] = "~";
827 opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&";
828 opname_tab[(int) TRUTH_ORIF_EXPR] = "||";
829 opname_tab[(int) TRUTH_AND_EXPR] = "strict &&";
830 opname_tab[(int) TRUTH_OR_EXPR] = "strict ||";
831 opname_tab[(int) TRUTH_NOT_EXPR] = "!";
832 opname_tab[(int) LT_EXPR] = "<";
833 opname_tab[(int) LE_EXPR] = "<=";
834 opname_tab[(int) GT_EXPR] = ">";
835 opname_tab[(int) GE_EXPR] = ">=";
836 opname_tab[(int) EQ_EXPR] = "==";
837 opname_tab[(int) NE_EXPR] = "!=";
838 opname_tab[(int) IN_EXPR] = "in";
839 opname_tab[(int) RANGE_EXPR] = "...";
840 opname_tab[(int) CONVERT_EXPR] = "+";
841 opname_tab[(int) ADDR_EXPR] = "&";
842 opname_tab[(int) PREDECREMENT_EXPR] = "--";
843 opname_tab[(int) PREINCREMENT_EXPR] = "++";
844 opname_tab[(int) POSTDECREMENT_EXPR] = "--";
845 opname_tab[(int) POSTINCREMENT_EXPR] = "++";
846 opname_tab[(int) COMPOUND_EXPR] = ",";
848 assignop_tab[(int) NOP_EXPR] = "=";
849 assignop_tab[(int) PLUS_EXPR] = "+=";
850 assignop_tab[(int) CONVERT_EXPR] = "+=";
851 assignop_tab[(int) MINUS_EXPR] = "-=";
852 assignop_tab[(int) NEGATE_EXPR] = "-=";
853 assignop_tab[(int) MULT_EXPR] = "*=";
854 assignop_tab[(int) INDIRECT_REF] = "*=";
855 assignop_tab[(int) TRUNC_DIV_EXPR] = "/=";
856 assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)";
857 assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)";
858 assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)";
859 assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)";
860 assignop_tab[(int) TRUNC_MOD_EXPR] = "%=";
861 assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)";
862 assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)";
863 assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)";
864 assignop_tab[(int) MIN_EXPR] = "<?=";
865 assignop_tab[(int) MAX_EXPR] = ">?=";
866 assignop_tab[(int) LSHIFT_EXPR] = "<<=";
867 assignop_tab[(int) RSHIFT_EXPR] = ">>=";
868 assignop_tab[(int) BIT_IOR_EXPR] = "|=";
869 assignop_tab[(int) BIT_XOR_EXPR] = "^=";
870 assignop_tab[(int) BIT_AND_EXPR] = "&=";
871 assignop_tab[(int) ADDR_EXPR] = "&=";
873 init_filename_times ();
875 /* Some options inhibit certain reserved words.
876 Clear those words out of the hash table so they won't be recognized. */
877 #define UNSET_RESERVED_WORD(STRING) \
878 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
879 if (s) s->name = ""; } while (0)
881 #if 0
882 /* let's parse things, and if they use it, then give them an error. */
883 if (!flag_exceptions)
885 UNSET_RESERVED_WORD ("throw");
886 UNSET_RESERVED_WORD ("try");
887 UNSET_RESERVED_WORD ("catch");
889 #endif
891 if (!flag_rtti || flag_no_gnu_keywords)
893 UNSET_RESERVED_WORD ("classof");
894 UNSET_RESERVED_WORD ("headof");
897 if (flag_no_asm || flag_no_gnu_keywords)
898 UNSET_RESERVED_WORD ("typeof");
899 if (! flag_operator_names)
901 /* These are new ANSI keywords that may break code. */
902 UNSET_RESERVED_WORD ("and");
903 UNSET_RESERVED_WORD ("and_eq");
904 UNSET_RESERVED_WORD ("bitand");
905 UNSET_RESERVED_WORD ("bitor");
906 UNSET_RESERVED_WORD ("compl");
907 UNSET_RESERVED_WORD ("not");
908 UNSET_RESERVED_WORD ("not_eq");
909 UNSET_RESERVED_WORD ("or");
910 UNSET_RESERVED_WORD ("or_eq");
911 UNSET_RESERVED_WORD ("xor");
912 UNSET_RESERVED_WORD ("xor_eq");
915 token_count = init_cpp_parse ();
916 interface_unknown = 1;
918 ggc_add_tree_root (ansi_opname, LAST_CPLUS_TREE_CODE);
919 ggc_add_tree_root (ansi_assopname, LAST_CPLUS_TREE_CODE);
920 ggc_add_string_root (&internal_filename, 1);
921 ggc_add_tree_root (ridpointers, RID_MAX);
922 ggc_add_tree_root (&defarg_fns, 1);
923 ggc_add_tree_root (&defarg_parm, 1);
924 ggc_add_tree_root (&this_filename_time, 1);
925 ggc_add_tree_root (&filename_times, 1);
926 ggc_add_root (&impl_file_chain, 1, sizeof (impl_file_chain),
927 mark_impl_file_chain);
928 return filename;
931 void
932 finish_parse ()
934 #if USE_CPPLIB
935 cpp_finish (&parse_in);
936 errorcount += parse_in.errors;
937 #else
938 fclose (finput);
939 #endif
942 void
943 reinit_parse_for_function ()
945 current_base_init_list = NULL_TREE;
946 current_member_init_list = NULL_TREE;
949 inline void
950 yyprint (file, yychar, yylval)
951 FILE *file;
952 int yychar;
953 YYSTYPE yylval;
955 tree t;
956 switch (yychar)
958 case IDENTIFIER:
959 case TYPENAME:
960 case TYPESPEC:
961 case PTYPENAME:
962 case PFUNCNAME:
963 case IDENTIFIER_DEFN:
964 case TYPENAME_DEFN:
965 case PTYPENAME_DEFN:
966 case SCSPEC:
967 case PRE_PARSED_CLASS_DECL:
968 t = yylval.ttype;
969 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL)
971 fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t)));
972 break;
974 my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
975 if (IDENTIFIER_POINTER (t))
976 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
977 break;
979 case AGGR:
980 if (yylval.ttype == class_type_node)
981 fprintf (file, " `class'");
982 else if (yylval.ttype == record_type_node)
983 fprintf (file, " `struct'");
984 else if (yylval.ttype == union_type_node)
985 fprintf (file, " `union'");
986 else if (yylval.ttype == enum_type_node)
987 fprintf (file, " `enum'");
988 else
989 my_friendly_abort (80);
990 break;
992 case CONSTANT:
993 t = yylval.ttype;
994 if (TREE_CODE (t) == INTEGER_CST)
995 fprintf (file,
996 #if HOST_BITS_PER_WIDE_INT == 64
997 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
998 " 0x%x%016x",
999 #else
1000 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1001 " 0x%lx%016lx",
1002 #else
1003 " 0x%llx%016llx",
1004 #endif
1005 #endif
1006 #else
1007 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
1008 " 0x%lx%08lx",
1009 #else
1010 " 0x%x%08x",
1011 #endif
1012 #endif
1013 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
1014 break;
1018 #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
1019 static int *reduce_count;
1020 #endif
1022 int *token_count;
1024 #if 0
1025 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
1026 #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
1027 #endif
1029 #ifdef GATHER_STATISTICS
1030 #ifdef REDUCE_LENGTH
1031 void
1032 yyhook (yyn)
1033 int yyn;
1035 reduce_count[yyn] += 1;
1038 static int
1039 reduce_cmp (p, q)
1040 int *p, *q;
1042 return reduce_count[*q] - reduce_count[*p];
1045 static int
1046 token_cmp (p, q)
1047 int *p, *q;
1049 return token_count[*q] - token_count[*p];
1051 #endif
1052 #endif
1054 void
1055 print_parse_statistics ()
1057 #ifdef GATHER_STATISTICS
1058 #ifdef REDUCE_LENGTH
1059 #if YYDEBUG != 0
1060 int i;
1061 int maxlen = REDUCE_LENGTH;
1062 unsigned *sorted;
1064 if (reduce_count[-1] == 0)
1065 return;
1067 if (TOKEN_LENGTH > REDUCE_LENGTH)
1068 maxlen = TOKEN_LENGTH;
1069 sorted = (unsigned *) alloca (sizeof (int) * maxlen);
1071 for (i = 0; i < TOKEN_LENGTH; i++)
1072 sorted[i] = i;
1073 qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
1074 for (i = 0; i < TOKEN_LENGTH; i++)
1076 int idx = sorted[i];
1077 if (token_count[idx] == 0)
1078 break;
1079 if (token_count[idx] < token_count[-1])
1080 break;
1081 fprintf (stderr, "token %d, `%s', count = %d\n",
1082 idx, yytname[YYTRANSLATE (idx)], token_count[idx]);
1084 fprintf (stderr, "\n");
1085 for (i = 0; i < REDUCE_LENGTH; i++)
1086 sorted[i] = i;
1087 qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
1088 for (i = 0; i < REDUCE_LENGTH; i++)
1090 int idx = sorted[i];
1091 if (reduce_count[idx] == 0)
1092 break;
1093 if (reduce_count[idx] < reduce_count[-1])
1094 break;
1095 fprintf (stderr, "rule %d, line %d, count = %d\n",
1096 idx, yyrline[idx], reduce_count[idx]);
1098 fprintf (stderr, "\n");
1099 #endif
1100 #endif
1101 #endif
1104 /* Sets the value of the 'yydebug' variable to VALUE.
1105 This is a function so we don't have to have YYDEBUG defined
1106 in order to build the compiler. */
1108 void
1109 set_yydebug (value)
1110 int value;
1112 #if YYDEBUG != 0
1113 extern int yydebug;
1114 yydebug = value;
1115 #else
1116 warning ("YYDEBUG not defined.");
1117 #endif
1121 /* Mark ARG (which is really a struct impl_files **) for GC. */
1123 static void
1124 mark_impl_file_chain (arg)
1125 void *arg;
1127 struct impl_files *ifs;
1129 ifs = *(struct impl_files **) arg;
1130 while (ifs)
1132 ggc_mark_string (ifs->filename);
1133 ifs = ifs->next;
1137 /* Helper function to load global variables with interface
1138 information. */
1140 void
1141 extract_interface_info ()
1143 tree fileinfo = 0;
1145 if (flag_alt_external_templates)
1147 struct tinst_level *til = tinst_for_decl ();
1149 if (til)
1150 fileinfo = get_time_identifier (til->file);
1152 if (!fileinfo)
1153 fileinfo = get_time_identifier (input_filename);
1154 fileinfo = TIME_IDENTIFIER_FILEINFO (fileinfo);
1155 interface_only = TREE_INT_CST_LOW (fileinfo);
1156 interface_unknown = TREE_INT_CST_HIGH (fileinfo);
1159 /* Return nonzero if S is not considered part of an
1160 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
1162 static int
1163 interface_strcmp (s)
1164 const char *s;
1166 /* Set the interface/implementation bits for this scope. */
1167 struct impl_files *ifiles;
1168 const char *s1;
1170 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
1172 const char *t1 = ifiles->filename;
1173 s1 = s;
1175 if (*s1 != *t1 || *s1 == 0)
1176 continue;
1178 while (*s1 == *t1 && *s1 != 0)
1179 s1++, t1++;
1181 /* A match. */
1182 if (*s1 == *t1)
1183 return 0;
1185 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
1186 if (index (s1, '.') || index (t1, '.'))
1187 continue;
1189 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
1190 continue;
1192 /* A match. */
1193 return 0;
1196 /* No matches. */
1197 return 1;
1200 static void
1201 cp_pragma_interface (main_filename)
1202 char *main_filename;
1204 tree fileinfo
1205 = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename));
1207 if (impl_file_chain == 0)
1209 /* If this is zero at this point, then we are
1210 auto-implementing. */
1211 if (main_input_filename == 0)
1212 main_input_filename = input_filename;
1214 #ifdef AUTO_IMPLEMENT
1215 filename = file_name_nondirectory (main_input_filename);
1216 fi = get_time_identifier (filename);
1217 fi = TIME_IDENTIFIER_FILEINFO (fi);
1218 TREE_INT_CST_LOW (fi) = 0;
1219 TREE_INT_CST_HIGH (fi) = 1;
1220 /* Get default. */
1221 impl_file_chain
1222 = (struct impl_files *) xmalloc (sizeof (struct impl_files));
1223 impl_file_chain->filename = ggc_alloc_string (filename, -1);
1224 impl_file_chain->next = 0;
1225 #endif
1228 interface_only = interface_strcmp (main_filename);
1229 #ifdef MULTIPLE_SYMBOL_SPACES
1230 if (! interface_only)
1231 interface_unknown = 0;
1232 #else /* MULTIPLE_SYMBOL_SPACES */
1233 interface_unknown = 0;
1234 #endif /* MULTIPLE_SYMBOL_SPACES */
1235 TREE_INT_CST_LOW (fileinfo) = interface_only;
1236 TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
1239 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
1240 We used to only allow this at toplevel, but that restriction was buggy
1241 in older compilers and it seems reasonable to allow it in the headers
1242 themselves, too. It only needs to precede the matching #p interface.
1244 We don't touch interface_only or interface_unknown; the user must specify
1245 a matching #p interface for this to have any effect. */
1247 static void
1248 cp_pragma_implementation (main_filename)
1249 char *main_filename;
1251 struct impl_files *ifiles = impl_file_chain;
1252 for (; ifiles; ifiles = ifiles->next)
1254 if (! strcmp (ifiles->filename, main_filename))
1255 break;
1257 if (ifiles == 0)
1259 ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files));
1260 ifiles->filename = ggc_alloc_string (main_filename, -1);
1261 ifiles->next = impl_file_chain;
1262 impl_file_chain = ifiles;
1266 /* Set up the state required to correctly handle the definition of the
1267 inline function whose preparsed state has been saved in PI. */
1269 static void
1270 begin_definition_of_inclass_inline (pi)
1271 struct pending_inline* pi;
1273 tree context;
1275 if (!pi->fndecl)
1276 return;
1278 /* If this is an inline function in a local class, we must make sure
1279 that we save all pertinent information about the function
1280 surrounding the local class. */
1281 context = hack_decl_function_context (pi->fndecl);
1282 if (context)
1283 push_function_context_to (context);
1285 feed_input (pi->buf, pi->len, pi->filename, pi->lineno);
1286 yychar = PRE_PARSED_FUNCTION_DECL;
1287 yylval.pi = pi;
1288 /* Pass back a handle to the rest of the inline functions, so that they
1289 can be processed later. */
1290 DECL_PENDING_INLINE_INFO (pi->fndecl) = 0;
1291 DECL_PENDING_INLINE_P (pi->fndecl) = 0;
1292 interface_unknown = pi->interface == 1;
1293 interface_only = pi->interface == 0;
1296 /* Called from the top level: if there are any pending inlines to
1297 do, set up to process them now. This function sets up the first function
1298 to be parsed; after it has been, the rule for fndef in parse.y will
1299 call process_next_inline to start working on the next one. */
1301 void
1302 do_pending_inlines ()
1304 struct pending_inline *t;
1306 /* Oops, we're still dealing with the last batch. */
1307 if (yychar == PRE_PARSED_FUNCTION_DECL)
1308 return;
1310 /* Reverse the pending inline functions, since
1311 they were cons'd instead of appended. */
1313 struct pending_inline *prev = 0, *tail;
1314 t = pending_inlines;
1315 pending_inlines = 0;
1317 for (; t; t = tail)
1319 tail = t->next;
1320 t->next = prev;
1321 t->deja_vu = 1;
1322 prev = t;
1324 t = prev;
1327 if (t == 0)
1328 return;
1330 /* Now start processing the first inline function. */
1331 begin_definition_of_inclass_inline (t);
1334 /* Called from the fndecl rule in the parser when the function just parsed
1335 was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1336 do_pending_inlines). */
1338 void
1339 process_next_inline (i)
1340 struct pending_inline *i;
1342 tree context;
1343 context = hack_decl_function_context (i->fndecl);
1344 if (context)
1345 pop_function_context_from (context);
1346 i = i->next;
1347 if (yychar == YYEMPTY)
1348 yychar = yylex ();
1349 if (yychar != END_OF_SAVED_INPUT)
1351 error ("parse error at end of saved function text");
1353 /* restore_pending_input will abort unless yychar is either
1354 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1355 hosed, feed back YYEMPTY. */
1357 yychar = YYEMPTY;
1358 end_input ();
1359 if (i)
1360 begin_definition_of_inclass_inline (i);
1361 else
1362 extract_interface_info ();
1365 /* Since inline methods can refer to text which has not yet been seen,
1366 we store the text of the method in a structure which is placed in the
1367 DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1368 After parsing the body of the class definition, the FUNCTION_DECL's are
1369 scanned to see which ones have this field set. Those are then digested
1370 one at a time.
1372 This function's FUNCTION_DECL will have a bit set in its common so
1373 that we know to watch out for it. */
1375 static void
1376 consume_string (this_obstack, matching_char)
1377 register struct obstack *this_obstack;
1378 int matching_char;
1380 register int c;
1381 int starting_lineno;
1383 #if USE_CPPLIB
1384 if (cpp_token == CPP_STRING)
1386 /* The C preprocessor will warn about newlines in strings. */
1387 obstack_grow (this_obstack, yy_cur, (yy_lim - yy_cur));
1388 yy_cur = yy_lim;
1389 lineno = parse_in.lineno;
1390 return;
1392 #endif
1394 starting_lineno = lineno;
1397 c = getch ();
1398 if (c == EOF)
1400 int save_lineno = lineno;
1401 lineno = starting_lineno;
1402 if (matching_char == '"')
1403 error ("end of file encountered inside string constant");
1404 else
1405 error ("end of file encountered inside character constant");
1406 lineno = save_lineno;
1407 return;
1409 if (c == '\\')
1411 obstack_1grow (this_obstack, c);
1412 c = getch ();
1413 obstack_1grow (this_obstack, c);
1415 /* Make sure we continue the loop */
1416 c = 0;
1417 continue;
1419 if (c == '\n')
1421 if (pedantic)
1422 pedwarn ("ANSI C++ forbids newline in string constant");
1423 lineno++;
1425 obstack_1grow (this_obstack, c);
1427 while (c != matching_char);
1430 struct pending_input {
1431 int yychar, eof;
1432 YYSTYPE yylval;
1433 struct obstack token_obstack;
1434 int first_token;
1437 struct pending_input *
1438 save_pending_input ()
1440 struct pending_input *p;
1441 p = (struct pending_input *) xmalloc (sizeof (struct pending_input));
1442 p->yychar = yychar;
1443 p->yylval = yylval;
1444 p->eof = end_of_file;
1445 yychar = YYEMPTY;
1446 p->first_token = first_token;
1447 p->token_obstack = token_obstack;
1449 first_token = 0;
1450 gcc_obstack_init (&token_obstack);
1451 end_of_file = 0;
1452 return p;
1455 void
1456 restore_pending_input (p)
1457 struct pending_input *p;
1459 my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230);
1460 yychar = p->yychar;
1461 yylval = p->yylval;
1462 first_token = p->first_token;
1463 obstack_free (&token_obstack, (char *) 0);
1464 token_obstack = p->token_obstack;
1465 end_of_file = p->eof;
1466 free (p);
1469 /* Unget character CH from the input stream.
1470 If RESCAN is non-zero, then we want to `see' this
1471 character as the next input token. */
1473 void
1474 yyungetc (ch, rescan)
1475 int ch;
1476 int rescan;
1478 /* Unget a character from the input stream. */
1479 if (yychar == YYEMPTY || rescan == 0)
1481 /* If we're putting back a brace, undo the change in indent_level
1482 from the first time we saw it. */
1483 if (ch == '{')
1484 indent_level--;
1485 else if (ch == '}')
1486 indent_level++;
1488 put_back (ch);
1490 else
1492 yychar = ch;
1496 void
1497 clear_inline_text_obstack ()
1499 obstack_free (&inline_text_obstack, inline_text_firstobj);
1502 /* This function stores away the text for an inline function that should
1503 be processed later. It decides how much later, and may need to move
1504 the info between obstacks; therefore, the caller should not refer to
1505 the T parameter after calling this function. */
1507 static void
1508 store_pending_inline (decl, t)
1509 tree decl;
1510 struct pending_inline *t;
1512 t->fndecl = decl;
1513 DECL_PENDING_INLINE_INFO (decl) = t;
1514 DECL_PENDING_INLINE_P (decl) = 1;
1516 /* Because we use obstacks, we must process these in precise order. */
1517 t->next = pending_inlines;
1518 pending_inlines = t;
1521 void
1522 reinit_parse_for_method (yychar, decl)
1523 int yychar;
1524 tree decl;
1526 int len;
1527 int starting_lineno = lineno;
1528 char *starting_filename = input_filename;
1530 reinit_parse_for_block (yychar, &inline_text_obstack);
1532 len = obstack_object_size (&inline_text_obstack);
1533 if (decl == void_type_node
1534 || (current_class_type && TYPE_REDEFINED (current_class_type)))
1536 /* Happens when we get two declarations of the same
1537 function in the same scope. */
1538 char *buf = obstack_finish (&inline_text_obstack);
1539 obstack_free (&inline_text_obstack, buf);
1540 return;
1542 else
1544 struct pending_inline *t;
1545 char *buf = obstack_finish (&inline_text_obstack);
1547 t = (struct pending_inline *) obstack_alloc (&inline_text_obstack,
1548 sizeof (struct pending_inline));
1549 t->lineno = starting_lineno;
1550 t->filename = starting_filename;
1551 t->token = YYEMPTY;
1552 t->token_value = 0;
1553 t->buf = buf;
1554 t->len = len;
1555 t->deja_vu = 0;
1556 #if 0
1557 if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
1558 warn_if_unknown_interface (decl);
1559 #endif
1560 t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2));
1561 store_pending_inline (decl, t);
1565 /* Consume a block -- actually, a method beginning
1566 with `:' or `{' -- and save it away on the specified obstack. */
1568 void
1569 reinit_parse_for_block (pyychar, obstackp)
1570 int pyychar;
1571 struct obstack *obstackp;
1573 register int c;
1574 int blev = 1;
1575 int starting_lineno = lineno;
1576 char *starting_filename = input_filename;
1577 int len;
1578 int look_for_semicolon = 0;
1579 int look_for_lbrac = 0;
1581 if (pyychar == '{')
1583 obstack_1grow (obstackp, '{');
1584 /* We incremented indent_level in yylex; undo that. */
1585 indent_level--;
1587 else if (pyychar == '=')
1588 look_for_semicolon = 1;
1589 else if (pyychar == ':')
1591 obstack_1grow (obstackp, pyychar);
1592 /* Add a space so we don't get confused by ': ::A(20)'. */
1593 obstack_1grow (obstackp, ' ');
1594 look_for_lbrac = 1;
1595 blev = 0;
1597 else if (pyychar == RETURN_KEYWORD)
1599 obstack_grow (obstackp, "return", 6);
1600 look_for_lbrac = 1;
1601 blev = 0;
1603 else if (pyychar == TRY)
1605 obstack_grow (obstackp, "try", 3);
1606 look_for_lbrac = 1;
1607 blev = 0;
1609 else
1611 yyerror ("parse error in method specification");
1612 obstack_1grow (obstackp, '{');
1615 c = getch ();
1617 while (c != EOF)
1619 int this_lineno = lineno;
1621 saving_parse_to_obstack = 1;
1622 c = skip_white_space (c);
1623 saving_parse_to_obstack = 0;
1625 /* Don't lose our cool if there are lots of comments. */
1626 if (lineno == this_lineno + 1)
1627 obstack_1grow (obstackp, '\n');
1628 else if (lineno == this_lineno)
1630 else if (lineno - this_lineno < 10)
1632 int i;
1633 for (i = lineno - this_lineno; i > 0; i--)
1634 obstack_1grow (obstackp, '\n');
1636 else
1638 char buf[16];
1639 sprintf (buf, "\n# %d \"", lineno);
1640 len = strlen (buf);
1641 obstack_grow (obstackp, buf, len);
1643 len = strlen (input_filename);
1644 obstack_grow (obstackp, input_filename, len);
1645 obstack_1grow (obstackp, '\"');
1646 obstack_1grow (obstackp, '\n');
1649 while (c > ' ') /* ASCII dependent... */
1651 obstack_1grow (obstackp, c);
1652 if (c == '{')
1654 look_for_lbrac = 0;
1655 blev++;
1657 else if (c == '}')
1659 blev--;
1660 if (blev == 0 && !look_for_semicolon)
1662 if (pyychar == TRY)
1664 if (peekyylex () == CATCH)
1666 yylex ();
1667 obstack_grow (obstackp, " catch ", 7);
1668 look_for_lbrac = 1;
1670 else
1672 yychar = '{';
1673 goto done;
1676 else
1678 goto done;
1682 else if (c == '\\')
1684 /* Don't act on the next character...e.g, doing an escaped
1685 double-quote. */
1686 c = getch ();
1687 if (c == EOF)
1689 error_with_file_and_line (starting_filename,
1690 starting_lineno,
1691 "end of file read inside definition");
1692 goto done;
1694 obstack_1grow (obstackp, c);
1696 else if (c == '\"')
1697 consume_string (obstackp, c);
1698 else if (c == '\'')
1699 consume_string (obstackp, c);
1700 else if (c == ';')
1702 if (look_for_lbrac)
1704 error ("function body for constructor missing");
1705 obstack_1grow (obstackp, '{');
1706 obstack_1grow (obstackp, '}');
1707 len += 2;
1708 goto done;
1710 else if (look_for_semicolon && blev == 0)
1711 goto done;
1713 c = getch ();
1716 if (c == EOF)
1718 error_with_file_and_line (starting_filename,
1719 starting_lineno,
1720 "end of file read inside definition");
1721 goto done;
1723 else if (c != '\n')
1725 obstack_1grow (obstackp, c);
1726 c = getch ();
1729 done:
1730 obstack_1grow (obstackp, '\0');
1733 /* Consume a no-commas expression -- actually, a default argument -- and
1734 save it away on the specified obstack. */
1736 static void
1737 reinit_parse_for_expr (obstackp)
1738 struct obstack *obstackp;
1740 register int c;
1741 int starting_lineno = lineno;
1742 char *starting_filename = input_filename;
1743 int len;
1744 int plev = 0;
1746 c = getch ();
1748 while (c != EOF)
1750 int this_lineno = lineno;
1752 saving_parse_to_obstack = 1;
1753 c = skip_white_space (c);
1754 saving_parse_to_obstack = 0;
1756 /* Don't lose our cool if there are lots of comments. */
1757 if (lineno == this_lineno + 1)
1758 obstack_1grow (obstackp, '\n');
1759 else if (lineno == this_lineno)
1761 else if (lineno - this_lineno < 10)
1763 int i;
1764 for (i = lineno - this_lineno; i > 0; --i)
1765 obstack_1grow (obstackp, '\n');
1767 else
1769 char buf[16];
1770 sprintf (buf, "\n# %d \"", lineno);
1771 len = strlen (buf);
1772 obstack_grow (obstackp, buf, len);
1774 len = strlen (input_filename);
1775 obstack_grow (obstackp, input_filename, len);
1776 obstack_1grow (obstackp, '\"');
1777 obstack_1grow (obstackp, '\n');
1780 while (c > ' ') /* ASCII dependent... */
1782 if (plev <= 0 && (c == ')' || c == ','))
1784 put_back (c);
1785 goto done;
1787 obstack_1grow (obstackp, c);
1788 if (c == '(' || c == '[')
1789 ++plev;
1790 else if (c == ']' || c == ')')
1791 --plev;
1792 else if (c == '\\')
1794 /* Don't act on the next character...e.g, doing an escaped
1795 double-quote. */
1796 c = getch ();
1797 if (c == EOF)
1799 error_with_file_and_line (starting_filename,
1800 starting_lineno,
1801 "end of file read inside definition");
1802 goto done;
1804 obstack_1grow (obstackp, c);
1806 else if (c == '\"')
1807 consume_string (obstackp, c);
1808 else if (c == '\'')
1809 consume_string (obstackp, c);
1810 c = getch ();
1813 if (c == EOF)
1815 error_with_file_and_line (starting_filename,
1816 starting_lineno,
1817 "end of file read inside definition");
1818 goto done;
1820 else if (c != '\n')
1822 obstack_1grow (obstackp, c);
1823 c = getch ();
1826 done:
1827 obstack_1grow (obstackp, '\0');
1830 int do_snarf_defarg;
1832 /* Decide whether the default argument we are about to see should be
1833 gobbled up as text for later parsing. */
1835 void
1836 maybe_snarf_defarg ()
1838 if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
1839 do_snarf_defarg = 1;
1842 tree
1843 snarf_defarg ()
1845 int len;
1846 char *buf;
1847 tree arg;
1849 reinit_parse_for_expr (&inline_text_obstack);
1850 len = obstack_object_size (&inline_text_obstack);
1851 buf = obstack_finish (&inline_text_obstack);
1853 arg = make_node (DEFAULT_ARG);
1854 DEFARG_LENGTH (arg) = len - 1;
1855 DEFARG_POINTER (arg) = buf;
1857 return arg;
1860 /* Called from grokfndecl to note a function decl with unparsed default
1861 arguments for later processing. Also called from grokdeclarator
1862 for function types with unparsed defargs; the call from grokfndecl
1863 will always come second, so we can overwrite the entry from the type. */
1865 void
1866 add_defarg_fn (decl)
1867 tree decl;
1869 if (TREE_CODE (decl) == FUNCTION_DECL)
1870 TREE_VALUE (defarg_fns) = decl;
1871 else
1872 defarg_fns = tree_cons (current_class_type, decl, defarg_fns);
1875 /* Helper for do_pending_defargs. Starts the parsing of a default arg. */
1877 static void
1878 feed_defarg (f, p)
1879 tree f, p;
1881 tree d = TREE_PURPOSE (p);
1882 char *file;
1883 int line;
1884 if (TREE_CODE (f) == FUNCTION_DECL)
1886 line = DECL_SOURCE_LINE (f);
1887 file = DECL_SOURCE_FILE (f);
1889 else
1891 line = lineno;
1892 file = input_filename;
1895 feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d), file, line);
1896 yychar = DEFARG_MARKER;
1897 yylval.ttype = p;
1900 /* Helper for do_pending_defargs. Ends the parsing of a default arg. */
1902 static void
1903 finish_defarg ()
1905 if (yychar == YYEMPTY)
1906 yychar = yylex ();
1907 if (yychar != END_OF_SAVED_INPUT)
1909 error ("parse error at end of saved function text");
1911 /* restore_pending_input will abort unless yychar is either
1912 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1913 hosed, feed back YYEMPTY. */
1915 yychar = YYEMPTY;
1916 end_input ();
1919 /* Main function for deferred parsing of default arguments. Called from
1920 the parser. */
1922 void
1923 do_pending_defargs ()
1925 if (defarg_parm)
1926 finish_defarg ();
1928 for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns))
1930 tree defarg_fn = TREE_VALUE (defarg_fns);
1931 if (defarg_parm == NULL_TREE)
1933 push_nested_class (TREE_PURPOSE (defarg_fns), 1);
1934 pushlevel (0);
1935 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1936 maybe_begin_member_template_processing (defarg_fn);
1938 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1940 #if 0
1941 tree p;
1942 for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p))
1943 pushdecl (copy_node (p));
1944 #endif
1945 defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn));
1947 else
1948 defarg_parm = TYPE_ARG_TYPES (defarg_fn);
1950 else
1951 defarg_parm = TREE_CHAIN (defarg_parm);
1953 for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm))
1954 if (TREE_PURPOSE (defarg_parm)
1955 && TREE_CODE (TREE_PURPOSE (defarg_parm)) == DEFAULT_ARG)
1957 feed_defarg (defarg_fn, defarg_parm);
1959 /* Return to the parser, which will process this defarg
1960 and call us again. */
1961 return;
1964 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1966 maybe_end_member_template_processing ();
1967 check_default_args (defarg_fn);
1970 poplevel (0, 0, 0);
1971 pop_nested_class ();
1975 /* Build a default function named NAME for type TYPE.
1976 KIND says what to build.
1978 When KIND == 0, build default destructor.
1979 When KIND == 1, build virtual destructor.
1980 When KIND == 2, build default constructor.
1981 When KIND == 3, build default X(const X&) constructor.
1982 When KIND == 4, build default X(X&) constructor.
1983 When KIND == 5, build default operator = (const X&).
1984 When KIND == 6, build default operator = (X&). */
1986 tree
1987 cons_up_default_function (type, full_name, kind)
1988 tree type, full_name;
1989 int kind;
1991 tree declspecs = NULL_TREE;
1992 tree fn, args = NULL_TREE;
1993 tree argtype;
1994 int retref = 0;
1995 tree name = constructor_name (full_name);
1997 switch (kind)
1999 /* Destructors. */
2000 case 0:
2001 name = build_parse_node (BIT_NOT_EXPR, name);
2002 args = void_list_node;
2003 break;
2005 case 2:
2006 /* Default constructor. */
2007 args = void_list_node;
2008 break;
2010 case 3:
2011 type = build_qualified_type (type, TYPE_QUAL_CONST);
2012 /* Fall through... */
2013 case 4:
2014 /* According to ARM $12.8, the default copy ctor will be declared, but
2015 not defined, unless it's needed. */
2016 argtype = build_reference_type (type);
2017 args = tree_cons (NULL_TREE,
2018 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
2019 get_identifier ("_ctor_arg")),
2020 void_list_node);
2021 break;
2023 case 5:
2024 case 6:
2025 retref = 1;
2026 declspecs = build_decl_list (NULL_TREE, type);
2028 if (kind == 5)
2029 type = build_qualified_type (type, TYPE_QUAL_CONST);
2031 name = ansi_opname [(int) MODIFY_EXPR];
2033 argtype = build_reference_type (type);
2034 args = tree_cons (NULL_TREE,
2035 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
2036 get_identifier ("_ctor_arg")),
2037 void_list_node);
2038 break;
2040 default:
2041 my_friendly_abort (59);
2044 declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE],
2045 declspecs);
2047 TREE_PARMLIST (args) = 1;
2050 tree declarator = make_call_declarator (name, args, NULL_TREE, NULL_TREE);
2051 if (retref)
2052 declarator = build_parse_node (ADDR_EXPR, declarator);
2054 fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
2057 if (fn == void_type_node)
2058 return fn;
2060 if (kind > 2)
2061 SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn)));
2063 #if 0
2064 if (processing_template_defn)
2066 SET_DECL_IMPLICIT_INSTANTIATION (fn);
2067 repo_template_used (fn);
2069 #endif
2071 #if 0
2072 if (CLASSTYPE_INTERFACE_KNOWN (type))
2074 DECL_INTERFACE_KNOWN (fn) = 1;
2075 DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type)
2076 && flag_implement_inlines);
2078 else
2079 #endif
2080 DECL_NOT_REALLY_EXTERN (fn) = 1;
2082 mark_inline_for_output (fn);
2084 #ifdef DEBUG_DEFAULT_FUNCTIONS
2085 { char *fn_type = NULL;
2086 tree t = name;
2087 switch (kind)
2089 case 0: fn_type = "default destructor"; break;
2090 case 1: fn_type = "virtual destructor"; break;
2091 case 2: fn_type = "default constructor"; break;
2092 case 3: fn_type = "default X(const X&)"; break;
2093 case 4: fn_type = "default X(X&)"; break;
2095 if (fn_type)
2097 if (TREE_CODE (name) == BIT_NOT_EXPR)
2098 t = TREE_OPERAND (name, 0);
2099 fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type,
2100 IDENTIFIER_POINTER (t), func_buf);
2103 #endif /* DEBUG_DEFAULT_FUNCTIONS */
2105 /* Show that this function was generated by the compiler. */
2106 SET_DECL_ARTIFICIAL (fn);
2108 return fn;
2111 /* Heuristic to tell whether the user is missing a semicolon
2112 after a struct or enum declaration. Emit an error message
2113 if we know the user has blown it. */
2115 void
2116 check_for_missing_semicolon (type)
2117 tree type;
2119 if (yychar < 0)
2120 yychar = yylex ();
2122 if ((yychar > 255
2123 && yychar != SCSPEC
2124 && yychar != IDENTIFIER
2125 && yychar != TYPENAME
2126 && yychar != CV_QUALIFIER
2127 && yychar != SELFNAME)
2128 || end_of_file)
2130 if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
2131 error ("semicolon missing after %s declaration",
2132 TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
2133 else
2134 cp_error ("semicolon missing after declaration of `%T'", type);
2135 shadow_tag (build_tree_list (0, type));
2137 /* Could probably also hack cases where class { ... } f (); appears. */
2138 clear_anon_tags ();
2141 void
2142 note_got_semicolon (type)
2143 tree type;
2145 if (TREE_CODE_CLASS (TREE_CODE (type)) != 't')
2146 my_friendly_abort (60);
2147 if (CLASS_TYPE_P (type))
2148 CLASSTYPE_GOT_SEMICOLON (type) = 1;
2151 void
2152 note_list_got_semicolon (declspecs)
2153 tree declspecs;
2155 tree link;
2157 for (link = declspecs; link; link = TREE_CHAIN (link))
2159 tree type = TREE_VALUE (link);
2160 if (TREE_CODE_CLASS (TREE_CODE (type)) == 't')
2161 note_got_semicolon (type);
2163 clear_anon_tags ();
2166 /* Iff C is a carriage return, warn about it - if appropriate -
2167 and return nonzero. */
2168 static int
2169 whitespace_cr (c)
2170 int c;
2172 static int newline_warning = 0;
2174 if (c == '\r')
2176 /* ANSI C says the effects of a carriage return in a source file
2177 are undefined. */
2178 if (pedantic && !newline_warning)
2180 warning ("carriage return in source file");
2181 warning ("(we only warn about the first carriage return)");
2182 newline_warning = 1;
2184 return 1;
2186 return 0;
2189 /* If C is not whitespace, return C.
2190 Otherwise skip whitespace and return first nonwhite char read. */
2192 static int
2193 skip_white_space (c)
2194 register int c;
2196 for (;;)
2198 switch (c)
2200 /* We don't recognize comments here, because
2201 cpp output can include / and * consecutively as operators.
2202 Also, there's no need, since cpp removes all comments. */
2204 case '\n':
2205 if (linemode)
2207 put_back (c);
2208 return EOF;
2210 c = check_newline ();
2211 break;
2213 case ' ':
2214 case '\t':
2215 case '\f':
2216 case '\v':
2217 case '\b':
2218 #if USE_CPPLIB
2219 /* While processing a # directive we don't get CPP_HSPACE
2220 tokens, so we also need to handle whitespace the normal way. */
2221 if (cpp_token == CPP_HSPACE)
2222 c = yy_get_token ();
2223 else
2224 #endif
2225 c = getch ();
2226 break;
2228 case '\r':
2229 whitespace_cr (c);
2230 c = getch ();
2231 break;
2233 case '\\':
2234 c = getch ();
2235 if (c == '\n')
2236 lineno++;
2237 else
2238 error ("stray '\\' in program");
2239 c = getch ();
2240 break;
2242 default:
2243 return (c);
2248 /* Make the token buffer longer, preserving the data in it.
2249 P should point to just beyond the last valid character in the old buffer.
2250 The value we return is a pointer to the new buffer
2251 at a place corresponding to P. */
2253 static void
2254 extend_token_buffer_to (size)
2255 int size;
2258 maxtoken = maxtoken * 2 + 10;
2259 while (maxtoken < size);
2260 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
2263 static char *
2264 extend_token_buffer (p)
2265 const char *p;
2267 int offset = p - token_buffer;
2268 extend_token_buffer_to (offset);
2269 return token_buffer + offset;
2272 #if defined HANDLE_PRAGMA
2273 /* Local versions of these macros, that can be passed as function pointers. */
2274 static int
2275 pragma_getc ()
2277 return getch ();
2280 static void
2281 pragma_ungetc (arg)
2282 int arg;
2284 put_back (arg);
2286 #endif
2288 static int
2289 read_line_number (num)
2290 int *num;
2292 register int token = real_yylex ();
2294 if (token == CONSTANT
2295 && TREE_CODE (yylval.ttype) == INTEGER_CST)
2297 *num = TREE_INT_CST_LOW (yylval.ttype);
2298 return 1;
2300 else
2302 if (token != END_OF_LINE)
2303 error ("invalid #-line");
2304 return 0;
2308 /* At the beginning of a line, increment the line number
2309 and process any #-directive on this line.
2310 If the line is a #-directive, read the entire line and return a newline.
2311 Otherwise, return the line's first non-whitespace character.
2313 Note that in the case of USE_CPPLIB, we get the whole line as one
2314 CPP_DIRECTIVE token. */
2316 static int
2317 check_newline ()
2319 register int c;
2320 register int token;
2321 int saw_line;
2322 enum { act_none, act_push, act_pop } action;
2323 int old_lineno, action_number, l;
2324 int entering_c_header;
2326 restart:
2327 /* Read first nonwhite char on the line. Do this before incrementing the
2328 line number, in case we're at the end of saved text. */
2330 #ifdef USE_CPPLIB
2331 c = getch ();
2332 /* In some cases where we're leaving an include file, we can get multiple
2333 CPP_HSPACE tokens in a row, so we need to loop. */
2334 while (cpp_token == CPP_HSPACE)
2335 c = yy_get_token ();
2336 #else
2338 c = getch ();
2339 while (c == ' ' || c == '\t');
2340 #endif
2342 lineno++;
2344 if (c != '#')
2346 /* Sequences of multiple newlines are very common; optimize them. */
2347 if (c == '\n')
2348 goto restart;
2350 /* If not #, return it so caller will use it. */
2351 return c;
2354 /* Don't read beyond this line. */
2355 saw_line = 0;
2356 linemode = 1;
2358 #if USE_CPPLIB
2359 if (cpp_token == CPP_VSPACE)
2361 /* Format is "<space> <line number> <filename> <newline>".
2362 Only the line number is interesting, and even that
2363 we can get more efficiently than scanning the line. */
2364 yy_cur = yy_lim - 1;
2365 lineno = parse_in.lineno - 1;
2366 goto skipline;
2368 #endif
2370 token = real_yylex ();
2372 if (token == IDENTIFIER)
2374 /* If a letter follows, then if the word here is `line', skip
2375 it and ignore it; otherwise, ignore the line, with an error
2376 if the word isn't `pragma'. */
2378 const char *name = IDENTIFIER_POINTER (yylval.ttype);
2380 if (!strcmp (name, "pragma"))
2382 token = real_yylex ();
2383 if (token != IDENTIFIER
2384 || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
2385 goto skipline;
2387 /* If this is 1, we handled it; if it's -1, it was one we
2388 wanted but had something wrong with it. Only if it's
2389 0 was it not handled. */
2390 if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype)))
2391 goto skipline;
2393 #ifdef HANDLE_PRAGMA
2394 /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
2395 (if both are defined), in order to give the back
2396 end a chance to override the interpretation of
2397 SYSV style pragmas. */
2398 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
2399 IDENTIFIER_POINTER (yylval.ttype)))
2400 goto skipline;
2401 #endif /* HANDLE_PRAGMA */
2403 #ifdef HANDLE_GENERIC_PRAGMAS
2404 if (handle_generic_pragma (token))
2405 goto skipline;
2406 #endif /* HANDLE_GENERIC_PRAGMAS */
2408 /* Issue a warning message if we have been asked to do so.
2409 Ignoring unknown pragmas in system header file unless
2410 an explcit -Wunknown-pragmas has been given. */
2411 if (warn_unknown_pragmas > 1
2412 || (warn_unknown_pragmas && ! in_system_header))
2413 warning ("ignoring pragma: %s", token_buffer);
2415 goto skipline;
2417 else if (!strcmp (name, "define"))
2419 debug_define (lineno, GET_DIRECTIVE_LINE ());
2420 goto skipline;
2422 else if (!strcmp (name, "undef"))
2424 debug_undef (lineno, GET_DIRECTIVE_LINE ());
2425 goto skipline;
2427 else if (!strcmp (name, "line"))
2429 saw_line = 1;
2430 token = real_yylex ();
2431 goto linenum;
2433 else if (!strcmp (name, "ident"))
2435 /* #ident. The pedantic warning is now in cccp.c. */
2437 /* Here we have just seen `#ident '.
2438 A string constant should follow. */
2440 token = real_yylex ();
2441 if (token == END_OF_LINE)
2442 goto skipline;
2443 if (token != STRING
2444 || TREE_CODE (yylval.ttype) != STRING_CST)
2446 error ("invalid #ident");
2447 goto skipline;
2450 if (! flag_no_ident)
2452 #ifdef ASM_OUTPUT_IDENT
2453 ASM_OUTPUT_IDENT (asm_out_file,
2454 TREE_STRING_POINTER (yylval.ttype));
2455 #endif
2458 /* Skip the rest of this line. */
2459 goto skipline;
2462 error ("undefined or invalid # directive `%s'", name);
2463 goto skipline;
2466 /* If the # is the only nonwhite char on the line,
2467 just ignore it. Check the new newline. */
2468 if (token == END_OF_LINE)
2469 goto skipline;
2471 linenum:
2472 /* Here we have either `#line' or `# <nonletter>'.
2473 In either case, it should be a line number; a digit should follow. */
2475 if (token != CONSTANT
2476 || TREE_CODE (yylval.ttype) != INTEGER_CST)
2478 error ("invalid #-line");
2479 goto skipline;
2482 /* subtract one, because it is the following line that
2483 gets the specified number */
2485 l = TREE_INT_CST_LOW (yylval.ttype) - 1;
2487 /* More follows: it must be a string constant (filename).
2488 It would be neat to use cpplib to quickly process the string, but
2489 (1) we don't have a handy tokenization of the string, and
2490 (2) I don't know how well that would work in the presense
2491 of filenames that contain wide characters. */
2493 if (saw_line || saving_parse_to_obstack)
2495 /* Don't treat \ as special if we are processing #line 1 "...".
2496 If you want it to be treated specially, use # 1 "...". Also
2497 ignore these if saving to an obstack for later parsing. */
2498 ignore_escape_flag = 1;
2501 /* Read the string constant. */
2502 token = real_yylex ();
2504 ignore_escape_flag = 0;
2506 if (token == END_OF_LINE)
2508 /* No more: store the line number and check following line. */
2509 lineno = l;
2510 goto skipline;
2513 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2515 error ("invalid #line");
2516 goto skipline;
2519 /* Changing files again. This means currently collected time
2520 is charged against header time, and body time starts back at 0. */
2521 if (flag_detailed_statistics)
2523 int this_time = my_get_run_time ();
2524 tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype));
2525 header_time += this_time - body_time;
2526 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
2527 += this_time - body_time;
2528 this_filename_time = time_identifier;
2529 body_time = this_time;
2532 input_filename = TREE_STRING_POINTER (yylval.ttype);
2534 GNU_xref_file (input_filename);
2536 if (main_input_filename == 0)
2538 struct impl_files *ifiles = impl_file_chain;
2540 if (ifiles)
2542 while (ifiles->next)
2543 ifiles = ifiles->next;
2544 ifiles->filename = file_name_nondirectory (input_filename);
2547 main_input_filename = input_filename;
2550 extract_interface_info ();
2552 old_lineno = lineno;
2553 action = act_none;
2554 action_number = 0;
2555 lineno = l;
2557 /* Each change of file name
2558 reinitializes whether we are now in a system header. */
2559 in_system_header = 0;
2560 entering_c_header = 0;
2562 if (!read_line_number (&action_number))
2564 /* Update the name in the top element of input_file_stack. */
2565 if (input_file_stack)
2566 input_file_stack->name = input_filename;
2569 /* `1' after file name means entering new file.
2570 `2' after file name means just left a file. */
2572 if (action_number == 1)
2574 action = act_push;
2575 read_line_number (&action_number);
2577 else if (action_number == 2)
2579 action = act_pop;
2580 read_line_number (&action_number);
2582 if (action_number == 3)
2584 /* `3' after file name means this is a system header file. */
2585 in_system_header = 1;
2586 read_line_number (&action_number);
2588 if (action_number == 4)
2590 /* `4' after file name means this is a C header file. */
2591 entering_c_header = 1;
2592 read_line_number (&action_number);
2595 /* Do the actions implied by the preceding numbers. */
2597 if (action == act_push)
2599 /* Pushing to a new file. */
2600 struct file_stack *p
2601 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2602 input_file_stack->line = old_lineno;
2603 p->next = input_file_stack;
2604 p->name = input_filename;
2605 p->indent_level = indent_level;
2606 input_file_stack = p;
2607 input_file_stack_tick++;
2608 debug_start_source_file (input_filename);
2609 if (c_header_level)
2610 ++c_header_level;
2611 else if (entering_c_header)
2613 c_header_level = 1;
2614 ++pending_lang_change;
2617 else if (action == act_pop)
2619 /* Popping out of a file. */
2620 if (input_file_stack->next)
2622 struct file_stack *p = input_file_stack;
2624 if (c_header_level && --c_header_level == 0)
2626 if (entering_c_header)
2627 warning ("badly nested C headers from preprocessor");
2628 --pending_lang_change;
2631 if (indent_level != p->indent_level)
2633 warning_with_file_and_line
2634 (p->name, old_lineno,
2635 "This file contains more `%c's than `%c's.",
2636 indent_level > p->indent_level ? '{' : '}',
2637 indent_level > p->indent_level ? '}' : '{');
2639 input_file_stack = p->next;
2640 free (p);
2641 input_file_stack_tick++;
2642 debug_end_source_file (input_file_stack->line);
2644 else
2645 error ("#-lines for entering and leaving files don't match");
2648 /* Now that we've pushed or popped the input stack,
2649 update the name in the top element. */
2650 if (input_file_stack)
2651 input_file_stack->name = input_filename;
2653 /* skip the rest of this line. */
2654 skipline:
2655 linemode = 0;
2656 end_of_file = 0;
2659 c = getch ();
2660 while (c != '\n' && c != EOF);
2661 return c;
2664 #ifdef HANDLE_GENERIC_PRAGMAS
2666 /* Handle a #pragma directive.
2667 TOKEN is the token we read after `#pragma'. Processes the entire input
2668 line and return non-zero iff the pragma has been successfully parsed. */
2670 /* This function has to be in this file, in order to get at
2671 the token types. */
2673 static int
2674 handle_generic_pragma (token)
2675 register int token;
2677 for (;;)
2679 switch (token)
2681 case IDENTIFIER:
2682 case TYPENAME:
2683 case STRING:
2684 case CONSTANT:
2685 handle_pragma_token (token_buffer, yylval.ttype);
2686 break;
2688 case LEFT_RIGHT:
2689 handle_pragma_token ("(", NULL_TREE);
2690 handle_pragma_token (")", NULL_TREE);
2691 break;
2693 case END_OF_LINE:
2694 return handle_pragma_token (NULL_PTR, NULL_TREE);
2696 default:
2697 handle_pragma_token (token_buffer, NULL_TREE);
2700 token = real_yylex ();
2703 #endif /* HANDLE_GENERIC_PRAGMAS */
2705 static int
2706 handle_cp_pragma (pname)
2707 const char *pname;
2709 register int token;
2711 if (! strcmp (pname, "vtable"))
2713 /* More follows: it must be a string constant (class name). */
2714 token = real_yylex ();
2715 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2717 error ("invalid #pragma vtable");
2718 return -1;
2721 pending_vtables
2722 = tree_cons (NULL_TREE,
2723 get_identifier (TREE_STRING_POINTER (yylval.ttype)),
2724 pending_vtables);
2725 token = real_yylex ();
2726 if (token != END_OF_LINE)
2727 warning ("trailing characters ignored");
2728 return 1;
2730 else if (! strcmp (pname, "unit"))
2732 /* More follows: it must be a string constant (unit name). */
2733 token = real_yylex ();
2734 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2736 error ("invalid #pragma unit");
2737 return -1;
2739 token = real_yylex ();
2740 if (token != END_OF_LINE)
2741 warning ("trailing characters ignored");
2742 return 1;
2744 else if (! strcmp (pname, "interface"))
2746 char *main_filename = input_filename;
2748 main_filename = file_name_nondirectory (main_filename);
2750 token = real_yylex ();
2752 if (token != END_OF_LINE)
2754 if (token != STRING
2755 || TREE_CODE (yylval.ttype) != STRING_CST)
2757 error ("invalid `#pragma interface'");
2758 return -1;
2760 main_filename = TREE_STRING_POINTER (yylval.ttype);
2761 token = real_yylex ();
2764 if (token != END_OF_LINE)
2765 warning ("garbage after `#pragma interface' ignored");
2767 cp_pragma_interface (main_filename);
2769 return 1;
2771 else if (! strcmp (pname, "implementation"))
2773 char *main_filename = main_input_filename ? main_input_filename : input_filename;
2775 main_filename = file_name_nondirectory (main_filename);
2777 token = real_yylex ();
2779 if (token != END_OF_LINE)
2781 if (token != STRING
2782 || TREE_CODE (yylval.ttype) != STRING_CST)
2784 error ("invalid `#pragma implementation'");
2785 return -1;
2787 main_filename = TREE_STRING_POINTER (yylval.ttype);
2788 token = real_yylex ();
2791 if (token != END_OF_LINE)
2792 warning ("garbage after `#pragma implementation' ignored");
2794 cp_pragma_implementation (main_filename);
2796 return 1;
2799 return 0;
2802 void
2803 do_pending_lang_change ()
2805 for (; pending_lang_change > 0; --pending_lang_change)
2806 push_lang_context (lang_name_c);
2807 for (; pending_lang_change < 0; ++pending_lang_change)
2808 pop_lang_context ();
2811 #define ENDFILE -1 /* token that represents end-of-file */
2813 /* Read an escape sequence, returning its equivalent as a character,
2814 or store 1 in *ignore_ptr if it is backslash-newline. */
2816 static int
2817 readescape (ignore_ptr)
2818 int *ignore_ptr;
2820 register int c = getch ();
2821 register int code;
2822 register unsigned count;
2823 unsigned firstdig = 0;
2824 int nonnull;
2826 switch (c)
2828 case 'x':
2829 code = 0;
2830 count = 0;
2831 nonnull = 0;
2832 while (1)
2834 c = getch ();
2835 if (! ISXDIGIT (c))
2837 put_back (c);
2838 break;
2840 code *= 16;
2841 if (c >= 'a' && c <= 'f')
2842 code += c - 'a' + 10;
2843 if (c >= 'A' && c <= 'F')
2844 code += c - 'A' + 10;
2845 if (c >= '0' && c <= '9')
2846 code += c - '0';
2847 if (code != 0 || count != 0)
2849 if (count == 0)
2850 firstdig = code;
2851 count++;
2853 nonnull = 1;
2855 if (! nonnull)
2856 error ("\\x used with no following hex digits");
2857 else if (count == 0)
2858 /* Digits are all 0's. Ok. */
2860 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
2861 || (count > 1
2862 && (((unsigned)1
2863 << (TYPE_PRECISION (integer_type_node)
2864 - (count - 1) * 4))
2865 <= firstdig)))
2866 pedwarn ("hex escape out of range");
2867 return code;
2869 case '0': case '1': case '2': case '3': case '4':
2870 case '5': case '6': case '7':
2871 code = 0;
2872 count = 0;
2873 while ((c <= '7') && (c >= '0') && (count++ < 3))
2875 code = (code * 8) + (c - '0');
2876 c = getch ();
2878 put_back (c);
2879 return code;
2881 case '\\': case '\'': case '"':
2882 return c;
2884 case '\n':
2885 lineno++;
2886 *ignore_ptr = 1;
2887 return 0;
2889 case 'n':
2890 return TARGET_NEWLINE;
2892 case 't':
2893 return TARGET_TAB;
2895 case 'r':
2896 return TARGET_CR;
2898 case 'f':
2899 return TARGET_FF;
2901 case 'b':
2902 return TARGET_BS;
2904 case 'a':
2905 return TARGET_BELL;
2907 case 'v':
2908 return TARGET_VT;
2910 case 'e':
2911 case 'E':
2912 if (pedantic)
2913 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
2914 return 033;
2916 case '?':
2917 return c;
2919 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
2920 case '(':
2921 case '{':
2922 case '[':
2923 /* `\%' is used to prevent SCCS from getting confused. */
2924 case '%':
2925 if (pedantic)
2926 pedwarn ("unknown escape sequence `\\%c'", c);
2927 return c;
2929 if (ISGRAPH (c))
2930 pedwarn ("unknown escape sequence `\\%c'", c);
2931 else
2932 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
2933 return c;
2936 void
2937 yyerror (string)
2938 const char *string;
2940 extern int end_of_file;
2942 /* We can't print string and character constants well
2943 because the token_buffer contains the result of processing escapes. */
2944 if (end_of_file)
2946 if (input_redirected ())
2947 error ("%s at end of saved text", string);
2948 else
2949 error ("%s at end of input", string);
2951 else if (token_buffer[0] == 0)
2952 error ("%s at null character", string);
2953 else if (token_buffer[0] == '"')
2954 error ("%s before string constant", string);
2955 else if (token_buffer[0] == '\'')
2956 error ("%s before character constant", string);
2957 else if (!ISGRAPH ((unsigned char)token_buffer[0]))
2958 error ("%s before character 0%o", string, (unsigned char) token_buffer[0]);
2959 else
2960 error ("%s before `%s'", string, token_buffer);
2963 /* Value is 1 (or 2) if we should try to make the next identifier look like
2964 a typename (when it may be a local variable or a class variable).
2965 Value is 0 if we treat this name in a default fashion. */
2966 int looking_for_typename;
2968 inline int
2969 identifier_type (decl)
2970 tree decl;
2972 tree t;
2973 if (TREE_CODE (decl) == TEMPLATE_DECL)
2975 if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL)
2976 return PTYPENAME;
2977 else if (looking_for_template)
2978 return PFUNCNAME;
2980 if (looking_for_template && really_overloaded_fn (decl))
2982 /* See through a baselink. */
2983 if (TREE_CODE (decl) == TREE_LIST)
2984 decl = TREE_VALUE (decl);
2986 for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t))
2987 if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t)))
2988 return PFUNCNAME;
2990 if (TREE_CODE (decl) == NAMESPACE_DECL)
2991 return NSNAME;
2992 if (TREE_CODE (decl) != TYPE_DECL)
2993 return IDENTIFIER;
2994 if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type)
2995 return SELFNAME;
2997 /* A constructor declarator for a template type will get here as an
2998 implicit typename, a TYPENAME_TYPE with a type. */
2999 t = got_scope;
3000 if (t && TREE_CODE (t) == TYPENAME_TYPE)
3001 t = TREE_TYPE (t);
3002 decl = TREE_TYPE (decl);
3003 if (TREE_CODE (decl) == TYPENAME_TYPE)
3004 decl = TREE_TYPE (decl);
3005 if (t && t == decl)
3006 return SELFNAME;
3008 return TYPENAME;
3011 void
3012 see_typename ()
3014 /* Only types expected, not even namespaces. */
3015 looking_for_typename = 2;
3016 if (yychar < 0)
3017 if ((yychar = yylex ()) < 0) yychar = 0;
3018 looking_for_typename = 0;
3019 if (yychar == IDENTIFIER)
3021 lastiddecl = lookup_name (yylval.ttype, -2);
3022 if (lastiddecl == 0)
3024 if (flag_labels_ok)
3025 lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype);
3027 else
3028 yychar = identifier_type (lastiddecl);
3032 /* Return true if d is in a global scope. */
3034 static int
3035 is_global (d)
3036 tree d;
3038 while (1)
3039 switch (TREE_CODE (d))
3041 case ERROR_MARK:
3042 return 1;
3044 case OVERLOAD: d = OVL_FUNCTION (d); continue;
3045 case TREE_LIST: d = TREE_VALUE (d); continue;
3046 default:
3047 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (d)) == 'd', 980629);
3049 return DECL_NAMESPACE_SCOPE_P (d);
3053 tree
3054 do_identifier (token, parsing, args)
3055 register tree token;
3056 int parsing;
3057 tree args;
3059 register tree id;
3060 int lexing = (parsing == 1);
3061 int in_call = (parsing == 2);
3063 if (! lexing || IDENTIFIER_OPNAME_P (token))
3064 id = lookup_name (token, 0);
3065 else
3066 id = lastiddecl;
3068 /* Do Koenig lookup if appropriate (inside templates we build lookup
3069 expressions instead).
3071 [basic.lookup.koenig]: If the ordinary unqualified lookup of the name
3072 finds the declaration of a class member function, the associated
3073 namespaces and classes are not considered. */
3075 if (args && !current_template_parms && (!id || is_global (id)))
3076 id = lookup_arg_dependent (token, id, args);
3078 /* Remember that this name has been used in the class definition, as per
3079 [class.scope0] */
3080 if (id && parsing)
3081 maybe_note_name_used_in_class (token, id);
3083 if (id == error_mark_node)
3085 /* lookup_name quietly returns error_mark_node if we're parsing,
3086 as we don't want to complain about an identifier that ends up
3087 being used as a declarator. So we call it again to get the error
3088 message. */
3089 id = lookup_name (token, 0);
3090 return error_mark_node;
3093 if (!id)
3095 if (current_template_parms)
3096 return build_min_nt (LOOKUP_EXPR, token);
3097 else if (IDENTIFIER_OPNAME_P (token))
3099 if (token != ansi_opname[ERROR_MARK])
3100 cp_error ("`%D' not defined", token);
3101 id = error_mark_node;
3103 else if (in_call && ! flag_strict_prototype)
3105 id = implicitly_declare (token);
3107 else if (current_function_decl == 0)
3109 cp_error ("`%D' was not declared in this scope", token);
3110 id = error_mark_node;
3112 else
3114 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node
3115 || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
3117 static int undeclared_variable_notice;
3119 cp_error ("`%D' undeclared (first use this function)", token);
3121 if (! undeclared_variable_notice)
3123 error ("(Each undeclared identifier is reported only once");
3124 error ("for each function it appears in.)");
3125 undeclared_variable_notice = 1;
3128 id = error_mark_node;
3129 /* Prevent repeated error messages. */
3130 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3131 SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
3135 if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
3137 tree shadowed = DECL_SHADOWED_FOR_VAR (id);
3138 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
3139 && DECL_DEAD_FOR_LOCAL (shadowed))
3140 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
3141 if (!shadowed)
3142 shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id));
3143 if (shadowed)
3145 if (!DECL_ERROR_REPORTED (id))
3147 warning ("name lookup of `%s' changed",
3148 IDENTIFIER_POINTER (token));
3149 cp_warning_at (" matches this `%D' under current ANSI rules",
3150 shadowed);
3151 cp_warning_at (" matches this `%D' under old rules", id);
3152 DECL_ERROR_REPORTED (id) = 1;
3154 id = shadowed;
3156 else if (!DECL_ERROR_REPORTED (id))
3158 DECL_ERROR_REPORTED (id) = 1;
3159 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id)))
3161 error ("name lookup of `%s' changed for new ANSI `for' scoping",
3162 IDENTIFIER_POINTER (token));
3163 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id);
3164 id = error_mark_node;
3166 else
3168 pedwarn ("name lookup of `%s' changed for new ANSI `for' scoping",
3169 IDENTIFIER_POINTER (token));
3170 cp_pedwarn_at (" using obsolete binding at `%D'", id);
3174 /* TREE_USED is set in `hack_identifier'. */
3175 if (TREE_CODE (id) == CONST_DECL)
3177 /* Check access. */
3178 if (IDENTIFIER_CLASS_VALUE (token) == id)
3179 enforce_access (DECL_REAL_CONTEXT(id), id);
3180 if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
3181 id = DECL_INITIAL (id);
3183 else
3184 id = hack_identifier (id, token);
3186 /* We must look up dependent names when the template is
3187 instantiated, not while parsing it. For now, we don't
3188 distinguish between dependent and independent names. So, for
3189 example, we look up all overloaded functions at
3190 instantiation-time, even though in some cases we should just use
3191 the DECL we have here. We also use LOOKUP_EXPRs to find things
3192 like local variables, rather than creating TEMPLATE_DECLs for the
3193 local variables and then finding matching instantiations. */
3194 if (current_template_parms
3195 && (is_overloaded_fn (id)
3196 /* Some local VAR_DECLs (such as those for local variables
3197 in member functions of local classes) are built on the
3198 permanent obstack. */
3199 || (TREE_CODE (id) == VAR_DECL
3200 && CP_DECL_CONTEXT (id)
3201 && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL)
3202 || TREE_CODE (id) == PARM_DECL
3203 || TREE_CODE (id) == RESULT_DECL
3204 || TREE_CODE (id) == USING_DECL))
3205 id = build_min_nt (LOOKUP_EXPR, token);
3207 return id;
3210 tree
3211 do_scoped_id (token, parsing)
3212 tree token;
3213 int parsing;
3215 tree id;
3216 /* during parsing, this is ::name. Otherwise, it is black magic. */
3217 if (parsing)
3219 id = make_node (CPLUS_BINDING);
3220 if (!qualified_lookup_using_namespace (token, global_namespace, id, 0))
3221 id = NULL_TREE;
3222 else
3223 id = BINDING_VALUE (id);
3225 else
3226 id = IDENTIFIER_GLOBAL_VALUE (token);
3227 if (parsing && yychar == YYEMPTY)
3228 yychar = yylex ();
3229 if (! id)
3231 if (processing_template_decl)
3233 id = build_min_nt (LOOKUP_EXPR, token);
3234 LOOKUP_EXPR_GLOBAL (id) = 1;
3235 return id;
3237 if (parsing && (yychar == '(' || yychar == LEFT_RIGHT)
3238 && ! flag_strict_prototype)
3239 id = implicitly_declare (token);
3240 else
3242 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
3243 cp_error ("`::%D' undeclared (first use here)", token);
3244 id = error_mark_node;
3245 /* Prevent repeated error messages. */
3246 SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3249 else
3251 if (TREE_CODE (id) == ADDR_EXPR)
3252 mark_used (TREE_OPERAND (id, 0));
3253 else if (TREE_CODE (id) != OVERLOAD)
3254 mark_used (id);
3256 if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
3258 /* XXX CHS - should we set TREE_USED of the constant? */
3259 id = DECL_INITIAL (id);
3260 /* This is to prevent an enum whose value is 0
3261 from being considered a null pointer constant. */
3262 id = build1 (NOP_EXPR, TREE_TYPE (id), id);
3263 TREE_CONSTANT (id) = 1;
3266 if (processing_template_decl)
3268 if (is_overloaded_fn (id))
3270 id = build_min_nt (LOOKUP_EXPR, token);
3271 LOOKUP_EXPR_GLOBAL (id) = 1;
3272 return id;
3274 /* else just use the decl */
3276 return convert_from_reference (id);
3279 tree
3280 identifier_typedecl_value (node)
3281 tree node;
3283 tree t, type;
3284 type = IDENTIFIER_TYPE_VALUE (node);
3285 if (type == NULL_TREE)
3286 return NULL_TREE;
3288 if (IDENTIFIER_BINDING (node))
3290 t = IDENTIFIER_VALUE (node);
3291 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3292 return t;
3294 if (IDENTIFIER_NAMESPACE_VALUE (node))
3296 t = IDENTIFIER_NAMESPACE_VALUE (node);
3297 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3298 return t;
3301 /* Will this one ever happen? */
3302 if (TYPE_MAIN_DECL (type))
3303 return TYPE_MAIN_DECL (type);
3305 /* We used to do an internal error of 62 here, but instead we will
3306 handle the return of a null appropriately in the callers. */
3307 return NULL_TREE;
3310 struct pf_args
3312 /* Input */
3313 int base;
3314 char * p;
3315 /* I/O */
3316 int c;
3317 /* Output */
3318 int imag;
3319 tree type;
3320 int conversion_errno;
3321 REAL_VALUE_TYPE value;
3324 static void
3325 parse_float (data)
3326 PTR data;
3328 struct pf_args * args = (struct pf_args *) data;
3329 int fflag = 0, lflag = 0;
3330 /* Copy token_buffer now, while it has just the number
3331 and not the suffixes; once we add `f' or `i',
3332 REAL_VALUE_ATOF may not work any more. */
3333 char *copy = (char *) alloca (args->p - token_buffer + 1);
3334 bcopy (token_buffer, copy, args->p - token_buffer + 1);
3335 args->imag = 0;
3336 args->conversion_errno = 0;
3337 args->type = double_type_node;
3339 while (1)
3341 int lose = 0;
3343 /* Read the suffixes to choose a data type. */
3344 switch (args->c)
3346 case 'f': case 'F':
3347 if (fflag)
3348 error ("more than one `f' in numeric constant");
3349 fflag = 1;
3350 break;
3352 case 'l': case 'L':
3353 if (lflag)
3354 error ("more than one `l' in numeric constant");
3355 lflag = 1;
3356 break;
3358 case 'i': case 'I':
3359 if (args->imag)
3360 error ("more than one `i' or `j' in numeric constant");
3361 else if (pedantic)
3362 pedwarn ("ANSI C++ forbids imaginary numeric constants");
3363 args->imag = 1;
3364 break;
3366 default:
3367 lose = 1;
3370 if (lose)
3371 break;
3373 if (args->p >= token_buffer + maxtoken - 3)
3374 args->p = extend_token_buffer (args->p);
3375 *(args->p++) = args->c;
3376 *(args->p) = 0;
3377 args->c = getch ();
3380 /* The second argument, machine_mode, of REAL_VALUE_ATOF
3381 tells the desired precision of the binary result
3382 of decimal-to-binary conversion. */
3384 if (fflag)
3386 if (lflag)
3387 error ("both `f' and `l' in floating constant");
3389 args->type = float_type_node;
3390 errno = 0;
3391 if (args->base == 16)
3392 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3393 else
3394 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3395 args->conversion_errno = errno;
3396 /* A diagnostic is required here by some ANSI C testsuites.
3397 This is not pedwarn, because some people don't want
3398 an error for this. */
3399 if (REAL_VALUE_ISINF (args->value) && pedantic)
3400 warning ("floating point number exceeds range of `float'");
3402 else if (lflag)
3404 args->type = long_double_type_node;
3405 errno = 0;
3406 if (args->base == 16)
3407 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3408 else
3409 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3410 args->conversion_errno = errno;
3411 if (REAL_VALUE_ISINF (args->value) && pedantic)
3412 warning ("floating point number exceeds range of `long double'");
3414 else
3416 errno = 0;
3417 if (args->base == 16)
3418 args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3419 else
3420 args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3421 args->conversion_errno = errno;
3422 if (REAL_VALUE_ISINF (args->value) && pedantic)
3423 warning ("floating point number exceeds range of `double'");
3427 /* Get the next character, staying within the current token if possible.
3428 If we're lexing a token, we don't want to look beyond the end of the
3429 token cpplib has prepared for us; otherwise, we end up reading in the
3430 next token, which screws up feed_input. So just return a null
3431 character. */
3433 static int
3434 token_getch ()
3436 #if USE_CPPLIB
3437 if (yy_cur == yy_lim)
3438 return '\0';
3439 #endif
3440 return getch ();
3443 static void
3444 token_put_back (ch)
3445 int ch;
3447 #if USE_CPPLIB
3448 if (ch == '\0')
3449 return;
3450 #endif
3451 put_back (ch);
3454 /* Read a single token from the input stream, and assign it lexical
3455 semantics.
3457 Note: We used to do token pasting here, to produce compound tokens like
3458 LEFT_RIGHT and EXTERN_LANG_STRING. That's now handled in spew.c, along
3459 with symbol table interaction and other context-sensitivity. */
3462 real_yylex ()
3464 register int c;
3465 register char *p;
3466 register int value;
3467 int wide_flag = 0;
3469 c = getch ();
3471 /* Effectively do c = skip_white_space (c)
3472 but do it faster in the usual cases. */
3473 while (1)
3474 switch (c)
3476 case ' ':
3477 case '\t':
3478 case '\f':
3479 case '\v':
3480 case '\b':
3481 #if USE_CPPLIB
3482 if (cpp_token == CPP_HSPACE)
3483 c = yy_get_token ();
3484 else
3485 #endif
3486 c = getch ();
3487 break;
3489 case '\r':
3490 /* Call skip_white_space so we can warn if appropriate. */
3492 case '\n':
3493 case '/':
3494 case '\\':
3495 c = skip_white_space (c);
3496 default:
3497 goto found_nonwhite;
3499 found_nonwhite:
3501 token_buffer[0] = c;
3502 token_buffer[1] = 0;
3504 /* yylloc.first_line = lineno; */
3506 switch (c)
3508 case EOF:
3509 end_of_file = 1;
3510 token_buffer[0] = 0;
3511 if (linemode)
3512 value = END_OF_LINE;
3513 else if (input_redirected ())
3514 value = END_OF_SAVED_INPUT;
3515 else
3516 value = ENDFILE;
3517 break;
3519 case 'L':
3520 #if USE_CPPLIB
3521 if (cpp_token == CPP_NAME)
3522 goto letter;
3523 #endif
3524 /* Capital L may start a wide-string or wide-character constant. */
3526 register int c = token_getch ();
3527 if (c == '\'')
3529 wide_flag = 1;
3530 goto char_constant;
3532 if (c == '"')
3534 wide_flag = 1;
3535 goto string_constant;
3537 token_put_back (c);
3540 case 'A': case 'B': case 'C': case 'D': case 'E':
3541 case 'F': case 'G': case 'H': case 'I': case 'J':
3542 case 'K': case 'M': case 'N': case 'O':
3543 case 'P': case 'Q': case 'R': case 'S': case 'T':
3544 case 'U': case 'V': case 'W': case 'X': case 'Y':
3545 case 'Z':
3546 case 'a': case 'b': case 'c': case 'd': case 'e':
3547 case 'f': case 'g': case 'h': case 'i': case 'j':
3548 case 'k': case 'l': case 'm': case 'n': case 'o':
3549 case 'p': case 'q': case 'r': case 's': case 't':
3550 case 'u': case 'v': case 'w': case 'x': case 'y':
3551 case 'z':
3552 case '_':
3553 case '$':
3554 #if USE_CPPLIB
3555 letter:
3556 if (cpp_token == CPP_NAME)
3558 /* Note that one character has already been read from
3559 yy_cur into token_buffer. Also, cpplib complains about
3560 $ in identifiers, so we don't have to. */
3562 int len = yy_lim - yy_cur + 1;
3563 if (len >= maxtoken)
3564 extend_token_buffer_to (len + 1);
3565 memcpy (token_buffer + 1, yy_cur, len);
3566 p = token_buffer + len;
3567 yy_cur = yy_lim;
3569 else
3570 #endif
3572 p = token_buffer;
3573 while (ISALNUM (c) || (c == '_') || c == '$')
3575 /* Make sure this char really belongs in an identifier. */
3576 if (c == '$')
3578 if (! dollars_in_ident)
3579 error ("`$' in identifier");
3580 else if (pedantic)
3581 pedwarn ("`$' in identifier");
3584 if (p >= token_buffer + maxtoken)
3585 p = extend_token_buffer (p);
3587 *p++ = c;
3588 c = token_getch ();
3591 *p = 0;
3592 token_put_back (c);
3595 value = IDENTIFIER;
3596 yylval.itype = 0;
3598 /* Try to recognize a keyword. Uses minimum-perfect hash function */
3601 register struct resword *ptr;
3603 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
3605 if (ptr->rid)
3607 if (ptr->token == VISSPEC)
3609 switch (ptr->rid)
3611 case RID_PUBLIC:
3612 yylval.ttype = access_public_node;
3613 break;
3614 case RID_PRIVATE:
3615 yylval.ttype = access_private_node;
3616 break;
3617 case RID_PROTECTED:
3618 yylval.ttype = access_protected_node;
3619 break;
3620 default:
3621 my_friendly_abort (63);
3624 else
3625 yylval.ttype = ridpointers[(int) ptr->rid];
3627 else switch (ptr->token)
3629 case EQCOMPARE:
3630 yylval.code = NE_EXPR;
3631 token_buffer[0] = '!';
3632 token_buffer[1] = '=';
3633 token_buffer[2] = 0;
3634 break;
3636 case ASSIGN:
3637 if (strcmp ("and_eq", token_buffer) == 0)
3639 yylval.code = BIT_AND_EXPR;
3640 token_buffer[0] = '&';
3642 else if (strcmp ("or_eq", token_buffer) == 0)
3644 yylval.code = BIT_IOR_EXPR;
3645 token_buffer[0] = '|';
3647 else if (strcmp ("xor_eq", token_buffer) == 0)
3649 yylval.code = BIT_XOR_EXPR;
3650 token_buffer[0] = '^';
3652 token_buffer[1] = '=';
3653 token_buffer[2] = 0;
3654 break;
3656 case '&':
3657 yylval.code = BIT_AND_EXPR;
3658 token_buffer[0] = '&';
3659 token_buffer[1] = 0;
3660 break;
3662 case '|':
3663 yylval.code = BIT_IOR_EXPR;
3664 token_buffer[0] = '|';
3665 token_buffer[1] = 0;
3666 break;
3668 case '^':
3669 yylval.code = BIT_XOR_EXPR;
3670 token_buffer[0] = '^';
3671 token_buffer[1] = 0;
3672 break;
3675 value = (int) ptr->token;
3679 /* If we did not find a keyword, look for an identifier
3680 (or a typename). */
3682 if (value == IDENTIFIER || value == TYPESPEC)
3683 GNU_xref_ref (current_function_decl, token_buffer);
3685 if (value == IDENTIFIER)
3687 register tree tmp = get_identifier (token_buffer);
3689 #if !defined(VMS) && defined(JOINER)
3690 /* Make sure that user does not collide with our internal
3691 naming scheme. */
3692 if (JOINER == '$'
3693 && (THIS_NAME_P (tmp)
3694 || VPTR_NAME_P (tmp)
3695 || DESTRUCTOR_NAME_P (tmp)
3696 || VTABLE_NAME_P (tmp)
3697 || TEMP_NAME_P (tmp)
3698 || ANON_AGGRNAME_P (tmp)
3699 || ANON_PARMNAME_P (tmp)))
3700 warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3701 token_buffer);
3702 #endif
3704 yylval.ttype = tmp;
3706 if (value == NEW && ! global_bindings_p ())
3708 value = NEW;
3709 goto done;
3711 break;
3713 case '.':
3714 #if USE_CPPLIB
3715 if (yy_cur < yy_lim)
3716 #endif
3718 /* It's hard to preserve tokenization on '.' because
3719 it could be a symbol by itself, or it could be the
3720 start of a floating point number and cpp won't tell us. */
3721 register int c1 = token_getch ();
3722 token_buffer[1] = c1;
3723 if (c1 == '*')
3725 value = DOT_STAR;
3726 token_buffer[2] = 0;
3727 goto done;
3729 if (c1 == '.')
3731 c1 = token_getch ();
3732 if (c1 == '.')
3734 token_buffer[2] = c1;
3735 token_buffer[3] = 0;
3736 value = ELLIPSIS;
3737 goto done;
3739 error ("parse error at `..'");
3741 if (ISDIGIT (c1))
3743 token_put_back (c1);
3744 goto number;
3746 token_put_back (c1);
3748 value = '.';
3749 token_buffer[1] = 0;
3750 break;
3752 case '0': case '1':
3753 /* Optimize for most frequent case. */
3755 register int cond;
3757 #if USE_CPPLIB
3758 cond = (yy_cur == yy_lim);
3759 #else
3760 register int c1 = token_getch ();
3761 token_put_back (c1);
3762 cond = (! ISALNUM (c1) && c1 != '.');
3763 #endif
3764 if (cond)
3766 yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
3767 value = CONSTANT;
3768 break;
3770 /*FALLTHRU*/
3772 case '2': case '3': case '4':
3773 case '5': case '6': case '7': case '8': case '9':
3774 number:
3776 int base = 10;
3777 int count = 0;
3778 int largest_digit = 0;
3779 int numdigits = 0;
3780 int overflow = 0;
3782 /* We actually store only HOST_BITS_PER_CHAR bits in each part.
3783 The code below which fills the parts array assumes that a host
3784 int is at least twice as wide as a host char, and that
3785 HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
3786 Two HOST_WIDE_INTs is the largest int literal we can store.
3787 In order to detect overflow below, the number of parts (TOTAL_PARTS)
3788 must be exactly the number of parts needed to hold the bits
3789 of two HOST_WIDE_INTs. */
3790 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
3791 unsigned int parts[TOTAL_PARTS];
3793 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON }
3794 floatflag = NOT_FLOAT;
3796 for (count = 0; count < TOTAL_PARTS; count++)
3797 parts[count] = 0;
3799 p = token_buffer;
3800 *p++ = c;
3802 if (c == '0')
3804 *p++ = (c = token_getch ());
3805 if ((c == 'x') || (c == 'X'))
3807 base = 16;
3808 *p++ = (c = token_getch ());
3810 /* Leading 0 forces octal unless the 0 is the only digit. */
3811 else if (c >= '0' && c <= '9')
3813 base = 8;
3814 numdigits++;
3816 else
3817 numdigits++;
3820 /* Read all the digits-and-decimal-points. */
3822 while (c == '.'
3823 || (ISALNUM (c) && c != 'l' && c != 'L'
3824 && c != 'u' && c != 'U'
3825 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
3826 && (floatflag == NOT_FLOAT
3827 || ((base != 16) && (c != 'f') && (c != 'F'))
3828 || base == 16)))
3830 if (c == '.')
3832 if (base == 16 && pedantic)
3833 pedwarn ("floating constant may not be in radix 16");
3834 if (floatflag == TOO_MANY_POINTS)
3835 /* We have already emitted an error. Don't need another. */
3837 else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON)
3839 error ("malformed floating constant");
3840 floatflag = TOO_MANY_POINTS;
3841 /* Avoid another error from atof by forcing all characters
3842 from here on to be ignored. */
3843 p[-1] = '\0';
3845 else
3846 floatflag = AFTER_POINT;
3848 if (base == 8)
3849 base = 10;
3850 *p++ = c = token_getch ();
3851 /* Accept '.' as the start of a floating-point number
3852 only when it is followed by a digit. */
3853 if (p == token_buffer + 2 && !ISDIGIT (c))
3854 my_friendly_abort (990710);
3856 else
3858 /* It is not a decimal point.
3859 It should be a digit (perhaps a hex digit). */
3861 if (ISDIGIT (c))
3863 c = c - '0';
3865 else if (base <= 10)
3867 if (c == 'e' || c == 'E')
3869 base = 10;
3870 floatflag = AFTER_EXPON;
3871 break; /* start of exponent */
3873 error ("nondigits in number and not hexadecimal");
3874 c = 0;
3876 else if (base == 16 && (c == 'p' || c == 'P'))
3878 floatflag = AFTER_EXPON;
3879 break; /* start of exponent */
3881 else if (c >= 'a')
3883 c = c - 'a' + 10;
3885 else
3887 c = c - 'A' + 10;
3889 if (c >= largest_digit)
3890 largest_digit = c;
3891 numdigits++;
3893 for (count = 0; count < TOTAL_PARTS; count++)
3895 parts[count] *= base;
3896 if (count)
3898 parts[count]
3899 += (parts[count-1] >> HOST_BITS_PER_CHAR);
3900 parts[count-1]
3901 &= (1 << HOST_BITS_PER_CHAR) - 1;
3903 else
3904 parts[0] += c;
3907 /* If the highest-order part overflows (gets larger than
3908 a host char will hold) then the whole number has
3909 overflowed. Record this and truncate the highest-order
3910 part. */
3911 if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
3913 overflow = 1;
3914 parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
3917 if (p >= token_buffer + maxtoken - 3)
3918 p = extend_token_buffer (p);
3919 *p++ = (c = token_getch ());
3923 /* This can happen on input like `int i = 0x;' */
3924 if (numdigits == 0)
3925 error ("numeric constant with no digits");
3927 if (largest_digit >= base)
3928 error ("numeric constant contains digits beyond the radix");
3930 /* Remove terminating char from the token buffer and delimit the
3931 string. */
3932 *--p = 0;
3934 if (floatflag != NOT_FLOAT)
3936 tree type;
3937 int imag, conversion_errno;
3938 REAL_VALUE_TYPE value;
3939 struct pf_args args;
3941 /* Read explicit exponent if any, and put it in tokenbuf. */
3943 if ((base == 10 && ((c == 'e') || (c == 'E')))
3944 || (base == 16 && (c == 'p' || c == 'P')))
3946 if (p >= token_buffer + maxtoken - 3)
3947 p = extend_token_buffer (p);
3948 *p++ = c;
3949 c = token_getch ();
3950 if ((c == '+') || (c == '-'))
3952 *p++ = c;
3953 c = token_getch ();
3955 /* Exponent is decimal, even if string is a hex float. */
3956 if (! ISDIGIT (c))
3957 error ("floating constant exponent has no digits");
3958 while (ISDIGIT (c))
3960 if (p >= token_buffer + maxtoken - 3)
3961 p = extend_token_buffer (p);
3962 *p++ = c;
3963 c = token_getch ();
3966 if (base == 16 && floatflag != AFTER_EXPON)
3967 error ("hexadecimal floating constant has no exponent");
3969 *p = 0;
3971 /* Setup input for parse_float() */
3972 args.base = base;
3973 args.p = p;
3974 args.c = c;
3976 /* Convert string to a double, checking for overflow. */
3977 if (do_float_handler (parse_float, (PTR) &args))
3979 /* Receive output from parse_float() */
3980 value = args.value;
3982 else
3984 /* We got an exception from parse_float() */
3985 error ("floating constant out of range");
3986 value = dconst0;
3989 /* Receive output from parse_float() */
3990 c = args.c;
3991 imag = args.imag;
3992 type = args.type;
3993 conversion_errno = args.conversion_errno;
3995 #ifdef ERANGE
3996 /* ERANGE is also reported for underflow,
3997 so test the value to distinguish overflow from that. */
3998 if (conversion_errno == ERANGE && pedantic
3999 && (REAL_VALUES_LESS (dconst1, value)
4000 || REAL_VALUES_LESS (value, dconstm1)))
4001 warning ("floating point number exceeds range of `double'");
4002 #endif
4004 /* If the result is not a number, assume it must have been
4005 due to some error message above, so silently convert
4006 it to a zero. */
4007 if (REAL_VALUE_ISNAN (value))
4008 value = dconst0;
4010 /* Create a node with determined type and value. */
4011 if (imag)
4012 yylval.ttype = build_complex (NULL_TREE,
4013 convert (type, integer_zero_node),
4014 build_real (type, value));
4015 else
4016 yylval.ttype = build_real (type, value);
4018 else
4020 tree type;
4021 HOST_WIDE_INT high, low;
4022 int spec_unsigned = 0;
4023 int spec_long = 0;
4024 int spec_long_long = 0;
4025 int spec_imag = 0;
4026 int warn = 0;
4027 int i;
4029 while (1)
4031 if (c == 'u' || c == 'U')
4033 if (spec_unsigned)
4034 error ("two `u's in integer constant");
4035 spec_unsigned = 1;
4037 else if (c == 'l' || c == 'L')
4039 if (spec_long)
4041 if (spec_long_long)
4042 error ("three `l's in integer constant");
4043 else if (pedantic && ! in_system_header && warn_long_long)
4044 pedwarn ("ANSI C++ forbids long long integer constants");
4045 spec_long_long = 1;
4047 spec_long = 1;
4049 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
4051 if (spec_imag)
4052 error ("more than one `i' or `j' in numeric constant");
4053 else if (pedantic)
4054 pedwarn ("ANSI C++ forbids imaginary numeric constants");
4055 spec_imag = 1;
4057 else
4058 break;
4059 if (p >= token_buffer + maxtoken - 3)
4060 p = extend_token_buffer (p);
4061 *p++ = c;
4062 c = token_getch ();
4065 /* If the literal overflowed, pedwarn about it now. */
4066 if (overflow)
4068 warn = 1;
4069 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
4072 /* This is simplified by the fact that our constant
4073 is always positive. */
4075 high = low = 0;
4077 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
4079 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
4080 / HOST_BITS_PER_CHAR)]
4081 << (i * HOST_BITS_PER_CHAR));
4082 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
4085 yylval.ttype = build_int_2 (low, high);
4086 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
4088 /* Calculate the ANSI type. */
4089 if (! spec_long && ! spec_unsigned
4090 && int_fits_type_p (yylval.ttype, integer_type_node))
4091 type = integer_type_node;
4092 else if (! spec_long && (base != 10 || spec_unsigned)
4093 && int_fits_type_p (yylval.ttype, unsigned_type_node))
4094 type = unsigned_type_node;
4095 else if (! spec_unsigned && !spec_long_long
4096 && int_fits_type_p (yylval.ttype, long_integer_type_node))
4097 type = long_integer_type_node;
4098 else if (! spec_long_long
4099 && int_fits_type_p (yylval.ttype,
4100 long_unsigned_type_node))
4101 type = long_unsigned_type_node;
4102 else if (! spec_unsigned
4103 && int_fits_type_p (yylval.ttype,
4104 long_long_integer_type_node))
4105 type = long_long_integer_type_node;
4106 else if (int_fits_type_p (yylval.ttype,
4107 long_long_unsigned_type_node))
4108 type = long_long_unsigned_type_node;
4109 else if (! spec_unsigned
4110 && int_fits_type_p (yylval.ttype,
4111 widest_integer_literal_type_node))
4112 type = widest_integer_literal_type_node;
4113 else
4114 type = widest_unsigned_literal_type_node;
4116 if (pedantic && !spec_long_long && !warn
4117 && (TYPE_PRECISION (long_integer_type_node)
4118 < TYPE_PRECISION (type)))
4120 warn = 1;
4121 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
4124 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
4125 warning ("decimal constant is so large that it is unsigned");
4127 if (spec_imag)
4129 if (TYPE_PRECISION (type)
4130 <= TYPE_PRECISION (integer_type_node))
4131 yylval.ttype
4132 = build_complex (NULL_TREE, integer_zero_node,
4133 convert (integer_type_node,
4134 yylval.ttype));
4135 else
4136 error ("complex integer constant is too wide for `__complex int'");
4138 else
4139 TREE_TYPE (yylval.ttype) = type;
4142 /* If it's still an integer (not a complex), and it doesn't
4143 fit in the type we choose for it, then pedwarn. */
4145 if (! warn
4146 && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
4147 && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
4148 pedwarn ("integer constant is larger than the maximum value for its type");
4151 token_put_back (c);
4152 *p = 0;
4154 if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
4155 || ((c == '-' || c == '+')
4156 && (p[-1] == 'e' || p[-1] == 'E')))
4157 error ("missing white space after number `%s'", token_buffer);
4159 value = CONSTANT; break;
4162 case '\'':
4163 char_constant:
4165 register int result = 0;
4166 register int num_chars = 0;
4167 int chars_seen = 0;
4168 unsigned width = TYPE_PRECISION (char_type_node);
4169 int max_chars;
4170 #ifdef MULTIBYTE_CHARS
4171 int longest_char = local_mb_cur_max ();
4172 local_mbtowc (NULL_PTR, NULL_PTR, 0);
4173 #endif
4175 max_chars = TYPE_PRECISION (integer_type_node) / width;
4176 if (wide_flag)
4177 width = WCHAR_TYPE_SIZE;
4179 while (1)
4181 tryagain:
4182 c = token_getch ();
4184 if (c == '\'' || c == EOF)
4185 break;
4187 ++chars_seen;
4188 if (c == '\\')
4190 int ignore = 0;
4191 c = readescape (&ignore);
4192 if (ignore)
4193 goto tryagain;
4194 if (width < HOST_BITS_PER_INT
4195 && (unsigned) c >= ((unsigned)1 << width))
4196 pedwarn ("escape sequence out of range for character");
4197 #ifdef MAP_CHARACTER
4198 if (ISPRINT (c))
4199 c = MAP_CHARACTER (c);
4200 #endif
4202 else if (c == '\n')
4204 if (pedantic)
4205 pedwarn ("ANSI C forbids newline in character constant");
4206 lineno++;
4208 else
4210 #ifdef MULTIBYTE_CHARS
4211 wchar_t wc;
4212 int i;
4213 int char_len = -1;
4214 for (i = 1; i <= longest_char; ++i)
4216 if (i > maxtoken - 4)
4217 extend_token_buffer (token_buffer);
4219 token_buffer[i] = c;
4220 char_len = local_mbtowc (& wc,
4221 token_buffer + 1,
4223 if (char_len != -1)
4224 break;
4225 c = token_getch ();
4227 if (char_len > 1)
4229 /* mbtowc sometimes needs an extra char before accepting */
4230 if (char_len < i)
4231 token_put_back (c);
4232 if (! wide_flag)
4234 /* Merge character into result; ignore excess chars. */
4235 for (i = 1; i <= char_len; ++i)
4237 if (i > max_chars)
4238 break;
4239 if (width < HOST_BITS_PER_INT)
4240 result = (result << width)
4241 | (token_buffer[i]
4242 & ((1 << width) - 1));
4243 else
4244 result = token_buffer[i];
4246 num_chars += char_len;
4247 goto tryagain;
4249 c = wc;
4251 else
4253 if (char_len == -1)
4255 warning ("Ignoring invalid multibyte character");
4256 /* Replace all but the first byte. */
4257 for (--i; i > 1; --i)
4258 token_put_back (token_buffer[i]);
4259 wc = token_buffer[1];
4261 #ifdef MAP_CHARACTER
4262 c = MAP_CHARACTER (wc);
4263 #else
4264 c = wc;
4265 #endif
4267 #else /* ! MULTIBYTE_CHARS */
4268 #ifdef MAP_CHARACTER
4269 c = MAP_CHARACTER (c);
4270 #endif
4271 #endif /* ! MULTIBYTE_CHARS */
4274 if (wide_flag)
4276 if (chars_seen == 1) /* only keep the first one */
4277 result = c;
4278 goto tryagain;
4281 /* Merge character into result; ignore excess chars. */
4282 num_chars += (width / TYPE_PRECISION (char_type_node));
4283 if (num_chars < max_chars + 1)
4285 if (width < HOST_BITS_PER_INT)
4286 result = (result << width) | (c & ((1 << width) - 1));
4287 else
4288 result = c;
4292 if (c != '\'')
4293 error ("malformatted character constant");
4294 else if (chars_seen == 0)
4295 error ("empty character constant");
4296 else if (num_chars > max_chars)
4298 num_chars = max_chars;
4299 error ("character constant too long");
4301 else if (chars_seen != 1 && warn_multichar)
4302 warning ("multi-character character constant");
4304 /* If char type is signed, sign-extend the constant. */
4305 if (! wide_flag)
4307 int num_bits = num_chars * width;
4308 if (num_bits == 0)
4309 /* We already got an error; avoid invalid shift. */
4310 yylval.ttype = build_int_2 (0, 0);
4311 else if (TREE_UNSIGNED (char_type_node)
4312 || ((result >> (num_bits - 1)) & 1) == 0)
4313 yylval.ttype
4314 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
4315 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4317 else
4318 yylval.ttype
4319 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
4320 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4321 -1);
4322 /* In C, a character constant has type 'int'; in C++, 'char'. */
4323 if (chars_seen <= 1)
4324 TREE_TYPE (yylval.ttype) = char_type_node;
4325 else
4326 TREE_TYPE (yylval.ttype) = integer_type_node;
4328 else
4330 yylval.ttype = build_int_2 (result, 0);
4331 TREE_TYPE (yylval.ttype) = wchar_type_node;
4334 value = CONSTANT;
4335 break;
4338 case '"':
4339 string_constant:
4341 unsigned width = wide_flag ? WCHAR_TYPE_SIZE
4342 : TYPE_PRECISION (char_type_node);
4343 #ifdef MULTIBYTE_CHARS
4344 int longest_char = local_mb_cur_max ();
4345 local_mbtowc (NULL_PTR, NULL_PTR, 0);
4346 #endif
4348 c = token_getch ();
4349 p = token_buffer + 1;
4351 while (c != '"' && c != EOF)
4353 /* ignore_escape_flag is set for reading the filename in #line. */
4354 if (!ignore_escape_flag && c == '\\')
4356 int ignore = 0;
4357 c = readescape (&ignore);
4358 if (ignore)
4359 goto skipnewline;
4360 if (width < HOST_BITS_PER_INT
4361 && (unsigned) c >= ((unsigned)1 << width))
4362 pedwarn ("escape sequence out of range for character");
4364 else if (c == '\n')
4366 if (pedantic)
4367 pedwarn ("ANSI C++ forbids newline in string constant");
4368 lineno++;
4370 else
4372 #ifdef MULTIBYTE_CHARS
4373 wchar_t wc;
4374 int i;
4375 int char_len = -1;
4376 for (i = 0; i < longest_char; ++i)
4378 if (p + i >= token_buffer + maxtoken)
4379 p = extend_token_buffer (p);
4380 p[i] = c;
4382 char_len = local_mbtowc (& wc, p, i + 1);
4383 if (char_len != -1)
4384 break;
4385 c = token_getch ();
4387 if (char_len == -1)
4389 warning ("Ignoring invalid multibyte character");
4390 /* Replace all except the first byte. */
4391 token_put_back (c);
4392 for (--i; i > 0; --i)
4393 token_put_back (p[i]);
4394 char_len = 1;
4396 /* mbtowc sometimes needs an extra char before accepting */
4397 if (char_len <= i)
4398 token_put_back (c);
4399 if (! wide_flag)
4401 p += (i + 1);
4402 c = token_getch ();
4403 continue;
4405 c = wc;
4406 #endif /* MULTIBYTE_CHARS */
4409 /* Add this single character into the buffer either as a wchar_t
4410 or as a single byte. */
4411 if (wide_flag)
4413 unsigned width = TYPE_PRECISION (char_type_node);
4414 unsigned bytemask = (1 << width) - 1;
4415 int byte;
4417 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4418 p = extend_token_buffer (p);
4420 for (byte = 0; byte < WCHAR_BYTES; ++byte)
4422 int value;
4423 if (byte >= (int) sizeof (c))
4424 value = 0;
4425 else
4426 value = (c >> (byte * width)) & bytemask;
4427 if (BYTES_BIG_ENDIAN)
4428 p[WCHAR_BYTES - byte - 1] = value;
4429 else
4430 p[byte] = value;
4432 p += WCHAR_BYTES;
4434 else
4436 if (p >= token_buffer + maxtoken)
4437 p = extend_token_buffer (p);
4438 *p++ = c;
4441 skipnewline:
4442 c = token_getch ();
4445 /* Terminate the string value, either with a single byte zero
4446 or with a wide zero. */
4447 if (wide_flag)
4449 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4450 p = extend_token_buffer (p);
4451 bzero (p, WCHAR_BYTES);
4452 p += WCHAR_BYTES;
4454 else
4456 if (p >= token_buffer + maxtoken)
4457 p = extend_token_buffer (p);
4458 *p++ = 0;
4461 if (c == EOF)
4462 error ("Unterminated string constant");
4464 /* We have read the entire constant.
4465 Construct a STRING_CST for the result. */
4467 yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1);
4469 if (wide_flag)
4470 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
4471 else
4472 TREE_TYPE (yylval.ttype) = char_array_type_node;
4474 value = STRING; break;
4477 case '+':
4478 case '-':
4479 case '&':
4480 case '|':
4481 case ':':
4482 case '<':
4483 case '>':
4484 case '*':
4485 case '/':
4486 case '%':
4487 case '^':
4488 case '!':
4489 case '=':
4491 register int c1;
4493 combine:
4495 switch (c)
4497 case '+':
4498 yylval.code = PLUS_EXPR; break;
4499 case '-':
4500 yylval.code = MINUS_EXPR; break;
4501 case '&':
4502 yylval.code = BIT_AND_EXPR; break;
4503 case '|':
4504 yylval.code = BIT_IOR_EXPR; break;
4505 case '*':
4506 yylval.code = MULT_EXPR; break;
4507 case '/':
4508 yylval.code = TRUNC_DIV_EXPR; break;
4509 case '%':
4510 yylval.code = TRUNC_MOD_EXPR; break;
4511 case '^':
4512 yylval.code = BIT_XOR_EXPR; break;
4513 case LSHIFT:
4514 yylval.code = LSHIFT_EXPR; break;
4515 case RSHIFT:
4516 yylval.code = RSHIFT_EXPR; break;
4517 case '<':
4518 yylval.code = LT_EXPR; break;
4519 case '>':
4520 yylval.code = GT_EXPR; break;
4523 token_buffer[1] = c1 = token_getch ();
4524 token_buffer[2] = 0;
4526 if (c1 == '=')
4528 switch (c)
4530 case '<':
4531 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
4532 case '>':
4533 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
4534 case '!':
4535 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
4536 case '=':
4537 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
4539 value = ASSIGN; goto done;
4541 else if (c == c1)
4542 switch (c)
4544 case '+':
4545 value = PLUSPLUS; goto done;
4546 case '-':
4547 value = MINUSMINUS; goto done;
4548 case '&':
4549 value = ANDAND; goto done;
4550 case '|':
4551 value = OROR; goto done;
4552 case '<':
4553 c = LSHIFT;
4554 goto combine;
4555 case '>':
4556 c = RSHIFT;
4557 goto combine;
4558 case ':':
4559 value = SCOPE;
4560 yylval.itype = 1;
4561 goto done;
4563 else if (c1 == '?' && (c == '<' || c == '>'))
4565 token_buffer[3] = 0;
4567 c1 = token_getch ();
4568 yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR);
4569 if (c1 == '=')
4571 /* <?= or >?= expression. */
4572 token_buffer[2] = c1;
4573 value = ASSIGN;
4575 else
4577 value = MIN_MAX;
4578 token_put_back (c1);
4580 if (pedantic)
4581 pedwarn ("use of `operator %s' is not standard C++",
4582 token_buffer);
4583 goto done;
4585 else
4586 switch (c)
4588 case '-':
4589 if (c1 == '>')
4591 c1 = token_getch ();
4592 if (c1 == '*')
4593 value = POINTSAT_STAR;
4594 else
4596 token_put_back (c1);
4597 value = POINTSAT;
4599 goto done;
4601 break;
4603 /* digraphs */
4604 case ':':
4605 if (c1 == '>')
4606 { value = ']'; goto done; }
4607 break;
4608 case '<':
4609 if (c1 == '%')
4610 { value = '{'; indent_level++; goto done; }
4611 if (c1 == ':')
4612 { value = '['; goto done; }
4613 break;
4614 case '%':
4615 if (c1 == '>')
4616 { value = '}'; indent_level--; goto done; }
4617 break;
4620 token_put_back (c1);
4621 token_buffer[1] = 0;
4623 /* Here the C frontend changes < and > to ARITHCOMPARE. We don't
4624 do that because of templates. */
4626 value = c;
4627 break;
4630 case 0:
4631 /* Don't make yyparse think this is eof. */
4632 value = 1;
4633 break;
4635 case '{':
4636 indent_level++;
4637 value = c;
4638 break;
4640 case '}':
4641 indent_level--;
4642 value = c;
4643 break;
4645 default:
4646 value = c;
4649 done:
4650 /* yylloc.last_line = lineno; */
4651 #ifdef GATHER_STATISTICS
4652 #ifdef REDUCE_LENGTH
4653 token_count[value] += 1;
4654 #endif
4655 #endif
4657 return value;
4661 is_rid (t)
4662 tree t;
4664 return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
4667 #ifdef GATHER_STATISTICS
4668 /* The original for tree_node_kind is in the toplevel tree.c; changes there
4669 need to be brought into here, unless this were actually put into a header
4670 instead. */
4671 /* Statistics-gathering stuff. */
4672 typedef enum
4674 d_kind,
4675 t_kind,
4676 b_kind,
4677 s_kind,
4678 r_kind,
4679 e_kind,
4680 c_kind,
4681 id_kind,
4682 op_id_kind,
4683 perm_list_kind,
4684 temp_list_kind,
4685 vec_kind,
4686 x_kind,
4687 lang_decl,
4688 lang_type,
4689 all_kinds
4690 } tree_node_kind;
4692 extern int tree_node_counts[];
4693 extern int tree_node_sizes[];
4694 #endif
4696 tree
4697 build_lang_decl (code, name, type)
4698 enum tree_code code;
4699 tree name;
4700 tree type;
4702 tree t;
4704 t = build_decl (code, name, type);
4705 retrofit_lang_decl (t);
4707 return t;
4710 /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
4711 and pushdecl (for functions generated by the backend). */
4713 void
4714 retrofit_lang_decl (t)
4715 tree t;
4717 struct lang_decl *ld;
4718 size_t size;
4720 if (CAN_HAVE_FULL_LANG_DECL_P (t))
4721 size = sizeof (struct lang_decl);
4722 else
4723 size = sizeof (struct lang_decl_flags);
4725 ld = (struct lang_decl *) ggc_alloc (size);
4726 memset (ld, 0, size);
4728 DECL_LANG_SPECIFIC (t) = ld;
4729 if (current_lang_name == lang_name_cplusplus)
4730 DECL_LANGUAGE (t) = lang_cplusplus;
4731 else if (current_lang_name == lang_name_c)
4732 DECL_LANGUAGE (t) = lang_c;
4733 else if (current_lang_name == lang_name_java)
4734 DECL_LANGUAGE (t) = lang_java;
4735 else my_friendly_abort (64);
4737 if (CAN_HAVE_FULL_LANG_DECL_P (t))
4738 DECL_MAIN_VARIANT (t) = t;
4740 #ifdef GATHER_STATISTICS
4741 tree_node_counts[(int)lang_decl] += 1;
4742 tree_node_sizes[(int)lang_decl] += size;
4743 #endif
4746 void
4747 copy_lang_decl (node)
4748 tree node;
4750 int size;
4751 struct lang_decl *ld;
4753 if (! DECL_LANG_SPECIFIC (node))
4754 return;
4756 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
4757 size = sizeof (struct lang_decl_flags);
4758 else
4759 size = sizeof (struct lang_decl);
4760 ld = (struct lang_decl *) ggc_alloc (size);
4761 bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)ld, size);
4762 DECL_LANG_SPECIFIC (node) = ld;
4765 tree
4766 cp_make_lang_type (code)
4767 enum tree_code code;
4769 register tree t = make_node (code);
4771 /* Set up some flags that give proper default behavior. */
4772 if (IS_AGGR_TYPE_CODE (code))
4774 struct lang_type *pi;
4776 pi = (struct lang_type *) ggc_alloc (sizeof (struct lang_type));
4777 bzero ((char *) pi, (int) sizeof (struct lang_type));
4779 TYPE_LANG_SPECIFIC (t) = pi;
4780 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
4781 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
4783 /* Make sure this is laid out, for ease of use later. In the
4784 presence of parse errors, the normal was of assuring this
4785 might not ever get executed, so we lay it out *immediately*. */
4786 build_pointer_type (t);
4788 #ifdef GATHER_STATISTICS
4789 tree_node_counts[(int)lang_type] += 1;
4790 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
4791 #endif
4793 else
4794 /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
4795 TYPE_ALIAS_SET is initialized to -1 by default, so we must
4796 clear it here. */
4797 TYPE_ALIAS_SET (t) = 0;
4799 /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
4800 since they can be virtual base types, and we then need a
4801 canonical binfo for them. Ideally, this would be done lazily for
4802 all types. */
4803 if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM)
4804 TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE);
4806 return t;
4809 tree
4810 make_aggr_type (code)
4811 enum tree_code code;
4813 tree t = cp_make_lang_type (code);
4815 if (IS_AGGR_TYPE_CODE (code))
4816 SET_IS_AGGR_TYPE (t, 1);
4818 return t;
4821 void
4822 dump_time_statistics ()
4824 register tree prev = 0, decl, next;
4825 int this_time = my_get_run_time ();
4826 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
4827 += this_time - body_time;
4829 fprintf (stderr, "\n******\n");
4830 print_time ("header files (total)", header_time);
4831 print_time ("main file (total)", this_time - body_time);
4832 fprintf (stderr, "ratio = %g : 1\n",
4833 (double)header_time / (double)(this_time - body_time));
4834 fprintf (stderr, "\n******\n");
4836 for (decl = filename_times; decl; decl = next)
4838 next = IDENTIFIER_GLOBAL_VALUE (decl);
4839 SET_IDENTIFIER_GLOBAL_VALUE (decl, prev);
4840 prev = decl;
4843 for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl))
4844 print_time (IDENTIFIER_POINTER (decl),
4845 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (decl)));
4848 void
4849 compiler_error VPARAMS ((const char *msg, ...))
4851 #ifndef ANSI_PROTOTYPES
4852 const char *msg;
4853 #endif
4854 char buf[1024];
4855 va_list ap;
4857 VA_START (ap, msg);
4859 #ifndef ANSI_PROTOTYPES
4860 msg = va_arg (ap, const char *);
4861 #endif
4863 vsprintf (buf, msg, ap);
4864 va_end (ap);
4865 error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
4868 /* Return the type-qualifier corresponding to the identifier given by
4869 RID. */
4872 cp_type_qual_from_rid (rid)
4873 tree rid;
4875 if (rid == ridpointers[(int) RID_CONST])
4876 return TYPE_QUAL_CONST;
4877 else if (rid == ridpointers[(int) RID_VOLATILE])
4878 return TYPE_QUAL_VOLATILE;
4879 else if (rid == ridpointers[(int) RID_RESTRICT])
4880 return TYPE_QUAL_RESTRICT;
4882 my_friendly_abort (0);
4883 return TYPE_UNQUALIFIED;