[PATCH] Use new UnicodeCharSet interface.

Alexander Kornienko alexfh at google.com
Tue Aug 27 10:33:38 PDT 2013


Hi jordan_rose, klimek,

This is a Clang part of http://llvm-reviews.chandlerc.com/D1534

http://llvm-reviews.chandlerc.com/D1535

Files:
  lib/Lex/Lexer.cpp
  lib/Lex/UnicodeCharSets.h

Index: lib/Lex/Lexer.cpp
===================================================================
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1366,21 +1366,21 @@
 
 static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts) {
   if (LangOpts.CPlusPlus11 || LangOpts.C11)
-    return isCharInSet(C, C11AllowedIDChars);
+    return C11AllowedIDChars.contains(C);
   else if (LangOpts.CPlusPlus)
-    return isCharInSet(C, CXX03AllowedIDChars);
+    return CXX03AllowedIDChars.contains(C);
   else
-    return isCharInSet(C, C99AllowedIDChars);
+    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);
+    return !C11DisallowedInitialIDChars.contains(C);
   else if (LangOpts.CPlusPlus)
     return true;
   else
-    return !isCharInSet(C, C99DisallowedInitialIDChars);
+    return !C99DisallowedInitialIDChars.contains(C);
 }
 
 static inline CharSourceRange makeCharRange(Lexer &L, const char *Begin,
@@ -1399,11 +1399,11 @@
       CannotStartIdentifier
     };
 
-    if (!isCharInSet(C, C99AllowedIDChars)) {
+    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 +1413,7 @@
   // Check C++98 compatibility.
   if (Diags.getDiagnosticLevel(diag::warn_cxx98_compat_unicode_id,
                                Range.getBegin()) > DiagnosticsEngine::Ignored) {
-    if (!isCharInSet(C, CXX03AllowedIDChars)) {
+    if (!CXX03AllowedIDChars.contains(C)) {
       Diags.Report(Range.getBegin(), diag::warn_cxx98_compat_unicode_id)
         << Range;
     }
@@ -2696,7 +2696,7 @@
 
 void Lexer::LexUnicode(Token &Result, uint32_t C, const char *CurPtr) {
   if (!isLexingRawMode() && !PP->isPreprocessedOutput() &&
-      isCharInSet(C, UnicodeWhitespaceChars)) {
+      UnicodeWhitespaceChars.contains(C)) {
     Diag(BufferPtr, diag::ext_unicode_whitespace)
       << makeCharRange(*this, BufferPtr, CurPtr);
 
Index: lib/Lex/UnicodeCharSets.h
===================================================================
--- lib/Lex/UnicodeCharSets.h
+++ lib/Lex/UnicodeCharSets.h
@@ -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 },
@@ -40,11 +40,13 @@
   { 0xA0000, 0xAFFFD }, { 0xB0000, 0xBFFFD }, { 0xC0000, 0xCFFFD },
   { 0xD0000, 0xDFFFD }, { 0xE0000, 0xEFFFD }
 };
+static const llvm::sys::UnicodeCharSet
+C11AllowedIDChars(C11AllowedIDCharRanges);
 
 // 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 },
@@ -161,9 +163,11 @@
   { 0xFFC2, 0xFFC7 }, { 0xFFCA, 0xFFCF }, { 0xFFD2, 0xFFD7 },
   { 0xFFDA, 0xFFDC }
 };
+static const llvm::sys::UnicodeCharSet
+CXX03AllowedIDChars(CXX03AllowedIDCharRanges);
 
 // C99 Annex D
-static const UnicodeCharRange C99AllowedIDChars[] = {
+static const llvm::sys::UnicodeCharRange C99AllowedIDCharRanges[] = {
   // Latin (1)
   { 0x00AA, 0x00AA },
 
@@ -380,29 +384,37 @@
   // Hangul,
   { 0xAC00, 0xD7A3 }
 };
+static const llvm::sys::UnicodeCharSet
+C99AllowedIDChars(C99AllowedIDCharRanges);
 
 // 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 }
 };
+static const llvm::sys::UnicodeCharSet
+C11DisallowedInitialIDChars(C11DisallowedInitialIDCharRanges);
 
 // 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 },
   { 0x0CE6, 0x0CEF }, { 0x0D66, 0x0D6F }, { 0x0E50, 0x0E59 },
   { 0x0ED0, 0x0ED9 }, { 0x0F20, 0x0F33 }
 };
+static const llvm::sys::UnicodeCharSet
+C99DisallowedInitialIDChars(C99DisallowedInitialIDCharRanges);
 
 // 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 }
 };
+static const llvm::sys::UnicodeCharSet
+UnicodeWhitespaceChars(UnicodeWhitespaceCharRanges);
 
 #endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1535.1.patch
Type: text/x-patch
Size: 5665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130827/ba7b1e1f/attachment.bin>


More information about the cfe-commits mailing list