diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-23 00:34:09 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-23 00:34:09 +0000 |
commit | 86d802e03a267af79663990c39865c67e0645238 (patch) | |
tree | 58b70d4a1cb95123c38c27f78e44f0c149e056b9 /lib/Sema/SemaCodeComplete.cpp | |
parent | 0594438e06f58ab3798416324780ab39ca9c8f54 (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/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
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; |