Mercurial > projects > ddmd
annotate dmd/DeleteDeclaration.d @ 191:52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
Also changed Array allocation policy:
Now doesn't reallocate but malloc's, followed by a memcpy (no free).
(this fixes a crash while compiling druntime. Same bug in dmd)
author | korDen@korDen-pc |
---|---|
date | Sun, 25 Mar 2012 03:11:12 +0400 |
parents | b0d41ff5e0df |
children |
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 |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
20 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
21 |
0 | 22 class DeleteDeclaration : FuncDeclaration |
23 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
24 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
25 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
26 Parameters arguments; |
0 | 27 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
28 this(Loc loc, Loc endloc, Parameters arguments) |
0 | 29 { |
178 | 30 register(); |
123 | 31 super(loc, endloc, Id.classDelete, STCstatic, null); |
32 this.arguments = arguments; | |
0 | 33 } |
34 | |
72 | 35 override Dsymbol syntaxCopy(Dsymbol) |
0 | 36 { |
123 | 37 DeleteDeclaration f; |
38 | |
39 f = new DeleteDeclaration(loc, endloc, null); | |
40 | |
41 FuncDeclaration.syntaxCopy(f); | |
42 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
43 f.arguments = Parameter.arraySyntaxCopy(arguments); |
123 | 44 |
45 return f; | |
0 | 46 } |
47 | |
72 | 48 override void semantic(Scope sc) |
0 | 49 { |
123 | 50 //printf("DeleteDeclaration.semantic()\n"); |
51 | |
52 parent = sc.parent; | |
53 Dsymbol parent = toParent(); | |
179 | 54 ClassDeclaration cd = parent.isClassDeclaration(); |
123 | 55 if (!cd && !parent.isStructDeclaration()) |
56 { | |
57 error("new allocators only are for class or struct definitions"); | |
58 } | |
179 | 59 if (!type) |
60 type = new TypeFunction(arguments, Type.tvoid, 0, LINKd); | |
123 | 61 |
62 type = type.semantic(loc, sc); | |
63 assert(type.ty == Tfunction); | |
64 | |
65 // Check that there is only one argument of type void* | |
66 TypeFunction tf = cast(TypeFunction)type; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
67 if (Parameter.dim(tf.parameters) != 1) |
123 | 68 { |
69 error("one argument of type void* expected"); | |
70 } | |
71 else | |
72 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
73 auto a = Parameter.getNth(tf.parameters, 0); |
123 | 74 if (!a.type.equals(Type.tvoid.pointerTo())) |
75 error("one argument of type void* expected, not %s", a.type.toChars()); | |
76 } | |
77 | |
78 FuncDeclaration.semantic(sc); | |
0 | 79 } |
80 | |
72 | 81 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 82 { |
123 | 83 buf.writestring("delete"); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
84 Parameter.argsToCBuffer(buf, hgs, arguments, 0); |
123 | 85 bodyToCBuffer(buf, hgs); |
0 | 86 } |
87 | |
72 | 88 override string kind() |
0 | 89 { |
123 | 90 return "deallocator"; |
0 | 91 } |
92 | |
72 | 93 override bool isDelete() |
0 | 94 { |
123 | 95 return true; |
0 | 96 } |
97 | |
72 | 98 override bool isVirtual() |
0 | 99 { |
123 | 100 return false; |
0 | 101 } |
102 | |
72 | 103 override bool addPreInvariant() |
0 | 104 { |
123 | 105 return false; |
0 | 106 } |
107 | |
72 | 108 override bool addPostInvariant() |
0 | 109 { |
123 | 110 return false; |
0 | 111 } |
112 | |
113 version (_DH) { | |
114 DeleteDeclaration isDeleteDeclaration() { return this; } | |
115 } | |
72 | 116 } |