From 75d322093fb9ab9cbed7f69b1ef89408d4f94db2 Mon Sep 17 00:00:00 2001 From: intjftw Date: Thu, 3 Feb 2022 16:25:42 +0100 Subject: [PATCH 1/2] Filter C/C++ compile commands. --- plugins/cpp/parser/src/cppparser.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/cpp/parser/src/cppparser.cpp b/plugins/cpp/parser/src/cppparser.cpp index c11687acc..5e2060d5c 100644 --- a/plugins/cpp/parser/src/cppparser.cpp +++ b/plugins/cpp/parser/src/cppparser.cpp @@ -748,8 +748,21 @@ bool CppParser::parseByJson( //--- Read the compilation commands compile database ---// - std::vector compileCommands = + std::vector tempCompileCommands = compDb->getAllCompileCommands(); + std::vector compileCommands; + + const std::vector cppExts{ + ".c", ".cc", ".cpp", ".cxx", ".o", ".so", ".a"}; + + std::copy_if(tempCompileCommands.begin(), tempCompileCommands.end(), + std::back_inserter(compileCommands), [&](clang::tooling::CompileCommand c) + { + auto iter = std::find(cppExts.begin(), cppExts.end(), + fs::extension(c.Filename)); + return iter != cppExts.end(); + }); + std::size_t numCompileCommands = compileCommands.size(); //--- Create a thread pool for the current commands ---// From 05f3e24c74dc3f96d9da85fdaf186f94554af6ff Mon Sep 17 00:00:00 2001 From: intjftw Date: Wed, 16 Feb 2022 12:55:18 +0100 Subject: [PATCH 2/2] Fix according to change requests. --- plugins/cpp/parser/src/cppparser.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/cpp/parser/src/cppparser.cpp b/plugins/cpp/parser/src/cppparser.cpp index 5e2060d5c..3730cbdcc 100644 --- a/plugins/cpp/parser/src/cppparser.cpp +++ b/plugins/cpp/parser/src/cppparser.cpp @@ -748,20 +748,16 @@ bool CppParser::parseByJson( //--- Read the compilation commands compile database ---// - std::vector tempCompileCommands = + std::vector compileCommands = compDb->getAllCompileCommands(); - std::vector compileCommands; - const std::vector cppExts{ - ".c", ".cc", ".cpp", ".cxx", ".o", ".so", ".a"}; - - std::copy_if(tempCompileCommands.begin(), tempCompileCommands.end(), - std::back_inserter(compileCommands), [&](clang::tooling::CompileCommand c) - { - auto iter = std::find(cppExts.begin(), cppExts.end(), - fs::extension(c.Filename)); - return iter != cppExts.end(); - }); + compileCommands.erase( + std::remove_if(compileCommands.begin(), compileCommands.end(), + [&](const clang::tooling::CompileCommand& c) + { + return !isSourceFile(c.Filename); + }), + compileCommands.end()); std::size_t numCompileCommands = compileCommands.size();