Use more Effective C++ code style in SymbolDatabase class:
1)The SymbolDatabase::findScope code is moved to the const-version. The non-const version is reimplemented as the combination with const_cast and static_cast. 2)Unrelated: change style of the declaration of some functions (the '*' is moved near the function name).
This commit is contained in:
parent
4b386986fc
commit
c9fb7f529d
@ -2401,7 +2401,7 @@ Scope * Scope::findInNestedList(const std::string & name)
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
Scope * Scope::findRecordInNestedList(const std::string & name)
|
const Scope *Scope::findRecordInNestedList(const std::string & name) const
|
||||||
{
|
{
|
||||||
std::list<Scope *>::const_iterator it;
|
std::list<Scope *>::const_iterator it;
|
||||||
|
|
||||||
@ -2491,16 +2491,11 @@ bool SymbolDatabase::isCPP() const
|
|||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope) const
|
const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope) const
|
||||||
{
|
|
||||||
return const_cast<SymbolDatabase*>(this)->findScope(tok, const_cast<Scope*>(startScope));
|
|
||||||
}
|
|
||||||
|
|
||||||
Scope * SymbolDatabase::findScope(const Token *tok, Scope *startScope)
|
|
||||||
{
|
{
|
||||||
// absolute path
|
// absolute path
|
||||||
if (tok->str() == "::") {
|
if (tok->str() == "::") {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
Scope *scope = &scopeList.front();
|
const Scope *scope = &scopeList.front();
|
||||||
|
|
||||||
while (scope && tok && tok->isName()) {
|
while (scope && tok && tok->isName()) {
|
||||||
scope = scope->findRecordInNestedList(tok->str());
|
scope = scope->findRecordInNestedList(tok->str());
|
||||||
@ -2519,7 +2514,7 @@ Scope * SymbolDatabase::findScope(const Token *tok, Scope *startScope)
|
|||||||
|
|
||||||
// relative path
|
// relative path
|
||||||
else if (tok->isName()) {
|
else if (tok->isName()) {
|
||||||
Scope *scope = startScope;
|
const Scope *scope = startScope;
|
||||||
|
|
||||||
while (scope && tok && tok->isName()) {
|
while (scope && tok && tok->isName()) {
|
||||||
scope = scope->findRecordInNestedList(tok->str());
|
scope = scope->findRecordInNestedList(tok->str());
|
||||||
|
@ -511,7 +511,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
Scope *findInNestedList(const std::string & name);
|
Scope *findInNestedList(const std::string & name);
|
||||||
|
|
||||||
Scope * findRecordInNestedList(const std::string & name);
|
const Scope *findRecordInNestedList(const std::string & name) const;
|
||||||
|
Scope *findRecordInNestedList(const std::string & name) {
|
||||||
|
return const_cast<Scope *>(static_cast<const Scope *>(this)->findRecordInNestedList(name));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief find if name is in nested list
|
* @brief find if name is in nested list
|
||||||
@ -614,6 +617,9 @@ public:
|
|||||||
const Scope *findScopeByName(const std::string& name) const;
|
const Scope *findScopeByName(const std::string& name) const;
|
||||||
|
|
||||||
const Scope *findScope(const Token *tok, const Scope *startScope) const;
|
const Scope *findScope(const Token *tok, const Scope *startScope) const;
|
||||||
|
Scope *findScope(const Token *tok, Scope *startScope) const {
|
||||||
|
return const_cast<Scope *>(this->findScope(tok, static_cast<const Scope *>(startScope)));
|
||||||
|
}
|
||||||
|
|
||||||
bool isClassOrStruct(const std::string &type) const {
|
bool isClassOrStruct(const std::string &type) const {
|
||||||
return bool(classAndStructTypes.find(type) != classAndStructTypes.end());
|
return bool(classAndStructTypes.find(type) != classAndStructTypes.end());
|
||||||
@ -648,8 +654,6 @@ private:
|
|||||||
void addNewFunction(Scope **info, const Token **tok);
|
void addNewFunction(Scope **info, const Token **tok);
|
||||||
static bool isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart);
|
static bool isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart);
|
||||||
|
|
||||||
Scope *findScope(const Token *tok, Scope *startScope);
|
|
||||||
|
|
||||||
/** class/struct types */
|
/** class/struct types */
|
||||||
std::set<std::string> classAndStructTypes;
|
std::set<std::string> classAndStructTypes;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user