@@ -190,7 +190,6 @@ GetMangledName(swift::Demangle::Demangler &dem,
190
190
return mangleNode (global);
191
191
}
192
192
193
- // / Find a Clang type by name in the modules in \p module_holder.
194
193
TypeSP TypeSystemSwiftTypeRef::LookupClangType (StringRef name_ref) {
195
194
llvm::SmallVector<CompilerContext, 2 > decl_context;
196
195
// Make up a decl context for non-nested types.
@@ -199,40 +198,40 @@ TypeSP TypeSystemSwiftTypeRef::LookupClangType(StringRef name_ref) {
199
198
return LookupClangType (name_ref, decl_context);
200
199
}
201
200
202
- // / Find a Clang type by name in the modules in \p module_holder.
203
- TypeSP TypeSystemSwiftTypeRef::LookupClangType (
204
- StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context) {
205
-
201
+ // / Look up one Clang type in a module.
202
+ static TypeSP LookupClangType (Module &m,
203
+ llvm::ArrayRef<CompilerContext> decl_context) {
206
204
TypeQuery query (decl_context, TypeQueryOptions::e_find_one |
207
205
TypeQueryOptions::e_module_search);
208
206
query.SetLanguages (TypeSystemClang::GetSupportedLanguagesForTypes ());
207
+ TypeResults results;
208
+ m.FindTypes (query, results);
209
+ return results.GetFirstType ();
210
+ }
209
211
210
- auto lookup = [&](Module &M) -> TypeSP {
211
- TypeResults results;
212
- M.FindTypes (query, results);
213
- return results.GetFirstType ();
214
- };
212
+ TypeSP TypeSystemSwiftTypeRef::LookupClangType (
213
+ StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context) {
214
+ Module *m = GetModule ();
215
+ if (!m)
216
+ return {};
217
+ return ::LookupClangType (const_cast <Module &>(*m), decl_context);
218
+ }
215
219
220
+ TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType (
221
+ StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context) {
216
222
// Check the cache first. Negative results are also cached.
217
223
TypeSP result;
218
224
ConstString name (name_ref);
219
225
if (m_clang_type_cache.Lookup (name.AsCString (), result))
220
226
return result;
221
227
222
- if (auto *M = GetModule ()) {
223
- TypeSP result = lookup (*M);
224
- // Cache it.
225
- m_clang_type_cache.Insert (name.AsCString (), result);
226
- return result;
227
- }
228
-
229
228
TargetSP target_sp = GetTargetWP ().lock ();
230
229
if (!target_sp)
231
230
return {};
232
- target_sp->GetImages ().ForEach ([&](const ModuleSP &module ) -> bool {
231
+ target_sp->GetImages ().ForEach ([&](const ModuleSP &m ) -> bool {
233
232
// Don't recursively call into LookupClangTypes() to avoid filling
234
233
// hundreds of image caches with negative results.
235
- result = lookup (const_cast <Module &>(*module ) );
234
+ result = :: LookupClangType (const_cast <Module &>(*m), decl_context );
236
235
// Cache it in the expression context.
237
236
if (result)
238
237
m_clang_type_cache.Insert (name.AsCString (), result);
0 commit comments