Mercurial > projects > ddmd
annotate dmd/IdentityExp.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | 6caaf0256da1 |
children | e3afd1303184 |
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 //printf("IdentityExp.optimize(result = %d) %s\n", result, toChars()); | |
57 e1 = e1.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret)); | |
58 e2 = e2.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret)); | |
135 | 59 Expression e = this; |
0 | 60 |
61 if ((this.e1.isConst() && this.e2.isConst()) || (this.e1.op == TOK.TOKnull && this.e2.op == TOK.TOKnull)) | |
62 { | |
63 e = Identity(op, type, this.e1, this.e2); | |
73 | 64 if (e is EXP_CANT_INTERPRET) |
65 e = this; | |
0 | 66 } |
67 | |
68 return e; | |
69 } | |
70 | |
72 | 71 override Expression interpret(InterState istate) |
0 | 72 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
73 return interpretCommon2(istate, &Identity); |
0 | 74 } |
75 | |
72 | 76 override elem* toElem(IRState* irs) |
0 | 77 { |
78 elem *e; | |
79 OPER eop; | |
80 Type t1 = e1.type.toBasetype(); | |
81 Type t2 = e2.type.toBasetype(); | |
82 | |
83 switch (op) | |
84 { | |
85 case TOK.TOKidentity: eop = OPER.OPeqeq; break; | |
86 case TOK.TOKnotidentity: eop = OPER.OPne; break; | |
87 default: | |
88 dump(0); | |
89 assert(0); | |
90 } | |
91 | |
92 //printf("IdentityExp.toElem() %s\n", toChars()); | |
93 | |
94 if (t1.ty == TY.Tstruct) | |
95 { | |
96 // Do bit compare of struct's | |
97 elem* es1; | |
98 elem* es2; | |
99 elem* ecount; | |
100 | |
101 es1 = e1.toElem(irs); | |
102 es1 = addressElem(es1, e1.type); | |
103 //es1 = el_una(OPaddr, TYnptr, es1); | |
104 es2 = e2.toElem(irs); | |
105 es2 = addressElem(es2, e2.type); | |
106 //es2 = el_una(OPaddr, TYnptr, es2); | |
107 e = el_param(es1, es2); | |
108 ecount = el_long(TYM.TYint, t1.size()); | |
109 e = el_bin(OPER.OPmemcmp, TYM.TYint, e, ecount); | |
110 e = el_bin(eop, TYM.TYint, e, el_long(TYM.TYint, 0)); | |
111 el_setLoc(e,loc); | |
112 } | |
113 else if ((t1.ty == TY.Tarray || t1.ty == TY.Tsarray) && (t2.ty == TY.Tarray || t2.ty == TY.Tsarray)) | |
114 { | |
115 elem* ea1; | |
116 elem* ea2; | |
117 | |
118 ea1 = e1.toElem(irs); | |
119 ea1 = array_toDarray(t1, ea1); | |
120 ea2 = e2.toElem(irs); | |
121 ea2 = array_toDarray(t2, ea2); | |
122 | |
123 e = el_bin(eop, type.totym(), ea1, ea2); | |
124 el_setLoc(e,loc); | |
125 } | |
126 else | |
127 e = toElemBin(irs, eop); | |
128 | |
129 return e; | |
130 } | |
131 } | |
132 |