Refactorization in SymbolDatabase: Do not redundantly store name in FriendInfo, and store FriendInfo in vector instead of list

This commit is contained in:
PKEuS 2018-05-14 12:18:59 +02:00
parent 4d549553b0
commit 090a178ed6
4 changed files with 13 additions and 22 deletions

View File

@ -1055,10 +1055,10 @@ void CheckClass::privateFunctions()
// Check that all private functions are used
bool used = checkFunctionUsage(privateFuncs.front(), scope); // Usage in this class
// Check in friend classes
const std::list<Type::FriendInfo>& friendList = scope->definedType->friendList;
for (std::list<Type::FriendInfo>::const_iterator it = friendList.begin(); !used && it != friendList.end(); ++it) {
if (it->type)
used = checkFunctionUsage(privateFuncs.front(), it->type->classScope);
const std::vector<Type::FriendInfo>& friendList = scope->definedType->friendList;
for (size_t i = 0; i < friendList.size(); i++) {
if (friendList[i].type)
used = checkFunctionUsage(privateFuncs.front(), friendList[i].type->classScope);
else
used = true; // Assume, it is used if we do not see friend class
}

View File

@ -544,10 +544,6 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
while (friendInfo.nameEnd && friendInfo.nameEnd->strAt(1) == "::")
friendInfo.nameEnd = friendInfo.nameEnd->tokAt(2);
// save the name
if (friendInfo.nameEnd)
friendInfo.name = friendInfo.nameEnd->str();
// fill this in after parsing is complete
friendInfo.type = nullptr;
@ -705,7 +701,7 @@ void SymbolDatabase::createSymbolDatabaseClassInfo()
// fill in friend info
for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
for (std::list<Type::FriendInfo>::iterator i = it->friendList.begin(); i != it->friendList.end(); ++i) {
for (std::vector<Type::FriendInfo>::iterator i = it->friendList.begin(); i != it->friendList.end(); ++i) {
i->type = findType(i->nameStart, it->enclosingScope);
}
}
@ -2884,18 +2880,14 @@ void SymbolDatabase::printOut(const char *title) const
std::cout << " )" << std::endl;
std::cout << " friendList[" << type->friendList.size() << "] = (";
std::list<Type::FriendInfo>::const_iterator fii;
count = type->friendList.size();
for (fii = type->friendList.begin(); fii != type->friendList.end(); ++fii) {
if (fii->type)
std::cout << fii->type;
for (size_t i = 0; i < type->friendList.size(); i++) {
if (type->friendList[i].type)
std::cout << type->friendList[i].type;
else
std::cout << " Unknown";
std::cout << " " << fii->name;
if (count-- > 1)
std::cout << " " << type->friendList[i].nameEnd ? type->friendList[i].nameEnd->str() : emptyString;
if (i+1 < type->friendList.size())
std::cout << ",";
}

View File

@ -93,12 +93,11 @@ public:
const Token* nameStart;
const Token* nameEnd;
std::string name;
const Type* type;
};
std::vector<BaseInfo> derivedFrom;
std::list<FriendInfo> friendList;
std::vector<FriendInfo> friendList;
const Token * typeStart;
const Token * typeEnd;

View File

@ -1580,8 +1580,8 @@ private:
ASSERT(bar2 != nullptr);
if (foo && bar1 && bar2) {
ASSERT(bar1->definedType->friendList.size() == 1 && bar1->definedType->friendList.front().name == "Foo" && bar1->definedType->friendList.front().type == foo->definedType);
ASSERT(bar2->definedType->friendList.size() == 1 && bar2->definedType->friendList.front().name == "Foo" && bar2->definedType->friendList.front().type == foo->definedType);
ASSERT(bar1->definedType->friendList.size() == 1 && bar1->definedType->friendList.front().nameEnd->str() == "Foo" && bar1->definedType->friendList.front().type == foo->definedType);
ASSERT(bar2->definedType->friendList.size() == 1 && bar2->definedType->friendList.front().nameEnd->str() == "Foo" && bar2->definedType->friendList.front().type == foo->definedType);
}
}
}