From 74f2655dc7f2a7ece916e315bf9302f92d8425d4 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Thu, 26 Jul 2018 12:05:31 +0000 Subject: [PATCH] [clangd] Fix (most) naming warnings from clang-tidy. NFC llvm-svn: 338021 --- clang-tools-extra/clangd/ClangdUnit.cpp | 4 +-- clang-tools-extra/clangd/ClangdUnit.h | 2 +- clang-tools-extra/clangd/CodeComplete.cpp | 4 +-- clang-tools-extra/clangd/CodeCompletionStrings.cpp | 6 ++-- clang-tools-extra/clangd/JSONRPCDispatcher.cpp | 8 +++--- clang-tools-extra/clangd/JSONRPCDispatcher.h | 2 +- clang-tools-extra/clangd/Protocol.cpp | 6 ++-- clang-tools-extra/clangd/Quality.cpp | 16 +++++------ clang-tools-extra/clangd/TUScheduler.cpp | 6 ++-- clang-tools-extra/clangd/XRefs.cpp | 32 +++++++++++----------- clang-tools-extra/clangd/index/Merge.cpp | 2 +- clang-tools-extra/clangd/index/SymbolYAML.cpp | 2 +- clang-tools-extra/clangd/index/SymbolYAML.h | 2 +- clang-tools-extra/clangd/tool/ClangdMain.cpp | 2 +- .../unittests/clangd/SymbolCollectorTests.cpp | 6 ++-- clang-tools-extra/unittests/clangd/TestTU.cpp | 2 +- 16 files changed, 51 insertions(+), 51 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index a5ab483..86e7497 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/clangd/ClangdUnit.cpp @@ -121,7 +121,7 @@ void clangd::dumpAST(ParsedAST &AST, llvm::raw_ostream &OS) { } llvm::Optional -ParsedAST::Build(std::unique_ptr CI, +ParsedAST::build(std::unique_ptr CI, std::shared_ptr Preamble, std::unique_ptr Buffer, std::shared_ptr PCHs, @@ -367,7 +367,7 @@ llvm::Optional clangd::buildAST( // dirs. } - return ParsedAST::Build( + return ParsedAST::build( llvm::make_unique(*Invocation), Preamble, llvm::MemoryBuffer::getMemBufferCopy(Inputs.Contents), PCHs, Inputs.FS); } diff --git a/clang-tools-extra/clangd/ClangdUnit.h b/clang-tools-extra/clangd/ClangdUnit.h index 6db1e86..c7aca17 100644 --- a/clang-tools-extra/clangd/ClangdUnit.h +++ b/clang-tools-extra/clangd/ClangdUnit.h @@ -68,7 +68,7 @@ public: /// Attempts to run Clang and store parsed AST. If \p Preamble is non-null /// it is reused during parsing. static llvm::Optional - Build(std::unique_ptr CI, + build(std::unique_ptr CI, std::shared_ptr Preamble, std::unique_ptr Buffer, std::shared_ptr PCHs, diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 44c44b6..a040659 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -704,7 +704,7 @@ public: CurrentArg, S, *Allocator, CCTUInfo, true); assert(CCS && "Expected the CodeCompletionString to be non-null"); // FIXME: for headers, we need to get a comment from the index. - SigHelp.signatures.push_back(ProcessOverloadCandidate( + SigHelp.signatures.push_back(processOverloadCandidate( Candidate, *CCS, getParameterDocComment(S.getASTContext(), Candidate, CurrentArg, /*CommentsFromHeaders=*/false))); @@ -719,7 +719,7 @@ private: // FIXME(ioeric): consider moving CodeCompletionString logic here to // CompletionString.h. SignatureInformation - ProcessOverloadCandidate(const OverloadCandidate &Candidate, + processOverloadCandidate(const OverloadCandidate &Candidate, const CodeCompletionString &CCS, llvm::StringRef DocComment) const { SignatureInformation Result; diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp b/clang-tools-extra/clangd/CodeCompletionStrings.cpp index 474419d..88b37da 100644 --- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp +++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp @@ -32,7 +32,7 @@ void appendEscapeSnippet(const llvm::StringRef Text, std::string *Out) { } } -bool LooksLikeDocComment(llvm::StringRef CommentText) { +bool looksLikeDocComment(llvm::StringRef CommentText) { // We don't report comments that only contain "special" chars. // This avoids reporting various delimiters, like: // ================= @@ -67,7 +67,7 @@ std::string getDocComment(const ASTContext &Ctx, // write them into PCH, because they are racy and slow to load. assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getLocStart())); std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics()); - if (!LooksLikeDocComment(Doc)) + if (!looksLikeDocComment(Doc)) return ""; return Doc; } @@ -86,7 +86,7 @@ getParameterDocComment(const ASTContext &Ctx, // write them into PCH, because they are racy and slow to load. assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getLocStart())); std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics()); - if (!LooksLikeDocComment(Doc)) + if (!looksLikeDocComment(Doc)) return ""; return Doc; } diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp index 8c5fec6..2741c66 100644 --- a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp +++ b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp @@ -109,10 +109,10 @@ void clangd::reply(json::Value &&Result) { }); } -void clangd::replyError(ErrorCode code, const llvm::StringRef &Message) { - elog("Error {0}: {1}", static_cast(code), Message); +void clangd::replyError(ErrorCode Code, const llvm::StringRef &Message) { + elog("Error {0}: {1}", static_cast(Code), Message); RequestSpan::attach([&](json::Object &Args) { - Args["Error"] = json::Object{{"code", static_cast(code)}, + Args["Error"] = json::Object{{"code", static_cast(Code)}, {"message", Message.str()}}; }); @@ -123,7 +123,7 @@ void clangd::replyError(ErrorCode code, const llvm::StringRef &Message) { ->writeMessage(json::Object{ {"jsonrpc", "2.0"}, {"id", *ID}, - {"error", json::Object{{"code", static_cast(code)}, + {"error", json::Object{{"code", static_cast(Code)}, {"message", Message}}}, }); } diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.h b/clang-tools-extra/clangd/JSONRPCDispatcher.h index a391212..e8c96fc 100644 --- a/clang-tools-extra/clangd/JSONRPCDispatcher.h +++ b/clang-tools-extra/clangd/JSONRPCDispatcher.h @@ -63,7 +63,7 @@ private: void reply(llvm::json::Value &&Result); /// Sends an error response to the client, and logs it. /// Current context must derive from JSONRPCDispatcher::Handler. -void replyError(ErrorCode code, const llvm::StringRef &Message); +void replyError(ErrorCode Code, const llvm::StringRef &Message); /// Sends a request to the client. /// Current context must derive from JSONRPCDispatcher::Handler. void call(llvm::StringRef Method, llvm::json::Value &&Params); diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index 8d99e18..c9ff74f 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -208,10 +208,10 @@ bool fromJSON(const json::Value &Params, SymbolKindCapabilities &R) { } SymbolKind adjustKindToCapability(SymbolKind Kind, - SymbolKindBitset &supportedSymbolKinds) { + SymbolKindBitset &SupportedSymbolKinds) { auto KindVal = static_cast(Kind); - if (KindVal >= SymbolKindMin && KindVal <= supportedSymbolKinds.size() && - supportedSymbolKinds[KindVal]) + if (KindVal >= SymbolKindMin && KindVal <= SupportedSymbolKinds.size() && + SupportedSymbolKinds[KindVal]) return Kind; switch (Kind) { diff --git a/clang-tools-extra/clangd/Quality.cpp b/clang-tools-extra/clangd/Quality.cpp index afbcdec..61195b5 100644 --- a/clang-tools-extra/clangd/Quality.cpp +++ b/clang-tools-extra/clangd/Quality.cpp @@ -27,7 +27,7 @@ namespace clang { namespace clangd { using namespace llvm; -static bool IsReserved(StringRef Name) { +static bool isReserved(StringRef Name) { // FIXME: Should we exclude _Bool and others recognized by the standard? return Name.size() >= 2 && Name[0] == '_' && (isUppercase(Name[1]) || Name[1] == '_'); @@ -174,15 +174,15 @@ void SymbolQualitySignals::merge(const CodeCompletionResult &SemaCCResult) { if (SemaCCResult.Declaration) { if (auto *ID = SemaCCResult.Declaration->getIdentifier()) - ReservedName = ReservedName || IsReserved(ID->getName()); + ReservedName = ReservedName || isReserved(ID->getName()); } else if (SemaCCResult.Kind == CodeCompletionResult::RK_Macro) - ReservedName = ReservedName || IsReserved(SemaCCResult.Macro->getName()); + ReservedName = ReservedName || isReserved(SemaCCResult.Macro->getName()); } void SymbolQualitySignals::merge(const Symbol &IndexResult) { References = std::max(IndexResult.References, References); Category = categorize(IndexResult.SymInfo); - ReservedName = ReservedName || IsReserved(IndexResult.Name); + ReservedName = ReservedName || isReserved(IndexResult.Name); } float SymbolQualitySignals::evaluate() const { @@ -199,8 +199,8 @@ float SymbolQualitySignals::evaluate() const { // boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59 // Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82), // (10K, 2.21), (100K, 2.58), (1M, 2.94) - float s = std::pow(References, -0.06); - Score *= 6.0 * (1 - s) / (1 + s) + 0.59; + float S = std::pow(References, -0.06); + Score *= 6.0 * (1 - S) / (1 + S) + 0.59; } if (Deprecated) @@ -241,7 +241,7 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolQualitySignals &S) { } static SymbolRelevanceSignals::AccessibleScope -ComputeScope(const NamedDecl *D) { +computeScope(const NamedDecl *D) { // Injected "Foo" within the class "Foo" has file scope, not class scope. const DeclContext *DC = D->getDeclContext(); if (auto *R = dyn_cast_or_null(D)) @@ -291,7 +291,7 @@ void SymbolRelevanceSignals::merge(const CodeCompletionResult &SemaCCResult) { // Declarations are scoped, others (like macros) are assumed global. if (SemaCCResult.Declaration) - Scope = std::min(Scope, ComputeScope(SemaCCResult.Declaration)); + Scope = std::min(Scope, computeScope(SemaCCResult.Declaration)); } static std::pair proximityScore(llvm::StringRef SymbolURI, diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index 36cada5..b530534 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -159,7 +159,7 @@ public: /// is null, all requests will be processed on the calling thread /// synchronously instead. \p Barrier is acquired when processing each /// request, it is be used to limit the number of actively running threads. - static ASTWorkerHandle Create(PathRef FileName, + static ASTWorkerHandle create(PathRef FileName, TUScheduler::ASTCache &IdleASTs, AsyncTaskRunner *Tasks, Semaphore &Barrier, steady_clock::duration UpdateDebounce, @@ -282,7 +282,7 @@ private: std::shared_ptr Worker; }; -ASTWorkerHandle ASTWorker::Create(PathRef FileName, +ASTWorkerHandle ASTWorker::create(PathRef FileName, TUScheduler::ASTCache &IdleASTs, AsyncTaskRunner *Tasks, Semaphore &Barrier, steady_clock::duration UpdateDebounce, @@ -639,7 +639,7 @@ void TUScheduler::update( std::unique_ptr &FD = Files[File]; if (!FD) { // Create a new worker to process the AST-related tasks. - ASTWorkerHandle Worker = ASTWorker::Create( + ASTWorkerHandle Worker = ASTWorker::create( File, *IdleASTs, WorkerThreads ? WorkerThreads.getPointer() : nullptr, Barrier, UpdateDebounce, PCHOps, StorePreamblesInMemory, PreambleCallback); diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index 9388206..99ccd21 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -25,7 +25,7 @@ namespace { // Get the definition from a given declaration `D`. // Return nullptr if no definition is found, or the declaration type of `D` is // not supported. -const Decl *GetDefinition(const Decl *D) { +const Decl *getDefinition(const Decl *D) { assert(D); if (const auto *TD = dyn_cast(D)) return TD->getDefinition(); @@ -40,7 +40,7 @@ const Decl *GetDefinition(const Decl *D) { // HintPath is used to resolve the path of URI. // FIXME: figure out a good home for it, and share the implementation with // FindSymbols. -llvm::Optional ToLSPLocation(const SymbolLocation &Loc, +llvm::Optional toLSPLocation(const SymbolLocation &Loc, llvm::StringRef HintPath) { if (!Loc) return llvm::None; @@ -116,7 +116,7 @@ public: // We don't use parameter `D`, as Parameter `D` is the canonical // declaration, which is the first declaration of a redeclarable // declaration, and it could be a forward declaration. - if (const auto *Def = GetDefinition(D)) { + if (const auto *Def = getDefinition(D)) { Decls.push_back(Def); } else { // Couldn't find a definition, fall back to use `D`. @@ -279,7 +279,7 @@ std::vector findDefinitions(ParsedAST &AST, Position Pos, auto L = makeLocation(AST, SourceRange(Loc, Loc)); // The declaration in the identified symbols is a definition if possible // otherwise it is declaration. - bool IsDef = GetDefinition(D) == D; + bool IsDef = getDefinition(D) == D; // Populate one of the slots with location for the AST. if (!IsDef) Candidate.Decl = L; @@ -305,9 +305,9 @@ std::vector findDefinitions(ParsedAST &AST, Position Pos, auto &Value = It->second; if (!Value.Def) - Value.Def = ToLSPLocation(Sym.Definition, HintPath); + Value.Def = toLSPLocation(Sym.Definition, HintPath); if (!Value.Decl) - Value.Decl = ToLSPLocation(Sym.CanonicalDeclaration, HintPath); + Value.Decl = toLSPLocation(Sym.CanonicalDeclaration, HintPath); }); } @@ -410,7 +410,7 @@ std::vector findDocumentHighlights(ParsedAST &AST, return DocHighlightsFinder.takeHighlights(); } -static PrintingPolicy PrintingPolicyForDecls(PrintingPolicy Base) { +static PrintingPolicy printingPolicyForDecls(PrintingPolicy Base) { PrintingPolicy Policy(Base); Policy.AnonymousTagLocations = false; @@ -424,11 +424,11 @@ static PrintingPolicy PrintingPolicyForDecls(PrintingPolicy Base) { /// Return a string representation (e.g. "class MyNamespace::MyClass") of /// the type declaration \p TD. -static std::string TypeDeclToString(const TypeDecl *TD) { +static std::string typeDeclToString(const TypeDecl *TD) { QualType Type = TD->getASTContext().getTypeDeclType(TD); PrintingPolicy Policy = - PrintingPolicyForDecls(TD->getASTContext().getPrintingPolicy()); + printingPolicyForDecls(TD->getASTContext().getPrintingPolicy()); std::string Name; llvm::raw_string_ostream Stream(Name); @@ -439,10 +439,10 @@ static std::string TypeDeclToString(const TypeDecl *TD) { /// Return a string representation (e.g. "namespace ns1::ns2") of /// the named declaration \p ND. -static std::string NamedDeclQualifiedName(const NamedDecl *ND, +static std::string namedDeclQualifiedName(const NamedDecl *ND, StringRef Prefix) { PrintingPolicy Policy = - PrintingPolicyForDecls(ND->getASTContext().getPrintingPolicy()); + printingPolicyForDecls(ND->getASTContext().getPrintingPolicy()); std::string Name; llvm::raw_string_ostream Stream(Name); @@ -461,11 +461,11 @@ static llvm::Optional getScopeName(const Decl *D) { if (isa(DC)) return std::string("global namespace"); if (const TypeDecl *TD = dyn_cast(DC)) - return TypeDeclToString(TD); + return typeDeclToString(TD); else if (const NamespaceDecl *ND = dyn_cast(DC)) - return NamedDeclQualifiedName(ND, "namespace"); + return namedDeclQualifiedName(ND, "namespace"); else if (const FunctionDecl *FD = dyn_cast(DC)) - return NamedDeclQualifiedName(FD, "function"); + return namedDeclQualifiedName(FD, "function"); return llvm::None; } @@ -492,7 +492,7 @@ static Hover getHoverContents(const Decl *D) { llvm::raw_string_ostream OS(DeclText); PrintingPolicy Policy = - PrintingPolicyForDecls(D->getASTContext().getPrintingPolicy()); + printingPolicyForDecls(D->getASTContext().getPrintingPolicy()); D->print(OS, Policy); @@ -507,7 +507,7 @@ static Hover getHoverContents(QualType T, ASTContext &ASTCtx) { Hover H; std::string TypeText; llvm::raw_string_ostream OS(TypeText); - PrintingPolicy Policy = PrintingPolicyForDecls(ASTCtx.getPrintingPolicy()); + PrintingPolicy Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy()); T.print(OS, Policy); OS.flush(); H.contents.value += TypeText; diff --git a/clang-tools-extra/clangd/index/Merge.cpp b/clang-tools-extra/clangd/index/Merge.cpp index 4365e04..da31f8b 100644 --- a/clang-tools-extra/clangd/index/Merge.cpp +++ b/clang-tools-extra/clangd/index/Merge.cpp @@ -77,7 +77,7 @@ class MergedIndex : public SymbolIndex { private: const SymbolIndex *Dynamic, *Static; }; -} +} // namespace Symbol mergeSymbol(const Symbol &L, const Symbol &R, Symbol::Details *Scratch) { diff --git a/clang-tools-extra/clangd/index/SymbolYAML.cpp b/clang-tools-extra/clangd/index/SymbolYAML.cpp index 304443e..1701b5a 100644 --- a/clang-tools-extra/clangd/index/SymbolYAML.cpp +++ b/clang-tools-extra/clangd/index/SymbolYAML.cpp @@ -168,7 +168,7 @@ template <> struct ScalarEnumerationTraits { namespace clang { namespace clangd { -SymbolSlab SymbolsFromYAML(llvm::StringRef YAMLContent) { +SymbolSlab symbolsFromYAML(llvm::StringRef YAMLContent) { // Store data of pointer fields (excl. `StringRef`) like `Detail`. llvm::BumpPtrAllocator Arena; llvm::yaml::Input Yin(YAMLContent, &Arena); diff --git a/clang-tools-extra/clangd/index/SymbolYAML.h b/clang-tools-extra/clangd/index/SymbolYAML.h index 9d16cc5d..726af6c 100644 --- a/clang-tools-extra/clangd/index/SymbolYAML.h +++ b/clang-tools-extra/clangd/index/SymbolYAML.h @@ -27,7 +27,7 @@ namespace clang { namespace clangd { // Read symbols from a YAML-format string. -SymbolSlab SymbolsFromYAML(llvm::StringRef YAMLContent); +SymbolSlab symbolsFromYAML(llvm::StringRef YAMLContent); // Read one symbol from a YAML-stream. // The arena must be the Input's context! (i.e. yaml::Input Input(Text, &Arena)) diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index f04a975..5ae5740 100644 --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -40,7 +40,7 @@ std::unique_ptr buildStaticIndex(llvm::StringRef YamlSymbolFile) { llvm::errs() << "Can't open " << YamlSymbolFile << "\n"; return nullptr; } - auto Slab = SymbolsFromYAML(Buffer.get()->getBuffer()); + auto Slab = symbolsFromYAML(Buffer.get()->getBuffer()); SymbolSlab::Builder SymsBuilder; for (auto Sym : Slab) SymsBuilder.insert(Sym); diff --git a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp index b2a9990..666d0bb 100644 --- a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp +++ b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp @@ -723,14 +723,14 @@ CompletionSnippetSuffix: '-snippet' ... )"; - auto Symbols1 = SymbolsFromYAML(YAML1); + auto Symbols1 = symbolsFromYAML(YAML1); EXPECT_THAT(Symbols1, UnorderedElementsAre(AllOf(QName("clang::Foo1"), Labeled("Foo1"), Doc("Foo doc"), ReturnType("int"), DeclURI("file:///path/foo.h"), ForCodeCompletion(true)))); - auto Symbols2 = SymbolsFromYAML(YAML2); + auto Symbols2 = symbolsFromYAML(YAML2); EXPECT_THAT(Symbols2, UnorderedElementsAre(AllOf( QName("clang::Foo2"), Labeled("Foo2-sig"), Not(HasReturnType()), DeclURI("file:///path/bar.h"), @@ -742,7 +742,7 @@ CompletionSnippetSuffix: '-snippet' SymbolsToYAML(Symbols1, OS); SymbolsToYAML(Symbols2, OS); } - auto ConcatenatedSymbols = SymbolsFromYAML(ConcatenatedYAML); + auto ConcatenatedSymbols = symbolsFromYAML(ConcatenatedYAML); EXPECT_THAT(ConcatenatedSymbols, UnorderedElementsAre(QName("clang::Foo1"), QName("clang::Foo2"))); diff --git a/clang-tools-extra/unittests/clangd/TestTU.cpp b/clang-tools-extra/unittests/clangd/TestTU.cpp index 3128120..b47d944 100644 --- a/clang-tools-extra/unittests/clangd/TestTU.cpp +++ b/clang-tools-extra/unittests/clangd/TestTU.cpp @@ -30,7 +30,7 @@ ParsedAST TestTU::build() const { Cmd.push_back(FullHeaderName.c_str()); } Cmd.insert(Cmd.end(), ExtraArgs.begin(), ExtraArgs.end()); - auto AST = ParsedAST::Build( + auto AST = ParsedAST::build( createInvocationFromCommandLine(Cmd), nullptr, MemoryBuffer::getMemBufferCopy(Code), std::make_shared(), -- 2.7.4