Use proper indents.

This commit is contained in:
Vassil Vassilev 2014-05-21 16:55:19 +02:00 committed by sftnight
parent e1c16dec1b
commit b855d1111c

View File

@ -105,163 +105,162 @@ namespace {
namespace cling {
Value::Value(const Value& other):
m_Storage(other.m_Storage), m_Type(other.m_Type),
m_Interpreter(other.m_Interpreter) {
if (needsManagedAllocation())
AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Retain();
}
Value::Value(Value&& other):
m_Storage(other.m_Storage), m_Type(other.m_Type),
m_Interpreter(other.m_Interpreter) {
// Invalidate other so it will not release.
other.m_Type = 0;
}
Value::Value(clang::QualType clangTy, Interpreter& Interp):
m_Type(clangTy.getAsOpaquePtr()), m_Interpreter(&Interp) {
if (needsManagedAllocation())
ManagedAllocate();
}
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;
m_Interpreter = other.m_Interpreter;
if (needsManagedAllocation())
AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Retain();
return *this;
}
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;
m_Interpreter = other.m_Interpreter;
// Invalidate other so it will not release.
other.m_Type = 0;
return *this;
}
Value::~Value() {
if (needsManagedAllocation())
AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Release();
}
clang::QualType Value::getType() const {
return clang::QualType::getFromOpaquePtr(m_Type);
}
clang::ASTContext& Value::getASTContext() const {
return m_Interpreter->getCI()->getASTContext();
}
bool Value::isValid() const { return !getType().isNull(); }
bool Value::isVoid() const {
const clang::ASTContext& Ctx = getASTContext();
return isValid() && Ctx.hasSameType(getType(), Ctx.VoidTy);
}
unsigned long Value::GetNumberOfElements() const {
if (const clang::ConstantArrayType* ArrTy
= llvm::dyn_cast<clang::ConstantArrayType>(getType())) {
llvm::APInt arrSize(sizeof(unsigned long)*8, 1);
do {
arrSize *= ArrTy->getSize();
ArrTy = llvm::dyn_cast<clang::ConstantArrayType>(ArrTy->getElementType()
.getTypePtr());
} while (ArrTy);
return (unsigned long)arrSize.getZExtValue();
}
return 1;
}
Value::EStorageType Value::getStorageType() const {
const clang::Type* desugCanon = getType()->getUnqualifiedDesugaredType();
desugCanon = desugCanon->getCanonicalTypeUnqualified()->getTypePtr()
->getUnqualifiedDesugaredType();
if (desugCanon->isSignedIntegerOrEnumerationType())
return kSignedIntegerOrEnumerationType;
else if (desugCanon->isUnsignedIntegerOrEnumerationType())
return kUnsignedIntegerOrEnumerationType;
else if (desugCanon->isRealFloatingType()) {
const clang::BuiltinType* BT = desugCanon->getAs<clang::BuiltinType>();
if (BT->getKind() == clang::BuiltinType::Double)
return kDoubleType;
else if (BT->getKind() == clang::BuiltinType::Float)
return kFloatType;
else if (BT->getKind() == clang::BuiltinType::LongDouble)
return kLongDoubleType;
} else if (desugCanon->isPointerType() || desugCanon->isObjectType()
|| desugCanon->isReferenceType())
return kPointerType;
return kUnsupportedType;
}
bool Value::needsManagedAllocation() const {
if (!isValid()) return false;
const clang::Type* UnqDes = getType()->getUnqualifiedDesugaredType();
return UnqDes->isRecordType() || UnqDes->isConstantArrayType()
|| UnqDes->isMemberPointerType();
}
void Value::ManagedAllocate() {
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 = GetDtorWrapperPtr(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();
}
void Value::AssertOnUnsupportedTypeCast() const {
assert("unsupported type in Value, cannot cast simplistically!" && 0);
}
/// \brief Get the function address of the wrapper of the destructor.
void* Value::GetDtorWrapperPtr(const clang::RecordDecl* RD) const {
std::string funcname;
{
llvm::raw_string_ostream namestr(funcname);
namestr << "__cling_StoredValue_Destruct_" << RD;
Value::Value(const Value& other):
m_Storage(other.m_Storage), m_Type(other.m_Type),
m_Interpreter(other.m_Interpreter) {
if (needsManagedAllocation())
AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Retain();
}
std::string code("extern \"C\" void ");
{
clang::QualType RDQT(RD->getTypeForDecl(), 0);
std::string typeName
= utils::TypeName::GetFullyQualifiedName(RDQT, RD->getASTContext());
std::string dtorName = RD->getNameAsString();
code += funcname + "(void* obj){((" + typeName + "*)obj)->~"
+ dtorName + "();}";
Value::Value(Value&& other):
m_Storage(other.m_Storage), m_Type(other.m_Type),
m_Interpreter(other.m_Interpreter) {
// Invalidate other so it will not release.
other.m_Type = 0;
}
return m_Interpreter->compileFunction(funcname, code, true /*ifUniq*/,
false /*withAccessControl*/);
}
Value::Value(clang::QualType clangTy, Interpreter& Interp):
m_Type(clangTy.getAsOpaquePtr()), m_Interpreter(&Interp) {
if (needsManagedAllocation())
ManagedAllocate();
}
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;
m_Interpreter = other.m_Interpreter;
if (needsManagedAllocation())
AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Retain();
return *this;
}
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;
m_Interpreter = other.m_Interpreter;
// Invalidate other so it will not release.
other.m_Type = 0;
return *this;
}
Value::~Value() {
if (needsManagedAllocation())
AllocatedValue::getFromPayload(m_Storage.m_Ptr)->Release();
}
clang::QualType Value::getType() const {
return clang::QualType::getFromOpaquePtr(m_Type);
}
clang::ASTContext& Value::getASTContext() const {
return m_Interpreter->getCI()->getASTContext();
}
bool Value::isValid() const { return !getType().isNull(); }
bool Value::isVoid() const {
const clang::ASTContext& Ctx = getASTContext();
return isValid() && Ctx.hasSameType(getType(), Ctx.VoidTy);
}
unsigned long Value::GetNumberOfElements() const {
if (const clang::ConstantArrayType* ArrTy
= llvm::dyn_cast<clang::ConstantArrayType>(getType())) {
llvm::APInt arrSize(sizeof(unsigned long)*8, 1);
do {
arrSize *= ArrTy->getSize();
ArrTy = llvm::dyn_cast<clang::ConstantArrayType>(ArrTy->getElementType()
.getTypePtr());
} while (ArrTy);
return (unsigned long)arrSize.getZExtValue();
}
return 1;
}
Value::EStorageType Value::getStorageType() const {
const clang::Type* desugCanon = getType()->getUnqualifiedDesugaredType();
desugCanon = desugCanon->getCanonicalTypeUnqualified()->getTypePtr()
->getUnqualifiedDesugaredType();
if (desugCanon->isSignedIntegerOrEnumerationType())
return kSignedIntegerOrEnumerationType;
else if (desugCanon->isUnsignedIntegerOrEnumerationType())
return kUnsignedIntegerOrEnumerationType;
else if (desugCanon->isRealFloatingType()) {
const clang::BuiltinType* BT = desugCanon->getAs<clang::BuiltinType>();
if (BT->getKind() == clang::BuiltinType::Double)
return kDoubleType;
else if (BT->getKind() == clang::BuiltinType::Float)
return kFloatType;
else if (BT->getKind() == clang::BuiltinType::LongDouble)
return kLongDoubleType;
} else if (desugCanon->isPointerType() || desugCanon->isObjectType()
|| desugCanon->isReferenceType())
return kPointerType;
return kUnsupportedType;
}
bool Value::needsManagedAllocation() const {
if (!isValid()) return false;
const clang::Type* UnqDes = getType()->getUnqualifiedDesugaredType();
return UnqDes->isRecordType() || UnqDes->isConstantArrayType()
|| UnqDes->isMemberPointerType();
}
void Value::ManagedAllocate() {
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 = GetDtorWrapperPtr(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();
}
void Value::AssertOnUnsupportedTypeCast() const {
assert("unsupported type in Value, cannot cast simplistically!" && 0);
}
/// \brief Get the function address of the wrapper of the destructor.
void* Value::GetDtorWrapperPtr(const clang::RecordDecl* RD) const {
std::string funcname;
{
llvm::raw_string_ostream namestr(funcname);
namestr << "__cling_StoredValue_Destruct_" << RD;
}
std::string code("extern \"C\" void ");
{
clang::QualType RDQT(RD->getTypeForDecl(), 0);
std::string typeName
= utils::TypeName::GetFullyQualifiedName(RDQT, RD->getASTContext());
std::string dtorName = RD->getNameAsString();
code += funcname + "(void* obj){((" + typeName + "*)obj)->~"
+ dtorName + "();}";
}
return m_Interpreter->compileFunction(funcname, code, true /*ifUniq*/,
false /*withAccessControl*/);
}
static bool hasViableCandidateToCall(clang::LookupResult& R,
const cling::Value& V) {