[cfe-dev] CompilerInstance and ASTConsumer with clang 3.6

cedlemo cedlemo at gmx.com
Fri Apr 3 09:31:45 PDT 2015


Hi,

with clang 3.5, when I wanted to parse a source file, I created a 
compiler instance and a new class that inherit from the class 
ASTConsumer like this :

ci = new clang::CompilerInstance()
ci.createDiagnostics();
ci.createFileManager();
ci.createSourceManager(ci.getFileManager());
std::shared_ptr<clang::TargetOptions> pto = 
std::make_shared<clang::TargetOptions>();
pto->Triple = llvm::sys::getDefaultTargetTriple();
clang::TargetInfo *pti = 
clang::TargetInfo::CreateTargetInfo(m_ci.getDiagnostics(), pto);
ci.setTarget(pti);
ci.createPreprocessor(clang::TU_Complete);
...
//add source file and the headers paths
...
MyASTConsumer * myASTConsumerClassInstance = new MyASTConsumer;
ci.setASTConsumer(myASTConsumerClassInstance);
...
//parse the header file

with the ASTConsumer :

class MyASTConsumer : public clang::ASTConsumer
{
     MyASTConsumer()
     ~MyASTConsumer() {};
     virtual bool HandleTopLevelDecl( clang::DeclGroupRef d);
     virtual void HandleTagDeclDefinition( clang::TagDecl * d);
     private:
     std::vector<clang::TagDecl *> m_my_tags;
}

Now with clang 3.6, the CompilerInstance::setASTConsumer methods asks 
for a std::unique_ptr<ASTConsumer> as argument. How to adapt my previous 
code with the new api.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150403/73ce37b5/attachment.html>


More information about the cfe-dev mailing list