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
|
|
75 Expression interpret(InterState* istate)
|
|
76 {
|
|
77 assert(false);
|
|
78 }
|
|
79
|
|
80 void buildArrayIdent(OutBuffer buf, Expressions arguments)
|
|
81 {
|
|
82 assert(false);
|
|
83 }
|
|
84
|
|
85 Expression buildArrayLoop(Arguments fparams)
|
|
86 {
|
|
87 assert(false);
|
|
88 }
|
|
89
|
|
90 Identifier opId()
|
|
91 {
|
|
92 return Id.mod;
|
|
93 }
|
|
94
|
|
95 Identifier opId_r()
|
|
96 {
|
|
97 return Id.mod_r;
|
|
98 }
|
|
99
|
|
100 elem* toElem(IRState* irs)
|
|
101 {
|
|
102 elem* e;
|
|
103 elem* e1;
|
|
104 elem* e2;
|
|
105 tym_t tym;
|
|
106
|
|
107 tym = type.totym();
|
|
108
|
|
109 e1 = this.e1.toElem(irs);
|
|
110 e2 = this.e2.toElem(irs);
|
|
111
|
|
112 static if (false) { // Now inlined
|
|
113 if (this.e1.type.isfloating())
|
|
114 {
|
|
115 elem* ep;
|
|
116
|
|
117 switch (this.e1.type.ty)
|
|
118 {
|
|
119 case Tfloat32:
|
|
120 case Timaginary32:
|
|
121 e1 = el_una(OPf_d, TYdouble, e1);
|
|
122 e2 = el_una(OPf_d, TYdouble, e2);
|
|
123 case Tfloat64:
|
|
124 case Timaginary64:
|
|
125 e1 = el_una(OPd_ld, TYldouble, e1);
|
|
126 e2 = el_una(OPd_ld, TYldouble, e2);
|
|
127 break;
|
|
128 case Tfloat80:
|
|
129 case Timaginary80:
|
|
130 break;
|
|
131 default:
|
|
132 assert(0);
|
|
133 break;
|
|
134 }
|
|
135 ep = el_param(e2,e1);
|
|
136 e = el_bin(OPcall,tym,el_var(rtlsym[RTLSYM_MODULO]),ep);
|
|
137 }
|
|
138 else
|
|
139 {
|
|
140 e = el_bin(OPmod,tym,e1,e2);
|
|
141 el_setLoc(e,loc);
|
|
142 }
|
|
143 } else {
|
|
144 e = el_bin(OPmod,tym,e1,e2);
|
|
145 el_setLoc(e,loc);
|
|
146 }
|
|
147 return e;
|
|
148 }
|
|
149 }
|
|
150
|