Improve findEnumerator() (refs #10045) (#5459)

This commit is contained in:
chrchr-github 2023-09-19 11:45:59 +02:00 committed by GitHub
parent 176edbd22c
commit c6b3c56174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 28 deletions

View File

@ -5050,19 +5050,16 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
else { else {
// FIXME search base class here // FIXME search base class here
const Scope* temp{}; // find first scope
if (scope->functionOf && (temp = scope->functionOf->findRecordInNestedList(tok1->str()))) { while (scope && scope->nestedIn) {
scope = temp; const Scope* temp = scope->nestedIn->findRecordInNestedList(tok1->str());
} else { if (!temp && scope->functionOf)
// find first scope temp = scope->functionOf->findRecordInNestedList(tok1->str());
while (scope && scope->nestedIn) { if (temp) {
temp = scope->nestedIn->findRecordInNestedList(tok1->str()); scope = temp;
if (temp) { break;
scope = temp;
break;
}
scope = scope->nestedIn;
} }
scope = scope->nestedIn;
} }
} }

View File

@ -5827,22 +5827,43 @@ private:
} }
void enum15() { void enum15() {
GET_SYMBOL_DB("struct S {\n" {
" S();\n" GET_SYMBOL_DB("struct S {\n"
" enum E { E0 };\n" " S();\n"
"};\n" " enum E { E0 };\n"
"S::S() {\n" "};\n"
" E e = E::E0;\n" "S::S() {\n"
"}\n"); " E e = E::E0;\n"
ASSERT(db != nullptr); "}\n");
auto it = db->scopeList.begin(); ASSERT(db != nullptr);
std::advance(it, 2); auto it = db->scopeList.begin();
const Enumerator* E0 = it->findEnumerator("E0"); std::advance(it, 2);
ASSERT(E0 && E0->value_known && E0->value == 0); const Enumerator* E0 = it->findEnumerator("E0");
std::advance(it, 1); ASSERT(E0 && E0->value_known && E0->value == 0);
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E0 ;"); std::advance(it, 1);
ASSERT(e && e->enumerator()); const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E0 ;");
ASSERT_EQUALS(E0, e->enumerator()); ASSERT(e && e->enumerator());
ASSERT_EQUALS(E0, e->enumerator());
}
{
GET_SYMBOL_DB("struct S {\n"
" S(bool x);\n"
" enum E { E0 };\n"
"};\n"
"S::S(bool x) {\n"
" if (x)\n"
" E e = E::E0;\n"
"}\n");
ASSERT(db != nullptr);
auto it = db->scopeList.begin();
std::advance(it, 2);
const Enumerator* E0 = it->findEnumerator("E0");
ASSERT(E0 && E0->value_known && E0->value == 0);
std::advance(it, 1);
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E0 ;");
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E0, e->enumerator());
}
} }
void sizeOfType() { void sizeOfType() {