OLD | NEW |
| (Empty) |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | |
2 # | |
3 # Redistribution and use in source and binary forms, with or without | |
4 # modification, are permitted provided that the following conditions are | |
5 # met: | |
6 # | |
7 # * Redistributions of source code must retain the above copyright | |
8 # notice, this list of conditions and the following disclaimer. | |
9 # * Redistributions in binary form must reproduce the above | |
10 # copyright notice, this list of conditions and the following disclaimer | |
11 # in the documentation and/or other materials provided with the | |
12 # distribution. | |
13 # * Neither the name of Google Inc. nor the names of its | |
14 # contributors may be used to endorse or promote products derived from | |
15 # this software without specific prior written permission. | |
16 # | |
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
28 | |
29 """Read an IDL file or complete IDL interface, producing an IdlDefinitions objec
t.""" | |
30 | |
31 import os.path | |
32 | |
33 import blink_idl_parser | |
34 import idl_definitions_builder | |
35 import idl_validator | |
36 import interface_dependency_resolver | |
37 | |
38 | |
39 class IdlReader(object): | |
40 def __init__(self, interfaces_info=None, idl_attributes_filename=None, outpu
tdir=''): | |
41 if idl_attributes_filename: | |
42 self.extended_attribute_validator = idl_validator.IDLExtendedAttribu
teValidator(idl_attributes_filename) | |
43 else: | |
44 self.extended_attribute_validator = None | |
45 | |
46 if interfaces_info: | |
47 self.interface_dependency_resolver = interface_dependency_resolver.I
nterfaceDependencyResolver(interfaces_info, self) | |
48 else: | |
49 self.interface_dependency_resolver = None | |
50 | |
51 self.parser = blink_idl_parser.BlinkIDLParser(outputdir=outputdir) | |
52 | |
53 def read_idl_definitions(self, idl_filename): | |
54 """Returns an IdlDefinitions object for an IDL file, including all depen
dencies.""" | |
55 definitions = self.read_idl_file(idl_filename) | |
56 if not self.interface_dependency_resolver: | |
57 return definitions | |
58 | |
59 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | |
60 self.interface_dependency_resolver.resolve_dependencies( | |
61 definitions, interface_name) | |
62 return definitions | |
63 | |
64 def read_idl_file(self, idl_filename): | |
65 """Returns an IdlDefinitions object for an IDL file, without any depende
ncies.""" | |
66 ast = blink_idl_parser.parse_file(self.parser, idl_filename) | |
67 definitions = idl_definitions_builder.build_idl_definitions_from_ast(ast
) | |
68 if not self.extended_attribute_validator: | |
69 return definitions | |
70 | |
71 try: | |
72 self.extended_attribute_validator.validate_extended_attributes(defin
itions) | |
73 except idl_validator.IDLInvalidExtendedAttributeError as error: | |
74 raise idl_validator.IDLInvalidExtendedAttributeError("""IDL ATTRIBUT
E ERROR in file %s: | |
75 %s | |
76 If you want to add a new IDL extended attribute, please add it to | |
77 bindings/IDLExtendedAttributes.txt | |
78 and add an explanation to the Blink IDL documentation at: | |
79 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes | |
80 """ % (idl_filename, str(error))) | |
81 | |
82 return definitions | |
OLD | NEW |