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