Mercurial > projects > ddmd
annotate dmd/TypeFunction.d @ 143:95b3ed3cddd5
fixed phobos compilation bug
author | Trass3r |
---|---|
date | Tue, 14 Sep 2010 15:25:44 +0200 |
parents | af1bebfd96a4 |
children | fe2e1b93e88f |
rev | line source |
---|---|
0 | 1 module dmd.TypeFunction; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.TypeNext; |
5 import dmd.TypeSArray; | |
6 import dmd.TypeArray; | |
123 | 7 import dmd.TemplateTupleParameter; |
0 | 8 import dmd.ArrayTypes; |
9 import dmd.LINK; | |
10 import dmd.StructDeclaration; | |
11 import dmd.TypeStruct; | |
12 import dmd.Global; | |
13 import dmd.STC; | |
14 import dmd.MOD; | |
73 | 15 import dmd.PROT; |
123 | 16 import dmd.TypeIdentifier; |
17 import dmd.TemplateParameter; | |
129 | 18 import dmd.TypeInfoFunctionDeclaration; |
123 | 19 import dmd.Tuple; |
0 | 20 import dmd.Type; |
21 import dmd.Loc; | |
22 import dmd.Scope; | |
23 import dmd.Identifier; | |
24 import dmd.OutBuffer; | |
25 import dmd.HdrGenState; | |
26 import dmd.CppMangleState; | |
27 import dmd.TypeInfoDeclaration; | |
28 import dmd.MATCH; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
29 import dmd.Parameter; |
0 | 30 import dmd.Expression; |
31 import dmd.RET; | |
32 import dmd.TY; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
33 import dmd.TRUST; |
0 | 34 import dmd.Util; |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
35 import dmd.FuncDeclaration; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
36 import dmd.Dsymbol; |
135 | 37 import dmd.TypeTuple; |
123 | 38 import dmd.TemplateInstance : isTuple; |
0 | 39 |
40 import dmd.backend.TYPE; | |
41 import dmd.backend.PARAM; | |
42 import dmd.backend.Util; | |
43 import dmd.backend.TYM; | |
44 import dmd.backend.TF; | |
45 import dmd.backend.mTY; | |
46 | |
47 import core.stdc.stdlib; | |
48 import core.stdc.string; | |
49 | |
129 | 50 import std.stdio; |
51 | |
0 | 52 class TypeFunction : TypeNext |
53 { | |
54 // .next is the return type | |
55 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
56 Parameters parameters; // function parameters |
0 | 57 int varargs; // 1: T t, ...) style for variable number of arguments |
58 // 2: T t ...) style for variable number of arguments | |
59 bool isnothrow; // true: nothrow | |
60 bool ispure; // true: pure | |
61 bool isproperty; // can be called without parentheses | |
62 bool isref; // true: returns a reference | |
63 LINK linkage; // calling convention | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
64 TRUST trust; // level of trust |
135 | 65 Expressions fargs; // function arguments |
0 | 66 |
67 int inuse; | |
68 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
69 this(Parameters parameters, Type treturn, int varargs, LINK linkage) |
0 | 70 { |
71 super(TY.Tfunction, treturn); | |
72 | |
73 //if (!treturn) *(char*)0=0; | |
74 // assert(treturn); | |
75 assert(0 <= varargs && varargs <= 2); | |
76 this.parameters = parameters; | |
77 this.varargs = varargs; | |
78 this.linkage = linkage; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
79 this.trust = TRUSTdefault; |
0 | 80 } |
81 | |
72 | 82 override Type syntaxCopy() |
0 | 83 { |
84 Type treturn = next ? next.syntaxCopy() : null; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
85 auto params = Parameter.arraySyntaxCopy(parameters); |
0 | 86 TypeFunction t = new TypeFunction(params, treturn, varargs, linkage); |
87 t.mod = mod; | |
88 t.isnothrow = isnothrow; | |
89 t.ispure = ispure; | |
90 t.isproperty = isproperty; | |
91 t.isref = isref; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
92 t.trust = trust; |
135 | 93 t.fargs = fargs; |
0 | 94 |
95 return t; | |
96 } | |
97 | |
98 version (DumbClone) { | |
99 } else { | |
100 final TypeFunction cloneTo(TypeFunction t) | |
101 { | |
102 super.cloneTo(t); | |
103 | |
104 // these 3 should be set by ctor | |
105 assert(t.parameters is null); | |
106 assert(t.varargs == varargs); | |
107 assert(t.linkage == linkage); | |
108 | |
109 t.isnothrow = isnothrow; | |
110 t.ispure = ispure; | |
111 t.isproperty = isproperty; | |
112 t.isref = isref; | |
113 t.inuse = inuse; | |
114 | |
115 if (parameters) | |
116 { | |
117 t.parameters = parameters.copy(); | |
129 | 118 foreach (arg; parameters) |
0 | 119 { |
120 Argument cpy = arg.clone(); | |
129 | 121 t.parameters[i] = cpy; |
0 | 122 } |
123 } | |
124 | |
125 return t; | |
126 } | |
127 | |
128 TypeFunction clone() | |
129 { | |
129 | 130 assert(this.classinfo is TypeFunction.classinfo); |
0 | 131 return cloneTo(new TypeFunction(null, next, varargs, linkage)); |
132 } | |
133 } | |
72 | 134 override Type semantic(Loc loc, Scope sc) |
0 | 135 { |
136 if (deco) // if semantic() already run | |
137 { | |
138 //printf("already done\n"); | |
139 return this; | |
140 } | |
141 //printf("TypeFunction.semantic() this = %p\n", this); | |
135 | 142 //printf("TypeFunction::semantic() %s, sc->stc = %llx, fargs = %p\n", toChars(), sc->stc, fargs); |
0 | 143 |
144 /* Copy in order to not mess up original. | |
145 * This can produce redundant copies if inferring return type, | |
146 * as semantic() will get called again on this. | |
147 */ | |
148 | |
129 | 149 TypeFunction tf = cloneThis(this); |
0 | 150 |
151 if (sc.stc & STC.STCpure) | |
152 tf.ispure = true; | |
153 if (sc.stc & STC.STCnothrow) | |
154 tf.isnothrow = true; | |
155 if (sc.stc & STC.STCref) | |
156 tf.isref = true; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
157 if (sc.stc & STCsafe) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
158 tf.trust = TRUST.TRUSTsafe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
159 if (sc.stc & STCtrusted) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
160 tf.trust = TRUST.TRUSTtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
161 if (sc.stc & STCproperty) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
162 tf.isproperty = true; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
163 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
164 tf.linkage = sc.linkage; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
165 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
166 /* If the parent is @safe, then this function defaults to safe |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
167 * too. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
168 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
169 if (tf.trust == TRUST.TRUSTdefault) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
170 for (Dsymbol p = sc.func; p; p = p.toParent2()) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
171 { FuncDeclaration fd = p.isFuncDeclaration(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
172 if (fd) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
173 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
174 if (fd.isSafe()) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
175 tf.trust = TRUST.TRUSTsafe; // default to @safe |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
176 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
177 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
178 } |
0 | 179 |
135 | 180 bool wildreturn = false; |
0 | 181 if (tf.next) |
182 { | |
183 tf.next = tf.next.semantic(loc,sc); | |
96 | 184 version(SARRAYVALUE) {} else |
185 { | |
0 | 186 if (tf.next.toBasetype().ty == TY.Tsarray) |
129 | 187 { |
188 error(loc, "functions cannot return static array %s", tf.next.toChars()); | |
0 | 189 tf.next = Type.terror; |
190 } | |
96 | 191 } |
0 | 192 if (tf.next.toBasetype().ty == TY.Tfunction) |
129 | 193 { |
194 error(loc, "functions cannot return a function"); | |
0 | 195 tf.next = Type.terror; |
196 } | |
197 if (tf.next.toBasetype().ty == TY.Ttuple) | |
129 | 198 { |
199 error(loc, "functions cannot return a tuple"); | |
0 | 200 tf.next = Type.terror; |
201 } | |
202 if (tf.next.isauto() && !(sc.flags & SCOPE.SCOPEctor)) | |
129 | 203 error(loc, "functions cannot return scope %s", tf.next.toChars()); |
135 | 204 if (tf.next.toBasetype().ty == TY.Tvoid) |
205 tf.isref = false; // rewrite "ref void" as just "void" | |
206 if (tf.next.isWild()) | |
207 wildreturn = true; | |
208 } | |
0 | 209 |
135 | 210 bool wildparams = false; |
211 bool wildsubparams = false; | |
0 | 212 if (tf.parameters) |
73 | 213 { |
214 /* Create a scope for evaluating the default arguments for the parameters | |
215 */ | |
216 Scope argsc = sc.push(); | |
217 argsc.stc = STCundefined; // don't inherit storage class | |
218 argsc.protection = PROT.PROTpublic; | |
219 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
220 size_t dim = Parameter.dim(tf.parameters); |
0 | 221 |
222 for (size_t i = 0; i < dim; i++) | |
135 | 223 { auto fparam = Parameter.getNth(tf.parameters, i); |
0 | 224 |
225 tf.inuse++; | |
135 | 226 fparam.type = fparam.type.semantic(loc, argsc); |
0 | 227 if (tf.inuse == 1) tf.inuse--; |
228 | |
135 | 229 fparam.type = fparam.type.addStorageClass(fparam.storageClass); |
0 | 230 |
135 | 231 if (fparam.storageClass & (STC.STCauto | STC.STCalias | STC.STCstatic)) |
0 | 232 { |
135 | 233 if (!fparam.type) |
0 | 234 continue; |
235 } | |
236 | |
135 | 237 Type t = fparam.type.toBasetype(); |
0 | 238 |
135 | 239 if (fparam.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) |
0 | 240 { |
96 | 241 //if (t.ty == TY.Tsarray) |
242 //error(loc, "cannot have out or ref parameter of type %s", t.toChars()); | |
135 | 243 if (fparam.storageClass & STC.STCout && fparam.type.mod & (STCconst | STCimmutable)) |
96 | 244 error(loc, "cannot have const or immutabl out parameter of type %s", t.toChars()); |
0 | 245 } |
135 | 246 if (!(fparam.storageClass & STC.STClazy) && t.ty == TY.Tvoid) |
247 error(loc, "cannot have parameter of type %s", fparam.type.toChars()); | |
0 | 248 |
135 | 249 if (t.isWild()) |
250 { | |
251 wildparams = true; | |
252 if (tf.next && !wildreturn) | |
253 error(loc, "inout on parameter means inout must be on return type as well (if from D1 code, replace with 'ref')"); | |
254 } | |
255 else if (!wildsubparams && t.hasWild()) | |
256 wildsubparams = true; | |
0 | 257 |
135 | 258 if (fparam.defaultArg) |
259 { | |
260 fparam.defaultArg = fparam.defaultArg.semantic(argsc); | |
261 fparam.defaultArg = resolveProperties(argsc, fparam.defaultArg); | |
262 fparam.defaultArg = fparam.defaultArg.implicitCastTo(argsc, fparam.type); | |
263 } | |
264 | |
265 /* If fparam turns out to be a tuple, the number of parameters may | |
0 | 266 * change. |
267 */ | |
268 if (t.ty == TY.Ttuple) | |
135 | 269 { |
270 // Propagate storage class from tuple parameters to their element-parameters. | |
271 auto tt = cast(TypeTuple)t; | |
272 if (tt.arguments) | |
273 { | |
274 auto tdim = tt.arguments.dim; | |
275 foreach (narg; tt.arguments) | |
276 { | |
277 narg.storageClass = fparam.storageClass; | |
278 } | |
279 } | |
280 | |
281 /* Reset number of parameters, and back up one to do this fparam again, | |
282 * now that it is the first element of a tuple | |
283 */ | |
284 dim = Parameter.dim(tf.parameters); | |
0 | 285 i--; |
135 | 286 continue; |
0 | 287 } |
135 | 288 |
289 /* Resolve "auto ref" storage class to be either ref or value, | |
290 * based on the argument matching the parameter | |
291 */ | |
292 if (fparam.storageClass & STC.STCauto) | |
293 { | |
294 if (fargs && i < fargs.dim) | |
295 { | |
296 auto farg = fargs[i]; | |
297 if (farg.isLvalue()) | |
298 {} // ref parameter | |
299 else | |
300 fparam.storageClass &= ~STC.STCref; // value parameter | |
301 } | |
302 else | |
303 error(loc, "auto can only be used for template function parameters"); | |
304 } | |
0 | 305 } |
73 | 306 argsc.pop(); |
0 | 307 } |
135 | 308 |
309 if (wildreturn && !wildparams) | |
310 error(loc, "inout on return means inout must be on a parameter as well for %s", toChars()); | |
311 if (wildsubparams && wildparams) | |
312 error(loc, "inout must be all or none on top level for %s", toChars()); | |
313 | |
0 | 314 if (tf.next) |
315 tf.deco = tf.merge().deco; | |
316 | |
317 if (tf.inuse) | |
318 { error(loc, "recursive type"); | |
319 tf.inuse = 0; | |
320 return terror; | |
321 } | |
322 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
323 if (tf.isproperty && (tf.varargs || Parameter.dim(tf.parameters) > 1)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
324 error(loc, "properties can only have zero or one parameter"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
325 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
326 if (tf.varargs == 1 && tf.linkage != LINK.LINKd && Parameter.dim(tf.parameters) == 0) |
0 | 327 error(loc, "variadic functions with non-D linkage must have at least one parameter"); |
328 | |
329 /* Don't return merge(), because arg identifiers and default args | |
330 * can be different | |
331 * even though the types match | |
332 */ | |
333 return tf; | |
334 } | |
335 | |
72 | 336 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 337 { |
338 ubyte mc; | |
339 | |
340 //printf("TypeFunction.toDecoBuffer() this = %p %s\n", this, toChars()); | |
341 //static int nest; if (++nest == 50) *(char*)0=0; | |
342 if (inuse) | |
343 { | |
344 inuse = 2; // flag error to caller | |
345 return; | |
346 } | |
347 inuse++; | |
135 | 348 MODtoDecoBuffer(buf, mod); |
0 | 349 switch (linkage) |
350 { | |
351 case LINK.LINKd: mc = 'F'; break; | |
352 case LINK.LINKc: mc = 'U'; break; | |
353 case LINK.LINKwindows: mc = 'W'; break; | |
354 case LINK.LINKpascal: mc = 'V'; break; | |
355 case LINK.LINKcpp: mc = 'R'; break; | |
356 } | |
357 buf.writeByte(mc); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
358 if (ispure || isnothrow || isproperty || isref || trust) |
0 | 359 { |
360 if (ispure) | |
361 buf.writestring("Na"); | |
362 if (isnothrow) | |
363 buf.writestring("Nb"); | |
364 if (isref) | |
365 buf.writestring("Nc"); | |
366 if (isproperty) | |
367 buf.writestring("Nd"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
368 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
369 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
370 case TRUST.TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
371 buf.writestring("Ne"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
372 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
373 case TRUST.TRUSTsafe: |
135 | 374 buf.writestring("Nf"); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
375 break; |
132
c494af1dba80
Fixes for dmd 2.037
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
131
diff
changeset
|
376 default: |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
377 } |
0 | 378 } |
379 // Write argument types | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
380 Parameter.argsToDecoBuffer(buf, parameters); |
0 | 381 //if (buf.data[buf.offset - 1] == '@') halt(); |
382 buf.writeByte('Z' - varargs); // mark end of arg list | |
79 | 383 assert(next); |
0 | 384 next.toDecoBuffer(buf); |
385 inuse--; | |
386 } | |
387 | |
72 | 388 override void toCBuffer(OutBuffer buf, Identifier ident, HdrGenState* hgs) |
0 | 389 { |
390 //printf("TypeFunction.toCBuffer() this = %p\n", this); | |
391 string p = null; | |
392 | |
393 if (inuse) | |
394 { | |
395 inuse = 2; // flag error to caller | |
396 return; | |
397 } | |
398 inuse++; | |
399 | |
400 /* Use 'storage class' style for attributes | |
401 */ | |
135 | 402 if (mod) |
403 { | |
404 MODtoBuffer(buf, mod); | |
405 buf.writeByte(' '); | |
406 } | |
0 | 407 |
408 if (ispure) | |
409 buf.writestring("pure "); | |
410 if (isnothrow) | |
411 buf.writestring("nothrow "); | |
412 if (isproperty) | |
413 buf.writestring("@property "); | |
414 if (isref) | |
415 buf.writestring("ref "); | |
416 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
417 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
418 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
419 case TRUST.TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
420 buf.writestring("@trusted "); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
421 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
422 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
423 case TRUST.TRUSTsafe: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
424 buf.writestring("@safe "); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
425 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
426 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
427 |
0 | 428 if (next && (!ident || ident.toHChars2() == ident.toChars())) |
429 next.toCBuffer2(buf, hgs, MODundefined); | |
430 if (hgs.ddoc != 1) | |
431 { | |
432 switch (linkage) | |
433 { | |
434 case LINKd: p = null; break; | |
73 | 435 case LINKc: p = " C"; break; |
436 case LINKwindows: p = " Windows"; break; | |
437 case LINKpascal: p = " Pascal"; break; | |
438 case LINKcpp: p = " C++"; break; | |
0 | 439 default: |
440 assert(0); | |
441 } | |
442 } | |
443 | |
444 if (!hgs.hdrgen && p) | |
445 buf.writestring(p); | |
446 if (ident) | |
447 { | |
448 buf.writeByte(' '); | |
449 buf.writestring(ident.toHChars2()); | |
450 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
451 Parameter.argsToCBuffer(buf, hgs, parameters, varargs); |
0 | 452 inuse--; |
453 } | |
454 | |
72 | 455 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 456 { |
457 //printf("TypeFunction::toCBuffer2() this = %p, ref = %d\n", this, isref); | |
458 string p; | |
459 | |
460 if (inuse) | |
461 { | |
462 inuse = 2; // flag error to caller | |
463 return; | |
464 } | |
465 | |
466 inuse++; | |
467 if (next) | |
468 next.toCBuffer2(buf, hgs, MODundefined); | |
469 | |
470 if (hgs.ddoc != 1) | |
471 { | |
472 switch (linkage) | |
473 { | |
474 case LINKd: p = null; break; | |
475 case LINKc: p = "C "; break; | |
476 case LINKwindows: p = "Windows "; break; | |
477 case LINKpascal: p = "Pascal "; break; | |
478 case LINKcpp: p = "C++ "; break; | |
479 default: assert(0); | |
480 } | |
481 } | |
482 | |
483 if (!hgs.hdrgen && p) | |
484 buf.writestring(p); | |
485 buf.writestring(" function"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
486 Parameter.argsToCBuffer(buf, hgs, parameters, varargs); |
0 | 487 |
488 /* Use postfix style for attributes | |
489 */ | |
490 if (mod != this.mod) | |
491 { | |
492 modToBuffer(buf); | |
493 } | |
494 | |
495 if (ispure) | |
496 buf.writestring(" pure"); | |
497 if (isnothrow) | |
498 buf.writestring(" nothrow"); | |
499 if (isproperty) | |
500 buf.writestring(" @property"); | |
501 if (isref) | |
502 buf.writestring(" ref"); | |
503 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
504 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
505 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
506 case TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
507 buf.writestring(" @trusted"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
508 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
509 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
510 case TRUSTsafe: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
511 buf.writestring(" @safe"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
512 break; |
143 | 513 |
514 default: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
515 } |
0 | 516 inuse--; |
517 } | |
518 | |
72 | 519 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 520 { |
123 | 521 //printf("TypeFunction.deduceType()\n"); |
522 //printf("\tthis = %d, ", ty); print(); | |
523 //printf("\ttparam = %d, ", tparam.ty); tparam.print(); | |
524 | |
525 // Extra check that function characteristics must match | |
526 if (tparam && tparam.ty == Tfunction) | |
527 { | |
528 TypeFunction tp = cast(TypeFunction)tparam; | |
529 if (varargs != tp.varargs || | |
530 linkage != tp.linkage) | |
531 return MATCHnomatch; | |
532 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
533 size_t nfargs = Parameter.dim(this.parameters); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
534 size_t nfparams = Parameter.dim(tp.parameters); |
123 | 535 |
536 /* See if tuple match | |
537 */ | |
538 if (nfparams > 0 && nfargs >= nfparams - 1) | |
539 { | |
540 /* See if 'A' of the template parameter matches 'A' | |
541 * of the type of the last function parameter. | |
542 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
543 auto fparam = Parameter.getNth(tp.parameters, nfparams - 1); |
123 | 544 assert(fparam); |
545 assert(fparam.type); | |
546 if (fparam.type.ty != Tident) | |
547 goto L1; | |
548 TypeIdentifier tid = cast(TypeIdentifier)fparam.type; | |
549 if (tid.idents.dim) | |
550 goto L1; | |
551 | |
552 /* Look through parameters to find tuple matching tid.ident | |
553 */ | |
554 size_t tupi = 0; | |
555 for (; 1; tupi++) | |
556 { | |
557 if (tupi == parameters.dim) | |
558 goto L1; | |
559 TemplateParameter t = parameters[tupi]; | |
560 TemplateTupleParameter tup = t.isTemplateTupleParameter(); | |
561 if (tup && tup.ident.equals(tid.ident)) | |
562 break; | |
563 } | |
564 | |
565 /* The types of the function arguments [nfparams - 1 .. nfargs] | |
566 * now form the tuple argument. | |
567 */ | |
568 int tuple_dim = nfargs - (nfparams - 1); | |
569 | |
570 /* See if existing tuple, and whether it matches or not | |
571 */ | |
572 Object o = dedtypes[tupi]; | |
573 if (o) | |
574 { | |
575 // Existing deduced argument must be a tuple, and must match | |
576 Tuple t = isTuple(o); | |
577 if (!t || t.objects.dim != tuple_dim) | |
578 return MATCHnomatch; | |
579 for (size_t i = 0; i < tuple_dim; i++) | |
580 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
581 auto arg = Parameter.getNth(this.parameters, nfparams - 1 + i); |
123 | 582 if (!arg.type.equals(t.objects[i])) |
583 return MATCHnomatch; | |
584 } | |
585 } | |
586 else | |
587 { // Create new tuple | |
588 Tuple t = new Tuple(); | |
589 t.objects.setDim(tuple_dim); | |
590 for (size_t i = 0; i < tuple_dim; i++) | |
591 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
592 auto arg = Parameter.getNth(this.parameters, nfparams - 1 + i); |
123 | 593 t.objects[i] = arg.type; |
594 } | |
595 dedtypes[tupi] = t; | |
596 } | |
597 nfparams--; // don't consider the last parameter for type deduction | |
598 goto L2; | |
599 } | |
600 | |
601 L1: | |
602 if (nfargs != nfparams) | |
603 return MATCHnomatch; | |
604 L2: | |
605 for (size_t i = 0; i < nfparams; i++) | |
606 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
607 auto a = Parameter.getNth(this.parameters, i); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
608 auto ap = Parameter.getNth(tp.parameters, i); |
123 | 609 if (a.storageClass != ap.storageClass || |
610 !a.type.deduceType(sc, ap.type, parameters, dedtypes)) | |
611 return MATCHnomatch; | |
612 } | |
613 } | |
614 return Type.deduceType(sc, tparam, parameters, dedtypes); | |
0 | 615 } |
616 | |
72 | 617 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 618 { |
129 | 619 return new TypeInfoFunctionDeclaration(this); |
0 | 620 } |
621 | |
72 | 622 override Type reliesOnTident() |
0 | 623 { |
135 | 624 size_t dim = Parameter.dim(parameters); |
625 for (size_t i = 0; i < dim; i++) | |
626 { | |
627 auto fparam = Parameter.getNth(parameters, i); | |
628 Type t = fparam.type.reliesOnTident(); | |
629 if (t) | |
630 return t; | |
631 } | |
632 return next ? next.reliesOnTident() : null; | |
0 | 633 } |
634 | |
635 version (CPP_MANGLE) { | |
636 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
637 { | |
638 assert(false); | |
639 } | |
640 } | |
641 | |
642 /*************************** | |
643 * Examine function signature for parameter p and see if | |
644 * p can 'escape' the scope of the function. | |
645 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
646 bool parameterEscapes(Parameter p) |
0 | 647 { |
648 /* Scope parameters do not escape. | |
649 * Allow 'lazy' to imply 'scope' - | |
650 * lazy parameters can be passed along | |
651 * as lazy parameters to the next function, but that isn't | |
652 * escaping. | |
653 */ | |
654 if (p.storageClass & (STC.STCscope | STC.STClazy)) | |
655 return false; | |
656 | |
657 if (ispure) | |
658 { /* With pure functions, we need only be concerned if p escapes | |
659 * via any return statement. | |
660 */ | |
661 Type tret = nextOf().toBasetype(); | |
662 if (!isref && !tret.hasPointers()) | |
663 { /* The result has no references, so p could not be escaping | |
664 * that way. | |
665 */ | |
666 return false; | |
667 } | |
668 } | |
669 | |
670 /* Assume it escapes in the absence of better information. | |
671 */ | |
672 return true; | |
673 } | |
674 | |
675 /******************************** | |
676 * 'args' are being matched to function 'this' | |
677 * Determine match level. | |
678 * Returns: | |
679 * MATCHxxxx | |
680 */ | |
681 MATCH callMatch(Expression ethis, Expressions args) | |
682 { | |
683 //printf("TypeFunction.callMatch() %s\n", toChars()); | |
684 MATCH match = MATCH.MATCHexact; // assume exact match | |
135 | 685 bool exactwildmatch = false; |
686 bool wildmatch = false; | |
0 | 687 |
688 if (ethis) | |
689 { | |
690 Type t = ethis.type; | |
691 if (t.toBasetype().ty == TY.Tpointer) | |
692 t = t.toBasetype().nextOf(); // change struct* to struct | |
693 | |
694 if (t.mod != mod) | |
695 { | |
135 | 696 if (MODimplicitConv(t.mod, mod)) |
0 | 697 match = MATCH.MATCHconst; |
698 else | |
699 return MATCH.MATCHnomatch; | |
700 } | |
701 } | |
702 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
703 size_t nparams = Parameter.dim(parameters); |
0 | 704 size_t nargs = args ? args.dim : 0; |
705 if (nparams == nargs) { | |
706 ; | |
707 } else if (nargs > nparams) | |
708 { | |
709 if (varargs == 0) | |
710 goto Nomatch; // too many args; no match | |
711 match = MATCH.MATCHconvert; // match ... with a "conversion" match level | |
712 } | |
713 | |
714 for (size_t u = 0; u < nparams; u++) | |
715 { | |
716 MATCH m; | |
717 Expression arg; | |
718 | |
719 // BUG: what about out and ref? | |
720 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
721 auto p = Parameter.getNth(parameters, u); |
0 | 722 assert(p); |
723 if (u >= nargs) | |
724 { | |
725 if (p.defaultArg) | |
726 continue; | |
727 if (varargs == 2 && u + 1 == nparams) | |
728 goto L1; | |
729 goto Nomatch; // not enough arguments | |
730 } | |
731 | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
96
diff
changeset
|
732 arg = cast(Expression)args[u]; |
0 | 733 assert(arg); |
96 | 734 // writef("arg: %s, type: %s\n", arg.toChars(), arg.type.toChars()); |
735 | |
0 | 736 |
737 // Non-lvalues do not match ref or out parameters | |
96 | 738 if (p.storageClass & (STC.STCref | STC.STCout)) |
739 { | |
740 if (!arg.isLvalue()) | |
741 goto Nomatch; | |
742 } | |
743 | |
744 if (p.storageClass & STCref) | |
745 { | |
135 | 746 /* Don't allow static arrays to be passed to mutable references |
96 | 747 * to static arrays if the argument cannot be modified. |
748 */ | |
749 Type targb = arg.type.toBasetype(); | |
750 Type tparb = p.type.toBasetype(); | |
751 //writef("%s\n", targb.toChars()); | |
752 //writef("%s\n", tparb.toChars()); | |
753 if (targb.nextOf() && tparb.ty == Tsarray && | |
135 | 754 !MODimplicitConv(targb.nextOf().mod, tparb.nextOf().mod)) |
96 | 755 goto Nomatch; |
756 } | |
0 | 757 |
758 if (p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid && arg.type.ty != TY.Tvoid) | |
759 m = MATCH.MATCHconvert; | |
760 else | |
135 | 761 { |
0 | 762 m = arg.implicitConvTo(p.type); |
135 | 763 if (p.type.isWild()) |
764 { | |
765 if (m == MATCHnomatch) | |
766 { | |
767 m = arg.implicitConvTo(p.type.constOf()); | |
768 if (m == MATCHnomatch) | |
769 m = arg.implicitConvTo(p.type.sharedConstOf()); | |
770 if (m != MATCHnomatch) | |
771 wildmatch = true; // mod matched to wild | |
772 } | |
773 else | |
774 exactwildmatch = true; // wild matched to wild | |
775 | |
776 /* If both are allowed, then there could be more than one | |
777 * binding of mod to wild, leaving a gaping type hole. | |
778 */ | |
779 if (wildmatch && exactwildmatch) | |
780 m = MATCHnomatch; | |
781 } | |
782 } | |
783 | |
0 | 784 //printf("\tm = %d\n", m); |
785 if (m == MATCH.MATCHnomatch) // if no match | |
786 { | |
787 L1: | |
788 if (varargs == 2 && u + 1 == nparams) // if last varargs param | |
789 { | |
790 Type tb = p.type.toBasetype(); | |
791 TypeSArray tsa; | |
792 long sz; | |
793 | |
794 switch (tb.ty) | |
795 { | |
796 case TY.Tsarray: | |
797 tsa = cast(TypeSArray)tb; | |
798 sz = tsa.dim.toInteger(); | |
799 if (sz != nargs - u) | |
800 goto Nomatch; | |
801 case TY.Tarray: | |
802 { | |
803 TypeArray ta = cast(TypeArray)tb; | |
804 for (; u < nargs; u++) | |
805 { | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
96
diff
changeset
|
806 arg = cast(Expression)args[u]; |
0 | 807 assert(arg); |
808 static if (true) { | |
809 /* If lazy array of delegates, | |
810 * convert arg(s) to delegate(s) | |
811 */ | |
812 Type tret = p.isLazyArray(); | |
813 if (tret) | |
814 { | |
815 if (ta.next.equals(arg.type)) | |
816 { | |
817 m = MATCH.MATCHexact; | |
818 } | |
819 else | |
820 { | |
821 m = arg.implicitConvTo(tret); | |
822 if (m == MATCH.MATCHnomatch) | |
823 { | |
824 if (tret.toBasetype().ty == TY.Tvoid) | |
825 m = MATCH.MATCHconvert; | |
826 } | |
827 } | |
828 } | |
829 else | |
830 m = arg.implicitConvTo(ta.next); | |
831 } else { | |
832 m = arg.implicitConvTo(ta.next); | |
833 } | |
834 if (m == MATCH.MATCHnomatch) | |
835 goto Nomatch; | |
836 | |
837 if (m < match) | |
838 match = m; | |
839 } | |
840 goto Ldone; | |
841 } | |
842 | |
843 case TY.Tclass: | |
844 // Should see if there's a constructor match? | |
845 // Or just leave it ambiguous? | |
846 goto Ldone; | |
847 | |
848 default: | |
849 goto Nomatch; | |
850 } | |
851 } | |
852 | |
853 goto Nomatch; | |
854 } | |
855 | |
856 if (m < match) | |
857 match = m; // pick worst match | |
858 } | |
859 | |
860 Ldone: | |
861 //printf("match = %d\n", match); | |
862 return match; | |
863 | |
864 Nomatch: | |
865 //printf("no match\n"); | |
866 return MATCH.MATCHnomatch; | |
867 } | |
868 | |
96 | 869 override type* toCtype() |
0 | 870 { |
871 if (ctype) { | |
872 return ctype; | |
873 } | |
874 | |
875 type* t; | |
876 if (true) | |
877 { | |
878 param_t* paramtypes; | |
879 tym_t tyf; | |
880 type* tp; | |
881 | |
882 paramtypes = null; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
883 size_t nparams = Parameter.dim(parameters); |
0 | 884 for (size_t i = 0; i < nparams; i++) |
885 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
886 auto arg = Parameter.getNth(parameters, i); |
0 | 887 tp = arg.type.toCtype(); |
888 if (arg.storageClass & (STC.STCout | STC.STCref)) | |
889 { | |
890 // C doesn't have reference types, so it's really a pointer | |
891 // to the parameter type | |
892 tp = type_allocn(TYM.TYref, tp); | |
893 } | |
894 param_append_type(¶mtypes,tp); | |
895 } | |
896 tyf = totym(); | |
897 t = type_alloc(tyf); | |
898 t.Tflags |= TF.TFprototype; | |
899 if (varargs != 1) | |
900 t.Tflags |= TF.TFfixed; | |
901 ctype = t; | |
902 t.Tnext = next.toCtype(); | |
903 t.Tnext.Tcount++; | |
904 t.Tparamtypes = paramtypes; | |
905 } | |
906 ctype = t; | |
907 return t; | |
908 } | |
909 | |
910 /*************************** | |
911 * Determine return style of function - whether in registers or | |
912 * through a hidden pointer to the caller's stack. | |
913 */ | |
96 | 914 RET retStyle() |
0 | 915 { |
916 //printf("TypeFunction.retStyle() %s\n", toChars()); | |
95 | 917 version (DMDV2) |
918 { | |
0 | 919 if (isref) |
920 return RET.RETregs; // returns a pointer | |
921 } | |
922 | |
923 Type tn = next.toBasetype(); | |
95 | 924 Type tns = tn; |
925 ulong sz = tn.size(); | |
0 | 926 |
95 | 927 version(SARRAYVALUE) |
928 { | |
929 if (tn.ty == Tsarray) | |
930 { | |
931 do | |
932 { | |
933 tns = tns.nextOf().toBasetype(); | |
934 } while (tns.ty == Tsarray); | |
935 if (tns.ty != Tstruct) | |
936 { | |
937 if (global.params.isLinux && linkage != LINKd) | |
938 {} | |
939 else | |
940 { | |
941 switch (sz) | |
942 { case 1: | |
943 case 2: | |
944 case 4: | |
945 case 8: | |
96 | 946 return RET.RETregs; // return small structs in regs |
947 // (not 3 byte structs!) | |
95 | 948 default: |
949 break; | |
950 } | |
951 } | |
96 | 952 return RET.RETstack; |
95 | 953 } |
954 } | |
955 } | |
956 if (tns.ty == TY.Tstruct) | |
0 | 957 { |
958 StructDeclaration sd = (cast(TypeStruct)tn).sym; | |
959 if (global.params.isLinux && linkage != LINK.LINKd) { | |
960 ; | |
961 } | |
95 | 962 ///version (DMDV2) { // TODO: |
963 else if (sd.dtor || sd.cpctor) | |
964 { | |
0 | 965 } |
966 ///} | |
967 else | |
968 { | |
95 | 969 switch (sz) |
0 | 970 { |
971 case 1: | |
972 case 2: | |
973 case 4: | |
974 case 8: | |
975 return RET.RETregs; // return small structs in regs | |
976 // (not 3 byte structs!) | |
977 default: | |
978 break; | |
979 } | |
980 } | |
981 return RET.RETstack; | |
982 } | |
983 else if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && | |
984 linkage == LINK.LINKc && | |
985 tn.iscomplex()) | |
986 { | |
987 if (tn.ty == TY.Tcomplex32) | |
988 return RET.RETregs; // in EDX:EAX, not ST1:ST0 | |
989 else | |
990 return RET.RETstack; | |
991 } | |
992 else | |
993 return RET.RETregs; | |
994 } | |
995 | |
72 | 996 override TYM totym() |
0 | 997 { |
998 TYM tyf; | |
999 | |
1000 //printf("TypeFunction.totym(), linkage = %d\n", linkage); | |
1001 switch (linkage) | |
1002 { | |
1003 case LINK.LINKwindows: | |
1004 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnsfunc; | |
1005 break; | |
1006 | |
1007 case LINK.LINKpascal: | |
1008 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnpfunc; | |
1009 break; | |
1010 | |
1011 case LINK.LINKc: | |
1012 tyf = TYM.TYnfunc; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
1013 version (POSIX) {///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 1014 if (retStyle() == RET.RETstack) |
1015 tyf = TYM.TYhfunc; | |
1016 } | |
1017 break; | |
1018 | |
1019 case LINK.LINKd: | |
1020 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYjfunc; | |
1021 break; | |
1022 | |
1023 case LINK.LINKcpp: | |
1024 tyf = TYM.TYnfunc; | |
1025 break; | |
1026 | |
1027 default: | |
1028 writef("linkage = %d\n", linkage); | |
1029 assert(0); | |
1030 } | |
1031 version (DMDV2) { | |
1032 if (isnothrow) | |
1033 tyf |= mTY.mTYnothrow; | |
1034 } | |
1035 return tyf; | |
1036 } | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
1037 } |