| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 self.__inline = inline | 54 self.__inline = inline |
| 55 self.__switching = switching | 55 self.__switching = switching |
| 56 self.__jump_table = [] | 56 self.__jump_table = [] |
| 57 | 57 |
| 58 __jump_labels = ['state_entry', 'after_entry_code'] | 58 __jump_labels = ['state_entry', 'after_entry_code'] |
| 59 | 59 |
| 60 @staticmethod | 60 @staticmethod |
| 61 def __transform_state(encoding, state): | 61 def __transform_state(encoding, state): |
| 62 # action data | 62 # action data |
| 63 action = state.action() | 63 action = state.action() |
| 64 entry_action = None if not action else action.entry_action() | 64 entry_action = action.entry_action() |
| 65 match_action = None if not action else action.match_action() | 65 match_action = action.match_action() |
| 66 # generate ordered transitions | 66 # generate ordered transitions |
| 67 transitions = map(lambda (k, v) : (k, v.node_number()), | 67 transitions = map(lambda (k, v) : (k, v.node_number()), |
| 68 state.transitions().items()) | 68 state.transitions().items()) |
| 69 def cmp(left, right): | 69 def cmp(left, right): |
| 70 return TransitionKey.canonical_compare(left[0], right[0]) | 70 return TransitionKey.canonical_compare(left[0], right[0]) |
| 71 transitions = sorted(transitions, cmp) | 71 transitions = sorted(transitions, cmp) |
| 72 # map transition keys to disjoint ranges and collect stats | 72 # map transition keys to disjoint ranges and collect stats |
| 73 disjoint_keys = [] | 73 disjoint_keys = [] |
| 74 unique_transitions = {} | 74 unique_transitions = {} |
| 75 old_transitions = transitions | 75 old_transitions = transitions |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 assert id_map[self.__start_node_number]['node_number'] == 0 | 290 assert id_map[self.__start_node_number]['node_number'] == 0 |
| 291 assert len(dfa_states) == self.__dfa.node_count() | 291 assert len(dfa_states) == self.__dfa.node_count() |
| 292 # mark eos states | 292 # mark eos states |
| 293 self.__mark_eos_states(dfa_states, eos_states) | 293 self.__mark_eos_states(dfa_states, eos_states) |
| 294 self.__dfa_states = dfa_states | 294 self.__dfa_states = dfa_states |
| 295 | 295 |
| 296 def __rewrite_gotos(self): | 296 def __rewrite_gotos(self): |
| 297 goto_map = {} | 297 goto_map = {} |
| 298 states = self.__dfa_states | 298 states = self.__dfa_states |
| 299 for state in states: | 299 for state in states: |
| 300 if (state['match_action'] and | 300 if (state['match_action'].name() == 'do_stored_token'): |
| 301 state['match_action'].name() == 'do_stored_token'): | |
| 302 assert not state['match_action'].args()[0] in goto_map | 301 assert not state['match_action'].args()[0] in goto_map |
| 303 goto_map[state['match_action'].args()[0]] = state['node_number'] | 302 goto_map[state['match_action'].args()[0]] = state['node_number'] |
| 304 mapped_actions = set([ | 303 mapped_actions = set([ |
| 305 'store_harmony_token_and_goto', | 304 'store_harmony_token_and_goto', |
| 306 'store_token_and_goto', | 305 'store_token_and_goto', |
| 307 'goto_start']) | 306 'goto_start']) |
| 308 for state in states: | 307 for state in states: |
| 309 if not state['match_action']: | 308 if not state['match_action']: |
| 310 continue | 309 continue |
| 311 action = state['match_action'].name() | 310 action = state['match_action'].name() |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 423 |
| 425 return template.render( | 424 return template.render( |
| 426 start_node_number = 0, | 425 start_node_number = 0, |
| 427 debug_print = self.__debug_print, | 426 debug_print = self.__debug_print, |
| 428 default_action = default_action, | 427 default_action = default_action, |
| 429 dfa_states = dfa_states, | 428 dfa_states = dfa_states, |
| 430 jump_table = self.__jump_table, | 429 jump_table = self.__jump_table, |
| 431 encoding = encoding.name(), | 430 encoding = encoding.name(), |
| 432 char_type = char_type, | 431 char_type = char_type, |
| 433 upper_bound = encoding.primary_range()[1]) | 432 upper_bound = encoding.primary_range()[1]) |
| OLD | NEW |