 |
Changeset 2780
- Timestamp:
- 11/05/07 18:53:59
(1 year ago)
- Author:
- schveiguy
- Message:
Fixed invariant/const problems in Layout.d
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2769 |
r2780 |
|
| 426 | 426 | private Cutf!(T) munge (T[] result, Cutf!(T) format, TypeInfo type, Arg p) |
|---|
| 427 | 427 | { |
|---|
| | 428 | // remove leading const/invariant. Note that we only ever |
|---|
| | 429 | // refer to const versions of the type or call const methods, |
|---|
| | 430 | // so this is ok. |
|---|
| | 431 | // |
|---|
| | 432 | if(auto ti = cast(TypeInfo_Const)type) |
|---|
| | 433 | type = ti.next; |
|---|
| | 434 | |
|---|
| 428 | 435 | switch (type.classinfo.name[9]) |
|---|
| 429 | 436 | { |
|---|
| 430 | 437 | case TypeCode.ARRAY: |
|---|
| 431 | | if (type is typeid(char[])) |
|---|
| 432 | | return fromUtf8 (*cast(char[]*) p, result); |
|---|
| 433 | | |
|---|
| 434 | | if (type is typeid(wchar[])) |
|---|
| 435 | | return fromUtf16 (*cast(wchar[]*) p, result); |
|---|
| 436 | | |
|---|
| 437 | | if (type is typeid(dchar[])) |
|---|
| 438 | | return fromUtf32 (*cast(dchar[]*) p, result); |
|---|
| | 438 | |
|---|
| | 439 | // |
|---|
| | 440 | // this should handle all forms of d/w/char[] |
|---|
| | 441 | // arrays including invariant and const. |
|---|
| | 442 | // |
|---|
| | 443 | TypeInfo elemType = type.next; |
|---|
| | 444 | if(auto ti = cast(TypeInfo_Const)elemType) |
|---|
| | 445 | elemType = ti.next; |
|---|
| | 446 | |
|---|
| | 447 | if (elemType is typeid(char)) |
|---|
| | 448 | return fromUtf8 (*cast(Cutf8*) p, result); |
|---|
| | 449 | |
|---|
| | 450 | if (elemType is typeid(wchar)) |
|---|
| | 451 | return fromUtf16 (*cast(Cutf16*) p, result); |
|---|
| | 452 | |
|---|
| | 453 | if (elemType is typeid(dchar)) |
|---|
| | 454 | return fromUtf32 (*cast(Cutf32*) p, result); |
|---|
| 439 | 455 | |
|---|
| 440 | 456 | // Currently we only format d/w/char[] arrays. |
|---|
| … | … | |
| 447 | 463 | |
|---|
| 448 | 464 | case TypeCode.BYTE: |
|---|
| 449 | | return integer (result, *cast(byte*) p, format); |
|---|
| | 465 | return integer (result, *cast(const byte*) p, format); |
|---|
| 450 | 466 | |
|---|
| 451 | 467 | case TypeCode.UBYTE: |
|---|
| 452 | | return integer (result, *cast(ubyte*) p, format, 'u'); |
|---|
| | 468 | return integer (result, *cast(const ubyte*) p, format, 'u'); |
|---|
| 453 | 469 | |
|---|
| 454 | 470 | case TypeCode.SHORT: |
|---|
| 455 | | return integer (result, *cast(short*) p, format); |
|---|
| | 471 | return integer (result, *cast(const short*) p, format); |
|---|
| 456 | 472 | |
|---|
| 457 | 473 | case TypeCode.USHORT: |
|---|
| 458 | | return integer (result, *cast(ushort*) p, format, 'u'); |
|---|
| | 474 | return integer (result, *cast(const ushort*) p, format, 'u'); |
|---|
| 459 | 475 | |
|---|
| 460 | 476 | case TypeCode.INT: |
|---|
| 461 | | return integer (result, *cast(int*) p, format); |
|---|
| | 477 | return integer (result, *cast(const int*) p, format); |
|---|
| 462 | 478 | |
|---|
| 463 | 479 | case TypeCode.UINT: |
|---|
| 464 | 480 | case TypeCode.POINTER: |
|---|
| 465 | | return integer (result, *cast(uint*) p, format, 'u'); |
|---|
| | 481 | return integer (result, *cast(const uint*) p, format, 'u'); |
|---|
| 466 | 482 | |
|---|
| 467 | 483 | case TypeCode.LONG: |
|---|
| 468 | 484 | case TypeCode.ULONG: |
|---|
| 469 | | return integer (result, *cast(long*) p, format); |
|---|
| | 485 | return integer (result, *cast(const long*) p, format); |
|---|
| 470 | 486 | |
|---|
| 471 | 487 | case TypeCode.FLOAT: |
|---|
| 472 | | return floater (result, *cast(float*) p, format); |
|---|
| | 488 | return floater (result, *cast(const float*) p, format); |
|---|
| 473 | 489 | |
|---|
| 474 | 490 | case TypeCode.DOUBLE: |
|---|
| 475 | | return floater (result, *cast(double*) p, format); |
|---|
| | 491 | return floater (result, *cast(const double*) p, format); |
|---|
| 476 | 492 | |
|---|
| 477 | 493 | case TypeCode.REAL: |
|---|
| 478 | | return floater (result, *cast(real*) p, format); |
|---|
| | 494 | return floater (result, *cast(const real*) p, format); |
|---|
| 479 | 495 | |
|---|
| 480 | 496 | case TypeCode.CHAR: |
|---|
| 481 | | return fromUtf8 ((cast(char*) p)[0..1], result); |
|---|
| | 497 | return fromUtf8 ((cast(const char*) p)[0..1], result); |
|---|
| 482 | 498 | |
|---|
| 483 | 499 | case TypeCode.WCHAR: |
|---|
| 484 | | return fromUtf16 ((cast(wchar*) p)[0..1], result); |
|---|
| | 500 | return fromUtf16 ((cast(const wchar*) p)[0..1], result); |
|---|
| 485 | 501 | |
|---|
| 486 | 502 | case TypeCode.DCHAR: |
|---|
| 487 | | return fromUtf32 ((cast(dchar*) p)[0..1], result); |
|---|
| | 503 | return fromUtf32 ((cast(const dchar*) p)[0..1], result); |
|---|
| 488 | 504 | |
|---|
| 489 | 505 | case TypeCode.INTERFACE: |
|---|
| | 506 | // TODO: toUtf8 is not a const function, so we |
|---|
| | 507 | // cannot cast to const Object. However, I'm not |
|---|
| | 508 | // sure how to declare const member functions, so |
|---|
| | 509 | // we'll wait until that debate is settled. For |
|---|
| | 510 | // now, we just cast away const. This goes for |
|---|
| | 511 | // interface and class. This should be relatively |
|---|
| | 512 | // safe because toUtf8 should be const for the |
|---|
| | 513 | // most part. |
|---|
| 490 | 514 | Interface* pi = **cast(Interface ***)*cast(void**) p; |
|---|
| 491 | 515 | Object o = cast(Object)(*cast(void**)p - pi.offset); |
|---|
Download in other formats:
|
 |