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