mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 17:23:56 -06:00
qapi-visit: Add visitor.type classification
We have three classes of QAPI visitors: input, output, and dealloc. Currently, all implementations of these visitors have one thing in common based on their visitor type: the implementation used for the visit_type_enum() callback. But since we plan to add more such common behavior, in relation to documenting and further refining the semantics, it makes more sense to have the visitor implementations advertise which class they belong to, so the common qapi-visit-core code can use that information in multiple places. A later patch will better document the types of visitors directly in visitor.h. For this patch, knowing the class of a visitor implementation lets us make input_type_enum() and output_type_enum() become static functions, by replacing the callback function Visitor.type_enum() with the simpler enum member Visitor.type. Share a common assertion in qapi-visit-core as part of the refactoring. Move comments in opts-visitor.c to match the refactored layout. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1461879932-9020-2-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
bfc766d38e
commit
983f52d4b3
9 changed files with 52 additions and 42 deletions
|
@ -317,6 +317,11 @@ opts_type_str(Visitor *v, const char *name, char **obj, Error **errp)
|
|||
return;
|
||||
}
|
||||
*obj = g_strdup(opt->str ? opt->str : "");
|
||||
/* Note that we consume a string even if this is called as part of
|
||||
* an enum visit that later fails because the string is not a
|
||||
* valid enum value; this is harmless because tracking what gets
|
||||
* consumed only matters to visit_end_struct() as the final error
|
||||
* check if there were no other failures during the visit. */
|
||||
processed(ov, name);
|
||||
}
|
||||
|
||||
|
@ -507,6 +512,8 @@ opts_visitor_new(const QemuOpts *opts)
|
|||
|
||||
ov = g_malloc0(sizeof *ov);
|
||||
|
||||
ov->visitor.type = VISITOR_INPUT;
|
||||
|
||||
ov->visitor.start_struct = &opts_start_struct;
|
||||
ov->visitor.end_struct = &opts_end_struct;
|
||||
|
||||
|
@ -514,16 +521,6 @@ opts_visitor_new(const QemuOpts *opts)
|
|||
ov->visitor.next_list = &opts_next_list;
|
||||
ov->visitor.end_list = &opts_end_list;
|
||||
|
||||
/* input_type_enum() covers both "normal" enums and union discriminators.
|
||||
* The union discriminator field is always generated as "type"; it should
|
||||
* match the "type" QemuOpt child of any QemuOpts.
|
||||
*
|
||||
* input_type_enum() will remove the looked-up key from the
|
||||
* "unprocessed_opts" hash even if the lookup fails, because the removal is
|
||||
* done earlier in opts_type_str(). This should be harmless.
|
||||
*/
|
||||
ov->visitor.type_enum = &input_type_enum;
|
||||
|
||||
ov->visitor.type_int64 = &opts_type_int64;
|
||||
ov->visitor.type_uint64 = &opts_type_uint64;
|
||||
ov->visitor.type_size = &opts_type_size;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue