Skip to content

Commit

Permalink
Improved documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudomanifold committed Sep 8, 2017
1 parent 0701933 commit a1a50ee
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions README.md
Expand Up @@ -34,12 +34,12 @@ compiling a given program.

Let me briefly explain how to use some of the experiments.

## `ast-walker`
## `ast-dumper` & `ast-walker`

This programs walks an abstract syntax tree. It follows the
implementation given in [this blog
post](http://bastian.rieck.ru/blog/posts/2015/baby_steps_libclang_ast).
To use it, you require the creation of an abstract syntax tree:
These programs walk an abstract syntax tree. They roughly follow the
implementation given in [this blog post](http://bastian.rieck.ru/blog/posts/2015/baby_steps_libclang_ast).
To use one of them (I am exemplarily demonstrating `ast-walker`),
you require the creation of an abstract syntax tree:

$ clang++ -std=c++11 -emit-ast ../examples/tuple.cc
$ ./ast-walker tuple.ast
Expand Down Expand Up @@ -106,6 +106,51 @@ This should result in an output similar to this:
- FieldDecl (c)
- FieldDecl (d)

## `count-function-extents`

Getting this program to run can be a *tiny* bit more trickier. We should
supply it with the default paths required by `clang++`. To determine
them, call

$ clang++ -v -c FILE

where `FILE` is a source file of your choice. The resulting output
should contain the line

#include <...> search starts here:

and a list of paths. Copy them and put them into one command-line
variable, like so:

$ export CPLUS_INCLUDE_PATH=/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1:/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/x86_64-pc-linux-gnu:/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/backward:/usr/local/include:/usr/bin/../lib/clang/4.0.1/include

Afterwards, you can call the program on a test executable:

$ ./count-function-extents ../examples/functions.cc

This should result in the following output:

Obtained 0 compile commands
theAnswerToLifeTheUniverseAndEverything: 3
sum: 3
square: 3
cube: 3
factorial: 6
fibonacci: 14

You can also call the function for any executable specified in
a `compile_commands.json` data base:

$ ./count-function-extents ../count-function-extents.cc
Parsing /home/brieck/Projects/libclang-experiments/count-function-extents.cc...
Obtained 1 compile commands
getCursorSpelling: 7
resolvePath: 17
functionVisitor: 24
main: 74

I am sure that these programs could be easily improved. I look forward
to your changes!

# Additional information

Expand Down

0 comments on commit a1a50ee

Please sign in to comment.