#!/usr/bin/env python
""" Usage: call with <filename> <classname>
"""

import sys
import clang.cindex

cursorkind = clang.cindex.CursorKind
access_specifier = clang.cindex.AccessSpecifier
def find_classdecl(node, classname):
    """ Find class named 'classname'
    """
    if node.spelling == classname and node.kind == cursorkind.CLASS_DECL:
        print "class " + node.spelling + " {"
        print "public:"
        for c in node.get_children():
            if c.access_specifier == access_specifier.PUBLIC:
                if c.kind == cursorkind.CXX_METHOD:
                    print "    " + c.result_type.spelling + " " + c.displayname
                    print "    {"
                    print "    }"
                if c.kind == cursorkind.FIELD_DECL:
                    print "    " + c.type.spelling + " " + c.displayname + ";"

        print "}"

    # Recurse for children of this node
    for c in node.get_children():
        find_classdecl(c, classname)

index = clang.cindex.Index.create()
tu = index.parse(sys.argv[1])
print 'Translation unit:', tu.spelling
find_classdecl(tu.cursor, sys.argv[2])
