Mercurial > projects > ddmd
annotate dmd/DeleteDeclaration.d @ 161:584dc990e12f
type fixed
author | korDen |
---|---|
date | Mon, 20 Sep 2010 01:19:36 +0400 |
parents | 60bb0fe4563e |
children | e3afd1303184 |
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 { |
123 | 26 super(loc, endloc, Id.classDelete, STCstatic, null); |
27 this.arguments = arguments; | |
0 | 28 } |
29 | |
72 | 30 override Dsymbol syntaxCopy(Dsymbol) |
0 | 31 { |
123 | 32 DeleteDeclaration f; |
33 | |
34 f = new DeleteDeclaration(loc, endloc, null); | |
35 | |
36 FuncDeclaration.syntaxCopy(f); | |
37 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
38 f.arguments = Parameter.arraySyntaxCopy(arguments); |
123 | 39 |
40 return f; | |
0 | 41 } |
42 | |
72 | 43 override void semantic(Scope sc) |
0 | 44 { |
123 | 45 ClassDeclaration cd; |
46 | |
47 //printf("DeleteDeclaration.semantic()\n"); | |
48 | |
49 parent = sc.parent; | |
50 Dsymbol parent = toParent(); | |
51 cd = parent.isClassDeclaration(); | |
52 if (!cd && !parent.isStructDeclaration()) | |
53 { | |
54 error("new allocators only are for class or struct definitions"); | |
55 } | |
56 type = new TypeFunction(arguments, Type.tvoid, 0, LINKd); | |
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 } |