mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 01:05:36 +00:00
qapi: Create simple union type member earlier
For simple unions, we were creating the implicit 'type' tag member during the QAPISchemaObjectTypeVariants constructor. This is different from every other implicit QAPISchemaEntity object, which get created by QAPISchema methods. Hoist the creation to the caller (renaming _make_tag_enum() to _make_implicit_tag()), and pass the entity rather than the string name, so that we have the nice property that no entities are created as a side effect within a different entity. A later patch will then have an easier time of associating location info with each entity creation. No change to generated code. Backports commit 46292ba75c515baf733df18644052b2ce9492728 from qemu
This commit is contained in:
parent
b9b76f9b4b
commit
738fd1e5ad
|
@ -40,7 +40,7 @@ const char *const X86CPURegister32_lookup[] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
void qapi_free_ErrorClassList(ErrorClassList *obj)
|
||||
void qapi_free_DummyForceArrays(DummyForceArrays *obj)
|
||||
{
|
||||
QapiDeallocVisitor *qdv;
|
||||
Visitor *v;
|
||||
|
@ -51,7 +51,7 @@ void qapi_free_ErrorClassList(ErrorClassList *obj)
|
|||
|
||||
qdv = qapi_dealloc_visitor_new();
|
||||
v = qapi_dealloc_get_visitor(qdv);
|
||||
visit_type_ErrorClassList(v, &obj, NULL, NULL);
|
||||
visit_type_DummyForceArrays(v, &obj, NULL, NULL);
|
||||
qapi_dealloc_visitor_cleanup(qdv);
|
||||
}
|
||||
|
||||
|
@ -85,21 +85,6 @@ void qapi_free_X86CPUFeatureWordInfoList(X86CPUFeatureWordInfoList *obj)
|
|||
qapi_dealloc_visitor_cleanup(qdv);
|
||||
}
|
||||
|
||||
void qapi_free_X86CPURegister32List(X86CPURegister32List *obj)
|
||||
{
|
||||
QapiDeallocVisitor *qdv;
|
||||
Visitor *v;
|
||||
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
|
||||
qdv = qapi_dealloc_visitor_new();
|
||||
v = qapi_dealloc_get_visitor(qdv);
|
||||
visit_type_X86CPURegister32List(v, &obj, NULL, NULL);
|
||||
qapi_dealloc_visitor_cleanup(qdv);
|
||||
}
|
||||
|
||||
void qapi_free_anyList(anyList *obj)
|
||||
{
|
||||
QapiDeallocVisitor *qdv;
|
||||
|
|
|
@ -166,6 +166,8 @@ void qapi_free_uint8List(uint8List *obj);
|
|||
#endif /* QAPI_TYPES_BUILTIN */
|
||||
|
||||
|
||||
typedef struct DummyForceArrays DummyForceArrays;
|
||||
|
||||
typedef enum ErrorClass {
|
||||
ERROR_CLASS_GENERIC_ERROR = 0,
|
||||
ERROR_CLASS_COMMAND_NOT_FOUND = 1,
|
||||
|
@ -177,8 +179,6 @@ typedef enum ErrorClass {
|
|||
} ErrorClass;
|
||||
extern const char *const ErrorClass_lookup[];
|
||||
|
||||
typedef struct ErrorClassList ErrorClassList;
|
||||
|
||||
typedef struct X86CPUFeatureWordInfo X86CPUFeatureWordInfo;
|
||||
|
||||
typedef struct X86CPUFeatureWordInfoList X86CPUFeatureWordInfoList;
|
||||
|
@ -195,16 +195,10 @@ typedef enum X86CPURegister32 {
|
|||
X86_CPU_REGISTER32_MAX = 8,
|
||||
} X86CPURegister32;
|
||||
extern const char *const X86CPURegister32_lookup[];
|
||||
|
||||
typedef struct X86CPURegister32List X86CPURegister32List;
|
||||
struct ErrorClassList {
|
||||
union {
|
||||
ErrorClass value;
|
||||
uint64_t padding;
|
||||
};
|
||||
struct ErrorClassList *next;
|
||||
struct DummyForceArrays {
|
||||
X86CPUFeatureWordInfoList *unused;
|
||||
};
|
||||
void qapi_free_ErrorClassList(ErrorClassList *obj);
|
||||
void qapi_free_DummyForceArrays(DummyForceArrays *obj);
|
||||
struct X86CPUFeatureWordInfo {
|
||||
int64_t cpuid_input_eax;
|
||||
bool has_cpuid_input_ecx;
|
||||
|
@ -221,13 +215,5 @@ struct X86CPUFeatureWordInfoList {
|
|||
struct X86CPUFeatureWordInfoList *next;
|
||||
};
|
||||
void qapi_free_X86CPUFeatureWordInfoList(X86CPUFeatureWordInfoList *obj);
|
||||
struct X86CPURegister32List {
|
||||
union {
|
||||
X86CPURegister32 value;
|
||||
uint64_t padding;
|
||||
};
|
||||
struct X86CPURegister32List *next;
|
||||
};
|
||||
void qapi_free_X86CPURegister32List(X86CPURegister32List *obj);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,35 +16,39 @@
|
|||
#include "qemu-common.h"
|
||||
#include "qapi-visit.h"
|
||||
|
||||
void visit_type_ErrorClass(Visitor *v, ErrorClass *obj, const char *name, Error **errp)
|
||||
{
|
||||
visit_type_enum(v, (int *)obj, ErrorClass_lookup, "ErrorClass", name, errp);
|
||||
}
|
||||
|
||||
void visit_type_ErrorClassList(Visitor *v, ErrorClassList **obj, const char *name, Error **errp)
|
||||
static void visit_type_DummyForceArrays_fields(Visitor *v, DummyForceArrays **obj, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
GenericList *i, **prev;
|
||||
|
||||
visit_start_list(v, name, &err);
|
||||
visit_type_X86CPUFeatureWordInfoList(v, &(*obj)->unused, "unused", &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (prev = (GenericList **)obj;
|
||||
!err && (i = visit_next_list(v, prev)) != NULL;
|
||||
prev = &i) {
|
||||
ErrorClassList *native_i = (ErrorClassList *)i;
|
||||
visit_type_ErrorClass(v, &native_i->value, NULL, &err);
|
||||
}
|
||||
|
||||
error_propagate(errp, err);
|
||||
err = NULL;
|
||||
visit_end_list(v);
|
||||
out:
|
||||
error_propagate(errp, err);
|
||||
}
|
||||
|
||||
void visit_type_DummyForceArrays(Visitor *v, DummyForceArrays **obj, const char *name, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
||||
visit_start_struct(v, (void **)obj, "DummyForceArrays", name, sizeof(DummyForceArrays), &err);
|
||||
|
||||
if (!err) {
|
||||
if (*obj) {
|
||||
visit_type_DummyForceArrays_fields(v, obj, errp);
|
||||
}
|
||||
visit_end_struct(v, &err);
|
||||
}
|
||||
error_propagate(errp, err);
|
||||
}
|
||||
|
||||
void visit_type_ErrorClass(Visitor *v, ErrorClass *obj, const char *name, Error **errp)
|
||||
{
|
||||
visit_type_enum(v, (int *)obj, ErrorClass_lookup, "ErrorClass", name, errp);
|
||||
}
|
||||
|
||||
static void visit_type_X86CPUFeatureWordInfo_fields(Visitor *v, X86CPUFeatureWordInfo **obj, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
@ -120,30 +124,6 @@ void visit_type_X86CPURegister32(Visitor *v, X86CPURegister32 *obj, const char *
|
|||
visit_type_enum(v, (int *)obj, X86CPURegister32_lookup, "X86CPURegister32", name, errp);
|
||||
}
|
||||
|
||||
void visit_type_X86CPURegister32List(Visitor *v, X86CPURegister32List **obj, const char *name, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
GenericList *i, **prev;
|
||||
|
||||
visit_start_list(v, name, &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (prev = (GenericList **)obj;
|
||||
!err && (i = visit_next_list(v, prev)) != NULL;
|
||||
prev = &i) {
|
||||
X86CPURegister32List *native_i = (X86CPURegister32List *)i;
|
||||
visit_type_X86CPURegister32(v, &native_i->value, NULL, &err);
|
||||
}
|
||||
|
||||
error_propagate(errp, err);
|
||||
err = NULL;
|
||||
visit_end_list(v);
|
||||
out:
|
||||
error_propagate(errp, err);
|
||||
}
|
||||
|
||||
void visit_type_anyList(Visitor *v, anyList **obj, const char *name, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
|
|
@ -40,11 +40,10 @@ void visit_type_uint8List(Visitor *v, uint8List **obj, const char *name, Error *
|
|||
|
||||
#endif /* QAPI_VISIT_BUILTIN */
|
||||
|
||||
void visit_type_DummyForceArrays(Visitor *v, DummyForceArrays **obj, const char *name, Error **errp);
|
||||
void visit_type_ErrorClass(Visitor *v, ErrorClass *obj, const char *name, Error **errp);
|
||||
void visit_type_ErrorClassList(Visitor *v, ErrorClassList **obj, const char *name, Error **errp);
|
||||
void visit_type_X86CPUFeatureWordInfo(Visitor *v, X86CPUFeatureWordInfo **obj, const char *name, Error **errp);
|
||||
void visit_type_X86CPUFeatureWordInfoList(Visitor *v, X86CPUFeatureWordInfoList **obj, const char *name, Error **errp);
|
||||
void visit_type_X86CPURegister32(Visitor *v, X86CPURegister32 *obj, const char *name, Error **errp);
|
||||
void visit_type_X86CPURegister32List(Visitor *v, X86CPURegister32List **obj, const char *name, Error **errp);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1010,18 +1010,18 @@ class QAPISchemaObjectTypeMember(object):
|
|||
|
||||
|
||||
class QAPISchemaObjectTypeVariants(object):
|
||||
def __init__(self, tag_name, tag_enum, variants):
|
||||
assert tag_name is None or isinstance(tag_name, str)
|
||||
assert tag_enum is None or isinstance(tag_enum, str)
|
||||
def __init__(self, tag_name, tag_member, variants):
|
||||
# Flat unions pass tag_name but not tag_member.
|
||||
# Simple unions and alternates pass tag_member but not tag_name.
|
||||
# After check(), tag_member is always set, and tag_name remains
|
||||
# a reliable witness of being used by a flat union.
|
||||
assert bool(tag_member) != bool(tag_name)
|
||||
assert (isinstance(tag_name, str) or
|
||||
isinstance(tag_member, QAPISchemaObjectTypeMember))
|
||||
for v in variants:
|
||||
assert isinstance(v, QAPISchemaObjectTypeVariant)
|
||||
self.tag_name = tag_name
|
||||
if tag_name:
|
||||
assert not tag_enum
|
||||
self.tag_member = None
|
||||
else:
|
||||
self.tag_member = QAPISchemaObjectTypeMember('type', tag_enum,
|
||||
False)
|
||||
self.tag_member = tag_member
|
||||
self.variants = variants
|
||||
|
||||
def check(self, schema, members, seen):
|
||||
|
@ -1230,28 +1230,29 @@ class QAPISchema(object):
|
|||
[self._make_member('data', typ)])
|
||||
return QAPISchemaObjectTypeVariant(case, typ)
|
||||
|
||||
def _make_tag_enum(self, type_name, variants):
|
||||
return self._make_implicit_enum_type(type_name,
|
||||
[v.name for v in variants])
|
||||
def _make_implicit_tag(self, type_name, variants):
|
||||
typ = self._make_implicit_enum_type(type_name,
|
||||
[v.name for v in variants])
|
||||
return QAPISchemaObjectTypeMember('type', typ, False)
|
||||
|
||||
def _def_union_type(self, expr, info):
|
||||
name = expr['union']
|
||||
data = expr['data']
|
||||
base = expr.get('base')
|
||||
tag_name = expr.get('discriminator')
|
||||
tag_enum = None
|
||||
tag_member = None
|
||||
if tag_name:
|
||||
variants = [self._make_variant(key, value)
|
||||
for (key, value) in data.iteritems()]
|
||||
else:
|
||||
variants = [self._make_simple_variant(key, value)
|
||||
for (key, value) in data.iteritems()]
|
||||
tag_enum = self._make_tag_enum(name, variants)
|
||||
tag_member = self._make_implicit_tag(name, variants)
|
||||
self._def_entity(
|
||||
QAPISchemaObjectType(name, info, base,
|
||||
self._make_members(OrderedDict()),
|
||||
QAPISchemaObjectTypeVariants(tag_name,
|
||||
tag_enum,
|
||||
tag_member,
|
||||
variants)))
|
||||
|
||||
def _def_alternate_type(self, expr, info):
|
||||
|
@ -1259,11 +1260,11 @@ class QAPISchema(object):
|
|||
data = expr['data']
|
||||
variants = [self._make_variant(key, value)
|
||||
for (key, value) in data.iteritems()]
|
||||
tag_enum = self._make_tag_enum(name, variants)
|
||||
tag_member = self._make_implicit_tag(name, variants)
|
||||
self._def_entity(
|
||||
QAPISchemaAlternateType(name, info,
|
||||
QAPISchemaObjectTypeVariants(None,
|
||||
tag_enum,
|
||||
tag_member,
|
||||
variants)))
|
||||
|
||||
def _def_command(self, expr, info):
|
||||
|
|
Loading…
Reference in a new issue