File indexing completed on 2026-05-10 08:36:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_AST_APNUMERICSTORAGE_H
0010 #define LLVM_CLANG_AST_APNUMERICSTORAGE_H
0011
0012 #include "llvm/ADT/APFloat.h"
0013 #include "llvm/ADT/APInt.h"
0014
0015 namespace clang {
0016 class ASTContext;
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 class APNumericStorage {
0027 union {
0028 uint64_t VAL;
0029 uint64_t *pVal;
0030 };
0031 unsigned BitWidth;
0032
0033 bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
0034
0035 APNumericStorage(const APNumericStorage &) = delete;
0036 void operator=(const APNumericStorage &) = delete;
0037
0038 protected:
0039 APNumericStorage() : VAL(0), BitWidth(0) {}
0040
0041 llvm::APInt getIntValue() const {
0042 unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
0043 if (NumWords > 1)
0044 return llvm::APInt(BitWidth, NumWords, pVal);
0045 else
0046 return llvm::APInt(BitWidth, VAL);
0047 }
0048 void setIntValue(const ASTContext &C, const llvm::APInt &Val);
0049 };
0050
0051 class APIntStorage : private APNumericStorage {
0052 public:
0053 llvm::APInt getValue() const { return getIntValue(); }
0054 void setValue(const ASTContext &C, const llvm::APInt &Val) {
0055 setIntValue(C, Val);
0056 }
0057 };
0058
0059 class APFloatStorage : private APNumericStorage {
0060 public:
0061 llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
0062 return llvm::APFloat(Semantics, getIntValue());
0063 }
0064 void setValue(const ASTContext &C, const llvm::APFloat &Val) {
0065 setIntValue(C, Val.bitcastToAPInt());
0066 }
0067 };
0068
0069 }
0070
0071 #endif