Mercurial > projects > ddmd
annotate dmd/ModExp.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.ModExp; |
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.IRState; | |
12 import dmd.ArrayTypes; | |
13 import dmd.BinExp; | |
0 | 14 import dmd.TOK; |
15 import dmd.Id; | |
16 import dmd.ErrorExp; | |
17 | |
18 import dmd.expression.Util; | |
19 import dmd.expression.Mod; | |
20 import dmd.backend.RTLSYM; | |
21 import dmd.backend.OPER; | |
72 | 22 import dmd.backend.Util; |
23 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 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
|
25 |
0 | 26 class ModExp : BinExp |
27 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 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
|
29 |
0 | 30 this(Loc loc, Expression e1, Expression e2) |
31 { | |
178 | 32 register(); |
0 | 33 super(loc, TOK.TOKmod, ModExp.sizeof, e1, e2); |
34 } | |
35 | |
72 | 36 override Expression semantic(Scope sc) |
0 | 37 { |
38 Expression e; | |
39 | |
40 if (type) | |
41 return this; | |
42 | |
43 BinExp.semanticp(sc); | |
44 e = op_overload(sc); | |
45 if (e) | |
46 return e; | |
47 | |
48 typeCombine(sc); | |
109 | 49 if (!e1.isArrayOperand()) |
0 | 50 e1.checkArithmetic(); |
109 | 51 if (!e2.isArrayOperand()) |
0 | 52 e2.checkArithmetic(); |
109 | 53 |
0 | 54 if (type.isfloating()) |
55 { | |
56 type = e1.type; | |
57 if (e2.type.iscomplex()) | |
58 { | |
59 error("cannot perform modulo complex arithmetic"); | |
60 return new ErrorExp(); | |
61 } | |
62 } | |
63 return this; | |
64 } | |
65 | |
72 | 66 override Expression optimize(int result) |
0 | 67 { |
68 Expression e; | |
69 | |
70 e1 = e1.optimize(result); | |
71 e2 = e2.optimize(result); | |
72 if (e1.isConst() == 1 && e2.isConst() == 1) | |
73 { | |
74 e = Mod(type, e1, e2); | |
75 } | |
76 else | |
77 e = this; | |
78 return e; | |
79 } | |
80 | |
72 | 81 override Expression interpret(InterState istate) |
0 | 82 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
83 return interpretCommon(istate, &Mod); |
0 | 84 } |
85 | |
72 | 86 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 87 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
88 Exp_buildArrayIdent(buf, arguments, "Mod"); |
0 | 89 } |
90 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
91 override Expression buildArrayLoop(Parameters fparams) |
0 | 92 { |
123 | 93 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 94 } |
95 | |
72 | 96 override Identifier opId() |
0 | 97 { |
98 return Id.mod; | |
99 } | |
100 | |
72 | 101 override Identifier opId_r() |
0 | 102 { |
103 return Id.mod_r; | |
104 } | |
105 | |
72 | 106 override elem* toElem(IRState* irs) |
0 | 107 { |
108 elem* e; | |
109 elem* e1; | |
110 elem* e2; | |
111 tym_t tym; | |
112 | |
113 tym = type.totym(); | |
114 | |
115 e1 = this.e1.toElem(irs); | |
116 e2 = this.e2.toElem(irs); | |
117 | |
118 static if (false) { // Now inlined | |
119 if (this.e1.type.isfloating()) | |
120 { | |
121 elem* ep; | |
122 | |
123 switch (this.e1.type.ty) | |
124 { | |
125 case Tfloat32: | |
126 case Timaginary32: | |
127 e1 = el_una(OPf_d, TYdouble, e1); | |
128 e2 = el_una(OPf_d, TYdouble, e2); | |
129 case Tfloat64: | |
130 case Timaginary64: | |
131 e1 = el_una(OPd_ld, TYldouble, e1); | |
132 e2 = el_una(OPd_ld, TYldouble, e2); | |
133 break; | |
134 case Tfloat80: | |
135 case Timaginary80: | |
136 break; | |
137 default: | |
138 assert(0); | |
139 break; | |
140 } | |
141 ep = el_param(e2,e1); | |
142 e = el_bin(OPcall,tym,el_var(rtlsym[RTLSYM_MODULO]),ep); | |
143 } | |
144 else | |
145 { | |
146 e = el_bin(OPmod,tym,e1,e2); | |
147 el_setLoc(e,loc); | |
148 } | |
149 } else { | |
150 e = el_bin(OPmod,tym,e1,e2); | |
151 el_setLoc(e,loc); | |
152 } | |
153 return e; | |
154 } | |
155 } | |
156 |