board_inspector: try mroe type convertions when evaluating branch conditions

In commit e5ba06cbe8 ("board_inspector: a workaround to an incorrect
interpretation") a workaround is introduced to check the data type of
predicate operands. That commit assumes that both operands must be exactly
integers, which is not usually the case as operation fields or strings can
also be used in predicates.

This patch applies the following conversions on both operands when
evaluating a predicate:

  1. Try converting both operands to integers

  2. If either conversion in step 1 fails, try regarding both operands as
     strings.

  3. If either operand is not a string, return the default
     result (i.e. False).

Fixes: e5ba06cbe8 ("board_inspector: a workaround to an incorrect interpretation")
Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2021-08-09 10:22:25 +08:00 committed by wenlingz
parent 25cabe14db
commit 4cb0d95fc0
1 changed files with 7 additions and 4 deletions

View File

@ -398,10 +398,13 @@ class ConcreteInterpreter(Interpreter):
#
# As a workaround, check if both the left and right hand sides are integers first. If either is not the case,
# the condition is evaluated to False.
if isinstance(lhs, Integer) and isinstance(rhs, Integer):
res = Integer(op(lhs.get(), rhs.get()))
else:
res = Integer(0)
try:
res = Integer(op(lhs.to_integer().get(), rhs.to_integer().get()))
except NotImplementedError:
if isinstance(lhs, String) and isinstance(rhs, String):
res = Integer(op(lhs.get(), rhs.get()))
else:
res = Integer(0)
if len(tree.children) >= 3:
target = self.interpret(tree.children[2])
if target: