cppcheckdata: Add Scope.varlist

This commit is contained in:
Daniel Marjamäki 2020-11-13 21:03:02 +01:00
parent b7f812739c
commit 9a81d17a58
1 changed files with 18 additions and 14 deletions

View File

@ -361,6 +361,8 @@ class Scope:
nestedIn = None
type = None
isExecutable = None
varlistId = None
varlist = None
def __init__(self, element):
self.Id = element.get('id')
@ -376,6 +378,8 @@ class Scope:
self.type = element.get('type')
self.isExecutable = (self.type in ('Function', 'If', 'Else', 'For', 'While', 'Do',
'Switch', 'Try', 'Catch', 'Unconditional', 'Lambda'))
self.varlistId = list()
self.varlist = list()
def __repr__(self):
attrs = ["Id", "className", "functionId", "bodyStartId", "bodyEndId",
@ -390,6 +394,8 @@ class Scope:
self.bodyEnd = IdMap[self.bodyEndId]
self.nestedIn = IdMap[self.nestedInId]
self.function = IdMap[self.functionId]
for v in self.varlistId:
self.varlist.append(IdMap[v])
class Function:
@ -909,13 +915,8 @@ class CppcheckData:
cfg_function = None
cfg_valueflow = None
# Scopes contains <varlist> with all occurred variables. Some of them
# appearaed in <variables> node for this configuration.
# Others are arguments of functions.
# They have similar tag <var> but doesn't contain any attributes. So we
# set set a special state when iterate <varlist> node to prevent
# overriding of cfg.variables list with empty values.
iter_varlist = False
# Iterating <varlist> in a <scope>.
iter_scope_varlist = False
# Use iterable objects to traverse XML tree for dump files incrementally.
# Iterative approach is required to avoid large memory consumption.
@ -959,9 +960,9 @@ class CppcheckData:
cfg.scopes.append(Scope(node))
elif node.tag == 'varlist':
if event == 'start':
iter_varlist = True
iter_scope_varlist = True
elif event == 'end':
iter_varlist = False
iter_scope_varlist = False
# Parse functions
elif node.tag == 'functionList' and event == 'start':
@ -982,11 +983,14 @@ class CppcheckData:
# Parse variables
elif node.tag == 'var' and event == 'start':
var = Variable(node)
if var.nameTokenId:
cfg.variables.append(var)
elif not iter_varlist:
cfg_arguments.append(var)
if iter_scope_varlist:
cfg.scopes[-1].varlistId.append(node.get('id'))
else:
var = Variable(node)
if var.nameTokenId:
cfg.variables.append(var)
else:
cfg_arguments.append(var)
# Parse valueflows (list of values)
elif node.tag == 'valueflow' and event == 'start':