cppcheck-suppress functionConst
| 3988 | |
| 3989 | // cppcheck-suppress functionConst |
| 3990 | void Tokenizer::arraySizeAfterValueFlow() |
| 3991 | { |
| 3992 | // After ValueFlow, adjust array sizes. |
| 3993 | for (const Variable* var: mSymbolDatabase->variableList()) { |
| 3994 | if (!var || !var->isArray()) |
| 3995 | continue; |
| 3996 | if (!Token::Match(var->nameToken(), "%name% [ ] = { [")) |
| 3997 | continue; |
| 3998 | MathLib::bigint maxIndex = -1; |
| 3999 | const Token* const startToken = var->nameToken()->tokAt(4); |
| 4000 | const Token* const endToken = startToken->link(); |
| 4001 | for (const Token* tok = startToken; tok != endToken; tok = tok->next()) { |
| 4002 | if (!Token::Match(tok, "[{,] [") || !Token::simpleMatch(tok->linkAt(1), "] =")) |
| 4003 | continue; |
| 4004 | const Token* expr = tok->next()->astOperand1(); |
| 4005 | if (expr && expr->hasKnownIntValue()) |
| 4006 | maxIndex = std::max(maxIndex, expr->getKnownIntValue()); |
| 4007 | } |
| 4008 | if (maxIndex >= 0) { |
| 4009 | // insert array size |
| 4010 | auto* tok = const_cast<Token*>(var->nameToken()->next()); |
| 4011 | tok->insertToken(MathLib::toString(maxIndex + 1)); |
| 4012 | // ast |
| 4013 | tok->astOperand2(tok->next()); |
| 4014 | // Token::scope |
| 4015 | tok->next()->scope(tok->scope()); |
| 4016 | // Value flow |
| 4017 | ValueFlow::Value value(maxIndex + 1); |
| 4018 | value.setKnown(); |
| 4019 | tok->next()->addValue(value); |
| 4020 | // Set array dimensions |
| 4021 | Dimension d; |
| 4022 | d.num = maxIndex + 1; |
| 4023 | std::vector<Dimension> dimensions{d}; |
| 4024 | const_cast<Variable*>(var)->setDimensions(dimensions); |
| 4025 | } |
| 4026 | } |
| 4027 | } |
| 4028 | |
| 4029 | static Token *skipTernaryOp(Token *tok) |
| 4030 | { |
nothing calls this directly
no test coverage detected