static void printEnum( c_enumeration _this, toolActionData actionData) { c_object o; c_long i, size; c_constant constant; o = c_iterObject(actionData->stack, 0); size = c_enumerationCount(_this); i = *(c_long *)o; if ((i < 0) || (i > size)) { printf("(%d) \"Bad enumeration value\"\n", i); } else { constant = c_enumeration(_this)->elements[i]; printf("%s",_METANAME(constant)); } }
c_char * idl_genJavaLiteralValueImage( c_value literal, c_type type) { c_char * valueImg = NULL; c_char *val2; int i; if (c_baseObject(type)->kind != M_ENUMERATION) { switch (literal.kind) { case V_OCTET: valueImg = os_malloc (40); snprintf(valueImg, 40, "%d", literal.is.Octet); break; case V_FLOAT: case V_DOUBLE: val2 = os_malloc(45); valueImg = os_malloc(45); snprintf(val2, 45, "%40.17g", literal.is.Double); i = 0; while (val2[i] == ' ') { i++; } os_strncpy(valueImg, &val2[i], 40); os_free(val2); if ((strchr(valueImg, '.') == NULL) && (strchr(valueImg, 'E') == NULL)) { strcat(valueImg, ".0"); } break; case V_STRING: valueImg = os_malloc(strlen(literal.is.String)+3); snprintf(valueImg, strlen(literal.is.String)+3, "\"%s\"", literal.is.String); break; case V_BOOLEAN: valueImg = os_malloc(40); if (literal.is.Boolean) { snprintf(valueImg, 40, "true"); } else { snprintf (valueImg, 40, "false"); } break; case V_LONGLONG: valueImg = os_malloc(40); switch (c_primitive(type)->kind) { case P_SHORT: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ snprintf(valueImg, 40, "%hu", (c_short)literal.is.LongLong); break; case P_USHORT: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ snprintf(valueImg, 40, "%hd", (c_short)literal.is.LongLong); break; case P_LONG: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ snprintf(valueImg, 40, "%u", (c_long)literal.is.LongLong); break; case P_ULONG: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ snprintf(valueImg, 40, "%d", (c_long)literal.is.LongLong); break; case P_LONGLONG: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ snprintf(valueImg, 40, "%"PA_PRIu64"L", (c_longlong)literal.is.LongLong); break; case P_ULONGLONG: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ snprintf(valueImg, 40, "%"PA_PRId64"L", (c_longlong)literal.is.LongLong); break; case P_CHAR: snprintf(valueImg, 40, "%d", (unsigned char)literal.is.LongLong); break; case P_OCTET: snprintf(valueImg, 40, "%d", (unsigned char)literal.is.LongLong); break; case P_ADDRESS: snprintf(valueImg, 40, PA_ADDRFMT, (PA_ADDRCAST)literal.is.LongLong); break; case P_UNDEFINED: case P_BOOLEAN: case P_WCHAR: case P_FLOAT: case P_DOUBLE: case P_VOIDP: case P_MUTEX: case P_LOCK: case P_COND: case P_COUNT: case P_PA_UINT32: case P_PA_UINTPTR: case P_PA_VOIDP: /* Do nothing */ break; } break; case V_SHORT: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%hu", literal.is.Short); break; case V_LONG: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%u", (c_long)literal.is.Long); break; case V_USHORT: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%hd", (c_short)literal.is.UShort); break; case V_ULONG: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%d", (c_long)literal.is.ULong); break; case V_ULONGLONG: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%" PA_PRId64, (c_longlong)literal.is.ULongLong); break; case V_ADDRESS: valueImg = os_malloc(40); snprintf(valueImg, 40, PA_ADDRFMT, (PA_ADDRCAST)literal.is.Address); break; case V_CHAR: valueImg = os_malloc(40); snprintf(valueImg, 40, "%u", (unsigned char)literal.is.Char); break; case V_UNDEFINED: case V_WCHAR: case V_WSTRING: case V_FIXED: case V_VOIDP: case V_OBJECT: case V_COUNT: /* Invalid types for literal constants*/ /* FALL THROUGH */ default: valueImg = NULL; break; } } else { const char *ENUM_TEMPLATE = "%s.%s"; char *javaEnumTp = idl_javaId(c_metaObject(type)->name); char *javaEnumLabel = idl_javaId(c_metaObject(c_enumeration(type)->elements[literal.is.Long])->name); size_t valLen = strlen(javaEnumTp) + strlen(javaEnumLabel) + strlen(ENUM_TEMPLATE) + 1; valueImg = os_malloc(valLen); snprintf(valueImg, valLen, ENUM_TEMPLATE, javaEnumTp, javaEnumLabel); os_free(javaEnumTp); os_free(javaEnumLabel); } return valueImg; }