slither-format : use utils.patches.create_patch in naming convention

pull/238/head
Josselin 6 years ago
parent 7f8289aad0
commit 0dacdddaa4
  1. 456
      utils/slither_format/formatters/naming_convention.py
  2. 8
      utils/slither_format/utils/patches.py

@ -4,6 +4,7 @@ from slither.exceptions import SlitherException
from slither.core.expressions.identifier import Identifier from slither.core.expressions.identifier import Identifier
from slither.slithir.operations import NewContract from slither.slithir.operations import NewContract
from slither.slithir.operations import Member from slither.slithir.operations import Member
from ..utils.patches import create_patch
# The Namedtuple will be used to give all the parameters from _patch to the _create_X functions # The Namedtuple will be used to give all the parameters from _patch to the _create_X functions
# Its used to improve code readability and avoid incorrect parameters order # Its used to improve code readability and avoid incorrect parameters order
@ -122,16 +123,14 @@ def _create_patch_contract_definition(format_info):
r'\1'+"contract"+r'\2'+format_info.name.capitalize(), r'\1'+"contract"+r'\2'+format_info.name.capitalize(),
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(format_info.patches,
"file" : format_info.in_file, "naming-convention (contract definition)",
"detector" : "naming-convention (contract definition)", format_info.in_file_relative,
"start": format_info.loc_start, format_info.in_file,
"end": format_info.loc_start+m.span()[1], format_info.loc_start,
"old_string":old_str_of_interest.decode('utf-8'), format_info.loc_start + m.span()[1],
"new_string":new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in format_info.patches[format_info.in_file_relative]:
format_info.patches[format_info.in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find contract?!") raise SlitherException("Could not find contract?!")
@ -153,16 +152,14 @@ def _create_patch_contract_uses(format_info):
sv.source_mapping['length'])] sv.source_mapping['length'])]
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(), (new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
patch = { create_patch(patches,
"file" : in_file, "naming-convention (contract state variable)",
"detector" : "naming-convention (contract state variable)", in_file_relative,
"start" : sv.source_mapping['start'], in_file,
"end" : sv.source_mapping['start'] + sv.source_mapping['length'], sv.source_mapping['start'],
"old_string" : old_str_of_interest.decode('utf-8'), sv.source_mapping['start'] + sv.source_mapping['length'],
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
# Check function+modifier locals+parameters+returns # Check function+modifier locals+parameters+returns
# To-do: Deep-check aggregate types (struct and mapping) # To-do: Deep-check aggregate types (struct and mapping)
fms = contract.functions + contract.modifiers fms = contract.functions + contract.modifiers
@ -173,16 +170,16 @@ def _create_patch_contract_uses(format_info):
v.source_mapping['length'])] v.source_mapping['length'])]
old_str_of_interest = old_str_of_interest.decode('utf-8').split('=')[0] old_str_of_interest = old_str_of_interest.decode('utf-8').split('=')[0]
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),old_str_of_interest, 1) (new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),old_str_of_interest, 1)
patch = {
"file" : in_file, create_patch(patches,
"detector" : "naming-convention (contract function variable)", "naming-convention (contract function variable)",
"start" : v.source_mapping['start'], in_file_relative,
"end" : v.source_mapping['start'] + len(old_str_of_interest), in_file,
"old_string" : old_str_of_interest, v.source_mapping['start'],
"new_string" : new_str_of_interest v.source_mapping['start'] + len(old_str_of_interest),
} old_str_of_interest,
if not patch in patches[in_file_relative]: new_str_of_interest)
patches[in_file_relative].append(patch)
# Check "new" expressions for creation of contract objects # Check "new" expressions for creation of contract objects
for function in contract.functions: for function in contract.functions:
for node in function.nodes: for node in function.nodes:
@ -195,16 +192,14 @@ def _create_patch_contract_uses(format_info):
(new_str_of_interest, num_repl) = re.subn("new"+r'(.*)'+name, "new"+r'\1'+name[0].upper() + (new_str_of_interest, num_repl) = re.subn("new"+r'(.*)'+name, "new"+r'\1'+name[0].upper() +
name[1:], old_str_of_interest, 1) name[1:], old_str_of_interest, 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (contract new object)",
"detector" : "naming-convention (contract new object)", in_file_relative,
"start" : node.source_mapping['start'] + m.span()[0], in_file,
"end" : node.source_mapping['start'] + m.span()[1], node.source_mapping['start'] + m.span()[0],
"old_string" : old_str_of_interest, node.source_mapping['start'] + m.span()[1],
"new_string" : new_str_of_interest old_str_of_interest,
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find new object?!") raise SlitherException("Could not find new object?!")
@ -227,16 +222,14 @@ def _create_patch_modifier_definition(format_info):
(new_str_of_interest, num_repl) = re.subn(r'(.*)'+"modifier"+r'(.*)'+name, r'\1'+"modifier"+r'\2' + (new_str_of_interest, num_repl) = re.subn(r'(.*)'+"modifier"+r'(.*)'+name, r'\1'+"modifier"+r'\2' +
name[0].lower()+name[1:], old_str_of_interest.decode('utf-8'), 1) name[0].lower()+name[1:], old_str_of_interest.decode('utf-8'), 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (modifier definition)",
"detector" : "naming-convention (modifier definition)", in_file_relative,
"start" : modify_loc_start, in_file,
"end" : modify_loc_start+m.span()[1], modify_loc_start,
"old_string" : old_str_of_interest.decode('utf-8'), modify_loc_start + m.span()[1],
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find modifier?!") raise SlitherException("Could not find modifier?!")
@ -259,16 +252,14 @@ def _create_patch_modifier_uses(format_info):
(new_str_of_interest, num_repl) = re.subn(name, name[0].lower()+name[1:], (new_str_of_interest, num_repl) = re.subn(name, name[0].lower()+name[1:],
old_str_of_interest.decode('utf-8'),1) old_str_of_interest.decode('utf-8'),1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (modifier uses)",
"detector" : "naming-convention (modifier uses)", in_file_relative,
"start" : int(function.parameters_src.source_mapping['start']), in_file,
"end" : int(function.returns_src.source_mapping['start']), int(function.parameters_src.source_mapping['start']),
"old_string" : old_str_of_interest.decode('utf-8'), int(function.returns_src.source_mapping['start']),
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find modifier name?!") raise SlitherException("Could not find modifier name?!")
@ -291,16 +282,15 @@ def _create_patch_function_definition(format_info):
(new_str_of_interest, num_repl) = re.subn(r'(.*)'+"function"+r'(.*)'+name, r'\1'+"function"+r'\2'+ (new_str_of_interest, num_repl) = re.subn(r'(.*)'+"function"+r'(.*)'+name, r'\1'+"function"+r'\2'+
name[0].lower()+name[1:], old_str_of_interest.decode('utf-8'), 1) name[0].lower()+name[1:], old_str_of_interest.decode('utf-8'), 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (function definition)",
"detector" : "naming-convention (function definition)", in_file_relative,
"start" : modify_loc_start, in_file,
"end" : modify_loc_start+m.span()[1], modify_loc_start,
"old_string" : old_str_of_interest.decode('utf-8'), modify_loc_start+m.span()[1],
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find function?!") raise SlitherException("Could not find function?!")
@ -325,18 +315,16 @@ def _create_patch_function_calls(format_info):
called_function_name = old_str_of_interest.decode('utf-8').split('.')[-1] called_function_name = old_str_of_interest.decode('utf-8').split('.')[-1]
fixed_function_name = called_function_name[0].lower() + called_function_name[1:] fixed_function_name = called_function_name[0].lower() + called_function_name[1:]
new_string = '.'.join(old_str_of_interest.decode('utf-8').split('.')[:-1]) + '.' + \ new_string = '.'.join(old_str_of_interest.decode('utf-8').split('.')[:-1]) + '.' + \
fixed_function_name fixed_function_name
patch = { create_patch(patches,
"file" : in_file, "naming-convention (function calls)",
"detector" : "naming-convention (function calls)", in_file_relative,
"start" : external_call.source_mapping['start'], in_file,
"end" : int(external_call.source_mapping['start']) + external_call.source_mapping['start'],
int(external_call.source_mapping['length']), int(external_call.source_mapping['start']) +
"old_string" : old_str_of_interest.decode('utf-8'), int(external_call.source_mapping['length']),
"new_string" : new_string old_str_of_interest.decode('utf-8'),
} new_string)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
for internal_call in node.internal_calls_as_expressions: for internal_call in node.internal_calls_as_expressions:
if (str(internal_call.called) == name): if (str(internal_call.called) == name):
in_file_str = slither.source_code[in_file].encode('utf-8') in_file_str = slither.source_code[in_file].encode('utf-8')
@ -344,21 +332,22 @@ def _create_patch_function_calls(format_info):
int(internal_call.source_mapping['start']) + int(internal_call.source_mapping['start']) +
int(internal_call.source_mapping['length'])] int(internal_call.source_mapping['length'])]
old_str_of_interest = old_str_of_interest.decode('utf-8').split('(')[0] old_str_of_interest = old_str_of_interest.decode('utf-8').split('(')[0]
patch = { # Avoid parameters
"file" : in_file, # TODO: (JF) review me
"detector" : "naming-convention (function calls)", end_loc = int(internal_call.source_mapping['start']) + \
"start" : internal_call.source_mapping['start'], int(internal_call.source_mapping['length']) - \
"end" : int(internal_call.source_mapping['start']) +
int(internal_call.source_mapping['length']) -
len('('.join(in_file_str[int(internal_call.source_mapping['start']): len('('.join(in_file_str[int(internal_call.source_mapping['start']):
int(internal_call.source_mapping['start']) + int(internal_call.source_mapping['start']) +
int(internal_call.source_mapping['length'])] \ int(internal_call.source_mapping['length'])] \
.decode('utf-8').split('(')[1:])) - 1, .decode('utf-8').split('(')[1:])) - 1
"old_string" : old_str_of_interest, create_patch(patches,
"new_string" : old_str_of_interest[0].lower()+old_str_of_interest[1:] "naming-convention (function calls)",
} in_file_relative,
if not patch in patches[in_file_relative]: in_file,
patches[in_file_relative].append(patch) internal_call.source_mapping['start'],
end_loc,
old_str_of_interest,
old_str_of_interest[0].lower()+old_str_of_interest[1:])
def _create_patch_event_definition(format_info): def _create_patch_event_definition(format_info):
@ -379,16 +368,14 @@ def _create_patch_event_definition(format_info):
event_name[0].capitalize()+event_name[1:], event_name[0].capitalize()+event_name[1:],
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (event definition)",
"detector" : "naming-convention (event definition)", in_file_relative,
"start" : modify_loc_start, in_file,
"end" : modify_loc_end, modify_loc_start,
"old_string" : old_str_of_interest.decode('utf-8'), modify_loc_end,
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find event?!") raise SlitherException("Could not find event?!")
@ -411,17 +398,16 @@ def _create_patch_event_calls(format_info):
old_str_of_interest = in_file_str[int(call.source_mapping['start']): old_str_of_interest = in_file_str[int(call.source_mapping['start']):
int(call.source_mapping['start']) + int(call.source_mapping['start']) +
int(call.source_mapping['length'])] int(call.source_mapping['length'])]
patch = {
"file" : in_file, create_patch(patches,
"detector" : "naming-convention (event calls)", "naming-convention (event calls)",
"start" : call.source_mapping['start'], in_file_relative,
"end" : int(call.source_mapping['start']) + int(call.source_mapping['length']), in_file,
"old_string" : old_str_of_interest.decode('utf-8'), call.source_mapping['start'],
"new_string" : old_str_of_interest.decode('utf-8')[0].capitalize() + int(call.source_mapping['start']) + int(call.source_mapping['length']),
old_str_of_interest.decode('utf-8')[1:] old_str_of_interest.decode('utf-8'),
} old_str_of_interest.decode('utf-8')[0].capitalize() +
if not patch in patches[in_file_relative]: old_str_of_interest.decode('utf-8')[1:])
patches[in_file_relative].append(patch)
def _create_patch_parameter_declaration(format_info): def _create_patch_parameter_declaration(format_info):
@ -445,16 +431,14 @@ def _create_patch_parameter_declaration(format_info):
(new_str_of_interest, num_repl) = re.subn(r'(.*)'+name+r'(.*)', r'\1'+'_'+name[0].upper() + (new_str_of_interest, num_repl) = re.subn(r'(.*)'+name+r'(.*)', r'\1'+'_'+name[0].upper() +
name[1:]+r'\2', old_str_of_interest.decode('utf-8'), 1) name[1:]+r'\2', old_str_of_interest.decode('utf-8'), 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (parameter declaration)",
"detector" : "naming-convention (parameter declaration)", in_file_relative,
"start" : modify_loc_start, in_file,
"end" : modify_loc_end, modify_loc_start,
"old_string" : old_str_of_interest.decode('utf-8'), modify_loc_end,
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find parameter declaration?!") raise SlitherException("Could not find parameter declaration?!")
@ -489,16 +473,14 @@ def _create_patch_parameter_uses(format_info):
name[0].upper()+name[1:]+r'\2', name[0].upper()+name[1:]+r'\2',
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (parameter uses)",
"detector" : "naming-convention (parameter uses)", in_file_relative,
"start" : modify_loc_start, in_file,
"end" : modify_loc_end, modify_loc_start,
"old_string" : old_str_of_interest.decode('utf-8'), modify_loc_end,
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find parameter use?!") raise SlitherException("Could not find parameter use?!")
@ -520,17 +502,15 @@ def _create_patch_parameter_uses(format_info):
name[0].upper()+name[1:]+r'\2', name[0].upper()+name[1:]+r'\2',
old_str_of_interest_beyond_modifier_name, 1) old_str_of_interest_beyond_modifier_name, 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (parameter uses)",
"detector" : "naming-convention (parameter uses)", in_file_relative,
"start" : modifier.source_mapping['start'] + in_file,
len(old_str_of_interest.decode('utf-8').split('(')[0]) + 1, modifier.source_mapping['start'] +
"end" : modifier.source_mapping['start'] + modifier.source_mapping['length'], len(old_str_of_interest.decode('utf-8').split('(')[0]) + 1,
"old_string" : old_str_of_interest_beyond_modifier_name, modifier.source_mapping['start'] + modifier.source_mapping['length'],
"new_string" : new_str_of_interest old_str_of_interest_beyond_modifier_name,
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find parameter use in modifier?!") raise SlitherException("Could not find parameter use in modifier?!")
@ -559,16 +539,15 @@ def _create_patch_state_variable_declaration(format_info):
else: else:
new_string = old_str_of_interest.decode('utf-8')[m.span()[0]:m.span()[1]] new_string = old_str_of_interest.decode('utf-8')[m.span()[0]:m.span()[1]]
new_string = new_string[0].lower()+new_string[1:] new_string = new_string[0].lower()+new_string[1:]
patch = {
"file" : in_file, create_patch(patches,
"detector" : "naming-convention (state variable declaration)", "naming-convention (state variable declaration)",
"start" : modify_loc_start+m.span()[0], in_file_relative,
"end" : modify_loc_start+m.span()[1], in_file,
"old_string" : old_str_of_interest.decode('utf-8')[m.span()[0]:m.span()[1]], modify_loc_start+m.span()[0],
"new_string" : new_string modify_loc_start+m.span()[1],
} old_str_of_interest.decode('utf-8')[m.span()[0]:m.span()[1]],
if not patch in patches[in_file_relative]: new_string)
patches[in_file_relative].append(patch)
def _create_patch_state_variable_uses(format_info): def _create_patch_state_variable_uses(format_info):
@ -601,16 +580,15 @@ def _create_patch_state_variable_uses(format_info):
else: else:
new_str_of_interest = old_str_of_interest.decode('utf-8') new_str_of_interest = old_str_of_interest.decode('utf-8')
new_str_of_interest = new_str_of_interest[0].lower()+new_str_of_interest[1:] new_str_of_interest = new_str_of_interest[0].lower()+new_str_of_interest[1:]
patch = {
"file" : in_file, create_patch(patches,
"detector" : "naming-convention (state variable uses)", "naming-convention (state variable uses)",
"start" : modify_loc_start, in_file_relative,
"end" : modify_loc_end, in_file,
"old_string" : old_str_of_interest.decode('utf-8'), modify_loc_start,
"new_string" : new_str_of_interest modify_loc_end,
} old_str_of_interest.decode('utf-8'),
if not patch in patches[in_file_relative]: new_str_of_interest)
patches[in_file_relative].append(patch)
def _create_patch_enum_definition(format_info): def _create_patch_enum_definition(format_info):
@ -635,16 +613,14 @@ def _create_patch_enum_definition(format_info):
name[0].capitalize()+name[1:], name[0].capitalize()+name[1:],
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (enum definition)",
"detector" : "naming-convention (enum definition)", in_file_relative,
"start" : modify_loc_start, in_file,
"end" : modify_loc_end, modify_loc_start,
"old_string" : old_str_of_interest.decode('utf-8'), modify_loc_end,
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find enum?!") raise SlitherException("Could not find enum?!")
@ -669,16 +645,16 @@ def _create_patch_enum_uses(format_info):
sv.source_mapping['length'])] sv.source_mapping['length'])]
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(), (new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
patch = {
"file" : in_file, create_patch(patches,
"detector" : "naming-convention (enum use)", "naming-convention (enum use)",
"start" : sv.source_mapping['start'], in_file_relative,
"end" : sv.source_mapping['start'] + sv.source_mapping['length'], in_file,
"old_string" : old_str_of_interest.decode('utf-8'), sv.source_mapping['start'],
"new_string" : new_str_of_interest sv.source_mapping['start'] + sv.source_mapping['length'],
} old_str_of_interest.decode('utf-8'),
if not patch in patches[in_file_relative]: new_str_of_interest)
patches[in_file_relative].append(patch)
# Check function+modifier locals+parameters+returns # Check function+modifier locals+parameters+returns
# To-do: Deep-check aggregate types (struct and mapping) # To-do: Deep-check aggregate types (struct and mapping)
fms = contract.functions + contract.modifiers fms = contract.functions + contract.modifiers
@ -690,16 +666,16 @@ def _create_patch_enum_uses(format_info):
v.source_mapping['length'])] v.source_mapping['length'])]
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(), (new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
patch = {
"file" : in_file, create_patch(patches,
"detector" : "naming-convention (enum use)", "naming-convention (enum use)",
"start" : v.source_mapping['start'], in_file_relative,
"end" : v.source_mapping['start'] + v.source_mapping['length'], in_file,
"old_string" : old_str_of_interest.decode('utf-8'), v.source_mapping['start'],
"new_string" : new_str_of_interest v.source_mapping['start'] + v.source_mapping['length'],
} old_str_of_interest.decode('utf-8'),
if not patch in patches[in_file_relative]: new_str_of_interest)
patches[in_file_relative].append(patch)
# Capture enum uses such as "num = numbers.ONE;" # Capture enum uses such as "num = numbers.ONE;"
for function in contract.functions: for function in contract.functions:
for node in function.nodes: for node in function.nodes:
@ -715,23 +691,28 @@ def _create_patch_enum_uses(format_info):
(new_str_of_interest, num_repl) = re.subn(r'(.*)'+name, r'\1'+name[0].upper()+name[1:], (new_str_of_interest, num_repl) = re.subn(r'(.*)'+name, r'\1'+name[0].upper()+name[1:],
old_str_of_interest, 1) old_str_of_interest, 1)
if num_repl != 0: if num_repl != 0:
patch = {
"file" : in_file, # TODO (JF): review me
"detector" : "naming-convention (enum use)", loc_start = node.source_mapping['start'] + \
"start" : node.source_mapping['start'] +
len(in_file_str[node.source_mapping['start']: len(in_file_str[node.source_mapping['start']:
(node.source_mapping['start']+ (node.source_mapping['start']+
node.source_mapping['length'])].decode('utf-8').split('=')[0]) + node.source_mapping['length'])].decode('utf-8').split('=')[0]) + \
1 + m.span()[0], 1 + m.span()[0]
"end" : node.source_mapping['start'] +
loc_end = node.source_mapping['start'] +\
len(in_file_str[node.source_mapping['start']:(node.source_mapping['start']+ len(in_file_str[node.source_mapping['start']:(node.source_mapping['start']+
node.source_mapping['length'])].\ node.source_mapping['length'])].\
decode('utf-8').split('=')[0]) + 1 + m.span()[0] + len(old_str_of_interest), decode('utf-8').split('=')[0]) + 1 + m.span()[0] + len(old_str_of_interest)
"old_string" : old_str_of_interest,
"new_string" : new_str_of_interest create_patch(patches,
} "naming-convention (enum use)",
if not patch in patches[in_file_relative]: in_file_relative,
patches[in_file_relative].append(patch) in_file,
loc_start,
loc_end,
old_str_of_interest,
new_str_of_interest)
else: else:
raise SlitherException("Could not find new object?!") raise SlitherException("Could not find new object?!")
# To-do: Check any other place/way where enum type is used # To-do: Check any other place/way where enum type is used
@ -759,16 +740,15 @@ def _create_patch_struct_definition(format_info):
name[0].capitalize()+name[1:], name[0].capitalize()+name[1:],
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
if num_repl != 0: if num_repl != 0:
patch = { create_patch(patches,
"file" : in_file, "naming-convention (struct definition)",
"detector" : "naming-convention (struct definition)", in_file_relative,
"start" : modify_loc_start, in_file,
"end" : modify_loc_end, modify_loc_start,
"old_string" : old_str_of_interest.decode('utf-8'), modify_loc_end,
"new_string" : new_str_of_interest old_str_of_interest.decode('utf-8'),
} new_str_of_interest)
if not patch in patches[in_file_relative]:
patches[in_file_relative].append(patch)
else: else:
raise SlitherException("Could not find struct?!") raise SlitherException("Could not find struct?!")
@ -793,16 +773,15 @@ def _create_patch_struct_uses(format_info):
sv.source_mapping['length'])] sv.source_mapping['length'])]
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(), (new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
patch = {
"file" : in_file, create_patch(patches,
"detector" : "naming-convention (struct use)", "naming-convention (struct use)",
"start" : sv.source_mapping['start'], in_file_relative,
"end" : sv.source_mapping['start'] + sv.source_mapping['length'], in_file,
"old_string" : old_str_of_interest.decode('utf-8'), sv.source_mapping['start'],
"new_string" : new_str_of_interest sv.source_mapping['start'] + sv.source_mapping['length'],
} old_str_of_interest.decode('utf-8'),
if not patch in patches[in_file_relative]: new_str_of_interest)
patches[in_file_relative].append(patch)
# Check function+modifier locals+parameters+returns # Check function+modifier locals+parameters+returns
# To-do: Deep-check aggregate types (struct and mapping) # To-do: Deep-check aggregate types (struct and mapping)
fms = contract.functions + contract.modifiers fms = contract.functions + contract.modifiers
@ -813,14 +792,13 @@ def _create_patch_struct_uses(format_info):
v.source_mapping['length'])] v.source_mapping['length'])]
(new_str_of_interest, num_repl) = re.subn(name, name.capitalize(), (new_str_of_interest, num_repl) = re.subn(name, name.capitalize(),
old_str_of_interest.decode('utf-8'), 1) old_str_of_interest.decode('utf-8'), 1)
patch = {
"file" : in_file, create_patch(patches,
"detector" : "naming-convention (struct use)", "naming-convention (struct use)",
"start" : v.source_mapping['start'], in_file_relative,
"end" : v.source_mapping['start'] + v.source_mapping['length'], in_file,
"old_string" : old_str_of_interest.decode('utf-8'), v.source_mapping['start'],
"new_string" : new_str_of_interest v.source_mapping['start'] + v.source_mapping['length'],
} old_str_of_interest.decode('utf-8'),
if not patch in patches[in_file_relative]: new_str_of_interest)
patches[in_file_relative].append(patch)
# To-do: Check any other place/way where struct type is used (e.g. typecast) # To-do: Check any other place/way where struct type is used (e.g. typecast)

@ -1,10 +1,14 @@
def create_patch(patches, detector, file_relative, file, start, end, old_str, new_str): def create_patch(patches, detector, file_relative, file, start, end, old_str, new_str):
patches[file_relative].append({ p = {
"file": file, "file": file,
"detector": detector, "detector": detector,
"start": start, "start": start,
"end": end, "end": end,
"old_string": old_str, "old_string": old_str,
"new_string": new_str "new_string": new_str
}) }
if not file_relative in patches:
patches[file_relative] = []
if p not in patches[file_relative]:
patches[file_relative].append(p)
Loading…
Cancel
Save