[cfe-dev] default include paths in the frontend
Chandler Carruth
chandlerc at google.com
Sat Nov 12 01:02:35 PST 2011
On Sat, Nov 12, 2011 at 12:44 AM, Sven Verdoolaege <skimo-cfe at kotnet.org>wrote:
> Hi,
>
Hey, sorry for not getting back to you sooner...
> I'm using the clang libraries in one of my applications
> (called pet) to parse a C file, after which I extract
> some information from the generated AST. Since I only
> need the parser, I'm using the frontend directly.
>
Ok... is there any reason you don't use the driver at all? The driver is
structured such that you can call into it as a library as well, and get it
to reason about command line options.
The sources I need to parse may include system headers
> and so clang should also look in system include paths.
> This used to work fine, but in revision 143822, the
> Linux header searching was moved from the frontend to
> the driver, leaving InitHeaderSearch::AddDefaultIncludePaths
> in the frontend to do nothing and system header files
> no longer getting found.
>
Correct. The frontend should be in the business of parsing C++ code, not of
inspecting your system to find various versions of libstdc++, etc. This was
always a poor location for the logic... I didn't worry much about
announcing that I was actually moving the logic because frankly, it was so
broken that I doubted many people used it.
For reference, we use Clang in extremely similar ways, and have many tools
in this space. However, the header search logic never really worked
correctly in the frontend, so we have for a long time been rolling our own.
> How am I supposed to make the frontend look for system
> header files now?
>
You can't directly make the frontend do this, but you can always use the
driver to build up the arguments for your compiler invocation. Look at
Driver::BuildCompilation, which accepts commandline args for a compile. You
can then get the JobList out of the Compilation. It should have a single
job in it, which is the command for running the Frontend CC1 layer, with
system header search paths pre-filled. You can pull the ArgStringList
directly out of the command and hand it to the Frontend APIs yourself if
you need to avoid a subprocess.
I can sketch out the code to do this if it helps (as I said, we're doing it
ourselves), but there's nothing really fancy to it. The interface is kinda
gross and unpolished, but that's because this isn't a usecase that has been
heavily polished in Clang.
>
> Thanks,
>
> skimo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111112/c910e360/attachment.html>
More information about the cfe-dev
mailing list