add a varId to Variable lookup table and fill it in with all variables

This commit is contained in:
Robert Reif 2011-02-26 15:57:16 -05:00
parent 7638a4554e
commit 8152cbbd1b
2 changed files with 50 additions and 6 deletions

View File

@ -510,13 +510,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
{ {
scope = *it; scope = *it;
// skip functions
if (scope->type != Scope::eFunction)
{
// find variables // find variables
scope->getVariableList(); scope->getVariableList();
} }
}
// fill in function arguments // fill in function arguments
for (it = scopeList.begin(); it != scopeList.end(); ++it) for (it = scopeList.begin(); it != scopeList.end(); ++it)
@ -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<Variable>::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<Function>::const_iterator func;
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func)
{
// ignore function without implementations
if (!func->hasBody)
continue;
std::list<Variable>::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() SymbolDatabase::~SymbolDatabase()

View File

@ -473,6 +473,11 @@ public:
return bool(classAndStructTypes.find(type) != classAndStructTypes.end()); return bool(classAndStructTypes.find(type) != classAndStructTypes.end());
} }
const Variable *getVariableFromVarId(unsigned int varId) const
{
return _variableList[varId];
}
private: private:
// Needed by Borland C++: // Needed by Borland C++:
@ -489,6 +494,9 @@ private:
const Tokenizer *_tokenizer; const Tokenizer *_tokenizer;
const Settings *_settings; const Settings *_settings;
ErrorLogger *_errorLogger; ErrorLogger *_errorLogger;
/** variable symbol table */
std::vector<const Variable *> _variableList;
}; };
#endif #endif