[cfe-dev] Design: clang-format
Gregory Szorc
gregory.szorc at gmail.com
Sun May 13 18:08:49 PDT 2012
On 5/11/12 9:27 AM, Manuel Klimek wrote:
> Hi,
>
> we're working on the design of clang-format; there are quite a few open
> questions, but I'd rather get some early feedback to see whether we're
> completely off track somewhere.
I'm glad to see work in this area!
A few months ago, I set out to accomplish something similar. I didn't
make much progress because I wanted to utilize the Python bindings
instead of writing C++ (mainly because I think tools like this are much
easier to implement in higher-level languages). Anyway, I was
sidetracked because the Python bindings were lacking features needed to
implement such a tool. (This actually spawned much of my work on the
Python bindings, which have been trickling into the tree.)
Anyway, you may be interested in clanalyze [1]. My goal for clanalyze
was to build APIs for inspecting the lexer output and AST. It is
essentially a higher-level API for the Python bindings. I didn't get
very far, so the code isn't that useful. What I do think is worth
considering is the concept of an API that sits above the lexer output
and AST that provides commonly-needed functionality. I think any tool
that does code formatting, style critiquing, documentation generation,
etc, is bound to perform many of the same tasks. e.g. "get a list of all
the functions in a class," "list all the classes declared in this file,"
"return the comment block(s) before this declaration."
Since something like clang-format would need such abilities and since
there are many other tools that could reuse this logic, I think there is
value in implementing a higher-level "query" interface as a standalone
library/module. Such an interface could also provide a bridge between
the lexer tokens and AST (you need to use both for things like getting
the comment block(s) before a declaration).
I didn't get very far with clanalyze (yet). Hopefully you can do better.
Also worth mentioning is linty [2].
Greg
[1] https://github.com/indygreg/clanalyze
[2] https://github.com/holtgrewe/linty
More information about the cfe-dev
mailing list