@@ -1053,6 +1053,63 @@ void TBDGenVisitor::visit(Decl *D) {
1053
1053
ASTVisitor::visit (D);
1054
1054
}
1055
1055
1056
+ static bool hasLinkerDirective (Decl *D) {
1057
+ return !getAllMovedPlatformVersions (D).empty ();
1058
+ }
1059
+
1060
+ void TBDGenVisitor::visitFile (FileUnit *file) {
1061
+ if (file == SwiftModule->getFiles ()[0 ])
1062
+ addFirstFileSymbols ();
1063
+
1064
+ SmallVector<Decl *, 16 > decls;
1065
+ file->getTopLevelDecls (decls);
1066
+
1067
+ addMainIfNecessary (file);
1068
+
1069
+ for (auto d : decls) {
1070
+ if (Opts.LinkerDirectivesOnly && !hasLinkerDirective (d))
1071
+ continue ;
1072
+ visit (d);
1073
+ }
1074
+ }
1075
+
1076
+ void TBDGenVisitor::visit (const TBDGenDescriptor &desc) {
1077
+ if (auto *singleFile = desc.getSingleFile ()) {
1078
+ assert (SwiftModule == singleFile->getParentModule () &&
1079
+ " mismatched file and module" );
1080
+ visitFile (singleFile);
1081
+
1082
+ // Visit synthesized file, if it exists.
1083
+ if (auto *SF = dyn_cast<SourceFile>(singleFile)) {
1084
+ if (auto *synthesizedFile = SF->getSynthesizedFile ())
1085
+ visitFile (synthesizedFile);
1086
+ }
1087
+ return ;
1088
+ }
1089
+
1090
+ llvm::SmallVector<ModuleDecl*, 4 > Modules;
1091
+ Modules.push_back (SwiftModule);
1092
+
1093
+ auto &ctx = SwiftModule->getASTContext ();
1094
+ for (auto Name: Opts.embedSymbolsFromModules ) {
1095
+ if (auto *MD = ctx.getModuleByName (Name)) {
1096
+ // If it is a clang module, the symbols should be collected by TAPI.
1097
+ if (!MD->isNonSwiftModule ()) {
1098
+ Modules.push_back (MD);
1099
+ continue ;
1100
+ }
1101
+ }
1102
+ // Diagnose module name that cannot be found
1103
+ ctx.Diags .diagnose (SourceLoc (), diag::unknown_swift_module_name, Name);
1104
+ }
1105
+ // Collect symbols in each module.
1106
+ llvm::for_each (Modules, [&](ModuleDecl *M) {
1107
+ for (auto *file : M->getFiles ()) {
1108
+ visitFile (file);
1109
+ }
1110
+ });
1111
+ }
1112
+
1056
1113
// / The kind of version being parsed, used for diagnostics.
1057
1114
// / Note: Must match the order in DiagnosticsFrontend.def
1058
1115
enum DylibVersionKind_t: unsigned {
@@ -1100,10 +1157,6 @@ static bool isApplicationExtensionSafe(const LangOptions &LangOpts) {
1100
1157
llvm::sys::Process::GetEnv (" LD_APPLICATION_EXTENSION_SAFE" );
1101
1158
}
1102
1159
1103
- static bool hasLinkerDirective (Decl *D) {
1104
- return !getAllMovedPlatformVersions (D).empty ();
1105
- }
1106
-
1107
1160
TBDFileAndSymbols
1108
1161
GenerateTBDRequest::evaluate (Evaluator &evaluator,
1109
1162
TBDGenDescriptor desc) const {
@@ -1144,53 +1197,7 @@ GenerateTBDRequest::evaluate(Evaluator &evaluator,
1144
1197
auto *clang = static_cast <ClangImporter *>(ctx.getClangModuleLoader ());
1145
1198
TBDGenVisitor visitor (file, {target}, clang->getTargetInfo ().getDataLayout (),
1146
1199
linkInfo, M, opts);
1147
-
1148
- auto visitFile = [&](FileUnit *file) {
1149
- if (file == M->getFiles ()[0 ]) {
1150
- visitor.addFirstFileSymbols ();
1151
- }
1152
-
1153
- SmallVector<Decl *, 16 > decls;
1154
- file->getTopLevelDecls (decls);
1155
-
1156
- visitor.addMainIfNecessary (file);
1157
-
1158
- for (auto d : decls) {
1159
- if (opts.LinkerDirectivesOnly && !hasLinkerDirective (d))
1160
- continue ;
1161
- visitor.visit (d);
1162
- }
1163
- };
1164
-
1165
- if (auto *singleFile = desc.getSingleFile ()) {
1166
- assert (M == singleFile->getParentModule () && " mismatched file and module" );
1167
- visitFile (singleFile);
1168
- // Visit synthesized file, if it exists.
1169
- if (auto *SF = dyn_cast<SourceFile>(singleFile))
1170
- if (auto *synthesizedFile = SF->getSynthesizedFile ())
1171
- visitFile (synthesizedFile);
1172
- } else {
1173
- llvm::SmallVector<ModuleDecl*, 4 > Modules;
1174
- Modules.push_back (M);
1175
- for (auto Name: opts.embedSymbolsFromModules ) {
1176
- if (auto *MD = ctx.getModuleByName (Name)) {
1177
- // If it is a clang module, the symbols should be collected by TAPI.
1178
- if (!MD->isNonSwiftModule ()) {
1179
- Modules.push_back (MD);
1180
- continue ;
1181
- }
1182
- }
1183
- // Diagnose module name that cannot be found
1184
- ctx.Diags .diagnose (SourceLoc (), diag::unknown_swift_module_name, Name);
1185
- }
1186
- // Collect symbols in each module.
1187
- llvm::for_each (Modules, [&](ModuleDecl *M) {
1188
- for (auto *file : M->getFiles ()) {
1189
- visitFile (file);
1190
- }
1191
- });
1192
- }
1193
-
1200
+ visitor.visit (desc);
1194
1201
return std::make_pair (std::move (file), std::move (visitor.StringSymbols ));
1195
1202
}
1196
1203
0 commit comments