MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / isDeadCode

Method isDeadCode

lib/reverseanalyzer.cpp:161–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

astIsLHSFunction · 0.85
astIsRHSFunction · 0.85
evalCondFunction · 0.85
astParentMethod · 0.80
astOperand2Method · 0.80
astOperand1Method · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected