Skip to content
Closed
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
5 changes: 5 additions & 0 deletions compiler/src/dmd/astbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -4806,6 +4806,11 @@ struct ASTBase
}
}

static IntegerExp newIntegerExp(Loc loc, dinteger_t value, Type type)
{
return new IntegerExp(loc, value, type);
}

extern (C++) final class NewAnonClassExp : Expression
{
Expression thisexp; // if !=null, 'this' for class being allocated
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dmd/astcodegen.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ struct ASTCodegen
public import dmd.hdrgen;
public import dmd.init;
public import dmd.initsem;
public import dmd.expressionsem;
public import dmd.mtype;
public import dmd.nspace;
public import dmd.statement;
public import dmd.staticassert;
public import dmd.init : Designator;


alias newIntegerExp = dmd.expressionsem.newIntegerExp;
alias initializerToExpression = dmd.initsem.initializerToExpression;
alias typeToExpression = dmd.mtype.typeToExpression;
alias UserAttributeDeclaration = dmd.attrib.UserAttributeDeclaration;
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dmd/builtin.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import dmd.arraytypes;
import dmd.astenums;
import dmd.errors;
import dmd.expression;
import dmd.expressionsem : toInteger, toReal;
import dmd.expressionsem : toInteger, toReal, newIntegerExp;
import dmd.typesem : isFloating;
import dmd.func;
import dmd.location;
Expand Down Expand Up @@ -379,7 +379,7 @@ Expression eval_bsf(Loc loc, FuncDeclaration fd, Expression[] arguments)
auto n = arg0.toInteger();
if (n == 0)
error(loc, "`bsf(0)` is undefined");
return new IntegerExp(loc, core.bitop.bsf(n), Type.tint32);
return newIntegerExp(loc, core.bitop.bsf(n), Type.tint32);
}

Expression eval_bsr(Loc loc, FuncDeclaration fd, Expression[] arguments)
Expand All @@ -389,7 +389,7 @@ Expression eval_bsr(Loc loc, FuncDeclaration fd, Expression[] arguments)
auto n = arg0.toInteger();
if (n == 0)
error(loc, "`bsr(0)` is undefined");
return new IntegerExp(loc, core.bitop.bsr(n), Type.tint32);
return newIntegerExp(loc, core.bitop.bsr(n), Type.tint32);
}

Expression eval_bswap(Loc loc, FuncDeclaration fd, Expression[] arguments)
Expand All @@ -399,17 +399,17 @@ Expression eval_bswap(Loc loc, FuncDeclaration fd, Expression[] arguments)
auto n = arg0.toInteger();
TY ty = arg0.type.toBasetype().ty;
if (ty == Tint64 || ty == Tuns64)
return new IntegerExp(loc, core.bitop.bswap(cast(ulong) n), arg0.type);
return newIntegerExp(loc, core.bitop.bswap(cast(ulong) n), arg0.type);
else
return new IntegerExp(loc, core.bitop.bswap(cast(uint) n), arg0.type);
return newIntegerExp(loc, core.bitop.bswap(cast(uint) n), arg0.type);
}

Expression eval_popcnt(Loc loc, FuncDeclaration fd, Expression[] arguments)
{
Expression arg0 = arguments[0];
assert(arg0.op == EXP.int64);
auto n = arg0.toInteger();
return new IntegerExp(loc, core.bitop.popcnt(n), Type.tint32);
return newIntegerExp(loc, core.bitop.popcnt(n), Type.tint32);
}

Expression eval_yl2x(Loc loc, FuncDeclaration fd, Expression[] arguments)
Expand Down
14 changes: 7 additions & 7 deletions compiler/src/dmd/clone.d
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,8 @@ void buildDtors(AggregateDeclaration ad, Scope* sc)
if (stc & STC.safe)
stc = (stc & ~STC.safe) | STC.trusted;

