Skip to content

Commit

Permalink
Remove D1 operators from the D2 language (#20744)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Jan 20, 2025
1 parent 2a62701 commit fc2b227
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 342 deletions.
47 changes: 0 additions & 47 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8820,59 +8820,15 @@ struct Id final
static Identifier* system;
static Identifier* disable;
static Identifier* _dollar;
static Identifier* uadd;
static Identifier* neg;
static Identifier* com;
static Identifier* add;
static Identifier* add_r;
static Identifier* sub;
static Identifier* sub_r;
static Identifier* mul;
static Identifier* mul_r;
static Identifier* div;
static Identifier* div_r;
static Identifier* mod;
static Identifier* mod_r;
static Identifier* eq;
static Identifier* cmp;
static Identifier* iand;
static Identifier* iand_r;
static Identifier* ior;
static Identifier* ior_r;
static Identifier* ixor;
static Identifier* ixor_r;
static Identifier* shl;
static Identifier* shl_r;
static Identifier* shr;
static Identifier* shr_r;
static Identifier* ushr;
static Identifier* ushr_r;
static Identifier* cat;
static Identifier* cat_r;
static Identifier* assign;
static Identifier* addass;
static Identifier* subass;
static Identifier* mulass;
static Identifier* divass;
static Identifier* modass;
static Identifier* andass;
static Identifier* orass;
static Identifier* xorass;
static Identifier* shlass;
static Identifier* shrass;
static Identifier* ushrass;
static Identifier* catass;
static Identifier* postinc;
static Identifier* postdec;
static Identifier* index;
static Identifier* indexass;
static Identifier* slice;
static Identifier* sliceass;
static Identifier* call;
static Identifier* _cast;
static Identifier* opIn;
static Identifier* opIn_r;
static Identifier* opStar;
static Identifier* opDot;
static Identifier* opDispatch;
static Identifier* opDollar;
Expand All @@ -8884,9 +8840,6 @@ struct Id final
static Identifier* opOpAssign;
static Identifier* opIndexOpAssign;
static Identifier* opSliceOpAssign;
static Identifier* pow;
static Identifier* pow_r;
static Identifier* powass;
static Identifier* classNew;
static Identifier* classDelete;
static Identifier* apply;
Expand Down
47 changes: 0 additions & 47 deletions compiler/src/dmd/id.d
Original file line number Diff line number Diff line change
Expand Up @@ -223,59 +223,15 @@ immutable Msgtable[] msgtable =
{ "__LOCAL_SIZE" },

// For operator overloads
{ "uadd", "opPos" },
{ "neg", "opNeg" },
{ "com", "opCom" },
{ "add", "opAdd" },
{ "add_r", "opAdd_r" },
{ "sub", "opSub" },
{ "sub_r", "opSub_r" },
{ "mul", "opMul" },
{ "mul_r", "opMul_r" },
{ "div", "opDiv" },
{ "div_r", "opDiv_r" },
{ "mod", "opMod" },
{ "mod_r", "opMod_r" },
{ "eq", "opEquals" },
{ "cmp", "opCmp" },
{ "iand", "opAnd" },
{ "iand_r", "opAnd_r" },
{ "ior", "opOr" },
{ "ior_r", "opOr_r" },
{ "ixor", "opXor" },
{ "ixor_r", "opXor_r" },
{ "shl", "opShl" },
{ "shl_r", "opShl_r" },
{ "shr", "opShr" },
{ "shr_r", "opShr_r" },
{ "ushr", "opUShr" },
{ "ushr_r", "opUShr_r" },
{ "cat", "opCat" },
{ "cat_r", "opCat_r" },
{ "assign", "opAssign" },
{ "addass", "opAddAssign" },
{ "subass", "opSubAssign" },
{ "mulass", "opMulAssign" },
{ "divass", "opDivAssign" },
{ "modass", "opModAssign" },
{ "andass", "opAndAssign" },
{ "orass", "opOrAssign" },
{ "xorass", "opXorAssign" },
{ "shlass", "opShlAssign" },
{ "shrass", "opShrAssign" },
{ "ushrass", "opUShrAssign" },
{ "catass", "opCatAssign" },
{ "postinc", "opPostInc" },
{ "postdec", "opPostDec" },
{ "index", "opIndex" },
{ "indexass", "opIndexAssign" },
{ "slice", "opSlice" },
{ "sliceass", "opSliceAssign" },
{ "call", "opCall" },
{ "_cast", "opCast" },
{ "opIn" },
{ "opIn_r" },
{ "opStar" },
{ "opDot" },
{ "opDispatch" },
{ "opDollar" },
Expand All @@ -287,9 +243,6 @@ immutable Msgtable[] msgtable =
{ "opOpAssign" },
{ "opIndexOpAssign" },
{ "opSliceOpAssign" },
{ "pow", "opPow" },
{ "pow_r", "opPow_r" },
{ "powass", "opPowAssign" },

{ "classNew", "new" },
{ "classDelete", "delete" },
Expand Down
15 changes: 1 addition & 14 deletions compiler/src/dmd/mustuse.d
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,12 @@ private bool isAssignmentOpId(Identifier id)
import dmd.id : Id;

return id == Id.assign
|| id == Id.addass
|| id == Id.subass
|| id == Id.mulass
|| id == Id.divass
|| id == Id.modass
|| id == Id.andass
|| id == Id.orass
|| id == Id.xorass
|| id == Id.shlass
|| id == Id.shrass
|| id == Id.ushrass
|| id == Id.catass
|| id == Id.indexass
|| id == Id.slice
|| id == Id.sliceass
|| id == Id.opOpAssign
|| id == Id.opIndexOpAssign
|| id == Id.opSliceOpAssign
|| id == Id.powass;
|| id == Id.opSliceOpAssign;
}

