json_files_dir = dir_path + '/jsons' if not os.path.exists(json_files_dir): os.mkdir(json_files_dir) # json_file1 is a nested dict json_file1 = json_files_dir + '/AST.json' # json file2 is the trace of each node json_file2 = json_files_dir + '/trace.json' # json file3 restore the name of each module json_file3 = json_files_dir + '/Module_names.json' # json file4 restore the unnested dict json_file4 = json_files_dir + '/uAST.json' if '.c' in code_path or '.cpp' in code_path or '.h' in code_path: code_path_list.append(code_path) node_list, name_all, node_list1 = Node_extract( code_path, sel) node_list.insert(0, code_path) names.append(name_all) to_json(node_list, json_file1, json_file2, False) uAST = to_init_dict(node_list1, 0)[1] print('The total amount of the nodes is {}'.format( len(node_list1))) with open(json_file3, 'w+') as f: json.dump(names, f, ensure_ascii=False, indent=4) f.close() with open(json_file4, 'w+') as f1: json.dump(uAST, f1, ensure_ascii=False, indent=4) f1.close() print("The json file path: " + json_files_dir) else: json_list = [] AST_patch = []
json_file2 = json_files_dir + '/trace.json' to_json(node_list, json_file1, json_file2, False) print ("The json file path: "+json_files_dir) else: json_list = [] node_len = 0 g = os.walk(code_path) for path, di, filelist in g: for filename in filelist: k = os.path.join(path, filename) if '.c' in k or '.cpp' in k: code_path_list.append(k) for i in range(len(code_path_list)): node_list = Node_extract(code_path_list[i], sel) name = code_path_list[i] node_list.insert(0, name) json_list.append(node_list) node_len += len(node_list) print ('The total amount of the nodes is {}'.format(node_len)) json_files_dir = dir_path + '/jsons' if not os.path.exists(json_files_dir): os.mkdir(json_files_dir) json_file1 = json_files_dir + '/AST.json' json_file2 = json_files_dir + '/trace.json' to_json(json_list, json_file1, json_file2, True) print ("The json file path: "+json_files_dir) code_path_file = dir_path + "/jsons/file_path.json" with open(code_path_file, 'w+') as f: json.dump(code_path_list, f, ensure_ascii=False, indent=4) f.close() else: