@@ -620,6 +620,11 @@ template <> struct MappingTraits<const InterfaceFile *> {
620620 !(Flags & TBDFlags::NotApplicationExtensionSafe));
621621 }
622622
623+ // For older file formats, the segment where the symbol
624+ // comes from is unknown, treat all symbols as Data
625+ // in these cases.
626+ const auto Flags = SymbolFlags::Data;
627+
623628 for (const auto &Section : Exports) {
624629 const auto Targets =
625630 synthesizeTargets (Section.Architectures , Platforms);
@@ -634,26 +639,27 @@ template <> struct MappingTraits<const InterfaceFile *> {
634639
635640 for (const auto &Symbol : Section.Symbols ) {
636641 if (Ctx->FileKind != FileType::TBD_V3 &&
637- Symbol.value .startswith (" _OBJC_EHTYPE_$_ " ))
642+ Symbol.value .startswith (ObjC2EHTypePrefix ))
638643 File->addSymbol (SymbolKind::ObjectiveCClassEHType,
639- Symbol.value .drop_front (15 ), Targets);
644+ Symbol.value .drop_front (15 ), Targets, Flags );
640645 else
641- File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets);
646+ File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets, Flags );
642647 }
643648 for (auto &Symbol : Section.Classes ) {
644649 auto Name = Symbol.value ;
645650 if (Ctx->FileKind != FileType::TBD_V3)
646651 Name = Name.drop_front ();
647- File->addSymbol (SymbolKind::ObjectiveCClass, Name, Targets);
652+ File->addSymbol (SymbolKind::ObjectiveCClass, Name, Targets, Flags );
648653 }
649654 for (auto &Symbol : Section.ClassEHs )
650- File->addSymbol (SymbolKind::ObjectiveCClassEHType, Symbol, Targets);
655+ File->addSymbol (SymbolKind::ObjectiveCClassEHType, Symbol, Targets,
656+ Flags);
651657 for (auto &Symbol : Section.IVars ) {
652658 auto Name = Symbol.value ;
653659 if (Ctx->FileKind != FileType::TBD_V3)
654660 Name = Name.drop_front ();
655- File->addSymbol (SymbolKind::ObjectiveCInstanceVariable, Name,
656- Targets );
661+ File->addSymbol (SymbolKind::ObjectiveCInstanceVariable, Name, Targets,
662+ Flags );
657663 }
658664 for (auto &Symbol : Section.WeakDefSymbols )
659665 File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets,
@@ -668,34 +674,35 @@ template <> struct MappingTraits<const InterfaceFile *> {
668674 synthesizeTargets (Section.Architectures , Platforms);
669675 for (auto &Symbol : Section.Symbols ) {
670676 if (Ctx->FileKind != FileType::TBD_V3 &&
671- Symbol.value .startswith (" _OBJC_EHTYPE_$_ " ))
677+ Symbol.value .startswith (ObjC2EHTypePrefix ))
672678 File->addSymbol (SymbolKind::ObjectiveCClassEHType,
673679 Symbol.value .drop_front (15 ), Targets,
674- SymbolFlags::Undefined);
680+ SymbolFlags::Undefined | Flags );
675681 else
676682 File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets,
677- SymbolFlags::Undefined);
683+ SymbolFlags::Undefined | Flags );
678684 }
679685 for (auto &Symbol : Section.Classes ) {
680686 auto Name = Symbol.value ;
681687 if (Ctx->FileKind != FileType::TBD_V3)
682688 Name = Name.drop_front ();
683689 File->addSymbol (SymbolKind::ObjectiveCClass, Name, Targets,
684- SymbolFlags::Undefined);
690+ SymbolFlags::Undefined | Flags );
685691 }
686692 for (auto &Symbol : Section.ClassEHs )
687693 File->addSymbol (SymbolKind::ObjectiveCClassEHType, Symbol, Targets,
688- SymbolFlags::Undefined);
694+ SymbolFlags::Undefined | Flags );
689695 for (auto &Symbol : Section.IVars ) {
690696 auto Name = Symbol.value ;
691697 if (Ctx->FileKind != FileType::TBD_V3)
692698 Name = Name.drop_front ();
693699 File->addSymbol (SymbolKind::ObjectiveCInstanceVariable, Name, Targets,
694- SymbolFlags::Undefined);
700+ SymbolFlags::Undefined | Flags );
695701 }
696702 for (auto &Symbol : Section.WeakRefSymbols )
697703 File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets,
698- SymbolFlags::Undefined | SymbolFlags::WeakReferenced);
704+ SymbolFlags::Undefined | SymbolFlags::WeakReferenced |
705+ Flags);
699706 }
700707
701708 return File;
@@ -906,7 +913,12 @@ template <> struct MappingTraits<const InterfaceFile *> {
906913 }
907914
908915 auto handleSymbols = [File](const SectionList &CurrentSections,
909- SymbolFlags Flag = SymbolFlags::None) {
916+ SymbolFlags InputFlag = SymbolFlags::None) {
917+ // For older file formats, the segment where the symbol
918+ // comes from is unknown, treat all symbols as Data
919+ // in these cases.
920+ const SymbolFlags Flag = InputFlag | SymbolFlags::Data;
921+
910922 for (const auto &CurrentSection : CurrentSections) {
911923 for (auto &sym : CurrentSection.Symbols )
912924 File->addSymbol (SymbolKind::GlobalSymbol, sym,
@@ -924,9 +936,10 @@ template <> struct MappingTraits<const InterfaceFile *> {
924936 File->addSymbol (SymbolKind::ObjectiveCInstanceVariable, sym,
925937 CurrentSection.Targets , Flag);
926938
927- SymbolFlags SymFlag = (Flag == SymbolFlags::Undefined)
928- ? SymbolFlags::WeakReferenced
929- : SymbolFlags::WeakDefined;
939+ SymbolFlags SymFlag =
940+ ((Flag & SymbolFlags::Undefined) == SymbolFlags::Undefined)
941+ ? SymbolFlags::WeakReferenced
942+ : SymbolFlags::WeakDefined;
930943 for (auto &sym : CurrentSection.WeakSymbols ) {
931944 File->addSymbol (SymbolKind::GlobalSymbol, sym,
932945 CurrentSection.Targets , Flag | SymFlag);
@@ -1078,9 +1091,7 @@ static void DiagHandler(const SMDiagnostic &Diag, void *Context) {
10781091 File->ErrorMessage = (" malformed file\n " + Message).str ();
10791092}
10801093
1081- namespace {
1082-
1083- Expected<FileType> canReadFileType (MemoryBufferRef InputBuffer) {
1094+ Expected<FileType> TextAPIReader::canRead (MemoryBufferRef InputBuffer) {
10841095 auto TAPIFile = InputBuffer.getBuffer ().trim ();
10851096 if (TAPIFile.startswith (" {" ) && TAPIFile.endswith (" }" ))
10861097 return FileType::TBD_V5;
@@ -1103,13 +1114,12 @@ Expected<FileType> canReadFileType(MemoryBufferRef InputBuffer) {
11031114
11041115 return createStringError (std::errc::not_supported, " unsupported file type" );
11051116}
1106- } // namespace
11071117
11081118Expected<std::unique_ptr<InterfaceFile>>
11091119TextAPIReader::get (MemoryBufferRef InputBuffer) {
11101120 TextAPIContext Ctx;
11111121 Ctx.Path = std::string (InputBuffer.getBufferIdentifier ());
1112- if (auto FTOrErr = canReadFileType (InputBuffer))
1122+ if (auto FTOrErr = canRead (InputBuffer))
11131123 Ctx.FileKind = *FTOrErr;
11141124 else
11151125 return FTOrErr.takeError ();
@@ -1145,14 +1155,18 @@ TextAPIReader::get(MemoryBufferRef InputBuffer) {
11451155}
11461156
11471157Error TextAPIWriter::writeToStream (raw_ostream &OS, const InterfaceFile &File,
1148- bool Compact) {
1158+ const FileType FileKind, bool Compact) {
11491159 TextAPIContext Ctx;
11501160 Ctx.Path = std::string (File.getPath ());
1151- Ctx.FileKind = File.getFileType ();
1161+
1162+ // Prefer parameter for format if passed, otherwise fallback to the File
1163+ // FileType.
1164+ Ctx.FileKind =
1165+ (FileKind == FileType::Invalid) ? File.getFileType () : FileKind;
11521166
11531167 // Write out in JSON format.
11541168 if (Ctx.FileKind >= FileType::TBD_V5) {
1155- return serializeInterfaceFileToJSON (OS, File, Compact);
1169+ return serializeInterfaceFileToJSON (OS, File, Ctx. FileKind , Compact);
11561170 }
11571171
11581172 llvm::yaml::Output YAMLOut (OS, &Ctx, /* WrapColumn=*/ 80 );
0 commit comments