Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 2780

Show
Ignore:
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
  • branches/experimental/D2.0/tango/text/convert/Layout.d

    r2769 r2780  
    426426        private Cutf!(T) munge (T[] result, Cutf!(T) format, TypeInfo type, Arg p) 
    427427        { 
     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 
    428435                switch (type.classinfo.name[9]) 
    429436                       { 
    430437                       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); 
    439455 
    440456                            // Currently we only format d/w/char[] arrays. 
     
    447463 
    448464                       case TypeCode.BYTE: 
    449                             return integer (result, *cast(byte*) p, format); 
     465                            return integer (result, *cast(const byte*) p, format); 
    450466 
    451467                       case TypeCode.UBYTE: 
    452                             return integer (result, *cast(ubyte*) p, format, 'u'); 
     468                            return integer (result, *cast(const ubyte*) p, format, 'u'); 
    453469 
    454470                       case TypeCode.SHORT: 
    455                             return integer (result, *cast(short*) p, format); 
     471                            return integer (result, *cast(const short*) p, format); 
    456472 
    457473                       case TypeCode.USHORT: 
    458                             return integer (result, *cast(ushort*) p, format, 'u'); 
     474                            return integer (result, *cast(const ushort*) p, format, 'u'); 
    459475 
    460476                       case TypeCode.INT: 
    461                             return integer (result, *cast(int*) p, format); 
     477                            return integer (result, *cast(const int*) p, format); 
    462478 
    463479                       case TypeCode.UINT: 
    464480                       case TypeCode.POINTER: 
    465                             return integer (result, *cast(uint*) p, format, 'u'); 
     481                            return integer (result, *cast(const uint*) p, format, 'u'); 
    466482 
    467483                       case TypeCode.LONG: 
    468484                       case TypeCode.ULONG: 
    469                             return integer (result, *cast(long*) p, format); 
     485                            return integer (result, *cast(const long*) p, format); 
    470486 
    471487                       case TypeCode.FLOAT: 
    472                             return floater (result, *cast(float*) p, format); 
     488                            return floater (result, *cast(const float*) p, format); 
    473489 
    474490                       case TypeCode.DOUBLE: 
    475                             return floater (result, *cast(double*) p, format); 
     491                            return floater (result, *cast(const double*) p, format); 
    476492 
    477493                       case TypeCode.REAL: 
    478                             return floater (result, *cast(real*) p, format); 
     494                            return floater (result, *cast(const real*) p, format); 
    479495 
    480496                       case TypeCode.CHAR: 
    481                             return fromUtf8 ((cast(char*) p)[0..1], result); 
     497                            return fromUtf8 ((cast(const char*) p)[0..1], result); 
    482498 
    483499                       case TypeCode.WCHAR: 
    484                             return fromUtf16 ((cast(wchar*) p)[0..1], result); 
     500                            return fromUtf16 ((cast(const wchar*) p)[0..1], result); 
    485501 
    486502                       case TypeCode.DCHAR: 
    487                             return fromUtf32 ((cast(dchar*) p)[0..1], result); 
     503                            return fromUtf32 ((cast(const dchar*) p)[0..1], result); 
    488504 
    489505                       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. 
    490514                            Interface* pi = **cast(Interface ***)*cast(void**) p; 
    491515                            Object o = cast(Object)(*cast(void**)p - pi.offset);