@@ -611,8 +611,6 @@ UnionExp Equal(EXP op, Loc loc, Type type, Expression e1, Expression e2)
611
611
{
612
612
UnionExp ue = void ;
613
613
int cmp = 0 ;
614
- real_t r1 = CTFloat.zero;
615
- real_t r2 = CTFloat.zero;
616
614
// printf("Equal(e1 = %s, e2 = %s)\n", e1.toChars(), e2.toChars());
617
615
assert (op == EXP .equal || op == EXP .notEqual);
618
616
if (e1.op == EXP .null_)
@@ -691,17 +689,17 @@ UnionExp Equal(EXP op, Loc loc, Type type, Expression e1, Expression e2)
691
689
}
692
690
}
693
691
}
694
- else if (e1.op == EXP .arrayLiteral && e2.op == EXP .string_)
692
+ else if ((e1.op == EXP .arrayLiteral && e2.op == EXP .string_) ||
693
+ (e1.op == EXP .string_ && e2.op == EXP .arrayLiteral))
695
694
{
696
- // Swap operands and use common code
697
- Expression etmp = e1;
698
- e1 = e2;
699
- e2 = etmp;
700
- goto Lsa;
701
- }
702
- else if (e1.op == EXP .string_ && e2.op == EXP .arrayLiteral)
703
- {
704
- Lsa:
695
+ if (e1.op == EXP .arrayLiteral)
696
+ {
697
+ // Swap operands and use common code
698
+ Expression etmp = e1;
699
+ e1 = e2;
700
+ e2 = etmp;
701
+ }
702
+
705
703
StringExp es1 = e1.isStringExp();
706
704
ArrayLiteralExp es2 = e2.isArrayLiteralExp();
707
705
size_t dim1 = es1.len;
@@ -766,17 +764,12 @@ UnionExp Equal(EXP op, Loc loc, Type type, Expression e1, Expression e2)
766
764
cantExp(ue);
767
765
return ue;
768
766
}
769
- else if (e1.type.isReal())
767
+ else if (e1.type.isReal() || e1.type.isImaginary() )
770
768
{
771
- r1 = e1.toReal();
772
- r2 = e2.toReal();
773
- goto L1 ;
774
- }
775
- else if (e1.type.isImaginary())
776
- {
777
- r1 = e1.toImaginary();
778
- r2 = e2.toImaginary();
779
- L1 :
769
+ const bool isReal = e1.type.isReal();
770
+ real_t r1 = isReal ? e1.toReal() : e1.toImaginary();
771
+ real_t r2 = isReal ? e2.toReal() : e2.toImaginary();
772
+
780
773
if (CTFloat.isNaN(r1) || CTFloat.isNaN(r2)) // if unordered
781
774
{
782
775
cmp = 0 ;
@@ -854,8 +847,6 @@ UnionExp Cmp(EXP op, Loc loc, Type type, Expression e1, Expression e2)
854
847
{
855
848
UnionExp ue = void ;
856
849
dinteger_t n;
857
- real_t r1 = CTFloat.zero;
858
- real_t r2 = CTFloat.zero;
859
850
// printf("Cmp(e1 = %s, e2 = %s)\n", e1.toChars(), e2.toChars());
860
851
if (e1.op == EXP .string_ && e2.op == EXP .string_)
861
852
{
@@ -878,17 +869,11 @@ UnionExp Cmp(EXP op, Loc loc, Type type, Expression e1, Expression e2)
878
869
cantExp(ue);
879
870
return ue;
880
871
}
881
- else if (e1.type.isReal())
882
- {
883
- r1 = e1.toReal();
884
- r2 = e2.toReal();
885
- goto L1 ;
886
- }
887
- else if (e1.type.isImaginary())
872
+ else if (e1.type.isReal() || e1.type.isImaginary())
888
873
{
889
- r1 = e1.toImaginary ();
890
- r2 = e2 .toImaginary();
891
- L1 :
874
+ const bool isReal = e1.type.isReal ();
875
+ real_t r1 = isReal ? e1.toReal() : e1 .toImaginary();
876
+ real_t r2 = isReal ? e2.toReal() : e2.toImaginary();
892
877
n = realCmp(op, r1, r2);
893
878
}
894
879
else if (e1.type.isComplex())
@@ -938,32 +923,35 @@ UnionExp Cast(Loc loc, Type type, Type to, Expression e1)
938
923
ue.exp().type = type;
939
924
return ue;
940
925
}
926
+ UnionExp retExpType ()
927
+ {
928
+ Expression ex = expType(to, e1);
929
+ emplaceExp! (UnionExp)(&ue, ex);
930
+ return ue;
931
+ }
941
932
if (e1.type.implicitConvTo(to) >= MATCH .constant || to.implicitConvTo(e1.type) >= MATCH .constant)
942
933
{
943
- goto L1 ;
934
+ return retExpType () ;
944
935
}
945
936
// Allow covariant converions of delegates
946
937
// (Perhaps implicit conversion from pure to impure should be a MATCH.constant,
947
938
// then we wouldn't need this extra check.)
948
939
if (e1.type.toBasetype().ty == Tdelegate && e1.type.implicitConvTo(to) == MATCH .convert)
949
940
{
950
- goto L1 ;
941
+ return retExpType () ;
951
942
}
952
943
/* Allow casting from one string type to another
953
944
*/
954
945
if (e1.op == EXP .string_)
955
946
{
956
947
if (tb.ty == Tarray && typeb.ty == Tarray && tb.nextOf().size() == typeb.nextOf().size())
957
948
{
958
- goto L1 ;
949
+ return retExpType () ;
959
950
}
960
951
}
961
952
if (e1.op == EXP .arrayLiteral && typeb == tb)
962
953
{
963
- L1 :
964
- Expression ex = expType(to, e1);
965
- emplaceExp! (UnionExp)(&ue, ex);
966
- return ue;
954
+ return retExpType ();
967
955
}
968
956
if (e1.isConst() != 1 )
969
957
{
@@ -1602,15 +1590,12 @@ UnionExp Cat(Loc loc, Type type, Expression e1, Expression e2)
1602
1590
assert (ue.exp().type);
1603
1591
return ue;
1604
1592
}
1605
- else if (e1.op == EXP .arrayLiteral && e2.op == EXP .null_ && t1.nextOf().equals(t2.nextOf()))
1593
+ else if ((e1.op == EXP .arrayLiteral && e2.op == EXP .null_)
1594
+ || (e1.op == EXP .null_ && e2.op == EXP .arrayLiteral)
1595
+ && t1.nextOf().equals(t2.nextOf()))
1606
1596
{
1607
- e = e1;
1608
- goto L3 ;
1609
- }
1610
- else if (e1.op == EXP .null_ && e2.op == EXP .arrayLiteral && t1.nextOf().equals(t2.nextOf()))
1611
- {
1612
- e = e2;
1613
- L3 :
1597
+ e = (e1.op == EXP .arrayLiteral) ? e1 : e2;
1598
+
1614
1599
// Concatenate the array with null
1615
1600
auto elems = copyElements(e);
1616
1601
@@ -1660,17 +1645,13 @@ UnionExp Cat(Loc loc, Type type, Expression e1, Expression e2)
1660
1645
assert (ue.exp().type);
1661
1646
return ue;
1662
1647
}
1663
- else if (e1.op == EXP .null_ && e2.op == EXP .string_)
1648
+ else if ((e1.op == EXP .null_ && e2.op == EXP .string_) ||
1649
+ (e1.op == EXP .string_ && e2.op == EXP .null_))
1664
1650
{
1665
- t = e1.type;
1666
- e = e2;
1667
- goto L1 ;
1668
- }
1669
- else if (e1.op == EXP .string_ && e2.op == EXP .null_)
1670
- {
1671
- e = e1;
1672
- t = e2.type;
1673
- L1 :
1651
+ const bool b = e1.op == EXP .null_;
1652
+ t = b ? e1.type : e2.type;
1653
+ e = b ? e2 : e1;
1654
+
1674
1655
Type tb = t.toBasetype();
1675
1656
if (tb.ty == Tarray && tb.nextOf().equivalent(e.type))
1676
1657
{
0 commit comments