@@ -2832,24 +2832,51 @@ def misra_15_6(self, rawTokens):
28322832 state = 0
28332833 indent = 0
28342834 tok1 = None
2835+ def tokAt (tok ,i ):
2836+ while i < 0 and tok :
2837+ tok = tok .previous
2838+ if tok .str .startswith ('//' ) or tok .str .startswith ('/*' ):
2839+ continue
2840+ i += 1
2841+ while i > 0 and tok :
2842+ tok = tok .next
2843+ if tok .str .startswith ('//' ) or tok .str .startswith ('/*' ):
2844+ continue
2845+ i -= 1
2846+ return tok
2847+
2848+ def strtokens (tok , i1 , i2 ):
2849+ tok1 = tokAt (tok , i1 )
2850+ tok2 = tokAt (tok , i2 )
2851+ tok = tok1
2852+ s = ''
2853+ while tok != tok2 :
2854+ if tok .str .startswith ('//' ) or tok .str .startswith ('/*' ):
2855+ tok = tok .next
2856+ continue
2857+ s += ' ' + tok .str
2858+ tok = tok .next
2859+ s += ' ' + tok .str
2860+ return s [1 :]
2861+
28352862 for token in rawTokens :
28362863 if token .str in ['if' , 'for' , 'while' ]:
2837- if simpleMatch (token . previous , '# if' ) :
2864+ if strtokens (token , - 1 , 0 ) == '# if' :
28382865 continue
2839- if simpleMatch (token . previous , "} while" ) :
2866+ if strtokens (token , - 1 , 0 ) == "} while" :
28402867 # is there a 'do { .. } while'?
2841- start = rawlink (token . previous )
2842- if start and simpleMatch (start . previous , 'do {' ) :
2868+ start = rawlink (tokAt ( token , - 1 ) )
2869+ if start and strtokens (start , - 1 , 0 ) == 'do {' :
28432870 continue
28442871 if state == 2 :
28452872 self .reportError (tok1 , 15 , 6 )
28462873 state = 1
28472874 indent = 0
28482875 tok1 = token
28492876 elif token .str == 'else' :
2850- if simpleMatch (token . previous , '# else' ) :
2877+ if strtokens (token , - 1 , 0 ) == '# else' :
28512878 continue
2852- if simpleMatch (token , 'else if' ) :
2879+ if strtokens (token ,0 , 1 ) == 'else if' :
28532880 continue
28542881 if state == 2 :
28552882 self .reportError (tok1 , 15 , 6 )
0 commit comments