SliceExp se = new SliceExp(loc, ex, new IntegerExp(loc, 0, Type.tsize_t),
new IntegerExp(loc, n, Type.tsize_t));
SliceExp se = new SliceExp(loc, ex, newIntegerExp(loc, 0, Type.tsize_t),
newIntegerExp(loc, n, Type.tsize_t));
// Prevent redundant bounds check
se.upperIsInBounds = true;
se.lowerIsLessThanUpper = true;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ private DtorDeclaration buildWindowsCppDtor(AggregateDeclaration ad, DtorDeclara
// // TODO: if (del) delete (char*)this;
// return (void*) this;
// }
Parameter delparam = new Parameter(Loc.initial, STC.none, Type.tuns32, Identifier.idPool("del"), new IntegerExp(dtor.loc, 0, Type.tuns32), null);
Parameter delparam = new Parameter(Loc.initial, STC.none, Type.tuns32, Identifier.idPool("del"), newIntegerExp(dtor.loc, 0, Type.tuns32), null);
Parameters* params = new Parameters;
params.push(delparam);
const stc = dtor.storage_class & ~STC.scope_; // because we add the `return this;` later
Expand Down Expand Up @@ -1354,8 +1354,8 @@ FuncDeclaration buildPostBlit(StructDeclaration sd, Scope* sc)
if (stc & STC.safe)
stc = (stc & ~STC.safe) | STC.trusted;

auto se = new SliceExp(loc, ex, new IntegerExp(loc, 0, Type.tsize_t),
new IntegerExp(loc, length, Type.tsize_t));
auto se = new SliceExp(loc, ex, newIntegerExp(loc, 0, Type.tsize_t),
newIntegerExp(loc, length, Type.tsize_t));
// Prevent redundant bounds check
se.upperIsInBounds = true;
se.lowerIsLessThanUpper = true;
Expand Down Expand Up @@ -1432,8 +1432,8 @@ FuncDeclaration buildPostBlit(StructDeclaration sd, Scope* sc)
if (stc & STC.safe)
stc = (stc & ~STC.safe) | STC.trusted;

auto se = new SliceExp(loc, ex, new IntegerExp(loc, 0, Type.tsize_t),
new IntegerExp(loc, length, Type.tsize_t));
auto se = new SliceExp(loc, ex, newIntegerExp(loc, 0, Type.tsize_t),
newIntegerExp(loc, length, Type.tsize_t));
// Prevent redundant bounds check
se.upperIsInBounds = true;
se.lowerIsLessThanUpper = true;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ void sliceAssignArrayLiteralFromString(ArrayLiteralExp existingAE, const StringE
foreach (j; 0 .. len)
{
const val = newval.getIndex(j);
(*existingAE.elements)[j + firstIndex] = new IntegerExp(newval.loc, val, elemType);
(*existingAE.elements)[j + firstIndex] = newIntegerExp(newval.loc, val, elemType);
}
}

Expand Down
20 changes: 10 additions & 10 deletions compiler/src/dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -770,28 +770,28 @@ final class CParser(AST) : Parser!AST

case TOK.charLiteral:
case TOK.int32Literal:
e = new AST.IntegerExp(loc, token.intvalue, AST.Type.tint32);
e = AST.newIntegerExp(loc, token.intvalue, AST.Type.tint32);
nextToken();
break;

case TOK.wcharLiteral:
e = new AST.IntegerExp(loc, token.intvalue, AST.Type.tuns16);
e = AST.newIntegerExp(loc, token.intvalue, AST.Type.tuns16);
nextToken();
break;

case TOK.dcharLiteral:
case TOK.uns32Literal:
e = new AST.IntegerExp(loc, token.unsvalue, AST.Type.tuns32);
e = AST.newIntegerExp(loc, token.unsvalue, AST.Type.tuns32);
nextToken();
break;

case TOK.int64Literal:
e = new AST.IntegerExp(loc, token.intvalue, AST.Type.tint64);
e = AST.newIntegerExp(loc, token.intvalue, AST.Type.tint64);
nextToken();
break;

case TOK.uns64Literal:
e = new AST.IntegerExp(loc, token.unsvalue, AST.Type.tuns64);
e = AST.newIntegerExp(loc, token.unsvalue, AST.Type.tuns64);
nextToken();
break;

Expand Down Expand Up @@ -882,7 +882,7 @@ final class CParser(AST) : Parser!AST
default:
error("expression expected, not `%s`", token.toChars());
// Anything for e, as long as it's not NULL
e = new AST.IntegerExp(loc, 0, AST.Type.tint32);
e = AST.newIntegerExp(loc, 0, AST.Type.tint32);
nextToken();
break;
}
Expand Down Expand Up @@ -1953,7 +1953,7 @@ final class CParser(AST) : Parser!AST

