comparison dmd/expression/Neg.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children e28b18c23469
comparison
equal deleted inserted replaced
-1:000000000000 0:10317f0c89a5
1 module dmd.expression.Neg;
2
3 import dmd.Type;
4 import dmd.Loc;
5 import dmd.RealExp;
6 import dmd.Expression;
7 import dmd.ComplexExp;
8 import dmd.IntegerExp;
9 import dmd.Complex;
10
11 Expression Neg(Type type, Expression e1)
12 {
13 Expression e;
14 Loc loc = e1.loc;
15
16 if (e1.type.isreal())
17 {
18 e = new RealExp(loc, -e1.toReal(), type);
19 }
20 else if (e1.type.isimaginary())
21 {
22 e = new RealExp(loc, -e1.toImaginary(), type);
23 }
24 else if (e1.type.iscomplex())
25 {
26 Complex!(real) c = e1.toComplex();
27 e = new ComplexExp(loc, Complex!(real)(-c.re, -c.im), type);
28 }
29 else
30 e = new IntegerExp(loc, -e1.toInteger(), type);
31
32 return e;
33 }