Skip to content

Commit dcecb46

Browse files
authored
Merge pull request #17062 from kinke/nodup_binexp_sema
expressionsem.d: Get rid of duplication for shift and binary bit-op expressions Signed-off-by: Dennis <dkorpel@users.noreply.github.com> Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents 5cce98e + cb1d616 commit dcecb46

File tree

1 file changed

+14
-171
lines changed

1 file changed

+14
-171
lines changed

compiler/src/dmd/expressionsem.d

+14-171
Original file line numberDiff line numberDiff line change
@@ -13086,9 +13086,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
1308613086
return;
1308713087
}
1308813088

13089-
override void visit(ShlExp exp)
13089+
private void visitShift(BinExp exp)
1309013090
{
13091-
//printf("ShlExp::semantic(), type = %p\n", type);
1309213091
if (exp.type)
1309313092
{
1309413093
result = exp;
@@ -13123,79 +13122,20 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
1312313122
result = exp;
1312413123
}
1312513124

13125+
override void visit(ShlExp exp)
13126+
{
13127+
visitShift(exp);
13128+
}
1312613129
override void visit(ShrExp exp)
1312713130
{
13128-
if (exp.type)
13129-
{
13130-
result = exp;
13131-
return;
13132-
}
13133-
13134-
if (Expression ex = binSemanticProp(exp, sc))
13135-
{
13136-
result = ex;
13137-
return;
13138-
}
13139-
Expression e = exp.op_overload(sc);
13140-
if (e)
13141-
{
13142-
result = e;
13143-
return;
13144-
}
13145-
13146-
if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
13147-
return setError();
13148-
13149-
if (!target.isVectorOpSupported(exp.e1.type.toBasetype(), exp.op, exp.e2.type.toBasetype()))
13150-
{
13151-
result = exp.incompatibleTypes();
13152-
return;
13153-
}
13154-
exp.e1 = integralPromotions(exp.e1, sc);
13155-
if (exp.e2.type.toBasetype().ty != Tvector)
13156-
exp.e2 = exp.e2.castTo(sc, Type.tshiftcnt);
13157-
13158-
exp.type = exp.e1.type;
13159-
result = exp;
13131+
visitShift(exp);
1316013132
}
13161-
1316213133
override void visit(UshrExp exp)
1316313134
{
13164-
if (exp.type)
13165-
{
13166-
result = exp;
13167-
return;
13168-
}
13169-
13170-
if (Expression ex = binSemanticProp(exp, sc))
13171-
{
13172-
result = ex;
13173-
return;
13174-
}
13175-
Expression e = exp.op_overload(sc);
13176-
if (e)
13177-
{
13178-
result = e;
13179-
return;
13180-
}
13181-
13182-
if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
13183-
return setError();
13184-
13185-
if (!target.isVectorOpSupported(exp.e1.type.toBasetype(), exp.op, exp.e2.type.toBasetype()))
13186-
{
13187-
result = exp.incompatibleTypes();
13188-
return;
13189-
}
13190-
exp.e1 = integralPromotions(exp.e1, sc);
13191-
if (exp.e2.type.toBasetype().ty != Tvector)
13192-
exp.e2 = exp.e2.castTo(sc, Type.tshiftcnt);
13193-
13194-
exp.type = exp.e1.type;
13195-
result = exp;
13135+
visitShift(exp);
1319613136
}
1319713137

13198-
override void visit(AndExp exp)
13138+
private void visitBinaryBitOp(BinExp exp)
1319913139
{
1320013140
if (exp.type)
1320113141
{
@@ -13250,114 +13190,17 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
1325013190
result = exp;
1325113191
}
1325213192

13193+
override void visit(AndExp exp)
13194+
{
13195+
visitBinaryBitOp(exp);
13196+
}
1325313197
override void visit(OrExp exp)
1325413198
{
13255-
if (exp.type)
13256-
{
13257-
result = exp;
13258-
return;
13259-
}
13260-
13261-
if (Expression ex = binSemanticProp(exp, sc))
13262-
{
13263-
result = ex;
13264-
return;
13265-
}
13266-
Expression e = exp.op_overload(sc);
13267-
if (e)
13268-
{
13269-
result = e;
13270-
return;
13271-
}
13272-
13273-
if (exp.e1.type.toBasetype().ty == Tbool && exp.e2.type.toBasetype().ty == Tbool)
13274-
{
13275-
exp.type = exp.e1.type;
13276-
result = exp;
13277-
return;
13278-
}
13279-
13280-
if (Expression ex = typeCombine(exp, sc))
13281-
{
13282-
result = ex;
13283-
return;
13284-
}
13285-
13286-
Type tb = exp.type.toBasetype();
13287-
if (tb.ty == Tarray || tb.ty == Tsarray)
13288-
{
13289-
if (!isArrayOpValid(exp))
13290-
{
13291-
result = arrayOpInvalidError(exp);
13292-
return;
13293-
}
13294-
result = exp;
13295-
return;
13296-
}
13297-
if (!target.isVectorOpSupported(tb, exp.op, exp.e2.type.toBasetype()))
13298-
{
13299-
result = exp.incompatibleTypes();
13300-
return;
13301-
}
13302-
if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
13303-
return setError();
13304-
13305-
result = exp;
13199+
visitBinaryBitOp(exp);
1330613200
}
13307-
1330813201
override void visit(XorExp exp)
1330913202
{
13310-
if (exp.type)
13311-
{
13312-
result = exp;
13313-
return;
13314-
}
13315-
13316-
if (Expression ex = binSemanticProp(exp, sc))
13317-
{
13318-
result = ex;
13319-
return;
13320-
}
13321-
Expression e = exp.op_overload(sc);
13322-
if (e)
13323-
{
13324-
result = e;
13325-
return;
13326-
}
13327-
13328-
if (exp.e1.type.toBasetype().ty == Tbool && exp.e2.type.toBasetype().ty == Tbool)
13329-
{
13330-
exp.type = exp.e1.type;
13331-
result = exp;
13332-
return;
13333-
}
13334-
13335-
if (Expression ex = typeCombine(exp, sc))
13336-
{
13337-
result = ex;
13338-
return;
13339-
}
13340-
13341-
Type tb = exp.type.toBasetype();
13342-
if (tb.ty == Tarray || tb.ty == Tsarray)
13343-
{
13344-
if (!isArrayOpValid(exp))
13345-
{
13346-
result = arrayOpInvalidError(exp);
13347-
return;
13348-
}
13349-
result = exp;
13350-
return;
13351-
}
13352-
if (!target.isVectorOpSupported(tb, exp.op, exp.e2.type.toBasetype()))
13353-
{
13354-
result = exp.incompatibleTypes();
13355-
return;
13356-
}
13357-
if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
13358-
return setError();
13359-
13360-
result = exp;
13203+
visitBinaryBitOp(exp);
1336113204
}
1336213205

1336313206
override void visit(LogicalExp exp)

0 commit comments

Comments
 (0)