mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 18:55:49 +00:00
qapi: Consistent generated code: prefer common indentation
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 adjusts gen_visit_union() to use the same indentation as other functions, namely, by jumping early to the error label if the object was not set rather than placing the rest of the body inside an if for when it is set. No change in semantics to the generated code. Backports commit e36c714e6aad7c9266132350833e2f263f6d8874 from qemu
This commit is contained in:
parent
53c2c709af
commit
ec89e19b30
|
@ -262,16 +262,18 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error
|
||||||
if (err) {
|
if (err) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (*obj) {
|
if (!*obj) {
|
||||||
|
goto out_obj;
|
||||||
|
}
|
||||||
''',
|
''',
|
||||||
c_name=c_name(name), name=name)
|
c_name=c_name(name), name=name)
|
||||||
|
|
||||||
if base:
|
if base:
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
visit_type_%(c_name)s_fields(v, obj, &err);
|
visit_type_%(c_name)s_fields(v, obj, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto out_obj;
|
goto out_obj;
|
||||||
}
|
}
|
||||||
''',
|
''',
|
||||||
c_name=c_name(name))
|
c_name=c_name(name))
|
||||||
|
|
||||||
|
@ -280,14 +282,14 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error
|
||||||
# we pointlessly use a different key for simple unions
|
# we pointlessly use a different key for simple unions
|
||||||
tag_key = 'type'
|
tag_key = 'type'
|
||||||
ret += mcgen('''
|
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);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto out_obj;
|
goto out_obj;
|
||||||
}
|
}
|
||||||
if (!visit_start_union(v, !!(*obj)->data, &err) || err) {
|
if (!visit_start_union(v, !!(*obj)->data, &err) || err) {
|
||||||
goto out_obj;
|
goto out_obj;
|
||||||
}
|
}
|
||||||
switch ((*obj)->%(c_name)s) {
|
switch ((*obj)->%(c_name)s) {
|
||||||
''',
|
''',
|
||||||
c_type=variants.tag_member.type.c_name(),
|
c_type=variants.tag_member.type.c_name(),
|
||||||
# TODO ugly special case for simple union
|
# TODO ugly special case for simple union
|
||||||
|
@ -300,38 +302,37 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error
|
||||||
# TODO ugly special case for simple union
|
# TODO ugly special case for simple union
|
||||||
simple_union_type = var.simple_union_type()
|
simple_union_type = var.simple_union_type()
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
case %(case)s:
|
case %(case)s:
|
||||||
''',
|
''',
|
||||||
case=c_enum_const(variants.tag_member.type.name,
|
case=c_enum_const(variants.tag_member.type.name,
|
||||||
var.name))
|
var.name))
|
||||||
if simple_union_type:
|
if simple_union_type:
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "data", &err);
|
visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "data", &err);
|
||||||
''',
|
''',
|
||||||
c_type=simple_union_type.c_name(),
|
c_type=simple_union_type.c_name(),
|
||||||
c_name=c_name(var.name))
|
c_name=c_name(var.name))
|
||||||
else:
|
else:
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
visit_type_implicit_%(c_type)s(v, &(*obj)->%(c_name)s, &err);
|
visit_type_implicit_%(c_type)s(v, &(*obj)->%(c_name)s, &err);
|
||||||
''',
|
''',
|
||||||
c_type=var.type.c_name(),
|
c_type=var.type.c_name(),
|
||||||
c_name=c_name(var.name))
|
c_name=c_name(var.name))
|
||||||
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
break;
|
break;
|
||||||
''')
|
''')
|
||||||
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
|
||||||
out_obj:
|
|
||||||
error_propagate(errp, err);
|
|
||||||
err = NULL;
|
|
||||||
visit_end_union(v, !!(*obj)->data, &err);
|
|
||||||
error_propagate(errp, err);
|
|
||||||
err = NULL;
|
|
||||||
}
|
}
|
||||||
|
out_obj:
|
||||||
|
error_propagate(errp, err);
|
||||||
|
err = NULL;
|
||||||
|
visit_end_union(v, !!(*obj)->data, &err);
|
||||||
|
error_propagate(errp, err);
|
||||||
|
err = NULL;
|
||||||
visit_end_struct(v, &err);
|
visit_end_struct(v, &err);
|
||||||
out:
|
out:
|
||||||
error_propagate(errp, err);
|
error_propagate(errp, err);
|
||||||
|
|
Loading…
Reference in a new issue