[cfe-dev] [Libtooling] Parse file with previous AST

Vladimir Voskresensky - Oracle via cfe-dev cfe-dev at lists.llvm.org
Tue Mar 15 04:20:56 PDT 2016



On 03/15/16 01:10 PM, David Come via cfe-dev wrote:
> Hello,
>
> I'm writing a some tool for doing static analysis on C++ code.
>
> My tool has obviously two inputs:  the file(s) to check (let's say /f.cpp/)  
> and the property to check .
>
> Currently (I'm in a early stage of development), I want to describe the 
> property directly in C++ (let's say /prop.cpp/).
> and use clang/libtooling to read it .The thing is that the property will use 
> symbols that are defined in the code to analyze.
>
> Thus, I wish to parse /prop.cpp /knowing /f.cpp/'s AST so I don't run into 
> unknown symbols. But I haven't been successful so far.
>
> i could cheat and merge the two files in a temporary file but I don't like 
> that idea.
> I could also require /prop.cpp /to be self contained  (with all the headers 
> needed) but that would hinder the tool's usability (headers to include, need 
> to provide to clang all the compilation options...).
You can try the trick with one pass: when prepare cmd line options for parsing 
the second TU pass "-inlclude first_file.cpp" and add cmd line options of 
first_file.cpp as well.
it will invisibly add
#include "first_file.cpp"
as the first line text in your
prop.cpp

Note that you should add cmd line options of first_file.cpp as well, because you 
want this phantom #include to be correctly handled.

Hope it helps,
Vladimir.

>
> If you have any lead,
>
> Thanks,
> David.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160315/69ddb987/attachment.html>


More information about the cfe-dev mailing list