def find_and_replace(self, org_prog, corrupted_prog, regex, replacement='', name='', include_kind=False): # for pointer mutate if regex == '[^)@,#\]] (_<op>_\*)(?! _<number>_)': positions = [m.span(1) for m in re.finditer(regex, corrupted_prog)] else: positions = [m.span() for m in re.finditer(regex, corrupted_prog)] if len(positions) > 1: to_corrupt = np.random.randint(len(positions)) elif len(positions) == 1: to_corrupt = 0 elif include_kind: return corrupted_prog, None, None, None else: return corrupted_prog, None, None corrupted_prog = corrupted_prog[:positions[to_corrupt][0]] + replacement + corrupted_prog[positions[to_corrupt][1]:] fix = isolate_line(org_prog, positions[to_corrupt][0]) line = extract_line_number(fix) if include_kind: return corrupted_prog, fix, line, name else: return corrupted_prog, fix, line
def find_and_replace(org_prog, corrupted_prog, regex, replacement, extra_ids, last_id): positions = [m.span() for m in re.finditer(regex, corrupted_prog)] if len(positions) > 1: to_corrupt = np.random.randint(len(positions)) elif len(positions) == 1: to_corrupt = 0 else: return corrupted_prog, None, None, extra_ids, last_id corrupted_prog = corrupted_prog[:positions[to_corrupt][0]] + replacement + corrupted_prog[positions[to_corrupt][1]:] fix = isolate_line(org_prog, positions[to_corrupt][0]) line = extract_line_number(org_prog, positions[to_corrupt][0]) return corrupted_prog, fix, line, extra_ids, last_id
def find_and_replace(self, corrupted_prog, regex, replacement, mutation_name): positions = [m.span() for m in re.finditer(regex, corrupted_prog)] if len(positions) > 1: to_corrupt = self.rng.randint(len(positions)) elif len(positions) == 1: to_corrupt = 0 else: return corrupted_prog, None, mutation_name line_number = extract_line_number( isolate_line(corrupted_prog, positions[to_corrupt][0])) corrupted_prog = corrupted_prog[:positions[to_corrupt][0]] + \ replacement + corrupted_prog[positions[to_corrupt][1]:] return corrupted_prog, line_number, mutation_name
def find_and_replace(self, org_prog, corrupted_prog, regex, replacement, mutation_name): # special handling for pointer mutate if regex == '[^)@,#\]] (_<op>_\*)(?! _<number>_)': positions = [m.span(1) for m in re.finditer(regex, corrupted_prog)] else: positions = [m.span() for m in re.finditer(regex, corrupted_prog)] if len(positions) > 1: to_corrupt = self.rng.randint(len(positions)) elif len(positions) == 1: to_corrupt = 0 else: return corrupted_prog, None, mutation_name line_number = extract_line_number(isolate_line(corrupted_prog, positions[to_corrupt][0])) corrupted_prog = corrupted_prog[:positions[to_corrupt][0]] + replacement + corrupted_prog[positions[to_corrupt][1]:] return corrupted_prog, line_number, mutation_name