annotate dmd/TypePointer.d @ 192:eb38fdcb3e62 default tip

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