[svn r57] Added most basic TypeInfo (rebuild lphobos).

Fixed some SymOffExp bugs.
Added another typeinfo test case.
This commit is contained in:
Tomas Lindquist Olsen
2007-10-23 07:16:02 +02:00
parent 5fee3fc8b7
commit b72a4fa645
14 changed files with 533 additions and 4 deletions

View File

@@ -0,0 +1,45 @@
// dchar
module typeinfo.ti_dchar;
class TypeInfo_w : TypeInfo
{
char[] toString() { return "dchar"; }
hash_t getHash(void *p)
{
return *cast(dchar *)p;
}
int equals(void *p1, void *p2)
{
return *cast(dchar *)p1 == *cast(dchar *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(dchar *)p1 - *cast(dchar *)p2;
}
size_t tsize()
{
return dchar.sizeof;
}
void swap(void *p1, void *p2)
{
dchar t;
t = *cast(dchar *)p1;
*cast(dchar *)p1 = *cast(dchar *)p2;
*cast(dchar *)p2 = t;
}
void[] init()
{ static dchar c;
return (cast(dchar *)&c)[0 .. 1];
}
}

View File

@@ -0,0 +1,40 @@
// delegate
module typeinfo.ti_delegate;
alias void delegate(int) dg;
class TypeInfo_D : TypeInfo
{
hash_t getHash(void *p)
{ long l = *cast(long *)p;
return cast(uint)(l + (l >> 32));
}
int equals(void *p1, void *p2)
{
return *cast(dg *)p1 == *cast(dg *)p2;
}
size_t tsize()
{
return dg.sizeof;
}
void swap(void *p1, void *p2)
{
dg t;
t = *cast(dg *)p1;
*cast(dg *)p1 = *cast(dg *)p2;
*cast(dg *)p2 = t;
}
uint flags()
{
return 1;
}
}

View File

@@ -0,0 +1,70 @@
// double
module typeinfo.ti_double;
class TypeInfo_d : TypeInfo
{
char[] toString() { return "double"; }
hash_t getHash(void *p)
{
return (cast(uint *)p)[0] + (cast(uint *)p)[1];
}
static bool _isnan(double d)
{
return d !<>= 0;
}
static int _equals(double f1, double f2)
{
return f1 == f2 ||
(_isnan(f1) && _isnan(f2));
}
static int _compare(double d1, double d2)
{
if (d1 !<>= d2) // if either are NaN
{
if (_isnan(d1))
{ if (_isnan(d2))
return 0;
return -1;
}
return 1;
}
return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
}
int equals(void *p1, void *p2)
{
return _equals(*cast(double *)p1, *cast(double *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(double *)p1, *cast(double *)p2);
}
size_t tsize()
{
return double.sizeof;
}
void swap(void *p1, void *p2)
{
double t;
t = *cast(double *)p1;
*cast(double *)p1 = *cast(double *)p2;
*cast(double *)p2 = t;
}
void[] init()
{ static double r;
return (&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,70 @@
// float
module typeinfo.ti_float;
class TypeInfo_f : TypeInfo
{
char[] toString() { return "float"; }
hash_t getHash(void *p)
{
return *cast(uint *)p;
}
static bool _isnan(float f)
{
return f !<>= 0;
}
static int _equals(float f1, float f2)
{
return f1 == f2 ||
(_isnan(f1) && _isnan(f2));
}
static int _compare(float d1, float d2)
{
if (d1 !<>= d2) // if either are NaN
{
if (_isnan(d1))
{ if (_isnan(d2))
return 0;
return -1;
}
return 1;
}
return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
}
int equals(void *p1, void *p2)
{
return _equals(*cast(float *)p1, *cast(float *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(float *)p1, *cast(float *)p2);
}
size_t tsize()
{
return float.sizeof;
}
void swap(void *p1, void *p2)
{
float t;
t = *cast(float *)p1;
*cast(float *)p1 = *cast(float *)p2;
*cast(float *)p2 = t;
}
void[] init()
{ static float r;
return (&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,43 @@
// long
module typeinfo.ti_long;
class TypeInfo_l : TypeInfo
{
char[] toString() { return "long"; }
hash_t getHash(void *p)
{
return *cast(uint *)p + (cast(uint *)p)[1];
}
int equals(void *p1, void *p2)
{
return *cast(long *)p1 == *cast(long *)p2;
}
int compare(void *p1, void *p2)
{
if (*cast(long *)p1 < *cast(long *)p2)
return -1;
else if (*cast(long *)p1 > *cast(long *)p2)
return 1;
return 0;
}
size_t tsize()
{
return long.sizeof;
}
void swap(void *p1, void *p2)
{
long t;
t = *cast(long *)p1;
*cast(long *)p1 = *cast(long *)p2;
*cast(long *)p2 = t;
}
}

View File

@@ -0,0 +1,70 @@
// real
module typeinfo.ti_real;
class TypeInfo_e : TypeInfo
{
char[] toString() { return "real"; }
hash_t getHash(void *p)
{
return (cast(uint *)p)[0] + (cast(uint *)p)[1] + (cast(ushort *)p)[4];
}
static bool _isnan(real r)
{
return r !<>= 0;
}
static int _equals(real f1, real f2)
{
return f1 == f2 ||
(_isnan(f1) && _isnan(f2));
}
static int _compare(real d1, real d2)
{
if (d1 !<>= d2) // if either are NaN
{
if (_isnan(d1))
{ if (_isnan(d2))
return 0;
return -1;
}
return 1;
}
return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
}
int equals(void *p1, void *p2)
{
return _equals(*cast(real *)p1, *cast(real *)p2);
}
int compare(void *p1, void *p2)
{
return _compare(*cast(real *)p1, *cast(real *)p2);
}
size_t tsize()
{
return real.sizeof;
}
void swap(void *p1, void *p2)
{
real t;
t = *cast(real *)p1;
*cast(real *)p1 = *cast(real *)p2;
*cast(real *)p2 = t;
}
void[] init()
{ static real r;
return (&r)[0 .. 1];
}
}

View File

@@ -0,0 +1,43 @@
// ulong
module typeinfo.ti_ulong;
class TypeInfo_m : TypeInfo
{
char[] toString() { return "ulong"; }
hash_t getHash(void *p)
{
return *cast(uint *)p + (cast(uint *)p)[1];
}
int equals(void *p1, void *p2)
{
return *cast(ulong *)p1 == *cast(ulong *)p2;
}
int compare(void *p1, void *p2)
{
if (*cast(ulong *)p1 < *cast(ulong *)p2)
return -1;
else if (*cast(ulong *)p1 > *cast(ulong *)p2)
return 1;
return 0;
}
size_t tsize()
{
return ulong.sizeof;
}
void swap(void *p1, void *p2)
{
ulong t;
t = *cast(ulong *)p1;
*cast(ulong *)p1 = *cast(ulong *)p2;
*cast(ulong *)p2 = t;
}
}

View File

@@ -0,0 +1,44 @@
// void
module typeinfo.ti_void;
class TypeInfo_v : TypeInfo
{
char[] toString() { return "void"; }
hash_t getHash(void *p)
{
assert(0);
}
int equals(void *p1, void *p2)
{
return *cast(byte *)p1 == *cast(byte *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(byte *)p1 - *cast(byte *)p2;
}
size_t tsize()
{
return void.sizeof;
}
void swap(void *p1, void *p2)
{
byte t;
t = *cast(byte *)p1;
*cast(byte *)p1 = *cast(byte *)p2;
*cast(byte *)p2 = t;
}
uint flags()
{
return 1;
}
}

View File

@@ -0,0 +1,44 @@
module typeinfo.ti_wchar;
class TypeInfo_u : TypeInfo
{
char[] toString() { return "wchar"; }
hash_t getHash(void *p)
{
return *cast(wchar *)p;
}
int equals(void *p1, void *p2)
{
return *cast(wchar *)p1 == *cast(wchar *)p2;
}
int compare(void *p1, void *p2)
{
return *cast(wchar *)p1 - *cast(wchar *)p2;
}
size_t tsize()
{
return wchar.sizeof;
}
void swap(void *p1, void *p2)
{
wchar t;
t = *cast(wchar *)p1;
*cast(wchar *)p1 = *cast(wchar *)p2;
*cast(wchar *)p2 = t;
}
void[] init()
{ static wchar c;
return (cast(wchar *)&c)[0 .. 1];
}
}

20
lphobos/typeinfos.d Normal file
View File

@@ -0,0 +1,20 @@
module typeinfos;
import
typeinfo.ti_byte,
typeinfo.ti_char,
typeinfo.ti_delegate,
typeinfo.ti_dchar,
typeinfo.ti_double,
typeinfo.ti_float,
typeinfo.ti_int,
typeinfo.ti_long,
typeinfo.ti_ptr,
typeinfo.ti_real,
typeinfo.ti_short,
typeinfo.ti_ubyte,
typeinfo.ti_uint,
typeinfo.ti_ulong,
typeinfo.ti_ushort,
typeinfo.ti_void,
typeinfo.ti_wchar;