diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-02-19 16:08:35 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-02-19 16:08:35 +0000 |
commit | 337caf9e3e19444a658db6febd1ff697febaa745 (patch) | |
tree | 73d632d8683c6f1d4ab6bf99c76bc5844ce428ba /clang/lib/Sema/SemaLookup.cpp | |
parent | cfd70242ca544c0738fabc55d17ace9fc1d5a7b9 (diff) | |
download | bcm5719-llvm-337caf9e3e19444a658db6febd1ff697febaa745.tar.gz bcm5719-llvm-337caf9e3e19444a658db6febd1ff697febaa745.zip |
Implement C++ name lookup for instance variables of Objective-C classes
from an instance method. Previously, we were following the Objective-C
name lookup rules for ivars, which are of course completely different
from and incompatible with the Objective-C++ rules.
For the record, the Objective-C++ rules are the sane ones.
This is another part of <rdar://problem/7660386>.
llvm-svn: 96677
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index c7569d6eda2..8d93eed0dcf 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -644,14 +644,37 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) { DeclContext *OuterCtx = findOuterContext(S); for (; Ctx && Ctx->getPrimaryContext() != OuterCtx; Ctx = Ctx->getLookupParent()) { - // We do not directly look into function or method contexts - // (since all local variables are found via the identifier - // changes) or in transparent contexts (since those entities - // will be found in the nearest enclosing non-transparent - // context). - if (Ctx->isFunctionOrMethod() || Ctx->isTransparentContext()) + // We do not directly look into transparent contexts, since + // those entities will be found in the nearest enclosing + // non-transparent context. + if (Ctx->isTransparentContext()) continue; - + + // We do not look directly into function or method contexts, + // since all of the local variables and parameters of the + // function/method are present within the Scope. + if (Ctx->isFunctionOrMethod()) { + // If we have an Objective-C instance method, look for ivars + // in the corresponding interface. + if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(Ctx)) { + if (Method->isInstanceMethod() && Name.getAsIdentifierInfo()) + if (ObjCInterfaceDecl *Class = Method->getClassInterface()) { + ObjCInterfaceDecl *ClassDeclared; + if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable( + Name.getAsIdentifierInfo(), + ClassDeclared)) { + if (R.isAcceptableDecl(Ivar)) { + R.addDecl(Ivar); + R.resolveKind(); + return true; + } + } + } + } + + continue; + } + // Perform qualified name lookup into this context. // FIXME: In some cases, we know that every name that could be found by // this qualified name lookup will also be on the identifier chain. For |