clang: include/clang/AST/APValue.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_CLANG_AST_APVALUE_H

14#define LLVM_CLANG_AST_APVALUE_H

15

17#include "llvm/ADT/APFixedPoint.h"

18#include "llvm/ADT/APFloat.h"

19#include "llvm/ADT/APSInt.h"

20#include "llvm/ADT/FoldingSet.h"

21#include "llvm/ADT/PointerIntPair.h"

22#include "llvm/ADT/PointerUnion.h"

23#include "llvm/Support/AlignOf.h"

24

26namespace serialization {

28}

29

42

43

45 const Type *T;

46

47public:

50

52 explicit operator bool() const { return T; }

53

57 V.T = reinterpret_cast<const Type*>(Value);

58 return V;

59 }

60

62};

63

64

66 unsigned Index;

67

68public:

71 unsigned getIndex() { return Index - 1; }

72

73 explicit operator bool() const { return Index != 0; }

74

76 return reinterpret_cast<void *>(static_cast<uintptr_t>(Index)

78 }

82 return V;

83 }

84

87 }

88

90};

91}

92

93namespace llvm {

96 return V.getOpaqueValue();

97 }

100 }

101

102

103 static constexpr int NumLowBitsAvailable = 3;

104};

105

108 return V.getOpaqueValue();

109 }

112 }

113 static constexpr int NumLowBitsAvailable =

115};

116}

117

119

120

121

123 typedef llvm::APFixedPoint APFixedPoint;

124 typedef llvm::APSInt APSInt;

125 typedef llvm::APFloat APFloat;

126public:

128

130

145

149 PtrTy;

150

151 public:

157

158 void Profile(llvm::FoldingSetNodeID &ID) const;

159

160 template bool is() const { return isa(Ptr); }

161

162 template T get() const { return cast(Ptr); }

163

164 template

166

168

170

171 explicit operator bool() const;

172

177

179

182 return !(LHS == RHS);

183 }

185 friend struct llvm::DenseMapInfo<LValueBase>;

186

187 private:

188 PtrTy Ptr;

189 struct LocalState {

190 unsigned CallIndex, Version;

191 };

192 union {

194

196

198 };

199 };

200

201

202

204

205

207 static_assert(sizeof(uintptr_t) <= sizeof(uint64_t),

208 "pointer doesn't fit in 64 bits?");

210

211 public:

216 Result.Value = Index;

218 }

219

221 return BaseOrMemberType::getFromOpaqueValue(

222 reinterpret_cast<void *>(Value));

223 }

225

226 void Profile(llvm::FoldingSetNodeID &ID) const;

227

229 return A.Value == B.Value;

230 }

232 return A.Value != B.Value;

233 }

236 }

237 };

239 const void *Ty;

240

241 public:

243

246 };

250

254

255private:

257

258 struct ComplexAPSInt {

259 APSInt Real, Imag;

260 ComplexAPSInt() : Real(1), Imag(1) {}

261 };

262 struct ComplexAPFloat {

263 APFloat Real, Imag;

264 ComplexAPFloat() : Real(0.0), Imag(0.0) {}

265 };

266 struct LV;

267 struct Vec {

269 unsigned NumElts = 0;

270 Vec() = default;

271 Vec(const Vec &) = delete;

272 Vec &operator=(const Vec &) = delete;

273 ~Vec() { delete[] Elts; }

274 };

275 struct Arr {

277 unsigned NumElts, ArrSize;

278 Arr(unsigned NumElts, unsigned ArrSize);

279 Arr(const Arr &) = delete;

280 Arr &operator=(const Arr &) = delete;

281 ~Arr();

282 };

283 struct StructData {

285 unsigned NumBases;

286 unsigned NumFields;

287 StructData(unsigned NumBases, unsigned NumFields);

288 StructData(const StructData &) = delete;

289 StructData &operator=(const StructData &) = delete;

290 ~StructData();

291 };

