Skip to content

Commit

Permalink
Merge pull request #17062 from kinke/nodup_binexp_sema
Browse files Browse the repository at this point in the history
expressionsem.d: Get rid of duplication for shift and binary bit-op expressions

Signed-off-by: Dennis <[email protected]>
Merged-on-behalf-of: Nicholas Wilson <[email protected]>
  • Loading branch information
dlang-bot authored Nov 13, 2024
2 parents 5cce98e + cb1d616 commit dcecb46
Showing 1 changed file with 14 additions and 171 deletions.
185 changes: 14 additions & 171 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -13086,9 +13086,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return;
}

override void visit(ShlExp exp)
private void visitShift(BinExp exp)
{
//printf("ShlExp::semantic(), type = %p\n", type);
if (exp.type)
{
result = exp;
Expand Down Expand Up @@ -13123,79 +13122,20 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
result = exp;
}

override void visit(ShlExp exp)
{
visitShift(exp);
}
override void visit(ShrExp exp)
{
if (exp.type)
{
result = exp;
return;
}

if (Expression ex = binSemanticProp(exp, sc))
{
result = ex;
return;
}
Expression e = exp.op_overload(sc);
if (e)
{
result = e;
return;
}

if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
return setError();

if (!target.isVectorOpSupported(exp.e1.type.toBasetype(), exp.op, exp.e2.type.toBasetype()))
{
result = exp.incompatibleTypes();
return;
}
exp.e1 = integralPromotions(exp.e1, sc);
if (exp.e2.type.toBasetype().ty != Tvector)
exp.e2 = exp.e2.castTo(sc, Type.tshiftcnt);

exp.type = exp.e1.type;
result = exp;
visitShift(exp);
}

override void visit(UshrExp exp)
{
if (exp.type)
{
result = exp;
return;
}

if (Expression ex = binSemanticProp(exp, sc))
{
result = ex;
return;
}
Expression e = exp.op_overload(sc);
if (e)
{
result = e;
return;
}

if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
return setError();

if (!target.isVectorOpSupported(exp.e1.type.toBasetype(), exp.op, exp.e2.type.toBasetype()))
{
result = exp.incompatibleTypes();
return;
}
exp.e1 = integralPromotions(exp.e1, sc);
if (exp.e2.type.toBasetype().ty != Tvector)
exp.e2 = exp.e2.castTo(sc, Type.tshiftcnt);

exp.type = exp.e1.type;
result = exp;
visitShift(exp);
}

override void visit(AndExp exp)
private void visitBinaryBitOp(BinExp exp)
{
if (exp.type)
{
Expand Down Expand Up @@ -13250,114 +13190,17 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
result = exp;
}

override void visit(AndExp exp)
{
visitBinaryBitOp(exp);
}
override void visit(OrExp exp)
{
if (exp.type)
{
result = exp;
return;
}

if (Expression ex = binSemanticProp(exp, sc))
{
result = ex;
return;
}
Expression e = exp.op_overload(sc);
if (e)
{
result = e;
return;
}

if (exp.e1.type.toBasetype().ty == Tbool && exp.e2.type.toBasetype().ty == Tbool)
{
exp.type = exp.e1.type;
result = exp;
return;
}

if (Expression ex = typeCombine(exp, sc))
{
result = ex;
return;
}

Type tb = exp.type.toBasetype();
if (tb.ty == Tarray || tb.ty == Tsarray)
{
if (!isArrayOpValid(exp))
{
result = arrayOpInvalidError(exp);
return;
}
result = exp;
return;
}
if (!target.isVectorOpSupported(tb, exp.op, exp.e2.type.toBasetype()))
{
result = exp.incompatibleTypes();
return;
}
if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
return setError();

result = exp;
visitBinaryBitOp(exp);
}

override void visit(XorExp exp)
{
if (exp.type)
{
result = exp;
return;
}

if (Expression ex = binSemanticProp(exp, sc))
{
result = ex;
return;
}
Expression e = exp.op_overload(sc);
if (e)
{
result = e;
return;
}

if (exp.e1.type.toBasetype().ty == Tbool && exp.e2.type.toBasetype().ty == Tbool)
{
exp.type = exp.e1.type;
result = exp;
return;
}

if (Expression ex = typeCombine(exp, sc))
{
result = ex;
return;
}

Type tb = exp.type.toBasetype();
if (tb.ty == Tarray || tb.ty == Tsarray)
{
if (!isArrayOpValid(exp))
{
result = arrayOpInvalidError(exp);
return;
}
result = exp;
return;
}
if (!target.isVectorOpSupported(tb, exp.op, exp.e2.type.toBasetype()))
{
result = exp.incompatibleTypes();
return;
}
if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
return setError();

result = exp;
visitBinaryBitOp(exp);
}

override void visit(LogicalExp exp)
Expand Down

0 comments on commit dcecb46

Please sign in to comment.