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 IdlDocument object. | |
30 | |
31 For a single IDL file, this library calls the parser, which produces a generic | |
32 Web IDL AST. The AST is then converted into the IR, a Python object of class | |
33 IdlDocument. | |
34 For a complete interface, it calls the dependency resolver, which reads all | |
35 IDLs files needed by an interface (main file plus partial interfaces and | |
36 implements), merges these into a single IdlDocument, and then calls the | |
37 validator to validate extended attributes. | |
38 The result is an IdlDocument representing a complete, validated interface. | |
39 This IdlDocument is then used by the code generator to produce .h/.cpp files. | |
40 | |
41 Ideally the parser would generate the IdlDocument directly, rather then | |
42 requiring this additional phase, but that would require major changes to the | |
43 parser, which currently produces a generic AST instead. | |
haraken
2013/07/10 06:22:48
I'd remove this comment at this point, since none
Nils Barth (inactive)
2013/07/10 07:04:11
Got it; will add when actually implemented.
| |
44 | |
45 FIXME: Currently a stub, as part of landing the parser incrementally. | |
46 Just create dummy IdlDocuments (no parsing or object building done), and | |
47 resolve dependencies. | |
48 The interface reader should always return None, indicating that bindings should | |
49 not be generated, since the code generator has also not landed yet. | |
50 """ | |
51 | |
52 import os.path | |
53 | |
54 import idl_dependency_resolver | |
55 | |
56 | |
57 class IdlDocument(): | |
haraken
2013/07/10 06:22:48
There is no concept of "IdlDocument" in the spec.
Nils Barth (inactive)
2013/07/10 07:04:11
Closest to the spec would be "IdlDefinitions", as
| |
58 """Top-level IDL class. | |
59 | |
60 In Web IDL spec terms, represents a set of definitions, obtained by parsing | |
61 a set of IDL fragments (i.e., the contents of .idl files).""" | |
haraken
2013/07/10 06:22:48
Would you add a link to the exact position of the
Nils Barth (inactive)
2013/07/10 07:04:11
Done.
| |
62 # FIXME: Dummy class; full class hierarchy will be added with parser | |
63 pass | |
64 | |
65 | |
66 def read_idl_interface(idl_filename, interface_dependencies_filename, additional _idl_filenames): | |
67 """Returns an IdlDocument for an IDL interface, including all dependencies." "" | |
68 basename = os.path.basename(idl_filename) | |
69 | |
70 idl_document = read_idl_file(idl_filename) | |
71 should_generate_bindings = idl_dependency_resolver.merge_interface_dependenc ies(idl_document, idl_filename, interface_dependencies_filename, additional_idl_ filenames) | |
72 if not should_generate_bindings: | |
73 return None | |
74 # FIXME: turn on validator | |
75 # idl_validator.validate_extended_attributes(idl_document, basename, options .idl_attributes_file) | |
76 return idl_document | |
77 | |
78 | |
79 def read_idl_file(idl_filename, verbose=False): | |
80 """Returns an IdlDocument for an IDL file, without any dependencies.""" | |
81 # FIXME: Currently returns dummy object, as parser not present yet. | |
82 # parser = BlinkIDLParser(verbose=verbose) | |
83 # file_node = blink_idl_parser.parse_file(parser, idl_filename) | |
84 # return idl_document_builder.file_node_to_idl_document(file_node) | |
85 return IdlDocument() | |
OLD | NEW |