summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-06-11 10:28:04 +0000
committerPavel Labath <labath@google.com>2018-06-11 10:28:04 +0000
commitd8c6290ba46d2aafb0d9ff8f1ed361da588b44df (patch)
tree14111d8461876324f651939fc276c5ef9a2f23f8
parentb896c4e86005657cca6ba96960779b36016a9189 (diff)
downloadbcm5719-llvm-d8c6290ba46d2aafb0d9ff8f1ed361da588b44df.tar.gz
bcm5719-llvm-d8c6290ba46d2aafb0d9ff8f1ed361da588b44df.zip
Move VersionTuple from clang/Basic to llvm/Support
Summary: This kind of functionality is useful to other project apart from clang. LLDB works with version numbers a lot, but it does not have a convenient abstraction for this. Moving this class to a lower level library allows it to be freely used within LLDB. Since this class is used in a lot of places in clang, and it used to be in the clang namespace, it seemed appropriate to add it to the list of adopted classes in LLVM.h to avoid prefixing all uses with "llvm::". Also, I didn't find any tests specific for this class, so I wrote a couple of quick ones for the more interesting bits of functionality. Reviewers: zturner, erik.pilkington Subscribers: mgorny, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D47887 llvm-svn: 334399
-rw-r--r--clang/include/clang/AST/Attr.h2
-rw-r--r--clang/include/clang/AST/Availability.h2
-rw-r--r--clang/include/clang/AST/DeclBase.h2
-rw-r--r--clang/include/clang/AST/ExprObjC.h2
-rw-r--r--clang/include/clang/Basic/AlignedAllocation.h2
-rw-r--r--clang/include/clang/Basic/LLVM.h12
-rw-r--r--clang/include/clang/Basic/ObjCRuntime.h2
-rw-r--r--clang/include/clang/Basic/TargetInfo.h2
-rw-r--r--clang/include/clang/Driver/ToolChain.h2
-rw-r--r--clang/include/clang/Parse/Parser.h1
-rw-r--r--clang/include/clang/Sema/AttributeList.h2
-rw-r--r--clang/include/clang/Serialization/ASTReader.h2
-rw-r--r--clang/include/clang/Serialization/ASTWriter.h1
-rw-r--r--clang/lib/AST/DeclBase.cpp2
-rw-r--r--clang/lib/Basic/CMakeLists.txt1
-rw-r--r--clang/lib/Basic/ObjCRuntime.cpp2
-rw-r--r--clang/lib/Driver/ToolChain.cpp4
-rw-r--r--clang/lib/Driver/ToolChains/Cuda.h4
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp2
-rw-r--r--clang/lib/Serialization/ASTReader.cpp4
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp2
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp9
-rw-r--r--llvm/include/llvm/Support/VersionTuple.h (renamed from clang/include/clang/Basic/VersionTuple.h)25
-rw-r--r--llvm/lib/Support/CMakeLists.txt1
-rw-r--r--llvm/lib/Support/VersionTuple.cpp (renamed from clang/lib/Basic/VersionTuple.cpp)44
-rw-r--r--llvm/unittests/Support/CMakeLists.txt1
-rw-r--r--llvm/unittests/Support/VersionTupleTest.cpp50
27 files changed, 123 insertions, 62 deletions
diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 390e840b330..32a61c59d23 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -23,9 +23,9 @@
#include "clang/Basic/OpenMPKinds.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
diff --git a/clang/include/clang/AST/Availability.h b/clang/include/clang/AST/Availability.h
index e1f5671b8c5..28f3c3c01d2 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -15,8 +15,8 @@
#define LLVM_CLANG_AST_AVAILABILITY_H
#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VersionTuple.h"
namespace clang {
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index ae7cd4d10db..229e7cd839b 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -19,7 +19,6 @@
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerUnion.h"
@@ -28,6 +27,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/VersionTuple.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
diff --git a/clang/include/clang/AST/ExprObjC.h b/clang/include/clang/AST/ExprObjC.h
index 361aa48cb28..5dac0e037da 100644
--- a/clang/include/clang/AST/ExprObjC.h
+++ b/clang/include/clang/AST/ExprObjC.h
@@ -25,7 +25,6 @@
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
@@ -36,6 +35,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/TrailingObjects.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/type_traits.h"
#include <cassert>
#include <cstddef>
diff --git a/clang/include/clang/Basic/AlignedAllocation.h b/clang/include/clang/Basic/AlignedAllocation.h
index 853f8dad25e..a84d22dda81 100644
--- a/clang/include/clang/Basic/AlignedAllocation.h
+++ b/clang/include/clang/Basic/AlignedAllocation.h
@@ -16,9 +16,9 @@
#ifndef LLVM_CLANG_BASIC_ALIGNED_ALLOCATION_H
#define LLVM_CLANG_BASIC_ALIGNED_ALLOCATION_H
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/VersionTuple.h"
namespace clang {
diff --git a/clang/include/clang/Basic/LLVM.h b/clang/include/clang/Basic/LLVM.h
index 885fba6afb7..8a432db911d 100644
--- a/clang/include/clang/Basic/LLVM.h
+++ b/clang/include/clang/Basic/LLVM.h
@@ -28,6 +28,7 @@ namespace llvm {
// ADT's.
class StringRef;
class Twine;
+ class VersionTuple;
template<typename T> class ArrayRef;
template<typename T> class MutableArrayRef;
template<typename T> class OwningArrayRef;
@@ -60,17 +61,18 @@ namespace clang {
using llvm::cast_or_null;
// ADT's.
- using llvm::None;
- using llvm::Optional;
- using llvm::StringRef;
- using llvm::Twine;
using llvm::ArrayRef;
using llvm::MutableArrayRef;
+ using llvm::None;
+ using llvm::Optional;
using llvm::OwningArrayRef;
+ using llvm::SaveAndRestore;
using llvm::SmallString;
using llvm::SmallVector;
using llvm::SmallVectorImpl;
- using llvm::SaveAndRestore;
+ using llvm::StringRef;
+ using llvm::Twine;
+ using llvm::VersionTuple;
// Error handling.
using llvm::Expected;
diff --git a/clang/include/clang/Basic/ObjCRuntime.h b/clang/include/clang/Basic/ObjCRuntime.h
index bc51574cf34..d5f4f50fe36 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -16,10 +16,10 @@
#define LLVM_CLANG_BASIC_OBJCRUNTIME_H
#include "clang/Basic/LLVM.h"
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/VersionTuple.h"
#include <string>
namespace clang {
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 08e33f58f55..c5a187e6f80 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -20,7 +20,6 @@
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetCXXABI.h"
#include "clang/Basic/TargetOptions.h"
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/Optional.h"
@@ -30,6 +29,7 @@
#include "llvm/ADT/Triple.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/VersionTuple.h"
#include <cassert>
#include <string>
#include <vector>
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index f94a210bd9a..addf7aa6a9c 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -12,7 +12,6 @@
#include "clang/Basic/LLVM.h"
#include "clang/Basic/Sanitizers.h"
-#include "clang/Basic/VersionTuple.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Multilib.h"
#include "clang/Driver/Types.h"
@@ -22,6 +21,7 @@
#include "llvm/ADT/Triple.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Option/Option.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Target/TargetOptions.h"
#include <cassert>
#include <memory>
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 49d6182cd2d..6e911230b28 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -45,7 +45,6 @@ namespace clang {
class ColonProtectionRAIIObject;
class InMessageExpressionRAIIObject;
class PoisonSEHIdentifiersRAIIObject;
- class VersionTuple;
class OMPClause;
class ObjCTypeParamList;
class ObjCTypeParameter;
diff --git a/clang/include/clang/Sema/AttributeList.h b/clang/include/clang/Sema/AttributeList.h
index 03761501805..dd15b7a2f56 100644
--- a/clang/include/clang/Sema/AttributeList.h
+++ b/clang/include/clang/Sema/AttributeList.h
@@ -18,11 +18,11 @@
#include "clang/Basic/AttrSubjectMatchRules.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
-#include "clang/Basic/VersionTuple.h"
#include "clang/Sema/Ownership.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/VersionTuple.h"
#include <cassert>
#include <cstddef>
#include <cstring>
diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h
index d9e9174b748..7de511ad617 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -28,7 +28,6 @@
#include "clang/Basic/OpenCLOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Version.h"
-#include "clang/Basic/VersionTuple.h"
#include "clang/Lex/ExternalPreprocessorSource.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/PreprocessingRecord.h"
@@ -62,6 +61,7 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Timer.h"
+#include "llvm/Support/VersionTuple.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h
index 9d4a3f9cf58..28db00df899 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -93,7 +93,6 @@ class SwitchCase;
class TemplateParameterList;
class Token;
class TypeSourceInfo;
-class VersionTuple;
/// Writes an AST file containing the contents of a translation unit.
///
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 3db886957c0..7b7febdc410 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -34,7 +34,6 @@
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallVector.h"
@@ -42,6 +41,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 2e394916b52..e82f451dea1 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -93,7 +93,6 @@ add_clang_library(clangBasic
Targets/XCore.cpp
TokenKinds.cpp
Version.cpp
- VersionTuple.cpp
VirtualFileSystem.cpp
Warnings.cpp
XRayInstr.cpp
diff --git a/clang/lib/Basic/ObjCRuntime.cpp b/clang/lib/Basic/ObjCRuntime.cpp
index 15f38d1156a..8fa0afbe03f 100644
--- a/clang/lib/Basic/ObjCRuntime.cpp
+++ b/clang/lib/Basic/ObjCRuntime.cpp
@@ -13,8 +13,8 @@
//===----------------------------------------------------------------------===//
#include "clang/Basic/ObjCRuntime.h"
-#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/raw_ostream.h"
#include <cstddef>
#include <string>
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index a3799ac6138..a56a0380541 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -13,7 +13,6 @@
#include "ToolChains/Clang.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Sanitizers.h"
-#include "clang/Basic/VersionTuple.h"
#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
@@ -29,6 +28,7 @@
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/llvm-config.h"
+#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/OptTable.h"
@@ -36,9 +36,9 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
-#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Support/TargetParser.h"
#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/VersionTuple.h"
#include <cassert>
#include <cstddef>
#include <cstring>
diff --git a/clang/lib/Driver/ToolChains/Cuda.h b/clang/lib/Driver/ToolChains/Cuda.h
index 057eb220c2a..99d5a4a628c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.h
+++ b/clang/lib/Driver/ToolChains/Cuda.h
@@ -11,14 +11,14 @@
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
#include "clang/Basic/Cuda.h"
-#include "clang/Basic/VersionTuple.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Multilib.h"
-#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/VersionTuple.h"
#include <set>
#include <vector>
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index b10155da96c..a959cdb2347 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -23,7 +23,6 @@
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/Version.h"
-#include "clang/Basic/VersionTuple.h"
#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Basic/Visibility.h"
#include "clang/Basic/XRayInstr.h"
@@ -76,6 +75,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Regex.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetOptions.h"
#include <algorithm>
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 4dd79720270..89dff67446a 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -61,7 +61,6 @@
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Basic/Version.h"
-#include "clang/Basic/VersionTuple.h"
#include "clang/Frontend/PCHContainerOperations.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/HeaderSearchOptions.h"
@@ -104,8 +103,8 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Support/Casting.h"
-#include "llvm/Support/Compression.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compression.h"
#include "llvm/Support/DJB.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
@@ -115,6 +114,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/Timer.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index c1f552e536a..1e3a098b09e 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -53,7 +53,6 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/Version.h"
-#include "clang/Basic/VersionTuple.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/MacroInfo.h"
@@ -97,6 +96,7 @@
#include "llvm/Support/OnDiskHashTable.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SHA1.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 92ad6608888..fa4a16b7671 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -16,8 +16,6 @@
#include <algorithm>
#include <mutex>
-// Other libraries and framework includes
-#include "clang/Basic/VersionTuple.h"
// Project includes
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Breakpoint/BreakpointSite.h"
@@ -42,6 +40,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Threading.h"
+#include "llvm/Support/VersionTuple.h"
#if defined(__APPLE__)
#include <TargetConditionals.h> // for TARGET_OS_TV, TARGET_OS_WATCH
@@ -1612,19 +1611,19 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
case SDKType::iPhoneOS:
minimum_version_option.PutCString("-mios-version-min=");
minimum_version_option.PutCString(
- clang::VersionTuple(versions[0], versions[1], versions[2])
+ llvm::VersionTuple(versions[0], versions[1], versions[2])
.getAsString());
break;
case SDKType::iPhoneSimulator:
minimum_version_option.PutCString("-mios-simulator-version-min=");
minimum_version_option.PutCString(
- clang::VersionTuple(versions[0], versions[1], versions[2])
+ llvm::VersionTuple(versions[0], versions[1], versions[2])
.getAsString());
break;
case SDKType::MacOSX:
minimum_version_option.PutCString("-mmacosx-version-min=");
minimum_version_option.PutCString(
- clang::VersionTuple(versions[0], versions[1], versions[2])
+ llvm::VersionTuple(versions[0], versions[1], versions[2])
.getAsString());
}
options.push_back(minimum_version_option.GetString());
diff --git a/clang/include/clang/Basic/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h
index e7385b0b3bd..e85a188e54b 100644
--- a/clang/include/clang/Basic/VersionTuple.h
+++ b/llvm/include/llvm/Support/VersionTuple.h
@@ -8,19 +8,20 @@
//===----------------------------------------------------------------------===//
///
/// \file
-/// Defines the clang::VersionTuple class, which represents a version in
+/// Defines the llvm::VersionTuple class, which represents a version in
/// the form major[.minor[.subminor]].
///
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_BASIC_VERSIONTUPLE_H
-#define LLVM_CLANG_BASIC_VERSIONTUPLE_H
+#ifndef LLVM_SUPPORT_VERSIONTUPLE_H
+#define LLVM_SUPPORT_VERSIONTUPLE_H
-#include "clang/Basic/LLVM.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
#include <string>
#include <tuple>
-namespace clang {
+namespace llvm {
/// Represents a version number in the form major[.minor[.subminor[.build]]].
class VersionTuple {
@@ -86,17 +87,17 @@ public:
return None;
return Build;
}
-
+
/// Determine if two version numbers are equivalent. If not
/// provided, minor and subminor version numbers are considered to be zero.
- friend bool operator==(const VersionTuple& X, const VersionTuple &Y) {
+ friend bool operator==(const VersionTuple &X, const VersionTuple &Y) {
return X.Major == Y.Major && X.Minor == Y.Minor &&
X.Subminor == Y.Subminor && X.Build == Y.Build;
}
/// Determine if two version numbers are not equivalent.
///
- /// If not provided, minor and subminor version numbers are considered to be
+ /// If not provided, minor and subminor version numbers are considered to be
/// zero.
friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) {
return !(X == Y);
@@ -120,7 +121,7 @@ public:
}
/// Determine whether one version number precedes or is
- /// equivalent to another.
+ /// equivalent to another.
///
/// If not provided, minor and subminor version numbers are considered to be
/// zero.
@@ -147,7 +148,7 @@ public:
};
/// Print a version number.
-raw_ostream& operator<<(raw_ostream &Out, const VersionTuple &V);
+raw_ostream &operator<<(raw_ostream &Out, const VersionTuple &V);
-} // end namespace clang
-#endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H
+} // end namespace llvm
+#endif // LLVM_SUPPORT_VERSIONTUPLE_H
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 3548a99934c..e1a48ac97fb 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -124,6 +124,7 @@ add_llvm_library(LLVMSupport
Twine.cpp
Unicode.cpp
UnicodeCaseFold.cpp
+ VersionTuple.cpp
WithColor.cpp
YAMLParser.cpp
YAMLTraits.cpp
diff --git a/clang/lib/Basic/VersionTuple.cpp b/llvm/lib/Support/VersionTuple.cpp
index 7a9176a808e..3f219bfbedf 100644
--- a/clang/lib/Basic/VersionTuple.cpp
+++ b/llvm/lib/Support/VersionTuple.cpp
@@ -11,10 +11,10 @@
// the form major[.minor[.subminor]].
//
//===----------------------------------------------------------------------===//
-#include "clang/Basic/VersionTuple.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/raw_ostream.h"
-using namespace clang;
+using namespace llvm;
std::string VersionTuple::getAsString() const {
std::string Result;
@@ -25,8 +25,7 @@ std::string VersionTuple::getAsString() const {
return Result;
}
-raw_ostream& clang::operator<<(raw_ostream &Out,
- const VersionTuple &V) {
+raw_ostream &llvm::operator<<(raw_ostream &Out, const VersionTuple &V) {
Out << V.getMajor();
if (Optional<unsigned> Minor = V.getMinor())
Out << '.' << *Minor;
@@ -39,18 +38,21 @@ raw_ostream& clang::operator<<(raw_ostream &Out,
static bool parseInt(StringRef &input, unsigned &value) {
assert(value == 0);
- if (input.empty()) return true;
+ if (input.empty())
+ return true;
char next = input[0];
input = input.substr(1);
- if (next < '0' || next > '9') return true;
- value = (unsigned) (next - '0');
+ if (next < '0' || next > '9')
+ return true;
+ value = (unsigned)(next - '0');
while (!input.empty()) {
next = input[0];
- if (next < '0' || next > '9') return false;
+ if (next < '0' || next > '9')
+ return false;
input = input.substr(1);
- value = value * 10 + (unsigned) (next - '0');
+ value = value * 10 + (unsigned)(next - '0');
}
return false;
@@ -60,7 +62,8 @@ bool VersionTuple::tryParse(StringRef input) {
unsigned major = 0, minor = 0, micro = 0, build = 0;
// Parse the major version, [0-9]+
- if (parseInt(input, major)) return true;
+ if (parseInt(input, major))
+ return true;
if (input.empty()) {
*this = VersionTuple(major);
@@ -68,9 +71,11 @@ bool VersionTuple::tryParse(StringRef input) {
}
// If we're not done, parse the minor version, \.[0-9]+
- if (input[0] != '.') return true;
+ if (input[0] != '.')
+ return true;
input = input.substr(1);
- if (parseInt(input, minor)) return true;
+ if (parseInt(input, minor))
+ return true;
if (input.empty()) {
*this = VersionTuple(major, minor);
@@ -78,9 +83,11 @@ bool VersionTuple::tryParse(StringRef input) {
}
// If we're not done, parse the micro version, \.[0-9]+
- if (input[0] != '.') return true;
+ if (input[0] != '.')
+ return true;
input = input.substr(1);
- if (parseInt(input, micro)) return true;
+ if (parseInt(input, micro))
+ return true;
if (input.empty()) {
*this = VersionTuple(major, minor, micro);
@@ -88,12 +95,15 @@ bool VersionTuple::tryParse(StringRef input) {
}
// If we're not done, parse the micro version, \.[0-9]+
- if (input[0] != '.') return true;
+ if (input[0] != '.')
+ return true;
input = input.substr(1);
- if (parseInt(input, build)) return true;
+ if (parseInt(input, build))
+ return true;
// If we have characters left over, it's an error.
- if (!input.empty()) return true;
+ if (!input.empty())
+ return true;
*this = VersionTuple(major, minor, micro, build);
return false;
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt
index 89e16ef4b3f..4b46387a471 100644
--- a/llvm/unittests/Support/CMakeLists.txt
+++ b/llvm/unittests/Support/CMakeLists.txt
@@ -61,6 +61,7 @@ add_llvm_unittest(SupportTests
TrailingObjectsTest.cpp
TrigramIndexTest.cpp
UnicodeTest.cpp
+ VersionTupleTest.cpp
YAMLIOTest.cpp
YAMLParserTest.cpp
formatted_raw_ostream_test.cpp
diff --git a/llvm/unittests/Support/VersionTupleTest.cpp b/llvm/unittests/Support/VersionTupleTest.cpp
new file mode 100644
index 00000000000..cd7ecda5fef
--- /dev/null
+++ b/llvm/unittests/Support/VersionTupleTest.cpp
@@ -0,0 +1,50 @@
+//===- VersionTupleTests.cpp - Version Number Handling Tests --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/VersionTuple.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+TEST(VersionTuple, getAsString) {
+ EXPECT_EQ("0", VersionTuple().getAsString());
+ EXPECT_EQ("1", VersionTuple(1).getAsString());
+ EXPECT_EQ("1.2", VersionTuple(1, 2).getAsString());
+ EXPECT_EQ("1.2.3", VersionTuple(1, 2, 3).getAsString());
+ EXPECT_EQ("1.2.3.4", VersionTuple(1, 2, 3, 4).getAsString());
+}
+
+TEST(VersionTuple, tryParse) {
+ VersionTuple VT;
+
+ EXPECT_FALSE(VT.tryParse("1"));
+ EXPECT_EQ("1", VT.getAsString());
+
+ EXPECT_FALSE(VT.tryParse("1.2"));
+ EXPECT_EQ("1.2", VT.getAsString());
+
+ EXPECT_FALSE(VT.tryParse("1.2.3"));
+ EXPECT_EQ("1.2.3", VT.getAsString());
+
+ EXPECT_FALSE(VT.tryParse("1.2.3.4"));
+ EXPECT_EQ("1.2.3.4", VT.getAsString());
+
+ EXPECT_TRUE(VT.tryParse(""));
+ EXPECT_TRUE(VT.tryParse("1."));
+ EXPECT_TRUE(VT.tryParse("1.2."));
+ EXPECT_TRUE(VT.tryParse("1.2.3."));
+ EXPECT_TRUE(VT.tryParse("1.2.3.4."));
+ EXPECT_TRUE(VT.tryParse("1.2.3.4.5"));
+ EXPECT_TRUE(VT.tryParse("1-2"));
+ EXPECT_TRUE(VT.tryParse("1+2"));
+ EXPECT_TRUE(VT.tryParse(".1"));
+ EXPECT_TRUE(VT.tryParse(" 1"));
+ EXPECT_TRUE(VT.tryParse("1 "));
+ EXPECT_TRUE(VT.tryParse("."));
+}
OpenPOWER on IntegriCloud