Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/ObjCRuntime.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ObjCRuntime.cpp - Objective-C Runtime Handling ---------------------===//
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 ObjCRuntime class, which represents the
10
// target Objective-C runtime.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/Basic/ObjCRuntime.h"
15
#include "llvm/ADT/StringRef.h"
16
#include "llvm/Support/VersionTuple.h"
17
#include "llvm/Support/raw_ostream.h"
18
#include <cstddef>
19
#include <string>
20
21
using namespace clang;
22
23
26.1k
std::string ObjCRuntime::getAsString() const {
24
26.1k
  std::string Result;
25
26.1k
  {
26
26.1k
    llvm::raw_string_ostream Out(Result);
27
26.1k
    Out << *this;
28
26.1k
  }
29
26.1k
  return Result;
30
26.1k
}
31
32
26.1k
raw_ostream &clang::operator<<(raw_ostream &out, const ObjCRuntime &value) {
33
26.1k
  switch (value.getKind()) {
34
16.4k
  case ObjCRuntime::MacOSX: out << "macosx"; break;
35
94
  case ObjCRuntime::FragileMacOSX: out << "macosx-fragile"; break;
36
181
  case ObjCRuntime::iOS: out << "ios"; break;
37
41
  case ObjCRuntime::WatchOS: out << "watchos"; break;
38
740
  case ObjCRuntime::GNUstep: out << "gnustep"; break;
39
8.63k
  case ObjCRuntime::GCC: out << "gcc"; break;
40
0
  case ObjCRuntime::ObjFW: out << "objfw"; break;
41
26.1k
  }
42
26.1k
  if (value.getVersion() > VersionTuple(0)) {
43
16.7k
    out << '-' << value.getVersion();
44
16.7k
  }
45
26.1k
  return out;
46
26.1k
}
47
48
3.17k
bool ObjCRuntime::tryParse(StringRef input) {
49
3.17k
  // Look for the last dash.
50
3.17k
  std::size_t dash = input.rfind('-');
51
3.17k
52
3.17k
  // We permit dashes in the runtime name, and we also permit the
53
3.17k
  // version to be omitted, so if we see a dash not followed by a
54
3.17k
  // digit then we need to ignore it.
55
3.17k
  if (dash != StringRef::npos && 
dash + 1 != input.size()2.95k
&&
56
3.17k
      
(2.95k
input[dash+1] < '0'2.95k
||
input[dash+1] > '9'2.95k
)) {
57
21
    dash = StringRef::npos;
58
21
  }
59
3.17k
60
3.17k
  // Everything prior to that must be a valid string name.
61
3.17k
  Kind kind;
62
3.17k
  StringRef runtimeName = input.substr(0, dash);
63
3.17k
  Version = VersionTuple(0);
64
3.17k
  if (runtimeName == "macosx") {
65
2.62k
    kind = ObjCRuntime::MacOSX;
66
2.62k
  } else 
if (557
runtimeName == "macosx-fragile"557
) {
67
278
    kind = ObjCRuntime::FragileMacOSX;
68
279
  } else if (runtimeName == "ios") {
69
66
    kind = ObjCRuntime::iOS;
70
213
  } else if (runtimeName == "watchos") {
71
16
    kind = ObjCRuntime::WatchOS;
72
197
  } else if (runtimeName == "gnustep") {
73
136
    // If no version is specified then default to the most recent one that we
74
136
    // know about.
75
136
    Version = VersionTuple(1, 6);
76
136
    kind = ObjCRuntime::GNUstep;
77
136
  } else 
if (61
runtimeName == "gcc"61
) {
78
40
    kind = ObjCRuntime::GCC;
79
40
  } else 
if (21
runtimeName == "objfw"21
) {
80
21
    kind = ObjCRuntime::ObjFW;
81
21
    Version = VersionTuple(0, 8);
82
21
  } else {
83
0
    return true;
84
0
  }
85
3.17k
  TheKind = kind;
86
3.17k
87
3.17k
  if (dash != StringRef::npos) {
88
2.93k
    StringRef verString = input.substr(dash + 1);
89
2.93k
    if (Version.tryParse(verString))
90
0
      return true;
91
3.17k
  }
92
3.17k
93
3.17k
  if (kind == ObjCRuntime::ObjFW && 
Version > VersionTuple(0, 8)21
)
94
0
    Version = VersionTuple(0, 8);
95
3.17k
96
3.17k
  return false;
97
3.17k
}