2018-03-29 06:09:09 +08:00
|
|
|
//===- ObjCRuntime.cpp - Objective-C Runtime Handling ---------------------===//
|
2012-06-20 14:18:46 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-06-20 14:18:46 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the ObjCRuntime class, which represents the
|
|
|
|
// target Objective-C runtime.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2018-03-29 06:09:09 +08:00
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
#include "clang/Basic/ObjCRuntime.h"
|
2018-03-29 06:09:09 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-06-11 18:28:04 +08:00
|
|
|
#include "llvm/Support/VersionTuple.h"
|
2012-06-20 14:18:46 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2018-03-29 06:09:09 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <string>
|
2012-06-20 14:18:46 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
std::string ObjCRuntime::getAsString() const {
|
|
|
|
std::string Result;
|
|
|
|
{
|
|
|
|
llvm::raw_string_ostream Out(Result);
|
|
|
|
Out << *this;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
return Result;
|
2012-06-20 14:18:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
raw_ostream &clang::operator<<(raw_ostream &out, const ObjCRuntime &value) {
|
|
|
|
switch (value.getKind()) {
|
|
|
|
case ObjCRuntime::MacOSX: out << "macosx"; break;
|
|
|
|
case ObjCRuntime::FragileMacOSX: out << "macosx-fragile"; break;
|
|
|
|
case ObjCRuntime::iOS: out << "ios"; break;
|
2015-10-31 00:30:36 +08:00
|
|
|
case ObjCRuntime::WatchOS: out << "watchos"; break;
|
2012-07-04 04:49:52 +08:00
|
|
|
case ObjCRuntime::GNUstep: out << "gnustep"; break;
|
|
|
|
case ObjCRuntime::GCC: out << "gcc"; break;
|
2012-07-12 10:07:58 +08:00
|
|
|
case ObjCRuntime::ObjFW: out << "objfw"; break;
|
2012-06-20 14:18:46 +08:00
|
|
|
}
|
|
|
|
if (value.getVersion() > VersionTuple(0)) {
|
|
|
|
out << '-' << value.getVersion();
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjCRuntime::tryParse(StringRef input) {
|
|
|
|
// Look for the last dash.
|
|
|
|
std::size_t dash = input.rfind('-');
|
|
|
|
|
2012-06-21 05:58:02 +08:00
|
|
|
// We permit dashes in the runtime name, and we also permit the
|
|
|
|
// version to be omitted, so if we see a dash not followed by a
|
|
|
|
// digit then we need to ignore it.
|
2012-06-20 14:18:46 +08:00
|
|
|
if (dash != StringRef::npos && dash + 1 != input.size() &&
|
|
|
|
(input[dash+1] < '0' || input[dash+1] > '9')) {
|
|
|
|
dash = StringRef::npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Everything prior to that must be a valid string name.
|
|
|
|
Kind kind;
|
|
|
|
StringRef runtimeName = input.substr(0, dash);
|
2012-07-04 18:37:03 +08:00
|
|
|
Version = VersionTuple(0);
|
2012-06-20 14:18:46 +08:00
|
|
|
if (runtimeName == "macosx") {
|
|
|
|
kind = ObjCRuntime::MacOSX;
|
|
|
|
} else if (runtimeName == "macosx-fragile") {
|
|
|
|
kind = ObjCRuntime::FragileMacOSX;
|
|
|
|
} else if (runtimeName == "ios") {
|
|
|
|
kind = ObjCRuntime::iOS;
|
2015-10-31 00:30:36 +08:00
|
|
|
} else if (runtimeName == "watchos") {
|
|
|
|
kind = ObjCRuntime::WatchOS;
|
2012-07-04 04:49:52 +08:00
|
|
|
} else if (runtimeName == "gnustep") {
|
2012-07-04 18:37:03 +08:00
|
|
|
// If no version is specified then default to the most recent one that we
|
|
|
|
// know about.
|
|
|
|
Version = VersionTuple(1, 6);
|
2012-07-04 04:49:52 +08:00
|
|
|
kind = ObjCRuntime::GNUstep;
|
|
|
|
} else if (runtimeName == "gcc") {
|
|
|
|
kind = ObjCRuntime::GCC;
|
2012-07-12 10:07:58 +08:00
|
|
|
} else if (runtimeName == "objfw") {
|
|
|
|
kind = ObjCRuntime::ObjFW;
|
2013-09-17 00:31:49 +08:00
|
|
|
Version = VersionTuple(0, 8);
|
2012-06-20 14:18:46 +08:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
TheKind = kind;
|
2013-09-17 00:31:49 +08:00
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
if (dash != StringRef::npos) {
|
|
|
|
StringRef verString = input.substr(dash + 1);
|
2013-09-17 00:31:49 +08:00
|
|
|
if (Version.tryParse(verString))
|
2012-06-20 14:18:46 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-17 00:31:49 +08:00
|
|
|
if (kind == ObjCRuntime::ObjFW && Version > VersionTuple(0, 8))
|
|
|
|
Version = VersionTuple(0, 8);
|
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
return false;
|
|
|
|
}
|