From 49c8e42b30afce23173202364581b9864f883e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 13 Mar 2018 13:14:26 +0100 Subject: [PATCH] misra.py: Clarify code for switch case fallthrough --- addons/misra.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index 756dd2b99..2d214d9d2 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -796,32 +796,31 @@ def misra_16_2(data): def misra_16_3(rawTokens): - # state: - # 0 => default state - # 1 => break/attribute is seen but not its ';' - # 2 => a case/default is allowed (we have seen 'break;'/'comment'/'{'/attribute) - state = 0 + STATE_NONE = 0 # default state, not in switch case/default block + STATE_BREAK = 1 # break/comment is seen but not its ';' + STATE_OK = 2 # a case/default is allowed (we have seen 'break;'/'comment'/'{'/attribute) + state = STATE_NONE for token in rawTokens: if token.str == 'break' or token.str == 'return' or token.str == 'throw': - state = 1 + state = STATE_BREAK elif token.str == ';': - if state == 1: - state = 2 + if state == STATE_BREAK: + state = STATE_OK else: - state = 0 + state = STATE_NONE elif token.str.startswith('/*') or token.str.startswith('//'): if 'fallthrough' in token.str.lower(): - state = 2 + state = STATE_OK elif simpleMatch(token, '[ [ fallthrough ] ] ;'): - state = 1 + state = STATE_BREAK elif token.str == '{': - state = 2 + state = STATE_OK elif token.str == '}': - state = 0 + state = STATE_NONE elif token.str == 'case' or token.str == 'default': - if state != 2: + if state != STATE_OK: reportError(token, 16, 3) - state = 2 + state = STATE_OK def misra_16_4(data):