Browse Source

structs implemented

master
heck 5 years ago
parent
commit
786beb40e3
  1. 48
      gen/extract.py

48
gen/extract.py

@ -48,6 +48,7 @@ def create_simple_ast(ast):
"structs": "",
"enums": ""}
elems["functions"] = extract_functions_from_ast(ast)
elems["structs"] = extract_structs_from_ast(ast)
elems["enums"] = extract_enums_from_ast(ast)
return elems
@ -105,13 +106,14 @@ def simple_ast_enums(enum_ast, typename):
"items": []}
items = []
for item in enum_ast["children"]:
if item["kind"] == "CursorKind.ENUM_CONSTANT_DECL":
simple_item = {"name": "",
"value": ""}
simple_item["name"] = item["name"]
simple_item["value"] = item["value"]
items.append(simple_item)
if "children" in enum_ast:
for item in enum_ast["children"]:
if item["kind"] == "CursorKind.ENUM_CONSTANT_DECL":
simple_item = {"name": "",
"value": ""}
simple_item["name"] = item["name"]
simple_item["value"] = item["value"]
items.append(simple_item)
if items:
simple_enum["items"] = items
@ -119,6 +121,38 @@ def simple_ast_enums(enum_ast, typename):
return simple_enum
# only typedef structs
def extract_structs_from_ast(ast):
structs = []
for typedef in ast["children"]:
if typedef["kind"] == "CursorKind.TYPEDEF_DECL":
typename = typedef["type"]
if "children" in typedef:
for struct in typedef["children"]:
if struct["kind"] == "CursorKind.STRUCT_DECL":
structs.append(simple_ast_structs(struct, typename))
return structs
def simple_ast_structs(struct_ast, typename):
simple_struct = {"name" : typename,
"fields" : []}
fields = []
if "children" in struct_ast:
for field in struct_ast["children"]:
if field["kind"] == "CursorKind.FIELD_DECL":
simple_field = {"name": "",
"type": ""}
simple_field["name"] = field["name"]
simple_field["type"] = field["type"]
fields.append(simple_field)
if fields:
simple_struct["fields"] = fields
return simple_struct
def main():
input()

Loading…
Cancel
Save