diff --git a/compiler/src/dmd/astbase.d b/compiler/src/dmd/astbase.d index 85b254f4a128..1c895e4854ef 100644 --- a/compiler/src/dmd/astbase.d +++ b/compiler/src/dmd/astbase.d @@ -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 diff --git a/compiler/src/dmd/astcodegen.d b/compiler/src/dmd/astcodegen.d index 53afd53de98f..9ce3cd8ff672 100644 --- a/compiler/src/dmd/astcodegen.d +++ b/compiler/src/dmd/astcodegen.d @@ -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; diff --git a/compiler/src/dmd/builtin.d b/compiler/src/dmd/builtin.d index 3f814244e025..6bd533b5aec4 100644 --- a/compiler/src/dmd/builtin.d +++ b/compiler/src/dmd/builtin.d @@ -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; @@ -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) @@ -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) @@ -399,9 +399,9 @@ 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) @@ -409,7 +409,7 @@ 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) diff --git a/compiler/src/dmd/clone.d b/compiler/src/dmd/clone.d index f3f359ee3129..c186d4d48390 100644 --- a/compiler/src/dmd/clone.d +++ b/compiler/src/dmd/clone.d @@ -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; @@ -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 @@ -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; @@ -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; diff --git a/compiler/src/dmd/constfold.d b/compiler/src/dmd/constfold.d index d7db3c3bf32c..0772c6de74dd 100644 --- a/compiler/src/dmd/constfold.d +++ b/compiler/src/dmd/constfold.d @@ -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); } } diff --git a/compiler/src/dmd/cparse.d b/compiler/src/dmd/cparse.d index 9c4645a9914f..fe3a30fd7793 100644 --- a/compiler/src/dmd/cparse.d +++ b/compiler/src/dmd/cparse.d @@ -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; @@ -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; } @@ -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 @@ -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 @@ -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; @@ -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); diff --git a/compiler/src/dmd/ctfeexpr.d b/compiler/src/dmd/ctfeexpr.d index 8087db2d25a6..f76b20810807 100644 --- a/compiler/src/dmd/ctfeexpr.d +++ b/compiler/src/dmd/ctfeexpr.d @@ -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 diff --git a/compiler/src/dmd/dcast.d b/compiler/src/dmd/dcast.d index ff604c9cce9e..46b880894718 100644 --- a/compiler/src/dmd/dcast.d +++ b/compiler/src/dmd/dcast.d @@ -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; } @@ -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; diff --git a/compiler/src/dmd/dinterpret.d b/compiler/src/dmd/dinterpret.d index 61088e02bbfd..79f276a10c61 100644 --- a/compiler/src/dmd/dinterpret.d +++ b/compiler/src/dmd/dinterpret.d @@ -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; diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 37258e1d71de..a5813c37ea57 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -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); @@ -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); @@ -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_; } @@ -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); @@ -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; diff --git a/compiler/src/dmd/enumsem.d b/compiler/src/dmd/enumsem.d index f00c69c4510e..4fbd98de0234 100644 --- a/compiler/src/dmd/enumsem.d +++ b/compiler/src/dmd/enumsem.d @@ -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) { diff --git a/compiler/src/dmd/expression.d b/compiler/src/dmd/expression.d index 3a6a042f0fb2..9b2a3507b4f9 100644 --- a/compiler/src/dmd/expression.d +++ b/compiler/src/dmd/expression.d @@ -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) @@ -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; diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 869ead772216..016a9048022c 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -147,13 +147,99 @@ real_t toImaginary(Expression _this) return CTFloat.zero; } +void integerExpConstruct(IntegerExp _this, Loc loc, dinteger_t value, Type type) +{ + //printf("IntegerExp(value = %lld, type = '%s')\n", value, type ? type.toChars() : ""); + assert(type); + if (!type.isScalar()) + { + //printf("%s, loc = %d\n", toChars(), loc.linnum); + if (type.ty != Terror) + error(loc, "integral constant must be scalar type, not `%s`", type.toChars()); + type = Type.terror; + } + _this.type = type; + _this.value = normalize(type.toBasetype().ty, value); +} + +IntegerExp newIntegerExp(Loc loc, dinteger_t value, Type type) +{ + auto exp = new IntegerExp(loc, value, type); + exp.integerExpConstruct(loc, value, type); + return exp; +} + +IntegerExp newIntegerExp(dinteger_t value) +{ + return new IntegerExp(value); +} + +void setInteger(IntegerExp _this, dinteger_t value) +{ + _this.value = normalize(_this.type.toBasetype().ty, _this.value); +} + +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; +} + real_t toReal(Expression _this) { if (auto iexp = _this.isIntegerExp()) { // normalize() is necessary until we fix all the paints of 'type' const ty = iexp.type.toBasetype().ty; - const val = iexp.normalize(ty, iexp.value); + const val = normalize(ty, iexp.value); iexp.value = val; return (ty == Tuns64) ? real_t(cast(ulong)val) @@ -194,7 +280,7 @@ dinteger_t toInteger(Expression _this) if (auto iexp = _this.isIntegerExp()) { // normalize() is necessary until we fix all the paints of 'type' - return iexp.value = IntegerExp.normalize(iexp.type.toBasetype().ty, iexp.value); + return iexp.value = normalize(iexp.type.toBasetype().ty, iexp.value); } else if (auto rexp = _this.isRealExp()) { @@ -1697,7 +1783,7 @@ Expression resolveOpDollar(Scope* sc, ArrayExp ae, out Expression pe0) if (auto ie = e.isIntervalExp()) { - Expression edim = new IntegerExp(ae.loc, i, Type.tsize_t); + Expression edim = newIntegerExp(ae.loc, i, Type.tsize_t); edim = edim.expressionSemantic(sc); auto tiargs = new Objects(edim); @@ -5050,7 +5136,7 @@ Expression lowerArrayLiteral(ArrayLiteralExp ale, Scope* sc) auto tiargs = new Objects(t); lowering = new DotTemplateInstanceExp(ale.loc, lowering, hook, tiargs); - auto arguments = new Expressions(new IntegerExp(dim)); + auto arguments = new Expressions(newIntegerExp(dim)); lowering = new CallExp(ale.loc, lowering, arguments); ale.lowering = lowering.expressionSemantic(sc); @@ -6898,7 +6984,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor auto tiargs = new Objects(t); lowering = new DotTemplateInstanceExp(exp.loc, lowering, hook, tiargs); - auto arguments = new Expressions((*exp.arguments)[0], new IntegerExp(exp.loc, isShared, Type.tbool)); + auto arguments = new Expressions((*exp.arguments)[0], newIntegerExp(exp.loc, isShared, Type.tbool)); lowering = new CallExp(exp.loc, lowering, arguments); exp.lowering = lowering.expressionSemantic(sc); @@ -6926,7 +7012,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor lowering = new DotTemplateInstanceExp(exp.loc, lowering, hook, tiargs); auto arguments = new Expressions(new ArrayLiteralExp(exp.loc, Type.tsize_t.sarrayOf(nargs), exp.arguments), - new IntegerExp(exp.loc, tbn.isShared(), Type.tbool)); + newIntegerExp(exp.loc, tbn.isShared(), Type.tbool)); lowering = new CallExp(exp.loc, lowering, arguments); exp.lowering = lowering.expressionSemantic(sc); @@ -13408,7 +13494,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor Expression eValue1; Expression value1 = extractSideEffect(sc, "__appendtmp", eValue1, exp.e1); - auto arguments = new Expressions(value1, new IntegerExp(exp.loc, 1, Type.tsize_t)); + auto arguments = new Expressions(value1, newIntegerExp(exp.loc, 1, Type.tsize_t)); Expression ce = new CallExp(exp.loc, id, arguments); @@ -13612,13 +13698,13 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor stride = t2.nextOf().size(); if (stride == 0) { - e = new IntegerExp(exp.loc, 0, Type.tptrdiff_t); + e = newIntegerExp(exp.loc, 0, Type.tptrdiff_t); } else if (stride == cast(long)SIZE_INVALID) e = ErrorExp.get(); else { - e = new DivExp(exp.loc, exp, new IntegerExp(Loc.initial, stride, Type.tptrdiff_t)); + e = new DivExp(exp.loc, exp, newIntegerExp(Loc.initial, stride, Type.tptrdiff_t)); e.type = Type.tptrdiff_t; } } @@ -14163,7 +14249,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor { Expression one; if (pe.e1.type.isIntegral()) { - one = new IntegerExp(e.loc, 1, pe.e1.type); + one = newIntegerExp(e.loc, 1, pe.e1.type); } else { one = new RealExp(e.loc, CTFloat.one, pe.e1.type); } @@ -14356,7 +14442,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor if (e1x.toBool().hasValue(exp.op == EXP.orOr)) { if (sc.inCfile) - result = new IntegerExp(exp.op == EXP.orOr); + result = newIntegerExp(exp.op == EXP.orOr); else result = IntegerExp.createBool(exp.op == EXP.orOr); return; @@ -15604,7 +15690,7 @@ private Expression dotIdSemanticPropX(DotIdExp exp, Scope* sc) if (exp.ident == Id.length) { // Don't evaluate te.e0 in runtime - return new IntegerExp(exp.loc, te.exps.length, Type.tsize_t); + return newIntegerExp(exp.loc, te.exps.length, Type.tsize_t); } } @@ -15948,14 +16034,14 @@ Expression dotIdSemanticProp(DotIdExp exp, Scope* sc, bool gag) const explicitAlignment = exp.e1.isVarExp().var.isVarDeclaration().alignment; const naturalAlignment = exp.e1.type.alignsize(); const actualAlignment = explicitAlignment.isDefault() ? naturalAlignment : explicitAlignment.get(); - Expression e = new IntegerExp(exp.loc, actualAlignment, Type.tsize_t); + Expression e = newIntegerExp(exp.loc, actualAlignment, Type.tsize_t); return e; } else if ((exp.ident == Id.max || exp.ident == Id.min) && exp.e1.isBitField()) { // For `x.max` and `x.min` get the max/min of the bitfield, not the max/min of its type auto bf = exp.e1.isBitField(); - return new IntegerExp(exp.loc, bf.getMinMax(exp.ident), bf.type); + return newIntegerExp(exp.loc, bf.getMinMax(exp.ident), bf.type); } else { @@ -16900,7 +16986,7 @@ Expression resolveLoc(Expression exp, Loc loc, Scope* sc) Expression visitLineInit(LineInitExp exp) { - Expression e = new IntegerExp(loc, loc.linnum, Type.tint32); + Expression e = newIntegerExp(loc, loc.linnum, Type.tint32); return e.expressionSemantic(sc); } @@ -17813,7 +17899,7 @@ Expression getThisSkipNestedFuncs(Loc loc, Scope* sc, Dsymbol s, AggregateDeclar e1 = e1.expressionSemantic(sc); e1 = new PtrExp(loc, e1); uint i = f.followInstantiationContext(ad); - e1 = new IndexExp(loc, e1, new IntegerExp(i)); + e1 = new IndexExp(loc, e1, newIntegerExp(i)); s = f.toParentP(ad); continue; } @@ -19210,13 +19296,13 @@ void lowerNonArrayAggregate(StaticForeach sfe, Scope* sc) if (sfe.rangefe.op == TOK.foreach_) { foreach (i; 0 .. length) - (*exps)[i] = new IntegerExp(aloc, lwr + i, indexty); + (*exps)[i] = newIntegerExp(aloc, lwr + i, indexty); } else { --upr; foreach (i; 0 .. length) - (*exps)[i] = new IntegerExp(aloc, upr - i, indexty); + (*exps)[i] = newIntegerExp(aloc, upr - i, indexty); } aggr = new ArrayLiteralExp(aloc, indexty.arrayOf(), exps); } @@ -19308,7 +19394,7 @@ extern(D) void lowerArrayAggregate(StaticForeach sfe, Scope* sc) es = new Expressions(length); foreach (i; 0 .. length) { - auto index = new IntegerExp(sfe.loc, i, Type.tsize_t); + auto index = newIntegerExp(sfe.loc, i, Type.tsize_t); auto value = new IndexExp(aggr.loc, aggr, index); (*es)[i] = value; } diff --git a/compiler/src/dmd/iasm/package.d b/compiler/src/dmd/iasm/package.d index 33af0ca11dd5..1602c707413b 100644 --- a/compiler/src/dmd/iasm/package.d +++ b/compiler/src/dmd/iasm/package.d @@ -24,6 +24,7 @@ import dmd.target; import dmd.tokens; import dmd.statement; import dmd.statementsem; +import dmd.expressionsem; version (NoBackend) { @@ -76,7 +77,7 @@ Statement asmSemantic(AsmStatement s, Scope* sc) /* Replace the asm statement with an assert(0, msg) that trips at runtime. */ const loc = s.loc; - auto e = new IntegerExp(loc, 0, Type.tint32); + auto e = newIntegerExp(loc, 0, Type.tint32); auto msg = new StringExp(loc, "Gnu Asm not supported - compile this function with gcc or clang"); auto ae = new AssertExp(loc, e, msg); auto se = new ExpStatement(loc, ae); diff --git a/compiler/src/dmd/importc.d b/compiler/src/dmd/importc.d index db16ce763d28..80f17e740189 100644 --- a/compiler/src/dmd/importc.d +++ b/compiler/src/dmd/importc.d @@ -654,7 +654,7 @@ void cEnumSemantic(Scope* sc, EnumDeclaration ed) /* To merge the type of e with commonType, add 0 of type commonType */ if (!ed.memtype) - e = new AddExp(em.loc, e, new IntegerExp(em.loc, 0, commonType)); + e = new AddExp(em.loc, e, newIntegerExp(em.loc, 0, commonType)); e = e.expressionSemantic(sc); e = resolveProperties(sc, e); @@ -678,7 +678,7 @@ void cEnumSemantic(Scope* sc, EnumDeclaration ed) nextValue = ie.toInteger(); if (!ed.memtype) commonType = e.type; - em.value = new IntegerExp(em.loc, nextValue, commonType); + em.value = newIntegerExp(em.loc, nextValue, commonType); } else { @@ -694,7 +694,7 @@ void cEnumSemantic(Scope* sc, EnumDeclaration ed) } nextValue += 1; } - em.value = new IntegerExp(em.loc, nextValue, commonType); + em.value = newIntegerExp(em.loc, nextValue, commonType); } em.type = commonType; em.semanticRun = PASS.semanticdone; diff --git a/compiler/src/dmd/initsem.d b/compiler/src/dmd/initsem.d index 43ea1cd4c4ca..8c182ddb8db6 100644 --- a/compiler/src/dmd/initsem.d +++ b/compiler/src/dmd/initsem.d @@ -313,7 +313,7 @@ Initializer initializerSemantic(Initializer init, Scope* sc, ref Type tx, NeedIn { // Change to array of known length auto tn = tsa.next.toBasetype(); - tsa = new TypeSArray(tn, new IntegerExp(Loc.initial, i.dim, Type.tsize_t)); + tsa = new TypeSArray(tn, newIntegerExp(Loc.initial, i.dim, Type.tsize_t)); tx = tsa; // rewrite caller's type i.type = tsa; // remember for later passes } @@ -480,7 +480,7 @@ Initializer initializerSemantic(Initializer init, Scope* sc, ref Type tx, NeedIn tb.isTypeSArray() && tb.isTypeSArray().isIncomplete()) { StringExp se = i.exp.isStringExp(); - auto ts = new TypeSArray(tb.nextOf(), new IntegerExp(Loc.initial, se.len + 1, Type.tsize_t)); + auto ts = new TypeSArray(tb.nextOf(), newIntegerExp(Loc.initial, se.len + 1, Type.tsize_t)); t = typeSemantic(ts, Loc.initial, sc); i.exp.type = t; tx = t; diff --git a/compiler/src/dmd/optimize.d b/compiler/src/dmd/optimize.d index 88a947f6b02a..667778592c7c 100644 --- a/compiler/src/dmd/optimize.d +++ b/compiler/src/dmd/optimize.d @@ -235,7 +235,7 @@ package void setLengthVarIfKnown(VarDeclaration lengthVar, Expression arr) return; // we don't know the length yet len = tsa.dim.toInteger(); } - Expression dollar = new IntegerExp(Loc.initial, len, Type.tsize_t); + Expression dollar = newIntegerExp(Loc.initial, len, Type.tsize_t); lengthVar._init = new ExpInitializer(Loc.initial, dollar); lengthVar.storage_class |= STC.static_ | STC.const_; } @@ -256,7 +256,7 @@ package void setLengthVarIfKnown(VarDeclaration lengthVar, Type type) if (!tsa) return; // we don't know the length yet const len = tsa.dim.toInteger(); - Expression dollar = new IntegerExp(Loc.initial, len, Type.tsize_t); + Expression dollar = newIntegerExp(Loc.initial, len, Type.tsize_t); lengthVar._init = new ExpInitializer(Loc.initial, dollar); lengthVar.storage_class |= STC.static_ | STC.const_; } @@ -554,7 +554,7 @@ Expression optimize(Expression e, int result, bool keepLvalue = false) } if (eint) { - ret = new IntegerExp(e.loc, eint.toInteger() + offset, e.type); + ret = newIntegerExp(e.loc, eint.toInteger() + offset, e.type); return; } } @@ -588,7 +588,7 @@ Expression optimize(Expression e, int result, bool keepLvalue = false) Expression ex = new AddrExp(ae1.loc, ae1); // &a[i] ex.type = ae1.type.pointerTo(); - Expression add = new AddExp(ae.loc, ex, new IntegerExp(ae.e2.loc, offset, ae.e2.type)); + Expression add = new AddExp(ae.loc, ex, newIntegerExp(ae.e2.loc, offset, ae.e2.type)); add.type = e.type; ret = optimize(add, result, keepLvalue); return; @@ -662,7 +662,7 @@ Expression optimize(Expression e, int result, bool keepLvalue = false) auto pe = new AddrExp(e.loc, ve); pe.type = e.type; - ret = new AddExp(e.loc, pe, new IntegerExp(e.loc, offset, Type.tsize_t)); + ret = new AddExp(e.loc, pe, newIntegerExp(e.loc, offset, Type.tsize_t)); ret.type = e.type; return; } @@ -1081,7 +1081,7 @@ Expression optimize(Expression e, int result, bool keepLvalue = false) { // This only applies to floating point, or positive integral powers. if (e.e1.type.isFloating() || cast(sinteger_t)e.e2.toInteger() >= 0) - e.e2 = new IntegerExp(e.loc, e.e2.toInteger(), Type.tint64); + e.e2 = newIntegerExp(e.loc, e.e2.toInteger(), Type.tint64); } if (e.e1.isConst() == 1 && e.e2.isConst() == 1) { @@ -1269,7 +1269,7 @@ Expression optimize(Expression e, int result, bool keepLvalue = false) { bool n1 = e1Opt.get(); bool n2 = e.e2.toBool().get(); - ret = new IntegerExp(e.loc, oror ? (n1 || n2) : (n1 && n2), e.type); + ret = newIntegerExp(e.loc, oror ? (n1 || n2) : (n1 && n2), e.type); } else if (e1Opt.hasValue(!oror)) { diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index e5f9b665a097..9613d1584b02 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -8191,22 +8191,22 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer break; 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.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; @@ -8274,27 +8274,27 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer break; case TOK.true_: - e = new AST.IntegerExp(loc, 1, AST.Type.tbool); + e = AST.newIntegerExp(loc, 1, AST.Type.tbool); nextToken(); break; case TOK.false_: - e = new AST.IntegerExp(loc, 0, AST.Type.tbool); + e = AST.newIntegerExp(loc, 0, AST.Type.tbool); nextToken(); break; case TOK.charLiteral: - e = new AST.IntegerExp(loc, token.unsvalue, AST.Type.tchar); + e = AST.newIntegerExp(loc, token.unsvalue, AST.Type.tchar); nextToken(); break; case TOK.wcharLiteral: - e = new AST.IntegerExp(loc, token.unsvalue, AST.Type.twchar); + e = AST.newIntegerExp(loc, token.unsvalue, AST.Type.twchar); nextToken(); break; case TOK.dcharLiteral: - e = new AST.IntegerExp(loc, token.unsvalue, AST.Type.tdchar); + e = AST.newIntegerExp(loc, token.unsvalue, AST.Type.tdchar); nextToken(); break; diff --git a/compiler/src/dmd/statementsem.d b/compiler/src/dmd/statementsem.d index 35d4b1bf3f4c..3a13abd21068 100644 --- a/compiler/src/dmd/statementsem.d +++ b/compiler/src/dmd/statementsem.d @@ -65,6 +65,7 @@ import dmd.target; import dmd.targetcompiler; import dmd.tokens; import dmd.typesem; +import dmd.expressionsem; import dmd.visitor; version (DMDLIB) @@ -945,7 +946,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) { // 'Promote' it to this scope, and replace with a return fs.cases.push(gs); - ss.statement = new ReturnStatement(Loc.initial, new IntegerExp(fs.cases.length + 1)); + ss.statement = new ReturnStatement(Loc.initial, newIntegerExp(fs.cases.length + 1)); } } @@ -1166,7 +1167,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) if (fs.op == TOK.foreach_reverse_) fs.key._init = new ExpInitializer(loc, tmp_length); else - fs.key._init = new ExpInitializer(loc, new IntegerExp(loc, 0, fs.key.type)); + fs.key._init = new ExpInitializer(loc, newIntegerExp(loc, 0, fs.key.type)); auto cs = new Statements(); if (vinit) @@ -1191,7 +1192,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) if (fs.op == TOK.foreach_) { // key += 1 - increment = new AddAssignExp(loc, new VarExp(loc, fs.key), new IntegerExp(loc, 1, fs.key.type)); + increment = new AddAssignExp(loc, new VarExp(loc, fs.key), newIntegerExp(loc, 1, fs.key.type)); } // T value = tmp[key]; @@ -2046,7 +2047,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) Expressions* args = new Expressions(2); (*args)[0] = new StringExp(ss.loc, ss.loc.filename.toDString()); - (*args)[1] = new IntegerExp(ss.loc.linnum); + (*args)[1] = newIntegerExp(ss.loc.linnum); sl = new CallExp(ss.loc, sl, args); sl = sl.expressionSemantic(sc); @@ -2146,7 +2147,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) auto i = 0; foreach (c; *csCopy) { - (*ss.cases)[c.index].exp = new IntegerExp(i++); + (*ss.cases)[c.index].exp = newIntegerExp(i++); } //printf("%s\n", ss._body.toChars()); @@ -2375,7 +2376,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) Statement s = crs.statement; if (i != lval) // if not last case s = new ExpStatement(crs.loc, cast(Expression)null); - Expression e = new IntegerExp(crs.loc, i, crs.first.type); + Expression e = newIntegerExp(crs.loc, i, crs.first.type); Statement cs = new CaseStatement(crs.loc, e, s); statements.push(cs); } @@ -2492,7 +2493,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) { assert(rs.caseDim == 0); sc.fes.cases.push(rs); - result = new ReturnStatement(Loc.initial, new IntegerExp(sc.fes.cases.length + 1)); + result = new ReturnStatement(Loc.initial, newIntegerExp(sc.fes.cases.length + 1)); return; } if (fd.returnLabel) @@ -2864,7 +2865,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) // Immediately rewrite "this" return statement as: // return cases.length+1; - rs.exp = new IntegerExp(sc.fes.cases.length + 1); + rs.exp = newIntegerExp(sc.fes.cases.length + 1); if (e0) { result = new CompoundStatement(rs.loc, new ExpStatement(rs.loc, e0), rs); @@ -2946,7 +2947,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) * and 1 is break. */ sc.fes.cases.push(bs); - result = new ReturnStatement(Loc.initial, new IntegerExp(sc.fes.cases.length + 1)); + result = new ReturnStatement(Loc.initial, newIntegerExp(sc.fes.cases.length + 1)); return; } break; // can't break to it @@ -3034,7 +3035,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) * and 1 is break. */ sc.fes.cases.push(cs); - result = new ReturnStatement(Loc.initial, new IntegerExp(sc.fes.cases.length + 1)); + result = new ReturnStatement(Loc.initial, newIntegerExp(sc.fes.cases.length + 1)); return; } break; // can't continue to it @@ -3986,7 +3987,7 @@ private extern(D) Statement loopReturn(Expression e, Statements* cases, Loc loc) // cases 2... foreach (i, c; *cases) { - s = new CaseStatement(Loc.initial, new IntegerExp(i + 2), c); + s = new CaseStatement(Loc.initial, newIntegerExp(i + 2), c); a.push(s); } @@ -4469,7 +4470,7 @@ public auto makeTupleForeach(Scope* sc, bool isStatic, bool isDecl, ForeachState p.type.toChars(), cast(ulong)length); return returnEarly(); } - Initializer ie = new ExpInitializer(Loc.initial, new IntegerExp(k)); + Initializer ie = new ExpInitializer(Loc.initial, newIntegerExp(k)); auto var = new VarDeclaration(loc, p.type, p.ident, ie); var.storage_class |= STC.foreach_ | STC.manifest; if (isStatic) @@ -4653,7 +4654,7 @@ public auto makeTupleForeach(Scope* sc, bool isStatic, bool isDecl, ForeachState foreach (l; 0 .. dim) { auto cp = (*fs.parameters)[l]; - Expression init_ = new IndexExp(loc, access, new IntegerExp(loc, l, Type.tsize_t)); + Expression init_ = new IndexExp(loc, access, newIntegerExp(loc, l, Type.tsize_t)); init_ = init_.expressionSemantic(sc); assert(init_.type); declareVariable(p.storageClass, init_.type, cp.ident, init_, null); diff --git a/compiler/src/dmd/templatesem.d b/compiler/src/dmd/templatesem.d index ac107b049241..f295d231c2d1 100644 --- a/compiler/src/dmd/templatesem.d +++ b/compiler/src/dmd/templatesem.d @@ -4779,7 +4779,7 @@ private MATCHpair deduceFunctionTemplateMatch(TemplateDeclaration td, TemplateIn } else if (TypeAArray taa = tb.isTypeAArray()) { - Expression dim = new IntegerExp(instLoc, fargs.length - argi, Type.tsize_t); + Expression dim = newIntegerExp(instLoc, fargs.length - argi, Type.tsize_t); size_t i = templateParameterLookup(taa.index, td.parameters); if (i == IDX_NOTFOUND) diff --git a/compiler/src/dmd/traits.d b/compiler/src/dmd/traits.d index 568fe0807789..41eeff535f3b 100644 --- a/compiler/src/dmd/traits.d +++ b/compiler/src/dmd/traits.d @@ -308,9 +308,9 @@ private Expression pointerBitmap(TraitsExp e, ErrorSink eSink) return ErrorExp.get(); auto exps = new Expressions(data.length + 1); - (*exps)[0] = new IntegerExp(e.loc, sz, Type.tsize_t); // [0] is size in bytes of t + (*exps)[0] = newIntegerExp(e.loc, sz, Type.tsize_t); // [0] is size in bytes of t foreach (size_t i; 1 .. exps.length) - (*exps)[i] = new IntegerExp(e.loc, data[cast(size_t) (i - 1)], Type.tsize_t); + (*exps)[i] = newIntegerExp(e.loc, data[cast(size_t) (i - 1)], Type.tsize_t); auto ale = new ArrayLiteralExp(e.loc, Type.tsize_t.sarrayOf(data.length + 1), exps); return ale; @@ -834,7 +834,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) bitOffset = 0; } uint value = e.ident == Id.getBitfieldOffset ? bitOffset : fieldWidth; - return new IntegerExp(e.loc, value, Type.tuns32); + return newIntegerExp(e.loc, value, Type.tuns32); } if (e.ident == Id.getProtection || e.ident == Id.getVisibility) { @@ -1275,7 +1275,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) return ErrorExp.get(); } - return new IntegerExp(e.loc, e.ident == Id.classInstanceSize ? cd.structsize : cd.alignsize, Type.tsize_t); + return newIntegerExp(e.loc, e.ident == Id.classInstanceSize ? cd.structsize : cd.alignsize, Type.tsize_t); } if (e.ident == Id.getAliasThis) { @@ -1963,7 +1963,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) } fd = fd.toAliasFunc(); // Necessary to support multiple overloads. - return new IntegerExp(e.loc, fd.vtblIndex, Type.tptrdiff_t); + return newIntegerExp(e.loc, fd.vtblIndex, Type.tptrdiff_t); } if (e.ident == Id.getPointerBitmap) { @@ -2070,8 +2070,8 @@ Expression semanticTraits(TraitsExp e, Scope* sc) auto exps = new Expressions(3); (*exps)[0] = new StringExp(e.loc, s.loc.filename.toDString()); - (*exps)[1] = new IntegerExp(e.loc, s.loc.linnum,Type.tint32); - (*exps)[2] = new IntegerExp(e.loc, s.loc.charnum,Type.tint32); + (*exps)[1] = newIntegerExp(e.loc, s.loc.linnum,Type.tint32); + (*exps)[2] = newIntegerExp(e.loc, s.loc.charnum,Type.tint32); auto tup = new TupleExp(e.loc, exps); return tup.expressionSemantic(sc); } diff --git a/compiler/src/dmd/typesem.d b/compiler/src/dmd/typesem.d index 1dbeefe792c4..fa1210181724 100644 --- a/compiler/src/dmd/typesem.d +++ b/compiler/src/dmd/typesem.d @@ -4807,14 +4807,14 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, Identifier ident, int fla const sz = mt.size(loc); if (sz == SIZE_INVALID) return ErrorExp.get(); - return new IntegerExp(loc, sz, Type.tsize_t); + return newIntegerExp(loc, sz, Type.tsize_t); } else if (ident == Id.__xalignof) { const explicitAlignment = mt.alignment(); const naturalAlignment = mt.alignsize(); const actualAlignment = (explicitAlignment.isDefault() ? naturalAlignment : explicitAlignment.get()); - return new IntegerExp(loc, actualAlignment, Type.tsize_t); + return newIntegerExp(loc, actualAlignment, Type.tsize_t); } else if (ident == Id._init) { @@ -4943,12 +4943,12 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, Identifier ident, int fla { Expression integerValue(dinteger_t i) { - return new IntegerExp(loc, i, mt); + return newIntegerExp(loc, i, mt); } Expression intValue(dinteger_t i) { - return new IntegerExp(loc, i, Type.tint32); + return newIntegerExp(loc, i, Type.tint32); } Expression floatValue(real_t r) @@ -5214,7 +5214,7 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, Identifier ident, int fla } if (ident == Id.length) { - e = new IntegerExp(loc, mt.arguments.length, Type.tsize_t); + e = newIntegerExp(loc, mt.arguments.length, Type.tsize_t); } else if (ident == Id._init) { @@ -5980,7 +5980,7 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag else error(v.loc, "`%s` is not a bitfield, cannot apply `%s`", v.toChars(), ident.toChars()); } - return new IntegerExp(e.loc, value, Type.tsize_t); + return newIntegerExp(e.loc, value, Type.tsize_t); } } else if (ident == Id._init) @@ -6229,7 +6229,7 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag auto exps = new Expressions(); exps.reserve(length); foreach (i; 0 .. length) - exps.push(new IndexExp(e.loc, ev, new IntegerExp(e.loc, i, Type.tsize_t))); + exps.push(new IndexExp(e.loc, ev, newIntegerExp(e.loc, i, Type.tsize_t))); e = new TupleExp(e.loc, e0, exps); } } @@ -6258,11 +6258,11 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag if (e.op == EXP.string_) { StringExp se = cast(StringExp)e; - return new IntegerExp(se.loc, se.len, Type.tsize_t); + return newIntegerExp(se.loc, se.len, Type.tsize_t); } if (e.op == EXP.null_) { - return new IntegerExp(e.loc, 0, Type.tsize_t); + return newIntegerExp(e.loc, 0, Type.tsize_t); } if (checkNonAssignmentArrayOp(e)) { @@ -7408,7 +7408,7 @@ Expression defaultInit(Type mt, Loc loc, const bool isCfile = false) default: break; } - return new IntegerExp(loc, value, mt); + return newIntegerExp(loc, value, mt); } Expression visitVector(TypeVector mt) @@ -8233,7 +8233,7 @@ Type referenceTo(Type type) Type sarrayOf(Type type, dinteger_t dim) { assert(type.deco); - Type t = new TypeSArray(type, new IntegerExp(Loc.initial, dim, Type.tsize_t)); + Type t = new TypeSArray(type, newIntegerExp(Loc.initial, dim, Type.tsize_t)); // according to TypeSArray.semantic() t = t.addMod(type.mod); t = t.merge();