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