Mercurial > projects > ddmd
annotate dmd/TypeFunction.d @ 73:ef02e2e203c2
Updating to dmd2.033
author | korDen |
---|---|
date | Sat, 28 Aug 2010 19:42:41 +0400 |
parents | 2e2a5c3f943a |
children | 43073c7c7769 |
rev | line source |
---|---|
0 | 1 module dmd.TypeFunction; |
2 | |
3 import dmd.TypeNext; | |
4 import dmd.TypeSArray; | |
5 import dmd.TypeArray; | |
6 import dmd.ArrayTypes; | |
7 import dmd.LINK; | |
8 import dmd.StructDeclaration; | |
9 import dmd.TypeStruct; | |
10 import dmd.Global; | |
11 import dmd.STC; | |
12 import dmd.MOD; | |
73 | 13 import dmd.PROT; |
0 | 14 import dmd.Type; |
15 import dmd.Loc; | |
16 import dmd.Scope; | |
17 import dmd.Identifier; | |
18 import dmd.OutBuffer; | |
19 import dmd.HdrGenState; | |
20 import dmd.CppMangleState; | |
21 import dmd.TypeInfoDeclaration; | |
22 import dmd.MATCH; | |
23 import dmd.Argument; | |
24 import dmd.Expression; | |
25 import dmd.RET; | |
26 import dmd.TY; | |
27 import dmd.Util; | |
28 | |
29 import dmd.backend.TYPE; | |
30 import dmd.backend.PARAM; | |
31 import dmd.backend.Util; | |
32 import dmd.backend.TYM; | |
33 import dmd.backend.TF; | |
34 import dmd.backend.mTY; | |
35 | |
36 import core.stdc.stdlib; | |
37 import core.stdc.string; | |
38 | |
39 class TypeFunction : TypeNext | |
40 { | |
41 // .next is the return type | |
42 | |
43 Arguments parameters; // function parameters | |
44 int varargs; // 1: T t, ...) style for variable number of arguments | |
45 // 2: T t ...) style for variable number of arguments | |
46 bool isnothrow; // true: nothrow | |
47 bool ispure; // true: pure | |
48 bool isproperty; // can be called without parentheses | |
49 bool isref; // true: returns a reference | |
50 LINK linkage; // calling convention | |
51 | |
52 int inuse; | |
53 | |
54 this(Arguments parameters, Type treturn, int varargs, LINK linkage) | |
55 { | |
56 super(TY.Tfunction, treturn); | |
57 | |
58 //if (!treturn) *(char*)0=0; | |
59 // assert(treturn); | |
60 assert(0 <= varargs && varargs <= 2); | |
61 this.parameters = parameters; | |
62 this.varargs = varargs; | |
63 this.linkage = linkage; | |
64 } | |
65 | |
72 | 66 override Type syntaxCopy() |
0 | 67 { |
68 Type treturn = next ? next.syntaxCopy() : null; | |
69 Arguments params = Argument.arraySyntaxCopy(parameters); | |
70 TypeFunction t = new TypeFunction(params, treturn, varargs, linkage); | |
71 t.mod = mod; | |
72 t.isnothrow = isnothrow; | |
73 t.ispure = ispure; | |
74 t.isproperty = isproperty; | |
75 t.isref = isref; | |
76 | |
77 return t; | |
78 } | |
79 | |
80 version (DumbClone) { | |
81 } else { | |
82 final TypeFunction cloneTo(TypeFunction t) | |
83 { | |
84 super.cloneTo(t); | |
85 | |
86 // these 3 should be set by ctor | |
87 assert(t.parameters is null); | |
88 assert(t.varargs == varargs); | |
89 assert(t.linkage == linkage); | |
90 | |
91 t.isnothrow = isnothrow; | |
92 t.ispure = ispure; | |
93 t.isproperty = isproperty; | |
94 t.isref = isref; | |
95 t.inuse = inuse; | |
96 | |
97 if (parameters) | |
98 { | |
99 t.parameters = parameters.copy(); | |
100 for (size_t i = 0; i < parameters.dim; i++) | |
101 { | |
102 Argument arg = cast(Argument)parameters.data[i]; | |
103 Argument cpy = arg.clone(); | |
104 t.parameters.data[i] = cast(void*)cpy; | |
105 } | |
106 } | |
107 | |
108 return t; | |
109 } | |
110 | |
111 TypeFunction clone() | |
112 { | |
113 assert(this.classinfo == TypeFunction.classinfo); | |
114 return cloneTo(new TypeFunction(null, next, varargs, linkage)); | |
115 } | |
116 } | |
72 | 117 override Type semantic(Loc loc, Scope sc) |
0 | 118 { |
119 if (deco) // if semantic() already run | |
120 { | |
121 //printf("already done\n"); | |
122 return this; | |
123 } | |
124 //printf("TypeFunction.semantic() this = %p\n", this); | |
125 //printf("TypeFunction.semantic() %s, sc.stc = %x\n", toChars(), sc.stc); | |
126 | |
127 /* Copy in order to not mess up original. | |
128 * This can produce redundant copies if inferring return type, | |
129 * as semantic() will get called again on this. | |
130 */ | |
131 | |
132 TypeFunction tf = cast(TypeFunction)clone(); | |
133 | |
134 if (sc.stc & STC.STCpure) | |
135 tf.ispure = true; | |
136 if (sc.stc & STC.STCnothrow) | |
137 tf.isnothrow = true; | |
138 if (sc.stc & STC.STCref) | |
139 tf.isref = true; | |
140 | |
141 tf.linkage = sc.linkage; | |
142 if (tf.next) | |
143 { | |
144 tf.next = tf.next.semantic(loc,sc); | |
145 if (tf.next.toBasetype().ty == TY.Tsarray) | |
146 { error(loc, "functions cannot return static array %s", tf.next.toChars()); | |
147 tf.next = Type.terror; | |
148 } | |
149 if (tf.next.toBasetype().ty == TY.Tfunction) | |
150 { error(loc, "functions cannot return a function"); | |
151 tf.next = Type.terror; | |
152 } | |
153 if (tf.next.toBasetype().ty == TY.Ttuple) | |
154 { error(loc, "functions cannot return a tuple"); | |
155 tf.next = Type.terror; | |
156 } | |
157 if (tf.next.isauto() && !(sc.flags & SCOPE.SCOPEctor)) | |
158 error(loc, "functions cannot return scope %s", tf.next.toChars()); | |
159 } | |
160 | |
161 if (tf.parameters) | |
73 | 162 { |
163 /* Create a scope for evaluating the default arguments for the parameters | |
164 */ | |
165 Scope argsc = sc.push(); | |
166 argsc.stc = STCundefined; // don't inherit storage class | |
167 argsc.protection = PROT.PROTpublic; | |
168 | |
169 size_t dim = Argument.dim(tf.parameters); | |
0 | 170 |
171 for (size_t i = 0; i < dim; i++) | |
172 { Argument arg = Argument.getNth(tf.parameters, i); | |
173 | |
174 tf.inuse++; | |
73 | 175 arg.type = arg.type.semantic(loc, argsc); |
0 | 176 if (tf.inuse == 1) tf.inuse--; |
177 | |
178 arg.type = arg.type.addStorageClass(arg.storageClass); | |
179 | |
180 if (arg.storageClass & (STC.STCauto | STC.STCalias | STC.STCstatic)) | |
181 { | |
182 if (!arg.type) | |
183 continue; | |
184 } | |
185 | |
186 Type t = arg.type.toBasetype(); | |
187 | |
188 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) | |
189 { | |
190 if (t.ty == TY.Tsarray) | |
191 error(loc, "cannot have out or ref parameter of type %s", t.toChars()); | |
192 if (arg.storageClass & STC.STCout && arg.type.mod) | |
193 error(loc, "cannot have const/invariant out parameter of type %s", t.toChars()); | |
194 } | |
195 if (!(arg.storageClass & STC.STClazy) && t.ty == TY.Tvoid) | |
196 error(loc, "cannot have parameter of type %s", arg.type.toChars()); | |
197 | |
198 if (arg.defaultArg) | |
199 { | |
73 | 200 arg.defaultArg = arg.defaultArg.semantic(argsc); |
201 arg.defaultArg = resolveProperties(argsc, arg.defaultArg); | |
202 arg.defaultArg = arg.defaultArg.implicitCastTo(argsc, arg.type); | |
0 | 203 } |
204 | |
205 /* If arg turns out to be a tuple, the number of parameters may | |
206 * change. | |
207 */ | |
208 if (t.ty == TY.Ttuple) | |
209 { dim = Argument.dim(tf.parameters); | |
210 i--; | |
211 } | |
212 } | |
73 | 213 argsc.pop(); |
0 | 214 } |
215 if (tf.next) | |
216 tf.deco = tf.merge().deco; | |
217 | |
218 if (tf.inuse) | |
219 { error(loc, "recursive type"); | |
220 tf.inuse = 0; | |
221 return terror; | |
222 } | |
223 | |
224 if (tf.varargs == 1 && tf.linkage != LINK.LINKd && Argument.dim(tf.parameters) == 0) | |
225 error(loc, "variadic functions with non-D linkage must have at least one parameter"); | |
226 | |
227 /* Don't return merge(), because arg identifiers and default args | |
228 * can be different | |
229 * even though the types match | |
230 */ | |
231 return tf; | |
232 } | |
233 | |
72 | 234 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 235 { |
236 ubyte mc; | |
237 | |
238 //printf("TypeFunction.toDecoBuffer() this = %p %s\n", this, toChars()); | |
239 //static int nest; if (++nest == 50) *(char*)0=0; | |
240 if (inuse) | |
241 { | |
242 inuse = 2; // flag error to caller | |
243 return; | |
244 } | |
245 inuse++; | |
246 static if (true) { | |
247 if (mod & MOD.MODshared) | |
248 buf.writeByte('O'); | |
249 if (mod & MOD.MODconst) | |
250 buf.writeByte('x'); | |
251 else if (mod & MOD.MODinvariant) | |
252 buf.writeByte('y'); | |
253 } | |
254 switch (linkage) | |
255 { | |
256 case LINK.LINKd: mc = 'F'; break; | |
257 case LINK.LINKc: mc = 'U'; break; | |
258 case LINK.LINKwindows: mc = 'W'; break; | |
259 case LINK.LINKpascal: mc = 'V'; break; | |
260 case LINK.LINKcpp: mc = 'R'; break; | |
261 } | |
262 buf.writeByte(mc); | |
263 if (ispure || isnothrow || isproperty || isref) | |
264 { | |
265 if (ispure) | |
266 buf.writestring("Na"); | |
267 if (isnothrow) | |
268 buf.writestring("Nb"); | |
269 if (isref) | |
270 buf.writestring("Nc"); | |
271 if (isproperty) | |
272 buf.writestring("Nd"); | |
273 } | |
274 // Write argument types | |
275 Argument.argsToDecoBuffer(buf, parameters); | |
276 //if (buf.data[buf.offset - 1] == '@') halt(); | |
277 buf.writeByte('Z' - varargs); // mark end of arg list | |
278 next.toDecoBuffer(buf); | |
279 inuse--; | |
280 } | |
281 | |
72 | 282 override void toCBuffer(OutBuffer buf, Identifier ident, HdrGenState* hgs) |
0 | 283 { |
284 //printf("TypeFunction.toCBuffer() this = %p\n", this); | |
285 string p = null; | |
286 | |
287 if (inuse) | |
288 { | |
289 inuse = 2; // flag error to caller | |
290 return; | |
291 } | |
292 inuse++; | |
293 | |
294 /* Use 'storage class' style for attributes | |
295 */ | |
296 if (mod & MODconst) | |
297 buf.writestring("const "); | |
298 if (mod & MODinvariant) | |
299 buf.writestring("immutable "); | |
300 if (mod & MODshared) | |
301 buf.writestring("shared "); | |
302 | |
303 if (ispure) | |
304 buf.writestring("pure "); | |
305 if (isnothrow) | |
306 buf.writestring("nothrow "); | |
307 if (isproperty) | |
308 buf.writestring("@property "); | |
309 if (isref) | |
310 buf.writestring("ref "); | |
311 | |
312 if (next && (!ident || ident.toHChars2() == ident.toChars())) | |
313 next.toCBuffer2(buf, hgs, MODundefined); | |
314 if (hgs.ddoc != 1) | |
315 { | |
316 switch (linkage) | |
317 { | |
318 case LINKd: p = null; break; | |
73 | 319 case LINKc: p = " C"; break; |
320 case LINKwindows: p = " Windows"; break; | |
321 case LINKpascal: p = " Pascal"; break; | |
322 case LINKcpp: p = " C++"; break; | |
0 | 323 default: |
324 assert(0); | |
325 } | |
326 } | |
327 | |
328 if (!hgs.hdrgen && p) | |
329 buf.writestring(p); | |
330 if (ident) | |
331 { | |
332 buf.writeByte(' '); | |
333 buf.writestring(ident.toHChars2()); | |
334 } | |
335 Argument.argsToCBuffer(buf, hgs, parameters, varargs); | |
336 inuse--; | |
337 } | |
338 | |
72 | 339 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 340 { |
341 //printf("TypeFunction::toCBuffer2() this = %p, ref = %d\n", this, isref); | |
342 string p; | |
343 | |
344 if (inuse) | |
345 { | |
346 inuse = 2; // flag error to caller | |
347 return; | |
348 } | |
349 | |
350 inuse++; | |
351 if (next) | |
352 next.toCBuffer2(buf, hgs, MODundefined); | |
353 | |
354 if (hgs.ddoc != 1) | |
355 { | |
356 switch (linkage) | |
357 { | |
358 case LINKd: p = null; break; | |
359 case LINKc: p = "C "; break; | |
360 case LINKwindows: p = "Windows "; break; | |
361 case LINKpascal: p = "Pascal "; break; | |
362 case LINKcpp: p = "C++ "; break; | |
363 default: assert(0); | |
364 } | |
365 } | |
366 | |
367 if (!hgs.hdrgen && p) | |
368 buf.writestring(p); | |
369 buf.writestring(" function"); | |
370 Argument.argsToCBuffer(buf, hgs, parameters, varargs); | |
371 | |
372 /* Use postfix style for attributes | |
373 */ | |
374 if (mod != this.mod) | |
375 { | |
376 modToBuffer(buf); | |
377 } | |
378 | |
379 if (ispure) | |
380 buf.writestring(" pure"); | |
381 if (isnothrow) | |
382 buf.writestring(" nothrow"); | |
383 if (isproperty) | |
384 buf.writestring(" @property"); | |
385 if (isref) | |
386 buf.writestring(" ref"); | |
387 | |
388 inuse--; | |
389 } | |
390 | |
72 | 391 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 392 { |
393 assert(false); | |
394 } | |
395 | |
72 | 396 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 397 { |
398 assert(false); | |
399 } | |
400 | |
72 | 401 override Type reliesOnTident() |
0 | 402 { |
403 if (parameters) | |
404 { | |
405 for (size_t i = 0; i < parameters.dim; i++) | |
406 { | |
407 Argument arg = cast(Argument)parameters.data[i]; | |
408 Type t = arg.type.reliesOnTident(); | |
409 if (t) | |
410 return t; | |
411 } | |
412 } | |
413 return next.reliesOnTident(); | |
414 } | |
415 | |
416 version (CPP_MANGLE) { | |
417 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
418 { | |
419 assert(false); | |
420 } | |
421 } | |
422 | |
423 /*************************** | |
424 * Examine function signature for parameter p and see if | |
425 * p can 'escape' the scope of the function. | |
426 */ | |
427 bool parameterEscapes(Argument p) | |
428 { | |
429 /* Scope parameters do not escape. | |
430 * Allow 'lazy' to imply 'scope' - | |
431 * lazy parameters can be passed along | |
432 * as lazy parameters to the next function, but that isn't | |
433 * escaping. | |
434 */ | |
435 if (p.storageClass & (STC.STCscope | STC.STClazy)) | |
436 return false; | |
437 | |
438 if (ispure) | |
439 { /* With pure functions, we need only be concerned if p escapes | |
440 * via any return statement. | |
441 */ | |
442 Type tret = nextOf().toBasetype(); | |
443 if (!isref && !tret.hasPointers()) | |
444 { /* The result has no references, so p could not be escaping | |
445 * that way. | |
446 */ | |
447 return false; | |
448 } | |
449 } | |
450 | |
451 /* Assume it escapes in the absence of better information. | |
452 */ | |
453 return true; | |
454 } | |
455 | |
456 /******************************** | |
457 * 'args' are being matched to function 'this' | |
458 * Determine match level. | |
459 * Returns: | |
460 * MATCHxxxx | |
461 */ | |
462 MATCH callMatch(Expression ethis, Expressions args) | |
463 { | |
464 //printf("TypeFunction.callMatch() %s\n", toChars()); | |
465 MATCH match = MATCH.MATCHexact; // assume exact match | |
466 | |
467 if (ethis) | |
468 { | |
469 Type t = ethis.type; | |
470 if (t.toBasetype().ty == TY.Tpointer) | |
471 t = t.toBasetype().nextOf(); // change struct* to struct | |
472 | |
473 if (t.mod != mod) | |
474 { | |
475 if (mod == MOD.MODconst) | |
476 match = MATCH.MATCHconst; | |
477 else | |
478 return MATCH.MATCHnomatch; | |
479 } | |
480 } | |
481 | |
482 size_t nparams = Argument.dim(parameters); | |
483 size_t nargs = args ? args.dim : 0; | |
484 if (nparams == nargs) { | |
485 ; | |
486 } else if (nargs > nparams) | |
487 { | |
488 if (varargs == 0) | |
489 goto Nomatch; // too many args; no match | |
490 match = MATCH.MATCHconvert; // match ... with a "conversion" match level | |
491 } | |
492 | |
493 for (size_t u = 0; u < nparams; u++) | |
494 { | |
495 MATCH m; | |
496 Expression arg; | |
497 | |
498 // BUG: what about out and ref? | |
499 | |
500 Argument p = Argument.getNth(parameters, u); | |
501 assert(p); | |
502 if (u >= nargs) | |
503 { | |
504 if (p.defaultArg) | |
505 continue; | |
506 if (varargs == 2 && u + 1 == nparams) | |
507 goto L1; | |
508 goto Nomatch; // not enough arguments | |
509 } | |
510 | |
511 arg = cast(Expression)args.data[u]; | |
512 assert(arg); | |
513 | |
514 // Non-lvalues do not match ref or out parameters | |
515 if (p.storageClass & (STC.STCref | STC.STCout) && !arg.isLvalue()) | |
516 goto Nomatch; | |
517 | |
518 if (p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid && arg.type.ty != TY.Tvoid) | |
519 m = MATCH.MATCHconvert; | |
520 else | |
521 m = arg.implicitConvTo(p.type); | |
522 //printf("\tm = %d\n", m); | |
523 if (m == MATCH.MATCHnomatch) // if no match | |
524 { | |
525 L1: | |
526 if (varargs == 2 && u + 1 == nparams) // if last varargs param | |
527 { | |
528 Type tb = p.type.toBasetype(); | |
529 TypeSArray tsa; | |
530 long sz; | |
531 | |
532 switch (tb.ty) | |
533 { | |
534 case TY.Tsarray: | |
535 tsa = cast(TypeSArray)tb; | |
536 sz = tsa.dim.toInteger(); | |
537 if (sz != nargs - u) | |
538 goto Nomatch; | |
539 case TY.Tarray: | |
540 { | |
541 TypeArray ta = cast(TypeArray)tb; | |
542 for (; u < nargs; u++) | |
543 { | |
544 arg = cast(Expression)args.data[u]; | |
545 assert(arg); | |
546 static if (true) { | |
547 /* If lazy array of delegates, | |
548 * convert arg(s) to delegate(s) | |
549 */ | |
550 Type tret = p.isLazyArray(); | |
551 if (tret) | |
552 { | |
553 if (ta.next.equals(arg.type)) | |
554 { | |
555 m = MATCH.MATCHexact; | |
556 } | |
557 else | |
558 { | |
559 m = arg.implicitConvTo(tret); | |
560 if (m == MATCH.MATCHnomatch) | |
561 { | |
562 if (tret.toBasetype().ty == TY.Tvoid) | |
563 m = MATCH.MATCHconvert; | |
564 } | |
565 } | |
566 } | |
567 else | |
568 m = arg.implicitConvTo(ta.next); | |
569 } else { | |
570 m = arg.implicitConvTo(ta.next); | |
571 } | |
572 if (m == MATCH.MATCHnomatch) | |
573 goto Nomatch; | |
574 | |
575 if (m < match) | |
576 match = m; | |
577 } | |
578 goto Ldone; | |
579 } | |
580 | |
581 case TY.Tclass: | |
582 // Should see if there's a constructor match? | |
583 // Or just leave it ambiguous? | |
584 goto Ldone; | |
585 | |
586 default: | |
587 goto Nomatch; | |
588 } | |
589 } | |
590 | |
591 goto Nomatch; | |
592 } | |
593 | |
594 if (m < match) | |
595 match = m; // pick worst match | |
596 } | |
597 | |
598 Ldone: | |
599 //printf("match = %d\n", match); | |
600 return match; | |
601 | |
602 Nomatch: | |
603 //printf("no match\n"); | |
604 return MATCH.MATCHnomatch; | |
605 } | |
606 | |
72 | 607 override type* toCtype() |
0 | 608 { |
609 if (ctype) { | |
610 return ctype; | |
611 } | |
612 | |
613 type* t; | |
614 if (true) | |
615 { | |
616 param_t* paramtypes; | |
617 tym_t tyf; | |
618 type* tp; | |
619 | |
620 paramtypes = null; | |
621 size_t nparams = Argument.dim(parameters); | |
622 for (size_t i = 0; i < nparams; i++) | |
623 { | |
624 Argument arg = Argument.getNth(parameters, i); | |
625 tp = arg.type.toCtype(); | |
626 if (arg.storageClass & (STC.STCout | STC.STCref)) | |
627 { | |
628 // C doesn't have reference types, so it's really a pointer | |
629 // to the parameter type | |
630 tp = type_allocn(TYM.TYref, tp); | |
631 } | |
632 param_append_type(¶mtypes,tp); | |
633 } | |
634 tyf = totym(); | |
635 t = type_alloc(tyf); | |
636 t.Tflags |= TF.TFprototype; | |
637 if (varargs != 1) | |
638 t.Tflags |= TF.TFfixed; | |
639 ctype = t; | |
640 t.Tnext = next.toCtype(); | |
641 t.Tnext.Tcount++; | |
642 t.Tparamtypes = paramtypes; | |
643 } | |
644 ctype = t; | |
645 return t; | |
646 } | |
647 | |
648 /*************************** | |
649 * Determine return style of function - whether in registers or | |
650 * through a hidden pointer to the caller's stack. | |
651 */ | |
652 RET retStyle() | |
653 { | |
654 //printf("TypeFunction.retStyle() %s\n", toChars()); | |
655 version (DMDV2) { | |
656 if (isref) | |
657 return RET.RETregs; // returns a pointer | |
658 } | |
659 | |
660 Type tn = next.toBasetype(); | |
661 | |
662 if (tn.ty == TY.Tstruct) | |
663 { | |
664 StructDeclaration sd = (cast(TypeStruct)tn).sym; | |
665 if (global.params.isLinux && linkage != LINK.LINKd) { | |
666 ; | |
667 } | |
668 ///version (DMDV2) { | |
669 else if (sd.dtor || sd.cpctor) { | |
670 ; | |
671 } | |
672 ///} | |
673 else | |
674 { | |
675 switch (cast(int)tn.size()) | |
676 { | |
677 case 1: | |
678 case 2: | |
679 case 4: | |
680 case 8: | |
681 return RET.RETregs; // return small structs in regs | |
682 // (not 3 byte structs!) | |
683 default: | |
684 break; | |
685 } | |
686 } | |
687 return RET.RETstack; | |
688 } | |
689 else if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && | |
690 linkage == LINK.LINKc && | |
691 tn.iscomplex()) | |
692 { | |
693 if (tn.ty == TY.Tcomplex32) | |
694 return RET.RETregs; // in EDX:EAX, not ST1:ST0 | |
695 else | |
696 return RET.RETstack; | |
697 } | |
698 else | |
699 return RET.RETregs; | |
700 } | |
701 | |
72 | 702 override TYM totym() |
0 | 703 { |
704 TYM tyf; | |
705 | |
706 //printf("TypeFunction.totym(), linkage = %d\n", linkage); | |
707 switch (linkage) | |
708 { | |
709 case LINK.LINKwindows: | |
710 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnsfunc; | |
711 break; | |
712 | |
713 case LINK.LINKpascal: | |
714 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnpfunc; | |
715 break; | |
716 | |
717 case LINK.LINKc: | |
718 tyf = TYM.TYnfunc; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
719 version (POSIX) {///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 720 if (retStyle() == RET.RETstack) |
721 tyf = TYM.TYhfunc; | |
722 } | |
723 break; | |
724 | |
725 case LINK.LINKd: | |
726 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYjfunc; | |
727 break; | |
728 | |
729 case LINK.LINKcpp: | |
730 tyf = TYM.TYnfunc; | |
731 break; | |
732 | |
733 default: | |
734 writef("linkage = %d\n", linkage); | |
735 assert(0); | |
736 } | |
737 version (DMDV2) { | |
738 if (isnothrow) | |
739 tyf |= mTY.mTYnothrow; | |
740 } | |
741 return tyf; | |
742 } | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
743 } |