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

Function getSwitchValues

lib/astutils.cpp:3767–3793  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3765}
3766
3767static std::set<MathLib::bigint> getSwitchValues(const Token *startbrace, bool &hasDefault)
3768{
3769 std::set<MathLib::bigint> values;
3770 const Token *endbrace = startbrace->link();
3771 if (!endbrace)
3772 return values;
3773
3774 hasDefault = false;
3775 for (const Token *tok = startbrace->next(); tok && tok != endbrace; tok = tok->next()) {
3776 if (Token::simpleMatch(tok, "{") && tok->scope()->type == ScopeType::eSwitch) {
3777 tok = tok->link();
3778 continue;
3779 }
3780 if (Token::simpleMatch(tok, "default")) {
3781 hasDefault = true;
3782 break;
3783 }
3784 if (Token::simpleMatch(tok, "case")) {
3785 const Token *valueTok = tok->astOperand1();
3786 if (const ValueFlow::Value* v = valueTok->getKnownValue(ValueFlow::Value::ValueType::INT))
3787 values.insert(v->intvalue);
3788 continue;
3789 }
3790 }
3791
3792 return values;
3793}
3794
3795bool isExhaustiveSwitch(const Token *startbrace)
3796{

Callers 1

isExhaustiveSwitchFunction · 0.85

Calls 5

nextMethod · 0.80
scopeMethod · 0.80
astOperand1Method · 0.80
getKnownValueMethod · 0.80
simpleMatchFunction · 0.70

Tested by

no test coverage detected