Mercurial > projects > ddmd
annotate dmd/XorExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | 9e39c7de8438 |
children | e3afd1303184 |
rev | line source |
---|---|
72 | 1 module dmd.XorExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
6 import dmd.InterState; | |
0 | 7 import dmd.MATCH; |
72 | 8 import dmd.Id; |
9 import dmd.Type; | |
10 import dmd.OutBuffer; | |
11 import dmd.Loc; | |
12 import dmd.Scope; | |
13 import dmd.IntRange; | |
14 import dmd.IRState; | |
15 import dmd.ArrayTypes; | |
16 import dmd.BinExp; | |
0 | 17 import dmd.TOK; |
72 | 18 import dmd.TY; |
19 | |
20 import dmd.backend.elem; | |
67 | 21 import dmd.backend.OPER; |
0 | 22 import dmd.expression.Util; |
72 | 23 import dmd.expression.Xor; |
24 | |
0 | 25 class XorExp : BinExp |
26 { | |
27 this(Loc loc, Expression e1, Expression e2) | |
28 { | |
29 super(loc, TOK.TOKxor, XorExp.sizeof, e1, e2); | |
30 } | |
31 | |
72 | 32 override Expression semantic(Scope sc) |
0 | 33 { |
34 Expression e; | |
35 | |
36 if (!type) | |
37 { | |
38 BinExp.semanticp(sc); | |
39 e = op_overload(sc); | |
40 if (e) | |
41 return e; | |
42 if (e1.type.toBasetype().ty == Tbool && | |
43 e2.type.toBasetype().ty == Tbool) | |
44 { | |
45 type = e1.type; | |
46 e = this; | |
47 } | |
48 else | |
49 { | |
50 typeCombine(sc); | |
109 | 51 if (!e1.isArrayOperand()) |
0 | 52 e1.checkIntegral(); |
109 | 53 if (!e2.isArrayOperand()) |
0 | 54 e2.checkIntegral(); |
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 e = Xor(type, e1, e2); | |
68 else | |
69 e = this; | |
70 | |
71 return e; | |
72 } | |
73 | |
72 | 74 override Expression interpret(InterState istate) |
0 | 75 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
76 return interpretCommon(istate, &Xor); |
0 | 77 } |
78 | |
72 | 79 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 80 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
81 Exp_buildArrayIdent(buf, arguments, "Xor"); |
0 | 82 } |
83 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
84 override Expression buildArrayLoop(Parameters fparams) |
0 | 85 { |
123 | 86 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 87 } |
88 | |
72 | 89 override MATCH implicitConvTo(Type t) |
0 | 90 { |
72 | 91 MATCH result = Expression.implicitConvTo(t); |
92 | |
93 if (result == MATCHnomatch) | |
94 { | |
95 MATCH m1 = e1.implicitConvTo(t); | |
96 MATCH m2 = e2.implicitConvTo(t); | |
97 | |
98 // Pick the worst match | |
99 result = (m1 < m2) ? m1 : m2; | |
100 } | |
56 | 101 return result; |
0 | 102 } |
103 | |
72 | 104 override IntRange getIntRange() |
0 | 105 { |
106 assert(false); | |
107 } | |
108 | |
72 | 109 override bool isCommutative() |
0 | 110 { |
111 return true; | |
112 } | |
113 | |
72 | 114 override Identifier opId() |
0 | 115 { |
116 return Id.ixor; | |
117 } | |
118 | |
72 | 119 override Identifier opId_r() |
0 | 120 { |
121 return Id.ixor_r; | |
122 } | |
123 | |
72 | 124 override elem* toElem(IRState* irs) |
0 | 125 { |
67 | 126 return toElemBin(irs,OPxor); |
0 | 127 } |
128 } | |
129 |