llvm/clang/lib/ASTMatchers/GtestMatchers.cpp

//===- GtestMatchers.cpp - AST Matchers for Gtest ---------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file implements several matchers for popular gtest macros. In general,
// AST matchers cannot match calls to macros. However, we can simulate such
// matches if the macro definition has identifiable elements that themselves can
// be matched. In that case, we can match on those elements and then check that
// the match occurs within an expansion of the desired macro. The more uncommon
// the identified elements, the more efficient this process will be.
//
//===----------------------------------------------------------------------===//

#include "clang/ASTMatchers/GtestMatchers.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"

namespace clang {
namespace ast_matchers {
namespace {

enum class MacroType {};

} // namespace

static DeclarationMatcher getComparisonDecl(GtestCmp Cmp) {}

static llvm::StringRef getMacroTypeName(MacroType Macro) {}

static llvm::StringRef getComparisonTypeName(GtestCmp Cmp) {}

static std::string getMacroName(MacroType Macro, GtestCmp Cmp) {}

static std::string getMacroName(MacroType Macro, llvm::StringRef Operation) {}

// Under the hood, ON_CALL is expanded to a call to `InternalDefaultActionSetAt`
// to set a default action spec to the underlying function mocker, while
// EXPECT_CALL is expanded to a call to `InternalExpectedAt` to set a new
// expectation spec.
static llvm::StringRef getSpecSetterName(MacroType Macro) {}

// In general, AST matchers cannot match calls to macros. However, we can
// simulate such matches if the macro definition has identifiable elements that
// themselves can be matched. In that case, we can match on those elements and
// then check that the match occurs within an expansion of the desired
// macro. The more uncommon the identified elements, the more efficient this
// process will be.
//
// We use this approach to implement the derived matchers gtestAssert and
// gtestExpect.
static internal::BindableMatcher<Stmt>
gtestComparisonInternal(MacroType Macro, GtestCmp Cmp, StatementMatcher Left,
                        StatementMatcher Right) {}

static internal::BindableMatcher<Stmt>
gtestThatInternal(MacroType Macro, StatementMatcher Actual,
                  StatementMatcher Matcher) {}

static internal::BindableMatcher<Stmt>
gtestCallInternal(MacroType Macro, StatementMatcher MockCall, MockArgs Args) {}

static internal::BindableMatcher<Stmt>
gtestCallInternal(MacroType Macro, StatementMatcher MockObject,
                  llvm::StringRef MockMethodName, MockArgs Args) {}

internal::BindableMatcher<Stmt> gtestAssert(GtestCmp Cmp, StatementMatcher Left,
                                            StatementMatcher Right) {}

internal::BindableMatcher<Stmt> gtestExpect(GtestCmp Cmp, StatementMatcher Left,
                                            StatementMatcher Right) {}

internal::BindableMatcher<Stmt> gtestAssertThat(StatementMatcher Actual,
                                                StatementMatcher Matcher) {}

internal::BindableMatcher<Stmt> gtestExpectThat(StatementMatcher Actual,
                                                StatementMatcher Matcher) {}

internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockObject,
                                            llvm::StringRef MockMethodName,
                                            MockArgs Args) {}

internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockCall,
                                            MockArgs Args) {}

internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockObject,
                                                llvm::StringRef MockMethodName,
                                                MockArgs Args) {}

internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockCall,
                                                MockArgs Args) {}

} // end namespace ast_matchers
} // end namespace clang