@@ -258,16 +258,6 @@ struct UUIDv4 {
258258 UUIDv4 (const Target &TargetID, const std::string &Value)
259259 : TargetID(TargetID), Value(Value) {}
260260};
261-
262- // clang-format off
263- enum TBDFlags : unsigned {
264- None = 0U ,
265- FlatNamespace = 1U << 0 ,
266- NotApplicationExtensionSafe = 1U << 1 ,
267- InstallAPI = 1U << 2 ,
268- LLVM_MARK_AS_BITMASK_ENUM (/* LargestValue=*/ InstallAPI),
269- };
270- // clang-format on
271261} // end anonymous namespace.
272262
273263LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR (Architecture)
@@ -1105,10 +1095,49 @@ static void DiagHandler(const SMDiagnostic &Diag, void *Context) {
11051095 File->ErrorMessage = (" malformed file\n " + Message).str ();
11061096}
11071097
1098+ namespace {
1099+
1100+ Expected<FileType> canReadFileType (MemoryBufferRef InputBuffer) {
1101+ auto TAPIFile = InputBuffer.getBuffer ().trim ();
1102+ if (TAPIFile.startswith (" {" ) && TAPIFile.endswith (" }" ))
1103+ return FileType::TBD_V5;
1104+
1105+ if (!TAPIFile.endswith (" ..." ))
1106+ return createStringError (std::errc::not_supported, " unsupported file type" );
1107+
1108+ if (TAPIFile.startswith (" --- !tapi-tbd\n " ))
1109+ return FileType::TBD_V4;
1110+
1111+ if (TAPIFile.startswith (" --- !tapi-tbd-v3\n " ))
1112+ return FileType::TBD_V3;
1113+
1114+ if (TAPIFile.startswith (" --- !tapi-tbd-v2\n " ))
1115+ return FileType::TBD_V2;
1116+
1117+ if (TAPIFile.startswith (" --- !tapi-tbd-v1\n " ) ||
1118+ TAPIFile.startswith (" ---\n archs:" ))
1119+ return FileType::TBD_V1;
1120+
1121+ return createStringError (std::errc::not_supported, " unsupported file type" );
1122+ }
1123+ } // namespace
1124+
11081125Expected<std::unique_ptr<InterfaceFile>>
11091126TextAPIReader::get (MemoryBufferRef InputBuffer) {
11101127 TextAPIContext Ctx;
11111128 Ctx.Path = std::string (InputBuffer.getBufferIdentifier ());
1129+ if (auto FTOrErr = canReadFileType (InputBuffer))
1130+ Ctx.FileKind = *FTOrErr;
1131+ else
1132+ return FTOrErr.takeError ();
1133+
1134+ // Handle JSON Format.
1135+ if (Ctx.FileKind >= FileType::TBD_V5) {
1136+ auto FileOrErr = getInterfaceFileFromJSON (InputBuffer.getBuffer ());
1137+ if (!FileOrErr)
1138+ return FileOrErr.takeError ();
1139+ return std::move (*FileOrErr);
1140+ }
11121141 yaml::Input YAMLIn (InputBuffer.getBuffer (), &Ctx, DiagHandler, &Ctx);
11131142
11141143 // Fill vector with interface file objects created by parsing the YAML file.
0 commit comments