Mercurial > projects > ddmd
annotate dmd/IdentityExp.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 | af1bebfd96a4 |
rev | line source |
---|---|
72 | 1 module dmd.IdentityExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.InterState; | |
6 import dmd.Loc; | |
7 import dmd.Scope; | |
8 import dmd.IRState; | |
9 import dmd.BinExp; | |
0 | 10 import dmd.TOK; |
11 import dmd.Type; | |
12 import dmd.WANT; | |
13 import dmd.TY; | |
73 | 14 import dmd.GlobalExpressions; |
72 | 15 import dmd.expression.Identity; |
16 | |
0 | 17 import dmd.backend.elem; |
18 import dmd.backend.TYM; | |
19 import dmd.backend.OPER; | |
20 import dmd.backend.Util; | |
72 | 21 import dmd.codegen.Util; |
22 | |
0 | 23 class IdentityExp : BinExp |
24 { | |
25 this(TOK op, Loc loc, Expression e1, Expression e2) | |
26 { | |
27 super(loc, op, IdentityExp.sizeof, e1, e2); | |
28 } | |
29 | |
72 | 30 override Expression semantic(Scope sc) |
0 | 31 { |
32 if (type) | |
33 return this; | |
34 | |
35 BinExp.semanticp(sc); | |
36 type = Type.tboolean; | |
37 typeCombine(sc); | |
38 | |
39 if (e1.type != e2.type && e1.type.isfloating() && e2.type.isfloating()) | |
40 { | |
41 // Cast both to complex | |
42 e1 = e1.castTo(sc, Type.tcomplex80); | |
43 e2 = e2.castTo(sc, Type.tcomplex80); | |
44 } | |
45 | |
46 return this; | |
47 } | |
48 | |
72 | 49 override int isBit() |
0 | 50 { |
51 assert(false); | |
52 } | |
53 | |
72 | 54 override Expression optimize(int result) |
0 | 55 { |
56 Expression e; | |
57 | |
58 //printf("IdentityExp.optimize(result = %d) %s\n", result, toChars()); | |
59 e1 = e1.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret)); | |
60 e2 = e2.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret)); | |
61 e = this; | |
62 | |
63 if ((this.e1.isConst() && this.e2.isConst()) || (this.e1.op == TOK.TOKnull && this.e2.op == TOK.TOKnull)) | |
64 { | |
65 e = Identity(op, type, this.e1, this.e2); | |
73 | 66 if (e is EXP_CANT_INTERPRET) |
67 e = this; | |
0 | 68 } |
69 | |
70 return e; | |
71 } | |
72 | |
72 | 73 override Expression interpret(InterState istate) |
0 | 74 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
75 return interpretCommon2(istate, &Identity); |
0 | 76 } |
77 | |
72 | 78 override elem* toElem(IRState* irs) |
0 | 79 { |
80 elem *e; | |
81 OPER eop; | |
82 Type t1 = e1.type.toBasetype(); | |
83 Type t2 = e2.type.toBasetype(); | |
84 | |
85 switch (op) | |
86 { | |
87 case TOK.TOKidentity: eop = OPER.OPeqeq; break; | |
88 case TOK.TOKnotidentity: eop = OPER.OPne; break; | |
89 default: | |
90 dump(0); | |
91 assert(0); | |
92 } | |
93 | |
94 //printf("IdentityExp.toElem() %s\n", toChars()); | |
95 | |
96 if (t1.ty == TY.Tstruct) | |
97 { | |
98 // Do bit compare of struct's | |
99 elem* es1; | |
100 elem* es2; | |
101 elem* ecount; | |
102 | |
103 es1 = e1.toElem(irs); | |
104 es1 = addressElem(es1, e1.type); | |
105 //es1 = el_una(OPaddr, TYnptr, es1); | |
106 es2 = e2.toElem(irs); | |
107 es2 = addressElem(es2, e2.type); | |
108 //es2 = el_una(OPaddr, TYnptr, es2); | |
109 e = el_param(es1, es2); | |
110 ecount = el_long(TYM.TYint, t1.size()); | |
111 e = el_bin(OPER.OPmemcmp, TYM.TYint, e, ecount); | |
112 e = el_bin(eop, TYM.TYint, e, el_long(TYM.TYint, 0)); | |
113 el_setLoc(e,loc); | |
114 } | |
115 else if ((t1.ty == TY.Tarray || t1.ty == TY.Tsarray) && (t2.ty == TY.Tarray || t2.ty == TY.Tsarray)) | |
116 { | |
117 elem* ea1; | |
118 elem* ea2; | |
119 | |
120 ea1 = e1.toElem(irs); | |
121 ea1 = array_toDarray(t1, ea1); | |
122 ea2 = e2.toElem(irs); | |
123 ea2 = array_toDarray(t2, ea2); | |
124 | |
125 e = el_bin(eop, type.totym(), ea1, ea2); | |
126 el_setLoc(e,loc); | |
127 } | |
128 else | |
129 e = toElemBin(irs, eop); | |
130 | |
131 return e; | |
132 } | |
133 } | |
134 |