Make use of C++11 range-based for

Should be available now that support for LLVM < 3.5 has been dropped.
This commit is contained in:
Martin 2015-11-01 14:29:58 +01:00
parent 3d803c7a1c
commit 2d959ea540
34 changed files with 182 additions and 335 deletions

View file

@ -906,11 +906,8 @@ Params parseArgs(size_t originalArgc, char** originalArgv, const std::string &ld
void pushSwitches(const char* prefix, const std::vector<char*>& vals, std::vector<const char*>& r)
{
typedef std::vector<char*>::const_iterator It;
for (It it = vals.begin(), end = vals.end(); it != end; ++it)
{
r.push_back(concat(prefix, *it));
}
for (auto v : vals)
r.push_back(concat(prefix, v));
}
/**
@ -1105,11 +1102,8 @@ int main(int argc, char *argv[])
{
llvm::raw_fd_ostream rspOut(rspFd, /*shouldClose=*/true);
typedef std::vector<const char*>::const_iterator It;
for (It it = args.begin(), end = args.end(); it != end; ++it)
{
rspOut << *it << '\n';
}
for (auto arg : args)
rspOut << arg << '\n';
}
std::string rspArg = "@";

View file

@ -248,11 +248,10 @@ static int linkObjToBinaryGcc(bool sharedLib)
}
Logger::println("Linking with: ");
std::vector<std::string>::const_iterator I = args.begin(), E = args.end();
Stream logstr = Logger::cout();
for (; I != E; ++I)
if (!(*I).empty())
logstr << "'" << *I << "'" << " ";
for (const auto& arg : args)
if (!arg.empty())
logstr << "'" << arg << "'" << " ";
logstr << "\n"; // FIXME where's flush ?
// try to call linker
@ -554,11 +553,10 @@ static int linkObjToBinaryWin(bool sharedLib)
args.push_back("advapi32.lib");
Logger::println("Linking with: ");
std::vector<std::string>::const_iterator I = args.begin(), E = args.end();
Stream logstr = Logger::cout();
for (; I != E; ++I)
if (!(*I).empty())
logstr << "'" << *I << "'" << " ";
for (const auto& arg : args)
if (!arg.empty())
logstr << "'" << arg << "'" << " ";
logstr << "\n"; // FIXME where's flush ?
// try to call linker

View file

