Mercurial > projects > ddmd
annotate dmd/XorExp.d @ 63:cab4c37afb89
A bunch of implementations
author | korDen |
---|---|
date | Mon, 23 Aug 2010 16:52:24 +0400 |
parents | 51605de93870 |
children | f708f0452e81 |
rev | line source |
---|---|
0 | 1 module dmd.XorExp; |
2 | |
3 import dmd.Expression; | |
4 import dmd.Identifier; | |
5 import dmd.InterState; | |
6 import dmd.MATCH; | |
7 import dmd.Id; | |
8 import dmd.Type; | |
9 import dmd.OutBuffer; | |
10 import dmd.Loc; | |
11 import dmd.Scope; | |
12 import dmd.IntRange; | |
13 import dmd.IRState; | |
14 import dmd.ArrayTypes; | |
15 import dmd.BinExp; | |
16 import dmd.TOK; | |
17 import dmd.TY; | |
18 | |
19 import dmd.backend.elem; | |
20 import dmd.expression.Util; | |
21 import dmd.expression.Xor; | |
22 | |
23 class XorExp : BinExp | |
24 { | |
25 this(Loc loc, Expression e1, Expression e2) | |
26 { | |
27 super(loc, TOK.TOKxor, XorExp.sizeof, e1, e2); | |
28 } | |
29 | |
30 Expression semantic(Scope sc) | |
31 { | |
32 Expression e; | |
33 | |
34 if (!type) | |
35 { | |
36 BinExp.semanticp(sc); | |
37 e = op_overload(sc); | |
38 if (e) | |
39 return e; | |
40 if (e1.type.toBasetype().ty == Tbool && | |
41 e2.type.toBasetype().ty == Tbool) | |
42 { | |
43 type = e1.type; | |
44 e = this; | |
45 } | |
46 else | |
47 { | |
48 typeCombine(sc); | |
49 if (e1.op != TOKslice && e2.op != TOKslice) | |
50 { | |
51 e1.checkIntegral(); | |
52 e2.checkIntegral(); | |
53 } | |
54 } | |
55 } | |
56 return this; | |
57 } | |
58 | |
59 Expression optimize(int result) | |
60 { | |
61 Expression e; | |
62 | |
63 e1 = e1.optimize(result); | |
64 e2 = e2.optimize(result); | |
65 if (e1.isConst() == 1 && e2.isConst() == 1) | |
66 e = Xor(type, e1, e2); | |
67 else | |
68 e = this; | |
69 | |
70 return e; | |
71 } | |
72 | |
63 | 73 Expression interpret(InterState istate) |
0 | 74 { |
75 assert(false); | |
76 } | |
77 | |
78 void buildArrayIdent(OutBuffer buf, Expressions arguments) | |
79 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
80 Exp_buildArrayIdent(buf, arguments, "Xor"); |
0 | 81 } |
82 | |
83 Expression buildArrayLoop(Arguments fparams) | |
84 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
85 /* Evaluate assign expressions left to right |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
86 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
87 Expression ex1 = e1.buildArrayLoop(fparams); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
88 Expression ex2 = e2.buildArrayLoop(fparams); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
89 Expression e = new XorExp(Loc(0), ex1, ex2); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
90 return e; |
0 | 91 } |
92 | |
93 MATCH implicitConvTo(Type t) | |
94 { | |
56 | 95 MATCH result = Expression.implicitConvTo(t); |
96 | |
97 if (result == MATCHnomatch) | |
98 { | |
99 MATCH m1 = e1.implicitConvTo(t); | |
100 MATCH m2 = e2.implicitConvTo(t); | |
101 | |
102 // Pick the worst match | |
103 result = (m1 < m2) ? m1 : m2; | |
104 } | |
105 return result; | |
0 | 106 } |
107 | |
108 IntRange getIntRange() | |
109 { | |
110 assert(false); | |
111 } | |
112 | |
113 bool isCommutative() | |
114 { | |
115 return true; | |
116 } | |
117 | |
118 Identifier opId() | |
119 { | |
120 return Id.ixor; | |
121 } | |
122 | |
123 Identifier opId_r() | |
124 { | |
125 return Id.ixor_r; | |
126 } | |
127 | |
128 elem* toElem(IRState* irs) | |
129 { | |
130 assert(false); | |
131 } | |
132 } | |
133 |