1 /* Separate lexical analyzer for GNU C++.
2 Copyright (C) 1987, 89, 92, 93, 94, 95, 1996 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)
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. */
28 #include <sys/types.h>
42 #ifdef MULTIBYTE_CHARS
48 extern int errno; /* needed for VAX. */
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
54 extern struct obstack permanent_obstack;
55 extern struct obstack *current_obstack, *saveable_obstack;
57 extern double atof ();
59 extern char *get_directive_line (); /* In c-common.c */
61 /* Given a file name X, return the nondirectory portion.
62 Keep in mind that X can be computed more than once. */
63 #ifndef FILE_NAME_NONDIRECTORY
64 #define FILE_NAME_NONDIRECTORY(X) \
65 (rindex (X, '/') != 0 ? rindex (X, '/') + 1 : X)
68 extern char *index ();
69 extern char *rindex ();
72 /* This obstack is needed to hold text. It is not safe to use
73 TOKEN_BUFFER because `check_newline' calls `yylex'. */
74 struct obstack inline_text_obstack;
75 char *inline_text_firstobj;
79 /* Pending language change.
80 Positive is push count, negative is pop count. */
81 int pending_lang_change = 0;
83 /* Wrap the current header file in extern "C". */
84 static int c_header_level = 0;
86 extern int first_token;
87 extern struct obstack token_obstack;
89 /* ??? Don't really know where this goes yet. */
93 extern void put_back (/* int */);
94 extern int input_redirected ();
95 extern void feed_input (/* char *, int */);
98 /* Holds translations from TREE_CODEs to operator name strings,
99 i.e., opname_tab[PLUS_EXPR] == "+". */
103 extern int yychar; /* the lookahead symbol */
104 extern YYSTYPE yylval; /* the semantic value of the */
105 /* lookahead symbol */
108 YYLTYPE yylloc; /* location data for the lookahead */
113 /* the declaration found for the last IDENTIFIER token read in.
114 yylex must look this up to detect typedefs, which get token type TYPENAME,
115 so it is left around in case the identifier is not a typedef but is
116 used in a context which makes it a reference to a variable. */
119 /* The elements of `ridpointers' are identifier nodes
120 for the reserved type names and storage classes.
121 It is indexed by a RID_... value. */
122 tree ridpointers[(int) RID_MAX];
124 /* We may keep statistics about how long which files took to compile. */
125 static int header_time, body_time;
126 static tree get_time_identifier ();
127 static tree filename_times;
128 static tree this_filename_time;
130 /* Array for holding counts of the numbers of tokens seen. */
131 extern int *token_count;
133 /* Return something to represent absolute declarators containing a *.
134 TARGET is the absolute declarator that the * contains.
135 CV_QUALIFIERS is a list of modifiers such as const or volatile
136 to apply to the pointer type, represented as identifiers.
138 We return an INDIRECT_REF whose "contents" are TARGET
139 and whose type is the modifier list. */
142 make_pointer_declarator (cv_qualifiers, target)
143 tree cv_qualifiers, target;
145 if (target && TREE_CODE (target) == IDENTIFIER_NODE
146 && ANON_AGGRNAME_P (target))
147 error ("type name expected before `*'");
148 target = build_parse_node (INDIRECT_REF, target);
149 TREE_TYPE (target) = cv_qualifiers;
153 /* Return something to represent absolute declarators containing a &.
154 TARGET is the absolute declarator that the & contains.
155 CV_QUALIFIERS is a list of modifiers such as const or volatile
156 to apply to the reference type, represented as identifiers.
158 We return an ADDR_EXPR whose "contents" are TARGET
159 and whose type is the modifier list. */
162 make_reference_declarator (cv_qualifiers, target)
163 tree cv_qualifiers, target;
167 if (TREE_CODE (target) == ADDR_EXPR)
169 error ("cannot declare references to references");
172 if (TREE_CODE (target) == INDIRECT_REF)
174 error ("cannot declare pointers to references");
177 if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
178 error ("type name expected before `&'");
180 target = build_parse_node (ADDR_EXPR, target);
181 TREE_TYPE (target) = cv_qualifiers;
186 make_call_declarator (target, parms, cv_qualifiers, exception_specification)
187 tree target, parms, cv_qualifiers, exception_specification;
189 target = build_parse_node (CALL_EXPR, target, parms, cv_qualifiers);
190 TREE_TYPE (target) = exception_specification;
195 set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
196 tree call_declarator, cv_qualifiers, exception_specification;
198 TREE_OPERAND (call_declarator, 2) = cv_qualifiers;
199 TREE_TYPE (call_declarator) = exception_specification;
202 /* Build names and nodes for overloaded operators. */
204 tree ansi_opname[LAST_CPLUS_TREE_CODE];
205 tree ansi_assopname[LAST_CPLUS_TREE_CODE];
208 operator_name_string (name)
211 char *opname = IDENTIFIER_POINTER (name) + 2;
215 /* Works for builtin and user defined types. */
216 if (IDENTIFIER_GLOBAL_VALUE (name)
217 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL)
218 return IDENTIFIER_POINTER (name);
220 if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_')
224 opname_table = ansi_assopname;
229 opname_table = ansi_opname;
232 for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
234 if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign]
235 && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign])
239 if (i == LAST_CPLUS_TREE_CODE)
240 return "<invalid operator>";
243 return assignop_tab[i];
245 return opname_tab[i];
248 int interface_only; /* whether or not current file is only for
249 interface definitions. */
250 int interface_unknown; /* whether or not we know this class
251 to behave according to #pragma interface. */
253 /* lexical analyzer */
255 /* File used for outputting assembler code. */
256 extern FILE *asm_out_file;
258 #ifndef WCHAR_TYPE_SIZE
260 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
262 #define WCHAR_TYPE_SIZE BITS_PER_WORD
266 /* Number of bytes in a wide character. */
267 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
269 static int maxtoken; /* Current nominal length of token buffer. */
270 char *token_buffer; /* Pointer to token buffer.
271 Actual allocated length is maxtoken + 2. */
275 static int check_newline ();
277 /* Nonzero tells yylex to ignore \ in string constants. */
278 static int ignore_escape_flag = 0;
280 static int skip_white_space ();
283 get_time_identifier (name)
286 tree time_identifier;
287 int len = strlen (name);
288 char *buf = (char *) alloca (len + 6);
289 strcpy (buf, "file ");
290 bcopy (name, buf+5, len);
292 time_identifier = get_identifier (buf);
293 if (IDENTIFIER_LOCAL_VALUE (time_identifier) == NULL_TREE)
295 push_obstacks_nochange ();
296 end_temporary_allocation ();
297 IDENTIFIER_LOCAL_VALUE (time_identifier) = build_int_2 (0, 0);
298 IDENTIFIER_CLASS_VALUE (time_identifier) = build_int_2 (0, 1);
299 IDENTIFIER_GLOBAL_VALUE (time_identifier) = filename_times;
300 filename_times = time_identifier;
303 return time_identifier;
312 int old_quiet_flag = quiet_flag;
315 this_time = get_run_time ();
316 quiet_flag = old_quiet_flag;
320 /* Table indexed by tree code giving a string containing a character
321 classifying the tree code. Possibilities are
322 t, d, s, c, r, <, 1 and 2. See cp/cp-tree.def for details. */
324 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
326 char *cplus_tree_code_type[] = {
328 #include "cp-tree.def"
332 /* Table indexed by tree code giving number of expression
333 operands beyond the fixed part of the node structure.
334 Not used for types or decls. */
336 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
338 int cplus_tree_code_length[] = {
340 #include "cp-tree.def"
344 /* Names of tree components.
345 Used for printing out the tree and error messages. */
346 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
348 char *cplus_tree_code_name[] = {
350 #include "cp-tree.def"
354 /* toplev.c needs to call these. */
359 /* the beginning of the file is a new line; check for # */
360 /* With luck, we discover the real source file's name from that
361 and put it in input_filename. */
362 put_back (check_newline ());
363 if (flag_gnu_xref) GNU_xref_begin (input_filename);
364 init_repo (input_filename);
370 extern int errorcount, sorrycount;
371 if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount);
381 init_filename_times ()
383 this_filename_time = get_time_identifier ("<top level>");
384 if (flag_detailed_statistics)
387 body_time = my_get_run_time ();
388 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time)) = body_time;
392 /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
393 Stuck this hack in to get the files open correctly; this is called
394 in place of init_lex if we are an unexec'd binary. */
398 reinit_lang_specific ()
400 init_filename_times ();
401 reinit_search_statistics ();
410 extern char *(*decl_printable_name) ();
411 extern int flag_no_gnu_keywords;
412 extern int flag_operator_names;
416 /* Initialize the lookahead machinery. */
419 /* Make identifier nodes long enough for the language-specific slots. */
420 set_identifier_size (sizeof (struct lang_identifier));
421 decl_printable_name = lang_printable_name;
423 init_cplus_expand ();
426 = (char **) realloc (tree_code_type,
427 sizeof (char *) * LAST_CPLUS_TREE_CODE);
429 = (int *) realloc (tree_code_length,
430 sizeof (int) * LAST_CPLUS_TREE_CODE);
432 = (char **) realloc (tree_code_name,
433 sizeof (char *) * LAST_CPLUS_TREE_CODE);
434 bcopy ((char *)cplus_tree_code_type,
435 (char *)(tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE),
436 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
437 bcopy ((char *)cplus_tree_code_length,
438 (char *)(tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE),
439 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
440 bcopy ((char *)cplus_tree_code_name,
441 (char *)(tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE),
442 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
444 opname_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
445 bzero ((char *)opname_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
446 assignop_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
447 bzero ((char *)assignop_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
449 ansi_opname[0] = get_identifier ("<invalid operator>");
450 for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
452 ansi_opname[i] = ansi_opname[0];
453 ansi_assopname[i] = ansi_opname[0];
456 ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml");
457 IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1;
458 ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR];
459 ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml");
460 IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1;
461 ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR];
462 ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md");
463 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1;
464 ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd");
465 IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1;
466 ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
467 ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
468 ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
469 ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi");
470 IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1;
471 ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR];
472 ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami");
473 IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1;
474 ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR];
475 ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs");
476 IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1;
477 ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars");
478 IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1;
479 ansi_opname[(int) NE_EXPR] = get_identifier ("__ne");
480 IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1;
481 ansi_opname[(int) GT_EXPR] = get_identifier ("__gt");
482 IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1;
483 ansi_opname[(int) GE_EXPR] = get_identifier ("__ge");
484 IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1;
485 ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or");
486 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1;
487 ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor");
488 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1;
489 ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa");
490 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1;
491 ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt");
492 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1;
493 ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp");
494 IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1;
495 ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR];
496 ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as");
497 IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1;
498 ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR];
499 ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm");
500 IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1;
501 ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv");
502 IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1;
503 ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv");
504 IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1;
505 ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
506 ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
507 ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
508 ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
509 ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl");
510 ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
511 ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
512 ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
513 ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
514 IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1;
515 ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl");
516 IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1;
517 ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR];
518 ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR];
519 ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls");
520 IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1;
521 ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als");
522 IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1;
523 ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq");
524 IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1;
525 ansi_opname[(int) LT_EXPR] = get_identifier ("__lt");
526 IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1;
527 ansi_opname[(int) LE_EXPR] = get_identifier ("__le");
528 IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1;
529 ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad");
530 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1;
531 ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad");
532 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1;
533 ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR];
534 ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR];
535 ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er");
536 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1;
537 ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer");
538 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1;
539 ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo");
540 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1;
541 ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co");
542 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1;
543 ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm");
544 IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1;
545 ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR];
546 ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf");
547 IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1;
548 ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm");
549 IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1;
550 ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl");
551 IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1;
552 ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc");
553 IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1;
554 ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw");
555 IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1;
556 ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl");
557 IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1;
558 ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn");
559 IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1;
560 ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd");
561 IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1;
562 ansi_opname[(int) TYPE_EXPR] = get_identifier ("__op");
563 IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1;
565 /* This is not true: these operators are not defined in ANSI,
566 but we need them anyway. */
567 ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn");
568 IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1;
569 ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx");
570 IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1;
571 ansi_opname[(int) COND_EXPR] = get_identifier ("__cn");
572 IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1;
573 ansi_opname[(int) METHOD_CALL_EXPR] = get_identifier ("__wr");
574 IDENTIFIER_OPNAME_P (ansi_opname[(int) METHOD_CALL_EXPR]) = 1;
578 gcc_obstack_init (&inline_text_obstack);
579 inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
581 /* Start it at 0, because check_newline is called at the very beginning
582 and will increment it to 1. */
584 input_filename = "<internal>";
585 current_function_decl = NULL;
588 token_buffer = (char *) xmalloc (maxtoken + 2);
590 ridpointers[(int) RID_INT] = get_identifier ("int");
591 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_INT],
592 build_tree_list (NULL_TREE, ridpointers[(int) RID_INT]));
593 ridpointers[(int) RID_BOOL] = get_identifier ("bool");
594 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_BOOL],
595 build_tree_list (NULL_TREE, ridpointers[(int) RID_BOOL]));
596 ridpointers[(int) RID_CHAR] = get_identifier ("char");
597 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_CHAR],
598 build_tree_list (NULL_TREE, ridpointers[(int) RID_CHAR]));
599 ridpointers[(int) RID_VOID] = get_identifier ("void");
600 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VOID],
601 build_tree_list (NULL_TREE, ridpointers[(int) RID_VOID]));
602 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
603 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_FLOAT],
604 build_tree_list (NULL_TREE, ridpointers[(int) RID_FLOAT]));
605 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
606 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_DOUBLE],
607 build_tree_list (NULL_TREE, ridpointers[(int) RID_DOUBLE]));
608 ridpointers[(int) RID_SHORT] = get_identifier ("short");
609 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_SHORT],
610 build_tree_list (NULL_TREE, ridpointers[(int) RID_SHORT]));
611 ridpointers[(int) RID_LONG] = get_identifier ("long");
612 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_LONG],
613 build_tree_list (NULL_TREE, ridpointers[(int) RID_LONG]));
614 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
615 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_UNSIGNED],
616 build_tree_list (NULL_TREE, ridpointers[(int) RID_UNSIGNED]));
617 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
618 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_SIGNED],
619 build_tree_list (NULL_TREE, ridpointers[(int) RID_SIGNED]));
620 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
621 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_INLINE],
622 build_tree_list (NULL_TREE, ridpointers[(int) RID_INLINE]));
623 ridpointers[(int) RID_CONST] = get_identifier ("const");
624 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_CONST],
625 build_tree_list (NULL_TREE, ridpointers[(int) RID_CONST]));
626 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
627 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VOLATILE],
628 build_tree_list (NULL_TREE, ridpointers[(int) RID_VOLATILE]));
629 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
630 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_AUTO],
631 build_tree_list (NULL_TREE, ridpointers[(int) RID_AUTO]));
632 ridpointers[(int) RID_STATIC] = get_identifier ("static");
633 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_STATIC],
634 build_tree_list (NULL_TREE, ridpointers[(int) RID_STATIC]));
635 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
636 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_EXTERN],
637 build_tree_list (NULL_TREE, ridpointers[(int) RID_EXTERN]));
638 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
639 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_TYPEDEF],
640 build_tree_list (NULL_TREE, ridpointers[(int) RID_TYPEDEF]));
641 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
642 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_REGISTER],
643 build_tree_list (NULL_TREE, ridpointers[(int) RID_REGISTER]));
644 ridpointers[(int) RID_COMPLEX] = get_identifier ("complex");
645 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_COMPLEX],
646 build_tree_list (NULL_TREE, ridpointers[(int) RID_COMPLEX]));
648 /* C++ extensions. These are probably not correctly named. */
649 ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t");
650 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_WCHAR],
651 build_tree_list (NULL_TREE, ridpointers[(int) RID_WCHAR]));
652 class_type_node = build_int_2 (class_type, 0);
653 TREE_TYPE (class_type_node) = class_type_node;
654 ridpointers[(int) RID_CLASS] = class_type_node;
656 record_type_node = build_int_2 (record_type, 0);
657 TREE_TYPE (record_type_node) = record_type_node;
658 ridpointers[(int) RID_RECORD] = record_type_node;
660 union_type_node = build_int_2 (union_type, 0);
661 TREE_TYPE (union_type_node) = union_type_node;
662 ridpointers[(int) RID_UNION] = union_type_node;
664 enum_type_node = build_int_2 (enum_type, 0);
665 TREE_TYPE (enum_type_node) = enum_type_node;
666 ridpointers[(int) RID_ENUM] = enum_type_node;
668 ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual");
669 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VIRTUAL],
670 build_tree_list (NULL_TREE, ridpointers[(int) RID_VIRTUAL]));
671 ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit");
672 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_EXPLICIT],
673 build_tree_list (NULL_TREE, ridpointers[(int) RID_EXPLICIT]));
674 ridpointers[(int) RID_FRIEND] = get_identifier ("friend");
675 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_FRIEND],
676 build_tree_list (NULL_TREE, ridpointers[(int) RID_FRIEND]));
678 ridpointers[(int) RID_PUBLIC] = get_identifier ("public");
679 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PUBLIC],
680 build_tree_list (NULL_TREE, ridpointers[(int) RID_PUBLIC]));
681 ridpointers[(int) RID_PRIVATE] = get_identifier ("private");
682 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PRIVATE],
683 build_tree_list (NULL_TREE, ridpointers[(int) RID_PRIVATE]));
684 ridpointers[(int) RID_PROTECTED] = get_identifier ("protected");
685 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PROTECTED],
686 build_tree_list (NULL_TREE, ridpointers[(int) RID_PROTECTED]));
687 ridpointers[(int) RID_TEMPLATE] = get_identifier ("template");
688 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_TEMPLATE],
689 build_tree_list (NULL_TREE, ridpointers[(int) RID_TEMPLATE]));
690 /* This is for ANSI C++. */
691 ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable");
692 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_MUTABLE],
693 build_tree_list (NULL_TREE, ridpointers[(int) RID_MUTABLE]));
695 /* Signature handling extensions. */
696 signature_type_node = build_int_2 (signature_type, 0);
697 TREE_TYPE (signature_type_node) = signature_type_node;
698 ridpointers[(int) RID_SIGNATURE] = signature_type_node;
700 null_node = build_int_2 (0, 0);
701 ridpointers[RID_NULL] = null_node;
703 opname_tab[(int) COMPONENT_REF] = "->";
704 opname_tab[(int) MEMBER_REF] = "->*";
705 opname_tab[(int) METHOD_CALL_EXPR] = "->()";
706 opname_tab[(int) INDIRECT_REF] = "*";
707 opname_tab[(int) ARRAY_REF] = "[]";
708 opname_tab[(int) MODIFY_EXPR] = "=";
709 opname_tab[(int) NEW_EXPR] = "new";
710 opname_tab[(int) DELETE_EXPR] = "delete";
711 opname_tab[(int) VEC_NEW_EXPR] = "new []";
712 opname_tab[(int) VEC_DELETE_EXPR] = "delete []";
713 opname_tab[(int) COND_EXPR] = "?:";
714 opname_tab[(int) CALL_EXPR] = "()";
715 opname_tab[(int) PLUS_EXPR] = "+";
716 opname_tab[(int) MINUS_EXPR] = "-";
717 opname_tab[(int) MULT_EXPR] = "*";
718 opname_tab[(int) TRUNC_DIV_EXPR] = "/";
719 opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)";
720 opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)";
721 opname_tab[(int) ROUND_DIV_EXPR] = "(round /)";
722 opname_tab[(int) TRUNC_MOD_EXPR] = "%";
723 opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)";
724 opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)";
725 opname_tab[(int) ROUND_MOD_EXPR] = "(round %)";
726 opname_tab[(int) NEGATE_EXPR] = "-";
727 opname_tab[(int) MIN_EXPR] = "<?";
728 opname_tab[(int) MAX_EXPR] = ">?";
729 opname_tab[(int) ABS_EXPR] = "abs";
730 opname_tab[(int) FFS_EXPR] = "ffs";
731 opname_tab[(int) LSHIFT_EXPR] = "<<";
732 opname_tab[(int) RSHIFT_EXPR] = ">>";
733 opname_tab[(int) BIT_IOR_EXPR] = "|";
734 opname_tab[(int) BIT_XOR_EXPR] = "^";
735 opname_tab[(int) BIT_AND_EXPR] = "&";
736 opname_tab[(int) BIT_ANDTC_EXPR] = "&~";
737 opname_tab[(int) BIT_NOT_EXPR] = "~";
738 opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&";
739 opname_tab[(int) TRUTH_ORIF_EXPR] = "||";
740 opname_tab[(int) TRUTH_AND_EXPR] = "strict &&";
741 opname_tab[(int) TRUTH_OR_EXPR] = "strict ||";
742 opname_tab[(int) TRUTH_NOT_EXPR] = "!";
743 opname_tab[(int) LT_EXPR] = "<";
744 opname_tab[(int) LE_EXPR] = "<=";
745 opname_tab[(int) GT_EXPR] = ">";
746 opname_tab[(int) GE_EXPR] = ">=";
747 opname_tab[(int) EQ_EXPR] = "==";
748 opname_tab[(int) NE_EXPR] = "!=";
749 opname_tab[(int) IN_EXPR] = "in";
750 opname_tab[(int) RANGE_EXPR] = "...";
751 opname_tab[(int) CONVERT_EXPR] = "+";
752 opname_tab[(int) ADDR_EXPR] = "&";
753 opname_tab[(int) PREDECREMENT_EXPR] = "--";
754 opname_tab[(int) PREINCREMENT_EXPR] = "++";
755 opname_tab[(int) POSTDECREMENT_EXPR] = "--";
756 opname_tab[(int) POSTINCREMENT_EXPR] = "++";
757 opname_tab[(int) COMPOUND_EXPR] = ",";
759 assignop_tab[(int) NOP_EXPR] = "=";
760 assignop_tab[(int) PLUS_EXPR] = "+=";
761 assignop_tab[(int) CONVERT_EXPR] = "+=";
762 assignop_tab[(int) MINUS_EXPR] = "-=";
763 assignop_tab[(int) NEGATE_EXPR] = "-=";
764 assignop_tab[(int) MULT_EXPR] = "*=";
765 assignop_tab[(int) INDIRECT_REF] = "*=";
766 assignop_tab[(int) TRUNC_DIV_EXPR] = "/=";
767 assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)";
768 assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)";
769 assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)";
770 assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)";
771 assignop_tab[(int) TRUNC_MOD_EXPR] = "%=";
772 assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)";
773 assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)";
774 assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)";
775 assignop_tab[(int) MIN_EXPR] = "<?=";
776 assignop_tab[(int) MAX_EXPR] = ">?=";
777 assignop_tab[(int) LSHIFT_EXPR] = "<<=";
778 assignop_tab[(int) RSHIFT_EXPR] = ">>=";
779 assignop_tab[(int) BIT_IOR_EXPR] = "|=";
780 assignop_tab[(int) BIT_XOR_EXPR] = "^=";
781 assignop_tab[(int) BIT_AND_EXPR] = "&=";
782 assignop_tab[(int) ADDR_EXPR] = "&=";
784 init_filename_times ();
786 /* Some options inhibit certain reserved words.
787 Clear those words out of the hash table so they won't be recognized. */
788 #define UNSET_RESERVED_WORD(STRING) \
789 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
790 if (s) s->name = ""; } while (0)
793 /* let's parse things, and if they use it, then give them an error. */
794 if (!flag_exceptions)
796 UNSET_RESERVED_WORD ("throw");
797 UNSET_RESERVED_WORD ("try");
798 UNSET_RESERVED_WORD ("catch");
802 if (!flag_rtti || flag_no_gnu_keywords)
804 UNSET_RESERVED_WORD ("classof");
805 UNSET_RESERVED_WORD ("headof");
807 if (! flag_handle_signatures || flag_no_gnu_keywords)
809 /* Easiest way to not recognize signature
810 handling extensions... */
811 UNSET_RESERVED_WORD ("signature");
812 UNSET_RESERVED_WORD ("sigof");
814 if (flag_no_gnu_keywords)
815 UNSET_RESERVED_WORD ("complex");
816 if (flag_no_asm || flag_no_gnu_keywords)
817 UNSET_RESERVED_WORD ("typeof");
818 if (! flag_operator_names)
820 /* These are new ANSI keywords that may break code. */
821 UNSET_RESERVED_WORD ("and");
822 UNSET_RESERVED_WORD ("and_eq");
823 UNSET_RESERVED_WORD ("bitand");
824 UNSET_RESERVED_WORD ("bitor");
825 UNSET_RESERVED_WORD ("compl");
826 UNSET_RESERVED_WORD ("not");
827 UNSET_RESERVED_WORD ("not_eq");
828 UNSET_RESERVED_WORD ("or");
829 UNSET_RESERVED_WORD ("or_eq");
830 UNSET_RESERVED_WORD ("xor");
831 UNSET_RESERVED_WORD ("xor_eq");
834 token_count = init_parse ();
835 interface_unknown = 1;
839 reinit_parse_for_function ()
841 current_base_init_list = NULL_TREE;
842 current_member_init_list = NULL_TREE;
849 yyprint (file, yychar, yylval)
861 case IDENTIFIER_DEFN:
864 case TYPENAME_ELLIPSIS:
866 case PRE_PARSED_CLASS_DECL:
868 if (TREE_CODE (t) == TYPE_DECL)
870 fprintf (file, " `%s'", DECL_NAME (t));
873 my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
874 if (IDENTIFIER_POINTER (t))
875 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
878 if (yylval.ttype == class_type_node)
879 fprintf (file, " `class'");
880 else if (yylval.ttype == record_type_node)
881 fprintf (file, " `struct'");
882 else if (yylval.ttype == union_type_node)
883 fprintf (file, " `union'");
884 else if (yylval.ttype == enum_type_node)
885 fprintf (file, " `enum'");
886 else if (yylval.ttype == signature_type_node)
887 fprintf (file, " `signature'");
889 my_friendly_abort (80);
894 #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
895 static int *reduce_count;
901 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
902 #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
908 #ifdef GATHER_STATISTICS
910 reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1));
911 bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1));
913 token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1));
914 bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1));
921 #ifdef GATHER_STATISTICS
927 reduce_count[yyn] += 1;
934 return reduce_count[*q] - reduce_count[*p];
941 return token_count[*q] - token_count[*p];
947 print_parse_statistics ()
949 #ifdef GATHER_STATISTICS
953 int maxlen = REDUCE_LENGTH;
956 if (reduce_count[-1] == 0)
959 if (TOKEN_LENGTH > REDUCE_LENGTH)
960 maxlen = TOKEN_LENGTH;
961 sorted = (unsigned *) alloca (sizeof (int) * maxlen);
963 for (i = 0; i < TOKEN_LENGTH; i++)
965 qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
966 for (i = 0; i < TOKEN_LENGTH; i++)
969 if (token_count[idx] == 0)
971 if (token_count[idx] < token_count[-1])
973 fprintf (stderr, "token %d, `%s', count = %d\n",
974 idx, yytname[YYTRANSLATE (idx)], token_count[idx]);
976 fprintf (stderr, "\n");
977 for (i = 0; i < REDUCE_LENGTH; i++)
979 qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
980 for (i = 0; i < REDUCE_LENGTH; i++)
983 if (reduce_count[idx] == 0)
985 if (reduce_count[idx] < reduce_count[-1])
987 fprintf (stderr, "rule %d, line %d, count = %d\n",
988 idx, yyrline[idx], reduce_count[idx]);
990 fprintf (stderr, "\n");
996 /* Sets the value of the 'yydebug' variable to VALUE.
997 This is a function so we don't have to have YYDEBUG defined
998 in order to build the compiler. */
1008 warning ("YYDEBUG not defined.");
1013 /* Functions and data structures for #pragma interface.
1015 `#pragma implementation' means that the main file being compiled
1016 is considered to implement (provide) the classes that appear in
1017 its main body. I.e., if this is file "foo.cc", and class `bar'
1018 is defined in "foo.cc", then we say that "foo.cc implements bar".
1020 All main input files "implement" themselves automagically.
1022 `#pragma interface' means that unless this file (of the form "foo.h"
1023 is not presently being included by file "foo.cc", the
1024 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
1025 of the vtables nor any of the inline functions defined in foo.h
1026 will ever be output.
1028 There are cases when we want to link files such as "defs.h" and
1029 "main.cc". In this case, we give "defs.h" a `#pragma interface',
1030 and "main.cc" has `#pragma implementation "defs.h"'. */
1035 struct impl_files *next;
1038 static struct impl_files *impl_file_chain;
1040 /* Helper function to load global variables with interface
1044 extract_interface_info ()
1048 if (flag_alt_external_templates)
1050 struct tinst_level *til = tinst_for_decl ();
1053 fileinfo = get_time_identifier (til->file);
1056 fileinfo = get_time_identifier (input_filename);
1057 fileinfo = IDENTIFIER_CLASS_VALUE (fileinfo);
1058 interface_only = TREE_INT_CST_LOW (fileinfo);
1059 interface_unknown = TREE_INT_CST_HIGH (fileinfo);
1062 /* Return nonzero if S is not considered part of an
1063 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
1066 interface_strcmp (s)
1069 /* Set the interface/implementation bits for this scope. */
1070 struct impl_files *ifiles;
1073 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
1075 char *t1 = ifiles->filename;
1078 if (*s1 != *t1 || *s1 == 0)
1081 while (*s1 == *t1 && *s1 != 0)
1088 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
1089 if (index (s1, '.') || index (t1, '.'))
1092 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
1104 set_typedecl_interface_info (prev, vars)
1107 tree id = get_time_identifier (DECL_SOURCE_FILE (vars));
1108 tree fileinfo = IDENTIFIER_CLASS_VALUE (id);
1109 tree type = TREE_TYPE (vars);
1111 CLASSTYPE_INTERFACE_ONLY (type) = TREE_INT_CST_LOW (fileinfo)
1112 = interface_strcmp (FILE_NAME_NONDIRECTORY (DECL_SOURCE_FILE (vars)));
1116 set_vardecl_interface_info (prev, vars)
1119 tree type = DECL_CONTEXT (vars);
1121 if (CLASSTYPE_INTERFACE_KNOWN (type))
1123 if (CLASSTYPE_INTERFACE_ONLY (type))
1124 set_typedecl_interface_info (prev, TYPE_MAIN_DECL (type));
1126 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 1;
1127 DECL_EXTERNAL (vars) = CLASSTYPE_INTERFACE_ONLY (type);
1128 TREE_PUBLIC (vars) = 1;
1134 /* Called from the top level: if there are any pending inlines to
1135 do, set up to process them now. This function sets up the first function
1136 to be parsed; after it has been, the rule for fndef in parse.y will
1137 call process_next_inline to start working on the next one. */
1140 do_pending_inlines ()
1142 struct pending_inline *t;
1145 /* Oops, we're still dealing with the last batch. */
1146 if (yychar == PRE_PARSED_FUNCTION_DECL)
1149 /* Reverse the pending inline functions, since
1150 they were cons'd instead of appended. */
1152 struct pending_inline *prev = 0, *tail;
1153 t = pending_inlines;
1154 pending_inlines = 0;
1169 /* Now start processing the first inline function. */
1170 context = hack_decl_function_context (t->fndecl);
1172 push_cp_function_context (context);
1175 feed_input (t->buf, t->len);
1178 if (input_filename != t->filename)
1180 input_filename = t->filename;
1181 /* Get interface/implementation back in sync. */
1182 extract_interface_info ();
1185 input_filename = t->filename;
1186 interface_unknown = t->interface == 1;
1187 interface_only = t->interface == 0;
1189 yychar = PRE_PARSED_FUNCTION_DECL;
1191 /* Pass back a handle on the rest of the inline functions, so that they
1192 can be processed later. */
1193 yylval.ttype = build_tree_list ((tree) t, t->fndecl);
1194 DECL_PENDING_INLINE_INFO (t->fndecl) = 0;
1197 static int nextchar = -1;
1199 /* Called from the fndecl rule in the parser when the function just parsed
1200 was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1201 do_pending_inlines). */
1204 process_next_inline (t)
1208 struct pending_inline *i = (struct pending_inline *) TREE_PURPOSE (t);
1209 context = hack_decl_function_context (i->fndecl);
1211 pop_cp_function_context (context);
1213 if (yychar == YYEMPTY)
1215 if (yychar != END_OF_SAVED_INPUT)
1217 error ("parse error at end of saved function text");
1219 /* restore_pending_input will abort unless yychar is either
1220 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1221 hosed, feed back YYEMPTY. We also need to discard nextchar,
1222 since that may have gotten set as well. */
1227 if (i && i->fndecl != NULL_TREE)
1229 context = hack_decl_function_context (i->fndecl);
1231 push_cp_function_context (context);
1232 feed_input (i->buf, i->len);
1234 input_filename = i->filename;
1235 yychar = PRE_PARSED_FUNCTION_DECL;
1236 yylval.ttype = build_tree_list ((tree) i, i->fndecl);
1237 DECL_PENDING_INLINE_INFO (i->fndecl) = 0;
1241 interface_unknown = i->interface == 1;
1242 interface_only = i->interface == 0;
1245 extract_interface_info ();
1248 /* Since inline methods can refer to text which has not yet been seen,
1249 we store the text of the method in a structure which is placed in the
1250 DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1251 After parsing the body of the class definition, the FUNCTION_DECL's are
1252 scanned to see which ones have this field set. Those are then digested
1255 This function's FUNCTION_DECL will have a bit set in its common so
1256 that we know to watch out for it. */
1259 consume_string (this_obstack, matching_char)
1260 register struct obstack *this_obstack;
1264 int starting_lineno = lineno;
1270 int save_lineno = lineno;
1271 lineno = starting_lineno;
1272 if (matching_char == '"')
1273 error ("end of file encountered inside string constant");
1275 error ("end of file encountered inside character constant");
1276 lineno = save_lineno;
1281 obstack_1grow (this_obstack, c);
1283 obstack_1grow (this_obstack, c);
1285 /* Make sure we continue the loop */
1292 pedwarn ("ANSI C++ forbids newline in string constant");
1295 obstack_1grow (this_obstack, c);
1297 while (c != matching_char);
1300 static int nextyychar = YYEMPTY;
1301 static YYSTYPE nextyylval;
1303 struct pending_input {
1304 int nextchar, yychar, nextyychar, eof;
1305 YYSTYPE yylval, nextyylval;
1306 struct obstack token_obstack;
1310 struct pending_input *
1311 save_pending_input ()
1313 struct pending_input *p;
1314 p = (struct pending_input *) xmalloc (sizeof (struct pending_input));
1315 p->nextchar = nextchar;
1317 p->nextyychar = nextyychar;
1319 p->nextyylval = nextyylval;
1320 p->eof = end_of_file;
1321 yychar = nextyychar = YYEMPTY;
1323 p->first_token = first_token;
1324 p->token_obstack = token_obstack;
1327 gcc_obstack_init (&token_obstack);
1333 restore_pending_input (p)
1334 struct pending_input *p;
1336 my_friendly_assert (nextchar == -1, 229);
1337 nextchar = p->nextchar;
1338 my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230);
1340 my_friendly_assert (nextyychar == YYEMPTY, 231);
1341 nextyychar = p->nextyychar;
1343 nextyylval = p->nextyylval;
1344 first_token = p->first_token;
1345 obstack_free (&token_obstack, (char *) 0);
1346 token_obstack = p->token_obstack;
1347 end_of_file = p->eof;
1351 /* Return next non-whitespace input character, which may come
1352 from `finput', or from `nextchar'. */
1365 return skip_white_space (c);
1368 /* Unget character CH from the input stream.
1369 If RESCAN is non-zero, then we want to `see' this
1370 character as the next input token. */
1373 yyungetc (ch, rescan)
1377 /* Unget a character from the input stream. */
1378 if (yychar == YYEMPTY || rescan == 0)
1381 put_back (nextchar);
1386 my_friendly_assert (nextyychar == YYEMPTY, 232);
1387 nextyychar = yychar;
1388 nextyylval = yylval;
1394 clear_inline_text_obstack ()
1396 obstack_free (&inline_text_obstack, inline_text_firstobj);
1399 /* This function stores away the text for an inline function that should
1400 be processed later. It decides how much later, and may need to move
1401 the info between obstacks; therefore, the caller should not refer to
1402 the T parameter after calling this function. */
1405 store_pending_inline (decl, t)
1407 struct pending_inline *t;
1410 DECL_PENDING_INLINE_INFO (decl) = t;
1412 /* Because we use obstacks, we must process these in precise order. */
1413 t->next = pending_inlines;
1414 pending_inlines = t;
1417 static void reinit_parse_for_block PROTO((int, struct obstack *));
1420 reinit_parse_for_method (yychar, decl)
1425 int starting_lineno = lineno;
1426 char *starting_filename = input_filename;
1428 reinit_parse_for_block (yychar, &inline_text_obstack);
1430 len = obstack_object_size (&inline_text_obstack);
1431 current_base_init_list = NULL_TREE;
1432 current_member_init_list = NULL_TREE;
1433 if (decl == void_type_node
1434 || (current_class_type && TYPE_REDEFINED (current_class_type)))
1436 /* Happens when we get two declarations of the same
1437 function in the same scope. */
1438 char *buf = obstack_finish (&inline_text_obstack);
1439 obstack_free (&inline_text_obstack, buf);
1444 struct pending_inline *t;
1445 char *buf = obstack_finish (&inline_text_obstack);
1447 t = (struct pending_inline *) obstack_alloc (&inline_text_obstack,
1448 sizeof (struct pending_inline));
1449 t->lineno = starting_lineno;
1450 t->filename = starting_filename;
1457 if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
1458 warn_if_unknown_interface (decl);
1460 t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2));
1461 store_pending_inline (decl, t);
1465 /* Consume a block -- actually, a method beginning
1466 with `:' or `{' -- and save it away on the specified obstack. */
1469 reinit_parse_for_block (pyychar, obstackp)
1471 struct obstack *obstackp;
1475 int starting_lineno = lineno;
1476 char *starting_filename = input_filename;
1478 int look_for_semicolon = 0;
1479 int look_for_lbrac = 0;
1482 obstack_1grow (obstackp, '{');
1483 else if (pyychar == '=')
1484 look_for_semicolon = 1;
1485 else if (pyychar == ':')
1487 obstack_1grow (obstackp, pyychar);
1491 else if (pyychar == RETURN)
1493 obstack_grow (obstackp, "return", 6);
1497 else if (pyychar == TRY)
1499 obstack_grow (obstackp, "try", 3);
1505 yyerror ("parse error in method specification");
1506 obstack_1grow (obstackp, '{');
1509 if (nextchar != EOF)
1519 int this_lineno = lineno;
1521 c = skip_white_space (c);
1523 /* Don't lose our cool if there are lots of comments. */
1524 if (lineno == this_lineno + 1)
1525 obstack_1grow (obstackp, '\n');
1526 else if (lineno == this_lineno)
1528 else if (lineno - this_lineno < 10)
1531 for (i = lineno - this_lineno; i > 0; i--)
1532 obstack_1grow (obstackp, '\n');
1537 sprintf (buf, "\n# %d \"", lineno);
1539 obstack_grow (obstackp, buf, len);
1541 len = strlen (input_filename);
1542 obstack_grow (obstackp, input_filename, len);
1543 obstack_1grow (obstackp, '\"');
1544 obstack_1grow (obstackp, '\n');
1547 while (c > ' ') /* ASCII dependent... */
1549 obstack_1grow (obstackp, c);
1558 if (blev == 0 && !look_for_semicolon)
1562 if (peekyylex () == CATCH)
1565 obstack_grow (obstackp, " catch ", 7);
1582 /* Don't act on the next character...e.g, doing an escaped
1587 error_with_file_and_line (starting_filename,
1589 "end of file read inside definition");
1592 obstack_1grow (obstackp, c);
1595 consume_string (obstackp, c);
1597 consume_string (obstackp, c);
1602 error ("function body for constructor missing");
1603 obstack_1grow (obstackp, '{');
1604 obstack_1grow (obstackp, '}');
1608 else if (look_for_semicolon && blev == 0)
1616 error_with_file_and_line (starting_filename,
1618 "end of file read inside definition");
1623 obstack_1grow (obstackp, c);
1628 obstack_1grow (obstackp, '\0');
1631 /* Consume a no-commas expression -- actually, a default argument -- and
1632 save it away on the specified obstack. */
1635 reinit_parse_for_expr (obstackp)
1636 struct obstack *obstackp;
1639 int starting_lineno = lineno;
1640 char *starting_filename = input_filename;
1642 int look_for_semicolon = 0;
1643 int look_for_lbrac = 0;
1646 if (nextchar != EOF)
1656 int this_lineno = lineno;
1658 c = skip_white_space (c);
1660 /* Don't lose our cool if there are lots of comments. */
1661 if (lineno == this_lineno + 1)
1662 obstack_1grow (obstackp, '\n');
1663 else if (lineno == this_lineno)
1665 else if (lineno - this_lineno < 10)
1668 for (i = lineno - this_lineno; i > 0; --i)
1669 obstack_1grow (obstackp, '\n');
1674 sprintf (buf, "\n# %d \"", lineno);
1676 obstack_grow (obstackp, buf, len);
1678 len = strlen (input_filename);
1679 obstack_grow (obstackp, input_filename, len);
1680 obstack_1grow (obstackp, '\"');
1681 obstack_1grow (obstackp, '\n');
1684 while (c > ' ') /* ASCII dependent... */
1686 if (plev <= 0 && (c == ')' || c == ','))
1691 obstack_1grow (obstackp, c);
1692 if (c == '(' || c == '[')
1694 else if (c == ']' || c == ')')
1698 /* Don't act on the next character...e.g, doing an escaped
1703 error_with_file_and_line (starting_filename,
1705 "end of file read inside definition");
1708 obstack_1grow (obstackp, c);
1711 consume_string (obstackp, c);
1713 consume_string (obstackp, c);
1719 error_with_file_and_line (starting_filename,
1721 "end of file read inside definition");
1726 obstack_1grow (obstackp, c);
1731 obstack_1grow (obstackp, '\0');
1734 int do_snarf_defarg;
1736 /* Decide whether the default argument we are about to see should be
1737 gobbled up as text for later parsing. */
1740 maybe_snarf_defarg ()
1742 if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
1743 do_snarf_defarg = 1;
1746 /* When we see a default argument in a method declaration, we snarf it as
1747 text using snarf_defarg. When we get up to namespace scope, we then go
1748 through and parse all of them using do_pending_defargs. Since yacc
1749 parsers are not reentrant, we retain defargs state in these two
1750 variables so that subsequent calls to do_pending_defargs can resume
1751 where the previous call left off. */
1762 struct pending_inline *t;
1764 reinit_parse_for_expr (&inline_text_obstack);
1765 len = obstack_object_size (&inline_text_obstack);
1766 buf = obstack_finish (&inline_text_obstack);
1768 push_obstacks (&inline_text_obstack, &inline_text_obstack);
1769 arg = make_node (DEFAULT_ARG);
1770 DEFARG_LENGTH (arg) = len - 1;
1771 DEFARG_POINTER (arg) = buf;
1777 /* Called from grokfndecl to note a function decl with unparsed default
1778 arguments for later processing. Also called from grokdeclarator
1779 for function types with unparsed defargs; the call from grokfndecl
1780 will always come second, so we can overwrite the entry from the type. */
1783 add_defarg_fn (decl)
1786 if (TREE_CODE (decl) == FUNCTION_DECL)
1787 TREE_VALUE (defarg_fns) = decl;
1790 push_obstacks (&inline_text_obstack, &inline_text_obstack);
1791 defarg_fns = tree_cons (current_class_type, decl, defarg_fns);
1796 /* Helper for do_pending_defargs. Starts the parsing of a default arg. */
1802 tree d = TREE_PURPOSE (p);
1803 feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d));
1804 if (TREE_CODE (f) == FUNCTION_DECL)
1806 lineno = DECL_SOURCE_LINE (f);
1807 input_filename = DECL_SOURCE_FILE (f);
1809 yychar = DEFARG_MARKER;
1813 /* Helper for do_pending_defargs. Ends the parsing of a default arg. */
1818 if (yychar == YYEMPTY)
1820 if (yychar != END_OF_SAVED_INPUT)
1822 error ("parse error at end of saved function text");
1824 /* restore_pending_input will abort unless yychar is either
1825 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1826 hosed, feed back YYEMPTY. We also need to discard nextchar,
1827 since that may have gotten set as well. */
1834 /* Main function for deferred parsing of default arguments. Called from
1838 do_pending_defargs ()
1843 for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns))
1845 tree defarg_fn = TREE_VALUE (defarg_fns);
1846 if (defarg_parm == NULL_TREE)
1850 push_nested_class (TREE_PURPOSE (defarg_fns), 1);
1853 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1856 for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p))
1857 pushdecl (copy_node (p));
1859 defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn));
1862 defarg_parm = TYPE_ARG_TYPES (defarg_fn);
1865 defarg_parm = TREE_CHAIN (defarg_parm);
1867 for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm))
1868 if (TREE_PURPOSE (defarg_parm))
1870 my_friendly_assert (TREE_CODE (TREE_PURPOSE (defarg_parm))
1871 == DEFAULT_ARG, 2349);
1872 feed_defarg (defarg_fn, defarg_parm);
1874 /* Return to the parser, which will process this defarg
1875 and call us again. */
1880 pop_nested_class (1);
1884 /* Build a default function named NAME for type TYPE.
1885 KIND says what to build.
1887 When KIND == 0, build default destructor.
1888 When KIND == 1, build virtual destructor.
1889 When KIND == 2, build default constructor.
1890 When KIND == 3, build default X(const X&) constructor.
1891 When KIND == 4, build default X(X&) constructor.
1892 When KIND == 5, build default operator = (const X&).
1893 When KIND == 6, build default operator = (X&). */
1896 cons_up_default_function (type, full_name, kind)
1897 tree type, full_name;
1900 extern tree void_list_node;
1901 tree declspecs = NULL_TREE;
1905 tree name = constructor_name (full_name);
1911 declspecs = build_decl_list (NULL_TREE, ridpointers [(int) RID_VIRTUAL]);
1912 /* Fall through... */
1914 name = build_parse_node (BIT_NOT_EXPR, name);
1915 args = void_list_node;
1919 /* Default constructor. */
1920 args = void_list_node;
1924 type = build_type_variant (type, 1, 0);
1925 /* Fall through... */
1927 /* According to ARM $12.8, the default copy ctor will be declared, but
1928 not defined, unless it's needed. */
1929 argtype = build_reference_type (type);
1930 args = tree_cons (NULL_TREE,
1931 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
1932 get_identifier ("_ctor_arg")),
1939 declspecs = build_decl_list (NULL_TREE, type);
1942 type = build_type_variant (type, 1, 0);
1944 name = ansi_opname [(int) MODIFY_EXPR];
1946 argtype = build_reference_type (type);
1947 args = tree_cons (NULL_TREE,
1948 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
1949 get_identifier ("_ctor_arg")),
1954 my_friendly_abort (59);
1957 declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE],
1960 TREE_PARMLIST (args) = 1;
1963 tree declarator = make_call_declarator (name, args, NULL_TREE, NULL_TREE);
1965 declarator = build_parse_node (ADDR_EXPR, declarator);
1967 fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
1970 if (fn == void_type_node)
1974 SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn)));
1977 if (processing_template_defn)
1979 SET_DECL_IMPLICIT_INSTANTIATION (fn);
1980 repo_template_used (fn);
1985 if (CLASSTYPE_INTERFACE_KNOWN (type))
1987 DECL_INTERFACE_KNOWN (fn) = 1;
1988 DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type)
1989 && flag_implement_inlines);
1993 DECL_NOT_REALLY_EXTERN (fn) = 1;
1995 mark_inline_for_output (fn);
1997 #ifdef DEBUG_DEFAULT_FUNCTIONS
1998 { char *fn_type = NULL;
2002 case 0: fn_type = "default destructor"; break;
2003 case 1: fn_type = "virtual destructor"; break;
2004 case 2: fn_type = "default constructor"; break;
2005 case 3: fn_type = "default X(const X&)"; break;
2006 case 4: fn_type = "default X(X&)"; break;
2010 if (TREE_CODE (name) == BIT_NOT_EXPR)
2011 t = TREE_OPERAND (name, 0);
2012 fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type,
2013 IDENTIFIER_POINTER (t), func_buf);
2016 #endif /* DEBUG_DEFAULT_FUNCTIONS */
2018 /* Show that this function was generated by the compiler. */
2019 SET_DECL_ARTIFICIAL (fn);
2024 /* Heuristic to tell whether the user is missing a semicolon
2025 after a struct or enum declaration. Emit an error message
2026 if we know the user has blown it. */
2029 check_for_missing_semicolon (type)
2037 && yychar != IDENTIFIER
2038 && yychar != TYPENAME
2039 && yychar != CV_QUALIFIER
2040 && yychar != SELFNAME)
2043 if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
2044 error ("semicolon missing after %s declaration",
2045 TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
2047 cp_error ("semicolon missing after declaration of `%T'", type);
2048 shadow_tag (build_tree_list (0, type));
2050 /* Could probably also hack cases where class { ... } f (); appears. */
2055 note_got_semicolon (type)
2058 if (TREE_CODE_CLASS (TREE_CODE (type)) != 't')
2059 my_friendly_abort (60);
2060 if (IS_AGGR_TYPE (type))
2061 CLASSTYPE_GOT_SEMICOLON (type) = 1;
2065 note_list_got_semicolon (declspecs)
2070 for (link = declspecs; link; link = TREE_CHAIN (link))
2072 tree type = TREE_VALUE (link);
2073 if (TREE_CODE_CLASS (TREE_CODE (type)) == 't')
2074 note_got_semicolon (type);
2079 /* If C is not whitespace, return C.
2080 Otherwise skip whitespace and return first nonwhite char read. */
2083 skip_white_space (c)
2091 c = check_newline ();
2102 while (c == ' ' || c == '\t');
2110 error ("stray '\\' in program");
2122 /* Make the token buffer longer, preserving the data in it.
2123 P should point to just beyond the last valid character in the old buffer.
2124 The value we return is a pointer to the new buffer
2125 at a place corresponding to P. */
2128 extend_token_buffer (p)
2131 int offset = p - token_buffer;
2133 maxtoken = maxtoken * 2 + 10;
2134 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
2136 return token_buffer + offset;
2140 get_last_nonwhite_on_line ()
2144 /* Is this the last nonwhite stuff on the line? */
2146 c = nextchar, nextchar = -1;
2150 while (c == ' ' || c == '\t')
2155 /* At the beginning of a line, increment the line number
2156 and process any #-directive on this line.
2157 If the line is a #-directive, read the entire line and return a newline.
2158 Otherwise, return the line's first non-whitespace character. */
2162 #ifdef HANDLE_SYSV_PRAGMA
2163 static int handle_sysv_pragma ();
2165 static int handle_cp_pragma ();
2173 /* Read first nonwhite char on the line. Do this before incrementing the
2174 line number, in case we're at the end of saved text. */
2178 while (c == ' ' || c == '\t');
2184 /* If not #, return it so caller will use it. */
2188 /* Don't read beyond this line. */
2191 /* Read first nonwhite char after the `#'. */
2195 while (c == ' ' || c == '\t');
2197 /* If a letter follows, then if the word here is `line', skip
2198 it and ignore it; otherwise, ignore the line, with an error
2199 if the word isn't `pragma'. */
2201 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
2211 token = real_yylex ();
2212 if (token == IDENTIFIER
2213 && TREE_CODE (yylval.ttype) == IDENTIFIER_NODE)
2215 /* If this is 1, we handled it; if it's -1, it was one we
2216 wanted but had something wrong with it. Only if it's
2217 0 was it not handled. */
2218 if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype)))
2221 else if (token == END_OF_LINE)
2224 #ifdef HANDLE_SYSV_PRAGMA
2225 if (handle_sysv_pragma (finput, token))
2228 #ifdef HANDLE_PRAGMA
2229 if (HANDLE_PRAGMA (finput, yylval.ttype))
2243 && ((c = getch ()) == ' ' || c == '\t'))
2245 debug_define (lineno, get_directive_line (finput));
2255 && ((c = getch ()) == ' ' || c == '\t'))
2257 debug_undef (lineno, get_directive_line (finput));
2266 && ((c = getch ()) == ' ' || c == '\t'))
2275 && ((c = getch ()) == ' ' || c == '\t'))
2277 #ifdef ASM_OUTPUT_IDENT
2278 extern FILE *asm_out_file;
2280 /* #ident. The pedantic warning is now in cccp.c. */
2282 /* Here we have just seen `#ident '.
2283 A string constant should follow. */
2285 token = real_yylex ();
2286 if (token == END_OF_LINE)
2289 || TREE_CODE (yylval.ttype) != STRING_CST)
2291 error ("invalid #ident");
2295 if (! flag_no_ident)
2297 #ifdef ASM_OUTPUT_IDENT
2298 ASM_OUTPUT_IDENT (asm_out_file,
2299 TREE_STRING_POINTER (yylval.ttype));
2303 /* Skip the rest of this line. */
2316 && ((c = getch ()) == ' ' || c == '\t'))
2318 /* Used to test incremental compilation. */
2319 sorry ("#pragma newworld");
2323 error ("undefined or invalid # directive");
2328 /* Here we have either `#line' or `# <nonletter>'.
2329 In either case, it should be a line number; a digit should follow. */
2331 while (c == ' ' || c == '\t')
2334 /* If the # is the only nonwhite char on the line,
2335 just ignore it. Check the new newline. */
2339 /* Something follows the #; read a token. */
2342 token = real_yylex ();
2344 if (token == CONSTANT
2345 && TREE_CODE (yylval.ttype) == INTEGER_CST)
2347 int old_lineno = lineno;
2348 enum { act_none, act_push, act_pop } action = act_none;
2349 int entering_system_header = 0;
2350 int entering_c_header = 0;
2352 /* subtract one, because it is the following line that
2353 gets the specified number */
2355 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
2356 c = get_last_nonwhite_on_line ();
2359 /* No more: store the line number and check following line. */
2365 /* More follows: it must be a string constant (filename). */
2367 /* Read the string constant, but don't treat \ as special. */
2368 ignore_escape_flag = 1;
2369 token = real_yylex ();
2370 ignore_escape_flag = 0;
2372 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2374 error ("invalid #line");
2378 /* Changing files again. This means currently collected time
2379 is charged against header time, and body time starts back
2381 if (flag_detailed_statistics)
2383 int this_time = my_get_run_time ();
2384 tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype));
2385 header_time += this_time - body_time;
2386 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time))
2387 += this_time - body_time;
2388 this_filename_time = time_identifier;
2389 body_time = this_time;
2393 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
2394 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
2396 GNU_xref_file (input_filename);
2398 if (main_input_filename == 0)
2400 struct impl_files *ifiles = impl_file_chain;
2404 while (ifiles->next)
2405 ifiles = ifiles->next;
2406 ifiles->filename = FILE_NAME_NONDIRECTORY (input_filename);
2409 main_input_filename = input_filename;
2410 if (write_virtuals == 3)
2411 walk_vtables (set_typedecl_interface_info, set_vardecl_interface_info);
2414 extract_interface_info ();
2416 c = get_last_nonwhite_on_line ();
2419 /* Update the name in the top element of input_file_stack. */
2420 if (input_file_stack)
2421 input_file_stack->name = input_filename;
2427 token = real_yylex ();
2429 /* `1' after file name means entering new file.
2430 `2' after file name means just left a file. */
2432 if (token == CONSTANT
2433 && TREE_CODE (yylval.ttype) == INTEGER_CST)
2435 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
2437 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
2442 c = get_last_nonwhite_on_line ();
2446 token = real_yylex ();
2451 /* `3' after file name means this is a system header file. */
2453 if (token == CONSTANT
2454 && TREE_CODE (yylval.ttype) == INTEGER_CST
2455 && TREE_INT_CST_LOW (yylval.ttype) == 3)
2457 entering_system_header = 1;
2459 c = get_last_nonwhite_on_line ();
2463 token = real_yylex ();
2467 /* `4' after file name means this is a C header file. */
2469 if (token == CONSTANT
2470 && TREE_CODE (yylval.ttype) == INTEGER_CST
2471 && TREE_INT_CST_LOW (yylval.ttype) == 4)
2473 entering_c_header = 1;
2475 c = get_last_nonwhite_on_line ();
2479 token = real_yylex ();
2483 /* Do the actions implied by the preceding numbers. */
2485 if (action == act_push)
2487 /* Pushing to a new file. */
2488 struct file_stack *p;
2490 p = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2491 input_file_stack->line = old_lineno;
2492 p->next = input_file_stack;
2493 p->name = input_filename;
2494 input_file_stack = p;
2495 input_file_stack_tick++;
2496 debug_start_source_file (input_filename);
2497 in_system_header = entering_system_header;
2500 else if (entering_c_header)
2503 ++pending_lang_change;
2506 else if (action == act_pop)
2508 /* Popping out of a file. */
2509 if (input_file_stack->next)
2511 struct file_stack *p;
2513 if (c_header_level && --c_header_level == 0)
2515 if (entering_c_header)
2516 warning ("badly nested C headers from preprocessor");
2517 --pending_lang_change;
2519 in_system_header = entering_system_header;
2521 p = input_file_stack;
2522 input_file_stack = p->next;
2524 input_file_stack_tick++;
2525 debug_end_source_file (input_file_stack->line);
2528 error ("#-lines for entering and leaving files don't match");
2531 in_system_header = entering_system_header;
2534 /* If NEXTCHAR is not end of line, we don't care what it is. */
2535 if (nextchar == EOF)
2539 error ("invalid #-line");
2541 /* skip the rest of this line. */
2546 while ((c = getch ()) != EOF && c != '\n');
2551 do_pending_lang_change ()
2553 for (; pending_lang_change > 0; --pending_lang_change)
2554 push_lang_context (lang_name_c);
2555 for (; pending_lang_change < 0; ++pending_lang_change)
2556 pop_lang_context ();
2560 #define isalnum(char) (char >= 'a' ? char <= 'z' : char >= '0' ? char <= '9' || (char >= 'A' && char <= 'Z') : 0)
2561 #define isdigit(char) (char >= '0' && char <= '9')
2566 #define ENDFILE -1 /* token that represents end-of-file */
2568 /* Read an escape sequence, returning its equivalent as a character,
2569 or store 1 in *ignore_ptr if it is backslash-newline. */
2572 readescape (ignore_ptr)
2575 register int c = getch ();
2577 register unsigned count;
2596 if (c >= 'a' && c <= 'f')
2597 code += c - 'a' + 10;
2598 if (c >= 'A' && c <= 'F')
2599 code += c - 'A' + 10;
2600 if (c >= '0' && c <= '9')
2602 if (code != 0 || count != 0)
2611 error ("\\x used with no following hex digits");
2612 else if (count == 0)
2613 /* Digits are all 0's. Ok. */
2615 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
2617 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
2619 pedwarn ("hex escape out of range");
2622 case '0': case '1': case '2': case '3': case '4':
2623 case '5': case '6': case '7':
2626 while ((c <= '7') && (c >= '0') && (count++ < 3))
2628 code = (code * 8) + (c - '0');
2634 case '\\': case '\'': case '"':
2643 return TARGET_NEWLINE;
2666 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
2672 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
2676 /* `\%' is used to prevent SCCS from getting confused. */
2679 pedwarn ("unknown escape sequence `\\%c'", c);
2682 if (c >= 040 && c < 0177)
2683 pedwarn ("unknown escape sequence `\\%c'", c);
2685 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
2689 /* Value is 1 (or 2) if we should try to make the next identifier look like
2690 a typename (when it may be a local variable or a class variable).
2691 Value is 0 if we treat this name in a default fashion. */
2692 int looking_for_typename = 0;
2695 extern __inline int identifier_type ();
2699 identifier_type (decl)
2702 if (TREE_CODE (decl) == TEMPLATE_DECL)
2704 if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL)
2707 if (TREE_CODE (decl) == NAMESPACE_DECL)
2709 if (TREE_CODE (decl) != TYPE_DECL)
2711 if (((got_scope && TREE_TYPE (decl) == got_scope)
2712 || TREE_TYPE (decl) == current_class_type)
2713 && DECL_ARTIFICIAL (decl))
2721 looking_for_typename = 1;
2723 if ((yychar = yylex ()) < 0) yychar = 0;
2724 looking_for_typename = 0;
2725 if (yychar == IDENTIFIER)
2727 lastiddecl = lookup_name (yylval.ttype, -2);
2728 if (lastiddecl == 0)
2731 lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype);
2734 yychar = identifier_type (lastiddecl);
2739 do_identifier (token, parsing)
2740 register tree token;
2745 if (! parsing || IDENTIFIER_OPNAME_P (token))
2746 id = lookup_name (token, 0);
2750 if (parsing && yychar == YYEMPTY)
2752 /* Scope class declarations before global
2754 if (id == IDENTIFIER_GLOBAL_VALUE (token)
2755 && current_class_type != 0
2756 && TYPE_SIZE (current_class_type) == 0)
2758 /* Could be from one of the base classes. */
2759 tree field = lookup_field (current_class_type, token, 1, 0);
2762 else if (field == error_mark_node)
2763 /* We have already generated the error message.
2764 But we still want to return this value. */
2765 id = lookup_field (current_class_type, token, 0, 0);
2766 else if (TREE_CODE (field) == VAR_DECL
2767 || TREE_CODE (field) == CONST_DECL)
2769 else if (TREE_CODE (field) != FIELD_DECL)
2770 my_friendly_abort (61);
2773 cp_error ("invalid use of member `%D' from base class `%T'", field,
2774 DECL_FIELD_CONTEXT (field));
2775 id = error_mark_node;
2780 /* Remember that this name has been used in the class definition, as per
2782 if (id && current_class_type && parsing
2783 && TYPE_BEING_DEFINED (current_class_type)
2784 && ! IDENTIFIER_CLASS_VALUE (token)
2785 /* Avoid breaking if we get called for a default argument that
2786 refers to an overloaded method. Eventually this will not be
2787 necessary, since default arguments shouldn't be parsed until
2788 after the class is complete. (jason 3/12/97) */
2789 && TREE_CODE (id) != TREE_LIST)
2790 pushdecl_class_level (id);
2792 if (!id || id == error_mark_node)
2794 if (id == error_mark_node && current_class_type != NULL_TREE)
2796 id = lookup_nested_field (token, 1);
2797 /* In lookup_nested_field(), we marked this so we can gracefully
2798 leave this whole mess. */
2799 if (id && id != error_mark_node && TREE_TYPE (id) == error_mark_node)
2803 if (current_template_parms)
2804 return build_min_nt (LOOKUP_EXPR, token, NULL_TREE);
2805 else if (IDENTIFIER_OPNAME_P (token))
2807 if (token != ansi_opname[ERROR_MARK])
2808 cp_error ("`%D' not defined", token);
2809 id = error_mark_node;
2811 else if (parsing && (yychar == '(' || yychar == LEFT_RIGHT))
2813 id = implicitly_declare (token);
2815 else if (current_function_decl == 0)
2817 cp_error ("`%D' was not declared in this scope", token);
2818 id = error_mark_node;
2822 if (IDENTIFIER_GLOBAL_VALUE (token) != error_mark_node
2823 || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
2825 static int undeclared_variable_notice;
2827 cp_error ("`%D' undeclared (first use this function)", token);
2829 if (! undeclared_variable_notice)
2831 error ("(Each undeclared identifier is reported only once");
2832 error ("for each function it appears in.)");
2833 undeclared_variable_notice = 1;
2836 id = error_mark_node;
2837 /* Prevent repeated error messages. */
2838 IDENTIFIER_GLOBAL_VALUE (token) = error_mark_node;
2839 SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
2843 if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
2845 tree shadowed = DECL_SHADOWED_FOR_VAR (id);
2846 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
2847 && DECL_DEAD_FOR_LOCAL (shadowed))
2848 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
2850 shadowed = IDENTIFIER_GLOBAL_VALUE (DECL_NAME (id));
2853 if (!DECL_ERROR_REPORTED (id))
2855 warning ("name lookup of `%s' changed",
2856 IDENTIFIER_POINTER (token));
2857 cp_warning_at (" matches this `%D' under current ANSI rules",
2859 cp_warning_at (" matches this `%D' under old rules", id);
2860 DECL_ERROR_REPORTED (id) = 1;
2864 else if (!DECL_ERROR_REPORTED (id))
2867 = "name lookup of `%s' changed for new ANSI `for' scoping";
2868 DECL_ERROR_REPORTED (id) = 1;
2869 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id)))
2871 error (msg, IDENTIFIER_POINTER (token));
2872 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id);
2873 id = error_mark_node;
2877 pedwarn (msg, IDENTIFIER_POINTER (token));
2878 cp_pedwarn_at (" using obsolete binding at `%D'", id);
2882 /* TREE_USED is set in `hack_identifier'. */
2883 if (TREE_CODE (id) == CONST_DECL)
2885 if (IDENTIFIER_CLASS_VALUE (token) == id)
2888 tree access = compute_access (TYPE_BINFO (current_class_type), id);
2889 if (access == access_private_node)
2890 cp_error ("enum `%D' is private", id);
2891 /* protected is OK, since it's an enum of `this'. */
2893 if (! processing_template_decl
2894 || (DECL_INITIAL (id)
2895 && TREE_CODE (DECL_INITIAL (id)) == TEMPLATE_CONST_PARM))
2896 id = DECL_INITIAL (id);
2899 id = hack_identifier (id, token);
2901 if (current_template_parms)
2903 if (is_overloaded_fn (id))
2905 tree t = build_min (LOOKUP_EXPR, unknown_type_node,
2906 token, get_first_fn (id));
2907 if (id != IDENTIFIER_GLOBAL_VALUE (token))
2908 TREE_OPERAND (t, 1) = error_mark_node;
2911 else if (! TREE_PERMANENT (id) || TREE_CODE (id) == PARM_DECL
2912 || TREE_CODE (id) == USING_DECL)
2913 id = build_min (LOOKUP_EXPR, TREE_TYPE (id), token, error_mark_node);
2914 /* else just use the decl */
2921 do_scoped_id (token, parsing)
2925 tree id = IDENTIFIER_GLOBAL_VALUE (token);
2926 if (parsing && yychar == YYEMPTY)
2930 if (processing_template_decl)
2932 id = build_min_nt (LOOKUP_EXPR, token, NULL_TREE);
2933 LOOKUP_EXPR_GLOBAL (id) = 1;
2936 if (parsing && yychar == '(' || yychar == LEFT_RIGHT)
2937 id = implicitly_declare (token);
2940 if (IDENTIFIER_GLOBAL_VALUE (token) != error_mark_node)
2941 error ("undeclared variable `%s' (first use here)",
2942 IDENTIFIER_POINTER (token));
2943 id = error_mark_node;
2944 /* Prevent repeated error messages. */
2945 IDENTIFIER_GLOBAL_VALUE (token) = error_mark_node;
2950 if (TREE_CODE (id) == ADDR_EXPR)
2951 mark_used (TREE_OPERAND (id, 0));
2952 else if (TREE_CODE (id) != TREE_LIST)
2955 if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
2957 /* XXX CHS - should we set TREE_USED of the constant? */
2958 id = DECL_INITIAL (id);
2959 /* This is to prevent an enum whose value is 0
2960 from being considered a null pointer constant. */
2961 id = build1 (NOP_EXPR, TREE_TYPE (id), id);
2962 TREE_CONSTANT (id) = 1;
2965 if (processing_template_decl)
2967 if (is_overloaded_fn (id))
2969 id = build_min (LOOKUP_EXPR, unknown_type_node,
2970 token, get_first_fn (id));
2971 LOOKUP_EXPR_GLOBAL (id) = 1;
2973 /* else just use the decl */
2975 return convert_from_reference (id);
2979 identifier_typedecl_value (node)
2983 type = IDENTIFIER_TYPE_VALUE (node);
2984 if (type == NULL_TREE)
2989 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) \
2992 do (IDENTIFIER_LOCAL_VALUE (node));
2993 do (IDENTIFIER_CLASS_VALUE (node));
2994 do (IDENTIFIER_GLOBAL_VALUE (node));
2996 /* Will this one ever happen? */
2997 if (TYPE_MAIN_DECL (type))
2998 return TYPE_MAIN_DECL (type);
3000 /* We used to do an internal error of 62 here, but instead we will
3001 handle the return of a null appropriately in the callers. */
3011 int dollar_seen = 0;
3015 c = nextchar, nextchar = -1;
3019 /* Effectively do c = skip_white_space (c)
3020 but do it faster in the usual cases. */
3033 /* Call skip_white_space so we can warn if appropriate. */
3038 c = skip_white_space (c);
3040 goto found_nonwhite;
3044 token_buffer[0] = c;
3045 token_buffer[1] = 0;
3047 /* yylloc.first_line = lineno; */
3052 token_buffer[0] = '\0';
3054 if (input_redirected ())
3055 value = END_OF_SAVED_INPUT;
3057 value = END_OF_LINE;
3063 if (dollars_in_ident)
3072 /* Capital L may start a wide-string or wide-character constant. */
3074 register int c = getch ();
3083 goto string_constant;
3088 case 'A': case 'B': case 'C': case 'D': case 'E':
3089 case 'F': case 'G': case 'H': case 'I': case 'J':
3090 case 'K': case 'M': case 'N': case 'O':
3091 case 'P': case 'Q': case 'R': case 'S': case 'T':
3092 case 'U': case 'V': case 'W': case 'X': case 'Y':
3094 case 'a': case 'b': case 'c': case 'd': case 'e':
3095 case 'f': case 'g': case 'h': case 'i': case 'j':
3096 case 'k': case 'l': case 'm': case 'n': case 'o':
3097 case 'p': case 'q': case 'r': case 's': case 't':
3098 case 'u': case 'v': case 'w': case 'x': case 'y':
3108 /* We know that `token_buffer' can hold at least on char,
3109 so we install C immediately.
3110 We may have to read the value in `putback_char', so call
3115 /* Make this run fast. We know that we are reading straight
3116 from FINPUT in this case (since identifiers cannot straddle
3118 while (isalnum (c) || (c == '_') || c == '$')
3120 if (c == '$' && ! dollars_in_ident)
3122 if (p >= token_buffer + maxtoken)
3123 p = extend_token_buffer (p);
3129 if (linemode && c == '\n')
3137 /* We know that `token_buffer' can hold at least on char,
3138 so we install C immediately. */
3142 while (isalnum (c) || (c == '_') || c == '$')
3144 if (c == '$' && ! dollars_in_ident)
3146 if (p >= token_buffer + maxtoken)
3147 p = extend_token_buffer (p);
3160 /* Try to recognize a keyword. Uses minimum-perfect hash function */
3163 register struct resword *ptr;
3165 if (ptr = is_reserved_word (token_buffer, p - token_buffer))
3169 tree old_ttype = ridpointers[(int) ptr->rid];
3171 /* If this provides a type for us, then revert lexical
3172 state to standard state. */
3173 if (TREE_CODE (old_ttype) == IDENTIFIER_NODE
3174 && IDENTIFIER_GLOBAL_VALUE (old_ttype) != 0
3175 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (old_ttype)) == TYPE_DECL)
3176 looking_for_typename = 0;
3177 else if (ptr->token == AGGR || ptr->token == ENUM)
3178 looking_for_typename = 1;
3180 /* Check if this is a language-type declaration.
3181 Just glimpse the next non-white character. */
3182 nextchar = skip_white_space (nextchar);
3183 if (nextchar == '"')
3185 /* We are looking at a string. Complain
3186 if the token before the string is no `extern'.
3188 Could cheat some memory by placing this string
3189 on the temporary_, instead of the saveable_
3192 if (ptr->rid != RID_EXTERN)
3193 error ("invalid modifier `%s' for language string",
3196 value = EXTERN_LANG_STRING;
3197 yylval.ttype = get_identifier (TREE_STRING_POINTER (yylval.ttype));
3200 if (ptr->token == VISSPEC)
3205 yylval.ttype = access_public_node;
3208 yylval.ttype = access_private_node;
3211 yylval.ttype = access_protected_node;
3214 my_friendly_abort (63);
3218 yylval.ttype = old_ttype;
3220 else if (ptr->token == EQCOMPARE)
3222 yylval.code = NE_EXPR;
3223 token_buffer[0] = '!';
3224 token_buffer[1] = '=';
3225 token_buffer[2] = 0;
3227 else if (ptr->token == ASSIGN)
3229 if (strcmp ("and_eq", token_buffer) == 0)
3231 yylval.code = BIT_AND_EXPR;
3232 token_buffer[0] = '&';
3234 else if (strcmp ("or_eq", token_buffer) == 0)
3236 yylval.code = BIT_IOR_EXPR;
3237 token_buffer[0] = '|';
3239 else if (strcmp ("xor_eq", token_buffer) == 0)
3241 yylval.code = BIT_XOR_EXPR;
3242 token_buffer[0] = '^';
3244 token_buffer[1] = '=';
3245 token_buffer[2] = 0;
3247 else if (ptr->token == '&')
3249 yylval.code = BIT_AND_EXPR;
3250 token_buffer[0] = '&';
3251 token_buffer[1] = 0;
3253 else if (ptr->token == '|')
3255 yylval.code = BIT_IOR_EXPR;
3256 token_buffer[0] = '|';
3257 token_buffer[1] = 0;
3259 else if (ptr->token == '^')
3261 yylval.code = BIT_XOR_EXPR;
3262 token_buffer[0] = '^';
3263 token_buffer[1] = 0;
3266 value = (int) ptr->token;
3270 /* If we did not find a keyword, look for an identifier
3273 if (value == IDENTIFIER || value == TYPESPEC)
3274 GNU_xref_ref (current_function_decl, token_buffer);
3276 if (value == IDENTIFIER)
3278 register tree tmp = get_identifier (token_buffer);
3280 #if !defined(VMS) && defined(JOINER)
3281 /* Make sure that user does not collide with our internal
3285 && (THIS_NAME_P (tmp)
3286 || VPTR_NAME_P (tmp)
3287 || DESTRUCTOR_NAME_P (tmp)
3288 || VTABLE_NAME_P (tmp)
3289 || TEMP_NAME_P (tmp)
3290 || ANON_AGGRNAME_P (tmp)
3291 || ANON_PARMNAME_P (tmp)))
3292 warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3298 /* A user-invisible read-only initialized variable
3299 should be replaced by its value. We only handle strings
3300 since that's the only case used in C (and C++). */
3301 /* Note we go right after the local value for the identifier
3302 (e.g., __FUNCTION__ or __PRETTY_FUNCTION__). We used to
3303 call lookup_name, but that could result in an error about
3305 tmp = IDENTIFIER_LOCAL_VALUE (yylval.ttype);
3306 if (tmp != NULL_TREE
3307 && TREE_CODE (tmp) == VAR_DECL
3308 && DECL_IGNORED_P (tmp)
3309 && TREE_READONLY (tmp)
3310 && DECL_INITIAL (tmp) != NULL_TREE
3311 && TREE_CODE (DECL_INITIAL (tmp)) == STRING_CST)
3313 tree stringval = DECL_INITIAL (tmp);
3315 /* Copy the string value so that we won't clobber anything
3316 if we put something in the TREE_CHAIN of this one. */
3317 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
3318 TREE_STRING_POINTER (stringval));
3322 if (value == NEW && ! global_bindings_p ())
3332 register int c1 = getch ();
3333 token_buffer[0] = c;
3334 token_buffer[1] = c1;
3338 token_buffer[2] = 0;
3346 token_buffer[2] = c1;
3347 token_buffer[3] = 0;
3351 error ("parse error at `..'");
3356 goto resume_numerical_scan;
3360 token_buffer[1] = 0;
3364 /* Optimize for most frequent case. */
3366 register int c1 = getch ();
3367 if (! isalnum (c1) && c1 != '.')
3369 /* Terminate string. */
3370 token_buffer[0] = c;
3371 token_buffer[1] = 0;
3373 yylval.ttype = integer_zero_node;
3375 yylval.ttype = integer_one_node;
3382 /* fall through... */
3383 case '2': case '3': case '4':
3384 case '5': case '6': case '7': case '8': case '9':
3385 resume_numerical_scan:
3390 int largest_digit = 0;
3392 /* for multi-precision arithmetic,
3393 we actually store only HOST_BITS_PER_CHAR bits in each part.
3394 The number of parts is chosen so as to be sufficient to hold
3395 the enough bits to fit into the two HOST_WIDE_INTs that contain
3396 the integer value (this is always at least as many bits as are
3397 in a target `long long' value, but may be wider). */
3398 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
3399 int parts[TOTAL_PARTS];
3402 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
3405 for (count = 0; count < TOTAL_PARTS; count++)
3413 *p++ = (c = getch ());
3414 if ((c == 'x') || (c == 'X'))
3417 *p++ = (c = getch ());
3419 /* Leading 0 forces octal unless the 0 is the only digit. */
3420 else if (c >= '0' && c <= '9')
3429 /* Read all the digits-and-decimal-points. */
3432 || (isalnum (c) && (c != 'l') && (c != 'L')
3433 && (c != 'u') && (c != 'U')
3434 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
3435 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
3440 error ("floating constant may not be in radix 16");
3441 if (floatflag == TOO_MANY_POINTS)
3442 /* We have already emitted an error. Don't need another. */
3444 else if (floatflag == AFTER_POINT)
3446 error ("malformed floating constant");
3447 floatflag = TOO_MANY_POINTS;
3448 /* Avoid another error from atof by forcing all characters
3449 from here on to be ignored. */
3453 floatflag = AFTER_POINT;
3456 *p++ = c = getch ();
3457 /* Accept '.' as the start of a floating-point number
3458 only when it is followed by a digit.
3459 Otherwise, unread the following non-digit
3460 and use the '.' as a structural token. */
3461 if (p == token_buffer + 2 && !isdigit (c))
3473 error ("parse error at `..'");
3476 token_buffer[1] = '\0';
3483 /* It is not a decimal point.
3484 It should be a digit (perhaps a hex digit). */
3490 else if (base <= 10)
3492 if (c == 'e' || c == 'E')
3495 floatflag = AFTER_POINT;
3496 break; /* start of exponent */
3498 error ("nondigits in number and not hexadecimal");
3509 if (c >= largest_digit)
3513 for (count = 0; count < TOTAL_PARTS; count++)
3515 parts[count] *= base;
3519 += (parts[count-1] >> HOST_BITS_PER_CHAR);
3521 &= (1 << HOST_BITS_PER_CHAR) - 1;
3527 /* If the extra highest-order part ever gets anything in it,
3528 the number is certainly too big. */
3529 if (parts[TOTAL_PARTS - 1] != 0)
3532 if (p >= token_buffer + maxtoken - 3)
3533 p = extend_token_buffer (p);
3534 *p++ = (c = getch ());
3539 error ("numeric constant with no digits");
3541 if (largest_digit >= base)
3542 error ("numeric constant contains digits beyond the radix");
3544 /* Remove terminating char from the token buffer and delimit the string */
3547 if (floatflag != NOT_FLOAT)
3549 tree type = double_type_node;
3550 int exceeds_double = 0;
3552 REAL_VALUE_TYPE value;
3555 /* Read explicit exponent if any, and put it in tokenbuf. */
3557 if ((c == 'e') || (c == 'E'))
3559 if (p >= token_buffer + maxtoken - 3)
3560 p = extend_token_buffer (p);
3563 if ((c == '+') || (c == '-'))
3569 error ("floating constant exponent has no digits");
3572 if (p >= token_buffer + maxtoken - 3)
3573 p = extend_token_buffer (p);
3582 /* Convert string to a double, checking for overflow. */
3583 if (setjmp (handler))
3585 error ("floating constant out of range");
3590 int fflag = 0, lflag = 0;
3591 /* Copy token_buffer now, while it has just the number
3592 and not the suffixes; once we add `f' or `i',
3593 REAL_VALUE_ATOF may not work any more. */
3594 char *copy = (char *) alloca (p - token_buffer + 1);
3595 bcopy (token_buffer, copy, p - token_buffer + 1);
3597 set_float_handler (handler);
3603 /* Read the suffixes to choose a data type. */
3608 error ("more than one `f' in numeric constant");
3614 error ("more than one `l' in numeric constant");
3620 error ("more than one `i' or `j' in numeric constant");
3622 pedwarn ("ANSI C++ forbids imaginary numeric constants");
3633 if (p >= token_buffer + maxtoken - 3)
3634 p = extend_token_buffer (p);
3640 /* The second argument, machine_mode, of REAL_VALUE_ATOF
3641 tells the desired precision of the binary result
3642 of decimal-to-binary conversion. */
3647 error ("both `f' and `l' in floating constant");
3649 type = float_type_node;
3650 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
3651 /* A diagnostic is required here by some ANSI C testsuites.
3652 This is not pedwarn, become some people don't want
3653 an error for this. */
3654 if (REAL_VALUE_ISINF (value) && pedantic)
3655 warning ("floating point number exceeds range of `float'");
3659 type = long_double_type_node;
3660 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
3661 if (REAL_VALUE_ISINF (value) && pedantic)
3662 warning ("floating point number exceeds range of `long double'");
3666 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
3667 if (REAL_VALUE_ISINF (value) && pedantic)
3668 warning ("floating point number exceeds range of `double'");
3671 set_float_handler (NULL_PTR);
3674 if (errno == ERANGE && pedantic)
3676 /* ERANGE is also reported for underflow,
3677 so test the value to distinguish overflow from that. */
3678 if (REAL_VALUES_LESS (dconst1, value)
3679 || REAL_VALUES_LESS (value, dconstm1))
3681 pedwarn ("floating point number exceeds range of `%s'",
3682 IDENTIFIER_POINTER (TYPE_IDENTIFIER (type)));
3688 /* If the result is not a number, assume it must have been
3689 due to some error message above, so silently convert
3691 if (REAL_VALUE_ISNAN (value))
3694 /* Create a node with determined type and value. */
3696 yylval.ttype = build_complex (NULL_TREE,
3697 cp_convert (type, integer_zero_node),
3698 build_real (type, value));
3700 yylval.ttype = build_real (type, value);
3705 HOST_WIDE_INT high, low;
3706 int spec_unsigned = 0;
3708 int spec_long_long = 0;
3714 if (c == 'u' || c == 'U')
3717 error ("two `u's in integer constant");
3720 else if (c == 'l' || c == 'L')
3725 error ("three `l's in integer constant");
3727 pedwarn ("ANSI C++ forbids long long integer constants");
3732 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
3735 error ("more than one `i' or `j' in numeric constant");
3737 pedwarn ("ANSI C++ forbids imaginary numeric constants");
3742 if (p >= token_buffer + maxtoken - 3)
3743 p = extend_token_buffer (p);
3748 /* If the constant is not long long and it won't fit in an
3749 unsigned long, or if the constant is long long and won't fit
3750 in an unsigned long long, then warn that the constant is out
3753 /* ??? This assumes that long long and long integer types are
3754 a multiple of 8 bits. This better than the original code
3755 though which assumed that long was exactly 32 bits and long
3756 long was exactly 64 bits. */
3759 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
3761 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
3764 for (i = bytes; i < TOTAL_PARTS; i++)
3768 pedwarn ("integer constant out of range");
3770 /* This is simplified by the fact that our constant
3771 is always positive. */
3774 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
3776 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
3777 / HOST_BITS_PER_CHAR)]
3778 << (i * HOST_BITS_PER_CHAR));
3779 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
3783 yylval.ttype = build_int_2 (low, high);
3784 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
3786 if (!spec_long && !spec_unsigned
3787 && int_fits_type_p (yylval.ttype, integer_type_node))
3789 type = integer_type_node;
3791 else if (!spec_long && (base != 10 || spec_unsigned)
3792 && int_fits_type_p (yylval.ttype, unsigned_type_node))
3794 /* Nondecimal constants try unsigned even in traditional C. */
3795 type = unsigned_type_node;
3797 else if (!spec_unsigned && !spec_long_long
3798 && int_fits_type_p (yylval.ttype, long_integer_type_node))
3799 type = long_integer_type_node;
3800 else if (! spec_long_long)
3801 type = long_unsigned_type_node;
3802 else if (! spec_unsigned
3803 /* Verify value does not overflow into sign bit. */
3804 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
3805 && int_fits_type_p (yylval.ttype,
3806 long_long_integer_type_node))
3807 type = long_long_integer_type_node;
3808 else if (int_fits_type_p (yylval.ttype,
3809 long_long_unsigned_type_node))
3810 type = long_long_unsigned_type_node;
3814 type = long_long_integer_type_node;
3815 warning ("integer constant out of range");
3817 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
3818 warning ("decimal integer constant is so large that it is unsigned");
3821 if (TYPE_PRECISION (type)
3822 <= TYPE_PRECISION (integer_type_node))
3824 = build_complex (NULL_TREE, integer_zero_node,
3825 cp_convert (integer_type_node,
3828 error ("complex integer constant is too wide for `complex int'");
3832 TREE_TYPE (yylval.ttype) = type;
3838 value = CONSTANT; break;
3844 register int result = 0;
3845 register int num_chars = 0;
3846 unsigned width = TYPE_PRECISION (char_type_node);
3851 width = WCHAR_TYPE_SIZE;
3852 #ifdef MULTIBYTE_CHARS
3853 max_chars = MB_CUR_MAX;
3859 max_chars = TYPE_PRECISION (integer_type_node) / width;
3867 if (c == '\'' || c == EOF)
3873 c = readescape (&ignore);
3876 if (width < HOST_BITS_PER_INT
3877 && (unsigned) c >= (1 << width))
3878 warning ("escape sequence out of range for character");
3879 #ifdef MAP_CHARACTER
3881 c = MAP_CHARACTER (c);
3887 pedwarn ("ANSI C++ forbids newline in character constant");
3890 #ifdef MAP_CHARACTER
3892 c = MAP_CHARACTER (c);
3896 if (num_chars > maxtoken - 4)
3897 extend_token_buffer (token_buffer);
3899 token_buffer[num_chars] = c;
3901 /* Merge character into result; ignore excess chars. */
3902 if (num_chars < max_chars + 1)
3904 if (width < HOST_BITS_PER_INT)
3905 result = (result << width) | (c & ((1 << width) - 1));
3911 token_buffer[num_chars + 1] = '\'';
3912 token_buffer[num_chars + 2] = 0;
3915 error ("malformatted character constant");
3916 else if (num_chars == 0)
3917 error ("empty character constant");
3918 else if (num_chars > max_chars)
3920 num_chars = max_chars;
3921 error ("character constant too long");
3923 else if (num_chars != 1)
3924 warning ("multi-character character constant");
3926 /* If char type is signed, sign-extend the constant. */
3929 int num_bits = num_chars * width;
3931 /* We already got an error; avoid invalid shift. */
3932 yylval.ttype = build_int_2 (0, 0);
3933 else if (TREE_UNSIGNED (char_type_node)
3934 || ((result >> (num_bits - 1)) & 1) == 0)
3936 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
3937 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
3941 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
3942 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
3945 TREE_TYPE (yylval.ttype) = char_type_node;
3947 TREE_TYPE (yylval.ttype) = integer_type_node;
3951 #ifdef MULTIBYTE_CHARS
3952 /* Set the initial shift state and convert the next sequence. */
3954 /* In all locales L'\0' is zero and mbtowc will return zero,
3957 || (num_chars == 1 && token_buffer[1] != '\0'))
3960 (void) mbtowc (NULL, NULL, 0);
3961 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
3964 warning ("Ignoring invalid multibyte character");
3967 yylval.ttype = build_int_2 (result, 0);
3968 TREE_TYPE (yylval.ttype) = wchar_type_node;
3981 p = token_buffer + 1;
3983 while (c != '"' && c >= 0)
3985 /* ignore_escape_flag is set for reading the filename in #line. */
3986 if (!ignore_escape_flag && c == '\\')
3989 c = readescape (&ignore);
3993 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
3994 && c >= ((unsigned) 1 << TYPE_PRECISION (char_type_node)))
3995 warning ("escape sequence out of range for character");
4000 pedwarn ("ANSI C++ forbids newline in string constant");
4004 if (p == token_buffer + maxtoken)
4005 p = extend_token_buffer (p);
4011 error ("Unterminated string");
4017 /* We have read the entire constant.
4018 Construct a STRING_CST for the result. */
4022 /* If this is a L"..." wide-string, convert the multibyte string
4023 to a wide character string. */
4024 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
4027 #ifdef MULTIBYTE_CHARS
4028 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
4029 if (len < 0 || len >= (p - token_buffer))
4031 warning ("Ignoring invalid multibyte string");
4034 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
4037 union { long l; char c[sizeof (long)]; } u;
4041 /* Determine whether host is little or big endian. */
4043 big_endian = u.c[sizeof (long) - 1];
4044 wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
4046 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
4047 for (cp = token_buffer + 1; cp < p; cp++)
4048 *wp = *cp, wp += WCHAR_BYTES;
4049 len = p - token_buffer - 1;
4052 if (processing_template_decl)
4053 push_obstacks (&permanent_obstack, &permanent_obstack);
4054 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
4055 if (processing_template_decl)
4057 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
4061 if (processing_template_decl)
4062 push_obstacks (&permanent_obstack, &permanent_obstack);
4063 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
4064 if (processing_template_decl)
4066 TREE_TYPE (yylval.ttype) = char_array_type_node;
4072 value = STRING; break;
4095 yylval.code = PLUS_EXPR; break;
4097 yylval.code = MINUS_EXPR; break;
4099 yylval.code = BIT_AND_EXPR; break;
4101 yylval.code = BIT_IOR_EXPR; break;
4103 yylval.code = MULT_EXPR; break;
4105 yylval.code = TRUNC_DIV_EXPR; break;
4107 yylval.code = TRUNC_MOD_EXPR; break;
4109 yylval.code = BIT_XOR_EXPR; break;
4111 yylval.code = LSHIFT_EXPR; break;
4113 yylval.code = RSHIFT_EXPR; break;
4115 yylval.code = LT_EXPR; break;
4117 yylval.code = GT_EXPR; break;
4120 token_buffer[1] = c1 = getch ();
4121 token_buffer[2] = 0;
4128 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
4130 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
4132 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
4134 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
4136 value = ASSIGN; goto done;
4142 value = PLUSPLUS; goto done;
4144 value = MINUSMINUS; goto done;
4146 value = ANDAND; goto done;
4148 value = OROR; goto done;
4156 else if ((c == '-') && (c1 == '>'))
4158 nextchar = getch ();
4159 if (nextchar == '*')
4162 value = POINTSAT_STAR;
4168 else if (c1 == '?' && (c == '<' || c == '>'))
4170 token_buffer[3] = 0;
4173 yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR);
4176 /* <?= or >?= expression. */
4177 token_buffer[2] = c1;
4186 pedwarn ("use of `operator %s' is not standard C++",
4191 else if (c == '<' && c1 == '%')
4192 { value = '{'; goto done; }
4193 else if (c == '<' && c1 == ':')
4194 { value = '['; goto done; }
4195 else if (c == '%' && c1 == '>')
4196 { value = '}'; goto done; }
4197 else if (c == '%' && c1 == ':')
4198 { value = '#'; goto done; }
4201 token_buffer[1] = 0;
4211 token_buffer[1] = ':';
4212 token_buffer[2] = '\0';
4229 /* Don't make yyparse think this is eof. */
4234 /* try, weakly, to handle casts to pointers to functions. */
4235 nextchar = skip_white_space (getch ());
4236 if (nextchar == '*')
4238 int next_c = skip_white_space (getch ());
4242 yylval.ttype = build1 (INDIRECT_REF, 0, 0);
4243 value = PAREN_STAR_PAREN;
4251 else if (nextchar == ')')
4254 yylval.ttype = NULL_TREE;
4265 /* yylloc.last_line = lineno; */
4266 #ifdef GATHER_STATISTICS
4267 #ifdef REDUCE_LENGTH
4268 token_count[value] += 1;
4279 return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
4282 #ifdef GATHER_STATISTICS
4283 /* The original for tree_node_kind is in the toplevel tree.c; changes there
4284 need to be brought into here, unless this were actually put into a header
4286 /* Statistics-gathering stuff. */
4307 extern int tree_node_counts[];
4308 extern int tree_node_sizes[];
4311 /* Place to save freed lang_decls which were allocated on the
4312 permanent_obstack. @@ Not currently used. */
4313 tree free_lang_decl_chain;
4316 build_lang_decl (code, name, type)
4317 enum tree_code code;
4321 register tree t = build_decl (code, name, type);
4322 struct obstack *obstack = current_obstack;
4323 register int i = sizeof (struct lang_decl) / sizeof (int);
4326 if (! TREE_PERMANENT (t))
4327 obstack = saveable_obstack;
4329 /* Could be that saveable is permanent and current is not. */
4330 obstack = &permanent_obstack;
4332 if (free_lang_decl_chain && obstack == &permanent_obstack)
4334 pi = (int *)free_lang_decl_chain;
4335 free_lang_decl_chain = TREE_CHAIN (free_lang_decl_chain);
4338 pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl));
4343 DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi;
4344 LANG_DECL_PERMANENT ((struct lang_decl *) pi)
4345 = obstack == &permanent_obstack;
4346 my_friendly_assert (LANG_DECL_PERMANENT ((struct lang_decl *) pi)
4347 == TREE_PERMANENT (t), 234);
4348 DECL_MAIN_VARIANT (t) = t;
4349 if (current_lang_name == lang_name_cplusplus)
4350 DECL_LANGUAGE (t) = lang_cplusplus;
4351 else if (current_lang_name == lang_name_c)
4352 DECL_LANGUAGE (t) = lang_c;
4353 else my_friendly_abort (64);
4355 #if 0 /* not yet, should get fixed properly later */
4356 if (code == TYPE_DECL)
4359 id = get_identifier (build_overload_name (type, 1, 1));
4360 DECL_ASSEMBLER_NAME (t) = id;
4364 #ifdef GATHER_STATISTICS
4365 tree_node_counts[(int)lang_decl] += 1;
4366 tree_node_sizes[(int)lang_decl] += sizeof (struct lang_decl);
4373 build_lang_field_decl (code, name, type)
4374 enum tree_code code;
4378 extern struct obstack *current_obstack, *saveable_obstack;
4379 register tree t = build_decl (code, name, type);
4380 struct obstack *obstack = current_obstack;
4381 register int i = sizeof (struct lang_decl_flags) / sizeof (int);
4383 #if 0 /* not yet, should get fixed properly later */
4385 if (code == TYPE_DECL)
4388 id = get_identifier (build_overload_name (type, 1, 1));
4389 DECL_ASSEMBLER_NAME (t) = id;
4393 if (! TREE_PERMANENT (t))
4394 obstack = saveable_obstack;
4396 my_friendly_assert (obstack == &permanent_obstack, 235);
4398 pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl_flags));
4402 DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi;
4407 copy_lang_decl (node)
4413 if (! DECL_LANG_SPECIFIC (node))
4416 if (TREE_CODE (node) == FIELD_DECL)
4417 size = sizeof (struct lang_decl_flags);
4419 size = sizeof (struct lang_decl);
4420 pi = (int *)obstack_alloc (&permanent_obstack, size);
4421 bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)pi, size);
4422 DECL_LANG_SPECIFIC (node) = (struct lang_decl *)pi;
4426 make_lang_type (code)
4427 enum tree_code code;
4429 extern struct obstack *current_obstack, *saveable_obstack;
4430 register tree t = make_node (code);
4431 struct obstack *obstack = current_obstack;
4432 register int i = sizeof (struct lang_type) / sizeof (int);
4435 /* Set up some flags that give proper default behavior. */
4436 IS_AGGR_TYPE (t) = 1;
4438 if (! TREE_PERMANENT (t))
4439 obstack = saveable_obstack;
4441 my_friendly_assert (obstack == &permanent_obstack, 236);
4443 pi = (int *) obstack_alloc (obstack, sizeof (struct lang_type));
4447 TYPE_LANG_SPECIFIC (t) = (struct lang_type *) pi;
4448 CLASSTYPE_AS_LIST (t) = build_tree_list (NULL_TREE, t);
4449 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
4450 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
4451 CLASSTYPE_VBASE_SIZE (t) = integer_zero_node;
4452 TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE,
4454 CLASSTYPE_BINFO_AS_LIST (t) = build_tree_list (NULL_TREE, TYPE_BINFO (t));
4456 /* Make sure this is laid out, for ease of use later.
4457 In the presence of parse errors, the normal was of assuring
4458 this might not ever get executed, so we lay it out *immediately*. */
4459 build_pointer_type (t);
4461 #ifdef GATHER_STATISTICS
4462 tree_node_counts[(int)lang_type] += 1;
4463 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
4470 dump_time_statistics ()
4472 register tree prev = 0, decl, next;
4473 int this_time = my_get_run_time ();
4474 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time))
4475 += this_time - body_time;
4477 fprintf (stderr, "\n******\n");
4478 print_time ("header files (total)", header_time);
4479 print_time ("main file (total)", this_time - body_time);
4480 fprintf (stderr, "ratio = %g : 1\n",
4481 (double)header_time / (double)(this_time - body_time));
4482 fprintf (stderr, "\n******\n");
4484 for (decl = filename_times; decl; decl = next)
4486 next = IDENTIFIER_GLOBAL_VALUE (decl);
4487 IDENTIFIER_GLOBAL_VALUE (decl) = prev;
4491 for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl))
4492 print_time (IDENTIFIER_POINTER (decl),
4493 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (decl)));
4497 compiler_error (s, v, v2)
4499 HOST_WIDE_INT v, v2; /* @@also used as pointer */
4502 sprintf (buf, s, v, v2);
4503 error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
4510 extern int end_of_file;
4513 strcpy (buf, string);
4515 /* We can't print string and character constants well
4516 because the token_buffer contains the result of processing escapes. */
4518 strcat (buf, input_redirected ()
4519 ? " at end of saved text"
4520 : " at end of input");
4521 else if (token_buffer[0] == 0)
4522 strcat (buf, " at null character");
4523 else if (token_buffer[0] == '"')
4524 strcat (buf, " before string constant");
4525 else if (token_buffer[0] == '\'')
4526 strcat (buf, " before character constant");
4527 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
4528 sprintf (buf + strlen (buf), " before character 0%o",
4529 (unsigned char) token_buffer[0]);
4531 strcat (buf, " before `%s'");
4533 error (buf, token_buffer);
4537 handle_cp_pragma (pname)
4542 if (! strcmp (pname, "vtable"))
4544 extern tree pending_vtables;
4546 /* More follows: it must be a string constant (class name). */
4547 token = real_yylex ();
4548 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
4550 error ("invalid #pragma vtable");
4554 if (write_virtuals != 2)
4556 warning ("use `+e2' option to enable #pragma vtable");
4560 = perm_tree_cons (NULL_TREE,
4561 get_identifier (TREE_STRING_POINTER (yylval.ttype)),
4563 token = real_yylex ();
4564 if (token != END_OF_LINE)
4565 warning ("trailing characters ignored");
4568 else if (! strcmp (pname, "unit"))
4570 /* More follows: it must be a string constant (unit name). */
4571 token = real_yylex ();
4572 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
4574 error ("invalid #pragma unit");
4577 token = real_yylex ();
4578 if (token != END_OF_LINE)
4579 warning ("trailing characters ignored");
4582 else if (! strcmp (pname, "interface"))
4584 tree fileinfo = IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename));
4585 char *main_filename = input_filename;
4587 main_filename = FILE_NAME_NONDIRECTORY (main_filename);
4589 token = real_yylex ();
4591 if (token != END_OF_LINE)
4594 || TREE_CODE (yylval.ttype) != STRING_CST)
4596 error ("invalid `#pragma interface'");
4599 main_filename = TREE_STRING_POINTER (yylval.ttype);
4600 token = real_yylex ();
4603 if (token != END_OF_LINE)
4604 warning ("garbage after `#pragma interface' ignored");
4606 #ifndef NO_LINKAGE_HEURISTICS
4609 if (impl_file_chain == 0)
4611 /* If this is zero at this point, then we are
4612 auto-implementing. */
4613 if (main_input_filename == 0)
4614 main_input_filename = input_filename;
4616 #ifdef AUTO_IMPLEMENT
4617 filename = FILE_NAME_NONDIRECTORY (main_input_filename);
4618 fi = get_time_identifier (filename);
4619 fi = IDENTIFIER_CLASS_VALUE (fi);
4620 TREE_INT_CST_LOW (fi) = 0;
4621 TREE_INT_CST_HIGH (fi) = 1;
4623 impl_file_chain = (struct impl_files *)permalloc (sizeof (struct impl_files));
4624 impl_file_chain->filename = filename;
4625 impl_file_chain->next = 0;
4629 interface_only = interface_strcmp (main_filename);
4630 interface_unknown = 0;
4631 TREE_INT_CST_LOW (fileinfo) = interface_only;
4632 TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
4633 #endif /* NO_LINKAGE_HEURISTICS */
4637 else if (! strcmp (pname, "implementation"))
4639 tree fileinfo = IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename));
4640 char *main_filename = main_input_filename ? main_input_filename : input_filename;
4642 main_filename = FILE_NAME_NONDIRECTORY (main_filename);
4643 token = real_yylex ();
4644 if (token != END_OF_LINE)
4647 || TREE_CODE (yylval.ttype) != STRING_CST)
4649 error ("invalid `#pragma implementation'");
4652 main_filename = TREE_STRING_POINTER (yylval.ttype);
4653 token = real_yylex ();
4656 if (token != END_OF_LINE)
4657 warning ("garbage after `#pragma implementation' ignored");
4659 #ifndef NO_LINKAGE_HEURISTICS
4660 if (write_virtuals == 3)
4662 struct impl_files *ifiles = impl_file_chain;
4665 if (! strcmp (ifiles->filename, main_filename))
4667 ifiles = ifiles->next;
4671 ifiles = (struct impl_files*) permalloc (sizeof (struct impl_files));
4672 ifiles->filename = main_filename;
4673 ifiles->next = impl_file_chain;
4674 impl_file_chain = ifiles;
4677 else if ((main_input_filename != 0
4678 && ! strcmp (main_input_filename, input_filename))
4679 || ! strcmp (input_filename, main_filename))
4682 if (impl_file_chain == 0)
4684 impl_file_chain = (struct impl_files*) permalloc (sizeof (struct impl_files));
4685 impl_file_chain->filename = main_filename;
4686 impl_file_chain->next = 0;
4690 error ("`#pragma implementation' can only appear at top-level");
4693 /* We make this non-zero so that we infer decl linkage
4694 in the impl file only for variables first declared
4695 in the interface file. */
4696 interface_unknown = 1;
4698 /* We make this zero so that templates in the impl
4699 file will be emitted properly. */
4700 interface_unknown = 0;
4702 TREE_INT_CST_LOW (fileinfo) = interface_only;
4703 TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
4704 #endif /* NO_LINKAGE_HEURISTICS */
4712 #ifdef HANDLE_SYSV_PRAGMA
4714 /* Handle a #pragma directive. INPUT is the current input stream,
4715 and C is a character to reread. Processes the entire input line
4716 and returns a character for the caller to reread: either \n or EOF. */
4718 /* This function has to be in this file, in order to get at
4722 handle_sysv_pragma (finput, token)
4734 handle_pragma_token ("ignored", yylval.ttype);
4737 handle_pragma_token ("(", NULL_TREE);
4740 handle_pragma_token (")", NULL_TREE);
4743 handle_pragma_token (",", NULL_TREE);
4746 handle_pragma_token ("=", NULL_TREE);
4749 handle_pragma_token ("(", NULL_TREE);
4750 handle_pragma_token (")", NULL_TREE);
4754 handle_pragma_token (NULL_PTR, NULL_TREE);
4757 token = real_yylex ();
4760 #endif /* HANDLE_SYSV_PRAGMA */