Mercurial > projects > ddmd
annotate dmd/IdentityExp.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | af1bebfd96a4 |
children | b0d41ff5e0df |
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 { | |
178 | 27 register(); |
0 | 28 super(loc, op, IdentityExp.sizeof, e1, e2); |
29 } | |
30 | |
72 | 31 override Expression semantic(Scope sc) |
0 | 32 { |
33 if (type) | |
34 return this; | |
35 | |
36 BinExp.semanticp(sc); | |
37 type = Type.tboolean; | |
38 typeCombine(sc); | |
39 | |
40 if (e1.type != e2.type && e1.type.isfloating() && e2.type.isfloating()) | |
41 { | |
42 // Cast both to complex | |
43 e1 = e1.castTo(sc, Type.tcomplex80); | |
44 e2 = e2.castTo(sc, Type.tcomplex80); | |
45 } | |
46 | |
47 return this; | |
48 } | |
49 | |
72 | 50 override int isBit() |
0 | 51 { |
52 assert(false); | |
53 } | |
54 | |
72 | 55 override Expression optimize(int result) |
0 | 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)); | |
135 | 60 Expression e = this; |
0 | 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 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
74 return interpretCommon2(istate, &Identity); |
0 | 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 |