Skip to content

Commit

Permalink
Range-ify usages of front-end Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Jun 2, 2017
1 parent 9fd7fa2 commit 2acddf9
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 50 deletions.
5 changes: 3 additions & 2 deletions driver/archiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ int createStaticLibrary() {
}

// object files
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
args.push_back((*global.params.objfiles)[i]);
for (auto objfile : *global.params.objfiles) {
args.push_back(objfile);
}

// .res/.def files for lib.exe
if (isTargetMSVC) {
Expand Down
14 changes: 8 additions & 6 deletions driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ void ArgsBuilder::addLTOLinkFlags() {
void ArgsBuilder::build(llvm::StringRef outputPath,
llvm::cl::boolOrDefault fullyStaticFlag) {
// object files
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
args.push_back((*global.params.objfiles)[i]);
for (auto objfile : *global.params.objfiles) {
args.push_back(objfile);
}

// Link with profile-rt library when generating an instrumented binary.
// profile-rt uses Phobos (MD5 hashing) and therefore must be passed on the
Expand All @@ -191,8 +192,9 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
}

// user libs
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
args.push_back((*global.params.libfiles)[i]);
for (auto libfile : *global.params.libfiles) {
args.push_back(libfile);
}

if (global.params.dll) {
args.push_back("-shared");
Expand All @@ -217,8 +219,8 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
addUserSwitches();

// libs added via pragma(lib, libname)
for (unsigned i = 0; i < global.params.linkswitches->dim; i++) {
args.push_back((*global.params.linkswitches)[i]);
for (auto ls : *global.params.linkswitches) {
args.push_back(ls);
}

if (global.params.targetTriple->getOS() == llvm::Triple::Linux) {
Expand Down
14 changes: 8 additions & 6 deletions driver/linker-msvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
args.push_back(("/OUT:" + outputPath).str());

// object files
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
args.push_back((*global.params.objfiles)[i]);
for (auto objfile : *global.params.objfiles) {
args.push_back(objfile);
}

// .res/.def files
if (global.params.resfile)
Expand All @@ -118,8 +119,9 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
}

// user libs
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
args.push_back((*global.params.libfiles)[i]);
for (auto libfile : *global.params.libfiles) {
args.push_back(libfile);
}

// additional linker switches
auto addSwitch = [&](std::string str) {
Expand All @@ -138,8 +140,8 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
addSwitch(str);
}

for (unsigned i = 0; i < global.params.linkswitches->dim; i++) {
addSwitch(global.params.linkswitches->data[i]);
for (auto ls : *global.params.linkswitches) {
addSwitch(ls);
}

// default libs
Expand Down
4 changes: 2 additions & 2 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
const auto toWinPaths = [](Strings *paths) {
if (!paths)
return;
for (unsigned i = 0; i < paths->dim; ++i)
(*paths)[i] = dupPathString((*paths)[i]);
for (auto &path : *paths)
path = dupPathString(path);
};
toWinPaths(global.params.imppath);
toWinPaths(global.params.fileImppath);
Expand Down
3 changes: 1 addition & 2 deletions gen/asmstmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState *p) {
p->asmBlock = asmblock;

// do asm statements
for (unsigned i = 0; i < stmt->statements->dim; i++) {
Statement *s = (*stmt->statements)[i];
for (auto s : *stmt->statements) {
if (s) {
Statement_toIR(s, p);
}
Expand Down
8 changes: 3 additions & 5 deletions gen/dibuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,11 +1177,9 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
size_t argNo = 0;
if (fd->vthis != vd) {
assert(fd->parameters);
for (argNo = 0; argNo < fd->parameters->dim; argNo++) {
if ((*fd->parameters)[argNo] == vd)
break;
}
assert(argNo < fd->parameters->dim);
auto it = std::find(fd->parameters->begin(), fd->parameters->end(), vd);
assert(it != fd->parameters->end());
argNo = it - fd->parameters->begin();
if (fd->vthis)
argNo++;
}
Expand Down
7 changes: 3 additions & 4 deletions gen/inlineir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl,
fun->setCallingConv(llvm::CallingConv::C);

// Build the runtime arguments
size_t n = arguments->dim;
llvm::SmallVector<llvm::Value *, 8> args;
args.reserve(n);
for (size_t i = 0; i < n; i++) {
args.push_back(DtoRVal((*arguments)[i]));
args.reserve(arguments->dim);
for (auto arg : *arguments) {
args.push_back(DtoRVal(arg));
}

llvm::Value *rv = gIR->ir->CreateCall(fun, args);
Expand Down
13 changes: 6 additions & 7 deletions gen/llvmhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,10 +988,9 @@ DValue *DtoDeclarationExp(Dsymbol *declaration) {
} else if (AttribDeclaration *a = declaration->isAttribDeclaration()) {
Logger::println("AttribDeclaration");
// choose the right set in case this is a conditional declaration
Dsymbols *d = a->include(nullptr, nullptr);
if (d) {
for (unsigned i = 0; i < d->dim; ++i) {
DtoDeclarationExp((*d)[i]);
if (auto symbols = a->include(nullptr, nullptr)) {
for (auto symbol : *symbols) {
DtoDeclarationExp(symbol);
}
}
} else if (TemplateMixin *m = declaration->isTemplateMixin()) {
Expand All @@ -1003,9 +1002,9 @@ DValue *DtoDeclarationExp(Dsymbol *declaration) {
Logger::println("TupleDeclaration");
assert(tupled->isexp && "Non-expression tuple decls not handled yet.");
assert(tupled->objects);
for (unsigned i = 0; i < tupled->objects->dim; ++i) {
DsymbolExp *exp = static_cast<DsymbolExp *>(tupled->objects->data[i]);
DtoDeclarationExp(exp->s);
for (auto object : *tupled->objects) {
auto symExp = static_cast<DsymbolExp *>(object);
DtoDeclarationExp(symExp->s);
}
} else {
// Do nothing for template/alias/enum declarations and static
Expand Down
4 changes: 2 additions & 2 deletions gen/mangling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ std::string hashSymbolName(llvm::StringRef name, Dsymbol *symb) {
auto moddecl = symb->getModule()->md;
assert(moddecl);
if (auto packages = moddecl->packages) {
for (size_t i = 0; i < packages->dim; ++i) {
llvm::StringRef str = (*packages)[i]->toChars();
for (auto package : *packages) {
llvm::StringRef str = package->toChars();
ret += std::to_string(str.size());
ret += str;
}
Expand Down
1 change: 1 addition & 0 deletions gen/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ void codegenModule(IRState *irs, Module *m) {
}

// process module members
// NOTE: m->members may grow during codegen
for (unsigned k = 0; k < m->members->dim; k++) {
Dsymbol *dsym = (*m->members)[k];
assert(dsym);
Expand Down
2 changes: 1 addition & 1 deletion gen/statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ class ToIRVisitor : public Visitor {
}

// do statements
Statement **stmts = static_cast<Statement **>(stmt->statements->data);
Statement **stmts = stmt->statements->data;

for (size_t i = 0; i < nstmt; i++) {
Statement *s = stmts[i];
Expand Down
8 changes: 4 additions & 4 deletions gen/toconstelem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ class ToConstElemVisitor : public Visitor {
std::map<VarDeclaration *, llvm::Constant *> varInits;
const size_t nexprs = e->elements->dim;
for (size_t i = 0; i < nexprs; i++) {
if ((*e->elements)[i]) {
LLConstant *c = toConstElem((*e->elements)[i]);
if (auto elem = (*e->elements)[i]) {
LLConstant *c = toConstElem(elem);
// extend i1 to i8
if (c->getType() == LLType::getInt1Ty(p->context()))
c = llvm::ConstantExpr::getZExt(c, LLType::getInt8Ty(p->context()));
Expand Down Expand Up @@ -641,12 +641,12 @@ class ToConstElemVisitor : public Visitor {
cur = classHierachy.top();
classHierachy.pop();
for (size_t j = 0; j < cur->fields.dim; ++j) {
if ((*value->elements)[i]) {
if (auto elem = (*value->elements)[i]) {
VarDeclaration *field = cur->fields[j];
IF_LOG Logger::println("Getting initializer for: %s",
field->toChars());
LOG_SCOPE;
varInits[field] = toConstElem((*value->elements)[i]);
varInits[field] = toConstElem(elem);
}
++i;
}
Expand Down
14 changes: 7 additions & 7 deletions gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,8 +1466,8 @@ class ToElemVisitor : public Visitor {
size_t ndims = e->arguments->dim;
std::vector<DValue *> dims;
dims.reserve(ndims);
for (size_t i = 0; i < ndims; ++i) {
dims.push_back(toElem((*e->arguments)[i]));
for (auto arg : *e->arguments) {
dims.push_back(toElem(arg));
}
result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims);
}
Expand Down Expand Up @@ -2272,7 +2272,7 @@ class ToElemVisitor : public Visitor {
auto global = new llvm::GlobalVariable(
gIR->module, init->getType(), true,
llvm::GlobalValue::InternalLinkage, init, ".immutablearray");
result = new DSliceValue(arrayType, DtoConstSize_t(e->elements->dim),
result = new DSliceValue(arrayType, DtoConstSize_t(len),
DtoBitCast(global, getPtrToType(llElemType)));
} else {
DSliceValue *dynSlice = DtoNewDynArray(
Expand Down Expand Up @@ -2431,8 +2431,8 @@ class ToElemVisitor : public Visitor {
keysInits.reserve(e->keys->dim);
valuesInits.reserve(e->keys->dim);
for (size_t i = 0, n = e->keys->dim; i < n; ++i) {
Expression *ekey = e->keys->tdata()[i];
Expression *eval = e->values->tdata()[i];
Expression *ekey = (*e->keys)[i];
Expression *eval = (*e->values)[i];
IF_LOG Logger::println("(%llu) aa[%s] = %s",
static_cast<unsigned long long>(i),
ekey->toChars(), eval->toChars());
Expand Down Expand Up @@ -2585,8 +2585,8 @@ class ToElemVisitor : public Visitor {

std::vector<LLType *> types;
types.reserve(e->exps->dim);
for (size_t i = 0; i < e->exps->dim; i++) {
types.push_back(DtoMemType((*e->exps)[i]->type));
for (auto exp : *e->exps) {
types.push_back(DtoMemType(exp->type));
}
LLValue *val =
DtoRawAlloca(LLStructType::get(gIR->context(), types), 0, ".tuple");
Expand Down
3 changes: 1 addition & 2 deletions gen/typinf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ class LLVMDefineVisitor : public Visitor {

LLType *tiTy = DtoType(Type::dtypeinfo->type);

for (size_t i = 0; i < dim; i++) {
Parameter *arg = static_cast<Parameter *>(tu->arguments->data[i]);
for (auto arg : *tu->arguments) {
arrInits.push_back(DtoTypeInfoOf(arg->type, true));
}

Expand Down

0 comments on commit 2acddf9

Please sign in to comment.