//===- unittest/AST/MatchVerifier.h - AST unit test support ---------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Provides MatchVerifier, a base class to implement gtest matchers that // verify things that can be matched on the AST. // // Also implements matchers based on MatchVerifier: // LocationVerifier and RangeVerifier to verify whether a matched node has // the expected source location or source range. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_UNITTESTS_AST_MATCHVERIFIER_H #define LLVM_CLANG_UNITTESTS_AST_MATCHVERIFIER_H #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Testing/CommandLineArgs.h" #include "clang/Tooling/Tooling.h" #include "gtest/gtest.h" namespace clang { namespace ast_matchers { /// \brief Base class for verifying some property of nodes found by a matcher. template <typename NodeType> class MatchVerifier : public MatchFinder::MatchCallback { … }; /// \brief Runs a matcher over some code, and returns the result of the /// verifier for the matched node. template <typename NodeType> template <typename MatcherType> testing::AssertionResult MatchVerifier<NodeType>::match(const std::string &Code, const MatcherType &AMatcher, std::vector<std::string> &Args, TestLanguage L) { … } /// \brief Runs a matcher over some AST, and returns the result of the /// verifier for the matched node. template <typename NodeType> template <typename MatcherType> testing::AssertionResult MatchVerifier<NodeType>::match( const Decl *D, const MatcherType &AMatcher) { … } template <typename NodeType> void MatchVerifier<NodeType>::run(const MatchFinder::MatchResult &Result) { … } template <> inline void MatchVerifier<DynTypedNode>::run(const MatchFinder::MatchResult &Result) { … } /// \brief Verify whether a node has the correct source location. /// /// By default, Node.getSourceLocation() is checked. This can be changed /// by overriding getLocation(). template <typename NodeType> class LocationVerifier : public MatchVerifier<NodeType> { … }; /// \brief Verify whether a node has the correct source range. /// /// By default, Node.getSourceRange() is checked. This can be changed /// by overriding getRange(). template <typename NodeType> class RangeVerifier : public MatchVerifier<NodeType> { … }; /// \brief Verify whether a node's dump contains a given substring. class DumpVerifier : public MatchVerifier<DynTypedNode> { … }; /// \brief Verify whether a node's pretty print matches a given string. class PrintVerifier : public MatchVerifier<DynTypedNode> { … }; } // end namespace ast_matchers } // end namespace clang #endif