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

Function isFloatCounterInWhileLoop

addons/misra.py:983–1015  ·  view source on GitHub ↗
(whileToken)

Source from the content-addressed store, hash-verified

981
982
983def isFloatCounterInWhileLoop(whileToken):
984 if not simpleMatch(whileToken, 'while ('):
985 return False
986 lpar = whileToken.next
987 rpar = lpar.link
988 counterTokens = findCounterTokens(lpar.astOperand2)
989 tok_varid = tuple(tok.varId for tok in counterTokens if tok.varId)
990 whileBodyStart = None
991 if simpleMatch(rpar, ') {'):
992 whileBodyStart = rpar.next
993 elif simpleMatch(whileToken.previous, '} while') and simpleMatch(whileToken.previous.link.previous, 'do {'):
994 whileBodyStart = whileToken.previous.link
995 else:
996 return False
997 token = whileBodyStart
998 while token != whileBodyStart.link:
999 token = token.next
1000 if not token.varId:
1001 continue
1002 if token.varId not in tok_varid:
1003 continue
1004 if not token.astParent or not token.valueType or not token.valueType.isFloat():
1005 continue
1006 parent = token.astParent
1007 if parent.str in ('++', '--'):
1008 return True
1009 while parent:
1010 if parent.isAssignmentOp and parent.str != "=" and parent.astOperand1 == token:
1011 return True
1012 if parent.str == "=" and parent.astOperand1.str == token.str and parent.astOperand1 != token:
1013 return True
1014 parent = parent.astParent
1015 return False
1016
1017
1018def countSideEffectsRecursive(expr):

Callers 1

misra_14_1Method · 0.85

Calls 3

findCounterTokensFunction · 0.85
simpleMatchFunction · 0.70
isFloatMethod · 0.45

Tested by

no test coverage detected