QAPISchemaModularCVisitor attempts to encapsulate the way it splits the module name space between user modules (name can't start with './') and system modules (name is None or starts with './') by providing separate ._add_user_module() and ._add_system_module(), where the latter prepends './' to names other than None.
Not worthwhile. Dumb down to a single ._add_module(), and have the callers take care of giving system modules names starting with './'. Signed-off-by: Markus Armbruster <arm...@redhat.com> --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 2 +- scripts/qapi/gen.py | 16 +++++----------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 71744f48a3..4911166339 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -286,7 +286,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): types=types)) def visit_end(self) -> None: - self._add_system_module('init', ' * QAPI Commands initialization') + self._add_module('./init', ' * QAPI Commands initialization') self._genh.add(mcgen(''' #include "qapi/qmp/dispatch.h" diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 9851653b9d..079c666ec6 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -191,7 +191,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): types=types)) def visit_end(self) -> None: - self._add_system_module('emit', ' * QAPI Events emission') + self._add_module('./emit', ' * QAPI Events emission') self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "%(prefix)sqapi-emit-events.h" diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 67635b6a26..d9f8bac9aa 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -287,21 +287,15 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): self._module_basename(what, name)) def _add_module(self, name: str, blurb: str) -> None: + if self._is_user_module(name): + if self._main_module is None: + self._main_module = name basename = self._module_filename(self._what, name) genc = QAPIGenC(basename + '.c', blurb, self._pydoc) genh = QAPIGenH(basename + '.h', blurb, self._pydoc) self._module[name] = (genc, genh) self._current_module = name - def _add_user_module(self, name: str, blurb: str) -> None: - assert self._is_user_module(name) - if self._main_module is None: - self._main_module = name - self._add_module(name, blurb) - - def _add_system_module(self, name: str, blurb: str) -> None: - self._add_module('./' + name, blurb) - def write(self, output_dir: str, opt_builtins: bool = False) -> None: for name in self._module: if self._is_builtin_module(name) and not opt_builtins: @@ -319,14 +313,14 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): def visit_module(self, name: Optional[str]) -> None: if name is None: if self._builtin_blurb: - self._add_system_module('builtin', self._builtin_blurb) + self._add_module('./builtin', self._builtin_blurb) self._begin_builtin_module() else: # The built-in module has not been created. No code may # be generated. self._current_module = None else: - self._add_user_module(name, self._user_blurb) + self._add_module(name, self._user_blurb) self._begin_user_module(name) def visit_include(self, name: str, info: QAPISourceInfo) -> None: -- 2.26.2