Mercurial > projects > ddmd
annotate dmd/ModExp.d @ 109:ceda59b4d255
expression.c changes, now only ddoc should be left
author | Trass3r |
---|---|
date | Tue, 31 Aug 2010 22:08:52 +0200 |
parents | 2e2a5c3f943a |
children | e28b18c23469 |
rev | line source |
---|---|
72 | 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; | |
0 | 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; | |
72 | 21 import dmd.backend.Util; |
22 | |
0 | 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 | |
72 | 30 override Expression semantic(Scope sc) |
0 | 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); | |
109 | 43 if (!e1.isArrayOperand()) |
0 | 44 e1.checkArithmetic(); |
109 | 45 if (!e2.isArrayOperand()) |
0 | 46 e2.checkArithmetic(); |
109 | 47 |
0 | 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 | |
72 | 60 override Expression optimize(int result) |
0 | 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 | |
72 | 75 override Expression interpret(InterState istate) |
0 | 76 { |
77 assert(false); | |
78 } | |
79 | |
72 | 80 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 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 | |
72 | 85 override Expression buildArrayLoop(Arguments fparams) |
0 | 86 { |
72 | 87 /* Evaluate assign expressions left to right |
88 */ | |
89 Expression ex1 = e1.buildArrayLoop(fparams); | |
90 Expression ex2 = e2.buildArrayLoop(fparams); | |
91 Expression e = new ModExp(Loc(0), ex1, ex2); | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
92 return e; |
0 | 93 } |
94 | |
72 | 95 override Identifier opId() |
0 | 96 { |
97 return Id.mod; | |
98 } | |
99 | |
72 | 100 override Identifier opId_r() |
0 | 101 { |
102 return Id.mod_r; | |
103 } | |
104 | |
72 | 105 override elem* toElem(IRState* irs) |
0 | 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 |