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