Commit 912ae9c8 authored by Michael S. Tsirkin's avatar Michael S. Tsirkin Committed by Luiz Capitulino
Browse files

qapi-types: add C99 index names to arrays



It's not easy to figure out how monitor translates
strings: most QEMU code deals with translated indexes,
these are translated using _lookup arrays,
so you need to find the array name, and find the
appropriate offset.

This patch adds C99 indexes to lookup arrays, which makes it possible to
find the correct key using simple grep, and see that the matching is
correct at a glance.

Example:

Before:

const char *MigrationCapability_lookup[] = {
    "xbzrle",
    "rdma-pin-all",
    "auto-converge",
    "zero-blocks",
    NULL,
};

After:

const char *MigrationCapability_lookup[] = {
    [MIGRATION_CAPABILITY_XBZRLE] = "xbzrle",
    [MIGRATION_CAPABILITY_RDMA_PIN_ALL] = "rdma-pin-all",
    [MIGRATION_CAPABILITY_AUTO_CONVERGE] = "auto-converge",
    [MIGRATION_CAPABILITY_ZERO_BLOCKS] = "zero-blocks",
    [MIGRATION_CAPABILITY_MAX] = NULL,
};

Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarLuiz Capitulino <lcapitulino@redhat.com>
parent 606ee8f5
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -123,16 +123,19 @@ const char *%(name)s_lookup[] = {
                         name=name)
    i = 0
    for value in values:
        index = generate_enum_full_value(name, value)
        ret += mcgen('''
    "%(value)s",
    [%(index)s] = "%(value)s",
''',
                     value=value)
                     index = index, value = value)

    max_index = generate_enum_full_value(name, 'MAX')
    ret += mcgen('''
    NULL,
    [%(max_index)s] = NULL,
};

''')
''',
        max_index=max_index)
    return ret

def generate_enum(name, values):