Skip to content
Draft
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
17 changes: 12 additions & 5 deletions compiler/include/dmd/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,19 @@ class Expression : public ASTNode
Loc loc; // file location
EXP op; // to minimize use of dynamic_cast
uint8_t bitFields;
uint16_t astNodeBitFields;

bool parens() const;
bool parens(bool v);
bool rvalue() const;
bool rvalue(bool v);

size_t size() const;
virtual size_t size() const;

static void _init();
static void deinitialize();

virtual Expression copy();
virtual Expression *syntaxCopy();

// kludge for template.isExpression()
Expand Down Expand Up @@ -227,16 +232,18 @@ class Expression : public ASTNode
void accept(Visitor *v) override { v->visit(this); }
};

class IntegerExp final : public Expression
class IntegerExp : public Expression
{
public:
dinteger_t value;

static IntegerExp *create(Loc loc, dinteger_t value, Type *type);
void accept(Visitor *v) override { v->visit(this); }
dinteger_t getInteger() { return value; }
virtual dinteger_t value() const = 0;
virtual dinteger_t getInteger() = 0;
virtual void setInteger(dinteger_t val) = 0;
template<int v>
static IntegerExp literal();
static IntegerExp* literal();
static IntegerExp* createBool(bool b);
};

class ErrorExp final : public Expression
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dmd/astbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -4724,6 +4724,11 @@ struct ASTBase
setInteger(value);
}

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

void setInteger(dinteger_t value)
{
this.value = value;
Expand Down Expand Up @@ -5762,7 +5767,7 @@ struct ASTBase
{
extern (D) this(EXP op, Loc loc, Expression e)
{
super(loc, op, __traits(classInstanceSize, PostExp), e, new IntegerExp(loc, 1, Type.tint32));
super(loc, op, __traits(classInstanceSize, PostExp), e, IntegerExp.create(loc, 1, Type.tint32));
}

override void accept(Visitor v)
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dmd/builtin.d
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ Expression eval_bsf(Loc loc, FuncDeclaration fd, Expression[] arguments)
auto eSink = global.errorSink;
eSink.error(loc, "`bsf(0)` is undefined");
}
return new IntegerExp(loc, core.bitop.bsf(n), Type.tint32);
return IntegerExp.create(loc, core.bitop.bsf(n), Type.tint32);
}

Expression eval_bsr(Loc loc, FuncDeclaration fd, Expression[] arguments)
Expand All @@ -397,7 +397,7 @@ Expression eval_bsr(Loc loc, FuncDeclaration fd, Expression[] arguments)
auto eSink = global.errorSink;
eSink.error(loc, "`bsr(0)` is undefined");
}
return new IntegerExp(loc, core.bitop.bsr(n), Type.tint32);
return IntegerExp.create(loc, core.bitop.bsr(n), Type.tint32);
}

Expression eval_bswap(Loc loc, FuncDeclaration fd, Expression[] arguments)
Expand All @@ -407,17 +407,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 IntegerExp.create(loc, core.bitop.bswap(cast(ulong) n), arg0.type);
else
return new IntegerExp(loc, core.bitop.bswap(cast(uint) n), arg0.type);
return IntegerExp.create(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 IntegerExp.create(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 @@ -1063,8 +1063,8 @@ private DtorDeclaration buildFieldDtor(AggregateDeclaration ad, Loc declLoc, ref
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, IntegerExp.create(loc, 0, Type.tsize_t),
IntegerExp.create(loc, n, Type.tsize_t));
// Prevent redundant bounds check
se.upperIsInBounds = true;
se.lowerIsLessThanUpper = true;
Expand Down Expand Up @@ -1161,7 +1161,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, null);
Parameter delparam = new Parameter(Loc.initial, STC.none, Type.tuns32, Identifier.idPool("del"), IntegerExp.create(dtor.loc, 0, Type.tuns32), null, 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 @@ -1406,8 +1406,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, IntegerExp.create(loc, 0, Type.tsize_t),
IntegerExp.create(loc, length, Type.tsize_t));
// Prevent redundant bounds check
se.upperIsInBounds = true;
se.lowerIsLessThanUpper = true;
Expand Down Expand Up @@ -1484,8 +1484,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, IntegerExp.create(loc, 0, Type.tsize_t),
IntegerExp.create(loc, length, Type.tsize_t));
// Prevent redundant bounds check
se.upperIsInBounds = true;
se.lowerIsLessThanUpper = true;
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ extern (C++) struct Compiler
{
case Tint32:
case Tuns32:
emplaceExp!(IntegerExp)(pue, e.loc, u.int32value, type);
emplaceExp!(Integer64Exp)(pue, e.loc, u.int32value, type);
break;

case Tint64:
case Tuns64:
emplaceExp!(IntegerExp)(pue, e.loc, u.int64value, type);
emplaceExp!(Integer64Exp)(pue, e.loc, u.int64value, type);
break;

case Tfloat32:
Expand Down
Loading
Loading