Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | |
|
haraken
2013/07/08 06:06:29
Actually I don't see a benefit in splitting build_
Nils Barth (inactive)
2013/07/09 08:48:16
In the context of the full parsing, these are quit
| |
| 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. | |
|
haraken
2013/07/08 06:06:29
As commented below, I'd avoid using the word "IR"
Nils Barth (inactive)
2013/07/09 08:48:16
The code generator takes as input a Python object
| |
| 30 | |
| 31 This is the last phase of the frontend, after the lexer and the parser. | |
| 32 This also merges interface dependencies (partial interfaces and implements), | |
| 33 and validates extended attributes. | |
|
haraken
2013/07/08 06:06:29
Where is this implemented?
Nils Barth (inactive)
2013/07/09 08:48:16
The validation isn't included in this CL, which is
| |
| 34 The IR is then used by the code generator to produce .cpp/.h files. | |
| 35 | |
| 36 Ideally the parser would generate the IR directly, rather then requiring this | |
| 37 additional phase, but that would require major changes to the parser, which | |
| 38 currently produces a generic AST instead. | |
| 39 | |
| 40 FIXME: Currently a stub, as part of landing the parser incrementally. | |
| 41 Just computes supplemental files, and should always raise an exception, | |
| 42 indicating no file found, so no actual parsing done. | |
| 43 """ | |
| 44 | |
| 45 import os.path | |
| 46 | |
| 47 # Generic Web IDL AST to Blink IR | |
|
haraken
2013/07/08 06:06:29
Nit: Remove this comment.
Nils Barth (inactive)
2013/07/09 08:48:16
Done.
(The full file is rather long, so I have com
| |
| 48 | |
| 49 | |
| 50 def read_merged_idl(idl_filename, supplemental_dependency_file=None, additional_ idl_files=None): | |
|
haraken
2013/07/08 06:06:29
read_merged_idl => resolve_idl_dependency ?
Nils Barth (inactive)
2013/07/09 08:48:16
This actually calls the parser, converts to IR, do
| |
| 51 """Returns Blink IR for an IDL file, including all dependencies.""" | |
| 52 basename = os.path.basename(idl_filename) | |
| 53 | |
| 54 # First check supplemental files, so throws exception if not listed. | |
| 55 supplemental_idl_files = compute_supplemental_idl_files(basename, supplement al_dependency_file, additional_idl_files) | |
| 56 # FIXME: currently *must* raise IdlNotFoundError (indicating that dummy | |
| 57 # .cpp and .h files should be generated), as actual parser not present yet. | |
| 58 raise RuntimeError('Stub: parser not implemented yet') | |
| 59 | |
| 60 # Merge supplemental interfaces ('partial interface' and 'implements') | |
|
haraken
2013/07/08 06:06:29
Nit: Remove this comment.
Nils Barth (inactive)
2013/07/09 08:48:16
Done.
| |
| 61 | |
| 62 | |
| 63 class IdlNotFoundError(Exception): | |
| 64 """Raised if IDL not found in dependencies file or additional files list.""" | |
|
haraken
2013/07/08 06:06:29
Slightly better:
Raised if the IDL file is a pa
Nils Barth (inactive)
2013/07/09 08:48:16
Dependencies now include both partial IDL files an
| |
| 65 pass | |
| 66 | |
| 67 | |
| 68 def compute_supplemental_idl_files(target_idl_basename, supplemental_dependencie s_filename, additional_idl_files): | |
|
haraken
2013/07/08 06:06:29
compute_supplemental_idl_files => compute_partial_
Nils Barth (inactive)
2013/07/09 08:48:16
Changed!
(Actually to "dependencies" because also
| |
| 69 """Returns list of IDL file dependencies for a given main IDL file. | |
| 70 | |
| 71 Also returns empty list if input is an additional IDL file (one not part | |
| 72 of main bindings). | |
| 73 If an IDL file is neither in the main bindings (listed in the dependencies | |
| 74 file) nor in the additional IDL files list, raise an IdlNotFoundError. | |
|
haraken
2013/07/08 06:06:29
Slightly better:
- Returns a list of partial IDL
Nils Barth (inactive)
2013/07/09 08:48:16
I've reworded following this, trying to avoid redu
| |
| 75 """ | |
| 76 # The format of the supplemental dependencies file is: | |
| 77 # | |
| 78 # DOMWindow.idl P.idl Q.idl R.idl | |
| 79 # Document.idl S.idl | |
| 80 # Event.idl | |
| 81 # ... | |
| 82 # | |
| 83 # The above indicates that: | |
| 84 # DOMWindow.idl is supplemented by P.idl, Q.idl, and R.idl, | |
|
haraken
2013/07/08 06:06:29
P.idl, Q.idl and R.idl are partial files of DOMWin
Nils Barth (inactive)
2013/07/09 08:48:16
Replaced with "dependencies", since includes both
| |
| 85 # Document.idl is supplemented by S.idl, and | |
| 86 # Event.idl is supplemented by no IDL files. | |
| 87 # | |
| 88 # An IDL file that supplements another IDL file (e.g., P.idl in the above) | |
| 89 # does not appear on its own line in the dependency file: supplemental | |
| 90 # files are not themselves supplemented. | |
| 91 if supplemental_dependencies_filename is None: | |
| 92 return [] | |
|
haraken
2013/07/08 06:06:29
This should raise an exception.
Nils Barth (inactive)
2013/07/09 08:48:16
The dependencies file is optional, as is the list
| |
| 93 with open(supplemental_dependencies_filename) as supplemental_dependencies_f ile: | |
| 94 for line in supplemental_dependencies_file: | |
| 95 idl_filename, _, dependency_files = line.partition(' ') | |
| 96 if os.path.basename(idl_filename) == target_idl_basename: | |
| 97 return dependency_files.split() | |
| 98 | |
| 99 # additional_idl_files is a list of IDL files which should not be included | |
| 100 # in DerivedSources*.cpp, and hence are not listed in the supplemental | |
| 101 # dependency file, but for which we should generate .cpp and .h files. | |
| 102 additional_idl_basenames = set(map(os.path.basename, additional_idl_files)) | |
| 103 if target_idl_basename in additional_idl_basenames: | |
| 104 return [] | |
| 105 raise IdlNotFoundError | |
| OLD | NEW |