2013-07-27 17:41:53 +02: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 14:42:04 +01:00
|
|
|
from __future__ import print_function
|
2013-07-27 17:41:53 +02:00
|
|
|
import sys
|
2018-02-11 10:35:51 +01:00
|
|
|
from qapi.common import QAPIError, QAPISchema, QAPISchemaVisitor
|
2013-07-27 17:41:53 +02:00
|
|
|
|
2015-09-16 13:06:08 +02:00
|
|
|
|
|
|
|
class QAPISchemaTestVisitor(QAPISchemaVisitor):
|
2018-02-11 10:35:55 +01:00
|
|
|
|
|
|
|
def visit_module(self, name):
|
|
|
|
print('module %s' % name)
|
|
|
|
|
|
|
|
def visit_include(self, name, info):
|
|
|
|
print('include %s' % name)
|
|
|
|
|
2015-09-16 13:06:08 +02:00
|
|
|
def visit_enum_type(self, name, info, values, prefix):
|
2018-01-16 14:42:04 +01:00
|
|
|
print('enum %s %s' % (name, values))
|
2015-09-16 13:06:08 +02:00
|
|
|
if prefix:
|
2018-01-16 14:42:04 +01:00
|
|
|
print(' prefix %s' % prefix)
|
2015-09-16 13:06:08 +02:00
|
|
|
|
|
|
|
def visit_object_type(self, name, info, base, members, variants):
|
2018-01-16 14:42:04 +01:00
|
|
|
print('object %s' % name)
|
2015-09-16 13:06:08 +02:00
|
|
|
if base:
|
2018-01-16 14:42:04 +01:00
|
|
|
print(' base %s' % base.name)
|
2015-09-16 13:06:08 +02:00
|
|
|
for m in members:
|
2018-01-16 14:42:04 +01:00
|
|
|
print(' member %s: %s optional=%s' % \
|
|
|
|
(m.name, m.type.name, m.optional))
|
2015-09-16 13:06:08 +02:00
|
|
|
self._print_variants(variants)
|
|
|
|
|
|
|
|
def visit_alternate_type(self, name, info, variants):
|
2018-01-16 14:42:04 +01:00
|
|
|
print('alternate %s' % name)
|
2015-09-16 13:06:08 +02:00
|
|
|
self._print_variants(variants)
|
|
|
|
|
|
|
|
def visit_command(self, name, info, arg_type, ret_type,
|
2016-07-14 05:50:19 +02:00
|
|
|
gen, success_response, boxed):
|
2018-01-16 14:42:04 +01: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' % \
|
|
|
|
(gen, success_response, boxed))
|
2015-09-16 13:06:08 +02:00
|
|
|
|
2016-07-14 05:50:19 +02:00
|
|
|
def visit_event(self, name, info, arg_type, boxed):
|
2018-01-16 14:42:04 +01:00
|
|
|
print('event %s %s' % (name, arg_type and arg_type.name))
|
|
|
|
print(' boxed=%s' % boxed)
|
2015-09-16 13:06:08 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _print_variants(variants):
|
|
|
|
if variants:
|
2018-01-16 14:42:04 +01:00
|
|
|
print(' tag %s' % variants.tag_member.name)
|
2015-09-16 13:06:08 +02:00
|
|
|
for v in variants.variants:
|
2018-01-16 14:42:04 +01:00
|
|
|
print(' case %s: %s' % (v.name, v.type.name))
|
2015-09-16 13:06:08 +02:00
|
|
|
|
2018-02-11 10:35:51 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
schema = QAPISchema(sys.argv[1])
|
|
|
|
except QAPIError as err:
|
|
|
|
print(err, file=sys.stderr)
|
|
|
|
exit(1)
|
|
|
|
|
2015-09-16 13:06:08 +02:00
|
|
|
schema.visit(QAPISchemaTestVisitor())
|
2017-03-20 14:11:53 +01:00
|
|
|
|
|
|
|
for doc in schema.docs:
|
|
|
|
if doc.symbol:
|
2018-01-16 14:42:04 +01:00
|
|
|
print('doc symbol=%s' % doc.symbol)
|
2017-03-20 14:11:53 +01:00
|
|
|
else:
|
2018-01-16 14:42:04 +01:00
|
|
|
print('doc freeform')
|
|
|
|
print(' body=\n%s' % doc.body.text)
|
2018-01-16 14:42:05 +01:00
|
|
|
for arg, section in doc.args.items():
|
2018-01-16 14:42:04 +01:00
|
|
|
print(' arg=%s\n%s' % (arg, section.text))
|
2017-03-20 14:11:53 +01:00
|
|
|
for section in doc.sections:
|
2018-01-16 14:42:04 +01:00
|
|
|
print(' section=%s\n%s' % (section.name, section.text))
|