diff options
author | Eric Blake <eblake@redhat.com> | 2015-09-29 16:21:12 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-10-12 18:46:49 +0200 |
commit | 05372f708a8cb3556e4d67458de79417dadf241f (patch) | |
tree | c69355a75b390f831b438b4004774a0ea84e0b42 /scripts/qapi-visit.py | |
parent | e36c714e6aad7c9266132350833e2f263f6d8874 (diff) |
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: Eric Blake <eblake@redhat.com>
Message-Id: <1443565276-4535-15-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts/qapi-visit.py')
-rw-r--r-- | scripts/qapi-visit.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index fe9780e0fa..78ad5560d0 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -77,28 +77,27 @@ 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(''' -visit_type_implicit_%(c_type)s(v, &(*obj)->%(c_name)s, &err); -if (err) { - goto out; -} + visit_type_implicit_%(c_type)s(v, &(*obj)->%(c_name)s, &err); + if (err) { + goto out; + } ''', c_type=base.c_name(), c_name=c_name('base')) for memb in members: if memb.optional: ret += mcgen(''' -visit_optional(v, &(*obj)->has_%(c_name)s, "%(name)s", &err); -if (!err && (*obj)->has_%(c_name)s) { + visit_optional(v, &(*obj)->has_%(c_name)s, "%(name)s", &err); + if (!err && (*obj)->has_%(c_name)s) { ''', c_name=c_name(memb.name), name=memb.name) push_indent() ret += mcgen(''' -visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err); + visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err); ''', c_type=memb.type.c_name(), c_name=c_name(memb.name), name=memb.name) @@ -106,15 +105,14 @@ visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err); if memb.optional: pop_indent() ret += mcgen(''' -} + } ''') ret += mcgen(''' -if (err) { - goto out; -} + if (err) { + goto out; + } ''') - pop_indent() if re.search('^ *goto out;', ret, re.MULTILINE): ret += mcgen(''' |