ECode CStructInfo::InitStatic(
    /* [in] */ CClsModule* clsModule,
    /* [in] */ StructDirEntry* structDirEntry)
{
    mClsModule = clsModule;

    Int32 base = mClsModule->mBase;
    mStructDirEntry = structDirEntry;
    mName = adjustNameAddr(base, mStructDirEntry->mName);
    StructDescriptor* desc = adjustStructDescAddr(base, structDirEntry->mDesc);
    StructElement* elem = NULL;

    ECode ec = NOERROR;
    mFieldTypeInfos = ArrayOf<IDataTypeInfo*>::Alloc(desc->mElementCount);
    if (!mFieldTypeInfos) {
        ec = E_OUT_OF_MEMORY;
        goto EExit;
    }

    mFieldNames = ArrayOf<String>::Alloc(desc->mElementCount);
    if (!mFieldNames) {
        ec = E_OUT_OF_MEMORY;
        goto EExit;
    }

    for (Int32 i = 0; i < desc->mElementCount; i++) {
        elem = getStructElementAddr(base, desc->mElements, i);
        (*mFieldNames)[i] = adjustNameAddr(base, elem->mName);

        AutoPtr<IDataTypeInfo> dataTypeInfo;
        ec = g_objInfoList.AcquireDataTypeInfo(mClsModule,
                &elem->mType, (IDataTypeInfo**)&dataTypeInfo, TRUE);
        if (FAILED(ec)) goto EExit;
        mFieldTypeInfos->Set(i, dataTypeInfo);
    }

    ec = InitFieldElement();
    if (FAILED(ec)) goto EExit;

    ec = InitFieldInfos();
    if (FAILED(ec)) goto EExit;

    return NOERROR;

EExit:
    mFieldNames = NULL;
    mFieldTypeInfos = NULL;

    return ec;
}
示例#2
0
UInt32 GetDataTypeSize(
    /* [in] */ const CClsModule* clsModule,
    /* [in] */ TypeDescriptor* typeDesc)
{
    UInt32 size = 0;

    CLSModule* module = clsModule->mClsMod;
    if (typeDesc->mType == Type_alias) {
        TypeDescriptor orgTypeDesc;
        _GetOriginalType(clsModule, typeDesc, &orgTypeDesc);
        typeDesc = &orgTypeDesc;
    }

    if (typeDesc->mPointer) {
        return sizeof(void *);
    }

    ArrayDirEntry* arrayDir = NULL;
    StructDirEntry* structDir = NULL;
    Int32 base = clsModule->mBase;
    switch (typeDesc->mType) {
        case Type_Char16:
            size = sizeof(Char16);
            break;
        case Type_Char32:
            size = sizeof(Char32);
            break;
        case Type_Int8:
            size = sizeof(Int8);
            break;
        case Type_Int16:
            size = sizeof(Int16);
            break;
        case Type_Int32:
            size = sizeof(Int32);
            break;
        case Type_Int64:
            size = sizeof(Int64);
            break;
        case Type_UInt16:
            size = sizeof(UInt16);
            break;
        case Type_UInt32:
            size = sizeof(UInt32);
            break;
        case Type_UInt64:
            size = sizeof(UInt64);
            break;
        case Type_Byte:
            size = sizeof(Byte);
            break;
        case Type_Boolean:
            size = sizeof(Boolean);
            break;
        case Type_EMuid:
            size = sizeof(EMuid);
            break;
        case Type_Float:
            size = sizeof(float);
            break;
        case Type_Double:
            size = sizeof(double);
            break;
        case Type_PVoid:
            size = 4;
            break;
        case Type_ECode:
            size = sizeof(ECode);
            break;
        case Type_EGuid:
            size = sizeof(ClassID);
            break;
        case Type_EventHandler:
            size = sizeof(EventHandler);
            break;
        case Type_String:
            // [in] String (in car) --> /* [in] */ const String& (in c++), so should be sizeof(String*)
            size = sizeof(String*);
            break;
        case Type_interface:
            size = sizeof(PInterface);
            break;
        case Type_struct:
            structDir = getStructDirAddr(base,
                    module->mStructDirs, typeDesc->mIndex);
            size = adjustStructDescAddr(base, structDir->mDesc)->nAlignSize;
            break;
        case Type_Array:
            arrayDir = getArrayDirAddr(base,
                    module->mArrayDirs, typeDesc->mIndex);
            size = GetDataTypeSize(clsModule, &arrayDir->type) * arrayDir->nElements;
            break;
        case Type_enum:
            size = sizeof(int);
            break;
        case Type_ArrayOf:
            size = GetDataTypeSize(clsModule,
                    adjustNestedTypeAddr(base, typeDesc->mNestedType));
            break;
//        case Type_EzEnum:
//            size = sizeof(EzEnum);
//            break;
        case Type_alias:
        case Type_const:
        default:
            size = 0;
    }

    return size;
}