Refactoring SymbolDatabase. Reuse Tokenizer::isFunctionHead().
This commit is contained in:
parent
0a1d10bf2f
commit
66e047ee7d
|
@ -443,17 +443,32 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
function.arg = function.argDef;
|
function.arg = function.argDef;
|
||||||
|
|
||||||
// out of line function
|
// out of line function
|
||||||
if (Token::Match(end, ") const| &|&&| ;")) {
|
if (_tokenizer->isFunctionHead(end, ";")) {
|
||||||
// find the function implementation later
|
// find the function implementation later
|
||||||
tok = end->next();
|
tok = end->next();
|
||||||
|
|
||||||
if (tok->str() == "const")
|
if (tok->str() == "const")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
if (tok->str() == "&") {
|
if (tok->str() == "&") {
|
||||||
function.hasLvalRefQualifier(true);
|
function.hasLvalRefQualifier(true);
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
} else if (tok->str() == "&&") {
|
} else if (tok->str() == "&&") {
|
||||||
function.hasRvalRefQualifier(true);
|
function.hasRvalRefQualifier(true);
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
} else if (Token::simpleMatch(tok, "noexcept (")) {
|
||||||
|
function.isNoExcept(tok->strAt(2) != "false");
|
||||||
|
tok = tok->linkAt(1)->next();
|
||||||
|
} else if (Token::simpleMatch(tok, "throw (")) {
|
||||||
|
function.isThrow(true);
|
||||||
|
if (tok->strAt(2) != ")")
|
||||||
|
function.throwArg = end->tokAt(2);
|
||||||
|
tok = tok->linkAt(1)->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Token::Match(tok, "= 0|default ;")) {
|
||||||
|
function.isPure(tok->strAt(1) == "0");
|
||||||
|
tok = tok->tokAt(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
scope->addFunction(function);
|
scope->addFunction(function);
|
||||||
|
@ -491,68 +506,6 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
scope->addFunction(function);
|
scope->addFunction(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
// noexcept(...);
|
|
||||||
// noexcept(...) = 0;
|
|
||||||
// const noexcept(...);
|
|
||||||
// const noexcept(...) = 0;
|
|
||||||
else if (Token::Match(end, ") const| noexcept (") &&
|
|
||||||
(end->next()->str() == "const" ? Token::Match(end->linkAt(3), ") ;|=") :
|
|
||||||
Token::Match(end->linkAt(2), ") ;|="))) {
|
|
||||||
|
|
||||||
if (end->next()->str() == "const")
|
|
||||||
tok = end->tokAt(3);
|
|
||||||
else
|
|
||||||
tok = end->tokAt(2);
|
|
||||||
|
|
||||||
function.isNoExcept(tok->strAt(1) != "false");
|
|
||||||
|
|
||||||
if (Token::Match(tok->link()->next(), "= %any% ;")) {
|
|
||||||
function.isPure(true);
|
|
||||||
tok = tok->tokAt(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
scope->addFunction(function);
|
|
||||||
}
|
|
||||||
|
|
||||||
// throw();
|
|
||||||
// throw() = 0;
|
|
||||||
// const throw();
|
|
||||||
// const throw() = 0;
|
|
||||||
else if (Token::Match(end, ") const| throw (") &&
|
|
||||||
(end->next()->str() == "const" ? Token::Match(end->linkAt(3), ") ;|=") :
|
|
||||||
Token::Match(end->linkAt(2), ") ;|="))) {
|
|
||||||
function.isThrow(true);
|
|
||||||
|
|
||||||
if (end->next()->str() == "const") {
|
|
||||||
if (end->strAt(4) != ")")
|
|
||||||
function.throwArg = end->tokAt(4);
|
|
||||||
tok = end->linkAt(3)->next();
|
|
||||||
} else {
|
|
||||||
if (end->strAt(3) != ")")
|
|
||||||
function.throwArg = end->tokAt(3);
|
|
||||||
tok = end->linkAt(2)->next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Token::Match(tok, "= %any% ;")) {
|
|
||||||
function.isPure(true);
|
|
||||||
tok = tok->tokAt(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
scope->addFunction(function);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pure virtual function
|
|
||||||
else if (Token::Match(end, ") const| = %any% ;")) {
|
|
||||||
function.isPure(true);
|
|
||||||
|
|
||||||
if (end->next()->str() == "const")
|
|
||||||
tok = end->tokAt(4);
|
|
||||||
else
|
|
||||||
tok = end->tokAt(3);
|
|
||||||
|
|
||||||
scope->addFunction(function);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'const' or unknown macro (#5197)
|
// 'const' or unknown macro (#5197)
|
||||||
else if (Token::Match(end, ") %any% ;")) {
|
else if (Token::Match(end, ") %any% ;")) {
|
||||||
tok = end->tokAt(2);
|
tok = end->tokAt(2);
|
||||||
|
|
|
@ -58,10 +58,14 @@ const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &end
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (tok->str() == "(")
|
if (tok->str() == "(")
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
if (Token::Match(tok, ") const| &|&&| [;:{]")) {
|
if (Token::Match(tok, ") const| &|&&| [;:{=]")) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (tok->isName())
|
if (tok->isName())
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
if (Token::Match(tok, "&|&&"))
|
||||||
|
tok = tok->next();
|
||||||
|
if (Token::Match(tok, "= 0|default ;"))
|
||||||
|
tok = tok->tokAt(2);
|
||||||
return (endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr;
|
return (endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr;
|
||||||
}
|
}
|
||||||
if (isCPP() && Token::Match(tok, ") const| throw|noexcept (")) {
|
if (isCPP() && Token::Match(tok, ") const| throw|noexcept (")) {
|
||||||
|
@ -71,6 +75,8 @@ const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &end
|
||||||
tok = tok->link()->next();
|
tok = tok->link()->next();
|
||||||
while (tok && tok->isName())
|
while (tok && tok->isName())
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
if (Token::Match(tok, "= 0|default ;"))
|
||||||
|
tok = tok->tokAt(2);
|
||||||
return (tok && endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr;
|
return (tok && endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in New Issue