qapi: Introduce a first class 'null' type

I expect the 'null' type to be useful mostly for members of alternate
types.

Backports commit 4d2d5c41a9e8ee201cda8be8701f7f9fc92e71aa from qemu
This commit is contained in:
Markus Armbruster 2018-03-07 16:52:39 -05:00 committed by Lioncash
parent 4a7abec7c9
commit 615e361cf2
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7
3 changed files with 7 additions and 3 deletions

View File

@ -99,9 +99,9 @@ static inline QType qobject_type(const QObject *obj)
return obj->type;
}
typedef struct QNull {
struct QNull {
QObject base;
} QNull;
};
extern QNull qnull_;

View File

@ -73,6 +73,7 @@ typedef struct QBool QBool;
typedef struct QDict QDict;
typedef struct QList QList;
typedef struct QNum QNum;
typedef struct QNull QNull;
typedef struct QObject QObject;
typedef struct QString QString;
typedef struct RAMBlock RAMBlock;

View File

@ -28,6 +28,7 @@ except ImportError:
from io import StringIO
builtin_types = {
'null': 'QTYPE_QNULL',
'str': 'QTYPE_QSTRING',
'int': 'QTYPE_QNUM',
'number': 'QTYPE_QNUM',
@ -1064,6 +1065,7 @@ class QAPISchemaType(QAPISchemaEntity):
def alternate_qtype(self):
json2qtype = {
'null': 'QTYPE_QNULL',
'string': 'QTYPE_QSTRING',
'number': 'QTYPE_QNUM',
'int': 'QTYPE_QNUM',
@ -1523,7 +1525,8 @@ class QAPISchema(object):
('uint64', 'int', 'uint64_t'),
('size', 'int', 'uint64_t'),
('bool', 'boolean', 'bool'),
('any', 'value', 'QObject' + pointer_suffix)]:
('any', 'value', 'QObject' + pointer_suffix),
('null', 'null', 'QNull' + pointer_suffix)]:
self._def_builtin_type(*t)
self.the_empty_object_type = QAPISchemaObjectType(
'q_empty', None, None, None, [], None)