From 91ca6165ebb5c0ee349f6368b06c098c1c3f343c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 31 Jul 2019 18:35:56 +0200 Subject: [PATCH] SymbolDatabase: Use ValueType::matchParameter for expression parameters --- lib/symboldatabase.cpp | 66 +++++++----------------------------------- 1 file changed, 10 insertions(+), 56 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 4cb7c7a20..b2fa30059 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4081,25 +4081,6 @@ static void checkVariableCallMatch(const Variable* callarg, const Variable* func } } -static bool valueTypeMatch(const ValueType * valuetype, const Token * type) -{ - if (valuetype->typeScope && type->type() && type->type()->classScope == valuetype->typeScope) - return true; - - return ((((type->str() == "bool" && valuetype->type == ValueType::BOOL) || - (type->str() == "char" && valuetype->type == ValueType::CHAR) || - (type->str() == "short" && valuetype->type == ValueType::SHORT) || - (type->str() == "wchar_t" && valuetype->type == ValueType::WCHAR_T) || - (type->str() == "int" && valuetype->type == ValueType::INT) || - ((type->str() == "long" && type->isLong()) && valuetype->type == ValueType::LONGLONG) || - (type->str() == "long" && valuetype->type == ValueType::LONG) || - (type->str() == "float" && valuetype->type == ValueType::FLOAT) || - ((type->str() == "double" && type->isLong()) && valuetype->type == ValueType::LONGDOUBLE) || - (type->str() == "double" && valuetype->type == ValueType::DOUBLE)) && - (type->isUnsigned() == (valuetype->sign == ValueType::UNSIGNED))) || - (valuetype->isEnum() && type->isEnumType() && valuetype->typeScope->className == type->str())); -} - const Function* Scope::findFunction(const Token *tok, bool requireConst) const { // make sure this is a function call @@ -4294,43 +4275,13 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const // Try to evaluate the apparently more complex expression else { - const Token* argtok = arguments[j]; - while (argtok->astParent() && argtok->astParent() != tok->next() && argtok->astParent()->str() != ",") { - argtok = argtok->astParent(); - } - if (argtok && argtok->valueType()) { - const ValueType* valuetype = argtok->valueType(); - const bool isArrayOrPointer = valuetype->pointer; - const bool ptrequals = isArrayOrPointer == funcarg->isArrayOrPointer(); - const bool constEquals = !isArrayOrPointer || - ((valuetype->constness > 0) == (funcarg->typeStartToken()->strAt(-1) == "const")); - if (ptrequals && constEquals && valueTypeMatch(valuetype, funcarg->typeStartToken())) { - same++; - } else if (isArrayOrPointer) { - if (ptrequals && constEquals && valuetype->type == ValueType::VOID) - fallback1++; - else if (constEquals && funcarg->isStlStringType() && valuetype->type == ValueType::CHAR) - fallback2++; - } else if (ptrequals) { - const bool takesInt = Token::Match(funcarg->typeStartToken(), "bool|char|short|int|long") || - funcarg->typeStartToken()->isEnumType(); - const bool takesFloat = Token::Match(funcarg->typeStartToken(), "float|double"); - const bool passesInt = valuetype->isIntegral() || valuetype->isEnum(); - const bool passesFloat = valuetype->isFloat(); - if ((takesInt && passesInt) || (takesFloat && passesFloat)) - fallback1++; - else if ((takesInt && passesFloat) || (takesFloat && passesInt)) - fallback2++; - } - } else { - while (Token::Match(argtok, ".|::")) - argtok = argtok->astOperand2(); - - if (argtok) { - const Variable * callarg = check->getVariableFromVarId(argtok->varId()); - checkVariableCallMatch(callarg, funcarg, same, fallback1, fallback2); - } - } + ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), funcarg->valueType()); + if (res == ValueType::MatchResult::SAME) + ++same; + else if (res == ValueType::MatchResult::FALLBACK1) + ++fallback1; + else if (res == ValueType::MatchResult::FALLBACK2) + ++fallback2; } } @@ -5882,6 +5833,9 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va return ValueType::MatchResult::UNKNOWN; // TODO } + if (call->typeScope != nullptr || func->typeScope != nullptr) + return call->typeScope == func->typeScope ? ValueType::MatchResult::SAME : ValueType::MatchResult::NOMATCH; + if (func->type < ValueType::Type::VOID || func->type == ValueType::Type::UNKNOWN_INT) return ValueType::MatchResult::UNKNOWN;