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