Mercurial > projects > ddmd
annotate dmd/DeleteDeclaration.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 | 60bb0fe4563e |
children | cd48cb899aee |
rev | line source |
---|---|
0 | 1 module dmd.DeleteDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.FuncDeclaration; |
5 import dmd.ArrayTypes; | |
6 import dmd.Loc; | |
7 import dmd.Dsymbol; | |
8 import dmd.Scope; | |
9 import dmd.OutBuffer; | |
10 import dmd.HdrGenState; | |
11 import dmd.STC; | |
123 | 12 import dmd.Id; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
13 import dmd.Parameter; |
123 | 14 import dmd.ClassDeclaration; |
15 import dmd.TypeFunction; | |
16 import dmd.Type; | |
17 import dmd.LINK; | |
18 import dmd.TY; | |
0 | 19 |
20 class DeleteDeclaration : FuncDeclaration | |
21 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
22 Parameters arguments; |
0 | 23 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
24 this(Loc loc, Loc endloc, Parameters arguments) |
0 | 25 { |
178 | 26 register(); |
123 | 27 super(loc, endloc, Id.classDelete, STCstatic, null); |
28 this.arguments = arguments; | |
0 | 29 } |
30 | |
72 | 31 override Dsymbol syntaxCopy(Dsymbol) |
0 | 32 { |
123 | 33 DeleteDeclaration f; |
34 | |
35 f = new DeleteDeclaration(loc, endloc, null); | |
36 | |
37 FuncDeclaration.syntaxCopy(f); | |
38 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
39 f.arguments = Parameter.arraySyntaxCopy(arguments); |
123 | 40 |
41 return f; | |
0 | 42 } |
43 | |
72 | 44 override void semantic(Scope sc) |
0 | 45 { |
123 | 46 ClassDeclaration cd; |
47 | |
48 //printf("DeleteDeclaration.semantic()\n"); | |
49 | |
50 parent = sc.parent; | |
51 Dsymbol parent = toParent(); | |
52 cd = parent.isClassDeclaration(); | |
53 if (!cd && !parent.isStructDeclaration()) | |
54 { | |
55 error("new allocators only are for class or struct definitions"); | |
56 } | |
57 type = new TypeFunction(arguments, Type.tvoid, 0, LINKd); | |
58 | |
59 type = type.semantic(loc, sc); | |
60 assert(type.ty == Tfunction); | |
61 | |
62 // Check that there is only one argument of type void* | |
63 TypeFunction tf = cast(TypeFunction)type; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
64 if (Parameter.dim(tf.parameters) != 1) |
123 | 65 { |
66 error("one argument of type void* expected"); | |
67 } | |
68 else | |
69 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
70 auto a = Parameter.getNth(tf.parameters, 0); |
123 | 71 if (!a.type.equals(Type.tvoid.pointerTo())) |
72 error("one argument of type void* expected, not %s", a.type.toChars()); | |
73 } | |
74 | |
75 FuncDeclaration.semantic(sc); | |
0 | 76 } |
77 | |
72 | 78 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 79 { |
123 | 80 buf.writestring("delete"); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
81 Parameter.argsToCBuffer(buf, hgs, arguments, 0); |
123 | 82 bodyToCBuffer(buf, hgs); |
0 | 83 } |
84 | |
72 | 85 override string kind() |
0 | 86 { |
123 | 87 return "deallocator"; |
0 | 88 } |
89 | |
72 | 90 override bool isDelete() |
0 | 91 { |
123 | 92 return true; |
0 | 93 } |
94 | |
72 | 95 override bool isVirtual() |
0 | 96 { |
123 | 97 return false; |
0 | 98 } |
99 | |
72 | 100 override bool addPreInvariant() |
0 | 101 { |
123 | 102 return false; |
0 | 103 } |
104 | |
72 | 105 override bool addPostInvariant() |
0 | 106 { |
123 | 107 return false; |
0 | 108 } |
109 | |
110 version (_DH) { | |
111 DeleteDeclaration isDeleteDeclaration() { return this; } | |
112 } | |
72 | 113 } |