[Tooling] Add operator== to CompileCommand

Summary:
It does the obvious thing of comparing all fields.  This will be needed
for a clangd patch I have in the pipeline.

Subscribers: dblaikie, ilya-biryukov, ioeric, cfe-commits

Differential Revision: https://reviews.llvm.org/D49265

llvm-svn: 337284
This commit is contained in:
Simon Marchi 2018-07-17 14:13:05 +00:00
parent d95761d9d0
commit 6567c9e5e0
2 changed files with 37 additions and 0 deletions
clang
include/clang/Tooling
unittests/Tooling

View File

@ -59,6 +59,15 @@ struct CompileCommand {
/// The output file associated with the command.
std::string Output;
friend bool operator==(const CompileCommand &LHS, const CompileCommand &RHS) {
return LHS.Directory == RHS.Directory && LHS.Filename == RHS.Filename &&
LHS.CommandLine == RHS.CommandLine && LHS.Output == RHS.Output;
}
friend bool operator!=(const CompileCommand &LHS, const CompileCommand &RHS) {
return !(LHS == RHS);
}
};
/// Interface for compilation databases.

View File

@ -736,5 +736,33 @@ TEST_F(InterpolateTest, Case) {
EXPECT_EQ(getCommand("foo/bar/baz/shout.C"), "clang -D FOO/BAR/BAZ/SHOUT.cc");
}
TEST(CompileCommandTest, EqualityOperator) {
CompileCommand CCRef("/foo/bar", "hello.c", {"a", "b"}, "hello.o");
CompileCommand CCTest = CCRef;
EXPECT_TRUE(CCRef == CCTest);
EXPECT_FALSE(CCRef != CCTest);
CCTest = CCRef;
CCTest.Directory = "/foo/baz";
EXPECT_FALSE(CCRef == CCTest);
EXPECT_TRUE(CCRef != CCTest);
CCTest = CCRef;
CCTest.Filename = "bonjour.c";
EXPECT_FALSE(CCRef == CCTest);
EXPECT_TRUE(CCRef != CCTest);
CCTest = CCRef;
CCTest.CommandLine.push_back("c");
EXPECT_FALSE(CCRef == CCTest);
EXPECT_TRUE(CCRef != CCTest);
CCTest = CCRef;
CCTest.Output = "bonjour.o";
EXPECT_FALSE(CCRef == CCTest);
EXPECT_TRUE(CCRef != CCTest);
}
} // end namespace tooling
} // end namespace clang