diff options
Diffstat (limited to '')
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | cgrep.cpp | 34 | ||||
-rw-r--r-- | compile_commands.json | 2 | ||||
-rw-r--r-- | pch.hpp | 1 |
4 files changed, 29 insertions, 9 deletions
@@ -6,6 +6,7 @@ <img alt="Coverity Scan Build Status" src="https://scan.coverity.com/projects/19431/badge.svg"/> </a> +[![Coverage Status](https://coveralls.io/repos/github/bloodstalker/cgrep/badge.svg?branch=master)](https://coveralls.io/github/bloodstalker/cgrep?branch=master) # cgrep `grep` for C/C++ source files.<br/> @@ -19,11 +19,11 @@ using namespace clang::tooling; /*************************************************************************************************/ namespace { static llvm::cl::OptionCategory CGrepCat("cgrep options"); -cl::opt<std::string> CO_DIRECTORY( +cl::opt<std::string> CO_RECURSIVE( "dir", cl::desc("recursively goes through all the files and directories. assumes " - "compilation databases are present for all source files."), - cl::init(""), cl::cat(CGrepCat), cl::Optional); + "compilation databases are present for all source files."), + cl::init(""), cl::cat(CGrepCat), cl::Optional); // done cl::opt<std::string> CO_REGEX("regex", cl::desc("the regex to match against"), cl::init(""), cl::cat(CGrepCat), cl::Required); // done @@ -120,6 +120,20 @@ cl::opt<int> CO_B( #define CLEAR "\033[2J" /** + * @brief recursively goes through all the directories starting from path + * + * @param path + */ +static void dig(std::string path) { + for (const auto &entry : std::filesystem::directory_iterator(path)) { + std::cout << entry.path() << "\n"; + if (true == entry.is_directory()) { + dig(entry.path()); + } + } +} + +/** * @brief does some preprocessing on the regex string we get as input * @param rx_str * @return the preprocessed string @@ -172,8 +186,9 @@ void output_handler(const MatchFinder::MatchResult &MR, SourceRange SR, std::cout << line[i]; } } - if (isdecl) - std::cout << GREEN << "\t<---defined here" << NORMAL << "\n"; + if (isdecl) { + std::cout << GREEN << "\t<---declared here" << NORMAL << "\n"; + } } else { std::cout << line << "\n"; } @@ -228,10 +243,12 @@ public: return void(); std::string name = FD->getNameAsString(); if (regex_handler(REGEX_PP(CO_REGEX), name)) { + ast_type_traits::DynTypedNode DNode = ast_type_traits::DynTypedNode::create(*FD); + NamedDecl const * ND = DNode.get<NamedDecl>(); auto StartLocation = FD->getLocation(); auto EndLocation = StartLocation.getLocWithOffset(name.size() - 1); auto Range = SourceRange(StartLocation, EndLocation); - output_handler(MR, Range, *MR.SourceManager, true); + output_handler(MR, Range, *MR.SourceManager, FD->isThisDeclarationADefinition()); } } } @@ -247,8 +264,6 @@ public: virtual void run(const MatchFinder::MatchResult &MR) { const FieldDecl *FD = MR.Nodes.getNodeAs<clang::FieldDecl>("fielddecl"); if (FD) { - // IdentifierInfo* ID = VD->getIdentifier(); - // SourceRange SR = VD->getSourceRange(); SourceRange SR = FD->getSourceRange(); SourceLocation SL = SR.getBegin(); CheckSLValidity(SL); @@ -769,6 +784,9 @@ int main(int argc, const char **argv) { op.getSourcePathList(); ClangTool Tool(op.getCompilations(), op.getSourcePathList()); int ret = Tool.run(newFrontendActionFactory<AppFrontendAction>().get()); + if ("" != CO_RECURSIVE) { + dig(CO_RECURSIVE); + } return ret; } /*************************************************************************************************/ diff --git a/compile_commands.json b/compile_commands.json index fcd399f..2803ad9 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1,6 +1,6 @@ [ { - "command": "c++ -c -include-pch pch.hpp.gch -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++11 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cgrep.o cgrep.cpp", + "command": "c++ -c -include-pch pch.hpp.gch -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cgrep.o cgrep.cpp", "directory": "/home/bloodstalker/extra/cgrep", "file": "/home/bloodstalker/extra/cgrep/cgrep.cpp" } @@ -18,3 +18,4 @@ #include <regex> #include <string> #include <vector> +#include <filesystem> |