Get rid of more superfluous casts with DMD arrays.

There are still a few more left.
This commit is contained in:
David Nadlinger 2014-11-16 08:00:17 +01:00
parent b8aed4538a
commit e4aa92deb3
6 changed files with 41 additions and 49 deletions

View file

@ -509,7 +509,7 @@ void AsmBlockStatement_toIR(AsmBlockStatement *stmt, IRState* p)
// do asm statements // do asm statements
for (unsigned i=0; i < stmt->statements->dim; i++) for (unsigned i=0; i < stmt->statements->dim; i++)
{ {
Statement* s = static_cast<Statement*>(stmt->statements->data[i]); Statement* s = (*stmt->statements)[i];
if (s) { if (s) {
Statement_toIR(s, p); Statement_toIR(s, p);
} }
@ -780,7 +780,7 @@ Statement *AsmBlockStatement::syntaxCopy()
a->setDim(statements->dim); a->setDim(statements->dim);
for (size_t i = 0; i < statements->dim; i++) for (size_t i = 0; i < statements->dim; i++)
{ {
Statement *s = static_cast<Statement *>(statements->data[i]); Statement *s = (*statements)[i];
if (s) if (s)
s = s->syntaxCopy(); s = s->syntaxCopy();
a->data[i] = s; a->data[i] = s;
@ -811,7 +811,7 @@ AsmBlockStatement* CompoundStatement::endsWithAsm()
if (statements && statements->dim) if (statements && statements->dim)
{ {
unsigned last = statements->dim - 1; unsigned last = statements->dim - 1;
Statement* s = static_cast<Statement*>(statements->data[last]); Statement* s = (*statements)[last];
if (s) return s->endsWithAsm(); if (s) return s->endsWithAsm();
} }
return NULL; return NULL;

View file

@ -562,7 +562,7 @@ static void codegenModule(Module* m)
// process module members // process module members
for (unsigned k=0; k < m->members->dim; k++) { for (unsigned k=0; k < m->members->dim; k++) {
Dsymbol* dsym = static_cast<Dsymbol*>(m->members->data[k]); Dsymbol* dsym = (*m->members)[k];
assert(dsym); assert(dsym);
Declaration_codegen(dsym); Declaration_codegen(dsym);
} }
@ -755,11 +755,7 @@ void Module::genmoduleinfo()
//printf("members->dim = %d\n", members->dim); //printf("members->dim = %d\n", members->dim);
for (size_t i = 0; i < members->dim; i++) for (size_t i = 0; i < members->dim; i++)
{ {
Dsymbol *member; (*members)[i]->addLocalClass(&aclasses);
member = static_cast<Dsymbol *>(members->data[i]);
//printf("\tmember '%s'\n", member->toChars());
member->addLocalClass(&aclasses);
} }
// fill inits // fill inits
std::vector<LLConstant*> classInits; std::vector<LLConstant*> classInits;

View file

@ -433,7 +433,7 @@ DValue * DtoInlineAsmExpr(Loc& loc, FuncDeclaration * fd, Expressions * argument
assert(arguments->dim >= 2 && "invalid __asm call"); assert(arguments->dim >= 2 && "invalid __asm call");
// get code param // get code param
Expression* e = static_cast<Expression*>(arguments->data[0]); Expression* e = (*arguments)[0];
IF_LOG Logger::println("code exp: %s", e->toChars()); IF_LOG Logger::println("code exp: %s", e->toChars());
StringExp* se = static_cast<StringExp*>(e); StringExp* se = static_cast<StringExp*>(e);
if (e->op != TOKstring || se->sz != 1) if (e->op != TOKstring || se->sz != 1)
@ -444,7 +444,7 @@ DValue * DtoInlineAsmExpr(Loc& loc, FuncDeclaration * fd, Expressions * argument
std::string code(static_cast<char*>(se->string), se->len); std::string code(static_cast<char*>(se->string), se->len);
// get constraints param // get constraints param
e = static_cast<Expression*>(arguments->data[1]); e = (*arguments)[1];
IF_LOG Logger::println("constraint exp: %s", e->toChars()); IF_LOG Logger::println("constraint exp: %s", e->toChars());
se = static_cast<StringExp*>(e); se = static_cast<StringExp*>(e);
if (e->op != TOKstring || se->sz != 1) if (e->op != TOKstring || se->sz != 1)
@ -464,8 +464,7 @@ DValue * DtoInlineAsmExpr(Loc& loc, FuncDeclaration * fd, Expressions * argument
for (size_t i = 2; i < n; i++) for (size_t i = 2; i < n; i++)
{ {
e = static_cast<Expression*>(arguments->data[i]); args.push_back(toElem((*arguments)[i])->getRVal());
args.push_back(toElem(e)->getRVal());
argtypes.push_back(args.back()->getType()); argtypes.push_back(args.back()->getType());
} }

View file

@ -227,7 +227,7 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args,
// build struct with argument types (non variadic args) // build struct with argument types (non variadic args)
for (size_t i=begin; i<n_arguments; i++) for (size_t i=begin; i<n_arguments; i++)
{ {
Expression* argexp = static_cast<Expression*>(arguments->data[i]); Expression* argexp = (*arguments)[i];
assert(argexp->type->ty != Ttuple); assert(argexp->type->ty != Ttuple);
vtypes.push_back(DtoType(argexp->type)); vtypes.push_back(DtoType(argexp->type));
size_t sz = getTypePaddedSize(vtypes.back()); size_t sz = getTypePaddedSize(vtypes.back());
@ -263,7 +263,7 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args,
// store arguments in the struct // store arguments in the struct
for (size_t i=begin,k=0; i<n_arguments; i++,k++) for (size_t i=begin,k=0; i<n_arguments; i++,k++)
{ {
Expression* argexp = static_cast<Expression*>(arguments->data[i]); Expression* argexp = (*arguments)[i];
LLValue* argdst = DtoGEPi(mem,0,k); LLValue* argdst = DtoGEPi(mem,0,k);
argdst = DtoBitCast(argdst, getPtrToType(i1ToI8(DtoType(argexp->type)))); argdst = DtoBitCast(argdst, getPtrToType(i1ToI8(DtoType(argexp->type))));
DtoVariadicArgument(argexp, argdst); DtoVariadicArgument(argexp, argdst);
@ -281,8 +281,7 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args,
vtypeinfos.reserve(n_arguments); vtypeinfos.reserve(n_arguments);
for (size_t i=begin; i<n_arguments; i++) for (size_t i=begin; i<n_arguments; i++)
{ {
Expression* argexp = static_cast<Expression*>(arguments->data[i]); vtypeinfos.push_back(DtoTypeInfoOf((*arguments)[i]->type));
vtypeinfos.push_back(DtoTypeInfoOf(argexp->type));
} }
// apply initializer // apply initializer
@ -315,7 +314,7 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args,
for (int i=0; i<begin; i++) for (int i=0; i<begin; i++)
{ {
Parameter* fnarg = Parameter::getNth(tf->parameters, i); Parameter* fnarg = Parameter::getNth(tf->parameters, i);
DValue* argval = DtoArgument(fnarg, static_cast<Expression*>(arguments->data[i])); DValue* argval = DtoArgument(fnarg, (*arguments)[i]);
args.push_back(fixArgument(argval, irFty, callableTy->getParamType(argidx++), i)); args.push_back(fixArgument(argval, irFty, callableTy->getParamType(argidx++), i));
if (HAS_ATTRIBUTES(irFty.args[i]->attrs)) if (HAS_ATTRIBUTES(irFty.args[i]->attrs))
@ -497,8 +496,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
{ {
for (size_t i=0; i<n_arguments; i++) for (size_t i=0; i<n_arguments; i++)
{ {
Expression* exp = static_cast<Expression*>(arguments->data[i]); DValue* expelem = toElem((*arguments)[i]);
DValue* expelem = toElem(exp);
// cast to va_list* // cast to va_list*
LLValue* val = DtoBitCast(expelem->getLVal(), getVoidPtrType()); LLValue* val = DtoBitCast(expelem->getLVal(), getVoidPtrType());
++argiter; ++argiter;
@ -539,14 +537,14 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
for (int i=n-1; i>=0; --i) { for (int i=n-1; i>=0; --i) {
Parameter* fnarg = Parameter::getNth(tf->parameters, i); Parameter* fnarg = Parameter::getNth(tf->parameters, i);
assert(fnarg); assert(fnarg);
DValue* argval = DtoArgument(fnarg, static_cast<Expression*>(arguments->data[i])); DValue* argval = DtoArgument(fnarg, (*arguments)[i]);
argvals.insert(argvals.begin(), argval); argvals.insert(argvals.begin(), argval);
} }
} else { } else {
for (size_t i=0; i<n; ++i) { for (size_t i=0; i<n; ++i) {
Parameter* fnarg = Parameter::getNth(tf->parameters, i); Parameter* fnarg = Parameter::getNth(tf->parameters, i);
assert(fnarg); assert(fnarg);
DValue* argval = DtoArgument(fnarg, static_cast<Expression*>(arguments->data[i])); DValue* argval = DtoArgument(fnarg, (*arguments)[i]);
argvals.push_back(argval); argvals.push_back(argval);
} }
} }
@ -599,7 +597,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
for (size_t i=n; i<n_arguments; i++) for (size_t i=n; i<n_arguments; i++)
{ {
Parameter* fnarg = Parameter::getNth(tf->parameters, i); Parameter* fnarg = Parameter::getNth(tf->parameters, i);
DValue* argval = DtoArgument(fnarg, static_cast<Expression*>(arguments->data[i])); DValue* argval = DtoArgument(fnarg, (*arguments)[i]);
LLValue* arg = argval->getRVal(); LLValue* arg = argval->getRVal();
// FIXME: do we need any param attrs here ? // FIXME: do we need any param attrs here ?

View file

@ -832,7 +832,7 @@ public:
{ {
if (fndecl->linkage == LINKc && strcmp(fndecl->ident->string, "printf") == 0) if (fndecl->linkage == LINKc && strcmp(fndecl->ident->string, "printf") == 0)
{ {
warnInvalidPrintfCall(e->loc, static_cast<Expression*>(e->arguments->data[0]), e->arguments->dim); warnInvalidPrintfCall(e->loc, (*e->arguments)[0], e->arguments->dim);
} }
} }
@ -889,7 +889,7 @@ public:
e->error("va_arg instruction expects 1 arguments"); e->error("va_arg instruction expects 1 arguments");
fatal(); fatal();
} }
result = DtoVaArg(e->loc, e->type, static_cast<Expression*>(e->arguments->data[0])); result = DtoVaArg(e->loc, e->type, (*e->arguments)[0]);
} }
// C alloca // C alloca
else if (fndecl->llvmInternal == LLVMalloca) { else if (fndecl->llvmInternal == LLVMalloca) {
@ -897,7 +897,7 @@ public:
e->error("alloca expects 1 arguments"); e->error("alloca expects 1 arguments");
fatal(); fatal();
} }
Expression* exp = static_cast<Expression*>(e->arguments->data[0]); Expression* exp = (*e->arguments)[0];
DValue* expv = toElem(exp); DValue* expv = toElem(exp);
if (expv->getType()->toBasetype()->ty != Tint32) if (expv->getType()->toBasetype()->ty != Tint32)
expv = DtoCast(e->loc, expv, Type::tint32); expv = DtoCast(e->loc, expv, Type::tint32);
@ -909,7 +909,7 @@ public:
e->error("fence instruction expects 1 arguments"); e->error("fence instruction expects 1 arguments");
fatal(); fatal();
} }
gIR->ir->CreateFence(llvm::AtomicOrdering(static_cast<Expression*>(e->arguments->data[0])->toInteger())); gIR->ir->CreateFence(llvm::AtomicOrdering((*e->arguments)[0]->toInteger()));
return; return;
} }
// atomic store instruction // atomic store instruction
@ -918,9 +918,9 @@ public:
e->error("atomic store instruction expects 3 arguments"); e->error("atomic store instruction expects 3 arguments");
fatal(); fatal();
} }
Expression* exp1 = static_cast<Expression*>(e->arguments->data[0]); Expression* exp1 = (*e->arguments)[0];
Expression* exp2 = static_cast<Expression*>(e->arguments->data[1]); Expression* exp2 = (*e->arguments)[1];
int atomicOrdering = static_cast<Expression*>(e->arguments->data[2])->toInteger(); int atomicOrdering = (*e->arguments)[2]->toInteger();
LLValue* val = toElem(exp1)->getRVal(); LLValue* val = toElem(exp1)->getRVal();
LLValue* ptr = toElem(exp2)->getRVal(); LLValue* ptr = toElem(exp2)->getRVal();
@ -941,8 +941,8 @@ public:
fatal(); fatal();
} }
Expression* exp = static_cast<Expression*>(e->arguments->data[0]); Expression* exp = (*e->arguments)[0];
int atomicOrdering = static_cast<Expression*>(e->arguments->data[1])->toInteger(); int atomicOrdering = (*e->arguments)[1]->toInteger();
LLValue* ptr = toElem(exp)->getRVal(); LLValue* ptr = toElem(exp)->getRVal();
Type* retType = exp->type->nextOf(); Type* retType = exp->type->nextOf();
@ -963,10 +963,10 @@ public:
e->error("cmpxchg instruction expects 4 arguments"); e->error("cmpxchg instruction expects 4 arguments");
fatal(); fatal();
} }
Expression* exp1 = static_cast<Expression*>(e->arguments->data[0]); Expression* exp1 = (*e->arguments)[0];
Expression* exp2 = static_cast<Expression*>(e->arguments->data[1]); Expression* exp2 = (*e->arguments)[1];
Expression* exp3 = static_cast<Expression*>(e->arguments->data[2]); Expression* exp3 = (*e->arguments)[2];
int atomicOrdering = static_cast<Expression*>(e->arguments->data[3])->toInteger(); int atomicOrdering = (*e->arguments)[3]->toInteger();
LLValue* ptr = toElem(exp1)->getRVal(); LLValue* ptr = toElem(exp1)->getRVal();
LLValue* cmp = toElem(exp2)->getRVal(); LLValue* cmp = toElem(exp2)->getRVal();
LLValue* val = toElem(exp3)->getRVal(); LLValue* val = toElem(exp3)->getRVal();
@ -1011,9 +1011,9 @@ public:
break; break;
} }
Expression* exp1 = static_cast<Expression*>(e->arguments->data[0]); Expression* exp1 = (*e->arguments)[0];
Expression* exp2 = static_cast<Expression*>(e->arguments->data[1]); Expression* exp2 = (*e->arguments)[1];
int atomicOrdering = static_cast<Expression*>(e->arguments->data[2])->toInteger(); int atomicOrdering = (*e->arguments)[2]->toInteger();
LLValue* ptr = toElem(exp1)->getRVal(); LLValue* ptr = toElem(exp1)->getRVal();
LLValue* val = toElem(exp2)->getRVal(); LLValue* val = toElem(exp2)->getRVal();
LLValue* ret = gIR->ir->CreateAtomicRMW(llvm::AtomicRMWInst::BinOp(op), ptr, val, LLValue* ret = gIR->ir->CreateAtomicRMW(llvm::AtomicRMWInst::BinOp(op), ptr, val,
@ -1031,8 +1031,8 @@ public:
fatal(); fatal();
} }
Expression* exp1 = static_cast<Expression*>(e->arguments->data[0]); Expression* exp1 = (*e->arguments)[0];
Expression* exp2 = static_cast<Expression*>(e->arguments->data[1]); Expression* exp2 = (*e->arguments)[1];
LLValue* ptr = toElem(exp1)->getRVal(); LLValue* ptr = toElem(exp1)->getRVal();
LLValue* bitnum = toElem(exp2)->getRVal(); LLValue* bitnum = toElem(exp2)->getRVal();
@ -1839,7 +1839,7 @@ public:
assert(e->arguments->dim >= 1); assert(e->arguments->dim >= 1);
if (e->arguments->dim == 1) if (e->arguments->dim == 1)
{ {
DValue* sz = toElem(static_cast<Expression*>(e->arguments->data[0])); DValue* sz = toElem((*e->arguments)[0]);
// allocate & init // allocate & init
result = DtoNewDynArray(e->loc, e->newtype, sz, true); result = DtoNewDynArray(e->loc, e->newtype, sz, true);
} }
@ -1849,7 +1849,7 @@ public:
std::vector<DValue*> dims; std::vector<DValue*> dims;
dims.reserve(ndims); dims.reserve(ndims);
for (size_t i=0; i<ndims; ++i) for (size_t i=0; i<ndims; ++i)
dims.push_back(toElem(static_cast<Expression*>(e->arguments->data[i]))); dims.push_back(toElem((*e->arguments)[i]));
result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims, true); result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims, true);
} }
} }
@ -2873,8 +2873,8 @@ public:
const size_t n = e->keys->dim; const size_t n = e->keys->dim;
for (size_t i = 0; i<n; ++i) for (size_t i = 0; i<n; ++i)
{ {
Expression* ekey = static_cast<Expression*>(e->keys->data[i]); Expression* ekey = (*e->keys)[i];
Expression* eval = static_cast<Expression*>(e->values->data[i]); Expression* eval = (*e->values)[i];
IF_LOG Logger::println("(%zu) aa[%s] = %s", i, ekey->toChars(), eval->toChars()); IF_LOG Logger::println("(%zu) aa[%s] = %s", i, ekey->toChars(), eval->toChars());
@ -2960,13 +2960,12 @@ public:
types.reserve(e->exps->dim); types.reserve(e->exps->dim);
for (size_t i = 0; i < e->exps->dim; i++) for (size_t i = 0; i < e->exps->dim; i++)
{ {
Expression *el = static_cast<Expression *>(e->exps->data[i]); types.push_back(i1ToI8(voidToI8(DtoType((*e->exps)[i]->type))));
types.push_back(i1ToI8(voidToI8(DtoType(el->type))));
} }
LLValue *val = DtoRawAlloca(LLStructType::get(gIR->context(), types),0, "tuple"); LLValue *val = DtoRawAlloca(LLStructType::get(gIR->context(), types),0, "tuple");
for (size_t i = 0; i < e->exps->dim; i++) for (size_t i = 0; i < e->exps->dim; i++)
{ {
Expression *el = static_cast<Expression *>(e->exps->data[i]); Expression *el = (*e->exps)[i];
DValue* ep = toElem(el); DValue* ep = toElem(el);
LLValue *gep = DtoGEPi(val,0,i); LLValue *gep = DtoGEPi(val,0,i);
if (el->type->ty == Tstruct) if (el->type->ty == Tstruct)

View file

@ -253,7 +253,7 @@ LLType* DtoStructTypeFromArguments(Arguments* arguments)
std::vector<LLType*> types; std::vector<LLType*> types;
for (size_t i = 0; i < arguments->dim; i++) for (size_t i = 0; i < arguments->dim; i++)
{ {
Argument *arg = static_cast<Argument *>(arguments->data[i]); Argument *arg = (*arguments)[i];
assert(arg && arg->type); assert(arg && arg->type);
types.push_back(DtoType(arg->type)); types.push_back(DtoType(arg->type));