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.
|
|
|
|
#
|
|
|
|
|
|
|
|
from qapi import *
|
|
|
|
from pprint import pprint
|
2014-05-02 15:52:35 +02:00
|
|
|
import os
|
2013-07-27 17:41:53 +02:00
|
|
|
import sys
|
|
|
|
|
2015-09-16 13:06:08 +02:00
|
|
|
|
|
|
|
class QAPISchemaTestVisitor(QAPISchemaVisitor):
|
|
|
|
def visit_enum_type(self, name, info, values, prefix):
|
|
|
|
print 'enum %s %s' % (name, values)
|
|
|
|
if prefix:
|
|
|
|
print ' prefix %s' % prefix
|
|
|
|
|
|
|
|
def visit_object_type(self, name, info, base, members, variants):
|
|
|
|
print 'object %s' % name
|
|
|
|
if base:
|
|
|
|
print ' base %s' % base.name
|
|
|
|
for m in members:
|
|
|
|
print ' member %s: %s optional=%s' % \
|
|
|
|
(m.name, m.type.name, m.optional)
|
|
|
|
self._print_variants(variants)
|
|
|
|
|
|
|
|
def visit_alternate_type(self, name, info, variants):
|
|
|
|
print 'alternate %s' % name
|
|
|
|
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):
|
2015-09-16 13:06:08 +02:00
|
|
|
print 'command %s %s -> %s' % \
|
|
|
|
(name, arg_type and arg_type.name, ret_type and ret_type.name)
|
2016-07-14 05:50:19 +02:00
|
|
|
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):
|
2015-09-16 13:06:08 +02:00
|
|
|
print 'event %s %s' % (name, arg_type and arg_type.name)
|
2016-07-14 05:50:19 +02:00
|
|
|
print ' boxed=%s' % boxed
|
2015-09-16 13:06:08 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _print_variants(variants):
|
|
|
|
if variants:
|
2016-07-14 05:50:15 +02:00
|
|
|
print ' tag %s' % variants.tag_member.name
|
2015-09-16 13:06:08 +02:00
|
|
|
for v in variants.variants:
|
|
|
|
print ' case %s: %s' % (v.name, v.type.name)
|
|
|
|
|
|
|
|
schema = QAPISchema(sys.argv[1])
|
|
|
|
schema.visit(QAPISchemaTestVisitor())
|