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