예제 #1
0
파일: type.c 프로젝트: MatzeB/fluffy
void print_type(const type_t *type)
{
	if (type == NULL) {
		fputs("nil type", out);
		return;
	}

	switch (type->kind) {
	case TYPE_INVALID:
		fputs("invalid", out);
		return;
	case TYPE_TYPEOF: {
		const typeof_type_t *typeof_type = (const typeof_type_t*) type;
		fputs("typeof(", out);
		print_expression(typeof_type->expression);
		fputs(")", out);
		return;
	}
	case TYPE_ERROR:
		fputs("error", out);
		return;
	case TYPE_VOID:
		fputs("void", out);
		return;
	case TYPE_ATOMIC:
		print_atomic_type(&type->atomic);
		return;
	case TYPE_COMPOUND_UNION:
	case TYPE_COMPOUND_STRUCT:
		print_compound_type(&type->compound);
		return;
	case TYPE_FUNCTION:
		print_function_type(&type->function);
		return;
	case TYPE_POINTER:
		print_pointer_type(&type->pointer);
		return;
	case TYPE_ARRAY:
		print_array_type(&type->array);
		return;
	case TYPE_REFERENCE:
		print_type_reference(&type->reference);
		return;
	case TYPE_REFERENCE_TYPE_VARIABLE:
		print_type_reference_variable(&type->reference);
		return;
	case TYPE_BIND_TYPEVARIABLES:
		print_bind_type_variables(&type->bind_typevariables);
		return;
	}
	fputs("unknown", out);
}
예제 #2
0
void
ada_print_type (struct type *type0, const char *varstring,
                struct ui_file *stream, int show, int level,
                const struct type_print_options *flags)
{
    struct type *type = ada_check_typedef (ada_get_base_type (type0));
    char *type_name = decoded_type_name (type0);
    int is_var_decl = (varstring != NULL && varstring[0] != '\0');

    if (type == NULL)
    {
        if (is_var_decl)
            fprintf_filtered (stream, "%.*s: ",
                              ada_name_prefix_len (varstring), varstring);
        fprintf_filtered (stream, "<null type?>");
        return;
    }

    if (show > 0)
        type = ada_check_typedef (type);

    if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC)
        fprintf_filtered (stream, "%.*s: ",
                          ada_name_prefix_len (varstring), varstring);

    if (type_name != NULL && show <= 0 && !ada_is_aligner_type (type))
    {
        fprintf_filtered (stream, "%.*s",
                          ada_name_prefix_len (type_name), type_name);
        return;
    }

    if (ada_is_aligner_type (type))
        ada_print_type (ada_aligned_type (type), "", stream, show, level, flags);
    else if (ada_is_constrained_packed_array_type (type)
             && TYPE_CODE (type) != TYPE_CODE_PTR)
        print_array_type (type, stream, show, level, flags);
    else
        switch (TYPE_CODE (type))
        {
        default:
            fprintf_filtered (stream, "<");
            c_print_type (type, "", stream, show, level, flags);
            fprintf_filtered (stream, ">");
            break;
        case TYPE_CODE_PTR:
        case TYPE_CODE_TYPEDEF:
            fprintf_filtered (stream, "access ");
            ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                            flags);
            break;
        case TYPE_CODE_REF:
            fprintf_filtered (stream, "<ref> ");
            ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                            flags);
            break;
        case TYPE_CODE_ARRAY:
            print_array_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_BOOL:
            fprintf_filtered (stream, "(false, true)");
            break;
        case TYPE_CODE_INT:
            if (ada_is_fixed_point_type (type))
                print_fixed_point_type (type, stream);
            else
            {
                const char *name = ada_type_name (type);

                if (!ada_is_range_type_name (name))
                    fprintf_filtered (stream, _("<%d-byte integer>"),
                                      TYPE_LENGTH (type));
                else
                {
                    fprintf_filtered (stream, "range ");
                    print_range_type (type, stream);
                }
            }
            break;
        case TYPE_CODE_RANGE:
            if (ada_is_fixed_point_type (type))
                print_fixed_point_type (type, stream);
            else if (ada_is_modular_type (type))
                fprintf_filtered (stream, "mod %s",
                                  int_string (ada_modulus (type), 10, 0, 0, 1));
            else
            {
                fprintf_filtered (stream, "range ");
                print_range (type, stream);
            }
            break;
        case TYPE_CODE_FLT:
            fprintf_filtered (stream, _("<%d-byte float>"), TYPE_LENGTH (type));
            break;
        case TYPE_CODE_ENUM:
            if (show < 0)
                fprintf_filtered (stream, "(...)");
            else
                print_enum_type (type, stream);
            break;
        case TYPE_CODE_STRUCT:
            if (ada_is_array_descriptor_type (type))
                print_array_type (type, stream, show, level, flags);
            else if (ada_is_bogus_array_descriptor (type))
                fprintf_filtered (stream,
                                  _("array (?) of ? (<mal-formed descriptor>)"));
            else
                print_record_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_UNION:
            print_unchecked_union_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_FUNC:
            print_func_type (type, stream, varstring, flags);
            break;
        }
}