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

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

Issue 184233005: Pre-cache PLY yacc parse table and use optimized mode (45% build time improvement) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Reupload Created 6 years, 9 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
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 13 matching lines...) Expand all
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 """Read an IDL file or complete IDL interface, producing an IdlDefinitions objec t.""" 29 """Read an IDL file or complete IDL interface, producing an IdlDefinitions objec t."""
30 30
31 import os 31 import os
32 32
33 import blink_idl_parser 33 import blink_idl_parser
34 from blink_idl_parser import BlinkIDLParser
Nils Barth (inactive) 2014/03/05 06:11:51 These are just some formatting fixes for consisten
34 from idl_definitions import IdlDefinitions 35 from idl_definitions import IdlDefinitions
35 import idl_validator 36 from idl_validator import IDLInvalidExtendedAttributeError, IDLExtendedAttribute Validator
36 import interface_dependency_resolver 37 from interface_dependency_resolver import InterfaceDependencyResolver
37 38
38 39
39 class IdlReader(object): 40 class IdlReader(object):
40 def __init__(self, interfaces_info=None, idl_attributes_filename=None, outpu tdir=''): 41 def __init__(self, interfaces_info=None, idl_attributes_filename=None, outpu tdir=''):
41 if idl_attributes_filename: 42 if idl_attributes_filename:
42 self.extended_attribute_validator = idl_validator.IDLExtendedAttribu teValidator(idl_attributes_filename) 43 self.extended_attribute_validator = IDLExtendedAttributeValidator(id l_attributes_filename)
43 else: 44 else:
44 self.extended_attribute_validator = None 45 self.extended_attribute_validator = None
45 46
46 if interfaces_info: 47 if interfaces_info:
47 self.interface_dependency_resolver = interface_dependency_resolver.I nterfaceDependencyResolver(interfaces_info, self) 48 self.interface_dependency_resolver = InterfaceDependencyResolver(int erfaces_info, self)
48 else: 49 else:
49 self.interface_dependency_resolver = None 50 self.interface_dependency_resolver = None
50 51
51 self.parser = blink_idl_parser.BlinkIDLParser(outputdir=outputdir) 52 self.parser = BlinkIDLParser(outputdir=outputdir)
52 53
53 def read_idl_definitions(self, idl_filename): 54 def read_idl_definitions(self, idl_filename):
54 """Returns an IdlDefinitions object for an IDL file, including all depen dencies.""" 55 """Returns an IdlDefinitions object for an IDL file, including all depen dencies."""
55 definitions = self.read_idl_file(idl_filename) 56 definitions = self.read_idl_file(idl_filename)
56 if not self.interface_dependency_resolver: 57 if not self.interface_dependency_resolver:
57 return definitions 58 return definitions
58 59
59 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) 60 interface_name, _ = os.path.splitext(os.path.basename(idl_filename))
60 self.interface_dependency_resolver.resolve_dependencies( 61 self.interface_dependency_resolver.resolve_dependencies(
61 definitions, interface_name) 62 definitions, interface_name)
62 return definitions 63 return definitions
63 64
64 def read_idl_file(self, idl_filename): 65 def read_idl_file(self, idl_filename):
65 """Returns an IdlDefinitions object for an IDL file, without any depende ncies.""" 66 """Returns an IdlDefinitions object for an IDL file, without any depende ncies."""
66 ast = blink_idl_parser.parse_file(self.parser, idl_filename) 67 ast = blink_idl_parser.parse_file(self.parser, idl_filename)
67 if not ast: 68 if not ast:
68 raise Exception('Failed to parse %s' % idl_filename) 69 raise Exception('Failed to parse %s' % idl_filename)
69 definitions = IdlDefinitions(ast) 70 definitions = IdlDefinitions(ast)
70 if not self.extended_attribute_validator: 71 if not self.extended_attribute_validator:
71 return definitions 72 return definitions
72 73
73 try: 74 try:
74 self.extended_attribute_validator.validate_extended_attributes(defin itions) 75 self.extended_attribute_validator.validate_extended_attributes(defin itions)
75 except idl_validator.IDLInvalidExtendedAttributeError as error: 76 except IDLInvalidExtendedAttributeError as error:
76 raise idl_validator.IDLInvalidExtendedAttributeError("""IDL ATTRIBUT E ERROR in file %s: 77 raise IDLInvalidExtendedAttributeError(
78 """IDL ATTRIBUTE ERROR in file %s:
77 %s 79 %s
78 If you want to add a new IDL extended attribute, please add it to 80 If you want to add a new IDL extended attribute, please add it to
79 bindings/IDLExtendedAttributes.txt 81 bindings/IDLExtendedAttributes.txt
80 and add an explanation to the Blink IDL documentation at: 82 and add an explanation to the Blink IDL documentation at:
81 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes 83 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes
82 """ % (idl_filename, str(error))) 84 """ % (idl_filename, str(error)))
83 85
84 return definitions 86 return definitions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698