Chromium Code Reviews| 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 """Convert generic Web IDL AST to Blink IR. | |
| 30 | |
| 31 This converts the AST (produced by the parser) into the IR (a Python object | |
| 32 of class IdlDocument). | |
| 33 This is the last phase of the frontend, after the lexer and the parser. | |
| 34 This also merges interface dependencies (partial interfaces and implements), | |
| 35 and validates extended attributes. | |
| 36 The result is an object representing a complete, validated interface. | |
| 37 The IR is then used by the code generator to produce .cpp/.h files. | |
| 38 | |
| 39 Ideally the parser would generate the IR directly, rather then requiring this | |
| 40 additional phase, but that would require major changes to the parser, which | |
| 41 currently produces a generic AST instead. | |
| 42 | |
| 43 FIXME: Currently a stub, as part of landing the parser incrementally. | |
| 44 Just computes dependencies, and should always raise an exception, | |
| 45 indicating no file found, so no actual parsing done. | |
| 46 """ | |
| 47 | |
| 48 import os.path | |
| 49 | |
| 50 | |
| 51 def read_merged_idl(idl_filename, supplemental_dependency_file=None, additional_ idl_files=None): | |
| 52 """Returns Blink IR for an IDL file, including all dependencies.""" | |
| 53 basename = os.path.basename(idl_filename) | |
| 54 | |
| 55 # First check dependency files, so throws exception if not listed. | |
| 56 dependency_idl_files = compute_dependency_idl_files(basename, supplemental_d ependency_file, additional_idl_files) | |
| 57 # FIXME: currently *must* raise IdlNotFoundError (indicating that dummy | |
| 58 # .cpp and .h files should be generated), as actual parser not present yet. | |
| 59 raise RuntimeError('Stub: parser not implemented yet') | |
| 60 # FIXME: turn on parser and other steps once these land | |
| 61 # blink_ir = read_idl_file(idl_filename, verbose=verbose) | |
| 62 # interface = get_interface(blink_ir, interface_name) | |
| 63 # merge_interface_dependencies(interface, idl_filename, dependency_idl_files , verbose=verbose) | |
| 64 # validate_extended_attributes(blink_ir, basename, idl_attributes_file) | |
| 65 | |
| 66 | |
| 67 class IdlNotFoundError(Exception): | |
|
haraken
2013/07/09 11:16:48
Instead of raising IdlNotFoundError, can we just r
Nils Barth (inactive)
2013/07/10 02:38:32
It is a bit more explicit to return None, since th
| |
| 68 """Raised if IDL file not found in lists of files to generate bindings for. | |
| 69 | |
| 70 Concretely, this means the IDL filename is neither found as a head entry in | |
| 71 the dependencies file nor in the additional files list. | |
| 72 This indicates that the IDL should not have bindings generated, and | |
| 73 occurs if one tries to compute dependencies for a file that is itself | |
| 74 a dependency, i.e., a partial dependency or an interface that is | |
| 75 implemented by another interface. | |
| 76 """ | |
| 77 pass | |
| 78 | |
| 79 | |
| 80 def compute_dependency_idl_files(target_idl_basename, interface_dependencies_fil ename, additional_idl_files): | |
| 81 """Returns list of IDL file dependencies for a given main IDL file. | |
| 82 | |
| 83 - Returns a list of IDL files on which a given IDL file depends, | |
| 84 possibly empty. | |
| 85 - Dependencies consist of partial interface files and files for other | |
| 86 interfaces that the given interface implements. | |
|
haraken
2013/07/09 11:16:48
Nit: Let's put these two sentences in one paragrap
Nils Barth (inactive)
2013/07/10 02:38:32
Done.
| |
| 87 - Returns an empty list also if the given IDL file is an additional IDL | |
| 88 file. | |
| 89 - Raises IdlNotFoundError otherwise. This happens when the given IDL file | |
| 90 is a dependency, for which we don't want to generate bindings. | |
| 91 """ | |
| 92 # The format of the interface dependencies file is: | |
| 93 # | |
| 94 # Document.idl P.idl | |
| 95 # Event.idl | |
| 96 # Window.idl Q.idl R.idl S.idl | |
| 97 # ... | |
| 98 # | |
| 99 # The above indicates that: | |
| 100 # Document.idl depends on P.idl, | |
| 101 # Event.idl depends on no other IDL files, and | |
| 102 # Window.idl depends on Q.idl, R.idl, and S.idl. | |
| 103 # | |
| 104 # The head entries (first IDL file on a line) are the files that should | |
| 105 # have bindings generated. | |
| 106 # | |
| 107 # An IDL file that is a dependency of another IDL file (e.g., P.idl in the | |
| 108 # above example) does not have its own line in the dependency file: | |
| 109 # dependencies do not have bindings generated, and do not have their | |
| 110 # own dependencies. | |
| 111 | |
| 112 if interface_dependencies_filename is None: | |
| 113 return [] | |
| 114 with open(interface_dependencies_filename) as interface_dependencies_file: | |
| 115 for line in interface_dependencies_file: | |
| 116 idl_filename, _, dependency_files = line.partition(' ') | |
| 117 if os.path.basename(idl_filename) == target_idl_basename: | |
| 118 return dependency_files.split() | |
| 119 | |
| 120 # additional_idl_files is a list of IDL files which should not be included | |
| 121 # in DerivedSources*.cpp, and hence are not listed in the supplemental | |
| 122 # dependency file, but for which we should generate .cpp and .h files. | |
| 123 additional_idl_basenames = set(map(os.path.basename, additional_idl_files)) | |
| 124 if target_idl_basename in additional_idl_basenames: | |
| 125 return [] | |
| 126 raise IdlNotFoundError | |
| OLD | NEW |