...
This commit is contained in:
@@ -106,10 +106,11 @@ if tu.diagnostics:
|
||||
if diag.severity >= clang.cindex.Diagnostic.Error:
|
||||
print(f"Error: {diag.spelling}", file=sys.stderr)
|
||||
|
||||
print(f'module "{os.path.basename(filename).split(".")[0]}"')
|
||||
print(f'module {os.path.basename(filename).split(".")[0]}')
|
||||
print()
|
||||
|
||||
seen_structs = []
|
||||
seen_enums = []
|
||||
|
||||
for cursor in tu.cursor.walk_preorder():
|
||||
if cursor.location.file and cursor.location.file.name != filename:
|
||||
@@ -151,16 +152,22 @@ for cursor in tu.cursor.walk_preorder():
|
||||
print("}")
|
||||
|
||||
elif cursor.kind == CursorKind.ENUM_DECL:
|
||||
name = cursor.spelling
|
||||
print(f"export enum {name} : u32")
|
||||
print("{")
|
||||
for field in cursor.get_children():
|
||||
if field.kind == CursorKind.ENUM_CONSTANT_DECL:
|
||||
field_name = field.spelling
|
||||
field_value = field.enum_value
|
||||
print(f" {field_name} = {field_value}")
|
||||
else:
|
||||
raise Exception(
|
||||
f"Unsupported child of enum: {field.spelling}: {field.kind}"
|
||||
)
|
||||
print("}")
|
||||
if cursor.get_usr() in seen_enums:
|
||||
continue
|
||||
|
||||
seen_enums.append(cursor.get_usr())
|
||||
|
||||
if cursor.is_definition():
|
||||
name = cursor.spelling
|
||||
print(f"export enum {name} : u32")
|
||||
print("{")
|
||||
for field in cursor.get_children():
|
||||
if field.kind == CursorKind.ENUM_CONSTANT_DECL:
|
||||
field_name = field.spelling
|
||||
field_value = field.enum_value
|
||||
print(f" {field_name} = {field_value}")
|
||||
else:
|
||||
raise Exception(
|
||||
f"Unsupported child of enum: {field.spelling}: {field.kind}"
|
||||
)
|
||||
print("}")
|
||||
|
||||
Reference in New Issue
Block a user