changeset 372:83ade4f4025a trunk

[svn r393] Started implementation for DtoNullValue.
author ChristianK
date Tue, 15 Jul 2008 14:53:16 +0200
parents f2b608012699
children d1574e142e93
files gen/llvmhelpers.cpp gen/llvmhelpers.h
diffstat 2 files changed, 47 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Tue Jul 15 10:56:16 2008 +0200
+++ b/gen/llvmhelpers.cpp	Tue Jul 15 14:53:16 2008 +0200
@@ -630,6 +630,49 @@
 
 /****************************************************************************************/
 /*////////////////////////////////////////////////////////////////////////////////////////
+//      NULL VALUE HELPER
+////////////////////////////////////////////////////////////////////////////////////////*/
+
+DValue* DtoNullValue(Type* type)
+{
+    Type* basetype = type->toBasetype();
+    TY basety = basetype->ty;
+    const LLType* lltype = DtoType(basetype);
+
+    // complex, needs to be first since complex are also floating
+    if (basetype->iscomplex())
+    {
+        const LLType* basefp = DtoComplexBaseType(basetype);
+        return new DComplexValue(type, LLConstant::getNullValue(basefp), LLConstant::getNullValue(basefp));
+    }
+    // integer, floating, pointer and class have no special representation
+    else if (basetype->isintegral() || basetype->isfloating() || basety == Tpointer || basety == Tclass)
+    {
+        return new DConstValue(type, LLConstant::getNullValue(lltype));
+    }
+    // dynamic array
+    else if (basety == Tarray)
+    {
+        //TODO: What types do the constants here need to have?
+        return new DSliceValue(type, NULL, NULL);
+    }
+    // delegate
+    else if (basety == Tdelegate)
+    {
+        //TODO: Is this correct?
+        return new DNullValue(type, LLConstant::getNullValue(lltype));
+    }
+
+    // unknown
+    std::cout << "unsupported: null value for " << type->toChars() << '\n';
+    assert(0);
+    return 0;
+
+}
+
+
+/****************************************************************************************/
+/*////////////////////////////////////////////////////////////////////////////////////////
 //      CASTING HELPERS
 ////////////////////////////////////////////////////////////////////////////////////////*/
 
@@ -1335,8 +1378,7 @@
     // complex
     else if (dtype->iscomplex())
     {
-        // huh?
-        return DtoComplexEquals(TOKnotequal, dval, DtoComplex(dtype, new DNullValue(Type::tint8, llvm::ConstantInt::get(LLType::Int8Ty, 0))));
+        return DtoComplexEquals(TOKnotequal, dval, DtoNullValue(dtype));
     }
     // floating point
     else if (dtype->isfloating())
--- a/gen/llvmhelpers.h	Tue Jul 15 10:56:16 2008 +0200
+++ b/gen/llvmhelpers.h	Tue Jul 15 14:53:16 2008 +0200
@@ -41,6 +41,9 @@
 // basic operations
 void DtoAssign(DValue* lhs, DValue* rhs);
 
+// create a null dvalue
+DValue* DtoNullValue(Type* t);
+
 // casts
 DValue* DtoCastInt(DValue* val, Type* to);
 DValue* DtoCastPtr(DValue* val, Type* to);