[Spice-devel,v4,07/41] codegen: Allows to specify descriptions for enumerations

Submitted by Frediano Ziglio on July 23, 2015, 3:54 p.m.

Details

Message ID 1437666898-27863-8-git-send-email-fziglio@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 23, 2015, 3:54 p.m.
These descriptions will be used to show in wireshark dissector.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 python_modules/ptypes.py       | 16 ++++++++++++----
 python_modules/spice_parser.py |  2 +-
 2 files changed, 13 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index f635955..e01d3e7 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -371,20 +371,24 @@  class EnumType(EnumBaseType):
         last = -1
         names = {}
         values = {}
+        descs = {}
         for v in enums:
             name = v[0]
-            if len(v) > 1:
-                value = v[1]
+            desc = v[1][1]
+            if len(v) > 2:
+                value = v[2]
             else:
                 value = last + 1
             last = value
 
             assert value not in names
             names[value] = name
+            descs[value] = desc
             values[name] = value
 
         self.names = names
         self.values = values
+        self.descs = descs
 
         self.attributes = fix_attributes(attribute_list)
 
@@ -424,20 +428,24 @@  class FlagsType(EnumBaseType):
         last = -1
         names = {}
         values = {}
+        descs = {}
         for v in flags:
             name = v[0]
-            if len(v) > 1:
-                value = v[1]
+            desc = v[1][1]
+            if len(v) > 2:
+                value = v[2]
             else:
                 value = last + 1
             last = value
 
             assert value not in names
             names[value] = name
+            descs[value] = desc
             values[name] = value
 
         self.names = names
         self.values = values
+        self.descs = descs
 
         self.attributes = fix_attributes(attribute_list)
 
diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py
index a0f969a..06000a4 100644
--- a/python_modules/spice_parser.py
+++ b/python_modules/spice_parser.py
@@ -120,7 +120,7 @@  def SPICE_BNF():
                      int32_ ^ uint32_ ^ int64_ ^ uint64_ ^
                      typename).setName("type")
 
-        flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(equals + integer))) + Optional(comma) + rbrace)
+        flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(Group(ws_desc), default=[None,None]) + Optional(equals + integer))) + Optional(comma) + rbrace)
 
         messageSpec = Group(message_ + messageBody + attributes).setParseAction(lambda toks: ptypes.MessageType(None, toks[0][1], toks[0][2])) | typename
 

Comments

On Thu, Jul 23, 2015 at 04:54:24PM +0100, Frediano Ziglio wrote:
> These descriptions will be used to show in wireshark dissector.

Could be 'will be shown', but does not matter too much to be :)

Christophe

> 
> Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  python_modules/ptypes.py       | 16 ++++++++++++----
>  python_modules/spice_parser.py |  2 +-
>  2 files changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
> index f635955..e01d3e7 100644
> --- a/python_modules/ptypes.py
> +++ b/python_modules/ptypes.py
> @@ -371,20 +371,24 @@ class EnumType(EnumBaseType):
>          last = -1
>          names = {}
>          values = {}
> +        descs = {}
>          for v in enums:
>              name = v[0]
> -            if len(v) > 1:
> -                value = v[1]
> +            desc = v[1][1]
> +            if len(v) > 2:
> +                value = v[2]
>              else:
>                  value = last + 1
>              last = value
>  
>              assert value not in names
>              names[value] = name
> +            descs[value] = desc
>              values[name] = value
>  
>          self.names = names
>          self.values = values
> +        self.descs = descs
>  
>          self.attributes = fix_attributes(attribute_list)
>  
> @@ -424,20 +428,24 @@ class FlagsType(EnumBaseType):
>          last = -1
>          names = {}
>          values = {}
> +        descs = {}
>          for v in flags:
>              name = v[0]
> -            if len(v) > 1:
> -                value = v[1]
> +            desc = v[1][1]
> +            if len(v) > 2:
> +                value = v[2]
>              else:
>                  value = last + 1
>              last = value
>  
>              assert value not in names
>              names[value] = name
> +            descs[value] = desc
>              values[name] = value
>  
>          self.names = names
>          self.values = values
> +        self.descs = descs
>  
>          self.attributes = fix_attributes(attribute_list)
>  
> diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py
> index a0f969a..06000a4 100644
> --- a/python_modules/spice_parser.py
> +++ b/python_modules/spice_parser.py
> @@ -120,7 +120,7 @@ def SPICE_BNF():
>                       int32_ ^ uint32_ ^ int64_ ^ uint64_ ^
>                       typename).setName("type")
>  
> -        flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(equals + integer))) + Optional(comma) + rbrace)
> +        flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(Group(ws_desc), default=[None,None]) + Optional(equals + integer))) + Optional(comma) + rbrace)
>  
>          messageSpec = Group(message_ + messageBody + attributes).setParseAction(lambda toks: ptypes.MessageType(None, toks[0][1], toks[0][2])) | typename
>  
> -- 
> 2.1.0
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel