aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Tooling/CompilationDatabase.cpp
diff options
context:
space:
mode:
authorNathan James <n.james93@hotmail.co.uk>2020-11-14 14:03:35 +0000
committerNathan James <n.james93@hotmail.co.uk>2020-11-14 14:03:35 +0000
commit0a6e051a9b30cc1eade2c7a5045c9c643598499b (patch)
treedfc46a553ca38ae74833967071356dda4878f621 /clang/lib/Tooling/CompilationDatabase.cpp
parent8ec7ea3ddce7379e13e8dfb4a5260a6d2004aa1c (diff)
downloadllvm-0a6e051a9b30cc1eade2c7a5045c9c643598499b.zip
llvm-0a6e051a9b30cc1eade2c7a5045c9c643598499b.tar.gz
llvm-0a6e051a9b30cc1eade2c7a5045c9c643598499b.tar.bz2
[NFC] Small refactor to CompilationDatabase
Diffstat (limited to 'clang/lib/Tooling/CompilationDatabase.cpp')
-rw-r--r--clang/lib/Tooling/CompilationDatabase.cpp36
1 files changed, 9 insertions, 27 deletions
diff --git a/clang/lib/Tooling/CompilationDatabase.cpp b/clang/lib/Tooling/CompilationDatabase.cpp
index 2b4c26d..79bb8c0 100644
--- a/clang/lib/Tooling/CompilationDatabase.cpp
+++ b/clang/lib/Tooling/CompilationDatabase.cpp
@@ -199,22 +199,6 @@ public:
SmallVector<std::string, 2> UnusedInputs;
};
-// Unary functor for asking "Given a StringRef S1, does there exist a string
-// S2 in Arr where S1 == S2?"
-struct MatchesAny {
- MatchesAny(ArrayRef<std::string> Arr) : Arr(Arr) {}
-
- bool operator() (StringRef S) {
- for (const std::string *I = Arr.begin(), *E = Arr.end(); I != E; ++I)
- if (*I == S)
- return true;
- return false;
- }
-
-private:
- ArrayRef<std::string> Arr;
-};
-
// Filter of tools unused flags such as -no-integrated-as and -Wa,*.
// They are not used for syntax checking, and could confuse targets
// which don't support these options.
@@ -292,8 +276,7 @@ static bool stripPositionalArgs(std::vector<const char *> Args,
// up with no jobs but then this is the user's fault.
Args.push_back("placeholder.cpp");
- Args.erase(std::remove_if(Args.begin(), Args.end(), FilterUnusedFlags()),
- Args.end());
+ llvm::erase_if(Args, FilterUnusedFlags());
const std::unique_ptr<driver::Compilation> Compilation(
NewDriver->BuildCompilation(Args));
@@ -320,15 +303,14 @@ static bool stripPositionalArgs(std::vector<const char *> Args,
return false;
}
- // Remove all compilation input files from the command line. This is
- // necessary so that getCompileCommands() can construct a command line for
- // each file.
- std::vector<const char *>::iterator End = std::remove_if(
- Args.begin(), Args.end(), MatchesAny(CompileAnalyzer.Inputs));
-
- // Remove all inputs deemed unused for compilation.
- End = std::remove_if(Args.begin(), End, MatchesAny(DiagClient.UnusedInputs));
-
+ // Remove all compilation input files from the command line and inputs deemed
+ // unused for compilation. This is necessary so that getCompileCommands() can
+ // construct a command line for each file.
+ std::vector<const char *>::iterator End =
+ llvm::remove_if(Args, [&](StringRef S) {
+ return llvm::is_contained(CompileAnalyzer.Inputs, S) ||
+ llvm::is_contained(DiagClient.UnusedInputs, S);
+ });
// Remove the -c add above as well. It will be at the end right now.
assert(strcmp(*(End - 1), "-c") == 0);
--End;