Commit Graph

70 Commits

Author SHA1 Message Date
Eric Blake
0327ce85e4
qapi: More rigourous checking of types
Now that we know every expression is valid with regards to
its keys, we can add further tests that those keys refer to
valid types. With this patch, all uses of a type (the 'data':
of command, type, union, alternate, and event; the 'returns':
of command; the 'base': of type and union) must resolve to an
appropriate subset of metatypes declared by the current qapi
parse; this includes recursing into each member of a data
dictionary. Dealing with '**' and nested anonymous structs
will be done in later patches.

Backports commit dd883c6f0547f02ae805d02852ff3691f6d08f85 from qemu
2018-02-19 14:01:14 -05:00
Fam Zheng
1f9419be44
qapi: Allow true, false and null in schema json
In the near term, we will use it for a sensible-looking
'gen':false inside command declarations, instead of the
current ugly 'gen':'no'.

In the long term, it will allow conversion from shorthand
with defaults mentioned only in side-band documentation:
'data':{'*flag':'bool', '*string':'str'}
into an explicit default value documentation, as in:
'data':{'flag':{'type':'bool', 'optional':true, 'default':true},
'string':{'type':'str', 'optional':true, 'default':null}}

We still don't parse integer values (also necessary before
we can allow explicit defaults), but that can come in a later
series.

Backports commit e53188ada516c814a729551be2448684d6d8ce08 from qemu
2018-02-19 13:57:53 -05:00
Eric Blake
b19cd2bd9a
qapi: Better error messages for duplicated expressions
The previous commit demonstrated that the generator overlooked
duplicate expressions:
- a complex type or command reusing a built-in type name
- redeclaration of a type name, whether by the same or different
metatype
- redeclaration of a command or event
- collision of a type with implicit 'Kind' enum for a union
- collision with an implicit MAX enum constant

Since the c_type() function in the generator treats all names
as being in the same namespace, this patch adds a global array
to track all known names and their source, to prevent collisions
before it can cause further problems. While valid .json files
won't trigger any of these cases, we might as well be nicer to
developers that make a typo while trying to add new QAPI code.

Backports commit 4dc2e6906e1084fdd37bf67385c5dcd2c72ae22b from qemu
2018-02-19 13:56:05 -05:00
Eric Blake
75ba2155af
qapi: Better error messages for bad expressions
The previous commit demonstrated that the generator overlooked some
fairly basic broken expressions:
- missing metataype
- metatype key has a non-string value
- unknown key in relation to the metatype
- conflicting metatype (this patch treats the second metatype as an
unknown key of the first key visited, which is not necessarily the
first key the user typed)

Add check_keys to cover these situations, and update testcases to
match. A couple other tests (enum-missing-data, indented-expr) had
to change since the validation added here occurs so early.
Conversely, changes to ident-with-escape results show that we still
have problems where our handling of escape sequences differs from
true JSON, which will matter down the road if we allow arbitrary
default string values for optional parameters (but for now is not
too bad, as we currently can avoid unicode escaping as we don't
need to represent anything beyond C identifier material).

While valid .json files won't trigger any of these cases, we might
as well be nicer to developers that make a typo while trying to add
new QAPI code.

Backports commit 0545f6b8874c28d97369f2c83e5077e0461d4f12 from qemu
2018-02-19 13:52:12 -05:00
Eric Blake
8744d16fbe
qapi: Use 'alternate' to replace anonymous union
Previous patches have led up to the point where I create the
new meta-type "'alternate':'Foo'". See the previous patches
for documentation; I intentionally split as much work into
earlier patches to minimize the size of this patch, but a lot
of it is churn due to testsuite fallout after updating to the
new type.

Backports commit ab916faddd16f0165e9cc2551f90699be8efde53 from qemu
2018-02-19 13:49:56 -05:00
Eric Blake
8a6303f9cd
qapi: Segregate anonymous unions into alternates in generator
Special-casing 'discriminator == {}' for handling anonymous unions
is getting awkward; since this particular type is not always a
dictionary on the wire, it is easier to treat it as a completely
different class of type, "alternate", so that if a type is listed
in the union_types array, we know it is not an anonymous union.

This patch just further segregates union handling, to make sure that
anonymous unions are not stored in union_types, and splitting up
check_union() into separate functions. A future patch will change
the qapi grammar, and having the segregation already in place will
make it easier to deal with the distinct meta-type.

Backports commit 811d04fd0cff1229480d3f5b2e349f646ab6e3c1 from qemu
2018-02-19 13:44:17 -05:00
Eric Blake
9e87ec4b54
qapi: Prepare for catching more semantic parse errors
This patch widens the scope of a try block (with the attending
reindentation required by Python) in preparation for a future
patch adding more instances of QAPIExprError inside the block.
It's easier to separate indentation from semantic changes, so
this patch has no real behavior change.

