Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/VersionTuple.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- VersionTuple.cpp - Version Number Handling ---------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements the VersionTuple class, which represents a version in
10
// the form major[.minor[.subminor]].
11
//
12
//===----------------------------------------------------------------------===//
13
#include "llvm/Support/VersionTuple.h"
14
#include "llvm/Support/raw_ostream.h"
15
16
using namespace llvm;
17
18
32.4k
std::string VersionTuple::getAsString() const {
19
32.4k
  std::string Result;
20
32.4k
  {
21
32.4k
    llvm::raw_string_ostream Out(Result);
22
32.4k
    Out << *this;
23
32.4k
  }
24
32.4k
  return Result;
25
32.4k
}
26
27
123k
raw_ostream &llvm::operator<<(raw_ostream &Out, const VersionTuple &V) {
28
123k
  Out << V.getMajor();
29
123k
  if (Optional<unsigned> Minor = V.getMinor())
30
123k
    Out << '.' << *Minor;
31
123k
  if (Optional<unsigned> Subminor = V.getSubminor())
32
48.2k
    Out << '.' << *Subminor;
33
123k
  if (Optional<unsigned> Build = V.getBuild())
34
3
    Out << '.' << *Build;
35
123k
  return Out;
36
123k
}
37
38
52.0k
static bool parseInt(StringRef &input, unsigned &value) {
39
52.0k
  assert(value == 0);
40
52.0k
  if (input.empty())
41
4
    return true;
42
52.0k
43
52.0k
  char next = input[0];
44
52.0k
  input = input.substr(1);
45
52.0k
  if (next < '0' || 
next > '9'52.0k
)
46
3
    return true;
47
52.0k
  value = (unsigned)(next - '0');
48
52.0k
49
85.9k
  while (!input.empty()) {
50
60.2k
    next = input[0];
51
60.2k
    if (next < '0' || 
next > '9'33.8k
)
52
26.3k
      return false;
53
33.8k
    input = input.substr(1);
54
33.8k
    value = value * 10 + (unsigned)(next - '0');
55
33.8k
  }
56
52.0k
57
52.0k
  
return false25.7k
;
58
52.0k
}
59
60
25.7k
bool VersionTuple::tryParse(StringRef input) {
61
25.7k
  unsigned major = 0, minor = 0, micro = 0, build = 0;
62
25.7k
63
25.7k
  // Parse the major version, [0-9]+
64
25.7k
  if (parseInt(input, major))
65
4
    return true;
66
25.7k
67
25.7k
  if (input.empty()) {
68
34
    *this = VersionTuple(major);
69
34
    return false;
70
34
  }
71
25.6k
72
25.6k
  // If we're not done, parse the minor version, \.[0-9]+
73
25.6k
  if (input[0] != '.')
74
3
    return true;
75
25.6k
  input = input.substr(1);
76
25.6k
  if (parseInt(input, minor))
77
1
    return true;
78
25.6k
79
25.6k
  if (input.empty()) {
80
25.0k
    *this = VersionTuple(major, minor);
81
25.0k
    return false;
82
25.0k
  }
83
622
84
622
  // If we're not done, parse the micro version, \.[0-9]+
85
622
  if (input[0] != '.')
86
0
    return true;
87
622
  input = input.substr(1);
88
622
  if (parseInt(input, micro))
89
1
    return true;
90
621
91
621
  if (input.empty()) {
92
614
    *this = VersionTuple(major, minor, micro);
93
614
    return false;
94
614
  }
95
7
96
7
  // If we're not done, parse the micro version, \.[0-9]+
97
7
  if (input[0] != '.')
98
0
    return true;
99
7
  input = input.substr(1);
100
7
  if (parseInt(input, build))
101
1
    return true;
102
6
103
6
  // If we have characters left over, it's an error.
104
6
  if (!input.empty())
105
2
    return true;
106
4
107
4
  *this = VersionTuple(major, minor, micro, build);
108
4
  return false;
109
4
}