qapi/parser: add QAPIExpression type
commit420110591c54f5fd38e065d5bddac73b3076bf9e
authorJohn Snow <jsnow@redhat.com>
Wed, 15 Feb 2023 00:00:09 +0000 (14 19:00 -0500)
committerMarkus Armbruster <armbru@redhat.com>
Thu, 23 Feb 2023 12:01:45 +0000 (23 13:01 +0100)
treee48291e9f8efd56878e9eb64c753854cdf90bb65
parentc60caf8086247afbfbf0673993d809d348238ef6
qapi/parser: add QAPIExpression type

This patch creates a new type, QAPIExpression, which represents a parsed
expression complete with QAPIDoc and QAPISourceInfo.

This patch turns parser.exprs into a list of QAPIExpression instead,
and adjusts expr.py to match.

This allows the types we specify in parser.py to be "remembered" all the
way through expr.py and into schema.py. Several assertions around
packing and unpacking this data can be removed as a result.

It also corrects a harmless typing error.  Before the patch,
check_exprs() allegedly takes a List[_JSONObject].  It actually takes
a list of dicts of the form

    {'expr': E, 'info': I, 'doc': D}

where E is of type _ExprValue, I is of type QAPISourceInfo, and D is
of type QAPIDoc.  Key 'doc' is optional.  This is not a _JSONObject!
Passes type checking anyway, because _JSONObject is Dict[str, object].

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20230215000011.1725012-5-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Commit message amended to point out the typing fix]
scripts/qapi/expr.py
scripts/qapi/parser.py
scripts/qapi/schema.py