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