diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2016-02-19 14:18:21 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2016-02-19 14:18:21 +0000 |
commit | 5cfffc30de4a34a47d2719d2cd87ababb6c6379b (patch) | |
tree | f0c82e5d2b983aed4280267a78906fd473bf051c /include | |
parent | 09125c5e76923aa22a72f43cb34b6e74ae7fe17f (diff) | |
parent | dbf11922622685934bfb41e7cf2be9bd4a0405c0 (diff) |
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-02-19' into staging
QAPI patches for 2016-02-19
# gpg: Signature made Fri 19 Feb 2016 10:10:18 GMT using RSA key ID EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg: aka "Markus Armbruster <armbru@pond.sub.org>"
* remotes/armbru/tags/pull-qapi-2016-02-19:
qapi: Change visit_start_implicit_struct to visit_start_alternate
qapi: Don't box branches of flat unions
qapi: Don't box struct branch of alternate
qapi-visit: Use common idiom in gen_visit_fields_decl()
qapi: Emit structs used as variants in topological order
qapi: Adjust layout of FooList types
qapi-visit: Less indirection in visit_type_Foo_fields()
qapi-visit: Unify struct and union visit
qapi: Visit variants in visit_type_FOO_fields()
qapi-visit: Simplify how we visit common union members
qapi: Add tests of complex objects within alternate
qapi: Forbid 'any' inside an alternate
qapi: Forbid empty unions and useless alternates
qapi: Simplify excess input reporting in input visitors
qapi-visit: Honor prefix of discriminator enum
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/qapi/visitor-impl.h | 21 | ||||
-rw-r--r-- | include/qapi/visitor.h | 63 |
2 files changed, 54 insertions, 30 deletions
diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index ea252f8e3a..6a1ddfbd9a 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -22,22 +22,23 @@ struct Visitor size_t size, Error **errp); void (*end_struct)(Visitor *v, Error **errp); - void (*start_implicit_struct)(Visitor *v, void **obj, size_t size, - Error **errp); - /* May be NULL */ - void (*end_implicit_struct)(Visitor *v); - void (*start_list)(Visitor *v, const char *name, Error **errp); /* Must be set */ - GenericList *(*next_list)(Visitor *v, GenericList **list); + GenericList *(*next_list)(Visitor *v, GenericList **list, size_t size); /* Must be set */ void (*end_list)(Visitor *v); + /* Optional, needed for input and dealloc visitors. */ + void (*start_alternate)(Visitor *v, const char *name, + GenericAlternate **obj, size_t size, + bool promote_int, Error **errp); + + /* Optional, needed for dealloc visitor. */ + void (*end_alternate)(Visitor *v); + + /* Must be set. */ void (*type_enum)(Visitor *v, const char *name, int *obj, const char *const strings[], Error **errp); - /* May be NULL; only needed for input visitors. */ - void (*get_next_type)(Visitor *v, const char *name, QType *type, - bool promote_int, Error **errp); /* Must be set. */ void (*type_int64)(Visitor *v, const char *name, int64_t *obj, @@ -58,8 +59,6 @@ struct Visitor /* May be NULL; most useful for input visitors. */ void (*optional)(Visitor *v, const char *name, bool *present); - - bool (*start_union)(Visitor *v, bool data_present, Error **errp); }; void input_type_enum(Visitor *v, const char *name, int *obj, diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 5e581dcf7e..83cad74c88 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -19,26 +19,60 @@ #include "qapi/error.h" #include <stdlib.h> -typedef struct GenericList -{ - union { - void *value; - uint64_t padding; - }; +/* This struct is layout-compatible with all other *List structs + * created by the qapi generator. It is used as a typical + * singly-linked list. */ +typedef struct GenericList { struct GenericList *next; + char padding[]; } GenericList; +/* This struct is layout-compatible with all Alternate types + * created by the qapi generator. */ +typedef struct GenericAlternate { + QType type; + char padding[]; +} GenericAlternate; + void visit_start_struct(Visitor *v, const char *name, void **obj, size_t size, Error **errp); void visit_end_struct(Visitor *v, Error **errp); -void visit_start_implicit_struct(Visitor *v, void **obj, size_t size, - Error **errp); -void visit_end_implicit_struct(Visitor *v); void visit_start_list(Visitor *v, const char *name, Error **errp); -GenericList *visit_next_list(Visitor *v, GenericList **list); +GenericList *visit_next_list(Visitor *v, GenericList **list, size_t size); void visit_end_list(Visitor *v); +/* + * Start the visit of an alternate @obj with the given @size. + * + * @name specifies the relationship to the containing struct (ignored + * for a top level visit, the name of the key if this alternate is + * part of an object, or NULL if this alternate is part of a list). + * + * @obj must not be NULL. Input visitors will allocate @obj and + * determine the qtype of the next thing to be visited, stored in + * (*@obj)->type. Other visitors will leave @obj unchanged. + * + * If @promote_int, treat integers as QTYPE_FLOAT. + * + * If successful, this must be paired with visit_end_alternate(), even + * if visiting the contents of the alternate fails. + */ +void visit_start_alternate(Visitor *v, const char *name, + GenericAlternate **obj, size_t size, + bool promote_int, Error **errp); + +/* + * Finish visiting an alternate type. + * + * Must be called after a successful visit_start_alternate(), even if + * an error occurred in the meantime. + * + * TODO: Should all the visit_end_* interfaces take obj parameter, so + * that dealloc visitor need not track what was passed in visit_start? + */ +void visit_end_alternate(Visitor *v); + /** * Check if an optional member @name of an object needs visiting. * For input visitors, set *@present according to whether the @@ -47,14 +81,6 @@ void visit_end_list(Visitor *v); */ bool visit_optional(Visitor *v, const char *name, bool *present); -/** - * Determine the qtype of the item @name in the current object visit. - * For input visitors, set *@type to the correct qtype of a qapi - * alternate type; for other visitors, leave *@type unchanged. - * If @promote_int, treat integers as QTYPE_FLOAT. - */ -void visit_get_next_type(Visitor *v, const char *name, QType *type, - bool promote_int, Error **errp); void visit_type_enum(Visitor *v, const char *name, int *obj, const char *const strings[], Error **errp); void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp); @@ -80,6 +106,5 @@ void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp); void visit_type_number(Visitor *v, const char *name, double *obj, Error **errp); void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp); -bool visit_start_union(Visitor *v, bool data_present, Error **errp); #endif |