/**
Expand Down
104 changes: 4 additions & 100 deletions compiler/src/dmd/opover.d
Original file line number Diff line number Diff line change
Expand Up @@ -71,84 +71,6 @@ bool isCommutative(EXP op) @safe
return false;
}

/***********************************
* Get Identifier for operator overload.
*/
private Identifier opId(Expression e)
{
switch (e.op)
{
case EXP.uadd: return Id.uadd;
case EXP.negate: return Id.neg;
case EXP.tilde: return Id.com;
case EXP.cast_: return Id._cast;
case EXP.in_: return Id.opIn;
case EXP.plusPlus: return Id.postinc;
case EXP.minusMinus: return Id.postdec;
case EXP.add: return Id.add;
case EXP.min: return Id.sub;
case EXP.mul: return Id.mul;
case EXP.div: return Id.div;
case EXP.mod: return Id.mod;
case EXP.pow: return Id.pow;
case EXP.leftShift: return Id.shl;
case EXP.rightShift: return Id.shr;
case EXP.unsignedRightShift: return Id.ushr;
case EXP.and: return Id.iand;
case EXP.or: return Id.ior;
case EXP.xor: return Id.ixor;
case EXP.concatenate: return Id.cat;
case EXP.assign: return Id.assign;
case EXP.addAssign: return Id.addass;
case EXP.minAssign: return Id.subass;
case EXP.mulAssign: return Id.mulass;
case EXP.divAssign: return Id.divass;
case EXP.modAssign: return Id.modass;
case EXP.powAssign: return Id.powass;
case EXP.leftShiftAssign: return Id.shlass;
case EXP.rightShiftAssign: return Id.shrass;
case EXP.unsignedRightShiftAssign: return Id.ushrass;
case EXP.andAssign: return Id.andass;
case EXP.orAssign: return Id.orass;
case EXP.xorAssign: return Id.xorass;
case EXP.concatenateAssign: return Id.catass;
case EXP.equal: return Id.eq;
case EXP.lessThan:
case EXP.lessOrEqual:
case EXP.greaterThan:
case EXP.greaterOrEqual: return Id.cmp;
case EXP.array: return Id.index;
case EXP.star: return Id.opStar;
default: assert(0);
}
}

