Mercurial > projects > ddmd
annotate dmd/NewDeclaration.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | 60bb0fe4563e |
children | cd48cb899aee |
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 ClassDeclaration cd; |
49 Type tret; | |
50 | |
51 //printf("NewDeclaration.semantic()\n"); | |
52 | |
53 parent = sc.parent; | |
54 Dsymbol parent = toParent(); | |
55 cd = parent.isClassDeclaration(); | |
56 if (!cd && !parent.isStructDeclaration()) | |
57 { | |
58 error("new allocators only are for class or struct definitions"); | |
59 } | |
60 tret = Type.tvoid.pointerTo(); | |
61 type = new TypeFunction(arguments, tret, varargs, LINKd); | |
62 | |
63 type = type.semantic(loc, sc); | |
64 assert(type.ty == Tfunction); | |
65 | |
66 // Check that there is at least one argument of type size_t | |
67 TypeFunction tf = cast(TypeFunction)type; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
68 if (Parameter.dim(tf.parameters) < 1) |
123 | 69 { |
70 error("at least one argument of type size_t expected"); | |
71 } | |
72 else | |
73 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
74 auto a = Parameter.getNth(tf.parameters, 0); |
123 | 75 if (!a.type.equals(Type.tsize_t)) |
76 error("first argument must be type size_t, not %s", a.type.toChars()); | |
77 } | |
78 | |
79 FuncDeclaration.semantic(sc); | |
0 | 80 } |
81 | |
72 | 82 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 83 { |
123 | 84 buf.writestring("new"); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
85 Parameter.argsToCBuffer(buf, hgs, arguments, varargs); |
123 | 86 bodyToCBuffer(buf, hgs); |
0 | 87 } |
88 | |
72 | 89 override string kind() |
0 | 90 { |
123 | 91 return "allocator"; |
0 | 92 } |
93 | |
72 | 94 override bool isVirtual() |
0 | 95 { |
123 | 96 return false; |
0 | 97 } |
98 | |
72 | 99 override bool addPreInvariant() |
0 | 100 { |
123 | 101 return false; |
0 | 102 } |
103 | |
72 | 104 override bool addPostInvariant() |
0 | 105 { |
123 | 106 return false; |
0 | 107 } |
108 | |
72 | 109 override NewDeclaration isNewDeclaration() { return this; } |
110 } |