def eliminate_duplicate_funcs(file_name):
    if shared.Settings.ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS != 0:
        # Remove previous log file if it exists
        equivalent_fn_json_file = file_name + ".equivalent_functions.json"
        if os.path.isfile(equivalent_fn_json_file):
            print("Deleting old json: " + equivalent_fn_json_file,
                  file=sys.stderr)
            os.remove(equivalent_fn_json_file)

        old_funcs = get_func_names(file_name)

    for pass_num in range(
            shared.Settings.ELIMINATE_DUPLICATE_FUNCTIONS_PASSES):
        if DEBUG:
            print("[PASS {}]: eliminating duplicate functions in: {}.".format(
                pass_num, file_name),
                  file=sys.stderr)

        # Generate the JSON for the equivalent hash first
        processed_file = run_on_js(filename=file_name, gen_hash_info=True)
        try:
            save_temp_file(processed_file)
            # Use the hash to reduce the JS file
            final_file = run_on_js(filename=processed_file,
                                   gen_hash_info=False)
        finally:
            os.remove(processed_file)

        save_temp_file(final_file)

        shared.safe_move(final_file, file_name)

    if shared.Settings.ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS != 0:
        new_funcs = get_func_names(file_name)

        eliminated_funcs_file = file_name + ".eliminated_functions.json"
        print("Writing eliminated functions to file: {}".format(
            eliminated_funcs_file),
              file=sys.stderr)

        with open(eliminated_funcs_file, 'w') as fout:
            eliminated_functions = list(set(old_funcs) - set(new_funcs))
            eliminated_functions.sort()
            for eliminated_function in eliminated_functions:
                fout.write('{}\n'.format(eliminated_function))
예제 #2
0
def eliminate_duplicate_funcs(file_name):
  if shared.Settings.ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS != 0:
    # Remove previous log file if it exists
    equivalent_fn_json_file = file_name + ".equivalent_functions.json"
    if os.path.isfile(equivalent_fn_json_file):
      print("Deleting old json: " + equivalent_fn_json_file, file=sys.stderr)
      os.remove(equivalent_fn_json_file)

    old_funcs = get_func_names(file_name)

  for pass_num in range(shared.Settings.ELIMINATE_DUPLICATE_FUNCTIONS_PASSES):
    if DEBUG:
      print("[PASS {}]: eliminating duplicate functions in: {}.".format(pass_num, file_name), file=sys.stderr)

    # Generate the JSON for the equivalent hash first
    processed_file = run_on_js(filename=file_name, gen_hash_info=True)
    try:
      save_temp_file(processed_file)
      # Use the hash to reduce the JS file
      final_file = run_on_js(filename=processed_file, gen_hash_info=False)
    finally:
      os.remove(processed_file)

    save_temp_file(final_file)

    shared.safe_move(final_file, file_name)

  if shared.Settings.ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS != 0:
    new_funcs = get_func_names(file_name)

    eliminated_funcs_file = file_name + ".eliminated_functions.json"
    print("Writing eliminated functions to file: {}".format(eliminated_funcs_file), file=sys.stderr)

    with open(eliminated_funcs_file, 'w') as fout:
      eliminated_functions = list(set(old_funcs) - set(new_funcs))
      eliminated_functions.sort()
      for eliminated_function in eliminated_functions:
        fout.write('{}\n'.format(eliminated_function))