[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 1/7] qapi: Allow decimal values
From: |
Fam Zheng |
Subject: |
[Qemu-devel] [RFC PATCH v2 1/7] qapi: Allow decimal values |
Date: |
Tue, 20 May 2014 17:07:55 +0800 |
This allows giving decimal constants in the schema as expr.
Signed-off-by: Fam Zheng <address@hidden>
---
scripts/qapi.py | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 0265b40..4c945ad 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -157,6 +157,21 @@ class QAPISchema:
return
else:
string += ch
+ elif self.tok in "-0123456789":
+ val = self.tok
+ while self.src[self.cursor] in "0123456789":
+ val += self.src[self.cursor]
+ self.cursor += 1
+ try:
+ if val.startswith("0") and len(val) > 1:
+ raise Exception("Leading zero for non-zero integer")
+ self.val = int(val)
+ if self.val > 0x7fffffffffffffffL or self.val <
-0x7fffffffffffffffL - 1:
+ raise Exception("Value too big")
+ return
+ except Exception, e:
+ raise QAPISchemaError(self, 'Invalid number "%s": %s' %
(val, e))
+
elif self.tok == '\n':
if self.cursor == len(self.src):
self.tok = None
@@ -196,8 +211,8 @@ class QAPISchema:
if self.tok == ']':
self.accept()
return expr
- if not self.tok in [ '{', '[', "'" ]:
- raise QAPISchemaError(self, 'Expected "{", "[", "]" or string')
+ if not self.tok in "{['-0123456789":
+ raise QAPISchemaError(self, 'Expected "{", "[", "]", string or
number')
while True:
expr.append(self.get_expr(True))
if self.tok == ']':
@@ -219,6 +234,9 @@ class QAPISchema:
elif self.tok == "'":
expr = self.val
self.accept()
+ elif self.tok in "-0123456789":
+ expr = self.val
+ self.accept()
else:
raise QAPISchemaError(self, 'Expected "{", "[" or string')
return expr
--
1.9.2
- [Qemu-devel] [RFC PATCH v2 0/7] qapi: Specify default value for optional argument in schema json, Fam Zheng, 2014/05/20
- [Qemu-devel] [RFC PATCH v2 1/7] qapi: Allow decimal values,
Fam Zheng <=
- [Qemu-devel] [RFC PATCH v2 2/7] qapi: Allow true, false and null in schema json, Fam Zheng, 2014/05/20
- [Qemu-devel] [RFC PATCH v2 4/7] qapi: Add c_val(t, val) for int, Fam Zheng, 2014/05/20
- [Qemu-devel] [RFC PATCH v2 5/7] qapi: Add @arg property dictionary syntax, Fam Zheng, 2014/05/20
- [Qemu-devel] [RFC PATCH v2 6/7] qapi: Initialize argument value in generated code if has 'default', Fam Zheng, 2014/05/20
- [Qemu-devel] [RFC PATCH v2 3/7] tests: Add decimal test cases for qapi-schema, Fam Zheng, 2014/05/20
- [Qemu-devel] [RFC PATCH v2 7/7] qmp: Convert block-commit speed to arg property dict, Fam Zheng, 2014/05/20
- Re: [Qemu-devel] [RFC PATCH v2 0/7] qapi: Specify default value for optional argument in schema json, Fam Zheng, 2014/05/20