Remove last uses of ArrayIter<>.

This commit is contained in:
kai
2014-01-12 17:57:21 +01:00
parent a831d4e11c
commit c6f856c01e
4 changed files with 56 additions and 59 deletions

View File

@@ -35,7 +35,6 @@
#include "gen/structs.h"
#include "gen/tollvm.h"
#include "gen/typeinf.h"
#include "gen/utils.h"
#include "gen/warnings.h"
#include "ir/irtypeclass.h"
#include "ir/irtypestruct.h"
@@ -3029,7 +3028,7 @@ DValue* StructLiteralExp::toElem(IRState* p)
// ready elements data
assert(elements && "struct literal has null elements");
size_t nexprs = elements->dim;
const size_t nexprs = elements->dim;
Expression **exprs = reinterpret_cast<Expression **>(elements->data);
// might be reset to an actual i8* value so only a single bitcast is emitted.
@@ -3037,13 +3036,13 @@ DValue* StructLiteralExp::toElem(IRState* p)
unsigned offset = 0;
// go through fields
ArrayIter<VarDeclaration> it(sd->fields);
for (; !it.done(); it.next())
const size_t nfields = sd->fields.dim;
for (size_t index = 0; index < nfields; ++index)
{
VarDeclaration* vd = it.get();
VarDeclaration *vd = sd->fields[index];
// get initializer expression
Expression* expr = (it.index < nexprs) ? exprs[it.index] : NULL;
Expression* expr = (index < nexprs) ? exprs[index] : NULL;
if (!expr)
{
// In case of an union, we can't simply use the default initializer.
@@ -3052,13 +3051,12 @@ DValue* StructLiteralExp::toElem(IRState* p)
// The loop will first visit variable i and then d. Since d has an
// explicit initializer, we must use this one. The solution is to
// peek at the next variables.
ArrayIter<VarDeclaration> it2(it.array, it.index+1);
for (; !it2.done(); it2.next())
for (size_t index2 = index+1; index2 < nfields; ++index2)
{
VarDeclaration* vd2 = it2.get();
VarDeclaration *vd2 = sd->fields[index2];
if (vd->offset != vd2->offset) break;
it.next(); // skip var
Expression* expr2 = (it2.index < nexprs) ? exprs[it2.index] : NULL;
++index; // skip var
Expression* expr2 = (index2 < nexprs) ? exprs[index2] : NULL;
if (expr2)
{
vd = vd2;
@@ -3088,7 +3086,7 @@ DValue* StructLiteralExp::toElem(IRState* p)
DConstValue cv(vd->type, NULL); // Only used in one branch; value is set beforehand
if (expr)
{
IF_LOG Logger::println("expr %zu = %s", it.index, expr->toChars());
IF_LOG Logger::println("expr %zu = %s", index, expr->toChars());
val = expr->toElem(gIR);
}
else if (vd == sd->vthis) {

View File

@@ -17,7 +17,6 @@
#include "gen/llvmhelpers.h"
#include "gen/logger.h"
#include "gen/tollvm.h"
#include "gen/utils.h"
#include "ir/iraggr.h"
#include "ir/irtypeclass.h"
#include "ir/irtypestruct.h"
@@ -359,15 +358,15 @@ void IrAggr::addFieldInitializers(
offset = (offset + Target::ptrsize - 1) & ~(Target::ptrsize - 1);
ArrayIter<BaseClass> it2(*cd->vtblInterfaces);
for (; !it2.done(); it2.next())
for (BaseClasses::iterator I = cd->vtblInterfaces->begin(),
E = cd->vtblInterfaces->end();
I != E; ++I)
{
BaseClass* b = it2.get();
constants.push_back(getInterfaceVtbl(b, newinsts, inter_idx));
constants.push_back(getInterfaceVtbl(*I, newinsts, inter_idx));
offset += Target::ptrsize;
// add to the interface list
interfacesWithVtbls.push_back(b);
interfacesWithVtbls.push_back(*I);
inter_idx++;
}
}

View File

@@ -23,7 +23,6 @@
#include "gen/irstate.h"
#include "gen/logger.h"
#include "gen/tollvm.h"
#include "gen/utils.h"
#include "gen/llvmhelpers.h"
#include "gen/functions.h"
#include "ir/irtypeclass.h"
@@ -64,27 +63,28 @@ void IrTypeClass::addBaseClassData(
// FIXME: merge code with structs in IrTypeAggr
// mirror the sd->fields array but only fill in contributors
size_t n = base->fields.dim;
const size_t n = base->fields.dim;
LLSmallVector<VarDeclaration*, 16> data(n, NULL);
default_fields.reserve(n);
// first fill in the fields with explicit initializers
VarDeclarationIter field_it(base->fields);
for (; field_it.more(); field_it.next())
for (size_t index = 0; index < n; ++index)
{
VarDeclaration *field = base->fields[index];
// init is !null for explicit inits
if (field_it->init != NULL)
if (field->init != NULL)
{
IF_LOG Logger::println("adding explicit initializer for struct field %s",
field_it->toChars());
field->toChars());
data[field_it.index] = *field_it;
data[index] = field;
size_t f_begin = field_it->offset;
size_t f_end = f_begin + field_it->type->size();
size_t f_begin = field->offset;
size_t f_end = f_begin + field->type->size();
// make sure there is no overlap
for (size_t i = 0; i < field_it.index; i++)
for (size_t i = 0; i < index; i++)
{
if (data[i] != NULL)
{
@@ -96,7 +96,7 @@ void IrTypeClass::addBaseClassData(
continue;
base->error(vd->loc, "has overlapping initialization for %s and %s",
field_it->toChars(), vd->toChars());
field->toChars(), vd->toChars());
}
}
}
@@ -108,14 +108,14 @@ void IrTypeClass::addBaseClassData(
}
// fill in default initializers
field_it = VarDeclarationIter(base->fields);
for (;field_it.more(); field_it.next())
for (size_t index = 0; index < n; ++index)
{
if (data[field_it.index])
if (data[index])
continue;
VarDeclaration *field = base->fields[index];
size_t f_begin = field_it->offset;
size_t f_end = f_begin + field_it->type->size();
size_t f_begin = field->offset;
size_t f_end = f_begin + field->type->size();
// make sure it doesn't overlap anything explicit
bool overlaps = false;
@@ -138,8 +138,8 @@ void IrTypeClass::addBaseClassData(
if (!overlaps)
{
IF_LOG Logger::println("adding default initializer for struct field %s",
field_it->toChars());
data[field_it.index] = *field_it;
field->toChars());
data[index] = field;
}
}
@@ -187,17 +187,17 @@ void IrTypeClass::addBaseClassData(
{
bool new_instances = (base == cd);
ArrayIter<BaseClass> it2(*base->vtblInterfaces);
VarDeclarationIter interfaces_idx(Type::typeinfoclass->fields, 3);
VarDeclaration *interfaces_idx = Type::typeinfoclass->fields[3];
Type* first = interfaces_idx->type->nextOf()->pointerTo();
// align offset
offset = (offset + Target::ptrsize - 1) & ~(Target::ptrsize - 1);
for (; !it2.done(); it2.next())
for (BaseClasses::iterator I = base->vtblInterfaces->begin(),
E = base->vtblInterfaces->end();
I != E; ++I)
{
BaseClass* b = it2.get();
BaseClass *b = *I;
IF_LOG Logger::println("Adding interface vtbl for %s", b->base->toPrettyChars());
FuncDeclarations arr;

View File

@@ -23,7 +23,6 @@
#include "gen/irstate.h"
#include "gen/tollvm.h"
#include "gen/logger.h"
#include "gen/utils.h"
#include "gen/llvmhelpers.h"
//////////////////////////////////////////////////////////////////////////////
@@ -111,27 +110,28 @@ IrTypeStruct* IrTypeStruct::get(StructDeclaration* sd)
// replace it by just taking the type of the default initializer.
// mirror the sd->fields array but only fill in contributors
size_t n = sd->fields.dim;
const size_t n = sd->fields.dim;
LLSmallVector<VarDeclaration*, 16> data(n, NULL);
t->default_fields.reserve(n);
// first fill in the fields with explicit initializers
VarDeclarationIter field_it(sd->fields);
for (; field_it.more(); field_it.next())
for (size_t index = 0; index < n; ++index)
{
VarDeclaration *field = sd->fields[index];
// init is !null for explicit inits
if (field_it->init != NULL && !field_it->init->isVoidInitializer())
if (field->init != NULL && !field->init->isVoidInitializer())
{
IF_LOG Logger::println("adding explicit initializer for struct field %s",
field_it->toChars());
field->toChars());
data[field_it.index] = *field_it;
data[index] = field;
size_t f_begin = field_it->offset;
size_t f_end = f_begin + field_it->type->size();
size_t f_begin = field->offset;
size_t f_end = f_begin + field->type->size();
// make sure there is no overlap
for (size_t i = 0; i < field_it.index; i++)
for (size_t i = 0; i < index; i++)
{
if (data[i] != NULL)
{
@@ -143,7 +143,7 @@ IrTypeStruct* IrTypeStruct::get(StructDeclaration* sd)
continue;
sd->error(vd->loc, "has overlapping initialization for %s and %s",
field_it->toChars(), vd->toChars());
field->toChars(), vd->toChars());
}
}
}
@@ -155,14 +155,14 @@ IrTypeStruct* IrTypeStruct::get(StructDeclaration* sd)
}
// fill in default initializers
field_it = VarDeclarationIter(sd->fields);
for (;field_it.more(); field_it.next())
for (size_t index = 0; index < n; ++index)
{
if (data[field_it.index])
if (data[index])
continue;
VarDeclaration *field = sd->fields[index];
size_t f_begin = field_it->offset;
size_t f_end = f_begin + field_it->type->size();
size_t f_begin = field->offset;
size_t f_end = f_begin + field->type->size();
// make sure it doesn't overlap anything explicit
bool overlaps = false;
@@ -185,8 +185,8 @@ IrTypeStruct* IrTypeStruct::get(StructDeclaration* sd)
if (!overlaps)
{
IF_LOG Logger::println("adding default initializer for struct field %s",
field_it->toChars());
data[field_it.index] = *field_it;
field->toChars());
data[index] = field;
}
}