#include <clang/Frontend/FrontendAction.h>#include <clang/Tooling/Tooling.h>#include <clang/AST/ASTConsumer.h>#include <clang/AST/Decl.h>#include <iostream>structMyASTConsumer:clang::ASTConsumer{voidHandleTagDeclDefinition(clang::TagDecl*D)override{// if it's a struct or a classif(D->isRecord())std::cout<<"Found a class: "<<D->getNameAsString()<<std::endl;}};structMyAction:clang::ASTFrontendAction{virtualclang::ASTConsumer*CreateASTConsumer(clang::CompilerInstance&CI,llvm::StringRef)override{returnnewMyASTConsumer();}};intmain(intargc,constchar**argv){std::vector<std::string>Argv;// Just forward all the arguments to the toolfor(intI=0;I<argc;++I)Argv.push_back(argv[I]);clang::FileManagerFM({"."});clang::tooling::ToolInvocationInv(Argv,newMyAction,&FM);return!Inv.run();}
Ça s'utilise comme ça:
./a.out mylib.h -c -x c++ -I/usr/include
Et ça affiche toute les classes (y compris toutes celle de la stdlib)
[^] # Re: Superbe article !
Posté par Gof (site web personnel) . En réponse à la dépêche LLVM 3.3 et Clang 3.3. Évalué à 10.
Voilà:
Ça s'utilise comme ça:
Et ça affiche toute les classes (y compris toutes celle de la stdlib)