diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index b516ef51f9d..38f9a0f3169 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -1281,6 +1281,8 @@ def iterconfigurations(self): # Iterating iter_typedef_info = False + iter_directive = False + # Use iterable objects to traverse XML tree for dump files incrementally. # Iterative approach is required to avoid large memory consumption. # Calling .clear() is necessary to let the element be garbage collected. @@ -1312,8 +1314,12 @@ def iterconfigurations(self): cfg.standards.set_posix(node) # Parse directives list - elif node.tag == 'directive' and event == 'start': - cfg.directives.append(Directive(node)) + elif node.tag == 'directive': + if event == 'start': + cfg.directives.append(Directive(node)) + iter_directive = True + elif event == 'end': + iter_directive = False # Parse macro usage elif node.tag == 'macro' and event == 'start': cfg.macro_usage.append(MacroUsage(node)) @@ -1325,7 +1331,7 @@ def iterconfigurations(self): # Parse tokens elif node.tag == 'tokenlist' and event == 'start': continue - elif node.tag == 'token' and event == 'start': + elif node.tag == 'token' and event == 'start' and not iter_directive: cfg.tokenlist.append(Token(node)) # Parse scopes