2013-07-27 19:41:53 +04:00
|
|
|
#
|
|
|
|
# QAPI parser test harness
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013 Red Hat Inc.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Markus Armbruster <armbru@redhat.com>
|
|
|
|
#
|
|
|
|
# This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
# See the COPYING file in the top-level directory.
|
|
|
|
#
|
|
|
|
|
2018-01-16 16:42:04 +03:00
|
|
|
from __future__ import print_function
|
2013-07-27 19:41:53 +04:00
|
|
|
import sys
|
2018-02-11 12:35:51 +03:00
|
|
|
from qapi.common import QAPIError, QAPISchema, QAPISchemaVisitor
|
2013-07-27 19:41:53 +04:00
|
|
|
|
2015-09-16 14:06:08 +03:00
|
|
|
|
|
|
|
class QAPISchemaTestVisitor(QAPISchemaVisitor):
|
2018-02-11 12:35:55 +03:00
|
|
|
|
|
|
|
def visit_module(self, name):
|
|
|
|
print('module %s' % name)
|
|
|
|
|
|
|
|
def visit_include(self, name, info):
|
|
|
|
print('include %s' % name)
|
|
|
|
|
2018-12-13 15:37:04 +03:00
|
|
|
def visit_enum_type(self, name, info, ifcond, members, prefix):
|
2018-12-13 15:37:05 +03:00
|
|
|
print('enum %s' % name)
|
2015-09-16 14:06:08 +03:00
|
|
|
if prefix:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' prefix %s' % prefix)
|
2018-12-13 15:37:05 +03:00
|
|
|
for m in members:
|
|
|
|
print(' member %s' % m.name)
|
2018-12-13 15:37:11 +03:00
|
|
|
self._print_if(m.ifcond, indent=8)
|
2018-07-03 18:56:38 +03:00
|
|
|
self._print_if(ifcond)
|
2015-09-16 14:06:08 +03:00
|
|
|
|
2018-07-03 18:56:38 +03:00
|
|
|
def visit_object_type(self, name, info, ifcond, base, members, variants):
|
2018-01-16 16:42:04 +03:00
|
|
|
print('object %s' % name)
|
2015-09-16 14:06:08 +03:00
|
|
|
if base:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' base %s' % base.name)
|
2015-09-16 14:06:08 +03:00
|
|
|
for m in members:
|
2018-06-21 11:35:51 +03:00
|
|
|
print(' member %s: %s optional=%s'
|
|
|
|
% (m.name, m.type.name, m.optional))
|
2018-12-13 15:37:15 +03:00
|
|
|
self._print_if(m.ifcond, 8)
|
2015-09-16 14:06:08 +03:00
|
|
|
self._print_variants(variants)
|
2018-07-03 18:56:38 +03:00
|
|
|
self._print_if(ifcond)
|
2015-09-16 14:06:08 +03:00
|
|
|
|
2018-07-03 18:56:38 +03:00
|
|
|
def visit_alternate_type(self, name, info, ifcond, variants):
|
2018-01-16 16:42:04 +03:00
|
|
|
print('alternate %s' % name)
|
2015-09-16 14:06:08 +03:00
|
|
|
self._print_variants(variants)
|
2018-07-03 18:56:38 +03:00
|
|
|
self._print_if(ifcond)
|
2015-09-16 14:06:08 +03:00
|
|
|
|
2018-07-03 18:56:38 +03:00
|
|
|
def visit_command(self, name, info, ifcond, arg_type, ret_type, gen,
|
2018-05-11 19:51:43 +03:00
|
|
|
success_response, boxed, allow_oob, allow_preconfig):
|
2018-06-21 11:35:51 +03:00
|
|
|
print('command %s %s -> %s'
|
|
|
|
% (name, arg_type and arg_type.name,
|
|
|
|
ret_type and ret_type.name))
|
|
|
|
print(' gen=%s success_response=%s boxed=%s oob=%s preconfig=%s'
|
|
|
|
% (gen, success_response, boxed, allow_oob, allow_preconfig))
|
2018-07-03 18:56:38 +03:00
|
|
|
self._print_if(ifcond)
|
2015-09-16 14:06:08 +03:00
|
|
|
|
2018-07-03 18:56:38 +03:00
|
|
|
def visit_event(self, name, info, ifcond, arg_type, boxed):
|
2018-01-16 16:42:04 +03:00
|
|
|
print('event %s %s' % (name, arg_type and arg_type.name))
|
|
|
|
print(' boxed=%s' % boxed)
|
2018-07-03 18:56:38 +03:00
|
|
|
self._print_if(ifcond)
|
2015-09-16 14:06:08 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _print_variants(variants):
|
|
|
|
if variants:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' tag %s' % variants.tag_member.name)
|
2015-09-16 14:06:08 +03:00
|
|
|
for v in variants.variants:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' case %s: %s' % (v.name, v.type.name))
|
2018-12-13 15:37:17 +03:00
|
|
|
QAPISchemaTestVisitor._print_if(v.ifcond, indent=8)
|
2015-09-16 14:06:08 +03:00
|
|
|
|
2018-07-03 18:56:38 +03:00
|
|
|
@staticmethod
|
|
|
|
def _print_if(ifcond, indent=4):
|
|
|
|
if ifcond:
|
|
|
|
print('%sif %s' % (' ' * indent, ifcond))
|
|
|
|
|
2018-02-11 12:35:51 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
schema = QAPISchema(sys.argv[1])
|
|
|
|
except QAPIError as err:
|
|
|
|
print(err, file=sys.stderr)
|
|
|
|
exit(1)
|
|
|
|
|
2015-09-16 14:06:08 +03:00
|
|
|
schema.visit(QAPISchemaTestVisitor())
|
2017-03-20 16:11:53 +03:00
|
|
|
|
|
|
|
for doc in schema.docs:
|
|
|
|
if doc.symbol:
|
2018-01-16 16:42:04 +03:00
|
|
|
print('doc symbol=%s' % doc.symbol)
|
2017-03-20 16:11:53 +03:00
|
|
|
else:
|
2018-01-16 16:42:04 +03:00
|
|
|
print('doc freeform')
|
|
|
|
print(' body=\n%s' % doc.body.text)
|
2018-01-16 16:42:05 +03:00
|
|
|
for arg, section in doc.args.items():
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' arg=%s\n%s' % (arg, section.text))
|
2017-03-20 16:11:53 +03:00
|
|
|
for section in doc.sections:
|
2018-01-16 16:42:04 +03:00
|
|
|
print(' section=%s\n%s' % (section.name, section.text))
|