Value& Value::operator =(const Value& other) { // Release old value. if (needsManagedAllocation()) AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Release(); // Retain new one. m_Type = other.m_Type; m_Storage = other.m_Storage; if (needsManagedAllocation()) AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Retain(); return *this; }
Value::Value(clang::QualType clangTy, Interpreter& Interp): m_StorageType(determineStorageType(clangTy)), m_Type(clangTy.getAsOpaquePtr()), m_Interpreter(&Interp) { if (needsManagedAllocation()) ManagedAllocate(); }
Value& Value::operator =(Value&& other) { // Release old value. if (needsManagedAllocation()) AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Release(); // Move new one. m_Type = other.m_Type; m_Storage = other.m_Storage; // Invalidate other so it will not release. other.m_Type = 0; return *this; }
void Value::ManagedAllocate() { assert(needsManagedAllocation() && "Does not need managed allocation"); void* dtorFunc = 0; clang::QualType DtorType = getType(); // For arrays we destruct the elements. if (const clang::ConstantArrayType* ArrTy = llvm::dyn_cast<clang::ConstantArrayType>(DtorType.getTypePtr())) { DtorType = ArrTy->getElementType(); } if (const clang::RecordType* RTy = DtorType->getAs<clang::RecordType>()) dtorFunc = m_Interpreter->compileDtorCallFor(RTy->getDecl()); const clang::ASTContext& ctx = getASTContext(); unsigned payloadSize = ctx.getTypeSizeInChars(getType()).getQuantity(); char* alloc = new char[AllocatedValue::getPayloadOffset() + payloadSize]; AllocatedValue* allocVal = new (alloc) AllocatedValue(dtorFunc, payloadSize, GetNumberOfElements()); m_Storage.m_Ptr = allocVal->getPayload(); }
Value::~Value() { if (needsManagedAllocation()) AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Release(); }
Value::Value(const Value& other): m_Storage(other.m_Storage), m_Type(other.m_Type) { if (needsManagedAllocation()) AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Retain(); }
Value::Value(clang::QualType clangTy, Interpreter* Interp): m_Type(clangTy.getAsOpaquePtr()) { if (needsManagedAllocation()) ManagedAllocate(Interp); }