292 struct UnionData {

293 const FieldDecl *Field;

295 UnionData();

296 UnionData(const UnionData &) = delete;

297 UnionData &operator=(const UnionData &) = delete;

298 ~UnionData();

299 };

300 struct AddrLabelDiffData {

301 const AddrLabelExpr* LHSExpr;

302 const AddrLabelExpr* RHSExpr;

303 };

304 struct MemberPointerData;

305

306

307 typedef llvm::AlignedCharArrayUnion<void *, APSInt, APFloat, ComplexAPSInt,

308 ComplexAPFloat, Vec, Arr, StructData,

309 UnionData, AddrLabelDiffData> DataType;

310 static const size_t DataSize = sizeof(DataType);

311

312 DataType Data;

313

314public:

315

317

319 MakeInt(); setInt(std::move(I));

320 }

321

323 MakeFloat(); setFloat(std::move(F));

324 }

325

327 MakeFixedPoint(std::move(FX));

328 }

329

330

333 }

334

335

337 MakeComplexInt(); setComplexInt(std::move(R), std::move(I));

338 }

339

341 MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I));

342 }

345

346

347

348

350 bool IsNullPtr = false)

352 MakeLValue();

354 }

355

356

357

358

359

360

361

364 bool IsNullPtr = false)

366 MakeLValue();

368 }

369

370

371

372

373

375 MakeArray(InitElts, Size);

376 }

377

378

379

380

382 MakeStruct(NumBases, NumMembers);

383 }

384

385

386

390 MakeUnion();

391 setUnion(ActiveDecl, ActiveValue);

392 }

393

394

395

396

399 MakeMemberPointer(Member, IsDerivedMember, Path);

400 }

401

402

403

407 }

412 }

413

416

419 DestroyDataAndMakeUninit();

420 }

421

422

423

424

425

426

428

429

431

432

433

434

435 void Profile(llvm::FoldingSetNodeID &ID) const;

436

438

442

455

456 void dump() const;

457 void dump(raw_ostream &OS, const ASTContext &Context) const;

458

461 const ASTContext *Ctx = nullptr) const;

462

464

466 assert(isInt() && "Invalid accessor");

467 return *(APSInt *)(char *)&Data;

468 }

471 }

472

473

474

475

478

480 assert(isFloat() && "Invalid accessor");

481 return *(APFloat *)(char *)&Data;

482 }

485 }

486

488 assert(isFixedPoint() && "Invalid accessor");

489 return *(APFixedPoint *)(char *)&Data;

490 }

493 }

494

496 assert(isComplexInt() && "Invalid accessor");

497 return ((ComplexAPSInt *)(char *)&Data)->Real;

498 }

501 }

502

504 assert(isComplexInt() && "Invalid accessor");

505 return ((ComplexAPSInt *)(char *)&Data)->Imag;

506 }

509 }

510

513 return ((ComplexAPFloat *)(char *)&Data)->Real;

514 }

517 }

518

521 return ((ComplexAPFloat *)(char *)&Data)->Imag;

522 }

525 }

526

531 }

538

540 assert(isVector() && "Invalid accessor");

542 return ((Vec *)(char *)&Data)->Elts[I];

543 }

546 }

548 assert(isVector() && "Invalid accessor");

549 return ((const Vec *)(const void *)&Data)->NumElts;

550 }

551

553 assert(isArray() && "Invalid accessor");

555 return ((Arr *)(char *)&Data)->Elts[I];

556 }

559 }

562 }

564 assert(isArray() && "Invalid accessor");

567 }

570 }

572 assert(isArray() && "Invalid accessor");

573 return ((const Arr *)(const void *)&Data)->NumElts;

574 }

576 assert(isArray() && "Invalid accessor");

577 return ((const Arr *)(const void *)&Data)->ArrSize;

578 }

579

581 assert(isStruct() && "Invalid accessor");

582 return ((const StructData *)(const char *)&Data)->NumBases;

583 }

585 assert(isStruct() && "Invalid accessor");

586 return ((const StructData *)(const char *)&Data)->NumFields;

587 }

589 assert(isStruct() && "Invalid accessor");

