namespace clang {
class ASTContext;
class CXXRecordDecl;
+ class Decl;
class DeclGroupRef;
class HandleTagDeclDefinition;
class PPMutationListener;
/// PrintStats - If desired, print any statistics.
virtual void PrintStats() {}
+
+ /// \brief This callback is called for each function if the Parser was
+ /// initialized with \c SkipFunctionBodies set to \c true.
+ ///
+ /// \return \c true if the function's body should be skipped. The function
+ /// body may be parsed anyway if it is needed (for instance, if it contains
+ /// the code completion point or is constexpr).
+ virtual bool shouldSkipFunctionBody(Decl *D) { return true; }
};
} // end namespace clang.
#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"
}
#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