diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-18 18:53:37 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-18 18:53:37 +0000 |
commit | ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aa (patch) | |
tree | fdc221aa0e45746fd32384e472b3446a610bf8d4 /lib/Sema/SemaCodeComplete.cpp | |
parent | eac7c53f16bc12bcd9baac756b6f9bb77b74b0ad (diff) |
Extend code-completion results with the type of each result
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91702 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 6b485ba7a9..1391adfd48 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -829,6 +829,39 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, unsigned Rank, } } +/// \brief If the given declaration has an associated type, add it as a result +/// type chunk. +static void AddResultTypeChunk(ASTContext &Context, + NamedDecl *ND, + CodeCompletionString *Result) { + if (!ND) + return; + + // Determine the type of the declaration (if it has a type). + QualType T; + if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) + T = Function->getResultType(); + else if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) + T = Method->getResultType(); + else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) + T = FunTmpl->getTemplatedDecl()->getResultType(); + else if (EnumConstantDecl *Enumerator = dyn_cast<EnumConstantDecl>(ND)) + T = Context.getTypeDeclType(cast<TypeDecl>(Enumerator->getDeclContext())); + else if (isa<UnresolvedUsingValueDecl>(ND)) { + /* Do nothing: ignore unresolved using declarations*/ + } else if (ValueDecl *Value = dyn_cast<ValueDecl>(ND)) + T = Value->getType(); + else if (ObjCPropertyDecl *Property = dyn_cast<ObjCPropertyDecl>(ND)) + T = Property->getType(); + + if (T.isNull() || Context.hasSameType(T, Context.DependentTy)) + return; + + std::string TypeStr; + T.getAsStringInternal(TypeStr, Context.PrintingPolicy); + Result->AddResultTypeChunk(TypeStr); +} + /// \brief Add function parameter chunks to the given code completion string. static void AddFunctionParameterChunks(ASTContext &Context, FunctionDecl *Function, @@ -1042,6 +1075,8 @@ CodeCompleteConsumer::Result::CreateCodeCompletionString(Sema &S) { return Result; } + AddResultTypeChunk(S.Context, ND, Result); + if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) { AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, S.Context); @@ -1189,6 +1224,7 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString( CodeCompletionString *Result = new CodeCompletionString; FunctionDecl *FDecl = getFunction(); + AddResultTypeChunk(S.Context, FDecl, Result); const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(getFunctionType()); if (!FDecl && !Proto) { |