# Order the groups such that those at the start of the program come first. # This ensures that parents are processed before their children, potentially # saving time. sids = sorted(sids) for sid in sids: # Process the fixes in reverse order. for gi, (pi, fix) in enumerate(reversed(groups[sid])): # If replacement occurs, discard all fixes at this SID before this # operation, and destroy all changes made to each of its children # (before this operation). if fix.is_replacement(): groups[sid] = groups[sid][gi:] for c in children[sid]: groups[c] = filter(lambda (cfi, cf): cfi > pi, groups[c]) # If this statement is a delete, then for now we can no longer # address it or its children. if fix.is_deletion(): groups[sid] = [(pi, fix)] for c in children[sid]: groups[c] = [] # Form a canonical patch by adding each group from left to right. fixes = reduce(lambda p, sid: p + map(lambda (i, f): f, groups[sid]), sids, []) return Patch(fixes, True) storage.register("patch", Patch)
lines = [pid] for cid in self.immediate_children(pid): lines.extend(self.lines_within(cid)) return lines # Returns a list of all the ancestors of the statement at a given SID. def ancestors(self, sid): pid = self.parent(sid) return [pid] + self.ancestors(pid) if pid else [] # Returns the SID of the parent of a statement at a given SID. # If that statement has no parent, 0 is returned. def parent(self, sid): return self.enclosure[sid] # Returns the "size" of a statement at a given SID. def size_of(self, sid): return self.__size_of[sid] # Returns a list of the immediate children of a statement at a given SID. def immediate_children(self, sid): return self.__immediate_children[sid] # Returns a list of all the children of a statement at a given SID, # recursively. def children(self, sid): return self.__children[sid] # Register this problem class. storage.register(Repair)