Improve ValueType::matchParameter for pointers with different types
This commit is contained in:
parent
35a3a34632
commit
039d49bcb1
|
@ -5834,8 +5834,10 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
|
||||||
if (call->pointer > 0 && func->type != ValueType::Type::VOID && ((call->constness | func->constness) != func->constness))
|
if (call->pointer > 0 && func->type != ValueType::Type::VOID && ((call->constness | func->constness) != func->constness))
|
||||||
return ValueType::MatchResult::UNKNOWN;
|
return ValueType::MatchResult::UNKNOWN;
|
||||||
if (call->type != func->type) {
|
if (call->type != func->type) {
|
||||||
if (func->type == ValueType::Type::VOID)
|
if (call->type == ValueType::Type::VOID || func->type == ValueType::Type::VOID)
|
||||||
return ValueType::MatchResult::FALLBACK1;
|
return ValueType::MatchResult::FALLBACK1;
|
||||||
|
if (call->pointer > 0 && func->pointer > 0)
|
||||||
|
return ValueType::MatchResult::UNKNOWN;
|
||||||
if (call->isIntegral() && func->isIntegral())
|
if (call->isIntegral() && func->isIntegral())
|
||||||
return call->type < func->type ?
|
return call->type < func->type ?
|
||||||
ValueType::MatchResult::FALLBACK1 :
|
ValueType::MatchResult::FALLBACK1 :
|
||||||
|
|
|
@ -5533,18 +5533,17 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueTypeMatchParameter() {
|
void valueTypeMatchParameter() {
|
||||||
ValueType vt_int;
|
ValueType vt_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0);
|
||||||
vt_int.type = ValueType::Type::INT;
|
ValueType vt_const_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0, 1);
|
||||||
vt_int.sign = ValueType::Sign::SIGNED;
|
|
||||||
|
|
||||||
ValueType vt_const_int;
|
|
||||||
vt_const_int.type = ValueType::Type::INT;
|
|
||||||
vt_const_int.sign = ValueType::Sign::SIGNED;
|
|
||||||
vt_const_int.constness = 1;
|
|
||||||
|
|
||||||
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_int));
|
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_int));
|
||||||
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_const_int, &vt_int));
|
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_const_int, &vt_int));
|
||||||
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_const_int));
|
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_const_int));
|
||||||
|
|
||||||
|
ValueType vt_char_pointer(ValueType::Sign::SIGNED, ValueType::Type::CHAR, 1);
|
||||||
|
ValueType vt_void_pointer(ValueType::Sign::SIGNED, ValueType::Type::VOID, 1); // compatible
|
||||||
|
ValueType vt_int_pointer(ValueType::Sign::SIGNED, ValueType::Type::INT, 1); // not compatible
|
||||||
|
ASSERT_EQUALS((int)ValueType::MatchResult::FALLBACK1, (int)ValueType::matchParameter(&vt_char_pointer, &vt_void_pointer));
|
||||||
|
ASSERT_EQUALS((int)ValueType::MatchResult::UNKNOWN, (int)ValueType::matchParameter(&vt_char_pointer, &vt_int_pointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \
|
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \
|
||||||
|
|
Loading…
Reference in New Issue