aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2024-02-27 12:39:09 +0100
committerMarkus Armbruster <armbru@redhat.com>2024-03-04 07:12:40 +0100
commitba7f63f9a4a3c80bb92a00a7a07a350ca0e6fb72 (patch)
treed384af296f552daf1d1f5b765fcd9c2585d5b466 /scripts
parente1007b6bab5cf97705bf4f2aaec1f607787355b8 (diff)
qapi: Memorize since & returns sections
This is chiefly to make code that looks up these sections easier to read. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-ID: <20240227113921.236097-2-armbru@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi/parser.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 11707418fb..bfc47cf3cb 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -639,6 +639,10 @@ class QAPIDoc:
# dicts mapping parameter/feature names to their description
self.args: Dict[str, QAPIDoc.ArgSection] = {}
self.features: Dict[str, QAPIDoc.ArgSection] = {}
+ # a command's "Returns" section
+ self.returns: Optional[QAPIDoc.Section] = None
+ # "Since" section
+ self.since: Optional[QAPIDoc.Section] = None
# sections other than .body, .args, .features
self.sections: List[QAPIDoc.Section] = []
@@ -660,14 +664,17 @@ class QAPIDoc:
self.all_sections.append(section)
def new_tagged_section(self, info: QAPISourceInfo, tag: str) -> None:
- if tag in ('Returns', 'Since'):
- for section in self.all_sections:
- if isinstance(section, self.ArgSection):
- continue
- if section.tag == tag:
- raise QAPISemError(
- info, "duplicated '%s' section" % tag)
section = self.Section(info, tag)
+ if tag == 'Returns':
+ if self.returns:
+ raise QAPISemError(
+ info, "duplicated '%s' section" % tag)
+ self.returns = section
+ elif tag == 'Since':
+ if self.since:
+ raise QAPISemError(
+ info, "duplicated '%s' section" % tag)
+ self.since = section
self.sections.append(section)
self.all_sections.append(section)
@@ -708,13 +715,9 @@ class QAPIDoc:
self.features[feature.name].connect(feature)
def check_expr(self, expr: QAPIExpression) -> None:
- if 'command' not in expr:
- sec = next((sec for sec in self.sections
- if sec.tag == 'Returns'),
- None)
- if sec:
- raise QAPISemError(sec.info,
- "'Returns:' is only valid for commands")
+ if self.returns and 'command' not in expr:
+ raise QAPISemError(self.returns.info,
+ "'Returns:' is only valid for commands")
def check(self) -> None: