static char* sig_to_name (MonoMethodSignature *sig, const char *prefix) { int i; char *result; GString *res = g_string_new (""); char *p; if (prefix) { g_string_append (res, prefix); g_string_append_c (res, '_'); } mono_type_get_desc (res, sig->ret, TRUE); for (i = 0; i < sig->param_count; ++i) { g_string_append_c (res, '_'); mono_type_get_desc (res, sig->params [i], TRUE); } result = res->str; p = result; /* remove chars Sun's asssembler doesn't like */ while (*p != '\0') { if (*p == '.' || *p == '/') *p = '_'; else if (*p == '&') *p = '$'; else if (*p == '[' || *p == ']') *p = 'X'; p++; } g_string_free (res, FALSE); return result; }
char* mono_type_full_name (MonoType *type) { GString *str; str = g_string_new (""); mono_type_get_desc (str, type, TRUE); return g_string_free (str, FALSE); }
static void ginst_get_desc (GString *str, MonoGenericInst *ginst) { int i; for (i = 0; i < ginst->type_argc; ++i) { if (i > 0) g_string_append (str, ", "); mono_type_get_desc (str, ginst->type_argv [i], TRUE); } }
char* mono_signature_full_name (MonoMethodSignature *sig) { int i; char *result; GString *res; if (!sig) return g_strdup ("<invalid signature>"); res = g_string_new (""); mono_type_get_desc (res, sig->ret, TRUE); g_string_append_c (res, '('); for (i = 0; i < sig->param_count; ++i) { if (i > 0) g_string_append_c (res, ','); mono_type_get_desc (res, sig->params [i], TRUE); } g_string_append_c (res, ')'); result = res->str; g_string_free (res, FALSE); return result; }
void mono_error_set_field_missing (MonoError *error, MonoClass *klass, const char *field_name, MonoType *sig, const char *reason, ...) { char *result; GString *res; res = g_string_new ("Field not found: "); if (sig) { mono_type_get_desc (res, sig, TRUE); g_string_append_c (res, ' '); } if (klass) { if (m_class_get_name_space (klass)) { g_string_append (res, m_class_get_name_space (klass)); g_string_append_c (res, '.'); } g_string_append (res, m_class_get_name (klass)); } else { g_string_append (res, "<unknown type>"); } g_string_append_c (res, '.'); if (field_name) g_string_append (res, field_name); else g_string_append (res, "<unknown field>"); if (reason && *reason) { va_list args; va_start (args, reason); g_string_append (res, " Due to: "); g_string_append_vprintf (res, reason, args); va_end (args); } result = res->str; g_string_free (res, FALSE); mono_error_set_specific (error, MONO_ERROR_MISSING_FIELD, result); }
char* mono_signature_get_desc (MonoMethodSignature *sig, gboolean include_namespace) { int i; char *result; GString *res; if (!sig) return g_strdup ("<invalid signature>"); res = g_string_new (""); for (i = 0; i < sig->param_count; ++i) { if (i > 0) g_string_append_c (res, ','); mono_type_get_desc (res, sig->params [i], include_namespace); } result = res->str; g_string_free (res, FALSE); return result; }
void mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace) { int i; switch (type->type) { case MONO_TYPE_VOID: g_string_append (res, "void"); break; case MONO_TYPE_CHAR: g_string_append (res, "char"); break; case MONO_TYPE_BOOLEAN: g_string_append (res, "bool"); break; case MONO_TYPE_U1: g_string_append (res, "byte"); break; case MONO_TYPE_I1: g_string_append (res, "sbyte"); break; case MONO_TYPE_U2: g_string_append (res, "uint16"); break; case MONO_TYPE_I2: g_string_append (res, "int16"); break; case MONO_TYPE_U4: g_string_append (res, "uint"); break; case MONO_TYPE_I4: g_string_append (res, "int"); break; case MONO_TYPE_U8: g_string_append (res, "ulong"); break; case MONO_TYPE_I8: g_string_append (res, "long"); break; case MONO_TYPE_FNPTR: /* who cares for the exact signature? */ g_string_append (res, "*()"); break; case MONO_TYPE_U: g_string_append (res, "uintptr"); break; case MONO_TYPE_I: g_string_append (res, "intptr"); break; case MONO_TYPE_R4: g_string_append (res, "single"); break; case MONO_TYPE_R8: g_string_append (res, "double"); break; case MONO_TYPE_STRING: g_string_append (res, "string"); break; case MONO_TYPE_OBJECT: g_string_append (res, "object"); break; case MONO_TYPE_PTR: mono_type_get_desc (res, type->data.type, include_namespace); g_string_append_c (res, '*'); break; case MONO_TYPE_ARRAY: mono_type_get_desc (res, &type->data.array->eklass->byval_arg, include_namespace); g_string_append_printf (res, "[%d]", type->data.array->rank); break; case MONO_TYPE_SZARRAY: mono_type_get_desc (res, &type->data.klass->byval_arg, include_namespace); g_string_append (res, "[]"); break; case MONO_TYPE_CLASS: case MONO_TYPE_VALUETYPE: append_class_name (res, type->data.klass, include_namespace); break; case MONO_TYPE_GENERICINST: { MonoGenericContext *context; mono_type_get_desc (res, &type->data.generic_class->container_class->byval_arg, include_namespace); g_string_append (res, "<"); context = &type->data.generic_class->context; if (context->class_inst) { for (i = 0; i < context->class_inst->type_argc; ++i) { if (i > 0) g_string_append (res, ", "); mono_type_get_desc (res, context->class_inst->type_argv [i], include_namespace); } } if (context->method_inst) { if (context->class_inst) g_string_append (res, "; "); for (i = 0; i < context->method_inst->type_argc; ++i) { if (i > 0) g_string_append (res, ", "); mono_type_get_desc (res, context->method_inst->type_argv [i], include_namespace); } } g_string_append (res, ">"); break; } case MONO_TYPE_VAR: case MONO_TYPE_MVAR: if (type->data.generic_param) { const char *name = mono_generic_param_name (type->data.generic_param); if (name) g_string_append (res, name); else g_string_append_printf (res, "%s%d", type->type == MONO_TYPE_VAR ? "!" : "!!", mono_generic_param_num (type->data.generic_param)); } else { g_string_append (res, "<unknown>"); } break; case MONO_TYPE_TYPEDBYREF: g_string_append (res, "typedbyref"); break; default: break; } if (type->byref) g_string_append_c (res, '&'); }
/* * Sets @error to a method missing error. */ void mono_error_set_method_missing (MonoError *error, MonoClass *klass, const char *method_name, MonoMethodSignature *sig, const char *reason, ...) { int i; char *result; GString *res; res = g_string_new ("Method not found: "); if (sig) { mono_type_get_desc (res, sig->ret, TRUE); g_string_append_c (res, ' '); } if (klass) { if (m_class_get_name_space (klass)) { g_string_append (res, m_class_get_name_space (klass)); g_string_append_c (res, '.'); } g_string_append (res, m_class_get_name (klass)); } else { g_string_append (res, "<unknown type>"); } g_string_append_c (res, '.'); if (method_name) g_string_append (res, method_name); else g_string_append (res, "<unknown method>"); if (sig) { if (sig->generic_param_count) { g_string_append_c (res, '<'); for (i = 0; i < sig->generic_param_count; ++i) { if (i > 0) g_string_append (res, ","); g_string_append_printf (res, "!%d", i); } g_string_append_c (res, '>'); } g_string_append_c (res, '('); for (i = 0; i < sig->param_count; ++i) { if (i > 0) g_string_append_c (res, ','); mono_type_get_desc (res, sig->params [i], TRUE); } g_string_append_c (res, ')'); } if (reason && *reason) { va_list args; va_start (args, reason); g_string_append (res, " Due to: "); g_string_append_vprintf (res, reason, args); va_end (args); } result = res->str; g_string_free (res, FALSE); mono_error_set_specific (error, MONO_ERROR_MISSING_METHOD, result); }
static void add_pool_entry (MonoCompile *cfg, ConstantPoolEntry *entry) { int *cp_id= (int *) mono_mempool_alloc0 (cfg->mempool, sizeof (int)); *cp_id = cfg->gdump_ctx->next_cp_id; g_hash_table_insert (cfg->gdump_ctx->constant_pool, entry, cp_id); write_byte (cfg, POOL_NEW); write_short (cfg, cfg->gdump_ctx->next_cp_id++); switch (entry->pt) { case PT_STRING: write_byte (cfg, POOL_STRING); write_string (cfg, (char *) entry->data); break; case PT_METHOD: { MonoMethod *method = (MonoMethod *) entry->data; write_byte (cfg, POOL_METHOD); write_pool (cfg, create_cp_entry (cfg, (void *) method->klass, PT_KLASS)); write_pool (cfg, create_cp_entry (cfg, (void *) method->name, PT_STRING)); write_pool (cfg, create_cp_entry (cfg, (void *) method->signature, PT_SIGNATURE)); write_int (cfg, (int) method->flags); write_int (cfg, -1); // don't transmit bytecode. break; } case PT_KLASS: { MonoClass *klass = (MonoClass *) entry->data; write_byte (cfg, POOL_KLASS); write_string (cfg, m_class_get_name (klass)); write_byte (cfg, KLASS); break; } case PT_SIGNATURE: { write_byte (cfg, POOL_SIGNATURE); MonoMethodSignature *sig = (MonoMethodSignature *) entry->data; write_short (cfg, sig->param_count); for (int i = 0; i < sig->param_count; i++) { GString *sbuf = g_string_new (NULL); mono_type_get_desc (sbuf, sig->params [i], TRUE); write_pool (cfg, create_cp_entry (cfg, (void *) sbuf->str, PT_STRING)); g_string_free (sbuf, TRUE); } GString *sbuf = g_string_new (NULL); mono_type_get_desc (sbuf, sig->ret, TRUE); write_pool (cfg, create_cp_entry (cfg, (void *) sbuf->str, PT_STRING)); g_string_free (sbuf, TRUE); break; } case PT_OPTYPE: { MonoInst *insn = (MonoInst *) entry->data; write_byte (cfg, POOL_NODE_CLASS); write_string (cfg, mono_inst_name (insn->opcode)); GString *insndesc = mono_print_ins_index_strbuf (-1, insn); int len = strnlen (insndesc->str, 0x2000); #define CUTOFF 40 if (len > CUTOFF) { insndesc->str[CUTOFF] = '\0'; insndesc->str[CUTOFF - 1] = '.'; insndesc->str[CUTOFF - 2] = '.'; } write_string (cfg, insndesc->str); if (len > CUTOFF) insndesc->str[CUTOFF] = ' '; g_string_free (insndesc, TRUE); // one predecessor write_short (cfg, 1); write_byte (cfg, 0); write_pool (cfg, create_cp_entry (cfg, (void *) "predecessor", PT_STRING)); write_pool (cfg, create_cp_entry (cfg, (void *) NULL, PT_INPUTTYPE)); // make NUM_SUCCESSOR successor edges, not everyone will be used. #define NUM_SUCCESSOR 5 write_short (cfg, NUM_SUCCESSOR); for (int i = 0; i < NUM_SUCCESSOR; i++) { char *str = g_strdup ("successor1"); str[9] = '0' + i; write_byte (cfg, 0); write_pool (cfg, create_cp_entry (cfg, (void *) str, PT_STRING)); } break; } case PT_INPUTTYPE: { write_byte (cfg, POOL_ENUM); write_pool (cfg, create_cp_entry (cfg, (void *) NULL, PT_ENUMKLASS)); write_int (cfg, 0); break; } case PT_ENUMKLASS: { write_byte (cfg, POOL_KLASS); write_string (cfg, "InputType"); write_byte (cfg, ENUM_KLASS); write_int (cfg, 1); write_pool (cfg, create_cp_entry (cfg, (void *) "fixed", PT_STRING)); break; } } }