From 879bed7df6e32c2c49a846ac70c8501d2a7b8e19 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Tue, 2 Dec 2008 01:44:17 +0100 Subject: [PATCH] Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF. --- CMakeLists.txt | 5 +++++ gen/classes.cpp | 16 ++++++++++++++-- tests/mini/classinfo3.d | 4 +++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17d18933..b2b8698f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ execute_process( set(D_VERSION 1 CACHE STRING "D language version") option(USE_BOEHM_GC "use the Boehm garbage collector internally") +option(GENERATE_OFFTI "generate complete ClassInfo.offTi arrays") if(D_VERSION EQUAL 1) set(DMDFE_PATH dmd) @@ -142,6 +143,10 @@ if(USE_BOEHM_GC) add_definitions(-DUSE_BOEHM_GC) endif(USE_BOEHM_GC) +if(GENERATE_OFFTI) + add_definitions(-DGENERATE_OFFTI) +endif(GENERATE_OFFTI) + if(CMAKE_MINOR_VERSION LESS 6) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "output dir for built executables") set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "output dir for built libraries") diff --git a/gen/classes.cpp b/gen/classes.cpp index 071195dd..3d67abcb 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -1312,6 +1312,8 @@ void DtoDeclareClassInfo(ClassDeclaration* cd) ////////////////////////////////////////////////////////////////////////////////////////// +#if GENERATE_OFFTI + // build a single element for the OffsetInfo[] of ClassInfo static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd) { @@ -1371,6 +1373,8 @@ static LLConstant* build_offti_array(ClassDeclaration* cd, const LLType* arrayT) return DtoConstSlice(size, ptr); } +#endif // GENERATE_OFFTI + static LLConstant* build_class_dtor(ClassDeclaration* cd) { FuncDeclaration* dtor = cd->dtor; @@ -1581,10 +1585,20 @@ void DtoDefineClassInfo(ClassDeclaration* cd) // offset typeinfo VarDeclaration* offTiVar = (VarDeclaration*)cinfo->fields.data[9]; const LLType* offTiTy = DtoType(offTiVar->type); + +#if GENERATE_OFFTI + if (cd->isInterfaceDeclaration()) c = LLConstant::getNullValue(offTiTy); else c = build_offti_array(cd, offTiTy); + +#else // GENERATE_OFFTI + + c = LLConstant::getNullValue(offTiTy); + +#endif // GENERATE_OFFTI + inits.push_back(c); // default constructor @@ -1606,8 +1620,6 @@ void DtoDefineClassInfo(ClassDeclaration* cd) // FIXME: fill it out! inits.push_back( LLConstant::getNullValue(xgetTy) ); - -#else #endif /*size_t n = inits.size(); diff --git a/tests/mini/classinfo3.d b/tests/mini/classinfo3.d index a1e857e6..05bf394e 100644 --- a/tests/mini/classinfo3.d +++ b/tests/mini/classinfo3.d @@ -11,7 +11,8 @@ class C void main() { auto c = C.classinfo; - assert(c.offTi !is null); + if (c.offTi !is null) + { assert(c.offTi.length == 4); size_t base = 2*size_t.sizeof; @@ -24,4 +25,5 @@ void main() assert(c.offTi[2].ti == typeid(long)); assert(c.offTi[3].offset == base+16); assert(c.offTi[3].ti == typeid(int)); + } }