#include "AvoidBindCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstddef>
#include <string>
usingnamespaceclang::ast_matchers;
namespace clang::tidy::modernize {
namespace {
enum BindArgumentKind { … };
enum CaptureMode { … };
enum CaptureExpr { … };
enum CallableType { … };
enum CallableMaterializationKind { … };
struct BindArgument { … };
struct CallableInfo { … };
struct LambdaProperties { … };
}
static bool tryCaptureAsLocalVariable(const MatchFinder::MatchResult &Result,
BindArgument &B, const Expr *E);
static bool tryCaptureAsMemberVariable(const MatchFinder::MatchResult &Result,
BindArgument &B, const Expr *E);
static const Expr *ignoreTemporariesAndPointers(const Expr *E) { … }
static const Expr *ignoreTemporariesAndConstructors(const Expr *E) { … }
static StringRef getSourceTextForExpr(const MatchFinder::MatchResult &Result,
const Expr *E) { … }
static bool isCallExprNamed(const Expr *E, StringRef Name) { … }
static void
initializeBindArgumentForCallExpr(const MatchFinder::MatchResult &Result,
BindArgument &B, const CallExpr *CE,
unsigned &CaptureIndex) { … }
static bool anyDescendantIsLocal(const Stmt *Statement) { … }
static bool tryCaptureAsLocalVariable(const MatchFinder::MatchResult &Result,
BindArgument &B, const Expr *E) { … }
static bool tryCaptureAsMemberVariable(const MatchFinder::MatchResult &Result,
BindArgument &B, const Expr *E) { … }
static SmallVector<BindArgument, 4>
buildBindArguments(const MatchFinder::MatchResult &Result,
const CallableInfo &Callable) { … }
static int findPositionOfPlaceholderUse(ArrayRef<BindArgument> Args,
size_t PlaceholderIndex) { … }
static void addPlaceholderArgs(const LambdaProperties &LP,
llvm::raw_ostream &Stream,
bool PermissiveParameterList) { … }
static void addFunctionCallArgs(ArrayRef<BindArgument> Args,
llvm::raw_ostream &Stream) { … }
static bool isPlaceHolderIndexRepeated(const ArrayRef<BindArgument> Args) { … }
static std::vector<const FunctionDecl *>
findCandidateCallOperators(const CXXRecordDecl *RecordDecl, size_t NumArgs) { … }
static bool isFixitSupported(const CallableInfo &Callee,
ArrayRef<BindArgument> Args) { … }
const FunctionDecl *getCallOperator(const CXXRecordDecl *Callable,
size_t NumArgs) { … }
const FunctionDecl *
getCallMethodDecl(const MatchFinder::MatchResult &Result, CallableType Type,
CallableMaterializationKind Materialization) { … }
static CallableType getCallableType(const MatchFinder::MatchResult &Result) { … }
static CallableMaterializationKind
getCallableMaterialization(const MatchFinder::MatchResult &Result) { … }
static LambdaProperties
getLambdaProperties(const MatchFinder::MatchResult &Result) { … }
static bool emitCapture(llvm::StringSet<> &CaptureSet, StringRef Delimiter,
CaptureMode CM, CaptureExpr CE, StringRef Identifier,
StringRef InitExpression, raw_ostream &Stream) { … }
static void emitCaptureList(const LambdaProperties &LP,
const MatchFinder::MatchResult &Result,
raw_ostream &Stream) { … }
static ArrayRef<BindArgument>
getForwardedArgumentList(const LambdaProperties &P) { … }
AvoidBindCheck::AvoidBindCheck(StringRef Name, ClangTidyContext *Context)
: … { … }
void AvoidBindCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { … }
void AvoidBindCheck::registerMatchers(MatchFinder *Finder) { … }
void AvoidBindCheck::check(const MatchFinder::MatchResult &Result) { … }
}