[Qemu-devel] [PATCH v2 30/54] qapi: add #if conditions on generated enum values

Marc-André Lureau posted 54 patches 8 years, 5 months ago
There is a newer version of this series
[Qemu-devel] [PATCH v2 30/54] qapi: add #if conditions on generated enum values
Posted by Marc-André Lureau 8 years, 5 months ago
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/qapi.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 9c7c01c11d..201e425842 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1967,13 +1967,16 @@ static const char *const %(c_name)s_array[] = {
 ''',
                 c_name=c_name(name))
     for value in values:
+        ifcond = None
         if isinstance(value, tuple):
             value, ifcond = value
+        ret += gen_if(ifcond)
         index = c_enum_const(name, value, prefix)
         ret += mcgen('''
     [%(index)s] = "%(value)s",
 ''',
                      index=index, value=value)
+        ret += gen_endif(ifcond)
 
     max_index = c_enum_const(name, '_MAX', prefix)
     ret += mcgen('''
@@ -1999,12 +2002,15 @@ typedef enum %(c_name)s {
                 c_name=c_name(name))
 
     for value in enum_values:
+        ifcond = None
         if isinstance(value, tuple):
             value, ifcond = value
+        ret += gen_if(ifcond)
         ret += mcgen('''
     %(c_enum)s,
 ''',
                      c_enum=c_enum_const(name, value, prefix))
+        ret += gen_endif(ifcond)
 
     ret += mcgen('''
 } %(c_name)s;
-- 
2.14.1.146.gd35faa819


Re: [Qemu-devel] [PATCH v2 30/54] qapi: add #if conditions on generated enum values
Posted by Markus Armbruster 8 years, 5 months ago
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  scripts/qapi.py | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index 9c7c01c11d..201e425842 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -1967,13 +1967,16 @@ static const char *const %(c_name)s_array[] = {
>  ''',
>                  c_name=c_name(name))
>      for value in values:
> +        ifcond = None

I hoped I would see this line in a later patch when I asked for it in my
review of the previous patch :)

>          if isinstance(value, tuple):
>              value, ifcond = value
> +        ret += gen_if(ifcond)
>          index = c_enum_const(name, value, prefix)
>          ret += mcgen('''
>      [%(index)s] = "%(value)s",
>  ''',
>                       index=index, value=value)
> +        ret += gen_endif(ifcond)
>  
>      max_index = c_enum_const(name, '_MAX', prefix)
>      ret += mcgen('''
> @@ -1999,12 +2002,15 @@ typedef enum %(c_name)s {
>                  c_name=c_name(name))
>  
>      for value in enum_values:
> +        ifcond = None
>          if isinstance(value, tuple):
>              value, ifcond = value
> +        ret += gen_if(ifcond)
>          ret += mcgen('''
>      %(c_enum)s,
>  ''',
>                       c_enum=c_enum_const(name, value, prefix))
> +        ret += gen_endif(ifcond)
>  
>      ret += mcgen('''
>  } %(c_name)s;