term.append(nodes.literal('', member.type.doc_type()))
if member.optional:
term.append(nodes.Text(' (optional)'))
- if member.ifcond.ifcond:
+ if member.ifcond.is_present():
term.extend(self._nodes_for_ifcond(member.ifcond))
return term
nodes.literal('', variants.tag_member.name),
nodes.Text(' is '),
nodes.literal('', '"%s"' % variant.name)]
- if variant.ifcond.ifcond:
+ if variant.ifcond.is_present():
term.extend(self._nodes_for_ifcond(variant.ifcond))
return term
dlnode = nodes.definition_list()
for section in doc.args.values():
termtext = [nodes.literal('', section.member.name)]
- if section.member.ifcond.ifcond:
+ if section.member.ifcond.is_present():
termtext.extend(self._nodes_for_ifcond(section.member.ifcond))
# TODO drop fallbacks when undocumented members are outlawed
if section.text:
def _nodes_for_if_section(self, ifcond):
"""Return list of doctree nodes for the "If" section"""
nodelist = []
- if ifcond.ifcond:
+ if ifcond.is_present():
snode = self._make_section('If')
snode += nodes.paragraph(
'', '', *self._nodes_for_ifcond(ifcond, with_if=False)
ret = ''
if obj.comment:
ret += indent(level) + f"/* {obj.comment} */\n"
- if obj.ifcond.ifcond:
+ if obj.ifcond.is_present():
ret += gen_if(obj.ifcond.ifcond)
ret += _tree_to_qlit(obj.value, level)
- if obj.ifcond.ifcond:
+ if obj.ifcond.is_present():
ret += '\n' + gen_endif(obj.ifcond.ifcond)
return ret
def __init__(self, ifcond=None):
self.ifcond = ifcond or []
+ def is_present(self):
+ return bool(self.ifcond)
+
class QAPISchemaEntity:
meta: Optional[str] = None
self.info,
"discriminator member '%s' of %s must not be optional"
% (self._tag_name, base))
- if self.tag_member.ifcond.ifcond:
+ if self.tag_member.ifcond.is_present():
raise QAPISemError(
self.info,
"discriminator member '%s' of %s must not be conditional"
else: # simple union
assert isinstance(self.tag_member.type, QAPISchemaEnumType)
assert not self.tag_member.optional
- assert self.tag_member.ifcond.ifcond == []
+ assert not self.tag_member.ifcond.is_present()
if self._tag_name: # flat union
# branches that are not explicitly covered get an empty type
cases = {v.name for v in self.variants}