test.hpp
Код: Выделить всё
#pragma once
struct my_struct {
int mdarr[10][20];
};
Код: Выделить всё
import clang.cindex as cl
def process(c):
if c.kind in [cl.CursorKind.STRUCT_DECL, cl.CursorKind.CLASS_DECL]:
print("Found struct: ", c.spelling)
for field in c.type.get_fields():
print("Found field: ", field.spelling)
# Returns size of first dimension but not the second dimension
print("Array size: ", field.type.get_array_size())
for child in field.get_children():
# Prints an empty string
print("Found child: ", child.spelling)
# How do I extract the value from the `INTEGER_LITERAL`?
print("Child cursor kind: ", child.kind)
return
for child in c.get_children():
process(child)
idx = cl.Index.create()
tu = idx.parse("test.hpp")
process(tu.cursor)
Код: Выделить всё
Found struct: my_struct
Found field: mdarr
Array size: 10
Found child:
Child cursor kind: CursorKind.INTEGER_LITERAL
Found child:
Child cursor kind: CursorKind.INTEGER_LITERAL
Подробнее здесь: https://stackoverflow.com/questions/786 ... g-bindings