Пример #1
0
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;
}
Пример #2
0
 Value::Value(clang::QualType clangTy, Interpreter& Interp):
   m_StorageType(determineStorageType(clangTy)),
   m_Type(clangTy.getAsOpaquePtr()),
   m_Interpreter(&Interp) {
   if (needsManagedAllocation())
     ManagedAllocate();
 }
Пример #3
0
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;
}
Пример #4
0
  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();
  }
Пример #5
0
 Value::~Value() {
   if (needsManagedAllocation())
     AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Release();
 }
Пример #6
0
Value::Value(const Value& other):
  m_Storage(other.m_Storage), m_Type(other.m_Type) {
  if (needsManagedAllocation())
    AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Retain();
}
Пример #7
0
Value::Value(clang::QualType clangTy, Interpreter* Interp):
  m_Type(clangTy.getAsOpaquePtr()) {
  if (needsManagedAllocation())
    ManagedAllocate(Interp);
}