SymbolDatabase: Match function overloads by using ValueType information by running a second pass of the function pointer assignment routine.
This commit is contained in:
parent
abba762d42
commit
f4c0ab5dd5
|
@ -55,7 +55,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
createSymbolDatabaseNeedInitialization();
|
||||
createSymbolDatabaseVariableSymbolTable();
|
||||
createSymbolDatabaseSetScopePointers();
|
||||
createSymbolDatabaseSetFunctionPointers();
|
||||
createSymbolDatabaseSetFunctionPointers(true);
|
||||
createSymbolDatabaseSetVariablePointers();
|
||||
createSymbolDatabaseSetTypePointers();
|
||||
createSymbolDatabaseEnums();
|
||||
|
@ -1148,8 +1148,9 @@ void SymbolDatabase::createSymbolDatabaseSetScopePointers()
|
|||
}
|
||||
}
|
||||
|
||||
void SymbolDatabase::createSymbolDatabaseSetFunctionPointers()
|
||||
void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
|
||||
{
|
||||
if (firstPass) {
|
||||
// Set function definition and declaration pointers
|
||||
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
|
||||
for (std::list<Function>::const_iterator func = it->functionList.begin(); func != it->functionList.end(); ++func) {
|
||||
|
@ -1160,17 +1161,16 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers()
|
|||
const_cast<Token *>(func->token)->function(&*func);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set function call pointers
|
||||
for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) {
|
||||
if (Token::Match(tok, "%name% (")) {
|
||||
if (!tok->function() && tok->varId() == 0 && !isReservedName(tok->str())) {
|
||||
if (!tok->function() && tok->varId() == 0 && Token::Match(tok, "%name% (") && !isReservedName(tok->str())) {
|
||||
const Function *function = findFunction(tok);
|
||||
if (function)
|
||||
const_cast<Token *>(tok)->function(function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set C++ 11 delegate constructor function call pointers
|
||||
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
|
||||
|
@ -4010,6 +4010,24 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
|
|||
while (argtok->astParent() && argtok->astParent() != tok->next() && argtok->astParent()->str() != ",") {
|
||||
argtok = argtok->astParent();
|
||||
}
|
||||
if (argtok && argtok->valueType() && !funcarg->isArrayOrPointer()) { // TODO: Pointers
|
||||
if (argtok->valueType()->type == ValueType::BOOL) {
|
||||
if (funcarg->typeStartToken()->str() == "bool")
|
||||
same++;
|
||||
else if (Token::Match(funcarg->typeStartToken(), "wchar_t|char|short|int|long"))
|
||||
fallback1++;
|
||||
} else if (argtok->valueType()->isIntegral()) {
|
||||
if (Token::Match(funcarg->typeStartToken(), "wchar_t|char|short|int|long"))
|
||||
same++;
|
||||
else if (Token::Match(funcarg->typeStartToken(), "float|double"))
|
||||
fallback1++;
|
||||
} else if (argtok->valueType()->isFloat()) {
|
||||
if (Token::Match(funcarg->typeStartToken(), "float|double"))
|
||||
same++;
|
||||
else if (Token::Match(funcarg->typeStartToken(), "wchar_t|char|short|int|long"))
|
||||
fallback1++;
|
||||
}
|
||||
} else {
|
||||
while (Token::Match(argtok, ".|::"))
|
||||
argtok = argtok->astOperand2();
|
||||
|
||||
|
@ -4019,6 +4037,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t hasToBe = func->isVariadic() ? (func->argCount() - 1) : args;
|
||||
|
||||
|
@ -4998,6 +5017,9 @@ void SymbolDatabase::setValueTypeInTokenList()
|
|||
}
|
||||
}
|
||||
|
||||
// Update functions with new type information.
|
||||
createSymbolDatabaseSetFunctionPointers(false);
|
||||
|
||||
// Update auto variables with new type information.
|
||||
createSymbolDatabaseSetVariablePointers();
|
||||
}
|
||||
|
|
|
@ -1159,7 +1159,7 @@ private:
|
|||
void createSymbolDatabaseNeedInitialization();
|
||||
void createSymbolDatabaseVariableSymbolTable();
|
||||
void createSymbolDatabaseSetScopePointers();
|
||||
void createSymbolDatabaseSetFunctionPointers();
|
||||
void createSymbolDatabaseSetFunctionPointers(bool firstPass);
|
||||
void createSymbolDatabaseSetVariablePointers();
|
||||
void createSymbolDatabaseSetTypePointers();
|
||||
void createSymbolDatabaseEnums();
|
||||
|
|
|
@ -286,6 +286,7 @@ private:
|
|||
TEST_CASE(findFunction14);
|
||||
TEST_CASE(findFunction15);
|
||||
TEST_CASE(findFunction16);
|
||||
TEST_CASE(findFunction17);
|
||||
|
||||
TEST_CASE(noexceptFunction1);
|
||||
TEST_CASE(noexceptFunction2);
|
||||
|
@ -3753,6 +3754,37 @@ private:
|
|||
ASSERT_EQUALS(true, f && f->function() == nullptr);
|
||||
}
|
||||
|
||||
void findFunction17() {
|
||||
GET_SYMBOL_DB("void foo(int a) { }\n"
|
||||
"void foo(float a) { }\n"
|
||||
"void foo(void* a) { }\n"
|
||||
"void foo(bool a) { }\n"
|
||||
"void func(int i, float f, bool b) {\n"
|
||||
" foo(i + i);\n"
|
||||
" foo(f + f);\n"
|
||||
" foo(!b);\n"
|
||||
" foo(i > 0);\n"
|
||||
" foo(f + i);\n"
|
||||
"}");
|
||||
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( i + i ) ;");
|
||||
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 1);
|
||||
|
||||
f = Token::findsimplematch(tokenizer.tokens(), "foo ( f + f ) ;");
|
||||
ASSERT_EQUALS(true, f && f->function() && f->function()->tokenDef->linenr() == 2);
|
||||
|
||||
f = Token::findsimplematch(tokenizer.tokens(), "foo ( ! b ) ;");
|
||||
ASSERT_EQUALS(true, f && f->function() && f->function()->tokenDef->linenr() == 4);
|
||||
|
||||
f = Token::findsimplematch(tokenizer.tokens(), "foo ( i > 0 ) ;");
|
||||
ASSERT_EQUALS(true, f && f->function() && f->function()->tokenDef->linenr() == 4);
|
||||
|
||||
f = Token::findsimplematch(tokenizer.tokens(), "foo ( f + i ) ;");
|
||||
ASSERT_EQUALS(true, f && f->function() && f->function()->tokenDef->linenr() == 2);
|
||||
}
|
||||
|
||||
|
||||
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \
|
||||
ASSERT_EQUALS(true, x != nullptr); \
|
||||
|
|
Loading…
Reference in New Issue