Skip to content

Commit 1a97921

Browse files
committed
code review
1 parent d4ceb23 commit 1a97921

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

clang/lib/Tooling/Tooling.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,13 @@ namespace {
644644

645645
class ASTBuilderAction : public ToolAction {
646646
std::vector<std::unique_ptr<ASTUnit>> &ASTs;
647-
CaptureDiagsKind CaptureKinds;
647+
CaptureDiagsKind CaptureKind;
648648

649649
public:
650650
ASTBuilderAction(
651651
std::vector<std::unique_ptr<ASTUnit>> &ASTs,
652-
CaptureDiagsKind CaptureDiagnosticKinds = CaptureDiagsKind::None)
653-
: ASTs(ASTs), CaptureKinds(CaptureDiagnosticKinds) {}
652+
CaptureDiagsKind CaptureDiagnosticsKind = CaptureDiagsKind::None)
653+
: ASTs(ASTs), CaptureKind(CaptureDiagnosticsKind) {}
654654

655655
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
656656
FileManager *Files,
@@ -662,7 +662,7 @@ class ASTBuilderAction : public ToolAction {
662662
Invocation->getDiagnosticOpts(),
663663
DiagConsumer,
664664
/*ShouldOwnClient=*/false),
665-
Files, false, CaptureKinds);
665+
Files, false, CaptureKind);
666666
if (!AST)
667667
return false;
668668

clang/unittests/Sema/HeuristicResolverTest.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "clang/ASTMatchers/ASTMatchers.h"
1111
#include "clang/Basic/Diagnostic.h"
1212
#include "clang/Tooling/Tooling.h"
13-
#include "llvm/ADT/SmallSet.h"
1413
#include "gmock/gmock-matchers.h"
1514
#include "gtest/gtest.h"
1615

@@ -33,24 +32,6 @@ template <typename InputNode>
3332
using ResolveFnT = std::function<std::vector<const NamedDecl *>(
3433
const HeuristicResolver *, InputNode)>;
3534

36-
std::string format_error(const clang::StoredDiagnostic &D) {
37-
std::ostringstream Msg{};
38-
if (D.getLevel() == DiagnosticsEngine::Level::Ignored)
39-
Msg << "Ignored: ";
40-
if (D.getLevel() == DiagnosticsEngine::Level::Note)
41-
Msg << "Note: ";
42-
if (D.getLevel() == DiagnosticsEngine::Level::Remark)
43-
Msg << "Remark: ";
44-
if (D.getLevel() == DiagnosticsEngine::Level::Warning)
45-
Msg << "Warning: ";
46-
if (D.getLevel() == DiagnosticsEngine::Level::Error)
47-
Msg << "Error: ";
48-
if (D.getLevel() == DiagnosticsEngine::Level::Fatal)
49-
Msg << "Fatal: ";
50-
Msg << D.getID() << ": " << D.getMessage().str();
51-
return Msg.str();
52-
}
53-
5435
// Test heuristic resolution on `Code` using the resolution procedure
5536
// `ResolveFn`, which takes a `HeuristicResolver` and an input AST node of type
5637
// `InputNode` and returns a `std::vector<const NamedDecl *>`.
@@ -61,10 +42,17 @@ template <typename InputNode, typename ParamT, typename InputMatcher,
6142
typename... OutputMatchers>
6243
void expectResolution(llvm::StringRef Code, ResolveFnT<ParamT> ResolveFn,
6344
const InputMatcher &IM, const OutputMatchers &...OMS) {
64-
auto TU = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++23"});
45+
auto TU = tooling::buildASTFromCodeWithArgs(
46+
Code, {"-std=c++23"}, "input.cc", "clang-tool",
47+
std::make_shared<PCHContainerOperations>(),
48+
tooling::getClangStripDependencyFileAdjuster(),
49+
tooling::FileContentMappings(), nullptr, llvm::vfs::getRealFileSystem(),
50+
CaptureDiagsKind::All);
6551

6652
for (const auto &D : TU->storedDiagnostics()) {
67-
EXPECT_TRUE(D.getLevel() < DiagnosticsEngine::Error) << format_error(D);
53+
EXPECT_TRUE(D.getLevel() < DiagnosticsEngine::Error)
54+
<< "Unexpected error diagnostic while building AST for test code: "
55+
<< D.getMessage();
6856
}
6957

7058
auto &Ctx = TU->getASTContext();

0 commit comments

Comments
 (0)