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

Function isSimpleExpr

lib/checkother.cpp:1156–1181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1154}
1155
1156static 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..

Callers 1

checkVariableScopeMethod · 0.85

Calls 12

isNullOperandFunction · 0.85
isLeafDotFunction · 0.85
findExpressionChangedFunction · 0.85
isArithmeticalOpMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
isConstMethod · 0.80
isFunctionConstMethod · 0.80
astParentMethod · 0.80
scopeMethod · 0.80
functionMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected