[clangd] Rename ClangdUnit.h -> ParsedAST.h. NFC

This much better reflects what is (now) in this header.
Maybe a rename to ParsedTU would be an improvement, but that's a much
more invasive change and life is too short.

ClangdUnit is dead, long live ClangdUnitTests!

llvm-svn: 370862
This commit is contained in:
Sam McCall 2019-09-04 09:46:06 +00:00
parent a1a22f375a
commit 915f9785e0
31 changed files with 65 additions and 44 deletions

View File

@ -39,7 +39,6 @@ add_clang_library(clangDaemon
Cancellation.cpp
ClangdLSPServer.cpp
ClangdServer.cpp
ClangdUnit.cpp
CodeComplete.cpp
CodeCompletionStrings.cpp
Compiler.cpp
@ -62,6 +61,7 @@ add_clang_library(clangDaemon
Logger.cpp
Protocol.cpp
Quality.cpp
ParsedAST.cpp
Preamble.cpp
RIFF.cpp
Selection.cpp

View File

@ -7,12 +7,12 @@
//===-------------------------------------------------------------------===//
#include "ClangdServer.h"
#include "ClangdUnit.h"
#include "CodeComplete.h"
#include "FindSymbols.h"
#include "Format.h"
#include "FormattedString.h"
#include "Headers.h"
#include "ParsedAST.h"
#include "Preamble.h"
#include "Protocol.h"
#include "SemanticHighlighting.h"

View File

@ -8,9 +8,9 @@
#include "FindSymbols.h"
#include "AST.h"
#include "ClangdUnit.h"
#include "FuzzyMatch.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "Quality.h"
#include "SourceCode.h"
#include "index/Index.h"

View File

@ -1,4 +1,4 @@
//===--- ClangdUnit.cpp ------------------------------------------*- C++-*-===//
//===--- ParsedAST.cpp -------------------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "ClangdUnit.h"
#include "ParsedAST.h"
#include "../clang-tidy/ClangTidyDiagnosticConsumer.h"
#include "../clang-tidy/ClangTidyModuleRegistry.h"
#include "AST.h"

View File

@ -1,13 +1,25 @@
//===--- ClangdUnit.h --------------------------------------------*- C++-*-===//
//===--- ParsedAST.h - Building translation units ----------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file exposes building a file as if it were open in clangd, and defines
// the ParsedAST structure that holds the results.
//
// This is similar to a clang -fsyntax-only run that produces a clang AST, but
// we have several customizations:
// - preamble handling
// - capturing diagnostics for later access
// - running clang-tidy checks checks
//
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PARSEDAST_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PARSEDAST_H
#include "Compiler.h"
#include "Diagnostics.h"
@ -136,4 +148,4 @@ void dumpAST(ParsedAST &AST, llvm::raw_ostream &OS);
} // namespace clangd
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_PARSEDAST_H

View File

@ -25,7 +25,7 @@ bool compileCommandsAreEqual(const tooling::CompileCommand &LHS,
}
// This collects macro definitions in the *preamble region* of the main file.
// (Contrast with CollectMainFileMacroExpansions in ClangdUnit.cpp, which
// (Contrast with CollectMainFileMacroExpansions in ParsedAST.cpp, which
// collects macro *expansions* in the rest of the main file.
class CollectMainFileMacros : public PPCallbacks {
public:

View File

@ -8,6 +8,7 @@
#include "SemanticHighlighting.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "Protocol.h"
#include "SourceCode.h"
#include "clang/AST/ASTContext.h"

View File

@ -17,11 +17,11 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHTING_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHTING_H
#include "ClangdUnit.h"
#include "Protocol.h"
namespace clang {
namespace clangd {
class ParsedAST;
enum class HighlightingKind {
Variable = 0,

View File

@ -43,11 +43,11 @@
#include "TUScheduler.h"
#include "Cancellation.h"
#include "ClangdUnit.h"
#include "Compiler.h"
#include "Diagnostics.h"
#include "GlobalCompilationDatabase.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "Preamble.h"
#include "Trace.h"
#include "index/CanonicalIncludes.h"

View File

@ -11,6 +11,7 @@
#include "FindSymbols.h"
#include "FormattedString.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "Protocol.h"
#include "SourceCode.h"
#include "URI.h"

View File

@ -13,11 +13,13 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
#include "ClangdUnit.h"
#include "FormattedString.h"
#include "Path.h"
#include "Protocol.h"
#include "index/Index.h"
#include "clang/AST/Type.h"
#include "index/SymbolLocation.h"
#include "clang/Format/Format.h"
#include "clang/Index/IndexSymbol.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/raw_ostream.h"
@ -25,6 +27,7 @@
namespace clang {
namespace clangd {
class ParsedAST;
// Describes where a symbol is declared and defined (as far as clangd knows).
// There are three cases:

View File

@ -7,12 +7,12 @@
//===----------------------------------------------------------------------===//
#include "index/Background.h"
#include "ClangdUnit.h"
#include "Compiler.h"
#include "Context.h"
#include "FSProvider.h"
#include "Headers.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "Path.h"
#include "SourceCode.h"
#include "Symbol.h"

View File

@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//
#include "index/BackgroundRebuild.h"
#include "ClangdUnit.h"
#include "Compiler.h"
#include "Headers.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "Path.h"
#include "SourceCode.h"
#include "Symbol.h"

View File

@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "FileIndex.h"
#include "ClangdUnit.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "SymbolCollector.h"
#include "index/CanonicalIncludes.h"
#include "index/Index.h"

View File

@ -8,8 +8,8 @@
#include "refactor/Rename.h"
#include "AST.h"
#include "ClangdUnit.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "SourceCode.h"
#include "index/SymbolCollector.h"
#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"

View File

@ -19,7 +19,7 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_ACTIONS_TWEAK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_ACTIONS_TWEAK_H
#include "ClangdUnit.h"
#include "ParsedAST.h"
#include "Protocol.h"
#include "Selection.h"
#include "clang/Tooling/Core/Replacement.h"

View File

@ -47,8 +47,8 @@
//===----------------------------------------------------------------------===//
#include "AST.h"
#include "ClangdUnit.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "Selection.h"
#include "SourceCode.h"
#include "refactor/Tweak.h"

View File

@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "ClangdUnit.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "Protocol.h"
#include "Selection.h"
#include "SourceCode.h"

View File

@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "ClangdUnit.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "SourceCode.h"
#include "refactor/Tweak.h"
#include "clang/AST/ASTContext.h"

View File

@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "ClangdUnit.h"
#include "Logger.h"
#include "ParsedAST.h"
#include "SourceCode.h"
#include "refactor/Tweak.h"
#include "clang/AST/ASTContext.h"

View File

@ -28,7 +28,6 @@ add_unittest(ClangdUnitTests ClangdTests
CancellationTests.cpp
CanonicalIncludesTests.cpp
ClangdTests.cpp
ClangdUnitTests.cpp
CodeCompleteTests.cpp
CodeCompletionStringsTests.cpp
ContextTests.cpp
@ -50,6 +49,7 @@ add_unittest(ClangdUnitTests ClangdTests
IndexActionTests.cpp
IndexTests.cpp
JSONTransportTests.cpp
ParsedASTTests.cpp
PrintASTTests.cpp
QualityTests.cpp
RenameTests.cpp

View File

@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Annotations.h"
#include "ClangdUnit.h"
#include "Diagnostics.h"
#include "ParsedAST.h"
#include "Path.h"
#include "Protocol.h"
#include "SourceCode.h"

View File

@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#include "ClangdUnit.h"
#include "ExpectedTypes.h"
#include "ParsedAST.h"
#include "TestTU.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"

View File

@ -8,8 +8,8 @@
#include "AST.h"
#include "Annotations.h"
#include "ClangdUnit.h"
#include "Compiler.h"
#include "ParsedAST.h"
#include "SyncAPI.h"
#include "TestFS.h"
#include "TestTU.h"

View File

@ -1,16 +1,21 @@
//===-- ClangdUnitTests.cpp - ClangdUnit tests ------------------*- C++ -*-===//
//===-- ParsedASTTests.cpp ------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// These tests cover clangd's logic to build a TU, which generally uses the APIs
// in ParsedAST and Preamble, via the TestTU helper.
//
//===----------------------------------------------------------------------===//
#include "AST.h"
#include "Annotations.h"
#include "ClangdUnit.h"
#include "Compiler.h"
#include "Diagnostics.h"
#include "ParsedAST.h"
#include "SourceCode.h"
#include "TestFS.h"
#include "TestTU.h"
@ -26,9 +31,9 @@ namespace clang {
namespace clangd {
namespace {
using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::ElementsAreArray;
using ::testing::AllOf;
MATCHER_P(DeclNamed, Name, "") {
if (NamedDecl *ND = dyn_cast<NamedDecl>(arg))
@ -66,7 +71,7 @@ MATCHER_P(WithTemplateArgs, ArgName, "") {
return false;
}
TEST(ClangdUnitTest, TopLevelDecls) {
TEST(ParsedASTTest, TopLevelDecls) {
TestTU TU;
TU.HeaderCode = R"(
int header1();
@ -77,7 +82,7 @@ TEST(ClangdUnitTest, TopLevelDecls) {
EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
}
TEST(ClangdUnitTest, DoesNotGetIncludedTopDecls) {
TEST(ParsedASTTest, DoesNotGetIncludedTopDecls) {
TestTU TU;
TU.HeaderCode = R"cpp(
#define LL void foo(){}
@ -97,7 +102,7 @@ TEST(ClangdUnitTest, DoesNotGetIncludedTopDecls) {
EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
}
TEST(ClangdUnitTest, DoesNotGetImplicitTemplateTopDecls) {
TEST(ParsedASTTest, DoesNotGetImplicitTemplateTopDecls) {
TestTU TU;
TU.Code = R"cpp(
template<typename T>
@ -112,7 +117,7 @@ TEST(ClangdUnitTest, DoesNotGetImplicitTemplateTopDecls) {
ElementsAre(DeclNamed("f"), DeclNamed("s")));
}
TEST(ClangdUnitTest,
TEST(ParsedASTTest,
GetsExplicitInstantiationAndSpecializationTemplateTopDecls) {
TestTU TU;
TU.Code = R"cpp(
@ -156,7 +161,7 @@ TEST(ClangdUnitTest,
AllOf(DeclNamed("foo"), WithTemplateArgs("<bool>"))}));
}
TEST(ClangdUnitTest, TokensAfterPreamble) {
TEST(ParsedASTTest, TokensAfterPreamble) {
TestTU TU;
TU.AdditionalFiles["foo.h"] = R"(
int foo();
@ -187,8 +192,7 @@ TEST(ClangdUnitTest, TokensAfterPreamble) {
EXPECT_EQ(Spelled.back().text(SM), "last_token");
}
TEST(ClangdUnitTest, NoCrashOnTokensWithTidyCheck) {
TEST(ParsedASTTest, NoCrashOnTokensWithTidyCheck) {
TestTU TU;
// this check runs the preprocessor, we need to make sure it does not break
// our recording logic.
@ -208,7 +212,7 @@ TEST(ClangdUnitTest, NoCrashOnTokensWithTidyCheck) {
EXPECT_EQ(T.expandedTokens().drop_back().back().text(SM), "}");
}
TEST(ClangdUnitTest, CanBuildInvocationWithUnknownArgs) {
TEST(ParsedASTTest, CanBuildInvocationWithUnknownArgs) {
// Unknown flags should not prevent a build of compiler invocation.
ParseInputs Inputs;
Inputs.FS = buildTestFS({{testPath("foo.cpp"), "void test() {}"}});
@ -223,7 +227,7 @@ TEST(ClangdUnitTest, CanBuildInvocationWithUnknownArgs) {
EXPECT_NE(buildCompilerInvocation(Inputs, IgnoreDiags), nullptr);
}
TEST(ClangdUnitTest, CollectsMainFileMacroExpansions) {
TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
Annotations TestCase(R"cpp(
#define MACRO_ARGS(X, Y) X Y
^ID(int A);

View File

@ -312,7 +312,7 @@ TEST(SourceCodeTests, SourceLocationInMainFile) {
}
}
TEST(ClangdUnitTest, GetBeginningOfIdentifier) {
TEST(SourceCodeTests, GetBeginningOfIdentifier) {
std::string Preamble = R"cpp(
struct Bar { int func(); };
#define MACRO(X) void f() { X; }

View File

@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
#include "Annotations.h"
#include "ClangdUnit.h"
#include "Compiler.h"
#include "Matchers.h"
#include "ParsedAST.h"
#include "SyncAPI.h"
#include "TestFS.h"
#include "TestTU.h"

View File

@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//
#include "Annotations.h"
#include "ClangdUnit.h"
#include "Context.h"
#include "Diagnostics.h"
#include "Matchers.h"
#include "ParsedAST.h"
#include "Path.h"
#include "Preamble.h"
#include "TUScheduler.h"

View File

@ -17,7 +17,7 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
#include "ClangdUnit.h"
#include "ParsedAST.h"
#include "Path.h"
#include "index/Index.h"
#include "llvm/ADT/StringMap.h"

View File

@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
#include "Annotations.h"
#include "ClangdUnit.h"
#include "Compiler.h"
#include "Matchers.h"
#include "ParsedAST.h"
#include "SyncAPI.h"
#include "TestFS.h"
#include "TestTU.h"

View File

@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
#include "Annotations.h"
#include "ClangdUnit.h"
#include "Compiler.h"
#include "Matchers.h"
#include "ParsedAST.h"
#include "Protocol.h"
#include "SyncAPI.h"
#include "TestFS.h"