mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-06 18:05:37 +00:00
qapi: Generated code cleanup
Clean up white-space, brace placement, and superfluous #ifdef QAPI_TYPES_BUILTIN_CLEANUP_DEF. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
3f99144cd9
commit
3a864e7c52
|
@ -568,7 +568,6 @@ Example:
|
|||
visit_type_UserDefOne(v, &obj, NULL, NULL);
|
||||
qapi_dealloc_visitor_cleanup(md);
|
||||
}
|
||||
|
||||
$ cat qapi-generated/example-qapi-types.h
|
||||
[Uninteresting stuff omitted...]
|
||||
|
||||
|
@ -579,8 +578,7 @@ Example:
|
|||
|
||||
typedef struct UserDefOne UserDefOne;
|
||||
|
||||
typedef struct UserDefOneList
|
||||
{
|
||||
typedef struct UserDefOneList {
|
||||
union {
|
||||
UserDefOne *value;
|
||||
uint64_t padding;
|
||||
|
@ -588,10 +586,10 @@ Example:
|
|||
struct UserDefOneList *next;
|
||||
} UserDefOneList;
|
||||
|
||||
|
||||
[Functions on built-in types omitted...]
|
||||
|
||||
struct UserDefOne
|
||||
{
|
||||
struct UserDefOne {
|
||||
int64_t integer;
|
||||
char *string;
|
||||
};
|
||||
|
@ -629,6 +627,7 @@ Example:
|
|||
static void visit_type_UserDefOne_fields(Visitor *m, UserDefOne **obj, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
||||
visit_type_int(m, &(*obj)->integer, "integer", &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
|
@ -842,8 +841,7 @@ Example:
|
|||
void qapi_event_send_my_event(Error **errp);
|
||||
|
||||
extern const char *example_QAPIEvent_lookup[];
|
||||
typedef enum example_QAPIEvent
|
||||
{
|
||||
typedef enum example_QAPIEvent {
|
||||
EXAMPLE_QAPI_EVENT_MY_EVENT = 0,
|
||||
EXAMPLE_QAPI_EVENT_MAX = 1,
|
||||
} example_QAPIEvent;
|
||||
|
|
|
@ -218,6 +218,7 @@ def gen_marshal_input(name, args, ret_type, middle_mode):
|
|||
ret += mcgen('''
|
||||
|
||||
(void)args;
|
||||
|
||||
''')
|
||||
|
||||
ret += gen_sync_call(name, args, ret_type)
|
||||
|
|
|
@ -167,8 +167,7 @@ def generate_event_enum_decl(event_enum_name, event_enum_values):
|
|||
event_enum_name = event_enum_name)
|
||||
|
||||
enum_decl = mcgen('''
|
||||
typedef enum %(event_enum_name)s
|
||||
{
|
||||
typedef enum %(event_enum_name)s {
|
||||
''',
|
||||
event_enum_name = event_enum_name)
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
def generate_fwd_builtin(name):
|
||||
return mcgen('''
|
||||
|
||||
typedef struct %(name)sList
|
||||
{
|
||||
typedef struct %(name)sList {
|
||||
union {
|
||||
%(type)s value;
|
||||
uint64_t padding;
|
||||
|
@ -32,8 +31,7 @@ def generate_fwd_struct(name):
|
|||
|
||||
typedef struct %(name)s %(name)s;
|
||||
|
||||
typedef struct %(name)sList
|
||||
{
|
||||
typedef struct %(name)sList {
|
||||
union {
|
||||
%(name)s *value;
|
||||
uint64_t padding;
|
||||
|
@ -45,8 +43,8 @@ def generate_fwd_struct(name):
|
|||
|
||||
def generate_fwd_enum_struct(name):
|
||||
return mcgen('''
|
||||
typedef struct %(name)sList
|
||||
{
|
||||
|
||||
typedef struct %(name)sList {
|
||||
union {
|
||||
%(name)s value;
|
||||
uint64_t padding;
|
||||
|
@ -79,8 +77,8 @@ def generate_struct(expr):
|
|||
base = expr.get('base')
|
||||
|
||||
ret = mcgen('''
|
||||
struct %(name)s
|
||||
{
|
||||
|
||||
struct %(name)s {
|
||||
''',
|
||||
name=c_name(structname))
|
||||
|
||||
|
@ -105,7 +103,8 @@ def generate_struct(expr):
|
|||
|
||||
def generate_enum_lookup(name, values):
|
||||
ret = mcgen('''
|
||||
const char * const %(name)s_lookup[] = {
|
||||
|
||||
const char *const %(name)s_lookup[] = {
|
||||
''',
|
||||
name=c_name(name))
|
||||
for value in values:
|
||||
|
@ -119,7 +118,6 @@ def generate_enum_lookup(name, values):
|
|||
ret += mcgen('''
|
||||
[%(max_index)s] = NULL,
|
||||
};
|
||||
|
||||
''',
|
||||
max_index=max_index)
|
||||
return ret
|
||||
|
@ -127,13 +125,14 @@ def generate_enum_lookup(name, values):
|
|||
def generate_enum(name, values):
|
||||
name = c_name(name)
|
||||
lookup_decl = mcgen('''
|
||||
extern const char * const %(name)s_lookup[];
|
||||
|
||||
extern const char *const %(name)s_lookup[];
|
||||
''',
|
||||
name=name)
|
||||
|
||||
enum_decl = mcgen('''
|
||||
typedef enum %(name)s
|
||||
{
|
||||
|
||||
typedef enum %(name)s {
|
||||
''',
|
||||
name=name)
|
||||
|
||||
|
@ -155,7 +154,7 @@ def generate_enum(name, values):
|
|||
''',
|
||||
name=name)
|
||||
|
||||
return lookup_decl + enum_decl
|
||||
return enum_decl + lookup_decl
|
||||
|
||||
def generate_alternate_qtypes(expr):
|
||||
|
||||
|
@ -163,6 +162,7 @@ def generate_alternate_qtypes(expr):
|
|||
members = expr['data']
|
||||
|
||||
ret = mcgen('''
|
||||
|
||||
const int %(name)s_qtypes[QTYPE_MAX] = {
|
||||
''',
|
||||
name=c_name(name))
|
||||
|
@ -198,8 +198,8 @@ def generate_union(expr, meta):
|
|||
discriminator_type_name = '%sKind' % (name)
|
||||
|
||||
ret = mcgen('''
|
||||
struct %(name)s
|
||||
{
|
||||
|
||||
struct %(name)s {
|
||||
''',
|
||||
name=name)
|
||||
if base:
|
||||
|
@ -328,14 +328,12 @@ def generate_type_cleanup(name):
|
|||
#include "qapi/dealloc-visitor.h"
|
||||
#include "%(prefix)sqapi-types.h"
|
||||
#include "%(prefix)sqapi-visit.h"
|
||||
|
||||
''',
|
||||
prefix=prefix))
|
||||
|
||||
fdecl.write(mcgen('''
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
'''))
|
||||
|
||||
exprs = parse_schema(input_file)
|
||||
|
@ -346,22 +344,22 @@ def generate_type_cleanup(name):
|
|||
fdecl.write(guardend("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
|
||||
|
||||
for expr in exprs:
|
||||
ret = "\n"
|
||||
ret = ""
|
||||
if expr.has_key('struct'):
|
||||
ret += generate_fwd_struct(expr['struct'])
|
||||
elif expr.has_key('enum'):
|
||||
ret += generate_enum(expr['enum'], expr['data']) + "\n"
|
||||
ret += generate_enum(expr['enum'], expr['data'])
|
||||
ret += generate_fwd_enum_struct(expr['enum'])
|
||||
fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
|
||||
elif expr.has_key('union'):
|
||||
ret += generate_fwd_struct(expr['union']) + "\n"
|
||||
ret += generate_fwd_struct(expr['union'])
|
||||
enum_define = discriminator_find_enum_define(expr)
|
||||
if not enum_define:
|
||||
ret += generate_enum('%sKind' % expr['union'], expr['data'].keys())
|
||||
fdef.write(generate_enum_lookup('%sKind' % expr['union'],
|
||||
expr['data'].keys()))
|
||||
elif expr.has_key('alternate'):
|
||||
ret += generate_fwd_struct(expr['alternate']) + "\n"
|
||||
ret += generate_fwd_struct(expr['alternate'])
|
||||
ret += generate_enum('%sKind' % expr['alternate'], expr['data'].keys())
|
||||
fdef.write(generate_enum_lookup('%sKind' % expr['alternate'],
|
||||
expr['data'].keys()))
|
||||
|
@ -381,34 +379,32 @@ def generate_type_cleanup(name):
|
|||
# have the functions defined, so we use -b option to provide control
|
||||
# over these cases
|
||||
if do_builtins:
|
||||
fdef.write(guardstart("QAPI_TYPES_BUILTIN_CLEANUP_DEF"))
|
||||
for typename in builtin_types.keys():
|
||||
fdef.write(generate_type_cleanup(typename + "List"))
|
||||
fdef.write(guardend("QAPI_TYPES_BUILTIN_CLEANUP_DEF"))
|
||||
|
||||
for expr in exprs:
|
||||
ret = "\n"
|
||||
ret = ""
|
||||
if expr.has_key('struct'):
|
||||
ret += generate_struct(expr) + "\n"
|
||||
ret += generate_type_cleanup_decl(expr['struct'] + "List")
|
||||
fdef.write(generate_type_cleanup(expr['struct'] + "List") + "\n")
|
||||
fdef.write(generate_type_cleanup(expr['struct'] + "List"))
|
||||
ret += generate_type_cleanup_decl(expr['struct'])
|
||||
fdef.write(generate_type_cleanup(expr['struct']) + "\n")
|
||||
fdef.write(generate_type_cleanup(expr['struct']))
|
||||
elif expr.has_key('union'):
|
||||
ret += generate_union(expr, 'union')
|
||||
ret += generate_union(expr, 'union') + "\n"
|
||||
ret += generate_type_cleanup_decl(expr['union'] + "List")
|
||||
fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
|
||||
fdef.write(generate_type_cleanup(expr['union'] + "List"))
|
||||
ret += generate_type_cleanup_decl(expr['union'])
|
||||
fdef.write(generate_type_cleanup(expr['union']) + "\n")
|
||||
fdef.write(generate_type_cleanup(expr['union']))
|
||||
elif expr.has_key('alternate'):
|
||||
ret += generate_union(expr, 'alternate')
|
||||
ret += generate_union(expr, 'alternate') + "\n"
|
||||
ret += generate_type_cleanup_decl(expr['alternate'] + "List")
|
||||
fdef.write(generate_type_cleanup(expr['alternate'] + "List") + "\n")
|
||||
fdef.write(generate_type_cleanup(expr['alternate'] + "List"))
|
||||
ret += generate_type_cleanup_decl(expr['alternate'])
|
||||
fdef.write(generate_type_cleanup(expr['alternate']) + "\n")
|
||||
fdef.write(generate_type_cleanup(expr['alternate']))
|
||||
elif expr.has_key('enum'):
|
||||
ret += generate_type_cleanup_decl(expr['enum'] + "List")
|
||||
fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")
|
||||
ret += "\n" + generate_type_cleanup_decl(expr['enum'] + "List")
|
||||
fdef.write(generate_type_cleanup(expr['enum'] + "List"))
|
||||
else:
|
||||
continue
|
||||
fdecl.write(ret)
|
||||
|
|
|
@ -62,6 +62,7 @@ def generate_visit_struct_fields(name, members, base = None):
|
|||
static void visit_type_%(name)s_fields(Visitor *m, %(name)s **obj, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
||||
''',
|
||||
name=c_name(name))
|
||||
push_indent()
|
||||
|
|
Loading…
Reference in a new issue