Patch: FYI: avoid use of C++ keywords in gcc/java
Tom Tromey
tromey@redhat.com
Thu Jun 26 21:13:00 GMT 2008
>>>>> "Kaveh" == Kaveh R GHAZI <ghazi@caip.rutgers.edu> writes:
>> As for folks fixing it... eventually I hope we can do the poison
>> thing, and then anyone changing it will get an error.
Kaveh> I think Gaby is going to extend -Wc++-compat to warn about these so we
Kaveh> won't have to poison them long-term (PR21759).
Today I wrote an experimental patch to do this. I've appended it, in
all its ChangeLog-less glory. This patch is kind of bogus, but it
works well enough to prevent bootstrapping :). I get a lot of errors
(due to -Werror) from the C++ FE about uses of 'template' and
'namespace' as identifiers.
Tom
Index: gcc/cp/lex.c
===================================================================
--- gcc/cp/lex.c (revision 137041)
+++ gcc/cp/lex.c (working copy)
@@ -163,190 +163,26 @@
= "(round %=)";
}
-/* The reserved keyword table. */
-struct resword
-{
- const char *const word;
- ENUM_BITFIELD(rid) const rid : 16;
- const unsigned int disable : 16;
-};
-
-/* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
- _true_. */
-#define D_EXT 0x01 /* GCC extension */
-#define D_ASM 0x02 /* in C99, but has a switch to turn it off */
-#define D_OBJC 0x04 /* Objective C++ only */
-#define D_CXX0X 0x08 /* C++0x only */
-
CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
-static const struct resword reswords[] =
-{
- { "_Complex", RID_COMPLEX, 0 },
- { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
- { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
- { "__alignof", RID_ALIGNOF, 0 },
- { "__alignof__", RID_ALIGNOF, 0 },
- { "__asm", RID_ASM, 0 },
- { "__asm__", RID_ASM, 0 },
- { "__attribute", RID_ATTRIBUTE, 0 },
- { "__attribute__", RID_ATTRIBUTE, 0 },
- { "__builtin_offsetof", RID_OFFSETOF, 0 },
- { "__builtin_va_arg", RID_VA_ARG, 0 },
- { "__complex", RID_COMPLEX, 0 },
- { "__complex__", RID_COMPLEX, 0 },
- { "__const", RID_CONST, 0 },
- { "__const__", RID_CONST, 0 },
- { "__decltype", RID_DECLTYPE, 0 },
- { "__extension__", RID_EXTENSION, 0 },
- { "__func__", RID_C99_FUNCTION_NAME, 0 },
- { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN, 0 },
- { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR, 0 },
- { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY, 0 },
- { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN, 0 },
- { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR, 0 },
- { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY, 0 },
- { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR, 0 },
- { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR, 0 },
- { "__is_abstract", RID_IS_ABSTRACT, 0 },
- { "__is_base_of", RID_IS_BASE_OF, 0 },
- { "__is_class", RID_IS_CLASS, 0 },
- { "__is_convertible_to", RID_IS_CONVERTIBLE_TO, 0 },
- { "__is_empty", RID_IS_EMPTY, 0 },
- { "__is_enum", RID_IS_ENUM, 0 },
- { "__is_pod", RID_IS_POD, 0 },
- { "__is_polymorphic", RID_IS_POLYMORPHIC, 0 },
- { "__is_union", RID_IS_UNION, 0 },
- { "__imag", RID_IMAGPART, 0 },
- { "__imag__", RID_IMAGPART, 0 },
- { "__inline", RID_INLINE, 0 },
- { "__inline__", RID_INLINE, 0 },
- { "__label__", RID_LABEL, 0 },
- { "__null", RID_NULL, 0 },
- { "__real", RID_REALPART, 0 },
- { "__real__", RID_REALPART, 0 },
- { "__restrict", RID_RESTRICT, 0 },
- { "__restrict__", RID_RESTRICT, 0 },
- { "__signed", RID_SIGNED, 0 },
- { "__signed__", RID_SIGNED, 0 },
- { "__thread", RID_THREAD, 0 },
- { "__typeof", RID_TYPEOF, 0 },
- { "__typeof__", RID_TYPEOF, 0 },
- { "__volatile", RID_VOLATILE, 0 },
- { "__volatile__", RID_VOLATILE, 0 },
- { "asm", RID_ASM, D_ASM },
- { "auto", RID_AUTO, 0 },
- { "bool", RID_BOOL, 0 },
- { "break", RID_BREAK, 0 },
- { "case", RID_CASE, 0 },
- { "catch", RID_CATCH, 0 },
- { "char", RID_CHAR, 0 },
- { "char16_t", RID_CHAR16, D_CXX0X },
- { "char32_t", RID_CHAR32, D_CXX0X },
- { "class", RID_CLASS, 0 },
- { "const", RID_CONST, 0 },
- { "const_cast", RID_CONSTCAST, 0 },
- { "continue", RID_CONTINUE, 0 },
- { "decltype", RID_DECLTYPE, D_CXX0X },
- { "default", RID_DEFAULT, 0 },
- { "delete", RID_DELETE, 0 },
- { "do", RID_DO, 0 },
- { "double", RID_DOUBLE, 0 },
- { "dynamic_cast", RID_DYNCAST, 0 },
- { "else", RID_ELSE, 0 },
- { "enum", RID_ENUM, 0 },
- { "explicit", RID_EXPLICIT, 0 },
- { "export", RID_EXPORT, 0 },
- { "extern", RID_EXTERN, 0 },
- { "false", RID_FALSE, 0 },
- { "float", RID_FLOAT, 0 },
- { "for", RID_FOR, 0 },
- { "friend", RID_FRIEND, 0 },
- { "goto", RID_GOTO, 0 },
- { "if", RID_IF, 0 },
- { "inline", RID_INLINE, 0 },
- { "int", RID_INT, 0 },
- { "long", RID_LONG, 0 },
- { "mutable", RID_MUTABLE, 0 },
- { "namespace", RID_NAMESPACE, 0 },
- { "new", RID_NEW, 0 },
- { "operator", RID_OPERATOR, 0 },
- { "private", RID_PRIVATE, 0 },
- { "protected", RID_PROTECTED, 0 },
- { "public", RID_PUBLIC, 0 },
- { "register", RID_REGISTER, 0 },
- { "reinterpret_cast", RID_REINTCAST, 0 },
- { "return", RID_RETURN, 0 },
- { "short", RID_SHORT, 0 },
- { "signed", RID_SIGNED, 0 },
- { "sizeof", RID_SIZEOF, 0 },
- { "static", RID_STATIC, 0 },
- { "static_assert", RID_STATIC_ASSERT, D_CXX0X },
- { "static_cast", RID_STATCAST, 0 },
- { "struct", RID_STRUCT, 0 },
- { "switch", RID_SWITCH, 0 },
- { "template", RID_TEMPLATE, 0 },
- { "this", RID_THIS, 0 },
- { "throw", RID_THROW, 0 },
- { "true", RID_TRUE, 0 },
- { "try", RID_TRY, 0 },
- { "typedef", RID_TYPEDEF, 0 },
- { "typename", RID_TYPENAME, 0 },
- { "typeid", RID_TYPEID, 0 },
- { "typeof", RID_TYPEOF, D_ASM|D_EXT },
- { "union", RID_UNION, 0 },
- { "unsigned", RID_UNSIGNED, 0 },
- { "using", RID_USING, 0 },
- { "virtual", RID_VIRTUAL, 0 },
- { "void", RID_VOID, 0 },
- { "volatile", RID_VOLATILE, 0 },
- { "wchar_t", RID_WCHAR, 0 },
- { "while", RID_WHILE, 0 },
-
- /* The remaining keywords are specific to Objective-C++. NB:
- All of them will remain _disabled_, since they are context-
- sensitive. */
-
- /* These ObjC keywords are recognized only immediately after
- an '@'. NB: The following C++ keywords double as
- ObjC keywords in this context: RID_CLASS, RID_PRIVATE,
- RID_PROTECTED, RID_PUBLIC, RID_THROW, RID_TRY and RID_CATCH. */
- { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
- { "defs", RID_AT_DEFS, D_OBJC },
- { "encode", RID_AT_ENCODE, D_OBJC },
- { "end", RID_AT_END, D_OBJC },
- { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
- { "interface", RID_AT_INTERFACE, D_OBJC },
- { "protocol", RID_AT_PROTOCOL, D_OBJC },
- { "selector", RID_AT_SELECTOR, D_OBJC },
- { "finally", RID_AT_FINALLY, D_OBJC },
- { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
- /* These are recognized only in protocol-qualifier context. */
- { "bycopy", RID_BYCOPY, D_OBJC },
- { "byref", RID_BYREF, D_OBJC },
- { "in", RID_IN, D_OBJC },
- { "inout", RID_INOUT, D_OBJC },
- { "oneway", RID_ONEWAY, D_OBJC },
- { "out", RID_OUT, D_OBJC },
-};
-
void
init_reswords (void)
{
unsigned int i;
tree id;
- int mask = ((flag_no_asm ? D_ASM : 0)
+ int mask = (D_CONLY
+ | (flag_no_asm ? D_ASM : 0)
| D_OBJC
| (flag_no_gnu_keywords ? D_EXT : 0)
| ((cxx_dialect == cxx0x) ? 0 : D_CXX0X));
ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
- for (i = 0; i < ARRAY_SIZE (reswords); i++)
+ for (i = 0; i < num_c_common_reswords; i++)
{
- id = get_identifier (reswords[i].word);
- C_SET_RID_CODE (id, reswords[i].rid);
- ridpointers [(int) reswords[i].rid] = id;
- if (! (reswords[i].disable & mask))
+ id = get_identifier (c_common_reswords[i].word);
+ C_SET_RID_CODE (id, c_common_reswords[i].rid);
+ ridpointers [(int) c_common_reswords[i].rid] = id;
+ if (! (c_common_reswords[i].disable & mask))
C_IS_RESERVED_WORD (id) = 1;
}
}
Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c (revision 137041)
+++ gcc/c-common.c (working copy)
@@ -219,6 +219,173 @@
tree c_global_trees[CTI_MAX];
+/* Reserved words. */
+const struct c_common_resword c_common_reswords[] =
+{
+ { "_Accum", RID_ACCUM, D_EXT | D_CONLY },
+ { "_Bool", RID_BOOL, 0 },
+ { "_Complex", RID_COMPLEX, 0 },
+ { "_Decimal128", RID_DFLOAT128, D_EXT | D_CONLY },
+ { "_Decimal32", RID_DFLOAT32, D_EXT | D_CONLY },
+ { "_Decimal64", RID_DFLOAT64, D_EXT | D_CONLY },
+ { "_Fract", RID_FRACT, D_EXT | D_CONLY },
+ { "_Sat", RID_SAT, D_EXT | D_CONLY },
+ { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
+ { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
+ { "__alignof", RID_ALIGNOF, 0 },
+ { "__alignof__", RID_ALIGNOF, 0 },
+ { "__asm", RID_ASM, 0 },
+ { "__asm__", RID_ASM, 0 },
+ { "__attribute", RID_ATTRIBUTE, 0 },
+ { "__attribute__", RID_ATTRIBUTE, 0 },
+ { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
+ { "__builtin_offsetof", RID_OFFSETOF, 0 },
+ { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
+ { "__builtin_va_arg", RID_VA_ARG, 0 },
+ { "__complex", RID_COMPLEX, 0 },
+ { "__complex__", RID_COMPLEX, 0 },
+ { "__const", RID_CONST, 0 },
+ { "__const__", RID_CONST, 0 },
+ { "__decltype", RID_DECLTYPE, D_CXX },
+ { "__extension__", RID_EXTENSION, 0 },
+ { "__func__", RID_C99_FUNCTION_NAME, 0 },
+ { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN, D_CXX },
+ { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR, D_CXX },
+ { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY, D_CXX },
+ { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN, D_CXX },
+ { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR, D_CXX },
+ { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY, D_CXX },
+ { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR, D_CXX },
+ { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR, D_CXX },
+ { "__imag", RID_IMAGPART, 0 },
+ { "__imag__", RID_IMAGPART, 0 },
+ { "__inline", RID_INLINE, 0 },
+ { "__inline__", RID_INLINE, 0 },
+ { "__is_abstract", RID_IS_ABSTRACT, D_CXX },
+ { "__is_base_of", RID_IS_BASE_OF, D_CXX },
+ { "__is_class", RID_IS_CLASS, D_CXX },
+ { "__is_convertible_to", RID_IS_CONVERTIBLE_TO, D_CXX },
+ { "__is_empty", RID_IS_EMPTY, D_CXX },
+ { "__is_enum", RID_IS_ENUM, D_CXX },
+ { "__is_pod", RID_IS_POD, D_CXX },
+ { "__is_polymorphic", RID_IS_POLYMORPHIC, D_CXX },
+ { "__is_union", RID_IS_UNION, D_CXX },
+ { "__label__", RID_LABEL, 0 },
+ { "__null", RID_NULL, 0 },
+ { "__real", RID_REALPART, 0 },
+ { "__real__", RID_REALPART, 0 },
+ { "__restrict", RID_RESTRICT, 0 },
+ { "__restrict__", RID_RESTRICT, 0 },
+ { "__signed", RID_SIGNED, 0 },
+ { "__signed__", RID_SIGNED, 0 },
+ { "__thread", RID_THREAD, 0 },
+ { "__typeof", RID_TYPEOF, 0 },
+ { "__typeof__", RID_TYPEOF, 0 },
+ { "__volatile", RID_VOLATILE, 0 },
+ { "__volatile__", RID_VOLATILE, 0 },
+ { "asm", RID_ASM, D_ASM },
+ { "auto", RID_AUTO, 0 },
+ { "bool", RID_BOOL, D_CXX },
+ { "break", RID_BREAK, 0 },
+ { "case", RID_CASE, 0 },
+ { "catch", RID_CATCH, D_OBJC | D_CXX },
+ { "char", RID_CHAR, 0 },
+ { "char16_t", RID_CHAR16, D_CXX0X },
+ { "char32_t", RID_CHAR32, D_CXX0X },
+ { "class", RID_CLASS, D_OBJC | D_CXX },
+ { "const", RID_CONST, 0 },
+ { "const_cast", RID_CONSTCAST, D_CXX },
+ { "continue", RID_CONTINUE, 0 },
+ { "decltype", RID_DECLTYPE, D_CXX0X },
+ { "default", RID_DEFAULT, 0 },
+ { "delete", RID_DELETE, D_CXX },
+ { "do", RID_DO, 0 },
+ { "double", RID_DOUBLE, 0 },
+ { "dynamic_cast", RID_DYNCAST, D_CXX },
+ { "else", RID_ELSE, 0 },
+ { "enum", RID_ENUM, 0 },
+ { "explicit", RID_EXPLICIT, D_CXX },
+ { "export", RID_EXPORT, D_CXX },
+ { "extern", RID_EXTERN, 0 },
+ { "false", RID_FALSE, D_CXX },
+ { "float", RID_FLOAT, 0 },
+ { "for", RID_FOR, 0 },
+ { "friend", RID_FRIEND, D_CXX },
+ { "goto", RID_GOTO, 0 },
+ { "if", RID_IF, 0 },
+ { "inline", RID_INLINE, D_EXT89 },
+ { "int", RID_INT, 0 },
+ { "long", RID_LONG, 0 },
+ { "mutable", RID_MUTABLE, D_CXX },
+ { "namespace", RID_NAMESPACE, D_CXX },
+ { "new", RID_NEW, D_CXX },
+ { "operator", RID_OPERATOR, D_CXX },
+ { "private", RID_PRIVATE, D_OBJC | D_CXX },
+ { "protected", RID_PROTECTED, D_OBJC | D_CXX },
+ { "public", RID_PUBLIC, D_OBJC | D_CXX },
+ { "register", RID_REGISTER, 0 },
+ { "reinterpret_cast", RID_REINTCAST, D_CXX },
+ { "restrict", RID_RESTRICT, D_C89 },
+ { "return", RID_RETURN, 0 },
+ { "short", RID_SHORT, 0 },
+ { "signed", RID_SIGNED, 0 },
+ { "sizeof", RID_SIZEOF, 0 },
+ { "static", RID_STATIC, 0 },
+ { "static_assert", RID_STATIC_ASSERT, D_CXX0X },
+ { "static_cast", RID_STATCAST, D_CXX },
+ { "struct", RID_STRUCT, 0 },
+ { "switch", RID_SWITCH, 0 },
+ { "template", RID_TEMPLATE, D_CXX },
+ { "this", RID_THIS, D_CXX },
+ { "throw", RID_THROW, D_OBJC | D_CXX },
+ { "true", RID_TRUE, D_CXX },
+ { "try", RID_TRY, D_OBJC | D_CXX },
+ { "typedef", RID_TYPEDEF, 0 },
+ { "typeid", RID_TYPEID, D_CXX },
+ { "typename", RID_TYPENAME, D_CXX },
+ { "typeof", RID_TYPEOF, D_ASM|D_EXT },
+ { "union", RID_UNION, 0 },
+ { "unsigned", RID_UNSIGNED, 0 },
+ { "using", RID_USING, D_CXX },
+ { "virtual", RID_VIRTUAL, D_CXX },
+ { "void", RID_VOID, 0 },
+ { "volatile", RID_VOLATILE, 0 },
+ { "wchar_t", RID_WCHAR, D_CXX },
+ { "while", RID_WHILE, 0 },
+
+ /* The remaining keywords are specific to Objective-C++. NB:
+ All of them will remain _disabled_, since they are context-
+ sensitive. */
+
+ /* These ObjC keywords are recognized only immediately after
+ an '@'. NB: The following C++ keywords double as
+ ObjC keywords in this context: RID_CLASS, RID_PRIVATE,
+ RID_PROTECTED, RID_PUBLIC, RID_THROW, RID_TRY and RID_CATCH. */
+ { "class", RID_AT_CLASS, D_OBJC },
+ { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
+ { "defs", RID_AT_DEFS, D_OBJC },
+ { "encode", RID_AT_ENCODE, D_OBJC },
+ { "end", RID_AT_END, D_OBJC },
+ { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
+ { "interface", RID_AT_INTERFACE, D_OBJC },
+ { "protocol", RID_AT_PROTOCOL, D_OBJC },
+ { "selector", RID_AT_SELECTOR, D_OBJC },
+ { "finally", RID_AT_FINALLY, D_OBJC },
+ { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
+ /* These are recognized only in protocol-qualifier context
+ (see above) */
+ { "bycopy", RID_BYCOPY, D_OBJC },
+ { "byref", RID_BYREF, D_OBJC },
+ { "in", RID_IN, D_OBJC },
+ { "inout", RID_INOUT, D_OBJC },
+ { "oneway", RID_ONEWAY, D_OBJC },
+ { "out", RID_OUT, D_OBJC },
+};
+
+const unsigned int num_c_common_reswords = (sizeof c_common_reswords
+ / sizeof (struct c_common_resword));
+
+
/* Switches common to the C front ends. */
/* Nonzero if preprocessing only. */
Index: gcc/c-common.h
===================================================================
--- gcc/c-common.h (revision 137041)
+++ gcc/c-common.h (working copy)
@@ -1,6 +1,6 @@
/* Definitions for c-common.c.
Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
This file is part of GCC.
@@ -71,8 +71,8 @@
RID_ASM, RID_TYPEOF, RID_ALIGNOF, RID_ATTRIBUTE, RID_VA_ARG,
RID_EXTENSION, RID_IMAGPART, RID_REALPART, RID_LABEL, RID_CHOOSE_EXPR,
RID_TYPES_COMPATIBLE_P,
- RID_DFLOAT32, RID_DFLOAT64, RID_DFLOAT128,
- RID_FRACT, RID_ACCUM,
+ RID_DFLOAT32, RID_DFLOAT64, RID_DFLOAT128,
+ RID_FRACT, RID_ACCUM, RID_OFFSETOF,
/* Too many ways of getting the name of a function as a string */
RID_FUNCTION_NAME, RID_PRETTY_FUNCTION_NAME, RID_C99_FUNCTION_NAME,
@@ -82,7 +82,7 @@
RID_PUBLIC, RID_PRIVATE, RID_PROTECTED,
RID_TEMPLATE, RID_NULL, RID_CATCH,
RID_DELETE, RID_FALSE, RID_NAMESPACE,
- RID_NEW, RID_OFFSETOF, RID_OPERATOR,
+ RID_NEW, RID_OPERATOR,
RID_THIS, RID_THROW, RID_TRUE,
RID_TRY, RID_TYPENAME, RID_TYPEID,
RID_USING, RID_CHAR16, RID_CHAR32,
@@ -135,6 +135,12 @@
((unsigned int) (rid) >= (unsigned int) RID_FIRST_PQ && \
(unsigned int) (rid) <= (unsigned int) RID_LAST_PQ)
+#define C_COMMON_IS_CXX_KEYWORD(rid) \
+ (((unsigned int) (rid) >= (unsigned int) RID_FRIEND \
+ && (unsigned int) (rid) <= (unsigned int) RID_MUTABLE) \
+ || ((unsigned int) (rid) >= (unsigned int) RID_BOOL \
+ && (unsigned int) (rid) <= (unsigned int) RID_USING))
+
/* The elements of `ridpointers' are identifier nodes for the reserved
type names and storage classes. It is indexed by a RID_... value. */
extern GTY ((length ("(int) RID_MAX"))) tree *ridpointers;
@@ -197,6 +203,31 @@
struct cpp_hashnode node;
};
+/* Disable mask for keyword table. Keywords are disabled if
+ (c_common_reswords[i].disable & mask) is _true_. */
+#define D_EXT 0x01 /* GCC extension */
+#define D_ASM 0x02 /* in C99, but has a switch to turn it off */
+#define D_OBJC 0x04 /* Objective C++ only */
+#define D_CXX0X 0x08 /* C++0x only */
+#define D_C89 0x10 /* not in C89 */
+#define D_EXT89 0x20 /* GCC extension incorporated in C99 */
+#define D_CXX 0x40 /* C++ */
+#define D_CONLY 0x80 /* C only */
+
+/* An element of the reserved keyword table has this type. */
+struct c_common_resword
+{
+ const char *word;
+ ENUM_BITFIELD(rid) rid : 16;
+ unsigned int disable : 16;
+};
+
+/* The reserved keyword table. */
+extern const struct c_common_resword c_common_reswords[];
+
+/* The number of items in the reserved keyword table. */
+extern const unsigned int num_c_common_reswords;
+
#define char16_type_node c_global_trees[CTI_CHAR16_TYPE]
#define char32_type_node c_global_trees[CTI_CHAR32_TYPE]
#define wchar_type_node c_global_trees[CTI_WCHAR_TYPE]
Index: gcc/c-parser.c
===================================================================
--- gcc/c-parser.c (revision 137041)
+++ gcc/c-parser.c (working copy)
@@ -59,131 +59,6 @@
#include "cgraph.h"
-/* The reserved keyword table. */
-struct resword
-{
- const char *word;
- ENUM_BITFIELD(rid) rid : 16;
- unsigned int disable : 16;
-};
-
-/* Disable mask. Keywords are disabled if (reswords[i].disable &
- mask) is _true_. */
-#define D_C89 0x01 /* not in C89 */
-#define D_EXT 0x02 /* GCC extension */
-#define D_EXT89 0x04 /* GCC extension incorporated in C99 */
-#define D_OBJC 0x08 /* Objective C only */
-
-static const struct resword reswords[] =
-{
- { "_Bool", RID_BOOL, 0 },
- { "_Complex", RID_COMPLEX, 0 },
- { "_Decimal32", RID_DFLOAT32, D_EXT },
- { "_Decimal64", RID_DFLOAT64, D_EXT },
- { "_Decimal128", RID_DFLOAT128, D_EXT },
- { "_Fract", RID_FRACT, D_EXT },
- { "_Accum", RID_ACCUM, D_EXT },
- { "_Sat", RID_SAT, D_EXT },
- { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
- { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
- { "__alignof", RID_ALIGNOF, 0 },
- { "__alignof__", RID_ALIGNOF, 0 },
- { "__asm", RID_ASM, 0 },
- { "__asm__", RID_ASM, 0 },
- { "__attribute", RID_ATTRIBUTE, 0 },
- { "__attribute__", RID_ATTRIBUTE, 0 },
- { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
- { "__builtin_offsetof", RID_OFFSETOF, 0 },
- { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
- { "__builtin_va_arg", RID_VA_ARG, 0 },
- { "__complex", RID_COMPLEX, 0 },
- { "__complex__", RID_COMPLEX, 0 },
- { "__const", RID_CONST, 0 },
- { "__const__", RID_CONST, 0 },
- { "__extension__", RID_EXTENSION, 0 },
- { "__func__", RID_C99_FUNCTION_NAME, 0 },
- { "__imag", RID_IMAGPART, 0 },
- { "__imag__", RID_IMAGPART, 0 },
- { "__inline", RID_INLINE, 0 },
- { "__inline__", RID_INLINE, 0 },
- { "__label__", RID_LABEL, 0 },
- { "__real", RID_REALPART, 0 },
- { "__real__", RID_REALPART, 0 },
- { "__restrict", RID_RESTRICT, 0 },
- { "__restrict__", RID_RESTRICT, 0 },
- { "__signed", RID_SIGNED, 0 },
- { "__signed__", RID_SIGNED, 0 },
- { "__thread", RID_THREAD, 0 },
- { "__typeof", RID_TYPEOF, 0 },
- { "__typeof__", RID_TYPEOF, 0 },
- { "__volatile", RID_VOLATILE, 0 },
- { "__volatile__", RID_VOLATILE, 0 },
- { "asm", RID_ASM, D_EXT },
- { "auto", RID_AUTO, 0 },
- { "break", RID_BREAK, 0 },
- { "case", RID_CASE, 0 },
- { "char", RID_CHAR, 0 },
- { "const", RID_CONST, 0 },
- { "continue", RID_CONTINUE, 0 },
- { "default", RID_DEFAULT, 0 },
- { "do", RID_DO, 0 },
- { "double", RID_DOUBLE, 0 },
- { "else", RID_ELSE, 0 },
- { "enum", RID_ENUM, 0 },
- { "extern", RID_EXTERN, 0 },
- { "float", RID_FLOAT, 0 },
- { "for", RID_FOR, 0 },
- { "goto", RID_GOTO, 0 },
- { "if", RID_IF, 0 },
- { "inline", RID_INLINE, D_EXT89 },
- { "int", RID_INT, 0 },
- { "long", RID_LONG, 0 },
- { "register", RID_REGISTER, 0 },
- { "restrict", RID_RESTRICT, D_C89 },
- { "return", RID_RETURN, 0 },
- { "short", RID_SHORT, 0 },
- { "signed", RID_SIGNED, 0 },
- { "sizeof", RID_SIZEOF, 0 },
- { "static", RID_STATIC, 0 },
- { "struct", RID_STRUCT, 0 },
- { "switch", RID_SWITCH, 0 },
- { "typedef", RID_TYPEDEF, 0 },
- { "typeof", RID_TYPEOF, D_EXT },
- { "union", RID_UNION, 0 },
- { "unsigned", RID_UNSIGNED, 0 },
- { "void", RID_VOID, 0 },
- { "volatile", RID_VOLATILE, 0 },
- { "while", RID_WHILE, 0 },
- /* These Objective-C keywords are recognized only immediately after
- an '@'. */
- { "class", RID_AT_CLASS, D_OBJC },
- { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
- { "defs", RID_AT_DEFS, D_OBJC },
- { "encode", RID_AT_ENCODE, D_OBJC },
- { "end", RID_AT_END, D_OBJC },
- { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
- { "interface", RID_AT_INTERFACE, D_OBJC },
- { "private", RID_AT_PRIVATE, D_OBJC },
- { "protected", RID_AT_PROTECTED, D_OBJC },
- { "protocol", RID_AT_PROTOCOL, D_OBJC },
- { "public", RID_AT_PUBLIC, D_OBJC },
- { "selector", RID_AT_SELECTOR, D_OBJC },
- { "throw", RID_AT_THROW, D_OBJC },
- { "try", RID_AT_TRY, D_OBJC },
- { "catch", RID_AT_CATCH, D_OBJC },
- { "finally", RID_AT_FINALLY, D_OBJC },
- { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
- /* These are recognized only in protocol-qualifier context
- (see above) */
- { "bycopy", RID_BYCOPY, D_OBJC },
- { "byref", RID_BYREF, D_OBJC },
- { "in", RID_IN, D_OBJC },
- { "inout", RID_INOUT, D_OBJC },
- { "oneway", RID_ONEWAY, D_OBJC },
- { "out", RID_OUT, D_OBJC },
-};
-#define N_reswords (sizeof reswords / sizeof (struct resword))
-
/* Initialization routine for this file. */
void
@@ -193,24 +68,26 @@
identifiers. */
unsigned int i;
tree id;
- int mask = (flag_isoc99 ? 0 : D_C89)
- | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
+ int mask = ((flag_isoc99 ? 0 : D_C89)
+ | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0)
+ | (warn_cxx_compat ? 0 : D_CXX)
+ | (warn_cxx0x_compat ? 0 : D_CXX0X));
if (!c_dialect_objc ())
mask |= D_OBJC;
ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
- for (i = 0; i < N_reswords; i++)
+ for (i = 0; i < num_c_common_reswords; i++)
{
/* If a keyword is disabled, do not enter it into the table
and so create a canonical spelling that isn't a keyword. */
- if (reswords[i].disable & mask)
+ if (c_common_reswords[i].disable & mask)
continue;
- id = get_identifier (reswords[i].word);
- C_SET_RID_CODE (id, reswords[i].rid);
+ id = get_identifier (c_common_reswords[i].word);
+ C_SET_RID_CODE (id, c_common_reswords[i].rid);
C_IS_RESERVED_WORD (id) = 1;
- ridpointers [(int) reswords[i].rid] = id;
+ ridpointers [(int) c_common_reswords[i].rid] = id;
}
}
@@ -343,6 +220,13 @@
break;
}
}
+ else if (C_COMMON_IS_CXX_KEYWORD (rid_code))
+ {
+ warning (0,
+ "%Hidentifier named %qs conflicts with C++ keyword",
+ &token->location,
+ IDENTIFIER_POINTER (token->value));
+ }
else
{
/* Return the canonical spelling for this keyword. */
More information about the Gcc-patches
mailing list