qapi: Rename visitor parameter @variants to @branches

The previous commit narrowed the type of .visit_object_type()
parameter @variants from QAPISchemaVariants to QAPISchemaBranches.
Rename it to @branches.

Same for .visit_object_type_flat().

A few of these pass @branches to helper functions:
QAPISchemaGenRSTVisitor.visit_object_type() to ._nodes_for_members()
and ._nodes_for_variant_when(), and
QAPISchemaGenVisitVisitor.visit_object_type() to
gen_visit_object_members().  Rename the helpers' @variants parameters
to @branches as well.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2024-03-15 16:28:22 +01:00
parent 1d067e3953
commit d1da8af897
6 changed files with 25 additions and 25 deletions

View File

@ -145,22 +145,22 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
term.extend(self._nodes_for_ifcond(member.ifcond)) term.extend(self._nodes_for_ifcond(member.ifcond))
return term return term
def _nodes_for_variant_when(self, variants, variant): def _nodes_for_variant_when(self, branches, variant):
"""Return list of Text, literal nodes for variant 'when' clause """Return list of Text, literal nodes for variant 'when' clause
Return a list of doctree nodes which give text like Return a list of doctree nodes which give text like
'when tagname is variant (If: ...)' suitable for use in 'when tagname is variant (If: ...)' suitable for use in
the 'variants' part of a definition list. the 'branches' part of a definition list.
""" """
term = [nodes.Text(' when '), term = [nodes.Text(' when '),
nodes.literal('', variants.tag_member.name), nodes.literal('', branches.tag_member.name),
nodes.Text(' is '), nodes.Text(' is '),
nodes.literal('', '"%s"' % variant.name)] nodes.literal('', '"%s"' % variant.name)]
if variant.ifcond.is_present(): if variant.ifcond.is_present():
term.extend(self._nodes_for_ifcond(variant.ifcond)) term.extend(self._nodes_for_ifcond(variant.ifcond))
return term return term
def _nodes_for_members(self, doc, what, base=None, variants=None): def _nodes_for_members(self, doc, what, base=None, branches=None):
"""Return list of doctree nodes for the table of members""" """Return list of doctree nodes for the table of members"""
dlnode = nodes.definition_list() dlnode = nodes.definition_list()
for section in doc.args.values(): for section in doc.args.values():
@ -178,14 +178,14 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
nodes.literal('', base.doc_type())], nodes.literal('', base.doc_type())],
None) None)
if variants: if branches:
for v in variants.variants: for v in branches.variants:
if v.type.name == 'q_empty': if v.type.name == 'q_empty':
continue continue
assert not v.type.is_implicit() assert not v.type.is_implicit()
term = [nodes.Text('The members of '), term = [nodes.Text('The members of '),
nodes.literal('', v.type.doc_type())] nodes.literal('', v.type.doc_type())]
term.extend(self._nodes_for_variant_when(variants, v)) term.extend(self._nodes_for_variant_when(branches, v))
dlnode += self._make_dlitem(term, None) dlnode += self._make_dlitem(term, None)
if not dlnode.children: if not dlnode.children:
@ -308,12 +308,12 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
+ self._nodes_for_if_section(ifcond)) + self._nodes_for_if_section(ifcond))
def visit_object_type(self, name, info, ifcond, features, def visit_object_type(self, name, info, ifcond, features,
base, members, variants): base, members, branches):
doc = self._cur_doc doc = self._cur_doc
if base and base.is_implicit(): if base and base.is_implicit():
base = None base = None
self._add_doc('Object', self._add_doc('Object',
self._nodes_for_members(doc, 'Members', base, variants) self._nodes_for_members(doc, 'Members', base, branches)
+ self._nodes_for_features(doc) + self._nodes_for_features(doc)
+ self._nodes_for_sections(doc) + self._nodes_for_sections(doc)
+ self._nodes_for_if_section(ifcond)) + self._nodes_for_if_section(ifcond))

View File

@ -336,13 +336,13 @@ const QLitObject %(c_name)s = %(c_string)s;
ifcond: QAPISchemaIfCond, ifcond: QAPISchemaIfCond,
features: List[QAPISchemaFeature], features: List[QAPISchemaFeature],
members: List[QAPISchemaObjectTypeMember], members: List[QAPISchemaObjectTypeMember],
variants: Optional[QAPISchemaBranches]) -> None: branches: Optional[QAPISchemaBranches]) -> None:
obj: SchemaInfoObject = { obj: SchemaInfoObject = {
'members': [self._gen_object_member(m) for m in members] 'members': [self._gen_object_member(m) for m in members]
} }
if variants: if branches:
obj['tag'] = variants.tag_member.name obj['tag'] = branches.tag_member.name
obj['variants'] = [self._gen_variant(v) for v in variants.variants] obj['variants'] = [self._gen_variant(v) for v in branches.variants]
self._gen_tree(name, 'object', obj, ifcond, features) self._gen_tree(name, 'object', obj, ifcond, features)
def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo], def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo],

View File

