r337284 - [Tooling] Add operator== to CompileCommand
Simon Marchi via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 17 07:13:05 PDT 2018
Author: simark
Date: Tue Jul 17 07:13:05 2018
New Revision: 337284
URL: http://llvm.org/viewvc/llvm-project?rev=337284&view=rev
Log:
[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
Modified:
cfe/trunk/include/clang/Tooling/CompilationDatabase.h
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
Modified: cfe/trunk/include/clang/Tooling/CompilationDatabase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CompilationDatabase.h?rev=337284&r1=337283&r2=337284&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/CompilationDatabase.h (original)
+++ cfe/trunk/include/clang/Tooling/CompilationDatabase.h Tue Jul 17 07:13:05 2018
@@ -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.
Modified: cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp?rev=337284&r1=337283&r2=337284&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp Tue Jul 17 07:13:05 2018
@@ -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
More information about the cfe-commits
mailing list