board_inspector: skip visiting DefMethod properly when unregistering symbols

The current implementation of the ConditionallyUnregisterSymbolVisitor
exits upon visiting a DefMethod node without unregistering that method. As
a result, methods in False branches in DSDT/SSDTs are not removed from the
parsed namespace, which can lead to further confusions when these methods
are referenced (e.g. a _CRS method visited by the board inspector).

This patch fixes this by always visiting a DefMethod node but stops
traversing its children.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2021-07-29 16:00:52 +08:00 committed by wenlingz
parent 5ad06e933a
commit d58ef5e2aa
2 changed files with 16 additions and 12 deletions

View File

@ -63,15 +63,18 @@ class Visitor:
if not fn: if not fn:
fn = getattr(self, "default", None) fn = getattr(self, "default", None)
if fn: if fn:
fn(tree) return fn(tree)
else:
return True
def _visit_topdown(self, tree): def _visit_topdown(self, tree):
self.__visit_node(tree) go_on = self.__visit_node(tree)
self.depth += 1 if go_on != False:
for child in tree.children: self.depth += 1
if isinstance(child, Tree): for child in tree.children:
self.visit(child) if isinstance(child, Tree):
self.depth -= 1 self.visit(child)
self.depth -= 1
def _visit_bottomup(self, tree): def _visit_bottomup(self, tree):
self.depth += 1 self.depth += 1

View File

@ -38,17 +38,18 @@ class ConditionallyUnregisterSymbolVisitor(Visitor):
self.interpreter = interpreter self.interpreter = interpreter
self.conditionally_hidden = False self.conditionally_hidden = False
self.DefName = self.__unregister(0) self.DefName = self.__unregister(0, False)
self.DefMethod = self.__unregister(1) self.DefMethod = self.__unregister(1, False)
self.DefDevice = self.__unregister(1) self.DefDevice = self.__unregister(1, True)
def __unregister(self, name_string_idx): def __unregister(self, name_string_idx, go_on):
def f(tree): def f(tree):
if self.conditionally_hidden: if self.conditionally_hidden:
scope = tree.scope scope = tree.scope
name = tree.children[name_string_idx].value name = tree.children[name_string_idx].value
realpath = self.context.realpath(scope, name) realpath = self.context.realpath(scope, name)
self.context.unregister_object(realpath) self.context.unregister_object(realpath)
return go_on
return f return f
def visit(self, tree): def visit(self, tree):
@ -73,7 +74,7 @@ class ConditionallyUnregisterSymbolVisitor(Visitor):
if hasattr(tree, "DefElse") and tree.DefElse: if hasattr(tree, "DefElse") and tree.DefElse:
self.visit(tree.DefElse) self.visit(tree.DefElse)
self.depth -= 1 self.depth -= 1
elif tree.label not in ["DefMethod"]: else:
self._visit_topdown(tree) self._visit_topdown(tree)
class GenerateBinaryVisitor(Visitor): class GenerateBinaryVisitor(Visitor):