2 # QAPI parser test harness
4 # Copyright (c) 2013 Red Hat Inc.
7 # Markus Armbruster <armbru@redhat.com>
9 # This work is licensed under the terms of the GNU GPL, version 2 or later.
10 # See the COPYING file in the top-level directory.
13 from __future__
import print_function
15 from pprint
import pprint
20 class QAPISchemaTestVisitor(QAPISchemaVisitor
):
21 def visit_enum_type(self
, name
, info
, values
, prefix
):
22 print('enum %s %s' % (name
, values
))
24 print(' prefix %s' % prefix
)
26 def visit_object_type(self
, name
, info
, base
, members
, variants
):
27 print('object %s' % name
)
29 print(' base %s' % base
.name
)
31 print(' member %s: %s optional=%s' % \
32 (m
.name
, m
.type.name
, m
.optional
))
33 self
._print
_variants
(variants
)
35 def visit_alternate_type(self
, name
, info
, variants
):
36 print('alternate %s' % name
)
37 self
._print
_variants
(variants
)
39 def visit_command(self
, name
, info
, arg_type
, ret_type
,
40 gen
, success_response
, boxed
):
41 print('command %s %s -> %s' % \
42 (name
, arg_type
and arg_type
.name
, ret_type
and ret_type
.name
))
43 print(' gen=%s success_response=%s boxed=%s' % \
44 (gen
, success_response
, boxed
))
46 def visit_event(self
, name
, info
, arg_type
, boxed
):
47 print('event %s %s' % (name
, arg_type
and arg_type
.name
))
48 print(' boxed=%s' % boxed
)
51 def _print_variants(variants
):
53 print(' tag %s' % variants
.tag_member
.name
)
54 for v
in variants
.variants
:
55 print(' case %s: %s' % (v
.name
, v
.type.name
))
57 schema
= QAPISchema(sys
.argv
[1])
58 schema
.visit(QAPISchemaTestVisitor())
60 for doc
in schema
.docs
:
62 print('doc symbol=%s' % doc
.symbol
)
65 print(' body=\n%s' % doc
.body
.text
)
66 for arg
, section
in doc
.args
.items():
67 print(' arg=%s\n%s' % (arg
, section
.text
))
68 for section
in doc
.sections
:
69 print(' section=%s\n%s' % (section
.name
, section
.text
))