From 9a81d17a58924ebfcdbba5e56538beaba7cb8c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 13 Nov 2020 21:03:02 +0100 Subject: [PATCH] cppcheckdata: Add Scope.varlist --- addons/cppcheckdata.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index bb836dcd1..a27e5c394 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -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 with all occurred variables. Some of them - # appearaed in node for this configuration. - # Others are arguments of functions. - # They have similar tag but doesn't contain any attributes. So we - # set set a special state when iterate node to prevent - # overriding of cfg.variables list with empty values. - iter_varlist = False + # Iterating in a . + 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':