[cfe-dev] How to get the code of an Expr with qualified types/names

Wang Qi wqking at outlook.com
Mon Jun 17 00:47:28 PDT 2013


Hi, all,

I'm quite new to Clang, but I'd thank for all your great work.

Assume I have below code,

struct Abc {
    static const int A = 5;
    void func(int a = A + 1); // note the default value
};

What I want to do is to use Clang to parse the code, and
when I find the default value "A + 1", I put the expression
to a tool generated C++ file, and use the expression there.

The generated C++ code may look like,

int defaultValue = Abc::A + 1; // this is in global namespace

But now I can only get the expression text from Expr's
source location, that results the generated code look like,

int defaultValue = A + 1; // Can't compile!

So my question is, how to get the expression text with all
values and types fully qualified? Travel through the expression tree
and reconstruct the text should work, but that may be too complicated.


Thanks 		 	   		  



More information about the cfe-dev mailing list