OLD | NEW |
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 10 matching lines...) Expand all Loading... |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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.path | 31 import os |
32 | 32 |
33 import blink_idl_parser | 33 import blink_idl_parser |
34 import idl_definitions_builder | 34 from idl_definitions import IdlDefinitions |
35 import idl_validator | 35 import idl_validator |
36 import interface_dependency_resolver | 36 import interface_dependency_resolver |
37 | 37 |
38 | 38 |
39 class IdlReader(object): | 39 class IdlReader(object): |
40 def __init__(self, interfaces_info=None, idl_attributes_filename=None, outpu
tdir=''): | 40 def __init__(self, interfaces_info=None, idl_attributes_filename=None, outpu
tdir=''): |
41 if idl_attributes_filename: | 41 if idl_attributes_filename: |
42 self.extended_attribute_validator = idl_validator.IDLExtendedAttribu
teValidator(idl_attributes_filename) | 42 self.extended_attribute_validator = idl_validator.IDLExtendedAttribu
teValidator(idl_attributes_filename) |
43 else: | 43 else: |
44 self.extended_attribute_validator = None | 44 self.extended_attribute_validator = None |
(...skipping 12 matching lines...) Expand all Loading... |
57 return definitions | 57 return definitions |
58 | 58 |
59 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | 59 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) |
60 self.interface_dependency_resolver.resolve_dependencies( | 60 self.interface_dependency_resolver.resolve_dependencies( |
61 definitions, interface_name) | 61 definitions, interface_name) |
62 return definitions | 62 return definitions |
63 | 63 |
64 def read_idl_file(self, idl_filename): | 64 def read_idl_file(self, idl_filename): |
65 """Returns an IdlDefinitions object for an IDL file, without any depende
ncies.""" | 65 """Returns an IdlDefinitions object for an IDL file, without any depende
ncies.""" |
66 ast = blink_idl_parser.parse_file(self.parser, idl_filename) | 66 ast = blink_idl_parser.parse_file(self.parser, idl_filename) |
67 definitions = idl_definitions_builder.build_idl_definitions_from_ast(ast
) | 67 if not ast: |
| 68 raise Exception('Failed to parse %s' % idl_filename) |
| 69 definitions = IdlDefinitions(ast) |
68 if not self.extended_attribute_validator: | 70 if not self.extended_attribute_validator: |
69 return definitions | 71 return definitions |
70 | 72 |
71 try: | 73 try: |
72 self.extended_attribute_validator.validate_extended_attributes(defin
itions) | 74 self.extended_attribute_validator.validate_extended_attributes(defin
itions) |
73 except idl_validator.IDLInvalidExtendedAttributeError as error: | 75 except idl_validator.IDLInvalidExtendedAttributeError as error: |
74 raise idl_validator.IDLInvalidExtendedAttributeError("""IDL ATTRIBUT
E ERROR in file %s: | 76 raise idl_validator.IDLInvalidExtendedAttributeError("""IDL ATTRIBUT
E ERROR in file %s: |
75 %s | 77 %s |
76 If you want to add a new IDL extended attribute, please add it to | 78 If you want to add a new IDL extended attribute, please add it to |
77 bindings/IDLExtendedAttributes.txt | 79 bindings/IDLExtendedAttributes.txt |
78 and add an explanation to the Blink IDL documentation at: | 80 and add an explanation to the Blink IDL documentation at: |
79 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes | 81 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes |
80 """ % (idl_filename, str(error))) | 82 """ % (idl_filename, str(error))) |
81 | 83 |
82 return definitions | 84 return definitions |
OLD | NEW |