annotate dmd/expression/Mul.d @ 192:eb38fdcb3e62 default tip

updated to compile with dmd2.062
author korDen
date Sat, 02 Mar 2013 01:25:52 -0800
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.Mul;
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.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.RealExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ComplexExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Complex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 Expression Mul(Type type, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 Loc loc = e1.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 if (type.isfloating())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 Complex!(real) c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 real r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 if (e1.type.isreal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 r = e1.toReal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 c = e2.toComplex();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 c = Complex!(real)(r * c.re, r * c.im);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 else if (e1.type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 r = e1.toImaginary();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 c = e2.toComplex();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 c = Complex!(real)(-r * c.im, r * c.re);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 else if (e2.type.isreal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 0
diff changeset
36 r = e2.toReal();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 c = e1.toComplex();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 c = Complex!(real)(r * c.re, r * c.im);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 else if (e2.type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 r = e2.toImaginary();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 c = e1.toComplex();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 c = Complex!(real)(-r * c.im, r * c.re);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Complex!(real) c1 = e1.toComplex();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Complex!(real) c2 = e2.toComplex();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 c = Complex!(real)(c1.re * c2.re - c1.im * c2.im, c1.re * c2.im + c1.im * c2.re);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 if (type.isreal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 e = new RealExp(loc, c.re, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 else if (type.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 e = new RealExp(loc, c.im, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 else if (type.iscomplex())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 e = new ComplexExp(loc, c, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 e = new IntegerExp(loc, e1.toInteger() * e2.toInteger(), type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }