[cfe-dev] Tokens for rewriting C++ constructor initializers

Lukhnos Liu lukhnos at lukhnos.org
Mon May 14 17:52:10 PDT 2012


I'm writing a refactoring tool as a way to learn Clang internals. A problem I run into is: how do you get the locations of the tokens that are not present in the AST?

What I'm doing is like this: I have an ASTConsumer, which I call ParseAST to run. In the consumer, I look for CXXConstructorDecl with the TraverseDecl method, then I want to rewrite the method (for example, to move the function body from the header to an implementation file).

Getting the function body is easy, but I'm not sure what to do with the initializers. For each item in the initializer list that I get from init_begin() and init_end(), the source range encompasses the item itself, but not the preceding colon or the in-between commas. Is there a way to get those parts from the AST, or do I need to get those lex info elsewhere?

Thank you,

More information about the cfe-dev mailing list