diff --git a/gen/gen_cdl.py b/gen/gen_cdl.py index 96084c4..f1b1cfa 100755 --- a/gen/gen_cdl.py +++ b/gen/gen_cdl.py @@ -51,37 +51,6 @@ def write_json(content, outpath): json.dump(content, f, indent=4) -# generates simple-ast for each header specified in spec out dir. -def main_old(): - parser = ASTParser("/opt/local/libexec/llvm-9.0/lib/libclang.dylib") - - in_dir = r"/Users/heck/local-default/include/pEp/" - filenames = ["pEpEngine.h", - "keymanagement.h", - "message_api.h", - "message.h", - "sync_api.h", - "key_reset.h", - "Identity.h", - "Rating.h"] - - out_dir = "data/output" - - paths = join_dir_and_filenames(in_dir, filenames) - - headers = [] - for path in paths: - headers.append(create_header(path, out_dir)) - - for header in headers: - print("processing path: " + header["path"] + "...") - header["ast"] = parser.parse(header["path"], header["sourcecode"]) - write_json(header["ast"], header["out_dir"] + "/" + header["filename"] + ".ast.json") - - simpleAst = SimpleAST() - header["simple_ast"] = simpleAst.create_simple_ast(header["ast"]) - write_json(header["simple_ast"], header["out_dir"] + "/" + header["filename"] + ".simple_ast.json") - # works on valid json like structure lists/dict def recursive_query(data, filter, transform=lambda x: x): @@ -183,12 +152,6 @@ def extract_types(data): return True def xform(item): - # ret = {} - # ret["name"] = item["name"] - # if "utypekind" in item: - # ret["utypekind"] = item["utypekind"] - # else: - # ret["utypekind"] = item["type"] ret = item["name"] return ret @@ -239,7 +202,7 @@ def extract_enum_decl(ast, name): res = recursive_query(ast, filter) if len(res) > 1: - assert (False, "duplicate definition") + assert False, "duplicate definition" if len(res) == 1: ret = res[0] @@ -257,7 +220,7 @@ def extract_struct_decl(ast, name): res = recursive_query(ast, filter) if len(res) > 1: - assert (False, "duplicate definition") + assert False, "duplicate definition" if len(res) == 1: ret = res[0] @@ -285,20 +248,6 @@ def extract_typedef_decl(ast, name): return ret -# def remove_already_resolved(resolved, typerefs): -# unresolved = [] -# for typeref in typerefs: -# def filter(data): -# if (data["kind"] == "CursorKind.STRUCT_DECL" -# or data["kind"] == "CursorKind.ENUM_DECL" #maybe typedef -# and data["type"] == typeref["type"]): -# return True -# -# contained = recursive_query(resolved, filter) -# if not contained: -# unresolved.append(typeref) -# return unresolved - def find_dup_types(data): def filter(item): if (item["kind"] == "CursorKind.STRUCT_DECL" @@ -413,7 +362,7 @@ def main_new(): (views["all_types"], views["dup_types"]) = find_dup_types(cdl) - + (views["ast_all_types"], views["ast_dup_types"]) = find_dup_types(header["ast"]) header["cdl"] = cdl write_json(header["cdl"], header["out_dir"] + "/" + header["filename"] + ".cdl.json") @@ -421,6 +370,40 @@ def main_new(): write_json(header["views"], header["out_dir"] + "/" + header["filename"] + ".views.json") + + + +# generates simple-ast for each header specified in spec out dir. +def main_old(): + parser = ASTParser("/opt/local/libexec/llvm-9.0/lib/libclang.dylib") + + in_dir = r"/Users/heck/local-default/include/pEp/" + filenames = ["pEpEngine.h", + "keymanagement.h", + "message_api.h", + "message.h", + "sync_api.h", + "key_reset.h", + "Identity.h", + "Rating.h"] + + out_dir = "data/output" + + paths = join_dir_and_filenames(in_dir, filenames) + + headers = [] + for path in paths: + headers.append(create_header(path, out_dir)) + + for header in headers: + print("processing path: " + header["path"] + "...") + header["ast"] = parser.parse(header["path"], header["sourcecode"]) + write_json(header["ast"], header["out_dir"] + "/" + header["filename"] + ".ast.json") + + simpleAst = SimpleAST() + header["simple_ast"] = simpleAst.create_simple_ast(header["ast"]) + write_json(header["simple_ast"], header["out_dir"] + "/" + header["filename"] + ".simple_ast.json") + def main(): # main_old() main_new()