SymbolDatabase: Use ValueType::matchParameter for string literal parameters

This commit is contained in:
Daniel Marjamäki 2019-07-30 21:02:12 +02:00
parent 2e11fbbfd6
commit f5c269a191
1 changed files with 11 additions and 8 deletions

View File

@ -4222,12 +4222,13 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
// check for a match with a string literal // check for a match with a string literal
else if (Token::Match(arguments[j], "%str% ,|)")) { else if (Token::Match(arguments[j], "%str% ,|)")) {
if (funcarg->typeStartToken() != funcarg->typeEndToken() && ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), funcarg->valueType());
((!arguments[j]->isLong() && Token::simpleMatch(funcarg->typeStartToken(), "char *")) || if (res == ValueType::MatchResult::SAME)
(arguments[j]->isLong() && Token::simpleMatch(funcarg->typeStartToken(), "wchar_t *")))) ++same;
same++; else if (res == ValueType::MatchResult::FALLBACK1)
else if (Token::simpleMatch(funcarg->typeStartToken(), "void *")) ++fallback1;
fallback1++; else if (res == ValueType::MatchResult::FALLBACK2)
++fallback2;
else if (funcarg->isStlStringType()) else if (funcarg->isStlStringType())
fallback2++; fallback2++;
} }
@ -5829,9 +5830,11 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
return ValueType::MatchResult::UNKNOWN; return ValueType::MatchResult::UNKNOWN;
if (call->pointer != func->pointer) if (call->pointer != func->pointer)
return ValueType::MatchResult::UNKNOWN; // TODO return ValueType::MatchResult::UNKNOWN; // TODO
if (call->pointer > 0 && ((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)
return ValueType::MatchResult::FALLBACK1;
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 :
@ -5848,7 +5851,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
if (func->type < ValueType::Type::VOID || func->type == ValueType::Type::UNKNOWN_INT) if (func->type < ValueType::Type::VOID || func->type == ValueType::Type::UNKNOWN_INT)
return ValueType::MatchResult::UNKNOWN; return ValueType::MatchResult::UNKNOWN;
if (call->isIntegral() && func->isIntegral() && call->sign != func->sign) if (call->isIntegral() && func->isIntegral() && call->sign != ValueType::Sign::UNKNOWN_SIGN && func->sign != ValueType::Sign::UNKNOWN_SIGN && call->sign != func->sign)
return ValueType::MatchResult::UNKNOWN; // TODO return ValueType::MatchResult::UNKNOWN; // TODO
return ValueType::MatchResult::SAME; return ValueType::MatchResult::SAME;