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

Side by Side Diff: Source/bindings/scripts/blink_idl_parser.py

Issue 429523002: IDL: Make caching lex table robust (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 'Comments', # [0.1] 88 'Comments', # [0.1]
89 'CommentsRest', # [0.2] 89 'CommentsRest', # [0.2]
90 ] 90 ]
91 91
92 # Remove rules from base class 92 # Remove rules from base class
93 # FIXME: add a class method upstream: @classmethod IDLParser._RemoveRules 93 # FIXME: add a class method upstream: @classmethod IDLParser._RemoveRules
94 for rule in REMOVED_RULES: 94 for rule in REMOVED_RULES:
95 production_name = 'p_' + rule 95 production_name = 'p_' + rule
96 delattr(IDLParser, production_name) 96 delattr(IDLParser, production_name)
97 97
98 # The base name of cached lexer table generated by BlinkIDLLexer
99 LEX_TABLE_BASENAME = 'lextab'
100
101
102 def remove_cached_lex_table(outputdir):
103 table_files = [
104 os.path.join(outputdir, '%s.py' % LEX_TABLE_BASENAME),
105 os.path.join(outputdir, '%s.pyc' % LEX_TABLE_BASENAME),
106 ]
107 for table_file in table_files:
108 if os.path.exists(table_file):
109 os.unlink(table_file)
110
98 111
99 class BlinkIDLParser(IDLParser): 112 class BlinkIDLParser(IDLParser):
100 # [1] 113 # [1]
101 # FIXME: Need to duplicate rule for starting symbol here, with line number 114 # FIXME: Need to duplicate rule for starting symbol here, with line number
102 # *lower* than in the base parser (idl_parser.py). 115 # *lower* than in the base parser (idl_parser.py).
103 # This is a bug in PLY: it determines starting symbol by lowest line number. 116 # This is a bug in PLY: it determines starting symbol by lowest line number.
104 # This can be overridden by the 'start' parameter, but as of PLY 3.4 this 117 # This can be overridden by the 'start' parameter, but as of PLY 3.4 this
105 # doesn't work correctly. 118 # doesn't work correctly.
106 def p_Definitions(self, p): 119 def p_Definitions(self, p):
107 """Definitions : ExtendedAttributeList Definition Definitions 120 """Definitions : ExtendedAttributeList Definition Definitions
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 self._parse_errors = 0 446 self._parse_errors = 0
434 self._parse_warnings = 0 447 self._parse_warnings = 0
435 self._last_error_msg = None 448 self._last_error_msg = None
436 self._last_error_lineno = 0 449 self._last_error_lineno = 0
437 self._last_error_pos = 0 450 self._last_error_pos = 0
438 451
439 452
440 ################################################################################ 453 ################################################################################
441 454
442 def main(argv): 455 def main(argv):
443 # If file itself executed, cache parse table 456 # If file itself executed, cache parse table. Caching the parse table
457 # also caches lex table. Before caching these tables, we remove the
458 # previous cached lex table if exists so that the build system can keep
459 # track of dependencies. See http://crbug.com/397909
444 try: 460 try:
445 outputdir = argv[1] 461 outputdir = argv[1]
446 except IndexError as err: 462 except IndexError as err:
447 print 'Usage: %s OUTPUT_DIR' % argv[0] 463 print 'Usage: %s OUTPUT_DIR' % argv[0]
448 return 1 464 return 1
465 remove_cached_lex_table(outputdir)
449 # Important: rewrite_tables=True causes the cache file to be deleted if it 466 # Important: rewrite_tables=True causes the cache file to be deleted if it
450 # exists, thus making sure that PLY doesn't load it instead of regenerating 467 # exists, thus making sure that PLY doesn't load it instead of regenerating
451 # the parse table. 468 # the parse table.
452 parser = BlinkIDLParser(outputdir=outputdir, rewrite_tables=True) 469 parser = BlinkIDLParser(outputdir=outputdir, rewrite_tables=True)
453 470
454 471
455 if __name__ == '__main__': 472 if __name__ == '__main__':
456 sys.exit(main(sys.argv)) 473 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698