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

Method misra_15_6

addons/misra.py:3202–3274  ·  view source on GitHub ↗
(self, rawTokens)

Source from the content-addressed store, hash-verified

3200 self.reportError(token, 15, 5)
3201
3202 def misra_15_6(self, rawTokens):
3203 state = 0
3204 indent = 0
3205 tok1 = None
3206 def tokAt(tok,i):
3207 while i < 0 and tok:
3208 tok = tok.previous
3209 if tok.str.startswith('//') or tok.str.startswith('/*'):
3210 continue
3211 i += 1
3212 while i > 0 and tok:
3213 tok = tok.next
3214 if tok.str.startswith('//') or tok.str.startswith('/*'):
3215 continue
3216 i -= 1
3217 return tok
3218
3219 def strtokens(tok, i1, i2):
3220 tok1 = tokAt(tok, i1)
3221 tok2 = tokAt(tok, i2)
3222 tok = tok1
3223 s = ''
3224 while tok != tok2:
3225 if tok.str.startswith('//') or tok.str.startswith('/*'):
3226 tok = tok.next
3227 continue
3228 s += ' ' + tok.str
3229 tok = tok.next
3230 s += ' ' + tok.str
3231 return s[1:]
3232
3233 for token in rawTokens:
3234 if token.str in ['if', 'for', 'while']:
3235 if strtokens(token,-1,0) == '# if':
3236 continue
3237 if strtokens(token,-1,0) == "} while":
3238 # is there a 'do { .. } while'?
3239 start = rawlink(tokAt(token,-1))
3240 if start and strtokens(start, -1, 0) == 'do {':
3241 continue
3242 if state == 2:
3243 self.reportError(tok1, 15, 6)
3244 state = 1
3245 indent = 0
3246 tok1 = token
3247 elif token.str == 'else':
3248 if strtokens(token,-1,0) == '# else':
3249 continue
3250 if strtokens(token,0,1) == 'else if':
3251 continue
3252 if state == 2:
3253 self.reportError(tok1, 15, 6)
3254 state = 2
3255 indent = 0
3256 tok1 = token
3257 elif state == 1:
3258 if indent == 0 and token.str != '(':
3259 state = 0

Callers

nothing calls this directly

Calls 3

reportErrorMethod · 0.95
rawlinkFunction · 0.85
tokAtFunction · 0.85

Tested by

no test coverage detected