[PATCH] Use isCharInSet from llvm/Support/UnicodeCharRanges.h, added a test for double-width characters in FixIt-hints.

Alexander Kornienko alexfh at google.com
Tue Aug 6 17:20:18 PDT 2013


Hi gribozavr, jordan_rose,

This is a follow-up to r187837.

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

Files:
  lib/Lex/UnicodeCharSets.h
  test/FixIt/fixit-unicode.c

Index: lib/Lex/UnicodeCharSets.h
===================================================================
--- lib/Lex/UnicodeCharSets.h
+++ lib/Lex/UnicodeCharSets.h
@@ -9,95 +9,7 @@
 #ifndef CLANG_LEX_UNICODECHARSETS_H
 #define CLANG_LEX_UNICODECHARSETS_H
 
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/Mutex.h"
-#include "llvm/Support/MutexGuard.h"
-#include "llvm/Support/raw_ostream.h"
-
-namespace {
-  struct UnicodeCharRange {
-    uint32_t Lower;
-    uint32_t Upper;
-  };
-  typedef llvm::ArrayRef<UnicodeCharRange> UnicodeCharSet;
-
-  typedef llvm::SmallPtrSet<const UnicodeCharRange *, 16> ValidatedCharSetsTy;
-}
-
-static inline ValidatedCharSetsTy &getValidatedCharSets() {
-  static ValidatedCharSetsTy Validated;
-  return Validated;
-}
-
-/// Returns true if each of the ranges in \p CharSet is a proper closed range
-/// [min, max], and if the ranges themselves are ordered and non-overlapping.
-static inline bool isValidCharSet(UnicodeCharSet CharSet) {
-#ifndef NDEBUG
-  static llvm::sys::Mutex ValidationMutex;
-
-  // Check the validation cache.
-  {
-    llvm::MutexGuard Guard(ValidationMutex);
-    if (getValidatedCharSets().count(CharSet.data()))
-      return true;
-  }
-
-  // Walk through the ranges.
-  uint32_t Prev = 0;
-  for (UnicodeCharSet::iterator I = CharSet.begin(), E = CharSet.end();
-       I != E; ++I) {
-    if (Prev >= I->Lower) {
-      DEBUG(llvm::dbgs() << "Upper bound 0x");
-      DEBUG(llvm::dbgs().write_hex(Prev));
-      DEBUG(llvm::dbgs() << " should be less than succeeding lower bound 0x");
-      DEBUG(llvm::dbgs().write_hex(I->Lower) << "\n");
-      return false;
-    }
-    if (I->Upper < I->Lower) {
-      DEBUG(llvm::dbgs() << "Upper bound 0x");
-      DEBUG(llvm::dbgs().write_hex(I->Lower));
-      DEBUG(llvm::dbgs() << " should not be less than lower bound 0x");
-      DEBUG(llvm::dbgs().write_hex(I->Upper) << "\n");
-      return false;
-    }
-    Prev = I->Upper;
-  }
-
-  // Update the validation cache.
-  {
-    llvm::MutexGuard Guard(ValidationMutex);
-    getValidatedCharSets().insert(CharSet.data());
-  }
-#endif
-  return true;
-}
-
-/// Returns true if the Unicode code point \p C is within the set of
-/// characters specified by \p CharSet.
-LLVM_READONLY static inline bool isCharInSet(uint32_t C,
-                                             UnicodeCharSet CharSet) {
-  assert(isValidCharSet(CharSet));
-
-  size_t LowPoint = 0;
-  size_t HighPoint = CharSet.size();
-
-  // Binary search the set of char ranges.
-  while (HighPoint != LowPoint) {
-    size_t MidPoint = (HighPoint + LowPoint) / 2;
-    if (C < CharSet[MidPoint].Lower)
-      HighPoint = MidPoint;
-    else if (C > CharSet[MidPoint].Upper)
-      LowPoint = MidPoint + 1;
-    else
-      return true;
-  }
-
-  return false;
-}
-
+#include "llvm/Support/UnicodeCharRanges.h"
 
 // C11 D.1, C++11 [charname.allowed]
 static const UnicodeCharRange C11AllowedIDChars[] = {
Index: test/FixIt/fixit-unicode.c
===================================================================
--- test/FixIt/fixit-unicode.c
+++ test/FixIt/fixit-unicode.c
@@ -48,6 +48,12 @@
 // CHECK: {{^          ss.+ss}}
 // CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:17}:"ss\340\270\201ss"
 
+  int s一二三 = 42;
+  int b一二三四五六七 = ss一二三; // expected-error{{use of undeclared identifier 'ss一二三'; did you mean 's一二三'?}}
+// CHECK: {{^                        \^~~~~~~~}}
+// CHECK: {{^                        s.+}}
+// CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-3]]:32-[[@LINE-3]]:43}:"s\344\270\200\344\272\214\344\270\211"
+
   int sssssssssก = 42;
   int c = sssssssss; // expected-error{{use of undeclared identifier 'sssssssss'; did you mean 'sssssssssก'?}}
 // CHECK: {{^          \^}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1306.1.patch
Type: text/x-patch
Size: 3886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130806/782066dc/attachment.bin>


More information about the cfe-commits mailing list