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

View file

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

View file

@ -123,16 +123,14 @@ void printVersion() {
// Helper function to handle -d-debug=* and -d-version=* // Helper function to handle -d-debug=* and -d-version=*
static void processVersions(std::vector<std::string>& list, const char* type, static void processVersions(std::vector<std::string>& list, const char* type,
void (*setLevel)(unsigned), void (*addIdent)(const char*)) { void (*setLevel)(unsigned), void (*addIdent)(const char*)) {
typedef std::vector<std::string>::iterator It; for (const auto& i : list) {
const char* value = i.c_str();
for(It I = list.begin(), E = list.end(); I != E; ++I) {
const char* value = I->c_str();
if (isdigit(value[0])) { if (isdigit(value[0])) {
errno = 0; errno = 0;
char* end; char* end;
long level = strtol(value, &end, 10); long level = strtol(value, &end, 10);
if (*end || errno || level > INT_MAX) { 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 { } else {
setLevel((unsigned)level); setLevel((unsigned)level);
} }
@ -142,7 +140,7 @@ static void processVersions(std::vector<std::string>& list, const char* type,
addIdent(cstr); addIdent(cstr);
continue; continue;
} else { } 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) { 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()) if (i != map.end())
{ {
cl::Option *opt = i->getValue(); cl::Option *opt = i->getValue();
@ -406,14 +404,13 @@ static void parseCommandLine(int argc, char **argv, Strings &sourceFiles, bool &
} }
sourceFiles.reserve(fileList.size()); sourceFiles.reserve(fileList.size());
typedef std::vector<std::string>::iterator It; for (const auto& file : fileList)
for(It I = fileList.begin(), E = fileList.end(); I != E; ++I)
{ {
if (!I->empty()) if (!file.empty())
{ {
char* copy = mem.xstrdup(I->c_str()); char* copy = mem.xstrdup(file.c_str());
#ifdef _WIN32 #ifdef _WIN32
std::replace(copy, copy + I->length(), '/', '\\'); std::replace(copy, copy + file.length(), '/', '\\');
#endif #endif
sourceFiles.push(copy); sourceFiles.push(copy);
} }
@ -835,18 +832,16 @@ static void dumpPredefinedVersions()
{ {
fprintf(global.stdmsg, "predefs "); fprintf(global.stdmsg, "predefs ");
int col = 10; int col = 10;
for (Strings::iterator I = global.params.versionids->begin(), for (auto id : *global.params.versionids)
E = global.params.versionids->end();
I != E; ++I)
{ {
int len = strlen(*I) + 1; int len = strlen(id) + 1;
if (col + len > 80) if (col + len > 80)
{ {
col = 10; col = 10;
fprintf(global.stdmsg, "\n "); fprintf(global.stdmsg, "\n ");
} }
col += len; col += len;
fprintf(global.stdmsg, " %s", *I); fprintf(global.stdmsg, " %s", id);
} }
fprintf(global.stdmsg, "\n"); 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; triple.getArch() == llvm::Triple::mips64el;
const uint32_t defaultABI = is64Bit ? N64 : O32; const uint32_t defaultABI = is64Bit ? N64 : O32;
uint32_t bits = defaultABI; uint32_t bits = defaultABI;
std::vector<std::string>::iterator I = attrs.begin(); auto I = attrs.begin();
while (I != attrs.end()) while (I != attrs.end())
{ {
std::string str = *I; 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()) for (const llvm::Target &T : llvm::TargetRegistry::targets())
{ {
#else #else
for (llvm::TargetRegistry::iterator it = llvm::TargetRegistry::begin(), for (auto it = llvm::TargetRegistry::begin(), ie = llvm::TargetRegistry::end(); it != ie; ++it)
ie = llvm::TargetRegistry::end(); it != ie; ++it)
{ {
const llvm::Target& T = *it; const llvm::Target& T = *it;
#endif #endif
@ -435,10 +434,8 @@ llvm::TargetMachine* createTargetMachine(
llvm::StringMap<bool> hostFeatures; llvm::StringMap<bool> hostFeatures;
if (llvm::sys::getHostCPUFeatures(hostFeatures)) if (llvm::sys::getHostCPUFeatures(hostFeatures))
{ {
llvm::StringMapConstIterator<bool> i = hostFeatures.begin(), for (const auto& hf : hostFeatures)
end = hostFeatures.end(); features.AddFeature(std::string(hf.second ? "+" : "-").append(hf.first()));
for (; i != end; ++i)
features.AddFeature(std::string((i->second ? "+" : "-")).append(i->first()));
} }
} }
#if LDC_LLVM_VER < 307 #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; std::vector<const char *> realargs;
realargs.reserve(args.size() + 2); realargs.reserve(args.size() + 2);
realargs.push_back(tool.c_str()); realargs.push_back(tool.c_str());
for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it) for (const auto& arg : args)
{ realargs.push_back(arg.c_str());
realargs.push_back((*it).c_str());
}
realargs.push_back(NULL); realargs.push_back(NULL);
// Print command line if requested // Print command line if requested

View file

@ -52,14 +52,12 @@ struct AArch64TargetABI : TargetABI
return t->toBasetype()->ty == Tstruct; return t->toBasetype()->ty == Tstruct;
} }
void rewriteFunctionType(TypeFunction* t, IrFuncTy &fty) 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) 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) void rewriteFunctionType(TypeFunction* tf, IrFuncTy &fty)
{ {
// EXPLICIT PARAMETERS // 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); rewriteArgument(fty, *fty.ret);
// EXPLICIT PARAMETERS // 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 // extern(D): reverse parameter order for non variadics, for DMD-compliance

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -178,18 +178,12 @@ ldc::DIType ldc::DIBuilder::CreateEnumType(Type *type)
#else #else
llvm::SmallVector<llvm::Value *, 8> subscripts; llvm::SmallVector<llvm::Value *, 8> subscripts;
#endif #endif
for (Dsymbols::iterator I = te->sym->members->begin(), for (auto m : *te->sym->members)
E = te->sym->members->end();
I != E; ++I)
{ {
EnumMember *em = (*I)->isEnumMember(); EnumMember *em = m->isEnumMember();
llvm::StringRef Name(em->toChars()); llvm::StringRef Name(em->toChars());
uint64_t Val = em->value->toInteger(); uint64_t Val = em->value->toInteger();
#if LDC_LLVM_VER >= 306 auto Subscript = DBuilder.createEnumerator(Name, Val);
llvm::Metadata *Subscript = DBuilder.createEnumerator(Name, Val);
#else
llvm::Value *Subscript = DBuilder.createEnumerator(Name, Val);
#endif
subscripts.push_back(Subscript); subscripts.push_back(Subscript);
} }
@ -312,13 +306,8 @@ void ldc::DIBuilder::AddBaseFields(ClassDeclaration *sd, ldc::DIFile file,
size_t narr = sd->fields.dim; size_t narr = sd->fields.dim;
elems.reserve(narr); elems.reserve(narr);
for (VarDeclarations::iterator I = sd->fields.begin(), for (auto vd : sd->fields)
E = sd->fields.end();
I != E; ++I)
{
VarDeclaration* vd = *I;
elems.push_back(CreateMemberType(vd->loc.linnum, vd->type, file, vd->toChars(), vd->offset, vd->prot().kind)); elems.push_back(CreateMemberType(vd->loc.linnum, vd->type, file, vd->toChars(), vd->offset, vd->prot().kind));
}
} }
ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type) ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type)
@ -389,11 +378,8 @@ ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type)
if (t->ty == Tstruct) if (t->ty == Tstruct)
{ {
elems.reserve(sd->fields.dim); elems.reserve(sd->fields.dim);
for (VarDeclarations::iterator I = sd->fields.begin(), for (auto vd : sd->fields)
E = sd->fields.end();
I != E; ++I)
{ {
VarDeclaration* vd = *I;
ldc::DIType dt = CreateMemberType(vd->loc.linnum, vd->type, file, vd->toChars(), vd->offset, vd->prot().kind); ldc::DIType dt = CreateMemberType(vd->loc.linnum, vd->type, file, vd->toChars(), vd->offset, vd->prot().kind);
elems.push_back(dt); elems.push_back(dt);
} }
@ -845,7 +831,7 @@ void ldc::DIBuilder::EmitStopPoint(Loc& loc)
void ldc::DIBuilder::EmitValue(llvm::Value *val, VarDeclaration *vd) 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()) if (sub == IR->func()->variableMap.end())
return; return;
@ -879,8 +865,8 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
Logger::println("D to dwarf local variable"); Logger::println("D to dwarf local variable");
LOG_SCOPE; LOG_SCOPE;
IrFunction::VariableMap& variableMap = IR->func()->variableMap; auto& variableMap = IR->func()->variableMap;
IrFunction::VariableMap::iterator sub = variableMap.find(vd); auto sub = variableMap.find(vd);
if (sub != variableMap.end()) if (sub != variableMap.end())
return; // ensure that the debug variable is created only once 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) static void check_and_add_output_file(Module* NewMod, const std::string& str)
{ {
typedef std::map<std::string, Module*> map_t; static std::map<std::string, Module*> files;
static map_t files;
map_t::iterator i = files.find(str); auto i = files.find(str);
if (i != files.end()) { if (i != files.end()) {
Module* ThisMod = i->second; Module* ThisMod = i->second;
error(Loc(), "Output file '%s' for module '%s' collides with previous module '%s'. See the -oq option", 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 // Call ctor's
typedef std::list<FuncDeclaration*>::const_iterator FuncIterator; for (auto func : funcs) {
for (FuncIterator itr = funcs.begin(), end = funcs.end(); itr != end; ++itr) { llvm::Function* f = getIrFunc(func)->func;
llvm::Function* f = getIrFunc(*itr)->func;
#if LDC_LLVM_VER >= 307 #if LDC_LLVM_VER >= 307
llvm::CallInst* call = builder.CreateCall(f, {}); llvm::CallInst* call = builder.CreateCall(f, {});
#else #else
@ -206,10 +204,9 @@ static llvm::Function* build_module_function(const std::string &name, const std:
} }
// Increment vgate's // Increment vgate's
typedef std::list<VarDeclaration*>::const_iterator GatesIterator; for (auto gate : gates) {
for (GatesIterator itr = gates.begin(), end = gates.end(); itr != end; ++itr) { assert(getIrGlobal(gate));
assert(getIrGlobal(*itr)); llvm::Value* val = getIrGlobal(gate)->value;
llvm::Value* val = getIrGlobal(*itr)->value;
llvm::Value* rval = builder.CreateLoad(val, "vgate"); llvm::Value* rval = builder.CreateLoad(val, "vgate");
llvm::Value* res = builder.CreateAdd(rval, DtoConstUint(1), "vgate"); llvm::Value* res = builder.CreateAdd(rval, DtoConstUint(1), "vgate");
builder.CreateStore(res, val); builder.CreateStore(res, val);
@ -563,11 +560,8 @@ static void build_llvm_used_array(IRState* p)
std::vector<llvm::Constant*> usedVoidPtrs; std::vector<llvm::Constant*> usedVoidPtrs;
usedVoidPtrs.reserve(p->usedArray.size()); usedVoidPtrs.reserve(p->usedArray.size());
for (std::vector<llvm::Constant*>::iterator it = p->usedArray.begin(), for (auto constant : p->usedArray)
end = p->usedArray.end(); it != end; ++it) usedVoidPtrs.push_back(DtoBitCast(constant, getVoidPtrType()));
{
usedVoidPtrs.push_back(DtoBitCast(*it, getVoidPtrType()));
}
llvm::ArrayType *arrayType = llvm::ArrayType::get( llvm::ArrayType *arrayType = llvm::ArrayType::get(
getVoidPtrType(), usedVoidPtrs.size()); getVoidPtrType(), usedVoidPtrs.size());

View file

@ -57,13 +57,8 @@ public:
LOG_SCOPE; LOG_SCOPE;
if (stmt->statements) if (stmt->statements)
for (Statements::iterator I = stmt->statements->begin(), for (auto s : *stmt->statements)
E = stmt->statements->end();
I != E; ++I)
{
Statement *s = *I;
if (s) s->accept(this); 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. // Add the direct nested variables of this function, and update their indices to match.
// TODO: optimize ordering for minimal space usage? // TODO: optimize ordering for minimal space usage?
for (VarDeclarations::iterator I = fd->closureVars.begin(), for (auto vd : fd->closureVars)
E = fd->closureVars.end();
I != E; ++I)
{ {
VarDeclaration* vd = *I;
unsigned alignment = DtoAlignment(vd); unsigned alignment = DtoAlignment(vd);
if (alignment > 1) if (alignment > 1)
builder.alignCurrentOffset(alignment); builder.alignCurrentOffset(alignment);
@ -508,11 +504,7 @@ void DtoCreateNestedContext(FuncDeclaration* fd) {
irfunction->nestedVar = frame; irfunction->nestedVar = frame;
// go through all nested vars and assign addresses where possible. // go through all nested vars and assign addresses where possible.
for (VarDeclarations::iterator I = fd->closureVars.begin(), for (auto vd : fd->closureVars) {
E = fd->closureVars.end();
I != E; ++I) {
VarDeclaration *vd = *I;
if (needsClosure && vd->needsAutoDtor()) { if (needsClosure && vd->needsAutoDtor()) {
// This should really be a front-end, not a glue layer error, // This should really be a front-end, not a glue layer error,
// but we need to fix this in DMD too. // 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. // Run per-function passes.
fpm.doInitialization(); fpm.doInitialization();
for (llvm::Module::iterator F = M->begin(), E = M->end(); F != E; ++F) for (auto& F : *M)
fpm.run(*F); fpm.run(F);
fpm.doFinalization(); fpm.doFinalization();
// Run per-module passes. // Run per-module passes.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -197,11 +197,10 @@ llvm::Constant* IrAggr::createInitializerConstant(
// get initializer type // get initializer type
if (!initializerType || initializerType->isOpaque()) if (!initializerType || initializerType->isOpaque())
{ {
llvm::SmallVector<llvm::Constant*, 16>::iterator itr, end = constants.end();
llvm::SmallVector<llvm::Type*, 16> types; llvm::SmallVector<llvm::Type*, 16> types;
types.reserve(constants.size()); types.reserve(constants.size());
for (itr = constants.begin(); itr != end; ++itr) for (auto c : constants)
types.push_back((*itr)->getType()); types.push_back(c->getType());
if (!initializerType) if (!initializerType)
initializerType = LLStructType::get(gIR->context(), types, isPacked()); initializerType = LLStructType::get(gIR->context(), types, isPacked());
else else
@ -352,16 +351,14 @@ void IrAggr::addFieldInitializers(
offset = (offset + Target::ptrsize - 1) & ~(Target::ptrsize - 1); offset = (offset + Target::ptrsize - 1) & ~(Target::ptrsize - 1);
for (BaseClasses::iterator I = cd->vtblInterfaces->begin(), for (auto bc : *cd->vtblInterfaces)
E = cd->vtblInterfaces->end();
I != E; ++I)
{ {
constants.push_back(getInterfaceVtbl(*I, newinsts, inter_idx)); constants.push_back(getInterfaceVtbl(bc, newinsts, inter_idx));
offset += Target::ptrsize; offset += Target::ptrsize;
inter_idx++; inter_idx++;
if (populateInterfacesWithVtbls) 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) 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()) if (it != interfaceVtblMap.end())
return it->second; return it->second;
@ -488,7 +488,7 @@ LLConstant * IrAggr::getClassInfoInterfaces()
} }
else else
{ {
ClassGlobalMap::iterator itv = interfaceVtblMap.find(it->base); auto itv = interfaceVtblMap.find(it->base);
assert(itv != interfaceVtblMap.end() && "interface vtbl not found"); assert(itv != interfaceVtblMap.end() && "interface vtbl not found");
vtb = itv->second; vtb = itv->second;
vtb = DtoBitCast(vtb, voidptrptr_type); vtb = DtoBitCast(vtb, voidptrptr_type);
@ -548,12 +548,10 @@ void IrAggr::initializeInterface()
if (!base->vtblInterfaces) if (!base->vtblInterfaces)
return; return;
for (BaseClasses::iterator I = base->vtblInterfaces->begin(), for (auto bc : *base->vtblInterfaces)
E = base->vtblInterfaces->end();
I != E; ++I)
{ {
// add to the interface list // 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())); 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) for (auto s : list)
(*it)->reset(); s->reset();
} }
IrDsymbol::IrDsymbol() IrDsymbol::IrDsymbol()
@ -44,7 +44,7 @@ IrDsymbol::~IrDsymbol()
return; 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 // base() returns the iterator _after_ the found position
list.erase(--it); 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 // Now we also need to store 0 to it to keep the paths that go to the
// only existing branch target the same. // only existing branch target the same.
std::vector<llvm::BasicBlock*>& v = scope.exitTargets.front().sourceBlocks; auto& v = scope.exitTargets.front().sourceBlocks;
for (std::vector<llvm::BasicBlock*>::iterator it = v.begin(), end = v.end(); for (auto bb : v)
it != end; ++it {
) {
new llvm::StoreInst(DtoConstUint(0), scope.branchSelector, new llvm::StoreInst(DtoConstUint(0), scope.branchSelector,
(*it)->getTerminator()); bb->getTerminator());
} }
// And convert the BranchInst to the existing branch target to a // 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 // down or "sideways" (i.e. down another branch) of the tree of all
// cleanup scopes, both of which are not allowed in D. // cleanup scopes, both of which are not allowed in D.
if (!topLevelUnresolvedGotos.empty()) { if (!topLevelUnresolvedGotos.empty()) {
for (std::vector<GotoJump>::iterator it = topLevelUnresolvedGotos.begin(), for (const auto& i : topLevelUnresolvedGotos)
end = topLevelUnresolvedGotos.end(); error(i.sourceLoc, "goto into try/finally scope is not allowed");
it != end; ++it
) {
error(it->sourceLoc, "goto into try/finally scope is not allowed");
}
fatal(); fatal();
} }
} }
@ -160,17 +155,15 @@ void ScopeStack::popCleanups(CleanupCursor targetScope) {
for (CleanupCursor i = currentCleanupScope(); i-- > targetScope;) { for (CleanupCursor i = currentCleanupScope(); i-- > targetScope;) {
// Any gotos that are still unresolved necessarily leave this scope. // Any gotos that are still unresolved necessarily leave this scope.
// Thus, the cleanup needs to be executed. // Thus, the cleanup needs to be executed.
for (std::vector<GotoJump>::iterator it = currentUnresolvedGotos().begin(), for (const auto& gotoJump : currentUnresolvedGotos())
end = currentUnresolvedGotos().end(); {
it != end; ++it
) {
// Make the source resp. last cleanup branch to this one. // 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); tentative->replaceAllUsesWith(cleanupScopes[i].beginBlock);
// And continue execution with the tentative target (we simply reuse // And continue execution with the tentative target (we simply reuse
// it because there is no reason not to). // 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) { void ScopeStack::jumpToLabel(Loc loc, Identifier* labelName) {
// If we have already seen that label, branch to it, executing any cleanups // If we have already seen that label, branch to it, executing any cleanups
// as necessary. // as necessary.
LabelTargetMap::iterator it = labelTargets.find(labelName); auto it = labelTargets.find(labelName);
if (it != labelTargets.end()) { if (it != labelTargets.end()) {
runCleanups(it->second.cleanupScope, it->second.targetBlock); runCleanups(it->second.cleanupScope, it->second.targetBlock);
return; return;

View file

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

View file

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

View file

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