diff --git a/src/compile_commands.cc b/src/compile_commands.cc index 27f946b..4c58eda 100644 --- a/src/compile_commands.cc +++ b/src/compile_commands.cc @@ -97,7 +97,8 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: ignore_next=false; continue; } - else if(cmd_arguments[c]=="-o" || cmd_arguments[c]=="-c") { + else if(cmd_arguments[c]=="-o" || cmd_arguments[c]=="-c" || + cmd_arguments[c]=="-x") { // Remove language arguments since some tools add languages not understood by clang ignore_next=true; continue; } @@ -132,28 +133,30 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: arguments.emplace_back("-fretain-comments-from-system-headers"); auto extension=file_path.extension().string(); - if(extension==".h" || //TODO: temporary fix for .h-files (parse as c++) - extension!=".c") - arguments.emplace_back("-xc++"); + bool is_header=CompileCommands::is_header(file_path) || extension.empty(); // Include std C++ headers that are without extensions - if(extension.empty() || (1 CompileCommands::get_arguments(const boost::filesystem: return arguments; } + +bool CompileCommands::is_header(const boost::filesystem::path &path) { + auto ext = path.extension(); + if(ext == ".h" || // c headers + ext == ".hh" || ext == ".hp" || ext == ".hpp" || ext == ".h++" || ext == ".tcc" || // c++ headers + ext == ".cuh") // CUDA headers + return true; + else + return false; +} + +bool CompileCommands::is_source(const boost::filesystem::path &path) { + auto ext = path.extension(); + if(ext == ".c" || // c sources + ext == ".cpp" || ext == ".cxx" || ext == ".cc" || ext == ".C" || ext == ".c++" || // c++ sources + ext == ".cu" || // CUDA sources + ext == ".cl") // OpenCL sources + return true; + else + return false; +} diff --git a/src/compile_commands.h b/src/compile_commands.h index 642cd33..a992019 100644 --- a/src/compile_commands.h +++ b/src/compile_commands.h @@ -19,4 +19,7 @@ public: /// Return arguments for the given file using libclangmm static std::vector get_arguments(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path); + + static bool is_header(const boost::filesystem::path &path); + static bool is_source(const boost::filesystem::path &path); }; diff --git a/src/usages_clang.cc b/src/usages_clang.cc index fd50f37..9ebf624 100644 --- a/src/usages_clang.cc +++ b/src/usages_clang.cc @@ -532,9 +532,9 @@ Usages::Clang::PathSet Usages::Clang::find_paths(const boost::filesystem::path & continue; } - if(is_header(path)) + if(CompileCommands::is_header(path)) paths.emplace(path); - else if(is_source(path)) { + else if(CompileCommands::is_source(path)) { for(auto &command : compile_commands.commands) { if(filesystem::get_normal_path(command.file) == path) { paths.emplace(path); @@ -547,27 +547,6 @@ Usages::Clang::PathSet Usages::Clang::find_paths(const boost::filesystem::path & return paths; } -bool Usages::Clang::is_header(const boost::filesystem::path &path) { - auto ext = path.extension(); - if(ext == ".h" || // c headers - ext == ".hh" || ext == ".hp" || ext == ".hpp" || ext == ".h++" || ext == ".tcc" || // c++ headers - ext == ".cuh") // CUDA headers - return true; - else - return false; -} - -bool Usages::Clang::is_source(const boost::filesystem::path &path) { - auto ext = path.extension(); - if(ext == ".c" || // c sources - ext == ".cpp" || ext == ".cxx" || ext == ".cc" || ext == ".C" || ext == ".c++" || // c++ sources - ext == ".cu" || // CUDA sources - ext == ".cl") // OpenCL sources - return true; - else - return false; -} - std::pair, Usages::Clang::PathSet> Usages::Clang::parse_paths(const std::string &spelling, const PathSet &paths) { std::map paths_includes; PathSet paths_with_spelling; diff --git a/src/usages_clang.h b/src/usages_clang.h index bce406b..56ae3f2 100644 --- a/src/usages_clang.h +++ b/src/usages_clang.h @@ -133,9 +133,6 @@ namespace Usages { static PathSet find_paths(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &debug_path); - static bool is_header(const boost::filesystem::path &path); - static bool is_source(const boost::filesystem::path &path); - static std::pair, PathSet> parse_paths(const std::string &spelling, const PathSet &paths); /// Recursively find and return all the include paths of path