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

Function assume

lib/vf_analyzers.cpp:726–763  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

724 }
725
726 void assume(const Token* tok, bool state, unsigned int flags) override {
727 // Update program state
728 pms.removeModifiedVars(tok);
729 pms.addState(tok, getProgramState());
730 pms.assume(tok, state, flags & Assume::ContainerEmpty);
731
732 bool isCondBlock = false;
733 const Token* parent = tok->astParent();
734 if (parent) {
735 isCondBlock = Token::Match(parent->previous(), "if|while (");
736 }
737
738 if (isCondBlock) {
739 const Token* startBlock = parent->link()->next();
740 if (Token::simpleMatch(startBlock, ";") && Token::simpleMatch(parent->tokAt(-2), "} while ("))
741 startBlock = parent->linkAt(-2);
742 const Token* endBlock = startBlock->link();
743 if (state) {
744 pms.removeModifiedVars(endBlock);
745 pms.addState(endBlock->previous(), getProgramState());
746 } else {
747 if (Token::simpleMatch(endBlock, "} else {"))
748 pms.addState(endBlock->linkAt(2)->previous(), getProgramState());
749 }
750 }
751
752 if (!(flags & Assume::Quiet)) {
753 if (flags & Assume::ContainerEmpty) {
754 std::string s = state ? "empty" : "not empty";
755 addErrorPath(tok, "Assuming container is " + s);
756 } else {
757 std::string s = bool_to_string(state);
758 addErrorPath(tok, "Assuming condition is " + s);
759 }
760 }
761 if (!(flags & Assume::Absolute))
762 makeConditional();
763 }
764
765 void updateState(const Token* tok) override
766 {

Callers

nothing calls this directly

Calls 9

bool_to_stringFunction · 0.85
removeModifiedVarsMethod · 0.80
addStateMethod · 0.80
assumeMethod · 0.80
astParentMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
simpleMatchFunction · 0.70
tokAtMethod · 0.45

Tested by

no test coverage detected