Backports commit 268a1c5eb10832c2e4476d3fe199ea547dabecb7 from qemu
2018-02-19 13:39:37 -05:00
Eric Blake
3ee6a0c88a
qapi: Tighten checking of unions
Previous commits demonstrated that the generator had several
flaws with less-than-perfect unions:
- a simple union that listed the same branch twice (or two variant
names that map to the same C enumerator, including the implicit
MAX sentinel) ended up generating invalid C code
- an anonymous union that listed two branches with the same qtype
ended up generating invalid C code
- the generator crashed on anonymous union attempts to use an
array type
- the generator was silently ignoring a base type for anonymous
unions
- the generator allowed unknown types or nested anonymous unions
as a branch in an anonymous union

Backports commit 44bd1276a7dea747c41f250cb71ab65965343a7f from qemu
2018-02-19 13:34:22 -05:00
Eric Blake
8023795233
qapi: Forbid base without discriminator in unions
None of the existing QMP or QGA interfaces uses a union with a
base type but no discriminator; it is easier to avoid this in the
generator to save room for other future extensions more likely to
be useful.  An earlier commit added a union-base-no-discriminator
test to ensure that we eventually give a decent error message;
likewise, removing UserDefUnion outright is okay, because we moved
all the tests we wish to keep into the tests of the simple union
UserDefNativeListUnion in the previous commit.  Now is the time to
actually forbid simple union with base, and remove the last
vestiges from the testsuite.

Backports commit a8d4a2e4d7e1a0207699de47142c9bdbf2cc8675 from qemu
2018-02-19 13:29:39 -05:00
Eric Blake
d8f8b1925c
qapi: Better error messages for bad enums
The previous commit demonstrated that the generator had several
flaws with less-than-perfect enums:
- an enum that listed the same string twice (or two variant
strings that map to the same C enumerator) ended up generating
an invalid C enum
- because the generator adds a _MAX terminator to each enum,
the use of an enum member 'max' can also cause this clash
- if an enum omits 'data', the generator left a python stack
trace rather than a graceful message
- an enum that used a non-array 'data' was silently accepted by
the parser
- an enum that used non-string members in the 'data' member
was silently accepted by the parser

Add check_enum to cover these situations, and update testcases
to match.  While valid .json files won't trigger any of these
cases, we might as well be nicer to developers that make a typo
while trying to add new QAPI code.

Backports commit cf3935907b5df16f667d54ad6761c7e937dcf425 from qemu
2018-02-19 13:23:55 -05:00
Eric Blake
79c351d3e6
qapi: Fix generation of 'size' builtin type
We were missing the 'size' builtin type (which means that QAPI using
[ 'size' ] would fail to compile).

Backports commit cb17f79eef0d161e81ac457e4c1f124405be2a18 from qemu
2018-02-19 13:20:05 -05:00
Eric Blake
9d5a99b029
qapi: Simplify builtin type handling
There was some redundancy between builtin_types[] and
builtin_type_qtypes{}.  Merge them into one.

Backports commit b52c4b9cf0bbafdf8cede4ea1f62770d86815718 from qemu
2018-02-19 13:15:21 -05:00
Eric Blake
bf18f16174
qapi: Drop dead genlist parameter
Defaulting a parameter to True, then having all callers omit or
pass an explicit True for that parameter, is pointless. Looks
like it has been dead since introduction in commit 06d64c6, more
than 4 years ago.

Backports commit 6540e9f35bfeea2baf4509745516172070dca412 from qemu
2018-02-19 13:09:44 -05:00
Eric Blake
3aba81d5aa
qapi: Drop unused error argument for list and implicit struct
No backend was setting an error when ending the visit of a list or
implicit struct, or when moving to the next list node. Make the
callers a bit easier to follow by making this a part of the contract,
and removing the errp argument - callers can then unconditionally end
an object as part of cleanup without having to think about whether a
second error is dominated by a first, because there is no second
error.

A later patch will then tackle the larger task of splitting
visit_end_struct(), which can indeed set an error.

Backports commit 08f9541dec51700abef0c37994213164ca4e4fc9 from qemu
2018-02-19 12:59:54 -05:00
xorstream
8840d5b42b Save copies of generated qapi files. 2017-01-21 00:30:50 +11:00
Nguyen Anh Quynh
7e2234237c del qemu/scripts/dump-guest-memory.py 2017-01-19 20:56:07 +08:00
Nguyen Anh Quynh
f2691b0107 more cleanup qemu/configure 2017-01-19 14:11:54 +08:00
Chris Eagle
986096d443 fix file perms 2015-08-28 21:05:38 -07:00
Chris Eagle
94ac0f02e6 file permissions changes 2015-08-28 20:03:36 -07:00
Nguyen Anh Quynh
344d016104 import 2015-08-21 15:04:50 +08:00