Skip to content

Commit 6699af7

Browse files
committed
generate token references during symbol database creation [skip ci]
1 parent fdd2939 commit 6699af7

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

lib/symboldatabase.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, E
8585
createSymbolDatabaseEnums();
8686
createSymbolDatabaseEscapeFunctions();
8787
createSymbolDatabaseIncompleteVars();
88+
createTokenRefs();
8889
createSymbolDatabaseExprIds();
8990
debugSymbolDatabase();
9091
}
@@ -1622,16 +1623,20 @@ namespace {
16221623
key.parentOp += type;
16231624
}
16241625

1625-
for (const auto& ref: followAllReferences(op1)) {
1626-
if (ref.token->exprId() != 0) { // cppcheck-suppress useStlAlgorithm
1627-
key.operand1 = ref.token->exprId();
1628-
break;
1626+
if (op1) {
1627+
for (const auto& ref: op1->refs()) {
1628+
if (ref.token->exprId() != 0) { // cppcheck-suppress useStlAlgorithm
1629+
key.operand1 = ref.token->exprId();
1630+
break;
1631+
}
16291632
}
16301633
}
1631-
for (const auto& ref: followAllReferences(op2)) {
1632-
if (ref.token->exprId() != 0) { // cppcheck-suppress useStlAlgorithm
1633-
key.operand2 = ref.token->exprId();
1634-
break;
1634+
if (op2) {
1635+
for (const auto& ref: op2->refs()) {
1636+
if (ref.token->exprId() != 0) { // cppcheck-suppress useStlAlgorithm
1637+
key.operand2 = ref.token->exprId();
1638+
break;
1639+
}
16351640
}
16361641
}
16371642

@@ -1660,6 +1665,15 @@ namespace {
16601665
}
16611666
}
16621667

1668+
void SymbolDatabase::createTokenRefs()
1669+
{
1670+
for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
1671+
tok->refs(true);
1672+
tok->refs(false);
1673+
}
1674+
// TODO: debug output
1675+
}
1676+
16631677
void SymbolDatabase::createSymbolDatabaseExprIds()
16641678
{
16651679
// Find highest varId

lib/symboldatabase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ class CPPCHECKLIB SymbolDatabase {
14151415
void setArrayDimensionsUsingValueFlow();
14161416

14171417
void clangSetVariables(const std::vector<const Variable *> &variableList);
1418+
void createTokenRefs();
14181419
void createSymbolDatabaseExprIds();
14191420

14201421
/* returns the opening { if tok points to enum */

0 commit comments

Comments
 (0)