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