summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/sphinx/qapidoc.py14
-rw-r--r--scripts/qapi/common.py7
-rw-r--r--scripts/qapi/schema.py10
3 files changed, 24 insertions, 7 deletions
diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py
index 511520f33f..d791b59492 100644
--- a/docs/sphinx/qapidoc.py
+++ b/docs/sphinx/qapidoc.py
@@ -112,17 +112,19 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
def _nodes_for_ifcond(self, ifcond, with_if=True):
"""Return list of Text, literal nodes for the ifcond
- Return a list which gives text like ' (If: cond1, cond2, cond3)', where
- the conditions are in literal-text and the commas are not.
+ Return a list which gives text like ' (If: condition)'.
If with_if is False, we don't return the "(If: " and ")".
"""
- condlist = intersperse([nodes.literal('', c) for c in ifcond.ifcond],
- nodes.Text(', '))
+
+ doc = ifcond.docgen()
+ if not doc:
+ return []
+ doc = nodes.literal('', doc)
if not with_if:
- return condlist
+ return [doc]
nodelist = [nodes.Text(' ('), nodes.strong('', 'If: ')]
- nodelist.extend(condlist)
+ nodelist.append(doc)
nodelist.append(nodes.Text(')'))
return nodelist
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index ba9fe14e4b..ddc54e4368 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -205,6 +205,13 @@ def cgen_ifcond(ifcond: Union[str, List[str]]) -> str:
return '(' + ') && ('.join(ifcond) + ')'
+def docgen_ifcond(ifcond: Union[str, List[str]]) -> str:
+ # TODO Doc generated for conditions needs polish
+ if not ifcond:
+ return ''
+ return ' and '.join(ifcond)
+
+
def gen_if(cond: str) -> str:
if not cond:
return ''
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 4ea7e88846..a9345af7b7 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -19,7 +19,12 @@ import os
import re
from typing import Optional
-from .common import POINTER_SUFFIX, c_name, cgen_ifcond
+from .common import (
+ POINTER_SUFFIX,
+ c_name,
+ cgen_ifcond,
+ docgen_ifcond,
+)
from .error import QAPIError, QAPISemError, QAPISourceError
from .expr import check_exprs
from .parser import QAPISchemaParser
@@ -32,6 +37,9 @@ class QAPISchemaIfCond:
def cgen(self):
return cgen_ifcond(self.ifcond)
+ def docgen(self):
+ return docgen_ifcond(self.ifcond)
+
def is_present(self):
return bool(self.ifcond)