qapi: Adjust names of implicit types

The original choice of ':obj-' as the prefix for implicit types
made it obvious that we weren't going to clash with any user-defined
names, which cannot contain ':'. But now we want to create structs
for implicit types, to get rid of special cases in the generators,
and our use of ':' in implicit names needs a tweak to produce valid
C code.

We could transliterate ':' to '_', except that C99 mandates that
"identifiers that begin with an underscore are always reserved for
use as identifiers with file scope in both the ordinary and tag name
spaces". So it's time to change our naming convention: we can
instead use the 'q_' prefix that we reserved for ourselves back in
commit 9fb081e0. Technically, since we aren't planning on exposing
the empty type in generated code, we could keep the name ':empty',
but renaming it to 'q_empty' makes the check for startswith('q_')
cover all implicit types, whether or not code is generated for them.

As long as we don't declare 'empty' or 'obj' ticklish, it shouldn't
clash with c_name() prepending 'q_' to the user's ticklish names.

Backports commit 7599697c66d22ff4c859ba6ccea30e6a9aae6b9b from qemu
This commit is contained in:
Eric Blake 2018-02-21 22:35:11 -05:00 committed by Lioncash
parent d777876e6b
commit 9aa8356bce
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 10 additions and 10 deletions

View file

@ -298,8 +298,6 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
if name == 'q_empty':
return
self.decl += gen_visit_members_decl(name)
self.decl += gen_visit_decl(name)
self.defn += gen_visit_object(name, base, members, variants)
self.defn += gen_visit_object_members(name, base, members, variants)
# TODO Worth changing the visitor signature, so we could
# directly use rather than repeat type.is_implicit()?

View file

@ -396,7 +396,8 @@ def check_name(expr_info, source, name, allow_optional=False,
# code always prefixes it with the enum name
if enum_member and membername[0].isdigit():
membername = 'D' + membername
# Reserve the entire 'q_' namespace for c_name()
# Reserve the entire 'q_' namespace for c_name(), and for 'q_empty'
# and 'q_obj_*' implicit type names.
if not valid_name.match(membername) or \
c_name(membername, False).startswith('q_'):
raise QAPIExprError(expr_info,
@ -1000,8 +1001,9 @@ class QAPISchemaObjectType(QAPISchemaType):
m.check_clash(info, seen)
def is_implicit(self):
# See QAPISchema._make_implicit_object_type()
return self.name[0] == ':'
# See QAPISchema._make_implicit_object_type(), as well as
# _def_predefineds()
return self.name.startswith('q_')
def c_name(self):
return QAPISchemaType.c_name(self)
@ -1048,10 +1050,10 @@ class QAPISchemaMember(object):
def _pretty_owner(self):
owner = self.owner
if owner.startswith(':obj-'):
if owner.startswith('q_obj_'):
# See QAPISchema._make_implicit_object_type() - reverse the
# mapping there to create a nice human-readable description
owner = owner[5:]
owner = owner[6:]
if owner.endswith('-arg'):
return '(parameter of %s)' % owner[:-4]
else:
@ -1268,8 +1270,8 @@ class QAPISchema(object):
('bool', 'boolean', 'bool', 'false'),
('any', 'value', 'QObject' + pointer_suffix, 'NULL')]:
self._def_builtin_type(*t)
self.the_empty_object_type = QAPISchemaObjectType(':empty', None, None,
[], None)
self.the_empty_object_type = QAPISchemaObjectType('q_empty', None,
None, [], None)
self._def_entity(self.the_empty_object_type)
qtype_values = self._make_enum_members(['none', 'qnull', 'qint',
'qstring', 'qdict', 'qlist',
@ -1297,7 +1299,7 @@ class QAPISchema(object):
if not members:
return None
# See also QAPISchemaObjectTypeMember._pretty_owner()
name = ':obj-%s-%s' % (name, role)
name = 'q_obj_%s-%s' % (name, role)
if not self.lookup_entity(name, QAPISchemaObjectType):
self._def_entity(QAPISchemaObjectType(name, info, None,
members, None))