Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expressionsem.d: Get rid of duplication for shift and binary bit-op expressions #17062

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
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
Loading