Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: tools/lexer_generator/code_generator.py

Issue 152513004: Experimental parser: some tuple removal (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/lexer_generator/code_generator.jinja ('k') | tools/lexer_generator/dfa_optimizer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 import os 28 import os
29 import sys 29 import sys
30 import jinja2 30 import jinja2
31 from copy import deepcopy 31 from copy import deepcopy
32 from dfa import Dfa 32 from dfa import Dfa
33 from automaton import Term
33 from transition_keys import TransitionKey 34 from transition_keys import TransitionKey
34 35
35 class CodeGenerator: 36 class CodeGenerator:
36 37
37 def __init__(self, 38 def __init__(self,
38 rule_processor, 39 rule_processor,
39 minimize_default = True, 40 minimize_default = True,
40 inline = True, 41 inline = True,
41 switching = True, 42 switching = True,
42 debug_print = False, 43 debug_print = False,
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 assert len(dfa_states) == self.__dfa.node_count() 291 assert len(dfa_states) == self.__dfa.node_count()
291 # mark eos states 292 # mark eos states
292 self.__mark_eos_states(dfa_states, eos_states) 293 self.__mark_eos_states(dfa_states, eos_states)
293 self.__dfa_states = dfa_states 294 self.__dfa_states = dfa_states
294 295
295 def __rewrite_gotos(self): 296 def __rewrite_gotos(self):
296 goto_map = {} 297 goto_map = {}
297 states = self.__dfa_states 298 states = self.__dfa_states
298 for state in states: 299 for state in states:
299 if (state['match_action'] and 300 if (state['match_action'] and
300 state['match_action'][0] == 'do_stored_token'): 301 state['match_action'].name() == 'do_stored_token'):
301 assert not state['match_action'][1] in goto_map 302 assert not state['match_action'].args()[0] in goto_map
302 goto_map[state['match_action'][1]] = state['node_number'] 303 goto_map[state['match_action'].args()[0]] = state['node_number']
303 mapped_actions = set([ 304 mapped_actions = set([
304 'store_harmony_token_and_goto', 305 'store_harmony_token_and_goto',
305 'store_token_and_goto', 306 'store_token_and_goto',
306 'goto_start']) 307 'goto_start'])
307 for state in states: 308 for state in states:
308 if not state['match_action']: 309 if not state['match_action']:
309 continue 310 continue
310 action = state['match_action'][0] 311 action = state['match_action'].name()
311 if action in mapped_actions: 312 if action in mapped_actions:
312 value = state['match_action'][1] 313 value = state['match_action'].args()
313 target_id = goto_map[value[-1]] 314 target_id = goto_map[value[-1]]
314 states[target_id]['must_not_inline'] = True 315 states[target_id]['must_not_inline'] = True
315 if action != 'goto_start': 316 if action != 'goto_start':
316 state['can_elide_read'] = False 317 state['can_elide_read'] = False
317 label = 'after_entry_code' 318 label = 'after_entry_code'
318 else: 319 else:
319 states[target_id]['can_elide_read'] = False 320 states[target_id]['can_elide_read'] = False
320 label = 'state_entry' 321 label = 'state_entry'
321 jump_label = self.__register_jump(target_id, label) 322 jump_label = self.__register_jump(target_id, label)
322 state['match_action'] = (action, tuple(list(value[:-1]) + [jump_label])) 323 new_args = list(value[:-1]) + [str(jump_label)]
324 state['match_action'] = Term(action, *new_args)
323 325
324 def __inlined_state(self, target_id): 326 def __inlined_state(self, target_id):
325 state = deepcopy(self.__dfa_states[target_id]) 327 state = deepcopy(self.__dfa_states[target_id])
326 state['node_number'] = len(self.__dfa_states) 328 state['node_number'] = len(self.__dfa_states)
327 self.__dfa_states.append(state) 329 self.__dfa_states.append(state)
328 # mark as just generated, so it will correctly rewritten 330 # mark as just generated, so it will correctly rewritten
329 state['just_generated_inline_state'] = True 331 state['just_generated_inline_state'] = True
330 # clear entry points 332 # clear entry points
331 state['entry_points'] = {k : False for k in CodeGenerator.__jump_labels} 333 state['entry_points'] = {k : False for k in CodeGenerator.__jump_labels}
332 return state['node_number'] 334 return state['node_number']
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 424
423 return template.render( 425 return template.render(
424 start_node_number = 0, 426 start_node_number = 0,
425 debug_print = self.__debug_print, 427 debug_print = self.__debug_print,
426 default_action = default_action, 428 default_action = default_action,
427 dfa_states = dfa_states, 429 dfa_states = dfa_states,
428 jump_table = self.__jump_table, 430 jump_table = self.__jump_table,
429 encoding = encoding.name(), 431 encoding = encoding.name(),
430 char_type = char_type, 432 char_type = char_type,
431 upper_bound = encoding.primary_range()[1]) 433 upper_bound = encoding.primary_range()[1])
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator.jinja ('k') | tools/lexer_generator/dfa_optimizer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698