Refactoring: use continue

This commit is contained in:
Daniel Marjamäki 2019-03-14 19:53:45 +01:00
parent 5728bd63af
commit 56c47fc6ed
1 changed files with 70 additions and 70 deletions

View File

@ -1263,84 +1263,84 @@ void SymbolDatabase::createSymbolDatabaseUnknownArrayDimensions()
// set all unknown array dimensions // set all unknown array dimensions
for (std::size_t i = 1; i <= mTokenizer->varIdCount(); i++) { for (std::size_t i = 1; i <= mTokenizer->varIdCount(); i++) {
// check each array variable // check each array variable
if (mVariableList[i] && mVariableList[i]->isArray()) { if (!mVariableList[i] || !mVariableList[i]->isArray())
// check each array dimension continue;
const std::vector<Dimension>& dimensions = mVariableList[i]->dimensions(); // check each array dimension
for (std::size_t j = 0; j < dimensions.size(); j++) { const std::vector<Dimension>& dimensions = mVariableList[i]->dimensions();
Dimension &dimension = const_cast<Dimension &>(dimensions[j]); for (std::size_t j = 0; j < dimensions.size(); j++) {
if (dimension.num == 0) { Dimension &dimension = const_cast<Dimension &>(dimensions[j]);
dimension.known = false; if (dimension.num != 0)
// check for a single token dimension continue;
if (dimension.start && (dimension.start == dimension.end)) { dimension.known = false;
// check for an enumerator // check for a single token dimension
if (dimension.start->enumerator()) { if (dimension.start && (dimension.start == dimension.end)) {
if (dimension.start->enumerator()->value_known) { // check for an enumerator
dimension.num = dimension.start->enumerator()->value; if (dimension.start->enumerator()) {
dimension.known = true; if (dimension.start->enumerator()->value_known) {
} dimension.num = dimension.start->enumerator()->value;
} dimension.known = true;
}
}
// check for a variable // check for a variable
else if (dimension.start->varId()) { else if (dimension.start->varId()) {
// get maximum size from type // get maximum size from type
// find where this type is defined // find where this type is defined
const Variable *var = getVariableFromVarId(dimension.start->varId()); const Variable *var = getVariableFromVarId(dimension.start->varId());
// make sure it is in the database // make sure it is in the database
if (!var) if (!var)
break; break;
// get type token // get type token
const Token *index_type = var->typeEndToken(); const Token *index_type = var->typeEndToken();
if (index_type->str() == "char") { if (index_type->str() == "char") {
if (index_type->isUnsigned()) if (index_type->isUnsigned())
dimension.num = UCHAR_MAX + 1; dimension.num = UCHAR_MAX + 1;
else if (index_type->isSigned()) else if (index_type->isSigned())
dimension.num = SCHAR_MAX + 1; dimension.num = SCHAR_MAX + 1;
else else
dimension.num = CHAR_MAX + 1; dimension.num = CHAR_MAX + 1;
} else if (index_type->str() == "short") { } else if (index_type->str() == "short") {
if (index_type->isUnsigned()) if (index_type->isUnsigned())
dimension.num = USHRT_MAX + 1; dimension.num = USHRT_MAX + 1;
else else
dimension.num = SHRT_MAX + 1; dimension.num = SHRT_MAX + 1;
} }
// checkScope assumes size is signed int so we limit the following sizes to INT_MAX // checkScope assumes size is signed int so we limit the following sizes to INT_MAX
else if (index_type->str() == "int") { else if (index_type->str() == "int") {
if (index_type->isUnsigned()) if (index_type->isUnsigned())
dimension.num = UINT_MAX + 1ULL; dimension.num = UINT_MAX + 1ULL;
else else
dimension.num = INT_MAX + 1ULL; dimension.num = INT_MAX + 1ULL;
} else if (index_type->str() == "long") { } else if (index_type->str() == "long") {
if (index_type->isUnsigned()) { if (index_type->isUnsigned()) {
if (index_type->isLong()) if (index_type->isLong())
dimension.num = ULLONG_MAX; // should be ULLONG_MAX + 1ULL dimension.num = ULLONG_MAX; // should be ULLONG_MAX + 1ULL
else else
dimension.num = ULONG_MAX; // should be ULONG_MAX + 1ULL dimension.num = ULONG_MAX; // should be ULONG_MAX + 1ULL
} else { } else {
if (index_type->isLong()) if (index_type->isLong())
dimension.num = LLONG_MAX; // should be LLONG_MAX + 1LL dimension.num = LLONG_MAX; // should be LLONG_MAX + 1LL
else else
dimension.num = LONG_MAX; // should be LONG_MAX + 1LL dimension.num = LONG_MAX; // should be LONG_MAX + 1LL
}
}
} }
} }
// check for qualified enumerator }
else if (dimension.start) { }
// rhs of [ // check for qualified enumerator
const Token *rhs = dimension.start->previous()->astOperand2(); else if (dimension.start) {
// rhs of [
const Token *rhs = dimension.start->previous()->astOperand2();
// constant folding of expression: // constant folding of expression:
ValueFlow::valueFlowConstantFoldAST(rhs, mSettings); ValueFlow::valueFlowConstantFoldAST(rhs, mSettings);
// get constant folded value: // get constant folded value:
if (rhs && rhs->hasKnownIntValue()) { if (rhs && rhs->hasKnownIntValue()) {
dimension.num = rhs->values().front().intvalue; dimension.num = rhs->values().front().intvalue;
dimension.known = true; dimension.known = true;
}
}
} }
} }
} }