Fix potential typo: use token.next.linenr instead of token.linenr (#2483)

Also make use of defaultdict to minimize risk of similar typos in the future and to clean up the code
This commit is contained in:
mlambacher 2020-01-09 19:31:18 +01:00 committed by Daniel Marjamäki
parent 34a26c7dd7
commit 3ada7672f3
1 changed files with 3 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import os
import argparse import argparse
import codecs import codecs
import string import string
from collections import defaultdict
try: try:
from itertools import izip as zip from itertools import izip as zip
@ -1381,7 +1382,7 @@ class MisraChecker:
# initialization lists and function calls, e.g.: # initialization lists and function calls, e.g.:
# struct S a = {1, 2, 3}, b, c = foo(1, 2), d; # struct S a = {1, 2, 3}, b, c = foo(1, 2), d;
# ^ ^ # ^ ^
end_tokens_map = {} end_tokens_map = defaultdict(set)
skip_to = None skip_to = None
for token in data.tokenlist: for token in data.tokenlist:
@ -1399,10 +1400,8 @@ class MisraChecker:
# Save end tokens from function calls in initialization # Save end tokens from function calls in initialization
if simpleMatch(token, ') ;'): if simpleMatch(token, ') ;'):
if (token.isExpandedMacro): if (token.isExpandedMacro):
end_tokens_map.setdefault(token.next.linenr, set()) end_tokens_map[token.next.linenr].add(token.next.column)
end_tokens_map[token.linenr].add(token.next.column)
else: else:
end_tokens_map.setdefault(token.linenr, set())
end_tokens_map[token.linenr].add(token.column) end_tokens_map[token.linenr].add(token.column)
if token.str != ',': if token.str != ',':
continue continue
@ -1410,7 +1409,6 @@ class MisraChecker:
if token.astParent.str in ('(', '{'): if token.astParent.str in ('(', '{'):
end_token = token.astParent.link end_token = token.astParent.link
if end_token: if end_token:
end_tokens_map.setdefault(end_token.linenr, set())
end_tokens_map[end_token.linenr].add(end_token.column) end_tokens_map[end_token.linenr].add(end_token.column)
continue continue
elif token.astParent.str == ',': elif token.astParent.str == ',':