qapi: Generate FOO_str() macro for QAPI enum FOO

The next commit will put it to use.  May look pointless now, but we're
going to change the FOO_lookup's type, and then it'll help.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1503564371-26090-13-git-send-email-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Markus Armbruster 2017-08-24 10:46:07 +02:00
parent 1c236ba531
commit 5b5f825d44
25 changed files with 19 additions and 20 deletions

View File

@ -42,7 +42,6 @@
#include "qapi-event.h"
#include "qemu/cutils.h"
#include "qemu/id.h"
#include "qapi/util.h"
#ifdef CONFIG_BSD
#include <sys/ioctl.h>

View File

@ -32,7 +32,6 @@
#include "qapi/qmp/qbool.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qstring.h"
#include "qapi/util.h"
#include "sysemu/qtest.h"
typedef struct BDRVBlkdebugState {

View File

@ -31,7 +31,6 @@
#include "block/thread-pool.h"
#include "qemu/iov.h"
#include "block/raw-aio.h"
#include "qapi/util.h"
#include "qapi/qmp/qstring.h"
#if defined(__APPLE__) && (__MACH__)

View File

@ -31,7 +31,6 @@
#include "block/thread-pool.h"
#include "qemu/iov.h"
#include "qapi/qmp/qstring.h"
#include "qapi/util.h"
#include <windows.h>
#include <winioctl.h>

View File

@ -12,7 +12,6 @@
#include "block/block_int.h"
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
#include "qapi/util.h"
#include "qemu/uri.h"
#include "qemu/error-report.h"
#include "qemu/cutils.h"

View File

@ -35,7 +35,6 @@
#include "qemu/module.h"
#include "qemu/bswap.h"
#include "qemu/bitmap.h"
#include "qapi/util.h"
/**************************************************************/

View File

@ -30,7 +30,6 @@
#include "qemu/error-report.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qmp/qbool.h"
#include "qapi/util.h"
#include "qapi/qmp/types.h"
#include "qapi-event.h"
#include "trace.h"

View File

@ -22,7 +22,6 @@
#include "qapi/qmp/qjson.h"
#include "qapi/qmp/qlist.h"
#include "qapi/qmp/qstring.h"
#include "qapi/util.h"
#include "qapi-event.h"
#include "crypto/hash.h"

View File

@ -44,7 +44,6 @@
#include "qapi-visit.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qobject-output-visitor.h"
#include "qapi/util.h"
#include "sysemu/sysemu.h"
#include "block/block_int.h"
#include "qmp-commands.h"

View File

@ -20,7 +20,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/util.h"
#include "qemu/bswap.h"
#include "crypto/block-luks.h"

View File

@ -1275,6 +1275,9 @@ Example:
EXAMPLE_QAPI_EVENT__MAX = 1,
} example_QAPIEvent;
#define example_QAPIEvent_str(val) \
qapi_enum_lookup(example_QAPIEvent_lookup, (val))
extern const char *const example_QAPIEvent_lookup[];
#endif

1
hmp.c
View File

@ -31,7 +31,6 @@
#include "qapi/qmp/qerror.h"
#include "qapi/string-input-visitor.h"
#include "qapi/string-output-visitor.h"
#include "qapi/util.h"
#include "qapi-visit.h"
#include "qom/object_interfaces.h"
#include "ui/console.h"

View File

@ -11,6 +11,7 @@
#ifndef QAPI_UTIL_H
#define QAPI_UTIL_H
const char *qapi_enum_lookup(const char *const lookup[], int val);
int qapi_enum_parse(const char * const lookup[], const char *buf,
int def, Error **errp);

View File

@ -14,7 +14,6 @@
#include "qemu/cutils.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "qapi/util.h"
#include "migration.h"
#include "migration/global_state.h"
#include "migration/vmstate.h"

View File

@ -31,7 +31,6 @@
#include "migration/vmstate.h"
#include "block/block.h"
#include "qapi/qmp/qerror.h"
#include "qapi/util.h"
#include "qemu/rcu.h"
#include "block.h"
#include "postcopy-ram.h"

View File

@ -13,7 +13,13 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
#include "qapi/util.h"
const char *qapi_enum_lookup(const char *const lookup[], int val)
{
assert(val >= 0);
return lookup[val];
}
int qapi_enum_parse(const char * const lookup[], const char *buf,
int def, Error **errp)

View File

@ -14,7 +14,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/util.h"
#include "qemu-common.h"
#include "qapi/qmp/qobject.h"
#include "qapi/qmp/qerror.h"

View File

@ -26,7 +26,6 @@
#include "qemu-version.h"
#include "qapi/error.h"
#include "qapi/util.h"
#include "qapi-visit.h"
#include "qapi/qobject-output-visitor.h"
#include "qapi/qmp/qerror.h"

View File

@ -34,7 +34,6 @@
#include "qemu/log.h"
#include "qemu/systemd.h"
#include "block/snapshot.h"
#include "qapi/util.h"
#include "qapi/qmp/qstring.h"
#include "qom/object_interfaces.h"
#include "io/channel-socket.h"

View File

@ -217,6 +217,7 @@ def visit_event(self, name, info, arg_type, boxed):
fdecl.write(mcgen('''
#include "qapi/error.h"
#include "qapi/util.h"
#include "qapi/qmp/qdict.h"
#include "%(prefix)sqapi-types.h"

View File

@ -292,6 +292,10 @@ def visit_alternate_type(self, name, info, variants):
''',
prefix=prefix))
fdecl.write(mcgen('''
#include "qapi/util.h"
'''))
schema = QAPISchema(input_file)
gen = QAPISchemaGenTypeVisitor()
schema.visit(gen)

View File

@ -1894,6 +1894,9 @@ def gen_enum(name, values, prefix=None):
ret += mcgen('''
#define %(c_name)s_str(val) \\
qapi_enum_lookup(%(c_name)s_lookup, (val))
extern const char *const %(c_name)s_lookup[];
''',
c_name=c_name(name))

View File

@ -12,7 +12,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/util.h"
#include "test-qapi-types.h"
static void test_qapi_enum_parse(void)

1
tpm.c
View File

@ -14,7 +14,6 @@
#include "qemu/osdep.h"
#include "qapi/qmp/qerror.h"
#include "qapi/util.h"
#include "sysemu/tpm_backend.h"
#include "sysemu/tpm.h"
#include "qemu/config-file.h"

View File

@ -82,7 +82,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qapi/qmp/qstring.h"
#include "qapi/util.h"
#include "qemu/cutils.h"
#include "qemu/option.h"