Mercurial > projects > ddmd
annotate dmd/expression/Min.d @ 157:b7b61140701d
* added all missing default cases in switch statements
+ Lexer.getDocComment
+ Lexer.combineComments
author | trass3r |
---|---|
date | Thu, 16 Sep 2010 01:34:10 +0200 |
parents | e28b18c23469 |
children |
rev | line source |
---|---|
0 | 1 module dmd.expression.Min; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Expression; |
5 import dmd.Type; | |
6 import dmd.Loc; | |
7 import dmd.RealExp; | |
8 import dmd.ComplexExp; | |
9 import dmd.IntegerExp; | |
10 import dmd.TOK; | |
11 import dmd.SymOffExp; | |
12 import dmd.Complex; | |
13 | |
14 Expression Min(Type type, Expression e1, Expression e2) | |
15 { | |
16 Expression e; | |
17 Loc loc = e1.loc; | |
18 | |
19 if (type.isreal()) | |
20 { | |
21 e = new RealExp(loc, e1.toReal() - e2.toReal(), type); | |
22 } | |
23 else if (type.isimaginary()) | |
24 { | |
25 e = new RealExp(loc, e1.toImaginary() - e2.toImaginary(), type); | |
26 } | |
27 else if (type.iscomplex()) | |
28 { | |
29 // This rigamarole is necessary so that -0.0 doesn't get | |
30 // converted to +0.0 by doing an extraneous add with +0.0 | |
31 Complex!(real) c1; | |
32 real r1; | |
33 real i1; | |
34 | |
35 Complex!(real) c2; | |
36 real r2; | |
37 real i2; | |
38 | |
39 Complex!(real) v; | |
40 int x; | |
41 | |
42 if (e1.type.isreal()) | |
43 { | |
44 r1 = e1.toReal(); | |
45 x = 0; | |
46 } | |
47 else if (e1.type.isimaginary()) | |
48 { | |
49 i1 = e1.toImaginary(); | |
50 x = 3; | |
51 } | |
52 else | |
53 { | |
54 c1 = e1.toComplex(); | |
55 x = 6; | |
56 } | |
57 | |
58 if (e2.type.isreal()) | |
59 { | |
60 r2 = e2.toReal(); | |
61 } | |
62 else if (e2.type.isimaginary()) | |
63 { | |
64 i2 = e2.toImaginary(); | |
65 x += 1; | |
66 } | |
67 else | |
68 { | |
69 c2 = e2.toComplex(); | |
70 x += 2; | |
71 } | |
72 | |
73 switch (x) | |
74 { | |
75 case 0+0: v = Complex!(real)(r1 - r2, 0); break; | |
76 case 0+1: v = Complex!(real)(r1, -i2); break; | |
77 case 0+2: v = Complex!(real)(r1 - c2.re, -c2.im); break; | |
78 case 3+0: v = Complex!(real)(-r2, i1); break; | |
79 case 3+1: v = Complex!(real)(0, i1 - i2); break; | |
80 case 3+2: v = Complex!(real)(c2.re, i1 - c2.im); break; | |
81 case 6+0: v = Complex!(real)(c1.re - r2, c1.im); break; | |
82 case 6+1: v = Complex!(real)(c1.re, c1.im - i2); break; | |
83 case 6+2: v = Complex!(real)(c1.re - c2.re, c1.im - c2.im); break; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
114
diff
changeset
|
84 default: |
0 | 85 } |
86 e = new ComplexExp(loc, v, type); | |
87 } | |
88 else if (e1.op == TOK.TOKsymoff) | |
89 { | |
90 SymOffExp soe = cast(SymOffExp)e1; | |
91 e = new SymOffExp(loc, soe.var, soe.offset - cast(uint)e2.toInteger()); | |
92 e.type = type; | |
93 } | |
94 else | |
95 { | |
96 e = new IntegerExp(loc, e1.toInteger() - e2.toInteger(), type); | |
97 } | |
98 return e; | |
99 } |