Index: cfe/trunk/include/clang/AST/Attr.h =================================================================== --- cfe/trunk/include/clang/AST/Attr.h +++ cfe/trunk/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 #include Index: cfe/trunk/include/clang/AST/Availability.h =================================================================== --- cfe/trunk/include/clang/AST/Availability.h +++ cfe/trunk/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 { Index: cfe/trunk/include/clang/AST/DeclBase.h =================================================================== --- cfe/trunk/include/clang/AST/DeclBase.h +++ cfe/trunk/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 #include #include Index: cfe/trunk/include/clang/AST/ExprObjC.h =================================================================== --- cfe/trunk/include/clang/AST/ExprObjC.h +++ cfe/trunk/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 #include Index: cfe/trunk/include/clang/Basic/AlignedAllocation.h =================================================================== --- cfe/trunk/include/clang/Basic/AlignedAllocation.h +++ cfe/trunk/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 { Index: cfe/trunk/include/clang/Basic/LLVM.h =================================================================== --- cfe/trunk/include/clang/Basic/LLVM.h +++ cfe/trunk/include/clang/Basic/LLVM.h @@ -28,6 +28,7 @@ // ADT's. class StringRef; class Twine; + class VersionTuple; template class ArrayRef; template class MutableArrayRef; template class OwningArrayRef; @@ -60,17 +61,18 @@ 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; Index: cfe/trunk/include/clang/Basic/ObjCRuntime.h =================================================================== --- cfe/trunk/include/clang/Basic/ObjCRuntime.h +++ cfe/trunk/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 namespace clang { Index: cfe/trunk/include/clang/Basic/TargetInfo.h =================================================================== --- cfe/trunk/include/clang/Basic/TargetInfo.h +++ cfe/trunk/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 #include #include Index: cfe/trunk/include/clang/Basic/VersionTuple.h =================================================================== --- cfe/trunk/include/clang/Basic/VersionTuple.h +++ cfe/trunk/include/clang/Basic/VersionTuple.h @@ -1,153 +0,0 @@ -//===- VersionTuple.h - Version Number Handling -----------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// Defines the clang::VersionTuple class, which represents a version in -/// the form major[.minor[.subminor]]. -/// -//===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_BASIC_VERSIONTUPLE_H -#define LLVM_CLANG_BASIC_VERSIONTUPLE_H - -#include "clang/Basic/LLVM.h" -#include "llvm/ADT/Optional.h" -#include -#include - -namespace clang { - -/// Represents a version number in the form major[.minor[.subminor[.build]]]. -class VersionTuple { - unsigned Major : 32; - - unsigned Minor : 31; - unsigned HasMinor : 1; - - unsigned Subminor : 31; - unsigned HasSubminor : 1; - - unsigned Build : 31; - unsigned HasBuild : 1; - -public: - VersionTuple() - : Major(0), Minor(0), HasMinor(false), Subminor(0), HasSubminor(false), - Build(0), HasBuild(false) {} - - explicit VersionTuple(unsigned Major) - : Major(Major), Minor(0), HasMinor(false), Subminor(0), - HasSubminor(false), Build(0), HasBuild(false) {} - - explicit VersionTuple(unsigned Major, unsigned Minor) - : Major(Major), Minor(Minor), HasMinor(true), Subminor(0), - HasSubminor(false), Build(0), HasBuild(false) {} - - explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor) - : Major(Major), Minor(Minor), HasMinor(true), Subminor(Subminor), - HasSubminor(true), Build(0), HasBuild(false) {} - - explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor, - unsigned Build) - : Major(Major), Minor(Minor), HasMinor(true), Subminor(Subminor), - HasSubminor(true), Build(Build), HasBuild(true) {} - - /// Determine whether this version information is empty - /// (e.g., all version components are zero). - bool empty() const { - return Major == 0 && Minor == 0 && Subminor == 0 && Build == 0; - } - - /// Retrieve the major version number. - unsigned getMajor() const { return Major; } - - /// Retrieve the minor version number, if provided. - Optional getMinor() const { - if (!HasMinor) - return None; - return Minor; - } - - /// Retrieve the subminor version number, if provided. - Optional getSubminor() const { - if (!HasSubminor) - return None; - return Subminor; - } - - /// Retrieve the build version number, if provided. - Optional getBuild() const { - if (!HasBuild) - 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) { - 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 - /// zero. - friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) { - return !(X == Y); - } - - /// Determine whether one version number precedes another. - /// - /// If not provided, minor and subminor version numbers are considered to be - /// zero. - friend bool operator<(const VersionTuple &X, const VersionTuple &Y) { - return std::tie(X.Major, X.Minor, X.Subminor, X.Build) < - std::tie(Y.Major, Y.Minor, Y.Subminor, Y.Build); - } - - /// Determine whether one version number follows another. - /// - /// If not provided, minor and subminor version numbers are considered to be - /// zero. - friend bool operator>(const VersionTuple &X, const VersionTuple &Y) { - return Y < X; - } - - /// Determine whether one version number precedes or is - /// equivalent to another. - /// - /// If not provided, minor and subminor version numbers are considered to be - /// zero. - friend bool operator<=(const VersionTuple &X, const VersionTuple &Y) { - return !(Y < X); - } - - /// Determine whether one version number follows or is - /// equivalent to another. - /// - /// 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); - } - - /// Retrieve a string representation of the version number. - std::string getAsString() const; - - /// Try to parse the given string as a version number. - /// \returns \c true if the string does not match the regular expression - /// [0-9]+(\.[0-9]+){0,3} - bool tryParse(StringRef string); -}; - -/// Print a version number. -raw_ostream& operator<<(raw_ostream &Out, const VersionTuple &V); - -} // end namespace clang -#endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H Index: cfe/trunk/include/clang/Driver/ToolChain.h =================================================================== --- cfe/trunk/include/clang/Driver/ToolChain.h +++ cfe/trunk/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 #include Index: cfe/trunk/include/clang/Parse/Parser.h =================================================================== --- cfe/trunk/include/clang/Parse/Parser.h +++ cfe/trunk/include/clang/Parse/Parser.h @@ -45,7 +45,6 @@ class ColonProtectionRAIIObject; class InMessageExpressionRAIIObject; class PoisonSEHIdentifiersRAIIObject; - class VersionTuple; class OMPClause; class ObjCTypeParamList; class ObjCTypeParameter; Index: cfe/trunk/include/clang/Sema/AttributeList.h =================================================================== --- cfe/trunk/include/clang/Sema/AttributeList.h +++ cfe/trunk/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 #include #include Index: cfe/trunk/include/clang/Serialization/ASTReader.h =================================================================== --- cfe/trunk/include/clang/Serialization/ASTReader.h +++ cfe/trunk/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 #include #include Index: cfe/trunk/include/clang/Serialization/ASTWriter.h =================================================================== --- cfe/trunk/include/clang/Serialization/ASTWriter.h +++ cfe/trunk/include/clang/Serialization/ASTWriter.h @@ -93,7 +93,6 @@ class TemplateParameterList; class Token; class TypeSourceInfo; -class VersionTuple; /// Writes an AST file containing the contents of a translation unit. /// Index: cfe/trunk/lib/AST/DeclBase.cpp =================================================================== --- cfe/trunk/lib/AST/DeclBase.cpp +++ cfe/trunk/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 #include Index: cfe/trunk/lib/Basic/CMakeLists.txt =================================================================== --- cfe/trunk/lib/Basic/CMakeLists.txt +++ cfe/trunk/lib/Basic/CMakeLists.txt @@ -93,7 +93,6 @@ Targets/XCore.cpp TokenKinds.cpp Version.cpp - VersionTuple.cpp VirtualFileSystem.cpp Warnings.cpp XRayInstr.cpp Index: cfe/trunk/lib/Basic/ObjCRuntime.cpp =================================================================== --- cfe/trunk/lib/Basic/ObjCRuntime.cpp +++ cfe/trunk/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 #include Index: cfe/trunk/lib/Basic/VersionTuple.cpp =================================================================== --- cfe/trunk/lib/Basic/VersionTuple.cpp +++ cfe/trunk/lib/Basic/VersionTuple.cpp @@ -1,100 +0,0 @@ -//===- VersionTuple.cpp - Version Number Handling ---------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the VersionTuple class, which represents a version in -// the form major[.minor[.subminor]]. -// -//===----------------------------------------------------------------------===// -#include "clang/Basic/VersionTuple.h" -#include "llvm/Support/raw_ostream.h" - -using namespace clang; - -std::string VersionTuple::getAsString() const { - std::string Result; - { - llvm::raw_string_ostream Out(Result); - Out << *this; - } - return Result; -} - -raw_ostream& clang::operator<<(raw_ostream &Out, - const VersionTuple &V) { - Out << V.getMajor(); - if (Optional Minor = V.getMinor()) - Out << '.' << *Minor; - if (Optional Subminor = V.getSubminor()) - Out << '.' << *Subminor; - if (Optional Build = V.getBuild()) - Out << '.' << *Build; - return Out; -} - -static bool parseInt(StringRef &input, unsigned &value) { - assert(value == 0); - if (input.empty()) return true; - - char next = input[0]; - input = input.substr(1); - if (next < '0' || next > '9') return true; - value = (unsigned) (next - '0'); - - while (!input.empty()) { - next = input[0]; - if (next < '0' || next > '9') return false; - input = input.substr(1); - value = value * 10 + (unsigned) (next - '0'); - } - - return false; -} - -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 (input.empty()) { - *this = VersionTuple(major); - return false; - } - - // If we're not done, parse the minor version, \.[0-9]+ - if (input[0] != '.') return true; - input = input.substr(1); - if (parseInt(input, minor)) return true; - - if (input.empty()) { - *this = VersionTuple(major, minor); - return false; - } - - // If we're not done, parse the micro version, \.[0-9]+ - if (input[0] != '.') return true; - input = input.substr(1); - if (parseInt(input, micro)) return true; - - if (input.empty()) { - *this = VersionTuple(major, minor, micro); - return false; - } - - // If we're not done, parse the micro version, \.[0-9]+ - if (input[0] != '.') return true; - input = input.substr(1); - if (parseInt(input, build)) return true; - - // If we have characters left over, it's an error. - if (!input.empty()) return true; - - *this = VersionTuple(major, minor, micro, build); - return false; -} Index: cfe/trunk/lib/Driver/ToolChain.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChain.cpp +++ cfe/trunk/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 #include #include Index: cfe/trunk/lib/Driver/ToolChains/Cuda.h =================================================================== --- cfe/trunk/lib/Driver/ToolChains/Cuda.h +++ cfe/trunk/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 #include Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/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 Index: cfe/trunk/lib/Serialization/ASTReader.cpp =================================================================== --- cfe/trunk/lib/Serialization/ASTReader.cpp +++ cfe/trunk/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 #include Index: cfe/trunk/lib/Serialization/ASTWriter.cpp =================================================================== --- cfe/trunk/lib/Serialization/ASTWriter.cpp +++ cfe/trunk/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 #include Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -16,8 +16,6 @@ #include #include -// 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 // for TARGET_OS_TV, TARGET_OS_WATCH @@ -1612,19 +1611,19 @@ 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()); Index: llvm/trunk/include/llvm/Support/VersionTuple.h =================================================================== --- llvm/trunk/include/llvm/Support/VersionTuple.h +++ llvm/trunk/include/llvm/Support/VersionTuple.h @@ -0,0 +1,154 @@ +//===- VersionTuple.h - Version Number Handling -----------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Defines the llvm::VersionTuple class, which represents a version in +/// the form major[.minor[.subminor]]. +/// +//===----------------------------------------------------------------------===// +#ifndef LLVM_SUPPORT_VERSIONTUPLE_H +#define LLVM_SUPPORT_VERSIONTUPLE_H + +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +namespace llvm { + +/// Represents a version number in the form major[.minor[.subminor[.build]]]. +class VersionTuple { + unsigned Major : 32; + + unsigned Minor : 31; + unsigned HasMinor : 1; + + unsigned Subminor : 31; + unsigned HasSubminor : 1; + + unsigned Build : 31; + unsigned HasBuild : 1; + +public: + VersionTuple() + : Major(0), Minor(0), HasMinor(false), Subminor(0), HasSubminor(false), + Build(0), HasBuild(false) {} + + explicit VersionTuple(unsigned Major) + : Major(Major), Minor(0), HasMinor(false), Subminor(0), + HasSubminor(false), Build(0), HasBuild(false) {} + + explicit VersionTuple(unsigned Major, unsigned Minor) + : Major(Major), Minor(Minor), HasMinor(true), Subminor(0), + HasSubminor(false), Build(0), HasBuild(false) {} + + explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor) + : Major(Major), Minor(Minor), HasMinor(true), Subminor(Subminor), + HasSubminor(true), Build(0), HasBuild(false) {} + + explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor, + unsigned Build) + : Major(Major), Minor(Minor), HasMinor(true), Subminor(Subminor), + HasSubminor(true), Build(Build), HasBuild(true) {} + + /// Determine whether this version information is empty + /// (e.g., all version components are zero). + bool empty() const { + return Major == 0 && Minor == 0 && Subminor == 0 && Build == 0; + } + + /// Retrieve the major version number. + unsigned getMajor() const { return Major; } + + /// Retrieve the minor version number, if provided. + Optional getMinor() const { + if (!HasMinor) + return None; + return Minor; + } + + /// Retrieve the subminor version number, if provided. + Optional getSubminor() const { + if (!HasSubminor) + return None; + return Subminor; + } + + /// Retrieve the build version number, if provided. + Optional getBuild() const { + if (!HasBuild) + 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) { + 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 + /// zero. + friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) { + return !(X == Y); + } + + /// Determine whether one version number precedes another. + /// + /// If not provided, minor and subminor version numbers are considered to be + /// zero. + friend bool operator<(const VersionTuple &X, const VersionTuple &Y) { + return std::tie(X.Major, X.Minor, X.Subminor, X.Build) < + std::tie(Y.Major, Y.Minor, Y.Subminor, Y.Build); + } + + /// Determine whether one version number follows another. + /// + /// If not provided, minor and subminor version numbers are considered to be + /// zero. + friend bool operator>(const VersionTuple &X, const VersionTuple &Y) { + return Y < X; + } + + /// Determine whether one version number precedes or is + /// equivalent to another. + /// + /// If not provided, minor and subminor version numbers are considered to be + /// zero. + friend bool operator<=(const VersionTuple &X, const VersionTuple &Y) { + return !(Y < X); + } + + /// Determine whether one version number follows or is + /// equivalent to another. + /// + /// 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); + } + + /// Retrieve a string representation of the version number. + std::string getAsString() const; + + /// Try to parse the given string as a version number. + /// \returns \c true if the string does not match the regular expression + /// [0-9]+(\.[0-9]+){0,3} + bool tryParse(StringRef string); +}; + +/// Print a version number. +raw_ostream &operator<<(raw_ostream &Out, const VersionTuple &V); + +} // end namespace llvm +#endif // LLVM_SUPPORT_VERSIONTUPLE_H Index: llvm/trunk/lib/Support/CMakeLists.txt =================================================================== --- llvm/trunk/lib/Support/CMakeLists.txt +++ llvm/trunk/lib/Support/CMakeLists.txt @@ -124,6 +124,7 @@ Twine.cpp Unicode.cpp UnicodeCaseFold.cpp + VersionTuple.cpp WithColor.cpp YAMLParser.cpp YAMLTraits.cpp Index: llvm/trunk/lib/Support/VersionTuple.cpp =================================================================== --- llvm/trunk/lib/Support/VersionTuple.cpp +++ llvm/trunk/lib/Support/VersionTuple.cpp @@ -0,0 +1,110 @@ +//===- VersionTuple.cpp - Version Number Handling ---------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the VersionTuple class, which represents a version in +// the form major[.minor[.subminor]]. +// +//===----------------------------------------------------------------------===// +#include "llvm/Support/VersionTuple.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +std::string VersionTuple::getAsString() const { + std::string Result; + { + llvm::raw_string_ostream Out(Result); + Out << *this; + } + return Result; +} + +raw_ostream &llvm::operator<<(raw_ostream &Out, const VersionTuple &V) { + Out << V.getMajor(); + if (Optional Minor = V.getMinor()) + Out << '.' << *Minor; + if (Optional Subminor = V.getSubminor()) + Out << '.' << *Subminor; + if (Optional Build = V.getBuild()) + Out << '.' << *Build; + return Out; +} + +static bool parseInt(StringRef &input, unsigned &value) { + assert(value == 0); + if (input.empty()) + return true; + + char next = input[0]; + input = input.substr(1); + if (next < '0' || next > '9') + return true; + value = (unsigned)(next - '0'); + + while (!input.empty()) { + next = input[0]; + if (next < '0' || next > '9') + return false; + input = input.substr(1); + value = value * 10 + (unsigned)(next - '0'); + } + + return false; +} + +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 (input.empty()) { + *this = VersionTuple(major); + return false; + } + + // If we're not done, parse the minor version, \.[0-9]+ + if (input[0] != '.') + return true; + input = input.substr(1); + if (parseInt(input, minor)) + return true; + + if (input.empty()) { + *this = VersionTuple(major, minor); + return false; + } + + // If we're not done, parse the micro version, \.[0-9]+ + if (input[0] != '.') + return true; + input = input.substr(1); + if (parseInt(input, micro)) + return true; + + if (input.empty()) { + *this = VersionTuple(major, minor, micro); + return false; + } + + // If we're not done, parse the micro version, \.[0-9]+ + if (input[0] != '.') + return true; + input = input.substr(1); + if (parseInt(input, build)) + return true; + + // If we have characters left over, it's an error. + if (!input.empty()) + return true; + + *this = VersionTuple(major, minor, micro, build); + return false; +} Index: llvm/trunk/unittests/Support/CMakeLists.txt =================================================================== --- llvm/trunk/unittests/Support/CMakeLists.txt +++ llvm/trunk/unittests/Support/CMakeLists.txt @@ -61,6 +61,7 @@ TrailingObjectsTest.cpp TrigramIndexTest.cpp UnicodeTest.cpp + VersionTupleTest.cpp YAMLIOTest.cpp YAMLParserTest.cpp formatted_raw_ostream_test.cpp Index: llvm/trunk/unittests/Support/VersionTupleTest.cpp =================================================================== --- llvm/trunk/unittests/Support/VersionTupleTest.cpp +++ llvm/trunk/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(".")); +}