@ -123,16 +123,14 @@ void printVersion() {
// Helper function to handle -d-debug=* and -d-version=*
static void processVersions(std::vector<std::string>& list, const char* type,
void (*setLevel)(unsigned), void (*addIdent)(const char*)) {
typedef std::vector<std::string>::iterator It;
for(It I = list.begin(), E = list.end(); I != E; ++I) {
const char* value = I->c_str();
for (const auto& i : list) {
const char* value = i.c_str();
if (isdigit(value[0])) {
errno = 0;
char* end;
long level = strtol(value, &end, 10);
if (*end || errno || level > INT_MAX) {
error(Loc(), "Invalid %s level: %s", type, I->c_str());
error(Loc(), "Invalid %s level: %s", type, i.c_str());
} else {
setLevel((unsigned)level);
}
@ -142,7 +140,7 @@ static void processVersions(std::vector<std::string>& list, const char* type,
addIdent(cstr);
continue;
} else {
error(Loc(), "Invalid %s identifier or level: '%s'", type, I->c_str());
error(Loc(), "Invalid %s identifier or level: '%s'", type, i.c_str());
}
}
}
@ -167,7 +165,7 @@ static void hide(llvm::StringMap<cl::Option *>& map, const char* name) {
}
static void rename(llvm::StringMap<cl::Option *>& map, const char* from, const char *to) {
llvm::StringMap<cl::Option*>::iterator i = map.find(from);
auto i = map.find(from);
if (i != map.end())
{
cl::Option *opt = i->getValue();
@ -406,14 +404,13 @@ static void parseCommandLine(int argc, char **argv, Strings &sourceFiles, bool &
}
sourceFiles.reserve(fileList.size());
typedef std::vector<std::string>::iterator It;
for(It I = fileList.begin(), E = fileList.end(); I != E; ++I)
for (const auto& file : fileList)
{
if (!I->empty())
if (!file.empty())
{
char* copy = mem.xstrdup(I->c_str());
char* copy = mem.xstrdup(file.c_str());
#ifdef _WIN32
std::replace(copy, copy + I->length(), '/', '\\');
std::replace(copy, copy + file.length(), '/', '\\');
#endif
sourceFiles.push(copy);
}
@ -835,18 +832,16 @@ static void dumpPredefinedVersions()
{
fprintf(global.stdmsg, "predefs ");
int col = 10;
for (Strings::iterator I = global.params.versionids->begin(),
E = global.params.versionids->end();
I != E; ++I)
for (auto id : *global.params.versionids)
{
int len = strlen(*I) + 1;
int len = strlen(id) + 1;
if (col + len > 80)
{
col = 10;
fprintf(global.stdmsg, "\n ");
}
col += len;
fprintf(global.stdmsg, " %s", *I);
fprintf(global.stdmsg, " %s", id);
}
fprintf(global.stdmsg, "\n");
}

View file

@ -289,7 +289,7 @@ static void addMipsABI(const llvm::Triple &triple, std::vector<std::string> &att
triple.getArch() == llvm::Triple::mips64el;
const uint32_t defaultABI = is64Bit ? N64 : O32;
uint32_t bits = defaultABI;
std::vector<std::string>::iterator I = attrs.begin();
auto I = attrs.begin();
while (I != attrs.end())
{
std::string str = *I;
@ -343,8 +343,7 @@ const llvm::Target *lookupTarget(const std::string &arch, llvm::Triple &triple,
for (const llvm::Target &T : llvm::TargetRegistry::targets())
{
#else
for (llvm::TargetRegistry::iterator it = llvm::TargetRegistry::begin(),
ie = llvm::TargetRegistry::end(); it != ie; ++it)
for (auto it = llvm::TargetRegistry::begin(), ie = llvm::TargetRegistry::end(); it != ie; ++it)
{
const llvm::Target& T = *it;
#endif
@ -435,10 +434,8 @@ llvm::TargetMachine* createTargetMachine(
llvm::StringMap<bool> hostFeatures;
if (llvm::sys::getHostCPUFeatures(hostFeatures))
{
llvm::StringMapConstIterator<bool> i = hostFeatures.begin(),
end = hostFeatures.end();
for (; i != end; ++i)
features.AddFeature(std::string((i->second ? "+" : "-")).append(i->first()));
for (const auto& hf : hostFeatures)
features.AddFeature(std::string(hf.second ? "+" : "-").append(hf.first()));
}
}
#if LDC_LLVM_VER < 307

View file

@ -18,10 +18,8 @@ int executeToolAndWait(const std::string &tool, std::vector<std::string> const &
std::vector<const char *> realargs;
realargs.reserve(args.size() + 2);
realargs.push_back(tool.c_str());
for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
{
realargs.push_back((*it).c_str());
}
for (const auto& arg : args)
realargs.push_back(arg.c_str());
realargs.push_back(NULL);
// Print command line if requested

View file

@ -54,12 +54,10 @@ struct AArch64TargetABI : TargetABI
void rewriteFunctionType(TypeFunction* t, IrFuncTy& fty)
{
for (IrFuncTy::ArgIter I = fty.args.begin(), E = fty.args.end(); I != E; ++I)
for (auto arg : fty.args)
{
IrFuncTyArg& arg = **I;
if (!arg.byref)
rewriteArgument(fty, arg);
if (!arg->byref)
rewriteArgument(fty, *arg);
}
}

View file

@ -49,12 +49,10 @@ struct MIPS64TargetABI : TargetABI {
void rewriteFunctionType(TypeFunction* tf, IrFuncTy &fty)
{
for (IrFuncTy::ArgIter I = fty.args.begin(), E = fty.args.end(); I != E; ++I)
for (auto arg : fty.args)
{
IrFuncTyArg& arg = **I;
if (!arg.byref)
rewriteArgument(fty, arg);
if (!arg->byref)
rewriteArgument(fty, *arg);
}
}

View file

@ -50,12 +50,10 @@ struct PPC64TargetABI : TargetABI {
void rewriteFunctionType(TypeFunction* tf, IrFuncTy &fty)
{
// EXPLICIT PARAMETERS
for (IrFuncTy::ArgIter I = fty.args.begin(), E = fty.args.end(); I != E; ++I)
for (auto arg : fty.args)
{
IrFuncTyArg& arg = **I;
if (!arg.byref)
rewriteArgument(fty, arg);
if (!arg->byref)
rewriteArgument(fty, *arg);
}
}

View file

@ -127,12 +127,10 @@ void Win64TargetABI::rewriteFunctionType(TypeFunction* tf, IrFuncTy &fty)
rewriteArgument(fty, *fty.ret);
// EXPLICIT PARAMETERS
for (IrFuncTy::ArgIter I = fty.args.begin(), E = fty.args.end(); I != E; ++I)
for (auto arg : fty.args)
{
IrFuncTyArg& arg = **I;
if (!arg.byref)
rewriteArgument(fty, arg);
if (!arg->byref)
rewriteArgument(fty, *arg);
}
// extern(D): reverse parameter order for non variadics, for DMD-compliance

View file

@ -68,8 +68,8 @@ namespace {
abiTy = i1ToI8(abiTy);
} else {
std::vector<LLType*> parts;
for (Array<Parameter*>::iterator I = argTypes->arguments->begin(), E = argTypes->arguments->end(); I != E; ++I) {
LLType* partType = DtoType((*I)->type);
for (auto param : *argTypes->arguments) {
LLType* partType = DtoType(param->type);
// round up the DMD argtype for an eightbyte of a struct to a corresponding 64-bit type
// this makes sure that 64 bits of the chosen register are used and thus
// makes sure all potential padding bytes of a struct are copied

View file

@ -248,18 +248,16 @@ struct IntrinsicABI : TargetABI
Logger::println("Intrinsic ABI: Transforming arguments");
LOG_SCOPE;
for (IrFuncTy::ArgIter I = fty.args.begin(), E = fty.args.end(); I != E; ++I) {
IrFuncTyArg& arg = **I;
IF_LOG Logger::cout() << "Arg: " << arg.type->toChars() << '\n';
for (auto arg : fty.args) {
IF_LOG Logger::cout() << "Arg: " << arg->type->toChars() << '\n';
// Arguments that are in memory are of no interest to us.
if (arg.byref)
if (arg->byref)
continue;
rewriteArgument(fty, arg);
rewriteArgument(fty, *arg);
IF_LOG Logger::cout() << "New arg type: " << *arg.ltype << '\n';
IF_LOG Logger::cout() << "New arg type: " << *arg->ltype << '\n';
}
}
};

View file

@ -210,7 +210,7 @@ void AsmStatement_toIR(AsmStatement *stmt, IRState * irs)
assert(code->args.size() <= 10);
std::vector<AsmArg>::iterator arg = code->args.begin();
auto arg = code->args.begin();
for (unsigned i = 0; i < code->args.size(); i++, ++arg) {
bool is_input = true;
LLValue* arg_val = 0;
@ -301,9 +301,8 @@ void AsmStatement_toIR(AsmStatement *stmt, IRState * irs)
}
bool pct = false;
std::string::iterator
p = code->insnTemplate.begin(),
q = code->insnTemplate.end();
auto p = code->insnTemplate.begin();
auto q = code->insnTemplate.end();
//printf("start: %.*s\n", code->insnTemplateLen, code->insnTemplate);
while (p < q) {
if (pct) {
@ -320,30 +319,29 @@ void AsmStatement_toIR(AsmStatement *stmt, IRState * irs)
++p;
}
typedef std::vector<std::string>::iterator It;
IF_LOG {
Logger::cout() << "final asm: " << code->insnTemplate << '\n';
std::ostringstream ss;
ss << "GCC-style output constraints: {";
for (It i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i) {
ss << " " << *i;
for (const auto& oc : output_constraints) {
ss << " " << oc;
}
ss << " }";
Logger::println("%s", ss.str().c_str());
ss.str("");
ss << "GCC-style input constraints: {";
for (It i = input_constraints.begin(), e = input_constraints.end(); i != e; ++i) {
ss << " " << *i;
for (const auto& ic : input_constraints) {
ss << " " << ic;
}
ss << " }";
Logger::println("%s", ss.str().c_str());
ss.str("");
ss << "GCC-style clobbers: {";
for (It i = clobbers.begin(), e = clobbers.end(); i != e; ++i) {
ss << " " << *i;
for (const auto& c : clobbers) {
ss << " " << c;
}
ss << " }";
Logger::println("%s", ss.str().c_str());
@ -353,16 +351,16 @@ void AsmStatement_toIR(AsmStatement *stmt, IRState * irs)
std::string llvmOutConstraints;
std::string llvmInConstraints;
int n = 0;
for(It i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i, ++n) {
for (auto& oc : output_constraints) {
// rewrite update constraint to in and out constraints
if((*i)[0] == '+') {
assert(*i == mrw_cns && "What else are we updating except memory?");
if(oc[0] == '+') {
assert(oc == mrw_cns && "What else are we updating except memory?");
/* LLVM doesn't support updating operands, so split into an input
* and an output operand.
*/
// Change update operand to pure output operand.
*i = mw_cns;
oc = mw_cns;
// Add input operand with same value, with original as "matching output".
std::ostringstream ss;
@ -371,38 +369,37 @@ void AsmStatement_toIR(AsmStatement *stmt, IRState * irs)
input_constraints.push_back(ss.str());
input_values.push_back(output_values[n]);
}
llvmOutConstraints += *i;
llvmOutConstraints += oc;
llvmOutConstraints += ",";
}
asmblock->outputcount += n;
for(It i = input_constraints.begin(), e = input_constraints.end(); i != e; ++i) {
llvmInConstraints += *i;
for (const auto& ic : input_constraints) {
llvmInConstraints += ic;
llvmInConstraints += ",";
}
std::string clobstr;
for(It i = clobbers.begin(), e = clobbers.end(); i != e; ++i) {
clobstr = "~{" + *i + "},";
for (const auto& c : clobbers) {
clobstr = "~{" + c + "},";
asmblock->clobs.insert(clobstr);
}
IF_LOG {
typedef std::vector<LLValue*>::iterator It;
{
Logger::println("Output values:");
LOG_SCOPE
size_t i = 0;
for (It I = output_values.begin(), E = output_values.end(); I != E; ++I) {
Logger::cout() << "Out " << i++ << " = " << **I << '\n';
for (auto ov : output_values) {
Logger::cout() << "Out " << i++ << " = " << *ov << '\n';
}
}
{
Logger::println("Input values:");
LOG_SCOPE
size_t i = 0;
for (It I = input_values.begin(), E = input_values.end(); I != E; ++I) {
Logger::cout() << "In " << i++ << " = " << **I << '\n';
for (auto iv : input_values) {
Logger::cout() << "In " << i++ << " = " << *iv << '\n';
}
}
}
@ -541,8 +538,8 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState* p)
std::vector<Identifier*>::const_iterator it, end;
end = asmblock->internalLabels.end();
bool skip = false;
for(it = asmblock->internalLabels.begin(); it != end; ++it)
if((*it)->equals(a->isBranchToLabel->ident))
for(auto il : asmblock->internalLabels)
if(il->equals(a->isBranchToLabel->ident))
skip = true;
if(skip)
continue;
@ -657,10 +654,9 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState* p)
out_c += in_c;
// append clobbers
typedef std::set<std::string>::iterator clobs_it;
for (clobs_it i=asmblock->clobs.begin(); i!=asmblock->clobs.end(); ++i)
for (const auto& c : asmblock->clobs)
{
out_c += *i;
out_c += c;
}
// remove excessive comma
@ -693,11 +689,13 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState* p)
IF_LOG {
Logger::cout() << "Arguments:" << '\n';
Logger::indent();
for (std::vector<LLValue*>::iterator b = args.begin(), i = b, e = args.end(); i != e; ++i) {
size_t i = 0;
for (auto arg : args) {
Stream cout = Logger::cout();
cout << '$' << (i - b) << " ==> " << **i;
if (!llvm::isa<llvm::Instruction>(*i) && !llvm::isa<LLGlobalValue>(*i))
cout << '$' << i << " ==> " << *arg;
if (!llvm::isa<llvm::Instruction>(arg) && !llvm::isa<LLGlobalValue>(arg))
cout << '\n';
++i;
}
Logger::undent();
}
@ -735,14 +733,13 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState* p)
llvm::SwitchInst* sw = p->ir->CreateSwitch(val, bb, gotoToVal.size());
// add all cases
std::map<LabelDsymbol*, int>::iterator it, end = gotoToVal.end();
for(it = gotoToVal.begin(); it != end; ++it)
for (const auto& pair : gotoToVal)
{
llvm::BasicBlock* casebb = llvm::BasicBlock::Create(gIR->context(), "case", p->topfunc(), bb);
sw->addCase(LLConstantInt::get(llvm::IntegerType::get(gIR->context(), 32), it->second), casebb);
sw->addCase(LLConstantInt::get(llvm::IntegerType::get(gIR->context(), 32), pair.second), casebb);
p->scope() = IRScope(casebb);
DtoGoto(stmt->loc, it->first);
DtoGoto(stmt->loc, pair.first);
}
p->scope() = IRScope(bb);

View file

@ -32,9 +32,8 @@ MultiSetter::MultiSetter(bool invert, bool* p, ...) {
}
void MultiSetter::operator=(bool val) {
typedef std::vector<bool*>::iterator It;
for (It I = locations.begin(), E = locations.end(); I != E; ++I) {
**I = (val != invert);
for (auto& l : locations) {
*l = (val != invert);
}
}

View file

@ -113,16 +113,15 @@ namespace opts {
// parse - Return true on error.
bool parse(cl::Option& O, llvm::StringRef ArgName, llvm::StringRef Arg, DataType& Val) {
typedef typename llvm::SmallVector<std::pair<std::string, DataType>, 2>::iterator It;
for (It I = switches.begin(), E = switches.end(); I != E; ++I) {
llvm::StringRef name = I->first;
for (const auto& pair : switches) {
const auto& name = pair.first;
if (name == ArgName
|| (name.size() < ArgName.size()
&& ArgName.substr(0, name.size()) == name
&& ArgName[name.size()] == '=')) {
if (!parse(owner(), Arg, Val))
{
Val = (Val == I->second) ? FlagParserDataType<DataType>::true_val() : FlagParserDataType<DataType>::false_val();
Val = (Val == pair.second) ? FlagParserDataType<DataType>::true_val() : FlagParserDataType<DataType>::false_val();
return false;
}
// Invalid option value
@ -133,8 +132,7 @@ namespace opts {
}
void getExtraOptionNames(llvm::SmallVectorImpl<const char*>& Names) {
typedef typename llvm::SmallVector<std::pair<std::string, DataType>, 2>::iterator It;
for (It I = switches.begin() + 1, E = switches.end(); I != E; ++I) {
for (auto I = switches.begin() + 1, E = switches.end(); I != E; ++I) {
Names.push_back(I->first.data());
}
}

View file

@ -42,11 +42,9 @@ void DtoResolveClass(ClassDeclaration* cd)
LOG_SCOPE;
// make sure the base classes are processed first
for (BaseClasses::iterator I = cd->baseclasses->begin(),
E = cd->baseclasses->end();
I != E; ++I)
for (auto bc : *cd->baseclasses)
{
DtoResolveClass((*I)->base);
DtoResolveClass(bc->base);
}
// make sure type exists
@ -56,11 +54,8 @@ void DtoResolveClass(ClassDeclaration* cd)
IrAggr* irAggr = getIrAggr(cd, true);
// make sure all fields really get their ir field
for (VarDeclarations::iterator I = cd->fields.begin(),
E = cd->fields.end();
I != E; ++I)
for (auto vd : cd->fields)
{
VarDeclaration* vd = *I;
IF_LOG {
if (isIrFieldCreated(vd))
Logger::println("class field already exists");

View file

@ -163,12 +163,8 @@ public:
decl->ir.setDefined();
// Emit any members (e.g. final functions).
for (Dsymbols::iterator I = decl->members->begin(),
E = decl->members->end();
I != E; ++I)
{
(*I)->accept(this);
}
for (auto m : *decl->members)
m->accept(this);
// Emit TypeInfo.
DtoTypeInfoOf(decl->type);
@ -203,12 +199,8 @@ public:
DtoResolveStruct(decl);
decl->ir.setDefined();
for (Dsymbols::iterator I = decl->members->begin(),
E = decl->members->end();
I != E; ++I)
{
(*I)->accept(this);
}
for (auto m : *decl->members)
m->accept(this);
// Define the __initZ symbol.
IrAggr *ir = getIrAggr(decl);
@ -251,12 +243,8 @@ public:
DtoResolveClass(decl);
decl->ir.setDefined();
for (Dsymbols::iterator I = decl->members->begin(),
E = decl->members->end();
I != E; ++I)
{
(*I)->accept(this);
}
for (auto m : *decl->members)
m->accept(this);
IrAggr *ir = getIrAggr(decl);
const LinkageWithCOMDAT lwc = DtoLinkage(decl);
@ -292,11 +280,9 @@ public:
assert(decl->isexp);
assert(decl->objects);
for (Objects::iterator I = decl->objects->begin(),
E = decl->objects->end();
I != E; ++I)
for (auto o : *decl->objects)
{
DsymbolExp *exp = static_cast<DsymbolExp *>(*I);
DsymbolExp *exp = static_cast<DsymbolExp *>(o);
assert(exp->op == TOKdsymbol);
exp->s->accept(this);
}
@ -426,12 +412,8 @@ public:
if (!isError(decl) && decl->members)
{
for (Dsymbols::iterator I = decl->members->begin(),
E = decl->members->end();
I != E; ++I)
{
(*I)->accept(this);
}
for (auto m : *decl->members)
m->accept(this);
}
}
@ -446,12 +428,8 @@ public:
if (!isError(decl) && decl->members)
{
for (Dsymbols::iterator I = decl->members->begin(),
E = decl->members->end();
I != E; ++I)
{
(*I)->accept(this);
}
for (auto m : *decl->members)
m->accept(this);
}
}
@ -462,12 +440,8 @@ public:
if (d)
{
for (Dsymbols::iterator I = d->begin(),
E = d->end();
I != E; ++I)
{
(*I)->accept(this);
}
for (auto s : *d)
s->accept(this);
}
}

View file

@ -178,18 +178,12 @@ ldc::DIType ldc::DIBuilder::CreateEnumType(Type *type)
#else
llvm::SmallVector<llvm::Value *, 8> subscripts;
#endif
for (Dsymbols::iterator I = te->sym->members->begin(),
E = te->sym->members->end();
I != E; ++I)
for (auto m : *te->sym->members)
{
EnumMember *em = (*I)->isEnumMember();
EnumMember *em = m->isEnumMember();
llvm::StringRef Name(em->toChars());
uint64_t Val = em->value->toInteger();
#if LDC_LLVM_VER >= 306
llvm::Metadata *Subscript = DBuilder.createEnumerator(Name, Val);
#else
llvm::Value *Subscript = DBuilder.createEnumerator(Name, Val);
#endif
auto Subscript = DBuilder.createEnumerator(Name, Val);
subscripts.push_back(Subscript);
}
@ -312,14 +306,9 @@ void ldc::DIBuilder::AddBaseFields(ClassDeclaration *sd, ldc::DIFile file,
size_t narr = sd->fields.dim;
elems.reserve(narr);
for (VarDeclarations::iterator I = sd->fields.begin(),
E = sd->fields.end();
I != E; ++I)
{
VarDeclaration* vd = *I;
for (auto vd : sd->fields)
elems.push_back(CreateMemberType(vd->loc.linnum, vd->type, file, vd->toChars(), vd->offset, vd->prot().kind));
}
}
ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type)
{
@ -389,11 +378,8 @@ ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type)
if (t->ty == Tstruct)
{
elems.reserve(sd->fields.dim);
for (VarDeclarations::iterator I = sd->fields.begin(),
E = sd->fields.end();
I != E; ++I)
for (auto vd : sd->fields)
{
VarDeclaration* vd = *I;
ldc::DIType dt = CreateMemberType(vd->loc.linnum, vd->type, file, vd->toChars(), vd->offset, vd->prot().kind);
elems.push_back(dt);
}
@ -845,7 +831,7 @@ void ldc::DIBuilder::EmitStopPoint(Loc& loc)
void ldc::DIBuilder::EmitValue(llvm::Value *val, VarDeclaration *vd)
{
IrFunction::VariableMap::iterator sub = IR->func()->variableMap.find(vd);
auto sub = IR->func()->variableMap.find(vd);
if (sub == IR->func()->variableMap.end())
return;
@ -879,8 +865,8 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
Logger::println("D to dwarf local variable");
LOG_SCOPE;
IrFunction::VariableMap& variableMap = IR->func()->variableMap;
IrFunction::VariableMap::iterator sub = variableMap.find(vd);
auto& variableMap = IR->func()->variableMap;
auto sub = variableMap.find(vd);
if (sub != variableMap.end())
return; // ensure that the debug variable is created only once

View file

@ -61,10 +61,9 @@ static llvm::cl::opt<bool> fqnNames("oq",
static void check_and_add_output_file(Module* NewMod, const std::string& str)
{
typedef std::map<std::string, Module*> map_t;
static map_t files;
static std::map<std::string, Module*> files;
map_t::iterator i = files.find(str);
auto i = files.find(str);
if (i != files.end()) {
Module* ThisMod = i->second;
error(Loc(), "Output file '%s' for module '%s' collides with previous module '%s'. See the -oq option",
@ -190,9 +189,8 @@ static llvm::Function* build_module_function(const std::string &name, const std:
}
// Call ctor's
typedef std::list<FuncDeclaration*>::const_iterator FuncIterator;
for (FuncIterator itr = funcs.begin(), end = funcs.end(); itr != end; ++itr) {
llvm::Function* f = getIrFunc(*itr)->func;
for (auto func : funcs) {
llvm::Function* f = getIrFunc(func)->func;
#if LDC_LLVM_VER >= 307
llvm::CallInst* call = builder.CreateCall(f, {});
#else
@ -206,10 +204,9 @@ static llvm::Function* build_module_function(const std::string &name, const std:
}
// Increment vgate's
typedef std::list<VarDeclaration*>::const_iterator GatesIterator;
for (GatesIterator itr = gates.begin(), end = gates.end(); itr != end; ++itr) {
assert(getIrGlobal(*itr));
llvm::Value* val = getIrGlobal(*itr)->value;
for (auto gate : gates) {
assert(getIrGlobal(gate));
llvm::Value* val = getIrGlobal(gate)->value;
llvm::Value* rval = builder.CreateLoad(val, "vgate");
llvm::Value* res = builder.CreateAdd(rval, DtoConstUint(1), "vgate");
builder.CreateStore(res, val);
@ -563,11 +560,8 @@ static void build_llvm_used_array(IRState* p)
std::vector<llvm::Constant*> usedVoidPtrs;
usedVoidPtrs.reserve(p->usedArray.size());
for (std::vector<llvm::Constant*>::iterator it = p->usedArray.begin(),
end = p->usedArray.end(); it != end; ++it)
{
usedVoidPtrs.push_back(DtoBitCast(*it, getVoidPtrType()));
}
for (auto constant : p->usedArray)
usedVoidPtrs.push_back(DtoBitCast(constant, getVoidPtrType()));
llvm::ArrayType *arrayType = llvm::ArrayType::get(
getVoidPtrType(), usedVoidPtrs.size());

View file

@ -57,14 +57,9 @@ public:
LOG_SCOPE;
if (stmt->statements)
for (Statements::iterator I = stmt->statements->begin(),
E = stmt->statements->end();
I != E; ++I)
{
Statement *s = *I;
for (auto s : *stmt->statements)
if (s) s->accept(this);
}
}
//////////////////////////////////////////////////////////////////////////

View file

@ -377,12 +377,8 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd)
// Add the direct nested variables of this function, and update their indices to match.
// TODO: optimize ordering for minimal space usage?
for (VarDeclarations::iterator I = fd->closureVars.begin(),
E = fd->closureVars.end();
I != E; ++I)
for (auto vd : fd->closureVars)
{
VarDeclaration* vd = *I;
unsigned alignment = DtoAlignment(vd);
if (alignment > 1)
builder.alignCurrentOffset(alignment);
@ -508,11 +504,7 @@ void DtoCreateNestedContext(FuncDeclaration* fd) {
irfunction->nestedVar = frame;
// go through all nested vars and assign addresses where possible.
for (VarDeclarations::iterator I = fd->closureVars.begin(),
E = fd->closureVars.end();
I != E; ++I) {
VarDeclaration *vd = *I;
for (auto vd : fd->closureVars) {
if (needsClosure && vd->needsAutoDtor()) {
// This should really be a front-end, not a glue layer error,
// but we need to fix this in DMD too.

View file

@ -402,8 +402,8 @@ bool ldc_optimize_module(llvm::Module *M)
// Run per-function passes.
fpm.doInitialization();
for (llvm::Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
fpm.run(*F);
for (auto& F : *M)
fpm.run(F);
fpm.doFinalization();
// Run per-module passes.

View file

@ -473,8 +473,8 @@ bool GarbageCollect2Stack::runOnFunction(Function &F) {
IRBuilder<> AllocaBuilder(&Entry, Entry.begin());
bool Changed = false;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
for (auto& BB : F) {
for (auto I = BB.begin(), E = BB.end(); I != E; ) {
// Ignore non-calls.
Instruction* Inst = I++;
CallSite CS(Inst);
@ -487,8 +487,7 @@ bool GarbageCollect2Stack::runOnFunction(Function &F) {
continue;
// Ignore unknown calls.
StringMap<FunctionInfo*>::iterator OMI =
KnownFunctions.find(Callee->getName());
auto OMI = KnownFunctions.find(Callee->getName());
if (OMI == KnownFunctions.end()) continue;
FunctionInfo* info = OMI->getValue();
@ -517,12 +516,10 @@ bool GarbageCollect2Stack::runOnFunction(Function &F) {
// First demote tail calls which use the value so there IR is never
// in an invalid state.
SmallVector<CallInst*, 4>::iterator it, end = RemoveTailCallInsts.end();
for (it = RemoveTailCallInsts.begin(); it != end; ++it) {
(*it)->setTailCall(false);
}
for (auto i : RemoveTailCallInsts)
i->setTailCall(false);
IRBuilder<> Builder(BB, Inst);
IRBuilder<> Builder(&BB, Inst);
Value* newVal = info->promote(CS, Builder, A);
DEBUG(errs() << "Promoted to: " << *newVal);

View file

@ -377,26 +377,25 @@ bool SimplifyDRuntimeCalls::runOnce(Function &F, const DataLayout *DL, AliasAnal
IRBuilder<> Builder(F.getContext());
bool Changed = false;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
for (auto& BB : F) {
for (auto I = BB.begin(); I != BB.end(); ) {
// Ignore non-calls.
CallInst *CI = dyn_cast<CallInst>(I++);
if (!CI) continue;
// Ignore indirect calls and calls to non-external functions.
Function *Callee = CI->getCalledFunction();
if (Callee == 0 || !Callee->isDeclaration() || !Callee->hasExternalLinkage())
if (Callee == nullptr || !Callee->isDeclaration() || !Callee->hasExternalLinkage())
continue;
// Ignore unknown calls.
StringMap<LibCallOptimization*>::iterator OMI =
Optimizations.find(Callee->getName());
auto OMI = Optimizations.find(Callee->getName());
if (OMI == Optimizations.end()) continue;
DEBUG(errs() << "SimplifyDRuntimeCalls inspecting: " << *CI);
// Set the builder to the instruction after the call.
Builder.SetInsertPoint(BB, I);
Builder.SetInsertPoint(&BB, I);
// Try to optimize this call.
#if LDC_LLVM_VER >= 308

View file

@ -50,14 +50,14 @@ ModulePass *createStripExternalsPass() { return new StripExternals(); }
bool StripExternals::runOnModule(Module &M) {
bool Changed = false;
for (Module::iterator I = M.begin(); I != M.end(); ) {
for (auto I = M.begin(); I != M.end(); ) {
if (I->hasAvailableExternallyLinkage()) {
assert(!I->isDeclaration()&&"Declarations can't be available_externally");
Changed = true;
++NumFunctions;
if (I->use_empty()) {
DEBUG(errs() << "Deleting function: " << *I);
Module::iterator todelete = I;
auto todelete = I;
++I;
todelete->eraseFromParent();
continue;

View file

@ -114,11 +114,8 @@ public:
IF_LOG Logger::println("CompoundStatement::toIR(): %s", stmt->loc.toChars());
LOG_SCOPE;
for (Statements::iterator I = stmt->statements->begin(),
E = stmt->statements->end();
I != E; ++I)
for (auto s : *stmt->statements)
{
Statement *s = *I;
if (s) {
s->accept(this);
}
@ -777,13 +774,11 @@ public:
// Only after emitting all the catch bodies, register the catch scopes.
// This is so that (re)throwing inside a catch does not match later
// catches.
for (CatchBlocks::iterator it = catchBlocks.begin(),
end = catchBlocks.end();
it != end; ++it
) {
DtoResolveClass(it->first);
for (const auto& pair : catchBlocks)
{
DtoResolveClass(pair.first);
irs->func()->scopes->pushCatch(
getIrAggr(it->first)->getClassInfoSymbol(), it->second);
getIrAggr(pair.first)->getClassInfoSymbol(), pair.second);
}
// Emit the try block.
@ -848,12 +843,9 @@ public:
// 'switch' instruction (that can happen because D2 allows to
// initialize a global variable in a static constructor).
bool useSwitchInst = true;
for (CaseStatements::iterator I = stmt->cases->begin(),
E = stmt->cases->end();
I != E; ++I)
for (auto cs : *stmt->cases)
{
CaseStatement *cs = *I;
VarDeclaration* vd = 0;
VarDeclaration* vd = nullptr;
if (cs->exp->op == TOKvar)
vd = static_cast<VarExp*>(cs->exp)->var->isVarDeclaration();
if (vd && (!vd->init || !vd->isConst())) {
@ -945,14 +937,9 @@ public:
// create switch and add the cases
llvm::SwitchInst* si = llvm::SwitchInst::Create(condVal, defbb ? defbb : endbb, stmt->cases->dim, irs->scopebb());
for (CaseStatements::iterator I = stmt->cases->begin(),
E = stmt->cases->end();
I != E; ++I)
{
CaseStatement *cs = *I;
for (auto cs : *stmt->cases)
si->addCase(isaConstantInt(cs->llvmIdx), cs->bodyBB);
}
}
else
{ // we can't use switch, so we will use a bunch of br instructions instead
DValue* cond = toElemDtor(stmt->condition);
@ -962,12 +949,8 @@ public:
llvm::BranchInst::Create(nextbb, irs->scopebb());
irs->scope() = IRScope(nextbb);
for (CaseStatements::iterator I = stmt->cases->begin(),
E = stmt->cases->end();
I != E; ++I)
for (auto cs : *stmt->cases)
{
CaseStatement *cs = *I;
LLValue *cmp = irs->ir->CreateICmp(llvm::ICmpInst::ICMP_EQ, cs->llvmIdx, condVal, "checkcase");
nextbb = llvm::BasicBlock::Create(irs->context(), "checkcase", irs->topfunc());
llvm::BranchInst::Create(cs->bodyBB, nextbb, cmp, irs->scopebb());

View file

@ -56,11 +56,8 @@ void DtoResolveStruct(StructDeclaration* sd, Loc& callerLoc)
getIrAggr(sd, true);
// Set up our field metadata.
for (VarDeclarations::iterator I = sd->fields.begin(),
E = sd->fields.end();
I != E; ++I)
for (auto vd : sd->fields)
{
VarDeclaration *vd = *I;
IF_LOG {
if (isIrFieldCreated(vd))
Logger::println("struct field already exists");
@ -105,7 +102,7 @@ LLType* DtoUnpaddedStructType(Type* dty) {
typedef llvm::DenseMap<Type*, llvm::StructType*> CacheT;
static llvm::ManagedStatic<CacheT> cache;
CacheT::iterator it = cache->find(dty);
auto it = cache->find(dty);
if (it != cache->end())
return it->second;

View file

@ -2689,13 +2689,12 @@ public:
llvm::Type* elementType = NULL;
bool differentTypes = false;
for (std::vector<llvm::Constant*>::iterator i = vals.begin(), end = vals.end();
i != end; ++i)
for (auto v : vals)
{
if (!elementType)
elementType = (*i)->getType();
elementType = v->getType();
else
differentTypes |= (elementType != (*i)->getType());
differentTypes |= (elementType != v->getType());
}
if (differentTypes)

View file

@ -197,11 +197,10 @@ llvm::Constant* IrAggr::createInitializerConstant(
// get initializer type
if (!initializerType || initializerType->isOpaque())
{
llvm::SmallVector<llvm::Constant*, 16>::iterator itr, end = constants.end();
llvm::SmallVector<llvm::Type*, 16> types;
types.reserve(constants.size());
for (itr = constants.begin(); itr != end; ++itr)
types.push_back((*itr)->getType());
for (auto c : constants)
types.push_back(c->getType());
if (!initializerType)
initializerType = LLStructType::get(gIR->context(), types, isPacked());
else
@ -352,16 +351,14 @@ void IrAggr::addFieldInitializers(
offset = (offset + Target::ptrsize - 1) & ~(Target::ptrsize - 1);
for (BaseClasses::iterator I = cd->vtblInterfaces->begin(),
E = cd->vtblInterfaces->end();
I != E; ++I)
for (auto bc : *cd->vtblInterfaces)
{
constants.push_back(getInterfaceVtbl(*I, newinsts, inter_idx));
constants.push_back(getInterfaceVtbl(bc, newinsts, inter_idx));
offset += Target::ptrsize;
inter_idx++;
if (populateInterfacesWithVtbls)
interfacesWithVtbls.push_back(*I);
interfacesWithVtbls.push_back(bc);
}
}
}

View file

@ -273,7 +273,7 @@ LLConstant * IrAggr::getClassInfoInit()
llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance, size_t interfaces_index)
{
ClassGlobalMap::iterator it = interfaceVtblMap.find(b->base);
auto it = interfaceVtblMap.find(b->base);
if (it != interfaceVtblMap.end())
return it->second;
@ -488,7 +488,7 @@ LLConstant * IrAggr::getClassInfoInterfaces()
}
else
{
ClassGlobalMap::iterator itv = interfaceVtblMap.find(it->base);
auto itv = interfaceVtblMap.find(it->base);
assert(itv != interfaceVtblMap.end() && "interface vtbl not found");
vtb = itv->second;
vtb = DtoBitCast(vtb, voidptrptr_type);
@ -548,12 +548,10 @@ void IrAggr::initializeInterface()
if (!base->vtblInterfaces)
return;
for (BaseClasses::iterator I = base->vtblInterfaces->begin(),
E = base->vtblInterfaces->end();
I != E; ++I)
for (auto bc : *base->vtblInterfaces)
{
// add to the interface list
interfacesWithVtbls.push_back(*I);
interfacesWithVtbls.push_back(bc);
}
}

View file

@ -18,8 +18,8 @@ void IrDsymbol::resetAll()
{
Logger::println("resetting %llu Dsymbols", static_cast<unsigned long long>(list.size()));
for (std::vector<IrDsymbol*>::iterator it = list.begin(), end = list.end(); it != end; ++it)
(*it)->reset();
for (auto s : list)
s->reset();
}
IrDsymbol::IrDsymbol()
@ -44,7 +44,7 @@ IrDsymbol::~IrDsymbol()
return;
}
std::vector<IrDsymbol*>::iterator it = std::find(list.rbegin(), list.rend(), this).base();
auto it = std::find(list.rbegin(), list.rend(), this).base();
// base() returns the iterator _after_ the found position
list.erase(--it);
}

View file

@ -48,12 +48,11 @@ void executeCleanup(IRState* irs, CleanupScope& scope,
// Now we also need to store 0 to it to keep the paths that go to the
// only existing branch target the same.
std::vector<llvm::BasicBlock*>& v = scope.exitTargets.front().sourceBlocks;
for (std::vector<llvm::BasicBlock*>::iterator it = v.begin(), end = v.end();
it != end; ++it
) {
auto& v = scope.exitTargets.front().sourceBlocks;
for (auto bb : v)
{
new llvm::StoreInst(DtoConstUint(0), scope.branchSelector,
(*it)->getTerminator());
bb->getTerminator());
}
// And convert the BranchInst to the existing branch target to a
@ -110,12 +109,8 @@ ScopeStack::~ScopeStack() {
// down or "sideways" (i.e. down another branch) of the tree of all
// cleanup scopes, both of which are not allowed in D.
if (!topLevelUnresolvedGotos.empty()) {
for (std::vector<GotoJump>::iterator it = topLevelUnresolvedGotos.begin(),
end = topLevelUnresolvedGotos.end();
it != end; ++it
) {
error(it->sourceLoc, "goto into try/finally scope is not allowed");
}
for (const auto& i : topLevelUnresolvedGotos)
error(i.sourceLoc, "goto into try/finally scope is not allowed");
fatal();
}
}
@ -160,17 +155,15 @@ void ScopeStack::popCleanups(CleanupCursor targetScope) {
for (CleanupCursor i = currentCleanupScope(); i-- > targetScope;) {
// Any gotos that are still unresolved necessarily leave this scope.
// Thus, the cleanup needs to be executed.
for (std::vector<GotoJump>::iterator it = currentUnresolvedGotos().begin(),
end = currentUnresolvedGotos().end();
it != end; ++it
) {
for (const auto& gotoJump : currentUnresolvedGotos())
{
// Make the source resp. last cleanup branch to this one.
llvm::BasicBlock* tentative = it->tentativeTarget;
llvm::BasicBlock* tentative = gotoJump.tentativeTarget;
tentative->replaceAllUsesWith(cleanupScopes[i].beginBlock);
// And continue execution with the tentative target (we simply reuse
// it because there is no reason not to).
executeCleanup(irs, cleanupScopes[i], it->sourceBlock, tentative);
executeCleanup(irs, cleanupScopes[i], gotoJump.sourceBlock, tentative);
}
@ -244,7 +237,7 @@ void ScopeStack::addLabelTarget(Identifier* labelName,
void ScopeStack::jumpToLabel(Loc loc, Identifier* labelName) {
// If we have already seen that label, branch to it, executing any cleanups
// as necessary.
LabelTargetMap::iterator it = labelTargets.find(labelName);
auto it = labelTargets.find(labelName);
if (it != labelTargets.end()) {
runCleanups(it->second.cleanupScope, it->second.targetBlock);
return;

View file

@ -102,12 +102,8 @@ struct IrFuncTy
// typedef llvm::SmallVector<IrFuncTyArg*, 4> ArgList;
#if defined(_MSC_VER)
typedef Array<IrFuncTyArg *> ArgList;
typedef ArgList::iterator ArgIter;
typedef ArgList::reverse_iterator ArgRIter;
#else
typedef std::vector<IrFuncTyArg*> ArgList;
typedef ArgList::iterator ArgIter;
typedef ArgList::reverse_iterator ArgRIter;
#endif
ArgList args;

View file

@ -59,11 +59,8 @@ void IrTypeClass::addBaseClassData(AggrTypeBuilder &builder, ClassDeclaration *b
// align offset
builder.alignCurrentOffset(Target::ptrsize);
for (BaseClasses::iterator I = base->vtblInterfaces->begin(),
E = base->vtblInterfaces->end();
I != E; ++I)
for (auto b : *base->vtblInterfaces)
{
BaseClass *b = *I;
IF_LOG Logger::println("Adding interface vtbl for %s", b->base->toPrettyChars());
FuncDeclarations arr;
@ -167,9 +164,7 @@ std::vector<llvm::Type*> IrTypeClass::buildVtblType(Type* first, FuncDeclaration
types.push_back(DtoType(first));
// then come the functions
for (FuncDeclarations::iterator I = vtbl_array->begin() + 1,
E = vtbl_array->end();
I != E; ++I)
for (auto I = vtbl_array->begin() + 1, E = vtbl_array->end(); I != E; ++I)
{
FuncDeclaration* fd = *I;
if (fd == NULL)
@ -230,7 +225,7 @@ llvm::Type * IrTypeClass::getMemoryLLType()
size_t IrTypeClass::getInterfaceIndex(ClassDeclaration * inter)
{
ClassIndexMap::iterator it = interfaceMap.find(inter);
auto it = interfaceMap.find(inter);
if (it == interfaceMap.end())
return ~0UL;
return it->second;

View file

@ -183,17 +183,8 @@ bool emit(raw_ostream& os, RecordKeeper& records)
map<string, Record*> defs = records.getDefs();
#endif
for(
#if LDC_LLVM_VER >= 306
auto it = defs.cbegin();
#else
map<string, Record* >::iterator it = defs.begin();
#endif
it != defs.end();
it++)
{
processRecord(os, *(*it).second, arch);
}
for (const auto& d : defs)
processRecord(os, *d.second, arch);
return false;
}