From a347be5b890ebf696a046cc182c5ccd163c4c571 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 22 Mar 2020 10:14:16 +0430 Subject: updated the README. fixed a bug with declrefexpr where it was checking too late whether the match was expanded from a macro which would result in an assertion failure. --- README.md | 14 +++++++++++--- cgrep.cpp | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b09bb20..2d6035a 100644 --- a/README.md +++ b/README.md @@ -36,16 +36,24 @@ For windows builds, cygwin builds are supported. Get llvm and clang along with t A simple usage example: ```bash -cgrep -A 1 -B 1 --func --declrefexpr --regex n[aA]m --noclor --nodecl ./cgrep.cpp +cgrep -A 1 -B 1 --func --declrefexpr --regex n[aA]m --nocolor --nodecl ./myawesomecode.cpp ``` -Please 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 command line arg would be `\\\\` instead of the normal `\\`. -In order for cgrep to work, you need to have a compilation database, tools like `cmake` can generate one for you. +In order for cgrep to work, you need to have a compilation database, tools like `cmake` can generate one for you.
+You can, by all means, run cgrep without a compilation databse but whether that works or not really depends on your source file. Can you build your source file with clang without passing it any options? +If the answer to that is yes, then you can just run cgrep without a compilation databse like so:
+```bash +cgrep -A 1 -B 1 --func --declrefexpr --regex n[aA]m --nocolor --nodecl ./myawesomecode.cpp -- +``` +Otherwise you need a compilation database.
+ +Please 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 command line arg would be `\\\\` instead of the normal `\\`.
If your build tool doesn't do that, you can just use [bear](https://github.com/rizsotto/Bear) or [scan-build](https://github.com/rizsotto/scan-build). You can also skip the compilation database altogether passing cgrep `--` after the input file name which means you have chosen not to pass it anything. You can pass the options by hand since cgrep is a Clang instance so it recognizes every option clang has. cgrep uses ANSI escape sequences for colors so your terminal should support those. In case your terminal does not support ANSI escape sequences, you can silence those using the `--nocolor` option. + By default, cgrep will print out the declaration location for a match. In case you don't want those in the output, you can pass cgrep the `--nodecl` switch. You can use `--extra-arg==--std=` to tell cgrep which C-family language the source file is supposed to be in. diff --git a/cgrep.cpp b/cgrep.cpp index 2aa6575..e259d08 100644 --- a/cgrep.cpp +++ b/cgrep.cpp @@ -576,10 +576,10 @@ public: const NamedDecl *ND = DRE->getFoundDecl(); std::string name = ND->getNameAsString(); SourceLocation SL = DRE->DEVI_GETLOCSTART(); + SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start"); SourceLocation SLE = SL.getLocWithOffset(name.length() - 1); // SourceLocation SLE = DRE->DEVI_GETLOCEND(); CheckSLValidity(SL); - SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start"); if (Devi::IsTheMatchInSysHeader(CO_SYSHDR, MR, SL)) return void(); if (!Devi::IsTheMatchInMainFile(CO_MAINFILE, MR, SL)) -- cgit v1.2.3