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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.expression.Min;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 0
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.RealExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ComplexExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.SymOffExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Complex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 Expression Min(Type type, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 Loc loc = e1.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 if (type.isreal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 e = new RealExp(loc, e1.toReal() - e2.toReal(), type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 else if (type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 e = new RealExp(loc, e1.toImaginary() - e2.toImaginary(), type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 else if (type.iscomplex())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 // This rigamarole is necessary so that -0.0 doesn't get
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 // converted to +0.0 by doing an extraneous add with +0.0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 Complex!(real) c1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 real r1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 real i1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 Complex!(real) c2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 real r2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 real i2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 Complex!(real) v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 int x;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 if (e1.type.isreal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 r1 = e1.toReal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 x = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 else if (e1.type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 i1 = e1.toImaginary();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 x = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 c1 = e1.toComplex();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 x = 6;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 if (e2.type.isreal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 r2 = e2.toReal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 else if (e2.type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 i2 = e2.toImaginary();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 x += 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 c2 = e2.toComplex();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 x += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 switch (x)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 case 0+0: v = Complex!(real)(r1 - r2, 0); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 case 0+1: v = Complex!(real)(r1, -i2); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 case 0+2: v = Complex!(real)(r1 - c2.re, -c2.im); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 case 3+0: v = Complex!(real)(-r2, i1); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 case 3+1: v = Complex!(real)(0, i1 - i2); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 case 3+2: v = Complex!(real)(c2.re, i1 - c2.im); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 case 6+0: v = Complex!(real)(c1.re - r2, c1.im); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 case 6+1: v = Complex!(real)(c1.re, c1.im - i2); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 e = new ComplexExp(loc, v, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 else if (e1.op == TOK.TOKsymoff)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 SymOffExp soe = cast(SymOffExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 e = new SymOffExp(loc, soe.var, soe.offset - cast(uint)e2.toInteger());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 e = new IntegerExp(loc, e1.toInteger() - e2.toInteger(), type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }