diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 2632db65c..fbbcc535c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -510,12 +510,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti { scope = *it; - // skip functions - if (scope->type != Scope::eFunction) - { - // find variables - scope->getVariableList(); - } + // find variables + scope->getVariableList(); } // fill in function arguments @@ -645,6 +641,46 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } } } + + // create variable symbol table + _variableList.resize(_tokenizer->varIdCount() + 1); + fill_n(_variableList.begin(), _variableList.size(), (const Variable*)NULL); + + // check all scopes for variables + for (it = scopeList.begin(); it != scopeList.end(); ++it) + { + scope = *it; + + // add all variables + std::list::const_iterator var; + for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) + { + unsigned int varId = var->varId(); + if (varId) + _variableList[varId] = &*var; + } + + // add all function paramaters + std::list::const_iterator func; + for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) + { + // ignore function without implementations + if (!func->hasBody) + continue; + + std::list::const_iterator arg; + for (arg = func->argumentList.begin(); arg != func->argumentList.end(); ++arg) + { + // check for named parameters + if (arg->nameToken() && arg->varId()) + { + unsigned int varId = arg->varId(); + if (varId) + _variableList[varId] = &*arg; + } + } + } + } } SymbolDatabase::~SymbolDatabase() diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index ab7841451..8f6cdbc63 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -473,6 +473,11 @@ public: return bool(classAndStructTypes.find(type) != classAndStructTypes.end()); } + const Variable *getVariableFromVarId(unsigned int varId) const + { + return _variableList[varId]; + } + private: // Needed by Borland C++: @@ -489,6 +494,9 @@ private: const Tokenizer *_tokenizer; const Settings *_settings; ErrorLogger *_errorLogger; + + /** variable symbol table */ + std::vector _variableList; }; #endif