MCPcopy Create free account
hub / github.com/argotorg/solidity / fix_ids_in_source_file

Function fix_ids_in_source_file

scripts/error_codes.py:70–98  ·  view source on GitHub ↗
(file_name, id_to_count, available_ids)

Source from the content-addressed store, hash-verified

68
69
70def fix_ids_in_source_file(file_name, id_to_count, available_ids):
71 source = read_file(file_name)
72
73 k = 0
74 destination = []
75 for m in re.finditer(SOURCE_FILE_PATTERN, source):
76 destination.extend(source[k:m.start()])
77
78 underscore_pos = m.group(0).index("_")
79 error_id = m.group(0)[0:underscore_pos]
80
81 # incorrect id or id has a duplicate somewhere
82 if not in_comment(source, m.start()) and (len(error_id) != 4 or error_id[0] == "0" or id_to_count[error_id] > 1):
83 assert error_id in id_to_count
84 new_id = get_next_id(available_ids)
85 assert new_id not in id_to_count
86 id_to_count[error_id] -= 1
87 else:
88 new_id = error_id
89
90 destination.extend(new_id + "_error")
91 k = m.end()
92
93 destination.extend(source[k:])
94
95 destination = ''.join(destination)
96 if source != destination:
97 write_file(file_name, destination)
98 print(f"Fixed file: {file_name}")
99
100
101def fix_ids_in_source_files(file_names, id_to_count):

Callers 1

fix_ids_in_source_filesFunction · 0.85

Calls 7

read_fileFunction · 0.85
in_commentFunction · 0.85
get_next_idFunction · 0.85
write_fileFunction · 0.85
startMethod · 0.80
indexMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected