* config/alpha/alpha.c, config/alpha/alpha.md,
[official-gcc.git] / gcc / cp / lex.c
blob2f619be9645f710e9b4b685ff522f02f99449697
1 /* Separate lexical analyzer for GNU C++.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GCC.
8 GCC 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.
13 GCC 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.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
24 /* This file is the lexical analyzer for GNU C++. */
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "tm.h"
30 #include "input.h"
31 #include "tree.h"
32 #include "cp-tree.h"
33 #include "cpplib.h"
34 #include "flags.h"
35 #include "c-pragma.h"
36 #include "toplev.h"
37 #include "output.h"
38 #include "tm_p.h"
39 #include "timevar.h"
41 static int interface_strcmp (const char *);
42 static void init_cp_pragma (void);
44 static tree parse_strconst_pragma (const char *, int);
45 static void handle_pragma_vtable (cpp_reader *);
46 static void handle_pragma_unit (cpp_reader *);
47 static void handle_pragma_interface (cpp_reader *);
48 static void handle_pragma_implementation (cpp_reader *);
49 static void handle_pragma_java_exceptions (cpp_reader *);
51 static void init_operators (void);
52 static void copy_lang_type (tree);
54 /* A constraint that can be tested at compile time. */
55 #define CONSTRAINT(name, expr) extern int constraint_##name [(expr) ? 1 : -1]
57 /* Functions and data structures for #pragma interface.
59 `#pragma implementation' means that the main file being compiled
60 is considered to implement (provide) the classes that appear in
61 its main body. I.e., if this is file "foo.cc", and class `bar'
62 is defined in "foo.cc", then we say that "foo.cc implements bar".
64 All main input files "implement" themselves automagically.
66 `#pragma interface' means that unless this file (of the form "foo.h"
67 is not presently being included by file "foo.cc", the
68 CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none
69 of the vtables nor any of the inline functions defined in foo.h
70 will ever be output.
72 There are cases when we want to link files such as "defs.h" and
73 "main.cc". In this case, we give "defs.h" a `#pragma interface',
74 and "main.cc" has `#pragma implementation "defs.h"'. */
76 struct impl_files
78 const char *filename;
79 struct impl_files *next;
82 static struct impl_files *impl_file_chain;
85 void
86 cxx_finish (void)
88 c_common_finish ();
91 /* A mapping from tree codes to operator name information. */
92 operator_name_info_t operator_name_info[(int) LAST_CPLUS_TREE_CODE];
93 /* Similar, but for assignment operators. */
94 operator_name_info_t assignment_operator_name_info[(int) LAST_CPLUS_TREE_CODE];
96 /* Initialize data structures that keep track of operator names. */
98 #define DEF_OPERATOR(NAME, C, M, AR, AP) \
99 CONSTRAINT (C, sizeof "operator " + sizeof NAME <= 256);
100 #include "operators.def"
101 #undef DEF_OPERATOR
103 static void
104 init_operators (void)
106 tree identifier;
107 char buffer[256];
108 struct operator_name_info_t *oni;
110 #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \
111 sprintf (buffer, ISALPHA (NAME[0]) ? "operator %s" : "operator%s", NAME); \
112 identifier = get_identifier (buffer); \
113 IDENTIFIER_OPNAME_P (identifier) = 1; \
115 oni = (ASSN_P \
116 ? &assignment_operator_name_info[(int) CODE] \
117 : &operator_name_info[(int) CODE]); \
118 oni->identifier = identifier; \
119 oni->name = NAME; \
120 oni->mangled_name = MANGLING; \
121 oni->arity = ARITY;
123 #include "operators.def"
124 #undef DEF_OPERATOR
126 operator_name_info[(int) ERROR_MARK].identifier
127 = get_identifier ("<invalid operator>");
129 /* Handle some special cases. These operators are not defined in
130 the language, but can be produced internally. We may need them
131 for error-reporting. (Eventually, we should ensure that this
132 does not happen. Error messages involving these operators will
133 be confusing to users.) */
135 operator_name_info [(int) INIT_EXPR].name
136 = operator_name_info [(int) MODIFY_EXPR].name;
137 operator_name_info [(int) EXACT_DIV_EXPR].name = "(ceiling /)";
138 operator_name_info [(int) CEIL_DIV_EXPR].name = "(ceiling /)";
139 operator_name_info [(int) FLOOR_DIV_EXPR].name = "(floor /)";
140 operator_name_info [(int) ROUND_DIV_EXPR].name = "(round /)";
141 operator_name_info [(int) CEIL_MOD_EXPR].name = "(ceiling %)";
142 operator_name_info [(int) FLOOR_MOD_EXPR].name = "(floor %)";
143 operator_name_info [(int) ROUND_MOD_EXPR].name = "(round %)";
144 operator_name_info [(int) ABS_EXPR].name = "abs";
145 operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
146 operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
147 operator_name_info [(int) RANGE_EXPR].name = "...";
148 operator_name_info [(int) UNARY_PLUS_EXPR].name = "+";
150 assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
151 = "(exact /=)";
152 assignment_operator_name_info [(int) CEIL_DIV_EXPR].name
153 = "(ceiling /=)";
154 assignment_operator_name_info [(int) FLOOR_DIV_EXPR].name
155 = "(floor /=)";
156 assignment_operator_name_info [(int) ROUND_DIV_EXPR].name
157 = "(round /=)";
158 assignment_operator_name_info [(int) CEIL_MOD_EXPR].name
159 = "(ceiling %=)";
160 assignment_operator_name_info [(int) FLOOR_MOD_EXPR].name
161 = "(floor %=)";
162 assignment_operator_name_info [(int) ROUND_MOD_EXPR].name
163 = "(round %=)";
166 /* The reserved keyword table. */
167 struct resword
169 const char *const word;
170 ENUM_BITFIELD(rid) const rid : 16;
171 const unsigned int disable : 16;
174 /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
175 _true_. */
176 #define D_EXT 0x01 /* GCC extension */
177 #define D_ASM 0x02 /* in C99, but has a switch to turn it off */
178 #define D_OBJC 0x04 /* Objective C++ only */
179 #define D_CXX0X 0x08 /* C++0x only */
181 CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
183 static const struct resword reswords[] =
185 { "_Complex", RID_COMPLEX, 0 },
186 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
187 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
188 { "__alignof", RID_ALIGNOF, 0 },
189 { "__alignof__", RID_ALIGNOF, 0 },
190 { "__asm", RID_ASM, 0 },
191 { "__asm__", RID_ASM, 0 },
192 { "__attribute", RID_ATTRIBUTE, 0 },
193 { "__attribute__", RID_ATTRIBUTE, 0 },
194 { "__builtin_offsetof", RID_OFFSETOF, 0 },
195 { "__builtin_va_arg", RID_VA_ARG, 0 },
196 { "__complex", RID_COMPLEX, 0 },
197 { "__complex__", RID_COMPLEX, 0 },
198 { "__const", RID_CONST, 0 },
199 { "__const__", RID_CONST, 0 },
200 { "__extension__", RID_EXTENSION, 0 },
201 { "__func__", RID_C99_FUNCTION_NAME, 0 },
202 { "__imag", RID_IMAGPART, 0 },
203 { "__imag__", RID_IMAGPART, 0 },
204 { "__inline", RID_INLINE, 0 },
205 { "__inline__", RID_INLINE, 0 },
206 { "__label__", RID_LABEL, 0 },
207 { "__null", RID_NULL, 0 },
208 { "__real", RID_REALPART, 0 },
209 { "__real__", RID_REALPART, 0 },
210 { "__restrict", RID_RESTRICT, 0 },
211 { "__restrict__", RID_RESTRICT, 0 },
212 { "__signed", RID_SIGNED, 0 },
213 { "__signed__", RID_SIGNED, 0 },
214 { "__thread", RID_THREAD, 0 },
215 { "__typeof", RID_TYPEOF, 0 },
216 { "__typeof__", RID_TYPEOF, 0 },
217 { "__volatile", RID_VOLATILE, 0 },
218 { "__volatile__", RID_VOLATILE, 0 },
219 { "asm", RID_ASM, D_ASM },
220 { "auto", RID_AUTO, 0 },
221 { "bool", RID_BOOL, 0 },
222 { "break", RID_BREAK, 0 },
223 { "case", RID_CASE, 0 },
224 { "catch", RID_CATCH, 0 },
225 { "char", RID_CHAR, 0 },
226 { "class", RID_CLASS, 0 },
227 { "const", RID_CONST, 0 },
228 { "const_cast", RID_CONSTCAST, 0 },
229 { "continue", RID_CONTINUE, 0 },
230 { "default", RID_DEFAULT, 0 },
231 { "delete", RID_DELETE, 0 },
232 { "do", RID_DO, 0 },
233 { "double", RID_DOUBLE, 0 },
234 { "dynamic_cast", RID_DYNCAST, 0 },
235 { "else", RID_ELSE, 0 },
236 { "enum", RID_ENUM, 0 },
237 { "explicit", RID_EXPLICIT, 0 },
238 { "export", RID_EXPORT, 0 },
239 { "extern", RID_EXTERN, 0 },
240 { "false", RID_FALSE, 0 },
241 { "float", RID_FLOAT, 0 },
242 { "for", RID_FOR, 0 },
243 { "friend", RID_FRIEND, 0 },
244 { "goto", RID_GOTO, 0 },
245 { "if", RID_IF, 0 },
246 { "inline", RID_INLINE, 0 },
247 { "int", RID_INT, 0 },
248 { "long", RID_LONG, 0 },
249 { "mutable", RID_MUTABLE, 0 },
250 { "namespace", RID_NAMESPACE, 0 },
251 { "new", RID_NEW, 0 },
252 { "operator", RID_OPERATOR, 0 },
253 { "private", RID_PRIVATE, 0 },
254 { "protected", RID_PROTECTED, 0 },
255 { "public", RID_PUBLIC, 0 },
256 { "register", RID_REGISTER, 0 },
257 { "reinterpret_cast", RID_REINTCAST, 0 },
258 { "return", RID_RETURN, 0 },
259 { "short", RID_SHORT, 0 },
260 { "signed", RID_SIGNED, 0 },
261 { "sizeof", RID_SIZEOF, 0 },
262 { "static", RID_STATIC, 0 },
263 { "static_assert", RID_STATIC_ASSERT, D_CXX0X },
264 { "static_cast", RID_STATCAST, 0 },
265 { "struct", RID_STRUCT, 0 },
266 { "switch", RID_SWITCH, 0 },
267 { "template", RID_TEMPLATE, 0 },
268 { "this", RID_THIS, 0 },
269 { "throw", RID_THROW, 0 },
270 { "true", RID_TRUE, 0 },
271 { "try", RID_TRY, 0 },
272 { "typedef", RID_TYPEDEF, 0 },
273 { "typename", RID_TYPENAME, 0 },
274 { "typeid", RID_TYPEID, 0 },
275 { "typeof", RID_TYPEOF, D_ASM|D_EXT },
276 { "union", RID_UNION, 0 },
277 { "unsigned", RID_UNSIGNED, 0 },
278 { "using", RID_USING, 0 },
279 { "virtual", RID_VIRTUAL, 0 },
280 { "void", RID_VOID, 0 },
281 { "volatile", RID_VOLATILE, 0 },
282 { "wchar_t", RID_WCHAR, 0 },
283 { "while", RID_WHILE, 0 },
285 /* The remaining keywords are specific to Objective-C++. NB:
286 All of them will remain _disabled_, since they are context-
287 sensitive. */
289 /* These ObjC keywords are recognized only immediately after
290 an '@'. NB: The following C++ keywords double as
291 ObjC keywords in this context: RID_CLASS, RID_PRIVATE,
292 RID_PROTECTED, RID_PUBLIC, RID_THROW, RID_TRY and RID_CATCH. */
293 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
294 { "defs", RID_AT_DEFS, D_OBJC },
295 { "encode", RID_AT_ENCODE, D_OBJC },
296 { "end", RID_AT_END, D_OBJC },
297 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
298 { "interface", RID_AT_INTERFACE, D_OBJC },
299 { "protocol", RID_AT_PROTOCOL, D_OBJC },
300 { "selector", RID_AT_SELECTOR, D_OBJC },
301 { "finally", RID_AT_FINALLY, D_OBJC },
302 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
303 /* These are recognized only in protocol-qualifier context. */
304 { "bycopy", RID_BYCOPY, D_OBJC },
305 { "byref", RID_BYREF, D_OBJC },
306 { "in", RID_IN, D_OBJC },
307 { "inout", RID_INOUT, D_OBJC },
308 { "oneway", RID_ONEWAY, D_OBJC },
309 { "out", RID_OUT, D_OBJC },
312 void
313 init_reswords (void)
315 unsigned int i;
316 tree id;
317 int mask = ((flag_no_asm ? D_ASM : 0)
318 | D_OBJC
319 | (flag_no_gnu_keywords ? D_EXT : 0)
320 | (flag_cpp0x ? 0 : D_CXX0X));
322 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
323 for (i = 0; i < ARRAY_SIZE (reswords); i++)
325 id = get_identifier (reswords[i].word);
326 C_RID_CODE (id) = reswords[i].rid;
327 ridpointers [(int) reswords[i].rid] = id;
328 if (! (reswords[i].disable & mask))
329 C_IS_RESERVED_WORD (id) = 1;
333 static void
334 init_cp_pragma (void)
336 c_register_pragma (0, "vtable", handle_pragma_vtable);
337 c_register_pragma (0, "unit", handle_pragma_unit);
338 c_register_pragma (0, "interface", handle_pragma_interface);
339 c_register_pragma (0, "implementation", handle_pragma_implementation);
340 c_register_pragma ("GCC", "interface", handle_pragma_interface);
341 c_register_pragma ("GCC", "implementation", handle_pragma_implementation);
342 c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions);
345 /* TRUE if a code represents a statement. */
347 bool statement_code_p[MAX_TREE_CODES];
349 /* Initialize the C++ front end. This function is very sensitive to
350 the exact order that things are done here. It would be nice if the
351 initialization done by this routine were moved to its subroutines,
352 and the ordering dependencies clarified and reduced. */
353 bool
354 cxx_init (void)
356 unsigned int i;
357 static const enum tree_code stmt_codes[] = {
358 CTOR_INITIALIZER, TRY_BLOCK, HANDLER,
359 EH_SPEC_BLOCK, USING_STMT, TAG_DEFN,
360 IF_STMT, CLEANUP_STMT, FOR_STMT,
361 WHILE_STMT, DO_STMT, BREAK_STMT,
362 CONTINUE_STMT, SWITCH_STMT, EXPR_STMT
365 memset (&statement_code_p, 0, sizeof (statement_code_p));
366 for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
367 statement_code_p[stmt_codes[i]] = true;
369 /* We cannot just assign to input_filename because it has already
370 been initialized and will be used later as an N_BINCL for stabs+
371 debugging. */
372 #ifdef USE_MAPPED_LOCATION
373 push_srcloc (BUILTINS_LOCATION);
374 #else
375 push_srcloc ("<built-in>", 0);
376 #endif
378 init_reswords ();
379 init_tree ();
380 init_cp_semantics ();
381 init_operators ();
382 init_method ();
383 init_error ();
385 current_function_decl = NULL;
387 class_type_node = ridpointers[(int) RID_CLASS];
389 cxx_init_decl_processing ();
391 /* The fact that G++ uses COMDAT for many entities (inline
392 functions, template instantiations, virtual tables, etc.) mean
393 that it is fundamentally unreliable to try to make decisions
394 about whether or not to output a particular entity until the end
395 of the compilation. However, the inliner requires that functions
396 be provided to the back end if they are to be inlined.
397 Therefore, we always use unit-at-a-time mode; in that mode, we
398 can provide entities to the back end and it will decide what to
399 emit based on what is actually needed. */
400 flag_unit_at_a_time = 1;
402 if (c_common_init () == false)
404 pop_srcloc();
405 return false;
408 init_cp_pragma ();
410 init_repo ();
412 pop_srcloc();
413 return true;
416 /* Return nonzero if S is not considered part of an
417 INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */
419 static int
420 interface_strcmp (const char* s)
422 /* Set the interface/implementation bits for this scope. */
423 struct impl_files *ifiles;
424 const char *s1;
426 for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
428 const char *t1 = ifiles->filename;
429 s1 = s;
431 if (*s1 != *t1 || *s1 == 0)
432 continue;
434 while (*s1 == *t1 && *s1 != 0)
435 s1++, t1++;
437 /* A match. */
438 if (*s1 == *t1)
439 return 0;
441 /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */
442 if (strchr (s1, '.') || strchr (t1, '.'))
443 continue;
445 if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
446 continue;
448 /* A match. */
449 return 0;
452 /* No matches. */
453 return 1;
458 /* Parse a #pragma whose sole argument is a string constant.
459 If OPT is true, the argument is optional. */
460 static tree
461 parse_strconst_pragma (const char* name, int opt)
463 tree result, x;
464 enum cpp_ttype t;
466 t = pragma_lex (&result);
467 if (t == CPP_STRING)
469 if (pragma_lex (&x) != CPP_EOF)
470 warning (0, "junk at end of #pragma %s", name);
471 return result;
474 if (t == CPP_EOF && opt)
475 return NULL_TREE;
477 error ("invalid #pragma %s", name);
478 return error_mark_node;
481 static void
482 handle_pragma_vtable (cpp_reader* dfile ATTRIBUTE_UNUSED )
484 parse_strconst_pragma ("vtable", 0);
485 sorry ("#pragma vtable no longer supported");
488 static void
489 handle_pragma_unit (cpp_reader* dfile ATTRIBUTE_UNUSED )
491 /* Validate syntax, but don't do anything. */
492 parse_strconst_pragma ("unit", 0);
495 static void
496 handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
498 tree fname = parse_strconst_pragma ("interface", 1);
499 struct c_fileinfo *finfo;
500 const char *filename;
502 if (fname == error_mark_node)
503 return;
504 else if (fname == 0)
505 filename = lbasename (input_filename);
506 else
507 filename = ggc_strdup (TREE_STRING_POINTER (fname));
509 finfo = get_fileinfo (input_filename);
511 if (impl_file_chain == 0)
513 /* If this is zero at this point, then we are
514 auto-implementing. */
515 if (main_input_filename == 0)
516 main_input_filename = input_filename;
519 finfo->interface_only = interface_strcmp (filename);
520 /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see
521 a definition in another file. */
522 if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only)
523 finfo->interface_unknown = 0;
526 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
527 We used to only allow this at toplevel, but that restriction was buggy
528 in older compilers and it seems reasonable to allow it in the headers
529 themselves, too. It only needs to precede the matching #p interface.
531 We don't touch finfo->interface_only or finfo->interface_unknown;
532 the user must specify a matching #p interface for this to have
533 any effect. */
535 static void
536 handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
538 tree fname = parse_strconst_pragma ("implementation", 1);
539 const char *filename;
540 struct impl_files *ifiles = impl_file_chain;
542 if (fname == error_mark_node)
543 return;
545 if (fname == 0)
547 if (main_input_filename)
548 filename = main_input_filename;
549 else
550 filename = input_filename;
551 filename = lbasename (filename);
553 else
555 filename = ggc_strdup (TREE_STRING_POINTER (fname));
556 #if 0
557 /* We currently cannot give this diagnostic, as we reach this point
558 only after cpplib has scanned the entire translation unit, so
559 cpp_included always returns true. A plausible fix is to compare
560 the current source-location cookie with the first source-location
561 cookie (if any) of the filename, but this requires completing the
562 --enable-mapped-location project first. See PR 17577. */
563 if (cpp_included (parse_in, filename))
564 warning (0, "#pragma implementation for %qs appears after "
565 "file is included", filename);
566 #endif
569 for (; ifiles; ifiles = ifiles->next)
571 if (! strcmp (ifiles->filename, filename))
572 break;
574 if (ifiles == 0)
576 ifiles = XNEW (struct impl_files);
577 ifiles->filename = filename;
578 ifiles->next = impl_file_chain;
579 impl_file_chain = ifiles;
583 /* Indicate that this file uses Java-personality exception handling. */
584 static void
585 handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED)
587 tree x;
588 if (pragma_lex (&x) != CPP_EOF)
589 warning (0, "junk at end of #pragma GCC java_exceptions");
591 choose_personality_routine (lang_java);
594 /* Issue an error message indicating that the lookup of NAME (an
595 IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */
597 tree
598 unqualified_name_lookup_error (tree name)
600 if (IDENTIFIER_OPNAME_P (name))
602 if (name != ansi_opname (ERROR_MARK))
603 error ("%qD not defined", name);
605 else
607 error ("%qD was not declared in this scope", name);
608 /* Prevent repeated error messages by creating a VAR_DECL with
609 this NAME in the innermost block scope. */
610 if (current_function_decl)
612 tree decl;
613 decl = build_decl (VAR_DECL, name, error_mark_node);
614 DECL_CONTEXT (decl) = current_function_decl;
615 push_local_binding (name, decl, 0);
616 /* Mark the variable as used so that we do not get warnings
617 about it being unused later. */
618 TREE_USED (decl) = 1;
622 return error_mark_node;
625 /* Like unqualified_name_lookup_error, but NAME is an unqualified-id
626 used as a function. Returns an appropriate expression for
627 NAME. */
629 tree
630 unqualified_fn_lookup_error (tree name)
632 if (processing_template_decl)
634 /* In a template, it is invalid to write "f()" or "f(3)" if no
635 declaration of "f" is available. Historically, G++ and most
636 other compilers accepted that usage since they deferred all name
637 lookup until instantiation time rather than doing unqualified
638 name lookup at template definition time; explain to the user what
639 is going wrong.
641 Note that we have the exact wording of the following message in
642 the manual (trouble.texi, node "Name lookup"), so they need to
643 be kept in synch. */
644 pedwarn ("there are no arguments to %qD that depend on a template "
645 "parameter, so a declaration of %qD must be available",
646 name, name);
648 if (!flag_permissive)
650 static bool hint;
651 if (!hint)
653 error ("(if you use %<-fpermissive%>, G++ will accept your "
654 "code, but allowing the use of an undeclared name is "
655 "deprecated)");
656 hint = true;
659 return name;
662 return unqualified_name_lookup_error (name);
665 tree
666 build_lang_decl (enum tree_code code, tree name, tree type)
668 tree t;
670 t = build_decl (code, name, type);
671 retrofit_lang_decl (t);
673 /* All nesting of C++ functions is lexical; there is never a "static
674 chain" in the sense of GNU C nested functions. */
675 if (code == FUNCTION_DECL)
676 DECL_NO_STATIC_CHAIN (t) = 1;
678 return t;
681 /* Add DECL_LANG_SPECIFIC info to T. Called from build_lang_decl
682 and pushdecl (for functions generated by the back end). */
684 void
685 retrofit_lang_decl (tree t)
687 struct lang_decl *ld;
688 size_t size;
690 if (CAN_HAVE_FULL_LANG_DECL_P (t))
691 size = sizeof (struct lang_decl);
692 else
693 size = sizeof (struct lang_decl_flags);
695 ld = GGC_CNEWVAR (struct lang_decl, size);
697 ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
698 ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
699 ld->decl_flags.u2sel = 0;
700 if (ld->decl_flags.can_be_full)
701 ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
703 DECL_LANG_SPECIFIC (t) = ld;
704 if (current_lang_name == lang_name_cplusplus
705 || decl_linkage (t) == lk_none)
706 SET_DECL_LANGUAGE (t, lang_cplusplus);
707 else if (current_lang_name == lang_name_c)
708 SET_DECL_LANGUAGE (t, lang_c);
709 else if (current_lang_name == lang_name_java)
710 SET_DECL_LANGUAGE (t, lang_java);
711 else
712 gcc_unreachable ();
714 #ifdef GATHER_STATISTICS
715 tree_node_counts[(int)lang_decl] += 1;
716 tree_node_sizes[(int)lang_decl] += size;
717 #endif
720 void
721 cxx_dup_lang_specific_decl (tree node)
723 int size;
724 struct lang_decl *ld;
726 if (! DECL_LANG_SPECIFIC (node))
727 return;
729 if (!CAN_HAVE_FULL_LANG_DECL_P (node))
730 size = sizeof (struct lang_decl_flags);
731 else
732 size = sizeof (struct lang_decl);
733 ld = GGC_NEWVAR (struct lang_decl, size);
734 memcpy (ld, DECL_LANG_SPECIFIC (node), size);
735 DECL_LANG_SPECIFIC (node) = ld;
737 #ifdef GATHER_STATISTICS
738 tree_node_counts[(int)lang_decl] += 1;
739 tree_node_sizes[(int)lang_decl] += size;
740 #endif
743 /* Copy DECL, including any language-specific parts. */
745 tree
746 copy_decl (tree decl)
748 tree copy;
750 copy = copy_node (decl);
751 cxx_dup_lang_specific_decl (copy);
752 return copy;
755 /* Replace the shared language-specific parts of NODE with a new copy. */
757 static void
758 copy_lang_type (tree node)
760 int size;
761 struct lang_type *lt;
763 if (! TYPE_LANG_SPECIFIC (node))
764 return;
766 if (TYPE_LANG_SPECIFIC (node)->u.h.is_lang_type_class)
767 size = sizeof (struct lang_type);
768 else
769 size = sizeof (struct lang_type_ptrmem);
770 lt = GGC_NEWVAR (struct lang_type, size);
771 memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
772 TYPE_LANG_SPECIFIC (node) = lt;
774 #ifdef GATHER_STATISTICS
775 tree_node_counts[(int)lang_type] += 1;
776 tree_node_sizes[(int)lang_type] += size;
777 #endif
780 /* Copy TYPE, including any language-specific parts. */
782 tree
783 copy_type (tree type)
785 tree copy;
787 copy = copy_node (type);
788 copy_lang_type (copy);
789 return copy;
792 tree
793 cxx_make_type (enum tree_code code)
795 tree t = make_node (code);
797 /* Create lang_type structure. */
798 if (IS_AGGR_TYPE_CODE (code)
799 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
801 struct lang_type *pi = GGC_CNEW (struct lang_type);
803 TYPE_LANG_SPECIFIC (t) = pi;
804 pi->u.c.h.is_lang_type_class = 1;
806 #ifdef GATHER_STATISTICS
807 tree_node_counts[(int)lang_type] += 1;
808 tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
809 #endif
812 /* Set up some flags that give proper default behavior. */
813 if (IS_AGGR_TYPE_CODE (code))
815 struct c_fileinfo *finfo = get_fileinfo (input_filename);
816 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
817 CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
820 return t;
823 tree
824 make_aggr_type (enum tree_code code)
826 tree t = cxx_make_type (code);
828 if (IS_AGGR_TYPE_CODE (code))
829 SET_IS_AGGR_TYPE (t, 1);
831 return t;