| 1154 | } |
| 1155 | |
| 1156 | static bool isSimpleExpr(const Token* tok, const Variable* var, const Settings& settings) { |
| 1157 | if (!tok) |
| 1158 | return false; |
| 1159 | if (tok->isNumber() || tok->tokType() == Token::eString || tok->tokType() == Token::eChar || tok->isBoolean()) |
| 1160 | return true; |
| 1161 | if (isNullOperand(tok)) |
| 1162 | return true; |
| 1163 | bool needsCheck = tok->varId() > 0; |
| 1164 | if (!needsCheck) { |
| 1165 | if (tok->isArithmeticalOp()) |
| 1166 | return isSimpleExpr(tok->astOperand1(), var, settings) && (!tok->astOperand2() || isSimpleExpr(tok->astOperand2(), var, settings)); |
| 1167 | const Token* ftok = tok->previous(); |
| 1168 | if (Token::Match(ftok, "%name% (") && |
| 1169 | ((ftok->function() && ftok->function()->isConst()) || settings.library.isFunctionConst(ftok->str(), /*pure*/ true))) |
| 1170 | needsCheck = true; |
| 1171 | else if (tok->str() == "[") { |
| 1172 | needsCheck = tok->astOperand1() && tok->astOperand1()->varId() > 0; |
| 1173 | tok = tok->astOperand1(); |
| 1174 | } |
| 1175 | else if (isLeafDot(tok->astOperand2())) { |
| 1176 | needsCheck = tok->astOperand2()->varId() > 0; |
| 1177 | tok = tok->astOperand2(); |
| 1178 | } |
| 1179 | } |
| 1180 | return (needsCheck && !findExpressionChanged(tok, tok->astParent(), var->scope()->bodyEnd, settings)); |
| 1181 | } |
| 1182 | |
| 1183 | //--------------------------------------------------------------------------- |
| 1184 | // Check scope of variables.. |
no test coverage detected