591 return ((StructData *)(char *)&Data)->Elts[i];

592 }

594 assert(isStruct() && "Invalid accessor");

597 }

600 }

603 }

604

606 assert(isUnion() && "Invalid accessor");

607 return ((const UnionData *)(const char *)&Data)->Field;

608 }

610 assert(isUnion() && "Invalid accessor");

611 return *((UnionData *)(char *)&Data)->Value;

612 }

615 }

616

620

623 return ((const AddrLabelDiffData *)(const char *)&Data)->LHSExpr;

624 }

627 return ((const AddrLabelDiffData *)(const char *)&Data)->RHSExpr;

628 }

629

631 assert(isInt() && "Invalid accessor");

632 *(APSInt *)(char *)&Data = std::move(I);

633 }

635 assert(isFloat() && "Invalid accessor");

636 *(APFloat *)(char *)&Data = std::move(F);

637 }

639 assert(isFixedPoint() && "Invalid accessor");

640 *(APFixedPoint *)(char *)&Data = std::move(FX);

641 }

644 for (unsigned i = 0; i != N; ++i)

645 InternalElts[i] = E[i];

646 }

648 assert(R.getBitWidth() == I.getBitWidth() &&

649 "Invalid complex int (type mismatch).");

650 assert(isComplexInt() && "Invalid accessor");

651 ((ComplexAPSInt *)(char *)&Data)->Real = std::move(R);

652 ((ComplexAPSInt *)(char *)&Data)->Imag = std::move(I);

653 }

655 assert(&R.getSemantics() == &I.getSemantics() &&

656 "Invalid complex float (type mismatch).");

658 ((ComplexAPFloat *)(char *)&Data)->Real = std::move(R);

659 ((ComplexAPFloat *)(char *)&Data)->Imag = std::move(I);

660 }

662 bool IsNullPtr);

665 bool IsNullPtr);

669 ((AddrLabelDiffData *)(char *)&Data)->LHSExpr = LHSExpr;

670 ((AddrLabelDiffData *)(char *)&Data)->RHSExpr = RHSExpr;

671 }

672

673private:

674 void DestroyDataAndMakeUninit();

675 void MakeInt() {

676 assert(isAbsent() && "Bad state change");

679 }

680 void MakeFloat() {

681 assert(isAbsent() && "Bad state change");

682 new ((void *)(char *)&Data) APFloat(0.0);

684 }

685 void MakeFixedPoint(APFixedPoint &&FX) {

686 assert(isAbsent() && "Bad state change");

687 new ((void *)(char *)&Data) APFixedPoint(std::move(FX));

689 }

690 void MakeVector() {

691 assert(isAbsent() && "Bad state change");

692 new ((void *)(char *)&Data) Vec();

694 }

695 void MakeComplexInt() {

696 assert(isAbsent() && "Bad state change");

697 new ((void *)(char *)&Data) ComplexAPSInt();

699 }

700 void MakeComplexFloat() {

701 assert(isAbsent() && "Bad state change");

702 new ((void *)(char *)&Data) ComplexAPFloat();

704 }

705 void MakeLValue();

706 void MakeArray(unsigned InitElts, unsigned Size);

707 void MakeStruct(unsigned B, unsigned M) {

708 assert(isAbsent() && "Bad state change");

709 new ((void *)(char *)&Data) StructData(B, M);

711 }

712 void MakeUnion() {

713 assert(isAbsent() && "Bad state change");

714 new ((void *)(char *)&Data) UnionData();

716 }

717 void MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,

718 ArrayRef<const CXXRecordDecl*> Path);

719 void MakeAddrLabelDiff() {

720 assert(isAbsent() && "Bad state change");

721 new ((void *)(char *)&Data) AddrLabelDiffData();

723 }

724

725private:

726

727

728

729 MutableArrayRef setVectorUninit(unsigned N) {

730 assert(isVector() && "Invalid accessor");

731 Vec *V = ((Vec *)(char *)&Data);

733 V->NumElts = N;

734 return {V->Elts, V->NumElts};

735 }

