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

Manuel Klimek klimek at google.com
Mon Jun 17 00:56:07 PDT 2013


On Mon, Jun 17, 2013 at 9:47 AM, Wang Qi <wqking at outlook.com> wrote:

> 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.
>

That pretty much seems like the only approach I can think of, too...

Cheers,
/Manuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130617/f02cf064/attachment.html>


More information about the cfe-dev mailing list