Mercurial > projects > ddmd
annotate dmd/DeleteDeclaration.d @ 179:cd48cb899aee
Updated to dmd2.040
author | korDen |
---|---|
date | Sun, 17 Oct 2010 20:56:07 +0400 |
parents | e3afd1303184 |
children | b0d41ff5e0df |
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 //printf("DeleteDeclaration.semantic()\n"); |
47 | |
48 parent = sc.parent; | |
49 Dsymbol parent = toParent(); | |
179 | 50 ClassDeclaration cd = parent.isClassDeclaration(); |
123 | 51 if (!cd && !parent.isStructDeclaration()) |
52 { | |
53 error("new allocators only are for class or struct definitions"); | |
54 } | |
179 | 55 if (!type) |
56 type = new TypeFunction(arguments, Type.tvoid, 0, LINKd); | |
123 | 57 |
58 type = type.semantic(loc, sc); | |
59 assert(type.ty == Tfunction); | |
60 | |
61 // Check that there is only one argument of type void* | |
62 TypeFunction tf = cast(TypeFunction)type; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
63 if (Parameter.dim(tf.parameters) != 1) |
123 | 64 { |
65 error("one argument of type void* expected"); | |
66 } | |
67 else | |
68 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
69 auto a = Parameter.getNth(tf.parameters, 0); |
123 | 70 if (!a.type.equals(Type.tvoid.pointerTo())) |
71 error("one argument of type void* expected, not %s", a.type.toChars()); | |
72 } | |
73 | |
74 FuncDeclaration.semantic(sc); | |
0 | 75 } |
76 | |
72 | 77 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 78 { |
123 | 79 buf.writestring("delete"); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
80 Parameter.argsToCBuffer(buf, hgs, arguments, 0); |
123 | 81 bodyToCBuffer(buf, hgs); |
0 | 82 } |
83 | |
72 | 84 override string kind() |
0 | 85 { |
123 | 86 return "deallocator"; |
0 | 87 } |
88 | |
72 | 89 override bool isDelete() |
0 | 90 { |
123 | 91 return true; |
0 | 92 } |
93 | |
72 | 94 override bool isVirtual() |
0 | 95 { |
123 | 96 return false; |
0 | 97 } |
98 | |
72 | 99 override bool addPreInvariant() |
0 | 100 { |
123 | 101 return false; |
0 | 102 } |
103 | |
72 | 104 override bool addPostInvariant() |
0 | 105 { |
123 | 106 return false; |
0 | 107 } |
108 | |
109 version (_DH) { | |
110 DeleteDeclaration isDeleteDeclaration() { return this; } | |
111 } | |
72 | 112 } |