Coverage Report

Created: 2020-09-22 08:39

/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
3.49k
std::string ObjCRuntime::getAsString() const {
24
3.49k
  std::string Result;
25
3.49k
  {
26
3.49k
    llvm::raw_string_ostream Out(Result);
27
3.49k
    Out << *this;
28
3.49k
  }
29
3.49k
  return Result;
30
3.49k
}
31
32
3.49k
raw_ostream &clang::operator<<(raw_ostream &out, const ObjCRuntime &value) {
33
3.49k
  switch (value.getKind()) {
34
2.69k
  case ObjCRuntime::MacOSX: out << "macosx"; break;
35
12
  case ObjCRuntime::FragileMacOSX: out << "macosx-fragile"; break;
36
16
  case ObjCRuntime::iOS: out << "ios"; break;
37
2
  case ObjCRuntime::WatchOS: out << "watchos"; break;
38
756
  case ObjCRuntime::GNUstep: out << "gnustep"; break;
39
14
  case ObjCRuntime::GCC: out << "gcc"; break;
40
0
  case ObjCRuntime::ObjFW: out << "objfw"; break;
41
3.49k
  }
42
3.49k
  if (value.getVersion() > VersionTuple(0)) {
43
2.72k
    out << '-' << value.getVersion();
44
2.72k
  }
45
3.49k
  return out;
46
3.49k
}
47
48
3.94k
bool ObjCRuntime::tryParse(StringRef input) {
49
  // Look for the last dash.
50
3.94k
  std::size_t dash = input.rfind('-');
51
52
  // We permit dashes in the runtime name, and we also permit the
53
  // version to be omitted, so if we see a dash not followed by a
54
  // digit then we need to ignore it.
55
3.94k
  if (dash != StringRef::npos && 
dash + 1 != input.size()3.05k
&&
56
3.05k
      (input[dash+1] < '0' || input[dash+1] > '9')) {
57
21
    dash = StringRef::npos;
58
21
  }
59
60
  // Everything prior to that must be a valid string name.
61
3.94k
  Kind kind;
62
3.94k
  StringRef runtimeName = input.substr(0, dash);
63
3.94k
  Version = VersionTuple(0);
64
3.94k
  if (runtimeName == "macosx") {
65
2.72k
    kind = ObjCRuntime::MacOSX;
66
1.22k
  } else if (runtimeName == "macosx-fragile") {
67
278
    kind = ObjCRuntime::FragileMacOSX;
68
943
  } else if (runtimeName == "ios") {
69
69
    kind = ObjCRuntime::iOS;
70
874
  } else if (runtimeName == "watchos") {
71
16
    kind = ObjCRuntime::WatchOS;
72
858
  } else if (runtimeName == "gnustep") {
73
    // If no version is specified then default to the most recent one that we
74
    // know about.
75
794
    Version = VersionTuple(1, 6);
76
794
    kind = ObjCRuntime::GNUstep;
77
64
  } else if (runtimeName == "gcc") {
78
43
    kind = ObjCRuntime::GCC;
79
21
  } else if (runtimeName == "objfw") {
80
21
    kind = ObjCRuntime::ObjFW;
81
21
    Version = VersionTuple(0, 8);
82
0
  } else {
83
0
    return true;
84
0
  }
85
3.94k
  TheKind = kind;
86
87
3.94k
  if (dash != StringRef::npos) {
88
3.03k
    StringRef verString = input.substr(dash + 1);
89
3.03k
    if (Version.tryParse(verString))
90
0
      return true;
91
3.94k
  }
92
93
3.94k
  if (kind == ObjCRuntime::ObjFW && 
Version > VersionTuple(0, 8)21
)
94
0
    Version = VersionTuple(0, 8);
95
96
3.94k
  return false;
97
3.94k
}