Re: [PATCH v2 02/53] qapi/introspect: expose the type name map

Markus Armbruster <[email protected]>
Newsgroups gmane.comp.emulators.qemu
Message-ID <[email protected]>
Marc-André Lureau <[email protected]> writes:

> Preserve the internal-to-masked name map computed during introspection
> visitation and return it from gen_introspect(). The type-infos generator
> will consume this map to produce per-type QAPITypeInfo constants with
> correct masked names.
>
> Signed-off-by: Marc-André Lureau <[email protected]>
> ---
>  scripts/qapi/introspect.py | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
> index 7e28de2279a..d3d3de481f4 100644
> --- a/scripts/qapi/introspect.py
> +++ b/scripts/qapi/introspect.py
> @@ -178,6 +178,7 @@ def __init__(self, prefix: str, unmask: bool):
>          self._trees: List[Annotated[SchemaInfo]] = []
>          self._used_types: List[QAPISchemaType] = []
>          self._name_map: Dict[str, str] = {}
> +        self._final_name_map: Dict[str, str] = {}
>          self._genc.add(mcgen('''
>  #include "qemu/osdep.h"
>  #include "%(prefix)sqapi-introspect.h"
> @@ -208,8 +209,17 @@ def visit_end(self) -> None:
>          self._schema = None
>          self._trees = []
>          self._used_types = []
> +        self._final_name_map = dict(self._name_map)
>          self._name_map = {}
>  
> +    def name_map(self) -> Dict[str, str]:
> +        """Return the QAPI-name-to-schema-name map.
> +
> +        Must be called after visit() has completed; the map is
> +        populated during visit_end().
> +        """
> +        return self._final_name_map

Can you explain why ._final_name_map is useful?

> +
>      def visit_needed(self, entity: QAPISchemaEntity) -> bool:
>          # Ignore types on first pass; visit_end() will pick up used types
>          return not isinstance(entity, QAPISchemaType)
> @@ -387,7 +397,8 @@ def visit_event(self, name: str, info: Optional[QAPISourceInfo],
>  
>  
>  def gen_introspect(schema: QAPISchema, output_dir: str, prefix: str,
> -                   opt_unmask: bool) -> None:
> +                   opt_unmask: bool) -> Dict[str, str]:
>      vis = QAPISchemaGenIntrospectVisitor(prefix, opt_unmask)
>      schema.visit(vis)
>      vis.write(output_dir)
> +    return vis.name_map()

Returning QAPISchemaGenIntrospectVisitor's existing map through
gen_introspect() works.

Taking a step back...  QAPISchemaGenIntrospectVisitor computes the set
of types that are actually used in QMP, and a map from type name to
masked type name.  Back when I wrote the class, nothing else was
interested in either of these two things, so keeping them within their
only user made sense.

Now you want masked type names for QAPISchemaGenTypeInfoVisitor.  And
the doc generator could use the set of types used in QMP to trim the QMP
reference manual.  Are these things still in the right place?

If no: we can move them to a better place before or after this series.
Before would be less churn in master, but more in your tree.  So perhaps
you'd rather have it done afterwards.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.