diff options
author | Eugene Zelenko <eugene.zelenko@gmail.com> | 2018-02-20 02:16:28 +0000 |
---|---|---|
committer | Eugene Zelenko <eugene.zelenko@gmail.com> | 2018-02-20 02:16:28 +0000 |
commit | 711964ddc19dfafeec35ba291ebd01d0c6cc0839 (patch) | |
tree | 27d0d4b2cbfe8c659525ab25ef1ac07d636f001c /clang/lib/Sema/CodeCompleteConsumer.cpp | |
parent | bab2d3e2b972549d51791a4a14ff86d88dc78077 (diff) | |
download | bcm5719-llvm-711964ddc19dfafeec35ba291ebd01d0c6cc0839.tar.gz bcm5719-llvm-711964ddc19dfafeec35ba291ebd01d0c6cc0839.zip |
[Sema] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 325544
Diffstat (limited to 'clang/lib/Sema/CodeCompleteConsumer.cpp')
-rw-r--r-- | clang/lib/Sema/CodeCompleteConsumer.cpp | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/clang/lib/Sema/CodeCompleteConsumer.cpp b/clang/lib/Sema/CodeCompleteConsumer.cpp index 798e7d6a1c2..d012e55e3da 100644 --- a/clang/lib/Sema/CodeCompleteConsumer.cpp +++ b/clang/lib/Sema/CodeCompleteConsumer.cpp @@ -1,4 +1,4 @@ -//===--- CodeCompleteConsumer.cpp - Code Completion Interface ---*- C++ -*-===// +//===- CodeCompleteConsumer.cpp - Code Completion Interface ---------------===// // // The LLVM Compiler Infrastructure // @@ -10,21 +10,30 @@ // This file implements the CodeCompleteConsumer class. // //===----------------------------------------------------------------------===// + #include "clang/Sema/CodeCompleteConsumer.h" #include "clang-c/Index.h" -#include "clang/AST/DeclCXX.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" -#include "clang/Sema/Scope.h" +#include "clang/AST/DeclarationName.h" +#include "clang/AST/Type.h" +#include "clang/Basic/IdentifierTable.h" #include "clang/Sema/Sema.h" #include "clang/Lex/Preprocessor.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> -#include <cstring> -#include <functional> +#include <cassert> +#include <cstdint> +#include <string> using namespace clang; @@ -154,9 +163,9 @@ StringRef clang::getCompletionKindString(CodeCompletionContext::Kind Kind) { //===----------------------------------------------------------------------===// // Code completion string implementation //===----------------------------------------------------------------------===// + CodeCompletionString::Chunk::Chunk(ChunkKind Kind, const char *Text) - : Kind(Kind), Text("") -{ + : Kind(Kind), Text("") { switch (Kind) { case CK_TypedText: case CK_Text: @@ -270,10 +279,9 @@ CodeCompletionString::CodeCompletionString(const Chunk *Chunks, unsigned NumAnnotations, StringRef ParentName, const char *BriefComment) - : NumChunks(NumChunks), NumAnnotations(NumAnnotations), - Priority(Priority), Availability(Availability), - ParentName(ParentName), BriefComment(BriefComment) -{ + : NumChunks(NumChunks), NumAnnotations(NumAnnotations), + Priority(Priority), Availability(Availability), + ParentName(ParentName), BriefComment(BriefComment) { assert(NumChunks <= 0xffff); assert(NumAnnotations <= 0xffff); @@ -297,7 +305,6 @@ const char *CodeCompletionString::getAnnotation(unsigned AnnotationNr) const { return nullptr; } - std::string CodeCompletionString::getAsString() const { std::string Result; llvm::raw_string_ostream OS(Result); @@ -342,7 +349,7 @@ const char *CodeCompletionAllocator::CopyString(const Twine &String) { StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) { const NamedDecl *ND = dyn_cast<NamedDecl>(DC); if (!ND) - return StringRef(); + return {}; // Check whether we've already cached the parent name. StringRef &CachedParentName = ParentNames[DC]; @@ -352,7 +359,7 @@ StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) { // If we already processed this DeclContext and assigned empty to it, the // data pointer will be non-null. if (CachedParentName.data() != nullptr) - return StringRef(); + return {}; // Find the interesting names. SmallVector<const DeclContext *, 2> Contexts; @@ -386,7 +393,7 @@ StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) { // Assign an empty StringRef but with non-null data to distinguish // between empty because we didn't process the DeclContext yet. CachedParentName = StringRef((const char *)(uintptr_t)~0U, 0); - return StringRef(); + return {}; } OS << Interface->getName() << '(' << Cat->getName() << ')'; @@ -450,9 +457,8 @@ void CodeCompletionBuilder::AddChunk(CodeCompletionString::ChunkKind CK, } void CodeCompletionBuilder::addParentContext(const DeclContext *DC) { - if (DC->isTranslationUnit()) { + if (DC->isTranslationUnit()) return; - } if (DC->isFunctionOrMethod()) return; @@ -502,25 +508,21 @@ CodeCompleteConsumer::OverloadCandidate::getFunctionType() const { // Code completion consumer implementation //===----------------------------------------------------------------------===// -CodeCompleteConsumer::~CodeCompleteConsumer() { } +CodeCompleteConsumer::~CodeCompleteConsumer() = default; bool PrintingCodeCompleteConsumer::isResultFilteredOut(StringRef Filter, CodeCompletionResult Result) { switch (Result.Kind) { - case CodeCompletionResult::RK_Declaration: { + case CodeCompletionResult::RK_Declaration: return !(Result.Declaration->getIdentifier() && Result.Declaration->getIdentifier()->getName().startswith(Filter)); - } - case CodeCompletionResult::RK_Keyword: { + case CodeCompletionResult::RK_Keyword: return !StringRef(Result.Keyword).startswith(Filter); - } - case CodeCompletionResult::RK_Macro: { + case CodeCompletionResult::RK_Macro: return !Result.Macro->getName().startswith(Filter); - } - case CodeCompletionResult::RK_Pattern: { + case CodeCompletionResult::RK_Pattern: return !StringRef(Result.Pattern->getAsString()).startswith(Filter); } - } llvm_unreachable("Unknown code completion result Kind."); } @@ -552,7 +554,6 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef, if (const char *BriefComment = CCS->getBriefComment()) OS << " : " << BriefComment; } - OS << '\n'; break; @@ -560,7 +561,7 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef, OS << Results[I].Keyword << '\n'; break; - case CodeCompletionResult::RK_Macro: { + case CodeCompletionResult::RK_Macro: OS << Results[I].Macro->getName(); if (CodeCompletionString *CCS = Results[I].CreateCodeCompletionString(SemaRef, Context, @@ -571,14 +572,12 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef, } OS << '\n'; break; - } - case CodeCompletionResult::RK_Pattern: { + case CodeCompletionResult::RK_Pattern: OS << "Pattern : " << Results[I].Pattern->getAsString() << '\n'; break; } - } } } |