dump: Read platform info from dump file

This commit is contained in:
Daniel Marjamäki 2017-04-15 19:15:48 +02:00
parent ef416d318e
commit dd8b96f4c8
2 changed files with 55 additions and 10 deletions

View File

@ -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

View File

@ -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 = []