diff options
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/CodeCompleteConsumer.cpp | 64 | ||||
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 12 |
2 files changed, 69 insertions, 7 deletions
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index f490a2b523..f1b475a6df 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/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/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index ec01941901..754d505bc0 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/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, |