if (specifier.vector_size)
{
auto length = new AST.IntegerExp(token.loc, specifier.vector_size / dt.size(), AST.Type.tuns32);
auto length = AST.newIntegerExp(token.loc, specifier.vector_size / dt.size(), AST.Type.tuns32);
auto tsa = new AST.TypeSArray(dt, length);
dt = new AST.TypeVector(tsa);
specifier.vector_size = 0; // used it up
Expand Down Expand Up @@ -3047,7 +3047,7 @@ final class CParser(AST) : Parser!AST

if (specifier.vector_size)
{
auto length = new AST.IntegerExp(token.loc, specifier.vector_size / tbase.size(), AST.Type.tuns32);
auto length = AST.newIntegerExp(token.loc, specifier.vector_size / tbase.size(), AST.Type.tuns32);
auto tsa = new AST.TypeSArray(tbase, length);
AST.Type tv = new AST.TypeVector(tsa);
specifier.vector_size = 0; // used it up
Expand Down Expand Up @@ -4856,7 +4856,7 @@ final class CParser(AST) : Parser!AST
const fn = id.toString(); // function-name
auto efn = new AST.StringExp(loc, fn, fn.length, 1, 'c');
auto ifn = new AST.ExpInitializer(loc, efn);
auto lenfn = new AST.IntegerExp(loc, fn.length + 1, AST.Type.tuns32); // +1 for terminating 0
auto lenfn = AST.newIntegerExp(loc, fn.length + 1, AST.Type.tuns32); // +1 for terminating 0
auto tfn = new AST.TypeSArray(AST.Type.tchar, lenfn);
efn.type = tfn.makeImmutable();
efn.committed = true;
Expand Down Expand Up @@ -5649,7 +5649,7 @@ final class CParser(AST) : Parser!AST
/* Declare manifest constant:
* enum id = intvalue;
*/
AST.Expression e = new AST.IntegerExp(scanloc, intvalue, t);
AST.Expression e = AST.newIntegerExp(scanloc, intvalue, t);
if (hasMinus)
e = new AST.NegExp(scanloc, e);
auto v = new AST.VarDeclaration(scanloc, t, id, new AST.ExpInitializer(scanloc, e), STC.manifest);
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dmd/ctfeexpr.d
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ void emplaceExp(T : Expression, Args...)(void* p, Args args)
const init = __traits(initSymbol, T);
p[0 .. __traits(classInstanceSize, T)] = init[];
(cast(T)p).__ctor(args);

static if (is( T == IntegerExp) && args.length == 3)
(cast(T)p).integerExpConstruct(args);
}

void emplaceExp(T : UnionExp)(T* p, Expression e) nothrow
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -3266,7 +3266,7 @@ Expression scaleFactor(BinExp be, Scope* sc)
if (!t.equals(t2b))
be.e2 = be.e2.castTo(sc, t);
eoff = be.e2;
be.e2 = new MulExp(be.loc, be.e2, new IntegerExp(Loc.initial, stride, t));
be.e2 = new MulExp(be.loc, be.e2, newIntegerExp(Loc.initial, stride, t));
be.e2.type = t;
be.type = be.e1.type;
}
Expand All @@ -3283,7 +3283,7 @@ Expression scaleFactor(BinExp be, Scope* sc)
else
e = be.e1;
eoff = e;
e = new MulExp(be.loc, e, new IntegerExp(Loc.initial, stride, t));
e = new MulExp(be.loc, e, newIntegerExp(Loc.initial, stride, t));
e.type = t;
be.type = be.e2.type;
be.e1 = be.e2;
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ public Expression getValue(VarDeclaration vd)
T ctfeEmplaceExp(T : Expression, Args...)(Args args)
{
if (mem.isGCEnabled)
return new T(args);
{
static if (is(T == IntegerExp) && args.length == 3)
return newIntegerExp(args);
else
return new T(args);
}
auto p = ctfeGlobals.region.malloc(__traits(classInstanceSize, T));
emplaceExp!T(p, args);
return cast(T)p;
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -7357,7 +7357,7 @@ private extern(C++) class SearchVisitor : Visitor
/* $ gives the number of type entries in the type tuple
*/
auto v = new VarDeclaration(loc, Type.tsize_t, Id.dollar, null);
Expression e = new IntegerExp(Loc.initial, tt.arguments.length, Type.tsize_t);
Expression e = newIntegerExp(Loc.initial, tt.arguments.length, Type.tsize_t);
v._init = new ExpInitializer(Loc.initial, e);
v.storage_class |= STC.temp | STC.static_ | STC.const_;
v.dsymbolSemantic(sc);
Expand All @@ -7372,7 +7372,7 @@ private extern(C++) class SearchVisitor : Visitor
/* $ gives the number of elements in the tuple
*/
auto v = new VarDeclaration(loc, Type.tsize_t, Id.dollar, null);
Expression e = new IntegerExp(Loc.initial, td.objects.length, Type.tsize_t);
Expression e = newIntegerExp(Loc.initial, td.objects.length, Type.tsize_t);
v._init = new ExpInitializer(Loc.initial, e);
v.storage_class |= STC.temp | STC.static_ | STC.const_;
v.dsymbolSemantic(ass._scope);
Expand Down Expand Up @@ -7435,7 +7435,7 @@ private extern(C++) class SearchVisitor : Visitor
/* It is for an expression tuple, so the
* length will be a const.
*/
Expression e = new IntegerExp(Loc.initial, tupexp.exps.length, Type.tsize_t);
Expression e = newIntegerExp(Loc.initial, tupexp.exps.length, Type.tsize_t);
v = new VarDeclaration(loc, Type.tsize_t, Id.dollar, new ExpInitializer(Loc.initial, e));
v.storage_class |= STC.temp | STC.static_ | STC.const_;
}
Expand Down Expand Up @@ -7466,7 +7466,7 @@ private extern(C++) class SearchVisitor : Visitor
{
assert(0);
}
Expression edim = new IntegerExp(Loc.initial, dim, Type.tsize_t);
Expression edim = newIntegerExp(Loc.initial, dim, Type.tsize_t);
edim = edim.expressionSemantic(ass._scope);
auto tiargs = new Objects(edim);
e = new DotTemplateInstanceExp(loc, ce, td.ident, tiargs);
Expand Down Expand Up @@ -8878,8 +8878,8 @@ private Expression callScopeDtor(VarDeclaration vd, Scope* sc)
const sdsz = sd.type.size();
assert(sdsz != SIZE_INVALID && sdsz != 0);
const n = sz / sdsz;
SliceExp se = new SliceExp(vd.loc, e, new IntegerExp(vd.loc, 0, Type.tsize_t),
new IntegerExp(vd.loc, n, Type.tsize_t));
SliceExp se = new SliceExp(vd.loc, e, newIntegerExp(vd.loc, 0, Type.tsize_t),
newIntegerExp(vd.loc, n, Type.tsize_t));

