From d32596661245767dd40b7fcd9059604c5c029129 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Fri, 16 Jul 2021 21:15:11 +0800 Subject: [PATCH] board_inspector: always defer parsing of method bodies The current ACPI AML parser can generate incorrect AST if a DSDT/SSDT satisfies the following: 1. The body of a method invokes a NameString that is defined later. 2. Before that method the same NameString is also defined but in an outer scope and with a different number of parameter. Since method bodies hardly define any further symbol that is referenced outside the method itself, this patch forces the parsing of method bodies to be deferred to the second pass when all symbols have been declared. Tracked-On: #6298 Signed-off-by: Junjie Mao --- .../config_tools/board_inspector/acpiparser/aml/parser.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/misc/config_tools/board_inspector/acpiparser/aml/parser.py b/misc/config_tools/board_inspector/acpiparser/aml/parser.py index b05034350..f993c71dc 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/parser.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/parser.py @@ -293,6 +293,14 @@ class SequenceFactory(Factory): factory.parse(context, child) tree.append_child(child) else: + # It is likely that a method body has forward definitions, while typically it does not define + # symbols that are referred later. Thus always defer the parsing of method bodies to the second + # phase. + # + # In second phase the labels of sequence factories always have the ".deferred" suffix. Thus it is + # safe to check self.label against "DefMethod" here. + if elem == "TermList" and self.label == "DefMethod": + raise DeferLater(self.label, [elem]) factory = globals()[elem] child = Tree() factory.parse(context, child)