Skip to content

Commit

Permalink
Merge pull request #4160 from WalterBright/changearraylength
Browse files Browse the repository at this point in the history
changeArrayLiteralLength() now returns UnionExp
  • Loading branch information
MartinNowak committed Nov 23, 2014
2 parents 3ba4b64 + 4fbd471 commit 81d5a43
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ctfe.h
Expand Up @@ -177,7 +177,7 @@ Expression *assignAssocArrayElement(Loc loc, AssocArrayLiteralExp *aae,
/// Given array literal oldval of type ArrayLiteralExp or StringExp, of length
/// oldlen, change its length to newlen. If the newlen is longer than oldlen,
/// all new elements will be set to the default initializer for the element type.
Expression *changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
UnionExp changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
Expression *oldval, size_t oldlen, size_t newlen);


Expand Down
12 changes: 7 additions & 5 deletions src/ctfeexpr.c
Expand Up @@ -1909,9 +1909,10 @@ Expression *assignAssocArrayElement(Loc loc, AssocArrayLiteralExp *aae,
/// Given array literal oldval of type ArrayLiteralExp or StringExp, of length
/// oldlen, change its length to newlen. If the newlen is longer than oldlen,
/// all new elements will be set to the default initializer for the element type.
Expression *changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
UnionExp changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
Expression *oldval, size_t oldlen, size_t newlen)
{
UnionExp ue;
Type *elemType = arrayType->next;
assert(elemType);
Expression *defaultElem = elemType->defaultInitLiteral(loc);
Expand Down Expand Up @@ -1942,12 +1943,12 @@ Expression *changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
default: assert(0);
}
}
StringExp *se = new StringExp(loc, s, newlen);
new(&ue) StringExp(loc, s, newlen);
StringExp *se = (StringExp *)ue.exp();
se->type = arrayType;
se->sz = oldse->sz;
se->committed = oldse->committed;
se->ownedByCtfe = true;
return se;
}
else
{
Expand All @@ -1969,11 +1970,12 @@ Expression *changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
for (size_t i = copylen; i < newlen; i++)
(*elements)[i] = defaultElem;
}
ArrayLiteralExp *aae = new ArrayLiteralExp(loc, elements);
new(&ue) ArrayLiteralExp(loc, elements);
ArrayLiteralExp *aae = (ArrayLiteralExp *)ue.exp();
aae->type = arrayType;
aae->ownedByCtfe = true;
return aae;
}
return ue;
}


Expand Down
2 changes: 1 addition & 1 deletion src/interpret.c
Expand Up @@ -3733,7 +3733,7 @@ class Interpreter : public Visitor
if (t->ty == Tarray)
{
newval = changeArrayLiteralLength(e->loc, (TypeArray *)t, oldval,
oldlen, newlen);
oldlen, newlen).copy();
// We have changed it into a reference assignment
// Note that returnValue is still the new length.
wantRef = true;
Expand Down

0 comments on commit 81d5a43

Please sign in to comment.