[pkg-d-commits] [ldc] 69/74: Range-ify usages of front-end Arrays

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:54:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta2
in repository ldc.

commit 383c2d3a599cf4921c07593e7e90a74e10958a38
Author: Martin <noone at nowhere.com>
Date:   Fri Jun 2 20:43:25 2017 +0200

    Range-ify usages of front-end Arrays
---
 driver/archiver.cpp    |  5 +++--
 driver/linker-gcc.cpp  | 14 ++++++++------
 driver/linker-msvc.cpp | 14 ++++++++------
 driver/main.cpp        |  4 ++--
 gen/asmstmt.cpp        |  3 +--
 gen/dibuilder.cpp      |  8 +++-----
 gen/inlineir.cpp       |  7 +++----
 gen/llvmhelpers.cpp    |  5 ++---
 gen/mangling.cpp       |  4 ++--
 gen/modules.cpp        |  1 +
 gen/statements.cpp     |  2 +-
 gen/toconstelem.cpp    |  8 ++++----
 gen/toir.cpp           | 14 +++++++-------
 gen/typinf.cpp         |  3 +--
 14 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/driver/archiver.cpp b/driver/archiver.cpp
index 2c156ce..8a8aacb 100644
--- a/driver/archiver.cpp
+++ b/driver/archiver.cpp
@@ -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) {
diff --git a/driver/linker-gcc.cpp b/driver/linker-gcc.cpp
index c12f602..0d7a8e3 100644
--- a/driver/linker-gcc.cpp
+++ b/driver/linker-gcc.cpp
@@ -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
@@ -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");
@@ -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) {
diff --git a/driver/linker-msvc.cpp b/driver/linker-msvc.cpp
index 3624b36..6ead29f 100644
--- a/driver/linker-msvc.cpp
+++ b/driver/linker-msvc.cpp
@@ -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)
@@ -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) {
@@ -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
diff --git a/driver/main.cpp b/driver/main.cpp
index 40a9b75..7e44541 100644
--- a/driver/main.cpp
+++ b/driver/main.cpp
@@ -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);
diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp
index ccba4aa..29c3647 100644
--- a/gen/asmstmt.cpp
+++ b/gen/asmstmt.cpp
@@ -480,8 +480,7 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState *p) {
 
   // do asm statements
   for (unsigned i = 0; i < stmt->statements->dim; i++) {
-    Statement *s = (*stmt->statements)[i];
-    if (s) {
+    if (Statement *s = (*stmt->statements)[i]) {
       Statement_toIR(s, p);
     }
   }
diff --git a/gen/dibuilder.cpp b/gen/dibuilder.cpp
index 79267b8..03fca63 100644
--- a/gen/dibuilder.cpp
+++ b/gen/dibuilder.cpp
@@ -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++;
     }
diff --git a/gen/inlineir.cpp b/gen/inlineir.cpp
index bb87e1b..8a7f286 100644
--- a/gen/inlineir.cpp
+++ b/gen/inlineir.cpp
@@ -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);
diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp
index 6e8909f..0c91230 100644
--- a/gen/llvmhelpers.cpp
+++ b/gen/llvmhelpers.cpp
@@ -988,8 +988,7 @@ 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) {
+    if (auto d = a->include(nullptr, nullptr)) {
       for (unsigned i = 0; i < d->dim; ++i) {
         DtoDeclarationExp((*d)[i]);
       }
@@ -1004,7 +1003,7 @@ DValue *DtoDeclarationExp(Dsymbol *declaration) {
     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]);
+      auto exp = static_cast<DsymbolExp *>((*tupled->objects)[i]);
       DtoDeclarationExp(exp->s);
     }
   } else {
diff --git a/gen/mangling.cpp b/gen/mangling.cpp
index ef31200..a9c7689 100644
--- a/gen/mangling.cpp
+++ b/gen/mangling.cpp
@@ -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;
       }
diff --git a/gen/modules.cpp b/gen/modules.cpp
index f4105a4..a3428cd 100644
--- a/gen/modules.cpp
+++ b/gen/modules.cpp
@@ -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);
diff --git a/gen/statements.cpp b/gen/statements.cpp
index 4b16074..056e81c 100644
--- a/gen/statements.cpp
+++ b/gen/statements.cpp
@@ -1210,7 +1210,7 @@ public:
     }
 
     // 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];
diff --git a/gen/toconstelem.cpp b/gen/toconstelem.cpp
index 481e502..a6652fb 100644
--- a/gen/toconstelem.cpp
+++ b/gen/toconstelem.cpp
@@ -591,8 +591,8 @@ public:
       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()));
@@ -641,12 +641,12 @@ public:
           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;
           }
diff --git a/gen/toir.cpp b/gen/toir.cpp
index f970952..b4764e0 100644
--- a/gen/toir.cpp
+++ b/gen/toir.cpp
@@ -1466,8 +1466,8 @@ public:
         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);
       }
@@ -2272,7 +2272,7 @@ public:
         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(
@@ -2431,8 +2431,8 @@ public:
       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());
@@ -2585,8 +2585,8 @@ public:
 
     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");
diff --git a/gen/typinf.cpp b/gen/typinf.cpp
index a63cbf0..5747b01 100644
--- a/gen/typinf.cpp
+++ b/gen/typinf.cpp
@@ -486,8 +486,7 @@ public:
 
     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));
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list