OSDN Git Service

Move UTF functions into namespace llvm.
authorJustin Lebar <jlebar@google.com>
Fri, 30 Sep 2016 00:38:45 +0000 (00:38 +0000)
committerJustin Lebar <jlebar@google.com>
Fri, 30 Sep 2016 00:38:45 +0000 (00:38 +0000)
Summary:
This lets people link against LLVM and their own version of the UTF
library.

I determined this only affects llvm, clang, lld, and lldb by running

$ git grep -wl 'UTF[0-9]\+\|\bConvertUTF\bisLegalUTF\|getNumBytesFor' | cut -f 1 -d '/' | sort | uniq
  clang
  lld
  lldb
  llvm

Tested with

  ninja lldb
  ninja check-clang check-llvm check-lld

(ninja check-lldb doesn't complete for me with or without this patch.)

Reviewers: rnk

Subscribers: klimek, beanz, mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D24996

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282822 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/ConvertUTF.h
lib/Support/CMakeLists.txt
lib/Support/ConvertUTF.cpp [moved from lib/Support/ConvertUTF.c with 99% similarity]

index 5de5774..f714c0e 100644 (file)
 #ifndef LLVM_SUPPORT_CONVERTUTF_H
 #define LLVM_SUPPORT_CONVERTUTF_H
 
+#include <string>
+#include <cstddef>
+
+// Wrap everything in namespace llvm so that programs can link with llvm and
+// their own version of the unicode libraries.
+
+namespace llvm {
+
 /* ---------------------------------------------------------------------
     The following 4 definitions are compiler-specific.
     The C standard does not guarantee that wchar_t has at least
@@ -127,11 +135,6 @@ typedef enum {
   lenientConversion
 } ConversionFlags;
 
-/* This is for C++ and does no harm in C */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 ConversionResult ConvertUTF8toUTF16 (
   const UTF8** sourceStart, const UTF8* sourceEnd,
   UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
@@ -174,16 +177,9 @@ Boolean isLegalUTF8String(const UTF8 **source, const UTF8 *sourceEnd);
 
 unsigned getNumBytesForUTF8(UTF8 firstByte);
 
-#ifdef __cplusplus
-}
-
 /*************************************************************************/
 /* Below are LLVM-specific wrappers of the functions above. */
 
-#include <string>
-#include <cstddef>
-
-namespace llvm {
 template <typename T> class ArrayRef;
 template <typename T> class SmallVectorImpl;
 class StringRef;
@@ -293,7 +289,3 @@ bool convertUTF8ToUTF16String(StringRef SrcUTF8,
 } /* end namespace llvm */
 
 #endif
-
-/* --------------------------------------------------------------------- */
-
-#endif
index b188b4c..9f75545 100644 (file)
@@ -40,7 +40,7 @@ add_llvm_library(LLVMSupport
   COM.cpp
   CommandLine.cpp
   Compression.cpp
-  ConvertUTF.c
+  ConvertUTF.cpp
   ConvertUTFWrapper.cpp
   CrashRecoveryContext.cpp
   DataExtractor.cpp
similarity index 99%
rename from lib/Support/ConvertUTF.c
rename to lib/Support/ConvertUTF.cpp
index 128459a..39fd218 100644 (file)
@@ -53,6 +53,8 @@
 #endif
 #include <assert.h>
 
+namespace llvm {
+
 static const int halfShift  = 10; /* used for shifting by 10 bits */
 
 static const UTF32 halfBase = 0x0010000UL;
@@ -62,8 +64,6 @@ static const UTF32 halfMask = 0x3FFUL;
 #define UNI_SUR_HIGH_END    (UTF32)0xDBFF
 #define UNI_SUR_LOW_START   (UTF32)0xDC00
 #define UNI_SUR_LOW_END     (UTF32)0xDFFF
-#define false      0
-#define true        1
 
 /* --------------------------------------------------------------------- */
 
@@ -706,3 +706,5 @@ ConversionResult ConvertUTF8toUTF32(const UTF8 **sourceStart,
     similarly unrolled loops.
 
    --------------------------------------------------------------------- */
+
+} // namespace llvm