[cfe-dev] Is Clang what I need?

Manuel Klimek klimek at google.com
Tue Jan 8 01:03:52 PST 2013


On Mon, Jan 7, 2013 at 10:35 PM, David Blaikie <dblaikie at gmail.com> wrote:

> On Mon, Jan 7, 2013 at 1:29 PM, Pedro Delgado Perez
> <pedro.delgadoperez at mail.uca.es> wrote:
> > Thank you very much David.
> >
> > Which interface would you recommend me to use for my purpose? I don't
> > understand really well what are the difference among them (LibClang,
> > Plugins, LibTooling or Clang Tools) and i would need to know the best
> option
> > for me. What I want is to create a tool reusing Clang only to analyze C++
> > programs. If you need more information to give me an answer, please tell
> me
> > what you would need to know.
>
> If you're trying to do AST-matched source code transformations what
> you probably want is to use libTooling (to write a "Clang Tool") along
> with the AST matchers.
>
>
> [The one thing still pending that blocks truly streamlined refactoring
> tools using this infrastructure is the ability to automatically format
> the modified code so it's still legible (eg: re-wrapping lines when
> changing an identifier makes it shorter/longer), there's currently
> work underway (in the form of "clang-format") to support this. Once
> this functionality is combined with tooling and AST matchers we should
> have the ability to write fairly ad-hoc C++ refactoring tools that
> Just Work]
>
> [+Manuel to this thread in case he has anything to add]
>

Yep - you can already run clang-format over the diffs afterwards (daniel
has a script that he plans to land soon).

Cheers,
/Manuel


> - David
>
> >
> > Thanks,
> >
> > Pedro D.
> >
> > El dia 07 ene 2013 17:29, David Blaikie <dblaikie at gmail.com> escribió:
> >
> > On Mon, Jan 7, 2013 at 2:44 AM, Pedro Delgado Perez
> > <pedro.delgadoperez at mail.uca.es> wrote:
> >
> > Hello,
> > I've just known Clang looking for a soution to the task i need to
> perform.
> > Well, what I need is to parser a C++ program in order to get some
> > information about the code and, after that, to change the code regarding
> > that information collected.For instance, I would need to know if a
> certain
> > program contains some arithmetic operators., obtaining a record with the
> > line where the operator is located and which operator is. I've been
> reading
> > about Clang and now I know you can go through the AST, but i'm not
> totally
> > sure if it's what I'm looking for because apart from the example I've
> > commented above, I would need a lot of kinds of information:- What are
> the
> > global and the local variables.- If there is an overriden member when a
> > class inherits from another.- If a method of a class is overloaded.-...I
> > need that information because I have to change the original program once
> I
> > have the record with the information. For instance, if in the code there
> is
> > a reference to an overriden member, I have to turn that reference into
> the
> > hidden member.
> >
> >
> >
> > The other question I have is: is it worth the effort and the time to
> learn
> > how to use clang? I need an opinion to know how easy or tough is to learn
> > how to use it.
> >
> > I hope you could lend me a hand. Thanks in advance.
> >
> > It depends a little on what alternatives you're considering. Clang
> > isn't necessarily going to be easy to get started with, especially
> > making source modifications, avoiding conflicts, etc, but it's
> > probably the easiest thing available to do this job well.
> >
> > The tooling infrastructure ( http://clang.llvm.org/docs/Tooling.html )
> > and AST Matchers ( http://clang.llvm.org/docs/LibASTMatchers.html )
> > are designed to make this sort of task as easy & painless as possible.
> >
> > - David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130108/b5aeea7c/attachment.html>


More information about the cfe-dev mailing list