comparison dmd/Expression.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 7171e6ea651d
children cd48cb899aee
comparison
equal deleted inserted replaced
177:1475fd394c9e 178:e3afd1303184
181 string type_print(Type type) 181 string type_print(Type type)
182 { 182 {
183 return type ? type.toChars() : "null"; 183 return type ? type.toChars() : "null";
184 } 184 }
185 185
186 class Expression 186 import dmd.TObject;
187
188 class Expression : TObject
187 { 189 {
188 Loc loc; // file location 190 Loc loc; // file location
189 TOK op; // handy to minimize use of dynamic_cast 191 TOK op; // handy to minimize use of dynamic_cast
190 Type type; // !=null means that semantic() has been run 192 Type type; // !=null means that semantic() has been run
191 int size; // # of bytes in Expression so we can copy() it 193 int size; // # of bytes in Expression so we can copy() it
192 194
193 this(Loc loc, TOK op, int size) 195 this(Loc loc, TOK op, int size)
194 { 196 {
197 register();
195 this.loc = loc; 198 this.loc = loc;
196 //writef("Expression.Expression(op = %d %s) this = %p\n", op, to!(string)(op), this); 199 //writef("Expression.Expression(op = %d %s) this = %p\n", op, to!(string)(op), this);
197 this.op = op; 200 this.op = op;
198 this.size = size; 201 this.size = size;
199 type = null; 202 type = null;
205 } 208 }
206 209
207 /********************************* 210 /*********************************
208 * Does *not* do a deep copy. 211 * Does *not* do a deep copy.
209 */ 212 */
210 Expression copy() /// bad bad bad 213 Expression copy()
211 { 214 {
212 Expression e; 215 return cloneThis(this);
213 if (!size)
214 {
215 debug {
216 writef("No expression copy for: %s\n", toChars());
217 writef("op = %d\n", op);
218 dump(0);
219 }
220 assert(0);
221 }
222 auto size = this.classinfo.init.length;
223 auto ptr = GC.malloc(size);
224 memcpy(ptr, cast(void*)this, size);
225
226 return cast(Expression)ptr;
227 } 216 }
228 217
229 Expression syntaxCopy() 218 Expression syntaxCopy()
230 { 219 {
231 //printf("Expression::syntaxCopy()\n"); 220 //printf("Expression::syntaxCopy()\n");