1 //===- VersionTuple.h - Version Number Handling -----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines the clang::VersionTuple class, which represents a version in
12 /// the form major[.minor[.subminor]].
14 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_VERSIONTUPLE_H
16 #define LLVM_CLANG_BASIC_VERSIONTUPLE_H
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/Optional.h"
24 /// \brief Represents a version number in the form major[.minor[.subminor]].
28 unsigned Subminor : 31;
29 unsigned HasMinor : 1;
30 unsigned HasSubminor : 1;
34 : Major(0), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false) { }
36 explicit VersionTuple(unsigned Major)
37 : Major(Major), Minor(0), Subminor(0), HasMinor(false), HasSubminor(false)
40 explicit VersionTuple(unsigned Major, unsigned Minor)
41 : Major(Major), Minor(Minor), Subminor(0), HasMinor(true),
45 explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor)
46 : Major(Major), Minor(Minor), Subminor(Subminor), HasMinor(true),
50 /// \brief Determine whether this version information is empty
51 /// (e.g., all version components are zero).
52 bool empty() const { return Major == 0 && Minor == 0 && Subminor == 0; }
54 /// \brief Retrieve the major version number.
55 unsigned getMajor() const { return Major; }
57 /// \brief Retrieve the minor version number, if provided.
58 Optional<unsigned> getMinor() const {
64 /// \brief Retrieve the subminor version number, if provided.
65 Optional<unsigned> getSubminor() const {
71 /// \brief Determine if two version numbers are equivalent. If not
72 /// provided, minor and subminor version numbers are considered to be zero.
73 friend bool operator==(const VersionTuple& X, const VersionTuple &Y) {
74 return X.Major == Y.Major && X.Minor == Y.Minor && X.Subminor == Y.Subminor;
77 /// \brief Determine if two version numbers are not equivalent.
79 /// If not provided, minor and subminor version numbers are considered to be
81 friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) {
85 /// \brief Determine whether one version number precedes another.
87 /// If not provided, minor and subminor version numbers are considered to be
89 friend bool operator<(const VersionTuple &X, const VersionTuple &Y) {
90 if (X.Major != Y.Major)
91 return X.Major < Y.Major;
93 if (X.Minor != Y.Minor)
94 return X.Minor < Y.Minor;
96 return X.Subminor < Y.Subminor;
99 /// \brief Determine whether one version number follows another.
101 /// If not provided, minor and subminor version numbers are considered to be
103 friend bool operator>(const VersionTuple &X, const VersionTuple &Y) {
107 /// \brief Determine whether one version number precedes or is
108 /// equivalent to another.
110 /// If not provided, minor and subminor version numbers are considered to be
112 friend bool operator<=(const VersionTuple &X, const VersionTuple &Y) {
116 /// \brief Determine whether one version number follows or is
117 /// equivalent to another.
119 /// If not provided, minor and subminor version numbers are considered to be
121 friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) {
125 /// \brief Retrieve a string representation of the version number.
126 std::string getAsString() const;
128 /// \brief Try to parse the given string as a version number.
129 /// \returns \c true if the string does not match the regular expression
130 /// [0-9]+(\.[0-9]+(\.[0-9]+))
131 bool tryParse(StringRef string);
134 /// \brief Print a version number.
135 raw_ostream& operator<<(raw_ostream &Out, const VersionTuple &V);
137 } // end namespace clang
138 #endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H