#include "TextStubCommon.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/JSON.h"
#include <utility>
usingnamespacellvm;
usingnamespacellvm::json;
usingnamespacellvm::MachO;
namespace {
struct JSONSymbol { … };
AttrToTargets;
TargetsToSymbols;
enum TBDKey : size_t { … };
std::array<StringRef, 64> Keys = …;
static llvm::SmallString<128> getParseErrorMsg(TBDKey Key) { … }
static llvm::SmallString<128> getSerializeErrorMsg(TBDKey Key) { … }
class JSONStubError : public llvm::ErrorInfo<llvm::json::ParseError> { … };
template <typename JsonT, typename StubT = JsonT>
Expected<StubT> getRequiredValue(
TBDKey Key, const Object *Obj,
std::function<std::optional<JsonT>(const Object *, StringRef)> GetValue,
std::function<std::optional<StubT>(JsonT)> Validate = nullptr) { … }
template <typename JsonT, typename StubT = JsonT>
Expected<StubT> getRequiredValue(
TBDKey Key, const Object *Obj,
std::function<std::optional<JsonT>(const Object *, StringRef)> const
GetValue,
StubT DefaultValue, function_ref<std::optional<StubT>(JsonT)> Validate) { … }
Error collectFromArray(TBDKey Key, const Object *Obj,
function_ref<void(StringRef)> Append,
bool IsRequired = false) { … }
namespace StubParser {
Expected<FileType> getVersion(const Object *File) { … }
Expected<TargetList> getTargets(const Object *Section) { … }
Expected<TargetList> getTargetsSection(const Object *Section) { … }
Error collectSymbolsFromSegment(const Object *Segment, TargetsToSymbols &Result,
SymbolFlags SectionFlag) { … }
Expected<StringRef> getNameSection(const Object *File) { … }
Expected<TargetsToSymbols> getSymbolSection(const Object *File, TBDKey Key,
TargetList &Targets) { … }
Expected<AttrToTargets> getLibSection(const Object *File, TBDKey Key,
TBDKey SubKey,
const TargetList &Targets) { … }
Expected<AttrToTargets> getUmbrellaSection(const Object *File,
const TargetList &Targets) { … }
Expected<uint8_t> getSwiftVersion(const Object *File) { … }
Expected<PackedVersion> getPackedVersion(const Object *File, TBDKey Key) { … }
Expected<TBDFlags> getFlags(const Object *File) { … }
IFPtr;
Expected<IFPtr> parseToInterfaceFile(const Object *File) { … }
Expected<std::vector<IFPtr>> getInlinedLibs(const Object *File) { … }
}
}
Expected<std::unique_ptr<InterfaceFile>>
MachO::getInterfaceFileFromJSON(StringRef JSON) { … }
namespace {
template <typename ContainerT = Array>
bool insertNonEmptyValues(Object &Obj, TBDKey Key, ContainerT &&Contents) { … }
std::string getFormattedStr(const MachO::Target &Targ) { … }
template <typename AggregateT>
std::vector<std::string> serializeTargets(const AggregateT Targets,
const TargetList &ActiveTargets) { … }
Array serializeTargetInfo(const TargetList &ActiveTargets) { … }
template <typename ValueT, typename EntryT = ValueT>
Array serializeScalar(TBDKey Key, ValueT Value, ValueT Default = ValueT()) { … }
TargetsToValuesMap;
template <typename AggregateT = TargetsToValuesMap>
Array serializeAttrToTargets(AggregateT &Entries, TBDKey Key) { … }
template <typename ValueT = std::string,
typename AggregateT = std::vector<std::pair<MachO::Target, ValueT>>>
Array serializeField(TBDKey Key, const AggregateT &Values,
const TargetList &ActiveTargets, bool IsArray = true) { … }
Array serializeField(TBDKey Key, const std::vector<InterfaceFileRef> &Values,
const TargetList &ActiveTargets) { … }
struct SymbolFields { … };
Array serializeSymbols(InterfaceFile::const_filtered_symbol_range Symbols,
const TargetList &ActiveTargets) { … }
Array serializeFlags(const InterfaceFile *File) { … }
Expected<Object> serializeIF(const InterfaceFile *File) { … }
Expected<Object> getJSON(const InterfaceFile *File, const FileType FileKind) { … }
}
Error MachO::serializeInterfaceFileToJSON(raw_ostream &OS,
const InterfaceFile &File,
const FileType FileKind,
bool Compact) { … }