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;
|
123
|
8 import dmd.Argument;
|
|
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 {
|
|
22 Arguments arguments;
|
|
23 int varargs;
|
|
24
|
|
25 this(Loc loc, Loc endloc, Arguments arguments, int varargs)
|
|
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
|
|
40 f.arguments = Argument.arraySyntaxCopy(arguments);
|
|
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;
|
|
67 if (Argument.dim(tf.parameters) < 1)
|
|
68 {
|
|
69 error("at least one argument of type size_t expected");
|
|
70 }
|
|
71 else
|
|
72 {
|
|
73 Argument a = Argument.getNth(tf.parameters, 0);
|
|
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");
|
|
84 Argument.argsToCBuffer(buf, hgs, arguments, varargs);
|
|
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 }
|