You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.6 KiB
70 lines
1.6 KiB
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import os
|
|
import json
|
|
|
|
|
|
from ast_parser import AST_Parser
|
|
|
|
def create_paths_list(dirname, filenames):
|
|
paths = []
|
|
for basename in filenames:
|
|
path = dirname + basename
|
|
paths.append(path)
|
|
return paths
|
|
|
|
|
|
def read_files(paths):
|
|
content = []
|
|
for path in paths:
|
|
file_info = read_file(path)
|
|
content.append(file_info)
|
|
return content
|
|
|
|
|
|
def read_file(path):
|
|
with open(path) as f:
|
|
file_content = f.read()
|
|
item = {"path": path,
|
|
"sourcecode": file_content}
|
|
return item
|
|
|
|
|
|
def write_json(header):
|
|
header["outpath"] += ".json"
|
|
with open(header.get("outpath"), "w+") as f:
|
|
json.dump(header, f, indent=4)
|
|
|
|
|
|
def prepare_header(header, out_dir):
|
|
basename = os.path.basename(header.get("path"))
|
|
outpath = out_dir + basename
|
|
header["outpath"] = outpath
|
|
return header
|
|
|
|
|
|
def main():
|
|
input()
|
|
parser = AST_Parser("/opt/local/libexec/llvm-9.0/lib/libclang.dylib")
|
|
# Input
|
|
prefix = r"/Users/heck/local-default/"
|
|
filenames = ["pEpEngine.h",
|
|
"keymanagement.h"]
|
|
# Output
|
|
out_dir = "data/output/"
|
|
if not os.path.isdir(out_dir):
|
|
os.makedirs(out_dir)
|
|
|
|
in_dir = prefix + r"include/pEp/"
|
|
paths = create_paths_list(in_dir, filenames)
|
|
headers = read_files(paths)
|
|
|
|
for header in headers:
|
|
header = prepare_header(header, out_dir)
|
|
print("processing path: " + header.get("path") + "...")
|
|
header["AST"] = parser.parse(header["path"], header["sourcecode"])
|
|
write_json(header)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|