Mercurial > projects > ddmd
annotate dmd/MinExp.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
72 | 1 module dmd.MinExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.TY; | |
6 import dmd.ErrorExp; | |
7 import dmd.Identifier; | |
8 import dmd.IntegerExp; | |
9 import dmd.DivExp; | |
10 import dmd.Type; | |
11 import dmd.InterState; | |
12 import dmd.OutBuffer; | |
13 import dmd.Loc; | |
14 import dmd.Scope; | |
15 import dmd.IRState; | |
16 import dmd.ArrayTypes; | |
17 import dmd.BinExp; | |
18 import dmd.TOK; | |
19 import dmd.Id; | |
20 import dmd.expression.Min; | |
21 | |
22 import dmd.backend.elem; | |
23 import dmd.backend.Util; | |
24 import dmd.backend.OPER; | |
25 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 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
|
27 |
0 | 28 class MinExp : BinExp |
29 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 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
|
31 |
0 | 32 this(Loc loc, Expression e1, Expression e2) |
33 { | |
178 | 34 register(); |
0 | 35 super(loc, TOK.TOKmin, MinExp.sizeof, e1, e2); |
36 } | |
37 | |
72 | 38 override Expression semantic(Scope sc) |
0 | 39 { |
72 | 40 Expression e; |
41 Type t1; | |
42 Type t2; | |
43 | |
44 version (LOGSEMANTIC) { | |
45 printf("MinExp.semantic('%s')\n", toChars()); | |
46 } | |
47 if (type) | |
48 return this; | |
49 | |
50 super.semanticp(sc); | |
51 | |
52 e = op_overload(sc); | |
53 if (e) | |
54 return e; | |
55 | |
56 e = this; | |
57 t1 = e1.type.toBasetype(); | |
58 t2 = e2.type.toBasetype(); | |
59 if (t1.ty == TY.Tpointer) | |
60 { | |
61 if (t2.ty == TY.Tpointer) | |
62 { // Need to divide the result by the stride | |
63 // Replace (ptr - ptr) with (ptr - ptr) / stride | |
64 long stride; | |
65 Expression ee; | |
66 | |
67 typeCombine(sc); // make sure pointer types are compatible | |
68 type = Type.tptrdiff_t; | |
69 stride = t2.nextOf().size(); | |
70 if (stride == 0) | |
71 { | |
72 ee = new IntegerExp(loc, 0, Type.tptrdiff_t); | |
73 } | |
74 else | |
75 { | |
76 ee = new DivExp(loc, this, new IntegerExp(Loc(0), stride, Type.tptrdiff_t)); | |
77 ee.type = Type.tptrdiff_t; | |
78 } | |
79 return ee; | |
80 } | |
81 else if (t2.isintegral()) | |
82 e = scaleFactor(sc); | |
83 else | |
84 { | |
85 error("incompatible types for minus"); | |
86 return new ErrorExp(); | |
87 } | |
88 } | |
89 else if (t2.ty == TY.Tpointer) | |
90 { | |
91 type = e2.type; | |
92 error("can't subtract pointer from %s", e1.type.toChars()); | |
93 return new ErrorExp(); | |
94 } | |
95 else | |
96 { | |
97 typeCombine(sc); | |
98 t1 = e1.type.toBasetype(); | |
99 t2 = e2.type.toBasetype(); | |
100 if ((t1.isreal() && t2.isimaginary()) || | |
101 (t1.isimaginary() && t2.isreal())) | |
102 { | |
103 switch (type.ty) | |
104 { | |
105 case TY.Tfloat32: | |
106 case TY.Timaginary32: | |
107 type = Type.tcomplex32; | |
108 break; | |
109 | |
110 case TY.Tfloat64: | |
111 case TY.Timaginary64: | |
112 type = Type.tcomplex64; | |
113 break; | |
114 | |
115 case TY.Tfloat80: | |
116 case TY.Timaginary80: | |
117 type = Type.tcomplex80; | |
118 break; | |
119 | |
120 default: | |
121 assert(0); | |
122 } | |
123 } | |
124 } | |
0 | 125 return e; |
126 } | |
127 | |
72 | 128 override Expression optimize(int result) |
0 | 129 { |
72 | 130 Expression e; |
131 | |
132 e1 = e1.optimize(result); | |
133 e2 = e2.optimize(result); | |
134 if (e1.isConst() && e2.isConst()) | |
135 { | |
136 if (e2.op == TOK.TOKsymoff) | |
137 return this; | |
138 e = Min(type, e1, e2); | |
139 } | |
140 else | |
141 e = this; | |
142 | |
0 | 143 return e; |
144 } | |
145 | |
72 | 146 override Expression interpret(InterState istate) |
0 | 147 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
148 return interpretCommon(istate, &Min); |
0 | 149 } |
150 | |
72 | 151 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 152 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
153 Exp_buildArrayIdent(buf, arguments, "Min"); |
0 | 154 } |
155 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
156 override Expression buildArrayLoop(Parameters fparams) |
0 | 157 { |
123 | 158 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 159 } |
160 | |
72 | 161 override Identifier opId() |
0 | 162 { |
163 return Id.sub; | |
164 } | |
165 | |
72 | 166 override Identifier opId_r() |
0 | 167 { |
168 return Id.sub_r; | |
169 } | |
170 | |
72 | 171 override elem* toElem(IRState* irs) |
0 | 172 { |
72 | 173 Type tb1 = e1.type.toBasetype(); |
174 Type tb2 = e2.type.toBasetype(); | |
175 | |
176 if ((tb1.ty == TY.Tarray || tb1.ty == TY.Tsarray) && (tb2.ty == TY.Tarray || tb2.ty == TY.Tsarray)) | |
177 { | |
178 error("Array operation %s not implemented", toChars()); | |
179 return el_long(type.totym(), 0); // error recovery | |
180 } | |
181 | |
182 return toElemBin(irs, OPER.OPmin); | |
0 | 183 } |
184 } | |
185 |