Skip to content

Instantly share code, notes, and snippets.

Created April 20, 2016 17:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save daniel-beard/7dab28f3c2fbf24f6c6c3816d76109af to your computer and use it in GitHub Desktop.
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "llvm/Support/CommandLine.h"
#include "clang/Tooling/Tooling.h"
#include <iostream>
using namespace clang::tooling;
using namespace llvm;
using namespace clang;
class FindCommentsConsumer : public clang::ASTConsumer {
explicit FindCommentsConsumer(ASTContext *Context) {}
virtual void HandleTranslationUnit(clang::ASTContext &Context) {
auto comments = Context.getRawCommentList().getComments();
for (auto comment : comments) {
std::cout << comment->getRawText(Context.getSourceManager()).str() << std::endl;
std::cout << "Finished parsing for comments" << std::endl;
class FindCommentsAction : public clang::ASTFrontendAction {
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
clang::CompilerInstance &Compiler, llvm::StringRef InFile) {
return std::unique_ptr<clang::ASTConsumer>(
new FindCommentsConsumer(&Compiler.getASTContext()));
static llvm::cl::OptionCategory MyToolCategory("My tool options");
int main(int argc, const char **argv) {
CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
ClangTool Tool(OptionsParser.getCompilations(),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment