annotate dmd/TypePointer.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 af1bebfd96a4
children b0d41ff5e0df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TypeNext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TypeInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TypeInfoPointerDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.CppMangleState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 class TypePointer : TypeNext
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 this(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 135
diff changeset
29 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 super(TY.Tpointer, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
33 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 Type t = next.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 if (t == next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 t = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 t = new TypePointer(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 t.mod = mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
46 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 //printf("TypePointer.semantic()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 if (deco)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 Type n = next.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 switch (n.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 case TY.Ttuple:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 error(loc, "can't have pointer to %s", n.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 n = tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 if (n !is next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 deco = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 next = n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 transitive();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
70 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 return PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
75 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 //printf("TypePointer::toCBuffer2() next = %d\n", next->ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 if (mod != this.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 toCBuffer3(buf, hgs, mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 next.toCBuffer2(buf, hgs, this.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 if (next.ty != Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 buf.writeByte('*');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
88 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 //printf("TypePointer.implicitConvTo(to = %s) %s\n", to.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 if (equals(to))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 return MATCH.MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 if (to.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 TypePointer tp = cast(TypePointer)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 assert(tp.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
99 if (!MODimplicitConv(next.mod, tp.next.mod))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 return MATCH.MATCHnomatch; // not const-compatible
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 /* Alloc conversion to void[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (next.ty != TY.Tvoid && tp.next.ty == TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 return MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 MATCH m = next.constConv(tp.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 if (m != MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (m == MATCH.MATCHexact && mod != to.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 m = MATCH.MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 /* Conversion of ptr to derived to ptr to base
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (tp.next.isBaseOf(next, &offset) && offset == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 return MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 return MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
126 override bool isscalar()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
131 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 printf("TypePointer::defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
136 return new NullExp(loc, this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
139 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
144 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 return new TypeInfoPointerDeclaration(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
149 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
161 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 type* tn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 //printf("TypePointer.toCtype() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 if (ctype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 return ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (1 || global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 { /* Need to always do this, otherwise C++ name mangling
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 * goes awry.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 t = type_alloc(TYM.TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 ctype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 tn = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 t.Tnext = tn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 tn.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 t = type_fake(totym());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 ctype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
187 }