Code Monkey home page Code Monkey logo

cgrep's Introduction

example workflow Build status Codacy Badge FOSSA Status Gitter

cgrep

cgrep is grep for C-family source files.

You can write something like this:

cgrep --regex [a-z]* --func -A 1 -B 1 myawesomecode.cpp

and it will match your regex against all function declarations, and will output the result, plus one line before and after the context.

cgrep is implemented using Clang's libtooling libraries.

Features

  • It's basically Clang regexing it's way through your C-family source-code. You have all the context you can ever need.
  • Can output whether to print the declaration of a match even if the match itself is not a declaration along with the matched result.
  • Can output matches in a script-friendly format which could be used in turn by a secondary script.

Will cgrep try to implement all of the grep switches?

The answer is no. The main distinction is that cgrep is only meant to work on C-family source files not text files. Most of grep's switches don't apply to the usecase or provide almost no benefits at all.
That being said, I might have missd something so you can always make suggestions in the form of a new issue.

Will cgrep support a new switch that matches X?

If it makes sense sure, but I want to be careful with what cgrep implements. If everything gets implemented, that is, cgrep implements every possible switch(well, a subset of "all"), we end up with an inferior version of clang-query that would be too slow to be of any use to anyone. So please keep in mind that I will have to draw the line somewhere.

Building

You can get the source files from the release page or a release branch usually named rcx.
The Release Candidate branches are the release branches. Master is the dev branch.

Fedora

sudo dnf install clang-devel llvm-devel llvm-static

Ubuntu

sudo apt install clang-X llvm-X-dev libclang-common-X-dev libclang-X-dev
Replace X with the LLVM version of your choice.

Debian

sudo apt install clang-X llvm-X-dev libclang-common-X-dev libclang-X-dev
Replace X with the LLVM version of your choice.

Arch

You can get cgrep from AUR. Thanks to schra.

Cygwin

You will need libclang-devel, libllvm-devel, clang, libiconv-devel.

Good Ole' Makefiles

NOTE:the monolithic libtooling library is not supported with the good ole makefiles. Look down below at Cmake for that.
NOTE:Starting with llvm/clang 15.0.0 the gnu makefile should not be able to build cgrep anymore. It will be kept for older versions but moving on only the cmake build will receive updates.
Assuming you have the llvm/clang libraries (the build file will read your llvm options using llvm-config so make sure it's in path), just run:

git clone https://github.com/bloodstalker/cgrep
cd cgrep
git submodule init
git submodule update
make

After the build is finished you can choose to run make install. It will simply symlink cgrep into /usr/local/bin.

If you have installed LLVM but don't have llvm-config, you are missing the dev package for LLVM.
cgrep supports LLVM 7,8,9,10,11,12,13,14,15 and 16.
We support whatever version we can get from https://apt.llvm.org/llvm.sh. The versions above are the ones currently provided by the script. When they remove a version we drop support. When they add a new one we start supporting that.
The makefile assumes clang is called clang and llvm-config is called llvm-config. On some distros, the names might not be the same. In those cases use CXX and LLVM_CONF to pass the values to the makefile like so:

make CXX=clang-15 LLVM_CONF=llvm-config-15

For windows builds, cygwin builds are supported. Get llvm and clang along with their sources and build like usual. If you run into problems while building on cygwin, you can take a look at the appveyor.yml file under the repository root.

Cmake

To do an out-of-source build simply do:

git clone https://github.com/terminaldweller/cgrep
cd cgrep
git submodule init
git submodule update
mkdir build
cmake ../ -DLLVM_CONF=llvm-config-15 -DCMAKE_CXX_COMPILER=clang++-15 -DUSE_MONOLITH_LIBTOOLING=ON -DLLVM_PACKAGE_VERSION=15.0.0
make

The 4 variables denote the llvm-config executable name, the clang++ name and finally, the 3rd one tells cmake whether to build using the single c++ libtooling library or just use the old way with all the libtooling libraries. The last one lets cmake know which version of llvm/clang is being used.

Usage

A simple usage example:

cgrep -A 1 -B 1 --func --declrefexpr --regex n[aA]m --nocolor --nodecl ./myawesomecode.cpp

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 database 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 database like so:

cgrep -A 1 -B 1 --func --declrefexpr --regex n[aA]m --nocolor --nodecl ./myawesomecode.cpp --

the -- at the end is an explicit way of saying that you will not be providing a compilation database. Newer versions of clang will try to still go through with the compilation even if there is no compilation database found. 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 or 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 using --extra-arg= since cgrep is a clang instance so it recognizes every option clang has. As a general rule, if you're not going to pass cgrep a compilation database, it's always better to explicitly let cgrep know using --. Not doing so can result in instances when cgrep behaves in a way that you might not expect it.

cgrep uses ANSI escape sequences for colors so your terminal should support those. In case your terminal does not support ANSI escape sequences or you don't want thos for any other reason, 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.

Options

Here's an option list, though it's usually not up-to-date.
For an up-to-date list, you can run cgrep --help or look at the man page.

  -A=<int>                    - Same as grep, how many lines after the matched line to print. Defaults to 0.
  -B=<int>                    - Same as grep, how many lines before the matched line to print. Defaults to 0.
  --all                       - Turns on all switches other than nameddecl.
  --awk                       - Outputs location in a gawk friendly format, not meant for human consumption. Defaults to false.
  --call                      - Match function calls.
  --class                     - Match class declarations.
  --cxxcall                   - Match member function calls.
  --declrefexpr               - Matches declrefexpr.
  --dir=<string>              - Recursively goes through all the files and directories. Assumes compilation databases are present for all source files.
  --extra-arg=<string>        - Additional argument to append to the compiler command line
  --extra-arg-before=<string> - Additional argument to prepend to the compiler command line
  --func                      - Match functions.
  --header                    - Match headers in header inclusions.
  --macro                     - Match macro definitions.
  --mainfile                  - Match identifiers in the main file only. Defaults to true.
  --memfunc                   - Match member functions.
  --memvar                    - Match member variables.
  --nameddecl                 - Matches all named declarations.
  --nocolor                   - For terminals that don't support ANSI escape sequences. The default is to false.
  --nodecl                    - For switches that are not declarations, don't print declarations. Defaults to false.
  -p=<string>                 - Build path
  --recorddecl                - Match a record declaration.
  --regex=<string>            - The regex to match against.
  --struct                    - Match structures.
  --syshdr                    - Match identifiers in system header as well. Defaults to false.
  --union                     - Match unions.
  --var                       - Match variables.

cgrep is a clang tool, so it will accept all valid clang command line options.

Known Issues

cgrep complains that it cannot find stddef.h or some other similar header. If that happens to you , it's because cgrep can't find the clang built-in headers. run llvm-config --libdir, then head on to clang. Inside that directory you should see one(or maybe more) llvm/clang versions. Pick the one you used to build cgrep against. Inside that directory there will be a directory named include. Pass that to cgrep any way you see fit.
Alternatively, $(llvm-config --libdir)/clang/$(llvm-config --version)/include should give the path cgrep needs to include. If you build your llvm/clang from upstream, this might not work. SVN builds will have the svn string attached to the version number.
You could,for example, use --extra-arg=-I/usr/lib/llvm-9/lib/clang/9.0.0/include to call cgrep or you could just alias cgrep to cgrep --extra-arg=-I/usr/lib/llvm-9/lib/clang/9.0.0/include.

cgrep, replaces the clang diagnosticConsumer with a simple one that only tells you there are erros during the compilation. You can get the normal clang output using the --clangdiag switch. The decision was made to declutter the output generated by cgrep.

License

cgrep is licensed under GPL-3.0. Everything else is licensed under it's own respective license.

FOSSA Status

cgrep's People

Contributors

fossabot avatar pjunger avatar schra avatar terminaldweller avatar yeger00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cgrep's Issues

cgrep doesn't build with Clang 10 (depending on how it is packaged)

On operating systems such as Arch Linux, the libclang libraries of Clang 10 are package differently now.

See https://www.archlinux.org/todo/llvm-10/:

All of clang's C++ API is now shipped as libclang-cpp.so instead of
the numerous component libraries we had before. This change will
require patching in most packages to use the new library name. Look
for upstream commits that support the new library; if that fails,
Fedora and/or Gentoo should have patches for this.

This essentially means that it's not possible to build cgrep on Arch Linux now. For the AUR package I maintain I created a simple patch file that fixes this problem: https://github.com/schra/pkgbuilds/blob/d551ebc734a02f3418ff0df58a25d314cb973084/cgrep-clang/adjust-libclang-lib-names.patch

I think a proper fix would check if the library libclang-cpp exists. If yes, use it. If no, use the smaller libraries as done before.

Btw, Ubuntu ships both libclang-cpp.so.10 and also the smaller libraries.

cmake with -DUSE_MONOLITH_LIBTOOLING=ON fails to build

I'm on the latest commit 308bc02 and my Clang/ LLVM is version 12.0.1

Building with cmake and -DUSE_MONOLITH_LIBTOOLING=ON doesn't work:

$ cmake -B ../build -S . -DUSE_MONOLITH_LIBTOOLING=ON
-- The C compiler identification is GNU 11.1.0
-- The CXX compiler identification is GNU 11.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/andre/tmp/build

$ cmake --build ../build
Consolidate compiler generated dependencies of target cgrep
[ 33%] Building CXX object CMakeFiles/cgrep.dir/cgrep.cpp.o
[ 66%] Building CXX object CMakeFiles/cgrep.dir/cfe-extra/cfe_extra.cpp.o
/home/andre/tmp/cgrep/cfe-extra/cfe_extra.cpp: In function ‘clang::SourceLocation Devi::SourceLocationHasMacro(clang::SourceLocation, clang::Rewriter&, std::string)’:
/home/andre/tmp/cgrep/cfe-extra/cfe_extra.cpp:43:114: error: conversion from ‘clang::CharSourceRange’ to non-scalar type ‘std::pair<clang::SourceLocation, clang::SourceLocation>’ requested
   43 |     std::pair <SourceLocation, SourceLocation> expansionRange = Rewrite.getSourceMgr().getImmediateExpansionRange(SL);
      |                                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:242:51: error: expected ‘,’ or ‘...’ before ‘&’ token
  242 |                     AST_TYPE_TRAITS::DynTypedNode &DTN) {
      |                                                   ^
/home/andre/tmp/cgrep/cgrep.cpp: In function ‘void output_handler(const clang::ast_matchers::MatchFinder::MatchResult&, clang::SourceRange, clang::SourceManager&, bool, int)’:
/home/andre/tmp/cgrep/cgrep.cpp:277:37: error: ‘DTN’ was not declared in this scope
  277 |               const NamedDecl *ND = DTN.get<NamedDecl>();
      |                                     ^~~
/home/andre/tmp/cgrep/cgrep.cpp:277:54: error: expected primary-expression before ‘>’ token
  277 |               const NamedDecl *ND = DTN.get<NamedDecl>();
      |                                                      ^
/home/andre/tmp/cgrep/cgrep.cpp:277:56: error: expected primary-expression before ‘)’ token
  277 |               const NamedDecl *ND = DTN.get<NamedDecl>();
      |                                                        ^
