Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view Clang AST?

I am trying to get hold on Clang. So, I would like to view the AST generated by Clang after parsing the given program. Is it possible to dump AST in .dot or .viz format? Is there any tool out there?

like image 610
username_4567 Avatar asked Sep 01 '13 15:09

username_4567


People also ask

What is AST in clang?

Clang's AST nodes are modeled on a class hierarchy that does not have a common ancestor. Instead, there are multiple larger hierarchies for basic node types like Decl and Stmt. Many important AST nodes derive from Type, Decl, DeclContext or Stmt, with some classes deriving from both Decl and DeclContext.

How do you use a clang check?

Running clang-check without any options runs the -fsyntax-only mode (checking for correct syntax). Only if you specify -analyze , the static analysis tool is executed, see http://clang-analyzer.llvm.org/available_checks.html for a full list of executed checks.

What is clang query?

clang-query is a tool that allows you to quickly iterate and develop the difficult part of a matcher. Once the design of the matcher is completed, it can be transferred to a C++ clang-tidy plugin, similar to the ones in mozilla-central.


1 Answers

The method with -cc1 invocation will have problem with includes and recognizing C++.

For full-featured parsing, use:

clang -Xclang -ast-dump file.cpp 
like image 118
Kornel Avatar answered Sep 22 '22 12:09

Kornel