| 159 | } |
| 160 | |
| 161 | Token* isDeadCode(Token* tok, const Token* end = nullptr) const { |
| 162 | int opSide = 0; |
| 163 | for (; tok && tok->astParent(); tok = tok->astParent()) { |
| 164 | if (tok == end) |
| 165 | break; |
| 166 | Token* parent = tok->astParent(); |
| 167 | if (Token::simpleMatch(parent, ":")) { |
| 168 | if (astIsLHS(tok)) |
| 169 | opSide = 1; |
| 170 | else if (astIsRHS(tok)) |
| 171 | opSide = 2; |
| 172 | else |
| 173 | opSide = 0; |
| 174 | } |
| 175 | if (tok != parent->astOperand2()) |
| 176 | continue; |
| 177 | if (Token::simpleMatch(parent, ":")) |
| 178 | parent = parent->astParent(); |
| 179 | if (!Token::Match(parent, "%oror%|&&|?")) |
| 180 | continue; |
| 181 | const Token* condTok = parent->astOperand1(); |
| 182 | if (!condTok) |
| 183 | continue; |
| 184 | bool checkThen, checkElse; |
| 185 | std::tie(checkThen, checkElse) = evalCond(condTok); |
| 186 | |
| 187 | if (parent->str() == "?") { |
| 188 | if (checkElse && opSide == 1) |
| 189 | return parent; |
| 190 | if (checkThen && opSide == 2) |
| 191 | return parent; |
| 192 | } |
| 193 | if (!checkThen && parent->str() == "&&") |
| 194 | return parent; |
| 195 | if (!checkElse && parent->str() == "||") |
| 196 | return parent; |
| 197 | } |
| 198 | return nullptr; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * @throws InternalError thrown on cyclic analysis |
nothing calls this directly
no test coverage detected