From 9d57b17e209983252f0ebda98087316577f04e6e Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 12 Nov 2018 16:57:34 +0330 Subject: update --- README.md | 8 +++----- cgrep.cpp | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 63fec2c..5fd02a8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ make ## Usage A simple usage example:
```bash -cgrep --func --var --regex nam ./cgrep.cpp +cgrep --func --var --regex n[aA]m ./cgrep.cpp ``` Pleade do note that the regex will pass through both C++ and the regex engine, so if you would want to escape `\`, the regex you pass as the commandline arg would be `\\\\` instead of the normal `\\`.
@@ -24,10 +24,9 @@ For an up-to-date list, you can run `crep --help`.
```bash -all - turns on all switches other than nameddecl + -awk - outputs location in a gawk freidnly format -class - match class declrations only -dir= - recursively goes through all the files and directories. assumes compilation databases are present for all source files. - -extra-arg= - Additional argument to append to the compiler command line - -extra-arg-before= - Additional argument to prepend to the compiler command line -func - match functions only -header - match headers in header inclusions -macro - match macro definitions @@ -35,7 +34,6 @@ For an up-to-date list, you can run `crep --help`.
-memfunc - match member functions only -memvar - match member variables only -nameddecl - matches all named declrations - -p= - Build path -regex= - the regex to match against -struct - match structures only -syshdr - match identifiers in system header as well @@ -43,4 +41,4 @@ For an up-to-date list, you can run `crep --help`.
-var - map variables only ``` -Also, cgrep is a clang tool, so it will accecpt all valid clang commandline options.
+`cgrep` is a clang tool, so it will accecpt all valid clang commandline options.
diff --git a/cgrep.cpp b/cgrep.cpp index a4855be..87c60a1 100644 --- a/cgrep.cpp +++ b/cgrep.cpp @@ -51,7 +51,7 @@ cl::opt CO_CLASS("class", cl::desc("match class declrations only"), cl::in cl::opt CO_STRUCT("struct", cl::desc("match structures only"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done cl::opt CO_UNION("union", cl::desc("match unions only"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done cl::opt CO_MACRO("macro", cl::desc("match macro definitions"), cl::init(false), cl::cat(CGrepCat), cl::Optional); //done -cl::opt CO_HEADER("header", cl::desc("match headers in header inclusions"), cl::init(false), cl::cat(CGrepCat), cl::Optional); +cl::opt CO_HEADER("header", cl::desc("match headers in header inclusions"), cl::init(false), cl::cat(CGrepCat), cl::Optional); //done cl::opt CO_ALL("all", cl::desc("turns on all switches other than nameddecl"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done cl::opt CO_NAMEDDECL("nameddecl", cl::desc("matches all named declrations"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done cl::opt CO_AWK("awk", cl::desc("outputs location in a gawk freidnly format"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done @@ -361,7 +361,17 @@ public: const clang::Module *Imported, SrcMgr::CharacteristicKind FileType) { #endif - if (CO_HEADER) {} + if (CO_HEADER) { + CheckSLValidity(HashLoc); + SourceLocation SL = Devi::SourceLocationHasMacro(HashLoc, Rewrite, "start"); + if (Devi::IsTheMatchInSysHeader(CO_SYSHDR, SM, SL)) return void(); + if (!Devi::IsTheMatchInMainFile(CO_MAINFILE, SM, SL)) return void(); + std::string name = FileName.str(); + if (regex_handler(REGEX_PP(CO_REGEX), name)) { + std::cout << name << "\t"; + std::cout << SL.printToString(SM) << "\n"; + } + } } private: -- cgit v1.2.3