aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/CodeCompleteConsumer.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-23 00:16:58 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-23 00:16:58 +0000
commit0594438e06f58ab3798416324780ab39ca9c8f54 (patch)
tree89c539ff1c473d05a56b8a8ca2b68af630969483 /lib/Sema/CodeCompleteConsumer.cpp
parent8e0a0e4e4554ab31d793413e0fb4d9532872a53a (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82592 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/CodeCompleteConsumer.cpp')
-rw-r--r--lib/Sema/CodeCompleteConsumer.cpp64
1 files changed, 64 insertions, 0 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();
+}