Mercurial > projects > ddmd
annotate dmd/DivExp.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | 60bb0fe4563e |
children | b0d41ff5e0df |
rev | line source |
---|---|
72 | 1 module dmd.DivExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
6 import dmd.backend.elem; | |
7 import dmd.InterState; | |
8 import dmd.OutBuffer; | |
9 import dmd.Loc; | |
10 import dmd.Scope; | |
11 import dmd.IntRange; | |
12 import dmd.IRState; | |
13 import dmd.ArrayTypes; | |
14 import dmd.BinExp; | |
15 import dmd.TOK; | |
16 import dmd.Type; | |
17 import dmd.NegExp; | |
18 import dmd.TY; | |
19 import dmd.Id; | |
20 | |
21 import dmd.expression.Div; | |
22 import dmd.backend.OPER; | |
23 import dmd.backend.Util; | |
24 | |
0 | 25 class DivExp : BinExp |
26 { | |
27 this(Loc loc, Expression e1, Expression e2) | |
28 { | |
178 | 29 register(); |
0 | 30 super(loc, TOK.TOKdiv, DivExp.sizeof, e1, e2); |
31 } | |
32 | |
72 | 33 override Expression semantic(Scope sc) |
0 | 34 { |
72 | 35 Expression e; |
36 | |
37 if (type) | |
38 return this; | |
39 | |
40 super.semanticp(sc); | |
41 e = op_overload(sc); | |
42 if (e) | |
43 return e; | |
44 | |
45 typeCombine(sc); | |
109 | 46 if (!e1.isArrayOperand()) |
72 | 47 e1.checkArithmetic(); |
109 | 48 if (!e2.isArrayOperand()) |
72 | 49 e2.checkArithmetic(); |
109 | 50 |
72 | 51 if (type.isfloating()) |
52 { | |
53 Type t1 = e1.type; | |
54 Type t2 = e2.type; | |
55 | |
56 if (t1.isreal()) | |
57 { | |
58 type = t2; | |
59 if (t2.isimaginary()) | |
60 { | |
61 // x/iv = i(-x/v) | |
62 e2.type = t1; | |
63 Expression ee = new NegExp(loc, this); | |
64 ee = ee.semantic(sc); | |
65 return e; | |
66 } | |
67 } | |
68 else if (t2.isreal()) | |
69 { | |
70 type = t1; | |
71 } | |
72 else if (t1.isimaginary()) | |
73 { | |
74 if (t2.isimaginary()) { | |
75 switch (t1.ty) | |
76 { | |
77 case TY.Timaginary32: type = Type.tfloat32; break; | |
78 case TY.Timaginary64: type = Type.tfloat64; break; | |
79 case TY.Timaginary80: type = Type.tfloat80; break; | |
80 default: assert(0); | |
81 } | |
82 } else { | |
83 type = t2; // t2 is complex | |
84 } | |
85 } | |
86 else if (t2.isimaginary()) | |
87 { | |
88 type = t1; // t1 is complex | |
89 } | |
90 } | |
0 | 91 return this; |
92 } | |
93 | |
72 | 94 override Expression optimize(int result) |
0 | 95 { |
72 | 96 Expression e; |
97 | |
98 //printf("DivExp.optimize(%s)\n", toChars()); | |
99 e1 = e1.optimize(result); | |
100 e2 = e2.optimize(result); | |
101 if (e1.isConst() == 1 && e2.isConst() == 1) | |
102 { | |
103 e = Div(type, e1, e2); | |
104 } | |
105 else | |
106 e = this; | |
0 | 107 return e; |
108 } | |
109 | |
72 | 110 override Expression interpret(InterState istate) |
0 | 111 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
112 return interpretCommon(istate, &Div); |
0 | 113 } |
114 | |
72 | 115 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 116 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
117 Exp_buildArrayIdent(buf, arguments, "Div"); |
0 | 118 } |
119 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
120 override Expression buildArrayLoop(Parameters fparams) |
0 | 121 { |
123 | 122 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 123 } |
124 | |
72 | 125 override IntRange getIntRange() |
0 | 126 { |
127 assert(false); | |
128 } | |
129 | |
72 | 130 override Identifier opId() |
0 | 131 { |
132 return Id.div; | |
133 } | |
134 | |
72 | 135 override Identifier opId_r() |
0 | 136 { |
137 return Id.div_r; | |
138 } | |
139 | |
72 | 140 override elem* toElem(IRState* irs) |
0 | 141 { |
142 return toElemBin(irs,OPdiv); | |
143 } | |
144 } | |
145 |