Mercurial > projects > ddmd
annotate dmd/ModExp.d @ 63:cab4c37afb89
A bunch of implementations
author | korDen |
---|---|
date | Mon, 23 Aug 2010 16:52:24 +0400 |
parents | 832f71e6f96c |
children | 2e2a5c3f943a |
rev | line source |
---|---|
0 | 1 module dmd.ModExp; |
2 | |
3 import dmd.Expression; | |
4 import dmd.Identifier; | |
5 import dmd.backend.elem; | |
6 import dmd.InterState; | |
7 import dmd.OutBuffer; | |
8 import dmd.Loc; | |
9 import dmd.Scope; | |
10 import dmd.IRState; | |
11 import dmd.ArrayTypes; | |
12 import dmd.BinExp; | |
13 import dmd.TOK; | |
14 import dmd.Id; | |
15 import dmd.ErrorExp; | |
16 | |
17 import dmd.expression.Util; | |
18 import dmd.expression.Mod; | |
19 import dmd.backend.RTLSYM; | |
20 import dmd.backend.OPER; | |
21 import dmd.backend.Util; | |
22 | |
23 class ModExp : BinExp | |
24 { | |
25 this(Loc loc, Expression e1, Expression e2) | |
26 { | |
27 super(loc, TOK.TOKmod, ModExp.sizeof, e1, e2); | |
28 } | |
29 | |
30 Expression semantic(Scope sc) | |
31 { | |
32 Expression e; | |
33 | |
34 if (type) | |
35 return this; | |
36 | |
37 BinExp.semanticp(sc); | |
38 e = op_overload(sc); | |
39 if (e) | |
40 return e; | |
41 | |
42 typeCombine(sc); | |
43 if (e1.op != TOKslice && e2.op != TOKslice) | |
44 { | |
45 e1.checkArithmetic(); | |
46 e2.checkArithmetic(); | |
47 } | |
48 if (type.isfloating()) | |
49 { | |
50 type = e1.type; | |
51 if (e2.type.iscomplex()) | |
52 { | |
53 error("cannot perform modulo complex arithmetic"); | |
54 return new ErrorExp(); | |
55 } | |
56 } | |
57 return this; | |
58 } | |
59 | |
60 Expression optimize(int result) | |
61 { | |
62 Expression e; | |
63 | |
64 e1 = e1.optimize(result); | |
65 e2 = e2.optimize(result); | |
66 if (e1.isConst() == 1 && e2.isConst() == 1) | |
67 { | |
68 e = Mod(type, e1, e2); | |
69 } | |
70 else | |
71 e = this; | |
72 return e; | |
73 } | |
74 | |
63 | 75 Expression interpret(InterState istate) |
0 | 76 { |
77 assert(false); | |
78 } | |
79 | |
80 void buildArrayIdent(OutBuffer buf, Expressions arguments) | |
81 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
82 Exp_buildArrayIdent(buf, arguments, "Mod"); |
0 | 83 } |
84 | |
85 Expression buildArrayLoop(Arguments fparams) | |
86 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
87 /* Evaluate assign expressions left to right |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
88 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
89 Expression ex1 = e1.buildArrayLoop(fparams); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
90 Expression ex2 = e2.buildArrayLoop(fparams); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
91 Expression e = new ModExp(Loc(0), ex1, ex2); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
92 return e; |
0 | 93 } |
94 | |
95 Identifier opId() | |
96 { | |
97 return Id.mod; | |
98 } | |
99 | |
100 Identifier opId_r() | |
101 { | |
102 return Id.mod_r; | |
103 } | |
104 | |
105 elem* toElem(IRState* irs) | |
106 { | |
107 elem* e; | |
108 elem* e1; | |
109 elem* e2; | |
110 tym_t tym; | |
111 | |
112 tym = type.totym(); | |
113 | |
114 e1 = this.e1.toElem(irs); | |
115 e2 = this.e2.toElem(irs); | |
116 | |
117 static if (false) { // Now inlined | |
118 if (this.e1.type.isfloating()) | |
119 { | |
120 elem* ep; | |
121 | |
122 switch (this.e1.type.ty) | |
123 { | |
124 case Tfloat32: | |
125 case Timaginary32: | |
126 e1 = el_una(OPf_d, TYdouble, e1); | |
127 e2 = el_una(OPf_d, TYdouble, e2); | |
128 case Tfloat64: | |
129 case Timaginary64: | |
130 e1 = el_una(OPd_ld, TYldouble, e1); | |
131 e2 = el_una(OPd_ld, TYldouble, e2); | |
132 break; | |
133 case Tfloat80: | |
134 case Timaginary80: | |
135 break; | |
136 default: | |
137 assert(0); | |
138 break; | |
139 } | |
140 ep = el_param(e2,e1); | |
141 e = el_bin(OPcall,tym,el_var(rtlsym[RTLSYM_MODULO]),ep); | |
142 } | |
143 else | |
144 { | |
145 e = el_bin(OPmod,tym,e1,e2); | |
146 el_setLoc(e,loc); | |
147 } | |
148 } else { | |
149 e = el_bin(OPmod,tym,e1,e2); | |
150 el_setLoc(e,loc); | |
151 } | |
152 return e; | |
153 } | |
154 } | |
155 |