Mercurial > projects > ddmd
annotate dmd/NewDeclaration.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.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 |
20 class NewDeclaration : 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 int varargs; |
24 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
25 this(Loc loc, Loc endloc, Parameters arguments, int varargs) |
0 | 26 { |
178 | 27 register(); |
123 | 28 super(loc, endloc, Id.classNew, STCstatic, null); |
29 this.arguments = arguments; | |
30 this.varargs = varargs; | |
0 | 31 } |
32 | |
72 | 33 override Dsymbol syntaxCopy(Dsymbol) |
0 | 34 { |
123 | 35 NewDeclaration f; |
36 | |
37 f = new NewDeclaration(loc, endloc, null, varargs); | |
38 | |
39 FuncDeclaration.syntaxCopy(f); | |
40 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
41 f.arguments = Parameter.arraySyntaxCopy(arguments); |
123 | 42 |
43 return f; | |
0 | 44 } |
45 | |
72 | 46 override void semantic(Scope sc) |
0 | 47 { |
123 | 48 //printf("NewDeclaration.semantic()\n"); |
49 | |
50 parent = sc.parent; | |
51 Dsymbol parent = toParent(); | |
179 | 52 ClassDeclaration cd = parent.isClassDeclaration(); |
123 | 53 if (!cd && !parent.isStructDeclaration()) |
54 { | |
55 error("new allocators only are for class or struct definitions"); | |
56 } | |
179 | 57 Type tret = Type.tvoid.pointerTo(); |
58 if (!type) | |
59 type = new TypeFunction(arguments, tret, varargs, LINKd); | |
123 | 60 |
61 type = type.semantic(loc, sc); | |
62 assert(type.ty == Tfunction); | |
63 | |
64 // Check that there is at least one argument of type size_t | |
65 TypeFunction tf = cast(TypeFunction)type; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
66 if (Parameter.dim(tf.parameters) < 1) |
123 | 67 { |
68 error("at least one argument of type size_t expected"); | |
69 } | |
70 else | |
71 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
72 auto a = Parameter.getNth(tf.parameters, 0); |
123 | 73 if (!a.type.equals(Type.tsize_t)) |
74 error("first argument must be type size_t, not %s", a.type.toChars()); | |
75 } | |
76 | |
77 FuncDeclaration.semantic(sc); | |
0 | 78 } |
79 | |
72 | 80 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 81 { |
123 | 82 buf.writestring("new"); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
83 Parameter.argsToCBuffer(buf, hgs, arguments, varargs); |
123 | 84 bodyToCBuffer(buf, hgs); |
0 | 85 } |
86 | |
72 | 87 override string kind() |
0 | 88 { |
123 | 89 return "allocator"; |
0 | 90 } |
91 | |
72 | 92 override bool isVirtual() |
0 | 93 { |
123 | 94 return false; |
0 | 95 } |
96 | |
72 | 97 override bool addPreInvariant() |
0 | 98 { |
123 | 99 return false; |
0 | 100 } |
101 | |
72 | 102 override bool addPostInvariant() |
0 | 103 { |
123 | 104 return false; |
0 | 105 } |
106 | |
72 | 107 override NewDeclaration isNewDeclaration() { return this; } |
108 } |