]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Separate lexical analyzer for GNU C++. |
d6a8bdff JL |
2 | Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
3 | 1999, 2000 Free Software Foundation, Inc. | |
8d08fdba MS |
4 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
5 | ||
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
22 | |
23 | ||
24 | /* This file is the lexical analyzer for GNU C++. */ | |
25 | ||
8926095f | 26 | /* Cause the `yydebug' variable to be defined. */ |
8d08fdba | 27 | #define YYDEBUG 1 |
8d08fdba | 28 | |
da20811c | 29 | #include "config.h" |
8d052bc7 | 30 | #include "system.h" |
8d08fdba MS |
31 | #include "input.h" |
32 | #include "tree.h" | |
33 | #include "lex.h" | |
8d08fdba | 34 | #include "cp-tree.h" |
46b02c6d | 35 | #include "parse.h" |
8d08fdba MS |
36 | #include "flags.h" |
37 | #include "obstack.h" | |
3d6f7931 | 38 | #include "c-pragma.h" |
54f92bfb | 39 | #include "toplev.h" |
7dee3f36 | 40 | #include "output.h" |
9cd64686 | 41 | #include "ggc.h" |
7bdb32b9 | 42 | #include "tm_p.h" |
8d08fdba MS |
43 | |
44 | #ifdef MULTIBYTE_CHARS | |
0d3ba739 | 45 | #include "mbchar.h" |
8d08fdba MS |
46 | #include <locale.h> |
47 | #endif | |
48 | ||
8d08fdba MS |
49 | #define obstack_chunk_alloc xmalloc |
50 | #define obstack_chunk_free free | |
51 | ||
158991b7 KG |
52 | extern void yyprint PARAMS ((FILE *, int, YYSTYPE)); |
53 | ||
54 | static tree get_time_identifier PARAMS ((const char *)); | |
55 | static int check_newline PARAMS ((void)); | |
56 | static int whitespace_cr PARAMS ((int)); | |
57 | static int skip_white_space PARAMS ((int)); | |
58 | static void finish_defarg PARAMS ((void)); | |
59 | static int my_get_run_time PARAMS ((void)); | |
60 | static int interface_strcmp PARAMS ((const char *)); | |
61 | static int readescape PARAMS ((int *)); | |
62 | static char *extend_token_buffer PARAMS ((const char *)); | |
63 | static void consume_string PARAMS ((struct obstack *, int)); | |
64 | static void feed_defarg PARAMS ((tree, tree)); | |
65 | static void store_pending_inline PARAMS ((tree, struct pending_inline *)); | |
66 | static void reinit_parse_for_expr PARAMS ((struct obstack *)); | |
67 | static int *init_cpp_parse PARAMS ((void)); | |
68 | static void cp_pragma_interface PARAMS ((char *)); | |
69 | static void cp_pragma_implementation PARAMS ((char *)); | |
70 | static int handle_cp_pragma PARAMS ((const char *)); | |
a09a009c | 71 | #ifdef HANDLE_GENERIC_PRAGMAS |
158991b7 | 72 | static int handle_generic_pragma PARAMS ((int)); |
69ac77ce JL |
73 | #endif |
74 | #ifdef GATHER_STATISTICS | |
75 | #ifdef REDUCE_LENGTH | |
158991b7 KG |
76 | static int reduce_cmp PARAMS ((int *, int *)); |
77 | static int token_cmp PARAMS ((int *, int *)); | |
69ac77ce JL |
78 | #endif |
79 | #endif | |
158991b7 KG |
80 | static void begin_definition_of_inclass_inline PARAMS ((struct pending_inline*)); |
81 | static void parse_float PARAMS ((PTR)); | |
82 | static int is_global PARAMS ((tree)); | |
83 | static void init_filename_times PARAMS ((void)); | |
84 | static void extend_token_buffer_to PARAMS ((int)); | |
9c0758dd | 85 | #ifdef HANDLE_PRAGMA |
158991b7 KG |
86 | static int pragma_getc PARAMS ((void)); |
87 | static void pragma_ungetc PARAMS ((int)); | |
9c0758dd | 88 | #endif |
158991b7 KG |
89 | static int read_line_number PARAMS ((int *)); |
90 | static int token_getch PARAMS ((void)); | |
91 | static void token_put_back PARAMS ((int)); | |
92 | static void mark_impl_file_chain PARAMS ((void *)); | |
8d08fdba MS |
93 | |
94 | /* Given a file name X, return the nondirectory portion. | |
95 | Keep in mind that X can be computed more than once. */ | |
b2bb2710 BK |
96 | char * |
97 | file_name_nondirectory (x) | |
d8e178a0 | 98 | const char *x; |
b2bb2710 | 99 | { |
e95d117b MK |
100 | char *tmp = (char *) rindex (x, '/'); |
101 | if (DIR_SEPARATOR != '/' && ! tmp) | |
102 | tmp = (char *) rindex (x, DIR_SEPARATOR); | |
b2bb2710 BK |
103 | if (tmp) |
104 | return (char *) (tmp + 1); | |
105 | else | |
d8e178a0 | 106 | return (char *) x; |
b2bb2710 | 107 | } |
8d08fdba | 108 | |
8d08fdba MS |
109 | /* This obstack is needed to hold text. It is not safe to use |
110 | TOKEN_BUFFER because `check_newline' calls `yylex'. */ | |
111 | struct obstack inline_text_obstack; | |
42976354 | 112 | char *inline_text_firstobj; |
f376e137 | 113 | |
0b807ad8 MK |
114 | /* Nonzero if parse output is being saved to an obstack for later parsing. */ |
115 | static int saving_parse_to_obstack = 0; | |
116 | ||
d4dfe7d6 DB |
117 | #if USE_CPPLIB |
118 | #include "cpplib.h" | |
276ca6ea DB |
119 | extern cpp_reader parse_in; |
120 | extern cpp_options parse_options; | |
121 | extern unsigned char *yy_cur, *yy_lim; | |
66a6250f | 122 | extern enum cpp_token cpp_token; |
d4dfe7d6 | 123 | #else |
2b2a3531 DB |
124 | FILE *finput; |
125 | #endif | |
8d08fdba MS |
126 | int end_of_file; |
127 | ||
66a6250f JM |
128 | int linemode; |
129 | ||
8d08fdba MS |
130 | /* Pending language change. |
131 | Positive is push count, negative is pop count. */ | |
132 | int pending_lang_change = 0; | |
133 | ||
134 | /* Wrap the current header file in extern "C". */ | |
135 | static int c_header_level = 0; | |
136 | ||
137 | extern int first_token; | |
138 | extern struct obstack token_obstack; | |
139 | ||
140 | /* ??? Don't really know where this goes yet. */ | |
8d08fdba | 141 | #include "input.c" |
8d08fdba MS |
142 | |
143 | /* Holds translations from TREE_CODEs to operator name strings, | |
144 | i.e., opname_tab[PLUS_EXPR] == "+". */ | |
9c0758dd KG |
145 | const char **opname_tab; |
146 | const char **assignop_tab; | |
8d08fdba MS |
147 | \f |
148 | extern int yychar; /* the lookahead symbol */ | |
149 | extern YYSTYPE yylval; /* the semantic value of the */ | |
150 | /* lookahead symbol */ | |
151 | ||
152 | #if 0 | |
153 | YYLTYPE yylloc; /* location data for the lookahead */ | |
154 | /* symbol */ | |
155 | #endif | |
156 | ||
157 | ||
158 | /* the declaration found for the last IDENTIFIER token read in. | |
159 | yylex must look this up to detect typedefs, which get token type TYPENAME, | |
160 | so it is left around in case the identifier is not a typedef but is | |
161 | used in a context which makes it a reference to a variable. */ | |
162 | tree lastiddecl; | |
163 | ||
164 | /* The elements of `ridpointers' are identifier nodes | |
165 | for the reserved type names and storage classes. | |
166 | It is indexed by a RID_... value. */ | |
167 | tree ridpointers[(int) RID_MAX]; | |
168 | ||
169 | /* We may keep statistics about how long which files took to compile. */ | |
170 | static int header_time, body_time; | |
8d08fdba MS |
171 | static tree filename_times; |
172 | static tree this_filename_time; | |
173 | ||
8d08fdba MS |
174 | /* Array for holding counts of the numbers of tokens seen. */ |
175 | extern int *token_count; | |
9cd64686 MM |
176 | |
177 | /* When we see a default argument in a method declaration, we snarf it as | |
178 | text using snarf_defarg. When we get up to namespace scope, we then go | |
179 | through and parse all of them using do_pending_defargs. Since yacc | |
180 | parsers are not reentrant, we retain defargs state in these two | |
181 | variables so that subsequent calls to do_pending_defargs can resume | |
182 | where the previous call left off. */ | |
183 | ||
184 | static tree defarg_fns; | |
185 | static tree defarg_parm; | |
186 | ||
87e3dbc9 MM |
187 | /* Functions and data structures for #pragma interface. |
188 | ||
189 | `#pragma implementation' means that the main file being compiled | |
190 | is considered to implement (provide) the classes that appear in | |
191 | its main body. I.e., if this is file "foo.cc", and class `bar' | |
192 | is defined in "foo.cc", then we say that "foo.cc implements bar". | |
193 | ||
194 | All main input files "implement" themselves automagically. | |
195 | ||
196 | `#pragma interface' means that unless this file (of the form "foo.h" | |
197 | is not presently being included by file "foo.cc", the | |
198 | CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none | |
199 | of the vtables nor any of the inline functions defined in foo.h | |
200 | will ever be output. | |
201 | ||
202 | There are cases when we want to link files such as "defs.h" and | |
203 | "main.cc". In this case, we give "defs.h" a `#pragma interface', | |
204 | and "main.cc" has `#pragma implementation "defs.h"'. */ | |
205 | ||
206 | struct impl_files | |
207 | { | |
208 | char *filename; | |
209 | struct impl_files *next; | |
210 | }; | |
211 | ||
212 | static struct impl_files *impl_file_chain; | |
213 | ||
f3cdb9c6 AS |
214 | /* The string used to represent the filename of internally generated |
215 | tree nodes. The variable, which is dynamically allocated, should | |
216 | be used; the macro is only used to initialize it. */ | |
217 | static char *internal_filename; | |
218 | #define INTERNAL_FILENAME ("<internal>") | |
8d08fdba MS |
219 | \f |
220 | /* Return something to represent absolute declarators containing a *. | |
221 | TARGET is the absolute declarator that the * contains. | |
c11b6f21 | 222 | CV_QUALIFIERS is a list of modifiers such as const or volatile |
8d08fdba MS |
223 | to apply to the pointer type, represented as identifiers. |
224 | ||
225 | We return an INDIRECT_REF whose "contents" are TARGET | |
226 | and whose type is the modifier list. */ | |
227 | ||
228 | tree | |
c11b6f21 MS |
229 | make_pointer_declarator (cv_qualifiers, target) |
230 | tree cv_qualifiers, target; | |
8d08fdba MS |
231 | { |
232 | if (target && TREE_CODE (target) == IDENTIFIER_NODE | |
233 | && ANON_AGGRNAME_P (target)) | |
8251199e | 234 | error ("type name expected before `*'"); |
8d08fdba | 235 | target = build_parse_node (INDIRECT_REF, target); |
c11b6f21 | 236 | TREE_TYPE (target) = cv_qualifiers; |
8d08fdba MS |
237 | return target; |
238 | } | |
239 | ||
240 | /* Return something to represent absolute declarators containing a &. | |
241 | TARGET is the absolute declarator that the & contains. | |
c11b6f21 | 242 | CV_QUALIFIERS is a list of modifiers such as const or volatile |
8d08fdba MS |
243 | to apply to the reference type, represented as identifiers. |
244 | ||
245 | We return an ADDR_EXPR whose "contents" are TARGET | |
246 | and whose type is the modifier list. */ | |
247 | ||
248 | tree | |
c11b6f21 MS |
249 | make_reference_declarator (cv_qualifiers, target) |
250 | tree cv_qualifiers, target; | |
8d08fdba MS |
251 | { |
252 | if (target) | |
253 | { | |
254 | if (TREE_CODE (target) == ADDR_EXPR) | |
255 | { | |
8251199e | 256 | error ("cannot declare references to references"); |
8d08fdba MS |
257 | return target; |
258 | } | |
259 | if (TREE_CODE (target) == INDIRECT_REF) | |
260 | { | |
8251199e | 261 | error ("cannot declare pointers to references"); |
8d08fdba MS |
262 | return target; |
263 | } | |
264 | if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target)) | |
8251199e | 265 | error ("type name expected before `&'"); |
8d08fdba MS |
266 | } |
267 | target = build_parse_node (ADDR_EXPR, target); | |
c11b6f21 | 268 | TREE_TYPE (target) = cv_qualifiers; |
8d08fdba MS |
269 | return target; |
270 | } | |
c11b6f21 MS |
271 | |
272 | tree | |
273 | make_call_declarator (target, parms, cv_qualifiers, exception_specification) | |
274 | tree target, parms, cv_qualifiers, exception_specification; | |
275 | { | |
43f887f9 MM |
276 | target = build_parse_node (CALL_EXPR, target, |
277 | /* Both build_parse_node and | |
278 | decl_tree_cons build on the | |
279 | temp_decl_obstack. */ | |
280 | decl_tree_cons (parms, cv_qualifiers, NULL_TREE), | |
281 | /* The third operand is really RTL. We | |
282 | shouldn't put anything there. */ | |
283 | NULL_TREE); | |
284 | CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification; | |
c11b6f21 MS |
285 | return target; |
286 | } | |
287 | ||
288 | void | |
289 | set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification) | |
290 | tree call_declarator, cv_qualifiers, exception_specification; | |
291 | { | |
43f887f9 MM |
292 | CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers; |
293 | CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification; | |
c11b6f21 | 294 | } |
8d08fdba MS |
295 | \f |
296 | /* Build names and nodes for overloaded operators. */ | |
297 | ||
298 | tree ansi_opname[LAST_CPLUS_TREE_CODE]; | |
299 | tree ansi_assopname[LAST_CPLUS_TREE_CODE]; | |
300 | ||
9c0758dd | 301 | const char * |
8d08fdba MS |
302 | operator_name_string (name) |
303 | tree name; | |
304 | { | |
305 | char *opname = IDENTIFIER_POINTER (name) + 2; | |
306 | tree *opname_table; | |
307 | int i, assign; | |
308 | ||
309 | /* Works for builtin and user defined types. */ | |
310 | if (IDENTIFIER_GLOBAL_VALUE (name) | |
311 | && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL) | |
312 | return IDENTIFIER_POINTER (name); | |
313 | ||
314 | if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_') | |
315 | { | |
316 | opname += 1; | |
317 | assign = 1; | |
318 | opname_table = ansi_assopname; | |
319 | } | |
320 | else | |
321 | { | |
322 | assign = 0; | |
323 | opname_table = ansi_opname; | |
324 | } | |
325 | ||
326 | for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++) | |
327 | { | |
328 | if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign] | |
329 | && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign]) | |
330 | break; | |
331 | } | |
332 | ||
333 | if (i == LAST_CPLUS_TREE_CODE) | |
334 | return "<invalid operator>"; | |
335 | ||
336 | if (assign) | |
337 | return assignop_tab[i]; | |
338 | else | |
339 | return opname_tab[i]; | |
340 | } | |
341 | \f | |
342 | int interface_only; /* whether or not current file is only for | |
343 | interface definitions. */ | |
344 | int interface_unknown; /* whether or not we know this class | |
345 | to behave according to #pragma interface. */ | |
346 | ||
347 | /* lexical analyzer */ | |
348 | ||
5096c664 JM |
349 | #undef WCHAR_TYPE_SIZE |
350 | #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node) | |
8d08fdba MS |
351 | |
352 | /* Number of bytes in a wide character. */ | |
353 | #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT) | |
354 | ||
355 | static int maxtoken; /* Current nominal length of token buffer. */ | |
356 | char *token_buffer; /* Pointer to token buffer. | |
357 | Actual allocated length is maxtoken + 2. */ | |
358 | ||
1ceb5ff3 | 359 | static int indent_level; /* Number of { minus number of }. */ |
66a6250f | 360 | |
8d08fdba MS |
361 | #include "hash.h" |
362 | \f | |
8d08fdba MS |
363 | |
364 | /* Nonzero tells yylex to ignore \ in string constants. */ | |
1ceb5ff3 | 365 | static int ignore_escape_flag; |
8d08fdba | 366 | |
8d08fdba MS |
367 | static tree |
368 | get_time_identifier (name) | |
d8e178a0 | 369 | const char *name; |
8d08fdba MS |
370 | { |
371 | tree time_identifier; | |
372 | int len = strlen (name); | |
373 | char *buf = (char *) alloca (len + 6); | |
374 | strcpy (buf, "file "); | |
375 | bcopy (name, buf+5, len); | |
376 | buf[len+5] = '\0'; | |
377 | time_identifier = get_identifier (buf); | |
f181d4ae | 378 | if (TIME_IDENTIFIER_TIME (time_identifier) == NULL_TREE) |
8d08fdba | 379 | { |
f181d4ae MM |
380 | TIME_IDENTIFIER_TIME (time_identifier) = build_int_2 (0, 0); |
381 | TIME_IDENTIFIER_FILEINFO (time_identifier) | |
382 | = build_int_2 (0, 1); | |
2c73f9f5 | 383 | SET_IDENTIFIER_GLOBAL_VALUE (time_identifier, filename_times); |
8d08fdba | 384 | filename_times = time_identifier; |
8d08fdba MS |
385 | } |
386 | return time_identifier; | |
387 | } | |
388 | ||
f9c4f105 | 389 | static inline int |
8d08fdba MS |
390 | my_get_run_time () |
391 | { | |
392 | int old_quiet_flag = quiet_flag; | |
393 | int this_time; | |
394 | quiet_flag = 0; | |
395 | this_time = get_run_time (); | |
396 | quiet_flag = old_quiet_flag; | |
397 | return this_time; | |
398 | } | |
399 | \f | |
400 | /* Table indexed by tree code giving a string containing a character | |
401 | classifying the tree code. Possibilities are | |
e92cc029 | 402 | t, d, s, c, r, <, 1 and 2. See cp/cp-tree.def for details. */ |
8d08fdba MS |
403 | |
404 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, | |
405 | ||
46e8c075 | 406 | static char cplus_tree_code_type[] = { |
0a6969ad | 407 | 'x', |
e92cc029 | 408 | #include "cp-tree.def" |
8d08fdba MS |
409 | }; |
410 | #undef DEFTREECODE | |
411 | ||
412 | /* Table indexed by tree code giving number of expression | |
413 | operands beyond the fixed part of the node structure. | |
414 | Not used for types or decls. */ | |
415 | ||
416 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, | |
417 | ||
46e8c075 | 418 | static int cplus_tree_code_length[] = { |
8d08fdba | 419 | 0, |
e92cc029 | 420 | #include "cp-tree.def" |
8d08fdba MS |
421 | }; |
422 | #undef DEFTREECODE | |
423 | ||
424 | /* Names of tree components. | |
425 | Used for printing out the tree and error messages. */ | |
426 | #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, | |
427 | ||
46e8c075 | 428 | static const char *cplus_tree_code_name[] = { |
8d08fdba | 429 | "@@dummy", |
e92cc029 | 430 | #include "cp-tree.def" |
8d08fdba MS |
431 | }; |
432 | #undef DEFTREECODE | |
433 | \f | |
434 | /* toplev.c needs to call these. */ | |
435 | ||
9116eca2 RH |
436 | void |
437 | lang_init_options () | |
438 | { | |
dfb0fb1d DB |
439 | #if USE_CPPLIB |
440 | cpp_reader_init (&parse_in); | |
441 | parse_in.opts = &parse_options; | |
442 | cpp_options_init (&parse_options); | |
66a6250f | 443 | parse_options.cplusplus = 1; |
dfb0fb1d DB |
444 | #endif |
445 | ||
9116eca2 RH |
446 | /* Default exceptions on. */ |
447 | flag_exceptions = 1; | |
9329983a GM |
448 | /* Mark as "unspecified". */ |
449 | flag_bounds_check = -1; | |
2269eec3 MM |
450 | /* By default wrap lines at 72 characters. */ |
451 | set_message_length (72); | |
9116eca2 RH |
452 | } |
453 | ||
8d08fdba MS |
454 | void |
455 | lang_init () | |
456 | { | |
9329983a GM |
457 | /* If still "unspecified", make it match -fbounded-pointers. */ |
458 | if (flag_bounds_check < 0) | |
459 | flag_bounds_check = flag_bounded_pointers; | |
460 | ||
8d08fdba MS |
461 | /* the beginning of the file is a new line; check for # */ |
462 | /* With luck, we discover the real source file's name from that | |
463 | and put it in input_filename. */ | |
464 | put_back (check_newline ()); | |
8d08fdba | 465 | if (flag_gnu_xref) GNU_xref_begin (input_filename); |
faae18ab | 466 | init_repo (input_filename); |
8d08fdba MS |
467 | } |
468 | ||
469 | void | |
470 | lang_finish () | |
471 | { | |
8d08fdba MS |
472 | if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount); |
473 | } | |
474 | ||
8df4696d | 475 | const char * |
8d08fdba MS |
476 | lang_identify () |
477 | { | |
478 | return "cplusplus"; | |
479 | } | |
480 | ||
d8e178a0 | 481 | static void |
8d08fdba MS |
482 | init_filename_times () |
483 | { | |
484 | this_filename_time = get_time_identifier ("<top level>"); | |
485 | if (flag_detailed_statistics) | |
486 | { | |
487 | header_time = 0; | |
488 | body_time = my_get_run_time (); | |
f181d4ae MM |
489 | TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time)) |
490 | = body_time; | |
8d08fdba MS |
491 | } |
492 | } | |
493 | ||
494 | /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989. | |
495 | Stuck this hack in to get the files open correctly; this is called | |
2b2a3531 | 496 | in place of init_parse if we are an unexec'd binary. */ |
e92cc029 | 497 | |
bd6dd845 | 498 | #if 0 |
8d08fdba MS |
499 | void |
500 | reinit_lang_specific () | |
501 | { | |
502 | init_filename_times (); | |
503 | reinit_search_statistics (); | |
504 | } | |
bd6dd845 | 505 | #endif |
8d08fdba | 506 | |
2b2a3531 DB |
507 | static int * |
508 | init_cpp_parse () | |
509 | { | |
510 | #ifdef GATHER_STATISTICS | |
511 | #ifdef REDUCE_LENGTH | |
fffeac96 | 512 | reduce_count = (int *) xcalloc (sizeof (int), (REDUCE_LENGTH + 1)); |
2b2a3531 | 513 | reduce_count += 1; |
fffeac96 | 514 | token_count = (int *) xcalloc (sizeof (int), (TOKEN_LENGTH + 1)); |
2b2a3531 DB |
515 | token_count += 1; |
516 | #endif | |
517 | #endif | |
518 | return token_count; | |
519 | } | |
520 | ||
a755ad1c | 521 | char * |
2b2a3531 DB |
522 | init_parse (filename) |
523 | char *filename; | |
8d08fdba | 524 | { |
e1cd6e56 MS |
525 | extern int flag_no_gnu_keywords; |
526 | extern int flag_operator_names; | |
8d08fdba MS |
527 | |
528 | int i; | |
529 | ||
0d3ba739 DB |
530 | #ifdef MULTIBYTE_CHARS |
531 | /* Change to the native locale for multibyte conversions. */ | |
532 | setlocale (LC_CTYPE, ""); | |
3e81ad16 | 533 | literal_codeset = getenv ("LANG"); |
0d3ba739 DB |
534 | #endif |
535 | ||
1ceb5ff3 | 536 | #if !USE_CPPLIB |
2b2a3531 DB |
537 | /* Open input file. */ |
538 | if (filename == 0 || !strcmp (filename, "-")) | |
539 | { | |
540 | finput = stdin; | |
541 | filename = "stdin"; | |
542 | } | |
543 | else | |
544 | finput = fopen (filename, "r"); | |
545 | if (finput == 0) | |
546 | pfatal_with_name (filename); | |
547 | ||
548 | #ifdef IO_BUFFER_SIZE | |
549 | setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE); | |
550 | #endif | |
1ceb5ff3 JM |
551 | #else /* !USE_CPPLIB */ |
552 | parse_in.show_column = 1; | |
553 | if (! cpp_start_read (&parse_in, filename)) | |
554 | abort (); | |
555 | ||
556 | if (filename == 0 || !strcmp (filename, "-")) | |
557 | filename = "stdin"; | |
558 | ||
559 | /* cpp_start_read always puts at least one line directive into the | |
560 | token buffer. We must arrange to read it out here. */ | |
561 | yy_cur = parse_in.token_buffer; | |
562 | yy_lim = CPP_PWRITTEN (&parse_in); | |
563 | cpp_token = CPP_DIRECTIVE; | |
564 | ||
2b2a3531 DB |
565 | #endif /* !USE_CPPLIB */ |
566 | ||
8d08fdba MS |
567 | /* Initialize the lookahead machinery. */ |
568 | init_spew (); | |
569 | ||
570 | /* Make identifier nodes long enough for the language-specific slots. */ | |
571 | set_identifier_size (sizeof (struct lang_identifier)); | |
572 | decl_printable_name = lang_printable_name; | |
573 | ||
87e3dbc9 | 574 | init_tree (); |
8d08fdba MS |
575 | init_cplus_expand (); |
576 | ||
f5984164 KG |
577 | memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE, |
578 | cplus_tree_code_type, | |
579 | (int)LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE); | |
580 | memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE, | |
581 | cplus_tree_code_length, | |
582 | (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int)); | |
583 | memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE, | |
584 | cplus_tree_code_name, | |
585 | (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *)); | |
8d08fdba | 586 | |
9c0758dd | 587 | opname_tab = (const char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *)); |
f5984164 | 588 | memset (opname_tab, 0, (int)LAST_CPLUS_TREE_CODE * sizeof (char *)); |
9c0758dd | 589 | assignop_tab = (const char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *)); |
f5984164 | 590 | memset (assignop_tab, 0, (int)LAST_CPLUS_TREE_CODE * sizeof (char *)); |
8d08fdba MS |
591 | |
592 | ansi_opname[0] = get_identifier ("<invalid operator>"); | |
593 | for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++) | |
594 | { | |
595 | ansi_opname[i] = ansi_opname[0]; | |
596 | ansi_assopname[i] = ansi_opname[0]; | |
597 | } | |
598 | ||
599 | ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml"); | |
600 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1; | |
601 | ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR]; | |
602 | ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml"); | |
603 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1; | |
604 | ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR]; | |
605 | ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md"); | |
606 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1; | |
607 | ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd"); | |
608 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1; | |
609 | ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; | |
610 | ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; | |
611 | ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; | |
612 | ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi"); | |
613 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1; | |
614 | ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR]; | |
615 | ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami"); | |
616 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1; | |
617 | ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR]; | |
618 | ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs"); | |
619 | IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1; | |
620 | ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars"); | |
621 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1; | |
622 | ansi_opname[(int) NE_EXPR] = get_identifier ("__ne"); | |
623 | IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1; | |
624 | ansi_opname[(int) GT_EXPR] = get_identifier ("__gt"); | |
625 | IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1; | |
626 | ansi_opname[(int) GE_EXPR] = get_identifier ("__ge"); | |
627 | IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1; | |
628 | ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or"); | |
629 | IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1; | |
630 | ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor"); | |
631 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1; | |
632 | ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa"); | |
633 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1; | |
634 | ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt"); | |
635 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1; | |
636 | ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp"); | |
637 | IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1; | |
638 | ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR]; | |
639 | ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as"); | |
640 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1; | |
641 | ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR]; | |
642 | ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm"); | |
643 | IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1; | |
644 | ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv"); | |
645 | IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1; | |
646 | ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv"); | |
647 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1; | |
648 | ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; | |
649 | ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; | |
650 | ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; | |
651 | ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; | |
652 | ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl"); | |
653 | ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; | |
654 | ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; | |
655 | ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; | |
656 | ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; | |
657 | IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1; | |
658 | ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl"); | |
659 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1; | |
660 | ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR]; | |
661 | ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR]; | |
662 | ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls"); | |
663 | IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1; | |
664 | ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als"); | |
665 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1; | |
666 | ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq"); | |
667 | IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1; | |
668 | ansi_opname[(int) LT_EXPR] = get_identifier ("__lt"); | |
669 | IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1; | |
670 | ansi_opname[(int) LE_EXPR] = get_identifier ("__le"); | |
671 | IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1; | |
672 | ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad"); | |
673 | IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1; | |
674 | ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad"); | |
675 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1; | |
676 | ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR]; | |
677 | ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR]; | |
678 | ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er"); | |
679 | IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1; | |
680 | ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer"); | |
681 | IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1; | |
682 | ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo"); | |
683 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1; | |
684 | ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co"); | |
685 | IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1; | |
686 | ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm"); | |
687 | IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1; | |
688 | ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR]; | |
689 | ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf"); | |
690 | IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1; | |
691 | ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm"); | |
692 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1; | |
693 | ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl"); | |
694 | IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1; | |
695 | ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc"); | |
696 | IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1; | |
697 | ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw"); | |
698 | IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1; | |
699 | ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl"); | |
700 | IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1; | |
a28e3c7f MS |
701 | ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn"); |
702 | IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1; | |
703 | ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd"); | |
704 | IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1; | |
4c571114 | 705 | ansi_opname[(int) TYPE_EXPR] = get_identifier (OPERATOR_TYPENAME_FORMAT); |
8d08fdba MS |
706 | IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1; |
707 | ||
708 | /* This is not true: these operators are not defined in ANSI, | |
709 | but we need them anyway. */ | |
710 | ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn"); | |
711 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1; | |
712 | ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx"); | |
713 | IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1; | |
714 | ansi_opname[(int) COND_EXPR] = get_identifier ("__cn"); | |
715 | IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1; | |
ff29fd00 MM |
716 | ansi_opname[(int) SIZEOF_EXPR] = get_identifier ("__sz"); |
717 | IDENTIFIER_OPNAME_P (ansi_opname[(int) SIZEOF_EXPR]) = 1; | |
8d08fdba MS |
718 | |
719 | init_method (); | |
720 | init_error (); | |
721 | gcc_obstack_init (&inline_text_obstack); | |
42976354 | 722 | inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0); |
8d08fdba | 723 | |
f3cdb9c6 AS |
724 | internal_filename = ggc_alloc_string (INTERNAL_FILENAME, |
725 | sizeof (INTERNAL_FILENAME)); | |
726 | ||
8d08fdba MS |
727 | /* Start it at 0, because check_newline is called at the very beginning |
728 | and will increment it to 1. */ | |
729 | lineno = 0; | |
f3cdb9c6 | 730 | input_filename = internal_filename; |
8d08fdba MS |
731 | current_function_decl = NULL; |
732 | ||
733 | maxtoken = 40; | |
734 | token_buffer = (char *) xmalloc (maxtoken + 2); | |
735 | ||
736 | ridpointers[(int) RID_INT] = get_identifier ("int"); | |
2986ae00 | 737 | ridpointers[(int) RID_BOOL] = get_identifier ("bool"); |
8d08fdba | 738 | ridpointers[(int) RID_CHAR] = get_identifier ("char"); |
8d08fdba | 739 | ridpointers[(int) RID_VOID] = get_identifier ("void"); |
8d08fdba | 740 | ridpointers[(int) RID_FLOAT] = get_identifier ("float"); |
8d08fdba | 741 | ridpointers[(int) RID_DOUBLE] = get_identifier ("double"); |
8d08fdba | 742 | ridpointers[(int) RID_SHORT] = get_identifier ("short"); |
8d08fdba | 743 | ridpointers[(int) RID_LONG] = get_identifier ("long"); |
8d08fdba | 744 | ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned"); |
8d08fdba | 745 | ridpointers[(int) RID_SIGNED] = get_identifier ("signed"); |
8d08fdba | 746 | ridpointers[(int) RID_INLINE] = get_identifier ("inline"); |
8d08fdba | 747 | ridpointers[(int) RID_CONST] = get_identifier ("const"); |
91063b51 | 748 | ridpointers[(int) RID_RESTRICT] = get_identifier ("__restrict"); |
1ceb5ff3 | 749 | ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile"); |
8d08fdba | 750 | ridpointers[(int) RID_AUTO] = get_identifier ("auto"); |
8d08fdba | 751 | ridpointers[(int) RID_STATIC] = get_identifier ("static"); |
8d08fdba | 752 | ridpointers[(int) RID_EXTERN] = get_identifier ("extern"); |
8d08fdba | 753 | ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef"); |
8d08fdba | 754 | ridpointers[(int) RID_REGISTER] = get_identifier ("register"); |
8eeda2ec | 755 | ridpointers[(int) RID_COMPLEX] = get_identifier ("__complex"); |
8d08fdba | 756 | |
e92cc029 | 757 | /* C++ extensions. These are probably not correctly named. */ |
8d08fdba | 758 | ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t"); |
8d08fdba MS |
759 | class_type_node = build_int_2 (class_type, 0); |
760 | TREE_TYPE (class_type_node) = class_type_node; | |
761 | ridpointers[(int) RID_CLASS] = class_type_node; | |
762 | ||
763 | record_type_node = build_int_2 (record_type, 0); | |
764 | TREE_TYPE (record_type_node) = record_type_node; | |
765 | ridpointers[(int) RID_RECORD] = record_type_node; | |
766 | ||
767 | union_type_node = build_int_2 (union_type, 0); | |
768 | TREE_TYPE (union_type_node) = union_type_node; | |
769 | ridpointers[(int) RID_UNION] = union_type_node; | |
770 | ||
771 | enum_type_node = build_int_2 (enum_type, 0); | |
772 | TREE_TYPE (enum_type_node) = enum_type_node; | |
773 | ridpointers[(int) RID_ENUM] = enum_type_node; | |
774 | ||
775 | ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual"); | |
db5ae43f | 776 | ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit"); |
9a469008 | 777 | ridpointers[(int) RID_EXPORT] = get_identifier ("export"); |
8d08fdba | 778 | ridpointers[(int) RID_FRIEND] = get_identifier ("friend"); |
8d08fdba MS |
779 | |
780 | ridpointers[(int) RID_PUBLIC] = get_identifier ("public"); | |
8d08fdba | 781 | ridpointers[(int) RID_PRIVATE] = get_identifier ("private"); |
8d08fdba | 782 | ridpointers[(int) RID_PROTECTED] = get_identifier ("protected"); |
a4443a08 | 783 | ridpointers[(int) RID_TEMPLATE] = get_identifier ("template"); |
e92cc029 | 784 | /* This is for ANSI C++. */ |
8d08fdba | 785 | ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable"); |
8d08fdba | 786 | |
898600d5 MM |
787 | /* Create the built-in __null node. Note that we can't yet call for |
788 | type_for_size here because integer_type_node and so forth are not | |
789 | set up. Therefore, we don't set the type of these nodes until | |
790 | init_decl_processing. */ | |
03d0f4af | 791 | null_node = build_int_2 (0, 0); |
d11ad92e | 792 | ridpointers[RID_NULL] = null_node; |
c73964b2 | 793 | |
8d08fdba MS |
794 | opname_tab[(int) COMPONENT_REF] = "->"; |
795 | opname_tab[(int) MEMBER_REF] = "->*"; | |
6467930b | 796 | opname_tab[(int) INDIRECT_REF] = "*"; |
8d08fdba MS |
797 | opname_tab[(int) ARRAY_REF] = "[]"; |
798 | opname_tab[(int) MODIFY_EXPR] = "="; | |
b3ab27f3 | 799 | opname_tab[(int) INIT_EXPR] = "="; |
8d08fdba MS |
800 | opname_tab[(int) NEW_EXPR] = "new"; |
801 | opname_tab[(int) DELETE_EXPR] = "delete"; | |
a28e3c7f MS |
802 | opname_tab[(int) VEC_NEW_EXPR] = "new []"; |
803 | opname_tab[(int) VEC_DELETE_EXPR] = "delete []"; | |
6467930b | 804 | opname_tab[(int) COND_EXPR] = "?:"; |
8d08fdba MS |
805 | opname_tab[(int) CALL_EXPR] = "()"; |
806 | opname_tab[(int) PLUS_EXPR] = "+"; | |
807 | opname_tab[(int) MINUS_EXPR] = "-"; | |
808 | opname_tab[(int) MULT_EXPR] = "*"; | |
809 | opname_tab[(int) TRUNC_DIV_EXPR] = "/"; | |
810 | opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)"; | |
811 | opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)"; | |
812 | opname_tab[(int) ROUND_DIV_EXPR] = "(round /)"; | |
813 | opname_tab[(int) TRUNC_MOD_EXPR] = "%"; | |
814 | opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)"; | |
815 | opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)"; | |
816 | opname_tab[(int) ROUND_MOD_EXPR] = "(round %)"; | |
2adeacc9 | 817 | opname_tab[(int) EXACT_DIV_EXPR] = "/"; |
8d08fdba MS |
818 | opname_tab[(int) NEGATE_EXPR] = "-"; |
819 | opname_tab[(int) MIN_EXPR] = "<?"; | |
820 | opname_tab[(int) MAX_EXPR] = ">?"; | |
821 | opname_tab[(int) ABS_EXPR] = "abs"; | |
822 | opname_tab[(int) FFS_EXPR] = "ffs"; | |
823 | opname_tab[(int) LSHIFT_EXPR] = "<<"; | |
824 | opname_tab[(int) RSHIFT_EXPR] = ">>"; | |
825 | opname_tab[(int) BIT_IOR_EXPR] = "|"; | |
826 | opname_tab[(int) BIT_XOR_EXPR] = "^"; | |
827 | opname_tab[(int) BIT_AND_EXPR] = "&"; | |
828 | opname_tab[(int) BIT_ANDTC_EXPR] = "&~"; | |
829 | opname_tab[(int) BIT_NOT_EXPR] = "~"; | |
830 | opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&"; | |
831 | opname_tab[(int) TRUTH_ORIF_EXPR] = "||"; | |
832 | opname_tab[(int) TRUTH_AND_EXPR] = "strict &&"; | |
833 | opname_tab[(int) TRUTH_OR_EXPR] = "strict ||"; | |
834 | opname_tab[(int) TRUTH_NOT_EXPR] = "!"; | |
835 | opname_tab[(int) LT_EXPR] = "<"; | |
836 | opname_tab[(int) LE_EXPR] = "<="; | |
837 | opname_tab[(int) GT_EXPR] = ">"; | |
838 | opname_tab[(int) GE_EXPR] = ">="; | |
839 | opname_tab[(int) EQ_EXPR] = "=="; | |
840 | opname_tab[(int) NE_EXPR] = "!="; | |
841 | opname_tab[(int) IN_EXPR] = "in"; | |
6467930b MS |
842 | opname_tab[(int) RANGE_EXPR] = "..."; |
843 | opname_tab[(int) CONVERT_EXPR] = "+"; | |
844 | opname_tab[(int) ADDR_EXPR] = "&"; | |
8d08fdba MS |
845 | opname_tab[(int) PREDECREMENT_EXPR] = "--"; |
846 | opname_tab[(int) PREINCREMENT_EXPR] = "++"; | |
847 | opname_tab[(int) POSTDECREMENT_EXPR] = "--"; | |
848 | opname_tab[(int) POSTINCREMENT_EXPR] = "++"; | |
849 | opname_tab[(int) COMPOUND_EXPR] = ","; | |
850 | ||
851 | assignop_tab[(int) NOP_EXPR] = "="; | |
852 | assignop_tab[(int) PLUS_EXPR] = "+="; | |
853 | assignop_tab[(int) CONVERT_EXPR] = "+="; | |
854 | assignop_tab[(int) MINUS_EXPR] = "-="; | |
855 | assignop_tab[(int) NEGATE_EXPR] = "-="; | |
856 | assignop_tab[(int) MULT_EXPR] = "*="; | |
857 | assignop_tab[(int) INDIRECT_REF] = "*="; | |
858 | assignop_tab[(int) TRUNC_DIV_EXPR] = "/="; | |
859 | assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)"; | |
860 | assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)"; | |
861 | assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)"; | |
862 | assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)"; | |
863 | assignop_tab[(int) TRUNC_MOD_EXPR] = "%="; | |
864 | assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)"; | |
865 | assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)"; | |
866 | assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)"; | |
867 | assignop_tab[(int) MIN_EXPR] = "<?="; | |
868 | assignop_tab[(int) MAX_EXPR] = ">?="; | |
869 | assignop_tab[(int) LSHIFT_EXPR] = "<<="; | |
870 | assignop_tab[(int) RSHIFT_EXPR] = ">>="; | |
871 | assignop_tab[(int) BIT_IOR_EXPR] = "|="; | |
872 | assignop_tab[(int) BIT_XOR_EXPR] = "^="; | |
873 | assignop_tab[(int) BIT_AND_EXPR] = "&="; | |
874 | assignop_tab[(int) ADDR_EXPR] = "&="; | |
875 | ||
876 | init_filename_times (); | |
877 | ||
878 | /* Some options inhibit certain reserved words. | |
879 | Clear those words out of the hash table so they won't be recognized. */ | |
880 | #define UNSET_RESERVED_WORD(STRING) \ | |
881 | do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \ | |
882 | if (s) s->name = ""; } while (0) | |
883 | ||
8d2733ca MS |
884 | #if 0 |
885 | /* let's parse things, and if they use it, then give them an error. */ | |
6467930b | 886 | if (!flag_exceptions) |
8d08fdba | 887 | { |
8d2733ca MS |
888 | UNSET_RESERVED_WORD ("throw"); |
889 | UNSET_RESERVED_WORD ("try"); | |
8d08fdba MS |
890 | UNSET_RESERVED_WORD ("catch"); |
891 | } | |
8d2733ca | 892 | #endif |
8d08fdba | 893 | |
9e9ff709 | 894 | if (!flag_rtti || flag_no_gnu_keywords) |
8d08fdba MS |
895 | { |
896 | UNSET_RESERVED_WORD ("classof"); | |
897 | UNSET_RESERVED_WORD ("headof"); | |
898 | } | |
5427d758 | 899 | |
e1cd6e56 | 900 | if (flag_no_asm || flag_no_gnu_keywords) |
8d08fdba | 901 | UNSET_RESERVED_WORD ("typeof"); |
e1cd6e56 | 902 | if (! flag_operator_names) |
db5ae43f MS |
903 | { |
904 | /* These are new ANSI keywords that may break code. */ | |
905 | UNSET_RESERVED_WORD ("and"); | |
79ff2c6c | 906 | UNSET_RESERVED_WORD ("and_eq"); |
db5ae43f MS |
907 | UNSET_RESERVED_WORD ("bitand"); |
908 | UNSET_RESERVED_WORD ("bitor"); | |
909 | UNSET_RESERVED_WORD ("compl"); | |
910 | UNSET_RESERVED_WORD ("not"); | |
79ff2c6c | 911 | UNSET_RESERVED_WORD ("not_eq"); |
db5ae43f | 912 | UNSET_RESERVED_WORD ("or"); |
79ff2c6c | 913 | UNSET_RESERVED_WORD ("or_eq"); |
db5ae43f | 914 | UNSET_RESERVED_WORD ("xor"); |
79ff2c6c | 915 | UNSET_RESERVED_WORD ("xor_eq"); |
db5ae43f | 916 | } |
8d08fdba | 917 | |
2b2a3531 | 918 | token_count = init_cpp_parse (); |
8d08fdba | 919 | interface_unknown = 1; |
a755ad1c | 920 | |
9cd64686 MM |
921 | ggc_add_tree_root (ansi_opname, LAST_CPLUS_TREE_CODE); |
922 | ggc_add_tree_root (ansi_assopname, LAST_CPLUS_TREE_CODE); | |
f3cdb9c6 | 923 | ggc_add_string_root (&internal_filename, 1); |
9cd64686 MM |
924 | ggc_add_tree_root (ridpointers, RID_MAX); |
925 | ggc_add_tree_root (&defarg_fns, 1); | |
926 | ggc_add_tree_root (&defarg_parm, 1); | |
927 | ggc_add_tree_root (&this_filename_time, 1); | |
928 | ggc_add_tree_root (&filename_times, 1); | |
87e3dbc9 MM |
929 | ggc_add_root (&impl_file_chain, 1, sizeof (impl_file_chain), |
930 | mark_impl_file_chain); | |
a755ad1c | 931 | return filename; |
8d08fdba MS |
932 | } |
933 | ||
2b2a3531 DB |
934 | void |
935 | finish_parse () | |
936 | { | |
937 | #if USE_CPPLIB | |
938 | cpp_finish (&parse_in); | |
1b87232a | 939 | errorcount += parse_in.errors; |
2b2a3531 DB |
940 | #else |
941 | fclose (finput); | |
942 | #endif | |
943 | } | |
944 | ||
8d08fdba MS |
945 | void |
946 | reinit_parse_for_function () | |
947 | { | |
948 | current_base_init_list = NULL_TREE; | |
949 | current_member_init_list = NULL_TREE; | |
950 | } | |
951 | \f | |
f9c4f105 | 952 | inline void |
8d08fdba MS |
953 | yyprint (file, yychar, yylval) |
954 | FILE *file; | |
955 | int yychar; | |
956 | YYSTYPE yylval; | |
957 | { | |
958 | tree t; | |
959 | switch (yychar) | |
960 | { | |
961 | case IDENTIFIER: | |
962 | case TYPENAME: | |
963 | case TYPESPEC: | |
964 | case PTYPENAME: | |
074917ba | 965 | case PFUNCNAME: |
8d08fdba MS |
966 | case IDENTIFIER_DEFN: |
967 | case TYPENAME_DEFN: | |
968 | case PTYPENAME_DEFN: | |
8d08fdba MS |
969 | case SCSPEC: |
970 | case PRE_PARSED_CLASS_DECL: | |
971 | t = yylval.ttype; | |
11686454 | 972 | if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL) |
fc378698 | 973 | { |
430bb96b | 974 | fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t))); |
fc378698 MS |
975 | break; |
976 | } | |
8d08fdba MS |
977 | my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224); |
978 | if (IDENTIFIER_POINTER (t)) | |
979 | fprintf (file, " `%s'", IDENTIFIER_POINTER (t)); | |
980 | break; | |
1ceb5ff3 | 981 | |
8d08fdba MS |
982 | case AGGR: |
983 | if (yylval.ttype == class_type_node) | |
984 | fprintf (file, " `class'"); | |
985 | else if (yylval.ttype == record_type_node) | |
986 | fprintf (file, " `struct'"); | |
987 | else if (yylval.ttype == union_type_node) | |
988 | fprintf (file, " `union'"); | |
989 | else if (yylval.ttype == enum_type_node) | |
990 | fprintf (file, " `enum'"); | |
8d08fdba MS |
991 | else |
992 | my_friendly_abort (80); | |
993 | break; | |
1ceb5ff3 JM |
994 | |
995 | case CONSTANT: | |
996 | t = yylval.ttype; | |
997 | if (TREE_CODE (t) == INTEGER_CST) | |
998 | fprintf (file, | |
999 | #if HOST_BITS_PER_WIDE_INT == 64 | |
1000 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
1001 | " 0x%x%016x", | |
1002 | #else | |
1003 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG | |
1004 | " 0x%lx%016lx", | |
1005 | #else | |
1006 | " 0x%llx%016llx", | |
1007 | #endif | |
1008 | #endif | |
1009 | #else | |
1010 | #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT | |
1011 | " 0x%lx%08lx", | |
1012 | #else | |
1013 | " 0x%x%08x", | |
1014 | #endif | |
1015 | #endif | |
1016 | TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t)); | |
1017 | break; | |
8d08fdba MS |
1018 | } |
1019 | } | |
1020 | ||
5566b478 | 1021 | #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH) |
8d08fdba | 1022 | static int *reduce_count; |
5566b478 MS |
1023 | #endif |
1024 | ||
8d08fdba MS |
1025 | int *token_count; |
1026 | ||
72b7eeff | 1027 | #if 0 |
8d08fdba MS |
1028 | #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0])) |
1029 | #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0])) | |
72b7eeff | 1030 | #endif |
8d08fdba | 1031 | |
8d08fdba | 1032 | #ifdef GATHER_STATISTICS |
72b7eeff | 1033 | #ifdef REDUCE_LENGTH |
8d08fdba MS |
1034 | void |
1035 | yyhook (yyn) | |
1036 | int yyn; | |
1037 | { | |
1038 | reduce_count[yyn] += 1; | |
1039 | } | |
8d08fdba MS |
1040 | |
1041 | static int | |
1042 | reduce_cmp (p, q) | |
1043 | int *p, *q; | |
1044 | { | |
1045 | return reduce_count[*q] - reduce_count[*p]; | |
1046 | } | |
1047 | ||
1048 | static int | |
1049 | token_cmp (p, q) | |
1050 | int *p, *q; | |
1051 | { | |
1052 | return token_count[*q] - token_count[*p]; | |
1053 | } | |
8926095f | 1054 | #endif |
72b7eeff | 1055 | #endif |
8d08fdba MS |
1056 | |
1057 | void | |
1058 | print_parse_statistics () | |
1059 | { | |
1060 | #ifdef GATHER_STATISTICS | |
72b7eeff | 1061 | #ifdef REDUCE_LENGTH |
8d08fdba MS |
1062 | #if YYDEBUG != 0 |
1063 | int i; | |
1064 | int maxlen = REDUCE_LENGTH; | |
1065 | unsigned *sorted; | |
1066 | ||
1067 | if (reduce_count[-1] == 0) | |
1068 | return; | |
1069 | ||
1070 | if (TOKEN_LENGTH > REDUCE_LENGTH) | |
1071 | maxlen = TOKEN_LENGTH; | |
1072 | sorted = (unsigned *) alloca (sizeof (int) * maxlen); | |
1073 | ||
1074 | for (i = 0; i < TOKEN_LENGTH; i++) | |
1075 | sorted[i] = i; | |
1076 | qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp); | |
1077 | for (i = 0; i < TOKEN_LENGTH; i++) | |
1078 | { | |
e92cc029 MS |
1079 | int idx = sorted[i]; |
1080 | if (token_count[idx] == 0) | |
8d08fdba | 1081 | break; |
e92cc029 | 1082 | if (token_count[idx] < token_count[-1]) |
8d08fdba MS |
1083 | break; |
1084 | fprintf (stderr, "token %d, `%s', count = %d\n", | |
e92cc029 | 1085 | idx, yytname[YYTRANSLATE (idx)], token_count[idx]); |
8d08fdba MS |
1086 | } |
1087 | fprintf (stderr, "\n"); | |
1088 | for (i = 0; i < REDUCE_LENGTH; i++) | |
1089 | sorted[i] = i; | |
1090 | qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp); | |
1091 | for (i = 0; i < REDUCE_LENGTH; i++) | |
1092 | { | |
e92cc029 MS |
1093 | int idx = sorted[i]; |
1094 | if (reduce_count[idx] == 0) | |
8d08fdba | 1095 | break; |
e92cc029 | 1096 | if (reduce_count[idx] < reduce_count[-1]) |
8d08fdba MS |
1097 | break; |
1098 | fprintf (stderr, "rule %d, line %d, count = %d\n", | |
e92cc029 | 1099 | idx, yyrline[idx], reduce_count[idx]); |
8d08fdba MS |
1100 | } |
1101 | fprintf (stderr, "\n"); | |
1102 | #endif | |
1103 | #endif | |
72b7eeff | 1104 | #endif |
8d08fdba MS |
1105 | } |
1106 | ||
1107 | /* Sets the value of the 'yydebug' variable to VALUE. | |
1108 | This is a function so we don't have to have YYDEBUG defined | |
1109 | in order to build the compiler. */ | |
e92cc029 | 1110 | |
8d08fdba MS |
1111 | void |
1112 | set_yydebug (value) | |
1113 | int value; | |
1114 | { | |
1115 | #if YYDEBUG != 0 | |
1116 | extern int yydebug; | |
1117 | yydebug = value; | |
1118 | #else | |
8251199e | 1119 | warning ("YYDEBUG not defined."); |
8d08fdba MS |
1120 | #endif |
1121 | } | |
1122 | ||
8d08fdba | 1123 | \f |
87e3dbc9 | 1124 | /* Mark ARG (which is really a struct impl_files **) for GC. */ |
8d08fdba | 1125 | |
87e3dbc9 MM |
1126 | static void |
1127 | mark_impl_file_chain (arg) | |
1128 | void *arg; | |
8d08fdba | 1129 | { |
87e3dbc9 | 1130 | struct impl_files *ifs; |
8d08fdba | 1131 | |
87e3dbc9 | 1132 | ifs = *(struct impl_files **) arg; |
01fba8d9 RH |
1133 | while (ifs) |
1134 | { | |
1135 | ggc_mark_string (ifs->filename); | |
1136 | ifs = ifs->next; | |
1137 | } | |
87e3dbc9 | 1138 | } |
8d08fdba MS |
1139 | |
1140 | /* Helper function to load global variables with interface | |
1141 | information. */ | |
e92cc029 | 1142 | |
8d08fdba MS |
1143 | void |
1144 | extract_interface_info () | |
1145 | { | |
1146 | tree fileinfo = 0; | |
1147 | ||
1148 | if (flag_alt_external_templates) | |
1149 | { | |
1150 | struct tinst_level *til = tinst_for_decl (); | |
1151 | ||
1152 | if (til) | |
1153 | fileinfo = get_time_identifier (til->file); | |
1154 | } | |
1155 | if (!fileinfo) | |
1156 | fileinfo = get_time_identifier (input_filename); | |
f181d4ae | 1157 | fileinfo = TIME_IDENTIFIER_FILEINFO (fileinfo); |
8d08fdba | 1158 | interface_only = TREE_INT_CST_LOW (fileinfo); |
5566b478 | 1159 | interface_unknown = TREE_INT_CST_HIGH (fileinfo); |
8d08fdba MS |
1160 | } |
1161 | ||
51c184be | 1162 | /* Return nonzero if S is not considered part of an |
8d08fdba | 1163 | INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */ |
e92cc029 | 1164 | |
8d08fdba MS |
1165 | static int |
1166 | interface_strcmp (s) | |
d8e178a0 | 1167 | const char *s; |
8d08fdba MS |
1168 | { |
1169 | /* Set the interface/implementation bits for this scope. */ | |
1170 | struct impl_files *ifiles; | |
d8e178a0 | 1171 | const char *s1; |
8d08fdba | 1172 | |
8d08fdba MS |
1173 | for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next) |
1174 | { | |
d8e178a0 | 1175 | const char *t1 = ifiles->filename; |
8d08fdba MS |
1176 | s1 = s; |
1177 | ||
1178 | if (*s1 != *t1 || *s1 == 0) | |
1179 | continue; | |
1180 | ||
1181 | while (*s1 == *t1 && *s1 != 0) | |
1182 | s1++, t1++; | |
1183 | ||
1184 | /* A match. */ | |
1185 | if (*s1 == *t1) | |
1186 | return 0; | |
1187 | ||
1188 | /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */ | |
1189 | if (index (s1, '.') || index (t1, '.')) | |
1190 | continue; | |
1191 | ||
1192 | if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.') | |
1193 | continue; | |
1194 | ||
1195 | /* A match. */ | |
1196 | return 0; | |
1197 | } | |
1198 | ||
1199 | /* No matches. */ | |
1200 | return 1; | |
1201 | } | |
1202 | ||
1d02ac83 JM |
1203 | static void |
1204 | cp_pragma_interface (main_filename) | |
1205 | char *main_filename; | |
1206 | { | |
1207 | tree fileinfo | |
1208 | = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename)); | |
1209 | ||
1210 | if (impl_file_chain == 0) | |
1211 | { | |
1212 | /* If this is zero at this point, then we are | |
1213 | auto-implementing. */ | |
1214 | if (main_input_filename == 0) | |
1215 | main_input_filename = input_filename; | |
1216 | ||
1217 | #ifdef AUTO_IMPLEMENT | |
1218 | filename = file_name_nondirectory (main_input_filename); | |
1219 | fi = get_time_identifier (filename); | |
1220 | fi = TIME_IDENTIFIER_FILEINFO (fi); | |
1221 | TREE_INT_CST_LOW (fi) = 0; | |
1222 | TREE_INT_CST_HIGH (fi) = 1; | |
1223 | /* Get default. */ | |
87e3dbc9 MM |
1224 | impl_file_chain |
1225 | = (struct impl_files *) xmalloc (sizeof (struct impl_files)); | |
354f0b04 | 1226 | impl_file_chain->filename = ggc_alloc_string (filename, -1); |
1d02ac83 JM |
1227 | impl_file_chain->next = 0; |
1228 | #endif | |
1229 | } | |
1230 | ||
1231 | interface_only = interface_strcmp (main_filename); | |
1232 | #ifdef MULTIPLE_SYMBOL_SPACES | |
1233 | if (! interface_only) | |
1234 | interface_unknown = 0; | |
1235 | #else /* MULTIPLE_SYMBOL_SPACES */ | |
1236 | interface_unknown = 0; | |
1237 | #endif /* MULTIPLE_SYMBOL_SPACES */ | |
1238 | TREE_INT_CST_LOW (fileinfo) = interface_only; | |
1239 | TREE_INT_CST_HIGH (fileinfo) = interface_unknown; | |
1240 | } | |
1241 | ||
777ffbda JM |
1242 | /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME. |
1243 | We used to only allow this at toplevel, but that restriction was buggy | |
1244 | in older compilers and it seems reasonable to allow it in the headers | |
1245 | themselves, too. It only needs to precede the matching #p interface. | |
1246 | ||
1247 | We don't touch interface_only or interface_unknown; the user must specify | |
1248 | a matching #p interface for this to have any effect. */ | |
1249 | ||
1d02ac83 JM |
1250 | static void |
1251 | cp_pragma_implementation (main_filename) | |
1252 | char *main_filename; | |
1253 | { | |
777ffbda JM |
1254 | struct impl_files *ifiles = impl_file_chain; |
1255 | for (; ifiles; ifiles = ifiles->next) | |
1d02ac83 | 1256 | { |
777ffbda JM |
1257 | if (! strcmp (ifiles->filename, main_filename)) |
1258 | break; | |
1d02ac83 | 1259 | } |
777ffbda | 1260 | if (ifiles == 0) |
1d02ac83 | 1261 | { |
777ffbda JM |
1262 | ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files)); |
1263 | ifiles->filename = ggc_alloc_string (main_filename, -1); | |
1264 | ifiles->next = impl_file_chain; | |
1265 | impl_file_chain = ifiles; | |
1d02ac83 | 1266 | } |
1d02ac83 | 1267 | } |
8d08fdba | 1268 | \f |
f181d4ae MM |
1269 | /* Set up the state required to correctly handle the definition of the |
1270 | inline function whose preparsed state has been saved in PI. */ | |
1271 | ||
1272 | static void | |
1273 | begin_definition_of_inclass_inline (pi) | |
1274 | struct pending_inline* pi; | |
1275 | { | |
1276 | tree context; | |
1277 | ||
1278 | if (!pi->fndecl) | |
1279 | return; | |
1280 | ||
1281 | /* If this is an inline function in a local class, we must make sure | |
1282 | that we save all pertinent information about the function | |
1283 | surrounding the local class. */ | |
4f1c5b7d | 1284 | context = decl_function_context (pi->fndecl); |
f181d4ae | 1285 | if (context) |
99dccabc | 1286 | push_function_context_to (context); |
f181d4ae | 1287 | |
1946537b | 1288 | feed_input (pi->buf, pi->len, pi->filename, pi->lineno); |
f181d4ae | 1289 | yychar = PRE_PARSED_FUNCTION_DECL; |
87e3dbc9 | 1290 | yylval.pi = pi; |
f181d4ae MM |
1291 | /* Pass back a handle to the rest of the inline functions, so that they |
1292 | can be processed later. */ | |
1293 | DECL_PENDING_INLINE_INFO (pi->fndecl) = 0; | |
59026e79 | 1294 | DECL_PENDING_INLINE_P (pi->fndecl) = 0; |
f181d4ae MM |
1295 | interface_unknown = pi->interface == 1; |
1296 | interface_only = pi->interface == 0; | |
1297 | } | |
1298 | ||
8d08fdba MS |
1299 | /* Called from the top level: if there are any pending inlines to |
1300 | do, set up to process them now. This function sets up the first function | |
51c184be | 1301 | to be parsed; after it has been, the rule for fndef in parse.y will |
8d08fdba | 1302 | call process_next_inline to start working on the next one. */ |
e92cc029 | 1303 | |
8d08fdba MS |
1304 | void |
1305 | do_pending_inlines () | |
1306 | { | |
8d08fdba MS |
1307 | struct pending_inline *t; |
1308 | ||
1309 | /* Oops, we're still dealing with the last batch. */ | |
1310 | if (yychar == PRE_PARSED_FUNCTION_DECL) | |
1311 | return; | |
f376e137 | 1312 | |
8d08fdba MS |
1313 | /* Reverse the pending inline functions, since |
1314 | they were cons'd instead of appended. */ | |
f376e137 | 1315 | { |
9e9ff709 | 1316 | struct pending_inline *prev = 0, *tail; |
f376e137 MS |
1317 | t = pending_inlines; |
1318 | pending_inlines = 0; | |
1319 | ||
1320 | for (; t; t = tail) | |
1321 | { | |
1322 | tail = t->next; | |
eac293a1 MS |
1323 | t->next = prev; |
1324 | t->deja_vu = 1; | |
1325 | prev = t; | |
1326 | } | |
f376e137 MS |
1327 | t = prev; |
1328 | } | |
1329 | ||
1330 | if (t == 0) | |
1331 | return; | |
1332 | ||
8d08fdba | 1333 | /* Now start processing the first inline function. */ |
f181d4ae | 1334 | begin_definition_of_inclass_inline (t); |
8d08fdba MS |
1335 | } |
1336 | ||
8d08fdba MS |
1337 | /* Called from the fndecl rule in the parser when the function just parsed |
1338 | was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from | |
1339 | do_pending_inlines). */ | |
e92cc029 | 1340 | |
8d08fdba | 1341 | void |
87e3dbc9 MM |
1342 | process_next_inline (i) |
1343 | struct pending_inline *i; | |
8d08fdba | 1344 | { |
5566b478 | 1345 | tree context; |
4f1c5b7d | 1346 | context = decl_function_context (i->fndecl); |
5566b478 | 1347 | if (context) |
99dccabc | 1348 | pop_function_context_from (context); |
8d08fdba MS |
1349 | i = i->next; |
1350 | if (yychar == YYEMPTY) | |
1351 | yychar = yylex (); | |
1352 | if (yychar != END_OF_SAVED_INPUT) | |
1353 | { | |
8251199e | 1354 | error ("parse error at end of saved function text"); |
e92cc029 | 1355 | |
8d08fdba | 1356 | /* restore_pending_input will abort unless yychar is either |
e92cc029 | 1357 | END_OF_SAVED_INPUT or YYEMPTY; since we already know we're |
66a6250f | 1358 | hosed, feed back YYEMPTY. */ |
8d08fdba MS |
1359 | } |
1360 | yychar = YYEMPTY; | |
42976354 | 1361 | end_input (); |
8d08fdba | 1362 | if (i) |
f181d4ae | 1363 | begin_definition_of_inclass_inline (i); |
8d08fdba MS |
1364 | else |
1365 | extract_interface_info (); | |
1366 | } | |
1367 | ||
1368 | /* Since inline methods can refer to text which has not yet been seen, | |
1369 | we store the text of the method in a structure which is placed in the | |
1370 | DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL. | |
1371 | After parsing the body of the class definition, the FUNCTION_DECL's are | |
1372 | scanned to see which ones have this field set. Those are then digested | |
1373 | one at a time. | |
1374 | ||
1375 | This function's FUNCTION_DECL will have a bit set in its common so | |
1376 | that we know to watch out for it. */ | |
1377 | ||
1378 | static void | |
1379 | consume_string (this_obstack, matching_char) | |
1380 | register struct obstack *this_obstack; | |
1381 | int matching_char; | |
1382 | { | |
1383 | register int c; | |
66a6250f JM |
1384 | int starting_lineno; |
1385 | ||
1386 | #if USE_CPPLIB | |
1387 | if (cpp_token == CPP_STRING) | |
1388 | { | |
1389 | /* The C preprocessor will warn about newlines in strings. */ | |
1390 | obstack_grow (this_obstack, yy_cur, (yy_lim - yy_cur)); | |
1391 | yy_cur = yy_lim; | |
1392 | lineno = parse_in.lineno; | |
1393 | return; | |
1394 | } | |
1395 | #endif | |
1396 | ||
1397 | starting_lineno = lineno; | |
8d08fdba MS |
1398 | do |
1399 | { | |
1400 | c = getch (); | |
1401 | if (c == EOF) | |
1402 | { | |
1403 | int save_lineno = lineno; | |
1404 | lineno = starting_lineno; | |
1405 | if (matching_char == '"') | |
8251199e | 1406 | error ("end of file encountered inside string constant"); |
8d08fdba | 1407 | else |
8251199e | 1408 | error ("end of file encountered inside character constant"); |
8d08fdba MS |
1409 | lineno = save_lineno; |
1410 | return; | |
1411 | } | |
1412 | if (c == '\\') | |
1413 | { | |
1414 | obstack_1grow (this_obstack, c); | |
1415 | c = getch (); | |
1416 | obstack_1grow (this_obstack, c); | |
1417 | ||
1418 | /* Make sure we continue the loop */ | |
1419 | c = 0; | |
1420 | continue; | |
1421 | } | |
1422 | if (c == '\n') | |
1423 | { | |
1424 | if (pedantic) | |
cab1f180 | 1425 | pedwarn ("ISO C++ forbids newline in string constant"); |
8d08fdba MS |
1426 | lineno++; |
1427 | } | |
1428 | obstack_1grow (this_obstack, c); | |
1429 | } | |
1430 | while (c != matching_char); | |
1431 | } | |
1432 | ||
8d08fdba | 1433 | struct pending_input { |
66a6250f JM |
1434 | int yychar, eof; |
1435 | YYSTYPE yylval; | |
8d08fdba MS |
1436 | struct obstack token_obstack; |
1437 | int first_token; | |
1438 | }; | |
1439 | ||
1440 | struct pending_input * | |
1441 | save_pending_input () | |
1442 | { | |
1443 | struct pending_input *p; | |
1444 | p = (struct pending_input *) xmalloc (sizeof (struct pending_input)); | |
8d08fdba | 1445 | p->yychar = yychar; |
8d08fdba | 1446 | p->yylval = yylval; |
8d08fdba | 1447 | p->eof = end_of_file; |
66a6250f | 1448 | yychar = YYEMPTY; |
8d08fdba MS |
1449 | p->first_token = first_token; |
1450 | p->token_obstack = token_obstack; | |
1451 | ||
1452 | first_token = 0; | |
1453 | gcc_obstack_init (&token_obstack); | |
1454 | end_of_file = 0; | |
1455 | return p; | |
1456 | } | |
1457 | ||
1458 | void | |
1459 | restore_pending_input (p) | |
1460 | struct pending_input *p; | |
1461 | { | |
8d08fdba MS |
1462 | my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230); |
1463 | yychar = p->yychar; | |
8d08fdba | 1464 | yylval = p->yylval; |
8d08fdba MS |
1465 | first_token = p->first_token; |
1466 | obstack_free (&token_obstack, (char *) 0); | |
1467 | token_obstack = p->token_obstack; | |
1468 | end_of_file = p->eof; | |
1469 | free (p); | |
1470 | } | |
1471 | ||
8d08fdba MS |
1472 | /* Unget character CH from the input stream. |
1473 | If RESCAN is non-zero, then we want to `see' this | |
1474 | character as the next input token. */ | |
e92cc029 | 1475 | |
8d08fdba MS |
1476 | void |
1477 | yyungetc (ch, rescan) | |
1478 | int ch; | |
1479 | int rescan; | |
1480 | { | |
1481 | /* Unget a character from the input stream. */ | |
1482 | if (yychar == YYEMPTY || rescan == 0) | |
1483 | { | |
1ceb5ff3 JM |
1484 | /* If we're putting back a brace, undo the change in indent_level |
1485 | from the first time we saw it. */ | |
1486 | if (ch == '{') | |
1487 | indent_level--; | |
1488 | else if (ch == '}') | |
1489 | indent_level++; | |
1490 | ||
66a6250f | 1491 | put_back (ch); |
8d08fdba MS |
1492 | } |
1493 | else | |
1494 | { | |
8d08fdba MS |
1495 | yychar = ch; |
1496 | } | |
1497 | } | |
1498 | ||
42976354 BK |
1499 | void |
1500 | clear_inline_text_obstack () | |
1501 | { | |
1502 | obstack_free (&inline_text_obstack, inline_text_firstobj); | |
1503 | } | |
1504 | ||
8d08fdba MS |
1505 | /* This function stores away the text for an inline function that should |
1506 | be processed later. It decides how much later, and may need to move | |
1507 | the info between obstacks; therefore, the caller should not refer to | |
5566b478 | 1508 | the T parameter after calling this function. */ |
8d08fdba MS |
1509 | |
1510 | static void | |
1511 | store_pending_inline (decl, t) | |
1512 | tree decl; | |
1513 | struct pending_inline *t; | |
1514 | { | |
8d08fdba | 1515 | t->fndecl = decl; |
5566b478 | 1516 | DECL_PENDING_INLINE_INFO (decl) = t; |
59026e79 | 1517 | DECL_PENDING_INLINE_P (decl) = 1; |
8d08fdba MS |
1518 | |
1519 | /* Because we use obstacks, we must process these in precise order. */ | |
5566b478 MS |
1520 | t->next = pending_inlines; |
1521 | pending_inlines = t; | |
8d08fdba MS |
1522 | } |
1523 | ||
8d08fdba MS |
1524 | void |
1525 | reinit_parse_for_method (yychar, decl) | |
1526 | int yychar; | |
1527 | tree decl; | |
1528 | { | |
1529 | int len; | |
1530 | int starting_lineno = lineno; | |
1531 | char *starting_filename = input_filename; | |
1532 | ||
5566b478 | 1533 | reinit_parse_for_block (yychar, &inline_text_obstack); |
8d08fdba MS |
1534 | |
1535 | len = obstack_object_size (&inline_text_obstack); | |
8d08fdba MS |
1536 | if (decl == void_type_node |
1537 | || (current_class_type && TYPE_REDEFINED (current_class_type))) | |
1538 | { | |
1539 | /* Happens when we get two declarations of the same | |
1540 | function in the same scope. */ | |
1541 | char *buf = obstack_finish (&inline_text_obstack); | |
1542 | obstack_free (&inline_text_obstack, buf); | |
1543 | return; | |
1544 | } | |
1545 | else | |
1546 | { | |
1547 | struct pending_inline *t; | |
1548 | char *buf = obstack_finish (&inline_text_obstack); | |
1549 | ||
1550 | t = (struct pending_inline *) obstack_alloc (&inline_text_obstack, | |
1551 | sizeof (struct pending_inline)); | |
1552 | t->lineno = starting_lineno; | |
1553 | t->filename = starting_filename; | |
1554 | t->token = YYEMPTY; | |
1555 | t->token_value = 0; | |
1556 | t->buf = buf; | |
1557 | t->len = len; | |
8d08fdba | 1558 | t->deja_vu = 0; |
5566b478 | 1559 | #if 0 |
8d08fdba | 1560 | if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl)) |
8ccc31eb | 1561 | warn_if_unknown_interface (decl); |
5566b478 | 1562 | #endif |
8d08fdba MS |
1563 | t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2)); |
1564 | store_pending_inline (decl, t); | |
1565 | } | |
1566 | } | |
1567 | ||
5566b478 MS |
1568 | /* Consume a block -- actually, a method beginning |
1569 | with `:' or `{' -- and save it away on the specified obstack. */ | |
8d08fdba | 1570 | |
49c249e1 | 1571 | void |
5566b478 | 1572 | reinit_parse_for_block (pyychar, obstackp) |
f30432d7 | 1573 | int pyychar; |
8d08fdba | 1574 | struct obstack *obstackp; |
8d08fdba | 1575 | { |
66a6250f | 1576 | register int c; |
8d08fdba MS |
1577 | int blev = 1; |
1578 | int starting_lineno = lineno; | |
1579 | char *starting_filename = input_filename; | |
1580 | int len; | |
1581 | int look_for_semicolon = 0; | |
1582 | int look_for_lbrac = 0; | |
1583 | ||
f30432d7 | 1584 | if (pyychar == '{') |
1ceb5ff3 JM |
1585 | { |
1586 | obstack_1grow (obstackp, '{'); | |
1587 | /* We incremented indent_level in yylex; undo that. */ | |
1588 | indent_level--; | |
1589 | } | |
f30432d7 | 1590 | else if (pyychar == '=') |
8d08fdba | 1591 | look_for_semicolon = 1; |
f30432d7 | 1592 | else if (pyychar == ':') |
8d08fdba | 1593 | { |
f30432d7 | 1594 | obstack_1grow (obstackp, pyychar); |
8ebeee52 JM |
1595 | /* Add a space so we don't get confused by ': ::A(20)'. */ |
1596 | obstack_1grow (obstackp, ' '); | |
f30432d7 MS |
1597 | look_for_lbrac = 1; |
1598 | blev = 0; | |
8d08fdba | 1599 | } |
3dcaad8b | 1600 | else if (pyychar == RETURN_KEYWORD) |
f30432d7 MS |
1601 | { |
1602 | obstack_grow (obstackp, "return", 6); | |
1603 | look_for_lbrac = 1; | |
1604 | blev = 0; | |
1605 | } | |
5566b478 | 1606 | else if (pyychar == TRY) |
8d08fdba | 1607 | { |
f30432d7 | 1608 | obstack_grow (obstackp, "try", 3); |
8d08fdba MS |
1609 | look_for_lbrac = 1; |
1610 | blev = 0; | |
1611 | } | |
f30432d7 MS |
1612 | else |
1613 | { | |
5566b478 | 1614 | yyerror ("parse error in method specification"); |
f30432d7 MS |
1615 | obstack_1grow (obstackp, '{'); |
1616 | } | |
8d08fdba | 1617 | |
66a6250f JM |
1618 | c = getch (); |
1619 | ||
8d08fdba MS |
1620 | while (c != EOF) |
1621 | { | |
1622 | int this_lineno = lineno; | |
1623 | ||
0b807ad8 | 1624 | saving_parse_to_obstack = 1; |
8d08fdba | 1625 | c = skip_white_space (c); |
0b807ad8 | 1626 | saving_parse_to_obstack = 0; |
8d08fdba MS |
1627 | |
1628 | /* Don't lose our cool if there are lots of comments. */ | |
1629 | if (lineno == this_lineno + 1) | |
1630 | obstack_1grow (obstackp, '\n'); | |
1631 | else if (lineno == this_lineno) | |
1632 | ; | |
1633 | else if (lineno - this_lineno < 10) | |
1634 | { | |
1635 | int i; | |
1636 | for (i = lineno - this_lineno; i > 0; i--) | |
1637 | obstack_1grow (obstackp, '\n'); | |
1638 | } | |
1639 | else | |
1640 | { | |
1641 | char buf[16]; | |
1642 | sprintf (buf, "\n# %d \"", lineno); | |
1643 | len = strlen (buf); | |
1644 | obstack_grow (obstackp, buf, len); | |
1645 | ||
1646 | len = strlen (input_filename); | |
1647 | obstack_grow (obstackp, input_filename, len); | |
1648 | obstack_1grow (obstackp, '\"'); | |
1649 | obstack_1grow (obstackp, '\n'); | |
1650 | } | |
1651 | ||
1652 | while (c > ' ') /* ASCII dependent... */ | |
1653 | { | |
1654 | obstack_1grow (obstackp, c); | |
1655 | if (c == '{') | |
1656 | { | |
1657 | look_for_lbrac = 0; | |
1658 | blev++; | |
1659 | } | |
1660 | else if (c == '}') | |
1661 | { | |
1662 | blev--; | |
1663 | if (blev == 0 && !look_for_semicolon) | |
f30432d7 MS |
1664 | { |
1665 | if (pyychar == TRY) | |
1666 | { | |
1667 | if (peekyylex () == CATCH) | |
1668 | { | |
1669 | yylex (); | |
1670 | obstack_grow (obstackp, " catch ", 7); | |
1671 | look_for_lbrac = 1; | |
1672 | } | |
1673 | else | |
1674 | { | |
1675 | yychar = '{'; | |
1676 | goto done; | |
1677 | } | |
1678 | } | |
1679 | else | |
1680 | { | |
1681 | goto done; | |
1682 | } | |
1683 | } | |
8d08fdba MS |
1684 | } |
1685 | else if (c == '\\') | |
1686 | { | |
1687 | /* Don't act on the next character...e.g, doing an escaped | |
1688 | double-quote. */ | |
1689 | c = getch (); | |
1690 | if (c == EOF) | |
1691 | { | |
1692 | error_with_file_and_line (starting_filename, | |
1693 | starting_lineno, | |
1694 | "end of file read inside definition"); | |
1695 | goto done; | |
1696 | } | |
1697 | obstack_1grow (obstackp, c); | |
1698 | } | |
1699 | else if (c == '\"') | |
1700 | consume_string (obstackp, c); | |
1701 | else if (c == '\'') | |
1702 | consume_string (obstackp, c); | |
1703 | else if (c == ';') | |
1704 | { | |
1705 | if (look_for_lbrac) | |
1706 | { | |
8251199e | 1707 | error ("function body for constructor missing"); |
8d08fdba MS |
1708 | obstack_1grow (obstackp, '{'); |
1709 | obstack_1grow (obstackp, '}'); | |
1710 | len += 2; | |
1711 | goto done; | |
1712 | } | |
1713 | else if (look_for_semicolon && blev == 0) | |
1714 | goto done; | |
1715 | } | |
1716 | c = getch (); | |
1717 | } | |
1718 | ||
1719 | if (c == EOF) | |
1720 | { | |
1721 | error_with_file_and_line (starting_filename, | |
1722 | starting_lineno, | |
1723 | "end of file read inside definition"); | |
1724 | goto done; | |
1725 | } | |
1726 | else if (c != '\n') | |
1727 | { | |
1728 | obstack_1grow (obstackp, c); | |
1729 | c = getch (); | |
1730 | } | |
1731 | } | |
1732 | done: | |
1733 | obstack_1grow (obstackp, '\0'); | |
1734 | } | |
1735 | ||
42976354 BK |
1736 | /* Consume a no-commas expression -- actually, a default argument -- and |
1737 | save it away on the specified obstack. */ | |
1738 | ||
1739 | static void | |
1740 | reinit_parse_for_expr (obstackp) | |
1741 | struct obstack *obstackp; | |
1742 | { | |
66a6250f | 1743 | register int c; |
42976354 BK |
1744 | int starting_lineno = lineno; |
1745 | char *starting_filename = input_filename; | |
1746 | int len; | |
42976354 BK |
1747 | int plev = 0; |
1748 | ||
66a6250f JM |
1749 | c = getch (); |
1750 | ||
42976354 BK |
1751 | while (c != EOF) |
1752 | { | |
1753 | int this_lineno = lineno; | |
1754 | ||
0b807ad8 | 1755 | saving_parse_to_obstack = 1; |
42976354 | 1756 | c = skip_white_space (c); |
0b807ad8 | 1757 | saving_parse_to_obstack = 0; |
42976354 BK |
1758 | |
1759 | /* Don't lose our cool if there are lots of comments. */ | |
1760 | if (lineno == this_lineno + 1) | |
1761 | obstack_1grow (obstackp, '\n'); | |
1762 | else if (lineno == this_lineno) | |
1763 | ; | |
1764 | else if (lineno - this_lineno < 10) | |
1765 | { | |
1766 | int i; | |
1767 | for (i = lineno - this_lineno; i > 0; --i) | |
1768 | obstack_1grow (obstackp, '\n'); | |
1769 | } | |
1770 | else | |
1771 | { | |
1772 | char buf[16]; | |
1773 | sprintf (buf, "\n# %d \"", lineno); | |
1774 | len = strlen (buf); | |
1775 | obstack_grow (obstackp, buf, len); | |
1776 | ||
1777 | len = strlen (input_filename); | |
1778 | obstack_grow (obstackp, input_filename, len); | |
1779 | obstack_1grow (obstackp, '\"'); | |
1780 | obstack_1grow (obstackp, '\n'); | |
1781 | } | |
1782 | ||
1783 | while (c > ' ') /* ASCII dependent... */ | |
1784 | { | |
1785 | if (plev <= 0 && (c == ')' || c == ',')) | |
1786 | { | |
1787 | put_back (c); | |
1788 | goto done; | |
1789 | } | |
1790 | obstack_1grow (obstackp, c); | |
1791 | if (c == '(' || c == '[') | |
1792 | ++plev; | |
1793 | else if (c == ']' || c == ')') | |
1794 | --plev; | |
1795 | else if (c == '\\') | |
1796 | { | |
1797 | /* Don't act on the next character...e.g, doing an escaped | |
1798 | double-quote. */ | |
1799 | c = getch (); | |
1800 | if (c == EOF) | |
1801 | { | |
1802 | error_with_file_and_line (starting_filename, | |
1803 | starting_lineno, | |
1804 | "end of file read inside definition"); | |
1805 | goto done; | |
1806 | } | |
1807 | obstack_1grow (obstackp, c); | |
1808 | } | |
1809 | else if (c == '\"') | |
1810 | consume_string (obstackp, c); | |
1811 | else if (c == '\'') | |
1812 | consume_string (obstackp, c); | |
1813 | c = getch (); | |
1814 | } | |
1815 | ||
1816 | if (c == EOF) | |
1817 | { | |
1818 | error_with_file_and_line (starting_filename, | |
1819 | starting_lineno, | |
1820 | "end of file read inside definition"); | |
1821 | goto done; | |
1822 | } | |
1823 | else if (c != '\n') | |
1824 | { | |
1825 | obstack_1grow (obstackp, c); | |
1826 | c = getch (); | |
1827 | } | |
1828 | } | |
1829 | done: | |
1830 | obstack_1grow (obstackp, '\0'); | |
1831 | } | |
1832 | ||
1833 | int do_snarf_defarg; | |
1834 | ||
1835 | /* Decide whether the default argument we are about to see should be | |
1836 | gobbled up as text for later parsing. */ | |
1837 | ||
1838 | void | |
1839 | maybe_snarf_defarg () | |
1840 | { | |
1841 | if (current_class_type && TYPE_BEING_DEFINED (current_class_type)) | |
1842 | do_snarf_defarg = 1; | |
1843 | } | |
1844 | ||
42976354 BK |
1845 | tree |
1846 | snarf_defarg () | |
1847 | { | |
1848 | int len; | |
1849 | char *buf; | |
1850 | tree arg; | |
42976354 BK |
1851 | |
1852 | reinit_parse_for_expr (&inline_text_obstack); | |
1853 | len = obstack_object_size (&inline_text_obstack); | |
1854 | buf = obstack_finish (&inline_text_obstack); | |
1855 | ||
42976354 BK |
1856 | arg = make_node (DEFAULT_ARG); |
1857 | DEFARG_LENGTH (arg) = len - 1; | |
1858 | DEFARG_POINTER (arg) = buf; | |
42976354 BK |
1859 | |
1860 | return arg; | |
1861 | } | |
1862 | ||
1863 | /* Called from grokfndecl to note a function decl with unparsed default | |
1864 | arguments for later processing. Also called from grokdeclarator | |
1865 | for function types with unparsed defargs; the call from grokfndecl | |
1866 | will always come second, so we can overwrite the entry from the type. */ | |
1867 | ||
1868 | void | |
1869 | add_defarg_fn (decl) | |
1870 | tree decl; | |
1871 | { | |
1872 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1873 | TREE_VALUE (defarg_fns) = decl; | |
1874 | else | |
cd9f6678 | 1875 | defarg_fns = tree_cons (current_class_type, decl, defarg_fns); |
42976354 BK |
1876 | } |
1877 | ||
1878 | /* Helper for do_pending_defargs. Starts the parsing of a default arg. */ | |
1879 | ||
1880 | static void | |
1881 | feed_defarg (f, p) | |
1882 | tree f, p; | |
1883 | { | |
1884 | tree d = TREE_PURPOSE (p); | |
1946537b JM |
1885 | char *file; |
1886 | int line; | |
42976354 BK |
1887 | if (TREE_CODE (f) == FUNCTION_DECL) |
1888 | { | |
1946537b JM |
1889 | line = DECL_SOURCE_LINE (f); |
1890 | file = DECL_SOURCE_FILE (f); | |
42976354 | 1891 | } |
1946537b JM |
1892 | else |
1893 | { | |
1894 | line = lineno; | |
1895 | file = input_filename; | |
1896 | } | |
1897 | ||
1898 | feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d), file, line); | |
42976354 BK |
1899 | yychar = DEFARG_MARKER; |
1900 | yylval.ttype = p; | |
1901 | } | |
1902 | ||
1903 | /* Helper for do_pending_defargs. Ends the parsing of a default arg. */ | |
1904 | ||
1905 | static void | |
1906 | finish_defarg () | |
1907 | { | |
1908 | if (yychar == YYEMPTY) | |
1909 | yychar = yylex (); | |
1910 | if (yychar != END_OF_SAVED_INPUT) | |
1911 | { | |
8251199e | 1912 | error ("parse error at end of saved function text"); |
42976354 BK |
1913 | |
1914 | /* restore_pending_input will abort unless yychar is either | |
1915 | END_OF_SAVED_INPUT or YYEMPTY; since we already know we're | |
66a6250f | 1916 | hosed, feed back YYEMPTY. */ |
42976354 BK |
1917 | } |
1918 | yychar = YYEMPTY; | |
1919 | end_input (); | |
1920 | } | |
1921 | ||
1922 | /* Main function for deferred parsing of default arguments. Called from | |
1923 | the parser. */ | |
1924 | ||
1925 | void | |
1926 | do_pending_defargs () | |
1927 | { | |
1928 | if (defarg_parm) | |
1929 | finish_defarg (); | |
1930 | ||
1931 | for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns)) | |
1932 | { | |
1933 | tree defarg_fn = TREE_VALUE (defarg_fns); | |
1934 | if (defarg_parm == NULL_TREE) | |
1935 | { | |
42976354 BK |
1936 | push_nested_class (TREE_PURPOSE (defarg_fns), 1); |
1937 | pushlevel (0); | |
22531e51 JM |
1938 | if (TREE_CODE (defarg_fn) == FUNCTION_DECL) |
1939 | maybe_begin_member_template_processing (defarg_fn); | |
42976354 BK |
1940 | |
1941 | if (TREE_CODE (defarg_fn) == FUNCTION_DECL) | |
1942 | { | |
1943 | #if 0 | |
b2bb2710 | 1944 | tree p; |
42976354 BK |
1945 | for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p)) |
1946 | pushdecl (copy_node (p)); | |
1947 | #endif | |
1948 | defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn)); | |
1949 | } | |
1950 | else | |
1951 | defarg_parm = TYPE_ARG_TYPES (defarg_fn); | |
1952 | } | |
1953 | else | |
1954 | defarg_parm = TREE_CHAIN (defarg_parm); | |
1955 | ||
1956 | for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm)) | |
da20811c JM |
1957 | if (TREE_PURPOSE (defarg_parm) |
1958 | && TREE_CODE (TREE_PURPOSE (defarg_parm)) == DEFAULT_ARG) | |
42976354 | 1959 | { |
42976354 BK |
1960 | feed_defarg (defarg_fn, defarg_parm); |
1961 | ||
1962 | /* Return to the parser, which will process this defarg | |
1963 | and call us again. */ | |
1964 | return; | |
1965 | } | |
1966 | ||
22531e51 | 1967 | if (TREE_CODE (defarg_fn) == FUNCTION_DECL) |
b7698cf0 | 1968 | { |
b370501f | 1969 | maybe_end_member_template_processing (); |
b7698cf0 JM |
1970 | check_default_args (defarg_fn); |
1971 | } | |
1972 | ||
42976354 | 1973 | poplevel (0, 0, 0); |
b74a0560 | 1974 | pop_nested_class (); |
42976354 BK |
1975 | } |
1976 | } | |
1977 | ||
8d08fdba MS |
1978 | /* Build a default function named NAME for type TYPE. |
1979 | KIND says what to build. | |
1980 | ||
1981 | When KIND == 0, build default destructor. | |
1982 | When KIND == 1, build virtual destructor. | |
1983 | When KIND == 2, build default constructor. | |
1984 | When KIND == 3, build default X(const X&) constructor. | |
1985 | When KIND == 4, build default X(X&) constructor. | |
1986 | When KIND == 5, build default operator = (const X&). | |
1987 | When KIND == 6, build default operator = (X&). */ | |
1988 | ||
1989 | tree | |
8ccc31eb MS |
1990 | cons_up_default_function (type, full_name, kind) |
1991 | tree type, full_name; | |
8d08fdba MS |
1992 | int kind; |
1993 | { | |
8d08fdba | 1994 | tree declspecs = NULL_TREE; |
a703fb38 | 1995 | tree fn, args = NULL_TREE; |
8d08fdba MS |
1996 | tree argtype; |
1997 | int retref = 0; | |
8ccc31eb | 1998 | tree name = constructor_name (full_name); |
8d08fdba | 1999 | |
8d08fdba MS |
2000 | switch (kind) |
2001 | { | |
2002 | /* Destructors. */ | |
8d08fdba MS |
2003 | case 0: |
2004 | name = build_parse_node (BIT_NOT_EXPR, name); | |
db5ae43f MS |
2005 | args = void_list_node; |
2006 | break; | |
2007 | ||
8d08fdba MS |
2008 | case 2: |
2009 | /* Default constructor. */ | |
2010 | args = void_list_node; | |
8d08fdba MS |
2011 | break; |
2012 | ||
2013 | case 3: | |
91063b51 | 2014 | type = build_qualified_type (type, TYPE_QUAL_CONST); |
8d08fdba MS |
2015 | /* Fall through... */ |
2016 | case 4: | |
2017 | /* According to ARM $12.8, the default copy ctor will be declared, but | |
f376e137 | 2018 | not defined, unless it's needed. */ |
8d08fdba MS |
2019 | argtype = build_reference_type (type); |
2020 | args = tree_cons (NULL_TREE, | |
2021 | build_tree_list (hash_tree_chain (argtype, NULL_TREE), | |
2022 | get_identifier ("_ctor_arg")), | |
2023 | void_list_node); | |
8d08fdba MS |
2024 | break; |
2025 | ||
2026 | case 5: | |
8d08fdba MS |
2027 | case 6: |
2028 | retref = 1; | |
6b5fbb55 | 2029 | declspecs = build_decl_list (NULL_TREE, type); |
8d08fdba | 2030 | |
824b9a4c | 2031 | if (kind == 5) |
91063b51 | 2032 | type = build_qualified_type (type, TYPE_QUAL_CONST); |
824b9a4c | 2033 | |
8d08fdba MS |
2034 | name = ansi_opname [(int) MODIFY_EXPR]; |
2035 | ||
2036 | argtype = build_reference_type (type); | |
2037 | args = tree_cons (NULL_TREE, | |
2038 | build_tree_list (hash_tree_chain (argtype, NULL_TREE), | |
2039 | get_identifier ("_ctor_arg")), | |
2040 | void_list_node); | |
8d08fdba MS |
2041 | break; |
2042 | ||
2043 | default: | |
2044 | my_friendly_abort (59); | |
2045 | } | |
2046 | ||
f376e137 MS |
2047 | declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE], |
2048 | declspecs); | |
8d08fdba MS |
2049 | |
2050 | TREE_PARMLIST (args) = 1; | |
2051 | ||
2052 | { | |
c11b6f21 | 2053 | tree declarator = make_call_declarator (name, args, NULL_TREE, NULL_TREE); |
8d08fdba MS |
2054 | if (retref) |
2055 | declarator = build_parse_node (ADDR_EXPR, declarator); | |
92eca640 | 2056 | |
c11b6f21 | 2057 | fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE); |
8d08fdba MS |
2058 | } |
2059 | ||
2060 | if (fn == void_type_node) | |
2061 | return fn; | |
2062 | ||
d11ad92e MS |
2063 | if (kind > 2) |
2064 | SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn))); | |
2065 | ||
5566b478 | 2066 | #if 0 |
db5ae43f | 2067 | if (processing_template_defn) |
79ff2c6c MS |
2068 | { |
2069 | SET_DECL_IMPLICIT_INSTANTIATION (fn); | |
2070 | repo_template_used (fn); | |
2071 | } | |
5566b478 | 2072 | #endif |
3536cd7e | 2073 | |
fc378698 | 2074 | #if 0 |
db5ae43f MS |
2075 | if (CLASSTYPE_INTERFACE_KNOWN (type)) |
2076 | { | |
2077 | DECL_INTERFACE_KNOWN (fn) = 1; | |
a5894242 MS |
2078 | DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type) |
2079 | && flag_implement_inlines); | |
db5ae43f | 2080 | } |
e8abc66f | 2081 | else |
fc378698 | 2082 | #endif |
e8abc66f | 2083 | DECL_NOT_REALLY_EXTERN (fn) = 1; |
db5ae43f | 2084 | |
5566b478 | 2085 | mark_inline_for_output (fn); |
8d08fdba | 2086 | |
8d08fdba MS |
2087 | #ifdef DEBUG_DEFAULT_FUNCTIONS |
2088 | { char *fn_type = NULL; | |
2089 | tree t = name; | |
2090 | switch (kind) | |
2091 | { | |
2092 | case 0: fn_type = "default destructor"; break; | |
2093 | case 1: fn_type = "virtual destructor"; break; | |
2094 | case 2: fn_type = "default constructor"; break; | |
2095 | case 3: fn_type = "default X(const X&)"; break; | |
2096 | case 4: fn_type = "default X(X&)"; break; | |
2097 | } | |
2098 | if (fn_type) | |
2099 | { | |
2100 | if (TREE_CODE (name) == BIT_NOT_EXPR) | |
2101 | t = TREE_OPERAND (name, 0); | |
2102 | fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type, | |
2103 | IDENTIFIER_POINTER (t), func_buf); | |
2104 | } | |
2105 | } | |
8926095f | 2106 | #endif /* DEBUG_DEFAULT_FUNCTIONS */ |
8d08fdba | 2107 | |
8d08fdba | 2108 | /* Show that this function was generated by the compiler. */ |
700f8a87 | 2109 | SET_DECL_ARTIFICIAL (fn); |
8d08fdba MS |
2110 | |
2111 | return fn; | |
2112 | } | |
2113 | ||
8d08fdba MS |
2114 | /* Heuristic to tell whether the user is missing a semicolon |
2115 | after a struct or enum declaration. Emit an error message | |
2116 | if we know the user has blown it. */ | |
e92cc029 | 2117 | |
8d08fdba MS |
2118 | void |
2119 | check_for_missing_semicolon (type) | |
2120 | tree type; | |
2121 | { | |
2122 | if (yychar < 0) | |
2123 | yychar = yylex (); | |
2124 | ||
00595019 MS |
2125 | if ((yychar > 255 |
2126 | && yychar != SCSPEC | |
2127 | && yychar != IDENTIFIER | |
a80e4195 | 2128 | && yychar != TYPENAME |
b88c08b6 | 2129 | && yychar != CV_QUALIFIER |
a80e4195 | 2130 | && yychar != SELFNAME) |
00595019 | 2131 | || end_of_file) |
8d08fdba MS |
2132 | { |
2133 | if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) | |
8251199e | 2134 | error ("semicolon missing after %s declaration", |
8d08fdba MS |
2135 | TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct"); |
2136 | else | |
8251199e | 2137 | cp_error ("semicolon missing after declaration of `%T'", type); |
8d08fdba MS |
2138 | shadow_tag (build_tree_list (0, type)); |
2139 | } | |
2140 | /* Could probably also hack cases where class { ... } f (); appears. */ | |
2141 | clear_anon_tags (); | |
2142 | } | |
2143 | ||
2144 | void | |
2145 | note_got_semicolon (type) | |
2146 | tree type; | |
2147 | { | |
2148 | if (TREE_CODE_CLASS (TREE_CODE (type)) != 't') | |
2149 | my_friendly_abort (60); | |
7ddedda4 | 2150 | if (CLASS_TYPE_P (type)) |
8d08fdba MS |
2151 | CLASSTYPE_GOT_SEMICOLON (type) = 1; |
2152 | } | |
2153 | ||
2154 | void | |
2155 | note_list_got_semicolon (declspecs) | |
2156 | tree declspecs; | |
2157 | { | |
2158 | tree link; | |
2159 | ||
2160 | for (link = declspecs; link; link = TREE_CHAIN (link)) | |
2161 | { | |
2162 | tree type = TREE_VALUE (link); | |
2163 | if (TREE_CODE_CLASS (TREE_CODE (type)) == 't') | |
2164 | note_got_semicolon (type); | |
2165 | } | |
2166 | clear_anon_tags (); | |
2167 | } | |
2168 | \f | |
1ceb5ff3 JM |
2169 | /* Iff C is a carriage return, warn about it - if appropriate - |
2170 | and return nonzero. */ | |
2171 | static int | |
2172 | whitespace_cr (c) | |
2173 | int c; | |
2174 | { | |
2175 | static int newline_warning = 0; | |
2176 | ||
2177 | if (c == '\r') | |
2178 | { | |
2179 | /* ANSI C says the effects of a carriage return in a source file | |
2180 | are undefined. */ | |
2181 | if (pedantic && !newline_warning) | |
2182 | { | |
2183 | warning ("carriage return in source file"); | |
2184 | warning ("(we only warn about the first carriage return)"); | |
2185 | newline_warning = 1; | |
2186 | } | |
2187 | return 1; | |
2188 | } | |
2189 | return 0; | |
2190 | } | |
2191 | ||
8d08fdba MS |
2192 | /* If C is not whitespace, return C. |
2193 | Otherwise skip whitespace and return first nonwhite char read. */ | |
2194 | ||
2195 | static int | |
2196 | skip_white_space (c) | |
2197 | register int c; | |
2198 | { | |
2199 | for (;;) | |
2200 | { | |
2201 | switch (c) | |
2202 | { | |
1ceb5ff3 JM |
2203 | /* We don't recognize comments here, because |
2204 | cpp output can include / and * consecutively as operators. | |
2205 | Also, there's no need, since cpp removes all comments. */ | |
2206 | ||
8d08fdba | 2207 | case '\n': |
66a6250f JM |
2208 | if (linemode) |
2209 | { | |
2210 | put_back (c); | |
2211 | return EOF; | |
2212 | } | |
8d08fdba MS |
2213 | c = check_newline (); |
2214 | break; | |
2215 | ||
2216 | case ' ': | |
2217 | case '\t': | |
2218 | case '\f': | |
8d08fdba MS |
2219 | case '\v': |
2220 | case '\b': | |
66a6250f JM |
2221 | #if USE_CPPLIB |
2222 | /* While processing a # directive we don't get CPP_HSPACE | |
2223 | tokens, so we also need to handle whitespace the normal way. */ | |
2224 | if (cpp_token == CPP_HSPACE) | |
2225 | c = yy_get_token (); | |
2226 | else | |
2227 | #endif | |
8d08fdba | 2228 | c = getch (); |
8d08fdba MS |
2229 | break; |
2230 | ||
1ceb5ff3 JM |
2231 | case '\r': |
2232 | whitespace_cr (c); | |
2233 | c = getch (); | |
2234 | break; | |
2235 | ||
8d08fdba MS |
2236 | case '\\': |
2237 | c = getch (); | |
2238 | if (c == '\n') | |
2239 | lineno++; | |
2240 | else | |
8251199e | 2241 | error ("stray '\\' in program"); |
8d08fdba MS |
2242 | c = getch (); |
2243 | break; | |
2244 | ||
2245 | default: | |
2246 | return (c); | |
2247 | } | |
2248 | } | |
2249 | } | |
2250 | ||
8d08fdba MS |
2251 | /* Make the token buffer longer, preserving the data in it. |
2252 | P should point to just beyond the last valid character in the old buffer. | |
2253 | The value we return is a pointer to the new buffer | |
2254 | at a place corresponding to P. */ | |
2255 | ||
66a6250f JM |
2256 | static void |
2257 | extend_token_buffer_to (size) | |
2258 | int size; | |
2259 | { | |
2260 | do | |
2261 | maxtoken = maxtoken * 2 + 10; | |
2262 | while (maxtoken < size); | |
2263 | token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2); | |
2264 | } | |
2265 | ||
8d08fdba MS |
2266 | static char * |
2267 | extend_token_buffer (p) | |
d8e178a0 | 2268 | const char *p; |
8d08fdba MS |
2269 | { |
2270 | int offset = p - token_buffer; | |
66a6250f | 2271 | extend_token_buffer_to (offset); |
8d08fdba MS |
2272 | return token_buffer + offset; |
2273 | } | |
2274 | \f | |
1ceb5ff3 JM |
2275 | #if defined HANDLE_PRAGMA |
2276 | /* Local versions of these macros, that can be passed as function pointers. */ | |
2277 | static int | |
2278 | pragma_getc () | |
2279 | { | |
2280 | return getch (); | |
2281 | } | |
2282 | ||
2283 | static void | |
2284 | pragma_ungetc (arg) | |
2285 | int arg; | |
2286 | { | |
2287 | put_back (arg); | |
2288 | } | |
2289 | #endif | |
2290 | ||
8d08fdba | 2291 | static int |
66a6250f JM |
2292 | read_line_number (num) |
2293 | int *num; | |
8d08fdba | 2294 | { |
66a6250f | 2295 | register int token = real_yylex (); |
8d08fdba | 2296 | |
66a6250f JM |
2297 | if (token == CONSTANT |
2298 | && TREE_CODE (yylval.ttype) == INTEGER_CST) | |
ae4d12ca | 2299 | { |
66a6250f JM |
2300 | *num = TREE_INT_CST_LOW (yylval.ttype); |
2301 | return 1; | |
ae4d12ca NC |
2302 | } |
2303 | else | |
66a6250f JM |
2304 | { |
2305 | if (token != END_OF_LINE) | |
2306 | error ("invalid #-line"); | |
2307 | return 0; | |
2308 | } | |
ae4d12ca | 2309 | } |
ae4d12ca | 2310 | |
8d08fdba MS |
2311 | /* At the beginning of a line, increment the line number |
2312 | and process any #-directive on this line. | |
2313 | If the line is a #-directive, read the entire line and return a newline. | |
66a6250f | 2314 | Otherwise, return the line's first non-whitespace character. |
8d08fdba | 2315 | |
66a6250f JM |
2316 | Note that in the case of USE_CPPLIB, we get the whole line as one |
2317 | CPP_DIRECTIVE token. */ | |
d18c083e | 2318 | |
bd6dd845 | 2319 | static int |
8d08fdba MS |
2320 | check_newline () |
2321 | { | |
2322 | register int c; | |
2323 | register int token; | |
66a6250f JM |
2324 | int saw_line; |
2325 | enum { act_none, act_push, act_pop } action; | |
574a0ef5 | 2326 | int action_number, l; |
66a6250f | 2327 | int entering_c_header; |
574a0ef5 | 2328 | char *new_file; |
8d08fdba | 2329 | |
66a6250f | 2330 | restart: |
a28e3c7f MS |
2331 | /* Read first nonwhite char on the line. Do this before incrementing the |
2332 | line number, in case we're at the end of saved text. */ | |
8d08fdba | 2333 | |
66a6250f JM |
2334 | #ifdef USE_CPPLIB |
2335 | c = getch (); | |
2336 | /* In some cases where we're leaving an include file, we can get multiple | |
2337 | CPP_HSPACE tokens in a row, so we need to loop. */ | |
2338 | while (cpp_token == CPP_HSPACE) | |
2339 | c = yy_get_token (); | |
2340 | #else | |
8d08fdba MS |
2341 | do |
2342 | c = getch (); | |
2343 | while (c == ' ' || c == '\t'); | |
66a6250f | 2344 | #endif |
8d08fdba | 2345 | |
a28e3c7f MS |
2346 | lineno++; |
2347 | ||
8d08fdba MS |
2348 | if (c != '#') |
2349 | { | |
66a6250f JM |
2350 | /* Sequences of multiple newlines are very common; optimize them. */ |
2351 | if (c == '\n') | |
2352 | goto restart; | |
2353 | ||
8d08fdba MS |
2354 | /* If not #, return it so caller will use it. */ |
2355 | return c; | |
2356 | } | |
2357 | ||
d18c083e | 2358 | /* Don't read beyond this line. */ |
66a6250f | 2359 | saw_line = 0; |
d18c083e MS |
2360 | linemode = 1; |
2361 | ||
66a6250f JM |
2362 | #if USE_CPPLIB |
2363 | if (cpp_token == CPP_VSPACE) | |
2364 | { | |
2365 | /* Format is "<space> <line number> <filename> <newline>". | |
2366 | Only the line number is interesting, and even that | |
2367 | we can get more efficiently than scanning the line. */ | |
2368 | yy_cur = yy_lim - 1; | |
2369 | lineno = parse_in.lineno - 1; | |
2370 | goto skipline; | |
2371 | } | |
2372 | #endif | |
8d08fdba | 2373 | |
66a6250f | 2374 | token = real_yylex (); |
8d08fdba | 2375 | |
66a6250f | 2376 | if (token == IDENTIFIER) |
8d08fdba | 2377 | { |
66a6250f JM |
2378 | /* If a letter follows, then if the word here is `line', skip |
2379 | it and ignore it; otherwise, ignore the line, with an error | |
2380 | if the word isn't `pragma'. */ | |
2381 | ||
2382 | const char *name = IDENTIFIER_POINTER (yylval.ttype); | |
2383 | ||
2384 | if (!strcmp (name, "pragma")) | |
8d08fdba | 2385 | { |
66a6250f | 2386 | token = real_yylex (); |
1ceb5ff3 JM |
2387 | if (token != IDENTIFIER |
2388 | || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE) | |
2389 | goto skipline; | |
2390 | ||
2391 | /* If this is 1, we handled it; if it's -1, it was one we | |
2392 | wanted but had something wrong with it. Only if it's | |
2393 | 0 was it not handled. */ | |
2394 | if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype))) | |
66a6250f | 2395 | goto skipline; |
51c184be | 2396 | |
ae4d12ca | 2397 | #ifdef HANDLE_PRAGMA |
66a6250f JM |
2398 | /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS |
2399 | (if both are defined), in order to give the back | |
2400 | end a chance to override the interpretation of | |
2401 | SYSV style pragmas. */ | |
1ceb5ff3 | 2402 | if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc, |
66a6250f JM |
2403 | IDENTIFIER_POINTER (yylval.ttype))) |
2404 | goto skipline; | |
ae4d12ca NC |
2405 | #endif /* HANDLE_PRAGMA */ |
2406 | ||
a09a009c | 2407 | #ifdef HANDLE_GENERIC_PRAGMAS |
66a6250f JM |
2408 | if (handle_generic_pragma (token)) |
2409 | goto skipline; | |
a09a009c | 2410 | #endif /* HANDLE_GENERIC_PRAGMAS */ |
ae4d12ca | 2411 | |
66a6250f JM |
2412 | /* Issue a warning message if we have been asked to do so. |
2413 | Ignoring unknown pragmas in system header file unless | |
2414 | an explcit -Wunknown-pragmas has been given. */ | |
2415 | if (warn_unknown_pragmas > 1 | |
2416 | || (warn_unknown_pragmas && ! in_system_header)) | |
2417 | warning ("ignoring pragma: %s", token_buffer); | |
2418 | ||
a82e1b55 | 2419 | goto skipline; |
8d08fdba | 2420 | } |
66a6250f | 2421 | else if (!strcmp (name, "define")) |
8d08fdba | 2422 | { |
66a6250f JM |
2423 | debug_define (lineno, GET_DIRECTIVE_LINE ()); |
2424 | goto skipline; | |
8d08fdba | 2425 | } |
66a6250f | 2426 | else if (!strcmp (name, "undef")) |
8d08fdba | 2427 | { |
66a6250f JM |
2428 | debug_undef (lineno, GET_DIRECTIVE_LINE ()); |
2429 | goto skipline; | |
8d08fdba | 2430 | } |
66a6250f | 2431 | else if (!strcmp (name, "line")) |
8d08fdba | 2432 | { |
66a6250f JM |
2433 | saw_line = 1; |
2434 | token = real_yylex (); | |
2435 | goto linenum; | |
8d08fdba | 2436 | } |
66a6250f | 2437 | else if (!strcmp (name, "ident")) |
8d08fdba | 2438 | { |
66a6250f | 2439 | /* #ident. The pedantic warning is now in cccp.c. */ |
8d08fdba | 2440 | |
66a6250f JM |
2441 | /* Here we have just seen `#ident '. |
2442 | A string constant should follow. */ | |
8d08fdba | 2443 | |
66a6250f JM |
2444 | token = real_yylex (); |
2445 | if (token == END_OF_LINE) | |
2446 | goto skipline; | |
2447 | if (token != STRING | |
2448 | || TREE_CODE (yylval.ttype) != STRING_CST) | |
2449 | { | |
2450 | error ("invalid #ident"); | |
8d08fdba MS |
2451 | goto skipline; |
2452 | } | |
66a6250f JM |
2453 | |
2454 | if (! flag_no_ident) | |
8d08fdba | 2455 | { |
66a6250f JM |
2456 | #ifdef ASM_OUTPUT_IDENT |
2457 | ASM_OUTPUT_IDENT (asm_out_file, | |
2458 | TREE_STRING_POINTER (yylval.ttype)); | |
2459 | #endif | |
8d08fdba | 2460 | } |
66a6250f JM |
2461 | |
2462 | /* Skip the rest of this line. */ | |
2463 | goto skipline; | |
8d08fdba | 2464 | } |
66a6250f JM |
2465 | |
2466 | error ("undefined or invalid # directive `%s'", name); | |
8d08fdba MS |
2467 | goto skipline; |
2468 | } | |
2469 | ||
8d08fdba MS |
2470 | /* If the # is the only nonwhite char on the line, |
2471 | just ignore it. Check the new newline. */ | |
66a6250f | 2472 | if (token == END_OF_LINE) |
d18c083e | 2473 | goto skipline; |
8d08fdba | 2474 | |
66a6250f JM |
2475 | linenum: |
2476 | /* Here we have either `#line' or `# <nonletter>'. | |
2477 | In either case, it should be a line number; a digit should follow. */ | |
8d08fdba | 2478 | |
66a6250f JM |
2479 | if (token != CONSTANT |
2480 | || TREE_CODE (yylval.ttype) != INTEGER_CST) | |
8d08fdba | 2481 | { |
66a6250f JM |
2482 | error ("invalid #-line"); |
2483 | goto skipline; | |
2484 | } | |
8d08fdba | 2485 | |
66a6250f JM |
2486 | /* subtract one, because it is the following line that |
2487 | gets the specified number */ | |
8d08fdba | 2488 | |
66a6250f | 2489 | l = TREE_INT_CST_LOW (yylval.ttype) - 1; |
8d08fdba | 2490 | |
66a6250f JM |
2491 | /* More follows: it must be a string constant (filename). |
2492 | It would be neat to use cpplib to quickly process the string, but | |
2493 | (1) we don't have a handy tokenization of the string, and | |
2494 | (2) I don't know how well that would work in the presense | |
2495 | of filenames that contain wide characters. */ | |
8d08fdba | 2496 | |
0b807ad8 | 2497 | if (saw_line || saving_parse_to_obstack) |
66a6250f JM |
2498 | { |
2499 | /* Don't treat \ as special if we are processing #line 1 "...". | |
0b807ad8 MK |
2500 | If you want it to be treated specially, use # 1 "...". Also |
2501 | ignore these if saving to an obstack for later parsing. */ | |
66a6250f JM |
2502 | ignore_escape_flag = 1; |
2503 | } | |
069f7cf2 | 2504 | |
66a6250f JM |
2505 | /* Read the string constant. */ |
2506 | token = real_yylex (); | |
069f7cf2 | 2507 | |
66a6250f | 2508 | ignore_escape_flag = 0; |
8d08fdba | 2509 | |
66a6250f JM |
2510 | if (token == END_OF_LINE) |
2511 | { | |
2512 | /* No more: store the line number and check following line. */ | |
2513 | lineno = l; | |
2514 | goto skipline; | |
2515 | } | |
8d08fdba | 2516 | |
66a6250f JM |
2517 | if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) |
2518 | { | |
2519 | error ("invalid #line"); | |
2520 | goto skipline; | |
2521 | } | |
8d08fdba | 2522 | |
66a6250f JM |
2523 | /* Changing files again. This means currently collected time |
2524 | is charged against header time, and body time starts back at 0. */ | |
2525 | if (flag_detailed_statistics) | |
2526 | { | |
2527 | int this_time = my_get_run_time (); | |
2528 | tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype)); | |
2529 | header_time += this_time - body_time; | |
2530 | TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time)) | |
2531 | += this_time - body_time; | |
2532 | this_filename_time = time_identifier; | |
2533 | body_time = this_time; | |
2534 | } | |
2535 | ||
574a0ef5 | 2536 | new_file = TREE_STRING_POINTER (yylval.ttype); |
8d08fdba | 2537 | |
574a0ef5 | 2538 | GNU_xref_file (new_file); |
66a6250f JM |
2539 | |
2540 | if (main_input_filename == 0) | |
2541 | { | |
2542 | struct impl_files *ifiles = impl_file_chain; | |
8d08fdba | 2543 | |
66a6250f | 2544 | if (ifiles) |
28cbf42c | 2545 | { |
66a6250f JM |
2546 | while (ifiles->next) |
2547 | ifiles = ifiles->next; | |
574a0ef5 | 2548 | ifiles->filename = file_name_nondirectory (new_file); |
28cbf42c | 2549 | } |
8d08fdba | 2550 | |
574a0ef5 | 2551 | main_input_filename = new_file; |
66a6250f | 2552 | } |
8d08fdba | 2553 | |
66a6250f JM |
2554 | action = act_none; |
2555 | action_number = 0; | |
8d08fdba | 2556 | |
1ceb5ff3 JM |
2557 | /* Each change of file name |
2558 | reinitializes whether we are now in a system header. */ | |
2559 | in_system_header = 0; | |
2560 | entering_c_header = 0; | |
2561 | ||
574a0ef5 | 2562 | if (!read_line_number (&action_number) && input_file_stack) |
66a6250f | 2563 | { |
574a0ef5 MM |
2564 | input_file_stack->name = input_filename = new_file; |
2565 | input_file_stack->line = lineno = l; | |
66a6250f | 2566 | } |
8d08fdba | 2567 | |
66a6250f JM |
2568 | /* `1' after file name means entering new file. |
2569 | `2' after file name means just left a file. */ | |
8d08fdba | 2570 | |
66a6250f JM |
2571 | if (action_number == 1) |
2572 | { | |
2573 | action = act_push; | |
2574 | read_line_number (&action_number); | |
2575 | } | |
2576 | else if (action_number == 2) | |
2577 | { | |
2578 | action = act_pop; | |
2579 | read_line_number (&action_number); | |
2580 | } | |
2581 | if (action_number == 3) | |
2582 | { | |
2583 | /* `3' after file name means this is a system header file. */ | |
1ceb5ff3 | 2584 | in_system_header = 1; |
66a6250f JM |
2585 | read_line_number (&action_number); |
2586 | } | |
2587 | if (action_number == 4) | |
2588 | { | |
2589 | /* `4' after file name means this is a C header file. */ | |
2590 | entering_c_header = 1; | |
2591 | read_line_number (&action_number); | |
2592 | } | |
8d08fdba | 2593 | |
66a6250f | 2594 | /* Do the actions implied by the preceding numbers. */ |
8d08fdba | 2595 | |
66a6250f JM |
2596 | if (action == act_push) |
2597 | { | |
2598 | /* Pushing to a new file. */ | |
574a0ef5 MM |
2599 | push_srcloc (new_file, l); |
2600 | input_file_stack->indent_level = indent_level; | |
66a6250f | 2601 | debug_start_source_file (input_filename); |
66a6250f JM |
2602 | if (c_header_level) |
2603 | ++c_header_level; | |
2604 | else if (entering_c_header) | |
2605 | { | |
2606 | c_header_level = 1; | |
2607 | ++pending_lang_change; | |
2608 | } | |
2609 | } | |
2610 | else if (action == act_pop) | |
2611 | { | |
2612 | /* Popping out of a file. */ | |
2613 | if (input_file_stack->next) | |
2614 | { | |
66a6250f | 2615 | if (c_header_level && --c_header_level == 0) |
8d08fdba | 2616 | { |
66a6250f JM |
2617 | if (entering_c_header) |
2618 | warning ("badly nested C headers from preprocessor"); | |
2619 | --pending_lang_change; | |
8d08fdba MS |
2620 | } |
2621 | ||
574a0ef5 | 2622 | if (indent_level != input_file_stack->indent_level) |
8d08fdba | 2623 | { |
66a6250f | 2624 | warning_with_file_and_line |
574a0ef5 | 2625 | (input_filename, lineno, |
66a6250f | 2626 | "This file contains more `%c's than `%c's.", |
574a0ef5 MM |
2627 | indent_level > input_file_stack->indent_level ? '{' : '}', |
2628 | indent_level > input_file_stack->indent_level ? '}' : '{'); | |
8d08fdba | 2629 | } |
574a0ef5 MM |
2630 | |
2631 | pop_srcloc (); | |
2632 | input_file_stack->name = new_file; | |
2633 | lineno = l; | |
66a6250f | 2634 | debug_end_source_file (input_file_stack->line); |
8d08fdba | 2635 | } |
66a6250f JM |
2636 | else |
2637 | error ("#-lines for entering and leaving files don't match"); | |
8d08fdba | 2638 | } |
1ceb5ff3 | 2639 | |
574a0ef5 | 2640 | extract_interface_info (); |
8d08fdba MS |
2641 | |
2642 | /* skip the rest of this line. */ | |
2643 | skipline: | |
d18c083e MS |
2644 | linemode = 0; |
2645 | end_of_file = 0; | |
66a6250f | 2646 | |
1ceb5ff3 JM |
2647 | do |
2648 | c = getch (); | |
2649 | while (c != '\n' && c != EOF); | |
8d08fdba MS |
2650 | return c; |
2651 | } | |
1ceb5ff3 JM |
2652 | \f |
2653 | #ifdef HANDLE_GENERIC_PRAGMAS | |
2654 | ||
2655 | /* Handle a #pragma directive. | |
2656 | TOKEN is the token we read after `#pragma'. Processes the entire input | |
2657 | line and return non-zero iff the pragma has been successfully parsed. */ | |
2658 | ||
2659 | /* This function has to be in this file, in order to get at | |
2660 | the token types. */ | |
2661 | ||
2662 | static int | |
2663 | handle_generic_pragma (token) | |
2664 | register int token; | |
2665 | { | |
2666 | for (;;) | |
2667 | { | |
2668 | switch (token) | |
2669 | { | |
2670 | case IDENTIFIER: | |
2671 | case TYPENAME: | |
2672 | case STRING: | |
2673 | case CONSTANT: | |
2674 | handle_pragma_token (token_buffer, yylval.ttype); | |
2675 | break; | |
2676 | ||
2677 | case LEFT_RIGHT: | |
2678 | handle_pragma_token ("(", NULL_TREE); | |
2679 | handle_pragma_token (")", NULL_TREE); | |
2680 | break; | |
2681 | ||
2682 | case END_OF_LINE: | |
2683 | return handle_pragma_token (NULL_PTR, NULL_TREE); | |
2684 | ||
2685 | default: | |
2686 | handle_pragma_token (token_buffer, NULL_TREE); | |
2687 | } | |
2688 | ||
2689 | token = real_yylex (); | |
2690 | } | |
2691 | } | |
2692 | #endif /* HANDLE_GENERIC_PRAGMAS */ | |
2693 | ||
2694 | static int | |
2695 | handle_cp_pragma (pname) | |
2696 | const char *pname; | |
2697 | { | |
2698 | register int token; | |
2699 | ||
2700 | if (! strcmp (pname, "vtable")) | |
2701 | { | |
1ceb5ff3 JM |
2702 | /* More follows: it must be a string constant (class name). */ |
2703 | token = real_yylex (); | |
2704 | if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) | |
2705 | { | |
2706 | error ("invalid #pragma vtable"); | |
2707 | return -1; | |
2708 | } | |
2709 | ||
2710 | pending_vtables | |
e1b3e07d MM |
2711 | = tree_cons (NULL_TREE, |
2712 | get_identifier (TREE_STRING_POINTER (yylval.ttype)), | |
2713 | pending_vtables); | |
1ceb5ff3 JM |
2714 | token = real_yylex (); |
2715 | if (token != END_OF_LINE) | |
2716 | warning ("trailing characters ignored"); | |
2717 | return 1; | |
2718 | } | |
2719 | else if (! strcmp (pname, "unit")) | |
2720 | { | |
2721 | /* More follows: it must be a string constant (unit name). */ | |
2722 | token = real_yylex (); | |
2723 | if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) | |
2724 | { | |
2725 | error ("invalid #pragma unit"); | |
2726 | return -1; | |
2727 | } | |
2728 | token = real_yylex (); | |
2729 | if (token != END_OF_LINE) | |
2730 | warning ("trailing characters ignored"); | |
2731 | return 1; | |
2732 | } | |
2733 | else if (! strcmp (pname, "interface")) | |
2734 | { | |
2735 | char *main_filename = input_filename; | |
2736 | ||
2737 | main_filename = file_name_nondirectory (main_filename); | |
2738 | ||
2739 | token = real_yylex (); | |
2740 | ||
2741 | if (token != END_OF_LINE) | |
2742 | { | |
2743 | if (token != STRING | |
2744 | || TREE_CODE (yylval.ttype) != STRING_CST) | |
2745 | { | |
2746 | error ("invalid `#pragma interface'"); | |
2747 | return -1; | |
2748 | } | |
2749 | main_filename = TREE_STRING_POINTER (yylval.ttype); | |
2750 | token = real_yylex (); | |
2751 | } | |
2752 | ||
2753 | if (token != END_OF_LINE) | |
2754 | warning ("garbage after `#pragma interface' ignored"); | |
2755 | ||
2756 | cp_pragma_interface (main_filename); | |
2757 | ||
2758 | return 1; | |
2759 | } | |
2760 | else if (! strcmp (pname, "implementation")) | |
2761 | { | |
2762 | char *main_filename = main_input_filename ? main_input_filename : input_filename; | |
2763 | ||
2764 | main_filename = file_name_nondirectory (main_filename); | |
2765 | ||
2766 | token = real_yylex (); | |
2767 | ||
2768 | if (token != END_OF_LINE) | |
2769 | { | |
2770 | if (token != STRING | |
2771 | || TREE_CODE (yylval.ttype) != STRING_CST) | |
2772 | { | |
2773 | error ("invalid `#pragma implementation'"); | |
2774 | return -1; | |
2775 | } | |
2776 | main_filename = TREE_STRING_POINTER (yylval.ttype); | |
2777 | token = real_yylex (); | |
2778 | } | |
2779 | ||
2780 | if (token != END_OF_LINE) | |
2781 | warning ("garbage after `#pragma implementation' ignored"); | |
2782 | ||
2783 | cp_pragma_implementation (main_filename); | |
8d08fdba | 2784 | |
1ceb5ff3 JM |
2785 | return 1; |
2786 | } | |
2787 | ||
2788 | return 0; | |
2789 | } | |
2790 | \f | |
8d08fdba MS |
2791 | void |
2792 | do_pending_lang_change () | |
2793 | { | |
2794 | for (; pending_lang_change > 0; --pending_lang_change) | |
2795 | push_lang_context (lang_name_c); | |
2796 | for (; pending_lang_change < 0; ++pending_lang_change) | |
2797 | pop_lang_context (); | |
2798 | } | |
2799 | \f | |
8d08fdba MS |
2800 | #define ENDFILE -1 /* token that represents end-of-file */ |
2801 | ||
2802 | /* Read an escape sequence, returning its equivalent as a character, | |
2803 | or store 1 in *ignore_ptr if it is backslash-newline. */ | |
2804 | ||
2805 | static int | |
2806 | readescape (ignore_ptr) | |
2807 | int *ignore_ptr; | |
2808 | { | |
2809 | register int c = getch (); | |
2810 | register int code; | |
2811 | register unsigned count; | |
a703fb38 | 2812 | unsigned firstdig = 0; |
8d08fdba MS |
2813 | int nonnull; |
2814 | ||
2815 | switch (c) | |
2816 | { | |
2817 | case 'x': | |
8d08fdba MS |
2818 | code = 0; |
2819 | count = 0; | |
2820 | nonnull = 0; | |
2821 | while (1) | |
2822 | { | |
2823 | c = getch (); | |
faa25e97 | 2824 | if (! ISXDIGIT (c)) |
8d08fdba MS |
2825 | { |
2826 | put_back (c); | |
2827 | break; | |
2828 | } | |
2829 | code *= 16; | |
2830 | if (c >= 'a' && c <= 'f') | |
2831 | code += c - 'a' + 10; | |
2832 | if (c >= 'A' && c <= 'F') | |
2833 | code += c - 'A' + 10; | |
2834 | if (c >= '0' && c <= '9') | |
2835 | code += c - '0'; | |
2836 | if (code != 0 || count != 0) | |
2837 | { | |
2838 | if (count == 0) | |
2839 | firstdig = code; | |
2840 | count++; | |
2841 | } | |
2842 | nonnull = 1; | |
2843 | } | |
2844 | if (! nonnull) | |
8251199e | 2845 | error ("\\x used with no following hex digits"); |
8d08fdba MS |
2846 | else if (count == 0) |
2847 | /* Digits are all 0's. Ok. */ | |
2848 | ; | |
2849 | else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node) | |
2850 | || (count > 1 | |
1ceb5ff3 JM |
2851 | && (((unsigned)1 |
2852 | << (TYPE_PRECISION (integer_type_node) | |
2853 | - (count - 1) * 4)) | |
8d08fdba | 2854 | <= firstdig))) |
8251199e | 2855 | pedwarn ("hex escape out of range"); |
8d08fdba MS |
2856 | return code; |
2857 | ||
2858 | case '0': case '1': case '2': case '3': case '4': | |
2859 | case '5': case '6': case '7': | |
2860 | code = 0; | |
2861 | count = 0; | |
2862 | while ((c <= '7') && (c >= '0') && (count++ < 3)) | |
2863 | { | |
2864 | code = (code * 8) + (c - '0'); | |
2865 | c = getch (); | |
2866 | } | |
2867 | put_back (c); | |
2868 | return code; | |
2869 | ||
2870 | case '\\': case '\'': case '"': | |
2871 | return c; | |
2872 | ||
2873 | case '\n': | |
2874 | lineno++; | |
2875 | *ignore_ptr = 1; | |
2876 | return 0; | |
2877 | ||
2878 | case 'n': | |
2879 | return TARGET_NEWLINE; | |
2880 | ||
2881 | case 't': | |
2882 | return TARGET_TAB; | |
2883 | ||
2884 | case 'r': | |
2885 | return TARGET_CR; | |
2886 | ||
2887 | case 'f': | |
2888 | return TARGET_FF; | |
2889 | ||
2890 | case 'b': | |
2891 | return TARGET_BS; | |
2892 | ||
2893 | case 'a': | |
8d08fdba MS |
2894 | return TARGET_BELL; |
2895 | ||
2896 | case 'v': | |
2897 | return TARGET_VT; | |
2898 | ||
2899 | case 'e': | |
2900 | case 'E': | |
2901 | if (pedantic) | |
cab1f180 | 2902 | pedwarn ("non-ISO-standard escape sequence, `\\%c'", c); |
8d08fdba MS |
2903 | return 033; |
2904 | ||
2905 | case '?': | |
2906 | return c; | |
2907 | ||
2908 | /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */ | |
2909 | case '(': | |
2910 | case '{': | |
2911 | case '[': | |
2912 | /* `\%' is used to prevent SCCS from getting confused. */ | |
2913 | case '%': | |
2914 | if (pedantic) | |
8251199e | 2915 | pedwarn ("unknown escape sequence `\\%c'", c); |
8d08fdba MS |
2916 | return c; |
2917 | } | |
83f660b7 | 2918 | if (ISGRAPH (c)) |
8251199e | 2919 | pedwarn ("unknown escape sequence `\\%c'", c); |
8d08fdba | 2920 | else |
8251199e | 2921 | pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c); |
8d08fdba MS |
2922 | return c; |
2923 | } | |
1ceb5ff3 JM |
2924 | \f |
2925 | void | |
2926 | yyerror (string) | |
2927 | const char *string; | |
2928 | { | |
2929 | extern int end_of_file; | |
1ceb5ff3 JM |
2930 | |
2931 | /* We can't print string and character constants well | |
2932 | because the token_buffer contains the result of processing escapes. */ | |
2933 | if (end_of_file) | |
486837a7 KG |
2934 | { |
2935 | if (input_redirected ()) | |
2936 | error ("%s at end of saved text", string); | |
2937 | else | |
2938 | error ("%s at end of input", string); | |
2939 | } | |
1ceb5ff3 | 2940 | else if (token_buffer[0] == 0) |
486837a7 | 2941 | error ("%s at null character", string); |
1ceb5ff3 | 2942 | else if (token_buffer[0] == '"') |
486837a7 | 2943 | error ("%s before string constant", string); |
1ceb5ff3 | 2944 | else if (token_buffer[0] == '\'') |
486837a7 | 2945 | error ("%s before character constant", string); |
1ceb5ff3 | 2946 | else if (!ISGRAPH ((unsigned char)token_buffer[0])) |
486837a7 | 2947 | error ("%s before character 0%o", string, (unsigned char) token_buffer[0]); |
1ceb5ff3 | 2948 | else |
486837a7 | 2949 | error ("%s before `%s'", string, token_buffer); |
1ceb5ff3 JM |
2950 | } |
2951 | \f | |
a28e3c7f MS |
2952 | /* Value is 1 (or 2) if we should try to make the next identifier look like |
2953 | a typename (when it may be a local variable or a class variable). | |
2954 | Value is 0 if we treat this name in a default fashion. */ | |
00dc6358 | 2955 | int looking_for_typename; |
8d08fdba | 2956 | |
f9c4f105 | 2957 | inline int |
8d08fdba MS |
2958 | identifier_type (decl) |
2959 | tree decl; | |
2960 | { | |
830fcda8 | 2961 | tree t; |
5566b478 MS |
2962 | if (TREE_CODE (decl) == TEMPLATE_DECL) |
2963 | { | |
2964 | if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL) | |
2965 | return PTYPENAME; | |
386b8a85 JM |
2966 | else if (looking_for_template) |
2967 | return PFUNCNAME; | |
2968 | } | |
2969 | if (looking_for_template && really_overloaded_fn (decl)) | |
2970 | { | |
161c12b0 JM |
2971 | /* See through a baselink. */ |
2972 | if (TREE_CODE (decl) == TREE_LIST) | |
2973 | decl = TREE_VALUE (decl); | |
2974 | ||
2c73f9f5 ML |
2975 | for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t)) |
2976 | if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t))) | |
386b8a85 | 2977 | return PFUNCNAME; |
5566b478 | 2978 | } |
a9aedbc2 MS |
2979 | if (TREE_CODE (decl) == NAMESPACE_DECL) |
2980 | return NSNAME; | |
8d08fdba MS |
2981 | if (TREE_CODE (decl) != TYPE_DECL) |
2982 | return IDENTIFIER; | |
830fcda8 JM |
2983 | if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type) |
2984 | return SELFNAME; | |
2985 | ||
2986 | /* A constructor declarator for a template type will get here as an | |
2987 | implicit typename, a TYPENAME_TYPE with a type. */ | |
2988 | t = got_scope; | |
2989 | if (t && TREE_CODE (t) == TYPENAME_TYPE) | |
2990 | t = TREE_TYPE (t); | |
2991 | decl = TREE_TYPE (decl); | |
2992 | if (TREE_CODE (decl) == TYPENAME_TYPE) | |
2993 | decl = TREE_TYPE (decl); | |
2994 | if (t && t == decl) | |
a80e4195 | 2995 | return SELFNAME; |
830fcda8 | 2996 | |
8d08fdba MS |
2997 | return TYPENAME; |
2998 | } | |
2999 | ||
3000 | void | |
3001 | see_typename () | |
3002 | { | |
2c73f9f5 ML |
3003 | /* Only types expected, not even namespaces. */ |
3004 | looking_for_typename = 2; | |
f30432d7 | 3005 | if (yychar < 0) |
fc378698 | 3006 | if ((yychar = yylex ()) < 0) yychar = 0; |
8d08fdba MS |
3007 | looking_for_typename = 0; |
3008 | if (yychar == IDENTIFIER) | |
3009 | { | |
a28e3c7f | 3010 | lastiddecl = lookup_name (yylval.ttype, -2); |
8d08fdba MS |
3011 | if (lastiddecl == 0) |
3012 | { | |
3013 | if (flag_labels_ok) | |
3014 | lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype); | |
3015 | } | |
3016 | else | |
3017 | yychar = identifier_type (lastiddecl); | |
3018 | } | |
3019 | } | |
3020 | ||
a759e627 ML |
3021 | /* Return true if d is in a global scope. */ |
3022 | ||
3023 | static int | |
3024 | is_global (d) | |
3025 | tree d; | |
3026 | { | |
3027 | while (1) | |
3028 | switch (TREE_CODE (d)) | |
3029 | { | |
01240200 MM |
3030 | case ERROR_MARK: |
3031 | return 1; | |
3032 | ||
a759e627 ML |
3033 | case OVERLOAD: d = OVL_FUNCTION (d); continue; |
3034 | case TREE_LIST: d = TREE_VALUE (d); continue; | |
3035 | default: | |
3036 | my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (d)) == 'd', 980629); | |
8bcc97de | 3037 | |
cd9f6678 | 3038 | return DECL_NAMESPACE_SCOPE_P (d); |
a759e627 ML |
3039 | } |
3040 | } | |
3041 | ||
8d08fdba | 3042 | tree |
a759e627 | 3043 | do_identifier (token, parsing, args) |
8d08fdba | 3044 | register tree token; |
5566b478 | 3045 | int parsing; |
a759e627 | 3046 | tree args; |
8d08fdba | 3047 | { |
5566b478 | 3048 | register tree id; |
e13a4123 JM |
3049 | int lexing = (parsing == 1); |
3050 | int in_call = (parsing == 2); | |
8d08fdba | 3051 | |
e13a4123 | 3052 | if (! lexing || IDENTIFIER_OPNAME_P (token)) |
72b7eeff | 3053 | id = lookup_name (token, 0); |
5566b478 MS |
3054 | else |
3055 | id = lastiddecl; | |
72b7eeff | 3056 | |
a759e627 | 3057 | /* Do Koenig lookup if appropriate (inside templates we build lookup |
2c169bab JM |
3058 | expressions instead). |
3059 | ||
3060 | [basic.lookup.koenig]: If the ordinary unqualified lookup of the name | |
3061 | finds the declaration of a class member function, the associated | |
3062 | namespaces and classes are not considered. */ | |
3063 | ||
a759e627 | 3064 | if (args && !current_template_parms && (!id || is_global (id))) |
f181d4ae | 3065 | id = lookup_arg_dependent (token, id, args); |
a759e627 | 3066 | |
8d2733ca MS |
3067 | /* Remember that this name has been used in the class definition, as per |
3068 | [class.scope0] */ | |
70adf8a9 | 3069 | if (id && parsing) |
8f032717 | 3070 | maybe_note_name_used_in_class (token, id); |
72b7eeff | 3071 | |
5b163de4 JM |
3072 | if (id == error_mark_node) |
3073 | { | |
3074 | /* lookup_name quietly returns error_mark_node if we're parsing, | |
3075 | as we don't want to complain about an identifier that ends up | |
3076 | being used as a declarator. So we call it again to get the error | |
3077 | message. */ | |
3078 | id = lookup_name (token, 0); | |
3079 | return error_mark_node; | |
3080 | } | |
3081 | ||
3082 | if (!id) | |
3083 | { | |
5566b478 | 3084 | if (current_template_parms) |
672476cb | 3085 | return build_min_nt (LOOKUP_EXPR, token); |
5566b478 | 3086 | else if (IDENTIFIER_OPNAME_P (token)) |
72b7eeff MS |
3087 | { |
3088 | if (token != ansi_opname[ERROR_MARK]) | |
8251199e | 3089 | cp_error ("`%D' not defined", token); |
72b7eeff MS |
3090 | id = error_mark_node; |
3091 | } | |
830fcda8 | 3092 | else if (in_call && ! flag_strict_prototype) |
8d08fdba MS |
3093 | { |
3094 | id = implicitly_declare (token); | |
3095 | } | |
3096 | else if (current_function_decl == 0) | |
3097 | { | |
8251199e | 3098 | cp_error ("`%D' was not declared in this scope", token); |
8d08fdba MS |
3099 | id = error_mark_node; |
3100 | } | |
3101 | else | |
3102 | { | |
30394414 | 3103 | if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node |
8d08fdba MS |
3104 | || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl) |
3105 | { | |
3106 | static int undeclared_variable_notice; | |
3107 | ||
8251199e | 3108 | cp_error ("`%D' undeclared (first use this function)", token); |
8d08fdba MS |
3109 | |
3110 | if (! undeclared_variable_notice) | |
3111 | { | |
8251199e JM |
3112 | error ("(Each undeclared identifier is reported only once"); |
3113 | error ("for each function it appears in.)"); | |
8d08fdba MS |
3114 | undeclared_variable_notice = 1; |
3115 | } | |
3116 | } | |
3117 | id = error_mark_node; | |
3118 | /* Prevent repeated error messages. */ | |
2c73f9f5 | 3119 | SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node); |
8d08fdba MS |
3120 | SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl); |
3121 | } | |
3122 | } | |
f3be9e3c PB |
3123 | |
3124 | if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id)) | |
3125 | { | |
3126 | tree shadowed = DECL_SHADOWED_FOR_VAR (id); | |
2ee887f2 MS |
3127 | while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL |
3128 | && DECL_DEAD_FOR_LOCAL (shadowed)) | |
3129 | shadowed = DECL_SHADOWED_FOR_VAR (shadowed); | |
3130 | if (!shadowed) | |
30394414 | 3131 | shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id)); |
f3be9e3c PB |
3132 | if (shadowed) |
3133 | { | |
3134 | if (!DECL_ERROR_REPORTED (id)) | |
3135 | { | |
8251199e | 3136 | warning ("name lookup of `%s' changed", |
f3be9e3c | 3137 | IDENTIFIER_POINTER (token)); |
cab1f180 | 3138 | cp_warning_at (" matches this `%D' under ISO standard rules", |
f3be9e3c | 3139 | shadowed); |
8251199e | 3140 | cp_warning_at (" matches this `%D' under old rules", id); |
f3be9e3c PB |
3141 | DECL_ERROR_REPORTED (id) = 1; |
3142 | } | |
3143 | id = shadowed; | |
3144 | } | |
3145 | else if (!DECL_ERROR_REPORTED (id)) | |
3146 | { | |
f3be9e3c PB |
3147 | DECL_ERROR_REPORTED (id) = 1; |
3148 | if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id))) | |
3149 | { | |
cab1f180 | 3150 | error ("name lookup of `%s' changed for new ISO `for' scoping", |
b9d12519 | 3151 | IDENTIFIER_POINTER (token)); |
8251199e | 3152 | cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id); |
f3be9e3c PB |
3153 | id = error_mark_node; |
3154 | } | |
3155 | else | |
3156 | { | |
cab1f180 | 3157 | pedwarn ("name lookup of `%s' changed for new ISO `for' scoping", |
b9d12519 | 3158 | IDENTIFIER_POINTER (token)); |
8251199e | 3159 | cp_pedwarn_at (" using obsolete binding at `%D'", id); |
f3be9e3c PB |
3160 | } |
3161 | } | |
3162 | } | |
8d08fdba MS |
3163 | /* TREE_USED is set in `hack_identifier'. */ |
3164 | if (TREE_CODE (id) == CONST_DECL) | |
3165 | { | |
d6479fe7 | 3166 | /* Check access. */ |
8d08fdba | 3167 | if (IDENTIFIER_CLASS_VALUE (token) == id) |
4f1c5b7d | 3168 | enforce_access (CP_DECL_CONTEXT(id), id); |
50714e79 | 3169 | if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id)) |
5566b478 | 3170 | id = DECL_INITIAL (id); |
8d08fdba MS |
3171 | } |
3172 | else | |
5566b478 MS |
3173 | id = hack_identifier (id, token); |
3174 | ||
ed44da02 MM |
3175 | /* We must look up dependent names when the template is |
3176 | instantiated, not while parsing it. For now, we don't | |
3177 | distinguish between dependent and independent names. So, for | |
3178 | example, we look up all overloaded functions at | |
3179 | instantiation-time, even though in some cases we should just use | |
3180 | the DECL we have here. We also use LOOKUP_EXPRs to find things | |
c0a483c7 | 3181 | like local variables, rather than creating TEMPLATE_DECLs for the |
ed44da02 | 3182 | local variables and then finding matching instantiations. */ |
672476cb MM |
3183 | if (current_template_parms |
3184 | && (is_overloaded_fn (id) | |
ed44da02 MM |
3185 | /* Some local VAR_DECLs (such as those for local variables |
3186 | in member functions of local classes) are built on the | |
3187 | permanent obstack. */ | |
3188 | || (TREE_CODE (id) == VAR_DECL | |
3189 | && CP_DECL_CONTEXT (id) | |
3190 | && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL) | |
672476cb | 3191 | || TREE_CODE (id) == PARM_DECL |
c6882a35 | 3192 | || TREE_CODE (id) == RESULT_DECL |
672476cb MM |
3193 | || TREE_CODE (id) == USING_DECL)) |
3194 | id = build_min_nt (LOOKUP_EXPR, token); | |
5566b478 MS |
3195 | |
3196 | return id; | |
3197 | } | |
3198 | ||
3199 | tree | |
3200 | do_scoped_id (token, parsing) | |
3201 | tree token; | |
3202 | int parsing; | |
3203 | { | |
30394414 JM |
3204 | tree id; |
3205 | /* during parsing, this is ::name. Otherwise, it is black magic. */ | |
3206 | if (parsing) | |
2c73f9f5 | 3207 | { |
87e3dbc9 | 3208 | id = make_node (CPLUS_BINDING); |
52c11ef6 | 3209 | if (!qualified_lookup_using_namespace (token, global_namespace, id, 0)) |
2c73f9f5 ML |
3210 | id = NULL_TREE; |
3211 | else | |
3212 | id = BINDING_VALUE (id); | |
3213 | } | |
30394414 JM |
3214 | else |
3215 | id = IDENTIFIER_GLOBAL_VALUE (token); | |
5566b478 MS |
3216 | if (parsing && yychar == YYEMPTY) |
3217 | yychar = yylex (); | |
3218 | if (! id) | |
3219 | { | |
5156628f | 3220 | if (processing_template_decl) |
5566b478 | 3221 | { |
672476cb | 3222 | id = build_min_nt (LOOKUP_EXPR, token); |
5566b478 MS |
3223 | LOOKUP_EXPR_GLOBAL (id) = 1; |
3224 | return id; | |
3225 | } | |
830fcda8 JM |
3226 | if (parsing && (yychar == '(' || yychar == LEFT_RIGHT) |
3227 | && ! flag_strict_prototype) | |
5566b478 MS |
3228 | id = implicitly_declare (token); |
3229 | else | |
3230 | { | |
30394414 | 3231 | if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node) |
8251199e | 3232 | cp_error ("`::%D' undeclared (first use here)", token); |
5566b478 MS |
3233 | id = error_mark_node; |
3234 | /* Prevent repeated error messages. */ | |
2c73f9f5 | 3235 | SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node); |
5566b478 MS |
3236 | } |
3237 | } | |
3238 | else | |
3239 | { | |
3240 | if (TREE_CODE (id) == ADDR_EXPR) | |
3241 | mark_used (TREE_OPERAND (id, 0)); | |
2c73f9f5 | 3242 | else if (TREE_CODE (id) != OVERLOAD) |
5566b478 MS |
3243 | mark_used (id); |
3244 | } | |
5156628f | 3245 | if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl) |
5566b478 MS |
3246 | { |
3247 | /* XXX CHS - should we set TREE_USED of the constant? */ | |
3248 | id = DECL_INITIAL (id); | |
3249 | /* This is to prevent an enum whose value is 0 | |
3250 | from being considered a null pointer constant. */ | |
3251 | id = build1 (NOP_EXPR, TREE_TYPE (id), id); | |
3252 | TREE_CONSTANT (id) = 1; | |
3253 | } | |
3254 | ||
5156628f | 3255 | if (processing_template_decl) |
5566b478 MS |
3256 | { |
3257 | if (is_overloaded_fn (id)) | |
3258 | { | |
672476cb | 3259 | id = build_min_nt (LOOKUP_EXPR, token); |
5566b478 | 3260 | LOOKUP_EXPR_GLOBAL (id) = 1; |
672476cb | 3261 | return id; |
5566b478 MS |
3262 | } |
3263 | /* else just use the decl */ | |
3264 | } | |
42976354 | 3265 | return convert_from_reference (id); |
8d08fdba MS |
3266 | } |
3267 | ||
3268 | tree | |
3269 | identifier_typedecl_value (node) | |
3270 | tree node; | |
3271 | { | |
3272 | tree t, type; | |
3273 | type = IDENTIFIER_TYPE_VALUE (node); | |
3274 | if (type == NULL_TREE) | |
3275 | return NULL_TREE; | |
f181d4ae MM |
3276 | |
3277 | if (IDENTIFIER_BINDING (node)) | |
3278 | { | |
3279 | t = IDENTIFIER_VALUE (node); | |
3280 | if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) | |
3281 | return t; | |
3282 | } | |
3283 | if (IDENTIFIER_NAMESPACE_VALUE (node)) | |
3284 | { | |
3285 | t = IDENTIFIER_NAMESPACE_VALUE (node); | |
3286 | if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) | |
3287 | return t; | |
3288 | } | |
3289 | ||
8d08fdba | 3290 | /* Will this one ever happen? */ |
d2e5ee5c MS |
3291 | if (TYPE_MAIN_DECL (type)) |
3292 | return TYPE_MAIN_DECL (type); | |
8d08fdba MS |
3293 | |
3294 | /* We used to do an internal error of 62 here, but instead we will | |
3295 | handle the return of a null appropriately in the callers. */ | |
3296 | return NULL_TREE; | |
3297 | } | |
3298 | ||
1ceb5ff3 | 3299 | struct pf_args |
9b2bf201 KG |
3300 | { |
3301 | /* Input */ | |
1ceb5ff3 JM |
3302 | int base; |
3303 | char * p; | |
9b2bf201 | 3304 | /* I/O */ |
9b2bf201 | 3305 | int c; |
1ceb5ff3 | 3306 | /* Output */ |
9b2bf201 KG |
3307 | int imag; |
3308 | tree type; | |
1ceb5ff3 | 3309 | int conversion_errno; |
9b2bf201 KG |
3310 | REAL_VALUE_TYPE value; |
3311 | }; | |
3312 | ||
3313 | static void | |
3314 | parse_float (data) | |
3315 | PTR data; | |
3316 | { | |
3317 | struct pf_args * args = (struct pf_args *) data; | |
3318 | int fflag = 0, lflag = 0; | |
3319 | /* Copy token_buffer now, while it has just the number | |
3320 | and not the suffixes; once we add `f' or `i', | |
3321 | REAL_VALUE_ATOF may not work any more. */ | |
3322 | char *copy = (char *) alloca (args->p - token_buffer + 1); | |
3323 | bcopy (token_buffer, copy, args->p - token_buffer + 1); | |
1ceb5ff3 JM |
3324 | args->imag = 0; |
3325 | args->conversion_errno = 0; | |
3326 | args->type = double_type_node; | |
3327 | ||
9b2bf201 KG |
3328 | while (1) |
3329 | { | |
3330 | int lose = 0; | |
1ceb5ff3 | 3331 | |
9b2bf201 KG |
3332 | /* Read the suffixes to choose a data type. */ |
3333 | switch (args->c) | |
3334 | { | |
3335 | case 'f': case 'F': | |
3336 | if (fflag) | |
3337 | error ("more than one `f' in numeric constant"); | |
3338 | fflag = 1; | |
3339 | break; | |
1ceb5ff3 | 3340 | |
9b2bf201 KG |
3341 | case 'l': case 'L': |
3342 | if (lflag) | |
3343 | error ("more than one `l' in numeric constant"); | |
3344 | lflag = 1; | |
3345 | break; | |
1ceb5ff3 | 3346 | |
9b2bf201 KG |
3347 | case 'i': case 'I': |
3348 | if (args->imag) | |
3349 | error ("more than one `i' or `j' in numeric constant"); | |
3350 | else if (pedantic) | |
cab1f180 | 3351 | pedwarn ("ISO C++ forbids imaginary numeric constants"); |
9b2bf201 KG |
3352 | args->imag = 1; |
3353 | break; | |
1ceb5ff3 | 3354 | |
9b2bf201 KG |
3355 | default: |
3356 | lose = 1; | |
3357 | } | |
1ceb5ff3 | 3358 | |
9b2bf201 KG |
3359 | if (lose) |
3360 | break; | |
1ceb5ff3 | 3361 | |
9b2bf201 KG |
3362 | if (args->p >= token_buffer + maxtoken - 3) |
3363 | args->p = extend_token_buffer (args->p); | |
3364 | *(args->p++) = args->c; | |
3365 | *(args->p) = 0; | |
3366 | args->c = getch (); | |
3367 | } | |
1ceb5ff3 | 3368 | |
9b2bf201 KG |
3369 | /* The second argument, machine_mode, of REAL_VALUE_ATOF |
3370 | tells the desired precision of the binary result | |
3371 | of decimal-to-binary conversion. */ | |
1ceb5ff3 | 3372 | |
9b2bf201 KG |
3373 | if (fflag) |
3374 | { | |
3375 | if (lflag) | |
3376 | error ("both `f' and `l' in floating constant"); | |
1ceb5ff3 | 3377 | |
9b2bf201 | 3378 | args->type = float_type_node; |
1ceb5ff3 JM |
3379 | errno = 0; |
3380 | if (args->base == 16) | |
3381 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
3382 | else | |
3383 | args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type)); | |
3384 | args->conversion_errno = errno; | |
9b2bf201 | 3385 | /* A diagnostic is required here by some ANSI C testsuites. |
1ceb5ff3 | 3386 | This is not pedwarn, because some people don't want |
9b2bf201 KG |
3387 | an error for this. */ |
3388 | if (REAL_VALUE_ISINF (args->value) && pedantic) | |
3389 | warning ("floating point number exceeds range of `float'"); | |
3390 | } | |
3391 | else if (lflag) | |
3392 | { | |
3393 | args->type = long_double_type_node; | |
1ceb5ff3 JM |
3394 | errno = 0; |
3395 | if (args->base == 16) | |
3396 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
3397 | else | |
3398 | args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type)); | |
3399 | args->conversion_errno = errno; | |
9b2bf201 KG |
3400 | if (REAL_VALUE_ISINF (args->value) && pedantic) |
3401 | warning ("floating point number exceeds range of `long double'"); | |
3402 | } | |
3403 | else | |
3404 | { | |
1ceb5ff3 JM |
3405 | errno = 0; |
3406 | if (args->base == 16) | |
3407 | args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type)); | |
3408 | else | |
3409 | args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type)); | |
3410 | args->conversion_errno = errno; | |
9b2bf201 KG |
3411 | if (REAL_VALUE_ISINF (args->value) && pedantic) |
3412 | warning ("floating point number exceeds range of `double'"); | |
3413 | } | |
3414 | } | |
3415 | ||
66a6250f JM |
3416 | /* Get the next character, staying within the current token if possible. |
3417 | If we're lexing a token, we don't want to look beyond the end of the | |
3418 | token cpplib has prepared for us; otherwise, we end up reading in the | |
3419 | next token, which screws up feed_input. So just return a null | |
3420 | character. */ | |
3421 | ||
f5984164 | 3422 | static int |
66a6250f JM |
3423 | token_getch () |
3424 | { | |
3425 | #if USE_CPPLIB | |
3426 | if (yy_cur == yy_lim) | |
3427 | return '\0'; | |
3428 | #endif | |
3429 | return getch (); | |
3430 | } | |
3431 | ||
f5984164 | 3432 | static void |
66a6250f JM |
3433 | token_put_back (ch) |
3434 | int ch; | |
3435 | { | |
3436 | #if USE_CPPLIB | |
3437 | if (ch == '\0') | |
3438 | return; | |
3439 | #endif | |
3440 | put_back (ch); | |
3441 | } | |
3442 | ||
3443 | /* Read a single token from the input stream, and assign it lexical | |
3444 | semantics. | |
3445 | ||
3446 | Note: We used to do token pasting here, to produce compound tokens like | |
3447 | LEFT_RIGHT and EXTERN_LANG_STRING. That's now handled in spew.c, along | |
3448 | with symbol table interaction and other context-sensitivity. */ | |
3449 | ||
8d08fdba MS |
3450 | int |
3451 | real_yylex () | |
3452 | { | |
3453 | register int c; | |
1ceb5ff3 | 3454 | register char *p; |
8d08fdba MS |
3455 | register int value; |
3456 | int wide_flag = 0; | |
8d08fdba | 3457 | |
66a6250f | 3458 | c = getch (); |
8d08fdba MS |
3459 | |
3460 | /* Effectively do c = skip_white_space (c) | |
3461 | but do it faster in the usual cases. */ | |
3462 | while (1) | |
3463 | switch (c) | |
3464 | { | |
3465 | case ' ': | |
3466 | case '\t': | |
3467 | case '\f': | |
3468 | case '\v': | |
3469 | case '\b': | |
66a6250f JM |
3470 | #if USE_CPPLIB |
3471 | if (cpp_token == CPP_HSPACE) | |
3472 | c = yy_get_token (); | |
3473 | else | |
3474 | #endif | |
3475 | c = getch (); | |
8d08fdba MS |
3476 | break; |
3477 | ||
3478 | case '\r': | |
3479 | /* Call skip_white_space so we can warn if appropriate. */ | |
3480 | ||
3481 | case '\n': | |
3482 | case '/': | |
3483 | case '\\': | |
3484 | c = skip_white_space (c); | |
3485 | default: | |
3486 | goto found_nonwhite; | |
3487 | } | |
3488 | found_nonwhite: | |
3489 | ||
3490 | token_buffer[0] = c; | |
3491 | token_buffer[1] = 0; | |
3492 | ||
3493 | /* yylloc.first_line = lineno; */ | |
3494 | ||
3495 | switch (c) | |
3496 | { | |
3497 | case EOF: | |
8d08fdba | 3498 | end_of_file = 1; |
1ceb5ff3 | 3499 | token_buffer[0] = 0; |
1946537b | 3500 | if (linemode) |
d18c083e | 3501 | value = END_OF_LINE; |
1946537b JM |
3502 | else if (input_redirected ()) |
3503 | value = END_OF_SAVED_INPUT; | |
8d08fdba MS |
3504 | else |
3505 | value = ENDFILE; | |
3506 | break; | |
3507 | ||
8d08fdba | 3508 | case 'L': |
66a6250f JM |
3509 | #if USE_CPPLIB |
3510 | if (cpp_token == CPP_NAME) | |
3511 | goto letter; | |
3512 | #endif | |
8d08fdba MS |
3513 | /* Capital L may start a wide-string or wide-character constant. */ |
3514 | { | |
66a6250f | 3515 | register int c = token_getch (); |
8d08fdba MS |
3516 | if (c == '\'') |
3517 | { | |
3518 | wide_flag = 1; | |
3519 | goto char_constant; | |
3520 | } | |
3521 | if (c == '"') | |
3522 | { | |
3523 | wide_flag = 1; | |
3524 | goto string_constant; | |
3525 | } | |
66a6250f | 3526 | token_put_back (c); |
8d08fdba | 3527 | } |
1ceb5ff3 | 3528 | |
8d08fdba MS |
3529 | case 'A': case 'B': case 'C': case 'D': case 'E': |
3530 | case 'F': case 'G': case 'H': case 'I': case 'J': | |
3531 | case 'K': case 'M': case 'N': case 'O': | |
3532 | case 'P': case 'Q': case 'R': case 'S': case 'T': | |
3533 | case 'U': case 'V': case 'W': case 'X': case 'Y': | |
3534 | case 'Z': | |
3535 | case 'a': case 'b': case 'c': case 'd': case 'e': | |
3536 | case 'f': case 'g': case 'h': case 'i': case 'j': | |
3537 | case 'k': case 'l': case 'm': case 'n': case 'o': | |
3538 | case 'p': case 'q': case 'r': case 's': case 't': | |
3539 | case 'u': case 'v': case 'w': case 'x': case 'y': | |
3540 | case 'z': | |
3541 | case '_': | |
1ceb5ff3 | 3542 | case '$': |
66a6250f | 3543 | #if USE_CPPLIB |
9c0758dd | 3544 | letter: |
1ceb5ff3 JM |
3545 | if (cpp_token == CPP_NAME) |
3546 | { | |
3547 | /* Note that one character has already been read from | |
3548 | yy_cur into token_buffer. Also, cpplib complains about | |
3549 | $ in identifiers, so we don't have to. */ | |
3550 | ||
3551 | int len = yy_lim - yy_cur + 1; | |
3552 | if (len >= maxtoken) | |
3553 | extend_token_buffer_to (len + 1); | |
3554 | memcpy (token_buffer + 1, yy_cur, len); | |
3555 | p = token_buffer + len; | |
3556 | yy_cur = yy_lim; | |
3557 | } | |
3558 | else | |
66a6250f | 3559 | #endif |
1ceb5ff3 JM |
3560 | { |
3561 | p = token_buffer; | |
3562 | while (ISALNUM (c) || (c == '_') || c == '$') | |
3563 | { | |
3564 | /* Make sure this char really belongs in an identifier. */ | |
3565 | if (c == '$') | |
3566 | { | |
3567 | if (! dollars_in_ident) | |
3568 | error ("`$' in identifier"); | |
3569 | else if (pedantic) | |
3570 | pedwarn ("`$' in identifier"); | |
3571 | } | |
4f6140be | 3572 | |
1ceb5ff3 JM |
3573 | if (p >= token_buffer + maxtoken) |
3574 | p = extend_token_buffer (p); | |
8d08fdba | 3575 | |
1ceb5ff3 JM |
3576 | *p++ = c; |
3577 | c = token_getch (); | |
3578 | } | |
8d08fdba | 3579 | |
1ceb5ff3 JM |
3580 | *p = 0; |
3581 | token_put_back (c); | |
3582 | } | |
8d08fdba | 3583 | |
1ceb5ff3 JM |
3584 | value = IDENTIFIER; |
3585 | yylval.itype = 0; | |
8d08fdba | 3586 | |
1ceb5ff3 | 3587 | /* Try to recognize a keyword. Uses minimum-perfect hash function */ |
8d08fdba | 3588 | |
1ceb5ff3 JM |
3589 | { |
3590 | register struct resword *ptr; | |
8d08fdba | 3591 | |
1ceb5ff3 JM |
3592 | if ((ptr = is_reserved_word (token_buffer, p - token_buffer))) |
3593 | { | |
3594 | if (ptr->rid) | |
3595 | { | |
3596 | if (ptr->token == VISSPEC) | |
3597 | { | |
3598 | switch (ptr->rid) | |
3599 | { | |
3600 | case RID_PUBLIC: | |
3601 | yylval.ttype = access_public_node; | |
3602 | break; | |
3603 | case RID_PRIVATE: | |
3604 | yylval.ttype = access_private_node; | |
3605 | break; | |
3606 | case RID_PROTECTED: | |
3607 | yylval.ttype = access_protected_node; | |
3608 | break; | |
3609 | default: | |
3610 | my_friendly_abort (63); | |
3611 | } | |
3612 | } | |
3613 | else | |
3614 | yylval.ttype = ridpointers[(int) ptr->rid]; | |
3615 | } | |
3616 | else switch (ptr->token) | |
3617 | { | |
3618 | case EQCOMPARE: | |
3619 | yylval.code = NE_EXPR; | |
3620 | token_buffer[0] = '!'; | |
3621 | token_buffer[1] = '='; | |
3622 | token_buffer[2] = 0; | |
3623 | break; | |
66a6250f | 3624 | |
1ceb5ff3 JM |
3625 | case ASSIGN: |
3626 | if (strcmp ("and_eq", token_buffer) == 0) | |
3627 | { | |
3628 | yylval.code = BIT_AND_EXPR; | |
3629 | token_buffer[0] = '&'; | |
3630 | } | |
3631 | else if (strcmp ("or_eq", token_buffer) == 0) | |
3632 | { | |
3633 | yylval.code = BIT_IOR_EXPR; | |
3634 | token_buffer[0] = '|'; | |
3635 | } | |
3636 | else if (strcmp ("xor_eq", token_buffer) == 0) | |
3637 | { | |
3638 | yylval.code = BIT_XOR_EXPR; | |
3639 | token_buffer[0] = '^'; | |
3640 | } | |
3641 | token_buffer[1] = '='; | |
3642 | token_buffer[2] = 0; | |
3643 | break; | |
66a6250f | 3644 | |
1ceb5ff3 JM |
3645 | case '&': |
3646 | yylval.code = BIT_AND_EXPR; | |
3647 | token_buffer[0] = '&'; | |
3648 | token_buffer[1] = 0; | |
3649 | break; | |
66a6250f | 3650 | |
1ceb5ff3 JM |
3651 | case '|': |
3652 | yylval.code = BIT_IOR_EXPR; | |
3653 | token_buffer[0] = '|'; | |
3654 | token_buffer[1] = 0; | |
3655 | break; | |
66a6250f | 3656 | |
1ceb5ff3 JM |
3657 | case '^': |
3658 | yylval.code = BIT_XOR_EXPR; | |
3659 | token_buffer[0] = '^'; | |
3660 | token_buffer[1] = 0; | |
3661 | break; | |
3662 | } | |
db5ae43f | 3663 | |
1ceb5ff3 JM |
3664 | value = (int) ptr->token; |
3665 | } | |
3666 | } | |
8d08fdba | 3667 | |
1ceb5ff3 JM |
3668 | /* If we did not find a keyword, look for an identifier |
3669 | (or a typename). */ | |
8d08fdba | 3670 | |
1ceb5ff3 JM |
3671 | if (value == IDENTIFIER || value == TYPESPEC) |
3672 | GNU_xref_ref (current_function_decl, token_buffer); | |
8d08fdba | 3673 | |
1ceb5ff3 JM |
3674 | if (value == IDENTIFIER) |
3675 | { | |
3676 | register tree tmp = get_identifier (token_buffer); | |
8d08fdba MS |
3677 | |
3678 | #if !defined(VMS) && defined(JOINER) | |
1ceb5ff3 JM |
3679 | /* Make sure that user does not collide with our internal |
3680 | naming scheme. */ | |
3681 | if (JOINER == '$' | |
3682 | && (THIS_NAME_P (tmp) | |
3683 | || VPTR_NAME_P (tmp) | |
3684 | || DESTRUCTOR_NAME_P (tmp) | |
3685 | || VTABLE_NAME_P (tmp) | |
3686 | || TEMP_NAME_P (tmp) | |
3687 | || ANON_AGGRNAME_P (tmp) | |
3688 | || ANON_PARMNAME_P (tmp))) | |
3689 | warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy", | |
3690 | token_buffer); | |
8d08fdba MS |
3691 | #endif |
3692 | ||
1ceb5ff3 JM |
3693 | yylval.ttype = tmp; |
3694 | } | |
3695 | if (value == NEW && ! global_bindings_p ()) | |
3696 | { | |
3697 | value = NEW; | |
3698 | goto done; | |
3699 | } | |
8d08fdba MS |
3700 | break; |
3701 | ||
3702 | case '.': | |
66a6250f JM |
3703 | #if USE_CPPLIB |
3704 | if (yy_cur < yy_lim) | |
3705 | #endif | |
3706 | { | |
3707 | /* It's hard to preserve tokenization on '.' because | |
3708 | it could be a symbol by itself, or it could be the | |
3709 | start of a floating point number and cpp won't tell us. */ | |
3710 | register int c1 = token_getch (); | |
3711 | token_buffer[1] = c1; | |
3712 | if (c1 == '*') | |
3713 | { | |
3714 | value = DOT_STAR; | |
3715 | token_buffer[2] = 0; | |
3716 | goto done; | |
3717 | } | |
3718 | if (c1 == '.') | |
3719 | { | |
3720 | c1 = token_getch (); | |
3721 | if (c1 == '.') | |
3722 | { | |
3723 | token_buffer[2] = c1; | |
3724 | token_buffer[3] = 0; | |
3725 | value = ELLIPSIS; | |
3726 | goto done; | |
3727 | } | |
3728 | error ("parse error at `..'"); | |
3729 | } | |
3730 | if (ISDIGIT (c1)) | |
3731 | { | |
3732 | token_put_back (c1); | |
1ceb5ff3 | 3733 | goto number; |
66a6250f JM |
3734 | } |
3735 | token_put_back (c1); | |
3736 | } | |
3737 | value = '.'; | |
3738 | token_buffer[1] = 0; | |
1ceb5ff3 | 3739 | break; |
66a6250f | 3740 | |
8d08fdba | 3741 | case '0': case '1': |
66a6250f | 3742 | /* Optimize for most frequent case. */ |
8d08fdba | 3743 | { |
66a6250f JM |
3744 | register int cond; |
3745 | ||
3746 | #if USE_CPPLIB | |
3747 | cond = (yy_cur == yy_lim); | |
3748 | #else | |
3749 | register int c1 = token_getch (); | |
3750 | token_put_back (c1); | |
3751 | cond = (! ISALNUM (c1) && c1 != '.'); | |
3752 | #endif | |
3753 | if (cond) | |
8d08fdba | 3754 | { |
1ceb5ff3 | 3755 | yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node; |
8d08fdba | 3756 | value = CONSTANT; |
1ceb5ff3 | 3757 | break; |
8d08fdba | 3758 | } |
1ceb5ff3 | 3759 | /*FALLTHRU*/ |
8d08fdba | 3760 | } |
1ceb5ff3 | 3761 | case '2': case '3': case '4': |
8d08fdba | 3762 | case '5': case '6': case '7': case '8': case '9': |
1ceb5ff3 | 3763 | number: |
8d08fdba | 3764 | { |
8d08fdba MS |
3765 | int base = 10; |
3766 | int count = 0; | |
3767 | int largest_digit = 0; | |
3768 | int numdigits = 0; | |
8d08fdba MS |
3769 | int overflow = 0; |
3770 | ||
cc144655 GRK |
3771 | /* We actually store only HOST_BITS_PER_CHAR bits in each part. |
3772 | The code below which fills the parts array assumes that a host | |
3773 | int is at least twice as wide as a host char, and that | |
3774 | HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR. | |
3775 | Two HOST_WIDE_INTs is the largest int literal we can store. | |
3776 | In order to detect overflow below, the number of parts (TOTAL_PARTS) | |
3777 | must be exactly the number of parts needed to hold the bits | |
3778 | of two HOST_WIDE_INTs. */ | |
3779 | #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2) | |
3780 | unsigned int parts[TOTAL_PARTS]; | |
3781 | ||
1ceb5ff3 JM |
3782 | enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON } |
3783 | floatflag = NOT_FLOAT; | |
8d08fdba | 3784 | |
8d08fdba MS |
3785 | for (count = 0; count < TOTAL_PARTS; count++) |
3786 | parts[count] = 0; | |
3787 | ||
37c46b43 MS |
3788 | p = token_buffer; |
3789 | *p++ = c; | |
3790 | ||
8d08fdba MS |
3791 | if (c == '0') |
3792 | { | |
66a6250f | 3793 | *p++ = (c = token_getch ()); |
8d08fdba MS |
3794 | if ((c == 'x') || (c == 'X')) |
3795 | { | |
3796 | base = 16; | |
66a6250f | 3797 | *p++ = (c = token_getch ()); |
8d08fdba MS |
3798 | } |
3799 | /* Leading 0 forces octal unless the 0 is the only digit. */ | |
3800 | else if (c >= '0' && c <= '9') | |
3801 | { | |
3802 | base = 8; | |
3803 | numdigits++; | |
3804 | } | |
3805 | else | |
3806 | numdigits++; | |
3807 | } | |
3808 | ||
3809 | /* Read all the digits-and-decimal-points. */ | |
3810 | ||
3811 | while (c == '.' | |
1ceb5ff3 JM |
3812 | || (ISALNUM (c) && c != 'l' && c != 'L' |
3813 | && c != 'u' && c != 'U' | |
37c46b43 | 3814 | && c != 'i' && c != 'I' && c != 'j' && c != 'J' |
5630b463 SM |
3815 | && (floatflag == NOT_FLOAT |
3816 | || ((base != 16) && (c != 'f') && (c != 'F')) | |
3817 | || base == 16))) | |
8d08fdba MS |
3818 | { |
3819 | if (c == '.') | |
3820 | { | |
1ceb5ff3 JM |
3821 | if (base == 16 && pedantic) |
3822 | pedwarn ("floating constant may not be in radix 16"); | |
37c46b43 MS |
3823 | if (floatflag == TOO_MANY_POINTS) |
3824 | /* We have already emitted an error. Don't need another. */ | |
3825 | ; | |
1ceb5ff3 | 3826 | else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON) |
8d08fdba | 3827 | { |
8251199e | 3828 | error ("malformed floating constant"); |
8d08fdba | 3829 | floatflag = TOO_MANY_POINTS; |
37c46b43 MS |
3830 | /* Avoid another error from atof by forcing all characters |
3831 | from here on to be ignored. */ | |
3832 | p[-1] = '\0'; | |
8d08fdba MS |
3833 | } |
3834 | else | |
3835 | floatflag = AFTER_POINT; | |
3836 | ||
1ceb5ff3 JM |
3837 | if (base == 8) |
3838 | base = 10; | |
66a6250f | 3839 | *p++ = c = token_getch (); |
8d08fdba | 3840 | /* Accept '.' as the start of a floating-point number |
66a6250f | 3841 | only when it is followed by a digit. */ |
faa25e97 | 3842 | if (p == token_buffer + 2 && !ISDIGIT (c)) |
66a6250f | 3843 | my_friendly_abort (990710); |
8d08fdba MS |
3844 | } |
3845 | else | |
3846 | { | |
3847 | /* It is not a decimal point. | |
3848 | It should be a digit (perhaps a hex digit). */ | |
3849 | ||
faa25e97 | 3850 | if (ISDIGIT (c)) |
8d08fdba MS |
3851 | { |
3852 | c = c - '0'; | |
3853 | } | |
3854 | else if (base <= 10) | |
3855 | { | |
3856 | if (c == 'e' || c == 'E') | |
3857 | { | |
3858 | base = 10; | |
1ceb5ff3 | 3859 | floatflag = AFTER_EXPON; |
8d08fdba MS |
3860 | break; /* start of exponent */ |
3861 | } | |
8251199e | 3862 | error ("nondigits in number and not hexadecimal"); |
8d08fdba MS |
3863 | c = 0; |
3864 | } | |
1ceb5ff3 JM |
3865 | else if (base == 16 && (c == 'p' || c == 'P')) |
3866 | { | |
3867 | floatflag = AFTER_EXPON; | |
3868 | break; /* start of exponent */ | |
3869 | } | |
8d08fdba MS |
3870 | else if (c >= 'a') |
3871 | { | |
3872 | c = c - 'a' + 10; | |
3873 | } | |
3874 | else | |
3875 | { | |
3876 | c = c - 'A' + 10; | |
3877 | } | |
3878 | if (c >= largest_digit) | |
3879 | largest_digit = c; | |
3880 | numdigits++; | |
3881 | ||
3882 | for (count = 0; count < TOTAL_PARTS; count++) | |
3883 | { | |
3884 | parts[count] *= base; | |
3885 | if (count) | |
3886 | { | |
3887 | parts[count] | |
3888 | += (parts[count-1] >> HOST_BITS_PER_CHAR); | |
3889 | parts[count-1] | |
3890 | &= (1 << HOST_BITS_PER_CHAR) - 1; | |
3891 | } | |
3892 | else | |
3893 | parts[0] += c; | |
3894 | } | |
3895 | ||
cc144655 GRK |
3896 | /* If the highest-order part overflows (gets larger than |
3897 | a host char will hold) then the whole number has | |
3898 | overflowed. Record this and truncate the highest-order | |
3899 | part. */ | |
3900 | if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR) | |
3901 | { | |
3902 | overflow = 1; | |
3903 | parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1; | |
3904 | } | |
8d08fdba MS |
3905 | |
3906 | if (p >= token_buffer + maxtoken - 3) | |
3907 | p = extend_token_buffer (p); | |
66a6250f | 3908 | *p++ = (c = token_getch ()); |
8d08fdba MS |
3909 | } |
3910 | } | |
3911 | ||
6ad07332 | 3912 | /* This can happen on input like `int i = 0x;' */ |
8d08fdba | 3913 | if (numdigits == 0) |
6ad07332 | 3914 | error ("numeric constant with no digits"); |
8d08fdba MS |
3915 | |
3916 | if (largest_digit >= base) | |
8251199e | 3917 | error ("numeric constant contains digits beyond the radix"); |
8d08fdba | 3918 | |
66a6250f JM |
3919 | /* Remove terminating char from the token buffer and delimit the |
3920 | string. */ | |
8d08fdba MS |
3921 | *--p = 0; |
3922 | ||
3923 | if (floatflag != NOT_FLOAT) | |
3924 | { | |
1ceb5ff3 JM |
3925 | tree type; |
3926 | int imag, conversion_errno; | |
8d08fdba | 3927 | REAL_VALUE_TYPE value; |
9b2bf201 | 3928 | struct pf_args args; |
8d08fdba MS |
3929 | |
3930 | /* Read explicit exponent if any, and put it in tokenbuf. */ | |
3931 | ||
1ceb5ff3 JM |
3932 | if ((base == 10 && ((c == 'e') || (c == 'E'))) |
3933 | || (base == 16 && (c == 'p' || c == 'P'))) | |
8d08fdba MS |
3934 | { |
3935 | if (p >= token_buffer + maxtoken - 3) | |
3936 | p = extend_token_buffer (p); | |
3937 | *p++ = c; | |
66a6250f | 3938 | c = token_getch (); |
8d08fdba MS |
3939 | if ((c == '+') || (c == '-')) |
3940 | { | |
3941 | *p++ = c; | |
66a6250f | 3942 | c = token_getch (); |
8d08fdba | 3943 | } |
1ceb5ff3 | 3944 | /* Exponent is decimal, even if string is a hex float. */ |
faa25e97 | 3945 | if (! ISDIGIT (c)) |
8251199e | 3946 | error ("floating constant exponent has no digits"); |
1ceb5ff3 | 3947 | while (ISDIGIT (c)) |
8d08fdba MS |
3948 | { |
3949 | if (p >= token_buffer + maxtoken - 3) | |
3950 | p = extend_token_buffer (p); | |
3951 | *p++ = c; | |
66a6250f | 3952 | c = token_getch (); |
8d08fdba MS |
3953 | } |
3954 | } | |
1ceb5ff3 JM |
3955 | if (base == 16 && floatflag != AFTER_EXPON) |
3956 | error ("hexadecimal floating constant has no exponent"); | |
8d08fdba MS |
3957 | |
3958 | *p = 0; | |
8d08fdba | 3959 | |
9b2bf201 | 3960 | /* Setup input for parse_float() */ |
1ceb5ff3 | 3961 | args.base = base; |
9b2bf201 KG |
3962 | args.p = p; |
3963 | args.c = c; | |
1ceb5ff3 | 3964 | |
8d08fdba | 3965 | /* Convert string to a double, checking for overflow. */ |
9b2bf201 | 3966 | if (do_float_handler (parse_float, (PTR) &args)) |
8d08fdba | 3967 | { |
9b2bf201 KG |
3968 | /* Receive output from parse_float() */ |
3969 | value = args.value; | |
8d08fdba MS |
3970 | } |
3971 | else | |
3972 | { | |
9b2bf201 KG |
3973 | /* We got an exception from parse_float() */ |
3974 | error ("floating constant out of range"); | |
3975 | value = dconst0; | |
8d08fdba | 3976 | } |
9b2bf201 KG |
3977 | |
3978 | /* Receive output from parse_float() */ | |
9b2bf201 KG |
3979 | c = args.c; |
3980 | imag = args.imag; | |
3981 | type = args.type; | |
1ceb5ff3 | 3982 | conversion_errno = args.conversion_errno; |
9b2bf201 | 3983 | |
8d08fdba | 3984 | #ifdef ERANGE |
1ceb5ff3 JM |
3985 | /* ERANGE is also reported for underflow, |
3986 | so test the value to distinguish overflow from that. */ | |
3987 | if (conversion_errno == ERANGE && pedantic | |
3988 | && (REAL_VALUES_LESS (dconst1, value) | |
3989 | || REAL_VALUES_LESS (value, dconstm1))) | |
3990 | warning ("floating point number exceeds range of `double'"); | |
37c46b43 | 3991 | #endif |
8d08fdba | 3992 | |
37c46b43 MS |
3993 | /* If the result is not a number, assume it must have been |
3994 | due to some error message above, so silently convert | |
3995 | it to a zero. */ | |
3996 | if (REAL_VALUE_ISNAN (value)) | |
3997 | value = dconst0; | |
8d08fdba MS |
3998 | |
3999 | /* Create a node with determined type and value. */ | |
37c46b43 MS |
4000 | if (imag) |
4001 | yylval.ttype = build_complex (NULL_TREE, | |
1ceb5ff3 | 4002 | convert (type, integer_zero_node), |
37c46b43 MS |
4003 | build_real (type, value)); |
4004 | else | |
4005 | yylval.ttype = build_real (type, value); | |
8d08fdba MS |
4006 | } |
4007 | else | |
4008 | { | |
4009 | tree type; | |
4010 | HOST_WIDE_INT high, low; | |
4011 | int spec_unsigned = 0; | |
4012 | int spec_long = 0; | |
4013 | int spec_long_long = 0; | |
37c46b43 | 4014 | int spec_imag = 0; |
9dfce8fd JM |
4015 | int warn = 0; |
4016 | int i; | |
8d08fdba MS |
4017 | |
4018 | while (1) | |
4019 | { | |
4020 | if (c == 'u' || c == 'U') | |
4021 | { | |
4022 | if (spec_unsigned) | |
8251199e | 4023 | error ("two `u's in integer constant"); |
8d08fdba MS |
4024 | spec_unsigned = 1; |
4025 | } | |
4026 | else if (c == 'l' || c == 'L') | |
4027 | { | |
4028 | if (spec_long) | |
4029 | { | |
4030 | if (spec_long_long) | |
8251199e | 4031 | error ("three `l's in integer constant"); |
31928556 | 4032 | else if (pedantic && ! in_system_header && warn_long_long) |
cab1f180 | 4033 | pedwarn ("ISO C++ forbids long long integer constants"); |
8d08fdba MS |
4034 | spec_long_long = 1; |
4035 | } | |
4036 | spec_long = 1; | |
4037 | } | |
37c46b43 | 4038 | else if (c == 'i' || c == 'j' || c == 'I' || c == 'J') |
8d08fdba | 4039 | { |
37c46b43 | 4040 | if (spec_imag) |
8251199e | 4041 | error ("more than one `i' or `j' in numeric constant"); |
37c46b43 | 4042 | else if (pedantic) |
cab1f180 | 4043 | pedwarn ("ISO C++ forbids imaginary numeric constants"); |
37c46b43 | 4044 | spec_imag = 1; |
8d08fdba | 4045 | } |
37c46b43 MS |
4046 | else |
4047 | break; | |
8d08fdba MS |
4048 | if (p >= token_buffer + maxtoken - 3) |
4049 | p = extend_token_buffer (p); | |
4050 | *p++ = c; | |
66a6250f | 4051 | c = token_getch (); |
8d08fdba MS |
4052 | } |
4053 | ||
cc144655 GRK |
4054 | /* If the literal overflowed, pedwarn about it now. */ |
4055 | if (overflow) | |
4056 | { | |
4057 | warn = 1; | |
4058 | pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2); | |
4059 | } | |
8d08fdba MS |
4060 | |
4061 | /* This is simplified by the fact that our constant | |
4062 | is always positive. */ | |
1ceb5ff3 | 4063 | |
8d08fdba MS |
4064 | high = low = 0; |
4065 | ||
4066 | for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++) | |
4067 | { | |
4068 | high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT | |
4069 | / HOST_BITS_PER_CHAR)] | |
4070 | << (i * HOST_BITS_PER_CHAR)); | |
4071 | low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR); | |
4072 | } | |
1ceb5ff3 | 4073 | |
8d08fdba MS |
4074 | yylval.ttype = build_int_2 (low, high); |
4075 | TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node; | |
4076 | ||
a3f44a13 | 4077 | /* Calculate the ANSI type. */ |
1ceb5ff3 | 4078 | if (! spec_long && ! spec_unsigned |
8d08fdba | 4079 | && int_fits_type_p (yylval.ttype, integer_type_node)) |
a3f44a13 | 4080 | type = integer_type_node; |
1ceb5ff3 | 4081 | else if (! spec_long && (base != 10 || spec_unsigned) |
8d08fdba | 4082 | && int_fits_type_p (yylval.ttype, unsigned_type_node)) |
a3f44a13 | 4083 | type = unsigned_type_node; |
1ceb5ff3 | 4084 | else if (! spec_unsigned && !spec_long_long |
8d08fdba MS |
4085 | && int_fits_type_p (yylval.ttype, long_integer_type_node)) |
4086 | type = long_integer_type_node; | |
1ceb5ff3 JM |
4087 | else if (! spec_long_long |
4088 | && int_fits_type_p (yylval.ttype, | |
4089 | long_unsigned_type_node)) | |
d22c8596 | 4090 | type = long_unsigned_type_node; |
8d08fdba | 4091 | else if (! spec_unsigned |
8d08fdba MS |
4092 | && int_fits_type_p (yylval.ttype, |
4093 | long_long_integer_type_node)) | |
4094 | type = long_long_integer_type_node; | |
835f9b4d GRK |
4095 | else if (int_fits_type_p (yylval.ttype, |
4096 | long_long_unsigned_type_node)) | |
d22c8596 | 4097 | type = long_long_unsigned_type_node; |
835f9b4d GRK |
4098 | else if (! spec_unsigned |
4099 | && int_fits_type_p (yylval.ttype, | |
4100 | widest_integer_literal_type_node)) | |
4101 | type = widest_integer_literal_type_node; | |
4102 | else | |
4103 | type = widest_unsigned_literal_type_node; | |
8d08fdba | 4104 | |
1ceb5ff3 JM |
4105 | if (pedantic && !spec_long_long && !warn |
4106 | && (TYPE_PRECISION (long_integer_type_node) | |
4107 | < TYPE_PRECISION (type))) | |
4108 | { | |
4109 | warn = 1; | |
4110 | pedwarn ("integer constant larger than the maximum value of an unsigned long int"); | |
4111 | } | |
8d08fdba | 4112 | |
a3f44a13 | 4113 | if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type)) |
1ceb5ff3 | 4114 | warning ("decimal constant is so large that it is unsigned"); |
8d08fdba | 4115 | |
a3f44a13 BK |
4116 | if (spec_imag) |
4117 | { | |
4118 | if (TYPE_PRECISION (type) | |
4119 | <= TYPE_PRECISION (integer_type_node)) | |
4120 | yylval.ttype | |
4121 | = build_complex (NULL_TREE, integer_zero_node, | |
1ceb5ff3 JM |
4122 | convert (integer_type_node, |
4123 | yylval.ttype)); | |
a3f44a13 | 4124 | else |
8251199e | 4125 | error ("complex integer constant is too wide for `__complex int'"); |
a3f44a13 BK |
4126 | } |
4127 | else | |
4128 | TREE_TYPE (yylval.ttype) = type; | |
1ceb5ff3 JM |
4129 | |
4130 | ||
4131 | /* If it's still an integer (not a complex), and it doesn't | |
4132 | fit in the type we choose for it, then pedwarn. */ | |
4133 | ||
4134 | if (! warn | |
4135 | && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE | |
4136 | && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype))) | |
4137 | pedwarn ("integer constant is larger than the maximum value for its type"); | |
8d08fdba MS |
4138 | } |
4139 | ||
66a6250f | 4140 | token_put_back (c); |
37c46b43 MS |
4141 | *p = 0; |
4142 | ||
1ceb5ff3 JM |
4143 | if (ISALNUM (c) || c == '.' || c == '_' || c == '$' |
4144 | || ((c == '-' || c == '+') | |
4145 | && (p[-1] == 'e' || p[-1] == 'E'))) | |
4146 | error ("missing white space after number `%s'", token_buffer); | |
4147 | ||
8d08fdba MS |
4148 | value = CONSTANT; break; |
4149 | } | |
4150 | ||
4151 | case '\'': | |
4152 | char_constant: | |
4153 | { | |
4154 | register int result = 0; | |
4155 | register int num_chars = 0; | |
0d3ba739 | 4156 | int chars_seen = 0; |
8d08fdba MS |
4157 | unsigned width = TYPE_PRECISION (char_type_node); |
4158 | int max_chars; | |
8d08fdba | 4159 | #ifdef MULTIBYTE_CHARS |
0d3ba739 | 4160 | int longest_char = local_mb_cur_max (); |
66a6250f | 4161 | local_mbtowc (NULL_PTR, NULL_PTR, 0); |
8d08fdba | 4162 | #endif |
0d3ba739 DB |
4163 | |
4164 | max_chars = TYPE_PRECISION (integer_type_node) / width; | |
4165 | if (wide_flag) | |
4166 | width = WCHAR_TYPE_SIZE; | |
8d08fdba MS |
4167 | |
4168 | while (1) | |
4169 | { | |
4170 | tryagain: | |
66a6250f | 4171 | c = token_getch (); |
8d08fdba MS |
4172 | |
4173 | if (c == '\'' || c == EOF) | |
4174 | break; | |
4175 | ||
0d3ba739 | 4176 | ++chars_seen; |
8d08fdba MS |
4177 | if (c == '\\') |
4178 | { | |
4179 | int ignore = 0; | |
4180 | c = readescape (&ignore); | |
4181 | if (ignore) | |
4182 | goto tryagain; | |
4183 | if (width < HOST_BITS_PER_INT | |
b370501f | 4184 | && (unsigned) c >= ((unsigned)1 << width)) |
8251199e | 4185 | pedwarn ("escape sequence out of range for character"); |
8d08fdba | 4186 | #ifdef MAP_CHARACTER |
faa25e97 | 4187 | if (ISPRINT (c)) |
8d08fdba MS |
4188 | c = MAP_CHARACTER (c); |
4189 | #endif | |
4190 | } | |
4191 | else if (c == '\n') | |
4192 | { | |
4193 | if (pedantic) | |
cab1f180 | 4194 | pedwarn ("ISO C++ forbids newline in character constant"); |
8d08fdba MS |
4195 | lineno++; |
4196 | } | |
8d08fdba | 4197 | else |
0d3ba739 DB |
4198 | { |
4199 | #ifdef MULTIBYTE_CHARS | |
4200 | wchar_t wc; | |
4201 | int i; | |
4202 | int char_len = -1; | |
4203 | for (i = 1; i <= longest_char; ++i) | |
4204 | { | |
4205 | if (i > maxtoken - 4) | |
4206 | extend_token_buffer (token_buffer); | |
4207 | ||
4208 | token_buffer[i] = c; | |
4209 | char_len = local_mbtowc (& wc, | |
4210 | token_buffer + 1, | |
4211 | i); | |
4212 | if (char_len != -1) | |
4213 | break; | |
66a6250f | 4214 | c = token_getch (); |
0d3ba739 DB |
4215 | } |
4216 | if (char_len > 1) | |
4217 | { | |
4218 | /* mbtowc sometimes needs an extra char before accepting */ | |
4219 | if (char_len < i) | |
66a6250f | 4220 | token_put_back (c); |
0d3ba739 DB |
4221 | if (! wide_flag) |
4222 | { | |
4223 | /* Merge character into result; ignore excess chars. */ | |
4224 | for (i = 1; i <= char_len; ++i) | |
4225 | { | |
4226 | if (i > max_chars) | |
4227 | break; | |
4228 | if (width < HOST_BITS_PER_INT) | |
4229 | result = (result << width) | |
4230 | | (token_buffer[i] | |
4231 | & ((1 << width) - 1)); | |
4232 | else | |
4233 | result = token_buffer[i]; | |
4234 | } | |
4235 | num_chars += char_len; | |
4236 | goto tryagain; | |
4237 | } | |
4238 | c = wc; | |
4239 | } | |
4240 | else | |
4241 | { | |
4242 | if (char_len == -1) | |
cd28936c DB |
4243 | { |
4244 | warning ("Ignoring invalid multibyte character"); | |
4245 | /* Replace all but the first byte. */ | |
4246 | for (--i; i > 1; --i) | |
66a6250f | 4247 | token_put_back (token_buffer[i]); |
cd28936c DB |
4248 | wc = token_buffer[1]; |
4249 | } | |
0d3ba739 | 4250 | #ifdef MAP_CHARACTER |
cd28936c DB |
4251 | c = MAP_CHARACTER (wc); |
4252 | #else | |
4253 | c = wc; | |
8d08fdba | 4254 | #endif |
0d3ba739 DB |
4255 | } |
4256 | #else /* ! MULTIBYTE_CHARS */ | |
4257 | #ifdef MAP_CHARACTER | |
4258 | c = MAP_CHARACTER (c); | |
4259 | #endif | |
4260 | #endif /* ! MULTIBYTE_CHARS */ | |
4261 | } | |
8d08fdba | 4262 | |
0d3ba739 DB |
4263 | if (wide_flag) |
4264 | { | |
4265 | if (chars_seen == 1) /* only keep the first one */ | |
4266 | result = c; | |
4267 | goto tryagain; | |
4268 | } | |
8d08fdba MS |
4269 | |
4270 | /* Merge character into result; ignore excess chars. */ | |
1ceb5ff3 | 4271 | num_chars += (width / TYPE_PRECISION (char_type_node)); |
8d08fdba MS |
4272 | if (num_chars < max_chars + 1) |
4273 | { | |
4274 | if (width < HOST_BITS_PER_INT) | |
4275 | result = (result << width) | (c & ((1 << width) - 1)); | |
4276 | else | |
4277 | result = c; | |
4278 | } | |
4279 | } | |
4280 | ||
8d08fdba | 4281 | if (c != '\'') |
8251199e | 4282 | error ("malformatted character constant"); |
0d3ba739 | 4283 | else if (chars_seen == 0) |
8251199e | 4284 | error ("empty character constant"); |
8d08fdba MS |
4285 | else if (num_chars > max_chars) |
4286 | { | |
4287 | num_chars = max_chars; | |
8251199e | 4288 | error ("character constant too long"); |
8d08fdba | 4289 | } |
0d3ba739 | 4290 | else if (chars_seen != 1 && warn_multichar) |
8251199e | 4291 | warning ("multi-character character constant"); |
8d08fdba MS |
4292 | |
4293 | /* If char type is signed, sign-extend the constant. */ | |
4294 | if (! wide_flag) | |
4295 | { | |
4296 | int num_bits = num_chars * width; | |
4297 | if (num_bits == 0) | |
4298 | /* We already got an error; avoid invalid shift. */ | |
4299 | yylval.ttype = build_int_2 (0, 0); | |
4300 | else if (TREE_UNSIGNED (char_type_node) | |
4301 | || ((result >> (num_bits - 1)) & 1) == 0) | |
4302 | yylval.ttype | |
0d3ba739 | 4303 | = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0 |
c6a29b1f | 4304 | >> (HOST_BITS_PER_WIDE_INT - num_bits)), |
8d08fdba MS |
4305 | 0); |
4306 | else | |
4307 | yylval.ttype | |
0d3ba739 | 4308 | = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0 |
c6a29b1f | 4309 | >> (HOST_BITS_PER_WIDE_INT - num_bits)), |
8d08fdba | 4310 | -1); |
1ceb5ff3 | 4311 | /* In C, a character constant has type 'int'; in C++, 'char'. */ |
0d3ba739 | 4312 | if (chars_seen <= 1) |
8d08fdba MS |
4313 | TREE_TYPE (yylval.ttype) = char_type_node; |
4314 | else | |
4315 | TREE_TYPE (yylval.ttype) = integer_type_node; | |
4316 | } | |
4317 | else | |
4318 | { | |
8d08fdba MS |
4319 | yylval.ttype = build_int_2 (result, 0); |
4320 | TREE_TYPE (yylval.ttype) = wchar_type_node; | |
4321 | } | |
4322 | ||
4323 | value = CONSTANT; | |
4324 | break; | |
4325 | } | |
4326 | ||
4327 | case '"': | |
4328 | string_constant: | |
4329 | { | |
0d3ba739 DB |
4330 | unsigned width = wide_flag ? WCHAR_TYPE_SIZE |
4331 | : TYPE_PRECISION (char_type_node); | |
4332 | #ifdef MULTIBYTE_CHARS | |
4333 | int longest_char = local_mb_cur_max (); | |
66a6250f | 4334 | local_mbtowc (NULL_PTR, NULL_PTR, 0); |
0d3ba739 | 4335 | #endif |
8d08fdba | 4336 | |
66a6250f | 4337 | c = token_getch (); |
8d08fdba MS |
4338 | p = token_buffer + 1; |
4339 | ||
66a6250f | 4340 | while (c != '"' && c != EOF) |
8d08fdba MS |
4341 | { |
4342 | /* ignore_escape_flag is set for reading the filename in #line. */ | |
4343 | if (!ignore_escape_flag && c == '\\') | |
4344 | { | |
4345 | int ignore = 0; | |
4346 | c = readescape (&ignore); | |
4347 | if (ignore) | |
4348 | goto skipnewline; | |
0d3ba739 | 4349 | if (width < HOST_BITS_PER_INT |
b370501f | 4350 | && (unsigned) c >= ((unsigned)1 << width)) |
1ceb5ff3 | 4351 | pedwarn ("escape sequence out of range for character"); |
8d08fdba MS |
4352 | } |
4353 | else if (c == '\n') | |
4354 | { | |
4355 | if (pedantic) | |
cab1f180 | 4356 | pedwarn ("ISO C++ forbids newline in string constant"); |
8d08fdba MS |
4357 | lineno++; |
4358 | } | |
0d3ba739 DB |
4359 | else |
4360 | { | |
4361 | #ifdef MULTIBYTE_CHARS | |
4362 | wchar_t wc; | |
4363 | int i; | |
4364 | int char_len = -1; | |
4365 | for (i = 0; i < longest_char; ++i) | |
4366 | { | |
ea6c1142 | 4367 | if (p + i >= token_buffer + maxtoken) |
0d3ba739 DB |
4368 | p = extend_token_buffer (p); |
4369 | p[i] = c; | |
4370 | ||
4371 | char_len = local_mbtowc (& wc, p, i + 1); | |
4372 | if (char_len != -1) | |
4373 | break; | |
66a6250f | 4374 | c = token_getch (); |
0d3ba739 DB |
4375 | } |
4376 | if (char_len == -1) | |
0d3ba739 | 4377 | { |
cd28936c DB |
4378 | warning ("Ignoring invalid multibyte character"); |
4379 | /* Replace all except the first byte. */ | |
66a6250f | 4380 | token_put_back (c); |
cd28936c | 4381 | for (--i; i > 0; --i) |
66a6250f | 4382 | token_put_back (p[i]); |
cd28936c DB |
4383 | char_len = 1; |
4384 | } | |
4385 | /* mbtowc sometimes needs an extra char before accepting */ | |
4386 | if (char_len <= i) | |
66a6250f | 4387 | token_put_back (c); |
cd28936c DB |
4388 | if (! wide_flag) |
4389 | { | |
4390 | p += (i + 1); | |
66a6250f | 4391 | c = token_getch (); |
cd28936c | 4392 | continue; |
0d3ba739 | 4393 | } |
cd28936c | 4394 | c = wc; |
0d3ba739 DB |
4395 | #endif /* MULTIBYTE_CHARS */ |
4396 | } | |
8d08fdba | 4397 | |
0d3ba739 DB |
4398 | /* Add this single character into the buffer either as a wchar_t |
4399 | or as a single byte. */ | |
4400 | if (wide_flag) | |
4401 | { | |
4402 | unsigned width = TYPE_PRECISION (char_type_node); | |
4403 | unsigned bytemask = (1 << width) - 1; | |
4404 | int byte; | |
4405 | ||
ea6c1142 | 4406 | if (p + WCHAR_BYTES > token_buffer + maxtoken) |
0d3ba739 DB |
4407 | p = extend_token_buffer (p); |
4408 | ||
4409 | for (byte = 0; byte < WCHAR_BYTES; ++byte) | |
4410 | { | |
4411 | int value; | |
1ceb5ff3 | 4412 | if (byte >= (int) sizeof (c)) |
0d3ba739 DB |
4413 | value = 0; |
4414 | else | |
4415 | value = (c >> (byte * width)) & bytemask; | |
4416 | if (BYTES_BIG_ENDIAN) | |
4417 | p[WCHAR_BYTES - byte - 1] = value; | |
4418 | else | |
4419 | p[byte] = value; | |
4420 | } | |
4421 | p += WCHAR_BYTES; | |
4422 | } | |
4423 | else | |
4424 | { | |
ea6c1142 | 4425 | if (p >= token_buffer + maxtoken) |
0d3ba739 DB |
4426 | p = extend_token_buffer (p); |
4427 | *p++ = c; | |
4428 | } | |
8d08fdba MS |
4429 | |
4430 | skipnewline: | |
66a6250f | 4431 | c = token_getch (); |
8d08fdba | 4432 | } |
8d08fdba | 4433 | |
0d3ba739 DB |
4434 | /* Terminate the string value, either with a single byte zero |
4435 | or with a wide zero. */ | |
8d08fdba MS |
4436 | if (wide_flag) |
4437 | { | |
ea6c1142 | 4438 | if (p + WCHAR_BYTES > token_buffer + maxtoken) |
0d3ba739 DB |
4439 | p = extend_token_buffer (p); |
4440 | bzero (p, WCHAR_BYTES); | |
4441 | p += WCHAR_BYTES; | |
8d08fdba MS |
4442 | } |
4443 | else | |
4444 | { | |
ea6c1142 | 4445 | if (p >= token_buffer + maxtoken) |
0d3ba739 DB |
4446 | p = extend_token_buffer (p); |
4447 | *p++ = 0; | |
8d08fdba MS |
4448 | } |
4449 | ||
1ceb5ff3 JM |
4450 | if (c == EOF) |
4451 | error ("Unterminated string constant"); | |
4452 | ||
0d3ba739 DB |
4453 | /* We have read the entire constant. |
4454 | Construct a STRING_CST for the result. */ | |
4455 | ||
0d3ba739 | 4456 | yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1); |
0d3ba739 DB |
4457 | |
4458 | if (wide_flag) | |
4459 | TREE_TYPE (yylval.ttype) = wchar_array_type_node; | |
4460 | else | |
4461 | TREE_TYPE (yylval.ttype) = char_array_type_node; | |
8d08fdba MS |
4462 | |
4463 | value = STRING; break; | |
4464 | } | |
4465 | ||
4466 | case '+': | |
4467 | case '-': | |
4468 | case '&': | |
4469 | case '|': | |
1ceb5ff3 | 4470 | case ':': |
8d08fdba MS |
4471 | case '<': |
4472 | case '>': | |
4473 | case '*': | |
4474 | case '/': | |
4475 | case '%': | |
4476 | case '^': | |
4477 | case '!': | |
4478 | case '=': | |
4479 | { | |
4480 | register int c1; | |
4481 | ||
4482 | combine: | |
4483 | ||
4484 | switch (c) | |
4485 | { | |
4486 | case '+': | |
4487 | yylval.code = PLUS_EXPR; break; | |
4488 | case '-': | |
4489 | yylval.code = MINUS_EXPR; break; | |
4490 | case '&': | |
4491 | yylval.code = BIT_AND_EXPR; break; | |
4492 | case '|': | |
4493 | yylval.code = BIT_IOR_EXPR; break; | |
4494 | case '*': | |
4495 | yylval.code = MULT_EXPR; break; | |
4496 | case '/': | |
4497 | yylval.code = TRUNC_DIV_EXPR; break; | |
4498 | case '%': | |
4499 | yylval.code = TRUNC_MOD_EXPR; break; | |
4500 | case '^': | |
4501 | yylval.code = BIT_XOR_EXPR; break; | |
4502 | case LSHIFT: | |
4503 | yylval.code = LSHIFT_EXPR; break; | |
4504 | case RSHIFT: | |
4505 | yylval.code = RSHIFT_EXPR; break; | |
4506 | case '<': | |
4507 | yylval.code = LT_EXPR; break; | |
4508 | case '>': | |
4509 | yylval.code = GT_EXPR; break; | |
4510 | } | |
4511 | ||
66a6250f | 4512 | token_buffer[1] = c1 = token_getch (); |
8d08fdba MS |
4513 | token_buffer[2] = 0; |
4514 | ||
4515 | if (c1 == '=') | |
4516 | { | |
4517 | switch (c) | |
4518 | { | |
4519 | case '<': | |
4520 | value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done; | |
4521 | case '>': | |
4522 | value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done; | |
4523 | case '!': | |
4524 | value = EQCOMPARE; yylval.code = NE_EXPR; goto done; | |
4525 | case '=': | |
4526 | value = EQCOMPARE; yylval.code = EQ_EXPR; goto done; | |
4527 | } | |
4528 | value = ASSIGN; goto done; | |
4529 | } | |
4530 | else if (c == c1) | |
4531 | switch (c) | |
4532 | { | |
4533 | case '+': | |
4534 | value = PLUSPLUS; goto done; | |
4535 | case '-': | |
4536 | value = MINUSMINUS; goto done; | |
4537 | case '&': | |
4538 | value = ANDAND; goto done; | |
4539 | case '|': | |
4540 | value = OROR; goto done; | |
4541 | case '<': | |
4542 | c = LSHIFT; | |
4543 | goto combine; | |
4544 | case '>': | |
4545 | c = RSHIFT; | |
4546 | goto combine; | |
1ceb5ff3 JM |
4547 | case ':': |
4548 | value = SCOPE; | |
4549 | yylval.itype = 1; | |
4550 | goto done; | |
8d08fdba | 4551 | } |
8d08fdba MS |
4552 | else if (c1 == '?' && (c == '<' || c == '>')) |
4553 | { | |
4554 | token_buffer[3] = 0; | |
4555 | ||
66a6250f | 4556 | c1 = token_getch (); |
8d08fdba MS |
4557 | yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR); |
4558 | if (c1 == '=') | |
4559 | { | |
4560 | /* <?= or >?= expression. */ | |
4561 | token_buffer[2] = c1; | |
4562 | value = ASSIGN; | |
4563 | } | |
4564 | else | |
4565 | { | |
4566 | value = MIN_MAX; | |
66a6250f | 4567 | token_put_back (c1); |
8d08fdba | 4568 | } |
e1cd6e56 | 4569 | if (pedantic) |
8251199e | 4570 | pedwarn ("use of `operator %s' is not standard C++", |
2986ae00 | 4571 | token_buffer); |
8d08fdba MS |
4572 | goto done; |
4573 | } | |
1ceb5ff3 JM |
4574 | else |
4575 | switch (c) | |
4576 | { | |
4577 | case '-': | |
4578 | if (c1 == '>') | |
4579 | { | |
4580 | c1 = token_getch (); | |
4581 | if (c1 == '*') | |
4582 | value = POINTSAT_STAR; | |
4583 | else | |
4584 | { | |
4585 | token_put_back (c1); | |
4586 | value = POINTSAT; | |
4587 | } | |
4588 | goto done; | |
4589 | } | |
4590 | break; | |
4591 | ||
4592 | /* digraphs */ | |
4593 | case ':': | |
4594 | if (c1 == '>') | |
4595 | { value = ']'; goto done; } | |
4596 | break; | |
4597 | case '<': | |
4598 | if (c1 == '%') | |
4599 | { value = '{'; indent_level++; goto done; } | |
4600 | if (c1 == ':') | |
4601 | { value = '['; goto done; } | |
4602 | break; | |
4603 | case '%': | |
4604 | if (c1 == '>') | |
4605 | { value = '}'; indent_level--; goto done; } | |
4606 | break; | |
4607 | } | |
8d08fdba | 4608 | |
66a6250f | 4609 | token_put_back (c1); |
8d08fdba MS |
4610 | token_buffer[1] = 0; |
4611 | ||
1ceb5ff3 JM |
4612 | /* Here the C frontend changes < and > to ARITHCOMPARE. We don't |
4613 | do that because of templates. */ | |
4614 | ||
8d08fdba | 4615 | value = c; |
1ceb5ff3 | 4616 | break; |
8d08fdba MS |
4617 | } |
4618 | ||
8d08fdba MS |
4619 | case 0: |
4620 | /* Don't make yyparse think this is eof. */ | |
4621 | value = 1; | |
4622 | break; | |
4623 | ||
1ceb5ff3 JM |
4624 | case '{': |
4625 | indent_level++; | |
4626 | value = c; | |
4627 | break; | |
4628 | ||
4629 | case '}': | |
4630 | indent_level--; | |
4631 | value = c; | |
4632 | break; | |
4633 | ||
8d08fdba MS |
4634 | default: |
4635 | value = c; | |
4636 | } | |
4637 | ||
4638 | done: | |
4639 | /* yylloc.last_line = lineno; */ | |
4640 | #ifdef GATHER_STATISTICS | |
72b7eeff | 4641 | #ifdef REDUCE_LENGTH |
8d08fdba | 4642 | token_count[value] += 1; |
72b7eeff | 4643 | #endif |
8d08fdba MS |
4644 | #endif |
4645 | ||
4646 | return value; | |
4647 | } | |
4648 | ||
be99da77 MS |
4649 | int |
4650 | is_rid (t) | |
4651 | tree t; | |
4652 | { | |
4653 | return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t)); | |
4654 | } | |
4655 | ||
5566b478 | 4656 | #ifdef GATHER_STATISTICS |
5156628f MS |
4657 | /* The original for tree_node_kind is in the toplevel tree.c; changes there |
4658 | need to be brought into here, unless this were actually put into a header | |
4659 | instead. */ | |
4660 | /* Statistics-gathering stuff. */ | |
4661 | typedef enum | |
4662 | { | |
4663 | d_kind, | |
4664 | t_kind, | |
4665 | b_kind, | |
4666 | s_kind, | |
4667 | r_kind, | |
4668 | e_kind, | |
4669 | c_kind, | |
4670 | id_kind, | |
4671 | op_id_kind, | |
4672 | perm_list_kind, | |
4673 | temp_list_kind, | |
4674 | vec_kind, | |
4675 | x_kind, | |
4676 | lang_decl, | |
4677 | lang_type, | |
4678 | all_kinds | |
4679 | } tree_node_kind; | |
4680 | ||
8d08fdba MS |
4681 | extern int tree_node_counts[]; |
4682 | extern int tree_node_sizes[]; | |
5566b478 | 4683 | #endif |
8d08fdba | 4684 | |
8d08fdba MS |
4685 | tree |
4686 | build_lang_decl (code, name, type) | |
4687 | enum tree_code code; | |
4688 | tree name; | |
4689 | tree type; | |
4690 | { | |
4ce3d537 MM |
4691 | tree t; |
4692 | ||
4ce3d537 | 4693 | t = build_decl (code, name, type); |
fcfcdfc8 | 4694 | retrofit_lang_decl (t); |
4ce3d537 | 4695 | |
fcfcdfc8 JM |
4696 | return t; |
4697 | } | |
4698 | ||
4699 | /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl | |
4700 | and pushdecl (for functions generated by the backend). */ | |
4701 | ||
4702 | void | |
4703 | retrofit_lang_decl (t) | |
4704 | tree t; | |
4705 | { | |
9188c363 | 4706 | struct lang_decl *ld; |
4ce3d537 | 4707 | size_t size; |
8d08fdba | 4708 | |
4ce3d537 MM |
4709 | if (CAN_HAVE_FULL_LANG_DECL_P (t)) |
4710 | size = sizeof (struct lang_decl); | |
4711 | else | |
4712 | size = sizeof (struct lang_decl_flags); | |
b0d06515 | 4713 | |
d60f72ae | 4714 | ld = (struct lang_decl *) ggc_alloc (size); |
f5984164 | 4715 | memset (ld, 0, size); |
8d08fdba | 4716 | |
9188c363 | 4717 | DECL_LANG_SPECIFIC (t) = ld; |
8d08fdba | 4718 | if (current_lang_name == lang_name_cplusplus) |
d22c8596 | 4719 | DECL_LANGUAGE (t) = lang_cplusplus; |
8d08fdba MS |
4720 | else if (current_lang_name == lang_name_c) |
4721 | DECL_LANGUAGE (t) = lang_c; | |
a1774733 BK |
4722 | else if (current_lang_name == lang_name_java) |
4723 | DECL_LANGUAGE (t) = lang_java; | |
8d08fdba MS |
4724 | else my_friendly_abort (64); |
4725 | ||
4ce3d537 MM |
4726 | if (CAN_HAVE_FULL_LANG_DECL_P (t)) |
4727 | DECL_MAIN_VARIANT (t) = t; | |
4728 | ||
8d08fdba MS |
4729 | #ifdef GATHER_STATISTICS |
4730 | tree_node_counts[(int)lang_decl] += 1; | |
4ce3d537 | 4731 | tree_node_sizes[(int)lang_decl] += size; |
8d08fdba | 4732 | #endif |
8d08fdba MS |
4733 | } |
4734 | ||
8d08fdba MS |
4735 | void |
4736 | copy_lang_decl (node) | |
4737 | tree node; | |
4738 | { | |
4739 | int size; | |
d60f72ae | 4740 | struct lang_decl *ld; |
8d08fdba | 4741 | |
5566b478 MS |
4742 | if (! DECL_LANG_SPECIFIC (node)) |
4743 | return; | |
4744 | ||
b0d06515 | 4745 | if (!CAN_HAVE_FULL_LANG_DECL_P (node)) |
8d08fdba MS |
4746 | size = sizeof (struct lang_decl_flags); |
4747 | else | |
4748 | size = sizeof (struct lang_decl); | |
d60f72ae MM |
4749 | ld = (struct lang_decl *) ggc_alloc (size); |
4750 | bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)ld, size); | |
4751 | DECL_LANG_SPECIFIC (node) = ld; | |
8d08fdba MS |
4752 | } |
4753 | ||
4754 | tree | |
266f2faa | 4755 | cp_make_lang_type (code) |
8d08fdba MS |
4756 | enum tree_code code; |
4757 | { | |
8d08fdba | 4758 | register tree t = make_node (code); |
8d08fdba MS |
4759 | |
4760 | /* Set up some flags that give proper default behavior. */ | |
7ddedda4 MM |
4761 | if (IS_AGGR_TYPE_CODE (code)) |
4762 | { | |
32201ce4 AS |
4763 | struct lang_type *pi; |
4764 | ||
c27db0df | 4765 | pi = (struct lang_type *) ggc_alloc (sizeof (struct lang_type)); |
32201ce4 | 4766 | bzero ((char *) pi, (int) sizeof (struct lang_type)); |
8d08fdba | 4767 | |
32201ce4 | 4768 | TYPE_LANG_SPECIFIC (t) = pi; |
7ddedda4 MM |
4769 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown); |
4770 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
8d08fdba | 4771 | |
7ddedda4 MM |
4772 | /* Make sure this is laid out, for ease of use later. In the |
4773 | presence of parse errors, the normal was of assuring this | |
4774 | might not ever get executed, so we lay it out *immediately*. */ | |
4775 | build_pointer_type (t); | |
8d08fdba MS |
4776 | |
4777 | #ifdef GATHER_STATISTICS | |
7ddedda4 MM |
4778 | tree_node_counts[(int)lang_type] += 1; |
4779 | tree_node_sizes[(int)lang_type] += sizeof (struct lang_type); | |
8d08fdba | 4780 | #endif |
7ddedda4 MM |
4781 | } |
4782 | else | |
4783 | /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But, | |
4784 | TYPE_ALIAS_SET is initialized to -1 by default, so we must | |
4785 | clear it here. */ | |
4786 | TYPE_ALIAS_SET (t) = 0; | |
8d08fdba | 4787 | |
807625cf | 4788 | /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs |
f6a7cfd2 MM |
4789 | since they can be virtual base types, and we then need a |
4790 | canonical binfo for them. Ideally, this would be done lazily for | |
4791 | all types. */ | |
4792 | if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM) | |
4793 | TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE); | |
4794 | ||
8d08fdba MS |
4795 | return t; |
4796 | } | |
4797 | ||
33848bb0 RH |
4798 | tree |
4799 | make_aggr_type (code) | |
4800 | enum tree_code code; | |
4801 | { | |
4802 | tree t = cp_make_lang_type (code); | |
4803 | ||
4804 | if (IS_AGGR_TYPE_CODE (code)) | |
4805 | SET_IS_AGGR_TYPE (t, 1); | |
4806 | ||
4807 | return t; | |
4808 | } | |
4809 | ||
8d08fdba MS |
4810 | void |
4811 | dump_time_statistics () | |
4812 | { | |
4813 | register tree prev = 0, decl, next; | |
4814 | int this_time = my_get_run_time (); | |
f181d4ae | 4815 | TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time)) |
8d08fdba MS |
4816 | += this_time - body_time; |
4817 | ||
4818 | fprintf (stderr, "\n******\n"); | |
4819 | print_time ("header files (total)", header_time); | |
4820 | print_time ("main file (total)", this_time - body_time); | |
4821 | fprintf (stderr, "ratio = %g : 1\n", | |
4822 | (double)header_time / (double)(this_time - body_time)); | |
4823 | fprintf (stderr, "\n******\n"); | |
4824 | ||
4825 | for (decl = filename_times; decl; decl = next) | |
4826 | { | |
4827 | next = IDENTIFIER_GLOBAL_VALUE (decl); | |
2c73f9f5 | 4828 | SET_IDENTIFIER_GLOBAL_VALUE (decl, prev); |
8d08fdba MS |
4829 | prev = decl; |
4830 | } | |
4831 | ||
4832 | for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl)) | |
4833 | print_time (IDENTIFIER_POINTER (decl), | |
f181d4ae | 4834 | TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (decl))); |
8d08fdba MS |
4835 | } |
4836 | ||
4837 | void | |
158991b7 | 4838 | compiler_error VPARAMS ((const char *msg, ...)) |
8d08fdba | 4839 | { |
d8e178a0 KG |
4840 | #ifndef ANSI_PROTOTYPES |
4841 | const char *msg; | |
4842 | #endif | |
8d08fdba | 4843 | char buf[1024]; |
d8e178a0 KG |
4844 | va_list ap; |
4845 | ||
4846 | VA_START (ap, msg); | |
4847 | ||
4848 | #ifndef ANSI_PROTOTYPES | |
4849 | msg = va_arg (ap, const char *); | |
4850 | #endif | |
4851 | ||
4852 | vsprintf (buf, msg, ap); | |
f0305a2b | 4853 | va_end (ap); |
8d08fdba MS |
4854 | error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf); |
4855 | } | |
8d08fdba | 4856 | \f |
91063b51 MM |
4857 | /* Return the type-qualifier corresponding to the identifier given by |
4858 | RID. */ | |
4859 | ||
4860 | int | |
4861 | cp_type_qual_from_rid (rid) | |
4862 | tree rid; | |
4863 | { | |
4864 | if (rid == ridpointers[(int) RID_CONST]) | |
4865 | return TYPE_QUAL_CONST; | |
4866 | else if (rid == ridpointers[(int) RID_VOLATILE]) | |
4867 | return TYPE_QUAL_VOLATILE; | |
4868 | else if (rid == ridpointers[(int) RID_RESTRICT]) | |
4869 | return TYPE_QUAL_RESTRICT; | |
4870 | ||
4871 | my_friendly_abort (0); | |
4872 | return TYPE_UNQUALIFIED; | |
4873 | } |