mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-11-29 20:33:50 +01:00
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
Added initial support for CatExp aka 'a ~ b' Fixed global constant static arrays initialized with string literals Fixed casting any dynamic array to void* Fixed new expression with temporary storage Fixed alias declarations in function scope Fixed relational comparisons of pointers
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
module arrays8;
|
||||
|
||||
void main()
|
||||
{
|
||||
char[] a = "hello ";
|
||||
printf(" \"%s\".length = %u\n", a.ptr, a.length);
|
||||
char[] b = "world";
|
||||
printf(" \"%s\".length = %u\n", b.ptr, b.length);
|
||||
char[] c = a ~ b;
|
||||
printf("After 'a ~ b':\n");
|
||||
printf(" \"%.*s\".length = %u\n", a.length, a.ptr, a.length);
|
||||
printf(" \"%.*s\".length = %u\n", b.length, b.ptr, b.length);
|
||||
printf(" \"%.*s\".length = %u\n", c.length, c.ptr, c.length);
|
||||
assert(c.length == a.length + b.length);
|
||||
assert(c !is a);
|
||||
assert(c !is b);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
module bug34;
|
||||
|
||||
class MyTypeInfo_Pointer
|
||||
{
|
||||
char[] toString() { return m_next.toString() ~ "*"; }
|
||||
|
||||
int opEquals(Object o)
|
||||
{ TypeInfo_Pointer c;
|
||||
|
||||
return this is o ||
|
||||
((c = cast(TypeInfo_Pointer)o) !is null &&
|
||||
this.m_next == c.m_next);
|
||||
}
|
||||
|
||||
hash_t getHash(void *p)
|
||||
{
|
||||
return cast(uint)*cast(void* *)p;
|
||||
}
|
||||
|
||||
int equals(void *p1, void *p2)
|
||||
{
|
||||
return cast(int)(*cast(void* *)p1 == *cast(void* *)p2);
|
||||
}
|
||||
|
||||
int compare(void *p1, void *p2)
|
||||
{
|
||||
if (*cast(void* *)p1 < *cast(void* *)p2)
|
||||
return -1;
|
||||
else if (*cast(void* *)p1 > *cast(void* *)p2)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t tsize()
|
||||
{
|
||||
return (void*).sizeof;
|
||||
}
|
||||
|
||||
void swap(void *p1, void *p2)
|
||||
{ void* tmp;
|
||||
tmp = *cast(void**)p1;
|
||||
*cast(void**)p1 = *cast(void**)p2;
|
||||
*cast(void**)p2 = tmp;
|
||||
}
|
||||
|
||||
TypeInfo next() { return m_next; }
|
||||
uint flags() { return 1; }
|
||||
|
||||
TypeInfo m_next;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
module bug35;
|
||||
|
||||
private const char[10] digits = "0123456789"; /// 0..9
|
||||
|
||||
void main()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
module bug36;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[] a;
|
||||
void* cp = cast(void*)a;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
module typeinfo4;
|
||||
|
||||
void main()
|
||||
{
|
||||
auto ti = typeid(void*);
|
||||
assert(ti.toString() == "void*");
|
||||
assert(ti.tsize() == size_t.sizeof);
|
||||
void* a = null;
|
||||
void* b = a + 1;
|
||||
assert(ti.compare(&a,&b) < 0);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
module typeinfo5;
|
||||
|
||||
void main()
|
||||
{
|
||||
enum E : uint {
|
||||
A,B,C
|
||||
}
|
||||
auto ti = typeid(E);
|
||||
assert(ti.next() is typeid(uint));
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
module typeinfo6;
|
||||
|
||||
void main()
|
||||
{
|
||||
auto ti = typeid(int[]);
|
||||
assert(ti.toString() == "int[]");
|
||||
assert(ti.next() is typeid(int));
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
module typeinfo7;
|
||||
|
||||
int func(long)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
auto ti = typeid(typeof(func));
|
||||
auto s = ti.toString;
|
||||
printf("%.*s\n", s.length, s.ptr);
|
||||
assert(s == "int()");
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
module typeinfo8;
|
||||
|
||||
struct S
|
||||
{
|
||||
void func()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
S a;
|
||||
auto ti = typeid(typeof(&a.func));
|
||||
auto s = ti.toString;
|
||||
printf("%.*s\n", s.length, s.ptr);
|
||||
assert(s == "void delegate()");
|
||||
}
|
||||
Reference in New Issue
Block a user