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