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
+
     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()

-- 
2.54.0


Reply via email to