Mercurial > projects > ddmd
annotate dmd/Type.d @ 20:1628b221808d
Fleshed out more unimplemented methods.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Wed, 07 Apr 2010 00:29:13 +0100 |
parents | 5c9b78899f5d |
children | fd4acc376c45 |
rev | line source |
---|---|
0 | 1 module dmd.Type; |
2 | |
3 import dmd.TY; | |
4 import dmd.Argument; | |
5 import dmd.TOK; | |
6 import dmd.STC; | |
7 import dmd.TypeArray; | |
8 import dmd.DotVarExp; | |
9 import dmd.ErrorExp; | |
10 import dmd.StringExp; | |
11 import dmd.IntegerExp; | |
12 import dmd.VarExp; | |
13 import dmd.TemplateParameter; | |
14 import dmd.TypeInfoSharedDeclaration; | |
15 import dmd.TypeInfoConstDeclaration; | |
16 import dmd.TypeInfoInvariantDeclaration; | |
17 import dmd.Module; | |
18 import dmd.Id; | |
19 import dmd.Util; | |
20 import dmd.VarDeclaration; | |
21 import dmd.Loc; | |
22 import dmd.Scope; | |
23 import dmd.OutBuffer; | |
24 import dmd.Identifier; | |
25 import dmd.HdrGenState; | |
26 import dmd.Expression; | |
27 import dmd.Dsymbol; | |
28 import dmd.MATCH; | |
29 import dmd.TypeInfoDeclaration; | |
30 import dmd.ClassDeclaration; | |
31 import dmd.StringTable; | |
32 import dmd.ArrayTypes; | |
33 import dmd.TypeBasic; | |
34 import dmd.DYNCAST; | |
35 import dmd.MOD; | |
36 import dmd.Lexer; | |
37 import dmd.TypeSArray; | |
38 import dmd.TypeDArray; | |
39 import dmd.TypeAArray; | |
40 import dmd.TypePointer; | |
41 import dmd.TypeReference; | |
42 import dmd.TypeFunction; | |
43 import dmd.TypeDelegate; | |
44 import dmd.TypeIdentifier; | |
45 import dmd.TypeInstance; | |
46 import dmd.TypeTypeof; | |
47 import dmd.TypeReturn; | |
48 import dmd.TypeStruct; | |
49 import dmd.TypeEnum; | |
50 import dmd.TypeTypedef; | |
51 import dmd.TypeClass; | |
52 import dmd.TypeTuple; | |
53 import dmd.TypeSlice; | |
54 import dmd.Global; | |
55 import dmd.StringValue; | |
56 | |
57 import dmd.backend.Symbol; | |
58 import dmd.backend.TYPE; | |
59 import dmd.backend.dt_t; | |
60 import dmd.backend.Util; | |
61 import dmd.backend.TYM; | |
62 import dmd.backend.mTY; | |
63 | |
64 import core.stdc.stdio; | |
65 | |
4 | 66 import core.memory; |
2 | 67 |
0 | 68 /* These have default values for 32 bit code, they get |
69 * adjusted for 64 bit code. | |
70 */ | |
71 | |
72 int PTRSIZE = 4; | |
73 | |
74 int Tsize_t; | |
75 int Tptrdiff_t; | |
76 | |
77 /* REALSIZE = size a real consumes in memory | |
78 * REALPAD = 'padding' added to the CPU real size to bring it up to REALSIZE | |
79 * REALALIGNSIZE = alignment for reals | |
80 */ | |
81 version (TARGET_OSX) { | |
82 int REALSIZE = 16; | |
83 int REALPAD = 6; | |
84 int REALALIGNSIZE = 16; | |
85 } else version (XXX) { /// TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS | |
86 int REALSIZE = 12; | |
87 int REALPAD = 2; | |
88 int REALALIGNSIZE = 4; | |
89 } else { | |
90 int REALSIZE = 10; | |
91 int REALPAD = 0; | |
92 int REALALIGNSIZE = 2; | |
93 } | |
94 | |
95 /**** | |
96 * Given an identifier, figure out which TemplateParameter it is. | |
97 * Return -1 if not found. | |
98 */ | |
99 | |
100 int templateIdentifierLookup(Identifier id, TemplateParameters parameters) | |
101 { | |
102 for (size_t i = 0; i < parameters.dim; i++) | |
103 { | |
104 TemplateParameter tp = cast(TemplateParameter)parameters.data[i]; | |
105 | |
106 if (tp.ident.equals(id)) | |
107 return i; | |
108 } | |
109 return -1; | |
110 } | |
111 | |
112 int templateParameterLookup(Type tparam, TemplateParameters parameters) | |
113 { | |
114 assert(tparam.ty == Tident); | |
115 TypeIdentifier tident = cast(TypeIdentifier)tparam; | |
116 //printf("\ttident = '%s'\n", tident.toChars()); | |
117 if (tident.idents.dim == 0) | |
118 { | |
119 return templateIdentifierLookup(tident.ident, parameters); | |
120 } | |
121 return -1; | |
122 } | |
123 | |
124 class Type | |
125 { | |
126 TY ty; | |
127 MOD mod; // modifiers MODxxxx | |
128 /* pick this order of numbers so switch statements work better | |
129 */ | |
130 /// #define MODconst 1 // type is const | |
131 /// #define MODinvariant 4 // type is invariant | |
132 /// #define MODshared 2 // type is shared | |
133 string deco; | |
134 | |
135 /* These are cached values that are lazily evaluated by constOf(), invariantOf(), etc. | |
136 * They should not be referenced by anybody but mtype.c. | |
137 * They can be null if not lazily evaluated yet. | |
138 * Note that there is no "shared immutable", because that is just immutable | |
139 */ | |
140 | |
141 Type cto; // MODconst ? mutable version of this type : const version | |
142 Type ito; // MODinvariant ? mutable version of this type : invariant version | |
143 Type sto; // MODshared ? mutable version of this type : shared mutable version | |
144 Type scto; // MODshared|MODconst ? mutable version of this type : shared const version | |
145 | |
146 Type pto; // merged pointer to this type | |
147 Type rto; // reference to this type | |
148 Type arrayof; // array of this type | |
149 TypeInfoDeclaration vtinfo; // TypeInfo object for this Type | |
150 | |
151 type* ctype; // for back end | |
152 | |
153 static ClassDeclaration typeinfo; | |
154 static ClassDeclaration typeinfoclass; | |
155 static ClassDeclaration typeinfointerface; | |
156 static ClassDeclaration typeinfostruct; | |
157 static ClassDeclaration typeinfotypedef; | |
158 static ClassDeclaration typeinfopointer; | |
159 static ClassDeclaration typeinfoarray; | |
160 static ClassDeclaration typeinfostaticarray; | |
161 static ClassDeclaration typeinfoassociativearray; | |
162 static ClassDeclaration typeinfoenum; | |
163 static ClassDeclaration typeinfofunction; | |
164 static ClassDeclaration typeinfodelegate; | |
165 static ClassDeclaration typeinfotypelist; | |
166 static ClassDeclaration typeinfoconst; | |
167 static ClassDeclaration typeinfoinvariant; | |
168 static ClassDeclaration typeinfoshared; | |
169 | |
170 static Type basic[TY.TMAX]; | |
171 static ubyte mangleChar[TY.TMAX]; | |
172 static ubyte sizeTy[TY.TMAX]; | |
173 static StringTable stringtable; | |
174 | |
175 // These tables are for implicit conversion of binary ops; | |
176 // the indices are the type of operand one, followed by operand two. | |
177 static ubyte impcnvResult[TY.TMAX][TY.TMAX] = [ | |
178 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
179 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
180 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
181 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
182 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
183 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
184 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
185 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
186 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
187 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
188 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
189 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
190 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
191 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
192 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
193 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
194 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
195 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
196 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
197 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
198 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,20,20,20,20,20,20,21,22,23,24,25,23,24,25,29,30,31,37,20,37,37,37,37,37,37,37,37,37], | |
199 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,21,21,21,21,21,21,21,22,23,24,25,23,24,25,29,30,31,37,21,37,37,37,37,37,37,37,37,37], | |
200 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,22,22,22,22,22,22,22,22,23,24,25,23,24,25,29,30,31,37,22,37,37,37,37,37,37,37,37,37], | |
201 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,23,24,25,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
202 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,24,24,25,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
203 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,25,25,25,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
204 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,26,27,28,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
205 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,27,27,28,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
206 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,28,28,28,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
207 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,29,29,29,29,29,29,29,29,29,30,31,29,30,31,29,30,31,37,29,37,37,37,37,37,37,37,37,37], | |
208 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,30,30,30,30,30,30,30,30,30,30,31,30,30,31,30,30,31,37,30,37,37,37,37,37,37,37,37,37], | |
209 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,37,31,37,37,37,37,37,37,37,37,37], | |
210 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
211 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,33,37,37,37,37,37,37,37,37,37], | |
212 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
213 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
214 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
215 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
216 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
217 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
218 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
219 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
220 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
221 ]; | |
222 | |
223 static ubyte impcnvType1[TY.TMAX][TY.TMAX] = [ | |
224 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
225 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
226 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
227 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
228 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
229 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
230 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
231 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
232 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
233 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
234 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
235 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
236 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
237 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
238 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
239 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
240 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
241 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
242 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
243 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
244 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,20,20,20,20,20,20,21,22,23,24,25,23,24,25,23,24,25,37,20,37,37,37,37,37,37,37,37,37], | |
245 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,21,21,21,21,21,21,21,22,23,24,25,23,24,25,23,24,25,37,21,37,37,37,37,37,37,37,37,37], | |
246 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,22,22,22,22,22,22,22,22,23,24,25,23,24,25,23,24,25,37,22,37,37,37,37,37,37,37,37,37], | |
247 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,23,24,25,23,24,25,37,23,37,37,37,37,37,37,37,37,37], | |
248 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,24,24,25,24,24,25,37,24,37,37,37,37,37,37,37,37,37], | |
249 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,37,25,37,37,37,37,37,37,37,37,37], | |
250 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,26,26,26,26,26,26,26,26,26,27,28,26,27,28,26,27,28,37,26,37,37,37,37,37,37,37,37,37], | |
251 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,27,27,27,27,27,27,27,27,27,27,28,27,27,28,27,27,28,37,27,37,37,37,37,37,37,37,37,37], | |
252 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,37,28,37,37,37,37,37,37,37,37,37], | |
253 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,29,29,29,29,29,29,29,29,29,30,31,29,30,31,29,30,31,37,29,37,37,37,37,37,37,37,37,37], | |
254 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,30,30,30,30,30,30,30,30,30,30,31,30,30,31,30,30,31,37,30,37,37,37,37,37,37,37,37,37], | |
255 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,37,31,37,37,37,37,37,37,37,37,37], | |
256 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
257 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,33,37,37,37,37,37,37,37,37,37], | |
258 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
259 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
260 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
261 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
262 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
263 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
264 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
265 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
266 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
267 ]; | |
268 | |
269 static ubyte impcnvType2[TY.TMAX][TY.TMAX] = [ | |
270 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
271 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
272 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
273 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
274 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
275 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
276 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
277 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
278 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
279 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
280 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
281 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
282 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
283 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
284 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
285 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
286 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
287 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
288 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
289 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
290 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,20,20,20,20,20,20,21,22,23,24,25,26,27,28,29,30,31,37,20,37,37,37,37,37,37,37,37,37], | |
291 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,21,21,21,21,21,21,21,22,23,24,25,26,27,28,29,30,31,37,21,37,37,37,37,37,37,37,37,37], | |
292 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,22,22,22,22,22,22,22,22,23,24,25,26,27,28,29,30,31,37,22,37,37,37,37,37,37,37,37,37], | |
293 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,26,27,28,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
294 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,27,27,28,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
295 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,28,28,28,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
296 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,26,27,28,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
297 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,27,27,28,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
298 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,28,28,28,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
299 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,26,27,28,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
300 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,27,27,28,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
301 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,28,28,28,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
302 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
303 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,33,37,37,37,37,37,37,37,37,37], | |
304 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
305 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
306 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
307 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
308 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
309 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
310 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
311 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
312 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
313 ]; | |
314 | |
315 // If !=0, give warning on implicit conversion | |
316 static const(bool) impcnvWarn[TY.TMAX][TY.TMAX] = [ | |
317 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
318 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
319 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
320 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
321 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
322 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
323 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
324 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
325 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
326 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
327 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
328 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
329 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
330 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
331 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
332 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0], | |
333 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
334 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], | |
335 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0], | |
336 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], | |
337 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], | |
338 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0], | |
339 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0], | |
340 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
341 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
342 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
343 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
344 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
345 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
346 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
347 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
348 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
349 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
350 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
351 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
352 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
353 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
354 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
355 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
356 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
357 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
358 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
359 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
360 ]; | |
361 | |
362 static this() | |
363 { | |
364 stringtable = new StringTable(); | |
365 } | |
366 | |
367 static ~this() | |
368 { | |
369 delete stringtable; | |
370 } | |
371 | |
372 this(TY ty) | |
373 { | |
374 this.ty = ty; | |
375 } | |
376 | |
377 Type syntaxCopy() | |
378 { | |
379 assert(false); | |
380 } | |
381 | |
382 int equals(Object o) | |
383 { | |
384 Type t = cast(Type)o; | |
385 //printf("Type.equals(%s, %s)\n", toChars(), t.toChars()); | |
386 if (this is o || (t && deco == t.deco) && // deco strings are unique | |
387 deco !is null) // and semantic() has been run | |
388 { | |
389 //printf("deco = '%s', t.deco = '%s'\n", deco, t.deco); | |
390 return 1; | |
391 } | |
392 //if (deco && t && t.deco) printf("deco = '%s', t.deco = '%s'\n", deco, t.deco); | |
393 return 0; | |
394 } | |
395 | |
396 DYNCAST dyncast() { return DYNCAST.DYNCAST_TYPE; } // kludge for template.isType() | |
397 | |
398 /******************************* | |
399 * Returns: | |
400 * 0 types are distinct | |
401 * 1 this is covariant with t | |
402 * 2 arguments match as far as overloading goes, | |
403 * but types are not covariant | |
404 * 3 cannot determine covariance because of forward references | |
405 */ | |
406 int covariant(Type t) | |
407 { | |
408 static if (false) { | |
409 printf("Type.covariant(t = %s) %s\n", t.toChars(), toChars()); | |
410 printf("deco = %p, %p\n", deco, t.deco); | |
411 // printf("ty = %d\n", next.ty); | |
412 printf("mod = %x, %x\n", mod, t.mod); | |
413 } | |
414 | |
415 int inoutmismatch = 0; | |
416 | |
417 TypeFunction t1; | |
418 TypeFunction t2; | |
419 | |
420 if (equals(t)) | |
421 return 1; // covariant | |
422 | |
423 if (ty != TY.Tfunction || t.ty != TY.Tfunction) | |
424 goto Ldistinct; | |
425 | |
426 t1 = cast(TypeFunction)this; | |
427 t2 = cast(TypeFunction)t; | |
428 | |
429 if (t1.varargs != t2.varargs) | |
430 goto Ldistinct; | |
431 | |
432 if (t1.parameters && t2.parameters) | |
433 { | |
434 size_t dim = Argument.dim(t1.parameters); | |
435 if (dim != Argument.dim(t2.parameters)) | |
436 goto Ldistinct; | |
437 | |
438 for (size_t i = 0; i < dim; i++) | |
439 { | |
440 Argument arg1 = Argument.getNth(t1.parameters, i); | |
441 Argument arg2 = Argument.getNth(t2.parameters, i); | |
442 | |
443 if (!arg1.type.equals(arg2.type)) | |
444 { | |
445 ///static if (false) { | |
446 /// // turn on this for contravariant argument types, see bugzilla 3075 | |
447 /// // We can add const, but not subtract it | |
448 /// if (arg2.type.implicitConvTo(arg1.type) < MATCH.MATCHconst) | |
449 ///} | |
450 goto Ldistinct; | |
451 } | |
452 if ((arg1.storageClass & ~STC.STCscope) != (arg2.storageClass & ~STC.STCscope)) | |
453 inoutmismatch = 1; | |
454 // We can add scope, but not subtract it | |
455 if (!(arg1.storageClass & STC.STCscope) && (arg2.storageClass & STC.STCscope)) | |
456 inoutmismatch = 1; | |
457 } | |
458 } | |
459 else if (t1.parameters != t2.parameters) | |
460 goto Ldistinct; | |
461 | |
462 // The argument lists match | |
463 if (inoutmismatch) | |
464 goto Lnotcovariant; | |
465 if (t1.linkage != t2.linkage) | |
466 goto Lnotcovariant; | |
467 | |
468 { | |
469 // Return types | |
470 Type t1n = t1.next; | |
471 Type t2n = t2.next; | |
472 | |
473 if (t1n.equals(t2n)) | |
474 goto Lcovariant; | |
475 if (t1n.ty == TY.Tclass && t2n.ty == TY.Tclass) | |
476 { | |
477 /* If same class type, but t2n is const, then it's | |
478 * covariant. Do this test first because it can work on | |
479 * forward references. | |
480 */ | |
481 if ((cast(TypeClass)t1n).sym == (cast(TypeClass)t2n).sym && | |
482 t2n.mod == MOD.MODconst) | |
483 goto Lcovariant; | |
484 | |
485 // If t1n is forward referenced: | |
486 ClassDeclaration cd = (cast(TypeClass)t1n).sym; | |
487 if (!cd.baseClass && cd.baseclasses.dim && !cd.isInterfaceDeclaration()) | |
488 { | |
489 return 3; | |
490 } | |
491 } | |
492 if (t1n.implicitConvTo(t2n)) | |
493 goto Lcovariant; | |
494 } | |
495 | |
496 goto Lnotcovariant; | |
497 | |
498 Lcovariant: | |
499 /* Can convert mutable to const | |
500 */ | |
501 if (t1.mod != t2.mod) | |
502 { | |
503 if (!(t1.mod & MOD.MODconst) && (t2.mod & MOD.MODconst)) | |
504 goto Lnotcovariant; | |
505 if (!(t1.mod & MOD.MODshared) && (t2.mod & MOD.MODshared)) | |
506 goto Lnotcovariant; | |
507 } | |
508 | |
509 /* Can convert pure to impure, and nothrow to throw | |
510 */ | |
511 if (!t1.ispure && t2.ispure) | |
512 goto Lnotcovariant; | |
513 | |
514 if (!t1.isnothrow && t2.isnothrow) | |
515 goto Lnotcovariant; | |
516 | |
517 if (t1.isref != t2.isref) | |
518 goto Lnotcovariant; | |
519 | |
520 //printf("\tcovaraint: 1\n"); | |
521 return 1; | |
522 | |
523 Ldistinct: | |
524 //printf("\tcovaraint: 0\n"); | |
525 return 0; | |
526 | |
527 Lnotcovariant: | |
528 //printf("\tcovaraint: 2\n"); | |
529 return 2; | |
530 } | |
531 | |
532 string toChars() | |
533 { | |
534 scope OutBuffer buf = new OutBuffer(); | |
535 | |
536 HdrGenState hgs; | |
537 toCBuffer(buf, null, &hgs); | |
538 return buf.toChars(); | |
539 } | |
540 | |
541 static char needThisPrefix() | |
542 { | |
543 return 'M'; // name mangling prefix for functions needing 'this' | |
544 } | |
545 | |
546 static void init() | |
547 { | |
548 Lexer.initKeywords(); | |
549 | |
550 for (int i = 0; i < TY.TMAX; i++) | |
551 sizeTy[i] = TypeBasic.sizeof; | |
552 | |
553 sizeTy[TY.Tsarray] = TypeSArray.sizeof; | |
554 sizeTy[TY.Tarray] = TypeDArray.sizeof; | |
555 //sizeTy[TY.Tnarray] = TypeNArray.sizeof; | |
556 sizeTy[TY.Taarray] = TypeAArray.sizeof; | |
557 sizeTy[TY.Tpointer] = TypePointer.sizeof; | |
558 sizeTy[TY.Treference] = TypeReference.sizeof; | |
559 sizeTy[TY.Tfunction] = TypeFunction.sizeof; | |
560 sizeTy[TY.Tdelegate] = TypeDelegate.sizeof; | |
561 sizeTy[TY.Tident] = TypeIdentifier.sizeof; | |
562 sizeTy[TY.Tinstance] = TypeInstance.sizeof; | |
563 sizeTy[TY.Ttypeof] = TypeTypeof.sizeof; | |
564 sizeTy[TY.Tenum] = TypeEnum.sizeof; | |
565 sizeTy[TY.Ttypedef] = TypeTypedef.sizeof; | |
566 sizeTy[TY.Tstruct] = TypeStruct.sizeof; | |
567 sizeTy[TY.Tclass] = TypeClass.sizeof; | |
568 sizeTy[TY.Ttuple] = TypeTuple.sizeof; | |
569 sizeTy[TY.Tslice] = TypeSlice.sizeof; | |
570 sizeTy[TY.Treturn] = TypeReturn.sizeof; | |
571 | |
572 mangleChar[TY.Tarray] = 'A'; | |
573 mangleChar[TY.Tsarray] = 'G'; | |
574 mangleChar[TY.Tnarray] = '@'; | |
575 mangleChar[TY.Taarray] = 'H'; | |
576 mangleChar[TY.Tpointer] = 'P'; | |
577 mangleChar[TY.Treference] = 'R'; | |
578 mangleChar[TY.Tfunction] = 'F'; | |
579 mangleChar[TY.Tident] = 'I'; | |
580 mangleChar[TY.Tclass] = 'C'; | |
581 mangleChar[TY.Tstruct] = 'S'; | |
582 mangleChar[TY.Tenum] = 'E'; | |
583 mangleChar[TY.Ttypedef] = 'T'; | |
584 mangleChar[TY.Tdelegate] = 'D'; | |
585 | |
586 mangleChar[TY.Tnone] = 'n'; | |
587 mangleChar[TY.Tvoid] = 'v'; | |
588 mangleChar[TY.Tint8] = 'g'; | |
589 mangleChar[TY.Tuns8] = 'h'; | |
590 mangleChar[TY.Tint16] = 's'; | |
591 mangleChar[TY.Tuns16] = 't'; | |
592 mangleChar[TY.Tint32] = 'i'; | |
593 mangleChar[TY.Tuns32] = 'k'; | |
594 mangleChar[TY.Tint64] = 'l'; | |
595 mangleChar[TY.Tuns64] = 'm'; | |
596 mangleChar[TY.Tfloat32] = 'f'; | |
597 mangleChar[TY.Tfloat64] = 'd'; | |
598 mangleChar[TY.Tfloat80] = 'e'; | |
599 | |
600 mangleChar[TY.Timaginary32] = 'o'; | |
601 mangleChar[TY.Timaginary64] = 'p'; | |
602 mangleChar[TY.Timaginary80] = 'j'; | |
603 mangleChar[TY.Tcomplex32] = 'q'; | |
604 mangleChar[TY.Tcomplex64] = 'r'; | |
605 mangleChar[TY.Tcomplex80] = 'c'; | |
606 | |
607 mangleChar[TY.Tbool] = 'b'; | |
608 mangleChar[TY.Tascii] = 'a'; | |
609 mangleChar[TY.Twchar] = 'u'; | |
610 mangleChar[TY.Tdchar] = 'w'; | |
611 | |
612 mangleChar[TY.Tbit] = '@'; | |
613 mangleChar[TY.Tinstance] = '@'; | |
614 mangleChar[TY.Terror] = '@'; | |
615 mangleChar[TY.Ttypeof] = '@'; | |
616 mangleChar[TY.Ttuple] = 'B'; | |
617 mangleChar[TY.Tslice] = '@'; | |
618 mangleChar[TY.Treturn] = '@'; | |
619 | |
620 debug { | |
621 for (int i = 0; i < TY.TMAX; i++) { | |
622 if (!mangleChar[i]) { | |
623 writef("ty = %d\n", i); | |
624 } | |
625 assert(mangleChar[i]); | |
626 } | |
627 } | |
628 // Set basic types | |
629 static TY[] basetab = [ | |
630 TY.Tvoid, TY.Tint8, TY.Tuns8, TY.Tint16, TY.Tuns16, TY.Tint32, TY.Tuns32, TY.Tint64, TY.Tuns64, | |
631 TY.Tfloat32, TY.Tfloat64, TY.Tfloat80, | |
632 TY.Timaginary32, TY.Timaginary64, TY.Timaginary80, | |
633 TY.Tcomplex32, TY.Tcomplex64, TY.Tcomplex80, | |
634 TY.Tbool, | |
635 TY.Tascii, TY.Twchar, TY.Tdchar | |
636 ]; | |
637 | |
638 foreach (bt; basetab) { | |
639 Type t = new TypeBasic(bt); | |
640 t = t.merge(); | |
641 basic[bt] = t; | |
642 } | |
643 | |
644 basic[TY.Terror] = basic[TY.Tint32]; | |
645 | |
646 tvoidptr = tvoid.pointerTo(); | |
647 | |
648 if (global.params.isX86_64) { | |
649 PTRSIZE = 8; | |
650 if (global.params.isLinux || global.params.isFreeBSD || global.params.isSolaris) | |
651 REALSIZE = 10; | |
652 else | |
653 REALSIZE = 8; | |
654 Tsize_t = TY.Tuns64; | |
655 Tptrdiff_t = TY.Tint64; | |
656 } | |
657 else | |
658 { | |
659 PTRSIZE = 4; | |
660 version (TARGET_OSX) { | |
661 REALSIZE = 16; | |
662 REALPAD = 6; | |
663 } else version (XXX) { //#elif TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS | |
664 REALSIZE = 12; | |
665 REALPAD = 2; | |
666 } else { | |
667 REALSIZE = 10; | |
668 REALPAD = 0; | |
669 } | |
670 Tsize_t = TY.Tuns32; | |
671 Tptrdiff_t = TY.Tint32; | |
672 } | |
673 } | |
674 | |
675 ulong size() | |
676 { | |
677 return size(Loc(0)); | |
678 } | |
679 | |
680 ulong size(Loc loc) | |
681 { | |
682 error(loc, "no size for type %s", toChars()); | |
683 return 1; | |
684 } | |
685 | |
686 uint alignsize() | |
687 { | |
688 return cast(uint)size(Loc(0)); /// | |
689 } | |
690 | |
691 Type semantic(Loc loc, Scope sc) | |
692 { | |
693 return merge(); | |
694 } | |
695 | |
696 Type trySemantic(Loc loc, Scope sc) | |
697 { | |
698 uint errors = global.errors; | |
699 global.gag++; // suppress printing of error messages | |
700 Type t = semantic(loc, sc); | |
701 global.gag--; | |
702 if (errors != global.errors) // if any errors happened | |
703 { | |
704 global.errors = errors; | |
705 t = null; | |
706 } | |
707 return t; | |
708 } | |
709 | |
710 /******************************** | |
711 * Name mangling. | |
712 * Input: | |
713 * flag 0x100 do not do const/invariant | |
714 */ | |
715 void toDecoBuffer(OutBuffer buf, int flag = 0) | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
16
diff
changeset
|
716 { |
0 | 717 if (flag != mod && flag != 0x100) |
718 { | |
719 if (mod & MOD.MODshared) | |
720 buf.writeByte('O'); | |
721 | |
722 if (mod & MOD.MODconst) | |
723 buf.writeByte('x'); | |
724 else if (mod & MOD.MODinvariant) | |
725 buf.writeByte('y'); | |
726 | |
727 // Cannot be both const and invariant | |
728 assert((mod & (MOD.MODconst | MOD.MODinvariant)) != (MOD.MODconst | MOD.MODinvariant)); | |
729 } | |
730 buf.writeByte(mangleChar[ty]); | |
731 } | |
732 | |
733 Type merge() | |
734 { | |
735 Type t = this; | |
736 assert(t); | |
737 | |
738 //printf("merge(%s)\n", toChars()); | |
739 if (deco is null) | |
740 { | |
741 OutBuffer buf = new OutBuffer(); | |
742 | |
743 //if (next) | |
744 //next = next.merge(); | |
745 toDecoBuffer(buf); | |
746 StringValue* sv = stringtable.update(buf.extractString()); | |
747 if (sv.ptrvalue) | |
748 { | |
749 t = cast(Type) sv.ptrvalue; | |
750 debug { | |
751 if (!t.deco) | |
752 writef("t = %s\n", t.toChars()); | |
753 } | |
754 assert(t.deco); | |
755 //printf("old value, deco = '%s' %p\n", t.deco, t.deco); | |
756 } | |
757 else | |
758 { | |
759 sv.ptrvalue = cast(void*)this; | |
760 deco = sv.lstring.string_; | |
761 //printf("new value, deco = '%s' %p\n", t.deco, t.deco); | |
762 } | |
763 } | |
764 return t; | |
765 } | |
766 | |
767 /************************************* | |
768 * This version does a merge even if the deco is already computed. | |
769 * Necessary for types that have a deco, but are not merged. | |
770 */ | |
771 Type merge2() | |
772 { | |
773 //printf("merge2(%s)\n", toChars()); | |
774 Type t = this; | |
775 assert(t); | |
776 if (!t.deco) | |
777 return t.merge(); | |
778 | |
779 StringValue* sv = stringtable.lookup(t.deco); | |
780 if (sv && sv.ptrvalue) | |
781 { | |
782 t = cast(Type)sv.ptrvalue; | |
783 assert(t.deco); | |
784 } | |
785 else | |
786 assert(0); | |
787 | |
788 return t; | |
789 } | |
790 | |
791 void toCBuffer(OutBuffer buf, Identifier ident, HdrGenState* hgs) | |
792 { | |
793 toCBuffer2(buf, hgs, MOD.MODundefined); | |
794 if (ident) | |
795 { | |
796 buf.writeByte(' '); | |
797 buf.writestring(ident.toChars()); | |
798 } | |
799 } | |
800 | |
801 void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) | |
802 { | |
803 if (mod != this.mod) | |
804 { | |
805 toCBuffer3(buf, hgs, mod); | |
806 return; | |
807 } | |
808 buf.writestring(toChars()); | |
809 } | |
810 | |
811 void toCBuffer3(OutBuffer buf, HdrGenState* hgs, MOD mod) | |
812 { | |
813 if (mod != this.mod) | |
814 { | |
815 string p; | |
816 | |
817 if (this.mod & MOD.MODshared) | |
818 buf.writestring("shared("); | |
819 | |
820 switch (this.mod & (MOD.MODconst | MOD.MODinvariant)) | |
821 { | |
822 case MOD.MODundefined: | |
823 toCBuffer2(buf, hgs, this.mod); | |
824 break; | |
825 case MOD.MODconst: | |
826 p = "const("; | |
827 goto L1; | |
828 case MOD.MODinvariant: | |
829 p = "immutable("; | |
830 L1: buf.writestring(p); | |
831 toCBuffer2(buf, hgs, this.mod); | |
832 buf.writeByte(')'); | |
833 break; | |
834 } | |
835 | |
836 if (this.mod & MOD.MODshared) | |
837 buf.writeByte(')'); | |
838 } | |
839 } | |
840 | |
841 void modToBuffer(OutBuffer buf) | |
842 { | |
843 if (mod & MOD.MODshared) | |
844 buf.writestring(" shared"); | |
845 if (mod & MOD.MODconst) | |
846 buf.writestring(" const"); | |
847 if (mod & MOD.MODinvariant) | |
848 buf.writestring(" immutable"); | |
849 } | |
850 | |
851 version (CPP_MANGLE) { | |
852 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
853 { | |
854 assert(false); | |
855 } | |
856 } | |
857 bool isintegral() | |
858 { | |
859 return false; | |
860 } | |
861 | |
862 bool isfloating() // real, imaginary, or complex | |
863 { | |
864 return false; | |
865 } | |
866 | |
867 bool isreal() | |
868 { | |
869 return false; | |
870 } | |
871 | |
872 bool isimaginary() | |
873 { | |
874 return false; | |
875 } | |
876 | |
877 bool iscomplex() | |
878 { | |
879 return false; | |
880 } | |
881 | |
882 bool isscalar() | |
883 { | |
884 return false; | |
885 } | |
886 | |
887 bool isunsigned() | |
888 { | |
889 return false; | |
890 } | |
891 | |
892 bool isauto() | |
893 { | |
894 return false; | |
895 } | |
896 | |
897 int isString() | |
898 { | |
899 return false; | |
900 } | |
901 | |
902 /************************** | |
903 * Given: | |
904 * T a, b; | |
905 * Can we assign: | |
906 * a = b; | |
907 * ? | |
908 */ | |
909 int isAssignable() | |
910 { | |
911 return true; | |
912 } | |
913 | |
914 bool checkBoolean() // if can be converted to boolean value | |
915 { | |
916 return isscalar(); | |
917 } | |
918 | |
919 /********************************* | |
920 * Check type to see if it is based on a deprecated symbol. | |
921 */ | |
922 void checkDeprecated(Loc loc, Scope sc) | |
923 { | |
924 Dsymbol s = toDsymbol(sc); | |
925 if (s) | |
926 s.checkDeprecated(loc, sc); | |
927 } | |
928 | |
929 bool isConst() { return (mod & MOD.MODconst) != 0; } | |
930 | |
931 int isInvariant() { return mod & MOD.MODinvariant; } | |
932 | |
933 int isMutable() { return !(mod & (MOD.MODconst | MOD.MODinvariant)); } | |
934 | |
935 int isShared() { return mod & MOD.MODshared; } | |
936 | |
937 int isSharedConst() { return mod == (MOD.MODshared | MOD.MODconst); } | |
938 | |
939 /******************************** | |
940 * Convert to 'const'. | |
941 */ | |
942 Type constOf() | |
943 { | |
944 static if (false) { | |
945 //printf("Type.constOf() %p %s\n", this, toChars()); | |
946 if (isConst()) | |
947 return this; | |
948 if (cto) | |
949 return cto; | |
950 Type t = makeConst(); | |
951 t = t.merge(); | |
952 cto = t; | |
953 if (ito) | |
954 ito.cto = t; | |
955 //if (t.nextOf()) assert(t.nextOf().isConst()); | |
956 //printf("-Type.constOf() %p %s\n", t, toChars()); | |
957 return t; | |
958 } else { | |
959 //printf("Type.constOf() %p %s\n", this, toChars()); | |
960 if (mod == MOD.MODconst) | |
961 return this; | |
962 if (cto) | |
963 { | |
964 assert(cto.mod == MOD.MODconst); | |
965 return cto; | |
966 } | |
967 Type t = makeConst(); | |
968 t = t.merge(); | |
969 t.fixTo(this); | |
970 //printf("-Type.constOf() %p %s\n", t, toChars()); | |
971 return t; | |
972 } | |
973 } | |
974 | |
975 /******************************** | |
976 * Convert to 'immutable'. | |
977 */ | |
978 Type invariantOf() | |
979 { | |
980 static if (false) { | |
981 //printf("Type.invariantOf() %p %s\n", this, toChars()); | |
982 if (isInvariant()) | |
983 { | |
984 return this; | |
985 } | |
986 if (ito) | |
987 { | |
988 //if (!ito.isInvariant()) printf("\tito is %p %s\n", ito, ito.toChars()); | |
989 assert(ito.isInvariant()); | |
990 return ito; | |
991 } | |
992 Type t = makeInvariant(); | |
993 t = t.merge(); | |
994 ito = t; | |
995 if (cto) | |
996 cto.ito = t; | |
997 static if (false) {// fails for function types | |
998 if (t.nextOf() && !t.nextOf().isInvariant()) | |
999 { | |
1000 assert(0); | |
1001 } | |
1002 } | |
1003 //printf("\t%p\n", t); | |
1004 return t; | |
1005 } else { | |
1006 //printf("Type.invariantOf() %p %s\n", this, toChars()); | |
1007 if (isInvariant()) | |
1008 { | |
1009 return this; | |
1010 } | |
1011 if (ito) | |
1012 { | |
1013 assert(ito.isInvariant()); | |
1014 return ito; | |
1015 } | |
1016 Type t = makeInvariant(); | |
1017 t = t.merge(); | |
1018 t.fixTo(this); | |
1019 //printf("\t%p\n", t); | |
1020 return t; | |
1021 } | |
1022 } | |
1023 | |
1024 Type mutableOf() | |
1025 { | |
1026 static if (false) { | |
1027 //printf("Type.mutableOf() %p, %s\n", this, toChars()); | |
1028 Type t = this; | |
1029 if (isConst()) | |
1030 { | |
1031 t = cto; | |
1032 assert(!t || t.isMutable()); | |
1033 } | |
1034 else if (isInvariant()) | |
1035 { | |
1036 t = ito; | |
1037 assert(!t || t.isMutable()); | |
1038 } | |
1039 if (!t) | |
1040 { | |
1041 uint sz = this.classinfo.init.length; | |
2 | 1042 t = cast(Type)GC.malloc(sz); |
0 | 1043 memcpy(cast(void*)t, cast(void*)this, sz); |
1044 t.mod = 0; | |
1045 t.deco = null; | |
1046 t.arrayof = null; | |
1047 t.pto = null; | |
1048 t.rto = null; | |
1049 t.cto = null; | |
1050 t.ito = null; | |
1051 t.sto = null; | |
1052 t.scto = null; | |
1053 t.vtinfo = null; | |
1054 if (ty == Tsarray) | |
1055 { | |
1056 TypeSArray ta = cast(TypeSArray)t; | |
1057 //ta.next = ta.next.mutableOf(); | |
1058 } | |
1059 t = t.merge(); | |
1060 if (isConst()) | |
1061 { cto = t; | |
1062 t.cto = this; | |
1063 if (ito) | |
1064 ito.cto = this; | |
1065 } | |
1066 else if (isInvariant()) | |
1067 { ito = t; | |
1068 t.ito = this; | |
1069 if (cto) | |
1070 cto.ito = this; | |
1071 } | |
1072 } | |
1073 return t; | |
1074 } else { | |
1075 //printf("Type.mutableOf() %p, %s\n", this, toChars()); | |
1076 Type t = this; | |
1077 if (isConst()) | |
1078 { | |
1079 if (isShared()) | |
1080 t = sto; // shared const => shared | |
1081 else | |
1082 t = cto; | |
1083 assert(!t || t.isMutable()); | |
1084 } | |
1085 else if (isInvariant()) | |
1086 { | |
1087 t = ito; | |
1088 assert(!t || (t.isMutable() && !t.isShared())); | |
1089 } | |
1090 if (!t) | |
1091 { | |
1092 uint sz = this.classinfo.init.length; | |
2 | 1093 t = cast(Type)GC.malloc(sz); |
0 | 1094 memcpy(cast(void*)t, cast(void*)this, sz); |
1095 t.mod = MODundefined; | |
1096 t.deco = null; | |
1097 t.arrayof = null; | |
1098 t.pto = null; | |
1099 t.rto = null; | |
1100 t.cto = null; | |
1101 t.ito = null; | |
1102 t.sto = null; | |
1103 t.scto = null; | |
1104 t.vtinfo = null; | |
1105 t = t.merge(); | |
1106 | |
1107 t.fixTo(this); | |
1108 | |
1109 switch (mod) | |
1110 { | |
1111 case MODconst: | |
1112 t.cto = this; | |
1113 break; | |
1114 | |
1115 case MODinvariant: | |
1116 t.ito = this; | |
1117 break; | |
1118 | |
1119 case MODshared: | |
1120 t.sto = this; | |
1121 break; | |
1122 | |
1123 case MODshared | MODconst: | |
1124 t.scto = this; | |
1125 break; | |
1126 | |
1127 default: | |
1128 assert(0); | |
1129 } | |
1130 } | |
1131 return t; | |
1132 } | |
1133 } | |
1134 | |
1135 Type sharedOf() | |
1136 { | |
1137 //printf("Type.sharedOf() %p, %s\n", this, toChars()); | |
1138 if (mod == MOD.MODshared) | |
1139 { | |
1140 return this; | |
1141 } | |
1142 if (sto) | |
1143 { | |
1144 assert(sto.isShared()); | |
1145 return sto; | |
1146 } | |
1147 | |
1148 Type t = makeShared(); | |
1149 t = t.merge(); | |
1150 t.fixTo(this); | |
1151 | |
1152 //printf("\t%p\n", t); | |
1153 return t; | |
1154 } | |
1155 | |
1156 Type sharedConstOf() | |
1157 { | |
1158 //printf("Type.sharedConstOf() %p, %s\n", this, toChars()); | |
1159 if (mod == (MODshared | MODconst)) | |
1160 { | |
1161 return this; | |
1162 } | |
1163 if (scto) | |
1164 { | |
1165 assert(scto.mod == (MODshared | MODconst)); | |
1166 return scto; | |
1167 } | |
1168 | |
1169 Type t = makeSharedConst(); | |
1170 t = t.merge(); | |
1171 t.fixTo(this); | |
1172 //printf("\t%p\n", t); | |
1173 | |
1174 return t; | |
1175 } | |
1176 | |
1177 static uint X(MOD m, MOD n) | |
1178 { | |
1179 return (((m) << 3) | (n)); | |
1180 } | |
1181 | |
1182 /********************************** | |
1183 * For our new type 'this', which is type-constructed from t, | |
1184 * fill in the cto, ito, sto, scto shortcuts. | |
1185 */ | |
1186 void fixTo(Type t) | |
1187 { | |
1188 ito = t.ito; | |
1189 static if (false) { | |
1190 /* Cannot do these because these are not fully transitive: | |
1191 * there can be a shared ptr to immutable, for example. | |
1192 * Immutable subtypes are always immutable, though. | |
1193 */ | |
1194 cto = t.cto; | |
1195 sto = t.sto; | |
1196 scto = t.scto; | |
1197 } | |
1198 | |
1199 assert(mod != t.mod); | |
1200 | |
1201 switch (X(mod, t.mod)) | |
1202 { | |
1203 case X(MOD.MODundefined, MOD.MODconst): | |
1204 cto = t; | |
1205 break; | |
1206 | |
1207 case X(MOD.MODundefined, MOD.MODinvariant): | |
1208 ito = t; | |
1209 break; | |
1210 | |
1211 case X(MOD.MODundefined, MOD.MODshared): | |
1212 sto = t; | |
1213 break; | |
1214 | |
1215 case X(MOD.MODundefined, MOD.MODshared | MOD.MODconst): | |
1216 scto = t; | |
1217 break; | |
1218 | |
1219 | |
1220 case X(MOD.MODconst, MOD.MODundefined): | |
1221 cto = null; | |
1222 goto L2; | |
1223 | |
1224 case X(MOD.MODconst, MOD.MODinvariant): | |
1225 ito = t; | |
1226 goto L2; | |
1227 | |
1228 case X(MOD.MODconst, MOD.MODshared): | |
1229 sto = t; | |
1230 goto L2; | |
1231 | |
1232 case X(MOD.MODconst, MOD.MODshared | MOD.MODconst): | |
1233 scto = t; | |
1234 L2: | |
1235 t.cto = this; | |
1236 break; | |
1237 | |
1238 | |
1239 case X(MOD.MODinvariant, MOD.MODundefined): | |
1240 ito = null; | |
1241 goto L3; | |
1242 | |
1243 case X(MOD.MODinvariant, MOD.MODconst): | |
1244 cto = t; | |
1245 goto L3; | |
1246 | |
1247 case X(MOD.MODinvariant, MOD.MODshared): | |
1248 sto = t; | |
1249 goto L3; | |
1250 | |
1251 case X(MOD.MODinvariant, MOD.MODshared | MOD.MODconst): | |
1252 scto = t; | |
1253 L3: | |
1254 t.ito = this; | |
1255 if (t.cto) t.cto.ito = this; | |
1256 if (t.sto) t.sto.ito = this; | |
1257 if (t.scto) t.scto.ito = this; | |
1258 break; | |
1259 | |
1260 | |
1261 case X(MOD.MODshared, MOD.MODundefined): | |
1262 sto = null; | |
1263 goto L4; | |
1264 | |
1265 case X(MOD.MODshared, MOD.MODconst): | |
1266 cto = t; | |
1267 goto L4; | |
1268 | |
1269 case X(MOD.MODshared, MOD.MODinvariant): | |
1270 ito = t; | |
1271 goto L4; | |
1272 | |
1273 case X(MOD.MODshared, MOD.MODshared | MOD.MODconst): | |
1274 scto = t; | |
1275 L4: | |
1276 t.sto = this; | |
1277 break; | |
1278 | |
1279 | |
1280 case X(MOD.MODshared | MOD.MODconst, MOD.MODundefined): | |
1281 scto = null; | |
1282 break; | |
1283 | |
1284 case X(MOD.MODshared | MOD.MODconst, MOD.MODconst): | |
1285 cto = t; | |
1286 break; | |
1287 | |
1288 case X(MOD.MODshared | MOD.MODconst, MOD.MODinvariant): | |
1289 ito = t; | |
1290 break; | |
1291 | |
1292 case X(MOD.MODshared | MOD.MODconst, MOD.MODshared): | |
1293 sto = t; | |
1294 L5: | |
1295 t.scto = this; | |
1296 break; | |
1297 } | |
1298 | |
1299 check(); | |
1300 t.check(); | |
1301 //printf("fixTo: %s, %s\n", toChars(), t.toChars()); | |
1302 } | |
1303 | |
1304 /*************************** | |
1305 * Look for bugs in constructing types. | |
1306 */ | |
1307 void check() | |
1308 { | |
1309 switch (mod) | |
1310 { | |
1311 case MOD.MODundefined: | |
1312 if (cto) assert(cto.mod == MOD.MODconst); | |
1313 if (ito) assert(ito.mod == MOD.MODinvariant); | |
1314 if (sto) assert(sto.mod == MOD.MODshared); | |
1315 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1316 break; | |
1317 | |
1318 case MOD.MODconst: | |
1319 if (cto) assert(cto.mod == MOD.MODundefined); | |
1320 if (ito) assert(ito.mod == MOD.MODinvariant); | |
1321 if (sto) assert(sto.mod == MOD.MODshared); | |
1322 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1323 break; | |
1324 | |
1325 case MOD.MODinvariant: | |
1326 if (cto) assert(cto.mod == MOD.MODconst); | |
1327 if (ito) assert(ito.mod == MOD.MODundefined); | |
1328 if (sto) assert(sto.mod == MOD.MODshared); | |
1329 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1330 break; | |
1331 | |
1332 case MOD.MODshared: | |
1333 if (cto) assert(cto.mod == MOD.MODconst); | |
1334 if (ito) assert(ito.mod == MOD.MODinvariant); | |
1335 if (sto) assert(sto.mod == MOD.MODundefined); | |
1336 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1337 break; | |
1338 | |
1339 case MOD.MODshared | MOD.MODconst: | |
1340 if (cto) assert(cto.mod == MOD.MODconst); | |
1341 if (ito) assert(ito.mod == MOD.MODinvariant); | |
1342 if (sto) assert(sto.mod == MOD.MODshared); | |
1343 if (scto) assert(scto.mod == MOD.MODundefined); | |
1344 break; | |
1345 } | |
1346 | |
1347 Type tn = nextOf(); | |
1348 if (tn && ty != TY.Tfunction && ty != TY.Tdelegate) | |
1349 { | |
1350 // Verify transitivity | |
1351 switch (mod) | |
1352 { | |
1353 case MOD.MODundefined: | |
1354 break; | |
1355 | |
1356 case MOD.MODconst: | |
1357 assert(tn.mod & MOD.MODinvariant || tn.mod & MOD.MODconst); | |
1358 break; | |
1359 | |
1360 case MOD.MODinvariant: | |
1361 assert(tn.mod == MOD.MODinvariant); | |
1362 break; | |
1363 | |
1364 case MOD.MODshared: | |
1365 assert(tn.mod & MOD.MODinvariant || tn.mod & MOD.MODshared); | |
1366 break; | |
1367 | |
1368 case MOD.MODshared | MOD.MODconst: | |
1369 assert(tn.mod & MOD.MODinvariant || tn.mod & (MOD.MODshared | MOD.MODconst)); | |
1370 break; | |
1371 } | |
1372 tn.check(); | |
1373 } | |
1374 } | |
1375 | |
1376 Type castMod(uint mod) | |
1377 { | |
1378 assert(false); | |
1379 } | |
1380 | |
1381 /************************************ | |
1382 * Add MODxxxx bits to existing type. | |
1383 * We're adding, not replacing, so adding const to | |
1384 * a shared type => "shared const" | |
1385 */ | |
1386 Type addMod(MOD mod) | |
1387 { | |
1388 Type t = this; | |
1389 | |
1390 /* Add anything to immutable, and it remains immutable | |
1391 */ | |
1392 if (!t.isInvariant()) | |
1393 { | |
1394 switch (mod) | |
1395 { | |
1396 case MOD.MODundefined: | |
1397 break; | |
1398 | |
1399 case MOD.MODconst: | |
1400 if (isShared()) | |
1401 t = sharedConstOf(); | |
1402 else | |
1403 t = constOf(); | |
1404 break; | |
1405 | |
1406 case MOD.MODinvariant: | |
1407 t = invariantOf(); | |
1408 break; | |
1409 | |
1410 case MOD.MODshared: | |
1411 if (isConst()) | |
1412 t = sharedConstOf(); | |
1413 else | |
1414 t = sharedOf(); | |
1415 break; | |
1416 | |
1417 case MOD.MODshared | MOD.MODconst: | |
1418 t = sharedConstOf(); | |
1419 break; | |
1420 } | |
1421 } | |
1422 return t; | |
1423 } | |
1424 | |
1425 Type addStorageClass(STC stc) | |
1426 { | |
1427 /* Just translate to MOD bits and let addMod() do the work | |
1428 */ | |
1429 MOD mod = MOD.MODundefined; | |
1430 | |
1431 if (stc & STC.STCimmutable) | |
1432 mod = MOD.MODinvariant; | |
1433 else | |
1434 { | |
1435 if (stc & (STC.STCconst | STC.STCin)) | |
1436 mod = MOD.MODconst; | |
1437 if (stc & STC.STCshared) | |
1438 mod |= MOD.MODshared; | |
1439 } | |
1440 | |
1441 return addMod(mod); | |
1442 } | |
1443 | |
1444 Type pointerTo() | |
1445 { | |
1446 if (pto is null) | |
1447 { | |
1448 Type t = new TypePointer(this); | |
1449 pto = t.merge(); | |
1450 } | |
1451 | |
1452 return pto; | |
1453 } | |
1454 | |
1455 Type referenceTo() | |
1456 { | |
1457 assert(false); | |
1458 } | |
1459 | |
1460 version (DumbClone) { | |
1461 final Type clone() | |
1462 { | |
1463 auto size = this.classinfo.init.length; | |
2 | 1464 auto ptr = GC.malloc(size); |
0 | 1465 memcpy(ptr, cast(void*)this, size); |
1466 | |
1467 return cast(Type)ptr; | |
1468 } | |
1469 } else { | |
1470 final Type cloneTo(Type t) | |
1471 { | |
1472 t.ctype = ctype; | |
1473 return t; | |
1474 } | |
1475 | |
1476 Type clone() | |
1477 { | |
1478 assert(this.classinfo is Type.classinfo); | |
1479 return cloneTo(new Type(ty)); | |
1480 } | |
1481 } | |
1482 | |
1483 Type arrayOf() | |
1484 { | |
1485 if (!arrayof) | |
1486 { | |
1487 Type t = new TypeDArray(this); | |
1488 arrayof = t.merge(); | |
1489 } | |
1490 return arrayof; | |
1491 } | |
1492 | |
1493 Type makeConst() | |
1494 { | |
1495 //printf("Type.makeConst() %p, %s\n", this, toChars()); | |
1496 if (cto) | |
1497 return cto; | |
1498 | |
1499 Type t = clone(); | |
1500 t.mod = MOD.MODconst; | |
1501 | |
1502 t.deco = null; | |
1503 t.arrayof = null; | |
1504 t.pto = null; | |
1505 t.rto = null; | |
1506 t.cto = null; | |
1507 t.ito = null; | |
1508 t.sto = null; | |
1509 t.scto = null; | |
1510 t.vtinfo = null; | |
1511 | |
1512 //printf("-Type.makeConst() %p, %s\n", t, toChars()); | |
1513 return t; | |
1514 } | |
1515 | |
1516 Type makeInvariant() | |
1517 { | |
1518 if (ito) { | |
1519 return ito; | |
1520 } | |
1521 | |
1522 Type t = clone(); | |
1523 t.mod = MOD.MODinvariant; | |
1524 | |
1525 t.deco = null; | |
1526 t.arrayof = null; | |
1527 t.pto = null; | |
1528 t.rto = null; | |
1529 t.cto = null; | |
1530 t.ito = null; | |
1531 t.sto = null; | |
1532 t.scto = null; | |
1533 t.vtinfo = null; | |
1534 | |
1535 return t; | |
1536 } | |
1537 | |
1538 Type makeShared() | |
1539 { | |
1540 if (sto) | |
1541 return sto; | |
1542 | |
1543 Type t = clone(); | |
1544 t.mod = MOD.MODshared; | |
1545 | |
1546 t.deco = null; | |
1547 t.arrayof = null; | |
1548 t.pto = null; | |
1549 t.rto = null; | |
1550 t.cto = null; | |
1551 t.ito = null; | |
1552 t.sto = null; | |
1553 t.scto = null; | |
1554 t.vtinfo = null; | |
1555 | |
1556 return t; | |
1557 } | |
1558 | |
1559 Type makeSharedConst() | |
1560 { | |
1561 if (scto) | |
1562 return scto; | |
1563 | |
1564 Type t = clone(); | |
1565 t.mod = MODshared | MODconst; | |
1566 | |
1567 t.deco = null; | |
1568 t.arrayof = null; | |
1569 t.pto = null; | |
1570 t.rto = null; | |
1571 t.cto = null; | |
1572 t.ito = null; | |
1573 t.sto = null; | |
1574 t.scto = null; | |
1575 t.vtinfo = null; | |
1576 | |
1577 return t; | |
1578 } | |
1579 | |
1580 Dsymbol toDsymbol(Scope sc) | |
1581 { | |
1582 return null; | |
1583 } | |
1584 | |
1585 /******************************* | |
1586 * If this is a shell around another type, | |
1587 * get that other type. | |
1588 */ | |
1589 | |
1590 Type toBasetype() | |
1591 { | |
1592 return this; | |
1593 } | |
1594 | |
1595 /************************** | |
1596 * Return type with the top level of it being mutable. | |
1597 */ | |
1598 Type toHeadMutable() | |
1599 { | |
1600 if (!mod) | |
1601 return this; | |
1602 | |
1603 return mutableOf(); | |
1604 } | |
1605 | |
1606 bool isBaseOf(Type t, int* poffset) | |
1607 { | |
1608 return false; // assume not | |
1609 } | |
1610 | |
1611 /******************************* | |
1612 * Determine if converting 'this' to 'to' is an identity operation, | |
1613 * a conversion to const operation, or the types aren't the same. | |
1614 * Returns: | |
1615 * MATCHequal 'this' == 'to' | |
1616 * MATCHconst 'to' is const | |
1617 * MATCHnomatch conversion to mutable or invariant | |
1618 */ | |
1619 MATCH constConv(Type to) | |
1620 { | |
1621 if (equals(to)) | |
1622 return MATCH.MATCHexact; | |
1623 if (ty == to.ty && to.mod == MOD.MODconst) | |
1624 return MATCH.MATCHconst; | |
1625 return MATCH.MATCHnomatch; | |
1626 } | |
1627 | |
1628 /******************************** | |
1629 * Determine if 'this' can be implicitly converted | |
1630 * to type 'to'. | |
1631 * Returns: | |
1632 * MATCHnomatch, MATCHconvert, MATCHconst, MATCHexact | |
1633 */ | |
1634 MATCH implicitConvTo(Type to) | |
1635 { | |
1636 //printf("Type.implicitConvTo(this=%p, to=%p)\n", this, to); | |
1637 //printf("from: %s\n", toChars()); | |
1638 //printf("to : %s\n", to.toChars()); | |
1639 if (this is to) | |
1640 return MATCHexact; | |
1641 | |
1642 return MATCHnomatch; | |
1643 } | |
1644 | |
1645 ClassDeclaration isClassHandle() | |
1646 { | |
1647 return null; | |
1648 } | |
1649 | |
1650 Expression getProperty(Loc loc, Identifier ident) | |
1651 { | |
1652 Expression e; | |
1653 | |
1654 version (LOGDOTEXP) { | |
1655 printf("Type.getProperty(type = '%s', ident = '%s')\n", toChars(), ident.toChars()); | |
1656 } | |
1657 if (ident == Id.__sizeof) | |
1658 { | |
1659 e = new IntegerExp(loc, size(loc), Type.tsize_t); | |
1660 } | |
1661 else if (ident == Id.size) | |
1662 { | |
1663 error(loc, ".size property should be replaced with .sizeof"); | |
1664 e = new ErrorExp(); | |
1665 } | |
1666 else if (ident is Id.alignof_) | |
1667 { | |
1668 e = new IntegerExp(loc, alignsize(), Type.tsize_t); | |
1669 } | |
1670 else if (ident == Id.typeinfo_) | |
1671 { | |
1672 if (!global.params.useDeprecated) | |
1673 error(loc, ".typeinfo deprecated, use typeid(type)"); | |
1674 e = getTypeInfo(null); | |
1675 } | |
1676 else if (ident == Id.init_) | |
1677 { | |
1678 if (ty == TY.Tvoid) | |
1679 error(loc, "void does not have an initializer"); | |
1680 e = defaultInit(loc); | |
1681 } | |
1682 else if (ident is Id.mangleof_) | |
1683 { | |
1684 string s; | |
1685 if (!deco) { | |
1686 s = toChars(); | |
1687 error(loc, "forward reference of type %s.mangleof", s); | |
1688 } else { | |
1689 s = deco; | |
1690 } | |
1691 | |
1692 e = new StringExp(loc, s, 'c'); | |
1693 Scope sc = new Scope(); | |
1694 e = e.semantic(sc); | |
1695 } | |
1696 else if (ident is Id.stringof_) | |
1697 { | |
1698 string s = toChars(); | |
1699 e = new StringExp(loc, s, 'c'); | |
1700 Scope sc = new Scope(); | |
1701 e = e.semantic(sc); | |
1702 } | |
1703 else | |
1704 { | |
1705 error(loc, "no property '%s' for type '%s'", ident.toChars(), toChars()); | |
1706 e = new ErrorExp(); | |
1707 } | |
1708 return e; | |
1709 } | |
1710 | |
1711 Expression dotExp(Scope sc, Expression e, Identifier ident) | |
1712 { | |
1713 VarDeclaration v = null; | |
1714 | |
1715 version (LOGDOTEXP) { | |
1716 printf("Type.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
1717 } | |
1718 if (e.op == TOK.TOKdotvar) | |
1719 { | |
1720 DotVarExp dv = cast(DotVarExp)e; | |
1721 v = dv.var.isVarDeclaration(); | |
1722 } | |
1723 else if (e.op == TOK.TOKvar) | |
1724 { | |
1725 VarExp ve = cast(VarExp)e; | |
1726 v = ve.var.isVarDeclaration(); | |
1727 } | |
1728 if (v) | |
1729 { | |
1730 if (ident is Id.offset) | |
1731 { | |
1732 if (!global.params.useDeprecated) | |
1733 error(e.loc, ".offset deprecated, use .offsetof"); | |
1734 goto Loffset; | |
1735 } | |
1736 else if (ident is Id.offsetof) | |
1737 { | |
1738 Loffset: | |
1739 if (v.storage_class & STC.STCfield) | |
1740 { | |
1741 e = new IntegerExp(e.loc, v.offset, Type.tsize_t); | |
1742 return e; | |
1743 } | |
1744 } | |
1745 else if (ident is Id.init_) | |
1746 { | |
1747 static if (false) { | |
1748 if (v.init) | |
1749 { | |
1750 if (v.init.isVoidInitializer()) | |
1751 error(e.loc, "%s.init is void", v.toChars()); | |
1752 else | |
1753 { Loc loc = e.loc; | |
1754 e = v.init.toExpression(); | |
1755 if (e.op == TOK.TOKassign || e.op == TOK.TOKconstruct || e.op == TOK.TOKblit) | |
1756 { | |
1757 e = (cast(AssignExp)e).e2; | |
1758 | |
1759 /* Take care of case where we used a 0 | |
1760 * to initialize the struct. | |
1761 */ | |
1762 if (e.type == Type.tint32 && | |
1763 e.isBool(0) && | |
1764 v.type.toBasetype().ty == TY.Tstruct) | |
1765 { | |
1766 e = v.type.defaultInit(e.loc); | |
1767 } | |
1768 } | |
1769 e = e.optimize(WANTvalue | WANTinterpret); | |
1770 // if (!e.isConst()) | |
1771 // error(loc, ".init cannot be evaluated at compile time"); | |
1772 } | |
1773 return e; | |
1774 } | |
1775 } | |
1776 Expression ex = defaultInit(e.loc); | |
1777 return ex; | |
1778 } | |
1779 } | |
1780 if (ident is Id.typeinfo_) | |
1781 { | |
1782 if (!global.params.useDeprecated) | |
1783 error(e.loc, ".typeinfo deprecated, use typeid(type)"); | |
1784 e = getTypeInfo(sc); | |
1785 return e; | |
1786 } | |
1787 if (ident is Id.stringof_) | |
1788 { | |
1789 string s = e.toChars(); | |
1790 e = new StringExp(e.loc, s, 'c'); | |
1791 Scope sc2 = new Scope(); /// | |
1792 e = e.semantic(sc2); | |
1793 return e; | |
1794 } | |
1795 return getProperty(e.loc, ident); | |
1796 } | |
1797 | |
1798 uint memalign(uint salign) | |
1799 { | |
1800 return salign; | |
1801 } | |
1802 | |
1803 ///Expression defaultInit(Loc loc = Loc(0)) | |
1804 Expression defaultInit(Loc loc) | |
1805 { | |
1806 assert(false); | |
1807 } | |
1808 | |
1809 ///bool isZeroInit(Loc loc = Loc(0)) // if initializer is 0 | |
1810 bool isZeroInit(Loc loc) // if initializer is 0 | |
1811 { | |
1812 assert(false); | |
1813 } | |
1814 | |
1815 dt_t** toDt(dt_t** pdt) | |
1816 { | |
1817 //printf("Type.toDt()\n"); | |
1818 Expression e = defaultInit(Loc(0)); | |
1819 return e.toDt(pdt); | |
1820 } | |
1821 | |
1822 Identifier getTypeInfoIdent(int internal) | |
1823 { | |
1824 // _init_10TypeInfo_%s | |
1825 scope OutBuffer buf = new OutBuffer(); | |
1826 Identifier id; | |
1827 char* name; | |
1828 int len; | |
1829 | |
1830 if (internal) | |
1831 { | |
1832 buf.writeByte(mangleChar[ty]); | |
1833 if (ty == TY.Tarray) | |
1834 buf.writeByte(mangleChar[(cast(TypeArray)this).next.ty]); | |
1835 } | |
1836 else | |
1837 toDecoBuffer(buf); | |
1838 | |
1839 len = buf.offset; | |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1840 version (Bug4054) |
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1841 name = cast(char*)GC.malloc(19 + len.sizeof * 3 + len + 1); |
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1842 else |
0 | 1843 name = cast(char*)alloca(19 + len.sizeof * 3 + len + 1); |
1844 buf.writeByte(0); | |
1845 version (TARGET_OSX) { | |
1846 // The LINKc will prepend the _ | |
1847 len = sprintf(name, "D%dTypeInfo_%s6__initZ".ptr, 9 + len, buf.data); | |
1848 } else { | |
1849 len = sprintf(name, "_D%dTypeInfo_%s6__initZ".ptr, 9 + len, buf.data); | |
1850 } | |
1851 if (global.params.isWindows) | |
1852 name++; // C mangling will add it back in | |
1853 //printf("name = %s\n", name); | |
1854 id = Lexer.idPool(name[0..len-1].idup); | |
1855 return id; | |
1856 } | |
1857 | |
1858 /* These form the heart of template argument deduction. | |
1859 * Given 'this' being the type argument to the template instance, | |
1860 * it is matched against the template declaration parameter specialization | |
1861 * 'tparam' to determine the type to be used for the parameter. | |
1862 * Example: | |
1863 * template Foo(T:T*) // template declaration | |
1864 * Foo!(int*) // template instantiation | |
1865 * Input: | |
1866 * this = int* | |
1867 * tparam = T | |
1868 * parameters = [ T:T* ] // Array of TemplateParameter's | |
1869 * Output: | |
1870 * dedtypes = [ int ] // Array of Expression/Type's | |
1871 */ | |
1872 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) | |
1873 { | |
1874 static if (false) { | |
1875 printf("Type.deduceType()\n"); | |
1876 printf("\tthis = %d, ", ty); print(); | |
1877 printf("\ttparam = %d, ", tparam.ty); tparam.print(); | |
1878 } | |
1879 if (!tparam) | |
1880 goto Lnomatch; | |
1881 | |
1882 if (this == tparam) | |
1883 goto Lexact; | |
1884 | |
1885 if (tparam.ty == Tident) | |
1886 { | |
1887 // Determine which parameter tparam is | |
1888 int i = templateParameterLookup(tparam, parameters); | |
1889 if (i == -1) | |
1890 { | |
1891 if (!sc) | |
1892 goto Lnomatch; | |
1893 | |
1894 /* Need a loc to go with the semantic routine. | |
1895 */ | |
1896 Loc loc; | |
1897 if (parameters.dim) | |
1898 { | |
1899 TemplateParameter tp = cast(TemplateParameter)parameters.data[0]; | |
1900 loc = tp.loc; | |
1901 } | |
1902 | |
1903 /* BUG: what if tparam is a template instance, that | |
1904 * has as an argument another Tident? | |
1905 */ | |
1906 tparam = tparam.semantic(loc, sc); | |
1907 assert(tparam.ty != Tident); | |
1908 return deduceType(sc, tparam, parameters, dedtypes); | |
1909 } | |
1910 | |
1911 TemplateParameter tp = cast(TemplateParameter)parameters.data[i]; | |
1912 | |
1913 // Found the corresponding parameter tp | |
1914 if (!tp.isTemplateTypeParameter()) | |
1915 goto Lnomatch; | |
1916 Type tt = this; | |
1917 Type at = cast(Type)dedtypes.data[i]; | |
1918 | |
1919 // 3*3 == 9 cases | |
1920 if (tparam.isMutable()) | |
1921 { // foo(U:U) T => T | |
1922 // foo(U:U) const(T) => const(T) | |
1923 // foo(U:U) invariant(T) => invariant(T) | |
1924 if (!at) | |
1925 { | |
1926 dedtypes.data[i] = cast(void*)this; | |
1927 goto Lexact; | |
1928 } | |
1929 } | |
1930 else if (mod == tparam.mod) | |
1931 { // foo(U:const(U)) const(T) => T | |
1932 // foo(U:invariant(U)) invariant(T) => T | |
1933 tt = mutableOf(); | |
1934 if (!at) | |
1935 { | |
1936 dedtypes.data[i] = cast(void*)tt; | |
1937 goto Lexact; | |
1938 } | |
1939 } | |
1940 else if (tparam.isConst()) | |
1941 { // foo(U:const(U)) T => T | |
1942 // foo(U:const(U)) invariant(T) => T | |
1943 tt = mutableOf(); | |
1944 if (!at) | |
1945 { | |
1946 dedtypes.data[i] = cast(void*)tt; | |
1947 goto Lconst; | |
1948 } | |
1949 } | |
1950 else | |
1951 { // foo(U:invariant(U)) T => nomatch | |
1952 // foo(U:invariant(U)) const(T) => nomatch | |
1953 if (!at) | |
1954 goto Lnomatch; | |
1955 } | |
1956 | |
1957 if (tt.equals(at)) | |
1958 goto Lexact; | |
1959 else if (tt.ty == Tclass && at.ty == Tclass) | |
1960 { | |
1961 return tt.implicitConvTo(at); | |
1962 } | |
1963 else if (tt.ty == Tsarray && at.ty == Tarray && | |
1964 tt.nextOf().implicitConvTo(at.nextOf()) >= MATCHconst) | |
1965 { | |
1966 goto Lexact; | |
1967 } | |
1968 else | |
1969 goto Lnomatch; | |
1970 } | |
1971 | |
1972 if (ty != tparam.ty) | |
1973 return implicitConvTo(tparam); | |
1974 // goto Lnomatch; | |
1975 | |
1976 if (nextOf()) | |
1977 return nextOf().deduceType(sc, tparam.nextOf(), parameters, dedtypes); | |
1978 | |
1979 Lexact: | |
1980 return MATCHexact; | |
1981 | |
1982 Lnomatch: | |
1983 return MATCHnomatch; | |
1984 | |
1985 version (DMDV2) { | |
1986 Lconst: | |
1987 return MATCHconst; | |
1988 } | |
1989 } | |
1990 | |
1991 void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) | |
1992 { | |
1993 //printf("Type.resolve() %s, %d\n", toChars(), ty); | |
1994 Type t = semantic(loc, sc); | |
1995 *pt = t; | |
1996 *pe = null; | |
1997 *ps = null; | |
1998 } | |
1999 | |
2000 /******************************************* | |
2001 * Get a canonicalized form of the TypeInfo for use with the internal | |
2002 * runtime library routines. Canonicalized in that static arrays are | |
2003 * represented as dynamic arrays, enums are represented by their | |
2004 * underlying type, etc. This reduces the number of TypeInfo's needed, | |
2005 * so we can use the custom internal ones more. | |
2006 */ | |
2007 Expression getInternalTypeInfo(Scope sc) | |
2008 { | |
2009 TypeInfoDeclaration tid; | |
2010 Expression e; | |
2011 Type t; | |
2012 static TypeInfoDeclaration internalTI[TMAX]; | |
2013 | |
2014 //printf("Type.getInternalTypeInfo() %s\n", toChars()); | |
2015 t = toBasetype(); | |
2016 switch (t.ty) | |
2017 { | |
2018 case Tsarray: | |
2019 static if (false) { | |
2020 // convert to corresponding dynamic array type | |
2021 t = t.nextOf().mutableOf().arrayOf(); | |
2022 } | |
2023 break; | |
2024 | |
2025 case Tclass: | |
2026 if ((cast(TypeClass)t).sym.isInterfaceDeclaration()) | |
2027 break; | |
2028 goto Linternal; | |
2029 | |
2030 case Tarray: | |
2031 // convert to corresponding dynamic array type | |
2032 t = t.nextOf().mutableOf().arrayOf(); | |
2033 if (t.nextOf().ty != Tclass) | |
2034 break; | |
2035 goto Linternal; | |
2036 | |
2037 case Tfunction: | |
2038 case Tdelegate: | |
2039 case Tpointer: | |
2040 Linternal: | |
2041 tid = internalTI[t.ty]; | |
2042 if (!tid) | |
2043 { | |
2044 tid = new TypeInfoDeclaration(t, 1); | |
2045 internalTI[t.ty] = tid; | |
2046 } | |
2047 e = new VarExp(Loc(0), tid); | |
2048 e = e.addressOf(sc); | |
2049 e.type = tid.type; // do this so we don't get redundant dereference | |
2050 return e; | |
2051 | |
2052 default: | |
2053 break; | |
2054 } | |
2055 //printf("\tcalling getTypeInfo() %s\n", t.toChars()); | |
2056 return t.getTypeInfo(sc); | |
2057 } | |
2058 | |
2059 /**************************************************** | |
2060 * Get the exact TypeInfo. | |
2061 */ | |
2062 Expression getTypeInfo(Scope sc) | |
2063 { | |
2064 Expression e; | |
2065 Type t; | |
2066 | |
2067 //printf("Type.getTypeInfo() %p, %s\n", this, toChars()); | |
2068 t = merge2(); // do this since not all Type's are merge'd | |
2069 if (!t.vtinfo) | |
2070 { | |
2071 version (DMDV2) { | |
2072 if (t.isShared()) // does both 'shared' and 'shared const' | |
2073 t.vtinfo = new TypeInfoSharedDeclaration(t); | |
2074 else if (t.isConst()) | |
2075 t.vtinfo = new TypeInfoConstDeclaration(t); | |
2076 else if (t.isInvariant()) | |
2077 t.vtinfo = new TypeInfoInvariantDeclaration(t); | |
2078 else | |
2079 t.vtinfo = t.getTypeInfoDeclaration(); | |
2080 } else { | |
2081 t.vtinfo = t.getTypeInfoDeclaration(); | |
2082 } | |
2083 assert(t.vtinfo); | |
2084 vtinfo = t.vtinfo; | |
2085 | |
2086 /* If this has a custom implementation in std/typeinfo, then | |
2087 * do not generate a COMDAT for it. | |
2088 */ | |
2089 if (!t.builtinTypeInfo()) | |
2090 { | |
2091 // Generate COMDAT | |
2092 if (sc) // if in semantic() pass | |
2093 { | |
2094 // Find module that will go all the way to an object file | |
2095 Module m = sc.module_.importedFrom; | |
2096 m.members.push(cast(void*)t.vtinfo); | |
2097 } | |
2098 else // if in obj generation pass | |
2099 { | |
2100 t.vtinfo.toObjFile(global.params.multiobj); | |
2101 } | |
2102 } | |
2103 } | |
2104 e = new VarExp(Loc(0), t.vtinfo); | |
2105 e = e.addressOf(sc); | |
2106 e.type = t.vtinfo.type; // do this so we don't get redundant dereference | |
2107 return e; | |
2108 } | |
2109 | |
2110 TypeInfoDeclaration getTypeInfoDeclaration() | |
2111 { | |
2112 //printf("Type.getTypeInfoDeclaration() %s\n", toChars()); | |
2113 return new TypeInfoDeclaration(this, 0); | |
2114 } | |
2115 | |
2116 /* These decide if there's an instance for them already in std.typeinfo, | |
2117 * because then the compiler doesn't need to build one. | |
2118 */ | |
2119 bool builtinTypeInfo() | |
2120 { | |
2121 return false; | |
2122 } | |
2123 | |
2124 /******************************* | |
2125 * If one of the subtypes of this type is a TypeIdentifier, | |
2126 * i.e. it's an unresolved type, return that type. | |
2127 */ | |
2128 Type reliesOnTident() | |
2129 { | |
2130 return null; | |
2131 } | |
2132 | |
2133 Expression toExpression() | |
2134 { | |
2135 assert(false); | |
2136 } | |
2137 | |
2138 /*************************************** | |
2139 * Return true if type has pointers that need to | |
2140 * be scanned by the GC during a collection cycle. | |
2141 */ | |
2142 bool hasPointers() | |
2143 { | |
2144 return false; | |
2145 } | |
2146 | |
2147 /************************************* | |
2148 * If this is a type of something, return that something. | |
2149 */ | |
2150 Type nextOf() | |
2151 { | |
2152 return null; | |
2153 } | |
2154 | |
2155 ulong sizemask() | |
2156 { | |
2157 assert(false); | |
2158 } | |
2159 | |
2160 static void error(T...)(Loc loc, string format, T t) | |
2161 { | |
2162 .error(loc, format, t); | |
2163 } | |
2164 | |
2165 static void warning(T...)(Loc loc, string format, T t) | |
2166 { | |
2167 assert(false); | |
2168 } | |
2169 | |
2170 // For backend | |
2171 /***************************** | |
2172 * Return back end type corresponding to D front end type. | |
2173 */ | |
2174 TYM totym() | |
2175 { | |
2176 TYM t; | |
2177 | |
2178 switch (ty) | |
2179 { | |
2180 case TY.Tvoid: t = TYM.TYvoid; break; | |
2181 case TY.Tint8: t = TYM.TYschar; break; | |
2182 case TY.Tuns8: t = TYM.TYuchar; break; | |
2183 case TY.Tint16: t = TYM.TYshort; break; | |
2184 case TY.Tuns16: t = TYM.TYushort; break; | |
2185 case TY.Tint32: t = TYM.TYint; break; | |
2186 case TY.Tuns32: t = TYM.TYuint; break; | |
2187 case TY.Tint64: t = TYM.TYllong; break; | |
2188 case TY.Tuns64: t = TYM.TYullong; break; | |
2189 case TY.Tfloat32: t = TYM.TYfloat; break; | |
2190 case TY.Tfloat64: t = TYM.TYdouble; break; | |
2191 case TY.Tfloat80: t = TYM.TYldouble; break; | |
2192 case TY.Timaginary32: t = TYM.TYifloat; break; | |
2193 case TY.Timaginary64: t = TYM.TYidouble; break; | |
2194 case TY.Timaginary80: t = TYM.TYildouble; break; | |
2195 case TY.Tcomplex32: t = TYM.TYcfloat; break; | |
2196 case TY.Tcomplex64: t = TYM.TYcdouble; break; | |
2197 case TY.Tcomplex80: t = TYM.TYcldouble; break; | |
2198 //case Tbit: t = TYM.TYuchar; break; | |
2199 case TY.Tbool: t = TYM.TYbool; break; | |
2200 case TY.Tchar: t = TYM.TYchar; break; | |
2201 version (XXX) { ///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS | |
2202 case TY.Twchar: t = TYM.TYwchar_t; break; | |
2203 case TY.Tdchar: t = TYM.TYdchar; break; | |
2204 } else { | |
2205 case TY.Twchar: t = TYM.TYwchar_t; break; | |
2206 case TY.Tdchar: | |
2207 t = (global.params.symdebug == 1) ? TYM.TYdchar : TYM.TYulong; | |
2208 break; | |
2209 } | |
2210 | |
2211 case TY.Taarray: t = TYM.TYaarray; break; | |
2212 case TY.Tclass: | |
2213 case TY.Treference: | |
2214 case TY.Tpointer: t = TYM.TYnptr; break; | |
2215 case TY.Tdelegate: t = TYM.TYdelegate; break; | |
2216 case TY.Tarray: t = TYM.TYdarray; break; | |
2217 case TY.Tsarray: t = TYM.TYarray; break; | |
2218 case TY.Tstruct: t = TYM.TYstruct; break; | |
2219 | |
2220 case TY.Tenum: | |
2221 case TY.Ttypedef: | |
2222 t = toBasetype().totym(); | |
2223 break; | |
2224 | |
2225 case TY.Tident: | |
2226 case TY.Ttypeof: | |
2227 debug { | |
2228 writef("ty = %d, '%s'\n", ty, toChars()); | |
2229 } | |
2230 error (Loc(0), "forward reference of %s", toChars()); | |
2231 t = TYM.TYint; | |
2232 break; | |
2233 | |
2234 default: | |
2235 debug { | |
2236 writef("ty = %d, '%s'\n", ty, toChars()); | |
2237 } | |
2238 assert(0); | |
2239 } | |
2240 | |
2241 version (DMDV2) { | |
2242 // Add modifiers | |
2243 switch (mod) | |
2244 { | |
2245 case MOD.MODundefined: | |
2246 break; | |
2247 case MOD.MODconst: | |
2248 t |= mTY.mTYconst; | |
2249 break; | |
2250 case MOD.MODinvariant: | |
2251 t |= mTY.mTYimmutable; | |
2252 break; | |
2253 case MOD.MODshared: | |
2254 t |= mTY.mTYshared; | |
2255 break; | |
2256 case MOD.MODshared | MOD.MODconst: | |
2257 t |= mTY.mTYshared | mTY.mTYconst; | |
2258 break; | |
2259 default: | |
2260 assert(0); | |
2261 } | |
2262 } | |
2263 | |
2264 return t; | |
2265 } | |
2266 | |
2267 /*************************************** | |
2268 * Convert from D type to C type. | |
2269 * This is done so C debug info can be generated. | |
2270 */ | |
2271 type* toCtype() | |
2272 { | |
2273 if (!ctype) | |
2274 { | |
2275 ctype = type_fake(totym()); | |
2276 ctype.Tcount++; | |
2277 } | |
2278 return ctype; | |
2279 } | |
2280 | |
2281 type* toCParamtype() | |
2282 { | |
2283 return toCtype(); | |
2284 } | |
2285 | |
2286 Symbol* toSymbol() | |
2287 { | |
2288 assert(false); | |
2289 } | |
2290 | |
2291 // For eliminating dynamic_cast | |
2292 TypeBasic isTypeBasic() | |
2293 { | |
2294 return null; | |
2295 } | |
2296 | |
2297 static Type tvoid() | |
2298 { | |
2299 return basic[TY.Tvoid]; | |
2300 } | |
2301 | |
2302 static Type tint8() | |
2303 { | |
2304 return basic[TY.Tint8]; | |
2305 } | |
2306 | |
2307 static Type tuns8() | |
2308 { | |
2309 return basic[TY.Tuns8]; | |
2310 } | |
2311 | |
2312 static Type tint16() | |
2313 { | |
2314 return basic[TY.Tint16]; | |
2315 } | |
2316 | |
2317 static Type tuns16() | |
2318 { | |
2319 return basic[TY.Tuns16]; | |
2320 } | |
2321 | |
2322 static Type tint32() | |
2323 { | |
2324 return basic[TY.Tint32]; | |
2325 } | |
2326 | |
2327 static Type tuns32() | |
2328 { | |
2329 return basic[TY.Tuns32]; | |
2330 } | |
2331 | |
2332 static Type tint64() | |
2333 { | |
2334 return basic[TY.Tint64]; | |
2335 } | |
2336 | |
2337 static Type tuns64() | |
2338 { | |
2339 return basic[TY.Tuns64]; | |
2340 } | |
2341 | |
2342 static Type tfloat32() | |
2343 { | |
2344 return basic[TY.Tfloat32]; | |
2345 } | |
2346 | |
2347 static Type tfloat64() | |
2348 { | |
2349 return basic[TY.Tfloat64]; | |
2350 } | |
2351 | |
2352 static Type tfloat80() | |
2353 { | |
2354 return basic[TY.Tfloat80]; | |
2355 } | |
2356 | |
2357 static Type timaginary32() | |
2358 { | |
2359 return basic[TY.Timaginary32]; | |
2360 } | |
2361 | |
2362 static Type timaginary64() | |
2363 { | |
2364 return basic[TY.Timaginary64]; | |
2365 } | |
2366 | |
2367 static Type timaginary80() | |
2368 { | |
2369 return basic[TY.Timaginary80]; | |
2370 } | |
2371 | |
2372 static Type tcomplex32() | |
2373 { | |
2374 return basic[TY.Tcomplex32]; | |
2375 } | |
2376 | |
2377 static Type tcomplex64() | |
2378 { | |
2379 return basic[TY.Tcomplex64]; | |
2380 } | |
2381 | |
2382 static Type tcomplex80() | |
2383 { | |
2384 return basic[TY.Tcomplex80]; | |
2385 } | |
2386 | |
2387 static Type tbit() | |
2388 { | |
2389 return basic[TY.Tbit]; | |
2390 } | |
2391 | |
2392 static Type tbool() | |
2393 { | |
2394 return basic[TY.Tbool]; | |
2395 } | |
2396 | |
2397 static Type tchar() | |
2398 { | |
2399 return basic[TY.Tchar]; | |
2400 } | |
2401 | |
2402 static Type twchar() | |
2403 { | |
2404 return basic[TY.Twchar]; | |
2405 } | |
2406 | |
2407 static Type tdchar() | |
2408 { | |
2409 return basic[TY.Tdchar]; | |
2410 } | |
2411 | |
2412 // Some special types | |
2413 static Type tshiftcnt() | |
2414 { | |
2415 return tint32; // right side of shift expression | |
2416 } | |
2417 | |
2418 // #define tboolean tint32 // result of boolean expression | |
2419 static Type tboolean() | |
2420 { | |
2421 return tbool; // result of boolean expression | |
2422 } | |
2423 | |
2424 static Type tindex() | |
2425 { | |
2426 return tint32; // array/ptr index | |
2427 } | |
2428 | |
2429 static Type tvoidptr; // void* | |
2430 | |
2431 static Type terror() | |
2432 { | |
2433 return basic[TY.Terror]; // for error recovery | |
2434 } | |
2435 | |
2436 static Type tsize_t() | |
2437 { | |
2438 return basic[Tsize_t]; // matches size_t alias | |
2439 } | |
2440 | |
2441 static Type tptrdiff_t() | |
2442 { | |
2443 return basic[Tptrdiff_t]; // matches ptrdiff_t alias | |
2444 } | |
2445 | |
2446 static Type thash_t() | |
2447 { | |
2448 return tsize_t; // matches hash_t alias | |
2449 } | |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
2450 } |