Mercurial > projects > ddmd
annotate dmd/XorExp.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 |
0 | 27 class XorExp : BinExp |
28 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 |
0 | 31 this(Loc loc, Expression e1, Expression e2) |
32 { | |
178 | 33 register(); |
0 | 34 super(loc, TOK.TOKxor, XorExp.sizeof, e1, e2); |
35 } | |
36 | |
72 | 37 override Expression semantic(Scope sc) |
0 | 38 { |
39 Expression e; | |
40 | |
41 if (!type) | |
42 { | |
43 BinExp.semanticp(sc); | |
44 e = op_overload(sc); | |
45 if (e) | |
46 return e; | |
47 if (e1.type.toBasetype().ty == Tbool && | |
48 e2.type.toBasetype().ty == Tbool) | |
49 { | |
50 type = e1.type; | |
51 e = this; | |
52 } | |
53 else | |
54 { | |
55 typeCombine(sc); | |
109 | 56 if (!e1.isArrayOperand()) |
0 | 57 e1.checkIntegral(); |
109 | 58 if (!e2.isArrayOperand()) |
0 | 59 e2.checkIntegral(); |
60 } | |
61 } | |
62 return this; | |
63 } | |
64 | |
72 | 65 override Expression optimize(int result) |
0 | 66 { |
67 Expression e; | |
68 | |
69 e1 = e1.optimize(result); | |
70 e2 = e2.optimize(result); | |
71 if (e1.isConst() == 1 && e2.isConst() == 1) | |
72 e = Xor(type, e1, e2); | |
73 else | |
74 e = this; | |
75 | |
76 return e; | |
77 } | |
78 | |
72 | 79 override Expression interpret(InterState istate) |
0 | 80 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
81 return interpretCommon(istate, &Xor); |
0 | 82 } |
83 | |
72 | 84 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 85 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
86 Exp_buildArrayIdent(buf, arguments, "Xor"); |
0 | 87 } |
88 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
89 override Expression buildArrayLoop(Parameters fparams) |
0 | 90 { |
123 | 91 return Exp_buildArrayLoop!(typeof(this))(fparams); |
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 |