Ejemplo n.º 1
0
static ir_tarval *builtin_types_compatible_to_tarval(
		builtin_types_compatible_expression_t const *const expression)
{
	type_t  *const left  = skip_typeref(expression->left);
	type_t  *const right = skip_typeref(expression->right);
	bool     const value = types_compatible_ignore_qualifiers(left, right);
	ir_mode *const mode  = get_ir_mode_storage(expression->base.type);
	return create_tarval_from_bool(mode, value);
}
Ejemplo n.º 2
0
bool types_compatible(const type_t *type1, const type_t *type2)
{
	assert(!is_typeref(type1));
	assert(!is_typeref(type2));

	/* shortcut: the same type is always compatible */
	if (type1 == type2)
		return true;
	if (type1->base.qualifiers != type2->base.qualifiers)
		return false;
	return types_compatible_ignore_qualifiers(type1, type2);
}
Ejemplo n.º 3
0
/**
 * Check if two function types are compatible.
 */
static bool function_types_compatible(const function_type_t *func1,
                                      const function_type_t *func2)
{
	const type_t* const ret1 = skip_typeref(func1->return_type);
	const type_t* const ret2 = skip_typeref(func2->return_type);
	if (!types_compatible(ret1, ret2))
		return false;

	if (func1->linkage != func2->linkage)
		return false;

	cc_kind_t cc1 = func1->calling_convention;
	if (cc1 == CC_DEFAULT)
		cc1 = default_calling_convention;
	cc_kind_t cc2 = func2->calling_convention;
	if (cc2 == CC_DEFAULT)
		cc2 = default_calling_convention;

	if (cc1 != cc2)
		return false;

	if (func1->variadic != func2->variadic)
		return false;

	/* can parameters be compared? */
	if (func1->unspecified_parameters && !func1->kr_style_parameters) {
		if (func2->unspecified_parameters && !func2->kr_style_parameters)
			return true;
		const function_type_t *const temp = func1;
		func1 = func2;
		func2 = temp;
		goto check_promoted_types;
	} else if (func2->unspecified_parameters && !func2->kr_style_parameters) {
check_promoted_types:
		/* all argument types must already be promoted */
		for (function_parameter_t *parameter = func1->parameters;
		     parameter != NULL; parameter = parameter->next) {
			type_t *const parameter_type = skip_typeref(parameter->type);
			type_t *const promoted
				= get_default_promoted_type(parameter_type);
			if (promoted != parameter_type)
				return false;
		}
		return true;
	}

	/* all argument types must be compatible */
	function_parameter_t *parameter1 = func1->parameters;
	function_parameter_t *parameter2 = func2->parameters;
	for ( ; parameter1 != NULL && parameter2 != NULL;
	     parameter1 = parameter1->next, parameter2 = parameter2->next) {
		type_t *parameter1_type = skip_typeref(parameter1->type);
		type_t *parameter2_type = skip_typeref(parameter2->type);

		if (!types_compatible_ignore_qualifiers(parameter1_type,
		                                        parameter2_type))
			return false;
	}
	/* same number of arguments? */
	if (parameter1 != NULL || parameter2 != NULL)
		return false;

	return true;
}