| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 # map the old state to the new state, with fewer transitions and | 242 # map the old state to the new state, with fewer transitions and |
| 243 # goto actions | 243 # goto actions |
| 244 def replace_state(state, acc): | 244 def replace_state(state, acc): |
| 245 new_state = { | 245 new_state = { |
| 246 'transitions' : {}, | 246 'transitions' : {}, |
| 247 'terminal' : state in self.__dfa.terminal_set(), | 247 'terminal' : state in self.__dfa.terminal_set(), |
| 248 'action' : state.action(), | 248 'action' : state.action(), |
| 249 } | 249 } |
| 250 states[name(state)] = new_state | 250 states[name(state)] = new_state |
| 251 state_replacements = replacements[state] if state in replacements else {} | 251 state_replacements = replacements[state] if state in replacements else {} |
| 252 for transition_key, transition_state in state.transitions().items(): | 252 for (transition_key, transition_state) in state.key_state_iter(): |
| 253 if not transition_key in state_replacements: | 253 if not transition_key in state_replacements: |
| 254 new_state['transitions'][transition_key] = name(transition_state) | 254 new_state['transitions'][transition_key] = name(transition_state) |
| 255 continue | 255 continue |
| 256 replacement = state_replacements[transition_key] | 256 replacement = state_replacements[transition_key] |
| 257 del state_replacements[transition_key] | 257 del state_replacements[transition_key] |
| 258 # just drop the transition | 258 # just drop the transition |
| 259 if replacement == None: | 259 if replacement == None: |
| 260 counters['removals'] += 1 | 260 counters['removals'] += 1 |
| 261 continue | 261 continue |
| 262 assert replacement == transition_state | 262 assert replacement == transition_state |
| (...skipping 28 matching lines...) Expand all Loading... |
| 291 counters['store_harmony_token_and_goto']) | 291 counters['store_harmony_token_and_goto']) |
| 292 print 'transitions removed %s' % counters['removals'] | 292 print 'transitions removed %s' % counters['removals'] |
| 293 print 'do_stored_token actions added %s' % len(store_states) | 293 print 'do_stored_token actions added %s' % len(store_states) |
| 294 self.__dfa = Dfa(self.__dfa.encoding(), start_name, states) | 294 self.__dfa = Dfa(self.__dfa.encoding(), start_name, states) |
| 295 | 295 |
| 296 @staticmethod | 296 @staticmethod |
| 297 def optimize(dfa, log): | 297 def optimize(dfa, log): |
| 298 optimizer = DfaOptimizer(dfa, log) | 298 optimizer = DfaOptimizer(dfa, log) |
| 299 optimizer.replace_tokens_with_gotos() | 299 optimizer.replace_tokens_with_gotos() |
| 300 return optimizer.__dfa | 300 return optimizer.__dfa |
| OLD | NEW |