[cfe-dev] Requesting Help Understanding ASTs and LibTooling

Jonas Devlieghere via cfe-dev cfe-dev at lists.llvm.org
Fri Jul 8 12:57:01 PDT 2016


On Fri, Jul 8, 2016 at 8:45 PM, Aryal, Saurav via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Hi everyone,
>
> I am just starting out with Clang and working for a project where I am
> trying to generate and compare ASTs to measure code similarity.

Welcome, good luck with your project!

> I figured around a way using Clang to get the AST, but it turns out I am
> expected to use Libtooling.

There are actually different interfaces available to interact with
Clang's AST. Which one is best depends on your use case. I'd recommend
looking at [1] to make an informed decision.

> Anyone have an example where I can parse C++
> code to generate an AST using Libtooling.

Yes; clang's documentation [2] contains an excellent tutorial. There
are also many blog post available that will get you started with
concrete examples, including one I wrote myself when I started looking
at the clang AST [3].

> Also, would love design
> suggestions regarding comparing tree similarity. any examples with
> explanations would be really helpful.
>
> Thanking you.
>
> Sincerely,
> Saurav
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>

[1] http://clang.llvm.org/docs/Tooling.html
[2] http://clang.llvm.org/docs/LibTooling.html
[3] https://jonasdevlieghere.com/understanding-the-clang-ast/)

-- Jonas


More information about the cfe-dev mailing list