Implemented -ast-dump, -ast-print, -ast-dump-filter options in clang-check

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161753 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexander Kornienko 2012-08-13 10:50:08 +00:00
Родитель cd6df6695c
Коммит 4846470d20
2 изменённых файлов: 78 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,35 @@
// RUN: clang-check -ast-dump "%s" -- 2>&1 | FileCheck %s
// CHECK: namespace test_namespace
// CHECK-NEXT: class TheClass
// CHECK: int theMethod(int x) (CompoundStmt
// CHECK-NEXT: (ReturnStmt
// CHECK-NEXT: (BinaryOperator
//
// RUN: clang-check -ast-dump -ast-dump-filter test_namespace::TheClass::theMethod "%s" -- 2>&1 | FileCheck -check-prefix CHECK-FILTER %s
// CHECK-FILTER-NOT: namespace test_namespace
// CHECK-FILTER-NOT: class TheClass
// CHECK-FILTER: int theMethod(int x) (CompoundStmt
// CHECK-FILTER-NEXT: (ReturnStmt
// CHECK-FILTER-NEXT: (BinaryOperator
//
// RUN: clang-check -ast-print "%s" -- 2>&1 | FileCheck -check-prefix CHECK-PRINT %s
// CHECK-PRINT: namespace test_namespace
// CHECK-PRINT: class TheClass
// CHECK-PRINT: int theMethod(int x)
//
// RUN: clang-check -ast-list "%s" -- 2>&1 | FileCheck -check-prefix CHECK-LIST %s
// CHECK-LIST: test_namespace
// CHECK-LIST-NEXT: test_namespace::TheClass
// CHECK-LIST-NEXT: test_namespace::TheClass::theMethod
// CHECK-LIST-NEXT: x
namespace test_namespace {
class TheClass {
public:
int theMethod(int x) {
return x + x;
}
};
}

Просмотреть файл

@ -17,10 +17,15 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/CommandLine.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/Driver/OptTable.h"
#include "clang/Driver/Options.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommandLineClangTool.h"
#include "clang/Tooling/Tooling.h"
using namespace clang::driver;
using namespace clang::tooling;
using namespace llvm;
@ -38,9 +43,46 @@ static const char *MoreHelpText =
"\trules described above.\n"
"\n";
namespace {
class ActionFactory {
public:
ActionFactory()
: Options(createDriverOptTable()),
ASTDump(
"ast-dump",
cl::desc(Options->getOptionHelpText(options::OPT_ast_dump))),
ASTList(
"ast-list",
cl::desc(Options->getOptionHelpText(options::OPT_ast_list))),
ASTPrint(
"ast-print",
cl::desc(Options->getOptionHelpText(options::OPT_ast_print))),
ASTDumpFilter(
"ast-dump-filter",
cl::desc(Options->getOptionHelpText(options::OPT_ast_dump_filter))) {}
clang::ASTConsumer *newASTConsumer() {
if (ASTList)
return clang::CreateASTDeclNodeLister();
if (ASTDump)
return clang::CreateASTDumper(ASTDumpFilter);
if (ASTPrint)
return clang::CreateASTPrinter(&llvm::outs(), ASTDumpFilter);
return new clang::ASTConsumer();
}
private:
OwningPtr<OptTable> Options;
cl::opt<bool> ASTDump;
cl::opt<bool> ASTList;
cl::opt<bool> ASTPrint;
cl::opt<std::string> ASTDumpFilter;
};
}
int main(int argc, const char **argv) {
ActionFactory Factory;
CommandLineClangTool Tool;
cl::extrahelp MoreHelp(MoreHelpText);
Tool.initialize(argc, argv);
return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());
return Tool.run(newFrontendActionFactory(&Factory));
}