Skip to content

A simple C++ function parser/tagger based on tree-sitter

License

Notifications You must be signed in to change notification settings

tum-i4/what-the-func

Repository files navigation

What the func?! - A simple C++ function parser/tagger

example workflow

This project implements a simple C++ function parser, what-the-func, based on the tree-sitter C++ grammar. Similar to source code taggers such as ctags, what-the-func can be used to detect all function definitions in C++ source files as required, e.g., for function-level regression test selection. The main advantage of what-the-func is its robustness towards syntax problems (as opposed to solutions using clang or gcc), allowing to analyze arbitrary single source files without providing compiler flags (e.g., to resolve #includes).

Build

To build and run the project, you need NodeJS >= 14.

$ npm install
$ npm run build  # will transpile TypeScript sources

Run

# sample C++ file
$ cat foo.cpp
int max(int a, int b) {
  return a > b ? a : b;
}

# build and run `what-the-func` with arguments
$ npm run start -- -f foo.cpp
{"name":"max(int a, int b)","start":1,"end":3,"properties":[],"file":"/path/to/foo.cpp"}

# or, if using executable binary
$ what-the-func -f foo.cpp
{"name":"max(int a, int b)","start":1,"end":3,"properties":[],"file":"/path/to/foo.cpp"}

Test

$ npm run test  # executes jest test suite

Package

$ npm run package  # builds project and generates executable `what-the-func` binaries (into ./bin)

Contributors

Built and maintained by Daniel Elsner (daniel.elsner<at>tum.de).