mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-31 14:23:53 -06:00
docs/qapidoc: add format_type() method
This method is responsible for generating a type name for a given member with the correct annotations for the QAPI domain. Features and enums do not *have* types, so they return None. Everything else returns the type name with a "?" suffix if that type is optional, and ensconced in [brackets] if it's an array type. Signed-off-by: John Snow <jsnow@redhat.com> Message-ID: <20250311034303.75779-47-jsnow@redhat.com> Acked-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
e9fbf1a0c6
commit
3a396a865b
1 changed files with 32 additions and 0 deletions
|
@ -40,7 +40,13 @@ from qapi.error import QAPIError
|
||||||
from qapi.parser import QAPIDoc
|
from qapi.parser import QAPIDoc
|
||||||
from qapi.schema import (
|
from qapi.schema import (
|
||||||
QAPISchema,
|
QAPISchema,
|
||||||
|
QAPISchemaArrayType,
|
||||||
QAPISchemaDefinition,
|
QAPISchemaDefinition,
|
||||||
|
QAPISchemaEnumMember,
|
||||||
|
QAPISchemaFeature,
|
||||||
|
QAPISchemaMember,
|
||||||
|
QAPISchemaObjectTypeMember,
|
||||||
|
QAPISchemaType,
|
||||||
QAPISchemaVisitor,
|
QAPISchemaVisitor,
|
||||||
)
|
)
|
||||||
from qapi.source import QAPISourceInfo
|
from qapi.source import QAPISourceInfo
|
||||||
|
@ -58,7 +64,9 @@ if TYPE_CHECKING:
|
||||||
Any,
|
Any,
|
||||||
Generator,
|
Generator,
|
||||||
List,
|
List,
|
||||||
|
Optional,
|
||||||
Sequence,
|
Sequence,
|
||||||
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
|
@ -128,6 +136,30 @@ class Transmogrifier:
|
||||||
# +2: correct for zero/one index, then increment by one.
|
# +2: correct for zero/one index, then increment by one.
|
||||||
self.add_line_raw("", fname, line + 2)
|
self.add_line_raw("", fname, line + 2)
|
||||||
|
|
||||||
|
def format_type(
|
||||||
|
self, ent: Union[QAPISchemaDefinition | QAPISchemaMember]
|
||||||
|
) -> Optional[str]:
|
||||||
|
if isinstance(ent, (QAPISchemaEnumMember, QAPISchemaFeature)):
|
||||||
|
return None
|
||||||
|
|
||||||
|
qapi_type = ent
|
||||||
|
optional = False
|
||||||
|
if isinstance(ent, QAPISchemaObjectTypeMember):
|
||||||
|
qapi_type = ent.type
|
||||||
|
optional = ent.optional
|
||||||
|
|
||||||
|
if isinstance(qapi_type, QAPISchemaArrayType):
|
||||||
|
ret = f"[{qapi_type.element_type.doc_type()}]"
|
||||||
|
else:
|
||||||
|
assert isinstance(qapi_type, QAPISchemaType)
|
||||||
|
tmp = qapi_type.doc_type()
|
||||||
|
assert tmp
|
||||||
|
ret = tmp
|
||||||
|
if optional:
|
||||||
|
ret += "?"
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
# Transmogrification helpers
|
# Transmogrification helpers
|
||||||
|
|
||||||
def visit_paragraph(self, section: QAPIDoc.Section) -> None:
|
def visit_paragraph(self, section: QAPIDoc.Section) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue