From d58ef5e2aa775910a8f82b0e7f598053f1968d7c Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Thu, 29 Jul 2021 16:00:52 +0800 Subject: [PATCH] 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 --- .../board_inspector/acpiparser/aml/tree.py | 17 ++++++++++------- .../board_inspector/acpiparser/aml/visitors.py | 11 ++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/misc/config_tools/board_inspector/acpiparser/aml/tree.py b/misc/config_tools/board_inspector/acpiparser/aml/tree.py index 8aa049f2c..252d20f33 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/tree.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/tree.py @@ -63,15 +63,18 @@ class Visitor: if not fn: fn = getattr(self, "default", None) if fn: - fn(tree) + return fn(tree) + else: + return True def _visit_topdown(self, tree): - self.__visit_node(tree) - self.depth += 1 - for child in tree.children: - if isinstance(child, Tree): - self.visit(child) - self.depth -= 1 + go_on = self.__visit_node(tree) + if go_on != False: + self.depth += 1 + for child in tree.children: + if isinstance(child, Tree): + self.visit(child) + self.depth -= 1 def _visit_bottomup(self, tree): self.depth += 1 diff --git a/misc/config_tools/board_inspector/acpiparser/aml/visitors.py b/misc/config_tools/board_inspector/acpiparser/aml/visitors.py index 1e9808e25..0e2d9bb8e 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/visitors.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/visitors.py @@ -38,17 +38,18 @@ class ConditionallyUnregisterSymbolVisitor(Visitor): self.interpreter = interpreter self.conditionally_hidden = False - self.DefName = self.__unregister(0) - self.DefMethod = self.__unregister(1) - self.DefDevice = self.__unregister(1) + self.DefName = self.__unregister(0, False) + self.DefMethod = self.__unregister(1, False) + self.DefDevice = self.__unregister(1, True) - def __unregister(self, name_string_idx): + def __unregister(self, name_string_idx, go_on): def f(tree): if self.conditionally_hidden: scope = tree.scope name = tree.children[name_string_idx].value realpath = self.context.realpath(scope, name) self.context.unregister_object(realpath) + return go_on return f def visit(self, tree): @@ -73,7 +74,7 @@ class ConditionallyUnregisterSymbolVisitor(Visitor): if hasattr(tree, "DefElse") and tree.DefElse: self.visit(tree.DefElse) self.depth -= 1 - elif tree.label not in ["DefMethod"]: + else: self._visit_topdown(tree) class GenerateBinaryVisitor(Visitor):