set symbol database array variable dimensions specified by a variable to the maximum size that variable can hold

This commit is contained in:
Robert Reif 2011-06-23 22:35:15 -04:00
parent 65ecbfd4ff
commit 4656eba34c
1 changed files with 74 additions and 0 deletions

View File

@ -31,6 +31,7 @@
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
//---------------------------------------------------------------------------
@ -801,6 +802,79 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
}
}
}
/* set all unknown array dimensions that are set by a variable to the maximum size of that variable type */
for (size_t i = 1; i <= _tokenizer->varIdCount(); i++)
{
// check each array variable
if (_variableList[i] && _variableList[i]->isArray())
{
// check each array dimension
for (size_t j = 0; j < _variableList[i]->dimensions().size(); j++)
{
// check for a single token dimension that is a variable
if ((_variableList[i]->dimensions()[j].start == _variableList[i]->dimensions()[j].end) &&
_variableList[i]->dimensions()[j].start->varId())
{
Dimension &dimension = const_cast<Dimension &>(_variableList[i]->dimensions()[j]);
// get maximum size from type
// find where this type is defined
const Variable *var = getVariableFromVarId(dimension.start->varId());
// make sure it is in the database
if (!var)
break;
// get type token
const Token *index_type = var->typeEndToken();
if (index_type->str() == "char")
{
if (index_type->isUnsigned())
dimension.num = UCHAR_MAX + 1;
else if (index_type->isSigned())
dimension.num = SCHAR_MAX + 1;
else
dimension.num = CHAR_MAX + 1;
}
else if (index_type->str() == "short")
{
if (index_type->isUnsigned())
dimension.num = USHRT_MAX + 1;
else
dimension.num = SHRT_MAX + 1;
}
// checkScope assumes size is signed int so we limit the following sizes to INT_MAX
else if (index_type->str() == "int")
{
if (index_type->isUnsigned())
dimension.num = UINT_MAX + 1ULL;
else
dimension.num = INT_MAX + 1ULL;
}
else if (index_type->str() == "long")
{
if (index_type->isUnsigned())
{
if (index_type->isLong())
dimension.num = ULLONG_MAX; // should be ULLONG_MAX + 1ULL;
else
dimension.num = ULONG_MAX + 1ULL;
}
else
{
if (index_type->isLong())
dimension.num = LLONG_MAX; // should be LLONG_MAX + 1LL;
else
dimension.num = LONG_MAX + 1LL;
}
}
}
}
}
}
}
bool SymbolDatabase::isFunction(const Token *tok, const Token **funcStart, const Token **argStart) const