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 13from __future__ import print_function 14from qapi import * 15from pprint import pprint 16import os 17import sys 18 19 20class QAPISchemaTestVisitor(QAPISchemaVisitor): 21 def visit_enum_type(self, name, info, values, prefix): 22 print('enum %s %s' % (name, values)) 23 if prefix: 24 print(' prefix %s' % prefix) 25 26 def visit_object_type(self, name, info, base, members, variants): 27 print('object %s' % name) 28 if base: 29 print(' base %s' % base.name) 30 for m in members: 31 print(' member %s: %s optional=%s' % \ 32 (m.name, m.type.name, m.optional)) 33 self._print_variants(variants) 34 35 def visit_alternate_type(self, name, info, variants): 36 print('alternate %s' % name) 37 self._print_variants(variants) 38 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)) 45 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) 49 50 @staticmethod 51 def _print_variants(variants): 52 if 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)) 56 57schema = QAPISchema(sys.argv[1]) 58schema.visit(QAPISchemaTestVisitor()) 59 60for doc in schema.docs: 61 if doc.symbol: 62 print('doc symbol=%s' % doc.symbol) 63 else: 64 print('doc freeform') 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)) 70