mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-24 02:05:40 +00:00
qapi: Generated code cleanup
Clean up white-space, brace placement, and superfluous #ifdef QAPI_TYPES_BUILTIN_CLEANUP_DEF. Backports commit 3a864e7c52af15017d5082a9ee39a7919f46d2b5 from qemu
This commit is contained in:
parent
c5e8b70b5a
commit
46cf5ed6ae
|
@ -167,8 +167,7 @@ extern const char *%(event_enum_name)s_lookup[];
|
||||||
event_enum_name = event_enum_name)
|
event_enum_name = event_enum_name)
|
||||||
|
|
||||||
enum_decl = mcgen('''
|
enum_decl = mcgen('''
|
||||||
typedef enum %(event_enum_name)s
|
typedef enum %(event_enum_name)s {
|
||||||
{
|
|
||||||
''',
|
''',
|
||||||
event_enum_name = event_enum_name)
|
event_enum_name = event_enum_name)
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,7 @@ from qapi import *
|
||||||
def generate_fwd_builtin(name):
|
def generate_fwd_builtin(name):
|
||||||
return mcgen('''
|
return mcgen('''
|
||||||
|
|
||||||
typedef struct %(name)sList
|
typedef struct %(name)sList {
|
||||||
{
|
|
||||||
union {
|
union {
|
||||||
%(type)s value;
|
%(type)s value;
|
||||||
uint64_t padding;
|
uint64_t padding;
|
||||||
|
@ -32,8 +31,7 @@ def generate_fwd_struct(name):
|
||||||
|
|
||||||
typedef struct %(name)s %(name)s;
|
typedef struct %(name)s %(name)s;
|
||||||
|
|
||||||
typedef struct %(name)sList
|
typedef struct %(name)sList {
|
||||||
{
|
|
||||||
union {
|
union {
|
||||||
%(name)s *value;
|
%(name)s *value;
|
||||||
uint64_t padding;
|
uint64_t padding;
|
||||||
|
@ -45,8 +43,7 @@ typedef struct %(name)sList
|
||||||
|
|
||||||
def generate_fwd_enum_struct(name):
|
def generate_fwd_enum_struct(name):
|
||||||
return mcgen('''
|
return mcgen('''
|
||||||
typedef struct %(name)sList
|
typedef struct %(name)sList {
|
||||||
{
|
|
||||||
union {
|
union {
|
||||||
%(name)s value;
|
%(name)s value;
|
||||||
uint64_t padding;
|
uint64_t padding;
|
||||||
|
@ -79,8 +76,7 @@ def generate_struct(expr):
|
||||||
base = expr.get('base')
|
base = expr.get('base')
|
||||||
|
|
||||||
ret = mcgen('''
|
ret = mcgen('''
|
||||||
struct %(name)s
|
struct %(name)s {
|
||||||
{
|
|
||||||
''',
|
''',
|
||||||
name=c_name(structname))
|
name=c_name(structname))
|
||||||
|
|
||||||
|
@ -105,7 +101,7 @@ struct %(name)s
|
||||||
|
|
||||||
def generate_enum_lookup(name, values):
|
def generate_enum_lookup(name, values):
|
||||||
ret = mcgen('''
|
ret = mcgen('''
|
||||||
const char * const %(name)s_lookup[] = {
|
const char *const %(name)s_lookup[] = {
|
||||||
''',
|
''',
|
||||||
name=c_name(name))
|
name=c_name(name))
|
||||||
for value in values:
|
for value in values:
|
||||||
|
@ -117,20 +113,18 @@ const char * const %(name)s_lookup[] = {
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
''')
|
''')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def generate_enum(name, values):
|
def generate_enum(name, values):
|
||||||
name = c_name(name)
|
name = c_name(name)
|
||||||
lookup_decl = mcgen('''
|
lookup_decl = mcgen('''
|
||||||
extern const char * const %(name)s_lookup[];
|
extern const char *const %(name)s_lookup[];
|
||||||
''',
|
''',
|
||||||
name=name)
|
name=name)
|
||||||
|
|
||||||
enum_decl = mcgen('''
|
enum_decl = mcgen('''
|
||||||
typedef enum %(name)s
|
typedef enum %(name)s {
|
||||||
{
|
|
||||||
''',
|
''',
|
||||||
name=name)
|
name=name)
|
||||||
|
|
||||||
|
@ -152,7 +146,7 @@ typedef enum %(name)s
|
||||||
''',
|
''',
|
||||||
name=name)
|
name=name)
|
||||||
|
|
||||||
return lookup_decl + enum_decl
|
return enum_decl + lookup_decl
|
||||||
|
|
||||||
def generate_alternate_qtypes(expr):
|
def generate_alternate_qtypes(expr):
|
||||||
|
|
||||||
|
@ -160,6 +154,7 @@ def generate_alternate_qtypes(expr):
|
||||||
members = expr['data']
|
members = expr['data']
|
||||||
|
|
||||||
ret = mcgen('''
|
ret = mcgen('''
|
||||||
|
|
||||||
const int %(name)s_qtypes[QTYPE_MAX] = {
|
const int %(name)s_qtypes[QTYPE_MAX] = {
|
||||||
''',
|
''',
|
||||||
name=c_name(name))
|
name=c_name(name))
|
||||||
|
@ -196,8 +191,7 @@ def generate_union(expr, meta):
|
||||||
discriminator_type_name = '%sKind' % (name)
|
discriminator_type_name = '%sKind' % (name)
|
||||||
|
|
||||||
ret = mcgen('''
|
ret = mcgen('''
|
||||||
struct %(name)s
|
struct %(name)s {
|
||||||
{
|
|
||||||
''',
|
''',
|
||||||
name=name)
|
name=name)
|
||||||
if base:
|
if base:
|
||||||
|
@ -325,7 +319,6 @@ fdef.write(mcgen('''
|
||||||
#include "qapi/dealloc-visitor.h"
|
#include "qapi/dealloc-visitor.h"
|
||||||
#include "%(prefix)sqapi-types.h"
|
#include "%(prefix)sqapi-types.h"
|
||||||
#include "%(prefix)sqapi-visit.h"
|
#include "%(prefix)sqapi-visit.h"
|
||||||
|
|
||||||
''',
|
''',
|
||||||
prefix=prefix))
|
prefix=prefix))
|
||||||
|
|
||||||
|
@ -341,22 +334,22 @@ for typename in builtin_types.keys():
|
||||||
fdecl.write(guardend("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
|
fdecl.write(guardend("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
|
||||||
|
|
||||||
for expr in exprs:
|
for expr in exprs:
|
||||||
ret = "\n"
|
ret = ""
|
||||||
if expr.has_key('struct'):
|
if expr.has_key('struct'):
|
||||||
ret += generate_fwd_struct(expr['struct'])
|
ret += generate_fwd_struct(expr['struct'])
|
||||||
elif expr.has_key('enum'):
|
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'])
|
ret += generate_fwd_enum_struct(expr['enum'])
|
||||||
fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
|
fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
|
||||||
elif expr.has_key('union'):
|
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)
|
enum_define = discriminator_find_enum_define(expr)
|
||||||
if not enum_define:
|
if not enum_define:
|
||||||
ret += generate_enum('%sKind' % expr['union'], expr['data'].keys())
|
ret += generate_enum('%sKind' % expr['union'], expr['data'].keys())
|
||||||
fdef.write(generate_enum_lookup('%sKind' % expr['union'],
|
fdef.write(generate_enum_lookup('%sKind' % expr['union'],
|
||||||
expr['data'].keys()))
|
expr['data'].keys()))
|
||||||
elif expr.has_key('alternate'):
|
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())
|
ret += generate_enum('%sKind' % expr['alternate'], expr['data'].keys())
|
||||||
fdef.write(generate_enum_lookup('%sKind' % expr['alternate'],
|
fdef.write(generate_enum_lookup('%sKind' % expr['alternate'],
|
||||||
expr['data'].keys()))
|
expr['data'].keys()))
|
||||||
|
@ -376,34 +369,32 @@ fdecl.write(guardend("QAPI_TYPES_BUILTIN_CLEANUP_DECL"))
|
||||||
# have the functions defined, so we use -b option to provide control
|
# have the functions defined, so we use -b option to provide control
|
||||||
# over these cases
|
# over these cases
|
||||||
if do_builtins:
|
if do_builtins:
|
||||||
fdef.write(guardstart("QAPI_TYPES_BUILTIN_CLEANUP_DEF"))
|
|
||||||
for typename in builtin_types.keys():
|
for typename in builtin_types.keys():
|
||||||
fdef.write(generate_type_cleanup(typename + "List"))
|
fdef.write(generate_type_cleanup(typename + "List"))
|
||||||
fdef.write(guardend("QAPI_TYPES_BUILTIN_CLEANUP_DEF"))
|
|
||||||
|
|
||||||
for expr in exprs:
|
for expr in exprs:
|
||||||
ret = "\n"
|
ret = ""
|
||||||
if expr.has_key('struct'):
|
if expr.has_key('struct'):
|
||||||
ret += generate_struct(expr) + "\n"
|
ret += generate_struct(expr) + "\n"
|
||||||
ret += generate_type_cleanup_decl(expr['struct'] + "List")
|
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'])
|
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'):
|
elif expr.has_key('union'):
|
||||||
ret += generate_union(expr, 'union')
|
ret += generate_union(expr, 'union') + "\n"
|
||||||
ret += generate_type_cleanup_decl(expr['union'] + "List")
|
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'])
|
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'):
|
elif expr.has_key('alternate'):
|
||||||
ret += generate_union(expr, 'alternate')
|
ret += generate_union(expr, 'alternate') + "\n"
|
||||||
ret += generate_type_cleanup_decl(expr['alternate'] + "List")
|
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'])
|
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'):
|
elif expr.has_key('enum'):
|
||||||
ret += generate_type_cleanup_decl(expr['enum'] + "List")
|
ret += "\n" + generate_type_cleanup_decl(expr['enum'] + "List")
|
||||||
fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")
|
fdef.write(generate_type_cleanup(expr['enum'] + "List"))
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
fdecl.write(ret)
|
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)
|
static void visit_type_%(name)s_fields(Visitor *m, %(name)s **obj, Error **errp)
|
||||||
{
|
{
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
|
||||||
''',
|
''',
|
||||||
name=c_name(name))
|
name=c_name(name))
|
||||||
push_indent()
|
push_indent()
|
||||||
|
|
Loading…
Reference in a new issue