Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-02-1…
Browse files Browse the repository at this point in the history
…8' into staging

QAPI patches patches for 2021-02-18

# gpg: Signature made Thu 18 Feb 2021 18:51:35 GMT
# gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg:                issuer "armbru@redhat.com"
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full]
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>" [full]
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653

* remotes/armbru/tags/pull-qapi-2021-02-18:
  qapi/introspect.py: set _gen_tree's default ifcond argument to ()
  qapi/introspect.py: Type _gen_tree variants as Sequence[str]
  qapi/introspect.py: Update copyright and authors list
  qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlit
  qapi/introspect.py: add type hint annotations
  qapi/introspect.py: remove _gen_variants helper
  qapi/introspect.py: improve readability of _tree_to_qlit
  qapi/introspect.py: improve _tree_to_qlit error message
  qapi/introspect.py: create a typed 'Annotated' data strutcure
  qapi/introspect.py: Introduce preliminary tree typing
  qapi/introspect.py: Always define all 'extra' dict keys
  qapi/introspect.py: replace 'extra' dict with 'comment' argument
  qapi/introspect.py: Unify return type of _make_tree()
  qapi/introspect.py: guard against ifcond/comment misuse
  qapi/introspect.py: add _gen_features helper
  qapi/introspect.py: use _make_tree for features nodes
  qapi/introspect.py: assert schema is not None
  qapi: Replace List[str] with Sequence[str] for ifcond

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Feb 19, 2021
2 parents ce42fe1 + 9b77d94 commit e90ef02
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 131 deletions.
3 changes: 2 additions & 1 deletion scripts/qapi/commands.py
Expand Up @@ -17,6 +17,7 @@
Dict,
List,
Optional,
Sequence,
Set,
)

Expand Down Expand Up @@ -297,7 +298,7 @@ def visit_end(self) -> None:
def visit_command(self,
name: str,
info: Optional[QAPISourceInfo],
ifcond: List[str],
ifcond: Sequence[str],
features: List[QAPISchemaFeature],
arg_type: Optional[QAPISchemaObjectType],
ret_type: Optional[QAPISchemaType],
Expand Down
4 changes: 2 additions & 2 deletions scripts/qapi/events.py
Expand Up @@ -12,7 +12,7 @@
See the COPYING file in the top-level directory.
"""

from typing import List, Optional
from typing import List, Optional, Sequence

from .common import c_enum_const, c_name, mcgen
from .gen import QAPISchemaModularCVisitor, build_params, ifcontext
Expand Down Expand Up @@ -214,7 +214,7 @@ def visit_end(self) -> None:
def visit_event(self,
name: str,
info: Optional[QAPISourceInfo],
ifcond: List[str],
ifcond: Sequence[str],
features: List[QAPISchemaFeature],
arg_type: Optional[QAPISchemaObjectType],
boxed: bool) -> None:
Expand Down
12 changes: 6 additions & 6 deletions scripts/qapi/gen.py
Expand Up @@ -17,8 +17,8 @@
from typing import (
Dict,
Iterator,
List,
Optional,
Sequence,
Tuple,
)

Expand Down Expand Up @@ -85,7 +85,7 @@ def write(self, output_dir: str) -> None:
fp.write(text)


def _wrap_ifcond(ifcond: List[str], before: str, after: str) -> str:
def _wrap_ifcond(ifcond: Sequence[str], before: str, after: str) -> str:
if before == after:
return after # suppress empty #if ... #endif

Expand Down Expand Up @@ -127,9 +127,9 @@ def build_params(arg_type: Optional[QAPISchemaObjectType],
class QAPIGenCCode(QAPIGen):
def __init__(self, fname: str):
super().__init__(fname)
self._start_if: Optional[Tuple[List[str], str, str]] = None
self._start_if: Optional[Tuple[Sequence[str], str, str]] = None

def start_if(self, ifcond: List[str]) -> None:
def start_if(self, ifcond: Sequence[str]) -> None:
assert self._start_if is None
self._start_if = (ifcond, self._body, self._preamble)

Expand Down Expand Up @@ -187,11 +187,11 @@ def _bottom(self) -> str:


@contextmanager
def ifcontext(ifcond: List[str], *args: QAPIGenCCode) -> Iterator[None]:
def ifcontext(ifcond: Sequence[str], *args: QAPIGenCCode) -> Iterator[None]:
"""
A with-statement context manager that wraps with `start_if()` / `end_if()`.
:param ifcond: A list of conditionals, passed to `start_if()`.
:param ifcond: A sequence of conditionals, passed to `start_if()`.
:param args: any number of `QAPIGenCCode`.
Example::
Expand Down

0 comments on commit e90ef02

Please sign in to comment.