Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions compiler/src/dmd/ctfeexpr.d
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ uinteger_t resolveArrayLength(Expression e)
case EXP.arrayLiteral:
{
const ale = e.isArrayLiteralExp();
return ale.elements ? ale.elements.length : 0;
return ale.length;
}

case EXP.assocArrayLiteral:
Expand Down Expand Up @@ -1399,12 +1399,12 @@ UnionExp ctfeCat(Loc loc, Type type, Expression e1, Expression e2)
// [chars] ~ string => string (only valid for CTFE)
StringExp es1 = e2.isStringExp();
ArrayLiteralExp es2 = e1.isArrayLiteralExp();
const len = es1.len + es2.elements.length;
const len = es1.len + es2.length;
const sz = es1.sz;
void* s = mem.xmalloc_noscan((len + 1) * sz);
const data1 = es1.peekData();
memcpy(cast(char*)s + sz * es2.elements.length, data1.ptr, data1.length);
foreach (size_t i; 0 .. es2.elements.length)
memcpy(cast(char*)s + sz * es2.length, data1.ptr, data1.length);
foreach (size_t i; 0 .. es2.length)
{
Expression es2e = (*es2.elements)[i];
if (!es2e) es2e = es2.basis;
Expand All @@ -1430,12 +1430,12 @@ UnionExp ctfeCat(Loc loc, Type type, Expression e1, Expression e2)
// Concatenate the strings
StringExp es1 = e1.isStringExp();
ArrayLiteralExp es2 = e2.isArrayLiteralExp();
const len = es1.len + es2.elements.length;
const len = es1.len + es2.length;
const sz = es1.sz;
void* s = mem.xmalloc_noscan((len + 1) * sz);
auto slice = es1.peekData();
memcpy(s, slice.ptr, slice.length);
foreach (size_t i; 0 .. es2.elements.length)
foreach (size_t i; 0 .. es2.length)
{
Expression es2e = (*es2.elements)[i];
if (!es2e) es2e = es2.basis;
Expand Down Expand Up @@ -1463,7 +1463,7 @@ UnionExp ctfeCat(Loc loc, Type type, Expression e1, Expression e2)
ArrayLiteralExp es2 = e2.isArrayLiteralExp();
emplaceExp!(ArrayLiteralExp)(&ue, es1.loc, type, copyLiteralArrayExpand(es1.elements, es1.basis));
es1 = ue.exp().isArrayLiteralExp();
es1.elements.insert(es1.elements.length, copyLiteralArrayExpand(es2.elements, es2.basis));
es1.elements.insert(es1.length, copyLiteralArrayExpand(es2.elements, es2.basis));
return ue;
}
if (e1.op == EXP.arrayLiteral && e2.op == EXP.null_ && t1.nextOf().equals(t2.nextOf()))
Expand Down Expand Up @@ -1525,13 +1525,12 @@ Expression ctfeIndex(UnionExp* pue, Loc loc, Type type, Expression e1, uinteger_

if (auto ale = e1.isArrayLiteralExp())
{
if (indx >= ale.elements.length)
if (indx >= ale.length)
{
error(loc, "array index %llu is out of bounds `%s[0 .. %llu]`", indx, e1.toErrMsg(), cast(ulong)ale.elements.length);
error(loc, "array index %llu is out of bounds `%s[0 .. %llu]`", indx, e1.toErrMsg(), cast(ulong)ale.length);
return CTFEExp.cantexp;
}
Expression e = (*ale.elements)[cast(size_t)indx];
if (!e) e = ale.basis;
Expression e = ale[cast(size_t)indx];
return paintTypeOntoLiteral(pue, type, e);
}

Expand Down Expand Up @@ -1951,7 +1950,7 @@ void showCtfeExpr(Expression e, int level = 0)
}
else if (e.op == EXP.arrayLiteral)
{
elements = e.isArrayLiteralExp().elements;
elements = e.isArrayLiteralExp().elements; // what about basis?
printf("ARRAY LITERAL type=%s %p:\n", e.type.toChars(), e);
}
else if (e.op == EXP.assocArrayLiteral)
Expand Down
57 changes: 30 additions & 27 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,11 @@ bool canElideCopy(Expression e, Type to, bool checkMod = false)
}

