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