@@ -620,6 +620,11 @@ template <> struct MappingTraits<const InterfaceFile *> {
620
620
!(Flags & TBDFlags::NotApplicationExtensionSafe));
621
621
}
622
622
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
+
623
628
for (const auto &Section : Exports) {
624
629
const auto Targets =
625
630
synthesizeTargets (Section.Architectures , Platforms);
@@ -634,26 +639,27 @@ template <> struct MappingTraits<const InterfaceFile *> {
634
639
635
640
for (const auto &Symbol : Section.Symbols ) {
636
641
if (Ctx->FileKind != FileType::TBD_V3 &&
637
- Symbol.value .startswith (" _OBJC_EHTYPE_$_ " ))
642
+ Symbol.value .startswith (ObjC2EHTypePrefix ))
638
643
File->addSymbol (SymbolKind::ObjectiveCClassEHType,
639
- Symbol.value .drop_front (15 ), Targets);
644
+ Symbol.value .drop_front (15 ), Targets, Flags );
640
645
else
641
- File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets);
646
+ File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets, Flags );
642
647
}
643
648
for (auto &Symbol : Section.Classes ) {
644
649
auto Name = Symbol.value ;
645
650
if (Ctx->FileKind != FileType::TBD_V3)
646
651
Name = Name.drop_front ();
647
- File->addSymbol (SymbolKind::ObjectiveCClass, Name, Targets);
652
+ File->addSymbol (SymbolKind::ObjectiveCClass, Name, Targets, Flags );
648
653
}
649
654
for (auto &Symbol : Section.ClassEHs )
650
- File->addSymbol (SymbolKind::ObjectiveCClassEHType, Symbol, Targets);
655
+ File->addSymbol (SymbolKind::ObjectiveCClassEHType, Symbol, Targets,
656
+ Flags);
651
657
for (auto &Symbol : Section.IVars ) {
652
658
auto Name = Symbol.value ;
653
659
if (Ctx->FileKind != FileType::TBD_V3)
654
660
Name = Name.drop_front ();
655
- File->addSymbol (SymbolKind::ObjectiveCInstanceVariable, Name,
656
- Targets );
661
+ File->addSymbol (SymbolKind::ObjectiveCInstanceVariable, Name, Targets,
662
+ Flags );
657
663
}
658
664
for (auto &Symbol : Section.WeakDefSymbols )
659
665
File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets,
@@ -668,34 +674,35 @@ template <> struct MappingTraits<const InterfaceFile *> {
668
674
synthesizeTargets (Section.Architectures , Platforms);
669
675
for (auto &Symbol : Section.Symbols ) {
670
676
if (Ctx->FileKind != FileType::TBD_V3 &&
671
- Symbol.value .startswith (" _OBJC_EHTYPE_$_ " ))
677
+ Symbol.value .startswith (ObjC2EHTypePrefix ))
672
678
File->addSymbol (SymbolKind::ObjectiveCClassEHType,
673
679
Symbol.value .drop_front (15 ), Targets,
674
- SymbolFlags::Undefined);
680
+ SymbolFlags::Undefined | Flags );
675
681
else
676
682
File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets,
677
- SymbolFlags::Undefined);
683
+ SymbolFlags::Undefined | Flags );
678
684
}
679
685
for (auto &Symbol : Section.Classes ) {
680
686
auto Name = Symbol.value ;
681
687
if (Ctx->FileKind != FileType::TBD_V3)
682
688
Name = Name.drop_front ();
683
689
File->addSymbol (SymbolKind::ObjectiveCClass, Name, Targets,
684
- SymbolFlags::Undefined);
690
+ SymbolFlags::Undefined | Flags );
685
691
}
686
692
for (auto &Symbol : Section.ClassEHs )
687
693
File->addSymbol (SymbolKind::ObjectiveCClassEHType, Symbol, Targets,
688
- SymbolFlags::Undefined);
694
+ SymbolFlags::Undefined | Flags );
689
695
for (auto &Symbol : Section.IVars ) {
690
696
auto Name = Symbol.value ;
691
697
if (Ctx->FileKind != FileType::TBD_V3)
692
698
Name = Name.drop_front ();
693
699
File->addSymbol (SymbolKind::ObjectiveCInstanceVariable, Name, Targets,
694
- SymbolFlags::Undefined);
700
+ SymbolFlags::Undefined | Flags );
695
701
}
696
702
for (auto &Symbol : Section.WeakRefSymbols )
697
703
File->addSymbol (SymbolKind::GlobalSymbol, Symbol, Targets,
698
- SymbolFlags::Undefined | SymbolFlags::WeakReferenced);
704
+ SymbolFlags::Undefined | SymbolFlags::WeakReferenced |
705
+ Flags);
699
706
}
700
707
701
708
return File;
@@ -906,7 +913,12 @@ template <> struct MappingTraits<const InterfaceFile *> {
906
913
}
907
914
908
915
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
+
910
922
for (const auto &CurrentSection : CurrentSections) {
911
923
for (auto &sym : CurrentSection.Symbols )
912
924
File->addSymbol (SymbolKind::GlobalSymbol, sym,
@@ -924,9 +936,10 @@ template <> struct MappingTraits<const InterfaceFile *> {
924
936
File->addSymbol (SymbolKind::ObjectiveCInstanceVariable, sym,
925
937
CurrentSection.Targets , Flag);
926
938
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;
930
943
for (auto &sym : CurrentSection.WeakSymbols ) {
931
944
File->addSymbol (SymbolKind::GlobalSymbol, sym,
932
945
CurrentSection.Targets , Flag | SymFlag);
@@ -1078,9 +1091,7 @@ static void DiagHandler(const SMDiagnostic &Diag, void *Context) {
1078
1091
File->ErrorMessage = (" malformed file\n " + Message).str ();
1079
1092
}
1080
1093
1081
- namespace {
1082
-
1083
- Expected<FileType> canReadFileType (MemoryBufferRef InputBuffer) {
1094
+ Expected<FileType> TextAPIReader::canRead (MemoryBufferRef InputBuffer) {
1084
1095
auto TAPIFile = InputBuffer.getBuffer ().trim ();
1085
1096
if (TAPIFile.startswith (" {" ) && TAPIFile.endswith (" }" ))
1086
1097
return FileType::TBD_V5;
@@ -1103,13 +1114,12 @@ Expected<FileType> canReadFileType(MemoryBufferRef InputBuffer) {
1103
1114
1104
1115
return createStringError (std::errc::not_supported, " unsupported file type" );
1105
1116
}
1106
- } // namespace
1107
1117
1108
1118
Expected<std::unique_ptr<InterfaceFile>>
1109
1119
TextAPIReader::get (MemoryBufferRef InputBuffer) {
1110
1120
TextAPIContext Ctx;
1111
1121
Ctx.Path = std::string (InputBuffer.getBufferIdentifier ());
1112
- if (auto FTOrErr = canReadFileType (InputBuffer))
1122
+ if (auto FTOrErr = canRead (InputBuffer))
1113
1123
Ctx.FileKind = *FTOrErr;
1114
1124
else
1115
1125
return FTOrErr.takeError ();
@@ -1145,14 +1155,18 @@ TextAPIReader::get(MemoryBufferRef InputBuffer) {
1145
1155
}
1146
1156
1147
1157
Error TextAPIWriter::writeToStream (raw_ostream &OS, const InterfaceFile &File,
1148
- bool Compact) {
1158
+ const FileType FileKind, bool Compact) {
1149
1159
TextAPIContext Ctx;
1150
1160
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;
1152
1166
1153
1167
// Write out in JSON format.
1154
1168
if (Ctx.FileKind >= FileType::TBD_V5) {
1155
- return serializeInterfaceFileToJSON (OS, File, Compact);
1169
+ return serializeInterfaceFileToJSON (OS, File, Ctx. FileKind , Compact);
1156
1170
}
1157
1171
1158
1172
llvm::yaml::Output YAMLOut (OS, &Ctx, /* WrapColumn=*/ 80 );
0 commit comments