Mercurial > projects > ddmd
annotate dmd/AndExp.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.AndExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
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.BinExp; | |
13 import dmd.TOK; | |
0 | 14 import dmd.ArrayTypes; |
15 import dmd.TY; | |
16 import dmd.Type; | |
17 import dmd.Id; | |
72 | 18 import dmd.Global; |
19 | |
0 | 20 import dmd.backend.elem; |
21 import dmd.backend.Util; | |
22 import dmd.backend.OPER; | |
23 import dmd.expression.Util; | |
72 | 24 import dmd.expression.And; |
25 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 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
|
27 |
0 | 28 class AndExp : BinExp |
29 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 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
|
31 |
0 | 32 this(Loc loc, Expression e1, Expression e2) |
33 { | |
178 | 34 register(); |
0 | 35 super(loc, TOK.TOKand, AndExp.sizeof, e1, e2); |
36 } | |
37 | |
72 | 38 override Expression semantic(Scope sc) |
0 | 39 { |
40 Expression e; | |
41 | |
42 if (!type) | |
43 { | |
44 BinExp.semanticp(sc); | |
45 e = op_overload(sc); | |
46 | |
47 if (e) | |
48 return e; | |
49 | |
50 if (e1.type.toBasetype().ty == TY.Tbool && e2.type.toBasetype().ty == TY.Tbool) | |
51 { | |
52 type = e1.type; | |
53 e = this; | |
54 } | |
55 else | |
56 { | |
57 typeCombine(sc); | |
109 | 58 if (!e1.isArrayOperand()) |
0 | 59 e1.checkIntegral(); |
109 | 60 if (!e2.isArrayOperand()) |
0 | 61 e2.checkIntegral(); |
62 } | |
63 } | |
64 return this; | |
65 } | |
66 | |
72 | 67 override Expression optimize(int result) |
0 | 68 { |
69 Expression e; | |
70 | |
71 e1 = e1.optimize(result); | |
72 e2 = e2.optimize(result); | |
73 if (e1.isConst() == 1 && e2.isConst() == 1) | |
74 e = And(type, e1, e2); | |
75 else | |
76 e = this; | |
77 | |
78 return e; | |
79 } | |
80 | |
72 | 81 override Expression interpret(InterState istate) |
0 | 82 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
83 return interpretCommon(istate, &And); |
0 | 84 } |
85 | |
72 | 86 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 87 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
88 Exp_buildArrayIdent(buf, arguments, "And"); |
0 | 89 } |
90 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
91 override Expression buildArrayLoop(Parameters fparams) |
0 | 92 { |
123 | 93 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 94 } |
95 | |
72 | 96 override IntRange getIntRange() |
0 | 97 { |
72 | 98 IntRange ir; |
99 IntRange ir1 = e1.getIntRange(); | |
100 IntRange ir2 = e2.getIntRange(); | |
101 | |
102 ir.imin = ir1.imin; | |
103 if (ir2.imin < ir.imin) | |
104 ir.imin = ir2.imin; | |
105 | |
106 ir.imax = ir1.imax; | |
107 if (ir2.imax > ir.imax) | |
108 ir.imax = ir2.imax; | |
109 | |
110 ulong u; | |
111 | |
112 u = getMask(ir1.imax); | |
113 ir.imin &= u; | |
114 ir.imax &= u; | |
115 | |
116 u = getMask(ir2.imax); | |
117 ir.imin &= u; | |
118 ir.imax &= u; | |
119 | |
120 ir.imin &= type.sizemask(); | |
121 ir.imax &= type.sizemask(); | |
122 | |
123 //printf("AndExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); | |
124 //e1.dump(0); | |
125 | |
53 | 126 return ir; |
0 | 127 } |
128 | |
72 | 129 override bool isCommutative() |
0 | 130 { |
131 return true; | |
132 } | |
133 | |
72 | 134 override Identifier opId() |
0 | 135 { |
136 return Id.iand; | |
137 } | |
138 | |
72 | 139 override Identifier opId_r() |
0 | 140 { |
141 return Id.iand_r; | |
142 } | |
143 | |
72 | 144 override elem* toElem(IRState* irs) |
0 | 145 { |
146 return toElemBin(irs, OPER.OPand); | |
147 } | |
148 } | |
149 |