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] factorise some commonalities of BinExp semantic #17013

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
171 changes: 36 additions & 135 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -12753,51 +12753,66 @@
trySetCatExpLowering(result);
}

override void visit(MulExp exp)
bool commonBinOpSemantic(BinExp exp)
{
version (none)
{
printf("MulExp::semantic() %s\n", exp.toChars());
}
if (exp.type)
{
result = exp;
return;
return true;
}

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

if (Expression ex = typeCombine(exp, sc))
{
result = ex;
return;
return true;
}
return false;
}
bool commonArithBinOpSemantic(BinExp exp)
{
if (commonBinOpSemantic(exp))
return true;

Type tb = exp.type.toBasetype();
if (tb.ty == Tarray || tb.ty == Tsarray)
{
if (!isArrayOpValid(exp))
{
result = arrayOpInvalidError(exp);
return;
return true;

Check warning on line 12794 in compiler/src/dmd/expressionsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/expressionsem.d#L12794

Added line #L12794 was not covered by tests
}
result = exp;
return;
return true;
}

if (exp.checkArithmeticBin() || exp.checkSharedAccessBin(sc))
return setError();
{
setError();
return true;
}
return false;
}
override void visit(MulExp exp)
{
version (none)
{
printf("MulExp::semantic() %s\n", exp.toChars());
}

if (commonArithBinOpSemantic(exp))
return;
if (exp.type.isFloating())
{
Type t1 = exp.e1.type;
Expand Down Expand Up @@ -12836,7 +12851,7 @@
// iy * iv = -yv
exp.e1.type = exp.type;
exp.e2.type = exp.type;
e = new NegExp(exp.loc, exp);
Expression e = new NegExp(exp.loc, exp);
e = e.expressionSemantic(sc);
result = e;
return;
Expand All @@ -12849,7 +12864,7 @@
exp.type = t1; // t1 is complex
}
}
else if (!target.isVectorOpSupported(tb, exp.op, exp.e2.type.toBasetype()))
else if (!target.isVectorOpSupported(exp.type.toBasetype(), exp.op, exp.e2.type.toBasetype()))
{
result = exp.incompatibleTypes();
return;
Expand All @@ -12859,44 +12874,8 @@

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

if (Expression ex = binSemanticProp(exp, sc))
{
result = ex;
return;
}
Expression e = exp.op_overload(sc);
if (e)
{
result = e;
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 (exp.checkArithmeticBin() || exp.checkSharedAccessBin(sc))
return setError();

if (exp.type.isFloating())
{
Expand All @@ -12910,7 +12889,7 @@
{
// x/iv = i(-x/v)
exp.e2.type = t1;
e = new NegExp(exp.loc, exp);
Expression e = new NegExp(exp.loc, exp);
e = e.expressionSemantic(sc);
result = e;
return;
Expand Down Expand Up @@ -12950,7 +12929,7 @@
exp.type = t1; // t1 is complex
}
}
else if (!target.isVectorOpSupported(tb, exp.op, exp.e2.type.toBasetype()))
else if (!target.isVectorOpSupported(exp.type.toBasetype(), exp.op, exp.e2.type.toBasetype()))
{
result = exp.incompatibleTypes();
return;
Expand All @@ -12960,49 +12939,8 @@

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

if (Expression ex = binSemanticProp(exp, sc))
{
result = ex;
return;
}
Expression e = exp.op_overload(sc);
if (e)
{
result = e;
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.checkArithmeticBin() || exp.checkSharedAccessBin(sc))
return setError();

if (exp.type.isFloating())
{
Expand All @@ -13018,54 +12956,17 @@

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

//printf("PowExp::semantic() %s\n", toChars());
if (Expression ex = binSemanticProp(exp, sc))
{
result = ex;
return;
}
Expression e = exp.op_overload(sc);
if (e)
{
result = e;
return;
}

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

Type tb = exp.type.toBasetype();
if (tb.ty == Tarray || tb.ty == Tsarray)
{
if (!isArrayOpValid(exp))
{
result = arrayOpInvalidError(exp);
return;
}
result = exp;
return;
}

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

if (!target.isVectorOpSupported(tb, exp.op, exp.e2.type.toBasetype()))
if (!target.isVectorOpSupported(exp.type.toBasetype(), exp.op, exp.e2.type.toBasetype()))
{
result = exp.incompatibleTypes();
return;
}

// First, attempt to fold the expression.
e = exp.optimize(WANTvalue);
Expression e = exp.optimize(WANTvalue);
if (e.op != EXP.pow)
{
e = e.expressionSemantic(sc);
Expand Down
Loading