Recursive AST Visitor


I am trying to recursively visit all node in the AST and count the number of
functions in my code.
However, the AST visitor counts functions in the header files as well such
as in "include<stdio.h>".
Is there anyway to exclude the header files from this?

I get this error when I run the recursive visitor on my code which is due to
the included files:

1. /usr/include/libio.h:417:1: current parser token 'extern'
clang: error: unable to execute command: Segmentation fault
clang: error: clang frontend command failed due to signal (use -v to see
clang: note: diagnostic msg: Please submit a bug report to and include command line arguments and all diagnostic
clang: note: diagnostic msg: Error generating preprocessed source(s).

I'm not sure what exactly your code is doing, but a few thoughts come to
mind. With the recursive AST visitor, the paths to the include files are
hard-coded (look at the AddPath calls in the code you're using) and make
sure they're using the appropriate paths you need for your code.
You can ask the SourceManager if a given SourceLocation is part of the file
you're analysing (i.e. not from an include file) with the
isFromMainFile(location) call.