9#ifndef LLVM_CLANG_AST_INTERP_CHAR_H
10#define LLVM_CLANG_AST_INTERP_CHAR_H
18template <
unsigned N,
bool Signed>
class Integral;
28template <
bool Signed>
class Char final {
30 template <
bool OtherSigned>
friend class Char;
33 static_assert(std::is_trivially_copyable_v<ReprT>);
38 constexpr Char() =
default;
39 constexpr Char(ReprT V) : V(V) {}
42 : V(V.
isSigned() ? V.getSExtValue() : V.getZExtValue()) {}
45 return Char(
static_cast<ReprT
>(t));
47 template <
typename T>
static Char from(T t,
unsigned BitWidth) {
48 return Char(
static_cast<ReprT
>(t));
57 return V == std::numeric_limits<ReprT>::min();
61 constexpr bool isZero()
const {
return V == 0; }
64 template <
typename Ty,
typename = std::enable_if_t<std::is_
integral_v<Ty>>>
65 explicit operator Ty()
const {
76 return static_cast<unsigned>(V) >= RHS;
80 return V >= 0 &&
static_cast<unsigned>(V) > RHS;
89 std::memcpy(Dest, &V,
sizeof(V));
93 assert(BitWidth == 8);
96 std::memcpy(&V, Src,
sizeof(ReprT));
108 return APInt(8,
static_cast<uint64_t
>(V),
Signed).sextOrTrunc(BitWidth);
110 return APInt(8,
static_cast<uint64_t
>(V),
Signed).zextOrTrunc(BitWidth);
115 llvm::raw_string_ostream OS(NameStr);
122 assert(TruncBits >= 1);
125 const ReprT BitMask = (ReprT(1) << ReprT(TruncBits)) - 1;
126 const ReprT SignBit = ReprT(1) << (TruncBits - 1);
127 const ReprT ExtMask = ~BitMask;
128 return Char((V & BitMask) | (
Signed && (V & SignBit) ? ExtMask : 0));
133 return llvm::countl_zero<ReprT>(V);
135 return llvm::countl_zero<typename AsUnsigned::ReprT>(
136 static_cast<typename AsUnsigned::ReprT
>(V));
137 llvm_unreachable(
"Don't call countLeadingZeros() on negative values.");
161 *R =
Char(A.V % B.V);
166 *R =
Char(A.V / B.V);
171 *R =
Char(A.V & B.V);
176 *R =
Char(A.V | B.V);
181 *R =
Char(A.V ^ B.V);
198 template <
bool RHSSign>
201 *R =
Char(A.V << B.V);
204 template <
bool RHSSign>
207 *R =
Char(A.V >> B.V);
210 void print(llvm::raw_ostream &OS)
const { OS << V; }
213static_assert(
sizeof(Char<true>) == 1);
214static_assert(
sizeof(Char<false>) == 1);
216template <
bool Signed>
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static bool bitAnd(Char A, Char B, unsigned OpBits, Char *R)
static bool neg(Char A, Char *R)
constexpr bool isZero() const
Char truncate(unsigned TruncBits) const
void bitcastToMemory(std::byte *Dest) const
constexpr bool isPositive() const
ComparisonCategoryResult compare(Char RHS) const
bool operator>=(unsigned RHS) const
static bool decrement(Char A, Char *R)
static bool rem(Char A, Char B, unsigned OpBits, Char *R)
static bool sub(Char A, Char B, unsigned OpBits, Char *R)
APValue toAPValue(const ASTContext &) const
static Char zero(unsigned BitWidth=8)
static bool bitOr(Char A, Char B, unsigned OpBits, Char *R)
bool operator<(Char RHS) const
static unsigned bitWidth()
bool operator>=(Char RHS) const
static bool bitXor(Char A, Char B, unsigned OpBits, Char *R)
static bool mul(Char A, Char B, unsigned OpBits, Char *R)
bool operator!=(Char RHS) const
std::string toDiagnosticString(const ASTContext &Ctx) const
static void shiftRight(const Char A, const Char< RHSSign > B, unsigned OpBits, Char *R)
unsigned countLeadingZeros() const
static bool div(Char A, Char B, unsigned OpBits, Char *R)
static bool add(Char A, Char B, unsigned OpBits, Char *R)
Char operator-(Char Other) const
static Char bitcastFromMemory(const std::byte *Src, unsigned BitWidth)
static void shiftLeft(const Char A, const Char< RHSSign > B, unsigned OpBits, Char *R)
constexpr bool isNegative() const
bool operator>(Char RHS) const
bool operator>(unsigned RHS) const
Char< false > toUnsigned() const
APSInt toAPSInt(unsigned BitWidth) const
static Char from(T t, unsigned BitWidth)
constexpr bool isMin() const
bool operator<=(Char RHS) const
bool operator==(Char RHS) const
static bool increment(Char A, Char *R)
void print(llvm::raw_ostream &OS) const
APInt toAPInt(unsigned BitWidth) const
constexpr bool isMinusOne() const
static bool comp(Char A, Char *R)
Wrapper around numeric types.
bool CheckMulUB(T A, T B, T &R)
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
ComparisonCategoryResult Compare(const T &X, const T &Y)
Helper to compare two comparable types.
bool CheckSubUB(T A, T B, T &R)
bool CheckAddUB(T A, T B, T &R)
The JSON file list parser is used to communicate input to InstallAPI.
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
@ Other
Other implicit parameter.