mirror of
https://github.com/qemu/qemu.git
synced 2024-11-23 19:03:38 +08:00
qapi-schema: support alternates with array type
Detect array types as alternate branches, and turn the JSON list into a QAPISchemaArrayType. Array types in an alternate are represented with QTYPE_QLIST in the type field. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20220321164243.200569-2-pbonzini@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
9c125d17e9
commit
a58069494d
@ -554,7 +554,7 @@ def check_alternate(expr: _JSONObject, info: QAPISourceInfo) -> None:
|
|||||||
check_name_lower(key, info, source)
|
check_name_lower(key, info, source)
|
||||||
check_keys(value, info, source, ['type'], ['if'])
|
check_keys(value, info, source, ['type'], ['if'])
|
||||||
check_if(value, info, source)
|
check_if(value, info, source)
|
||||||
check_type(value['type'], info, source)
|
check_type(value['type'], info, source, allow_array=True)
|
||||||
|
|
||||||
|
|
||||||
def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None:
|
def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None:
|
||||||
|
@ -243,6 +243,7 @@ class QAPISchemaType(QAPISchemaEntity):
|
|||||||
'number': 'QTYPE_QNUM',
|
'number': 'QTYPE_QNUM',
|
||||||
'int': 'QTYPE_QNUM',
|
'int': 'QTYPE_QNUM',
|
||||||
'boolean': 'QTYPE_QBOOL',
|
'boolean': 'QTYPE_QBOOL',
|
||||||
|
'array': 'QTYPE_QLIST',
|
||||||
'object': 'QTYPE_QDICT'
|
'object': 'QTYPE_QDICT'
|
||||||
}
|
}
|
||||||
return json2qtype.get(self.json_type())
|
return json2qtype.get(self.json_type())
|
||||||
@ -1069,6 +1070,9 @@ class QAPISchema:
|
|||||||
None))
|
None))
|
||||||
|
|
||||||
def _make_variant(self, case, typ, ifcond, info):
|
def _make_variant(self, case, typ, ifcond, info):
|
||||||
|
if isinstance(typ, list):
|
||||||
|
assert len(typ) == 1
|
||||||
|
typ = self._make_array_type(typ[0], info)
|
||||||
return QAPISchemaVariant(case, info, typ, ifcond)
|
return QAPISchemaVariant(case, info, typ, ifcond)
|
||||||
|
|
||||||
def _def_union_type(self, expr, info, doc):
|
def _def_union_type(self, expr, info, doc):
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
alternate-array.json: In alternate 'Alt':
|
|
||||||
alternate-array.json:5: 'data' member 'two' cannot be an array
|
|
@ -1,5 +1,3 @@
|
|||||||
# we do not allow array branches in alternates
|
|
||||||
# TODO: should we support this?
|
|
||||||
{ 'struct': 'One',
|
{ 'struct': 'One',
|
||||||
'data': { 'name': 'str' } }
|
'data': { 'name': 'str' } }
|
||||||
{ 'alternate': 'Alt',
|
{ 'alternate': 'Alt',
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
module ./builtin
|
||||||
|
object q_empty
|
||||||
|
enum QType
|
||||||
|
prefix QTYPE
|
||||||
|
member none
|
||||||
|
member qnull
|
||||||
|
member qnum
|
||||||
|
member qstring
|
||||||
|
member qdict
|
||||||
|
member qlist
|
||||||
|
member qbool
|
||||||
|
module alternate-array.json
|
||||||
|
object One
|
||||||
|
member name: str optional=False
|
||||||
|
alternate Alt
|
||||||
|
tag type
|
||||||
|
case one: One
|
||||||
|
case two: intList
|
Loading…
Reference in New Issue
Block a user