1 /* Separate lexical analyzer for GNU C++.
2 Copyright (C) 1987, 89, 92-96, 1997 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. */
40 /* MULTIBYTE_CHARS support only works for native compilers.
41 ??? Ideally what we want is to model widechar support after
42 the current floating point support. */
44 #undef MULTIBYTE_CHARS
47 #ifdef MULTIBYTE_CHARS
53 #ifndef MULTIBYTE_CHARS
57 extern double atof ();
60 #define obstack_chunk_alloc xmalloc
61 #define obstack_chunk_free free
64 #define DIR_SEPARATOR '/'
67 extern struct obstack permanent_obstack;
68 extern struct obstack *current_obstack, *saveable_obstack;
70 extern void yyprint PROTO((FILE *, int, YYSTYPE));
71 extern void set_float_handler PROTO((jmp_buf));
72 extern void compiler_error PROTO((char *, HOST_WIDE_INT,
75 static tree get_time_identifier PROTO((char *));
76 static int check_newline PROTO((void));
77 static int skip_white_space PROTO((int));
78 static void finish_defarg PROTO((void));
79 static int my_get_run_time PROTO((void));
80 static int get_last_nonwhite_on_line PROTO((void));
81 static int interface_strcmp PROTO((char *));
82 static int readescape PROTO((int *));
83 static char *extend_token_buffer PROTO((char *));
84 static void consume_string PROTO((struct obstack *, int));
85 static void set_typedecl_interface_info PROTO((tree, tree));
86 static void feed_defarg PROTO((tree, tree));
87 static int set_vardecl_interface_info PROTO((tree, tree));
88 static void store_pending_inline PROTO((tree, struct pending_inline *));
89 static void reinit_parse_for_expr PROTO((struct obstack *));
91 /* Given a file name X, return the nondirectory portion.
92 Keep in mind that X can be computed more than once. */
94 file_name_nondirectory (x)
97 char *tmp = (char *) rindex (x, '/');
98 if (DIR_SEPARATOR != '/' && ! tmp)
99 tmp = (char *) rindex (x, DIR_SEPARATOR);
101 return (char *) (tmp + 1);
106 /* This obstack is needed to hold text. It is not safe to use
107 TOKEN_BUFFER because `check_newline' calls `yylex'. */
108 struct obstack inline_text_obstack;
109 char *inline_text_firstobj;
113 /* Pending language change.
114 Positive is push count, negative is pop count. */
115 int pending_lang_change = 0;
117 /* Wrap the current header file in extern "C". */
118 static int c_header_level = 0;
120 extern int first_token;
121 extern struct obstack token_obstack;
123 /* ??? Don't really know where this goes yet. */
127 extern void put_back (/* int */);
128 extern int input_redirected ();
129 extern void feed_input (/* char *, int */);
132 /* Holds translations from TREE_CODEs to operator name strings,
133 i.e., opname_tab[PLUS_EXPR] == "+". */
137 extern int yychar; /* the lookahead symbol */
138 extern YYSTYPE yylval; /* the semantic value of the */
139 /* lookahead symbol */
142 YYLTYPE yylloc; /* location data for the lookahead */
147 /* the declaration found for the last IDENTIFIER token read in.
148 yylex must look this up to detect typedefs, which get token type TYPENAME,
149 so it is left around in case the identifier is not a typedef but is
150 used in a context which makes it a reference to a variable. */
153 /* The elements of `ridpointers' are identifier nodes
154 for the reserved type names and storage classes.
155 It is indexed by a RID_... value. */
156 tree ridpointers[(int) RID_MAX];
158 /* We may keep statistics about how long which files took to compile. */
159 static int header_time, body_time;
160 static tree filename_times;
161 static tree this_filename_time;
163 /* Array for holding counts of the numbers of tokens seen. */
164 extern int *token_count;
166 /* Return something to represent absolute declarators containing a *.
167 TARGET is the absolute declarator that the * contains.
168 CV_QUALIFIERS is a list of modifiers such as const or volatile
169 to apply to the pointer type, represented as identifiers.
171 We return an INDIRECT_REF whose "contents" are TARGET
172 and whose type is the modifier list. */
175 make_pointer_declarator (cv_qualifiers, target)
176 tree cv_qualifiers, target;
178 if (target && TREE_CODE (target) == IDENTIFIER_NODE
179 && ANON_AGGRNAME_P (target))
180 error ("type name expected before `*'");
181 target = build_parse_node (INDIRECT_REF, target);
182 TREE_TYPE (target) = cv_qualifiers;
186 /* Return something to represent absolute declarators containing a &.
187 TARGET is the absolute declarator that the & contains.
188 CV_QUALIFIERS is a list of modifiers such as const or volatile
189 to apply to the reference type, represented as identifiers.
191 We return an ADDR_EXPR whose "contents" are TARGET
192 and whose type is the modifier list. */
195 make_reference_declarator (cv_qualifiers, target)
196 tree cv_qualifiers, target;
200 if (TREE_CODE (target) == ADDR_EXPR)
202 error ("cannot declare references to references");
205 if (TREE_CODE (target) == INDIRECT_REF)
207 error ("cannot declare pointers to references");
210 if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
211 error ("type name expected before `&'");
213 target = build_parse_node (ADDR_EXPR, target);
214 TREE_TYPE (target) = cv_qualifiers;
219 make_call_declarator (target, parms, cv_qualifiers, exception_specification)
220 tree target, parms, cv_qualifiers, exception_specification;
222 target = build_parse_node (CALL_EXPR, target, parms, cv_qualifiers);
223 TREE_TYPE (target) = exception_specification;
228 set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
229 tree call_declarator, cv_qualifiers, exception_specification;
231 TREE_OPERAND (call_declarator, 2) = cv_qualifiers;
232 TREE_TYPE (call_declarator) = exception_specification;
235 /* Build names and nodes for overloaded operators. */
237 tree ansi_opname[LAST_CPLUS_TREE_CODE];
238 tree ansi_assopname[LAST_CPLUS_TREE_CODE];
241 operator_name_string (name)
244 char *opname = IDENTIFIER_POINTER (name) + 2;
248 /* Works for builtin and user defined types. */
249 if (IDENTIFIER_GLOBAL_VALUE (name)
250 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL)
251 return IDENTIFIER_POINTER (name);
253 if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_')
257 opname_table = ansi_assopname;
262 opname_table = ansi_opname;
265 for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
267 if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign]
268 && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign])
272 if (i == LAST_CPLUS_TREE_CODE)
273 return "<invalid operator>";
276 return assignop_tab[i];
278 return opname_tab[i];
281 int interface_only; /* whether or not current file is only for
282 interface definitions. */
283 int interface_unknown; /* whether or not we know this class
284 to behave according to #pragma interface. */
286 /* lexical analyzer */
288 /* File used for outputting assembler code. */
289 extern FILE *asm_out_file;
291 #ifndef WCHAR_TYPE_SIZE
293 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
295 #define WCHAR_TYPE_SIZE BITS_PER_WORD
299 /* Number of bytes in a wide character. */
300 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
302 static int maxtoken; /* Current nominal length of token buffer. */
303 char *token_buffer; /* Pointer to token buffer.
304 Actual allocated length is maxtoken + 2. */
309 /* Nonzero tells yylex to ignore \ in string constants. */
310 static int ignore_escape_flag = 0;
313 get_time_identifier (name)
316 tree time_identifier;
317 int len = strlen (name);
318 char *buf = (char *) alloca (len + 6);
319 strcpy (buf, "file ");
320 bcopy (name, buf+5, len);
322 time_identifier = get_identifier (buf);
323 if (IDENTIFIER_LOCAL_VALUE (time_identifier) == NULL_TREE)
325 push_obstacks_nochange ();
326 end_temporary_allocation ();
327 IDENTIFIER_LOCAL_VALUE (time_identifier) = build_int_2 (0, 0);
328 IDENTIFIER_CLASS_VALUE (time_identifier) = build_int_2 (0, 1);
329 IDENTIFIER_GLOBAL_VALUE (time_identifier) = filename_times;
330 filename_times = time_identifier;
333 return time_identifier;
342 int old_quiet_flag = quiet_flag;
345 this_time = get_run_time ();
346 quiet_flag = old_quiet_flag;
350 /* Table indexed by tree code giving a string containing a character
351 classifying the tree code. Possibilities are
352 t, d, s, c, r, <, 1 and 2. See cp/cp-tree.def for details. */
354 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
356 char cplus_tree_code_type[] = {
358 #include "cp-tree.def"
362 /* Table indexed by tree code giving number of expression
363 operands beyond the fixed part of the node structure.
364 Not used for types or decls. */
366 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
368 int cplus_tree_code_length[] = {
370 #include "cp-tree.def"
374 /* Names of tree components.
375 Used for printing out the tree and error messages. */
376 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
378 char *cplus_tree_code_name[] = {
380 #include "cp-tree.def"
384 /* toplev.c needs to call these. */
389 /* the beginning of the file is a new line; check for # */
390 /* With luck, we discover the real source file's name from that
391 and put it in input_filename. */
392 put_back (check_newline ());
393 if (flag_gnu_xref) GNU_xref_begin (input_filename);
394 init_repo (input_filename);
396 /* See comments in toplev.c before the call to lang_init. */
397 if (flag_exceptions == 2)
404 extern int errorcount, sorrycount;
405 if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount);
415 init_filename_times ()
417 this_filename_time = get_time_identifier ("<top level>");
418 if (flag_detailed_statistics)
421 body_time = my_get_run_time ();
422 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time)) = body_time;
426 /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
427 Stuck this hack in to get the files open correctly; this is called
428 in place of init_lex if we are an unexec'd binary. */
432 reinit_lang_specific ()
434 init_filename_times ();
435 reinit_search_statistics ();
442 extern int flag_no_gnu_keywords;
443 extern int flag_operator_names;
447 /* Initialize the lookahead machinery. */
450 /* Make identifier nodes long enough for the language-specific slots. */
451 set_identifier_size (sizeof (struct lang_identifier));
452 decl_printable_name = lang_printable_name;
454 init_cplus_expand ();
456 bcopy (cplus_tree_code_type,
457 tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
458 (int)LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
459 bcopy ((char *)cplus_tree_code_length,
460 (char *)(tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE),
461 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
462 bcopy ((char *)cplus_tree_code_name,
463 (char *)(tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE),
464 (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
466 opname_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
467 bzero ((char *)opname_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
468 assignop_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
469 bzero ((char *)assignop_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
471 ansi_opname[0] = get_identifier ("<invalid operator>");
472 for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
474 ansi_opname[i] = ansi_opname[0];
475 ansi_assopname[i] = ansi_opname[0];
478 ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml");
479 IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1;
480 ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR];
481 ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml");
482 IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1;
483 ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR];
484 ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md");
485 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1;
486 ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd");
487 IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1;
488 ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
489 ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
490 ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
491 ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi");
492 IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1;
493 ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR];
494 ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami");
495 IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1;
496 ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR];
497 ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs");
498 IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1;
499 ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars");
500 IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1;
501 ansi_opname[(int) NE_EXPR] = get_identifier ("__ne");
502 IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1;
503 ansi_opname[(int) GT_EXPR] = get_identifier ("__gt");
504 IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1;
505 ansi_opname[(int) GE_EXPR] = get_identifier ("__ge");
506 IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1;
507 ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or");
508 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1;
509 ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor");
510 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1;
511 ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa");
512 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1;
513 ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt");
514 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1;
515 ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp");
516 IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1;
517 ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR];
518 ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as");
519 IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1;
520 ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR];
521 ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm");
522 IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1;
523 ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv");
524 IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1;
525 ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv");
526 IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1;
527 ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
528 ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
529 ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
530 ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
531 ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl");
532 ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
533 ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
534 ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
535 ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
536 IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1;
537 ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl");
538 IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1;
539 ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR];
540 ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR];
541 ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls");
542 IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1;
543 ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als");
544 IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1;
545 ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq");
546 IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1;
547 ansi_opname[(int) LT_EXPR] = get_identifier ("__lt");
548 IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1;
549 ansi_opname[(int) LE_EXPR] = get_identifier ("__le");
550 IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1;
551 ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad");
552 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1;
553 ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad");
554 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1;
555 ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR];
556 ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR];
557 ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er");
558 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1;
559 ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer");
560 IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1;
561 ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo");
562 IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1;
563 ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co");
564 IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1;
565 ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm");
566 IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1;
567 ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR];
568 ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf");
569 IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1;
570 ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm");
571 IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1;
572 ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl");
573 IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1;
574 ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc");
575 IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1;
576 ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw");
577 IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1;
578 ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl");
579 IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1;
580 ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn");
581 IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1;
582 ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd");
583 IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1;
584 ansi_opname[(int) TYPE_EXPR] = get_identifier ("__op");
585 IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1;
587 /* This is not true: these operators are not defined in ANSI,
588 but we need them anyway. */
589 ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn");
590 IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1;
591 ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx");
592 IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1;
593 ansi_opname[(int) COND_EXPR] = get_identifier ("__cn");
594 IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1;
595 ansi_opname[(int) SIZEOF_EXPR] = get_identifier ("__sz");
596 IDENTIFIER_OPNAME_P (ansi_opname[(int) SIZEOF_EXPR]) = 1;
600 gcc_obstack_init (&inline_text_obstack);
601 inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
603 /* Start it at 0, because check_newline is called at the very beginning
604 and will increment it to 1. */
606 input_filename = "<internal>";
607 current_function_decl = NULL;
610 token_buffer = (char *) xmalloc (maxtoken + 2);
612 ridpointers[(int) RID_INT] = get_identifier ("int");
613 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_INT],
614 build_tree_list (NULL_TREE, ridpointers[(int) RID_INT]));
615 ridpointers[(int) RID_BOOL] = get_identifier ("bool");
616 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_BOOL],
617 build_tree_list (NULL_TREE, ridpointers[(int) RID_BOOL]));
618 ridpointers[(int) RID_CHAR] = get_identifier ("char");
619 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_CHAR],
620 build_tree_list (NULL_TREE, ridpointers[(int) RID_CHAR]));
621 ridpointers[(int) RID_VOID] = get_identifier ("void");
622 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VOID],
623 build_tree_list (NULL_TREE, ridpointers[(int) RID_VOID]));
624 ridpointers[(int) RID_FLOAT] = get_identifier ("float");
625 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_FLOAT],
626 build_tree_list (NULL_TREE, ridpointers[(int) RID_FLOAT]));
627 ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
628 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_DOUBLE],
629 build_tree_list (NULL_TREE, ridpointers[(int) RID_DOUBLE]));
630 ridpointers[(int) RID_SHORT] = get_identifier ("short");
631 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_SHORT],
632 build_tree_list (NULL_TREE, ridpointers[(int) RID_SHORT]));
633 ridpointers[(int) RID_LONG] = get_identifier ("long");
634 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_LONG],
635 build_tree_list (NULL_TREE, ridpointers[(int) RID_LONG]));
636 ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
637 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_UNSIGNED],
638 build_tree_list (NULL_TREE, ridpointers[(int) RID_UNSIGNED]));
639 ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
640 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_SIGNED],
641 build_tree_list (NULL_TREE, ridpointers[(int) RID_SIGNED]));
642 ridpointers[(int) RID_INLINE] = get_identifier ("inline");
643 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_INLINE],
644 build_tree_list (NULL_TREE, ridpointers[(int) RID_INLINE]));
645 ridpointers[(int) RID_CONST] = get_identifier ("const");
646 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_CONST],
647 build_tree_list (NULL_TREE, ridpointers[(int) RID_CONST]));
648 ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
649 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VOLATILE],
650 build_tree_list (NULL_TREE, ridpointers[(int) RID_VOLATILE]));
651 ridpointers[(int) RID_AUTO] = get_identifier ("auto");
652 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_AUTO],
653 build_tree_list (NULL_TREE, ridpointers[(int) RID_AUTO]));
654 ridpointers[(int) RID_STATIC] = get_identifier ("static");
655 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_STATIC],
656 build_tree_list (NULL_TREE, ridpointers[(int) RID_STATIC]));
657 ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
658 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_EXTERN],
659 build_tree_list (NULL_TREE, ridpointers[(int) RID_EXTERN]));
660 ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
661 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_TYPEDEF],
662 build_tree_list (NULL_TREE, ridpointers[(int) RID_TYPEDEF]));
663 ridpointers[(int) RID_REGISTER] = get_identifier ("register");
664 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_REGISTER],
665 build_tree_list (NULL_TREE, ridpointers[(int) RID_REGISTER]));
666 ridpointers[(int) RID_COMPLEX] = get_identifier ("__complex");
667 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_COMPLEX],
668 build_tree_list (NULL_TREE, ridpointers[(int) RID_COMPLEX]));
670 /* C++ extensions. These are probably not correctly named. */
671 ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t");
672 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_WCHAR],
673 build_tree_list (NULL_TREE, ridpointers[(int) RID_WCHAR]));
674 class_type_node = build_int_2 (class_type, 0);
675 TREE_TYPE (class_type_node) = class_type_node;
676 ridpointers[(int) RID_CLASS] = class_type_node;
678 record_type_node = build_int_2 (record_type, 0);
679 TREE_TYPE (record_type_node) = record_type_node;
680 ridpointers[(int) RID_RECORD] = record_type_node;
682 union_type_node = build_int_2 (union_type, 0);
683 TREE_TYPE (union_type_node) = union_type_node;
684 ridpointers[(int) RID_UNION] = union_type_node;
686 enum_type_node = build_int_2 (enum_type, 0);
687 TREE_TYPE (enum_type_node) = enum_type_node;
688 ridpointers[(int) RID_ENUM] = enum_type_node;
690 ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual");
691 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VIRTUAL],
692 build_tree_list (NULL_TREE, ridpointers[(int) RID_VIRTUAL]));
693 ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit");
694 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_EXPLICIT],
695 build_tree_list (NULL_TREE, ridpointers[(int) RID_EXPLICIT]));
696 ridpointers[(int) RID_FRIEND] = get_identifier ("friend");
697 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_FRIEND],
698 build_tree_list (NULL_TREE, ridpointers[(int) RID_FRIEND]));
700 ridpointers[(int) RID_PUBLIC] = get_identifier ("public");
701 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PUBLIC],
702 build_tree_list (NULL_TREE, ridpointers[(int) RID_PUBLIC]));
703 ridpointers[(int) RID_PRIVATE] = get_identifier ("private");
704 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PRIVATE],
705 build_tree_list (NULL_TREE, ridpointers[(int) RID_PRIVATE]));
706 ridpointers[(int) RID_PROTECTED] = get_identifier ("protected");
707 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PROTECTED],
708 build_tree_list (NULL_TREE, ridpointers[(int) RID_PROTECTED]));
709 ridpointers[(int) RID_TEMPLATE] = get_identifier ("template");
710 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_TEMPLATE],
711 build_tree_list (NULL_TREE, ridpointers[(int) RID_TEMPLATE]));
712 /* This is for ANSI C++. */
713 ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable");
714 SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_MUTABLE],
715 build_tree_list (NULL_TREE, ridpointers[(int) RID_MUTABLE]));
717 /* Signature handling extensions. */
718 signature_type_node = build_int_2 (signature_type, 0);
719 TREE_TYPE (signature_type_node) = signature_type_node;
720 ridpointers[(int) RID_SIGNATURE] = signature_type_node;
722 null_node = build_int_2 (0, 0);
723 ridpointers[RID_NULL] = null_node;
725 opname_tab[(int) COMPONENT_REF] = "->";
726 opname_tab[(int) MEMBER_REF] = "->*";
727 opname_tab[(int) INDIRECT_REF] = "*";
728 opname_tab[(int) ARRAY_REF] = "[]";
729 opname_tab[(int) MODIFY_EXPR] = "=";
730 opname_tab[(int) NEW_EXPR] = "new";
731 opname_tab[(int) DELETE_EXPR] = "delete";
732 opname_tab[(int) VEC_NEW_EXPR] = "new []";
733 opname_tab[(int) VEC_DELETE_EXPR] = "delete []";
734 opname_tab[(int) COND_EXPR] = "?:";
735 opname_tab[(int) CALL_EXPR] = "()";
736 opname_tab[(int) PLUS_EXPR] = "+";
737 opname_tab[(int) MINUS_EXPR] = "-";
738 opname_tab[(int) MULT_EXPR] = "*";
739 opname_tab[(int) TRUNC_DIV_EXPR] = "/";
740 opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)";
741 opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)";
742 opname_tab[(int) ROUND_DIV_EXPR] = "(round /)";
743 opname_tab[(int) TRUNC_MOD_EXPR] = "%";
744 opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)";
745 opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)";
746 opname_tab[(int) ROUND_MOD_EXPR] = "(round %)";
747 opname_tab[(int) NEGATE_EXPR] = "-";
748 opname_tab[(int) MIN_EXPR] = "<?";
749 opname_tab[(int) MAX_EXPR] = ">?";
750 opname_tab[(int) ABS_EXPR] = "abs";
751 opname_tab[(int) FFS_EXPR] = "ffs";
752 opname_tab[(int) LSHIFT_EXPR] = "<<";
753 opname_tab[(int) RSHIFT_EXPR] = ">>";
754 opname_tab[(int) BIT_IOR_EXPR] = "|";
755 opname_tab[(int) BIT_XOR_EXPR] = "^";
756 opname_tab[(int) BIT_AND_EXPR] = "&";
757 opname_tab[(int) BIT_ANDTC_EXPR] = "&~";
758 opname_tab[(int) BIT_NOT_EXPR] = "~";
759 opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&";
760 opname_tab[(int) TRUTH_ORIF_EXPR] = "||";
761 opname_tab[(int) TRUTH_AND_EXPR] = "strict &&";
762 opname_tab[(int) TRUTH_OR_EXPR] = "strict ||";
763 opname_tab[(int) TRUTH_NOT_EXPR] = "!";
764 opname_tab[(int) LT_EXPR] = "<";
765 opname_tab[(int) LE_EXPR] = "<=";
766 opname_tab[(int) GT_EXPR] = ">";
767 opname_tab[(int) GE_EXPR] = ">=";
768 opname_tab[(int) EQ_EXPR] = "==";
769 opname_tab[(int) NE_EXPR] = "!=";
770 opname_tab[(int) IN_EXPR] = "in";
771 opname_tab[(int) RANGE_EXPR] = "...";
772 opname_tab[(int) CONVERT_EXPR] = "+";
773 opname_tab[(int) ADDR_EXPR] = "&";
774 opname_tab[(int) PREDECREMENT_EXPR] = "--";
775 opname_tab[(int) PREINCREMENT_EXPR] = "++";
776 opname_tab[(int) POSTDECREMENT_EXPR] = "--";
777 opname_tab[(int) POSTINCREMENT_EXPR] = "++";
778 opname_tab[(int) COMPOUND_EXPR] = ",";
780 assignop_tab[(int) NOP_EXPR] = "=";
781 assignop_tab[(int) PLUS_EXPR] = "+=";
782 assignop_tab[(int) CONVERT_EXPR] = "+=";
783 assignop_tab[(int) MINUS_EXPR] = "-=";
784 assignop_tab[(int) NEGATE_EXPR] = "-=";
785 assignop_tab[(int) MULT_EXPR] = "*=";
786 assignop_tab[(int) INDIRECT_REF] = "*=";
787 assignop_tab[(int) TRUNC_DIV_EXPR] = "/=";
788 assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)";
789 assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)";
790 assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)";
791 assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)";
792 assignop_tab[(int) TRUNC_MOD_EXPR] = "%=";
793 assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)";
794 assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)";
795 assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)";
796 assignop_tab[(int) MIN_EXPR] = "<?=";
797 assignop_tab[(int) MAX_EXPR] = ">?=";
798 assignop_tab[(int) LSHIFT_EXPR] = "<<=";
799 assignop_tab[(int) RSHIFT_EXPR] = ">>=";
800 assignop_tab[(int) BIT_IOR_EXPR] = "|=";
801 assignop_tab[(int) BIT_XOR_EXPR] = "^=";
802 assignop_tab[(int) BIT_AND_EXPR] = "&=";
803 assignop_tab[(int) ADDR_EXPR] = "&=";
805 init_filename_times ();
807 /* Some options inhibit certain reserved words.
808 Clear those words out of the hash table so they won't be recognized. */
809 #define UNSET_RESERVED_WORD(STRING) \
810 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
811 if (s) s->name = ""; } while (0)
814 /* let's parse things, and if they use it, then give them an error. */
815 if (!flag_exceptions)
817 UNSET_RESERVED_WORD ("throw");
818 UNSET_RESERVED_WORD ("try");
819 UNSET_RESERVED_WORD ("catch");
823 if (!flag_rtti || flag_no_gnu_keywords)
825 UNSET_RESERVED_WORD ("classof");
826 UNSET_RESERVED_WORD ("headof");
829 if (! flag_handle_signatures || flag_no_gnu_keywords)
831 /* Easiest way to not recognize signature
832 handling extensions... */
833 UNSET_RESERVED_WORD ("signature");
834 UNSET_RESERVED_WORD ("sigof");
836 if (flag_no_asm || flag_no_gnu_keywords)
837 UNSET_RESERVED_WORD ("typeof");
838 if (! flag_operator_names)
840 /* These are new ANSI keywords that may break code. */
841 UNSET_RESERVED_WORD ("and");
842 UNSET_RESERVED_WORD ("and_eq");
843 UNSET_RESERVED_WORD ("bitand");
844 UNSET_RESERVED_WORD ("bitor");
845 UNSET_RESERVED_WORD ("compl");
846 UNSET_RESERVED_WORD ("not");
847 UNSET_RESERVED_WORD ("not_eq");
848 UNSET_RESERVED_WORD ("or");
849 UNSET_RESERVED_WORD ("or_eq");
850 UNSET_RESERVED_WORD ("xor");
851 UNSET_RESERVED_WORD ("xor_eq");
854 token_count = init_parse ();
855 interface_unknown = 1;
859 reinit_parse_for_function ()
861 current_base_init_list = NULL_TREE;
862 current_member_init_list = NULL_TREE;
869 yyprint (file, yychar, yylval)
881 case IDENTIFIER_DEFN:
884 case TYPENAME_ELLIPSIS:
886 case PRE_PARSED_CLASS_DECL:
888 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL)
890 fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t)));
893 my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
894 if (IDENTIFIER_POINTER (t))
895 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
898 if (yylval.ttype == class_type_node)
899 fprintf (file, " `class'");
900 else if (yylval.ttype == record_type_node)
901 fprintf (file, " `struct'");
902 else if (yylval.ttype == union_type_node)
903 fprintf (file, " `union'");
904 else if (yylval.ttype == enum_type_node)
905 fprintf (file, " `enum'");
906 else if (yylval.ttype == signature_type_node)
907 fprintf (file, " `signature'");
909 my_friendly_abort (80);
914 #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
915 static int *reduce_count;
921 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
922 #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
928 #ifdef GATHER_STATISTICS
930 reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1));
931 bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1));
933 token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1));
934 bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1));
941 #ifdef GATHER_STATISTICS
947 reduce_count[yyn] += 1;
954 return reduce_count[*q] - reduce_count[*p];
961 return token_count[*q] - token_count[*p];
967 print_parse_statistics ()
969 #ifdef GATHER_STATISTICS
973 int maxlen = REDUCE_LENGTH;
976 if (reduce_count[-1] == 0)
979 if (TOKEN_LENGTH > REDUCE_LENGTH)
980 maxlen = TOKEN_LENGTH;
981 sorted = (unsigned *) alloca (sizeof (int) * maxlen);
983 for (i = 0; i < TOKEN_LENGTH; i++)
985 qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
986 for (i = 0; i < TOKEN_LENGTH; i++)
989 if (token_count[idx] == 0)
991 if (token_count[idx] < token_count[-1])
993 fprintf (stderr, "token %d, `%s', count = %d\n",
994 idx, yytname[YYTRANSLATE (idx)], token_count[idx]);
996 fprintf (stderr, "\n");
997 for (i = 0; i < REDUCE_LENGTH; i++)
999 qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
1000 for (i = 0; i < REDUCE_LENGTH; i++)
1002 int idx = sorted[i];
1003 if (reduce_count[idx] == 0)
1005 if (reduce_count[idx] < reduce_count[-1])
1007 fprintf (stderr, "rule %d, line %d, count = %d\n",
1008 idx, yyrline[idx], reduce_count[idx]);
1010 fprintf (stderr, "\n");
1016 /* Sets the value of the 'yydebug' variable to VALUE.
1017 This is a function so we don't have to have YYDEBUG defined
1018 in order to build the compiler. */
1028 warning ("YYDEBUG not defined.");
1033 /* Functions and data structures for #pragma interface.
1035 `#pragma implementation' means that the main file being compiled
1036 is considered to implement (provide) the classes that appear in
1037 its main body. I.e., if this is file "foo.cc", and class `bar'
1038 is defined in "foo.cc", then we say that "foo.cc implements bar".
1040 All main input files "implement" themselves automagically.
1042 `#pragma interface' means that unless this file (of the form "foo.h"
1043 is not presently being included by file "foo.cc", the
1044 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
1045 of the vtables nor any of the inline functions defined in foo.h
1046 will ever be output.
1048 There are cases when we want to link files such as "defs.h" and
1049 "main.cc". In this case, we give "defs.h" a `#pragma interface',
1050 and "main.cc" has `#pragma implementation "defs.h"'. */
1055 struct impl_files *next;
1058 static struct impl_files *impl_file_chain;
1060 /* Helper function to load global variables with interface
1064 extract_interface_info ()
1068 if (flag_alt_external_templates)
1070 struct tinst_level *til = tinst_for_decl ();
1073 fileinfo = get_time_identifier (til->file);
1076 fileinfo = get_time_identifier (input_filename);
1077 fileinfo = IDENTIFIER_CLASS_VALUE (fileinfo);
1078 interface_only = TREE_INT_CST_LOW (fileinfo);
1079 interface_unknown = TREE_INT_CST_HIGH (fileinfo);
1082 /* Return nonzero if S is not considered part of an
1083 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
1086 interface_strcmp (s)
1089 /* Set the interface/implementation bits for this scope. */
1090 struct impl_files *ifiles;
1093 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
1095 char *t1 = ifiles->filename;
1098 if (*s1 != *t1 || *s1 == 0)
1101 while (*s1 == *t1 && *s1 != 0)
1108 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
1109 if (index (s1, '.') || index (t1, '.'))
1112 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
1124 set_typedecl_interface_info (prev, vars)
1127 tree id = get_time_identifier (DECL_SOURCE_FILE (vars));
1128 tree fileinfo = IDENTIFIER_CLASS_VALUE (id);
1129 tree type = TREE_TYPE (vars);
1131 CLASSTYPE_INTERFACE_ONLY (type) = TREE_INT_CST_LOW (fileinfo)
1132 = interface_strcmp (file_name_nondirectory (DECL_SOURCE_FILE (vars)));
1136 set_vardecl_interface_info (prev, vars)
1139 tree type = DECL_CONTEXT (vars);
1141 if (CLASSTYPE_INTERFACE_KNOWN (type))
1143 if (CLASSTYPE_INTERFACE_ONLY (type))
1144 set_typedecl_interface_info (prev, TYPE_MAIN_DECL (type));
1146 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 1;
1147 DECL_EXTERNAL (vars) = CLASSTYPE_INTERFACE_ONLY (type);
1148 TREE_PUBLIC (vars) = 1;
1154 /* Called from the top level: if there are any pending inlines to
1155 do, set up to process them now. This function sets up the first function
1156 to be parsed; after it has been, the rule for fndef in parse.y will
1157 call process_next_inline to start working on the next one. */
1160 do_pending_inlines ()
1162 struct pending_inline *t;
1165 /* Oops, we're still dealing with the last batch. */
1166 if (yychar == PRE_PARSED_FUNCTION_DECL)
1169 /* Reverse the pending inline functions, since
1170 they were cons'd instead of appended. */
1172 struct pending_inline *prev = 0, *tail;
1173 t = pending_inlines;
1174 pending_inlines = 0;
1189 /* Now start processing the first inline function. */
1190 context = hack_decl_function_context (t->fndecl);
1192 push_cp_function_context (context);
1193 maybe_begin_member_template_processing (t->fndecl);
1196 feed_input (t->buf, t->len);
1199 if (input_filename != t->filename)
1201 input_filename = t->filename;
1202 /* Get interface/implementation back in sync. */
1203 extract_interface_info ();
1206 input_filename = t->filename;
1207 interface_unknown = t->interface == 1;
1208 interface_only = t->interface == 0;
1210 yychar = PRE_PARSED_FUNCTION_DECL;
1212 /* Pass back a handle on the rest of the inline functions, so that they
1213 can be processed later. */
1214 yylval.ttype = build_tree_list ((tree) t, t->fndecl);
1215 DECL_PENDING_INLINE_INFO (t->fndecl) = 0;
1218 static int nextchar = -1;
1220 /* Called from the fndecl rule in the parser when the function just parsed
1221 was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1222 do_pending_inlines). */
1225 process_next_inline (t)
1229 struct pending_inline *i = (struct pending_inline *) TREE_PURPOSE (t);
1230 context = hack_decl_function_context (i->fndecl);
1231 maybe_end_member_template_processing (i->fndecl);
1233 pop_cp_function_context (context);
1235 if (yychar == YYEMPTY)
1237 if (yychar != END_OF_SAVED_INPUT)
1239 error ("parse error at end of saved function text");
1241 /* restore_pending_input will abort unless yychar is either
1242 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1243 hosed, feed back YYEMPTY. We also need to discard nextchar,
1244 since that may have gotten set as well. */
1249 if (i && i->fndecl != NULL_TREE)
1251 context = hack_decl_function_context (i->fndecl);
1253 push_cp_function_context (context);
1254 maybe_begin_member_template_processing (i->fndecl);
1255 feed_input (i->buf, i->len);
1257 input_filename = i->filename;
1258 yychar = PRE_PARSED_FUNCTION_DECL;
1259 yylval.ttype = build_tree_list ((tree) i, i->fndecl);
1260 DECL_PENDING_INLINE_INFO (i->fndecl) = 0;
1264 interface_unknown = i->interface == 1;
1265 interface_only = i->interface == 0;
1268 extract_interface_info ();
1271 /* Since inline methods can refer to text which has not yet been seen,
1272 we store the text of the method in a structure which is placed in the
1273 DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1274 After parsing the body of the class definition, the FUNCTION_DECL's are
1275 scanned to see which ones have this field set. Those are then digested
1278 This function's FUNCTION_DECL will have a bit set in its common so
1279 that we know to watch out for it. */
1282 consume_string (this_obstack, matching_char)
1283 register struct obstack *this_obstack;
1287 int starting_lineno = lineno;
1293 int save_lineno = lineno;
1294 lineno = starting_lineno;
1295 if (matching_char == '"')
1296 error ("end of file encountered inside string constant");
1298 error ("end of file encountered inside character constant");
1299 lineno = save_lineno;
1304 obstack_1grow (this_obstack, c);
1306 obstack_1grow (this_obstack, c);
1308 /* Make sure we continue the loop */
1315 pedwarn ("ANSI C++ forbids newline in string constant");
1318 obstack_1grow (this_obstack, c);
1320 while (c != matching_char);
1323 static int nextyychar = YYEMPTY;
1324 static YYSTYPE nextyylval;
1326 struct pending_input {
1327 int nextchar, yychar, nextyychar, eof;
1328 YYSTYPE yylval, nextyylval;
1329 struct obstack token_obstack;
1333 struct pending_input *
1334 save_pending_input ()
1336 struct pending_input *p;
1337 p = (struct pending_input *) xmalloc (sizeof (struct pending_input));
1338 p->nextchar = nextchar;
1340 p->nextyychar = nextyychar;
1342 p->nextyylval = nextyylval;
1343 p->eof = end_of_file;
1344 yychar = nextyychar = YYEMPTY;
1346 p->first_token = first_token;
1347 p->token_obstack = token_obstack;
1350 gcc_obstack_init (&token_obstack);
1356 restore_pending_input (p)
1357 struct pending_input *p;
1359 my_friendly_assert (nextchar == -1, 229);
1360 nextchar = p->nextchar;
1361 my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230);
1363 my_friendly_assert (nextyychar == YYEMPTY, 231);
1364 nextyychar = p->nextyychar;
1366 nextyylval = p->nextyylval;
1367 first_token = p->first_token;
1368 obstack_free (&token_obstack, (char *) 0);
1369 token_obstack = p->token_obstack;
1370 end_of_file = p->eof;
1374 /* Unget character CH from the input stream.
1375 If RESCAN is non-zero, then we want to `see' this
1376 character as the next input token. */
1379 yyungetc (ch, rescan)
1383 /* Unget a character from the input stream. */
1384 if (yychar == YYEMPTY || rescan == 0)
1387 put_back (nextchar);
1392 my_friendly_assert (nextyychar == YYEMPTY, 232);
1393 nextyychar = yychar;
1394 nextyylval = yylval;
1400 clear_inline_text_obstack ()
1402 obstack_free (&inline_text_obstack, inline_text_firstobj);
1405 /* This function stores away the text for an inline function that should
1406 be processed later. It decides how much later, and may need to move
1407 the info between obstacks; therefore, the caller should not refer to
1408 the T parameter after calling this function. */
1411 store_pending_inline (decl, t)
1413 struct pending_inline *t;
1416 DECL_PENDING_INLINE_INFO (decl) = t;
1418 /* Because we use obstacks, we must process these in precise order. */
1419 t->next = pending_inlines;
1420 pending_inlines = t;
1424 reinit_parse_for_method (yychar, decl)
1429 int starting_lineno = lineno;
1430 char *starting_filename = input_filename;
1432 reinit_parse_for_block (yychar, &inline_text_obstack);
1434 len = obstack_object_size (&inline_text_obstack);
1435 current_base_init_list = NULL_TREE;
1436 current_member_init_list = NULL_TREE;
1437 if (decl == void_type_node
1438 || (current_class_type && TYPE_REDEFINED (current_class_type)))
1440 /* Happens when we get two declarations of the same
1441 function in the same scope. */
1442 char *buf = obstack_finish (&inline_text_obstack);
1443 obstack_free (&inline_text_obstack, buf);
1448 struct pending_inline *t;
1449 char *buf = obstack_finish (&inline_text_obstack);
1451 t = (struct pending_inline *) obstack_alloc (&inline_text_obstack,
1452 sizeof (struct pending_inline));
1453 t->lineno = starting_lineno;
1454 t->filename = starting_filename;
1461 if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
1462 warn_if_unknown_interface (decl);
1464 t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2));
1465 store_pending_inline (decl, t);
1469 /* Consume a block -- actually, a method beginning
1470 with `:' or `{' -- and save it away on the specified obstack. */
1473 reinit_parse_for_block (pyychar, obstackp)
1475 struct obstack *obstackp;
1479 int starting_lineno = lineno;
1480 char *starting_filename = input_filename;
1482 int look_for_semicolon = 0;
1483 int look_for_lbrac = 0;
1486 obstack_1grow (obstackp, '{');
1487 else if (pyychar == '=')
1488 look_for_semicolon = 1;
1489 else if (pyychar == ':')
1491 obstack_1grow (obstackp, pyychar);
1495 else if (pyychar == RETURN)
1497 obstack_grow (obstackp, "return", 6);
1501 else if (pyychar == TRY)
1503 obstack_grow (obstackp, "try", 3);
1509 yyerror ("parse error in method specification");
1510 obstack_1grow (obstackp, '{');
1513 if (nextchar != EOF)
1523 int this_lineno = lineno;
1525 c = skip_white_space (c);
1527 /* Don't lose our cool if there are lots of comments. */
1528 if (lineno == this_lineno + 1)
1529 obstack_1grow (obstackp, '\n');
1530 else if (lineno == this_lineno)
1532 else if (lineno - this_lineno < 10)
1535 for (i = lineno - this_lineno; i > 0; i--)
1536 obstack_1grow (obstackp, '\n');
1541 sprintf (buf, "\n# %d \"", lineno);
1543 obstack_grow (obstackp, buf, len);
1545 len = strlen (input_filename);
1546 obstack_grow (obstackp, input_filename, len);
1547 obstack_1grow (obstackp, '\"');
1548 obstack_1grow (obstackp, '\n');
1551 while (c > ' ') /* ASCII dependent... */
1553 obstack_1grow (obstackp, c);
1562 if (blev == 0 && !look_for_semicolon)
1566 if (peekyylex () == CATCH)
1569 obstack_grow (obstackp, " catch ", 7);
1586 /* Don't act on the next character...e.g, doing an escaped
1591 error_with_file_and_line (starting_filename,
1593 "end of file read inside definition");
1596 obstack_1grow (obstackp, c);
1599 consume_string (obstackp, c);
1601 consume_string (obstackp, c);
1606 error ("function body for constructor missing");
1607 obstack_1grow (obstackp, '{');
1608 obstack_1grow (obstackp, '}');
1612 else if (look_for_semicolon && blev == 0)
1620 error_with_file_and_line (starting_filename,
1622 "end of file read inside definition");
1627 obstack_1grow (obstackp, c);
1632 obstack_1grow (obstackp, '\0');
1635 /* Consume a no-commas expression -- actually, a default argument -- and
1636 save it away on the specified obstack. */
1639 reinit_parse_for_expr (obstackp)
1640 struct obstack *obstackp;
1643 int starting_lineno = lineno;
1644 char *starting_filename = input_filename;
1648 if (nextchar != EOF)
1658 int this_lineno = lineno;
1660 c = skip_white_space (c);
1662 /* Don't lose our cool if there are lots of comments. */
1663 if (lineno == this_lineno + 1)
1664 obstack_1grow (obstackp, '\n');
1665 else if (lineno == this_lineno)
1667 else if (lineno - this_lineno < 10)
1670 for (i = lineno - this_lineno; i > 0; --i)
1671 obstack_1grow (obstackp, '\n');
1676 sprintf (buf, "\n# %d \"", lineno);
1678 obstack_grow (obstackp, buf, len);
1680 len = strlen (input_filename);
1681 obstack_grow (obstackp, input_filename, len);
1682 obstack_1grow (obstackp, '\"');
1683 obstack_1grow (obstackp, '\n');
1686 while (c > ' ') /* ASCII dependent... */
1688 if (plev <= 0 && (c == ')' || c == ','))
1693 obstack_1grow (obstackp, c);
1694 if (c == '(' || c == '[')
1696 else if (c == ']' || c == ')')
1700 /* Don't act on the next character...e.g, doing an escaped
1705 error_with_file_and_line (starting_filename,
1707 "end of file read inside definition");
1710 obstack_1grow (obstackp, c);
1713 consume_string (obstackp, c);
1715 consume_string (obstackp, c);
1721 error_with_file_and_line (starting_filename,
1723 "end of file read inside definition");
1728 obstack_1grow (obstackp, c);
1733 obstack_1grow (obstackp, '\0');
1736 int do_snarf_defarg;
1738 /* Decide whether the default argument we are about to see should be
1739 gobbled up as text for later parsing. */
1742 maybe_snarf_defarg ()
1744 if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
1745 do_snarf_defarg = 1;
1748 /* When we see a default argument in a method declaration, we snarf it as
1749 text using snarf_defarg. When we get up to namespace scope, we then go
1750 through and parse all of them using do_pending_defargs. Since yacc
1751 parsers are not reentrant, we retain defargs state in these two
1752 variables so that subsequent calls to do_pending_defargs can resume
1753 where the previous call left off. */
1765 reinit_parse_for_expr (&inline_text_obstack);
1766 len = obstack_object_size (&inline_text_obstack);
1767 buf = obstack_finish (&inline_text_obstack);
1769 push_obstacks (&inline_text_obstack, &inline_text_obstack);
1770 arg = make_node (DEFAULT_ARG);
1771 DEFARG_LENGTH (arg) = len - 1;
1772 DEFARG_POINTER (arg) = buf;
1778 /* Called from grokfndecl to note a function decl with unparsed default
1779 arguments for later processing. Also called from grokdeclarator
1780 for function types with unparsed defargs; the call from grokfndecl
1781 will always come second, so we can overwrite the entry from the type. */
1784 add_defarg_fn (decl)
1787 if (TREE_CODE (decl) == FUNCTION_DECL)
1788 TREE_VALUE (defarg_fns) = decl;
1791 push_obstacks (&inline_text_obstack, &inline_text_obstack);
1792 defarg_fns = tree_cons (current_class_type, decl, defarg_fns);
1797 /* Helper for do_pending_defargs. Starts the parsing of a default arg. */
1803 tree d = TREE_PURPOSE (p);
1804 feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d));
1805 if (TREE_CODE (f) == FUNCTION_DECL)
1807 lineno = DECL_SOURCE_LINE (f);
1808 input_filename = DECL_SOURCE_FILE (f);
1810 yychar = DEFARG_MARKER;
1814 /* Helper for do_pending_defargs. Ends the parsing of a default arg. */
1819 if (yychar == YYEMPTY)
1821 if (yychar != END_OF_SAVED_INPUT)
1823 error ("parse error at end of saved function text");
1825 /* restore_pending_input will abort unless yychar is either
1826 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1827 hosed, feed back YYEMPTY. We also need to discard nextchar,
1828 since that may have gotten set as well. */
1835 /* Main function for deferred parsing of default arguments. Called from
1839 do_pending_defargs ()
1844 for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns))
1846 tree defarg_fn = TREE_VALUE (defarg_fns);
1847 if (defarg_parm == NULL_TREE)
1849 push_nested_class (TREE_PURPOSE (defarg_fns), 1);
1851 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1852 maybe_begin_member_template_processing (defarg_fn);
1854 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1858 for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p))
1859 pushdecl (copy_node (p));
1861 defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn));
1864 defarg_parm = TYPE_ARG_TYPES (defarg_fn);
1867 defarg_parm = TREE_CHAIN (defarg_parm);
1869 for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm))
1870 if (TREE_PURPOSE (defarg_parm)
1871 && TREE_CODE (TREE_PURPOSE (defarg_parm)) == DEFAULT_ARG)
1873 feed_defarg (defarg_fn, defarg_parm);
1875 /* Return to the parser, which will process this defarg
1876 and call us again. */
1880 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1881 maybe_end_member_template_processing (defarg_fn);
1883 pop_nested_class (1);
1887 /* Build a default function named NAME for type TYPE.
1888 KIND says what to build.
1890 When KIND == 0, build default destructor.
1891 When KIND == 1, build virtual destructor.
1892 When KIND == 2, build default constructor.
1893 When KIND == 3, build default X(const X&) constructor.
1894 When KIND == 4, build default X(X&) constructor.
1895 When KIND == 5, build default operator = (const X&).
1896 When KIND == 6, build default operator = (X&). */
1899 cons_up_default_function (type, full_name, kind)
1900 tree type, full_name;
1903 extern tree void_list_node;
1904 tree declspecs = NULL_TREE;
1905 tree fn, args = NULL_TREE;
1908 tree name = constructor_name (full_name);
1914 declspecs = build_decl_list (NULL_TREE, ridpointers [(int) RID_VIRTUAL]);
1915 /* Fall through... */
1917 name = build_parse_node (BIT_NOT_EXPR, name);
1918 args = void_list_node;
1922 /* Default constructor. */
1923 args = void_list_node;
1927 type = build_type_variant (type, 1, 0);
1928 /* Fall through... */
1930 /* According to ARM $12.8, the default copy ctor will be declared, but
1931 not defined, unless it's needed. */
1932 argtype = build_reference_type (type);
1933 args = tree_cons (NULL_TREE,
1934 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
1935 get_identifier ("_ctor_arg")),
1942 declspecs = build_decl_list (NULL_TREE, type);
1945 type = build_type_variant (type, 1, 0);
1947 name = ansi_opname [(int) MODIFY_EXPR];
1949 argtype = build_reference_type (type);
1950 args = tree_cons (NULL_TREE,
1951 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
1952 get_identifier ("_ctor_arg")),
1957 my_friendly_abort (59);
1960 declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE],
1963 TREE_PARMLIST (args) = 1;
1966 tree declarator = make_call_declarator (name, args, NULL_TREE, NULL_TREE);
1968 declarator = build_parse_node (ADDR_EXPR, declarator);
1970 fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
1973 if (fn == void_type_node)
1977 SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn)));
1980 if (processing_template_defn)
1982 SET_DECL_IMPLICIT_INSTANTIATION (fn);
1983 repo_template_used (fn);
1988 if (CLASSTYPE_INTERFACE_KNOWN (type))
1990 DECL_INTERFACE_KNOWN (fn) = 1;
1991 DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type)
1992 && flag_implement_inlines);
1996 DECL_NOT_REALLY_EXTERN (fn) = 1;
1998 mark_inline_for_output (fn);
2000 #ifdef DEBUG_DEFAULT_FUNCTIONS
2001 { char *fn_type = NULL;
2005 case 0: fn_type = "default destructor"; break;
2006 case 1: fn_type = "virtual destructor"; break;
2007 case 2: fn_type = "default constructor"; break;
2008 case 3: fn_type = "default X(const X&)"; break;
2009 case 4: fn_type = "default X(X&)"; break;
2013 if (TREE_CODE (name) == BIT_NOT_EXPR)
2014 t = TREE_OPERAND (name, 0);
2015 fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type,
2016 IDENTIFIER_POINTER (t), func_buf);
2019 #endif /* DEBUG_DEFAULT_FUNCTIONS */
2021 /* Show that this function was generated by the compiler. */
2022 SET_DECL_ARTIFICIAL (fn);
2027 /* Heuristic to tell whether the user is missing a semicolon
2028 after a struct or enum declaration. Emit an error message
2029 if we know the user has blown it. */
2032 check_for_missing_semicolon (type)
2040 && yychar != IDENTIFIER
2041 && yychar != TYPENAME
2042 && yychar != CV_QUALIFIER
2043 && yychar != SELFNAME)
2046 if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
2047 error ("semicolon missing after %s declaration",
2048 TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
2050 cp_error ("semicolon missing after declaration of `%T'", type);
2051 shadow_tag (build_tree_list (0, type));
2053 /* Could probably also hack cases where class { ... } f (); appears. */
2058 note_got_semicolon (type)
2061 if (TREE_CODE_CLASS (TREE_CODE (type)) != 't')
2062 my_friendly_abort (60);
2063 if (IS_AGGR_TYPE (type))
2064 CLASSTYPE_GOT_SEMICOLON (type) = 1;
2068 note_list_got_semicolon (declspecs)
2073 for (link = declspecs; link; link = TREE_CHAIN (link))
2075 tree type = TREE_VALUE (link);
2076 if (TREE_CODE_CLASS (TREE_CODE (type)) == 't')
2077 note_got_semicolon (type);
2082 /* If C is not whitespace, return C.
2083 Otherwise skip whitespace and return first nonwhite char read. */
2086 skip_white_space (c)
2094 c = check_newline ();
2105 while (c == ' ' || c == '\t');
2113 error ("stray '\\' in program");
2125 /* Make the token buffer longer, preserving the data in it.
2126 P should point to just beyond the last valid character in the old buffer.
2127 The value we return is a pointer to the new buffer
2128 at a place corresponding to P. */
2131 extend_token_buffer (p)
2134 int offset = p - token_buffer;
2136 maxtoken = maxtoken * 2 + 10;
2137 token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
2139 return token_buffer + offset;
2143 get_last_nonwhite_on_line ()
2147 /* Is this the last nonwhite stuff on the line? */
2149 c = nextchar, nextchar = -1;
2153 while (c == ' ' || c == '\t')
2158 /* At the beginning of a line, increment the line number
2159 and process any #-directive on this line.
2160 If the line is a #-directive, read the entire line and return a newline.
2161 Otherwise, return the line's first non-whitespace character. */
2165 #ifdef HANDLE_SYSV_PRAGMA
2166 static int handle_sysv_pragma PROTO((FILE *, int));
2168 static int handle_cp_pragma PROTO((char *));
2176 /* Read first nonwhite char on the line. Do this before incrementing the
2177 line number, in case we're at the end of saved text. */
2181 while (c == ' ' || c == '\t');
2187 /* If not #, return it so caller will use it. */
2191 /* Don't read beyond this line. */
2194 /* Read first nonwhite char after the `#'. */
2198 while (c == ' ' || c == '\t');
2200 /* If a letter follows, then if the word here is `line', skip
2201 it and ignore it; otherwise, ignore the line, with an error
2202 if the word isn't `pragma'. */
2204 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
2214 token = real_yylex ();
2215 if (token == IDENTIFIER
2216 && TREE_CODE (yylval.ttype) == IDENTIFIER_NODE)
2218 /* If this is 1, we handled it; if it's -1, it was one we
2219 wanted but had something wrong with it. Only if it's
2220 0 was it not handled. */
2221 if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype)))
2224 else if (token == END_OF_LINE)
2227 #ifdef HANDLE_SYSV_PRAGMA
2228 if (handle_sysv_pragma (finput, token))
2231 #ifdef HANDLE_PRAGMA
2232 if (HANDLE_PRAGMA (finput, yylval.ttype))
2246 && ((c = getch ()) == ' ' || c == '\t'))
2248 debug_define (lineno, get_directive_line (finput));
2258 && ((c = getch ()) == ' ' || c == '\t'))
2260 debug_undef (lineno, get_directive_line (finput));
2269 && ((c = getch ()) == ' ' || c == '\t'))
2278 && ((c = getch ()) == ' ' || c == '\t'))
2280 #ifdef ASM_OUTPUT_IDENT
2281 extern FILE *asm_out_file;
2283 /* #ident. The pedantic warning is now in cccp.c. */
2285 /* Here we have just seen `#ident '.
2286 A string constant should follow. */
2288 token = real_yylex ();
2289 if (token == END_OF_LINE)
2292 || TREE_CODE (yylval.ttype) != STRING_CST)
2294 error ("invalid #ident");
2298 if (! flag_no_ident)
2300 #ifdef ASM_OUTPUT_IDENT
2301 ASM_OUTPUT_IDENT (asm_out_file,
2302 TREE_STRING_POINTER (yylval.ttype));
2306 /* Skip the rest of this line. */
2319 && ((c = getch ()) == ' ' || c == '\t'))
2321 /* Used to test incremental compilation. */
2322 sorry ("#pragma newworld");
2326 error ("undefined or invalid # directive");
2331 /* Here we have either `#line' or `# <nonletter>'.
2332 In either case, it should be a line number; a digit should follow. */
2334 while (c == ' ' || c == '\t')
2337 /* If the # is the only nonwhite char on the line,
2338 just ignore it. Check the new newline. */
2342 /* Something follows the #; read a token. */
2345 token = real_yylex ();
2347 if (token == CONSTANT
2348 && TREE_CODE (yylval.ttype) == INTEGER_CST)
2350 int old_lineno = lineno;
2351 enum { act_none, act_push, act_pop } action = act_none;
2352 int entering_system_header = 0;
2353 int entering_c_header = 0;
2355 /* subtract one, because it is the following line that
2356 gets the specified number */
2358 int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
2359 c = get_last_nonwhite_on_line ();
2362 /* No more: store the line number and check following line. */
2368 /* More follows: it must be a string constant (filename). */
2370 /* Read the string constant, but don't treat \ as special. */
2371 ignore_escape_flag = 1;
2372 token = real_yylex ();
2373 ignore_escape_flag = 0;
2375 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2377 error ("invalid #line");
2381 /* Changing files again. This means currently collected time
2382 is charged against header time, and body time starts back
2384 if (flag_detailed_statistics)
2386 int this_time = my_get_run_time ();
2387 tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype));
2388 header_time += this_time - body_time;
2389 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time))
2390 += this_time - body_time;
2391 this_filename_time = time_identifier;
2392 body_time = this_time;
2396 = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
2397 strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
2399 GNU_xref_file (input_filename);
2401 if (main_input_filename == 0)
2403 struct impl_files *ifiles = impl_file_chain;
2407 while (ifiles->next)
2408 ifiles = ifiles->next;
2409 ifiles->filename = file_name_nondirectory (input_filename);
2412 main_input_filename = input_filename;
2413 if (write_virtuals == 3)
2414 walk_vtables (set_typedecl_interface_info, set_vardecl_interface_info);
2417 extract_interface_info ();
2419 c = get_last_nonwhite_on_line ();
2422 /* Update the name in the top element of input_file_stack. */
2423 if (input_file_stack)
2424 input_file_stack->name = input_filename;
2430 token = real_yylex ();
2432 /* `1' after file name means entering new file.
2433 `2' after file name means just left a file. */
2435 if (token == CONSTANT
2436 && TREE_CODE (yylval.ttype) == INTEGER_CST)
2438 if (TREE_INT_CST_LOW (yylval.ttype) == 1)
2440 else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
2445 c = get_last_nonwhite_on_line ();
2449 token = real_yylex ();
2454 /* `3' after file name means this is a system header file. */
2456 if (token == CONSTANT
2457 && TREE_CODE (yylval.ttype) == INTEGER_CST
2458 && TREE_INT_CST_LOW (yylval.ttype) == 3)
2460 entering_system_header = 1;
2462 c = get_last_nonwhite_on_line ();
2466 token = real_yylex ();
2470 /* `4' after file name means this is a C header file. */
2472 if (token == CONSTANT
2473 && TREE_CODE (yylval.ttype) == INTEGER_CST
2474 && TREE_INT_CST_LOW (yylval.ttype) == 4)
2476 entering_c_header = 1;
2478 c = get_last_nonwhite_on_line ();
2482 token = real_yylex ();
2486 /* Do the actions implied by the preceding numbers. */
2488 if (action == act_push)
2490 /* Pushing to a new file. */
2491 struct file_stack *p;
2493 p = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2494 input_file_stack->line = old_lineno;
2495 p->next = input_file_stack;
2496 p->name = input_filename;
2497 input_file_stack = p;
2498 input_file_stack_tick++;
2499 debug_start_source_file (input_filename);
2500 in_system_header = entering_system_header;
2503 else if (entering_c_header)
2506 ++pending_lang_change;
2509 else if (action == act_pop)
2511 /* Popping out of a file. */
2512 if (input_file_stack->next)
2514 struct file_stack *p;
2516 if (c_header_level && --c_header_level == 0)
2518 if (entering_c_header)
2519 warning ("badly nested C headers from preprocessor");
2520 --pending_lang_change;
2522 in_system_header = entering_system_header;
2524 p = input_file_stack;
2525 input_file_stack = p->next;
2527 input_file_stack_tick++;
2528 debug_end_source_file (input_file_stack->line);
2531 error ("#-lines for entering and leaving files don't match");
2534 in_system_header = entering_system_header;
2537 /* If NEXTCHAR is not end of line, we don't care what it is. */
2538 if (nextchar == EOF)
2542 error ("invalid #-line");
2544 /* skip the rest of this line. */
2549 while ((c = getch ()) != EOF && c != '\n');
2554 do_pending_lang_change ()
2556 for (; pending_lang_change > 0; --pending_lang_change)
2557 push_lang_context (lang_name_c);
2558 for (; pending_lang_change < 0; ++pending_lang_change)
2559 pop_lang_context ();
2563 #define isalnum(char) (char >= 'a' ? char <= 'z' : char >= '0' ? char <= '9' || (char >= 'A' && char <= 'Z') : 0)
2564 #define isdigit(char) (char >= '0' && char <= '9')
2569 #define ENDFILE -1 /* token that represents end-of-file */
2571 /* Read an escape sequence, returning its equivalent as a character,
2572 or store 1 in *ignore_ptr if it is backslash-newline. */
2575 readescape (ignore_ptr)
2578 register int c = getch ();
2580 register unsigned count;
2581 unsigned firstdig = 0;
2599 if (c >= 'a' && c <= 'f')
2600 code += c - 'a' + 10;
2601 if (c >= 'A' && c <= 'F')
2602 code += c - 'A' + 10;
2603 if (c >= '0' && c <= '9')
2605 if (code != 0 || count != 0)
2614 error ("\\x used with no following hex digits");
2615 else if (count == 0)
2616 /* Digits are all 0's. Ok. */
2618 else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
2620 && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
2622 pedwarn ("hex escape out of range");
2625 case '0': case '1': case '2': case '3': case '4':
2626 case '5': case '6': case '7':
2629 while ((c <= '7') && (c >= '0') && (count++ < 3))
2631 code = (code * 8) + (c - '0');
2637 case '\\': case '\'': case '"':
2646 return TARGET_NEWLINE;
2669 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
2675 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
2679 /* `\%' is used to prevent SCCS from getting confused. */
2682 pedwarn ("unknown escape sequence `\\%c'", c);
2685 if (c >= 040 && c < 0177)
2686 pedwarn ("unknown escape sequence `\\%c'", c);
2688 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
2692 /* Value is 1 (or 2) if we should try to make the next identifier look like
2693 a typename (when it may be a local variable or a class variable).
2694 Value is 0 if we treat this name in a default fashion. */
2695 int looking_for_typename = 0;
2701 identifier_type (decl)
2704 if (TREE_CODE (decl) == TEMPLATE_DECL)
2706 if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL)
2708 else if (looking_for_template)
2711 if (looking_for_template && really_overloaded_fn (decl))
2714 for (t = TREE_VALUE (decl); t != NULL_TREE; t = DECL_CHAIN (t))
2715 if (DECL_FUNCTION_TEMPLATE_P (t))
2718 if (TREE_CODE (decl) == NAMESPACE_DECL)
2720 if (TREE_CODE (decl) != TYPE_DECL)
2722 if (((got_scope && TREE_TYPE (decl) == got_scope)
2723 || TREE_TYPE (decl) == current_class_type)
2724 && DECL_ARTIFICIAL (decl))
2732 looking_for_typename = 1;
2734 if ((yychar = yylex ()) < 0) yychar = 0;
2735 looking_for_typename = 0;
2736 if (yychar == IDENTIFIER)
2738 lastiddecl = lookup_name (yylval.ttype, -2);
2739 if (lastiddecl == 0)
2742 lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype);
2745 yychar = identifier_type (lastiddecl);
2750 do_identifier (token, parsing)
2751 register tree token;
2756 if (! parsing || IDENTIFIER_OPNAME_P (token))
2757 id = lookup_name (token, 0);
2761 if (parsing && yychar == YYEMPTY)
2763 /* Scope class declarations before global
2765 if (id == IDENTIFIER_NAMESPACE_VALUE (token)
2766 && current_class_type != 0
2767 && TYPE_SIZE (current_class_type) == 0)
2769 /* Could be from one of the base classes. */
2770 tree field = lookup_field (current_class_type, token, 1, 0);
2773 else if (field == error_mark_node)
2774 /* We have already generated the error message.
2775 But we still want to return this value. */
2776 id = lookup_field (current_class_type, token, 0, 0);
2777 else if (TREE_CODE (field) == VAR_DECL
2778 || TREE_CODE (field) == CONST_DECL
2779 || TREE_CODE (field) == TEMPLATE_DECL)
2781 else if (TREE_CODE (field) != FIELD_DECL)
2782 my_friendly_abort (61);
2785 cp_error ("invalid use of member `%D' from base class `%T'", field,
2786 DECL_FIELD_CONTEXT (field));
2787 id = error_mark_node;
2792 /* Remember that this name has been used in the class definition, as per
2794 if (id && current_class_type && parsing
2795 && TYPE_BEING_DEFINED (current_class_type)
2796 && ! IDENTIFIER_CLASS_VALUE (token)
2797 /* Avoid breaking if we get called for a default argument that
2798 refers to an overloaded method. Eventually this will not be
2799 necessary, since default arguments shouldn't be parsed until
2800 after the class is complete. (jason 3/12/97) */
2801 && TREE_CODE (id) != TREE_LIST)
2802 pushdecl_class_level (id);
2804 if (!id || id == error_mark_node)
2806 if (id == error_mark_node && current_class_type != NULL_TREE)
2808 id = lookup_nested_field (token, 1);
2809 /* In lookup_nested_field(), we marked this so we can gracefully
2810 leave this whole mess. */
2811 if (id && id != error_mark_node && TREE_TYPE (id) == error_mark_node)
2815 if (current_template_parms)
2816 return build_min_nt (LOOKUP_EXPR, token, NULL_TREE);
2817 else if (IDENTIFIER_OPNAME_P (token))
2819 if (token != ansi_opname[ERROR_MARK])
2820 cp_error ("`%D' not defined", token);
2821 id = error_mark_node;
2823 else if (parsing && (yychar == '(' || yychar == LEFT_RIGHT))
2825 id = implicitly_declare (token);
2827 else if (current_function_decl == 0)
2829 cp_error ("`%D' was not declared in this scope", token);
2830 id = error_mark_node;
2834 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node
2835 || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
2837 static int undeclared_variable_notice;
2839 cp_error ("`%D' undeclared (first use this function)", token);
2841 if (! undeclared_variable_notice)
2843 error ("(Each undeclared identifier is reported only once");
2844 error ("for each function it appears in.)");
2845 undeclared_variable_notice = 1;
2848 id = error_mark_node;
2849 /* Prevent repeated error messages. */
2850 IDENTIFIER_NAMESPACE_VALUE (token) = error_mark_node;
2851 SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
2855 if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
2857 tree shadowed = DECL_SHADOWED_FOR_VAR (id);
2858 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
2859 && DECL_DEAD_FOR_LOCAL (shadowed))
2860 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
2862 shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id));
2865 if (!DECL_ERROR_REPORTED (id))
2867 warning ("name lookup of `%s' changed",
2868 IDENTIFIER_POINTER (token));
2869 cp_warning_at (" matches this `%D' under current ANSI rules",
2871 cp_warning_at (" matches this `%D' under old rules", id);
2872 DECL_ERROR_REPORTED (id) = 1;
2876 else if (!DECL_ERROR_REPORTED (id))
2879 = "name lookup of `%s' changed for new ANSI `for' scoping";
2880 DECL_ERROR_REPORTED (id) = 1;
2881 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id)))
2883 error (msg, IDENTIFIER_POINTER (token));
2884 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id);
2885 id = error_mark_node;
2889 pedwarn (msg, IDENTIFIER_POINTER (token));
2890 cp_pedwarn_at (" using obsolete binding at `%D'", id);
2894 /* TREE_USED is set in `hack_identifier'. */
2895 if (TREE_CODE (id) == CONST_DECL)
2897 if (IDENTIFIER_CLASS_VALUE (token) == id)
2900 tree access = compute_access (TYPE_BINFO (current_class_type), id);
2901 if (access == access_private_node)
2902 cp_error ("enum `%D' is private", id);
2903 /* protected is OK, since it's an enum of `this'. */
2905 if (! processing_template_decl
2906 || (DECL_INITIAL (id)
2907 && TREE_CODE (DECL_INITIAL (id)) == TEMPLATE_PARM_INDEX))
2908 id = DECL_INITIAL (id);
2911 id = hack_identifier (id, token);
2913 if (current_template_parms)
2915 if (is_overloaded_fn (id))
2917 tree t = build_min (LOOKUP_EXPR, unknown_type_node,
2918 token, get_first_fn (id));
2919 if (id != IDENTIFIER_NAMESPACE_VALUE (token))
2920 TREE_OPERAND (t, 1) = error_mark_node;
2923 else if (! TREE_PERMANENT (id) || TREE_CODE (id) == PARM_DECL
2924 || TREE_CODE (id) == USING_DECL)
2925 id = build_min (LOOKUP_EXPR, TREE_TYPE (id), token, error_mark_node);
2926 /* else just use the decl */
2933 do_scoped_id (token, parsing)
2938 /* during parsing, this is ::name. Otherwise, it is black magic. */
2940 id = qualified_lookup_using_namespace (token, global_namespace);
2942 id = IDENTIFIER_GLOBAL_VALUE (token);
2943 if (parsing && yychar == YYEMPTY)
2947 if (processing_template_decl)
2949 id = build_min_nt (LOOKUP_EXPR, token, NULL_TREE);
2950 LOOKUP_EXPR_GLOBAL (id) = 1;
2953 if (parsing && (yychar == '(' || yychar == LEFT_RIGHT))
2954 id = implicitly_declare (token);
2957 if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
2958 error ("undeclared variable `%s' (first use here)",
2959 IDENTIFIER_POINTER (token));
2960 id = error_mark_node;
2961 /* Prevent repeated error messages. */
2962 IDENTIFIER_NAMESPACE_VALUE (token) = error_mark_node;
2967 if (TREE_CODE (id) == ADDR_EXPR)
2968 mark_used (TREE_OPERAND (id, 0));
2969 else if (TREE_CODE (id) != TREE_LIST)
2972 if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
2974 /* XXX CHS - should we set TREE_USED of the constant? */
2975 id = DECL_INITIAL (id);
2976 /* This is to prevent an enum whose value is 0
2977 from being considered a null pointer constant. */
2978 id = build1 (NOP_EXPR, TREE_TYPE (id), id);
2979 TREE_CONSTANT (id) = 1;
2982 if (processing_template_decl)
2984 if (is_overloaded_fn (id))
2986 id = build_min (LOOKUP_EXPR, unknown_type_node,
2987 token, get_first_fn (id));
2988 LOOKUP_EXPR_GLOBAL (id) = 1;
2990 /* else just use the decl */
2992 return convert_from_reference (id);
2996 identifier_typedecl_value (node)
3000 type = IDENTIFIER_TYPE_VALUE (node);
3001 if (type == NULL_TREE)
3006 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) \
3009 do (IDENTIFIER_LOCAL_VALUE (node));
3010 do (IDENTIFIER_CLASS_VALUE (node));
3011 do (IDENTIFIER_NAMESPACE_VALUE (node));
3013 /* Will this one ever happen? */
3014 if (TYPE_MAIN_DECL (type))
3015 return TYPE_MAIN_DECL (type);
3017 /* We used to do an internal error of 62 here, but instead we will
3018 handle the return of a null appropriately in the callers. */
3028 int dollar_seen = 0;
3032 c = nextchar, nextchar = -1;
3036 /* Effectively do c = skip_white_space (c)
3037 but do it faster in the usual cases. */
3050 /* Call skip_white_space so we can warn if appropriate. */
3055 c = skip_white_space (c);
3057 goto found_nonwhite;
3061 token_buffer[0] = c;
3062 token_buffer[1] = 0;
3064 /* yylloc.first_line = lineno; */
3069 token_buffer[0] = '\0';
3071 if (input_redirected ())
3072 value = END_OF_SAVED_INPUT;
3074 value = END_OF_LINE;
3080 if (! dollars_in_ident)
3081 error ("`$' in identifier");
3083 pedwarn ("`$' in identifier");
3088 /* Capital L may start a wide-string or wide-character constant. */
3090 register int c = getch ();
3099 goto string_constant;
3104 case 'A': case 'B': case 'C': case 'D': case 'E':
3105 case 'F': case 'G': case 'H': case 'I': case 'J':
3106 case 'K': case 'M': case 'N': case 'O':
3107 case 'P': case 'Q': case 'R': case 'S': case 'T':
3108 case 'U': case 'V': case 'W': case 'X': case 'Y':
3110 case 'a': case 'b': case 'c': case 'd': case 'e':
3111 case 'f': case 'g': case 'h': case 'i': case 'j':
3112 case 'k': case 'l': case 'm': case 'n': case 'o':
3113 case 'p': case 'q': case 'r': case 's': case 't':
3114 case 'u': case 'v': case 'w': case 'x': case 'y':
3124 /* We know that `token_buffer' can hold at least on char,
3125 so we install C immediately.
3126 We may have to read the value in `putback_char', so call
3131 /* Make this run fast. We know that we are reading straight
3132 from FINPUT in this case (since identifiers cannot straddle
3134 while (isalnum (c) || (c == '_') || c == '$')
3138 if (! dollars_in_ident)
3139 error ("`$' in identifier");
3141 pedwarn ("`$' in identifier");
3144 if (p >= token_buffer + maxtoken)
3145 p = extend_token_buffer (p);
3151 if (linemode && c == '\n')
3159 /* We know that `token_buffer' can hold at least on char,
3160 so we install C immediately. */
3164 while (isalnum (c) || (c == '_') || c == '$')
3168 if (! dollars_in_ident)
3169 error ("`$' in identifier");
3171 pedwarn ("`$' in identifier");
3174 if (p >= token_buffer + maxtoken)
3175 p = extend_token_buffer (p);
3188 /* Try to recognize a keyword. Uses minimum-perfect hash function */
3191 register struct resword *ptr;
3193 if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
3197 tree old_ttype = ridpointers[(int) ptr->rid];
3199 /* If this provides a type for us, then revert lexical
3200 state to standard state. */
3201 if (TREE_CODE (old_ttype) == IDENTIFIER_NODE
3202 && IDENTIFIER_GLOBAL_VALUE (old_ttype) != 0
3203 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (old_ttype)) == TYPE_DECL)
3204 looking_for_typename = 0;
3205 else if (ptr->token == AGGR || ptr->token == ENUM)
3206 looking_for_typename = 1;
3208 /* Check if this is a language-type declaration.
3209 Just glimpse the next non-white character. */
3210 nextchar = skip_white_space (nextchar);
3211 if (nextchar == '"')
3213 /* We are looking at a string. Complain
3214 if the token before the string is no `extern'.
3216 Could cheat some memory by placing this string
3217 on the temporary_, instead of the saveable_
3220 if (ptr->rid != RID_EXTERN)
3221 error ("invalid modifier `%s' for language string",
3224 value = EXTERN_LANG_STRING;
3225 yylval.ttype = get_identifier (TREE_STRING_POINTER (yylval.ttype));
3228 if (ptr->token == VISSPEC)
3233 yylval.ttype = access_public_node;
3236 yylval.ttype = access_private_node;
3239 yylval.ttype = access_protected_node;
3242 my_friendly_abort (63);
3246 yylval.ttype = old_ttype;
3248 else if (ptr->token == EQCOMPARE)
3250 yylval.code = NE_EXPR;
3251 token_buffer[0] = '!';
3252 token_buffer[1] = '=';
3253 token_buffer[2] = 0;
3255 else if (ptr->token == ASSIGN)
3257 if (strcmp ("and_eq", token_buffer) == 0)
3259 yylval.code = BIT_AND_EXPR;
3260 token_buffer[0] = '&';
3262 else if (strcmp ("or_eq", token_buffer) == 0)
3264 yylval.code = BIT_IOR_EXPR;
3265 token_buffer[0] = '|';
3267 else if (strcmp ("xor_eq", token_buffer) == 0)
3269 yylval.code = BIT_XOR_EXPR;
3270 token_buffer[0] = '^';
3272 token_buffer[1] = '=';
3273 token_buffer[2] = 0;
3275 else if (ptr->token == '&')
3277 yylval.code = BIT_AND_EXPR;
3278 token_buffer[0] = '&';
3279 token_buffer[1] = 0;
3281 else if (ptr->token == '|')
3283 yylval.code = BIT_IOR_EXPR;
3284 token_buffer[0] = '|';
3285 token_buffer[1] = 0;
3287 else if (ptr->token == '^')
3289 yylval.code = BIT_XOR_EXPR;
3290 token_buffer[0] = '^';
3291 token_buffer[1] = 0;
3294 value = (int) ptr->token;
3298 /* If we did not find a keyword, look for an identifier
3301 if (value == IDENTIFIER || value == TYPESPEC)
3302 GNU_xref_ref (current_function_decl, token_buffer);
3304 if (value == IDENTIFIER)
3306 register tree tmp = get_identifier (token_buffer);
3308 #if !defined(VMS) && defined(JOINER)
3309 /* Make sure that user does not collide with our internal
3313 && (THIS_NAME_P (tmp)
3314 || VPTR_NAME_P (tmp)
3315 || DESTRUCTOR_NAME_P (tmp)
3316 || VTABLE_NAME_P (tmp)
3317 || TEMP_NAME_P (tmp)
3318 || ANON_AGGRNAME_P (tmp)
3319 || ANON_PARMNAME_P (tmp)))
3320 warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3326 if (value == NEW && ! global_bindings_p ())
3336 register int c1 = getch ();
3337 token_buffer[0] = c;
3338 token_buffer[1] = c1;
3342 token_buffer[2] = 0;
3350 token_buffer[2] = c1;
3351 token_buffer[3] = 0;
3355 error ("parse error at `..'");
3360 goto resume_numerical_scan;
3364 token_buffer[1] = 0;
3368 /* Optimize for most frequent case. */
3370 register int c1 = getch ();
3371 if (! isalnum (c1) && c1 != '.')
3373 /* Terminate string. */
3374 token_buffer[0] = c;
3375 token_buffer[1] = 0;
3377 yylval.ttype = integer_zero_node;
3379 yylval.ttype = integer_one_node;
3386 /* fall through... */
3387 case '2': case '3': case '4':
3388 case '5': case '6': case '7': case '8': case '9':
3389 resume_numerical_scan:
3394 int largest_digit = 0;
3396 /* for multi-precision arithmetic,
3397 we actually store only HOST_BITS_PER_CHAR bits in each part.
3398 The number of parts is chosen so as to be sufficient to hold
3399 the enough bits to fit into the two HOST_WIDE_INTs that contain
3400 the integer value (this is always at least as many bits as are
3401 in a target `long long' value, but may be wider). */
3402 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
3403 int parts[TOTAL_PARTS];
3406 enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
3409 for (count = 0; count < TOTAL_PARTS; count++)
3417 *p++ = (c = getch ());
3418 if ((c == 'x') || (c == 'X'))
3421 *p++ = (c = getch ());
3423 /* Leading 0 forces octal unless the 0 is the only digit. */
3424 else if (c >= '0' && c <= '9')
3433 /* Read all the digits-and-decimal-points. */
3436 || (isalnum (c) && (c != 'l') && (c != 'L')
3437 && (c != 'u') && (c != 'U')
3438 && c != 'i' && c != 'I' && c != 'j' && c != 'J'
3439 && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
3444 error ("floating constant may not be in radix 16");
3445 if (floatflag == TOO_MANY_POINTS)
3446 /* We have already emitted an error. Don't need another. */
3448 else if (floatflag == AFTER_POINT)
3450 error ("malformed floating constant");
3451 floatflag = TOO_MANY_POINTS;
3452 /* Avoid another error from atof by forcing all characters
3453 from here on to be ignored. */
3457 floatflag = AFTER_POINT;
3460 *p++ = c = getch ();
3461 /* Accept '.' as the start of a floating-point number
3462 only when it is followed by a digit.
3463 Otherwise, unread the following non-digit
3464 and use the '.' as a structural token. */
3465 if (p == token_buffer + 2 && !isdigit (c))
3477 error ("parse error at `..'");
3480 token_buffer[1] = '\0';
3487 /* It is not a decimal point.
3488 It should be a digit (perhaps a hex digit). */
3494 else if (base <= 10)
3496 if (c == 'e' || c == 'E')
3499 floatflag = AFTER_POINT;
3500 break; /* start of exponent */
3502 error ("nondigits in number and not hexadecimal");
3513 if (c >= largest_digit)
3517 for (count = 0; count < TOTAL_PARTS; count++)
3519 parts[count] *= base;
3523 += (parts[count-1] >> HOST_BITS_PER_CHAR);
3525 &= (1 << HOST_BITS_PER_CHAR) - 1;
3531 /* If the extra highest-order part ever gets anything in it,
3532 the number is certainly too big. */
3533 if (parts[TOTAL_PARTS - 1] != 0)
3536 if (p >= token_buffer + maxtoken - 3)
3537 p = extend_token_buffer (p);
3538 *p++ = (c = getch ());
3543 error ("numeric constant with no digits");
3545 if (largest_digit >= base)
3546 error ("numeric constant contains digits beyond the radix");
3548 /* Remove terminating char from the token buffer and delimit the string */
3551 if (floatflag != NOT_FLOAT)
3553 tree type = double_type_node;
3554 int exceeds_double = 0;
3556 REAL_VALUE_TYPE value;
3559 /* Read explicit exponent if any, and put it in tokenbuf. */
3561 if ((c == 'e') || (c == 'E'))
3563 if (p >= token_buffer + maxtoken - 3)
3564 p = extend_token_buffer (p);
3567 if ((c == '+') || (c == '-'))
3573 error ("floating constant exponent has no digits");
3576 if (p >= token_buffer + maxtoken - 3)
3577 p = extend_token_buffer (p);
3586 /* Convert string to a double, checking for overflow. */
3587 if (setjmp (handler))
3589 error ("floating constant out of range");
3594 int fflag = 0, lflag = 0;
3595 /* Copy token_buffer now, while it has just the number
3596 and not the suffixes; once we add `f' or `i',
3597 REAL_VALUE_ATOF may not work any more. */
3598 char *copy = (char *) alloca (p - token_buffer + 1);
3599 bcopy (token_buffer, copy, p - token_buffer + 1);
3601 set_float_handler (handler);
3607 /* Read the suffixes to choose a data type. */
3612 error ("more than one `f' in numeric constant");
3618 error ("more than one `l' in numeric constant");
3624 error ("more than one `i' or `j' in numeric constant");
3626 pedwarn ("ANSI C++ forbids imaginary numeric constants");
3637 if (p >= token_buffer + maxtoken - 3)
3638 p = extend_token_buffer (p);
3644 /* The second argument, machine_mode, of REAL_VALUE_ATOF
3645 tells the desired precision of the binary result
3646 of decimal-to-binary conversion. */
3651 error ("both `f' and `l' in floating constant");
3653 type = float_type_node;
3654 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
3655 /* A diagnostic is required here by some ANSI C testsuites.
3656 This is not pedwarn, become some people don't want
3657 an error for this. */
3658 if (REAL_VALUE_ISINF (value) && pedantic)
3659 warning ("floating point number exceeds range of `float'");
3663 type = long_double_type_node;
3664 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
3665 if (REAL_VALUE_ISINF (value) && pedantic)
3666 warning ("floating point number exceeds range of `long double'");
3670 value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
3671 if (REAL_VALUE_ISINF (value) && pedantic)
3672 warning ("floating point number exceeds range of `double'");
3675 set_float_handler (NULL_PTR);
3678 if (errno == ERANGE && pedantic)
3680 /* ERANGE is also reported for underflow,
3681 so test the value to distinguish overflow from that. */
3682 if (REAL_VALUES_LESS (dconst1, value)
3683 || REAL_VALUES_LESS (value, dconstm1))
3685 pedwarn ("floating point number exceeds range of `%s'",
3686 IDENTIFIER_POINTER (TYPE_IDENTIFIER (type)));
3692 /* If the result is not a number, assume it must have been
3693 due to some error message above, so silently convert
3695 if (REAL_VALUE_ISNAN (value))
3698 /* Create a node with determined type and value. */
3700 yylval.ttype = build_complex (NULL_TREE,
3701 cp_convert (type, integer_zero_node),
3702 build_real (type, value));
3704 yylval.ttype = build_real (type, value);
3709 HOST_WIDE_INT high, low;
3710 int spec_unsigned = 0;
3712 int spec_long_long = 0;
3718 if (c == 'u' || c == 'U')
3721 error ("two `u's in integer constant");
3724 else if (c == 'l' || c == 'L')
3729 error ("three `l's in integer constant");
3731 pedwarn ("ANSI C++ forbids long long integer constants");
3736 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
3739 error ("more than one `i' or `j' in numeric constant");
3741 pedwarn ("ANSI C++ forbids imaginary numeric constants");
3746 if (p >= token_buffer + maxtoken - 3)
3747 p = extend_token_buffer (p);
3752 /* If the constant is not long long and it won't fit in an
3753 unsigned long, or if the constant is long long and won't fit
3754 in an unsigned long long, then warn that the constant is out
3757 /* ??? This assumes that long long and long integer types are
3758 a multiple of 8 bits. This better than the original code
3759 though which assumed that long was exactly 32 bits and long
3760 long was exactly 64 bits. */
3763 bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
3765 bytes = TYPE_PRECISION (long_integer_type_node) / 8;
3768 for (i = bytes; i < TOTAL_PARTS; i++)
3772 pedwarn ("integer constant out of range");
3774 /* This is simplified by the fact that our constant
3775 is always positive. */
3778 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
3780 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
3781 / HOST_BITS_PER_CHAR)]
3782 << (i * HOST_BITS_PER_CHAR));
3783 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
3787 yylval.ttype = build_int_2 (low, high);
3788 TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
3790 /* Calculate the ANSI type. */
3791 if (!spec_long && !spec_unsigned
3792 && int_fits_type_p (yylval.ttype, integer_type_node))
3793 type = integer_type_node;
3794 else if (!spec_long && (base != 10 || spec_unsigned)
3795 && int_fits_type_p (yylval.ttype, unsigned_type_node))
3796 /* Nondecimal constants try unsigned even in traditional C. */
3797 type = unsigned_type_node;
3798 else if (!spec_unsigned && !spec_long_long
3799 && int_fits_type_p (yylval.ttype, long_integer_type_node))
3800 type = long_integer_type_node;
3801 else if (! spec_long_long)
3802 type = long_unsigned_type_node;
3803 else if (! spec_unsigned
3804 /* Verify value does not overflow into sign bit. */
3805 && TREE_INT_CST_HIGH (yylval.ttype) >= 0
3806 && int_fits_type_p (yylval.ttype,
3807 long_long_integer_type_node))
3808 type = long_long_integer_type_node;
3810 type = long_long_unsigned_type_node;
3812 if (!int_fits_type_p (yylval.ttype, type) && !warn)
3813 pedwarn ("integer constant out of range");
3815 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
3816 warning ("decimal integer constant is so large that it is unsigned");
3820 if (TYPE_PRECISION (type)
3821 <= TYPE_PRECISION (integer_type_node))
3823 = build_complex (NULL_TREE, integer_zero_node,
3824 cp_convert (integer_type_node,
3827 error ("complex integer constant is too wide for `__complex int'");
3830 TREE_TYPE (yylval.ttype) = type;
3836 value = CONSTANT; break;
3842 register int result = 0;
3843 register int num_chars = 0;
3844 unsigned width = TYPE_PRECISION (char_type_node);
3849 width = WCHAR_TYPE_SIZE;
3850 #ifdef MULTIBYTE_CHARS
3851 max_chars = MB_CUR_MAX;
3857 max_chars = TYPE_PRECISION (integer_type_node) / width;
3865 if (c == '\'' || c == EOF)
3871 c = readescape (&ignore);
3874 if (width < HOST_BITS_PER_INT
3875 && (unsigned) c >= (1 << width))
3876 warning ("escape sequence out of range for character");
3877 #ifdef MAP_CHARACTER
3879 c = MAP_CHARACTER (c);
3885 pedwarn ("ANSI C++ forbids newline in character constant");
3888 #ifdef MAP_CHARACTER
3890 c = MAP_CHARACTER (c);
3894 if (num_chars > maxtoken - 4)
3895 extend_token_buffer (token_buffer);
3897 token_buffer[num_chars] = c;
3899 /* Merge character into result; ignore excess chars. */
3900 if (num_chars < max_chars + 1)
3902 if (width < HOST_BITS_PER_INT)
3903 result = (result << width) | (c & ((1 << width) - 1));
3909 token_buffer[num_chars + 1] = '\'';
3910 token_buffer[num_chars + 2] = 0;
3913 error ("malformatted character constant");
3914 else if (num_chars == 0)
3915 error ("empty character constant");
3916 else if (num_chars > max_chars)
3918 num_chars = max_chars;
3919 error ("character constant too long");
3921 else if (num_chars != 1)
3922 warning ("multi-character character constant");
3924 /* If char type is signed, sign-extend the constant. */
3927 int num_bits = num_chars * width;
3929 /* We already got an error; avoid invalid shift. */
3930 yylval.ttype = build_int_2 (0, 0);
3931 else if (TREE_UNSIGNED (char_type_node)
3932 || ((result >> (num_bits - 1)) & 1) == 0)
3934 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
3935 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
3939 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
3940 >> (HOST_BITS_PER_WIDE_INT - num_bits)),
3943 TREE_TYPE (yylval.ttype) = char_type_node;
3945 TREE_TYPE (yylval.ttype) = integer_type_node;
3949 #ifdef MULTIBYTE_CHARS
3950 /* Set the initial shift state and convert the next sequence. */
3952 /* In all locales L'\0' is zero and mbtowc will return zero,
3955 || (num_chars == 1 && token_buffer[1] != '\0'))
3958 (void) mbtowc (NULL, NULL, 0);
3959 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
3962 warning ("Ignoring invalid multibyte character");
3965 yylval.ttype = build_int_2 (result, 0);
3966 TREE_TYPE (yylval.ttype) = wchar_type_node;
3979 p = token_buffer + 1;
3981 while (c != '"' && c >= 0)
3983 /* ignore_escape_flag is set for reading the filename in #line. */
3984 if (!ignore_escape_flag && c == '\\')
3987 c = readescape (&ignore);
3991 && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
3992 && c >= ((unsigned) 1 << TYPE_PRECISION (char_type_node)))
3993 warning ("escape sequence out of range for character");
3998 pedwarn ("ANSI C++ forbids newline in string constant");
4002 if (p == token_buffer + maxtoken)
4003 p = extend_token_buffer (p);
4009 error ("Unterminated string");
4015 /* We have read the entire constant.
4016 Construct a STRING_CST for the result. */
4020 /* If this is a L"..." wide-string, convert the multibyte string
4021 to a wide character string. */
4022 char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
4025 #ifdef MULTIBYTE_CHARS
4026 len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
4027 if (len < 0 || len >= (p - token_buffer))
4029 warning ("Ignoring invalid multibyte string");
4032 bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
4037 wp = widep + (BYTES_BIG_ENDIAN ? WCHAR_BYTES - 1 : 0);
4038 bzero (widep, (p - token_buffer) * WCHAR_BYTES);
4039 for (cp = token_buffer + 1; cp < p; cp++)
4040 *wp = *cp, wp += WCHAR_BYTES;
4041 len = p - token_buffer - 1;
4044 if (processing_template_decl)
4045 push_obstacks (&permanent_obstack, &permanent_obstack);
4046 yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
4047 if (processing_template_decl)
4049 TREE_TYPE (yylval.ttype) = wchar_array_type_node;
4053 if (processing_template_decl)
4054 push_obstacks (&permanent_obstack, &permanent_obstack);
4055 yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
4056 if (processing_template_decl)
4058 TREE_TYPE (yylval.ttype) = char_array_type_node;
4064 value = STRING; break;
4087 yylval.code = PLUS_EXPR; break;
4089 yylval.code = MINUS_EXPR; break;
4091 yylval.code = BIT_AND_EXPR; break;
4093 yylval.code = BIT_IOR_EXPR; break;
4095 yylval.code = MULT_EXPR; break;
4097 yylval.code = TRUNC_DIV_EXPR; break;
4099 yylval.code = TRUNC_MOD_EXPR; break;
4101 yylval.code = BIT_XOR_EXPR; break;
4103 yylval.code = LSHIFT_EXPR; break;
4105 yylval.code = RSHIFT_EXPR; break;
4107 yylval.code = LT_EXPR; break;
4109 yylval.code = GT_EXPR; break;
4112 token_buffer[1] = c1 = getch ();
4113 token_buffer[2] = 0;
4120 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
4122 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
4124 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
4126 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
4128 value = ASSIGN; goto done;
4134 value = PLUSPLUS; goto done;
4136 value = MINUSMINUS; goto done;
4138 value = ANDAND; goto done;
4140 value = OROR; goto done;
4148 else if ((c == '-') && (c1 == '>'))
4150 nextchar = getch ();
4151 if (nextchar == '*')
4154 value = POINTSAT_STAR;
4160 else if (c1 == '?' && (c == '<' || c == '>'))
4162 token_buffer[3] = 0;
4165 yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR);
4168 /* <?= or >?= expression. */
4169 token_buffer[2] = c1;
4178 pedwarn ("use of `operator %s' is not standard C++",
4183 else if (c == '<' && c1 == '%')
4184 { value = '{'; goto done; }
4185 else if (c == '<' && c1 == ':')
4186 { value = '['; goto done; }
4187 else if (c == '%' && c1 == '>')
4188 { value = '}'; goto done; }
4189 else if (c == '%' && c1 == ':')
4190 { value = '#'; goto done; }
4193 token_buffer[1] = 0;
4203 token_buffer[1] = ':';
4204 token_buffer[2] = '\0';
4221 /* Don't make yyparse think this is eof. */
4226 /* try, weakly, to handle casts to pointers to functions. */
4227 nextchar = skip_white_space (getch ());
4228 if (nextchar == '*')
4230 int next_c = skip_white_space (getch ());
4234 yylval.ttype = build1 (INDIRECT_REF, 0, 0);
4235 value = PAREN_STAR_PAREN;
4243 else if (nextchar == ')')
4246 yylval.ttype = NULL_TREE;
4257 /* yylloc.last_line = lineno; */
4258 #ifdef GATHER_STATISTICS
4259 #ifdef REDUCE_LENGTH
4260 token_count[value] += 1;
4271 return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
4274 #ifdef GATHER_STATISTICS
4275 /* The original for tree_node_kind is in the toplevel tree.c; changes there
4276 need to be brought into here, unless this were actually put into a header
4278 /* Statistics-gathering stuff. */
4299 extern int tree_node_counts[];
4300 extern int tree_node_sizes[];
4303 /* Place to save freed lang_decls which were allocated on the
4304 permanent_obstack. @@ Not currently used. */
4305 tree free_lang_decl_chain;
4308 build_lang_decl (code, name, type)
4309 enum tree_code code;
4313 register tree t = build_decl (code, name, type);
4314 struct obstack *obstack = current_obstack;
4315 register int i = sizeof (struct lang_decl) / sizeof (int);
4318 if (! TREE_PERMANENT (t))
4319 obstack = saveable_obstack;
4321 /* Could be that saveable is permanent and current is not. */
4322 obstack = &permanent_obstack;
4324 if (free_lang_decl_chain && obstack == &permanent_obstack)
4326 pi = (int *)free_lang_decl_chain;
4327 free_lang_decl_chain = TREE_CHAIN (free_lang_decl_chain);
4330 pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl));
4335 DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi;
4336 LANG_DECL_PERMANENT ((struct lang_decl *) pi)
4337 = obstack == &permanent_obstack;
4338 my_friendly_assert (LANG_DECL_PERMANENT ((struct lang_decl *) pi)
4339 == TREE_PERMANENT (t), 234);
4340 DECL_MAIN_VARIANT (t) = t;
4341 if (current_lang_name == lang_name_cplusplus)
4342 DECL_LANGUAGE (t) = lang_cplusplus;
4343 else if (current_lang_name == lang_name_c)
4344 DECL_LANGUAGE (t) = lang_c;
4345 else my_friendly_abort (64);
4347 SET_DECL_NAMESPACE (t, current_namespace);
4349 #if 0 /* not yet, should get fixed properly later */
4350 if (code == TYPE_DECL)
4353 id = get_identifier (build_overload_name (type, 1, 1));
4354 DECL_ASSEMBLER_NAME (t) = id;
4358 #ifdef GATHER_STATISTICS
4359 tree_node_counts[(int)lang_decl] += 1;
4360 tree_node_sizes[(int)lang_decl] += sizeof (struct lang_decl);
4367 build_lang_field_decl (code, name, type)
4368 enum tree_code code;
4372 extern struct obstack *current_obstack, *saveable_obstack;
4373 register tree t = build_decl (code, name, type);
4374 struct obstack *obstack = current_obstack;
4375 register int i = sizeof (struct lang_decl_flags) / sizeof (int);
4377 #if 0 /* not yet, should get fixed properly later */
4379 if (code == TYPE_DECL)
4382 id = get_identifier (build_overload_name (type, 1, 1));
4383 DECL_ASSEMBLER_NAME (t) = id;
4387 if (! TREE_PERMANENT (t))
4388 obstack = saveable_obstack;
4390 my_friendly_assert (obstack == &permanent_obstack, 235);
4392 pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl_flags));
4396 DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi;
4401 copy_lang_decl (node)
4407 if (! DECL_LANG_SPECIFIC (node))
4410 if (TREE_CODE (node) == FIELD_DECL)
4411 size = sizeof (struct lang_decl_flags);
4413 size = sizeof (struct lang_decl);
4414 pi = (int *)obstack_alloc (&permanent_obstack, size);
4415 bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)pi, size);
4416 DECL_LANG_SPECIFIC (node) = (struct lang_decl *)pi;
4420 make_lang_type (code)
4421 enum tree_code code;
4423 extern struct obstack *current_obstack, *saveable_obstack;
4424 register tree t = make_node (code);
4425 struct obstack *obstack = current_obstack;
4426 register int i = sizeof (struct lang_type) / sizeof (int);
4429 /* Set up some flags that give proper default behavior. */
4430 IS_AGGR_TYPE (t) = 1;
4432 if (! TREE_PERMANENT (t))
4433 obstack = saveable_obstack;
4435 my_friendly_assert (obstack == &permanent_obstack, 236);
4437 pi = (int *) obstack_alloc (obstack, sizeof (struct lang_type));
4441 TYPE_LANG_SPECIFIC (t) = (struct lang_type *) pi;
4442 CLASSTYPE_AS_LIST (t) = build_expr_list (NULL_TREE, t);
4443 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
4444 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
4445 TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE,
4447 CLASSTYPE_BINFO_AS_LIST (t) = build_tree_list (NULL_TREE, TYPE_BINFO (t));
4449 /* Make sure this is laid out, for ease of use later.
4450 In the presence of parse errors, the normal was of assuring
4451 this might not ever get executed, so we lay it out *immediately*. */
4452 build_pointer_type (t);
4454 #ifdef GATHER_STATISTICS
4455 tree_node_counts[(int)lang_type] += 1;
4456 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
4463 dump_time_statistics ()
4465 register tree prev = 0, decl, next;
4466 int this_time = my_get_run_time ();
4467 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time))
4468 += this_time - body_time;
4470 fprintf (stderr, "\n******\n");
4471 print_time ("header files (total)", header_time);
4472 print_time ("main file (total)", this_time - body_time);
4473 fprintf (stderr, "ratio = %g : 1\n",
4474 (double)header_time / (double)(this_time - body_time));
4475 fprintf (stderr, "\n******\n");
4477 for (decl = filename_times; decl; decl = next)
4479 next = IDENTIFIER_GLOBAL_VALUE (decl);
4480 IDENTIFIER_GLOBAL_VALUE (decl) = prev;
4484 for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl))
4485 print_time (IDENTIFIER_POINTER (decl),
4486 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (decl)));
4490 compiler_error (s, v, v2)
4492 HOST_WIDE_INT v, v2; /* @@also used as pointer */
4495 sprintf (buf, s, v, v2);
4496 error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
4503 extern int end_of_file;
4506 strcpy (buf, string);
4508 /* We can't print string and character constants well
4509 because the token_buffer contains the result of processing escapes. */
4511 strcat (buf, input_redirected ()
4512 ? " at end of saved text"
4513 : " at end of input");
4514 else if (token_buffer[0] == 0)
4515 strcat (buf, " at null character");
4516 else if (token_buffer[0] == '"')
4517 strcat (buf, " before string constant");
4518 else if (token_buffer[0] == '\'')
4519 strcat (buf, " before character constant");
4520 else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
4521 sprintf (buf + strlen (buf), " before character 0%o",
4522 (unsigned char) token_buffer[0]);
4524 strcat (buf, " before `%s'");
4526 error (buf, token_buffer);
4530 handle_cp_pragma (pname)
4535 if (! strcmp (pname, "vtable"))
4537 extern tree pending_vtables;
4539 /* More follows: it must be a string constant (class name). */
4540 token = real_yylex ();
4541 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
4543 error ("invalid #pragma vtable");
4547 if (write_virtuals != 2)
4549 warning ("use `+e2' option to enable #pragma vtable");
4553 = perm_tree_cons (NULL_TREE,
4554 get_identifier (TREE_STRING_POINTER (yylval.ttype)),
4556 token = real_yylex ();
4557 if (token != END_OF_LINE)
4558 warning ("trailing characters ignored");
4561 else if (! strcmp (pname, "unit"))
4563 /* More follows: it must be a string constant (unit name). */
4564 token = real_yylex ();
4565 if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
4567 error ("invalid #pragma unit");
4570 token = real_yylex ();
4571 if (token != END_OF_LINE)
4572 warning ("trailing characters ignored");
4575 else if (! strcmp (pname, "interface"))
4577 tree fileinfo = IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename));
4578 char *main_filename = input_filename;
4580 main_filename = file_name_nondirectory (main_filename);
4582 token = real_yylex ();
4584 if (token != END_OF_LINE)
4587 || TREE_CODE (yylval.ttype) != STRING_CST)
4589 error ("invalid `#pragma interface'");
4592 main_filename = TREE_STRING_POINTER (yylval.ttype);
4593 token = real_yylex ();
4596 if (token != END_OF_LINE)
4597 warning ("garbage after `#pragma interface' ignored");
4599 #ifndef NO_LINKAGE_HEURISTICS
4602 if (impl_file_chain == 0)
4604 /* If this is zero at this point, then we are
4605 auto-implementing. */
4606 if (main_input_filename == 0)
4607 main_input_filename = input_filename;
4609 #ifdef AUTO_IMPLEMENT
4610 filename = file_name_nondirectory (main_input_filename);
4611 fi = get_time_identifier (filename);
4612 fi = IDENTIFIER_CLASS_VALUE (fi);
4613 TREE_INT_CST_LOW (fi) = 0;
4614 TREE_INT_CST_HIGH (fi) = 1;
4616 impl_file_chain = (struct impl_files *)permalloc (sizeof (struct impl_files));
4617 impl_file_chain->filename = filename;
4618 impl_file_chain->next = 0;
4622 interface_only = interface_strcmp (main_filename);
4623 interface_unknown = 0;
4624 TREE_INT_CST_LOW (fileinfo) = interface_only;
4625 TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
4626 #endif /* NO_LINKAGE_HEURISTICS */
4630 else if (! strcmp (pname, "implementation"))
4632 tree fileinfo = IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename));
4633 char *main_filename = main_input_filename ? main_input_filename : input_filename;
4635 main_filename = file_name_nondirectory (main_filename);
4636 token = real_yylex ();
4637 if (token != END_OF_LINE)
4640 || TREE_CODE (yylval.ttype) != STRING_CST)
4642 error ("invalid `#pragma implementation'");
4645 main_filename = TREE_STRING_POINTER (yylval.ttype);
4646 token = real_yylex ();
4649 if (token != END_OF_LINE)
4650 warning ("garbage after `#pragma implementation' ignored");
4652 #ifndef NO_LINKAGE_HEURISTICS
4653 if (write_virtuals == 3)
4655 struct impl_files *ifiles = impl_file_chain;
4658 if (! strcmp (ifiles->filename, main_filename))
4660 ifiles = ifiles->next;
4664 ifiles = (struct impl_files*) permalloc (sizeof (struct impl_files));
4665 ifiles->filename = main_filename;
4666 ifiles->next = impl_file_chain;
4667 impl_file_chain = ifiles;
4670 else if ((main_input_filename != 0
4671 && ! strcmp (main_input_filename, input_filename))
4672 || ! strcmp (input_filename, main_filename))
4675 if (impl_file_chain == 0)
4677 impl_file_chain = (struct impl_files*) permalloc (sizeof (struct impl_files));
4678 impl_file_chain->filename = main_filename;
4679 impl_file_chain->next = 0;
4683 error ("`#pragma implementation' can only appear at top-level");
4686 /* We make this non-zero so that we infer decl linkage
4687 in the impl file only for variables first declared
4688 in the interface file. */
4689 interface_unknown = 1;
4691 /* We make this zero so that templates in the impl
4692 file will be emitted properly. */
4693 interface_unknown = 0;
4695 TREE_INT_CST_LOW (fileinfo) = interface_only;
4696 TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
4697 #endif /* NO_LINKAGE_HEURISTICS */
4705 #ifdef HANDLE_SYSV_PRAGMA
4707 /* Handle a #pragma directive. INPUT is the current input stream,
4708 and C is a character to reread. Processes the entire input line
4709 and returns a character for the caller to reread: either \n or EOF. */
4711 /* This function has to be in this file, in order to get at
4715 handle_sysv_pragma (finput, token)
4727 handle_pragma_token ("ignored", yylval.ttype);
4730 handle_pragma_token ("(", NULL_TREE);
4733 handle_pragma_token (")", NULL_TREE);
4736 handle_pragma_token (",", NULL_TREE);
4739 handle_pragma_token ("=", NULL_TREE);
4742 handle_pragma_token ("(", NULL_TREE);
4743 handle_pragma_token (")", NULL_TREE);
4747 handle_pragma_token (NULL_PTR, NULL_TREE);
4750 token = real_yylex ();
4753 #endif /* HANDLE_SYSV_PRAGMA */