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 |
11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
12 # distribution. | 12 # distribution. |
13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
16 # | 16 # |
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
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 | |
31 FIXME: Currently a stub, as part of landing the parser incrementally. | |
32 Just create dummy IdlDefinitions objects (no parsing or object building done), | |
33 and resolve dependencies. | |
34 The interface reader should always return None, indicating that bindings should | |
35 not be generated, since the code generator has also not landed yet. | |
36 """ | |
37 | 30 |
38 import os.path | 31 import os.path |
39 | 32 |
| 33 import blink_idl_parser |
| 34 import idl_definitions_builder |
| 35 import idl_validator |
40 import interface_dependency_resolver | 36 import interface_dependency_resolver |
41 | 37 |
42 | 38 |
43 class IdlDefinitions(): | 39 def read_idl_definitions(idl_filename, interface_dependencies_filename, addition
al_idl_filenames, idl_attributes_filename, verbose=False): |
44 """Top-level IDL class. | |
45 | |
46 In Web IDL spec terms, represents a set of definitions, obtained by parsing | |
47 a set of IDL fragments (i.e., the contents of .idl files). | |
48 See: http://www.w3.org/TR/WebIDL/#idl | |
49 """ | |
50 # FIXME: Dummy class; full class hierarchy will be added with parser | |
51 pass | |
52 | |
53 | |
54 def read_idl_definitions(idl_filename, interface_dependencies_filename, addition
al_idl_filenames): | |
55 """Returns an IdlDefinitions object for an IDL file, including all dependenc
ies.""" | 40 """Returns an IdlDefinitions object for an IDL file, including all dependenc
ies.""" |
56 basename = os.path.basename(idl_filename) | 41 basename = os.path.basename(idl_filename) |
57 | 42 |
58 idl_definitions = read_idl_file(idl_filename) | 43 definitions = read_idl_file(idl_filename) |
59 should_generate_bindings = interface_dependency_resolver.merge_interface_dep
endencies(idl_definitions, idl_filename, interface_dependencies_filename, additi
onal_idl_filenames) | 44 if interface_dependencies_filename: |
60 if not should_generate_bindings: | 45 should_generate_bindings = interface_dependency_resolver.resolve_depende
ncies(definitions, idl_filename, interface_dependencies_filename, additional_idl
_filenames, verbose=verbose) |
61 return None | 46 if not should_generate_bindings: |
62 # FIXME: turn on validator | 47 return None |
63 # idl_validator.validate_extended_attributes(idl_definitions, basename, opti
ons.idl_attributes_file) | 48 if idl_attributes_filename: |
64 return idl_definitions | 49 idl_validator.validate_extended_attributes(definitions, basename, idl_at
tributes_filename) |
| 50 return definitions |
65 | 51 |
66 | 52 |
67 def read_idl_file(idl_filename, verbose=False): | 53 def read_idl_file(idl_filename, verbose=False): |
68 """Returns an IdlDefinitions object for an IDL file, without any dependencie
s.""" | 54 """Returns an IdlDefinitions object for an IDL file, without any dependencie
s.""" |
69 # FIXME: Currently returns dummy object, as parser not present yet. | 55 parser = blink_idl_parser.BlinkIDLParser(verbose=verbose) |
70 # parser = BlinkIDLParser(verbose=verbose) | 56 ast = blink_idl_parser.parse_file(parser, idl_filename) |
71 # file_node = blink_idl_parser.parse_file(parser, idl_filename) | 57 return idl_definitions_builder.build_idl_definitions_from_ast(ast) |
72 # return idl_object_builder.file_node_to_idl_definitions(file_node) | |
73 return IdlDefinitions() | |
OLD | NEW |