Chromium Code Reviews| Index: Source/bindings/scripts/build_ir.py |
| diff --git a/Source/bindings/scripts/build_ir.py b/Source/bindings/scripts/build_ir.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c34b581aab6a03daa3a3f03dc086ebb8e8796beb |
| --- /dev/null |
| +++ b/Source/bindings/scripts/build_ir.py |
| @@ -0,0 +1,105 @@ |
| +# 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
|
| +# |
| +# Redistribution and use in source and binary forms, with or without |
| +# modification, are permitted provided that the following conditions are |
| +# met: |
| +# |
| +# * Redistributions of source code must retain the above copyright |
| +# notice, this list of conditions and the following disclaimer. |
| +# * Redistributions in binary form must reproduce the above |
| +# copyright notice, this list of conditions and the following disclaimer |
| +# in the documentation and/or other materials provided with the |
| +# distribution. |
| +# * Neither the name of Google Inc. nor the names of its |
| +# contributors may be used to endorse or promote products derived from |
| +# this software without specific prior written permission. |
| +# |
| +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + |
| +"""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
|
| + |
| +This is the last phase of the frontend, after the lexer and the parser. |
| +This also merges interface dependencies (partial interfaces and implements), |
| +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
|
| +The IR is then used by the code generator to produce .cpp/.h files. |
| + |
| +Ideally the parser would generate the IR directly, rather then requiring this |
| +additional phase, but that would require major changes to the parser, which |
| +currently produces a generic AST instead. |
| + |
| +FIXME: Currently a stub, as part of landing the parser incrementally. |
| +Just computes supplemental files, and should always raise an exception, |
| +indicating no file found, so no actual parsing done. |
| +""" |
| + |
| +import os.path |
| + |
| +# 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
|
| + |
| + |
| +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
|
| + """Returns Blink IR for an IDL file, including all dependencies.""" |
| + basename = os.path.basename(idl_filename) |
| + |
| + # First check supplemental files, so throws exception if not listed. |
| + supplemental_idl_files = compute_supplemental_idl_files(basename, supplemental_dependency_file, additional_idl_files) |
| + # FIXME: currently *must* raise IdlNotFoundError (indicating that dummy |
| + # .cpp and .h files should be generated), as actual parser not present yet. |
| + raise RuntimeError('Stub: parser not implemented yet') |
| + |
| +# 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.
|
| + |
| + |
| +class IdlNotFoundError(Exception): |
| + """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
|
| + pass |
| + |
| + |
| +def compute_supplemental_idl_files(target_idl_basename, supplemental_dependencies_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
|
| + """Returns list of IDL file dependencies for a given main IDL file. |
| + |
| + Also returns empty list if input is an additional IDL file (one not part |
| + of main bindings). |
| + If an IDL file is neither in the main bindings (listed in the dependencies |
| + 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
|
| + """ |
| + # The format of the supplemental dependencies file is: |
| + # |
| + # DOMWindow.idl P.idl Q.idl R.idl |
| + # Document.idl S.idl |
| + # Event.idl |
| + # ... |
| + # |
| + # The above indicates that: |
| + # 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
|
| + # Document.idl is supplemented by S.idl, and |
| + # Event.idl is supplemented by no IDL files. |
| + # |
| + # An IDL file that supplements another IDL file (e.g., P.idl in the above) |
| + # does not appear on its own line in the dependency file: supplemental |
| + # files are not themselves supplemented. |
| + if supplemental_dependencies_filename is None: |
| + 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
|
| + with open(supplemental_dependencies_filename) as supplemental_dependencies_file: |
| + for line in supplemental_dependencies_file: |
| + idl_filename, _, dependency_files = line.partition(' ') |
| + if os.path.basename(idl_filename) == target_idl_basename: |
| + return dependency_files.split() |
| + |
| + # additional_idl_files is a list of IDL files which should not be included |
| + # in DerivedSources*.cpp, and hence are not listed in the supplemental |
| + # dependency file, but for which we should generate .cpp and .h files. |
| + additional_idl_basenames = set(map(os.path.basename, additional_idl_files)) |
| + if target_idl_basename in additional_idl_basenames: |
| + return [] |
| + raise IdlNotFoundError |