[cfe-dev] parsing multiple source files

Hironobu TAKEI hironobu_takei at zipc.com
Thu Jan 27 08:28:31 PST 2011


Thank you very much, Doug.
I try CompilerInvocation and CompilerInstance.

Regards,
Takei



At 27 Jan 2011 07:23:00 -0800 Douglas Gregor wrote:
> 
> On Jan 27, 2011, at 7:09 AM, Hironobu TAKEI wrote:
> 
> > Hello
> > 
> > I'd like to get ASTContext-s for multiple input files (by calling
> > ParseAST)
> > I've looked into web and clang's sources but I lost my way...
> > 
> > My understand is that each of FileManager, SourceManager,
IdentifierTable,
> > SelectorTable and HeaderSearch is unique to MY PROGRAM,
> > then, each of Preprocessor and ASTContext is unique to each of INPUT
FILES.
> > 
> > Is it correct?
> 
> To. All of these entities are unique to each translation unit.
> 
> > My code:
> > {
> >    ...
> >    SourceManager srcMgr(diag);
> >    ...
> >    foreach input-files {
> >        if (file-is-main) {
> >            srcMgr.createMainFileID(file);
> >        }
> >        else {
> >            srcMgr.createFileID(file, ...);
> >    }
> >    ASTContext context(langOpts, srcMgr, ...);
> >    Preprocessor cpp(diag, langOpts, targetInfo, srcMgr, headerSearch);
> >    ParseAST(cpp, consumer, context);
> >    ...
> > } parses only the main file.
> > 
> > Preprocessor and ASTContext must have a reference to its SourceManager
> > but never know any specific FileID. How can I tell my program to parse
> > other files?
> > Could anyone point to or suggest any solutions?
> 
> You'll need to create all of these entities from scratch each time to
process a new translation unit.
> 
> However, I strongly suggest not trying to do all of this by creating
contexts, preprocessors, file/source managers, etc., directly. Instead,
use CompilerInvocation and CompilerInstance, with your own custom Action,
to drive the compilation process.
> 
> 	- Doug

=====================================================================
 Hironobu TAKEI @ CATS Co.,Ltd. System Div.
 KAWAASA BLDG. 2-11-5 Shin-Yokohama Kohoku, Yokohama 222-0033 Japan.
 http://www.zipc.com TEL: +81-45-473-2088 FAX: +81-45-473-2689



More information about the cfe-dev mailing list