[cfe-dev] AST node creation

Martin C. Martin martin at martincmartin.com
Tue Mar 23 04:50:59 PDT 2010


To see the AST, you can use the -ast-print command line option. You can 
get a "binary" representation by setting Dump in ASTPrinter.  I couldn't 
figure out how to do this from the command line (is there a way?), so I 
just hacked the ASTPrinter::HandleTranslationUnit to always set 
Policy.Dump to true.

clang -cc1 ~/t.c -ast-print

Best,
Martin


On 3/22/2010 11:28 PM, Ted Kremenek wrote:
> Hi Kalyan,
>
> If you want to see where various AST nodes are created, you can try
> putting breakpoints in many of the 'Create()' static member functions
> that occur in many of the subclasses of Stmt, or search for the 'new
> (ASTContext)' form that is used to create ASTs using the allocator
> associated with the ASTContext object. For example:
>
> $ grep -r "[)] ForStmt" *
> lib/Frontend/PCHReaderStmt.cpp: S = new (Context) ForStmt(Empty);
> lib/Sema/SemaStmt.cpp: return Owned(new (Context) ForStmt(First, Second,
> ConditionVar, Third, Body,
>
> libSema is the semantic analyzer, so that's where a ForStmt will get
> created during regular compilation. The AST is defined in libAST, with
> the important header files being Stmt.h, Decl.h, and their derivatives.
>
> Cheers,
> Ted
>
> On Mar 22, 2010, at 7:46 PM, kalyan ponnala wrote:
>
>> Hi,
>>
>> I am trying to understand about ASTs in clang by stepping through the
>> code. I am using a program with "for loop".
>> Can someone tell me better places to put breakpoints which would help
>> me understand that particular part of clang.
>>
>> Thanks.
>>
>> --
>> Kalyan Ponnala
>> phone: 8163772059
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu <mailto:cfe-dev at cs.uiuc.edu>
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list