APValue.h revision e24f5fc8c763f1b5536b8d70dd510ca959db3a80
1014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//===--- APValue.h - Union class for APFloat/APSInt/Complex -----*- C++ -*-===//
2014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//
3014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//                     The LLVM Compiler Infrastructure
4014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//
5014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// This file is distributed under the University of Illinois Open Source
6014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// License. See LICENSE.TXT for details.
7014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//
8014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//===----------------------------------------------------------------------===//
9014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//
10014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//  This file defines the APValue class.
11014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//
12014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//===----------------------------------------------------------------------===//
13014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
14014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#ifndef LLVM_CLANG_AST_APVALUE_H
15014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#define LLVM_CLANG_AST_APVALUE_H
16014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
17014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#include "clang/Basic/LLVM.h"
18014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#include "llvm/ADT/APSInt.h"
19014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#include "llvm/ADT/APFloat.h"
20014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#include "llvm/ADT/PointerIntPair.h"
21014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#include "llvm/ADT/PointerUnion.h"
221b268ca467c924004286c97bac133db489cf43d0Ben Murdoch
23014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochnamespace clang {
241b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  class CharUnits;
251b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  class DiagnosticBuilder;
261b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  class Expr;
271b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  class FieldDecl;
28014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  class Decl;
29014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  class ValueDecl;
30014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  class CXXRecordDecl;
31014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
32014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch/// APValue - This class implements a discriminated union of [uninitialized]
33014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch/// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
34014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch/// [Vector: N * APValue], [Array: N * APValue]
35014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochclass APValue {
36014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  typedef llvm::APSInt APSInt;
371b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  typedef llvm::APFloat APFloat;
38014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochpublic:
39014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  enum ValueKind {
40014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Uninitialized,
41014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Int,
42014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Float,
431b268ca467c924004286c97bac133db489cf43d0Ben Murdoch    ComplexInt,
44014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ComplexFloat,
45014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    LValue,
46014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Vector,
47014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Array,
48014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Struct,
49014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Union,
50014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MemberPointer
511b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  };
52014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  typedef llvm::PointerUnion<const ValueDecl *, const Expr *> LValueBase;
53014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  typedef llvm::PointerIntPair<const Decl *, 1, bool> BaseOrMemberType;
541b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  union LValuePathEntry {
551b268ca467c924004286c97bac133db489cf43d0Ben Murdoch    /// BaseOrMember - The FieldDecl or CXXRecordDecl indicating the next item
561b268ca467c924004286c97bac133db489cf43d0Ben Murdoch    /// in the path. An opaque value of type BaseOrMemberType.
571b268ca467c924004286c97bac133db489cf43d0Ben Murdoch    void *BaseOrMember;
581b268ca467c924004286c97bac133db489cf43d0Ben Murdoch    /// ArrayIndex - The array index of the next item in the path.
591b268ca467c924004286c97bac133db489cf43d0Ben Murdoch    uint64_t ArrayIndex;
601b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  };
611b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  struct NoLValuePath {};
621b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  struct UninitArray {};
631b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  struct UninitStruct {};
64014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochprivate:
65014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ValueKind Kind;
66014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
67014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  struct ComplexAPSInt {
68014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    APSInt Real, Imag;
691b268ca467c924004286c97bac133db489cf43d0Ben Murdoch    ComplexAPSInt() : Real(1), Imag(1) {}
70014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
71014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  struct ComplexAPFloat {
72014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    APFloat Real, Imag;
73014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ComplexAPFloat() : Real(0.0), Imag(0.0) {}
74014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
75014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  struct LV;
76014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  struct Vec {
77014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    APValue *Elts;
78014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    unsigned NumElts;
79014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Vec() : Elts(0), NumElts(0) {}
80014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ~Vec() { delete[] Elts; }
81014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
821b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  struct Arr {
83014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    APValue *Elts;
84014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    unsigned NumElts, ArrSize;
85014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Arr(unsigned NumElts, unsigned ArrSize);
86014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ~Arr();
87014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
88014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  struct StructData {
89014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    APValue *Elts;
90014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    unsigned NumBases;
911b268ca467c924004286c97bac133db489cf43d0Ben Murdoch    unsigned NumFields;
92014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StructData(unsigned NumBases, unsigned NumFields);
93014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ~StructData();
94014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
95014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  struct UnionData {
96014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    const FieldDecl *Field;
97014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    APValue *Value;
98014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    UnionData();
99014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ~UnionData();
100014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
101014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  struct MemberPointerData;
102014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
103014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  enum {
104014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MaxSize = (sizeof(ComplexAPSInt) > sizeof(ComplexAPFloat) ?
105014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch               sizeof(ComplexAPSInt) : sizeof(ComplexAPFloat))
106014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
107014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1081b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  union {
109014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    void *Aligner;
110014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    char Data[MaxSize];
111014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
112014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
113014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochpublic:
114014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  APValue() : Kind(Uninitialized) {}
115014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  explicit APValue(const APSInt &I) : Kind(Uninitialized) {
116014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MakeInt(); setInt(I);
117014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
1181b268ca467c924004286c97bac133db489cf43d0Ben Murdoch  explicit APValue(const APFloat &F) : Kind(Uninitialized) {
119014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MakeFloat(); setFloat(F);
120014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
121014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  explicit APValue(const APValue *E, unsigned N) : Kind(Uninitialized) {
122014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MakeVector(); setVector(E, N);
123014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
124014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  APValue(const APSInt &R, const APSInt &I) : Kind(Uninitialized) {
125014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MakeComplexInt(); setComplexInt(R, I);
126014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
127014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  APValue(const APFloat &R, const APFloat &I) : Kind(Uninitialized) {
128014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MakeComplexFloat(); setComplexFloat(R, I);
129014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
130014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  APValue(const APValue &RHS) : Kind(Uninitialized) {
131014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    *this = RHS;
132014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
133014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  APValue(LValueBase B, const CharUnits &O, NoLValuePath N)
134014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      : Kind(Uninitialized) {
135014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MakeLValue(); setLValue(B, O, N);
136014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
137014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  APValue(LValueBase B, const CharUnits &O, ArrayRef<LValuePathEntry> Path,
138014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch          bool OnePastTheEnd)
139014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      : Kind(Uninitialized) {
140014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    MakeLValue(); setLValue(B, O, Path, OnePastTheEnd);
141014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
142014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(Uninitialized) {
143    MakeArray(InitElts, Size);
144  }
145  APValue(UninitStruct, unsigned B, unsigned M) : Kind(Uninitialized) {
146    MakeStruct(B, M);
147  }
148  explicit APValue(const FieldDecl *D, const APValue &V = APValue())
149      : Kind(Uninitialized) {
150    MakeUnion(); setUnion(D, V);
151  }
152  APValue(const ValueDecl *Member, bool IsDerivedMember,
153          ArrayRef<const CXXRecordDecl*> Path) : Kind(Uninitialized) {
154    MakeMemberPointer(Member, IsDerivedMember, Path);
155  }
156
157  ~APValue() {
158    MakeUninit();
159  }
160
161  ValueKind getKind() const { return Kind; }
162  bool isUninit() const { return Kind == Uninitialized; }
163  bool isInt() const { return Kind == Int; }
164  bool isFloat() const { return Kind == Float; }
165  bool isComplexInt() const { return Kind == ComplexInt; }
166  bool isComplexFloat() const { return Kind == ComplexFloat; }
167  bool isLValue() const { return Kind == LValue; }
168  bool isVector() const { return Kind == Vector; }
169  bool isArray() const { return Kind == Array; }
170  bool isStruct() const { return Kind == Struct; }
171  bool isUnion() const { return Kind == Union; }
172  bool isMemberPointer() const { return Kind == MemberPointer; }
173
174  void print(raw_ostream &OS) const;
175  void dump() const;
176
177  APSInt &getInt() {
178    assert(isInt() && "Invalid accessor");
179    return *(APSInt*)(char*)Data;
180  }
181  const APSInt &getInt() const {
182    return const_cast<APValue*>(this)->getInt();
183  }
184
185  APFloat &getFloat() {
186    assert(isFloat() && "Invalid accessor");
187    return *(APFloat*)(char*)Data;
188  }
189  const APFloat &getFloat() const {
190    return const_cast<APValue*>(this)->getFloat();
191  }
192
193  APSInt &getComplexIntReal() {
194    assert(isComplexInt() && "Invalid accessor");
195    return ((ComplexAPSInt*)(char*)Data)->Real;
196  }
197  const APSInt &getComplexIntReal() const {
198    return const_cast<APValue*>(this)->getComplexIntReal();
199  }
200
201  APSInt &getComplexIntImag() {
202    assert(isComplexInt() && "Invalid accessor");
203    return ((ComplexAPSInt*)(char*)Data)->Imag;
204  }
205  const APSInt &getComplexIntImag() const {
206    return const_cast<APValue*>(this)->getComplexIntImag();
207  }
208
209  APFloat &getComplexFloatReal() {
210    assert(isComplexFloat() && "Invalid accessor");
211    return ((ComplexAPFloat*)(char*)Data)->Real;
212  }
213  const APFloat &getComplexFloatReal() const {
214    return const_cast<APValue*>(this)->getComplexFloatReal();
215  }
216
217  APFloat &getComplexFloatImag() {
218    assert(isComplexFloat() && "Invalid accessor");
219    return ((ComplexAPFloat*)(char*)Data)->Imag;
220  }
221  const APFloat &getComplexFloatImag() const {
222    return const_cast<APValue*>(this)->getComplexFloatImag();
223  }
224
225  const LValueBase getLValueBase() const;
226  CharUnits &getLValueOffset();
227  const CharUnits &getLValueOffset() const {
228    return const_cast<APValue*>(this)->getLValueOffset();
229  }
230  bool isLValueOnePastTheEnd() const;
231  bool hasLValuePath() const;
232  ArrayRef<LValuePathEntry> getLValuePath() const;
233
234  APValue &getVectorElt(unsigned I) {
235    assert(isVector() && "Invalid accessor");
236    assert(I < getVectorLength() && "Index out of range");
237    return ((Vec*)(char*)Data)->Elts[I];
238  }
239  const APValue &getVectorElt(unsigned I) const {
240    return const_cast<APValue*>(this)->getVectorElt(I);
241  }
242  unsigned getVectorLength() const {
243    assert(isVector() && "Invalid accessor");
244    return ((const Vec*)(const void *)Data)->NumElts;
245  }
246
247  APValue &getArrayInitializedElt(unsigned I) {
248    assert(isArray() && "Invalid accessor");
249    assert(I < getArrayInitializedElts() && "Index out of range");
250    return ((Arr*)(char*)Data)->Elts[I];
251  }
252  const APValue &getArrayInitializedElt(unsigned I) const {
253    return const_cast<APValue*>(this)->getArrayInitializedElt(I);
254  }
255  bool hasArrayFiller() const {
256    return getArrayInitializedElts() != getArraySize();
257  }
258  APValue &getArrayFiller() {
259    assert(isArray() && "Invalid accessor");
260    assert(hasArrayFiller() && "No array filler");
261    return ((Arr*)(char*)Data)->Elts[getArrayInitializedElts()];
262  }
263  const APValue &getArrayFiller() const {
264    return const_cast<APValue*>(this)->getArrayFiller();
265  }
266  unsigned getArrayInitializedElts() const {
267    assert(isArray() && "Invalid accessor");
268    return ((const Arr*)(const void *)Data)->NumElts;
269  }
270  unsigned getArraySize() const {
271    assert(isArray() && "Invalid accessor");
272    return ((const Arr*)(const void *)Data)->ArrSize;
273  }
274
275  unsigned getStructNumBases() const {
276    assert(isStruct() && "Invalid accessor");
277    return ((const StructData*)(const char*)Data)->NumBases;
278  }
279  unsigned getStructNumFields() const {
280    assert(isStruct() && "Invalid accessor");
281    return ((const StructData*)(const char*)Data)->NumFields;
282  }
283  APValue &getStructBase(unsigned i) {
284    assert(isStruct() && "Invalid accessor");
285    return ((StructData*)(char*)Data)->Elts[i];
286  }
287  APValue &getStructField(unsigned i) {
288    assert(isStruct() && "Invalid accessor");
289    return ((StructData*)(char*)Data)->Elts[getStructNumBases() + i];
290  }
291  const APValue &getStructBase(unsigned i) const {
292    return const_cast<APValue*>(this)->getStructBase(i);
293  }
294  const APValue &getStructField(unsigned i) const {
295    return const_cast<APValue*>(this)->getStructField(i);
296  }
297
298  const FieldDecl *getUnionField() const {
299    assert(isUnion() && "Invalid accessor");
300    return ((const UnionData*)(const char*)Data)->Field;
301  }
302  APValue &getUnionValue() {
303    assert(isUnion() && "Invalid accessor");
304    return *((UnionData*)(char*)Data)->Value;
305  }
306  const APValue &getUnionValue() const {
307    return const_cast<APValue*>(this)->getUnionValue();
308  }
309
310  const ValueDecl *getMemberPointerDecl() const;
311  bool isMemberPointerToDerivedMember() const;
312  ArrayRef<const CXXRecordDecl*> getMemberPointerPath() const;
313
314  void setInt(const APSInt &I) {
315    assert(isInt() && "Invalid accessor");
316    *(APSInt*)(char*)Data = I;
317  }
318  void setFloat(const APFloat &F) {
319    assert(isFloat() && "Invalid accessor");
320    *(APFloat*)(char*)Data = F;
321  }
322  void setVector(const APValue *E, unsigned N) {
323    assert(isVector() && "Invalid accessor");
324    ((Vec*)(char*)Data)->Elts = new APValue[N];
325    ((Vec*)(char*)Data)->NumElts = N;
326    for (unsigned i = 0; i != N; ++i)
327      ((Vec*)(char*)Data)->Elts[i] = E[i];
328  }
329  void setComplexInt(const APSInt &R, const APSInt &I) {
330    assert(R.getBitWidth() == I.getBitWidth() &&
331           "Invalid complex int (type mismatch).");
332    assert(isComplexInt() && "Invalid accessor");
333    ((ComplexAPSInt*)(char*)Data)->Real = R;
334    ((ComplexAPSInt*)(char*)Data)->Imag = I;
335  }
336  void setComplexFloat(const APFloat &R, const APFloat &I) {
337    assert(&R.getSemantics() == &I.getSemantics() &&
338           "Invalid complex float (type mismatch).");
339    assert(isComplexFloat() && "Invalid accessor");
340    ((ComplexAPFloat*)(char*)Data)->Real = R;
341    ((ComplexAPFloat*)(char*)Data)->Imag = I;
342  }
343  void setLValue(LValueBase B, const CharUnits &O, NoLValuePath);
344  void setLValue(LValueBase B, const CharUnits &O,
345                 ArrayRef<LValuePathEntry> Path, bool OnePastTheEnd);
346  void setUnion(const FieldDecl *Field, const APValue &Value) {
347    assert(isUnion() && "Invalid accessor");
348    ((UnionData*)(char*)Data)->Field = Field;
349    *((UnionData*)(char*)Data)->Value = Value;
350  }
351
352  const APValue &operator=(const APValue &RHS);
353
354private:
355  void MakeUninit();
356  void MakeInt() {
357    assert(isUninit() && "Bad state change");
358    new ((void*)Data) APSInt(1);
359    Kind = Int;
360  }
361  void MakeFloat() {
362    assert(isUninit() && "Bad state change");
363    new ((void*)(char*)Data) APFloat(0.0);
364    Kind = Float;
365  }
366  void MakeVector() {
367    assert(isUninit() && "Bad state change");
368    new ((void*)(char*)Data) Vec();
369    Kind = Vector;
370  }
371  void MakeComplexInt() {
372    assert(isUninit() && "Bad state change");
373    new ((void*)(char*)Data) ComplexAPSInt();
374    Kind = ComplexInt;
375  }
376  void MakeComplexFloat() {
377    assert(isUninit() && "Bad state change");
378    new ((void*)(char*)Data) ComplexAPFloat();
379    Kind = ComplexFloat;
380  }
381  void MakeLValue();
382  void MakeArray(unsigned InitElts, unsigned Size);
383  void MakeStruct(unsigned B, unsigned M) {
384    assert(isUninit() && "Bad state change");
385    new ((void*)(char*)Data) StructData(B, M);
386    Kind = Struct;
387  }
388  void MakeUnion() {
389    assert(isUninit() && "Bad state change");
390    new ((void*)(char*)Data) UnionData();
391    Kind = Union;
392  }
393  void MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
394                         ArrayRef<const CXXRecordDecl*> Path);
395};
396
397inline raw_ostream &operator<<(raw_ostream &OS, const APValue &V) {
398  V.print(OS);
399  return OS;
400}
401
402// Writes a concise representation of V to DB, in a single << operation.
403const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
404                                    const APValue &V);
405
406} // end namespace clang.
407
408#endif
409