@@ -219,7 +219,7 @@ bool SwiftLookupTable::contextRequiresName(ContextKind kind) {
219
219
220
220
// / Try to translate the given Clang declaration into a context.
221
221
static std::optional<SwiftLookupTable::StoredContext>
222
- translateDeclToContext (clang::NamedDecl *decl) {
222
+ translateDeclToContext (const clang::NamedDecl *decl) {
223
223
// Tag declaration.
224
224
if (auto tag = dyn_cast<clang::TagDecl>(decl)) {
225
225
if (tag->getIdentifier ())
@@ -324,22 +324,46 @@ SwiftLookupTable::translateContext(EffectiveClangContext context) {
324
324
325
325
// / Lookup an unresolved context name and resolve it to a Clang
326
326
// / declaration context or typedef name.
327
- clang::NamedDecl *SwiftLookupTable::resolveContext (StringRef unresolvedName) {
327
+ const clang::NamedDecl *
328
+ SwiftLookupTable::resolveContext (StringRef unresolvedName) {
329
+ SmallVector<StringRef, 1 > nameComponents;
330
+ unresolvedName.split (nameComponents, ' .' );
331
+
332
+ EffectiveClangContext parentContext;
333
+
328
334
// Look for a context with the given Swift name.
329
- for (auto entry :
330
- lookup (SerializedSwiftName (unresolvedName),
331
- std::make_pair (ContextKind::TranslationUnit, StringRef ()))) {
332
- if (auto decl = entry.dyn_cast <clang::NamedDecl *>()) {
333
- if (isa<clang::TagDecl>(decl) ||
334
- isa<clang::ObjCInterfaceDecl>(decl) ||
335
- isa<clang::TypedefNameDecl>(decl))
336
- return decl;
335
+ for (auto nameComponent : nameComponents) {
336
+ auto entries =
337
+ parentContext
338
+ ? lookup (SerializedSwiftName (nameComponent), parentContext)
339
+ : lookup (SerializedSwiftName (nameComponent),
340
+ std::make_pair (ContextKind::TranslationUnit, StringRef ()));
341
+ bool entryFound = false ;
342
+ for (auto entry : entries) {
343
+ if (auto decl = entry.dyn_cast <clang::NamedDecl *>()) {
344
+ if (isa<clang::TagDecl>(decl) ||
345
+ isa<clang::ObjCInterfaceDecl>(decl) ||
346
+ isa<clang::NamespaceDecl>(decl)) {
347
+ entryFound = true ;
348
+ parentContext = EffectiveClangContext (cast<clang::DeclContext>(decl));
349
+ break ;
350
+ }
351
+ if (auto typedefDecl = dyn_cast<clang::TypedefNameDecl>(decl)) {
352
+ entryFound = true ;
353
+ parentContext = EffectiveClangContext (typedefDecl);
354
+ break ;
355
+ }
356
+ }
337
357
}
338
- }
339
358
340
- // FIXME: Search imported modules to resolve the context.
359
+ // If we could not resolve this component of the qualified name, bail.
360
+ if (!entryFound)
361
+ return nullptr ;
362
+ }
341
363
342
- return nullptr ;
364
+ return parentContext.getAsDeclContext ()
365
+ ? cast<clang::NamedDecl>(parentContext.getAsDeclContext ())
366
+ : parentContext.getTypedefName ();
343
367
}
344
368
345
369
void SwiftLookupTable::addCategory (clang::ObjCCategoryDecl *category) {
0 commit comments