# HG changeset patch # User ChristianK # Date 1216126396 -7200 # Node ID 83ade4f4025a887a52840d4787907202c6105f0c # Parent f2b6080126996b5a761b661f6d47fe592e0b2a5c [svn r393] Started implementation for DtoNullValue. diff -r f2b608012699 -r 83ade4f4025a gen/llvmhelpers.cpp --- 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()) diff -r f2b608012699 -r 83ade4f4025a gen/llvmhelpers.h --- 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);