comparison dmd/Type.d @ 0:10317f0c89a5

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