Patchwork [v2] qapi: escaping dots in c_var and in de_camel_case

login
register
mail settings
Submitter Federico Simoncelli
Date March 15, 2012, 3:45 p.m.
Message ID <1331826359-13398-1-git-send-email-fsimonce@redhat.com>
Download mbox | patch
Permalink /patch/147037/
State New
Headers show

Comments

Federico Simoncelli - March 15, 2012, 3:45 p.m.
This allows qapi commands and types with dots (downstream QMP extensions
containing fully qualified domain names).

Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
---
 scripts/qapi.py |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Luiz Capitulino - March 16, 2012, 7:16 p.m.
On Thu, 15 Mar 2012 15:45:59 +0000
Federico Simoncelli <fsimonce@redhat.com> wrote:

> This allows qapi commands and types with dots (downstream QMP extensions
> containing fully qualified domain names).
> 
> Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
> ---
>  scripts/qapi.py |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index 6e05469..b1173bf 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -111,7 +111,7 @@ def de_camel_case(name):
>      for ch in name:
>          if ch.isupper() and new_name:
>              new_name += '_'
> -        if ch == '-':
> +        if ch == '-' or ch == '.':
>              new_name += '_'
>          else:
>              new_name += ch.lower()
> @@ -131,7 +131,7 @@ def camel_case(name):
>      return new_name
>  
>  def c_var(name):
> -    return '_'.join(name.split('-')).lstrip("*")
> +    return name.replace('-', '_').replace('.', '_').lstrip('*')

This changes a struct member access from 'foo.bar' to 'foo_bar' in the
generated qapi-visit.c.

Please, test build your patches against master before posting.

>  
>  def c_list_type(name):
>      return '%sList' % name

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 6e05469..b1173bf 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -111,7 +111,7 @@  def de_camel_case(name):
     for ch in name:
         if ch.isupper() and new_name:
             new_name += '_'
-        if ch == '-':
+        if ch == '-' or ch == '.':
             new_name += '_'
         else:
             new_name += ch.lower()
@@ -131,7 +131,7 @@  def camel_case(name):
     return new_name
 
 def c_var(name):
-    return '_'.join(name.split('-')).lstrip("*")
+    return name.replace('-', '_').replace('.', '_').lstrip('*')
 
 def c_list_type(name):
     return '%sList' % name