#include "NarrowingConversionsCheck.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Type.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include <cstdint>
usingnamespaceclang::ast_matchers;
namespace clang::tidy::cppcoreguidelines {
namespace {
AST_MATCHER_P(QualType, hasAnyType, std::vector<StringRef>, Names) { … }
AST_MATCHER(FieldDecl, hasIntBitwidth) { … }
}
NarrowingConversionsCheck::NarrowingConversionsCheck(StringRef Name,
ClangTidyContext *Context)
: … { … }
void NarrowingConversionsCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) { … }
void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) { … }
static const BuiltinType *getBuiltinType(const Expr &E) { … }
static QualType getUnqualifiedType(const Expr &E) { … }
static APValue getConstantExprValue(const ASTContext &Ctx, const Expr &E) { … }
static bool getIntegerConstantExprValue(const ASTContext &Context,
const Expr &E, llvm::APSInt &Value) { … }
static bool getFloatingConstantExprValue(const ASTContext &Context,
const Expr &E, llvm::APFloat &Value) { … }
namespace {
struct IntegerRange { … };
}
static IntegerRange createFromType(const ASTContext &Context,
const BuiltinType &T) { … }
static bool isWideEnoughToHold(const ASTContext &Context,
const BuiltinType &FromType,
const BuiltinType &ToType) { … }
static bool isWideEnoughToHold(const ASTContext &Context,
const llvm::APSInt &IntegerConstant,
const BuiltinType &ToType) { … }
static bool isFloatExactlyRepresentable(const ASTContext &Context,
const llvm::APFloat &FloatConstant,
const QualType &DestType) { … }
static llvm::SmallString<64> getValueAsString(const llvm::APSInt &Value,
uint64_t HexBits) { … }
bool NarrowingConversionsCheck::isWarningInhibitedByEquivalentSize(
const ASTContext &Context, const BuiltinType &FromType,
const BuiltinType &ToType) const { … }
void NarrowingConversionsCheck::diagNarrowType(SourceLocation SourceLoc,
const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::diagNarrowTypeToSignedInt(
SourceLocation SourceLoc, const Expr &Lhs, const Expr &Rhs) { … }
void NarrowingConversionsCheck::diagNarrowIntegerConstant(
SourceLocation SourceLoc, const Expr &Lhs, const Expr &Rhs,
const llvm::APSInt &Value) { … }
void NarrowingConversionsCheck::diagNarrowIntegerConstantToSignedInt(
SourceLocation SourceLoc, const Expr &Lhs, const Expr &Rhs,
const llvm::APSInt &Value, const uint64_t HexBits) { … }
void NarrowingConversionsCheck::diagNarrowConstant(SourceLocation SourceLoc,
const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::diagConstantCast(SourceLocation SourceLoc,
const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::diagNarrowTypeOrConstant(
const ASTContext &Context, SourceLocation SourceLoc, const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleIntegralCast(const ASTContext &Context,
SourceLocation SourceLoc,
const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleIntegralToBoolean(
const ASTContext &Context, SourceLocation SourceLoc, const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleIntegralToFloating(
const ASTContext &Context, SourceLocation SourceLoc, const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleFloatingToIntegral(
const ASTContext &Context, SourceLocation SourceLoc, const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleFloatingToBoolean(
const ASTContext &Context, SourceLocation SourceLoc, const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleBooleanToSignedIntegral(
const ASTContext &Context, SourceLocation SourceLoc, const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleFloatingCast(const ASTContext &Context,
SourceLocation SourceLoc,
const Expr &Lhs,
const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleBinaryOperator(const ASTContext &Context,
SourceLocation SourceLoc,
const Expr &Lhs,
const Expr &Rhs) { … }
bool NarrowingConversionsCheck::handleConditionalOperator(
const ASTContext &Context, const Expr &Lhs, const Expr &Rhs) { … }
void NarrowingConversionsCheck::handleImplicitCast(
const ASTContext &Context, const ImplicitCastExpr &Cast) { … }
void NarrowingConversionsCheck::handleBinaryOperator(const ASTContext &Context,
const BinaryOperator &Op) { … }
void NarrowingConversionsCheck::check(const MatchFinder::MatchResult &Result) { … }
}