1 /* Separate lexical analyzer for GNU C++.
2 Copyright (C) 1987, 89, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file is the lexical analyzer for GNU C++. */
25 /* Cause the `yydebug' variable to be defined. */
29 #include <sys/types.h>
42 #ifdef MULTIBYTE_CHARS
48 #ifndef MULTIBYTE_CHARS
52 extern double atof ();
58 extern char *index ();
59 extern char *rindex ();
63 extern int errno
; /* needed for VAX. */
66 #define obstack_chunk_alloc xmalloc
67 #define obstack_chunk_free free
69 extern struct obstack permanent_obstack
;
70 extern struct obstack
*current_obstack
, *saveable_obstack
;
72 extern void yyprint
PROTO((FILE *, int, YYSTYPE
));
73 extern void set_float_handler
PROTO((jmp_buf));
74 extern void compiler_error
PROTO((char *, HOST_WIDE_INT
,
77 static tree get_time_identifier
PROTO((char *));
78 static int check_newline
PROTO((void));
79 static int skip_white_space
PROTO((int));
80 static int yynextch
PROTO((void));
81 static void finish_defarg
PROTO((void));
82 static int my_get_run_time
PROTO((void));
83 static int get_last_nonwhite_on_line
PROTO((void));
84 static int interface_strcmp
PROTO((char *));
85 static int readescape
PROTO((int *));
86 static char *extend_token_buffer
PROTO((char *));
87 static void consume_string
PROTO((struct obstack
*, int));
88 static void set_typedecl_interface_info
PROTO((tree
, tree
));
89 static void feed_defarg
PROTO((tree
, tree
));
90 static int set_vardecl_interface_info
PROTO((tree
, tree
));
91 static void store_pending_inline
PROTO((tree
, struct pending_inline
*));
92 static void reinit_parse_for_expr
PROTO((struct obstack
*));
94 /* Given a file name X, return the nondirectory portion.
95 Keep in mind that X can be computed more than once. */
96 #ifndef FILE_NAME_NONDIRECTORY
97 #define FILE_NAME_NONDIRECTORY(X) \
98 (rindex (X, '/') != 0 ? rindex (X, '/') + 1 : X)
101 /* This obstack is needed to hold text. It is not safe to use
102 TOKEN_BUFFER because `check_newline' calls `yylex'. */
103 struct obstack inline_text_obstack
;
104 char *inline_text_firstobj
;
108 /* Pending language change.
109 Positive is push count, negative is pop count. */
110 int pending_lang_change
= 0;
112 /* Wrap the current header file in extern "C". */
113 static int c_header_level
= 0;
115 extern int first_token
;
116 extern struct obstack token_obstack
;
118 /* ??? Don't really know where this goes yet. */
122 extern void put_back (/* int */);
123 extern int input_redirected ();
124 extern void feed_input (/* char *, int */);
127 /* Holds translations from TREE_CODEs to operator name strings,
128 i.e., opname_tab[PLUS_EXPR] == "+". */
132 extern int yychar
; /* the lookahead symbol */
133 extern YYSTYPE yylval
; /* the semantic value of the */
134 /* lookahead symbol */
137 YYLTYPE yylloc
; /* location data for the lookahead */
142 /* the declaration found for the last IDENTIFIER token read in.
143 yylex must look this up to detect typedefs, which get token type TYPENAME,
144 so it is left around in case the identifier is not a typedef but is
145 used in a context which makes it a reference to a variable. */
148 /* The elements of `ridpointers' are identifier nodes
149 for the reserved type names and storage classes.
150 It is indexed by a RID_... value. */
151 tree ridpointers
[(int) RID_MAX
];
153 /* We may keep statistics about how long which files took to compile. */
154 static int header_time
, body_time
;
155 static tree filename_times
;
156 static tree this_filename_time
;
158 /* Array for holding counts of the numbers of tokens seen. */
159 extern int *token_count
;
161 /* Return something to represent absolute declarators containing a *.
162 TARGET is the absolute declarator that the * contains.
163 CV_QUALIFIERS is a list of modifiers such as const or volatile
164 to apply to the pointer type, represented as identifiers.
166 We return an INDIRECT_REF whose "contents" are TARGET
167 and whose type is the modifier list. */
170 make_pointer_declarator (cv_qualifiers
, target
)
171 tree cv_qualifiers
, target
;
173 if (target
&& TREE_CODE (target
) == IDENTIFIER_NODE
174 && ANON_AGGRNAME_P (target
))
175 error ("type name expected before `*'");
176 target
= build_parse_node (INDIRECT_REF
, target
);
177 TREE_TYPE (target
) = cv_qualifiers
;
181 /* Return something to represent absolute declarators containing a &.
182 TARGET is the absolute declarator that the & contains.
183 CV_QUALIFIERS is a list of modifiers such as const or volatile
184 to apply to the reference type, represented as identifiers.
186 We return an ADDR_EXPR whose "contents" are TARGET
187 and whose type is the modifier list. */
190 make_reference_declarator (cv_qualifiers
, target
)
191 tree cv_qualifiers
, target
;
195 if (TREE_CODE (target
) == ADDR_EXPR
)
197 error ("cannot declare references to references");
200 if (TREE_CODE (target
) == INDIRECT_REF
)
202 error ("cannot declare pointers to references");
205 if (TREE_CODE (target
) == IDENTIFIER_NODE
&& ANON_AGGRNAME_P (target
))
206 error ("type name expected before `&'");
208 target
= build_parse_node (ADDR_EXPR
, target
);
209 TREE_TYPE (target
) = cv_qualifiers
;
214 make_call_declarator (target
, parms
, cv_qualifiers
, exception_specification
)
215 tree target
, parms
, cv_qualifiers
, exception_specification
;
217 target
= build_parse_node (CALL_EXPR
, target
, parms
, cv_qualifiers
);
218 TREE_TYPE (target
) = exception_specification
;
223 set_quals_and_spec (call_declarator
, cv_qualifiers
, exception_specification
)
224 tree call_declarator
, cv_qualifiers
, exception_specification
;
226 TREE_OPERAND (call_declarator
, 2) = cv_qualifiers
;
227 TREE_TYPE (call_declarator
) = exception_specification
;
230 /* Build names and nodes for overloaded operators. */
232 tree ansi_opname
[LAST_CPLUS_TREE_CODE
];
233 tree ansi_assopname
[LAST_CPLUS_TREE_CODE
];
236 operator_name_string (name
)
239 char *opname
= IDENTIFIER_POINTER (name
) + 2;
243 /* Works for builtin and user defined types. */
244 if (IDENTIFIER_GLOBAL_VALUE (name
)
245 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name
)) == TYPE_DECL
)
246 return IDENTIFIER_POINTER (name
);
248 if (opname
[0] == 'a' && opname
[2] != '\0' && opname
[2] != '_')
252 opname_table
= ansi_assopname
;
257 opname_table
= ansi_opname
;
260 for (i
= 0; i
< (int) LAST_CPLUS_TREE_CODE
; i
++)
262 if (opname
[0] == IDENTIFIER_POINTER (opname_table
[i
])[2+assign
]
263 && opname
[1] == IDENTIFIER_POINTER (opname_table
[i
])[3+assign
])
267 if (i
== LAST_CPLUS_TREE_CODE
)
268 return "<invalid operator>";
271 return assignop_tab
[i
];
273 return opname_tab
[i
];
276 int interface_only
; /* whether or not current file is only for
277 interface definitions. */
278 int interface_unknown
; /* whether or not we know this class
279 to behave according to #pragma interface. */
281 /* lexical analyzer */
283 /* File used for outputting assembler code. */
284 extern FILE *asm_out_file
;
286 #ifndef WCHAR_TYPE_SIZE
288 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
290 #define WCHAR_TYPE_SIZE BITS_PER_WORD
294 /* Number of bytes in a wide character. */
295 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
297 static int maxtoken
; /* Current nominal length of token buffer. */
298 char *token_buffer
; /* Pointer to token buffer.
299 Actual allocated length is maxtoken + 2. */
304 /* Nonzero tells yylex to ignore \ in string constants. */
305 static int ignore_escape_flag
= 0;
308 get_time_identifier (name
)
311 tree time_identifier
;
312 int len
= strlen (name
);
313 char *buf
= (char *) alloca (len
+ 6);
314 strcpy (buf
, "file ");
315 bcopy (name
, buf
+5, len
);
317 time_identifier
= get_identifier (buf
);
318 if (IDENTIFIER_LOCAL_VALUE (time_identifier
) == NULL_TREE
)
320 push_obstacks_nochange ();
321 end_temporary_allocation ();
322 IDENTIFIER_LOCAL_VALUE (time_identifier
) = build_int_2 (0, 0);
323 IDENTIFIER_CLASS_VALUE (time_identifier
) = build_int_2 (0, 1);
324 IDENTIFIER_GLOBAL_VALUE (time_identifier
) = filename_times
;
325 filename_times
= time_identifier
;
328 return time_identifier
;
337 int old_quiet_flag
= quiet_flag
;
340 this_time
= get_run_time ();
341 quiet_flag
= old_quiet_flag
;
345 /* Table indexed by tree code giving a string containing a character
346 classifying the tree code. Possibilities are
347 t, d, s, c, r, <, 1 and 2. See cp/cp-tree.def for details. */
349 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
351 char *cplus_tree_code_type
[] = {
353 #include "cp-tree.def"
357 /* Table indexed by tree code giving number of expression
358 operands beyond the fixed part of the node structure.
359 Not used for types or decls. */
361 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
363 int cplus_tree_code_length
[] = {
365 #include "cp-tree.def"
369 /* Names of tree components.
370 Used for printing out the tree and error messages. */
371 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
373 char *cplus_tree_code_name
[] = {
375 #include "cp-tree.def"
379 /* toplev.c needs to call these. */
384 /* the beginning of the file is a new line; check for # */
385 /* With luck, we discover the real source file's name from that
386 and put it in input_filename. */
387 put_back (check_newline ());
388 if (flag_gnu_xref
) GNU_xref_begin (input_filename
);
389 init_repo (input_filename
);
395 extern int errorcount
, sorrycount
;
396 if (flag_gnu_xref
) GNU_xref_end (errorcount
+sorrycount
);
406 init_filename_times ()
408 this_filename_time
= get_time_identifier ("<top level>");
409 if (flag_detailed_statistics
)
412 body_time
= my_get_run_time ();
413 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time
)) = body_time
;
417 /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
418 Stuck this hack in to get the files open correctly; this is called
419 in place of init_lex if we are an unexec'd binary. */
423 reinit_lang_specific ()
425 init_filename_times ();
426 reinit_search_statistics ();
433 extern int flag_no_gnu_keywords
;
434 extern int flag_operator_names
;
438 /* Initialize the lookahead machinery. */
441 /* Make identifier nodes long enough for the language-specific slots. */
442 set_identifier_size (sizeof (struct lang_identifier
));
443 decl_printable_name
= lang_printable_name
;
445 init_cplus_expand ();
448 = (char **) realloc (tree_code_type
,
449 sizeof (char *) * LAST_CPLUS_TREE_CODE
);
451 = (int *) realloc (tree_code_length
,
452 sizeof (int) * LAST_CPLUS_TREE_CODE
);
454 = (char **) realloc (tree_code_name
,
455 sizeof (char *) * LAST_CPLUS_TREE_CODE
);
456 bcopy ((char *)cplus_tree_code_type
,
457 (char *)(tree_code_type
+ (int) LAST_AND_UNUSED_TREE_CODE
),
458 (LAST_CPLUS_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (char *));
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) METHOD_CALL_EXPR
] = get_identifier ("__wr");
596 IDENTIFIER_OPNAME_P (ansi_opname
[(int) METHOD_CALL_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) METHOD_CALL_EXPR
] = "->()";
728 opname_tab
[(int) INDIRECT_REF
] = "*";
729 opname_tab
[(int) ARRAY_REF
] = "[]";
730 opname_tab
[(int) MODIFY_EXPR
] = "=";
731 opname_tab
[(int) NEW_EXPR
] = "new";
732 opname_tab
[(int) DELETE_EXPR
] = "delete";
733 opname_tab
[(int) VEC_NEW_EXPR
] = "new []";
734 opname_tab
[(int) VEC_DELETE_EXPR
] = "delete []";
735 opname_tab
[(int) COND_EXPR
] = "?:";
736 opname_tab
[(int) CALL_EXPR
] = "()";
737 opname_tab
[(int) PLUS_EXPR
] = "+";
738 opname_tab
[(int) MINUS_EXPR
] = "-";
739 opname_tab
[(int) MULT_EXPR
] = "*";
740 opname_tab
[(int) TRUNC_DIV_EXPR
] = "/";
741 opname_tab
[(int) CEIL_DIV_EXPR
] = "(ceiling /)";
742 opname_tab
[(int) FLOOR_DIV_EXPR
] = "(floor /)";
743 opname_tab
[(int) ROUND_DIV_EXPR
] = "(round /)";
744 opname_tab
[(int) TRUNC_MOD_EXPR
] = "%";
745 opname_tab
[(int) CEIL_MOD_EXPR
] = "(ceiling %)";
746 opname_tab
[(int) FLOOR_MOD_EXPR
] = "(floor %)";
747 opname_tab
[(int) ROUND_MOD_EXPR
] = "(round %)";
748 opname_tab
[(int) NEGATE_EXPR
] = "-";
749 opname_tab
[(int) MIN_EXPR
] = "<?";
750 opname_tab
[(int) MAX_EXPR
] = ">?";
751 opname_tab
[(int) ABS_EXPR
] = "abs";
752 opname_tab
[(int) FFS_EXPR
] = "ffs";
753 opname_tab
[(int) LSHIFT_EXPR
] = "<<";
754 opname_tab
[(int) RSHIFT_EXPR
] = ">>";
755 opname_tab
[(int) BIT_IOR_EXPR
] = "|";
756 opname_tab
[(int) BIT_XOR_EXPR
] = "^";
757 opname_tab
[(int) BIT_AND_EXPR
] = "&";
758 opname_tab
[(int) BIT_ANDTC_EXPR
] = "&~";
759 opname_tab
[(int) BIT_NOT_EXPR
] = "~";
760 opname_tab
[(int) TRUTH_ANDIF_EXPR
] = "&&";
761 opname_tab
[(int) TRUTH_ORIF_EXPR
] = "||";
762 opname_tab
[(int) TRUTH_AND_EXPR
] = "strict &&";
763 opname_tab
[(int) TRUTH_OR_EXPR
] = "strict ||";
764 opname_tab
[(int) TRUTH_NOT_EXPR
] = "!";
765 opname_tab
[(int) LT_EXPR
] = "<";
766 opname_tab
[(int) LE_EXPR
] = "<=";
767 opname_tab
[(int) GT_EXPR
] = ">";
768 opname_tab
[(int) GE_EXPR
] = ">=";
769 opname_tab
[(int) EQ_EXPR
] = "==";
770 opname_tab
[(int) NE_EXPR
] = "!=";
771 opname_tab
[(int) IN_EXPR
] = "in";
772 opname_tab
[(int) RANGE_EXPR
] = "...";
773 opname_tab
[(int) CONVERT_EXPR
] = "+";
774 opname_tab
[(int) ADDR_EXPR
] = "&";
775 opname_tab
[(int) PREDECREMENT_EXPR
] = "--";
776 opname_tab
[(int) PREINCREMENT_EXPR
] = "++";
777 opname_tab
[(int) POSTDECREMENT_EXPR
] = "--";
778 opname_tab
[(int) POSTINCREMENT_EXPR
] = "++";
779 opname_tab
[(int) COMPOUND_EXPR
] = ",";
781 assignop_tab
[(int) NOP_EXPR
] = "=";
782 assignop_tab
[(int) PLUS_EXPR
] = "+=";
783 assignop_tab
[(int) CONVERT_EXPR
] = "+=";
784 assignop_tab
[(int) MINUS_EXPR
] = "-=";
785 assignop_tab
[(int) NEGATE_EXPR
] = "-=";
786 assignop_tab
[(int) MULT_EXPR
] = "*=";
787 assignop_tab
[(int) INDIRECT_REF
] = "*=";
788 assignop_tab
[(int) TRUNC_DIV_EXPR
] = "/=";
789 assignop_tab
[(int) EXACT_DIV_EXPR
] = "(exact /=)";
790 assignop_tab
[(int) CEIL_DIV_EXPR
] = "(ceiling /=)";
791 assignop_tab
[(int) FLOOR_DIV_EXPR
] = "(floor /=)";
792 assignop_tab
[(int) ROUND_DIV_EXPR
] = "(round /=)";
793 assignop_tab
[(int) TRUNC_MOD_EXPR
] = "%=";
794 assignop_tab
[(int) CEIL_MOD_EXPR
] = "(ceiling %=)";
795 assignop_tab
[(int) FLOOR_MOD_EXPR
] = "(floor %=)";
796 assignop_tab
[(int) ROUND_MOD_EXPR
] = "(round %=)";
797 assignop_tab
[(int) MIN_EXPR
] = "<?=";
798 assignop_tab
[(int) MAX_EXPR
] = ">?=";
799 assignop_tab
[(int) LSHIFT_EXPR
] = "<<=";
800 assignop_tab
[(int) RSHIFT_EXPR
] = ">>=";
801 assignop_tab
[(int) BIT_IOR_EXPR
] = "|=";
802 assignop_tab
[(int) BIT_XOR_EXPR
] = "^=";
803 assignop_tab
[(int) BIT_AND_EXPR
] = "&=";
804 assignop_tab
[(int) ADDR_EXPR
] = "&=";
806 init_filename_times ();
808 /* Some options inhibit certain reserved words.
809 Clear those words out of the hash table so they won't be recognized. */
810 #define UNSET_RESERVED_WORD(STRING) \
811 do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
812 if (s) s->name = ""; } while (0)
815 /* let's parse things, and if they use it, then give them an error. */
816 if (!flag_exceptions
)
818 UNSET_RESERVED_WORD ("throw");
819 UNSET_RESERVED_WORD ("try");
820 UNSET_RESERVED_WORD ("catch");
824 if (!flag_rtti
|| flag_no_gnu_keywords
)
826 UNSET_RESERVED_WORD ("classof");
827 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
)
890 fprintf (file
, " `%s'", 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 if (is_member_template (t
->fndecl
))
1194 begin_member_template_processing (DECL_TI_ARGS (t
->fndecl
));
1197 feed_input (t
->buf
, t
->len
);
1200 if (input_filename
!= t
->filename
)
1202 input_filename
= t
->filename
;
1203 /* Get interface/implementation back in sync. */
1204 extract_interface_info ();
1207 input_filename
= t
->filename
;
1208 interface_unknown
= t
->interface
== 1;
1209 interface_only
= t
->interface
== 0;
1211 yychar
= PRE_PARSED_FUNCTION_DECL
;
1213 /* Pass back a handle on the rest of the inline functions, so that they
1214 can be processed later. */
1215 yylval
.ttype
= build_tree_list ((tree
) t
, t
->fndecl
);
1216 DECL_PENDING_INLINE_INFO (t
->fndecl
) = 0;
1219 static int nextchar
= -1;
1221 /* Called from the fndecl rule in the parser when the function just parsed
1222 was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1223 do_pending_inlines). */
1226 process_next_inline (t
)
1230 struct pending_inline
*i
= (struct pending_inline
*) TREE_PURPOSE (t
);
1231 context
= hack_decl_function_context (i
->fndecl
);
1232 if (is_member_template (i
->fndecl
))
1233 end_member_template_processing ();
1235 pop_cp_function_context (context
);
1237 if (yychar
== YYEMPTY
)
1239 if (yychar
!= END_OF_SAVED_INPUT
)
1241 error ("parse error at end of saved function text");
1243 /* restore_pending_input will abort unless yychar is either
1244 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1245 hosed, feed back YYEMPTY. We also need to discard nextchar,
1246 since that may have gotten set as well. */
1251 if (i
&& i
->fndecl
!= NULL_TREE
)
1253 context
= hack_decl_function_context (i
->fndecl
);
1255 push_cp_function_context (context
);
1256 if (is_member_template (i
->fndecl
))
1257 begin_member_template_processing (DECL_TI_ARGS (i
->fndecl
));
1258 feed_input (i
->buf
, i
->len
);
1260 input_filename
= i
->filename
;
1261 yychar
= PRE_PARSED_FUNCTION_DECL
;
1262 yylval
.ttype
= build_tree_list ((tree
) i
, i
->fndecl
);
1263 DECL_PENDING_INLINE_INFO (i
->fndecl
) = 0;
1267 interface_unknown
= i
->interface
== 1;
1268 interface_only
= i
->interface
== 0;
1271 extract_interface_info ();
1274 /* Since inline methods can refer to text which has not yet been seen,
1275 we store the text of the method in a structure which is placed in the
1276 DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1277 After parsing the body of the class definition, the FUNCTION_DECL's are
1278 scanned to see which ones have this field set. Those are then digested
1281 This function's FUNCTION_DECL will have a bit set in its common so
1282 that we know to watch out for it. */
1285 consume_string (this_obstack
, matching_char
)
1286 register struct obstack
*this_obstack
;
1290 int starting_lineno
= lineno
;
1296 int save_lineno
= lineno
;
1297 lineno
= starting_lineno
;
1298 if (matching_char
== '"')
1299 error ("end of file encountered inside string constant");
1301 error ("end of file encountered inside character constant");
1302 lineno
= save_lineno
;
1307 obstack_1grow (this_obstack
, c
);
1309 obstack_1grow (this_obstack
, c
);
1311 /* Make sure we continue the loop */
1318 pedwarn ("ANSI C++ forbids newline in string constant");
1321 obstack_1grow (this_obstack
, c
);
1323 while (c
!= matching_char
);
1326 static int nextyychar
= YYEMPTY
;
1327 static YYSTYPE nextyylval
;
1329 struct pending_input
{
1330 int nextchar
, yychar
, nextyychar
, eof
;
1331 YYSTYPE yylval
, nextyylval
;
1332 struct obstack token_obstack
;
1336 struct pending_input
*
1337 save_pending_input ()
1339 struct pending_input
*p
;
1340 p
= (struct pending_input
*) xmalloc (sizeof (struct pending_input
));
1341 p
->nextchar
= nextchar
;
1343 p
->nextyychar
= nextyychar
;
1345 p
->nextyylval
= nextyylval
;
1346 p
->eof
= end_of_file
;
1347 yychar
= nextyychar
= YYEMPTY
;
1349 p
->first_token
= first_token
;
1350 p
->token_obstack
= token_obstack
;
1353 gcc_obstack_init (&token_obstack
);
1359 restore_pending_input (p
)
1360 struct pending_input
*p
;
1362 my_friendly_assert (nextchar
== -1, 229);
1363 nextchar
= p
->nextchar
;
1364 my_friendly_assert (yychar
== YYEMPTY
|| yychar
== END_OF_SAVED_INPUT
, 230);
1366 my_friendly_assert (nextyychar
== YYEMPTY
, 231);
1367 nextyychar
= p
->nextyychar
;
1369 nextyylval
= p
->nextyylval
;
1370 first_token
= p
->first_token
;
1371 obstack_free (&token_obstack
, (char *) 0);
1372 token_obstack
= p
->token_obstack
;
1373 end_of_file
= p
->eof
;
1377 /* Return next non-whitespace input character, which may come
1378 from `finput', or from `nextchar'. */
1391 return skip_white_space (c
);
1394 /* Unget character CH from the input stream.
1395 If RESCAN is non-zero, then we want to `see' this
1396 character as the next input token. */
1399 yyungetc (ch
, rescan
)
1403 /* Unget a character from the input stream. */
1404 if (yychar
== YYEMPTY
|| rescan
== 0)
1407 put_back (nextchar
);
1412 my_friendly_assert (nextyychar
== YYEMPTY
, 232);
1413 nextyychar
= yychar
;
1414 nextyylval
= yylval
;
1420 clear_inline_text_obstack ()
1422 obstack_free (&inline_text_obstack
, inline_text_firstobj
);
1425 /* This function stores away the text for an inline function that should
1426 be processed later. It decides how much later, and may need to move
1427 the info between obstacks; therefore, the caller should not refer to
1428 the T parameter after calling this function. */
1431 store_pending_inline (decl
, t
)
1433 struct pending_inline
*t
;
1436 DECL_PENDING_INLINE_INFO (decl
) = t
;
1438 /* Because we use obstacks, we must process these in precise order. */
1439 t
->next
= pending_inlines
;
1440 pending_inlines
= t
;
1444 reinit_parse_for_method (yychar
, decl
)
1449 int starting_lineno
= lineno
;
1450 char *starting_filename
= input_filename
;
1452 reinit_parse_for_block (yychar
, &inline_text_obstack
);
1454 len
= obstack_object_size (&inline_text_obstack
);
1455 current_base_init_list
= NULL_TREE
;
1456 current_member_init_list
= NULL_TREE
;
1457 if (decl
== void_type_node
1458 || (current_class_type
&& TYPE_REDEFINED (current_class_type
)))
1460 /* Happens when we get two declarations of the same
1461 function in the same scope. */
1462 char *buf
= obstack_finish (&inline_text_obstack
);
1463 obstack_free (&inline_text_obstack
, buf
);
1468 struct pending_inline
*t
;
1469 char *buf
= obstack_finish (&inline_text_obstack
);
1471 t
= (struct pending_inline
*) obstack_alloc (&inline_text_obstack
,
1472 sizeof (struct pending_inline
));
1473 t
->lineno
= starting_lineno
;
1474 t
->filename
= starting_filename
;
1481 if (interface_unknown
&& processing_template_defn
&& flag_external_templates
&& ! DECL_IN_SYSTEM_HEADER (decl
))
1482 warn_if_unknown_interface (decl
);
1484 t
->interface
= (interface_unknown
? 1 : (interface_only
? 0 : 2));
1485 store_pending_inline (decl
, t
);
1489 /* Consume a block -- actually, a method beginning
1490 with `:' or `{' -- and save it away on the specified obstack. */
1493 reinit_parse_for_block (pyychar
, obstackp
)
1495 struct obstack
*obstackp
;
1499 int starting_lineno
= lineno
;
1500 char *starting_filename
= input_filename
;
1502 int look_for_semicolon
= 0;
1503 int look_for_lbrac
= 0;
1506 obstack_1grow (obstackp
, '{');
1507 else if (pyychar
== '=')
1508 look_for_semicolon
= 1;
1509 else if (pyychar
== ':')
1511 obstack_1grow (obstackp
, pyychar
);
1515 else if (pyychar
== RETURN
)
1517 obstack_grow (obstackp
, "return", 6);
1521 else if (pyychar
== TRY
)
1523 obstack_grow (obstackp
, "try", 3);
1529 yyerror ("parse error in method specification");
1530 obstack_1grow (obstackp
, '{');
1533 if (nextchar
!= EOF
)
1543 int this_lineno
= lineno
;
1545 c
= skip_white_space (c
);
1547 /* Don't lose our cool if there are lots of comments. */
1548 if (lineno
== this_lineno
+ 1)
1549 obstack_1grow (obstackp
, '\n');
1550 else if (lineno
== this_lineno
)
1552 else if (lineno
- this_lineno
< 10)
1555 for (i
= lineno
- this_lineno
; i
> 0; i
--)
1556 obstack_1grow (obstackp
, '\n');
1561 sprintf (buf
, "\n# %d \"", lineno
);
1563 obstack_grow (obstackp
, buf
, len
);
1565 len
= strlen (input_filename
);
1566 obstack_grow (obstackp
, input_filename
, len
);
1567 obstack_1grow (obstackp
, '\"');
1568 obstack_1grow (obstackp
, '\n');
1571 while (c
> ' ') /* ASCII dependent... */
1573 obstack_1grow (obstackp
, c
);
1582 if (blev
== 0 && !look_for_semicolon
)
1586 if (peekyylex () == CATCH
)
1589 obstack_grow (obstackp
, " catch ", 7);
1606 /* Don't act on the next character...e.g, doing an escaped
1611 error_with_file_and_line (starting_filename
,
1613 "end of file read inside definition");
1616 obstack_1grow (obstackp
, c
);
1619 consume_string (obstackp
, c
);
1621 consume_string (obstackp
, c
);
1626 error ("function body for constructor missing");
1627 obstack_1grow (obstackp
, '{');
1628 obstack_1grow (obstackp
, '}');
1632 else if (look_for_semicolon
&& blev
== 0)
1640 error_with_file_and_line (starting_filename
,
1642 "end of file read inside definition");
1647 obstack_1grow (obstackp
, c
);
1652 obstack_1grow (obstackp
, '\0');
1655 /* Consume a no-commas expression -- actually, a default argument -- and
1656 save it away on the specified obstack. */
1659 reinit_parse_for_expr (obstackp
)
1660 struct obstack
*obstackp
;
1663 int starting_lineno
= lineno
;
1664 char *starting_filename
= input_filename
;
1666 int look_for_semicolon
= 0;
1667 int look_for_lbrac
= 0;
1670 if (nextchar
!= EOF
)
1680 int this_lineno
= lineno
;
1682 c
= skip_white_space (c
);
1684 /* Don't lose our cool if there are lots of comments. */
1685 if (lineno
== this_lineno
+ 1)
1686 obstack_1grow (obstackp
, '\n');
1687 else if (lineno
== this_lineno
)
1689 else if (lineno
- this_lineno
< 10)
1692 for (i
= lineno
- this_lineno
; i
> 0; --i
)
1693 obstack_1grow (obstackp
, '\n');
1698 sprintf (buf
, "\n# %d \"", lineno
);
1700 obstack_grow (obstackp
, buf
, len
);
1702 len
= strlen (input_filename
);
1703 obstack_grow (obstackp
, input_filename
, len
);
1704 obstack_1grow (obstackp
, '\"');
1705 obstack_1grow (obstackp
, '\n');
1708 while (c
> ' ') /* ASCII dependent... */
1710 if (plev
<= 0 && (c
== ')' || c
== ','))
1715 obstack_1grow (obstackp
, c
);
1716 if (c
== '(' || c
== '[')
1718 else if (c
== ']' || c
== ')')
1722 /* Don't act on the next character...e.g, doing an escaped
1727 error_with_file_and_line (starting_filename
,
1729 "end of file read inside definition");
1732 obstack_1grow (obstackp
, c
);
1735 consume_string (obstackp
, c
);
1737 consume_string (obstackp
, c
);
1743 error_with_file_and_line (starting_filename
,
1745 "end of file read inside definition");
1750 obstack_1grow (obstackp
, c
);
1755 obstack_1grow (obstackp
, '\0');
1758 int do_snarf_defarg
;
1760 /* Decide whether the default argument we are about to see should be
1761 gobbled up as text for later parsing. */
1764 maybe_snarf_defarg ()
1766 if (current_class_type
&& TYPE_BEING_DEFINED (current_class_type
))
1767 do_snarf_defarg
= 1;
1770 /* When we see a default argument in a method declaration, we snarf it as
1771 text using snarf_defarg. When we get up to namespace scope, we then go
1772 through and parse all of them using do_pending_defargs. Since yacc
1773 parsers are not reentrant, we retain defargs state in these two
1774 variables so that subsequent calls to do_pending_defargs can resume
1775 where the previous call left off. */
1786 struct pending_inline
*t
;
1788 reinit_parse_for_expr (&inline_text_obstack
);
1789 len
= obstack_object_size (&inline_text_obstack
);
1790 buf
= obstack_finish (&inline_text_obstack
);
1792 push_obstacks (&inline_text_obstack
, &inline_text_obstack
);
1793 arg
= make_node (DEFAULT_ARG
);
1794 DEFARG_LENGTH (arg
) = len
- 1;
1795 DEFARG_POINTER (arg
) = buf
;
1801 /* Called from grokfndecl to note a function decl with unparsed default
1802 arguments for later processing. Also called from grokdeclarator
1803 for function types with unparsed defargs; the call from grokfndecl
1804 will always come second, so we can overwrite the entry from the type. */
1807 add_defarg_fn (decl
)
1810 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1811 TREE_VALUE (defarg_fns
) = decl
;
1814 push_obstacks (&inline_text_obstack
, &inline_text_obstack
);
1815 defarg_fns
= tree_cons (current_class_type
, decl
, defarg_fns
);
1820 /* Helper for do_pending_defargs. Starts the parsing of a default arg. */
1826 tree d
= TREE_PURPOSE (p
);
1827 feed_input (DEFARG_POINTER (d
), DEFARG_LENGTH (d
));
1828 if (TREE_CODE (f
) == FUNCTION_DECL
)
1830 lineno
= DECL_SOURCE_LINE (f
);
1831 input_filename
= DECL_SOURCE_FILE (f
);
1833 yychar
= DEFARG_MARKER
;
1837 /* Helper for do_pending_defargs. Ends the parsing of a default arg. */
1842 if (yychar
== YYEMPTY
)
1844 if (yychar
!= END_OF_SAVED_INPUT
)
1846 error ("parse error at end of saved function text");
1848 /* restore_pending_input will abort unless yychar is either
1849 END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1850 hosed, feed back YYEMPTY. We also need to discard nextchar,
1851 since that may have gotten set as well. */
1858 /* Main function for deferred parsing of default arguments. Called from
1862 do_pending_defargs ()
1867 for (; defarg_fns
; defarg_fns
= TREE_CHAIN (defarg_fns
))
1869 tree defarg_fn
= TREE_VALUE (defarg_fns
);
1870 if (defarg_parm
== NULL_TREE
)
1874 push_nested_class (TREE_PURPOSE (defarg_fns
), 1);
1877 if (TREE_CODE (defarg_fn
) == FUNCTION_DECL
)
1880 for (p
= DECL_ARGUMENTS (defarg_fn
); p
; p
= TREE_CHAIN (p
))
1881 pushdecl (copy_node (p
));
1883 defarg_parm
= TYPE_ARG_TYPES (TREE_TYPE (defarg_fn
));
1886 defarg_parm
= TYPE_ARG_TYPES (defarg_fn
);
1889 defarg_parm
= TREE_CHAIN (defarg_parm
);
1891 for (; defarg_parm
; defarg_parm
= TREE_CHAIN (defarg_parm
))
1892 if (TREE_PURPOSE (defarg_parm
)
1893 && TREE_CODE (TREE_PURPOSE (defarg_parm
)) == DEFAULT_ARG
)
1895 feed_defarg (defarg_fn
, defarg_parm
);
1897 /* Return to the parser, which will process this defarg
1898 and call us again. */
1903 pop_nested_class (1);
1907 /* Build a default function named NAME for type TYPE.
1908 KIND says what to build.
1910 When KIND == 0, build default destructor.
1911 When KIND == 1, build virtual destructor.
1912 When KIND == 2, build default constructor.
1913 When KIND == 3, build default X(const X&) constructor.
1914 When KIND == 4, build default X(X&) constructor.
1915 When KIND == 5, build default operator = (const X&).
1916 When KIND == 6, build default operator = (X&). */
1919 cons_up_default_function (type
, full_name
, kind
)
1920 tree type
, full_name
;
1923 extern tree void_list_node
;
1924 tree declspecs
= NULL_TREE
;
1928 tree name
= constructor_name (full_name
);
1934 declspecs
= build_decl_list (NULL_TREE
, ridpointers
[(int) RID_VIRTUAL
]);
1935 /* Fall through... */
1937 name
= build_parse_node (BIT_NOT_EXPR
, name
);
1938 args
= void_list_node
;
1942 /* Default constructor. */
1943 args
= void_list_node
;
1947 type
= build_type_variant (type
, 1, 0);
1948 /* Fall through... */
1950 /* According to ARM $12.8, the default copy ctor will be declared, but
1951 not defined, unless it's needed. */
1952 argtype
= build_reference_type (type
);
1953 args
= tree_cons (NULL_TREE
,
1954 build_tree_list (hash_tree_chain (argtype
, NULL_TREE
),
1955 get_identifier ("_ctor_arg")),
1962 declspecs
= build_decl_list (NULL_TREE
, type
);
1965 type
= build_type_variant (type
, 1, 0);
1967 name
= ansi_opname
[(int) MODIFY_EXPR
];
1969 argtype
= build_reference_type (type
);
1970 args
= tree_cons (NULL_TREE
,
1971 build_tree_list (hash_tree_chain (argtype
, NULL_TREE
),
1972 get_identifier ("_ctor_arg")),
1977 my_friendly_abort (59);
1980 declspecs
= decl_tree_cons (NULL_TREE
, ridpointers
[(int) RID_INLINE
],
1983 TREE_PARMLIST (args
) = 1;
1986 tree declarator
= make_call_declarator (name
, args
, NULL_TREE
, NULL_TREE
);
1988 declarator
= build_parse_node (ADDR_EXPR
, declarator
);
1990 fn
= grokfield (declarator
, declspecs
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1993 if (fn
== void_type_node
)
1997 SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn
)));
2000 if (processing_template_defn
)
2002 SET_DECL_IMPLICIT_INSTANTIATION (fn
);
2003 repo_template_used (fn
);
2008 if (CLASSTYPE_INTERFACE_KNOWN (type
))
2010 DECL_INTERFACE_KNOWN (fn
) = 1;
2011 DECL_NOT_REALLY_EXTERN (fn
) = (!CLASSTYPE_INTERFACE_ONLY (type
)
2012 && flag_implement_inlines
);
2016 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2018 mark_inline_for_output (fn
);
2020 #ifdef DEBUG_DEFAULT_FUNCTIONS
2021 { char *fn_type
= NULL
;
2025 case 0: fn_type
= "default destructor"; break;
2026 case 1: fn_type
= "virtual destructor"; break;
2027 case 2: fn_type
= "default constructor"; break;
2028 case 3: fn_type
= "default X(const X&)"; break;
2029 case 4: fn_type
= "default X(X&)"; break;
2033 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
2034 t
= TREE_OPERAND (name
, 0);
2035 fprintf (stderr
, "[[[[ %s for %s:\n%s]]]]\n", fn_type
,
2036 IDENTIFIER_POINTER (t
), func_buf
);
2039 #endif /* DEBUG_DEFAULT_FUNCTIONS */
2041 /* Show that this function was generated by the compiler. */
2042 SET_DECL_ARTIFICIAL (fn
);
2047 /* Heuristic to tell whether the user is missing a semicolon
2048 after a struct or enum declaration. Emit an error message
2049 if we know the user has blown it. */
2052 check_for_missing_semicolon (type
)
2060 && yychar
!= IDENTIFIER
2061 && yychar
!= TYPENAME
2062 && yychar
!= CV_QUALIFIER
2063 && yychar
!= SELFNAME
)
2066 if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type
)))
2067 error ("semicolon missing after %s declaration",
2068 TREE_CODE (type
) == ENUMERAL_TYPE
? "enum" : "struct");
2070 cp_error ("semicolon missing after declaration of `%T'", type
);
2071 shadow_tag (build_tree_list (0, type
));
2073 /* Could probably also hack cases where class { ... } f (); appears. */
2078 note_got_semicolon (type
)
2081 if (TREE_CODE_CLASS (TREE_CODE (type
)) != 't')
2082 my_friendly_abort (60);
2083 if (IS_AGGR_TYPE (type
))
2084 CLASSTYPE_GOT_SEMICOLON (type
) = 1;
2088 note_list_got_semicolon (declspecs
)
2093 for (link
= declspecs
; link
; link
= TREE_CHAIN (link
))
2095 tree type
= TREE_VALUE (link
);
2096 if (TREE_CODE_CLASS (TREE_CODE (type
)) == 't')
2097 note_got_semicolon (type
);
2102 /* If C is not whitespace, return C.
2103 Otherwise skip whitespace and return first nonwhite char read. */
2106 skip_white_space (c
)
2114 c
= check_newline ();
2125 while (c
== ' ' || c
== '\t');
2133 error ("stray '\\' in program");
2145 /* Make the token buffer longer, preserving the data in it.
2146 P should point to just beyond the last valid character in the old buffer.
2147 The value we return is a pointer to the new buffer
2148 at a place corresponding to P. */
2151 extend_token_buffer (p
)
2154 int offset
= p
- token_buffer
;
2156 maxtoken
= maxtoken
* 2 + 10;
2157 token_buffer
= (char *) xrealloc (token_buffer
, maxtoken
+ 2);
2159 return token_buffer
+ offset
;
2163 get_last_nonwhite_on_line ()
2167 /* Is this the last nonwhite stuff on the line? */
2169 c
= nextchar
, nextchar
= -1;
2173 while (c
== ' ' || c
== '\t')
2178 /* At the beginning of a line, increment the line number
2179 and process any #-directive on this line.
2180 If the line is a #-directive, read the entire line and return a newline.
2181 Otherwise, return the line's first non-whitespace character. */
2185 #ifdef HANDLE_SYSV_PRAGMA
2186 static int handle_sysv_pragma
PROTO((FILE *, int));
2188 static int handle_cp_pragma
PROTO((char *));
2196 /* Read first nonwhite char on the line. Do this before incrementing the
2197 line number, in case we're at the end of saved text. */
2201 while (c
== ' ' || c
== '\t');
2207 /* If not #, return it so caller will use it. */
2211 /* Don't read beyond this line. */
2214 /* Read first nonwhite char after the `#'. */
2218 while (c
== ' ' || c
== '\t');
2220 /* If a letter follows, then if the word here is `line', skip
2221 it and ignore it; otherwise, ignore the line, with an error
2222 if the word isn't `pragma'. */
2224 if ((c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'))
2234 token
= real_yylex ();
2235 if (token
== IDENTIFIER
2236 && TREE_CODE (yylval
.ttype
) == IDENTIFIER_NODE
)
2238 /* If this is 1, we handled it; if it's -1, it was one we
2239 wanted but had something wrong with it. Only if it's
2240 0 was it not handled. */
2241 if (handle_cp_pragma (IDENTIFIER_POINTER (yylval
.ttype
)))
2244 else if (token
== END_OF_LINE
)
2247 #ifdef HANDLE_SYSV_PRAGMA
2248 if (handle_sysv_pragma (finput
, token
))
2251 #ifdef HANDLE_PRAGMA
2252 if (HANDLE_PRAGMA (finput
, yylval
.ttype
))
2266 && ((c
= getch ()) == ' ' || c
== '\t'))
2268 debug_define (lineno
, get_directive_line (finput
));
2278 && ((c
= getch ()) == ' ' || c
== '\t'))
2280 debug_undef (lineno
, get_directive_line (finput
));
2289 && ((c
= getch ()) == ' ' || c
== '\t'))
2298 && ((c
= getch ()) == ' ' || c
== '\t'))
2300 #ifdef ASM_OUTPUT_IDENT
2301 extern FILE *asm_out_file
;
2303 /* #ident. The pedantic warning is now in cccp.c. */
2305 /* Here we have just seen `#ident '.
2306 A string constant should follow. */
2308 token
= real_yylex ();
2309 if (token
== END_OF_LINE
)
2312 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
2314 error ("invalid #ident");
2318 if (! flag_no_ident
)
2320 #ifdef ASM_OUTPUT_IDENT
2321 ASM_OUTPUT_IDENT (asm_out_file
,
2322 TREE_STRING_POINTER (yylval
.ttype
));
2326 /* Skip the rest of this line. */
2339 && ((c
= getch ()) == ' ' || c
== '\t'))
2341 /* Used to test incremental compilation. */
2342 sorry ("#pragma newworld");
2346 error ("undefined or invalid # directive");
2351 /* Here we have either `#line' or `# <nonletter>'.
2352 In either case, it should be a line number; a digit should follow. */
2354 while (c
== ' ' || c
== '\t')
2357 /* If the # is the only nonwhite char on the line,
2358 just ignore it. Check the new newline. */
2362 /* Something follows the #; read a token. */
2365 token
= real_yylex ();
2367 if (token
== CONSTANT
2368 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
2370 int old_lineno
= lineno
;
2371 enum { act_none
, act_push
, act_pop
} action
= act_none
;
2372 int entering_system_header
= 0;
2373 int entering_c_header
= 0;
2375 /* subtract one, because it is the following line that
2376 gets the specified number */
2378 int l
= TREE_INT_CST_LOW (yylval
.ttype
) - 1;
2379 c
= get_last_nonwhite_on_line ();
2382 /* No more: store the line number and check following line. */
2388 /* More follows: it must be a string constant (filename). */
2390 /* Read the string constant, but don't treat \ as special. */
2391 ignore_escape_flag
= 1;
2392 token
= real_yylex ();
2393 ignore_escape_flag
= 0;
2395 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
2397 error ("invalid #line");
2401 /* Changing files again. This means currently collected time
2402 is charged against header time, and body time starts back
2404 if (flag_detailed_statistics
)
2406 int this_time
= my_get_run_time ();
2407 tree time_identifier
= get_time_identifier (TREE_STRING_POINTER (yylval
.ttype
));
2408 header_time
+= this_time
- body_time
;
2409 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time
))
2410 += this_time
- body_time
;
2411 this_filename_time
= time_identifier
;
2412 body_time
= this_time
;
2416 = (char *) permalloc (TREE_STRING_LENGTH (yylval
.ttype
) + 1);
2417 strcpy (input_filename
, TREE_STRING_POINTER (yylval
.ttype
));
2419 GNU_xref_file (input_filename
);
2421 if (main_input_filename
== 0)
2423 struct impl_files
*ifiles
= impl_file_chain
;
2427 while (ifiles
->next
)
2428 ifiles
= ifiles
->next
;
2429 ifiles
->filename
= FILE_NAME_NONDIRECTORY (input_filename
);
2432 main_input_filename
= input_filename
;
2433 if (write_virtuals
== 3)
2434 walk_vtables (set_typedecl_interface_info
, set_vardecl_interface_info
);
2437 extract_interface_info ();
2439 c
= get_last_nonwhite_on_line ();
2442 /* Update the name in the top element of input_file_stack. */
2443 if (input_file_stack
)
2444 input_file_stack
->name
= input_filename
;
2450 token
= real_yylex ();
2452 /* `1' after file name means entering new file.
2453 `2' after file name means just left a file. */
2455 if (token
== CONSTANT
2456 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
)
2458 if (TREE_INT_CST_LOW (yylval
.ttype
) == 1)
2460 else if (TREE_INT_CST_LOW (yylval
.ttype
) == 2)
2465 c
= get_last_nonwhite_on_line ();
2469 token
= real_yylex ();
2474 /* `3' after file name means this is a system header file. */
2476 if (token
== CONSTANT
2477 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
2478 && TREE_INT_CST_LOW (yylval
.ttype
) == 3)
2480 entering_system_header
= 1;
2482 c
= get_last_nonwhite_on_line ();
2486 token
= real_yylex ();
2490 /* `4' after file name means this is a C header file. */
2492 if (token
== CONSTANT
2493 && TREE_CODE (yylval
.ttype
) == INTEGER_CST
2494 && TREE_INT_CST_LOW (yylval
.ttype
) == 4)
2496 entering_c_header
= 1;
2498 c
= get_last_nonwhite_on_line ();
2502 token
= real_yylex ();
2506 /* Do the actions implied by the preceding numbers. */
2508 if (action
== act_push
)
2510 /* Pushing to a new file. */
2511 struct file_stack
*p
;
2513 p
= (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
2514 input_file_stack
->line
= old_lineno
;
2515 p
->next
= input_file_stack
;
2516 p
->name
= input_filename
;
2517 input_file_stack
= p
;
2518 input_file_stack_tick
++;
2519 debug_start_source_file (input_filename
);
2520 in_system_header
= entering_system_header
;
2523 else if (entering_c_header
)
2526 ++pending_lang_change
;
2529 else if (action
== act_pop
)
2531 /* Popping out of a file. */
2532 if (input_file_stack
->next
)
2534 struct file_stack
*p
;
2536 if (c_header_level
&& --c_header_level
== 0)
2538 if (entering_c_header
)
2539 warning ("badly nested C headers from preprocessor");
2540 --pending_lang_change
;
2542 in_system_header
= entering_system_header
;
2544 p
= input_file_stack
;
2545 input_file_stack
= p
->next
;
2547 input_file_stack_tick
++;
2548 debug_end_source_file (input_file_stack
->line
);
2551 error ("#-lines for entering and leaving files don't match");
2554 in_system_header
= entering_system_header
;
2557 /* If NEXTCHAR is not end of line, we don't care what it is. */
2558 if (nextchar
== EOF
)
2562 error ("invalid #-line");
2564 /* skip the rest of this line. */
2569 while ((c
= getch ()) != EOF
&& c
!= '\n');
2574 do_pending_lang_change ()
2576 for (; pending_lang_change
> 0; --pending_lang_change
)
2577 push_lang_context (lang_name_c
);
2578 for (; pending_lang_change
< 0; ++pending_lang_change
)
2579 pop_lang_context ();
2583 #define isalnum(char) (char >= 'a' ? char <= 'z' : char >= '0' ? char <= '9' || (char >= 'A' && char <= 'Z') : 0)
2584 #define isdigit(char) (char >= '0' && char <= '9')
2589 #define ENDFILE -1 /* token that represents end-of-file */
2591 /* Read an escape sequence, returning its equivalent as a character,
2592 or store 1 in *ignore_ptr if it is backslash-newline. */
2595 readescape (ignore_ptr
)
2598 register int c
= getch ();
2600 register unsigned count
;
2619 if (c
>= 'a' && c
<= 'f')
2620 code
+= c
- 'a' + 10;
2621 if (c
>= 'A' && c
<= 'F')
2622 code
+= c
- 'A' + 10;
2623 if (c
>= '0' && c
<= '9')
2625 if (code
!= 0 || count
!= 0)
2634 error ("\\x used with no following hex digits");
2635 else if (count
== 0)
2636 /* Digits are all 0's. Ok. */
2638 else if ((count
- 1) * 4 >= TYPE_PRECISION (integer_type_node
)
2640 && ((1 << (TYPE_PRECISION (integer_type_node
) - (count
- 1) * 4))
2642 pedwarn ("hex escape out of range");
2645 case '0': case '1': case '2': case '3': case '4':
2646 case '5': case '6': case '7':
2649 while ((c
<= '7') && (c
>= '0') && (count
++ < 3))
2651 code
= (code
* 8) + (c
- '0');
2657 case '\\': case '\'': case '"':
2666 return TARGET_NEWLINE
;
2689 pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c
);
2695 /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
2699 /* `\%' is used to prevent SCCS from getting confused. */
2702 pedwarn ("unknown escape sequence `\\%c'", c
);
2705 if (c
>= 040 && c
< 0177)
2706 pedwarn ("unknown escape sequence `\\%c'", c
);
2708 pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c
);
2712 /* Value is 1 (or 2) if we should try to make the next identifier look like
2713 a typename (when it may be a local variable or a class variable).
2714 Value is 0 if we treat this name in a default fashion. */
2715 int looking_for_typename
= 0;
2721 identifier_type (decl
)
2724 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2726 if (TREE_CODE (DECL_RESULT (decl
)) == TYPE_DECL
)
2729 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
2731 if (TREE_CODE (decl
) != TYPE_DECL
)
2733 if (((got_scope
&& TREE_TYPE (decl
) == got_scope
)
2734 || TREE_TYPE (decl
) == current_class_type
)
2735 && DECL_ARTIFICIAL (decl
))
2743 looking_for_typename
= 1;
2745 if ((yychar
= yylex ()) < 0) yychar
= 0;
2746 looking_for_typename
= 0;
2747 if (yychar
== IDENTIFIER
)
2749 lastiddecl
= lookup_name (yylval
.ttype
, -2);
2750 if (lastiddecl
== 0)
2753 lastiddecl
= IDENTIFIER_LABEL_VALUE (yylval
.ttype
);
2756 yychar
= identifier_type (lastiddecl
);
2761 do_identifier (token
, parsing
)
2762 register tree token
;
2767 if (! parsing
|| IDENTIFIER_OPNAME_P (token
))
2768 id
= lookup_name (token
, 0);
2772 if (parsing
&& yychar
== YYEMPTY
)
2774 /* Scope class declarations before global
2776 if (id
== IDENTIFIER_GLOBAL_VALUE (token
)
2777 && current_class_type
!= 0
2778 && TYPE_SIZE (current_class_type
) == 0)
2780 /* Could be from one of the base classes. */
2781 tree field
= lookup_field (current_class_type
, token
, 1, 0);
2784 else if (field
== error_mark_node
)
2785 /* We have already generated the error message.
2786 But we still want to return this value. */
2787 id
= lookup_field (current_class_type
, token
, 0, 0);
2788 else if (TREE_CODE (field
) == VAR_DECL
2789 || TREE_CODE (field
) == CONST_DECL
)
2791 else if (TREE_CODE (field
) != FIELD_DECL
)
2792 my_friendly_abort (61);
2795 cp_error ("invalid use of member `%D' from base class `%T'", field
,
2796 DECL_FIELD_CONTEXT (field
));
2797 id
= error_mark_node
;
2802 /* Remember that this name has been used in the class definition, as per
2804 if (id
&& current_class_type
&& parsing
2805 && TYPE_BEING_DEFINED (current_class_type
)
2806 && ! IDENTIFIER_CLASS_VALUE (token
)
2807 /* Avoid breaking if we get called for a default argument that
2808 refers to an overloaded method. Eventually this will not be
2809 necessary, since default arguments shouldn't be parsed until
2810 after the class is complete. (jason 3/12/97) */
2811 && TREE_CODE (id
) != TREE_LIST
)
2812 pushdecl_class_level (id
);
2814 if (!id
|| id
== error_mark_node
)
2816 if (id
== error_mark_node
&& current_class_type
!= NULL_TREE
)
2818 id
= lookup_nested_field (token
, 1);
2819 /* In lookup_nested_field(), we marked this so we can gracefully
2820 leave this whole mess. */
2821 if (id
&& id
!= error_mark_node
&& TREE_TYPE (id
) == error_mark_node
)
2825 if (current_template_parms
)
2826 return build_min_nt (LOOKUP_EXPR
, token
, NULL_TREE
);
2827 else if (IDENTIFIER_OPNAME_P (token
))
2829 if (token
!= ansi_opname
[ERROR_MARK
])
2830 cp_error ("`%D' not defined", token
);
2831 id
= error_mark_node
;
2833 else if (parsing
&& (yychar
== '(' || yychar
== LEFT_RIGHT
))
2835 id
= implicitly_declare (token
);
2837 else if (current_function_decl
== 0)
2839 cp_error ("`%D' was not declared in this scope", token
);
2840 id
= error_mark_node
;
2844 if (IDENTIFIER_GLOBAL_VALUE (token
) != error_mark_node
2845 || IDENTIFIER_ERROR_LOCUS (token
) != current_function_decl
)
2847 static int undeclared_variable_notice
;
2849 cp_error ("`%D' undeclared (first use this function)", token
);
2851 if (! undeclared_variable_notice
)
2853 error ("(Each undeclared identifier is reported only once");
2854 error ("for each function it appears in.)");
2855 undeclared_variable_notice
= 1;
2858 id
= error_mark_node
;
2859 /* Prevent repeated error messages. */
2860 IDENTIFIER_GLOBAL_VALUE (token
) = error_mark_node
;
2861 SET_IDENTIFIER_ERROR_LOCUS (token
, current_function_decl
);
2865 if (TREE_CODE (id
) == VAR_DECL
&& DECL_DEAD_FOR_LOCAL (id
))
2867 tree shadowed
= DECL_SHADOWED_FOR_VAR (id
);
2868 while (shadowed
!= NULL_TREE
&& TREE_CODE (shadowed
) == VAR_DECL
2869 && DECL_DEAD_FOR_LOCAL (shadowed
))
2870 shadowed
= DECL_SHADOWED_FOR_VAR (shadowed
);
2872 shadowed
= IDENTIFIER_GLOBAL_VALUE (DECL_NAME (id
));
2875 if (!DECL_ERROR_REPORTED (id
))
2877 warning ("name lookup of `%s' changed",
2878 IDENTIFIER_POINTER (token
));
2879 cp_warning_at (" matches this `%D' under current ANSI rules",
2881 cp_warning_at (" matches this `%D' under old rules", id
);
2882 DECL_ERROR_REPORTED (id
) = 1;
2886 else if (!DECL_ERROR_REPORTED (id
))
2889 = "name lookup of `%s' changed for new ANSI `for' scoping";
2890 DECL_ERROR_REPORTED (id
) = 1;
2891 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id
)))
2893 error (msg
, IDENTIFIER_POINTER (token
));
2894 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id
);
2895 id
= error_mark_node
;
2899 pedwarn (msg
, IDENTIFIER_POINTER (token
));
2900 cp_pedwarn_at (" using obsolete binding at `%D'", id
);
2904 /* TREE_USED is set in `hack_identifier'. */
2905 if (TREE_CODE (id
) == CONST_DECL
)
2907 if (IDENTIFIER_CLASS_VALUE (token
) == id
)
2910 tree access
= compute_access (TYPE_BINFO (current_class_type
), id
);
2911 if (access
== access_private_node
)
2912 cp_error ("enum `%D' is private", id
);
2913 /* protected is OK, since it's an enum of `this'. */
2915 if (! processing_template_decl
2916 || (DECL_INITIAL (id
)
2917 && TREE_CODE (DECL_INITIAL (id
)) == TEMPLATE_CONST_PARM
))
2918 id
= DECL_INITIAL (id
);
2921 id
= hack_identifier (id
, token
);
2923 if (current_template_parms
)
2925 if (is_overloaded_fn (id
))
2927 tree t
= build_min (LOOKUP_EXPR
, unknown_type_node
,
2928 token
, get_first_fn (id
));
2929 if (id
!= IDENTIFIER_GLOBAL_VALUE (token
))
2930 TREE_OPERAND (t
, 1) = error_mark_node
;
2933 else if (! TREE_PERMANENT (id
) || TREE_CODE (id
) == PARM_DECL
2934 || TREE_CODE (id
) == USING_DECL
)
2935 id
= build_min (LOOKUP_EXPR
, TREE_TYPE (id
), token
, error_mark_node
);
2936 /* else just use the decl */
2943 do_scoped_id (token
, parsing
)
2947 tree id
= IDENTIFIER_GLOBAL_VALUE (token
);
2948 if (parsing
&& yychar
== YYEMPTY
)
2952 if (processing_template_decl
)
2954 id
= build_min_nt (LOOKUP_EXPR
, token
, NULL_TREE
);
2955 LOOKUP_EXPR_GLOBAL (id
) = 1;
2958 if (parsing
&& yychar
== '(' || yychar
== LEFT_RIGHT
)
2959 id
= implicitly_declare (token
);
2962 if (IDENTIFIER_GLOBAL_VALUE (token
) != error_mark_node
)
2963 error ("undeclared variable `%s' (first use here)",
2964 IDENTIFIER_POINTER (token
));
2965 id
= error_mark_node
;
2966 /* Prevent repeated error messages. */
2967 IDENTIFIER_GLOBAL_VALUE (token
) = error_mark_node
;
2972 if (TREE_CODE (id
) == ADDR_EXPR
)
2973 mark_used (TREE_OPERAND (id
, 0));
2974 else if (TREE_CODE (id
) != TREE_LIST
)
2977 if (TREE_CODE (id
) == CONST_DECL
&& ! processing_template_decl
)
2979 /* XXX CHS - should we set TREE_USED of the constant? */
2980 id
= DECL_INITIAL (id
);
2981 /* This is to prevent an enum whose value is 0
2982 from being considered a null pointer constant. */
2983 id
= build1 (NOP_EXPR
, TREE_TYPE (id
), id
);
2984 TREE_CONSTANT (id
) = 1;
2987 if (processing_template_decl
)
2989 if (is_overloaded_fn (id
))
2991 id
= build_min (LOOKUP_EXPR
, unknown_type_node
,
2992 token
, get_first_fn (id
));
2993 LOOKUP_EXPR_GLOBAL (id
) = 1;
2995 /* else just use the decl */
2997 return convert_from_reference (id
);
3001 identifier_typedecl_value (node
)
3005 type
= IDENTIFIER_TYPE_VALUE (node
);
3006 if (type
== NULL_TREE
)
3011 if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) \
3014 do (IDENTIFIER_LOCAL_VALUE (node
));
3015 do (IDENTIFIER_CLASS_VALUE (node
));
3016 do (IDENTIFIER_GLOBAL_VALUE (node
));
3018 /* Will this one ever happen? */
3019 if (TYPE_MAIN_DECL (type
))
3020 return TYPE_MAIN_DECL (type
);
3022 /* We used to do an internal error of 62 here, but instead we will
3023 handle the return of a null appropriately in the callers. */
3033 int dollar_seen
= 0;
3037 c
= nextchar
, nextchar
= -1;
3041 /* Effectively do c = skip_white_space (c)
3042 but do it faster in the usual cases. */
3055 /* Call skip_white_space so we can warn if appropriate. */
3060 c
= skip_white_space (c
);
3062 goto found_nonwhite
;
3066 token_buffer
[0] = c
;
3067 token_buffer
[1] = 0;
3069 /* yylloc.first_line = lineno; */
3074 token_buffer
[0] = '\0';
3076 if (input_redirected ())
3077 value
= END_OF_SAVED_INPUT
;
3079 value
= END_OF_LINE
;
3085 if (dollars_in_ident
)
3094 /* Capital L may start a wide-string or wide-character constant. */
3096 register int c
= getch ();
3105 goto string_constant
;
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 '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':
3116 case 'a': case 'b': case 'c': case 'd': case 'e':
3117 case 'f': case 'g': case 'h': case 'i': case 'j':
3118 case 'k': case 'l': case 'm': case 'n': case 'o':
3119 case 'p': case 'q': case 'r': case 's': case 't':
3120 case 'u': case 'v': case 'w': case 'x': case 'y':
3130 /* We know that `token_buffer' can hold at least on char,
3131 so we install C immediately.
3132 We may have to read the value in `putback_char', so call
3137 /* Make this run fast. We know that we are reading straight
3138 from FINPUT in this case (since identifiers cannot straddle
3140 while (isalnum (c
) || (c
== '_') || c
== '$')
3142 if (c
== '$' && ! dollars_in_ident
)
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
== '$')
3166 if (c
== '$' && ! dollars_in_ident
)
3168 if (p
>= token_buffer
+ maxtoken
)
3169 p
= extend_token_buffer (p
);
3182 /* Try to recognize a keyword. Uses minimum-perfect hash function */
3185 register struct resword
*ptr
;
3187 if (ptr
= is_reserved_word (token_buffer
, p
- token_buffer
))
3191 tree old_ttype
= ridpointers
[(int) ptr
->rid
];
3193 /* If this provides a type for us, then revert lexical
3194 state to standard state. */
3195 if (TREE_CODE (old_ttype
) == IDENTIFIER_NODE
3196 && IDENTIFIER_GLOBAL_VALUE (old_ttype
) != 0
3197 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (old_ttype
)) == TYPE_DECL
)
3198 looking_for_typename
= 0;
3199 else if (ptr
->token
== AGGR
|| ptr
->token
== ENUM
)
3200 looking_for_typename
= 1;
3202 /* Check if this is a language-type declaration.
3203 Just glimpse the next non-white character. */
3204 nextchar
= skip_white_space (nextchar
);
3205 if (nextchar
== '"')
3207 /* We are looking at a string. Complain
3208 if the token before the string is no `extern'.
3210 Could cheat some memory by placing this string
3211 on the temporary_, instead of the saveable_
3214 if (ptr
->rid
!= RID_EXTERN
)
3215 error ("invalid modifier `%s' for language string",
3218 value
= EXTERN_LANG_STRING
;
3219 yylval
.ttype
= get_identifier (TREE_STRING_POINTER (yylval
.ttype
));
3222 if (ptr
->token
== VISSPEC
)
3227 yylval
.ttype
= access_public_node
;
3230 yylval
.ttype
= access_private_node
;
3233 yylval
.ttype
= access_protected_node
;
3236 my_friendly_abort (63);
3240 yylval
.ttype
= old_ttype
;
3242 else if (ptr
->token
== EQCOMPARE
)
3244 yylval
.code
= NE_EXPR
;
3245 token_buffer
[0] = '!';
3246 token_buffer
[1] = '=';
3247 token_buffer
[2] = 0;
3249 else if (ptr
->token
== ASSIGN
)
3251 if (strcmp ("and_eq", token_buffer
) == 0)
3253 yylval
.code
= BIT_AND_EXPR
;
3254 token_buffer
[0] = '&';
3256 else if (strcmp ("or_eq", token_buffer
) == 0)
3258 yylval
.code
= BIT_IOR_EXPR
;
3259 token_buffer
[0] = '|';
3261 else if (strcmp ("xor_eq", token_buffer
) == 0)
3263 yylval
.code
= BIT_XOR_EXPR
;
3264 token_buffer
[0] = '^';
3266 token_buffer
[1] = '=';
3267 token_buffer
[2] = 0;
3269 else if (ptr
->token
== '&')
3271 yylval
.code
= BIT_AND_EXPR
;
3272 token_buffer
[0] = '&';
3273 token_buffer
[1] = 0;
3275 else if (ptr
->token
== '|')
3277 yylval
.code
= BIT_IOR_EXPR
;
3278 token_buffer
[0] = '|';
3279 token_buffer
[1] = 0;
3281 else if (ptr
->token
== '^')
3283 yylval
.code
= BIT_XOR_EXPR
;
3284 token_buffer
[0] = '^';
3285 token_buffer
[1] = 0;
3288 value
= (int) ptr
->token
;
3292 /* If we did not find a keyword, look for an identifier
3295 if (value
== IDENTIFIER
|| value
== TYPESPEC
)
3296 GNU_xref_ref (current_function_decl
, token_buffer
);
3298 if (value
== IDENTIFIER
)
3300 register tree tmp
= get_identifier (token_buffer
);
3302 #if !defined(VMS) && defined(JOINER)
3303 /* Make sure that user does not collide with our internal
3307 && (THIS_NAME_P (tmp
)
3308 || VPTR_NAME_P (tmp
)
3309 || DESTRUCTOR_NAME_P (tmp
)
3310 || VTABLE_NAME_P (tmp
)
3311 || TEMP_NAME_P (tmp
)
3312 || ANON_AGGRNAME_P (tmp
)
3313 || ANON_PARMNAME_P (tmp
)))
3314 warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3320 if (value
== NEW
&& ! global_bindings_p ())
3330 register int c1
= getch ();
3331 token_buffer
[0] = c
;
3332 token_buffer
[1] = c1
;
3336 token_buffer
[2] = 0;
3344 token_buffer
[2] = c1
;
3345 token_buffer
[3] = 0;
3349 error ("parse error at `..'");
3354 goto resume_numerical_scan
;
3358 token_buffer
[1] = 0;
3362 /* Optimize for most frequent case. */
3364 register int c1
= getch ();
3365 if (! isalnum (c1
) && c1
!= '.')
3367 /* Terminate string. */
3368 token_buffer
[0] = c
;
3369 token_buffer
[1] = 0;
3371 yylval
.ttype
= integer_zero_node
;
3373 yylval
.ttype
= integer_one_node
;
3380 /* fall through... */
3381 case '2': case '3': case '4':
3382 case '5': case '6': case '7': case '8': case '9':
3383 resume_numerical_scan
:
3388 int largest_digit
= 0;
3390 /* for multi-precision arithmetic,
3391 we actually store only HOST_BITS_PER_CHAR bits in each part.
3392 The number of parts is chosen so as to be sufficient to hold
3393 the enough bits to fit into the two HOST_WIDE_INTs that contain
3394 the integer value (this is always at least as many bits as are
3395 in a target `long long' value, but may be wider). */
3396 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
3397 int parts
[TOTAL_PARTS
];
3400 enum anon1
{ NOT_FLOAT
, AFTER_POINT
, TOO_MANY_POINTS
} floatflag
3403 for (count
= 0; count
< TOTAL_PARTS
; count
++)
3411 *p
++ = (c
= getch ());
3412 if ((c
== 'x') || (c
== 'X'))
3415 *p
++ = (c
= getch ());
3417 /* Leading 0 forces octal unless the 0 is the only digit. */
3418 else if (c
>= '0' && c
<= '9')
3427 /* Read all the digits-and-decimal-points. */
3430 || (isalnum (c
) && (c
!= 'l') && (c
!= 'L')
3431 && (c
!= 'u') && (c
!= 'U')
3432 && c
!= 'i' && c
!= 'I' && c
!= 'j' && c
!= 'J'
3433 && (floatflag
== NOT_FLOAT
|| ((c
!= 'f') && (c
!= 'F')))))
3438 error ("floating constant may not be in radix 16");
3439 if (floatflag
== TOO_MANY_POINTS
)
3440 /* We have already emitted an error. Don't need another. */
3442 else if (floatflag
== AFTER_POINT
)
3444 error ("malformed floating constant");
3445 floatflag
= TOO_MANY_POINTS
;
3446 /* Avoid another error from atof by forcing all characters
3447 from here on to be ignored. */
3451 floatflag
= AFTER_POINT
;
3454 *p
++ = c
= getch ();
3455 /* Accept '.' as the start of a floating-point number
3456 only when it is followed by a digit.
3457 Otherwise, unread the following non-digit
3458 and use the '.' as a structural token. */
3459 if (p
== token_buffer
+ 2 && !isdigit (c
))
3471 error ("parse error at `..'");
3474 token_buffer
[1] = '\0';
3481 /* It is not a decimal point.
3482 It should be a digit (perhaps a hex digit). */
3488 else if (base
<= 10)
3490 if (c
== 'e' || c
== 'E')
3493 floatflag
= AFTER_POINT
;
3494 break; /* start of exponent */
3496 error ("nondigits in number and not hexadecimal");
3507 if (c
>= largest_digit
)
3511 for (count
= 0; count
< TOTAL_PARTS
; count
++)
3513 parts
[count
] *= base
;
3517 += (parts
[count
-1] >> HOST_BITS_PER_CHAR
);
3519 &= (1 << HOST_BITS_PER_CHAR
) - 1;
3525 /* If the extra highest-order part ever gets anything in it,
3526 the number is certainly too big. */
3527 if (parts
[TOTAL_PARTS
- 1] != 0)
3530 if (p
>= token_buffer
+ maxtoken
- 3)
3531 p
= extend_token_buffer (p
);
3532 *p
++ = (c
= getch ());
3537 error ("numeric constant with no digits");
3539 if (largest_digit
>= base
)
3540 error ("numeric constant contains digits beyond the radix");
3542 /* Remove terminating char from the token buffer and delimit the string */
3545 if (floatflag
!= NOT_FLOAT
)
3547 tree type
= double_type_node
;
3548 int exceeds_double
= 0;
3550 REAL_VALUE_TYPE value
;
3553 /* Read explicit exponent if any, and put it in tokenbuf. */
3555 if ((c
== 'e') || (c
== 'E'))
3557 if (p
>= token_buffer
+ maxtoken
- 3)
3558 p
= extend_token_buffer (p
);
3561 if ((c
== '+') || (c
== '-'))
3567 error ("floating constant exponent has no digits");
3570 if (p
>= token_buffer
+ maxtoken
- 3)
3571 p
= extend_token_buffer (p
);
3580 /* Convert string to a double, checking for overflow. */
3581 if (setjmp (handler
))
3583 error ("floating constant out of range");
3588 int fflag
= 0, lflag
= 0;
3589 /* Copy token_buffer now, while it has just the number
3590 and not the suffixes; once we add `f' or `i',
3591 REAL_VALUE_ATOF may not work any more. */
3592 char *copy
= (char *) alloca (p
- token_buffer
+ 1);
3593 bcopy (token_buffer
, copy
, p
- token_buffer
+ 1);
3595 set_float_handler (handler
);
3601 /* Read the suffixes to choose a data type. */
3606 error ("more than one `f' in numeric constant");
3612 error ("more than one `l' in numeric constant");
3618 error ("more than one `i' or `j' in numeric constant");
3620 pedwarn ("ANSI C++ forbids imaginary numeric constants");
3631 if (p
>= token_buffer
+ maxtoken
- 3)
3632 p
= extend_token_buffer (p
);
3638 /* The second argument, machine_mode, of REAL_VALUE_ATOF
3639 tells the desired precision of the binary result
3640 of decimal-to-binary conversion. */
3645 error ("both `f' and `l' in floating constant");
3647 type
= float_type_node
;
3648 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
3649 /* A diagnostic is required here by some ANSI C testsuites.
3650 This is not pedwarn, become some people don't want
3651 an error for this. */
3652 if (REAL_VALUE_ISINF (value
) && pedantic
)
3653 warning ("floating point number exceeds range of `float'");
3657 type
= long_double_type_node
;
3658 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
3659 if (REAL_VALUE_ISINF (value
) && pedantic
)
3660 warning ("floating point number exceeds range of `long double'");
3664 value
= REAL_VALUE_ATOF (copy
, TYPE_MODE (type
));
3665 if (REAL_VALUE_ISINF (value
) && pedantic
)
3666 warning ("floating point number exceeds range of `double'");
3669 set_float_handler (NULL_PTR
);
3672 if (errno
== ERANGE
&& pedantic
)
3674 /* ERANGE is also reported for underflow,
3675 so test the value to distinguish overflow from that. */
3676 if (REAL_VALUES_LESS (dconst1
, value
)
3677 || REAL_VALUES_LESS (value
, dconstm1
))
3679 pedwarn ("floating point number exceeds range of `%s'",
3680 IDENTIFIER_POINTER (TYPE_IDENTIFIER (type
)));
3686 /* If the result is not a number, assume it must have been
3687 due to some error message above, so silently convert
3689 if (REAL_VALUE_ISNAN (value
))
3692 /* Create a node with determined type and value. */
3694 yylval
.ttype
= build_complex (NULL_TREE
,
3695 cp_convert (type
, integer_zero_node
),
3696 build_real (type
, value
));
3698 yylval
.ttype
= build_real (type
, value
);
3703 HOST_WIDE_INT high
, low
;
3704 int spec_unsigned
= 0;
3706 int spec_long_long
= 0;
3712 if (c
== 'u' || c
== 'U')
3715 error ("two `u's in integer constant");
3718 else if (c
== 'l' || c
== 'L')
3723 error ("three `l's in integer constant");
3725 pedwarn ("ANSI C++ forbids long long integer constants");
3730 else if (c
== 'i' || c
== 'j' || c
== 'I' || c
== 'J')
3733 error ("more than one `i' or `j' in numeric constant");
3735 pedwarn ("ANSI C++ forbids imaginary numeric constants");
3740 if (p
>= token_buffer
+ maxtoken
- 3)
3741 p
= extend_token_buffer (p
);
3746 /* If the constant is not long long and it won't fit in an
3747 unsigned long, or if the constant is long long and won't fit
3748 in an unsigned long long, then warn that the constant is out
3751 /* ??? This assumes that long long and long integer types are
3752 a multiple of 8 bits. This better than the original code
3753 though which assumed that long was exactly 32 bits and long
3754 long was exactly 64 bits. */
3757 bytes
= TYPE_PRECISION (long_long_integer_type_node
) / 8;
3759 bytes
= TYPE_PRECISION (long_integer_type_node
) / 8;
3762 for (i
= bytes
; i
< TOTAL_PARTS
; i
++)
3766 pedwarn ("integer constant out of range");
3768 /* This is simplified by the fact that our constant
3769 is always positive. */
3772 for (i
= 0; i
< HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
; i
++)
3774 high
|= ((HOST_WIDE_INT
) parts
[i
+ (HOST_BITS_PER_WIDE_INT
3775 / HOST_BITS_PER_CHAR
)]
3776 << (i
* HOST_BITS_PER_CHAR
));
3777 low
|= (HOST_WIDE_INT
) parts
[i
] << (i
* HOST_BITS_PER_CHAR
);
3781 yylval
.ttype
= build_int_2 (low
, high
);
3782 TREE_TYPE (yylval
.ttype
) = long_long_unsigned_type_node
;
3784 if (!spec_long
&& !spec_unsigned
3785 && int_fits_type_p (yylval
.ttype
, integer_type_node
))
3787 type
= integer_type_node
;
3789 else if (!spec_long
&& (base
!= 10 || spec_unsigned
)
3790 && int_fits_type_p (yylval
.ttype
, unsigned_type_node
))
3792 /* Nondecimal constants try unsigned even in traditional C. */
3793 type
= unsigned_type_node
;
3795 else if (!spec_unsigned
&& !spec_long_long
3796 && int_fits_type_p (yylval
.ttype
, long_integer_type_node
))
3797 type
= long_integer_type_node
;
3798 else if (! spec_long_long
)
3799 type
= long_unsigned_type_node
;
3800 else if (! spec_unsigned
3801 /* Verify value does not overflow into sign bit. */
3802 && TREE_INT_CST_HIGH (yylval
.ttype
) >= 0
3803 && int_fits_type_p (yylval
.ttype
,
3804 long_long_integer_type_node
))
3805 type
= long_long_integer_type_node
;
3806 else if (int_fits_type_p (yylval
.ttype
,
3807 long_long_unsigned_type_node
))
3808 type
= long_long_unsigned_type_node
;
3812 type
= long_long_integer_type_node
;
3813 warning ("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");
3819 if (TYPE_PRECISION (type
)
3820 <= TYPE_PRECISION (integer_type_node
))
3822 = build_complex (NULL_TREE
, integer_zero_node
,
3823 cp_convert (integer_type_node
,
3826 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
);
4035 union { long l
; char c
[sizeof (long)]; } u
;
4039 /* Determine whether host is little or big endian. */
4041 big_endian
= u
.c
[sizeof (long) - 1];
4042 wp
= widep
+ (big_endian
? WCHAR_BYTES
- 1 : 0);
4044 bzero (widep
, (p
- token_buffer
) * WCHAR_BYTES
);
4045 for (cp
= token_buffer
+ 1; cp
< p
; cp
++)
4046 *wp
= *cp
, wp
+= WCHAR_BYTES
;
4047 len
= p
- token_buffer
- 1;
4050 if (processing_template_decl
)
4051 push_obstacks (&permanent_obstack
, &permanent_obstack
);
4052 yylval
.ttype
= build_string ((len
+ 1) * WCHAR_BYTES
, widep
);
4053 if (processing_template_decl
)
4055 TREE_TYPE (yylval
.ttype
) = wchar_array_type_node
;
4059 if (processing_template_decl
)
4060 push_obstacks (&permanent_obstack
, &permanent_obstack
);
4061 yylval
.ttype
= build_string (p
- token_buffer
, token_buffer
+ 1);
4062 if (processing_template_decl
)
4064 TREE_TYPE (yylval
.ttype
) = char_array_type_node
;
4070 value
= STRING
; break;
4093 yylval
.code
= PLUS_EXPR
; break;
4095 yylval
.code
= MINUS_EXPR
; break;
4097 yylval
.code
= BIT_AND_EXPR
; break;
4099 yylval
.code
= BIT_IOR_EXPR
; break;
4101 yylval
.code
= MULT_EXPR
; break;
4103 yylval
.code
= TRUNC_DIV_EXPR
; break;
4105 yylval
.code
= TRUNC_MOD_EXPR
; break;
4107 yylval
.code
= BIT_XOR_EXPR
; break;
4109 yylval
.code
= LSHIFT_EXPR
; break;
4111 yylval
.code
= RSHIFT_EXPR
; break;
4113 yylval
.code
= LT_EXPR
; break;
4115 yylval
.code
= GT_EXPR
; break;
4118 token_buffer
[1] = c1
= getch ();
4119 token_buffer
[2] = 0;
4126 value
= ARITHCOMPARE
; yylval
.code
= LE_EXPR
; goto done
;
4128 value
= ARITHCOMPARE
; yylval
.code
= GE_EXPR
; goto done
;
4130 value
= EQCOMPARE
; yylval
.code
= NE_EXPR
; goto done
;
4132 value
= EQCOMPARE
; yylval
.code
= EQ_EXPR
; goto done
;
4134 value
= ASSIGN
; goto done
;
4140 value
= PLUSPLUS
; goto done
;
4142 value
= MINUSMINUS
; goto done
;
4144 value
= ANDAND
; goto done
;
4146 value
= OROR
; goto done
;
4154 else if ((c
== '-') && (c1
== '>'))
4156 nextchar
= getch ();
4157 if (nextchar
== '*')
4160 value
= POINTSAT_STAR
;
4166 else if (c1
== '?' && (c
== '<' || c
== '>'))
4168 token_buffer
[3] = 0;
4171 yylval
.code
= (c
== '<' ? MIN_EXPR
: MAX_EXPR
);
4174 /* <?= or >?= expression. */
4175 token_buffer
[2] = c1
;
4184 pedwarn ("use of `operator %s' is not standard C++",
4189 else if (c
== '<' && c1
== '%')
4190 { value
= '{'; goto done
; }
4191 else if (c
== '<' && c1
== ':')
4192 { value
= '['; goto done
; }
4193 else if (c
== '%' && c1
== '>')
4194 { value
= '}'; goto done
; }
4195 else if (c
== '%' && c1
== ':')
4196 { value
= '#'; goto done
; }
4199 token_buffer
[1] = 0;
4209 token_buffer
[1] = ':';
4210 token_buffer
[2] = '\0';
4227 /* Don't make yyparse think this is eof. */
4232 /* try, weakly, to handle casts to pointers to functions. */
4233 nextchar
= skip_white_space (getch ());
4234 if (nextchar
== '*')
4236 int next_c
= skip_white_space (getch ());
4240 yylval
.ttype
= build1 (INDIRECT_REF
, 0, 0);
4241 value
= PAREN_STAR_PAREN
;
4249 else if (nextchar
== ')')
4252 yylval
.ttype
= NULL_TREE
;
4263 /* yylloc.last_line = lineno; */
4264 #ifdef GATHER_STATISTICS
4265 #ifdef REDUCE_LENGTH
4266 token_count
[value
] += 1;
4277 return !!is_reserved_word (IDENTIFIER_POINTER (t
), IDENTIFIER_LENGTH (t
));
4280 #ifdef GATHER_STATISTICS
4281 /* The original for tree_node_kind is in the toplevel tree.c; changes there
4282 need to be brought into here, unless this were actually put into a header
4284 /* Statistics-gathering stuff. */
4305 extern int tree_node_counts
[];
4306 extern int tree_node_sizes
[];
4309 /* Place to save freed lang_decls which were allocated on the
4310 permanent_obstack. @@ Not currently used. */
4311 tree free_lang_decl_chain
;
4314 build_lang_decl (code
, name
, type
)
4315 enum tree_code code
;
4319 register tree t
= build_decl (code
, name
, type
);
4320 struct obstack
*obstack
= current_obstack
;
4321 register int i
= sizeof (struct lang_decl
) / sizeof (int);
4324 if (! TREE_PERMANENT (t
))
4325 obstack
= saveable_obstack
;
4327 /* Could be that saveable is permanent and current is not. */
4328 obstack
= &permanent_obstack
;
4330 if (free_lang_decl_chain
&& obstack
== &permanent_obstack
)
4332 pi
= (int *)free_lang_decl_chain
;
4333 free_lang_decl_chain
= TREE_CHAIN (free_lang_decl_chain
);
4336 pi
= (int *) obstack_alloc (obstack
, sizeof (struct lang_decl
));
4341 DECL_LANG_SPECIFIC (t
) = (struct lang_decl
*) pi
;
4342 LANG_DECL_PERMANENT ((struct lang_decl
*) pi
)
4343 = obstack
== &permanent_obstack
;
4344 my_friendly_assert (LANG_DECL_PERMANENT ((struct lang_decl
*) pi
)
4345 == TREE_PERMANENT (t
), 234);
4346 DECL_MAIN_VARIANT (t
) = t
;
4347 if (current_lang_name
== lang_name_cplusplus
)
4348 DECL_LANGUAGE (t
) = lang_cplusplus
;
4349 else if (current_lang_name
== lang_name_c
)
4350 DECL_LANGUAGE (t
) = lang_c
;
4351 else my_friendly_abort (64);
4353 #if 0 /* not yet, should get fixed properly later */
4354 if (code
== TYPE_DECL
)
4357 id
= get_identifier (build_overload_name (type
, 1, 1));
4358 DECL_ASSEMBLER_NAME (t
) = id
;
4362 #ifdef GATHER_STATISTICS
4363 tree_node_counts
[(int)lang_decl
] += 1;
4364 tree_node_sizes
[(int)lang_decl
] += sizeof (struct lang_decl
);
4371 build_lang_field_decl (code
, name
, type
)
4372 enum tree_code code
;
4376 extern struct obstack
*current_obstack
, *saveable_obstack
;
4377 register tree t
= build_decl (code
, name
, type
);
4378 struct obstack
*obstack
= current_obstack
;
4379 register int i
= sizeof (struct lang_decl_flags
) / sizeof (int);
4381 #if 0 /* not yet, should get fixed properly later */
4383 if (code
== TYPE_DECL
)
4386 id
= get_identifier (build_overload_name (type
, 1, 1));
4387 DECL_ASSEMBLER_NAME (t
) = id
;
4391 if (! TREE_PERMANENT (t
))
4392 obstack
= saveable_obstack
;
4394 my_friendly_assert (obstack
== &permanent_obstack
, 235);
4396 pi
= (int *) obstack_alloc (obstack
, sizeof (struct lang_decl_flags
));
4400 DECL_LANG_SPECIFIC (t
) = (struct lang_decl
*) pi
;
4405 copy_lang_decl (node
)
4411 if (! DECL_LANG_SPECIFIC (node
))
4414 if (TREE_CODE (node
) == FIELD_DECL
)
4415 size
= sizeof (struct lang_decl_flags
);
4417 size
= sizeof (struct lang_decl
);
4418 pi
= (int *)obstack_alloc (&permanent_obstack
, size
);
4419 bcopy ((char *)DECL_LANG_SPECIFIC (node
), (char *)pi
, size
);
4420 DECL_LANG_SPECIFIC (node
) = (struct lang_decl
*)pi
;
4424 make_lang_type (code
)
4425 enum tree_code code
;
4427 extern struct obstack
*current_obstack
, *saveable_obstack
;
4428 register tree t
= make_node (code
);
4429 struct obstack
*obstack
= current_obstack
;
4430 register int i
= sizeof (struct lang_type
) / sizeof (int);
4433 /* Set up some flags that give proper default behavior. */
4434 IS_AGGR_TYPE (t
) = 1;
4436 if (! TREE_PERMANENT (t
))
4437 obstack
= saveable_obstack
;
4439 my_friendly_assert (obstack
== &permanent_obstack
, 236);
4441 pi
= (int *) obstack_alloc (obstack
, sizeof (struct lang_type
));
4445 TYPE_LANG_SPECIFIC (t
) = (struct lang_type
*) pi
;
4446 CLASSTYPE_AS_LIST (t
) = build_tree_list (NULL_TREE
, t
);
4447 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t
, interface_unknown
);
4448 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
4449 CLASSTYPE_VBASE_SIZE (t
) = integer_zero_node
;
4450 TYPE_BINFO (t
) = make_binfo (integer_zero_node
, t
, NULL_TREE
, NULL_TREE
,
4452 CLASSTYPE_BINFO_AS_LIST (t
) = build_tree_list (NULL_TREE
, TYPE_BINFO (t
));
4454 /* Make sure this is laid out, for ease of use later.
4455 In the presence of parse errors, the normal was of assuring
4456 this might not ever get executed, so we lay it out *immediately*. */
4457 build_pointer_type (t
);
4459 #ifdef GATHER_STATISTICS
4460 tree_node_counts
[(int)lang_type
] += 1;
4461 tree_node_sizes
[(int)lang_type
] += sizeof (struct lang_type
);
4468 dump_time_statistics ()
4470 register tree prev
= 0, decl
, next
;
4471 int this_time
= my_get_run_time ();
4472 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time
))
4473 += this_time
- body_time
;
4475 fprintf (stderr
, "\n******\n");
4476 print_time ("header files (total)", header_time
);
4477 print_time ("main file (total)", this_time
- body_time
);
4478 fprintf (stderr
, "ratio = %g : 1\n",
4479 (double)header_time
/ (double)(this_time
- body_time
));
4480 fprintf (stderr
, "\n******\n");
4482 for (decl
= filename_times
; decl
; decl
= next
)
4484 next
= IDENTIFIER_GLOBAL_VALUE (decl
);
4485 IDENTIFIER_GLOBAL_VALUE (decl
) = prev
;
4489 for (decl
= prev
; decl
; decl
= IDENTIFIER_GLOBAL_VALUE (decl
))
4490 print_time (IDENTIFIER_POINTER (decl
),
4491 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (decl
)));
4495 compiler_error (s
, v
, v2
)
4497 HOST_WIDE_INT v
, v2
; /* @@also used as pointer */
4500 sprintf (buf
, s
, v
, v2
);
4501 error_with_file_and_line (input_filename
, lineno
, "%s (compiler error)", buf
);
4508 extern int end_of_file
;
4511 strcpy (buf
, string
);
4513 /* We can't print string and character constants well
4514 because the token_buffer contains the result of processing escapes. */
4516 strcat (buf
, input_redirected ()
4517 ? " at end of saved text"
4518 : " at end of input");
4519 else if (token_buffer
[0] == 0)
4520 strcat (buf
, " at null character");
4521 else if (token_buffer
[0] == '"')
4522 strcat (buf
, " before string constant");
4523 else if (token_buffer
[0] == '\'')
4524 strcat (buf
, " before character constant");
4525 else if (token_buffer
[0] < 040 || (unsigned char) token_buffer
[0] >= 0177)
4526 sprintf (buf
+ strlen (buf
), " before character 0%o",
4527 (unsigned char) token_buffer
[0]);
4529 strcat (buf
, " before `%s'");
4531 error (buf
, token_buffer
);
4535 handle_cp_pragma (pname
)
4540 if (! strcmp (pname
, "vtable"))
4542 extern tree pending_vtables
;
4544 /* More follows: it must be a string constant (class name). */
4545 token
= real_yylex ();
4546 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
4548 error ("invalid #pragma vtable");
4552 if (write_virtuals
!= 2)
4554 warning ("use `+e2' option to enable #pragma vtable");
4558 = perm_tree_cons (NULL_TREE
,
4559 get_identifier (TREE_STRING_POINTER (yylval
.ttype
)),
4561 token
= real_yylex ();
4562 if (token
!= END_OF_LINE
)
4563 warning ("trailing characters ignored");
4566 else if (! strcmp (pname
, "unit"))
4568 /* More follows: it must be a string constant (unit name). */
4569 token
= real_yylex ();
4570 if (token
!= STRING
|| TREE_CODE (yylval
.ttype
) != STRING_CST
)
4572 error ("invalid #pragma unit");
4575 token
= real_yylex ();
4576 if (token
!= END_OF_LINE
)
4577 warning ("trailing characters ignored");
4580 else if (! strcmp (pname
, "interface"))
4582 tree fileinfo
= IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename
));
4583 char *main_filename
= input_filename
;
4585 main_filename
= FILE_NAME_NONDIRECTORY (main_filename
);
4587 token
= real_yylex ();
4589 if (token
!= END_OF_LINE
)
4592 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
4594 error ("invalid `#pragma interface'");
4597 main_filename
= TREE_STRING_POINTER (yylval
.ttype
);
4598 token
= real_yylex ();
4601 if (token
!= END_OF_LINE
)
4602 warning ("garbage after `#pragma interface' ignored");
4604 #ifndef NO_LINKAGE_HEURISTICS
4607 if (impl_file_chain
== 0)
4609 /* If this is zero at this point, then we are
4610 auto-implementing. */
4611 if (main_input_filename
== 0)
4612 main_input_filename
= input_filename
;
4614 #ifdef AUTO_IMPLEMENT
4615 filename
= FILE_NAME_NONDIRECTORY (main_input_filename
);
4616 fi
= get_time_identifier (filename
);
4617 fi
= IDENTIFIER_CLASS_VALUE (fi
);
4618 TREE_INT_CST_LOW (fi
) = 0;
4619 TREE_INT_CST_HIGH (fi
) = 1;
4621 impl_file_chain
= (struct impl_files
*)permalloc (sizeof (struct impl_files
));
4622 impl_file_chain
->filename
= filename
;
4623 impl_file_chain
->next
= 0;
4627 interface_only
= interface_strcmp (main_filename
);
4628 interface_unknown
= 0;
4629 TREE_INT_CST_LOW (fileinfo
) = interface_only
;
4630 TREE_INT_CST_HIGH (fileinfo
) = interface_unknown
;
4631 #endif /* NO_LINKAGE_HEURISTICS */
4635 else if (! strcmp (pname
, "implementation"))
4637 tree fileinfo
= IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename
));
4638 char *main_filename
= main_input_filename
? main_input_filename
: input_filename
;
4640 main_filename
= FILE_NAME_NONDIRECTORY (main_filename
);
4641 token
= real_yylex ();
4642 if (token
!= END_OF_LINE
)
4645 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
4647 error ("invalid `#pragma implementation'");
4650 main_filename
= TREE_STRING_POINTER (yylval
.ttype
);
4651 token
= real_yylex ();
4654 if (token
!= END_OF_LINE
)
4655 warning ("garbage after `#pragma implementation' ignored");
4657 #ifndef NO_LINKAGE_HEURISTICS
4658 if (write_virtuals
== 3)
4660 struct impl_files
*ifiles
= impl_file_chain
;
4663 if (! strcmp (ifiles
->filename
, main_filename
))
4665 ifiles
= ifiles
->next
;
4669 ifiles
= (struct impl_files
*) permalloc (sizeof (struct impl_files
));
4670 ifiles
->filename
= main_filename
;
4671 ifiles
->next
= impl_file_chain
;
4672 impl_file_chain
= ifiles
;
4675 else if ((main_input_filename
!= 0
4676 && ! strcmp (main_input_filename
, input_filename
))
4677 || ! strcmp (input_filename
, main_filename
))
4680 if (impl_file_chain
== 0)
4682 impl_file_chain
= (struct impl_files
*) permalloc (sizeof (struct impl_files
));
4683 impl_file_chain
->filename
= main_filename
;
4684 impl_file_chain
->next
= 0;
4688 error ("`#pragma implementation' can only appear at top-level");
4691 /* We make this non-zero so that we infer decl linkage
4692 in the impl file only for variables first declared
4693 in the interface file. */
4694 interface_unknown
= 1;
4696 /* We make this zero so that templates in the impl
4697 file will be emitted properly. */
4698 interface_unknown
= 0;
4700 TREE_INT_CST_LOW (fileinfo
) = interface_only
;
4701 TREE_INT_CST_HIGH (fileinfo
) = interface_unknown
;
4702 #endif /* NO_LINKAGE_HEURISTICS */
4710 #ifdef HANDLE_SYSV_PRAGMA
4712 /* Handle a #pragma directive. INPUT is the current input stream,
4713 and C is a character to reread. Processes the entire input line
4714 and returns a character for the caller to reread: either \n or EOF. */
4716 /* This function has to be in this file, in order to get at
4720 handle_sysv_pragma (finput
, token
)
4732 handle_pragma_token ("ignored", yylval
.ttype
);
4735 handle_pragma_token ("(", NULL_TREE
);
4738 handle_pragma_token (")", NULL_TREE
);
4741 handle_pragma_token (",", NULL_TREE
);
4744 handle_pragma_token ("=", NULL_TREE
);
4747 handle_pragma_token ("(", NULL_TREE
);
4748 handle_pragma_token (")", NULL_TREE
);
4752 handle_pragma_token (NULL_PTR
, NULL_TREE
);
4755 token
= real_yylex ();
4758 #endif /* HANDLE_SYSV_PRAGMA */