mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor error_codes.py to simplify generation of new error codes
This commit is contained in:
parent
8985a93b39
commit
4fcf0b489a
@ -56,14 +56,11 @@ def get_used_ids(file_names):
|
|||||||
return used_ids
|
return used_ids
|
||||||
|
|
||||||
|
|
||||||
def get_id(available_ids, used_ids):
|
def get_next_id(available_ids):
|
||||||
while len(available_ids) > 0:
|
assert len(available_ids) > 0, "Out of IDs"
|
||||||
k = random.randrange(len(available_ids))
|
next_id = random.choice(list(available_ids))
|
||||||
id = list(available_ids.keys())[k]
|
available_ids.remove(next_id)
|
||||||
del available_ids[id]
|
return next_id
|
||||||
if id not in used_ids:
|
|
||||||
return id
|
|
||||||
assert False, "Out of IDs"
|
|
||||||
|
|
||||||
|
|
||||||
def fix_ids_in_file(file_name, available_ids, used_ids):
|
def fix_ids_in_file(file_name, available_ids, used_ids):
|
||||||
@ -80,7 +77,8 @@ def fix_ids_in_file(file_name, available_ids, used_ids):
|
|||||||
# incorrect id or id has a duplicate somewhere
|
# incorrect id or id has a duplicate somewhere
|
||||||
if not in_comment(source, m.start()) and (len(id) != 4 or id[0] == "0" or used_ids[id] > 1):
|
if not in_comment(source, m.start()) and (len(id) != 4 or id[0] == "0" or used_ids[id] > 1):
|
||||||
assert id in used_ids
|
assert id in used_ids
|
||||||
new_id = get_id(available_ids, used_ids)
|
new_id = get_next_id(available_ids)
|
||||||
|
assert new_id not in used_ids
|
||||||
used_ids[id] -= 1
|
used_ids[id] -= 1
|
||||||
else:
|
else:
|
||||||
new_id = id
|
new_id = id
|
||||||
@ -97,7 +95,7 @@ def fix_ids_in_file(file_name, available_ids, used_ids):
|
|||||||
|
|
||||||
|
|
||||||
def fix_ids(used_ids, file_names):
|
def fix_ids(used_ids, file_names):
|
||||||
available_ids = {str(id): None for id in range(1000, 10000)}
|
available_ids = {str(id) for id in range(1000, 10000)} - used_ids.keys()
|
||||||
for file_name in file_names:
|
for file_name in file_names:
|
||||||
fix_ids_in_file(file_name, available_ids, used_ids)
|
fix_ids_in_file(file_name, available_ids, used_ids)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user