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

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

Issue 85853003: Experimental parser: simplify goto logic (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return id_map 292 return id_map
293 293
294 def __rewrite_gotos(self): 294 def __rewrite_gotos(self):
295 goto_map = {} 295 goto_map = {}
296 for state in self.__dfa_states: 296 for state in self.__dfa_states:
297 if (state['match_action'] and 297 if (state['match_action'] and
298 state['match_action'][0] == 'do_stored_token'): 298 state['match_action'][0] == 'do_stored_token'):
299 assert not state['match_action'][1] in goto_map 299 assert not state['match_action'][1] in goto_map
300 goto_map[state['match_action'][1]] = state['node_number'] 300 goto_map[state['match_action'][1]] = state['node_number']
301 state['has_goto_after_entry'] = True 301 state['has_goto_after_entry'] = True
302 mapped_actions = set([
303 'store_harmony_token_and_goto',
304 'store_token_and_goto',
305 'goto_start'])
302 for state in self.__dfa_states: 306 for state in self.__dfa_states:
303 if state['match_action'] and state['match_action'][0] == 'goto': 307 if not state['match_action']:
304 state['match_action'] = ('goto', goto_map[state['match_action'][1]]) 308 continue
309 if state['match_action'][0] in mapped_actions:
310 value = state['match_action'][1]
311 value = tuple(list(value[:-1]) + [goto_map[value[-1]]])
312 state['match_action'] = (state['match_action'][0], value)
305 313
306 def process(self): 314 def process(self):
307 315
308 id_map = self.__canonicalize_traversal() 316 id_map = self.__canonicalize_traversal()
309 self.__rewrite_gotos() 317 self.__rewrite_gotos()
310 318
311 dfa_states = self.__dfa_states 319 dfa_states = self.__dfa_states
312 # set nodes to inline 320 # set nodes to inline
313 if self.__inline: 321 if self.__inline:
314 inlined = reduce(self.__set_inline, dfa_states, 0) 322 inlined = reduce(self.__set_inline, dfa_states, 0)
(...skipping 24 matching lines...) Expand all
339 char_type = char_types[encoding.name()] 347 char_type = char_types[encoding.name()]
340 348
341 return template.render( 349 return template.render(
342 start_node_number = 0, 350 start_node_number = 0,
343 debug_print = self.__debug_print, 351 debug_print = self.__debug_print,
344 default_action = default_action, 352 default_action = default_action,
345 dfa_states = dfa_states, 353 dfa_states = dfa_states,
346 encoding = encoding.name(), 354 encoding = encoding.name(),
347 char_type = char_type, 355 char_type = char_type,
348 upper_bound = encoding.primary_range()[1]) 356 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