qapi: Require valid names
commitc9e0a798691d8c45747b082206e789c8f50523c9
authorEric Blake <eblake@redhat.com>
Mon, 4 May 2015 15:05:22 +0000 (4 09:05 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 5 May 2015 16:39:01 +0000 (5 18:39 +0200)
tree35bbc705d0227068e58d129b7f90d0b8e294d429
parentdd883c6f0547f02ae805d02852ff3691f6d08f85
qapi: Require valid names

Previous commits demonstrated that the generator overlooked various
bad naming situations:
- types, commands, and events need a valid name
- enum members must be valid names, when combined with prefix
- union and alternate branches cannot be marked optional

Valid upstream names match [a-zA-Z][a-zA-Z0-9_-]*; valid downstream
names match __[a-zA-Z][a-zA-Z0-9._-]*.  Enumerations match the
weaker [a-zA-Z0-9._-]+ (in part thanks to QKeyCode picking an enum
that starts with a digit, which we can't change now due to
backwards compatibility).  Rather than call out three separate
regex, this patch just uses a broader combination that allows both
upstream and downstream names, as well as a small hack that
realizes that any enum name is merely a suffix to an already valid
name prefix (that is, any enum name is valid if prepending _ fits
the normal rules).

We could reject new enumeration names beginning with a digit by
whitelisting existing exceptions.  We could also be stricter
about the distinction between upstream names (no leading
underscore, no use of dot) and downstream (mandatory leading
double underscore), but it is probably not worth the bother.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
19 files changed:
scripts/qapi.py
tests/qapi-schema/bad-ident.err
tests/qapi-schema/bad-ident.exit
tests/qapi-schema/bad-ident.json
tests/qapi-schema/bad-ident.out
tests/qapi-schema/enum-bad-name.err
tests/qapi-schema/enum-bad-name.exit
tests/qapi-schema/enum-bad-name.json
tests/qapi-schema/enum-bad-name.out
tests/qapi-schema/enum-dict-member.err
tests/qapi-schema/flat-union-bad-discriminator.err
tests/qapi-schema/flat-union-optional-discriminator.err
tests/qapi-schema/flat-union-optional-discriminator.exit
tests/qapi-schema/flat-union-optional-discriminator.json
tests/qapi-schema/flat-union-optional-discriminator.out [copied from tests/qapi-schema/bad-ident.err with 100% similarity]
tests/qapi-schema/union-optional-branch.err
tests/qapi-schema/union-optional-branch.exit
tests/qapi-schema/union-optional-branch.json
tests/qapi-schema/union-optional-branch.out