summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-06-07 20:35:58 +0400
committerMarkus Armbruster <armbru@redhat.com>2017-06-20 14:31:31 +0200
commit01b2ffcedd94ad7b42bc870e4c6936c87ad03429 (patch)
tree39bbadfbbaa229bfbda245840a256fe0132b2390 /scripts
parent58634047b7deeab36e4b07c4744e44d698975561 (diff)
qapi: merge QInt and QFloat in QNum
We would like to use a same QObject type to represent numbers, whether they are int, uint, or floats. Getters will allow some compatibility between the various types if the number fits other representations. Add a few more tests while at it. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20170607163635.17635-7-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [parse_stats_intervals() simplified a bit, comment in test_visitor_in_int_overflow() tidied up, suppress bogus warnings] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/coccinelle/qobject.cocci4
-rw-r--r--scripts/qapi-visit.py2
-rw-r--r--scripts/qapi.py36
3 files changed, 20 insertions, 22 deletions
diff --git a/scripts/coccinelle/qobject.cocci b/scripts/coccinelle/qobject.cocci
index 97703a438b..c3253deb1b 100644
--- a/scripts/coccinelle/qobject.cocci
+++ b/scripts/coccinelle/qobject.cocci
@@ -6,7 +6,7 @@ expression Obj, Key, E;
- qdict_put_obj(Obj, Key, QOBJECT(E));
+ qdict_put(Obj, Key, E);
|
-- qdict_put(Obj, Key, qint_from_int(E));
+- qdict_put(Obj, Key, qnum_from_int(E));
+ qdict_put_int(Obj, Key, E);
|
- qdict_put(Obj, Key, qbool_from_bool(E));
@@ -24,7 +24,7 @@ expression Obj, E;
- qlist_append_obj(Obj, QOBJECT(E));
+ qlist_append(Obj, E);
|
-- qlist_append(Obj, qint_from_int(E));
+- qlist_append(Obj, qnum_from_int(E));
+ qlist_append_int(Obj, E);
|
- qlist_append(Obj, qbool_from_bool(E));
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 5737aefa05..cc447ecacc 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -164,7 +164,7 @@ def gen_visit_alternate(name, variants):
promote_int = 'true'
ret = ''
for var in variants.variants:
- if var.type.alternate_qtype() == 'QTYPE_QINT':
+ if var.type.alternate_qtype() == 'QTYPE_QNUM':
promote_int = 'false'
ret += mcgen('''
diff --git a/scripts/qapi.py b/scripts/qapi.py
index b7a25e4759..0de809f56b 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -21,18 +21,18 @@ from ordereddict import OrderedDict
builtin_types = {
'str': 'QTYPE_QSTRING',
- 'int': 'QTYPE_QINT',
- 'number': 'QTYPE_QFLOAT',
+ 'int': 'QTYPE_QNUM',
+ 'number': 'QTYPE_QNUM',
'bool': 'QTYPE_QBOOL',
- 'int8': 'QTYPE_QINT',
- 'int16': 'QTYPE_QINT',
- 'int32': 'QTYPE_QINT',
- 'int64': 'QTYPE_QINT',
- 'uint8': 'QTYPE_QINT',
- 'uint16': 'QTYPE_QINT',
- 'uint32': 'QTYPE_QINT',
- 'uint64': 'QTYPE_QINT',
- 'size': 'QTYPE_QINT',
+ 'int8': 'QTYPE_QNUM',
+ 'int16': 'QTYPE_QNUM',
+ 'int32': 'QTYPE_QNUM',
+ 'int64': 'QTYPE_QNUM',
+ 'uint8': 'QTYPE_QNUM',
+ 'uint16': 'QTYPE_QNUM',
+ 'uint32': 'QTYPE_QNUM',
+ 'uint64': 'QTYPE_QNUM',
+ 'size': 'QTYPE_QNUM',
'any': None, # any QType possible, actually
'QType': 'QTYPE_QSTRING',
}
@@ -820,11 +820,9 @@ def check_alternate(expr, info):
if v in ['on', 'off']:
conflicting.add('QTYPE_QBOOL')
if re.match(r'[-+0-9.]', v): # lazy, could be tightened
- conflicting.add('QTYPE_QINT')
- conflicting.add('QTYPE_QFLOAT')
+ conflicting.add('QTYPE_QNUM')
else:
- conflicting.add('QTYPE_QINT')
- conflicting.add('QTYPE_QFLOAT')
+ conflicting.add('QTYPE_QNUM')
conflicting.add('QTYPE_QBOOL')
if conflicting & set(types_seen):
raise QAPISemError(info, "Alternate '%s' member '%s' can't "
@@ -1059,8 +1057,8 @@ class QAPISchemaType(QAPISchemaEntity):
def alternate_qtype(self):
json2qtype = {
'string': 'QTYPE_QSTRING',
- 'number': 'QTYPE_QFLOAT',
- 'int': 'QTYPE_QINT',
+ 'number': 'QTYPE_QNUM',
+ 'int': 'QTYPE_QNUM',
'boolean': 'QTYPE_QBOOL',
'object': 'QTYPE_QDICT'
}
@@ -1522,9 +1520,9 @@ class QAPISchema(object):
self.the_empty_object_type = QAPISchemaObjectType(
'q_empty', None, None, None, [], None)
self._def_entity(self.the_empty_object_type)
- qtype_values = self._make_enum_members(['none', 'qnull', 'qint',
+ qtype_values = self._make_enum_members(['none', 'qnull', 'qnum',
'qstring', 'qdict', 'qlist',
- 'qfloat', 'qbool'])
+ 'qbool'])
self._def_entity(QAPISchemaEnumType('QType', None, None,
qtype_values, 'QTYPE'))