diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-23 00:16:58 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-23 00:16:58 +0000 |
commit | 05f477c1779edd30cc472824b8e2924fcdc9e122 (patch) | |
tree | eff0ec0d88527fbf0d97b5144eb090399ef39f69 /clang/lib/Sema | |
parent | 8808063181dd392a5dbdf468001fb7305f5ab637 (diff) | |
download | bcm5719-llvm-05f477c1779edd30cc472824b8e2924fcdc9e122.tar.gz bcm5719-llvm-05f477c1779edd30cc472824b8e2924fcdc9e122.zip |
Separate the code-completion results for call completion from the
results for other, textual completion. For call completion, we now
produce enough information to show the function call argument that we
are currently on.
llvm-svn: 82592
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/CodeCompleteConsumer.cpp | 64 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 12 |
2 files changed, 69 insertions, 7 deletions
diff --git a/clang/lib/Sema/CodeCompleteConsumer.cpp b/clang/lib/Sema/CodeCompleteConsumer.cpp index f490a2b5235..f1b475a6df5 100644 --- a/clang/lib/Sema/CodeCompleteConsumer.cpp +++ b/clang/lib/Sema/CodeCompleteConsumer.cpp @@ -97,6 +97,36 @@ std::string CodeCompletionString::getAsString() const { } //===----------------------------------------------------------------------===// +// Code completion overload candidate implementation +//===----------------------------------------------------------------------===// +FunctionDecl * +CodeCompleteConsumer::OverloadCandidate::getFunction() const { + if (getKind() == CK_Function) + return Function; + else if (getKind() == CK_FunctionTemplate) + return FunctionTemplate->getTemplatedDecl(); + else + return 0; +} + +const FunctionType * +CodeCompleteConsumer::OverloadCandidate::getFunctionType() const { + switch (Kind) { + case CK_Function: + return Function->getType()->getAs<FunctionType>(); + + case CK_FunctionTemplate: + return FunctionTemplate->getTemplatedDecl()->getType() + ->getAs<FunctionType>(); + + case CK_FunctionType: + return Type; + } + + return 0; +} + +//===----------------------------------------------------------------------===// // Code completion consumer implementation //===----------------------------------------------------------------------===// @@ -133,3 +163,37 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Result *Results, // FIXME: Move this somewhere else! SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics(); } + +void +PrintingCodeCompleteConsumer::ProcessOverloadCandidates(unsigned CurrentArg, + OverloadCandidate *Candidates, + unsigned NumCandidates) { + for (unsigned I = 0; I != NumCandidates; ++I) { + std::string ArgString; + QualType ArgType; + + if (FunctionDecl *Function = Candidates[I].getFunction()) { + if (CurrentArg < Function->getNumParams()) { + ArgString = Function->getParamDecl(CurrentArg)->getNameAsString(); + ArgType = Function->getParamDecl(CurrentArg)->getOriginalType(); + } + } else if (const FunctionProtoType *Proto + = dyn_cast<FunctionProtoType>( + Candidates[I].getFunctionType())) { + if (CurrentArg < Proto->getNumArgs()) + ArgType = Proto->getArgType(CurrentArg); + } + + if (ArgType.isNull()) + OS << "...\n"; // We have no prototype or we're matching an ellipsis. + else { + ArgType.getAsStringInternal(ArgString, SemaRef.Context.PrintingPolicy); + OS << ArgString << "\n"; + } + } + + // Once we've printed the code-completion results, suppress remaining + // diagnostics. + // FIXME: Move this somewhere else! + SemaRef.PP.getDiagnostics().setSuppressAllDiagnostics(); +} diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index ec01941901e..754d505bc02 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -1161,19 +1161,17 @@ void Sema::CodeCompleteCall(Scope *S, ExprTy *FnIn, IsBetterOverloadCandidate(*this)); // Add the remaining viable overload candidates as code-completion reslults. - typedef CodeCompleteConsumer::Result Result; - ResultBuilder Results(*this); - Results.EnterNewScope(); + typedef CodeCompleteConsumer::OverloadCandidate ResultCandidate; + llvm::SmallVector<ResultCandidate, 8> Results; for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(), CandEnd = CandidateSet.end(); Cand != CandEnd; ++Cand) { if (Cand->Viable) - Results.MaybeAddResult(Result(Cand->Function, 0), 0); + Results.push_back(ResultCandidate(Cand->Function)); } - - Results.ExitScope(); - HandleCodeCompleteResults(CodeCompleter, Results.data(), Results.size()); + CodeCompleter->ProcessOverloadCandidates(NumArgs, Results.data(), + Results.size()); } void Sema::CodeCompleteQualifiedId(Scope *S, const CXXScopeSpec &SS, |