aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-23 00:34:09 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-23 00:34:09 +0000
commit86d802e03a267af79663990c39865c67e0645238 (patch)
tree58b70d4a1cb95123c38c27f78e44f0c149e056b9 /lib
parent0594438e06f58ab3798416324780ab39ca9c8f54 (diff)
Print the results of code-completion for overloading by displaying the
signature of the function with the current parameter highlighted as a placeholder. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82593 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/CodeCompleteConsumer.cpp24
-rw-r--r--lib/Sema/SemaCodeComplete.cpp62
2 files changed, 66 insertions, 20 deletions
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp
index f1b475a6df..a3d4d92fc3 100644
--- a/lib/Sema/CodeCompleteConsumer.cpp
+++ b/lib/Sema/CodeCompleteConsumer.cpp
@@ -169,26 +169,10 @@ 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";
+ if (CodeCompletionString *CCS
+ = Candidates[I].CreateSignatureString(CurrentArg, SemaRef)) {
+ OS << CCS->getAsString() << "\n";
+ delete CCS;
}
}
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index 754d505bc0..f879dae696 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -869,6 +869,68 @@ CodeCompleteConsumer::Result::CreateCodeCompletionString(Sema &S) {
return 0;
}
+CodeCompletionString *
+CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
+ unsigned CurrentArg,
+ Sema &S) const {
+ CodeCompletionString *Result = new CodeCompletionString;
+ FunctionDecl *FDecl = getFunction();
+ const FunctionProtoType *Proto
+ = dyn_cast<FunctionProtoType>(getFunctionType());
+ if (!FDecl && !Proto) {
+ // Function without a prototype. Just give the return type and a
+ // highlighted ellipsis.
+ const FunctionType *FT = getFunctionType();
+ Result->AddTextChunk(
+ FT->getResultType().getAsString(S.Context.PrintingPolicy).c_str());
+ Result->AddTextChunk("(");
+ Result->AddPlaceholderChunk("...");
+ Result->AddTextChunk("(");
+ return Result;
+ }
+
+ if (FDecl)
+ Result->AddTextChunk(FDecl->getNameAsString().c_str());
+ else
+ Result->AddTextChunk(
+ Proto->getResultType().getAsString(S.Context.PrintingPolicy).c_str());
+
+ Result->AddTextChunk("(");
+ unsigned NumParams = FDecl? FDecl->getNumParams() : Proto->getNumArgs();
+ for (unsigned I = 0; I != NumParams; ++I) {
+ if (I)
+ Result->AddTextChunk(", ");
+
+ std::string ArgString;
+ QualType ArgType;
+
+ if (FDecl) {
+ ArgString = FDecl->getParamDecl(I)->getNameAsString();
+ ArgType = FDecl->getParamDecl(I)->getOriginalType();
+ } else {
+ ArgType = Proto->getArgType(I);
+ }
+
+ ArgType.getAsStringInternal(ArgString, S.Context.PrintingPolicy);
+
+ if (I == CurrentArg)
+ Result->AddPlaceholderChunk(ArgString.c_str());
+ else
+ Result->AddTextChunk(ArgString.c_str());
+ }
+
+ if (Proto && Proto->isVariadic()) {
+ Result->AddTextChunk(", ");
+ if (CurrentArg < NumParams)
+ Result->AddTextChunk("...");
+ else
+ Result->AddPlaceholderChunk("...");
+ }
+ Result->AddTextChunk(")");
+
+ return Result;
+}
+
namespace {
struct SortCodeCompleteResult {
typedef CodeCompleteConsumer::Result Result;