[Qemu-devel] [PATCH v2 20/54] qapi-introspect: modify to_qlit() to take an optional suffix

Marc-André Lureau posted 54 patches 8 years, 5 months ago
There is a newer version of this series
[Qemu-devel] [PATCH v2 20/54] qapi-introspect: modify to_qlit() to take an optional suffix
Posted by Marc-André Lureau 8 years, 5 months ago
The following patch is going to break list entries with #if/#endif, so
they should have the trailing ',' as suffix.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/qapi-introspect.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 4c437d60ec..dfb6d2ded4 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -16,7 +16,7 @@ def to_c_string(s):
     return '"' + s.replace('\\', r'\\').replace('"', r'\"') + '"'
 
 
-def to_qlit(obj, level=0, first_indent=True):
+def to_qlit(obj, level=0, first_indent=True, suffix=''):
 
     def indent(level):
         return level * 4 * ' '
@@ -29,11 +29,11 @@ def to_qlit(obj, level=0, first_indent=True):
     elif isinstance(obj, str):
         ret += 'QLIT_QSTR(' + to_c_string(obj) + ')'
     elif isinstance(obj, list):
-        elts = [to_qlit(elt, level + 1)
+        elts = [to_qlit(elt, level + 1, suffix=',')
                 for elt in obj]
         elts.append(indent(level + 1) + "{}")
         ret += 'QLIT_QLIST(((QLitObject[]) {\n'
-        ret += ',\n'.join(elts) + '\n'
+        ret += '\n'.join(elts) + '\n'
         ret += indent(level) + '}))'
     elif isinstance(obj, dict):
         elts = []
@@ -46,7 +46,7 @@ def to_qlit(obj, level=0, first_indent=True):
         ret += indent(level) + '}))'
     else:
         assert False                # not implemented
-    return ret
+    return ret + suffix
 
 
 class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor):
-- 
2.14.1.146.gd35faa819


Re: [Qemu-devel] [PATCH v2 20/54] qapi-introspect: modify to_qlit() to take an optional suffix
Posted by Markus Armbruster 8 years, 5 months ago
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> The following patch is going to break list entries with #if/#endif, so
> they should have the trailing ',' as suffix.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  scripts/qapi-introspect.py | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
> index 4c437d60ec..dfb6d2ded4 100644
> --- a/scripts/qapi-introspect.py
> +++ b/scripts/qapi-introspect.py
> @@ -16,7 +16,7 @@ def to_c_string(s):
>      return '"' + s.replace('\\', r'\\').replace('"', r'\"') + '"'
>  
>  
> -def to_qlit(obj, level=0, first_indent=True):
> +def to_qlit(obj, level=0, first_indent=True, suffix=''):
>  
>      def indent(level):
>          return level * 4 * ' '
> @@ -29,11 +29,11 @@ def to_qlit(obj, level=0, first_indent=True):
>      elif isinstance(obj, str):
>          ret += 'QLIT_QSTR(' + to_c_string(obj) + ')'
>      elif isinstance(obj, list):
> -        elts = [to_qlit(elt, level + 1)
> +        elts = [to_qlit(elt, level + 1, suffix=',')
>                  for elt in obj]
>          elts.append(indent(level + 1) + "{}")
>          ret += 'QLIT_QLIST(((QLitObject[]) {\n'
> -        ret += ',\n'.join(elts) + '\n'
> +        ret += '\n'.join(elts) + '\n'
>          ret += indent(level) + '}))'
>      elif isinstance(obj, dict):
>          elts = []
> @@ -46,7 +46,7 @@ def to_qlit(obj, level=0, first_indent=True):
>          ret += indent(level) + '}))'
>      else:
>          assert False                # not implemented
> -    return ret
> +    return ret + suffix
>  
>  
>  class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor):

Hmm.  I wonder the appended simpler patch would do.

diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 4c437d60ec..73edb55cd5 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -33,7 +33,7 @@ def to_qlit(obj, level=0, first_indent=True):
                 for elt in obj]
         elts.append(indent(level + 1) + "{}")
         ret += 'QLIT_QLIST(((QLitObject[]) {\n'
-        ret += ',\n'.join(elts) + '\n'
+        ret += '\n'.join(elts) + '\n'
         ret += indent(level) + '}))'
     elif isinstance(obj, dict):
         elts = []
@@ -46,6 +46,8 @@ def to_qlit(obj, level=0, first_indent=True):
         ret += indent(level) + '}))'
     else:
         assert False                # not implemented
+    if level > 0:
+        ret += ','
     return ret
 
 

Re: [Qemu-devel] [PATCH v2 20/54] qapi-introspect: modify to_qlit() to take an optional suffix
Posted by Marc-André Lureau 8 years, 5 months ago
On Tue, Sep 5, 2017 at 11:42 AM, Markus Armbruster <armbru@redhat.com> wrote:
> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>
>> The following patch is going to break list entries with #if/#endif, so
>> they should have the trailing ',' as suffix.
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>  scripts/qapi-introspect.py | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
>> index 4c437d60ec..dfb6d2ded4 100644
>> --- a/scripts/qapi-introspect.py
>> +++ b/scripts/qapi-introspect.py
>> @@ -16,7 +16,7 @@ def to_c_string(s):
>>      return '"' + s.replace('\\', r'\\').replace('"', r'\"') + '"'
>>
>>
>> -def to_qlit(obj, level=0, first_indent=True):
>> +def to_qlit(obj, level=0, first_indent=True, suffix=''):
>>
>>      def indent(level):
>>          return level * 4 * ' '
>> @@ -29,11 +29,11 @@ def to_qlit(obj, level=0, first_indent=True):
>>      elif isinstance(obj, str):
>>          ret += 'QLIT_QSTR(' + to_c_string(obj) + ')'
>>      elif isinstance(obj, list):
>> -        elts = [to_qlit(elt, level + 1)
>> +        elts = [to_qlit(elt, level + 1, suffix=',')
>>                  for elt in obj]
>>          elts.append(indent(level + 1) + "{}")
>>          ret += 'QLIT_QLIST(((QLitObject[]) {\n'
>> -        ret += ',\n'.join(elts) + '\n'
>> +        ret += '\n'.join(elts) + '\n'
>>          ret += indent(level) + '}))'
>>      elif isinstance(obj, dict):
>>          elts = []
>> @@ -46,7 +46,7 @@ def to_qlit(obj, level=0, first_indent=True):
>>          ret += indent(level) + '}))'
>>      else:
>>          assert False                # not implemented
>> -    return ret
>> +    return ret + suffix
>>
>>
>>  class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor):
>
> Hmm.  I wonder the appended simpler patch would do.

It works, thanks for the suggestion

>
> diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
> index 4c437d60ec..73edb55cd5 100644
> --- a/scripts/qapi-introspect.py
> +++ b/scripts/qapi-introspect.py
> @@ -33,7 +33,7 @@ def to_qlit(obj, level=0, first_indent=True):
>                  for elt in obj]
>          elts.append(indent(level + 1) + "{}")
>          ret += 'QLIT_QLIST(((QLitObject[]) {\n'
> -        ret += ',\n'.join(elts) + '\n'
> +        ret += '\n'.join(elts) + '\n'
>          ret += indent(level) + '}))'
>      elif isinstance(obj, dict):
>          elts = []
> @@ -46,6 +46,8 @@ def to_qlit(obj, level=0, first_indent=True):
>          ret += indent(level) + '}))'
>      else:
>          assert False                # not implemented
> +    if level > 0:
> +        ret += ','
>      return ret
>
>
>



-- 
Marc-André Lureau