@@ -816,7 +816,11 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
816
816
return false ;
817
817
}
818
818
819
+ const static unsigned OBJC_METHOD_TRACE_FILE_FORMAT_VERSION = 1 ;
820
+
819
821
class ObjcMethodReferenceCollector : public SourceEntityWalker {
822
+ std::string target;
823
+ std::string targetVariant;
820
824
StringRef visitingFilePath;
821
825
llvm::DenseSet<const clang::ObjCMethodDecl*> results;
822
826
bool visitDeclReference (ValueDecl *D, CharSourceRange Range,
@@ -847,31 +851,43 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
847
851
return " type" ;
848
852
}
849
853
public:
854
+ ObjcMethodReferenceCollector (ModuleDecl *MD) {
855
+ auto &Opts = MD->getASTContext ().LangOpts ;
856
+ target = Opts.Target .str ();
857
+ targetVariant = Opts.TargetVariant .has_value () ?
858
+ Opts.TargetVariant ->str () : " " ;
859
+ }
850
860
void setFileBeforeVisiting (SourceFile *SF) {
851
861
assert (SF && " need to visit actual source files" );
852
862
visitingFilePath = SF->getFilename ();
853
863
}
854
864
void serializeAsJson (llvm::raw_ostream &OS) {
855
865
llvm::json::OStream out (OS, /* IndentSize=*/ 4 );
856
- out.array ([&] {
857
- for (const clang::ObjCMethodDecl* clangD: results) {
858
- auto &SM = clangD->getASTContext ().getSourceManager ();
859
- clang::SourceLocation Loc = clangD->getLocation ();
860
- if (!Loc.isValid ()) {
861
- continue ;
862
- }
863
- out.object ([&] {
864
- if (auto *parent = dyn_cast_or_null<clang::NamedDecl>(clangD
865
- ->getParent ())) {
866
- auto pName = parent->getName ();
867
- if (!pName.empty ())
868
- out.attribute (selectMethodOwnerKey (parent), pName);
866
+ out.object ([&] {
867
+ out.attribute (" format-vesion" , OBJC_METHOD_TRACE_FILE_FORMAT_VERSION);
868
+ out.attribute (" target" , target);
869
+ if (!targetVariant.empty ())
870
+ out.attribute (" target-variant" , targetVariant);
871
+ out.attributeArray (" references" , [&] {
872
+ for (const clang::ObjCMethodDecl* clangD: results) {
873
+ auto &SM = clangD->getASTContext ().getSourceManager ();
874
+ clang::SourceLocation Loc = clangD->getLocation ();
875
+ if (!Loc.isValid ()) {
876
+ continue ;
869
877
}
870
- out.attribute (selectMethodKey (clangD), clangD->getNameAsString ());
871
- out.attribute (" declared_at" , Loc.printToString (SM));
872
- out.attribute (" referenced_at" , visitingFilePath);
873
- });
874
- }
878
+ out.object ([&] {
879
+ if (auto *parent = dyn_cast_or_null<clang::NamedDecl>(clangD
880
+ ->getParent ())) {
881
+ auto pName = parent->getName ();
882
+ if (!pName.empty ())
883
+ out.attribute (selectMethodOwnerKey (parent), pName);
884
+ }
885
+ out.attribute (selectMethodKey (clangD), clangD->getNameAsString ());
886
+ out.attribute (" declared_at" , Loc.printToString (SM));
887
+ out.attribute (" referenced_at" , visitingFilePath);
888
+ });
889
+ }
890
+ });
875
891
});
876
892
}
877
893
};
@@ -900,7 +916,7 @@ bool swift::emitObjCMessageSendTraceIfNeeded(ModuleDecl *mainModule,
900
916
}
901
917
// Write the contents of the buffer.
902
918
llvm::raw_fd_ostream out (tmpFD, /* shouldClose=*/ true );
903
- ObjcMethodReferenceCollector collector;
919
+ ObjcMethodReferenceCollector collector (mainModule) ;
904
920
for (auto *FU : mainModule->getFiles ()) {
905
921
if (auto *SF = dyn_cast<SourceFile>(FU)) {
906
922
collector.setFileBeforeVisiting (SF);
0 commit comments