Initialize Function::start when the function is implemented, not when its defined. (Fixes #3826)
This commit is contained in:
parent
77e9106ec0
commit
26f5f08614
|
@ -429,7 +429,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
}
|
||||
// save function prototype in database
|
||||
if (newFunc)
|
||||
addGlobalFunctionDecl(scope, tok, argStart, funcStart);
|
||||
addGlobalFunctionDecl(scope, argStart, funcStart);
|
||||
|
||||
tok = argStart->link()->next();
|
||||
continue;
|
||||
|
@ -445,7 +445,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
}
|
||||
// save function prototype in database
|
||||
if (newFunc) {
|
||||
Function* func = addGlobalFunctionDecl(scope, tok, argStart, funcStart);
|
||||
Function* func = addGlobalFunctionDecl(scope, argStart, funcStart);
|
||||
func->retFuncPtr = true;
|
||||
}
|
||||
|
||||
|
@ -934,12 +934,19 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
|
|||
function = &*i;
|
||||
}
|
||||
if (!function)
|
||||
function = addGlobalFunctionDecl(scope, tok, argStart, funcStart);
|
||||
function = addGlobalFunctionDecl(scope, argStart, funcStart);
|
||||
|
||||
function->arg = argStart;
|
||||
function->token = funcStart;
|
||||
function->hasBody = true;
|
||||
|
||||
// find start of function '{'
|
||||
const Token *start = tok;
|
||||
while (start && start->str() != "{")
|
||||
start = start->next();
|
||||
// save start of function
|
||||
function->start = start;
|
||||
|
||||
addNewFunction(&scope, &tok);
|
||||
|
||||
if (scope) {
|
||||
|
@ -950,7 +957,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
|
|||
return 0;
|
||||
}
|
||||
|
||||
Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart)
|
||||
Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token *argStart, const Token* funcStart)
|
||||
{
|
||||
Function function;
|
||||
|
||||
|
@ -967,14 +974,6 @@ Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token*& tok
|
|||
function.hasBody = false;
|
||||
function.type = Function::eFunction;
|
||||
|
||||
// find start of function '{'
|
||||
const Token *start = tok;
|
||||
while (start && start->str() != "{")
|
||||
start = start->next();
|
||||
|
||||
// save start of function
|
||||
function.start = start;
|
||||
|
||||
scope->functionList.push_back(function);
|
||||
return &scope->functionList.back();
|
||||
}
|
||||
|
|
|
@ -585,7 +585,7 @@ private:
|
|||
friend class Scope;
|
||||
|
||||
void addClassFunction(Scope **info, const Token **tok, const Token *argStart);
|
||||
Function* addGlobalFunctionDecl(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
|
||||
Function* addGlobalFunctionDecl(Scope*& scope, const Token *argStart, const Token* funcStart);
|
||||
Function* addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
|
||||
void addNewFunction(Scope **info, const Token **tok);
|
||||
bool isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart) const;
|
||||
|
|
|
@ -102,6 +102,7 @@ private:
|
|||
TEST_CASE(classWithFriend);
|
||||
|
||||
TEST_CASE(parseFunctionCorrect);
|
||||
TEST_CASE(parseFunctionDeclarationCorrect);
|
||||
|
||||
TEST_CASE(hasGlobalVariables1);
|
||||
TEST_CASE(hasGlobalVariables2);
|
||||
|
@ -692,6 +693,13 @@ private:
|
|||
ASSERT(tokenizer.getFunctionTokenByName("if") == NULL);
|
||||
}
|
||||
|
||||
void parseFunctionDeclarationCorrect() {
|
||||
GET_SYMBOL_DB("void func();\n"
|
||||
"int bar() {}\n"
|
||||
"void func() {}")
|
||||
ASSERT_EQUALS(3, db->findScopeByName("func")->function->start->linenr());
|
||||
}
|
||||
|
||||
void hasGlobalVariables1() {
|
||||
GET_SYMBOL_DB("int i;\n")
|
||||
|
||||
|
|
Loading…
Reference in New Issue