[cfe-dev] Unable to do even basic Clang tutorial

Douglas Gregor dgregor at apple.com
Tue Jul 10 14:46:19 PDT 2012


On Jul 10, 2012, at 2:04 PM, Bill White <bill.white at griggsinst.com> wrote:

> So, here's a followon question.  If one was starting a new project,
> would one use libclang,
> write a plug-in, or use the libtooling library?

FWIW, that's the intent of this page:

	http://clang.llvm.org/docs/Tooling.html

>  For my application,
> at least initially, libclang
> seems like a good starting point.  But the tooling library would give
> me access to the
> compilation database, which would let me tell the clang parser what -I
> and -D flags to use.  I'm
> not sure how to do that with the libclang interface today.  The
> documentation is not
> clear.  Also, I'm not sure how system headers and definitions are to
> be supplied.  But in
> my application I would have to specify these separately, as we are
> very sensitive to the
> system headers, or at least to the version of the gcc headers which
> are included.

If Clang finds the right system headers when invoked as a compiler, libclang/tooling/plugins will all find those same headers.

> In particular, I'd like to write an indexing tool,
> like ctags but better.  There seems to be a lot of interest and
> discussion of it, but nothing
> seems to be usable.  I particularly want a tool which can be usable by
> emacs, which is my
> main editor, but with the kind of facilities that Eclipse CDT has.  These are:
>  1.) The ability to dive on an identifier and tell (a) where the identifier is
>      declared, and (b) the static type of the identifier.
>  2.) The ability to dive on a class name and display the entire class
> hierarchy,
>      both base classes and classes derived from the class.  I've used
> this is Java
>      under Eclipse, and found it enormously useful.
>  3.) The ability to show, in some sort of a pop-up window, the result
> of expanding
>      a macro invocation, or some kind of way of telling that a
> template is being
>      expanded.  These seem secondary to (1) and (2), though.
> 
> If I'm missing some progress in this area, I apologize.  It seems as
> if there has been a lot
> of discussion, but I haven't seen anything usable, and I'm coming into
> some time to
> work on it.  Does libclang seem usable?

libclang does much of this, although it only directly resolves within a single translation unit. It has some facilities (by way of "USRs"; see the documentation) to help clients provide cross-translation unit features.

(1) is handled by clang_getCursor() and clang_getCursorReferenced()/ clang_getCursorDefinition()

(2) is handled by walking the cursors of a particular class to find its base classes or (alternatively) using the indexing functionality and collecting all of the base classes of all types.

(3) is not supported by libclang, although it would make a wonderful addition to the library.

	- Doug



More information about the cfe-dev mailing list