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