clang API Documentation

APValue.cpp
Go to the documentation of this file.
00001 //===--- APValue.cpp - Union class for APFloat/APSInt/Complex -------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file implements the APValue class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "clang/AST/APValue.h"
00015 #include "clang/AST/ASTContext.h"
00016 #include "clang/AST/CharUnits.h"
00017 #include "clang/AST/DeclCXX.h"
00018 #include "clang/AST/Expr.h"
00019 #include "clang/AST/Type.h"
00020 #include "clang/Basic/Diagnostic.h"
00021 #include "llvm/ADT/SmallString.h"
00022 #include "llvm/Support/ErrorHandling.h"
00023 #include "llvm/Support/raw_ostream.h"
00024 using namespace clang;
00025 
00026 namespace {
00027   struct LVBase {
00028     llvm::PointerIntPair<APValue::LValueBase, 1, bool> BaseAndIsOnePastTheEnd;
00029     CharUnits Offset;
00030     unsigned PathLength;
00031     unsigned CallIndex;
00032   };
00033 }
00034 
00035 struct APValue::LV : LVBase {
00036   static const unsigned InlinePathSpace =
00037       (DataSize - sizeof(LVBase)) / sizeof(LValuePathEntry);
00038 
00039   /// Path - The sequence of base classes, fields and array indices to follow to
00040   /// walk from Base to the subobject. When performing GCC-style folding, there
00041   /// may not be such a path.
00042   union {
00043     LValuePathEntry Path[InlinePathSpace];
00044     LValuePathEntry *PathPtr;
00045   };
00046 
00047   LV() { PathLength = (unsigned)-1; }
00048   ~LV() { resizePath(0); }
00049 
00050   void resizePath(unsigned Length) {
00051     if (Length == PathLength)
00052       return;
00053     if (hasPathPtr())
00054       delete [] PathPtr;
00055     PathLength = Length;
00056     if (hasPathPtr())
00057       PathPtr = new LValuePathEntry[Length];
00058   }
00059 
00060   bool hasPath() const { return PathLength != (unsigned)-1; }
00061   bool hasPathPtr() const { return hasPath() && PathLength > InlinePathSpace; }
00062 
00063   LValuePathEntry *getPath() { return hasPathPtr() ? PathPtr : Path; }
00064   const LValuePathEntry *getPath() const {
00065     return hasPathPtr() ? PathPtr : Path;
00066   }
00067 };
00068 
00069 namespace {
00070   struct MemberPointerBase {
00071     llvm::PointerIntPair<const ValueDecl*, 1, bool> MemberAndIsDerivedMember;
00072     unsigned PathLength;
00073   };
00074 }
00075 
00076 struct APValue::MemberPointerData : MemberPointerBase {
00077   static const unsigned InlinePathSpace =
00078       (DataSize - sizeof(MemberPointerBase)) / sizeof(const CXXRecordDecl*);
00079   typedef const CXXRecordDecl *PathElem;
00080   union {
00081     PathElem Path[InlinePathSpace];
00082     PathElem *PathPtr;
00083   };
00084 
00085   MemberPointerData() { PathLength = 0; }
00086   ~MemberPointerData() { resizePath(0); }
00087 
00088   void resizePath(unsigned Length) {
00089     if (Length == PathLength)
00090       return;
00091     if (hasPathPtr())
00092       delete [] PathPtr;
00093     PathLength = Length;
00094     if (hasPathPtr())
00095       PathPtr = new PathElem[Length];
00096   }
00097 
00098   bool hasPathPtr() const { return PathLength > InlinePathSpace; }
00099 
00100   PathElem *getPath() { return hasPathPtr() ? PathPtr : Path; }
00101   const PathElem *getPath() const {
00102     return hasPathPtr() ? PathPtr : Path;
00103   }
00104 };
00105 
00106 // FIXME: Reduce the malloc traffic here.
00107 
00108 APValue::Arr::Arr(unsigned NumElts, unsigned Size) :
00109   Elts(new APValue[NumElts + (NumElts != Size ? 1 : 0)]),
00110   NumElts(NumElts), ArrSize(Size) {}
00111 APValue::Arr::~Arr() { delete [] Elts; }
00112 
00113 APValue::StructData::StructData(unsigned NumBases, unsigned NumFields) :
00114   Elts(new APValue[NumBases+NumFields]),
00115   NumBases(NumBases), NumFields(NumFields) {}
00116 APValue::StructData::~StructData() {
00117   delete [] Elts;
00118 }
00119 
00120 APValue::UnionData::UnionData() : Field(nullptr), Value(new APValue) {}
00121 APValue::UnionData::~UnionData () {
00122   delete Value;
00123 }
00124 
00125 APValue::APValue(const APValue &RHS) : Kind(Uninitialized) {
00126   switch (RHS.getKind()) {
00127   case Uninitialized:
00128     break;
00129   case Int:
00130     MakeInt();
00131     setInt(RHS.getInt());
00132     break;
00133   case Float:
00134     MakeFloat();
00135     setFloat(RHS.getFloat());
00136     break;
00137   case Vector:
00138     MakeVector();
00139     setVector(((const Vec *)(const char *)RHS.Data.buffer)->Elts,
00140               RHS.getVectorLength());
00141     break;
00142   case ComplexInt:
00143     MakeComplexInt();
00144     setComplexInt(RHS.getComplexIntReal(), RHS.getComplexIntImag());
00145     break;
00146   case ComplexFloat:
00147     MakeComplexFloat();
00148     setComplexFloat(RHS.getComplexFloatReal(), RHS.getComplexFloatImag());
00149     break;
00150   case LValue:
00151     MakeLValue();
00152     if (RHS.hasLValuePath())
00153       setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), RHS.getLValuePath(),
00154                 RHS.isLValueOnePastTheEnd(), RHS.getLValueCallIndex());
00155     else
00156       setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), NoLValuePath(),
00157                 RHS.getLValueCallIndex());
00158     break;
00159   case Array:
00160     MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize());
00161     for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; ++I)
00162       getArrayInitializedElt(I) = RHS.getArrayInitializedElt(I);
00163     if (RHS.hasArrayFiller())
00164       getArrayFiller() = RHS.getArrayFiller();
00165     break;
00166   case Struct:
00167     MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields());
00168     for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; ++I)
00169       getStructBase(I) = RHS.getStructBase(I);
00170     for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; ++I)
00171       getStructField(I) = RHS.getStructField(I);
00172     break;
00173   case Union:
00174     MakeUnion();
00175     setUnion(RHS.getUnionField(), RHS.getUnionValue());
00176     break;
00177   case MemberPointer:
00178     MakeMemberPointer(RHS.getMemberPointerDecl(),
00179                       RHS.isMemberPointerToDerivedMember(),
00180                       RHS.getMemberPointerPath());
00181     break;
00182   case AddrLabelDiff:
00183     MakeAddrLabelDiff();
00184     setAddrLabelDiff(RHS.getAddrLabelDiffLHS(), RHS.getAddrLabelDiffRHS());
00185     break;
00186   }
00187 }
00188 
00189 void APValue::DestroyDataAndMakeUninit() {
00190   if (Kind == Int)
00191     ((APSInt*)(char*)Data.buffer)->~APSInt();
00192   else if (Kind == Float)
00193     ((APFloat*)(char*)Data.buffer)->~APFloat();
00194   else if (Kind == Vector)
00195     ((Vec*)(char*)Data.buffer)->~Vec();
00196   else if (Kind == ComplexInt)
00197     ((ComplexAPSInt*)(char*)Data.buffer)->~ComplexAPSInt();
00198   else if (Kind == ComplexFloat)
00199     ((ComplexAPFloat*)(char*)Data.buffer)->~ComplexAPFloat();
00200   else if (Kind == LValue)
00201     ((LV*)(char*)Data.buffer)->~LV();
00202   else if (Kind == Array)
00203     ((Arr*)(char*)Data.buffer)->~Arr();
00204   else if (Kind == Struct)
00205     ((StructData*)(char*)Data.buffer)->~StructData();
00206   else if (Kind == Union)
00207     ((UnionData*)(char*)Data.buffer)->~UnionData();
00208   else if (Kind == MemberPointer)
00209     ((MemberPointerData*)(char*)Data.buffer)->~MemberPointerData();
00210   else if (Kind == AddrLabelDiff)
00211     ((AddrLabelDiffData*)(char*)Data.buffer)->~AddrLabelDiffData();
00212   Kind = Uninitialized;
00213 }
00214 
00215 bool APValue::needsCleanup() const {
00216   switch (getKind()) {
00217   case Uninitialized:
00218   case AddrLabelDiff:
00219     return false;
00220   case Struct:
00221   case Union:
00222   case Array:
00223   case Vector:
00224     return true;
00225   case Int:
00226     return getInt().needsCleanup();
00227   case Float:
00228     return getFloat().needsCleanup();
00229   case ComplexFloat:
00230     assert(getComplexFloatImag().needsCleanup() ==
00231                getComplexFloatReal().needsCleanup() &&
00232            "In _Complex float types, real and imaginary values always have the "
00233            "same size.");
00234     return getComplexFloatReal().needsCleanup();
00235   case ComplexInt:
00236     assert(getComplexIntImag().needsCleanup() ==
00237                getComplexIntReal().needsCleanup() &&
00238            "In _Complex int types, real and imaginary values must have the "
00239            "same size.");
00240     return getComplexIntReal().needsCleanup();
00241   case LValue:
00242     return reinterpret_cast<const LV *>(Data.buffer)->hasPathPtr();
00243   case MemberPointer:
00244     return reinterpret_cast<const MemberPointerData *>(Data.buffer)
00245         ->hasPathPtr();
00246   }
00247   llvm_unreachable("Unknown APValue kind!");
00248 }
00249 
00250 void APValue::swap(APValue &RHS) {
00251   std::swap(Kind, RHS.Kind);
00252   char TmpData[DataSize];
00253   memcpy(TmpData, Data.buffer, DataSize);
00254   memcpy(Data.buffer, RHS.Data.buffer, DataSize);
00255   memcpy(RHS.Data.buffer, TmpData, DataSize);
00256 }
00257 
00258 void APValue::dump() const {
00259   dump(llvm::errs());
00260   llvm::errs() << '\n';
00261 }
00262 
00263 static double GetApproxValue(const llvm::APFloat &F) {
00264   llvm::APFloat V = F;
00265   bool ignored;
00266   V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven,
00267             &ignored);
00268   return V.convertToDouble();
00269 }
00270 
00271 void APValue::dump(raw_ostream &OS) const {
00272   switch (getKind()) {
00273   case Uninitialized:
00274     OS << "Uninitialized";
00275     return;
00276   case Int:
00277     OS << "Int: " << getInt();
00278     return;
00279   case Float:
00280     OS << "Float: " << GetApproxValue(getFloat());
00281     return;
00282   case Vector:
00283     OS << "Vector: ";
00284     getVectorElt(0).dump(OS);
00285     for (unsigned i = 1; i != getVectorLength(); ++i) {
00286       OS << ", ";
00287       getVectorElt(i).dump(OS);
00288     }
00289     return;
00290   case ComplexInt:
00291     OS << "ComplexInt: " << getComplexIntReal() << ", " << getComplexIntImag();
00292     return;
00293   case ComplexFloat:
00294     OS << "ComplexFloat: " << GetApproxValue(getComplexFloatReal())
00295        << ", " << GetApproxValue(getComplexFloatImag());
00296     return;
00297   case LValue:
00298     OS << "LValue: <todo>";
00299     return;
00300   case Array:
00301     OS << "Array: ";
00302     for (unsigned I = 0, N = getArrayInitializedElts(); I != N; ++I) {
00303       getArrayInitializedElt(I).dump(OS);
00304       if (I != getArraySize() - 1) OS << ", ";
00305     }
00306     if (hasArrayFiller()) {
00307       OS << getArraySize() - getArrayInitializedElts() << " x ";
00308       getArrayFiller().dump(OS);
00309     }
00310     return;
00311   case Struct:
00312     OS << "Struct ";
00313     if (unsigned N = getStructNumBases()) {
00314       OS << " bases: ";
00315       getStructBase(0).dump(OS);
00316       for (unsigned I = 1; I != N; ++I) {
00317         OS << ", ";
00318         getStructBase(I).dump(OS);
00319       }
00320     }
00321     if (unsigned N = getStructNumFields()) {
00322       OS << " fields: ";
00323       getStructField(0).dump(OS);
00324       for (unsigned I = 1; I != N; ++I) {
00325         OS << ", ";
00326         getStructField(I).dump(OS);
00327       }
00328     }
00329     return;
00330   case Union:
00331     OS << "Union: ";
00332     getUnionValue().dump(OS);
00333     return;
00334   case MemberPointer:
00335     OS << "MemberPointer: <todo>";
00336     return;
00337   case AddrLabelDiff:
00338     OS << "AddrLabelDiff: <todo>";
00339     return;
00340   }
00341   llvm_unreachable("Unknown APValue kind!");
00342 }
00343 
00344 void APValue::printPretty(raw_ostream &Out, ASTContext &Ctx, QualType Ty) const{
00345   switch (getKind()) {
00346   case APValue::Uninitialized:
00347     Out << "<uninitialized>";
00348     return;
00349   case APValue::Int:
00350     if (Ty->isBooleanType())
00351       Out << (getInt().getBoolValue() ? "true" : "false");
00352     else
00353       Out << getInt();
00354     return;
00355   case APValue::Float:
00356     Out << GetApproxValue(getFloat());
00357     return;
00358   case APValue::Vector: {
00359     Out << '{';
00360     QualType ElemTy = Ty->getAs<VectorType>()->getElementType();
00361     getVectorElt(0).printPretty(Out, Ctx, ElemTy);
00362     for (unsigned i = 1; i != getVectorLength(); ++i) {
00363       Out << ", ";
00364       getVectorElt(i).printPretty(Out, Ctx, ElemTy);
00365     }
00366     Out << '}';
00367     return;
00368   }
00369   case APValue::ComplexInt:
00370     Out << getComplexIntReal() << "+" << getComplexIntImag() << "i";
00371     return;
00372   case APValue::ComplexFloat:
00373     Out << GetApproxValue(getComplexFloatReal()) << "+"
00374         << GetApproxValue(getComplexFloatImag()) << "i";
00375     return;
00376   case APValue::LValue: {
00377     LValueBase Base = getLValueBase();
00378     if (!Base) {
00379       Out << "0";
00380       return;
00381     }
00382 
00383     bool IsReference = Ty->isReferenceType();
00384     QualType InnerTy
00385       = IsReference ? Ty.getNonReferenceType() : Ty->getPointeeType();
00386     if (InnerTy.isNull())
00387       InnerTy = Ty;
00388 
00389     if (!hasLValuePath()) {
00390       // No lvalue path: just print the offset.
00391       CharUnits O = getLValueOffset();
00392       CharUnits S = Ctx.getTypeSizeInChars(InnerTy);
00393       if (!O.isZero()) {
00394         if (IsReference)
00395           Out << "*(";
00396         if (O % S) {
00397           Out << "(char*)";
00398           S = CharUnits::One();
00399         }
00400         Out << '&';
00401       } else if (!IsReference)
00402         Out << '&';
00403 
00404       if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>())
00405         Out << *VD;
00406       else {
00407         assert(Base.get<const Expr *>() != nullptr &&
00408                "Expecting non-null Expr");
00409         Base.get<const Expr*>()->printPretty(Out, nullptr,
00410                                              Ctx.getPrintingPolicy());
00411       }
00412 
00413       if (!O.isZero()) {
00414         Out << " + " << (O / S);
00415         if (IsReference)
00416           Out << ')';
00417       }
00418       return;
00419     }
00420 
00421     // We have an lvalue path. Print it out nicely.
00422     if (!IsReference)
00423       Out << '&';
00424     else if (isLValueOnePastTheEnd())
00425       Out << "*(&";
00426 
00427     QualType ElemTy;
00428     if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
00429       Out << *VD;
00430       ElemTy = VD->getType();
00431     } else {
00432       const Expr *E = Base.get<const Expr*>();
00433       assert(E != nullptr && "Expecting non-null Expr");
00434       E->printPretty(Out, nullptr, Ctx.getPrintingPolicy());
00435       ElemTy = E->getType();
00436     }
00437 
00438     ArrayRef<LValuePathEntry> Path = getLValuePath();
00439     const CXXRecordDecl *CastToBase = nullptr;
00440     for (unsigned I = 0, N = Path.size(); I != N; ++I) {
00441       if (ElemTy->getAs<RecordType>()) {
00442         // The lvalue refers to a class type, so the next path entry is a base
00443         // or member.
00444         const Decl *BaseOrMember =
00445         BaseOrMemberType::getFromOpaqueValue(Path[I].BaseOrMember).getPointer();
00446         if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(BaseOrMember)) {
00447           CastToBase = RD;
00448           ElemTy = Ctx.getRecordType(RD);
00449         } else {
00450           const ValueDecl *VD = cast<ValueDecl>(BaseOrMember);
00451           Out << ".";
00452           if (CastToBase)
00453             Out << *CastToBase << "::";
00454           Out << *VD;
00455           ElemTy = VD->getType();
00456         }
00457       } else {
00458         // The lvalue must refer to an array.
00459         Out << '[' << Path[I].ArrayIndex << ']';
00460         ElemTy = Ctx.getAsArrayType(ElemTy)->getElementType();
00461       }
00462     }
00463 
00464     // Handle formatting of one-past-the-end lvalues.
00465     if (isLValueOnePastTheEnd()) {
00466       // FIXME: If CastToBase is non-0, we should prefix the output with
00467       // "(CastToBase*)".
00468       Out << " + 1";
00469       if (IsReference)
00470         Out << ')';
00471     }
00472     return;
00473   }
00474   case APValue::Array: {
00475     const ArrayType *AT = Ctx.getAsArrayType(Ty);
00476     QualType ElemTy = AT->getElementType();
00477     Out << '{';
00478     if (unsigned N = getArrayInitializedElts()) {
00479       getArrayInitializedElt(0).printPretty(Out, Ctx, ElemTy);
00480       for (unsigned I = 1; I != N; ++I) {
00481         Out << ", ";
00482         if (I == 10) {
00483           // Avoid printing out the entire contents of large arrays.
00484           Out << "...";
00485           break;
00486         }
00487         getArrayInitializedElt(I).printPretty(Out, Ctx, ElemTy);
00488       }
00489     }
00490     Out << '}';
00491     return;
00492   }
00493   case APValue::Struct: {
00494     Out << '{';
00495     const RecordDecl *RD = Ty->getAs<RecordType>()->getDecl();
00496     bool First = true;
00497     if (unsigned N = getStructNumBases()) {
00498       const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
00499       CXXRecordDecl::base_class_const_iterator BI = CD->bases_begin();
00500       for (unsigned I = 0; I != N; ++I, ++BI) {
00501         assert(BI != CD->bases_end());
00502         if (!First)
00503           Out << ", ";
00504         getStructBase(I).printPretty(Out, Ctx, BI->getType());
00505         First = false;
00506       }
00507     }
00508     for (const auto *FI : RD->fields()) {
00509       if (!First)
00510         Out << ", ";
00511       if (FI->isUnnamedBitfield()) continue;
00512       getStructField(FI->getFieldIndex()).
00513         printPretty(Out, Ctx, FI->getType());
00514       First = false;
00515     }
00516     Out << '}';
00517     return;
00518   }
00519   case APValue::Union:
00520     Out << '{';
00521     if (const FieldDecl *FD = getUnionField()) {
00522       Out << "." << *FD << " = ";
00523       getUnionValue().printPretty(Out, Ctx, FD->getType());
00524     }
00525     Out << '}';
00526     return;
00527   case APValue::MemberPointer:
00528     // FIXME: This is not enough to unambiguously identify the member in a
00529     // multiple-inheritance scenario.
00530     if (const ValueDecl *VD = getMemberPointerDecl()) {
00531       Out << '&' << *cast<CXXRecordDecl>(VD->getDeclContext()) << "::" << *VD;
00532       return;
00533     }
00534     Out << "0";
00535     return;
00536   case APValue::AddrLabelDiff:
00537     Out << "&&" << getAddrLabelDiffLHS()->getLabel()->getName();
00538     Out << " - ";
00539     Out << "&&" << getAddrLabelDiffRHS()->getLabel()->getName();
00540     return;
00541   }
00542   llvm_unreachable("Unknown APValue kind!");
00543 }
00544 
00545 std::string APValue::getAsString(ASTContext &Ctx, QualType Ty) const {
00546   std::string Result;
00547   llvm::raw_string_ostream Out(Result);
00548   printPretty(Out, Ctx, Ty);
00549   Out.flush();
00550   return Result;
00551 }
00552 
00553 const APValue::LValueBase APValue::getLValueBase() const {
00554   assert(isLValue() && "Invalid accessor");
00555   return ((const LV*)(const void*)Data.buffer)->BaseAndIsOnePastTheEnd.getPointer();
00556 }
00557 
00558 bool APValue::isLValueOnePastTheEnd() const {
00559   assert(isLValue() && "Invalid accessor");
00560   return ((const LV*)(const void*)Data.buffer)->BaseAndIsOnePastTheEnd.getInt();
00561 }
00562 
00563 CharUnits &APValue::getLValueOffset() {
00564   assert(isLValue() && "Invalid accessor");
00565   return ((LV*)(void*)Data.buffer)->Offset;
00566 }
00567 
00568 bool APValue::hasLValuePath() const {
00569   assert(isLValue() && "Invalid accessor");
00570   return ((const LV*)(const char*)Data.buffer)->hasPath();
00571 }
00572 
00573 ArrayRef<APValue::LValuePathEntry> APValue::getLValuePath() const {
00574   assert(isLValue() && hasLValuePath() && "Invalid accessor");
00575   const LV &LVal = *((const LV*)(const char*)Data.buffer);
00576   return llvm::makeArrayRef(LVal.getPath(), LVal.PathLength);
00577 }
00578 
00579 unsigned APValue::getLValueCallIndex() const {
00580   assert(isLValue() && "Invalid accessor");
00581   return ((const LV*)(const char*)Data.buffer)->CallIndex;
00582 }
00583 
00584 void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
00585                         unsigned CallIndex) {
00586   assert(isLValue() && "Invalid accessor");
00587   LV &LVal = *((LV*)(char*)Data.buffer);
00588   LVal.BaseAndIsOnePastTheEnd.setPointer(B);
00589   LVal.BaseAndIsOnePastTheEnd.setInt(false);
00590   LVal.Offset = O;
00591   LVal.CallIndex = CallIndex;
00592   LVal.resizePath((unsigned)-1);
00593 }
00594 
00595 void APValue::setLValue(LValueBase B, const CharUnits &O,
00596                         ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
00597                         unsigned CallIndex) {
00598   assert(isLValue() && "Invalid accessor");
00599   LV &LVal = *((LV*)(char*)Data.buffer);
00600   LVal.BaseAndIsOnePastTheEnd.setPointer(B);
00601   LVal.BaseAndIsOnePastTheEnd.setInt(IsOnePastTheEnd);
00602   LVal.Offset = O;
00603   LVal.CallIndex = CallIndex;
00604   LVal.resizePath(Path.size());
00605   memcpy(LVal.getPath(), Path.data(), Path.size() * sizeof(LValuePathEntry));
00606 }
00607 
00608 const ValueDecl *APValue::getMemberPointerDecl() const {
00609   assert(isMemberPointer() && "Invalid accessor");
00610   const MemberPointerData &MPD =
00611       *((const MemberPointerData *)(const char *)Data.buffer);
00612   return MPD.MemberAndIsDerivedMember.getPointer();
00613 }
00614 
00615 bool APValue::isMemberPointerToDerivedMember() const {
00616   assert(isMemberPointer() && "Invalid accessor");
00617   const MemberPointerData &MPD =
00618       *((const MemberPointerData *)(const char *)Data.buffer);
00619   return MPD.MemberAndIsDerivedMember.getInt();
00620 }
00621 
00622 ArrayRef<const CXXRecordDecl*> APValue::getMemberPointerPath() const {
00623   assert(isMemberPointer() && "Invalid accessor");
00624   const MemberPointerData &MPD =
00625       *((const MemberPointerData *)(const char *)Data.buffer);
00626   return llvm::makeArrayRef(MPD.getPath(), MPD.PathLength);
00627 }
00628 
00629 void APValue::MakeLValue() {
00630   assert(isUninit() && "Bad state change");
00631   static_assert(sizeof(LV) <= DataSize, "LV too big");
00632   new ((void*)(char*)Data.buffer) LV();
00633   Kind = LValue;
00634 }
00635 
00636 void APValue::MakeArray(unsigned InitElts, unsigned Size) {
00637   assert(isUninit() && "Bad state change");
00638   new ((void*)(char*)Data.buffer) Arr(InitElts, Size);
00639   Kind = Array;
00640 }
00641 
00642 void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
00643                                 ArrayRef<const CXXRecordDecl*> Path) {
00644   assert(isUninit() && "Bad state change");
00645   MemberPointerData *MPD = new ((void*)(char*)Data.buffer) MemberPointerData;
00646   Kind = MemberPointer;
00647   MPD->MemberAndIsDerivedMember.setPointer(Member);
00648   MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
00649   MPD->resizePath(Path.size());
00650   memcpy(MPD->getPath(), Path.data(), Path.size()*sizeof(const CXXRecordDecl*));
00651 }