/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 | 16.3k | std::string ObjCRuntime::getAsString() const { |
24 | 16.3k | std::string Result; |
25 | 16.3k | { |
26 | 16.3k | llvm::raw_string_ostream Out(Result); |
27 | 16.3k | Out << *this; |
28 | 16.3k | } |
29 | 16.3k | return Result; |
30 | 16.3k | } |
31 | | |
32 | 16.3k | raw_ostream &clang::operator<<(raw_ostream &out, const ObjCRuntime &value) { |
33 | 16.3k | switch (value.getKind()) { |
34 | 13.0k | case ObjCRuntime::MacOSX: out << "macosx"; break; |
35 | 568 | case ObjCRuntime::FragileMacOSX: out << "macosx-fragile"; break; |
36 | 145 | case ObjCRuntime::iOS: out << "ios"; break; |
37 | 34 | case ObjCRuntime::WatchOS: out << "watchos"; break; |
38 | 2.37k | case ObjCRuntime::GNUstep: out << "gnustep"; break; |
39 | 126 | case ObjCRuntime::GCC: out << "gcc"; break; |
40 | 42 | case ObjCRuntime::ObjFW: out << "objfw"; break; |
41 | 16.3k | } |
42 | 16.3k | if (value.getVersion() > VersionTuple(0)) { |
43 | 9.84k | out << '-' << value.getVersion(); |
44 | 9.84k | } |
45 | 16.3k | return out; |
46 | 16.3k | } |
47 | | |
48 | 10.3k | bool ObjCRuntime::tryParse(StringRef input) { |
49 | | // Look for the last dash. |
50 | 10.3k | 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 | 10.3k | if (dash != StringRef::npos && dash + 1 != input.size()6.57k && |
56 | 10.3k | (6.57k input[dash+1] < '0'6.57k || input[dash+1] > '9'6.57k )) { |
57 | 42 | dash = StringRef::npos; |
58 | 42 | } |
59 | | |
60 | | // Everything prior to that must be a valid string name. |
61 | 10.3k | Kind kind; |
62 | 10.3k | StringRef runtimeName = input.substr(0, dash); |
63 | 10.3k | Version = VersionTuple(0); |
64 | 10.3k | if (runtimeName == "macosx") { |
65 | 7.80k | kind = ObjCRuntime::MacOSX; |
66 | 7.80k | } else if (2.54k runtimeName == "macosx-fragile"2.54k ) { |
67 | 562 | kind = ObjCRuntime::FragileMacOSX; |
68 | 1.98k | } else if (runtimeName == "ios") { |
69 | 133 | kind = ObjCRuntime::iOS; |
70 | 1.85k | } else if (runtimeName == "watchos") { |
71 | 32 | kind = ObjCRuntime::WatchOS; |
72 | 1.82k | } else if (runtimeName == "gnustep") { |
73 | | // If no version is specified then default to the most recent one that we |
74 | | // know about. |
75 | 1.61k | Version = VersionTuple(1, 6); |
76 | 1.61k | kind = ObjCRuntime::GNUstep; |
77 | 1.61k | } else if (208 runtimeName == "gcc"208 ) { |
78 | 166 | kind = ObjCRuntime::GCC; |
79 | 166 | } else if (42 runtimeName == "objfw"42 ) { |
80 | 42 | kind = ObjCRuntime::ObjFW; |
81 | 42 | Version = VersionTuple(0, 8); |
82 | 42 | } else { |
83 | 0 | return true; |
84 | 0 | } |
85 | 10.3k | TheKind = kind; |
86 | | |
87 | 10.3k | if (dash != StringRef::npos) { |
88 | 6.52k | StringRef verString = input.substr(dash + 1); |
89 | 6.52k | if (Version.tryParse(verString)) |
90 | 0 | return true; |
91 | 6.52k | } |
92 | | |
93 | 10.3k | if (kind == ObjCRuntime::ObjFW && Version > VersionTuple(0, 8)42 ) |
94 | 0 | Version = VersionTuple(0, 8); |
95 | | |
96 | 10.3k | return false; |
97 | 10.3k | } |