diff mbox

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

Message ID 1331826359-13398-1-git-send-email-fsimonce@redhat.com
State New
Headers show

Commit Message

Federico Simoncelli March 15, 2012, 3:45 p.m. UTC
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(-)

Comments

Luiz Capitulino March 16, 2012, 7:16 p.m. UTC | #1
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
diff mbox

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