From dd8b96f4c84651bd0613364d28bc4ee80fc9934d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 15 Apr 2017 19:15:48 +0200 Subject: [PATCH] dump: Read platform info from dump file --- addons/cppcheckdata.py | 37 +++++++++++++++++++++++++++++++++++++ addons/misra.py | 28 ++++++++++++++++++---------- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index b1b4d5a9b..0e81f1f31 100644 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -478,6 +478,38 @@ class Configuration: variable.setId(IdMap) +class Platform: + """ + Platform class + This class contains type sizes + + Attributes: + name Name of the platform + char_bit CHAR_BIT value + short_bit SHORT_BIT value + int_bit INT_BIT value + long_bit LONG_BIT value + long_long_bit LONG_LONG_BIT value + pointer_bit POINTER_BIT value + """ + + name = '' + char_bit = 0 + short_bit = 0 + int_bit = 0 + long_bit = 0 + long_long_bit = 0 + pointer_bit = 0 + + def __init__(self, platformnode): + self.name = platformnode.get('name') + self.char_bit = int(platformnode.get('char_bit')) + self.short_bit = int(platformnode.get('short_bit')) + self.int_bit = int(platformnode.get('int_bit')) + self.long_bit = int(platformnode.get('long_bit')) + self.long_long_bit = int(platformnode.get('long_long_bit')) + self.pointer_bit = int(platformnode.get('pointer_bit')) + class CppcheckData: """ @@ -516,6 +548,7 @@ class CppcheckData: """ rawTokens = [] + platform = None configurations = [] def __init__(self, filename): @@ -523,6 +556,10 @@ class CppcheckData: data = ET.parse(filename) + for platformNode in data.getroot(): + if platformNode.tag == 'platform': + self.platform = Platform(platformNode) + for rawTokensNode in data.getroot(): if rawTokensNode.tag != 'rawtokens': continue diff --git a/addons/misra.py b/addons/misra.py index eca6dbee4..29411779e 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -33,10 +33,12 @@ def simpleMatch(token, pattern): return True # Platform -# TODO get this from dump -CHAR_BITS = 8 -SHORT_BITS = 16 -INT_BITS = 32 +CHAR_BIT = 0 +SHORT_BIT = 0 +INT_BIT = 0 +LONG_BIT = 0 +LONG_LONG_BIT = 0 +POINTER_BIT = 0 KEYWORDS = ['auto', 'break', @@ -86,13 +88,12 @@ def bitsOfEssentialType(expr): type = getEssentialType(expr) if type is None: return 0 - # TODO get --platform type sizes if type == 'char': - return CHAR_BITS + return CHAR_BIT if type == 'short': - return SHORT_BITS + return SHORT_BIT if type == 'int': - return INT_BITS + return INT_BIT return 0 def isFunctionCall(expr): @@ -316,9 +317,9 @@ def misra_12_3(data): def misra_12_4(data): max_uint = 0 - if INT_BITS == 16: + if INT_BIT == 16: max_uint = 0xffff - elif INT_BITS == 32: + elif INT_BIT == 32: max_uint = 0xffffffff else: return @@ -686,6 +687,13 @@ for arg in sys.argv[1:]: data = cppcheckdata.parsedump(arg) + CHAR_BIT = data.platform.char_bit + SHORT_BIT = data.platform.short_bit + INT_BIT = data.platform.int_bit + LONG_BIT = data.platform.long_bit + LONG_LONG_BIT = data.platform.long_long_bit + POINTER_BIT = data.platform.pointer_bit + if VERIFY: VERIFY_ACTUAL = [] VERIFY_EXPECTED = []