Coverage Report

Created: 2019-07-24 05:18

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