SymbolDatabase: harden code for missing links (#1207)
* SymbolDatabase: harden code for missing links Missing links for templates are common so check links before using them to prevent crashes. * SymbolDatabase: replace link check and single token match with match of two tokens
This commit is contained in:
parent
858e055c0e
commit
5d417bbfa1
@ -70,7 +70,7 @@ static const Token* skipScopeIdentifiers(const Token* tok)
|
|||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
while (Token::Match(tok, "%name% ::") ||
|
while (Token::Match(tok, "%name% ::") ||
|
||||||
(Token::Match(tok, "%name% <") && tok->linkAt(1) && tok->linkAt(1)->strAt(1) == "::")) {
|
(Token::Match(tok, "%name% <") && Token::simpleMatch(tok->linkAt(1), "> ::"))) {
|
||||||
if (tok->strAt(1) == "::")
|
if (tok->strAt(1) == "::")
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
else
|
else
|
||||||
@ -3812,7 +3812,7 @@ const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *ty
|
|||||||
const Token *tok1 = typeTok;
|
const Token *tok1 = typeTok;
|
||||||
|
|
||||||
while (Token::Match(tok1->tokAt(-2), "%type% ::") ||
|
while (Token::Match(tok1->tokAt(-2), "%type% ::") ||
|
||||||
(Token::simpleMatch(tok1->tokAt(-2), "> ::") && Token::Match(tok1->linkAt(-2)->tokAt(-1), "%type%"))) {
|
(Token::simpleMatch(tok1->tokAt(-2), "> ::") && tok1->linkAt(-2) && Token::Match(tok1->linkAt(-2)->tokAt(-1), "%type%"))) {
|
||||||
if (tok1->strAt(-1) == "::")
|
if (tok1->strAt(-1) == "::")
|
||||||
tok1 = tok1->tokAt(-2);
|
tok1 = tok1->tokAt(-2);
|
||||||
else
|
else
|
||||||
@ -3848,7 +3848,7 @@ const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *ty
|
|||||||
if (scope) {
|
if (scope) {
|
||||||
// follow qualification
|
// follow qualification
|
||||||
while (scope && (Token::Match(tok1, "%type% ::") ||
|
while (scope && (Token::Match(tok1, "%type% ::") ||
|
||||||
(Token::Match(tok1, "%type% <") && Token::simpleMatch(tok1->linkAt(1)->next(), "::")))) {
|
(Token::Match(tok1, "%type% <") && Token::simpleMatch(tok1->linkAt(1), "> ::")))) {
|
||||||
if (tok1->strAt(1) == "::")
|
if (tok1->strAt(1) == "::")
|
||||||
tok1 = tok1->tokAt(2);
|
tok1 = tok1->tokAt(2);
|
||||||
else
|
else
|
||||||
@ -4497,7 +4497,7 @@ const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope
|
|||||||
if (tok->strAt(1) == "::") {
|
if (tok->strAt(1) == "::") {
|
||||||
scope = scope->findRecordInNestedList(tok->str());
|
scope = scope->findRecordInNestedList(tok->str());
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
} else if (tok->strAt(1) == "<" && tok->linkAt(1) && tok->linkAt(1)->strAt(1) == "::") {
|
} else if (tok->strAt(1) == "<" && Token::simpleMatch(tok->linkAt(1), "> ::")) {
|
||||||
scope = scope->findRecordInNestedList(tok->str());
|
scope = scope->findRecordInNestedList(tok->str());
|
||||||
tok = tok->linkAt(1)->tokAt(2);
|
tok = tok->linkAt(1)->tokAt(2);
|
||||||
} else
|
} else
|
||||||
@ -4532,7 +4532,7 @@ const Type* SymbolDatabase::findType(const Token *startTok, const Scope *startSc
|
|||||||
const Scope* scope = start_scope;
|
const Scope* scope = start_scope;
|
||||||
|
|
||||||
while (scope && tok && tok->isName()) {
|
while (scope && tok && tok->isName()) {
|
||||||
if (tok->strAt(1) == "::" || (tok->strAt(1) == "<" && tok->linkAt(1)->strAt(1) == "::")) {
|
if (tok->strAt(1) == "::" || (tok->strAt(1) == "<" && Token::simpleMatch(tok->linkAt(1), "> ::"))) {
|
||||||
scope = scope->findRecordInNestedList(tok->str());
|
scope = scope->findRecordInNestedList(tok->str());
|
||||||
if (scope) {
|
if (scope) {
|
||||||
if (tok->strAt(1) == "::")
|
if (tok->strAt(1) == "::")
|
||||||
@ -4564,7 +4564,7 @@ const Type* SymbolDatabase::findType(const Token *startTok, const Scope *startSc
|
|||||||
start_scope = startScope;
|
start_scope = startScope;
|
||||||
|
|
||||||
while (scope && tok && tok->isName()) {
|
while (scope && tok && tok->isName()) {
|
||||||
if (tok->strAt(1) == "::" || (tok->strAt(1) == "<" && tok->linkAt(1)->strAt(1) == "::")) {
|
if (tok->strAt(1) == "::" || (tok->strAt(1) == "<" && Token::simpleMatch(tok->linkAt(1), "> ::"))) {
|
||||||
scope = scope->findRecordInNestedList(tok->str());
|
scope = scope->findRecordInNestedList(tok->str());
|
||||||
if (scope) {
|
if (scope) {
|
||||||
if (tok->strAt(1) == "::")
|
if (tok->strAt(1) == "::")
|
||||||
@ -4619,7 +4619,7 @@ const Type* SymbolDatabase::findTypeInNested(const Token *startTok, const Scope
|
|||||||
const Scope* scope = startScope;
|
const Scope* scope = startScope;
|
||||||
|
|
||||||
while (scope && tok && tok->isName()) {
|
while (scope && tok && tok->isName()) {
|
||||||
if (tok->strAt(1) == "::" || (tok->strAt(1) == "<" && tok->linkAt(1)->strAt(1) == "::")) {
|
if (tok->strAt(1) == "::" || (tok->strAt(1) == "<" && Token::simpleMatch(tok->linkAt(1), "> ::"))) {
|
||||||
hasPath = true;
|
hasPath = true;
|
||||||
scope = scope->findRecordInNestedList(tok->str());
|
scope = scope->findRecordInNestedList(tok->str());
|
||||||
if (scope) {
|
if (scope) {
|
||||||
@ -4686,8 +4686,10 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n
|
|||||||
if (scope && Token::Match(func->tokAt(1), "::|<")) {
|
if (scope && Token::Match(func->tokAt(1), "::|<")) {
|
||||||
if (func->strAt(1) == "::")
|
if (func->strAt(1) == "::")
|
||||||
func = func->tokAt(2);
|
func = func->tokAt(2);
|
||||||
else
|
else if (func->linkAt(1))
|
||||||
func = func->linkAt(1)->tokAt(2);
|
func = func->linkAt(1)->tokAt(2);
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
if (func->str() == "~")
|
if (func->str() == "~")
|
||||||
func = func->next();
|
func = func->next();
|
||||||
function = findFunctionInScope(func, scope, path, path_length);
|
function = findFunctionInScope(func, scope, path, path_length);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user