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
2 changes: 1 addition & 1 deletion compiler/src/dmd/clone.d
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ private CtorDeclaration generateCtorDeclaration(StructDeclaration sd, const STC
{
auto structType = sd.type;
STC stc = move ? STC.none : STC.ref_; // the only difference between copy or move
auto fparams = new Parameters(new Parameter(Loc.initial, paramStc | stc, structType, Id.p, null, null, null));
auto fparams = new Parameters(new Parameter(Loc.initial, paramStc | stc, structType, Id.p, null, null, null));
ParameterList pList = ParameterList(fparams);
auto tf = new TypeFunction(pList, structType, LINK.d, STC.ref_);
auto ccd = new CtorDeclaration(sd.loc, Loc.initial, STC.ref_, tf);
Expand Down
37 changes: 16 additions & 21 deletions compiler/src/dmd/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ UnionExp Equal(EXP op, Loc loc, Type type, Expression e1, Expression e2)
}
else if (ArrayLiteralExp es2 = e2.isArrayLiteralExp())
{
cmp = !es2.elements || (0 == es2.elements.length);
cmp = (0 == es2.length);
}
else
{
Expand All @@ -641,7 +641,7 @@ UnionExp Equal(EXP op, Loc loc, Type type, Expression e1, Expression e2)
}
else if (ArrayLiteralExp es1 = e1.isArrayLiteralExp())
{
cmp = !es1.elements || (0 == es1.elements.length);
cmp = (0 == es1.length);
}
else
{
Expand Down Expand Up @@ -670,15 +670,10 @@ UnionExp Equal(EXP op, Loc loc, Type type, Expression e1, Expression e2)
{
ArrayLiteralExp es1 = e1.isArrayLiteralExp();
ArrayLiteralExp es2 = e2.isArrayLiteralExp();
if ((!es1.elements || !es1.elements.length) && (!es2.elements || !es2.elements.length))
cmp = 1; // both arrays are empty
else if (!es1.elements || !es2.elements)
cmp = 0;
else if (es1.elements.length != es2.elements.length)
cmp = 0;
else
if (es1.length == es2.length)
{
for (size_t i = 0; i < es1.elements.length; i++)
cmp = 1;
foreach (size_t i; 0 .. es1.length)
{
auto ee1 = es1[i];
auto ee2 = es2[i];
Expand All @@ -705,7 +700,7 @@ UnionExp Equal(EXP op, Loc loc, Type type, Expression e1, Expression e2)
StringExp es1 = e1.isStringExp();
ArrayLiteralExp es2 = e2.isArrayLiteralExp();
size_t dim1 = es1.len;
size_t dim2 = es2.elements ? es2.elements.length : 0;
size_t dim2 = es2.length;
if (dim1 != dim2)
cmp = 0;
else
Expand Down Expand Up @@ -1106,7 +1101,7 @@ UnionExp ArrayLength(Type type, Expression e1)
}
else if (ArrayLiteralExp ale = e1.isArrayLiteralExp())
{
size_t dim = ale.elements ? ale.elements.length : 0;
size_t dim = ale.length;
emplaceExp!(IntegerExp)(&ue, loc, dim, type);
}
else if (AssocArrayLiteralExp ale = e1.isAssocArrayLiteralExp)
Expand Down Expand Up @@ -1179,9 +1174,9 @@ UnionExp Index(Type type, Expression e1, Expression e2, bool indexIsInBounds)
uinteger_t i = e2.toInteger();
if (ArrayLiteralExp ale = e1.isArrayLiteralExp())
{
if (i >= ale.elements.length)
if (i >= ale.length)
{
error(e1.loc, "array index %llu is out of bounds `%s[0 .. %llu]`", i, e1.toErrMsg(), cast(ulong) ale.elements.length);
error(e1.loc, "array index %llu is out of bounds `%s[0 .. %llu]`", i, e1.toErrMsg(), cast(ulong) ale.length);
emplaceExp!(ErrorExp)(&ue);
}
else
Expand Down Expand Up @@ -1277,7 +1272,7 @@ UnionExp Slice(Type type, Expression e1, Expression lwr, Expression upr)
ArrayLiteralExp es1 = e1.isArrayLiteralExp();
const uinteger_t ilwr = lwr.toInteger();
const uinteger_t iupr = upr.toInteger();
if (sliceBoundsCheck(0, es1.elements.length, ilwr, iupr))
if (sliceBoundsCheck(0, es1.length, ilwr, iupr))
cantExp(ue);
else
{
Expand Down Expand Up @@ -1321,7 +1316,7 @@ void sliceAssignArrayLiteralFromString(ArrayLiteralExp existingAE, const StringE
void sliceAssignStringFromArrayLiteral(StringExp existingSE, ArrayLiteralExp newae, size_t firstIndex)
{
assert(existingSE.ownedByCtfe != OwnedBy.code);
foreach (j; 0 .. newae.elements.length)
foreach (j; 0 .. newae.length)
{
existingSE.setCodeUnit(firstIndex + j, cast(dchar)newae[j].toInteger());
}
Expand Down Expand Up @@ -1526,15 +1521,15 @@ UnionExp Cat(Loc loc, Type type, Expression e1, Expression e2)
// [chars] ~ string --> [chars]
StringExp es = e2.isStringExp();
ArrayLiteralExp ea = e1.isArrayLiteralExp();
size_t len = es.len + ea.elements.length;
size_t len = es.len + ea.length;
auto elems = new Expressions(len);
for (size_t i = 0; i < ea.elements.length; ++i)
for (size_t i = 0; i < ea.length; ++i)
{
(*elems)[i] = ea[i];
}
emplaceExp!(ArrayLiteralExp)(&ue, e1.loc, type, elems);
ArrayLiteralExp dest = ue.exp().isArrayLiteralExp();
sliceAssignArrayLiteralFromString(dest, es, ea.elements.length);
sliceAssignArrayLiteralFromString(dest, es, ea.length);
assert(ue.exp().type);
return ue;
}
Expand All @@ -1543,9 +1538,9 @@ UnionExp Cat(Loc loc, Type type, Expression e1, Expression e2)
// string ~ [chars] --> [chars]
StringExp es = e1.isStringExp();
ArrayLiteralExp ea = e2.isArrayLiteralExp();
size_t len = es.len + ea.elements.length;
size_t len = es.len + ea.length;
auto elems = new Expressions(len);
for (size_t i = 0; i < ea.elements.length; ++i)
for (size_t i = 0; i < ea.length; ++i)
{
(*elems)[es.len + i] = ea[i];
}
Expand Down
30 changes: 15 additions & 15 deletions compiler/src/dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Expression implicitCastTo(Expression e, Scope* sc, Type t)
{
Type tb = t.toBasetype();
Type tx = (tb.ty == Tsarray)
? tb.nextOf().sarrayOf(ale.elements ? ale.elements.length : 0)
? tb.nextOf().sarrayOf(ale.length)
: tb.nextOf().arrayOf();
se.e1 = ale.implicitCastTo(sc, tx);
}
Expand Down Expand Up @@ -849,12 +849,12 @@ MATCH implicitConvTo(Expression e, Type t)

if (auto tsa = tb.isTypeSArray())
{
if (e.elements.length != tsa.dim.toInteger())
if (e.length != tsa.dim.toInteger())
result = MATCH.nomatch;
}

Type telement = tb.nextOf();
if (!e.elements.length)
if (!e.length)
{
if (typen.ty != Tvoid)
result = typen.implicitConvTo(telement);
Expand All @@ -867,9 +867,9 @@ MATCH implicitConvTo(Expression e, Type t)
if (m < result)
result = m;
}
for (size_t i = 0; i < e.elements.length; i++)
foreach (i; 0 .. e.length)
{
Expression el = (*e.elements)[i];
Expression el = e[i];
if (result == MATCH.nomatch)
break;
if (!el)
Expand All @@ -892,7 +892,7 @@ MATCH implicitConvTo(Expression e, Type t)
TypeVector tv = tb.isTypeVector();
TypeSArray tbase = tv.basetype.isTypeSArray();
assert(tbase);
const edim = e.elements.length;
const edim = e.length;
const tbasedim = tbase.dim.toInteger();
if (edim > tbasedim)
{
Expand Down Expand Up @@ -2852,17 +2852,17 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
{
if (auto tsa = tb.isTypeSArray())
{
if (e.elements.length != tsa.dim.toInteger())
if (e.length != tsa.dim.toInteger())
return visit(ae);
}

ae = e.copy().isArrayLiteralExp();
if (e.basis)
ae.basis = e.basis.castTo(sc, tb.nextOf());
ae.elements = e.elements.copy();
for (size_t i = 0; i < e.elements.length; i++)
foreach (i; 0 .. e.length)
{
Expression ex = (*e.elements)[i];
Expression ex = e[i];
if (!ex)
continue;
ex = ex.castTo(sc, tb.nextOf());
Expand All @@ -2888,7 +2888,7 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
TypeVector tv = tb.isTypeVector();
TypeSArray tbase = tv.basetype.isTypeSArray();
assert(tbase.ty == Tsarray);
const edim = e.elements.length;
const edim = e.length;
const tbasedim = tbase.dim.toInteger();
if (edim > tbasedim)
return visit(ae);
Expand Down Expand Up @@ -3261,12 +3261,12 @@ Expression inferType(Expression e, Type t, int flag = 0)
Type tn = tb.nextOf();
if (ale.basis)
ale.basis = inferType(ale.basis, tn, flag);
for (size_t i = 0; i < ale.elements.length; i++)
foreach (i; 0 .. ale.length)
{
if (Expression e = (*ale.elements)[i])
if (Expression e = ale[i])
{
e = inferType(e, tn, flag);
(*ale.elements)[i] = e;
ale[i] = e;
}
}

Expand Down Expand Up @@ -3398,7 +3398,7 @@ Expression scaleFactor(BinExp be, Scope* sc)
*/
private bool isVoidArrayLiteral(Expression e, Type other)
{
while (e.op == EXP.arrayLiteral && e.type.ty == Tarray && (e.isArrayLiteralExp().elements.length == 1))
while (e.op == EXP.arrayLiteral && e.type.ty == Tarray && (e.isArrayLiteralExp().length == 1))
{
auto ale = e.isArrayLiteralExp();
e = ale[0];
Expand All @@ -3410,7 +3410,7 @@ private bool isVoidArrayLiteral(Expression e, Type other)
if (other.ty != Tsarray && other.ty != Tarray)
return false;
Type t = e.type;
return (e.op == EXP.arrayLiteral && t.ty == Tarray && t.nextOf().ty == Tvoid && e.isArrayLiteralExp().elements.length == 0);
return (e.op == EXP.arrayLiteral && t.ty == Tarray && t.nextOf().ty == Tvoid && e.isArrayLiteralExp().length == 0);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/dfa/fast/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ struct ExpressionWalker
// [foo = new int]
DFALatticeRef ret = this.callFunction(null, null, null, ale.elements, ale.loc);

if (ale.elements !is null && ale.elements.length > 0)
if (ale.elements !is null && ale.length > 0)
{
DFAObject* obj = ret.getContextObject();

Expand All @@ -1919,7 +1919,7 @@ struct ExpressionWalker

cctx.truthiness = Truthiness.True;
cctx.nullable = Nullable.NonNull;
cctx.pa = DFAPAValue(ale.elements.length);
cctx.pa = DFAPAValue(ale.length);
cctx.obj = obj;
}
else
Expand Down
17 changes: 8 additions & 9 deletions compiler/src/dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -3173,7 +3173,7 @@ public:
emplaceExp!ArrayLiteralExp(&ue, loc, type, cast(Expressions*) null);
return ue;
}
const length = aex.elements.length;
const length = aex.length;
Expressions* elements = new Expressions(length);

emplaceExp!ArrayLiteralExp(&ue, loc, type, elements);
Expand Down Expand Up @@ -3975,7 +3975,7 @@ public:
if (auto ale = e1.isArrayLiteralExp())
{
lowerbound = 0;
upperbound = ale.elements.length;
upperbound = ale.length;
}
else if (auto se = e1.isStringExp())
{
Expand Down Expand Up @@ -4211,9 +4211,9 @@ public:
bool needsPostblit;
bool needsDtor;

Expression assignTo(ArrayLiteralExp ae)
Expression assignTo(ArrayLiteralExp ale)
{
return assignTo(ae, 0, ae.elements.length);
return assignTo(ale, 0, ale.length);
}

Expression assignTo(ArrayLiteralExp ae, size_t lwr, size_t upr)
Expand Down Expand Up @@ -5738,7 +5738,7 @@ public:
{
ArrayLiteralExp ale = ie.e1.isArrayLiteralExp();
const indx = cast(size_t)ie.e2.toInteger();
if (indx < ale.elements.length)
if (indx < ale.length) // xyzzy
{
Expression xx = (*ale.elements)[indx];
if (!xx) xx = ale.basis;
Expand Down Expand Up @@ -6028,10 +6028,9 @@ public:
* Dereference it only if result should be an rvalue
*/
auto ae = result.isArrayLiteralExp();
if (ae.elements.length == 1)
if (ae.length == 1)
{
result = (*ae.elements)[0];
if (!result) result = ae.basis;
result = ae[0];
return;
}
}
Expand Down Expand Up @@ -7188,7 +7187,7 @@ private Expression interpret_aaApply(UnionExp* pue, InterState* istate, Expressi
/// Returns: equivalent `StringExp` from `ArrayLiteralExp ale` containing only `IntegerExp` elements
StringExp arrayLiteralToString(ArrayLiteralExp ale)
{
const len = ale.elements ? ale.elements.length : 0;
const len = ale.elements ? ale.length : 0;
const size = ale.type.nextOf().size();

StringExp impl(T)()
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor

if (auto ale = e.isArrayLiteralExp())
{
len = ale.elements.length;
len = ale.length;
return true;
}

Expand Down Expand Up @@ -2519,13 +2519,13 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor

if (auto ale = ie.isArrayLiteralExp())
{
dinteger_t len = ale.elements.length;
dinteger_t len = ale.length;
tsa.dim = new IntegerExp(loc, len, Type.tsize_t);
if (auto innerTsa = tsa.next.isTypeSArray())
{
if (ale.elements.length > 0)
if (len)
{
auto firstElem = (*ale.elements)[0];
auto firstElem = ale[0];
inferSArrayDim(innerTsa, firstElem, loc, sc);
}
}
Expand Down Expand Up @@ -10095,7 +10095,7 @@ bool _isZeroInit(Expression exp)
{
auto ale = cast(ArrayLiteralExp)exp;

const dim = ale.elements ? ale.elements.length : 0;
const dim = ale.length;

if (ale.type.toBasetype().ty == Tarray) // if initializing a dynamic array
return dim == 0;
Expand Down
8 changes: 8 additions & 0 deletions compiler/src/dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,14 @@ extern (C++) final class ArrayLiteralExp : Expression
return el ? el : basis;
}

extern (D) Expression opIndexAssign(Expression value, size_t i)
{
(*elements)[i] = value;
return value;
}

extern (D) size_t length() { return elements ? elements.length : 0; }

override void accept(Visitor v)
{
v.visit(this);
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dmd/glue/e2ir.d
Original file line number Diff line number Diff line change
Expand Up @@ -2909,7 +2909,7 @@ elem* toElem(Expression e, ref IRState irs)
{
ArrayLiteralExp ale = cast(ArrayLiteralExp)ae.e2;
elem* e;
if (ale.elements.length == 0)
if (ale.length == 0)
{
e = e1;
}
Expand Down Expand Up @@ -4089,7 +4089,7 @@ elem* toElem(Expression e, ref IRState irs)

elem* visitArrayLiteral(ArrayLiteralExp ale)
{
size_t dim = ale.elements ? ale.elements.length : 0;
size_t dim = ale.length;

//printf("ArrayLiteralExp.toElem() %s, type = %s\n", ale.toChars(), ale.type.toChars());
Type tb = ale.type.toBasetype();
Expand Down Expand Up @@ -4526,7 +4526,7 @@ elem* ExpressionsToStaticArray(ref IRState irs, Loc loc, Expressions* exps, Symb
el.type.toBasetype().ty == Tsarray)
{
ArrayLiteralExp ale = cast(ArrayLiteralExp)el;
if (ale.elements && ale.elements.length)
if (ale.length)
{
elem* ex = ExpressionsToStaticArray(irs,
ale.loc, ale.elements, &stmp, cast(uint)(offset + i * szelem), ale.basis);
Expand Down
Loading
Loading