Skip to content

Instantly share code, notes, and snippets.

@jeet-parekh
Created October 31, 2018 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeet-parekh/936b932b4f2501debd0c40172f6af128 to your computer and use it in GitHub Desktop.
Save jeet-parekh/936b932b4f2501debd0c40172f6af128 to your computer and use it in GitHub Desktop.
import sys
import clang.cindex
index = clang.cindex.Index.create()
fname = sys.argv[1]
tu = index.parse(fname)
c = tu.cursor
for x in c.walk_preorder():
if str(x.location.file) == fname:
if (x.kind) == clang.cindex.CursorKind.STRUCT_DECL:
print("displayname:", x.displayname)
print("spelling:", x.spelling)
print("fields count:", len(list(x.type.get_fields())))
print("#####")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment