Am 27.11.2013 um 03:32 hat Amos Kong geschrieben:
> On Fri, Jul 19, 2013 at 04:05:16PM -0600, Eric Blake wrote:
> > On 07/16/2013 04:37 AM, Amos Kong wrote:
> > > { 'type': 'DataObject',
> > >   'data': { '*key': 'str', '*type': 'str', '*data': ['DataObject'] } }
> > > 
> > > Not all the keys in data will be used.
> > >  # List: type
> > >  # Dict: key, type
> > >  # nested List: type, data
> > >  # nested Dict: key, type, data
> > 
> > I wonder if we can take advantage of Kevin's work on unions to make this
> > MUCH easier to use:
> > 
> > https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg01407.html
> > 
> > { 'enum': 'DataObjectType',
> >   'data': [ 'command', 'struct', 'union', 'enum' ] }
> > # extend to add 'event' later
> > 
> > { 'type': 'DataObjectBase',
> >   'data': { 'name': 'str' } }
> > 
> > { 'union': 'DataObjectMemberType',
> >   'discriminator': {},
> >   'data': { 'reference': 'str',
> >             'inline': 'DataObject' } }
> > 
> > { 'type': DataObjectMember',
> >   'data': { 'name': 'str', 'type': 'DataObjectMemberType',
> >             '*optional': 'bool', '*recursive': 'bool' } }
> > 
> > { 'type': 'DataObjectStruct',
> >   'data': { 'data': [ 'DataObjectMember' ] } }
> > { 'type': 'DataObjectEnum',
> >   'data': { 'data': [ 'str' ] } }
> > { 'type': 'DataObjectUnion',
> >   'data': { 'data': [ 'DataObjectMember' ], '*base': 'str',
> >             '*discriminator': 'str' } }
> > { 'type': 'DataObjectCommand',
> >   'data': { 'data': [ 'DataObjectMember' ], '*returns': 'DataObject' } }
> 
>  
> > { 'union': 'DataObject',
> >   'base': 'DataObjectBase',
> >   'discriminator': 'type',
> >   'data': {
> >     'struct': 'DataObjectStruct',
> >     'enum': 'DataObjectEnum',
> >     'union': 'DataObjectUnion',
> >     'command': 'DataObjectCommand',
> 
> >     'array': {} }
> 
> 
> In my patch, I used a _dictionary_ to describe this kind of thing
>  1) dict,  2) list, 3) str
> 
> The above line is used for Dictionary or List, it should be:
>       'array': ['DataObject']
> 
> But I touched a new error:
> qapi-visit.c: In function ‘visit_type_DataObject’:
> qapi-visit.c:7255:29: error: implicit declaration of function 
> ‘visit_type_DataObjectList_fields’ [-Werror=implicit-function-declaration]
>                              visit_type_DataObjectList_fields(m, 
> &(*obj)->array, &err);
> 
> ----
> So I try to defined 
> 
> { 'type': 'DataObjectArray', 'data': ['DataObject'] }
> 'DataObjectArrayType' } }
> 
> { 'union': 'DataObject',
>   'base': 'DataObjectBase',
>   'discriminator': 'name',
>   'data': {
>     'array': 'DataObjectArray',
> 
> got error:
> Traceback (most recent call last):
>   File "/home/devel/qemu/scripts/qapi-types.py", line 471, in <module>
>     ret += generate_struct(expr) + "\n"
>   File "/home/devel/qemu/scripts/qapi-types.py", line 101, in generate_struct
>     ret += generate_struct_fields(members)
>   File "/home/devel/qemu/scripts/qapi-types.py", line 67, in 
> generate_struct_fields
>     for argname, argentry, optional, structured in parse_args(members):
>   File "/home/devel/qemu/scripts/qapi.py", line 197, in parse_args
>     argentry = typeinfo[member]
> TypeError: list indices must be integers, not str

I've never had a need for unions inside an array so far, but that
doesn't make them less useful. We'll need them in more places than just
here.

So instead of working around the current limitations, the right thing to
do is to modify the QAPI generator to allow this kind of definitions.

Kevin

Attachment: pgpzJec99zfSG.pgp
Description: PGP signature

Reply via email to