// Return index of the field, or -1 if not found
int getFieldIndex(ClassReferenceExp _this, Type fieldtype, uint fieldoffset)
int getFieldIndex(ClassReferenceExp cre, Type fieldtype, uint fieldoffset)
{
ClassDeclaration cd = _this.originalClass();
ClassDeclaration cd = cre.originalClass();
uint fieldsSoFar = 0;
for (size_t j = 0; j < _this.value.elements.length; j++)
for (size_t j = 0; j < cre.value.elements.length; j++)
{
while (j - fieldsSoFar >= cd.fields.length)
{
Expand All @@ -865,36 +865,36 @@ int getFieldIndex(ClassReferenceExp _this, Type fieldtype, uint fieldoffset)
VarDeclaration v2 = cd.fields[j - fieldsSoFar];
if (fieldoffset == v2.offset && fieldtype.size() == v2.type.size())
{
return cast(int)( _this.value.elements.length - fieldsSoFar - cd.fields.length + (j - fieldsSoFar));
return cast(int)( cre.value.elements.length - fieldsSoFar - cd.fields.length + (j - fieldsSoFar));
}
}
return -1;
}

/************************************
* Get index of field.
* Returns -1 if not found.
* Returns: -1 if not found.
*/
int getFieldIndex(StructLiteralExp _this, Type type, uint offset)
int getFieldIndex(StructLiteralExp sle, Type type, uint offset)
{
/* Find which field offset is by looking at the field offsets
*/
if (!_this.elements.length)
if (!sle.elements.length)
return -1;

const sz = type.size();
if (sz == SIZE_INVALID)
return -1;
foreach (i, v; _this.sd.fields)
foreach (i, v; sle.sd.fields)
{
if (offset != v.offset)
continue;
if (sz != v.type.size())
continue;
/* context fields might not be filled. */
if (i >= _this.sd.nonHiddenFields())
if (i >= sle.sd.nonHiddenFields())
return cast(int)i;
if (auto e = (*_this.elements)[i])
if (auto e = (*sle.elements)[i])
{
return cast(int)i;
}
Expand Down Expand Up @@ -948,19 +948,19 @@ bool equals(const Expression _this, const Expression e)
return true;
}

static bool arrayLiteralExpEquals(const ArrayLiteralExp _this, const ArrayLiteralExp ale)
static bool arrayLiteralExpEquals(const ArrayLiteralExp ale1, const ArrayLiteralExp ale2)
{
if (_this.length != ale.length)
if (ale1.length != ale2.length)
return false;
if (_this.length == 0 && !_this.type.equals(ale.type))
if (ale1.length == 0 && !ale1.type.equals(ale2.type))
{
return false;
}

foreach (i; 0 .. _this.length)
foreach (i; 0 .. ale1.length)
{
auto e1x = _this[i];
auto e2x = ale[i];
auto e1x = ale1[i];
auto e2x = ale2[i];

if (e1x != e2x && (!e1x || !e2x || !e1x.equals(e2x)))
return false;
Expand Down Expand Up @@ -4615,10 +4615,10 @@ private bool functionParameters(Loc loc, Scope* sc,

ArrayLiteralExp ale;
if (p.type.toBasetype().ty == Tarray &&
(ale = a.isArrayLiteralExp()) !is null && ale.elements && ale.elements.length > 0)
(ale = a.isArrayLiteralExp()) !is null && ale.length)
{
// allocate the array literal as temporary static array on the stack
ale.type = ale.type.nextOf().sarrayOf(ale.elements.length);
ale.type = ale.type.nextOf().sarrayOf(ale.length);
auto tmp = copyToTemp(STC.none, "__arrayliteral_on_stack", ale);
tmp.storage_class |= STC.exptemp;
auto declareTmp = new DeclarationExp(ale.loc, tmp);
Expand Down Expand Up @@ -5253,7 +5253,7 @@ private bool checkNestedFuncReference(FuncDeclaration fd, Scope* sc, Loc loc)

Expression lowerArrayLiteral(ArrayLiteralExp ale, Scope* sc)
{
const dim = ale.elements ? ale.elements.length : 0;
const dim = ale.length;

Identifier hook = Id._d_arrayliteralTX;
if (!verifyHookExist(ale.loc, *sc, hook, "creating array literals"))
Expand Down Expand Up @@ -6105,7 +6105,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor

/* Disallow array literals of type void being used.
*/
if (e.elements.length > 0 && t0.ty == Tvoid)
if (e.length > 0 && t0.ty == Tvoid)
{
error(e.loc, "`%s` of type `%s` has no value", e.toErrMsg(), e.type.toErrMsg());
return setError();
Expand Down Expand Up @@ -12837,7 +12837,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
uinteger_t dim2 = dim1;
if (auto ale = e2x.isArrayLiteralExp())
{
dim2 = ale.elements ? ale.elements.length : 0;
dim2 = ale.length;
}
else if (auto se = e2x.isSliceExp())
{
Expand Down Expand Up @@ -13067,7 +13067,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
TypeSArray tsa1 = cast(TypeSArray)toStaticArrayType(se1);
TypeSArray tsa2 = null;
if (auto ale = e2x.isArrayLiteralExp())
tsa2 = cast(TypeSArray)t2.nextOf().sarrayOf(ale.elements.length);
tsa2 = cast(TypeSArray)t2.nextOf().sarrayOf(ale.length);
else if (auto se = e2x.isSliceExp())
tsa2 = cast(TypeSArray)toStaticArrayType(se);
else
Expand Down Expand Up @@ -15220,13 +15220,16 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
if (eNext && !eNext.toBasetype().isTypeStruct())
e.type = e.type.unqualify(MODFlags.const_);

if (!e.isArrayLiteralExp())
auto ale = e.isArrayLiteralExp();
if (!ale)
return;

if (auto elems = e.isArrayLiteralExp().elements)
foreach(elem; *elems)
if (elem)
unqualifyExp(elem);
foreach (i; 0 .. ale.length)
{
Expression ex = ale[i];
if (ex)
unqualifyExp(ex);
}
}
unqualifyExp(e1c);
unqualifyExp(e2c);
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dmd/glue/toobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,10 @@ void toObjFile(Dsymbol ds, bool multiobj)
if (!e.isStructLiteralExp())
return 0;

auto literal = e.isStructLiteralExp();
assert(literal.sd);
auto sle = e.isStructLiteralExp();
assert(sle.sd);

if (!isCoreUda(literal.sd, Id.udaSection))
if (!isCoreUda(sle.sd, Id.udaSection))
return 0;

if (userDefinedSection)
Expand All @@ -519,8 +519,8 @@ void toObjFile(Dsymbol ds, bool multiobj)
return 1;
}

assert(literal.elements.length == 1);
auto se = (*literal.elements)[0].isStringExp();
assert(sle.elements.length == 1);
auto se = (*sle.elements)[0].isStringExp();
assert(se);

userDefinedSection = cast(string)se.toUTF8(vd._scope).toStringz();
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dmd/lambdacomp.d
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,23 @@ public:
visitType(p.type);
}

override void visit(StructLiteralExp e)
override void visit(StructLiteralExp sle)
{
static if (LOG)
printf("StructLiteralExp: %s\n", e.toChars);
printf("StructLiteralExp: %s\n", sle.toChars);

auto ty = cast(TypeStruct)e.stype;
auto ty = cast(TypeStruct)sle.stype;
if (!ty)
{
buf.setsize(0);
return;
}

writeMangledName(ty.sym);
auto dim = e.elements.length;
auto dim = sle.elements.length;
foreach (i; 0..dim)
{
auto elem = (*e.elements)[i];
auto elem = (*sle.elements)[i];
if (elem)
elem.accept(this);
else
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/mangle/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ public:

override void visit(ArrayLiteralExp e)
{
const dim = e.elements.length;
const dim = e.length;
buf.writeByte('A');
buf.print(dim);
foreach (i; 0 .. dim)
Expand Down
Loading