[cfe-dev] CompilerInstance and ASTConsumer with clang 3.6

cedlemo cedlemo at gmx.com
Fri Apr 3 10:02:59 PDT 2015


Thanks It works!


On 03/04/2015 18:42, David Blaikie wrote:
>
>
> On Fri, Apr 3, 2015 at 9:31 AM, cedlemo <cedlemo at gmx.com 
> <mailto:cedlemo at gmx.com>> wrote:
>
>     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.
>
>     ...
>     //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
>
>     _______________________________________________
>     cfe-dev mailing list
>     cfe-dev at cs.uiuc.edu <mailto:cfe-dev at cs.uiuc.edu>
>     http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>

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


More information about the cfe-dev mailing list