aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi/introspect.py
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2021-08-04 12:30:57 +0400
committerMarkus Armbruster <armbru@redhat.com>2021-08-26 13:53:56 +0200
commitf17539c80da3c0ebabbe75a04f5451995367ec91 (patch)
tree38dbfd11f94fb0e4da26cd00b95228a6c9e521ea /scripts/qapi/introspect.py
parent3248c1aaf2dba296db98813303ccdda822708932 (diff)
downloadqemu-f17539c80da3c0ebabbe75a04f5451995367ec91.zip
qemu-f17539c80da3c0ebabbe75a04f5451995367ec91.tar.gz
qemu-f17539c80da3c0ebabbe75a04f5451995367ec91.tar.bz2
qapi: wrap Sequence[str] in an object
Mechanical change, except for a new assertion in QAPISchemaEntity.ifcond(). Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20210804083105.97531-3-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Rebased with obvious conflicts, commit message adjusted] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts/qapi/introspect.py')
-rw-r--r--scripts/qapi/introspect.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index 9a348ca..db1ebbf 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -15,11 +15,9 @@ from typing import (
Any,
Dict,
Generic,
- Iterable,
List,
Optional,
Sequence,
- Tuple,
TypeVar,
Union,
)
@@ -38,6 +36,7 @@ from .schema import (
QAPISchemaEntity,
QAPISchemaEnumMember,
QAPISchemaFeature,
+ QAPISchemaIfCond,
QAPISchemaObjectType,
QAPISchemaObjectTypeMember,
QAPISchemaType,
@@ -91,11 +90,11 @@ class Annotated(Generic[_ValueT]):
"""
# TODO: Remove after Python 3.7 adds @dataclass:
# pylint: disable=too-few-public-methods
- def __init__(self, value: _ValueT, ifcond: Iterable[str],
+ def __init__(self, value: _ValueT, ifcond: QAPISchemaIfCond,
comment: Optional[str] = None):
self.value = value
self.comment: Optional[str] = comment
- self.ifcond: Tuple[str, ...] = tuple(ifcond)
+ self.ifcond = ifcond
def _tree_to_qlit(obj: JSONValue,
@@ -124,11 +123,11 @@ def _tree_to_qlit(obj: JSONValue,
ret = ''
if obj.comment:
ret += indent(level) + f"/* {obj.comment} */\n"
- if obj.ifcond:
- ret += gen_if(obj.ifcond)
+ if obj.ifcond.ifcond:
+ ret += gen_if(obj.ifcond.ifcond)
ret += _tree_to_qlit(obj.value, level)
- if obj.ifcond:
- ret += '\n' + gen_endif(obj.ifcond)
+ if obj.ifcond.ifcond:
+ ret += '\n' + gen_endif(obj.ifcond.ifcond)
return ret
ret = ''
@@ -254,7 +253,7 @@ const QLitObject %(c_name)s = %(c_string)s;
return [Annotated(f.name, f.ifcond) for f in features]
def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object],
- ifcond: Sequence[str] = (),
+ ifcond: QAPISchemaIfCond = QAPISchemaIfCond(),
features: Sequence[QAPISchemaFeature] = ()) -> None:
"""
Build and append a SchemaInfo object to self._trees.
@@ -305,7 +304,7 @@ const QLitObject %(c_name)s = %(c_string)s;
self._gen_tree(name, 'builtin', {'json-type': json_type})
def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo],
- ifcond: Sequence[str],
+ ifcond: QAPISchemaIfCond,
features: List[QAPISchemaFeature],
members: List[QAPISchemaEnumMember],
prefix: Optional[str]) -> None:
@@ -316,14 +315,14 @@ const QLitObject %(c_name)s = %(c_string)s;
)
def visit_array_type(self, name: str, info: Optional[QAPISourceInfo],
- ifcond: Sequence[str],
+ ifcond: QAPISchemaIfCond,
element_type: QAPISchemaType) -> None:
element = self._use_type(element_type)
self._gen_tree('[' + element + ']', 'array', {'element-type': element},
ifcond)
def visit_object_type_flat(self, name: str, info: Optional[QAPISourceInfo],
- ifcond: Sequence[str],
+ ifcond: QAPISchemaIfCond,
features: List[QAPISchemaFeature],
members: List[QAPISchemaObjectTypeMember],
variants: Optional[QAPISchemaVariants]) -> None:
@@ -336,7 +335,7 @@ const QLitObject %(c_name)s = %(c_string)s;
self._gen_tree(name, 'object', obj, ifcond, features)
def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo],
- ifcond: Sequence[str],
+ ifcond: QAPISchemaIfCond,
features: List[QAPISchemaFeature],
variants: QAPISchemaVariants) -> None:
self._gen_tree(
@@ -348,7 +347,7 @@ const QLitObject %(c_name)s = %(c_string)s;
)
def visit_command(self, name: str, info: Optional[QAPISourceInfo],
- ifcond: Sequence[str],
+ ifcond: QAPISchemaIfCond,
features: List[QAPISchemaFeature],
arg_type: Optional[QAPISchemaObjectType],
ret_type: Optional[QAPISchemaType], gen: bool,
@@ -367,7 +366,8 @@ const QLitObject %(c_name)s = %(c_string)s;
self._gen_tree(name, 'command', obj, ifcond, features)
def visit_event(self, name: str, info: Optional[QAPISourceInfo],
- ifcond: Sequence[str], features: List[QAPISchemaFeature],
+ ifcond: QAPISchemaIfCond,
+ features: List[QAPISchemaFeature],
arg_type: Optional[QAPISchemaObjectType],
boxed: bool) -> None:
assert self._schema is not None