| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 distinct_keys += r[1] - r[0] + 1 | 157 distinct_keys += r[1] - r[0] + 1 |
| 158 ranges += 1 | 158 ranges += 1 |
| 159 else: | 159 else: |
| 160 raise Exception() | 160 raise Exception() |
| 161 if distinct_keys <= 7 or float(distinct_keys)/float(ranges) >= 7.0: | 161 if distinct_keys <= 7 or float(distinct_keys)/float(ranges) >= 7.0: |
| 162 return split_count | 162 return split_count |
| 163 switch_transitions = [] | 163 switch_transitions = [] |
| 164 if_transitions = [] | 164 if_transitions = [] |
| 165 for (ranges, node_id) in state['transitions']: | 165 for (ranges, node_id) in state['transitions']: |
| 166 i = [] | 166 i = [] |
| 167 s = [] |
| 167 for r in ranges: | 168 for r in ranges: |
| 168 if r[0] == 'CLASS': | 169 if r[0] == 'CLASS': |
| 169 i.append(r) | 170 i.append(r) |
| 170 else: | 171 else: |
| 171 for x in range(r[1][0], r[1][1] + 1): | 172 s.append(r[1]) |
| 172 switch_transitions.append((x, node_id)) | |
| 173 if i: | 173 if i: |
| 174 if_transitions.append((i, node_id)) | 174 if_transitions.append((i, node_id)) |
| 175 if s: |
| 176 switch_transitions.append((s, node_id)) |
| 175 state['transitions'] = if_transitions | 177 state['transitions'] = if_transitions |
| 176 state['switch_transitions'] = switch_transitions | 178 state['switch_transitions'] = switch_transitions |
| 177 return split_count + 1 | 179 return split_count + 1 |
| 178 | 180 |
| 179 def __canonicalize_traversal(self): | 181 def __canonicalize_traversal(self): |
| 180 dfa_states = [] | 182 dfa_states = [] |
| 181 self.__dfa.visit_all_states(lambda state, acc: dfa_states.append(state)) | 183 self.__dfa.visit_all_states(lambda state, acc: dfa_states.append(state)) |
| 182 dfa_states = map(CodeGenerator.__transform_state, dfa_states) | 184 dfa_states = map(CodeGenerator.__transform_state, dfa_states) |
| 183 id_map = {x['original_node_number'] : x for x in dfa_states} | 185 id_map = {x['original_node_number'] : x for x in dfa_states} |
| 184 CodeGenerator.__compute_depths(self.__start_node_number, 1, id_map) | 186 CodeGenerator.__compute_depths(self.__start_node_number, 1, id_map) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 template_env = jinja2.Environment( | 225 template_env = jinja2.Environment( |
| 224 loader = jinja2.PackageLoader('lexer_generator', '.'), | 226 loader = jinja2.PackageLoader('lexer_generator', '.'), |
| 225 undefined = jinja2.StrictUndefined) | 227 undefined = jinja2.StrictUndefined) |
| 226 template = template_env.get_template('code_generator.jinja') | 228 template = template_env.get_template('code_generator.jinja') |
| 227 | 229 |
| 228 return template.render( | 230 return template.render( |
| 229 start_node_number = 0, | 231 start_node_number = 0, |
| 230 debug_print = self.__debug_print, | 232 debug_print = self.__debug_print, |
| 231 default_action = default_action, | 233 default_action = default_action, |
| 232 dfa_states = dfa_states) | 234 dfa_states = dfa_states) |
| OLD | NEW |