[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 06/11] qapidoc: introduce QAPISchemaIfCond.docgen()
From: |
marcandre . lureau |
Subject: |
[PATCH v6 06/11] qapidoc: introduce QAPISchemaIfCond.docgen() |
Date: |
Fri, 18 Jun 2021 14:25:02 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Instead of building the condition documentation from a list of string,
use the result generated from QAPISchemaIfCond.docgen().
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
docs/sphinx/qapidoc.py | 14 ++++++++------
scripts/qapi/common.py | 6 ++++++
scripts/qapi/schema.py | 10 +++++++++-
3 files changed, 23 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 @@ def _make_section(self, title):
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..5181a0f167 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -205,6 +205,12 @@ def cgen_ifcond(ifcond: Union[str, List[str]]) -> str:
return '(' + ') && ('.join(ifcond) + ')'
+def docgen_ifcond(ifcond: Union[str, List[str]]) -> str:
+ 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 70120f0dcc..30d6a01ad1 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -19,7 +19,12 @@
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 @@ def __init__(self, ifcond=None):
def cgen(self):
return cgen_ifcond(self.ifcond)
+ def docgen(self):
+ return docgen_ifcond(self.ifcond)
+
def is_present(self):
return bool(self.ifcond)
--
2.29.0
- [PATCH v6 00/11] qapi: untie 'if' conditions from C preprocessor, marcandre . lureau, 2021/06/18
- [PATCH v6 01/11] docs: update the documentation upfront about schema configuration, marcandre . lureau, 2021/06/18
- [PATCH v6 02/11] qapi: wrap Sequence[str] in an object, marcandre . lureau, 2021/06/18
- [PATCH v6 03/11] qapi: add QAPISchemaIfCond.is_present(), marcandre . lureau, 2021/06/18
- [PATCH v6 04/11] qapi: _make_enum_members() to work with pre-built QAPISchemaIfCond, marcandre . lureau, 2021/06/18
- [PATCH v6 05/11] qapi: introduce QAPISchemaIfCond.cgen(), marcandre . lureau, 2021/06/18
- [PATCH v6 06/11] qapidoc: introduce QAPISchemaIfCond.docgen(),
marcandre . lureau <=
- [PATCH v6 07/11] qapi: replace if condition list with dict {'all': [...]}, marcandre . lureau, 2021/06/18
- [PATCH v6 08/11] qapi: add 'any' condition, marcandre . lureau, 2021/06/18
- [PATCH v6 09/11] qapi: convert 'if' C-expressions to the new syntax tree, marcandre . lureau, 2021/06/18
- [PATCH v6 10/11] qapi: add 'not' condition operation, marcandre . lureau, 2021/06/18
- [PATCH v6 11/11] qapi: make 'if' condition strings simple identifiers, marcandre . lureau, 2021/06/18