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 the method that 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 <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2021-07-16 21:15:11 +08:00 committed by Xie, Nanlin
parent 0395a8adf9
commit 6e79479a0a

View File

@ -293,6 +293,14 @@ class SequenceFactory(Factory):
factory.parse(context, child) factory.parse(context, child)
tree.append_child(child) tree.append_child(child)
else: 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] factory = globals()[elem]
child = Tree() child = Tree()
factory.parse(context, child) factory.parse(context, child)