@ -215,7 +215,7 @@ class QAPISchemaVisitor:
features: List[QAPISchemaFeature], features: List[QAPISchemaFeature],
base: Optional[QAPISchemaObjectType], base: Optional[QAPISchemaObjectType],
members: List[QAPISchemaObjectTypeMember], members: List[QAPISchemaObjectTypeMember],
variants: Optional[QAPISchemaBranches], branches: Optional[QAPISchemaBranches],
) -> None: ) -> None:
pass pass
@ -226,7 +226,7 @@ class QAPISchemaVisitor:
ifcond: QAPISchemaIfCond, ifcond: QAPISchemaIfCond,
features: List[QAPISchemaFeature], features: List[QAPISchemaFeature],
members: List[QAPISchemaObjectTypeMember], members: List[QAPISchemaObjectTypeMember],
variants: Optional[QAPISchemaBranches], branches: Optional[QAPISchemaBranches],
) -> None: ) -> None:
pass pass

View File

@ -350,13 +350,13 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor):
features: List[QAPISchemaFeature], features: List[QAPISchemaFeature],
base: Optional[QAPISchemaObjectType], base: Optional[QAPISchemaObjectType],
members: List[QAPISchemaObjectTypeMember], members: List[QAPISchemaObjectTypeMember],
variants: Optional[QAPISchemaBranches]) -> None: branches: Optional[QAPISchemaBranches]) -> None:
# Nothing to do for the special empty builtin # Nothing to do for the special empty builtin
if name == 'q_empty': if name == 'q_empty':
return return
with ifcontext(ifcond, self._genh): with ifcontext(ifcond, self._genh):
self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.preamble_add(gen_fwd_object_or_array(name))
self._genh.add(gen_object(name, ifcond, base, members, variants)) self._genh.add(gen_object(name, ifcond, base, members, branches))
with ifcontext(ifcond, self._genh, self._genc): with ifcontext(ifcond, self._genh, self._genc):
if base and not base.is_implicit(): if base and not base.is_implicit():
self._genh.add(gen_upcast(name, base)) self._genh.add(gen_upcast(name, base))

View File

@ -64,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, def gen_visit_object_members(name: str,
base: Optional[QAPISchemaObjectType], base: Optional[QAPISchemaObjectType],
members: List[QAPISchemaObjectTypeMember], members: List[QAPISchemaObjectTypeMember],
variants: Optional[QAPISchemaBranches]) -> str: branches: Optional[QAPISchemaBranches]) -> str:
ret = mcgen(''' ret = mcgen('''
bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
@ -132,8 +132,8 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
''') ''')
ret += memb.ifcond.gen_endif() ret += memb.ifcond.gen_endif()
if variants: if branches:
tag_member = variants.tag_member tag_member = branches.tag_member
assert isinstance(tag_member.type, QAPISchemaEnumType) assert isinstance(tag_member.type, QAPISchemaEnumType)
ret += mcgen(''' ret += mcgen('''
@ -141,7 +141,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
''', ''',
c_name=c_name(tag_member.name)) c_name=c_name(tag_member.name))
for var in variants.variants: for var in branches.variants:
case_str = c_enum_const(tag_member.type.name, var.name, case_str = c_enum_const(tag_member.type.name, var.name,
tag_member.type.prefix) tag_member.type.prefix)
ret += var.ifcond.gen_if() ret += var.ifcond.gen_if()
@ -394,14 +394,14 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
features: List[QAPISchemaFeature], features: List[QAPISchemaFeature],
base: Optional[QAPISchemaObjectType], base: Optional[QAPISchemaObjectType],
members: List[QAPISchemaObjectTypeMember], members: List[QAPISchemaObjectTypeMember],
variants: Optional[QAPISchemaBranches]) -> None: branches: Optional[QAPISchemaBranches]) -> None:
# Nothing to do for the special empty builtin # Nothing to do for the special empty builtin
if name == 'q_empty': if name == 'q_empty':
return return
with ifcontext(ifcond, self._genh, self._genc): with ifcontext(ifcond, self._genh, self._genc):
self._genh.add(gen_visit_members_decl(name)) self._genh.add(gen_visit_members_decl(name))
self._genc.add(gen_visit_object_members(name, base, self._genc.add(gen_visit_object_members(name, base,
members, variants)) members, branches))
# TODO Worth changing the visitor signature, so we could # TODO Worth changing the visitor signature, so we could
# directly use rather than repeat type.is_implicit()? # directly use rather than repeat type.is_implicit()?
if not name.startswith('q_'): if not name.startswith('q_'):

View File

@ -48,7 +48,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
self._print_if(ifcond) self._print_if(ifcond)
def visit_object_type(self, name, info, ifcond, features, def visit_object_type(self, name, info, ifcond, features,
base, members, variants): base, members, branches):
print('object %s' % name) print('object %s' % name)
if base: if base:
print(' base %s' % base.name) print(' base %s' % base.name)
@ -57,7 +57,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
% (m.name, m.type.name, m.optional)) % (m.name, m.type.name, m.optional))
self._print_if(m.ifcond, 8) self._print_if(m.ifcond, 8)
self._print_features(m.features, indent=8) self._print_features(m.features, indent=8)
self._print_variants(variants) self._print_variants(branches)
self._print_if(ifcond) self._print_if(ifcond)
self._print_features(features) self._print_features(features)