/home/andre/tmp/cgrep/cgrep.cpp:283:52: error: expected primary-expression before ‘>’ token
  283 |               const CallExpr *CE = DTN.get<CallExpr>();
      |                                                    ^
/home/andre/tmp/cgrep/cgrep.cpp:283:54: error: expected primary-expression before ‘)’ token
  283 |               const CallExpr *CE = DTN.get<CallExpr>();
      |                                                      ^
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:357:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  357 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void FunctionHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:351:60: error: ‘DNode’ was not declared in this scope
  351 |                        FD->isThisDeclarationADefinition(), DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:388:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  388 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void FieldHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:382:60: error: ‘DNode’ was not declared in this scope
  382 |         output_handler(MR, Range, *MR.SourceManager, true, DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:422:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  422 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void CXXMethodHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:416:60: error: ‘DNode’ was not declared in this scope
  416 |                        MD->isThisDeclarationADefinition(), DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:453:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  453 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void VDecl::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:447:60: error: ‘DNode’ was not declared in this scope
  447 |         output_handler(MR, Range, *MR.SourceManager, true, DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:484:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  484 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void ClassDecl::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:478:60: error: ‘DNode’ was not declared in this scope
  478 |         output_handler(MR, Range, *MR.SourceManager, true, DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:515:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  515 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void StructHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:509:60: error: ‘DNode’ was not declared in this scope
  509 |         output_handler(MR, Range, *MR.SourceManager, true, DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:546:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  546 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void UnionHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:540:60: error: ‘DNode’ was not declared in this scope
  540 |         output_handler(MR, Range, *MR.SourceManager, true, DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:577:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  577 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void NamedDeclHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:571:60: error: ‘DNode’ was not declared in this scope
  571 |         output_handler(MR, Range, *MR.SourceManager, true, DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:611:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  611 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void DeclRefExprHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:150:26: error: ‘const class clang::DeclRefExpr’ has no member named ‘getLocStart’
  150 | #define DEVI_GETLOCSTART getLocStart
      |                          ^~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:150:26: note: in definition of macro ‘DEVI_GETLOCSTART’
  150 | #define DEVI_GETLOCSTART getLocStart
      |                          ^~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:605:76: error: ‘DTN’ was not declared in this scope
  605 |         output_handler(MR, SourceRange(SL, SLE), *MR.SourceManager, false, DTN);
      |                                                                            ^~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:646:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  646 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void CallExprHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:150:26: error: ‘const class clang::CallExpr’ has no member named ‘getLocStart’
  150 | #define DEVI_GETLOCSTART getLocStart
      |                          ^~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:150:26: note: in definition of macro ‘DEVI_GETLOCSTART’
  150 | #define DEVI_GETLOCSTART getLocStart
      |                          ^~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:151:24: error: ‘const class clang::CallExpr’ has no member named ‘getLocEnd’
  151 | #define DEVI_GETLOCEND getLocEnd
      |                        ^~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:151:24: note: in definition of macro ‘DEVI_GETLOCEND’
  151 | #define DEVI_GETLOCEND getLocEnd
      |                        ^~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:640:61: error: ‘DTN’ was not declared in this scope
  640 |         output_handler(MR, Range, *MR.SourceManager, false, DTN);
      |                                                             ^~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:682:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  682 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void CXXCallExprHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:676:61: error: ‘DNode’ was not declared in this scope
  676 |         output_handler(MR, Range, *MR.SourceManager, false, DNode);
      |                                                             ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:714:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  714 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void RecordFieldHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:708:60: error: ‘DNode’ was not declared in this scope
  708 |         output_handler(MR, Range, *MR.SourceManager, true, DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:745:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  745 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual void RecordHandler::run(const clang::ast_matchers::MatchFinder::MatchResult&)’:
/home/andre/tmp/cgrep/cgrep.cpp:160:32: error: ‘clang::ast_type_traits’ has not been declared
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:160:32: note: in definition of macro ‘AST_TYPE_TRAITS’
  160 | #define AST_TYPE_TRAITS clang::ast_type_traits
      |                                ^~~~~~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:739:60: error: ‘DNode’ was not declared in this scope
  739 |         output_handler(MR, Range, *MR.SourceManager, true, DNode);
      |                                                            ^~~~~
/home/andre/tmp/cgrep/cgrep.cpp: At global scope:
/home/andre/tmp/cgrep/cgrep.cpp:768:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  768 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp:800:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  800 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp:812:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  812 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp:824:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  824 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp:897:42: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  897 |   const SourceManager &SM [[maybe_unused]];
      |                                          ^
/home/andre/tmp/cgrep/cgrep.cpp:898:36: warning: ‘maybe_unused’ attribute ignored [-Wattributes]
  898 |   Rewriter &Rewrite [[maybe_unused]];
      |                                    ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual std::unique_ptr<clang::ASTConsumer> TraceFrontendAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)’:
/home/andre/tmp/cgrep/cgrep.cpp:1059:18: error: ‘make_unique’ is not a member of ‘llvm’; did you mean ‘std::make_unique’?
 1059 |     return llvm::make_unique<TraceASTConsumer>(TheRewriter);
      |                  ^~~~~~~~~~~
In file included from /usr/include/c++/11.1.0/memory:76,
                 from /usr/include/llvm/Support/Casting.h:20,
                 from /usr/include/clang/Basic/LLVM.h:21,
                 from /usr/include/clang/Basic/DiagnosticIDs.h:17,
                 from /usr/include/clang/Basic/Diagnostic.h:17,
                 from /usr/include/clang/AST/NestedNameSpecifier.h:18,
                 from /usr/include/clang/AST/Type.h:21,
                 from /usr/include/clang/AST/CanonicalType.h:17,
                 from /usr/include/clang/AST/ASTContext.h:19,
                 from /usr/include/clang/AST/AST.h:17,
                 from /home/andre/tmp/cgrep/./cfe-extra/cfe_extra.h:29,
                 from /home/andre/tmp/cgrep/cgrep.cpp:10:
/usr/include/c++/11.1.0/bits/unique_ptr.h:973:5: note: ‘std::make_unique’ declared here
  973 |     make_unique(_Args&&...) = delete;
      |     ^~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:1059:46: error: expected primary-expression before ‘>’ token
 1059 |     return llvm::make_unique<TraceASTConsumer>(TheRewriter);
      |                                              ^
/home/andre/tmp/cgrep/cgrep.cpp: In member function ‘virtual std::unique_ptr<clang::ASTConsumer> CgrepFrontendAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)’:
/home/andre/tmp/cgrep/cgrep.cpp:1082:15: error: ‘make_unique’ is not a member of ‘llvm’; did you mean ‘std::make_unique’?
 1082 |         llvm::make_unique<PPInclusion>(&CI.getSourceManager(), &TheRewriter));
      |               ^~~~~~~~~~~
In file included from /usr/include/c++/11.1.0/memory:76,
                 from /usr/include/llvm/Support/Casting.h:20,
                 from /usr/include/clang/Basic/LLVM.h:21,
                 from /usr/include/clang/Basic/DiagnosticIDs.h:17,
                 from /usr/include/clang/Basic/Diagnostic.h:17,
                 from /usr/include/clang/AST/NestedNameSpecifier.h:18,
                 from /usr/include/clang/AST/Type.h:21,
                 from /usr/include/clang/AST/CanonicalType.h:17,
                 from /usr/include/clang/AST/ASTContext.h:19,
                 from /usr/include/clang/AST/AST.h:17,
                 from /home/andre/tmp/cgrep/./cfe-extra/cfe_extra.h:29,
                 from /home/andre/tmp/cgrep/cgrep.cpp:10:
/usr/include/c++/11.1.0/bits/unique_ptr.h:973:5: note: ‘std::make_unique’ declared here
  973 |     make_unique(_Args&&...) = delete;
      |     ^~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:1082:38: error: expected primary-expression before ‘>’ token
 1082 |         llvm::make_unique<PPInclusion>(&CI.getSourceManager(), &TheRewriter));
      |                                      ^
/home/andre/tmp/cgrep/cgrep.cpp:1094:18: error: ‘make_unique’ is not a member of ‘llvm’; did you mean ‘std::make_unique’?
 1094 |     return llvm::make_unique<CgrepASTConsumer>(TheRewriter);
      |                  ^~~~~~~~~~~
In file included from /usr/include/c++/11.1.0/memory:76,
                 from /usr/include/llvm/Support/Casting.h:20,
                 from /usr/include/clang/Basic/LLVM.h:21,
                 from /usr/include/clang/Basic/DiagnosticIDs.h:17,
                 from /usr/include/clang/Basic/Diagnostic.h:17,
                 from /usr/include/clang/AST/NestedNameSpecifier.h:18,
                 from /usr/include/clang/AST/Type.h:21,
                 from /usr/include/clang/AST/CanonicalType.h:17,
                 from /usr/include/clang/AST/ASTContext.h:19,
                 from /usr/include/clang/AST/AST.h:17,
                 from /home/andre/tmp/cgrep/./cfe-extra/cfe_extra.h:29,
                 from /home/andre/tmp/cgrep/cgrep.cpp:10:
/usr/include/c++/11.1.0/bits/unique_ptr.h:973:5: note: ‘std::make_unique’ declared here
  973 |     make_unique(_Args&&...) = delete;
      |     ^~~~~~~~~~~
/home/andre/tmp/cgrep/cgrep.cpp:1094:46: error: expected primary-expression before ‘>’ token
 1094 |     return llvm::make_unique<CgrepASTConsumer>(TheRewriter);
      |                                              ^
make[2]: *** [CMakeFiles/cgrep.dir/build.make:90: CMakeFiles/cgrep.dir/cfe-extra/cfe_extra.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/cgrep.dir/build.make:76: CMakeFiles/cgrep.dir/cgrep.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/cgrep.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

As already mentioned in #14, using make fails to compile, however, if I add the patch from that issue, make actually compiles successfully:

$ make
clang++ -fpic -I/usr/include -std=c++14   -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/build/llvm/src/llvm-12.0.1.src/tools/clang/include -I/usr/tools/clang/include -std=c++17 -fexceptions  -c cgrep.cpp -o cgrep.o
clang++ cgrep.o cfe-extra/cfe_extra.o -Wl,--start-group -lclang-cpp -lstdc++ -lLLVMRuntimeDyld -lm -Wl,--end-group -L/usr/lib  -lLLVM-12  -o cgrep

This is the patch:

diff --git a/makefile b/makefile
index 57414b3..930bdb9 100644
--- a/makefile
+++ b/makefile
@@ -38,12 +38,7 @@ LLVM_CXX_FLAGS=$(shell $(LLVM_CONF) --cxxflags)
 LLVM_CXX_FLAGS+=-I$(shell $(LLVM_CONF) --src-root)/tools/clang/include\
  -I$(shell $(LLVM_CONF) --obj-root)/tools/clang/include\
  -std=c++17 -fexceptions
-LLVM_LD_FLAGS=-Wl,--start-group -lclangAST -lclangAnalysis -lclangBasic\
- -lclangDriver -lclangEdit -lclangFrontend -lclangFrontendTool\
- -lclangLex -lclangParse -lclangSema -lclangEdit -lclangASTMatchers\
- -lclangRewrite -lclangRewriteFrontend -lclangStaticAnalyzerFrontend\
- -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore\
- -lclangSerialization -lclangToolingCore -lclangTooling -lstdc++\
+LLVM_LD_FLAGS=-Wl,--start-group -lclang-cpp -lstdc++\
  -lLLVMRuntimeDyld -lm -Wl,--end-group
 LLVM_LD_FLAGS+=$(shell $(LLVM_CONF) --ldflags --libs --system-libs)

Maybe the makefile and the CMakeLists.txt are out of sync, if one builds and the other doesn't?

can't find stddef.h

cgrep complains that it cannot find stddef.h or some other similar header. If that happens to you , it's because cgrep can't find the clang built-in headers. run llvm-config --libdir, then head on to clang. Inside that directory you should see one(or maybe more) llvm/clang versions. Pick the one you used to build cgrep against. Inside that directory there will be a directory named include. Pass that to cgrep any way you see fit.
Alternatively, $(llvm-config --libdir)/clang/$(llvm-config --version)/include should give the path cgrep needs to include.
You could,for example, use --extra-arg=-I/usr/lib/llvm-9/lib/clang/9.0.0/include to call cgrep or you could just alias cgrep to cgrep --extra-arg=-I/usr/lib/llvm-9/lib/clang/9.0.0/include.

Segmentation fault when grepping

What I observe:

$ ~/Git/cgrep/cgrep --var --regex ".*[a-z][A-Z].*" aerialmap_display.cpp
Segmentation fault

Also don't hit me, but with the debug symbol everything works :(

$ ~/Git/cgrep/cgrep-dbg --var --regex ".*[a-z][A-Z].*" aerialmap_display.cpp
/home/andre/Git/rviz_satellite/src/aerialmap_display.cpp:489:19:      TileId const toFind{ center_tile_->tile_server, { xx, yy }, center_tile_->zoom };

Backtrace (but without debug symbols as mentioned above):

$ lldb-10 /home/andre/.local/bin/cgrep
(lldb) target create "/home/andre/.local/bin/cgrep"
Current executable set to '/home/andre/.local/bin/cgrep' (x86_64).
(lldb) r --var --regex ".*[a-z][A-Z].*" aerialmap_display.cpp
Process 7022 launched: '/home/andre/.local/bin/cgrep' (x86_64)
Process 7022 stopped
* thread #1, name = 'cgrep', stop reason = signal SIGSEGV: invalid address (fault address: 0x108)
    frame #0: 0x00000000007ca20a cgrep`clang::SourceManager::getDecomposedExpansionLoc(clang::SourceLocation) const + 26
cgrep`clang::SourceManager::getDecomposedExpansionLoc:
->  0x7ca20a <+26>: movl   0x108(%rdi), %esi
    0x7ca210 <+32>: movl   %ebx, %edx
    0x7ca212 <+34>: callq  0x453990                  ; clang::SourceManager::isOffsetInFileID(clang::FileID, unsigned int) const
    0x7ca217 <+39>: testb  %al, %al
(lldb) bt
* thread #1, name = 'cgrep', stop reason = signal SIGSEGV: invalid address (fault address: 0x108)
  * frame #0: 0x00000000007ca20a cgrep`clang::SourceManager::getDecomposedExpansionLoc(clang::SourceLocation) const + 26
    frame #1: 0x00000000007cd653 cgrep`clang::SourceManager::getFileCharacteristic(clang::SourceLocation) const + 19
    frame #2: 0x00000000004b1395 cgrep`Devi::IsTheMatchInSysHeader(bool, clang::ast_matchers::MatchFinder::MatchResult const&, clang::SourceLocation) + 21
    frame #3: 0x000000000049c1ed cgrep`VDecl::run(clang::ast_matchers::MatchFinder::MatchResult const&) + 333
    frame #4: 0x00000000010662e1 cgrep`clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch(clang::ast_matchers::BoundNodes const&) + 193
    frame #5: 0x00000000010808ac cgrep`clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*) + 204
    frame #6: 0x0000000001065b62 cgrep`clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::ast_type_traits::DynTypedNode const&) + 1154
    frame #7: 0x000000000107c92b cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTypeLoc(clang::TypeLoc) + 2795
    frame #8: 0x000000000108045b cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) + 667
    frame #9: 0x00000000010680c4 cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) + 1748
    frame #10: 0x000000000106d1d7 cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) + 87
    frame #11: 0x0000000001067d8a cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) + 922
    frame #12: 0x000000000106b5fd cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) + 15373
    frame #13: 0x000000000106d1d7 cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) + 87
    frame #14: 0x0000000001067a8a cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) + 154
    frame #15: 0x000000000106d1d7 cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) + 87
    frame #16: 0x0000000001069efb cgrep`clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) + 9483
    frame #17: 0x000000000104baf9 cgrep`clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) + 825
    frame #18: 0x000000000049c066 cgrep`CgrepASTConsumer::HandleTranslationUnit(clang::ASTContext&) + 38
    frame #19: 0x0000000000934023 cgrep`clang::ParseAST(clang::Sema&, bool, bool) + 643
    frame #20: 0x00000000007d8e88 cgrep`clang::FrontendAction::Execute() + 72
    frame #21: 0x0000000000800921 cgrep`clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1585
    frame #22: 0x00000000011b93bc cgrep`clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) + 412
    frame #23: 0x00000000011b9126 cgrep`clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) + 262
    frame #24: 0x00000000011b85bf cgrep`clang::tooling::ToolInvocation::run() + 2655
    frame #25: 0x00000000011ba7ea cgrep`clang::tooling::ClangTool::run(clang::tooling::ToolAction*) + 3002
    frame #26: 0x000000000043417b cgrep`main + 635
    frame #27: 0x00007ffff29d4b97 libc.so.6`__libc_start_main(main=(cgrep`main), argc=5, argv=0x00007fffffffb9d8, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffb9c8) at libc-start.c:310
    frame #28: 0x00000000004328aa cgrep`_start + 42

I'm on Ubuntu and compiled cgrep like this:

$ make CXX=clang-10 LLVM_CONF=llvm-config-10 BUILD_MODE=DEBUG cgrep-dbg
clang-10 -fpic -I/usr/lib/llvm-10/include -std=c++14   -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/usr/lib/llvm-10/build//tools/clang/include -I/usr/lib/llvm-10/build//tools/clang/include -std=c++17 -fexceptions  -g -c cgrep.cpp -o cgrep.odbg
clang-10 -fpic -I/usr/lib/llvm-10/include -std=c++14   -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/usr/lib/llvm-10/build//tools/clang/include -I/usr/lib/llvm-10/build//tools/clang/include -std=c++17 -fexceptions  -g -c cfe-extra/cfe_extra.cpp -o cfe-extra/cfe_extra.odbg
clang-10 cgrep.odbg cfe-extra/cfe_extra.odbg  -Wl,--start-group -lclangAST -lclangAnalysis -lclangBasic -lclangDriver -lclangEdit -lclangFrontend -lclangFrontendTool -lclangLex -lclangParse -lclangSema -lclangEdit -lclangASTMatchers -lclangRewrite -lclangRewriteFrontend -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangSerialization -lclangToolingCore -lclangTooling -lstdc++ -lLLVMRuntimeDyld -lm -Wl,--end-group -L/usr/lib/llvm-10/lib  -lLLVM-10  -g -o cgrep-dbg

$ make CXX=clang-10 LLVM_CONF=llvm-config-10
clang-10 -fpic -I/usr/lib/llvm-10/include -std=c++14   -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/usr/lib/llvm-10/build//tools/clang/include -I/usr/lib/llvm-10/build//tools/clang/include -std=c++17 -fexceptions  -c cgrep.cpp -o cgrep.o
clang-10 cgrep.o cfe-extra/cfe_extra.o  -Wl,--start-group -lclangAST -lclangAnalysis -lclangBasic -lclangDriver -lclangEdit -lclangFrontend -lclangFrontendTool -lclangLex -lclangParse -lclangSema -lclangEdit -lclangASTMatchers -lclangRewrite -lclangRewriteFrontend -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangSerialization -lclangToolingCore -lclangTooling -lstdc++ -lLLVMRuntimeDyld -lm -Wl,--end-group -L/usr/lib/llvm-10/lib  -lLLVM-10  -o cgrep

Also if it helps: This is the repo where I tried to grep: https://github.com/gareth-cross/rviz_satellite

Match named fields inside structs initialization

Have a use case that I am not sure cgrep already supports.

I am working on some CPython code and wanted to find all places in my code where variables of a given type and print the value of a struct field in those variables.

Concrete example:

CPython has a PyModuleDef struct with a field named m_slots. I need to find all variables that value m_slots and set it to NULL.

Was considering using clang-query but looks like something cgrep could handle.

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.