/***********************************
* Get Identifier for reverse operator overload,
* `null` if not supported for this operator.
*/
private Identifier opId_r(Expression e)
{
switch (e.op)
{
case EXP.in_: return Id.opIn_r;
case EXP.add: return Id.add_r;
case EXP.min: return Id.sub_r;
case EXP.mul: return Id.mul_r;
case EXP.div: return Id.div_r;
case EXP.mod: return Id.mod_r;
case EXP.pow: return Id.pow_r;
case EXP.leftShift: return Id.shl_r;
case EXP.rightShift: return Id.shr_r;
case EXP.unsignedRightShift:return Id.ushr_r;
case EXP.and: return Id.iand_r;
case EXP.or: return Id.ior_r;
case EXP.xor: return Id.ixor_r;
case EXP.concatenate: return Id.cat_r;
default: return null;
}
}

/*******************************************
* Helper function to turn operator into template argument list
*/
Expand Down Expand Up @@ -400,19 +322,7 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
result = result.expressionSemantic(sc);
return result;
}
// D1-style operator overloads, deprecated
if (e.op != EXP.prePlusPlus && e.op != EXP.preMinusMinus)
{
auto id = opId(e);
fd = search_function(ad, id);
if (fd)
{
// @@@DEPRECATED_2.110@@@.
// Deprecated in 2.088, made an error in 2.100
error(e.loc, "`%s` is obsolete. Use `opUnary(string op)() if (op == \"%s\")` instead.", id.toChars(), EXPtoString(e.op).ptr);
return ErrorExp.get();
}
}

// Didn't find it. Forward to aliasthis
if (ad.aliasthis && !isRecursiveAliasThis(att, e.e1.type))
{
Expand Down Expand Up @@ -610,8 +520,6 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
Expression visitBin(BinExp e)
{
//printf("BinExp::op_overload() (%s)\n", e.toChars());
Identifier id = opId(e);
Identifier id_r = opId_r(e);
int argsset = 0;
AggregateDeclaration ad1 = isAggregate(e.e1.type);
AggregateDeclaration ad2 = isAggregate(e.e2.type);
Expand All @@ -638,6 +546,8 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
if (ad1 && search_function(ad1, Id.opUnary))
return null;
}
Identifier id = e.op == EXP.assign ? Id.assign : null;
Identifier id_r = null;
if (e.op != EXP.equal && e.op != EXP.notEqual && e.op != EXP.assign && e.op != EXP.plusPlus && e.op != EXP.minusMinus)
{
/* Try opBinary and opBinaryRight
Expand Down Expand Up @@ -678,12 +588,6 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
s = search_function(ad1, id);
if (s && id != Id.assign)
{
// @@@DEPRECATED_2.110@@@.
// Deprecated in 2.088, made an error in 2.100
if (id == Id.postinc || id == Id.postdec)
error(e.loc, "`%s` is obsolete. Use `opUnary(string op)() if (op == \"%s\")` instead.", id.toChars(), EXPtoString(e.op).ptr);
else
error(e.loc, "`%s` is obsolete. Use `opBinary(string op)(...) if (op == \"%s\")` instead.", id.toChars(), EXPtoString(e.op).ptr);
return ErrorExp.get();
}
}
Expand Down Expand Up @@ -1201,7 +1105,6 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
{
return ErrorExp.get();
}
Identifier id = opId(e);
Expressions* args2 = new Expressions();
AggregateDeclaration ad1 = isAggregate(e.e1.type);
Dsymbol s = null;
Expand All @@ -1218,6 +1121,7 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
}
}
// Set tiargs, the template argument list, which will be the operator string
Identifier id;
if (s)
{
id = Id.opOpAssign;
Expand Down
Loading

0 comments on commit fc2b227

Please sign in to comment.