qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] qapi: generate space in c_type() to fix coding


From: Amos Kong
Subject: Re: [Qemu-devel] [PATCH] qapi: generate space in c_type() to fix coding style
Date: Fri, 25 Apr 2014 12:36:36 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Apr 22, 2014 at 09:20:41AM +0200, Markus Armbruster wrote:
> Paolo Bonzini <address@hidden> writes:
> 
> > Il 18/04/2014 23:56, Amos Kong ha scritto:
> >> Currently we always add a space after c_type in mcgen(), there is
> >> some redundant space in generated code. The space isn't needed for
> >> points by the coding style.
> >>
> >>   char * value;
> >>         ^
> >>   qapi_free_NameInfo(NameInfo * obj)
> >>                                ^
> >> It's fussy to add checking in each mcgen(), this patch just addes
> >> the necessary space in c_type(), and remove original space in mcgen().
> >
> > It also makes the generator harder to read to though, and the
> > improvement in the generated code is minor enough that I think the
> > change is overall negative.  But I won't oppose the patch if the
> > maintainers are fine with it.

Hi Markus,
 
> The readability hit could be avoided: instead of moving the space from
> mcgen()'s argument to c_type()'s result, add a "hungry character" to
> c_type()'s result, then make it eat space to the right in mcgen().

'\b' is used to eat char in left, but what's the "hungry character" to
each char in right?

When I added a '\b' to c_type()'s return, there is an arror:
  error: stray '\10' in program


Another solution:

I tried to use '\b' to eat the redundant space by following code:

| def eat_space(type):
|     if type[-1] == '*':                                                       
          
|         return '\b'                                                           
          
|     return ''   


|         return mcgen('''
| 
| typedef struct %(name)sList
| {           
|     union {
|         %(type)s %(space)svalue;
|         uint64_t padding;
|     };
|     struct %(name)sList *next;
| } %(name)sList;
| ''',
|                      type=c_type(name),
|                      space=eat_space(name),
|                      name=name)

I looks still not good ?

-- 
                        Amos.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]