forked from OSchip/llvm-project
Use new UnicodeCharSet interface.
Summary: This is a Clang part of http://llvm-reviews.chandlerc.com/D1534 Reviewers: jordan_rose, klimek, rsmith Reviewed By: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1535 llvm-svn: 189583
This commit is contained in:
parent
a330ef49aa
commit
37d6b18633
|
@ -1365,22 +1365,34 @@ void Lexer::SkipBytes(unsigned Bytes, bool StartOfLine) {
|
|||
}
|
||||
|
||||
static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts) {
|
||||
if (LangOpts.CPlusPlus11 || LangOpts.C11)
|
||||
return isCharInSet(C, C11AllowedIDChars);
|
||||
else if (LangOpts.CPlusPlus)
|
||||
return isCharInSet(C, CXX03AllowedIDChars);
|
||||
else
|
||||
return isCharInSet(C, C99AllowedIDChars);
|
||||
if (LangOpts.CPlusPlus11 || LangOpts.C11) {
|
||||
static const llvm::sys::UnicodeCharSet C11AllowedIDChars(
|
||||
C11AllowedIDCharRanges);
|
||||
return C11AllowedIDChars.contains(C);
|
||||
} else if (LangOpts.CPlusPlus) {
|
||||
static const llvm::sys::UnicodeCharSet CXX03AllowedIDChars(
|
||||
CXX03AllowedIDCharRanges);
|
||||
return CXX03AllowedIDChars.contains(C);
|
||||
} else {
|
||||
static const llvm::sys::UnicodeCharSet C99AllowedIDChars(
|
||||
C99AllowedIDCharRanges);
|
||||
return C99AllowedIDChars.contains(C);
|
||||
}
|
||||
}
|
||||
|
||||
static bool isAllowedInitiallyIDChar(uint32_t C, const LangOptions &LangOpts) {
|
||||
assert(isAllowedIDChar(C, LangOpts));
|
||||
if (LangOpts.CPlusPlus11 || LangOpts.C11)
|
||||
return !isCharInSet(C, C11DisallowedInitialIDChars);
|
||||
else if (LangOpts.CPlusPlus)
|
||||
if (LangOpts.CPlusPlus11 || LangOpts.C11) {
|
||||
static const llvm::sys::UnicodeCharSet C11DisallowedInitialIDChars(
|
||||
C11DisallowedInitialIDCharRanges);
|
||||
return !C11DisallowedInitialIDChars.contains(C);
|
||||
} else if (LangOpts.CPlusPlus) {
|
||||
return true;
|
||||
else
|
||||
return !isCharInSet(C, C99DisallowedInitialIDChars);
|
||||
} else {
|
||||
static const llvm::sys::UnicodeCharSet C99DisallowedInitialIDChars(
|
||||
C99DisallowedInitialIDCharRanges);
|
||||
return !C99DisallowedInitialIDChars.contains(C);
|
||||
}
|
||||
}
|
||||
|
||||
static inline CharSourceRange makeCharRange(Lexer &L, const char *Begin,
|
||||
|
@ -1399,11 +1411,15 @@ static void maybeDiagnoseIDCharCompat(DiagnosticsEngine &Diags, uint32_t C,
|
|||
CannotStartIdentifier
|
||||
};
|
||||
|
||||
if (!isCharInSet(C, C99AllowedIDChars)) {
|
||||
static const llvm::sys::UnicodeCharSet C99AllowedIDChars(
|
||||
C99AllowedIDCharRanges);
|
||||
static const llvm::sys::UnicodeCharSet C99DisallowedInitialIDChars(
|
||||
C99DisallowedInitialIDCharRanges);
|
||||
if (!C99AllowedIDChars.contains(C)) {
|
||||
Diags.Report(Range.getBegin(), diag::warn_c99_compat_unicode_id)
|
||||
<< Range
|
||||
<< CannotAppearInIdentifier;
|
||||
} else if (IsFirst && isCharInSet(C, C99DisallowedInitialIDChars)) {
|
||||
} else if (IsFirst && C99DisallowedInitialIDChars.contains(C)) {
|
||||
Diags.Report(Range.getBegin(), diag::warn_c99_compat_unicode_id)
|
||||
<< Range
|
||||
<< CannotStartIdentifier;
|
||||
|
@ -1413,7 +1429,9 @@ static void maybeDiagnoseIDCharCompat(DiagnosticsEngine &Diags, uint32_t C,
|
|||
// Check C++98 compatibility.
|
||||
if (Diags.getDiagnosticLevel(diag::warn_cxx98_compat_unicode_id,
|
||||
Range.getBegin()) > DiagnosticsEngine::Ignored) {
|
||||
if (!isCharInSet(C, CXX03AllowedIDChars)) {
|
||||
static const llvm::sys::UnicodeCharSet CXX03AllowedIDChars(
|
||||
CXX03AllowedIDCharRanges);
|
||||
if (!CXX03AllowedIDChars.contains(C)) {
|
||||
Diags.Report(Range.getBegin(), diag::warn_cxx98_compat_unicode_id)
|
||||
<< Range;
|
||||
}
|
||||
|
@ -2695,8 +2713,10 @@ uint32_t Lexer::tryReadUCN(const char *&StartPtr, const char *SlashLoc,
|
|||
}
|
||||
|
||||
void Lexer::LexUnicode(Token &Result, uint32_t C, const char *CurPtr) {
|
||||
static const llvm::sys::UnicodeCharSet UnicodeWhitespaceChars(
|
||||
UnicodeWhitespaceCharRanges);
|
||||
if (!isLexingRawMode() && !PP->isPreprocessedOutput() &&
|
||||
isCharInSet(C, UnicodeWhitespaceChars)) {
|
||||
UnicodeWhitespaceChars.contains(C)) {
|
||||
Diag(BufferPtr, diag::ext_unicode_whitespace)
|
||||
<< makeCharRange(*this, BufferPtr, CurPtr);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "llvm/Support/UnicodeCharRanges.h"
|
||||
|
||||
// C11 D.1, C++11 [charname.allowed]
|
||||
static const UnicodeCharRange C11AllowedIDChars[] = {
|
||||
static const llvm::sys::UnicodeCharRange C11AllowedIDCharRanges[] = {
|
||||
// 1
|
||||
{ 0x00A8, 0x00A8 }, { 0x00AA, 0x00AA }, { 0x00AD, 0x00AD },
|
||||
{ 0x00AF, 0x00AF }, { 0x00B2, 0x00B5 }, { 0x00B7, 0x00BA },
|
||||
|
@ -44,7 +44,7 @@ static const UnicodeCharRange C11AllowedIDChars[] = {
|
|||
// C++03 [extendid]
|
||||
// Note that this is not the same as C++98, but we don't distinguish C++98
|
||||
// and C++03 in Clang.
|
||||
static const UnicodeCharRange CXX03AllowedIDChars[] = {
|
||||
static const llvm::sys::UnicodeCharRange CXX03AllowedIDCharRanges[] = {
|
||||
// Latin
|
||||
{ 0x00C0, 0x00D6 }, { 0x00D8, 0x00F6 }, { 0x00F8, 0x01F5 },
|
||||
{ 0x01FA, 0x0217 }, { 0x0250, 0x02A8 },
|
||||
|
@ -163,7 +163,7 @@ static const UnicodeCharRange CXX03AllowedIDChars[] = {
|
|||
};
|
||||
|
||||
// C99 Annex D
|
||||
static const UnicodeCharRange C99AllowedIDChars[] = {
|
||||
static const llvm::sys::UnicodeCharRange C99AllowedIDCharRanges[] = {
|
||||
// Latin (1)
|
||||
{ 0x00AA, 0x00AA },
|
||||
|
||||
|
@ -382,7 +382,7 @@ static const UnicodeCharRange C99AllowedIDChars[] = {
|
|||
};
|
||||
|
||||
// C11 D.2, C++11 [charname.disallowed]
|
||||
static const UnicodeCharRange C11DisallowedInitialIDChars[] = {
|
||||
static const llvm::sys::UnicodeCharRange C11DisallowedInitialIDCharRanges[] = {
|
||||
{ 0x0300, 0x036F }, { 0x1DC0, 0x1DFF }, { 0x20D0, 0x20FF },
|
||||
{ 0xFE20, 0xFE2F }
|
||||
};
|
||||
|
@ -390,7 +390,7 @@ static const UnicodeCharRange C11DisallowedInitialIDChars[] = {
|
|||
// C99 6.4.2.1p3: The initial character [of an identifier] shall not be a
|
||||
// universal character name designating a digit.
|
||||
// C99 Annex D defines these characters as "Digits".
|
||||
static const UnicodeCharRange C99DisallowedInitialIDChars[] = {
|
||||
static const llvm::sys::UnicodeCharRange C99DisallowedInitialIDCharRanges[] = {
|
||||
{ 0x0660, 0x0669 }, { 0x06F0, 0x06F9 }, { 0x0966, 0x096F },
|
||||
{ 0x09E6, 0x09EF }, { 0x0A66, 0x0A6F }, { 0x0AE6, 0x0AEF },
|
||||
{ 0x0B66, 0x0B6F }, { 0x0BE7, 0x0BEF }, { 0x0C66, 0x0C6F },
|
||||
|
@ -399,7 +399,7 @@ static const UnicodeCharRange C99DisallowedInitialIDChars[] = {
|
|||
};
|
||||
|
||||
// Unicode v6.2, chapter 6.2, table 6-2.
|
||||
static const UnicodeCharRange UnicodeWhitespaceChars[] = {
|
||||
static const llvm::sys::UnicodeCharRange UnicodeWhitespaceCharRanges[] = {
|
||||
{ 0x0085, 0x0085 }, { 0x00A0, 0x00A0 }, { 0x1680, 0x1680 },
|
||||
{ 0x180E, 0x180E }, { 0x2000, 0x200A }, { 0x2028, 0x2029 },
|
||||
{ 0x202F, 0x202F }, { 0x205F, 0x205F }, { 0x3000, 0x3000 }
|
||||
|
|
Loading…
Reference in New Issue