<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Jun 11, 2015 at 11:14 PM Peter Collingbourne <<a href="mailto:peter@pcc.me.uk">peter@pcc.me.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Jun 11, 2015 at 11:50:40AM +0000, Manuel Klimek wrote:<br>
> On Thu, Jun 11, 2015 at 1:29 PM Jacob Carlborg <<a href="mailto:doob@me.com" target="_blank">doob@me.com</a>> wrote:<br>
><br>
> > On 2015-06-11 11:24, Kevin Funk wrote:<br>
> > > Heya,<br>
> > ><br>
> > > I've found clang-query to be useful to query single files. Matching the<br>
> > Clang<br>
> > > AST is easy enough and fast to learn. I don't see how to use clang-query<br>
> > on a<br>
> > > whole project, though, which would be super useful.<br>
> > ><br>
> > > A simple example where it's effectively useless: Assume some header<br>
> > "global.h"<br>
> > > containing "struct Global {};", every file in the project includes this<br>
> > header.<br>
> > ><br>
> > > Now the idiomatic way to run clang-query over all the files in the<br>
> > project:<br>
> > >    clang-query -p $BUILD $(find . -name "*.cpp")<br>
> > ><br>
> > > Let's try to find record decls named "Global":<br>
> > >    match recordDecl(hasName("Global"), isDefinition())<br>
> > ><br>
> > > => You get one match per file / translation unit. But in fact, this is<br>
> > not<br>
> > > really what you want. You want one match here.<br>
> > ><br>
> > > So of course this is difficult: clang-query is TU-centric, while for a<br>
> > whole<br>
> > > project you'd "somehow" want a global view over the source code and not<br>
> > have<br>
> > > duplicate results for a query like above.<br>
> > ><br>
> > > Questions:<br>
> > > - Is it possible to get clang-query to behave like that?<br>
> > >    - Any research/pointers in that regard?<br>
> > > - Is it possible to filter duplicates in the results without external<br>
> > tools?<br>
> ><br>
> > In theory it should be easy to modify clang-query to check the location<br>
> > of a declaration and only return declarations for unique locations.<br>
> ><br>
><br>
> Well, the problem is that a clang-query process is started for each TU, so<br>
> you'd need to somehow tell clang-query which results were in a completely<br>
> different process of clang-query. I don't think this is going to be easy or<br>
> worth it...<br>
<br>
This isn't entirely accurate. Each TU is stored in a separate AST, but all<br>
of the ASTs live in a single process. When a match query is run, we simply<br>
iterate over a vector of TU ASTs (see MatchQuery::run in Query.cpp). If you<br>
wanted to deduplicate results, you could probably do it in MatchQuery::run<br>
by pretty printing each result's SourceLocation and using that as a string key.<br></blockquote><div><br></div><div>That doesn't really scale though. But yea, for small projects it might be enough...</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks,<br>
--<br>
Peter<br>
</blockquote></div></div>