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:
Edoardo Prezioso 2013-01-03 22:37:19 +01:00
parent 4b386986fc
commit c9fb7f529d
2 changed files with 24 additions and 25 deletions

View File

@ -2377,7 +2377,7 @@ const Function* SymbolDatabase::findFunctionByNameAndArgs(const Token *tok, cons
//---------------------------------------------------------------------------
const Scope* SymbolDatabase::findScopeByName(const std::string& name) const
const Scope *SymbolDatabase::findScopeByName(const std::string& name) const
{
for (std::list<Scope>::const_iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
if (it->className == name)
@ -2388,7 +2388,7 @@ const Scope* SymbolDatabase::findScopeByName(const std::string& name) const
//---------------------------------------------------------------------------
Scope * Scope::findInNestedList(const std::string & name)
Scope *Scope::findInNestedList(const std::string & name)
{
std::list<Scope *>::iterator it;
@ -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;
@ -2414,7 +2414,7 @@ Scope * Scope::findRecordInNestedList(const std::string & name)
//---------------------------------------------------------------------------
Scope * Scope::findInNestedListRecursive(const std::string & name)
Scope *Scope::findInNestedListRecursive(const std::string & name)
{
std::list<Scope *>::iterator it;
@ -2433,7 +2433,7 @@ Scope * Scope::findInNestedListRecursive(const std::string & name)
//---------------------------------------------------------------------------
const Scope * Scope::findQualifiedScope(const std::string & name) const
const Scope *Scope::findQualifiedScope(const std::string & name) const
{
if (type == Scope::eClass || type == Scope::eStruct || type == Scope::eNamespace) {
if (name.compare(0, className.size(), className) == 0) {
@ -2490,17 +2490,12 @@ bool SymbolDatabase::isCPP() 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)
const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope) const
{
// absolute path
if (tok->str() == "::") {
tok = tok->next();
Scope *scope = &scopeList.front();
const Scope *scope = &scopeList.front();
while (scope && tok && tok->isName()) {
scope = scope->findRecordInNestedList(tok->str());
@ -2519,7 +2514,7 @@ Scope * SymbolDatabase::findScope(const Token *tok, Scope *startScope)
// relative path
else if (tok->isName()) {
Scope *scope = startScope;
const Scope *scope = startScope;
while (scope && tok && tok->isName()) {
scope = scope->findRecordInNestedList(tok->str());

View File

@ -509,17 +509,20 @@ public:
* @brief find if name is in nested list
* @param name name of nested scope
*/
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
* @param name name of nested scope
*/
Scope * findInNestedListRecursive(const std::string & name);
Scope *findInNestedListRecursive(const std::string & name);
const Scope * findQualifiedScope(const std::string & name) const;
const Scope *findQualifiedScope(const std::string & name) const;
void addVariable(const Token *token_, const Token *start_,
const Token *end_, AccessControl access_, const Scope *type_,
@ -599,7 +602,7 @@ public:
const Function *findFunctionByToken(const Token *tok) const;
const Function* findFunctionByName(const std::string& str, const Scope* startScope) const;
const Function *findFunctionByName(const std::string& str, const Scope* startScope) const;
/**
* @brief find a function by name and arguments
@ -607,13 +610,16 @@ public:
* @param startScope scope to start looking in
* @return pointer to function if found or NULL if not found
*/
const Function* findFunctionByNameAndArgs(const Token *tok, const Scope *startScope) const;
const Function *findFunctionByNameAndArgs(const Token *tok, const Scope *startScope) const;
const Function* findFunctionByNameAndArgsInScope(const Token *tok, const Scope *scope) const;
const Function *findFunctionByNameAndArgsInScope(const Token *tok, const Scope *scope) const;
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;
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 {
return bool(classAndStructTypes.find(type) != classAndStructTypes.end());
@ -643,13 +649,11 @@ private:
friend class Scope;
void addClassFunction(Scope **info, const Token **tok, const Token *argStart);
Function* addGlobalFunctionDecl(Scope*& scope, const Token *argStart, const Token* funcStart);
Function* addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
Function *addGlobalFunctionDecl(Scope*& scope, const Token *argStart, const Token* funcStart);
Function *addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
void addNewFunction(Scope **info, const Token **tok);
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 */
std::set<std::string> classAndStructTypes;