static void printPrimitive( c_type _this, toolActionData actionData) { c_object o; c_value v; c_char *str; #define _CASE_(l,f,t) \ case P_##l: \ { \ v.is.f = *(t *)o; \ v.kind = V_##l; \ str = c_valueImage(v); \ printf("%s",c_valueImage(v)); \ os_free(str); \ } \ break o = c_iterObject(actionData->stack, 0); switch(c_primitiveKind(_this)) { _CASE_(BOOLEAN,Boolean,c_bool); _CASE_(SHORT,Short,c_short); _CASE_(LONG,Long,c_long); _CASE_(LONGLONG,LongLong,c_longlong); _CASE_(OCTET,Octet,c_octet); _CASE_(USHORT,UShort,c_ushort); _CASE_(ULONG,ULong,c_ulong); _CASE_(ULONGLONG,ULongLong,c_ulonglong); _CASE_(CHAR,Char,c_char); _CASE_(WCHAR,WChar,c_wchar); _CASE_(FLOAT,Float,c_float); _CASE_(DOUBLE,Double,c_double); case P_ADDRESS: v.is.Address = *(c_address *)o; v.kind = V_ADDRESS; str = c_valueImage(v); printf("<%s>",c_valueImage(v)); os_free(str); break; case P_VOIDP: v.is.Voidp = *(c_voidp *)o; v.kind = V_VOIDP; str = c_valueImage(v); printf("<%s>",c_valueImage(v)); os_free(str); break; case P_MUTEX: case P_LOCK: case P_COND: printf("<******>"); break; default: printf("Specified type <0x"PA_ADDRFMT"> is not a valid primitive type\n", (os_address)_this); break; } #undef _CASE_ }
void in_messageDeserializerReadUnion( in_messageDeserializer _this, c_type type, c_voidp data) { c_union utype = c_union(type); c_type caseType; c_type switchType; c_unionCase deflt; c_unionCase activeCase; c_unionCase currentCase; c_value switchValue; c_literal label; c_voidp o; os_uint32 length; os_uint32 i; os_uint32 j; os_uint32 n; assert(_this); assert(type); assert(data); /* action for the switch */ switchType = c_typeActualType(utype->switchType); in_messageDeserializerReadType(_this, switchType, data); /* Determine value of the switch field */ switch (c_baseObjectKind(switchType)) { case M_PRIMITIVE: switch (c_primitiveKind(switchType)) { #define __CASE__(prim, type) \ case prim: switchValue = type##Value(*((type *)data)); break; __CASE__(P_BOOLEAN,c_bool) __CASE__(P_CHAR,c_char) __CASE__(P_SHORT,c_short) __CASE__(P_USHORT,c_ushort) __CASE__(P_LONG,c_long) __CASE__(P_ULONG,c_ulong) __CASE__(P_LONGLONG,c_longlong) __CASE__(P_ULONGLONG,c_ulonglong) #undef __CASE__ default: switchValue = c_undefinedValue(); assert(FALSE); break; } break; case M_ENUMERATION: switchValue = c_longValue(*(c_long *)data); break; default: switchValue = c_undefinedValue(); assert(FALSE); break; } /* Determine the label corresponding to this field */ activeCase = NULL; deflt = NULL; length = c_arraySize(utype->cases); for (i = 0; (i < length) && !activeCase; i++) { currentCase = c_unionCase(utype->cases[i]); n = c_arraySize(currentCase->labels); if (n > 0) { for (j = 0; (j < n) && !activeCase; j++) { label = c_literal(currentCase->labels[j]); if (c_valueCompare(switchValue, label->value) == C_EQ) { activeCase = currentCase; } } } else { deflt = currentCase; } } if(!activeCase) { activeCase = deflt; } assert(activeCase); if (activeCase) { if (c_type(utype)->alignment >= utype->switchType->size) { length = c_type(utype)->alignment; } else { length = utype->switchType->size; } o = C_DISPLACE(data, (c_address)length); caseType = c_typeActualType(c_specifierType(activeCase)); in_messageDeserializerReadType(_this, caseType, o); } }