outanalyze.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import xlwt
  2. from utils.fileio import load_location, write_json
  3. def out_analyze(node_list, source, save_file: str, entire=False):
  4. book = xlwt.Workbook(encoding='utf-8')
  5. sheet = book.add_sheet("DataType")
  6. cols = ["Location", "Function", "DataType", "Purpose"]
  7. if entire:
  8. cols.remove("Function")
  9. for i in range(len(cols)):
  10. sheet.write(0, i, cols[i])
  11. tmp_row = 1
  12. for i in range(len(node_list)):
  13. node = node_list[i]
  14. file_path = node.file_path.replace('\\', '/').replace(source.replace('\\', '/') + '/', '').split('/')[-1]
  15. location = file_path + "#L" + str(node.line_no)
  16. for data_type, purpose in node.private_info:
  17. if not data_type:
  18. data_type = "None"
  19. if not purpose:
  20. purpose = "None"
  21. if not node.func_name:
  22. node.func_name = "None"
  23. sheet.write(tmp_row, 0, location)
  24. if not entire:
  25. sheet.write(tmp_row, 1, node.func_name)
  26. sheet.write(tmp_row, 2, data_type)
  27. sheet.write(tmp_row, 3, purpose)
  28. else:
  29. sheet.write(tmp_row, 1, data_type)
  30. sheet.write(tmp_row, 2, purpose)
  31. tmp_row += 1
  32. book.save(save_file)