| OLD | NEW |
| 1 # Copyright 2013 the V8 project authors. All rights reserved. | 1 # Copyright 2013 the V8 project authors. All rights reserved. |
| 2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
| 3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
| 4 # met: | 4 # met: |
| 5 # | 5 # |
| 6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
| 9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
| 10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 def build_incoming_transitions_map(self): | 162 def build_incoming_transitions_map(self): |
| 163 incoming_transitions = {} | 163 incoming_transitions = {} |
| 164 def f(state, visitor_state): | 164 def f(state, visitor_state): |
| 165 for key, transition_state in state.key_state_iter(): | 165 for key, transition_state in state.key_state_iter(): |
| 166 if not transition_state in incoming_transitions: | 166 if not transition_state in incoming_transitions: |
| 167 incoming_transitions[transition_state] = [] | 167 incoming_transitions[transition_state] = [] |
| 168 incoming_transitions[transition_state].append((key, state)) | 168 incoming_transitions[transition_state].append((key, state)) |
| 169 self.visit_all_states(f) | 169 self.visit_all_states(f) |
| 170 return incoming_transitions | 170 return incoming_transitions |
| 171 |
| 172 def path_iter(self): |
| 173 '''Walk all paths through the dfa, ending at nodes with no transitions |
| 174 or the first reappearance of a node. Yields data structures which cannot |
| 175 be modified or stored. |
| 176 Yields path: [(key, state)], states_in_path: set, is_terminal : boolean |
| 177 path always starts with (None, state_state)''' |
| 178 start_state = self.start_state() |
| 179 path = [(None, start_state)] |
| 180 in_path = set([start_state]) |
| 181 iters = [(start_state.key_state_iter(), False)] |
| 182 while path: |
| 183 assert len(path) == len(in_path) |
| 184 assert len(path) == len(iters) |
| 185 try: |
| 186 (it, called) = iters[-1] |
| 187 (key, state) = it.next() |
| 188 if not called: |
| 189 iters[-1] = (it, True) |
| 190 path.append((key, state)) |
| 191 if state in in_path: |
| 192 # Terminate nested iteration. |
| 193 yield path, in_path, False |
| 194 path.pop() |
| 195 continue |
| 196 # Continue nesting. |
| 197 in_path.add(state) |
| 198 iters.append((state.key_state_iter(), False)) |
| 199 except StopIteration: |
| 200 # No more transitions in iterator, pop everything. |
| 201 (it, called) = iters.pop() |
| 202 if not called: |
| 203 yield path, in_path, True |
| 204 in_path.remove(path.pop()[1]) |
| OLD | NEW |