<div class="gmail_quote">On Mon, May 14, 2012 at 3:08 AM, Gregory Szorc <span dir="ltr"><<a href="mailto:gregory.szorc@gmail.com" target="_blank">gregory.szorc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 5/11/12 9:27 AM, Manuel Klimek wrote:<br>
> Hi,<br>
><br>
> we're working on the design of clang-format; there are quite a few open<br>
> questions, but I'd rather get some early feedback to see whether we're<br>
> completely off track somewhere.<br>
<br>
</div>I'm glad to see work in this area!<br>
<br>
A few months ago, I set out to accomplish something similar. I didn't<br>
make much progress because I wanted to utilize the Python bindings<br>
instead of writing C++ (mainly because I think tools like this are much<br>
easier to implement in higher-level languages). Anyway, I was<br></blockquote><div><br></div><div>I think you're targeting something different here (worth pursuing, for sure, but different).</div><div><br></div><div>
clang-format is a tool to reformat code. The main use case we have is to reformat code after a refactoring. Our main goal is to write refactoring tools & services. That's also why it must be implemented in C++ - we want to be able to combine refactorings and the clean-up in one process and output only changes.</div>
<div><br></div><div>Now the second level above this is what I call a "linter-style" tool. This might well be better implemented in python on top of a query API (I doubt it, but I might be wrong). That seems more what you're trying to build. I want to see such a tool, too, but we won't get that as one of our priorities any time soon (I know an engineer who would be interested in contributing, but he won't have enough time to do the design work).</div>
<div><br></div><div>I'd suggest before going too far down a path here, to write up a short design idea, and send it past  this list, so you can get feedback by people who understand the implications of the different approaches very well and can catch dead ends before we hit them...</div>
<div><br></div><div>Cheers,</div><div>/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
sidetracked because the Python bindings were lacking features needed to<br>
implement such a tool. (This actually spawned much of my work on the<br>
Python bindings, which have been trickling into the tree.)<br>
<br>
Anyway, you may be interested in clanalyze [1]. My goal for clanalyze<br>
was to build APIs for inspecting the lexer output and AST. It is<br>
essentially a higher-level API for the Python bindings. I didn't get<br>
very far, so the code isn't that useful. What I do think is worth<br>
considering is the concept of an API that sits above the lexer output<br>
and AST that provides commonly-needed functionality. I think any tool<br>
that does code formatting, style critiquing, documentation generation,<br>
etc, is bound to perform many of the same tasks. e.g. "get a list of all<br>
the functions in a class," "list all the classes declared in this file,"<br>
"return the comment block(s) before this declaration."<br>
<br>
Since something like clang-format would need such abilities and since<br>
there are many other tools that could reuse this logic, I think there is<br>
value in implementing a higher-level "query" interface as a standalone<br>
library/module. Such an interface could also provide a bridge between<br>
the lexer tokens and AST (you need to use both for things like getting<br>
the comment block(s) before a declaration).<br>
<br>
I didn't get very far with clanalyze (yet). Hopefully you can do better.<br>
<br>
Also worth mentioning is linty [2].<br>
<br>
Greg<br>
<br>
[1] <a href="https://github.com/indygreg/clanalyze" target="_blank">https://github.com/indygreg/clanalyze</a><br>
[2] <a href="https://github.com/holtgrewe/linty" target="_blank">https://github.com/holtgrewe/linty</a><br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br>