736 MutableArrayRef

737 setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,

738 bool OnePastTheEnd, bool IsNullPtr);

739 MutableArrayRef<const CXXRecordDecl *>

740 setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember,

741 unsigned Size);

742};

743

744}

745

746namespace llvm {

747template<> struct DenseMapInfo<clang::APValue::LValueBase> {

753};

754}

755

756#endif

enum clang::sema::@1725::IndirectLocalPathEntry::EntryKind Kind

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

friend llvm::hash_code hash_value(const LValueBase &Base)

friend bool operator!=(const LValueBase &LHS, const LValueBase &RHS)

void Profile(llvm::FoldingSetNodeID &ID) const

unsigned getVersion() const

QualType getDynamicAllocType() const

QualType getTypeInfoType() const

friend bool operator==(const LValueBase &LHS, const LValueBase &RHS)

void * DynamicAllocType

The QualType, if this is a DynamicAllocLValue.

static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)

static LValueBase getDynamicAlloc(DynamicAllocLValue LV, QualType Type)

void * TypeInfoType

The type std::type_info, if this is a TypeInfoLValue.

void * getOpaqueValue() const

unsigned getCallIndex() const

A non-discriminated union of a base, field, or array index.

BaseOrMemberType getAsBaseOrMember() const

uint64_t getAsArrayIndex() const

friend llvm::hash_code hash_value(LValuePathEntry A)

friend bool operator!=(LValuePathEntry A, LValuePathEntry B)

static LValuePathEntry ArrayIndex(uint64_t Index)

friend bool operator==(LValuePathEntry A, LValuePathEntry B)

void Profile(llvm::FoldingSetNodeID &ID) const

ArrayRef< LValuePathEntry > Path

APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...

const APSInt & getComplexIntReal() const

bool hasArrayFiller() const

const LValueBase getLValueBase() const

APValue(LValueBase Base, const CharUnits &Offset, NoLValuePath, bool IsNullPtr=false)

Creates an lvalue APValue without an lvalue path.

APValue(APFloat F)

Creates a float APValue holding the given value.

APValue & getArrayInitializedElt(unsigned I)

ArrayRef< LValuePathEntry > getLValuePath() const

void swap(APValue &RHS)

Swaps the contents of this and the given APValue.

APValue & getStructField(unsigned i)

APValue(APSInt I)

Creates an integer APValue holding the given value.

const FieldDecl * getUnionField() const

const APFloat & getFloat() const

APSInt & getComplexIntImag()

unsigned getStructNumFields() const

const APValue & getArrayInitializedElt(unsigned I) const

APValue(APFloat R, APFloat I)

Creates a float complex APValue with the given real and imaginary values.

APValue(const FieldDecl *ActiveDecl, const APValue &ActiveValue=APValue())

Creates a new union APValue.

bool isComplexInt() const

llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType

A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...

ValueKind getKind() const

bool isLValueOnePastTheEnd() const

APValue(const APValue *E, unsigned N)

Creates a vector APValue with N elements.

void setFixedPoint(APFixedPoint FX)

unsigned getLValueVersion() const

bool isMemberPointerToDerivedMember() const

unsigned getArrayInitializedElts() const

static APValue IndeterminateValue()

void setComplexInt(APSInt R, APSInt I)

const APFixedPoint & getFixedPoint() const

void Profile(llvm::FoldingSetNodeID &ID) const

profile this value.

unsigned getStructNumBases() const

APFixedPoint & getFixedPoint()

APValue(const ValueDecl *Member, bool IsDerivedMember, ArrayRef< const CXXRecordDecl * > Path)

Creates a new member pointer APValue.

bool needsCleanup() const

Returns whether the object performed allocations.

const APValue & getStructBase(unsigned i) const

APValue(LValueBase Base, const CharUnits &Offset, ArrayRef< LValuePathEntry > Path, bool OnePastTheEnd, bool IsNullPtr=false)

Creates an lvalue APValue with an lvalue path.

