[cfe-commits] r39897 - in /cfe/trunk: Driver/clang.cpp Lex/IdentifierTable.cpp include/clang/Basic/LangOptions.h include/clang/Basic/TokenKinds.def test/Lexer/cxx0x_keyword.cpp test/Lexer/cxx0x_keyword_as_cxx98.cpp
Chris Lattner
sabre at nondot.org
Sun Jul 15 21:18:30 PDT 2007
Author: lattner
Date: Sun Jul 15 23:18:29 2007
New Revision: 39897
URL: http://llvm.org/viewvc/llvm-project?rev=39897&view=rev
Log:
Add support for C++'0x keywords, patch by Doug Gregor
Added:
cfe/trunk/test/Lexer/cxx0x_keyword.cpp
cfe/trunk/test/Lexer/cxx0x_keyword_as_cxx98.cpp
Modified:
cfe/trunk/Driver/clang.cpp
cfe/trunk/Lex/IdentifierTable.cpp
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Basic/TokenKinds.def
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=39897&r1=39896&r2=39897&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Sun Jul 15 23:18:29 2007
@@ -207,7 +207,8 @@
lang_unspecified,
lang_c89, lang_c94, lang_c99,
lang_gnu89, lang_gnu99,
- lang_cxx98, lang_gnucxx98
+ lang_cxx98, lang_gnucxx98,
+ lang_cxx0x, lang_gnucxx0x
};
static llvm::cl::opt<LangStds>
@@ -233,6 +234,11 @@
clEnumValN(lang_gnucxx98, "gnu++98",
"ISO C++ 1998 with amendments and GNU "
"extensions (default for C++)"),
+ clEnumValN(lang_cxx0x, "c++0x",
+ "Upcoming ISO C++ 200x with amendments"),
+ clEnumValN(lang_gnucxx0x, "gnu++0x",
+ "Upcoming ISO C++ 200x with amendments and GNU "
+ "extensions (default for C++)"),
clEnumValEnd));
static llvm::cl::opt<bool>
@@ -269,6 +275,10 @@
// Fall through from newer standards to older ones. This isn't really right.
// FIXME: Enable specifically the right features based on the language stds.
+ case lang_gnucxx0x:
+ case lang_cxx0x:
+ Options.CPlusPlus0x = 1;
+ // FALL THROUGH
case lang_gnucxx98:
case lang_cxx98:
Options.CPlusPlus = 1;
Modified: cfe/trunk/Lex/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/IdentifierTable.cpp?rev=39897&r1=39896&r2=39897&view=diff
==============================================================================
--- cfe/trunk/Lex/IdentifierTable.cpp (original)
+++ cfe/trunk/Lex/IdentifierTable.cpp Sun Jul 15 23:18:29 2007
@@ -59,14 +59,16 @@
/// identifiers because they are language keywords. This causes the lexer to
/// automatically map matching identifiers to specialized token codes.
///
-/// The C90/C99/CPP flags are set to 0 if the token should be enabled in the
-/// specified langauge, set to 1 if it is an extension in the specified
-/// language, and set to 2 if disabled in the specified language.
+/// The C90/C99/CPP/CPP0x flags are set to 0 if the token should be
+/// enabled in the specified langauge, set to 1 if it is an extension
+/// in the specified language, and set to 2 if disabled in the
+/// specified language.
static void AddKeyword(const char *Keyword, unsigned KWLen,
tok::TokenKind TokenCode,
- int C90, int C99, int CXX,
+ int C90, int C99, int CXX, int CXX0x,
const LangOptions &LangOpts, IdentifierTable &Table) {
- int Flags = LangOpts.CPlusPlus ? CXX : (LangOpts.C99 ? C99 : C90);
+ int Flags = LangOpts.CPlusPlus ? (LangOpts.CPlusPlus0x? CXX0x : CXX)
+ : (LangOpts.C99 ? C99 : C90);
// Don't add this keyword if disabled in this language or if an extension
// and extensions are disabled.
@@ -126,6 +128,9 @@
CPPShift = 4,
EXTCPP = 1 << CPPShift,
NOTCPP = 2 << CPPShift,
+ CPP0xShift = 6,
+ EXTCPP0x = 1 << CPP0xShift,
+ NOTCPP0x = 2 << CPP0xShift,
Mask = 3
};
@@ -134,7 +139,8 @@
AddKeyword(#NAME, strlen(#NAME), tok::kw_ ## NAME, \
((FLAGS) >> C90Shift) & Mask, \
((FLAGS) >> C99Shift) & Mask, \
- ((FLAGS) >> CPPShift) & Mask, LangOpts, *this);
+ ((FLAGS) >> CPPShift) & Mask, \
+ ((FLAGS) >> CPP0xShift) & Mask, LangOpts, *this);
#define ALIAS(NAME, TOK) \
AddAlias(NAME, strlen(NAME), #TOK, strlen(#TOK), LangOpts, *this);
#define PPKEYWORD(NAME) \
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=39897&r1=39896&r2=39897&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Sun Jul 15 23:18:29 2007
@@ -27,6 +27,7 @@
unsigned C99 : 1; // C99 Support
unsigned Microsoft : 1; // Microsoft extensions.
unsigned CPlusPlus : 1; // C++ Support
+ unsigned CPlusPlus0x : 1; // C++0x Support
unsigned NoExtensions : 1; // All extensions are disabled, strict mode.
unsigned CXXOperatorNames : 1; // Treat C++ operator names as keywords.
@@ -35,7 +36,8 @@
LangOptions() {
Trigraphs = BCPLComment = DollarIdents = Digraphs = ObjC1 = ObjC2 = 0;
- C99 = Microsoft = CPlusPlus = NoExtensions = CXXOperatorNames = 0;
+ C99 = Microsoft = CPlusPlus = CPlusPlus0x = NoExtensions = 0;
+ CXXOperatorNames = 0;
}
};
Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=39897&r1=39896&r2=39897&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Sun Jul 15 23:18:29 2007
@@ -180,8 +180,11 @@
// EXTC90 - In C90, this token is an extension that is enabled unless strict.
// NOTC99 - In C99, this token is never available.
// EXTC99 - In C99, this token is an extension that is enabled unless strict.
-// NOTCPP - In C++, this token is never available.
-// EXTCPP - In C++, this token is an extension that is enabled unless strict.
+// NOTCPP - In C++98, this token is never available.
+// EXTCPP - In C++98, this token is an extension that is enabled unless strict.
+// NOTCPP0x - In C++0x, this token is never available.
+// EXTCPP0x - In C++0x, this token is an extension that is enabled unless
+// strict.
//
KEYWORD(auto , 0)
KEYWORD(break , 0)
@@ -217,14 +220,14 @@
KEYWORD(void , 0)
KEYWORD(volatile , 0)
KEYWORD(while , 0)
-KEYWORD(_Bool , EXTC90|EXTCPP) // C99 only
+KEYWORD(_Bool , EXTC90|EXTCPP|EXTCPP0x) // C99 only
KEYWORD(_Complex , EXTC90) // C99/C++
-KEYWORD(_Imaginary , EXTC90|NOTCPP) // C90 only
+KEYWORD(_Imaginary , EXTC90|NOTCPP|NOTCPP0x) // C90 only
// Special tokens to the compiler.
-KEYWORD(__func__ , EXTC90|EXTCPP) // Only in C99.
-KEYWORD(__FUNCTION__ , EXTC90|EXTC99|EXTCPP) // GCC Extension.
-KEYWORD(__PRETTY_FUNCTION__ , EXTC90|EXTC99|EXTCPP) // GCC Extension.
+KEYWORD(__func__ , EXTC90|EXTCPP|EXTCPP0x) // Only in C99.
+KEYWORD(__FUNCTION__ , EXTC90|EXTC99|EXTCPP|EXTCPP0x) // GCC Extension.
+KEYWORD(__PRETTY_FUNCTION__ , EXTC90|EXTC99|EXTCPP|EXTCPP0x) // GCC Extension.
// C++ 2.11p1: Keywords.
KEYWORD(asm , EXTC90|EXTC99) // Exts in C90/C99
@@ -271,23 +274,28 @@
CXX_KEYWORD_OPERATOR(xor , caret)
CXX_KEYWORD_OPERATOR(xor_eq , caretequal)
+// C++0x keywords
+KEYWORD(char16_t , NOTC90|NOTC99|NOTCPP)
+KEYWORD(char32_t , NOTC90|NOTC99|NOTCPP)
+KEYWORD(static_assert , NOTC90|NOTC99|NOTCPP)
+
// GNU Extensions.
-KEYWORD(_Decimal32 , EXTC90|EXTC99|EXTCPP)
-KEYWORD(_Decimal64 , EXTC90|EXTC99|EXTCPP)
-KEYWORD(_Decimal128 , EXTC90|EXTC99|EXTCPP)
-KEYWORD(typeof , EXTC90|EXTC99|EXTCPP)
-KEYWORD(__null , NOTC90|NOTC99|EXTCPP) // C++-only Extensn
-KEYWORD(__alignof , EXTC90|EXTC99|EXTCPP)
-KEYWORD(__attribute , EXTC90|EXTC99|EXTCPP)
-KEYWORD(__builtin_choose_expr , EXTC90|EXTC99|EXTCPP)
-KEYWORD(__builtin_offsetof , EXTC90|EXTC99|EXTCPP)
-KEYWORD(__builtin_types_compatible_p, EXTC90|EXTC99|EXTCPP)
-KEYWORD(__builtin_va_arg , EXTC90|EXTC99|EXTCPP)
+KEYWORD(_Decimal32 , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(_Decimal64 , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(_Decimal128 , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(typeof , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__null , NOTC90|NOTC99|EXTCPP|EXTCPP0x) // C++-only Extensn
+KEYWORD(__alignof , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__attribute , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__builtin_choose_expr , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__builtin_offsetof , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__builtin_types_compatible_p, EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__builtin_va_arg , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
KEYWORD(__extension__ , 0) // Not treated as an extension!
-KEYWORD(__imag , EXTC90|EXTC99|EXTCPP)
-KEYWORD(__label__ , EXTC90|EXTC99|EXTCPP)
-KEYWORD(__real , EXTC90|EXTC99|EXTCPP)
-KEYWORD(__thread , EXTC90|EXTC99|EXTCPP)
+KEYWORD(__imag , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__label__ , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__real , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__thread , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
// Alternate spelling for various tokens. There are GCC extensions in all
// languages, but should not be disabled in strict conformance mode.
Added: cfe/trunk/test/Lexer/cxx0x_keyword.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx0x_keyword.cpp?rev=39897&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/cxx0x_keyword.cpp (added)
+++ cfe/trunk/test/Lexer/cxx0x_keyword.cpp Sun Jul 15 23:18:29 2007
@@ -0,0 +1,2 @@
+// RUN: clang -parse-ast-check -std=c++0x %s 2>&1
+int static_assert; /* expected-error {{expected identifier or '('}}} */
Added: cfe/trunk/test/Lexer/cxx0x_keyword_as_cxx98.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx0x_keyword_as_cxx98.cpp?rev=39897&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/cxx0x_keyword_as_cxx98.cpp (added)
+++ cfe/trunk/test/Lexer/cxx0x_keyword_as_cxx98.cpp Sun Jul 15 23:18:29 2007
@@ -0,0 +1,2 @@
+// RUN: clang %s -fsyntax-only
+int static_assert;
More information about the cfe-commits
mailing list