diff mbox series

[RFC,12/21] qapi: Concentrate QAPISchemaParser.exprs updates in .__init__()

Message ID 20180202130336.24719-13-armbru@redhat.com
State New
Headers show
Series Modularize generated QAPI code | expand

Commit Message

Markus Armbruster Feb. 2, 2018, 1:03 p.m. UTC
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/common.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Comments

Marc-Andre Lureau Feb. 5, 2018, 1:45 p.m. UTC | #1
On Fri, Feb 2, 2018 at 2:03 PM, Markus Armbruster <armbru@redhat.com> wrote:
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

It's not obvious the motivation behind this change (beside behind more
elegant), but
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  scripts/qapi/common.py | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index d334e1db5a..7a327bfe9f 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -286,8 +286,12 @@ class QAPISchemaParser(object):
>                  if not isinstance(include, str):
>                      raise QAPISemError(info,
>                                         "Value of 'include' must be a string")
> -                self._include(include, info, os.path.dirname(self.fname),
> -                              previously_included)
> +                exprs_include = self._include(include, info,
> +                                              os.path.dirname(self.fname),
> +                                              previously_included)
> +                if exprs_include:
> +                    self.exprs.extend(exprs_include.exprs)
> +                    self.docs.extend(exprs_include.docs)
>              elif "pragma" in expr:
>                  self.reject_expr_doc(cur_doc)
>                  if len(expr) != 1:
> @@ -330,14 +334,13 @@ class QAPISchemaParser(object):
>
>          # skip multiple include of the same file
>          if incl_abs_fname in previously_included:
> -            return
> +            return None
> +
>          try:
>              fobj = open(incl_fname, 'r')
>          except IOError as e:
>              raise QAPISemError(info, '%s: %s' % (e.strerror, incl_fname))
> -        exprs_include = QAPISchemaParser(fobj, previously_included, info)
> -        self.exprs.extend(exprs_include.exprs)
> -        self.docs.extend(exprs_include.docs)
> +        return QAPISchemaParser(fobj, previously_included, info)
>
>      def _pragma(self, name, value, info):
>          global doc_required, returns_whitelist, name_case_whitelist
> --
> 2.13.6
>
Markus Armbruster Feb. 5, 2018, 2:26 p.m. UTC | #2
Marc-Andre Lureau <mlureau@redhat.com> writes:

> On Fri, Feb 2, 2018 at 2:03 PM, Markus Armbruster <armbru@redhat.com> wrote:
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> It's not obvious the motivation behind this change (beside behind more
> elegant), but

At one point during my search for a good way to record includes in the
parse tree, updating .exprs in two places got in the way, so I cleaned
it up.  I guess it's not in the way of the solution I eventually chose,
but I consider it a worthwhile little cleanup on its own.

> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Thanks!
diff mbox series

Patch

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index d334e1db5a..7a327bfe9f 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -286,8 +286,12 @@  class QAPISchemaParser(object):
                 if not isinstance(include, str):
                     raise QAPISemError(info,
                                        "Value of 'include' must be a string")
-                self._include(include, info, os.path.dirname(self.fname),
-                              previously_included)
+                exprs_include = self._include(include, info,
+                                              os.path.dirname(self.fname),
+                                              previously_included)
+                if exprs_include:
+                    self.exprs.extend(exprs_include.exprs)
+                    self.docs.extend(exprs_include.docs)
             elif "pragma" in expr:
                 self.reject_expr_doc(cur_doc)
                 if len(expr) != 1:
@@ -330,14 +334,13 @@  class QAPISchemaParser(object):
 
         # skip multiple include of the same file
         if incl_abs_fname in previously_included:
-            return
+            return None
+
         try:
             fobj = open(incl_fname, 'r')
         except IOError as e:
             raise QAPISemError(info, '%s: %s' % (e.strerror, incl_fname))
-        exprs_include = QAPISchemaParser(fobj, previously_included, info)
-        self.exprs.extend(exprs_include.exprs)
-        self.docs.extend(exprs_include.docs)
+        return QAPISchemaParser(fobj, previously_included, info)
 
     def _pragma(self, name, value, info):
         global doc_required, returns_whitelist, name_case_whitelist