bool hasLValuePath() const

const ValueDecl * getMemberPointerDecl() const

APValue & getUnionValue()

const AddrLabelExpr * getAddrLabelDiffRHS() const

CharUnits & getLValueOffset()

void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const

void setAddrLabelDiff(const AddrLabelExpr *LHSExpr, const AddrLabelExpr *RHSExpr)

void setComplexFloat(APFloat R, APFloat I)

bool isComplexFloat() const

APValue & getVectorElt(unsigned I)

APValue & getArrayFiller()

const APValue & getArrayFiller() const

const APFloat & getComplexFloatImag() const

unsigned getVectorLength() const

const APValue & getUnionValue() const

const APValue & getVectorElt(unsigned I) const

APValue(UninitArray, unsigned InitElts, unsigned Size)

Creates a new array APValue.

APValue(UninitStruct, unsigned NumBases, unsigned NumMembers)

Creates a new struct APValue.

void setUnion(const FieldDecl *Field, const APValue &Value)

APValue(const AddrLabelExpr *LHSExpr, const AddrLabelExpr *RHSExpr)

Creates a new address label diff APValue.

bool isIndeterminate() const

void setLValue(LValueBase B, const CharUnits &O, NoLValuePath, bool IsNullPtr)

ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const

bool isMemberPointer() const

const APSInt & getInt() const

const APFloat & getComplexFloatReal() const

unsigned getArraySize() const

APValue(APSInt R, APSInt I)

Creates an integer complex APValue with the given real and imaginary values.

bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const

Try to convert this value to an integral constant.

const CharUnits & getLValueOffset() const

std::string getAsString(const ASTContext &Ctx, QualType Ty) const

bool isFixedPoint() const

APValue & operator=(const APValue &RHS)

unsigned getLValueCallIndex() const

void setVector(const APValue *E, unsigned N)

@ Indeterminate

This object has an indeterminate value (C++ [basic.indet]).

@ None

There is no such object (it's outside its lifetime).

const APValue & getStructField(unsigned i) const

const APSInt & getComplexIntImag() const

bool isNullPointer() const

APSInt & getComplexIntReal()

APFloat & getComplexFloatImag()

APFloat & getComplexFloatReal()

APValue & getStructBase(unsigned i)

APValue(APFixedPoint FX)

Creates a fixed-point APValue holding the given value.

const AddrLabelExpr * getAddrLabelDiffLHS() const

bool isAddrLabelDiff() const

APValue()

Creates an empty APValue of type None.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...

AddrLabelExpr - The GNU address of label extension, representing &&label.

Represents a C++ struct/union/class.

CharUnits - This is an opaque type for sizes expressed in character units.

Decl - This represents one declaration (or definition), e.g.

A little helper class used to produce diagnostics.

Symbolic representation of a dynamic allocation.

static unsigned getMaxIndex()

static constexpr int NumLowBitsAvailable

DynamicAllocLValue(unsigned Index)

static DynamicAllocLValue getFromOpaqueValue(void *Value)

This represents one expression.

Represents a member of a struct/union/class.

A (possibly-)qualified type.

Symbolic representation of typeid(T) for some type T.

const Type * getType() const

static TypeInfoLValue getFromOpaqueValue(void *Value)

void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const

The base class of the type hierarchy.

Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...

The JSON file list parser is used to communicate input to InstallAPI.

@ Result

The result type of a method or function.

const FunctionProtoType * T

Diagnostic wrappers for TextAPI types for error reporting.

hash_code hash_value(const clang::tooling::dependencies::ModuleID &ID)

__UINTPTR_TYPE__ uintptr_t

An unsigned integer type with the property that any valid pointer to void can be converted to this ty...

Describes how types, statements, expressions, and declarations should be printed.

static void * getAsVoidPointer(clang::DynamicAllocLValue V)

static clang::DynamicAllocLValue getFromVoidPointer(void *P)

static void * getAsVoidPointer(clang::TypeInfoLValue V)

static clang::TypeInfoLValue getFromVoidPointer(void *P)