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