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