| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = action.entry_action() | 64 entry_action = action.entry_action() |
| 65 match_action = 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.key_state_iter()) | 68 state.key_state_iter()) |
| 69 def cmp(left, right): | 69 transitions = sorted( |
| 70 return TransitionKey.canonical_compare(left[0], right[0]) | 70 transitions, cmp = TransitionKey.compare, key = lambda x : x[0]) |
| 71 transitions = sorted(transitions, cmp) | |
| 72 # map transition keys to disjoint ranges and collect stats | 71 # map transition keys to disjoint ranges and collect stats |
| 73 disjoint_keys = [] | 72 disjoint_keys = [] |
| 74 unique_transitions = {} | 73 unique_transitions = {} |
| 75 old_transitions = transitions | 74 old_transitions = transitions |
| 76 transitions = [] | 75 transitions = [] |
| 77 (class_keys, distinct_keys, ranges) = (0, 0, 0) | 76 (class_keys, distinct_keys, ranges) = (0, 0, 0) |
| 78 zero_transition = None | 77 zero_transition = None |
| 79 total_transitions = 0 | 78 total_transitions = 0 |
| 80 for key, transition_id in old_transitions: | 79 for key, transition_id in old_transitions: |
| 81 keys = [] | 80 keys = [] |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 'non_primary_identifier_part_not_letter' : 'IsIdentifierPartNotLetter', | 199 'non_primary_identifier_part_not_letter' : 'IsIdentifierPartNotLetter', |
| 201 'non_primary_line_terminator' : 'IsLineTerminator', | 200 'non_primary_line_terminator' : 'IsLineTerminator', |
| 202 } | 201 } |
| 203 | 202 |
| 204 def __rewrite_deferred_transitions(self, state): | 203 def __rewrite_deferred_transitions(self, state): |
| 205 transitions = state['deferred_transitions'] | 204 transitions = state['deferred_transitions'] |
| 206 if not transitions: | 205 if not transitions: |
| 207 return | 206 return |
| 208 encoding = self.__dfa.encoding() | 207 encoding = self.__dfa.encoding() |
| 209 catch_all = 'non_primary_everything_else' | 208 catch_all = 'non_primary_everything_else' |
| 210 all_classes = set(encoding.class_name_iter()) | 209 all_classes = set(encoding.named_range_key_iter()) |
| 211 call_classes = all_classes - set([catch_all]) | 210 call_classes = all_classes - set([catch_all]) |
| 212 def remap_transition(class_name): | 211 def remap_transition(class_name): |
| 213 if class_name in call_classes: | 212 if class_name in call_classes: |
| 214 return ('LONG_CHAR_CLASS', 'call', self.__call_map[class_name]) | 213 return ('LONG_CHAR_CLASS', 'call', self.__call_map[class_name]) |
| 215 raise Exception(class_name) | 214 raise Exception(class_name) |
| 216 long_class_transitions = [] | 215 long_class_transitions = [] |
| 217 long_class_map = {} | 216 long_class_map = {} |
| 218 catchall_transition = None | 217 catchall_transition = None |
| 219 # loop through and remove catch_all_transitions | 218 # loop through and remove catch_all_transitions |
| 220 for (classes, transition_node_id) in transitions: | 219 for (classes, transition_node_id) in transitions: |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 422 |
| 424 return template.render( | 423 return template.render( |
| 425 start_node_number = 0, | 424 start_node_number = 0, |
| 426 debug_print = self.__debug_print, | 425 debug_print = self.__debug_print, |
| 427 default_action = default_action, | 426 default_action = default_action, |
| 428 dfa_states = dfa_states, | 427 dfa_states = dfa_states, |
| 429 jump_table = self.__jump_table, | 428 jump_table = self.__jump_table, |
| 430 encoding = encoding.name(), | 429 encoding = encoding.name(), |
| 431 char_type = char_type, | 430 char_type = char_type, |
| 432 upper_bound = encoding.primary_range()[1]) | 431 upper_bound = encoding.primary_range()[1]) |
| OLD | NEW |