mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-31 14:23:53 -06:00
qapi: New QAPISchemaBranches, QAPISchemaAlternatives
QAPISchemaVariants represents either a union type's branches, or an alternate type's alternatives. Much of its code is conditional on which one it actually is. Create QAPISchemaBranches for branches, and QAPISchemaAlternatives for alternatives, both subtypes of QAPISchemaVariants. Replace QAPISchemaVariants by one of them where possible. Keep it only where we actually deal with either of them. QAPISchemaVariants.__init__() takes @tag_name and @tag_member, where exactly one must be None: @tag_name for alternatives, @tag_member for branches. Let QAPISchemaBranches.__init__() take just @tag_name, and QAPISchemaAlternatives.__init__() take just @tag_member. A later patch will move the conditional code to the subtypes. Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
248f6f62df
commit
1d067e3953
4 changed files with 38 additions and 18 deletions
|
@ -28,6 +28,8 @@ from .gen import (
|
|||
)
|
||||
from .schema import (
|
||||
QAPISchema,
|
||||
QAPISchemaAlternatives,
|
||||
QAPISchemaBranches,
|
||||
QAPISchemaEnumMember,
|
||||
QAPISchemaEnumType,
|
||||
QAPISchemaFeature,
|
||||
|
@ -35,7 +37,6 @@ from .schema import (
|
|||
QAPISchemaObjectType,
|
||||
QAPISchemaObjectTypeMember,
|
||||
QAPISchemaType,
|
||||
QAPISchemaVariants,
|
||||
)
|
||||
from .source import QAPISourceInfo
|
||||
|
||||
|
@ -63,7 +64,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp);
|
|||
def gen_visit_object_members(name: str,
|
||||
base: Optional[QAPISchemaObjectType],
|
||||
members: List[QAPISchemaObjectTypeMember],
|
||||
variants: Optional[QAPISchemaVariants]) -> str:
|
||||
variants: Optional[QAPISchemaBranches]) -> str:
|
||||
ret = mcgen('''
|
||||
|
||||
bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
|
||||
|
@ -222,7 +223,7 @@ bool visit_type_%(c_name)s(Visitor *v, const char *name,
|
|||
c_name=c_name(name))
|
||||
|
||||
|
||||
def gen_visit_alternate(name: str, variants: QAPISchemaVariants) -> str:
|
||||
def gen_visit_alternate(name: str, variants: QAPISchemaAlternatives) -> str:
|
||||
ret = mcgen('''
|
||||
|
||||
bool visit_type_%(c_name)s(Visitor *v, const char *name,
|
||||
|
@ -393,7 +394,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
|
|||
features: List[QAPISchemaFeature],
|
||||
base: Optional[QAPISchemaObjectType],
|
||||
members: List[QAPISchemaObjectTypeMember],
|
||||
variants: Optional[QAPISchemaVariants]) -> None:
|
||||
variants: Optional[QAPISchemaBranches]) -> None:
|
||||
# Nothing to do for the special empty builtin
|
||||
if name == 'q_empty':
|
||||
return
|
||||
|
@ -413,7 +414,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
|
|||
info: Optional[QAPISourceInfo],
|
||||
ifcond: QAPISchemaIfCond,
|
||||
features: List[QAPISchemaFeature],
|
||||
variants: QAPISchemaVariants) -> None:
|
||||
variants: QAPISchemaAlternatives) -> None:
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.add(gen_visit_decl(name))
|
||||
self._genc.add(gen_visit_alternate(name, variants))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue