annotate dmd/TypePointer.d @ 135:af1bebfd96a4 dmd2037

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