CompilerInstance and ASTConsumer with clang 3.6

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_ptrclang::TargetOptions pto = std::make_sharedclang::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 as argument. How to adapt my previous code with the new api.

Thanks

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);

ci.setASTConsumer(llvm::make_unique<MyASTConsumer>()); is the simplest way.

Thanks It works!