[cfe-commits] r82593 - in /cfe/trunk: include/clang/Sema/CodeCompleteConsumer.h lib/Sema/CodeCompleteConsumer.cpp lib/Sema/SemaCodeComplete.cpp test/CodeCompletion/call.cpp
Douglas Gregor
dgregor at apple.com
Tue Sep 22 17:34:10 PDT 2009
Author: dgregor
Date: Tue Sep 22 19:34:09 2009
New Revision: 82593
URL: http://llvm.org/viewvc/llvm-project?rev=82593&view=rev
Log:
Print the results of code-completion for overloading by displaying the
signature of the function with the current parameter highlighted as a
placeholder.
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/CodeCompletion/call.cpp
Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=82593&r1=82592&r2=82593&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Tue Sep 22 19:34:09 2009
@@ -273,6 +273,11 @@
/// \brief Retrieve the function type of the entity, regardless of how the
/// function is stored.
const FunctionType *getFunctionType() const;
+
+ /// \brief Create a new code-completion string that describes the function
+ /// signature of this overload candidate.
+ CodeCompletionString *CreateSignatureString(unsigned CurrentArg,
+ Sema &S) const;
};
/// \brief Deregisters and destroys this code-completion consumer.
Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=82593&r1=82592&r2=82593&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Tue Sep 22 19:34:09 2009
@@ -169,26 +169,10 @@
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;
}
}
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=82593&r1=82592&r2=82593&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Sep 22 19:34:09 2009
@@ -869,6 +869,68 @@
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;
Modified: cfe/trunk/test/CodeCompletion/call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/call.cpp?rev=82593&r1=82592&r2=82593&view=diff
==============================================================================
--- cfe/trunk/test/CodeCompletion/call.cpp (original)
+++ cfe/trunk/test/CodeCompletion/call.cpp Tue Sep 22 19:34:09 2009
@@ -18,11 +18,11 @@
void test() {
f(Y(), 0, 0);
// RUN: clang-cc -fsyntax-only -code-completion-at=%s:19:9 %s -o - | FileCheck -check-prefix=CC1 %s &&
- // CHECK-CC1: int ZZ
- // CHECK-NEXT-CC1: int j
- // CHECK-NEXT-CC1: float y
+ // CHECK-CC1: f(struct N::Y y, <#int ZZ#>)
+ // CHECK-NEXT-CC1: f(int i, <#int j#>, int k)
+ // CHECK-NEXT-CC1: f(float x, <#float y#>)
// RUN: clang-cc -fsyntax-only -code-completion-at=%s:19:13 %s -o - | FileCheck -check-prefix=CC2 %s &&
- // FIXME: two ellipses are showing up when they shouldn't
- // CHECK-CC2: int k
+ // FIXME: two extra overloads are showing up!
+ // CHECK-CC2: f(int i, int j, <#int k#>)
// RUN: true
}
More information about the cfe-commits
mailing list