Commit 05372f70 authored by Eric Blake's avatar Eric Blake Committed by Markus Armbruster
Browse files

qapi: Consistent generated code: minimize push_indent() usage



We had some pointless differences in the generated code for visit,
command marshalling, and events; unifying them makes it easier for
future patches to consolidate to common helper functions.
This is one patch of a series to clean up these differences.

This patch reduces the number of push_indent()/pop_indent() pairs
so that generated code is typically already at its natural output
indentation in the python files.  It is easier to reason about
generated code if the reader does not have to track how much
spacing will be inserted alongside the code, and moreso when all
of the generators use the same patterns (qapi-type and qapi-event
were already using in-place indentation).

Arguably, the resulting python may be a bit harder to read with C
code at the same indentation as python; on the other hand, not
having to think about push_indent() is a win, and most decent
editors provide syntax highlighting that makes it easier to
visually distinguish python code from string literals that will
become C code.

There is no change to the generated output.

Signed-off-by: default avatarEric Blake <eblake@redhat.com>
Message-Id: <1443565276-4535-15-git-send-email-eblake@redhat.com>
Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
parent e36c714e
Loading
Loading
Loading
Loading
+22 −32
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ def gen_call(name, arg_type, ret_type):
    if ret_type:
        lhs = 'retval = '

    push_indent()
    ret = mcgen('''

    %(lhs)sqmp_%(c_name)s(%(args)s&err);
@@ -63,7 +62,6 @@ def gen_call(name, arg_type, ret_type):
    qmp_marshal_output_%(c_name)s(retval, ret, &err);
''',
                     c_name=ret_type.c_name())
    pop_indent()
    return ret


@@ -72,8 +70,6 @@ def gen_marshal_vars(arg_type, ret_type):
    Error *err = NULL;
''')

    push_indent()

    if ret_type:
        ret += mcgen('''
    %(c_type)s retval;
@@ -106,7 +102,6 @@ bool has_%(c_name)s = false;
    (void)args;
''')

    pop_indent()
    return ret


@@ -116,8 +111,6 @@ def gen_marshal_input_visit(arg_type, dealloc=False):
    if not arg_type:
        return ret

    push_indent()

    if dealloc:
        errparg = 'NULL'
        errarg = None
@@ -162,7 +155,6 @@ visit_type_%(c_type)s(v, &%(c_name)s, "%(name)s", %(errp)s);
        ret += mcgen('''
    qapi_dealloc_visitor_cleanup(qdv);
''')
    pop_indent()
    return ret


@@ -237,7 +229,6 @@ out:


def gen_register_command(name, success_response):
    push_indent()
    options = 'QCO_NO_OPTIONS'
    if not success_response:
        options = 'QCO_NO_SUCCESS_RESP'
@@ -247,7 +238,6 @@ qmp_register_command("%(name)s", qmp_marshal_%(c_name)s, %(opts)s);
''',
                name=name, c_name=c_name(name),
                opts=options)
    pop_indent()
    return ret


+11 −13
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e

''',
                 c_name=c_name(name))
    push_indent()

    if base:
        ret += mcgen('''
@@ -114,7 +113,6 @@ if (err) {
    }
''')

    pop_indent()
    if re.search('^ *goto out;', ret, re.MULTILINE):
        ret += mcgen('''