// Prevent redundant bounds check
se.upperIsInBounds = true;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/enumsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void enumMemberSemantic(Scope* sc, EnumMember em)
}

const errors = global.startGagging();
Expression e = new IntegerExp(em.loc, 0, t);
Expression e = newIntegerExp(em.loc, 0, t);
e = e.ctfeInterpret();
if (global.endGagging(errors) || terror)
{
Expand Down
64 changes: 1 addition & 63 deletions compiler/src/dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,14 @@ extern (C++) final class IntegerExp : Expression
extern (D) this(Loc loc, dinteger_t value, Type type)
{
super(loc, EXP.int64);
//printf("IntegerExp(value = %lld, type = '%s')\n", value, type ? type.toChars() : "");
assert(type);

/* Verify no path to the following assert failure.
* Weirdly, the isScalar() includes floats - see enumsem.enumMemberSemantic() for the
* base type. This is possibly a bug.
*/
assert(_isRoughlyScalar(type) || type.ty == Terror);

this.type = type;
this.value = normalize(type.toBasetype().ty, value);
this.value = cast(int)value;
}

extern (D) this(dinteger_t value)
Expand All @@ -554,65 +551,6 @@ extern (C++) final class IntegerExp : Expression
return value;
}

extern (D) void setInteger(dinteger_t value)
{
this.value = normalize(type.toBasetype().ty, value);
}

extern (D) static dinteger_t normalize(TY ty, dinteger_t value)
{
/* 'Normalize' the value of the integer to be in range of the type
*/
dinteger_t result;
if (ty == Tpointer)
ty = Type.tsize_t.ty;
switch (ty)
{
case Tbool:
result = (value != 0);
break;

case Tint8:
result = cast(byte)value;
break;

case Tchar:
case Tuns8:
result = cast(ubyte)value;
break;

case Tint16:
result = cast(short)value;
break;

case Twchar:
case Tuns16:
result = cast(ushort)value;
break;

case Tint32:
result = cast(int)value;
break;

case Tdchar:
case Tuns32:
result = cast(uint)value;
break;

case Tint64:
result = cast(long)value;
break;

case Tuns64:
result = cast(ulong)value;
break;

default:
break;
}
return result;
}

override IntegerExp syntaxCopy()
{
return this;
Expand Down
Loading
Loading