diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-11-27 21:31:01 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-11-27 21:31:01 +0000 |
| commit | 9219d1b764d9ce765012a933d4c19eb23968387f (patch) | |
| tree | 64e306bbfe89c21bd56a4c518d8093b3857bcd9a /clang/unittests/Tooling | |
| parent | 7d125a11f152e1907b4eb50e48430cd89c0f130e (diff) | |
| download | bcm5719-llvm-9219d1b764d9ce765012a933d4c19eb23968387f.tar.gz bcm5719-llvm-9219d1b764d9ce765012a933d4c19eb23968387f.zip | |
Allow an ASTConsumer to selectively skip function bodies while parsing. Patch
by Olivier Goffart!
llvm-svn: 168726
Diffstat (limited to 'clang/unittests/Tooling')
| -rw-r--r-- | clang/unittests/Tooling/ToolingTest.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index d40c613dd05..a45935db4e3 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -10,6 +10,7 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclGroup.h" +#include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CompilationDatabase.h" @@ -162,5 +163,28 @@ TEST(newFrontendActionFactory, InjectsEndOfSourceFileCallback) { } #endif +struct SkipBodyConsumer : public clang::ASTConsumer { + /// Skip the 'skipMe' function. + virtual bool shouldSkipFunctionBody(Decl *D) { + FunctionDecl *F = dyn_cast<FunctionDecl>(D); + return F && F->getNameAsString() == "skipMe"; + } +}; + +struct SkipBodyAction : public clang::ASTFrontendAction { + virtual ASTConsumer *CreateASTConsumer(CompilerInstance &Compiler, + StringRef) { + Compiler.getFrontendOpts().SkipFunctionBodies = true; + return new SkipBodyConsumer; + } +}; + +TEST(runToolOnCode, TestSkipFunctionBoddy) { + EXPECT_TRUE(runToolOnCode(new SkipBodyAction, + "int skipMe() { an_error_here }")); + EXPECT_FALSE(runToolOnCode(new SkipBodyAction, + "int skipMeNot() { an_error_here }")); +} + } // end namespace tooling } // end namespace clang |

