From e4aa92deb3d5570eee4c05dda56e3f39cfbe56ee Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 16 Nov 2014 08:00:17 +0100 Subject: [PATCH] Get rid of more superfluous casts with DMD arrays. There are still a few more left. --- gen/asmstmt.cpp | 6 +++--- gen/module.cpp | 8 ++------ gen/naked.cpp | 7 +++---- gen/tocall.cpp | 18 ++++++++---------- gen/toir.cpp | 49 ++++++++++++++++++++++++------------------------- gen/tollvm.cpp | 2 +- 6 files changed, 41 insertions(+), 49 deletions(-) diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index fa18c8ab75..99e4ae8d9e 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -509,7 +509,7 @@ void AsmBlockStatement_toIR(AsmBlockStatement *stmt, IRState* p) // do asm statements for (unsigned i=0; i < stmt->statements->dim; i++) { - Statement* s = static_cast(stmt->statements->data[i]); + Statement* s = (*stmt->statements)[i]; if (s) { Statement_toIR(s, p); } @@ -780,7 +780,7 @@ Statement *AsmBlockStatement::syntaxCopy() a->setDim(statements->dim); for (size_t i = 0; i < statements->dim; i++) { - Statement *s = static_cast(statements->data[i]); + Statement *s = (*statements)[i]; if (s) s = s->syntaxCopy(); a->data[i] = s; @@ -811,7 +811,7 @@ AsmBlockStatement* CompoundStatement::endsWithAsm() if (statements && statements->dim) { unsigned last = statements->dim - 1; - Statement* s = static_cast(statements->data[last]); + Statement* s = (*statements)[last]; if (s) return s->endsWithAsm(); } return NULL; diff --git a/gen/module.cpp b/gen/module.cpp index 1394194839..e29786fc49 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -562,7 +562,7 @@ static void codegenModule(Module* m) // process module members for (unsigned k=0; k < m->members->dim; k++) { - Dsymbol* dsym = static_cast(m->members->data[k]); + Dsymbol* dsym = (*m->members)[k]; assert(dsym); Declaration_codegen(dsym); } @@ -755,11 +755,7 @@ void Module::genmoduleinfo() //printf("members->dim = %d\n", members->dim); for (size_t i = 0; i < members->dim; i++) { - Dsymbol *member; - - member = static_cast(members->data[i]); - //printf("\tmember '%s'\n", member->toChars()); - member->addLocalClass(&aclasses); + (*members)[i]->addLocalClass(&aclasses); } // fill inits std::vector classInits; diff --git a/gen/naked.cpp b/gen/naked.cpp index 13525447be..aa314dc8f9 100644 --- a/gen/naked.cpp +++ b/gen/naked.cpp @@ -433,7 +433,7 @@ DValue * DtoInlineAsmExpr(Loc& loc, FuncDeclaration * fd, Expressions * argument assert(arguments->dim >= 2 && "invalid __asm call"); // get code param - Expression* e = static_cast(arguments->data[0]); + Expression* e = (*arguments)[0]; IF_LOG Logger::println("code exp: %s", e->toChars()); StringExp* se = static_cast(e); if (e->op != TOKstring || se->sz != 1) @@ -444,7 +444,7 @@ DValue * DtoInlineAsmExpr(Loc& loc, FuncDeclaration * fd, Expressions * argument std::string code(static_cast(se->string), se->len); // get constraints param - e = static_cast(arguments->data[1]); + e = (*arguments)[1]; IF_LOG Logger::println("constraint exp: %s", e->toChars()); se = static_cast(e); 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++) { - e = static_cast(arguments->data[i]); - args.push_back(toElem(e)->getRVal()); + args.push_back(toElem((*arguments)[i])->getRVal()); argtypes.push_back(args.back()->getType()); } diff --git a/gen/tocall.cpp b/gen/tocall.cpp index 4768467ee0..ddbe0a0880 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -227,7 +227,7 @@ void DtoBuildDVarArgList(std::vector& args, // build struct with argument types (non variadic args) for (size_t i=begin; i(arguments->data[i]); + Expression* argexp = (*arguments)[i]; assert(argexp->type->ty != Ttuple); vtypes.push_back(DtoType(argexp->type)); size_t sz = getTypePaddedSize(vtypes.back()); @@ -263,7 +263,7 @@ void DtoBuildDVarArgList(std::vector& args, // store arguments in the struct for (size_t i=begin,k=0; i(arguments->data[i]); + Expression* argexp = (*arguments)[i]; LLValue* argdst = DtoGEPi(mem,0,k); argdst = DtoBitCast(argdst, getPtrToType(i1ToI8(DtoType(argexp->type)))); DtoVariadicArgument(argexp, argdst); @@ -281,8 +281,7 @@ void DtoBuildDVarArgList(std::vector& args, vtypeinfos.reserve(n_arguments); for (size_t i=begin; i(arguments->data[i]); - vtypeinfos.push_back(DtoTypeInfoOf(argexp->type)); + vtypeinfos.push_back(DtoTypeInfoOf((*arguments)[i]->type)); } // apply initializer @@ -315,7 +314,7 @@ void DtoBuildDVarArgList(std::vector& args, for (int i=0; iparameters, i); - DValue* argval = DtoArgument(fnarg, static_cast(arguments->data[i])); + DValue* argval = DtoArgument(fnarg, (*arguments)[i]); args.push_back(fixArgument(argval, irFty, callableTy->getParamType(argidx++), i)); 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(arguments->data[i]); - DValue* expelem = toElem(exp); + DValue* expelem = toElem((*arguments)[i]); // cast to va_list* LLValue* val = DtoBitCast(expelem->getLVal(), getVoidPtrType()); ++argiter; @@ -539,14 +537,14 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* for (int i=n-1; i>=0; --i) { Parameter* fnarg = Parameter::getNth(tf->parameters, i); assert(fnarg); - DValue* argval = DtoArgument(fnarg, static_cast(arguments->data[i])); + DValue* argval = DtoArgument(fnarg, (*arguments)[i]); argvals.insert(argvals.begin(), argval); } } else { for (size_t i=0; iparameters, i); assert(fnarg); - DValue* argval = DtoArgument(fnarg, static_cast(arguments->data[i])); + DValue* argval = DtoArgument(fnarg, (*arguments)[i]); argvals.push_back(argval); } } @@ -599,7 +597,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* for (size_t i=n; iparameters, i); - DValue* argval = DtoArgument(fnarg, static_cast(arguments->data[i])); + DValue* argval = DtoArgument(fnarg, (*arguments)[i]); LLValue* arg = argval->getRVal(); // FIXME: do we need any param attrs here ? diff --git a/gen/toir.cpp b/gen/toir.cpp index 54107e4ee6..6da7f460a1 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -832,7 +832,7 @@ public: { if (fndecl->linkage == LINKc && strcmp(fndecl->ident->string, "printf") == 0) { - warnInvalidPrintfCall(e->loc, static_cast(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"); fatal(); } - result = DtoVaArg(e->loc, e->type, static_cast(e->arguments->data[0])); + result = DtoVaArg(e->loc, e->type, (*e->arguments)[0]); } // C alloca else if (fndecl->llvmInternal == LLVMalloca) { @@ -897,7 +897,7 @@ public: e->error("alloca expects 1 arguments"); fatal(); } - Expression* exp = static_cast(e->arguments->data[0]); + Expression* exp = (*e->arguments)[0]; DValue* expv = toElem(exp); if (expv->getType()->toBasetype()->ty != Tint32) expv = DtoCast(e->loc, expv, Type::tint32); @@ -909,7 +909,7 @@ public: e->error("fence instruction expects 1 arguments"); fatal(); } - gIR->ir->CreateFence(llvm::AtomicOrdering(static_cast(e->arguments->data[0])->toInteger())); + gIR->ir->CreateFence(llvm::AtomicOrdering((*e->arguments)[0]->toInteger())); return; } // atomic store instruction @@ -918,9 +918,9 @@ public: e->error("atomic store instruction expects 3 arguments"); fatal(); } - Expression* exp1 = static_cast(e->arguments->data[0]); - Expression* exp2 = static_cast(e->arguments->data[1]); - int atomicOrdering = static_cast(e->arguments->data[2])->toInteger(); + Expression* exp1 = (*e->arguments)[0]; + Expression* exp2 = (*e->arguments)[1]; + int atomicOrdering = (*e->arguments)[2]->toInteger(); LLValue* val = toElem(exp1)->getRVal(); LLValue* ptr = toElem(exp2)->getRVal(); @@ -941,8 +941,8 @@ public: fatal(); } - Expression* exp = static_cast(e->arguments->data[0]); - int atomicOrdering = static_cast(e->arguments->data[1])->toInteger(); + Expression* exp = (*e->arguments)[0]; + int atomicOrdering = (*e->arguments)[1]->toInteger(); LLValue* ptr = toElem(exp)->getRVal(); Type* retType = exp->type->nextOf(); @@ -963,10 +963,10 @@ public: e->error("cmpxchg instruction expects 4 arguments"); fatal(); } - Expression* exp1 = static_cast(e->arguments->data[0]); - Expression* exp2 = static_cast(e->arguments->data[1]); - Expression* exp3 = static_cast(e->arguments->data[2]); - int atomicOrdering = static_cast(e->arguments->data[3])->toInteger(); + Expression* exp1 = (*e->arguments)[0]; + Expression* exp2 = (*e->arguments)[1]; + Expression* exp3 = (*e->arguments)[2]; + int atomicOrdering = (*e->arguments)[3]->toInteger(); LLValue* ptr = toElem(exp1)->getRVal(); LLValue* cmp = toElem(exp2)->getRVal(); LLValue* val = toElem(exp3)->getRVal(); @@ -1011,9 +1011,9 @@ public: break; } - Expression* exp1 = static_cast(e->arguments->data[0]); - Expression* exp2 = static_cast(e->arguments->data[1]); - int atomicOrdering = static_cast(e->arguments->data[2])->toInteger(); + Expression* exp1 = (*e->arguments)[0]; + Expression* exp2 = (*e->arguments)[1]; + int atomicOrdering = (*e->arguments)[2]->toInteger(); LLValue* ptr = toElem(exp1)->getRVal(); LLValue* val = toElem(exp2)->getRVal(); LLValue* ret = gIR->ir->CreateAtomicRMW(llvm::AtomicRMWInst::BinOp(op), ptr, val, @@ -1031,8 +1031,8 @@ public: fatal(); } - Expression* exp1 = static_cast(e->arguments->data[0]); - Expression* exp2 = static_cast(e->arguments->data[1]); + Expression* exp1 = (*e->arguments)[0]; + Expression* exp2 = (*e->arguments)[1]; LLValue* ptr = toElem(exp1)->getRVal(); LLValue* bitnum = toElem(exp2)->getRVal(); @@ -1839,7 +1839,7 @@ public: assert(e->arguments->dim >= 1); if (e->arguments->dim == 1) { - DValue* sz = toElem(static_cast(e->arguments->data[0])); + DValue* sz = toElem((*e->arguments)[0]); // allocate & init result = DtoNewDynArray(e->loc, e->newtype, sz, true); } @@ -1849,7 +1849,7 @@ public: std::vector dims; dims.reserve(ndims); for (size_t i=0; i(e->arguments->data[i]))); + dims.push_back(toElem((*e->arguments)[i])); result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims, true); } } @@ -2873,8 +2873,8 @@ public: const size_t n = e->keys->dim; for (size_t i = 0; i(e->keys->data[i]); - Expression* eval = static_cast(e->values->data[i]); + Expression* ekey = (*e->keys)[i]; + Expression* eval = (*e->values)[i]; IF_LOG Logger::println("(%zu) aa[%s] = %s", i, ekey->toChars(), eval->toChars()); @@ -2960,13 +2960,12 @@ public: types.reserve(e->exps->dim); for (size_t i = 0; i < e->exps->dim; i++) { - Expression *el = static_cast(e->exps->data[i]); - types.push_back(i1ToI8(voidToI8(DtoType(el->type)))); + types.push_back(i1ToI8(voidToI8(DtoType((*e->exps)[i]->type)))); } LLValue *val = DtoRawAlloca(LLStructType::get(gIR->context(), types),0, "tuple"); for (size_t i = 0; i < e->exps->dim; i++) { - Expression *el = static_cast(e->exps->data[i]); + Expression *el = (*e->exps)[i]; DValue* ep = toElem(el); LLValue *gep = DtoGEPi(val,0,i); if (el->type->ty == Tstruct) diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 1b3963be01..078ea5c946 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -253,7 +253,7 @@ LLType* DtoStructTypeFromArguments(Arguments* arguments) std::vector types; for (size_t i = 0; i < arguments->dim; i++) { - Argument *arg = static_cast(arguments->data[i]); + Argument *arg = (*arguments)[i]; assert(arg && arg->type); types.push_back(DtoType(arg->type));