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