]>
Commit | Line | Data |
---|---|---|
98626572 MA |
1 | # |
2 | # QAPI parser test harness | |
3 | # | |
4 | # Copyright (c) 2013 Red Hat Inc. | |
5 | # | |
6 | # Authors: | |
7 | # Markus Armbruster <armbru@redhat.com> | |
8 | # | |
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. | |
11 | # | |
12 | ||
ef9d9108 | 13 | from __future__ import print_function |
98626572 | 14 | import sys |
181feaf3 | 15 | from qapi.common import QAPIError, QAPISchema, QAPISchemaVisitor |
98626572 | 16 | |
156402e5 MA |
17 | |
18 | class QAPISchemaTestVisitor(QAPISchemaVisitor): | |
cf40a0a5 MA |
19 | |
20 | def visit_module(self, name): | |
21 | print('module %s' % name) | |
22 | ||
23 | def visit_include(self, name, info): | |
24 | print('include %s' % name) | |
25 | ||
1962bd39 | 26 | def visit_enum_type(self, name, info, ifcond, members, prefix): |
1e381b65 | 27 | print('enum %s' % name) |
156402e5 | 28 | if prefix: |
ef9d9108 | 29 | print(' prefix %s' % prefix) |
1e381b65 MAL |
30 | for m in members: |
31 | print(' member %s' % m.name) | |
6cc32b0e | 32 | self._print_if(m.ifcond, indent=8) |
fbf09a2f | 33 | self._print_if(ifcond) |
156402e5 | 34 | |
fbf09a2f | 35 | def visit_object_type(self, name, info, ifcond, base, members, variants): |
ef9d9108 | 36 | print('object %s' % name) |
156402e5 | 37 | if base: |
ef9d9108 | 38 | print(' base %s' % base.name) |
156402e5 | 39 | for m in members: |
b736e25a MA |
40 | print(' member %s: %s optional=%s' |
41 | % (m.name, m.type.name, m.optional)) | |
ccadd6bc | 42 | self._print_if(m.ifcond, 8) |
156402e5 | 43 | self._print_variants(variants) |
fbf09a2f | 44 | self._print_if(ifcond) |
156402e5 | 45 | |
fbf09a2f | 46 | def visit_alternate_type(self, name, info, ifcond, variants): |
ef9d9108 | 47 | print('alternate %s' % name) |
156402e5 | 48 | self._print_variants(variants) |
fbf09a2f | 49 | self._print_if(ifcond) |
156402e5 | 50 | |
fbf09a2f | 51 | def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, |
d6fe3d02 | 52 | success_response, boxed, allow_oob, allow_preconfig): |
b736e25a MA |
53 | print('command %s %s -> %s' |
54 | % (name, arg_type and arg_type.name, | |
55 | ret_type and ret_type.name)) | |
56 | print(' gen=%s success_response=%s boxed=%s oob=%s preconfig=%s' | |
57 | % (gen, success_response, boxed, allow_oob, allow_preconfig)) | |
fbf09a2f | 58 | self._print_if(ifcond) |
156402e5 | 59 | |
fbf09a2f | 60 | def visit_event(self, name, info, ifcond, arg_type, boxed): |
ef9d9108 DB |
61 | print('event %s %s' % (name, arg_type and arg_type.name)) |
62 | print(' boxed=%s' % boxed) | |
fbf09a2f | 63 | self._print_if(ifcond) |
156402e5 MA |
64 | |
65 | @staticmethod | |
66 | def _print_variants(variants): | |
67 | if variants: | |
ef9d9108 | 68 | print(' tag %s' % variants.tag_member.name) |
156402e5 | 69 | for v in variants.variants: |
ef9d9108 | 70 | print(' case %s: %s' % (v.name, v.type.name)) |
a2724280 | 71 | QAPISchemaTestVisitor._print_if(v.ifcond, indent=8) |
156402e5 | 72 | |
fbf09a2f MAL |
73 | @staticmethod |
74 | def _print_if(ifcond, indent=4): | |
75 | if ifcond: | |
76 | print('%sif %s' % (' ' * indent, ifcond)) | |
77 | ||
181feaf3 MA |
78 | |
79 | try: | |
80 | schema = QAPISchema(sys.argv[1]) | |
81 | except QAPIError as err: | |
82 | print(err, file=sys.stderr) | |
83 | exit(1) | |
84 | ||
156402e5 | 85 | schema.visit(QAPISchemaTestVisitor()) |
818c3318 MA |
86 | |
87 | for doc in schema.docs: | |
88 | if doc.symbol: | |
ef9d9108 | 89 | print('doc symbol=%s' % doc.symbol) |
818c3318 | 90 | else: |
ef9d9108 DB |
91 | print('doc freeform') |
92 | print(' body=\n%s' % doc.body.text) | |
2f848044 | 93 | for arg, section in doc.args.items(): |
ef9d9108 | 94 | print(' arg=%s\n%s' % (arg, section.text)) |
818c3318 | 95 | for section in doc.sections: |
ef9d9108 | 96 | print(' section=%s\n%s' % (section.name, section.text)) |