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