[cfe-dev] creating AST from file with custom entry point

Sean Silva silvas at purdue.edu
Mon Feb 27 15:49:47 PST 2012


One technique that I have used successfully in the past for something
similar (not with clang though), is to just wrap the code inside an
"environment" that will make it compile, and then extract the AST nodes you
want. So in this case, you would wrap a function and some variable
declarations around it.

Also, I don't know much about how it works, but the clang-bot in the IRC
channel does do some things that are probably related, but I don't know
enough about how it works to give you any useful advice.

--Sean Silva

On Mon, Feb 27, 2012 at 4:40 PM, Michael Hochgatterer <
michael.hochgatterer at students.fh-hagenberg.at> wrote:

>  Hi all.
>
> Is there a possiblilty to create an AST for C++ source code which has a
> custom entry point.
>
> To illustrate, the following code expample should be parsed to an AST:
>
> int z = a + b;
> while (z < 10) {
>     x = x * x;
> }
>
> There is no function declaration in the file and not all variables are
> declared. Is there a way to create
> an AST for this code so that all lexed tokens are parsed into the AST.
>
> I tried to do this with the "C" interface libclang but there only a
> complete translation unit can be parsed. When i parse
> this code i get a some diagnostic messages and the generated AST is
> incomplete.
> So my question is: is it possible to parse this code in an AST and if so,
> whats the best way to do this.
>
> Thx in advance
> Michael Hochgatterer
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120227/c94e1b1c/attachment.html>


More information about the cfe-dev mailing list