comparison dmd/mtype.c @ 159:5acec6b2eef8 trunk

[svn r175] merged dmd 1.029
author ChristianK
date Thu, 01 May 2008 15:15:28 +0200
parents 5c17f81fc1c1
children 1856c62af24b
comparison
equal deleted inserted replaced
158:287540c5f05e 159:5acec6b2eef8
1 1
2 // Compiler implementation of the D programming language 2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2007 by Digital Mars 3 // Copyright (c) 1999-2008 by Digital Mars
4 // All Rights Reserved 4 // All Rights Reserved
5 // written by Walter Bright 5 // written by Walter Bright
6 // http://www.digitalmars.com 6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License 7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt. 8 // in artistic.txt, or the GNU General Public License in gnu.txt.
105 105
106 106
107 Type::Type(TY ty, Type *next) 107 Type::Type(TY ty, Type *next)
108 { 108 {
109 this->ty = ty; 109 this->ty = ty;
110 this->mod = 0;
110 this->next = next; 111 this->next = next;
111 this->deco = NULL; 112 this->deco = NULL;
113 #if V2
114 this->cto = NULL;
115 this->ito = NULL;
116 #endif
112 this->pto = NULL; 117 this->pto = NULL;
113 this->rto = NULL; 118 this->rto = NULL;
114 this->arrayof = NULL; 119 this->arrayof = NULL;
115 this->vtinfo = NULL; 120 this->vtinfo = NULL;
116 this->ctype = NULL; 121 this->ctype = NULL;
336 next->toDecoBuffer(buf); 341 next->toDecoBuffer(buf);
337 } 342 }
338 } 343 }
339 344
340 /******************************** 345 /********************************
341 * Name mangling.
342 */
343
344 void Type::toTypeInfoBuffer(OutBuffer *buf)
345 {
346 assert(0);
347 buf->writeByte(mangleChar[ty]);
348 }
349
350 /********************************
351 * For pretty-printing a type. 346 * For pretty-printing a type.
352 */ 347 */
353 348
354 char *Type::toChars() 349 char *Type::toChars()
355 { OutBuffer *buf; 350 { OutBuffer *buf;
356 HdrGenState hgs; 351 HdrGenState hgs;
357 352
358 buf = new OutBuffer(); 353 buf = new OutBuffer();
359 toCBuffer2(buf, NULL, &hgs); 354 toCBuffer(buf, NULL, &hgs);
360 return buf->toChars(); 355 return buf->toChars();
361 } 356 }
362 357
363 void Type::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 358 void Type::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
364 { 359 {
365 OutBuffer tbuf; 360 toCBuffer2(buf, hgs, 0);
366
367 toCBuffer2(&tbuf, ident, hgs);
368 buf->write(&tbuf);
369 }
370
371 void Type::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
372 {
373 buf->prependstring(toChars());
374 if (ident) 361 if (ident)
375 { buf->writeByte(' '); 362 { buf->writeByte(' ');
376 buf->writestring(ident->toChars()); 363 buf->writestring(ident->toChars());
377 } 364 }
378 } 365 }
366
367 void Type::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
368 {
369 if (mod != this->mod)
370 { toCBuffer3(buf, hgs, mod);
371 return;
372 }
373 buf->writestring(toChars());
374 }
375
376 void Type::toCBuffer3(OutBuffer *buf, HdrGenState *hgs, int mod)
377 {
378 if (mod != this->mod)
379 { char *p;
380
381 switch (this->mod)
382 {
383 case 0:
384 toCBuffer2(buf, hgs, this->mod);
385 break;
386 case MODconst:
387 p = "const(";
388 goto L1;
389 case MODinvariant:
390 p = "invariant(";
391 L1: buf->writestring(p);
392 toCBuffer2(buf, hgs, this->mod);
393 buf->writeByte(')');
394 break;
395 default:
396 assert(0);
397 }
398 }
399 }
400
379 401
380 /************************************ 402 /************************************
381 */ 403 */
382 404
383 Type *Type::merge() 405 Type *Type::merge()
904 char *TypeBasic::toChars() 926 char *TypeBasic::toChars()
905 { 927 {
906 return dstring; 928 return dstring;
907 } 929 }
908 930
909 void TypeBasic::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 931 void TypeBasic::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
910 { 932 {
911 buf->prependstring(cstring); 933 //printf("TypeBasic::toCBuffer2(mod = %d, this->mod = %d)\n", mod, this->mod);
912 if (ident) 934 if (mod != this->mod)
913 { buf->writeByte(' '); 935 { toCBuffer3(buf, hgs, mod);
914 buf->writestring(ident->toChars()); 936 return;
915 } 937 }
938 buf->writestring(dstring);
916 } 939 }
917 940
918 d_uns64 TypeBasic::size(Loc loc) 941 d_uns64 TypeBasic::size(Loc loc)
919 { unsigned size; 942 { unsigned size;
920 943
1587 e = Type::dotExp(sc, e, ident); 1610 e = Type::dotExp(sc, e, ident);
1588 } 1611 }
1589 return e; 1612 return e;
1590 } 1613 }
1591 1614
1592 void TypeArray::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
1593 {
1594 #if 1
1595 OutBuffer buf2;
1596 toPrettyBracket(&buf2, hgs);
1597 buf->prependstring(buf2.toChars());
1598 if (ident)
1599 {
1600 buf->writeByte(' ');
1601 buf->writestring(ident->toChars());
1602 }
1603 next->toCBuffer2(buf, NULL, hgs);
1604 #elif 1
1605 // The D way
1606 Type *t;
1607 OutBuffer buf2;
1608 for (t = this; 1; t = t->next)
1609 { TypeArray *ta;
1610
1611 ta = dynamic_cast<TypeArray *>(t);
1612 if (!ta)
1613 break;
1614 ta->toPrettyBracket(&buf2, hgs);
1615 }
1616 buf->prependstring(buf2.toChars());
1617 if (ident)
1618 {
1619 buf2.writestring(ident->toChars());
1620 }
1621 t->toCBuffer2(buf, NULL, hgs);
1622 #else
1623 // The C way
1624 if (buf->offset)
1625 { buf->bracket('(', ')');
1626 assert(!ident);
1627 }
1628 else if (ident)
1629 buf->writestring(ident->toChars());
1630 Type *t = this;
1631 do
1632 { Expression *dim;
1633 buf->writeByte('[');
1634 dim = ((TypeSArray *)t)->dim;
1635 if (dim)
1636 buf->printf("%lld", dim->toInteger());
1637 buf->writeByte(']');
1638 t = t->next;
1639 } while (t->ty == Tsarray);
1640 t->toCBuffer2(buf, NULL, hgs);
1641 #endif
1642 }
1643
1644 1615
1645 /***************************** TypeSArray *****************************/ 1616 /***************************** TypeSArray *****************************/
1646 1617
1647 TypeSArray::TypeSArray(Type *t, Expression *dim) 1618 TypeSArray::TypeSArray(Type *t, Expression *dim)
1648 : TypeArray(Tsarray, t) 1619 : TypeArray(Tsarray, t)
1900 buf->printf("%ju", dim->toInteger()); 1871 buf->printf("%ju", dim->toInteger());
1901 if (next) 1872 if (next)
1902 next->toDecoBuffer(buf); 1873 next->toDecoBuffer(buf);
1903 } 1874 }
1904 1875
1905 void TypeSArray::toTypeInfoBuffer(OutBuffer *buf) 1876 void TypeSArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
1906 { 1877 {
1907 buf->writeByte(mangleChar[Tarray]); 1878 if (mod != this->mod)
1908 if (next) 1879 { toCBuffer3(buf, hgs, mod);
1909 next->toTypeInfoBuffer(buf); 1880 return;
1910 } 1881 }
1911 1882 next->toCBuffer2(buf, hgs, this->mod);
1912 void TypeSArray::toPrettyBracket(OutBuffer *buf, HdrGenState *hgs)
1913 {
1914 buf->printf("[%s]", dim->toChars()); 1883 buf->printf("[%s]", dim->toChars());
1915 } 1884 }
1916 1885
1917 Expression *TypeSArray::dotExp(Scope *sc, Expression *e, Identifier *ident) 1886 Expression *TypeSArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
1918 { 1887 {
2066 buf->writeByte(mangleChar[ty]); 2035 buf->writeByte(mangleChar[ty]);
2067 if (next) 2036 if (next)
2068 next->toDecoBuffer(buf); 2037 next->toDecoBuffer(buf);
2069 } 2038 }
2070 2039
2071 void TypeDArray::toTypeInfoBuffer(OutBuffer *buf) 2040 void TypeDArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
2072 { 2041 {
2073 buf->writeByte(mangleChar[ty]); 2042 if (mod != this->mod)
2074 if (next) 2043 { toCBuffer3(buf, hgs, mod);
2075 next->toTypeInfoBuffer(buf); 2044 return;
2076 } 2045 }
2077 2046 next->toCBuffer2(buf, hgs, this->mod);
2078 void TypeDArray::toPrettyBracket(OutBuffer *buf, HdrGenState *hgs)
2079 {
2080 buf->writestring("[]"); 2047 buf->writestring("[]");
2081 } 2048 }
2082 2049
2083 Expression *TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident) 2050 Expression *TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident)
2084 { 2051 {
2341 buf->writeByte(mangleChar[ty]); 2308 buf->writeByte(mangleChar[ty]);
2342 index->toDecoBuffer(buf); 2309 index->toDecoBuffer(buf);
2343 next->toDecoBuffer(buf); 2310 next->toDecoBuffer(buf);
2344 } 2311 }
2345 2312
2346 void TypeAArray::toPrettyBracket(OutBuffer *buf, HdrGenState *hgs) 2313 void TypeAArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
2347 { 2314 {
2315 if (mod != this->mod)
2316 { toCBuffer3(buf, hgs, mod);
2317 return;
2318 }
2319 next->toCBuffer2(buf, hgs, this->mod);
2348 buf->writeByte('['); 2320 buf->writeByte('[');
2349 { OutBuffer ibuf; 2321 index->toCBuffer2(buf, hgs, 0);
2350
2351 index->toCBuffer2(&ibuf, NULL, hgs);
2352 buf->write(&ibuf);
2353 }
2354 buf->writeByte(']'); 2322 buf->writeByte(']');
2355 } 2323 }
2356 2324
2357 Expression *TypeAArray::defaultInit(Loc loc) 2325 Expression *TypeAArray::defaultInit(Loc loc)
2358 { 2326 {
2413 d_uns64 TypePointer::size(Loc loc) 2381 d_uns64 TypePointer::size(Loc loc)
2414 { 2382 {
2415 return PTRSIZE; 2383 return PTRSIZE;
2416 } 2384 }
2417 2385
2418 void TypePointer::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 2386 void TypePointer::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
2419 { 2387 {
2420 //printf("TypePointer::toCBuffer2() next = %d\n", next->ty); 2388 //printf("TypePointer::toCBuffer2() next = %d\n", next->ty);
2421 buf->prependstring("*"); 2389 if (mod != this->mod)
2422 if (ident) 2390 { toCBuffer3(buf, hgs, mod);
2423 { 2391 return;
2424 buf->writeByte(' '); 2392 }
2425 buf->writestring(ident->toChars()); 2393 next->toCBuffer2(buf, hgs, this->mod);
2426 } 2394 if (next->ty != Tfunction)
2427 next->toCBuffer2(buf, NULL, hgs); 2395 buf->writeByte('*');
2428 } 2396 }
2429 2397
2430 MATCH TypePointer::implicitConvTo(Type *to) 2398 MATCH TypePointer::implicitConvTo(Type *to)
2431 { 2399 {
2432 //printf("TypePointer::implicitConvTo()\n"); 2400 //printf("TypePointer::implicitConvTo()\n");
2507 d_uns64 TypeReference::size(Loc loc) 2475 d_uns64 TypeReference::size(Loc loc)
2508 { 2476 {
2509 return PTRSIZE; 2477 return PTRSIZE;
2510 } 2478 }
2511 2479
2512 void TypeReference::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 2480 void TypeReference::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
2513 { 2481 {
2514 buf->prependstring("&"); 2482 if (mod != this->mod)
2515 if (ident) 2483 { toCBuffer3(buf, hgs, mod);
2516 { 2484 return;
2517 buf->writestring(ident->toChars()); 2485 }
2518 } 2486 next->toCBuffer2(buf, hgs, this->mod);
2519 next->toCBuffer2(buf, NULL, hgs); 2487 buf->writeByte('&');
2520 } 2488 }
2521 2489
2522 Expression *TypeReference::dotExp(Scope *sc, Expression *e, Identifier *ident) 2490 Expression *TypeReference::dotExp(Scope *sc, Expression *e, Identifier *ident)
2523 { 2491 {
2524 #if LOGDOTEXP 2492 #if LOGDOTEXP
2685 buf->writeByte('Z' - varargs); // mark end of arg list 2653 buf->writeByte('Z' - varargs); // mark end of arg list
2686 next->toDecoBuffer(buf); 2654 next->toDecoBuffer(buf);
2687 inuse--; 2655 inuse--;
2688 } 2656 }
2689 2657
2690 void TypeFunction::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 2658 void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
2691 { 2659 {
2692 char *p = NULL; 2660 char *p = NULL;
2693 2661
2694 if (inuse) 2662 if (inuse)
2695 { inuse = 2; // flag error to caller 2663 { inuse = 2; // flag error to caller
2696 return; 2664 return;
2697 } 2665 }
2698 inuse++; 2666 inuse++;
2667 if (next && (!ident || ident->toHChars2() == ident->toChars()))
2668 next->toCBuffer2(buf, hgs, 0);
2699 if (hgs->ddoc != 1) 2669 if (hgs->ddoc != 1)
2700 { 2670 {
2701 switch (linkage) 2671 switch (linkage)
2702 { 2672 {
2703 case LINKd: p = NULL; break; 2673 case LINKd: p = NULL; break;
2708 default: 2678 default:
2709 assert(0); 2679 assert(0);
2710 } 2680 }
2711 } 2681 }
2712 2682
2713 if (buf->offset) 2683 if (!hgs->hdrgen && p)
2714 { 2684 buf->writestring(p);
2715 if (!hgs->hdrgen && p) 2685 if (ident)
2716 buf->prependstring(p); 2686 { buf->writeByte(' ');
2717 buf->bracket('(', ')'); 2687 buf->writestring(ident->toHChars2());
2718 assert(!ident);
2719 }
2720 else
2721 {
2722 if (!hgs->hdrgen && p)
2723 buf->writestring(p);
2724 if (ident)
2725 { buf->writeByte(' ');
2726 buf->writestring(ident->toHChars2());
2727 }
2728 } 2688 }
2729 Argument::argsToCBuffer(buf, hgs, parameters, varargs); 2689 Argument::argsToCBuffer(buf, hgs, parameters, varargs);
2730 if (next && (!ident || ident->toHChars2() == ident->toChars())) 2690 inuse--;
2731 next->toCBuffer2(buf, NULL, hgs); 2691 }
2692
2693 void TypeFunction::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
2694 {
2695 char *p = NULL;
2696
2697 if (inuse)
2698 { inuse = 2; // flag error to caller
2699 return;
2700 }
2701 inuse++;
2702 if (next)
2703 next->toCBuffer2(buf, hgs, 0);
2704 if (hgs->ddoc != 1)
2705 {
2706 switch (linkage)
2707 {
2708 case LINKd: p = NULL; break;
2709 case LINKc: p = "C "; break;
2710 case LINKwindows: p = "Windows "; break;
2711 case LINKpascal: p = "Pascal "; break;
2712 case LINKcpp: p = "C++ "; break;
2713 default:
2714 assert(0);
2715 }
2716 }
2717
2718 if (!hgs->hdrgen && p)
2719 buf->writestring(p);
2720 buf->writestring(" function");
2721 Argument::argsToCBuffer(buf, hgs, parameters, varargs);
2732 inuse--; 2722 inuse--;
2733 } 2723 }
2734 2724
2735 Type *TypeFunction::semantic(Loc loc, Scope *sc) 2725 Type *TypeFunction::semantic(Loc loc, Scope *sc)
2736 { 2726 {
2997 d_uns64 TypeDelegate::size(Loc loc) 2987 d_uns64 TypeDelegate::size(Loc loc)
2998 { 2988 {
2999 return PTRSIZE * 2; 2989 return PTRSIZE * 2;
3000 } 2990 }
3001 2991
3002 void TypeDelegate::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 2992 void TypeDelegate::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
3003 { 2993 {
3004 #if 1 2994 if (mod != this->mod)
3005 OutBuffer args; 2995 { toCBuffer3(buf, hgs, mod);
2996 return;
2997 }
3006 TypeFunction *tf = (TypeFunction *)next; 2998 TypeFunction *tf = (TypeFunction *)next;
3007 2999
3008 Argument::argsToCBuffer(&args, hgs, tf->parameters, tf->varargs); 3000 tf->next->toCBuffer2(buf, hgs, 0);
3009 buf->prependstring(args.toChars()); 3001 buf->writestring(" delegate");
3010 buf->prependstring(" delegate"); 3002 Argument::argsToCBuffer(buf, hgs, tf->parameters, tf->varargs);
3011 if (ident)
3012 {
3013 buf->writeByte(' ');
3014 buf->writestring(ident->toChars());
3015 }
3016 next->next->toCBuffer2(buf, NULL, hgs);
3017 #else
3018 next->toCBuffer2(buf, Id::delegate, hgs);
3019 if (ident)
3020 {
3021 buf->writestring(ident->toChars());
3022 }
3023 #endif
3024 } 3003 }
3025 3004
3026 Expression *TypeDelegate::defaultInit(Loc loc) 3005 Expression *TypeDelegate::defaultInit(Loc loc)
3027 { 3006 {
3028 #if LOGDEFAULTINIT 3007 #if LOGDEFAULTINIT
3108 void TypeQualified::addIdent(Identifier *ident) 3087 void TypeQualified::addIdent(Identifier *ident)
3109 { 3088 {
3110 idents.push(ident); 3089 idents.push(ident);
3111 } 3090 }
3112 3091
3113 void TypeQualified::toCBuffer2Helper(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 3092 void TypeQualified::toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs)
3114 { 3093 {
3115 int i; 3094 int i;
3116 3095
3117 for (i = 0; i < idents.dim; i++) 3096 for (i = 0; i < idents.dim; i++)
3118 { Identifier *id = (Identifier *)idents.data[i]; 3097 { Identifier *id = (Identifier *)idents.data[i];
3338 len = strlen(name); 3317 len = strlen(name);
3339 buf->printf("%c%d%s", mangleChar[ty], len, name); 3318 buf->printf("%c%d%s", mangleChar[ty], len, name);
3340 //buf->printf("%c%s", mangleChar[ty], name); 3319 //buf->printf("%c%s", mangleChar[ty], name);
3341 } 3320 }
3342 3321
3343 void TypeIdentifier::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 3322 void TypeIdentifier::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
3344 { 3323 {
3345 OutBuffer tmp; 3324 if (mod != this->mod)
3346 3325 { toCBuffer3(buf, hgs, mod);
3347 tmp.writestring(this->ident->toChars()); 3326 return;
3348 toCBuffer2Helper(&tmp, NULL, hgs); 3327 }
3349 buf->prependstring(tmp.toChars()); 3328 buf->writestring(this->ident->toChars());
3350 if (ident) 3329 toCBuffer2Helper(buf, hgs);
3351 { buf->writeByte(' ');
3352 buf->writestring(ident->toChars());
3353 }
3354 } 3330 }
3355 3331
3356 /************************************* 3332 /*************************************
3357 * Takes an array of Identifiers and figures out if 3333 * Takes an array of Identifiers and figures out if
3358 * it represents a Type or an Expression. 3334 * it represents a Type or an Expression.
3470 t->syntaxCopyHelper(this); 3446 t->syntaxCopyHelper(this);
3471 return t; 3447 return t;
3472 } 3448 }
3473 3449
3474 3450
3475 void TypeInstance::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 3451 void TypeInstance::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
3476 { 3452 {
3477 OutBuffer tmp; 3453 if (mod != this->mod)
3478 3454 { toCBuffer3(buf, hgs, mod);
3479 tempinst->toCBuffer(&tmp, hgs); 3455 return;
3480 toCBuffer2Helper(&tmp, NULL, hgs); 3456 }
3481 buf->prependstring(tmp.toChars()); 3457 tempinst->toCBuffer(buf, hgs);
3482 if (ident) 3458 toCBuffer2Helper(buf, hgs);
3483 { buf->writeByte(' ');
3484 buf->writestring(ident->toChars());
3485 }
3486 } 3459 }
3487 3460
3488 void TypeInstance::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) 3461 void TypeInstance::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps)
3489 { 3462 {
3490 // Note close similarity to TypeIdentifier::resolve() 3463 // Note close similarity to TypeIdentifier::resolve()
3573 if (t == this) 3546 if (t == this)
3574 return NULL; 3547 return NULL;
3575 return t->toDsymbol(sc); 3548 return t->toDsymbol(sc);
3576 } 3549 }
3577 3550
3578 void TypeTypeof::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 3551 void TypeTypeof::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
3579 { 3552 {
3580 OutBuffer tmp; 3553 if (mod != this->mod)
3581 3554 { toCBuffer3(buf, hgs, mod);
3582 tmp.writestring("typeof("); 3555 return;
3583 exp->toCBuffer(&tmp, hgs); 3556 }
3584 tmp.writeByte(')'); 3557 buf->writestring("typeof(");
3585 toCBuffer2Helper(&tmp, NULL, hgs); 3558 exp->toCBuffer(buf, hgs);
3586 buf->prependstring(tmp.toChars()); 3559 buf->writeByte(')');
3587 if (ident) 3560 toCBuffer2Helper(buf, hgs);
3588 { buf->writeByte(' ');
3589 buf->writestring(ident->toChars());
3590 }
3591 } 3561 }
3592 3562
3593 Type *TypeTypeof::semantic(Loc loc, Scope *sc) 3563 Type *TypeTypeof::semantic(Loc loc, Scope *sc)
3594 { Expression *e; 3564 { Expression *e;
3595 Type *t; 3565 Type *t;
3762 // if (name[0] == '_' && name[1] == 'D') 3732 // if (name[0] == '_' && name[1] == 'D')
3763 // name += 2; 3733 // name += 2;
3764 buf->printf("%c%s", mangleChar[ty], name); 3734 buf->printf("%c%s", mangleChar[ty], name);
3765 } 3735 }
3766 3736
3767 void TypeEnum::toTypeInfoBuffer(OutBuffer *buf) 3737 void TypeEnum::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
3768 { 3738 {
3769 toBasetype()->toTypeInfoBuffer(buf); 3739 if (mod != this->mod)
3770 } 3740 { toCBuffer3(buf, hgs, mod);
3771 3741 return;
3772 void TypeEnum::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 3742 }
3773 { 3743 buf->writestring(sym->toChars());
3774 buf->prependstring(sym->toChars());
3775 if (ident)
3776 { buf->writeByte(' ');
3777 buf->writestring(ident->toChars());
3778 }
3779 } 3744 }
3780 3745
3781 Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident) 3746 Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident)
3782 { 3747 {
3783 EnumMember *m; 3748 EnumMember *m;
3943 //len = strlen(name); 3908 //len = strlen(name);
3944 //buf->printf("%c%d%s", mangleChar[ty], len, name); 3909 //buf->printf("%c%d%s", mangleChar[ty], len, name);
3945 buf->printf("%c%s", mangleChar[ty], name); 3910 buf->printf("%c%s", mangleChar[ty], name);
3946 } 3911 }
3947 3912
3948 void TypeTypedef::toTypeInfoBuffer(OutBuffer *buf) 3913 void TypeTypedef::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
3949 {
3950 sym->basetype->toTypeInfoBuffer(buf);
3951 }
3952
3953 void TypeTypedef::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
3954 { 3914 {
3955 //printf("TypeTypedef::toCBuffer2() '%s'\n", sym->toChars()); 3915 //printf("TypeTypedef::toCBuffer2() '%s'\n", sym->toChars());
3956 buf->prependstring(sym->toChars()); 3916 if (mod != this->mod)
3957 if (ident) 3917 { toCBuffer3(buf, hgs, mod);
3958 { buf->writeByte(' '); 3918 return;
3959 buf->writestring(ident->toChars()); 3919 }
3960 } 3920 buf->writestring(sym->toChars());
3961 } 3921 }
3962 3922
3963 Expression *TypeTypedef::dotExp(Scope *sc, Expression *e, Identifier *ident) 3923 Expression *TypeTypedef::dotExp(Scope *sc, Expression *e, Identifier *ident)
3964 { 3924 {
3965 #if LOGDOTEXP 3925 #if LOGDOTEXP
4171 //len = strlen(name); 4131 //len = strlen(name);
4172 //buf->printf("%c%d%s", mangleChar[ty], len, name); 4132 //buf->printf("%c%d%s", mangleChar[ty], len, name);
4173 buf->printf("%c%s", mangleChar[ty], name); 4133 buf->printf("%c%s", mangleChar[ty], name);
4174 } 4134 }
4175 4135
4176 void TypeStruct::toTypeInfoBuffer(OutBuffer *buf) 4136 void TypeStruct::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
4177 { 4137 {
4178 toDecoBuffer(buf); 4138 if (mod != this->mod)
4179 } 4139 { toCBuffer3(buf, hgs, mod);
4180 4140 return;
4181 4141 }
4182 void TypeStruct::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 4142 TemplateInstance *ti = sym->parent->isTemplateInstance();
4183 { 4143 if (ti && ti->toAlias() == sym)
4184 buf->prependbyte(' '); 4144 buf->writestring(ti->toChars());
4185 buf->prependstring(toChars()); 4145 else
4186 if (ident) 4146 buf->writestring(sym->toChars());
4187 buf->writestring(ident->toChars());
4188 } 4147 }
4189 4148
4190 Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident) 4149 Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident)
4191 { unsigned offset; 4150 { unsigned offset;
4192 4151
4453 //len = strlen(name); 4412 //len = strlen(name);
4454 //buf->printf("%c%d%s", mangleChar[ty], len, name); 4413 //buf->printf("%c%d%s", mangleChar[ty], len, name);
4455 buf->printf("%c%s", mangleChar[ty], name); 4414 buf->printf("%c%s", mangleChar[ty], name);
4456 } 4415 }
4457 4416
4458 void TypeClass::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 4417 void TypeClass::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
4459 { 4418 {
4460 buf->prependstring(sym->toChars()); 4419 if (mod != this->mod)
4461 if (ident) 4420 { toCBuffer3(buf, hgs, mod);
4462 { buf->writeByte(' '); 4421 return;
4463 buf->writestring(ident->toChars()); 4422 }
4464 } 4423 buf->writestring(sym->toChars());
4465 } 4424 }
4466 4425
4467 Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident) 4426 Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
4468 { unsigned offset; 4427 { unsigned offset;
4469 4428
4926 } 4885 }
4927 } 4886 }
4928 return NULL; 4887 return NULL;
4929 } 4888 }
4930 4889
4931 void TypeTuple::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 4890 void TypeTuple::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
4932 { 4891 {
4933 OutBuffer buf2; 4892 Argument::argsToCBuffer(buf, hgs, arguments, 0);
4934 Argument::argsToCBuffer(&buf2, hgs, arguments, 0);
4935 buf->prependstring(buf2.toChars());
4936 if (ident)
4937 { buf->writeByte(' ');
4938 buf->writestring(ident->toChars());
4939 }
4940 } 4893 }
4941 4894
4942 void TypeTuple::toDecoBuffer(OutBuffer *buf) 4895 void TypeTuple::toDecoBuffer(OutBuffer *buf)
4943 { 4896 {
4944 //printf("TypeTuple::toDecoBuffer() this = %p\n", this); 4897 //printf("TypeTuple::toDecoBuffer() this = %p\n", this);
5082 Ldefault: 5035 Ldefault:
5083 Type::resolve(loc, sc, pe, pt, ps); 5036 Type::resolve(loc, sc, pe, pt, ps);
5084 } 5037 }
5085 } 5038 }
5086 5039
5087 void TypeSlice::toCBuffer2(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) 5040 void TypeSlice::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
5088 { 5041 {
5089 OutBuffer buf2; 5042 if (mod != this->mod)
5090 5043 { toCBuffer3(buf, hgs, mod);
5091 buf2.printf("[%s .. ", lwr->toChars()); 5044 return;
5092 buf2.printf("%s]", upr->toChars()); 5045 }
5093 5046 next->toCBuffer2(buf, hgs, this->mod);
5094 buf->prependstring(buf2.toChars()); 5047
5095 if (ident) 5048 buf->printf("[%s .. ", lwr->toChars());
5096 { 5049 buf->printf("%s]", upr->toChars());
5097 buf->writeByte(' ');
5098 buf->writestring(ident->toChars());
5099 }
5100 next->toCBuffer2(buf, NULL, hgs);
5101 } 5050 }
5102 5051
5103 /***************************** Argument *****************************/ 5052 /***************************** Argument *****************************/
5104 5053
5105 Argument::Argument(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg) 5054 Argument::Argument(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg)
5153 5102
5154 if (i) 5103 if (i)
5155 buf->writeByte(','); 5104 buf->writeByte(',');
5156 arg = (Argument *)args->data[i]; 5105 arg = (Argument *)args->data[i];
5157 argbuf.reset(); 5106 argbuf.reset();
5158 arg->type->toCBuffer2(&argbuf, NULL, &hgs); 5107 arg->type->toCBuffer2(&argbuf, &hgs, 0);
5159 buf->write(&argbuf); 5108 buf->write(&argbuf);
5160 } 5109 }
5161 if (varargs) 5110 if (varargs)
5162 { 5111 {
5163 if (i && varargs == 1) 5112 if (i && varargs == 1)
5189 buf->writestring((global.params.Dversion == 1) 5138 buf->writestring((global.params.Dversion == 1)
5190 ? (char *)"inout " : (char *)"ref "); 5139 ? (char *)"inout " : (char *)"ref ");
5191 else if (arg->storageClass & STClazy) 5140 else if (arg->storageClass & STClazy)
5192 buf->writestring("lazy "); 5141 buf->writestring("lazy ");
5193 argbuf.reset(); 5142 argbuf.reset();
5194 arg->type->toCBuffer2(&argbuf, arg->ident, hgs); 5143 arg->type->toCBuffer(&argbuf, arg->ident, hgs);
5195 if (arg->defaultArg) 5144 if (arg->defaultArg)
5196 { 5145 {
5197 argbuf.writestring(" = "); 5146 argbuf.writestring(" = ");
5198 arg->defaultArg->toCBuffer(&argbuf, hgs); 5147 arg->defaultArg->toCBuffer(&argbuf, hgs);
5199 } 5148 }