0
|
1 module dmd.DivExp;
|
|
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.IntRange;
|
|
11 import dmd.IRState;
|
|
12 import dmd.ArrayTypes;
|
|
13 import dmd.BinExp;
|
|
14 import dmd.TOK;
|
|
15 import dmd.Type;
|
|
16 import dmd.NegExp;
|
|
17 import dmd.TY;
|
|
18 import dmd.Id;
|
|
19
|
|
20 import dmd.expression.Div;
|
|
21 import dmd.backend.OPER;
|
|
22 import dmd.backend.Util;
|
|
23
|
|
24 class DivExp : BinExp
|
|
25 {
|
|
26 this(Loc loc, Expression e1, Expression e2)
|
|
27 {
|
|
28 super(loc, TOK.TOKdiv, DivExp.sizeof, e1, e2);
|
|
29 }
|
|
30
|
|
31 Expression semantic(Scope sc)
|
|
32 {
|
|
33 Expression e;
|
|
34
|
|
35 if (type)
|
|
36 return this;
|
|
37
|
|
38 super.semanticp(sc);
|
|
39 e = op_overload(sc);
|
|
40 if (e)
|
|
41 return e;
|
|
42
|
|
43 typeCombine(sc);
|
|
44 if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice)
|
|
45 {
|
|
46 e1.checkArithmetic();
|
|
47 e2.checkArithmetic();
|
|
48 }
|
|
49 if (type.isfloating())
|
|
50 {
|
|
51 Type t1 = e1.type;
|
|
52 Type t2 = e2.type;
|
|
53
|
|
54 if (t1.isreal())
|
|
55 {
|
|
56 type = t2;
|
|
57 if (t2.isimaginary())
|
|
58 {
|
|
59 // x/iv = i(-x/v)
|
|
60 e2.type = t1;
|
|
61 Expression ee = new NegExp(loc, this);
|
|
62 ee = ee.semantic(sc);
|
|
63 return e;
|
|
64 }
|
|
65 }
|
|
66 else if (t2.isreal())
|
|
67 {
|
|
68 type = t1;
|
|
69 }
|
|
70 else if (t1.isimaginary())
|
|
71 {
|
|
72 if (t2.isimaginary()) {
|
|
73 switch (t1.ty)
|
|
74 {
|
|
75 case TY.Timaginary32: type = Type.tfloat32; break;
|
|
76 case TY.Timaginary64: type = Type.tfloat64; break;
|
|
77 case TY.Timaginary80: type = Type.tfloat80; break;
|
|
78 default: assert(0);
|
|
79 }
|
|
80 } else {
|
|
81 type = t2; // t2 is complex
|
|
82 }
|
|
83 }
|
|
84 else if (t2.isimaginary())
|
|
85 {
|
|
86 type = t1; // t1 is complex
|
|
87 }
|
|
88 }
|
|
89 return this;
|
|
90 }
|
|
91
|
|
92 Expression optimize(int result)
|
|
93 {
|
|
94 Expression e;
|
|
95
|
|
96 //printf("DivExp.optimize(%s)\n", toChars());
|
|
97 e1 = e1.optimize(result);
|
|
98 e2 = e2.optimize(result);
|
|
99 if (e1.isConst() == 1 && e2.isConst() == 1)
|
|
100 {
|
|
101 e = Div(type, e1, e2);
|
|
102 }
|
|
103 else
|
|
104 e = this;
|
|
105 return e;
|
|
106 }
|
|
107
|
|
108 Expression interpret(InterState* istate)
|
|
109 {
|
|
110 assert(false);
|
|
111 }
|
|
112
|
|
113 void buildArrayIdent(OutBuffer buf, Expressions arguments)
|
|
114 {
|
|
115 assert(false);
|
|
116 }
|
|
117
|
|
118 Expression buildArrayLoop(Arguments fparams)
|
|
119 {
|
|
120 assert(false);
|
|
121 }
|
|
122
|
|
123 IntRange getIntRange()
|
|
124 {
|
|
125 assert(false);
|
|
126 }
|
|
127
|
|
128 Identifier opId()
|
|
129 {
|
|
130 return Id.div;
|
|
131 }
|
|
132
|
|
133 Identifier opId_r()
|
|
134 {
|
|
135 return Id.div_r;
|
|
136 }
|
|
137
|
|
138 elem* toElem(IRState* irs)
|
|
139 {
|
|
140 return toElemBin(irs,OPdiv);
|
|
141 }
|
|
142 }
|
|
143
|