diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-03-27 23:34:16 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-03-27 23:34:16 +0000 |
commit | 78254c8880671f527e5145bc107f0c73e3cd9487 (patch) | |
tree | 567d620bf2b636551cca2ea22e3a91f4917e2e4d /clang/lib/Sema/SemaCodeComplete.cpp | |
parent | 43f340f440388f947e8046375ef4ba79a09edd70 (diff) | |
download | bcm5719-llvm-78254c8880671f527e5145bc107f0c73e3cd9487.tar.gz bcm5719-llvm-78254c8880671f527e5145bc107f0c73e3cd9487.zip |
Introduce a new libclang API to determine the parent context of a code
completion item. For example, if the code completion itself represents
a declaration in a namespace (say, std::vector), then this API
retrieves the cursor kind and name of the namespace (std). Implements
<rdar://problem/11121951>.
llvm-svn: 153545
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index b33c1697bf4..3fd66ec0429 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -2454,6 +2454,13 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, if (Kind == RK_Pattern) { Pattern->Priority = Priority; Pattern->Availability = Availability; + + if (Declaration) { + Result.addParentContext(Declaration->getDeclContext()); + Pattern->ParentKind = Result.getParentKind(); + Pattern->ParentName = Result.getParentName(); + } + return Pattern; } @@ -2509,7 +2516,8 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, assert(Kind == RK_Declaration && "Missed a result kind?"); NamedDecl *ND = Declaration; - + Result.addParentContext(ND->getDeclContext()); + if (StartsNestedNameSpecifier) { Result.AddTypedTextChunk( Result.getAllocator().CopyString(ND->getNameAsString())); @@ -3023,7 +3031,9 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, Builder.AddChunk(CodeCompletionString::CK_RightParen); Results.AddResult(CodeCompletionResult(Builder.TakeString(), CCP_SuperCompletion, - CXCursor_CXXMethod)); + CXCursor_CXXMethod, + CXAvailability_Available, + Overridden)); Results.Ignore(Overridden); } } @@ -3342,28 +3352,8 @@ static void AddObjCProperties(ObjCContainerDecl *Container, Builder.AddTypedTextChunk( Results.getAllocator().CopyString(Name->getName())); - CXAvailabilityKind Availability = CXAvailability_Available; - switch (M->getAvailability()) { - case AR_Available: - case AR_NotYetIntroduced: - Availability = CXAvailability_Available; - break; - - case AR_Deprecated: - Availability = CXAvailability_Deprecated; - break; - - case AR_Unavailable: - Availability = CXAvailability_NotAvailable; - break; - } - - Results.MaybeAddResult(Result(Builder.TakeString(), - CCP_MemberDeclaration + CCD_MethodAsProperty, - M->isInstanceMethod() - ? CXCursor_ObjCInstanceMethodDecl - : CXCursor_ObjCClassMethodDecl, - Availability), + Results.MaybeAddResult(Result(Builder.TakeString(), *M, + CCP_MemberDeclaration + CCD_MethodAsProperty), CurContext); } } @@ -4028,7 +4018,8 @@ void Sema::CodeCompleteNamespaceDecl(Scope *S) { // namespace to the list of results. Results.EnterNewScope(); for (std::map<NamespaceDecl *, NamespaceDecl *>::iterator - NS = OrigToLatest.begin(), NSEnd = OrigToLatest.end(); + NS = OrigToLatest.begin(), + NSEnd = OrigToLatest.end(); NS != NSEnd; ++NS) Results.AddResult(CodeCompletionResult(NS->second, 0), CurContext, 0, false); @@ -4188,7 +4179,9 @@ void Sema::CodeCompleteConstructorInitializer(Decl *ConstructorD, Results.AddResult(CodeCompletionResult(Builder.TakeString(), SawLastInitializer? CCP_NextInitializer : CCP_MemberDeclaration, - CXCursor_MemberRef)); + CXCursor_MemberRef, + CXAvailability_Available, + *Field)); SawLastInitializer = false; } Results.ExitScope(); @@ -5057,10 +5050,8 @@ static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword, } } - Results.AddResult(CodeCompletionResult(Builder.TakeString(), CCP_SuperCompletion, - SuperMethod->isInstanceMethod() - ? CXCursor_ObjCInstanceMethodDecl - : CXCursor_ObjCClassMethodDecl)); + Results.AddResult(CodeCompletionResult(Builder.TakeString(), SuperMethod, + CCP_SuperCompletion)); return SuperMethod; } @@ -6747,10 +6738,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, if (!M->second.second) Priority += CCD_InBaseClass; - Results.AddResult(Result(Builder.TakeString(), Priority, - Method->isInstanceMethod() - ? CXCursor_ObjCInstanceMethodDecl - : CXCursor_ObjCClassMethodDecl)); + Results.AddResult(Result(Builder.TakeString(), Method, Priority)); } // Add Key-Value-Coding and Key-Value-Observing accessor methods for all of |