mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Prefer C++-style casts.
This is based on Item 2 of "More Effective C++". In general, the C++ cast operators are more expressive and easy to find, e.g. by grep. Using const_cast also shuts up some compiler warnings.
This commit is contained in:
@@ -154,7 +154,7 @@ LLConstant * IrStruct::getVtblInit()
|
||||
size_t n = cd->vtbl.dim;
|
||||
for (size_t i = 1; i < n; i++)
|
||||
{
|
||||
Dsymbol* dsym = (Dsymbol*)cd->vtbl.data[i];
|
||||
Dsymbol* dsym = static_cast<Dsymbol*>(cd->vtbl.data[i]);
|
||||
assert(dsym && "null vtbl member");
|
||||
|
||||
FuncDeclaration* fd = dsym->isFuncDeclaration();
|
||||
@@ -178,14 +178,14 @@ LLConstant * IrStruct::getVtblInit()
|
||||
for (size_t j = 1; j < n; j++)
|
||||
{ if (j == i)
|
||||
continue;
|
||||
FuncDeclaration *fd2 = ((Dsymbol *)cd->vtbl.data[j])->isFuncDeclaration();
|
||||
FuncDeclaration *fd2 = static_cast<Dsymbol *>(cd->vtbl.data[j])->isFuncDeclaration();
|
||||
if (!fd2->ident->equals(fd->ident))
|
||||
continue;
|
||||
if (fd->leastAsSpecialized(fd2) || fd2->leastAsSpecialized(fd))
|
||||
{
|
||||
if (global.params.warnings)
|
||||
{
|
||||
TypeFunction *tf = (TypeFunction *)fd->type;
|
||||
TypeFunction *tf = static_cast<TypeFunction *>(fd->type);
|
||||
if (tf->ty == Tfunction)
|
||||
error("%s%s is hidden by %s\n", fd->toPrettyChars(), Parameter::argsTypesToChars(tf->parameters, tf->varargs), toChars());
|
||||
else
|
||||
@@ -385,7 +385,7 @@ llvm::GlobalVariable * IrStruct::getInterfaceVtbl(BaseClass * b, bool new_instan
|
||||
size_t n = vtbl_array.dim;
|
||||
for (size_t i = 1; i < n; i++)
|
||||
{
|
||||
Dsymbol* dsym = (Dsymbol*)vtbl_array.data[i];
|
||||
Dsymbol* dsym = static_cast<Dsymbol*>(vtbl_array.data[i]);
|
||||
if (dsym == NULL)
|
||||
{
|
||||
// FIXME
|
||||
|
||||
@@ -64,7 +64,7 @@ bool IrDsymbol::isSet()
|
||||
IrVar* IrDsymbol::getIrVar()
|
||||
{
|
||||
assert(irGlobal || irLocal || irField);
|
||||
return irGlobal ? (IrVar*)irGlobal : irLocal ? (IrVar*)irLocal : (IrVar*)irField;
|
||||
return irGlobal ? static_cast<IrVar*>(irGlobal) : irLocal ? static_cast<IrVar*>(irLocal) : static_cast<IrVar*>(irField);
|
||||
}
|
||||
|
||||
llvm::Value*& IrDsymbol::getIrValue() { return getIrVar()->value; }
|
||||
|
||||
@@ -129,7 +129,7 @@ IrFunction::IrFunction(FuncDeclaration* fd)
|
||||
|
||||
Type* t = fd->type->toBasetype();
|
||||
assert(t->ty == Tfunction);
|
||||
type = (TypeFunction*)t;
|
||||
type = static_cast<TypeFunction*>(t);
|
||||
func = NULL;
|
||||
allocapoint = NULL;
|
||||
|
||||
|
||||
@@ -251,8 +251,8 @@ LLConstant * IrStruct::createStructInitializer(StructInitializer * si)
|
||||
n = si->vars.dim;
|
||||
for (size_t i = 0; i < n; i++)
|
||||
{
|
||||
VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
|
||||
Initializer* ini = (Initializer*)si->value.data[i];
|
||||
VarDeclaration* vd = static_cast<VarDeclaration*>(si->vars.data[i]);
|
||||
Initializer* ini = static_cast<Initializer*>(si->value.data[i]);
|
||||
Loc loc = ini ? ini->loc : si->loc;
|
||||
|
||||
size_t idx = datamap[i];
|
||||
@@ -297,7 +297,7 @@ LLConstant * IrStruct::createStructInitializer(StructInitializer * si)
|
||||
if (vd)
|
||||
continue;
|
||||
|
||||
vd = (VarDeclaration*)aggrdecl->fields.data[i];
|
||||
vd = static_cast<VarDeclaration*>(aggrdecl->fields.data[i]);
|
||||
|
||||
unsigned vd_begin = vd->offset;
|
||||
unsigned vd_end = vd_begin + vd->type->size();
|
||||
|
||||
@@ -188,8 +188,8 @@ llvm::Type * IrTypeSArray::buildType()
|
||||
llvm::Type * IrTypeSArray::sarray2llvm(Type * t)
|
||||
{
|
||||
assert(t->ty == Tsarray && "not static array type");
|
||||
TypeSArray* tsa = (TypeSArray*)t;
|
||||
dim = (uint64_t)tsa->dim->toUInteger();
|
||||
TypeSArray* tsa = static_cast<TypeSArray*>(t);
|
||||
dim = static_cast<uint64_t>(tsa->dim->toUInteger());
|
||||
LLType* elemType = DtoType(t->nextOf());
|
||||
if (elemType == llvm::Type::getVoidTy(llvm::getGlobalContext()))
|
||||
elemType = llvm::Type::getInt8Ty(llvm::getGlobalContext());
|
||||
@@ -256,10 +256,10 @@ llvm::Type* IrTypeVector::buildType()
|
||||
llvm::Type* IrTypeVector::vector2llvm(Type* dt)
|
||||
{
|
||||
assert(dt->ty == Tvector && "not vector type");
|
||||
TypeVector* tv = (TypeVector*)dt;
|
||||
TypeVector* tv = static_cast<TypeVector*>(dt);
|
||||
assert(tv->basetype->ty == Tsarray);
|
||||
TypeSArray* tsa = (TypeSArray*)tv->basetype;
|
||||
dim = (uint64_t)tsa->dim->toUInteger();
|
||||
TypeSArray* tsa = static_cast<TypeSArray*>(tv->basetype);
|
||||
dim = static_cast<uint64_t>(tsa->dim->toUInteger());
|
||||
LLType* elemType = DtoType(tsa->next);
|
||||
if (elemType == llvm::Type::getVoidTy(llvm::getGlobalContext()))
|
||||
elemType = llvm::Type::getInt8Ty(llvm::getGlobalContext());
|
||||
|
||||
@@ -22,7 +22,7 @@ extern bool var_offset_sort_cb(const VarDeclaration* v1, const VarDeclaration* v
|
||||
IrTypeClass::IrTypeClass(ClassDeclaration* cd)
|
||||
: IrTypeAggr(cd),
|
||||
cd(cd),
|
||||
tc((TypeClass*)cd->type)
|
||||
tc(static_cast<TypeClass*>(cd->type))
|
||||
{
|
||||
std::string vtbl_name(cd->toPrettyChars());
|
||||
vtbl_name.append(".__vtbl");
|
||||
@@ -161,7 +161,7 @@ void IrTypeClass::addBaseClassData(
|
||||
offset = vd->offset + vd->type->size();
|
||||
|
||||
// create ir field
|
||||
vd->aggrIndex = (unsigned)field_index;
|
||||
vd->aggrIndex = static_cast<unsigned>(field_index);
|
||||
++field_index;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ llvm::Type * IrTypeFunction::buildType()
|
||||
llvm::Type* IrTypeFunction::func2llvm(Type* dt)
|
||||
{
|
||||
llvm::Type* T;
|
||||
TypeFunction* tf = (TypeFunction*)dt;
|
||||
TypeFunction* tf = static_cast<TypeFunction*>(dt);
|
||||
if (tf->funcdecl)
|
||||
T = DtoFunctionType(tf->funcdecl);
|
||||
else
|
||||
|
||||
@@ -29,7 +29,7 @@ IrTypeAggr::IrTypeAggr(AggregateDeclaration * ad)
|
||||
IrTypeStruct::IrTypeStruct(StructDeclaration * sd)
|
||||
: IrTypeAggr(sd),
|
||||
sd(sd),
|
||||
ts((TypeStruct*)sd->type)
|
||||
ts(static_cast<TypeStruct*>(sd->type))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user