Path: blob/main/contrib/llvm-project/clang/lib/Basic/ObjCRuntime.cpp
35233 views
//===- ObjCRuntime.cpp - Objective-C Runtime Handling ---------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the ObjCRuntime class, which represents the9// target Objective-C runtime.10//11//===----------------------------------------------------------------------===//1213#include "clang/Basic/ObjCRuntime.h"14#include "llvm/ADT/StringRef.h"15#include "llvm/Support/VersionTuple.h"16#include "llvm/Support/raw_ostream.h"17#include <cstddef>18#include <string>1920using namespace clang;2122std::string ObjCRuntime::getAsString() const {23std::string Result;24{25llvm::raw_string_ostream Out(Result);26Out << *this;27}28return Result;29}3031raw_ostream &clang::operator<<(raw_ostream &out, const ObjCRuntime &value) {32switch (value.getKind()) {33case ObjCRuntime::MacOSX: out << "macosx"; break;34case ObjCRuntime::FragileMacOSX: out << "macosx-fragile"; break;35case ObjCRuntime::iOS: out << "ios"; break;36case ObjCRuntime::WatchOS: out << "watchos"; break;37case ObjCRuntime::GNUstep: out << "gnustep"; break;38case ObjCRuntime::GCC: out << "gcc"; break;39case ObjCRuntime::ObjFW: out << "objfw"; break;40}41if (value.getVersion() > VersionTuple(0)) {42out << '-' << value.getVersion();43}44return out;45}4647bool ObjCRuntime::tryParse(StringRef input) {48// Look for the last dash.49std::size_t dash = input.rfind('-');5051// We permit dashes in the runtime name, and we also permit the52// version to be omitted, so if we see a dash not followed by a53// digit then we need to ignore it.54if (dash != StringRef::npos && dash + 1 != input.size() &&55(input[dash+1] < '0' || input[dash+1] > '9')) {56dash = StringRef::npos;57}5859// Everything prior to that must be a valid string name.60Kind kind;61StringRef runtimeName = input.substr(0, dash);62Version = VersionTuple(0);63if (runtimeName == "macosx") {64kind = ObjCRuntime::MacOSX;65} else if (runtimeName == "macosx-fragile") {66kind = ObjCRuntime::FragileMacOSX;67} else if (runtimeName == "ios") {68kind = ObjCRuntime::iOS;69} else if (runtimeName == "watchos") {70kind = ObjCRuntime::WatchOS;71} else if (runtimeName == "gnustep") {72// If no version is specified then default to the most recent one that we73// know about.74Version = VersionTuple(1, 6);75kind = ObjCRuntime::GNUstep;76} else if (runtimeName == "gcc") {77kind = ObjCRuntime::GCC;78} else if (runtimeName == "objfw") {79kind = ObjCRuntime::ObjFW;80Version = VersionTuple(0, 8);81} else {82return true;83}84TheKind = kind;8586if (dash != StringRef::npos) {87StringRef verString = input.substr(dash + 1);88if (Version.tryParse(verString))89return true;90}9192if (kind == ObjCRuntime::ObjFW && Version > VersionTuple(0, 8))93Version = VersionTuple(0, 8);9495return false;96}979899