diff options
author | Eric Liu <ioeric@google.com> | 2018-09-18 13:35:16 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-09-18 13:35:16 +0000 |
commit | d9a480a96a51a582c45fc6a94c86ed0a612f58b3 (patch) | |
tree | 639ae685905e876eb49b065028056931e2e68faf | |
parent | 5060576a82310b85d33bf38fd28059e3bad8f55f (diff) |
[clangd] Get rid of Decls parameter in indexMainDecls. NFC
It's already available in ParsedAST.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@342473 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | clangd/ClangdServer.cpp | 2 | ||||
-rw-r--r-- | clangd/index/FileIndex.cpp | 10 | ||||
-rw-r--r-- | clangd/index/FileIndex.h | 12 | ||||
-rw-r--r-- | unittests/clangd/FileIndexTests.cpp | 4 | ||||
-rw-r--r-- | unittests/clangd/IndexTests.cpp | 8 | ||||
-rw-r--r-- | unittests/clangd/TestTU.cpp | 2 |
6 files changed, 17 insertions, 21 deletions
diff --git a/clangd/ClangdServer.cpp b/clangd/ClangdServer.cpp index 6f2d13e0..153dce29 100644 --- a/clangd/ClangdServer.cpp +++ b/clangd/ClangdServer.cpp @@ -83,7 +83,7 @@ std::unique_ptr<ParsingCallbacks> makeUpdateCallbacks(FileIndex *FIndex) { } void onMainAST(PathRef Path, ParsedAST &AST) override { - FIndex->updateMain(Path, AST, AST.getLocalTopLevelDecls()); + FIndex->updateMain(Path, AST); } }; return llvm::make_unique<CB>(FIndex); diff --git a/clangd/index/FileIndex.cpp b/clangd/index/FileIndex.cpp index ad7f6345..22a32cca 100644 --- a/clangd/index/FileIndex.cpp +++ b/clangd/index/FileIndex.cpp @@ -65,10 +65,9 @@ indexSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP, } std::pair<SymbolSlab, RefSlab> -indexMainDecls(ParsedAST &AST, llvm::ArrayRef<Decl *> TopLevelDecls, - llvm::ArrayRef<std::string> URISchemes) { +indexMainDecls(ParsedAST &AST, llvm::ArrayRef<std::string> URISchemes) { return indexSymbols(AST.getASTContext(), AST.getPreprocessorPtr(), - TopLevelDecls, + AST.getLocalTopLevelDecls(), /*IsIndexMainAST=*/true, URISchemes); } @@ -163,9 +162,8 @@ void FileIndex::updatePreamble(PathRef Path, ASTContext &AST, PreambleIndex.reset(PreambleSymbols.buildMemIndex()); } -void FileIndex::updateMain(PathRef Path, ParsedAST &AST, - llvm::ArrayRef<Decl *> TopLevelDecls) { - auto Contents = indexMainDecls(AST, TopLevelDecls, URISchemes); +void FileIndex::updateMain(PathRef Path, ParsedAST &AST) { + auto Contents = indexMainDecls(AST, URISchemes); MainFileSymbols.update( Path, llvm::make_unique<SymbolSlab>(std::move(Contents.first)), llvm::make_unique<RefSlab>(std::move(Contents.second))); diff --git a/clangd/index/FileIndex.h b/clangd/index/FileIndex.h index 421cfa4e..7226e166 100644 --- a/clangd/index/FileIndex.h +++ b/clangd/index/FileIndex.h @@ -73,9 +73,9 @@ public: void updatePreamble(PathRef Path, ASTContext &AST, std::shared_ptr<Preprocessor> PP); - /// Update symbols from main file \p Path with symbols in \p TopLevelDecls. - void updateMain(PathRef Path, ParsedAST &AST, - llvm::ArrayRef<Decl *> TopLevelDecls); + /// Update symbols and references from main file \p Path with + /// `indexMainDecls`. + void updateMain(PathRef Path, ParsedAST &AST); private: std::vector<std::string> URISchemes; @@ -106,12 +106,12 @@ private: std::unique_ptr<SymbolIndex> MergedIndex; // Merge preamble and main index. }; -/// Retrieves symbols and refs of \p Decls in \p AST. +/// Retrieves symbols and refs of local top level decls in \p AST (i.e. +/// `AST.getLocalTopLevelDecls()`). /// Exposed to assist in unit tests. /// If URISchemes is empty, the default schemes in SymbolCollector will be used. std::pair<SymbolSlab, RefSlab> -indexMainDecls(ParsedAST &AST, llvm::ArrayRef<Decl *> Decls, - llvm::ArrayRef<std::string> URISchemes = {}); +indexMainDecls(ParsedAST &AST, llvm::ArrayRef<std::string> URISchemes = {}); /// Idex declarations from \p AST and macros from \p PP that are declared in /// included headers. diff --git a/unittests/clangd/FileIndexTests.cpp b/unittests/clangd/FileIndexTests.cpp index 346560ac..f8835519 100644 --- a/unittests/clangd/FileIndexTests.cpp +++ b/unittests/clangd/FileIndexTests.cpp @@ -314,14 +314,14 @@ TEST(FileIndexTest, Refs) { Test.Code = MainCode.code(); Test.Filename = "test.cc"; auto AST = Test.build(); - Index.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls()); + Index.updateMain(Test.Filename, AST); // Add test2.cc TestTU Test2; Test2.HeaderCode = HeaderCode; Test2.Code = MainCode.code(); Test2.Filename = "test2.cc"; AST = Test2.build(); - Index.updateMain(Test2.Filename, AST, AST.getLocalTopLevelDecls()); + Index.updateMain(Test2.Filename, AST); EXPECT_THAT(getRefs(Index.index(), Foo.ID), RefsAre({AllOf(RefRange(MainCode.range("foo")), diff --git a/unittests/clangd/IndexTests.cpp b/unittests/clangd/IndexTests.cpp index 1f8129f5..b774742c 100644 --- a/unittests/clangd/IndexTests.cpp +++ b/unittests/clangd/IndexTests.cpp @@ -244,7 +244,7 @@ TEST(MergeIndexTest, Refs) { Test.Code = Test1Code.code(); Test.Filename = "test.cc"; auto AST = Test.build(); - Dyn.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls()); + Dyn.updateMain(Test.Filename, AST); // Build static index for test.cc. Test.HeaderCode = HeaderCode; @@ -252,8 +252,7 @@ TEST(MergeIndexTest, Refs) { Test.Filename = "test.cc"; auto StaticAST = Test.build(); // Add stale refs for test.cc. - StaticIndex.updateMain(Test.Filename, StaticAST, - StaticAST.getLocalTopLevelDecls()); + StaticIndex.updateMain(Test.Filename, StaticAST); // Add refs for test2.cc Annotations Test2Code(R"(class $Foo[[Foo]] {};)"); @@ -262,8 +261,7 @@ TEST(MergeIndexTest, Refs) { Test2.Code = Test2Code.code(); Test2.Filename = "test2.cc"; StaticAST = Test2.build(); - StaticIndex.updateMain(Test2.Filename, StaticAST, - StaticAST.getLocalTopLevelDecls()); + StaticIndex.updateMain(Test2.Filename, StaticAST); RefsRequest Request; Request.IDs = {Foo.ID}; diff --git a/unittests/clangd/TestTU.cpp b/unittests/clangd/TestTU.cpp index 847f7965..4b610c8f 100644 --- a/unittests/clangd/TestTU.cpp +++ b/unittests/clangd/TestTU.cpp @@ -51,7 +51,7 @@ SymbolSlab TestTU::headerSymbols() const { // FIXME: This should return a FileIndex with both preamble and main index. std::unique_ptr<SymbolIndex> TestTU::index() const { auto AST = build(); - auto Content = indexMainDecls(AST, AST.getLocalTopLevelDecls()); + auto Content = indexMainDecls(AST); return MemIndex::build(std::move(Content.first), std::move(Content.second)); } |