Mercurial > projects > ddmd
annotate dmd/DivExp.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 |
0 | 27 class DivExp : BinExp |
28 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 |
0 | 31 this(Loc loc, Expression e1, Expression e2) |
32 { | |
178 | 33 register(); |
0 | 34 super(loc, TOK.TOKdiv, DivExp.sizeof, e1, e2); |
35 } | |
36 | |
72 | 37 override Expression semantic(Scope sc) |
0 | 38 { |
72 | 39 Expression e; |
40 | |
41 if (type) | |
42 return this; | |
43 | |
44 super.semanticp(sc); | |
45 e = op_overload(sc); | |
46 if (e) | |
47 return e; | |
48 | |
49 typeCombine(sc); | |
109 | 50 if (!e1.isArrayOperand()) |
72 | 51 e1.checkArithmetic(); |
109 | 52 if (!e2.isArrayOperand()) |
72 | 53 e2.checkArithmetic(); |
109 | 54 |
72 | 55 if (type.isfloating()) |
56 { | |
57 Type t1 = e1.type; | |
58 Type t2 = e2.type; | |
59 | |
60 if (t1.isreal()) | |
61 { | |
62 type = t2; | |
63 if (t2.isimaginary()) | |
64 { | |
65 // x/iv = i(-x/v) | |
66 e2.type = t1; | |
67 Expression ee = new NegExp(loc, this); | |
68 ee = ee.semantic(sc); | |
69 return e; | |
70 } | |
71 } | |
72 else if (t2.isreal()) | |
73 { | |
74 type = t1; | |
75 } | |
76 else if (t1.isimaginary()) | |
77 { | |
78 if (t2.isimaginary()) { | |
79 switch (t1.ty) | |
80 { | |
81 case TY.Timaginary32: type = Type.tfloat32; break; | |
82 case TY.Timaginary64: type = Type.tfloat64; break; | |
83 case TY.Timaginary80: type = Type.tfloat80; break; | |
84 default: assert(0); | |
85 } | |
86 } else { | |
87 type = t2; // t2 is complex | |
88 } | |
89 } | |
90 else if (t2.isimaginary()) | |
91 { | |
92 type = t1; // t1 is complex | |
93 } | |
94 } | |
0 | 95 return this; |
96 } | |
97 | |
72 | 98 override Expression optimize(int result) |
0 | 99 { |
72 | 100 Expression e; |
101 | |
102 //printf("DivExp.optimize(%s)\n", toChars()); | |
103 e1 = e1.optimize(result); | |
104 e2 = e2.optimize(result); | |
105 if (e1.isConst() == 1 && e2.isConst() == 1) | |
106 { | |
107 e = Div(type, e1, e2); | |
108 } | |
109 else | |
110 e = this; | |
0 | 111 return e; |
112 } | |
113 | |
72 | 114 override Expression interpret(InterState istate) |
0 | 115 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
116 return interpretCommon(istate, &Div); |
0 | 117 } |
118 | |
72 | 119 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 120 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
121 Exp_buildArrayIdent(buf, arguments, "Div"); |
0 | 122 } |
123 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
124 override Expression buildArrayLoop(Parameters fparams) |
0 | 125 { |
123 | 126 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 127 } |
128 | |
72 | 129 override IntRange getIntRange() |
0 | 130 { |
131 assert(false); | |
132 } | |
133 | |
72 | 134 override Identifier opId() |
0 | 135 { |
136 return Id.div; | |
137 } | |
138 | |
72 | 139 override Identifier opId_r() |
0 | 140 { |
141 return Id.div_r; | |
142 } | |
143 | |
72 | 144 override elem* toElem(IRState* irs) |
0 | 145 { |
146 return toElemBin(irs,OPdiv); | |
147 } | |
148 } | |
149 |