示例#1
0
文件: type.c 项目: oliwer/cparser
unsigned get_type_alignment(type_t const *const type)
{
	switch (type->kind) {
	case TYPE_ERROR:
		return 0;
	case TYPE_ATOMIC:
	case TYPE_IMAGINARY:
	case TYPE_COMPLEX:
	case TYPE_ENUM:
		return get_atomic_type_alignment(type->atomic.akind);
	case TYPE_COMPOUND_STRUCT:
	case TYPE_COMPOUND_UNION:
		return type->compound.compound->alignment;
	case TYPE_FUNCTION:
	case TYPE_VOID:
		return 1; /* GCC extension. */
	case TYPE_REFERENCE:
	case TYPE_POINTER:
		return pointer_properties.alignment;
	case TYPE_ARRAY:
		return get_type_alignment(type->array.element_type);
	case TYPE_TYPEDEF: {
		il_alignment_t const alignment = get_type_alignment(type->typedeft.typedefe->type);
		return MAX(alignment, type->typedeft.typedefe->alignment);
	}
	case TYPE_TYPEOF:
		return get_type_alignment(type->typeoft.typeof_type);
	case TYPE_BUILTIN_TEMPLATE:
		break;
	}
	panic("invalid type");
}
示例#2
0
unsigned get_type_alignment(type_t *type)
{
	switch (type->kind) {
	case TYPE_ERROR:
		return 0;
	case TYPE_ATOMIC:
	case TYPE_IMAGINARY:
	case TYPE_COMPLEX:
	case TYPE_ENUM:
		return get_atomic_type_alignment(type->atomic.akind);
	case TYPE_COMPOUND_UNION:
		layout_union_type(&type->compound);
		return type->compound.compound->alignment;
	case TYPE_COMPOUND_STRUCT:
		layout_struct_type(&type->compound);
		return type->compound.compound->alignment;
	case TYPE_FUNCTION:
		/* gcc says 1 here... */
		return 1;
	case TYPE_REFERENCE:
	case TYPE_POINTER:
		return pointer_properties.alignment;
	case TYPE_ARRAY:
		return get_type_alignment(type->array.element_type);
	case TYPE_TYPEDEF: {
		il_alignment_t alignment
			= get_type_alignment(type->typedeft.typedefe->type);
		if (type->typedeft.typedefe->alignment > alignment)
			alignment = type->typedeft.typedefe->alignment;

		return alignment;
	}
	case TYPE_TYPEOF:
		return get_type_alignment(type->typeoft.typeof_type);
	}
	panic("invalid type in get_type_alignment");
}