diff options
author | Cyndy Ishida <cyndy_ishida@apple.com> | 2023-02-17 15:58:04 -0800 |
---|---|---|
committer | Cyndy Ishida <cyndy_ishida@apple.com> | 2023-02-17 16:03:01 -0800 |
commit | b861b1225380175a5a724e2a677754f5f74e5b0d (patch) | |
tree | 971375059ea640b7f2268f4feb3b10ed4958b2f3 /llvm/lib/TextAPI/TextStub.cpp | |
parent | b309bc04eebc9c736b6c34d73d520a6ef7baf302 (diff) | |
download | llvm-b861b1225380175a5a724e2a677754f5f74e5b0d.zip llvm-b861b1225380175a5a724e2a677754f5f74e5b0d.tar.gz llvm-b861b1225380175a5a724e2a677754f5f74e5b0d.tar.bz2 |
[TextAPI] Implement TBDv5 Reader
[TextAPI] Implement TBDv5 Reader
Introduce initial reader for TBDv5 which is in JSON. This captures all
the currently understood fields within the internal structure
`InterfaceFile`.
New fields & follow up tests will be followed up in future PRs.
Reviewed By: pete
Differential Revision: https://reviews.llvm.org/D144156
Diffstat (limited to 'llvm/lib/TextAPI/TextStub.cpp')
-rw-r--r-- | llvm/lib/TextAPI/TextStub.cpp | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/llvm/lib/TextAPI/TextStub.cpp b/llvm/lib/TextAPI/TextStub.cpp index ff93e43..73cb614 100644 --- a/llvm/lib/TextAPI/TextStub.cpp +++ b/llvm/lib/TextAPI/TextStub.cpp @@ -258,16 +258,6 @@ struct UUIDv4 { UUIDv4(const Target &TargetID, const std::string &Value) : TargetID(TargetID), Value(Value) {} }; - -// clang-format off -enum TBDFlags : unsigned { - None = 0U, - FlatNamespace = 1U << 0, - NotApplicationExtensionSafe = 1U << 1, - InstallAPI = 1U << 2, - LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/InstallAPI), -}; -// clang-format on } // end anonymous namespace. LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(Architecture) @@ -1105,10 +1095,49 @@ static void DiagHandler(const SMDiagnostic &Diag, void *Context) { File->ErrorMessage = ("malformed file\n" + Message).str(); } +namespace { + +Expected<FileType> canReadFileType(MemoryBufferRef InputBuffer) { + auto TAPIFile = InputBuffer.getBuffer().trim(); + if (TAPIFile.startswith("{") && TAPIFile.endswith("}")) + return FileType::TBD_V5; + + if (!TAPIFile.endswith("...")) + return createStringError(std::errc::not_supported, "unsupported file type"); + + if (TAPIFile.startswith("--- !tapi-tbd\n")) + return FileType::TBD_V4; + + if (TAPIFile.startswith("--- !tapi-tbd-v3\n")) + return FileType::TBD_V3; + + if (TAPIFile.startswith("--- !tapi-tbd-v2\n")) + return FileType::TBD_V2; + + if (TAPIFile.startswith("--- !tapi-tbd-v1\n") || + TAPIFile.startswith("---\narchs:")) + return FileType::TBD_V1; + + return createStringError(std::errc::not_supported, "unsupported file type"); +} +} // namespace + Expected<std::unique_ptr<InterfaceFile>> TextAPIReader::get(MemoryBufferRef InputBuffer) { TextAPIContext Ctx; Ctx.Path = std::string(InputBuffer.getBufferIdentifier()); + if (auto FTOrErr = canReadFileType(InputBuffer)) + Ctx.FileKind = *FTOrErr; + else + return FTOrErr.takeError(); + + // Handle JSON Format. + if (Ctx.FileKind >= FileType::TBD_V5) { + auto FileOrErr = getInterfaceFileFromJSON(InputBuffer.getBuffer()); + if (!FileOrErr) + return FileOrErr.takeError(); + return std::move(*FileOrErr); + } yaml::Input YAMLIn(InputBuffer.getBuffer(), &Ctx, DiagHandler, &Ctx); // Fill vector with interface file objects created by parsing the YAML file. |