]>
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" | |
8d08fdba | 33 | #include "cp-tree.h" |
0e5921e8 ZW |
34 | #include "cpplib.h" |
35 | #include "c-lex.h" | |
f09f1de5 | 36 | #include "lex.h" |
46b02c6d | 37 | #include "parse.h" |
8d08fdba | 38 | #include "flags.h" |
3d6f7931 | 39 | #include "c-pragma.h" |
54f92bfb | 40 | #include "toplev.h" |
7dee3f36 | 41 | #include "output.h" |
9cd64686 | 42 | #include "ggc.h" |
7bdb32b9 | 43 | #include "tm_p.h" |
2a9a326b | 44 | #include "timevar.h" |
856b6244 | 45 | #include "diagnostic.h" |
8d08fdba MS |
46 | |
47 | #ifdef MULTIBYTE_CHARS | |
0d3ba739 | 48 | #include "mbchar.h" |
8d08fdba MS |
49 | #include <locale.h> |
50 | #endif | |
51 | ||
158991b7 KG |
52 | extern void yyprint PARAMS ((FILE *, int, YYSTYPE)); |
53 | ||
158991b7 | 54 | static int interface_strcmp PARAMS ((const char *)); |
158991b7 | 55 | static int *init_cpp_parse PARAMS ((void)); |
0e5921e8 ZW |
56 | static void init_reswords PARAMS ((void)); |
57 | static void init_cp_pragma PARAMS ((void)); | |
58 | static void mark_impl_file_chain PARAMS ((PTR)); | |
59 | ||
60 | static tree parse_strconst_pragma PARAMS ((const char *, int)); | |
61 | static void handle_pragma_vtable PARAMS ((cpp_reader *)); | |
62 | static void handle_pragma_unit PARAMS ((cpp_reader *)); | |
63 | static void handle_pragma_interface PARAMS ((cpp_reader *)); | |
64 | static void handle_pragma_implementation PARAMS ((cpp_reader *)); | |
65 | ||
69ac77ce JL |
66 | #ifdef GATHER_STATISTICS |
67 | #ifdef REDUCE_LENGTH | |
158991b7 KG |
68 | static int reduce_cmp PARAMS ((int *, int *)); |
69 | static int token_cmp PARAMS ((int *, int *)); | |
69ac77ce JL |
70 | #endif |
71 | #endif | |
158991b7 | 72 | static int is_global PARAMS ((tree)); |
596ea4e5 | 73 | static void init_operators PARAMS ((void)); |
8d08fdba | 74 | |
0e5921e8 ZW |
75 | /* A constraint that can be tested at compile time. */ |
76 | #ifdef __STDC__ | |
77 | #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1] | |
78 | #else | |
79 | #define CONSTRAINT(name, expr) extern int constraint_/**/name [(expr) ? 1 : -1] | |
80 | #endif | |
0b807ad8 | 81 | |
d4dfe7d6 | 82 | #include "cpplib.h" |
0e5921e8 | 83 | #if USE_CPPLIB |
276ca6ea | 84 | extern cpp_reader parse_in; |
d4dfe7d6 | 85 | #else |
2b2a3531 | 86 | FILE *finput; |
8d08fdba | 87 | |
66a6250f | 88 | int linemode; |
0e5921e8 | 89 | #endif |
66a6250f | 90 | |
8d08fdba MS |
91 | /* Pending language change. |
92 | Positive is push count, negative is pop count. */ | |
93 | int pending_lang_change = 0; | |
94 | ||
8d08fdba MS |
95 | extern int yychar; /* the lookahead symbol */ |
96 | extern YYSTYPE yylval; /* the semantic value of the */ | |
97 | /* lookahead symbol */ | |
98 | ||
0e5921e8 ZW |
99 | /* These flags are used by c-lex.c. In C++, they're always off and on, |
100 | respectively. */ | |
101 | int warn_traditional = 0; | |
102 | int flag_digraphs = 1; | |
8d08fdba MS |
103 | |
104 | /* the declaration found for the last IDENTIFIER token read in. | |
105 | yylex must look this up to detect typedefs, which get token type TYPENAME, | |
106 | so it is left around in case the identifier is not a typedef but is | |
107 | used in a context which makes it a reference to a variable. */ | |
108 | tree lastiddecl; | |
109 | ||
8d08fdba MS |
110 | /* Array for holding counts of the numbers of tokens seen. */ |
111 | extern int *token_count; | |
9cd64686 | 112 | |
87e3dbc9 MM |
113 | /* Functions and data structures for #pragma interface. |
114 | ||
115 | `#pragma implementation' means that the main file being compiled | |
116 | is considered to implement (provide) the classes that appear in | |
117 | its main body. I.e., if this is file "foo.cc", and class `bar' | |
118 | is defined in "foo.cc", then we say that "foo.cc implements bar". | |
119 | ||
120 | All main input files "implement" themselves automagically. | |
121 | ||
122 | `#pragma interface' means that unless this file (of the form "foo.h" | |
123 | is not presently being included by file "foo.cc", the | |
124 | CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none | |
125 | of the vtables nor any of the inline functions defined in foo.h | |
126 | will ever be output. | |
127 | ||
128 | There are cases when we want to link files such as "defs.h" and | |
129 | "main.cc". In this case, we give "defs.h" a `#pragma interface', | |
130 | and "main.cc" has `#pragma implementation "defs.h"'. */ | |
131 | ||
132 | struct impl_files | |
133 | { | |
134 | char *filename; | |
135 | struct impl_files *next; | |
136 | }; | |
137 | ||
138 | static struct impl_files *impl_file_chain; | |
139 | ||
f3cdb9c6 AS |
140 | /* The string used to represent the filename of internally generated |
141 | tree nodes. The variable, which is dynamically allocated, should | |
142 | be used; the macro is only used to initialize it. */ | |
143 | static char *internal_filename; | |
144 | #define INTERNAL_FILENAME ("<internal>") | |
8d08fdba MS |
145 | \f |
146 | /* Return something to represent absolute declarators containing a *. | |
147 | TARGET is the absolute declarator that the * contains. | |
c11b6f21 | 148 | CV_QUALIFIERS is a list of modifiers such as const or volatile |
8d08fdba MS |
149 | to apply to the pointer type, represented as identifiers. |
150 | ||
151 | We return an INDIRECT_REF whose "contents" are TARGET | |
152 | and whose type is the modifier list. */ | |
153 | ||
154 | tree | |
c11b6f21 MS |
155 | make_pointer_declarator (cv_qualifiers, target) |
156 | tree cv_qualifiers, target; | |
8d08fdba MS |
157 | { |
158 | if (target && TREE_CODE (target) == IDENTIFIER_NODE | |
159 | && ANON_AGGRNAME_P (target)) | |
8251199e | 160 | error ("type name expected before `*'"); |
8d08fdba | 161 | target = build_parse_node (INDIRECT_REF, target); |
c11b6f21 | 162 | TREE_TYPE (target) = cv_qualifiers; |
8d08fdba MS |
163 | return target; |
164 | } | |
165 | ||
166 | /* Return something to represent absolute declarators containing a &. | |
167 | TARGET is the absolute declarator that the & contains. | |
c11b6f21 | 168 | CV_QUALIFIERS is a list of modifiers such as const or volatile |
8d08fdba MS |
169 | to apply to the reference type, represented as identifiers. |
170 | ||
171 | We return an ADDR_EXPR whose "contents" are TARGET | |
172 | and whose type is the modifier list. */ | |
5362b086 | 173 | |
8d08fdba | 174 | tree |
c11b6f21 MS |
175 | make_reference_declarator (cv_qualifiers, target) |
176 | tree cv_qualifiers, target; | |
8d08fdba MS |
177 | { |
178 | if (target) | |
179 | { | |
180 | if (TREE_CODE (target) == ADDR_EXPR) | |
181 | { | |
8251199e | 182 | error ("cannot declare references to references"); |
8d08fdba MS |
183 | return target; |
184 | } | |
185 | if (TREE_CODE (target) == INDIRECT_REF) | |
186 | { | |
8251199e | 187 | error ("cannot declare pointers to references"); |
8d08fdba MS |
188 | return target; |
189 | } | |
190 | if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target)) | |
8251199e | 191 | error ("type name expected before `&'"); |
8d08fdba MS |
192 | } |
193 | target = build_parse_node (ADDR_EXPR, target); | |
c11b6f21 | 194 | TREE_TYPE (target) = cv_qualifiers; |
8d08fdba MS |
195 | return target; |
196 | } | |
c11b6f21 MS |
197 | |
198 | tree | |
199 | make_call_declarator (target, parms, cv_qualifiers, exception_specification) | |
200 | tree target, parms, cv_qualifiers, exception_specification; | |
201 | { | |
5362b086 | 202 | target = build_parse_node (CALL_EXPR, target, |
1f8f4a0b | 203 | tree_cons (parms, cv_qualifiers, NULL_TREE), |
43f887f9 MM |
204 | /* The third operand is really RTL. We |
205 | shouldn't put anything there. */ | |
206 | NULL_TREE); | |
207 | CALL_DECLARATOR_EXCEPTION_SPEC (target) = exception_specification; | |
c11b6f21 MS |
208 | return target; |
209 | } | |
210 | ||
211 | void | |
212 | set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification) | |
213 | tree call_declarator, cv_qualifiers, exception_specification; | |
214 | { | |
43f887f9 MM |
215 | CALL_DECLARATOR_QUALS (call_declarator) = cv_qualifiers; |
216 | CALL_DECLARATOR_EXCEPTION_SPEC (call_declarator) = exception_specification; | |
c11b6f21 | 217 | } |
8d08fdba | 218 | \f |
8d08fdba MS |
219 | int interface_only; /* whether or not current file is only for |
220 | interface definitions. */ | |
221 | int interface_unknown; /* whether or not we know this class | |
222 | to behave according to #pragma interface. */ | |
223 | ||
c7d87c0a | 224 | /* Tree code classes. */ |
8d08fdba MS |
225 | |
226 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, | |
227 | ||
46e8c075 | 228 | static char cplus_tree_code_type[] = { |
0a6969ad | 229 | 'x', |
e92cc029 | 230 | #include "cp-tree.def" |
8d08fdba MS |
231 | }; |
232 | #undef DEFTREECODE | |
233 | ||
234 | /* Table indexed by tree code giving number of expression | |
235 | operands beyond the fixed part of the node structure. | |
236 | Not used for types or decls. */ | |
237 | ||
238 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, | |
239 | ||
46e8c075 | 240 | static int cplus_tree_code_length[] = { |
8d08fdba | 241 | 0, |
e92cc029 | 242 | #include "cp-tree.def" |
8d08fdba MS |
243 | }; |
244 | #undef DEFTREECODE | |
245 | ||
246 | /* Names of tree components. | |
247 | Used for printing out the tree and error messages. */ | |
248 | #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, | |
249 | ||
46e8c075 | 250 | static const char *cplus_tree_code_name[] = { |
8d08fdba | 251 | "@@dummy", |
e92cc029 | 252 | #include "cp-tree.def" |
8d08fdba MS |
253 | }; |
254 | #undef DEFTREECODE | |
255 | \f | |
256 | /* toplev.c needs to call these. */ | |
257 | ||
9116eca2 RH |
258 | void |
259 | lang_init_options () | |
260 | { | |
dfb0fb1d | 261 | #if USE_CPPLIB |
0e5921e8 | 262 | cpp_init (); |
dfb0fb1d | 263 | cpp_reader_init (&parse_in); |
dfb0fb1d DB |
264 | #endif |
265 | ||
9116eca2 RH |
266 | /* Default exceptions on. */ |
267 | flag_exceptions = 1; | |
9329983a GM |
268 | /* Mark as "unspecified". */ |
269 | flag_bounds_check = -1; | |
24805e80 GDR |
270 | /* By default wrap lines at 80 characters. Is getenv ("COLUMNS") |
271 | preferable? */ | |
272 | diagnostic_message_length_per_line = 80; | |
856b6244 GDR |
273 | /* By default, emit location information once for every |
274 | diagnostic message. */ | |
275 | set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE); | |
9116eca2 RH |
276 | } |
277 | ||
8d08fdba MS |
278 | void |
279 | lang_init () | |
280 | { | |
9329983a GM |
281 | /* If still "unspecified", make it match -fbounded-pointers. */ |
282 | if (flag_bounds_check < 0) | |
283 | flag_bounds_check = flag_bounded_pointers; | |
284 | ||
0e5921e8 | 285 | #if !USE_CPPLIB |
8d08fdba MS |
286 | /* the beginning of the file is a new line; check for # */ |
287 | /* With luck, we discover the real source file's name from that | |
288 | and put it in input_filename. */ | |
0e5921e8 ZW |
289 | ungetc (check_newline (), finput); |
290 | #endif | |
291 | ||
8d08fdba | 292 | if (flag_gnu_xref) GNU_xref_begin (input_filename); |
faae18ab | 293 | init_repo (input_filename); |
8d08fdba MS |
294 | } |
295 | ||
296 | void | |
297 | lang_finish () | |
298 | { | |
8d08fdba MS |
299 | if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount); |
300 | } | |
301 | ||
8df4696d | 302 | const char * |
8d08fdba MS |
303 | lang_identify () |
304 | { | |
305 | return "cplusplus"; | |
306 | } | |
307 | ||
2b2a3531 DB |
308 | static int * |
309 | init_cpp_parse () | |
310 | { | |
311 | #ifdef GATHER_STATISTICS | |
312 | #ifdef REDUCE_LENGTH | |
fffeac96 | 313 | reduce_count = (int *) xcalloc (sizeof (int), (REDUCE_LENGTH + 1)); |
2b2a3531 | 314 | reduce_count += 1; |
fffeac96 | 315 | token_count = (int *) xcalloc (sizeof (int), (TOKEN_LENGTH + 1)); |
2b2a3531 DB |
316 | token_count += 1; |
317 | #endif | |
318 | #endif | |
319 | return token_count; | |
320 | } | |
321 | ||
596ea4e5 AS |
322 | /* A mapping from tree codes to operator name information. */ |
323 | operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE]; | |
324 | /* Similar, but for assignment operators. */ | |
325 | operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE]; | |
5362b086 | 326 | |
596ea4e5 AS |
327 | /* Initialize data structures that keep track of operator names. */ |
328 | ||
0e5921e8 ZW |
329 | #define DEF_OPERATOR(NAME, C, NM, OM, AR, AP) \ |
330 | CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256); | |
331 | #include "operators.def" | |
332 | #undef DEF_OPERATOR | |
333 | ||
596ea4e5 AS |
334 | static void |
335 | init_operators () | |
336 | { | |
337 | tree identifier; | |
338 | char buffer[256]; | |
339 | struct operator_name_info_t *oni; | |
5362b086 | 340 | |
669ec2b4 | 341 | #define DEF_OPERATOR(NAME, CODE, NEW_MANGLING, OLD_MANGLING, ARITY, ASSN_P) \ |
dba1acea | 342 | sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \ |
596ea4e5 AS |
343 | identifier = get_identifier (buffer); \ |
344 | IDENTIFIER_OPNAME_P (identifier) = 1; \ | |
345 | \ | |
346 | oni = (ASSN_P \ | |
347 | ? &assignment_operator_name_info[(int) CODE] \ | |
348 | : &operator_name_info[(int) CODE]); \ | |
349 | oni->identifier = identifier; \ | |
350 | oni->name = NAME; \ | |
669ec2b4 | 351 | oni->mangled_name = flag_new_abi ? NEW_MANGLING : OLD_MANGLING; |
596ea4e5 AS |
352 | |
353 | #include "operators.def" | |
354 | #undef DEF_OPERATOR | |
355 | ||
5362b086 | 356 | operator_name_info[(int) ERROR_MARK].identifier |
596ea4e5 AS |
357 | = get_identifier ("<invalid operator>"); |
358 | ||
359 | /* Handle some special cases. These operators are not defined in | |
360 | the language, but can be produced internally. We may need them | |
361 | for error-reporting. (Eventually, we should ensure that this | |
362 | does not happen. Error messages involving these operators will | |
363 | be confusing to users.) */ | |
5362b086 EC |
364 | |
365 | operator_name_info [(int) INIT_EXPR].name | |
596ea4e5 AS |
366 | = operator_name_info [(int) MODIFY_EXPR].name; |
367 | operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)"; | |
368 | operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)"; | |
369 | operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)"; | |
370 | operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)"; | |
371 | operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)"; | |
372 | operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)"; | |
373 | operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)"; | |
374 | operator_name_info [(int) ABS_EXPR].name = "abs"; | |
375 | operator_name_info [(int) FFS_EXPR].name = "ffs"; | |
376 | operator_name_info [(int) BIT_ANDTC_EXPR].name = "&~"; | |
377 | operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&"; | |
378 | operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||"; | |
379 | operator_name_info [(int) IN_EXPR].name = "in"; | |
380 | operator_name_info [(int) RANGE_EXPR].name = "..."; | |
381 | operator_name_info [(int) CONVERT_EXPR].name = "+"; | |
382 | ||
5362b086 | 383 | assignment_operator_name_info [(int) EXACT_DIV_EXPR].name |
596ea4e5 | 384 | = "(exact /=)"; |
5362b086 | 385 | assignment_operator_name_info [(int) CEIL_DIV_EXPR].name |
596ea4e5 | 386 | = "(ceiling /=)"; |
5362b086 | 387 | assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name |
596ea4e5 | 388 | = "(floor /=)"; |
5362b086 | 389 | assignment_operator_name_info [(int) ROUND_DIV_EXPR].name |
596ea4e5 | 390 | = "(round /=)"; |
5362b086 | 391 | assignment_operator_name_info [(int) CEIL_MOD_EXPR].name |
596ea4e5 | 392 | = "(ceiling %=)"; |
5362b086 | 393 | assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name |
596ea4e5 | 394 | = "(floor %=)"; |
5362b086 | 395 | assignment_operator_name_info [(int) ROUND_MOD_EXPR].name |
596ea4e5 AS |
396 | = "(round %=)"; |
397 | } | |
398 | ||
0e5921e8 ZW |
399 | /* The reserved keyword table. */ |
400 | struct resword | |
8d08fdba | 401 | { |
0e5921e8 ZW |
402 | const char *word; |
403 | ENUM_BITFIELD(rid) rid : 16; | |
404 | unsigned int disable : 16; | |
405 | }; | |
8d08fdba | 406 | |
0e5921e8 ZW |
407 | /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is |
408 | _true_. */ | |
409 | #define D_EXT 0x01 /* GCC extension */ | |
410 | #define D_ASM 0x02 /* in C99, but has a switch to turn it off */ | |
411 | #define D_OPNAME 0x04 /* operator names */ | |
412 | ||
413 | CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT); | |
414 | ||
415 | static const struct resword reswords[] = | |
416 | { | |
d9dbd9b1 | 417 | { "_Complex", RID_COMPLEX, 0 }, |
0e5921e8 ZW |
418 | { "__alignof", RID_ALIGNOF, 0 }, |
419 | { "__alignof__", RID_ALIGNOF, 0 }, | |
420 | { "__asm", RID_ASM, 0 }, | |
421 | { "__asm__", RID_ASM, 0 }, | |
422 | { "__attribute", RID_ATTRIBUTE, 0 }, | |
423 | { "__attribute__", RID_ATTRIBUTE, 0 }, | |
424 | { "__builtin_va_arg", RID_VA_ARG, 0 }, | |
425 | { "__complex", RID_COMPLEX, 0 }, | |
426 | { "__complex__", RID_COMPLEX, 0 }, | |
427 | { "__const", RID_CONST, 0 }, | |
428 | { "__const__", RID_CONST, 0 }, | |
429 | { "__extension__", RID_EXTENSION, 0 }, | |
430 | { "__imag", RID_IMAGPART, 0 }, | |
431 | { "__imag__", RID_IMAGPART, 0 }, | |
432 | { "__inline", RID_INLINE, 0 }, | |
433 | { "__inline__", RID_INLINE, 0 }, | |
434 | { "__label__", RID_LABEL, 0 }, | |
435 | { "__null", RID_NULL, 0 }, | |
436 | { "__real", RID_REALPART, 0 }, | |
437 | { "__real__", RID_REALPART, 0 }, | |
438 | { "__restrict", RID_RESTRICT, 0 }, | |
439 | { "__restrict__", RID_RESTRICT, 0 }, | |
440 | { "__signed", RID_SIGNED, 0 }, | |
441 | { "__signed__", RID_SIGNED, 0 }, | |
442 | { "__typeof", RID_TYPEOF, 0 }, | |
443 | { "__typeof__", RID_TYPEOF, 0 }, | |
444 | { "__volatile", RID_VOLATILE, 0 }, | |
445 | { "__volatile__", RID_VOLATILE, 0 }, | |
0e5921e8 ZW |
446 | { "asm", RID_ASM, D_ASM }, |
447 | { "and", RID_AND, D_OPNAME }, | |
448 | { "and_eq", RID_AND_EQ, D_OPNAME }, | |
449 | { "auto", RID_AUTO, 0 }, | |
450 | { "bitand", RID_BITAND, D_OPNAME }, | |
451 | { "bitor", RID_BITOR, D_OPNAME }, | |
452 | { "bool", RID_BOOL, 0 }, | |
453 | { "break", RID_BREAK, 0 }, | |
454 | { "case", RID_CASE, 0 }, | |
455 | { "catch", RID_CATCH, 0 }, | |
456 | { "char", RID_CHAR, 0 }, | |
457 | { "class", RID_CLASS, 0 }, | |
458 | { "compl", RID_COMPL, D_OPNAME }, | |
459 | { "const", RID_CONST, 0 }, | |
460 | { "const_cast", RID_CONSTCAST, 0 }, | |
461 | { "continue", RID_CONTINUE, 0 }, | |
462 | { "default", RID_DEFAULT, 0 }, | |
463 | { "delete", RID_DELETE, 0 }, | |
464 | { "do", RID_DO, 0 }, | |
465 | { "double", RID_DOUBLE, 0 }, | |
466 | { "dynamic_cast", RID_DYNCAST, 0 }, | |
467 | { "else", RID_ELSE, 0 }, | |
468 | { "enum", RID_ENUM, 0 }, | |
469 | { "explicit", RID_EXPLICIT, 0 }, | |
470 | { "export", RID_EXPORT, 0 }, | |
471 | { "extern", RID_EXTERN, 0 }, | |
472 | { "false", RID_FALSE, 0 }, | |
473 | { "float", RID_FLOAT, 0 }, | |
474 | { "for", RID_FOR, 0 }, | |
475 | { "friend", RID_FRIEND, 0 }, | |
476 | { "goto", RID_GOTO, 0 }, | |
477 | { "if", RID_IF, 0 }, | |
478 | { "inline", RID_INLINE, 0 }, | |
479 | { "int", RID_INT, 0 }, | |
480 | { "long", RID_LONG, 0 }, | |
481 | { "mutable", RID_MUTABLE, 0 }, | |
482 | { "namespace", RID_NAMESPACE, 0 }, | |
483 | { "new", RID_NEW, 0 }, | |
484 | { "not", RID_NOT, D_OPNAME }, | |
485 | { "not_eq", RID_NOT_EQ, D_OPNAME }, | |
486 | { "operator", RID_OPERATOR, 0 }, | |
487 | { "or", RID_OR, D_OPNAME }, | |
488 | { "or_eq", RID_OR_EQ, D_OPNAME }, | |
489 | { "private", RID_PRIVATE, 0 }, | |
490 | { "protected", RID_PROTECTED, 0 }, | |
491 | { "public", RID_PUBLIC, 0 }, | |
492 | { "register", RID_REGISTER, 0 }, | |
493 | { "reinterpret_cast", RID_REINTCAST, 0 }, | |
494 | { "return", RID_RETURN, 0 }, | |
495 | { "short", RID_SHORT, 0 }, | |
496 | { "signed", RID_SIGNED, 0 }, | |
497 | { "sizeof", RID_SIZEOF, 0 }, | |
498 | { "static", RID_STATIC, 0 }, | |
499 | { "static_cast", RID_STATCAST, 0 }, | |
500 | { "struct", RID_STRUCT, 0 }, | |
501 | { "switch", RID_SWITCH, 0 }, | |
502 | { "template", RID_TEMPLATE, 0 }, | |
503 | { "this", RID_THIS, 0 }, | |
504 | { "throw", RID_THROW, 0 }, | |
505 | { "true", RID_TRUE, 0 }, | |
506 | { "try", RID_TRY, 0 }, | |
507 | { "typedef", RID_TYPEDEF, 0 }, | |
508 | { "typename", RID_TYPENAME, 0 }, | |
509 | { "typeid", RID_TYPEID, 0 }, | |
510 | { "typeof", RID_TYPEOF, D_ASM|D_EXT }, | |
511 | { "union", RID_UNION, 0 }, | |
512 | { "unsigned", RID_UNSIGNED, 0 }, | |
513 | { "using", RID_USING, 0 }, | |
514 | { "virtual", RID_VIRTUAL, 0 }, | |
515 | { "void", RID_VOID, 0 }, | |
516 | { "volatile", RID_VOLATILE, 0 }, | |
5362b086 | 517 | { "wchar_t", RID_WCHAR, 0 }, |
0e5921e8 ZW |
518 | { "while", RID_WHILE, 0 }, |
519 | { "xor", RID_XOR, D_OPNAME }, | |
520 | { "xor_eq", RID_XOR_EQ, D_OPNAME }, | |
0d3ba739 | 521 | |
0e5921e8 ZW |
522 | }; |
523 | #define N_reswords (sizeof reswords / sizeof (struct resword)) | |
524 | ||
525 | /* Table mapping from RID_* constants to yacc token numbers. | |
526 | Unfortunately we have to have entries for all the keywords in all | |
527 | three languages. */ | |
528 | const short rid_to_yy[RID_MAX] = | |
529 | { | |
530 | /* RID_STATIC */ SCSPEC, | |
531 | /* RID_UNSIGNED */ TYPESPEC, | |
532 | /* RID_LONG */ TYPESPEC, | |
533 | /* RID_CONST */ CV_QUALIFIER, | |
534 | /* RID_EXTERN */ SCSPEC, | |
535 | /* RID_REGISTER */ SCSPEC, | |
536 | /* RID_TYPEDEF */ SCSPEC, | |
537 | /* RID_SHORT */ TYPESPEC, | |
538 | /* RID_INLINE */ SCSPEC, | |
539 | /* RID_VOLATILE */ CV_QUALIFIER, | |
540 | /* RID_SIGNED */ TYPESPEC, | |
541 | /* RID_AUTO */ SCSPEC, | |
542 | /* RID_RESTRICT */ CV_QUALIFIER, | |
543 | ||
544 | /* C extensions. Bounded pointers are not yet in C++ */ | |
545 | /* RID_BOUNDED */ 0, | |
546 | /* RID_UNBOUNDED */ 0, | |
547 | /* RID_COMPLEX */ TYPESPEC, | |
548 | ||
549 | /* C++ */ | |
550 | /* RID_FRIEND */ SCSPEC, | |
551 | /* RID_VIRTUAL */ SCSPEC, | |
552 | /* RID_EXPLICIT */ SCSPEC, | |
553 | /* RID_EXPORT */ SCSPEC, | |
554 | /* RID_MUTABLE */ SCSPEC, | |
555 | ||
556 | /* ObjC */ | |
557 | /* RID_IN */ 0, | |
558 | /* RID_OUT */ 0, | |
559 | /* RID_INOUT */ 0, | |
560 | /* RID_BYCOPY */ 0, | |
561 | /* RID_BYREF */ 0, | |
562 | /* RID_ONEWAY */ 0, | |
5362b086 | 563 | |
0e5921e8 ZW |
564 | /* C */ |
565 | /* RID_INT */ TYPESPEC, | |
566 | /* RID_CHAR */ TYPESPEC, | |
567 | /* RID_FLOAT */ TYPESPEC, | |
568 | /* RID_DOUBLE */ TYPESPEC, | |
569 | /* RID_VOID */ TYPESPEC, | |
570 | /* RID_ENUM */ ENUM, | |
571 | /* RID_STRUCT */ AGGR, | |
572 | /* RID_UNION */ AGGR, | |
573 | /* RID_IF */ IF, | |
574 | /* RID_ELSE */ ELSE, | |
575 | /* RID_WHILE */ WHILE, | |
576 | /* RID_DO */ DO, | |
577 | /* RID_FOR */ FOR, | |
578 | /* RID_SWITCH */ SWITCH, | |
579 | /* RID_CASE */ CASE, | |
580 | /* RID_DEFAULT */ DEFAULT, | |
581 | /* RID_BREAK */ BREAK, | |
582 | /* RID_CONTINUE */ CONTINUE, | |
583 | /* RID_RETURN */ RETURN_KEYWORD, | |
584 | /* RID_GOTO */ GOTO, | |
585 | /* RID_SIZEOF */ SIZEOF, | |
586 | ||
587 | /* C extensions */ | |
588 | /* RID_ASM */ ASM_KEYWORD, | |
589 | /* RID_TYPEOF */ TYPEOF, | |
590 | /* RID_ALIGNOF */ ALIGNOF, | |
591 | /* RID_ATTRIBUTE */ ATTRIBUTE, | |
592 | /* RID_VA_ARG */ VA_ARG, | |
593 | /* RID_EXTENSION */ EXTENSION, | |
594 | /* RID_IMAGPART */ IMAGPART, | |
595 | /* RID_REALPART */ REALPART, | |
596 | /* RID_LABEL */ LABEL, | |
597 | /* RID_PTRBASE */ 0, | |
598 | /* RID_PTREXTENT */ 0, | |
599 | /* RID_PTRVALUE */ 0, | |
600 | ||
601 | /* C++ */ | |
602 | /* RID_BOOL */ TYPESPEC, | |
603 | /* RID_WCHAR */ TYPESPEC, | |
604 | /* RID_CLASS */ AGGR, | |
605 | /* RID_PUBLIC */ VISSPEC, | |
606 | /* RID_PRIVATE */ VISSPEC, | |
607 | /* RID_PROTECTED */ VISSPEC, | |
608 | /* RID_TEMPLATE */ TEMPLATE, | |
609 | /* RID_NULL */ CONSTANT, | |
610 | /* RID_CATCH */ CATCH, | |
611 | /* RID_DELETE */ DELETE, | |
612 | /* RID_FALSE */ CXX_FALSE, | |
613 | /* RID_NAMESPACE */ NAMESPACE, | |
614 | /* RID_NEW */ NEW, | |
615 | /* RID_OPERATOR */ OPERATOR, | |
616 | /* RID_THIS */ THIS, | |
617 | /* RID_THROW */ THROW, | |
618 | /* RID_TRUE */ CXX_TRUE, | |
619 | /* RID_TRY */ TRY, | |
620 | /* RID_TYPENAME */ TYPENAME_KEYWORD, | |
621 | /* RID_TYPEID */ TYPEID, | |
622 | /* RID_USING */ USING, | |
623 | ||
624 | /* casts */ | |
625 | /* RID_CONSTCAST */ CONST_CAST, | |
626 | /* RID_DYNCAST */ DYNAMIC_CAST, | |
627 | /* RID_REINTCAST */ REINTERPRET_CAST, | |
628 | /* RID_STATCAST */ STATIC_CAST, | |
629 | ||
630 | /* alternate spellings */ | |
631 | /* RID_AND */ ANDAND, | |
632 | /* RID_AND_EQ */ ASSIGN, | |
633 | /* RID_NOT */ '!', | |
634 | /* RID_NOT_EQ */ EQCOMPARE, | |
635 | /* RID_OR */ OROR, | |
636 | /* RID_OR_EQ */ ASSIGN, | |
637 | /* RID_XOR */ '^', | |
638 | /* RID_XOR_EQ */ ASSIGN, | |
639 | /* RID_BITAND */ '&', | |
640 | /* RID_BITOR */ '|', | |
641 | /* RID_COMPL */ '~', | |
642 | ||
643 | /* Objective C */ | |
644 | /* RID_ID */ 0, | |
645 | /* RID_AT_ENCODE */ 0, | |
646 | /* RID_AT_END */ 0, | |
647 | /* RID_AT_CLASS */ 0, | |
648 | /* RID_AT_ALIAS */ 0, | |
649 | /* RID_AT_DEFS */ 0, | |
650 | /* RID_AT_PRIVATE */ 0, | |
651 | /* RID_AT_PROTECTED */ 0, | |
652 | /* RID_AT_PUBLIC */ 0, | |
653 | /* RID_AT_PROTOCOL */ 0, | |
654 | /* RID_AT_SELECTOR */ 0, | |
655 | /* RID_AT_INTERFACE */ 0, | |
656 | /* RID_AT_IMPLEMENTATION */ 0 | |
657 | }; | |
658 | ||
659 | static void | |
660 | init_reswords () | |
661 | { | |
662 | unsigned int i; | |
663 | tree id; | |
664 | int mask = ((flag_operator_names ? 0 : D_OPNAME) | |
665 | | (flag_no_asm ? D_ASM : 0) | |
666 | | (flag_no_gnu_keywords ? D_EXT : 0)); | |
667 | ||
668 | /* It is not necessary to register ridpointers as a GC root, because | |
669 | all the trees it points to are permanently interned in the | |
670 | get_identifier hash anyway. */ | |
671 | ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree)); | |
672 | for (i = 0; i < N_reswords; i++) | |
2b2a3531 | 673 | { |
0e5921e8 ZW |
674 | id = get_identifier (reswords[i].word); |
675 | C_RID_CODE (id) = reswords[i].rid; | |
676 | ridpointers [(int) reswords[i].rid] = id; | |
677 | if (! (reswords[i].disable & mask)) | |
678 | C_IS_RESERVED_WORD (id) = 1; | |
2b2a3531 | 679 | } |
0e5921e8 | 680 | } |
2b2a3531 | 681 | |
0e5921e8 ZW |
682 | static void |
683 | init_cp_pragma () | |
684 | { | |
685 | #if USE_CPPLIB | |
686 | #define pfile &parse_in | |
687 | #else | |
688 | #define pfile 0 | |
2b2a3531 | 689 | #endif |
0e5921e8 ZW |
690 | cpp_register_pragma (pfile, 0, "vtable", handle_pragma_vtable); |
691 | cpp_register_pragma (pfile, 0, "unit", handle_pragma_unit); | |
1ceb5ff3 | 692 | |
0e5921e8 ZW |
693 | cpp_register_pragma (pfile, 0, "interface", handle_pragma_interface); |
694 | cpp_register_pragma (pfile, 0, "implementation", | |
695 | handle_pragma_implementation); | |
1ceb5ff3 | 696 | |
0e5921e8 ZW |
697 | cpp_register_pragma_space (pfile, "GCC"); |
698 | cpp_register_pragma (pfile, "GCC", "interface", handle_pragma_interface); | |
699 | cpp_register_pragma (pfile, "GCC", "implementation", | |
700 | handle_pragma_implementation); | |
701 | } | |
8d08fdba | 702 | |
0e5921e8 ZW |
703 | const char * |
704 | init_parse (filename) | |
705 | const char *filename; | |
706 | { | |
8d08fdba MS |
707 | /* Make identifier nodes long enough for the language-specific slots. */ |
708 | set_identifier_size (sizeof (struct lang_identifier)); | |
709 | decl_printable_name = lang_printable_name; | |
710 | ||
5362b086 | 711 | internal_filename = ggc_alloc_string (INTERNAL_FILENAME, |
0e5921e8 ZW |
712 | sizeof (INTERNAL_FILENAME)); |
713 | input_filename = internal_filename; | |
714 | ||
715 | init_reswords (); | |
716 | init_pragma (); | |
717 | init_cp_pragma (); | |
0e5921e8 | 718 | init_spew (); |
87e3dbc9 | 719 | init_tree (); |
8d08fdba | 720 | init_cplus_expand (); |
54f7877c | 721 | init_cp_semantics (); |
8d08fdba | 722 | |
c7d87c0a BC |
723 | add_c_tree_codes (); |
724 | ||
725 | memcpy (tree_code_type + (int) LAST_C_TREE_CODE, | |
f5984164 | 726 | cplus_tree_code_type, |
c7d87c0a BC |
727 | (int)LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE); |
728 | memcpy (tree_code_length + (int) LAST_C_TREE_CODE, | |
f5984164 | 729 | cplus_tree_code_length, |
c7d87c0a BC |
730 | (LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE) * sizeof (int)); |
731 | memcpy (tree_code_name + (int) LAST_C_TREE_CODE, | |
f5984164 | 732 | cplus_tree_code_name, |
c7d87c0a | 733 | (LAST_CPLUS_TREE_CODE - (int)LAST_C_TREE_CODE) * sizeof (char *)); |
8d08fdba | 734 | |
596ea4e5 | 735 | init_operators (); |
669ec2b4 | 736 | init_method (); |
8d08fdba | 737 | init_error (); |
f3cdb9c6 | 738 | |
8d08fdba MS |
739 | current_function_decl = NULL; |
740 | ||
8d08fdba MS |
741 | class_type_node = build_int_2 (class_type, 0); |
742 | TREE_TYPE (class_type_node) = class_type_node; | |
743 | ridpointers[(int) RID_CLASS] = class_type_node; | |
744 | ||
745 | record_type_node = build_int_2 (record_type, 0); | |
746 | TREE_TYPE (record_type_node) = record_type_node; | |
0e5921e8 | 747 | ridpointers[(int) RID_STRUCT] = record_type_node; |
8d08fdba MS |
748 | |
749 | union_type_node = build_int_2 (union_type, 0); | |
750 | TREE_TYPE (union_type_node) = union_type_node; | |
751 | ridpointers[(int) RID_UNION] = union_type_node; | |
752 | ||
753 | enum_type_node = build_int_2 (enum_type, 0); | |
754 | TREE_TYPE (enum_type_node) = enum_type_node; | |
755 | ridpointers[(int) RID_ENUM] = enum_type_node; | |
756 | ||
898600d5 MM |
757 | /* Create the built-in __null node. Note that we can't yet call for |
758 | type_for_size here because integer_type_node and so forth are not | |
759 | set up. Therefore, we don't set the type of these nodes until | |
760 | init_decl_processing. */ | |
03d0f4af | 761 | null_node = build_int_2 (0, 0); |
d11ad92e | 762 | ridpointers[RID_NULL] = null_node; |
c73964b2 | 763 | |
2b2a3531 | 764 | token_count = init_cpp_parse (); |
8d08fdba | 765 | interface_unknown = 1; |
a755ad1c | 766 | |
f3cdb9c6 | 767 | ggc_add_string_root (&internal_filename, 1); |
87e3dbc9 MM |
768 | ggc_add_root (&impl_file_chain, 1, sizeof (impl_file_chain), |
769 | mark_impl_file_chain); | |
0e5921e8 ZW |
770 | |
771 | return init_c_lex (filename); | |
8d08fdba MS |
772 | } |
773 | ||
2b2a3531 DB |
774 | void |
775 | finish_parse () | |
776 | { | |
777 | #if USE_CPPLIB | |
23356f93 | 778 | cpp_finish (&parse_in); |
1b87232a | 779 | errorcount += parse_in.errors; |
2b2a3531 DB |
780 | #else |
781 | fclose (finput); | |
782 | #endif | |
783 | } | |
8d08fdba | 784 | \f |
f9c4f105 | 785 | inline void |
8d08fdba MS |
786 | yyprint (file, yychar, yylval) |
787 | FILE *file; | |
788 | int yychar; | |
789 | YYSTYPE yylval; | |
790 | { | |
791 | tree t; | |
792 | switch (yychar) | |
793 | { | |
794 | case IDENTIFIER: | |
795 | case TYPENAME: | |
796 | case TYPESPEC: | |
797 | case PTYPENAME: | |
074917ba | 798 | case PFUNCNAME: |
8d08fdba MS |
799 | case IDENTIFIER_DEFN: |
800 | case TYPENAME_DEFN: | |
801 | case PTYPENAME_DEFN: | |
8d08fdba MS |
802 | case SCSPEC: |
803 | case PRE_PARSED_CLASS_DECL: | |
804 | t = yylval.ttype; | |
11686454 | 805 | if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL) |
fc378698 | 806 | { |
430bb96b | 807 | fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t))); |
fc378698 MS |
808 | break; |
809 | } | |
8d08fdba MS |
810 | my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224); |
811 | if (IDENTIFIER_POINTER (t)) | |
812 | fprintf (file, " `%s'", IDENTIFIER_POINTER (t)); | |
813 | break; | |
1ceb5ff3 | 814 | |
8d08fdba MS |
815 | case AGGR: |
816 | if (yylval.ttype == class_type_node) | |
817 | fprintf (file, " `class'"); | |
818 | else if (yylval.ttype == record_type_node) | |
819 | fprintf (file, " `struct'"); | |
820 | else if (yylval.ttype == union_type_node) | |
821 | fprintf (file, " `union'"); | |
822 | else if (yylval.ttype == enum_type_node) | |
823 | fprintf (file, " `enum'"); | |
8d08fdba MS |
824 | else |
825 | my_friendly_abort (80); | |
826 | break; | |
1ceb5ff3 JM |
827 | |
828 | case CONSTANT: | |
829 | t = yylval.ttype; | |
830 | if (TREE_CODE (t) == INTEGER_CST) | |
831 | fprintf (file, | |
832 | #if HOST_BITS_PER_WIDE_INT == 64 | |
833 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
834 | " 0x%x%016x", | |
835 | #else | |
836 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG | |
837 | " 0x%lx%016lx", | |
838 | #else | |
839 | " 0x%llx%016llx", | |
840 | #endif | |
841 | #endif | |
842 | #else | |
843 | #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT | |
844 | " 0x%lx%08lx", | |
845 | #else | |
846 | " 0x%x%08x", | |
847 | #endif | |
848 | #endif | |
849 | TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t)); | |
850 | break; | |
8d08fdba MS |
851 | } |
852 | } | |
853 | ||
5566b478 | 854 | #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH) |
8d08fdba | 855 | static int *reduce_count; |
5566b478 MS |
856 | #endif |
857 | ||
8d08fdba MS |
858 | int *token_count; |
859 | ||
72b7eeff | 860 | #if 0 |
8d08fdba MS |
861 | #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0])) |
862 | #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0])) | |
72b7eeff | 863 | #endif |
8d08fdba | 864 | |
8d08fdba | 865 | #ifdef GATHER_STATISTICS |
72b7eeff | 866 | #ifdef REDUCE_LENGTH |
8d08fdba MS |
867 | void |
868 | yyhook (yyn) | |
869 | int yyn; | |
870 | { | |
871 | reduce_count[yyn] += 1; | |
872 | } | |
8d08fdba MS |
873 | |
874 | static int | |
875 | reduce_cmp (p, q) | |
876 | int *p, *q; | |
877 | { | |
878 | return reduce_count[*q] - reduce_count[*p]; | |
879 | } | |
880 | ||
881 | static int | |
882 | token_cmp (p, q) | |
883 | int *p, *q; | |
884 | { | |
885 | return token_count[*q] - token_count[*p]; | |
886 | } | |
8926095f | 887 | #endif |
72b7eeff | 888 | #endif |
8d08fdba MS |
889 | |
890 | void | |
891 | print_parse_statistics () | |
892 | { | |
893 | #ifdef GATHER_STATISTICS | |
72b7eeff | 894 | #ifdef REDUCE_LENGTH |
8d08fdba MS |
895 | #if YYDEBUG != 0 |
896 | int i; | |
897 | int maxlen = REDUCE_LENGTH; | |
898 | unsigned *sorted; | |
5362b086 | 899 | |
8d08fdba MS |
900 | if (reduce_count[-1] == 0) |
901 | return; | |
902 | ||
903 | if (TOKEN_LENGTH > REDUCE_LENGTH) | |
904 | maxlen = TOKEN_LENGTH; | |
905 | sorted = (unsigned *) alloca (sizeof (int) * maxlen); | |
906 | ||
907 | for (i = 0; i < TOKEN_LENGTH; i++) | |
908 | sorted[i] = i; | |
909 | qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp); | |
910 | for (i = 0; i < TOKEN_LENGTH; i++) | |
911 | { | |
e92cc029 MS |
912 | int idx = sorted[i]; |
913 | if (token_count[idx] == 0) | |
8d08fdba | 914 | break; |
e92cc029 | 915 | if (token_count[idx] < token_count[-1]) |
8d08fdba MS |
916 | break; |
917 | fprintf (stderr, "token %d, `%s', count = %d\n", | |
e92cc029 | 918 | idx, yytname[YYTRANSLATE (idx)], token_count[idx]); |
8d08fdba MS |
919 | } |
920 | fprintf (stderr, "\n"); | |
921 | for (i = 0; i < REDUCE_LENGTH; i++) | |
922 | sorted[i] = i; | |
923 | qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp); | |
924 | for (i = 0; i < REDUCE_LENGTH; i++) | |
925 | { | |
e92cc029 MS |
926 | int idx = sorted[i]; |
927 | if (reduce_count[idx] == 0) | |
8d08fdba | 928 | break; |
e92cc029 | 929 | if (reduce_count[idx] < reduce_count[-1]) |
8d08fdba MS |
930 | break; |
931 | fprintf (stderr, "rule %d, line %d, count = %d\n", | |
e92cc029 | 932 | idx, yyrline[idx], reduce_count[idx]); |
8d08fdba MS |
933 | } |
934 | fprintf (stderr, "\n"); | |
935 | #endif | |
936 | #endif | |
72b7eeff | 937 | #endif |
8d08fdba MS |
938 | } |
939 | ||
940 | /* Sets the value of the 'yydebug' variable to VALUE. | |
941 | This is a function so we don't have to have YYDEBUG defined | |
942 | in order to build the compiler. */ | |
e92cc029 | 943 | |
8d08fdba MS |
944 | void |
945 | set_yydebug (value) | |
946 | int value; | |
947 | { | |
948 | #if YYDEBUG != 0 | |
949 | extern int yydebug; | |
950 | yydebug = value; | |
951 | #else | |
8251199e | 952 | warning ("YYDEBUG not defined."); |
8d08fdba MS |
953 | #endif |
954 | } | |
955 | ||
8d08fdba | 956 | \f |
87e3dbc9 | 957 | /* Mark ARG (which is really a struct impl_files **) for GC. */ |
8d08fdba | 958 | |
87e3dbc9 MM |
959 | static void |
960 | mark_impl_file_chain (arg) | |
961 | void *arg; | |
8d08fdba | 962 | { |
87e3dbc9 | 963 | struct impl_files *ifs; |
8d08fdba | 964 | |
87e3dbc9 | 965 | ifs = *(struct impl_files **) arg; |
01fba8d9 RH |
966 | while (ifs) |
967 | { | |
968 | ggc_mark_string (ifs->filename); | |
969 | ifs = ifs->next; | |
970 | } | |
87e3dbc9 | 971 | } |
8d08fdba MS |
972 | |
973 | /* Helper function to load global variables with interface | |
974 | information. */ | |
e92cc029 | 975 | |
8d08fdba MS |
976 | void |
977 | extract_interface_info () | |
978 | { | |
0e5921e8 | 979 | struct c_fileinfo *finfo = 0; |
8d08fdba MS |
980 | |
981 | if (flag_alt_external_templates) | |
982 | { | |
3ae18eaf | 983 | tree til = tinst_for_decl (); |
5362b086 | 984 | |
8d08fdba | 985 | if (til) |
0e5921e8 | 986 | finfo = get_fileinfo (TINST_FILE (til)); |
8d08fdba | 987 | } |
0e5921e8 ZW |
988 | if (!finfo) |
989 | finfo = get_fileinfo (input_filename); | |
990 | ||
991 | interface_only = finfo->interface_only; | |
992 | interface_unknown = finfo->interface_unknown; | |
993 | ||
994 | /* This happens to be a convenient place to put this. */ | |
995 | if (flag_gnu_xref) GNU_xref_file (input_filename); | |
8d08fdba MS |
996 | } |
997 | ||
51c184be | 998 | /* Return nonzero if S is not considered part of an |
8d08fdba | 999 | INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */ |
e92cc029 | 1000 | |
8d08fdba MS |
1001 | static int |
1002 | interface_strcmp (s) | |
d8e178a0 | 1003 | const char *s; |
8d08fdba MS |
1004 | { |
1005 | /* Set the interface/implementation bits for this scope. */ | |
1006 | struct impl_files *ifiles; | |
d8e178a0 | 1007 | const char *s1; |
8d08fdba | 1008 | |
8d08fdba MS |
1009 | for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next) |
1010 | { | |
d8e178a0 | 1011 | const char *t1 = ifiles->filename; |
8d08fdba MS |
1012 | s1 = s; |
1013 | ||
1014 | if (*s1 != *t1 || *s1 == 0) | |
1015 | continue; | |
1016 | ||
1017 | while (*s1 == *t1 && *s1 != 0) | |
1018 | s1++, t1++; | |
1019 | ||
1020 | /* A match. */ | |
1021 | if (*s1 == *t1) | |
1022 | return 0; | |
1023 | ||
1024 | /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */ | |
9473c522 | 1025 | if (strchr (s1, '.') || strchr (t1, '.')) |
8d08fdba MS |
1026 | continue; |
1027 | ||
1028 | if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.') | |
1029 | continue; | |
1030 | ||
1031 | /* A match. */ | |
1032 | return 0; | |
1033 | } | |
1034 | ||
1035 | /* No matches. */ | |
1036 | return 1; | |
1037 | } | |
1038 | ||
0e5921e8 ZW |
1039 | /* Heuristic to tell whether the user is missing a semicolon |
1040 | after a struct or enum declaration. Emit an error message | |
1041 | if we know the user has blown it. */ | |
1042 | ||
1043 | void | |
1044 | check_for_missing_semicolon (type) | |
1045 | tree type; | |
1046 | { | |
1047 | if (yychar < 0) | |
1048 | yychar = yylex (); | |
1049 | ||
1050 | if ((yychar > 255 | |
1051 | && yychar != SCSPEC | |
1052 | && yychar != IDENTIFIER | |
1053 | && yychar != TYPENAME | |
1054 | && yychar != CV_QUALIFIER | |
1055 | && yychar != SELFNAME) | |
1056 | || yychar == 0 /* EOF */) | |
1057 | { | |
1058 | if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) | |
1059 | error ("semicolon missing after %s declaration", | |
1060 | TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct"); | |
1061 | else | |
1062 | cp_error ("semicolon missing after declaration of `%T'", type); | |
1063 | shadow_tag (build_tree_list (0, type)); | |
1064 | } | |
1065 | /* Could probably also hack cases where class { ... } f (); appears. */ | |
1066 | clear_anon_tags (); | |
1067 | } | |
1068 | ||
1069 | void | |
1070 | note_got_semicolon (type) | |
1071 | tree type; | |
1072 | { | |
1073 | if (!TYPE_P (type)) | |
1074 | my_friendly_abort (60); | |
1075 | if (CLASS_TYPE_P (type)) | |
1076 | CLASSTYPE_GOT_SEMICOLON (type) = 1; | |
1077 | } | |
1078 | ||
1079 | void | |
1080 | note_list_got_semicolon (declspecs) | |
1081 | tree declspecs; | |
1082 | { | |
1083 | tree link; | |
1084 | ||
1085 | for (link = declspecs; link; link = TREE_CHAIN (link)) | |
1086 | { | |
1087 | tree type = TREE_VALUE (link); | |
1088 | if (TYPE_P (type)) | |
1089 | note_got_semicolon (type); | |
1090 | } | |
1091 | clear_anon_tags (); | |
1092 | } | |
1093 | \f | |
1094 | ||
1095 | /* Parse a #pragma whose sole argument is a string constant. | |
1096 | If OPT is true, the argument is optional. */ | |
1097 | static tree | |
1098 | parse_strconst_pragma (name, opt) | |
1099 | const char *name; | |
1100 | int opt; | |
1101 | { | |
1102 | tree result, x; | |
1103 | enum cpp_ttype t; | |
1104 | ||
1105 | t = c_lex (&x); | |
1106 | if (t == CPP_STRING) | |
1107 | { | |
1108 | result = x; | |
1109 | if (c_lex (&x) != CPP_EOF) | |
1110 | warning ("junk at end of #pragma %s", name); | |
1111 | return result; | |
1112 | } | |
1113 | ||
1114 | if (t == CPP_EOF && opt) | |
1115 | return 0; | |
1116 | ||
1117 | error ("invalid #pragma %s", name); | |
1118 | return (tree)-1; | |
1119 | } | |
5362b086 | 1120 | |
0e5921e8 ZW |
1121 | static void |
1122 | handle_pragma_vtable (dfile) | |
1123 | cpp_reader *dfile ATTRIBUTE_UNUSED; | |
1124 | { | |
1125 | tree vtbl = parse_strconst_pragma ("vtable", 0); | |
1126 | ||
1127 | if (vtbl && vtbl != (tree)-1) | |
1128 | pending_vtables = tree_cons (NULL_TREE, | |
1129 | get_identifier (TREE_STRING_POINTER (vtbl)), | |
1130 | pending_vtables); | |
1131 | } | |
1132 | ||
1d02ac83 | 1133 | static void |
0e5921e8 ZW |
1134 | handle_pragma_unit (dfile) |
1135 | cpp_reader *dfile ATTRIBUTE_UNUSED; | |
1d02ac83 | 1136 | { |
0e5921e8 ZW |
1137 | /* Validate syntax, but don't do anything. */ |
1138 | parse_strconst_pragma ("unit", 0); | |
1139 | } | |
1140 | ||
1141 | static void | |
1142 | handle_pragma_interface (dfile) | |
1143 | cpp_reader *dfile ATTRIBUTE_UNUSED; | |
1144 | { | |
1145 | tree fname = parse_strconst_pragma ("interface", 1); | |
1146 | struct c_fileinfo *finfo; | |
1147 | const char *main_filename; | |
1148 | ||
1149 | if (fname == (tree)-1) | |
1150 | return; | |
1151 | else if (fname == 0) | |
1152 | main_filename = file_name_nondirectory (input_filename); | |
1153 | else | |
1154 | main_filename = TREE_STRING_POINTER (fname); | |
1155 | ||
1156 | finfo = get_fileinfo (input_filename); | |
1d02ac83 JM |
1157 | |
1158 | if (impl_file_chain == 0) | |
1159 | { | |
1160 | /* If this is zero at this point, then we are | |
1161 | auto-implementing. */ | |
1162 | if (main_input_filename == 0) | |
1163 | main_input_filename = input_filename; | |
1d02ac83 JM |
1164 | } |
1165 | ||
1166 | interface_only = interface_strcmp (main_filename); | |
1167 | #ifdef MULTIPLE_SYMBOL_SPACES | |
1168 | if (! interface_only) | |
0e5921e8 | 1169 | #endif |
1d02ac83 | 1170 | interface_unknown = 0; |
0e5921e8 ZW |
1171 | |
1172 | finfo->interface_only = interface_only; | |
1173 | finfo->interface_unknown = interface_unknown; | |
1d02ac83 JM |
1174 | } |
1175 | ||
777ffbda JM |
1176 | /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME. |
1177 | We used to only allow this at toplevel, but that restriction was buggy | |
1178 | in older compilers and it seems reasonable to allow it in the headers | |
1179 | themselves, too. It only needs to precede the matching #p interface. | |
1180 | ||
1181 | We don't touch interface_only or interface_unknown; the user must specify | |
1182 | a matching #p interface for this to have any effect. */ | |
1183 | ||
1d02ac83 | 1184 | static void |
0e5921e8 ZW |
1185 | handle_pragma_implementation (dfile) |
1186 | cpp_reader *dfile ATTRIBUTE_UNUSED; | |
1d02ac83 | 1187 | { |
0e5921e8 ZW |
1188 | tree fname = parse_strconst_pragma ("implementation", 1); |
1189 | const char *main_filename; | |
777ffbda | 1190 | struct impl_files *ifiles = impl_file_chain; |
0e5921e8 ZW |
1191 | |
1192 | if (fname == (tree)-1) | |
1193 | return; | |
1194 | ||
1195 | if (fname == 0) | |
1196 | { | |
1197 | if (main_input_filename) | |
1198 | main_filename = main_input_filename; | |
1199 | else | |
1200 | main_filename = input_filename; | |
1201 | main_filename = file_name_nondirectory (main_filename); | |
1202 | } | |
1203 | else | |
1204 | { | |
1205 | main_filename = TREE_STRING_POINTER (fname); | |
1206 | #if USE_CPPLIB | |
1207 | ||
1208 | if (cpp_included (&parse_in, main_filename)) | |
1209 | warning ("#pragma implementation for %s appears after file is included", | |
1210 | main_filename); | |
1211 | #endif | |
1212 | } | |
1213 | ||
777ffbda | 1214 | for (; ifiles; ifiles = ifiles->next) |
1d02ac83 | 1215 | { |
777ffbda JM |
1216 | if (! strcmp (ifiles->filename, main_filename)) |
1217 | break; | |
1d02ac83 | 1218 | } |
777ffbda | 1219 | if (ifiles == 0) |
1d02ac83 | 1220 | { |
777ffbda JM |
1221 | ifiles = (struct impl_files*) xmalloc (sizeof (struct impl_files)); |
1222 | ifiles->filename = ggc_alloc_string (main_filename, -1); | |
1223 | ifiles->next = impl_file_chain; | |
1224 | impl_file_chain = ifiles; | |
1d02ac83 | 1225 | } |
1d02ac83 | 1226 | } |
f181d4ae | 1227 | |
0e5921e8 ZW |
1228 | void |
1229 | do_pending_lang_change () | |
f181d4ae | 1230 | { |
0e5921e8 ZW |
1231 | for (; pending_lang_change > 0; --pending_lang_change) |
1232 | push_lang_context (lang_name_c); | |
1233 | for (; pending_lang_change < 0; ++pending_lang_change) | |
1234 | pop_lang_context (); | |
f181d4ae MM |
1235 | } |
1236 | ||
0e5921e8 | 1237 | /* Return true if d is in a global scope. */ |
e92cc029 | 1238 | |
0e5921e8 ZW |
1239 | static int |
1240 | is_global (d) | |
1241 | tree d; | |
8d08fdba | 1242 | { |
0e5921e8 ZW |
1243 | while (1) |
1244 | switch (TREE_CODE (d)) | |
1245 | { | |
1246 | case ERROR_MARK: | |
1247 | return 1; | |
f376e137 | 1248 | |
0e5921e8 ZW |
1249 | case OVERLOAD: d = OVL_FUNCTION (d); continue; |
1250 | case TREE_LIST: d = TREE_VALUE (d); continue; | |
1251 | default: | |
1252 | my_friendly_assert (DECL_P (d), 980629); | |
f376e137 | 1253 | |
0e5921e8 | 1254 | return DECL_NAMESPACE_SCOPE_P (d); |
eac293a1 | 1255 | } |
8d08fdba MS |
1256 | } |
1257 | ||
0e5921e8 ZW |
1258 | tree |
1259 | do_identifier (token, parsing, args) | |
1260 | register tree token; | |
1261 | int parsing; | |
1262 | tree args; | |
8d08fdba | 1263 | { |
0e5921e8 ZW |
1264 | register tree id; |
1265 | int lexing = (parsing == 1); | |
e92cc029 | 1266 | |
5361cbb7 | 1267 | if (! lexing) |
0e5921e8 | 1268 | id = lookup_name (token, 0); |
8d08fdba | 1269 | else |
0e5921e8 | 1270 | id = lastiddecl; |
8d08fdba | 1271 | |
0e5921e8 ZW |
1272 | /* Do Koenig lookup if appropriate (inside templates we build lookup |
1273 | expressions instead). | |
8d08fdba | 1274 | |
0e5921e8 ZW |
1275 | [basic.lookup.koenig]: If the ordinary unqualified lookup of the name |
1276 | finds the declaration of a class member function, the associated | |
1277 | namespaces and classes are not considered. */ | |
2c169bab | 1278 | |
a759e627 | 1279 | if (args && !current_template_parms && (!id || is_global (id))) |
f181d4ae | 1280 | id = lookup_arg_dependent (token, id, args); |
a759e627 | 1281 | |
8d2733ca MS |
1282 | /* Remember that this name has been used in the class definition, as per |
1283 | [class.scope0] */ | |
70adf8a9 | 1284 | if (id && parsing) |
8f032717 | 1285 | maybe_note_name_used_in_class (token, id); |
72b7eeff | 1286 | |
5b163de4 JM |
1287 | if (id == error_mark_node) |
1288 | { | |
1289 | /* lookup_name quietly returns error_mark_node if we're parsing, | |
1290 | as we don't want to complain about an identifier that ends up | |
1291 | being used as a declarator. So we call it again to get the error | |
1292 | message. */ | |
1293 | id = lookup_name (token, 0); | |
1294 | return error_mark_node; | |
1295 | } | |
935d1834 ZW |
1296 | |
1297 | if (!id || (TREE_CODE (id) == FUNCTION_DECL | |
1298 | && DECL_ANTICIPATED (id))) | |
5b163de4 | 1299 | { |
5566b478 | 1300 | if (current_template_parms) |
672476cb | 1301 | return build_min_nt (LOOKUP_EXPR, token); |
5566b478 | 1302 | else if (IDENTIFIER_OPNAME_P (token)) |
72b7eeff | 1303 | { |
596ea4e5 | 1304 | if (token != ansi_opname (ERROR_MARK)) |
8251199e | 1305 | cp_error ("`%D' not defined", token); |
72b7eeff MS |
1306 | id = error_mark_node; |
1307 | } | |
8d08fdba MS |
1308 | else if (current_function_decl == 0) |
1309 | { | |
8251199e | 1310 | cp_error ("`%D' was not declared in this scope", token); |
8d08fdba MS |
1311 | id = error_mark_node; |
1312 | } | |
1313 | else | |
1314 | { | |
30394414 | 1315 | if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node |
8d08fdba MS |
1316 | || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl) |
1317 | { | |
1318 | static int undeclared_variable_notice; | |
1319 | ||
8251199e | 1320 | cp_error ("`%D' undeclared (first use this function)", token); |
8d08fdba MS |
1321 | |
1322 | if (! undeclared_variable_notice) | |
1323 | { | |
b4f4233d | 1324 | error ("(Each undeclared identifier is reported only once for each function it appears in.)"); |
8d08fdba MS |
1325 | undeclared_variable_notice = 1; |
1326 | } | |
1327 | } | |
1328 | id = error_mark_node; | |
1329 | /* Prevent repeated error messages. */ | |
2c73f9f5 | 1330 | SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node); |
8d08fdba MS |
1331 | SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl); |
1332 | } | |
1333 | } | |
f3be9e3c PB |
1334 | |
1335 | if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id)) | |
1336 | { | |
1337 | tree shadowed = DECL_SHADOWED_FOR_VAR (id); | |
2ee887f2 MS |
1338 | while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL |
1339 | && DECL_DEAD_FOR_LOCAL (shadowed)) | |
1340 | shadowed = DECL_SHADOWED_FOR_VAR (shadowed); | |
1341 | if (!shadowed) | |
30394414 | 1342 | shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id)); |
f3be9e3c PB |
1343 | if (shadowed) |
1344 | { | |
1345 | if (!DECL_ERROR_REPORTED (id)) | |
1346 | { | |
8251199e | 1347 | warning ("name lookup of `%s' changed", |
f3be9e3c | 1348 | IDENTIFIER_POINTER (token)); |
cab1f180 | 1349 | cp_warning_at (" matches this `%D' under ISO standard rules", |
f3be9e3c | 1350 | shadowed); |
8251199e | 1351 | cp_warning_at (" matches this `%D' under old rules", id); |
f3be9e3c PB |
1352 | DECL_ERROR_REPORTED (id) = 1; |
1353 | } | |
1354 | id = shadowed; | |
1355 | } | |
1356 | else if (!DECL_ERROR_REPORTED (id)) | |
1357 | { | |
f3be9e3c | 1358 | DECL_ERROR_REPORTED (id) = 1; |
834c6dff | 1359 | if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (id))) |
f3be9e3c | 1360 | { |
cab1f180 | 1361 | error ("name lookup of `%s' changed for new ISO `for' scoping", |
b9d12519 | 1362 | IDENTIFIER_POINTER (token)); |
8251199e | 1363 | cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id); |
f3be9e3c PB |
1364 | id = error_mark_node; |
1365 | } | |
1366 | else | |
1367 | { | |
cab1f180 | 1368 | pedwarn ("name lookup of `%s' changed for new ISO `for' scoping", |
b9d12519 | 1369 | IDENTIFIER_POINTER (token)); |
8251199e | 1370 | cp_pedwarn_at (" using obsolete binding at `%D'", id); |
f3be9e3c PB |
1371 | } |
1372 | } | |
1373 | } | |
8d08fdba MS |
1374 | /* TREE_USED is set in `hack_identifier'. */ |
1375 | if (TREE_CODE (id) == CONST_DECL) | |
1376 | { | |
d6479fe7 | 1377 | /* Check access. */ |
8d08fdba | 1378 | if (IDENTIFIER_CLASS_VALUE (token) == id) |
4f1c5b7d | 1379 | enforce_access (CP_DECL_CONTEXT(id), id); |
50714e79 | 1380 | if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id)) |
5566b478 | 1381 | id = DECL_INITIAL (id); |
8d08fdba MS |
1382 | } |
1383 | else | |
5566b478 MS |
1384 | id = hack_identifier (id, token); |
1385 | ||
ed44da02 MM |
1386 | /* We must look up dependent names when the template is |
1387 | instantiated, not while parsing it. For now, we don't | |
1388 | distinguish between dependent and independent names. So, for | |
1389 | example, we look up all overloaded functions at | |
1390 | instantiation-time, even though in some cases we should just use | |
1391 | the DECL we have here. We also use LOOKUP_EXPRs to find things | |
c0a483c7 | 1392 | like local variables, rather than creating TEMPLATE_DECLs for the |
ed44da02 | 1393 | local variables and then finding matching instantiations. */ |
672476cb | 1394 | if (current_template_parms |
5362b086 EC |
1395 | && (is_overloaded_fn (id) |
1396 | || (TREE_CODE (id) == VAR_DECL | |
ed44da02 MM |
1397 | && CP_DECL_CONTEXT (id) |
1398 | && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL) | |
672476cb | 1399 | || TREE_CODE (id) == PARM_DECL |
c6882a35 | 1400 | || TREE_CODE (id) == RESULT_DECL |
672476cb MM |
1401 | || TREE_CODE (id) == USING_DECL)) |
1402 | id = build_min_nt (LOOKUP_EXPR, token); | |
5362b086 | 1403 | |
5566b478 MS |
1404 | return id; |
1405 | } | |
1406 | ||
1407 | tree | |
1408 | do_scoped_id (token, parsing) | |
1409 | tree token; | |
1410 | int parsing; | |
1411 | { | |
30394414 JM |
1412 | tree id; |
1413 | /* during parsing, this is ::name. Otherwise, it is black magic. */ | |
1414 | if (parsing) | |
2c73f9f5 | 1415 | { |
87e3dbc9 | 1416 | id = make_node (CPLUS_BINDING); |
52c11ef6 | 1417 | if (!qualified_lookup_using_namespace (token, global_namespace, id, 0)) |
2c73f9f5 ML |
1418 | id = NULL_TREE; |
1419 | else | |
1420 | id = BINDING_VALUE (id); | |
5362b086 | 1421 | } |
30394414 JM |
1422 | else |
1423 | id = IDENTIFIER_GLOBAL_VALUE (token); | |
5566b478 MS |
1424 | if (parsing && yychar == YYEMPTY) |
1425 | yychar = yylex (); | |
1426 | if (! id) | |
1427 | { | |
5156628f | 1428 | if (processing_template_decl) |
5566b478 | 1429 | { |
672476cb | 1430 | id = build_min_nt (LOOKUP_EXPR, token); |
5566b478 MS |
1431 | LOOKUP_EXPR_GLOBAL (id) = 1; |
1432 | return id; | |
1433 | } | |
8b27e9ef NS |
1434 | if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node) |
1435 | cp_error ("`::%D' undeclared (first use here)", token); | |
1436 | id = error_mark_node; | |
1437 | /* Prevent repeated error messages. */ | |
1438 | SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node); | |
5566b478 MS |
1439 | } |
1440 | else | |
1441 | { | |
1442 | if (TREE_CODE (id) == ADDR_EXPR) | |
1443 | mark_used (TREE_OPERAND (id, 0)); | |
2c73f9f5 | 1444 | else if (TREE_CODE (id) != OVERLOAD) |
5566b478 MS |
1445 | mark_used (id); |
1446 | } | |
5156628f | 1447 | if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl) |
5566b478 MS |
1448 | { |
1449 | /* XXX CHS - should we set TREE_USED of the constant? */ | |
1450 | id = DECL_INITIAL (id); | |
1451 | /* This is to prevent an enum whose value is 0 | |
1452 | from being considered a null pointer constant. */ | |
1453 | id = build1 (NOP_EXPR, TREE_TYPE (id), id); | |
1454 | TREE_CONSTANT (id) = 1; | |
1455 | } | |
1456 | ||
5156628f | 1457 | if (processing_template_decl) |
5566b478 MS |
1458 | { |
1459 | if (is_overloaded_fn (id)) | |
1460 | { | |
672476cb | 1461 | id = build_min_nt (LOOKUP_EXPR, token); |
5566b478 | 1462 | LOOKUP_EXPR_GLOBAL (id) = 1; |
672476cb | 1463 | return id; |
5566b478 MS |
1464 | } |
1465 | /* else just use the decl */ | |
1466 | } | |
42976354 | 1467 | return convert_from_reference (id); |
8d08fdba MS |
1468 | } |
1469 | ||
1470 | tree | |
1471 | identifier_typedecl_value (node) | |
1472 | tree node; | |
1473 | { | |
1474 | tree t, type; | |
1475 | type = IDENTIFIER_TYPE_VALUE (node); | |
1476 | if (type == NULL_TREE) | |
1477 | return NULL_TREE; | |
f181d4ae MM |
1478 | |
1479 | if (IDENTIFIER_BINDING (node)) | |
1480 | { | |
1481 | t = IDENTIFIER_VALUE (node); | |
1482 | if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) | |
1483 | return t; | |
1484 | } | |
1485 | if (IDENTIFIER_NAMESPACE_VALUE (node)) | |
1486 | { | |
1487 | t = IDENTIFIER_NAMESPACE_VALUE (node); | |
1488 | if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) | |
1489 | return t; | |
1490 | } | |
1491 | ||
8d08fdba | 1492 | /* Will this one ever happen? */ |
d2e5ee5c MS |
1493 | if (TYPE_MAIN_DECL (type)) |
1494 | return TYPE_MAIN_DECL (type); | |
8d08fdba MS |
1495 | |
1496 | /* We used to do an internal error of 62 here, but instead we will | |
1497 | handle the return of a null appropriately in the callers. */ | |
1498 | return NULL_TREE; | |
1499 | } | |
1500 | ||
5566b478 | 1501 | #ifdef GATHER_STATISTICS |
5156628f MS |
1502 | /* The original for tree_node_kind is in the toplevel tree.c; changes there |
1503 | need to be brought into here, unless this were actually put into a header | |
1504 | instead. */ | |
1505 | /* Statistics-gathering stuff. */ | |
1506 | typedef enum | |
1507 | { | |
1508 | d_kind, | |
1509 | t_kind, | |
1510 | b_kind, | |
1511 | s_kind, | |
1512 | r_kind, | |
1513 | e_kind, | |
1514 | c_kind, | |
1515 | id_kind, | |
1516 | op_id_kind, | |
1517 | perm_list_kind, | |
1518 | temp_list_kind, | |
1519 | vec_kind, | |
1520 | x_kind, | |
1521 | lang_decl, | |
1522 | lang_type, | |
1523 | all_kinds | |
1524 | } tree_node_kind; | |
1525 | ||
8d08fdba MS |
1526 | extern int tree_node_counts[]; |
1527 | extern int tree_node_sizes[]; | |
5566b478 | 1528 | #endif |
8d08fdba | 1529 | |
8d08fdba MS |
1530 | tree |
1531 | build_lang_decl (code, name, type) | |
1532 | enum tree_code code; | |
1533 | tree name; | |
1534 | tree type; | |
1535 | { | |
4ce3d537 MM |
1536 | tree t; |
1537 | ||
4ce3d537 | 1538 | t = build_decl (code, name, type); |
fcfcdfc8 | 1539 | retrofit_lang_decl (t); |
4ce3d537 | 1540 | |
fcfcdfc8 JM |
1541 | return t; |
1542 | } | |
1543 | ||
1544 | /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl | |
1545 | and pushdecl (for functions generated by the backend). */ | |
1546 | ||
1547 | void | |
1548 | retrofit_lang_decl (t) | |
1549 | tree t; | |
1550 | { | |
9188c363 | 1551 | struct lang_decl *ld; |
4ce3d537 | 1552 | size_t size; |
8d08fdba | 1553 | |
4ce3d537 MM |
1554 | if (CAN_HAVE_FULL_LANG_DECL_P (t)) |
1555 | size = sizeof (struct lang_decl); | |
1556 | else | |
1557 | size = sizeof (struct lang_decl_flags); | |
b0d06515 | 1558 | |
f8a83ee3 | 1559 | ld = (struct lang_decl *) ggc_alloc_cleared (size); |
8d08fdba | 1560 | |
9188c363 | 1561 | DECL_LANG_SPECIFIC (t) = ld; |
8d08fdba | 1562 | if (current_lang_name == lang_name_cplusplus) |
d22c8596 | 1563 | DECL_LANGUAGE (t) = lang_cplusplus; |
8d08fdba MS |
1564 | else if (current_lang_name == lang_name_c) |
1565 | DECL_LANGUAGE (t) = lang_c; | |
a1774733 BK |
1566 | else if (current_lang_name == lang_name_java) |
1567 | DECL_LANGUAGE (t) = lang_java; | |
8d08fdba MS |
1568 | else my_friendly_abort (64); |
1569 | ||
8d08fdba MS |
1570 | #ifdef GATHER_STATISTICS |
1571 | tree_node_counts[(int)lang_decl] += 1; | |
4ce3d537 | 1572 | tree_node_sizes[(int)lang_decl] += size; |
8d08fdba | 1573 | #endif |
8d08fdba MS |
1574 | } |
1575 | ||
8d08fdba MS |
1576 | void |
1577 | copy_lang_decl (node) | |
1578 | tree node; | |
1579 | { | |
1580 | int size; | |
d60f72ae | 1581 | struct lang_decl *ld; |
8d08fdba | 1582 | |
5566b478 MS |
1583 | if (! DECL_LANG_SPECIFIC (node)) |
1584 | return; | |
1585 | ||
b0d06515 | 1586 | if (!CAN_HAVE_FULL_LANG_DECL_P (node)) |
8d08fdba MS |
1587 | size = sizeof (struct lang_decl_flags); |
1588 | else | |
1589 | size = sizeof (struct lang_decl); | |
d60f72ae MM |
1590 | ld = (struct lang_decl *) ggc_alloc (size); |
1591 | bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)ld, size); | |
1592 | DECL_LANG_SPECIFIC (node) = ld; | |
8d08fdba MS |
1593 | } |
1594 | ||
0acf7199 MM |
1595 | /* Copy DECL, including any language-specific parts. */ |
1596 | ||
1597 | tree | |
1598 | copy_decl (decl) | |
1599 | tree decl; | |
1600 | { | |
1601 | tree copy; | |
1602 | ||
1603 | copy = copy_node (decl); | |
1604 | copy_lang_decl (copy); | |
1605 | return copy; | |
1606 | } | |
1607 | ||
8d08fdba | 1608 | tree |
266f2faa | 1609 | cp_make_lang_type (code) |
8d08fdba MS |
1610 | enum tree_code code; |
1611 | { | |
8d08fdba | 1612 | register tree t = make_node (code); |
8d08fdba MS |
1613 | |
1614 | /* Set up some flags that give proper default behavior. */ | |
7ddedda4 MM |
1615 | if (IS_AGGR_TYPE_CODE (code)) |
1616 | { | |
32201ce4 AS |
1617 | struct lang_type *pi; |
1618 | ||
5362b086 | 1619 | pi = ((struct lang_type *) |
f15b9af9 | 1620 | ggc_alloc_cleared (sizeof (struct lang_type))); |
8d08fdba | 1621 | |
32201ce4 | 1622 | TYPE_LANG_SPECIFIC (t) = pi; |
7ddedda4 MM |
1623 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown); |
1624 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
8d08fdba | 1625 | |
7ddedda4 MM |
1626 | /* Make sure this is laid out, for ease of use later. In the |
1627 | presence of parse errors, the normal was of assuring this | |
1628 | might not ever get executed, so we lay it out *immediately*. */ | |
1629 | build_pointer_type (t); | |
8d08fdba MS |
1630 | |
1631 | #ifdef GATHER_STATISTICS | |
7ddedda4 MM |
1632 | tree_node_counts[(int)lang_type] += 1; |
1633 | tree_node_sizes[(int)lang_type] += sizeof (struct lang_type); | |
8d08fdba | 1634 | #endif |
7ddedda4 MM |
1635 | } |
1636 | else | |
1637 | /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But, | |
1638 | TYPE_ALIAS_SET is initialized to -1 by default, so we must | |
1639 | clear it here. */ | |
1640 | TYPE_ALIAS_SET (t) = 0; | |
8d08fdba | 1641 | |
807625cf | 1642 | /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs |
f6a7cfd2 MM |
1643 | since they can be virtual base types, and we then need a |
1644 | canonical binfo for them. Ideally, this would be done lazily for | |
1645 | all types. */ | |
1646 | if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM) | |
fed3cef0 | 1647 | TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE); |
f6a7cfd2 | 1648 | |
8d08fdba MS |
1649 | return t; |
1650 | } | |
1651 | ||
33848bb0 RH |
1652 | tree |
1653 | make_aggr_type (code) | |
1654 | enum tree_code code; | |
1655 | { | |
1656 | tree t = cp_make_lang_type (code); | |
1657 | ||
1658 | if (IS_AGGR_TYPE_CODE (code)) | |
1659 | SET_IS_AGGR_TYPE (t, 1); | |
1660 | ||
1661 | return t; | |
1662 | } | |
1663 | ||
8d08fdba | 1664 | void |
158991b7 | 1665 | compiler_error VPARAMS ((const char *msg, ...)) |
8d08fdba | 1666 | { |
d8e178a0 KG |
1667 | #ifndef ANSI_PROTOTYPES |
1668 | const char *msg; | |
1669 | #endif | |
8d08fdba | 1670 | char buf[1024]; |
d8e178a0 | 1671 | va_list ap; |
5362b086 | 1672 | |
d8e178a0 | 1673 | VA_START (ap, msg); |
5362b086 | 1674 | |
d8e178a0 KG |
1675 | #ifndef ANSI_PROTOTYPES |
1676 | msg = va_arg (ap, const char *); | |
1677 | #endif | |
1678 | ||
1679 | vsprintf (buf, msg, ap); | |
f0305a2b | 1680 | va_end (ap); |
8d08fdba MS |
1681 | error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf); |
1682 | } | |
0e5921e8 | 1683 | |
91063b51 MM |
1684 | /* Return the type-qualifier corresponding to the identifier given by |
1685 | RID. */ | |
1686 | ||
1687 | int | |
1688 | cp_type_qual_from_rid (rid) | |
1689 | tree rid; | |
1690 | { | |
1691 | if (rid == ridpointers[(int) RID_CONST]) | |
1692 | return TYPE_QUAL_CONST; | |
1693 | else if (rid == ridpointers[(int) RID_VOLATILE]) | |
1694 | return TYPE_QUAL_VOLATILE; | |
1695 | else if (rid == ridpointers[(int) RID_RESTRICT]) | |
1696 | return TYPE_QUAL_RESTRICT; | |
1697 | ||
1698 | my_friendly_abort (0); | |
1699 | return TYPE_UNQUALIFIED; | |
1700 | } |