Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/clang/include/clang/Basic/VersionTuple.h
Line
Count
Source
1
//===- VersionTuple.h - Version Number Handling -----------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// \brief Defines the clang::VersionTuple class, which represents a version in
12
/// the form major[.minor[.subminor]].
13
///
14
//===----------------------------------------------------------------------===//
15
#ifndef LLVM_CLANG_BASIC_VERSIONTUPLE_H
16
#define LLVM_CLANG_BASIC_VERSIONTUPLE_H
17
18
#include "clang/Basic/LLVM.h"
19
#include "llvm/ADT/Optional.h"
20
#include <string>
21
#include <tuple>
22
23
namespace clang {
24
25
/// \brief Represents a version number in the form major[.minor[.subminor[.build]]].
26
class VersionTuple {
27
  unsigned Major : 31;
28
29
  unsigned UsesUnderscores : 1;
30
31
  unsigned Minor : 31;
32
  unsigned HasMinor : 1;
33
34
  unsigned Subminor : 31;
35
  unsigned HasSubminor : 1;
36
37
  unsigned Build : 31;
38
  unsigned HasBuild : 1;
39
40
public:
41
  VersionTuple()
42
      : Major(0), UsesUnderscores(false), Minor(0), HasMinor(false),
43
27.6M
        Subminor(0), HasSubminor(false), Build(0), HasBuild(false) {}
44
45
  explicit VersionTuple(unsigned Major)
46
      : Major(Major), UsesUnderscores(false), Minor(0), HasMinor(false),
47
48.4k
        Subminor(0), HasSubminor(false), Build(0), HasBuild(false) {}
48
49
  explicit VersionTuple(unsigned Major, unsigned Minor,
50
                        bool UsesUnderscores = false)
51
      : Major(Major), UsesUnderscores(UsesUnderscores), Minor(Minor),
52
        HasMinor(true), Subminor(0), HasSubminor(false), Build(0),
53
564k
        HasBuild(false) {}
54
55
  explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor,
56
                        bool UsesUnderscores = false)
57
      : Major(Major), UsesUnderscores(UsesUnderscores), Minor(Minor),
58
        HasMinor(true), Subminor(Subminor), HasSubminor(true), Build(0),
59
164k
        HasBuild(false) {}
60
61
  explicit VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor,
62
                        unsigned Build, bool UsesUnderscores = false)
63
      : Major(Major), UsesUnderscores(UsesUnderscores), Minor(Minor),
64
        HasMinor(true), Subminor(Subminor), HasSubminor(true), Build(Build),
65
3
        HasBuild(true) {}
66
67
  /// \brief Determine whether this version information is empty
68
  /// (e.g., all version components are zero).
69
4.37M
  bool empty() const {
70
4.37M
    return Major == 0 && 
Minor == 02.30M
&&
Subminor == 02.30M
&&
Build == 02.30M
;
71
4.37M
  }
72
73
  /// \brief Retrieve the major version number.
74
141k
  unsigned getMajor() const { return Major; }
75
76
  /// \brief Retrieve the minor version number, if provided.
77
113k
  Optional<unsigned> getMinor() const {
78
113k
    if (!HasMinor)
79
31.3k
      return None;
80
82.2k
    return Minor;
81
113k
  }
82
83
  /// \brief Retrieve the subminor version number, if provided.
84
113k
  Optional<unsigned> getSubminor() const {
85
113k
    if (!HasSubminor)
86
59.3k
      return None;
87
54.2k
    return Subminor;
88
113k
  }
89
90
  /// \brief Retrieve the build version number, if provided.
91
63.7k
  Optional<unsigned> getBuild() const {
92
63.7k
    if (!HasBuild)
93
63.7k
      return None;
94
1
    return Build;
95
63.7k
  }
96
97
116k
  bool usesUnderscores() const {
98
116k
    return UsesUnderscores;
99
116k
  }
100
101
9.03k
  void UseDotAsSeparator() {
102
9.03k
    UsesUnderscores = false;
103
9.03k
  }
104
  
105
  /// \brief Determine if two version numbers are equivalent. If not
106
  /// provided, minor and subminor version numbers are considered to be zero.
107
59.3k
  friend bool operator==(const VersionTuple& X, const VersionTuple &Y) {
108
45.2k
    return X.Major == Y.Major && X.Minor == Y.Minor &&
109
59.3k
           
X.Subminor == Y.Subminor45.1k
&&
X.Build == Y.Build45.1k
;
110
59.3k
  }
111
112
  /// \brief Determine if two version numbers are not equivalent.
113
  ///
114
  /// If not provided, minor and subminor version numbers are considered to be 
115
  /// zero.
116
  friend bool operator!=(const VersionTuple &X, const VersionTuple &Y) {
117
    return !(X == Y);
118
  }
119
120
  /// \brief Determine whether one version number precedes another.
121
  ///
122
  /// If not provided, minor and subminor version numbers are considered to be
123
  /// zero.
124
336k
  friend bool operator<(const VersionTuple &X, const VersionTuple &Y) {
125
336k
    return std::tie(X.Major, X.Minor, X.Subminor, X.Build) <
126
336k
           std::tie(Y.Major, Y.Minor, Y.Subminor, Y.Build);
127
336k
  }
128
129
  /// \brief Determine whether one version number follows another.
130
  ///
131
  /// If not provided, minor and subminor version numbers are considered to be
132
  /// zero.
133
29.7k
  friend bool operator>(const VersionTuple &X, const VersionTuple &Y) {
134
29.7k
    return Y < X;
135
29.7k
  }
136
137
  /// \brief Determine whether one version number precedes or is
138
  /// equivalent to another. 
139
  ///
140
  /// If not provided, minor and subminor version numbers are considered to be
141
  /// zero.
142
63.1k
  friend bool operator<=(const VersionTuple &X, const VersionTuple &Y) {
143
63.1k
    return !(Y < X);
144
63.1k
  }
145
146
  /// \brief Determine whether one version number follows or is
147
  /// equivalent to another.
148
  ///
149
  /// If not provided, minor and subminor version numbers are considered to be
150
  /// zero.
151
26.3k
  friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) {
152
26.3k
    return !(X < Y);
153
26.3k
  }
154
155
  /// \brief Retrieve a string representation of the version number.
156
  std::string getAsString() const;
157
158
  /// \brief Try to parse the given string as a version number.
159
  /// \returns \c true if the string does not match the regular expression
160
  ///   [0-9]+(\.[0-9]+){0,3}
161
  bool tryParse(StringRef string);
162
};
163
164
/// \brief Print a version number.
165
raw_ostream& operator<<(raw_ostream &Out, const VersionTuple &V);
166
167
} // end namespace clang
168
#endif // LLVM_CLANG_BASIC_VERSIONTUPLE_H