Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
sesiuni:compiler:ast [2014/07/13 22:09]
freescale created
sesiuni:compiler:ast [2014/07/13 22:10] (current)
freescale [The Clang AST]
Line 7: Line 7:
 You should try this for a few examples to get a feel of it. You should try this for a few examples to get a feel of it.
  
-The **-fsyntax-only** option tells Clang to stop the compilation process after building the AST. The **-Xclang** flag specifies that the option following it should be passed to the front-end (which is confusingly dubbed Clang, just like the command line driver) ​- without ​this flag, **-ast-dump** is not recognized. ​+The **-fsyntax-only** option tells Clang to stop the compilation process after building the AST. The **-Xclang** flag specifies that the option following it should be passed to the front-end (which is confusingly dubbed Clang, just like the command line driver). Without ​this flag, **-ast-dump** is not recognized. ​
  
-There are several ways to obtain information from the AST, for instance by using [[http://​clang.llvm.org/​docs/​LibASTMatchersReference.html | **Matchers**]] or **Visitors**. We will use the most powerful visitor: **RecursiveASTVisitor**. Its strength lies in the fact that it not only provides access to the nodes of the AST, but also allows us to change the order in which the AST is traversed.+There are several ways to obtain information from the AST, for instance by using [[http://​clang.llvm.org/​docs/​LibASTMatchersReference.html | Matchers]] or **Visitors**. We will use the most powerful visitor: **RecursiveASTVisitor**. Its strength lies in the fact that it not only provides access to the nodes of the AST, but also allows us to change the order in which the AST is traversed.
  
 An interesting thing to note about the implementation of **RecursiveASTVisitor** is that it uses the **CRTP** (Curiously Recurring Template Pattern) idiom in order to achieve static polymorphism. An interesting thing to note about the implementation of **RecursiveASTVisitor** is that it uses the **CRTP** (Curiously Recurring Template Pattern) idiom in order to achieve static polymorphism.
  
-We will subclass **RecursiveASTVisitor** and invoke its **TraverseTranslationUnitDecl** from the **HandleTranslationUnitDecl** method of our **ASTConsumer**. This will make the visitor traverse the entire declaration (including, for function definitions,​ the body of the function), invoking **Visit*** methods on every node. We will write the largest part of our tools in these **Visit* ** methods.+We will subclass **RecursiveASTVisitor** and invoke its **TraverseTranslationUnitDecl** from the **HandleTranslationUnitDecl** method of our **ASTConsumer**. This will make the visitor traverse the entire declaration (including, for function definitions,​ the body of the function), invoking **Visit* ** methods on every node. We will write the largest part of our tools in these **Visit* ** methods.
  
 You can get a good understanding of the **RecursiveASTVisitor** by reading the comments in its header file (//​clang/​AST/​RecursiveASTVisitor.h//​). You can get a good understanding of the **RecursiveASTVisitor** by reading the comments in its header file (//​clang/​AST/​RecursiveASTVisitor.h//​).
sesiuni/compiler/ast.1405278562.txt.gz · Last modified: 2014/07/13 22:09 by freescale