[cfe-dev] collecting source code information

Douglas Gregor dgregor at apple.com
Tue Jun 29 07:25:10 PDT 2010


On Jun 24, 2010, at 10:19 AM, Dominik Grewe wrote:

> Hey!
> 
> I'd like to write a program that collects statistics of OpenCL kernels. Examples
> are the number of arithmetic operations, number and types of variables, etc. In
> the future I'd also like to do some static analysis, for example to try and
> derive memory access patterns.
> 
> I'm new to Clang, so I'm not quite sure how to go about this... It seems like
> the RecursiveASTVisitor class could be a good start, as it allows you to
> traverse the AST. Overloading VisitStmt() for example would allow me to count
> the number of arithmetic expressions, right?

Sure, although you probably want to overload VisitBinaryOperator/VisitUnaryOperator.

> Unfortunately I can't figure out how to start the tree traversal. What is it
> that I need to pass my visitor class in order to traverse the whole file or a
> certain function?
> Are there any examples that show a usage of RecursiveASTVisitor?

Check out lib/Frontend/BoostConAction.cpp

	- Doug



More information about the cfe-dev mailing list