Mercurial > projects > ddmd
annotate dmd/XorExp.d @ 115:6caaf0256da1
+ interpretation of (non-assign) binary expressions
+ BinExp.isunsigned
+ EqualExp.isBit
author | Trass3r |
---|---|
date | Thu, 02 Sep 2010 01:29:29 +0200 |
parents | e28b18c23469 |
children | 9e39c7de8438 |
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 | |
72 | 84 override Expression buildArrayLoop(Arguments fparams) |
0 | 85 { |
72 | 86 /* Evaluate assign expressions left to right |
87 */ | |
88 Expression ex1 = e1.buildArrayLoop(fparams); | |
89 Expression ex2 = e2.buildArrayLoop(fparams); | |
90 Expression e = new XorExp(Loc(0), ex1, ex2); | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
91 return e; |
0 | 92 } |
93 | |
72 | 94 override MATCH implicitConvTo(Type t) |
0 | 95 { |
72 | 96 MATCH result = Expression.implicitConvTo(t); |
97 | |
98 if (result == MATCHnomatch) | |
99 { | |
100 MATCH m1 = e1.implicitConvTo(t); | |
101 MATCH m2 = e2.implicitConvTo(t); | |
102 | |
103 // Pick the worst match | |
104 result = (m1 < m2) ? m1 : m2; | |
105 } | |
56 | 106 return result; |
0 | 107 } |
108 | |
72 | 109 override IntRange getIntRange() |
0 | 110 { |
111 assert(false); | |
112 } | |
113 | |
72 | 114 override bool isCommutative() |
0 | 115 { |
116 return true; | |
117 } | |
118 | |
72 | 119 override Identifier opId() |
0 | 120 { |
121 return Id.ixor; | |
122 } | |
123 | |
72 | 124 override Identifier opId_r() |
0 | 125 { |
126 return Id.ixor_r; | |
127 } | |
128 | |
72 | 129 override elem* toElem(IRState* irs) |
0 | 130 { |
67 | 131 return toElemBin(irs,OPxor); |
0 | 132 } |
133 } | |
134 |